@b-jones-rfd/qualtrics-api-tasks 0.2.0 → 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.mjs CHANGED
@@ -29,65 +29,6 @@ function getAuthHeaders(apiToken, bearerToken) {
29
29
  );
30
30
  }
31
31
 
32
- // src/utils/poll.ts
33
- async function poll({
34
- fn,
35
- validate,
36
- interval,
37
- maxAttempts
38
- }) {
39
- let attempts = 0;
40
- const executePoll = async (resolve, reject) => {
41
- try {
42
- const result = await fn();
43
- attempts++;
44
- if (validate(result)) {
45
- return resolve(result);
46
- } else if (maxAttempts && attempts === maxAttempts) {
47
- return reject(new Error("Exceeded max attempts"));
48
- } else {
49
- setTimeout(executePoll, interval, resolve, reject);
50
- }
51
- } catch (error) {
52
- reject(new Error(`Poll function execution failed: ${error}`));
53
- }
54
- };
55
- return new Promise(executePoll);
56
- }
57
-
58
- // src/methods/exportResponses.ts
59
- var exportResponses = (connectionOptions) => async (responseOptions) => {
60
- try {
61
- const startResponseAction = startResponseExport(connectionOptions);
62
- const startResponse = await startResponseAction(responseOptions);
63
- if (!startResponse.success)
64
- return failure(startResponse.error);
65
- const exportProgressAction = getResponseExportProgress(connectionOptions);
66
- const progressResponse = await poll({
67
- fn: async () => await exportProgressAction({
68
- exportProgressId: startResponse.data.progressId,
69
- surveyId: responseOptions.surveyId,
70
- bearerToken: responseOptions.bearerToken
71
- }),
72
- validate: (res) => res.success && res.data.percentComplete === 100,
73
- interval: 1,
74
- maxAttempts: 60
75
- });
76
- if (!progressResponse.success)
77
- return failure(progressResponse.error);
78
- const getFileResponseAction = getResponseExportFile(connectionOptions);
79
- const fileResponse = await getFileResponseAction({
80
- surveyId: responseOptions.surveyId,
81
- fileId: progressResponse.data.fileId,
82
- bearerToken: responseOptions.bearerToken
83
- });
84
- return fileResponse;
85
- } catch (error) {
86
- const message = getErrorMessage(error);
87
- return failure(message);
88
- }
89
- };
90
-
91
32
  // src/utils/parsers.ts
92
33
  function safeParseBearerToken(response) {
93
34
  return response?.access_token && typeof response.access_token === "string" ? success(response.access_token) : failure("Incorrect token format");
@@ -101,6 +42,33 @@ function safeParseStartFileExportResponse(response) {
101
42
  function safeParseFileProgressResponse(response) {
102
43
  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`);
103
44
  }
45
+ function safeParseCreateMailingListResponse(response) {
46
+ 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`);
47
+ }
48
+ function safeParseStartContactsImportResponse(response) {
49
+ 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`);
50
+ }
51
+ function safeParseContactsImportSummary(response) {
52
+ 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`);
53
+ }
54
+ function safeParseContactsImportStatus(response) {
55
+ 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`);
56
+ }
57
+ function safeParseCreateDistributionResponse(response) {
58
+ 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`);
59
+ }
60
+ function safeParseCreateReminderResponse(response) {
61
+ 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`);
62
+ }
63
+ function safeParseListLibraryMessages(response) {
64
+ 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`);
65
+ }
66
+ function safeParseGetDistribution(response) {
67
+ 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`);
68
+ }
69
+ function safeParseListDistributions(response) {
70
+ 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`);
71
+ }
104
72
 
105
73
  // src/qualtrics/index.ts
106
74
  async function execute(config) {
@@ -142,25 +110,94 @@ async function execute(config) {
142
110
  }
143
111
  }
144
112
 
145
- // src/methods/getBearerToken.ts
146
- var getBearerToken = (connectionOptions) => async ({ clientId, clientSecret, scope }) => {
147
- const route = `/oauth2/token`;
113
+ // src/methods/distributions/createDistribution.ts
114
+ var createDistribution = (connectionOptions) => async ({
115
+ libraryId,
116
+ messageId,
117
+ messageText,
118
+ mailingListId,
119
+ contactId,
120
+ transactionBatchId,
121
+ fromEmail,
122
+ replyToEmail,
123
+ fromName,
124
+ subject,
125
+ surveyId,
126
+ expirationDate,
127
+ type,
128
+ embeddedData,
129
+ sendDate,
130
+ bearerToken = void 0
131
+ }) => {
132
+ const route = `/API/v3/distributions`;
148
133
  try {
149
- const { datacenterId, timeout } = connectionOptions;
150
- const headers = new Headers({
151
- Authorization: "Basic " + Buffer.from(`${clientId}:${clientSecret}`).toString("base64")
134
+ const headers = getAuthHeaders(connectionOptions.apiToken, bearerToken);
135
+ const body = JSON.stringify({
136
+ message: {
137
+ libraryId,
138
+ messageId,
139
+ messageText
140
+ },
141
+ recipients: {
142
+ mailingListId,
143
+ contactId,
144
+ transactionBatchId
145
+ },
146
+ header: {
147
+ fromEmail,
148
+ replyToEmail,
149
+ fromName,
150
+ subject
151
+ },
152
+ surveyLink: {
153
+ surveyId,
154
+ expirationDate,
155
+ type
156
+ },
157
+ embeddedData,
158
+ sendDate
152
159
  });
153
- const body = new FormData();
154
- body.append("grant_type", "client_credentials");
155
- body.append("scope", scope);
156
- const response = await execute({
157
- datacenterId,
160
+ const config = {
161
+ datacenterId: connectionOptions.datacenterId,
158
162
  route,
159
163
  headers,
160
164
  body,
161
- timeout
165
+ timeout: connectionOptions.timeout
166
+ };
167
+ const response = await execute(config);
168
+ const result = safeParseCreateDistributionResponse(response);
169
+ return result;
170
+ } catch (error) {
171
+ const message = getErrorMessage(error);
172
+ return failure(message);
173
+ }
174
+ };
175
+
176
+ // src/methods/createMailingList.ts
177
+ var createMailingList = (connectionOptions) => async ({
178
+ directoryId,
179
+ name,
180
+ ownerId,
181
+ prioritizeListMetadata = false,
182
+ bearerToken = void 0
183
+ }) => {
184
+ const route = `/API/v3/directories/${directoryId}/mailinglists`;
185
+ try {
186
+ const headers = getAuthHeaders(connectionOptions.apiToken, bearerToken);
187
+ const body = JSON.stringify({
188
+ name,
189
+ ownerId,
190
+ prioritizeListMetadata
162
191
  });
163
- const result = safeParseBearerToken(response);
192
+ const config = {
193
+ datacenterId: connectionOptions.datacenterId,
194
+ route,
195
+ headers,
196
+ body,
197
+ timeout: connectionOptions.timeout
198
+ };
199
+ const response = await execute(config);
200
+ const result = safeParseCreateMailingListResponse(response);
164
201
  return result;
165
202
  } catch (error) {
166
203
  const message = getErrorMessage(error);
@@ -168,19 +205,45 @@ var getBearerToken = (connectionOptions) => async ({ clientId, clientSecret, sco
168
205
  }
169
206
  };
170
207
 
171
- // src/methods/getResponseExportProgress.ts
172
- var getResponseExportProgress = (connectionOptions) => async ({ exportProgressId, surveyId, bearerToken }) => {
173
- const route = `/API/v3/surveys/${surveyId}/export-responses/${exportProgressId}`;
208
+ // src/methods/distributions/createReminder.ts
209
+ var createReminder = (connectionOptions) => async ({
210
+ distributionId,
211
+ libraryId,
212
+ messageId,
213
+ fromEmail,
214
+ replyToEmail,
215
+ fromName,
216
+ subject,
217
+ embeddedData,
218
+ sendDate,
219
+ bearerToken = void 0
220
+ }) => {
221
+ const route = `/API/v3/distributions/${distributionId}/reminders`;
174
222
  try {
175
223
  const headers = getAuthHeaders(connectionOptions.apiToken, bearerToken);
224
+ const body = JSON.stringify({
225
+ message: {
226
+ libraryId,
227
+ messageId
228
+ },
229
+ header: {
230
+ fromEmail,
231
+ replyToEmail,
232
+ fromName,
233
+ subject
234
+ },
235
+ embeddedData,
236
+ sendDate
237
+ });
176
238
  const config = {
177
239
  datacenterId: connectionOptions.datacenterId,
178
240
  route,
179
241
  headers,
242
+ body,
180
243
  timeout: connectionOptions.timeout
181
244
  };
182
245
  const response = await execute(config);
183
- const result = safeParseFileProgressResponse(response);
246
+ const result = safeParseCreateReminderResponse(response);
184
247
  return result;
185
248
  } catch (error) {
186
249
  const message = getErrorMessage(error);
@@ -188,26 +251,201 @@ var getResponseExportProgress = (connectionOptions) => async ({ exportProgressId
188
251
  }
189
252
  };
190
253
 
191
- // src/methods/getResponseExportFile.ts
192
- var getResponseExportFile = (connectionOptions) => async ({ surveyId, fileId, bearerToken }) => {
193
- const route = `/API/v3/surveys/${surveyId}/export-responses/${fileId}/file`;
254
+ // src/utils/poll.ts
255
+ async function poll({
256
+ fn,
257
+ validate,
258
+ interval,
259
+ maxAttempts
260
+ }) {
261
+ let attempts = 0;
262
+ const executePoll = async (resolve, reject) => {
263
+ try {
264
+ const result = await fn();
265
+ attempts++;
266
+ if (validate(result)) {
267
+ return resolve(result);
268
+ } else if (maxAttempts && attempts === maxAttempts) {
269
+ return reject(new Error("Exceeded max attempts"));
270
+ } else {
271
+ setTimeout(executePoll, interval, resolve, reject);
272
+ }
273
+ } catch (error) {
274
+ reject(new Error(`Poll function execution failed: ${error}`));
275
+ }
276
+ };
277
+ return new Promise(executePoll);
278
+ }
279
+
280
+ // src/methods/contacts/startContactsImport.ts
281
+ var startContactsImport = (connectionOptions) => async (options) => {
282
+ const { directoryId, mailingListId, contacts, transactionMeta, bearerToken } = options;
283
+ const route = `/API/v3
284
+ /directories/${directoryId}/mailinglists/${mailingListId}/transactioncontacts`;
194
285
  try {
195
286
  const headers = getAuthHeaders(connectionOptions.apiToken, bearerToken);
287
+ const body = JSON.stringify({
288
+ transactionMeta,
289
+ contacts
290
+ });
196
291
  const config = {
197
292
  datacenterId: connectionOptions.datacenterId,
198
293
  route,
199
294
  headers,
295
+ body,
200
296
  timeout: connectionOptions.timeout
201
297
  };
202
298
  const response = await execute(config);
203
- return response;
299
+ const result = safeParseStartContactsImportResponse(response);
300
+ return result;
301
+ } catch (error) {
302
+ const message = getErrorMessage(error);
303
+ return failure(message);
304
+ }
305
+ };
306
+
307
+ // src/methods/contacts/getContactsImportStatus.ts
308
+ var getContactsImportStatus = (connectionOptions) => async ({ directoryId, importId, mailingListId, bearerToken = void 0 }) => {
309
+ const route = `/API/v3
310
+ /directories/${directoryId}/mailinglists/${mailingListId}/transactioncontacts/${importId}`;
311
+ try {
312
+ const headers = getAuthHeaders(connectionOptions.apiToken, bearerToken);
313
+ const config = {
314
+ datacenterId: connectionOptions.datacenterId,
315
+ route,
316
+ headers,
317
+ timeout: connectionOptions.timeout
318
+ };
319
+ const response = await execute(config);
320
+ const result = safeParseContactsImportStatus(response);
321
+ return result;
204
322
  } catch (error) {
205
323
  const message = getErrorMessage(error);
206
324
  return failure(message);
207
325
  }
208
326
  };
209
327
 
210
- // src/methods/startResponseExport.ts
328
+ // src/methods/contacts/getContactsImportSummary.ts
329
+ var getContactsImportSummary = (connectionOptions) => async ({ directoryId, importId, mailingListId, bearerToken = void 0 }) => {
330
+ const route = `/API/v3
331
+ /directories/${directoryId}/mailinglists/${mailingListId}/transactioncontacts/${importId}/summary`;
332
+ try {
333
+ const headers = getAuthHeaders(connectionOptions.apiToken, bearerToken);
334
+ const config = {
335
+ datacenterId: connectionOptions.datacenterId,
336
+ route,
337
+ headers,
338
+ timeout: connectionOptions.timeout
339
+ };
340
+ const response = await execute(config);
341
+ const result = safeParseContactsImportSummary(response);
342
+ return result;
343
+ } catch (error) {
344
+ const message = getErrorMessage(error);
345
+ return failure(message);
346
+ }
347
+ };
348
+
349
+ // src/methods/contacts/importContacts.ts
350
+ var importContacts = (connectionOptions) => async (importOptions) => {
351
+ try {
352
+ const startImportAction = startContactsImport(connectionOptions);
353
+ const startResponse = await startImportAction(importOptions);
354
+ if (!startResponse.success)
355
+ return failure(startResponse.error);
356
+ const importProgressAction = getContactsImportStatus(connectionOptions);
357
+ const progressResponse = await poll({
358
+ fn: async () => await importProgressAction({
359
+ directoryId: importOptions.directoryId,
360
+ importId: startResponse.data.id,
361
+ mailingListId: importOptions.mailingListId,
362
+ bearerToken: importOptions.bearerToken
363
+ }),
364
+ validate: (res) => res.success && res.data.percentComplete === 100,
365
+ interval: 1,
366
+ maxAttempts: 60
367
+ });
368
+ if (!progressResponse.success)
369
+ return failure(progressResponse.error);
370
+ const getContactImportSummaryAction = getContactsImportSummary(connectionOptions);
371
+ const fileResponse = await getContactImportSummaryAction({
372
+ directoryId: importOptions.directoryId,
373
+ importId: startResponse.data.id,
374
+ mailingListId: importOptions.mailingListId,
375
+ bearerToken: importOptions.bearerToken
376
+ });
377
+ return fileResponse;
378
+ } catch (error) {
379
+ const message = getErrorMessage(error);
380
+ return failure(message);
381
+ }
382
+ };
383
+
384
+ // src/methods/distributions/distributeSurveys.ts
385
+ var distributeSurveys = (connectionOptions) => async (options) => {
386
+ try {
387
+ const createMailingListAction = createMailingList(connectionOptions);
388
+ const startResponse = await createMailingListAction({
389
+ directoryId: options.directoryId,
390
+ name: options.mailingListName,
391
+ ownerId: options.ownerId,
392
+ prioritizeListMetadata: options.prioritizeListMetadata,
393
+ bearerToken: options.bearerToken
394
+ });
395
+ if (!startResponse.success)
396
+ return failure(startResponse.error);
397
+ const importContactsAction = importContacts(connectionOptions);
398
+ const importResponse = await importContactsAction({
399
+ directoryId: options.directoryId,
400
+ mailingListId: startResponse.data,
401
+ contacts: options.contacts,
402
+ transactionMeta: options.transactionMeta,
403
+ bearerToken: options.bearerToken
404
+ });
405
+ if (!importResponse.success)
406
+ return failure(importResponse.error);
407
+ const createDistributionAction = createDistribution(connectionOptions);
408
+ const distributionResponse = await createDistributionAction({
409
+ libraryId: options.libraryId,
410
+ messageId: options.distributionMessageId,
411
+ messageText: options.distributionMessageText,
412
+ mailingListId: startResponse.data,
413
+ fromEmail: options.fromEmail,
414
+ fromName: options.fromName,
415
+ replyToEmail: options.replyToEmail,
416
+ subject: options.subject,
417
+ surveyId: options.surveyId,
418
+ expirationDate: options.expirationDate,
419
+ type: options.type,
420
+ embeddedData: options.embeddedData,
421
+ sendDate: options.sendDate,
422
+ bearerToken: options.bearerToken
423
+ });
424
+ if (!distributionResponse.success)
425
+ return failure(distributionResponse.error);
426
+ const createReminderAction = createReminder(connectionOptions);
427
+ const reminderResponse = await createReminderAction({
428
+ distributionId: distributionResponse.data,
429
+ libraryId: options.libraryId,
430
+ messageId: options.reminderMessageId,
431
+ fromEmail: options.fromEmail,
432
+ fromName: options.fromName,
433
+ replyToEmail: options.replyToEmail,
434
+ subject: options.subject,
435
+ embeddedData: options.embeddedData,
436
+ sendDate: options.sendDate,
437
+ bearerToken: options.bearerToken
438
+ });
439
+ if (!reminderResponse.success)
440
+ return failure(reminderResponse.error);
441
+ return success(reminderResponse.data);
442
+ } catch (error) {
443
+ const message = getErrorMessage(error);
444
+ return failure(message);
445
+ }
446
+ };
447
+
448
+ // src/methods/responses/startResponseExport.ts
211
449
  var startResponseExport = (connectionOptions) => async ({
212
450
  surveyId,
213
451
  startDate,
@@ -243,6 +481,193 @@ var startResponseExport = (connectionOptions) => async ({
243
481
  }
244
482
  };
245
483
 
484
+ // src/methods/responses/getResponseExportFile.ts
485
+ var getResponseExportFile = (connectionOptions) => async ({ surveyId, fileId, bearerToken }) => {
486
+ const route = `/API/v3/surveys/${surveyId}/export-responses/${fileId}/file`;
487
+ try {
488
+ const headers = getAuthHeaders(connectionOptions.apiToken, bearerToken);
489
+ const config = {
490
+ datacenterId: connectionOptions.datacenterId,
491
+ route,
492
+ headers,
493
+ timeout: connectionOptions.timeout
494
+ };
495
+ const response = await execute(config);
496
+ return response;
497
+ } catch (error) {
498
+ const message = getErrorMessage(error);
499
+ return failure(message);
500
+ }
501
+ };
502
+
503
+ // src/methods/responses/getResponseExportProgress.ts
504
+ var getResponseExportProgress = (connectionOptions) => async ({ exportProgressId, surveyId, bearerToken }) => {
505
+ const route = `/API/v3/surveys/${surveyId}/export-responses/${exportProgressId}`;
506
+ try {
507
+ const headers = getAuthHeaders(connectionOptions.apiToken, bearerToken);
508
+ const config = {
509
+ datacenterId: connectionOptions.datacenterId,
510
+ route,
511
+ headers,
512
+ timeout: connectionOptions.timeout
513
+ };
514
+ const response = await execute(config);
515
+ const result = safeParseFileProgressResponse(response);
516
+ return result;
517
+ } catch (error) {
518
+ const message = getErrorMessage(error);
519
+ return failure(message);
520
+ }
521
+ };
522
+
523
+ // src/methods/responses/exportResponses.ts
524
+ var exportResponses = (connectionOptions) => async (responseOptions) => {
525
+ try {
526
+ const startResponseAction = startResponseExport(connectionOptions);
527
+ const startResponse = await startResponseAction(responseOptions);
528
+ if (!startResponse.success)
529
+ return failure(startResponse.error);
530
+ const exportProgressAction = getResponseExportProgress(connectionOptions);
531
+ const progressResponse = await poll({
532
+ fn: async () => await exportProgressAction({
533
+ exportProgressId: startResponse.data.progressId,
534
+ surveyId: responseOptions.surveyId,
535
+ bearerToken: responseOptions.bearerToken
536
+ }),
537
+ validate: (res) => res.success && res.data.percentComplete === 100,
538
+ interval: 1,
539
+ maxAttempts: 60
540
+ });
541
+ if (!progressResponse.success)
542
+ return failure(progressResponse.error);
543
+ const getFileResponseAction = getResponseExportFile(connectionOptions);
544
+ const fileResponse = await getFileResponseAction({
545
+ surveyId: responseOptions.surveyId,
546
+ fileId: progressResponse.data.fileId,
547
+ bearerToken: responseOptions.bearerToken
548
+ });
549
+ return fileResponse;
550
+ } catch (error) {
551
+ const message = getErrorMessage(error);
552
+ return failure(message);
553
+ }
554
+ };
555
+
556
+ // src/methods/getBearerToken.ts
557
+ var getBearerToken = (connectionOptions) => async ({ clientId, clientSecret, scope }) => {
558
+ const route = `/oauth2/token`;
559
+ try {
560
+ const { datacenterId, timeout } = connectionOptions;
561
+ const headers = new Headers({
562
+ Authorization: "Basic " + Buffer.from(`${clientId}:${clientSecret}`).toString("base64")
563
+ });
564
+ const body = new FormData();
565
+ body.append("grant_type", "client_credentials");
566
+ body.append("scope", scope);
567
+ const response = await execute({
568
+ datacenterId,
569
+ route,
570
+ headers,
571
+ body,
572
+ timeout
573
+ });
574
+ const result = safeParseBearerToken(response);
575
+ return result;
576
+ } catch (error) {
577
+ const message = getErrorMessage(error);
578
+ return failure(message);
579
+ }
580
+ };
581
+
582
+ // src/methods/distributions/getDistribution.ts
583
+ var getDistribution = (connectionOptions) => async ({ distributionId, surveyId, bearerToken = void 0 }) => {
584
+ try {
585
+ const headers = getAuthHeaders(connectionOptions.apiToken, bearerToken);
586
+ const qs = new URLSearchParams({ surveyId });
587
+ const route = `/API/v3/distributions/${distributionId}?${qs.toString()}`;
588
+ const config = {
589
+ datacenterId: connectionOptions.datacenterId,
590
+ route,
591
+ headers,
592
+ timeout: connectionOptions.timeout
593
+ };
594
+ const response = await execute(config);
595
+ const result = safeParseGetDistribution(response);
596
+ return result;
597
+ } catch (error) {
598
+ const message = getErrorMessage(error);
599
+ return failure(message);
600
+ }
601
+ };
602
+
603
+ // src/methods/distributions/listDistributions.ts
604
+ var listDistributions = (connectionOptions) => async ({
605
+ surveyId,
606
+ distributionRequestType,
607
+ mailingListId,
608
+ sendStartDate,
609
+ sendEndDate,
610
+ skipToken,
611
+ useNewPaginationScheme,
612
+ pageSize,
613
+ bearerToken = void 0
614
+ }) => {
615
+ try {
616
+ const headers = getAuthHeaders(connectionOptions.apiToken, bearerToken);
617
+ const qs = new URLSearchParams({
618
+ surveyId,
619
+ distributionRequestType,
620
+ mailingListId,
621
+ sendStartDate: sendStartDate.toISOString(),
622
+ sendEndDate: sendEndDate.toISOString()
623
+ });
624
+ if (skipToken)
625
+ qs.append("skipToken", skipToken);
626
+ if (useNewPaginationScheme)
627
+ qs.append("useNewPaginationScheme", useNewPaginationScheme.toString());
628
+ if (pageSize)
629
+ qs.append("pageSize", pageSize.toString());
630
+ const route = `/API/v3/distributions?${qs.toString()}`;
631
+ const config = {
632
+ datacenterId: connectionOptions.datacenterId,
633
+ route,
634
+ headers,
635
+ timeout: connectionOptions.timeout
636
+ };
637
+ const response = await execute(config);
638
+ const result = safeParseListDistributions(response);
639
+ return result;
640
+ } catch (error) {
641
+ const message = getErrorMessage(error);
642
+ return failure(message);
643
+ }
644
+ };
645
+
646
+ // src/methods/listLibraryMessages.ts
647
+ var listLibraryMessages = (connectionOptions) => async ({ libraryId, category, offset, bearerToken = void 0 }) => {
648
+ const route = `/API/v3/libraries/${libraryId}/messages`;
649
+ try {
650
+ const headers = getAuthHeaders(connectionOptions.apiToken, bearerToken);
651
+ const qs = new URLSearchParams();
652
+ if (category)
653
+ qs.append("category", category);
654
+ if (offset)
655
+ qs.append("offset", offset.toString());
656
+ const config = {
657
+ datacenterId: connectionOptions.datacenterId,
658
+ route: qs.size > 0 ? route + "?" + qs.toString() : route,
659
+ headers,
660
+ timeout: connectionOptions.timeout
661
+ };
662
+ const response = await execute(config);
663
+ const result = safeParseListLibraryMessages(response);
664
+ return result;
665
+ } catch (error) {
666
+ const message = getErrorMessage(error);
667
+ return failure(message);
668
+ }
669
+ };
670
+
246
671
  // src/methods/testConnection.ts
247
672
  var testConnection = (connectionOptions) => async (bearerToken) => {
248
673
  const route = "/API/v3/whoami";
@@ -265,19 +690,41 @@ var testConnection = (connectionOptions) => async (bearerToken) => {
265
690
 
266
691
  // src/createConnection.ts
267
692
  var createConnection = (options) => ({
693
+ createDistribution: createDistribution(options),
694
+ createMailingList: createMailingList(options),
695
+ createReminder: createReminder(options),
696
+ distributeSurveys: distributeSurveys(options),
268
697
  exportResponses: exportResponses(options),
269
698
  getBearerToken: getBearerToken(options),
699
+ getContactsImportStatus: getContactsImportStatus(options),
700
+ getContactsImportSummary: getContactsImportSummary(options),
701
+ getDistribution: getDistribution(options),
270
702
  getResponseExportFile: getResponseExportFile(options),
271
703
  getResponseExportProgress: getResponseExportProgress(options),
704
+ importContacts: importContacts(options),
705
+ listDistributions: listDistributions(options),
706
+ listLibraryMessages: listLibraryMessages(options),
707
+ startContactsImport: startContactsImport(options),
272
708
  startResponseExport: startResponseExport(options),
273
709
  testConnection: testConnection(options)
274
710
  });
275
711
  export {
276
712
  createConnection,
713
+ createDistribution,
714
+ createMailingList,
715
+ createReminder,
716
+ distributeSurveys,
277
717
  exportResponses,
278
718
  getBearerToken,
719
+ getContactsImportStatus,
720
+ getContactsImportSummary,
721
+ getDistribution,
279
722
  getResponseExportFile,
280
723
  getResponseExportProgress,
724
+ importContacts,
725
+ listDistributions,
726
+ listLibraryMessages,
727
+ startContactsImport,
281
728
  startResponseExport,
282
729
  testConnection
283
730
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@b-jones-rfd/qualtrics-api-tasks",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Perform common tasks using the Qualtrics API",
5
5
  "private": false,
6
6
  "main": "./dist/index.js",