UNPKG

@microsoft/teams-js

Version:

Microsoft Client SDK for building app for Microsoft hosts

2 lines (1 loc) 5.22 kB
import{Buffer as t}from"../../../../_virtual/_polyfill-node.buffer.js";import{minAdaptiveCardVersion as e}from"../public/constants.js";import{LegalAgeGroupClassification as n}from"../public/interfaces.js";import r from"../../../../node_modules/.pnpm/uuid@9.0.1/node_modules/uuid/dist/esm-browser/v4.js";import o from"../../../../node_modules/.pnpm/uuid@9.0.1/node_modules/uuid/dist/esm-browser/validate.js";function i(t){return(t,e)=>{if(!t)throw new Error(e)}}function s(t,e){if("string"!=typeof t||"string"!=typeof e)return NaN;const n=t.split("."),r=e.split(".");function o(t){return/^\d+$/.test(t)}if(!n.every(o)||!r.every(o))return NaN;for(;n.length<r.length;)n.push("0");for(;r.length<n.length;)r.push("0");for(let t=0;t<n.length;++t)if(Number(n[t])!=Number(r[t]))return Number(n[t])>Number(r[t])?1:-1;return 0}function u(){return r()}function c(t){return Object.keys(t).forEach((e=>{null!==t[e]&&void 0!==t[e]&&"object"==typeof t[e]&&c(t[e])})),Object.freeze(t)}function a(t,e,...n){const r=t(...n);return r.then((t=>{e&&e(void 0,t)})).catch((t=>{e&&e(t)})),r}function l(t,e,...n){const r=t(...n);return r.then((()=>{e&&e(null)})).catch((t=>{e&&e(t)})),r}function f(t,e,...n){const r=t(...n);return r.then((t=>{e&&e(null,t)})).catch((t=>{e&&e(t,null)})),r}function p(t,e,n){return new Promise(((r,o)=>{const i=setTimeout(o,e,n);t().then((t=>{clearTimeout(i),r(t)})).catch((t=>{clearTimeout(i),o(t)}))}))}function d(t){const e=new URL("https://teams.microsoft.com/l/entity/"+encodeURIComponent(t.appId.toString())+"/"+encodeURIComponent(t.pageId));return t.webUrl&&e.searchParams.append("webUrl",t.webUrl.toString()),(t.chatId||t.channelId||t.subPageId)&&e.searchParams.append("context",JSON.stringify({chatId:t.chatId,channelId:t.channelId,subEntityId:t.subPageId})),e.toString()}function m(t){return!(s(`${t.majorVersion}.${t.minorVersion}`,`${e.majorVersion}.${e.minorVersion}`)>=0)}function h(t){return"https:"===t.protocol}function b(e,n){return new Promise(((r,o)=>{if(e||o("MimeType cannot be null or empty."),n||o("Base64 string cannot be null or empty."),e.startsWith("image/")){const t=atob(n),o=new Uint8Array(t.length);for(let e=0;e<t.length;e++)o[e]=t.charCodeAt(e);r(new Blob([o],{type:e}))}const i=t.from(n,"base64").toString();r(new Blob([i],{type:e}))}))}function g(t){return new Promise(((e,n)=>{0===t.size&&n(new Error("Blob cannot be empty."));const r=new FileReader;r.onloadend=()=>{r.result?e(r.result.toString().split(",")[1]):n(new Error("Failed to read the blob"))},r.onerror=()=>{n(r.error)},r.readAsDataURL(t)}))}function w(){if(y())throw new Error("window object undefined at SSR check");return window}function y(){return"undefined"==typeof window}function j(t,e){if(E(t)||!function(t){return t.length<256&&t.length>4}(t)||!function(t){for(let e=0;e<t.length;e++){const n=t.charCodeAt(e);if(n<32||n>126)return!1}return!0}(t))throw e||new Error("id is not valid.")}function I(t,e){const n=t.toString().toLocaleLowerCase();if(E(n))throw new Error("Invalid Url");if(n.length>2048)throw new Error("Url exceeds the maximum size of 2048 characters");if(!h(t))throw new Error("Url should be a valid https url")}function v(t){const e=document.createElement("a");return e.href=t,new URL(e.href)}function E(t){return new RegExp(`${/<script[^>]*>|&lt;script[^&]*&gt;|%3Cscript[^%]*%3E/gi.source}|${/<\/script[^>]*>|&lt;\/script[^&]*&gt;|%3C\/script[^%]*%3E/gi.source}`,"gi").test(t)}function O(t){if(!t)throw new Error("id must not be empty");if(!1===o(t))throw new Error("id must be a valid UUID")}const U=!!performance&&"now"in performance;function N(){return U?performance.now()+performance.timeOrigin:void 0}function S(t,e=0){if(e>1e3)return!1;if(void 0===t||"boolean"==typeof t||"number"==typeof t||"bigint"==typeof t||"string"==typeof t||null===t)return!0;if(Array.isArray(t))return t.every((t=>S(t,e+1)));return!("object"!=typeof t||"[object Object]"!==Object.prototype.toString.call(t)||Object.getPrototypeOf(t)!==Object.prototype&&null!==Object.getPrototypeOf(t))&&Object.keys(t).every((n=>S(t[n],e+1)))}function P(t){var e,r;if(!(null===(r=null===(e=t.hostVersionsInfo)||void 0===e?void 0:e.appEligibilityInformation)||void 0===r?void 0:r.ageGroup))return t;const o=t.hostVersionsInfo.appEligibilityInformation.ageGroup;return"nonadult"!==(null==o?void 0:o.toLowerCase())?t:Object.assign(Object.assign({},t),{hostVersionsInfo:Object.assign(Object.assign({},t.hostVersionsInfo),{appEligibilityInformation:Object.assign(Object.assign({},t.hostVersionsInfo.appEligibilityInformation),{ageGroup:n.NotAdult})})})}export{b as base64ToBlob,a as callCallbackWithErrorOrResultFromPromiseAndReturnPromise,f as callCallbackWithErrorOrResultOrNullFromPromiseAndReturnPromise,l as callCallbackWithSdkErrorFromPromiseAndReturnPromise,s as compareSDKVersions,d as createTeamsAppLink,c as deepFreeze,v as fullyQualifyUrlString,u as generateGUID,g as getBase64StringFromBlob,N as getCurrentTimestamp,i as getGenericOnCompleteHandler,E as hasScriptTags,y as inServerSideRenderingEnvironment,m as isHostAdaptiveCardSchemaVersionUnsupported,S as isPrimitiveOrPlainObject,h as isValidHttpsURL,P as normalizeAgeGroupValue,p as runWithTimeout,w as ssrSafeWindow,j as validateId,I as validateUrl,O as validateUuid};