@simpleapps-com/augur-server 2.3.1 → 2026.11.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.
Files changed (140) hide show
  1. package/EXPORTS.md +29 -72
  2. package/README.md +29 -198
  3. package/dist/actions/agr-info.d.ts +43 -0
  4. package/dist/actions/agr-info.d.ts.map +1 -0
  5. package/dist/actions/agr-site.d.ts +37 -0
  6. package/dist/actions/agr-site.d.ts.map +1 -0
  7. package/dist/actions/agr-work.d.ts +29 -0
  8. package/dist/actions/agr-work.d.ts.map +1 -0
  9. package/dist/actions/avalara.d.ts +38 -0
  10. package/dist/actions/avalara.d.ts.map +1 -0
  11. package/dist/actions/basecamp2.d.ts +47 -0
  12. package/dist/actions/basecamp2.d.ts.map +1 -0
  13. package/dist/actions/brand-folder.d.ts +38 -0
  14. package/dist/actions/brand-folder.d.ts.map +1 -0
  15. package/dist/actions/commerce.d.ts +58 -0
  16. package/dist/actions/commerce.d.ts.map +1 -0
  17. package/dist/actions/customers.d.ts +44 -0
  18. package/dist/actions/customers.d.ts.map +1 -0
  19. package/dist/actions/favorites.d.ts +20 -0
  20. package/dist/actions/favorites.d.ts.map +1 -0
  21. package/dist/actions/gregorovich.d.ts +34 -0
  22. package/dist/actions/gregorovich.d.ts.map +1 -0
  23. package/dist/actions/items.d.ts +80 -0
  24. package/dist/actions/items.d.ts.map +1 -0
  25. package/dist/actions/joomla.d.ts +59 -0
  26. package/dist/actions/joomla.d.ts.map +1 -0
  27. package/dist/actions/legacy.d.ts +45 -0
  28. package/dist/actions/legacy.d.ts.map +1 -0
  29. package/dist/actions/logistics.d.ts +40 -0
  30. package/dist/actions/logistics.d.ts.map +1 -0
  31. package/dist/actions/orders.d.ts +36 -0
  32. package/dist/actions/orders.d.ts.map +1 -0
  33. package/dist/actions/p21-apis.d.ts +33 -0
  34. package/dist/actions/p21-apis.d.ts.map +1 -0
  35. package/dist/actions/p21-core.d.ts +46 -0
  36. package/dist/actions/p21-core.d.ts.map +1 -0
  37. package/dist/actions/p21-pim.d.ts +36 -0
  38. package/dist/actions/p21-pim.d.ts.map +1 -0
  39. package/dist/actions/p21-sism.d.ts +37 -0
  40. package/dist/actions/p21-sism.d.ts.map +1 -0
  41. package/dist/actions/payments.d.ts +39 -0
  42. package/dist/actions/payments.d.ts.map +1 -0
  43. package/dist/actions/pricing.d.ts +45 -0
  44. package/dist/actions/pricing.d.ts.map +1 -0
  45. package/dist/actions/search.d.ts +61 -0
  46. package/dist/actions/search.d.ts.map +1 -0
  47. package/dist/actions/shipping.d.ts +56 -0
  48. package/dist/actions/shipping.d.ts.map +1 -0
  49. package/dist/actions/site.d.ts +141 -0
  50. package/dist/actions/site.d.ts.map +1 -0
  51. package/dist/actions/smarty-streets.d.ts +45 -0
  52. package/dist/actions/smarty-streets.d.ts.map +1 -0
  53. package/dist/actions/vmi.d.ts +44 -0
  54. package/dist/actions/vmi.d.ts.map +1 -0
  55. package/dist/actions/wishlists.d.ts +28 -0
  56. package/dist/actions/wishlists.d.ts.map +1 -0
  57. package/dist/api-handler.d.ts +25 -0
  58. package/dist/api-handler.d.ts.map +1 -0
  59. package/dist/api.d.ts +2 -26
  60. package/dist/api.d.ts.map +1 -0
  61. package/dist/api.js +19 -14
  62. package/dist/api.js.map +1 -1
  63. package/dist/auth.d.ts +10 -12
  64. package/dist/auth.d.ts.map +1 -0
  65. package/dist/auth.js +2 -2
  66. package/dist/cache/redis-client.d.ts +16 -0
  67. package/dist/cache/redis-client.d.ts.map +1 -0
  68. package/dist/cache/with-cache.d.ts +18 -0
  69. package/dist/cache/with-cache.d.ts.map +1 -0
  70. package/dist/chunk-FWO6Q43T.js +162 -0
  71. package/dist/chunk-FWO6Q43T.js.map +1 -0
  72. package/dist/{chunk-HPQQYROJ.js → chunk-NTUPTNOI.js} +40 -7
  73. package/dist/chunk-NTUPTNOI.js.map +1 -0
  74. package/dist/{chunk-WOHZDFJF.js → chunk-PFYEMJTQ.js} +212 -642
  75. package/dist/chunk-PFYEMJTQ.js.map +1 -0
  76. package/dist/{chunk-KHFEDL47.js → chunk-SXXWBSTX.js} +18 -12
  77. package/dist/chunk-SXXWBSTX.js.map +1 -0
  78. package/dist/chunk-TVH5EONP.js +178 -0
  79. package/dist/chunk-TVH5EONP.js.map +1 -0
  80. package/dist/{chunk-TQP67TGL.js → chunk-U2BKHRJC.js} +13 -15
  81. package/dist/chunk-U2BKHRJC.js.map +1 -0
  82. package/dist/environment.d.ts +10 -0
  83. package/dist/environment.d.ts.map +1 -0
  84. package/dist/hooks.d.ts +8 -10
  85. package/dist/hooks.d.ts.map +1 -0
  86. package/dist/hooks.js +3 -3
  87. package/dist/hooks.js.map +1 -1
  88. package/dist/index.d.ts +16 -125
  89. package/dist/index.d.ts.map +1 -0
  90. package/dist/index.js +12 -8
  91. package/dist/index.js.map +1 -1
  92. package/dist/pagination.d.ts +32 -0
  93. package/dist/pagination.d.ts.map +1 -0
  94. package/dist/query-action.d.ts +156 -17
  95. package/dist/query-action.d.ts.map +1 -0
  96. package/dist/query-action.js +3 -3
  97. package/dist/query-options-helper.d.ts +33 -0
  98. package/dist/query-options-helper.d.ts.map +1 -0
  99. package/dist/query.js +1 -2
  100. package/dist/recaptcha.d.ts +6 -0
  101. package/dist/recaptcha.d.ts.map +1 -0
  102. package/dist/rules.d.ts +221 -0
  103. package/dist/rules.d.ts.map +1 -0
  104. package/dist/scoped-client-key.d.ts +9 -0
  105. package/dist/scoped-client-key.d.ts.map +1 -0
  106. package/dist/sdk-call.d.ts +66 -0
  107. package/dist/sdk-call.d.ts.map +1 -0
  108. package/dist/sdk-client-store.d.ts +250 -0
  109. package/dist/sdk-client-store.d.ts.map +1 -0
  110. package/dist/server-actions.d.ts +2 -0
  111. package/dist/server-actions.d.ts.map +1 -0
  112. package/dist/server-query-client.d.ts +19 -0
  113. package/dist/server-query-client.d.ts.map +1 -0
  114. package/dist/{server-site-registry-CdBfczOj.d.ts → server-site-registry.d.ts} +7 -9
  115. package/dist/server-site-registry.d.ts.map +1 -0
  116. package/dist/{site.d.ts → server-site.d.ts} +11 -16
  117. package/dist/server-site.d.ts.map +1 -0
  118. package/dist/site-actions-store.d.ts +27 -0
  119. package/dist/site-actions-store.d.ts.map +1 -0
  120. package/dist/site.js +10 -10
  121. package/dist/site.js.map +1 -1
  122. package/dist/testing.d.ts +9 -12
  123. package/dist/testing.d.ts.map +1 -0
  124. package/dist/testing.js +7 -27
  125. package/dist/testing.js.map +1 -1
  126. package/dist/utils/batch-fetch.d.ts +7 -0
  127. package/dist/utils/batch-fetch.d.ts.map +1 -0
  128. package/llms.txt +71 -50
  129. package/package.json +34 -20
  130. package/dist/actions.d.ts +0 -2
  131. package/dist/chunk-DGUM43GV.js +0 -11
  132. package/dist/chunk-DGUM43GV.js.map +0 -1
  133. package/dist/chunk-HPQQYROJ.js.map +0 -1
  134. package/dist/chunk-KHFEDL47.js.map +0 -1
  135. package/dist/chunk-TQP67TGL.js.map +0 -1
  136. package/dist/chunk-WOHZDFJF.js.map +0 -1
  137. package/dist/chunk-ZUJZDRTP.js +0 -136
  138. package/dist/chunk-ZUJZDRTP.js.map +0 -1
  139. package/dist/query.d.ts +0 -31
  140. package/dist/site-BjSFqufX.d.ts +0 -469
@@ -0,0 +1,66 @@
1
+ export type { EdgeCacheValue, ActionResult, ApiResult, ListResult, } from "@simpleapps-com/augur-core";
2
+ import type { ApiResult, ListResult } from "@simpleapps-com/augur-core";
3
+ /**
4
+ * Calls an Augur SDK method, forwarding all arguments with full type safety.
5
+ *
6
+ * With augur-api >= 0.9.6, SDK methods properly declare their `CacheParams`
7
+ * option (including `edgeCache`), so this wrapper preserves both parameter
8
+ * and return-type inference end-to-end.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * const result = await sdkCall(
13
+ * augurServices.items.invMast.get,
14
+ * invMastUid,
15
+ * { edgeCache: 4 },
16
+ * );
17
+ * ```
18
+ */
19
+ export declare function sdkCall<TArgs extends unknown[], TResult>(method: (...args: TArgs) => Promise<TResult>, ...args: TArgs): Promise<TResult>;
20
+ /** The SDK response envelope fields the result helpers read. */
21
+ interface SdkEnvelope {
22
+ data?: unknown;
23
+ total?: number;
24
+ count?: number;
25
+ totalResults?: number;
26
+ message?: string;
27
+ status?: number;
28
+ }
29
+ /**
30
+ * Extracts an ApiResult from an SDK response, preserving envelope metadata.
31
+ * Use this for single-item endpoints where `data` is a single object.
32
+ */
33
+ export declare function toApiResult<T>(response: SdkEnvelope): ApiResult<T>;
34
+ /**
35
+ * Extracts a ListResult from an SDK response, preserving envelope metadata.
36
+ * Use this for list endpoints where `data` is an array.
37
+ */
38
+ export declare function toListResult<T>(response: SdkEnvelope): ListResult<T>;
39
+ export { unwrap, unwrapOr } from "@simpleapps-com/augur-utils";
40
+ export type { SafeActionResult } from "@simpleapps-com/augur-utils";
41
+ import type { SafeActionResult } from "@simpleapps-com/augur-utils";
42
+ /**
43
+ * Wraps an async function call with error handling, returning a
44
+ * `SafeActionResult<T>` instead of throwing.
45
+ *
46
+ * Use this to eliminate try/catch boilerplate in server actions.
47
+ * Reads that go through React Query should NOT use this — let errors
48
+ * propagate so React Query can handle retries and error state.
49
+ *
50
+ * @param fn — The async function to execute
51
+ * @param onError — Optional callback for logging/reporting
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * const result = await safeAction(
56
+ * () => actions.commerce.addToCart(cartId, items),
57
+ * );
58
+ * if (result.ok) {
59
+ * // result.data is the response data (undefined for void actions)
60
+ * } else {
61
+ * // result.error is the error message
62
+ * }
63
+ * ```
64
+ */
65
+ export declare function safeAction<T>(fn: () => Promise<T>, onError?: (error: Error) => void): Promise<SafeActionResult<T>>;
66
+ //# sourceMappingURL=sdk-call.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sdk-call.d.ts","sourceRoot":"","sources":["../src/sdk-call.ts"],"names":[],"mappings":"AACA,YAAY,EACV,cAAc,EACd,YAAY,EACZ,SAAS,EACT,UAAU,GACX,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAExE;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,OAAO,CAAC,KAAK,SAAS,OAAO,EAAE,EAAE,OAAO,EAC5D,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,CAAC,OAAO,CAAC,EAC5C,GAAG,IAAI,EAAE,KAAK,GACb,OAAO,CAAC,OAAO,CAAC,CAElB;AAED,gEAAgE;AAChE,UAAU,WAAW;IACnB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,QAAQ,EAAE,WAAW,GAAG,SAAS,CAAC,CAAC,CAAC,CASlE;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,QAAQ,EAAE,WAAW,GAAG,UAAU,CAAC,CAAC,CAAC,CASpE;AAGD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAC/D,YAAY,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAEpE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAEpE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,UAAU,CAAC,CAAC,EAChC,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,GAC/B,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAS9B"}
@@ -0,0 +1,250 @@
1
+ /**
2
+ * Lightweight getter/setter for the raw SDK client instance, cache wrapper,
3
+ * auth secret, client factory, and scoped client cache.
4
+ *
5
+ * queryAction resolves method paths on the SDK client directly (not on
6
+ * SiteActions). This ensures the proxy pattern works end-to-end: the
7
+ * proxy generates SDK namespace paths (e.g. "pricing.priceEngine.get")
8
+ * which match the SDK client structure.
9
+ *
10
+ * The cache wrapper is a function registered by createServerSite() that
11
+ * wraps SDK calls with Redis caching. It captures withServerCache + config
12
+ * in its closure, so queryAction can use it without importing heavy deps.
13
+ *
14
+ * The auth secret, client factory, and scoped cache wrapper support
15
+ * per-request session credentials for multi-tenant apps. queryAction
16
+ * decodes the JWT from request cookies and creates scoped SDK clients
17
+ * when the session contains a targetSiteId + token.
18
+ *
19
+ * This module has ZERO imports from actions/site, cache/, or any factory.
20
+ * Same isolation constraints as site-actions-store.ts.
21
+ */
22
+ /** Function that wraps an SDK call with server-side caching. */
23
+ export type SdkCallWrapper = (methodPath: string, sdkCall: () => Promise<unknown>, ...keyArgs: unknown[]) => Promise<unknown>;
24
+ /** Function that wraps an SDK call with server-side caching using a specific prefix. */
25
+ export type ScopedCacheWrapper = (prefix: string, methodPath: string, sdkCall: () => Promise<unknown>, ...keyArgs: unknown[]) => Promise<unknown>;
26
+ /** Function that creates a scoped SDK client with different credentials. */
27
+ export type ClientFactory = (siteId: string, bearerToken: string) => unknown;
28
+ declare const SessionSiteIdBrand: unique symbol;
29
+ declare const SessionBearerTokenBrand: unique symbol;
30
+ declare const SessionCredentialsBrand: unique symbol;
31
+ declare const ApprovedMethodPathBrand: unique symbol;
32
+ /**
33
+ * Site identifier extracted from a validated Auth.js session JWT cookie.
34
+ *
35
+ * Intended to be minted only by `getSessionCredentials` in query-action.ts.
36
+ *
37
+ * Brand strength: code-review signal, not type-system enforcement. TypeScript
38
+ * allows `value as SessionSiteId` casts, so audit `as SessionSiteId` usages
39
+ * to catch unintended mints — there should be exactly one, at the JWT mint
40
+ * point.
41
+ */
42
+ export type SessionSiteId = string & {
43
+ readonly [SessionSiteIdBrand]: true;
44
+ };
45
+ /**
46
+ * Bearer token extracted from a validated Auth.js session JWT cookie.
47
+ * Same intended-mint and brand-strength caveat as {@link SessionSiteId}.
48
+ */
49
+ export type SessionBearerToken = string & {
50
+ readonly [SessionBearerTokenBrand]: true;
51
+ };
52
+ /**
53
+ * Paired session credentials. Bundles `siteId` and `token` from the same
54
+ * validated session into one value so downstream functions can accept the
55
+ * pair as a unit, instead of two separate parameters that callers might
56
+ * accidentally mix across sessions.
57
+ *
58
+ * Intended to be minted only by `getSessionCredentials` in query-action.ts,
59
+ * which performs the cross-check that the bearer's `client_id` siteId
60
+ * matches `targetSiteId`. Anything that holds a `SessionCredentials` *was*
61
+ * cross-checked at mint time — provided the value came through that mint
62
+ * and not via a cast.
63
+ *
64
+ * Brand strength: same code-review signal as the field brands. `value as
65
+ * SessionCredentials` compiles. Audit `as SessionCredentials` usages — there
66
+ * should be exactly one, in `getSessionCredentials`.
67
+ */
68
+ export type SessionCredentials = {
69
+ readonly siteId: SessionSiteId;
70
+ readonly token: SessionBearerToken;
71
+ readonly [SessionCredentialsBrand]: true;
72
+ };
73
+ /**
74
+ * SDK method path validated against the registered allowlist.
75
+ *
76
+ * Intended to be minted only by `parseMethodPath` below. Functions that walk
77
+ * the path into the SDK client (notably `resolveMethod`) demand this type
78
+ * so that an unvalidated string flowing into the walker is a compile error
79
+ * for code that respects the convention.
80
+ *
81
+ * Brand strength: code-review signal. `value as ApprovedMethodPath` compiles.
82
+ * Audit `as ApprovedMethodPath` usages — there should be one, in
83
+ * `parseMethodPath`.
84
+ *
85
+ * Scope of validation: this is a *site-level surface restriction*, not a
86
+ * security boundary. augur-api is the auth authority; the allowlist limits
87
+ * what the application's proxy will forward to the SDK, not what tokens are
88
+ * permitted to do. Useful for narrowing same-origin attack surface (XSS,
89
+ * malicious bundled deps); not a substitute for API-level authorization.
90
+ */
91
+ export type ApprovedMethodPath = string & {
92
+ readonly [ApprovedMethodPathBrand]: true;
93
+ };
94
+ /** Register the raw SDK client instance. Called by createServerSite(). */
95
+ export declare function registerSdkClient(client: unknown): void;
96
+ /** Returns the registered SDK client, or null if not yet registered. */
97
+ export declare function getSdkClientOrNull(): unknown;
98
+ /**
99
+ * Register a cache wrapper for SDK calls. Called by createServerSite().
100
+ * The wrapper captures withServerCache + config in its closure so that
101
+ * queryAction can use Redis caching without importing heavy deps.
102
+ */
103
+ export declare function registerSdkCallWrapper(wrapper: SdkCallWrapper): void;
104
+ /** Returns the registered cache wrapper, or null if not registered. */
105
+ export declare function getSdkCallWrapper(): SdkCallWrapper | null;
106
+ /** Register the auth secret for JWT decoding. Called by createServerSite(). */
107
+ export declare function registerAuthSecret(secret: string): void;
108
+ /** Returns the registered auth secret, or null if not registered. */
109
+ export declare function getAuthSecret(): string | null;
110
+ /** Register a factory that creates scoped SDK clients. Called by createServerSite(). */
111
+ export declare function registerClientFactory(factory: ClientFactory): void;
112
+ /** Returns the registered client factory, or null if not registered. */
113
+ export declare function getClientFactory(): ClientFactory | null;
114
+ /** Register a scoped cache wrapper that accepts a prefix. Called by createServerSite(). */
115
+ export declare function registerScopedCacheWrapper(wrapper: ScopedCacheWrapper): void;
116
+ /** Returns the registered scoped cache wrapper, or null if not registered. */
117
+ export declare function getScopedCacheWrapper(): ScopedCacheWrapper | null;
118
+ /**
119
+ * Returns a cached scoped client for the given credentials, or creates one
120
+ * via the registered factory. Caches the last credential pair so that
121
+ * multiple queryAction calls in the same request reuse the same client.
122
+ *
123
+ * Accepts `SessionCredentials` (a branded paired type) rather than two raw
124
+ * strings: well-behaved callers pass the pair as a unit, eliminating the
125
+ * "siteId from session A combined with token from session B" mistake at
126
+ * the type level — see {@link SessionCredentials} brand-strength caveat.
127
+ * The factory itself still receives strings (its signature is user-facing API).
128
+ *
129
+ * ## Trust
130
+ *
131
+ * @trusted credentials // the SessionCredentials brand carries the
132
+ * // bearer/session siteId cross-check discharged at
133
+ * // mint time by `getSessionCredentials`. This
134
+ * // function does NOT re-validate; if a non-mint
135
+ * // path produces a SessionCredentials value (via
136
+ * // `as` cast), this function will materialise a
137
+ * // client for whatever siteId + token are present
138
+ * // in the value. Audit `as SessionCredentials`
139
+ * // usages — there should be exactly one, in
140
+ * // getSessionCredentials.
141
+ *
142
+ * ## Decision (Property)
143
+ *
144
+ * let key = `${credentials.siteId}\0${credentials.token}` in
145
+ * result(credentials) =
146
+ * _scopedClient.client when _scopedClient?.key = key // cache hit
147
+ * factory(siteId, token) when factory ≠ null // mint + cache
148
+ * null when factory = null // uninitialised
149
+ *
150
+ * Three outcomes. Throws only if `credentials.siteId` contains a NUL
151
+ * (`scopedClientKey`), which the mint point rules out by `isSiteId`, so it
152
+ * is reachable only through an `as SessionCredentials` cast. Side effect on
153
+ * the mint path only:
154
+ * `_scopedClient` is replaced with `{key, client}` so the next call with
155
+ * the same credentials hits the cached branch. Minting implicitly evicts
156
+ * the previous `_scopedClient` value (single-slot semantics — see invariant).
157
+ *
158
+ * ## Invariant — null-byte key separator (machine-checked)
159
+ *
160
+ * The key is `scopedClientKey(siteId, token)` = `siteId + "\0" + token`
161
+ * (`scoped-client-key.ts`). Dafny proves (`ScopedClientKeyInjective`) that
162
+ * for two NUL-free siteIds, equal keys mean equal siteIds and equal tokens,
163
+ * so the cache cannot hand one credential pair another pair's client. Only
164
+ * the siteId has to be NUL-free; the token may contain anything.
165
+ *
166
+ * The precondition is enforced, not assumed: `getSessionCredentials`, the
167
+ * only mint point, refuses any `targetSiteId` that fails augur-api's
168
+ * `isSiteId` (`[a-z0-9_-]+`, machine-checked in augur-api), and
169
+ * `scopedClientKey` throws on a NUL rather than return a key that could
170
+ * collide. What is NOT proved: that no other code path casts a value to
171
+ * `SessionCredentials` (see the Trust note above).
172
+ *
173
+ * Do NOT change the separator to a character that could appear in a
174
+ * siteId; the proof is stated for NUL and would have to be redone.
175
+ *
176
+ * ## Invariant — single-slot cache (eviction is implicit)
177
+ *
178
+ * `_scopedClient` holds at most one entry. Minting a client for
179
+ * credentials A AFTER credentials B were cached evicts B unrecoverably;
180
+ * a later request with credentials B will call the factory again rather
181
+ * than retrieving the previously-minted client.
182
+ *
183
+ * This is intentional. Scoped clients are per-request shortcuts; the
184
+ * cache exists to let multiple queryAction calls within a single request
185
+ * share an SDK client without re-running the factory. Cross-request
186
+ * caching is NOT a goal — Next.js may or may not preserve module state
187
+ * across invocations, so any retention beyond the single slot is
188
+ * best-effort and MUST NOT be relied upon for correctness.
189
+ *
190
+ * A future refactor to multi-slot LRU would change this contract:
191
+ * per-credential client identity becomes ambiguous across requests, and
192
+ * eviction policy becomes security-relevant (e.g. oldest-out could re-mint
193
+ * a client immediately after a credential rotation, surfacing stale
194
+ * permissions to the next caller). Do not multi-slot this without
195
+ * re-deriving the contract — particularly the relationship to credential
196
+ * rotation and bearer-token revocation in augur-api.
197
+ *
198
+ * ## Postcondition — identity, not transformation
199
+ *
200
+ * result ≠ null ⟹ result is referentially identical to the value the
201
+ * factory returned for the matching credentials.
202
+ *
203
+ * The cache stores and serves the factory's exact return value. It does
204
+ * not wrap, transform, proxy, or copy the client. Consumers that mutate
205
+ * the returned client (e.g. setting per-request properties on a singleton
206
+ * field) will observe the mutation on subsequent cache hits within the
207
+ * same request — by design.
208
+ */
209
+ export declare function getOrCreateScopedClient(credentials: SessionCredentials): unknown;
210
+ /**
211
+ * Register one or more SDK method paths the application is permitted to call
212
+ * through `queryAction`. Subsequent calls accumulate (idempotent on repeats).
213
+ *
214
+ * This is *site-level surface restriction*, not security. augur-api remains
215
+ * the auth authority; this primitive lets a site narrow its proxy's surface
216
+ * to the methods its UI actually wires up. Useful as defense-in-depth against
217
+ * same-origin XSS or compromised bundled deps POSTing arbitrary methodPaths
218
+ * to `/api/augur` — those calls will hit augur-api with the user's bearer
219
+ * (which augur-api will allow if the bearer is authorized), but the allowlist
220
+ * stops them from leaving the proxy in the first place.
221
+ *
222
+ * Permissive default: if `registerAllowedMethodPaths` is never called, all
223
+ * non-empty paths pass — the proxy behaves as a transparent forwarder, which
224
+ * is the package's design intent. Sites that want surface restriction opt in
225
+ * by calling this function.
226
+ */
227
+ export declare function registerAllowedMethodPaths(paths: readonly string[]): void;
228
+ /**
229
+ * Returns true if the application has registered an allowlist via
230
+ * {@link registerAllowedMethodPaths}. When false, `parseMethodPath` operates
231
+ * in permissive mode (any non-empty string passes).
232
+ */
233
+ export declare function isMethodPathAllowlistRegistered(): boolean;
234
+ /**
235
+ * Validate a candidate method path against the registered allowlist.
236
+ *
237
+ * - Returns the branded value if the path is a non-empty string AND
238
+ * (no allowlist is registered OR the path is in the allowlist).
239
+ * - Returns null if the path is not a non-empty string, or if an allowlist
240
+ * has been registered and the path is not in it.
241
+ *
242
+ * The brand on the return type is the only way internal code can produce an
243
+ * `ApprovedMethodPath`. Functions that walk the path into the SDK should
244
+ * accept `ApprovedMethodPath`, forcing the caller to discharge the validation.
245
+ */
246
+ export declare function parseMethodPath(candidate: unknown): ApprovedMethodPath | null;
247
+ /** Clears the registered SDK client, wrapper, and session stores. Used in tests only. @internal */
248
+ export declare function clearSdkClient(): void;
249
+ export {};
250
+ //# sourceMappingURL=sdk-client-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sdk-client-store.d.ts","sourceRoot":"","sources":["../src/sdk-client-store.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,2 @@
1
+ export type { SafeActionResult, ApiResult, ListResult } from "./sdk-call";
2
+ //# sourceMappingURL=server-actions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-actions.d.ts","sourceRoot":"","sources":["../src/server-actions.ts"],"names":[],"mappings":"AAWA,YAAY,EAAE,gBAAgB,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { QueryClient } from "@tanstack/react-query";
2
+ /**
3
+ * Creates a server-side query client optimised for prefetching.
4
+ *
5
+ * - No persistence (server-only)
6
+ * - No GC timers (gcTime: Infinity), so the client is freed with the request
7
+ * - No retries (fail fast on server)
8
+ * - No refetching (server renders are one-shot)
9
+ */
10
+ export declare function createServerQueryClient(): QueryClient;
11
+ /**
12
+ * Returns a per-request singleton QueryClient for React Server Components.
13
+ *
14
+ * React's `cache()` deduplicates calls within a single server request,
15
+ * so each request gets its own QueryClient while avoiding the cross-request
16
+ * state leakage that a module-level singleton would cause.
17
+ */
18
+ export declare const getServerQueryClient: () => QueryClient;
19
+ //# sourceMappingURL=server-query-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-query-client.d.ts","sourceRoot":"","sources":["../src/server-query-client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGpD;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,IAAI,WAAW,CAerD;AAED;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,QAAa,WAAyC,CAAC"}
@@ -1,5 +1,4 @@
1
- import { S as SiteActions } from './site-BjSFqufX.js';
2
-
1
+ import type { SiteActions } from "./actions/site";
3
2
  /**
4
3
  * Process-global storage for the site actions singleton.
5
4
  *
@@ -13,7 +12,7 @@ import { S as SiteActions } from './site-BjSFqufX.js';
13
12
  * `globalThis` on dynamic routes -- see vercel/next.js#74204).
14
13
  *
15
14
  * As a last resort, if both caches are empty, `getSiteActions()` will
16
- * auto-initialize from `AUGUR_SITE_ID` + `JWT` environment variables.
15
+ * auto-initialize from `AUGUR_SITE_ID` + `AUGUR_JWT` environment variables.
17
16
  * This self-healing behaviour prevents crashes when Next.js loses the
18
17
  * singleton across webpack bundle boundaries.
19
18
  */
@@ -21,21 +20,20 @@ import { S as SiteActions } from './site-BjSFqufX.js';
21
20
  * Stores the site actions instance for use by server action exports.
22
21
  * Called automatically by {@link createServerSite}.
23
22
  */
24
- declare function registerSiteActions(actions: SiteActions): void;
23
+ export declare function registerSiteActions(actions: SiteActions): void;
25
24
  /**
26
25
  * Returns the registered site actions instance.
27
26
  *
28
27
  * Resolution order:
29
28
  * 1. `globalThis` singleton (fastest, cross-bundle)
30
29
  * 2. Module-level cache (survives globalThis resets)
31
- * 3. Auto-init from `AUGUR_SITE_ID` + `JWT` env vars (self-healing)
30
+ * 3. Auto-init from `AUGUR_SITE_ID` + `AUGUR_JWT` env vars (self-healing)
32
31
  * 4. Throws if none of the above succeed
33
32
  */
34
- declare function getSiteActions(): SiteActions;
33
+ export declare function getSiteActions(): SiteActions;
35
34
  /**
36
35
  * Clears the registered site actions. Used in tests only.
37
36
  * @internal
38
37
  */
39
- declare function clearSiteActions(): void;
40
-
41
- export { clearSiteActions as c, getSiteActions as g, registerSiteActions as r };
38
+ export declare function clearSiteActions(): void;
39
+ //# sourceMappingURL=server-site-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-site-registry.d.ts","sourceRoot":"","sources":["../src/server-site-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAclD;;;;;;;;;;;;;;;;GAgBG;AAEH;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,CAE9D;AAgCD;;;;;;;;GAQG;AACH,wBAAgB,cAAc,IAAI,WAAW,CAU5C;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAEvC"}
@@ -1,23 +1,19 @@
1
- import { S as SiteActions, a as SiteActionsConfig } from './site-BjSFqufX.js';
2
- import { AugurAuthCallbacks } from './auth.js';
3
- import { NextAuthConfig } from 'next-auth';
4
- import '@simpleapps-com/augur-core';
5
- import '@simpleapps-com/augur-utils';
6
- import '@simpleapps-com/augur-api';
7
-
1
+ import type { SiteActionsConfig, SiteActions } from "./actions/site";
2
+ import type { AugurAuthCallbacks } from "./auth";
3
+ import type { NextAuthConfig } from "next-auth";
8
4
  /** Auth options forwarded to NextAuth when creating a server site. */
9
- interface ServerSiteAuthConfig {
5
+ export interface ServerSiteAuthConfig {
10
6
  secret?: string;
11
7
  maxAge?: number;
12
8
  callbacks?: Partial<AugurAuthCallbacks>;
13
9
  debug?: boolean;
14
10
  }
15
11
  /** Configuration for {@link createServerSite}, combining action config and auth. */
16
- interface ServerSiteConfig extends SiteActionsConfig {
12
+ export interface ServerSiteConfig extends SiteActionsConfig {
17
13
  auth?: ServerSiteAuthConfig;
18
14
  }
19
15
  /** The object returned by {@link createServerSite}. */
20
- interface ServerSite<TApi extends object> {
16
+ export interface ServerSite<TApi extends object> {
21
17
  client: TApi;
22
18
  actions: SiteActions;
23
19
  auth: NextAuthConfig | undefined;
@@ -28,16 +24,15 @@ interface ServerSite<TApi extends object> {
28
24
  *
29
25
  * @example
30
26
  * ```ts
31
- * import { AugurApi } from "@simpleapps-com/augur-api";
32
- * import { createServerSite } from "@simpleapps-com/augur-server";
27
+ * import { AugurAPI } from "@simpleapps-com/augur-api";
28
+ * import { createServerSite } from "@simpleapps-com/augur-server/site";
33
29
  *
34
- * const api = new AugurApi({ baseUrl: process.env.AUGUR_API_URL! });
30
+ * const api = new AugurAPI({ siteId: process.env.AUGUR_SITE_ID!, bearerToken: process.env.AUGUR_JWT! });
35
31
  * export const site = createServerSite(api, {
36
32
  * defaultCustomerId: "12345",
37
33
  * auth: { secret: process.env.AUTH_SECRET },
38
34
  * });
39
35
  * ```
40
36
  */
41
- declare function createServerSite<TApi extends object>(client: TApi, config?: ServerSiteConfig): ServerSite<TApi>;
42
-
43
- export { type ServerSite, type ServerSiteAuthConfig, type ServerSiteConfig, createServerSite };
37
+ export declare function createServerSite<TApi extends object>(client: TApi, config?: ServerSiteConfig): ServerSite<TApi>;
38
+ //# sourceMappingURL=server-site.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-site.d.ts","sourceRoot":"","sources":["../src/server-site.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAErE,OAAO,KAAK,EAAE,kBAAkB,EAAmB,MAAM,QAAQ,CAAC;AAClE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAahD,sEAAsE;AACtE,MAAM,WAAW,oBAAoB;IACnC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAC;IACxC,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,oFAAoF;AACpF,MAAM,WAAW,gBAAiB,SAAQ,iBAAiB;IACzD,IAAI,CAAC,EAAE,oBAAoB,CAAC;CAC7B;AAED,uDAAuD;AACvD,MAAM,WAAW,UAAU,CAAC,IAAI,SAAS,MAAM;IAC7C,MAAM,EAAE,IAAI,CAAC;IACb,OAAO,EAAE,WAAW,CAAC;IACrB,IAAI,EAAE,cAAc,GAAG,SAAS,CAAC;CAClC;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,SAAS,MAAM,EAClD,MAAM,EAAE,IAAI,EACZ,MAAM,GAAE,gBAAqB,GAC5B,UAAU,CAAC,IAAI,CAAC,CAqDlB"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Lightweight getter/setter for the site actions singleton.
3
+ *
4
+ * This module has ZERO imports from actions/site or any factory module.
5
+ * queryAction imports from here so that its bundle chunk does not
6
+ * transitively pull in ioredis, withServerCache, or any other server-only
7
+ * dependency.
8
+ *
9
+ * The heavy auto-init-from-env fallback lives in server-site-registry.ts,
10
+ * which is only imported by server-side entrypoints (index, actions, site).
11
+ */
12
+ /**
13
+ * Stores the site actions instance for use by server action exports.
14
+ * Called automatically by {@link createServerSite} via the registry module.
15
+ */
16
+ export declare function registerSiteActions(actions: unknown): void;
17
+ /**
18
+ * Returns the registered site actions instance, or null if not yet registered.
19
+ * Does NOT auto-init from env — that responsibility belongs to the registry.
20
+ */
21
+ export declare function getSiteActionsOrNull(): unknown;
22
+ /**
23
+ * Clears the registered site actions. Used in tests only.
24
+ * @internal
25
+ */
26
+ export declare function clearSiteActions(): void;
27
+ //# sourceMappingURL=site-actions-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"site-actions-store.d.ts","sourceRoot":"","sources":["../src/site-actions-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAMH;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAG1D;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,IAAI,OAAO,CAS9C;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAGvC"}
package/dist/site.js CHANGED
@@ -1,19 +1,21 @@
1
1
  import {
2
2
  createAuthConfig
3
- } from "./chunk-KHFEDL47.js";
3
+ } from "./chunk-SXXWBSTX.js";
4
4
  import {
5
5
  createSiteActions,
6
6
  registerSiteActions,
7
7
  withServerCache
8
- } from "./chunk-WOHZDFJF.js";
8
+ } from "./chunk-PFYEMJTQ.js";
9
9
  import {
10
10
  registerAuthSecret,
11
11
  registerClientFactory,
12
12
  registerScopedCacheWrapper,
13
13
  registerSdkCallWrapper,
14
14
  registerSdkClient
15
- } from "./chunk-HPQQYROJ.js";
16
- import "./chunk-DGUM43GV.js";
15
+ } from "./chunk-NTUPTNOI.js";
16
+ import {
17
+ ttlFor
18
+ } from "./chunk-TVH5EONP.js";
17
19
 
18
20
  // src/server-site.ts
19
21
  import { getCacheTier } from "@simpleapps-com/augur-core";
@@ -23,15 +25,13 @@ function createServerSite(client, config = {}) {
23
25
  registerSdkClient(client);
24
26
  const { cachePrefix = "", redisTtl = 3600, longRedisTtl = 28800 } = config;
25
27
  registerSdkCallWrapper((methodPath, sdkCall, ...keyArgs) => {
26
- const tier = getCacheTier(methodPath);
27
- if (tier.staleTime === 0) return sdkCall();
28
- const ttl = tier.staleTime >= 36e5 ? longRedisTtl : redisTtl;
28
+ const ttl = ttlFor(getCacheTier(methodPath).staleTime, redisTtl, longRedisTtl);
29
+ if (ttl === null) return sdkCall();
29
30
  return withServerCache(cachePrefix, ttl, methodPath, sdkCall, ...keyArgs);
30
31
  });
31
32
  registerScopedCacheWrapper((prefix, methodPath, sdkCall, ...keyArgs) => {
32
- const tier = getCacheTier(methodPath);
33
- if (tier.staleTime === 0) return sdkCall();
34
- const ttl = tier.staleTime >= 36e5 ? longRedisTtl : redisTtl;
33
+ const ttl = ttlFor(getCacheTier(methodPath).staleTime, redisTtl, longRedisTtl);
34
+ if (ttl === null) return sdkCall();
35
35
  return withServerCache(prefix, ttl, methodPath, sdkCall, ...keyArgs);
36
36
  });
37
37
  const baseConfig = client["config"];
package/dist/site.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/server-site.ts"],"sourcesContent":["import { createSiteActions } from \"./actions/site\";\nimport type { SiteActionsConfig, SiteActions } from \"./actions/site\";\nimport { createAuthConfig } from \"./auth\";\nimport type { AugurAuthCallbacks, AugurAuthClient } from \"./auth\";\nimport type { NextAuthConfig } from \"next-auth\";\nimport { registerSiteActions } from \"./server-site-registry\";\nimport {\n registerSdkClient,\n registerSdkCallWrapper,\n registerAuthSecret,\n registerClientFactory,\n registerScopedCacheWrapper,\n} from \"./sdk-client-store\";\nimport { withServerCache } from \"./cache/with-cache\";\nimport { getCacheTier } from \"@simpleapps-com/augur-core\";\n\n/** Auth options forwarded to NextAuth when creating a server site. */\nexport interface ServerSiteAuthConfig {\n secret?: string;\n maxAge?: number;\n callbacks?: Partial<AugurAuthCallbacks>;\n debug?: boolean;\n}\n\n/** Configuration for {@link createServerSite}, combining action config and auth. */\nexport interface ServerSiteConfig extends SiteActionsConfig {\n auth?: ServerSiteAuthConfig;\n}\n\n/** The object returned by {@link createServerSite}. */\nexport interface ServerSite<TApi extends object> {\n client: TApi;\n actions: SiteActions;\n auth: NextAuthConfig | undefined;\n}\n\n/**\n * Create a server-side site instance that bundles the SDK client, server\n * actions, and (optional) NextAuth configuration.\n *\n * @example\n * ```ts\n * import { AugurApi } from \"@simpleapps-com/augur-api\";\n * import { createServerSite } from \"@simpleapps-com/augur-server\";\n *\n * const api = new AugurApi({ baseUrl: process.env.AUGUR_API_URL! });\n * export const site = createServerSite(api, {\n * defaultCustomerId: \"12345\",\n * auth: { secret: process.env.AUTH_SECRET },\n * });\n * ```\n */\nexport function createServerSite<TApi extends object>(\n client: TApi,\n config: ServerSiteConfig = {},\n): ServerSite<TApi> {\n const actions = createSiteActions(client, config);\n registerSiteActions(actions);\n registerSdkClient(client);\n\n // Register a cache wrapper that captures the site's Redis config.\n // queryAction uses this to wrap read methods in Redis caching without\n // importing withServerCache directly (which would pull ioredis into\n // the client bundle via tsup code splitting).\n const { cachePrefix = \"\", redisTtl = 3600, longRedisTtl = 28800 } = config;\n registerSdkCallWrapper((methodPath, sdkCall, ...keyArgs) => {\n const tier = getCacheTier(methodPath);\n // Static paths (staleTime >= 1 hour): long Redis TTL\n // SemiStatic paths (staleTime > 0): standard Redis TTL\n // None (staleTime === 0): no caching\n if (tier.staleTime === 0) return sdkCall();\n const ttl = tier.staleTime >= 3_600_000 ? longRedisTtl : redisTtl;\n return withServerCache(cachePrefix, ttl, methodPath, sdkCall, ...keyArgs);\n });\n\n // Register scoped cache wrapper for per-request session credentials.\n // queryAction uses this to wrap scoped client calls with Redis caching\n // using the targetSiteId as the cache prefix.\n registerScopedCacheWrapper((prefix, methodPath, sdkCall, ...keyArgs) => {\n const tier = getCacheTier(methodPath);\n if (tier.staleTime === 0) return sdkCall();\n const ttl = tier.staleTime >= 3_600_000 ? longRedisTtl : redisTtl;\n return withServerCache(prefix, ttl, methodPath, sdkCall, ...keyArgs);\n });\n\n // Register client factory for creating scoped SDK clients with\n // per-request credentials. Uses the same constructor + base config\n // (baseUrl, timeout, retries) but different siteId/bearerToken.\n const baseConfig = (client as Record<string, unknown>)[\"config\"] as\n | Record<string, unknown>\n | undefined;\n if (baseConfig) {\n const Ctor = client.constructor as new (cfg: Record<string, unknown>) => object;\n registerClientFactory((siteId: string, bearerToken: string) => {\n return new Ctor({ ...baseConfig, siteId, bearerToken });\n });\n }\n\n const authSecret = config.auth?.secret ?? process.env[\"AUTH_SECRET\"];\n if (authSecret) {\n registerAuthSecret(authSecret);\n }\n\n const auth = config.auth\n ? createAuthConfig({\n augurClient: client as unknown as AugurAuthClient,\n defaultCustomerId: config.defaultCustomerId,\n defaultContactId: config.defaultContactId,\n ...config.auth,\n })\n : undefined;\n\n return { client, actions, auth };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAcA,SAAS,oBAAoB;AAsCtB,SAAS,iBACd,QACA,SAA2B,CAAC,GACV;AAClB,QAAM,UAAU,kBAAkB,QAAQ,MAAM;AAChD,sBAAoB,OAAO;AAC3B,oBAAkB,MAAM;AAMxB,QAAM,EAAE,cAAc,IAAI,WAAW,MAAM,eAAe,MAAM,IAAI;AACpE,yBAAuB,CAAC,YAAY,YAAY,YAAY;AAC1D,UAAM,OAAO,aAAa,UAAU;AAIpC,QAAI,KAAK,cAAc,EAAG,QAAO,QAAQ;AACzC,UAAM,MAAM,KAAK,aAAa,OAAY,eAAe;AACzD,WAAO,gBAAgB,aAAa,KAAK,YAAY,SAAS,GAAG,OAAO;AAAA,EAC1E,CAAC;AAKD,6BAA2B,CAAC,QAAQ,YAAY,YAAY,YAAY;AACtE,UAAM,OAAO,aAAa,UAAU;AACpC,QAAI,KAAK,cAAc,EAAG,QAAO,QAAQ;AACzC,UAAM,MAAM,KAAK,aAAa,OAAY,eAAe;AACzD,WAAO,gBAAgB,QAAQ,KAAK,YAAY,SAAS,GAAG,OAAO;AAAA,EACrE,CAAC;AAKD,QAAM,aAAc,OAAmC,QAAQ;AAG/D,MAAI,YAAY;AACd,UAAM,OAAO,OAAO;AACpB,0BAAsB,CAAC,QAAgB,gBAAwB;AAC7D,aAAO,IAAI,KAAK,EAAE,GAAG,YAAY,QAAQ,YAAY,CAAC;AAAA,IACxD,CAAC;AAAA,EACH;AAEA,QAAM,aAAa,OAAO,MAAM,UAAU,QAAQ,IAAI,aAAa;AACnE,MAAI,YAAY;AACd,uBAAmB,UAAU;AAAA,EAC/B;AAEA,QAAM,OAAO,OAAO,OAChB,iBAAiB;AAAA,IACf,aAAa;AAAA,IACb,mBAAmB,OAAO;AAAA,IAC1B,kBAAkB,OAAO;AAAA,IACzB,GAAG,OAAO;AAAA,EACZ,CAAC,IACD;AAEJ,SAAO,EAAE,QAAQ,SAAS,KAAK;AACjC;","names":[]}
1
+ {"version":3,"sources":["../src/server-site.ts"],"sourcesContent":["import { createSiteActions } from \"./actions/site\";\nimport type { SiteActionsConfig, SiteActions } from \"./actions/site\";\nimport { createAuthConfig } from \"./auth\";\nimport type { AugurAuthCallbacks, AugurAuthClient } from \"./auth\";\nimport type { NextAuthConfig } from \"next-auth\";\nimport { registerSiteActions } from \"./server-site-registry\";\nimport {\n registerSdkClient,\n registerSdkCallWrapper,\n registerAuthSecret,\n registerClientFactory,\n registerScopedCacheWrapper,\n} from \"./sdk-client-store\";\nimport { withServerCache } from \"./cache/with-cache\";\nimport { ttlFor } from \"./rules\";\nimport { getCacheTier } from \"@simpleapps-com/augur-core\";\n\n/** Auth options forwarded to NextAuth when creating a server site. */\nexport interface ServerSiteAuthConfig {\n secret?: string;\n maxAge?: number;\n callbacks?: Partial<AugurAuthCallbacks>;\n debug?: boolean;\n}\n\n/** Configuration for {@link createServerSite}, combining action config and auth. */\nexport interface ServerSiteConfig extends SiteActionsConfig {\n auth?: ServerSiteAuthConfig;\n}\n\n/** The object returned by {@link createServerSite}. */\nexport interface ServerSite<TApi extends object> {\n client: TApi;\n actions: SiteActions;\n auth: NextAuthConfig | undefined;\n}\n\n/**\n * Create a server-side site instance that bundles the SDK client, server\n * actions, and (optional) NextAuth configuration.\n *\n * @example\n * ```ts\n * import { AugurAPI } from \"@simpleapps-com/augur-api\";\n * import { createServerSite } from \"@simpleapps-com/augur-server/site\";\n *\n * const api = new AugurAPI({ siteId: process.env.AUGUR_SITE_ID!, bearerToken: process.env.AUGUR_JWT! });\n * export const site = createServerSite(api, {\n * defaultCustomerId: \"12345\",\n * auth: { secret: process.env.AUTH_SECRET },\n * });\n * ```\n */\nexport function createServerSite<TApi extends object>(\n client: TApi,\n config: ServerSiteConfig = {},\n): ServerSite<TApi> {\n const actions = createSiteActions(client, config);\n registerSiteActions(actions);\n registerSdkClient(client);\n\n // Register a cache wrapper that captures the site's Redis config.\n // queryAction uses this to wrap read methods in Redis caching without\n // importing withServerCache directly (which would pull ioredis into\n // the client bundle via tsup code splitting).\n const { cachePrefix = \"\", redisTtl = 3600, longRedisTtl = 28800 } = config;\n registerSdkCallWrapper((methodPath, sdkCall, ...keyArgs) => {\n // An hour of staleTime or more: the long TTL; any other: the standard; 0: no caching.\n const ttl = ttlFor(getCacheTier(methodPath).staleTime, redisTtl, longRedisTtl);\n if (ttl === null) return sdkCall();\n return withServerCache(cachePrefix, ttl, methodPath, sdkCall, ...keyArgs);\n });\n\n // Register scoped cache wrapper for per-request session credentials.\n // queryAction uses this to wrap scoped client calls with Redis caching\n // using the targetSiteId as the cache prefix.\n registerScopedCacheWrapper((prefix, methodPath, sdkCall, ...keyArgs) => {\n const ttl = ttlFor(getCacheTier(methodPath).staleTime, redisTtl, longRedisTtl);\n if (ttl === null) return sdkCall();\n return withServerCache(prefix, ttl, methodPath, sdkCall, ...keyArgs);\n });\n\n // Register client factory for creating scoped SDK clients with\n // per-request credentials. Uses the same constructor + base config\n // (baseUrl, timeout, retries) but different siteId/bearerToken.\n const baseConfig = (client as Record<string, unknown>)[\"config\"] as\n Record<string, unknown> | undefined;\n if (baseConfig) {\n const Ctor = client.constructor as new (cfg: Record<string, unknown>) => object;\n registerClientFactory((siteId: string, bearerToken: string) => {\n return new Ctor({ ...baseConfig, siteId, bearerToken });\n });\n }\n\n const authSecret = config.auth?.secret ?? process.env[\"AUTH_SECRET\"];\n if (authSecret) {\n registerAuthSecret(authSecret);\n }\n\n const auth = config.auth\n ? createAuthConfig({\n augurClient: client as unknown as AugurAuthClient,\n defaultCustomerId: config.defaultCustomerId,\n defaultContactId: config.defaultContactId,\n ...config.auth,\n })\n : undefined;\n\n return { client, actions, auth };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAeA,SAAS,oBAAoB;AAsCtB,SAAS,iBACd,QACA,SAA2B,CAAC,GACV;AAClB,QAAM,UAAU,kBAAkB,QAAQ,MAAM;AAChD,sBAAoB,OAAO;AAC3B,oBAAkB,MAAM;AAMxB,QAAM,EAAE,cAAc,IAAI,WAAW,MAAM,eAAe,MAAM,IAAI;AACpE,yBAAuB,CAAC,YAAY,YAAY,YAAY;AAE1D,UAAM,MAAM,OAAO,aAAa,UAAU,EAAE,WAAW,UAAU,YAAY;AAC7E,QAAI,QAAQ,KAAM,QAAO,QAAQ;AACjC,WAAO,gBAAgB,aAAa,KAAK,YAAY,SAAS,GAAG,OAAO;AAAA,EAC1E,CAAC;AAKD,6BAA2B,CAAC,QAAQ,YAAY,YAAY,YAAY;AACtE,UAAM,MAAM,OAAO,aAAa,UAAU,EAAE,WAAW,UAAU,YAAY;AAC7E,QAAI,QAAQ,KAAM,QAAO,QAAQ;AACjC,WAAO,gBAAgB,QAAQ,KAAK,YAAY,SAAS,GAAG,OAAO;AAAA,EACrE,CAAC;AAKD,QAAM,aAAc,OAAmC,QAAQ;AAE/D,MAAI,YAAY;AACd,UAAM,OAAO,OAAO;AACpB,0BAAsB,CAAC,QAAgB,gBAAwB;AAC7D,aAAO,IAAI,KAAK,EAAE,GAAG,YAAY,QAAQ,YAAY,CAAC;AAAA,IACxD,CAAC;AAAA,EACH;AAEA,QAAM,aAAa,OAAO,MAAM,UAAU,QAAQ,IAAI,aAAa;AACnE,MAAI,YAAY;AACd,uBAAmB,UAAU;AAAA,EAC/B;AAEA,QAAM,OAAO,OAAO,OAChB,iBAAiB;AAAA,IACf,aAAa;AAAA,IACb,mBAAmB,OAAO;AAAA,IAC1B,kBAAkB,OAAO;AAAA,IACzB,GAAG,OAAO;AAAA,EACZ,CAAC,IACD;AAEJ,SAAO,EAAE,QAAQ,SAAS,KAAK;AACjC;","names":[]}
package/dist/testing.d.ts CHANGED
@@ -1,14 +1,12 @@
1
- export { DeepMockClient, MockClientResult, createMockClient } from '@simpleapps-com/augur-core/testing';
2
- export { c as clearSiteActions } from './server-site-registry-CdBfczOj.js';
3
- import { S as SiteActions } from './site-BjSFqufX.js';
4
- import '@simpleapps-com/augur-core';
5
- import '@simpleapps-com/augur-utils';
6
-
1
+ export { createMockClient } from "@simpleapps-com/augur-core/testing";
2
+ export { clearSiteActions } from "./server-site-registry";
3
+ export type { DeepMockClient, MockClientResult } from "@simpleapps-com/augur-core/testing";
4
+ import type { SiteActions } from "./actions/site";
7
5
  /**
8
6
  * A mock function type compatible with both Vitest and Jest.
9
7
  * Supports `.mockResolvedValue()`, `.mockRejectedValue()`, and call tracking.
10
8
  */
11
- interface MockFn {
9
+ export interface MockFn {
12
10
  (...args: unknown[]): unknown;
13
11
  mockResolvedValue: (value: unknown) => MockFn;
14
12
  mockRejectedValue: (value: unknown) => MockFn;
@@ -19,13 +17,13 @@ interface MockFn {
19
17
  };
20
18
  }
21
19
  /** Mirror of SiteActions where every method is a MockFn. */
22
- type MockSiteActions = {
20
+ export type MockSiteActions = {
23
21
  [K in keyof SiteActions]: {
24
22
  [M in keyof SiteActions[K]]: MockFn;
25
23
  };
26
24
  };
27
25
  /** Return type of createMockSiteActions. */
28
- interface MockSiteActionsResult {
26
+ export interface MockSiteActionsResult {
29
27
  /** Typed as SiteActions — pass this to your components/server actions. */
30
28
  actions: SiteActions;
31
29
  /** Same object typed with MockFn — use for assertions and mock setup. */
@@ -54,6 +52,5 @@ interface MockSiteActionsResult {
54
52
  * expect(mocks.pricing.getItemPrice.mock.calls[0]).toEqual(["ITEM-1"]);
55
53
  * ```
56
54
  */
57
- declare function createMockSiteActions(): MockSiteActionsResult;
58
-
59
- export { type MockFn, type MockSiteActions, type MockSiteActionsResult, createMockSiteActions };
55
+ export declare function createMockSiteActions(): MockSiteActionsResult;
56
+ //# sourceMappingURL=testing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,YAAY,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAE3F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD;;;GAGG;AACH,MAAM,WAAW,MAAM;IACrB,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAC9B,iBAAiB,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,CAAC;IAC9C,iBAAiB,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,CAAC;IAC9C,eAAe,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,CAAC;IAC5C,kBAAkB,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,KAAK,MAAM,CAAC;IACpE,IAAI,EAAE;QAAE,KAAK,EAAE,OAAO,EAAE,EAAE,CAAA;KAAE,CAAC;CAC9B;AAED,4DAA4D;AAC5D,MAAM,MAAM,eAAe,GAAG;KAC3B,CAAC,IAAI,MAAM,WAAW,GAAG;SACvB,CAAC,IAAI,MAAM,WAAW,CAAC,CAAC,CAAC,GAAG,MAAM;KACpC;CACF,CAAC;AAEF,4CAA4C;AAC5C,MAAM,WAAW,qBAAqB;IACpC,0EAA0E;IAC1E,OAAO,EAAE,WAAW,CAAC;IACrB,yEAAyE;IACzE,KAAK,EAAE,eAAe,CAAC;CACxB;AAwJD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,qBAAqB,IAAI,qBAAqB,CAe7D"}