@ekodb/ekodb-client 0.16.0 → 0.18.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/dist/functions.d.ts +457 -4
- package/dist/functions.js +312 -0
- package/dist/functions.test.d.ts +9 -0
- package/dist/functions.test.js +542 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/package.json +1 -1
- package/src/functions.test.ts +726 -0
- package/src/functions.ts +766 -4
- package/src/index.ts +2 -1
package/dist/functions.d.ts
CHANGED
|
@@ -15,6 +15,19 @@ export interface UserFunction {
|
|
|
15
15
|
tags?: string[];
|
|
16
16
|
created_at?: string;
|
|
17
17
|
updated_at?: string;
|
|
18
|
+
/**
|
|
19
|
+
* REST method this function answers — `"GET"`, `"POST"`, etc.
|
|
20
|
+
* Pair with `http_path` to expose the function under the
|
|
21
|
+
* path-routed dispatcher at `/api/route/{path}`.
|
|
22
|
+
* Requires ekoDB >= 0.42.0.
|
|
23
|
+
*/
|
|
24
|
+
http_method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
25
|
+
/**
|
|
26
|
+
* REST path pattern (e.g. `"/users/:id"`). Path segments
|
|
27
|
+
* starting with `:` are extracted into the function's params
|
|
28
|
+
* map at call time. Requires ekoDB >= 0.42.0.
|
|
29
|
+
*/
|
|
30
|
+
http_path?: string;
|
|
18
31
|
}
|
|
19
32
|
export interface ParameterDefinition {
|
|
20
33
|
required: boolean;
|
|
@@ -207,6 +220,233 @@ export type FunctionStageConfig = {
|
|
|
207
220
|
timeout_seconds?: number;
|
|
208
221
|
output_field?: string;
|
|
209
222
|
collection?: string;
|
|
223
|
+
} | {
|
|
224
|
+
/**
|
|
225
|
+
* Bcrypt-hash a plaintext value and add the result to every record in
|
|
226
|
+
* the working data as `output_field`. Requires ekoDB >= 0.41.0.
|
|
227
|
+
*/
|
|
228
|
+
type: "BcryptHash";
|
|
229
|
+
plain: string;
|
|
230
|
+
cost?: number;
|
|
231
|
+
output_field: string;
|
|
232
|
+
} | {
|
|
233
|
+
/**
|
|
234
|
+
* Verify a plaintext against a bcrypt hash stored on the first record
|
|
235
|
+
* in the working data and write a boolean result into `output_field`.
|
|
236
|
+
* Pair with an `If` stage for login flows. Requires ekoDB >= 0.41.0.
|
|
237
|
+
*/
|
|
238
|
+
type: "BcryptVerify";
|
|
239
|
+
plain: string;
|
|
240
|
+
hash_field: string;
|
|
241
|
+
output_field: string;
|
|
242
|
+
} | {
|
|
243
|
+
/**
|
|
244
|
+
* Generate a cryptographically-random token and add it to every
|
|
245
|
+
* record in the working data. Requires ekoDB >= 0.41.0.
|
|
246
|
+
*/
|
|
247
|
+
type: "RandomToken";
|
|
248
|
+
bytes: number;
|
|
249
|
+
encoding?: "hex" | "base64" | "base64url";
|
|
250
|
+
output_field: string;
|
|
251
|
+
} | {
|
|
252
|
+
/**
|
|
253
|
+
* Sign a JWT and write the resulting token to every working
|
|
254
|
+
* record. Pair with `BcryptVerify` to issue a session token
|
|
255
|
+
* after login. Use `"{{env.JWT_SECRET}}"` for `secret` so the
|
|
256
|
+
* LLM never sees the operator-owned signing key. `iat` and
|
|
257
|
+
* `exp` are auto-stamped when `expires_in_secs` is set.
|
|
258
|
+
* Requires ekoDB >= 0.42.0.
|
|
259
|
+
*/
|
|
260
|
+
type: "JwtSign";
|
|
261
|
+
claims: Record<string, unknown>;
|
|
262
|
+
secret: string;
|
|
263
|
+
algorithm?: "HS256" | "HS384" | "HS512";
|
|
264
|
+
expires_in_secs?: number;
|
|
265
|
+
output_field: string;
|
|
266
|
+
} | {
|
|
267
|
+
/**
|
|
268
|
+
* Verify a JWT held in `token_field` on the first working
|
|
269
|
+
* record. On success, writes the decoded claims object into
|
|
270
|
+
* `output_field`. On failure, writes `null` so callers can
|
|
271
|
+
* branch with `If { FieldEquals { value: null } }` to reject.
|
|
272
|
+
* Requires ekoDB >= 0.42.0.
|
|
273
|
+
*/
|
|
274
|
+
type: "JwtVerify";
|
|
275
|
+
token_field: string;
|
|
276
|
+
secret: string;
|
|
277
|
+
algorithm?: "HS256" | "HS384" | "HS512";
|
|
278
|
+
output_field: string;
|
|
279
|
+
} | {
|
|
280
|
+
/**
|
|
281
|
+
* Send a transactional email through a provider's REST API.
|
|
282
|
+
* Today only `provider = "sendgrid"` is supported. Pull the
|
|
283
|
+
* API key from `"{{env.SENDGRID_API_KEY}}"` so the LLM never
|
|
284
|
+
* sees the operator-owned secret. Result envelope
|
|
285
|
+
* `{provider_status, provider_message, provider}` is written
|
|
286
|
+
* to `output_field` (defaults to `"email_send"`).
|
|
287
|
+
* Requires ekoDB >= 0.42.0.
|
|
288
|
+
*/
|
|
289
|
+
type: "EmailSend";
|
|
290
|
+
to: string;
|
|
291
|
+
subject: string;
|
|
292
|
+
body: string;
|
|
293
|
+
from: string;
|
|
294
|
+
reply_to?: string;
|
|
295
|
+
api_key: string;
|
|
296
|
+
provider?: "sendgrid";
|
|
297
|
+
html?: boolean;
|
|
298
|
+
output_field?: string;
|
|
299
|
+
} | {
|
|
300
|
+
/** HMAC-SHA256/384/512 sign. Requires ekoDB >= 0.42.0. */
|
|
301
|
+
type: "HmacSign";
|
|
302
|
+
input: string;
|
|
303
|
+
secret: string;
|
|
304
|
+
algorithm?: "sha256" | "sha384" | "sha512";
|
|
305
|
+
output_field: string;
|
|
306
|
+
encoding?: "hex" | "base64";
|
|
307
|
+
} | {
|
|
308
|
+
/** HMAC verify (constant-time). Writes a boolean. */
|
|
309
|
+
type: "HmacVerify";
|
|
310
|
+
input: string;
|
|
311
|
+
provided_mac: string;
|
|
312
|
+
secret: string;
|
|
313
|
+
algorithm?: "sha256" | "sha384" | "sha512";
|
|
314
|
+
encoding?: "hex" | "base64";
|
|
315
|
+
output_field: string;
|
|
316
|
+
} | {
|
|
317
|
+
/** AES-256-GCM authenticated encryption. */
|
|
318
|
+
type: "AesEncrypt";
|
|
319
|
+
plaintext: string;
|
|
320
|
+
key: string;
|
|
321
|
+
key_encoding?: "hex" | "base64" | "base64url";
|
|
322
|
+
output_field: string;
|
|
323
|
+
} | {
|
|
324
|
+
/** AES-256-GCM decrypt. Reads `{ciphertext, nonce}` envelope from `ciphertext_field`. */
|
|
325
|
+
type: "AesDecrypt";
|
|
326
|
+
ciphertext_field: string;
|
|
327
|
+
key: string;
|
|
328
|
+
key_encoding?: "hex" | "base64" | "base64url";
|
|
329
|
+
output_field: string;
|
|
330
|
+
} | {
|
|
331
|
+
/** Generate a v4 UUID into `output_field`. */
|
|
332
|
+
type: "UuidGenerate";
|
|
333
|
+
output_field: string;
|
|
334
|
+
} | {
|
|
335
|
+
/** TOTP code generation (RFC 6238). */
|
|
336
|
+
type: "TotpGenerate";
|
|
337
|
+
secret: string;
|
|
338
|
+
digits?: 6 | 8;
|
|
339
|
+
period?: number;
|
|
340
|
+
algorithm?: "sha1" | "sha256" | "sha512";
|
|
341
|
+
output_field: string;
|
|
342
|
+
} | {
|
|
343
|
+
/** TOTP verify; tolerates `skew` time-steps either side. */
|
|
344
|
+
type: "TotpVerify";
|
|
345
|
+
code: string;
|
|
346
|
+
secret: string;
|
|
347
|
+
digits?: 6 | 8;
|
|
348
|
+
period?: number;
|
|
349
|
+
algorithm?: "sha1" | "sha256" | "sha512";
|
|
350
|
+
skew?: number;
|
|
351
|
+
output_field: string;
|
|
352
|
+
} | {
|
|
353
|
+
/** Base64 encode (`url_safe = true` for URL-safe / no-pad). */
|
|
354
|
+
type: "Base64Encode";
|
|
355
|
+
input: string;
|
|
356
|
+
url_safe?: boolean;
|
|
357
|
+
output_field: string;
|
|
358
|
+
} | {
|
|
359
|
+
/** Base64 decode → UTF-8 string. Fail-closed. */
|
|
360
|
+
type: "Base64Decode";
|
|
361
|
+
input: string;
|
|
362
|
+
url_safe?: boolean;
|
|
363
|
+
output_field: string;
|
|
364
|
+
} | {
|
|
365
|
+
/** Hex encode (lowercase). */
|
|
366
|
+
type: "HexEncode";
|
|
367
|
+
input: string;
|
|
368
|
+
output_field: string;
|
|
369
|
+
} | {
|
|
370
|
+
/** Hex decode → UTF-8 string. Fail-closed. */
|
|
371
|
+
type: "HexDecode";
|
|
372
|
+
input: string;
|
|
373
|
+
output_field: string;
|
|
374
|
+
} | {
|
|
375
|
+
/** URL-friendly slug. */
|
|
376
|
+
type: "Slugify";
|
|
377
|
+
input: string;
|
|
378
|
+
output_field: string;
|
|
379
|
+
} | {
|
|
380
|
+
/**
|
|
381
|
+
* Idempotency-key claim (KV SETNX with TTL). Writes
|
|
382
|
+
* `{claimed: true, key}` on first call, `{claimed: false, key,
|
|
383
|
+
* response}` on replay. Requires ekoDB >= 0.42.0.
|
|
384
|
+
*/
|
|
385
|
+
type: "IdempotencyClaim";
|
|
386
|
+
key: string;
|
|
387
|
+
ttl_secs: number;
|
|
388
|
+
output_field: string;
|
|
389
|
+
} | {
|
|
390
|
+
/**
|
|
391
|
+
* Fixed-window rate-limit gate. `on_exceed` either errors
|
|
392
|
+
* (`"fail"`, default) or writes `allowed: false` (`"skip"`).
|
|
393
|
+
*/
|
|
394
|
+
type: "RateLimit";
|
|
395
|
+
key: string;
|
|
396
|
+
limit: number;
|
|
397
|
+
window_secs: number;
|
|
398
|
+
on_exceed?: "fail" | "skip";
|
|
399
|
+
output_field: string;
|
|
400
|
+
} | {
|
|
401
|
+
/** Distributed-lock acquire (token-fenced). */
|
|
402
|
+
type: "LockAcquire";
|
|
403
|
+
key: string;
|
|
404
|
+
ttl_secs: number;
|
|
405
|
+
output_field: string;
|
|
406
|
+
} | {
|
|
407
|
+
/** Distributed-lock release; token-fenced (no foreign release). */
|
|
408
|
+
type: "LockRelease";
|
|
409
|
+
key: string;
|
|
410
|
+
token: string;
|
|
411
|
+
output_field: string;
|
|
412
|
+
} | {
|
|
413
|
+
/**
|
|
414
|
+
* Try/Catch error handling for graceful failure recovery.
|
|
415
|
+
* Executes try_functions, and if any fail, executes catch_functions.
|
|
416
|
+
*/
|
|
417
|
+
type: "TryCatch";
|
|
418
|
+
try_functions: FunctionStageConfig[];
|
|
419
|
+
catch_functions: FunctionStageConfig[];
|
|
420
|
+
output_error_field?: string;
|
|
421
|
+
} | {
|
|
422
|
+
/**
|
|
423
|
+
* Execute multiple functions in parallel (concurrently).
|
|
424
|
+
* All functions run simultaneously, results are merged.
|
|
425
|
+
*/
|
|
426
|
+
type: "Parallel";
|
|
427
|
+
functions: FunctionStageConfig[];
|
|
428
|
+
wait_for_all: boolean;
|
|
429
|
+
} | {
|
|
430
|
+
/** Sleep/delay execution for rate limiting or timing control. */
|
|
431
|
+
type: "Sleep";
|
|
432
|
+
duration_ms: string | number;
|
|
433
|
+
} | {
|
|
434
|
+
/**
|
|
435
|
+
* Return a shaped response (final output formatting).
|
|
436
|
+
* Constructs the final response object from current execution context.
|
|
437
|
+
*/
|
|
438
|
+
type: "Return";
|
|
439
|
+
fields: Record<string, any>;
|
|
440
|
+
status_code?: number;
|
|
441
|
+
} | {
|
|
442
|
+
/**
|
|
443
|
+
* Validate data against a JSON schema before processing.
|
|
444
|
+
* Prevents invalid data from corrupting database or causing errors downstream.
|
|
445
|
+
*/
|
|
446
|
+
type: "Validate";
|
|
447
|
+
schema: Record<string, any>;
|
|
448
|
+
data_field: string;
|
|
449
|
+
on_error?: FunctionStageConfig[];
|
|
210
450
|
};
|
|
211
451
|
export interface ChatMessage {
|
|
212
452
|
role: string;
|
|
@@ -287,15 +527,56 @@ export interface StageStats {
|
|
|
287
527
|
output_count: number;
|
|
288
528
|
execution_time_ms: number;
|
|
289
529
|
}
|
|
530
|
+
/**
|
|
531
|
+
* Reference a call-time function parameter inside a stored-function stage
|
|
532
|
+
* body (Insert.record, Update.updates, UpdateById.updates,
|
|
533
|
+
* FindOneAndUpdate.updates, BatchInsert.records, or any nested JSON value).
|
|
534
|
+
*
|
|
535
|
+
* Returns the structural placeholder `{"type": "Parameter", "name": "<name>"}`.
|
|
536
|
+
* ekoDB's `resolve_json_parameters` recognizes this shape and substitutes the
|
|
537
|
+
* actual parameter value at execution time, preserving the original FieldType
|
|
538
|
+
* (Binary, DateTime, UUID, Decimal, Duration, Number, Set, Vector) via the
|
|
539
|
+
* `{type,value}` wrapped form. Safe to use for any type.
|
|
540
|
+
*
|
|
541
|
+
* This is the structural alternative to the text-level `"{{name}}"` form;
|
|
542
|
+
* both are accepted but structural placeholders are preferred when the
|
|
543
|
+
* parameter is a whole-object Record or a value whose type would be lost in
|
|
544
|
+
* raw JSON.
|
|
545
|
+
*
|
|
546
|
+
* @example
|
|
547
|
+
* ```ts
|
|
548
|
+
* const createUser: UserFunction = {
|
|
549
|
+
* label: "users_create",
|
|
550
|
+
* name: "Create user",
|
|
551
|
+
* parameters: {
|
|
552
|
+
* record: { required: true },
|
|
553
|
+
* },
|
|
554
|
+
* functions: [
|
|
555
|
+
* Stage.insert("users", Stage.param("record")),
|
|
556
|
+
* ],
|
|
557
|
+
* };
|
|
558
|
+
* ```
|
|
559
|
+
*/
|
|
560
|
+
export interface ParameterRef {
|
|
561
|
+
type: "Parameter";
|
|
562
|
+
name: string;
|
|
563
|
+
}
|
|
564
|
+
export declare function parameterRef(name: string): ParameterRef;
|
|
290
565
|
export declare const Stage: {
|
|
566
|
+
/**
|
|
567
|
+
* Shorthand for `parameterRef(name)` — builds the structural placeholder
|
|
568
|
+
* `{"type": "Parameter", "name": name}`. See `parameterRef` for the full
|
|
569
|
+
* explanation and example.
|
|
570
|
+
*/
|
|
571
|
+
param: (name: string) => ParameterRef;
|
|
291
572
|
findAll: (collection: string) => FunctionStageConfig;
|
|
292
573
|
query: (collection: string, filter?: Record<string, any>, sort?: SortFieldConfig[], limit?: number, skip?: number) => FunctionStageConfig;
|
|
293
574
|
project: (fields: string[], exclude?: boolean) => FunctionStageConfig;
|
|
294
575
|
group: (by_fields: string[], functions: GroupFunctionConfig[]) => FunctionStageConfig;
|
|
295
576
|
count: (output_field?: string) => FunctionStageConfig;
|
|
296
|
-
insert: (collection: string, record: Record<string, any
|
|
297
|
-
update: (collection: string, filter: Record<string, any>, updates: Record<string, any
|
|
298
|
-
updateById: (collection: string, record_id: string, updates: Record<string, any
|
|
577
|
+
insert: (collection: string, record: Record<string, any> | ParameterRef, bypassRipple?: boolean, ttl?: number) => FunctionStageConfig;
|
|
578
|
+
update: (collection: string, filter: Record<string, any>, updates: Record<string, any> | ParameterRef, bypassRipple?: boolean, ttl?: number) => FunctionStageConfig;
|
|
579
|
+
updateById: (collection: string, record_id: string, updates: Record<string, any> | ParameterRef, bypassRipple?: boolean, ttl?: number) => FunctionStageConfig;
|
|
299
580
|
delete: (collection: string, filter: Record<string, any>, bypassRipple?: boolean) => FunctionStageConfig;
|
|
300
581
|
deleteById: (collection: string, record_id: string, bypassRipple?: boolean) => FunctionStageConfig;
|
|
301
582
|
batchInsert: (collection: string, records: Record<string, any>[], bypassRipple?: boolean) => FunctionStageConfig;
|
|
@@ -319,7 +600,7 @@ export declare const Stage: {
|
|
|
319
600
|
if: (condition: FunctionCondition, thenFunctions: FunctionStageConfig[], elseFunctions?: FunctionStageConfig[]) => FunctionStageConfig;
|
|
320
601
|
forEach: (functions: FunctionStageConfig[]) => FunctionStageConfig;
|
|
321
602
|
callFunction: (function_label: string, params?: Record<string, any>) => FunctionStageConfig;
|
|
322
|
-
findOneAndUpdate: (collection: string, record_id: string, updates: Record<string, any
|
|
603
|
+
findOneAndUpdate: (collection: string, record_id: string, updates: Record<string, any> | ParameterRef, bypassRipple?: boolean, ttl?: number) => FunctionStageConfig;
|
|
323
604
|
updateWithAction: (collection: string, record_id: string, action: string, field: string, value: any, bypassRipple?: boolean) => FunctionStageConfig;
|
|
324
605
|
createSavepoint: (name: string) => FunctionStageConfig;
|
|
325
606
|
rollbackToSavepoint: (name: string) => FunctionStageConfig;
|
|
@@ -344,4 +625,176 @@ export declare const Stage: {
|
|
|
344
625
|
* @param collection - Optional collection for audit trail storage
|
|
345
626
|
*/
|
|
346
627
|
swr: (cache_key: string, ttl: string | number, url: string, method?: string, headers?: Record<string, string>, body?: any, timeout_seconds?: number, output_field?: string, collection?: string) => FunctionStageConfig;
|
|
628
|
+
/**
|
|
629
|
+
* Bcrypt-hash a plaintext value and write the result into every record
|
|
630
|
+
* in the working data as `output_field`. Requires ekoDB >= 0.41.0.
|
|
631
|
+
*
|
|
632
|
+
* @param plain - Plaintext to hash. Typically a `"{{password}}"`
|
|
633
|
+
* placeholder that the substituter replaces with the call-time param
|
|
634
|
+
* before this stage runs.
|
|
635
|
+
* @param output_field - Field name to write the bcrypt hash into.
|
|
636
|
+
* @param cost - bcrypt cost factor (4..=31). Defaults to 12 when undefined.
|
|
637
|
+
*/
|
|
638
|
+
bcryptHash: (plain: string, output_field: string, cost?: number) => FunctionStageConfig;
|
|
639
|
+
/**
|
|
640
|
+
* Verify a plaintext against a bcrypt hash stored on the first record in
|
|
641
|
+
* the working data. Writes a boolean into `output_field` on every
|
|
642
|
+
* working record. Pair with `Stage.if` to branch on success / failure.
|
|
643
|
+
* Requires ekoDB >= 0.41.0.
|
|
644
|
+
*
|
|
645
|
+
* @param plain - Plaintext to verify (typically `"{{password}}"`).
|
|
646
|
+
* @param hash_field - Name of the field on the current record that
|
|
647
|
+
* holds the stored bcrypt hash (e.g. `"password_hash"`).
|
|
648
|
+
* @param output_field - Field name to write the boolean result into.
|
|
649
|
+
*/
|
|
650
|
+
bcryptVerify: (plain: string, hash_field: string, output_field: string) => FunctionStageConfig;
|
|
651
|
+
/**
|
|
652
|
+
* Generate a cryptographically-random token and add it to every record
|
|
653
|
+
* in the working data. Requires ekoDB >= 0.41.0.
|
|
654
|
+
*
|
|
655
|
+
* @param bytes - Number of random bytes to draw (1..=1024).
|
|
656
|
+
* @param output_field - Field name to write the encoded token into.
|
|
657
|
+
* @param encoding - `"hex"` (default) | `"base64"` | `"base64url"`.
|
|
658
|
+
*/
|
|
659
|
+
randomToken: (bytes: number, output_field: string, encoding?: "hex" | "base64" | "base64url") => FunctionStageConfig;
|
|
660
|
+
/**
|
|
661
|
+
* Sign a JWT and write the resulting token to every working
|
|
662
|
+
* record. Pair with `Stage.bcryptVerify` to issue a session
|
|
663
|
+
* token after login. Use `"{{env.JWT_SECRET}}"` for `secret` so
|
|
664
|
+
* the LLM never sees the operator-owned signing key. `iat` and
|
|
665
|
+
* `exp` are auto-stamped when `expires_in_secs` is set.
|
|
666
|
+
* Requires ekoDB >= 0.42.0.
|
|
667
|
+
*
|
|
668
|
+
* @param claims - JWT payload claims.
|
|
669
|
+
* @param secret - Signing secret (typically `"{{env.JWT_SECRET}}"`).
|
|
670
|
+
* @param output_field - Field name to write the signed JWT into.
|
|
671
|
+
* @param expires_in_secs - Lifetime in seconds (auto-stamps `iat` + `exp`).
|
|
672
|
+
* @param algorithm - `"HS256"` (default) | `"HS384"` | `"HS512"`.
|
|
673
|
+
*/
|
|
674
|
+
jwtSign: (claims: Record<string, unknown>, secret: string, output_field: string, expires_in_secs?: number, algorithm?: "HS256" | "HS384" | "HS512") => FunctionStageConfig;
|
|
675
|
+
/**
|
|
676
|
+
* Verify a JWT held in `token_field` on the first working record.
|
|
677
|
+
* On success writes the decoded claims object into `output_field`;
|
|
678
|
+
* on failure writes `null`. Branch with `Stage.if` matching
|
|
679
|
+
* `output_field == null` to reject. Requires ekoDB >= 0.42.0.
|
|
680
|
+
*
|
|
681
|
+
* @param token_field - Field on the working record holding the JWT.
|
|
682
|
+
* @param secret - Verification secret (must match the signing secret).
|
|
683
|
+
* @param output_field - Field name to write decoded claims into.
|
|
684
|
+
* @param algorithm - Expected algorithm (default `"HS256"`).
|
|
685
|
+
*/
|
|
686
|
+
jwtVerify: (token_field: string, secret: string, output_field: string, algorithm?: "HS256" | "HS384" | "HS512") => FunctionStageConfig;
|
|
687
|
+
/**
|
|
688
|
+
* Send a transactional email. Today only the `"sendgrid"`
|
|
689
|
+
* provider is supported. Use `"{{env.SENDGRID_API_KEY}}"` for
|
|
690
|
+
* `api_key` so the LLM never sees the operator-owned secret.
|
|
691
|
+
* Set `html: true` to send `text/html`. The result envelope
|
|
692
|
+
* (`{provider_status, provider_message, provider}`) is written
|
|
693
|
+
* to `output_field` (default `"email_send"`).
|
|
694
|
+
* Requires ekoDB >= 0.42.0.
|
|
695
|
+
*/
|
|
696
|
+
emailSend: (to: string, subject: string, body: string, from: string, api_key: string, options?: {
|
|
697
|
+
reply_to?: string;
|
|
698
|
+
provider?: "sendgrid";
|
|
699
|
+
html?: boolean;
|
|
700
|
+
output_field?: string;
|
|
701
|
+
}) => FunctionStageConfig;
|
|
702
|
+
/**
|
|
703
|
+
* Try/Catch error handling for graceful failure recovery.
|
|
704
|
+
* Executes tryFunctions, and if any fail, executes catchFunctions.
|
|
705
|
+
*
|
|
706
|
+
* @param tryFunctions - Functions to attempt.
|
|
707
|
+
* @param catchFunctions - Functions to execute on failure.
|
|
708
|
+
* @param outputErrorField - Field name to store error details (default: "error").
|
|
709
|
+
*/
|
|
710
|
+
tryCatch: (tryFunctions: FunctionStageConfig[], catchFunctions: FunctionStageConfig[], outputErrorField?: string) => FunctionStageConfig;
|
|
711
|
+
/**
|
|
712
|
+
* Execute multiple functions in parallel (concurrently).
|
|
713
|
+
* All functions run simultaneously, results are merged.
|
|
714
|
+
*
|
|
715
|
+
* @param functions - Functions to execute concurrently.
|
|
716
|
+
* @param waitForAll - true = wait for all to complete, false = return on first completion.
|
|
717
|
+
*/
|
|
718
|
+
parallel: (functions: FunctionStageConfig[], waitForAll?: boolean) => FunctionStageConfig;
|
|
719
|
+
/**
|
|
720
|
+
* Sleep/delay execution for rate limiting or timing control.
|
|
721
|
+
*
|
|
722
|
+
* @param durationMs - Duration in milliseconds: `1000` or `"{{delay_param}}"`.
|
|
723
|
+
*/
|
|
724
|
+
sleep: (durationMs: string | number) => FunctionStageConfig;
|
|
725
|
+
/**
|
|
726
|
+
* Return a shaped response (final output formatting).
|
|
727
|
+
* Constructs the final response object from current execution context.
|
|
728
|
+
*
|
|
729
|
+
* @param fields - Fields to include in response with `{{param}}` substitution.
|
|
730
|
+
* @param statusCode - HTTP status code (default: 200).
|
|
731
|
+
*/
|
|
732
|
+
returnResponse: (fields: Record<string, any>, statusCode?: number) => FunctionStageConfig;
|
|
733
|
+
/**
|
|
734
|
+
* Validate data against a JSON schema before processing.
|
|
735
|
+
*
|
|
736
|
+
* @param schema - JSON Schema to validate against.
|
|
737
|
+
* @param dataField - Field containing data to validate.
|
|
738
|
+
* @param onError - Functions to execute on validation failure.
|
|
739
|
+
*/
|
|
740
|
+
validate: (schema: Record<string, any>, dataField: string, onError?: FunctionStageConfig[]) => FunctionStageConfig;
|
|
741
|
+
/**
|
|
742
|
+
* HMAC-SHA256/384/512 sign. Use for outbound webhook signing or
|
|
743
|
+
* pre-signed URL generation. Requires ekoDB >= 0.42.0.
|
|
744
|
+
*/
|
|
745
|
+
hmacSign: (input: string, secret: string, output_field: string, options?: {
|
|
746
|
+
algorithm?: "sha256" | "sha384" | "sha512";
|
|
747
|
+
encoding?: "hex" | "base64";
|
|
748
|
+
}) => FunctionStageConfig;
|
|
749
|
+
/** HMAC verify (constant-time). Writes a boolean. */
|
|
750
|
+
hmacVerify: (input: string, provided_mac: string, secret: string, output_field: string, options?: {
|
|
751
|
+
algorithm?: "sha256" | "sha384" | "sha512";
|
|
752
|
+
encoding?: "hex" | "base64";
|
|
753
|
+
}) => FunctionStageConfig;
|
|
754
|
+
/** AES-256-GCM encrypt; writes `{ciphertext, nonce}` envelope. */
|
|
755
|
+
aesEncrypt: (plaintext: string, key: string, output_field: string, key_encoding?: "hex" | "base64" | "base64url") => FunctionStageConfig;
|
|
756
|
+
/** AES-256-GCM decrypt; reads envelope from `ciphertext_field`. */
|
|
757
|
+
aesDecrypt: (ciphertext_field: string, key: string, output_field: string, key_encoding?: "hex" | "base64" | "base64url") => FunctionStageConfig;
|
|
758
|
+
/** Generate a v4 UUID into `output_field`. */
|
|
759
|
+
uuidGenerate: (output_field: string) => FunctionStageConfig;
|
|
760
|
+
/** TOTP code generation (RFC 6238). */
|
|
761
|
+
totpGenerate: (secret: string, output_field: string, options?: {
|
|
762
|
+
digits?: 6 | 8;
|
|
763
|
+
period?: number;
|
|
764
|
+
algorithm?: "sha1" | "sha256" | "sha512";
|
|
765
|
+
}) => FunctionStageConfig;
|
|
766
|
+
/** TOTP verify; tolerates `skew` time-steps either side (default 1). */
|
|
767
|
+
totpVerify: (code: string, secret: string, output_field: string, options?: {
|
|
768
|
+
digits?: 6 | 8;
|
|
769
|
+
period?: number;
|
|
770
|
+
algorithm?: "sha1" | "sha256" | "sha512";
|
|
771
|
+
skew?: number;
|
|
772
|
+
}) => FunctionStageConfig;
|
|
773
|
+
/** Base64 encode (`url_safe = true` for URL-safe / no-pad). */
|
|
774
|
+
base64Encode: (input: string, output_field: string, url_safe?: boolean) => FunctionStageConfig;
|
|
775
|
+
/** Base64 decode → UTF-8 string. Fail-closed. */
|
|
776
|
+
base64Decode: (input: string, output_field: string, url_safe?: boolean) => FunctionStageConfig;
|
|
777
|
+
/** Hex encode (lowercase). */
|
|
778
|
+
hexEncode: (input: string, output_field: string) => FunctionStageConfig;
|
|
779
|
+
/** Hex decode → UTF-8 string. Fail-closed. */
|
|
780
|
+
hexDecode: (input: string, output_field: string) => FunctionStageConfig;
|
|
781
|
+
/** URL-friendly slug. */
|
|
782
|
+
slugify: (input: string, output_field: string) => FunctionStageConfig;
|
|
783
|
+
/**
|
|
784
|
+
* Idempotency-key claim (KV SETNX with TTL). Pass an idempotency
|
|
785
|
+
* key (typically `"{{idempotency_key}}"`) and a TTL; first call
|
|
786
|
+
* writes `{claimed: true, key}`, subsequent calls within the TTL
|
|
787
|
+
* write `{claimed: false, key, response}` so the caller can
|
|
788
|
+
* short-circuit. Requires ekoDB >= 0.42.0.
|
|
789
|
+
*/
|
|
790
|
+
idempotencyClaim: (key: string, ttl_secs: number, output_field: string) => FunctionStageConfig;
|
|
791
|
+
/**
|
|
792
|
+
* Fixed-window rate-limit gate. `on_exceed` either errors
|
|
793
|
+
* (`"fail"`, default) or writes `allowed: false` (`"skip"`).
|
|
794
|
+
*/
|
|
795
|
+
rateLimit: (key: string, limit: number, window_secs: number, output_field: string, on_exceed?: "fail" | "skip") => FunctionStageConfig;
|
|
796
|
+
/** Distributed-lock acquire (token-fenced). */
|
|
797
|
+
lockAcquire: (key: string, ttl_secs: number, output_field: string) => FunctionStageConfig;
|
|
798
|
+
/** Distributed-lock release; only releases on token match. */
|
|
799
|
+
lockRelease: (key: string, token: string, output_field: string) => FunctionStageConfig;
|
|
347
800
|
};
|