Skip to content

Commit 47d5d40

Browse files
committed
feat(js-api-client): Allow to change the Origin of the Client to reach the DEV
1 parent 2f45dc5 commit 47d5d40

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@crystallize/js-api-client",
33
"license": "MIT",
4-
"version": "1.3.0",
4+
"version": "1.3.1",
55
"author": "Crystallize <[email protected]> (https://crystallize.com)",
66
"contributors": [
77
"Sébastien Morel <[email protected]>"

src/core/client.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export type ClientConfiguration = {
66
accessTokenId?: string;
77
accessTokenSecret?: string;
88
sessionId?: string;
9+
origin?: string;
910
};
1011

1112
export type VariablesType = Record<string, any>;
@@ -90,9 +91,6 @@ function createApiCaller(uri: string, configuration: ClientConfiguration): ApiCa
9091
};
9192
}
9293

93-
const apiHost = (path: string[], prefix: 'api' | 'pim' = 'api') =>
94-
`https://${prefix}.crystallize.com/${path.join('/')}`;
95-
9694
/**
9795
* Create one api client for each api endpoint Crystallize offers (catalogue, search, order, subscription, pim).
9896
*
@@ -101,6 +99,8 @@ const apiHost = (path: string[], prefix: 'api' | 'pim' = 'api') =>
10199
*/
102100
export function createClient(configuration: ClientConfiguration): ClientInterface {
103101
const identifier = configuration.tenantIdentifier;
102+
const origin = configuration.origin || '.crystallize.com';
103+
const apiHost = (path: string[], prefix: 'api' | 'pim' = 'api') => `https://${prefix}${origin}/${path.join('/')}`;
104104

105105
return {
106106
catalogueApi: createApiCaller(apiHost([identifier, 'catalogue']), configuration),

tests/call.test.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,27 @@ test('callCatalogueApi: Raw fetch a product name: Bamboo Chair', async () => {
44
const CrystallizeClient = createClient({
55
tenantIdentifier: 'furniture',
66
});
7-
87
const caller = CrystallizeClient.catalogueApi;
8+
const query = ` query ($language: String!, $path: String!) {
9+
catalogue(language: $language, path: $path) {
10+
... on Product {
11+
name
12+
}
13+
}
14+
}`;
15+
const response = await caller(query, {
16+
language: 'en',
17+
path: '/shop/chairs/bamboo-chair',
18+
});
19+
expect(response.catalogue.name).toBe('Bamboo Chair');
20+
});
921

22+
test('callCatalogueApi DEV: Raw fetch a product name: Bamboo Chair', async () => {
23+
const CrystallizeClient = createClient({
24+
tenantIdentifier: 'furniture',
25+
origin: '-dev.crystallize.digital',
26+
});
27+
const caller = CrystallizeClient.catalogueApi;
1028
const query = ` query ($language: String!, $path: String!) {
1129
catalogue(language: $language, path: $path) {
1230
... on Product {

0 commit comments

Comments
 (0)