@01.software/sdk 0.2.3 → 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 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
@@ -1,5 +1,5 @@
1
1
  import { Sort, Where } from 'payload';
2
- import './payload-types-COjt2QTn.cjs';
2
+ import './payload-types-BFIUYPDZ.cjs';
3
3
 
4
4
  declare class SDKError extends Error {
5
5
  readonly code: string;
@@ -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 */
@@ -1,5 +1,5 @@
1
1
  import { Sort, Where } from 'payload';
2
- import './payload-types-COjt2QTn.js';
2
+ import './payload-types-BFIUYPDZ.js';
3
3
 
4
4
  declare class SDKError extends Error {
5
5
  readonly code: string;
@@ -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-C7hwnGOb.cjs';
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
- import './payload-types-COjt2QTn.cjs';
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-C-9PVtsp.js';
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
- import './payload-types-COjt2QTn.js';
3
+ import './payload-types-BFIUYPDZ.js';
@@ -2,7 +2,7 @@ import React, { CSSProperties } from 'react';
2
2
  import { SerializedLinkNode, SerializedBlockNode } from '@payloadcms/richtext-lexical';
3
3
  import { SerializedEditorState, SerializedLexicalNode } from '@payloadcms/richtext-lexical/lexical';
4
4
  import { JSXConverter } from '@payloadcms/richtext-lexical/react';
5
- import { F as Form } from './payload-types-COjt2QTn.cjs';
5
+ import { F as Form } from './payload-types-BFIUYPDZ.cjs';
6
6
  import { I as ImageData } from './image-TT8lTsk5.cjs';
7
7
 
8
8
  type RichTextData = SerializedEditorState<SerializedLexicalNode>;
@@ -2,7 +2,7 @@ import React, { CSSProperties } from 'react';
2
2
  import { SerializedLinkNode, SerializedBlockNode } from '@payloadcms/richtext-lexical';
3
3
  import { SerializedEditorState, SerializedLexicalNode } from '@payloadcms/richtext-lexical/lexical';
4
4
  import { JSXConverter } from '@payloadcms/richtext-lexical/react';
5
- import { F as Form } from './payload-types-COjt2QTn.js';
5
+ import { F as Form } from './payload-types-BFIUYPDZ.js';
6
6
  import { I as ImageData } from './image-TT8lTsk5.js';
7
7
 
8
8
  type RichTextData = SerializedEditorState<SerializedLexicalNode>;
package/dist/index.cjs CHANGED
@@ -701,7 +701,8 @@ var ProductApi = class {
701
701
 
702
702
  // src/utils/types.ts
703
703
  var resolveRelation = (ref) => {
704
- if (typeof ref === "number" || ref === null || ref === void 0) return null;
704
+ if (typeof ref === "string" || typeof ref === "number" || ref === null || ref === void 0)
705
+ return null;
705
706
  return ref;
706
707
  };
707
708
  var objectFor = resolveRelation;
@@ -1146,11 +1147,21 @@ var COLLECTIONS = [
1146
1147
  var DEFAULT_TIMEOUT2 = 15e3;
1147
1148
  var CustomerAuth = class {
1148
1149
  constructor(clientKey, baseUrl, options) {
1149
- var _a;
1150
+ var _a, _b;
1150
1151
  this.clientKey = clientKey;
1151
1152
  this.baseUrl = baseUrl;
1152
- this.token = (_a = options == null ? void 0 : options.token) != null ? _a : null;
1153
- this.onTokenChange = options == null ? void 0 : options.onTokenChange;
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
+ }
1154
1165
  }
1155
1166
  /**
1156
1167
  * Register a new customer account
@@ -1329,7 +1340,11 @@ var CustomerAuth = class {
1329
1340
  body.error
1330
1341
  );
1331
1342
  }
1332
- return res.json();
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
+ }
1333
1348
  });
1334
1349
  }
1335
1350
  };
@@ -1340,7 +1355,9 @@ function makeQueryClient() {
1340
1355
  return new import_react_query.QueryClient({
1341
1356
  defaultOptions: {
1342
1357
  queries: {
1343
- // SSR/RSC: server-fetched data doesn't auto-refetch; use refetch()/invalidate() to refresh
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 })
1344
1361
  staleTime: Number.POSITIVE_INFINITY,
1345
1362
  refetchOnWindowFocus: false
1346
1363
  },