@01.software/sdk 0.2.4 → 0.2.5
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/README.md +1 -3
- package/dist/{auth-DTkwMgvi.d.cts → auth-CP8gKMvj.d.cts} +9 -0
- package/dist/{auth-CWsLf5vd.d.ts → auth-j2yUrezU.d.ts} +9 -0
- package/dist/auth.d.cts +1 -1
- package/dist/auth.d.ts +1 -1
- package/dist/index.cjs +21 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +24 -15
- package/dist/index.d.ts +24 -15
- package/dist/index.js +21 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -266,9 +266,7 @@ Available on BrowserClient via `client.customer.*`.
|
|
|
266
266
|
```typescript
|
|
267
267
|
const client = createBrowserClient({
|
|
268
268
|
clientKey: process.env.NEXT_PUBLIC_SOFTWARE_CLIENT_KEY,
|
|
269
|
-
customer: {
|
|
270
|
-
onTokenChange: (token) => localStorage.setItem('customer-token', token ?? ''),
|
|
271
|
-
},
|
|
269
|
+
customer: { persist: true },
|
|
272
270
|
})
|
|
273
271
|
|
|
274
272
|
// Register & login
|
|
@@ -101,6 +101,15 @@ interface ClientBrowserConfig {
|
|
|
101
101
|
* Used to initialize CustomerAuth on BrowserClient.
|
|
102
102
|
*/
|
|
103
103
|
customer?: {
|
|
104
|
+
/**
|
|
105
|
+
* Automatically persist token in localStorage.
|
|
106
|
+
* - `true`: uses default key `'customer-token'`
|
|
107
|
+
* - `string`: uses the given string as localStorage key
|
|
108
|
+
*
|
|
109
|
+
* Handles SSR safely (no-op on server).
|
|
110
|
+
* When set, `token` and `onTokenChange` are ignored.
|
|
111
|
+
*/
|
|
112
|
+
persist?: boolean | string;
|
|
104
113
|
/** Initial token (e.g. from SSR cookie) */
|
|
105
114
|
token?: string;
|
|
106
115
|
/** Called when token changes (login/logout) — use to persist in localStorage/cookie */
|
|
@@ -101,6 +101,15 @@ interface ClientBrowserConfig {
|
|
|
101
101
|
* Used to initialize CustomerAuth on BrowserClient.
|
|
102
102
|
*/
|
|
103
103
|
customer?: {
|
|
104
|
+
/**
|
|
105
|
+
* Automatically persist token in localStorage.
|
|
106
|
+
* - `true`: uses default key `'customer-token'`
|
|
107
|
+
* - `string`: uses the given string as localStorage key
|
|
108
|
+
*
|
|
109
|
+
* Handles SSR safely (no-op on server).
|
|
110
|
+
* When set, `token` and `onTokenChange` are ignored.
|
|
111
|
+
*/
|
|
112
|
+
persist?: boolean | string;
|
|
104
113
|
/** Initial token (e.g. from SSR cookie) */
|
|
105
114
|
token?: string;
|
|
106
115
|
/** Called when token changes (login/logout) — use to persist in localStorage/cookie */
|
package/dist/auth.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { J as JwtPayload, q as createApiKey, o as createServerToken, p as decodeServerToken, r as parseApiKey, v as verifyServerToken } from './auth-
|
|
1
|
+
export { J as JwtPayload, q as createApiKey, o as createServerToken, p as decodeServerToken, r as parseApiKey, v as verifyServerToken } from './auth-CP8gKMvj.cjs';
|
|
2
2
|
import 'payload';
|
|
3
3
|
import './payload-types-BFIUYPDZ.cjs';
|
package/dist/auth.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { J as JwtPayload, q as createApiKey, o as createServerToken, p as decodeServerToken, r as parseApiKey, v as verifyServerToken } from './auth-
|
|
1
|
+
export { J as JwtPayload, q as createApiKey, o as createServerToken, p as decodeServerToken, r as parseApiKey, v as verifyServerToken } from './auth-j2yUrezU.js';
|
|
2
2
|
import 'payload';
|
|
3
3
|
import './payload-types-BFIUYPDZ.js';
|
package/dist/index.cjs
CHANGED
|
@@ -1147,11 +1147,21 @@ var COLLECTIONS = [
|
|
|
1147
1147
|
var DEFAULT_TIMEOUT2 = 15e3;
|
|
1148
1148
|
var CustomerAuth = class {
|
|
1149
1149
|
constructor(clientKey, baseUrl, options) {
|
|
1150
|
-
var _a;
|
|
1150
|
+
var _a, _b;
|
|
1151
1151
|
this.clientKey = clientKey;
|
|
1152
1152
|
this.baseUrl = baseUrl;
|
|
1153
|
-
|
|
1154
|
-
|
|
1153
|
+
if (options == null ? void 0 : options.persist) {
|
|
1154
|
+
const key = typeof options.persist === "string" ? options.persist : "customer-token";
|
|
1155
|
+
const isBrowser = typeof window !== "undefined";
|
|
1156
|
+
this.token = isBrowser ? (_a = localStorage.getItem(key)) != null ? _a : null : null;
|
|
1157
|
+
this.onTokenChange = isBrowser ? (token) => {
|
|
1158
|
+
if (token) localStorage.setItem(key, token);
|
|
1159
|
+
else localStorage.removeItem(key);
|
|
1160
|
+
} : void 0;
|
|
1161
|
+
} else {
|
|
1162
|
+
this.token = (_b = options == null ? void 0 : options.token) != null ? _b : null;
|
|
1163
|
+
this.onTokenChange = options == null ? void 0 : options.onTokenChange;
|
|
1164
|
+
}
|
|
1155
1165
|
}
|
|
1156
1166
|
/**
|
|
1157
1167
|
* Register a new customer account
|
|
@@ -1330,7 +1340,11 @@ var CustomerAuth = class {
|
|
|
1330
1340
|
body.error
|
|
1331
1341
|
);
|
|
1332
1342
|
}
|
|
1333
|
-
|
|
1343
|
+
try {
|
|
1344
|
+
return yield res.json();
|
|
1345
|
+
} catch (e) {
|
|
1346
|
+
throw new ApiError("Invalid JSON response from server", res.status, void 0, "INVALID_RESPONSE");
|
|
1347
|
+
}
|
|
1334
1348
|
});
|
|
1335
1349
|
}
|
|
1336
1350
|
};
|
|
@@ -1341,7 +1355,9 @@ function makeQueryClient() {
|
|
|
1341
1355
|
return new import_react_query.QueryClient({
|
|
1342
1356
|
defaultOptions: {
|
|
1343
1357
|
queries: {
|
|
1344
|
-
//
|
|
1358
|
+
// Infinite staleTime: server-fetched data persists until explicitly invalidated.
|
|
1359
|
+
// For browser clients needing fresher data, override per-query:
|
|
1360
|
+
// useQuery({ ..., staleTime: 5 * 60 * 1000 })
|
|
1345
1361
|
staleTime: Number.POSITIVE_INFINITY,
|
|
1346
1362
|
refetchOnWindowFocus: false
|
|
1347
1363
|
},
|