@visulima/notification 0.0.1 → 1.0.0-alpha.2
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 +35 -0
- package/LICENSE.md +874 -0
- package/README.md +313 -6
- package/dist/channels/email/index.d.ts +46 -0
- package/dist/channels/email/index.js +1 -0
- package/dist/channels/inapp/index.d.ts +99 -0
- package/dist/channels/inapp/index.js +1 -0
- package/dist/digest/index.d.ts +128 -0
- package/dist/digest/index.js +1 -0
- package/dist/events/index.d.ts +37 -0
- package/dist/events/index.js +1 -0
- package/dist/i18n/index.d.ts +42 -0
- package/dist/i18n/index.js +1 -0
- package/dist/index.d.ts +174 -0
- package/dist/index.js +1 -0
- package/dist/layouts/index.d.ts +45 -0
- package/dist/layouts/index.js +1 -0
- package/dist/middleware/index.d.ts +382 -0
- package/dist/middleware/index.js +1 -0
- package/dist/packem_shared/MemoryDigestStore-Bw-sE5MI.js +1 -0
- package/dist/packem_shared/MemoryEventStore-BGD_xRxu.js +1 -0
- package/dist/packem_shared/MemoryInAppStore-48qlrDCx.js +1 -0
- package/dist/packem_shared/MemoryQueue-CXgWoZoY.js +1 -0
- package/dist/packem_shared/Notification-B22tuJPy.js +1 -0
- package/dist/packem_shared/NotificationError-DVfMJQ1u.js +1 -0
- package/dist/packem_shared/NotificationMessageBuilder-Br_aZusY.js +1 -0
- package/dist/packem_shared/RequiredOptionError-CuL42XRq.js +1 -0
- package/dist/packem_shared/UnstorageDigestStore-QAcO3Vb_.js +1 -0
- package/dist/packem_shared/UnstorageInAppStore-Bq2LoDMO.js +1 -0
- package/dist/packem_shared/apnsProvider-C9WSv5sc.js +1 -0
- package/dist/packem_shared/circuitBreakerMiddleware-BlZN7SVT.js +1 -0
- package/dist/packem_shared/composeMiddleware-D6dR8DUS.js +1 -0
- package/dist/packem_shared/createDigester-vMNPejGF.js +1 -0
- package/dist/packem_shared/createNotificationWorkflow-B70OgeED.js +1 -0
- package/dist/packem_shared/createQueueWorker-DjQBxjXc.js +1 -0
- package/dist/packem_shared/createTranslator-CY91C2eS.js +1 -0
- package/dist/packem_shared/credentials-CG0zkn-W.js +1 -0
- package/dist/packem_shared/dedupeMiddleware-CQmPJd_h.js +1 -0
- package/dist/packem_shared/defineLayout-73TNxYPq.js +1 -0
- package/dist/packem_shared/defineProvider-C9q-7iwt.js +1 -0
- package/dist/packem_shared/discordProvider-ewPfe-J7.js +1 -0
- package/dist/packem_shared/emailChannel-CNDlX96Q.js +1 -0
- package/dist/packem_shared/expoProvider-CXq101FD.js +1 -0
- package/dist/packem_shared/failoverProvider-D1dAmW8U.js +1 -0
- package/dist/packem_shared/fcmProvider-WdJGZ55l.js +1 -0
- package/dist/packem_shared/getHeader-C_gkdnMQ.js +1 -0
- package/dist/packem_shared/hmacBase64-BhhoX0uo.js +1 -0
- package/dist/packem_shared/http-BMYcUNBU.js +1 -0
- package/dist/packem_shared/id-C_FRCsUM.js +1 -0
- package/dist/packem_shared/inAppProvider-ElbahgSj.js +1 -0
- package/dist/packem_shared/loggingMiddleware-Cs6EDLcL.js +1 -0
- package/dist/packem_shared/messageBirdProvider-CHUFB0hd.js +1 -0
- package/dist/packem_shared/mockProvider-BLwTZlkw.js +1 -0
- package/dist/packem_shared/msTeamsProvider-DBhrmuSd.js +1 -0
- package/dist/packem_shared/notification.d-DFCVTods.d.ts +104 -0
- package/dist/packem_shared/otelProvider-b6LVo0BS.js +1 -0
- package/dist/packem_shared/plivoProvider-CIOl6DWw.js +1 -0
- package/dist/packem_shared/provider.d-BQAGriz6.d.ts +33 -0
- package/dist/packem_shared/rateLimitMiddleware-DWmEYq-m.js +1 -0
- package/dist/packem_shared/retryMiddleware-uUJDcUoP.js +1 -0
- package/dist/packem_shared/roundRobinProvider-BetXJUUm.js +1 -0
- package/dist/packem_shared/slackProvider-N1wNtAZ3.js +1 -0
- package/dist/packem_shared/slackWebhook-GEx_GdcV.js +1 -0
- package/dist/packem_shared/sms-CU-OZvNU.js +1 -0
- package/dist/packem_shared/snsProvider-KCciJ-nj.js +4 -0
- package/dist/packem_shared/snsWebhook-ChZnBBT3.js +1 -0
- package/dist/packem_shared/standardWebhook-B-LxP8U7.js +1 -0
- package/dist/packem_shared/suppressionMiddleware-CY-Qo1A_.js +1 -0
- package/dist/packem_shared/telegramProvider-jqR5BhJL.js +1 -0
- package/dist/packem_shared/telemetryMiddleware-B1N4k171.js +1 -0
- package/dist/packem_shared/telnyxProvider-C8TMPir1.js +1 -0
- package/dist/packem_shared/tracer.d-Co1s_NwG.d.ts +494 -0
- package/dist/packem_shared/twilioProvider-BxI0e6LX.js +1 -0
- package/dist/packem_shared/twilioWebhook-F0mTmGXD.js +1 -0
- package/dist/packem_shared/types.d-67TogK4k.d.ts +33 -0
- package/dist/packem_shared/types.d-C1GoEAlI.d-Bv3grfyD.d.ts +83 -0
- package/dist/packem_shared/types.d-CximoA8M.d.ts +29 -0
- package/dist/packem_shared/types.d-GUzX1jTk.d.ts +235 -0
- package/dist/packem_shared/types.d-td-F2Oh0.d.ts +10 -0
- package/dist/packem_shared/unstorage.DqlWKU2I.d-CogP3Etw.d.ts +120 -0
- package/dist/packem_shared/vonageProvider-BF76ca89.js +1 -0
- package/dist/packem_shared/webPushProvider-B962RwsA.js +1 -0
- package/dist/packem_shared/webcrypto-bY7wJCB5.js +1 -0
- package/dist/packem_shared/webhookProvider-BALSb2pc.js +1 -0
- package/dist/preferences/index.d.ts +49 -0
- package/dist/preferences/index.js +1 -0
- package/dist/providers/chat/discord/index.d.ts +14 -0
- package/dist/providers/chat/discord/index.js +1 -0
- package/dist/providers/chat/msteams/index.d.ts +14 -0
- package/dist/providers/chat/msteams/index.js +1 -0
- package/dist/providers/chat/slack/index.d.ts +19 -0
- package/dist/providers/chat/slack/index.js +1 -0
- package/dist/providers/chat/telegram/index.d.ts +18 -0
- package/dist/providers/chat/telegram/index.js +1 -0
- package/dist/providers/failover/index.d.ts +16 -0
- package/dist/providers/failover/index.js +1 -0
- package/dist/providers/mock/index.d.ts +29 -0
- package/dist/providers/mock/index.js +1 -0
- package/dist/providers/opentelemetry/index.d.ts +21 -0
- package/dist/providers/opentelemetry/index.js +1 -0
- package/dist/providers/push/apns/index.d.ts +24 -0
- package/dist/providers/push/apns/index.js +1 -0
- package/dist/providers/push/expo/index.d.ts +14 -0
- package/dist/providers/push/expo/index.js +1 -0
- package/dist/providers/push/fcm/index.d.ts +26 -0
- package/dist/providers/push/fcm/index.js +1 -0
- package/dist/providers/push/web-push/index.d.ts +36 -0
- package/dist/providers/push/web-push/index.js +1 -0
- package/dist/providers/roundrobin/index.d.ts +17 -0
- package/dist/providers/roundrobin/index.js +1 -0
- package/dist/providers/sms/messagebird/index.d.ts +16 -0
- package/dist/providers/sms/messagebird/index.js +1 -0
- package/dist/providers/sms/plivo/index.d.ts +18 -0
- package/dist/providers/sms/plivo/index.js +1 -0
- package/dist/providers/sms/sns/index.d.ts +21 -0
- package/dist/providers/sms/sns/index.js +1 -0
- package/dist/providers/sms/telnyx/index.d.ts +18 -0
- package/dist/providers/sms/telnyx/index.js +1 -0
- package/dist/providers/sms/twilio/index.d.ts +20 -0
- package/dist/providers/sms/twilio/index.js +1 -0
- package/dist/providers/sms/vonage/index.d.ts +18 -0
- package/dist/providers/sms/vonage/index.js +1 -0
- package/dist/providers/webhook/index.d.ts +18 -0
- package/dist/providers/webhook/index.js +1 -0
- package/dist/queue/bullmq-queue.d.ts +58 -0
- package/dist/queue/bullmq-queue.js +1 -0
- package/dist/queue/index.d.ts +50 -0
- package/dist/queue/index.js +1 -0
- package/dist/queue/pg-boss-queue.d.ts +66 -0
- package/dist/queue/pg-boss-queue.js +1 -0
- package/dist/queue/sqs-queue.d.ts +91 -0
- package/dist/queue/sqs-queue.js +1 -0
- package/dist/queue/unstorage-queue.d.ts +30 -0
- package/dist/queue/unstorage-queue.js +1 -0
- package/dist/routing/index.d.ts +35 -0
- package/dist/routing/index.js +1 -0
- package/dist/template-engines/handlebars.d.ts +16 -0
- package/dist/template-engines/handlebars.js +1 -0
- package/dist/template-engines/liquid.d.ts +16 -0
- package/dist/template-engines/liquid.js +1 -0
- package/dist/template-engines/string.d.ts +20 -0
- package/dist/template-engines/string.js +1 -0
- package/dist/utils/result.d.ts +54 -0
- package/dist/utils/result.js +1 -0
- package/dist/webhooks/index.d.ts +110 -0
- package/dist/webhooks/index.js +1 -0
- package/dist/workflow/index.d.ts +83 -0
- package/dist/workflow/index.js +1 -0
- package/package.json +283 -43
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** Per-locale map of message key → ICU MessageFormat string. */
|
|
2
|
+
type LocaleMessages = Record<string, string>;
|
|
3
|
+
/** Options for {@link createTranslator}. */
|
|
4
|
+
interface TranslatorOptions {
|
|
5
|
+
/** The locale to fall back to when a key is missing for the requested locale. */
|
|
6
|
+
fallbackLocale: string;
|
|
7
|
+
/** `locale → (key → ICU message)`. Locales may be `en`, `de-DE`, `de_DE`, … */
|
|
8
|
+
messages: Record<string, LocaleMessages>;
|
|
9
|
+
/** Called when a key is missing in every candidate locale; defaults to returning the key. */
|
|
10
|
+
onMissing?: (locale: string, key: string) => string;
|
|
11
|
+
}
|
|
12
|
+
/** Resolves and formats localized messages with ICU MessageFormat. */
|
|
13
|
+
interface Translator {
|
|
14
|
+
/** Whether `key` resolves for `locale` (via region → language → fallback). */
|
|
15
|
+
has: (locale: string, key: string) => boolean;
|
|
16
|
+
/** Format `key` for `locale`, interpolating `values` (plurals/select via ICU). */
|
|
17
|
+
translate: (locale: string, key: string, values?: Record<string, unknown>) => string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Create a {@link Translator} over a set of locale message tables, using
|
|
21
|
+
* [ICU MessageFormat](https://formatjs.io/docs/core-concepts/icu-syntax/) (plurals,
|
|
22
|
+
* select, number/date) via `intl-messageformat`, with region → language → fallback
|
|
23
|
+
* resolution driven by the subscriber's locale. Edge-safe and dependency-light
|
|
24
|
+
* (requires the `intl-messageformat` peer).
|
|
25
|
+
* @param options Message tables, fallback locale, and an optional missing-key handler.
|
|
26
|
+
* @returns A {@link Translator}.
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* const t = createTranslator({
|
|
30
|
+
* fallbackLocale: "en",
|
|
31
|
+
* messages: {
|
|
32
|
+
* en: { likes: "{count, plural, one {# like} other {# likes}}" },
|
|
33
|
+
* de_DE: { likes: "{count, plural, one {# Like} other {# Likes}}" },
|
|
34
|
+
* },
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* t.translate("de_DE", "likes", { count: 3 }); // "3 Likes"
|
|
38
|
+
* t.translate("fr", "likes", { count: 1 }); // falls back to en → "1 like"
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
declare const createTranslator: (options: TranslatorOptions) => Translator;
|
|
42
|
+
export { type Translator, type TranslatorOptions, createTranslator };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{default as e}from"../packem_shared/createTranslator-CY91C2eS.js";export{e as createTranslator};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
export { type M as Middleware, type S as SendContext, type a as SendFunction, c as composeMiddleware } from "./packem_shared/types.d-CximoA8M.js";
|
|
2
|
+
import { C as ChannelPayloadMap, a as NotificationMessage } from "./packem_shared/notification.d-DFCVTods.js";
|
|
3
|
+
export { N as Notification, type b as NotificationProviders, type S as SendManyOptions, c as createNotification, s as send } from "./packem_shared/notification.d-DFCVTods.js";
|
|
4
|
+
export { type P as Provider, type a as ProviderFactory, d as defineProvider } from "./packem_shared/provider.d-BQAGriz6.js";
|
|
5
|
+
export type { d as BaseConfig, B as BaseNotificationPayload, C as ChannelType, b as ChatPayload, f as EmailAddressLike, E as EmailChannelPayload, g as FailureReceipt, F as FeatureFlags, I as InAppPayload, M as MaybePromise, N as NotificationEvent, e as NotificationEventType, h as NotificationPayload, a as NotificationResult, P as PushPayload, c as Receipt, i as RecipientResult, R as Result, S as SmsPayload, j as SuccessReceipt, W as WebhookPayload } from "./packem_shared/types.d-GUzX1jTk.js";
|
|
6
|
+
interface ErrorProperties {
|
|
7
|
+
cause?: unknown;
|
|
8
|
+
hint?: ErrorHint;
|
|
9
|
+
location?: ErrorLocation;
|
|
10
|
+
message?: string;
|
|
11
|
+
name: string;
|
|
12
|
+
stack?: string;
|
|
13
|
+
title?: string;
|
|
14
|
+
}
|
|
15
|
+
interface ErrorLocation {
|
|
16
|
+
column?: number;
|
|
17
|
+
file?: string;
|
|
18
|
+
line?: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* A message that explains to the user how they can fix the error.
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* const error = new VisulimaError({
|
|
25
|
+
* hint: "Try running `npm install` to install missing dependencies.",
|
|
26
|
+
* location: {
|
|
27
|
+
* file: "src/index.ts",
|
|
28
|
+
* line: 1,
|
|
29
|
+
* column: 1,
|
|
30
|
+
* },
|
|
31
|
+
* message: "Cannot find module 'react'",
|
|
32
|
+
* name: "ModuleNotFoundError",
|
|
33
|
+
* });
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* For more complex hints, you can pass an array of strings or a single string in markdown format.
|
|
37
|
+
*/
|
|
38
|
+
type ErrorHint = string[] | string;
|
|
39
|
+
declare class VisulimaError extends Error {
|
|
40
|
+
loc: ErrorLocation | undefined;
|
|
41
|
+
title: string | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* A message that explains to the user how they can fix the error.
|
|
44
|
+
*/
|
|
45
|
+
hint: ErrorHint | undefined;
|
|
46
|
+
type: string;
|
|
47
|
+
constructor({
|
|
48
|
+
cause,
|
|
49
|
+
hint,
|
|
50
|
+
location,
|
|
51
|
+
message,
|
|
52
|
+
name,
|
|
53
|
+
stack,
|
|
54
|
+
title
|
|
55
|
+
}: ErrorProperties);
|
|
56
|
+
setLocation(location: ErrorLocation): void;
|
|
57
|
+
setName(name: string): void;
|
|
58
|
+
setMessage(message: string): void;
|
|
59
|
+
setHint(hint: ErrorHint): void;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Will return an array of all causes in the error in the order they occurred.
|
|
63
|
+
*/
|
|
64
|
+
/**
|
|
65
|
+
* Base error class for notification package operations.
|
|
66
|
+
* @param component The component name where the error occurred.
|
|
67
|
+
* @param message The error message describing what went wrong.
|
|
68
|
+
* @param options Optional error options including cause, code, and hint.
|
|
69
|
+
*/
|
|
70
|
+
declare class NotificationError extends VisulimaError {
|
|
71
|
+
readonly component: string;
|
|
72
|
+
readonly code?: string;
|
|
73
|
+
constructor(component: string, message: string, options?: {
|
|
74
|
+
cause?: Error | unknown;
|
|
75
|
+
code?: string;
|
|
76
|
+
hint?: string | string[];
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Error for missing required options.
|
|
81
|
+
* @param component The component name where the error occurred.
|
|
82
|
+
* @param name The name(s) of the missing required option(s).
|
|
83
|
+
*/
|
|
84
|
+
declare class RequiredOptionError extends NotificationError {
|
|
85
|
+
constructor(component: string, name: string | string[]);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Fluent builder for assembling a multi-channel {@link NotificationMessage}.
|
|
89
|
+
*
|
|
90
|
+
* Mirrors the ergonomics of `@visulima/email`'s `MailMessage`: chainable, per-channel
|
|
91
|
+
* setters that accumulate a plain message object. It is a thin convenience over the
|
|
92
|
+
* existing `NotificationMessage` shape and does not change the facade — `build()`
|
|
93
|
+
* returns the exact object `Notification.send()` already accepts.
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* const message = createNotificationMessage()
|
|
97
|
+
* .sms({ text: "your code is 123", to: "+15555550100" })
|
|
98
|
+
* .push({ body: "deploy finished", title: "CI", to: "device-token" })
|
|
99
|
+
* .idempotencyKey("deploy-42")
|
|
100
|
+
* .build();
|
|
101
|
+
*
|
|
102
|
+
* await createNotification({ sms, push }).send(message);
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
declare class NotificationMessageBuilder {
|
|
106
|
+
#private;
|
|
107
|
+
/**
|
|
108
|
+
* Sets the SMS payload for the message.
|
|
109
|
+
* @param payload The SMS channel payload.
|
|
110
|
+
* @returns This instance for method chaining.
|
|
111
|
+
*/
|
|
112
|
+
sms(payload: ChannelPayloadMap["sms"]): this;
|
|
113
|
+
/**
|
|
114
|
+
* Sets the push payload for the message.
|
|
115
|
+
* @param payload The push channel payload.
|
|
116
|
+
* @returns This instance for method chaining.
|
|
117
|
+
*/
|
|
118
|
+
push(payload: ChannelPayloadMap["push"]): this;
|
|
119
|
+
/**
|
|
120
|
+
* Sets the chat payload for the message.
|
|
121
|
+
* @param payload The chat channel payload.
|
|
122
|
+
* @returns This instance for method chaining.
|
|
123
|
+
*/
|
|
124
|
+
chat(payload: ChannelPayloadMap["chat"]): this;
|
|
125
|
+
/**
|
|
126
|
+
* Sets the in-app inbox payload for the message.
|
|
127
|
+
* @param payload The in-app channel payload.
|
|
128
|
+
* @returns This instance for method chaining.
|
|
129
|
+
*/
|
|
130
|
+
inApp(payload: ChannelPayloadMap["inapp"]): this;
|
|
131
|
+
/**
|
|
132
|
+
* Sets the outbound webhook payload for the message.
|
|
133
|
+
* @param payload The webhook channel payload.
|
|
134
|
+
* @returns This instance for method chaining.
|
|
135
|
+
*/
|
|
136
|
+
webhook(payload: ChannelPayloadMap["webhook"]): this;
|
|
137
|
+
/**
|
|
138
|
+
* Sets the email payload for the message.
|
|
139
|
+
* @param payload The email channel payload.
|
|
140
|
+
* @returns This instance for method chaining.
|
|
141
|
+
*/
|
|
142
|
+
email(payload: ChannelPayloadMap["email"]): this;
|
|
143
|
+
/**
|
|
144
|
+
* Sets metadata applied to every present channel payload at build time.
|
|
145
|
+
*
|
|
146
|
+
* Per-channel `metadata` already set on a payload takes precedence over these
|
|
147
|
+
* builder-level values (the builder values are spread first).
|
|
148
|
+
* @param metadata Arbitrary metadata to attach.
|
|
149
|
+
* @returns This instance for method chaining.
|
|
150
|
+
*/
|
|
151
|
+
metadata(metadata: Record<string, unknown>): this;
|
|
152
|
+
/**
|
|
153
|
+
* Sets an idempotency key applied to every present channel payload at build time.
|
|
154
|
+
*
|
|
155
|
+
* A per-channel `idempotencyKey` already set on a payload takes precedence.
|
|
156
|
+
* @param key The idempotency key used to dedupe retried sends.
|
|
157
|
+
* @returns This instance for method chaining.
|
|
158
|
+
*/
|
|
159
|
+
idempotencyKey(key: string): this;
|
|
160
|
+
/**
|
|
161
|
+
* Builds the plain {@link NotificationMessage}.
|
|
162
|
+
*
|
|
163
|
+
* Applies builder-level `metadata` / `idempotencyKey` to each present channel
|
|
164
|
+
* payload without overriding values already set on the individual payloads.
|
|
165
|
+
* @returns The assembled multi-channel message.
|
|
166
|
+
*/
|
|
167
|
+
build(): NotificationMessage;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Creates a new {@link NotificationMessageBuilder}.
|
|
171
|
+
* @returns A fresh fluent message builder.
|
|
172
|
+
*/
|
|
173
|
+
declare const createNotificationMessage: () => NotificationMessageBuilder;
|
|
174
|
+
export { type ChannelPayloadMap, NotificationError, type NotificationMessage, NotificationMessageBuilder, RequiredOptionError, createNotificationMessage };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{default as r}from"./packem_shared/NotificationError-DVfMJQ1u.js";import{default as t}from"./packem_shared/RequiredOptionError-CuL42XRq.js";import{composeMiddleware as f}from"./packem_shared/composeMiddleware-D6dR8DUS.js";import{Notification as c,createNotification as n,send as p}from"./packem_shared/Notification-B22tuJPy.js";import{NotificationMessageBuilder as m,createNotificationMessage as x}from"./packem_shared/NotificationMessageBuilder-Br_aZusY.js";import{defineProvider as l}from"./packem_shared/defineProvider-C9q-7iwt.js";export{c as Notification,r as NotificationError,m as NotificationMessageBuilder,t as RequiredOptionError,f as composeMiddleware,n as createNotification,x as createNotificationMessage,l as defineProvider,p as send};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { T as TemplateRenderer } from "../packem_shared/types.d-td-F2Oh0.js";
|
|
2
|
+
/** Options for {@link defineLayout}. */
|
|
3
|
+
interface LayoutOptions {
|
|
4
|
+
/**
|
|
5
|
+
* The renderer used for the layout template. Defaults to the zero-dependency
|
|
6
|
+
* `renderString` (`{{var}}`); pass the Handlebars/Liquid renderer for logic.
|
|
7
|
+
*/
|
|
8
|
+
render?: TemplateRenderer;
|
|
9
|
+
/** Name of the slot variable the content is injected as. Defaults to `"content"`. */
|
|
10
|
+
slot?: string;
|
|
11
|
+
/**
|
|
12
|
+
* The layout template. Must contain the slot placeholder (default `{{content}}`).
|
|
13
|
+
* With the Handlebars renderer use the unescaped `{{{content}}}` so the already-
|
|
14
|
+
* rendered HTML body is not double-escaped.
|
|
15
|
+
*/
|
|
16
|
+
template: string;
|
|
17
|
+
}
|
|
18
|
+
/** A reusable layout: renders a content string into its slot, then renders the wrapper. */
|
|
19
|
+
interface Layout {
|
|
20
|
+
/**
|
|
21
|
+
* Wrap `content` in the layout.
|
|
22
|
+
* @param content The already-rendered body to inject into the slot.
|
|
23
|
+
* @param variables Extra variables available to the layout template (e.g. `unsubscribeUrl`).
|
|
24
|
+
*/
|
|
25
|
+
render: (content: string, variables?: Record<string, unknown>) => Promise<string>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Define a reusable content layout — shared chrome (header/footer/brand) with a
|
|
29
|
+
* `{{content}}` slot the per-notification body drops into. Code-first and engine-
|
|
30
|
+
* agnostic: it reuses the package's template renderers, so it stays edge-safe with
|
|
31
|
+
* the default `renderString`.
|
|
32
|
+
* @param options The layout template, optional renderer and slot name.
|
|
33
|
+
* @returns A {@link Layout} whose `render(content, vars)` returns the wrapped string.
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* const branded = defineLayout({
|
|
37
|
+
* template: `<table><tr><td>{{content}}</td></tr><tr><td><a href="{{unsubscribeUrl}}">unsubscribe</a></td></tr></table>`,
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* const html = await branded.render("<p>Welcome!</p>", { unsubscribeUrl: "https://app/u/123" });
|
|
41
|
+
* await notify.sendToChannel("email", { from, to, subject: "Hi", html });
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
declare const defineLayout: (options: LayoutOptions) => Layout;
|
|
45
|
+
export { type Layout, type LayoutOptions, defineLayout };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{default as f}from"../packem_shared/defineLayout-73TNxYPq.js";export{f as defineLayout};
|
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
import { M as Middleware, S as SendContext } from "../packem_shared/types.d-CximoA8M.js";
|
|
2
|
+
export { type a as SendFunction, c as composeMiddleware } from "../packem_shared/types.d-CximoA8M.js";
|
|
3
|
+
import { C as ChannelType, B as BaseNotificationPayload } from "../packem_shared/types.d-GUzX1jTk.js";
|
|
4
|
+
import { A as Attributes, C as Context, T as Tracer } from "../packem_shared/tracer.d-Co1s_NwG.js";
|
|
5
|
+
interface CircuitBreakerMiddlewareOptions {
|
|
6
|
+
/** Time in ms the circuit stays open before a trial request (default 30000). */
|
|
7
|
+
resetTimeout?: number;
|
|
8
|
+
/** Consecutive failures before the circuit opens (default 5). */
|
|
9
|
+
threshold?: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Trips a circuit after consecutive failures, short-circuiting further sends until a
|
|
13
|
+
* cool-off elapses (then allows a single trial request).
|
|
14
|
+
* @param options Failure `threshold` and open-circuit `resetTimeout` (ms).
|
|
15
|
+
* @returns A middleware.
|
|
16
|
+
*/
|
|
17
|
+
declare const circuitBreakerMiddleware: (options?: CircuitBreakerMiddlewareOptions) => Middleware;
|
|
18
|
+
interface DedupeMiddlewareOptions {
|
|
19
|
+
/** Derive the dedupe key (default: `payload.idempotencyKey`). */
|
|
20
|
+
keyFn?: (context: SendContext) => string | undefined;
|
|
21
|
+
/** How long a key is remembered, in ms (default 60000). */
|
|
22
|
+
ttl?: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Suppresses duplicate sends within a TTL window, keyed by idempotency key. A suppressed
|
|
26
|
+
* send resolves successfully with `sent: false` and a `deduped:` message id.
|
|
27
|
+
* @param options Custom `keyFn` and `ttl` (ms) controlling how keys are derived and expire.
|
|
28
|
+
* @returns A middleware.
|
|
29
|
+
*/
|
|
30
|
+
declare const dedupeMiddleware: (options?: DedupeMiddlewareOptions) => Middleware;
|
|
31
|
+
interface LoggingMiddlewareOptions {
|
|
32
|
+
/** Console-like logger (default `console`). */
|
|
33
|
+
logger?: Console;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Logs each send attempt and its outcome.
|
|
37
|
+
* @param options Provide a custom console-like `logger` (defaults to the global console).
|
|
38
|
+
* @returns A middleware.
|
|
39
|
+
*/
|
|
40
|
+
declare const loggingMiddleware: (options?: LoggingMiddlewareOptions) => Middleware;
|
|
41
|
+
interface RateLimitMiddlewareOptions {
|
|
42
|
+
/** Time window in ms over which `rate` tokens are available (default 1000). */
|
|
43
|
+
interval?: number;
|
|
44
|
+
/** Number of sends allowed per `interval` (token bucket capacity). */
|
|
45
|
+
rate: number;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Throttles sends with a token-bucket rate limiter.
|
|
49
|
+
* @param options Bucket `rate` (capacity) and refill `interval` (ms).
|
|
50
|
+
* @returns A middleware.
|
|
51
|
+
*/
|
|
52
|
+
declare const rateLimitMiddleware: (options: RateLimitMiddlewareOptions) => Middleware;
|
|
53
|
+
interface RetryMiddlewareOptions {
|
|
54
|
+
/** Base backoff delay in ms (default 250). */
|
|
55
|
+
baseDelay?: number;
|
|
56
|
+
/** Maximum retry attempts after the first try (default 3). */
|
|
57
|
+
retries?: number;
|
|
58
|
+
/** Decide whether a failed result is retryable (default: always retry). */
|
|
59
|
+
shouldRetry?: (error: unknown) => boolean;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Retries failed sends with exponential backoff + jitter.
|
|
63
|
+
* @param options Attempt count (`retries`), `baseDelay` (ms) and a `shouldRetry` predicate.
|
|
64
|
+
* @returns A middleware.
|
|
65
|
+
*/
|
|
66
|
+
declare const retryMiddleware: (options?: RetryMiddlewareOptions) => Middleware;
|
|
67
|
+
/**
|
|
68
|
+
* Options for {@link suppressionMiddleware}.
|
|
69
|
+
*/
|
|
70
|
+
interface SuppressionMiddlewareOptions {
|
|
71
|
+
/** Returns whether a recipient is suppressed on a channel (unsubscribed, hard-bounced); may be async. */
|
|
72
|
+
isSuppressed: (recipient: string, channel: ChannelType) => boolean | Promise<boolean>;
|
|
73
|
+
/** Resolves the recipient identifier from a payload. Defaults to a stringified `payload.to`. */
|
|
74
|
+
resolveRecipient?: (payload: BaseNotificationPayload) => string | undefined;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Short-circuits sends to suppressed recipients (unsubscribed, hard-bounced, ...). When the resolved
|
|
78
|
+
* recipient is suppressed the send resolves successfully with `sent: false` and a `suppressed:` message
|
|
79
|
+
* id, mirroring how {@link import("./dedupe").dedupeMiddleware} returns a synthetic success.
|
|
80
|
+
*
|
|
81
|
+
* Edge-safe: pure logic with no Node built-ins, so it runs on Cloudflare Workers and other edge runtimes.
|
|
82
|
+
* @param options Suppression check and optional recipient resolver. See {@link SuppressionMiddlewareOptions}.
|
|
83
|
+
* @returns A middleware.
|
|
84
|
+
*/
|
|
85
|
+
declare const suppressionMiddleware: (options: SuppressionMiddlewareOptions) => Middleware;
|
|
86
|
+
/**
|
|
87
|
+
* Advisory options influencing aggregation configuration parameters.
|
|
88
|
+
*
|
|
89
|
+
* @since 1.7.0
|
|
90
|
+
* @experimental
|
|
91
|
+
*/
|
|
92
|
+
interface MetricAdvice {
|
|
93
|
+
/**
|
|
94
|
+
* Hint the explicit bucket boundaries for SDK if the metric is been
|
|
95
|
+
* aggregated with a HistogramAggregator.
|
|
96
|
+
*/
|
|
97
|
+
explicitBucketBoundaries?: number[];
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Options needed for metric creation
|
|
101
|
+
*
|
|
102
|
+
* @since 1.3.0
|
|
103
|
+
*/
|
|
104
|
+
interface MetricOptions {
|
|
105
|
+
/**
|
|
106
|
+
* The description of the Metric.
|
|
107
|
+
* @default ''
|
|
108
|
+
*/
|
|
109
|
+
description?: string;
|
|
110
|
+
/**
|
|
111
|
+
* The unit of the Metric values.
|
|
112
|
+
* @default ''
|
|
113
|
+
*/
|
|
114
|
+
unit?: string;
|
|
115
|
+
/**
|
|
116
|
+
* Indicates the type of the recorded value.
|
|
117
|
+
* @default {@link ValueType.DOUBLE}
|
|
118
|
+
*/
|
|
119
|
+
valueType?: ValueType;
|
|
120
|
+
/**
|
|
121
|
+
* The advice influencing aggregation configuration parameters.
|
|
122
|
+
* @experimental
|
|
123
|
+
* @since 1.7.0
|
|
124
|
+
*/
|
|
125
|
+
advice?: MetricAdvice;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* The Type of value. It describes how the data is reported.
|
|
129
|
+
*
|
|
130
|
+
* @since 1.3.0
|
|
131
|
+
*/
|
|
132
|
+
declare enum ValueType {
|
|
133
|
+
INT = 0,
|
|
134
|
+
DOUBLE = 1,
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Counter is the most common synchronous instrument. This instrument supports
|
|
138
|
+
* an `Add(increment)` function for reporting a sum, and is restricted to
|
|
139
|
+
* non-negative increments. The default aggregation is Sum, as for any additive
|
|
140
|
+
* instrument.
|
|
141
|
+
*
|
|
142
|
+
* Example uses for Counter:
|
|
143
|
+
* <ol>
|
|
144
|
+
* <li> count the number of bytes received. </li>
|
|
145
|
+
* <li> count the number of requests completed. </li>
|
|
146
|
+
* <li> count the number of accounts created. </li>
|
|
147
|
+
* <li> count the number of checkpoints run. </li>
|
|
148
|
+
* <li> count the number of 5xx errors. </li>
|
|
149
|
+
* <ol>
|
|
150
|
+
*
|
|
151
|
+
* @since 1.3.0
|
|
152
|
+
*/
|
|
153
|
+
interface Counter<AttributesTypes extends MetricAttributes = MetricAttributes> {
|
|
154
|
+
/**
|
|
155
|
+
* Increment value of counter by the input. Inputs must not be negative.
|
|
156
|
+
*/
|
|
157
|
+
add(value: number, attributes?: AttributesTypes, context?: Context): void;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* @since 1.3.0
|
|
161
|
+
*/
|
|
162
|
+
interface UpDownCounter<AttributesTypes extends MetricAttributes = MetricAttributes> {
|
|
163
|
+
/**
|
|
164
|
+
* Increment value of counter by the input. Inputs may be negative.
|
|
165
|
+
*/
|
|
166
|
+
add(value: number, attributes?: AttributesTypes, context?: Context): void;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* @since 1.9.0
|
|
170
|
+
*/
|
|
171
|
+
interface Gauge<AttributesTypes extends MetricAttributes = MetricAttributes> {
|
|
172
|
+
/**
|
|
173
|
+
* Records a measurement.
|
|
174
|
+
*/
|
|
175
|
+
record(value: number, attributes?: AttributesTypes, context?: Context): void;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* @since 1.3.0
|
|
179
|
+
*/
|
|
180
|
+
interface Histogram<AttributesTypes extends MetricAttributes = MetricAttributes> {
|
|
181
|
+
/**
|
|
182
|
+
* Records a measurement. Value of the measurement must not be negative.
|
|
183
|
+
*/
|
|
184
|
+
record(value: number, attributes?: AttributesTypes, context?: Context): void;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* @deprecated please use {@link Attributes}
|
|
188
|
+
* @since 1.3.0
|
|
189
|
+
*/
|
|
190
|
+
type MetricAttributes = Attributes;
|
|
191
|
+
/**
|
|
192
|
+
* Interface that is being used in callback function for Observable Metric.
|
|
193
|
+
*
|
|
194
|
+
* @since 1.3.0
|
|
195
|
+
*/
|
|
196
|
+
interface ObservableResult<AttributesTypes extends MetricAttributes = MetricAttributes> {
|
|
197
|
+
/**
|
|
198
|
+
* Observe a measurement of the value associated with the given attributes.
|
|
199
|
+
*
|
|
200
|
+
* @param value The value to be observed.
|
|
201
|
+
* @param attributes The attributes associated with the value. If more than
|
|
202
|
+
* one value is associated with the same attributes values, SDK may pick the
|
|
203
|
+
* last one or simply drop the entire observable result.
|
|
204
|
+
*/
|
|
205
|
+
observe(this: ObservableResult<AttributesTypes>, value: number, attributes?: AttributesTypes): void;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Interface that is being used in batch observable callback function.
|
|
209
|
+
*/
|
|
210
|
+
interface BatchObservableResult<AttributesTypes extends MetricAttributes = MetricAttributes> {
|
|
211
|
+
/**
|
|
212
|
+
* Observe a measurement of the value associated with the given attributes.
|
|
213
|
+
*
|
|
214
|
+
* @param metric The observable metric to be observed.
|
|
215
|
+
* @param value The value to be observed.
|
|
216
|
+
* @param attributes The attributes associated with the value. If more than
|
|
217
|
+
* one value is associated with the same attributes values, SDK may pick the
|
|
218
|
+
* last one or simply drop the entire observable result.
|
|
219
|
+
*/
|
|
220
|
+
observe(this: BatchObservableResult<AttributesTypes>, metric: Observable<AttributesTypes>, value: number, attributes?: AttributesTypes): void;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* The observable callback for Observable instruments.
|
|
224
|
+
*
|
|
225
|
+
* @since 1.3.0
|
|
226
|
+
*/
|
|
227
|
+
type ObservableCallback<AttributesTypes extends MetricAttributes = MetricAttributes> = (observableResult: ObservableResult<AttributesTypes>) => void | Promise<void>;
|
|
228
|
+
/**
|
|
229
|
+
* The observable callback for a batch of Observable instruments.
|
|
230
|
+
*
|
|
231
|
+
* @since 1.3.0
|
|
232
|
+
*/
|
|
233
|
+
type BatchObservableCallback<AttributesTypes extends MetricAttributes = MetricAttributes> = (observableResult: BatchObservableResult<AttributesTypes>) => void | Promise<void>;
|
|
234
|
+
/**
|
|
235
|
+
* @since 1.3.0
|
|
236
|
+
*/
|
|
237
|
+
interface Observable<AttributesTypes extends MetricAttributes = MetricAttributes> {
|
|
238
|
+
/**
|
|
239
|
+
* Sets up a function that will be called whenever a metric collection is initiated.
|
|
240
|
+
*
|
|
241
|
+
* If the function is already in the list of callbacks for this Observable, the function is not added a second time.
|
|
242
|
+
*/
|
|
243
|
+
addCallback(callback: ObservableCallback<AttributesTypes>): void;
|
|
244
|
+
/**
|
|
245
|
+
* Removes a callback previously registered with {@link Observable.addCallback}.
|
|
246
|
+
*/
|
|
247
|
+
removeCallback(callback: ObservableCallback<AttributesTypes>): void;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* @since 1.3.0
|
|
251
|
+
*/
|
|
252
|
+
type ObservableCounter<AttributesTypes extends MetricAttributes = MetricAttributes> = Observable<AttributesTypes>;
|
|
253
|
+
/**
|
|
254
|
+
* @since 1.3.0
|
|
255
|
+
*/
|
|
256
|
+
type ObservableUpDownCounter<AttributesTypes extends MetricAttributes = MetricAttributes> = Observable<AttributesTypes>;
|
|
257
|
+
/**
|
|
258
|
+
* @since 1.3.0
|
|
259
|
+
*/
|
|
260
|
+
type ObservableGauge<AttributesTypes extends MetricAttributes = MetricAttributes> = Observable<AttributesTypes>;
|
|
261
|
+
/**
|
|
262
|
+
* An interface to allow the recording metrics.
|
|
263
|
+
*
|
|
264
|
+
* {@link Metric}s are used for recording pre-defined aggregation (`Counter`),
|
|
265
|
+
* or raw values (`Histogram`) in which the aggregation and attributes
|
|
266
|
+
* for the exported metric are deferred.
|
|
267
|
+
*
|
|
268
|
+
* @since 1.3.0
|
|
269
|
+
*/
|
|
270
|
+
interface Meter {
|
|
271
|
+
/**
|
|
272
|
+
* Creates and returns a new `Gauge`.
|
|
273
|
+
* @param name the name of the metric.
|
|
274
|
+
* @param [options] the metric options.
|
|
275
|
+
*/
|
|
276
|
+
createGauge<AttributesTypes extends MetricAttributes = MetricAttributes>(name: string, options?: MetricOptions): Gauge<AttributesTypes>;
|
|
277
|
+
/**
|
|
278
|
+
* Creates and returns a new `Histogram`.
|
|
279
|
+
* @param name the name of the metric.
|
|
280
|
+
* @param [options] the metric options.
|
|
281
|
+
*/
|
|
282
|
+
createHistogram<AttributesTypes extends MetricAttributes = MetricAttributes>(name: string, options?: MetricOptions): Histogram<AttributesTypes>;
|
|
283
|
+
/**
|
|
284
|
+
* Creates a new `Counter` metric. Generally, this kind of metric when the
|
|
285
|
+
* value is a quantity, the sum is of primary interest, and the event count
|
|
286
|
+
* and value distribution are not of primary interest.
|
|
287
|
+
* @param name the name of the metric.
|
|
288
|
+
* @param [options] the metric options.
|
|
289
|
+
*/
|
|
290
|
+
createCounter<AttributesTypes extends MetricAttributes = MetricAttributes>(name: string, options?: MetricOptions): Counter<AttributesTypes>;
|
|
291
|
+
/**
|
|
292
|
+
* Creates a new `UpDownCounter` metric. UpDownCounter is a synchronous
|
|
293
|
+
* instrument and very similar to Counter except that Add(increment)
|
|
294
|
+
* supports negative increments. It is generally useful for capturing changes
|
|
295
|
+
* in an amount of resources used, or any quantity that rises and falls
|
|
296
|
+
* during a request.
|
|
297
|
+
* Example uses for UpDownCounter:
|
|
298
|
+
* <ol>
|
|
299
|
+
* <li> count the number of active requests. </li>
|
|
300
|
+
* <li> count memory in use by instrumenting new and delete. </li>
|
|
301
|
+
* <li> count queue size by instrumenting enqueue and dequeue. </li>
|
|
302
|
+
* <li> count semaphore up and down operations. </li>
|
|
303
|
+
* </ol>
|
|
304
|
+
*
|
|
305
|
+
* @param name the name of the metric.
|
|
306
|
+
* @param [options] the metric options.
|
|
307
|
+
*/
|
|
308
|
+
createUpDownCounter<AttributesTypes extends MetricAttributes = MetricAttributes>(name: string, options?: MetricOptions): UpDownCounter<AttributesTypes>;
|
|
309
|
+
/**
|
|
310
|
+
* Creates a new `ObservableGauge` metric.
|
|
311
|
+
*
|
|
312
|
+
* The callback SHOULD be safe to be invoked concurrently.
|
|
313
|
+
*
|
|
314
|
+
* @param name the name of the metric.
|
|
315
|
+
* @param [options] the metric options.
|
|
316
|
+
*/
|
|
317
|
+
createObservableGauge<AttributesTypes extends MetricAttributes = MetricAttributes>(name: string, options?: MetricOptions): ObservableGauge<AttributesTypes>;
|
|
318
|
+
/**
|
|
319
|
+
* Creates a new `ObservableCounter` metric.
|
|
320
|
+
*
|
|
321
|
+
* The callback SHOULD be safe to be invoked concurrently.
|
|
322
|
+
*
|
|
323
|
+
* @param name the name of the metric.
|
|
324
|
+
* @param [options] the metric options.
|
|
325
|
+
*/
|
|
326
|
+
createObservableCounter<AttributesTypes extends MetricAttributes = MetricAttributes>(name: string, options?: MetricOptions): ObservableCounter<AttributesTypes>;
|
|
327
|
+
/**
|
|
328
|
+
* Creates a new `ObservableUpDownCounter` metric.
|
|
329
|
+
*
|
|
330
|
+
* The callback SHOULD be safe to be invoked concurrently.
|
|
331
|
+
*
|
|
332
|
+
* @param name the name of the metric.
|
|
333
|
+
* @param [options] the metric options.
|
|
334
|
+
*/
|
|
335
|
+
createObservableUpDownCounter<AttributesTypes extends MetricAttributes = MetricAttributes>(name: string, options?: MetricOptions): ObservableUpDownCounter<AttributesTypes>;
|
|
336
|
+
/**
|
|
337
|
+
* Sets up a function that will be called whenever a metric collection is
|
|
338
|
+
* initiated.
|
|
339
|
+
*
|
|
340
|
+
* If the function is already in the list of callbacks for this Observable,
|
|
341
|
+
* the function is not added a second time.
|
|
342
|
+
*
|
|
343
|
+
* Only the associated observables can be observed in the callback.
|
|
344
|
+
* Measurements of observables that are not associated observed in the
|
|
345
|
+
* callback are dropped.
|
|
346
|
+
*
|
|
347
|
+
* @param callback the batch observable callback
|
|
348
|
+
* @param observables the observables associated with this batch observable callback
|
|
349
|
+
*/
|
|
350
|
+
addBatchObservableCallback<AttributesTypes extends MetricAttributes = MetricAttributes>(callback: BatchObservableCallback<AttributesTypes>, observables: Observable<AttributesTypes>[]): void;
|
|
351
|
+
/**
|
|
352
|
+
* Removes a callback previously registered with {@link Meter.addBatchObservableCallback}.
|
|
353
|
+
*
|
|
354
|
+
* The callback to be removed is identified using a combination of the callback itself,
|
|
355
|
+
* and the set of the observables associated with it.
|
|
356
|
+
*
|
|
357
|
+
* @param callback the batch observable callback
|
|
358
|
+
* @param observables the observables associated with this batch observable callback
|
|
359
|
+
*/
|
|
360
|
+
removeBatchObservableCallback<AttributesTypes extends MetricAttributes = MetricAttributes>(callback: BatchObservableCallback<AttributesTypes>, observables: Observable<AttributesTypes>[]): void;
|
|
361
|
+
}
|
|
362
|
+
interface TelemetryMiddlewareOptions {
|
|
363
|
+
/**
|
|
364
|
+
* The OpenTelemetry {@link Meter} used to record a send counter and duration histogram.
|
|
365
|
+
* When omitted, no metrics are recorded.
|
|
366
|
+
*/
|
|
367
|
+
meter?: Meter;
|
|
368
|
+
/**
|
|
369
|
+
* The OpenTelemetry {@link Tracer} used to create a span per send. When omitted, no span
|
|
370
|
+
* is recorded (keeping `@opentelemetry/api` an optional peer dependency).
|
|
371
|
+
*/
|
|
372
|
+
tracer?: Tracer;
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Records an OpenTelemetry span plus a send counter and duration histogram for each send.
|
|
376
|
+
* Edge-safe: `@opentelemetry/api` is runtime-agnostic and both the tracer and meter are
|
|
377
|
+
* injected, so nothing is emitted until the host application supplies them.
|
|
378
|
+
* @param options Provide a `tracer` and/or `meter` to enable tracing and metrics.
|
|
379
|
+
* @returns A middleware.
|
|
380
|
+
*/
|
|
381
|
+
declare const telemetryMiddleware: (options?: TelemetryMiddlewareOptions) => Middleware;
|
|
382
|
+
export { type CircuitBreakerMiddlewareOptions, type DedupeMiddlewareOptions, type LoggingMiddlewareOptions, type Middleware, type RateLimitMiddlewareOptions, type RetryMiddlewareOptions, type SendContext, type SuppressionMiddlewareOptions, type TelemetryMiddlewareOptions, circuitBreakerMiddleware, dedupeMiddleware, loggingMiddleware, rateLimitMiddleware, retryMiddleware, suppressionMiddleware, telemetryMiddleware };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{circuitBreakerMiddleware as o}from"../packem_shared/circuitBreakerMiddleware-BlZN7SVT.js";import{dedupeMiddleware as i}from"../packem_shared/dedupeMiddleware-CQmPJd_h.js";import{loggingMiddleware as p}from"../packem_shared/loggingMiddleware-Cs6EDLcL.js";import{rateLimitMiddleware as a}from"../packem_shared/rateLimitMiddleware-DWmEYq-m.js";import{retryMiddleware as f}from"../packem_shared/retryMiddleware-uUJDcUoP.js";import{suppressionMiddleware as x}from"../packem_shared/suppressionMiddleware-CY-Qo1A_.js";import{telemetryMiddleware as s}from"../packem_shared/telemetryMiddleware-B1N4k171.js";import{composeMiddleware as g}from"../packem_shared/composeMiddleware-D6dR8DUS.js";export{o as circuitBreakerMiddleware,g as composeMiddleware,i as dedupeMiddleware,p as loggingMiddleware,a as rateLimitMiddleware,f as retryMiddleware,x as suppressionMiddleware,s as telemetryMiddleware};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
class a{#e=new Map;append(e,s,r){const t=this.#e.get(e);return t===void 0?(this.#e.set(e,{events:[s],key:e,wakeAt:r}),Promise.resolve(!0)):(t.events.push(s),Promise.resolve(!1))}read(e){return Promise.resolve(this.#e.get(e))}remove(e){return this.#e.delete(e),Promise.resolve()}due(e,s){const r=[...this.#e.values()].filter(t=>t.wakeAt<=e).toSorted((t,o)=>t.wakeAt-o.wakeAt).slice(0,s).map(t=>t.key);return Promise.resolve(r)}}export{a as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
class a{#e=new Map;append(e){const s=this.#e.get(e.messageId)??[];s.push(e),this.#e.set(e.messageId,s)}timeline(e){return this.#e.get(e)??[]}}export{a as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as i}from"./id-C_FRCsUM.js";class d{#e=new Map;add(r){const e={...r,createdAt:Date.now(),id:r.id??i("inapp"),read:!1};return this.#e.set(e.id,e),Promise.resolve(e)}list(r,e={}){let t=[...this.#e.values()].filter(s=>s.subscriberId===r);return e.unreadOnly&&(t=t.filter(s=>!s.read)),t.sort((s,o)=>o.createdAt-s.createdAt),Promise.resolve(e.limit?t.slice(0,e.limit):t)}markRead(r){const e=this.#e.get(r);return e&&(e.read=!0),Promise.resolve()}markAllRead(r){for(const e of this.#e.values())e.subscriberId===r&&(e.read=!0);return Promise.resolve()}unreadCount(r){let e=0;for(const t of this.#e.values())t.subscriberId===r&&!t.read&&(e+=1);return Promise.resolve(e)}remove(r){return this.#e.delete(r),Promise.resolve()}}export{d as MemoryInAppStore};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n}from"./id-C_FRCsUM.js";class r{#e=[];#t=new Map;enqueue(t,s){const e={attempts:0,id:n("job"),message:t,scheduledAt:s?.scheduledAt};return this.#e.push(e),e.id}reserve(){const t=Date.now(),s=this.#e.findIndex(i=>(i.scheduledAt??0)<=t);if(s===-1)return;const e=this.#e.splice(s,1)[0];return e.attempts+=1,this.#t.set(e.id,e),e}ack(t){this.#t.delete(t)}retry(t,s=0){const e=this.#t.get(t);e&&(this.#t.delete(t),e.scheduledAt=Date.now()+s,this.#e.push(e))}size(){return this.#e.length}}export{r as default};
|