From 4e93bfdb1d04ef43a3fa60299af36e296bb7e1b1 Mon Sep 17 00:00:00 2001 From: Nam Hoang Date: Tue, 15 Oct 2024 09:19:23 +0700 Subject: [PATCH] refactor: rename getStorageServiceLink to uploadData Signed-off-by: Nam Hoang --- .../__tests__/ConformityCredential.test.tsx | 6 ++-- .../ConformityCredential.tsx | 4 +-- .../src/__tests__/aggregationEvent.test.ts | 28 +++++++++++++++---- .../__tests__/epcisEvents/objectEvent.test.ts | 6 ++-- .../services/src/__tests__/mocks/constants.ts | 2 ++ .../services/src/__tests__/processDPP.test.ts | 22 +++++++++------ .../processDigitalFacilityRecord.test.ts | 6 ++-- .../processDigitalIdentityAnchor.test.ts | 6 ++-- .../services/src/__tests__/storage.test.ts | 4 +-- .../src/__tests__/transactionEvent.test.ts | 12 ++++---- .../src/__tests__/transformationEvent.test.ts | 8 +++--- .../src/epcisEvents/aggregationEvent.ts | 4 +-- .../services/src/epcisEvents/objectEvent.ts | 8 ++---- .../src/epcisEvents/transactionEvent.ts | 4 +-- .../src/epcisEvents/transformationEvent.ts | 4 +-- packages/services/src/processDPP.service.ts | 4 +-- .../processDigitalFacilityRecord.service.ts | 4 +-- .../processDigitalIdentityAnchor.service.ts | 4 +-- packages/services/src/storage.service.ts | 11 ++++---- packages/services/src/types/storage.ts | 2 +- 20 files changed, 84 insertions(+), 65 deletions(-) diff --git a/packages/components/src/__tests__/ConformityCredential.test.tsx b/packages/components/src/__tests__/ConformityCredential.test.tsx index cd45cb2b..eee8123b 100644 --- a/packages/components/src/__tests__/ConformityCredential.test.tsx +++ b/packages/components/src/__tests__/ConformityCredential.test.tsx @@ -2,11 +2,11 @@ import { fireEvent, render, screen } from '@testing-library/react'; import { act } from 'react-dom/test-utils'; import { ConformityCredential } from '../components'; import { FetchOptions } from '../types/conformityCredential.types'; -import { getJsonDataFromConformityAPI, getStorageServiceLink, getValueByPath } from '@mock-app/services'; +import { getJsonDataFromConformityAPI, uploadData, getValueByPath } from '@mock-app/services'; import { checkStoredCredentialsConfig } from '../components/ConformityCredential/utils'; jest.mock('@mock-app/services', () => ({ - getStorageServiceLink: jest.fn(), + uploadData: jest.fn(), generateUUID: jest.fn(), getJsonDataFromConformityAPI: jest.fn(), })); @@ -135,7 +135,7 @@ describe('ConformityCredential', () => { (getJsonDataFromConformityAPI as jest.Mock).mockResolvedValue(apiResp); (getValueByPath as jest.Mock).mockReturnValue(apiResp); (checkStoredCredentialsConfig as jest.Mock).mockReturnValue({ ok: true, value: '' }); - (getStorageServiceLink as jest.Mock).mockResolvedValue('https://storage.example.com/credential'); + (uploadData as jest.Mock).mockResolvedValue('https://storage.example.com/credential'); await act(async () => { render( diff --git a/packages/components/src/components/ConformityCredential/ConformityCredential.tsx b/packages/components/src/components/ConformityCredential/ConformityCredential.tsx index 3c448cd7..b7473610 100644 --- a/packages/components/src/components/ConformityCredential/ConformityCredential.tsx +++ b/packages/components/src/components/ConformityCredential/ConformityCredential.tsx @@ -7,7 +7,7 @@ import { validateAndConstructVerifyURL, generateUUID, getJsonDataFromConformityAPI, - getStorageServiceLink, + uploadData, getValueByPath, } from '@mock-app/services'; @@ -172,7 +172,7 @@ export const ConformityCredential: React.FC = ({ return; } - const vcUrl = await getStorageServiceLink(storedCredentialsConfig, extractedCredential, generateUUID()); + const vcUrl = await uploadData(storedCredentialsConfig, extractedCredential, generateUUID()); const verifyURL = validateAndConstructVerifyURL(vcUrl); saveConformityCredentials(credentialRequestConfig.credentialName, verifyURL, credentialRequestConfig.appOnly); diff --git a/packages/services/src/__tests__/aggregationEvent.test.ts b/packages/services/src/__tests__/aggregationEvent.test.ts index eea77efd..53239515 100644 --- a/packages/services/src/__tests__/aggregationEvent.test.ts +++ b/packages/services/src/__tests__/aggregationEvent.test.ts @@ -1,5 +1,5 @@ import * as vckitService from '../vckit.service'; -import { getStorageServiceLink } from '../storage.service'; +import { uploadData } from '../storage.service'; import * as linkResolverService from '../linkResolver.service'; import { IAggregationEventContext } from '../types/types'; import { Result } from '../types/validateContext'; @@ -13,13 +13,14 @@ jest.mock('../vckit.service', () => ({ issueVC: jest.fn(), })); jest.mock('../storage.service', () => ({ - getStorageServiceLink: jest.fn(), + uploadData: jest.fn(), })); jest.mock('../linkResolver.service', () => ({ registerLinkResolver: jest.fn(), createLinkResolver: jest.fn(), IdentificationKeyType: jest.fn(), getLinkResolverIdentifier: jest.fn(), + getLinkResolverIdentifierFromURI: jest.fn(), LinkType: { verificationLinkType: 'gs1:verificationService', certificationLinkType: 'gs1:certificationInfo', @@ -55,7 +56,7 @@ describe('processAggregationEvent', () => { it('should process aggregation event', async () => { (vckitService.issueVC as jest.Mock).mockImplementationOnce(() => aggregationVCMock); - (getStorageServiceLink as jest.Mock).mockResolvedValueOnce('https://exampleStorage.com/vc.json'); + (uploadData as jest.Mock).mockResolvedValueOnce('https://exampleStorage.com/vc.json'); jest .spyOn(validateContext, 'validateAggregationEventContext') @@ -67,7 +68,7 @@ describe('processAggregationEvent', () => { const aggregationVC = await processAggregationEvent(aggregationEvent, context); expect(aggregationVC).toBe(aggregationVCMock); - expect(getStorageServiceLink).toHaveBeenCalled(); + expect(uploadData).toHaveBeenCalled(); expect(validateContext.validateAggregationEventContext).toHaveBeenCalled(); expect(linkResolverService.registerLinkResolver).toHaveBeenCalled(); }); @@ -119,6 +120,11 @@ describe('processAggregationEvent', () => { jest .spyOn(linkResolverService, 'getLinkResolverIdentifier') .mockReturnValueOnce({ identifier: '0123456789', qualifierPath: '/10/ABC123' }); + jest.spyOn(linkResolverService, 'getLinkResolverIdentifierFromURI').mockReturnValueOnce({ + identifier: '0123456789', + qualifierPath: '/10/ABC123', + elementString: '01012345678910ABC123', + }); jest.spyOn(publicAPI, 'post').mockRejectedValueOnce("Can't issue VC"); await processAggregationEvent(aggregationEvent, invalidIssuerContext); @@ -142,6 +148,11 @@ describe('processAggregationEvent', () => { jest .spyOn(linkResolverService, 'getLinkResolverIdentifier') .mockReturnValueOnce({ identifier: '0123456789', qualifierPath: '/10/ABC123' }); + jest.spyOn(linkResolverService, 'getLinkResolverIdentifierFromURI').mockReturnValueOnce({ + identifier: '0123456789', + qualifierPath: '/10/ABC123', + elementString: '01012345678910ABC123', + }); jest.spyOn(publicAPI, 'put').mockRejectedValueOnce('Invalid storage provider'); await processAggregationEvent(aggregationEvent, invalidStorageContext); @@ -160,7 +171,7 @@ describe('processAggregationEvent', () => { dlr: { ...context.dlr, dlrAPIUrl: 'http://invalid-dlr.com' }, }; (vckitService.issueVC as jest.Mock).mockImplementationOnce(() => aggregationVCMock); - (getStorageServiceLink as jest.Mock).mockImplementation(({ url, _data, path }) => { + (uploadData as jest.Mock).mockImplementation(({ url, _data, path }) => { return `${url}/${path}`; }); jest @@ -169,6 +180,11 @@ describe('processAggregationEvent', () => { jest .spyOn(linkResolverService, 'getLinkResolverIdentifier') .mockReturnValueOnce({ identifier: '0123456789', qualifierPath: '/10/ABC123' }); + jest.spyOn(linkResolverService, 'getLinkResolverIdentifierFromURI').mockReturnValueOnce({ + identifier: '0123456789', + qualifierPath: '/10/ABC123', + elementString: '01012345678910ABC123', + }); jest.spyOn(linkResolverService, 'createLinkResolver').mockRejectedValueOnce('Invalid DLR API link resolver url'); await processAggregationEvent(aggregationEvent, invalidDLRContext); @@ -177,7 +193,7 @@ describe('processAggregationEvent', () => { expect(error.message).toBe('Invalid DLR API link resolver url'); expect(validateContext.validateAggregationEventContext).toHaveBeenCalled(); expect(vckitService.issueVC).toHaveBeenCalled(); - expect(getStorageServiceLink).toHaveBeenCalled(); + expect(uploadData).toHaveBeenCalled(); } }); }); diff --git a/packages/services/src/__tests__/epcisEvents/objectEvent.test.ts b/packages/services/src/__tests__/epcisEvents/objectEvent.test.ts index e740b8ab..1b57b4a5 100644 --- a/packages/services/src/__tests__/epcisEvents/objectEvent.test.ts +++ b/packages/services/src/__tests__/epcisEvents/objectEvent.test.ts @@ -1,7 +1,7 @@ import { ITraceabilityEvent } from '../../types'; import { processObjectEvent } from '../../epcisEvents/objectEvent'; import * as vckitService from '../../vckit.service'; -import { getStorageServiceLink } from '../../storage.service'; +import { uploadData } from '../../storage.service'; import * as linkResolverService from '../../linkResolver.service'; import { IAggregationEventContext, IObjectEventContext } from '../../types'; import { Result } from '../../types/validateContext'; @@ -12,7 +12,7 @@ jest.mock('../../vckit.service', () => ({ issueVC: jest.fn(), })); jest.mock('../../storage.service', () => ({ - getStorageServiceLink: jest.fn(), + uploadData: jest.fn(), })); jest.mock('../../linkResolver.service', () => ({ registerLinkResolver: jest.fn(), @@ -60,7 +60,7 @@ describe('processObjectEvent', () => { (vckitService.issueVC as jest.Mock).mockImplementation(() => ({ credentialSubject: { id: 'https://example.com/123' }, })); - (getStorageServiceLink as jest.Mock).mockResolvedValue('https://exampleStorage.com/vc.json'); + (uploadData as jest.Mock).mockResolvedValue('https://exampleStorage.com/vc.json'); jest .spyOn(validateContext, 'validateObjectEventContext') diff --git a/packages/services/src/__tests__/mocks/constants.ts b/packages/services/src/__tests__/mocks/constants.ts index 1ec3bd56..fa37562a 100644 --- a/packages/services/src/__tests__/mocks/constants.ts +++ b/packages/services/src/__tests__/mocks/constants.ts @@ -141,6 +141,8 @@ export const contextDPP = { dlr: { dlrAPIUrl: 'http://dlr.example.com', dlrAPIKey: '1234', + namespace: 'gs1', + linkRegisterPath: '/api/resolver', }, storage: { url: 'https://storage.example.com', diff --git a/packages/services/src/__tests__/processDPP.test.ts b/packages/services/src/__tests__/processDPP.test.ts index 1678c856..b17881dc 100644 --- a/packages/services/src/__tests__/processDPP.test.ts +++ b/packages/services/src/__tests__/processDPP.test.ts @@ -1,6 +1,6 @@ import { processDPP } from '../processDPP.service'; import { issueVC, contextDefault } from '../vckit.service'; -import { getStorageServiceLink } from '../storage.service'; +import { uploadData } from '../storage.service'; import { registerLinkResolver, IdentificationKeyType, LinkType } from '../linkResolver.service'; import { contextDPP, dataDPP } from './mocks/constants'; @@ -10,7 +10,7 @@ jest.mock('../vckit.service', () => ({ })); jest.mock('../storage.service', () => ({ - getStorageServiceLink: jest.fn(), + uploadData: jest.fn(), })); jest.mock('../linkResolver.service', () => ({ @@ -24,10 +24,9 @@ jest.mock('../linkResolver.service', () => ({ verificationLinkType: 'gs1:verificationService', certificationLinkType: 'gs1:certificationInfo', epcisLinkType: 'gs1:epcis', - } + }, })); - describe('processDPP', () => { describe('successful case', () => { afterEach(() => { @@ -56,7 +55,7 @@ describe('processDPP', () => { }); it('should call process DPP', async () => { - (getStorageServiceLink as jest.Mock).mockImplementation(({ url, _data, path }) => { + (uploadData as jest.Mock).mockImplementation(({ url, _data, path }) => { return `${url}/${dataDPP.data.herd.identifier}`; }); @@ -75,7 +74,7 @@ describe('processDPP', () => { linkTitle, verificationPage, dlrAPIKey, - identificationKey + identificationKey, }); return `${dlrAPIUrl}/${identificationKeyType}/${identificationKey}?linkType=all`; }, @@ -84,9 +83,15 @@ describe('processDPP', () => { const vc = await processDPP(dataDPP, contextDPP); expect(vc).toEqual({ vc: expectVCResult, - linkResolver: contextDPP.dpp.dlrVerificationPage + '/' + contextDPP.dpp.dlrIdentificationKeyType + '/' + dataDPP.data.herd.identifier + '?linkType=all', + linkResolver: + contextDPP.dpp.dlrVerificationPage + + '/' + + contextDPP.dpp.dlrIdentificationKeyType + + '/' + + dataDPP.data.herd.identifier + + '?linkType=all', }); - expect(getStorageServiceLink).toHaveBeenCalled(); + expect(uploadData).toHaveBeenCalled(); expect(registerLinkResolver).toHaveBeenCalled(); const dppContext = contextDPP.dpp; @@ -100,6 +105,7 @@ describe('processDPP', () => { dppContext.dlrVerificationPage, dlrContext.dlrAPIUrl, dlrContext.dlrAPIKey, + dlrContext.namespace, dataDPP.qualifierPath, LinkType.certificationLinkType, ); diff --git a/packages/services/src/__tests__/processDigitalFacilityRecord.test.ts b/packages/services/src/__tests__/processDigitalFacilityRecord.test.ts index 8ae42d45..d6bac88c 100644 --- a/packages/services/src/__tests__/processDigitalFacilityRecord.test.ts +++ b/packages/services/src/__tests__/processDigitalFacilityRecord.test.ts @@ -1,5 +1,5 @@ import * as vckitService from '../vckit.service'; -import { getStorageServiceLink } from '../storage.service'; +import { uploadData } from '../storage.service'; import * as linkResolverService from '../linkResolver.service'; import { Result } from '../types/validateContext'; import * as validateContext from '../validateContext'; @@ -11,7 +11,7 @@ jest.mock('../vckit.service', () => ({ issueVC: jest.fn(), })); jest.mock('../storage.service', () => ({ - getStorageServiceLink: jest.fn(), + uploadData: jest.fn(), })); jest.mock('../linkResolver.service', () => ({ registerLinkResolver: jest.fn(), @@ -40,7 +40,7 @@ describe('processDigitalFacilityRecord', () => { (vckitService.issueVC as jest.Mock).mockImplementation(() => ({ credentialSubject: { id: 'https://example.com/123' }, })); - (getStorageServiceLink as jest.Mock).mockResolvedValue('https://exampleStorage.com/vc.json'); + (uploadData as jest.Mock).mockResolvedValue('https://exampleStorage.com/vc.json'); jest .spyOn(validateContext, 'validateDigitalFacilityRecordContext') diff --git a/packages/services/src/__tests__/processDigitalIdentityAnchor.test.ts b/packages/services/src/__tests__/processDigitalIdentityAnchor.test.ts index e6f3e817..bc87582a 100644 --- a/packages/services/src/__tests__/processDigitalIdentityAnchor.test.ts +++ b/packages/services/src/__tests__/processDigitalIdentityAnchor.test.ts @@ -1,5 +1,5 @@ import * as vckitService from '../vckit.service'; -import { getStorageServiceLink } from '../storage.service'; +import { uploadData } from '../storage.service'; import * as linkResolverService from '../linkResolver.service'; import { Result } from '../types/validateContext'; import * as validateContext from '../validateContext'; @@ -11,7 +11,7 @@ jest.mock('../vckit.service', () => ({ issueVC: jest.fn(), })); jest.mock('../storage.service', () => ({ - getStorageServiceLink: jest.fn(), + uploadData: jest.fn(), })); jest.mock('../linkResolver.service', () => ({ registerLinkResolver: jest.fn(), @@ -40,7 +40,7 @@ describe('processDigitalIdentityAnchor', () => { (vckitService.issueVC as jest.Mock).mockImplementation(() => ({ credentialSubject: { id: 'https://example.com/123' }, })); - (getStorageServiceLink as jest.Mock).mockResolvedValue('https://exampleStorage.com/vc.json'); + (uploadData as jest.Mock).mockResolvedValue('https://exampleStorage.com/vc.json'); jest .spyOn(validateContext, 'validateDigitalIdentityAnchorContext') diff --git a/packages/services/src/__tests__/storage.test.ts b/packages/services/src/__tests__/storage.test.ts index 1a27f9d5..fd33cd74 100644 --- a/packages/services/src/__tests__/storage.test.ts +++ b/packages/services/src/__tests__/storage.test.ts @@ -9,7 +9,6 @@ jest.mock('../utils/httpService', () => ({ }, })); - describe('storage service', () => { afterEach(() => { jest.resetAllMocks(); @@ -42,7 +41,6 @@ describe('storage service', () => { }); expect(url).toEqual({ url: `https://dev-verifiable-credentials.com/${path}`, - }); }); @@ -64,7 +62,7 @@ describe('storage service', () => { headers: [], }, }); - expect(url).toEqual(`https://dev-verifiable-credentials.com/${path}`); + expect(url).toEqual({ url: `https://dev-verifiable-credentials.com/${path}` }); }); // error cases diff --git a/packages/services/src/__tests__/transactionEvent.test.ts b/packages/services/src/__tests__/transactionEvent.test.ts index b6d4a21b..6fd3b97f 100644 --- a/packages/services/src/__tests__/transactionEvent.test.ts +++ b/packages/services/src/__tests__/transactionEvent.test.ts @@ -3,7 +3,7 @@ import * as linkResolverService from '../linkResolver.service'; import * as helpers from '../epcisEvents/helpers'; import * as validateContext from '../validateContext'; import { processTransactionEvent } from '../epcisEvents/transactionEvent'; -import { getStorageServiceLink } from '../storage.service'; +import { uploadData } from '../storage.service'; import { Result } from '../types/validateContext'; import { ITransactionEventContext } from '../types/types'; import { publicAPI } from '../utils/httpService'; @@ -13,7 +13,7 @@ jest.mock('../vckit.service', () => ({ issueVC: jest.fn(), })); jest.mock('../storage.service', () => ({ - getStorageServiceLink: jest.fn(), + uploadData: jest.fn(), })); jest.mock('../linkResolver.service', () => ({ registerLinkResolver: jest.fn(), @@ -68,7 +68,7 @@ describe('processTransactionEvent', () => { it('should process transaction event', async () => { (vckitService.issueVC as jest.Mock).mockImplementationOnce(() => transactionVCMock); - (getStorageServiceLink as jest.Mock).mockImplementation(({ url, _data, path }) => { + (uploadData as jest.Mock).mockImplementation(({ url, _data, path }) => { return `${url}/${path}`; }); jest @@ -82,7 +82,7 @@ describe('processTransactionEvent', () => { vc: transactionVCMock, linkResolver: transactionEventDLRMock, }); - expect(getStorageServiceLink).toHaveBeenCalled(); + expect(uploadData).toHaveBeenCalled(); expect(validateContext.validateTransactionEventContext).toHaveBeenCalled(); expect(linkResolverService.registerLinkResolver).toHaveBeenCalled(); }); @@ -169,7 +169,7 @@ describe('processTransactionEvent', () => { dlr: { ...context.dlr, dlrAPIUrl: 'http://invalid-dlr.com' }, }; (vckitService.issueVC as jest.Mock).mockImplementationOnce(() => transactionVCMock); - (getStorageServiceLink as jest.Mock).mockResolvedValueOnce('https://storage.com/vc.json'); + (uploadData as jest.Mock).mockResolvedValueOnce('https://storage.com/vc.json'); jest .spyOn(validateContext, 'validateTransactionEventContext') .mockReturnValueOnce({ ok: true, value: context } as Result); @@ -181,7 +181,7 @@ describe('processTransactionEvent', () => { expect(error.message).toBe('Invalid DLR API link resolver url'); expect(validateContext.validateTransactionEventContext).toHaveBeenCalled(); expect(vckitService.issueVC).toHaveBeenCalled(); - expect(getStorageServiceLink).toHaveBeenCalled(); + expect(uploadData).toHaveBeenCalled(); } }); }); diff --git a/packages/services/src/__tests__/transformationEvent.test.ts b/packages/services/src/__tests__/transformationEvent.test.ts index f1936f61..e63b333c 100644 --- a/packages/services/src/__tests__/transformationEvent.test.ts +++ b/packages/services/src/__tests__/transformationEvent.test.ts @@ -5,7 +5,7 @@ import { uploadVC, } from '../epcisEvents/transformationEvent'; import { issueVC, contextDefault } from '../vckit.service'; -import { getStorageServiceLink } from '../storage.service'; +import { uploadData } from '../storage.service'; import { registerLinkResolver, IdentificationKeyType } from '../linkResolver.service'; import { fillArray } from '../utils/helpers'; import { IEntityIssue, IInputItems } from '../types'; @@ -17,7 +17,7 @@ jest.mock('../vckit.service', () => ({ })); jest.mock('../storage.service', () => ({ - getStorageServiceLink: jest.fn(), + uploadData: jest.fn(), })); jest.mock('../linkResolver.service', () => ({ @@ -112,7 +112,7 @@ describe('Transformation event', () => { it('should upload vc and return link to the uploaded json file', async () => { let expectResult = 'http://localhost/epcis-transformation-event/1234'; - (getStorageServiceLink as jest.Mock).mockResolvedValue(expectResult); + (uploadData as jest.Mock).mockResolvedValue(expectResult); const mockVc = { '@context': ['https://www.w3.org/2018/credentials/v1'], type: ['VerifiableCredential', 'MockEvent'], @@ -198,7 +198,7 @@ describe('Transformation event', () => { }); it('should call registerLinkResolver transformation event', async () => { - (getStorageServiceLink as jest.Mock).mockImplementation(({ url, _data, path }) => { + (uploadData as jest.Mock).mockImplementation(({ url, _data, path }) => { return `${url}/${path}`; }); (registerLinkResolver as jest.Mock).mockImplementation( diff --git a/packages/services/src/epcisEvents/aggregationEvent.ts b/packages/services/src/epcisEvents/aggregationEvent.ts index 3802db60..0437123a 100644 --- a/packages/services/src/epcisEvents/aggregationEvent.ts +++ b/packages/services/src/epcisEvents/aggregationEvent.ts @@ -1,6 +1,6 @@ import { VerifiableCredential } from '@vckit/core-types'; import { issueVC } from '../vckit.service.js'; -import { getStorageServiceLink } from '../storage.service.js'; +import { uploadData } from '../storage.service.js'; import { LinkType, getLinkResolverIdentifier, registerLinkResolver } from '../linkResolver.service.js'; import { IService } from '../types/IService.js'; import { ITraceabilityEvent, IAggregationEventContext } from '../types'; @@ -49,7 +49,7 @@ export const processAggregationEvent: IService = async ( }, }); - const aggregationVCLink = await getStorageServiceLink(storage, aggregationVC, `${identifier}/${generateUUID()}`); + const aggregationVCLink = await uploadData(storage, aggregationVC, `${identifier}/${generateUUID()}`); await registerLinkResolver( aggregationVCLink, diff --git a/packages/services/src/epcisEvents/objectEvent.ts b/packages/services/src/epcisEvents/objectEvent.ts index 8ec0aab0..e3042a37 100644 --- a/packages/services/src/epcisEvents/objectEvent.ts +++ b/packages/services/src/epcisEvents/objectEvent.ts @@ -1,6 +1,6 @@ import { VerifiableCredential } from '@vckit/core-types'; import { registerLinkResolver, LinkType, getLinkResolverIdentifier } from '../linkResolver.service.js'; -import { getStorageServiceLink } from '../storage.service.js'; +import { uploadData } from '../storage.service.js'; import { IService } from '../types/IService.js'; import { constructIdentifierString, generateUUID } from '../utils/helpers.js'; import { issueVC } from '../vckit.service.js'; @@ -45,11 +45,7 @@ export const processObjectEvent: IService = async ( }, }); - const objectEventVcUrl = await getStorageServiceLink( - storage, - objectEventVc, - `${objectEventIdentifier}/${generateUUID()}`, - ); + const objectEventVcUrl = await uploadData(storage, objectEventVc, `${objectEventIdentifier}/${generateUUID()}`); const objectEventLinkResolver = await registerLinkResolver( objectEventVcUrl, diff --git a/packages/services/src/epcisEvents/transactionEvent.ts b/packages/services/src/epcisEvents/transactionEvent.ts index 42f5c6ea..ec7c1249 100644 --- a/packages/services/src/epcisEvents/transactionEvent.ts +++ b/packages/services/src/epcisEvents/transactionEvent.ts @@ -1,7 +1,7 @@ import { VerifiableCredential } from '@vckit/core-types'; import { IService, ITraceabilityEvent, ITransactionEventContext } from '../types/index.js'; import { issueVC } from '../vckit.service.js'; -import { getStorageServiceLink } from '../storage.service.js'; +import { uploadData } from '../storage.service.js'; import { constructIdentifierString, generateUUID } from '../utils/helpers.js'; import { LinkType, getLinkResolverIdentifier, registerLinkResolver } from '../linkResolver.service.js'; import { validateTransactionEventContext } from '../validateContext.js'; @@ -36,7 +36,7 @@ export const processTransactionEvent: IService = async ( }, }); - const vcUrl = await getStorageServiceLink(storage, vc, `${identifier}/${generateUUID()}`); + const vcUrl = await uploadData(storage, vc, `${identifier}/${generateUUID()}`); const linkResolver = await registerLinkResolver( vcUrl, diff --git a/packages/services/src/epcisEvents/transformationEvent.ts b/packages/services/src/epcisEvents/transformationEvent.ts index 6d3bba69..9c84080f 100644 --- a/packages/services/src/epcisEvents/transformationEvent.ts +++ b/packages/services/src/epcisEvents/transformationEvent.ts @@ -2,7 +2,7 @@ import { VerifiableCredential } from '@vckit/core-types'; import _ from 'lodash'; import { issueVC } from '../vckit.service.js'; -import { getStorageServiceLink } from '../storage.service.js'; +import { uploadData } from '../storage.service.js'; import { IdentificationKeyType, LinkType, @@ -176,7 +176,7 @@ export const issueEpcisTransformationEvent = async ( * @returns string - url of the uploaded verifiable credential */ export const uploadVC = async (path: string, vc: VerifiableCredential, storageContext: StorageServiceConfig) => { - const result = await getStorageServiceLink(storageContext, vc, path); + const result = await uploadData(storageContext, vc, path); return result; }; diff --git a/packages/services/src/processDPP.service.ts b/packages/services/src/processDPP.service.ts index 91bad5b7..2432443a 100644 --- a/packages/services/src/processDPP.service.ts +++ b/packages/services/src/processDPP.service.ts @@ -2,7 +2,7 @@ import { W3CVerifiableCredential } from '@vckit/core-types'; import { IService, IDppContext } from './types/index.js'; import { constructIdentifierString, generateUUID } from './utils/helpers.js'; -import { getStorageServiceLink } from './storage.service.js'; +import { uploadData } from './storage.service.js'; import { issueVC } from './vckit.service.js'; import { LinkType, getLinkResolverIdentifier, registerLinkResolver } from './linkResolver.service.js'; import { validateContextDPP } from './validateContext.js'; @@ -38,7 +38,7 @@ export const processDPP: IService = async (data: any, context: IDppContext): Pro }); const storageContext = context.storage; - const vcUrl = await getStorageServiceLink(storageContext, vc, `${identifier}/${qualifierPath}`); + const vcUrl = await uploadData(storageContext, vc, `${identifier}/${qualifierPath}`); const linkResolverContext = context.dlr; const linkResolver = await registerLinkResolver( diff --git a/packages/services/src/processDigitalFacilityRecord.service.ts b/packages/services/src/processDigitalFacilityRecord.service.ts index 969d5e86..a730ebbc 100644 --- a/packages/services/src/processDigitalFacilityRecord.service.ts +++ b/packages/services/src/processDigitalFacilityRecord.service.ts @@ -1,6 +1,6 @@ import { VerifiableCredential } from '@vckit/core-types'; import { registerLinkResolver, LinkType, getLinkResolverIdentifier } from './linkResolver.service.js'; -import { getStorageServiceLink } from './storage.service.js'; +import { uploadData } from './storage.service.js'; import { IService } from './types/IService.js'; import { constructIdentifierString, generateUUID } from './utils/helpers.js'; import { issueVC } from './vckit.service.js'; @@ -44,7 +44,7 @@ export const processDigitalFacilityRecord: IService = async ( }, }); - const vcUrl = await getStorageServiceLink(storage, vc, `${identifier}/${generateUUID()}`); + const vcUrl = await uploadData(storage, vc, `${identifier}/${generateUUID()}`); const linkResolver = await registerLinkResolver( vcUrl, diff --git a/packages/services/src/processDigitalIdentityAnchor.service.ts b/packages/services/src/processDigitalIdentityAnchor.service.ts index 83526a2a..9d0fd6d8 100644 --- a/packages/services/src/processDigitalIdentityAnchor.service.ts +++ b/packages/services/src/processDigitalIdentityAnchor.service.ts @@ -1,6 +1,6 @@ import { VerifiableCredential } from '@vckit/core-types'; import { registerLinkResolver, LinkType, getLinkResolverIdentifier } from './linkResolver.service.js'; -import { getStorageServiceLink } from './storage.service.js'; +import { uploadData } from './storage.service.js'; import { IService } from './types/IService.js'; import { constructIdentifierString, generateUUID } from './utils/helpers.js'; import { issueVC } from './vckit.service.js'; @@ -44,7 +44,7 @@ export const processDigitalIdentityAnchor: IService = async ( }, }); - const vcUrl = await getStorageServiceLink(storage, vc, `${identifier}/${generateUUID()}`); + const vcUrl = await uploadData(storage, vc, `${identifier}/${generateUUID()}`); const linkResolver = await registerLinkResolver( vcUrl, diff --git a/packages/services/src/storage.service.ts b/packages/services/src/storage.service.ts index 0117ecb2..1c1e7dc5 100644 --- a/packages/services/src/storage.service.ts +++ b/packages/services/src/storage.service.ts @@ -1,4 +1,4 @@ -import { IGetStorageServiceLink, IStorageService } from './types/storage.js'; +import { IStorageService, IUploadData } from './types/storage.js'; import { getValueByPath } from './utils/helpers.js'; import { publicAPI } from './utils/httpService.js'; @@ -17,19 +17,18 @@ export const storageService: IStorageService = async (config) => { throw new Error(`Unsupported method`); } - const getResultByPath = getValueByPath(result, params.resultPath); - return getResultByPath; + return result; } catch (error: any) { console.error(error); throw new Error(error.message); } }; -export const getStorageServiceLink: IGetStorageServiceLink = async (storage, data, filename) => { +export const uploadData: IUploadData = async (storage, data, filename) => { // TODO: remove jwt check in the future const payloadData = typeof data === 'string' ? { jwt: data } : data; - return await storageService({ + const result = await storageService({ url: storage.url, params: { ...storage.params, @@ -38,4 +37,6 @@ export const getStorageServiceLink: IGetStorageServiceLink = async (storage, dat }, options: storage.options, }); + + return getValueByPath(result, storage.params.resultPath); }; diff --git a/packages/services/src/types/storage.ts b/packages/services/src/types/storage.ts index 0b59a7cd..ad29e6cd 100644 --- a/packages/services/src/types/storage.ts +++ b/packages/services/src/types/storage.ts @@ -18,6 +18,6 @@ export interface IStorageService { (config: StorageServiceConfig): Promise; } -export interface IGetStorageServiceLink { +export interface IUploadData { (storage: StorageServiceConfig, data: any, filename: string): Promise; }