From 1bd9962372c2b29f5c93d8c4964753518911b905 Mon Sep 17 00:00:00 2001 From: Convly Date: Tue, 17 Dec 2024 11:13:30 +0100 Subject: [PATCH 1/3] fix(README): update variable names for clarity --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 00e2bdd..953d3d5 100644 --- a/README.md +++ b/README.md @@ -184,10 +184,10 @@ The `.single()` method provides a manager for working with single-type resources const homepage = sdk.single('homepage'); // Fetch the default version of the homepage -const homepageContent = await homepage.find(); +const defaultHomepage = await homepage.find(); // Fetch the spanish version of the homepage -const homepageContent = await homepage.find({ locale: 'es' }); +const spanishHomepage = await homepage.find({ locale: 'es' }); // Update the homepage draft content const updatedHomepage = await homepage.update( From 55abdb545910af4fa6f02d56870434224b5d8d32 Mon Sep 17 00:00:00 2001 From: Convly Date: Tue, 17 Dec 2024 11:13:49 +0100 Subject: [PATCH 2/3] chore(sdk): rename createStrapiSDK to strapiSDK --- README.md | 11 ++++++----- src/index.ts | 4 ++-- src/sdk.ts | 2 +- tests/unit/index.test.ts | 10 +++++----- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 953d3d5..808b30d 100644 --- a/README.md +++ b/README.md @@ -83,18 +83,19 @@ pnpm add @strapi/sdk-js To interact with your Strapi backend, initialize the SDK with your Strapi API base URL: ```typescript -import { createStrapiSDK } from '@strapi/sdk-js'; +import { strapiSDK } from '@strapi/sdk-js'; -const sdk = createStrapiSDK({ baseURL: 'http://localhost:1337/api' }); +const sdk = strapiSDK({ baseURL: 'http://localhost:1337/api' }); ``` Alternatively, use a ` ``` @@ -107,7 +108,7 @@ The SDK supports multiple authentication strategies for accessing authenticated If your Strapi instance uses API tokens, configure the SDK like this: ```typescript -const sdk = createStrapiSDK({ +const sdk = strapiSDK({ baseURL: 'http://localhost:1337/api', auth: { strategy: 'api-token', @@ -204,7 +205,7 @@ await homepage.delete(); Here’s how to combine `.collection()` and `.single()` methods in a real-world scenario: ```typescript -const sdk = createStrapiSDK({ +const sdk = strapiSDK({ baseURL: 'http://localhost:1337/api', auth: { strategy: 'api-token', diff --git a/src/index.ts b/src/index.ts index 256388c..a8b8a5d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -32,7 +32,7 @@ export * from './errors'; * }; * * // Create the SDK instance - * const strapiSDK = createStrapiSDK(sdkConfig); + * const strapiSDK = strapiSDK(sdkConfig); * * // Using the SDK to fetch content from a custom endpoint * const response = await strapiSDK.fetch('/content-endpoint'); @@ -44,7 +44,7 @@ export * from './errors'; * @throws {StrapiSDKInitializationError} If the provided baseURL does not conform to a valid HTTP or HTTPS URL, * or if the auth configuration is invalid. */ -export const createStrapiSDK = (config: StrapiSDKConfig) => { +export const strapiSDK = (config: StrapiSDKConfig) => { const sdkValidator = new StrapiSDKValidator(); return new StrapiSDK( diff --git a/src/sdk.ts b/src/sdk.ts index cc5f7ac..b3cec68 100644 --- a/src/sdk.ts +++ b/src/sdk.ts @@ -158,7 +158,7 @@ export class StrapiSDK * @example * ```typescript * // Create the SDK instance - * const sdk = createStrapiSDK({ baseURL: 'http://localhost:1337/api' ); + * const sdk = strapiSDK({ baseURL: 'http://localhost:1337/api' ); * * // Perform a custom fetch query * const response = await sdk.fetch('/categories'); diff --git a/tests/unit/index.test.ts b/tests/unit/index.test.ts index b8e558c..6ec9212 100644 --- a/tests/unit/index.test.ts +++ b/tests/unit/index.test.ts @@ -1,15 +1,15 @@ -import { createStrapiSDK, StrapiSDKInitializationError, StrapiSDKValidationError } from '../../src'; +import { strapiSDK, StrapiSDKInitializationError, StrapiSDKValidationError } from '../../src'; import { StrapiSDK } from '../../src/sdk'; import type { StrapiSDKConfig } from '../../src/sdk'; -describe('createStrapiSDK', () => { +describe('strapiSDK', () => { it('should create an SDK instance with valid configuration', () => { // Arrange const config = { baseURL: 'https://api.example.com' } satisfies StrapiSDKConfig; // Act - const sdkInstance = createStrapiSDK(config); + const sdkInstance = strapiSDK(config); // Assert expect(sdkInstance).toBeInstanceOf(StrapiSDK); @@ -21,7 +21,7 @@ describe('createStrapiSDK', () => { const config = { baseURL: 'invalid-url' } satisfies StrapiSDKConfig; // Act & Assert - expect(() => createStrapiSDK(config)).toThrow(StrapiSDKInitializationError); + expect(() => strapiSDK(config)).toThrow(StrapiSDKInitializationError); }); it('should throw an error if auth configuration is invalid', () => { @@ -35,6 +35,6 @@ describe('createStrapiSDK', () => { } satisfies StrapiSDKConfig; // Act & Assert - expect(() => createStrapiSDK(config)).toThrow(StrapiSDKValidationError); + expect(() => strapiSDK(config)).toThrow(StrapiSDKValidationError); }); }); From 3a2eade6fe0435a324a61e04c6b071dd380a74bb Mon Sep 17 00:00:00 2001 From: Convly Date: Tue, 17 Dec 2024 11:15:14 +0100 Subject: [PATCH 3/3] docs: fix formatting in README code example --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 808b30d..6264a7f 100644 --- a/README.md +++ b/README.md @@ -91,11 +91,10 @@ const sdk = strapiSDK({ baseURL: 'http://localhost:1337/api' }); Alternatively, use a ` ```