@simpleapps-com/augur-server 2.4.0 → 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.
- package/EXPORTS.md +29 -72
- package/README.md +29 -198
- package/dist/actions/agr-info.d.ts +43 -0
- package/dist/actions/agr-info.d.ts.map +1 -0
- package/dist/actions/agr-site.d.ts +37 -0
- package/dist/actions/agr-site.d.ts.map +1 -0
- package/dist/actions/agr-work.d.ts +29 -0
- package/dist/actions/agr-work.d.ts.map +1 -0
- package/dist/actions/avalara.d.ts +38 -0
- package/dist/actions/avalara.d.ts.map +1 -0
- package/dist/actions/basecamp2.d.ts +47 -0
- package/dist/actions/basecamp2.d.ts.map +1 -0
- package/dist/actions/brand-folder.d.ts +38 -0
- package/dist/actions/brand-folder.d.ts.map +1 -0
- package/dist/actions/commerce.d.ts +58 -0
- package/dist/actions/commerce.d.ts.map +1 -0
- package/dist/actions/customers.d.ts +44 -0
- package/dist/actions/customers.d.ts.map +1 -0
- package/dist/actions/favorites.d.ts +20 -0
- package/dist/actions/favorites.d.ts.map +1 -0
- package/dist/actions/gregorovich.d.ts +34 -0
- package/dist/actions/gregorovich.d.ts.map +1 -0
- package/dist/actions/items.d.ts +80 -0
- package/dist/actions/items.d.ts.map +1 -0
- package/dist/actions/joomla.d.ts +59 -0
- package/dist/actions/joomla.d.ts.map +1 -0
- package/dist/actions/legacy.d.ts +45 -0
- package/dist/actions/legacy.d.ts.map +1 -0
- package/dist/actions/logistics.d.ts +40 -0
- package/dist/actions/logistics.d.ts.map +1 -0
- package/dist/actions/orders.d.ts +36 -0
- package/dist/actions/orders.d.ts.map +1 -0
- package/dist/actions/p21-apis.d.ts +33 -0
- package/dist/actions/p21-apis.d.ts.map +1 -0
- package/dist/actions/p21-core.d.ts +46 -0
- package/dist/actions/p21-core.d.ts.map +1 -0
- package/dist/actions/p21-pim.d.ts +36 -0
- package/dist/actions/p21-pim.d.ts.map +1 -0
- package/dist/actions/p21-sism.d.ts +37 -0
- package/dist/actions/p21-sism.d.ts.map +1 -0
- package/dist/actions/payments.d.ts +39 -0
- package/dist/actions/payments.d.ts.map +1 -0
- package/dist/actions/pricing.d.ts +45 -0
- package/dist/actions/pricing.d.ts.map +1 -0
- package/dist/actions/search.d.ts +61 -0
- package/dist/actions/search.d.ts.map +1 -0
- package/dist/actions/shipping.d.ts +56 -0
- package/dist/actions/shipping.d.ts.map +1 -0
- package/dist/actions/site.d.ts +141 -0
- package/dist/actions/site.d.ts.map +1 -0
- package/dist/actions/smarty-streets.d.ts +45 -0
- package/dist/actions/smarty-streets.d.ts.map +1 -0
- package/dist/actions/vmi.d.ts +44 -0
- package/dist/actions/vmi.d.ts.map +1 -0
- package/dist/actions/wishlists.d.ts +28 -0
- package/dist/actions/wishlists.d.ts.map +1 -0
- package/dist/api-handler.d.ts +25 -0
- package/dist/api-handler.d.ts.map +1 -0
- package/dist/api.d.ts +2 -26
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +19 -14
- package/dist/api.js.map +1 -1
- package/dist/auth.d.ts +10 -12
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +2 -2
- package/dist/cache/redis-client.d.ts +16 -0
- package/dist/cache/redis-client.d.ts.map +1 -0
- package/dist/cache/with-cache.d.ts +18 -0
- package/dist/cache/with-cache.d.ts.map +1 -0
- package/dist/{chunk-2NL4QKJN.js → chunk-FWO6Q43T.js} +31 -30
- package/dist/chunk-FWO6Q43T.js.map +1 -0
- package/dist/{chunk-ALTIINP6.js → chunk-NTUPTNOI.js} +30 -6
- package/dist/chunk-NTUPTNOI.js.map +1 -0
- package/dist/{chunk-26WZBC4F.js → chunk-PFYEMJTQ.js} +203 -631
- package/dist/chunk-PFYEMJTQ.js.map +1 -0
- package/dist/{chunk-KHFEDL47.js → chunk-SXXWBSTX.js} +18 -12
- package/dist/chunk-SXXWBSTX.js.map +1 -0
- package/dist/chunk-TVH5EONP.js +178 -0
- package/dist/chunk-TVH5EONP.js.map +1 -0
- package/dist/{chunk-PIYHMA6F.js → chunk-U2BKHRJC.js} +10 -13
- package/dist/chunk-U2BKHRJC.js.map +1 -0
- package/dist/environment.d.ts +10 -0
- package/dist/environment.d.ts.map +1 -0
- package/dist/hooks.d.ts +8 -10
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +3 -3
- package/dist/hooks.js.map +1 -1
- package/dist/index.d.ts +16 -125
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -7
- package/dist/index.js.map +1 -1
- package/dist/pagination.d.ts +32 -0
- package/dist/pagination.d.ts.map +1 -0
- package/dist/query-action.d.ts +15 -117
- package/dist/query-action.d.ts.map +1 -0
- package/dist/query-action.js +3 -3
- package/dist/{query.d.ts → query-options-helper.d.ts} +5 -7
- package/dist/query-options-helper.d.ts.map +1 -0
- package/dist/query.js +1 -2
- package/dist/recaptcha.d.ts +6 -0
- package/dist/recaptcha.d.ts.map +1 -0
- package/dist/rules.d.ts +221 -0
- package/dist/rules.d.ts.map +1 -0
- package/dist/scoped-client-key.d.ts +9 -0
- package/dist/scoped-client-key.d.ts.map +1 -0
- package/dist/sdk-call.d.ts +66 -0
- package/dist/sdk-call.d.ts.map +1 -0
- package/dist/sdk-client-store.d.ts +250 -0
- package/dist/sdk-client-store.d.ts.map +1 -0
- package/dist/server-actions.d.ts +2 -0
- package/dist/server-actions.d.ts.map +1 -0
- package/dist/server-query-client.d.ts +19 -0
- package/dist/server-query-client.d.ts.map +1 -0
- package/dist/{server-site-registry-CdBfczOj.d.ts → server-site-registry.d.ts} +7 -9
- package/dist/server-site-registry.d.ts.map +1 -0
- package/dist/{site.d.ts → server-site.d.ts} +11 -16
- package/dist/server-site.d.ts.map +1 -0
- package/dist/site-actions-store.d.ts +27 -0
- package/dist/site-actions-store.d.ts.map +1 -0
- package/dist/site.js +10 -10
- package/dist/site.js.map +1 -1
- package/dist/testing.d.ts +9 -12
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +7 -27
- package/dist/testing.js.map +1 -1
- package/dist/utils/batch-fetch.d.ts +7 -0
- package/dist/utils/batch-fetch.d.ts.map +1 -0
- package/llms.txt +71 -50
- package/package.json +29 -20
- package/dist/actions.d.ts +0 -2
- package/dist/chunk-26WZBC4F.js.map +0 -1
- package/dist/chunk-2NL4QKJN.js.map +0 -1
- package/dist/chunk-ALTIINP6.js.map +0 -1
- package/dist/chunk-DGUM43GV.js +0 -11
- package/dist/chunk-DGUM43GV.js.map +0 -1
- package/dist/chunk-KHFEDL47.js.map +0 -1
- package/dist/chunk-PIYHMA6F.js.map +0 -1
- package/dist/site-BjSFqufX.d.ts +0 -469
|
@@ -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 @@
|
|
|
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 {
|
|
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` + `
|
|
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` + `
|
|
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 {
|
|
2
|
-
import { AugurAuthCallbacks } from
|
|
3
|
-
import { NextAuthConfig } from
|
|
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 {
|
|
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
|
|
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-
|
|
3
|
+
} from "./chunk-SXXWBSTX.js";
|
|
4
4
|
import {
|
|
5
5
|
createSiteActions,
|
|
6
6
|
registerSiteActions,
|
|
7
7
|
withServerCache
|
|
8
|
-
} from "./chunk-
|
|
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-
|
|
16
|
-
import
|
|
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
|
|
27
|
-
if (
|
|
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
|
|
33
|
-
if (
|
|
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 {
|
|
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 {
|
|
2
|
-
export {
|
|
3
|
-
|
|
4
|
-
import
|
|
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"}
|
package/dist/testing.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
clearSiteActions
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
5
|
-
import "./chunk-
|
|
3
|
+
} from "./chunk-PFYEMJTQ.js";
|
|
4
|
+
import "./chunk-NTUPTNOI.js";
|
|
5
|
+
import "./chunk-TVH5EONP.js";
|
|
6
6
|
|
|
7
7
|
// src/testing.ts
|
|
8
8
|
import { createMockClient } from "@simpleapps-com/augur-core/testing";
|
|
@@ -47,7 +47,6 @@ var SERVICE_METHODS = {
|
|
|
47
47
|
],
|
|
48
48
|
legacy: ["getItemWebDesc", "getAlsoBoughtItems", "getItemTags", "getStates"],
|
|
49
49
|
customers: [
|
|
50
|
-
"getCustomer",
|
|
51
50
|
"customerLookup",
|
|
52
51
|
"getCustomerDoc",
|
|
53
52
|
"getCustomerOrders",
|
|
@@ -56,12 +55,11 @@ var SERVICE_METHODS = {
|
|
|
56
55
|
"getCustomerInvoiceDetail",
|
|
57
56
|
"getCustomerQuotes",
|
|
58
57
|
"getCustomerQuoteDetail",
|
|
59
|
-
"getContacts",
|
|
60
58
|
"getShipToAddresses"
|
|
61
59
|
],
|
|
62
60
|
smartyStreets: ["validateAddress"],
|
|
63
61
|
p21Pim: ["getInvMastExt", "listInvMastExt"],
|
|
64
|
-
agrSite: ["getSettings", "
|
|
62
|
+
agrSite: ["getSettings", "getRobots"],
|
|
65
63
|
avalara: ["calculateTax"],
|
|
66
64
|
payments: [
|
|
67
65
|
"transactionSetup",
|
|
@@ -72,14 +70,6 @@ var SERVICE_METHODS = {
|
|
|
72
70
|
"validatePayment"
|
|
73
71
|
],
|
|
74
72
|
logistics: ["getFreightRates", "getShipVia"],
|
|
75
|
-
nexus: [
|
|
76
|
-
"createBinTransfer",
|
|
77
|
-
"createReceiving",
|
|
78
|
-
"createTransfer",
|
|
79
|
-
"getPurchaseOrderReceipts",
|
|
80
|
-
"getTransferReceipts",
|
|
81
|
-
"getTransferShipping"
|
|
82
|
-
],
|
|
83
73
|
vmi: [
|
|
84
74
|
"getWarehouses",
|
|
85
75
|
"getWarehouseAvailability",
|
|
@@ -98,17 +88,8 @@ var SERVICE_METHODS = {
|
|
|
98
88
|
"getCashDrawers",
|
|
99
89
|
"getCodeP21"
|
|
100
90
|
],
|
|
101
|
-
p21Apis: [
|
|
102
|
-
|
|
103
|
-
"getCategoryDefaults",
|
|
104
|
-
"getCompanies",
|
|
105
|
-
"getUsers",
|
|
106
|
-
"getWebDisplayTypes",
|
|
107
|
-
"getWebDisplayTypeDefaults",
|
|
108
|
-
"refreshContacts",
|
|
109
|
-
"refreshCustomers"
|
|
110
|
-
],
|
|
111
|
-
p21Sism: ["getRecentImports", "getImport", "getImportLines", "getScheduledImports"],
|
|
91
|
+
p21Apis: ["refreshContacts", "refreshCustomers"],
|
|
92
|
+
p21Sism: ["getRecentImports", "getImport", "getScheduledImports"],
|
|
112
93
|
agrWork: ["healthCheck", "ping"],
|
|
113
94
|
agrInfo: ["getContext", "getRubrics", "getMicroservices", "generateAkasha", "generateJoomla"],
|
|
114
95
|
basecamp2: [
|
|
@@ -123,8 +104,7 @@ var SERVICE_METHODS = {
|
|
|
123
104
|
"getTodolists"
|
|
124
105
|
],
|
|
125
106
|
brandFolder: ["getCategories", "getCategory", "createFocus"],
|
|
126
|
-
gregorovich: ["
|
|
127
|
-
slack: ["sendWebhook", "getWebhooks"],
|
|
107
|
+
gregorovich: ["getDocuments"],
|
|
128
108
|
favorites: ["getFavorites", "addFavorite", "removeFavorite"],
|
|
129
109
|
wishlists: [
|
|
130
110
|
"getWishlists",
|