From 8847137926ce605131bd53b515fff54e185f0730 Mon Sep 17 00:00:00 2001 From: Sangeetha Krishnan Date: Mon, 26 Sep 2022 16:13:28 +0530 Subject: [PATCH 1/9] Update registration methods to use V2 API --- e2e/e2e.js | 41 ++++--- src/SDKErrors.js | 2 + src/index.js | 69 +++++++++--- test/index.test.js | 87 +++++++++------ test/mock.js | 272 +++++++++++++++++++++++++++++++++------------ 5 files changed, 330 insertions(+), 141 deletions(-) diff --git a/e2e/e2e.js b/e2e/e2e.js index fd3bdad..6d6c5c9 100644 --- a/e2e/e2e.js +++ b/e2e/e2e.js @@ -34,7 +34,6 @@ const accessToken = process.env.EVENTS_JWT_TOKEN const consumerOrgId = process.env.EVENTS_CONSUMER_ORG_ID const workspaceId = process.env.EVENTS_WORKSPACE_ID const projectId = process.env.EVENTS_PROJECT_ID -const integrationId = process.env.EVENTS_INTEGRATION_ID const httpOptions = { retries: 3 } const randomNumber = Math.round(Math.random() * 100000) @@ -77,26 +76,25 @@ test('test create event metadata', async () => { test('test register journalling endpoint', async () => { // create journal registration - journalReg = await sdkClient.createWebhookRegistration(consumerOrgId, - integrationId, { - name: 'Test Events SDK ' + randomNumber, - description: 'Test Events SDK ' + randomNumber, - client_id: apiKey, - delivery_type: 'JOURNAL', - events_of_interest: [ - { - event_code: eventCode, - provider_id: providerId - } - ] - }) - expect(journalReg.status).toBe('VERIFIED') - expect(journalReg.integration_status).toBe('ENABLED') + journalReg = await sdkClient.createWebhookRegistration(consumerOrgId, projectId, workspaceId, { + name: 'Test Events SDK ' + randomNumber, + description: 'Test Events SDK ' + randomNumber, + client_id: apiKey, + delivery_type: 'journal', + events_of_interest: [ + { + event_code: eventCode, + provider_id: providerId + } + ] + }) + expect(journalReg.webhook_status).toBe('verified') + expect(journalReg.enabled).toBe(true) }) test('test fetch journalling position', async () => { - const journallingUrl = journalReg.events_url - logger.info('Journal endpoint has been registered') + const journallingUrl = journalReg._links['rel:events'].href + logger.info('Journal endpoint ' + journallingUrl + ' has been registered') // sleep for one min await sleep(60000) @@ -124,7 +122,7 @@ test('test publish event', async () => { }) test('test event received in journalling endpoint', async () => { - var count = 0 + let count = 0 let nextLink = journalling.link.next // retry to fetch from journalling 3 times ( 30 seconds ) while (count < 3 && journalling.retryAfter && journalling.events === undefined) { @@ -141,8 +139,7 @@ test('test event received in journalling endpoint', async () => { }) test('delete webhook registration', async () => { - await sdkClient.deleteWebhookRegistration(consumerOrgId, - integrationId, journalReg.registration_id) + await sdkClient.deleteWebhookRegistration(consumerOrgId, projectId, workspaceId, journalReg.registration_id) journalReg = undefined }) @@ -161,7 +158,7 @@ test('delete provider', async () => { afterAll(async () => { // delete webhook registration if (journalReg) { - await sdkClient.deleteWebhookRegistration(consumerOrgId, integrationId, + await sdkClient.deleteWebhookRegistration(consumerOrgId, projectId, workspaceId, journalReg.registration_id) } diff --git a/src/SDKErrors.js b/src/SDKErrors.js index dbef19d..143d8c1 100644 --- a/src/SDKErrors.js +++ b/src/SDKErrors.js @@ -57,8 +57,10 @@ E('ERROR_UPDATE_EVENTMETADATA', '%s') E('ERROR_DELETE_ALL_EVENTMETADATA', '%s') E('ERROR_DELETE_EVENTMETADATA', '%s') E('ERROR_CREATE_REGISTRATION', '%s') +E('ERROR_UPDATE_REGISTRATION', '%s') E('ERROR_GET_REGISTRATION', '%s') E('ERROR_GET_ALL_REGISTRATION', '%s') +E('ERROR_GET_ALL_REGISTRATION_FOR_ORG', '%s') E('ERROR_DELETE_REGISTRATION', '%s') E('ERROR_GET_JOURNAL_DATA', '%s') E('ERROR_PUBLISH_EVENT', '%s') diff --git a/src/index.js b/src/index.js index cc47323..9135878 100644 --- a/src/index.js +++ b/src/index.js @@ -311,61 +311,104 @@ class EventsCoreAPI { * Create a webhook or journal registration * * @param {string} consumerOrgId Consumer Org Id from the console - * @param {string} integrationId integration Id from the console + * @param {string} projectId Project Id from the console + * @param {string} workspaceId Workspace Id from the console * @param {object} body Json data contains details of the registration * @returns {Promise} Details of the webhook/journal registration created */ - createWebhookRegistration (consumerOrgId, integrationId, body) { + createWebhookRegistration (consumerOrgId, projectId, workspaceId, body) { const headers = {} const requestOptions = this.__createRequest('POST', headers, JSON.stringify(body)) - const url = this.__getUrl(`/events/organizations/${consumerOrgId}/integrations/${integrationId}/registrations`) + const url = this.__getUrl(`/events/${consumerOrgId}/${projectId}/${workspaceId}/registrations`) const sdkDetails = { requestOptions: requestOptions, url: url } return this.__handleRequest(url, requestOptions, sdkDetails, codes.ERROR_CREATE_REGISTRATION) } + /** + * Update a webhook or journal registration + * + * @param {string} consumerOrgId Consumer Org Id from the console + * @param {string} projectId Project Id from the console + * @param {string} workspaceId Workspace Id from the console + * @param {string} registrationId Registration id whose details are to be fetched + * @param {object} body Json data contains details of the registration + * @returns {Promise} Details of the webhook/journal registration to be updated + */ + updateWebhookRegistration (consumerOrgId, projectId, workspaceId, registrationId, body) { + const headers = {} + const requestOptions = this.__createRequest('POST', headers, JSON.stringify(body)) + const url = this.__getUrl(`/events/${consumerOrgId}/${projectId}/${workspaceId}/registrations/${registrationId}`) + const sdkDetails = { requestOptions: requestOptions, url: url } + return this.__handleRequest(url, requestOptions, sdkDetails, codes.ERROR_UPDATE_REGISTRATION) + } + /** * Get registration details for a given registration * * @param {string} consumerOrgId Consumer Org Id from the console - * @param {string} integrationId Integration Id from the console + * @param {string} projectId Project Id from the console + * @param {string} workspaceId Workspace Id from the console * @param {string} registrationId Registration id whose details are to be fetched * @returns {Promise} Details of the webhook/journal registration */ - getWebhookRegistration (consumerOrgId, integrationId, registrationId) { + getWebhookRegistration (consumerOrgId, projectId, workspaceId, registrationId) { const headers = {} const requestOptions = this.__createRequest('GET', headers) - const url = this.__getUrl(`/events/organizations/${consumerOrgId}/integrations/${integrationId}/registrations/${registrationId}`) + const url = this.__getUrl(`/events/${consumerOrgId}/${projectId}/${workspaceId}/registrations/${registrationId}`) const sdkDetails = { requestOptions: requestOptions, url: url } return this.__handleRequest(url, requestOptions, sdkDetails, codes.ERROR_GET_REGISTRATION) } /** - * Get all registration details for a given integration + * Get all registration details for a workspace * * @param {string} consumerOrgId Consumer Org Id from the console - * @param {string} integrationId Integration Id from the console + * @param {string} projectId Project Id from the console + * @param {string} workspaceId Workspace Id from the console * @returns {Promise} List of all webhook/journal registrations */ - getAllWebhookRegistrations (consumerOrgId, integrationId) { + getAllWebhookRegistrationsForWorkspace (consumerOrgId, projectId, workspaceId) { const headers = {} const requestOptions = this.__createRequest('GET', headers) - const url = this.__getUrl(`/events/organizations/${consumerOrgId}/integrations/${integrationId}/registrations`) + const url = this.__getUrl(`/events/${consumerOrgId}/${projectId}/${workspaceId}/registrations`) const sdkDetails = { requestOptions: requestOptions, url: url } return this.__handleRequest(url, requestOptions, sdkDetails, codes.ERROR_GET_ALL_REGISTRATION) } + /** + * @typedef {object} Page + * @property {number} [page] page number to be fetched. Default 0 (optional) + * @property {number} [size] size of each page. Default 10 (optional) + */ + /** + * Get all registration details for an org + * + * @param {string} consumerOrgId Consumer Org Id from the console + * @param {Page} [page] page size and page number + * @returns {Promise} Paginated response of all webhook/journal registrations for an org + */ + getAllWebhookRegistrationsForOrg (consumerOrgId, page) { + const headers = {} + const requestOptions = this.__createRequest('GET', headers) + const url = this.__getUrl(`/events/${consumerOrgId}/registrations`) + const urlWithQueryParams = helpers.appendQueryParams(url, page) + const sdkDetails = { requestOptions: requestOptions, url: urlWithQueryParams } + return this.__handleRequest(url, requestOptions, sdkDetails, codes.ERROR_GET_ALL_REGISTRATION_FOR_ORG) + } + /** * Delete webhook registration * * @param {string} consumerOrgId Consumer Org Id from the console - * @param {string} integrationId Integration Id from the console + * @param {string} projectId Project Id from the console + * @param {string} workspaceId Workspace Id from the console * @param {string} registrationId Id of the registration to be deleted * @returns {Promise} Empty object if deletion was successful */ - deleteWebhookRegistration (consumerOrgId, integrationId, registrationId) { + deleteWebhookRegistration (consumerOrgId, projectId, workspaceId, registrationId) { const headers = {} const requestOptions = this.__createRequest('DELETE', headers) - const url = this.__getUrl(`/events/organizations/${consumerOrgId}/integrations/${integrationId}/registrations/${registrationId}`) + const url = this.__getUrl(`/events/${consumerOrgId}/${projectId}/${workspaceId}/registrations/${registrationId}`) const sdkDetails = { requestOptions: requestOptions, url: url } return this.__handleRequest(url, requestOptions, sdkDetails, codes.ERROR_DELETE_REGISTRATION) } diff --git a/test/index.test.js b/test/index.test.js index 3153ed2..cb277de 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -123,7 +123,7 @@ describe('test get all providers', () => { it('Success on get all providers', async () => { const sdkClient = await createSdkClient() exponentialBackoffMockReturnValue(mock.data.getAllProvidersResponse, { status: 200, statusText: 'OK' }) - const res = await sdkClient.getAllProviders('consumerOrgId') + const res = await sdkClient.getAllProviders('consumerId') expect(res._embedded.providers.length).toBe(2) expect(res._embedded.providers[0].id).toBe('test-id-1') expect(res._embedded.providers[1].id).toBe('test-id-2') @@ -131,7 +131,7 @@ describe('test get all providers', () => { it('Not found error on get all providers ', async () => { const api = 'getAllProviders' exponentialBackoffMockReturnValue({}, { status: 404, statusText: 'Not Found' }) - await checkErrorResponse(api, new errorSDK.codes.ERROR_GET_ALL_PROVIDERS(), ['consumerOrgId1']) + await checkErrorResponse(api, new errorSDK.codes.ERROR_GET_ALL_PROVIDERS(), ['consumerId1']) }) }) @@ -171,7 +171,7 @@ describe('test create new provider', () => { const sdkClient = await createSdkClient() exponentialBackoffMockReturnValue(mock.data.providerResponse, { status: 200, statusText: 'OK' }) - const res = await sdkClient.createProvider('consumerOrgId', 'projectId', + const res = await sdkClient.createProvider('consumerId', 'projectId', 'workspaceId', mock.data.createProvider) expect(res.id).toBe('test-id') }) @@ -179,7 +179,7 @@ describe('test create new provider', () => { const api = 'createProvider' exponentialBackoffMockReturnValue({}, { status: 400, statusText: 'Bad Request' }) await checkErrorResponse(api, new errorSDK.codes.ERROR_CREATE_PROVIDER(), - ['consumerOrgId', 'projectId', 'workspaceId', mock.data.createProviderBadRequest]) + ['consumerId', 'projectId', 'workspaceId', mock.data.createProviderBadRequest]) }) }) @@ -188,7 +188,7 @@ describe('test update provider', () => { const sdkClient = await createSdkClient() exponentialBackoffMockReturnValue(mock.data.updateProviderResponse, { status: 200, statusText: 'OK' }) - const res = await sdkClient.updateProvider('consumerOrgId', 'projectId', + const res = await sdkClient.updateProvider('consumerId', 'projectId', 'workspaceId', 'test-id', mock.data.updateProvider) expect(res.id).toBe('test-id') expect(res.label).toBe('Test provider 2') @@ -197,7 +197,7 @@ describe('test update provider', () => { const api = 'updateProvider' exponentialBackoffMockReturnValue({}, { status: 400, statusText: 'Bad Request' }) checkErrorResponse(api, new errorSDK.codes.ERROR_UPDATE_PROVIDER(), - ['consumerOrgId', 'projectId', 'workspaceId', 'test-id', + ['consumerId', 'projectId', 'workspaceId', 'test-id', mock.data.updateProviderBadRequest]) }) }) @@ -206,7 +206,7 @@ describe('test delete provider', () => { it('Success on delete provider', async () => { const sdkClient = await createSdkClient() exponentialBackoffMockReturnValue(undefined, { status: 204, statusText: 'No Content' }) - const res = await sdkClient.deleteProvider('consumerOrgId', 'projectId', + const res = await sdkClient.deleteProvider('consumerId', 'projectId', 'workspaceId', 'test-id') expect(res).toBe(undefined) }) @@ -214,7 +214,7 @@ describe('test delete provider', () => { const api = 'deleteProvider' exponentialBackoffMockReturnValue({}, { status: 404, statusText: 'Not Found' }) checkErrorResponse(api, new errorSDK.codes.ERROR_DELETE_PROVIDER(), - ['consumerOrgId', 'projectId', 'workspaceId', 'test-id1']) + ['consumerId', 'projectId', 'workspaceId', 'test-id1']) }) }) @@ -261,7 +261,7 @@ describe('Create event metadata for provider', () => { const sdkClient = await createSdkClient() exponentialBackoffMockReturnValue(mock.data.createEventMetadataForProviderResponse, { status: 200, statusText: 'OK' }) - const res = await sdkClient.createEventMetadataForProvider('consumerOrgId', + const res = await sdkClient.createEventMetadataForProvider('consumerId', 'projectId', 'workspaceId', 'test-id', mock.data.createEventMetadataForProvider) expect(res.event_code).toBe('com.adobe.event_code_1') @@ -273,7 +273,7 @@ describe('Create event metadata for provider', () => { exponentialBackoffMockReturnValue({}, { status: 404, statusText: 'Not Found' }) checkErrorResponse(api, new errorSDK.codes.ERROR_CREATE_EVENTMETADATA(), - ['consumerOrgId', 'projectId', 'workspaceId', 'test-id', + ['consumerId', 'projectId', 'workspaceId', 'test-id', mock.data.createEventMetadataBadRequest]) }) }) @@ -283,7 +283,7 @@ describe('Update event metadata for provider', () => { const sdkClient = await createSdkClient() exponentialBackoffMockReturnValue(mock.data.createEventMetadataForProviderResponse, { status: 200, statusText: 'OK' }) - const res = await sdkClient.updateEventMetadataForProvider('consumerOrgId', + const res = await sdkClient.updateEventMetadataForProvider('consumerId', 'projectId', 'workspaceId', 'test-id', 'event_code_1', mock.data.createEventMetadataForProvider) expect(res.event_code).toBe('com.adobe.event_code_1') @@ -295,7 +295,7 @@ describe('Update event metadata for provider', () => { exponentialBackoffMockReturnValue({}, { status: 400, statusText: 'Bad Request' }) checkErrorResponse(api, new errorSDK.codes.ERROR_UPDATE_EVENTMETADATA(), - ['consumerOrgId', 'projectId', 'workspaceId', 'test-id', 'event_code_1', + ['consumerId', 'projectId', 'workspaceId', 'test-id', 'event_code_1', mock.data.createEventMetadataBadRequest]) }) }) @@ -304,7 +304,7 @@ describe('Delete eventmetadata', () => { it('Success on delete eventmetadata', async () => { const sdkClient = await createSdkClient() exponentialBackoffMockReturnValue(undefined, { status: 204, statusText: 'No Content' }) - const res = await sdkClient.deleteEventMetadata('consumerOrgId', 'projectId', + const res = await sdkClient.deleteEventMetadata('consumerId', 'projectId', 'workspaceId', 'test-id', 'event_code_1') expect(res).toBe(undefined) }) @@ -313,7 +313,7 @@ describe('Delete eventmetadata', () => { exponentialBackoffMockReturnValue({}, { status: 404, statusText: 'Not Found' }) checkErrorResponse(api, new errorSDK.codes.ERROR_DELETE_EVENTMETADATA(), - ['consumerOrgId', 'projectId', 'workspaceId', 'test-id', 'event_code_2']) + ['consumerId', 'projectId', 'workspaceId', 'test-id', 'event_code_2']) }) }) @@ -321,7 +321,7 @@ describe('Delete all eventmetadata', () => { it('Success on delete all eventmetadata', async () => { const sdkClient = await createSdkClient() exponentialBackoffMockReturnValue(undefined, { status: 204, statusText: 'No Content' }) - const res = await sdkClient.deleteAllEventMetadata('consumerOrgId', 'projectId', + const res = await sdkClient.deleteAllEventMetadata('consumerId', 'projectId', 'workspaceId', 'test-id') expect(res).toBe(undefined) }) @@ -330,7 +330,7 @@ describe('Delete all eventmetadata', () => { exponentialBackoffMockReturnValue({}, { status: 404, statusText: 'Not Found' }) checkErrorResponse(api, new errorSDK.codes.ERROR_DELETE_ALL_EVENTMETADATA(), - ['consumerOrgId', 'projectId', 'workspaceId', 'test-id']) + ['consumerId', 'projectId', 'workspaceId', 'test-id']) }) }) @@ -338,14 +338,32 @@ describe('Create webhook registration', () => { it('Success on create webhook registration', async () => { const sdkClient = await createSdkClient() exponentialBackoffMockReturnValue(mock.data.createWebhookRegistrationResponse, { status: 200, statusText: 'OK' }) - const res = await sdkClient.createWebhookRegistration('consumerOrgId', 'integrationId', mock.data.createWebhookRegistration) + const res = await sdkClient.createWebhookRegistration('consumerId', 'projectId', 'workspaceId', mock.data.createWebhookRegistration) expect(res.id).toBe(248723) - expect(res.status).toBe('VERIFIED') + expect(res.webhook_status).toBe('verified') + expect(res.enabled).toBe(true) }) it('Bad request error on create webhook registration', async () => { const api = 'createWebhookRegistration' exponentialBackoffMockReturnValue({}, { status: 400, statusText: 'Bad Request' }) - await checkErrorResponse(api, new errorSDK.codes.ERROR_CREATE_REGISTRATION(), ['consumerOrgId', 'integrationId', mock.data.createWebhookRegistrationBadRequest]) + await checkErrorResponse(api, new errorSDK.codes.ERROR_CREATE_REGISTRATION(), ['consumerId', 'projectId', 'workspaceId', mock.data.createWebhookRegistrationBadRequest]) + }) +}) + +describe('Update webhook registration', () => { + it('Success on update webhook registration', async () => { + const sdkClient = await createSdkClient() + exponentialBackoffMockReturnValue(mock.data.updateWebhookRegistrationResponse, { status: 200, statusText: 'OK' }) + const res = await sdkClient.updateWebhookRegistration('consumerId', 'projectId', 'workspaceId', 'registrationId', mock.data.updateWebhookRegistration) + expect(res.id).toBe(248723) + expect(res.webhook_status).toBe('verified') + expect(res.delivery_type).toBe('webhook_batch') + expect(res.enabled).toBe(true) + }) + it('Bad request error on update webhook registration', async () => { + const api = 'updateWebhookRegistration' + exponentialBackoffMockReturnValue({}, { status: 400, statusText: 'Bad Request' }) + await checkErrorResponse(api, new errorSDK.codes.ERROR_UPDATE_REGISTRATION(), ['consumerId', 'projectId', 'workspaceId', 'registrationId', mock.data.createWebhookRegistrationBadRequest]) }) }) @@ -353,15 +371,18 @@ describe('Get all webhook registration', () => { it('Success on get all webhook registration', async () => { const sdkClient = await createSdkClient() exponentialBackoffMockReturnValue(mock.data.getAllWebhookRegistrationsResponse, { status: 200, statusText: 'OK' }) - const res = await sdkClient.getAllWebhookRegistrations('consumerOrgId', 'integrationId') - expect(res.length).toBe(2) - expect(res[0].id).toBe(1) - expect(res[1].status).toBe('VERIFIED') + const res = await sdkClient.getAllWebhookRegistrationsForWorkspace('consumerId', 'projectId', 'workspaceId') + expect(res._embedded.registrations.length).toBe(3) + const regs = res._embedded.registrations + expect(res._links.self.href).toBe('https://api.adobe.io/consumerId/projectId/workspaceId/registrations') + expect(regs[0].id).toBe(30000) + expect(regs[1].webhook_status).toBe('hook_unreachable') + expect(regs[2].delivery_type).toBe('journal') }) it('Not found error on get all webhook registration', async () => { - const api = 'getAllWebhookRegistrations' + const api = 'getAllWebhookRegistrationsForWorkspace' exponentialBackoffMockReturnValue({}, { status: 404, statusText: 'Not Found' }) - await checkErrorResponse(api, new errorSDK.codes.ERROR_GET_ALL_REGISTRATION(), ['consumerOrgId', 'integrationId-1']) + await checkErrorResponse(api, new errorSDK.codes.ERROR_GET_ALL_REGISTRATION(), ['consumerId', 'project-1', 'workspace-1']) }) }) @@ -369,14 +390,16 @@ describe('Get a webhook registration', () => { it('Success on get a webhook registration', async () => { const sdkClient = await createSdkClient() exponentialBackoffMockReturnValue(mock.data.createWebhookRegistrationResponse, { status: 200, statusText: 'OK' }) - const res = await sdkClient.getWebhookRegistration('consumerOrgId', 'integrationId', 'registration-id') + const res = await sdkClient.getWebhookRegistration('consumerId', 'projectId', 'workspaceId', 'registrationId') + expect(res._links.self.href).toBe('https://api.adobe.io/events/consumerId/projectId/workspaceId/registrations/registrationId') expect(res.id).toBe(248723) - expect(res.status).toBe('VERIFIED') + expect(res.webhook_status).toBe('verified') + expect(res.enabled).toBe(true) }) it('Not found error on get a webhook registration', async () => { const api = 'getWebhookRegistration' exponentialBackoffMockReturnValue({}, { status: 404, statusText: 'Not Found' }) - await checkErrorResponse(api, new errorSDK.codes.ERROR_GET_REGISTRATION(), ['consumerOrgId', 'integrationId', 'registration-id-1']) + await checkErrorResponse(api, new errorSDK.codes.ERROR_GET_REGISTRATION(), ['consumerId', 'projectId', 'workspaceId', 'registrationId-1']) }) }) @@ -385,7 +408,7 @@ describe('Get webhook registration with retries', () => { const sdkClient = await sdk.init(gOrganizationId, gApiKey, gAccessToken, { retries: 3 }) const error = new errorSDK.codes.ERROR_GET_REGISTRATION() exponentialBackoffMockReturnValue({}, { status: 500, statusText: 'Internal Server Error', url: journalUrl }) - await sdkClient.getWebhookRegistration('consumerOrgId', 'integrationId', 'registration-id') + await sdkClient.getWebhookRegistration('consumerId', 'projectId', 'workspaceId', 'registrationId') .then(res => { throw new Error(' No error response') }) @@ -394,7 +417,7 @@ describe('Get webhook registration with retries', () => { expect(e.code).toEqual(error.code) }) expect(fetchRetry.exponentialBackoff).toHaveBeenCalledWith( - 'https://api.adobe.io/events/organizations/consumerOrgId/integrations/integrationId/registrations/registration-id', + 'https://api.adobe.io/events/consumerId/projectId/workspaceId/registrations/registrationId', { body: undefined, headers: { @@ -413,7 +436,7 @@ describe('test delete webhook registration', () => { it('Success on delete registration', async () => { const sdkClient = await createSdkClient() exponentialBackoffMockReturnValue(undefined, { status: 204, statusText: 'No Content' }) - const res = await sdkClient.deleteWebhookRegistration('consumerOrgId', 'integrationId', + const res = await sdkClient.deleteWebhookRegistration('consumerId', 'projectId', 'workspaceId', 'registrationId') expect(res).toBe(undefined) }) @@ -421,7 +444,7 @@ describe('test delete webhook registration', () => { const api = 'deleteWebhookRegistration' exponentialBackoffMockReturnValue({}, { status: 404, statusText: 'Not Found' }) checkErrorResponse(api, new errorSDK.codes.ERROR_DELETE_REGISTRATION(), - ['consumerOrgId', 'integrationId', 'registrationId1']) + ['consumerId', 'integrationId', 'registrationId1']) }) }) diff --git a/test/mock.js b/test/mock.js index 30e64e3..26f68d3 100644 --- a/test/mock.js +++ b/test/mock.js @@ -239,29 +239,39 @@ const getEventMetadataResponse = { event_code: 'com.adobe.event_code_1' } -const createEventMetadataBadRequest = -{ +const createEventMetadataBadRequest = { label: 'test event code 1', description: 'Test for SDK 1' } -const createWebhookRegistration = -{ +const createWebhookRegistration = { name: 'name', description: 'description', client_id: 'test-apikey', webhook_url: 'https://test-webhook', - delivery_type: 'WEBHOOK', + delivery_type: 'webhook', events_of_interest: [ { event_code: 'event_code_1', - provider: 'provider_1' + provider_id: 'provider_id_1' + } + ] +} + +const updateWebhookRegistration = { + name: 'name', + description: 'description', + webhook_url: 'https://test-webhook', + delivery_type: 'webhook_batch', + events_of_interest: [ + { + event_code: 'event_code_1', + provider_id: 'provider_id_1' } ] } -const createWebhookRegistrationBadRequest = -{ +const createWebhookRegistrationBadRequest = { name: 'name', description: 'description', client_id: 'test-apikey', @@ -275,15 +285,61 @@ const createWebhookRegistrationBadRequest = } const createWebhookRegistrationResponse = { + _links: { + 'rel:events': { + href: 'https://events-va6.adobe.io/events/organizations/consumerId/integrations/integrationId/registrationId' + }, + 'rel:trace': { + href: 'https://eventtraces-va6.adobe.io/traces/consumerId/projectId/workspaceId/registration/registrationId' + }, + self: { + href: 'https://api.adobe.io/events/consumerId/projectId/workspaceId/registrations/registrationId' + } + }, id: 248723, name: 'name', description: 'description', client_id: 'test-apikey', - parent_client_id: 'test-apikey', + registration_id: 'registrationId', + events_of_interest: [ + { + event_code: 'event_code_1', + event_label: 'event_label', + event_description: 'event_description', + provider_id: 'provider_id', + provider: 'provider_1', + provider_label: 'label', + event_delivery_format: 'cloud_events' + } + ], + webhook_status: 'verified', + created_date: '2022-02-21T08:45:16.446Z', + updated_date: '2022-02-21T08:45:16.446Z', + consumer_id: 'consumerId', + project_id: 'projectId', + workspace_id: 'workspaceId', webhook_url: 'https://test-webhook', - status: 'VERIFIED', - type: 'APP', - integration_status: 'ENABLED', + delivery_type: 'webhook', + enabled: true +} + +const updateWebhookRegistrationResponse = { + _links: { + 'rel:events': { + href: 'https://events-va6.adobe.io/events/organizations/consumerId/integrations/integrationId/registrationId' + }, + 'rel:trace': { + href: 'https://eventtraces-va6.adobe.io/traces/consumerId/projectId/workspaceId/registration/registrationId' + }, + self: { + href: 'https://api.adobe.io/events/consumerId/projectId/workspaceId/registrations/registrationId' + } + }, + id: 248723, + name: 'name_updated', + description: 'description_updated', + client_id: 'test-apikey', + registration_id: 'registrationId', events_of_interest: [ { event_code: 'event_code_1', @@ -295,72 +351,138 @@ const createWebhookRegistrationResponse = { event_delivery_format: 'cloud_events' } ], - registration_id: 'registration_id', - delivery_type: 'WEBHOOK', - events_url: 'journal_url', - created_date: '2020-02-21T08:45:16.446Z', - updated_date: '2020-02-21T08:45:16.446Z', - runtime_action: '' -} - -const getAllWebhookRegistrationsResponse = [ - { - id: 1, - name: 'name', - description: 'description', - client_id: 'test-apikey', - parent_client_id: 'test-apikey', - webhook_url: 'https://test-webhook', - status: 'VERIFIED', - type: 'APP', - integration_status: 'ENABLED', - events_of_interest: [ - { - event_code: 'event_code_1', - event_label: 'event_label', - event_description: 'event_description', - provider_id: 'provider_id', - provider: 'provider_1', - provider_label: 'label', - event_delivery_format: 'cloud_events' - } - ], - registration_id: 'registration_id', - delivery_type: 'WEBHOOK', - events_url: 'journal_url', - created_date: '2020-02-21T08:45:16.446Z', - updated_date: '2020-02-21T08:45:16.446Z', - runtime_action: '' + webhook_status: 'verified', + created_date: '2022-02-21T08:45:16.446Z', + updated_date: '2022-02-21T08:45:16.446Z', + consumer_id: 'consumerId', + project_id: 'projectId', + workspace_id: 'workspaceId', + webhook_url: 'https://test-webhook', + delivery_type: 'webhook_batch', + enabled: true +} + +const getAllWebhookRegistrationsResponse = { + _links: { + self: { + href: 'https://api.adobe.io/consumerId/projectId/workspaceId/registrations' + } }, - { - id: 2, - name: 'name 2', - description: 'description 2', - client_id: 'test-apikey', - parent_client_id: 'test-apikey', - webhook_url: 'https://test-webhook-2', - status: 'VERIFIED', - type: 'APP', - integration_status: 'ENABLED', - events_of_interest: [ + _embedded: { + registrations: [ + { + _links: { + 'rel:events': { + href: 'https://events-stage-va6.adobe.io/events/organizations/consumerId/integrations/integrationId/registrationId1' + }, + 'rel:trace': { + href: 'https://eventtraces-stage-va6.adobe.io/traces/consumerId/projectId/workspaceId/registration/registrationId1' + }, + self: { + href: 'https://api.adobe.io/consumerId/projectId/workspaceId/registrations/registrationId1' + } + }, + id: 30000, + name: 'test name 1', + description: 'test description 1', + client_id: 'test-apikey', + registration_id: 'registrationId1', + events_of_interest: [ + { + event_code: 'event_code_1', + event_label: 'event_label', + event_description: 'event_description', + provider_id: 'provider_id', + provider_label: 'label', + event_delivery_format: 'adobe_io' + } + ], + webhook_status: 'verified', + created_date: '2022-06-13T16:31:57.000Z', + updated_date: '2022-09-19T05:46:36.000Z', + consumer_id: 'consumerId', + project_id: 'projectId', + workspace_id: 'workspaceId', + webhook_url: 'https://test-webhook-1', + delivery_type: 'webhook', + enabled: true + }, { - event_code: 'event_code_2', - event_label: 'event_label 2', - event_description: 'event_description 2', - provider_id: 'provider_id', - provider: 'provider_1', - provider_label: 'label 2', - event_delivery_format: 'cloud_events' + _links: { + 'rel:events': { + href: 'https://events-stage-va6.adobe.io/events/organizations/consumerId/integrations/integrationId/registrationId2' + }, + 'rel:trace': { + href: 'https://eventtraces-stage-va6.adobe.io/traces/consumerId/projectId/workspaceId/registration/registrationId2' + }, + self: { + href: 'https://csm-stage.adobe.io/consumerId/projectId/workspaceId/registrations/registrationId2' + } + }, + id: 30001, + name: 'test name 2', + description: 'test description 2', + client_id: 'test-apikey', + registration_id: 'registrationId2', + events_of_interest: [ + { + event_code: 'event_code_2', + event_label: 'event_label_2', + event_description: 'event_description_2', + provider_id: 'provider_id_2', + provider_label: 'label', + event_delivery_format: 'adobe_io' + } + ], + webhook_status: 'hook_unreachable', + created_date: '2022-06-13T16:31:57.000Z', + updated_date: '2022-09-19T05:46:36.000Z', + consumer_id: 'consumerId', + project_id: 'projectId', + workspace_id: 'workspaceId', + webhook_url: 'https://test-webhook-2', + delivery_type: 'webhook_batch', + enabled: false + }, + { + _links: { + 'rel:events': { + href: 'https://events-stage-va6.adobe.io/events/organizations/consumerId/integrations/integrationId/registrationId3' + }, + 'rel:trace': { + href: 'https://eventtraces-stage-va6.adobe.io/traces/consumerId/projectId/workspaceId/registration/registrationId3' + }, + self: { + href: 'https://csm-stage.adobe.io/consumerId/projectId/workspaceId/registrations/registrationId3' + } + }, + id: 30002, + name: 'test name 3', + description: 'test description 3', + client_id: 'test-apikey', + registration_id: 'registrationId3', + events_of_interest: [ + { + event_code: 'event_code_3', + event_label: 'event_label_3', + event_description: 'event_description_3', + provider_id: 'provider_id_3', + provider_label: 'label', + event_delivery_format: 'adobe_io' + } + ], + webhook_status: 'verified', + created_date: '2022-06-13T16:31:57.000Z', + updated_date: '2022-09-19T05:46:36.000Z', + consumer_id: 'consumerId', + project_id: 'projectId', + workspace_id: 'workspaceId', + delivery_type: 'journal', + enabled: true } - ], - registration_id: 'registration_id_2', - delivery_type: 'WEBHOOK', - events_url: 'journal_url_2', - created_date: '2020-02-21T08:45:16.446Z', - updated_date: '2020-02-21T08:45:16.446Z', - runtime_action: '' + ] } -] +} const cloudEvent = { id: 'test-id', @@ -583,6 +705,8 @@ const data = { createWebhookRegistration: createWebhookRegistration, createWebhookRegistrationResponse: createWebhookRegistrationResponse, createWebhookRegistrationBadRequest: createWebhookRegistrationBadRequest, + updateWebhookRegistrationResponse: updateWebhookRegistrationResponse, + updateWebhookRegistration: updateWebhookRegistration, getAllWebhookRegistrationsResponse: getAllWebhookRegistrationsResponse, cloudEvent: cloudEvent, cloudEventEmptyPayload: cloudEventEmptyPayload, From c57dbdc8ab239de09e3ca70fb33cdd51e9445952 Mon Sep 17 00:00:00 2001 From: Sangeetha Krishnan Date: Mon, 26 Sep 2022 23:50:25 +0530 Subject: [PATCH 2/9] remove from registration method names and add unit tests --- e2e/e2e.js | 6 +- src/index.js | 12 ++-- test/index.test.js | 84 +++++++++++++++++----------- test/mock.js | 134 ++++++++++++++++++++++++++++++++++++++++----- 4 files changed, 181 insertions(+), 55 deletions(-) diff --git a/e2e/e2e.js b/e2e/e2e.js index 6d6c5c9..9fceceb 100644 --- a/e2e/e2e.js +++ b/e2e/e2e.js @@ -76,7 +76,7 @@ test('test create event metadata', async () => { test('test register journalling endpoint', async () => { // create journal registration - journalReg = await sdkClient.createWebhookRegistration(consumerOrgId, projectId, workspaceId, { + journalReg = await sdkClient.createRegistration(consumerOrgId, projectId, workspaceId, { name: 'Test Events SDK ' + randomNumber, description: 'Test Events SDK ' + randomNumber, client_id: apiKey, @@ -139,7 +139,7 @@ test('test event received in journalling endpoint', async () => { }) test('delete webhook registration', async () => { - await sdkClient.deleteWebhookRegistration(consumerOrgId, projectId, workspaceId, journalReg.registration_id) + await sdkClient.deleteRegistration(consumerOrgId, projectId, workspaceId, journalReg.registration_id) journalReg = undefined }) @@ -158,7 +158,7 @@ test('delete provider', async () => { afterAll(async () => { // delete webhook registration if (journalReg) { - await sdkClient.deleteWebhookRegistration(consumerOrgId, projectId, workspaceId, + await sdkClient.deleteRegistration(consumerOrgId, projectId, workspaceId, journalReg.registration_id) } diff --git a/src/index.js b/src/index.js index 9135878..8858daa 100644 --- a/src/index.js +++ b/src/index.js @@ -316,7 +316,7 @@ class EventsCoreAPI { * @param {object} body Json data contains details of the registration * @returns {Promise} Details of the webhook/journal registration created */ - createWebhookRegistration (consumerOrgId, projectId, workspaceId, body) { + createRegistration (consumerOrgId, projectId, workspaceId, body) { const headers = {} const requestOptions = this.__createRequest('POST', headers, JSON.stringify(body)) const url = this.__getUrl(`/events/${consumerOrgId}/${projectId}/${workspaceId}/registrations`) @@ -334,7 +334,7 @@ class EventsCoreAPI { * @param {object} body Json data contains details of the registration * @returns {Promise} Details of the webhook/journal registration to be updated */ - updateWebhookRegistration (consumerOrgId, projectId, workspaceId, registrationId, body) { + updateRegistration (consumerOrgId, projectId, workspaceId, registrationId, body) { const headers = {} const requestOptions = this.__createRequest('POST', headers, JSON.stringify(body)) const url = this.__getUrl(`/events/${consumerOrgId}/${projectId}/${workspaceId}/registrations/${registrationId}`) @@ -351,7 +351,7 @@ class EventsCoreAPI { * @param {string} registrationId Registration id whose details are to be fetched * @returns {Promise} Details of the webhook/journal registration */ - getWebhookRegistration (consumerOrgId, projectId, workspaceId, registrationId) { + getRegistration (consumerOrgId, projectId, workspaceId, registrationId) { const headers = {} const requestOptions = this.__createRequest('GET', headers) const url = this.__getUrl(`/events/${consumerOrgId}/${projectId}/${workspaceId}/registrations/${registrationId}`) @@ -367,7 +367,7 @@ class EventsCoreAPI { * @param {string} workspaceId Workspace Id from the console * @returns {Promise} List of all webhook/journal registrations */ - getAllWebhookRegistrationsForWorkspace (consumerOrgId, projectId, workspaceId) { + getAllRegistrationsForWorkspace (consumerOrgId, projectId, workspaceId) { const headers = {} const requestOptions = this.__createRequest('GET', headers) const url = this.__getUrl(`/events/${consumerOrgId}/${projectId}/${workspaceId}/registrations`) @@ -387,7 +387,7 @@ class EventsCoreAPI { * @param {Page} [page] page size and page number * @returns {Promise} Paginated response of all webhook/journal registrations for an org */ - getAllWebhookRegistrationsForOrg (consumerOrgId, page) { + getAllRegistrationsForOrg (consumerOrgId, page) { const headers = {} const requestOptions = this.__createRequest('GET', headers) const url = this.__getUrl(`/events/${consumerOrgId}/registrations`) @@ -405,7 +405,7 @@ class EventsCoreAPI { * @param {string} registrationId Id of the registration to be deleted * @returns {Promise} Empty object if deletion was successful */ - deleteWebhookRegistration (consumerOrgId, projectId, workspaceId, registrationId) { + deleteRegistration (consumerOrgId, projectId, workspaceId, registrationId) { const headers = {} const requestOptions = this.__createRequest('DELETE', headers) const url = this.__getUrl(`/events/${consumerOrgId}/${projectId}/${workspaceId}/registrations/${registrationId}`) diff --git a/test/index.test.js b/test/index.test.js index cb277de..fb33d91 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -334,81 +334,101 @@ describe('Delete all eventmetadata', () => { }) }) -describe('Create webhook registration', () => { - it('Success on create webhook registration', async () => { +describe('Create registration', () => { + it('Success on create registration', async () => { const sdkClient = await createSdkClient() - exponentialBackoffMockReturnValue(mock.data.createWebhookRegistrationResponse, { status: 200, statusText: 'OK' }) - const res = await sdkClient.createWebhookRegistration('consumerId', 'projectId', 'workspaceId', mock.data.createWebhookRegistration) + exponentialBackoffMockReturnValue(mock.data.createRegistrationResponse, { status: 200, statusText: 'OK' }) + const res = await sdkClient.createRegistration('consumerId', 'projectId', 'workspaceId', mock.data.createRegistration) expect(res.id).toBe(248723) expect(res.webhook_status).toBe('verified') expect(res.enabled).toBe(true) }) - it('Bad request error on create webhook registration', async () => { - const api = 'createWebhookRegistration' + it('Bad request error on create registration', async () => { + const api = 'createRegistration' exponentialBackoffMockReturnValue({}, { status: 400, statusText: 'Bad Request' }) - await checkErrorResponse(api, new errorSDK.codes.ERROR_CREATE_REGISTRATION(), ['consumerId', 'projectId', 'workspaceId', mock.data.createWebhookRegistrationBadRequest]) + await checkErrorResponse(api, new errorSDK.codes.ERROR_CREATE_REGISTRATION(), ['consumerId', 'projectId', 'workspaceId', mock.data.createRegistrationBadRequest]) }) }) -describe('Update webhook registration', () => { - it('Success on update webhook registration', async () => { +describe('Update registration', () => { + it('Success on update registration', async () => { const sdkClient = await createSdkClient() - exponentialBackoffMockReturnValue(mock.data.updateWebhookRegistrationResponse, { status: 200, statusText: 'OK' }) - const res = await sdkClient.updateWebhookRegistration('consumerId', 'projectId', 'workspaceId', 'registrationId', mock.data.updateWebhookRegistration) + exponentialBackoffMockReturnValue(mock.data.updateRegistrationResponse, { status: 200, statusText: 'OK' }) + const res = await sdkClient.updateRegistration('consumerId', 'projectId', 'workspaceId', 'registrationId', mock.data.updateRegistration) expect(res.id).toBe(248723) expect(res.webhook_status).toBe('verified') expect(res.delivery_type).toBe('webhook_batch') expect(res.enabled).toBe(true) }) - it('Bad request error on update webhook registration', async () => { - const api = 'updateWebhookRegistration' + it('Bad request error on update registration', async () => { + const api = 'updateRegistration' exponentialBackoffMockReturnValue({}, { status: 400, statusText: 'Bad Request' }) - await checkErrorResponse(api, new errorSDK.codes.ERROR_UPDATE_REGISTRATION(), ['consumerId', 'projectId', 'workspaceId', 'registrationId', mock.data.createWebhookRegistrationBadRequest]) + await checkErrorResponse(api, new errorSDK.codes.ERROR_UPDATE_REGISTRATION(), ['consumerId', 'projectId', 'workspaceId', 'registrationId', mock.data.createRegistrationBadRequest]) }) }) -describe('Get all webhook registration', () => { - it('Success on get all webhook registration', async () => { +describe('Get all registration', () => { + it('Success on get all registration', async () => { const sdkClient = await createSdkClient() - exponentialBackoffMockReturnValue(mock.data.getAllWebhookRegistrationsResponse, { status: 200, statusText: 'OK' }) - const res = await sdkClient.getAllWebhookRegistrationsForWorkspace('consumerId', 'projectId', 'workspaceId') + exponentialBackoffMockReturnValue(mock.data.getAllRegistrationsResponse, { status: 200, statusText: 'OK' }) + const res = await sdkClient.getAllRegistrationsForWorkspace('consumerId', 'projectId', 'workspaceId') expect(res._embedded.registrations.length).toBe(3) const regs = res._embedded.registrations - expect(res._links.self.href).toBe('https://api.adobe.io/consumerId/projectId/workspaceId/registrations') + expect(res._links.self.href).toBe('https://api.adobe.io/events/consumerId/projectId/workspaceId/registrations') expect(regs[0].id).toBe(30000) expect(regs[1].webhook_status).toBe('hook_unreachable') expect(regs[2].delivery_type).toBe('journal') }) - it('Not found error on get all webhook registration', async () => { - const api = 'getAllWebhookRegistrationsForWorkspace' + it('Not found error on get all registration', async () => { + const api = 'getAllRegistrationsForWorkspace' exponentialBackoffMockReturnValue({}, { status: 404, statusText: 'Not Found' }) await checkErrorResponse(api, new errorSDK.codes.ERROR_GET_ALL_REGISTRATION(), ['consumerId', 'project-1', 'workspace-1']) }) }) -describe('Get a webhook registration', () => { - it('Success on get a webhook registration', async () => { +describe('Get a registration', () => { + it('Success on get a registration', async () => { const sdkClient = await createSdkClient() - exponentialBackoffMockReturnValue(mock.data.createWebhookRegistrationResponse, { status: 200, statusText: 'OK' }) - const res = await sdkClient.getWebhookRegistration('consumerId', 'projectId', 'workspaceId', 'registrationId') + exponentialBackoffMockReturnValue(mock.data.createRegistrationResponse, { status: 200, statusText: 'OK' }) + const res = await sdkClient.getRegistration('consumerId', 'projectId', 'workspaceId', 'registrationId') expect(res._links.self.href).toBe('https://api.adobe.io/events/consumerId/projectId/workspaceId/registrations/registrationId') expect(res.id).toBe(248723) expect(res.webhook_status).toBe('verified') expect(res.enabled).toBe(true) }) - it('Not found error on get a webhook registration', async () => { - const api = 'getWebhookRegistration' + it('Not found error on get a registration', async () => { + const api = 'getRegistration' exponentialBackoffMockReturnValue({}, { status: 404, statusText: 'Not Found' }) await checkErrorResponse(api, new errorSDK.codes.ERROR_GET_REGISTRATION(), ['consumerId', 'projectId', 'workspaceId', 'registrationId-1']) }) }) -describe('Get webhook registration with retries', () => { +describe('Get all registrations for org', () => { + it('Success on get all registrations for org', async () => { + const sdkClient = await createSdkClient() + exponentialBackoffMockReturnValue(mock.data.getAllRegistrationsForOrgResponse, { status: 200, statusText: 'OK' }) + const res = await sdkClient.getAllRegistrationsForOrg('consumerId', { page: 1, size: 2 }) + expect(res._links.self.href).toBe('https://api.adobe.io/events/consumerId/registrations?page=1&size=2') + expect(res._links.first.href).toBe('https://api.adobe.io/events/consumerId/registrations?page=0&size=2') + expect(res._links.last.href).toBe('https://api.adobe.io/events/consumerId/registrations?page=19&size=2') + expect(res._links.prev.href).toBe('https://api.adobe.io/events/consumerId/registrations?page=0&size=2') + expect(res._embedded.registrations.length).toBe(2) + expect(res.page.numberOfElements).toBe(2) + expect(res.page.totalElements).toBe(19) + }) + it('Not found error on get a registration', async () => { + const api = 'getAllRegistrationsForOrg' + exponentialBackoffMockReturnValue({}, { status: 404, statusText: 'Not Found' }) + await checkErrorResponse(api, new errorSDK.codes.ERROR_GET_ALL_REGISTRATION_FOR_ORG(), ['consumerId-2']) + }) +}) + +describe('Get registration with retries', () => { it('Test for retries on 5xx response', async () => { const sdkClient = await sdk.init(gOrganizationId, gApiKey, gAccessToken, { retries: 3 }) const error = new errorSDK.codes.ERROR_GET_REGISTRATION() exponentialBackoffMockReturnValue({}, { status: 500, statusText: 'Internal Server Error', url: journalUrl }) - await sdkClient.getWebhookRegistration('consumerId', 'projectId', 'workspaceId', 'registrationId') + await sdkClient.getRegistration('consumerId', 'projectId', 'workspaceId', 'registrationId') .then(res => { throw new Error(' No error response') }) @@ -432,16 +452,16 @@ describe('Get webhook registration with retries', () => { }) }) -describe('test delete webhook registration', () => { +describe('test delete registration', () => { it('Success on delete registration', async () => { const sdkClient = await createSdkClient() exponentialBackoffMockReturnValue(undefined, { status: 204, statusText: 'No Content' }) - const res = await sdkClient.deleteWebhookRegistration('consumerId', 'projectId', 'workspaceId', + const res = await sdkClient.deleteRegistration('consumerId', 'projectId', 'workspaceId', 'registrationId') expect(res).toBe(undefined) }) it('Not found error on delete registration', () => { - const api = 'deleteWebhookRegistration' + const api = 'deleteRegistration' exponentialBackoffMockReturnValue({}, { status: 404, statusText: 'Not Found' }) checkErrorResponse(api, new errorSDK.codes.ERROR_DELETE_REGISTRATION(), ['consumerId', 'integrationId', 'registrationId1']) diff --git a/test/mock.js b/test/mock.js index 26f68d3..a875dcd 100644 --- a/test/mock.js +++ b/test/mock.js @@ -244,7 +244,7 @@ const createEventMetadataBadRequest = { description: 'Test for SDK 1' } -const createWebhookRegistration = { +const createRegistration = { name: 'name', description: 'description', client_id: 'test-apikey', @@ -258,7 +258,7 @@ const createWebhookRegistration = { ] } -const updateWebhookRegistration = { +const updateRegistration = { name: 'name', description: 'description', webhook_url: 'https://test-webhook', @@ -271,7 +271,7 @@ const updateWebhookRegistration = { ] } -const createWebhookRegistrationBadRequest = { +const createRegistrationBadRequest = { name: 'name', description: 'description', client_id: 'test-apikey', @@ -284,7 +284,7 @@ const createWebhookRegistrationBadRequest = { ] } -const createWebhookRegistrationResponse = { +const createRegistrationResponse = { _links: { 'rel:events': { href: 'https://events-va6.adobe.io/events/organizations/consumerId/integrations/integrationId/registrationId' @@ -323,7 +323,7 @@ const createWebhookRegistrationResponse = { enabled: true } -const updateWebhookRegistrationResponse = { +const updateRegistrationResponse = { _links: { 'rel:events': { href: 'https://events-va6.adobe.io/events/organizations/consumerId/integrations/integrationId/registrationId' @@ -362,10 +362,10 @@ const updateWebhookRegistrationResponse = { enabled: true } -const getAllWebhookRegistrationsResponse = { +const getAllRegistrationsResponse = { _links: { self: { - href: 'https://api.adobe.io/consumerId/projectId/workspaceId/registrations' + href: 'https://api.adobe.io/events/consumerId/projectId/workspaceId/registrations' } }, _embedded: { @@ -379,7 +379,7 @@ const getAllWebhookRegistrationsResponse = { href: 'https://eventtraces-stage-va6.adobe.io/traces/consumerId/projectId/workspaceId/registration/registrationId1' }, self: { - href: 'https://api.adobe.io/consumerId/projectId/workspaceId/registrations/registrationId1' + href: 'https://api.adobe.io/events/consumerId/projectId/workspaceId/registrations/registrationId1' } }, id: 30000, @@ -484,6 +484,111 @@ const getAllWebhookRegistrationsResponse = { } } +const getAllRegistrationsForOrgResponse = { + _links: { + first: { + href: 'https://api.adobe.io/events/consumerId/registrations?page=0&size=2' + }, + last: { + href: 'https://api.adobe.io/events/consumerId/registrations?page=19&size=2' + }, + next: { + href: 'https://api.adobe.io/events/consumerId/registrations?page=2&size=2' + }, + prev: { + href: 'https://api.adobe.io/events/consumerId/registrations?page=0&size=2' + }, + self: { + href: 'https://api.adobe.io/events/consumerId/registrations?page=1&size=2' + } + }, + _embedded: { + registrations: [ + { + _links: { + 'rel:events': { + href: 'https://events-stage-va6.adobe.io/events/organizations/consumerId/integrations/integrationId/registrationId1' + }, + 'rel:trace': { + href: 'https://eventtraces-stage-va6.adobe.io/traces/consumerId/projectId/workspaceId/registration/registrationId1' + }, + self: { + href: 'https://api.adobe.io/events/consumerId/projectId/workspaceId/registrations/registrationId1' + } + }, + id: 30000, + name: 'test name 1', + description: 'test description 1', + client_id: 'test-apikey', + registration_id: 'registrationId1', + events_of_interest: [ + { + event_code: 'event_code_1', + event_label: 'event_label', + event_description: 'event_description', + provider_id: 'provider_id', + provider_label: 'label', + event_delivery_format: 'adobe_io' + } + ], + webhook_status: 'verified', + created_date: '2022-06-13T16:31:57.000Z', + updated_date: '2022-09-19T05:46:36.000Z', + consumer_id: 'consumerId', + project_id: 'projectId', + workspace_id: 'workspaceId', + webhook_url: 'https://test-webhook-1', + delivery_type: 'webhook', + enabled: true + }, + { + _links: { + 'rel:events': { + href: 'https://events-stage-va6.adobe.io/events/organizations/consumerId/integrations/integrationId/registrationId2' + }, + 'rel:trace': { + href: 'https://eventtraces-stage-va6.adobe.io/traces/consumerId/projectId/workspaceId/registration/registrationId2' + }, + self: { + href: 'https://csm-stage.adobe.io/consumerId/projectId/workspaceId/registrations/registrationId2' + } + }, + id: 30001, + name: 'test name 2', + description: 'test description 2', + client_id: 'test-apikey', + registration_id: 'registrationId2', + events_of_interest: [ + { + event_code: 'event_code_2', + event_label: 'event_label_2', + event_description: 'event_description_2', + provider_id: 'provider_id_2', + provider_label: 'label', + event_delivery_format: 'adobe_io' + } + ], + webhook_status: 'hook_unreachable', + created_date: '2022-06-13T16:31:57.000Z', + updated_date: '2022-09-19T05:46:36.000Z', + consumer_id: 'consumerId', + project_id: 'projectId', + workspace_id: 'workspaceId', + webhook_url: 'https://test-webhook-2', + delivery_type: 'webhook_batch', + enabled: false + } + ] + }, + page: { + size: 2, + number: 1, + numberOfElements: 2, + totalElements: 19, + totalPages: 10 + } +} + const cloudEvent = { id: 'test-id', source: 'urn:uuid:test-provider-id', @@ -702,12 +807,13 @@ const data = { createEventMetadataForProvider: createEventMetadataForProvider, createEventMetadataForProviderResponse: createEventMetadataForProviderResponse, createEventMetadataBadRequest: createEventMetadataBadRequest, - createWebhookRegistration: createWebhookRegistration, - createWebhookRegistrationResponse: createWebhookRegistrationResponse, - createWebhookRegistrationBadRequest: createWebhookRegistrationBadRequest, - updateWebhookRegistrationResponse: updateWebhookRegistrationResponse, - updateWebhookRegistration: updateWebhookRegistration, - getAllWebhookRegistrationsResponse: getAllWebhookRegistrationsResponse, + createRegistration: createRegistration, + createRegistrationResponse: createRegistrationResponse, + createRegistrationBadRequest: createRegistrationBadRequest, + updateRegistrationResponse: updateRegistrationResponse, + updateRegistration: updateRegistration, + getAllRegistrationsForOrgResponse: getAllRegistrationsForOrgResponse, + getAllRegistrationsResponse: getAllRegistrationsResponse, cloudEvent: cloudEvent, cloudEventEmptyPayload: cloudEventEmptyPayload, journalResponseBody: journalResponseBody, From 00a36f471e057eca1cae3a6be52381ddb655ac17 Mon Sep 17 00:00:00 2001 From: Sangeetha Krishnan Date: Tue, 27 Sep 2022 16:14:53 +0530 Subject: [PATCH 3/9] Update typings and README files --- README.md | 85 +++++++++++---- package.json | 5 +- types.d.ts | 286 +++++++++++++++++++++++++++------------------------ 3 files changed, 224 insertions(+), 152 deletions(-) diff --git a/README.md b/README.md index 2ed2c20..3524da8 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ governing permissions and limitations under the License. [![Downloads/week](https://img.shields.io/npm/dw/@adobe/aio-lib-events.svg)](https://npmjs.org/package/@adobe/aio-lib-events) [![Build Status](https://travis-ci.com/adobe/aio-lib-events.svg?branch=master)](https://travis-ci.com/adobe/aio-lib-events) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) +[![Greenkeeper badge](https://badges.greenkeeper.io/adobe/aio-lib-events.svg)](https://greenkeeper.io/) [![Codecov Coverage](https://img.shields.io/codecov/c/github/adobe/aio-lib-events/master.svg?style=flat-square)](https://codecov.io/gh/adobe/aio-lib-events/) # Adobe I/O Events Lib @@ -108,6 +109,8 @@ and max number of retries

EventsCoreAPIOptions : object
+
Page : object
+
EventsJournalOptions : object
EventsJournalPollingOptions : object
@@ -143,10 +146,12 @@ and max number of retries * [.updateEventMetadataForProvider(consumerOrgId, projectId, workspaceId, providerId, eventCode, body)](#EventsCoreAPI+updateEventMetadataForProvider) ⇒ Promise.<object> * [.deleteEventMetadata(consumerOrgId, projectId, workspaceId, providerId, eventCode)](#EventsCoreAPI+deleteEventMetadata) ⇒ Promise.<object> * [.deleteAllEventMetadata(consumerOrgId, projectId, workspaceId, providerId)](#EventsCoreAPI+deleteAllEventMetadata) ⇒ Promise.<object> - * [.createWebhookRegistration(consumerOrgId, integrationId, body)](#EventsCoreAPI+createWebhookRegistration) ⇒ Promise.<object> - * [.getWebhookRegistration(consumerOrgId, integrationId, registrationId)](#EventsCoreAPI+getWebhookRegistration) ⇒ Promise.<object> - * [.getAllWebhookRegistrations(consumerOrgId, integrationId)](#EventsCoreAPI+getAllWebhookRegistrations) ⇒ Promise.<object> - * [.deleteWebhookRegistration(consumerOrgId, integrationId, registrationId)](#EventsCoreAPI+deleteWebhookRegistration) ⇒ Promise.<object> + * [.createRegistration(consumerOrgId, projectId, workspaceId, body)](#EventsCoreAPI+createRegistration) ⇒ Promise.<object> + * [.updateRegistration(consumerOrgId, projectId, workspaceId, registrationId, body)](#EventsCoreAPI+updateRegistration) ⇒ Promise.<object> + * [.getRegistration(consumerOrgId, projectId, workspaceId, registrationId)](#EventsCoreAPI+getRegistration) ⇒ Promise.<object> + * [.getAllRegistrationsForWorkspace(consumerOrgId, projectId, workspaceId)](#EventsCoreAPI+getAllRegistrationsForWorkspace) ⇒ Promise.<object> + * [.getAllRegistrationsForOrg(consumerOrgId, [page])](#EventsCoreAPI+getAllRegistrationsForOrg) ⇒ Promise.<object> + * [.deleteRegistration(consumerOrgId, projectId, workspaceId, registrationId)](#EventsCoreAPI+deleteRegistration) ⇒ Promise.<object> * [.publishEvent(cloudEvent)](#EventsCoreAPI+publishEvent) ⇒ Promise.<string> * [.getEventsFromJournal(journalUrl, [eventsJournalOptions], [fetchResponseHeaders])](#EventsCoreAPI+getEventsFromJournal) ⇒ Promise.<object> * [.getEventsObservableFromJournal(journalUrl, [eventsJournalOptions], [eventsJournalPollingOptions])](#EventsCoreAPI+getEventsObservableFromJournal) ⇒ Observable @@ -351,9 +356,9 @@ Delete all event metadata of a provider | workspaceId | string | Workspace Id from the console | | providerId | string | provider for which the event metadata is to be updated | - + -### eventsCoreAPI.createWebhookRegistration(consumerOrgId, integrationId, body) ⇒ Promise.<object> +### eventsCoreAPI.createRegistration(consumerOrgId, projectId, workspaceId, body) ⇒ Promise.<object> Create a webhook or journal registration **Kind**: instance method of [EventsCoreAPI](#EventsCoreAPI) @@ -362,12 +367,29 @@ Create a webhook or journal registration | Param | Type | Description | | --- | --- | --- | | consumerOrgId | string | Consumer Org Id from the console | -| integrationId | string | integration Id from the console | +| projectId | string | Project Id from the console | +| workspaceId | string | Workspace Id from the console | +| body | object | Json data contains details of the registration | + + + +### eventsCoreAPI.updateRegistration(consumerOrgId, projectId, workspaceId, registrationId, body) ⇒ Promise.<object> +Update a webhook or journal registration + +**Kind**: instance method of [EventsCoreAPI](#EventsCoreAPI) +**Returns**: Promise.<object> - Details of the webhook/journal registration to be updated + +| Param | Type | Description | +| --- | --- | --- | +| consumerOrgId | string | Consumer Org Id from the console | +| projectId | string | Project Id from the console | +| workspaceId | string | Workspace Id from the console | +| registrationId | string | Registration id whose details are to be fetched | | body | object | Json data contains details of the registration | - + -### eventsCoreAPI.getWebhookRegistration(consumerOrgId, integrationId, registrationId) ⇒ Promise.<object> +### eventsCoreAPI.getRegistration(consumerOrgId, projectId, workspaceId, registrationId) ⇒ Promise.<object> Get registration details for a given registration **Kind**: instance method of [EventsCoreAPI](#EventsCoreAPI) @@ -376,13 +398,14 @@ Get registration details for a given registration | Param | Type | Description | | --- | --- | --- | | consumerOrgId | string | Consumer Org Id from the console | -| integrationId | string | Integration Id from the console | +| projectId | string | Project Id from the console | +| workspaceId | string | Workspace Id from the console | | registrationId | string | Registration id whose details are to be fetched | - + -### eventsCoreAPI.getAllWebhookRegistrations(consumerOrgId, integrationId) ⇒ Promise.<object> -Get all registration details for a given integration +### eventsCoreAPI.getAllRegistrationsForWorkspace(consumerOrgId, projectId, workspaceId) ⇒ Promise.<object> +Get all registration details for a workspace **Kind**: instance method of [EventsCoreAPI](#EventsCoreAPI) **Returns**: Promise.<object> - List of all webhook/journal registrations @@ -390,11 +413,25 @@ Get all registration details for a given integration | Param | Type | Description | | --- | --- | --- | | consumerOrgId | string | Consumer Org Id from the console | -| integrationId | string | Integration Id from the console | +| projectId | string | Project Id from the console | +| workspaceId | string | Workspace Id from the console | + + + +### eventsCoreAPI.getAllRegistrationsForOrg(consumerOrgId, [page]) ⇒ Promise.<object> +Get all registration details for an org + +**Kind**: instance method of [EventsCoreAPI](#EventsCoreAPI) +**Returns**: Promise.<object> - Paginated response of all webhook/journal registrations for an org + +| Param | Type | Description | +| --- | --- | --- | +| consumerOrgId | string | Consumer Org Id from the console | +| [page] | [Page](#Page) | page size and page number | - + -### eventsCoreAPI.deleteWebhookRegistration(consumerOrgId, integrationId, registrationId) ⇒ Promise.<object> +### eventsCoreAPI.deleteRegistration(consumerOrgId, projectId, workspaceId, registrationId) ⇒ Promise.<object> Delete webhook registration **Kind**: instance method of [EventsCoreAPI](#EventsCoreAPI) @@ -403,7 +440,8 @@ Delete webhook registration | Param | Type | Description | | --- | --- | --- | | consumerOrgId | string | Consumer Org Id from the console | -| integrationId | string | Integration Id from the console | +| projectId | string | Project Id from the console | +| workspaceId | string | Workspace Id from the console | | registrationId | string | Id of the registration to be deleted | @@ -411,7 +449,7 @@ Delete webhook registration ### eventsCoreAPI.publishEvent(cloudEvent) ⇒ Promise.<string> Publish Cloud Events -Event publishers can publish events to the Adobe I/O Events using this SDK. The events should follow Cloud Events 1.0 specification: https://github.com/cloudevents/spec/blob/v1.0/spec.md. +Event publishers can publish events to the Adobe I/O Events using this SDK. The events should follow Cloud Events 1.0 specification: https://github.com/cloudevents/spec/blob/v1.0/spec.md. As of now, only application/json is accepted as the content-type for the "data" field of the cloud event. If retries are set, publish events are retried on network issues, 5xx and 429 error response codes. @@ -496,6 +534,17 @@ Returns a Promise that resolves with a new EventsCoreAPI object. | [eventsBaseURL] | string | Base URL for Events Default https://api.adobe.io (optional) | | [eventsIngressURL] | string | Ingress URL for Events. Default https://eventsingress.adobe.io (optional) | + + +## Page : object +**Kind**: global typedef +**Properties** + +| Name | Type | Description | +| --- | --- | --- | +| [page] | number | page number to be fetched. Default 0 (optional) | +| [size] | number | size of each page. Default 10 (optional) | + ## EventsJournalOptions : object diff --git a/package.json b/package.json index be96c32..913abc2 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,8 @@ "unit-tests": "jest --config test/jest.config.js --maxWorkers=2", "e2e": "jest --config e2e/jest.config.js", "typings": "jsdoc -t node_modules/tsd-jsdoc/dist -r src/index.js -d .", - "generate-docs": "jsdoc2md -t ./docs/readme_template.md ./src/index.js > README.md" + "generate-docs": "npm run typings && npm run jsdoc", + "jsdoc": "jsdoc2md -t ./docs/readme_template.md ./src/index.js > README.md" }, "dependencies": { "@adobe/aio-lib-core-errors": "^3.1.1", @@ -48,7 +49,7 @@ "jest-junit": "^10.0.0", "jest-plugin-fs": "^2.9.0", "jsdoc": "^3.6.7", - "jsdoc-to-markdown": "^5.0.3", + "jsdoc-to-markdown": "^7.1.1", "openapi-schema-validator": "^3.0.3", "querystring": "^0.2.0", "stdout-stderr": "^0.1.13", diff --git a/types.d.ts b/types.d.ts index 7e2749d..2ff0880 100644 --- a/types.d.ts +++ b/types.d.ts @@ -12,224 +12,248 @@ declare type EventsCoreAPIOptions = { /** * Returns a Promise that resolves with a new EventsCoreAPI object. - * - * @param {string} organizationId The organization id from your integration - * @param {string} apiKey The api key from your integration - * @param {string} accessToken JWT Token for the integration with IO Management API scope - * @param {EventsCoreAPIOptions} [httpOptions] Options to configure API calls - * @returns {Promise} returns object of the class EventsCoreAPI + * @param organizationId - The organization id from your integration + * @param apiKey - The api key from your integration + * @param accessToken - JWT Token for the integration with IO Management API scope + * @param [httpOptions] - Options to configure API calls + * @returns returns object of the class EventsCoreAPI */ declare function init(organizationId: string, apiKey: string, accessToken: string, httpOptions?: EventsCoreAPIOptions): Promise; /** * This class provides methods to call your Adobe I/O Events APIs. * Before calling any method initialize the instance by calling the `init` method on it - * with valid values for organizationId, apiKey and accessToken + * with valid values for organizationId, apiKey, accessToken and optional http options such as timeout + * and max number of retries */ declare class EventsCoreAPI { /** * Initialize SDK. - * - * @param {string} organizationId The organization id from your integration - * @param {string} apiKey The api key from your integration - * @param {string} accessToken JWT Token for the integration with IO Management API scope - * @param {EventsCoreAPIOptions} [httpOptions] Options to configure API calls - * @returns {Promise} returns object of the class EventsCoreAPI + * @param organizationId - The organization id from your integration + * @param apiKey - The api key from your integration + * @param accessToken - JWT Token for the integration with IO Management API scope + * @param [httpOptions] - Options to configure API calls + * @returns returns object of the class EventsCoreAPI */ init(organizationId: string, apiKey: string, accessToken: string, httpOptions?: EventsCoreAPIOptions): Promise; - /** Http options {retries, timeout} + /** + * Http options {retries, timeout} */ httpOptions: EventsCoreAPIOptions; - /** The organization id from your integration + /** + * The organization id from your integration */ organizationId: string; - /** The api key from your integration + /** + * The api key from your integration */ apiKey: string; - /** The JWT Token for the integration with IO Management API scope + /** + * The JWT Token for the integration with IO Management API scope */ accessToken: string; /** * Fetch all the providers - * - * @param {string} consumerOrgId Consumer Org Id from the console - * @returns {Promise} Returns list of providers for the org + * @param consumerOrgId - Consumer Org Id from the console + * @returns Returns list of providers for the org */ getAllProviders(consumerOrgId: string): Promise; /** * Fetch a provider - * - * @param {string} providerId The id that uniquely identifies the provider to be fetched - * @param {boolean} [fetchEventMetadata] Set this to true if you want to fetch the associated eventmetadata of the provider - * @returns {Promise} Returns the provider specified by the provider id + * @param providerId - The id that uniquely identifies the provider to be fetched + * @param [fetchEventMetadata = false] - Set this to true if you want to fetch the associated eventmetadata of the provider + * @returns Returns the provider specified by the provider id */ getProvider(providerId: string, fetchEventMetadata?: boolean): Promise; /** * Create a new provider given the provider details - * - * @param {string} consumerOrgId Consumer Org Id from the console - * @param {string} projectId Project Id from the console - * @param {string} workspaceId Workspace Id from the console - * @param {object} body Json data that describes the provider - * @returns {Promise} Returns the details of the provider created + * @param consumerOrgId - Consumer Org Id from the console + * @param projectId - Project Id from the console + * @param workspaceId - Workspace Id from the console + * @param body - Json data that describes the provider + * @returns Returns the details of the provider created */ createProvider(consumerOrgId: string, projectId: string, workspaceId: string, body: any): Promise; /** * Update a provider given the id and provider details - * - * @param {string} consumerOrgId Consumer Org Id from the console - * @param {string} projectId Project Id from the console - * @param {string} workspaceId Workspace Id from the console - * @param {string} providerId The id that uniquely identifies the provider to be updated - * @param {object} body Json data that describes the provider - * @returns {Promise} Returns the details of the provider updated + * @param consumerOrgId - Consumer Org Id from the console + * @param projectId - Project Id from the console + * @param workspaceId - Workspace Id from the console + * @param providerId - The id that uniquely identifies the provider to be updated + * @param body - Json data that describes the provider + * @returns Returns the details of the provider updated */ updateProvider(consumerOrgId: string, projectId: string, workspaceId: string, providerId: string, body: any): Promise; /** * Delete a provider given the id - * - * @param {string} consumerOrgId Consumer Org Id from the console - * @param {string} projectId Project Id from the console - * @param {string} workspaceId Workspace Id from the console - * @param {string} providerId The id that uniquely identifies the provider to be deleted - * @returns {Promise} Returns an empty object if the deletion was successful + * @param consumerOrgId - Consumer Org Id from the console + * @param projectId - Project Id from the console + * @param workspaceId - Workspace Id from the console + * @param providerId - The id that uniquely identifies the provider to be deleted + * @returns Returns an empty object if the deletion was successful */ deleteProvider(consumerOrgId: string, projectId: string, workspaceId: string, providerId: string): Promise; /** * Get all event metadata for a provider - * - * @param {string} providerId The id that uniquely identifies the provider whose event metadata is to be fetched - * @returns {Promise} List of all event metadata of the provider + * @param providerId - The id that uniquely identifies the provider whose event metadata is to be fetched + * @returns List of all event metadata of the provider */ getAllEventMetadataForProvider(providerId: string): Promise; /** * Get an event metadata for given provider and event code - * - * @param {string} providerId The id that uniquely identifies the provider whose event metadata is to be fetched - * @param {string} eventCode The specific event code for which the details of the event metadata is to be fetched - * @returns {Promise} Event metadata that corresponds to the specified event code + * @param providerId - The id that uniquely identifies the provider whose event metadata is to be fetched + * @param eventCode - The specific event code for which the details of the event metadata is to be fetched + * @returns Event metadata that corresponds to the specified event code */ getEventMetadataForProvider(providerId: string, eventCode: string): Promise; /** * Create an event metadata for a provider - * - * @param {string} consumerOrgId Consumer Org Id from the console - * @param {string} projectId Project Id from the console - * @param {string} workspaceId Workspace Id from the console - * @param {string} providerId provider for which the event metadata is to be added - * @param {object} body Json data that describes the event metadata - * @returns {Promise} Details of the event metadata created + * @param consumerOrgId - Consumer Org Id from the console + * @param projectId - Project Id from the console + * @param workspaceId - Workspace Id from the console + * @param providerId - provider for which the event metadata is to be added + * @param body - Json data that describes the event metadata + * @returns Details of the event metadata created */ createEventMetadataForProvider(consumerOrgId: string, projectId: string, workspaceId: string, providerId: string, body: any): Promise; /** * Update the event metadata for a provider - * - * @param {string} consumerOrgId Consumer Org Id from the console - * @param {string} projectId Project Id from the console - * @param {string} workspaceId Workspace Id from the console - * @param {string} providerId provider for which the event metadata is to be updated - * @param {string} eventCode eventCode of the event metadata to be updated - * @param {object} body Json data that describes the event metadata - * @returns {Promise} Details of the event metadata updated + * @param consumerOrgId - Consumer Org Id from the console + * @param projectId - Project Id from the console + * @param workspaceId - Workspace Id from the console + * @param providerId - provider for which the event metadata is to be updated + * @param eventCode - eventCode of the event metadata to be updated + * @param body - Json data that describes the event metadata + * @returns Details of the event metadata updated */ updateEventMetadataForProvider(consumerOrgId: string, projectId: string, workspaceId: string, providerId: string, eventCode: string, body: any): Promise; /** * Delete an event metadata of a provider - * - * @param {string} consumerOrgId Consumer Org Id from the console - * @param {string} projectId Project Id from the console - * @param {string} workspaceId Workspace Id from the console - * @param {string} providerId provider for which the event metadata is to be updated - * @param {string} eventCode eventCode of the event metadata to be updated - * @returns {Promise} Empty object if deletion was successful + * @param consumerOrgId - Consumer Org Id from the console + * @param projectId - Project Id from the console + * @param workspaceId - Workspace Id from the console + * @param providerId - provider for which the event metadata is to be updated + * @param eventCode - eventCode of the event metadata to be updated + * @returns Empty object if deletion was successful */ deleteEventMetadata(consumerOrgId: string, projectId: string, workspaceId: string, providerId: string, eventCode: string): Promise; /** * Delete all event metadata of a provider - * - * @param {string} consumerOrgId Consumer Org Id from the console - * @param {string} projectId Project Id from the console - * @param {string} workspaceId Workspace Id from the console - * @param {string} providerId provider for which the event metadata is to be updated - * @returns {Promise} Empty object if deletion was successful + * @param consumerOrgId - Consumer Org Id from the console + * @param projectId - Project Id from the console + * @param workspaceId - Workspace Id from the console + * @param providerId - provider for which the event metadata is to be updated + * @returns Empty object if deletion was successful */ deleteAllEventMetadata(consumerOrgId: string, projectId: string, workspaceId: string, providerId: string): Promise; /** * Create a webhook or journal registration - * - * @param {string} consumerOrgId Consumer Org Id from the console - * @param {string} integrationId integration Id from the console - * @param {object} body Json data contains details of the registration - * @returns {Promise} Details of the webhook/journal registration created + * @param consumerOrgId - Consumer Org Id from the console + * @param projectId - Project Id from the console + * @param workspaceId - Workspace Id from the console + * @param body - Json data contains details of the registration + * @returns Details of the webhook/journal registration created + */ + createRegistration(consumerOrgId: string, projectId: string, workspaceId: string, body: any): Promise; + /** + * Update a webhook or journal registration + * @param consumerOrgId - Consumer Org Id from the console + * @param projectId - Project Id from the console + * @param workspaceId - Workspace Id from the console + * @param registrationId - Registration id whose details are to be fetched + * @param body - Json data contains details of the registration + * @returns Details of the webhook/journal registration to be updated */ - createWebhookRegistration(consumerOrgId: string, integrationId: string, body: any): Promise; + updateRegistration(consumerOrgId: string, projectId: string, workspaceId: string, registrationId: string, body: any): Promise; /** * Get registration details for a given registration - * - * @param {string} consumerOrgId Consumer Org Id from the console - * @param {string} integrationId Integration Id from the console - * @param {string} registrationId Registration id whose details are to be fetched - * @returns {Promise} Details of the webhook/journal registration + * @param consumerOrgId - Consumer Org Id from the console + * @param projectId - Project Id from the console + * @param workspaceId - Workspace Id from the console + * @param registrationId - Registration id whose details are to be fetched + * @returns Details of the webhook/journal registration */ - getWebhookRegistration(consumerOrgId: string, integrationId: string, registrationId: string): Promise; + getRegistration(consumerOrgId: string, projectId: string, workspaceId: string, registrationId: string): Promise; /** - * Get all registration details for a given integration - * - * @param {string} consumerOrgId Consumer Org Id from the console - * @param {string} integrationId Integration Id from the console - * @returns {Promise} List of all webhook/journal registrations + * Get all registration details for a workspace + * @param consumerOrgId - Consumer Org Id from the console + * @param projectId - Project Id from the console + * @param workspaceId - Workspace Id from the console + * @returns List of all webhook/journal registrations + */ + getAllRegistrationsForWorkspace(consumerOrgId: string, projectId: string, workspaceId: string): Promise; + /** + * Get all registration details for an org + * @param consumerOrgId - Consumer Org Id from the console + * @param [page] - page size and page number + * @returns Paginated response of all webhook/journal registrations for an org */ - getAllWebhookRegistrations(consumerOrgId: string, integrationId: string): Promise; + getAllRegistrationsForOrg(consumerOrgId: string, page?: Page): Promise; /** * Delete webhook registration - * - * @param {string} consumerOrgId Consumer Org Id from the console - * @param {string} integrationId Integration Id from the console - * @param {string} registrationId Id of the registration to be deleted - * @returns {Promise} Empty object if deletion was successful + * @param consumerOrgId - Consumer Org Id from the console + * @param projectId - Project Id from the console + * @param workspaceId - Workspace Id from the console + * @param registrationId - Id of the registration to be deleted + * @returns Empty object if deletion was successful */ - deleteWebhookRegistration(consumerOrgId: string, integrationId: string, registrationId: string): Promise; + deleteRegistration(consumerOrgId: string, projectId: string, workspaceId: string, registrationId: string): Promise; /** - * Publish cloud events to Adobe I/O Events + * Publish Cloud Events * - * @param {object} cloudEvent Object to be published to event receiver in cloud event format - * @returns {Promise} Returns OK/ undefined in case of success and error in case of failure + * Event publishers can publish events to the Adobe I/O Events using this SDK. The events should follow Cloud Events 1.0 specification: https://github.com/cloudevents/spec/blob/v1.0/spec.md. + * As of now, only application/json is accepted as the content-type for the "data" field of the cloud event. + * If retries are set, publish events are retried on network issues, 5xx and 429 error response codes. + * @param cloudEvent - Object to be published to event receiver in cloud event format + * @returns Returns OK/ undefined in case of success and error in case of failure */ publishEvent(cloudEvent: any): Promise; /** * Get events from a journal. - * - * @param {string} journalUrl URL of the journal or 'next' link to read from (required) - * @param {EventsJournalOptions} [eventsJournalOptions] Query options to send with the URL - * @returns {Promise} with the response json includes events and links (if available) + * @param journalUrl - URL of the journal or 'next' link to read from (required) + * @param [eventsJournalOptions] - Query options to send with the URL + * @param [fetchResponseHeaders] - Set this to true if you want to fetch the complete response headers + * @returns with the response json includes events and links (if available) */ - getEventsFromJournal(journalUrl: string, eventsJournalOptions?: EventsJournalOptions): Promise; - + getEventsFromJournal(journalUrl: string, eventsJournalOptions?: EventsJournalOptions, fetchResponseHeaders?: boolean): Promise; /** - * Get observable to start listening to journal events. + * getEventsObservableFromJournal returns an RxJS Observable * - * @param {string} journalUrl URL of the journal or 'next' link to read from (required) - * @param {EventsJournalOptions} [eventsJournalOptions] Query options to send with the Journal URL - * @param {EventsJournalPollingOptions} [eventsJournalPollingOptions] Journal polling options - * @returns {Observable} observable to which the user can subscribe to in order to listen to events + * One can go through the extensive documentation on RxJS in order to learn more + * and leverage the various RxJS Operators to act on emitted events. + * @param journalUrl - URL of the journal or 'next' link to read from (required) + * @param [eventsJournalOptions] - Query options to send with the Journal URL + * @param [eventsJournalPollingOptions] - Journal polling options + * @returns observable to which the user can subscribe to in order to listen to events */ getEventsObservableFromJournal(journalUrl: string, eventsJournalOptions?: EventsJournalOptions, eventsJournalPollingOptions?: EventsJournalPollingOptions): Observable; - /** * Authenticating events by verifying digital signature - * @param {object} event JSON payload delivered to the registered webhook URL - * @param {string} recipientClientId Target recipient client id retrieved from the Adobe I/O Console integration - * @param {SignatureOptions} signatureOptions Map of all digital signature header values consisting fields defined in SignatureOptions - * @returns {boolean} If signature matches return true else return false + * @param event - JSON payload delivered to the registered webhook URL + * @param recipientClientId - Target recipient client id retrieved from the Adobe I/O Console integration + * @param signatureOptions - map of all digital signature header values consisting fields as below + * digiSignature1 : Value of digital signature retrieved from the x-adobe-digital-signature1 header in each POST request to webhook + * digiSignature2 : Value of digital signature retrieved from the x-adobe-digital-signature2 header in each POST request to webhook + * publicKeyPath1 : Relative path of ioevents public key retrieved from the x-adobe-public-key1-path header in each POST request to webhook + * publicKeyPath2 : Relative path of ioevents public key retrieved from the x-adobe-public-key2-path header in each POST request to webhook + * @returns If signature matches return true else return false */ verifyDigitalSignatureForEvent(event: any, recipientClientId: string, signatureOptions?: SignatureOptions): boolean; } /** - * @typedef {object} EventsJournalOptions - * @property {boolean} [latest] Retrieve latest events (optional) - * @property {string} [since] Position at which to start fetching the events from (optional) - * @property {number} [limit] Maximum number of events to retrieve (optional) + * @property [page] - page number to be fetched. Default 0 (optional) + * @property [size] - size of each page. Default 10 (optional) + */ +declare type Page = { + page?: number; + size?: number; +}; + +/** + * @property [latest] - Retrieve latest events (optional) + * @property [since] - Position at which to start fetching the events from (optional) + * @property [limit] - Maximum number of events to retrieve (optional) */ declare type EventsJournalOptions = { latest?: boolean; @@ -238,8 +262,7 @@ declare type EventsJournalOptions = { }; /** - * @typedef {object} EventsJournalPollingOptions - * @property {number} [interval] Interval at which to poll the journal; If not provided, a default value will be used (optional) + * @property [interval] - Interval at which to poll the journal; If not provided, a default value will be used (optional) */ declare type EventsJournalPollingOptions = { interval?: number; @@ -247,10 +270,10 @@ declare type EventsJournalPollingOptions = { /** * @typedef {object} SignatureOptions - * @property {string} [digiSignature1] Value of digital signature retrieved from the x-adobe-digital-signature1 header in each POST request to webhook - * @property {string} [digiSignature2] Value of digital signature retrieved from the x-adobe-digital-signature2 header in each POST request to webhook - * @property {string} [publicKeyUrl1] Value of public key url retrieved from the x-adobe-public-key1-url header in each POST request to webhook - * @property {string} [publicKeyUrl2] Value of public key url retrieved from the x-adobe-public-key2-url header in each POST request to webhook + * @property [digiSignature1] - Value of digital signature retrieved from the x-adobe-digital-signature1 header in each POST request to webhook + * @property [digiSignature2] - Value of digital signature retrieved from the x-adobe-digital-signature2 header in each POST request to webhook + * @property [publicKeyUrl1] - Value of public key url retrieved from the x-adobe-public-key1-url header in each POST request to webhook + * @property [publicKeyUrl2] - Value of public key url retrieved from the x-adobe-public-key2-url header in each POST request to webhook */ declare type SignatureOptions = { digiSignature1: string; @@ -258,4 +281,3 @@ declare type SignatureOptions = { publicKeyUrl1: string; publicKeyUrl2: string; }; - From 3fc8d2ae449165b5334a80e11aef302957bc4dec Mon Sep 17 00:00:00 2001 From: Sangeetha Krishnan Date: Tue, 27 Sep 2022 23:36:36 +0530 Subject: [PATCH 4/9] address review comments --- src/SDKErrors.js | 2 +- src/index.js | 38 +++++++++++++++++++------------------- test/index.test.js | 2 +- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/SDKErrors.js b/src/SDKErrors.js index 143d8c1..02f353b 100644 --- a/src/SDKErrors.js +++ b/src/SDKErrors.js @@ -60,7 +60,7 @@ E('ERROR_CREATE_REGISTRATION', '%s') E('ERROR_UPDATE_REGISTRATION', '%s') E('ERROR_GET_REGISTRATION', '%s') E('ERROR_GET_ALL_REGISTRATION', '%s') -E('ERROR_GET_ALL_REGISTRATION_FOR_ORG', '%s') +E('ERROR_GET_ALL_REGISTRATIONS_FOR_ORG', '%s') E('ERROR_DELETE_REGISTRATION', '%s') E('ERROR_GET_JOURNAL_DATA', '%s') E('ERROR_PUBLISH_EVENT', '%s') diff --git a/src/index.js b/src/index.js index 8858daa..6a943f9 100644 --- a/src/index.js +++ b/src/index.js @@ -122,7 +122,7 @@ class EventsCoreAPI { const requestOptions = this.__createRequest('GET', headers) const url = this.__getUrl(`/events/${consumerOrgId}/providers`) const sdkDetails = { requestOptions: requestOptions, url: url } - return this.__handleRequest(url, requestOptions, sdkDetails, codes.ERROR_GET_ALL_PROVIDERS) + return this.__handleRequest(sdkDetails, codes.ERROR_GET_ALL_PROVIDERS) } /** @@ -137,7 +137,7 @@ class EventsCoreAPI { const requestOptions = this.__createRequest('GET', headers) const url = this.__getUrl(`/events/providers/${providerId}?eventmetadata=${fetchEventMetadata}`) const sdkDetails = { requestOptions: requestOptions, url: url } - return this.__handleRequest(url, requestOptions, sdkDetails, codes.ERROR_GET_PROVIDER) + return this.__handleRequest(sdkDetails, codes.ERROR_GET_PROVIDER) } /** @@ -155,7 +155,7 @@ class EventsCoreAPI { JSON.stringify(body)) const url = this.__getUrl(`/events/${consumerOrgId}/${projectId}/${workspaceId}/providers`) const sdkDetails = { requestOptions: requestOptions, url: url } - return this.__handleRequest(url, requestOptions, sdkDetails, codes.ERROR_CREATE_PROVIDER) + return this.__handleRequest(sdkDetails, codes.ERROR_CREATE_PROVIDER) } /** @@ -174,7 +174,7 @@ class EventsCoreAPI { JSON.stringify(body)) const url = this.__getUrl(`/events/${consumerOrgId}/${projectId}/${workspaceId}/providers/${providerId}`) const sdkDetails = { requestOptions: requestOptions, url: url } - return this.__handleRequest(url, requestOptions, sdkDetails, codes.ERROR_UPDATE_PROVIDER) + return this.__handleRequest(sdkDetails, codes.ERROR_UPDATE_PROVIDER) } /** @@ -191,7 +191,7 @@ class EventsCoreAPI { const requestOptions = this.__createRequest('DELETE', headers) const url = this.__getUrl(`/events/${consumerOrgId}/${projectId}/${workspaceId}/providers/${providerId}`) const sdkDetails = { requestOptions: requestOptions, url: url } - return this.__handleRequest(url, requestOptions, sdkDetails, codes.ERROR_DELETE_PROVIDER) + return this.__handleRequest(sdkDetails, codes.ERROR_DELETE_PROVIDER) } /** @@ -211,7 +211,7 @@ class EventsCoreAPI { const requestOptions = this.__createRequest('GET', headers) const url = this.__getUrl(`/events/providers/${providerId}/eventmetadata`) const sdkDetails = { requestOptions: requestOptions, url: url } - return this.__handleRequest(url, requestOptions, sdkDetails, codes.ERROR_GET_ALL_EVENTMETADATA) + return this.__handleRequest(sdkDetails, codes.ERROR_GET_ALL_EVENTMETADATA) } /** @@ -226,7 +226,7 @@ class EventsCoreAPI { const requestOptions = this.__createRequest('GET', headers) const url = this.__getUrl(`/events/providers/${providerId}/eventmetadata/${eventCode}`) const sdkDetails = { requestOptions: requestOptions, url: url } - return this.__handleRequest(url, requestOptions, sdkDetails, codes.ERROR_GET_EVENTMETADATA) + return this.__handleRequest(sdkDetails, codes.ERROR_GET_EVENTMETADATA) } /** @@ -244,7 +244,7 @@ class EventsCoreAPI { const requestOptions = this.__createRequest('POST', headers, JSON.stringify(body)) const url = this.__getUrl(`/events/${consumerOrgId}/${projectId}/${workspaceId}/providers/${providerId}/eventmetadata`) const sdkDetails = { requestOptions: requestOptions, url: url } - return this.__handleRequest(url, requestOptions, sdkDetails, codes.ERROR_CREATE_EVENTMETADATA) + return this.__handleRequest(sdkDetails, codes.ERROR_CREATE_EVENTMETADATA) } /** @@ -263,7 +263,7 @@ class EventsCoreAPI { const requestOptions = this.__createRequest('PUT', headers, JSON.stringify(body)) const url = this.__getUrl(`/events/${consumerOrgId}/${projectId}/${workspaceId}/providers/${providerId}/eventmetadata/${eventCode}`) const sdkDetails = { requestOptions: requestOptions, url: url } - return this.__handleRequest(url, requestOptions, sdkDetails, codes.ERROR_UPDATE_EVENTMETADATA) + return this.__handleRequest(sdkDetails, codes.ERROR_UPDATE_EVENTMETADATA) } /** @@ -281,7 +281,7 @@ class EventsCoreAPI { const requestOptions = this.__createRequest('DELETE', headers) const url = this.__getUrl(`/events/${consumerOrgId}/${projectId}/${workspaceId}/providers/${providerId}/eventmetadata/${eventCode}`) const sdkDetails = { requestOptions: requestOptions, url: url } - return this.__handleRequest(url, requestOptions, sdkDetails, codes.ERROR_DELETE_EVENTMETADATA) + return this.__handleRequest(sdkDetails, codes.ERROR_DELETE_EVENTMETADATA) } /** @@ -298,7 +298,7 @@ class EventsCoreAPI { const requestOptions = this.__createRequest('DELETE', headers) const url = this.__getUrl(`/events/${consumerOrgId}/${projectId}/${workspaceId}/providers/${providerId}/eventmetadata`) const sdkDetails = { requestOptions: requestOptions, url: url } - return this.__handleRequest(url, requestOptions, sdkDetails, codes.ERROR_DELETE_ALL_EVENTMETADATA) + return this.__handleRequest(sdkDetails, codes.ERROR_DELETE_ALL_EVENTMETADATA) } /** @@ -321,7 +321,7 @@ class EventsCoreAPI { const requestOptions = this.__createRequest('POST', headers, JSON.stringify(body)) const url = this.__getUrl(`/events/${consumerOrgId}/${projectId}/${workspaceId}/registrations`) const sdkDetails = { requestOptions: requestOptions, url: url } - return this.__handleRequest(url, requestOptions, sdkDetails, codes.ERROR_CREATE_REGISTRATION) + return this.__handleRequest(sdkDetails, codes.ERROR_CREATE_REGISTRATION) } /** @@ -339,7 +339,7 @@ class EventsCoreAPI { const requestOptions = this.__createRequest('POST', headers, JSON.stringify(body)) const url = this.__getUrl(`/events/${consumerOrgId}/${projectId}/${workspaceId}/registrations/${registrationId}`) const sdkDetails = { requestOptions: requestOptions, url: url } - return this.__handleRequest(url, requestOptions, sdkDetails, codes.ERROR_UPDATE_REGISTRATION) + return this.__handleRequest(sdkDetails, codes.ERROR_UPDATE_REGISTRATION) } /** @@ -356,7 +356,7 @@ class EventsCoreAPI { const requestOptions = this.__createRequest('GET', headers) const url = this.__getUrl(`/events/${consumerOrgId}/${projectId}/${workspaceId}/registrations/${registrationId}`) const sdkDetails = { requestOptions: requestOptions, url: url } - return this.__handleRequest(url, requestOptions, sdkDetails, codes.ERROR_GET_REGISTRATION) + return this.__handleRequest(sdkDetails, codes.ERROR_GET_REGISTRATION) } /** @@ -372,7 +372,7 @@ class EventsCoreAPI { const requestOptions = this.__createRequest('GET', headers) const url = this.__getUrl(`/events/${consumerOrgId}/${projectId}/${workspaceId}/registrations`) const sdkDetails = { requestOptions: requestOptions, url: url } - return this.__handleRequest(url, requestOptions, sdkDetails, codes.ERROR_GET_ALL_REGISTRATION) + return this.__handleRequest(sdkDetails, codes.ERROR_GET_ALL_REGISTRATION) } /** @@ -393,7 +393,7 @@ class EventsCoreAPI { const url = this.__getUrl(`/events/${consumerOrgId}/registrations`) const urlWithQueryParams = helpers.appendQueryParams(url, page) const sdkDetails = { requestOptions: requestOptions, url: urlWithQueryParams } - return this.__handleRequest(url, requestOptions, sdkDetails, codes.ERROR_GET_ALL_REGISTRATION_FOR_ORG) + return this.__handleRequest(sdkDetails, codes.ERROR_GET_ALL_REGISTRATIONS_FOR_ORG) } /** @@ -410,7 +410,7 @@ class EventsCoreAPI { const requestOptions = this.__createRequest('DELETE', headers) const url = this.__getUrl(`/events/${consumerOrgId}/${projectId}/${workspaceId}/registrations/${registrationId}`) const sdkDetails = { requestOptions: requestOptions, url: url } - return this.__handleRequest(url, requestOptions, sdkDetails, codes.ERROR_DELETE_REGISTRATION) + return this.__handleRequest(sdkDetails, codes.ERROR_DELETE_REGISTRATION) } /** @@ -590,9 +590,9 @@ class EventsCoreAPI { * @returns {Promise} returns the json result * @private */ - __handleRequest (url, requestOptions, sdkDetails, ErrorCode) { + __handleRequest (sdkDetails, ErrorCode) { return new Promise((resolve, reject) => { - fetchRetryClient.exponentialBackoff(url, requestOptions, { maxRetries: (this.httpOptions && this.httpOptions.retries) || 0, initialDelayInMillis: 1000 }) + fetchRetryClient.exponentialBackoff(sdkDetails.url, sdkDetails.requestOptions, { maxRetries: (this.httpOptions && this.httpOptions.retries) || 0, initialDelayInMillis: 1000 }) .then((response) => { if (!response.ok) { sdkDetails.requestId = response.headers.get('x-request-id') diff --git a/test/index.test.js b/test/index.test.js index fb33d91..0a1b582 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -419,7 +419,7 @@ describe('Get all registrations for org', () => { it('Not found error on get a registration', async () => { const api = 'getAllRegistrationsForOrg' exponentialBackoffMockReturnValue({}, { status: 404, statusText: 'Not Found' }) - await checkErrorResponse(api, new errorSDK.codes.ERROR_GET_ALL_REGISTRATION_FOR_ORG(), ['consumerId-2']) + await checkErrorResponse(api, new errorSDK.codes.ERROR_GET_ALL_REGISTRATIONS_FOR_ORG(), ['consumerId-2']) }) }) From abfca520051e06064390b329c6b957d09fa6b406 Mon Sep 17 00:00:00 2001 From: Sangeetha Krishnan Date: Wed, 28 Sep 2022 10:46:17 +0530 Subject: [PATCH 5/9] update registration to use PUT method --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 6a943f9..42b2da5 100644 --- a/src/index.js +++ b/src/index.js @@ -336,7 +336,7 @@ class EventsCoreAPI { */ updateRegistration (consumerOrgId, projectId, workspaceId, registrationId, body) { const headers = {} - const requestOptions = this.__createRequest('POST', headers, JSON.stringify(body)) + const requestOptions = this.__createRequest('PUT', headers, JSON.stringify(body)) const url = this.__getUrl(`/events/${consumerOrgId}/${projectId}/${workspaceId}/registrations/${registrationId}`) const sdkDetails = { requestOptions: requestOptions, url: url } return this.__handleRequest(sdkDetails, codes.ERROR_UPDATE_REGISTRATION) From 7b949aa74f4b1c2ef6e5c399126427de6a4769ef Mon Sep 17 00:00:00 2001 From: Sangeetha Krishnan Date: Wed, 28 Sep 2022 15:10:19 +0530 Subject: [PATCH 6/9] Make events base url const in test --- test/index.test.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/index.test.js b/test/index.test.js index 0a1b582..4917a07 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -44,8 +44,8 @@ const gOrganizationId = 'test-org' const gApiKey = 'test-apikey' const gAccessToken = 'test-token' const journalUrl = 'http://journal-url/events/organizations/orgId/integrations/integId/regId' -const EVENTS_BASE_URL = 'fakebaseurl' -const EVENTS_INGRESS_URL = 'fakeingressurl' +const EVENTS_BASE_URL = 'https://api.adobe.io/events' +const EVENTS_INGRESS_URL = 'https://eventsingress.adobe.io' // ///////////////////////////////////////////// @@ -374,7 +374,7 @@ describe('Get all registration', () => { const res = await sdkClient.getAllRegistrationsForWorkspace('consumerId', 'projectId', 'workspaceId') expect(res._embedded.registrations.length).toBe(3) const regs = res._embedded.registrations - expect(res._links.self.href).toBe('https://api.adobe.io/events/consumerId/projectId/workspaceId/registrations') + expect(res._links.self.href).toBe(EVENTS_BASE_URL + '/consumerId/projectId/workspaceId/registrations') expect(regs[0].id).toBe(30000) expect(regs[1].webhook_status).toBe('hook_unreachable') expect(regs[2].delivery_type).toBe('journal') @@ -391,7 +391,7 @@ describe('Get a registration', () => { const sdkClient = await createSdkClient() exponentialBackoffMockReturnValue(mock.data.createRegistrationResponse, { status: 200, statusText: 'OK' }) const res = await sdkClient.getRegistration('consumerId', 'projectId', 'workspaceId', 'registrationId') - expect(res._links.self.href).toBe('https://api.adobe.io/events/consumerId/projectId/workspaceId/registrations/registrationId') + expect(res._links.self.href).toBe(EVENTS_BASE_URL + '/consumerId/projectId/workspaceId/registrations/registrationId') expect(res.id).toBe(248723) expect(res.webhook_status).toBe('verified') expect(res.enabled).toBe(true) @@ -408,10 +408,10 @@ describe('Get all registrations for org', () => { const sdkClient = await createSdkClient() exponentialBackoffMockReturnValue(mock.data.getAllRegistrationsForOrgResponse, { status: 200, statusText: 'OK' }) const res = await sdkClient.getAllRegistrationsForOrg('consumerId', { page: 1, size: 2 }) - expect(res._links.self.href).toBe('https://api.adobe.io/events/consumerId/registrations?page=1&size=2') - expect(res._links.first.href).toBe('https://api.adobe.io/events/consumerId/registrations?page=0&size=2') - expect(res._links.last.href).toBe('https://api.adobe.io/events/consumerId/registrations?page=19&size=2') - expect(res._links.prev.href).toBe('https://api.adobe.io/events/consumerId/registrations?page=0&size=2') + expect(res._links.self.href).toBe(EVENTS_BASE_URL + '/consumerId/registrations?page=1&size=2') + expect(res._links.first.href).toBe(EVENTS_BASE_URL + '/consumerId/registrations?page=0&size=2') + expect(res._links.last.href).toBe(EVENTS_BASE_URL + '/consumerId/registrations?page=19&size=2') + expect(res._links.prev.href).toBe(EVENTS_BASE_URL + '/consumerId/registrations?page=0&size=2') expect(res._embedded.registrations.length).toBe(2) expect(res.page.numberOfElements).toBe(2) expect(res.page.totalElements).toBe(19) @@ -437,7 +437,7 @@ describe('Get registration with retries', () => { expect(e.code).toEqual(error.code) }) expect(fetchRetry.exponentialBackoff).toHaveBeenCalledWith( - 'https://api.adobe.io/events/consumerId/projectId/workspaceId/registrations/registrationId', + EVENTS_BASE_URL + '/consumerId/projectId/workspaceId/registrations/registrationId', { body: undefined, headers: { From fdc7bf970c361460831852bffc8f81c8f1b09618 Mon Sep 17 00:00:00 2001 From: Sangeetha Krishnan Date: Thu, 29 Sep 2022 14:12:12 +0530 Subject: [PATCH 7/9] add registration create and update model typedefs --- README.md | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++-- src/index.js | 28 ++++++++++++++++++++++++++-- types.d.ts | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 123 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 3524da8..460986b 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,12 @@ and max number of retries

EventsCoreAPIOptions : object
+
EventsOfInterest : object
+
+
RegistrationCreateModel : object
+
+
RegistrationUpdateModel : object
+
Page : object
EventsJournalOptions : object
@@ -369,7 +375,7 @@ Create a webhook or journal registration | consumerOrgId | string | Consumer Org Id from the console | | projectId | string | Project Id from the console | | workspaceId | string | Workspace Id from the console | -| body | object | Json data contains details of the registration | +| body | [RegistrationCreateModel](#RegistrationCreateModel) | Json data contains details of the registration | @@ -385,7 +391,7 @@ Update a webhook or journal registration | projectId | string | Project Id from the console | | workspaceId | string | Workspace Id from the console | | registrationId | string | Registration id whose details are to be fetched | -| body | object | Json data contains details of the registration | +| body | [RegistrationUpdateModel](#RegistrationUpdateModel) | Json data contains details of the registration | @@ -534,6 +540,48 @@ Returns a Promise that resolves with a new EventsCoreAPI object. | [eventsBaseURL] | string | Base URL for Events Default https://api.adobe.io (optional) | | [eventsIngressURL] | string | Ingress URL for Events. Default https://eventsingress.adobe.io (optional) | + + +## EventsOfInterest : object +**Kind**: global typedef +**Properties** + +| Name | Type | Description | +| --- | --- | --- | +| provider_id | string | The id of the provider of the events to be subscribed | +| event_code | string | The requested valid event code belonging to the provider | + + + +## RegistrationCreateModel : object +**Kind**: global typedef +**Properties** + +| Name | Type | Description | +| --- | --- | --- | +| client_id | string | Client id for which the registration is created | +| name | string | The name of the registration | +| description | string | The description of the registration | +| [webhook_url] | string | A valid webhook url where the events would be delivered for webhook or webhook_batch delivery_type | +| events_of_interest | [Array.<EventsOfInterest>](#EventsOfInterest) | The events for which the registration is to be subscribed to | +| delivery_type | string | Delivery type can either be webhook|webhook_batch|journal. | +| [enabled] | string | Enable or disable the registration. Default true. | + + + +## RegistrationUpdateModel : object +**Kind**: global typedef +**Properties** + +| Name | Type | Description | +| --- | --- | --- | +| name | string | The name of the registration | +| description | string | The description of the registration | +| [webhook_url] | string | A valid webhook url where the events would be delivered for webhook or webhook_batch delivery_type | +| events_of_interest | [Array.<EventsOfInterest>](#EventsOfInterest) | The events for which the registration is to be subscribed to | +| delivery_type | string | Delivery type can either be webhook|webhook_batch|journal. | +| [enabled] | string | Enable or disable the registration. Default true. | + ## Page : object diff --git a/src/index.js b/src/index.js index 42b2da5..70337fb 100644 --- a/src/index.js +++ b/src/index.js @@ -307,13 +307,28 @@ class EventsCoreAPI { * ========================================================================= */ + /** + * @typedef {object} EventsOfInterest + * @property {string} provider_id The id of the provider of the events to be subscribed + * @property {string} event_code The requested valid event code belonging to the provider + */ + /** + * @typedef {object} RegistrationCreateModel + * @property {string} client_id Client id for which the registration is created + * @property {string} name The name of the registration + * @property {string} description The description of the registration + * @property {string} [webhook_url] A valid webhook url where the events would be delivered for webhook or webhook_batch delivery_type + * @property {Array.} events_of_interest The events for which the registration is to be subscribed to + * @property {string} delivery_type Delivery type can either be webhook|webhook_batch|journal. + * @property {string} [enabled] Enable or disable the registration. Default true. + */ /** * Create a webhook or journal registration * * @param {string} consumerOrgId Consumer Org Id from the console * @param {string} projectId Project Id from the console * @param {string} workspaceId Workspace Id from the console - * @param {object} body Json data contains details of the registration + * @param {RegistrationCreateModel} body Json data contains details of the registration * @returns {Promise} Details of the webhook/journal registration created */ createRegistration (consumerOrgId, projectId, workspaceId, body) { @@ -324,6 +339,15 @@ class EventsCoreAPI { return this.__handleRequest(sdkDetails, codes.ERROR_CREATE_REGISTRATION) } + /** + * @typedef {object} RegistrationUpdateModel + * @property {string} name The name of the registration + * @property {string} description The description of the registration + * @property {string} [webhook_url] A valid webhook url where the events would be delivered for webhook or webhook_batch delivery_type + * @property {Array.} events_of_interest The events for which the registration is to be subscribed to + * @property {string} delivery_type Delivery type can either be webhook|webhook_batch|journal. + * @property {string} [enabled] Enable or disable the registration. Default true. + */ /** * Update a webhook or journal registration * @@ -331,7 +355,7 @@ class EventsCoreAPI { * @param {string} projectId Project Id from the console * @param {string} workspaceId Workspace Id from the console * @param {string} registrationId Registration id whose details are to be fetched - * @param {object} body Json data contains details of the registration + * @param {RegistrationUpdateModel} body Json data contains details of the registration * @returns {Promise} Details of the webhook/journal registration to be updated */ updateRegistration (consumerOrgId, projectId, workspaceId, registrationId, body) { diff --git a/types.d.ts b/types.d.ts index 2ff0880..b2acdf3 100644 --- a/types.d.ts +++ b/types.d.ts @@ -154,7 +154,7 @@ declare class EventsCoreAPI { * @param body - Json data contains details of the registration * @returns Details of the webhook/journal registration created */ - createRegistration(consumerOrgId: string, projectId: string, workspaceId: string, body: any): Promise; + createRegistration(consumerOrgId: string, projectId: string, workspaceId: string, body: RegistrationCreateModel): Promise; /** * Update a webhook or journal registration * @param consumerOrgId - Consumer Org Id from the console @@ -164,7 +164,7 @@ declare class EventsCoreAPI { * @param body - Json data contains details of the registration * @returns Details of the webhook/journal registration to be updated */ - updateRegistration(consumerOrgId: string, projectId: string, workspaceId: string, registrationId: string, body: any): Promise; + updateRegistration(consumerOrgId: string, projectId: string, workspaceId: string, registrationId: string, body: RegistrationUpdateModel): Promise; /** * Get registration details for a given registration * @param consumerOrgId - Consumer Org Id from the console @@ -241,6 +241,51 @@ declare class EventsCoreAPI { verifyDigitalSignatureForEvent(event: any, recipientClientId: string, signatureOptions?: SignatureOptions): boolean; } +/** + * @property provider_id - The id of the provider of the events to be subscribed + * @property event_code - The requested valid event code belonging to the provider + */ +declare type EventsOfInterest = { + provider_id: string; + event_code: string; +}; + +/** + * @property client_id - Client id for which the registration is created + * @property name - The name of the registration + * @property description - The description of the registration + * @property [webhook_url] - A valid webhook url where the events would be delivered for webhook or webhook_batch delivery_type + * @property events_of_interest - The events for which the registration is to be subscribed to + * @property delivery_type - Delivery type can either be webhook|webhook_batch|journal. + * @property [enabled] - Enable or disable the registration. Default true. + */ +declare type RegistrationCreateModel = { + client_id: string; + name: string; + description: string; + webhook_url?: string; + events_of_interest: EventsOfInterest[]; + delivery_type: string; + enabled?: string; +}; + +/** + * @property name - The name of the registration + * @property description - The description of the registration + * @property [webhook_url] - A valid webhook url where the events would be delivered for webhook or webhook_batch delivery_type + * @property events_of_interest - The events for which the registration is to be subscribed to + * @property delivery_type - Delivery type can either be webhook|webhook_batch|journal. + * @property [enabled] - Enable or disable the registration. Default true. + */ +declare type RegistrationUpdateModel = { + name: string; + description: string; + webhook_url?: string; + events_of_interest: EventsOfInterest[]; + delivery_type: string; + enabled?: string; +}; + /** * @property [page] - page number to be fetched. Default 0 (optional) * @property [size] - size of each page. Default 10 (optional) From 82ff1edcdb94ef6929309147aca8bccf7cfd4720 Mon Sep 17 00:00:00 2001 From: Sangeetha Krishnan Date: Thu, 29 Sep 2022 14:16:43 +0530 Subject: [PATCH 8/9] add typedefs for Provider and EventMetadata input models --- README.md | 37 +++++++++++++++++++++++++++++++++---- src/index.js | 21 +++++++++++++++++---- types.d.ts | 32 ++++++++++++++++++++++++++++---- 3 files changed, 78 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 460986b..6fe6f87 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,10 @@ and max number of retries

EventsCoreAPIOptions : object
+
ProviderInputModel : object
+
+
EventMetadataInputModel : object
+
EventsOfInterest : object
RegistrationCreateModel : object
@@ -240,7 +244,7 @@ Create a new provider given the provider details | consumerOrgId | string | Consumer Org Id from the console | | projectId | string | Project Id from the console | | workspaceId | string | Workspace Id from the console | -| body | object | Json data that describes the provider | +| body | [ProviderInputModel](#ProviderInputModel) | Json data that describes the provider | @@ -256,7 +260,7 @@ Update a provider given the id and provider details | projectId | string | Project Id from the console | | workspaceId | string | Workspace Id from the console | | providerId | string | The id that uniquely identifies the provider to be updated | -| body | object | Json data that describes the provider | +| body | [ProviderInputModel](#ProviderInputModel) | Json data that describes the provider | @@ -312,7 +316,7 @@ Create an event metadata for a provider | projectId | string | Project Id from the console | | workspaceId | string | Workspace Id from the console | | providerId | string | provider for which the event metadata is to be added | -| body | object | Json data that describes the event metadata | +| body | [EventMetadataInputModel](#EventMetadataInputModel) | Json data that describes the event metadata | @@ -329,7 +333,7 @@ Update the event metadata for a provider | workspaceId | string | Workspace Id from the console | | providerId | string | provider for which the event metadata is to be updated | | eventCode | string | eventCode of the event metadata to be updated | -| body | object | Json data that describes the event metadata | +| body | [EventMetadataInputModel](#EventMetadataInputModel) | Json data that describes the event metadata | @@ -540,6 +544,31 @@ Returns a Promise that resolves with a new EventsCoreAPI object. | [eventsBaseURL] | string | Base URL for Events Default https://api.adobe.io (optional) | | [eventsIngressURL] | string | Ingress URL for Events. Default https://eventsingress.adobe.io (optional) | + + +## ProviderInputModel : object +**Kind**: global typedef +**Properties** + +| Name | Type | Description | +| --- | --- | --- | +| label | string | The label of this Events Provider | +| [description] | string | The description of this Events Provider | +| [docs_url] | string | The documentation url of this Events Provider | + + + +## EventMetadataInputModel : object +**Kind**: global typedef +**Properties** + +| Name | Type | Description | +| --- | --- | --- | +| label | string | The description of this Event Metadata | +| description | string | The label of this Event Metadata | +| event_code | string | The event_code of this Event Metadata. This event_code describes the type of event. Ideally it should be prefixed with a reverse-DNS name (dictating the organization which defines the semantics of this event type) It is equivalent to the CloudEvents' type. See https://github.com/cloudevents/spec/blob/master/spec.md#type | +| [sample_event_template] | string | An optional base64 encoded sample event template | + ## EventsOfInterest : object diff --git a/src/index.js b/src/index.js index 70337fb..4a26b51 100644 --- a/src/index.js +++ b/src/index.js @@ -140,13 +140,19 @@ class EventsCoreAPI { return this.__handleRequest(sdkDetails, codes.ERROR_GET_PROVIDER) } + /** + * @typedef {object} ProviderInputModel + * @property {string} label The label of this Events Provider + * @property {string} [description] The description of this Events Provider + * @property {string} [docs_url] The documentation url of this Events Provider + */ /** * Create a new provider given the provider details * * @param {string} consumerOrgId Consumer Org Id from the console * @param {string} projectId Project Id from the console * @param {string} workspaceId Workspace Id from the console - * @param {object} body Json data that describes the provider + * @param {ProviderInputModel} body Json data that describes the provider * @returns {Promise} Returns the details of the provider created */ createProvider (consumerOrgId, projectId, workspaceId, body) { @@ -165,7 +171,7 @@ class EventsCoreAPI { * @param {string} projectId Project Id from the console * @param {string} workspaceId Workspace Id from the console * @param {string} providerId The id that uniquely identifies the provider to be updated - * @param {object} body Json data that describes the provider + * @param {ProviderInputModel} body Json data that describes the provider * @returns {Promise} Returns the details of the provider updated */ updateProvider (consumerOrgId, projectId, workspaceId, providerId, body) { @@ -229,6 +235,13 @@ class EventsCoreAPI { return this.__handleRequest(sdkDetails, codes.ERROR_GET_EVENTMETADATA) } + /** + * @typedef {object} EventMetadataInputModel + * @property {string} label The description of this Event Metadata + * @property {string} description The label of this Event Metadata + * @property {string} event_code The event_code of this Event Metadata. This event_code describes the type of event. Ideally it should be prefixed with a reverse-DNS name (dictating the organization which defines the semantics of this event type) It is equivalent to the CloudEvents' type. See https://github.com/cloudevents/spec/blob/master/spec.md#type + * @property {string} [sample_event_template] An optional base64 encoded sample event template + */ /** * Create an event metadata for a provider * @@ -236,7 +249,7 @@ class EventsCoreAPI { * @param {string} projectId Project Id from the console * @param {string} workspaceId Workspace Id from the console * @param {string} providerId provider for which the event metadata is to be added - * @param {object} body Json data that describes the event metadata + * @param {EventMetadataInputModel} body Json data that describes the event metadata * @returns {Promise} Details of the event metadata created */ createEventMetadataForProvider (consumerOrgId, projectId, workspaceId, providerId, body) { @@ -255,7 +268,7 @@ class EventsCoreAPI { * @param {string} workspaceId Workspace Id from the console * @param {string} providerId provider for which the event metadata is to be updated * @param {string} eventCode eventCode of the event metadata to be updated - * @param {object} body Json data that describes the event metadata + * @param {EventMetadataInputModel} body Json data that describes the event metadata * @returns {Promise} Details of the event metadata updated */ updateEventMetadataForProvider (consumerOrgId, projectId, workspaceId, providerId, eventCode, body) { diff --git a/types.d.ts b/types.d.ts index b2acdf3..3660983 100644 --- a/types.d.ts +++ b/types.d.ts @@ -73,7 +73,7 @@ declare class EventsCoreAPI { * @param body - Json data that describes the provider * @returns Returns the details of the provider created */ - createProvider(consumerOrgId: string, projectId: string, workspaceId: string, body: any): Promise; + createProvider(consumerOrgId: string, projectId: string, workspaceId: string, body: ProviderInputModel): Promise; /** * Update a provider given the id and provider details * @param consumerOrgId - Consumer Org Id from the console @@ -83,7 +83,7 @@ declare class EventsCoreAPI { * @param body - Json data that describes the provider * @returns Returns the details of the provider updated */ - updateProvider(consumerOrgId: string, projectId: string, workspaceId: string, providerId: string, body: any): Promise; + updateProvider(consumerOrgId: string, projectId: string, workspaceId: string, providerId: string, body: ProviderInputModel): Promise; /** * Delete a provider given the id * @param consumerOrgId - Consumer Org Id from the console @@ -115,7 +115,7 @@ declare class EventsCoreAPI { * @param body - Json data that describes the event metadata * @returns Details of the event metadata created */ - createEventMetadataForProvider(consumerOrgId: string, projectId: string, workspaceId: string, providerId: string, body: any): Promise; + createEventMetadataForProvider(consumerOrgId: string, projectId: string, workspaceId: string, providerId: string, body: EventMetadataInputModel): Promise; /** * Update the event metadata for a provider * @param consumerOrgId - Consumer Org Id from the console @@ -126,7 +126,7 @@ declare class EventsCoreAPI { * @param body - Json data that describes the event metadata * @returns Details of the event metadata updated */ - updateEventMetadataForProvider(consumerOrgId: string, projectId: string, workspaceId: string, providerId: string, eventCode: string, body: any): Promise; + updateEventMetadataForProvider(consumerOrgId: string, projectId: string, workspaceId: string, providerId: string, eventCode: string, body: EventMetadataInputModel): Promise; /** * Delete an event metadata of a provider * @param consumerOrgId - Consumer Org Id from the console @@ -241,6 +241,30 @@ declare class EventsCoreAPI { verifyDigitalSignatureForEvent(event: any, recipientClientId: string, signatureOptions?: SignatureOptions): boolean; } +/** + * @property label - The label of this Events Provider + * @property [description] - The description of this Events Provider + * @property [docs_url] - The documentation url of this Events Provider + */ +declare type ProviderInputModel = { + label: string; + description?: string; + docs_url?: string; +}; + +/** + * @property label - The description of this Event Metadata + * @property description - The label of this Event Metadata + * @property event_code - The event_code of this Event Metadata. This event_code describes the type of event. Ideally it should be prefixed with a reverse-DNS name (dictating the organization which defines the semantics of this event type) It is equivalent to the CloudEvents' type. See https://github.com/cloudevents/spec/blob/master/spec.md#type + * @property [sample_event_template] - An optional base64 encoded sample event template + */ +declare type EventMetadataInputModel = { + label: string; + description: string; + event_code: string; + sample_event_template?: string; +}; + /** * @property provider_id - The id of the provider of the events to be subscribed * @property event_code - The requested valid event code belonging to the provider From 6cc5908ddc09bf775808eeea48ec151bf549d0eb Mon Sep 17 00:00:00 2001 From: Sangeetha Krishnan Date: Wed, 5 Oct 2022 15:03:08 +0530 Subject: [PATCH 9/9] Update README.md Fix delivery type options Registration create and update models in the Readme file. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6fe6f87..eb2235c 100644 --- a/README.md +++ b/README.md @@ -593,7 +593,7 @@ Returns a Promise that resolves with a new EventsCoreAPI object. | description | string | The description of the registration | | [webhook_url] | string | A valid webhook url where the events would be delivered for webhook or webhook_batch delivery_type | | events_of_interest | [Array.<EventsOfInterest>](#EventsOfInterest) | The events for which the registration is to be subscribed to | -| delivery_type | string | Delivery type can either be webhook|webhook_batch|journal. | +| delivery_type | string | Delivery type can either be webhook, webhook_batch or journal. | | [enabled] | string | Enable or disable the registration. Default true. | @@ -608,7 +608,7 @@ Returns a Promise that resolves with a new EventsCoreAPI object. | description | string | The description of the registration | | [webhook_url] | string | A valid webhook url where the events would be delivered for webhook or webhook_batch delivery_type | | events_of_interest | [Array.<EventsOfInterest>](#EventsOfInterest) | The events for which the registration is to be subscribed to | -| delivery_type | string | Delivery type can either be webhook|webhook_batch|journal. | +| delivery_type | string | Delivery type can either be webhook, webhook_batch or journal. | | [enabled] | string | Enable or disable the registration. Default true. |