diff --git a/packages/core-app-api/src/apis/implementations/StorageApi/PersistentStorage.test.ts b/packages/core-app-api/src/apis/implementations/StorageApi/PersistentStorage.test.ts index 3157395bcf..79da01ca41 100644 --- a/packages/core-app-api/src/apis/implementations/StorageApi/PersistentStorage.test.ts +++ b/packages/core-app-api/src/apis/implementations/StorageApi/PersistentStorage.test.ts @@ -65,7 +65,7 @@ describe('Persistent Storage API', () => { server.use( rest.get( - `${mockBaseUrl}/buckets/:bucket/:key`, + `${mockBaseUrl}/buckets/:bucket/keys/:key`, async (_req, res, ctx) => { return res(ctx.json({ value: 'a' })); }, @@ -85,13 +85,16 @@ describe('Persistent Storage API', () => { const dummyValue = 'a'; server.use( - rest.put(`${mockBaseUrl}/buckets/:bucket/:key`, async (req, res, ctx) => { - const body = await req.json(); - const data = { value: JSON.stringify(dummyValue) }; - expect(body).toEqual(data); + rest.put( + `${mockBaseUrl}/buckets/:bucket/keys/:key`, + async (req, res, ctx) => { + const body = await req.json(); + const data = { value: JSON.stringify(dummyValue) }; + expect(body).toEqual(data); - return res(ctx.json(data)); - }), + return res(ctx.json(data)); + }, + ), ); await storage.set('my-key', dummyValue); @@ -105,13 +108,16 @@ describe('Persistent Storage API', () => { }; server.use( - rest.put(`${mockBaseUrl}/buckets/:bucket/:key`, async (req, res, ctx) => { - const body = await req.json(); - const data = { value: JSON.stringify(dummyValue) }; - expect(body).toEqual(data); + rest.put( + `${mockBaseUrl}/buckets/:bucket/keys/:key`, + async (req, res, ctx) => { + const body = await req.json(); + const data = { value: JSON.stringify(dummyValue) }; + expect(body).toEqual(data); - return res(ctx.json(data)); - }), + return res(ctx.json(data)); + }, + ), ); await storage.set('my-key', dummyValue); @@ -125,13 +131,16 @@ describe('Persistent Storage API', () => { const mockData = { hello: 'im a great new value' }; server.use( - rest.put(`${mockBaseUrl}/buckets/:bucket/:key`, async (req, res, ctx) => { - const body = await req.json(); - const data = { value: JSON.stringify(mockData) }; - expect(body).toEqual(data); + rest.put( + `${mockBaseUrl}/buckets/:bucket/keys/:key`, + async (req, res, ctx) => { + const body = await req.json(); + const data = { value: JSON.stringify(mockData) }; + expect(body).toEqual(data); - return res(ctx.json(data)); - }), + return res(ctx.json(data)); + }, + ), ); await new Promise(resolve => { @@ -166,7 +175,7 @@ describe('Persistent Storage API', () => { server.use( rest.delete( - `${mockBaseUrl}/buckets/:bucket/:key`, + `${mockBaseUrl}/buckets/:bucket/keys/:key`, async (_req, res, ctx) => { return res(ctx.status(204)); }, @@ -202,23 +211,29 @@ describe('Persistent Storage API', () => { const selectedKeyNextHandler = jest.fn(); server.use( - rest.put(`${mockBaseUrl}/buckets/:bucket/:key`, async (req, res, ctx) => { - const { bucket, key } = req.params; - const { value } = await req.json(); + rest.put( + `${mockBaseUrl}/buckets/:bucket/keys/:key`, + async (req, res, ctx) => { + const { bucket, key } = req.params; + const { value } = await req.json(); - expect(bucket).toEqual('default.profile.something.deep'); - expect(key).toEqual('test2'); + expect(bucket).toEqual('default.profile.something.deep'); + expect(key).toEqual('test2'); - return res(ctx.json({ value })); - }), - rest.get(`${mockBaseUrl}/buckets/:bucket/:key`, async (req, res, ctx) => { - const { bucket, key } = req.params; + return res(ctx.json({ value })); + }, + ), + rest.get( + `${mockBaseUrl}/buckets/:bucket/keys/:key`, + async (req, res, ctx) => { + const { bucket, key } = req.params; - expect(bucket).toEqual('default.profile/something'); - expect(key).toEqual('deep/test2'); + expect(bucket).toEqual('default.profile/something'); + expect(key).toEqual('deep/test2'); - return res(ctx.status(404)); - }), + return res(ctx.status(404)); + }, + ), ); // when getting key test2 it will translate to default.profile.something.deep/test2 @@ -259,14 +274,17 @@ describe('Persistent Storage API', () => { }); server.use( - rest.get(`${mockBaseUrl}/buckets/:bucket/:key`, async (req, res, ctx) => { - const { bucket, key } = req.params; + rest.get( + `${mockBaseUrl}/buckets/:bucket/keys/:key`, + async (req, res, ctx) => { + const { bucket, key } = req.params; - expect(bucket).toEqual('Test.Mock.Thing'); - expect(key).toEqual('key'); + expect(bucket).toEqual('Test.Mock.Thing'); + expect(key).toEqual('key'); - return res(ctx.text('{ invalid: json string }')); - }), + return res(ctx.text('{ invalid: json string }')); + }, + ), ); await new Promise(resolve => { @@ -297,7 +315,7 @@ describe('Persistent Storage API', () => { server.use( rest.get( - `${mockBaseUrl}/buckets/:bucket/:key`, + `${mockBaseUrl}/buckets/:bucket/keys/:key`, async (_req, res, ctx) => { return res(ctx.text(JSON.stringify({ value: JSON.stringify(data) }))); }, diff --git a/packages/core-app-api/src/apis/implementations/StorageApi/PersistentStorage.ts b/packages/core-app-api/src/apis/implementations/StorageApi/PersistentStorage.ts index 38a986863e..b23ecd2b3f 100644 --- a/packages/core-app-api/src/apis/implementations/StorageApi/PersistentStorage.ts +++ b/packages/core-app-api/src/apis/implementations/StorageApi/PersistentStorage.ts @@ -182,7 +182,7 @@ export class PersistentStorage implements StorageApi { const baseUrl = await this.discoveryApi.getBaseUrl('user-settings'); const encodedNamespace = encodeURIComponent(this.namespace); const encodedKey = encodeURIComponent(key); - return `${baseUrl}/buckets/${encodedNamespace}/${encodedKey}`; + return `${baseUrl}/buckets/${encodedNamespace}/keys/${encodedKey}`; } private async notifyChanges(snapshot: StorageValueSnapshot) { diff --git a/plugins/user-settings-backend/src/service/router.test.ts b/plugins/user-settings-backend/src/service/router.test.ts index 21aff9f164..a0e5403612 100644 --- a/plugins/user-settings-backend/src/service/router.test.ts +++ b/plugins/user-settings-backend/src/service/router.test.ts @@ -195,7 +195,7 @@ describe('createRouter', () => { }); }); - describe('GET /buckets/:bucket/:key', () => { + describe('GET /buckets/:bucket/keys/:key', () => { it('returns ok', async () => { const setting = { bucket: 'my-bucket', key: 'my-key', value: 'a' }; authenticateMock.mockResolvedValue({ @@ -205,7 +205,7 @@ describe('createRouter', () => { userSettingsStore.get.mockResolvedValue(setting); const responses = await request(app) - .get('/buckets/my-bucket/my-key') + .get('/buckets/my-bucket/keys/my-key') .set('Authorization', 'Bearer foo'); expect(responses.status).toEqual(200); @@ -221,14 +221,16 @@ describe('createRouter', () => { }); it('returns an error if the Authorization header is missing', async () => { - const responses = await request(app).get('/buckets/my-bucket/my-key'); + const responses = await request(app).get( + '/buckets/my-bucket/keys/my-key', + ); expect(responses.status).toEqual(401); expect(userSettingsStore.get).not.toHaveBeenCalled(); }); }); - describe('DELETE /buckets/:bucket/:key', () => { + describe('DELETE /buckets/:bucket/keys/:key', () => { it('returns ok', async () => { authenticateMock.mockResolvedValue({ identity: { userEntityRef: 'user-1' }, @@ -237,7 +239,7 @@ describe('createRouter', () => { userSettingsStore.delete.mockResolvedValue(); const responses = await request(app) - .delete('/buckets/my-bucket/my-key') + .delete('/buckets/my-bucket/keys/my-key') .set('Authorization', 'Bearer foo'); expect(responses.status).toEqual(204); @@ -252,14 +254,16 @@ describe('createRouter', () => { }); it('returns an error if the Authorization header is missing', async () => { - const responses = await request(app).delete('/buckets/my-bucket/my-key'); + const responses = await request(app).delete( + '/buckets/my-bucket/keys/my-key', + ); expect(responses.status).toEqual(401); expect(userSettingsStore.delete).not.toHaveBeenCalled(); }); }); - describe('PUT /buckets/:bucket/:key', () => { + describe('PUT /buckets/:bucket/keys/:key', () => { it('returns ok', async () => { const setting = { bucket: 'my-bucket', key: 'my-key', value: 'a' }; authenticateMock.mockResolvedValue({ @@ -270,7 +274,7 @@ describe('createRouter', () => { userSettingsStore.get.mockResolvedValue(setting); const responses = await request(app) - .put('/buckets/my-bucket/my-key') + .put('/buckets/my-bucket/keys/my-key') .set('Authorization', 'Bearer foo') .send({ value: 'a' }); @@ -299,7 +303,7 @@ describe('createRouter', () => { }); const responses = await request(app) - .put('/buckets/my-bucket/my-key') + .put('/buckets/my-bucket/keys/my-key') .set('Authorization', 'Bearer foo') .send({ value: { invalid: 'because not a string' } }); @@ -310,7 +314,9 @@ describe('createRouter', () => { }); it('returns an error if the Authorization header is missing', async () => { - const responses = await request(app).get('/buckets/my-bucket/my-key'); + const responses = await request(app).get( + '/buckets/my-bucket/keys/my-key', + ); expect(responses.status).toEqual(401); expect(userSettingsStore.get).not.toHaveBeenCalled(); diff --git a/plugins/user-settings-backend/src/service/router.ts b/plugins/user-settings-backend/src/service/router.ts index 588759c929..f51e38c10a 100644 --- a/plugins/user-settings-backend/src/service/router.ts +++ b/plugins/user-settings-backend/src/service/router.ts @@ -109,7 +109,7 @@ export async function createRouter( }); // get a single value - router.get('/buckets/:bucket/:key', async (req, res) => { + router.get('/buckets/:bucket/keys/:key', async (req, res) => { const userEntityRef = await getUserEntityRef(req); const { bucket, key } = req.params; @@ -121,7 +121,7 @@ export async function createRouter( }); // set a single value - router.put('/buckets/:bucket/:key', async (req, res) => { + router.put('/buckets/:bucket/keys/:key', async (req, res) => { const userEntityRef = await getUserEntityRef(req); const { bucket, key } = req.params; const { value } = req.body; @@ -144,7 +144,7 @@ export async function createRouter( }); // get a single value - router.delete('/buckets/:bucket/:key', async (req, res) => { + router.delete('/buckets/:bucket/keys/:key', async (req, res) => { const userEntityRef = await getUserEntityRef(req); const { bucket, key } = req.params;