@akropolys/sdk 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +130 -0
- package/dist/chunk-BDDPLGUO.mjs +1164 -0
- package/dist/chunk-BDDPLGUO.mjs.map +1 -0
- package/dist/chunk-FBM65EZM.mjs +1127 -0
- package/dist/chunk-FBM65EZM.mjs.map +1 -0
- package/dist/chunk-NWQKZTKU.mjs +1127 -0
- package/dist/chunk-NWQKZTKU.mjs.map +1 -0
- package/dist/commerce.d.mts +2 -0
- package/dist/commerce.d.ts +2 -0
- package/dist/commerce.js +1171 -0
- package/dist/commerce.js.map +1 -0
- package/dist/commerce.mjs +41 -0
- package/dist/commerce.mjs.map +1 -0
- package/dist/index.d.mts +377 -0
- package/dist/index.d.ts +377 -0
- package/dist/index.js +1168 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +38 -0
- package/dist/index.mjs.map +1 -0
- package/dist/property.d.mts +2 -0
- package/dist/property.d.ts +2 -0
- package/dist/property.js +1171 -0
- package/dist/property.js.map +1 -0
- package/dist/property.mjs +41 -0
- package/dist/property.mjs.map +1 -0
- package/package.json +71 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
type Product<T extends Record<string, any> = Record<string, any>> = {
|
|
4
|
+
name: string;
|
|
5
|
+
price: string;
|
|
6
|
+
url: string;
|
|
7
|
+
brand?: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
originalPrice?: string;
|
|
10
|
+
discount?: string;
|
|
11
|
+
currency?: string;
|
|
12
|
+
stock?: string;
|
|
13
|
+
availability?: string;
|
|
14
|
+
rating?: string;
|
|
15
|
+
reviewCount?: number;
|
|
16
|
+
category?: string;
|
|
17
|
+
subCategory?: string;
|
|
18
|
+
tags?: string[];
|
|
19
|
+
images?: string[];
|
|
20
|
+
specs?: Record<string, string>;
|
|
21
|
+
priceNumeric?: number;
|
|
22
|
+
slug?: string;
|
|
23
|
+
metadata?: Record<string, any>;
|
|
24
|
+
} & T;
|
|
25
|
+
type RawProductInput<T extends Record<string, any> = Record<string, any>> = {
|
|
26
|
+
name?: string;
|
|
27
|
+
title?: string;
|
|
28
|
+
productName?: string;
|
|
29
|
+
price?: string | number;
|
|
30
|
+
priceNumeric?: number;
|
|
31
|
+
url?: string;
|
|
32
|
+
image?: string;
|
|
33
|
+
thumbnail?: string;
|
|
34
|
+
images?: string[];
|
|
35
|
+
slug?: string;
|
|
36
|
+
id?: string;
|
|
37
|
+
productId?: string;
|
|
38
|
+
brand?: string;
|
|
39
|
+
description?: string;
|
|
40
|
+
originalPrice?: string;
|
|
41
|
+
discount?: string;
|
|
42
|
+
currency?: string;
|
|
43
|
+
stock?: string;
|
|
44
|
+
availability?: string;
|
|
45
|
+
rating?: string;
|
|
46
|
+
reviewCount?: number;
|
|
47
|
+
category?: string;
|
|
48
|
+
subCategory?: string;
|
|
49
|
+
tags?: string[];
|
|
50
|
+
specs?: Record<string, string>;
|
|
51
|
+
metadata?: Record<string, any>;
|
|
52
|
+
} & T;
|
|
53
|
+
interface CartItem {
|
|
54
|
+
id: string;
|
|
55
|
+
cart_id: string;
|
|
56
|
+
external_id?: string;
|
|
57
|
+
product_url: string;
|
|
58
|
+
name: string;
|
|
59
|
+
price: string;
|
|
60
|
+
price_numeric: number;
|
|
61
|
+
currency: string;
|
|
62
|
+
image: string;
|
|
63
|
+
brand: string;
|
|
64
|
+
category: string;
|
|
65
|
+
quantity: number;
|
|
66
|
+
}
|
|
67
|
+
interface CartPayload {
|
|
68
|
+
cart_id: string;
|
|
69
|
+
shopper_id: string;
|
|
70
|
+
site_id: string;
|
|
71
|
+
status: string;
|
|
72
|
+
items: CartItem[];
|
|
73
|
+
total: number;
|
|
74
|
+
currency: string;
|
|
75
|
+
item_count: number;
|
|
76
|
+
}
|
|
77
|
+
interface AkropolysConfig {
|
|
78
|
+
siteId?: string;
|
|
79
|
+
apiUrl?: string;
|
|
80
|
+
apiToken?: string;
|
|
81
|
+
shopperId?: string;
|
|
82
|
+
vertical?: 'commerce' | 'property' | 'motor' | 'blog' | string;
|
|
83
|
+
onCheckout?: (cart: CartPayload) => void;
|
|
84
|
+
onError?: (error: AkropolysError) => void;
|
|
85
|
+
authLoading?: boolean;
|
|
86
|
+
}
|
|
87
|
+
interface SearchRequest {
|
|
88
|
+
query: string;
|
|
89
|
+
siteId: string;
|
|
90
|
+
limit?: number;
|
|
91
|
+
}
|
|
92
|
+
interface SearchResult {
|
|
93
|
+
id: string;
|
|
94
|
+
score: number;
|
|
95
|
+
product: Product;
|
|
96
|
+
}
|
|
97
|
+
interface SearchResponse {
|
|
98
|
+
results: SearchResult[];
|
|
99
|
+
query: string;
|
|
100
|
+
}
|
|
101
|
+
interface IngestResponse {
|
|
102
|
+
success: boolean;
|
|
103
|
+
message?: string;
|
|
104
|
+
count?: number;
|
|
105
|
+
}
|
|
106
|
+
interface AkropolysError {
|
|
107
|
+
status: number;
|
|
108
|
+
message: string;
|
|
109
|
+
}
|
|
110
|
+
interface AkropolysTheme {
|
|
111
|
+
primaryColor?: string;
|
|
112
|
+
backgroundColor?: string;
|
|
113
|
+
textColor?: string;
|
|
114
|
+
fontFamily?: string;
|
|
115
|
+
borderRadius?: string;
|
|
116
|
+
}
|
|
117
|
+
interface CheckoutConfig {
|
|
118
|
+
payment_methods: Record<string, {
|
|
119
|
+
enabled: boolean;
|
|
120
|
+
}>;
|
|
121
|
+
}
|
|
122
|
+
interface PaymentInitResponse {
|
|
123
|
+
merchantReference: string;
|
|
124
|
+
checkoutRequestId?: string;
|
|
125
|
+
}
|
|
126
|
+
interface PaymentStatusResponse {
|
|
127
|
+
status: 'PENDING' | 'COMPLETED' | 'FAILED';
|
|
128
|
+
message?: string;
|
|
129
|
+
}
|
|
130
|
+
type ChatAction = {
|
|
131
|
+
type: 'add_to_cart';
|
|
132
|
+
[key: string]: any;
|
|
133
|
+
} | {
|
|
134
|
+
type: 'remove_from_cart';
|
|
135
|
+
[key: string]: any;
|
|
136
|
+
} | {
|
|
137
|
+
type: 'clear_cart';
|
|
138
|
+
[key: string]: any;
|
|
139
|
+
} | {
|
|
140
|
+
type: 'view_cart';
|
|
141
|
+
[key: string]: any;
|
|
142
|
+
} | {
|
|
143
|
+
type: 'checkout';
|
|
144
|
+
[key: string]: any;
|
|
145
|
+
} | {
|
|
146
|
+
type: 'request_phone';
|
|
147
|
+
[key: string]: any;
|
|
148
|
+
} | {
|
|
149
|
+
type: 'awaiting_payment';
|
|
150
|
+
merchantReference?: string | null;
|
|
151
|
+
[key: string]: any;
|
|
152
|
+
} | {
|
|
153
|
+
type: string;
|
|
154
|
+
[key: string]: any;
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
declare class AkropolysAPI {
|
|
158
|
+
private apiUrl;
|
|
159
|
+
private siteId;
|
|
160
|
+
private apiToken;
|
|
161
|
+
private getShopperId?;
|
|
162
|
+
private getSessionId?;
|
|
163
|
+
private vertical?;
|
|
164
|
+
constructor(apiUrl: string, siteId: string, apiToken: string, getShopperId?: (() => string | undefined) | undefined, getSessionId?: (() => string | undefined) | undefined, vertical?: string | undefined);
|
|
165
|
+
private post;
|
|
166
|
+
ingest(product: Product): Promise<IngestResponse>;
|
|
167
|
+
ingestBatch(products: Product[]): Promise<IngestResponse>;
|
|
168
|
+
search(query: string, limit?: number): Promise<SearchResponse>;
|
|
169
|
+
searchVector(query: string, limit?: number): Promise<SearchResponse>;
|
|
170
|
+
searchAutocomplete(query: string, limit?: number): Promise<SearchResponse>;
|
|
171
|
+
chat(query: string, history?: Array<{
|
|
172
|
+
role: 'user' | 'assistant';
|
|
173
|
+
content: string;
|
|
174
|
+
}>): Promise<{
|
|
175
|
+
answer: string;
|
|
176
|
+
sources: any[];
|
|
177
|
+
intent?: string;
|
|
178
|
+
checkout?: CartPayload;
|
|
179
|
+
action?: any;
|
|
180
|
+
}>;
|
|
181
|
+
chatStream(query: string, history?: Array<{
|
|
182
|
+
role: 'user' | 'assistant';
|
|
183
|
+
content: string;
|
|
184
|
+
}>, signal?: AbortSignal): Promise<Response>;
|
|
185
|
+
private buildHeaders;
|
|
186
|
+
getCart(): Promise<CartPayload>;
|
|
187
|
+
clearCart(): Promise<CartPayload>;
|
|
188
|
+
checkoutCart(): Promise<CartPayload>;
|
|
189
|
+
getCheckoutConfig(): Promise<CheckoutConfig>;
|
|
190
|
+
initiatePayment(phoneNumber: string, email?: string, firstName?: string, lastName?: string): Promise<PaymentInitResponse>;
|
|
191
|
+
getPaymentStatus(ref: string): Promise<PaymentStatusResponse>;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
interface ChatMessage {
|
|
195
|
+
role: 'user' | 'assistant';
|
|
196
|
+
content: string;
|
|
197
|
+
cartSnapshot?: CartPayload;
|
|
198
|
+
actionType?: string;
|
|
199
|
+
}
|
|
200
|
+
interface ChatSource {
|
|
201
|
+
id?: string;
|
|
202
|
+
name: string;
|
|
203
|
+
price?: string;
|
|
204
|
+
currency?: string;
|
|
205
|
+
category?: string;
|
|
206
|
+
url?: string;
|
|
207
|
+
image?: string;
|
|
208
|
+
brand?: string;
|
|
209
|
+
availability?: string;
|
|
210
|
+
}
|
|
211
|
+
interface ChatMetadata {
|
|
212
|
+
intent: string;
|
|
213
|
+
sources: ChatSource[];
|
|
214
|
+
action?: ChatAction;
|
|
215
|
+
checkout?: CartPayload;
|
|
216
|
+
}
|
|
217
|
+
declare class KikuStream {
|
|
218
|
+
private listeners;
|
|
219
|
+
private aborted;
|
|
220
|
+
private responsePromise;
|
|
221
|
+
private abortController;
|
|
222
|
+
constructor(responsePromise: Promise<Response>, abortController: AbortController);
|
|
223
|
+
on(event: 'token' | 'meta' | 'done' | 'error', callback: Function): this;
|
|
224
|
+
off(event: 'token' | 'meta' | 'done' | 'error', callback: Function): this;
|
|
225
|
+
destroy(): void;
|
|
226
|
+
private emit;
|
|
227
|
+
private startReading;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
declare function setSDKDefaultVertical(v: string): void;
|
|
231
|
+
declare class AkropolysClient {
|
|
232
|
+
readonly api: AkropolysAPI;
|
|
233
|
+
readonly vertical: string;
|
|
234
|
+
private ingestQueue;
|
|
235
|
+
private ingestTimer;
|
|
236
|
+
private ingestedUrls;
|
|
237
|
+
private onlineHandler;
|
|
238
|
+
private shopperId?;
|
|
239
|
+
private sessionId;
|
|
240
|
+
private authLoading?;
|
|
241
|
+
onCheckout?: (cart: CartPayload) => void;
|
|
242
|
+
onError?: (error: AkropolysError) => void;
|
|
243
|
+
private static INGEST_CACHE_KEY;
|
|
244
|
+
private static INGEST_CACHE_TTL;
|
|
245
|
+
private loadIngestedCache;
|
|
246
|
+
private saveIngestedCache;
|
|
247
|
+
constructor(config: AkropolysConfig);
|
|
248
|
+
chat(query: string, history?: Array<{
|
|
249
|
+
role: 'user' | 'assistant';
|
|
250
|
+
content: string;
|
|
251
|
+
}>): KikuStream;
|
|
252
|
+
reRegister(): void;
|
|
253
|
+
setShopperId(id: string | undefined): void;
|
|
254
|
+
setAuthLoading(loading: boolean): void;
|
|
255
|
+
getShopperId(): string | undefined;
|
|
256
|
+
getSessionId(): string;
|
|
257
|
+
private initSession;
|
|
258
|
+
destroy(): void;
|
|
259
|
+
queueIngest(rawProduct: RawProductInput): Promise<void>;
|
|
260
|
+
queueIngestBatch(rawProducts: RawProductInput[]): Promise<void>;
|
|
261
|
+
private scheduleFlush;
|
|
262
|
+
private flushQueue;
|
|
263
|
+
}
|
|
264
|
+
declare function initAkropolys(config: AkropolysConfig): AkropolysClient;
|
|
265
|
+
declare function getAkropolysClient(): AkropolysClient;
|
|
266
|
+
|
|
267
|
+
interface AkropolysProviderProps extends AkropolysConfig {
|
|
268
|
+
children: React.ReactNode;
|
|
269
|
+
}
|
|
270
|
+
declare function AkropolysProvider({ siteId, apiUrl, apiToken, shopperId, vertical, authLoading, onCheckout, onError, children }: AkropolysProviderProps): React.JSX.Element;
|
|
271
|
+
declare function useAkropolysContext(): AkropolysClient;
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* @deprecated Use <AkropolysProvider> instead to avoid SSR issues.
|
|
275
|
+
*/
|
|
276
|
+
declare function useAkropolys(config: AkropolysConfig): AkropolysClient;
|
|
277
|
+
|
|
278
|
+
interface UseSearchReturn {
|
|
279
|
+
results: SearchResult[];
|
|
280
|
+
loading: boolean;
|
|
281
|
+
error: string | null;
|
|
282
|
+
search: (query: string, limit?: number) => Promise<void>;
|
|
283
|
+
clear: () => void;
|
|
284
|
+
}
|
|
285
|
+
declare function useSearch(): UseSearchReturn;
|
|
286
|
+
|
|
287
|
+
interface UseIngestReturn {
|
|
288
|
+
ingest: (product: RawProductInput) => void;
|
|
289
|
+
ingestBatch: (products: RawProductInput[]) => void;
|
|
290
|
+
/**
|
|
291
|
+
* @deprecated Ingest is fire-and-forget. This is always `false` and will be
|
|
292
|
+
* removed in the next major version. Remove it from your destructuring.
|
|
293
|
+
*/
|
|
294
|
+
loading: false;
|
|
295
|
+
/**
|
|
296
|
+
* @deprecated Ingest is fire-and-forget. This is always `null` and will be
|
|
297
|
+
* removed in the next major version. Remove it from your destructuring.
|
|
298
|
+
*/
|
|
299
|
+
error: null;
|
|
300
|
+
}
|
|
301
|
+
declare function useIngest(): UseIngestReturn;
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* useListIngest — drop this into any catalog or list page.
|
|
305
|
+
* It automatically ingests all items in the array, using a built-in
|
|
306
|
+
* component-lifecycle ref guard to prevent duplicate calls during mounts.
|
|
307
|
+
*
|
|
308
|
+
* @example
|
|
309
|
+
* export function CategoryPage({ products }) {
|
|
310
|
+
* useListIngest(products);
|
|
311
|
+
* return <ProductGrid products={products} />;
|
|
312
|
+
* }
|
|
313
|
+
*/
|
|
314
|
+
declare function useListIngest(products: RawProductInput[] | null | undefined): void;
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* usePageIngest — drop this into any product page component.
|
|
318
|
+
* The moment a customer's browser renders the page, the product is
|
|
319
|
+
* automatically captured and queued for ingestion into the vector index.
|
|
320
|
+
*
|
|
321
|
+
* No configuration needed beyond <AkropolysProvider> in your layout.
|
|
322
|
+
*
|
|
323
|
+
* @example
|
|
324
|
+
* // Product detail page — Next.js or React
|
|
325
|
+
* export function ProductPage({ product }) {
|
|
326
|
+
* usePageIngest({
|
|
327
|
+
* name: product.title,
|
|
328
|
+
* price: product.price,
|
|
329
|
+
* url: window.location.href,
|
|
330
|
+
* images: [product.thumbnail],
|
|
331
|
+
* category: product.category,
|
|
332
|
+
* });
|
|
333
|
+
* return <div>...</div>;
|
|
334
|
+
* }
|
|
335
|
+
*/
|
|
336
|
+
declare function usePageIngest(product: RawProductInput | null | undefined): void;
|
|
337
|
+
|
|
338
|
+
interface UseKikuOptions {
|
|
339
|
+
initialMessages?: ChatMessage[];
|
|
340
|
+
onToken?: (token: string) => void;
|
|
341
|
+
onMeta?: (meta: any) => void;
|
|
342
|
+
onDone?: (fullMessage: string) => void;
|
|
343
|
+
onError?: (error: Error) => void;
|
|
344
|
+
}
|
|
345
|
+
interface UseKikuReturn {
|
|
346
|
+
messages: ChatMessage[];
|
|
347
|
+
sources: ChatSource[];
|
|
348
|
+
loading: boolean;
|
|
349
|
+
streaming: boolean;
|
|
350
|
+
error: string | null;
|
|
351
|
+
lastAction: ChatAction | null;
|
|
352
|
+
lastIntent: string | null;
|
|
353
|
+
send: (query: string, displayQuery?: string) => Promise<void>;
|
|
354
|
+
reset: () => void;
|
|
355
|
+
}
|
|
356
|
+
declare function useKiku(options?: UseKikuOptions): UseKikuReturn;
|
|
357
|
+
|
|
358
|
+
declare function useCart(): {
|
|
359
|
+
cart: CartPayload | null;
|
|
360
|
+
loading: boolean;
|
|
361
|
+
fetchCart: () => Promise<void>;
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
interface UsePaymentPollingProps {
|
|
365
|
+
client: AkropolysAPI;
|
|
366
|
+
merchantReference: string | null;
|
|
367
|
+
onSuccess?: () => void;
|
|
368
|
+
onFailure?: (errorMsg?: string) => void;
|
|
369
|
+
intervalMs?: number;
|
|
370
|
+
timeoutMs?: number;
|
|
371
|
+
}
|
|
372
|
+
declare function usePaymentPolling({ client, merchantReference, onSuccess, onFailure, intervalMs, timeoutMs, }: UsePaymentPollingProps): {
|
|
373
|
+
status: "PENDING" | "COMPLETED" | "FAILED" | "IDLE";
|
|
374
|
+
error: string | null;
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
export { AkropolysAPI, AkropolysClient, type AkropolysConfig, type AkropolysError, AkropolysProvider, type AkropolysTheme, type CartItem, type CartPayload, type ChatAction, type ChatMessage, type ChatMetadata, type ChatSource, type CheckoutConfig, type IngestResponse, KikuStream, type PaymentInitResponse, type PaymentStatusResponse, type Product, type RawProductInput, type SearchRequest, type SearchResponse, type SearchResult, type UsePaymentPollingProps, getAkropolysClient, initAkropolys, setSDKDefaultVertical, useAkropolys, useAkropolysContext, useCart, useIngest, useKiku, useListIngest, usePageIngest, usePaymentPolling, useSearch };
|