@microsoft/teams-js
Advanced tools
Comparing version 1.4.0-beta.3.7 to 1.4.0-beta.3.8
@@ -89,8 +89,18 @@ /******/ (function(modules) { // webpackBootstrap | ||
/* 0 */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
/***/ (function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
__webpack_require__.r(__webpack_exports__); | ||
// CONCATENATED MODULE: ./src/MicrosoftTeams.ts | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var MicrosoftTeams_1 = __webpack_require__(1); | ||
exports.microsoftTeams = MicrosoftTeams_1.microsoftTeams; | ||
/***/ }), | ||
/* 1 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
if (!String.prototype.startsWith) { | ||
@@ -104,1185 +114,1165 @@ String.prototype.startsWith = function (search, pos) { | ||
*/ | ||
"use strict"; | ||
var version = "1.3.6"; | ||
var validOrigins = [ | ||
"https://teams.microsoft.com", | ||
"https://teams.microsoft.us", | ||
"https://int.teams.microsoft.com", | ||
"https://devspaces.skype.com", | ||
"https://ssauth.skype.com", | ||
"http://dev.local", | ||
"https://msft.spoppe.com", | ||
"https://*.sharepoint.com", | ||
"https://*.sharepoint-df.com", | ||
"https://*.sharepointonline.com", | ||
"https://outlook.office.com", | ||
"https://outlook-sdf.office.com" | ||
]; | ||
// This will return a reg expression a given url | ||
function generateRegExpFromUrl(url) { | ||
var urlRegExpPart = "^"; | ||
var urlParts = url.split("."); | ||
for (var j = 0; j < urlParts.length; j++) { | ||
urlRegExpPart += | ||
(j > 0 ? "[.]" : "") + urlParts[j].replace("*", "[^/^.]+"); | ||
var microsoftTeams; | ||
(function (microsoftTeams) { | ||
"use strict"; | ||
const version = "1.3.6"; | ||
const validOrigins = [ | ||
"https://teams.microsoft.com", | ||
"https://teams.microsoft.us", | ||
"https://int.teams.microsoft.com", | ||
"https://devspaces.skype.com", | ||
"https://ssauth.skype.com", | ||
"http://dev.local", | ||
"https://msft.spoppe.com", | ||
"https://*.sharepoint.com", | ||
"https://*.sharepoint-df.com", | ||
"https://*.sharepointonline.com", | ||
"https://outlook.office.com", | ||
"https://outlook-sdf.office.com" | ||
]; | ||
// This will return a reg expression a given url | ||
function generateRegExpFromUrl(url) { | ||
let urlRegExpPart = "^"; | ||
let urlParts = url.split("."); | ||
for (let j = 0; j < urlParts.length; j++) { | ||
urlRegExpPart += | ||
(j > 0 ? "[.]" : "") + urlParts[j].replace("*", "[^/^.]+"); | ||
} | ||
urlRegExpPart += "$"; | ||
return urlRegExpPart; | ||
} | ||
urlRegExpPart += "$"; | ||
return urlRegExpPart; | ||
} | ||
// This will return a reg expression for list of url | ||
function generateRegExpFromUrls(urls) { | ||
var urlRegExp = ""; | ||
for (var i = 0; i < urls.length; i++) { | ||
urlRegExp += (i === 0 ? "" : "|") + generateRegExpFromUrl(urls[i]); | ||
// This will return a reg expression for list of url | ||
function generateRegExpFromUrls(urls) { | ||
let urlRegExp = ""; | ||
for (let i = 0; i < urls.length; i++) { | ||
urlRegExp += (i === 0 ? "" : "|") + generateRegExpFromUrl(urls[i]); | ||
} | ||
return new RegExp(urlRegExp); | ||
} | ||
return new RegExp(urlRegExp); | ||
} | ||
var validOriginRegExp = generateRegExpFromUrls(validOrigins); | ||
var handlers = {}; | ||
// Ensure these declarations stay in sync with the framework. | ||
var frameContexts = { | ||
settings: "settings", | ||
content: "content", | ||
authentication: "authentication", | ||
remove: "remove", | ||
task: "task" | ||
}; | ||
/** | ||
* Namespace to interact with the menu-specific part of the SDK. | ||
* This object is used to show View Configuration, Action Menu and Navigation Bar Menu. | ||
* | ||
* @private | ||
* Hide from docs until feature is complete | ||
*/ | ||
var menus; | ||
(function (menus) { | ||
const validOriginRegExp = generateRegExpFromUrls(validOrigins); | ||
const handlers = {}; | ||
// Ensure these declarations stay in sync with the framework. | ||
const frameContexts = { | ||
settings: "settings", | ||
content: "content", | ||
authentication: "authentication", | ||
remove: "remove", | ||
task: "task" | ||
}; | ||
/** | ||
* Represents information about menu item for Action Menu and Navigation Bar Menu. | ||
* Namespace to interact with the menu-specific part of the SDK. | ||
* This object is used to show View Configuration, Action Menu and Navigation Bar Menu. | ||
* | ||
* @private | ||
* Hide from docs until feature is complete | ||
*/ | ||
var MenuItem = /** @class */ (function () { | ||
function MenuItem() { | ||
/** | ||
* State of the menu item | ||
*/ | ||
this.enabled = true; | ||
let menus; | ||
(function (menus) { | ||
/** | ||
* Represents information about menu item for Action Menu and Navigation Bar Menu. | ||
*/ | ||
class MenuItem { | ||
constructor() { | ||
/** | ||
* State of the menu item | ||
*/ | ||
this.enabled = true; | ||
} | ||
} | ||
return MenuItem; | ||
}()); | ||
menus.MenuItem = MenuItem; | ||
menus.MenuItem = MenuItem; | ||
/** | ||
* Represents information about type of list to display in Navigation Bar Menu. | ||
*/ | ||
let MenuListType; | ||
(function (MenuListType) { | ||
MenuListType["dropDown"] = "dropDown"; | ||
MenuListType["popOver"] = "popOver"; | ||
})(MenuListType = menus.MenuListType || (menus.MenuListType = {})); | ||
let navBarMenuItemPressHandler; | ||
handlers["navBarMenuItemPress"] = handleNavBarMenuItemPress; | ||
let actionMenuItemPressHandler; | ||
handlers["actionMenuItemPress"] = handleActionMenuItemPress; | ||
let viewConfigItemPressHandler; | ||
handlers["setModuleView"] = handleViewConfigItemPress; | ||
/** | ||
* Registers list of view configurations and it's handler. | ||
* Handler is responsible for listening selection of View Configuration. | ||
* @param viewConfig List of view configurations. Minimum 1 value is required. | ||
* @param handler The handler to invoke when the user selects view configuration. | ||
*/ | ||
function setUpViews(viewConfig, handler) { | ||
ensureInitialized(); | ||
viewConfigItemPressHandler = handler; | ||
sendMessageRequest(parentWindow, "setUpViews", [viewConfig]); | ||
} | ||
menus.setUpViews = setUpViews; | ||
function handleViewConfigItemPress(id) { | ||
if (!viewConfigItemPressHandler || !viewConfigItemPressHandler(id)) { | ||
ensureInitialized(); | ||
sendMessageRequest(parentWindow, "viewConfigItemPress", [id]); | ||
} | ||
} | ||
/** | ||
* Used to set menu items on the Navigation Bar. If icon is available, icon will be shown, otherwise title will be shown. | ||
* @param items List of MenuItems for Navigation Bar Menu. | ||
* @param handler The handler to invoke when the user selects menu item. | ||
*/ | ||
function setNavBarMenu(items, handler) { | ||
ensureInitialized(); | ||
navBarMenuItemPressHandler = handler; | ||
sendMessageRequest(parentWindow, "setNavBarMenu", [items]); | ||
} | ||
menus.setNavBarMenu = setNavBarMenu; | ||
function handleNavBarMenuItemPress(id) { | ||
if (!navBarMenuItemPressHandler || !navBarMenuItemPressHandler(id)) { | ||
ensureInitialized(); | ||
sendMessageRequest(parentWindow, "handleNavBarMenuItemPress", [id]); | ||
} | ||
} | ||
/** | ||
* Used to show Action Menu. | ||
* @param params Parameters for Menu Parameters | ||
* @param handler The handler to invoke when the user selects menu item. | ||
*/ | ||
function showActionMenu(params, handler) { | ||
ensureInitialized(); | ||
actionMenuItemPressHandler = handler; | ||
sendMessageRequest(parentWindow, "showActionMenu", [params]); | ||
} | ||
menus.showActionMenu = showActionMenu; | ||
function handleActionMenuItemPress(id) { | ||
if (!actionMenuItemPressHandler || !actionMenuItemPressHandler(id)) { | ||
ensureInitialized(); | ||
sendMessageRequest(parentWindow, "handleActionMenuItemPress", [id]); | ||
} | ||
} | ||
})(menus = microsoftTeams.menus || (microsoftTeams.menus = {})); | ||
// This indicates whether initialize was called (started). | ||
// It does not indicate whether initialization is complete. That can be inferred by whether parentOrigin is set. | ||
let initializeCalled = false; | ||
let isFramelessWindow = false; | ||
let currentWindow; | ||
let parentWindow; | ||
let parentOrigin; | ||
let parentMessageQueue = []; | ||
let childWindow; | ||
let childOrigin; | ||
let childMessageQueue = []; | ||
let nextMessageId = 0; | ||
let callbacks = {}; | ||
let frameContext; | ||
let hostClientType; | ||
let printCapabilityEnabled = false; | ||
let themeChangeHandler; | ||
handlers["themeChange"] = handleThemeChange; | ||
let fullScreenChangeHandler; | ||
handlers["fullScreenChange"] = handleFullScreenChange; | ||
let backButtonPressHandler; | ||
handlers["backButtonPress"] = handleBackButtonPress; | ||
/** | ||
* Represents information about type of list to display in Navigation Bar Menu. | ||
* Initializes the library. This must be called before any other SDK calls | ||
* but after the frame is loaded successfully. | ||
*/ | ||
var MenuListType; | ||
(function (MenuListType) { | ||
MenuListType["dropDown"] = "dropDown"; | ||
MenuListType["popOver"] = "popOver"; | ||
})(MenuListType = menus.MenuListType || (menus.MenuListType = {})); | ||
var navBarMenuItemPressHandler; | ||
handlers["navBarMenuItemPress"] = handleNavBarMenuItemPress; | ||
var actionMenuItemPressHandler; | ||
handlers["actionMenuItemPress"] = handleActionMenuItemPress; | ||
var viewConfigItemPressHandler; | ||
handlers["setModuleView"] = handleViewConfigItemPress; | ||
function initialize(hostWindow = window) { | ||
if (initializeCalled) { | ||
// Independent components might not know whether the SDK is initialized so might call it to be safe. | ||
// Just no-op if that happens to make it easier to use. | ||
return; | ||
} | ||
initializeCalled = true; | ||
// Undocumented field used to mock the window for unit tests | ||
currentWindow = hostWindow; | ||
// Listen for messages post to our window | ||
let messageListener = (evt) => processMessage(evt); | ||
// If we are in an iframe, our parent window is the one hosting us (i.e., window.parent); otherwise, | ||
// it's the window that opened us (i.e., window.opener) | ||
parentWindow = | ||
currentWindow.parent !== currentWindow.self | ||
? currentWindow.parent | ||
: currentWindow.opener; | ||
if (!parentWindow) { | ||
isFramelessWindow = true; | ||
window.onNativeMessage = handleParentMessage; | ||
} | ||
else { | ||
// For iFrame scenario, add listener to listen 'message' | ||
currentWindow.addEventListener("message", messageListener, false); | ||
} | ||
try { | ||
// Send the initialized message to any origin, because at this point we most likely don't know the origin | ||
// of the parent window, and this message contains no data that could pose a security risk. | ||
parentOrigin = "*"; | ||
let messageId = sendMessageRequest(parentWindow, "initialize", [version]); | ||
callbacks[messageId] = (context, clientType) => { | ||
frameContext = context; | ||
hostClientType = clientType; | ||
}; | ||
} | ||
finally { | ||
parentOrigin = null; | ||
} | ||
// Undocumented function used to clear state between unit tests | ||
this._uninitialize = () => { | ||
if (frameContext) { | ||
registerOnThemeChangeHandler(null); | ||
registerFullScreenHandler(null); | ||
registerBackButtonHandler(null); | ||
} | ||
if (frameContext === frameContexts.settings) { | ||
settings.registerOnSaveHandler(null); | ||
} | ||
if (frameContext === frameContexts.remove) { | ||
settings.registerOnRemoveHandler(null); | ||
} | ||
if (!isFramelessWindow) { | ||
currentWindow.removeEventListener("message", messageListener, false); | ||
} | ||
initializeCalled = false; | ||
parentWindow = null; | ||
parentOrigin = null; | ||
parentMessageQueue = []; | ||
childWindow = null; | ||
childOrigin = null; | ||
childMessageQueue = []; | ||
nextMessageId = 0; | ||
callbacks = {}; | ||
frameContext = null; | ||
hostClientType = null; | ||
isFramelessWindow = false; | ||
}; | ||
} | ||
microsoftTeams.initialize = initialize; | ||
/** | ||
* Registers list of view configurations and it's handler. | ||
* Handler is responsible for listening selection of View Configuration. | ||
* @param viewConfig List of view configurations. Minimum 1 value is required. | ||
* @param handler The handler to invoke when the user selects view configuration. | ||
* Initializes the library. This must be called before any other SDK calls | ||
* but after the frame is loaded successfully. | ||
*/ | ||
function setUpViews(viewConfig, handler) { | ||
ensureInitialized(); | ||
viewConfigItemPressHandler = handler; | ||
sendMessageRequest(parentWindow, "setUpViews", [viewConfig]); | ||
} | ||
menus.setUpViews = setUpViews; | ||
function handleViewConfigItemPress(id) { | ||
if (!viewConfigItemPressHandler || !viewConfigItemPressHandler(id)) { | ||
function _uninitialize() { } | ||
microsoftTeams._uninitialize = _uninitialize; | ||
/** | ||
* Enable print capability to support printing page using Ctrl+P and cmd+P | ||
*/ | ||
function enablePrintCapability() { | ||
if (!printCapabilityEnabled) { | ||
printCapabilityEnabled = true; | ||
ensureInitialized(); | ||
sendMessageRequest(parentWindow, "viewConfigItemPress", [id]); | ||
// adding ctrl+P and cmd+P handler | ||
document.addEventListener("keydown", (event) => { | ||
if ((event.ctrlKey || event.metaKey) && event.keyCode === 80) { | ||
microsoftTeams.print(); | ||
event.cancelBubble = true; | ||
event.preventDefault(); | ||
event.stopImmediatePropagation(); | ||
} | ||
}); | ||
} | ||
} | ||
microsoftTeams.enablePrintCapability = enablePrintCapability; | ||
/** | ||
* Used to set menu items on the Navigation Bar. If icon is available, icon will be shown, otherwise title will be shown. | ||
* @param items List of MenuItems for Navigation Bar Menu. | ||
* @param handler The handler to invoke when the user selects menu item. | ||
* default print handler | ||
*/ | ||
function setNavBarMenu(items, handler) { | ||
function print() { | ||
window.print(); | ||
} | ||
microsoftTeams.print = print; | ||
/** | ||
* Retrieves the current context the frame is running in. | ||
* @param callback The callback to invoke when the {@link Context} object is retrieved. | ||
*/ | ||
function getContext(callback) { | ||
ensureInitialized(); | ||
navBarMenuItemPressHandler = handler; | ||
sendMessageRequest(parentWindow, "setNavBarMenu", [items]); | ||
let messageId = sendMessageRequest(parentWindow, "getContext"); | ||
callbacks[messageId] = callback; | ||
} | ||
menus.setNavBarMenu = setNavBarMenu; | ||
function handleNavBarMenuItemPress(id) { | ||
if (!navBarMenuItemPressHandler || !navBarMenuItemPressHandler(id)) { | ||
ensureInitialized(); | ||
sendMessageRequest(parentWindow, "handleNavBarMenuItemPress", [id]); | ||
microsoftTeams.getContext = getContext; | ||
/** | ||
* Registers a handler for theme changes. | ||
* Only one handler can be registered at a time. A subsequent registration replaces an existing registration. | ||
* @param handler The handler to invoke when the user changes their theme. | ||
*/ | ||
function registerOnThemeChangeHandler(handler) { | ||
ensureInitialized(); | ||
themeChangeHandler = handler; | ||
} | ||
microsoftTeams.registerOnThemeChangeHandler = registerOnThemeChangeHandler; | ||
function handleThemeChange(theme) { | ||
if (themeChangeHandler) { | ||
themeChangeHandler(theme); | ||
} | ||
if (childWindow) { | ||
sendMessageRequest(childWindow, "themeChange", [theme]); | ||
} | ||
} | ||
/** | ||
* Used to show Action Menu. | ||
* @param params Parameters for Menu Parameters | ||
* @param handler The handler to invoke when the user selects menu item. | ||
* Registers a handler for changes from or to full-screen view for a tab. | ||
* Only one handler can be registered at a time. A subsequent registration replaces an existing registration. | ||
* @param handler The handler to invoke when the user toggles full-screen view for a tab. | ||
*/ | ||
function showActionMenu(params, handler) { | ||
function registerFullScreenHandler(handler) { | ||
ensureInitialized(); | ||
actionMenuItemPressHandler = handler; | ||
sendMessageRequest(parentWindow, "showActionMenu", [params]); | ||
fullScreenChangeHandler = handler; | ||
} | ||
menus.showActionMenu = showActionMenu; | ||
function handleActionMenuItemPress(id) { | ||
if (!actionMenuItemPressHandler || !actionMenuItemPressHandler(id)) { | ||
ensureInitialized(); | ||
sendMessageRequest(parentWindow, "handleActionMenuItemPress", [id]); | ||
microsoftTeams.registerFullScreenHandler = registerFullScreenHandler; | ||
function handleFullScreenChange(isFullScreen) { | ||
if (fullScreenChangeHandler) { | ||
fullScreenChangeHandler(isFullScreen); | ||
} | ||
} | ||
})(menus || (menus = {})); | ||
// This indicates whether initialize was called (started). | ||
// It does not indicate whether initialization is complete. That can be inferred by whether parentOrigin is set. | ||
var initializeCalled = false; | ||
var isFramelessWindow = false; | ||
var currentWindow; | ||
var parentWindow; | ||
var parentOrigin; | ||
var parentMessageQueue = []; | ||
var childWindow; | ||
var childOrigin; | ||
var childMessageQueue = []; | ||
var nextMessageId = 0; | ||
var callbacks = {}; | ||
var frameContext; | ||
var hostClientType; | ||
var printCapabilityEnabled = false; | ||
var themeChangeHandler; | ||
handlers["themeChange"] = handleThemeChange; | ||
var fullScreenChangeHandler; | ||
handlers["fullScreenChange"] = handleFullScreenChange; | ||
var backButtonPressHandler; | ||
handlers["backButtonPress"] = handleBackButtonPress; | ||
/** | ||
* Initializes the library. This must be called before any other SDK calls | ||
* but after the frame is loaded successfully. | ||
*/ | ||
function initialize(hostWindow) { | ||
if (hostWindow === void 0) { hostWindow = window; } | ||
if (initializeCalled) { | ||
// Independent components might not know whether the SDK is initialized so might call it to be safe. | ||
// Just no-op if that happens to make it easier to use. | ||
return; | ||
/** | ||
* Registers a handler for user presses of the Team client's back button. Experiences that maintain an internal | ||
* navigation stack should use this handler to navigate the user back within their frame. If an app finds | ||
* that after running its back button handler it cannot handle the event it should call the navigateBack | ||
* method to ask the Teams client to handle it instead. | ||
* @param handler The handler to invoke when the user presses their Team client's back button. | ||
*/ | ||
function registerBackButtonHandler(handler) { | ||
ensureInitialized(); | ||
backButtonPressHandler = handler; | ||
} | ||
initializeCalled = true; | ||
// Undocumented field used to mock the window for unit tests | ||
currentWindow = hostWindow; | ||
// Listen for messages post to our window | ||
var messageListener = function (evt) { return processMessage(evt); }; | ||
// If we are in an iframe, our parent window is the one hosting us (i.e., window.parent); otherwise, | ||
// it's the window that opened us (i.e., window.opener) | ||
parentWindow = | ||
currentWindow.parent !== currentWindow.self | ||
? currentWindow.parent | ||
: currentWindow.opener; | ||
if (!parentWindow) { | ||
isFramelessWindow = true; | ||
window.onNativeMessage = handleParentMessage; | ||
microsoftTeams.registerBackButtonHandler = registerBackButtonHandler; | ||
function handleBackButtonPress() { | ||
if (!backButtonPressHandler || !backButtonPressHandler()) { | ||
navigateBack(); | ||
} | ||
} | ||
else { | ||
// For iFrame scenario, add listener to listen 'message' | ||
currentWindow.addEventListener("message", messageListener, false); | ||
} | ||
try { | ||
// Send the initialized message to any origin, because at this point we most likely don't know the origin | ||
// of the parent window, and this message contains no data that could pose a security risk. | ||
parentOrigin = "*"; | ||
var messageId = sendMessageRequest(parentWindow, "initialize", [version]); | ||
callbacks[messageId] = function (context, clientType) { | ||
frameContext = context; | ||
hostClientType = clientType; | ||
}; | ||
} | ||
finally { | ||
parentOrigin = null; | ||
} | ||
// Undocumented function used to clear state between unit tests | ||
this._uninitialize = function () { | ||
if (frameContext) { | ||
registerOnThemeChangeHandler(null); | ||
registerFullScreenHandler(null); | ||
registerBackButtonHandler(null); | ||
} | ||
if (frameContext === frameContexts.settings) { | ||
settings.registerOnSaveHandler(null); | ||
} | ||
if (frameContext === frameContexts.remove) { | ||
settings.registerOnRemoveHandler(null); | ||
} | ||
if (!isFramelessWindow) { | ||
currentWindow.removeEventListener("message", messageListener, false); | ||
} | ||
initializeCalled = false; | ||
parentWindow = null; | ||
parentOrigin = null; | ||
parentMessageQueue = []; | ||
childWindow = null; | ||
childOrigin = null; | ||
childMessageQueue = []; | ||
nextMessageId = 0; | ||
callbacks = {}; | ||
frameContext = null; | ||
hostClientType = null; | ||
isFramelessWindow = false; | ||
}; | ||
} | ||
/** | ||
* Initializes the library. This must be called before any other SDK calls | ||
* but after the frame is loaded successfully. | ||
*/ | ||
function _uninitialize() { } | ||
/** | ||
* Enable print capability to support printing page using Ctrl+P and cmd+P | ||
*/ | ||
function enablePrintCapability() { | ||
if (!printCapabilityEnabled) { | ||
printCapabilityEnabled = true; | ||
/** | ||
* Navigates back in the Teams client. See registerBackButtonHandler for more information on when | ||
* it's appropriate to use this method. | ||
*/ | ||
function navigateBack() { | ||
ensureInitialized(); | ||
// adding ctrl+P and cmd+P handler | ||
document.addEventListener("keydown", function (event) { | ||
if ((event.ctrlKey || event.metaKey) && event.keyCode === 80) { | ||
print(); | ||
event.cancelBubble = true; | ||
event.preventDefault(); | ||
event.stopImmediatePropagation(); | ||
let messageId = sendMessageRequest(parentWindow, "navigateBack", []); | ||
callbacks[messageId] = (success) => { | ||
if (!success) { | ||
throw new Error("Back navigation is not supported in the current client or context."); | ||
} | ||
}); | ||
}; | ||
} | ||
} | ||
/** | ||
* default print handler | ||
*/ | ||
function print() { | ||
window.print(); | ||
} | ||
/** | ||
* Retrieves the current context the frame is running in. | ||
* @param callback The callback to invoke when the {@link Context} object is retrieved. | ||
*/ | ||
function getContext(callback) { | ||
ensureInitialized(); | ||
var messageId = sendMessageRequest(parentWindow, "getContext"); | ||
callbacks[messageId] = callback; | ||
} | ||
/** | ||
* Registers a handler for theme changes. | ||
* Only one handler can be registered at a time. A subsequent registration replaces an existing registration. | ||
* @param handler The handler to invoke when the user changes their theme. | ||
*/ | ||
function registerOnThemeChangeHandler(handler) { | ||
ensureInitialized(); | ||
themeChangeHandler = handler; | ||
} | ||
function handleThemeChange(theme) { | ||
if (themeChangeHandler) { | ||
themeChangeHandler(theme); | ||
} | ||
if (childWindow) { | ||
sendMessageRequest(childWindow, "themeChange", [theme]); | ||
} | ||
} | ||
/** | ||
* Registers a handler for changes from or to full-screen view for a tab. | ||
* Only one handler can be registered at a time. A subsequent registration replaces an existing registration. | ||
* @param handler The handler to invoke when the user toggles full-screen view for a tab. | ||
*/ | ||
function registerFullScreenHandler(handler) { | ||
ensureInitialized(); | ||
fullScreenChangeHandler = handler; | ||
} | ||
function handleFullScreenChange(isFullScreen) { | ||
if (fullScreenChangeHandler) { | ||
fullScreenChangeHandler(isFullScreen); | ||
} | ||
} | ||
/** | ||
* Registers a handler for user presses of the Team client's back button. Experiences that maintain an internal | ||
* navigation stack should use this handler to navigate the user back within their frame. If an app finds | ||
* that after running its back button handler it cannot handle the event it should call the navigateBack | ||
* method to ask the Teams client to handle it instead. | ||
* @param handler The handler to invoke when the user presses their Team client's back button. | ||
*/ | ||
function registerBackButtonHandler(handler) { | ||
ensureInitialized(); | ||
backButtonPressHandler = handler; | ||
} | ||
function handleBackButtonPress() { | ||
if (!backButtonPressHandler || !backButtonPressHandler()) { | ||
navigateBack(); | ||
} | ||
} | ||
/** | ||
* Navigates back in the Teams client. See registerBackButtonHandler for more information on when | ||
* it's appropriate to use this method. | ||
*/ | ||
function navigateBack() { | ||
ensureInitialized(); | ||
var messageId = sendMessageRequest(parentWindow, "navigateBack", []); | ||
callbacks[messageId] = function (success) { | ||
if (!success) { | ||
throw new Error("Back navigation is not supported in the current client or context."); | ||
} | ||
}; | ||
} | ||
/** | ||
* Navigates the frame to a new cross-domain URL. The domain of this URL must match at least one of the | ||
* valid domains specified in the validDomains block of the manifest; otherwise, an exception will be | ||
* thrown. This function needs to be used only when navigating the frame to a URL in a different domain | ||
* than the current one in a way that keeps the app informed of the change and allows the SDK to | ||
* continue working. | ||
* @param url The URL to navigate the frame to. | ||
*/ | ||
function navigateCrossDomain(url) { | ||
ensureInitialized(frameContexts.content, frameContexts.settings, frameContexts.remove, frameContexts.task); | ||
var messageId = sendMessageRequest(parentWindow, "navigateCrossDomain", [ | ||
url | ||
]); | ||
callbacks[messageId] = function (success) { | ||
if (!success) { | ||
throw new Error("Cross-origin navigation is only supported for URLs matching the pattern registered in the manifest."); | ||
} | ||
}; | ||
} | ||
/** | ||
* Allows an app to retrieve for this user tabs that are owned by this app. | ||
* If no TabInstanceParameters are passed, the app defaults to favorite teams and favorite channels. | ||
* @param callback The callback to invoke when the {@link TabInstanceParameters} object is retrieved. | ||
* @param tabInstanceParameters OPTIONAL Flags that specify whether to scope call to favorite teams or channels. | ||
*/ | ||
function getTabInstances(callback, tabInstanceParameters) { | ||
ensureInitialized(); | ||
var messageId = sendMessageRequest(parentWindow, "getTabInstances", [ | ||
tabInstanceParameters | ||
]); | ||
callbacks[messageId] = callback; | ||
} | ||
/** | ||
* @private | ||
* Hide from docs | ||
* ------ | ||
* Allows an app to retrieve information of all user joined teams | ||
* @param callback The callback to invoke when the {@link TeamInstanceParameters} object is retrieved. | ||
* @param teamInstanceParameters OPTIONAL Flags that specify whether to scope call to favorite teams | ||
*/ | ||
function getUserJoinedTeams(callback, teamInstanceParameters) { | ||
ensureInitialized(); | ||
var messageId = sendMessageRequest(parentWindow, "getUserJoinedTeams", [ | ||
teamInstanceParameters | ||
]); | ||
callbacks[messageId] = callback; | ||
} | ||
/** | ||
* Allows an app to retrieve the most recently used tabs for this user. | ||
* @param callback The callback to invoke when the {@link TabInformation} object is retrieved. | ||
* @param tabInstanceParameters OPTIONAL Ignored, kept for future use | ||
*/ | ||
function getMruTabInstances(callback, tabInstanceParameters) { | ||
ensureInitialized(); | ||
var messageId = sendMessageRequest(parentWindow, "getMruTabInstances", [ | ||
tabInstanceParameters | ||
]); | ||
callbacks[messageId] = callback; | ||
} | ||
/** | ||
* Shares a deep link that a user can use to navigate back to a specific state in this page. | ||
* @param deepLinkParameters ID and label for the link and fallback URL. | ||
*/ | ||
function shareDeepLink(deepLinkParameters) { | ||
ensureInitialized(frameContexts.content); | ||
sendMessageRequest(parentWindow, "shareDeepLink", [ | ||
deepLinkParameters.subEntityId, | ||
deepLinkParameters.subEntityLabel, | ||
deepLinkParameters.subEntityWebUrl | ||
]); | ||
} | ||
/** | ||
* @private | ||
* Hide from docs. | ||
* ------ | ||
* Opens a client-friendly preview of the specified file. | ||
* @param file The file to preview. | ||
*/ | ||
function openFilePreview(filePreviewParameters) { | ||
ensureInitialized(frameContexts.content); | ||
var params = [ | ||
filePreviewParameters.entityId, | ||
filePreviewParameters.title, | ||
filePreviewParameters.description, | ||
filePreviewParameters.type, | ||
filePreviewParameters.objectUrl, | ||
filePreviewParameters.downloadUrl, | ||
filePreviewParameters.webPreviewUrl, | ||
filePreviewParameters.webEditUrl, | ||
filePreviewParameters.baseUrl, | ||
filePreviewParameters.editFile, | ||
filePreviewParameters.subEntityId | ||
]; | ||
sendMessageRequest(parentWindow, "openFilePreview", params); | ||
} | ||
/** | ||
* @private | ||
* Hide from docs. | ||
* ------ | ||
* download file. | ||
* @param file The file to download. | ||
*/ | ||
function showNotification(showNotificationParameters) { | ||
ensureInitialized(frameContexts.content); | ||
var params = [ | ||
showNotificationParameters.message, | ||
showNotificationParameters.isDownloadComplete | ||
]; | ||
sendMessageRequest(parentWindow, "showNotification", params); | ||
} | ||
/** | ||
* @private | ||
* Hide from docs. | ||
* ------ | ||
* Upload a custom App manifest directly to both team and personal scopes. | ||
* This method works just for the first party Apps. | ||
*/ | ||
function uploadCustomApp(manifestBlob) { | ||
ensureInitialized(); | ||
var messageId = sendMessageRequest(parentWindow, "uploadCustomApp", [ | ||
manifestBlob | ||
]); | ||
callbacks[messageId] = function (success, result) { | ||
if (!success) { | ||
throw new Error(result); | ||
} | ||
}; | ||
} | ||
/** | ||
* Navigates the Microsoft Teams app to the specified tab instance. | ||
* @param tabInstance The tab instance to navigate to. | ||
*/ | ||
function navigateToTab(tabInstance) { | ||
ensureInitialized(); | ||
var messageId = sendMessageRequest(parentWindow, "navigateToTab", [ | ||
tabInstance | ||
]); | ||
callbacks[messageId] = function (success) { | ||
if (!success) { | ||
throw new Error("Invalid internalTabInstanceId and/or channelId were/was provided"); | ||
} | ||
}; | ||
} | ||
/** | ||
* Namespace to interact with the settings-specific part of the SDK. | ||
* This object is usable only on the settings frame. | ||
*/ | ||
var settings; | ||
(function (settings) { | ||
var saveHandler; | ||
var removeHandler; | ||
handlers["settings.save"] = handleSave; | ||
handlers["settings.remove"] = handleRemove; | ||
microsoftTeams.navigateBack = navigateBack; | ||
/** | ||
* Sets the validity state for the settings. | ||
* The initial value is false, so the user cannot save the settings until this is called with true. | ||
* @param validityState Indicates whether the save or remove button is enabled for the user. | ||
* Navigates the frame to a new cross-domain URL. The domain of this URL must match at least one of the | ||
* valid domains specified in the validDomains block of the manifest; otherwise, an exception will be | ||
* thrown. This function needs to be used only when navigating the frame to a URL in a different domain | ||
* than the current one in a way that keeps the app informed of the change and allows the SDK to | ||
* continue working. | ||
* @param url The URL to navigate the frame to. | ||
*/ | ||
function setValidityState(validityState) { | ||
ensureInitialized(frameContexts.settings, frameContexts.remove); | ||
sendMessageRequest(parentWindow, "settings.setValidityState", [ | ||
validityState | ||
function navigateCrossDomain(url) { | ||
ensureInitialized(frameContexts.content, frameContexts.settings, frameContexts.remove, frameContexts.task); | ||
let messageId = sendMessageRequest(parentWindow, "navigateCrossDomain", [ | ||
url | ||
]); | ||
callbacks[messageId] = (success) => { | ||
if (!success) { | ||
throw new Error("Cross-origin navigation is only supported for URLs matching the pattern registered in the manifest."); | ||
} | ||
}; | ||
} | ||
settings.setValidityState = setValidityState; | ||
microsoftTeams.navigateCrossDomain = navigateCrossDomain; | ||
/** | ||
* Gets the settings for the current instance. | ||
* @param callback The callback to invoke when the {@link Settings} object is retrieved. | ||
* Allows an app to retrieve for this user tabs that are owned by this app. | ||
* If no TabInstanceParameters are passed, the app defaults to favorite teams and favorite channels. | ||
* @param callback The callback to invoke when the {@link TabInstanceParameters} object is retrieved. | ||
* @param tabInstanceParameters OPTIONAL Flags that specify whether to scope call to favorite teams or channels. | ||
*/ | ||
function getSettings(callback) { | ||
ensureInitialized(frameContexts.settings, frameContexts.remove); | ||
var messageId = sendMessageRequest(parentWindow, "settings.getSettings"); | ||
function getTabInstances(callback, tabInstanceParameters) { | ||
ensureInitialized(); | ||
let messageId = sendMessageRequest(parentWindow, "getTabInstances", [ | ||
tabInstanceParameters | ||
]); | ||
callbacks[messageId] = callback; | ||
} | ||
settings.getSettings = getSettings; | ||
microsoftTeams.getTabInstances = getTabInstances; | ||
/** | ||
* Sets the settings for the current instance. | ||
* This is an asynchronous operation; calls to getSettings are not guaranteed to reflect the changed state. | ||
* @param settings The desired settings for this instance. | ||
* @private | ||
* Hide from docs | ||
* ------ | ||
* Allows an app to retrieve information of all user joined teams | ||
* @param callback The callback to invoke when the {@link TeamInstanceParameters} object is retrieved. | ||
* @param teamInstanceParameters OPTIONAL Flags that specify whether to scope call to favorite teams | ||
*/ | ||
function setSettings(instanceSettings) { | ||
ensureInitialized(frameContexts.settings); | ||
sendMessageRequest(parentWindow, "settings.setSettings", [ | ||
instanceSettings | ||
function getUserJoinedTeams(callback, teamInstanceParameters) { | ||
ensureInitialized(); | ||
const messageId = sendMessageRequest(parentWindow, "getUserJoinedTeams", [ | ||
teamInstanceParameters | ||
]); | ||
callbacks[messageId] = callback; | ||
} | ||
settings.setSettings = setSettings; | ||
microsoftTeams.getUserJoinedTeams = getUserJoinedTeams; | ||
/** | ||
* Registers a handler for when the user attempts to save the settings. This handler should be used | ||
* to create or update the underlying resource powering the content. | ||
* The object passed to the handler must be used to notify whether to proceed with the save. | ||
* Only one handler can be registered at a time. A subsequent registration replaces an existing registration. | ||
* @param handler The handler to invoke when the user selects the save button. | ||
* Allows an app to retrieve the most recently used tabs for this user. | ||
* @param callback The callback to invoke when the {@link TabInformation} object is retrieved. | ||
* @param tabInstanceParameters OPTIONAL Ignored, kept for future use | ||
*/ | ||
function registerOnSaveHandler(handler) { | ||
ensureInitialized(frameContexts.settings); | ||
saveHandler = handler; | ||
function getMruTabInstances(callback, tabInstanceParameters) { | ||
ensureInitialized(); | ||
let messageId = sendMessageRequest(parentWindow, "getMruTabInstances", [ | ||
tabInstanceParameters | ||
]); | ||
callbacks[messageId] = callback; | ||
} | ||
settings.registerOnSaveHandler = registerOnSaveHandler; | ||
microsoftTeams.getMruTabInstances = getMruTabInstances; | ||
/** | ||
* Registers a handler for user attempts to remove content. This handler should be used | ||
* to remove the underlying resource powering the content. | ||
* The object passed to the handler must be used to indicate whether to proceed with the removal. | ||
* Only one handler may be registered at a time. Subsequent registrations will override the first. | ||
* @param handler The handler to invoke when the user selects the remove button. | ||
* Shares a deep link that a user can use to navigate back to a specific state in this page. | ||
* @param deepLinkParameters ID and label for the link and fallback URL. | ||
*/ | ||
function registerOnRemoveHandler(handler) { | ||
ensureInitialized(frameContexts.remove); | ||
removeHandler = handler; | ||
function shareDeepLink(deepLinkParameters) { | ||
ensureInitialized(frameContexts.content); | ||
sendMessageRequest(parentWindow, "shareDeepLink", [ | ||
deepLinkParameters.subEntityId, | ||
deepLinkParameters.subEntityLabel, | ||
deepLinkParameters.subEntityWebUrl | ||
]); | ||
} | ||
settings.registerOnRemoveHandler = registerOnRemoveHandler; | ||
function handleSave(result) { | ||
var saveEvent = new SaveEventImpl(result); | ||
if (saveHandler) { | ||
saveHandler(saveEvent); | ||
} | ||
else { | ||
// If no handler is registered, we assume success. | ||
saveEvent.notifySuccess(); | ||
} | ||
} | ||
microsoftTeams.shareDeepLink = shareDeepLink; | ||
/** | ||
* @private | ||
* Hide from docs, since this class is not directly used. | ||
* Hide from docs. | ||
* ------ | ||
* Opens a client-friendly preview of the specified file. | ||
* @param file The file to preview. | ||
*/ | ||
var SaveEventImpl = /** @class */ (function () { | ||
function SaveEventImpl(result) { | ||
this.notified = false; | ||
this.result = result ? result : {}; | ||
} | ||
SaveEventImpl.prototype.notifySuccess = function () { | ||
this.ensureNotNotified(); | ||
sendMessageRequest(parentWindow, "settings.save.success"); | ||
this.notified = true; | ||
}; | ||
SaveEventImpl.prototype.notifyFailure = function (reason) { | ||
this.ensureNotNotified(); | ||
sendMessageRequest(parentWindow, "settings.save.failure", [reason]); | ||
this.notified = true; | ||
}; | ||
SaveEventImpl.prototype.ensureNotNotified = function () { | ||
if (this.notified) { | ||
throw new Error("The SaveEvent may only notify success or failure once."); | ||
} | ||
}; | ||
return SaveEventImpl; | ||
}()); | ||
function handleRemove() { | ||
var removeEvent = new RemoveEventImpl(); | ||
if (removeHandler) { | ||
removeHandler(removeEvent); | ||
} | ||
else { | ||
// If no handler is registered, we assume success. | ||
removeEvent.notifySuccess(); | ||
} | ||
function openFilePreview(filePreviewParameters) { | ||
ensureInitialized(frameContexts.content); | ||
const params = [ | ||
filePreviewParameters.entityId, | ||
filePreviewParameters.title, | ||
filePreviewParameters.description, | ||
filePreviewParameters.type, | ||
filePreviewParameters.objectUrl, | ||
filePreviewParameters.downloadUrl, | ||
filePreviewParameters.webPreviewUrl, | ||
filePreviewParameters.webEditUrl, | ||
filePreviewParameters.baseUrl, | ||
filePreviewParameters.editFile, | ||
filePreviewParameters.subEntityId | ||
]; | ||
sendMessageRequest(parentWindow, "openFilePreview", params); | ||
} | ||
microsoftTeams.openFilePreview = openFilePreview; | ||
/** | ||
* @private | ||
* Hide from docs, since this class is not directly used. | ||
* Hide from docs. | ||
* ------ | ||
* download file. | ||
* @param file The file to download. | ||
*/ | ||
var RemoveEventImpl = /** @class */ (function () { | ||
function RemoveEventImpl() { | ||
this.notified = false; | ||
} | ||
RemoveEventImpl.prototype.notifySuccess = function () { | ||
this.ensureNotNotified(); | ||
sendMessageRequest(parentWindow, "settings.remove.success"); | ||
this.notified = true; | ||
}; | ||
RemoveEventImpl.prototype.notifyFailure = function (reason) { | ||
this.ensureNotNotified(); | ||
sendMessageRequest(parentWindow, "settings.remove.failure", [reason]); | ||
this.notified = true; | ||
}; | ||
RemoveEventImpl.prototype.ensureNotNotified = function () { | ||
if (this.notified) { | ||
throw new Error("The removeEvent may only notify success or failure once."); | ||
} | ||
}; | ||
return RemoveEventImpl; | ||
}()); | ||
})(settings || (settings = {})); | ||
/** | ||
* Namespace to interact with the authentication-specific part of the SDK. | ||
* This object is used for starting or completing authentication flows. | ||
*/ | ||
var authentication; | ||
(function (authentication) { | ||
var authParams; | ||
var authWindowMonitor; | ||
handlers["authentication.authenticate.success"] = handleSuccess; | ||
handlers["authentication.authenticate.failure"] = handleFailure; | ||
/** | ||
* Registers the authentication handlers | ||
* @param authenticateParameters A set of values that configure the authentication pop-up. | ||
*/ | ||
function registerAuthenticationHandlers(authenticateParameters) { | ||
authParams = authenticateParameters; | ||
function showNotification(showNotificationParameters) { | ||
ensureInitialized(frameContexts.content); | ||
const params = [ | ||
showNotificationParameters.message, | ||
showNotificationParameters.isDownloadComplete | ||
]; | ||
sendMessageRequest(parentWindow, "showNotification", params); | ||
} | ||
authentication.registerAuthenticationHandlers = registerAuthenticationHandlers; | ||
microsoftTeams.showNotification = showNotification; | ||
/** | ||
* Initiates an authentication request, which opens a new window with the specified settings. | ||
*/ | ||
function authenticate(authenticateParameters) { | ||
var authenticateParams = authenticateParameters !== undefined | ||
? authenticateParameters | ||
: authParams; | ||
ensureInitialized(frameContexts.content, frameContexts.settings, frameContexts.remove, frameContexts.task); | ||
if (hostClientType === "desktop" /* desktop */) { | ||
// Convert any relative URLs into absolute URLs before sending them over to the parent window. | ||
var link = document.createElement("a"); | ||
link.href = authenticateParams.url; | ||
// Ask the parent window to open an authentication window with the parameters provided by the caller. | ||
var messageId = sendMessageRequest(parentWindow, "authentication.authenticate", [link.href, authenticateParams.width, authenticateParams.height]); | ||
callbacks[messageId] = function (success, response) { | ||
if (success) { | ||
authenticateParams.successCallback(response); | ||
} | ||
else { | ||
authenticateParams.failureCallback(response); | ||
} | ||
}; | ||
} | ||
else { | ||
// Open an authentication window with the parameters provided by the caller. | ||
openAuthenticationWindow(authenticateParams); | ||
} | ||
} | ||
authentication.authenticate = authenticate; | ||
/** | ||
* @private | ||
* Hide from docs. | ||
* ------ | ||
* Requests an Azure AD token to be issued on behalf of the app. The token is acquired from the cache | ||
* if it is not expired. Otherwise a request is sent to Azure AD to obtain a new token. | ||
* @param authTokenRequest A set of values that configure the token request. | ||
* Upload a custom App manifest directly to both team and personal scopes. | ||
* This method works just for the first party Apps. | ||
*/ | ||
function getAuthToken(authTokenRequest) { | ||
function uploadCustomApp(manifestBlob) { | ||
ensureInitialized(); | ||
var messageId = sendMessageRequest(parentWindow, "authentication.getAuthToken", [authTokenRequest.resources]); | ||
callbacks[messageId] = function (success, result) { | ||
if (success) { | ||
authTokenRequest.successCallback(result); | ||
const messageId = sendMessageRequest(parentWindow, "uploadCustomApp", [ | ||
manifestBlob | ||
]); | ||
callbacks[messageId] = (success, result) => { | ||
if (!success) { | ||
throw new Error(result); | ||
} | ||
else { | ||
authTokenRequest.failureCallback(result); | ||
} | ||
}; | ||
} | ||
authentication.getAuthToken = getAuthToken; | ||
microsoftTeams.uploadCustomApp = uploadCustomApp; | ||
/** | ||
* @private | ||
* Hide from docs. | ||
* ------ | ||
* Requests the decoded Azure AD user identity on behalf of the app. | ||
* Navigates the Microsoft Teams app to the specified tab instance. | ||
* @param tabInstance The tab instance to navigate to. | ||
*/ | ||
function getUser(userRequest) { | ||
function navigateToTab(tabInstance) { | ||
ensureInitialized(); | ||
var messageId = sendMessageRequest(parentWindow, "authentication.getUser"); | ||
callbacks[messageId] = function (success, result) { | ||
if (success) { | ||
userRequest.successCallback(result); | ||
let messageId = sendMessageRequest(parentWindow, "navigateToTab", [ | ||
tabInstance | ||
]); | ||
callbacks[messageId] = (success) => { | ||
if (!success) { | ||
throw new Error("Invalid internalTabInstanceId and/or channelId were/was provided"); | ||
} | ||
else { | ||
userRequest.failureCallback(result); | ||
} | ||
}; | ||
} | ||
authentication.getUser = getUser; | ||
function closeAuthenticationWindow() { | ||
// Stop monitoring the authentication window | ||
stopAuthenticationWindowMonitor(); | ||
// Try to close the authentication window and clear all properties associated with it | ||
try { | ||
if (childWindow) { | ||
childWindow.close(); | ||
} | ||
microsoftTeams.navigateToTab = navigateToTab; | ||
/** | ||
* Namespace to interact with the settings-specific part of the SDK. | ||
* This object is usable only on the settings frame. | ||
*/ | ||
let settings; | ||
(function (settings) { | ||
let saveHandler; | ||
let removeHandler; | ||
handlers["settings.save"] = handleSave; | ||
handlers["settings.remove"] = handleRemove; | ||
/** | ||
* Sets the validity state for the settings. | ||
* The initial value is false, so the user cannot save the settings until this is called with true. | ||
* @param validityState Indicates whether the save or remove button is enabled for the user. | ||
*/ | ||
function setValidityState(validityState) { | ||
ensureInitialized(frameContexts.settings, frameContexts.remove); | ||
sendMessageRequest(parentWindow, "settings.setValidityState", [ | ||
validityState | ||
]); | ||
} | ||
finally { | ||
childWindow = null; | ||
childOrigin = null; | ||
settings.setValidityState = setValidityState; | ||
/** | ||
* Gets the settings for the current instance. | ||
* @param callback The callback to invoke when the {@link Settings} object is retrieved. | ||
*/ | ||
function getSettings(callback) { | ||
ensureInitialized(frameContexts.settings, frameContexts.remove); | ||
let messageId = sendMessageRequest(parentWindow, "settings.getSettings"); | ||
callbacks[messageId] = callback; | ||
} | ||
} | ||
function openAuthenticationWindow(authenticateParameters) { | ||
authParams = authenticateParameters; | ||
// Close the previously opened window if we have one | ||
closeAuthenticationWindow(); | ||
// Start with a sensible default size | ||
var width = authParams.width || 600; | ||
var height = authParams.height || 400; | ||
// Ensure that the new window is always smaller than our app's window so that it never fully covers up our app | ||
width = Math.min(width, currentWindow.outerWidth - 400); | ||
height = Math.min(height, currentWindow.outerHeight - 200); | ||
// Convert any relative URLs into absolute URLs before sending them over to the parent window | ||
var link = document.createElement("a"); | ||
link.href = authParams.url; | ||
// We are running in the browser, so we need to center the new window ourselves | ||
var left = typeof currentWindow.screenLeft !== "undefined" | ||
? currentWindow.screenLeft | ||
: currentWindow.screenX; | ||
var top = typeof currentWindow.screenTop !== "undefined" | ||
? currentWindow.screenTop | ||
: currentWindow.screenY; | ||
left += currentWindow.outerWidth / 2 - width / 2; | ||
top += currentWindow.outerHeight / 2 - height / 2; | ||
// Open a child window with a desired set of standard browser features | ||
childWindow = currentWindow.open(link.href, "_blank", "toolbar=no, location=yes, status=no, menubar=no, scrollbars=yes, top=" + | ||
top + | ||
", left=" + | ||
left + | ||
", width=" + | ||
width + | ||
", height=" + | ||
height); | ||
if (childWindow) { | ||
// Start monitoring the authentication window so that we can detect if it gets closed before the flow completes | ||
startAuthenticationWindowMonitor(); | ||
settings.getSettings = getSettings; | ||
/** | ||
* Sets the settings for the current instance. | ||
* This is an asynchronous operation; calls to getSettings are not guaranteed to reflect the changed state. | ||
* @param settings The desired settings for this instance. | ||
*/ | ||
function setSettings(instanceSettings) { | ||
ensureInitialized(frameContexts.settings); | ||
sendMessageRequest(parentWindow, "settings.setSettings", [ | ||
instanceSettings | ||
]); | ||
} | ||
else { | ||
// If we failed to open the window, fail the authentication flow | ||
handleFailure("FailedToOpenWindow"); | ||
settings.setSettings = setSettings; | ||
/** | ||
* Registers a handler for when the user attempts to save the settings. This handler should be used | ||
* to create or update the underlying resource powering the content. | ||
* The object passed to the handler must be used to notify whether to proceed with the save. | ||
* Only one handler can be registered at a time. A subsequent registration replaces an existing registration. | ||
* @param handler The handler to invoke when the user selects the save button. | ||
*/ | ||
function registerOnSaveHandler(handler) { | ||
ensureInitialized(frameContexts.settings); | ||
saveHandler = handler; | ||
} | ||
} | ||
function stopAuthenticationWindowMonitor() { | ||
if (authWindowMonitor) { | ||
clearInterval(authWindowMonitor); | ||
authWindowMonitor = 0; | ||
settings.registerOnSaveHandler = registerOnSaveHandler; | ||
/** | ||
* Registers a handler for user attempts to remove content. This handler should be used | ||
* to remove the underlying resource powering the content. | ||
* The object passed to the handler must be used to indicate whether to proceed with the removal. | ||
* Only one handler may be registered at a time. Subsequent registrations will override the first. | ||
* @param handler The handler to invoke when the user selects the remove button. | ||
*/ | ||
function registerOnRemoveHandler(handler) { | ||
ensureInitialized(frameContexts.remove); | ||
removeHandler = handler; | ||
} | ||
delete handlers["initialize"]; | ||
delete handlers["navigateCrossDomain"]; | ||
} | ||
function startAuthenticationWindowMonitor() { | ||
// Stop the previous window monitor if one is running | ||
stopAuthenticationWindowMonitor(); | ||
// Create an interval loop that | ||
// - Notifies the caller of failure if it detects that the authentication window is closed | ||
// - Keeps pinging the authentication window while it is open to re-establish | ||
// contact with any pages along the authentication flow that need to communicate | ||
// with us | ||
authWindowMonitor = currentWindow.setInterval(function () { | ||
if (!childWindow || childWindow.closed) { | ||
handleFailure("CancelledByUser"); | ||
settings.registerOnRemoveHandler = registerOnRemoveHandler; | ||
function handleSave(result) { | ||
let saveEvent = new SaveEventImpl(result); | ||
if (saveHandler) { | ||
saveHandler(saveEvent); | ||
} | ||
else { | ||
var savedChildOrigin = childOrigin; | ||
try { | ||
childOrigin = "*"; | ||
sendMessageRequest(childWindow, "ping"); | ||
// If no handler is registered, we assume success. | ||
saveEvent.notifySuccess(); | ||
} | ||
} | ||
/** | ||
* @private | ||
* Hide from docs, since this class is not directly used. | ||
*/ | ||
class SaveEventImpl { | ||
constructor(result) { | ||
this.notified = false; | ||
this.result = result ? result : {}; | ||
} | ||
notifySuccess() { | ||
this.ensureNotNotified(); | ||
sendMessageRequest(parentWindow, "settings.save.success"); | ||
this.notified = true; | ||
} | ||
notifyFailure(reason) { | ||
this.ensureNotNotified(); | ||
sendMessageRequest(parentWindow, "settings.save.failure", [reason]); | ||
this.notified = true; | ||
} | ||
ensureNotNotified() { | ||
if (this.notified) { | ||
throw new Error("The SaveEvent may only notify success or failure once."); | ||
} | ||
finally { | ||
childOrigin = savedChildOrigin; | ||
} | ||
} | ||
function handleRemove() { | ||
let removeEvent = new RemoveEventImpl(); | ||
if (removeHandler) { | ||
removeHandler(removeEvent); | ||
} | ||
else { | ||
// If no handler is registered, we assume success. | ||
removeEvent.notifySuccess(); | ||
} | ||
} | ||
/** | ||
* @private | ||
* Hide from docs, since this class is not directly used. | ||
*/ | ||
class RemoveEventImpl { | ||
constructor() { | ||
this.notified = false; | ||
} | ||
notifySuccess() { | ||
this.ensureNotNotified(); | ||
sendMessageRequest(parentWindow, "settings.remove.success"); | ||
this.notified = true; | ||
} | ||
notifyFailure(reason) { | ||
this.ensureNotNotified(); | ||
sendMessageRequest(parentWindow, "settings.remove.failure", [reason]); | ||
this.notified = true; | ||
} | ||
ensureNotNotified() { | ||
if (this.notified) { | ||
throw new Error("The removeEvent may only notify success or failure once."); | ||
} | ||
} | ||
}, 100); | ||
// Set up an initialize-message handler that gives the authentication window its frame context | ||
handlers["initialize"] = function () { | ||
return [frameContexts.authentication, hostClientType]; | ||
}; | ||
// Set up a navigateCrossDomain message handler that blocks cross-domain re-navigation attempts | ||
// in the authentication window. We could at some point choose to implement this method via a call to | ||
// authenticationWindow.location.href = url; however, we would first need to figure out how to | ||
// validate the URL against the tab's list of valid domains. | ||
handlers["navigateCrossDomain"] = function (url) { | ||
return false; | ||
}; | ||
} | ||
} | ||
})(settings = microsoftTeams.settings || (microsoftTeams.settings = {})); | ||
/** | ||
* Notifies the frame that initiated this authentication request that the request was successful. | ||
* This function is usable only on the authentication window. | ||
* This call causes the authentication window to be closed. | ||
* @param result Specifies a result for the authentication. If specified, the frame that initiated the authentication pop-up receives this value in its callback. | ||
* @param callbackUrl Specifies the url to redirect back to if the client is Win32 Outlook. | ||
* Namespace to interact with the authentication-specific part of the SDK. | ||
* This object is used for starting or completing authentication flows. | ||
*/ | ||
function notifySuccess(result, callbackUrl) { | ||
redirectIfWin32Outlook(callbackUrl, "result", result); | ||
ensureInitialized(frameContexts.authentication); | ||
sendMessageRequest(parentWindow, "authentication.authenticate.success", [ | ||
result | ||
]); | ||
// Wait for the message to be sent before closing the window | ||
waitForMessageQueue(parentWindow, function () { | ||
return setTimeout(function () { return currentWindow.close(); }, 200); | ||
}); | ||
} | ||
authentication.notifySuccess = notifySuccess; | ||
/** | ||
* Notifies the frame that initiated this authentication request that the request failed. | ||
* This function is usable only on the authentication window. | ||
* This call causes the authentication window to be closed. | ||
* @param result Specifies a result for the authentication. If specified, the frame that initiated the authentication pop-up receives this value in its callback. | ||
* @param callbackUrl Specifies the url to redirect back to if the client is Win32 Outlook. | ||
*/ | ||
function notifyFailure(reason, callbackUrl) { | ||
redirectIfWin32Outlook(callbackUrl, "reason", reason); | ||
ensureInitialized(frameContexts.authentication); | ||
sendMessageRequest(parentWindow, "authentication.authenticate.failure", [ | ||
reason | ||
]); | ||
// Wait for the message to be sent before closing the window | ||
waitForMessageQueue(parentWindow, function () { | ||
return setTimeout(function () { return currentWindow.close(); }, 200); | ||
}); | ||
} | ||
authentication.notifyFailure = notifyFailure; | ||
function handleSuccess(result) { | ||
try { | ||
if (authParams && authParams.successCallback) { | ||
authParams.successCallback(result); | ||
let authentication; | ||
(function (authentication) { | ||
let authParams; | ||
let authWindowMonitor; | ||
handlers["authentication.authenticate.success"] = handleSuccess; | ||
handlers["authentication.authenticate.failure"] = handleFailure; | ||
/** | ||
* Registers the authentication handlers | ||
* @param authenticateParameters A set of values that configure the authentication pop-up. | ||
*/ | ||
function registerAuthenticationHandlers(authenticateParameters) { | ||
authParams = authenticateParameters; | ||
} | ||
authentication.registerAuthenticationHandlers = registerAuthenticationHandlers; | ||
/** | ||
* Initiates an authentication request, which opens a new window with the specified settings. | ||
*/ | ||
function authenticate(authenticateParameters) { | ||
let authenticateParams = authenticateParameters !== undefined | ||
? authenticateParameters | ||
: authParams; | ||
ensureInitialized(frameContexts.content, frameContexts.settings, frameContexts.remove, frameContexts.task); | ||
if (hostClientType === "desktop" /* desktop */) { | ||
// Convert any relative URLs into absolute URLs before sending them over to the parent window. | ||
let link = document.createElement("a"); | ||
link.href = authenticateParams.url; | ||
// Ask the parent window to open an authentication window with the parameters provided by the caller. | ||
let messageId = sendMessageRequest(parentWindow, "authentication.authenticate", [link.href, authenticateParams.width, authenticateParams.height]); | ||
callbacks[messageId] = (success, response) => { | ||
if (success) { | ||
authenticateParams.successCallback(response); | ||
} | ||
else { | ||
authenticateParams.failureCallback(response); | ||
} | ||
}; | ||
} | ||
else { | ||
// Open an authentication window with the parameters provided by the caller. | ||
openAuthenticationWindow(authenticateParams); | ||
} | ||
} | ||
finally { | ||
authParams = null; | ||
closeAuthenticationWindow(); | ||
authentication.authenticate = authenticate; | ||
/** | ||
* @private | ||
* Hide from docs. | ||
* ------ | ||
* Requests an Azure AD token to be issued on behalf of the app. The token is acquired from the cache | ||
* if it is not expired. Otherwise a request is sent to Azure AD to obtain a new token. | ||
* @param authTokenRequest A set of values that configure the token request. | ||
*/ | ||
function getAuthToken(authTokenRequest) { | ||
ensureInitialized(); | ||
let messageId = sendMessageRequest(parentWindow, "authentication.getAuthToken", [authTokenRequest.resources]); | ||
callbacks[messageId] = (success, result) => { | ||
if (success) { | ||
authTokenRequest.successCallback(result); | ||
} | ||
else { | ||
authTokenRequest.failureCallback(result); | ||
} | ||
}; | ||
} | ||
} | ||
function handleFailure(reason) { | ||
try { | ||
if (authParams && authParams.failureCallback) { | ||
authParams.failureCallback(reason); | ||
authentication.getAuthToken = getAuthToken; | ||
/** | ||
* @private | ||
* Hide from docs. | ||
* ------ | ||
* Requests the decoded Azure AD user identity on behalf of the app. | ||
*/ | ||
function getUser(userRequest) { | ||
ensureInitialized(); | ||
let messageId = sendMessageRequest(parentWindow, "authentication.getUser"); | ||
callbacks[messageId] = (success, result) => { | ||
if (success) { | ||
userRequest.successCallback(result); | ||
} | ||
else { | ||
userRequest.failureCallback(result); | ||
} | ||
}; | ||
} | ||
authentication.getUser = getUser; | ||
function closeAuthenticationWindow() { | ||
// Stop monitoring the authentication window | ||
stopAuthenticationWindowMonitor(); | ||
// Try to close the authentication window and clear all properties associated with it | ||
try { | ||
if (childWindow) { | ||
childWindow.close(); | ||
} | ||
} | ||
finally { | ||
childWindow = null; | ||
childOrigin = null; | ||
} | ||
} | ||
finally { | ||
authParams = null; | ||
function openAuthenticationWindow(authenticateParameters) { | ||
authParams = authenticateParameters; | ||
// Close the previously opened window if we have one | ||
closeAuthenticationWindow(); | ||
// Start with a sensible default size | ||
let width = authParams.width || 600; | ||
let height = authParams.height || 400; | ||
// Ensure that the new window is always smaller than our app's window so that it never fully covers up our app | ||
width = Math.min(width, currentWindow.outerWidth - 400); | ||
height = Math.min(height, currentWindow.outerHeight - 200); | ||
// Convert any relative URLs into absolute URLs before sending them over to the parent window | ||
let link = document.createElement("a"); | ||
link.href = authParams.url; | ||
// We are running in the browser, so we need to center the new window ourselves | ||
let left = typeof currentWindow.screenLeft !== "undefined" | ||
? currentWindow.screenLeft | ||
: currentWindow.screenX; | ||
let top = typeof currentWindow.screenTop !== "undefined" | ||
? currentWindow.screenTop | ||
: currentWindow.screenY; | ||
left += currentWindow.outerWidth / 2 - width / 2; | ||
top += currentWindow.outerHeight / 2 - height / 2; | ||
// Open a child window with a desired set of standard browser features | ||
childWindow = currentWindow.open(link.href, "_blank", "toolbar=no, location=yes, status=no, menubar=no, scrollbars=yes, top=" + | ||
top + | ||
", left=" + | ||
left + | ||
", width=" + | ||
width + | ||
", height=" + | ||
height); | ||
if (childWindow) { | ||
// Start monitoring the authentication window so that we can detect if it gets closed before the flow completes | ||
startAuthenticationWindowMonitor(); | ||
} | ||
else { | ||
// If we failed to open the window, fail the authentication flow | ||
handleFailure("FailedToOpenWindow"); | ||
} | ||
} | ||
} | ||
/** | ||
* Validates that the callbackUrl param is a valid connector url, appends the result/reason and authSuccess/authFailure as URL fragments and redirects the window | ||
* @param callbackUrl - the connectors url to redirect to | ||
* @param key - "result" in case of success and "reason" in case of failure | ||
* @param value - the value of the passed result/reason parameter | ||
*/ | ||
function redirectIfWin32Outlook(callbackUrl, key, value) { | ||
if (callbackUrl) { | ||
var link = document.createElement("a"); | ||
link.href = decodeURIComponent(callbackUrl); | ||
if (link.host && | ||
link.host !== window.location.host && | ||
link.host === "outlook.office.com" && | ||
link.search.indexOf("client_type=Win32_Outlook") > -1) { | ||
if (key && key === "result") { | ||
if (value) { | ||
link.href = updateUrlParameter(link.href, "result", value); | ||
function stopAuthenticationWindowMonitor() { | ||
if (authWindowMonitor) { | ||
clearInterval(authWindowMonitor); | ||
authWindowMonitor = 0; | ||
} | ||
delete handlers["initialize"]; | ||
delete handlers["navigateCrossDomain"]; | ||
} | ||
function startAuthenticationWindowMonitor() { | ||
// Stop the previous window monitor if one is running | ||
stopAuthenticationWindowMonitor(); | ||
// Create an interval loop that | ||
// - Notifies the caller of failure if it detects that the authentication window is closed | ||
// - Keeps pinging the authentication window while it is open to re-establish | ||
// contact with any pages along the authentication flow that need to communicate | ||
// with us | ||
authWindowMonitor = currentWindow.setInterval(() => { | ||
if (!childWindow || childWindow.closed) { | ||
handleFailure("CancelledByUser"); | ||
} | ||
else { | ||
let savedChildOrigin = childOrigin; | ||
try { | ||
childOrigin = "*"; | ||
sendMessageRequest(childWindow, "ping"); | ||
} | ||
currentWindow.location.assign(updateUrlParameter(link.href, "authSuccess", "")); | ||
finally { | ||
childOrigin = savedChildOrigin; | ||
} | ||
} | ||
if (key && key === "reason") { | ||
if (value) { | ||
link.href = updateUrlParameter(link.href, "reason", value); | ||
}, 100); | ||
// Set up an initialize-message handler that gives the authentication window its frame context | ||
handlers["initialize"] = () => { | ||
return [frameContexts.authentication, hostClientType]; | ||
}; | ||
// Set up a navigateCrossDomain message handler that blocks cross-domain re-navigation attempts | ||
// in the authentication window. We could at some point choose to implement this method via a call to | ||
// authenticationWindow.location.href = url; however, we would first need to figure out how to | ||
// validate the URL against the tab's list of valid domains. | ||
handlers["navigateCrossDomain"] = (url) => { | ||
return false; | ||
}; | ||
} | ||
/** | ||
* Notifies the frame that initiated this authentication request that the request was successful. | ||
* This function is usable only on the authentication window. | ||
* This call causes the authentication window to be closed. | ||
* @param result Specifies a result for the authentication. If specified, the frame that initiated the authentication pop-up receives this value in its callback. | ||
* @param callbackUrl Specifies the url to redirect back to if the client is Win32 Outlook. | ||
*/ | ||
function notifySuccess(result, callbackUrl) { | ||
redirectIfWin32Outlook(callbackUrl, "result", result); | ||
ensureInitialized(frameContexts.authentication); | ||
sendMessageRequest(parentWindow, "authentication.authenticate.success", [ | ||
result | ||
]); | ||
// Wait for the message to be sent before closing the window | ||
waitForMessageQueue(parentWindow, () => setTimeout(() => currentWindow.close(), 200)); | ||
} | ||
authentication.notifySuccess = notifySuccess; | ||
/** | ||
* Notifies the frame that initiated this authentication request that the request failed. | ||
* This function is usable only on the authentication window. | ||
* This call causes the authentication window to be closed. | ||
* @param result Specifies a result for the authentication. If specified, the frame that initiated the authentication pop-up receives this value in its callback. | ||
* @param callbackUrl Specifies the url to redirect back to if the client is Win32 Outlook. | ||
*/ | ||
function notifyFailure(reason, callbackUrl) { | ||
redirectIfWin32Outlook(callbackUrl, "reason", reason); | ||
ensureInitialized(frameContexts.authentication); | ||
sendMessageRequest(parentWindow, "authentication.authenticate.failure", [ | ||
reason | ||
]); | ||
// Wait for the message to be sent before closing the window | ||
waitForMessageQueue(parentWindow, () => setTimeout(() => currentWindow.close(), 200)); | ||
} | ||
authentication.notifyFailure = notifyFailure; | ||
function handleSuccess(result) { | ||
try { | ||
if (authParams && authParams.successCallback) { | ||
authParams.successCallback(result); | ||
} | ||
} | ||
finally { | ||
authParams = null; | ||
closeAuthenticationWindow(); | ||
} | ||
} | ||
function handleFailure(reason) { | ||
try { | ||
if (authParams && authParams.failureCallback) { | ||
authParams.failureCallback(reason); | ||
} | ||
} | ||
finally { | ||
authParams = null; | ||
closeAuthenticationWindow(); | ||
} | ||
} | ||
/** | ||
* Validates that the callbackUrl param is a valid connector url, appends the result/reason and authSuccess/authFailure as URL fragments and redirects the window | ||
* @param callbackUrl - the connectors url to redirect to | ||
* @param key - "result" in case of success and "reason" in case of failure | ||
* @param value - the value of the passed result/reason parameter | ||
*/ | ||
function redirectIfWin32Outlook(callbackUrl, key, value) { | ||
if (callbackUrl) { | ||
let link = document.createElement("a"); | ||
link.href = decodeURIComponent(callbackUrl); | ||
if (link.host && | ||
link.host !== window.location.host && | ||
link.host === "outlook.office.com" && | ||
link.search.indexOf("client_type=Win32_Outlook") > -1) { | ||
if (key && key === "result") { | ||
if (value) { | ||
link.href = updateUrlParameter(link.href, "result", value); | ||
} | ||
currentWindow.location.assign(updateUrlParameter(link.href, "authSuccess", "")); | ||
} | ||
currentWindow.location.assign(updateUrlParameter(link.href, "authFailure", "")); | ||
if (key && key === "reason") { | ||
if (value) { | ||
link.href = updateUrlParameter(link.href, "reason", value); | ||
} | ||
currentWindow.location.assign(updateUrlParameter(link.href, "authFailure", "")); | ||
} | ||
} | ||
} | ||
} | ||
/** | ||
* Appends either result or reason as a fragment to the 'callbackUrl' | ||
* @param uri - the url to modify | ||
* @param key - the fragment key | ||
* @param value - the fragment value | ||
*/ | ||
function updateUrlParameter(uri, key, value) { | ||
let i = uri.indexOf("#"); | ||
let hash = i === -1 ? "#" : uri.substr(i); | ||
hash = hash + "&" + key + (value !== "" ? "=" + value : ""); | ||
uri = i === -1 ? uri : uri.substr(0, i); | ||
return uri + hash; | ||
} | ||
})(authentication = microsoftTeams.authentication || (microsoftTeams.authentication = {})); | ||
function ensureInitialized(...expectedFrameContexts) { | ||
if (!initializeCalled) { | ||
throw new Error("The library has not yet been initialized"); | ||
} | ||
if (frameContext && | ||
expectedFrameContexts && | ||
expectedFrameContexts.length > 0) { | ||
let found = false; | ||
for (let i = 0; i < expectedFrameContexts.length; i++) { | ||
if (expectedFrameContexts[i] === frameContext) { | ||
found = true; | ||
break; | ||
} | ||
} | ||
if (!found) { | ||
throw new Error("This call is not allowed in the '" + frameContext + "' context"); | ||
} | ||
} | ||
} | ||
/** | ||
* Appends either result or reason as a fragment to the 'callbackUrl' | ||
* @param uri - the url to modify | ||
* @param key - the fragment key | ||
* @param value - the fragment value | ||
*/ | ||
function updateUrlParameter(uri, key, value) { | ||
var i = uri.indexOf("#"); | ||
var hash = i === -1 ? "#" : uri.substr(i); | ||
hash = hash + "&" + key + (value !== "" ? "=" + value : ""); | ||
uri = i === -1 ? uri : uri.substr(0, i); | ||
return uri + hash; | ||
function processMessage(evt) { | ||
// Process only if we received a valid message | ||
if (!evt || !evt.data || typeof evt.data !== "object") { | ||
return; | ||
} | ||
// Process only if the message is coming from a different window and a valid origin | ||
let messageSource = evt.source || evt.originalEvent.source; | ||
let messageOrigin = evt.origin || evt.originalEvent.origin; | ||
if (messageSource === currentWindow || | ||
(messageOrigin !== currentWindow.location.origin && | ||
!validOriginRegExp.test(messageOrigin.toLowerCase()))) { | ||
return; | ||
} | ||
// Update our parent and child relationships based on this message | ||
updateRelationships(messageSource, messageOrigin); | ||
// Handle the message | ||
if (messageSource === parentWindow) { | ||
handleParentMessage(evt); | ||
} | ||
else if (messageSource === childWindow) { | ||
handleChildMessage(evt); | ||
} | ||
} | ||
})(authentication || (authentication = {})); | ||
function ensureInitialized() { | ||
var expectedFrameContexts = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
expectedFrameContexts[_i] = arguments[_i]; | ||
function updateRelationships(messageSource, messageOrigin) { | ||
// Determine whether the source of the message is our parent or child and update our | ||
// window and origin pointer accordingly | ||
if (!parentWindow || messageSource === parentWindow) { | ||
parentWindow = messageSource; | ||
parentOrigin = messageOrigin; | ||
} | ||
else if (!childWindow || messageSource === childWindow) { | ||
childWindow = messageSource; | ||
childOrigin = messageOrigin; | ||
} | ||
// Clean up pointers to closed parent and child windows | ||
if (parentWindow && parentWindow.closed) { | ||
parentWindow = null; | ||
parentOrigin = null; | ||
} | ||
if (childWindow && childWindow.closed) { | ||
childWindow = null; | ||
childOrigin = null; | ||
} | ||
// If we have any messages in our queue, send them now | ||
flushMessageQueue(parentWindow); | ||
flushMessageQueue(childWindow); | ||
} | ||
if (!initializeCalled) { | ||
throw new Error("The library has not yet been initialized"); | ||
} | ||
if (frameContext && | ||
expectedFrameContexts && | ||
expectedFrameContexts.length > 0) { | ||
var found = false; | ||
for (var i = 0; i < expectedFrameContexts.length; i++) { | ||
if (expectedFrameContexts[i] === frameContext) { | ||
found = true; | ||
break; | ||
function handleParentMessage(evt) { | ||
if ("id" in evt.data) { | ||
// Call any associated callbacks | ||
const message = evt.data; | ||
const callback = callbacks[message.id]; | ||
if (callback) { | ||
callback.apply(null, message.args); | ||
// Remove the callback to ensure that the callback is called only once and to free up memory. | ||
delete callbacks[message.id]; | ||
} | ||
} | ||
if (!found) { | ||
throw new Error("This call is not allowed in the '" + frameContext + "' context"); | ||
else if ("func" in evt.data) { | ||
// Delegate the request to the proper handler | ||
const message = evt.data; | ||
const handler = handlers[message.func]; | ||
if (handler) { | ||
// We don't expect any handler to respond at this point | ||
handler.apply(this, message.args); | ||
} | ||
} | ||
} | ||
} | ||
function processMessage(evt) { | ||
// Process only if we received a valid message | ||
if (!evt || !evt.data || typeof evt.data !== "object") { | ||
return; | ||
function handleChildMessage(evt) { | ||
if ("id" in evt.data && "func" in evt.data) { | ||
// Try to delegate the request to the proper handler | ||
const message = evt.data; | ||
const handler = handlers[message.func]; | ||
if (handler) { | ||
let result = handler.apply(this, message.args); | ||
if (result) { | ||
sendMessageResponse(childWindow, message.id, Array.isArray(result) ? result : [result]); | ||
} | ||
} | ||
else { | ||
// Proxy to parent | ||
let messageId = sendMessageRequest(parentWindow, message.func, message.args); | ||
// tslint:disable-next-line:no-any | ||
callbacks[messageId] = (...args) => { | ||
if (childWindow) { | ||
sendMessageResponse(childWindow, message.id, args); | ||
} | ||
}; | ||
} | ||
} | ||
} | ||
// Process only if the message is coming from a different window and a valid origin | ||
var messageSource = evt.source || evt.originalEvent.source; | ||
var messageOrigin = evt.origin || evt.originalEvent.origin; | ||
if (messageSource === currentWindow || | ||
(messageOrigin !== currentWindow.location.origin && | ||
!validOriginRegExp.test(messageOrigin.toLowerCase()))) { | ||
return; | ||
function getTargetMessageQueue(targetWindow) { | ||
return targetWindow === parentWindow | ||
? parentMessageQueue | ||
: targetWindow === childWindow | ||
? childMessageQueue | ||
: []; | ||
} | ||
// Update our parent and child relationships based on this message | ||
updateRelationships(messageSource, messageOrigin); | ||
// Handle the message | ||
if (messageSource === parentWindow) { | ||
handleParentMessage(evt); | ||
function getTargetOrigin(targetWindow) { | ||
return targetWindow === parentWindow | ||
? parentOrigin | ||
: targetWindow === childWindow | ||
? childOrigin | ||
: null; | ||
} | ||
else if (messageSource === childWindow) { | ||
handleChildMessage(evt); | ||
} | ||
} | ||
function updateRelationships(messageSource, messageOrigin) { | ||
// Determine whether the source of the message is our parent or child and update our | ||
// window and origin pointer accordingly | ||
if (!parentWindow || messageSource === parentWindow) { | ||
parentWindow = messageSource; | ||
parentOrigin = messageOrigin; | ||
} | ||
else if (!childWindow || messageSource === childWindow) { | ||
childWindow = messageSource; | ||
childOrigin = messageOrigin; | ||
} | ||
// Clean up pointers to closed parent and child windows | ||
if (parentWindow && parentWindow.closed) { | ||
parentWindow = null; | ||
parentOrigin = null; | ||
} | ||
if (childWindow && childWindow.closed) { | ||
childWindow = null; | ||
childOrigin = null; | ||
} | ||
// If we have any messages in our queue, send them now | ||
flushMessageQueue(parentWindow); | ||
flushMessageQueue(childWindow); | ||
} | ||
function handleParentMessage(evt) { | ||
if ("id" in evt.data) { | ||
// Call any associated callbacks | ||
var message = evt.data; | ||
var callback = callbacks[message.id]; | ||
if (callback) { | ||
callback.apply(null, message.args); | ||
// Remove the callback to ensure that the callback is called only once and to free up memory. | ||
delete callbacks[message.id]; | ||
function flushMessageQueue(targetWindow) { | ||
let targetOrigin = getTargetOrigin(targetWindow); | ||
let targetMessageQueue = getTargetMessageQueue(targetWindow); | ||
while (targetWindow && targetOrigin && targetMessageQueue.length > 0) { | ||
targetWindow.postMessage(targetMessageQueue.shift(), targetOrigin); | ||
} | ||
} | ||
else if ("func" in evt.data) { | ||
// Delegate the request to the proper handler | ||
var message = evt.data; | ||
var handler = handlers[message.func]; | ||
if (handler) { | ||
// We don't expect any handler to respond at this point | ||
handler.apply(this, message.args); | ||
} | ||
function waitForMessageQueue(targetWindow, callback) { | ||
let messageQueueMonitor = currentWindow.setInterval(() => { | ||
if (getTargetMessageQueue(targetWindow).length === 0) { | ||
clearInterval(messageQueueMonitor); | ||
callback(); | ||
} | ||
}, 100); | ||
} | ||
} | ||
function handleChildMessage(evt) { | ||
if ("id" in evt.data && "func" in evt.data) { | ||
// Try to delegate the request to the proper handler | ||
var message_1 = evt.data; | ||
var handler = handlers[message_1.func]; | ||
if (handler) { | ||
var result = handler.apply(this, message_1.args); | ||
if (result) { | ||
sendMessageResponse(childWindow, message_1.id, Array.isArray(result) ? result : [result]); | ||
function sendMessageRequest(targetWindow, actionName, | ||
// tslint:disable-next-line: no-any | ||
args) { | ||
let request = createMessageRequest(actionName, args); | ||
if (isFramelessWindow) { | ||
if (currentWindow && currentWindow.nativeInterface) { | ||
currentWindow.nativeInterface.framelessPostMessage(JSON.stringify(request)); | ||
} | ||
} | ||
else { | ||
// Proxy to parent | ||
var messageId = sendMessageRequest(parentWindow, message_1.func, message_1.args); | ||
// tslint:disable-next-line:no-any | ||
callbacks[messageId] = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
if (childWindow) { | ||
sendMessageResponse(childWindow, message_1.id, args); | ||
} | ||
}; | ||
let targetOrigin = getTargetOrigin(targetWindow); | ||
// If the target window isn't closed and we already know its origin, send the message right away; otherwise, | ||
// queue the message and send it after the origin is established | ||
if (targetWindow && targetOrigin) { | ||
targetWindow.postMessage(request, targetOrigin); | ||
} | ||
else { | ||
getTargetMessageQueue(targetWindow).push(request); | ||
} | ||
} | ||
return request.id; | ||
} | ||
} | ||
function getTargetMessageQueue(targetWindow) { | ||
return targetWindow === parentWindow | ||
? parentMessageQueue | ||
: targetWindow === childWindow | ||
? childMessageQueue | ||
: []; | ||
} | ||
function getTargetOrigin(targetWindow) { | ||
return targetWindow === parentWindow | ||
? parentOrigin | ||
: targetWindow === childWindow | ||
? childOrigin | ||
: null; | ||
} | ||
function flushMessageQueue(targetWindow) { | ||
var targetOrigin = getTargetOrigin(targetWindow); | ||
var targetMessageQueue = getTargetMessageQueue(targetWindow); | ||
while (targetWindow && targetOrigin && targetMessageQueue.length > 0) { | ||
targetWindow.postMessage(targetMessageQueue.shift(), targetOrigin); | ||
/** | ||
* @private | ||
* Internal use only | ||
* Sends a custom action message to Teams. | ||
* @param actionName Specifies name of the custom action to be sent | ||
* @param args Specifies additional arguments passed to the action | ||
* @returns id of sent message | ||
*/ | ||
function sendCustomMessage(actionName, | ||
// tslint:disable-next-line:no-any | ||
args) { | ||
ensureInitialized(); | ||
return sendMessageRequest(parentWindow, actionName, args); | ||
} | ||
} | ||
function waitForMessageQueue(targetWindow, callback) { | ||
var messageQueueMonitor = currentWindow.setInterval(function () { | ||
if (getTargetMessageQueue(targetWindow).length === 0) { | ||
clearInterval(messageQueueMonitor); | ||
callback(); | ||
} | ||
}, 100); | ||
} | ||
function sendMessageRequest(targetWindow, actionName, | ||
// tslint:disable-next-line: no-any | ||
args) { | ||
var request = createMessageRequest(actionName, args); | ||
if (isFramelessWindow) { | ||
if (currentWindow && currentWindow.nativeInterface) { | ||
currentWindow.nativeInterface.framelessPostMessage(JSON.stringify(request)); | ||
} | ||
} | ||
else { | ||
var targetOrigin = getTargetOrigin(targetWindow); | ||
// If the target window isn't closed and we already know its origin, send the message right away; otherwise, | ||
// queue the message and send it after the origin is established | ||
microsoftTeams.sendCustomMessage = sendCustomMessage; | ||
function sendMessageResponse(targetWindow, id, | ||
// tslint:disable-next-line:no-any | ||
args) { | ||
let response = createMessageResponse(id, args); | ||
let targetOrigin = getTargetOrigin(targetWindow); | ||
if (targetWindow && targetOrigin) { | ||
targetWindow.postMessage(request, targetOrigin); | ||
targetWindow.postMessage(response, targetOrigin); | ||
} | ||
else { | ||
getTargetMessageQueue(targetWindow).push(request); | ||
} | ||
} | ||
return request.id; | ||
} | ||
/** | ||
* @private | ||
* Internal use only | ||
* Sends a custom action message to Teams. | ||
* @param actionName Specifies name of the custom action to be sent | ||
* @param args Specifies additional arguments passed to the action | ||
* @returns id of sent message | ||
*/ | ||
function sendCustomMessage(actionName, | ||
// tslint:disable-next-line:no-any | ||
args) { | ||
ensureInitialized(); | ||
return sendMessageRequest(parentWindow, actionName, args); | ||
} | ||
function sendMessageResponse(targetWindow, id, | ||
// tslint:disable-next-line:no-any | ||
args) { | ||
var response = createMessageResponse(id, args); | ||
var targetOrigin = getTargetOrigin(targetWindow); | ||
if (targetWindow && targetOrigin) { | ||
targetWindow.postMessage(response, targetOrigin); | ||
// tslint:disable-next-line:no-any | ||
function createMessageRequest(func, args) { | ||
return { | ||
id: nextMessageId++, | ||
func: func, | ||
args: args || [] | ||
}; | ||
} | ||
} | ||
// tslint:disable-next-line:no-any | ||
function createMessageRequest(func, args) { | ||
return { | ||
id: nextMessageId++, | ||
func: func, | ||
args: args || [] | ||
}; | ||
} | ||
// tslint:disable-next-line:no-any | ||
function createMessageResponse(id, args) { | ||
return { | ||
id: id, | ||
args: args || [] | ||
}; | ||
} | ||
/** | ||
* Namespace to interact with the task module-specific part of the SDK. | ||
* This object is usable only on the content frame. | ||
*/ | ||
var tasks; | ||
(function (tasks) { | ||
// tslint:disable-next-line:no-any | ||
function createMessageResponse(id, args) { | ||
return { | ||
id: id, | ||
args: args || [] | ||
}; | ||
} | ||
/** | ||
* Allows an app to open the task module. | ||
* @param taskInfo An object containing the parameters of the task module | ||
* @param submitHandler Handler to call when the task module is completed | ||
* Namespace to interact with the task module-specific part of the SDK. | ||
* This object is usable only on the content frame. | ||
*/ | ||
function startTask(taskInfo, submitHandler) { | ||
ensureInitialized(frameContexts.content); | ||
var messageId = sendMessageRequest(parentWindow, "tasks.startTask", [ | ||
taskInfo | ||
]); | ||
callbacks[messageId] = submitHandler; | ||
} | ||
tasks.startTask = startTask; | ||
let tasks; | ||
(function (tasks) { | ||
/** | ||
* Allows an app to open the task module. | ||
* @param taskInfo An object containing the parameters of the task module | ||
* @param submitHandler Handler to call when the task module is completed | ||
*/ | ||
function startTask(taskInfo, submitHandler) { | ||
ensureInitialized(frameContexts.content); | ||
let messageId = sendMessageRequest(parentWindow, "tasks.startTask", [ | ||
taskInfo | ||
]); | ||
callbacks[messageId] = submitHandler; | ||
} | ||
tasks.startTask = startTask; | ||
/** | ||
* Submit the task module. | ||
* @param result Contains the result to be sent to the bot or the app. Typically a JSON object or a serialized version of it | ||
* @param appIds Helps to validate that the call originates from the same appId as the one that invoked the task module | ||
*/ | ||
function submitTask(result, appIds) { | ||
ensureInitialized(frameContexts.content, frameContexts.task); | ||
// Send tasks.completeTask instead of tasks.submitTask message for backward compatibility with Mobile clients | ||
sendMessageRequest(parentWindow, "tasks.completeTask", [ | ||
result, | ||
Array.isArray(appIds) ? appIds : [appIds] | ||
]); | ||
} | ||
tasks.submitTask = submitTask; | ||
})(tasks = microsoftTeams.tasks || (microsoftTeams.tasks = {})); | ||
/** | ||
* Submit the task module. | ||
* @param result Contains the result to be sent to the bot or the app. Typically a JSON object or a serialized version of it | ||
* @param appIds Helps to validate that the call originates from the same appId as the one that invoked the task module | ||
* @private | ||
* Hide from docs | ||
* ------ | ||
* Allows an app to retrieve information of all chat members | ||
* Because a malicious party run your content in a browser, this value should | ||
* be used only as a hint as to who the members are and never as proof of membership. | ||
* @param callback The callback to invoke when the {@link ChatMembersInformation} object is retrieved. | ||
*/ | ||
function submitTask(result, appIds) { | ||
ensureInitialized(frameContexts.content, frameContexts.task); | ||
// Send tasks.completeTask instead of tasks.submitTask message for backward compatibility with Mobile clients | ||
sendMessageRequest(parentWindow, "tasks.completeTask", [ | ||
result, | ||
Array.isArray(appIds) ? appIds : [appIds] | ||
]); | ||
function getChatMembers(callback) { | ||
ensureInitialized(); | ||
const messageId = sendMessageRequest(parentWindow, "getChatMembers"); | ||
callbacks[messageId] = callback; | ||
} | ||
tasks.submitTask = submitTask; | ||
})(tasks || (tasks = {})); | ||
/** | ||
* @private | ||
* Hide from docs | ||
* ------ | ||
* Allows an app to retrieve information of all chat members | ||
* Because a malicious party run your content in a browser, this value should | ||
* be used only as a hint as to who the members are and never as proof of membership. | ||
* @param callback The callback to invoke when the {@link ChatMembersInformation} object is retrieved. | ||
*/ | ||
function getChatMembers(callback) { | ||
ensureInitialized(); | ||
var messageId = sendMessageRequest(parentWindow, "getChatMembers"); | ||
callbacks[messageId] = callback; | ||
} | ||
microsoftTeams.getChatMembers = getChatMembers; | ||
})(microsoftTeams = exports.microsoftTeams || (exports.microsoftTeams = {})); | ||
// CONCATENATED MODULE: ./index.ts | ||
/* concated harmony reexport menus */__webpack_require__.d(__webpack_exports__, "menus", function() { return menus; }); | ||
/* concated harmony reexport initialize */__webpack_require__.d(__webpack_exports__, "initialize", function() { return initialize; }); | ||
/* concated harmony reexport _uninitialize */__webpack_require__.d(__webpack_exports__, "_uninitialize", function() { return _uninitialize; }); | ||
/* concated harmony reexport enablePrintCapability */__webpack_require__.d(__webpack_exports__, "enablePrintCapability", function() { return enablePrintCapability; }); | ||
/* concated harmony reexport print */__webpack_require__.d(__webpack_exports__, "print", function() { return print; }); | ||
/* concated harmony reexport getContext */__webpack_require__.d(__webpack_exports__, "getContext", function() { return getContext; }); | ||
/* concated harmony reexport registerOnThemeChangeHandler */__webpack_require__.d(__webpack_exports__, "registerOnThemeChangeHandler", function() { return registerOnThemeChangeHandler; }); | ||
/* concated harmony reexport registerFullScreenHandler */__webpack_require__.d(__webpack_exports__, "registerFullScreenHandler", function() { return registerFullScreenHandler; }); | ||
/* concated harmony reexport registerBackButtonHandler */__webpack_require__.d(__webpack_exports__, "registerBackButtonHandler", function() { return registerBackButtonHandler; }); | ||
/* concated harmony reexport navigateBack */__webpack_require__.d(__webpack_exports__, "navigateBack", function() { return navigateBack; }); | ||
/* concated harmony reexport navigateCrossDomain */__webpack_require__.d(__webpack_exports__, "navigateCrossDomain", function() { return navigateCrossDomain; }); | ||
/* concated harmony reexport getTabInstances */__webpack_require__.d(__webpack_exports__, "getTabInstances", function() { return getTabInstances; }); | ||
/* concated harmony reexport getUserJoinedTeams */__webpack_require__.d(__webpack_exports__, "getUserJoinedTeams", function() { return getUserJoinedTeams; }); | ||
/* concated harmony reexport getMruTabInstances */__webpack_require__.d(__webpack_exports__, "getMruTabInstances", function() { return getMruTabInstances; }); | ||
/* concated harmony reexport shareDeepLink */__webpack_require__.d(__webpack_exports__, "shareDeepLink", function() { return shareDeepLink; }); | ||
/* concated harmony reexport openFilePreview */__webpack_require__.d(__webpack_exports__, "openFilePreview", function() { return openFilePreview; }); | ||
/* concated harmony reexport showNotification */__webpack_require__.d(__webpack_exports__, "showNotification", function() { return showNotification; }); | ||
/* concated harmony reexport uploadCustomApp */__webpack_require__.d(__webpack_exports__, "uploadCustomApp", function() { return uploadCustomApp; }); | ||
/* concated harmony reexport navigateToTab */__webpack_require__.d(__webpack_exports__, "navigateToTab", function() { return navigateToTab; }); | ||
/* concated harmony reexport settings */__webpack_require__.d(__webpack_exports__, "settings", function() { return settings; }); | ||
/* concated harmony reexport authentication */__webpack_require__.d(__webpack_exports__, "authentication", function() { return authentication; }); | ||
/* concated harmony reexport sendCustomMessage */__webpack_require__.d(__webpack_exports__, "sendCustomMessage", function() { return sendCustomMessage; }); | ||
/* concated harmony reexport tasks */__webpack_require__.d(__webpack_exports__, "tasks", function() { return tasks; }); | ||
/* concated harmony reexport getChatMembers */__webpack_require__.d(__webpack_exports__, "getChatMembers", function() { return getChatMembers; }); | ||
/***/ }) | ||
/******/ ]); | ||
//# sourceMappingURL=MicrosoftTeams.js.map |
@@ -1,1 +0,1 @@ | ||
!function(t){var n={};function e(i){if(n[i])return n[i].exports;var o=n[i]={i:i,l:!1,exports:{}};return t[i].call(o.exports,o,o.exports,e),o.l=!0,o.exports}e.m=t,e.c=n,e.d=function(t,n,i){e.o(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:i})},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},e.t=function(t,n){if(1&n&&(t=e(t)),8&n)return t;if(4&n&&"object"==typeof t&&t&&t.__esModule)return t;var i=Object.create(null);if(e.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:t}),2&n&&"string"!=typeof t)for(var o in t)e.d(i,o,function(n){return t[n]}.bind(null,o));return i},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},e.p="",e(e.s=0)}([function(t,n,e){"use strict";e.r(n),String.prototype.startsWith||(String.prototype.startsWith=function(t,n){return this.substr(!n||n<0?0:+n,t.length)===t});var i="1.3.6";function o(t){for(var n="^",e=t.split("."),i=0;i<e.length;i++)n+=(i>0?"[.]":"")+e[i].replace("*","[^/^.]+");return n+="$"}var r,a=function(t){for(var n="",e=0;e<t.length;e++)n+=(0===e?"":"|")+o(t[e]);return new RegExp(n)}(["https://teams.microsoft.com","https://teams.microsoft.us","https://int.teams.microsoft.com","https://devspaces.skype.com","https://ssauth.skype.com","http://dev.local","https://msft.spoppe.com","https://*.sharepoint.com","https://*.sharepoint-df.com","https://*.sharepointonline.com","https://outlook.office.com","https://outlook-sdf.office.com"]),s={},u={settings:"settings",content:"content",authentication:"authentication",remove:"remove",task:"task"};!function(t){var n,e,i,o=function(){return function(){this.enabled=!0}}();t.MenuItem=o,function(t){t.dropDown="dropDown",t.popOver="popOver"}(t.MenuListType||(t.MenuListType={})),s.navBarMenuItemPress=function(t){n&&n(t)||(X(),Z(f,"handleNavBarMenuItemPress",[t]))},s.actionMenuItemPress=function(t){e&&e(t)||(X(),Z(f,"handleActionMenuItemPress",[t]))},s.setModuleView=function(t){i&&i(t)||(X(),Z(f,"viewConfigItemPress",[t]))},t.setUpViews=function(t,n){X(),i=n,Z(f,"setUpViews",[t])},t.setNavBarMenu=function(t,e){X(),n=e,Z(f,"setNavBarMenu",[t])},t.showActionMenu=function(t,n){X(),e=n,Z(f,"showActionMenu",[t])}}(r||(r={}));var c,f,l,d,h,v,p,g,m,y,b,w,k,C=!1,T=!1,M=[],I=[],S=0,E={},N=!1;function O(t){if(void 0===t&&(t=window),!C){C=!0;var n=function(t){return function(t){if(!t||!t.data||"object"!=typeof t.data)return;var n=t.source||t.originalEvent.source,e=t.origin||t.originalEvent.origin;if(n===c||e!==c.location.origin&&!a.test(e.toLowerCase()))return;(function(t,n){f&&t!==f?d&&t!==d||(d=t,h=n):(f=t,l=n),f&&f.closed&&(f=null,l=null),d&&d.closed&&(d=null,h=null),G(f),G(d)})(n,e),n===f?Y(t):n===d&&function(t){if("id"in t.data&&"func"in t.data){var n=t.data,e=s[n.func];if(e){var i=e.apply(this,n.args);i&&nt(d,n.id,Array.isArray(i)?i:[i])}else{var o=Z(f,n.func,n.args);E[o]=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];d&&nt(d,n.id,t)}}}}(t)}(t)};(f=(c=t).parent!==c.self?c.parent:c.opener)?c.addEventListener("message",n,!1):(T=!0,window.onNativeMessage=Y);try{l="*";var e=Z(f,"initialize",[i]);E[e]=function(t,n){v=t,p=n}}finally{l=null}this._uninitialize=function(){v&&(B(null),L(null),_(null)),v===u.settings&&b.registerOnSaveHandler(null),v===u.remove&&b.registerOnRemoveHandler(null),T||c.removeEventListener("message",n,!1),C=!1,f=null,l=null,M=[],d=null,h=null,I=[],S=0,E={},v=null,p=null,T=!1}}}function P(){}function U(){N||(N=!0,X(),document.addEventListener("keydown",function(t){(t.ctrlKey||t.metaKey)&&80===t.keyCode&&(x(),t.cancelBubble=!0,t.preventDefault(),t.stopImmediatePropagation())}))}function x(){window.print()}function A(t){X();var n=Z(f,"getContext");E[n]=t}function B(t){X(),g=t}function L(t){X(),m=t}function _(t){X(),y=t}function D(){X();var t=Z(f,"navigateBack",[]);E[t]=function(t){if(!t)throw new Error("Back navigation is not supported in the current client or context.")}}function H(t){X(u.content,u.settings,u.remove,u.task);var n=Z(f,"navigateCrossDomain",[t]);E[n]=function(t){if(!t)throw new Error("Cross-origin navigation is only supported for URLs matching the pattern registered in the manifest.")}}function j(t,n){X();var e=Z(f,"getTabInstances",[n]);E[e]=t}function F(t,n){X();var e=Z(f,"getUserJoinedTeams",[n]);E[e]=t}function z(t,n){X();var e=Z(f,"getMruTabInstances",[n]);E[e]=t}function W(t){X(u.content),Z(f,"shareDeepLink",[t.subEntityId,t.subEntityLabel,t.subEntityWebUrl])}function R(t){X(u.content);var n=[t.entityId,t.title,t.description,t.type,t.objectUrl,t.downloadUrl,t.webPreviewUrl,t.webEditUrl,t.baseUrl,t.editFile,t.subEntityId];Z(f,"openFilePreview",n)}function V(t){X(u.content);var n=[t.message,t.isDownloadComplete];Z(f,"showNotification",n)}function J(t){X();var n=Z(f,"uploadCustomApp",[t]);E[n]=function(t,n){if(!t)throw new Error(n)}}function K(t){X();var n=Z(f,"navigateToTab",[t]);E[n]=function(t){if(!t)throw new Error("Invalid internalTabInstanceId and/or channelId were/was provided")}}function X(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];if(!C)throw new Error("The library has not yet been initialized");if(v&&t&&t.length>0){for(var e=!1,i=0;i<t.length;i++)if(t[i]===v){e=!0;break}if(!e)throw new Error("This call is not allowed in the '"+v+"' context")}}function Y(t){if("id"in t.data){var n=t.data,e=E[n.id];e&&(e.apply(null,n.args),delete E[n.id])}else if("func"in t.data){n=t.data;var i=s[n.func];i&&i.apply(this,n.args)}}function $(t){return t===f?M:t===d?I:[]}function q(t){return t===f?l:t===d?h:null}function G(t){for(var n=q(t),e=$(t);t&&n&&e.length>0;)t.postMessage(e.shift(),n)}function Q(t,n){var e=c.setInterval(function(){0===$(t).length&&(clearInterval(e),n())},100)}function Z(t,n,e){var i=function(t,n){return{id:S++,func:t,args:n||[]}}(n,e);if(T)c&&c.nativeInterface&&c.nativeInterface.framelessPostMessage(JSON.stringify(i));else{var o=q(t);t&&o?t.postMessage(i,o):$(t).push(i)}return i.id}function tt(t,n){return X(),Z(f,t,n)}function nt(t,n,e){var i=function(t,n){return{id:t,args:n||[]}}(n,e),o=q(t);t&&o&&t.postMessage(i,o)}function et(t){X();var n=Z(f,"getChatMembers");E[n]=t}s.themeChange=function(t){g&&g(t);d&&Z(d,"themeChange",[t])},s.fullScreenChange=function(t){m&&m(t)},s.backButtonPress=function(){y&&y()||D()},function(t){var n,e;s["settings.save"]=function(t){var e=new i(t);n?n(e):e.notifySuccess()},s["settings.remove"]=function(){var t=new o;e?e(t):t.notifySuccess()},t.setValidityState=function(t){X(u.settings,u.remove),Z(f,"settings.setValidityState",[t])},t.getSettings=function(t){X(u.settings,u.remove);var n=Z(f,"settings.getSettings");E[n]=t},t.setSettings=function(t){X(u.settings),Z(f,"settings.setSettings",[t])},t.registerOnSaveHandler=function(t){X(u.settings),n=t},t.registerOnRemoveHandler=function(t){X(u.remove),e=t};var i=function(){function t(t){this.notified=!1,this.result=t||{}}return t.prototype.notifySuccess=function(){this.ensureNotNotified(),Z(f,"settings.save.success"),this.notified=!0},t.prototype.notifyFailure=function(t){this.ensureNotNotified(),Z(f,"settings.save.failure",[t]),this.notified=!0},t.prototype.ensureNotNotified=function(){if(this.notified)throw new Error("The SaveEvent may only notify success or failure once.")},t}();var o=function(){function t(){this.notified=!1}return t.prototype.notifySuccess=function(){this.ensureNotNotified(),Z(f,"settings.remove.success"),this.notified=!0},t.prototype.notifyFailure=function(t){this.ensureNotNotified(),Z(f,"settings.remove.failure",[t]),this.notified=!0},t.prototype.ensureNotNotified=function(){if(this.notified)throw new Error("The removeEvent may only notify success or failure once.")},t}()}(b||(b={})),function(t){var n,e;function i(){o();try{d&&d.close()}finally{d=null,h=null}}function o(){e&&(clearInterval(e),e=0),delete s.initialize,delete s.navigateCrossDomain}function r(t){try{n&&n.failureCallback&&n.failureCallback(t)}finally{n=null,i()}}function a(t,n,e){if(t){var i=document.createElement("a");i.href=decodeURIComponent(t),i.host&&i.host!==window.location.host&&"outlook.office.com"===i.host&&i.search.indexOf("client_type=Win32_Outlook")>-1&&(n&&"result"===n&&(e&&(i.href=l(i.href,"result",e)),c.location.assign(l(i.href,"authSuccess",""))),n&&"reason"===n&&(e&&(i.href=l(i.href,"reason",e)),c.location.assign(l(i.href,"authFailure",""))))}}function l(t,n,e){var i=t.indexOf("#"),o=-1===i?"#":t.substr(i);return o=o+"&"+n+(""!==e?"="+e:""),(t=-1===i?t:t.substr(0,i))+o}s["authentication.authenticate.success"]=function(t){try{n&&n.successCallback&&n.successCallback(t)}finally{n=null,i()}},s["authentication.authenticate.failure"]=r,t.registerAuthenticationHandlers=function(t){n=t},t.authenticate=function(t){var a=void 0!==t?t:n;if(X(u.content,u.settings,u.remove,u.task),"desktop"===p){var l=document.createElement("a");l.href=a.url;var v=Z(f,"authentication.authenticate",[l.href,a.width,a.height]);E[v]=function(t,n){t?a.successCallback(n):a.failureCallback(n)}}else!function(t){n=t,i();var a=n.width||600,f=n.height||400;a=Math.min(a,c.outerWidth-400),f=Math.min(f,c.outerHeight-200);var l=document.createElement("a");l.href=n.url;var v=void 0!==c.screenLeft?c.screenLeft:c.screenX,g=void 0!==c.screenTop?c.screenTop:c.screenY;v+=c.outerWidth/2-a/2,g+=c.outerHeight/2-f/2,(d=c.open(l.href,"_blank","toolbar=no, location=yes, status=no, menubar=no, scrollbars=yes, top="+g+", left="+v+", width="+a+", height="+f))?(o(),e=c.setInterval(function(){if(!d||d.closed)r("CancelledByUser");else{var t=h;try{h="*",Z(d,"ping")}finally{h=t}}},100),s.initialize=function(){return[u.authentication,p]},s.navigateCrossDomain=function(t){return!1}):r("FailedToOpenWindow")}(a)},t.getAuthToken=function(t){X();var n=Z(f,"authentication.getAuthToken",[t.resources]);E[n]=function(n,e){n?t.successCallback(e):t.failureCallback(e)}},t.getUser=function(t){X();var n=Z(f,"authentication.getUser");E[n]=function(n,e){n?t.successCallback(e):t.failureCallback(e)}},t.notifySuccess=function(t,n){a(n,"result",t),X(u.authentication),Z(f,"authentication.authenticate.success",[t]),Q(f,function(){return setTimeout(function(){return c.close()},200)})},t.notifyFailure=function(t,n){a(n,"reason",t),X(u.authentication),Z(f,"authentication.authenticate.failure",[t]),Q(f,function(){return setTimeout(function(){return c.close()},200)})}}(w||(w={})),function(t){t.startTask=function(t,n){X(u.content);var e=Z(f,"tasks.startTask",[t]);E[e]=n},t.submitTask=function(t,n){X(u.content,u.task),Z(f,"tasks.completeTask",[t,Array.isArray(n)?n:[n]])}}(k||(k={})),e.d(n,"menus",function(){return r}),e.d(n,"initialize",function(){return O}),e.d(n,"_uninitialize",function(){return P}),e.d(n,"enablePrintCapability",function(){return U}),e.d(n,"print",function(){return x}),e.d(n,"getContext",function(){return A}),e.d(n,"registerOnThemeChangeHandler",function(){return B}),e.d(n,"registerFullScreenHandler",function(){return L}),e.d(n,"registerBackButtonHandler",function(){return _}),e.d(n,"navigateBack",function(){return D}),e.d(n,"navigateCrossDomain",function(){return H}),e.d(n,"getTabInstances",function(){return j}),e.d(n,"getUserJoinedTeams",function(){return F}),e.d(n,"getMruTabInstances",function(){return z}),e.d(n,"shareDeepLink",function(){return W}),e.d(n,"openFilePreview",function(){return R}),e.d(n,"showNotification",function(){return V}),e.d(n,"uploadCustomApp",function(){return J}),e.d(n,"navigateToTab",function(){return K}),e.d(n,"settings",function(){return b}),e.d(n,"authentication",function(){return w}),e.d(n,"sendCustomMessage",function(){return tt}),e.d(n,"tasks",function(){return k}),e.d(n,"getChatMembers",function(){return et})}]); | ||
!function(t){var e={};function n(i){if(e[i])return e[i].exports;var o=e[i]={i:i,l:!1,exports:{}};return t[i].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=t,n.c=e,n.d=function(t,e,i){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:i})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(i,o,function(e){return t[e]}.bind(null,o));return i},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var i=n(1);e.microsoftTeams=i.microsoftTeams},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),String.prototype.startsWith||(String.prototype.startsWith=function(t,e){return this.substr(!e||e<0?0:+e,t.length)===t}),function(t){const e="1.3.6";function n(t){let e="^",n=t.split(".");for(let t=0;t<n.length;t++)e+=(t>0?"[.]":"")+n[t].replace("*","[^/^.]+");return e+="$"}const i=function(t){let e="";for(let i=0;i<t.length;i++)e+=(0===i?"":"|")+n(t[i]);return new RegExp(e)}(["https://teams.microsoft.com","https://teams.microsoft.us","https://int.teams.microsoft.com","https://devspaces.skype.com","https://ssauth.skype.com","http://dev.local","https://msft.spoppe.com","https://*.sharepoint.com","https://*.sharepoint-df.com","https://*.sharepointonline.com","https://outlook.office.com","https://outlook-sdf.office.com"]),o={},s={settings:"settings",content:"content",authentication:"authentication",remove:"remove",task:"task"};let r;!function(t){let e,n,i,s;t.MenuItem=class{constructor(){this.enabled=!0}},function(t){t.dropDown="dropDown",t.popOver="popOver"}(e=t.MenuListType||(t.MenuListType={})),o.navBarMenuItemPress=function(t){n&&n(t)||(U(),j(c,"handleNavBarMenuItemPress",[t]))},o.actionMenuItemPress=function(t){i&&i(t)||(U(),j(c,"handleActionMenuItemPress",[t]))},o.setModuleView=function(t){s&&s(t)||(U(),j(c,"viewConfigItemPress",[t]))},t.setUpViews=function(t,e){U(),s=e,j(c,"setUpViews",[t])},t.setNavBarMenu=function(t,e){U(),n=e,j(c,"setNavBarMenu",[t])},t.showActionMenu=function(t,e){U(),i=e,j(c,"showActionMenu",[t])}}(r=t.menus||(t.menus={}));let a,c,u,l,f,h,d,g,p,m,v,y,b,w=!1,k=!1,T=[],C=[],M=0,I={},S=!1;function E(t){U(),g=t}function O(t){U(),p=t}function N(t){U(),m=t}function P(){U();let t=j(c,"navigateBack",[]);I[t]=(t=>{if(!t)throw new Error("Back navigation is not supported in the current client or context.")})}function U(...t){if(!w)throw new Error("The library has not yet been initialized");if(h&&t&&t.length>0){let e=!1;for(let n=0;n<t.length;n++)if(t[n]===h){e=!0;break}if(!e)throw new Error("This call is not allowed in the '"+h+"' context")}}function _(t){if("id"in t.data){const e=t.data,n=I[e.id];n&&(n.apply(null,e.args),delete I[e.id])}else if("func"in t.data){const e=t.data,n=o[e.func];n&&n.apply(this,e.args)}}function x(t){return t===c?T:t===l?C:[]}function A(t){return t===c?u:t===l?f:null}function B(t){let e=A(t),n=x(t);for(;t&&e&&n.length>0;)t.postMessage(n.shift(),e)}function L(t,e){let n=a.setInterval(()=>{0===x(t).length&&(clearInterval(n),e())},100)}function j(t,e,n){let i=function(t,e){return{id:M++,func:t,args:e||[]}}(e,n);if(k)a&&a.nativeInterface&&a.nativeInterface.framelessPostMessage(JSON.stringify(i));else{let e=A(t);t&&e?t.postMessage(i,e):x(t).push(i)}return i.id}function D(t,e,n){let i=function(t,e){return{id:t,args:e||[]}}(e,n),o=A(t);t&&o&&t.postMessage(i,o)}o.themeChange=function(t){g&&g(t);l&&j(l,"themeChange",[t])},o.fullScreenChange=function(t){p&&p(t)},o.backButtonPress=function(){m&&m()||P()},t.initialize=function(t=window){if(w)return;w=!0;let n=t=>(function(t){if(!t||!t.data||"object"!=typeof t.data)return;let e=t.source||t.originalEvent.source,n=t.origin||t.originalEvent.origin;e===a||n!==a.location.origin&&!i.test(n.toLowerCase())||(function(t,e){c&&t!==c?l&&t!==l||(l=t,f=e):(c=t,u=e),c&&c.closed&&(c=null,u=null),l&&l.closed&&(l=null,f=null),B(c),B(l)}(e,n),e===c?_(t):e===l&&function(t){if("id"in t.data&&"func"in t.data){const e=t.data,n=o[e.func];if(n){let t=n.apply(this,e.args);t&&D(l,e.id,Array.isArray(t)?t:[t])}else{let t=j(c,e.func,e.args);I[t]=((...t)=>{l&&D(l,e.id,t)})}}}(t))})(t);(c=(a=t).parent!==a.self?a.parent:a.opener)?a.addEventListener("message",n,!1):(k=!0,window.onNativeMessage=_);try{u="*";let t=j(c,"initialize",[e]);I[t]=((t,e)=>{h=t,d=e})}finally{u=null}this._uninitialize=(()=>{h&&(E(null),O(null),N(null)),h===s.settings&&v.registerOnSaveHandler(null),h===s.remove&&v.registerOnRemoveHandler(null),k||a.removeEventListener("message",n,!1),w=!1,c=null,u=null,T=[],l=null,f=null,C=[],M=0,I={},h=null,d=null,k=!1})},t._uninitialize=function(){},t.enablePrintCapability=function(){S||(S=!0,U(),document.addEventListener("keydown",e=>{(e.ctrlKey||e.metaKey)&&80===e.keyCode&&(t.print(),e.cancelBubble=!0,e.preventDefault(),e.stopImmediatePropagation())}))},t.print=function(){window.print()},t.getContext=function(t){U();let e=j(c,"getContext");I[e]=t},t.registerOnThemeChangeHandler=E,t.registerFullScreenHandler=O,t.registerBackButtonHandler=N,t.navigateBack=P,t.navigateCrossDomain=function(t){U(s.content,s.settings,s.remove,s.task);let e=j(c,"navigateCrossDomain",[t]);I[e]=(t=>{if(!t)throw new Error("Cross-origin navigation is only supported for URLs matching the pattern registered in the manifest.")})},t.getTabInstances=function(t,e){U();let n=j(c,"getTabInstances",[e]);I[n]=t},t.getUserJoinedTeams=function(t,e){U();const n=j(c,"getUserJoinedTeams",[e]);I[n]=t},t.getMruTabInstances=function(t,e){U();let n=j(c,"getMruTabInstances",[e]);I[n]=t},t.shareDeepLink=function(t){U(s.content),j(c,"shareDeepLink",[t.subEntityId,t.subEntityLabel,t.subEntityWebUrl])},t.openFilePreview=function(t){U(s.content);const e=[t.entityId,t.title,t.description,t.type,t.objectUrl,t.downloadUrl,t.webPreviewUrl,t.webEditUrl,t.baseUrl,t.editFile,t.subEntityId];j(c,"openFilePreview",e)},t.showNotification=function(t){U(s.content);const e=[t.message,t.isDownloadComplete];j(c,"showNotification",e)},t.uploadCustomApp=function(t){U();const e=j(c,"uploadCustomApp",[t]);I[e]=((t,e)=>{if(!t)throw new Error(e)})},t.navigateToTab=function(t){U();let e=j(c,"navigateToTab",[t]);I[e]=(t=>{if(!t)throw new Error("Invalid internalTabInstanceId and/or channelId were/was provided")})},function(t){let e,n;o["settings.save"]=function(t){let n=new i(t);e?e(n):n.notifySuccess()},o["settings.remove"]=function(){let t=new r;n?n(t):t.notifySuccess()},t.setValidityState=function(t){U(s.settings,s.remove),j(c,"settings.setValidityState",[t])},t.getSettings=function(t){U(s.settings,s.remove);let e=j(c,"settings.getSettings");I[e]=t},t.setSettings=function(t){U(s.settings),j(c,"settings.setSettings",[t])},t.registerOnSaveHandler=function(t){U(s.settings),e=t},t.registerOnRemoveHandler=function(t){U(s.remove),n=t};class i{constructor(t){this.notified=!1,this.result=t||{}}notifySuccess(){this.ensureNotNotified(),j(c,"settings.save.success"),this.notified=!0}notifyFailure(t){this.ensureNotNotified(),j(c,"settings.save.failure",[t]),this.notified=!0}ensureNotNotified(){if(this.notified)throw new Error("The SaveEvent may only notify success or failure once.")}}class r{constructor(){this.notified=!1}notifySuccess(){this.ensureNotNotified(),j(c,"settings.remove.success"),this.notified=!0}notifyFailure(t){this.ensureNotNotified(),j(c,"settings.remove.failure",[t]),this.notified=!0}ensureNotNotified(){if(this.notified)throw new Error("The removeEvent may only notify success or failure once.")}}}(v=t.settings||(t.settings={})),function(t){let e,n;function i(){r();try{l&&l.close()}finally{l=null,f=null}}function r(){n&&(clearInterval(n),n=0),delete o.initialize,delete o.navigateCrossDomain}function u(t){try{e&&e.failureCallback&&e.failureCallback(t)}finally{e=null,i()}}function h(t,e,n){if(t){let i=document.createElement("a");i.href=decodeURIComponent(t),i.host&&i.host!==window.location.host&&"outlook.office.com"===i.host&&i.search.indexOf("client_type=Win32_Outlook")>-1&&(e&&"result"===e&&(n&&(i.href=g(i.href,"result",n)),a.location.assign(g(i.href,"authSuccess",""))),e&&"reason"===e&&(n&&(i.href=g(i.href,"reason",n)),a.location.assign(g(i.href,"authFailure",""))))}}function g(t,e,n){let i=t.indexOf("#"),o=-1===i?"#":t.substr(i);return o=o+"&"+e+(""!==n?"="+n:""),(t=-1===i?t:t.substr(0,i))+o}o["authentication.authenticate.success"]=function(t){try{e&&e.successCallback&&e.successCallback(t)}finally{e=null,i()}},o["authentication.authenticate.failure"]=u,t.registerAuthenticationHandlers=function(t){e=t},t.authenticate=function(t){let h=void 0!==t?t:e;if(U(s.content,s.settings,s.remove,s.task),"desktop"===d){let t=document.createElement("a");t.href=h.url;let e=j(c,"authentication.authenticate",[t.href,h.width,h.height]);I[e]=((t,e)=>{t?h.successCallback(e):h.failureCallback(e)})}else!function(t){e=t,i();let c=e.width||600,h=e.height||400;c=Math.min(c,a.outerWidth-400),h=Math.min(h,a.outerHeight-200);let g=document.createElement("a");g.href=e.url;let p=void 0!==a.screenLeft?a.screenLeft:a.screenX,m=void 0!==a.screenTop?a.screenTop:a.screenY;p+=a.outerWidth/2-c/2,m+=a.outerHeight/2-h/2,(l=a.open(g.href,"_blank","toolbar=no, location=yes, status=no, menubar=no, scrollbars=yes, top="+m+", left="+p+", width="+c+", height="+h))?(r(),n=a.setInterval(()=>{if(!l||l.closed)u("CancelledByUser");else{let t=f;try{f="*",j(l,"ping")}finally{f=t}}},100),o.initialize=(()=>[s.authentication,d]),o.navigateCrossDomain=(t=>!1)):u("FailedToOpenWindow")}(h)},t.getAuthToken=function(t){U();let e=j(c,"authentication.getAuthToken",[t.resources]);I[e]=((e,n)=>{e?t.successCallback(n):t.failureCallback(n)})},t.getUser=function(t){U();let e=j(c,"authentication.getUser");I[e]=((e,n)=>{e?t.successCallback(n):t.failureCallback(n)})},t.notifySuccess=function(t,e){h(e,"result",t),U(s.authentication),j(c,"authentication.authenticate.success",[t]),L(c,()=>setTimeout(()=>a.close(),200))},t.notifyFailure=function(t,e){h(e,"reason",t),U(s.authentication),j(c,"authentication.authenticate.failure",[t]),L(c,()=>setTimeout(()=>a.close(),200))}}(y=t.authentication||(t.authentication={})),t.sendCustomMessage=function(t,e){return U(),j(c,t,e)},function(t){t.startTask=function(t,e){U(s.content);let n=j(c,"tasks.startTask",[t]);I[n]=e},t.submitTask=function(t,e){U(s.content,s.task),j(c,"tasks.completeTask",[t,Array.isArray(e)?e:[e]])}}(b=t.tasks||(t.tasks={})),t.getChatMembers=function(t){U();const e=j(c,"getChatMembers");I[e]=t}}(e.microsoftTeams||(e.microsoftTeams={}))}]); |
{ | ||
"name": "@microsoft/teams-js", | ||
"author": "Microsoft Teams", | ||
"version": "1.4.0-beta.3.7", | ||
"version": "1.4.0-beta.3.8", | ||
"description": "Microsoft Client SDK for building app for Microsoft teams", | ||
"main": "index.ts", | ||
"main": "./dist/MicrosoftTeams.js", | ||
"typings": "./dts/src/index.d.ts", | ||
"repository": { | ||
@@ -32,2 +33,8 @@ "type": "git", | ||
}, | ||
"files": [ | ||
"dist/**", | ||
"dts/**", | ||
"README.md", | ||
"LICENSE" | ||
], | ||
"jest": { | ||
@@ -34,0 +41,0 @@ "transform": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
213344
9
2209
1
5
12
0
56