@christian-ek/sweego 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/README.md +357 -0
  2. package/dist/client/_generated/_ignore.d.ts +1 -0
  3. package/dist/client/_generated/_ignore.d.ts.map +1 -0
  4. package/dist/client/_generated/_ignore.js +3 -0
  5. package/dist/client/_generated/_ignore.js.map +1 -0
  6. package/dist/client/index.d.ts +282 -0
  7. package/dist/client/index.d.ts.map +1 -0
  8. package/dist/client/index.js +265 -0
  9. package/dist/client/index.js.map +1 -0
  10. package/dist/client/webhook.d.ts +42 -0
  11. package/dist/client/webhook.d.ts.map +1 -0
  12. package/dist/client/webhook.js +89 -0
  13. package/dist/client/webhook.js.map +1 -0
  14. package/dist/component/_generated/api.d.ts +43 -0
  15. package/dist/component/_generated/api.d.ts.map +1 -0
  16. package/dist/component/_generated/api.js +31 -0
  17. package/dist/component/_generated/api.js.map +1 -0
  18. package/dist/component/_generated/component.d.ts +226 -0
  19. package/dist/component/_generated/component.d.ts.map +1 -0
  20. package/dist/component/_generated/component.js +11 -0
  21. package/dist/component/_generated/component.js.map +1 -0
  22. package/dist/component/_generated/dataModel.d.ts +46 -0
  23. package/dist/component/_generated/dataModel.d.ts.map +1 -0
  24. package/dist/component/_generated/dataModel.js +11 -0
  25. package/dist/component/_generated/dataModel.js.map +1 -0
  26. package/dist/component/_generated/server.d.ts +121 -0
  27. package/dist/component/_generated/server.d.ts.map +1 -0
  28. package/dist/component/_generated/server.js +78 -0
  29. package/dist/component/_generated/server.js.map +1 -0
  30. package/dist/component/convex.config.d.ts +3 -0
  31. package/dist/component/convex.config.d.ts.map +1 -0
  32. package/dist/component/convex.config.js +10 -0
  33. package/dist/component/convex.config.js.map +1 -0
  34. package/dist/component/lib.d.ts +319 -0
  35. package/dist/component/lib.d.ts.map +1 -0
  36. package/dist/component/lib.js +725 -0
  37. package/dist/component/lib.js.map +1 -0
  38. package/dist/component/schema.d.ts +259 -0
  39. package/dist/component/schema.d.ts.map +1 -0
  40. package/dist/component/schema.js +99 -0
  41. package/dist/component/schema.js.map +1 -0
  42. package/dist/component/shared.d.ts +280 -0
  43. package/dist/component/shared.d.ts.map +1 -0
  44. package/dist/component/shared.js +213 -0
  45. package/dist/component/shared.js.map +1 -0
  46. package/dist/component/sweego.d.ts +95 -0
  47. package/dist/component/sweego.d.ts.map +1 -0
  48. package/dist/component/sweego.js +210 -0
  49. package/dist/component/sweego.js.map +1 -0
  50. package/dist/component/utils.d.ts +16 -0
  51. package/dist/component/utils.d.ts.map +1 -0
  52. package/dist/component/utils.js +29 -0
  53. package/dist/component/utils.js.map +1 -0
  54. package/package.json +100 -0
  55. package/src/client/_generated/_ignore.ts +1 -0
  56. package/src/client/index.ts +490 -0
  57. package/src/client/webhook.test.ts +146 -0
  58. package/src/client/webhook.ts +130 -0
  59. package/src/component/_generated/api.ts +59 -0
  60. package/src/component/_generated/component.ts +244 -0
  61. package/src/component/_generated/dataModel.ts +60 -0
  62. package/src/component/_generated/server.ts +156 -0
  63. package/src/component/convex.config.ts +12 -0
  64. package/src/component/lib.test.ts +189 -0
  65. package/src/component/lib.ts +835 -0
  66. package/src/component/schema.ts +117 -0
  67. package/src/component/shared.test.ts +64 -0
  68. package/src/component/shared.ts +315 -0
  69. package/src/component/sweego.test.ts +141 -0
  70. package/src/component/sweego.ts +310 -0
  71. package/src/component/utils.ts +35 -0
  72. package/src/test.ts +20 -0
@@ -0,0 +1,280 @@
1
+ import { type GenericActionCtx, type GenericDataModel, type GenericMutationCtx, type GenericQueryCtx } from "convex/server";
2
+ import { type Infer } from "convex/values";
3
+ export declare const SWEEGO_API_BASE_URL = "https://api.sweego.io";
4
+ export declare const DEFAULT_PROVIDER = "sweego";
5
+ export declare const vChannel: import("convex/values").VUnion<"email" | "sms", [import("convex/values").VLiteral<"email", "required">, import("convex/values").VLiteral<"sms", "required">], "required", never>;
6
+ export type Channel = Infer<typeof vChannel>;
7
+ export declare const vEmailAddress: import("convex/values").VObject<{
8
+ name?: string | undefined;
9
+ email: string;
10
+ }, {
11
+ email: import("convex/values").VString<string, "required">;
12
+ name: import("convex/values").VString<string | undefined, "optional">;
13
+ }, "required", "email" | "name">;
14
+ export type EmailAddress = Infer<typeof vEmailAddress>;
15
+ export declare const vVariables: import("convex/values").VRecord<Record<string, string | number | boolean>, import("convex/values").VString<string, "required">, import("convex/values").VUnion<string | number | boolean, [import("convex/values").VString<string, "required">, import("convex/values").VFloat64<number, "required">, import("convex/values").VBoolean<boolean, "required">], "required", never>, "required", string>;
16
+ export type Variables = Infer<typeof vVariables>;
17
+ export declare const vEmailRecipient: import("convex/values").VObject<{
18
+ name?: string | undefined;
19
+ variables?: Record<string, string | number | boolean> | undefined;
20
+ email: string;
21
+ }, {
22
+ email: import("convex/values").VString<string, "required">;
23
+ name: import("convex/values").VString<string | undefined, "optional">;
24
+ variables: import("convex/values").VRecord<Record<string, string | number | boolean> | undefined, import("convex/values").VString<string, "required">, import("convex/values").VUnion<string | number | boolean, [import("convex/values").VString<string, "required">, import("convex/values").VFloat64<number, "required">, import("convex/values").VBoolean<boolean, "required">], "required", never>, "optional", string>;
25
+ }, "required", "email" | "name" | "variables" | `variables.${string}`>;
26
+ export type EmailRecipient = Infer<typeof vEmailRecipient>;
27
+ export declare const vSmsRecipient: import("convex/values").VObject<{
28
+ num: string;
29
+ region: string;
30
+ }, {
31
+ num: import("convex/values").VString<string, "required">;
32
+ region: import("convex/values").VString<string, "required">;
33
+ }, "required", "num" | "region">;
34
+ export type SmsRecipient = Infer<typeof vSmsRecipient>;
35
+ export declare const vAttachment: import("convex/values").VObject<{
36
+ contentId?: string | undefined;
37
+ disposition?: "attachment" | "inline" | undefined;
38
+ isRelated?: boolean | undefined;
39
+ content: string;
40
+ filename: string;
41
+ }, {
42
+ content: import("convex/values").VString<string, "required">;
43
+ filename: import("convex/values").VString<string, "required">;
44
+ contentId: import("convex/values").VString<string | undefined, "optional">;
45
+ disposition: import("convex/values").VUnion<"attachment" | "inline" | undefined, [import("convex/values").VLiteral<"attachment", "required">, import("convex/values").VLiteral<"inline", "required">], "optional", never>;
46
+ isRelated: import("convex/values").VBoolean<boolean | undefined, "optional">;
47
+ }, "required", "content" | "filename" | "contentId" | "disposition" | "isRelated">;
48
+ export type Attachment = Infer<typeof vAttachment>;
49
+ export declare const vListUnsub: import("convex/values").VObject<{
50
+ method?: "mailto" | "one-click" | undefined;
51
+ value: string;
52
+ }, {
53
+ method: import("convex/values").VUnion<"mailto" | "one-click" | undefined, [import("convex/values").VLiteral<"mailto", "required">, import("convex/values").VLiteral<"one-click", "required">], "optional", never>;
54
+ value: import("convex/values").VString<string, "required">;
55
+ }, "required", "method" | "value">;
56
+ export type ListUnsub = Infer<typeof vListUnsub>;
57
+ export declare const vEmailCampaignType: import("convex/values").VUnion<"market" | "newsletter" | "transac", [import("convex/values").VLiteral<"market", "required">, import("convex/values").VLiteral<"newsletter", "required">, import("convex/values").VLiteral<"transac", "required">], "required", never>;
58
+ export declare const vSmsCampaignType: import("convex/values").VUnion<"market" | "transac", [import("convex/values").VLiteral<"market", "required">, import("convex/values").VLiteral<"transac", "required">], "required", never>;
59
+ export type SmsCampaignType = Infer<typeof vSmsCampaignType>;
60
+ export declare const vSendStatus: import("convex/values").VUnion<"sent" | "queued" | "failed" | "cancelled", [import("convex/values").VLiteral<"queued", "required">, import("convex/values").VLiteral<"sent", "required">, import("convex/values").VLiteral<"failed", "required">, import("convex/values").VLiteral<"cancelled", "required">], "required", never>;
61
+ export type SendStatus = Infer<typeof vSendStatus>;
62
+ export declare const vDeliveryStatus: import("convex/values").VUnion<"pending" | "sent" | "delivered" | "soft_bounced" | "bounced" | "undelivered" | "stopped", [import("convex/values").VLiteral<"pending", "required">, import("convex/values").VLiteral<"sent", "required">, import("convex/values").VLiteral<"delivered", "required">, import("convex/values").VLiteral<"soft_bounced", "required">, import("convex/values").VLiteral<"bounced", "required">, import("convex/values").VLiteral<"undelivered", "required">, import("convex/values").VLiteral<"stopped", "required">], "required", never>;
63
+ export type DeliveryStatus = Infer<typeof vDeliveryStatus>;
64
+ export declare const KNOWN_EMAIL_EVENT_TYPES: readonly ["email_sent", "delivered", "soft-bounce", "hard_bounce", "list_unsub", "complaint", "email_opened", "email_clicked", "email_inbound"];
65
+ export declare const KNOWN_SMS_EVENT_TYPES: readonly ["sms_sent", "sms_undelivered", "sms_stop", "sms_clicked"];
66
+ export declare const vSweegoEvent: import("convex/values").VObject<{
67
+ channel?: "email" | "sms" | undefined;
68
+ eventId?: string | undefined;
69
+ transactionId?: string | undefined;
70
+ timestamp?: string | undefined;
71
+ eventType: string;
72
+ swgUid: string;
73
+ raw: any;
74
+ }, {
75
+ eventType: import("convex/values").VString<string, "required">;
76
+ channel: import("convex/values").VUnion<"email" | "sms" | undefined, [import("convex/values").VLiteral<"email", "required">, import("convex/values").VLiteral<"sms", "required">], "optional", never>;
77
+ swgUid: import("convex/values").VString<string, "required">;
78
+ eventId: import("convex/values").VString<string | undefined, "optional">;
79
+ transactionId: import("convex/values").VString<string | undefined, "optional">;
80
+ timestamp: import("convex/values").VString<string | undefined, "optional">;
81
+ raw: import("convex/values").VAny<any, "required", string>;
82
+ }, "required", "eventType" | "channel" | "swgUid" | "eventId" | "transactionId" | "timestamp" | "raw" | `raw.${string}`>;
83
+ export type SweegoEvent = Infer<typeof vSweegoEvent>;
84
+ export type EventKind = "sent" | "delivered" | "soft_bounce" | "hard_bounce" | "complaint" | "unsub" | "open" | "click" | "sms_sent" | "sms_undelivered" | "sms_stop" | "sms_click" | "inbound" | "unknown";
85
+ export declare function normalizeEventType(raw: string): string;
86
+ export declare function classifyEvent(raw: string): EventKind;
87
+ export declare const onEvent: import("convex/values").VObject<{
88
+ fnHandle: string;
89
+ }, {
90
+ fnHandle: import("convex/values").VString<string, "required">;
91
+ }, "required", "fnHandle">;
92
+ export declare const vOptions: import("convex/values").VObject<{
93
+ onEvent?: {
94
+ fnHandle: string;
95
+ } | undefined;
96
+ apiKey: string;
97
+ provider: string;
98
+ initialBackoffMs: number;
99
+ retryAttempts: number;
100
+ testMode: boolean;
101
+ }, {
102
+ apiKey: import("convex/values").VString<string, "required">;
103
+ provider: import("convex/values").VString<string, "required">;
104
+ initialBackoffMs: import("convex/values").VFloat64<number, "required">;
105
+ retryAttempts: import("convex/values").VFloat64<number, "required">;
106
+ testMode: import("convex/values").VBoolean<boolean, "required">;
107
+ onEvent: import("convex/values").VObject<{
108
+ fnHandle: string;
109
+ } | undefined, {
110
+ fnHandle: import("convex/values").VString<string, "required">;
111
+ }, "optional", "fnHandle">;
112
+ }, "required", "apiKey" | "provider" | "initialBackoffMs" | "retryAttempts" | "testMode" | "onEvent" | "onEvent.fnHandle">;
113
+ export type RuntimeConfig = Infer<typeof vOptions>;
114
+ export declare const vMessageInput: import("convex/values").VObject<{
115
+ variables?: Record<string, string | number | boolean> | undefined;
116
+ emailRecipients?: {
117
+ name?: string | undefined;
118
+ variables?: Record<string, string | number | boolean> | undefined;
119
+ email: string;
120
+ }[] | undefined;
121
+ smsRecipients?: {
122
+ num: string;
123
+ region: string;
124
+ }[] | undefined;
125
+ from?: {
126
+ name?: string | undefined;
127
+ email: string;
128
+ } | undefined;
129
+ subject?: string | undefined;
130
+ cc?: {
131
+ name?: string | undefined;
132
+ email: string;
133
+ }[] | undefined;
134
+ bcc?: {
135
+ name?: string | undefined;
136
+ email: string;
137
+ }[] | undefined;
138
+ replyTo?: {
139
+ name?: string | undefined;
140
+ email: string;
141
+ } | undefined;
142
+ html?: string | undefined;
143
+ text?: string | undefined;
144
+ templateId?: string | undefined;
145
+ attachments?: {
146
+ contentId?: string | undefined;
147
+ disposition?: "attachment" | "inline" | undefined;
148
+ isRelated?: boolean | undefined;
149
+ content: string;
150
+ filename: string;
151
+ }[] | undefined;
152
+ headers?: Record<string, string> | undefined;
153
+ listUnsub?: {
154
+ method?: "mailto" | "one-click" | undefined;
155
+ value: string;
156
+ } | undefined;
157
+ expires?: string | undefined;
158
+ campaignId?: string | undefined;
159
+ campaignTags?: string[] | undefined;
160
+ campaignType?: string | undefined;
161
+ compressStyle?: boolean | undefined;
162
+ forceInlineStyle?: boolean | undefined;
163
+ dryRun?: boolean | undefined;
164
+ senderId?: string | undefined;
165
+ shortenUrls?: boolean | undefined;
166
+ shortenWithProtocol?: boolean | undefined;
167
+ bat?: boolean | undefined;
168
+ channel: "email" | "sms";
169
+ bulk: boolean;
170
+ }, {
171
+ channel: import("convex/values").VUnion<"email" | "sms", [import("convex/values").VLiteral<"email", "required">, import("convex/values").VLiteral<"sms", "required">], "required", never>;
172
+ bulk: import("convex/values").VBoolean<boolean, "required">;
173
+ emailRecipients: import("convex/values").VArray<{
174
+ name?: string | undefined;
175
+ variables?: Record<string, string | number | boolean> | undefined;
176
+ email: string;
177
+ }[] | undefined, import("convex/values").VObject<{
178
+ name?: string | undefined;
179
+ variables?: Record<string, string | number | boolean> | undefined;
180
+ email: string;
181
+ }, {
182
+ email: import("convex/values").VString<string, "required">;
183
+ name: import("convex/values").VString<string | undefined, "optional">;
184
+ variables: import("convex/values").VRecord<Record<string, string | number | boolean> | undefined, import("convex/values").VString<string, "required">, import("convex/values").VUnion<string | number | boolean, [import("convex/values").VString<string, "required">, import("convex/values").VFloat64<number, "required">, import("convex/values").VBoolean<boolean, "required">], "required", never>, "optional", string>;
185
+ }, "required", "email" | "name" | "variables" | `variables.${string}`>, "optional">;
186
+ smsRecipients: import("convex/values").VArray<{
187
+ num: string;
188
+ region: string;
189
+ }[] | undefined, import("convex/values").VObject<{
190
+ num: string;
191
+ region: string;
192
+ }, {
193
+ num: import("convex/values").VString<string, "required">;
194
+ region: import("convex/values").VString<string, "required">;
195
+ }, "required", "num" | "region">, "optional">;
196
+ from: import("convex/values").VObject<{
197
+ name?: string | undefined;
198
+ email: string;
199
+ } | undefined, {
200
+ email: import("convex/values").VString<string, "required">;
201
+ name: import("convex/values").VString<string | undefined, "optional">;
202
+ }, "optional", "email" | "name">;
203
+ subject: import("convex/values").VString<string | undefined, "optional">;
204
+ cc: import("convex/values").VArray<{
205
+ name?: string | undefined;
206
+ email: string;
207
+ }[] | undefined, import("convex/values").VObject<{
208
+ name?: string | undefined;
209
+ email: string;
210
+ }, {
211
+ email: import("convex/values").VString<string, "required">;
212
+ name: import("convex/values").VString<string | undefined, "optional">;
213
+ }, "required", "email" | "name">, "optional">;
214
+ bcc: import("convex/values").VArray<{
215
+ name?: string | undefined;
216
+ email: string;
217
+ }[] | undefined, import("convex/values").VObject<{
218
+ name?: string | undefined;
219
+ email: string;
220
+ }, {
221
+ email: import("convex/values").VString<string, "required">;
222
+ name: import("convex/values").VString<string | undefined, "optional">;
223
+ }, "required", "email" | "name">, "optional">;
224
+ replyTo: import("convex/values").VObject<{
225
+ name?: string | undefined;
226
+ email: string;
227
+ } | undefined, {
228
+ email: import("convex/values").VString<string, "required">;
229
+ name: import("convex/values").VString<string | undefined, "optional">;
230
+ }, "optional", "email" | "name">;
231
+ html: import("convex/values").VString<string | undefined, "optional">;
232
+ text: import("convex/values").VString<string | undefined, "optional">;
233
+ templateId: import("convex/values").VString<string | undefined, "optional">;
234
+ variables: import("convex/values").VRecord<Record<string, string | number | boolean> | undefined, import("convex/values").VString<string, "required">, import("convex/values").VUnion<string | number | boolean, [import("convex/values").VString<string, "required">, import("convex/values").VFloat64<number, "required">, import("convex/values").VBoolean<boolean, "required">], "required", never>, "optional", string>;
235
+ attachments: import("convex/values").VArray<{
236
+ contentId?: string | undefined;
237
+ disposition?: "attachment" | "inline" | undefined;
238
+ isRelated?: boolean | undefined;
239
+ content: string;
240
+ filename: string;
241
+ }[] | undefined, import("convex/values").VObject<{
242
+ contentId?: string | undefined;
243
+ disposition?: "attachment" | "inline" | undefined;
244
+ isRelated?: boolean | undefined;
245
+ content: string;
246
+ filename: string;
247
+ }, {
248
+ content: import("convex/values").VString<string, "required">;
249
+ filename: import("convex/values").VString<string, "required">;
250
+ contentId: import("convex/values").VString<string | undefined, "optional">;
251
+ disposition: import("convex/values").VUnion<"attachment" | "inline" | undefined, [import("convex/values").VLiteral<"attachment", "required">, import("convex/values").VLiteral<"inline", "required">], "optional", never>;
252
+ isRelated: import("convex/values").VBoolean<boolean | undefined, "optional">;
253
+ }, "required", "content" | "filename" | "contentId" | "disposition" | "isRelated">, "optional">;
254
+ headers: import("convex/values").VRecord<Record<string, string> | undefined, import("convex/values").VString<string, "required">, import("convex/values").VString<string, "required">, "optional", string>;
255
+ listUnsub: import("convex/values").VObject<{
256
+ method?: "mailto" | "one-click" | undefined;
257
+ value: string;
258
+ } | undefined, {
259
+ method: import("convex/values").VUnion<"mailto" | "one-click" | undefined, [import("convex/values").VLiteral<"mailto", "required">, import("convex/values").VLiteral<"one-click", "required">], "optional", never>;
260
+ value: import("convex/values").VString<string, "required">;
261
+ }, "optional", "method" | "value">;
262
+ expires: import("convex/values").VString<string | undefined, "optional">;
263
+ campaignId: import("convex/values").VString<string | undefined, "optional">;
264
+ campaignTags: import("convex/values").VArray<string[] | undefined, import("convex/values").VString<string, "required">, "optional">;
265
+ campaignType: import("convex/values").VString<string | undefined, "optional">;
266
+ compressStyle: import("convex/values").VBoolean<boolean | undefined, "optional">;
267
+ forceInlineStyle: import("convex/values").VBoolean<boolean | undefined, "optional">;
268
+ dryRun: import("convex/values").VBoolean<boolean | undefined, "optional">;
269
+ senderId: import("convex/values").VString<string | undefined, "optional">;
270
+ shortenUrls: import("convex/values").VBoolean<boolean | undefined, "optional">;
271
+ shortenWithProtocol: import("convex/values").VBoolean<boolean | undefined, "optional">;
272
+ bat: import("convex/values").VBoolean<boolean | undefined, "optional">;
273
+ }, "required", "variables" | `variables.${string}` | "channel" | "bulk" | "emailRecipients" | "smsRecipients" | "from" | "subject" | "cc" | "bcc" | "replyTo" | "html" | "text" | "templateId" | "attachments" | "headers" | "listUnsub" | "expires" | "campaignId" | "campaignTags" | "campaignType" | "compressStyle" | "forceInlineStyle" | "dryRun" | "senderId" | "shortenUrls" | "shortenWithProtocol" | "bat" | "from.email" | "from.name" | "replyTo.email" | "replyTo.name" | `headers.${string}` | "listUnsub.method" | "listUnsub.value">;
274
+ export type MessageInput = Infer<typeof vMessageInput>;
275
+ export declare function parseEmailAddress(input: string | EmailAddress): EmailAddress;
276
+ export declare function parseEmailAddresses(input: string | EmailAddress | Array<string | EmailAddress>): EmailAddress[];
277
+ export type QueryCtx = Pick<GenericQueryCtx<GenericDataModel>, "runQuery">;
278
+ export type MutationCtx = Pick<GenericMutationCtx<GenericDataModel>, "runQuery" | "runMutation">;
279
+ export type ActionCtx = Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation" | "runAction">;
280
+ //# sourceMappingURL=shared.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/component/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACrB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,KAAK,KAAK,EAAK,MAAM,eAAe,CAAC;AAG9C,eAAO,MAAM,mBAAmB,0BAA0B,CAAC;AAG3D,eAAO,MAAM,gBAAgB,WAAW,CAAC;AAMzC,eAAO,MAAM,QAAQ,kLAAgD,CAAC;AACtE,MAAM,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,QAAQ,CAAC,CAAC;AAO7C,eAAO,MAAM,aAAa;;;;;;gCAGxB,CAAC;AACH,MAAM,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AAIvD,eAAO,MAAM,UAAU,uYAGtB,CAAC;AACF,MAAM,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,UAAU,CAAC,CAAC;AAIjD,eAAO,MAAM,eAAe;;;;;;;;sEAI1B,CAAC;AACH,MAAM,MAAM,cAAc,GAAG,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAG3D,eAAO,MAAM,aAAa;;;;;;gCAGxB,CAAC;AACH,MAAM,M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;;;;;;;;;;;;;;;;;;;0HAQnB,CAAC;AACH,MAAM,MAAM,aAAa,GAAG,KAAK,CAAC,OAAO,QAAQ,CAAC,CAAC;AASnD,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ohBA4BxB,CAAC;AACH,MAAM,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AAQvD,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,MAAM,GAAG,YAAY,GAC3B,YAAY,CASd;AAED,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,MAAM,GAAG,YAAY,GAAG,KAAK,CAAC,MAAM,GAAG,YAAY,CAAC,GAC1D,YAAY,EAAE,CAGhB;AAMD,MAAM,MAAM,QAAQ,GAAG,IAAI,CAAC,eAAe,CAAC,gBAAgB,CAAC,EAAE,UAAU,CAAC,CAAC;AAC3E,MAAM,MAAM,WAAW,GAAG,IAAI,CAC5B,kBAAkB,CAAC,gBAAgB,CAAC,EACpC,UAAU,GAAG,aAAa,CAC3B,CAAC;AACF,MAAM,MAAM,SAAS,GAAG,IAAI,CAC1B,gBAAgB,CAAC,gBAAgB,CAAC,EAClC,UAAU,GAAG,aAAa,GAAG,WAAW,CACzC,CAAC"}
@@ -0,0 +1,213 @@
1
+ import { v } from "convex/values";
2
+ // The Sweego API base URL. All requests go here.
3
+ export const SWEEGO_API_BASE_URL = "https://api.sweego.io";
4
+ // The default provider Sweego expects on every send request.
5
+ export const DEFAULT_PROVIDER = "sweego";
6
+ /* -------------------------------------------------------------------------- */
7
+ /* Channels */
8
+ /* -------------------------------------------------------------------------- */
9
+ export const vChannel = v.union(v.literal("email"), v.literal("sms"));
10
+ /* -------------------------------------------------------------------------- */
11
+ /* Addresses / recipients */
12
+ /* -------------------------------------------------------------------------- */
13
+ // An email address with an optional display name, e.g. { email, name }.
14
+ export const vEmailAddress = v.object({
15
+ email: v.string(),
16
+ name: v.optional(v.string()),
17
+ });
18
+ // Variables passed to a Sweego template. Values are interpolated into
19
+ // `{{ placeholder }}` tokens; Sweego accepts string/number/boolean values.
20
+ export const vVariables = v.record(v.string(), v.union(v.string(), v.number(), v.boolean()));
21
+ // An email recipient. `variables` is only honored on the bulk endpoint
22
+ // (`/send/bulk/email`), where each recipient may be personalized.
23
+ export const vEmailRecipient = v.object({
24
+ email: v.string(),
25
+ name: v.optional(v.string()),
26
+ variables: v.optional(vVariables),
27
+ });
28
+ // An SMS recipient: a phone number plus its ISO-3166 alpha-2 region (e.g. "FR").
29
+ export const vSmsRecipient = v.object({
30
+ num: v.string(),
31
+ region: v.string(),
32
+ });
33
+ /* -------------------------------------------------------------------------- */
34
+ /* Email extras */
35
+ /* -------------------------------------------------------------------------- */
36
+ // A file attachment. `content` MUST be base64-encoded bytes. The total
37
+ // message (incl. attachments) must fit within a single Convex document
38
+ // (~1 MiB); use small attachments or host large files elsewhere.
39
+ export const vAttachment = v.object({
40
+ content: v.string(),
41
+ filename: v.string(),
42
+ contentId: v.optional(v.string()),
43
+ disposition: v.optional(v.union(v.literal("attachment"), v.literal("inline"))),
44
+ isRelated: v.optional(v.boolean()),
45
+ });
46
+ // The List-Unsubscribe header. For "mailto", `value` is an email; for
47
+ // "one-click", `value` is "<mailto:EMAIL>,<URL>".
48
+ export const vListUnsub = v.object({
49
+ method: v.optional(v.union(v.literal("mailto"), v.literal("one-click"))),
50
+ value: v.string(),
51
+ });
52
+ // Email campaign type. Optional for email.
53
+ export const vEmailCampaignType = v.union(v.literal("market"), v.literal("newsletter"), v.literal("transac"));
54
+ // SMS campaign type. REQUIRED by Sweego for every SMS send.
55
+ export const vSmsCampaignType = v.union(v.literal("market"), v.literal("transac"));
56
+ /* -------------------------------------------------------------------------- */
57
+ /* Statuses */
58
+ /* -------------------------------------------------------------------------- */
59
+ // Lifecycle of a logical send (one `messages` row).
60
+ export const vSendStatus = v.union(v.literal("queued"), // enqueued, not yet handed to Sweego
61
+ v.literal("sent"), // accepted by Sweego (swg_uids issued)
62
+ v.literal("failed"), // permanent failure / retries exhausted
63
+ v.literal("cancelled"));
64
+ // Per-recipient delivery outcome (one `deliveries` row per swg_uid).
65
+ export const vDeliveryStatus = v.union(v.literal("pending"), // accepted, awaiting delivery events
66
+ v.literal("sent"), v.literal("delivered"), v.literal("soft_bounced"), // transient bounce, may still deliver
67
+ v.literal("bounced"), // hard bounce (terminal)
68
+ v.literal("undelivered"), // SMS not delivered (terminal)
69
+ v.literal("stopped"));
70
+ /* -------------------------------------------------------------------------- */
71
+ /* Webhook events */
72
+ /* -------------------------------------------------------------------------- */
73
+ // Known Sweego email webhook event_type strings. Casing is inconsistent in
74
+ // Sweego's docs (e.g. "soft-bounce" vs "hard_bounce"), so we match defensively
75
+ // via `classifyEvent` rather than relying on these literally.
76
+ export const KNOWN_EMAIL_EVENT_TYPES = [
77
+ "email_sent",
78
+ "delivered",
79
+ "soft-bounce",
80
+ "hard_bounce",
81
+ "list_unsub",
82
+ "complaint",
83
+ "email_opened",
84
+ "email_clicked",
85
+ "email_inbound",
86
+ ];
87
+ export const KNOWN_SMS_EVENT_TYPES = [
88
+ "sms_sent",
89
+ "sms_undelivered",
90
+ "sms_stop",
91
+ "sms_clicked",
92
+ ];
93
+ // A normalized webhook event handed to your `onEvent` handler. The raw,
94
+ // unmodified payload is always available on `raw`.
95
+ export const vSweegoEvent = v.object({
96
+ eventType: v.string(),
97
+ channel: v.optional(vChannel),
98
+ swgUid: v.string(),
99
+ eventId: v.optional(v.string()),
100
+ transactionId: v.optional(v.string()),
101
+ timestamp: v.optional(v.string()),
102
+ raw: v.any(),
103
+ });
104
+ export function normalizeEventType(raw) {
105
+ return raw.trim().toLowerCase().replace(/-/g, "_");
106
+ }
107
+ export function classifyEvent(raw) {
108
+ switch (normalizeEventType(raw)) {
109
+ case "email_sent":
110
+ return "sent";
111
+ case "delivered":
112
+ return "delivered";
113
+ case "soft_bounce":
114
+ return "soft_bounce";
115
+ case "hard_bounce":
116
+ case "bounce":
117
+ return "hard_bounce";
118
+ case "complaint":
119
+ return "complaint";
120
+ case "list_unsub":
121
+ return "unsub";
122
+ case "email_opened":
123
+ return "open";
124
+ case "email_clicked":
125
+ return "click";
126
+ case "email_inbound":
127
+ return "inbound";
128
+ case "sms_sent":
129
+ return "sms_sent";
130
+ case "sms_undelivered":
131
+ return "sms_undelivered";
132
+ case "sms_stop":
133
+ case "stop":
134
+ return "sms_stop";
135
+ case "sms_clicked":
136
+ return "sms_click";
137
+ default:
138
+ return "unknown";
139
+ }
140
+ }
141
+ /* -------------------------------------------------------------------------- */
142
+ /* Runtime configuration */
143
+ /* -------------------------------------------------------------------------- */
144
+ // A reference to a mutation in the host app that runs after each event.
145
+ export const onEvent = v.object({ fnHandle: v.string() });
146
+ // Runtime configuration threaded from the client into the component on each
147
+ // send. Note: components cannot read the host app's environment variables, so
148
+ // the API key is passed in explicitly here.
149
+ export const vOptions = v.object({
150
+ apiKey: v.string(),
151
+ provider: v.string(),
152
+ initialBackoffMs: v.number(),
153
+ retryAttempts: v.number(),
154
+ // When true, email sends use Sweego's `dry-run` (validated, never sent).
155
+ testMode: v.boolean(),
156
+ onEvent: v.optional(onEvent),
157
+ });
158
+ /* -------------------------------------------------------------------------- */
159
+ /* Message input (client -> component) */
160
+ /* -------------------------------------------------------------------------- */
161
+ // The normalized message a client hands to the component's `enqueueMessage`
162
+ // mutation. Lifecycle fields (status, transactionId, finalizedAt, …) are added
163
+ // by the component, not provided here.
164
+ export const vMessageInput = v.object({
165
+ channel: vChannel,
166
+ bulk: v.boolean(),
167
+ emailRecipients: v.optional(v.array(vEmailRecipient)),
168
+ smsRecipients: v.optional(v.array(vSmsRecipient)),
169
+ from: v.optional(vEmailAddress),
170
+ subject: v.optional(v.string()),
171
+ cc: v.optional(v.array(vEmailAddress)),
172
+ bcc: v.optional(v.array(vEmailAddress)),
173
+ replyTo: v.optional(vEmailAddress),
174
+ html: v.optional(v.string()),
175
+ text: v.optional(v.string()),
176
+ templateId: v.optional(v.string()),
177
+ variables: v.optional(vVariables),
178
+ attachments: v.optional(v.array(vAttachment)),
179
+ headers: v.optional(v.record(v.string(), v.string())),
180
+ listUnsub: v.optional(vListUnsub),
181
+ expires: v.optional(v.string()),
182
+ campaignId: v.optional(v.string()),
183
+ campaignTags: v.optional(v.array(v.string())),
184
+ campaignType: v.optional(v.string()),
185
+ compressStyle: v.optional(v.boolean()),
186
+ forceInlineStyle: v.optional(v.boolean()),
187
+ dryRun: v.optional(v.boolean()),
188
+ senderId: v.optional(v.string()),
189
+ shortenUrls: v.optional(v.boolean()),
190
+ shortenWithProtocol: v.optional(v.boolean()),
191
+ bat: v.optional(v.boolean()),
192
+ });
193
+ /* -------------------------------------------------------------------------- */
194
+ /* Helpers */
195
+ /* -------------------------------------------------------------------------- */
196
+ // Accepts either a structured address or an RFC-5322-ish "Name <email>" /
197
+ // "email" string and returns { email, name? }.
198
+ export function parseEmailAddress(input) {
199
+ if (typeof input !== "string")
200
+ return input;
201
+ const match = input.match(/^\s*(.*?)\s*<\s*([^>]+)\s*>\s*$/);
202
+ if (match) {
203
+ const name = match[1].replace(/^["']|["']$/g, "").trim();
204
+ const email = match[2].trim();
205
+ return name ? { email, name } : { email };
206
+ }
207
+ return { email: input.trim() };
208
+ }
209
+ export function parseEmailAddresses(input) {
210
+ const list = Array.isArray(input) ? input : [input];
211
+ return list.map(parseEmailAddress);
212
+ }
213
+ //# sourceMappingURL=shared.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared.js","sourceRoot":"","sources":["../../src/component/shared.ts"],"names":[],"mappings":"AAMA,OAAO,EAAc,CAAC,EAAE,MAAM,eAAe,CAAC;AAE9C,iDAAiD;AACjD,MAAM,CAAC,MAAM,mBAAmB,GAAG,uBAAuB,CAAC;AAE3D,6DAA6D;A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CAAC"}
@@ -0,0 +1,95 @@
1
+ /**
2
+ * HTTP status codes from which retrying will never help. Everything else
3
+ * (429 rate limits, 409 conflicts, 5xx) is treated as transient and retried
4
+ * by the workpool. Derived from Sweego's documented status codes.
5
+ */
6
+ export declare const PERMANENT_ERROR_CODES: Set<number>;
7
+ export type SweegoRequestInit = Omit<RequestInit, "body"> & {
8
+ json?: unknown;
9
+ };
10
+ /** Low-level fetch against the Sweego API with the `Api-Key` auth header. */
11
+ export declare function sweegoFetch(apiKey: string, path: string, init?: SweegoRequestInit): Promise<Response>;
12
+ /** Turn a non-OK Sweego response into a concise, non-leaky Error message. */
13
+ export declare function sanitizeSweegoError(status: number, errorText: string): string;
14
+ export interface BuildableMessage {
15
+ channel: "email" | "sms";
16
+ provider: string;
17
+ bulk: boolean;
18
+ emailRecipients?: Array<{
19
+ email: string;
20
+ name?: string;
21
+ variables?: Record<string, string | number | boolean>;
22
+ }>;
23
+ smsRecipients?: Array<{
24
+ num: string;
25
+ region: string;
26
+ }>;
27
+ from?: {
28
+ email: string;
29
+ name?: string;
30
+ };
31
+ subject?: string;
32
+ cc?: Array<{
33
+ email: string;
34
+ name?: string;
35
+ }>;
36
+ bcc?: Array<{
37
+ email: string;
38
+ name?: string;
39
+ }>;
40
+ replyTo?: {
41
+ email: string;
42
+ name?: string;
43
+ };
44
+ html?: string;
45
+ text?: string;
46
+ templateId?: string;
47
+ variables?: Record<string, string | number | boolean>;
48
+ attachments?: Array<{
49
+ content: string;
50
+ filename: string;
51
+ contentId?: string;
52
+ disposition?: "attachment" | "inline";
53
+ isRelated?: boolean;
54
+ }>;
55
+ headers?: Record<string, string>;
56
+ listUnsub?: {
57
+ method?: "mailto" | "one-click";
58
+ value: string;
59
+ };
60
+ expires?: string;
61
+ campaignId?: string;
62
+ campaignTags?: string[];
63
+ campaignType?: string;
64
+ compressStyle?: boolean;
65
+ forceInlineStyle?: boolean;
66
+ dryRun?: boolean;
67
+ senderId?: string;
68
+ shortenUrls?: boolean;
69
+ shortenWithProtocol?: boolean;
70
+ bat?: boolean;
71
+ }
72
+ type Json = Record<string, unknown>;
73
+ /** Build the `{ path, body }` for a stored message. */
74
+ export declare function buildSendRequest(message: BuildableMessage): {
75
+ path: string;
76
+ body: Json;
77
+ };
78
+ export interface SendResult {
79
+ channel?: string;
80
+ provider?: string;
81
+ swgUids: Record<string, string>;
82
+ transactionId?: string;
83
+ creditLeft?: string;
84
+ }
85
+ /** Parse a Sweego `ModelOutSend` body into a normalized result. */
86
+ export declare function parseSendResponse(data: unknown): SendResult;
87
+ /** GET /logs/{swg_uid}/status — current remote status for one message. */
88
+ export declare function fetchLogStatus(apiKey: string, swgUid: string): Promise<{
89
+ status: string;
90
+ channel?: string;
91
+ } | null>;
92
+ /** POST /sms/estimate — estimate the cost/segments of an SMS send. */
93
+ export declare function fetchSmsEstimate(apiKey: string, body: Record<string, unknown>): Promise<unknown>;
94
+ export {};
95
+ //# sourceMappingURL=sweego.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sweego.d.ts","sourceRoot":"","sources":["../../src/component/sweego.ts"],"names":[],"mappings":"AAMA;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,aAYhC,CAAC;AAEH,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC,GAAG;IAAE,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAE/E,6EAA6E;AAC7E,wBAAsB,WAAW,CAC/B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,IAAI,GAAE,iBAAsB,GAC3B,OAAO,CAAC,QAAQ,CAAC,CAYnB;AAED,6EAA6E;AAC7E,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAY7E;AAYD,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,OAAO,GAAG,KAAK,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,IA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