@classytic/arc-next 0.7.0 → 0.7.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/dist/client.js CHANGED
@@ -585,16 +585,48 @@ function createClient(config) {
585
585
  * });
586
586
  */
587
587
  function createAuthAwareClient(overrides = {}) {
588
- return createClient({
589
- baseUrl: overrides.baseUrl ?? getBaseUrl(),
590
- authMode: overrides.authMode ?? getAuthMode(),
591
- autoIdempotency: overrides.autoIdempotency ?? isAutoIdempotency(),
592
- elevated: overrides.elevated ?? clientConfig?.elevated,
593
- ...overrides,
594
- getToken: overrides.getToken ?? (() => readToken(authConfig?.getToken)),
595
- getOrgId: overrides.getOrgId ?? (() => authConfig?.getOrgId?.() ?? null),
596
- headerName: overrides.headerName ?? authConfig?.headerName
588
+ const { toast, navigation, getToken, getOrgId, headerName, ...overrideCfg } = overrides;
589
+ const authGetToken = getToken ?? (() => readToken(authConfig?.getToken));
590
+ const authGetOrgId = getOrgId ?? (() => authConfig?.getOrgId?.() ?? null);
591
+ const authHeaderName = headerName ?? authConfig?.headerName;
592
+ const clientAuth = {
593
+ getToken: authGetToken,
594
+ getOrgId: authGetOrgId,
595
+ headerName: authHeaderName
596
+ };
597
+ const resolveClientCfg = () => ({
598
+ baseUrl: overrideCfg.baseUrl ?? getBaseUrl(),
599
+ authMode: overrideCfg.authMode ?? getAuthMode(),
600
+ autoIdempotency: overrideCfg.autoIdempotency ?? isAutoIdempotency(),
601
+ elevated: overrideCfg.elevated ?? clientConfig?.elevated,
602
+ internalApiKey: overrideCfg.internalApiKey ?? clientConfig?.internalApiKey,
603
+ defaultHeaders: overrideCfg.defaultHeaders ?? clientConfig?.defaultHeaders,
604
+ credentials: overrideCfg.credentials ?? clientConfig?.credentials,
605
+ apiVersion: overrideCfg.apiVersion ?? clientConfig?.apiVersion,
606
+ retry: overrideCfg.retry ?? clientConfig?.retry,
607
+ beforeRequest: overrideCfg.beforeRequest ?? clientConfig?.beforeRequest,
608
+ afterResponse: overrideCfg.afterResponse ?? clientConfig?.afterResponse
597
609
  });
610
+ return {
611
+ request: (method, endpoint, options) => {
612
+ const cfg = resolveClientCfg();
613
+ const resolved = { ...options };
614
+ if (resolved.token === void 0) resolved.token = readToken(authGetToken);
615
+ if (resolved.organizationId === void 0) resolved.organizationId = authGetOrgId();
616
+ if (cfg.authMode === "header" && resolved.token) {
617
+ resolved.headerOptions = {
618
+ [authHeaderName ?? "x-api-key"]: resolved.token,
619
+ ...resolved.headerOptions ?? {}
620
+ };
621
+ resolved.token = void 0;
622
+ }
623
+ return executeRequest(cfg, method, endpoint, resolved);
624
+ },
625
+ config: resolveClientCfg(),
626
+ toast,
627
+ navigation,
628
+ auth: clientAuth
629
+ };
598
630
  }
599
631
  /**
600
632
  * Get auth context for a specific client instance, falling back to global.
@@ -759,6 +791,7 @@ async function executeAttempt(config, method, endpoint, options, attempt) {
759
791
  ...fetchOptions.next,
760
792
  tags
761
793
  };
794
+ if (!/^https?:\/\//i.test(endpoint) && !config.baseUrl) throw new Error(`[arc-next] handleApiRequest(${method} ${endpoint}): baseUrl is empty. Call configureClient({ baseUrl: '...' }) BEFORE the first request. If you use createAuthAwareClient() at module top-level, make sure the Providers component runs configureClient() first (e.g. in a useState() initializer, before the children render).`);
762
795
  const response = await fetch(`${config.baseUrl}${endpoint}`, fetchOptions);
763
796
  if (!response.ok) {
764
797
  let json = null;
package/dist/query.d.ts CHANGED
@@ -57,8 +57,28 @@ interface DetailQueryOptions<TData = unknown> {
57
57
  /** Pass-through options for the underlying fetch request (cache, revalidate, tags, headers) */
58
58
  request?: RequestPassthrough;
59
59
  }
60
+ /**
61
+ * Result of `useList` (and `useListQuery`). Matches the same typed-end-to-end
62
+ * shape `repo-core` uses for its server-side result interfaces (`AggResult`,
63
+ * `OffsetPaginationResult`, etc.) — no raw-cache escape hatch on the public
64
+ * surface, just the typed extracted view.
65
+ *
66
+ * Need the raw cache entry? Use `useQueryClient().getQueryData(KEYS.list(...))`
67
+ * — it's typed against whatever `setQueryData` last wrote, and it makes the
68
+ * "I'm reaching past the SDK" intent explicit.
69
+ */
60
70
  interface ListQueryResult<T> {
71
+ /**
72
+ * Extracted items array — `T[]`. Always typed, always flat (infinite-list
73
+ * pages are pre-flattened), always consistent across response-shape
74
+ * variants (`data` / `items` / `results` / any-array fallback).
75
+ */
61
76
  items: T[];
77
+ /**
78
+ * Normalized pagination snapshot — offset / keyset / aggregate all map
79
+ * onto the same `{ method, total, pages, page, limit, hasNext, hasPrev, next? }`
80
+ * shape. `null` when the response carries no pagination signal.
81
+ */
62
82
  pagination: PaginationData | null;
63
83
  isLoading: boolean;
64
84
  isFetching: boolean;
@@ -67,9 +87,22 @@ interface ListQueryResult<T> {
67
87
  isStale: boolean;
68
88
  error: Error | null;
69
89
  refetch: () => Promise<unknown>;
70
- data: unknown;
71
90
  }
91
+ /**
92
+ * Result of `useDetail` (and `useDetailQuery`). Matches the typed-end-to-end
93
+ * shape repo-core uses for its result interfaces — no raw-cache escape
94
+ * hatch on the public surface, just the typed extracted view.
95
+ *
96
+ * Need the raw cache entry? `useQueryClient().getQueryData(KEYS.detail(id))`
97
+ * — typed against whatever `setQueryData` last wrote, and the explicit
98
+ * `getQueryData` call signals "I'm reaching past the SDK" at the call site.
99
+ */
72
100
  interface DetailQueryResult<T> {
101
+ /**
102
+ * The extracted entity — `T | null`. Always typed, always the raw doc
103
+ * (not a wrapper), always consistent with what `prefetchDetail` /
104
+ * `cache.getDetail` / `useNavigation` write back.
105
+ */
73
106
  item: T | null;
74
107
  isLoading: boolean;
75
108
  isFetching: boolean;
@@ -85,7 +118,6 @@ interface DetailQueryResult<T> {
85
118
  isPlaceholderData: boolean;
86
119
  error: Error | null;
87
120
  refetch: () => Promise<unknown>;
88
- data: unknown;
89
121
  }
90
122
  interface CreateListQueryConfig {
91
123
  queryKey: QueryKey;
package/dist/query.js CHANGED
@@ -39,8 +39,7 @@ function useListQuery({ queryKey, queryFn, enabled = true, options = {}, select
39
39
  isSuccess: query.isSuccess,
40
40
  isStale: query.isStale,
41
41
  error: query.error,
42
- refetch: query.refetch,
43
- data: query.data
42
+ refetch: query.refetch
44
43
  };
45
44
  }
46
45
  /**
@@ -97,8 +96,7 @@ function useDetailQuery({ queryKey, queryFn, enabled = true, options = {}, selec
97
96
  isStale: query.isStale,
98
97
  isPlaceholderData: query.isPlaceholderData,
99
98
  error: query.error,
100
- refetch: query.refetch,
101
- data: query.data
99
+ refetch: query.refetch
102
100
  };
103
101
  }
104
102
  function useInfiniteListQuery({ queryKey, queryFn, enabled = true, options = {}, initialPageParam = 1, getNextPageParam, getPreviousPageParam, maxPages }) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@classytic/arc-next",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "description": "React + TanStack Query SDK for Arc resources",
5
5
  "type": "module",
6
6
  "sideEffects": false,