Skip to content

Commit 7e460fe

Browse files
committed
feat: support for the apac region
1 parent 2ce4a07 commit 7e460fe

File tree

3 files changed

+68
-9
lines changed

3 files changed

+68
-9
lines changed

lib/AdobeState.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ const {
2929
REQUEST_ID_HEADER,
3030
MIN_LIST_COUNT_HINT,
3131
REGEX_PATTERN_MATCH_KEY,
32-
MAX_TTL_SECONDS
32+
MAX_TTL_SECONDS,
33+
ALLOWED_STAGE_REGION
3334
} = require('./constants')
3435

3536
/* *********************************** typedefs *********************************** */
@@ -146,9 +147,10 @@ class AdobeState {
146147
* @private
147148
* @param {string} namespace the namespace for the Adobe State Store
148149
* @param {string} apikey the apikey for the Adobe State Store
150+
* @param {string} env the Adobe environment (AIO_CLI_ENV)
149151
* @param {('amer'|'apac'|'emea')} [region] the region for the Adobe State Store. defaults to 'amer'
150152
*/
151-
constructor (namespace, apikey, region) {
153+
constructor (namespace, apikey, env, region) {
152154
/** @private */
153155
this.namespace = namespace
154156
/** @private */
@@ -158,7 +160,7 @@ class AdobeState {
158160
/** @private */
159161
this.region = region
160162
/** @private */
161-
this.endpoint = this.getRegionalEndpoint(ENDPOINTS[getCliEnv()], region)
163+
this.endpoint = this.getRegionalEndpoint(ENDPOINTS[env], region)
162164
/** @private */
163165
this.fetchRetry = new HttpExponentialBackoff()
164166
}
@@ -228,6 +230,16 @@ class AdobeState {
228230
const cloned = utils.withHiddenFields(credentials, ['apikey'])
229231
logger.debug(`init AdobeState with ${JSON.stringify(cloned, null, 2)}`)
230232

233+
const env = getCliEnv()
234+
235+
if (env === 'stage' &&
236+
credentials.region && credentials.region !== ALLOWED_STAGE_REGION) {
237+
logAndThrow(new codes.ERROR_BAD_ARGUMENT({
238+
messageValues: `AIO_CLI_ENV=stage only supports the ${ALLOWED_STAGE_REGION} region.`,
239+
sdkDetails: cloned
240+
}))
241+
}
242+
231243
if (!credentials.region) {
232244
credentials.region = ALLOWED_REGIONS.at(0) // first item is the default
233245
}
@@ -253,7 +265,7 @@ class AdobeState {
253265
}))
254266
}
255267

256-
return new AdobeState(credentials.namespace, credentials.apikey, credentials.region)
268+
return new AdobeState(credentials.namespace, credentials.apikey, env, credentials.region)
257269
}
258270

259271
/* **************************** ADOBE STATE STORE OPERATORS ***************************** */

lib/constants.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ const ENDPOINT_PROD_INTERNAL = 'https://storage-state-<region>.app-builder.int.a
2222
const ENDPOINT_STAGE = 'https://storage-state-<region>.stg.app-builder.adp.adobe.io'
2323
const ENDPOINT_STAGE_INTERNAL = 'https://storage-state-<region>.stg.app-builder.adp.adobe.io'
2424

25+
// prod
2526
const ALLOWED_REGIONS = [ // first region is the default region
2627
'amer',
27-
'emea'
28-
// soon to come: 'apac'
28+
'emea',
29+
'apac'
2930
]
31+
const ALLOWED_STAGE_REGION = 'amer' // STAGE only supports one region
3032

3133
// can be overwritten by env
3234
const {
@@ -55,6 +57,7 @@ const REQUEST_ID_HEADER = 'x-request-id'
5557

5658
module.exports = {
5759
ALLOWED_REGIONS,
60+
ALLOWED_STAGE_REGION,
5861
ENDPOINTS,
5962
CUSTOM_ENDPOINT,
6063
MAX_KEY_SIZE,

test/AdobeState.test.js

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -721,17 +721,61 @@ describe('private methods', () => {
721721
expect(url).toEqual(`https://storage-state-amer.app-builder.adp.adobe.io/containers/${fakeCredentials.namespace}`)
722722
})
723723

724-
test('custom stage, emea', async () => {
724+
test('env=stage', async () => {
725+
jest.resetModules()
726+
const env = STAGE_ENV
727+
mockCLIEnv.mockReturnValue(env)
728+
729+
// need to instantiate a new store, when env changes
730+
const customAdobeState = require('../lib/AdobeState').AdobeState
731+
const store = await customAdobeState.init({ ...fakeCredentials })
732+
const url = store.createRequestUrl()
733+
expect(url).toEqual(`https://storage-state-amer.stg.app-builder.adp.adobe.io/containers/${fakeCredentials.namespace}`)
734+
})
735+
736+
test('env=stage && region!=amer', async () => {
725737
jest.resetModules()
726-
const region = 'emea'
727738
const env = STAGE_ENV
728739
mockCLIEnv.mockReturnValue(env)
729740

741+
// need to instantiate a new store, when env changes
742+
const customAdobeState = require('../lib/AdobeState').AdobeState
743+
await expect(customAdobeState.init({ ...fakeCredentials, region: 'emea' })).rejects.toThrow('[AdobeStateLib:ERROR_BAD_ARGUMENT] AIO_CLI_ENV=stage only supports the amer region.')
744+
await expect(customAdobeState.init({ ...fakeCredentials, region: 'apac' })).rejects.toThrow('[AdobeStateLib:ERROR_BAD_ARGUMENT] AIO_CLI_ENV=stage only supports the amer region.')
745+
await expect(customAdobeState.init({ ...fakeCredentials, region: 'amerr' })).rejects.toThrow('[AdobeStateLib:ERROR_BAD_ARGUMENT] AIO_CLI_ENV=stage only supports the amer region.')
746+
})
747+
748+
test('region=amer', async () => {
749+
jest.resetModules()
750+
const region = 'amer'
751+
752+
// need to instantiate a new store, when env changes
753+
const customAdobeState = require('../lib/AdobeState').AdobeState
754+
const store = await customAdobeState.init({ ...fakeCredentials, region })
755+
const url = store.createRequestUrl()
756+
expect(url).toEqual(`https://storage-state-${region}.app-builder.adp.adobe.io/containers/${fakeCredentials.namespace}`)
757+
})
758+
759+
test('region=emea', async () => {
760+
jest.resetModules()
761+
const region = 'emea'
762+
763+
// need to instantiate a new store, when env changes
764+
const customAdobeState = require('../lib/AdobeState').AdobeState
765+
const store = await customAdobeState.init({ ...fakeCredentials, region })
766+
const url = store.createRequestUrl()
767+
expect(url).toEqual(`https://storage-state-${region}.app-builder.adp.adobe.io/containers/${fakeCredentials.namespace}`)
768+
})
769+
770+
test('region=apac', async () => {
771+
jest.resetModules()
772+
const region = 'apac'
773+
730774
// need to instantiate a new store, when env changes
731775
const customAdobeState = require('../lib/AdobeState').AdobeState
732776
const store = await customAdobeState.init({ ...fakeCredentials, region })
733777
const url = store.createRequestUrl()
734-
expect(url).toEqual(`https://storage-state-${region}.stg.app-builder.adp.adobe.io/containers/${fakeCredentials.namespace}`)
778+
expect(url).toEqual(`https://storage-state-${region}.app-builder.adp.adobe.io/containers/${fakeCredentials.namespace}`)
735779
})
736780

737781
test('custom AIO_STATE_ENDPOINT', async () => {

0 commit comments

Comments
 (0)