@b-jones-rfd/qualtrics-api-tasks 0.2.0 → 0.3.1
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/CHANGELOG.md +12 -0
- package/README.md +222 -29
- package/dist/index.d.mts +356 -1
- package/dist/index.d.ts +356 -1
- package/dist/index.js +539 -81
- package/dist/index.mjs +528 -81
- package/package.json +1 -1
- package/tests/utils.test.ts +360 -0
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,65 +72,6 @@ function getAuthHeaders(apiToken, bearerToken) {
|
|
|
61
72
|
);
|
|
62
73
|
}
|
|
63
74
|
|
|
64
|
-
// src/utils/poll.ts
|
|
65
|
-
async function poll({
|
|
66
|
-
fn,
|
|
67
|
-
validate,
|
|
68
|
-
interval,
|
|
69
|
-
maxAttempts
|
|
70
|
-
}) {
|
|
71
|
-
let attempts = 0;
|
|
72
|
-
const executePoll = async (resolve, reject) => {
|
|
73
|
-
try {
|
|
74
|
-
const result = await fn();
|
|
75
|
-
attempts++;
|
|
76
|
-
if (validate(result)) {
|
|
77
|
-
return resolve(result);
|
|
78
|
-
} else if (maxAttempts && attempts === maxAttempts) {
|
|
79
|
-
return reject(new Error("Exceeded max attempts"));
|
|
80
|
-
} else {
|
|
81
|
-
setTimeout(executePoll, interval, resolve, reject);
|
|
82
|
-
}
|
|
83
|
-
} catch (error) {
|
|
84
|
-
reject(new Error(`Poll function execution failed: ${error}`));
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
return new Promise(executePoll);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// src/methods/exportResponses.ts
|
|
91
|
-
var exportResponses = (connectionOptions) => async (responseOptions) => {
|
|
92
|
-
try {
|
|
93
|
-
const startResponseAction = startResponseExport(connectionOptions);
|
|
94
|
-
const startResponse = await startResponseAction(responseOptions);
|
|
95
|
-
if (!startResponse.success)
|
|
96
|
-
return failure(startResponse.error);
|
|
97
|
-
const exportProgressAction = getResponseExportProgress(connectionOptions);
|
|
98
|
-
const progressResponse = await poll({
|
|
99
|
-
fn: async () => await exportProgressAction({
|
|
100
|
-
exportProgressId: startResponse.data.progressId,
|
|
101
|
-
surveyId: responseOptions.surveyId,
|
|
102
|
-
bearerToken: responseOptions.bearerToken
|
|
103
|
-
}),
|
|
104
|
-
validate: (res) => res.success && res.data.percentComplete === 100,
|
|
105
|
-
interval: 1,
|
|
106
|
-
maxAttempts: 60
|
|
107
|
-
});
|
|
108
|
-
if (!progressResponse.success)
|
|
109
|
-
return failure(progressResponse.error);
|
|
110
|
-
const getFileResponseAction = getResponseExportFile(connectionOptions);
|
|
111
|
-
const fileResponse = await getFileResponseAction({
|
|
112
|
-
surveyId: responseOptions.surveyId,
|
|
113
|
-
fileId: progressResponse.data.fileId,
|
|
114
|
-
bearerToken: responseOptions.bearerToken
|
|
115
|
-
});
|
|
116
|
-
return fileResponse;
|
|
117
|
-
} catch (error) {
|
|
118
|
-
const message = getErrorMessage(error);
|
|
119
|
-
return failure(message);
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
|
|
123
75
|
// src/utils/parsers.ts
|
|
124
76
|
function safeParseBearerToken(response) {
|
|
125
77
|
return response?.access_token && typeof response.access_token === "string" ? success(response.access_token) : failure("Incorrect token format");
|
|
@@ -133,6 +85,33 @@ function safeParseStartFileExportResponse(response) {
|
|
|
133
85
|
function safeParseFileProgressResponse(response) {
|
|
134
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`);
|
|
135
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
|
+
}
|
|
136
115
|
|
|
137
116
|
// src/qualtrics/index.ts
|
|
138
117
|
async function execute(config) {
|
|
@@ -174,25 +153,94 @@ async function execute(config) {
|
|
|
174
153
|
}
|
|
175
154
|
}
|
|
176
155
|
|
|
177
|
-
// src/methods/
|
|
178
|
-
var
|
|
179
|
-
|
|
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`;
|
|
180
176
|
try {
|
|
181
|
-
const
|
|
182
|
-
const
|
|
183
|
-
|
|
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
|
|
184
202
|
});
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
-
body.append("scope", scope);
|
|
188
|
-
const response = await execute({
|
|
189
|
-
datacenterId,
|
|
203
|
+
const config = {
|
|
204
|
+
datacenterId: connectionOptions.datacenterId,
|
|
190
205
|
route,
|
|
191
206
|
headers,
|
|
192
207
|
body,
|
|
193
|
-
timeout
|
|
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
|
|
194
234
|
});
|
|
195
|
-
const
|
|
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);
|
|
196
244
|
return result;
|
|
197
245
|
} catch (error) {
|
|
198
246
|
const message = getErrorMessage(error);
|
|
@@ -200,19 +248,45 @@ var getBearerToken = (connectionOptions) => async ({ clientId, clientSecret, sco
|
|
|
200
248
|
}
|
|
201
249
|
};
|
|
202
250
|
|
|
203
|
-
// src/methods/
|
|
204
|
-
var
|
|
205
|
-
|
|
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`;
|
|
206
265
|
try {
|
|
207
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
|
+
});
|
|
208
281
|
const config = {
|
|
209
282
|
datacenterId: connectionOptions.datacenterId,
|
|
210
283
|
route,
|
|
211
284
|
headers,
|
|
285
|
+
body,
|
|
212
286
|
timeout: connectionOptions.timeout
|
|
213
287
|
};
|
|
214
288
|
const response = await execute(config);
|
|
215
|
-
const result =
|
|
289
|
+
const result = safeParseCreateReminderResponse(response);
|
|
216
290
|
return result;
|
|
217
291
|
} catch (error) {
|
|
218
292
|
const message = getErrorMessage(error);
|
|
@@ -220,26 +294,201 @@ var getResponseExportProgress = (connectionOptions) => async ({ exportProgressId
|
|
|
220
294
|
}
|
|
221
295
|
};
|
|
222
296
|
|
|
223
|
-
// src/
|
|
224
|
-
|
|
225
|
-
|
|
297
|
+
// src/utils/poll.ts
|
|
298
|
+
async function poll({
|
|
299
|
+
fn,
|
|
300
|
+
validate,
|
|
301
|
+
interval,
|
|
302
|
+
maxAttempts
|
|
303
|
+
}) {
|
|
304
|
+
let attempts = 0;
|
|
305
|
+
const executePoll = async (resolve, reject) => {
|
|
306
|
+
try {
|
|
307
|
+
const result = await fn();
|
|
308
|
+
attempts++;
|
|
309
|
+
if (validate(result)) {
|
|
310
|
+
return resolve(result);
|
|
311
|
+
} else if (maxAttempts && attempts === maxAttempts) {
|
|
312
|
+
return reject(new Error("Exceeded max attempts"));
|
|
313
|
+
} else {
|
|
314
|
+
setTimeout(executePoll, interval, resolve, reject);
|
|
315
|
+
}
|
|
316
|
+
} catch (error) {
|
|
317
|
+
reject(new Error(`Poll function execution failed: ${error}`));
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
return new Promise(executePoll);
|
|
321
|
+
}
|
|
322
|
+
|
|
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`;
|
|
226
328
|
try {
|
|
227
329
|
const headers = getAuthHeaders(connectionOptions.apiToken, bearerToken);
|
|
330
|
+
const body = JSON.stringify({
|
|
331
|
+
transactionMeta,
|
|
332
|
+
contacts
|
|
333
|
+
});
|
|
228
334
|
const config = {
|
|
229
335
|
datacenterId: connectionOptions.datacenterId,
|
|
230
336
|
route,
|
|
231
337
|
headers,
|
|
338
|
+
body,
|
|
232
339
|
timeout: connectionOptions.timeout
|
|
233
340
|
};
|
|
234
341
|
const response = await execute(config);
|
|
235
|
-
|
|
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;
|
|
236
365
|
} catch (error) {
|
|
237
366
|
const message = getErrorMessage(error);
|
|
238
367
|
return failure(message);
|
|
239
368
|
}
|
|
240
369
|
};
|
|
241
370
|
|
|
242
|
-
// src/methods/
|
|
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
|
|
243
492
|
var startResponseExport = (connectionOptions) => async ({
|
|
244
493
|
surveyId,
|
|
245
494
|
startDate,
|
|
@@ -275,6 +524,193 @@ var startResponseExport = (connectionOptions) => async ({
|
|
|
275
524
|
}
|
|
276
525
|
};
|
|
277
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
|
|
567
|
+
var exportResponses = (connectionOptions) => async (responseOptions) => {
|
|
568
|
+
try {
|
|
569
|
+
const startResponseAction = startResponseExport(connectionOptions);
|
|
570
|
+
const startResponse = await startResponseAction(responseOptions);
|
|
571
|
+
if (!startResponse.success)
|
|
572
|
+
return failure(startResponse.error);
|
|
573
|
+
const exportProgressAction = getResponseExportProgress(connectionOptions);
|
|
574
|
+
const progressResponse = await poll({
|
|
575
|
+
fn: async () => await exportProgressAction({
|
|
576
|
+
exportProgressId: startResponse.data.progressId,
|
|
577
|
+
surveyId: responseOptions.surveyId,
|
|
578
|
+
bearerToken: responseOptions.bearerToken
|
|
579
|
+
}),
|
|
580
|
+
validate: (res) => res.success && res.data.percentComplete === 100,
|
|
581
|
+
interval: 1,
|
|
582
|
+
maxAttempts: 60
|
|
583
|
+
});
|
|
584
|
+
if (!progressResponse.success)
|
|
585
|
+
return failure(progressResponse.error);
|
|
586
|
+
const getFileResponseAction = getResponseExportFile(connectionOptions);
|
|
587
|
+
const fileResponse = await getFileResponseAction({
|
|
588
|
+
surveyId: responseOptions.surveyId,
|
|
589
|
+
fileId: progressResponse.data.fileId,
|
|
590
|
+
bearerToken: responseOptions.bearerToken
|
|
591
|
+
});
|
|
592
|
+
return fileResponse;
|
|
593
|
+
} catch (error) {
|
|
594
|
+
const message = getErrorMessage(error);
|
|
595
|
+
return failure(message);
|
|
596
|
+
}
|
|
597
|
+
};
|
|
598
|
+
|
|
599
|
+
// src/methods/getBearerToken.ts
|
|
600
|
+
var getBearerToken = (connectionOptions) => async ({ clientId, clientSecret, scope }) => {
|
|
601
|
+
const route = `/oauth2/token`;
|
|
602
|
+
try {
|
|
603
|
+
const { datacenterId, timeout } = connectionOptions;
|
|
604
|
+
const headers = new Headers({
|
|
605
|
+
Authorization: "Basic " + Buffer.from(`${clientId}:${clientSecret}`).toString("base64")
|
|
606
|
+
});
|
|
607
|
+
const body = new FormData();
|
|
608
|
+
body.append("grant_type", "client_credentials");
|
|
609
|
+
body.append("scope", scope);
|
|
610
|
+
const response = await execute({
|
|
611
|
+
datacenterId,
|
|
612
|
+
route,
|
|
613
|
+
headers,
|
|
614
|
+
body,
|
|
615
|
+
timeout
|
|
616
|
+
});
|
|
617
|
+
const result = safeParseBearerToken(response);
|
|
618
|
+
return result;
|
|
619
|
+
} catch (error) {
|
|
620
|
+
const message = getErrorMessage(error);
|
|
621
|
+
return failure(message);
|
|
622
|
+
}
|
|
623
|
+
};
|
|
624
|
+
|
|
625
|
+
// src/methods/distributions/getDistribution.ts
|
|
626
|
+
var getDistribution = (connectionOptions) => async ({ distributionId, surveyId, bearerToken = void 0 }) => {
|
|
627
|
+
try {
|
|
628
|
+
const headers = getAuthHeaders(connectionOptions.apiToken, bearerToken);
|
|
629
|
+
const qs = new URLSearchParams({ surveyId });
|
|
630
|
+
const route = `/API/v3/distributions/${distributionId}?${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 = safeParseGetDistribution(response);
|
|
639
|
+
return result;
|
|
640
|
+
} catch (error) {
|
|
641
|
+
const message = getErrorMessage(error);
|
|
642
|
+
return failure(message);
|
|
643
|
+
}
|
|
644
|
+
};
|
|
645
|
+
|
|
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
|
+
}) => {
|
|
658
|
+
try {
|
|
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()}`;
|
|
674
|
+
const config = {
|
|
675
|
+
datacenterId: connectionOptions.datacenterId,
|
|
676
|
+
route,
|
|
677
|
+
headers,
|
|
678
|
+
timeout: connectionOptions.timeout
|
|
679
|
+
};
|
|
680
|
+
const response = await execute(config);
|
|
681
|
+
const result = safeParseListDistributions(response);
|
|
682
|
+
return result;
|
|
683
|
+
} catch (error) {
|
|
684
|
+
const message = getErrorMessage(error);
|
|
685
|
+
return failure(message);
|
|
686
|
+
}
|
|
687
|
+
};
|
|
688
|
+
|
|
689
|
+
// src/methods/listLibraryMessages.ts
|
|
690
|
+
var listLibraryMessages = (connectionOptions) => async ({ libraryId, category, offset, bearerToken = void 0 }) => {
|
|
691
|
+
const route = `/API/v3/libraries/${libraryId}/messages`;
|
|
692
|
+
try {
|
|
693
|
+
const headers = getAuthHeaders(connectionOptions.apiToken, bearerToken);
|
|
694
|
+
const qs = new URLSearchParams();
|
|
695
|
+
if (category)
|
|
696
|
+
qs.append("category", category);
|
|
697
|
+
if (offset)
|
|
698
|
+
qs.append("offset", offset.toString());
|
|
699
|
+
const config = {
|
|
700
|
+
datacenterId: connectionOptions.datacenterId,
|
|
701
|
+
route: qs.size > 0 ? route + "?" + qs.toString() : route,
|
|
702
|
+
headers,
|
|
703
|
+
timeout: connectionOptions.timeout
|
|
704
|
+
};
|
|
705
|
+
const response = await execute(config);
|
|
706
|
+
const result = safeParseListLibraryMessages(response);
|
|
707
|
+
return result;
|
|
708
|
+
} catch (error) {
|
|
709
|
+
const message = getErrorMessage(error);
|
|
710
|
+
return failure(message);
|
|
711
|
+
}
|
|
712
|
+
};
|
|
713
|
+
|
|
278
714
|
// src/methods/testConnection.ts
|
|
279
715
|
var testConnection = (connectionOptions) => async (bearerToken) => {
|
|
280
716
|
const route = "/API/v3/whoami";
|
|
@@ -297,20 +733,42 @@ var testConnection = (connectionOptions) => async (bearerToken) => {
|
|
|
297
733
|
|
|
298
734
|
// src/createConnection.ts
|
|
299
735
|
var createConnection = (options) => ({
|
|
736
|
+
createDistribution: createDistribution(options),
|
|
737
|
+
createMailingList: createMailingList(options),
|
|
738
|
+
createReminder: createReminder(options),
|
|
739
|
+
distributeSurveys: distributeSurveys(options),
|
|
300
740
|
exportResponses: exportResponses(options),
|
|
301
741
|
getBearerToken: getBearerToken(options),
|
|
742
|
+
getContactsImportStatus: getContactsImportStatus(options),
|
|
743
|
+
getContactsImportSummary: getContactsImportSummary(options),
|
|
744
|
+
getDistribution: getDistribution(options),
|
|
302
745
|
getResponseExportFile: getResponseExportFile(options),
|
|
303
746
|
getResponseExportProgress: getResponseExportProgress(options),
|
|
747
|
+
importContacts: importContacts(options),
|
|
748
|
+
listDistributions: listDistributions(options),
|
|
749
|
+
listLibraryMessages: listLibraryMessages(options),
|
|
750
|
+
startContactsImport: startContactsImport(options),
|
|
304
751
|
startResponseExport: startResponseExport(options),
|
|
305
752
|
testConnection: testConnection(options)
|
|
306
753
|
});
|
|
307
754
|
// Annotate the CommonJS export names for ESM import in node:
|
|
308
755
|
0 && (module.exports = {
|
|
309
756
|
createConnection,
|
|
757
|
+
createDistribution,
|
|
758
|
+
createMailingList,
|
|
759
|
+
createReminder,
|
|
760
|
+
distributeSurveys,
|
|
310
761
|
exportResponses,
|
|
311
762
|
getBearerToken,
|
|
763
|
+
getContactsImportStatus,
|
|
764
|
+
getContactsImportSummary,
|
|
765
|
+
getDistribution,
|
|
312
766
|
getResponseExportFile,
|
|
313
767
|
getResponseExportProgress,
|
|
768
|
+
importContacts,
|
|
769
|
+
listDistributions,
|
|
770
|
+
listLibraryMessages,
|
|
771
|
+
startContactsImport,
|
|
314
772
|
startResponseExport,
|
|
315
773
|
testConnection
|
|
316
774
|
});
|