Skip to content

Commit

Permalink
chore!: remove api version from path (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
moritzraho authored Jun 14, 2024
1 parent 647d97e commit f41cdeb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 34 deletions.
6 changes: 3 additions & 3 deletions lib/AdobeState.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const logger = require('@adobe/aio-lib-core-logging')('@adobe/aio-lib-state', {
const { HttpExponentialBackoff } = require('@adobe/aio-lib-core-networking')
const url = require('node:url')
const { getCliEnv } = require('@adobe/aio-lib-env')
const { REGEX_PATTERN_STORE_KEY, API_VERSION, HEADER_KEY_EXPIRES, CUSTOM_ENDPOINT, ENDPOINTS, ALLOWED_REGIONS } = require('./constants')
const { REGEX_PATTERN_STORE_KEY, HEADER_KEY_EXPIRES, CUSTOM_ENDPOINT, ENDPOINTS, ALLOWED_REGIONS } = require('./constants')
const Ajv = require('ajv')

/* *********************************** typedefs *********************************** */
Expand Down Expand Up @@ -167,9 +167,9 @@ class AdobeState {
let urlString

if (key) {
urlString = `${this.endpoint}/${API_VERSION}/containers/${this.namespace}/data/${key}`
urlString = `${this.endpoint}/containers/${this.namespace}/data/${key}`
} else {
urlString = `${this.endpoint}/${API_VERSION}/containers/${this.namespace}`
urlString = `${this.endpoint}/containers/${this.namespace}`
}

logger.debug('requestUrl string', urlString)
Expand Down
2 changes: 0 additions & 2 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const ALLOWED_REGIONS = [ // first region is the default region

// can be overwritten by env
const {
AIO_STATE_API_VERSION: API_VERSION = 'v1beta1',
// needs protocol
AIO_STATE_ENDPOINT: CUSTOM_ENDPOINT = null // make sure users can point to any instance (e.g. for testing)
} = process.env
Expand All @@ -50,7 +49,6 @@ const REGEX_PATTERN_STORE_KEY = `^[a-zA-Z0-9-_.]{1,${MAX_KEY_SIZE}}$`

module.exports = {
ALLOWED_REGIONS,
API_VERSION,
ENDPOINTS,
CUSTOM_ENDPOINT,
MAX_KEY_SIZE,
Expand Down
41 changes: 12 additions & 29 deletions test/AdobeState.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const { HttpExponentialBackoff } = require('@adobe/aio-lib-core-networking')
const { AdobeState } = require('../lib/AdobeState')
const querystring = require('node:querystring')
const { Buffer } = require('node:buffer')
const { ALLOWED_REGIONS, HEADER_KEY_EXPIRES, API_VERSION } = require('../lib/constants')
const { ALLOWED_REGIONS, HEADER_KEY_EXPIRES } = require('../lib/constants')

// constants //////////////////////////////////////////////////////////

Expand Down Expand Up @@ -77,7 +77,6 @@ jest.mock('@adobe/aio-lib-env', () => {

beforeEach(() => {
delete process.env.AIO_STATE_ENDPOINT
delete process.env.AIO_STATE_API_VERSION
mockCLIEnv.mockReturnValue(DEFAULT_ENV)
mockExponentialBackoff.mockReset()
})
Expand Down Expand Up @@ -376,7 +375,7 @@ describe('private methods', () => {
const store = await AdobeState.init(fakeCredentials)

const url = store.createRequestUrl()
expect(url).toEqual(`https://storage-state-${DEFAULT_REGION}.app-builder.adp.adobe.io/${API_VERSION}/containers/${fakeCredentials.namespace}`)
expect(url).toEqual(`https://storage-state-${DEFAULT_REGION}.app-builder.adp.adobe.io/containers/${fakeCredentials.namespace}`)
})

test('no params, custom endpoint', async () => {
Expand All @@ -388,7 +387,7 @@ describe('private methods', () => {
store.endpoint = 'http://localhost'

const url = store.createRequestUrl()
expect(url).toEqual(`${store.endpoint}/${API_VERSION}/containers/${fakeCredentials.namespace}`)
expect(url).toEqual(`${store.endpoint}/containers/${fakeCredentials.namespace}`)
})

test('key set, no query params', async () => {
Expand All @@ -400,7 +399,7 @@ describe('private methods', () => {
const store = await AdobeState.init(fakeCredentials)

const url = store.createRequestUrl(key)
expect(url).toEqual(`https://storage-state-${DEFAULT_REGION}.stg.app-builder.adp.adobe.io/${API_VERSION}/containers/${fakeCredentials.namespace}/data/${key}`)
expect(url).toEqual(`https://storage-state-${DEFAULT_REGION}.stg.app-builder.adp.adobe.io/containers/${fakeCredentials.namespace}/data/${key}`)
})

test('key set, some query params', async () => {
Expand All @@ -416,7 +415,7 @@ describe('private methods', () => {
const store = await AdobeState.init(fakeCredentials)

const url = store.createRequestUrl(key, queryParams)
expect(url).toEqual(`https://storage-state-${DEFAULT_REGION}.stg.app-builder.adp.adobe.io/${API_VERSION}/containers/${fakeCredentials.namespace}/data/${key}?${querystring.stringify(queryParams)}`)
expect(url).toEqual(`https://storage-state-${DEFAULT_REGION}.stg.app-builder.adp.adobe.io/containers/${fakeCredentials.namespace}/data/${key}?${querystring.stringify(queryParams)}`)
})

test('no params, region set', async () => {
Expand All @@ -428,7 +427,7 @@ describe('private methods', () => {
const store = await AdobeState.init({ ...fakeCredentials, region })

const url = store.createRequestUrl()
expect(url).toEqual(`https://storage-state-${region}.app-builder.adp.adobe.io/${API_VERSION}/containers/${fakeCredentials.namespace}`)
expect(url).toEqual(`https://storage-state-${region}.app-builder.adp.adobe.io/containers/${fakeCredentials.namespace}`)
})

test('no params, region invalid', async () => {
Expand All @@ -441,22 +440,20 @@ describe('private methods', () => {
})
})

test('custom AIO_STATE_API_VERSION, default env and region', async () => {
test('default env and region', async () => {
jest.resetModules()
process.env.AIO_STATE_API_VERSION = 'v5'
const env = PROD_ENV
mockCLIEnv.mockReturnValue(env)

// need to instantiate a new store, when env changes
const customAdobeState = require('../lib/AdobeState').AdobeState
const store = await customAdobeState.init({ ...fakeCredentials })
const url = store.createRequestUrl()
expect(url).toEqual(`https://storage-state-amer.app-builder.adp.adobe.io/v5/containers/${fakeCredentials.namespace}`)
expect(url).toEqual(`https://storage-state-amer.app-builder.adp.adobe.io/containers/${fakeCredentials.namespace}`)
})

test('custom AIO_STATE_API_VERSION, stage, emea', async () => {
test('custom stage, emea', async () => {
jest.resetModules()
process.env.AIO_STATE_API_VERSION = 'v5'
const region = 'emea'
const env = STAGE_ENV
mockCLIEnv.mockReturnValue(env)
Expand All @@ -465,7 +462,7 @@ describe('private methods', () => {
const customAdobeState = require('../lib/AdobeState').AdobeState
const store = await customAdobeState.init({ ...fakeCredentials, region })
const url = store.createRequestUrl()
expect(url).toEqual(`https://storage-state-${region}.stg.app-builder.adp.adobe.io/v5/containers/${fakeCredentials.namespace}`)
expect(url).toEqual(`https://storage-state-${region}.stg.app-builder.adp.adobe.io/containers/${fakeCredentials.namespace}`)
})

test('custom AIO_STATE_ENDPOINT', async () => {
Expand All @@ -476,7 +473,7 @@ describe('private methods', () => {
const customAdobeState = require('../lib/AdobeState').AdobeState
const store = await customAdobeState.init({ ...fakeCredentials })
const url = store.createRequestUrl()
expect(url).toEqual(`https://custom.abc.com/${API_VERSION}/containers/${fakeCredentials.namespace}`)
expect(url).toEqual(`https://custom.abc.com/containers/${fakeCredentials.namespace}`)
})

test('custom AIO_STATE_ENDPOINT, env and region should have no effect', async () => {
Expand All @@ -490,20 +487,6 @@ describe('private methods', () => {
const customAdobeState = require('../lib/AdobeState').AdobeState
const store = await customAdobeState.init({ ...fakeCredentials, region })
const url = store.createRequestUrl()
expect(url).toEqual(`https://custom.abc.com/${API_VERSION}/containers/${fakeCredentials.namespace}`)
})

test('custom AIO_STATE_ENDPOINT, custom AIO_STATE_API_VERSION', async () => {
jest.resetModules()
process.env.AIO_STATE_ENDPOINT = 'https://custom.abc.com'
process.env.AIO_STATE_API_VERSION = 'v5'
const env = PROD_ENV
mockCLIEnv.mockReturnValue(env)

// need to instantiate a new store, when env changes
const customAdobeState = require('../lib/AdobeState').AdobeState
const store = await customAdobeState.init({ ...fakeCredentials })
const url = store.createRequestUrl()
expect(url).toEqual(`https://custom.abc.com/v5/containers/${fakeCredentials.namespace}`)
expect(url).toEqual(`https://custom.abc.com/containers/${fakeCredentials.namespace}`)
})
})

0 comments on commit f41cdeb

Please sign in to comment.