Skip to content

Commit

Permalink
feat(js-storefrontaware-utils): Let us pass the tenantId from Superfa…
Browse files Browse the repository at this point in the history
…st and profiling options. Bump 1.0.0
  • Loading branch information
Plopix committed Feb 24, 2023
1 parent 3afa310 commit 38376c5
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@crystallize/js-storefrontaware-utils",
"license": "MIT",
"version": "0.2.3",
"version": "1.0.0",
"author": "Crystallize <[email protected]> (https://crystallize.com)",
"contributors": [
"Sébastien Morel <[email protected]>"
Expand All @@ -19,8 +19,8 @@
"main": "dist/index.js",
"types": "dist/index.d.ts",
"devDependencies": {
"@tsconfig/node16": "^1.0.2",
"@types/node": "^17.0.23",
"@tsconfig/node18": "^1.0.1",
"@types/node": "^18.11.15",
"jest": "^27.5.1"
},
"dependencies": {
Expand Down
1 change: 1 addition & 0 deletions src/adapters/superfast.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ async function fetchSuperFastConfig(domainkey: string, credentials: ClientConfig
return {
identifier: domainkey,
tenantIdentifier: components['tenant-identifier'],
tenantId: components['tenant-id'] || undefined,
language: 'en',
storefront: components.storefront,
logo: components.logos,
Expand Down
17 changes: 11 additions & 6 deletions src/storefront.server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createClient } from '@crystallize/js-api-client';
import { createClient, CreateClientOptions } from '@crystallize/js-api-client';
import { TStoreFront, TStoreFrontAdapter } from './types';

export type StoreFrontOptions = {
Expand All @@ -16,17 +16,22 @@ export type StoreFrontOptions = {
export const createStoreFront = async (
adapter: TStoreFrontAdapter,
options: StoreFrontOptions | boolean = false,
clientOptions?: CreateClientOptions,
): Promise<TStoreFront> => {
options = typeof options === 'boolean' ? { withSecrets: options } : options;
const withSecrets = options?.withSecrets ?? false;

const config = await adapter.config(withSecrets);
return {
config,
apiClient: createClient({
tenantIdentifier: config.tenantIdentifier,
accessTokenId: withSecrets ? config.configuration?.ACCESS_TOKEN_ID || '' : '',
accessTokenSecret: withSecrets ? config.configuration?.ACCESS_TOKEN_SECRET || '' : '',
}),
apiClient: createClient(
{
tenantIdentifier: config.tenantIdentifier,
tenantId: config.tenantId,
accessTokenId: withSecrets ? config.configuration?.ACCESS_TOKEN_ID || '' : '',
accessTokenSecret: withSecrets ? config.configuration?.ACCESS_TOKEN_SECRET || '' : '',
},
clientOptions,
),
};
};
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ClientInterface } from '@crystallize/js-api-client';
export type TStoreFrontConfig = {
identifier: string;
tenantIdentifier: string;
tenantId?: string;
language: string;
storefront: string;
logo: string;
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "@tsconfig/node16/tsconfig.json",
"extends": "@tsconfig/node18/tsconfig.json",
"compilerOptions": {
"outDir": "./dist",
"declaration": true,
Expand Down

0 comments on commit 38376c5

Please sign in to comment.