@b-jones-rfd/qualtrics-api-tasks 0.1.0 → 0.1.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 +6 -0
- package/README.md +4 -4
- package/dist/index.d.mts +40 -2
- package/dist/index.d.ts +40 -2
- package/dist/index.js +10 -5
- package/dist/index.mjs +10 -5
- package/package.json +1 -1
- package/tests/utils.test.ts +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -76,7 +76,7 @@ import { createConnection } from '@b-jones-rfd/qualtrics-api-tasks'
|
|
|
76
76
|
const connectionOptions = {
|
|
77
77
|
datacenterId: 'az1',
|
|
78
78
|
apiToken: 'my API Token', // optional
|
|
79
|
-
timeout:
|
|
79
|
+
timeout: 20 * 1000, // optional timeout in milliseconds, default is 30 seconds
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
const connection: SiteConnection = createConnection(connectionOptions)
|
|
@@ -123,9 +123,9 @@ async function testMyQualtricsConnection(listName: string) {
|
|
|
123
123
|
|
|
124
124
|
`timeout`
|
|
125
125
|
|
|
126
|
-
| Type | Default value | Description | Example
|
|
127
|
-
| ------ | ------------- | ------------------------- |
|
|
128
|
-
| number | 30000 | Qualtrics request timeout |
|
|
126
|
+
| Type | Default value | Description | Example | Required |
|
|
127
|
+
| ------ | ------------- | ------------------------- | ------- | -------- |
|
|
128
|
+
| number | 30000 | Qualtrics request timeout | 1000 | N |
|
|
129
129
|
|
|
130
130
|
### Actions
|
|
131
131
|
|
package/dist/index.d.mts
CHANGED
|
@@ -22,6 +22,11 @@ type Connection = {
|
|
|
22
22
|
clientSecret: string;
|
|
23
23
|
scope: string;
|
|
24
24
|
}, string>;
|
|
25
|
+
getResponseExportFile: Action<{
|
|
26
|
+
surveyId: string;
|
|
27
|
+
fileId: string;
|
|
28
|
+
bearerToken?: string;
|
|
29
|
+
}, Buffer>;
|
|
25
30
|
getResponseExportProgress: Action<{
|
|
26
31
|
exportProgressId: string;
|
|
27
32
|
surveyId: string;
|
|
@@ -33,7 +38,7 @@ type Connection = {
|
|
|
33
38
|
status: string;
|
|
34
39
|
continuationToken?: string;
|
|
35
40
|
}>;
|
|
36
|
-
testConnection: (bearerToken?: string) => Promise<Result<
|
|
41
|
+
testConnection: (bearerToken?: string) => Promise<Result<string>>;
|
|
37
42
|
};
|
|
38
43
|
type ConnectionFactory = (options: ConnectionOptions) => Connection;
|
|
39
44
|
type ExportResponsesOptions = {
|
|
@@ -71,26 +76,56 @@ type FileProgressResponse = {
|
|
|
71
76
|
|
|
72
77
|
declare const createConnection: ConnectionFactory;
|
|
73
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Export Survey Response File
|
|
81
|
+
*
|
|
82
|
+
* Implements Survey Response File Export end to end
|
|
83
|
+
* @see https://api.qualtrics.com/u9e5lh4172v0v-survey-response-export-guide
|
|
84
|
+
*/
|
|
74
85
|
declare const exportResponses: ActionFactory<ExportResponsesOptions, Buffer>;
|
|
75
86
|
|
|
87
|
+
/**
|
|
88
|
+
* Get Bearer Token
|
|
89
|
+
*
|
|
90
|
+
* Implements OAuth Authentication (Client Credentials
|
|
91
|
+
* @see https://api.qualtrics.com/9398592961ced-o-auth-authentication-client-credentials
|
|
92
|
+
*/
|
|
76
93
|
declare const getBearerToken: ActionFactory<{
|
|
77
94
|
clientId: string;
|
|
78
95
|
clientSecret: string;
|
|
79
96
|
scope: string;
|
|
80
97
|
}, string>;
|
|
81
98
|
|
|
99
|
+
/**
|
|
100
|
+
* Get Response Export File
|
|
101
|
+
*
|
|
102
|
+
* Implements Get Response Export Progress. This is step 2 in the survey response file export process.
|
|
103
|
+
* @see https://api.qualtrics.com/37e6a66f74ab4-get-response-export-progress
|
|
104
|
+
*/
|
|
82
105
|
declare const getResponseExportProgress: ActionFactory<{
|
|
83
106
|
exportProgressId: string;
|
|
84
107
|
surveyId: string;
|
|
85
108
|
bearerToken?: string;
|
|
86
109
|
}, FileProgressResponse>;
|
|
87
110
|
|
|
111
|
+
/**
|
|
112
|
+
* Get Response Export File
|
|
113
|
+
*
|
|
114
|
+
* Implements Get Response Export File. This is step 3 in the survey response file export process.
|
|
115
|
+
* @see https://api.qualtrics.com/41296b6f2e828-get-response-export-file
|
|
116
|
+
*/
|
|
88
117
|
declare const getResponseExportFile: ActionFactory<{
|
|
89
118
|
surveyId: string;
|
|
90
119
|
fileId: string;
|
|
91
120
|
bearerToken?: string;
|
|
92
121
|
}, Buffer>;
|
|
93
122
|
|
|
123
|
+
/**
|
|
124
|
+
* Start Response Export
|
|
125
|
+
*
|
|
126
|
+
* Implements Start Response File Export
|
|
127
|
+
* @see https://api.qualtrics.com/6b00592b9c013-start-response-export
|
|
128
|
+
*/
|
|
94
129
|
declare const startResponseExport: ActionFactory<ExportResponsesOptions, {
|
|
95
130
|
progressId: string;
|
|
96
131
|
percentComplete: number;
|
|
@@ -98,6 +133,9 @@ declare const startResponseExport: ActionFactory<ExportResponsesOptions, {
|
|
|
98
133
|
continuationToken?: string;
|
|
99
134
|
}>;
|
|
100
135
|
|
|
101
|
-
|
|
136
|
+
/**
|
|
137
|
+
* Test connection to Qualtrics API
|
|
138
|
+
*/
|
|
139
|
+
declare const testConnection: (connectionOptions: ConnectionOptions) => (bearerToken?: string) => Promise<Result<string>>;
|
|
102
140
|
|
|
103
141
|
export { type Action, type ActionFactory, type Connection, type ConnectionFactory, type ConnectionOptions, type ExportResponsesOptions, type Failure, type FileProgressResponse, type ResponseFormat, type Result, type Success, createConnection, exportResponses, getBearerToken, getResponseExportFile, getResponseExportProgress, startResponseExport, testConnection };
|
package/dist/index.d.ts
CHANGED
|
@@ -22,6 +22,11 @@ type Connection = {
|
|
|
22
22
|
clientSecret: string;
|
|
23
23
|
scope: string;
|
|
24
24
|
}, string>;
|
|
25
|
+
getResponseExportFile: Action<{
|
|
26
|
+
surveyId: string;
|
|
27
|
+
fileId: string;
|
|
28
|
+
bearerToken?: string;
|
|
29
|
+
}, Buffer>;
|
|
25
30
|
getResponseExportProgress: Action<{
|
|
26
31
|
exportProgressId: string;
|
|
27
32
|
surveyId: string;
|
|
@@ -33,7 +38,7 @@ type Connection = {
|
|
|
33
38
|
status: string;
|
|
34
39
|
continuationToken?: string;
|
|
35
40
|
}>;
|
|
36
|
-
testConnection: (bearerToken?: string) => Promise<Result<
|
|
41
|
+
testConnection: (bearerToken?: string) => Promise<Result<string>>;
|
|
37
42
|
};
|
|
38
43
|
type ConnectionFactory = (options: ConnectionOptions) => Connection;
|
|
39
44
|
type ExportResponsesOptions = {
|
|
@@ -71,26 +76,56 @@ type FileProgressResponse = {
|
|
|
71
76
|
|
|
72
77
|
declare const createConnection: ConnectionFactory;
|
|
73
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Export Survey Response File
|
|
81
|
+
*
|
|
82
|
+
* Implements Survey Response File Export end to end
|
|
83
|
+
* @see https://api.qualtrics.com/u9e5lh4172v0v-survey-response-export-guide
|
|
84
|
+
*/
|
|
74
85
|
declare const exportResponses: ActionFactory<ExportResponsesOptions, Buffer>;
|
|
75
86
|
|
|
87
|
+
/**
|
|
88
|
+
* Get Bearer Token
|
|
89
|
+
*
|
|
90
|
+
* Implements OAuth Authentication (Client Credentials
|
|
91
|
+
* @see https://api.qualtrics.com/9398592961ced-o-auth-authentication-client-credentials
|
|
92
|
+
*/
|
|
76
93
|
declare const getBearerToken: ActionFactory<{
|
|
77
94
|
clientId: string;
|
|
78
95
|
clientSecret: string;
|
|
79
96
|
scope: string;
|
|
80
97
|
}, string>;
|
|
81
98
|
|
|
99
|
+
/**
|
|
100
|
+
* Get Response Export File
|
|
101
|
+
*
|
|
102
|
+
* Implements Get Response Export Progress. This is step 2 in the survey response file export process.
|
|
103
|
+
* @see https://api.qualtrics.com/37e6a66f74ab4-get-response-export-progress
|
|
104
|
+
*/
|
|
82
105
|
declare const getResponseExportProgress: ActionFactory<{
|
|
83
106
|
exportProgressId: string;
|
|
84
107
|
surveyId: string;
|
|
85
108
|
bearerToken?: string;
|
|
86
109
|
}, FileProgressResponse>;
|
|
87
110
|
|
|
111
|
+
/**
|
|
112
|
+
* Get Response Export File
|
|
113
|
+
*
|
|
114
|
+
* Implements Get Response Export File. This is step 3 in the survey response file export process.
|
|
115
|
+
* @see https://api.qualtrics.com/41296b6f2e828-get-response-export-file
|
|
116
|
+
*/
|
|
88
117
|
declare const getResponseExportFile: ActionFactory<{
|
|
89
118
|
surveyId: string;
|
|
90
119
|
fileId: string;
|
|
91
120
|
bearerToken?: string;
|
|
92
121
|
}, Buffer>;
|
|
93
122
|
|
|
123
|
+
/**
|
|
124
|
+
* Start Response Export
|
|
125
|
+
*
|
|
126
|
+
* Implements Start Response File Export
|
|
127
|
+
* @see https://api.qualtrics.com/6b00592b9c013-start-response-export
|
|
128
|
+
*/
|
|
94
129
|
declare const startResponseExport: ActionFactory<ExportResponsesOptions, {
|
|
95
130
|
progressId: string;
|
|
96
131
|
percentComplete: number;
|
|
@@ -98,6 +133,9 @@ declare const startResponseExport: ActionFactory<ExportResponsesOptions, {
|
|
|
98
133
|
continuationToken?: string;
|
|
99
134
|
}>;
|
|
100
135
|
|
|
101
|
-
|
|
136
|
+
/**
|
|
137
|
+
* Test connection to Qualtrics API
|
|
138
|
+
*/
|
|
139
|
+
declare const testConnection: (connectionOptions: ConnectionOptions) => (bearerToken?: string) => Promise<Result<string>>;
|
|
102
140
|
|
|
103
141
|
export { type Action, type ActionFactory, type Connection, type ConnectionFactory, type ConnectionOptions, type ExportResponsesOptions, type Failure, type FileProgressResponse, type ResponseFormat, type Result, type Success, createConnection, exportResponses, getBearerToken, getResponseExportFile, getResponseExportProgress, startResponseExport, testConnection };
|
package/dist/index.js
CHANGED
|
@@ -125,7 +125,7 @@ function safeParseBearerToken(response) {
|
|
|
125
125
|
return response?.access_token && typeof response.access_token === "string" ? success(response.access_token) : failure("Incorrect token format");
|
|
126
126
|
}
|
|
127
127
|
function safeParseTestResponse(response) {
|
|
128
|
-
return response?.result?.userId ? success(
|
|
128
|
+
return response?.result?.userId ? success("Connection successful") : failure("Incorrect test response format");
|
|
129
129
|
}
|
|
130
130
|
function safeParseStartFileExportResponse(response) {
|
|
131
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`);
|
|
@@ -149,8 +149,10 @@ async function execute(config) {
|
|
|
149
149
|
signal: controller.signal
|
|
150
150
|
};
|
|
151
151
|
if (body) {
|
|
152
|
-
if (typeof body === "string")
|
|
152
|
+
if (typeof body === "string") {
|
|
153
153
|
headers.append("Content-Type", "application/json");
|
|
154
|
+
headers.append("Accept", "application/json");
|
|
155
|
+
}
|
|
154
156
|
options.method = "POST";
|
|
155
157
|
options.headers = headers;
|
|
156
158
|
options.body = body;
|
|
@@ -162,7 +164,7 @@ async function execute(config) {
|
|
|
162
164
|
const data = await response.json();
|
|
163
165
|
return Promise.resolve(data);
|
|
164
166
|
} else {
|
|
165
|
-
const message = await response.
|
|
167
|
+
const message = await response.json();
|
|
166
168
|
return Promise.reject(`${response.status}: ${message}`);
|
|
167
169
|
}
|
|
168
170
|
}
|
|
@@ -246,8 +248,10 @@ var startResponseExport = (connectionOptions) => async ({
|
|
|
246
248
|
try {
|
|
247
249
|
const headers = getAuthHeaders(connectionOptions.apiToken, bearerToken);
|
|
248
250
|
const body = JSON.stringify({
|
|
249
|
-
startDate:
|
|
250
|
-
|
|
251
|
+
startDate: "2024-03-01T06:00:00Z",
|
|
252
|
+
//startDate.toISOString(),
|
|
253
|
+
endDate: "2024-03-05T06:00:00Z",
|
|
254
|
+
//endDate.toISOString(),
|
|
251
255
|
format,
|
|
252
256
|
...rest
|
|
253
257
|
});
|
|
@@ -291,6 +295,7 @@ var testConnection = (connectionOptions) => async (bearerToken) => {
|
|
|
291
295
|
var createConnection = (options) => ({
|
|
292
296
|
exportResponses: exportResponses(options),
|
|
293
297
|
getBearerToken: getBearerToken(options),
|
|
298
|
+
getResponseExportFile: getResponseExportFile(options),
|
|
294
299
|
getResponseExportProgress: getResponseExportProgress(options),
|
|
295
300
|
startResponseExport: startResponseExport(options),
|
|
296
301
|
testConnection: testConnection(options)
|
package/dist/index.mjs
CHANGED
|
@@ -93,7 +93,7 @@ function safeParseBearerToken(response) {
|
|
|
93
93
|
return response?.access_token && typeof response.access_token === "string" ? success(response.access_token) : failure("Incorrect token format");
|
|
94
94
|
}
|
|
95
95
|
function safeParseTestResponse(response) {
|
|
96
|
-
return response?.result?.userId ? success(
|
|
96
|
+
return response?.result?.userId ? success("Connection successful") : failure("Incorrect test response format");
|
|
97
97
|
}
|
|
98
98
|
function safeParseStartFileExportResponse(response) {
|
|
99
99
|
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`);
|
|
@@ -117,8 +117,10 @@ async function execute(config) {
|
|
|
117
117
|
signal: controller.signal
|
|
118
118
|
};
|
|
119
119
|
if (body) {
|
|
120
|
-
if (typeof body === "string")
|
|
120
|
+
if (typeof body === "string") {
|
|
121
121
|
headers.append("Content-Type", "application/json");
|
|
122
|
+
headers.append("Accept", "application/json");
|
|
123
|
+
}
|
|
122
124
|
options.method = "POST";
|
|
123
125
|
options.headers = headers;
|
|
124
126
|
options.body = body;
|
|
@@ -130,7 +132,7 @@ async function execute(config) {
|
|
|
130
132
|
const data = await response.json();
|
|
131
133
|
return Promise.resolve(data);
|
|
132
134
|
} else {
|
|
133
|
-
const message = await response.
|
|
135
|
+
const message = await response.json();
|
|
134
136
|
return Promise.reject(`${response.status}: ${message}`);
|
|
135
137
|
}
|
|
136
138
|
}
|
|
@@ -214,8 +216,10 @@ var startResponseExport = (connectionOptions) => async ({
|
|
|
214
216
|
try {
|
|
215
217
|
const headers = getAuthHeaders(connectionOptions.apiToken, bearerToken);
|
|
216
218
|
const body = JSON.stringify({
|
|
217
|
-
startDate:
|
|
218
|
-
|
|
219
|
+
startDate: "2024-03-01T06:00:00Z",
|
|
220
|
+
//startDate.toISOString(),
|
|
221
|
+
endDate: "2024-03-05T06:00:00Z",
|
|
222
|
+
//endDate.toISOString(),
|
|
219
223
|
format,
|
|
220
224
|
...rest
|
|
221
225
|
});
|
|
@@ -259,6 +263,7 @@ var testConnection = (connectionOptions) => async (bearerToken) => {
|
|
|
259
263
|
var createConnection = (options) => ({
|
|
260
264
|
exportResponses: exportResponses(options),
|
|
261
265
|
getBearerToken: getBearerToken(options),
|
|
266
|
+
getResponseExportFile: getResponseExportFile(options),
|
|
262
267
|
getResponseExportProgress: getResponseExportProgress(options),
|
|
263
268
|
startResponseExport: startResponseExport(options),
|
|
264
269
|
testConnection: testConnection(options)
|
package/package.json
CHANGED
package/tests/utils.test.ts
CHANGED
|
@@ -126,7 +126,7 @@ describe('safeParseTestResponse', () => {
|
|
|
126
126
|
|
|
127
127
|
it('should pass with correct data', () => {
|
|
128
128
|
const res = fixture
|
|
129
|
-
const expected = success(
|
|
129
|
+
const expected = success('Connection successful')
|
|
130
130
|
const parsed = safeParseTestResponse(res)
|
|
131
131
|
expect(parsed).toStrictEqual(expected)
|
|
132
132
|
})
|