@salesforce/commerce-sdk-react 1.0.0-preview.0 → 1.0.0-preview.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/README.md +4 -0
- package/auth/index.d.ts +19 -4
- package/auth/index.js +49 -1
- package/auth/storage.d.ts +1 -1
- package/components/ShopperExperience/Component/index.d.ts +1 -1
- package/components/ShopperExperience/Page/index.d.ts +2 -2
- package/components/ShopperExperience/types.d.ts +5 -5
- package/hooks/ShopperBaskets/cache.d.ts +1 -1
- package/hooks/ShopperBaskets/mutation.d.ts +63 -282
- package/hooks/ShopperBaskets/mutation.js +60 -254
- package/hooks/ShopperBaskets/query.d.ts +11 -1
- package/hooks/ShopperBaskets/query.js +10 -0
- package/hooks/ShopperBaskets/queryKeyHelpers.d.ts +4 -4
- package/hooks/ShopperContexts/cache.d.ts +1 -1
- package/hooks/ShopperContexts/mutation.d.ts +18 -13
- package/hooks/ShopperContexts/mutation.js +16 -11
- package/hooks/ShopperContexts/query.d.ts +4 -2
- package/hooks/ShopperContexts/query.js +3 -1
- package/hooks/ShopperContexts/queryKeyHelpers.d.ts +4 -4
- package/hooks/ShopperCustomers/cache.d.ts +1 -1
- package/hooks/ShopperCustomers/mutation.d.ts +22 -82
- package/hooks/ShopperCustomers/mutation.js +20 -81
- package/hooks/ShopperCustomers/query.d.ts +28 -3
- package/hooks/ShopperCustomers/query.js +28 -2
- package/hooks/ShopperCustomers/queryKeyHelpers.d.ts +4 -4
- package/hooks/ShopperExperience/query.d.ts +13 -9
- package/hooks/ShopperExperience/query.js +12 -8
- package/hooks/ShopperExperience/queryKeyHelpers.d.ts +4 -4
- package/hooks/ShopperGiftCertificates/query.d.ts +3 -1
- package/hooks/ShopperGiftCertificates/query.js +2 -0
- package/hooks/ShopperGiftCertificates/queryKeyHelpers.d.ts +4 -4
- package/hooks/ShopperLogin/mutation.d.ts +21 -49
- package/hooks/ShopperLogin/mutation.js +19 -41
- package/hooks/ShopperLogin/query.d.ts +9 -1
- package/hooks/ShopperLogin/query.js +8 -0
- package/hooks/ShopperLogin/queryKeyHelpers.d.ts +4 -4
- package/hooks/ShopperOrders/cache.d.ts +1 -1
- package/hooks/ShopperOrders/mutation.d.ts +21 -25
- package/hooks/ShopperOrders/mutation.js +19 -21
- package/hooks/ShopperOrders/query.d.ts +7 -1
- package/hooks/ShopperOrders/query.js +7 -1
- package/hooks/ShopperOrders/queryKeyHelpers.d.ts +4 -4
- package/hooks/ShopperProducts/query.d.ts +9 -1
- package/hooks/ShopperProducts/query.js +8 -0
- package/hooks/ShopperProducts/queryKeyHelpers.d.ts +4 -4
- package/hooks/ShopperPromotions/query.d.ts +5 -1
- package/hooks/ShopperPromotions/query.js +4 -0
- package/hooks/ShopperPromotions/queryKeyHelpers.d.ts +4 -4
- package/hooks/ShopperSearch/query.d.ts +12 -4
- package/hooks/ShopperSearch/query.js +11 -3
- package/hooks/ShopperSearch/queryKeyHelpers.d.ts +4 -4
- package/hooks/types.d.ts +30 -27
- package/hooks/useAccessToken.d.ts +6 -0
- package/hooks/useAccessToken.js +8 -0
- package/hooks/useAuthHelper.d.ts +15 -1
- package/hooks/useAuthHelper.js +19 -0
- package/hooks/useCommerceApi.d.ts +2 -0
- package/hooks/useCommerceApi.js +2 -0
- package/hooks/useCustomerId.d.ts +2 -0
- package/hooks/useCustomerId.js +2 -0
- package/hooks/useCustomerType.d.ts +5 -2
- package/hooks/useCustomerType.js +12 -1
- package/hooks/useEncUserId.d.ts +3 -0
- package/hooks/useEncUserId.js +3 -0
- package/hooks/useLocalStorage.d.ts +1 -1
- package/hooks/useUsid.d.ts +2 -0
- package/hooks/useUsid.js +2 -0
- package/package.json +15 -13
- package/provider.d.ts +27 -1
- package/provider.js +27 -1
- package/scripts/build-and-release-docs.js +1 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { ShopperPromotions } from 'commerce-sdk-isomorphic';
|
|
2
2
|
import { Argument, ExcludeTail } from '../types';
|
|
3
|
-
|
|
3
|
+
type Client = ShopperPromotions<{
|
|
4
4
|
shortCode: string;
|
|
5
5
|
}>;
|
|
6
|
-
|
|
7
|
-
export
|
|
6
|
+
type Params<T extends keyof QueryKeys> = Partial<Argument<Client[T]>['parameters']>;
|
|
7
|
+
export type QueryKeys = {
|
|
8
8
|
getPromotions: [
|
|
9
9
|
'/commerce-sdk-react',
|
|
10
10
|
'/organizations/',
|
|
@@ -21,7 +21,7 @@ export declare type QueryKeys = {
|
|
|
21
21
|
Params<'getPromotionsForCampaign'>
|
|
22
22
|
];
|
|
23
23
|
};
|
|
24
|
-
|
|
24
|
+
type QueryKeyHelper<T extends keyof QueryKeys> = {
|
|
25
25
|
/**
|
|
26
26
|
* Reduces the given parameters (which may have additional, unknown properties) to an object
|
|
27
27
|
* containing *only* the properties required for an endpoint.
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { UseQueryResult } from '@tanstack/react-query';
|
|
2
2
|
import { ApiClients, ApiQueryOptions, Argument, DataType, NullableParameters } from '../types';
|
|
3
|
-
|
|
3
|
+
type Client = ApiClients['shopperSearch'];
|
|
4
4
|
/**
|
|
5
|
-
* Provides keyword and refinement search functionality for products.
|
|
6
|
-
|
|
5
|
+
* Provides keyword and refinement search functionality for products.
|
|
6
|
+
*
|
|
7
|
+
* Only returns the product ID, link, and name in the product search hit.
|
|
8
|
+
* The search result contains only products that are online and assigned to site catalog.
|
|
9
|
+
* @group ShopperSearch
|
|
10
|
+
* @category Query
|
|
7
11
|
* @parameter apiOptions - Options to pass through to `commerce-sdk-isomorphic`, with `null` accepted for unset API parameters.
|
|
8
12
|
* @parameter queryOptions - TanStack Query query options, with `enabled` by default set to check that all required API parameters have been set.
|
|
9
13
|
* @returns A TanStack Query query hook with data from the Shopper Search `productSearch` endpoint.
|
|
@@ -13,7 +17,11 @@ the product search hit. The search result contains only products that are online
|
|
|
13
17
|
*/
|
|
14
18
|
export declare const useProductSearch: (apiOptions: NullableParameters<Argument<Client['productSearch']>>, queryOptions?: ApiQueryOptions<Client['productSearch']>) => UseQueryResult<DataType<Client['productSearch']>>;
|
|
15
19
|
/**
|
|
16
|
-
* Provides keyword search functionality for products, categories, and brands suggestions.
|
|
20
|
+
* Provides keyword search functionality for products, categories, and brands suggestions.
|
|
21
|
+
*
|
|
22
|
+
* Returns suggested products, suggested categories, and suggested brands for the given search phrase.
|
|
23
|
+
* @group ShopperSearch
|
|
24
|
+
* @category Query
|
|
17
25
|
* @parameter apiOptions - Options to pass through to `commerce-sdk-isomorphic`, with `null` accepted for unset API parameters.
|
|
18
26
|
* @parameter queryOptions - TanStack Query query options, with `enabled` by default set to check that all required API parameters have been set.
|
|
19
27
|
* @returns A TanStack Query query hook with data from the Shopper Search `getSearchSuggestions` endpoint.
|
|
@@ -19,8 +19,12 @@ function _asyncToGenerator(fn) { return function () { var self = this, args = ar
|
|
|
19
19
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
20
20
|
*/
|
|
21
21
|
/**
|
|
22
|
-
* Provides keyword and refinement search functionality for products.
|
|
23
|
-
|
|
22
|
+
* Provides keyword and refinement search functionality for products.
|
|
23
|
+
*
|
|
24
|
+
* Only returns the product ID, link, and name in the product search hit.
|
|
25
|
+
* The search result contains only products that are online and assigned to site catalog.
|
|
26
|
+
* @group ShopperSearch
|
|
27
|
+
* @category Query
|
|
24
28
|
* @parameter apiOptions - Options to pass through to `commerce-sdk-isomorphic`, with `null` accepted for unset API parameters.
|
|
25
29
|
* @parameter queryOptions - TanStack Query query options, with `enabled` by default set to check that all required API parameters have been set.
|
|
26
30
|
* @returns A TanStack Query query hook with data from the Shopper Search `productSearch` endpoint.
|
|
@@ -58,7 +62,11 @@ const useProductSearch = (apiOptions, queryOptions = {}) => {
|
|
|
58
62
|
});
|
|
59
63
|
};
|
|
60
64
|
/**
|
|
61
|
-
* Provides keyword search functionality for products, categories, and brands suggestions.
|
|
65
|
+
* Provides keyword search functionality for products, categories, and brands suggestions.
|
|
66
|
+
*
|
|
67
|
+
* Returns suggested products, suggested categories, and suggested brands for the given search phrase.
|
|
68
|
+
* @group ShopperSearch
|
|
69
|
+
* @category Query
|
|
62
70
|
* @parameter apiOptions - Options to pass through to `commerce-sdk-isomorphic`, with `null` accepted for unset API parameters.
|
|
63
71
|
* @parameter queryOptions - TanStack Query query options, with `enabled` by default set to check that all required API parameters have been set.
|
|
64
72
|
* @returns A TanStack Query query hook with data from the Shopper Search `getSearchSuggestions` endpoint.
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { ShopperSearch } from 'commerce-sdk-isomorphic';
|
|
2
2
|
import { Argument, ExcludeTail } from '../types';
|
|
3
|
-
|
|
3
|
+
type Client = ShopperSearch<{
|
|
4
4
|
shortCode: string;
|
|
5
5
|
}>;
|
|
6
|
-
|
|
7
|
-
export
|
|
6
|
+
type Params<T extends keyof QueryKeys> = Partial<Argument<Client[T]>['parameters']>;
|
|
7
|
+
export type QueryKeys = {
|
|
8
8
|
productSearch: [
|
|
9
9
|
'/commerce-sdk-react',
|
|
10
10
|
'/organizations/',
|
|
@@ -20,7 +20,7 @@ export declare type QueryKeys = {
|
|
|
20
20
|
Params<'getSearchSuggestions'>
|
|
21
21
|
];
|
|
22
22
|
};
|
|
23
|
-
|
|
23
|
+
type QueryKeyHelper<T extends keyof QueryKeys> = {
|
|
24
24
|
/**
|
|
25
25
|
* Reduces the given parameters (which may have additional, unknown properties) to an object
|
|
26
26
|
* containing *only* the properties required for an endpoint.
|
package/hooks/types.d.ts
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
1
|
import { InvalidateQueryFilters, QueryFilters, Updater, UseQueryOptions } from '@tanstack/react-query';
|
|
2
2
|
import { ShopperBaskets, ShopperContexts, ShopperCustomers, ShopperExperience, ShopperGiftCertificates, ShopperLogin, ShopperOrders, ShopperProducts, ShopperPromotions, ShopperSearch } from 'commerce-sdk-isomorphic';
|
|
3
3
|
/** Makes a type easier to read. */
|
|
4
|
-
export
|
|
4
|
+
export type Prettify<T extends object> = NonNullable<Pick<T, keyof T>>;
|
|
5
5
|
/**
|
|
6
6
|
* Marks the given keys as required.
|
|
7
7
|
* WARNING: Does not work if T has an index signature.
|
|
8
8
|
*/
|
|
9
|
-
export
|
|
9
|
+
export type RequireKeys<T, K extends keyof T> = Prettify<T & Required<Pick<T, K>>>;
|
|
10
10
|
/** Removes keys whose value is `never`. */
|
|
11
|
-
|
|
11
|
+
type RemoveNeverValues<T> = {
|
|
12
12
|
[K in keyof T as T[K] extends never ? never : K]: T[K];
|
|
13
13
|
};
|
|
14
14
|
/** Change string index type to `never`. */
|
|
15
|
-
|
|
15
|
+
type StringIndexToNever<T> = {
|
|
16
16
|
[K in keyof T]: string extends K ? never : T[K];
|
|
17
17
|
};
|
|
18
18
|
/** Removes a string index type. */
|
|
19
|
-
export
|
|
19
|
+
export type RemoveStringIndex<T> = RemoveNeverValues<StringIndexToNever<T>>;
|
|
20
20
|
/** Gets the last element of an array. */
|
|
21
|
-
export
|
|
21
|
+
export type Tail<T extends readonly unknown[]> = T extends [...head: unknown[], tail: infer Tail] ? Tail : T;
|
|
22
22
|
/** Remove the last entry from a tuple type. */
|
|
23
|
-
export
|
|
23
|
+
export type ExcludeTail<T extends readonly unknown[]> = T extends readonly [...infer Head, unknown] ? T extends unknown[] ? Head : Readonly<Head> : T;
|
|
24
24
|
/** Adds `null` as an allowed value to all properties. */
|
|
25
|
-
|
|
25
|
+
type AllowNull<T> = {
|
|
26
26
|
[K in keyof T]: T[K] | null;
|
|
27
27
|
};
|
|
28
28
|
/** Gets the keys of `T` which allow `null` as a possible value. */
|
|
29
|
-
|
|
29
|
+
type NullKeys<T> = {
|
|
30
30
|
[K in keyof T]-?: null extends T[K] ? K : never;
|
|
31
31
|
}[keyof T];
|
|
32
32
|
/** Removes `null` values and marks those properties as optional. */
|
|
33
|
-
export
|
|
33
|
+
export type NullToOptional<T> = Omit<T, NullKeys<T>> & {
|
|
34
34
|
[K in keyof T]?: NonNullable<T[K]>;
|
|
35
35
|
};
|
|
36
|
-
export
|
|
36
|
+
export type ApiClientConfigParams = {
|
|
37
37
|
clientId: string;
|
|
38
38
|
organizationId: string;
|
|
39
39
|
siteId: string;
|
|
@@ -41,6 +41,9 @@ export declare type ApiClientConfigParams = {
|
|
|
41
41
|
locale?: string;
|
|
42
42
|
currency?: string;
|
|
43
43
|
};
|
|
44
|
+
/**
|
|
45
|
+
* A map of commerce-sdk-isomorphic API client instances.
|
|
46
|
+
*/
|
|
44
47
|
export interface ApiClients {
|
|
45
48
|
shopperBaskets: ShopperBaskets<ApiClientConfigParams>;
|
|
46
49
|
shopperContexts: ShopperContexts<ApiClientConfigParams>;
|
|
@@ -53,11 +56,11 @@ export interface ApiClients {
|
|
|
53
56
|
shopperPromotions: ShopperPromotions<ApiClientConfigParams>;
|
|
54
57
|
shopperSearch: ShopperSearch<ApiClientConfigParams>;
|
|
55
58
|
}
|
|
56
|
-
export
|
|
59
|
+
export type ApiClient = ApiClients[keyof ApiClients];
|
|
57
60
|
/**
|
|
58
61
|
* Generic signature of the options objects used by commerce-sdk-isomorphic
|
|
59
62
|
*/
|
|
60
|
-
export
|
|
63
|
+
export type ApiOptions<Parameters extends object = Record<string, unknown>, Body extends object | unknown[] | undefined = Record<string, unknown> | unknown[] | undefined, Headers extends Record<string, string> = Record<string, string>> = {
|
|
61
64
|
parameters?: Parameters;
|
|
62
65
|
headers?: Headers;
|
|
63
66
|
body?: Body;
|
|
@@ -65,35 +68,35 @@ export declare type ApiOptions<Parameters extends object = Record<string, unknow
|
|
|
65
68
|
/**
|
|
66
69
|
* Generic signature of API methods exported by commerce-sdk-isomorphic
|
|
67
70
|
*/
|
|
68
|
-
export
|
|
71
|
+
export type ApiMethod<Options extends ApiOptions, Data> = {
|
|
69
72
|
(options: Options): Promise<Data>;
|
|
70
73
|
};
|
|
71
74
|
/**
|
|
72
75
|
* The first argument of a function.
|
|
73
76
|
*/
|
|
74
|
-
export
|
|
77
|
+
export type Argument<T extends (arg: any) => unknown> = NonNullable<Parameters<T>[0]>;
|
|
75
78
|
/**
|
|
76
79
|
* The data type returned by a commerce-sdk-isomorphic method when the raw response
|
|
77
80
|
* flag is not set.
|
|
78
81
|
*/
|
|
79
|
-
export
|
|
82
|
+
export type DataType<T> = T extends ApiMethod<any, Response | infer R> ? R : never;
|
|
80
83
|
/**
|
|
81
84
|
* Merged headers and parameters from client config and options, mimicking the behavior
|
|
82
85
|
* of commerce-sdk-isomorphic.
|
|
83
86
|
*/
|
|
84
|
-
export
|
|
87
|
+
export type MergedOptions<Client extends ApiClient, Options extends ApiOptions> = Required<ApiOptions<NonNullable<Client['clientConfig']['parameters'] & Options['parameters']>, unknown extends Options['body'] ? never : Options['body'], NonNullable<Client['clientConfig']['headers'] & Options['headers']>>>;
|
|
85
88
|
/** Query key interface used by API query hooks. */
|
|
86
|
-
export
|
|
89
|
+
export type ApiQueryKey<Params extends Record<string, unknown> = Record<string, unknown>> = readonly [...path: (string | undefined)[], parameters: Params];
|
|
87
90
|
/** Query options for endpoint hooks. */
|
|
88
|
-
export
|
|
91
|
+
export type ApiQueryOptions<Method extends ApiMethod<any, unknown>> = Prettify<Omit<UseQueryOptions<DataType<Method>, unknown, DataType<Method>, ApiQueryKey>, 'queryFn' | 'queryKey'>>;
|
|
89
92
|
/** Adds `null` as an allowed value to all parameters. */
|
|
90
|
-
export
|
|
93
|
+
export type NullableParameters<T extends {
|
|
91
94
|
parameters?: object;
|
|
92
95
|
}> = {
|
|
93
96
|
[K in keyof T]: K extends 'parameters' ? AllowNull<T[K]> : T[K];
|
|
94
97
|
};
|
|
95
98
|
/** Remove `null` and `undefined` values from all parameters. */
|
|
96
|
-
export
|
|
99
|
+
export type OmitNullableParameters<T extends {
|
|
97
100
|
parameters: object;
|
|
98
101
|
}> = Omit<T, 'parameters'> & {
|
|
99
102
|
parameters: NullToOptional<T['parameters']>;
|
|
@@ -103,25 +106,25 @@ export declare type OmitNullableParameters<T extends {
|
|
|
103
106
|
* @property queryKey - The query key to update
|
|
104
107
|
* @property updater - Either the new data or a function that accepts old data and returns new data
|
|
105
108
|
*/
|
|
106
|
-
export
|
|
109
|
+
export type CacheUpdateUpdate<T> = {
|
|
107
110
|
queryKey: ApiQueryKey;
|
|
108
111
|
updater?: Updater<T | undefined, T | undefined>;
|
|
109
112
|
};
|
|
110
113
|
/** Query predicate for queries to invalidate */
|
|
111
|
-
export
|
|
114
|
+
export type CacheUpdateInvalidate = InvalidateQueryFilters;
|
|
112
115
|
/** Query predicate for queries to remove */
|
|
113
|
-
export
|
|
116
|
+
export type CacheUpdateRemove = QueryFilters;
|
|
114
117
|
/** Collection of updates to make to the cache when a request completes. */
|
|
115
|
-
export
|
|
118
|
+
export type CacheUpdate = {
|
|
116
119
|
update?: CacheUpdateUpdate<unknown>[];
|
|
117
120
|
invalidate?: CacheUpdateInvalidate[];
|
|
118
121
|
remove?: CacheUpdateRemove[];
|
|
119
122
|
clear?: boolean;
|
|
120
123
|
};
|
|
121
124
|
/** Generates a collection of cache updates to make for a given request. */
|
|
122
|
-
export
|
|
125
|
+
export type CacheUpdateGetter<Options, Data> = (customerId: string | null, options: Options, response: Data) => CacheUpdate;
|
|
123
126
|
/** Collection of cache update getters for each method of an API client. */
|
|
124
|
-
export
|
|
127
|
+
export type CacheUpdateMatrix<Client extends ApiClient> = {
|
|
125
128
|
[Method in keyof Client]?: Client[Method] extends ApiMethod<any, Response | infer Data> ? CacheUpdateGetter<MergedOptions<Client, Argument<Client[Method]>>, Data> : never;
|
|
126
129
|
};
|
|
127
130
|
export {};
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @group Shopper Authentication helpers
|
|
3
|
+
*/
|
|
1
4
|
interface AccessToken {
|
|
2
5
|
token: string | null;
|
|
3
6
|
getTokenWhenReady: () => Promise<string>;
|
|
@@ -5,6 +8,9 @@ interface AccessToken {
|
|
|
5
8
|
/**
|
|
6
9
|
* Hook that returns the access token.
|
|
7
10
|
*
|
|
11
|
+
* @group Helpers
|
|
12
|
+
* @category Shopper Authentication
|
|
13
|
+
*
|
|
8
14
|
*/
|
|
9
15
|
declare const useAccessToken: () => AccessToken;
|
|
10
16
|
export default useAccessToken;
|
package/hooks/useAccessToken.js
CHANGED
|
@@ -16,9 +16,17 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
const onClient = typeof window !== 'undefined';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @group Shopper Authentication helpers
|
|
22
|
+
*/
|
|
23
|
+
|
|
19
24
|
/**
|
|
20
25
|
* Hook that returns the access token.
|
|
21
26
|
*
|
|
27
|
+
* @group Helpers
|
|
28
|
+
* @category Shopper Authentication
|
|
29
|
+
*
|
|
22
30
|
*/
|
|
23
31
|
const useAccessToken = () => {
|
|
24
32
|
const config = (0, _useConfig.default)();
|
package/hooks/useAuthHelper.d.ts
CHANGED
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
import { UseMutationResult } from '@tanstack/react-query';
|
|
2
2
|
import Auth from '../auth';
|
|
3
|
+
/**
|
|
4
|
+
* @group Helpers
|
|
5
|
+
* @category Shopper Authentication
|
|
6
|
+
* @enum
|
|
7
|
+
*/
|
|
3
8
|
export declare const AuthHelpers: {
|
|
4
9
|
readonly LoginGuestUser: "loginGuestUser";
|
|
5
10
|
readonly LoginRegisteredUserB2C: "loginRegisteredUserB2C";
|
|
6
11
|
readonly Logout: "logout";
|
|
7
12
|
readonly Register: "register";
|
|
8
13
|
};
|
|
9
|
-
|
|
14
|
+
/**
|
|
15
|
+
* @group Helpers
|
|
16
|
+
* @category Shopper Authentication
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
export type AuthHelper = (typeof AuthHelpers)[keyof typeof AuthHelpers];
|
|
10
20
|
/**
|
|
11
21
|
* A hook for Public Client OAuth helpers.
|
|
22
|
+
*
|
|
12
23
|
* The hook calls the SLAS helpers imported from commerce-sdk-isomorphic.
|
|
13
24
|
* For more, see https://github.com/SalesforceCommerceCloud/commerce-sdk-isomorphic/#public-client-shopper-login-helpers
|
|
14
25
|
*
|
|
@@ -17,6 +28,9 @@ export declare type AuthHelper = (typeof AuthHelpers)[keyof typeof AuthHelpers];
|
|
|
17
28
|
* - loginGuestUser
|
|
18
29
|
* - logout
|
|
19
30
|
* - register
|
|
31
|
+
*
|
|
32
|
+
* @group Helpers
|
|
33
|
+
* @category Shopper Authentication
|
|
20
34
|
*/
|
|
21
35
|
export declare function useAuthHelper<Mutation extends AuthHelper>(mutation: Mutation): UseMutationResult<ReturnType<Auth[Mutation]> extends Promise<infer Data> ? Data : never, unknown, [
|
|
22
36
|
] extends Parameters<Auth[Mutation]> ? void : Parameters<Auth[Mutation]>[0], unknown>;
|
package/hooks/useAuthHelper.js
CHANGED
|
@@ -16,16 +16,32 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
16
16
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* @group Helpers
|
|
21
|
+
* @category Shopper Authentication
|
|
22
|
+
* @enum
|
|
23
|
+
*/
|
|
19
24
|
const AuthHelpers = {
|
|
20
25
|
LoginGuestUser: 'loginGuestUser',
|
|
21
26
|
LoginRegisteredUserB2C: 'loginRegisteredUserB2C',
|
|
22
27
|
Logout: 'logout',
|
|
23
28
|
Register: 'register'
|
|
24
29
|
};
|
|
30
|
+
/**
|
|
31
|
+
* @group Helpers
|
|
32
|
+
* @category Shopper Authentication
|
|
33
|
+
*
|
|
34
|
+
*/
|
|
25
35
|
exports.AuthHelpers = AuthHelpers;
|
|
26
36
|
const noop = () => ({});
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
|
|
27
42
|
/**
|
|
28
43
|
* A hook for Public Client OAuth helpers.
|
|
44
|
+
*
|
|
29
45
|
* The hook calls the SLAS helpers imported from commerce-sdk-isomorphic.
|
|
30
46
|
* For more, see https://github.com/SalesforceCommerceCloud/commerce-sdk-isomorphic/#public-client-shopper-login-helpers
|
|
31
47
|
*
|
|
@@ -34,6 +50,9 @@ const noop = () => ({});
|
|
|
34
50
|
* - loginGuestUser
|
|
35
51
|
* - logout
|
|
36
52
|
* - register
|
|
53
|
+
*
|
|
54
|
+
* @group Helpers
|
|
55
|
+
* @category Shopper Authentication
|
|
37
56
|
*/
|
|
38
57
|
function useAuthHelper(mutation) {
|
|
39
58
|
const auth = (0, _useAuthContext.default)();
|
|
@@ -2,6 +2,8 @@ import { ApiClients } from './types';
|
|
|
2
2
|
/**
|
|
3
3
|
* Access a set of initialized Commerce API clients, which are initialized using the configurations passed to the CommerceApiProvider.
|
|
4
4
|
*
|
|
5
|
+
* @group Helpers
|
|
6
|
+
*
|
|
5
7
|
* @returns Commerce API clients
|
|
6
8
|
*/
|
|
7
9
|
declare const useCommerceApi: () => ApiClients;
|
package/hooks/useCommerceApi.js
CHANGED
|
@@ -17,6 +17,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
17
17
|
/**
|
|
18
18
|
* Access a set of initialized Commerce API clients, which are initialized using the configurations passed to the CommerceApiProvider.
|
|
19
19
|
*
|
|
20
|
+
* @group Helpers
|
|
21
|
+
*
|
|
20
22
|
* @returns Commerce API clients
|
|
21
23
|
*/
|
|
22
24
|
const useCommerceApi = () => {
|
package/hooks/useCustomerId.d.ts
CHANGED
package/hooks/useCustomerId.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
1
|
+
export type CustomerType = null | 'guest' | 'registered';
|
|
2
|
+
type useCustomerType = {
|
|
3
3
|
customerType: CustomerType;
|
|
4
4
|
isGuest: boolean;
|
|
5
5
|
isRegistered: boolean;
|
|
@@ -15,6 +15,9 @@ declare type useCustomerType = {
|
|
|
15
15
|
* During initialization, type is null. And it is possible that
|
|
16
16
|
* isGuest and isRegistered to both be false.
|
|
17
17
|
*
|
|
18
|
+
* @group Helpers
|
|
19
|
+
* @category Shopper Authentication
|
|
20
|
+
*
|
|
18
21
|
*/
|
|
19
22
|
declare const useCustomerType: () => useCustomerType;
|
|
20
23
|
export default useCustomerType;
|
package/hooks/useCustomerType.js
CHANGED
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _useAuthContext = _interopRequireDefault(require("./useAuthContext"));
|
|
8
|
+
var _useLocalStorage = _interopRequireDefault(require("./useLocalStorage"));
|
|
9
|
+
var _useConfig = _interopRequireDefault(require("./useConfig"));
|
|
8
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
11
|
/*
|
|
10
12
|
* Copyright (c) 2023, salesforce.com, inc.
|
|
@@ -13,6 +15,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
13
15
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
14
16
|
*/
|
|
15
17
|
|
|
18
|
+
const onClient = typeof window !== 'undefined';
|
|
16
19
|
/**
|
|
17
20
|
* A hook to return customer auth type.
|
|
18
21
|
*
|
|
@@ -24,10 +27,18 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
24
27
|
* During initialization, type is null. And it is possible that
|
|
25
28
|
* isGuest and isRegistered to both be false.
|
|
26
29
|
*
|
|
30
|
+
* @group Helpers
|
|
31
|
+
* @category Shopper Authentication
|
|
32
|
+
*
|
|
27
33
|
*/
|
|
28
34
|
const useCustomerType = () => {
|
|
35
|
+
const config = (0, _useConfig.default)();
|
|
29
36
|
const auth = (0, _useAuthContext.default)();
|
|
30
|
-
let customerType =
|
|
37
|
+
let customerType = onClient ?
|
|
38
|
+
// This conditional is a constant value based on the environment, so the same path will
|
|
39
|
+
// always be followed., and the "rule of hooks" is not violated.
|
|
40
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
41
|
+
(0, _useLocalStorage.default)(`customer_type_${config.siteId}`) : auth.get('customer_type');
|
|
31
42
|
const isGuest = customerType === 'guest';
|
|
32
43
|
const isRegistered = customerType === 'registered';
|
|
33
44
|
if (customerType !== null && customerType !== 'guest' && customerType !== 'registered') {
|
package/hooks/useEncUserId.d.ts
CHANGED
package/hooks/useEncUserId.js
CHANGED
|
@@ -22,6 +22,9 @@ const onClient = typeof window !== 'undefined';
|
|
|
22
22
|
*
|
|
23
23
|
* This is sometimes used as the user ID for Einstein.
|
|
24
24
|
*
|
|
25
|
+
* @group Helpers
|
|
26
|
+
* @category Shopper Authentication
|
|
27
|
+
*
|
|
25
28
|
*/
|
|
26
29
|
const useEncUserId = () => {
|
|
27
30
|
const config = (0, _useConfig.default)();
|
package/hooks/useUsid.d.ts
CHANGED
package/hooks/useUsid.js
CHANGED
|
@@ -20,6 +20,8 @@ const onClient = typeof window !== 'undefined';
|
|
|
20
20
|
/**
|
|
21
21
|
* Hook that returns the usid associated with the current access token.
|
|
22
22
|
*
|
|
23
|
+
* @group Helpers
|
|
24
|
+
* @category Shopper Authentication
|
|
23
25
|
*/
|
|
24
26
|
const useUsid = () => {
|
|
25
27
|
const config = (0, _useConfig.default)();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/commerce-sdk-react",
|
|
3
|
-
"version": "1.0.0-preview.
|
|
3
|
+
"version": "1.0.0-preview.2",
|
|
4
4
|
"description": "A library that provides react hooks for fetching data from Commerce Cloud",
|
|
5
5
|
"homepage": "https://github.com/SalesforceCommerceCloud/pwa-kit/tree/develop/packages/ecom-react-hooks#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
],
|
|
27
27
|
"scripts": {
|
|
28
28
|
"build": "cross-env NODE_ENV=production internal-lib-build build && tsc --emitDeclarationOnly",
|
|
29
|
-
"build:docs": "typedoc",
|
|
29
|
+
"build:docs": "typedoc --plugin typedoc-plugin-missing-exports --hideGenerator",
|
|
30
30
|
"build:watch": "nodemon --watch 'src/**' --ext 'tsx,ts' --exec 'npm run build'",
|
|
31
31
|
"format": "internal-lib-build format \"**/*.{js,jsx,ts,tsx}\"",
|
|
32
32
|
"lint": "npm run lint:js && tsc --noEmit",
|
|
@@ -42,23 +42,25 @@
|
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"commerce-sdk-isomorphic": "^1.10.1",
|
|
44
44
|
"js-cookie": "^3.0.1",
|
|
45
|
-
"jwt-decode": "^3.1.2"
|
|
45
|
+
"jwt-decode": "^3.1.2",
|
|
46
|
+
"typedoc": "^0.24.7",
|
|
47
|
+
"typedoc-plugin-missing-exports": "^2.0.0"
|
|
46
48
|
},
|
|
47
49
|
"devDependencies": {
|
|
48
|
-
"@salesforce/pwa-kit-dev": "3.0.0-preview.
|
|
50
|
+
"@salesforce/pwa-kit-dev": "3.0.0-preview.2",
|
|
49
51
|
"@tanstack/react-query": "^4.28.0",
|
|
50
52
|
"@testing-library/jest-dom": "^5.16.5",
|
|
51
53
|
"@testing-library/react": "^14.0.0",
|
|
52
54
|
"@types/js-cookie": "^3.0.3",
|
|
53
|
-
"@types/jsonwebtoken": "^
|
|
55
|
+
"@types/jsonwebtoken": "^9.0.0",
|
|
54
56
|
"@types/jwt-decode": "^3.1.0",
|
|
55
57
|
"@types/node": "^14.18.40",
|
|
56
58
|
"@types/react": "^18.2.0",
|
|
57
59
|
"@types/react-dom": "^18.2.1",
|
|
58
60
|
"@types/react-helmet": "^6.1.6",
|
|
59
61
|
"cross-env": "^5.2.1",
|
|
60
|
-
"internal-lib-build": "3.0.0-preview.
|
|
61
|
-
"jsonwebtoken": "^
|
|
62
|
+
"internal-lib-build": "3.0.0-preview.2",
|
|
63
|
+
"jsonwebtoken": "^9.0.0",
|
|
62
64
|
"nock": "^13.3.0",
|
|
63
65
|
"nodemon": "^2.0.22",
|
|
64
66
|
"react": "^18.2.0",
|
|
@@ -66,13 +68,13 @@
|
|
|
66
68
|
"react-helmet": "^6.1.0",
|
|
67
69
|
"semver": "^7.3.8",
|
|
68
70
|
"shelljs": "^0.8.5",
|
|
69
|
-
"typedoc": "^0.
|
|
70
|
-
"typescript": "4.8.3"
|
|
71
|
+
"typedoc": "^0.24.7",
|
|
72
|
+
"typescript": "^4.8.3"
|
|
71
73
|
},
|
|
72
74
|
"peerDependencies": {
|
|
73
|
-
"@tanstack/react-query": "^4",
|
|
74
|
-
"react": "^18",
|
|
75
|
-
"react-helmet": "6"
|
|
75
|
+
"@tanstack/react-query": "^4.28.0",
|
|
76
|
+
"react": "^18.2.0",
|
|
77
|
+
"react-helmet": "^6.1.0"
|
|
76
78
|
},
|
|
77
79
|
"optionalDependencies": {
|
|
78
80
|
"prop-types": "^15.8.1"
|
|
@@ -84,5 +86,5 @@
|
|
|
84
86
|
"publishConfig": {
|
|
85
87
|
"directory": "dist"
|
|
86
88
|
},
|
|
87
|
-
"gitHead": "
|
|
89
|
+
"gitHead": "a2476c090ce48fd09e9116437aedc6cc45ae60bd"
|
|
88
90
|
}
|
package/provider.d.ts
CHANGED
|
@@ -28,7 +28,33 @@ export declare const AuthContext: React.Context<Auth>;
|
|
|
28
28
|
/**
|
|
29
29
|
* Initialize a set of Commerce API clients and make it available to all of descendant components
|
|
30
30
|
*
|
|
31
|
-
* @
|
|
31
|
+
* @group Components
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```js
|
|
35
|
+
import {CommerceApiProvider} from '@salesforce/commerce-sdk-react'
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
const App = ({children}) => {
|
|
39
|
+
return (
|
|
40
|
+
<CommerceApiProvider
|
|
41
|
+
clientId="12345678-1234-1234-1234-123412341234"
|
|
42
|
+
organizationId="f_ecom_aaaa_001"
|
|
43
|
+
proxy="localhost:3000/mobify/proxy/api"
|
|
44
|
+
redirectURI="localhost:3000/callback"
|
|
45
|
+
siteId="RefArch"
|
|
46
|
+
shortCode="12345678"
|
|
47
|
+
locale="en-US"
|
|
48
|
+
currency="USD"
|
|
49
|
+
>
|
|
50
|
+
{children}
|
|
51
|
+
</CommerceApiProvider>
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export default App
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
32
58
|
* @returns Provider to wrap your app with
|
|
33
59
|
*/
|
|
34
60
|
declare const CommerceApiProvider: (props: CommerceApiProviderProps) => ReactElement;
|