@qualtrics/plugin-client
Advanced tools
Comparing version 1.9.12 to 1.9.13
{ | ||
"name": "@qualtrics/plugin-client", | ||
"version": "1.9.12", | ||
"version": "1.9.13", | ||
"description": "Interface for XM Plugins to communicate with the environment they're rendered in", | ||
@@ -5,0 +5,0 @@ "scripts": { |
// Provide configuration that is supplied at build time. | ||
export var getClientVersion = function () { return "1.9.12"; }; | ||
export var getClientVersion = function () { return "1.9.13"; }; | ||
//# sourceMappingURL=buildConfig.js.map |
@@ -1,2 +0,2 @@ | ||
import { Context, FetchResponse, MessageData, SerializableRecord, UserProvidedFetchConfig, UserProvidedPredefinedRequest, UserProvidedQualtricsApiFetchConfig } from "../../models"; | ||
import { Context, FetchResponse, MessageData, PluginCredentialData, SerializableRecord, UserProvidedFetchConfig, UserProvidedPredefinedRequest, UserProvidedQualtricsApiFetchConfig } from "../../models"; | ||
import { Handler } from "./models"; | ||
@@ -96,2 +96,4 @@ declare class PluginClient { | ||
invokePredefinedRequest(predefinedRequest: UserProvidedPredefinedRequest, timeout?: number): Promise<FetchResponse>; | ||
private isCredentialSelected; | ||
onCredentialStatusChange: (callback: (data: PluginCredentialData) => void) => void; | ||
private isJSON; | ||
@@ -98,0 +100,0 @@ /** |
@@ -51,3 +51,3 @@ var __assign = (this && this.__assign) || function () { | ||
import { FetchError } from "../../errors/errorTypes"; | ||
import { EgressResponse, isContext, SerializableRecord, UserProvidedFetchConfig, UserProvidedPredefinedRequest, UserProvidedQualtricsApiFetchConfig, } from "../../models"; | ||
import { CredentialStatus, EgressResponse, isContext, SerializableRecord, UserProvidedFetchConfig, UserProvidedPredefinedRequest, UserProvidedQualtricsApiFetchConfig, } from "../../models"; | ||
import { isPresent, NonEmptyString, OptionalArg } from "../../modelUtils"; | ||
@@ -64,4 +64,53 @@ import MessageChannel from "../messages/messageChannel"; | ||
function PluginClient(context, channel) { | ||
var _this = this; | ||
this.context = context; | ||
this.channel = channel; | ||
this.onCredentialStatusChange = function (callback) { | ||
var fetchInitialStatus = function () { return __awaiter(_this, void 0, void 0, function () { | ||
var status; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.isCredentialSelected()]; | ||
case 1: | ||
status = _a.sent(); | ||
return [2 /*return*/, { | ||
isCredentialSelected: status, | ||
credentialStatus: CredentialStatus.INITIALIZED, | ||
connections: this.context.connections, | ||
}]; | ||
} | ||
}); | ||
}); }; | ||
var initializeOnCredentialStatusChange = function () { return __awaiter(_this, void 0, void 0, function () { | ||
var initialData, _a, handleMessage; | ||
var _this = this; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
_b.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, fetchInitialStatus()]; | ||
case 1: | ||
initialData = _b.sent(); | ||
callback(initialData); | ||
return [3 /*break*/, 3]; | ||
case 2: | ||
_a = _b.sent(); | ||
throw new Error('Error fetching initial credential status'); | ||
case 3: | ||
handleMessage = function (message) { | ||
if (typeof message !== 'object' || !message) | ||
return; | ||
if (!('isCredentialSelected' in message) || !('credentialStatus' in message)) | ||
return; | ||
callback(message); | ||
}; | ||
this.channel.registerHandler('useCredentials', handleMessage); | ||
return [2 /*return*/, function () { | ||
_this.channel.removeHandler('useCredentials'); | ||
}]; | ||
} | ||
}); | ||
}); }; | ||
initializeOnCredentialStatusChange().catch(function () { }); | ||
}; | ||
if (this.context.translations) { | ||
@@ -260,2 +309,19 @@ this.translator = new Translator(this.context.translations); | ||
}; | ||
PluginClient.prototype.isCredentialSelected = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var response; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (!this.context.availableConnections.length) { | ||
return [2 /*return*/, false]; | ||
} | ||
return [4 /*yield*/, this.channel.postMessage('isCredentialSelected')]; | ||
case 1: | ||
response = _a.sent(); | ||
return [2 /*return*/, !!response]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/* credit: https://github.com/lodash/lodash/issues/2142 */ | ||
@@ -262,0 +328,0 @@ PluginClient.prototype.isJSON = function (string) { |
@@ -60,3 +60,3 @@ import * as t from 'io-ts'; | ||
/** | ||
* Invoke predefined request paramters provided by developer | ||
* Invoke predefined request parameters provided by developer | ||
*/ | ||
@@ -136,2 +136,13 @@ export declare const UserProvidedPredefinedRequest: t.IntersectionC<[t.TypeC<{ | ||
export type InitMessage = t.TypeOf<typeof InitMessage>; | ||
export declare enum CredentialStatus { | ||
INITIALIZED = "initialized", | ||
NEW = "new", | ||
DELETED = "deleted", | ||
UPDATED = "updated" | ||
} | ||
export type PluginCredentialData = { | ||
isCredentialSelected: boolean; | ||
credentialStatus: CredentialStatus; | ||
connections?: Context['connections']; | ||
}; | ||
export {}; |
@@ -58,3 +58,3 @@ // Common models across the plugin client and plugin manager. Every item | ||
/** | ||
* Invoke predefined request paramters provided by developer | ||
* Invoke predefined request parameters provided by developer | ||
*/ | ||
@@ -145,2 +145,9 @@ export var UserProvidedPredefinedRequest = t.intersection([ | ||
]); | ||
export var CredentialStatus; | ||
(function (CredentialStatus) { | ||
CredentialStatus["INITIALIZED"] = "initialized"; | ||
CredentialStatus["NEW"] = "new"; | ||
CredentialStatus["DELETED"] = "deleted"; | ||
CredentialStatus["UPDATED"] = "updated"; | ||
})(CredentialStatus || (CredentialStatus = {})); | ||
//# sourceMappingURL=models.js.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
133172
2218