@salesforce/commerce-sdk-react 1.0.0-preview.1 → 1.0.0-preview.3

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.
Files changed (45) hide show
  1. package/CHANGELOG.md +1 -2
  2. package/README.md +58 -52
  3. package/auth/index.d.ts +4 -4
  4. package/auth/storage.d.ts +1 -1
  5. package/components/ShopperExperience/Component/index.d.ts +1 -1
  6. package/components/ShopperExperience/Page/index.d.ts +2 -2
  7. package/components/ShopperExperience/types.d.ts +5 -5
  8. package/hooks/ShopperBaskets/cache.d.ts +1 -1
  9. package/hooks/ShopperBaskets/mutation.d.ts +2 -2
  10. package/hooks/ShopperBaskets/query.d.ts +1 -1
  11. package/hooks/ShopperBaskets/queryKeyHelpers.d.ts +4 -4
  12. package/hooks/ShopperContexts/cache.d.ts +1 -1
  13. package/hooks/ShopperContexts/mutation.d.ts +2 -2
  14. package/hooks/ShopperContexts/query.d.ts +1 -1
  15. package/hooks/ShopperContexts/queryKeyHelpers.d.ts +4 -4
  16. package/hooks/ShopperCustomers/cache.d.ts +1 -1
  17. package/hooks/ShopperCustomers/mutation.d.ts +2 -2
  18. package/hooks/ShopperCustomers/query.d.ts +1 -1
  19. package/hooks/ShopperCustomers/queryKeyHelpers.d.ts +4 -4
  20. package/hooks/ShopperExperience/query.d.ts +1 -1
  21. package/hooks/ShopperExperience/queryKeyHelpers.d.ts +4 -4
  22. package/hooks/ShopperGiftCertificates/query.d.ts +1 -1
  23. package/hooks/ShopperGiftCertificates/queryKeyHelpers.d.ts +4 -4
  24. package/hooks/ShopperLogin/mutation.d.ts +2 -2
  25. package/hooks/ShopperLogin/query.d.ts +1 -1
  26. package/hooks/ShopperLogin/queryKeyHelpers.d.ts +4 -4
  27. package/hooks/ShopperOrders/cache.d.ts +1 -1
  28. package/hooks/ShopperOrders/mutation.d.ts +2 -2
  29. package/hooks/ShopperOrders/query.d.ts +1 -1
  30. package/hooks/ShopperOrders/queryKeyHelpers.d.ts +4 -4
  31. package/hooks/ShopperProducts/query.d.ts +1 -1
  32. package/hooks/ShopperProducts/queryKeyHelpers.d.ts +4 -4
  33. package/hooks/ShopperPromotions/query.d.ts +1 -1
  34. package/hooks/ShopperPromotions/queryKeyHelpers.d.ts +4 -4
  35. package/hooks/ShopperSearch/query.d.ts +1 -1
  36. package/hooks/ShopperSearch/queryKeyHelpers.d.ts +4 -4
  37. package/hooks/types.d.ts +27 -27
  38. package/hooks/useAuthHelper.d.ts +1 -1
  39. package/hooks/useCustomerType.d.ts +2 -2
  40. package/hooks/useEncUserId.d.ts +8 -1
  41. package/hooks/useEncUserId.js +13 -2
  42. package/hooks/useLocalStorage.d.ts +1 -1
  43. package/hooks/useUsid.d.ts +8 -1
  44. package/hooks/useUsid.js +17 -9
  45. package/package.json +11 -11
package/CHANGELOG.md CHANGED
@@ -1,5 +1,4 @@
1
- ## v1.0.0-preview.1 (Jun 02, 2023)
2
- ## v1.0.0-preview.0 (May 31, 2023)
1
+ ## v1.0.0-preview.3 (Jun 13, 2023)
3
2
  ## v1.0.0-dev (May 29, 2023)
4
3
  ## v3.0.0-dev (May 12, 2023)
5
4
 
package/README.md CHANGED
@@ -5,12 +5,12 @@ A collection of <a href="https://tanstack.com/query/latest/docs/react/overview">
5
5
 
6
6
  ## 🎯 Features
7
7
 
8
- - Shopper authentication & token management via [SLAS](https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-login)
9
- - Server side data fetching (in conjuction with PWA Kit)
10
- - Phased Launch support ([plugin_slas](https://github.com/SalesforceCommerceCloud/plugin_slas) compatible)
11
- - Built-in caching for easy state management
12
- - automatic cache invalidations/updates via the library's built-in mutations
13
- - automatic cache key generation
8
+ - Shopper authentication & token management via [SLAS](https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-login)
9
+ - Server side data fetching (in conjuction with PWA Kit)
10
+ - Phased Launch support ([plugin_slas](https://github.com/SalesforceCommerceCloud/plugin_slas) compatible)
11
+ - Built-in caching for easy state management
12
+ - automatic cache invalidations/updates via the library's built-in mutations
13
+ - automatic cache key generation
14
14
 
15
15
  ## ⚙️ Installation
16
16
 
@@ -43,7 +43,7 @@ const AppConfig = ({children}) => {
43
43
  {children}
44
44
  </CommerceApiProvider>
45
45
  )
46
- }
46
+ }
47
47
 
48
48
  // Set configuration options for react query.
49
49
  // NOTE: This configuration will be used both on the server-side and client-side.
@@ -65,13 +65,12 @@ export default withReactQuery(AppConfig, options)
65
65
 
66
66
  ## ⚡️ Quickstart (Generic React App)
67
67
 
68
- You can use this library in any React application by creating a new QueryClient and wrap your application with `QueryClientProvider`. For example:
68
+ You can use this library in any React application by creating a new QueryClient and wrap your application with `QueryClientProvider`. For example:
69
69
 
70
70
  ```jsx
71
71
  import {CommerceApiProvider} from '@salesforce/commerce-sdk-react'
72
72
  import {QueryClient, QueryClientProvider} from '@tanstack/react-query'
73
73
 
74
-
75
74
  const App = ({children}) => {
76
75
  const queryClient = new QueryClient()
77
76
 
@@ -91,7 +90,7 @@ const App = ({children}) => {
91
90
  </CommerceApiProvider>
92
91
  </QueryClientProvider>
93
92
  )
94
- }
93
+ }
95
94
 
96
95
  export default App
97
96
  ```
@@ -104,7 +103,7 @@ To help reduce boilerplate code for managing shopper authentication, by default,
104
103
 
105
104
  ### Shopper Session Initialization
106
105
 
107
- On `CommerceApiProvider` mount, the provider initializes shopper session by initiating the SLAS __Public Client__ login flow. The tokens are stored/managed/refreshed by the library.
106
+ On `CommerceApiProvider` mount, the provider initializes shopper session by initiating the SLAS **Public Client** login flow. The tokens are stored/managed/refreshed by the library.
108
107
 
109
108
  ### Authenticate request queue
110
109
 
@@ -136,19 +135,15 @@ You have the option of handling shopper authentication externally, by providing
136
135
 
137
136
  ```jsx
138
137
  const MyComponent = ({children}) => {
139
- return (
140
- <CommerceApiProvider fetchedToken="xxxxxxxxxxxx">
141
- {children}
142
- </CommerceApiProvider>
143
- )
144
- }
138
+ return <CommerceApiProvider fetchedToken="xxxxxxxxxxxx">{children}</CommerceApiProvider>
139
+ }
145
140
  ```
146
141
 
147
142
  ## Hooks
148
143
 
149
144
  The majority of hooks provided in this library are built on top of the [useQuery](https://tanstack.com/query/latest/docs/react/reference/useQuery) and the [useMutation](https://tanstack.com/query/latest/docs/react/reference/useMutation) hook from [react-query](https://tanstack.com/query/latest). React-query provides a declarative way for fetching and updating data. This library takes advantage of the features provided by react-query and combine with the [commerce-sdk-isomorphic](https://github.com/SalesforceCommerceCloud/commerce-sdk-isomorphic) API client to create a collection of hooks to simplify data fetching for SCAPI.
150
145
 
151
- The hooks can be categorized into __Query hooks__ and __Mutation hooks__.
146
+ The hooks can be categorized into **Query hooks** and **Mutation hooks**.
152
147
 
153
148
  ### Query hooks
154
149
 
@@ -158,7 +153,7 @@ The query hooks correspond to the http GET endpoints from the SCAPI. The query h
158
153
  use<EntityName>(CommerceClientOptions, ReactQueryOptions)
159
154
  ```
160
155
 
161
- Both the __required__ and __optional__ parameters for the underlying `commerce-sdk-isomorphic` call is passed as the first parameter:
156
+ Both the **required** and **optional** parameters for the underlying `commerce-sdk-isomorphic` call is passed as the first parameter:
162
157
 
163
158
  ```jsx
164
159
  import {useProduct} from '@salesforce/commerce-sdk-react'
@@ -171,10 +166,12 @@ const Example = () => {
171
166
  }
172
167
  })
173
168
 
174
- return <>
175
- <p>isLoading: {query.isLoading}</p>
176
- <p>name: {query.data?.name}</p>
177
- </>
169
+ return (
170
+ <>
171
+ <p>isLoading: {query.isLoading}</p>
172
+ <p>name: {query.data?.name}</p>
173
+ </>
174
+ )
178
175
  }
179
176
  ```
180
177
 
@@ -186,15 +183,18 @@ import {useBasket} from '@salesforce/commerce-sdk-react'
186
183
  const onServer = typeof window === undefined
187
184
 
188
185
  const Example = ({basketId}) => {
189
- const query = useBasket({
190
- parameters: {
191
- basketId: basketId
186
+ const query = useBasket(
187
+ {
188
+ parameters: {
189
+ basketId: basketId
190
+ }
192
191
  },
193
- }, {
194
- // A common use case for `enabled` is
195
- // to conditionally fetch based on environment
196
- enabled: !onServer && basketId
197
- })
192
+ {
193
+ // A common use case for `enabled` is
194
+ // to conditionally fetch based on environment
195
+ enabled: !onServer && basketId
196
+ }
197
+ )
198
198
  }
199
199
  ```
200
200
 
@@ -215,16 +215,22 @@ const Example = ({basketId}) => {
215
215
  // Typescript IDE intellisense for available options
216
216
  const addItemToBasket = useShopperBasketsMutation('addItemToBasket')
217
217
 
218
- return <button onClick={() => addItemToBasket.mutate({
219
- parameters: {
220
- basketId
221
- },
222
- body: {
223
- productId: '25592770M',
224
- price: 55,
225
- quantity: 1
226
- }
227
- })} />
218
+ return (
219
+ <button
220
+ onClick={() =>
221
+ addItemToBasket.mutate({
222
+ parameters: {
223
+ basketId
224
+ },
225
+ body: {
226
+ productId: '25592770M',
227
+ price: 55,
228
+ quantity: 1
229
+ }
230
+ })
231
+ }
232
+ />
233
+ )
228
234
  }
229
235
  ```
230
236
 
@@ -247,7 +253,7 @@ const Example = ({basketId}) => {
247
253
 
248
254
  Since mutations changes data on the server, the cache entries that are potentially affected by the mutation is automatically invalidated.
249
255
 
250
- For example, an `addItemToBasket` mutation automatically update `useBasket` and `useCustomerBaskets` query cache, because the mutation result contains the information for the updated basket. In other cases, when the mutation response do not have the updated data, the library will invalidate the cache and trigger a re-fetch. For the DELETE endpoints, the library removes the cache entries on successful mutations.
256
+ For example, an `addItemToBasket` mutation automatically update `useBasket` and `useCustomerBaskets` query cache, because the mutation result contains the information for the updated basket. In other cases, when the mutation response do not have the updated data, the library will invalidate the cache and trigger a re-fetch. For the DELETE endpoints, the library removes the cache entries on successful mutations.
251
257
 
252
258
  _💡 Debugging hint: install and include `@tanstack/react-query-devtools` in your React app to see the queries (inspect the query states and cache keys)._
253
259
 
@@ -269,14 +275,13 @@ const Example = () => {
269
275
  const fetchProducts = async () => {
270
276
  const token = await getTokenWhenReady()
271
277
  const products = await api.shopperProducts.getProducts({
272
- parameters: {ids: ids.join(',')},
273
- headers: {
274
- Authorization: `Bearer ${token}`
275
- }
276
- })
278
+ parameters: {ids: ids.join(',')},
279
+ headers: {
280
+ Authorization: `Bearer ${token}`
281
+ }
282
+ })
277
283
  return products
278
284
  }
279
-
280
285
  }
281
286
  ```
282
287
 
@@ -303,18 +308,19 @@ useCustomerId() => null | 'guest' | 'registered'
303
308
  ### `useEncUserId()`
304
309
 
305
310
  ```ts
306
- useEncUserId() => null | string
311
+ useEncUserId() => {encUserId: String, getEncUserIdWhenReady: Promise}
307
312
  ```
308
313
 
309
314
  ### `useUsid()`
310
315
 
311
316
  ```ts
312
- useUsid() => null | string
317
+ useUsid() => {usid: String, getUsidWhenReady: Promise}
313
318
  ```
314
319
 
315
320
  ## Roadmap
316
- - Optimistic update support
317
- - SLAS private client support
321
+
322
+ - Optimistic update support
323
+ - SLAS private client support
318
324
 
319
325
  ## Useful Links:
320
326
 
package/auth/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { helpers, ShopperLoginTypes, ShopperCustomersTypes } from 'commerce-sdk-isomorphic';
2
2
  import { ApiClientConfigParams, Prettify, RemoveStringIndex } from '../hooks/types';
3
3
  import { CustomerType } from '../hooks/useCustomerType';
4
- declare type TokenResponse = ShopperLoginTypes.TokenResponse;
5
- declare type Helpers = typeof helpers;
4
+ type TokenResponse = ShopperLoginTypes.TokenResponse;
5
+ type Helpers = typeof helpers;
6
6
  interface AuthConfig extends ApiClientConfigParams {
7
7
  redirectURI: string;
8
8
  proxy: string;
@@ -16,12 +16,12 @@ interface AuthConfig extends ApiClientConfigParams {
16
16
  * Plus, the getCustomer endpoint only works for registered user, it returns a 404 for a guest user,
17
17
  * and it's not easy to grab this info in user land, so we add it into the Auth object, and expose it via a hook
18
18
  */
19
- export declare type AuthData = Prettify<RemoveStringIndex<TokenResponse> & {
19
+ export type AuthData = Prettify<RemoveStringIndex<TokenResponse> & {
20
20
  customer_type: CustomerType;
21
21
  idp_access_token: string;
22
22
  }>;
23
23
  /** A shopper could be guest or registered, so we store the refresh tokens individually. */
24
- declare type AuthDataKeys = Exclude<keyof AuthData, 'refresh_token'> | 'refresh_token_guest' | 'refresh_token_registered' | 'refresh_token_guest_copy' | 'refresh_token_registered_copy';
24
+ type AuthDataKeys = Exclude<keyof AuthData, 'refresh_token'> | 'refresh_token_guest' | 'refresh_token_registered' | 'refresh_token_guest_copy' | 'refresh_token_registered_copy';
25
25
  /**
26
26
  * This class is used to handle shopper authentication.
27
27
  * It is responsible for initializing shopper session, manage access
package/auth/storage.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import Cookies from 'js-cookie';
2
- export declare type StorageType = 'cookie' | 'local' | 'memory';
2
+ export type StorageType = 'cookie' | 'local' | 'memory';
3
3
  export interface BaseStorageOptions {
4
4
  keySuffix?: string;
5
5
  }
@@ -1,5 +1,5 @@
1
1
  import { Component as ComponentType } from '../types';
2
- declare type ComponentProps = {
2
+ type ComponentProps = {
3
3
  component: ComponentType;
4
4
  };
5
5
  /**
@@ -1,13 +1,13 @@
1
1
  import React from 'react';
2
2
  import type { Component as ComponentType, Page as PageType } from '../types';
3
- declare type ComponentMap = {
3
+ type ComponentMap = {
4
4
  [typeId: string]: React.ComponentType<ComponentType & unknown>;
5
5
  };
6
6
  interface PageProps extends React.ComponentProps<'div'> {
7
7
  page: PageType;
8
8
  components: ComponentMap;
9
9
  }
10
- declare type PageContextValue = {
10
+ type PageContextValue = {
11
11
  components: ComponentMap;
12
12
  };
13
13
  export declare const PageContext: React.Context<PageContextValue | undefined>;
@@ -1,8 +1,8 @@
1
1
  import { ApiClients, DataType } from '../../hooks/types';
2
- declare type ArrayElement<ArrayType extends readonly unknown[]> = ArrayType[number];
3
- declare type Client = ApiClients['shopperExperience'];
4
- export declare type Page = DataType<Client['getPage']>;
5
- export declare type Region = ArrayElement<NonNullable<Page['regions']>>;
6
- export declare type Component = ArrayElement<NonNullable<Region['components']>>;
2
+ type ArrayElement<ArrayType extends readonly unknown[]> = ArrayType[number];
3
+ type Client = ApiClients['shopperExperience'];
4
+ export type Page = DataType<Client['getPage']>;
5
+ export type Region = ArrayElement<NonNullable<Page['regions']>>;
6
+ export type Component = ArrayElement<NonNullable<Region['components']>>;
7
7
  export {};
8
8
  //# sourceMappingURL=types.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { ApiClients, CacheUpdateMatrix } from '../types';
2
- declare type Client = ApiClients['shopperBaskets'];
2
+ type Client = ApiClients['shopperBaskets'];
3
3
  export declare const cacheUpdateMatrix: CacheUpdateMatrix<Client>;
4
4
  export {};
5
5
  //# sourceMappingURL=cache.d.ts.map
@@ -1,6 +1,6 @@
1
1
  import { ApiClients, Argument, DataType } from '../types';
2
2
  import { UseMutationResult } from '@tanstack/react-query';
3
- declare type Client = ApiClients['shopperBaskets'];
3
+ type Client = ApiClients['shopperBaskets'];
4
4
  /**
5
5
  * Mutations available for Shopper Baskets.
6
6
  * @group ShopperBaskets
@@ -151,7 +151,7 @@ export declare const ShopperBasketsMutations: {
151
151
  * @group ShopperBaskets
152
152
  * @category Mutation
153
153
  */
154
- export declare type ShopperBasketsMutation = (typeof ShopperBasketsMutations)[keyof typeof ShopperBasketsMutations];
154
+ export type ShopperBasketsMutation = (typeof ShopperBasketsMutations)[keyof typeof ShopperBasketsMutations];
155
155
  /**
156
156
  * Mutation hook for Shopper Baskets.
157
157
  * @group ShopperBaskets
@@ -1,6 +1,6 @@
1
1
  import { UseQueryResult } from '@tanstack/react-query';
2
2
  import { ApiClients, ApiQueryOptions, Argument, DataType, NullableParameters } from '../types';
3
- declare type Client = ApiClients['shopperBaskets'];
3
+ type Client = ApiClients['shopperBaskets'];
4
4
  /**
5
5
  * Gets a basket.
6
6
  * @group ShopperBaskets
@@ -1,10 +1,10 @@
1
1
  import type { ShopperBaskets } from 'commerce-sdk-isomorphic';
2
2
  import { Argument, ExcludeTail } from '../types';
3
- declare type Client = ShopperBaskets<{
3
+ type Client = ShopperBaskets<{
4
4
  shortCode: string;
5
5
  }>;
6
- declare type Params<T extends keyof QueryKeys> = Partial<Argument<Client[T]>['parameters']>;
7
- export declare type QueryKeys = {
6
+ type Params<T extends keyof QueryKeys> = Partial<Argument<Client[T]>['parameters']>;
7
+ export type QueryKeys = {
8
8
  getBasket: [
9
9
  '/commerce-sdk-react',
10
10
  '/organizations/',
@@ -52,7 +52,7 @@ export declare type QueryKeys = {
52
52
  Params<'getTaxesFromBasket'>
53
53
  ];
54
54
  };
55
- declare type QueryKeyHelper<T extends keyof QueryKeys> = {
55
+ type QueryKeyHelper<T extends keyof QueryKeys> = {
56
56
  /**
57
57
  * Reduces the given parameters (which may have additional, unknown properties) to an object
58
58
  * containing *only* the properties required for an endpoint.
@@ -1,5 +1,5 @@
1
1
  import { ApiClients, CacheUpdateMatrix } from '../types';
2
- declare type Client = ApiClients['shopperContexts'];
2
+ type Client = ApiClients['shopperContexts'];
3
3
  export declare const cacheUpdateMatrix: CacheUpdateMatrix<Client>;
4
4
  export {};
5
5
  //# sourceMappingURL=cache.d.ts.map
@@ -1,6 +1,6 @@
1
1
  import { ApiClients, Argument, DataType } from '../types';
2
2
  import { UseMutationResult } from '@tanstack/react-query';
3
- declare type Client = ApiClients['shopperContexts'];
3
+ type Client = ApiClients['shopperContexts'];
4
4
  /**
5
5
  * Mutation for Shopper Contexts.
6
6
  * @group ShopperContexts
@@ -29,7 +29,7 @@ export declare const ShopperContextsMutations: {
29
29
  * @group ShopperContexts
30
30
  * @category Mutation
31
31
  */
32
- export declare type ShopperContextsMutation = (typeof ShopperContextsMutations)[keyof typeof ShopperContextsMutations];
32
+ export type ShopperContextsMutation = (typeof ShopperContextsMutations)[keyof typeof ShopperContextsMutations];
33
33
  /**
34
34
  * Mutation hook for Shopper Contexts.
35
35
  * @group ShopperContexts
@@ -1,6 +1,6 @@
1
1
  import { UseQueryResult } from '@tanstack/react-query';
2
2
  import { ApiClients, ApiQueryOptions, Argument, DataType, NullableParameters } from '../types';
3
- declare type Client = ApiClients['shopperContexts'];
3
+ type Client = ApiClients['shopperContexts'];
4
4
  /**
5
5
  * Gets the shopper's context based on the shopperJWT.
6
6
  * @group ShopperContexts
@@ -1,10 +1,10 @@
1
1
  import type { ShopperContexts } from 'commerce-sdk-isomorphic';
2
2
  import { Argument, ExcludeTail } from '../types';
3
- declare type Client = ShopperContexts<{
3
+ type Client = ShopperContexts<{
4
4
  shortCode: string;
5
5
  }>;
6
- declare type Params<T extends keyof QueryKeys> = Partial<Argument<Client[T]>['parameters']>;
7
- export declare type QueryKeys = {
6
+ type Params<T extends keyof QueryKeys> = Partial<Argument<Client[T]>['parameters']>;
7
+ export type QueryKeys = {
8
8
  getShopperContext: [
9
9
  '/commerce-sdk-react',
10
10
  '/organizations/',
@@ -14,7 +14,7 @@ export declare type QueryKeys = {
14
14
  Params<'getShopperContext'>
15
15
  ];
16
16
  };
17
- declare type QueryKeyHelper<T extends keyof QueryKeys> = {
17
+ type QueryKeyHelper<T extends keyof QueryKeys> = {
18
18
  /**
19
19
  * Reduces the given parameters (which may have additional, unknown properties) to an object
20
20
  * containing *only* the properties required for an endpoint.
@@ -1,5 +1,5 @@
1
1
  import { ApiClients, CacheUpdateMatrix } from '../types';
2
- declare type Client = ApiClients['shopperCustomers'];
2
+ type Client = ApiClients['shopperCustomers'];
3
3
  export declare const cacheUpdateMatrix: CacheUpdateMatrix<Client>;
4
4
  export {};
5
5
  //# sourceMappingURL=cache.d.ts.map
@@ -1,6 +1,6 @@
1
1
  import { ApiClients, Argument, DataType } from '../types';
2
2
  import { UseMutationResult } from '@tanstack/react-query';
3
- declare type Client = ApiClients['shopperCustomers'];
3
+ type Client = ApiClients['shopperCustomers'];
4
4
  /**
5
5
  * Mutations available for Shopper Customers.
6
6
  * @group ShopperCustomers
@@ -92,7 +92,7 @@ export declare const ShopperCustomersMutations: {
92
92
  * @group ShopperCustomers
93
93
  * @category Mutation
94
94
  */
95
- export declare type ShopperCustomersMutation = (typeof ShopperCustomersMutations)[keyof typeof ShopperCustomersMutations];
95
+ export type ShopperCustomersMutation = (typeof ShopperCustomersMutations)[keyof typeof ShopperCustomersMutations];
96
96
  /**
97
97
  * Mutation hook for Shopper Customers.
98
98
  * @group ShopperCustomers
@@ -1,6 +1,6 @@
1
1
  import { UseQueryResult } from '@tanstack/react-query';
2
2
  import { ApiClients, ApiQueryOptions, Argument, DataType, NullableParameters } from '../types';
3
- declare type Client = ApiClients['shopperCustomers'];
3
+ type Client = ApiClients['shopperCustomers'];
4
4
  /**
5
5
  * Gets a customer's information.
6
6
  *
@@ -1,10 +1,10 @@
1
1
  import type { ShopperCustomers } from 'commerce-sdk-isomorphic';
2
2
  import { Argument, ExcludeTail } from '../types';
3
- declare type Client = ShopperCustomers<{
3
+ type Client = ShopperCustomers<{
4
4
  shortCode: string;
5
5
  }>;
6
- declare type Params<T extends keyof QueryKeys> = Partial<Argument<Client[T]>['parameters']>;
7
- export declare type QueryKeys = {
6
+ type Params<T extends keyof QueryKeys> = Partial<Argument<Client[T]>['parameters']>;
7
+ export type QueryKeys = {
8
8
  getExternalProfile: [
9
9
  '/commerce-sdk-react',
10
10
  '/organizations/',
@@ -115,7 +115,7 @@ export declare type QueryKeys = {
115
115
  Params<'getProductListItem'>
116
116
  ];
117
117
  };
118
- declare type QueryKeyHelper<T extends keyof QueryKeys> = {
118
+ type QueryKeyHelper<T extends keyof QueryKeys> = {
119
119
  /**
120
120
  * Reduces the given parameters (which may have additional, unknown properties) to an object
121
121
  * containing *only* the properties required for an endpoint.
@@ -1,6 +1,6 @@
1
1
  import { UseQueryResult } from '@tanstack/react-query';
2
2
  import { ApiClients, ApiQueryOptions, Argument, DataType, NullableParameters } from '../types';
3
- declare type Client = ApiClients['shopperExperience'];
3
+ type Client = ApiClients['shopperExperience'];
4
4
  /**
5
5
  * Get Page Designer pages.
6
6
  *
@@ -1,10 +1,10 @@
1
1
  import type { ShopperExperience } from 'commerce-sdk-isomorphic';
2
2
  import { Argument, ExcludeTail } from '../types';
3
- declare type Client = ShopperExperience<{
3
+ type Client = ShopperExperience<{
4
4
  shortCode: string;
5
5
  }>;
6
- declare type Params<T extends keyof QueryKeys> = Partial<Argument<Client[T]>['parameters']>;
7
- export declare type QueryKeys = {
6
+ type Params<T extends keyof QueryKeys> = Partial<Argument<Client[T]>['parameters']>;
7
+ export type QueryKeys = {
8
8
  getPages: [
9
9
  '/commerce-sdk-react',
10
10
  '/organizations/',
@@ -21,7 +21,7 @@ export declare type QueryKeys = {
21
21
  Params<'getPage'>
22
22
  ];
23
23
  };
24
- declare type QueryKeyHelper<T extends keyof QueryKeys> = {
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,6 +1,6 @@
1
1
  import { UseQueryResult } from '@tanstack/react-query';
2
2
  import { ApiClients, ApiQueryOptions, Argument, DataType, NullableParameters } from '../types';
3
- declare type Client = ApiClients['shopperGiftCertificates'];
3
+ type Client = ApiClients['shopperGiftCertificates'];
4
4
  /**
5
5
  * Action to retrieve an existing gift certificate.
6
6
  * @group ShopperGiftCertificates
@@ -1,10 +1,10 @@
1
1
  import type { ShopperGiftCertificates } from 'commerce-sdk-isomorphic';
2
2
  import { Argument, ExcludeTail } from '../types';
3
- declare type Client = ShopperGiftCertificates<{
3
+ type Client = ShopperGiftCertificates<{
4
4
  shortCode: string;
5
5
  }>;
6
- declare type Params<T extends keyof QueryKeys> = Partial<Argument<Client[T]>['parameters']>;
7
- export declare type QueryKeys = {
6
+ type Params<T extends keyof QueryKeys> = Partial<Argument<Client[T]>['parameters']>;
7
+ export type QueryKeys = {
8
8
  getGiftCertificate: [
9
9
  '/commerce-sdk-react',
10
10
  '/organizations/',
@@ -13,7 +13,7 @@ export declare type QueryKeys = {
13
13
  Params<'getGiftCertificate'>
14
14
  ];
15
15
  };
16
- declare type QueryKeyHelper<T extends keyof QueryKeys> = {
16
+ type QueryKeyHelper<T extends keyof QueryKeys> = {
17
17
  /**
18
18
  * Reduces the given parameters (which may have additional, unknown properties) to an object
19
19
  * containing *only* the properties required for an endpoint.
@@ -1,6 +1,6 @@
1
1
  import { ApiClients, Argument, DataType } from '../types';
2
2
  import { UseMutationResult } from '@tanstack/react-query';
3
- declare type Client = ApiClients['shopperLogin'];
3
+ type Client = ApiClients['shopperLogin'];
4
4
  /**
5
5
  * Mutations available for Shopper Login
6
6
  * @group ShopperLogin
@@ -80,7 +80,7 @@ The value of the `_sfdc_client_auth` header must be a Base64-encoded string. The
80
80
  * @group ShopperLogin
81
81
  * @category Mutation
82
82
  */
83
- export declare type ShopperLoginMutation = (typeof ShopperLoginMutations)[keyof typeof ShopperLoginMutations];
83
+ export type ShopperLoginMutation = (typeof ShopperLoginMutations)[keyof typeof ShopperLoginMutations];
84
84
  /**
85
85
  * Mutation hook for Shopper Login.
86
86
  * @group ShopperLogin
@@ -1,6 +1,6 @@
1
1
  import { UseQueryResult } from '@tanstack/react-query';
2
2
  import { ApiClients, ApiQueryOptions, Argument, DataType, NullableParameters } from '../types';
3
- declare type Client = ApiClients['shopperLogin'];
3
+ type Client = ApiClients['shopperLogin'];
4
4
  /**
5
5
  * Get credential quality statistics for a user.
6
6
  * @group ShopperLogin
@@ -1,10 +1,10 @@
1
1
  import type { ShopperLogin } from 'commerce-sdk-isomorphic';
2
2
  import { Argument, ExcludeTail } from '../types';
3
- declare type Client = ShopperLogin<{
3
+ type Client = ShopperLogin<{
4
4
  shortCode: string;
5
5
  }>;
6
- declare type Params<T extends keyof QueryKeys> = Partial<Argument<Client[T]>['parameters']>;
7
- export declare type QueryKeys = {
6
+ type Params<T extends keyof QueryKeys> = Partial<Argument<Client[T]>['parameters']>;
7
+ export type QueryKeys = {
8
8
  retrieveCredQualityUserInfo: [
9
9
  '/commerce-sdk-react',
10
10
  '/organizations/',
@@ -34,7 +34,7 @@ export declare type QueryKeys = {
34
34
  Params<'getJwksUri'>
35
35
  ];
36
36
  };
37
- declare type QueryKeyHelper<T extends keyof QueryKeys> = {
37
+ type QueryKeyHelper<T extends keyof QueryKeys> = {
38
38
  /**
39
39
  * Reduces the given parameters (which may have additional, unknown properties) to an object
40
40
  * containing *only* the properties required for an endpoint.
@@ -1,5 +1,5 @@
1
1
  import { ApiClients, CacheUpdateMatrix } from '../types';
2
- declare type Client = ApiClients['shopperOrders'];
2
+ type Client = ApiClients['shopperOrders'];
3
3
  export declare const cacheUpdateMatrix: CacheUpdateMatrix<Client>;
4
4
  export {};
5
5
  //# sourceMappingURL=cache.d.ts.map
@@ -1,6 +1,6 @@
1
1
  import { ApiClients, Argument, DataType } from '../types';
2
2
  import { UseMutationResult } from '@tanstack/react-query';
3
- declare type Client = ApiClients['shopperOrders'];
3
+ type Client = ApiClients['shopperOrders'];
4
4
  /**
5
5
  * Mutations available for Shopper Orders
6
6
  * @group ShopperOrders
@@ -39,7 +39,7 @@ The payment instrument is added with the provided details. The payment method mu
39
39
  * @group ShopperOrders
40
40
  * @category Mutation
41
41
  */
42
- export declare type ShopperOrdersMutation = (typeof ShopperOrdersMutations)[keyof typeof ShopperOrdersMutations];
42
+ export type ShopperOrdersMutation = (typeof ShopperOrdersMutations)[keyof typeof ShopperOrdersMutations];
43
43
  /**
44
44
  * Mutation hook for Shopper Orders.
45
45
  * @group ShopperOrders
@@ -1,6 +1,6 @@
1
1
  import { UseQueryResult } from '@tanstack/react-query';
2
2
  import { ApiClients, ApiQueryOptions, Argument, DataType, NullableParameters } from '../types';
3
- declare type Client = ApiClients['shopperOrders'];
3
+ type Client = ApiClients['shopperOrders'];
4
4
  /**
5
5
  * Gets information for an order.
6
6
  * @group ShopperOrders
@@ -1,10 +1,10 @@
1
1
  import type { ShopperOrders } from 'commerce-sdk-isomorphic';
2
2
  import { Argument, ExcludeTail } from '../types';
3
- declare type Client = ShopperOrders<{
3
+ type Client = ShopperOrders<{
4
4
  shortCode: string;
5
5
  }>;
6
- declare type Params<T extends keyof QueryKeys> = Partial<Argument<Client[T]>['parameters']>;
7
- export declare type QueryKeys = {
6
+ type Params<T extends keyof QueryKeys> = Partial<Argument<Client[T]>['parameters']>;
7
+ export type QueryKeys = {
8
8
  getOrder: [
9
9
  '/commerce-sdk-react',
10
10
  '/organizations/',
@@ -32,7 +32,7 @@ export declare type QueryKeys = {
32
32
  Params<'getTaxesFromOrder'>
33
33
  ];
34
34
  };
35
- declare type QueryKeyHelper<T extends keyof QueryKeys> = {
35
+ type QueryKeyHelper<T extends keyof QueryKeys> = {
36
36
  /**
37
37
  * Reduces the given parameters (which may have additional, unknown properties) to an object
38
38
  * containing *only* the properties required for an endpoint.
@@ -1,6 +1,6 @@
1
1
  import { UseQueryResult } from '@tanstack/react-query';
2
2
  import { ApiClients, ApiQueryOptions, Argument, DataType, NullableParameters } from '../types';
3
- declare type Client = ApiClients['shopperProducts'];
3
+ type Client = ApiClients['shopperProducts'];
4
4
  /**
5
5
  * Allows access to multiple products by a single request. Only products that are online and assigned to a site catalog are returned. The maximum number of productIDs that can be requested are 24. Along with product details, the availability, product options, images, price, promotions, and variations for the valid products will be included, as appropriate.
6
6
  * @group ShopperProducts
@@ -1,10 +1,10 @@
1
1
  import type { ShopperProducts } from 'commerce-sdk-isomorphic';
2
2
  import { Argument, ExcludeTail } from '../types';
3
- declare type Client = ShopperProducts<{
3
+ type Client = ShopperProducts<{
4
4
  shortCode: string;
5
5
  }>;
6
- declare type Params<T extends keyof QueryKeys> = Partial<Argument<Client[T]>['parameters']>;
7
- export declare type QueryKeys = {
6
+ type Params<T extends keyof QueryKeys> = Partial<Argument<Client[T]>['parameters']>;
7
+ export type QueryKeys = {
8
8
  getProducts: [
9
9
  '/commerce-sdk-react',
10
10
  '/organizations/',
@@ -36,7 +36,7 @@ export declare type QueryKeys = {
36
36
  Params<'getCategory'>
37
37
  ];
38
38
  };
39
- declare type QueryKeyHelper<T extends keyof QueryKeys> = {
39
+ type QueryKeyHelper<T extends keyof QueryKeys> = {
40
40
  /**
41
41
  * Reduces the given parameters (which may have additional, unknown properties) to an object
42
42
  * containing *only* the properties required for an endpoint.
@@ -1,6 +1,6 @@
1
1
  import { UseQueryResult } from '@tanstack/react-query';
2
2
  import { ApiClients, ApiQueryOptions, Argument, DataType, NullableParameters } from '../types';
3
- declare type Client = ApiClients['shopperPromotions'];
3
+ type Client = ApiClients['shopperPromotions'];
4
4
  /**
5
5
  * Returns an array of enabled promotions for a list of specified IDs. In the request URL, you can specify up to 50 IDs. If you specify an ID that contains either parentheses or the separator characters, you must URL encode these characters. Each request returns only enabled promotions as the server does not consider promotion qualifiers or schedules.
6
6
  * @group ShopperPromotions
@@ -1,10 +1,10 @@
1
1
  import type { ShopperPromotions } from 'commerce-sdk-isomorphic';
2
2
  import { Argument, ExcludeTail } from '../types';
3
- declare type Client = ShopperPromotions<{
3
+ type Client = ShopperPromotions<{
4
4
  shortCode: string;
5
5
  }>;
6
- declare type Params<T extends keyof QueryKeys> = Partial<Argument<Client[T]>['parameters']>;
7
- export declare type QueryKeys = {
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
- declare type QueryKeyHelper<T extends keyof QueryKeys> = {
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,6 +1,6 @@
1
1
  import { UseQueryResult } from '@tanstack/react-query';
2
2
  import { ApiClients, ApiQueryOptions, Argument, DataType, NullableParameters } from '../types';
3
- declare type Client = ApiClients['shopperSearch'];
3
+ type Client = ApiClients['shopperSearch'];
4
4
  /**
5
5
  * Provides keyword and refinement search functionality for products.
6
6
  *
@@ -1,10 +1,10 @@
1
1
  import type { ShopperSearch } from 'commerce-sdk-isomorphic';
2
2
  import { Argument, ExcludeTail } from '../types';
3
- declare type Client = ShopperSearch<{
3
+ type Client = ShopperSearch<{
4
4
  shortCode: string;
5
5
  }>;
6
- declare type Params<T extends keyof QueryKeys> = Partial<Argument<Client[T]>['parameters']>;
7
- export declare type QueryKeys = {
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
- declare type QueryKeyHelper<T extends keyof QueryKeys> = {
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 declare type Prettify<T extends object> = NonNullable<Pick<T, keyof T>>;
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 declare type RequireKeys<T, K extends keyof T> = Prettify<T & Required<Pick<T, K>>>;
9
+ export type RequireKeys<T, K extends keyof T> = Prettify<T & Required<Pick<T, K>>>;
10
10
  /** Removes keys whose value is `never`. */
11
- declare type RemoveNeverValues<T> = {
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
- declare type StringIndexToNever<T> = {
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 declare type RemoveStringIndex<T> = RemoveNeverValues<StringIndexToNever<T>>;
19
+ export type RemoveStringIndex<T> = RemoveNeverValues<StringIndexToNever<T>>;
20
20
  /** Gets the last element of an array. */
21
- export declare type Tail<T extends readonly unknown[]> = T extends [...head: unknown[], tail: infer Tail] ? Tail : T;
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 declare type ExcludeTail<T extends readonly unknown[]> = T extends readonly [...infer Head, unknown] ? T extends unknown[] ? Head : Readonly<Head> : T;
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
- declare type AllowNull<T> = {
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
- declare type NullKeys<T> = {
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 declare type NullToOptional<T> = Omit<T, NullKeys<T>> & {
33
+ export type NullToOptional<T> = Omit<T, NullKeys<T>> & {
34
34
  [K in keyof T]?: NonNullable<T[K]>;
35
35
  };
36
- export declare type ApiClientConfigParams = {
36
+ export type ApiClientConfigParams = {
37
37
  clientId: string;
38
38
  organizationId: string;
39
39
  siteId: string;
@@ -56,11 +56,11 @@ export interface ApiClients {
56
56
  shopperPromotions: ShopperPromotions<ApiClientConfigParams>;
57
57
  shopperSearch: ShopperSearch<ApiClientConfigParams>;
58
58
  }
59
- export declare type ApiClient = ApiClients[keyof ApiClients];
59
+ export type ApiClient = ApiClients[keyof ApiClients];
60
60
  /**
61
61
  * Generic signature of the options objects used by commerce-sdk-isomorphic
62
62
  */
63
- export declare 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>> = {
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>> = {
64
64
  parameters?: Parameters;
65
65
  headers?: Headers;
66
66
  body?: Body;
@@ -68,35 +68,35 @@ export declare type ApiOptions<Parameters extends object = Record<string, unknow
68
68
  /**
69
69
  * Generic signature of API methods exported by commerce-sdk-isomorphic
70
70
  */
71
- export declare type ApiMethod<Options extends ApiOptions, Data> = {
71
+ export type ApiMethod<Options extends ApiOptions, Data> = {
72
72
  (options: Options): Promise<Data>;
73
73
  };
74
74
  /**
75
75
  * The first argument of a function.
76
76
  */
77
- export declare type Argument<T extends (arg: any) => unknown> = NonNullable<Parameters<T>[0]>;
77
+ export type Argument<T extends (arg: any) => unknown> = NonNullable<Parameters<T>[0]>;
78
78
  /**
79
79
  * The data type returned by a commerce-sdk-isomorphic method when the raw response
80
80
  * flag is not set.
81
81
  */
82
- export declare type DataType<T> = T extends ApiMethod<any, Response | infer R> ? R : never;
82
+ export type DataType<T> = T extends ApiMethod<any, Response | infer R> ? R : never;
83
83
  /**
84
84
  * Merged headers and parameters from client config and options, mimicking the behavior
85
85
  * of commerce-sdk-isomorphic.
86
86
  */
87
- export declare 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']>>>;
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']>>>;
88
88
  /** Query key interface used by API query hooks. */
89
- export declare type ApiQueryKey<Params extends Record<string, unknown> = Record<string, unknown>> = readonly [...path: (string | undefined)[], parameters: Params];
89
+ export type ApiQueryKey<Params extends Record<string, unknown> = Record<string, unknown>> = readonly [...path: (string | undefined)[], parameters: Params];
90
90
  /** Query options for endpoint hooks. */
91
- export declare type ApiQueryOptions<Method extends ApiMethod<any, unknown>> = Prettify<Omit<UseQueryOptions<DataType<Method>, unknown, DataType<Method>, ApiQueryKey>, 'queryFn' | 'queryKey'>>;
91
+ export type ApiQueryOptions<Method extends ApiMethod<any, unknown>> = Prettify<Omit<UseQueryOptions<DataType<Method>, unknown, DataType<Method>, ApiQueryKey>, 'queryFn' | 'queryKey'>>;
92
92
  /** Adds `null` as an allowed value to all parameters. */
93
- export declare type NullableParameters<T extends {
93
+ export type NullableParameters<T extends {
94
94
  parameters?: object;
95
95
  }> = {
96
96
  [K in keyof T]: K extends 'parameters' ? AllowNull<T[K]> : T[K];
97
97
  };
98
98
  /** Remove `null` and `undefined` values from all parameters. */
99
- export declare type OmitNullableParameters<T extends {
99
+ export type OmitNullableParameters<T extends {
100
100
  parameters: object;
101
101
  }> = Omit<T, 'parameters'> & {
102
102
  parameters: NullToOptional<T['parameters']>;
@@ -106,25 +106,25 @@ export declare type OmitNullableParameters<T extends {
106
106
  * @property queryKey - The query key to update
107
107
  * @property updater - Either the new data or a function that accepts old data and returns new data
108
108
  */
109
- export declare type CacheUpdateUpdate<T> = {
109
+ export type CacheUpdateUpdate<T> = {
110
110
  queryKey: ApiQueryKey;
111
111
  updater?: Updater<T | undefined, T | undefined>;
112
112
  };
113
113
  /** Query predicate for queries to invalidate */
114
- export declare type CacheUpdateInvalidate = InvalidateQueryFilters;
114
+ export type CacheUpdateInvalidate = InvalidateQueryFilters;
115
115
  /** Query predicate for queries to remove */
116
- export declare type CacheUpdateRemove = QueryFilters;
116
+ export type CacheUpdateRemove = QueryFilters;
117
117
  /** Collection of updates to make to the cache when a request completes. */
118
- export declare type CacheUpdate = {
118
+ export type CacheUpdate = {
119
119
  update?: CacheUpdateUpdate<unknown>[];
120
120
  invalidate?: CacheUpdateInvalidate[];
121
121
  remove?: CacheUpdateRemove[];
122
122
  clear?: boolean;
123
123
  };
124
124
  /** Generates a collection of cache updates to make for a given request. */
125
- export declare type CacheUpdateGetter<Options, Data> = (customerId: string | null, options: Options, response: Data) => CacheUpdate;
125
+ export type CacheUpdateGetter<Options, Data> = (customerId: string | null, options: Options, response: Data) => CacheUpdate;
126
126
  /** Collection of cache update getters for each method of an API client. */
127
- export declare type CacheUpdateMatrix<Client extends ApiClient> = {
127
+ export type CacheUpdateMatrix<Client extends ApiClient> = {
128
128
  [Method in keyof Client]?: Client[Method] extends ApiMethod<any, Response | infer Data> ? CacheUpdateGetter<MergedOptions<Client, Argument<Client[Method]>>, Data> : never;
129
129
  };
130
130
  export {};
@@ -16,7 +16,7 @@ export declare const AuthHelpers: {
16
16
  * @category Shopper Authentication
17
17
  *
18
18
  */
19
- export declare type AuthHelper = (typeof AuthHelpers)[keyof typeof AuthHelpers];
19
+ export type AuthHelper = (typeof AuthHelpers)[keyof typeof AuthHelpers];
20
20
  /**
21
21
  * A hook for Public Client OAuth helpers.
22
22
  *
@@ -1,5 +1,5 @@
1
- export declare type CustomerType = null | 'guest' | 'registered';
2
- declare type useCustomerType = {
1
+ export type CustomerType = null | 'guest' | 'registered';
2
+ type useCustomerType = {
3
3
  customerType: CustomerType;
4
4
  isGuest: boolean;
5
5
  isRegistered: boolean;
@@ -1,3 +1,10 @@
1
+ /**
2
+ * @group Shopper Authentication helpers
3
+ */
4
+ interface EncUserId {
5
+ encUserId: string | null;
6
+ getEncUserIdWhenReady: () => Promise<string>;
7
+ }
1
8
  /**
2
9
  * Hook that returns the ecom user ID.
3
10
  *
@@ -7,6 +14,6 @@
7
14
  * @category Shopper Authentication
8
15
  *
9
16
  */
10
- declare const useEncUserId: () => string | null;
17
+ declare const useEncUserId: () => EncUserId;
11
18
  export default useEncUserId;
12
19
  //# sourceMappingURL=useEncUserId.d.ts.map
@@ -17,6 +17,10 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
17
17
 
18
18
  const onClient = typeof window !== 'undefined';
19
19
 
20
+ /**
21
+ * @group Shopper Authentication helpers
22
+ */
23
+
20
24
  /**
21
25
  * Hook that returns the ecom user ID.
22
26
  *
@@ -29,11 +33,18 @@ const onClient = typeof window !== 'undefined';
29
33
  const useEncUserId = () => {
30
34
  const config = (0, _useConfig.default)();
31
35
  const auth = (0, _useAuthContext.default)();
32
- return onClient ?
36
+ const encUserId = onClient ?
33
37
  // This conditional is a constant value based on the environment, so the same path will
34
38
  // always be followed., and the "rule of hooks" is not violated.
35
39
  // eslint-disable-next-line react-hooks/rules-of-hooks
36
- (0, _useLocalStorage.default)(`$enc_user_id_${config.siteId}`) : auth.get('enc_user_id');
40
+ (0, _useLocalStorage.default)(`enc_user_id_${config.siteId}`) : auth.get('enc_user_id');
41
+ const getEncUserIdWhenReady = () => auth.ready().then(({
42
+ enc_user_id
43
+ }) => enc_user_id);
44
+ return {
45
+ encUserId,
46
+ getEncUserIdWhenReady
47
+ };
37
48
  };
38
49
  var _default = useEncUserId;
39
50
  exports.default = _default;
@@ -1,4 +1,4 @@
1
- declare type Value = string | null;
1
+ type Value = string | null;
2
2
  /**
3
3
  * @internal
4
4
  *
@@ -1,9 +1,16 @@
1
+ /**
2
+ * @group Shopper Authentication helpers
3
+ */
4
+ interface Usid {
5
+ usid: string | null;
6
+ getUsidWhenReady: () => Promise<string>;
7
+ }
1
8
  /**
2
9
  * Hook that returns the usid associated with the current access token.
3
10
  *
4
11
  * @group Helpers
5
12
  * @category Shopper Authentication
6
13
  */
7
- declare const useUsid: () => string | null;
14
+ declare const useUsid: () => Usid;
8
15
  export default useUsid;
9
16
  //# sourceMappingURL=useUsid.d.ts.map
package/hooks/useUsid.js CHANGED
@@ -5,8 +5,6 @@ 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"));
10
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
9
  /*
12
10
  * Copyright (c) 2022, salesforce.com, inc.
@@ -15,7 +13,9 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
15
13
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
16
14
  */
17
15
 
18
- const onClient = typeof window !== 'undefined';
16
+ /**
17
+ * @group Shopper Authentication helpers
18
+ */
19
19
 
20
20
  /**
21
21
  * Hook that returns the usid associated with the current access token.
@@ -24,13 +24,21 @@ const onClient = typeof window !== 'undefined';
24
24
  * @category Shopper Authentication
25
25
  */
26
26
  const useUsid = () => {
27
- const config = (0, _useConfig.default)();
28
27
  const auth = (0, _useAuthContext.default)();
29
- return onClient ?
30
- // This conditional is a constant value based on the environment, so the same path will
31
- // always be followed., and the "rule of hooks" is not violated.
32
- // eslint-disable-next-line react-hooks/rules-of-hooks
33
- (0, _useLocalStorage.default)(`usid_${config.siteId}`) : auth.get('usid');
28
+
29
+ // TODO: auth.get does not trigger a re-render.
30
+ // This is fine for now since the only time the usid changes is on logout
31
+ // and currently when we log out we redirect to the login page which
32
+ // causes components to unmount.
33
+ // This will need to change if we stay on the PDP after logout
34
+ const usid = auth.get('usid');
35
+ const getUsidWhenReady = () => auth.ready().then(({
36
+ usid
37
+ }) => usid);
38
+ return {
39
+ usid,
40
+ getUsidWhenReady
41
+ };
34
42
  };
35
43
  var _default = useUsid;
36
44
  exports.default = _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/commerce-sdk-react",
3
- "version": "1.0.0-preview.1",
3
+ "version": "1.0.0-preview.3",
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": {
@@ -47,20 +47,20 @@
47
47
  "typedoc-plugin-missing-exports": "^2.0.0"
48
48
  },
49
49
  "devDependencies": {
50
- "@salesforce/pwa-kit-dev": "3.0.0-preview.1",
50
+ "@salesforce/pwa-kit-dev": "3.0.0-preview.3",
51
51
  "@tanstack/react-query": "^4.28.0",
52
52
  "@testing-library/jest-dom": "^5.16.5",
53
53
  "@testing-library/react": "^14.0.0",
54
54
  "@types/js-cookie": "^3.0.3",
55
- "@types/jsonwebtoken": "^8.5.9",
55
+ "@types/jsonwebtoken": "^9.0.0",
56
56
  "@types/jwt-decode": "^3.1.0",
57
57
  "@types/node": "^14.18.40",
58
58
  "@types/react": "^18.2.0",
59
59
  "@types/react-dom": "^18.2.1",
60
60
  "@types/react-helmet": "^6.1.6",
61
61
  "cross-env": "^5.2.1",
62
- "internal-lib-build": "3.0.0-preview.1",
63
- "jsonwebtoken": "^8.5.1",
62
+ "internal-lib-build": "3.0.0-preview.3",
63
+ "jsonwebtoken": "^9.0.0",
64
64
  "nock": "^13.3.0",
65
65
  "nodemon": "^2.0.22",
66
66
  "react": "^18.2.0",
@@ -68,13 +68,13 @@
68
68
  "react-helmet": "^6.1.0",
69
69
  "semver": "^7.3.8",
70
70
  "shelljs": "^0.8.5",
71
- "typedoc": "^0.23.28",
72
- "typescript": "4.8.3"
71
+ "typedoc": "^0.24.7",
72
+ "typescript": "^4.8.3"
73
73
  },
74
74
  "peerDependencies": {
75
- "@tanstack/react-query": "^4",
76
- "react": "^18",
77
- "react-helmet": "6"
75
+ "@tanstack/react-query": "^4.28.0",
76
+ "react": "^18.2.0",
77
+ "react-helmet": "^6.1.0"
78
78
  },
79
79
  "optionalDependencies": {
80
80
  "prop-types": "^15.8.1"
@@ -86,5 +86,5 @@
86
86
  "publishConfig": {
87
87
  "directory": "dist"
88
88
  },
89
- "gitHead": "457b0179e4cf536e55bf9b21758302ff68ef3ea4"
89
+ "gitHead": "0d435ccfb378e46a536e0eb4da3c9d3364ce89ea"
90
90
  }