@b-jones-rfd/qualtrics-api-tasks 0.1.1 → 0.3.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
@@ -21,10 +21,21 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
23
  createConnection: () => createConnection,
24
+ createDistribution: () => createDistribution,
25
+ createMailingList: () => createMailingList,
26
+ createReminder: () => createReminder,
27
+ distributeSurveys: () => distributeSurveys,
24
28
  exportResponses: () => exportResponses,
25
29
  getBearerToken: () => getBearerToken,
30
+ getContactsImportStatus: () => getContactsImportStatus,
31
+ getContactsImportSummary: () => getContactsImportSummary,
32
+ getDistribution: () => getDistribution,
26
33
  getResponseExportFile: () => getResponseExportFile,
27
34
  getResponseExportProgress: () => getResponseExportProgress,
35
+ importContacts: () => importContacts,
36
+ listDistributions: () => listDistributions,
37
+ listLibraryMessages: () => listLibraryMessages,
38
+ startContactsImport: () => startContactsImport,
28
39
  startResponseExport: () => startResponseExport,
29
40
  testConnection: () => testConnection
30
41
  });
@@ -61,6 +72,228 @@ function getAuthHeaders(apiToken, bearerToken) {
61
72
  );
62
73
  }
63
74
 
75
+ // src/utils/parsers.ts
76
+ function safeParseBearerToken(response) {
77
+ return response?.access_token && typeof response.access_token === "string" ? success(response.access_token) : failure("Incorrect token format");
78
+ }
79
+ function safeParseTestResponse(response) {
80
+ return response?.result?.userId ? success("Connection successful") : failure("Incorrect test response format");
81
+ }
82
+ function safeParseStartFileExportResponse(response) {
83
+ return "result" in response ? "progressId" in response.result && "percentComplete" in response.result && "status" in response.result ? success(response.result) : failure("Start Export Response invalid format") : "error" in response ? failure(`${response.error.errorCode}: ${response.error.errorMessage}`) : failure(`Unable to parse Start Export Response`);
84
+ }
85
+ function safeParseFileProgressResponse(response) {
86
+ return "result" in response ? "fileId" in response.result && "percentComplete" in response.result && "status" in response.result ? success(response.result) : failure("File Progress Response invalid format") : "error" in response ? failure(`${response.error.errorCode}: ${response.error.errorMessage}`) : failure(`Unable to parse File Progress Response`);
87
+ }
88
+ function safeParseCreateMailingListResponse(response) {
89
+ return "result" in response ? "id" in response.result ? success(response.result.id) : failure(`Id missing in Create Mailing List Response`) : failure(`Unable to parse Create Mailing List Response`);
90
+ }
91
+ function safeParseStartContactsImportResponse(response) {
92
+ return "result" in response ? "id" in response.result && "contacts" in response.result && "tracking" in response.result && "status" in response.result ? success(response.result) : failure("Start contacts import response invalid format") : failure(`Unable to parse Start Contacts Import Response`);
93
+ }
94
+ function safeParseContactsImportSummary(response) {
95
+ return "result" in response ? "percentComplete" in response.result && "contacts" in response.result && "invalidEmails" in response.result && "transactions" in response.result && "status" in response.result ? success(response.result) : failure("Contacts import summary response invalid format") : failure(`Unable to parse Contacts Import Summary Response`);
96
+ }
97
+ function safeParseContactsImportStatus(response) {
98
+ return "result" in response ? "percentComplete" in response.result && "contacts" in response.result && "transactions" in response.result && "status" in response.result ? success(response.result) : failure("Contacts import summary response invalid format") : failure(`Unable to parse Contacts Import Summary Response`);
99
+ }
100
+ function safeParseCreateDistributionResponse(response) {
101
+ return "result" in response ? "id" in response.result ? success(response.result.id) : failure(`Id missing in Create Distribution Response`) : failure(`Unable to parse Create Distribution Response`);
102
+ }
103
+ function safeParseCreateReminderResponse(response) {
104
+ return "result" in response ? "distributionId" in response.result ? success(response.result.distributionId) : failure(`distributionId missing in Create Reminder Response`) : failure(`Unable to parse Create Reminder Response`);
105
+ }
106
+ function safeParseListLibraryMessages(response) {
107
+ return "result" in response ? "elements" in response.result && Array.isArray(response.result.elements) ? success(response.result) : failure(`elements missing in List Library Messages response`) : failure(`Unable to parse List Library Messages response`);
108
+ }
109
+ function safeParseGetDistribution(response) {
110
+ return "result" in response ? "id" in response.result && "stats" in response.result ? success(response.result) : failure(`Properties missing in Get Distribution response`) : failure(`Unable to parse Get Distribution response`);
111
+ }
112
+ function safeParseListDistributions(response) {
113
+ return "result" in response ? "elements" in response.result ? success(response.result) : failure(`elements missing in List Distributions response`) : failure(`Unable to parse List Distribution response`);
114
+ }
115
+
116
+ // src/qualtrics/index.ts
117
+ async function execute(config) {
118
+ const { datacenterId, route, headers, timeout, body } = config;
119
+ const host = `https://${datacenterId}.qualtrics.com`;
120
+ const resource = new URL(route, host);
121
+ const controller = new AbortController();
122
+ const options = {
123
+ method: "GET",
124
+ headers,
125
+ signal: controller.signal
126
+ };
127
+ if (body) {
128
+ if (typeof body === "string") {
129
+ headers.append("Content-Type", "application/json");
130
+ }
131
+ options.method = "POST";
132
+ options.headers = headers;
133
+ options.body = body;
134
+ }
135
+ const timer = setTimeout(() => controller.abort(), timeout ?? 30 * 1e3);
136
+ const response = await fetch(resource, options);
137
+ clearTimeout(timer);
138
+ if (response.ok) {
139
+ const contentType = response.headers.get("content-type");
140
+ switch (contentType) {
141
+ case "application/json":
142
+ return Promise.resolve(await response.json());
143
+ case "application/csv":
144
+ case "application/tsv":
145
+ case "application/xml":
146
+ return Promise.resolve(await response.text());
147
+ default:
148
+ return Promise.resolve(response.body);
149
+ }
150
+ } else {
151
+ const message = await response.json();
152
+ return Promise.reject(`${response.status}: ${message}`);
153
+ }
154
+ }
155
+
156
+ // src/methods/distributions/createDistribution.ts
157
+ var createDistribution = (connectionOptions) => async ({
158
+ libraryId,
159
+ messageId,
160
+ messageText,
161
+ mailingListId,
162
+ contactId,
163
+ transactionBatchId,
164
+ fromEmail,
165
+ replyToEmail,
166
+ fromName,
167
+ subject,
168
+ surveyId,
169
+ expirationDate,
170
+ type,
171
+ embeddedData,
172
+ sendDate,
173
+ bearerToken = void 0
174
+ }) => {
175
+ const route = `/API/v3/distributions`;
176
+ try {
177
+ const headers = getAuthHeaders(connectionOptions.apiToken, bearerToken);
178
+ const body = JSON.stringify({
179
+ message: {
180
+ libraryId,
181
+ messageId,
182
+ messageText
183
+ },
184
+ recipients: {
185
+ mailingListId,
186
+ contactId,
187
+ transactionBatchId
188
+ },
189
+ header: {
190
+ fromEmail,
191
+ replyToEmail,
192
+ fromName,
193
+ subject
194
+ },
195
+ surveyLink: {
196
+ surveyId,
197
+ expirationDate,
198
+ type
199
+ },
200
+ embeddedData,
201
+ sendDate
202
+ });
203
+ const config = {
204
+ datacenterId: connectionOptions.datacenterId,
205
+ route,
206
+ headers,
207
+ body,
208
+ timeout: connectionOptions.timeout
209
+ };
210
+ const response = await execute(config);
211
+ const result = safeParseCreateDistributionResponse(response);
212
+ return result;
213
+ } catch (error) {
214
+ const message = getErrorMessage(error);
215
+ return failure(message);
216
+ }
217
+ };
218
+
219
+ // src/methods/createMailingList.ts
220
+ var createMailingList = (connectionOptions) => async ({
221
+ directoryId,
222
+ name,
223
+ ownerId,
224
+ prioritizeListMetadata = false,
225
+ bearerToken = void 0
226
+ }) => {
227
+ const route = `/API/v3/directories/${directoryId}/mailinglists`;
228
+ try {
229
+ const headers = getAuthHeaders(connectionOptions.apiToken, bearerToken);
230
+ const body = JSON.stringify({
231
+ name,
232
+ ownerId,
233
+ prioritizeListMetadata
234
+ });
235
+ const config = {
236
+ datacenterId: connectionOptions.datacenterId,
237
+ route,
238
+ headers,
239
+ body,
240
+ timeout: connectionOptions.timeout
241
+ };
242
+ const response = await execute(config);
243
+ const result = safeParseCreateMailingListResponse(response);
244
+ return result;
245
+ } catch (error) {
246
+ const message = getErrorMessage(error);
247
+ return failure(message);
248
+ }
249
+ };
250
+
251
+ // src/methods/distributions/createReminder.ts
252
+ var createReminder = (connectionOptions) => async ({
253
+ distributionId,
254
+ libraryId,
255
+ messageId,
256
+ fromEmail,
257
+ replyToEmail,
258
+ fromName,
259
+ subject,
260
+ embeddedData,
261
+ sendDate,
262
+ bearerToken = void 0
263
+ }) => {
264
+ const route = `/API/v3/distributions/${distributionId}/reminders`;
265
+ try {
266
+ const headers = getAuthHeaders(connectionOptions.apiToken, bearerToken);
267
+ const body = JSON.stringify({
268
+ message: {
269
+ libraryId,
270
+ messageId
271
+ },
272
+ header: {
273
+ fromEmail,
274
+ replyToEmail,
275
+ fromName,
276
+ subject
277
+ },
278
+ embeddedData,
279
+ sendDate
280
+ });
281
+ const config = {
282
+ datacenterId: connectionOptions.datacenterId,
283
+ route,
284
+ headers,
285
+ body,
286
+ timeout: connectionOptions.timeout
287
+ };
288
+ const response = await execute(config);
289
+ const result = safeParseCreateReminderResponse(response);
290
+ return result;
291
+ } catch (error) {
292
+ const message = getErrorMessage(error);
293
+ return failure(message);
294
+ }
295
+ };
296
+
64
297
  // src/utils/poll.ts
65
298
  async function poll({
66
299
  fn,
@@ -87,7 +320,250 @@ async function poll({
87
320
  return new Promise(executePoll);
88
321
  }
89
322
 
90
- // src/methods/exportResponses.ts
323
+ // src/methods/contacts/startContactsImport.ts
324
+ var startContactsImport = (connectionOptions) => async (options) => {
325
+ const { directoryId, mailingListId, contacts, transactionMeta, bearerToken } = options;
326
+ const route = `/API/v3
327
+ /directories/${directoryId}/mailinglists/${mailingListId}/transactioncontacts`;
328
+ try {
329
+ const headers = getAuthHeaders(connectionOptions.apiToken, bearerToken);
330
+ const body = JSON.stringify({
331
+ transactionMeta,
332
+ contacts
333
+ });
334
+ const config = {
335
+ datacenterId: connectionOptions.datacenterId,
336
+ route,
337
+ headers,
338
+ body,
339
+ timeout: connectionOptions.timeout
340
+ };
341
+ const response = await execute(config);
342
+ const result = safeParseStartContactsImportResponse(response);
343
+ return result;
344
+ } catch (error) {
345
+ const message = getErrorMessage(error);
346
+ return failure(message);
347
+ }
348
+ };
349
+
350
+ // src/methods/contacts/getContactsImportStatus.ts
351
+ var getContactsImportStatus = (connectionOptions) => async ({ directoryId, importId, mailingListId, bearerToken = void 0 }) => {
352
+ const route = `/API/v3
353
+ /directories/${directoryId}/mailinglists/${mailingListId}/transactioncontacts/${importId}`;
354
+ try {
355
+ const headers = getAuthHeaders(connectionOptions.apiToken, bearerToken);
356
+ const config = {
357
+ datacenterId: connectionOptions.datacenterId,
358
+ route,
359
+ headers,
360
+ timeout: connectionOptions.timeout
361
+ };
362
+ const response = await execute(config);
363
+ const result = safeParseContactsImportStatus(response);
364
+ return result;
365
+ } catch (error) {
366
+ const message = getErrorMessage(error);
367
+ return failure(message);
368
+ }
369
+ };
370
+
371
+ // src/methods/contacts/getContactsImportSummary.ts
372
+ var getContactsImportSummary = (connectionOptions) => async ({ directoryId, importId, mailingListId, bearerToken = void 0 }) => {
373
+ const route = `/API/v3
374
+ /directories/${directoryId}/mailinglists/${mailingListId}/transactioncontacts/${importId}/summary`;
375
+ try {
376
+ const headers = getAuthHeaders(connectionOptions.apiToken, bearerToken);
377
+ const config = {
378
+ datacenterId: connectionOptions.datacenterId,
379
+ route,
380
+ headers,
381
+ timeout: connectionOptions.timeout
382
+ };
383
+ const response = await execute(config);
384
+ const result = safeParseContactsImportSummary(response);
385
+ return result;
386
+ } catch (error) {
387
+ const message = getErrorMessage(error);
388
+ return failure(message);
389
+ }
390
+ };
391
+
392
+ // src/methods/contacts/importContacts.ts
393
+ var importContacts = (connectionOptions) => async (importOptions) => {
394
+ try {
395
+ const startImportAction = startContactsImport(connectionOptions);
396
+ const startResponse = await startImportAction(importOptions);
397
+ if (!startResponse.success)
398
+ return failure(startResponse.error);
399
+ const importProgressAction = getContactsImportStatus(connectionOptions);
400
+ const progressResponse = await poll({
401
+ fn: async () => await importProgressAction({
402
+ directoryId: importOptions.directoryId,
403
+ importId: startResponse.data.id,
404
+ mailingListId: importOptions.mailingListId,
405
+ bearerToken: importOptions.bearerToken
406
+ }),
407
+ validate: (res) => res.success && res.data.percentComplete === 100,
408
+ interval: 1,
409
+ maxAttempts: 60
410
+ });
411
+ if (!progressResponse.success)
412
+ return failure(progressResponse.error);
413
+ const getContactImportSummaryAction = getContactsImportSummary(connectionOptions);
414
+ const fileResponse = await getContactImportSummaryAction({
415
+ directoryId: importOptions.directoryId,
416
+ importId: startResponse.data.id,
417
+ mailingListId: importOptions.mailingListId,
418
+ bearerToken: importOptions.bearerToken
419
+ });
420
+ return fileResponse;
421
+ } catch (error) {
422
+ const message = getErrorMessage(error);
423
+ return failure(message);
424
+ }
425
+ };
426
+
427
+ // src/methods/distributions/distributeSurveys.ts
428
+ var distributeSurveys = (connectionOptions) => async (options) => {
429
+ try {
430
+ const createMailingListAction = createMailingList(connectionOptions);
431
+ const startResponse = await createMailingListAction({
432
+ directoryId: options.directoryId,
433
+ name: options.mailingListName,
434
+ ownerId: options.ownerId,
435
+ prioritizeListMetadata: options.prioritizeListMetadata,
436
+ bearerToken: options.bearerToken
437
+ });
438
+ if (!startResponse.success)
439
+ return failure(startResponse.error);
440
+ const importContactsAction = importContacts(connectionOptions);
441
+ const importResponse = await importContactsAction({
442
+ directoryId: options.directoryId,
443
+ mailingListId: startResponse.data,
444
+ contacts: options.contacts,
445
+ transactionMeta: options.transactionMeta,
446
+ bearerToken: options.bearerToken
447
+ });
448
+ if (!importResponse.success)
449
+ return failure(importResponse.error);
450
+ const createDistributionAction = createDistribution(connectionOptions);
451
+ const distributionResponse = await createDistributionAction({
452
+ libraryId: options.libraryId,
453
+ messageId: options.distributionMessageId,
454
+ messageText: options.distributionMessageText,
455
+ mailingListId: startResponse.data,
456
+ fromEmail: options.fromEmail,
457
+ fromName: options.fromName,
458
+ replyToEmail: options.replyToEmail,
459
+ subject: options.subject,
460
+ surveyId: options.surveyId,
461
+ expirationDate: options.expirationDate,
462
+ type: options.type,
463
+ embeddedData: options.embeddedData,
464
+ sendDate: options.sendDate,
465
+ bearerToken: options.bearerToken
466
+ });
467
+ if (!distributionResponse.success)
468
+ return failure(distributionResponse.error);
469
+ const createReminderAction = createReminder(connectionOptions);
470
+ const reminderResponse = await createReminderAction({
471
+ distributionId: distributionResponse.data,
472
+ libraryId: options.libraryId,
473
+ messageId: options.reminderMessageId,
474
+ fromEmail: options.fromEmail,
475
+ fromName: options.fromName,
476
+ replyToEmail: options.replyToEmail,
477
+ subject: options.subject,
478
+ embeddedData: options.embeddedData,
479
+ sendDate: options.sendDate,
480
+ bearerToken: options.bearerToken
481
+ });
482
+ if (!reminderResponse.success)
483
+ return failure(reminderResponse.error);
484
+ return success(reminderResponse.data);
485
+ } catch (error) {
486
+ const message = getErrorMessage(error);
487
+ return failure(message);
488
+ }
489
+ };
490
+
491
+ // src/methods/responses/startResponseExport.ts
492
+ var startResponseExport = (connectionOptions) => async ({
493
+ surveyId,
494
+ startDate,
495
+ endDate,
496
+ format = "csv",
497
+ bearerToken = void 0,
498
+ ...rest
499
+ }) => {
500
+ const route = `/API/v3/surveys/${surveyId}/export-responses`;
501
+ try {
502
+ const headers = getAuthHeaders(connectionOptions.apiToken, bearerToken);
503
+ const body = JSON.stringify({
504
+ startDate: "2024-03-01T06:00:00Z",
505
+ //startDate.toISOString(),
506
+ endDate: "2024-03-05T06:00:00Z",
507
+ //endDate.toISOString(),
508
+ format,
509
+ ...rest
510
+ });
511
+ const config = {
512
+ datacenterId: connectionOptions.datacenterId,
513
+ route,
514
+ headers,
515
+ body,
516
+ timeout: connectionOptions.timeout
517
+ };
518
+ const response = await execute(config);
519
+ const result = safeParseStartFileExportResponse(response);
520
+ return result;
521
+ } catch (error) {
522
+ const message = getErrorMessage(error);
523
+ return failure(message);
524
+ }
525
+ };
526
+
527
+ // src/methods/responses/getResponseExportFile.ts
528
+ var getResponseExportFile = (connectionOptions) => async ({ surveyId, fileId, bearerToken }) => {
529
+ const route = `/API/v3/surveys/${surveyId}/export-responses/${fileId}/file`;
530
+ try {
531
+ const headers = getAuthHeaders(connectionOptions.apiToken, bearerToken);
532
+ const config = {
533
+ datacenterId: connectionOptions.datacenterId,
534
+ route,
535
+ headers,
536
+ timeout: connectionOptions.timeout
537
+ };
538
+ const response = await execute(config);
539
+ return response;
540
+ } catch (error) {
541
+ const message = getErrorMessage(error);
542
+ return failure(message);
543
+ }
544
+ };
545
+
546
+ // src/methods/responses/getResponseExportProgress.ts
547
+ var getResponseExportProgress = (connectionOptions) => async ({ exportProgressId, surveyId, bearerToken }) => {
548
+ const route = `/API/v3/surveys/${surveyId}/export-responses/${exportProgressId}`;
549
+ try {
550
+ const headers = getAuthHeaders(connectionOptions.apiToken, bearerToken);
551
+ const config = {
552
+ datacenterId: connectionOptions.datacenterId,
553
+ route,
554
+ headers,
555
+ timeout: connectionOptions.timeout
556
+ };
557
+ const response = await execute(config);
558
+ const result = safeParseFileProgressResponse(response);
559
+ return result;
560
+ } catch (error) {
561
+ const message = getErrorMessage(error);
562
+ return failure(message);
563
+ }
564
+ };
565
+
566
+ // src/methods/responses/exportResponses.ts
91
567
  var exportResponses = (connectionOptions) => async (responseOptions) => {
92
568
  try {
93
569
  const startResponseAction = startResponseExport(connectionOptions);
@@ -120,55 +596,6 @@ var exportResponses = (connectionOptions) => async (responseOptions) => {
120
596
  }
121
597
  };
122
598
 
123
- // src/utils/parsers.ts
124
- function safeParseBearerToken(response) {
125
- return response?.access_token && typeof response.access_token === "string" ? success(response.access_token) : failure("Incorrect token format");
126
- }
127
- function safeParseTestResponse(response) {
128
- return response?.result?.userId ? success("Connection successful") : failure("Incorrect test response format");
129
- }
130
- function safeParseStartFileExportResponse(response) {
131
- return "result" in response ? "progressId" in response.result && "percentComplete" in response.result && "status" in response.result ? success(response.result) : failure("Start Export Response invalid format") : "error" in response ? failure(`${response.error.errorCode}: ${response.error.errorMessage}`) : failure(`Unable to parse Start Export Response`);
132
- }
133
- function safeParseFileProgressResponse(response) {
134
- return "result" in response ? "fileId" in response.result && "percentComplete" in response.result && "status" in response.result ? success(response.result) : failure("File Progress Response invalid format") : "error" in response ? failure(`${response.error.errorCode}: ${response.error.errorMessage}`) : failure(`Unable to parse File Progress Response`);
135
- }
136
- function safeParseFileResponse(response) {
137
- return Buffer.isBuffer(response) ? success(response) : failure("Incorrect file response format");
138
- }
139
-
140
- // src/qualtrics/index.ts
141
- async function execute(config) {
142
- const { datacenterId, route, headers, timeout, body } = config;
143
- const host = `https://${datacenterId}.qualtrics.com`;
144
- const resource = new URL(route, host);
145
- const controller = new AbortController();
146
- const options = {
147
- method: "GET",
148
- headers,
149
- signal: controller.signal
150
- };
151
- if (body) {
152
- if (typeof body === "string") {
153
- headers.append("Content-Type", "application/json");
154
- headers.append("Accept", "application/json");
155
- }
156
- options.method = "POST";
157
- options.headers = headers;
158
- options.body = body;
159
- }
160
- const timer = setTimeout(() => controller.abort(), timeout ?? 30 * 1e3);
161
- const response = await fetch(resource, options);
162
- clearTimeout(timer);
163
- if (response.ok) {
164
- const data = await response.json();
165
- return Promise.resolve(data);
166
- } else {
167
- const message = await response.json();
168
- return Promise.reject(`${response.status}: ${message}`);
169
- }
170
- }
171
-
172
599
  // src/methods/getBearerToken.ts
173
600
  var getBearerToken = (connectionOptions) => async ({ clientId, clientSecret, scope }) => {
174
601
  const route = `/oauth2/token`;
@@ -195,11 +622,12 @@ var getBearerToken = (connectionOptions) => async ({ clientId, clientSecret, sco
195
622
  }
196
623
  };
197
624
 
198
- // src/methods/getResponseExportProgress.ts
199
- var getResponseExportProgress = (connectionOptions) => async ({ exportProgressId, surveyId, bearerToken }) => {
200
- const route = `/surveys/${surveyId}/export-responses/${exportProgressId}`;
625
+ // src/methods/distributions/getDistribution.ts
626
+ var getDistribution = (connectionOptions) => async ({ distributionId, surveyId, bearerToken = void 0 }) => {
201
627
  try {
202
628
  const headers = getAuthHeaders(connectionOptions.apiToken, bearerToken);
629
+ const qs = new URLSearchParams({ surveyId });
630
+ const route = `/API/v3/distributions/${distributionId}?${qs.toString()}`;
203
631
  const config = {
204
632
  datacenterId: connectionOptions.datacenterId,
205
633
  route,
@@ -207,7 +635,7 @@ var getResponseExportProgress = (connectionOptions) => async ({ exportProgressId
207
635
  timeout: connectionOptions.timeout
208
636
  };
209
637
  const response = await execute(config);
210
- const result = safeParseFileProgressResponse(response);
638
+ const result = safeParseGetDistribution(response);
211
639
  return result;
212
640
  } catch (error) {
213
641
  const message = getErrorMessage(error);
@@ -215,11 +643,34 @@ var getResponseExportProgress = (connectionOptions) => async ({ exportProgressId
215
643
  }
216
644
  };
217
645
 
218
- // src/methods/getResponseExportFile.ts
219
- var getResponseExportFile = (connectionOptions) => async ({ surveyId, fileId, bearerToken }) => {
220
- const route = `/surveys/${surveyId}/export-responses/${fileId}/file`;
646
+ // src/methods/distributions/listDistributions.ts
647
+ var listDistributions = (connectionOptions) => async ({
648
+ surveyId,
649
+ distributionRequestType,
650
+ mailingListId,
651
+ sendStartDate,
652
+ sendEndDate,
653
+ skipToken,
654
+ useNewPaginationScheme,
655
+ pageSize,
656
+ bearerToken = void 0
657
+ }) => {
221
658
  try {
222
659
  const headers = getAuthHeaders(connectionOptions.apiToken, bearerToken);
660
+ const qs = new URLSearchParams({
661
+ surveyId,
662
+ distributionRequestType,
663
+ mailingListId,
664
+ sendStartDate: sendStartDate.toISOString(),
665
+ sendEndDate: sendEndDate.toISOString()
666
+ });
667
+ if (skipToken)
668
+ qs.append("skipToken", skipToken);
669
+ if (useNewPaginationScheme)
670
+ qs.append("useNewPaginationScheme", useNewPaginationScheme.toString());
671
+ if (pageSize)
672
+ qs.append("pageSize", pageSize.toString());
673
+ const route = `/API/v3/distributions?${qs.toString()}`;
223
674
  const config = {
224
675
  datacenterId: connectionOptions.datacenterId,
225
676
  route,
@@ -227,7 +678,7 @@ var getResponseExportFile = (connectionOptions) => async ({ surveyId, fileId, be
227
678
  timeout: connectionOptions.timeout
228
679
  };
229
680
  const response = await execute(config);
230
- const result = safeParseFileResponse(response);
681
+ const result = safeParseListDistributions(response);
231
682
  return result;
232
683
  } catch (error) {
233
684
  const message = getErrorMessage(error);
@@ -235,35 +686,24 @@ var getResponseExportFile = (connectionOptions) => async ({ surveyId, fileId, be
235
686
  }
236
687
  };
237
688
 
238
- // src/methods/startResponseExport.ts
239
- var startResponseExport = (connectionOptions) => async ({
240
- surveyId,
241
- startDate,
242
- endDate,
243
- format = "csv",
244
- bearerToken = void 0,
245
- ...rest
246
- }) => {
247
- const route = `/surveys/${surveyId}/export-responses`;
689
+ // src/methods/listLibraryMessages.ts
690
+ var listLibraryMessages = (connectionOptions) => async ({ libraryId, category, offset, bearerToken = void 0 }) => {
691
+ const route = `/API/v3/libraries/${libraryId}/messages`;
248
692
  try {
249
693
  const headers = getAuthHeaders(connectionOptions.apiToken, bearerToken);
250
- const body = JSON.stringify({
251
- startDate: "2024-03-01T06:00:00Z",
252
- //startDate.toISOString(),
253
- endDate: "2024-03-05T06:00:00Z",
254
- //endDate.toISOString(),
255
- format,
256
- ...rest
257
- });
694
+ const qs = new URLSearchParams();
695
+ if (category)
696
+ qs.append("category", category);
697
+ if (offset)
698
+ qs.append("offset", offset.toString());
258
699
  const config = {
259
700
  datacenterId: connectionOptions.datacenterId,
260
- route,
701
+ route: qs.size > 0 ? route + "?" + qs.toString() : route,
261
702
  headers,
262
- body,
263
703
  timeout: connectionOptions.timeout
264
704
  };
265
705
  const response = await execute(config);
266
- const result = safeParseStartFileExportResponse(response);
706
+ const result = safeParseListLibraryMessages(response);
267
707
  return result;
268
708
  } catch (error) {
269
709
  const message = getErrorMessage(error);
@@ -293,20 +733,42 @@ var testConnection = (connectionOptions) => async (bearerToken) => {
293
733
 
294
734
  // src/createConnection.ts
295
735
  var createConnection = (options) => ({
736
+ createDistribution: createDistribution(options),
737
+ createMailingList: createMailingList(options),
738
+ createReminder: createReminder(options),
739
+ distributeSurveys: distributeSurveys(options),
296
740
  exportResponses: exportResponses(options),
297
741
  getBearerToken: getBearerToken(options),
742
+ getContactsImportStatus: getContactsImportStatus(options),
743
+ getContactsImportSummary: getContactsImportSummary(options),
744
+ getDistribution: getDistribution(options),
298
745
  getResponseExportFile: getResponseExportFile(options),
299
746
  getResponseExportProgress: getResponseExportProgress(options),
747
+ importContacts: importContacts(options),
748
+ listDistributions: listDistributions(options),
749
+ listLibraryMessages: listLibraryMessages(options),
750
+ startContactsImport: startContactsImport(options),
300
751
  startResponseExport: startResponseExport(options),
301
752
  testConnection: testConnection(options)
302
753
  });
303
754
  // Annotate the CommonJS export names for ESM import in node:
304
755
  0 && (module.exports = {
305
756
  createConnection,
757
+ createDistribution,
758
+ createMailingList,
759
+ createReminder,
760
+ distributeSurveys,
306
761
  exportResponses,
307
762
  getBearerToken,
763
+ getContactsImportStatus,
764
+ getContactsImportSummary,
765
+ getDistribution,
308
766
  getResponseExportFile,
309
767
  getResponseExportProgress,
768
+ importContacts,
769
+ listDistributions,
770
+ listLibraryMessages,
771
+ startContactsImport,
310
772
  startResponseExport,
311
773
  testConnection
312
774
  });