Skip to content

Commit b229b90

Browse files
authored
chore: rename sdk constructor
2 parents 7eb9b70 + 3a2eade commit b229b90

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ pnpm add @strapi/sdk-js
8383
To interact with your Strapi backend, initialize the SDK with your Strapi API base URL:
8484

8585
```typescript
86-
import { createStrapiSDK } from '@strapi/sdk-js';
86+
import { strapiSDK } from '@strapi/sdk-js';
8787

88-
const sdk = createStrapiSDK({ baseURL: 'http://localhost:1337/api' });
88+
const sdk = strapiSDK({ baseURL: 'http://localhost:1337/api' });
8989
```
9090

9191
Alternatively, use a `<script>` tag in a browser environment:
@@ -94,7 +94,7 @@ Alternatively, use a `<script>` tag in a browser environment:
9494
<script src="https://cdn.jsdelivr.net/npm/@strapi/sdk-js"></script>
9595

9696
<script>
97-
const sdk = createStrapiSDK({ baseURL: 'http://localhost:1337/api' });
97+
const sdk = strapiSDK({ baseURL: 'http://localhost:1337/api' });
9898
</script>
9999
```
100100

@@ -107,7 +107,7 @@ The SDK supports multiple authentication strategies for accessing authenticated
107107
If your Strapi instance uses API tokens, configure the SDK like this:
108108

109109
```typescript
110-
const sdk = createStrapiSDK({
110+
const sdk = strapiSDK({
111111
baseURL: 'http://localhost:1337/api',
112112
auth: {
113113
strategy: 'api-token',
@@ -184,10 +184,10 @@ The `.single()` method provides a manager for working with single-type resources
184184
const homepage = sdk.single('homepage');
185185

186186
// Fetch the default version of the homepage
187-
const homepageContent = await homepage.find();
187+
const defaultHomepage = await homepage.find();
188188

189189
// Fetch the spanish version of the homepage
190-
const homepageContent = await homepage.find({ locale: 'es' });
190+
const spanishHomepage = await homepage.find({ locale: 'es' });
191191

192192
// Update the homepage draft content
193193
const updatedHomepage = await homepage.update(
@@ -204,7 +204,7 @@ await homepage.delete();
204204
Here’s how to combine `.collection()` and `.single()` methods in a real-world scenario:
205205

206206
```typescript
207-
const sdk = createStrapiSDK({
207+
const sdk = strapiSDK({
208208
baseURL: 'http://localhost:1337/api',
209209
auth: {
210210
strategy: 'api-token',

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export * from './errors';
3232
* };
3333
*
3434
* // Create the SDK instance
35-
* const strapiSDK = createStrapiSDK(sdkConfig);
35+
* const strapiSDK = strapiSDK(sdkConfig);
3636
*
3737
* // Using the SDK to fetch content from a custom endpoint
3838
* const response = await strapiSDK.fetch('/content-endpoint');
@@ -44,7 +44,7 @@ export * from './errors';
4444
* @throws {StrapiSDKInitializationError} If the provided baseURL does not conform to a valid HTTP or HTTPS URL,
4545
* or if the auth configuration is invalid.
4646
*/
47-
export const createStrapiSDK = (config: StrapiSDKConfig) => {
47+
export const strapiSDK = (config: StrapiSDKConfig) => {
4848
const sdkValidator = new StrapiSDKValidator();
4949

5050
return new StrapiSDK<typeof config>(

src/sdk.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export class StrapiSDK<const T_Config extends StrapiSDKConfig = StrapiSDKConfig>
158158
* @example
159159
* ```typescript
160160
* // Create the SDK instance
161-
* const sdk = createStrapiSDK({ baseURL: 'http://localhost:1337/api' );
161+
* const sdk = strapiSDK({ baseURL: 'http://localhost:1337/api' );
162162
*
163163
* // Perform a custom fetch query
164164
* const response = await sdk.fetch('/categories');

tests/unit/index.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { createStrapiSDK, StrapiSDKInitializationError, StrapiSDKValidationError } from '../../src';
1+
import { strapiSDK, StrapiSDKInitializationError, StrapiSDKValidationError } from '../../src';
22
import { StrapiSDK } from '../../src/sdk';
33

44
import type { StrapiSDKConfig } from '../../src/sdk';
55

6-
describe('createStrapiSDK', () => {
6+
describe('strapiSDK', () => {
77
it('should create an SDK instance with valid configuration', () => {
88
// Arrange
99
const config = { baseURL: 'https://api.example.com' } satisfies StrapiSDKConfig;
1010

1111
// Act
12-
const sdkInstance = createStrapiSDK(config);
12+
const sdkInstance = strapiSDK(config);
1313

1414
// Assert
1515
expect(sdkInstance).toBeInstanceOf(StrapiSDK);
@@ -21,7 +21,7 @@ describe('createStrapiSDK', () => {
2121
const config = { baseURL: 'invalid-url' } satisfies StrapiSDKConfig;
2222

2323
// Act & Assert
24-
expect(() => createStrapiSDK(config)).toThrow(StrapiSDKInitializationError);
24+
expect(() => strapiSDK(config)).toThrow(StrapiSDKInitializationError);
2525
});
2626

2727
it('should throw an error if auth configuration is invalid', () => {
@@ -35,6 +35,6 @@ describe('createStrapiSDK', () => {
3535
} satisfies StrapiSDKConfig;
3636

3737
// Act & Assert
38-
expect(() => createStrapiSDK(config)).toThrow(StrapiSDKValidationError);
38+
expect(() => strapiSDK(config)).toThrow(StrapiSDKValidationError);
3939
});
4040
});

0 commit comments

Comments
 (0)