Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@microsoft/omnichannel-amsclient

Package Overview
Dependencies
Maintainers
4
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@microsoft/omnichannel-amsclient - npm Package Compare versions

Comparing version 0.1.0-main.294e9eb to 0.1.0-main.2dcd513

lib/GlobalConfiguration.d.ts

8

CHANGELOG.md
# Changelog
All notable changes to this project will be documented in this file.
## [Unreleased]
## [Unreleased]
### Added
- Prevent multiple iframes being loaded
- Add `dispose()` on `FramedClient`
- Use `amsEndpoint` property by default
- Add `silentError` option

31

lib/API.js

@@ -50,2 +50,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var GlobalConfiguration_1 = require("./GlobalConfiguration");
var HeadersName;

@@ -96,5 +97,5 @@ (function (HeadersName) {

case 0:
console.log("[API][skypeTokenAuth]");
GlobalConfiguration_1.default.debug && console.log("[API][skypeTokenAuth]");
patchChatToken(chatToken);
url = ((_b = chatToken.regionGTMS) === null || _b === void 0 ? void 0 : _b.ams) + "/v1/skypetokenauth";
url = (chatToken.amsEndpoint || ((_b = chatToken.regionGTMS) === null || _b === void 0 ? void 0 : _b.ams)) + "/v1/skypetokenauth";
headers = (_a = {},

@@ -120,3 +121,3 @@ _a[HeadersName.Authorization] = "skype_token " + chatToken.token,

error_1 = _c.sent();
console.log(error_1);
!GlobalConfiguration_1.default.silentError && console.log(error_1);
throw new Error('AMSAuth');

@@ -134,3 +135,3 @@ case 4: return [2 /*return*/];

case 0:
console.log("[API][createObject]");
GlobalConfiguration_1.default.debug && console.log("[API][createObject]");
permissions = (_a = {},

@@ -145,3 +146,3 @@ _a[id] = ['read'],

patchChatToken(chatToken);
url = ((_c = chatToken === null || chatToken === void 0 ? void 0 : chatToken.regionGTMS) === null || _c === void 0 ? void 0 : _c.ams) + "/v1/objects";
url = (chatToken.amsEndpoint || ((_c = chatToken === null || chatToken === void 0 ? void 0 : chatToken.regionGTMS) === null || _c === void 0 ? void 0 : _c.ams)) + "/v1/objects";
headers = __assign(__assign({}, createDefaultHeaders(chatToken.token)), (_b = {}, _b[HeadersName.ContentType] = MIMEType.applicationJson, _b));

@@ -166,3 +167,3 @@ request = {

error_2 = _d.sent();
console.log(error_2);
!GlobalConfiguration_1.default.silentError && console.log(error_2);
throw new Error('AMSCreateObjectFailed');

@@ -180,5 +181,5 @@ case 5: return [2 /*return*/];

case 0:
console.log("[API][uploadDocument]");
GlobalConfiguration_1.default.debug && console.log("[API][uploadDocument]");
patchChatToken(chatToken);
url = ((_b = chatToken === null || chatToken === void 0 ? void 0 : chatToken.regionGTMS) === null || _b === void 0 ? void 0 : _b.ams) + "/v1/objects/" + documentId + "/content/" + (file.type.includes('image') ? 'imgpsh' : 'original');
url = (chatToken.amsEndpoint || ((_b = chatToken === null || chatToken === void 0 ? void 0 : chatToken.regionGTMS) === null || _b === void 0 ? void 0 : _b.ams)) + "/v1/objects/" + documentId + "/content/" + (file.type.includes('image') ? 'imgpsh' : 'original');
headers = __assign(__assign({}, createDefaultHeaders(chatToken.token)), (_a = {}, _a[HeadersName.ContentType] = MIMEType.applicationFormUrlEncoded, _a));

@@ -207,3 +208,3 @@ request = {

error_3 = _c.sent();
console.log(error_3);
!GlobalConfiguration_1.default.silentError && console.log(error_3);
throw new Error('AMSUploadDocumentFailed');

@@ -220,5 +221,5 @@ case 4: return [2 /*return*/];

case 0:
console.log("[API][getViewStatus]");
GlobalConfiguration_1.default.debug && console.log("[API][getViewStatus]");
patchChatToken(chatToken);
url = ((_a = chatToken === null || chatToken === void 0 ? void 0 : chatToken.regionGTMS) === null || _a === void 0 ? void 0 : _a.ams) + "/v1/objects/" + fileMetadata.id + "/views/" + (validImageTypes.includes(fileMetadata.type) ? 'imgpsh_fullsize_anim' : 'original') + "/status";
url = (chatToken.amsEndpoint || ((_a = chatToken === null || chatToken === void 0 ? void 0 : chatToken.regionGTMS) === null || _a === void 0 ? void 0 : _a.ams)) + "/v1/objects/" + fileMetadata.id + "/views/" + (validImageTypes.includes(fileMetadata.type) ? 'imgpsh_fullsize_anim' : 'original') + "/status";
headers = createDefaultHeaders(chatToken.token);

@@ -243,3 +244,3 @@ request = {

if (view_state && view_state !== AMSFileStatus.Ready.toString()) {
console.error('view_state is not ready');
!GlobalConfiguration_1.default.silentError && console.error('view_state is not ready');
}

@@ -252,3 +253,3 @@ if (content_state === AMSFileStatus.Expired.toString()) {

error_4 = _b.sent();
console.log(error_4);
!GlobalConfiguration_1.default.silentError && console.log(error_4);
throw new Error('AMSGetViewStatusFailed');

@@ -264,3 +265,3 @@ case 5: return [2 /*return*/];

case 0:
console.log("[API][getView]");
GlobalConfiguration_1.default.debug && console.log("[API][getView]");
patchChatToken(chatToken);

@@ -289,3 +290,3 @@ url = viewLocation;

error_5 = _a.sent();
console.log(error_5);
!GlobalConfiguration_1.default.silentError && console.log(error_5);
throw new Error('AMSGetViewFailed');

@@ -292,0 +293,0 @@ case 5: return [2 /*return*/];

@@ -1,1 +0,1 @@

exports.baseUrl = 'https://comms-test.omnichannelengagementhub.com/ams'; exports.sdkVersion = '0.1.0-main.294e9eb';
exports.baseUrl = 'https://comms.omnichannelengagementhub.com/ams'; exports.sdkVersion = '0.1.0-main.2dcd513';

@@ -8,4 +8,5 @@ import FramedClient from "./FramedClient";

logger?: PluggableLogger;
silentError?: boolean;
}
declare const createAMSClient: (config: AMSConfig) => Promise<FramedClient | FramedlessClient>;
export default createAMSClient;

@@ -42,2 +42,3 @@ "use strict";

var FramedlessClient_1 = require("./FramedlessClient");
var GlobalConfiguration_1 = require("./GlobalConfiguration");
var createAMSClient = function (config) { return __awaiter(void 0, void 0, void 0, function () {

@@ -50,2 +51,4 @@ var logger, client;

config.debug && client.setDebug(config.debug || false);
GlobalConfiguration_1.default.debug = config.debug || false;
GlobalConfiguration_1.default.silentError = config.silentError || true;
return [2 /*return*/, client];

@@ -52,0 +55,0 @@ });

export default interface FileMetadata {
fileSharingProtocolType: number;
fileSharingProtocolType?: number;
id: string;
name: string;
size: number;
name?: string;
size?: number;
type: string;
url: string;
url?: string;
}

@@ -10,2 +10,4 @@ import AMSFileInfo from "./AMSFileInfo";

declare class FramedClient {
private clientId;
private iframeId;
private origin;

@@ -29,5 +31,6 @@ private targetWindow;

postMessage(eventType: PostMessageEventType, eventName: PostMessageEventName, data?: PostMessageRequestData, resolve?: CallableFunction, reject?: CallableFunction): void;
handleEvent(event: MessageEvent<any>): Promise<void>;
private createIframe;
handleEvent(event: MessageEvent): Promise<void>;
dispose(): void;
private loadIframe;
}
export default FramedClient;

@@ -51,2 +51,3 @@ "use strict";

var config_1 = require("./config");
var GlobalConfiguration_1 = require("./GlobalConfiguration");
var platform_1 = require("./utils/platform");

@@ -57,2 +58,3 @@ var PostMessageEventName_1 = require("./PostMessageEventName");

var version = config_1.sdkVersion;
var iframePrefix = 'Microsoft_Omnichannel_AMSClient_Iframe_Window';
var FramedClient = /** @class */ (function () {

@@ -62,2 +64,3 @@ function FramedClient(logger) {

if (logger === void 0) { logger = undefined; }
this.clientId = uuid_1.uuidv4();
this.origin = window.location.origin;

@@ -68,2 +71,3 @@ this.requestCallbacks = {};

this.logger = logger;
this.iframeId = iframePrefix;
this.onMessageEvent(function (event) { return _this.handleEvent(event); }); // eslint-disable-line @typescript-eslint/no-explicit-any

@@ -85,7 +89,7 @@ }

}
return [4 /*yield*/, this.createIframe()];
return [4 /*yield*/, this.loadIframe()];
case 1:
_a.sent();
if (!this.iframeLoaded) {
console.error('iframe not loaded');
!GlobalConfiguration_1.default.silentError && console.error('iframe not loaded');
}

@@ -107,10 +111,16 @@ this.chatToken = initConfig.chatToken;

return __generator(this, function (_a) {
/* istanbul ignore next */
this.debug && console.log("[FramedClient][skypeAuth]");
data = {
chatToken: chatToken || this.chatToken
};
return [2 /*return*/, new Promise(function (resolve, reject) {
_this.postMessage(PostMessageEventType_1.default.Request, PostMessageEventName_1.default.SkypeTokenAuth, data, resolve, reject);
})];
switch (_a.label) {
case 0:
/* istanbul ignore next */
this.debug && console.log("[FramedClient][skypeAuth]");
data = {
chatToken: chatToken || this.chatToken
};
return [4 /*yield*/, this.loadIframe()];
case 1:
_a.sent();
return [2 /*return*/, new Promise(function (resolve, reject) {
_this.postMessage(PostMessageEventType_1.default.Request, PostMessageEventName_1.default.SkypeTokenAuth, data, resolve, reject);
})];
}
});

@@ -125,12 +135,18 @@ });

return __generator(this, function (_a) {
/* istanbul ignore next */
this.debug && console.log("[FramedClient][createObject]");
data = {
id: id,
file: file,
chatToken: chatToken || this.chatToken
};
return [2 /*return*/, new Promise(function (resolve, reject) {
_this.postMessage(PostMessageEventType_1.default.Request, PostMessageEventName_1.default.CreateObject, data, resolve, reject);
})];
switch (_a.label) {
case 0:
/* istanbul ignore next */
this.debug && console.log("[FramedClient][createObject]");
data = {
id: id,
file: file,
chatToken: chatToken || this.chatToken
};
return [4 /*yield*/, this.loadIframe()];
case 1:
_a.sent();
return [2 /*return*/, new Promise(function (resolve, reject) {
_this.postMessage(PostMessageEventType_1.default.Request, PostMessageEventName_1.default.CreateObject, data, resolve, reject);
})];
}
});

@@ -145,12 +161,18 @@ });

return __generator(this, function (_a) {
/* istanbul ignore next */
this.debug && console.log("[FramedClient][uploadDocument]");
data = {
documentId: documentId,
file: file,
chatToken: chatToken || this.chatToken
};
return [2 /*return*/, new Promise(function (resolve, reject) {
_this.postMessage(PostMessageEventType_1.default.Request, PostMessageEventName_1.default.UploadDocument, data, resolve, reject);
})];
switch (_a.label) {
case 0:
/* istanbul ignore next */
this.debug && console.log("[FramedClient][uploadDocument]");
data = {
documentId: documentId,
file: file,
chatToken: chatToken || this.chatToken
};
return [4 /*yield*/, this.loadIframe()];
case 1:
_a.sent();
return [2 /*return*/, new Promise(function (resolve, reject) {
_this.postMessage(PostMessageEventType_1.default.Request, PostMessageEventName_1.default.UploadDocument, data, resolve, reject);
})];
}
});

@@ -165,9 +187,15 @@ });

return __generator(this, function (_a) {
data = {
fileMetadata: fileMetadata,
chatToken: chatToken || this.chatToken
};
return [2 /*return*/, new Promise(function (resolve, reject) {
_this.postMessage(PostMessageEventType_1.default.Request, PostMessageEventName_1.default.GetViewStatus, data, resolve, reject);
})];
switch (_a.label) {
case 0:
data = {
fileMetadata: fileMetadata,
chatToken: chatToken || this.chatToken
};
return [4 /*yield*/, this.loadIframe()];
case 1:
_a.sent();
return [2 /*return*/, new Promise(function (resolve, reject) {
_this.postMessage(PostMessageEventType_1.default.Request, PostMessageEventName_1.default.GetViewStatus, data, resolve, reject);
})];
}
});

@@ -182,10 +210,16 @@ });

return __generator(this, function (_a) {
data = {
fileMetadata: fileMetadata,
viewLocation: viewLocation,
chatToken: chatToken || this.chatToken
};
return [2 /*return*/, new Promise(function (resolve, reject) {
_this.postMessage(PostMessageEventType_1.default.Request, PostMessageEventName_1.default.GetView, data, resolve, reject);
})];
switch (_a.label) {
case 0:
data = {
fileMetadata: fileMetadata,
viewLocation: viewLocation,
chatToken: chatToken || this.chatToken
};
return [4 /*yield*/, this.loadIframe()];
case 1:
_a.sent();
return [2 /*return*/, new Promise(function (resolve, reject) {
_this.postMessage(PostMessageEventType_1.default.Request, PostMessageEventName_1.default.GetView, data, resolve, reject);
})];
}
});

@@ -210,3 +244,3 @@ });

error_1 = _a.sent();
console.log(error_1);
!GlobalConfiguration_1.default.silentError && console.log(error_1);
throw new Error('fetchBlob');

@@ -230,3 +264,7 @@ case 4: return [2 /*return*/];

};
this.targetWindow.postMessage(__assign({ requestId: requestId,
if (!this.targetWindow) {
!GlobalConfiguration_1.default.silentError && console.error('Target window not found!');
return;
}
this.targetWindow.postMessage(__assign({ clientId: this.clientId, requestId: requestId,
eventType: eventType,

@@ -245,3 +283,6 @@ eventName: eventName }, data), '*');

this.debug && console.log(event);
this.targetWindow = event.source; // Finds target window to post message back
// Finds target window to post message back
if (event.source) {
this.targetWindow = event.source;
}
if (event.data.eventType === PostMessageEventType_1.default.Response) {

@@ -252,20 +293,30 @@ /* istanbul ignore next */

if (event.data.eventName === PostMessageEventName_1.default.SkypeTokenAuth) {
this.requestCallbacks[data.requestId].resolve();
delete this.requestCallbacks[data.requestId];
if (data.requestId in this.requestCallbacks) {
this.requestCallbacks[data.requestId].resolve();
delete this.requestCallbacks[data.requestId];
}
}
else if (event.data.eventName === PostMessageEventName_1.default.CreateObject) {
this.requestCallbacks[data.requestId].resolve(data.response);
delete this.requestCallbacks[data.requestId];
if (data.requestId in this.requestCallbacks) {
this.requestCallbacks[data.requestId].resolve(data.response);
delete this.requestCallbacks[data.requestId];
}
}
else if (event.data.eventName === PostMessageEventName_1.default.UploadDocument) {
this.requestCallbacks[data.requestId].resolve(data.response);
delete this.requestCallbacks[data.requestId];
if (data.requestId in this.requestCallbacks) {
this.requestCallbacks[data.requestId].resolve(data.response);
delete this.requestCallbacks[data.requestId];
}
}
else if (event.data.eventName === PostMessageEventName_1.default.GetViewStatus) {
this.requestCallbacks[data.requestId].resolve(data.response);
delete this.requestCallbacks[data.requestId];
if (data.requestId in this.requestCallbacks) {
this.requestCallbacks[data.requestId].resolve(data.response);
delete this.requestCallbacks[data.requestId];
}
}
else if (event.data.eventName === PostMessageEventName_1.default.GetView) {
this.requestCallbacks[data.requestId].resolve(data.response);
delete this.requestCallbacks[data.requestId];
if (data.requestId in this.requestCallbacks) {
this.requestCallbacks[data.requestId].resolve(data.response);
delete this.requestCallbacks[data.requestId];
}
}

@@ -280,12 +331,22 @@ else if (event.data.eventName === PostMessageEventName_1.default.SendTelemetry) {

};
FramedClient.prototype.createIframe = function () {
FramedClient.prototype.dispose = function () {
var _a;
(_a = document.getElementById(this.iframeId)) === null || _a === void 0 ? void 0 : _a.remove();
this.requestCallbacks = {};
this.iframeLoaded = false;
};
FramedClient.prototype.loadIframe = function () {
return __awaiter(this, void 0, void 0, function () {
var iframeId;
var _this = this;
return __generator(this, function (_a) {
iframeId = 'Microsoft_Omnichannel_AMSClient_Iframe_Window';
return [2 /*return*/, new Promise(function (resolve, reject) {
var iframeElements = Array.from(document.getElementsByTagName('iframe'));
var foundIframeElement = iframeElements.filter(function (iframeElement) { return iframeElement.id == _this.iframeId; });
// Avoid duplicate load
if (foundIframeElement.length) {
return resolve();
}
var iframeElement = document.createElement('iframe');
iframeElement.id = iframeId;
iframeElement.src = config_1.baseUrl + "/" + version + "/iframe.html?debug=" + _this.debug + "&telemetry=true";
iframeElement.id = _this.iframeId;
iframeElement.src = config_1.baseUrl + "/" + version + "/iframe.html?clientId=" + _this.clientId + "&debug=" + _this.debug + "&telemetry=true";
iframeElement.addEventListener('load', function () {

@@ -292,0 +353,0 @@ /* istanbul ignore next */

@@ -6,2 +6,3 @@ import PostMessageEventName from "./PostMessageEventName";

declare class IframeCommunicator {
private clientId;
private sourceWindow;

@@ -11,3 +12,3 @@ private targetWindow;

private telemetryEnabled;
constructor();
constructor(clientId: string);
setDebug(flag: boolean): void;

@@ -14,0 +15,0 @@ enableTelemetry(): void;

@@ -51,2 +51,3 @@ "use strict";

var API_1 = require("./API");
var fetchClientId_1 = require("./utils/fetchClientId");
var fetchDebugConfig_1 = require("./utils/fetchDebugConfig");

@@ -60,3 +61,4 @@ var fetchTelemetryConfig_1 = require("./utils/fetchTelemetryConfig");

var IframeCommunicator = /** @class */ (function () {
function IframeCommunicator() {
function IframeCommunicator(clientId) {
this.clientId = clientId;
this.sourceWindow = window;

@@ -90,3 +92,3 @@ this.targetWindow = window.parent;

if (data === void 0) { data = {}; }
this.targetWindow.postMessage(__assign({ eventType: eventType,
this.targetWindow.postMessage(__assign({ clientId: this.clientId, eventType: eventType,
eventName: eventName,

@@ -120,3 +122,3 @@ eventStatus: eventStatus }, data), '*');

this.sendTelemetry(LogLevel_1.default.ERROR, {
ChatId: data.chatToken.ChatId,
ChatId: data.chatToken.chatId,
AMSClientVersion: config_1.sdkVersion,

@@ -135,3 +137,3 @@ Event: PostMessageEventName_1.default.SkypeTokenAuth,

this.sendTelemetry(LogLevel_1.default.ERROR, {
ChatId: data.chatToken.ChatId,
ChatId: data.chatToken.chatId,
AMSClientVersion: config_1.sdkVersion,

@@ -164,3 +166,3 @@ Event: PostMessageEventName_1.default.SkypeTokenAuth,

this.sendTelemetry(LogLevel_1.default.ERROR, {
ChatId: data.chatToken.ChatId,
ChatId: data.chatToken.chatId,
AMSClientVersion: config_1.sdkVersion,

@@ -194,3 +196,3 @@ Event: PostMessageEventName_1.default.CreateObject,

this.sendTelemetry(LogLevel_1.default.ERROR, {
ChatId: data.chatToken.ChatId,
ChatId: data.chatToken.chatId,
AMSClientVersion: config_1.sdkVersion,

@@ -224,3 +226,3 @@ Event: PostMessageEventName_1.default.UploadDocument,

this.sendTelemetry(LogLevel_1.default.ERROR, {
ChatId: data.chatToken.ChatId,
ChatId: data.chatToken.chatId,
AMSClientVersion: config_1.sdkVersion,

@@ -254,3 +256,3 @@ Event: PostMessageEventName_1.default.GetViewStatus,

this.sendTelemetry(LogLevel_1.default.ERROR, {
ChatId: data.chatToken.ChatId,
ChatId: data.chatToken.chatId,
AMSClientVersion: config_1.sdkVersion,

@@ -279,6 +281,7 @@ Event: PostMessageEventName_1.default.GetView,

(function () {
var clientId = fetchClientId_1.default();
var telemetryConfig = fetchTelemetryConfig_1.default();
var debugConfig = fetchDebugConfig_1.default();
!debugConfig.disable && console.log("[IframeCommunicator][init]");
var iframeCommunicator = new IframeCommunicator();
var iframeCommunicator = new IframeCommunicator(clientId);
iframeCommunicator.initialize();

@@ -285,0 +288,0 @@ iframeCommunicator.setDebug(!debugConfig.disable);

@@ -9,3 +9,4 @@ interface OmnichannelChatToken {

voiceVideoCallToken?: string;
amsEndpoint?: string;
}
export default OmnichannelChatToken;
declare enum PostMessageEventName {
IframeLoaded = "IframeLoaded",
SkypeTokenAuth = "SkypeTokenAuth",
CreateObject = "CreateObject",
UploadDocument = "UploadDocument",
GetViewStatus = "GetViewStatus",
GetView = "GetView",
SendTelemetry = "SendTelemetry"
IframeLoaded = "AMSIframeLoaded",
SkypeTokenAuth = "AMSSkypeTokenAuth",
CreateObject = "AMSCreateObject",
UploadDocument = "AMSUploadDocument",
GetViewStatus = "AMSGetViewStatus",
GetView = "AMSGetView",
SendTelemetry = "AMSSendTelemetry"
}
export default PostMessageEventName;

@@ -5,11 +5,11 @@ "use strict";

(function (PostMessageEventName) {
PostMessageEventName["IframeLoaded"] = "IframeLoaded";
PostMessageEventName["SkypeTokenAuth"] = "SkypeTokenAuth";
PostMessageEventName["CreateObject"] = "CreateObject";
PostMessageEventName["UploadDocument"] = "UploadDocument";
PostMessageEventName["GetViewStatus"] = "GetViewStatus";
PostMessageEventName["GetView"] = "GetView";
PostMessageEventName["SendTelemetry"] = "SendTelemetry";
PostMessageEventName["IframeLoaded"] = "AMSIframeLoaded";
PostMessageEventName["SkypeTokenAuth"] = "AMSSkypeTokenAuth";
PostMessageEventName["CreateObject"] = "AMSCreateObject";
PostMessageEventName["UploadDocument"] = "AMSUploadDocument";
PostMessageEventName["GetViewStatus"] = "AMSGetViewStatus";
PostMessageEventName["GetView"] = "AMSGetView";
PostMessageEventName["SendTelemetry"] = "AMSSendTelemetry";
})(PostMessageEventName || (PostMessageEventName = {}));
exports.default = PostMessageEventName;
//# sourceMappingURL=PostMessageEventName.js.map
{
"name": "@microsoft/omnichannel-amsclient",
"version": "0.1.0-main.294e9eb",
"version": "0.1.0-main.2dcd513",
"description": "Microsoft Omnichannel AMSClient",

@@ -5,0 +5,0 @@ "files": [

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc