@raisindb/functions-types 0.4.0 → 0.4.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/package.json +1 -1
- package/raisin.d.ts +181 -2
package/package.json
CHANGED
package/raisin.d.ts
CHANGED
|
@@ -286,6 +286,20 @@ declare namespace raisin {
|
|
|
286
286
|
namespace crypto {
|
|
287
287
|
function uuid(): Promise<string>;
|
|
288
288
|
function verifyJwt(token: string, opts?: any | null): Promise<any>;
|
|
289
|
+
/** n cryptographically secure random bytes, base64-encoded. n: 1..=64. */
|
|
290
|
+
function randomBytes(n: number): Promise<string>;
|
|
291
|
+
/** Lowercase hex digest. alg: "sha256" (default) | "sha512". */
|
|
292
|
+
function hash(input: string, alg?: string | null): Promise<string>;
|
|
293
|
+
/** Generate a signing keypair; alg defaults to "ES256" (ECDSA P-256). */
|
|
294
|
+
function generateKeyPair(
|
|
295
|
+
alg?: string | null
|
|
296
|
+
): Promise<{ alg: string; publicJwk: any; privateJwk: any }>;
|
|
297
|
+
/** Sign claims into a compact JWS. Signature is JOSE r||s base64url. */
|
|
298
|
+
function signJwt(
|
|
299
|
+
claims: any,
|
|
300
|
+
privateJwk: any,
|
|
301
|
+
opts?: { alg?: string; kid?: string; expiresInSec?: number } | null
|
|
302
|
+
): Promise<string>;
|
|
289
303
|
}
|
|
290
304
|
|
|
291
305
|
namespace date {
|
|
@@ -306,18 +320,130 @@ declare namespace raisin {
|
|
|
306
320
|
interface EmailMessage {
|
|
307
321
|
/** One recipient address, or several. */
|
|
308
322
|
to: string | string[];
|
|
323
|
+
/** Carbon copy. Visible to every recipient. */
|
|
324
|
+
cc?: string | string[];
|
|
325
|
+
/**
|
|
326
|
+
* Blind carbon copy. Each address is invisible to every other recipient.
|
|
327
|
+
*
|
|
328
|
+
* Counted against the same 20-recipient cap as `to` and `cc`, and checked
|
|
329
|
+
* against the function's `email_policy` exactly like them — a blind copy
|
|
330
|
+
* is not a way around the allowlist.
|
|
331
|
+
*/
|
|
332
|
+
bcc?: string | string[];
|
|
309
333
|
subject: string;
|
|
310
334
|
/** Plain-text body. Always required, even alongside `html`. */
|
|
311
335
|
text: string;
|
|
312
336
|
html?: string;
|
|
337
|
+
/**
|
|
338
|
+
* Files to attach. Each entry names exactly one source.
|
|
339
|
+
*
|
|
340
|
+
* Defaults: at most 20 attachments, 10 MiB each and 10 MiB in total once
|
|
341
|
+
* decoded. An operator can raise them per sender in `/config/email`.
|
|
342
|
+
*/
|
|
343
|
+
attachments?: EmailAttachment[];
|
|
344
|
+
/**
|
|
345
|
+
* Which of the tenant's configured senders to send through, by name (see
|
|
346
|
+
* {@link email.providers}). Omit it for the tenant's default — which is
|
|
347
|
+
* what system mail such as the magic link uses.
|
|
348
|
+
*
|
|
349
|
+
* An unknown name REJECTS rather than falling back to the default: mail
|
|
350
|
+
* leaving through the wrong account is worse than mail not leaving.
|
|
351
|
+
*/
|
|
352
|
+
provider?: string;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/** Fields every attachment shares, whatever its source. */
|
|
356
|
+
interface EmailAttachmentBase {
|
|
357
|
+
/**
|
|
358
|
+
* Name the recipient sees. Required for `content`; for a node reference
|
|
359
|
+
* the stored file name is used when omitted.
|
|
360
|
+
*
|
|
361
|
+
* Rejected rather than cleaned up if it carries a path separator or a
|
|
362
|
+
* control character.
|
|
363
|
+
*/
|
|
364
|
+
filename?: string;
|
|
365
|
+
/**
|
|
366
|
+
* MIME type. Derived from the filename (or the stored resource) when
|
|
367
|
+
* omitted. `multipart/*` and `message/*` are refused — neither can be a
|
|
368
|
+
* single attachment.
|
|
369
|
+
*/
|
|
370
|
+
contentType?: string;
|
|
371
|
+
/**
|
|
372
|
+
* Set this to EMBED the file in the HTML body instead of listing it as a
|
|
373
|
+
* download: reference it as `<img src="cid:the-value">`.
|
|
374
|
+
*
|
|
375
|
+
* Requires an `html` body. Works over `smtp` and `resend`; `brevo` has no
|
|
376
|
+
* Content-ID and REJECTS an inline attachment rather than sending one that
|
|
377
|
+
* would arrive broken.
|
|
378
|
+
*/
|
|
379
|
+
contentId?: string;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/** Bytes the function already holds. */
|
|
383
|
+
interface EmailAttachmentContent extends EmailAttachmentBase {
|
|
384
|
+
/** Standard base64, or a `data:<type>;base64,...` URL. */
|
|
385
|
+
content: string;
|
|
386
|
+
filename: string;
|
|
387
|
+
node?: never;
|
|
313
388
|
}
|
|
314
389
|
|
|
390
|
+
/**
|
|
391
|
+
* A file stored on a node, fetched by the server.
|
|
392
|
+
*
|
|
393
|
+
* Read with the FUNCTION's authority, not the caller's — a function running
|
|
394
|
+
* from a trigger or a schedule reads as system. Treat it exactly as you
|
|
395
|
+
* treat {@link nodes.get}.
|
|
396
|
+
*/
|
|
397
|
+
interface EmailAttachmentNode extends EmailAttachmentBase {
|
|
398
|
+
/** Path of the node holding the file. */
|
|
399
|
+
node: string;
|
|
400
|
+
/** Workspace the node lives in. Required. */
|
|
401
|
+
workspace: string;
|
|
402
|
+
/** Property holding the file. Defaults to `"file"`. */
|
|
403
|
+
property?: string;
|
|
404
|
+
content?: never;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* One attachment: inline bytes, or a node reference.
|
|
409
|
+
*
|
|
410
|
+
* In JavaScript a `Resource` (from `node.getResource('file')`) may be passed
|
|
411
|
+
* directly and is converted to a node reference for you.
|
|
412
|
+
*/
|
|
413
|
+
type EmailAttachment = EmailAttachmentContent | EmailAttachmentNode;
|
|
414
|
+
|
|
315
415
|
/** Proof that the provider accepted a message. Acceptance is not delivery. */
|
|
316
416
|
interface EmailReceipt {
|
|
317
417
|
/** The provider's message id — what a later bounce/webhook correlates to. */
|
|
318
418
|
message_id: string;
|
|
319
|
-
/** The provider that issued it
|
|
419
|
+
/** The provider API that issued it: "resend", "brevo" or "smtp". */
|
|
420
|
+
provider: string;
|
|
421
|
+
/**
|
|
422
|
+
* The configured sender it went through. Answers "which of my accounts
|
|
423
|
+
* sent this", which `provider` alone cannot once a tenant has two entries
|
|
424
|
+
* on the same API.
|
|
425
|
+
*/
|
|
426
|
+
sender: string;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/** One of the tenant's configured senders, as {@link email.providers} lists it. */
|
|
430
|
+
interface EmailProviderInfo {
|
|
431
|
+
/** The name {@link email.send} accepts in `provider`. */
|
|
432
|
+
name: string;
|
|
433
|
+
/** The provider API behind it: "resend", "brevo" or "smtp". */
|
|
320
434
|
provider: string;
|
|
435
|
+
from_address: string;
|
|
436
|
+
/** A disabled sender cannot be selected, by name or as the default. */
|
|
437
|
+
enabled: boolean;
|
|
438
|
+
/** True for the one system mail goes through. */
|
|
439
|
+
default: boolean;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/** What {@link email.providers} returns. */
|
|
443
|
+
interface EmailProviders {
|
|
444
|
+
/** The tenant master switch — off means no sender works, however many exist. */
|
|
445
|
+
enabled: boolean;
|
|
446
|
+
providers: EmailProviderInfo[];
|
|
321
447
|
}
|
|
322
448
|
|
|
323
449
|
namespace email {
|
|
@@ -327,13 +453,66 @@ declare namespace raisin {
|
|
|
327
453
|
* Every recipient must be allowed by the function's `email_policy`
|
|
328
454
|
* (`{ enabled, allowed_recipients }` in its `.node.yaml`, matched against
|
|
329
455
|
* the recipient DOMAIN); with no block declared the function cannot send,
|
|
330
|
-
* and one disallowed recipient rejects the whole message.
|
|
456
|
+
* and one disallowed recipient rejects the whole message. "Every
|
|
457
|
+
* recipient" includes `cc` and `bcc`.
|
|
331
458
|
*
|
|
332
459
|
* Also rejects when email is not configured or not enabled for the tenant,
|
|
333
460
|
* when the function's `secret_policy` does not grant the credential the
|
|
334
461
|
* config references, or when the provider refuses the message.
|
|
335
462
|
*/
|
|
336
463
|
function send(message: EmailMessage): Promise<EmailReceipt>;
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* List the tenant's configured senders, so a function can discover the
|
|
467
|
+
* names `send` accepts rather than hardcoding one it cannot verify.
|
|
468
|
+
*
|
|
469
|
+
* Carries no credential and no `credential_ref`: a function that may send
|
|
470
|
+
* does not thereby get to enumerate the secret store. Gated on the same
|
|
471
|
+
* `email_policy` as {@link send} — a function that may not send has no use
|
|
472
|
+
* for the names.
|
|
473
|
+
*/
|
|
474
|
+
function providers(): Promise<EmailProviders>;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
/** A tenant auth identity — what a magic link or password check resolves to. */
|
|
478
|
+
interface Identity {
|
|
479
|
+
id: string;
|
|
480
|
+
email: string;
|
|
481
|
+
/** True only once the magic-link verify step has proven possession. */
|
|
482
|
+
email_verified: boolean;
|
|
483
|
+
display_name: string | null;
|
|
484
|
+
/** Whether the account has local (password) credentials. */
|
|
485
|
+
has_password: boolean;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
interface IdentityPatch {
|
|
489
|
+
/** New address; trimmed and lowercased. Clears `email_verified`. */
|
|
490
|
+
email?: string;
|
|
491
|
+
/** New password. Gives a magic-link-only account local credentials. */
|
|
492
|
+
password?: string;
|
|
493
|
+
display_name?: string;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* Tenant identities (the auth records, NOT `raisin:User` nodes).
|
|
498
|
+
*
|
|
499
|
+
* Gated by the function's `identity_policy: { enabled: true }` in its
|
|
500
|
+
* `.node.yaml`; with no block declared every call rejects with
|
|
501
|
+
* `[identities:policy_denied]`.
|
|
502
|
+
*/
|
|
503
|
+
namespace identities {
|
|
504
|
+
/** Look up an identity by (case-insensitive) email. `null` when none. */
|
|
505
|
+
function findByEmail(email: string): Promise<Identity | null>;
|
|
506
|
+
/**
|
|
507
|
+
* Change an identity's email, password and/or display name.
|
|
508
|
+
*
|
|
509
|
+
* Rejects with `[identities:email_taken]` when another account already
|
|
510
|
+
* holds the new address, and with `[identities:invalid_patch]` for any
|
|
511
|
+
* other key — `email_verified` in particular cannot be set here: a rename
|
|
512
|
+
* proves typing, not possession. When the email changes, the bound
|
|
513
|
+
* `raisin:User` node's `email` property follows.
|
|
514
|
+
*/
|
|
515
|
+
function update(id: string, patch: IdentityPatch): Promise<Identity>;
|
|
337
516
|
}
|
|
338
517
|
|
|
339
518
|
namespace events {
|