@qualtrics/plugin-client 1.8.19

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.
Files changed (49) hide show
  1. package/create-npm-package.js +39 -0
  2. package/dist/package.json +33 -0
  3. package/dist/src/constants.d.ts +12 -0
  4. package/dist/src/constants.js +21 -0
  5. package/dist/src/constants.js.map +1 -0
  6. package/dist/src/deferred.d.ts +6 -0
  7. package/dist/src/deferred.js +28 -0
  8. package/dist/src/deferred.js.map +1 -0
  9. package/dist/src/errors/encoder.d.ts +15 -0
  10. package/dist/src/errors/encoder.js +130 -0
  11. package/dist/src/errors/encoder.js.map +1 -0
  12. package/dist/src/errors/errorMessages.d.ts +4 -0
  13. package/dist/src/errors/errorMessages.js +14 -0
  14. package/dist/src/errors/errorMessages.js.map +1 -0
  15. package/dist/src/errors/errorTypes.d.ts +67 -0
  16. package/dist/src/errors/errorTypes.js +166 -0
  17. package/dist/src/errors/errorTypes.js.map +1 -0
  18. package/dist/src/errors/interfaceValidator.d.ts +30 -0
  19. package/dist/src/errors/interfaceValidator.js +54 -0
  20. package/dist/src/errors/interfaceValidator.js.map +1 -0
  21. package/dist/src/lib/messages/messageChannel.d.ts +126 -0
  22. package/dist/src/lib/messages/messageChannel.js +390 -0
  23. package/dist/src/lib/messages/messageChannel.js.map +1 -0
  24. package/dist/src/lib/plugin/buildConfig.d.ts +1 -0
  25. package/dist/src/lib/plugin/buildConfig.js +3 -0
  26. package/dist/src/lib/plugin/buildConfig.js.map +1 -0
  27. package/dist/src/lib/plugin/index.d.ts +3 -0
  28. package/dist/src/lib/plugin/index.js +4 -0
  29. package/dist/src/lib/plugin/index.js.map +1 -0
  30. package/dist/src/lib/plugin/models.d.ts +13 -0
  31. package/dist/src/lib/plugin/models.js +9 -0
  32. package/dist/src/lib/plugin/models.js.map +1 -0
  33. package/dist/src/lib/plugin/pluginClient.d.ts +155 -0
  34. package/dist/src/lib/plugin/pluginClient.js +436 -0
  35. package/dist/src/lib/plugin/pluginClient.js.map +1 -0
  36. package/dist/src/lib/plugin/translations.d.ts +15 -0
  37. package/dist/src/lib/plugin/translations.js +49 -0
  38. package/dist/src/lib/plugin/translations.js.map +1 -0
  39. package/dist/src/modelUtils.d.ts +6 -0
  40. package/dist/src/modelUtils.js +21 -0
  41. package/dist/src/modelUtils.js.map +1 -0
  42. package/dist/src/models.d.ts +125 -0
  43. package/dist/src/models.js +130 -0
  44. package/dist/src/models.js.map +1 -0
  45. package/dist/src/utils.d.ts +3 -0
  46. package/dist/src/utils.js +23 -0
  47. package/dist/src/utils.js.map +1 -0
  48. package/package.json +25 -0
  49. package/tsconfig.json +16 -0
@@ -0,0 +1,155 @@
1
+ import { Context, FetchResponse, MessageData, SerializableRecord, UserProvidedFetchConfig, UserProvidedQualtricsApiFetchConfig } from "../../models";
2
+ import { Handler } from "./models";
3
+ declare class PluginClient {
4
+ private readonly context;
5
+ private channel;
6
+ private translator?;
7
+ private constructor();
8
+ static initialize(handlers?: Record<string, Handler>): Promise<PluginClient>;
9
+ destroy(): void;
10
+ postMessage(name: string, data?: MessageData, timeout?: number): Promise<MessageData>;
11
+ /**
12
+ * Sends a request to the provided URL. Injects user defined account for authentication
13
+ * if specified in connection property.
14
+ *
15
+ * fetchConfig should be formatted as follows:
16
+ * {
17
+ * method {string}: the http method to use (ex: 'POST', 'GET, 'PUT', etc.)
18
+ * headers {object} (optional): key/value pairs that correspond to headers to add to the request (ex: "Content-Type": "application/json")
19
+ * body {object | string} (optional): the body of the request
20
+ * params {object} (optional): key/value pairs that correspond query params to add to the request URL (ex: "filter": "random")
21
+ * connection {object} (optional): {
22
+ * connectionName {string}: the name of the connection to use (see context.availableConnections for a list of connections).
23
+ * paramFormat {string}: where to place the credential. Can be 'header','body', or 'query'.
24
+ * paramName {string}: what to name the credential param. As in, the field name for a body param, the query name for a query param, or the header name for a header. Ex: for a bearer token this might be "Authorization".
25
+ * paramTemplate {string}: what to insert the credential as. Use it similarly to a string passed to String.format. EX: "Bearer %s" would be a template for bearer tokens, "%s" inserts the token as-is.
26
+ * }
27
+ * }
28
+ * @param {string} url - The URL to make a request to
29
+ * @param {object} fetchConfig - Configures all aspects of the request
30
+ * @param {number} timeout - Defaults to 10000 (10 seconds). Specifies the number of milliseconds at which to reject the returned promise if no response has been received from the Plugin.
31
+ * @returns {Promise} resolves to an object containing {responseBody: JSON string, httpStatusCode: string}
32
+ */
33
+ fetch(url: string, fetchConfig: UserProvidedFetchConfig, timeout?: number): Promise<MessageData>;
34
+ /**
35
+ * The exciting sequel to `fetch`
36
+ *
37
+ * Sends a request to the provided URL. Injects user defined account for authentication
38
+ * if specified in connection property.
39
+ *
40
+ * fetchConfig should be formatted as follows:
41
+ * {
42
+ * method {string}: the http method to use (ex: 'POST', 'GET, 'PUT', etc.)
43
+ * headers {object} (optional): key/value pairs that correspond to headers to add to the request (ex: "Content-Type": "application/json")
44
+ * body {object | string} (optional): the body of the request
45
+ * params {object} (optional): key/value pairs that correspond query params to add to the request URL (ex: "filter": "random")
46
+ * connection {object} (optional): {
47
+ * connectionName {string}: the name of the connection to use (see context.availableConnections for a list of connections).
48
+ * paramFormat {string}: where to place the credential. Can be 'header','body', or 'query'.
49
+ * paramName {string}: what to name the credential param. As in, the field name for a body param, the query name for a query param, or the header name for a header. Ex: for a bearer token this might be "Authorization".
50
+ * paramTemplate {string}: what to insert the credential as. Use it similarly to a string passed to String.format. EX: "Bearer %s" would be a template for bearer tokens, "%s" inserts the token as-is.
51
+ * }
52
+ * }
53
+ *
54
+ * Promise resolves to either a successful FetchResponse or throws a FetchError. Both
55
+ * contain a `status` prop for checking the status code and a `responseData` property that
56
+ * contains whatever the response has. This could be more information on the Error that
57
+ * occurred or the data that was requested.
58
+ *
59
+ * Successful response example:
60
+ * {
61
+ * status: 200
62
+ * responseData: {
63
+ * ... // data from the 3rd party service
64
+ * }
65
+ * }
66
+ *
67
+ * Error response Example:
68
+ * Uncaught Error: "GET https://pokeapi.co/api/v2/pokemon/porkachu/ 404 Not Found"
69
+ * {
70
+ * status: 404
71
+ * responseData: "404 - Not Found"
72
+ * }
73
+ *
74
+ * @param {string} url - The URL to make a request to
75
+ * @param {object} fetchConfig - Configures all aspects of the request
76
+ * @param {number} timeout - Defaults to 10000 (10 seconds). Specifies the number of milliseconds at which to reject the returned promise if no response has been received from the Plugin.
77
+ * @returns {Promise} response from the service
78
+ */
79
+ fetch2(url: string, fetchConfig: UserProvidedFetchConfig, timeout?: number): Promise<FetchResponse>;
80
+ private isJSON;
81
+ /**
82
+ * Make a request to Qualtrics Public API. Similar to fetch, but doesn't accept a connection.
83
+ *
84
+ * The config should be formatted as follows:
85
+ * {
86
+ * method {string}: the http method to use (ex: 'POST', 'GET, 'PUT', etc.)
87
+ * body {object | string} (optional): the body of the request
88
+ * }
89
+ * @param {string} url - The relative Qualtrics API path to make a request to, such as `surveys`
90
+ * @param {object} config - Configures all aspects of the request
91
+ * @param {number} timeout - Defaults to 10000 (10 seconds). Specifies the number of milliseconds at which to reject the returned promise if no response has been received from the Plugin.
92
+ * @returns {Promise} - response from the API
93
+ */
94
+ qualtricsApiFetch(url: string, config: UserProvidedQualtricsApiFetchConfig, timeout?: number): Promise<SerializableRecord>;
95
+ /**
96
+ * The exciting sequel to `qualtricsApiFetch`
97
+ *
98
+ * Make a request to Qualtrics Public API. Similar to fetch, but doesn't accept a connection.
99
+ *
100
+ * The config should be formatted as follows:
101
+ * {
102
+ * method {string}: the http method to use (ex: 'POST', 'GET, 'PUT', etc.)
103
+ * body {object | string} (optional): the body of the request
104
+ * }
105
+ *
106
+ * Promise resolves to either a successful FetchResponse or throws a FetchError. Both
107
+ * contain a `status` prop for checking the status code and a `responseData` property that
108
+ * contains whatever the response has. This could be more information on the Error that
109
+ * occurred or the data that was requested.
110
+ *
111
+ * Successful response example:
112
+ * {
113
+ * status: 200
114
+ * responseData: {
115
+ * meta: {
116
+ * httpStatus: "200 - OK"
117
+ * requestId: "c0bf74f9-7119-47c1-99bf-3d2353032d11"
118
+ * }
119
+ * result: {
120
+ * elements: [...] //surveys
121
+ * nextPage: null
122
+ * }
123
+ * }
124
+ * }
125
+ *
126
+ * Error response Example:
127
+ * Uncaught Error: "GET /API/v3/surveys/SV_notarealid 400 Bad Request"
128
+ * {
129
+ * status: 400
130
+ * responseData: {
131
+ * meta: {
132
+ * httpStatus: "400 - Bad Request"
133
+ * error: {
134
+ * errorMessage: "Invalid surveyId."
135
+ * errorCode: "GSI_1"
136
+ * }
137
+ * }
138
+ * requestId: "41885efc-4ecf-41db-890b-9e3d5222112a"
139
+ * }
140
+ * }
141
+ * }
142
+ * @param {string} url - The relative Qualtrics API path to make a request to, such as `surveys`
143
+ * @param {object} config - Configures all aspects of the request
144
+ * @param {number} timeout - Defaults to 10000 (10 seconds). Specifies the number of milliseconds at which to reject the returned promise if no response has been received from the Plugin.
145
+ * @returns {Promise} - response from the API.
146
+ */
147
+ qualtricsApiFetch2(url: string, config: UserProvidedQualtricsApiFetchConfig, timeout?: number): Promise<FetchResponse>;
148
+ logAmplitudeEvent(eventNamespace: string, eventName: string, eventData?: Record<string, unknown>): Promise<MessageData>;
149
+ private validateFetchInput;
150
+ private removeLeadingSlash;
151
+ getContext(): Context;
152
+ getLanguage(): string;
153
+ getText(key: string, placeHolders?: Record<string, string>, defaultVal?: string): string;
154
+ }
155
+ export default PluginClient;
@@ -0,0 +1,436 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __generator = (this && this.__generator) || function (thisArg, body) {
22
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
+ function verb(n) { return function (v) { return step([n, v]); }; }
25
+ function step(op) {
26
+ if (f) throw new TypeError("Generator is already executing.");
27
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
+ if (y = 0, t) op = [op[0] & 2, t.value];
30
+ switch (op[0]) {
31
+ case 0: case 1: t = op; break;
32
+ case 4: _.label++; return { value: op[1], done: false };
33
+ case 5: _.label++; y = op[1]; op = [0]; continue;
34
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
+ default:
36
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
+ if (t[2]) _.ops.pop();
41
+ _.trys.pop(); continue;
42
+ }
43
+ op = body.call(thisArg, _);
44
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
+ }
47
+ };
48
+ import * as t from 'io-ts';
49
+ import * as Errors from "../../errors/errorMessages";
50
+ import { FetchError } from "../../errors/errorTypes";
51
+ import { EgressResponse, isContext, SerializableRecord, UserProvidedFetchConfig, UserProvidedQualtricsApiFetchConfig, } from "../../models";
52
+ import { isPresent, NonEmptyString, OptionalArg } from "../../modelUtils";
53
+ import MessageChannel from "../messages/messageChannel";
54
+ import { getClientVersion } from "./buildConfig";
55
+ import { PluginClientHandlerCollection } from "./models";
56
+ import Translator from './translations';
57
+ var referrer = document.referrer ? new URL(document.referrer).origin : null;
58
+ window.Promise = window.Promise || Promise;
59
+ var LONG_TIMEOUT = 10000;
60
+ var INIT_EVENT = 'init';
61
+ var PluginClient = /** @class */ (function () {
62
+ function PluginClient(context, channel) {
63
+ this.context = context;
64
+ this.channel = channel;
65
+ if (this.context.translations) {
66
+ this.translator = new Translator(this.context.translations);
67
+ }
68
+ }
69
+ // Factory method. Fetches context before constructing and returning the plugin client.
70
+ PluginClient.initialize = function (handlers) {
71
+ if (handlers === void 0) { handlers = {}; }
72
+ return __awaiter(this, void 0, void 0, function () {
73
+ var channel, initMessage, maybeContext, context, pluginClient, getWrappedHandler, _i, _a, name_1;
74
+ return __generator(this, function (_b) {
75
+ switch (_b.label) {
76
+ case 0:
77
+ if (!PluginClientHandlerCollection.is(handlers)) {
78
+ throw Errors.invalidParameter('handlers', 'Must be a collection of functions');
79
+ }
80
+ channel = new MessageChannel({
81
+ name: 'plugin',
82
+ other: window.parent,
83
+ otherOrigin: referrer,
84
+ });
85
+ initMessage = { clientVersion: getClientVersion() };
86
+ return [4 /*yield*/, channel.postMessage(INIT_EVENT, initMessage)];
87
+ case 1:
88
+ maybeContext = _b.sent();
89
+ if (!isContext(maybeContext)) {
90
+ throw new Error("init message replied with an invalid context: ".concat(typeof maybeContext === 'object' && maybeContext
91
+ ? JSON.stringify(maybeContext)
92
+ : typeof maybeContext));
93
+ }
94
+ context = maybeContext;
95
+ channel.setInstanceId(context.instanceID);
96
+ pluginClient = new PluginClient(context, channel);
97
+ getWrappedHandler = function (handler, pluginClient) {
98
+ return function (data) { return handler(data, pluginClient); };
99
+ };
100
+ // wrap each of the provided handlers and register them to the channel
101
+ for (_i = 0, _a = Object.getOwnPropertyNames(handlers); _i < _a.length; _i++) {
102
+ name_1 = _a[_i];
103
+ channel.registerHandler(name_1, getWrappedHandler(handlers[name_1], pluginClient));
104
+ }
105
+ return [2 /*return*/, pluginClient];
106
+ }
107
+ });
108
+ });
109
+ };
110
+ PluginClient.prototype.destroy = function () {
111
+ // Disconnect message channel
112
+ if (this.channel) {
113
+ this.channel.destroy();
114
+ }
115
+ };
116
+ /*
117
+ Generic post message to the parent window. Returns a promise to be resolved once the host replies.
118
+ */
119
+ PluginClient.prototype.postMessage = function (name, data, timeout) {
120
+ if (timeout === void 0) { timeout = LONG_TIMEOUT; }
121
+ return this.channel.postMessage(name, data, timeout);
122
+ };
123
+ /**
124
+ * Sends a request to the provided URL. Injects user defined account for authentication
125
+ * if specified in connection property.
126
+ *
127
+ * fetchConfig should be formatted as follows:
128
+ * {
129
+ * method {string}: the http method to use (ex: 'POST', 'GET, 'PUT', etc.)
130
+ * headers {object} (optional): key/value pairs that correspond to headers to add to the request (ex: "Content-Type": "application/json")
131
+ * body {object | string} (optional): the body of the request
132
+ * params {object} (optional): key/value pairs that correspond query params to add to the request URL (ex: "filter": "random")
133
+ * connection {object} (optional): {
134
+ * connectionName {string}: the name of the connection to use (see context.availableConnections for a list of connections).
135
+ * paramFormat {string}: where to place the credential. Can be 'header','body', or 'query'.
136
+ * paramName {string}: what to name the credential param. As in, the field name for a body param, the query name for a query param, or the header name for a header. Ex: for a bearer token this might be "Authorization".
137
+ * paramTemplate {string}: what to insert the credential as. Use it similarly to a string passed to String.format. EX: "Bearer %s" would be a template for bearer tokens, "%s" inserts the token as-is.
138
+ * }
139
+ * }
140
+ * @param {string} url - The URL to make a request to
141
+ * @param {object} fetchConfig - Configures all aspects of the request
142
+ * @param {number} timeout - Defaults to 10000 (10 seconds). Specifies the number of milliseconds at which to reject the returned promise if no response has been received from the Plugin.
143
+ * @returns {Promise} resolves to an object containing {responseBody: JSON string, httpStatusCode: string}
144
+ */
145
+ PluginClient.prototype.fetch = function (url, fetchConfig, timeout) {
146
+ if (timeout === void 0) { timeout = LONG_TIMEOUT; }
147
+ return __awaiter(this, void 0, void 0, function () {
148
+ var fetchMessage;
149
+ return __generator(this, function (_a) {
150
+ this.validateFetchInput(url, timeout);
151
+ if (!isPresent(fetchConfig)) {
152
+ throw Errors.missingVariable('fetchConfig');
153
+ }
154
+ if (!UserProvidedFetchConfig.is(fetchConfig)) {
155
+ throw Errors.invalidInterface('fetchConfig', UserProvidedFetchConfig, fetchConfig);
156
+ }
157
+ fetchMessage = __assign(__assign({}, fetchConfig), { url: url });
158
+ return [2 /*return*/, this.channel.postMessage('fetch', fetchMessage, timeout)];
159
+ });
160
+ });
161
+ };
162
+ /**
163
+ * The exciting sequel to `fetch`
164
+ *
165
+ * Sends a request to the provided URL. Injects user defined account for authentication
166
+ * if specified in connection property.
167
+ *
168
+ * fetchConfig should be formatted as follows:
169
+ * {
170
+ * method {string}: the http method to use (ex: 'POST', 'GET, 'PUT', etc.)
171
+ * headers {object} (optional): key/value pairs that correspond to headers to add to the request (ex: "Content-Type": "application/json")
172
+ * body {object | string} (optional): the body of the request
173
+ * params {object} (optional): key/value pairs that correspond query params to add to the request URL (ex: "filter": "random")
174
+ * connection {object} (optional): {
175
+ * connectionName {string}: the name of the connection to use (see context.availableConnections for a list of connections).
176
+ * paramFormat {string}: where to place the credential. Can be 'header','body', or 'query'.
177
+ * paramName {string}: what to name the credential param. As in, the field name for a body param, the query name for a query param, or the header name for a header. Ex: for a bearer token this might be "Authorization".
178
+ * paramTemplate {string}: what to insert the credential as. Use it similarly to a string passed to String.format. EX: "Bearer %s" would be a template for bearer tokens, "%s" inserts the token as-is.
179
+ * }
180
+ * }
181
+ *
182
+ * Promise resolves to either a successful FetchResponse or throws a FetchError. Both
183
+ * contain a `status` prop for checking the status code and a `responseData` property that
184
+ * contains whatever the response has. This could be more information on the Error that
185
+ * occurred or the data that was requested.
186
+ *
187
+ * Successful response example:
188
+ * {
189
+ * status: 200
190
+ * responseData: {
191
+ * ... // data from the 3rd party service
192
+ * }
193
+ * }
194
+ *
195
+ * Error response Example:
196
+ * Uncaught Error: "GET https://pokeapi.co/api/v2/pokemon/porkachu/ 404 Not Found"
197
+ * {
198
+ * status: 404
199
+ * responseData: "404 - Not Found"
200
+ * }
201
+ *
202
+ * @param {string} url - The URL to make a request to
203
+ * @param {object} fetchConfig - Configures all aspects of the request
204
+ * @param {number} timeout - Defaults to 10000 (10 seconds). Specifies the number of milliseconds at which to reject the returned promise if no response has been received from the Plugin.
205
+ * @returns {Promise} response from the service
206
+ */
207
+ PluginClient.prototype.fetch2 = function (url, fetchConfig, timeout) {
208
+ if (timeout === void 0) { timeout = LONG_TIMEOUT; }
209
+ return __awaiter(this, void 0, void 0, function () {
210
+ var res, fetchResponse;
211
+ return __generator(this, function (_a) {
212
+ switch (_a.label) {
213
+ case 0: return [4 /*yield*/, this.fetch(url, fetchConfig, timeout)
214
+ // appeases TS - this error more than likely will never get thrown
215
+ ];
216
+ case 1:
217
+ res = _a.sent();
218
+ // appeases TS - this error more than likely will never get thrown
219
+ if (!EgressResponse.is(res)) {
220
+ throw new Error("Response from fetch is not an Egress Response. Instead received ".concat(typeof res));
221
+ }
222
+ fetchResponse = {
223
+ status: res.httpStatusCode,
224
+ responseData: this.isJSON(res.responseBody) ? JSON.parse(res.responseBody) : res.responseBody,
225
+ responseHeaders: res.responseHeaders,
226
+ };
227
+ return [2 /*return*/, fetchResponse];
228
+ }
229
+ });
230
+ });
231
+ };
232
+ /* credit: https://github.com/lodash/lodash/issues/2142 */
233
+ PluginClient.prototype.isJSON = function (string) {
234
+ try {
235
+ var obj = JSON.parse(string);
236
+ if (obj && typeof obj === 'object' && obj !== null) {
237
+ return true;
238
+ }
239
+ // eslint-disable-next-line no-empty
240
+ }
241
+ catch (err) { }
242
+ return false;
243
+ };
244
+ /**
245
+ * Make a request to Qualtrics Public API. Similar to fetch, but doesn't accept a connection.
246
+ *
247
+ * The config should be formatted as follows:
248
+ * {
249
+ * method {string}: the http method to use (ex: 'POST', 'GET, 'PUT', etc.)
250
+ * body {object | string} (optional): the body of the request
251
+ * }
252
+ * @param {string} url - The relative Qualtrics API path to make a request to, such as `surveys`
253
+ * @param {object} config - Configures all aspects of the request
254
+ * @param {number} timeout - Defaults to 10000 (10 seconds). Specifies the number of milliseconds at which to reject the returned promise if no response has been received from the Plugin.
255
+ * @returns {Promise} - response from the API
256
+ */
257
+ PluginClient.prototype.qualtricsApiFetch = function (url, config, timeout) {
258
+ if (timeout === void 0) { timeout = LONG_TIMEOUT; }
259
+ return __awaiter(this, void 0, void 0, function () {
260
+ var qualtricsApiFetchMessage, response;
261
+ return __generator(this, function (_a) {
262
+ switch (_a.label) {
263
+ case 0:
264
+ this.validateFetchInput(url, timeout);
265
+ if (!isPresent(config)) {
266
+ throw Errors.missingVariable('config');
267
+ }
268
+ if (!UserProvidedQualtricsApiFetchConfig.is(config)) {
269
+ throw Errors.invalidInterface('config', UserProvidedQualtricsApiFetchConfig, config);
270
+ }
271
+ url = this.removeLeadingSlash(url);
272
+ qualtricsApiFetchMessage = __assign(__assign({}, config), { url: url });
273
+ return [4 /*yield*/, this.channel.postMessage('apiv3', qualtricsApiFetchMessage, timeout)];
274
+ case 1:
275
+ response = _a.sent();
276
+ if (!SerializableRecord.is(response)) {
277
+ throw new Error("Response From API v3 is not a record. Instead received ".concat(typeof response === 'object' && response ? JSON.stringify(response) : 'unknown type'));
278
+ }
279
+ return [2 /*return*/, response];
280
+ }
281
+ });
282
+ });
283
+ };
284
+ /**
285
+ * The exciting sequel to `qualtricsApiFetch`
286
+ *
287
+ * Make a request to Qualtrics Public API. Similar to fetch, but doesn't accept a connection.
288
+ *
289
+ * The config should be formatted as follows:
290
+ * {
291
+ * method {string}: the http method to use (ex: 'POST', 'GET, 'PUT', etc.)
292
+ * body {object | string} (optional): the body of the request
293
+ * }
294
+ *
295
+ * Promise resolves to either a successful FetchResponse or throws a FetchError. Both
296
+ * contain a `status` prop for checking the status code and a `responseData` property that
297
+ * contains whatever the response has. This could be more information on the Error that
298
+ * occurred or the data that was requested.
299
+ *
300
+ * Successful response example:
301
+ * {
302
+ * status: 200
303
+ * responseData: {
304
+ * meta: {
305
+ * httpStatus: "200 - OK"
306
+ * requestId: "c0bf74f9-7119-47c1-99bf-3d2353032d11"
307
+ * }
308
+ * result: {
309
+ * elements: [...] //surveys
310
+ * nextPage: null
311
+ * }
312
+ * }
313
+ * }
314
+ *
315
+ * Error response Example:
316
+ * Uncaught Error: "GET /API/v3/surveys/SV_notarealid 400 Bad Request"
317
+ * {
318
+ * status: 400
319
+ * responseData: {
320
+ * meta: {
321
+ * httpStatus: "400 - Bad Request"
322
+ * error: {
323
+ * errorMessage: "Invalid surveyId."
324
+ * errorCode: "GSI_1"
325
+ * }
326
+ * }
327
+ * requestId: "41885efc-4ecf-41db-890b-9e3d5222112a"
328
+ * }
329
+ * }
330
+ * }
331
+ * @param {string} url - The relative Qualtrics API path to make a request to, such as `surveys`
332
+ * @param {object} config - Configures all aspects of the request
333
+ * @param {number} timeout - Defaults to 10000 (10 seconds). Specifies the number of milliseconds at which to reject the returned promise if no response has been received from the Plugin.
334
+ * @returns {Promise} - response from the API.
335
+ */
336
+ PluginClient.prototype.qualtricsApiFetch2 = function (url, config, timeout) {
337
+ if (timeout === void 0) { timeout = LONG_TIMEOUT; }
338
+ return __awaiter(this, void 0, void 0, function () {
339
+ var res, status, errorMessage, fetchResponse;
340
+ return __generator(this, function (_a) {
341
+ switch (_a.label) {
342
+ case 0: return [4 /*yield*/, this.qualtricsApiFetch(url, config, timeout)
343
+ // required typeguard to appease TS
344
+ ];
345
+ case 1:
346
+ res = _a.sent();
347
+ // required typeguard to appease TS
348
+ if (!(res === null || res === void 0 ? void 0 : res.status) || !(typeof (res === null || res === void 0 ? void 0 : res.status) === 'number')) {
349
+ throw new Error('Fetch response received is missing a status code.');
350
+ }
351
+ if (!(res === null || res === void 0 ? void 0 : res.statusText) || !(typeof (res === null || res === void 0 ? void 0 : res.statusText) === 'string')) {
352
+ throw new Error('Fetch response received is missing a status text.');
353
+ }
354
+ status = res.status;
355
+ // if there's an error on the request, the messageChannel promise won't reject, so it
356
+ // has to be manually checked for and thrown here
357
+ if (status > 299 || status < 200) {
358
+ errorMessage = "".concat(config.method, " /API/v3/").concat(url, " ").concat(status, " ").concat(res.statusText);
359
+ throw new FetchError(errorMessage, status, res.data);
360
+ }
361
+ fetchResponse = {
362
+ status: res.status,
363
+ responseData: res.data,
364
+ };
365
+ return [2 /*return*/, fetchResponse];
366
+ }
367
+ });
368
+ });
369
+ };
370
+ PluginClient.prototype.logAmplitudeEvent = function (eventNamespace, eventName, eventData) {
371
+ if (eventData === void 0) { eventData = {}; }
372
+ return __awaiter(this, void 0, void 0, function () {
373
+ return __generator(this, function (_a) {
374
+ return [2 /*return*/, this.channel.postMessage('logAmplitudeEvent', {
375
+ eventNamespace: eventNamespace,
376
+ eventName: eventName,
377
+ eventData: eventData,
378
+ }, LONG_TIMEOUT)];
379
+ });
380
+ });
381
+ };
382
+ /*
383
+ Validates expectations for the input to the fetch functions. Throws an error if any issues are detected.
384
+ Accepts isApiFetch to modify checks for qualtricsApiFetch; defaults to false.
385
+ */
386
+ PluginClient.prototype.validateFetchInput = function (url, timeout) {
387
+ if (!isPresent(url)) {
388
+ throw Errors.missingVariable('url');
389
+ }
390
+ if (!NonEmptyString.is(url)) {
391
+ throw Errors.invalidParameter('url', 'Must be a non-empty string');
392
+ }
393
+ if (!t.number.is(timeout)) {
394
+ throw Errors.invalidParameter('timeout', 'Must be an integer');
395
+ }
396
+ };
397
+ PluginClient.prototype.removeLeadingSlash = function (url) {
398
+ if (url.startsWith('/')) {
399
+ return url.substring(1);
400
+ }
401
+ return url;
402
+ };
403
+ /*
404
+ Returns the context object that was given by the host on init.
405
+ */
406
+ PluginClient.prototype.getContext = function () {
407
+ return this.context;
408
+ };
409
+ /*
410
+ Returns the language code of the logged in user given by the host on init.
411
+ */
412
+ PluginClient.prototype.getLanguage = function () {
413
+ return this.context.language;
414
+ };
415
+ PluginClient.prototype.getText = function (key, placeHolders, defaultVal) {
416
+ if (!isPresent(key)) {
417
+ throw Errors.missingVariable('key');
418
+ }
419
+ if (!NonEmptyString.is(key)) {
420
+ throw Errors.invalidParameter('key', 'Must be a non-empty string');
421
+ }
422
+ if (!OptionalArg(t.record(t.string, t.string)).is(placeHolders)) {
423
+ throw Errors.invalidParameter('placeHolders', 'Must be a collection of strings if present');
424
+ }
425
+ if (!OptionalArg(NonEmptyString).is(defaultVal)) {
426
+ throw Errors.invalidParameter('defaultValue', 'Must be non-empty string if provided');
427
+ }
428
+ if (!this.translator) {
429
+ throw new Error('Translation file not found');
430
+ }
431
+ return this.translator.getText(key, placeHolders, defaultVal);
432
+ };
433
+ return PluginClient;
434
+ }());
435
+ export default PluginClient;
436
+ //# sourceMappingURL=pluginClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pluginClient.js","sourceRoot":"","sources":["../../../../../plugin-sdk/src/lib/plugin/pluginClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,KAAK,CAAC,MAAM,OAAO,CAAA;AAE1B,OAAO,KAAK,MAAM,mCAAiC;AACnD,OAAO,EAAC,UAAU,EAAC,gCAA8B;AACjD,OAAO,EAGL,cAAc,EAGd,SAAS,EAET,kBAAkB,EAClB,uBAAuB,EACvB,mCAAmC,GACpC,qBAAmB;AACpB,OAAO,EAAC,SAAS,EAAE,cAAc,EAAE,WAAW,EAAC,yBAAuB;AACtE,OAAO,cAAc,mCAAgC;AACrD,OAAO,EAAC,gBAAgB,EAAC,sBAA2B;AACpD,OAAO,EAAU,6BAA6B,EAAC,iBAAsB;AACrE,OAAO,UAAU,MAAM,gBAAgB,CAAA;AAEvC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AAC;IAED;;MAEE;IACF,kCAAW,GAAX;QACE,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAA;IAC9B,CAAC;IAED,8BAAO,GAAP,UAAQ,GAAW,EAAE,YAAqC,EAAE,UAAmB;QAC7E,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC;YACpB,MAAM,MAAM,CAAC,eAAe,CAAC,KAAK,CAAC,CAAA;QACrC,CAAC;QACD,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC;YAC5B,MAAM,MAAM,CAAC,gBAAgB,CAAC,KAAK,EAAE,4BAA4B,CAAC,CAAA;QACpE,CAAC;QACD,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,YAAY,CAAC,EAAE,CAAC;YAChE,MAAM,MAAM,CAAC,gBAAgB,CAAC,cAAc,EAAE,4CAA4C,CAAC,CAAA;QAC7F,CAAC;QACD,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC;YAChD,MAAM,MAAM,CAAC,gBAAgB,CAAC,cAAc,EAAE,sCAAsC,CAAC,CAAA;QACvF,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAA;QAC/C,CAAC;QACD,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,EAAE,YAAY,EAAE,UAAU,CAAC,CAAA;IAC/D,CAAC;IACH,mBAAC;AAAD,CAAC,AAzXD,IAyXC;AAED,eAAe,YAAY,CAAA"}
@@ -0,0 +1,15 @@
1
+ import { TranslationFile, TranslationFileDeprecated } from "../../models";
2
+ declare class Translator {
3
+ private translationFile;
4
+ constructor(translationFile: TranslationFile | TranslationFileDeprecated);
5
+ getText(key: string, params?: Record<string, string>, defaultValue?: string): string;
6
+ private getTemplateOrDefault;
7
+ private getTemplate;
8
+ /**
9
+ * Replace placeholders like "{{foo}}" with the value specified in params['foo'].
10
+ *
11
+ * Placeholders without a value present in params are left untouched.
12
+ */
13
+ private static replacePlaceholders;
14
+ }
15
+ export default Translator;