From f20fd143bd13c383ac96f11cac01402df4aeb8c8 Mon Sep 17 00:00:00 2001 From: Jamie Howard Date: Wed, 4 Dec 2024 17:01:53 +0000 Subject: [PATCH 1/4] fix: pr review typos, always prepend api to baseurl and make package a module --- jest.config.js => jest.config.cjs | 0 package.json | 1 + src/auth/providers/users-permissions.ts | 2 +- src/http/client.ts | 2 +- tests/unit/auth/manager.test.ts | 2 +- tests/unit/auth/providers/api-token.test.ts | 2 +- tests/unit/http/client.test.ts | 2 +- tests/unit/sdk.test.ts | 4 ++-- 8 files changed, 8 insertions(+), 7 deletions(-) rename jest.config.js => jest.config.cjs (100%) diff --git a/jest.config.js b/jest.config.cjs similarity index 100% rename from jest.config.js rename to jest.config.cjs diff --git a/package.json b/package.json index 2460977..607c280 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "sdk", "js" ], + "type": "module", "repository": { "type": "git", "url": "https://github.com/strapi/sdk-js.git" diff --git a/src/auth/providers/users-permissions.ts b/src/auth/providers/users-permissions.ts index 2bc8bd9..cb00558 100644 --- a/src/auth/providers/users-permissions.ts +++ b/src/auth/providers/users-permissions.ts @@ -85,7 +85,7 @@ export class UsersPermissionsAuthProvider extends AbstractAuthProvider { try { const { baseURL } = httpClient; - const localAuthURL = `${baseURL}/api/auth/local`; + const localAuthURL = `${baseURL}/auth/local`; const request = new Request(localAuthURL, { method: 'POST', diff --git a/src/http/client.ts b/src/http/client.ts index 515da8b..c7668e2 100644 --- a/src/http/client.ts +++ b/src/http/client.ts @@ -62,7 +62,7 @@ export class HttpClient { setBaseURL(url: string): this { this._urlValidator.validate(url); - this._baseURL = url; + this._baseURL = `${url}/api`; return this; } diff --git a/tests/unit/auth/manager.test.ts b/tests/unit/auth/manager.test.ts index cdb2371..4ed00ca 100644 --- a/tests/unit/auth/manager.test.ts +++ b/tests/unit/auth/manager.test.ts @@ -49,7 +49,7 @@ describe('AuthManager', () => { expect(authManager.strategy).toBe(MockAuthProvider.identifier); }); - it('should not authenticated when strategy is not set', async () => { + it('should not be authenticated when strategy is not set', async () => { // Arrange const authManager = new AuthManager(new MockAuthProviderFactory()); diff --git a/tests/unit/auth/providers/api-token.test.ts b/tests/unit/auth/providers/api-token.test.ts index 3f466a6..0e3a520 100644 --- a/tests/unit/auth/providers/api-token.test.ts +++ b/tests/unit/auth/providers/api-token.test.ts @@ -56,7 +56,7 @@ describe('ApiTokenAuthProvider', () => { }); describe('Authenticate', () => { - it('should doe nothing when authenticate is called', async () => { + it('should do nothing when authenticate is called', async () => { // Arrange const token = 'abc-xyz'; const provider = new ApiTokenAuthProvider({ token }); diff --git a/tests/unit/http/client.test.ts b/tests/unit/http/client.test.ts index ecf7293..d70c261 100644 --- a/tests/unit/http/client.test.ts +++ b/tests/unit/http/client.test.ts @@ -47,7 +47,7 @@ describe('HttpClient', () => { // Assert expect(spy).toHaveBeenCalledWith(newBaseURL); - expect(httpClient.baseURL).toBe(newBaseURL); + expect(httpClient.baseURL).toBe(`${newBaseURL}/api`); }); it('setAuthStrategy should configure the authentication strategy', () => { diff --git a/tests/unit/sdk.test.ts b/tests/unit/sdk.test.ts index c95ef30..d14b61d 100644 --- a/tests/unit/sdk.test.ts +++ b/tests/unit/sdk.test.ts @@ -105,10 +105,10 @@ describe('StrapiSDK', () => { const sdk = new StrapiSDK(config, mockValidator, mockHttpClientFactory); // Act - const response = await sdk.fetch('/api/data'); + const response = await sdk.fetch('/data'); // Assert - expect(fetchSpy).toHaveBeenCalledWith('/api/data', undefined); + expect(fetchSpy).toHaveBeenCalledWith('/data', undefined); await expect(response.json()).resolves.toEqual({ ok: true }); }); From 935d16f056559a7792efac0c9640b9b2b9de4bc4 Mon Sep 17 00:00:00 2001 From: Jamie Howard Date: Thu, 5 Dec 2024 12:23:09 +0000 Subject: [PATCH 2/4] fix: expect content api url as baseurl --- src/http/client.ts | 2 +- src/index.ts | 2 +- src/sdk.ts | 2 +- tests/unit/http/client.test.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/http/client.ts b/src/http/client.ts index c7668e2..515da8b 100644 --- a/src/http/client.ts +++ b/src/http/client.ts @@ -62,7 +62,7 @@ export class HttpClient { setBaseURL(url: string): this { this._urlValidator.validate(url); - this._baseURL = `${url}/api`; + this._baseURL = url; return this; } diff --git a/src/index.ts b/src/index.ts index 9efc6b0..00522e2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,7 +12,7 @@ import type { StrapiSDKConfig } from './sdk'; * request dispatch, and response parsing for content management. * * @param config - The configuration for initializing the SDK. This should include the base URL - * of the Strapi backend instance that the SDK communicates with. The baseURL + * of the Strapi content API that the SDK communicates with. The baseURL * must be formatted with one of the supported protocols: `http` or `https`. * Additionally, optional authentication details can be specified within the config. * diff --git a/src/sdk.ts b/src/sdk.ts index 44e0d8c..fba800c 100644 --- a/src/sdk.ts +++ b/src/sdk.ts @@ -160,7 +160,7 @@ export class StrapiSDK * const sdk = createStrapiSDK({ baseURL: 'http://localhost:1337' ); * * // Perform a custom fetch query - * const response = await sdk.fetch('/api/categories'); + * const response = await sdk.fetch('/categories'); * * // Parse the categories into a readable JSON object * const categories = await response.json(); diff --git a/tests/unit/http/client.test.ts b/tests/unit/http/client.test.ts index d70c261..ecf7293 100644 --- a/tests/unit/http/client.test.ts +++ b/tests/unit/http/client.test.ts @@ -47,7 +47,7 @@ describe('HttpClient', () => { // Assert expect(spy).toHaveBeenCalledWith(newBaseURL); - expect(httpClient.baseURL).toBe(`${newBaseURL}/api`); + expect(httpClient.baseURL).toBe(newBaseURL); }); it('setAuthStrategy should configure the authentication strategy', () => { From 711e9ea1adca08421f50e0405191e8ce8fe19326 Mon Sep 17 00:00:00 2001 From: Jamie Howard Date: Thu, 5 Dec 2024 16:04:43 +0000 Subject: [PATCH 3/4] chore: revert type module --- jest.config.cjs => jest.config.js | 0 package.json | 1 - 2 files changed, 1 deletion(-) rename jest.config.cjs => jest.config.js (100%) diff --git a/jest.config.cjs b/jest.config.js similarity index 100% rename from jest.config.cjs rename to jest.config.js diff --git a/package.json b/package.json index 607c280..2460977 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,6 @@ "sdk", "js" ], - "type": "module", "repository": { "type": "git", "url": "https://github.com/strapi/sdk-js.git" From ad8fb9447312722b789616f0da01b57482679d1c Mon Sep 17 00:00:00 2001 From: Jamie Howard Date: Thu, 5 Dec 2024 16:09:05 +0000 Subject: [PATCH 4/4] chore: mark users and permissions auth as experimental --- src/auth/providers/users-permissions.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/auth/providers/users-permissions.ts b/src/auth/providers/users-permissions.ts index cb00558..3eb8b90 100644 --- a/src/auth/providers/users-permissions.ts +++ b/src/auth/providers/users-permissions.ts @@ -28,6 +28,11 @@ export type UsersPermissionsAuthPayload = Pick< 'identifier' | 'password' >; + /** + * @experimental + * Authentication through users and permissions is experimental for the MVP of + * the Strapi SDK. + */ export class UsersPermissionsAuthProvider extends AbstractAuthProvider { public static readonly identifier = USERS_PERMISSIONS_AUTH_STRATEGY_IDENTIFIER;