@salesforce/commerce-sdk-react 3.0.0 → 3.0.1

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 CHANGED
@@ -1,3 +1,6 @@
1
+ ## v3.0.1 (Sep 03, 2024)
2
+ - Fixed an issue where the `expires` attribute in cookies, ensuring it uses seconds instead of days. [#1994](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1994)
3
+
1
4
  ## v3.0.0 (Aug 07, 2024)
2
5
  - Add `meta.displayName` to queries. It can be used to identify queries in performance metrics or logs. [#1895](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1895)
3
6
  - Upgrade to commerce-sdk-isomorphic v3.0.0 [#1914](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1914)
package/auth/index.d.ts CHANGED
@@ -74,6 +74,15 @@ declare class Auth {
74
74
  */
75
75
  private getAccessToken;
76
76
  private clearSFRAAuthToken;
77
+ /**
78
+ * Converts a duration in seconds to a Date object.
79
+ * This function takes a number representing seconds and returns a Date object
80
+ * for the current time plus the given duration.
81
+ *
82
+ * @param {number} seconds - The number of seconds to add to the current time.
83
+ * @returns {Date} A Date object for the expiration time.
84
+ */
85
+ private convertSecondsToDate;
77
86
  /**
78
87
  * This method stores the TokenResponse object retrived from SLAS, and
79
88
  * store the data in storage.
package/auth/index.js CHANGED
@@ -305,6 +305,21 @@ class Auth {
305
305
  store.delete(key);
306
306
  }
307
307
 
308
+ /**
309
+ * Converts a duration in seconds to a Date object.
310
+ * This function takes a number representing seconds and returns a Date object
311
+ * for the current time plus the given duration.
312
+ *
313
+ * @param {number} seconds - The number of seconds to add to the current time.
314
+ * @returns {Date} A Date object for the expiration time.
315
+ */
316
+ convertSecondsToDate(seconds) {
317
+ if (typeof seconds !== 'number') {
318
+ throw new Error('The refresh_token_expires_in seconds parameter must be a number.');
319
+ }
320
+ return new Date(Date.now() + seconds * 1000);
321
+ }
322
+
308
323
  /**
309
324
  * This method stores the TokenResponse object retrived from SLAS, and
310
325
  * store the data in storage.
@@ -320,8 +335,9 @@ class Auth {
320
335
  this.set('usid', res.usid);
321
336
  this.set('customer_type', isGuest ? 'guest' : 'registered');
322
337
  const refreshTokenKey = isGuest ? 'refresh_token_guest' : 'refresh_token_registered';
338
+ const expiresDate = res.refresh_token_expires_in ? this.convertSecondsToDate(res.refresh_token_expires_in) : undefined;
323
339
  this.set(refreshTokenKey, res.refresh_token, {
324
- expires: res.refresh_token_expires_in
340
+ expires: expiresDate
325
341
  });
326
342
  }
327
343
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/commerce-sdk-react",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
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": {
@@ -90,5 +90,5 @@
90
90
  "publishConfig": {
91
91
  "directory": "dist"
92
92
  },
93
- "gitHead": "7a47e6b91a5a0edc69c999115345b9bd5154935f"
93
+ "gitHead": "1fef72f07d07392046c245082df8f8c07c14aeb8"
94
94
  }