@simpleapps-com/augur-server 0.2.3 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-I7EWYSPA.js +27 -0
- package/dist/chunk-I7EWYSPA.js.map +1 -0
- package/dist/index.d.ts +559 -1
- package/dist/index.js +595 -20
- package/dist/index.js.map +1 -1
- package/dist/prefetch.d.ts +78 -0
- package/dist/prefetch.js +149 -0
- package/dist/prefetch.js.map +1 -0
- package/package.json +13 -4
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// src/server-query-client.ts
|
|
2
|
+
import { cache } from "react";
|
|
3
|
+
import { QueryClient } from "@tanstack/react-query";
|
|
4
|
+
import { CACHE_CONFIG } from "@simpleapps-com/augur-utils";
|
|
5
|
+
function createServerQueryClient() {
|
|
6
|
+
return new QueryClient({
|
|
7
|
+
defaultOptions: {
|
|
8
|
+
queries: {
|
|
9
|
+
staleTime: CACHE_CONFIG.STATIC.staleTime,
|
|
10
|
+
gcTime: CACHE_CONFIG.STATIC.staleTime,
|
|
11
|
+
retry: 0,
|
|
12
|
+
refetchOnMount: false,
|
|
13
|
+
refetchOnWindowFocus: false,
|
|
14
|
+
refetchOnReconnect: false
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
var getServerQueryClient = cache(
|
|
20
|
+
() => createServerQueryClient()
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
export {
|
|
24
|
+
createServerQueryClient,
|
|
25
|
+
getServerQueryClient
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=chunk-I7EWYSPA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/server-query-client.ts"],"sourcesContent":["import { cache } from \"react\";\nimport { QueryClient } from \"@tanstack/react-query\";\nimport { CACHE_CONFIG } from \"@simpleapps-com/augur-utils\";\n\n/**\n * Creates a server-side query client optimised for prefetching.\n *\n * - No persistence (server-only)\n * - Longer cache times for prefetched data\n * - No retries (fail fast on server)\n * - No refetching (server renders are one-shot)\n */\nexport function createServerQueryClient(): QueryClient {\n return new QueryClient({\n defaultOptions: {\n queries: {\n staleTime: CACHE_CONFIG.STATIC.staleTime,\n gcTime: CACHE_CONFIG.STATIC.staleTime,\n retry: 0,\n refetchOnMount: false,\n refetchOnWindowFocus: false,\n refetchOnReconnect: false,\n },\n },\n });\n}\n\n/**\n * Returns a per-request singleton QueryClient for React Server Components.\n *\n * React's `cache()` deduplicates calls within a single server request,\n * so each request gets its own QueryClient while avoiding the cross-request\n * state leakage that a module-level singleton would cause.\n */\nexport const getServerQueryClient = cache(\n (): QueryClient => createServerQueryClient(),\n);\n"],"mappings":";AAAA,SAAS,aAAa;AACtB,SAAS,mBAAmB;AAC5B,SAAS,oBAAoB;AAUtB,SAAS,0BAAuC;AACrD,SAAO,IAAI,YAAY;AAAA,IACrB,gBAAgB;AAAA,MACd,SAAS;AAAA,QACP,WAAW,aAAa,OAAO;AAAA,QAC/B,QAAQ,aAAa,OAAO;AAAA,QAC5B,OAAO;AAAA,QACP,gBAAgB;AAAA,QAChB,sBAAsB;AAAA,QACtB,oBAAoB;AAAA,MACtB;AAAA,IACF;AAAA,EACF,CAAC;AACH;AASO,IAAM,uBAAuB;AAAA,EAClC,MAAmB,wBAAwB;AAC7C;","names":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { QueryClient } from '@tanstack/react-query';
|
|
2
2
|
export { QueryOptionsConfig, createQueryOptions, createSuspenseQueryOptions } from './query.js';
|
|
3
|
+
import { TPriceData, TTaxItem, TTax, TCategory, TAttribute, TInvMast, TInvMastDoc, TStockData, TItemAccessory, TStock, TCartLookUp, TCartLine, TProductItem } from '@simpleapps-com/augur-utils';
|
|
3
4
|
|
|
4
5
|
declare const env: "development" | "staging" | "production";
|
|
5
6
|
declare const isDev: boolean;
|
|
@@ -47,4 +48,561 @@ declare function createServerQueryClient(): QueryClient;
|
|
|
47
48
|
*/
|
|
48
49
|
declare const getServerQueryClient: () => QueryClient;
|
|
49
50
|
|
|
50
|
-
|
|
51
|
+
/**
|
|
52
|
+
* Server-side cache wrapper using augur-server's Redis client.
|
|
53
|
+
*
|
|
54
|
+
* Uses the same cache key format as augur-hooks' `withCache`:
|
|
55
|
+
* `${prefix}sdk:${methodPath}:${fnv1a(stableStringify(keyArgs))}`
|
|
56
|
+
*
|
|
57
|
+
* This means server-side cached data can be read by client-side hooks
|
|
58
|
+
* (and vice versa) when using the same prefix and method path.
|
|
59
|
+
*
|
|
60
|
+
* @param prefix Cache key prefix (e.g. "ampro:"). Empty string if none.
|
|
61
|
+
* @param redisTtl Redis TTL in seconds. 0 or undefined = skip caching.
|
|
62
|
+
* @param methodPath Dot-separated SDK method path (e.g. "pricing.priceEngine.get").
|
|
63
|
+
* @param fn The async function to cache.
|
|
64
|
+
* @param keyArgs Values to hash for the cache key.
|
|
65
|
+
*/
|
|
66
|
+
declare function withServerCache<T>(prefix: string, redisTtl: number | undefined, methodPath: string, fn: () => Promise<T>, ...keyArgs: unknown[]): Promise<T>;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The subset of augur-api used by pricing actions.
|
|
70
|
+
* Avoids importing the full SDK type so augur-server stays lightweight.
|
|
71
|
+
*/
|
|
72
|
+
interface PricingApiClient {
|
|
73
|
+
pricing: {
|
|
74
|
+
priceEngine: {
|
|
75
|
+
get: (params: Record<string, unknown>) => Promise<{
|
|
76
|
+
data: TPriceData;
|
|
77
|
+
}>;
|
|
78
|
+
};
|
|
79
|
+
taxEngine: {
|
|
80
|
+
create: (params: Record<string, unknown>) => Promise<{
|
|
81
|
+
data: TTax;
|
|
82
|
+
}>;
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
interface PricingActionsConfig {
|
|
87
|
+
/** Default customer ID when none is provided by the caller. */
|
|
88
|
+
defaultCustomerId?: string | number;
|
|
89
|
+
/** Cache key prefix (e.g. "ampro:"). Default: "". */
|
|
90
|
+
cachePrefix?: string;
|
|
91
|
+
/** CDN edge cache value passed to SDK. Default: 2 (hours). */
|
|
92
|
+
edgeCache?: number;
|
|
93
|
+
/** Redis TTL for price lookups in seconds. Default: 3600 (1 hour). */
|
|
94
|
+
redisTtl?: number;
|
|
95
|
+
/** Redis TTL for tax lookups in seconds. Default: 1800 (30 min). */
|
|
96
|
+
taxRedisTtl?: number;
|
|
97
|
+
}
|
|
98
|
+
interface PricingActions {
|
|
99
|
+
getItemPrice: (itemId: string, customerId?: string | number, quantity?: number) => Promise<TPriceData>;
|
|
100
|
+
batchGetItemPrices: (itemIds: string[], customerId?: string | number, quantity?: number) => Promise<Record<string, TPriceData>>;
|
|
101
|
+
getTaxEstimate: (customerId: string | number, postalCode: string, items: TTaxItem[]) => Promise<TTax>;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Creates server-side pricing actions with Redis caching and edge cache support.
|
|
105
|
+
*
|
|
106
|
+
* Uses `withServerCache` which produces cache keys compatible with augur-hooks'
|
|
107
|
+
* `withCache`, so server-prefetched data is shared with client-side hooks.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* // lib/pricing-actions.ts
|
|
112
|
+
* import { createPricingActions } from "@simpleapps-com/augur-server";
|
|
113
|
+
* import { getAugurClient } from "./augur-client";
|
|
114
|
+
*
|
|
115
|
+
* export const pricingActions = createPricingActions(getAugurClient(), {
|
|
116
|
+
* defaultCustomerId: process.env.NEXT_PUBLIC_DEFAULT_CUSTOMER_ID,
|
|
117
|
+
* cachePrefix: "ampro:",
|
|
118
|
+
* });
|
|
119
|
+
*
|
|
120
|
+
* // In a server component:
|
|
121
|
+
* const price = await pricingActions.getItemPrice("ITEM-1");
|
|
122
|
+
* const prices = await pricingActions.batchGetItemPrices(["ITEM-1", "ITEM-2"]);
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
declare function createPricingActions(api: PricingApiClient, config?: PricingActionsConfig): PricingActions;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* The subset of augur-api used by item actions.
|
|
129
|
+
* Avoids importing the full SDK type so augur-server stays lightweight.
|
|
130
|
+
*/
|
|
131
|
+
interface ItemsApiClient {
|
|
132
|
+
items: {
|
|
133
|
+
categories: {
|
|
134
|
+
get: (uid: number, params?: Record<string, unknown>) => Promise<{
|
|
135
|
+
data: TCategory;
|
|
136
|
+
}>;
|
|
137
|
+
lookup: {
|
|
138
|
+
get: (params: Record<string, unknown>) => Promise<{
|
|
139
|
+
data: unknown;
|
|
140
|
+
}>;
|
|
141
|
+
};
|
|
142
|
+
items: {
|
|
143
|
+
list: (params: Record<string, unknown>) => Promise<{
|
|
144
|
+
data: unknown;
|
|
145
|
+
}>;
|
|
146
|
+
};
|
|
147
|
+
attributes: {
|
|
148
|
+
list: (uid: number, params?: Record<string, unknown>) => Promise<{
|
|
149
|
+
data: {
|
|
150
|
+
attributes: TAttribute[];
|
|
151
|
+
};
|
|
152
|
+
}>;
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
invMast: {
|
|
156
|
+
get: (uid: number, params?: Record<string, unknown>) => Promise<{
|
|
157
|
+
data: TInvMast;
|
|
158
|
+
}>;
|
|
159
|
+
doc: {
|
|
160
|
+
list: (uid: number, params?: Record<string, unknown>) => Promise<{
|
|
161
|
+
data: TInvMastDoc;
|
|
162
|
+
}>;
|
|
163
|
+
};
|
|
164
|
+
stock: {
|
|
165
|
+
list: (uid: number, params?: Record<string, unknown>) => Promise<{
|
|
166
|
+
data: TStock;
|
|
167
|
+
}>;
|
|
168
|
+
};
|
|
169
|
+
faq: {
|
|
170
|
+
list: (uid: number, params?: Record<string, unknown>) => Promise<{
|
|
171
|
+
data: unknown[];
|
|
172
|
+
}>;
|
|
173
|
+
};
|
|
174
|
+
invSub: {
|
|
175
|
+
list: (uid: number, params?: Record<string, unknown>) => Promise<{
|
|
176
|
+
data: unknown[];
|
|
177
|
+
}>;
|
|
178
|
+
};
|
|
179
|
+
invAccessory: {
|
|
180
|
+
list: (uid: number, params?: Record<string, unknown>) => Promise<{
|
|
181
|
+
data: TItemAccessory[];
|
|
182
|
+
}>;
|
|
183
|
+
};
|
|
184
|
+
similar: {
|
|
185
|
+
list: (uid: number, params?: Record<string, unknown>) => Promise<{
|
|
186
|
+
data: unknown[];
|
|
187
|
+
}>;
|
|
188
|
+
};
|
|
189
|
+
};
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
interface ItemActionsConfig {
|
|
193
|
+
/** Cache key prefix (e.g. "ampro:"). Default: "". */
|
|
194
|
+
cachePrefix?: string;
|
|
195
|
+
/** CDN edge cache value for most calls. Default: 1 (hour). */
|
|
196
|
+
edgeCache?: number;
|
|
197
|
+
/** CDN edge cache for rarely-changing data like FAQs. Default: 8 (hours). */
|
|
198
|
+
longEdgeCache?: number;
|
|
199
|
+
/** Redis TTL for most calls in seconds. Default: 3600 (1 hour). */
|
|
200
|
+
redisTtl?: number;
|
|
201
|
+
/** Redis TTL for rarely-changing data in seconds. Default: 28800 (8 hours). */
|
|
202
|
+
longRedisTtl?: number;
|
|
203
|
+
}
|
|
204
|
+
interface ItemActions {
|
|
205
|
+
itemCategoryLookup: (path: string) => Promise<unknown>;
|
|
206
|
+
getItemCategory: (uid: number, options?: Record<string, unknown>) => Promise<TCategory>;
|
|
207
|
+
getCategoryItems: (uid: number, filters: Record<string, unknown>) => Promise<unknown>;
|
|
208
|
+
getItemAttributes: (categoryUid: number) => Promise<TAttribute[]>;
|
|
209
|
+
getInvMast: (uid: number) => Promise<TInvMast>;
|
|
210
|
+
getInvMastDoc: (params: {
|
|
211
|
+
invMastUid?: number;
|
|
212
|
+
itemId?: string;
|
|
213
|
+
}) => Promise<TInvMastDoc>;
|
|
214
|
+
getStock: (invMastUid: number) => Promise<TStockData[]>;
|
|
215
|
+
getStockCompanySummary: (invMastUid: number) => Promise<Record<string, number>>;
|
|
216
|
+
getItemFaqs: (invMastUid: number) => Promise<unknown[]>;
|
|
217
|
+
getItemSubstitutes: (invMastUid: number) => Promise<unknown[]>;
|
|
218
|
+
getItemAccessories: (invMastUid: number) => Promise<TItemAccessory[]>;
|
|
219
|
+
getSimilarItems: (invMastUid: number) => Promise<unknown[]>;
|
|
220
|
+
batchGetInvMastDocs: (params: {
|
|
221
|
+
invMastUid?: number;
|
|
222
|
+
itemId?: string;
|
|
223
|
+
}[]) => Promise<Record<string, TInvMastDoc>>;
|
|
224
|
+
batchGetStockData: (invMastUids: number[]) => Promise<Record<number, TStockData[]>>;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Creates server-side item actions with Redis caching and edge cache support.
|
|
228
|
+
*
|
|
229
|
+
* Uses `withServerCache` which produces cache keys compatible with augur-hooks'
|
|
230
|
+
* `withCache`, so server-prefetched data is shared with client-side hooks.
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* ```ts
|
|
234
|
+
* // lib/item-actions.ts
|
|
235
|
+
* import { createItemActions } from "@simpleapps-com/augur-server";
|
|
236
|
+
* import { getAugurClient } from "./augur-client";
|
|
237
|
+
*
|
|
238
|
+
* export const itemActions = createItemActions(getAugurClient(), {
|
|
239
|
+
* cachePrefix: "ampro:",
|
|
240
|
+
* });
|
|
241
|
+
*
|
|
242
|
+
* // In a server component:
|
|
243
|
+
* const category = await itemActions.getItemCategory(123);
|
|
244
|
+
* const doc = await itemActions.getInvMastDoc({ itemId: "ITEM-1" });
|
|
245
|
+
* ```
|
|
246
|
+
*/
|
|
247
|
+
declare function createItemActions(api: ItemsApiClient, config?: ItemActionsConfig): ItemActions;
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* The subset of augur-api used by commerce actions.
|
|
251
|
+
* Avoids importing the full SDK type so augur-server stays lightweight.
|
|
252
|
+
*/
|
|
253
|
+
interface CommerceApiClient {
|
|
254
|
+
commerce: {
|
|
255
|
+
cartHdr: {
|
|
256
|
+
lookup: {
|
|
257
|
+
get: (params: Record<string, unknown>) => Promise<{
|
|
258
|
+
data: TCartLookUp;
|
|
259
|
+
}>;
|
|
260
|
+
};
|
|
261
|
+
alsoBought: {
|
|
262
|
+
get: (cartHdrUid: number, params?: Record<string, unknown>) => Promise<{
|
|
263
|
+
data: unknown[];
|
|
264
|
+
}>;
|
|
265
|
+
};
|
|
266
|
+
};
|
|
267
|
+
cartLine: {
|
|
268
|
+
get: (cartHdrUid: number) => Promise<{
|
|
269
|
+
data: TCartLine[];
|
|
270
|
+
}>;
|
|
271
|
+
add: {
|
|
272
|
+
create: (cartHdrUid: number, params: Record<string, unknown>) => Promise<{
|
|
273
|
+
data: unknown;
|
|
274
|
+
}>;
|
|
275
|
+
};
|
|
276
|
+
update: {
|
|
277
|
+
create: (cartHdrUid: number, params: Record<string, unknown>) => Promise<{
|
|
278
|
+
data: unknown;
|
|
279
|
+
}>;
|
|
280
|
+
};
|
|
281
|
+
delete: (cartHdrUid: number) => Promise<{
|
|
282
|
+
data: unknown;
|
|
283
|
+
}>;
|
|
284
|
+
};
|
|
285
|
+
checkout: {
|
|
286
|
+
create: (params: Record<string, unknown>) => Promise<{
|
|
287
|
+
data: unknown;
|
|
288
|
+
}>;
|
|
289
|
+
};
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
interface CommerceActionsConfig {
|
|
293
|
+
defaultContactId?: string | number;
|
|
294
|
+
defaultCustomerId?: string | number;
|
|
295
|
+
/** Optional UOM conversion function. E.g. (uom) => uom === "EA" ? "EACH" : uom */
|
|
296
|
+
convertUnitOfMeasure?: (uom: string) => string;
|
|
297
|
+
}
|
|
298
|
+
interface CommerceActions {
|
|
299
|
+
cartHdrLookup: (params: {
|
|
300
|
+
userId?: string | number;
|
|
301
|
+
cartToken?: string;
|
|
302
|
+
contactId?: string | number;
|
|
303
|
+
customerId?: string | number;
|
|
304
|
+
}) => Promise<TCartLookUp>;
|
|
305
|
+
getCartLines: (cartHdrUid: number) => Promise<TCartLine[]>;
|
|
306
|
+
addToCart: (cartHdrUid: number, items: {
|
|
307
|
+
itemId: string;
|
|
308
|
+
quantity: number;
|
|
309
|
+
unitOfMeasure: string;
|
|
310
|
+
}[]) => Promise<unknown>;
|
|
311
|
+
updateCartLines: (cartHdrUid: number, lines: {
|
|
312
|
+
lineNo: number;
|
|
313
|
+
quantity: number;
|
|
314
|
+
unitOfMeasure: string;
|
|
315
|
+
}[]) => Promise<unknown>;
|
|
316
|
+
deleteCartItems: (cartHdrUid: number) => Promise<void>;
|
|
317
|
+
getCartAlsoBought: (cartHdrUid: number) => Promise<unknown[]>;
|
|
318
|
+
checkoutOrder: (cartHdrUid: number, data: Record<string, unknown>) => Promise<unknown>;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Creates server-side commerce actions for cart operations.
|
|
322
|
+
*
|
|
323
|
+
* Unlike pricing actions, commerce actions do NOT use caching because
|
|
324
|
+
* cart operations are real-time and must always reflect current state.
|
|
325
|
+
*
|
|
326
|
+
* @example
|
|
327
|
+
* ```ts
|
|
328
|
+
* // lib/commerce-actions.ts
|
|
329
|
+
* import { createCommerceActions } from "@simpleapps-com/augur-server";
|
|
330
|
+
* import { getAugurClient } from "./augur-client";
|
|
331
|
+
*
|
|
332
|
+
* export const commerceActions = createCommerceActions(getAugurClient(), {
|
|
333
|
+
* defaultContactId: process.env.NEXT_PUBLIC_DEFAULT_CONTACT_ID,
|
|
334
|
+
* defaultCustomerId: process.env.NEXT_PUBLIC_DEFAULT_CUSTOMER_ID,
|
|
335
|
+
* convertUnitOfMeasure: (uom) => uom === "EA" ? "EACH" : uom,
|
|
336
|
+
* });
|
|
337
|
+
*
|
|
338
|
+
* // In a server action:
|
|
339
|
+
* const cart = await commerceActions.cartHdrLookup({ userId: 123 });
|
|
340
|
+
* const lines = await commerceActions.getCartLines(cart.cartHdrUid);
|
|
341
|
+
* ```
|
|
342
|
+
*/
|
|
343
|
+
declare function createCommerceActions(api: CommerceApiClient, config?: CommerceActionsConfig): CommerceActions;
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* The subset of augur-api used by order actions.
|
|
347
|
+
* Avoids importing the full SDK type so augur-server stays lightweight.
|
|
348
|
+
*/
|
|
349
|
+
interface OrderApiClient {
|
|
350
|
+
orders: {
|
|
351
|
+
oeHdr: {
|
|
352
|
+
doc: {
|
|
353
|
+
get: (params: Record<string, unknown>) => Promise<{
|
|
354
|
+
data: unknown;
|
|
355
|
+
}>;
|
|
356
|
+
};
|
|
357
|
+
};
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
interface OrderActionsConfig {
|
|
361
|
+
/** Cache key prefix (e.g. "ampro:"). Default: "". */
|
|
362
|
+
cachePrefix?: string;
|
|
363
|
+
/** CDN edge cache value passed to SDK. Default: 1 (hour). */
|
|
364
|
+
edgeCache?: number;
|
|
365
|
+
/** Redis TTL for order doc lookups in seconds. Default: 3600 (1 hour). */
|
|
366
|
+
redisTtl?: number;
|
|
367
|
+
}
|
|
368
|
+
interface OrderActions {
|
|
369
|
+
getOrderDoc: (orderNo: string, zipCode: string) => Promise<unknown>;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Creates server-side order actions with Redis caching and edge cache support.
|
|
373
|
+
*
|
|
374
|
+
* Uses `withServerCache` which produces cache keys compatible with augur-hooks'
|
|
375
|
+
* `withCache`, so server-prefetched data is shared with client-side hooks.
|
|
376
|
+
*
|
|
377
|
+
* @example
|
|
378
|
+
* ```ts
|
|
379
|
+
* // lib/order-actions.ts
|
|
380
|
+
* import { createOrderActions } from "@simpleapps-com/augur-server";
|
|
381
|
+
* import { getAugurClient } from "./augur-client";
|
|
382
|
+
*
|
|
383
|
+
* export const orderActions = createOrderActions(getAugurClient(), {
|
|
384
|
+
* cachePrefix: "ampro:",
|
|
385
|
+
* });
|
|
386
|
+
*
|
|
387
|
+
* // In a server component:
|
|
388
|
+
* const doc = await orderActions.getOrderDoc("12345", "90210");
|
|
389
|
+
* ```
|
|
390
|
+
*/
|
|
391
|
+
declare function createOrderActions(api: OrderApiClient, config?: OrderActionsConfig): OrderActions;
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* The subset of augur-api used by search actions.
|
|
395
|
+
* Avoids importing the full SDK type so augur-server stays lightweight.
|
|
396
|
+
*/
|
|
397
|
+
interface SearchApiClient {
|
|
398
|
+
openSearch: {
|
|
399
|
+
itemSearch: {
|
|
400
|
+
list: (params: Record<string, unknown>) => Promise<{
|
|
401
|
+
data: {
|
|
402
|
+
items: TProductItem[];
|
|
403
|
+
totalResults: number;
|
|
404
|
+
};
|
|
405
|
+
}>;
|
|
406
|
+
attributes: {
|
|
407
|
+
list: (params: Record<string, unknown>) => Promise<{
|
|
408
|
+
data: {
|
|
409
|
+
attributes: TAttribute[];
|
|
410
|
+
};
|
|
411
|
+
}>;
|
|
412
|
+
};
|
|
413
|
+
};
|
|
414
|
+
suggestions: {
|
|
415
|
+
suggest: {
|
|
416
|
+
list: (params: Record<string, unknown>) => Promise<{
|
|
417
|
+
data: {
|
|
418
|
+
data: unknown[];
|
|
419
|
+
total: number;
|
|
420
|
+
totalResults: number;
|
|
421
|
+
};
|
|
422
|
+
}>;
|
|
423
|
+
};
|
|
424
|
+
};
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
interface SearchActionsConfig {
|
|
428
|
+
/** Cache key prefix (e.g. "ampro:"). Default: "". */
|
|
429
|
+
cachePrefix?: string;
|
|
430
|
+
/** CDN edge cache value passed to SDK. Default: 1 (hour). */
|
|
431
|
+
edgeCache?: number;
|
|
432
|
+
/** Redis TTL for search lookups in seconds. Default: 3600 (1 hour). */
|
|
433
|
+
redisTtl?: number;
|
|
434
|
+
/** Default source fields for item search. Default: "display_desc". */
|
|
435
|
+
defaultSourceFields?: string;
|
|
436
|
+
}
|
|
437
|
+
/** Paginated response for infinite scroll. */
|
|
438
|
+
interface SearchPage {
|
|
439
|
+
data: TProductItem[];
|
|
440
|
+
total: number;
|
|
441
|
+
nextCursor?: number;
|
|
442
|
+
}
|
|
443
|
+
interface SearchActions {
|
|
444
|
+
getSearchAttributes: (q: string) => Promise<TAttribute[]>;
|
|
445
|
+
getSearchSuggestions: (q: string, limit?: number, offset?: number) => Promise<{
|
|
446
|
+
data: unknown[];
|
|
447
|
+
total: number;
|
|
448
|
+
totalResults: number;
|
|
449
|
+
}>;
|
|
450
|
+
itemSearch: (filters: {
|
|
451
|
+
q: string;
|
|
452
|
+
limit: number;
|
|
453
|
+
offset: number;
|
|
454
|
+
sortBy?: string;
|
|
455
|
+
filters?: [string, string][];
|
|
456
|
+
}, itemCategoryUid?: number | string) => Promise<{
|
|
457
|
+
items: TProductItem[];
|
|
458
|
+
totalResults: number;
|
|
459
|
+
}>;
|
|
460
|
+
itemSearchInfinite: (filters: {
|
|
461
|
+
q: string;
|
|
462
|
+
limit: number;
|
|
463
|
+
sortBy?: string;
|
|
464
|
+
filters?: [string, string][];
|
|
465
|
+
}, itemCategoryUid?: number | string, pageParam?: number) => Promise<SearchPage>;
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Creates server-side search actions with Redis caching and edge cache support.
|
|
469
|
+
*
|
|
470
|
+
* Uses `withServerCache` which produces cache keys compatible with augur-hooks'
|
|
471
|
+
* `withCache`, so server-prefetched data is shared with client-side hooks.
|
|
472
|
+
*
|
|
473
|
+
* @example
|
|
474
|
+
* ```ts
|
|
475
|
+
* // lib/search-actions.ts
|
|
476
|
+
* import { createSearchActions } from "@simpleapps-com/augur-server";
|
|
477
|
+
* import { getAugurClient } from "./augur-client";
|
|
478
|
+
*
|
|
479
|
+
* export const searchActions = createSearchActions(getAugurClient(), {
|
|
480
|
+
* cachePrefix: "ampro:",
|
|
481
|
+
* });
|
|
482
|
+
*
|
|
483
|
+
* // In a server component:
|
|
484
|
+
* const attrs = await searchActions.getSearchAttributes("widget");
|
|
485
|
+
* const results = await searchActions.itemSearch({ q: "widget", limit: 20, offset: 0 });
|
|
486
|
+
* ```
|
|
487
|
+
*/
|
|
488
|
+
declare function createSearchActions(api: SearchApiClient, config?: SearchActionsConfig): SearchActions;
|
|
489
|
+
|
|
490
|
+
interface ShippingAddress {
|
|
491
|
+
address1: string;
|
|
492
|
+
city: string;
|
|
493
|
+
state: string;
|
|
494
|
+
postalCode: string;
|
|
495
|
+
country?: string;
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* The subset of augur-api used by shipping actions.
|
|
499
|
+
* Avoids importing the full SDK type so augur-server stays lightweight.
|
|
500
|
+
*/
|
|
501
|
+
interface ShippingApiClient {
|
|
502
|
+
ups: {
|
|
503
|
+
ratesShop: {
|
|
504
|
+
get: (params: Record<string, unknown>) => Promise<{
|
|
505
|
+
data: unknown;
|
|
506
|
+
}>;
|
|
507
|
+
};
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
interface ShippingActionsConfig {
|
|
511
|
+
/** Warehouse/origin address for rate calculations. */
|
|
512
|
+
fromAddress: ShippingAddress;
|
|
513
|
+
/** UPS service codes to filter results. Default: undefined (return all). */
|
|
514
|
+
defaultServiceCodes?: string[];
|
|
515
|
+
/** Cache key prefix (e.g. "ampro:"). Default: "". */
|
|
516
|
+
cachePrefix?: string;
|
|
517
|
+
/** CDN edge cache value passed to SDK. Default: 1 (hour). */
|
|
518
|
+
edgeCache?: number;
|
|
519
|
+
/** Redis TTL for shipping rate lookups in seconds. Default: 3600 (1 hour). */
|
|
520
|
+
redisTtl?: number;
|
|
521
|
+
}
|
|
522
|
+
interface ShippingActions {
|
|
523
|
+
getShippingRates: (toAddress: ShippingAddress, weight: number, serviceCodes?: string[]) => Promise<unknown>;
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* Creates server-side shipping actions with Redis caching and edge cache support.
|
|
527
|
+
*
|
|
528
|
+
* Uses `withServerCache` which produces cache keys compatible with augur-hooks'
|
|
529
|
+
* `withCache`, so server-prefetched data is shared with client-side hooks.
|
|
530
|
+
*
|
|
531
|
+
* @example
|
|
532
|
+
* ```ts
|
|
533
|
+
* // lib/shipping-actions.ts
|
|
534
|
+
* import { createShippingActions } from "@simpleapps-com/augur-server";
|
|
535
|
+
* import { getAugurClient } from "./augur-client";
|
|
536
|
+
*
|
|
537
|
+
* export const shippingActions = createShippingActions(getAugurClient(), {
|
|
538
|
+
* fromAddress: {
|
|
539
|
+
* address1: "123 Warehouse Ln",
|
|
540
|
+
* city: "Chicago",
|
|
541
|
+
* state: "IL",
|
|
542
|
+
* postalCode: "60601",
|
|
543
|
+
* },
|
|
544
|
+
* });
|
|
545
|
+
*
|
|
546
|
+
* // In a server component:
|
|
547
|
+
* const rates = await shippingActions.getShippingRates(
|
|
548
|
+
* { address1: "456 Main St", city: "Denver", state: "CO", postalCode: "80202" },
|
|
549
|
+
* 5.0,
|
|
550
|
+
* );
|
|
551
|
+
* ```
|
|
552
|
+
*/
|
|
553
|
+
declare function createShippingActions(api: ShippingApiClient, config: ShippingActionsConfig): ShippingActions;
|
|
554
|
+
|
|
555
|
+
/**
|
|
556
|
+
* The subset of augur-api used by Joomla content actions.
|
|
557
|
+
* Avoids importing the full SDK type so augur-server stays lightweight.
|
|
558
|
+
*/
|
|
559
|
+
interface JoomlaApiClient {
|
|
560
|
+
joomla: {
|
|
561
|
+
content: {
|
|
562
|
+
doc: {
|
|
563
|
+
get: (articleId: number, params?: Record<string, unknown>) => Promise<{
|
|
564
|
+
data: unknown;
|
|
565
|
+
}>;
|
|
566
|
+
};
|
|
567
|
+
list: (params?: Record<string, unknown>) => Promise<{
|
|
568
|
+
data: unknown[];
|
|
569
|
+
}>;
|
|
570
|
+
};
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
interface JoomlaActionsConfig {
|
|
574
|
+
/** Cache key prefix (e.g. "ampro:"). Default: "". */
|
|
575
|
+
cachePrefix?: string;
|
|
576
|
+
/** CDN edge cache value passed to SDK. Default: 1 (hour). */
|
|
577
|
+
edgeCache?: number;
|
|
578
|
+
/** Redis TTL for Joomla lookups in seconds. Default: 3600 (1 hour). */
|
|
579
|
+
redisTtl?: number;
|
|
580
|
+
}
|
|
581
|
+
interface JoomlaActions {
|
|
582
|
+
getJoomlaContent: (articleId: number) => Promise<unknown>;
|
|
583
|
+
getJoomlaContentList: (params?: Record<string, unknown>) => Promise<unknown[]>;
|
|
584
|
+
}
|
|
585
|
+
/**
|
|
586
|
+
* Creates server-side Joomla content actions with Redis caching and edge cache support.
|
|
587
|
+
*
|
|
588
|
+
* Uses `withServerCache` which produces cache keys compatible with augur-hooks'
|
|
589
|
+
* `withCache`, so server-prefetched data is shared with client-side hooks.
|
|
590
|
+
*
|
|
591
|
+
* @example
|
|
592
|
+
* ```ts
|
|
593
|
+
* // lib/joomla-actions.ts
|
|
594
|
+
* import { createJoomlaActions } from "@simpleapps-com/augur-server";
|
|
595
|
+
* import { getAugurClient } from "./augur-client";
|
|
596
|
+
*
|
|
597
|
+
* export const joomlaActions = createJoomlaActions(getAugurClient(), {
|
|
598
|
+
* cachePrefix: "ampro:",
|
|
599
|
+
* });
|
|
600
|
+
*
|
|
601
|
+
* // In a server component:
|
|
602
|
+
* const article = await joomlaActions.getJoomlaContent(42);
|
|
603
|
+
* const articles = await joomlaActions.getJoomlaContentList({ catid: 5 });
|
|
604
|
+
* ```
|
|
605
|
+
*/
|
|
606
|
+
declare function createJoomlaActions(api: JoomlaApiClient, config?: JoomlaActionsConfig): JoomlaActions;
|
|
607
|
+
|
|
608
|
+
export { type CommerceActions, type CommerceActionsConfig, type CommerceApiClient, type ItemActions, type ItemActionsConfig, type ItemsApiClient, type JoomlaActions, type JoomlaActionsConfig, type JoomlaApiClient, type OrderActions, type OrderActionsConfig, type OrderApiClient, type PricingActions, type PricingActionsConfig, type PricingApiClient, type SearchActions, type SearchActionsConfig, type SearchApiClient, type SearchPage, type ShippingActions, type ShippingActionsConfig, type ShippingAddress, type ShippingApiClient, cacheGet, cacheSet, createCommerceActions, createItemActions, createJoomlaActions, createOrderActions, createPricingActions, createSearchActions, createServerQueryClient, createShippingActions, env, getCircuitState, getServerQueryClient, isDev, isProduction, isRedisConnected, isStaging, sdkCall, withServerCache };
|