@visulima/notification 1.0.8 → 1.0.10
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/CHANGELOG.md +14 -0
- package/dist/channels/email/index.d.ts +23 -23
- package/dist/channels/email/index.js +1 -1
- package/dist/channels/inapp/index.d.ts +31 -31
- package/dist/digest/index.d.ts +55 -55
- package/dist/digest/index.js +1 -1
- package/dist/events/index.d.ts +16 -16
- package/dist/i18n/index.d.ts +21 -21
- package/dist/i18n/index.js +1 -1
- package/dist/index.d.ts +97 -108
- package/dist/index.js +1 -1
- package/dist/layouts/index.d.ts +28 -28
- package/dist/middleware/index.d.ts +49 -49
- package/dist/middleware/index.js +1 -1
- package/dist/packem_shared/{Notification-B22tuJPy.js → Notification-DH2mcFWI.js} +1 -1
- package/dist/packem_shared/NotificationError-B8CyoEaX.js +1 -0
- package/dist/packem_shared/{RequiredOptionError-CuL42XRq.js → RequiredOptionError-Bs282gKK.js} +1 -1
- package/dist/packem_shared/apnsProvider-BPH0pHvd.js +1 -0
- package/dist/packem_shared/{circuitBreakerMiddleware-BlZN7SVT.js → circuitBreakerMiddleware-CRBi0H7e.js} +1 -1
- package/dist/packem_shared/{createDigester-vMNPejGF.js → createDigester-DenmT8_X.js} +1 -1
- package/dist/packem_shared/{createNotificationWorkflow-B70OgeED.js → createNotificationWorkflow-5AY-ays0.js} +1 -1
- package/dist/packem_shared/{createTranslator-CY91C2eS.js → createTranslator-ByyvYNfG.js} +1 -1
- package/dist/packem_shared/{discordProvider-BhfXcCcI.js → discordProvider-BvKwrC8K.js} +1 -1
- package/dist/packem_shared/{emailChannel-CNDlX96Q.js → emailChannel-Cf8wZPZL.js} +1 -1
- package/dist/packem_shared/{expoProvider-DsZR4sUk.js → expoProvider-13gY7Ne8.js} +1 -1
- package/dist/packem_shared/{failoverProvider-D1dAmW8U.js → failoverProvider-DXcwmYev.js} +1 -1
- package/dist/packem_shared/{fcmProvider-DWRx8XBv.js → fcmProvider-DsGjzBzz.js} +1 -1
- package/dist/packem_shared/{messageBirdProvider-BfiTaNLn.js → messageBirdProvider-D1c3jUqj.js} +1 -1
- package/dist/packem_shared/{mockProvider-BLwTZlkw.js → mockProvider-DZ3immtm.js} +1 -1
- package/dist/packem_shared/{msTeamsProvider-DrmL3RYX.js → msTeamsProvider-Cd-BUhH1.js} +1 -1
- package/dist/packem_shared/notification.d-D0ado_cy.d.ts +104 -0
- package/dist/packem_shared/{plivoProvider-Dr8d5yD3.js → plivoProvider-C_koQ8X-.js} +1 -1
- package/dist/packem_shared/{provider.d-BQAGriz6.d.ts → provider.d-Dh32nRm9.d.ts} +10 -10
- package/dist/packem_shared/{roundRobinProvider-BetXJUUm.js → roundRobinProvider-CK3Vyc_u.js} +1 -1
- package/dist/packem_shared/{slackProvider-DPG1IlA0.js → slackProvider-B92QDf3e.js} +1 -1
- package/dist/packem_shared/{sms-CU-OZvNU.js → sms-64HGUCLu.js} +1 -1
- package/dist/packem_shared/{snsProvider-C2T2UxDK.js → snsProvider-CPGjOUP_.js} +1 -1
- package/dist/packem_shared/{telegramProvider-wyx3ksVm.js → telegramProvider-BmmroM5A.js} +1 -1
- package/dist/packem_shared/{telnyxProvider-jgpEwgPh.js → telnyxProvider-C41tE4VF.js} +1 -1
- package/dist/packem_shared/{tracer.d-Co1s_NwG.d.ts → tracer.d-BPznIQx9.d.ts} +2 -2
- package/dist/packem_shared/{twilioProvider-DMYWqvgZ.js → twilioProvider-DanDTzi3.js} +1 -1
- package/dist/packem_shared/{types.d-67TogK4k.d.ts → types.d--kw9ifOI.d.ts} +6 -6
- package/dist/packem_shared/types.d-BU-37j3S.d.ts +10 -0
- package/dist/packem_shared/{types.d-GUzX1jTk.d.ts → types.d-C7l7qdMG.d.ts} +52 -52
- package/dist/packem_shared/{types.d-CximoA8M.d.ts → types.d-CRs03TYV.d.ts} +13 -13
- package/dist/packem_shared/{types.d-C1GoEAlI.d-Bv3grfyD.d.ts → types.d-CcjfiGpo.d-DuZME7ry.d.ts} +27 -34
- package/dist/packem_shared/{vonageProvider-CT4KoWXu.js → vonageProvider-epeGBWW8.js} +1 -1
- package/dist/packem_shared/{webPushProvider-DwjmWASr.js → webPushProvider-K6-Drhaf.js} +1 -1
- package/dist/packem_shared/{webhookProvider-CPA1nKXJ.js → webhookProvider-DlwFyaGc.js} +1 -1
- package/dist/preferences/index.d.ts +19 -19
- package/dist/providers/chat/discord/index.d.ts +5 -5
- package/dist/providers/chat/discord/index.js +1 -1
- package/dist/providers/chat/msteams/index.d.ts +7 -7
- package/dist/providers/chat/msteams/index.js +1 -1
- package/dist/providers/chat/slack/index.d.ts +6 -6
- package/dist/providers/chat/slack/index.js +1 -1
- package/dist/providers/chat/telegram/index.d.ts +5 -5
- package/dist/providers/chat/telegram/index.js +1 -1
- package/dist/providers/failover/index.d.ts +7 -7
- package/dist/providers/failover/index.js +1 -1
- package/dist/providers/mock/index.d.ts +5 -5
- package/dist/providers/mock/index.js +1 -1
- package/dist/providers/opentelemetry/index.d.ts +14 -14
- package/dist/providers/push/apns/index.d.ts +9 -9
- package/dist/providers/push/apns/index.js +1 -1
- package/dist/providers/push/expo/index.d.ts +5 -5
- package/dist/providers/push/expo/index.js +1 -1
- package/dist/providers/push/fcm/index.d.ts +13 -13
- package/dist/providers/push/fcm/index.js +1 -1
- package/dist/providers/push/web-push/index.d.ts +11 -11
- package/dist/providers/push/web-push/index.js +1 -1
- package/dist/providers/roundrobin/index.d.ts +8 -8
- package/dist/providers/roundrobin/index.js +1 -1
- package/dist/providers/sms/messagebird/index.d.ts +5 -5
- package/dist/providers/sms/messagebird/index.js +1 -1
- package/dist/providers/sms/plivo/index.d.ts +5 -5
- package/dist/providers/sms/plivo/index.js +1 -1
- package/dist/providers/sms/sns/index.d.ts +6 -6
- package/dist/providers/sms/sns/index.js +1 -1
- package/dist/providers/sms/telnyx/index.d.ts +5 -5
- package/dist/providers/sms/telnyx/index.js +1 -1
- package/dist/providers/sms/twilio/index.d.ts +5 -5
- package/dist/providers/sms/twilio/index.js +1 -1
- package/dist/providers/sms/vonage/index.d.ts +5 -5
- package/dist/providers/sms/vonage/index.js +1 -1
- package/dist/providers/webhook/index.d.ts +7 -7
- package/dist/providers/webhook/index.js +1 -1
- package/dist/queue/bullmq-queue.d.ts +24 -24
- package/dist/queue/index.d.ts +15 -15
- package/dist/queue/pg-boss-queue.d.ts +26 -26
- package/dist/queue/sqs-queue.d.ts +27 -27
- package/dist/queue/unstorage-queue.d.ts +14 -14
- package/dist/routing/index.d.ts +22 -22
- package/dist/template-engines/handlebars.d.ts +13 -13
- package/dist/template-engines/handlebars.js +1 -1
- package/dist/template-engines/liquid.d.ts +13 -13
- package/dist/template-engines/liquid.js +1 -1
- package/dist/template-engines/string.d.ts +17 -17
- package/dist/utils/result.d.ts +32 -32
- package/dist/utils/result.js +1 -1
- package/dist/webhooks/index.d.ts +84 -84
- package/dist/workflow/index.d.ts +42 -42
- package/dist/workflow/index.js +1 -1
- package/package.json +2 -2
- package/dist/packem_shared/NotificationError-DVfMJQ1u.js +0 -1
- package/dist/packem_shared/apnsProvider-C9WSv5sc.js +0 -1
- package/dist/packem_shared/notification.d-DFCVTods.d.ts +0 -104
- package/dist/packem_shared/types.d-td-F2Oh0.d.ts +0 -10
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { T as TemplateRenderer } from "../packem_shared/types.d-
|
|
1
|
+
import { T as TemplateRenderer } from "../packem_shared/types.d-BU-37j3S.js";
|
|
2
2
|
/**
|
|
3
|
-
* Zero-dependency `{{var}}` interpolation renderer. Edge-safe and peer-free.
|
|
4
|
-
*
|
|
5
|
-
* Replaces `{{ key }}` / `{{ a.b.c }}` placeholders with the matching value from
|
|
6
|
-
* `data`. Unmatched placeholders render as an empty string. Whitespace inside the
|
|
7
|
-
* braces is ignored. This is intentionally minimal — for conditionals/loops use the
|
|
8
|
-
* Handlebars or Liquid renderers.
|
|
9
|
-
* @param template The template string containing `{{var}}` placeholders.
|
|
10
|
-
* @param data The data/variables to interpolate.
|
|
11
|
-
* @returns The rendered string.
|
|
12
|
-
* @throws {TypeError} When the template is not a string.
|
|
13
|
-
* @example
|
|
14
|
-
* ```ts
|
|
15
|
-
* renderString("Hi {{ user.name }}, code {{code}}", { code: "123", user: { name: "Ada" } });
|
|
16
|
-
* // => "Hi Ada, code 123"
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
3
|
+
* Zero-dependency `{{var}}` interpolation renderer. Edge-safe and peer-free.
|
|
4
|
+
*
|
|
5
|
+
* Replaces `{{ key }}` / `{{ a.b.c }}` placeholders with the matching value from
|
|
6
|
+
* `data`. Unmatched placeholders render as an empty string. Whitespace inside the
|
|
7
|
+
* braces is ignored. This is intentionally minimal — for conditionals/loops use the
|
|
8
|
+
* Handlebars or Liquid renderers.
|
|
9
|
+
* @param template The template string containing `{{var}}` placeholders.
|
|
10
|
+
* @param data The data/variables to interpolate.
|
|
11
|
+
* @returns The rendered string.
|
|
12
|
+
* @throws {TypeError} When the template is not a string.
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* renderString("Hi {{ user.name }}, code {{code}}", { code: "123", user: { name: "Ada" } });
|
|
16
|
+
* // => "Hi Ada, code 123"
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
19
|
declare const renderString: TemplateRenderer;
|
|
20
20
|
export { renderString as default, renderString };
|
package/dist/utils/result.d.ts
CHANGED
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
import { R as Result } from "../packem_shared/types.d-
|
|
1
|
+
import { R as Result } from "../packem_shared/types.d-C7l7qdMG.js";
|
|
2
2
|
/**
|
|
3
|
-
* A successful {@link Result} with its data narrowed to be present.
|
|
4
|
-
*/
|
|
3
|
+
* A successful {@link Result} with its data narrowed to be present.
|
|
4
|
+
*/
|
|
5
5
|
type OkResult<T> = Result<T> & {
|
|
6
6
|
data: T;
|
|
7
7
|
success: true;
|
|
8
8
|
};
|
|
9
9
|
/**
|
|
10
|
-
* A failed {@link Result}, narrowed to the failure case.
|
|
11
|
-
*/
|
|
10
|
+
* A failed {@link Result}, narrowed to the failure case.
|
|
11
|
+
*/
|
|
12
12
|
type FailResult<T> = Result<T> & {
|
|
13
13
|
success: false;
|
|
14
14
|
};
|
|
15
15
|
/**
|
|
16
|
-
* Returns whether a {@link Result} succeeded, narrowing `data` to be present.
|
|
17
|
-
* @param result The result to test.
|
|
18
|
-
* @returns `true` when the result is successful.
|
|
19
|
-
*/
|
|
16
|
+
* Returns whether a {@link Result} succeeded, narrowing `data` to be present.
|
|
17
|
+
* @param result The result to test.
|
|
18
|
+
* @returns `true` when the result is successful.
|
|
19
|
+
*/
|
|
20
20
|
declare const isOk: <T>(result: Result<T>) => result is OkResult<T>;
|
|
21
21
|
/**
|
|
22
|
-
* Returns whether a {@link Result} failed.
|
|
23
|
-
* @param result The result to test.
|
|
24
|
-
* @returns `true` when the result is a failure.
|
|
25
|
-
*/
|
|
22
|
+
* Returns whether a {@link Result} failed.
|
|
23
|
+
* @param result The result to test.
|
|
24
|
+
* @returns `true` when the result is a failure.
|
|
25
|
+
*/
|
|
26
26
|
declare const isErr: <T>(result: Result<T>) => result is FailResult<T>;
|
|
27
27
|
/**
|
|
28
|
-
* Returns the data of a successful {@link Result}, or throws its error.
|
|
29
|
-
* @param result The result to unwrap.
|
|
30
|
-
* @returns The contained data.
|
|
31
|
-
* @throws {NotificationError} The result's error (wrapped when it is not already an `Error`).
|
|
32
|
-
*/
|
|
28
|
+
* Returns the data of a successful {@link Result}, or throws its error.
|
|
29
|
+
* @param result The result to unwrap.
|
|
30
|
+
* @returns The contained data.
|
|
31
|
+
* @throws {NotificationError} The result's error (wrapped when it is not already an `Error`).
|
|
32
|
+
*/
|
|
33
33
|
declare const unwrap: <T>(result: Result<T>) => T;
|
|
34
34
|
/**
|
|
35
|
-
* Returns the data of a successful {@link Result}, or a fallback when it failed.
|
|
36
|
-
* @param result The result to unwrap.
|
|
37
|
-
* @param fallback The value to return on failure.
|
|
38
|
-
* @returns The data, or the fallback.
|
|
39
|
-
*/
|
|
35
|
+
* Returns the data of a successful {@link Result}, or a fallback when it failed.
|
|
36
|
+
* @param result The result to unwrap.
|
|
37
|
+
* @param fallback The value to return on failure.
|
|
38
|
+
* @returns The data, or the fallback.
|
|
39
|
+
*/
|
|
40
40
|
declare const unwrapOr: <T>(result: Result<T>, fallback: T) => T;
|
|
41
41
|
/**
|
|
42
|
-
* Maps the data of a successful {@link Result}, passing failures through unchanged.
|
|
43
|
-
* @param result The result to map.
|
|
44
|
-
* @param function_ The mapper applied to the data on success.
|
|
45
|
-
* @returns A new result with the mapped data, or the original failure.
|
|
46
|
-
*/
|
|
42
|
+
* Maps the data of a successful {@link Result}, passing failures through unchanged.
|
|
43
|
+
* @param result The result to map.
|
|
44
|
+
* @param function_ The mapper applied to the data on success.
|
|
45
|
+
* @returns A new result with the mapped data, or the original failure.
|
|
46
|
+
*/
|
|
47
47
|
declare const mapOk: <T, U>(result: Result<T>, function_: (data: T) => U) => Result<U>;
|
|
48
48
|
/**
|
|
49
|
-
* Runs an async function and captures its outcome as a {@link Result}, never throwing.
|
|
50
|
-
* @param function_ The async function to run.
|
|
51
|
-
* @returns A successful result with the value, or a failed result with the thrown error.
|
|
52
|
-
*/
|
|
49
|
+
* Runs an async function and captures its outcome as a {@link Result}, never throwing.
|
|
50
|
+
* @param function_ The async function to run.
|
|
51
|
+
* @returns A successful result with the value, or a failed result with the thrown error.
|
|
52
|
+
*/
|
|
53
53
|
declare const tryAsync: <T>(function_: () => Promise<T>) => Promise<Result<T>>;
|
|
54
54
|
export { FailResult, OkResult, isErr, isOk, mapOk, tryAsync, unwrap, unwrapOr };
|
package/dist/utils/result.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"../packem_shared/NotificationError-
|
|
1
|
+
import e from"../packem_shared/NotificationError-B8CyoEaX.js";const c=r=>r.success,t=r=>!r.success,u=r=>{if(r.success)return r.data;throw r.error instanceof Error?r.error:new e("result","Called unwrap() on a failed result",{cause:r.error})},o=(r,s)=>r.success?r.data:s,n=(r,s)=>r.success?{data:s(r.data),success:!0}:{error:r.error,success:!1},d=async r=>{try{return{data:await r(),success:!0}}catch(s){return{error:s,success:!1}}};export{t as isErr,c as isOk,n as mapOk,d as tryAsync,u as unwrap,o as unwrapOr};
|
package/dist/webhooks/index.d.ts
CHANGED
|
@@ -1,110 +1,110 @@
|
|
|
1
|
-
import { N as NotificationEvent } from "../packem_shared/types.d-
|
|
1
|
+
import { N as NotificationEvent } from "../packem_shared/types.d-C7l7qdMG.js";
|
|
2
2
|
/**
|
|
3
|
-
* Computes an HMAC over `message` and returns the lowercase hex digest.
|
|
4
|
-
* @param key The shared secret (UTF-8 string) or raw key bytes.
|
|
5
|
-
* @param message The message to sign.
|
|
6
|
-
* @param hash The hash algorithm (`"SHA-1"` or `"SHA-256"`).
|
|
7
|
-
* @returns The hex-encoded HMAC.
|
|
8
|
-
*/
|
|
3
|
+
* Computes an HMAC over `message` and returns the lowercase hex digest.
|
|
4
|
+
* @param key The shared secret (UTF-8 string) or raw key bytes.
|
|
5
|
+
* @param message The message to sign.
|
|
6
|
+
* @param hash The hash algorithm (`"SHA-1"` or `"SHA-256"`).
|
|
7
|
+
* @returns The hex-encoded HMAC.
|
|
8
|
+
*/
|
|
9
9
|
declare const hmacHex: (key: string | Uint8Array, message: string, hash: "SHA-1" | "SHA-256") => Promise<string>;
|
|
10
10
|
/**
|
|
11
|
-
* Computes an HMAC over `message` and returns the base64 digest.
|
|
12
|
-
* @param key The shared secret (UTF-8 string) or raw key bytes.
|
|
13
|
-
* @param message The message to sign.
|
|
14
|
-
* @param hash The hash algorithm (`"SHA-1"` or `"SHA-256"`).
|
|
15
|
-
* @returns The base64-encoded HMAC.
|
|
16
|
-
*/
|
|
11
|
+
* Computes an HMAC over `message` and returns the base64 digest.
|
|
12
|
+
* @param key The shared secret (UTF-8 string) or raw key bytes.
|
|
13
|
+
* @param message The message to sign.
|
|
14
|
+
* @param hash The hash algorithm (`"SHA-1"` or `"SHA-256"`).
|
|
15
|
+
* @returns The base64-encoded HMAC.
|
|
16
|
+
*/
|
|
17
17
|
declare const hmacBase64: (key: string | Uint8Array, message: string, hash: "SHA-1" | "SHA-256") => Promise<string>;
|
|
18
18
|
/**
|
|
19
|
-
* Constant-time string comparison to avoid leaking match position via timing.
|
|
20
|
-
*
|
|
21
|
-
* Both inputs are compared in full; the function returns early only on length
|
|
22
|
-
* mismatch (which is not secret).
|
|
23
|
-
* @param a The first string.
|
|
24
|
-
* @param b The second string.
|
|
25
|
-
* @returns `true` when the strings are equal.
|
|
26
|
-
*/
|
|
19
|
+
* Constant-time string comparison to avoid leaking match position via timing.
|
|
20
|
+
*
|
|
21
|
+
* Both inputs are compared in full; the function returns early only on length
|
|
22
|
+
* mismatch (which is not secret).
|
|
23
|
+
* @param a The first string.
|
|
24
|
+
* @param b The second string.
|
|
25
|
+
* @returns `true` when the strings are equal.
|
|
26
|
+
*/
|
|
27
27
|
declare const timingSafeEqual: (a: string, b: string) => boolean;
|
|
28
28
|
/**
|
|
29
|
-
* Case-insensitive map of inbound request headers. Values may be a single string or
|
|
30
|
-
* an array (mirroring `node:http` and `Headers`); verifiers normalise both forms.
|
|
31
|
-
*/
|
|
29
|
+
* Case-insensitive map of inbound request headers. Values may be a single string or
|
|
30
|
+
* an array (mirroring `node:http` and `Headers`); verifiers normalise both forms.
|
|
31
|
+
*/
|
|
32
32
|
type WebhookHeaders = Record<string, string | string[] | undefined>;
|
|
33
33
|
/**
|
|
34
|
-
* A provider inbound-webhook verifier: validates the request signature and normalises
|
|
35
|
-
* the body into a {@link NotificationEvent}.
|
|
36
|
-
*/
|
|
34
|
+
* A provider inbound-webhook verifier: validates the request signature and normalises
|
|
35
|
+
* the body into a {@link NotificationEvent}.
|
|
36
|
+
*/
|
|
37
37
|
interface WebhookVerifier {
|
|
38
38
|
/**
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
* Normalises a verified webhook body into a {@link NotificationEvent}.
|
|
40
|
+
* @param body The raw request body (string).
|
|
41
|
+
* @returns The normalised event, or `undefined` when the body is not a delivery event.
|
|
42
|
+
*/
|
|
43
43
|
parse: (body: string) => NotificationEvent | undefined;
|
|
44
44
|
/**
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
* Verifies the request signature against the shared secret.
|
|
46
|
+
* @param payload The raw request body (string).
|
|
47
|
+
* @param headers The inbound request headers.
|
|
48
|
+
* @param secret The provider signing secret / auth token.
|
|
49
|
+
* @returns `true` when the signature is valid.
|
|
50
|
+
*/
|
|
51
51
|
verify: (payload: string, headers: WebhookHeaders, secret: string) => Promise<boolean>;
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
54
|
-
* Reads a header value case-insensitively, coercing array values to their first entry.
|
|
55
|
-
* @param headers The inbound headers.
|
|
56
|
-
* @param name The header name to read.
|
|
57
|
-
* @returns The header value, or `undefined` when absent.
|
|
58
|
-
*/
|
|
54
|
+
* Reads a header value case-insensitively, coercing array values to their first entry.
|
|
55
|
+
* @param headers The inbound headers.
|
|
56
|
+
* @param name The header name to read.
|
|
57
|
+
* @returns The header value, or `undefined` when absent.
|
|
58
|
+
*/
|
|
59
59
|
declare const getHeader: (headers: WebhookHeaders, name: string) => string | undefined;
|
|
60
60
|
/**
|
|
61
|
-
* Verifier + parser for Slack event/interaction webhooks.
|
|
62
|
-
*
|
|
63
|
-
* Verification follows Slack's v0 signing scheme: the signature is
|
|
64
|
-
* `v0=` + hex HMAC-SHA256 (keyed by the signing secret) of `v0:{timestamp}:{body}`.
|
|
65
|
-
* The request timestamp is checked against a 5-minute replay window. Edge-safe — uses
|
|
66
|
-
* Web Crypto only.
|
|
67
|
-
*/
|
|
61
|
+
* Verifier + parser for Slack event/interaction webhooks.
|
|
62
|
+
*
|
|
63
|
+
* Verification follows Slack's v0 signing scheme: the signature is
|
|
64
|
+
* `v0=` + hex HMAC-SHA256 (keyed by the signing secret) of `v0:{timestamp}:{body}`.
|
|
65
|
+
* The request timestamp is checked against a 5-minute replay window. Edge-safe — uses
|
|
66
|
+
* Web Crypto only.
|
|
67
|
+
*/
|
|
68
68
|
declare const slackWebhook: WebhookVerifier;
|
|
69
69
|
/**
|
|
70
|
-
* Verifier + parser for AWS SNS HTTP/S subscription deliveries.
|
|
71
|
-
*
|
|
72
|
-
* NOTE: signature verification is NOT yet implemented. Real verification requires
|
|
73
|
-
* fetching the X.509 certificate at `SigningCertURL`, validating its cert chain back to
|
|
74
|
-
* an Amazon root, and checking the RSA-SHA1/RSA-SHA256 signature over the canonical
|
|
75
|
-
* string-to-sign (SignatureVersion 1 and 2). Until that lands, {@link snsWebhook.verify}
|
|
76
|
-
* fails closed and always returns `false` — accepting a payload purely on its structure
|
|
77
|
-
* (a `Signature` field plus an `sns.*.amazonaws.com` `SigningCertURL`) is an auth bypass,
|
|
78
|
-
* since both are attacker-controllable. `parse` remains available for callers that have
|
|
79
|
-
* verified the message out-of-band. Callers handling `SubscriptionConfirmation` should
|
|
80
|
-
* confirm the subscription by requesting the `SubscribeURL` from the parsed metadata.
|
|
81
|
-
* Edge-safe — performs no `node:*` work.
|
|
82
|
-
*
|
|
83
|
-
* TODO: implement RSA-SHA1/RSA-SHA256 verification of the canonical string-to-sign
|
|
84
|
-
* against the fetched signing certificate (SignatureVersion 1 and 2).
|
|
85
|
-
*/
|
|
70
|
+
* Verifier + parser for AWS SNS HTTP/S subscription deliveries.
|
|
71
|
+
*
|
|
72
|
+
* NOTE: signature verification is NOT yet implemented. Real verification requires
|
|
73
|
+
* fetching the X.509 certificate at `SigningCertURL`, validating its cert chain back to
|
|
74
|
+
* an Amazon root, and checking the RSA-SHA1/RSA-SHA256 signature over the canonical
|
|
75
|
+
* string-to-sign (SignatureVersion 1 and 2). Until that lands, {@link snsWebhook.verify}
|
|
76
|
+
* fails closed and always returns `false` — accepting a payload purely on its structure
|
|
77
|
+
* (a `Signature` field plus an `sns.*.amazonaws.com` `SigningCertURL`) is an auth bypass,
|
|
78
|
+
* since both are attacker-controllable. `parse` remains available for callers that have
|
|
79
|
+
* verified the message out-of-band. Callers handling `SubscriptionConfirmation` should
|
|
80
|
+
* confirm the subscription by requesting the `SubscribeURL` from the parsed metadata.
|
|
81
|
+
* Edge-safe — performs no `node:*` work.
|
|
82
|
+
*
|
|
83
|
+
* TODO: implement RSA-SHA1/RSA-SHA256 verification of the canonical string-to-sign
|
|
84
|
+
* against the fetched signing certificate (SignatureVersion 1 and 2).
|
|
85
|
+
*/
|
|
86
86
|
declare const snsWebhook: WebhookVerifier;
|
|
87
87
|
/**
|
|
88
|
-
* Verifier + parser implementing the generic
|
|
89
|
-
* [Standard Webhooks](https://www.standardwebhooks.com/) HMAC scheme.
|
|
90
|
-
*
|
|
91
|
-
* The signed content is `{id}.{timestamp}.{body}`; the signature is the base64
|
|
92
|
-
* HMAC-SHA256 prefixed with `v1,`. The `webhook-signature` header may carry several
|
|
93
|
-
* space-separated signatures (key rotation) — verification passes when any matches.
|
|
94
|
-
* If the secret begins with `whsec_`, the base64 remainder is decoded to raw key bytes
|
|
95
|
-
* and the HMAC is keyed with those bytes (per the spec); otherwise the raw secret string
|
|
96
|
-
* is used directly. A hex digest is also accepted as a fallback for non-conformant
|
|
97
|
-
* senders. Edge-safe — uses Web Crypto only.
|
|
98
|
-
*/
|
|
88
|
+
* Verifier + parser implementing the generic
|
|
89
|
+
* [Standard Webhooks](https://www.standardwebhooks.com/) HMAC scheme.
|
|
90
|
+
*
|
|
91
|
+
* The signed content is `{id}.{timestamp}.{body}`; the signature is the base64
|
|
92
|
+
* HMAC-SHA256 prefixed with `v1,`. The `webhook-signature` header may carry several
|
|
93
|
+
* space-separated signatures (key rotation) — verification passes when any matches.
|
|
94
|
+
* If the secret begins with `whsec_`, the base64 remainder is decoded to raw key bytes
|
|
95
|
+
* and the HMAC is keyed with those bytes (per the spec); otherwise the raw secret string
|
|
96
|
+
* is used directly. A hex digest is also accepted as a fallback for non-conformant
|
|
97
|
+
* senders. Edge-safe — uses Web Crypto only.
|
|
98
|
+
*/
|
|
99
99
|
declare const standardWebhook: WebhookVerifier;
|
|
100
100
|
/**
|
|
101
|
-
* Verifier + parser for Twilio status-callback webhooks.
|
|
102
|
-
*
|
|
103
|
-
* Verification follows Twilio's scheme: `X-Twilio-Signature` is the base64 HMAC-SHA1
|
|
104
|
-
* (keyed by the auth token) of the request URL concatenated with the form parameters
|
|
105
|
-
* sorted by key. The full request URL must be provided via the
|
|
106
|
-
* `x-twilio-signature-url` header (the verifier cannot reconstruct it from the body).
|
|
107
|
-
* Edge-safe — uses Web Crypto only.
|
|
108
|
-
*/
|
|
101
|
+
* Verifier + parser for Twilio status-callback webhooks.
|
|
102
|
+
*
|
|
103
|
+
* Verification follows Twilio's scheme: `X-Twilio-Signature` is the base64 HMAC-SHA1
|
|
104
|
+
* (keyed by the auth token) of the request URL concatenated with the form parameters
|
|
105
|
+
* sorted by key. The full request URL must be provided via the
|
|
106
|
+
* `x-twilio-signature-url` header (the verifier cannot reconstruct it from the body).
|
|
107
|
+
* Edge-safe — uses Web Crypto only.
|
|
108
|
+
*/
|
|
109
109
|
declare const twilioWebhook: WebhookVerifier;
|
|
110
110
|
export { type WebhookHeaders, type WebhookVerifier, getHeader, hmacBase64, hmacHex, slackWebhook, snsWebhook, standardWebhook, timingSafeEqual, twilioWebhook };
|
package/dist/workflow/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { M as MaybePromise, D as Duration, W as WorkflowConfig, a as WorkflowDefinition } from "../packem_shared/types.d-
|
|
1
|
+
import { M as MaybePromise, D as Duration, W as WorkflowConfig, a as WorkflowDefinition } from "../packem_shared/types.d-CcjfiGpo.d-DuZME7ry.js";
|
|
2
2
|
import '@standard-schema/spec';
|
|
3
|
-
import { C as ChannelPayloadMap, N as Notification } from "../packem_shared/notification.d-
|
|
4
|
-
import { C as ChannelType, c as Receipt } from "../packem_shared/types.d-
|
|
5
|
-
import "../packem_shared/types.d-
|
|
6
|
-
import "../packem_shared/provider.d-
|
|
3
|
+
import { C as ChannelPayloadMap, N as Notification } from "../packem_shared/notification.d-D0ado_cy.js";
|
|
4
|
+
import { C as ChannelType, c as Receipt } from "../packem_shared/types.d-C7l7qdMG.js";
|
|
5
|
+
import "../packem_shared/types.d-CRs03TYV.js";
|
|
6
|
+
import "../packem_shared/provider.d-Dh32nRm9.js";
|
|
7
7
|
/** The context handed to a step resolver / skip predicate. */
|
|
8
8
|
interface StepResolverContext<PayloadT> {
|
|
9
9
|
/** The validated trigger payload of the run. */
|
|
@@ -16,27 +16,27 @@ interface ChannelStepOptions<PayloadT> {
|
|
|
16
16
|
/** Skip the send when this returns `true`; the step records `undefined`. */
|
|
17
17
|
skip?: (context: StepResolverContext<PayloadT>) => MaybePromise<boolean>;
|
|
18
18
|
/**
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
* Treat a `FailureReceipt` as a thrown error so the run fails and the step
|
|
20
|
+
* re-runs on the next resume/sweep. Defaults to `false`.
|
|
21
|
+
*/
|
|
22
22
|
throwOnFailure?: boolean;
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
|
-
* A durable channel step. Resolves a channel payload and delivers it through the
|
|
26
|
-
* bound {@link Notification} facade exactly once; the receipt is recorded and
|
|
27
|
-
* returned on replay without re-sending. Returns `undefined` when `skip` matches.
|
|
28
|
-
*
|
|
29
|
-
* IMPORTANT: a delivery failure surfaces as a `FailureReceipt` (the facade does not
|
|
30
|
-
* throw), so by default a failed send is **recorded as a completed step and not
|
|
31
|
-
* retried** — inspect `receipt.successful`, or pass `throwOnFailure: true` to turn
|
|
32
|
-
* a failure into a thrown error that re-runs the step on the next activation.
|
|
33
|
-
*/
|
|
25
|
+
* A durable channel step. Resolves a channel payload and delivers it through the
|
|
26
|
+
* bound {@link Notification} facade exactly once; the receipt is recorded and
|
|
27
|
+
* returned on replay without re-sending. Returns `undefined` when `skip` matches.
|
|
28
|
+
*
|
|
29
|
+
* IMPORTANT: a delivery failure surfaces as a `FailureReceipt` (the facade does not
|
|
30
|
+
* throw), so by default a failed send is **recorded as a completed step and not
|
|
31
|
+
* retried** — inspect `receipt.successful`, or pass `throwOnFailure: true` to turn
|
|
32
|
+
* a failure into a thrown error that re-runs the step on the next activation.
|
|
33
|
+
*/
|
|
34
34
|
type ChannelStep<ChannelT extends ChannelType, PayloadT> = (id: string, resolve: StepResolver<PayloadT, ChannelPayloadMap[ChannelT]>, options?: ChannelStepOptions<PayloadT>) => Promise<Receipt | undefined>;
|
|
35
35
|
/**
|
|
36
|
-
* The `step` object handed to a notification workflow body. Channel steps deliver
|
|
37
|
-
* exactly once; `delay` pauses durably; `custom` is an escape hatch to the raw
|
|
38
|
-
* engine step.
|
|
39
|
-
*/
|
|
36
|
+
* The `step` object handed to a notification workflow body. Channel steps deliver
|
|
37
|
+
* exactly once; `delay` pauses durably; `custom` is an escape hatch to the raw
|
|
38
|
+
* engine step.
|
|
39
|
+
*/
|
|
40
40
|
interface NotificationStep<PayloadT> {
|
|
41
41
|
chat: ChannelStep<"chat", PayloadT>;
|
|
42
42
|
custom: <T>(id: string, function_: () => MaybePromise<T>) => Promise<T>;
|
|
@@ -58,26 +58,26 @@ interface NotificationWorkflowConfig<PayloadT, OutputT> extends Omit<WorkflowCon
|
|
|
58
58
|
run: NotificationWorkflowRun<PayloadT, OutputT>;
|
|
59
59
|
}
|
|
60
60
|
/**
|
|
61
|
-
* Define a durable notification workflow on top of [`@visulima/workflow`](https://visulima.com/packages/workflow).
|
|
62
|
-
*
|
|
63
|
-
* The returned value is a plain `WorkflowDefinition`, so it plugs straight into a
|
|
64
|
-
* workflow runtime (`createRuntime({ workflows: [wf] })` → `runtime.trigger(wf, payload)`).
|
|
65
|
-
* Channel steps deliver through the bound `notification` facade exactly once.
|
|
66
|
-
* @param notification The multi-channel facade messages are delivered through.
|
|
67
|
-
* @param config The workflow id, optional payload schema, and notification-flavoured `run`.
|
|
68
|
-
* @returns A {@link WorkflowDefinition} ready to register/trigger on a runtime.
|
|
69
|
-
* @example
|
|
70
|
-
* ```ts
|
|
71
|
-
* const onComment = createNotificationWorkflow(notify, {
|
|
72
|
-
* id: "comment-posted",
|
|
73
|
-
* payload: z.object({ subscriberId: z.string(), author: z.string() }),
|
|
74
|
-
* run: async ({ step, payload }) => {
|
|
75
|
-
* await step.inApp("inbox", () => ({ to: payload.subscriberId, body: `${payload.author} commented` }));
|
|
76
|
-
* await step.delay("cooldown", { amount: 1, unit: "hours" });
|
|
77
|
-
* await step.email("nudge", () => ({ from: "x@y.com", to: payload.subscriberId, subject: "New comment", html: "<p>…</p>" }));
|
|
78
|
-
* },
|
|
79
|
-
* });
|
|
80
|
-
* ```
|
|
81
|
-
*/
|
|
61
|
+
* Define a durable notification workflow on top of [`@visulima/workflow`](https://visulima.com/packages/workflow).
|
|
62
|
+
*
|
|
63
|
+
* The returned value is a plain `WorkflowDefinition`, so it plugs straight into a
|
|
64
|
+
* workflow runtime (`createRuntime({ workflows: [wf] })` → `runtime.trigger(wf, payload)`).
|
|
65
|
+
* Channel steps deliver through the bound `notification` facade exactly once.
|
|
66
|
+
* @param notification The multi-channel facade messages are delivered through.
|
|
67
|
+
* @param config The workflow id, optional payload schema, and notification-flavoured `run`.
|
|
68
|
+
* @returns A {@link WorkflowDefinition} ready to register/trigger on a runtime.
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* const onComment = createNotificationWorkflow(notify, {
|
|
72
|
+
* id: "comment-posted",
|
|
73
|
+
* payload: z.object({ subscriberId: z.string(), author: z.string() }),
|
|
74
|
+
* run: async ({ step, payload }) => {
|
|
75
|
+
* await step.inApp("inbox", () => ({ to: payload.subscriberId, body: `${payload.author} commented` }));
|
|
76
|
+
* await step.delay("cooldown", { amount: 1, unit: "hours" });
|
|
77
|
+
* await step.email("nudge", () => ({ from: "x@y.com", to: payload.subscriberId, subject: "New comment", html: "<p>…</p>" }));
|
|
78
|
+
* },
|
|
79
|
+
* });
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
82
|
declare const createNotificationWorkflow: <PayloadT = unknown, OutputT = unknown>(notification: Notification, config: NotificationWorkflowConfig<PayloadT, OutputT>) => WorkflowDefinition<PayloadT, OutputT>;
|
|
83
83
|
export { type ChannelStep, type ChannelStepOptions, type NotificationStep, type NotificationWorkflowConfig, type NotificationWorkflowRun, type StepResolver, type StepResolverContext, createNotificationWorkflow };
|
package/dist/workflow/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as a}from"../packem_shared/createNotificationWorkflow-
|
|
1
|
+
import{default as a}from"../packem_shared/createNotificationWorkflow-5AY-ays0.js";export{a as createNotificationWorkflow};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visulima/notification",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10",
|
|
4
4
|
"description": "A reusable, ESM-only, edge-ready multi-channel notification library with SMS, push, chat, in-app and webhook providers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"apns",
|
|
@@ -234,7 +234,7 @@
|
|
|
234
234
|
"peerDependencies": {
|
|
235
235
|
"@aws-sdk/client-sqs": "^3.0.0",
|
|
236
236
|
"@opentelemetry/api": "^1.0.0 || ^2.0.0",
|
|
237
|
-
"@visulima/email": "2.1.
|
|
237
|
+
"@visulima/email": "2.1.7",
|
|
238
238
|
"@visulima/workflow": "1.0.0",
|
|
239
239
|
"bullmq": "^5.0.0",
|
|
240
240
|
"croner": "^10.0.1",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{createRequire as h}from"node:module";const d=h(import.meta.url),t=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,m=o=>{if(typeof t<"u"&&t.versions&&t.versions.node){const[e,r]=t.versions.node.split(".").map(Number);if(e>22||e===22&&r>=3||e===20&&r>=16)return t.getBuiltinModule(o)}return d(o)},{createRequire:c}=m("node:module"),f=new Map([["Error",Error],["EvalError",EvalError],["RangeError",RangeError],["ReferenceError",ReferenceError],["SyntaxError",SyntaxError],["TypeError",TypeError],["URIError",URIError]]);typeof AggregateError<"u"&&f.set("AggregateError",AggregateError);const E=c(import.meta.url),i=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,y=o=>{if(typeof i<"u"&&i.versions&&i.versions.node){const[e,r]=i.versions.node.split(".").map(Number);if(e>22||e===22&&r>=3||e===20&&r>=16)return i.getBuiltinModule(o)}return E(o)};y("node:util");class b extends Error{loc;title;hint;type="VisulimaError";constructor({cause:e,hint:r,location:s,message:l,name:u,stack:p,title:g}){super(l,{cause:e}),this.title=g,this.name=u,this.stack=p??this.stack,this.loc=s,this.hint=r}setLocation(e){this.loc=e}setName(e){this.name=e}setMessage(e){this.message=e}setHint(e){this.hint=e}}const v=c(import.meta.url),n=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,a=o=>{if(typeof n<"u"&&n.versions&&n.versions.node){const[e,r]=n.versions.node.split(".").map(Number);if(e>22||e===22&&r>=3||e===20&&r>=16)return n.getBuiltinModule(o)}return v(o)};a("node:fs");a("node:path");a("node:url");class T extends b{component;code;constructor(e,r,s){super({cause:s?.cause,hint:s?.hint,message:`[@visulima/notification] [${e}] ${r}`,name:"NotificationError",title:`Notification ${e} Error`}),this.component=e,this.code=s?.code}}export{T as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{createRequire as I}from"node:module";import g from"./RequiredOptionError-CuL42XRq.js";import{defineProvider as j}from"./defineProvider-C9q-7iwt.js";import{t as k}from"./credentials-CG0zkn-W.js";import{a as N}from"./sms-CU-OZvNU.js";const S=I(import.meta.url),f=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,y=o=>{if(typeof f<"u"&&f.versions&&f.versions.node){const[t,r]=f.versions.node.split(".").map(Number);if(t>22||t===22&&r>=3||t===20&&r>=16)return f.getBuiltinModule(o)}return S(o)},{sign:T,createPrivateKey:$}=y("node:crypto"),{connect:P}=y("node:http2"),J="https://api.push.apple.com",K="https://api.sandbox.push.apple.com",O=3e3*1e3,R=200,h=o=>Buffer.from(o,"utf8").toString("base64url"),q=(o,t,r)=>{const l=h(JSON.stringify({alg:"ES256",kid:o.keyId,typ:"JWT"})),c=h(JSON.stringify({iat:r,iss:o.teamId})),u=`${l}.${c}`,n=T("sha256",Buffer.from(u,"utf8"),{dsaEncoding:"ieee-p1363",key:t}).toString("base64url");return`${u}.${n}`},z=j(o=>{const t=o??{};if(!t.teamId)throw new g("apns","teamId");if(!t.keyId)throw new g("apns","keyId");if(!t.signingKey)throw new g("apns","signingKey");if(!t.bundleId)throw new g("apns","bundleId");const r=t.production?J:K;let l,c,u=0,n;const b=()=>(l??=$({format:"pem",key:t.signingKey}),l),w=()=>{const e=Date.now();return(!c||e-u>O)&&(c=q(t,b(),Math.floor(e/1e3)),u=e),c},_=()=>((!n||n.closed||n.destroyed)&&(n=P(r),n.on("error",e=>{t.logger?.warn(`[@visulima/notification] [apns] HTTP/2 session error: ${e.message}`)})),n),v=async(e,m)=>new Promise(a=>{const i=_().request({":method":"POST",":path":`/3/device/${e}`,"apns-topic":t.bundleId,authorization:`bearer ${w()}`,"content-type":"application/json"});let d=0,p="";i.setEncoding("utf8"),i.on("response",s=>{d=s[":status"]??0}),i.on("data",s=>{p+=s}),i.on("error",s=>{a({error:s.message,id:e,status:"failed"})}),i.on("end",()=>{if(d===R){a({id:e,messageId:e,status:"sent"});return}let s=`HTTP ${String(d)}`;if(p)try{s=JSON.parse(p).reason??s}catch{s=p}a({error:s,id:e,status:"failed"})}),i.end(m)});return{channel:"push",endpoint:r,features:{batchSending:!1,media:!0,richContent:!0},id:"apns",initialize:()=>{},isAvailable:()=>!0,options:t,send:async e=>{const m=k(e.to),a={alert:{body:e.body,title:e.title}};e.sound!==void 0&&(a.sound=e.sound),e.badge!==void 0&&(a.badge=e.badge);const i=JSON.stringify({...e.data,aps:a}),d=[];for(const p of m)d.push(await v(p,i));return N("push","apns",d)},shutdown:()=>{n&&!n.closed&&n.close(),n=void 0}}});export{z as default};
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { M as Middleware } from "./types.d-CximoA8M.js";
|
|
2
|
-
import { P as Provider } from "./provider.d-BQAGriz6.js";
|
|
3
|
-
import { b as ChatPayload, E as EmailChannelPayload, I as InAppPayload, P as PushPayload, S as SmsPayload, W as WebhookPayload, C as ChannelType, c as Receipt } from "./types.d-GUzX1jTk.js";
|
|
4
|
-
/**
|
|
5
|
-
* Maps each channel to its payload type.
|
|
6
|
-
*/
|
|
7
|
-
interface ChannelPayloadMap {
|
|
8
|
-
chat: ChatPayload;
|
|
9
|
-
email: EmailChannelPayload;
|
|
10
|
-
inapp: InAppPayload;
|
|
11
|
-
push: PushPayload;
|
|
12
|
-
sms: SmsPayload;
|
|
13
|
-
webhook: WebhookPayload;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* A multi-channel message: a payload per channel to deliver on.
|
|
17
|
-
*/
|
|
18
|
-
type NotificationMessage = { [K in ChannelType]?: ChannelPayloadMap[K] };
|
|
19
|
-
/**
|
|
20
|
-
* Providers registered per channel.
|
|
21
|
-
*/
|
|
22
|
-
type NotificationProviders = { [K in ChannelType]?: Provider<unknown, ChannelPayloadMap[K]> };
|
|
23
|
-
interface SendManyOptions {
|
|
24
|
-
/** Maximum number of messages delivered concurrently (default 10). */
|
|
25
|
-
concurrency?: number;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* The high-level multi-channel notification facade. Holds a provider per channel,
|
|
29
|
-
* a shared middleware chain and dispatches messages across channels.
|
|
30
|
-
*/
|
|
31
|
-
declare class Notification {
|
|
32
|
-
#private;
|
|
33
|
-
constructor(providers: NotificationProviders);
|
|
34
|
-
/**
|
|
35
|
-
* Registers a middleware. First registered runs outermost.
|
|
36
|
-
* @param middleware The middleware to add.
|
|
37
|
-
* @returns This instance for chaining.
|
|
38
|
-
*/
|
|
39
|
-
use(middleware: Middleware): this;
|
|
40
|
-
/**
|
|
41
|
-
* Sets a logger used by the facade.
|
|
42
|
-
* @param logger The console-like logger.
|
|
43
|
-
* @returns This instance for chaining.
|
|
44
|
-
*/
|
|
45
|
-
setLogger(logger: Console): this;
|
|
46
|
-
/**
|
|
47
|
-
* Returns the provider registered for a channel, if any.
|
|
48
|
-
* @param channel The channel whose registered provider should be looked up.
|
|
49
|
-
* @returns The provider or undefined.
|
|
50
|
-
*/
|
|
51
|
-
getProvider(channel: ChannelType): Provider | undefined;
|
|
52
|
-
/**
|
|
53
|
-
* Sends a payload on a single channel.
|
|
54
|
-
* @param channel The target channel.
|
|
55
|
-
* @param payload The channel-specific payload to deliver.
|
|
56
|
-
* @returns A receipt describing the outcome.
|
|
57
|
-
*/
|
|
58
|
-
sendToChannel<K extends ChannelType>(channel: K, payload: ChannelPayloadMap[K]): Promise<Receipt>;
|
|
59
|
-
/**
|
|
60
|
-
* Sends a multi-channel message, delivering each present channel in parallel.
|
|
61
|
-
* @param message The multi-channel message.
|
|
62
|
-
* @returns One receipt per attempted channel.
|
|
63
|
-
*/
|
|
64
|
-
send(message: NotificationMessage): Promise<Receipt[]>;
|
|
65
|
-
/**
|
|
66
|
-
* Sends many messages with bounded concurrency, yielding the receipts for each.
|
|
67
|
-
* @param messages The messages to send.
|
|
68
|
-
* @param options Concurrency options.
|
|
69
|
-
* @yields The receipts for each message, in completion order.
|
|
70
|
-
*/
|
|
71
|
-
sendMany(messages: Iterable<NotificationMessage>, options?: SendManyOptions): AsyncGenerator<Receipt[]>;
|
|
72
|
-
/**
|
|
73
|
-
* Initializes every registered provider.
|
|
74
|
-
*/
|
|
75
|
-
initialize(): Promise<void>;
|
|
76
|
-
/**
|
|
77
|
-
* Shuts down every registered provider that supports it.
|
|
78
|
-
*/
|
|
79
|
-
shutdown(): Promise<void>;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Creates a {@link Notification} facade from a map of channel providers.
|
|
83
|
-
* @param providers Providers keyed by channel.
|
|
84
|
-
* @returns A configured notification facade.
|
|
85
|
-
*/
|
|
86
|
-
declare const createNotification: (providers: NotificationProviders) => Notification;
|
|
87
|
-
/**
|
|
88
|
-
* One-shot send through a single provider — the quickest path for a single-channel
|
|
89
|
-
* send without wiring a {@link Notification} facade. For multiple channels,
|
|
90
|
-
* middleware, routing or reuse, use {@link createNotification}.
|
|
91
|
-
* @param channel The channel to deliver on.
|
|
92
|
-
* @param provider The provider to deliver through.
|
|
93
|
-
* @param payload The channel-specific payload.
|
|
94
|
-
* @returns The send {@link Receipt}.
|
|
95
|
-
* @example
|
|
96
|
-
* ```ts
|
|
97
|
-
* import { send } from "@visulima/notification";
|
|
98
|
-
* import { twilioProvider } from "@visulima/notification/providers/twilio";
|
|
99
|
-
*
|
|
100
|
-
* await send("sms", twilioProvider({ accountSid, authToken, from }), { to: "+15555550100", text: "Hi" });
|
|
101
|
-
* ```
|
|
102
|
-
*/
|
|
103
|
-
declare const send: <ChannelT extends ChannelType>(channel: ChannelT, provider: Provider<unknown, ChannelPayloadMap[ChannelT]>, payload: ChannelPayloadMap[ChannelT]) => Promise<Receipt>;
|
|
104
|
-
export { ChannelPayloadMap as C, Notification as N, SendManyOptions as S, NotificationMessage as a, NotificationProviders as b, createNotification as c, send as s };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Template render function type. Engines accept a template, optional data and
|
|
3
|
-
* engine-specific options and return the rendered string (sync or async).
|
|
4
|
-
* @param template Template content (typically a string).
|
|
5
|
-
* @param data Data/variables to pass to the template.
|
|
6
|
-
* @param options Options specific to the template engine.
|
|
7
|
-
* @returns The rendered string.
|
|
8
|
-
*/
|
|
9
|
-
type TemplateRenderer = (template: unknown, data?: Record<string, unknown>, options?: Record<string, unknown>) => string | Promise<string>;
|
|
10
|
-
export { TemplateRenderer as T };
|