@superdurable/connector-campaignmonitor 0.1.0 → 0.2.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.
package/dist/index.js CHANGED
@@ -1,9 +1,114 @@
1
1
  import {
2
+ CampaignIdentitySchema,
3
+ CampaignProfileSchema,
4
+ CampaignSummarySchema,
5
+ CampaignsPageSchema,
2
6
  ClientMetadataSchema,
3
7
  ClientsListSchema,
4
8
  ConfigSchema,
5
9
  Connection,
6
10
  ConnectorID,
11
+ CreateDraftCampaignBranch,
12
+ CreateDraftCampaignBranchCreated,
13
+ CreateDraftCampaignBranchDefect,
14
+ CreateDraftCampaignBranchProviderRejected,
15
+ CreateDraftCampaignBranchUncertain,
16
+ CreateDraftCampaignDefinition,
17
+ CreateDraftCampaignInputSchema,
18
+ CreateDraftCampaignMetadata,
19
+ CreateListBranch,
20
+ CreateListBranchCreated,
21
+ CreateListBranchDefect,
22
+ CreateListBranchProviderRejected,
23
+ CreateListBranchUncertain,
24
+ CreateListDefinition,
25
+ CreateListInputSchema,
26
+ CreateListMetadata,
27
+ CreateSegmentBranch,
28
+ CreateSegmentBranchCreated,
29
+ CreateSegmentBranchDefect,
30
+ CreateSegmentBranchProviderRejected,
31
+ CreateSegmentBranchUncertain,
32
+ CreateSegmentDefinition,
33
+ CreateSegmentInputSchema,
34
+ CreateSegmentMetadata,
35
+ CredentialMaterialError,
36
+ DeleteCampaignBranch,
37
+ DeleteCampaignBranchDefect,
38
+ DeleteCampaignBranchDeleted,
39
+ DeleteCampaignBranchInvalidResponse,
40
+ DeleteCampaignBranchProviderRejected,
41
+ DeleteCampaignDefinition,
42
+ DeleteCampaignInputSchema,
43
+ DeleteCampaignMetadata,
44
+ DeleteListBranch,
45
+ DeleteListBranchDefect,
46
+ DeleteListBranchDeleted,
47
+ DeleteListBranchInvalidResponse,
48
+ DeleteListBranchProviderRejected,
49
+ DeleteListDefinition,
50
+ DeleteListInputSchema,
51
+ DeleteListMetadata,
52
+ DeleteSegmentBranch,
53
+ DeleteSegmentBranchDefect,
54
+ DeleteSegmentBranchDeleted,
55
+ DeleteSegmentBranchInvalidResponse,
56
+ DeleteSegmentBranchProviderRejected,
57
+ DeleteSegmentDefinition,
58
+ DeleteSegmentInputSchema,
59
+ DeleteSegmentMetadata,
60
+ DeleteSubscriberBranch,
61
+ DeleteSubscriberBranchDefect,
62
+ DeleteSubscriberBranchDeleted,
63
+ DeleteSubscriberBranchInvalidResponse,
64
+ DeleteSubscriberBranchProviderRejected,
65
+ DeleteSubscriberDefinition,
66
+ DeleteSubscriberInputSchema,
67
+ DeleteSubscriberMetadata,
68
+ GetCampaignSummaryBranch,
69
+ GetCampaignSummaryBranchDefect,
70
+ GetCampaignSummaryBranchFound,
71
+ GetCampaignSummaryBranchInvalidResponse,
72
+ GetCampaignSummaryBranchNotFound,
73
+ GetCampaignSummaryBranchProviderRejected,
74
+ GetCampaignSummaryDefinition,
75
+ GetCampaignSummaryInputSchema,
76
+ GetCampaignSummaryMetadata,
77
+ GetListBranch,
78
+ GetListBranchDefect,
79
+ GetListBranchFound,
80
+ GetListBranchInvalidResponse,
81
+ GetListBranchNotFound,
82
+ GetListBranchProviderRejected,
83
+ GetListDefinition,
84
+ GetListInputSchema,
85
+ GetListMetadata,
86
+ GetSegmentBranch,
87
+ GetSegmentBranchDefect,
88
+ GetSegmentBranchFound,
89
+ GetSegmentBranchInvalidResponse,
90
+ GetSegmentBranchNotFound,
91
+ GetSegmentBranchProviderRejected,
92
+ GetSegmentDefinition,
93
+ GetSegmentInputSchema,
94
+ GetSegmentMetadata,
95
+ GetSubscriberBranch,
96
+ GetSubscriberBranchDefect,
97
+ GetSubscriberBranchFound,
98
+ GetSubscriberBranchInvalidResponse,
99
+ GetSubscriberBranchNotFound,
100
+ GetSubscriberBranchProviderRejected,
101
+ GetSubscriberDefinition,
102
+ GetSubscriberInputSchema,
103
+ GetSubscriberMetadata,
104
+ ListCampaignsBranch,
105
+ ListCampaignsBranchDefect,
106
+ ListCampaignsBranchInvalidResponse,
107
+ ListCampaignsBranchListed,
108
+ ListCampaignsBranchProviderRejected,
109
+ ListCampaignsDefinition,
110
+ ListCampaignsInputSchema,
111
+ ListCampaignsMetadata,
7
112
  ListClientsBranch,
8
113
  ListClientsBranchDefect,
9
114
  ListClientsBranchInvalidResponse,
@@ -12,23 +117,368 @@ import {
12
117
  ListClientsDefinition,
13
118
  ListClientsInputSchema,
14
119
  ListClientsMetadata,
120
+ ListIdentitySchema,
121
+ ListProfileSchema,
122
+ ListSegmentsBranch,
123
+ ListSegmentsBranchDefect,
124
+ ListSegmentsBranchInvalidResponse,
125
+ ListSegmentsBranchListed,
126
+ ListSegmentsBranchProviderRejected,
127
+ ListSegmentsDefinition,
128
+ ListSegmentsInputSchema,
129
+ ListSegmentsMetadata,
130
+ ListSubscriberListsBranch,
131
+ ListSubscriberListsBranchDefect,
132
+ ListSubscriberListsBranchInvalidResponse,
133
+ ListSubscriberListsBranchListed,
134
+ ListSubscriberListsBranchProviderRejected,
135
+ ListSubscriberListsDefinition,
136
+ ListSubscriberListsInputSchema,
137
+ ListSubscriberListsMetadata,
138
+ ListSubscribersBranch,
139
+ ListSubscribersBranchDefect,
140
+ ListSubscribersBranchInvalidResponse,
141
+ ListSubscribersBranchListed,
142
+ ListSubscribersBranchProviderRejected,
143
+ ListSubscribersDefinition,
144
+ ListSubscribersInputSchema,
145
+ ListSubscribersMetadata,
15
146
  ProviderID,
147
+ SegmentIdentitySchema,
148
+ SegmentProfileSchema,
149
+ SegmentRuleGroupSchema,
150
+ SegmentRuleSchema,
151
+ SegmentsListSchema,
152
+ SendCampaignBranch,
153
+ SendCampaignBranchDefect,
154
+ SendCampaignBranchProviderRejected,
155
+ SendCampaignBranchSent,
156
+ SendCampaignBranchUncertain,
157
+ SendCampaignDefinition,
158
+ SendCampaignInputSchema,
159
+ SendCampaignMetadata,
160
+ SendCampaignPreviewBranch,
161
+ SendCampaignPreviewBranchDefect,
162
+ SendCampaignPreviewBranchProviderRejected,
163
+ SendCampaignPreviewBranchSent,
164
+ SendCampaignPreviewBranchUncertain,
165
+ SendCampaignPreviewDefinition,
166
+ SendCampaignPreviewInputSchema,
167
+ SendCampaignPreviewMetadata,
168
+ SubscriberIdentitySchema,
169
+ SubscriberListIdentitySchema,
170
+ SubscriberListsSchema,
171
+ SubscriberProfileSchema,
172
+ SubscribersPageSchema,
173
+ UnscheduleCampaignBranch,
174
+ UnscheduleCampaignBranchDefect,
175
+ UnscheduleCampaignBranchInvalidResponse,
176
+ UnscheduleCampaignBranchProviderRejected,
177
+ UnscheduleCampaignBranchUnscheduled,
178
+ UnscheduleCampaignDefinition,
179
+ UnscheduleCampaignInputSchema,
180
+ UnscheduleCampaignMetadata,
181
+ UnsubscribeSubscriberBranch,
182
+ UnsubscribeSubscriberBranchDefect,
183
+ UnsubscribeSubscriberBranchInvalidResponse,
184
+ UnsubscribeSubscriberBranchProviderRejected,
185
+ UnsubscribeSubscriberBranchUnsubscribed,
186
+ UnsubscribeSubscriberDefinition,
187
+ UnsubscribeSubscriberInputSchema,
188
+ UnsubscribeSubscriberMetadata,
189
+ UpdateListBranch,
190
+ UpdateListBranchDefect,
191
+ UpdateListBranchInvalidResponse,
192
+ UpdateListBranchNotFound,
193
+ UpdateListBranchProviderRejected,
194
+ UpdateListBranchUpdated,
195
+ UpdateListDefinition,
196
+ UpdateListInputSchema,
197
+ UpdateListMetadata,
198
+ UpdateSegmentBranch,
199
+ UpdateSegmentBranchDefect,
200
+ UpdateSegmentBranchInvalidResponse,
201
+ UpdateSegmentBranchNotFound,
202
+ UpdateSegmentBranchProviderRejected,
203
+ UpdateSegmentBranchUpdated,
204
+ UpdateSegmentDefinition,
205
+ UpdateSegmentInputSchema,
206
+ UpdateSegmentMetadata,
207
+ UpdateSubscriberBranch,
208
+ UpdateSubscriberBranchDefect,
209
+ UpdateSubscriberBranchInvalidResponse,
210
+ UpdateSubscriberBranchNotFound,
211
+ UpdateSubscriberBranchProviderRejected,
212
+ UpdateSubscriberBranchUpdated,
213
+ UpdateSubscriberDefinition,
214
+ UpdateSubscriberInputSchema,
215
+ UpdateSubscriberMetadata,
216
+ UpsertSubscriberBranch,
217
+ UpsertSubscriberBranchDefect,
218
+ UpsertSubscriberBranchInvalidResponse,
219
+ UpsertSubscriberBranchProviderRejected,
220
+ UpsertSubscriberBranchSaved,
221
+ UpsertSubscriberDefinition,
222
+ UpsertSubscriberInputSchema,
223
+ UpsertSubscriberMetadata,
16
224
  decodeCredentials,
225
+ decodeSignedInteger,
226
+ exactIntegerJSONCodec,
227
+ isCredentialMaterialError,
17
228
  newConnection,
18
229
  newConnectionWithOperations,
19
- newProjectConnection
20
- } from "./chunk-VKND2LIG.js";
230
+ newProjectConnection,
231
+ parseExactIntegerJSON,
232
+ parseJSONNumberTokens
233
+ } from "./chunk-XSS3TJM2.js";
21
234
 
22
235
  // src/generated/steps.ts
23
- import { goToBranch, newQueryStep } from "@superdurable/connectors-sdk";
236
+ import { goToBranch, newMutationStep, newQueryStep } from "@superdurable/connectors-sdk";
237
+ function newListCampaignsStep(configuration) {
238
+ const { connection, connectionName, listed, providerRejected, invalidResponse, defect: defect2, ...stepConfiguration } = configuration;
239
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
240
+ return newQueryStep({ ...stepConfiguration, operation: connection.operations.listCampaigns(), connection: connection.reference, branches: [
241
+ goToBranch("listed", listed),
242
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
243
+ ...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
244
+ ...defect2 ? [goToBranch("defect", defect2)] : []
245
+ ] });
246
+ }
247
+ function newGetCampaignSummaryStep(configuration) {
248
+ const { connection, connectionName, found, notFound, providerRejected, invalidResponse, defect: defect2, ...stepConfiguration } = configuration;
249
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
250
+ return newQueryStep({ ...stepConfiguration, operation: connection.operations.getCampaignSummary(), connection: connection.reference, branches: [
251
+ goToBranch("found", found),
252
+ ...notFound ? [goToBranch("notFound", notFound)] : [],
253
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
254
+ ...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
255
+ ...defect2 ? [goToBranch("defect", defect2)] : []
256
+ ] });
257
+ }
258
+ function newCreateDraftCampaignStep(configuration) {
259
+ const { connection, connectionName, created, providerRejected, uncertain, defect: defect2, ...stepConfiguration } = configuration;
260
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
261
+ return newMutationStep({ ...stepConfiguration, operation: connection.operations.createDraftCampaign(), connection: connection.reference, branches: [
262
+ goToBranch("created", created),
263
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
264
+ ...uncertain ? [goToBranch("uncertain", uncertain)] : [],
265
+ ...defect2 ? [goToBranch("defect", defect2)] : []
266
+ ] });
267
+ }
268
+ function newSendCampaignStep(configuration) {
269
+ const { connection, connectionName, sent, providerRejected, uncertain, defect: defect2, ...stepConfiguration } = configuration;
270
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
271
+ return newMutationStep({ ...stepConfiguration, operation: connection.operations.sendCampaign(), connection: connection.reference, branches: [
272
+ goToBranch("sent", sent),
273
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
274
+ ...uncertain ? [goToBranch("uncertain", uncertain)] : [],
275
+ ...defect2 ? [goToBranch("defect", defect2)] : []
276
+ ] });
277
+ }
278
+ function newSendCampaignPreviewStep(configuration) {
279
+ const { connection, connectionName, sent, providerRejected, uncertain, defect: defect2, ...stepConfiguration } = configuration;
280
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
281
+ return newMutationStep({ ...stepConfiguration, operation: connection.operations.sendCampaignPreview(), connection: connection.reference, branches: [
282
+ goToBranch("sent", sent),
283
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
284
+ ...uncertain ? [goToBranch("uncertain", uncertain)] : [],
285
+ ...defect2 ? [goToBranch("defect", defect2)] : []
286
+ ] });
287
+ }
288
+ function newUnscheduleCampaignStep(configuration) {
289
+ const { connection, connectionName, unscheduled, providerRejected, invalidResponse, defect: defect2, maxSends, ...stepConfiguration } = configuration;
290
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
291
+ return newMutationStep({ ...stepConfiguration, operation: connection.operations.unscheduleCampaign(), connection: connection.reference, branches: [
292
+ goToBranch("unscheduled", unscheduled),
293
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
294
+ ...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
295
+ ...defect2 ? [goToBranch("defect", defect2)] : []
296
+ ] });
297
+ }
298
+ function newDeleteCampaignStep(configuration) {
299
+ const { connection, connectionName, deleted, providerRejected, invalidResponse, defect: defect2, maxSends, ...stepConfiguration } = configuration;
300
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
301
+ return newMutationStep({ ...stepConfiguration, operation: connection.operations.deleteCampaign(), connection: connection.reference, branches: [
302
+ goToBranch("deleted", deleted),
303
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
304
+ ...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
305
+ ...defect2 ? [goToBranch("defect", defect2)] : []
306
+ ] });
307
+ }
308
+ function newListSegmentsStep(configuration) {
309
+ const { connection, connectionName, listed, providerRejected, invalidResponse, defect: defect2, ...stepConfiguration } = configuration;
310
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
311
+ return newQueryStep({ ...stepConfiguration, operation: connection.operations.listSegments(), connection: connection.reference, branches: [
312
+ goToBranch("listed", listed),
313
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
314
+ ...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
315
+ ...defect2 ? [goToBranch("defect", defect2)] : []
316
+ ] });
317
+ }
318
+ function newGetSegmentStep(configuration) {
319
+ const { connection, connectionName, found, notFound, providerRejected, invalidResponse, defect: defect2, ...stepConfiguration } = configuration;
320
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
321
+ return newQueryStep({ ...stepConfiguration, operation: connection.operations.getSegment(), connection: connection.reference, branches: [
322
+ goToBranch("found", found),
323
+ ...notFound ? [goToBranch("notFound", notFound)] : [],
324
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
325
+ ...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
326
+ ...defect2 ? [goToBranch("defect", defect2)] : []
327
+ ] });
328
+ }
329
+ function newCreateSegmentStep(configuration) {
330
+ const { connection, connectionName, created, providerRejected, uncertain, defect: defect2, ...stepConfiguration } = configuration;
331
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
332
+ return newMutationStep({ ...stepConfiguration, operation: connection.operations.createSegment(), connection: connection.reference, branches: [
333
+ goToBranch("created", created),
334
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
335
+ ...uncertain ? [goToBranch("uncertain", uncertain)] : [],
336
+ ...defect2 ? [goToBranch("defect", defect2)] : []
337
+ ] });
338
+ }
339
+ function newUpdateSegmentStep(configuration) {
340
+ const { connection, connectionName, updated, notFound, providerRejected, invalidResponse, defect: defect2, maxSends, ...stepConfiguration } = configuration;
341
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
342
+ return newMutationStep({ ...stepConfiguration, operation: connection.operations.updateSegment(), connection: connection.reference, branches: [
343
+ goToBranch("updated", updated),
344
+ ...notFound ? [goToBranch("notFound", notFound)] : [],
345
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
346
+ ...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
347
+ ...defect2 ? [goToBranch("defect", defect2)] : []
348
+ ] });
349
+ }
350
+ function newDeleteSegmentStep(configuration) {
351
+ const { connection, connectionName, deleted, providerRejected, invalidResponse, defect: defect2, maxSends, ...stepConfiguration } = configuration;
352
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
353
+ return newMutationStep({ ...stepConfiguration, operation: connection.operations.deleteSegment(), connection: connection.reference, branches: [
354
+ goToBranch("deleted", deleted),
355
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
356
+ ...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
357
+ ...defect2 ? [goToBranch("defect", defect2)] : []
358
+ ] });
359
+ }
360
+ function newGetListStep(configuration) {
361
+ const { connection, connectionName, found, notFound, providerRejected, invalidResponse, defect: defect2, ...stepConfiguration } = configuration;
362
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
363
+ return newQueryStep({ ...stepConfiguration, operation: connection.operations.getList(), connection: connection.reference, branches: [
364
+ goToBranch("found", found),
365
+ ...notFound ? [goToBranch("notFound", notFound)] : [],
366
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
367
+ ...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
368
+ ...defect2 ? [goToBranch("defect", defect2)] : []
369
+ ] });
370
+ }
371
+ function newCreateListStep(configuration) {
372
+ const { connection, connectionName, created, providerRejected, uncertain, defect: defect2, ...stepConfiguration } = configuration;
373
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
374
+ return newMutationStep({ ...stepConfiguration, operation: connection.operations.createList(), connection: connection.reference, branches: [
375
+ goToBranch("created", created),
376
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
377
+ ...uncertain ? [goToBranch("uncertain", uncertain)] : [],
378
+ ...defect2 ? [goToBranch("defect", defect2)] : []
379
+ ] });
380
+ }
381
+ function newUpdateListStep(configuration) {
382
+ const { connection, connectionName, updated, notFound, providerRejected, invalidResponse, defect: defect2, maxSends, ...stepConfiguration } = configuration;
383
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
384
+ return newMutationStep({ ...stepConfiguration, operation: connection.operations.updateList(), connection: connection.reference, branches: [
385
+ goToBranch("updated", updated),
386
+ ...notFound ? [goToBranch("notFound", notFound)] : [],
387
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
388
+ ...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
389
+ ...defect2 ? [goToBranch("defect", defect2)] : []
390
+ ] });
391
+ }
392
+ function newDeleteListStep(configuration) {
393
+ const { connection, connectionName, deleted, providerRejected, invalidResponse, defect: defect2, maxSends, ...stepConfiguration } = configuration;
394
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
395
+ return newMutationStep({ ...stepConfiguration, operation: connection.operations.deleteList(), connection: connection.reference, branches: [
396
+ goToBranch("deleted", deleted),
397
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
398
+ ...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
399
+ ...defect2 ? [goToBranch("defect", defect2)] : []
400
+ ] });
401
+ }
402
+ function newListSubscribersStep(configuration) {
403
+ const { connection, connectionName, listed, providerRejected, invalidResponse, defect: defect2, ...stepConfiguration } = configuration;
404
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
405
+ return newQueryStep({ ...stepConfiguration, operation: connection.operations.listSubscribers(), connection: connection.reference, branches: [
406
+ goToBranch("listed", listed),
407
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
408
+ ...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
409
+ ...defect2 ? [goToBranch("defect", defect2)] : []
410
+ ] });
411
+ }
412
+ function newListSubscriberListsStep(configuration) {
413
+ const { connection, connectionName, listed, providerRejected, invalidResponse, defect: defect2, ...stepConfiguration } = configuration;
414
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
415
+ return newQueryStep({ ...stepConfiguration, operation: connection.operations.listSubscriberLists(), connection: connection.reference, branches: [
416
+ goToBranch("listed", listed),
417
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
418
+ ...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
419
+ ...defect2 ? [goToBranch("defect", defect2)] : []
420
+ ] });
421
+ }
422
+ function newGetSubscriberStep(configuration) {
423
+ const { connection, connectionName, found, notFound, providerRejected, invalidResponse, defect: defect2, ...stepConfiguration } = configuration;
424
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
425
+ return newQueryStep({ ...stepConfiguration, operation: connection.operations.getSubscriber(), connection: connection.reference, branches: [
426
+ goToBranch("found", found),
427
+ ...notFound ? [goToBranch("notFound", notFound)] : [],
428
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
429
+ ...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
430
+ ...defect2 ? [goToBranch("defect", defect2)] : []
431
+ ] });
432
+ }
433
+ function newUpsertSubscriberStep(configuration) {
434
+ const { connection, connectionName, saved, providerRejected, invalidResponse, defect: defect2, maxSends, ...stepConfiguration } = configuration;
435
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
436
+ return newMutationStep({ ...stepConfiguration, operation: connection.operations.upsertSubscriber(), connection: connection.reference, branches: [
437
+ goToBranch("saved", saved),
438
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
439
+ ...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
440
+ ...defect2 ? [goToBranch("defect", defect2)] : []
441
+ ] });
442
+ }
443
+ function newUpdateSubscriberStep(configuration) {
444
+ const { connection, connectionName, updated, notFound, providerRejected, invalidResponse, defect: defect2, maxSends, ...stepConfiguration } = configuration;
445
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
446
+ return newMutationStep({ ...stepConfiguration, operation: connection.operations.updateSubscriber(), connection: connection.reference, branches: [
447
+ goToBranch("updated", updated),
448
+ ...notFound ? [goToBranch("notFound", notFound)] : [],
449
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
450
+ ...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
451
+ ...defect2 ? [goToBranch("defect", defect2)] : []
452
+ ] });
453
+ }
454
+ function newDeleteSubscriberStep(configuration) {
455
+ const { connection, connectionName, deleted, providerRejected, invalidResponse, defect: defect2, maxSends, ...stepConfiguration } = configuration;
456
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
457
+ return newMutationStep({ ...stepConfiguration, operation: connection.operations.deleteSubscriber(), connection: connection.reference, branches: [
458
+ goToBranch("deleted", deleted),
459
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
460
+ ...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
461
+ ...defect2 ? [goToBranch("defect", defect2)] : []
462
+ ] });
463
+ }
464
+ function newUnsubscribeSubscriberStep(configuration) {
465
+ const { connection, connectionName, unsubscribed, providerRejected, invalidResponse, defect: defect2, maxSends, ...stepConfiguration } = configuration;
466
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
467
+ return newMutationStep({ ...stepConfiguration, operation: connection.operations.unsubscribeSubscriber(), connection: connection.reference, branches: [
468
+ goToBranch("unsubscribed", unsubscribed),
469
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
470
+ ...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
471
+ ...defect2 ? [goToBranch("defect", defect2)] : []
472
+ ] });
473
+ }
24
474
  function newListClientsStep(configuration) {
25
- const { connection, connectionName, listed, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
475
+ const { connection, connectionName, listed, providerRejected, invalidResponse, defect: defect2, ...stepConfiguration } = configuration;
26
476
  if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
27
477
  return newQueryStep({ ...stepConfiguration, operation: connection.operations.listClients(), connection: connection.reference, branches: [
28
478
  goToBranch("listed", listed),
29
479
  ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
30
480
  ...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
31
- ...defect ? [goToBranch("defect", defect)] : []
481
+ ...defect2 ? [goToBranch("defect", defect2)] : []
32
482
  ] });
33
483
  }
34
484
 
@@ -37,8 +487,755 @@ import { SecretString as SecretString2 } from "@superdurable/connectors-sdk";
37
487
  import { z } from "zod";
38
488
 
39
489
  // src/client.ts
40
- import { SecretString, newQueryBranch, newQueryRetry } from "@superdurable/connectors-sdk";
41
- import { BodyTooLargeError, isHeaderSafeCredential, parseRetryAfter, sendProviderRequest, validateBaseURL } from "@superdurable/connectors-sdk/providerhttp";
490
+ import { SecretString, newQueryBranch as newQueryBranch2, newQueryRetry as newQueryRetry2 } from "@superdurable/connectors-sdk";
491
+ import { BodyTooLargeError, ProviderTransportError, ProviderStalledError, isHeaderSafeCredential, parseRetryAfter, sendProviderRequest, validateBaseURL } from "@superdurable/connectors-sdk/providerhttp";
492
+
493
+ // src/management.ts
494
+ import {
495
+ definitionMaxSends,
496
+ newMutationBranch,
497
+ newMutationRetry,
498
+ newMutationUncertain,
499
+ newQueryBranch,
500
+ newQueryRetry
501
+ } from "@superdurable/connectors-sdk";
502
+ import { CheckpointError, DispatchNotAllowedError, InsufficientTimeError, newFence } from "@superdurable/connectors-sdk/singledispatch";
503
+ import emailAddresses from "email-addresses";
504
+ var failures = /* @__PURE__ */ new Set([400, 401, 403, 404, 411, 413, 414, 415, 422]);
505
+ var unsubscribeSettings = ["AllClientLists", "OnlyThisList"];
506
+ var subscriberStates = ["active", "unconfirmed", "unsubscribed", "bounced", "deleted"];
507
+ var campaignPaths = /* @__PURE__ */ new Map([["draft", "drafts.json"], ["scheduled", "scheduled.json"], ["sent", "campaigns.json"]]);
508
+ var emptyCampaign = { id: "", name: "" };
509
+ var emptyCampaigns = { campaigns: [], pageNumber: 0, pageSize: 0, totalRecords: 0, numberOfPages: 0 };
510
+ var emptySummary = { name: "", recipients: 0, totalOpened: 0, clicks: 0, unsubscribed: 0 };
511
+ var emptySegment = { id: "", listId: "", title: "" };
512
+ var emptySegmentProfile = { ...emptySegment, activeSubscribers: 0, ruleGroups: [] };
513
+ var emptyList = { id: "", title: "" };
514
+ var emptyListProfile = { ...emptyList, unsubscribeSetting: "", confirmedOptIn: false };
515
+ var emptySubscriber = { email: "" };
516
+ var emptySubscriberProfile = { email: "", name: "", state: "" };
517
+ var emptySubscribers = { subscribers: [], pageNumber: 0, pageSize: 0, totalRecords: 0, numberOfPages: 0 };
518
+ var CampaignMonitorQuery = class {
519
+ /** Bind an authenticated Campaign Monitor client. */
520
+ constructor(client) {
521
+ this.client = client;
522
+ }
523
+ client;
524
+ /** Return the generated operation contract. */
525
+ definition() {
526
+ return this.contract;
527
+ }
528
+ };
529
+ var CampaignMonitorMutation = class {
530
+ /** Bind an authenticated Campaign Monitor client. */
531
+ constructor(client) {
532
+ this.client = client;
533
+ }
534
+ client;
535
+ /** Return the generated operation contract. */
536
+ definition() {
537
+ return this.contract;
538
+ }
539
+ /** Return the same Call ID for each attempt of the logical write. */
540
+ idempotencyKey(callID) {
541
+ return callID;
542
+ }
543
+ };
544
+ var ListCampaignsOperation = class extends CampaignMonitorQuery {
545
+ contract = ListCampaignsDefinition;
546
+ /** Run the operation through the authenticated client. */
547
+ invoke(call, input) {
548
+ const page = pageNumbers(input.pageNumber, input.pageSize), status = input.status || "draft";
549
+ const endpoint = campaignPaths.get(status);
550
+ if (!validID(input.clientId) || !page || !endpoint) return read(this.client, call, void 0, emptyCampaigns, "listed", () => emptyCampaigns);
551
+ const path = `/clients/${pathSegment(input.clientId)}/${endpoint}` + (status === "sent" ? pageQuery(page) : "");
552
+ return read(this.client, call, path, emptyCampaigns, "listed", (value) => campaignPage(value, status, page));
553
+ }
554
+ };
555
+ var GetCampaignSummaryOperation = class extends CampaignMonitorQuery {
556
+ contract = GetCampaignSummaryDefinition;
557
+ /** Run the operation through the authenticated client. */
558
+ invoke(call, input) {
559
+ const path = validID(input.campaignId) ? `/campaigns/${pathSegment(input.campaignId)}/summary.json` : void 0;
560
+ return read(this.client, call, path, emptySummary, "found", campaignSummary);
561
+ }
562
+ };
563
+ var CreateDraftCampaignOperation = class extends CampaignMonitorMutation {
564
+ contract = CreateDraftCampaignDefinition;
565
+ /** Run the operation through the authenticated client. */
566
+ async invoke(call, input) {
567
+ if (!validID(input.clientId) || !input.name.trim() || !input.subject.trim() || !input.fromName.trim() || !validEmail(input.fromEmail) || !validEmail(input.replyTo) || !input.htmlUrl || !validURL(input.htmlUrl) || !input.listIds?.length && !input.segmentIds?.length || ![...input.listIds ?? [], ...input.segmentIds ?? []].every(validID)) return defect(call, emptyCampaign);
568
+ const payload = {
569
+ Name: input.name,
570
+ Subject: input.subject,
571
+ FromName: input.fromName,
572
+ FromEmail: input.fromEmail,
573
+ ReplyTo: input.replyTo,
574
+ HtmlUrl: input.htmlUrl,
575
+ ListIDs: input.listIds ?? null,
576
+ SegmentIDs: input.segmentIds ?? null,
577
+ ...input.inlineCss == null ? {} : { InlineCss: input.inlineCss }
578
+ };
579
+ return limitedWrite(
580
+ this.client,
581
+ call,
582
+ this.contract,
583
+ { method: "POST", path: resource("campaigns", input.clientId), branch: "created", payload, statuses: [201] },
584
+ emptyCampaign,
585
+ (body) => ({ id: identity(body), name: input.name }),
586
+ () => lookupDraft(this.client, call, input.clientId, input.name)
587
+ );
588
+ }
589
+ };
590
+ var SendCampaignOperation = class extends CampaignMonitorMutation {
591
+ contract = SendCampaignDefinition;
592
+ /** Run the operation through the authenticated client. */
593
+ async invoke(call, input) {
594
+ const date = input.sendDate ?? "";
595
+ if (!validID(input.clientId) || !validID(input.campaignId) || !validEmail(input.confirmationEmail) || date && !validDate(date))
596
+ return defect(call, emptyCampaign);
597
+ const path = `/campaigns/${pathSegment(input.campaignId)}/send.json`;
598
+ const payload = { ConfirmationEmail: input.confirmationEmail, SendDate: date || "Immediately" };
599
+ return limitedWrite(
600
+ this.client,
601
+ call,
602
+ this.contract,
603
+ { method: "POST", path, branch: "sent", payload, statuses: [200] },
604
+ emptyCampaign,
605
+ (body) => emptyAcknowledgement(body, { ...emptyCampaign, id: input.campaignId }),
606
+ () => lookupSent(this.client, call, input.clientId, input.campaignId, Boolean(date))
607
+ );
608
+ }
609
+ };
610
+ var SendCampaignPreviewOperation = class extends CampaignMonitorMutation {
611
+ contract = SendCampaignPreviewDefinition;
612
+ /** Run the operation through the authenticated client. */
613
+ async invoke(call, input) {
614
+ if (!validID(input.campaignId) || !input.recipients?.length || input.recipients.length > 5 || !input.recipients.every(validEmail))
615
+ return defect(call, emptyCampaign);
616
+ const path = `/campaigns/${pathSegment(input.campaignId)}/sendpreview.json`;
617
+ return limitedWrite(
618
+ this.client,
619
+ call,
620
+ this.contract,
621
+ { method: "POST", path, branch: "sent", payload: { PreviewRecipients: input.recipients }, statuses: [200] },
622
+ emptyCampaign,
623
+ (body) => emptyAcknowledgement(body, { ...emptyCampaign, id: input.campaignId })
624
+ );
625
+ }
626
+ };
627
+ var UnscheduleCampaignOperation = class extends CampaignMonitorMutation {
628
+ contract = UnscheduleCampaignDefinition;
629
+ /** Run the operation through the authenticated client. */
630
+ async invoke(call, input) {
631
+ if (!validID(input.campaignId)) return defect(call, emptyCampaign);
632
+ return write(this.client, call, {
633
+ method: "POST",
634
+ path: `/campaigns/${pathSegment(input.campaignId)}/unschedule.json`,
635
+ branch: "unscheduled"
636
+ }, emptyCampaign, { ...emptyCampaign, id: input.campaignId });
637
+ }
638
+ };
639
+ var DeleteCampaignOperation = class extends CampaignMonitorMutation {
640
+ contract = DeleteCampaignDefinition;
641
+ /** Run the operation through the authenticated client. */
642
+ async invoke(call, input) {
643
+ if (!validID(input.campaignId)) return defect(call, emptyCampaign);
644
+ return write(
645
+ this.client,
646
+ call,
647
+ { method: "DELETE", path: resource("campaigns", input.campaignId), branch: "deleted" },
648
+ emptyCampaign,
649
+ { ...emptyCampaign, id: input.campaignId }
650
+ );
651
+ }
652
+ };
653
+ var ListSegmentsOperation = class extends CampaignMonitorQuery {
654
+ contract = ListSegmentsDefinition;
655
+ /** Run the operation through the authenticated client. */
656
+ invoke(call, input) {
657
+ const path = validID(input.listId) ? `/lists/${pathSegment(input.listId)}/segments.json` : void 0;
658
+ return read(this.client, call, path, { segments: [] }, "listed", (value) => segments(value, input.listId));
659
+ }
660
+ };
661
+ var GetSegmentOperation = class extends CampaignMonitorQuery {
662
+ contract = GetSegmentDefinition;
663
+ /** Run the operation through the authenticated client. */
664
+ invoke(call, input) {
665
+ const path = validID(input.segmentId) ? resource("segments", input.segmentId) : void 0;
666
+ return read(this.client, call, path, emptySegmentProfile, "found", (value) => segmentProfile(value, input.segmentId));
667
+ }
668
+ };
669
+ var CreateSegmentOperation = class extends CampaignMonitorMutation {
670
+ contract = CreateSegmentDefinition;
671
+ /** Run the operation through the authenticated client. */
672
+ async invoke(call, input) {
673
+ if (!validID(input.listId) || !input.title.trim() || !validGroups(input.ruleGroups)) return defect(call, emptySegment);
674
+ return limitedWrite(
675
+ this.client,
676
+ call,
677
+ this.contract,
678
+ {
679
+ method: "POST",
680
+ path: resource("segments", input.listId),
681
+ branch: "created",
682
+ payload: segmentPayload(input.title, input.ruleGroups),
683
+ statuses: [201]
684
+ },
685
+ emptySegment,
686
+ (body) => ({ id: identity(body), listId: input.listId, title: input.title })
687
+ );
688
+ }
689
+ };
690
+ var UpdateSegmentOperation = class extends CampaignMonitorMutation {
691
+ contract = UpdateSegmentDefinition;
692
+ /** Run the operation through the authenticated client. */
693
+ async invoke(call, input) {
694
+ if (!validID(input.segmentId) || !input.title.trim() || !validGroups(input.ruleGroups)) return defect(call, emptySegment);
695
+ return write(this.client, call, {
696
+ method: "PUT",
697
+ path: resource("segments", input.segmentId),
698
+ branch: "updated",
699
+ payload: segmentPayload(input.title, input.ruleGroups),
700
+ hasNotFound: true
701
+ }, emptySegment, { ...emptySegment, id: input.segmentId, title: input.title });
702
+ }
703
+ };
704
+ var DeleteSegmentOperation = class extends CampaignMonitorMutation {
705
+ contract = DeleteSegmentDefinition;
706
+ /** Run the operation through the authenticated client. */
707
+ async invoke(call, input) {
708
+ if (!validID(input.segmentId)) return defect(call, emptySegment);
709
+ return write(
710
+ this.client,
711
+ call,
712
+ { method: "DELETE", path: resource("segments", input.segmentId), branch: "deleted" },
713
+ emptySegment,
714
+ { ...emptySegment, id: input.segmentId }
715
+ );
716
+ }
717
+ };
718
+ var GetListOperation = class extends CampaignMonitorQuery {
719
+ contract = GetListDefinition;
720
+ /** Run the operation through the authenticated client. */
721
+ invoke(call, input) {
722
+ const path = validID(input.listId) ? resource("lists", input.listId) : void 0;
723
+ return read(this.client, call, path, emptyListProfile, "found", (value) => listProfile(value, input.listId));
724
+ }
725
+ };
726
+ var CreateListOperation = class extends CampaignMonitorMutation {
727
+ contract = CreateListDefinition;
728
+ /** Run the operation through the authenticated client. */
729
+ async invoke(call, input) {
730
+ const payload = listSettings(input);
731
+ if (!validID(input.clientId) || !payload) return defect(call, emptyList);
732
+ return limitedWrite(
733
+ this.client,
734
+ call,
735
+ this.contract,
736
+ { method: "POST", path: resource("lists", input.clientId), branch: "created", payload, statuses: [201] },
737
+ emptyList,
738
+ (body) => ({ id: identity(body), title: input.title })
739
+ );
740
+ }
741
+ };
742
+ var UpdateListOperation = class extends CampaignMonitorMutation {
743
+ contract = UpdateListDefinition;
744
+ /** Run the operation through the authenticated client. */
745
+ async invoke(call, input) {
746
+ const settings = listSettings(input);
747
+ if (!validID(input.listId) || !settings) return defect(call, emptyList);
748
+ const payload = { ...settings, AddUnsubscribesToSuppList: false, ScrubActiveWithSuppList: false };
749
+ return write(this.client, call, {
750
+ method: "PUT",
751
+ path: resource("lists", input.listId),
752
+ branch: "updated",
753
+ payload,
754
+ hasNotFound: true
755
+ }, emptyList, { id: input.listId, title: input.title });
756
+ }
757
+ };
758
+ var DeleteListOperation = class extends CampaignMonitorMutation {
759
+ contract = DeleteListDefinition;
760
+ /** Run the operation through the authenticated client. */
761
+ async invoke(call, input) {
762
+ if (!validID(input.listId)) return defect(call, emptyList);
763
+ return write(
764
+ this.client,
765
+ call,
766
+ { method: "DELETE", path: resource("lists", input.listId), branch: "deleted" },
767
+ emptyList,
768
+ { ...emptyList, id: input.listId }
769
+ );
770
+ }
771
+ };
772
+ var ListSubscribersOperation = class extends CampaignMonitorQuery {
773
+ contract = ListSubscribersDefinition;
774
+ /** Run the operation through the authenticated client. */
775
+ invoke(call, input) {
776
+ const page = pageNumbers(input.pageNumber, input.pageSize), state = input.state || "active";
777
+ if (!validID(input.listId) || !page || !subscriberStates.includes(state))
778
+ return read(this.client, call, void 0, emptySubscribers, "listed", () => emptySubscribers);
779
+ return read(
780
+ this.client,
781
+ call,
782
+ `/lists/${pathSegment(input.listId)}/${state}.json` + pageQuery(page),
783
+ emptySubscribers,
784
+ "listed",
785
+ (value) => subscribers(value, page)
786
+ );
787
+ }
788
+ };
789
+ var ListSubscriberListsOperation = class extends CampaignMonitorQuery {
790
+ contract = ListSubscriberListsDefinition;
791
+ /** Run the operation through the authenticated client. */
792
+ invoke(call, input) {
793
+ const path = validID(input.clientId) ? `/clients/${pathSegment(input.clientId)}/lists.json` : void 0;
794
+ return read(this.client, call, path, { lists: [] }, "listed", subscriberLists);
795
+ }
796
+ };
797
+ var GetSubscriberOperation = class extends CampaignMonitorQuery {
798
+ contract = GetSubscriberDefinition;
799
+ /** Run the operation through the authenticated client. */
800
+ invoke(call, input) {
801
+ const path = validID(input.listId) && validEmail(input.email) ? subscriberPath(input.listId, input.email) : void 0;
802
+ return read(this.client, call, path, emptySubscriberProfile, "found", subscriberProfile);
803
+ }
804
+ };
805
+ var UpsertSubscriberOperation = class extends CampaignMonitorMutation {
806
+ contract = UpsertSubscriberDefinition;
807
+ /** Run the operation through the authenticated client. */
808
+ invoke(call, input) {
809
+ return changeSubscriber(this.client, call, input.listId, input.email, input.name, false);
810
+ }
811
+ };
812
+ var UpdateSubscriberOperation = class extends CampaignMonitorMutation {
813
+ contract = UpdateSubscriberDefinition;
814
+ /** Run the operation through the authenticated client. */
815
+ invoke(call, input) {
816
+ return changeSubscriber(this.client, call, input.listId, input.email, input.name, true);
817
+ }
818
+ };
819
+ var DeleteSubscriberOperation = class extends CampaignMonitorMutation {
820
+ contract = DeleteSubscriberDefinition;
821
+ /** Run the operation through the authenticated client. */
822
+ async invoke(call, input) {
823
+ if (!validID(input.listId) || !validEmail(input.email)) return defect(call, emptySubscriber);
824
+ return write(
825
+ this.client,
826
+ call,
827
+ { method: "DELETE", path: subscriberPath(input.listId, input.email), branch: "deleted" },
828
+ emptySubscriber,
829
+ { email: input.email }
830
+ );
831
+ }
832
+ };
833
+ var UnsubscribeSubscriberOperation = class extends CampaignMonitorMutation {
834
+ contract = UnsubscribeSubscriberDefinition;
835
+ /** Run the operation through the authenticated client. */
836
+ async invoke(call, input) {
837
+ if (!validID(input.listId) || !validEmail(input.email)) return defect(call, emptySubscriber);
838
+ const path = `/subscribers/${pathSegment(input.listId)}/unsubscribe.json`;
839
+ return write(
840
+ this.client,
841
+ call,
842
+ {
843
+ method: "POST",
844
+ path,
845
+ branch: "unsubscribed",
846
+ payload: { EmailAddress: input.email },
847
+ statuses: [200]
848
+ },
849
+ emptySubscriber,
850
+ { email: input.email },
851
+ void 0,
852
+ () => confirmUnsubscribe(this.client, call, subscriberPath(input.listId, input.email), input.email)
853
+ );
854
+ }
855
+ };
856
+ function failure(call, kind, message) {
857
+ return { kind, provider: "campaignmonitor", operation: call.operation.operationId, message };
858
+ }
859
+ function terminal(call, empty, branch, kind, message) {
860
+ return newMutationBranch(branch, empty, {}, failure(call, kind, message));
861
+ }
862
+ function defect(call, empty) {
863
+ return terminal(call, empty, "defect", "VALIDATION", "Campaign Monitor input is invalid");
864
+ }
865
+ function retry(call, kind, delay = 0) {
866
+ return newMutationRetry(failure(call, kind, "Campaign Monitor request may be retried"), delay);
867
+ }
868
+ function retryKind(status) {
869
+ return status === 429 ? "RATE_LIMIT" : "AVAILABILITY";
870
+ }
871
+ function responseFailure(result) {
872
+ if (result.error === "tooLarge") return "RESPONSE_TOO_LARGE";
873
+ return result.error ? "TRANSPORT" : void 0;
874
+ }
875
+ async function read(client, call, path, empty, branch, parse) {
876
+ const terminal2 = (id, kind, message) => newQueryBranch(id, empty, {}, failure(call, kind, message));
877
+ if (path === void 0) return terminal2("defect", "VALIDATION", "Campaign Monitor input is invalid");
878
+ const result = await client.request(call, "GET", path);
879
+ if (result.error === "credential") return terminal2("defect", "AUTHENTICATION", "Campaign Monitor credentials are invalid");
880
+ if (result.error === "request") return newQueryRetry(failure(call, "TRANSPORT", "Campaign Monitor request failed"));
881
+ if (result.status === 408 || result.status === 429 || result.status >= 500)
882
+ return newQueryRetry(failure(call, retryKind(result.status), "Campaign Monitor asked to retry"), result.retryAfterMs);
883
+ if (result.status === 404 && branch === "found")
884
+ return terminal2("notFound", "NOT_FOUND", "Campaign Monitor did not find the resource");
885
+ if (result.status !== 200) return terminal2("providerRejected", "PROVIDER_REJECTION", "Campaign Monitor rejected the read");
886
+ if (result.error === "tooLarge") return terminal2("invalidResponse", "RESPONSE_TOO_LARGE", "Campaign Monitor response exceeded the limit");
887
+ if (result.error) return newQueryRetry(failure(call, "TRANSPORT", "Campaign Monitor response was interrupted"));
888
+ try {
889
+ return newQueryBranch(branch, parse(providerJSON(result.body)));
890
+ } catch {
891
+ return terminal2("invalidResponse", "PROTOCOL", "Campaign Monitor returned invalid JSON");
892
+ }
893
+ }
894
+ async function write(client, call, spec, empty, value, parse = (body) => body.length === 0, confirm) {
895
+ const result = await client.request(call, spec.method, spec.path, spec.payload);
896
+ const repeated = call.context.attempt > 1;
897
+ if (result.error === "credential") {
898
+ if (repeated) return retry(call, "TRANSPORT");
899
+ return terminal(call, empty, "defect", "AUTHENTICATION", "Campaign Monitor credentials are invalid");
900
+ }
901
+ if (result.error === "request") return retry(call, "TRANSPORT");
902
+ if (result.status === 408 || result.status === 429 || result.status >= 500)
903
+ return retry(call, retryKind(result.status), result.retryAfterMs);
904
+ if (confirm && result.status === 400 && notInList(result)) return confirm();
905
+ if (!(spec.statuses ?? [200, 204]).includes(result.status)) {
906
+ if (repeated || !definiteRefusal(result)) return retry(call, "TRANSPORT");
907
+ if (result.status === 404 && spec.hasNotFound)
908
+ return terminal(call, empty, "notFound", "NOT_FOUND", "Campaign Monitor did not find the resource");
909
+ return terminal(call, empty, "providerRejected", "PROVIDER_REJECTION", "Campaign Monitor rejected the write");
910
+ }
911
+ const error = responseFailure(result);
912
+ if (error) return retry(call, error);
913
+ if (!parse(result.body)) return retry(call, "PROTOCOL");
914
+ return newMutationBranch(spec.branch, value);
915
+ }
916
+ async function limitedWrite(client, call, contract, spec, empty, parse, readBack) {
917
+ const uncertain = (kind) => newMutationUncertain(empty, failure(call, kind, "Campaign Monitor write could not be confirmed"));
918
+ const maxSends = call.maxSendsOverride ?? definitionMaxSends(contract);
919
+ let fence;
920
+ try {
921
+ fence = newFence(call, contract.stepDefaults.executeMethodTimeoutMs, { maxSends });
922
+ } catch {
923
+ return terminal(call, empty, "defect", "LOCAL_DEFECT", "Campaign Monitor dispatch fence is invalid");
924
+ }
925
+ const decision = await fence.decide();
926
+ if (decision.kind === "failClosed") return retry(call, "TRANSPORT");
927
+ if (readBack && decision.kind !== "sendAllowed") {
928
+ const confirmed = await readBack();
929
+ if (confirmed !== void 0) return newMutationBranch(spec.branch, confirmed);
930
+ }
931
+ if (decision.kind === "readBackRequired") return uncertain("TRANSPORT");
932
+ const priorSends = decision.priorSendUpperBound ?? 0;
933
+ const atCap = priorSends + 1 >= maxSends;
934
+ let result;
935
+ try {
936
+ result = await fence.dispatch((signal) => client.request(call, spec.method, spec.path, spec.payload, signal));
937
+ } catch (error) {
938
+ if (error instanceof CheckpointError || error instanceof DispatchNotAllowedError || error instanceof InsufficientTimeError)
939
+ return retry(call, "AVAILABILITY");
940
+ return atCap ? uncertain("TRANSPORT") : retry(call, "TRANSPORT");
941
+ }
942
+ if (result.status === 429 || result.status === 503) {
943
+ try {
944
+ await fence.recordCanResend();
945
+ } catch {
946
+ return retry(call, "AVAILABILITY");
947
+ }
948
+ return retry(call, retryKind(result.status), result.retryAfterMs);
949
+ }
950
+ if (result.error || result.status === 408 || result.status >= 500)
951
+ return atCap ? uncertain("TRANSPORT") : retry(call, "TRANSPORT");
952
+ if (!(spec.statuses ?? [200, 204]).includes(result.status)) {
953
+ if (priorSends || !definiteRefusal(result)) return retry(call, "TRANSPORT");
954
+ try {
955
+ await fence.recordCanResend();
956
+ } catch {
957
+ return retry(call, "TRANSPORT");
958
+ }
959
+ return terminal(call, empty, "providerRejected", "PROVIDER_REJECTION", "Campaign Monitor rejected the write");
960
+ }
961
+ try {
962
+ return newMutationBranch(spec.branch, parse(result.body));
963
+ } catch {
964
+ return atCap ? uncertain("PROTOCOL") : retry(call, "PROTOCOL");
965
+ }
966
+ }
967
+ function definiteRefusal(result) {
968
+ if (result.error || !failures.has(result.status)) return false;
969
+ const absent = (value) => value == null || typeof value === "object" && Object.keys(value).length === 0;
970
+ try {
971
+ const body = object(JSON.parse(Buffer.from(result.body).toString("utf8")));
972
+ return body.success !== true && ["data", "result", "results"].every((name) => absent(body[name])) && ["code", "message", "error", "errors", "errorInfo", "Code", "Message"].some((name) => body[name] !== "" && !absent(body[name]));
973
+ } catch {
974
+ return false;
975
+ }
976
+ }
977
+ function providerJSON(body) {
978
+ return parseJSONNumberTokens(Buffer.from(body).toString("utf8"));
979
+ }
980
+ function object(value) {
981
+ const nativeJSON = JSON;
982
+ if (typeof value !== "object" || value === null || Array.isArray(value) || nativeJSON.isRawJSON(value))
983
+ throw new TypeError("Campaign Monitor object is missing");
984
+ return value;
985
+ }
986
+ function array(value) {
987
+ if (!Array.isArray(value)) throw new TypeError("Campaign Monitor list is missing");
988
+ return value;
989
+ }
990
+ function field(body, name) {
991
+ if (Object.hasOwn(body, name)) return body[name];
992
+ const key = Object.keys(body).find((key2) => key2.toLowerCase() === name.toLowerCase());
993
+ return key === void 0 ? void 0 : body[key];
994
+ }
995
+ function text(body, name, required = false) {
996
+ const value = field(body, name);
997
+ if (value == null && !required) return "";
998
+ if (typeof value !== "string" || required && !value) throw new TypeError("Campaign Monitor text field is invalid");
999
+ return value;
1000
+ }
1001
+ function integer(value) {
1002
+ return decodeSignedInteger(value ?? 0);
1003
+ }
1004
+ function signed(value) {
1005
+ return BigInt(typeof value === "number" ? value : value.rawJSON);
1006
+ }
1007
+ function count(row, name) {
1008
+ const value = integer(field(row, name));
1009
+ if (signed(value) < 0n) throw new TypeError("Campaign Monitor returned a negative count");
1010
+ return value;
1011
+ }
1012
+ function pageNumbers(pageNumber, pageSize) {
1013
+ try {
1014
+ const number = integer(pageNumber), size = integer(pageSize);
1015
+ if (signed(number) >= 0n && typeof size === "number" && size >= 0 && size <= 1e3) return [number || 1, size || 100];
1016
+ } catch {
1017
+ return void 0;
1018
+ }
1019
+ return void 0;
1020
+ }
1021
+ function counts(row, page) {
1022
+ const pageNumber = count(row, "PageNumber"), pageSize = count(row, "PageSize");
1023
+ if (signed(pageNumber) !== signed(page[0]) || pageSize !== page[1])
1024
+ throw new TypeError("Campaign Monitor page does not match the request");
1025
+ return { pageNumber, pageSize, totalRecords: count(row, "TotalNumberOfRecords"), numberOfPages: count(row, "NumberOfPages") };
1026
+ }
1027
+ function pathSegment(value) {
1028
+ return encodeURIComponent(value).replace(/[!'()*]/g, (character) => `%${character.charCodeAt(0).toString(16).toUpperCase()}`).replace(/%(24|26|2B|3A|3D|40)/gi, (encoded) => String.fromCharCode(Number.parseInt(encoded.slice(1), 16)));
1029
+ }
1030
+ function resource(kind, id) {
1031
+ return `/${kind}/${pathSegment(id)}.json`;
1032
+ }
1033
+ function subscriberPath(id, email = "") {
1034
+ const path = resource("subscribers", id);
1035
+ return email ? path + "?" + new URLSearchParams({ email }) : path;
1036
+ }
1037
+ function pageQuery(page) {
1038
+ return "?" + new URLSearchParams({ page: String(signed(page[0])), pagesize: String(page[1]) });
1039
+ }
1040
+ function validID(value) {
1041
+ return typeof value === "string" && Boolean(value) && value.trim() === value && !/[/?#\r\n]/.test(value);
1042
+ }
1043
+ function identity(body) {
1044
+ const id = providerJSON(body);
1045
+ if (!validID(id)) throw new TypeError("Campaign Monitor returned an invalid ID");
1046
+ return id;
1047
+ }
1048
+ function validEmail(value) {
1049
+ const address = emailAddresses.parseOneAddress({ input: value, rfc6532: true });
1050
+ return address?.type === "mailbox" && address.address === value && value.trim() === value;
1051
+ }
1052
+ function validURL(value) {
1053
+ if (!value) return true;
1054
+ if (!value.startsWith("https://")) return false;
1055
+ try {
1056
+ const url = new URL(value);
1057
+ return Boolean(url.host) && !url.username && !url.password && !url.hash;
1058
+ } catch {
1059
+ return false;
1060
+ }
1061
+ }
1062
+ function validDate(value) {
1063
+ const parts = /^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{1,2}):([0-9]{2})$/.exec(value);
1064
+ if (!parts || parts[0] !== value) return false;
1065
+ const [, year, month, day, hour, minute] = parts;
1066
+ const date = /* @__PURE__ */ new Date(`${year}-${month}-${day}T${hour.padStart(2, "0")}:${minute}:00Z`);
1067
+ return date.getUTCDate() === Number(day) && date.getUTCHours() === Number(hour);
1068
+ }
1069
+ function emptyAcknowledgement(body, value) {
1070
+ if (body.length) throw new TypeError("Campaign Monitor returned an unexpected confirmation body");
1071
+ return value;
1072
+ }
1073
+ function returnedEmail(body, expected) {
1074
+ try {
1075
+ const email = providerJSON(body);
1076
+ return typeof email === "string" && email.toLowerCase() === expected.toLowerCase();
1077
+ } catch {
1078
+ return false;
1079
+ }
1080
+ }
1081
+ function notInList(result) {
1082
+ try {
1083
+ return integer(field(object(providerJSON(result.body)), "Code")) === 203;
1084
+ } catch {
1085
+ return false;
1086
+ }
1087
+ }
1088
+ function campaignPage(value, status, page) {
1089
+ let rows;
1090
+ let pageInfo;
1091
+ if (status === "sent") {
1092
+ const record = object(value);
1093
+ rows = array(field(record, "Results"));
1094
+ pageInfo = counts(record, page);
1095
+ } else {
1096
+ rows = array(value);
1097
+ pageInfo = { pageNumber: 1, pageSize: rows.length, totalRecords: rows.length, numberOfPages: 1 };
1098
+ }
1099
+ const campaigns = rows.map((value2) => {
1100
+ const row = object(value2), id = text(row, "CampaignID");
1101
+ if (!validID(id)) throw new TypeError("Campaign Monitor campaign ID is invalid");
1102
+ return { id, name: text(row, "Name", true), subject: text(row, "Subject"), status };
1103
+ });
1104
+ return { campaigns, ...pageInfo };
1105
+ }
1106
+ function campaignSummary(value) {
1107
+ const row = object(value);
1108
+ return {
1109
+ name: text(row, "Name", true),
1110
+ recipients: count(row, "Recipients"),
1111
+ totalOpened: count(row, "TotalOpened"),
1112
+ clicks: count(row, "Clicks"),
1113
+ unsubscribed: count(row, "Unsubscribed")
1114
+ };
1115
+ }
1116
+ function segment(value) {
1117
+ const row = object(value), id = text(row, "SegmentID"), listId = text(row, "ListID");
1118
+ if (!validID(id) || !validID(listId)) throw new TypeError("Campaign Monitor segment IDs are invalid");
1119
+ return { id, listId, title: text(row, "Title", true) };
1120
+ }
1121
+ function segments(value, listId) {
1122
+ const segments2 = array(value).map(segment);
1123
+ if (segments2.some((segment2) => segment2.listId !== listId)) throw new TypeError("Campaign Monitor segment belongs to a different list");
1124
+ return { segments: segments2 };
1125
+ }
1126
+ function segmentProfile(value, id) {
1127
+ const result = segment(value), row = object(value);
1128
+ if (result.id !== id) throw new TypeError("Campaign Monitor returned a different segment");
1129
+ const ruleGroups = array(field(row, "RuleGroups")).map((group) => ({
1130
+ rules: array(field(object(group), "Rules")).map((rule) => {
1131
+ const row2 = object(rule);
1132
+ return { ruleType: text(row2, "RuleType", true), clause: text(row2, "Clause", true) };
1133
+ })
1134
+ }));
1135
+ return { ...result, activeSubscribers: count(row, "ActiveSubscribers"), ruleGroups };
1136
+ }
1137
+ function validGroups(groups) {
1138
+ return (groups ?? []).every((group) => Boolean(group.rules?.length && group.rules.every((rule) => rule.ruleType.trim() && rule.clause.trim())));
1139
+ }
1140
+ function segmentPayload(title, groups) {
1141
+ return { Title: title, ...groups == null ? {} : {
1142
+ RuleGroups: groups.map((group) => ({ Rules: group.rules.map((rule) => ({ RuleType: rule.ruleType, Clause: rule.clause })) }))
1143
+ } };
1144
+ }
1145
+ function listProfile(value, id) {
1146
+ const row = object(value), unsubscribeSetting = text(row, "UnsubscribeSetting"), confirmed = field(row, "ConfirmedOptIn");
1147
+ if (text(row, "ListID") !== id || !unsubscribeSettings.includes(unsubscribeSetting) || confirmed != null && typeof confirmed !== "boolean") throw new TypeError("Campaign Monitor list settings are invalid");
1148
+ const unsubscribePage = text(row, "UnsubscribePage"), confirmationSuccessPage = text(row, "ConfirmationSuccessPage");
1149
+ return {
1150
+ id,
1151
+ title: text(row, "Title", true),
1152
+ unsubscribeSetting,
1153
+ confirmedOptIn: confirmed === true,
1154
+ ...unsubscribePage ? { unsubscribePage } : {},
1155
+ ...confirmationSuccessPage ? { confirmationSuccessPage } : {}
1156
+ };
1157
+ }
1158
+ function listSettings(input) {
1159
+ const unsubscribePage = input.unsubscribePage ?? "", confirmation = input.confirmationSuccessPage ?? "";
1160
+ if (!input.title || input.title.trim() !== input.title || !unsubscribeSettings.includes(input.unsubscribeSetting) || !validURL(unsubscribePage) || !validURL(confirmation)) return void 0;
1161
+ return {
1162
+ Title: input.title,
1163
+ UnsubscribeSetting: input.unsubscribeSetting,
1164
+ ConfirmedOptIn: input.confirmedOptIn,
1165
+ ...unsubscribePage ? { UnsubscribePage: unsubscribePage } : {},
1166
+ ...confirmation ? { ConfirmationSuccessPage: confirmation } : {}
1167
+ };
1168
+ }
1169
+ function subscriberProfile(value) {
1170
+ const row = object(value);
1171
+ return { email: text(row, "EmailAddress", true), name: text(row, "Name"), state: text(row, "State", true) };
1172
+ }
1173
+ function subscribers(value, page) {
1174
+ const row = object(value), subscribers2 = array(field(row, "Results")).map(subscriberProfile);
1175
+ if (subscribers2.some((subscriber) => !validEmail(subscriber.email))) throw new TypeError("Campaign Monitor subscriber email is invalid");
1176
+ return { subscribers: subscribers2, ...counts(row, page) };
1177
+ }
1178
+ function subscriberLists(value) {
1179
+ return { lists: array(value).map((value2) => {
1180
+ const row = object(value2);
1181
+ return { id: text(row, "ListID", true), name: text(row, "Name", true) };
1182
+ }) };
1183
+ }
1184
+ async function lookupDraft(client, call, clientId, name) {
1185
+ const result = await client.request(call, "GET", `/clients/${pathSegment(clientId)}/drafts.json`);
1186
+ if (result.error || result.status !== 200) return void 0;
1187
+ try {
1188
+ const rows = array(providerJSON(result.body)).map(object).map((row) => ({ name: text(row, "Name"), id: text(row, "CampaignID") }));
1189
+ const matches = rows.filter((row) => row.name === name);
1190
+ return matches.length === 1 && validID(matches[0].id) ? matches[0] : void 0;
1191
+ } catch {
1192
+ return void 0;
1193
+ }
1194
+ }
1195
+ async function lookupSent(client, call, clientId, id, scheduled) {
1196
+ const endpoint = scheduled ? "scheduled.json" : "campaigns.json?page=1&pagesize=1000";
1197
+ const result = await client.request(call, "GET", `/clients/${pathSegment(clientId)}/${endpoint}`);
1198
+ if (result.error || result.status !== 200) return void 0;
1199
+ try {
1200
+ const value = providerJSON(result.body);
1201
+ const rows = array(scheduled ? value : field(object(value), "Results"));
1202
+ return rows.map((row) => text(object(row), "CampaignID")).includes(id) ? { ...emptyCampaign, id } : void 0;
1203
+ } catch {
1204
+ return void 0;
1205
+ }
1206
+ }
1207
+ async function changeSubscriber(client, call, id, email, name, update) {
1208
+ if (!validID(id) || !validEmail(email) || !name.trim()) return defect(call, emptySubscriber);
1209
+ const payload = { EmailAddress: email, Name: name, Resubscribe: false, RestartSubscriptionBasedAutoresponders: false };
1210
+ const spec = {
1211
+ method: update ? "PUT" : "POST",
1212
+ path: subscriberPath(id, update ? email : ""),
1213
+ branch: update ? "updated" : "saved",
1214
+ payload,
1215
+ statuses: [update ? 200 : 201],
1216
+ hasNotFound: update
1217
+ };
1218
+ return write(client, call, spec, emptySubscriber, { email }, (body) => returnedEmail(body, email));
1219
+ }
1220
+ async function confirmUnsubscribe(client, call, path, email) {
1221
+ const result = await client.request(call, "GET", path);
1222
+ if (result.error === "credential" || result.error === "request") return retry(call, "TRANSPORT");
1223
+ if (result.status === 408 || result.status === 429 || result.status >= 500)
1224
+ return retry(call, retryKind(result.status), result.retryAfterMs);
1225
+ if (result.status !== 200) return retry(call, "TRANSPORT");
1226
+ const error = responseFailure(result);
1227
+ if (error) return retry(call, error);
1228
+ try {
1229
+ const profile = subscriberProfile(providerJSON(result.body));
1230
+ if (profile.email.toLowerCase() !== email.toLowerCase()) return retry(call, "PROTOCOL");
1231
+ if (profile.state !== "Unsubscribed") return retry(call, "TRANSPORT");
1232
+ return newMutationBranch("unsubscribed", { email });
1233
+ } catch {
1234
+ return retry(call, "PROTOCOL");
1235
+ }
1236
+ }
1237
+
1238
+ // src/client.ts
42
1239
  var emptyClients = () => ({ clients: [] });
43
1240
  var CampaignMonitorClient = class {
44
1241
  /** Validate account configuration without contacting Campaign Monitor. */
@@ -61,41 +1258,148 @@ var CampaignMonitorClient = class {
61
1258
  listClients() {
62
1259
  return new ListClientsOperation(this);
63
1260
  }
1261
+ /** List draft, scheduled, or sent campaigns for one client. */
1262
+ listCampaigns() {
1263
+ return new ListCampaignsOperation(this);
1264
+ }
1265
+ /** Read sent campaign result counts. */
1266
+ getCampaignSummary() {
1267
+ return new GetCampaignSummaryOperation(this);
1268
+ }
1269
+ /** Create a draft campaign with hosted HTML and selected recipients. */
1270
+ createDraftCampaign() {
1271
+ return new CreateDraftCampaignOperation(this);
1272
+ }
1273
+ /** Send or schedule an existing draft campaign in the client's timezone. */
1274
+ sendCampaign() {
1275
+ return new SendCampaignOperation(this);
1276
+ }
1277
+ /** Send a draft campaign preview to selected addresses. */
1278
+ sendCampaignPreview() {
1279
+ return new SendCampaignPreviewOperation(this);
1280
+ }
1281
+ /** Move a scheduled campaign back to drafts. */
1282
+ unscheduleCampaign() {
1283
+ return new UnscheduleCampaignOperation(this);
1284
+ }
1285
+ /** Delete a campaign by ID. */
1286
+ deleteCampaign() {
1287
+ return new DeleteCampaignOperation(this);
1288
+ }
1289
+ /** List segment IDs and names for one subscriber list. */
1290
+ listSegments() {
1291
+ return new ListSegmentsOperation(this);
1292
+ }
1293
+ /** Read a segment's title, list, rules, and active count. */
1294
+ getSegment() {
1295
+ return new GetSegmentOperation(this);
1296
+ }
1297
+ /** Create a segment with optional rule groups. */
1298
+ createSegment() {
1299
+ return new CreateSegmentOperation(this);
1300
+ }
1301
+ /** Replace a segment's title and optionally its complete rule groups. */
1302
+ updateSegment() {
1303
+ return new UpdateSegmentOperation(this);
1304
+ }
1305
+ /** Delete one segment by ID. */
1306
+ deleteSegment() {
1307
+ return new DeleteSegmentOperation(this);
1308
+ }
1309
+ /** Read one subscriber list's settings. */
1310
+ getList() {
1311
+ return new GetListOperation(this);
1312
+ }
1313
+ /** Create a subscriber list for one client. */
1314
+ createList() {
1315
+ return new CreateListOperation(this);
1316
+ }
1317
+ /** Replace one list's basic settings without suppression-list scrubbing. */
1318
+ updateList() {
1319
+ return new UpdateListOperation(this);
1320
+ }
1321
+ /** Delete one subscriber list by ID. */
1322
+ deleteList() {
1323
+ return new DeleteListOperation(this);
1324
+ }
1325
+ /** List one page of subscribers in a selected list state. */
1326
+ listSubscribers() {
1327
+ return new ListSubscribersOperation(this);
1328
+ }
1329
+ /** List subscriber list IDs and names for one client. */
1330
+ listSubscriberLists() {
1331
+ return new ListSubscriberListsOperation(this);
1332
+ }
1333
+ /** Read one subscriber's email, name, and state. */
1334
+ getSubscriber() {
1335
+ return new GetSubscriberOperation(this);
1336
+ }
1337
+ /** Add a subscriber or replace the existing subscriber's name. */
1338
+ upsertSubscriber() {
1339
+ return new UpsertSubscriberOperation(this);
1340
+ }
1341
+ /** Replace one existing subscriber's name without resubscribing. */
1342
+ updateSubscriber() {
1343
+ return new UpdateSubscriberOperation(this);
1344
+ }
1345
+ /** Mark one active subscriber deleted in a list. */
1346
+ deleteSubscriber() {
1347
+ return new DeleteSubscriberOperation(this);
1348
+ }
1349
+ /** Unsubscribe one active subscriber and apply the list's suppression policy. */
1350
+ unsubscribeSubscriber() {
1351
+ return new UnsubscribeSubscriberOperation(this);
1352
+ }
64
1353
  /** Send one read and classify transport, HTTP, and response-size outcomes. */
65
1354
  async exchange(call) {
1355
+ const result = await this.request(call, "GET", "/clients.json");
1356
+ if (result.error === "credential") return { branch: "defect", failure: failure2("AUTHENTICATION", "connection credentials are unavailable or invalid") };
1357
+ if (result.error === "request") return { retry: true, failure: failure2("TRANSPORT", "Campaign Monitor request failed") };
1358
+ if (result.status === 429 || result.status === 408 || result.status >= 500)
1359
+ return { retry: true, retryAfterMs: result.retryAfterMs, failure: failure2(result.status === 429 ? "RATE_LIMIT" : "AVAILABILITY", "Campaign Monitor asked to retry the read") };
1360
+ if (result.status !== 200) return { branch: "providerRejected", failure: failure2("PROVIDER_REJECTION", `Campaign Monitor rejected HTTP ${result.status}`) };
1361
+ if (result.error === "tooLarge") return { branch: "invalidResponse", failure: failure2("RESPONSE_TOO_LARGE", "Campaign Monitor response exceeded the configured limit") };
1362
+ if (result.error) return { retry: true, failure: failure2("TRANSPORT", "Campaign Monitor response was interrupted") };
1363
+ return { body: result.body };
1364
+ }
1365
+ /** Resolve credentials and send one bounded provider request. */
1366
+ async request(call, method, path, payload, signal = call.context.cancellationSignal) {
1367
+ const empty = (error) => ({ status: 0, body: new Uint8Array(), retryAfterMs: 0, error });
66
1368
  let apiKey;
67
1369
  try {
68
- const resolved = await this.credentials.resolve(call, call.context.cancellationSignal);
1370
+ const resolved = await this.credentials.resolve(call, signal);
69
1371
  apiKey = resolved.apiKey instanceof SecretString ? resolved.apiKey.reveal() : "";
70
1372
  } catch {
71
- return { branch: "defect", failure: failure("AUTHENTICATION", "connection credentials are unavailable or invalid") };
1373
+ return empty("credential");
72
1374
  }
73
- if (!apiKey || !isHeaderSafeCredential(apiKey)) return { branch: "defect", failure: failure("AUTHENTICATION", "connection credentials are unavailable or invalid") };
74
- const request = {
75
- url: `${this.baseUrl}/clients.json`,
76
- method: "GET",
77
- headers: { Accept: "application/json", Authorization: `Basic ${Buffer.from(`${apiKey}:`, "utf8").toString("base64")}` },
78
- maxResponseBytes: this.maxResponseBytes,
79
- timeoutMs: this.timeoutMs,
80
- addressPolicy: this.baseUrl.startsWith("https://") ? "publicHTTPS" : "privateNetworkHTTP",
81
- signal: call.context.cancellationSignal
82
- };
83
- let response;
1375
+ if (!apiKey || !isHeaderSafeCredential(apiKey)) return empty("credential");
84
1376
  try {
85
- response = await this.sendRequest(request);
1377
+ const request = {
1378
+ url: this.baseUrl + path,
1379
+ method,
1380
+ headers: {
1381
+ Accept: "application/json",
1382
+ Authorization: `Basic ${Buffer.from(`${apiKey}:`, "utf8").toString("base64")}`,
1383
+ ...payload === void 0 ? {} : { "Content-Type": "application/json" }
1384
+ },
1385
+ ...payload === void 0 ? {} : { body: Buffer.from(JSON.stringify(payload)) },
1386
+ maxResponseBytes: this.maxResponseBytes,
1387
+ timeoutMs: this.timeoutMs,
1388
+ addressPolicy: this.baseUrl.startsWith("https://") ? "publicHTTPS" : "privateNetworkHTTP",
1389
+ signal
1390
+ };
1391
+ const response = await this.sendRequest(request);
1392
+ const retryAfterMs = providerRetryAfter(response.headers);
1393
+ if (response.body.length > this.maxResponseBytes)
1394
+ return { status: response.status, body: new Uint8Array(), retryAfterMs, error: "tooLarge" };
1395
+ return { status: response.status, body: response.body, retryAfterMs };
86
1396
  } catch (error) {
87
- if (error instanceof BodyTooLargeError && error.status !== void 0) {
88
- response = { status: error.status, headers: error.headers ?? {}, body: new Uint8Array() };
89
- if (response.status === 200) return { branch: "invalidResponse", failure: failure("RESPONSE_TOO_LARGE", "Campaign Monitor response exceeded the configured limit") };
90
- } else return { retry: true, failure: failure("TRANSPORT", "Campaign Monitor request failed") };
1397
+ if (error instanceof BodyTooLargeError && error.status !== void 0)
1398
+ return { status: error.status, body: new Uint8Array(), retryAfterMs: providerRetryAfter(error.headers), error: "tooLarge" };
1399
+ if ((error instanceof ProviderTransportError || error instanceof ProviderStalledError) && error.status !== void 0)
1400
+ return { status: error.status, body: new Uint8Array(), retryAfterMs: providerRetryAfter(error.headers), error: "interrupted" };
1401
+ return empty("request");
91
1402
  }
92
- const status = response.status;
93
- const retryAfter = parseRetryAfter(headerValue(response.headers["retry-after"]));
94
- if (status === 429) return { retry: true, retryAfterMs: retryAfter, failure: failure("RATE_LIMIT", "Campaign Monitor rate limited the request") };
95
- if (status === 408 || status >= 500) return { retry: true, retryAfterMs: retryAfter, failure: failure("AVAILABILITY", "Campaign Monitor is temporarily unavailable") };
96
- if (status !== 200) return { branch: "providerRejected", failure: failure("PROVIDER_REJECTION", `Campaign Monitor rejected HTTP ${status}`) };
97
- if (response.body.length > this.maxResponseBytes) return { branch: "invalidResponse", failure: failure("RESPONSE_TOO_LARGE", "Campaign Monitor response exceeded the configured limit") };
98
- return { body: response.body };
99
1403
  }
100
1404
  };
101
1405
  var ListClientsOperation = class {
@@ -110,10 +1414,10 @@ var ListClientsOperation = class {
110
1414
  }
111
1415
  /** Read the account's accessible clients. */
112
1416
  async invoke(call, input) {
113
- if (!input || typeof input !== "object") return newQueryBranch("defect", emptyClients(), {}, failure("VALIDATION", "client list input is invalid"));
1417
+ if (!input || typeof input !== "object") return newQueryBranch2("defect", emptyClients(), {}, failure2("VALIDATION", "client list input is invalid"));
114
1418
  const result = await this.client.exchange(call);
115
- if (result.retry) return newQueryRetry(result.failure, result.retryAfterMs);
116
- if (result.failure) return newQueryBranch(result.branch, emptyClients(), {}, result.failure);
1419
+ if (result.retry) return newQueryRetry2(result.failure, result.retryAfterMs);
1420
+ if (result.failure) return newQueryBranch2(result.branch, emptyClients(), {}, result.failure);
117
1421
  const document = parseJSON(result.body);
118
1422
  if (!Array.isArray(document)) return invalid();
119
1423
  const clients = [];
@@ -121,14 +1425,14 @@ var ListClientsOperation = class {
121
1425
  if (!isObject(item) || typeof item.ClientID !== "string" || !item.ClientID || typeof item.Name !== "string" || !item.Name) return invalid();
122
1426
  clients.push({ id: item.ClientID, name: item.Name });
123
1427
  }
124
- return newQueryBranch("listed", { clients });
1428
+ return newQueryBranch2("listed", { clients });
125
1429
  }
126
1430
  };
127
- function failure(kind, message) {
1431
+ function failure2(kind, message) {
128
1432
  return { provider: "campaignmonitor", operation: "listClients", kind, message };
129
1433
  }
130
1434
  function invalid() {
131
- return newQueryBranch("invalidResponse", emptyClients(), {}, failure("PROTOCOL", "Campaign Monitor returned invalid JSON"));
1435
+ return newQueryBranch2("invalidResponse", emptyClients(), {}, failure2("PROTOCOL", "Campaign Monitor returned invalid JSON"));
132
1436
  }
133
1437
  function isObject(value) {
134
1438
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -143,6 +1447,10 @@ function parseJSON(body) {
143
1447
  function headerValue(value) {
144
1448
  return Array.isArray(value) ? value[0] ?? "" : value ?? "";
145
1449
  }
1450
+ function providerRetryAfter(headers = {}) {
1451
+ const value = Object.entries(headers).find(([name]) => name.toLowerCase() === "retry-after")?.[1];
1452
+ return parseRetryAfter(headerValue(value));
1453
+ }
146
1454
 
147
1455
  // src/project.ts
148
1456
  function newProjectConnection2(project, connectionName) {
@@ -180,12 +1488,129 @@ function parseDurationMilliseconds(value) {
180
1488
  return milliseconds;
181
1489
  }
182
1490
  export {
1491
+ CampaignIdentitySchema,
183
1492
  CampaignMonitorClient,
1493
+ CampaignProfileSchema,
1494
+ CampaignSummarySchema,
1495
+ CampaignsPageSchema,
184
1496
  ClientMetadataSchema,
185
1497
  ClientsListSchema,
186
1498
  ConfigSchema,
187
1499
  Connection,
188
1500
  ConnectorID,
1501
+ CreateDraftCampaignBranch,
1502
+ CreateDraftCampaignBranchCreated,
1503
+ CreateDraftCampaignBranchDefect,
1504
+ CreateDraftCampaignBranchProviderRejected,
1505
+ CreateDraftCampaignBranchUncertain,
1506
+ CreateDraftCampaignDefinition,
1507
+ CreateDraftCampaignInputSchema,
1508
+ CreateDraftCampaignMetadata,
1509
+ CreateDraftCampaignOperation,
1510
+ CreateListBranch,
1511
+ CreateListBranchCreated,
1512
+ CreateListBranchDefect,
1513
+ CreateListBranchProviderRejected,
1514
+ CreateListBranchUncertain,
1515
+ CreateListDefinition,
1516
+ CreateListInputSchema,
1517
+ CreateListMetadata,
1518
+ CreateListOperation,
1519
+ CreateSegmentBranch,
1520
+ CreateSegmentBranchCreated,
1521
+ CreateSegmentBranchDefect,
1522
+ CreateSegmentBranchProviderRejected,
1523
+ CreateSegmentBranchUncertain,
1524
+ CreateSegmentDefinition,
1525
+ CreateSegmentInputSchema,
1526
+ CreateSegmentMetadata,
1527
+ CreateSegmentOperation,
1528
+ CredentialMaterialError,
1529
+ DeleteCampaignBranch,
1530
+ DeleteCampaignBranchDefect,
1531
+ DeleteCampaignBranchDeleted,
1532
+ DeleteCampaignBranchInvalidResponse,
1533
+ DeleteCampaignBranchProviderRejected,
1534
+ DeleteCampaignDefinition,
1535
+ DeleteCampaignInputSchema,
1536
+ DeleteCampaignMetadata,
1537
+ DeleteCampaignOperation,
1538
+ DeleteListBranch,
1539
+ DeleteListBranchDefect,
1540
+ DeleteListBranchDeleted,
1541
+ DeleteListBranchInvalidResponse,
1542
+ DeleteListBranchProviderRejected,
1543
+ DeleteListDefinition,
1544
+ DeleteListInputSchema,
1545
+ DeleteListMetadata,
1546
+ DeleteListOperation,
1547
+ DeleteSegmentBranch,
1548
+ DeleteSegmentBranchDefect,
1549
+ DeleteSegmentBranchDeleted,
1550
+ DeleteSegmentBranchInvalidResponse,
1551
+ DeleteSegmentBranchProviderRejected,
1552
+ DeleteSegmentDefinition,
1553
+ DeleteSegmentInputSchema,
1554
+ DeleteSegmentMetadata,
1555
+ DeleteSegmentOperation,
1556
+ DeleteSubscriberBranch,
1557
+ DeleteSubscriberBranchDefect,
1558
+ DeleteSubscriberBranchDeleted,
1559
+ DeleteSubscriberBranchInvalidResponse,
1560
+ DeleteSubscriberBranchProviderRejected,
1561
+ DeleteSubscriberDefinition,
1562
+ DeleteSubscriberInputSchema,
1563
+ DeleteSubscriberMetadata,
1564
+ DeleteSubscriberOperation,
1565
+ GetCampaignSummaryBranch,
1566
+ GetCampaignSummaryBranchDefect,
1567
+ GetCampaignSummaryBranchFound,
1568
+ GetCampaignSummaryBranchInvalidResponse,
1569
+ GetCampaignSummaryBranchNotFound,
1570
+ GetCampaignSummaryBranchProviderRejected,
1571
+ GetCampaignSummaryDefinition,
1572
+ GetCampaignSummaryInputSchema,
1573
+ GetCampaignSummaryMetadata,
1574
+ GetCampaignSummaryOperation,
1575
+ GetListBranch,
1576
+ GetListBranchDefect,
1577
+ GetListBranchFound,
1578
+ GetListBranchInvalidResponse,
1579
+ GetListBranchNotFound,
1580
+ GetListBranchProviderRejected,
1581
+ GetListDefinition,
1582
+ GetListInputSchema,
1583
+ GetListMetadata,
1584
+ GetListOperation,
1585
+ GetSegmentBranch,
1586
+ GetSegmentBranchDefect,
1587
+ GetSegmentBranchFound,
1588
+ GetSegmentBranchInvalidResponse,
1589
+ GetSegmentBranchNotFound,
1590
+ GetSegmentBranchProviderRejected,
1591
+ GetSegmentDefinition,
1592
+ GetSegmentInputSchema,
1593
+ GetSegmentMetadata,
1594
+ GetSegmentOperation,
1595
+ GetSubscriberBranch,
1596
+ GetSubscriberBranchDefect,
1597
+ GetSubscriberBranchFound,
1598
+ GetSubscriberBranchInvalidResponse,
1599
+ GetSubscriberBranchNotFound,
1600
+ GetSubscriberBranchProviderRejected,
1601
+ GetSubscriberDefinition,
1602
+ GetSubscriberInputSchema,
1603
+ GetSubscriberMetadata,
1604
+ GetSubscriberOperation,
1605
+ ListCampaignsBranch,
1606
+ ListCampaignsBranchDefect,
1607
+ ListCampaignsBranchInvalidResponse,
1608
+ ListCampaignsBranchListed,
1609
+ ListCampaignsBranchProviderRejected,
1610
+ ListCampaignsDefinition,
1611
+ ListCampaignsInputSchema,
1612
+ ListCampaignsMetadata,
1613
+ ListCampaignsOperation,
189
1614
  ListClientsBranch,
190
1615
  ListClientsBranchDefect,
191
1616
  ListClientsBranchInvalidResponse,
@@ -195,10 +1620,152 @@ export {
195
1620
  ListClientsInputSchema,
196
1621
  ListClientsMetadata,
197
1622
  ListClientsOperation,
1623
+ ListIdentitySchema,
1624
+ ListProfileSchema,
1625
+ ListSegmentsBranch,
1626
+ ListSegmentsBranchDefect,
1627
+ ListSegmentsBranchInvalidResponse,
1628
+ ListSegmentsBranchListed,
1629
+ ListSegmentsBranchProviderRejected,
1630
+ ListSegmentsDefinition,
1631
+ ListSegmentsInputSchema,
1632
+ ListSegmentsMetadata,
1633
+ ListSegmentsOperation,
1634
+ ListSubscriberListsBranch,
1635
+ ListSubscriberListsBranchDefect,
1636
+ ListSubscriberListsBranchInvalidResponse,
1637
+ ListSubscriberListsBranchListed,
1638
+ ListSubscriberListsBranchProviderRejected,
1639
+ ListSubscriberListsDefinition,
1640
+ ListSubscriberListsInputSchema,
1641
+ ListSubscriberListsMetadata,
1642
+ ListSubscriberListsOperation,
1643
+ ListSubscribersBranch,
1644
+ ListSubscribersBranchDefect,
1645
+ ListSubscribersBranchInvalidResponse,
1646
+ ListSubscribersBranchListed,
1647
+ ListSubscribersBranchProviderRejected,
1648
+ ListSubscribersDefinition,
1649
+ ListSubscribersInputSchema,
1650
+ ListSubscribersMetadata,
1651
+ ListSubscribersOperation,
198
1652
  ProviderID,
1653
+ SegmentIdentitySchema,
1654
+ SegmentProfileSchema,
1655
+ SegmentRuleGroupSchema,
1656
+ SegmentRuleSchema,
1657
+ SegmentsListSchema,
1658
+ SendCampaignBranch,
1659
+ SendCampaignBranchDefect,
1660
+ SendCampaignBranchProviderRejected,
1661
+ SendCampaignBranchSent,
1662
+ SendCampaignBranchUncertain,
1663
+ SendCampaignDefinition,
1664
+ SendCampaignInputSchema,
1665
+ SendCampaignMetadata,
1666
+ SendCampaignOperation,
1667
+ SendCampaignPreviewBranch,
1668
+ SendCampaignPreviewBranchDefect,
1669
+ SendCampaignPreviewBranchProviderRejected,
1670
+ SendCampaignPreviewBranchSent,
1671
+ SendCampaignPreviewBranchUncertain,
1672
+ SendCampaignPreviewDefinition,
1673
+ SendCampaignPreviewInputSchema,
1674
+ SendCampaignPreviewMetadata,
1675
+ SendCampaignPreviewOperation,
1676
+ SubscriberIdentitySchema,
1677
+ SubscriberListIdentitySchema,
1678
+ SubscriberListsSchema,
1679
+ SubscriberProfileSchema,
1680
+ SubscribersPageSchema,
1681
+ UnscheduleCampaignBranch,
1682
+ UnscheduleCampaignBranchDefect,
1683
+ UnscheduleCampaignBranchInvalidResponse,
1684
+ UnscheduleCampaignBranchProviderRejected,
1685
+ UnscheduleCampaignBranchUnscheduled,
1686
+ UnscheduleCampaignDefinition,
1687
+ UnscheduleCampaignInputSchema,
1688
+ UnscheduleCampaignMetadata,
1689
+ UnscheduleCampaignOperation,
1690
+ UnsubscribeSubscriberBranch,
1691
+ UnsubscribeSubscriberBranchDefect,
1692
+ UnsubscribeSubscriberBranchInvalidResponse,
1693
+ UnsubscribeSubscriberBranchProviderRejected,
1694
+ UnsubscribeSubscriberBranchUnsubscribed,
1695
+ UnsubscribeSubscriberDefinition,
1696
+ UnsubscribeSubscriberInputSchema,
1697
+ UnsubscribeSubscriberMetadata,
1698
+ UnsubscribeSubscriberOperation,
1699
+ UpdateListBranch,
1700
+ UpdateListBranchDefect,
1701
+ UpdateListBranchInvalidResponse,
1702
+ UpdateListBranchNotFound,
1703
+ UpdateListBranchProviderRejected,
1704
+ UpdateListBranchUpdated,
1705
+ UpdateListDefinition,
1706
+ UpdateListInputSchema,
1707
+ UpdateListMetadata,
1708
+ UpdateListOperation,
1709
+ UpdateSegmentBranch,
1710
+ UpdateSegmentBranchDefect,
1711
+ UpdateSegmentBranchInvalidResponse,
1712
+ UpdateSegmentBranchNotFound,
1713
+ UpdateSegmentBranchProviderRejected,
1714
+ UpdateSegmentBranchUpdated,
1715
+ UpdateSegmentDefinition,
1716
+ UpdateSegmentInputSchema,
1717
+ UpdateSegmentMetadata,
1718
+ UpdateSegmentOperation,
1719
+ UpdateSubscriberBranch,
1720
+ UpdateSubscriberBranchDefect,
1721
+ UpdateSubscriberBranchInvalidResponse,
1722
+ UpdateSubscriberBranchNotFound,
1723
+ UpdateSubscriberBranchProviderRejected,
1724
+ UpdateSubscriberBranchUpdated,
1725
+ UpdateSubscriberDefinition,
1726
+ UpdateSubscriberInputSchema,
1727
+ UpdateSubscriberMetadata,
1728
+ UpdateSubscriberOperation,
1729
+ UpsertSubscriberBranch,
1730
+ UpsertSubscriberBranchDefect,
1731
+ UpsertSubscriberBranchInvalidResponse,
1732
+ UpsertSubscriberBranchProviderRejected,
1733
+ UpsertSubscriberBranchSaved,
1734
+ UpsertSubscriberDefinition,
1735
+ UpsertSubscriberInputSchema,
1736
+ UpsertSubscriberMetadata,
1737
+ UpsertSubscriberOperation,
199
1738
  decodeCredentials,
1739
+ decodeSignedInteger,
1740
+ exactIntegerJSONCodec,
1741
+ isCredentialMaterialError,
200
1742
  newConnection,
201
1743
  newConnectionWithOperations,
1744
+ newCreateDraftCampaignStep,
1745
+ newCreateListStep,
1746
+ newCreateSegmentStep,
1747
+ newDeleteCampaignStep,
1748
+ newDeleteListStep,
1749
+ newDeleteSegmentStep,
1750
+ newDeleteSubscriberStep,
1751
+ newGetCampaignSummaryStep,
1752
+ newGetListStep,
1753
+ newGetSegmentStep,
1754
+ newGetSubscriberStep,
1755
+ newListCampaignsStep,
202
1756
  newListClientsStep,
203
- newProjectConnection2 as newProjectConnection
1757
+ newListSegmentsStep,
1758
+ newListSubscriberListsStep,
1759
+ newListSubscribersStep,
1760
+ newProjectConnection2 as newProjectConnection,
1761
+ newSendCampaignPreviewStep,
1762
+ newSendCampaignStep,
1763
+ newUnscheduleCampaignStep,
1764
+ newUnsubscribeSubscriberStep,
1765
+ newUpdateListStep,
1766
+ newUpdateSegmentStep,
1767
+ newUpdateSubscriberStep,
1768
+ newUpsertSubscriberStep,
1769
+ parseExactIntegerJSON,
1770
+ parseJSONNumberTokens
204
1771
  };