@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.
Files changed (149) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/LICENSE.md +874 -0
  3. package/README.md +313 -6
  4. package/dist/channels/email/index.d.ts +46 -0
  5. package/dist/channels/email/index.js +1 -0
  6. package/dist/channels/inapp/index.d.ts +99 -0
  7. package/dist/channels/inapp/index.js +1 -0
  8. package/dist/digest/index.d.ts +128 -0
  9. package/dist/digest/index.js +1 -0
  10. package/dist/events/index.d.ts +37 -0
  11. package/dist/events/index.js +1 -0
  12. package/dist/i18n/index.d.ts +42 -0
  13. package/dist/i18n/index.js +1 -0
  14. package/dist/index.d.ts +174 -0
  15. package/dist/index.js +1 -0
  16. package/dist/layouts/index.d.ts +45 -0
  17. package/dist/layouts/index.js +1 -0
  18. package/dist/middleware/index.d.ts +382 -0
  19. package/dist/middleware/index.js +1 -0
  20. package/dist/packem_shared/MemoryDigestStore-Bw-sE5MI.js +1 -0
  21. package/dist/packem_shared/MemoryEventStore-BGD_xRxu.js +1 -0
  22. package/dist/packem_shared/MemoryInAppStore-48qlrDCx.js +1 -0
  23. package/dist/packem_shared/MemoryQueue-CXgWoZoY.js +1 -0
  24. package/dist/packem_shared/Notification-B22tuJPy.js +1 -0
  25. package/dist/packem_shared/NotificationError-DVfMJQ1u.js +1 -0
  26. package/dist/packem_shared/NotificationMessageBuilder-Br_aZusY.js +1 -0
  27. package/dist/packem_shared/RequiredOptionError-CuL42XRq.js +1 -0
  28. package/dist/packem_shared/UnstorageDigestStore-QAcO3Vb_.js +1 -0
  29. package/dist/packem_shared/UnstorageInAppStore-Bq2LoDMO.js +1 -0
  30. package/dist/packem_shared/apnsProvider-C9WSv5sc.js +1 -0
  31. package/dist/packem_shared/circuitBreakerMiddleware-BlZN7SVT.js +1 -0
  32. package/dist/packem_shared/composeMiddleware-D6dR8DUS.js +1 -0
  33. package/dist/packem_shared/createDigester-vMNPejGF.js +1 -0
  34. package/dist/packem_shared/createNotificationWorkflow-B70OgeED.js +1 -0
  35. package/dist/packem_shared/createQueueWorker-DjQBxjXc.js +1 -0
  36. package/dist/packem_shared/createTranslator-CY91C2eS.js +1 -0
  37. package/dist/packem_shared/credentials-CG0zkn-W.js +1 -0
  38. package/dist/packem_shared/dedupeMiddleware-CQmPJd_h.js +1 -0
  39. package/dist/packem_shared/defineLayout-73TNxYPq.js +1 -0
  40. package/dist/packem_shared/defineProvider-C9q-7iwt.js +1 -0
  41. package/dist/packem_shared/discordProvider-ewPfe-J7.js +1 -0
  42. package/dist/packem_shared/emailChannel-CNDlX96Q.js +1 -0
  43. package/dist/packem_shared/expoProvider-CXq101FD.js +1 -0
  44. package/dist/packem_shared/failoverProvider-D1dAmW8U.js +1 -0
  45. package/dist/packem_shared/fcmProvider-WdJGZ55l.js +1 -0
  46. package/dist/packem_shared/getHeader-C_gkdnMQ.js +1 -0
  47. package/dist/packem_shared/hmacBase64-BhhoX0uo.js +1 -0
  48. package/dist/packem_shared/http-BMYcUNBU.js +1 -0
  49. package/dist/packem_shared/id-C_FRCsUM.js +1 -0
  50. package/dist/packem_shared/inAppProvider-ElbahgSj.js +1 -0
  51. package/dist/packem_shared/loggingMiddleware-Cs6EDLcL.js +1 -0
  52. package/dist/packem_shared/messageBirdProvider-CHUFB0hd.js +1 -0
  53. package/dist/packem_shared/mockProvider-BLwTZlkw.js +1 -0
  54. package/dist/packem_shared/msTeamsProvider-DBhrmuSd.js +1 -0
  55. package/dist/packem_shared/notification.d-DFCVTods.d.ts +104 -0
  56. package/dist/packem_shared/otelProvider-b6LVo0BS.js +1 -0
  57. package/dist/packem_shared/plivoProvider-CIOl6DWw.js +1 -0
  58. package/dist/packem_shared/provider.d-BQAGriz6.d.ts +33 -0
  59. package/dist/packem_shared/rateLimitMiddleware-DWmEYq-m.js +1 -0
  60. package/dist/packem_shared/retryMiddleware-uUJDcUoP.js +1 -0
  61. package/dist/packem_shared/roundRobinProvider-BetXJUUm.js +1 -0
  62. package/dist/packem_shared/slackProvider-N1wNtAZ3.js +1 -0
  63. package/dist/packem_shared/slackWebhook-GEx_GdcV.js +1 -0
  64. package/dist/packem_shared/sms-CU-OZvNU.js +1 -0
  65. package/dist/packem_shared/snsProvider-KCciJ-nj.js +4 -0
  66. package/dist/packem_shared/snsWebhook-ChZnBBT3.js +1 -0
  67. package/dist/packem_shared/standardWebhook-B-LxP8U7.js +1 -0
  68. package/dist/packem_shared/suppressionMiddleware-CY-Qo1A_.js +1 -0
  69. package/dist/packem_shared/telegramProvider-jqR5BhJL.js +1 -0
  70. package/dist/packem_shared/telemetryMiddleware-B1N4k171.js +1 -0
  71. package/dist/packem_shared/telnyxProvider-C8TMPir1.js +1 -0
  72. package/dist/packem_shared/tracer.d-Co1s_NwG.d.ts +494 -0
  73. package/dist/packem_shared/twilioProvider-BxI0e6LX.js +1 -0
  74. package/dist/packem_shared/twilioWebhook-F0mTmGXD.js +1 -0
  75. package/dist/packem_shared/types.d-67TogK4k.d.ts +33 -0
  76. package/dist/packem_shared/types.d-C1GoEAlI.d-Bv3grfyD.d.ts +83 -0
  77. package/dist/packem_shared/types.d-CximoA8M.d.ts +29 -0
  78. package/dist/packem_shared/types.d-GUzX1jTk.d.ts +235 -0
  79. package/dist/packem_shared/types.d-td-F2Oh0.d.ts +10 -0
  80. package/dist/packem_shared/unstorage.DqlWKU2I.d-CogP3Etw.d.ts +120 -0
  81. package/dist/packem_shared/vonageProvider-BF76ca89.js +1 -0
  82. package/dist/packem_shared/webPushProvider-B962RwsA.js +1 -0
  83. package/dist/packem_shared/webcrypto-bY7wJCB5.js +1 -0
  84. package/dist/packem_shared/webhookProvider-BALSb2pc.js +1 -0
  85. package/dist/preferences/index.d.ts +49 -0
  86. package/dist/preferences/index.js +1 -0
  87. package/dist/providers/chat/discord/index.d.ts +14 -0
  88. package/dist/providers/chat/discord/index.js +1 -0
  89. package/dist/providers/chat/msteams/index.d.ts +14 -0
  90. package/dist/providers/chat/msteams/index.js +1 -0
  91. package/dist/providers/chat/slack/index.d.ts +19 -0
  92. package/dist/providers/chat/slack/index.js +1 -0
  93. package/dist/providers/chat/telegram/index.d.ts +18 -0
  94. package/dist/providers/chat/telegram/index.js +1 -0
  95. package/dist/providers/failover/index.d.ts +16 -0
  96. package/dist/providers/failover/index.js +1 -0
  97. package/dist/providers/mock/index.d.ts +29 -0
  98. package/dist/providers/mock/index.js +1 -0
  99. package/dist/providers/opentelemetry/index.d.ts +21 -0
  100. package/dist/providers/opentelemetry/index.js +1 -0
  101. package/dist/providers/push/apns/index.d.ts +24 -0
  102. package/dist/providers/push/apns/index.js +1 -0
  103. package/dist/providers/push/expo/index.d.ts +14 -0
  104. package/dist/providers/push/expo/index.js +1 -0
  105. package/dist/providers/push/fcm/index.d.ts +26 -0
  106. package/dist/providers/push/fcm/index.js +1 -0
  107. package/dist/providers/push/web-push/index.d.ts +36 -0
  108. package/dist/providers/push/web-push/index.js +1 -0
  109. package/dist/providers/roundrobin/index.d.ts +17 -0
  110. package/dist/providers/roundrobin/index.js +1 -0
  111. package/dist/providers/sms/messagebird/index.d.ts +16 -0
  112. package/dist/providers/sms/messagebird/index.js +1 -0
  113. package/dist/providers/sms/plivo/index.d.ts +18 -0
  114. package/dist/providers/sms/plivo/index.js +1 -0
  115. package/dist/providers/sms/sns/index.d.ts +21 -0
  116. package/dist/providers/sms/sns/index.js +1 -0
  117. package/dist/providers/sms/telnyx/index.d.ts +18 -0
  118. package/dist/providers/sms/telnyx/index.js +1 -0
  119. package/dist/providers/sms/twilio/index.d.ts +20 -0
  120. package/dist/providers/sms/twilio/index.js +1 -0
  121. package/dist/providers/sms/vonage/index.d.ts +18 -0
  122. package/dist/providers/sms/vonage/index.js +1 -0
  123. package/dist/providers/webhook/index.d.ts +18 -0
  124. package/dist/providers/webhook/index.js +1 -0
  125. package/dist/queue/bullmq-queue.d.ts +58 -0
  126. package/dist/queue/bullmq-queue.js +1 -0
  127. package/dist/queue/index.d.ts +50 -0
  128. package/dist/queue/index.js +1 -0
  129. package/dist/queue/pg-boss-queue.d.ts +66 -0
  130. package/dist/queue/pg-boss-queue.js +1 -0
  131. package/dist/queue/sqs-queue.d.ts +91 -0
  132. package/dist/queue/sqs-queue.js +1 -0
  133. package/dist/queue/unstorage-queue.d.ts +30 -0
  134. package/dist/queue/unstorage-queue.js +1 -0
  135. package/dist/routing/index.d.ts +35 -0
  136. package/dist/routing/index.js +1 -0
  137. package/dist/template-engines/handlebars.d.ts +16 -0
  138. package/dist/template-engines/handlebars.js +1 -0
  139. package/dist/template-engines/liquid.d.ts +16 -0
  140. package/dist/template-engines/liquid.js +1 -0
  141. package/dist/template-engines/string.d.ts +20 -0
  142. package/dist/template-engines/string.js +1 -0
  143. package/dist/utils/result.d.ts +54 -0
  144. package/dist/utils/result.js +1 -0
  145. package/dist/webhooks/index.d.ts +110 -0
  146. package/dist/webhooks/index.js +1 -0
  147. package/dist/workflow/index.d.ts +83 -0
  148. package/dist/workflow/index.js +1 -0
  149. package/package.json +283 -43
@@ -0,0 +1,494 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+ interface Context {
5
+ /**
6
+ * Get a value from the context.
7
+ *
8
+ * @param key key which identifies a context value
9
+ */
10
+ getValue(key: symbol): unknown;
11
+ /**
12
+ * Create a new context which inherits from this context and has
13
+ * the given key set to the given value.
14
+ *
15
+ * @param key context key for which to set the value
16
+ * @param value value to set for the given key
17
+ */
18
+ setValue(key: symbol, value: unknown): Context;
19
+ /**
20
+ * Return a new context which inherits from this context but does
21
+ * not contain a value for the given key.
22
+ *
23
+ * @param key context key for which to clear a value
24
+ */
25
+ deleteValue(key: symbol): Context;
26
+ }
27
+ /**
28
+ * Attributes is a map from string to attribute values.
29
+ *
30
+ * Note: only the own enumerable keys are counted as valid attribute keys.
31
+ *
32
+ * @since 1.3.0
33
+ */
34
+ interface Attributes {
35
+ [attributeKey: string]: AttributeValue | undefined;
36
+ }
37
+ /**
38
+ * Attribute values may be any non-nullish primitive value except an object.
39
+ *
40
+ * null or undefined attribute values are invalid and will result in undefined behavior.
41
+ *
42
+ * @since 1.3.0
43
+ */
44
+ type AttributeValue = string | number | boolean | Array<null | undefined | string> | Array<null | undefined | number> | Array<null | undefined | boolean>;
45
+ interface ExceptionWithCode {
46
+ code: string | number;
47
+ name?: string;
48
+ message?: string;
49
+ stack?: string;
50
+ }
51
+ interface ExceptionWithMessage {
52
+ code?: string | number;
53
+ message: string;
54
+ name?: string;
55
+ stack?: string;
56
+ }
57
+ interface ExceptionWithName {
58
+ code?: string | number;
59
+ message?: string;
60
+ name: string;
61
+ stack?: string;
62
+ }
63
+ /**
64
+ * Defines Exception.
65
+ *
66
+ * string or an object with one of (message or name or code) and optional stack
67
+ *
68
+ * @since 1.0.0
69
+ */
70
+ type Exception = ExceptionWithCode | ExceptionWithMessage | ExceptionWithName | string;
71
+ /**
72
+ * Defines High-Resolution Time.
73
+ *
74
+ * The first number, HrTime[0], is UNIX Epoch time in seconds since 00:00:00 UTC on 1 January 1970.
75
+ * The second number, HrTime[1], represents the partial second elapsed since Unix Epoch time represented by first number in nanoseconds.
76
+ * For example, 2021-01-01T12:30:10.150Z in UNIX Epoch time in milliseconds is represented as 1609504210150.
77
+ * The first number is calculated by converting and truncating the Epoch time in milliseconds to seconds:
78
+ * HrTime[0] = Math.trunc(1609504210150 / 1000) = 1609504210.
79
+ * The second number is calculated by converting the digits after the decimal point of the subtraction, (1609504210150 / 1000) - HrTime[0], to nanoseconds:
80
+ * HrTime[1] = Number((1609504210.150 - HrTime[0]).toFixed(9)) * 1e9 = 150000000.
81
+ * This is represented in HrTime format as [1609504210, 150000000].
82
+ *
83
+ * @since 1.0.0
84
+ */
85
+ type HrTime = [number, number];
86
+ /**
87
+ * Defines TimeInput.
88
+ *
89
+ * hrtime, epoch milliseconds, performance.now() or Date
90
+ *
91
+ * @since 1.0.0
92
+ */
93
+ type TimeInput = HrTime | number | Date;
94
+ /**
95
+ * @deprecated please use {@link Attributes}
96
+ * @since 1.0.0
97
+ */
98
+ type SpanAttributes = Attributes;
99
+ /**
100
+ * @deprecated please use {@link AttributeValue}
101
+ * @since 1.0.0
102
+ */
103
+ type SpanAttributeValue = AttributeValue;
104
+ /**
105
+ * @since 1.0.0
106
+ */
107
+ interface TraceState {
108
+ /**
109
+ * Create a new TraceState which inherits from this TraceState and has the
110
+ * given key set.
111
+ * The new entry will always be added in the front of the list of states.
112
+ *
113
+ * @param key key of the TraceState entry.
114
+ * @param value value of the TraceState entry.
115
+ */
116
+ set(key: string, value: string): TraceState;
117
+ /**
118
+ * Return a new TraceState which inherits from this TraceState but does not
119
+ * contain the given key.
120
+ *
121
+ * @param key the key for the TraceState entry to be removed.
122
+ */
123
+ unset(key: string): TraceState;
124
+ /**
125
+ * Returns the value to which the specified key is mapped, or `undefined` if
126
+ * this map contains no mapping for the key.
127
+ *
128
+ * @param key with which the specified value is to be associated.
129
+ * @returns the value to which the specified key is mapped, or `undefined` if
130
+ * this map contains no mapping for the key.
131
+ */
132
+ get(key: string): string | undefined;
133
+ /**
134
+ * Serializes the TraceState to a `list` as defined below. The `list` is a
135
+ * series of `list-members` separated by commas `,`, and a list-member is a
136
+ * key/value pair separated by an equals sign `=`. Spaces and horizontal tabs
137
+ * surrounding `list-members` are ignored. There can be a maximum of 32
138
+ * `list-members` in a `list`.
139
+ *
140
+ * @returns the serialized string.
141
+ */
142
+ serialize(): string;
143
+ }
144
+ /**
145
+ * A SpanContext represents the portion of a {@link Span} which must be
146
+ * serialized and propagated along side of a {@link Baggage}.
147
+ *
148
+ * @since 1.0.0
149
+ */
150
+ interface SpanContext {
151
+ /**
152
+ * The ID of the trace that this span belongs to. It is worldwide unique
153
+ * with practically sufficient probability by being made as 16 randomly
154
+ * generated bytes, encoded as a 32 lowercase hex characters corresponding to
155
+ * 128 bits.
156
+ */
157
+ traceId: string;
158
+ /**
159
+ * The ID of the Span. It is globally unique with practically sufficient
160
+ * probability by being made as 8 randomly generated bytes, encoded as a 16
161
+ * lowercase hex characters corresponding to 64 bits.
162
+ */
163
+ spanId: string;
164
+ /**
165
+ * Only true if the SpanContext was propagated from a remote parent.
166
+ */
167
+ isRemote?: boolean;
168
+ /**
169
+ * Trace flags to propagate.
170
+ *
171
+ * It is represented as 1 byte (bitmap). Bit to represent whether trace is
172
+ * sampled or not. When set, the least significant bit documents that the
173
+ * caller may have recorded trace data. A caller who does not record trace
174
+ * data out-of-band leaves this flag unset.
175
+ *
176
+ * see {@link TraceFlags} for valid flag values.
177
+ */
178
+ traceFlags: number;
179
+ /**
180
+ * Tracing-system-specific info to propagate.
181
+ *
182
+ * The tracestate field value is a `list` as defined below. The `list` is a
183
+ * series of `list-members` separated by commas `,`, and a list-member is a
184
+ * key/value pair separated by an equals sign `=`. Spaces and horizontal tabs
185
+ * surrounding `list-members` are ignored. There can be a maximum of 32
186
+ * `list-members` in a `list`.
187
+ * More Info: https://www.w3.org/TR/trace-context/#tracestate-field
188
+ *
189
+ * Examples:
190
+ * Single tracing system (generic format):
191
+ * tracestate: rojo=00f067aa0ba902b7
192
+ * Multiple tracing systems (with different formatting):
193
+ * tracestate: rojo=00f067aa0ba902b7,congo=t61rcWkgMzE
194
+ */
195
+ traceState?: TraceState;
196
+ }
197
+ /**
198
+ * @since 1.0.0
199
+ */
200
+ interface SpanStatus {
201
+ /** The status code of this message. */
202
+ code: SpanStatusCode;
203
+ /** A developer-facing error message. */
204
+ message?: string;
205
+ }
206
+ /**
207
+ * An enumeration of status codes.
208
+ *
209
+ * @since 1.0.0
210
+ */
211
+ declare enum SpanStatusCode {
212
+ /**
213
+ * The default status.
214
+ */
215
+ UNSET = 0,
216
+ /**
217
+ * The operation has been validated by an Application developer or
218
+ * Operator to have completed successfully.
219
+ */
220
+ OK = 1,
221
+ /**
222
+ * The operation contains an error.
223
+ */
224
+ ERROR = 2,
225
+ }
226
+ /**
227
+ * A pointer from the current {@link Span} to another span in the same trace or
228
+ * in a different trace.
229
+ * Few examples of Link usage.
230
+ * 1. Batch Processing: A batch of elements may contain elements associated
231
+ * with one or more traces/spans. Since there can only be one parent
232
+ * SpanContext, Link is used to keep reference to SpanContext of all
233
+ * elements in the batch.
234
+ * 2. Public Endpoint: A SpanContext in incoming client request on a public
235
+ * endpoint is untrusted from service provider perspective. In such case it
236
+ * is advisable to start a new trace with appropriate sampling decision.
237
+ * However, it is desirable to associate incoming SpanContext to new trace
238
+ * initiated on service provider side so two traces (from Client and from
239
+ * Service Provider) can be correlated.
240
+ *
241
+ * @since 1.0.0
242
+ */
243
+ interface Link {
244
+ /** The {@link SpanContext} of a linked span. */
245
+ context: SpanContext;
246
+ /** A set of {@link SpanAttributes} on the link. */
247
+ attributes?: SpanAttributes;
248
+ /** Count of attributes of the link that were dropped due to collection limits */
249
+ droppedAttributesCount?: number;
250
+ }
251
+ /**
252
+ * An interface that represents a span. A span represents a single operation
253
+ * within a trace. Examples of span might include remote procedure calls or a
254
+ * in-process function calls to sub-components. A Trace has a single, top-level
255
+ * "root" Span that in turn may have zero or more child Spans, which in turn
256
+ * may have children.
257
+ *
258
+ * Spans are created by the {@link Tracer.startSpan} method.
259
+ *
260
+ * @since 1.0.0
261
+ */
262
+ interface Span {
263
+ /**
264
+ * Returns the {@link SpanContext} object associated with this Span.
265
+ *
266
+ * Get an immutable, serializable identifier for this span that can be used
267
+ * to create new child spans. Returned SpanContext is usable even after the
268
+ * span ends.
269
+ *
270
+ * @returns the SpanContext object associated with this Span.
271
+ */
272
+ spanContext(): SpanContext;
273
+ /**
274
+ * Sets an attribute to the span.
275
+ *
276
+ * Sets a single Attribute with the key and value passed as arguments.
277
+ *
278
+ * @param key the key for this attribute.
279
+ * @param value the value for this attribute. Setting a value null or
280
+ * undefined is invalid and will result in undefined behavior.
281
+ */
282
+ setAttribute(key: string, value: SpanAttributeValue): this;
283
+ /**
284
+ * Sets attributes to the span.
285
+ *
286
+ * @param attributes the attributes that will be added.
287
+ * null or undefined attribute values
288
+ * are invalid and will result in undefined behavior.
289
+ */
290
+ setAttributes(attributes: SpanAttributes): this;
291
+ /**
292
+ * Adds an event to the Span.
293
+ *
294
+ * @param name the name of the event.
295
+ * @param [attributesOrStartTime] the attributes that will be added; these are
296
+ * associated with this event. Can be also a start time
297
+ * if type is {@type TimeInput} and 3rd param is undefined
298
+ * @param [startTime] start time of the event.
299
+ */
300
+ addEvent(name: string, attributesOrStartTime?: SpanAttributes | TimeInput, startTime?: TimeInput): this;
301
+ /**
302
+ * Adds a single link to the span.
303
+ *
304
+ * Links added after the creation will not affect the sampling decision.
305
+ * It is preferred span links be added at span creation.
306
+ *
307
+ * @param link the link to add.
308
+ */
309
+ addLink(link: Link): this;
310
+ /**
311
+ * Adds multiple links to the span.
312
+ *
313
+ * Links added after the creation will not affect the sampling decision.
314
+ * It is preferred span links be added at span creation.
315
+ *
316
+ * @param links the links to add.
317
+ */
318
+ addLinks(links: Link[]): this;
319
+ /**
320
+ * Sets the status of the span.
321
+ *
322
+ * By default, a span has status {@link SpanStatusCode.UNSET}.
323
+ * Calling this method overrides that default.
324
+ *
325
+ * The status codes have a total order: `OK > ERROR > UNSET`.
326
+ *
327
+ * - Once {@link SpanStatusCode.OK} is set, any further attempts to change
328
+ * the status are ignored.
329
+ * - Any attempt to set {@link SpanStatusCode.UNSET} is always ignored.
330
+ *
331
+ * The `message` field is only used when {@link SpanStatusCode.ERROR} is set.
332
+ * For all other status codes, `message` is ignored.
333
+ *
334
+ * @param status The {@link SpanStatus} to set.
335
+ */
336
+ setStatus(status: SpanStatus): this;
337
+ /**
338
+ * Updates the Span name.
339
+ *
340
+ * This will override the name provided via {@link Tracer.startSpan}.
341
+ *
342
+ * Upon this update, any sampling behavior based on Span name will depend on
343
+ * the implementation.
344
+ *
345
+ * @param name the Span name.
346
+ */
347
+ updateName(name: string): this;
348
+ /**
349
+ * Marks the end of Span execution.
350
+ *
351
+ * Call to End of a Span MUST not have any effects on child spans. Those may
352
+ * still be running and can be ended later.
353
+ *
354
+ * Do not return `this`. The Span generally should not be used after it
355
+ * is ended so chaining is not desired in this context.
356
+ *
357
+ * @param [endTime] the time to set as Span's end time. If not provided,
358
+ * use the current time as the span's end time.
359
+ */
360
+ end(endTime?: TimeInput): void;
361
+ /**
362
+ * Returns the flag whether this span will be recorded.
363
+ *
364
+ * @returns true if this Span is active and recording information like events
365
+ * with the `AddEvent` operation and attributes using `setAttributes`.
366
+ */
367
+ isRecording(): boolean;
368
+ /**
369
+ * Sets exception as a span event
370
+ * @param exception the exception the only accepted values are string or Error
371
+ * @param [time] the time to set as Span's event time. If not provided,
372
+ * use the current time.
373
+ */
374
+ recordException(exception: Exception, time?: TimeInput): void;
375
+ }
376
+ /**
377
+ * @since 1.0.0
378
+ */
379
+ declare enum SpanKind {
380
+ /** Default value. Indicates that the span is used internally. */
381
+ INTERNAL = 0,
382
+ /**
383
+ * Indicates that the span covers server-side handling of an RPC or other
384
+ * remote request.
385
+ */
386
+ SERVER = 1,
387
+ /**
388
+ * Indicates that the span covers the client-side wrapper around an RPC or
389
+ * other remote request.
390
+ */
391
+ CLIENT = 2,
392
+ /**
393
+ * Indicates that the span describes producer sending a message to a
394
+ * broker. Unlike client and server, there is no direct critical path latency
395
+ * relationship between producer and consumer spans.
396
+ */
397
+ PRODUCER = 3,
398
+ /**
399
+ * Indicates that the span describes consumer receiving a message from a
400
+ * broker. Unlike client and server, there is no direct critical path latency
401
+ * relationship between producer and consumer spans.
402
+ */
403
+ CONSUMER = 4,
404
+ }
405
+ /**
406
+ * Options needed for span creation
407
+ *
408
+ * @since 1.0.0
409
+ */
410
+ interface SpanOptions {
411
+ /**
412
+ * The SpanKind of a span
413
+ * @default {@link SpanKind.INTERNAL}
414
+ */
415
+ kind?: SpanKind;
416
+ /** A span's attributes */
417
+ attributes?: Attributes;
418
+ /** {@link Link}s span to other spans */
419
+ links?: Link[];
420
+ /** A manually specified start time for the created `Span` object. */
421
+ startTime?: TimeInput;
422
+ /** The new span should be a root span. (Ignore parent from context). */
423
+ root?: boolean;
424
+ }
425
+ /**
426
+ * Tracer provides an interface for creating {@link Span}s.
427
+ *
428
+ * @since 1.0.0
429
+ */
430
+ interface Tracer {
431
+ /**
432
+ * Starts a new {@link Span}. Start the span without setting it on context.
433
+ *
434
+ * This method do NOT modify the current Context.
435
+ *
436
+ * @param name The name of the span
437
+ * @param [options] SpanOptions used for span creation
438
+ * @param [context] Context to use to extract parent
439
+ * @returns Span The newly created span
440
+ * @example
441
+ * const span = tracer.startSpan('op');
442
+ * span.setAttribute('key', 'value');
443
+ * span.end();
444
+ */
445
+ startSpan(name: string, options?: SpanOptions, context?: Context): Span;
446
+ /**
447
+ * Starts a new {@link Span} and calls the given function passing it the
448
+ * created span as first argument.
449
+ * Additionally the new span gets set in context and this context is activated
450
+ * for the duration of the function call.
451
+ *
452
+ * @param name The name of the span
453
+ * @param [options] SpanOptions used for span creation
454
+ * @param [context] Context to use to extract parent
455
+ * @param fn function called in the context of the span and receives the newly created span as an argument
456
+ * @returns return value of fn
457
+ * @example
458
+ * const something = tracer.startActiveSpan('op', span => {
459
+ * try {
460
+ * do some work
461
+ * span.setStatus({code: SpanStatusCode.OK});
462
+ * return something;
463
+ * } catch (err) {
464
+ * span.setStatus({
465
+ * code: SpanStatusCode.ERROR,
466
+ * message: err.message,
467
+ * });
468
+ * throw err;
469
+ * } finally {
470
+ * span.end();
471
+ * }
472
+ * });
473
+ *
474
+ * @example
475
+ * const span = tracer.startActiveSpan('op', span => {
476
+ * try {
477
+ * do some work
478
+ * return span;
479
+ * } catch (err) {
480
+ * span.setStatus({
481
+ * code: SpanStatusCode.ERROR,
482
+ * message: err.message,
483
+ * });
484
+ * throw err;
485
+ * }
486
+ * });
487
+ * do some more work
488
+ * span.end();
489
+ */
490
+ startActiveSpan<F extends (span: Span) => unknown>(name: string, fn: F): ReturnType<F>;
491
+ startActiveSpan<F extends (span: Span) => unknown>(name: string, options: SpanOptions, fn: F): ReturnType<F>;
492
+ startActiveSpan<F extends (span: Span) => unknown>(name: string, options: SpanOptions, context: Context, fn: F): ReturnType<F>;
493
+ }
494
+ export { Attributes as A, Context as C, Tracer as T };
@@ -0,0 +1 @@
1
+ import n from"./RequiredOptionError-CuL42XRq.js";import{defineProvider as g}from"./defineProvider-C9q-7iwt.js";import{b as S,t as h}from"./credentials-CG0zkn-W.js";import{r as w}from"./http-BMYcUNBU.js";import{s as y,b as T}from"./sms-CU-OZvNU.js";const v="https://api.twilio.com",M=g(d=>{const e=d??{};if(!e.accountSid)throw new n("twilio","accountSid");if(!e.authToken)throw new n("twilio","authToken");const a=e.endpoint??v,c=e.retries??3,u=e.timeout??3e4,m=`${a}/2010-04-01/Accounts/${e.accountSid}/Messages.json`,l=S(e.accountSid,e.authToken),f=async(t,o)=>{const i=new URLSearchParams;i.set("To",t),i.set("Body",o.text);const r=o.from??e.from;if(e.messagingServiceSid)i.set("MessagingServiceSid",e.messagingServiceSid);else if(r)i.set("From",r);else return{error:"Missing sender: provide `from` on the payload or provider config",id:t,status:"failed"};for(const p of o.mediaUrls??[])i.append("MediaUrl",p);const s=await w(m,{body:i.toString(),headers:{Authorization:l,"Content-Type":"application/x-www-form-urlencoded"},method:"POST",timeout:u},c);return!s.success||!s.data?{error:s.error instanceof Error?s.error.message:"Request failed",id:t,status:"failed"}:s.data.status>=400?{error:s.data.body.error_message??`HTTP ${String(s.data.status)}`,id:t,status:"failed"}:{id:t,messageId:s.data.body.sid,status:"sent"}};return{channel:"sms",endpoint:a,features:{batchSending:!1,deliveryReceipts:!0,media:!0,scheduling:!0},id:"twilio",initialize:()=>{},isAvailable:()=>!!(e.accountSid&&e.authToken),options:e,send:async t=>{const o=await y(h(t.to),async i=>f(i,t));return T("twilio",o)},validateCredentials:()=>!!(e.accountSid&&e.authToken)}});export{M as default};
@@ -0,0 +1 @@
1
+ import{hmacBase64 as u,timingSafeEqual as c}from"./hmacBase64-BhhoX0uo.js";import{getHeader as o}from"./getHeader-C_gkdnMQ.js";const f="X-Twilio-Signature",m={delivered:"delivered",failed:"failed",queued:"queued",sending:"queued",sent:"sent",undelivered:"failed"},S=(i,e)=>{const r=Object.keys(e).toSorted((a,s)=>a.localeCompare(s));let t=i;for(const a of r)t+=`${a}${e[a]??""}`;return t},n=i=>{const e={};return new URLSearchParams(i).forEach((r,t)=>{e[t]=r}),e},g={parse:i=>{const e=n(i),r=e.MessageStatus??e.SmsStatus??e.CallStatus;if(r===void 0)return;const t=m[r.toLowerCase()];return t===void 0?void 0:{channel:"sms",messageId:e.MessageSid??e.SmsSid??e.CallSid??"",provider:"twilio",recipient:e.To,timestamp:new Date,type:t}},verify:async(i,e,r)=>{if(r.trim()==="")return!1;const t=o(e,f),a=o(e,"x-twilio-signature-url");if(t===void 0||a===void 0)return!1;const s=n(i),d=S(a,s),l=await u(r,d,"SHA-1");return c(l,t)}};export{g as default,g as twilioWebhook};
@@ -0,0 +1,33 @@
1
+ import { a as NotificationMessage } from "./notification.d-DFCVTods.js";
2
+ /**
3
+ * A queued notification job.
4
+ */
5
+ interface QueueJob {
6
+ /** Number of delivery attempts so far. */
7
+ attempts: number;
8
+ /** Unique job id. */
9
+ id: string;
10
+ /** The multi-channel message to deliver. */
11
+ message: NotificationMessage;
12
+ /** Epoch ms before which the job must not be reserved. */
13
+ scheduledAt?: number;
14
+ }
15
+ /**
16
+ * A durable notification queue. The default {@link import("./memory-queue").MemoryQueue}
17
+ * is in-process; adapters (unstorage, BullMQ, ...) back it with external stores.
18
+ */
19
+ interface NotificationQueue {
20
+ /** Acknowledges a reserved job as completed, removing it. */
21
+ ack: (id: string) => Promise<void> | void;
22
+ /** Adds a message to the queue, returning its job id. */
23
+ enqueue: (message: NotificationMessage, options?: {
24
+ scheduledAt?: number;
25
+ }) => Promise<string> | string;
26
+ /** Reserves the next due job, or undefined when none are ready. */
27
+ reserve: () => Promise<QueueJob | undefined> | (QueueJob | undefined);
28
+ /** Returns a reserved job to the queue, optionally delaying it. */
29
+ retry: (id: string, delayMs?: number) => Promise<void> | void;
30
+ /** Returns the number of pending jobs. */
31
+ size: () => Promise<number> | number;
32
+ }
33
+ export { NotificationQueue as N, QueueJob as Q };
@@ -0,0 +1,83 @@
1
+ import { StandardSchemaV1 } from '@standard-schema/spec';
2
+ /** A value that may be returned directly or as a promise. */
3
+ type MaybePromise<T> = Promise<T> | T;
4
+ /**
5
+ * A human-friendly duration. Either a raw millisecond count, a structured
6
+ * `{ amount, unit }` pair, or a `{ cron }` expression resolved against "now".
7
+ */
8
+ type Duration = number | {
9
+ amount: number;
10
+ unit: DurationUnit;
11
+ } | {
12
+ cron: string;
13
+ tz?: string;
14
+ };
15
+ /** Units accepted by the structured {@link Duration} form. */
16
+ type DurationUnit = "days" | "hours" | "milliseconds" | "minutes" | "ms" | "seconds" | "weeks";
17
+ /** A JSON-serialisable snapshot of an `Error`, persisted in run history. */
18
+
19
+ /**
20
+ * The context handed to a workflow body. Every durable operation goes through
21
+ * `ctx` so the engine can record, skip and resume it deterministically.
22
+ *
23
+ * IMPORTANT: any side effect that must run *exactly once* has to be wrapped in
24
+ * {@link RunContext.step}. Code outside `step`/`sleep`/`waitForEvent` re-executes
25
+ * on every replay.
26
+ */
27
+ interface RunContext<PayloadT = unknown> {
28
+ /** The validated trigger payload. */
29
+ readonly payload: PayloadT;
30
+ /** The id of the current run. */
31
+ readonly runId: string;
32
+ /**
33
+ * Durably pause the run for a duration, then resume.
34
+ * @param id A stable, unique id for this sleep.
35
+ * @param duration How long to pause.
36
+ */
37
+ sleep: (id: string, duration: Duration) => Promise<void>;
38
+ /**
39
+ * Run a side effect exactly once. The result is recorded; on replay the
40
+ * recorded value is returned without re-executing the function.
41
+ * @param id A stable, unique id for this step within the workflow.
42
+ * @param function_ The side effect to run.
43
+ */
44
+ step: <T>(id: string, function_: () => MaybePromise<T>) => Promise<T>;
45
+ /**
46
+ * Durably suspend until an external event is delivered via
47
+ * `runtime.signal(runId, name, payload)`, or the optional timeout elapses.
48
+ * @param id A stable, unique id for this wait.
49
+ * @param name The event name to wait for.
50
+ * @param options Optional settings for the wait.
51
+ * @param options.timeout How long to wait before resolving to `undefined`.
52
+ * @returns The signalled payload, or `undefined` on timeout.
53
+ */
54
+ waitForEvent: <T = unknown>(id: string, name: string, options?: {
55
+ timeout?: Duration;
56
+ }) => Promise<T | undefined>;
57
+ }
58
+ /** The body of a workflow: an async function driven by {@link RunContext}. */
59
+ type WorkflowRun<PayloadT, OutputT> = (context: RunContext<PayloadT>) => MaybePromise<OutputT>;
60
+ /** Options accepted by `defineWorkflow`. */
61
+ interface WorkflowConfig<PayloadT, OutputT> {
62
+ /** Unique id of the workflow, used as the namespace for run ids and storage. */
63
+ id: string;
64
+ /** Optional Standard Schema validating (and typing) the trigger payload. */
65
+ payload?: StandardSchemaV1<unknown, PayloadT>;
66
+ /** The workflow body. */
67
+ run: WorkflowRun<PayloadT, OutputT>;
68
+ /** Optional free-form tags for routing/observability. */
69
+ tags?: string[];
70
+ }
71
+ /** A defined workflow: the config plus the validated payload-schema accessor. */
72
+ interface WorkflowDefinition<PayloadT = unknown, OutputT = unknown> extends WorkflowConfig<PayloadT, OutputT> {
73
+ /** Validate (and parse) an unknown input against the payload schema. */
74
+ parsePayload: (input: unknown) => Promise<PayloadT>;
75
+ /** Brand marking this object as a defined workflow. */
76
+ readonly [WORKFLOW_BRAND]: true;
77
+ }
78
+ /**
79
+ * The persisted form of a run. `snapshot` is the opaque XState persisted
80
+ * snapshot; `status`, `wakeAt` and `eventName` are denormalised so a store can
81
+ * answer {@link WorkflowStore.due} and signal lookups without parsing it.
82
+ */
83
+ export { Duration as D, MaybePromise as M, WorkflowConfig as W, WorkflowDefinition as a };
@@ -0,0 +1,29 @@
1
+ import { C as ChannelType, B as BaseNotificationPayload, a as NotificationResult, R as Result } from "./types.d-GUzX1jTk.js";
2
+ /**
3
+ * Context passed through the middleware chain for a single send.
4
+ */
5
+ interface SendContext {
6
+ /** The channel being sent on. */
7
+ channel: ChannelType;
8
+ /** The (possibly mutated) payload. */
9
+ payload: BaseNotificationPayload;
10
+ /** The provider id handling the send. */
11
+ provider: string;
12
+ }
13
+ /**
14
+ * The terminal send function and the type middleware wrap.
15
+ */
16
+ type SendFunction = (context: SendContext) => Promise<Result<NotificationResult>>;
17
+ /**
18
+ * A middleware wraps a {@link SendFunction}. The first registered middleware is the
19
+ * outermost wrapper (runs first on the way in, last on the way out).
20
+ */
21
+ type Middleware = (context: SendContext, next: SendFunction) => Promise<Result<NotificationResult>>;
22
+ /**
23
+ * Composes middleware around a terminal send function.
24
+ * @param middlewares Middleware in registration order.
25
+ * @param terminal The terminal send function.
26
+ * @returns A single composed send function.
27
+ */
28
+ declare const composeMiddleware: (middlewares: Middleware[], terminal: SendFunction) => SendFunction;
29
+ export { Middleware as M, SendContext as S, SendFunction as a, composeMiddleware as c };