UNPKG

@microsoft/teams-js

Version:

Microsoft Client SDK for building app for Microsoft hosts

2 lines (1 loc) 6.1 kB
import{sendMessageToParentAsync as t,callFunctionInHost as e,callFunctionInHostAndHandleResponse as n}from"../internal/communication.js";import{ensureInitialized as i}from"../internal/internalAPIs.js";import{ResponseHandler as o}from"../internal/responseHandler.js";import{getApiVersionTag as r}from"../internal/telemetry.js";import{isPrimitiveOrPlainObject as a,validateId as s,validateUrl as c}from"../internal/utils.js";import{FrameContexts as u,errorNotSupportedOnPlatform as h}from"../public/constants.js";import{runtime as l}from"../public/runtime.js";import{AppId as d}from"../public/appId.js";const p="v2";class f{constructor(t){this.invokeRequest=t}serialize(){return this.invokeRequest}}function m(t){const e=t;return e.responseType===w.ActionExecuteInvokeResponse&&void 0!==e.value&&void 0!==e.statusCode&&void 0!==e.type}const A="Action.Execute";var I,w,v,x;!function(t){t.ActionExecuteInvokeRequest="ActionExecuteInvokeRequest",t.QueryMessageExtensionRequest="QueryMessageExtensionRequest"}(I||(I={})),function(t){t.ActionExecuteInvokeResponse="ActionExecuteInvokeResponse",t.QueryMessageExtensionResponse="QueryMessageExtensionResponse"}(w||(w={}));class g extends o{validate(t){return m(t)}deserialize(t){return t}}function R(t){if("object"!=typeof t||null===t)return!1;const e=t;return Object.values(v).includes(e.errorCode)&&(void 0===e.message||"string"==typeof e.message)}function E(t){t.requestType===I.ActionExecuteInvokeRequest?y(t):t.requestType===I.QueryMessageExtensionRequest&&function(t){if(t.commandId.length>64)throw new Error("originalRequestInfo.commandId exceeds the maximum size of 64 characters");if(t.parameters.length>5)throw new Error("originalRequestInfo.parameters exceeds the maximum size of 5");for(const e of t.parameters){if(e.name.length>64)throw new Error("originalRequestInfo.parameters.name exceeds the maximum size of 64 characters");if(e.value.length>512)throw new Error("originalRequestInfo.parameters.value exceeds the maximum size of 512 characters")}}(t)}function y(t){if(t.type!==A){throw{errorCode:v.INTERNAL_ERROR,message:`Invalid action type ${t.type}. Action type must be "${A}"`}}if(!a(t.data)){throw{errorCode:v.INTERNAL_ERROR,message:`Invalid data type ${typeof t.data}. Data must be a primitive or a plain object.`}}}function C(e,n,o){if(i(l,u.content),!z())throw h;const a=new d(e);return E(o),t(r(p,"externalAppAuthentication.authenticateAndResendRequest"),"externalAppAuthentication.authenticateAndResendRequest",[a.toString(),o,n.url.href,n.width,n.height,n.isExternal]).then((([t,e])=>{if(t&&null!=e.responseType)return e;throw e}))}function q(e,n){if(i(l,u.content),!z())throw h;const o=new d(e);return t(r(p,"externalAppAuthentication.authenticateWithSSO"),"externalAppAuthentication.authenticateWithSSO",[o.toString(),n.claims,n.silent]).then((([t,e])=>{if(!t)throw e}))}function S(e,n,o){if(i(l,u.content),!z())throw h;const a=new d(e);return E(o),t(r(p,"externalAppAuthentication.authenticateWithSSOAndResendRequest"),"externalAppAuthentication.authenticateWithSSOAndResendRequest",[a.toString(),o,n.claims,n.silent]).then((([t,e])=>{if(t&&null!=e.responseType)return e;throw e}))}function j(e,n,o){if(i(l,u.content),!z())throw h;return s(e,new Error("titleId is Invalid.")),s(n,new Error("oauthConfigId is Invalid.")),t(r(p,"externalAppAuthentication.authenticateWithOauth2"),"externalAppAuthentication.authenticateWithOauth2",[e,n,o.width,o.height,o.isExternal]).then((([t,e])=>{if(!t)throw e}))}function O(e,n,o){if(i(l,u.content),!z())throw h;return s(e,new Error("titleId is Invalid.")),n&&c(n),t(r(p,"externalAppAuthentication.authenticateWithPowerPlatformConnectorPlugins"),"externalAppAuthentication.authenticateWithPowerPlatformConnectorPlugins",[e,null==n?void 0:n.toString(),null==o?void 0:o.width,null==o?void 0:o.height,null==o?void 0:o.isExternal]).then((([t,e])=>{if(!t)throw e}))}!function(t){t.INTERNAL_ERROR="INTERNAL_ERROR"}(v||(v={}));class P{constructor(t){this.param=t}serialize(){var t,e,n;return{connectorId:this.param.connectorId,oAuthConfigId:this.param.oAuthConfigId,traceId:null!==(n=null===(e=null===(t=this.param.traceId)||void 0===t?void 0:t.toString)||void 0===e?void 0:e.call(t))&&void 0!==n?n:this.param.traceId,windowParameters:this.param.windowParameters?Object.assign({},this.param.windowParameters):void 0}}}function W(t){if(i(l,u.content),!z())throw h;return s(t.connectorId,new Error("connectorId is Invalid.")),s(t.oAuthConfigId,new Error("oauthConfigId is Invalid.")),e("externalAppAuthentication.authenticateWithConnector",[new P(t)],r(p,"externalAppAuthentication.authenticateWithConnector"),R)}!function(t){t.Invalid="Invalid",t.Valid="Valid",t.Expired="Expired"}(x||(x={}));class b extends o{validate(t){return"string"==typeof t&&t in x}deserialize(t){return t}}function T(t){if(i(l,u.content),!z())throw h;return s(t.connectorId,new Error("connectorId is Invalid.")),s(t.oAuthConfigId,new Error("oAuthConfigId is Invalid.")),n("externalAppAuthentication.getUserAuthenticationStateForConnector",[new P(t)],new b,r(p,"externalAppAuthentication.getUserAuthenticationStateForConnector"),R)}function k(t){if(i(l,u.content),!z())throw h;return s(t.connectorId,new Error("connectorId is Invalid.")),s(t.oAuthConfigId,new Error("oauthConfigId is Invalid.")),e("externalAppAuthentication.disconnectConnector",[new P(t)],r(p,"externalAppAuthentication.disconnectConnector"),R)}function z(){return!(!i(l)||!l.supports.externalAppAuthentication)}export{A as ActionExecuteInvokeRequestType,g as ActionExecuteResponseHandler,v as InvokeErrorCode,w as InvokeResponseType,I as OriginalRequestType,f as SerializableActionExecuteInvokeRequest,P as SerializableConnectorParameters,x as UserAuthenticationState,C as authenticateAndResendRequest,W as authenticateWithConnector,j as authenticateWithOauth2,O as authenticateWithPowerPlatformConnectorPlugins,q as authenticateWithSSO,S as authenticateWithSSOAndResendRequest,k as disconnectConnector,T as getUserAuthenticationStateForConnector,m as isActionExecuteResponse,R as isInvokeError,z as isSupported,y as validateActionExecuteInvokeRequest};