@usequeek/theme-kit 0.1.34 → 0.1.35

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usequeek/theme-kit",
3
- "version": "0.1.34",
3
+ "version": "0.1.35",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "description": "The runtime a Queek storefront theme is built on: hooks, stores, page renderer, navigation, shared blocks and locale strings.",
@@ -90,6 +90,12 @@ export function getLastRequestId(): string | null {
90
90
 
91
91
  let cachedClient: QueekClientInstance | null = null;
92
92
  let cachedSlug: string | null = null;
93
+ let cachedTokens: string | null = null;
94
+
95
+ /** The stored token pair, as one comparable value. */
96
+ function storedTokens(): string {
97
+ return `${localStorageAdapter.getItem(ACCESS_KEY) ?? ''}\n${localStorageAdapter.getItem(REFRESH_KEY) ?? ''}`;
98
+ }
93
99
 
94
100
  /**
95
101
  * The Queek customer SDK client for this store, created once and reused.
@@ -97,14 +103,22 @@ let cachedSlug: string | null = null;
97
103
  * every request to the same-origin `/api/v1`. A 401 signs the customer out and
98
104
  * opens the sign-in modal (see `triggerReauth`).
99
105
  *
106
+ * The SDK reads the tokens once, when the client is created, so the cached
107
+ * client is rebuilt whenever the stored pair changed under it. Another tab
108
+ * signing in writes the tokens here too, and the user store syncs across tabs:
109
+ * a client still holding no token would send a signed-in shopper's request
110
+ * bare, its 401 would sign them out, and that sign-out would sync back to the
111
+ * tab they had just signed in on.
112
+ *
100
113
  * @example
101
114
  * const client = getQueekClient(vendor.slug);
102
115
  * const orders = await client.get('/client/store/orders');
103
116
  */
104
117
  export function getQueekClient(vendorSlug?: string): QueekClientInstance {
105
118
  const slug = vendorSlug ?? null;
119
+ const tokens = storedTokens();
106
120
 
107
- if (cachedClient && cachedSlug === slug) {
121
+ if (cachedClient && cachedSlug === slug && cachedTokens === tokens) {
108
122
  return cachedClient;
109
123
  }
110
124
 
@@ -121,6 +135,7 @@ export function getQueekClient(vendorSlug?: string): QueekClientInstance {
121
135
  },
122
136
  });
123
137
  cachedSlug = slug;
138
+ cachedTokens = tokens;
124
139
 
125
140
  return cachedClient;
126
141
  }
@@ -155,4 +170,5 @@ export function setAuthTokens(accessToken: string, refreshToken: string): void {
155
170
  // Reset cache so the next getQueekClient() reads the new tokens from localStorage.
156
171
  cachedClient = null;
157
172
  cachedSlug = null;
173
+ cachedTokens = null;
158
174
  }