@adobe/aio-lib-events
Advanced tools
Comparing version 3.1.1 to 3.2.0-pre.2024-01-08.sha-ebc18083
{ | ||
"extends": ["@adobe/eslint-config-aio-lib-config"] | ||
"extends": ["@adobe/eslint-config-aio-lib-config"], | ||
"rules": { | ||
"jsdoc/tag-lines": [ | ||
// The Error level should be `error`, `warn`, or `off` (or 2, 1, or 0) | ||
"error", | ||
"never", | ||
{ | ||
"startLines": null | ||
} | ||
] | ||
} | ||
} |
@@ -24,2 +24,4 @@ /* | ||
jest.setTimeout(240000) | ||
let sdkClient = {} | ||
@@ -43,3 +45,2 @@ let providerId = {} | ||
sdkClient = await sdk.init(orgId, apiKey, accessToken, httpOptions) | ||
jest.setTimeout(240000) | ||
jest.useRealTimers() | ||
@@ -52,3 +53,3 @@ }) | ||
test('test create provider', async () => { | ||
test('create provider', async () => { | ||
// create a provider | ||
@@ -66,3 +67,3 @@ provider = await sdkClient.createProvider(consumerOrgId, projectId, | ||
test('test create event metadata', async () => { | ||
test('create event metadata', async () => { | ||
// create event metadata | ||
@@ -81,3 +82,3 @@ eventCode = 'com.adobe.events.sdk.event.' + randomNumber | ||
test('test register journalling endpoint', async () => { | ||
test('register journalling endpoint', async () => { | ||
// create journal registration | ||
@@ -100,3 +101,3 @@ journalReg = await sdkClient.createRegistration(consumerOrgId, projectId, workspaceId, { | ||
test('test fetch journalling position', async () => { | ||
test('fetch journalling position', async () => { | ||
const journallingUrl = journalReg._links['rel:events'].href | ||
@@ -116,3 +117,3 @@ logger.info('Journal endpoint ' + journallingUrl + ' has been registered') | ||
test('test publish event', async () => { | ||
test('publish event', async () => { | ||
// fire event | ||
@@ -131,3 +132,3 @@ const publish = await sdkClient.publishEvent({ | ||
test('test event received in journalling endpoint', async () => { | ||
test('event received in journalling endpoint', async () => { | ||
let count = 0 | ||
@@ -134,0 +135,0 @@ let nextLink = journalling.link.next |
{ | ||
"name": "@adobe/aio-lib-events", | ||
"version": "3.1.1", | ||
"version": "3.2.0-pre.2024-01-08.sha-ebc18083", | ||
"description": "Adobe I/O Events", | ||
@@ -12,3 +12,3 @@ "repository": { | ||
"scripts": { | ||
"test": "npm run lint && npm run unit-tests", | ||
"test": "npm run unit-tests && npm run lint", | ||
"lint": "eslint src test e2e", | ||
@@ -22,25 +22,25 @@ "unit-tests": "jest --config test/jest.config.js --maxWorkers=2", | ||
"dependencies": { | ||
"@adobe/aio-lib-core-errors": "^3.1.1", | ||
"@adobe/aio-lib-core-logging": "^2.0.0", | ||
"@adobe/aio-lib-core-networking": "^3.0.0", | ||
"@adobe/aio-lib-state": "^2.0.1", | ||
"cross-fetch": "^3.0.4", | ||
"@adobe/aio-lib-core-errors": "next", | ||
"@adobe/aio-lib-core-logging": "next", | ||
"@adobe/aio-lib-core-networking": "next", | ||
"@adobe/aio-lib-state": "next", | ||
"@adobe/aio-lib-env": "^2.0.0", | ||
"crypto-js": "^4.0.0", | ||
"http-link-header": "^1.0.2", | ||
"node-fetch": "^2.6.0", | ||
"rxjs": "^6.5.4", | ||
"rxjs": "^7.8.1", | ||
"valid-url": "^1.0.9" | ||
}, | ||
"devDependencies": { | ||
"@adobe/eslint-config-aio-lib-config": "^2.0.0", | ||
"@adobe/eslint-config-aio-lib-config": "^2.0.2", | ||
"@js-joda/core": "^2.0.0", | ||
"babel-runtime": "^6.26.0", | ||
"codecov": "^3.5.0", | ||
"dotenv": "^8.1.0", | ||
"dotenv": "^16.3.1", | ||
"eol": "^0.9.1", | ||
"eslint": "^8.44.0", | ||
"eslint": "^8.46.0", | ||
"eslint-config-standard": "^17.1.0", | ||
"eslint-plugin-import": "^2.27.5", | ||
"eslint-plugin-jest": "^23.20.0", | ||
"eslint-plugin-jsdoc": "^37.9.7", | ||
"eslint-plugin-import": "^2.28.0", | ||
"eslint-plugin-jest": "^27.2.3", | ||
"eslint-plugin-jsdoc": "^42.0.0", | ||
"eslint-plugin-n": "^15.7.0", | ||
@@ -52,15 +52,16 @@ "eslint-plugin-node": "^11.1.0", | ||
"jest-fetch-mock": "^3.0.3", | ||
"jest-junit": "^10.0.0", | ||
"jest-junit": "^16.0.0", | ||
"jest-plugin-fs": "^2.9.0", | ||
"jsdoc": "^3.6.7", | ||
"jsdoc-to-markdown": "^8.0.0", | ||
"openapi-schema-validator": "^3.0.3", | ||
"openapi-schema-validator": "^12.1.3", | ||
"querystring": "^0.2.0", | ||
"stdout-stderr": "^0.1.13", | ||
"tsd-jsdoc": "^2.4.0", | ||
"typescript": "^4.9.5" | ||
"typescript": "^5.1.6" | ||
}, | ||
"engines": { | ||
"node": "^14.18 || ^16.13 || >=18" | ||
} | ||
} | ||
"node": ">=18" | ||
}, | ||
"prereleaseSha": "ebc180830a01f7c4bf577998338271d042e4e262" | ||
} |
<!-- | ||
Copyright 2020 Adobe. All rights reserved. | ||
Copyright 2019 Adobe. All rights reserved. | ||
This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
@@ -16,4 +16,3 @@ you may not use this file except in compliance with the License. You may obtain a copy | ||
[![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/) | ||
[![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/) | ||
@@ -23,4 +22,2 @@ | ||
Node Javascript API wrapping the [Adobe I/O Events API](https://www.adobe.io/apis/experienceplatform/events.html). | ||
### Installing | ||
@@ -55,3 +52,3 @@ | ||
try { | ||
// use one of the get methods | ||
// get profiles by custom filters | ||
const result = await client.getSomething({}) | ||
@@ -135,4 +132,2 @@ console.log(result) | ||
<dd></dd> | ||
<dt><a href="#SignatureOptions">SignatureOptions</a> : <code>object</code></dt> | ||
<dd></dd> | ||
</dl> | ||
@@ -177,3 +172,3 @@ | ||
* [.getEventsObservableFromJournal(journalUrl, [eventsJournalOptions], [eventsJournalPollingOptions])](#EventsCoreAPI+getEventsObservableFromJournal) ⇒ <code>Observable</code> | ||
* [.verifyDigitalSignatureForEvent(event, recipientClientId, [signatureOptions])](#EventsCoreAPI+verifyDigitalSignatureForEvent) ⇒ <code>boolean</code> | ||
* [.verifyDigitalSignatureForEvent(event, recipientClientId, signatureOptions)](#EventsCoreAPI+verifyDigitalSignatureForEvent) ⇒ <code>boolean</code> | ||
@@ -522,3 +517,3 @@ <a name="EventsCoreAPI+httpOptions"></a> | ||
### eventsCoreAPI.verifyDigitalSignatureForEvent(event, recipientClientId, [signatureOptions]) ⇒ <code>boolean</code> | ||
### eventsCoreAPI.verifyDigitalSignatureForEvent(event, recipientClientId, signatureOptions) ⇒ <code>boolean</code> | ||
Authenticating events by verifying digital signature | ||
@@ -531,7 +526,6 @@ | ||
| --- | --- | --- | | ||
| event | <code>object</code> | JSON payload delivered to the registered webhook URL | | ||
| recipientClientId | <code>string</code> | Target recipient client id retrieved from the Adobe I/O Console integration | | ||
| [signatureOptions] | [<code>SignatureOptions</code>](#SignatureOptions) | Map of digital signature header fields defined in SignatureOptions | | ||
| event | <code>\*</code> | JSON payload delivered to the registered webhook URL | | ||
| recipientClientId | <code>\*</code> | Target recipient client id retrieved from the Adobe I/O Console integration | | ||
| signatureOptions | <code>\*</code> | 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 | | ||
<a name="init"></a> | ||
@@ -637,3 +631,3 @@ | ||
| events_of_interest | [<code>Array.<EventsOfInterest></code>](#EventsOfInterest) | The events for which the registration is to be subscribed to | | ||
| delivery_type | <code>string</code> | Delivery type can either be webhook, webhook_batch or journal. | | ||
| delivery_type | <code>string</code> | Delivery type can either be webhook|webhook_batch|journal. | | ||
| [enabled] | <code>string</code> | Enable or disable the registration. Default true. | | ||
@@ -653,3 +647,3 @@ | ||
| events_of_interest | [<code>Array.<EventsOfInterest></code>](#EventsOfInterest) | The events for which the registration is to be subscribed to | | ||
| delivery_type | <code>string</code> | Delivery type can either be webhook, webhook_batch or journal. | | ||
| delivery_type | <code>string</code> | Delivery type can either be webhook|webhook_batch|journal. | | ||
| [enabled] | <code>string</code> | Enable or disable the registration. Default true. | | ||
@@ -690,15 +684,2 @@ | ||
<a name="SignatureOptions"></a> | ||
## SignatureOptions : <code>object</code> | ||
**Kind**: global typedef | ||
**Properties** | ||
| Name | Type | Description | | ||
| --- | --- | --- | | ||
| [digiSignature1] | <code>string</code> | Value of digital signature retrieved from the x-adobe-digital-signature1 header | | ||
| [digiSignature2] | <code>string</code> | Value of digital signature retrieved from the x-adobe-digital-signature2 header | | ||
| [publicKeyPath1] | <code>string</code> | Relative path of ioevents public key retrieved from the x-adobe-public-key1-path header | | ||
| [publicKeyPath2] | <code>string</code> | Relative path of ioevents public key retrieved from the x-adobe-public-key2-path header | | ||
### Debug Logs | ||
@@ -705,0 +686,0 @@ |
@@ -68,17 +68,2 @@ /* | ||
/** | ||
* Parse the Retry-After header | ||
* Spec: {@link https://tools.ietf.org/html/rfc7231#section-7.1.3} | ||
* | ||
* @param {string} header Retry-After header value | ||
* @returns {number} Number of milliseconds to sleep until the next call to getEventsFromJournal | ||
*/ | ||
function parseRetryAfterHeader (header) { | ||
if (header.match(/^[0-9]+$/)) { | ||
return parseInt(header, 10) * 1000 | ||
} else { | ||
return Date.parse(header) - Date.now() | ||
} | ||
} | ||
/** | ||
* Wrapper to check the event received by webhook | ||
@@ -132,3 +117,2 @@ * and return decoded (if encoded) payload | ||
parseLinkHeader, | ||
parseRetryAfterHeader, | ||
getProperPayload, | ||
@@ -135,0 +119,0 @@ genErrorResponse |
@@ -25,7 +25,20 @@ /* | ||
const { codes } = require('./SDKErrors') | ||
const { HttpExponentialBackoff } = require('@adobe/aio-lib-core-networking') | ||
const { HttpExponentialBackoff, parseRetryAfterHeader } = require('@adobe/aio-lib-core-networking') | ||
const fetchRetryClient = new HttpExponentialBackoff() | ||
const { DEFAULT_ENV, getCliEnv } = require('@adobe/aio-lib-env') | ||
const EventsConsumerFromJournal = require('./journalling') | ||
const EVENTS_BASE_URL = { | ||
prod: 'https://api.adobe.io', | ||
stage: 'https://api-stage.adobe.io' | ||
} | ||
const EVENTS_INGRESS_URL = { | ||
prod: 'https://eventsingress.adobe.io', | ||
stage: 'https://eventsingress-stage.adobe.io' | ||
} | ||
const APPLICATION_HAL_JSON = 'application/hal+json' | ||
/** | ||
@@ -50,4 +63,4 @@ * @typedef {object} EventsCoreAPIOptions | ||
const clientWrapper = new EventsCoreAPI() | ||
clientWrapper.init(organizationId, apiKey, accessToken, httpOptions) | ||
const env = getCliEnv() | ||
clientWrapper.init(organizationId, apiKey, accessToken, env, httpOptions) | ||
.then(initializedSDK => { | ||
@@ -77,6 +90,7 @@ logger.debug('sdk initialized successfully') | ||
* @param {string} accessToken JWT Token for the integration with IO Management API scope | ||
* @param {string} env the CLI environment | ||
* @param {EventsCoreAPIOptions} [httpOptions] Options to configure API calls | ||
* @returns {Promise<EventsCoreAPI>} returns object of the class EventsCoreAPI | ||
*/ | ||
async init (organizationId, apiKey, accessToken, httpOptions) { | ||
async init (organizationId, apiKey, accessToken, env, httpOptions) { | ||
const initErrors = [] | ||
@@ -97,2 +111,3 @@ if (!organizationId) { | ||
} | ||
/** Http options {retries, timeout} */ | ||
@@ -107,3 +122,3 @@ this.httpOptions = httpOptions | ||
/** Initialise base and Ingress URLs */ | ||
this.__initLibURLs() | ||
this.__initLibURLs(env) | ||
@@ -139,2 +154,3 @@ return this | ||
const headers = {} | ||
headers.Accept = APPLICATION_HAL_JSON | ||
const filterOptions = providerOptions.filterBy | ||
@@ -161,2 +177,3 @@ if (filterOptions && filterOptions.providerMetadataIds && filterOptions.providerMetadataId) { | ||
const headers = {} | ||
headers.Accept = APPLICATION_HAL_JSON | ||
const requestOptions = this.__createRequest('GET', headers) | ||
@@ -186,2 +203,3 @@ const url = this.__getUrl(`/events/providers/${providerId}`) | ||
const headers = {} | ||
headers.Accept = APPLICATION_HAL_JSON | ||
const requestOptions = this.__createRequest('POST', headers, | ||
@@ -206,2 +224,3 @@ JSON.stringify(body)) | ||
const headers = {} | ||
headers.Accept = APPLICATION_HAL_JSON | ||
const requestOptions = this.__createRequest('PUT', headers, | ||
@@ -242,2 +261,3 @@ JSON.stringify(body)) | ||
const headers = {} | ||
headers.Accept = APPLICATION_HAL_JSON | ||
const requestOptions = this.__createRequest('GET', headers) | ||
@@ -263,2 +283,3 @@ const url = this.__getUrl('/events/providermetadata') | ||
const headers = {} | ||
headers.Accept = APPLICATION_HAL_JSON | ||
const requestOptions = this.__createRequest('GET', headers) | ||
@@ -279,2 +300,3 @@ const url = this.__getUrl(`/events/providers/${providerId}/eventmetadata`) | ||
const headers = {} | ||
headers.Accept = APPLICATION_HAL_JSON | ||
const requestOptions = this.__createRequest('GET', headers) | ||
@@ -305,2 +327,3 @@ const url = this.__getUrl(`/events/providers/${providerId}/eventmetadata/${eventCode}`) | ||
const headers = {} | ||
headers.Accept = APPLICATION_HAL_JSON | ||
const requestOptions = this.__createRequest('POST', headers, JSON.stringify(body)) | ||
@@ -325,2 +348,3 @@ const url = this.__getUrl(`/events/${consumerOrgId}/${projectId}/${workspaceId}/providers/${providerId}/eventmetadata`) | ||
const headers = {} | ||
headers.Accept = APPLICATION_HAL_JSON | ||
const requestOptions = this.__createRequest('PUT', headers, JSON.stringify(body)) | ||
@@ -399,2 +423,3 @@ const url = this.__getUrl(`/events/${consumerOrgId}/${projectId}/${workspaceId}/providers/${providerId}/eventmetadata/${eventCode}`) | ||
const headers = {} | ||
headers.Accept = APPLICATION_HAL_JSON | ||
const requestOptions = this.__createRequest('POST', headers, JSON.stringify(body)) | ||
@@ -427,2 +452,3 @@ const url = this.__getUrl(`/events/${consumerOrgId}/${projectId}/${workspaceId}/registrations`) | ||
const headers = {} | ||
headers.Accept = APPLICATION_HAL_JSON | ||
const requestOptions = this.__createRequest('PUT', headers, JSON.stringify(body)) | ||
@@ -445,2 +471,3 @@ const url = this.__getUrl(`/events/${consumerOrgId}/${projectId}/${workspaceId}/registrations/${registrationId}`) | ||
const headers = {} | ||
headers.Accept = APPLICATION_HAL_JSON | ||
const requestOptions = this.__createRequest('GET', headers) | ||
@@ -462,2 +489,3 @@ const url = this.__getUrl(`/events/${consumerOrgId}/${projectId}/${workspaceId}/registrations/${registrationId}`) | ||
const headers = {} | ||
headers.Accept = APPLICATION_HAL_JSON | ||
const requestOptions = this.__createRequest('GET', headers) | ||
@@ -483,2 +511,3 @@ const url = this.__getUrl(`/events/${consumerOrgId}/${projectId}/${workspaceId}/registrations`) | ||
const headers = {} | ||
headers.Accept = APPLICATION_HAL_JSON | ||
const requestOptions = this.__createRequest('GET', headers) | ||
@@ -583,3 +612,3 @@ const url = this.__getUrl(`/events/${consumerOrgId}/registrations`) | ||
if (retryAfterHeader) { | ||
result.retryAfter = helpers.parseRetryAfterHeader(retryAfterHeader) | ||
result.retryAfter = parseRetryAfterHeader(retryAfterHeader) || undefined | ||
} | ||
@@ -763,6 +792,12 @@ if (fetchResponseHeaders) { | ||
__initLibURLs () { | ||
__initLibURLs (env) { | ||
this.httpOptions = this.httpOptions || {} | ||
this.httpOptions.eventsBaseURL = this.httpOptions.eventsBaseURL || 'https://api.adobe.io' | ||
this.httpOptions.eventsIngressURL = this.httpOptions.eventsIngressURL || 'https://eventsingress.adobe.io' | ||
let eventsBaseUrl = EVENTS_BASE_URL[env] | ||
if (!eventsBaseUrl) { | ||
eventsBaseUrl = EVENTS_BASE_URL[DEFAULT_ENV] | ||
env = DEFAULT_ENV | ||
} | ||
const eventsIngressUrl = EVENTS_INGRESS_URL[env] | ||
this.httpOptions.eventsBaseURL = this.httpOptions.eventsBaseURL || eventsBaseUrl | ||
this.httpOptions.eventsIngressURL = this.httpOptions.eventsIngressURL || eventsIngressUrl | ||
} | ||
@@ -769,0 +804,0 @@ } |
@@ -77,3 +77,3 @@ /* | ||
}) | ||
it('Do not append undefined query params to url ', () => { | ||
it('Do not append undefined query params to url', () => { | ||
const queryParams3 = { values: undefined } | ||
@@ -80,0 +80,0 @@ const url = helpers.appendQueryParams('https://base-url.adobe.io', queryParams3) |
@@ -28,9 +28,16 @@ /* | ||
jest.mock('@adobe/aio-lib-core-networking', () => ({ | ||
HttpExponentialBackoff: mockHttpExponentialBackoff | ||
})) | ||
jest.mock('@adobe/aio-lib-core-networking', () => { | ||
const originalModule = jest.requireActual('@adobe/aio-lib-core-networking') | ||
return { | ||
...originalModule, | ||
HttpExponentialBackoff: mockHttpExponentialBackoff | ||
} | ||
}) | ||
jest.mock('@adobe/aio-lib-env') | ||
const sdk = require('../src') | ||
const mock = require('./mock') | ||
const errorSDK = require('../src/SDKErrors') | ||
const { getCliEnv } = require('@adobe/aio-lib-env') | ||
const fetch = require('node-fetch') | ||
@@ -48,4 +55,6 @@ const { Response } = jest.requireActual('node-fetch') | ||
const journalUrl = 'http://journal-url/events/organizations/orgId/integrations/integId/regId' | ||
const EVENTS_BASE_URL = 'https://api.adobe.io/events' | ||
const EVENTS_BASE_URL = 'https://api.adobe.io' | ||
const EVENTS_INGRESS_URL = 'https://eventsingress.adobe.io' | ||
const EVENTS_BASE_URL_STAGE = 'https://api-stage.adobe.io' | ||
const EVENTS_INGRESS_URL_STAGE = 'https://eventsingress-stage.adobe.io' | ||
const CONFLICTING_ID = 'conflictingId' | ||
@@ -63,2 +72,3 @@ | ||
jest.clearAllMocks() | ||
getCliEnv.mockReturnValue('prod') | ||
}) | ||
@@ -69,8 +79,7 @@ | ||
describe('SDK init test', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks() | ||
}) | ||
it('sdk init test', async () => { | ||
const options = { | ||
eventsBaseURL: EVENTS_BASE_URL, | ||
eventsIngressURL: EVENTS_INGRESS_URL | ||
} | ||
const sdkClient = await sdk.init(gOrganizationId, gApiKey, gAccessToken, options) | ||
const sdkClient = await createSdkClient() | ||
expect(sdkClient.organizationId).toBe(gOrganizationId) | ||
@@ -83,7 +92,31 @@ expect(sdkClient.apiKey).toBe(gApiKey) | ||
it('sdk init test with URL options', async () => { | ||
const sdkClient = await createSdkClient() | ||
const options = { | ||
eventsBaseURL: 'http://localhost:8080', | ||
eventsIngressURL: 'http://localhost:9080' | ||
} | ||
const sdkClient = await sdk.init(gOrganizationId, gApiKey, gAccessToken, options) | ||
expect(sdkClient.organizationId).toBe(gOrganizationId) | ||
expect(sdkClient.apiKey).toBe(gApiKey) | ||
expect(sdkClient.accessToken).toBe(gAccessToken) | ||
expect(sdkClient.httpOptions.eventsBaseURL).toBe('http://localhost:8080') | ||
expect(sdkClient.httpOptions.eventsIngressURL).toBe('http://localhost:9080') | ||
}) | ||
it('sdk init test with getCliEnv returning stage', async () => { | ||
getCliEnv.mockReturnValue('stage') | ||
const sdkClient = await sdk.init(gOrganizationId, gApiKey, gAccessToken) | ||
expect(sdkClient.organizationId).toBe(gOrganizationId) | ||
expect(sdkClient.apiKey).toBe(gApiKey) | ||
expect(sdkClient.accessToken).toBe(gAccessToken) | ||
expect(sdkClient.httpOptions.eventsBaseURL).toBe(EVENTS_BASE_URL_STAGE) | ||
expect(sdkClient.httpOptions.eventsIngressURL).toBe(EVENTS_INGRESS_URL_STAGE) | ||
}) | ||
it('sdk init test with getCliEnv returning undefined', async () => { | ||
getCliEnv.mockReturnValue(undefined) | ||
const sdkClient = await sdk.init(gOrganizationId, gApiKey, gAccessToken) | ||
expect(sdkClient.organizationId).toBe(gOrganizationId) | ||
expect(sdkClient.apiKey).toBe(gApiKey) | ||
expect(sdkClient.accessToken).toBe(gAccessToken) | ||
expect(sdkClient.httpOptions.eventsBaseURL).toBe(EVENTS_BASE_URL) | ||
expect(sdkClient.httpOptions.eventsIngressURL).toBe(EVENTS_INGRESS_URL) | ||
}) | ||
it('sdk init test - no imsOrgId', async () => { | ||
@@ -184,3 +217,3 @@ return expect(sdk.init(null, gApiKey, gAccessToken)).rejects.toEqual( | ||
}) | ||
it('Not found error on get all providers ', async () => { | ||
it('Not found error on get all providers', async () => { | ||
const api = 'getAllProviders' | ||
@@ -200,3 +233,3 @@ exponentialBackoffMockReturnValue({}, { status: 404, statusText: 'Not Found' }) | ||
}) | ||
it('Not found error on get provider by id ', async () => { | ||
it('Not found error on get provider by id', async () => { | ||
const api = 'getProvider' | ||
@@ -217,3 +250,3 @@ exponentialBackoffMockReturnValue({}, { status: 404, statusText: 'Not Found' }) | ||
}) | ||
it('Not found error on get provider by id ', async () => { | ||
it('Not found error on get provider by id', async () => { | ||
const api = 'getProvider' | ||
@@ -456,3 +489,3 @@ exponentialBackoffMockReturnValue({}, { status: 404, statusText: 'Not Found' }) | ||
const regs = res._embedded.registrations | ||
expect(res._links.self.href).toBe(EVENTS_BASE_URL + '/consumerId/projectId/workspaceId/registrations') | ||
expect(res._links.self.href).toBe(EVENTS_BASE_URL + '/events/consumerId/projectId/workspaceId/registrations') | ||
expect(regs[0].id).toBe(30000) | ||
@@ -474,3 +507,3 @@ expect(regs[1].webhook_status).toBe('hook_unreachable') | ||
const res = await sdkClient.getRegistration('consumerId', 'projectId', 'workspaceId', 'registrationId') | ||
expect(res._links.self.href).toBe(EVENTS_BASE_URL + '/consumerId/projectId/workspaceId/registrations/registrationId') | ||
expect(res._links.self.href).toBe(EVENTS_BASE_URL + '/events/consumerId/projectId/workspaceId/registrations/registrationId') | ||
expect(res.id).toBe(248723) | ||
@@ -492,6 +525,6 @@ expect(res.webhook_status).toBe('verified') | ||
const res = await sdkClient.getAllRegistrationsForOrg('consumerId', { page: 1, 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._links.self.href).toBe(EVENTS_BASE_URL + '/events/consumerId/registrations?page=1&size=2') | ||
expect(res._links.first.href).toBe(EVENTS_BASE_URL + '/events/consumerId/registrations?page=0&size=2') | ||
expect(res._links.last.href).toBe(EVENTS_BASE_URL + '/events/consumerId/registrations?page=19&size=2') | ||
expect(res._links.prev.href).toBe(EVENTS_BASE_URL + '/events/consumerId/registrations?page=0&size=2') | ||
expect(res._embedded.registrations.length).toBe(2) | ||
@@ -518,10 +551,13 @@ expect(res.page.numberOfElements).toBe(2) | ||
.catch(e => { | ||
// eslint-disable-next-line jest/no-conditional-expect | ||
expect(e.name).toEqual(error.name) | ||
// eslint-disable-next-line jest/no-conditional-expect | ||
expect(e.code).toEqual(error.code) | ||
}) | ||
expect(fetchRetry.exponentialBackoff).toHaveBeenCalledWith( | ||
EVENTS_BASE_URL + '/consumerId/projectId/workspaceId/registrations/registrationId', | ||
EVENTS_BASE_URL + '/events/consumerId/projectId/workspaceId/registrations/registrationId', | ||
{ | ||
body: undefined, | ||
headers: { | ||
Accept: 'application/hal+json', | ||
Authorization: '***', | ||
@@ -585,3 +621,5 @@ 'Content-Type': 'application/json', | ||
.catch(e => { | ||
// eslint-disable-next-line jest/no-conditional-expect | ||
expect(e.name).toEqual(error.name) | ||
// eslint-disable-next-line jest/no-conditional-expect | ||
expect(e.code).toEqual(error.code) | ||
@@ -649,2 +687,9 @@ }) | ||
}) | ||
it('204 response on fetch from journal with invalid retry after', async () => { | ||
const sdkClient = await createSdkClient() | ||
exponentialBackoffMockReturnValue(undefined, mock.data.journalResponseHeader204InvalidTime) | ||
const res2 = await sdkClient.getEventsFromJournal(journalUrl) | ||
expect(res2.link.next).toBe('http://journal-url/events-fast/organizations/orgId/integrations/integId/regId?since=position-1') | ||
expect(res2.retryAfter).toBe(undefined) | ||
}) | ||
it('204 response on fetch from journal with retry after as date time string', async () => { | ||
@@ -688,3 +733,5 @@ const sdkClient = await createSdkClient() | ||
.catch(e => { | ||
// eslint-disable-next-line jest/no-conditional-expect | ||
expect(e.name).toEqual(error.name) | ||
// eslint-disable-next-line jest/no-conditional-expect | ||
expect(e.code).toEqual(error.code) | ||
@@ -769,17 +816,17 @@ }) | ||
async function checkErrorResponse (fn, error, args = []) { | ||
const client = await createSdkClient() | ||
return new Promise((resolve, reject) => { | ||
(client[fn].apply(client, args)) | ||
.then(res => { | ||
reject(new Error(' No error response')) | ||
}) | ||
.catch(e => { | ||
expect(e.name).toEqual(error.name) | ||
expect(e.code).toEqual(error.code) | ||
if (e.code === 409) { | ||
expect(e.conflictingId).toEqual(CONFLICTING_ID) | ||
} | ||
resolve() | ||
}) | ||
}) | ||
let e | ||
try { | ||
const client = await createSdkClient() | ||
await client[fn](args[0], args[1]) | ||
// should never get here | ||
e = new Error('No error response') | ||
} catch (err) { | ||
e = err | ||
} | ||
expect(e.name).toEqual(error.name) | ||
expect(e.code).toEqual(error.code) | ||
if (e.code === 409) { | ||
expect(e.conflictingId).toEqual(CONFLICTING_ID) | ||
} | ||
} |
@@ -53,3 +53,3 @@ /* | ||
describe('Subscribing and unsubscribing to journal', () => { | ||
test('Test subscribing and unsubscribing to journal ', async () => { | ||
test('subscribing and unsubscribing to journal', async () => { | ||
const eventsClient = await createSdkClient() | ||
@@ -72,3 +72,3 @@ const journalling = new EventsConsumerFromJournal(eventsClient, | ||
describe('Polling for journal events', () => { | ||
it('Test polling journal once with events ', async () => { | ||
it('Test polling journal once with events', async () => { | ||
jest.useFakeTimers() | ||
@@ -96,3 +96,3 @@ const eventsClient = await createSdkClient() | ||
it('Test polling journal once with error on poll ', async () => { | ||
it('Test polling journal once with error on poll', async () => { | ||
jest.useFakeTimers() | ||
@@ -126,3 +126,3 @@ const eventsClient = await createSdkClient() | ||
it(' Test polling journal twice no content ', async () => { | ||
it('Test polling journal twice no content', async () => { | ||
jest.useFakeTimers() | ||
@@ -136,13 +136,13 @@ const eventsClient = await createSdkClient() | ||
jest.advanceTimersByTime(1) | ||
expect(journalling.__checkPollingCondition).toBeCalled() | ||
expect(journalling.__checkPollingCondition).toHaveBeenCalled() | ||
expect(journalling.__checkPollingCondition).toHaveBeenCalledTimes(1) | ||
jest.advanceTimersByTime(1) | ||
expect(eventsClient.getEventsFromJournal).toBeCalled() | ||
expect(eventsClient.getEventsFromJournal).toHaveBeenCalled() | ||
expect(eventsClient.getEventsFromJournal).toHaveBeenCalledTimes(1) | ||
await Promise.resolve() | ||
jest.advanceTimersByTime(10000) | ||
expect(journalling.__checkPollingCondition).toBeCalled() | ||
expect(journalling.__checkPollingCondition).toHaveBeenCalled() | ||
expect(journalling.__checkPollingCondition).toHaveBeenCalledTimes(2) | ||
jest.advanceTimersByTime(1) | ||
expect(eventsClient.getEventsFromJournal).toBeCalled() | ||
expect(eventsClient.getEventsFromJournal).toHaveBeenCalled() | ||
expect(eventsClient.getEventsFromJournal).toHaveBeenCalledTimes(2) | ||
@@ -152,3 +152,3 @@ jest.clearAllTimers() | ||
}) | ||
it(' Test polling journal twice no content and default timeout ', async () => { | ||
it('Test polling journal twice no content and default timeout', async () => { | ||
jest.useFakeTimers() | ||
@@ -163,13 +163,13 @@ const eventsClient = await createSdkClient() | ||
jest.advanceTimersByTime(1) | ||
expect(journalling.__checkPollingCondition).toBeCalled() | ||
expect(journalling.__checkPollingCondition).toHaveBeenCalled() | ||
expect(journalling.__checkPollingCondition).toHaveBeenCalledTimes(1) | ||
jest.advanceTimersByTime(1) | ||
expect(eventsClient.getEventsFromJournal).toBeCalled() | ||
expect(eventsClient.getEventsFromJournal).toHaveBeenCalled() | ||
expect(eventsClient.getEventsFromJournal).toHaveBeenCalledTimes(1) | ||
await Promise.resolve() | ||
jest.advanceTimersByTime(2000) | ||
expect(journalling.__checkPollingCondition).toBeCalled() | ||
expect(journalling.__checkPollingCondition).toHaveBeenCalled() | ||
expect(journalling.__checkPollingCondition).toHaveBeenCalledTimes(2) | ||
jest.advanceTimersByTime(1) | ||
expect(eventsClient.getEventsFromJournal).toBeCalled() | ||
expect(eventsClient.getEventsFromJournal).toHaveBeenCalled() | ||
expect(eventsClient.getEventsFromJournal).toHaveBeenCalledTimes(2) | ||
@@ -180,3 +180,3 @@ jest.clearAllTimers() | ||
it(' Test polling journal twice no content and custom timeout ', async () => { | ||
it('Test polling journal twice no content and custom timeout', async () => { | ||
jest.useFakeTimers() | ||
@@ -191,6 +191,6 @@ const eventsClient = await createSdkClient() | ||
jest.advanceTimersByTime(1) | ||
expect(journalling.__checkPollingCondition).toBeCalled() | ||
expect(journalling.__checkPollingCondition).toHaveBeenCalled() | ||
expect(journalling.__checkPollingCondition).toHaveBeenCalledTimes(1) | ||
jest.advanceTimersByTime(1) | ||
expect(eventsClient.getEventsFromJournal).toBeCalled() | ||
expect(eventsClient.getEventsFromJournal).toHaveBeenCalled() | ||
expect(eventsClient.getEventsFromJournal).toHaveBeenCalledTimes(1) | ||
@@ -203,3 +203,3 @@ await Promise.resolve() | ||
jest.advanceTimersByTime(1) | ||
expect(eventsClient.getEventsFromJournal).toBeCalled() | ||
expect(eventsClient.getEventsFromJournal).toHaveBeenCalled() | ||
expect(eventsClient.getEventsFromJournal).toHaveBeenCalledTimes(2) | ||
@@ -212,3 +212,3 @@ jest.clearAllTimers() | ||
describe('No subscribers to journalling', () => { | ||
it(' Test no subscribers ', async () => { | ||
it('Test no subscribers', async () => { | ||
jest.useFakeTimers() | ||
@@ -220,3 +220,3 @@ const eventsClient = await createSdkClient() | ||
jest.advanceTimersByTime(1) | ||
expect(journalling.__checkPollingCondition).toBeCalled() | ||
expect(journalling.__checkPollingCondition).toHaveBeenCalled() | ||
expect(journalling.__checkPollingCondition).toHaveBeenCalledTimes(1) | ||
@@ -223,0 +223,0 @@ jest.advanceTimersByTime(2000) |
@@ -753,2 +753,18 @@ /* | ||
const journalResponseHeader204InvalidTime = { | ||
status: 204, | ||
headers: { | ||
link: [ | ||
'</events/organizations/orgId/integrations/integId/regId>; rel="events"', | ||
'</events-fast/organizations/orgId/integrations/integId/regId?since=position-1>; rel="next"', | ||
'</count/organizations/orgId/integrations/integId/regId?since=position-1>; rel="count"', | ||
'</events/organizations/orgId/integrations/integId/regId?latest=true>; rel="latest"', | ||
'</events/organizations/orgId/integrations/integId/regId?since={position}&limit={count}>; rel="page"', | ||
'</events/organizations/orgId/integrations/integId/regId?seek={duration}&limit={count}>; rel="seek"', | ||
'</events-validate/organizations/orgId/integrations/integId/regId?since=position-1>; rel="validate"' | ||
], | ||
'retry-after': 'not::a::valid::date' | ||
} | ||
} | ||
const journalResponseHeader204MissingLinks = { | ||
@@ -907,2 +923,3 @@ status: 204, | ||
journalResponseHeader204DateTime, | ||
journalResponseHeader204InvalidTime, | ||
journalPollerResponse, | ||
@@ -909,0 +926,0 @@ journalPollerNoContentResponse, |
@@ -84,3 +84,5 @@ /* | ||
.catch(e => { | ||
// eslint-disable-next-line jest/no-conditional-expect | ||
expect(e instanceof Error).toBe(true) | ||
// eslint-disable-next-line jest/no-conditional-expect | ||
expect(e.message).toEqual('invalid url') | ||
@@ -101,3 +103,5 @@ }) | ||
.catch(e => { | ||
// eslint-disable-next-line jest/no-conditional-expect | ||
expect(e instanceof Error).toBe(true) | ||
// eslint-disable-next-line jest/no-conditional-expect | ||
expect(e.message).toEqual('invalid url') | ||
@@ -114,3 +118,5 @@ }) | ||
.catch(e => { | ||
// eslint-disable-next-line jest/no-conditional-expect | ||
expect(e instanceof Error).toBe(true) | ||
// eslint-disable-next-line jest/no-conditional-expect | ||
expect(e.message).toEqual('lib state get error') | ||
@@ -117,0 +123,0 @@ }) |
@@ -1,3 +0,1 @@ | ||
import {Observable} from "rxjs"; | ||
/** | ||
@@ -45,15 +43,15 @@ * @property [timeout] - Http request timeout in ms (optional) | ||
*/ | ||
httpOptions: EventsCoreAPIOptions; | ||
httpOptions: any; | ||
/** | ||
* The organization id from your integration | ||
*/ | ||
organizationId: string; | ||
organizationId: any; | ||
/** | ||
* The api key from your integration | ||
*/ | ||
apiKey: string; | ||
apiKey: any; | ||
/** | ||
* The JWT Token for the integration with IO Management API scope | ||
*/ | ||
accessToken: string; | ||
accessToken: any; | ||
/** | ||
@@ -238,3 +236,3 @@ * Fetch all the providers | ||
*/ | ||
getEventsObservableFromJournal(journalUrl: string, eventsJournalOptions?: EventsJournalOptions, eventsJournalPollingOptions?: EventsJournalPollingOptions): Observable<object>; | ||
getEventsObservableFromJournal(journalUrl: string, eventsJournalOptions?: EventsJournalOptions, eventsJournalPollingOptions?: EventsJournalPollingOptions): Observable; | ||
/** | ||
@@ -251,3 +249,3 @@ * Authenticating events by verifying digital signature | ||
*/ | ||
verifyDigitalSignatureForEvent(event: any, recipientClientId: string, signatureOptions?: SignatureOptions): boolean; | ||
verifyDigitalSignatureForEvent(event: any, recipientClientId: any, signatureOptions: any): boolean; | ||
} | ||
@@ -371,14 +369,1 @@ | ||
/** | ||
* @typedef {object} SignatureOptions | ||
* @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; | ||
digiSignature2: string; | ||
publicKeyUrl1: string; | ||
publicKeyUrl2: string; | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
240368
4024
2
690
+ Added@adobe/aio-lib-env@^2.0.0
+ Added@adobe/aio-lib-core-config@4.0.0-pre.2024-01-08.d04a66d95.0.1(transitive)
+ Added@adobe/aio-lib-core-errors@3.1.1-pre.2024-01-08.6d76060c4.0.1(transitive)
+ Added@adobe/aio-lib-core-logging@2.0.1-pre.2024-01-08.sha-cbe78b133.0.2(transitive)
+ Added@adobe/aio-lib-core-networking@4.1.0-pre.2024-01-08.87a2e7f95.0.3(transitive)
+ Added@adobe/aio-lib-env@3.0.1(transitive)
+ Added@adobe/aio-lib-state@3.0.1-pre.2024-04-17.sha-9582f465(transitive)
+ Addedajv@8.17.1(transitive)
+ Addedargparse@2.0.1(transitive)
+ Addeddotenv@16.3.1(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-uri@3.0.5(transitive)
+ Addedfetch-retry@5.0.6(transitive)
+ Addedjs-yaml@4.1.0(transitive)
+ Addedjson-schema-traverse@1.0.0(transitive)
+ Addedrequire-from-string@2.0.2(transitive)
+ Addedrxjs@7.8.1(transitive)
- Removedcross-fetch@^3.0.4
- Removed@adobe/aio-lib-core-errors@3.1.1(transitive)
- Removed@adobe/aio-lib-core-networking@3.0.0(transitive)
- Removed@adobe/aio-lib-core-tvm@3.0.1(transitive)
- Removed@adobe/aio-lib-state@2.1.2(transitive)
- Removed@azure/abort-controller@1.1.02.1.2(transitive)
- Removed@azure/core-auth@1.9.0(transitive)
- Removed@azure/core-rest-pipeline@1.18.2(transitive)
- Removed@azure/core-tracing@1.2.0(transitive)
- Removed@azure/core-util@1.11.0(transitive)
- Removed@azure/cosmos@3.17.3(transitive)
- Removed@azure/logger@1.1.4(transitive)
- Removed@hapi/hoek@9.3.0(transitive)
- Removed@hapi/topo@5.1.0(transitive)
- Removed@sideway/address@4.1.5(transitive)
- Removed@sideway/formula@3.0.1(transitive)
- Removed@sideway/pinpoint@2.0.0(transitive)
- Removedat-least-node@1.0.0(transitive)
- Removedcross-fetch@3.2.0(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedfetch-retry@3.2.3(transitive)
- Removedfs-extra@9.1.0(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedjoi@17.13.3(transitive)
- Removedjsbi@3.2.5(transitive)
- Removedjsonfile@6.1.0(transitive)
- Removednode-abort-controller@3.1.1(transitive)
- Removedpriorityqueuejs@1.0.0(transitive)
- Removedrxjs@6.6.7(transitive)
- Removedsemaphore@1.1.0(transitive)
- Removedtslib@1.14.1(transitive)
- Removeduniversal-user-agent@6.0.1(transitive)
- Removeduniversalify@2.0.1(transitive)
- Removedupath@1.2.0(transitive)
- Removeduuid@8.3.2(transitive)
Updated@adobe/aio-lib-state@next
Updatedrxjs@^7.8.1