@proveanything/smartlinks 1.3.25 → 1.3.27
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 +48 -0
- package/dist/api/ai.d.ts +6 -380
- package/dist/api/ai.js +15 -15
- package/dist/api/index.d.ts +0 -1
- package/dist/docs/API_SUMMARY.md +2259 -2271
- package/dist/docs/utils.md +651 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/types/ai.d.ts +379 -0
- package/dist/types/ai.js +5 -0
- package/dist/types/collection.d.ts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/utils/conditions.d.ts +287 -0
- package/dist/utils/conditions.js +453 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.js +7 -0
- package/dist/utils/paths.d.ts +82 -0
- package/dist/utils/paths.js +164 -0
- package/docs/API_SUMMARY.md +2259 -2271
- package/docs/utils.md +651 -0
- package/package.json +1 -1
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI domain types
|
|
3
|
+
*/
|
|
4
|
+
/** Content part for multimodal messages */
|
|
5
|
+
export interface ContentPart {
|
|
6
|
+
type: 'text' | 'image_url';
|
|
7
|
+
text?: string;
|
|
8
|
+
image_url?: {
|
|
9
|
+
url: string;
|
|
10
|
+
detail?: 'auto' | 'low' | 'high';
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/** Function call representation */
|
|
14
|
+
export interface FunctionCall {
|
|
15
|
+
name: string;
|
|
16
|
+
arguments: string;
|
|
17
|
+
}
|
|
18
|
+
/** Tool call representation */
|
|
19
|
+
export interface ToolCall {
|
|
20
|
+
id: string;
|
|
21
|
+
type: 'function';
|
|
22
|
+
function: {
|
|
23
|
+
name: string;
|
|
24
|
+
arguments: string;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/** Chat message with role and content */
|
|
28
|
+
export interface ChatMessage {
|
|
29
|
+
role: 'system' | 'user' | 'assistant' | 'function' | 'tool';
|
|
30
|
+
content: string | ContentPart[];
|
|
31
|
+
name?: string;
|
|
32
|
+
function_call?: FunctionCall;
|
|
33
|
+
tool_calls?: ToolCall[];
|
|
34
|
+
tool_call_id?: string;
|
|
35
|
+
}
|
|
36
|
+
/** Tool/Function definition */
|
|
37
|
+
export interface ToolDefinition {
|
|
38
|
+
type: 'function';
|
|
39
|
+
function: {
|
|
40
|
+
name: string;
|
|
41
|
+
description: string;
|
|
42
|
+
parameters: {
|
|
43
|
+
type: 'object';
|
|
44
|
+
properties: Record<string, {
|
|
45
|
+
type: string;
|
|
46
|
+
description?: string;
|
|
47
|
+
enum?: string[];
|
|
48
|
+
}>;
|
|
49
|
+
required?: string[];
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/** Chat completion request */
|
|
54
|
+
export interface ChatCompletionRequest {
|
|
55
|
+
messages: ChatMessage[];
|
|
56
|
+
model?: string;
|
|
57
|
+
stream?: boolean;
|
|
58
|
+
tools?: ToolDefinition[];
|
|
59
|
+
tool_choice?: 'none' | 'auto' | 'required' | {
|
|
60
|
+
type: 'function';
|
|
61
|
+
function: {
|
|
62
|
+
name: string;
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
temperature?: number;
|
|
66
|
+
max_tokens?: number;
|
|
67
|
+
top_p?: number;
|
|
68
|
+
frequency_penalty?: number;
|
|
69
|
+
presence_penalty?: number;
|
|
70
|
+
response_format?: {
|
|
71
|
+
type: 'text' | 'json_object';
|
|
72
|
+
};
|
|
73
|
+
user?: string;
|
|
74
|
+
}
|
|
75
|
+
/** Chat completion choice */
|
|
76
|
+
export interface ChatCompletionChoice {
|
|
77
|
+
index: number;
|
|
78
|
+
message: ChatMessage;
|
|
79
|
+
finish_reason: 'stop' | 'length' | 'function_call' | 'tool_calls' | 'content_filter' | null;
|
|
80
|
+
}
|
|
81
|
+
/** Chat completion response */
|
|
82
|
+
export interface ChatCompletionResponse {
|
|
83
|
+
id: string;
|
|
84
|
+
object: 'chat.completion';
|
|
85
|
+
created: number;
|
|
86
|
+
model: string;
|
|
87
|
+
choices: ChatCompletionChoice[];
|
|
88
|
+
usage: {
|
|
89
|
+
prompt_tokens: number;
|
|
90
|
+
completion_tokens: number;
|
|
91
|
+
total_tokens: number;
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/** Streaming chunk */
|
|
95
|
+
export interface ChatCompletionChunk {
|
|
96
|
+
id: string;
|
|
97
|
+
object: 'chat.completion.chunk';
|
|
98
|
+
created: number;
|
|
99
|
+
model: string;
|
|
100
|
+
choices: Array<{
|
|
101
|
+
index: number;
|
|
102
|
+
delta: Partial<ChatMessage>;
|
|
103
|
+
finish_reason: string | null;
|
|
104
|
+
}>;
|
|
105
|
+
}
|
|
106
|
+
/** AI Model information */
|
|
107
|
+
export interface AIModel {
|
|
108
|
+
id: string;
|
|
109
|
+
provider: 'gemini' | 'openai';
|
|
110
|
+
modelId: string;
|
|
111
|
+
name: string;
|
|
112
|
+
description: string;
|
|
113
|
+
capabilities: Array<'text' | 'vision' | 'audio' | 'code'>;
|
|
114
|
+
contextWindow: number;
|
|
115
|
+
pricing: {
|
|
116
|
+
input: number;
|
|
117
|
+
output: number;
|
|
118
|
+
cached?: number;
|
|
119
|
+
};
|
|
120
|
+
features: string[];
|
|
121
|
+
recommended?: string;
|
|
122
|
+
}
|
|
123
|
+
/** Document chunk with embedding */
|
|
124
|
+
export interface DocumentChunk {
|
|
125
|
+
text: string;
|
|
126
|
+
embedding: number[];
|
|
127
|
+
metadata: {
|
|
128
|
+
chunkIndex: number;
|
|
129
|
+
documentId: string;
|
|
130
|
+
[key: string]: any;
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
/** Index document request */
|
|
134
|
+
export interface IndexDocumentRequest {
|
|
135
|
+
productId: string;
|
|
136
|
+
text?: string;
|
|
137
|
+
documentUrl?: string;
|
|
138
|
+
metadata?: Record<string, any>;
|
|
139
|
+
chunkSize?: number;
|
|
140
|
+
overlap?: number;
|
|
141
|
+
provider?: 'openai' | 'gemini';
|
|
142
|
+
}
|
|
143
|
+
/** Index document response */
|
|
144
|
+
export interface IndexDocumentResponse {
|
|
145
|
+
success: boolean;
|
|
146
|
+
productId: string;
|
|
147
|
+
documentId: string;
|
|
148
|
+
chunks: number;
|
|
149
|
+
metadata: {
|
|
150
|
+
textLength: number;
|
|
151
|
+
chunkSize: number;
|
|
152
|
+
overlap: number;
|
|
153
|
+
embeddingDimensions: number;
|
|
154
|
+
};
|
|
155
|
+
sample?: {
|
|
156
|
+
text: string;
|
|
157
|
+
chunkIndex: number;
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
/** Configure assistant request */
|
|
161
|
+
export interface ConfigureAssistantRequest {
|
|
162
|
+
productId: string;
|
|
163
|
+
systemPrompt?: string;
|
|
164
|
+
model?: string;
|
|
165
|
+
maxTokensPerResponse?: number;
|
|
166
|
+
temperature?: number;
|
|
167
|
+
rateLimitPerUser?: number;
|
|
168
|
+
allowedTopics?: string[];
|
|
169
|
+
customInstructions?: {
|
|
170
|
+
tone?: string;
|
|
171
|
+
additionalRules?: string;
|
|
172
|
+
[key: string]: any;
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
/** Configure assistant response */
|
|
176
|
+
export interface ConfigureAssistantResponse {
|
|
177
|
+
success: boolean;
|
|
178
|
+
configuration: {
|
|
179
|
+
productId: string;
|
|
180
|
+
systemPrompt: string;
|
|
181
|
+
model: string;
|
|
182
|
+
maxTokensPerResponse: number;
|
|
183
|
+
temperature: number;
|
|
184
|
+
rateLimitPerUser: number;
|
|
185
|
+
allowedTopics: string[];
|
|
186
|
+
customInstructions?: Record<string, any>;
|
|
187
|
+
updatedAt: string;
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
/** Public chat request */
|
|
191
|
+
export interface PublicChatRequest {
|
|
192
|
+
productId: string;
|
|
193
|
+
userId: string;
|
|
194
|
+
message: string;
|
|
195
|
+
sessionId?: string;
|
|
196
|
+
stream?: boolean;
|
|
197
|
+
}
|
|
198
|
+
/** Public chat response */
|
|
199
|
+
export interface PublicChatResponse {
|
|
200
|
+
message: string;
|
|
201
|
+
sessionId: string;
|
|
202
|
+
usage: {
|
|
203
|
+
prompt_tokens: number;
|
|
204
|
+
completion_tokens: number;
|
|
205
|
+
total_tokens: number;
|
|
206
|
+
};
|
|
207
|
+
context?: {
|
|
208
|
+
chunksUsed: number;
|
|
209
|
+
topSimilarity: number;
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
/** Session information */
|
|
213
|
+
export interface Session {
|
|
214
|
+
sessionId: string;
|
|
215
|
+
productId: string;
|
|
216
|
+
userId: string;
|
|
217
|
+
messageCount: number;
|
|
218
|
+
createdAt: string;
|
|
219
|
+
lastActivityAt: string;
|
|
220
|
+
messages: ChatMessage[];
|
|
221
|
+
}
|
|
222
|
+
/** Rate limit status */
|
|
223
|
+
export interface RateLimitStatus {
|
|
224
|
+
used: number;
|
|
225
|
+
remaining: number;
|
|
226
|
+
resetAt: string;
|
|
227
|
+
}
|
|
228
|
+
/** Session statistics */
|
|
229
|
+
export interface SessionStatistics {
|
|
230
|
+
totalSessions: number;
|
|
231
|
+
activeSessions: number;
|
|
232
|
+
totalMessages: number;
|
|
233
|
+
rateLimitedUsers: number;
|
|
234
|
+
}
|
|
235
|
+
/** Voice session request */
|
|
236
|
+
export interface VoiceSessionRequest {
|
|
237
|
+
productId: string;
|
|
238
|
+
userId: string;
|
|
239
|
+
collectionId: string;
|
|
240
|
+
settings?: {
|
|
241
|
+
voice?: string;
|
|
242
|
+
language?: string;
|
|
243
|
+
model?: string;
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
/** Voice session response */
|
|
247
|
+
export interface VoiceSessionResponse {
|
|
248
|
+
token: string;
|
|
249
|
+
systemInstruction: string;
|
|
250
|
+
expiresAt: string;
|
|
251
|
+
productName: string;
|
|
252
|
+
}
|
|
253
|
+
/** Ephemeral token request */
|
|
254
|
+
export interface EphemeralTokenRequest {
|
|
255
|
+
settings?: {
|
|
256
|
+
ttl?: number;
|
|
257
|
+
voice?: string;
|
|
258
|
+
language?: string;
|
|
259
|
+
model?: string;
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
/** Ephemeral token response */
|
|
263
|
+
export interface EphemeralTokenResponse {
|
|
264
|
+
token: string;
|
|
265
|
+
expiresAt: string;
|
|
266
|
+
}
|
|
267
|
+
/** Transcription response */
|
|
268
|
+
export interface TranscriptionResponse {
|
|
269
|
+
text: string;
|
|
270
|
+
}
|
|
271
|
+
/** TTS request */
|
|
272
|
+
export interface TTSRequest {
|
|
273
|
+
text: string;
|
|
274
|
+
voice?: 'alloy' | 'echo' | 'fable' | 'onyx' | 'nova' | 'shimmer';
|
|
275
|
+
speed?: number;
|
|
276
|
+
format?: 'mp3' | 'opus' | 'aac' | 'flac';
|
|
277
|
+
}
|
|
278
|
+
/** Podcast generation request */
|
|
279
|
+
export interface GeneratePodcastRequest {
|
|
280
|
+
productId: string;
|
|
281
|
+
documentText?: string;
|
|
282
|
+
duration?: number;
|
|
283
|
+
style?: 'casual' | 'professional' | 'educational' | 'entertaining';
|
|
284
|
+
voices?: {
|
|
285
|
+
host1?: string;
|
|
286
|
+
host2?: string;
|
|
287
|
+
};
|
|
288
|
+
includeAudio?: boolean;
|
|
289
|
+
language?: string;
|
|
290
|
+
customInstructions?: string;
|
|
291
|
+
}
|
|
292
|
+
/** Podcast script */
|
|
293
|
+
export interface PodcastScript {
|
|
294
|
+
title: string;
|
|
295
|
+
description: string;
|
|
296
|
+
segments: Array<{
|
|
297
|
+
speaker: 'host1' | 'host2';
|
|
298
|
+
text: string;
|
|
299
|
+
timestamp?: number;
|
|
300
|
+
duration?: number;
|
|
301
|
+
}>;
|
|
302
|
+
}
|
|
303
|
+
/** Podcast generation response */
|
|
304
|
+
export interface GeneratePodcastResponse {
|
|
305
|
+
success: boolean;
|
|
306
|
+
podcastId: string;
|
|
307
|
+
script: PodcastScript;
|
|
308
|
+
audio?: {
|
|
309
|
+
host1Url?: string;
|
|
310
|
+
host2Url?: string;
|
|
311
|
+
mixedUrl?: string;
|
|
312
|
+
};
|
|
313
|
+
metadata: {
|
|
314
|
+
duration: number;
|
|
315
|
+
wordCount: number;
|
|
316
|
+
generatedAt: string;
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
/** Podcast status */
|
|
320
|
+
export interface PodcastStatus {
|
|
321
|
+
podcastId: string;
|
|
322
|
+
status: 'generating_script' | 'generating_audio' | 'mixing' | 'completed' | 'failed';
|
|
323
|
+
progress: number;
|
|
324
|
+
estimatedTimeRemaining?: number;
|
|
325
|
+
error?: string;
|
|
326
|
+
result?: GeneratePodcastResponse;
|
|
327
|
+
}
|
|
328
|
+
/** Request shape for AI generateContent calls */
|
|
329
|
+
export interface AIGenerateContentRequest {
|
|
330
|
+
/** The prompt or message contents sent to the AI */
|
|
331
|
+
contents: string | any;
|
|
332
|
+
/** Desired MIME type of the response payload (e.g. 'application/json', 'text/plain') */
|
|
333
|
+
responseMimeType?: string;
|
|
334
|
+
/** Optional system instruction or system prompt to steer the model */
|
|
335
|
+
systemInstruction?: string;
|
|
336
|
+
/** AI provider identifier (e.g. 'openai', 'google', 'anthropic') */
|
|
337
|
+
provider?: string;
|
|
338
|
+
/** The model name to use (e.g. 'gpt-4o', 'gemini-1.5-pro') */
|
|
339
|
+
model?: string;
|
|
340
|
+
/** Allow passing additional provider/model-specific options */
|
|
341
|
+
[key: string]: any;
|
|
342
|
+
}
|
|
343
|
+
/** Request shape for AI generateImage calls (admin) */
|
|
344
|
+
export interface AIGenerateImageRequest {
|
|
345
|
+
/** Text prompt describing the desired image */
|
|
346
|
+
prompt: string;
|
|
347
|
+
/** AI provider identifier (e.g. 'openai', 'google', 'stability') */
|
|
348
|
+
provider?: string;
|
|
349
|
+
/** Optional model name to use for image generation */
|
|
350
|
+
model?: string;
|
|
351
|
+
/** Requested image size, e.g. '1024x1024' */
|
|
352
|
+
size?: string;
|
|
353
|
+
/** Additional provider/model-specific options */
|
|
354
|
+
[key: string]: any;
|
|
355
|
+
}
|
|
356
|
+
/** Request shape for AI searchPhotos calls (admin -> Unsplash proxy) */
|
|
357
|
+
export interface AISearchPhotosRequest {
|
|
358
|
+
/** Search query keyword(s) */
|
|
359
|
+
query: string;
|
|
360
|
+
/** Number of results to return per page (e.g. 1) */
|
|
361
|
+
per_page?: number;
|
|
362
|
+
/** Desired orientation of photos */
|
|
363
|
+
orientation?: 'landscape' | 'portrait' | 'squarish';
|
|
364
|
+
/** Additional provider-specific options */
|
|
365
|
+
[key: string]: any;
|
|
366
|
+
}
|
|
367
|
+
/** Single photo item returned by searchPhotos */
|
|
368
|
+
export interface AISearchPhotosPhoto {
|
|
369
|
+
/** Direct image URL */
|
|
370
|
+
url: string;
|
|
371
|
+
/** Alt text/description for accessibility */
|
|
372
|
+
alt?: string;
|
|
373
|
+
/** Photographer display name */
|
|
374
|
+
photographer?: string;
|
|
375
|
+
/** Link to the photographer profile */
|
|
376
|
+
photographerUrl?: string;
|
|
377
|
+
/** Allow extra fields */
|
|
378
|
+
[key: string]: any;
|
|
379
|
+
}
|
package/dist/types/ai.js
ADDED
|
@@ -62,6 +62,7 @@ export interface Collection {
|
|
|
62
62
|
shortId: string;
|
|
63
63
|
/** if dark mode is enabled for this collection */
|
|
64
64
|
dark?: boolean;
|
|
65
|
+
portalUrl?: string;
|
|
65
66
|
}
|
|
66
67
|
export type CollectionResponse = Collection;
|
|
67
68
|
export type CollectionCreateRequest = Omit<Collection, 'id' | 'shortId'>;
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/index.js
CHANGED
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Geographic region definitions for country-based conditions
|
|
3
|
+
*/
|
|
4
|
+
export declare const REGION_COUNTRIES: {
|
|
5
|
+
readonly eu: readonly ["AT", "BE", "BG", "HR", "CY", "CZ", "DK", "EE", "FI", "FR", "DE", "GR", "HU", "IE", "IT", "LV", "LT", "LU", "MT", "NL", "PL", "PT", "RO", "SK", "SI", "ES", "SE"];
|
|
6
|
+
readonly eea: readonly ["AT", "BE", "BG", "HR", "CY", "CZ", "DK", "EE", "FI", "FR", "DE", "GR", "HU", "IE", "IT", "LV", "LT", "LU", "MT", "NL", "PL", "PT", "RO", "SK", "SI", "ES", "SE", "IS", "LI", "NO"];
|
|
7
|
+
readonly uk: readonly ["GB"];
|
|
8
|
+
readonly northamerica: readonly ["US", "CA", "MX"];
|
|
9
|
+
readonly asiapacific: readonly ["AU", "NZ", "JP", "KR", "SG", "HK", "TW", "TH", "MY", "PH", "ID", "VN", "IN"];
|
|
10
|
+
};
|
|
11
|
+
export type RegionKey = keyof typeof REGION_COUNTRIES;
|
|
12
|
+
/**
|
|
13
|
+
* Base condition structure
|
|
14
|
+
*/
|
|
15
|
+
export interface BaseCondition {
|
|
16
|
+
type: string;
|
|
17
|
+
contains?: boolean;
|
|
18
|
+
passes?: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Country-based condition
|
|
22
|
+
*/
|
|
23
|
+
export interface CountryCondition extends BaseCondition {
|
|
24
|
+
type: 'country';
|
|
25
|
+
countries?: string[];
|
|
26
|
+
useRegions?: boolean;
|
|
27
|
+
regions?: RegionKey[];
|
|
28
|
+
contains: boolean;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Version-based condition
|
|
32
|
+
*/
|
|
33
|
+
export interface VersionCondition extends BaseCondition {
|
|
34
|
+
type: 'version';
|
|
35
|
+
versions: string[];
|
|
36
|
+
contains: boolean;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Device/platform condition
|
|
40
|
+
*/
|
|
41
|
+
export interface DeviceCondition extends BaseCondition {
|
|
42
|
+
type: 'device';
|
|
43
|
+
displays: Array<'android' | 'ios' | 'win' | 'mac' | 'desktop' | 'mobile'>;
|
|
44
|
+
contains: boolean;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Nested condition reference
|
|
48
|
+
*/
|
|
49
|
+
export interface NestedCondition extends BaseCondition {
|
|
50
|
+
type: 'condition';
|
|
51
|
+
conditionId: string;
|
|
52
|
+
passes: boolean;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* User type condition
|
|
56
|
+
*/
|
|
57
|
+
export interface UserCondition extends BaseCondition {
|
|
58
|
+
type: 'user';
|
|
59
|
+
userType: 'valid' | 'invalid' | 'owner' | 'admin' | 'group';
|
|
60
|
+
groupId?: string;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Product-based condition
|
|
64
|
+
*/
|
|
65
|
+
export interface ProductCondition extends BaseCondition {
|
|
66
|
+
type: 'product';
|
|
67
|
+
productIds: string[];
|
|
68
|
+
contains: boolean;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Tag-based condition
|
|
72
|
+
*/
|
|
73
|
+
export interface TagCondition extends BaseCondition {
|
|
74
|
+
type: 'tag';
|
|
75
|
+
tags: string[];
|
|
76
|
+
contains: boolean;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Date-based condition
|
|
80
|
+
*/
|
|
81
|
+
export interface DateCondition extends BaseCondition {
|
|
82
|
+
type: 'date';
|
|
83
|
+
dateTest: 'before' | 'after' | 'between';
|
|
84
|
+
beforeDate?: string;
|
|
85
|
+
afterDate?: string;
|
|
86
|
+
rangeDate?: [string, string];
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Geofence condition
|
|
90
|
+
*/
|
|
91
|
+
export interface GeofenceCondition extends BaseCondition {
|
|
92
|
+
type: 'geofence';
|
|
93
|
+
top: number;
|
|
94
|
+
bottom: number;
|
|
95
|
+
left: number;
|
|
96
|
+
right: number;
|
|
97
|
+
contains: boolean;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Value comparison condition
|
|
101
|
+
*/
|
|
102
|
+
export interface ValueCondition extends BaseCondition {
|
|
103
|
+
type: 'value';
|
|
104
|
+
field: string;
|
|
105
|
+
fieldType: 'string' | 'boolean' | 'integer' | 'number';
|
|
106
|
+
validationType: 'equal' | 'not' | 'greater' | 'less';
|
|
107
|
+
value: string | number | boolean;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Item status condition
|
|
111
|
+
*/
|
|
112
|
+
export interface ItemStatusCondition extends BaseCondition {
|
|
113
|
+
type: 'itemStatus';
|
|
114
|
+
statusType: 'isClaimable' | 'notClaimable' | 'noProof' | 'hasProof' | 'isVirtual' | 'notVirtual';
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Union of all condition types
|
|
118
|
+
*/
|
|
119
|
+
export type Condition = CountryCondition | VersionCondition | DeviceCondition | NestedCondition | UserCondition | ProductCondition | TagCondition | DateCondition | GeofenceCondition | ValueCondition | ItemStatusCondition;
|
|
120
|
+
/**
|
|
121
|
+
* Condition set that combines multiple conditions
|
|
122
|
+
*/
|
|
123
|
+
export interface ConditionSet {
|
|
124
|
+
id?: string;
|
|
125
|
+
type?: 'and' | 'or';
|
|
126
|
+
conditions?: Condition[];
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* User location information
|
|
130
|
+
*/
|
|
131
|
+
export interface UserLocation {
|
|
132
|
+
country?: string;
|
|
133
|
+
latitude?: number;
|
|
134
|
+
longitude?: number;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Platform detection information
|
|
138
|
+
*/
|
|
139
|
+
export interface PlatformInfo {
|
|
140
|
+
android?: boolean;
|
|
141
|
+
ios?: boolean;
|
|
142
|
+
win?: boolean;
|
|
143
|
+
mac?: boolean;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Statistics/tracking information
|
|
147
|
+
*/
|
|
148
|
+
export interface StatsInfo {
|
|
149
|
+
version?: string | null;
|
|
150
|
+
platform?: PlatformInfo;
|
|
151
|
+
mobile?: boolean;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* User information for condition validation
|
|
155
|
+
*/
|
|
156
|
+
export interface UserInfo {
|
|
157
|
+
valid: boolean;
|
|
158
|
+
uid?: string;
|
|
159
|
+
location?: UserLocation;
|
|
160
|
+
groups?: string[];
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Product information for condition validation
|
|
164
|
+
*/
|
|
165
|
+
export interface ProductInfo {
|
|
166
|
+
id: string;
|
|
167
|
+
tags?: Record<string, any>;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Proof information for condition validation
|
|
171
|
+
*/
|
|
172
|
+
export interface ProofInfo {
|
|
173
|
+
id?: string;
|
|
174
|
+
userId?: string;
|
|
175
|
+
claimable?: boolean;
|
|
176
|
+
virtual?: boolean;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Collection information for condition validation
|
|
180
|
+
*/
|
|
181
|
+
export interface CollectionInfo {
|
|
182
|
+
id: string;
|
|
183
|
+
roles?: Record<string, any>;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Parameters for condition validation
|
|
187
|
+
*/
|
|
188
|
+
export interface ConditionParams {
|
|
189
|
+
/** The condition set to validate (if not using conditionId) */
|
|
190
|
+
condition?: ConditionSet;
|
|
191
|
+
/** ID of a condition to load and validate */
|
|
192
|
+
conditionId?: string;
|
|
193
|
+
/** Stack to prevent infinite recursion in nested conditions */
|
|
194
|
+
conditionStack?: string[];
|
|
195
|
+
/** User information */
|
|
196
|
+
user?: UserInfo;
|
|
197
|
+
/** Product information */
|
|
198
|
+
product?: ProductInfo;
|
|
199
|
+
/** Proof information */
|
|
200
|
+
proof?: ProofInfo;
|
|
201
|
+
/** Collection information */
|
|
202
|
+
collection?: CollectionInfo;
|
|
203
|
+
/** Statistics/tracking information */
|
|
204
|
+
stats?: StatsInfo;
|
|
205
|
+
/** Function to fetch conditions by ID (optional) */
|
|
206
|
+
fetchCondition?: (collectionId: string, conditionId: string) => Promise<ConditionSet | null>;
|
|
207
|
+
/** Function to get user's current location (optional) */
|
|
208
|
+
getLocation?: () => Promise<{
|
|
209
|
+
latitude: number;
|
|
210
|
+
longitude: number;
|
|
211
|
+
}>;
|
|
212
|
+
/** Any additional custom fields for value-based conditions */
|
|
213
|
+
[key: string]: any;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Validates if a condition set passes based on the provided parameters.
|
|
217
|
+
*
|
|
218
|
+
* Conditions are commonly used for controlling page rendering, content visibility,
|
|
219
|
+
* and feature access based on various criteria like geography, device type, user status, etc.
|
|
220
|
+
*
|
|
221
|
+
* Supports multiple condition types:
|
|
222
|
+
* - **country** - Geographic restrictions (countries or regions like EU, EEA)
|
|
223
|
+
* - **version** - Version-based display (e.g., A/B testing)
|
|
224
|
+
* - **device** - Platform/device targeting (iOS, Android, desktop, mobile)
|
|
225
|
+
* - **user** - User authentication status (logged in, owner, admin)
|
|
226
|
+
* - **product** - Product-specific conditions
|
|
227
|
+
* - **tag** - Product tag-based conditions
|
|
228
|
+
* - **date** - Time-based conditions (before, after, between dates)
|
|
229
|
+
* - **geofence** - Location-based restrictions
|
|
230
|
+
* - **value** - Custom field comparisons
|
|
231
|
+
* - **itemStatus** - Proof/item status checks (claimable, virtual, etc.)
|
|
232
|
+
* - **condition** - Nested condition references
|
|
233
|
+
*
|
|
234
|
+
* Conditions can be combined with AND or OR logic.
|
|
235
|
+
*
|
|
236
|
+
* @param params - Validation parameters including condition and context
|
|
237
|
+
* @returns Promise that resolves to true if condition passes, false otherwise
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* ```typescript
|
|
241
|
+
* import { validateCondition } from '@proveanything/smartlinks'
|
|
242
|
+
*
|
|
243
|
+
* // Simple country check
|
|
244
|
+
* const canShow = await validateCondition({
|
|
245
|
+
* condition: {
|
|
246
|
+
* type: 'and',
|
|
247
|
+
* conditions: [{
|
|
248
|
+
* type: 'country',
|
|
249
|
+
* useRegions: true,
|
|
250
|
+
* regions: ['eu'],
|
|
251
|
+
* contains: true
|
|
252
|
+
* }]
|
|
253
|
+
* },
|
|
254
|
+
* user: { valid: true, location: { country: 'DE' } }
|
|
255
|
+
* })
|
|
256
|
+
*
|
|
257
|
+
* // Multiple conditions with AND logic
|
|
258
|
+
* const result = await validateCondition({
|
|
259
|
+
* condition: {
|
|
260
|
+
* type: 'and',
|
|
261
|
+
* conditions: [
|
|
262
|
+
* { type: 'user', userType: 'valid' },
|
|
263
|
+
* { type: 'device', displays: ['mobile'], contains: true }
|
|
264
|
+
* ]
|
|
265
|
+
* },
|
|
266
|
+
* user: { valid: true },
|
|
267
|
+
* stats: { mobile: true }
|
|
268
|
+
* })
|
|
269
|
+
*
|
|
270
|
+
* // Date-based condition
|
|
271
|
+
* const isActive = await validateCondition({
|
|
272
|
+
* condition: {
|
|
273
|
+
* type: 'and',
|
|
274
|
+
* conditions: [{
|
|
275
|
+
* type: 'date',
|
|
276
|
+
* dateTest: 'between',
|
|
277
|
+
* rangeDate: ['2026-01-01', '2026-12-31']
|
|
278
|
+
* }]
|
|
279
|
+
* }
|
|
280
|
+
* })
|
|
281
|
+
* ```
|
|
282
|
+
*/
|
|
283
|
+
export declare function validateCondition(params: ConditionParams): Promise<boolean>;
|
|
284
|
+
/**
|
|
285
|
+
* Clear the condition cache
|
|
286
|
+
*/
|
|
287
|
+
export declare function clearConditionCache(): void;
|