@liff/init
Advanced tools
Comparing version 2.17.0 to 2.18.0
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),t=require("@liff/util"),r=require("@liff/ready"),n=require("@liff/is-logged-in"),o=require("@liff/store"),i=require("@liff/consts"),a=require("@liff/extensions"),s=require("@liff/is-in-client"),l=require("@liff/logout"),c=require("@liff/is-sub-window"),f=require("@liff/sub-window"),u=require("@liff/server-api"),d=require("@liff/logger"),g=require("@liff/get-line-version"),h=require("@liff/native-bridge"),_=require("@liff/is-api-available"),p=require("@liff/get-os"),v={iconColor:"#111111",statusBarColor:"BLACK",titleTextColor:"#111111",titleSubtextColor:"#B7B7B7",titleButtonColor:"#111111",titleBackgroundColor:"#FFFFFF",progressBarColor:"#06C755",progressBackgroundColor:"#FFFFFF",titleButtonAreaBackgroundColor:"#1FFFFFFF",titleButtonAreaBorderColor:"#26000000",baseBackgroundColor:"#FFFFFF",baseTextColor:"#000000",lightButtonBorderColor:"rgba(0, 0, 0, 0.15)"},I={iconColor:"#FFFFFF",statusBarColor:"WHITE",titleTextColor:"#FFFFFF",titleSubtextColor:"#949494",titleButtonColor:"#FFFFFF",titleBackgroundColor:"#111111",progressBarColor:"#06C755",progressBackgroundColor:"#111111",titleButtonAreaBackgroundColor:"#1FFFFFFF",titleButtonAreaBorderColor:"#26000000",baseBackgroundColor:"#000000",baseTextColor:"#FFFFFF",lightButtonBorderColor:"rgba(255, 255, 255, 0.5)"};function w(){var e;F("color-scheme",((null==(e=o.getContext())?void 0:e.menuColorSetting)||{adaptableColorSchemes:["light"]}).adaptableColorSchemes.join(" "));var t=window.matchMedia("(prefers-color-scheme: dark)");b({matches:null==t?void 0:t.matches,media:null==t?void 0:t.media}),t.addEventListener?t.addEventListener("change",b):t.addListener&&t.addListener(b)}function b(t){var r=o.getContext(),n=(null==r?void 0:r.menuColorSetting)||{adaptableColorSchemes:["light"],lightModeColor:v,darkModeColor:I},i=n.adaptableColorSchemes,a=n.lightModeColor,s=n.darkModeColor,l=i.includes("dark");t.matches&&l?C(e.__assign(e.__assign({},I),s)):C(e.__assign(e.__assign({},v),a))}function C(e){var r=e.iconColor,n=e.statusBarColor,o=e.titleTextColor,i=e.titleSubtextColor,a=e.titleButtonColor,s=e.titleBackgroundColor,l=e.progressBarColor,c=e.progressBackgroundColor,f=e.titleButtonAreaBackgroundColor,u=e.titleButtonAreaBorderColor,d=e.baseBackgroundColor,g=e.baseTextColor,h=e.lightButtonBorderColor;F("--liff-base-background-color",d),F("--liff-base-text-color",g),F("--liff-base-background-rgb-color",t.convertHexToRgb(d)),F("--liff-base-text-rgb-color",t.convertHexToRgb(g)),F("--liff-light-button-border-color",h),F("--liff-title-text-color",o),F("--liff-title-background-color",s),F("--liff-title-button-color",a),F("--liff-icon-color",r),F("--liff-status-bar-color",n),F("--liff-title-subtext-color",i),F("--liff-progress-bar-color",l),F("--liff-progress-background-color",c),F("--liff-title-button-area-background-color",t.convertArgbToRgba(f)),F("--liff-title-button-area-border-color",t.convertArgbToRgba(u))}function F(e,t){document.documentElement.style.setProperty(e,t)}function T(t){return e.__awaiter(this,void 0,void 0,(function(){return e.__generator(this,(function(e){switch(e.label){case 0:return[4,a.load()];case 1:return e.sent().install(t),[2]}}))}))}function m(){return e.__awaiter(this,void 0,void 0,(function(){return e.__generator(this,(function(e){switch(e.label){case 0:return[4,u.fetch(u.getEndPoint("certs"))];case 1:return[2,e.sent()]}}))}))}function k(t,r,n){return e.__awaiter(this,void 0,void 0,(function(){var o;return e.__generator(this,(function(e){switch(e.label){case 0:return[4,crypto.subtle.importKey("jwk",t,{name:"ECDSA",namedCurve:"P-256"},!1,["verify"])];case 1:return o=e.sent(),[4,crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,n,r)];case 2:return[2,e.sent()]}}))}))}function L(r,n){return e.__awaiter(this,void 0,void 0,(function(){var o,a,s,l,c,f,u,d,g,h,_,p,v,I,w,b;return e.__generator(this,(function(C){switch(C.label){case 0:return o=r.split("."),a=e.__read(o,3),s=a[0],l=a[1],c=a[2],f=JSON.parse(t.base64Url.decode(s)),u=JSON.parse(t.base64Url.decodeUnicode(l)),d=t.convertArrayBuffer(t.base64Url.decode(c)),g=t.convertArrayBuffer(s+"."+l),[4,m()];case 1:if(h=C.sent(),!(_=h.keys.find((function(e){return e.kid===f.kid}))))return[3,6];if(delete _.alg,"ES256"!==f.alg)throw t.createLiffError(i.INVALID_ID_TOKEN,'Invalid "alg" value in ID_TOKEN');p=void 0,C.label=2;case 2:return C.trys.push([2,4,,5]),[4,k(_,g,d)];case 3:return p=C.sent(),[3,5];case 4:throw v=C.sent(),t.createLiffError(i.INVALID_ID_TOKEN,"Failed to use Crypto API to verify ID_TOKEN: "+v);case 5:if(p){if(I="https://access.line.me"!==u.iss,w=u.aud!==n,b=1e3*u.exp<Date.now(),I)throw t.createLiffError(i.INVALID_ID_TOKEN,'Invalid "iss" value in ID_TOKEN');if(w)throw t.createLiffError(i.INVALID_ID_TOKEN,'Invalid "aud" value in ID_TOKEN');if(b)throw t.createLiffError(i.INVALID_ID_TOKEN,'Invalid "exp" value in ID_TOKEN');return[2,u]}throw t.createLiffError(i.INVALID_ID_TOKEN,"Invalid signature in ID_TOKEN");case 6:throw t.createLiffError(i.INVALID_ID_TOKEN,'Invalid "kid" value in ID_TOKEN');case 7:return[2]}}))}))}function E(e){var t=e.split(".");if(t[1])try{var r=t[1].replace(/-/g,"+").replace(/_/g,"/");return JSON.parse(window.atob(r))}catch(n){return null}return null}function A(e){var r=e.pathname,n=e.query,o="liff://"+r+(n?"?"+t.qs.stringify(n):"");location.href=o}var D=null;function y(){"boolean"==typeof D&&d.logger.warn("liff.init is not expected to be called more than once"),D=!!o.getIsSubsequentLiffApp()||!(!s.isInClient()||t.qs.parse(window.location.hash).feature_token||o.getFeatureToken())&&(o.setIsSubsequentLiffApp(!0),!0)}function B(){return Boolean(D)}function S(t,r){return e.__awaiter(this,void 0,void 0,(function(){var n;return e.__generator(this,(function(e){switch(e.label){case 0:return(n=o.getMST())?[2,n]:t&&r?[4,f.getMSTByMSIT({msit:t,mstVerifier:r})]:[3,2];case 1:return[2,e.sent().mst];case 2:return[2,null]}}))}))}function x(e){return u.fetch(u.getEndPoint("apps")+"/"+e+"/featureToken")}function N(r){return e.__awaiter(this,void 0,void 0,(function(){var i,a,s,l,c,f,u;return e.__generator(this,(function(e){switch(e.label){case 0:return i=t.qs.parse(window.location.hash),a=t.objectAssignKeyOnlyWithValue({access_token:o.getAccessToken(),context_token:o.getRawContext(),feature_token:o.getFeatureToken(),id_token:o.getIDToken(),client_id:o.getClientId(),mst_challenge:o.getMSTChallenge(),mst_verifier:o.getMSTVerifier(),msit:o.getMSIT()},i),B()?n.isLoggedIn()?[4,x(r)]:[3,2]:[3,3];case 1:l=e.sent(),c=l.featureToken,f=l.features,s=f,a.feature_token||(a.feature_token=c),e.label=2;case 2:(u=t.extractChannelIdFromLiffId(r))&&(a.client_id=u),e.label=3;case 3:return[2,{credentials:a,features:s}]}}))}))}function O(e){if(e.persisted&&_.isApiAvailable("multipleLiffTransition"))if("ios"===p.getOS())window.location.reload();else{var r=o.getConfig().liffId,n=o.getFeatureToken();if(!r)throw t.createLiffError(i.INIT_FAILED,"Invalid LIFF ID.");if(!n)throw t.createLiffError(i.FORBIDDEN,"Invalid featureToken for client features");A({pathname:"app/"+r,query:{feature_token:n}})}}function q(r,n){return e.__awaiter(this,void 0,void 0,(function(){var o,i;return e.__generator(this,(function(e){switch(e.label){case 0:return[4,u.verifyAccessToken(r)];case 1:return o=e.sent().client_id,i=t.extractChannelIdFromLiffId(n),[2,o===i]}}))}))}function M(r,a){return e.__awaiter(this,void 0,void 0,(function(){var s,l,u,p,v,I,w,b,C,F,T,m,k;return e.__generator(this,(function(e){switch(e.label){case 0:return[4,new Promise((function(e){var r=g.getLineVersion();if(!r||t.compareVersion(r,"9.5.0")<0)e();else if(window._liff&&window._liff.features)e();else{d.logger.debug("cannot find window._liff.features, listen to ready event");var n=function(){d.logger.debug("ready event is fired"),h.removeListener("ready",n),e()};h.addListener("ready",n)}}))];case 1:return e.sent(),y(),[4,N(a.liffId)];case 2:return s=e.sent().credentials,l=s.access_token,u=s.context_token,p=s.feature_token,v=s.id_token,I=s.client_id,w=s.mst_verifier,b=s.mst_challenge,C=s.msit,!c.isSubWindow()&&p&&(!function(e,t){_.isApiAvailable("multipleLiffTransition")&&A({pathname:"app/"+e,query:{feature_token:t}})}(a.liffId,p),B()&&o.setFeatureToken(p)),u&&o.setContext(E(u)),b&&o.setMSTChallenge(b),w&&o.setMSTVerifier(w),I&&o.setClientId(I),C&&o.setMSIT(C),window.addEventListener("pageshow",O),n.isLoggedIn()?[3,7]:p&&l?[3,5]:B()?(F=t.addParamsToUrl(location.href,{"liff.hback":"2"}),r.login({redirectUri:F}),[4,new Promise((function(){}))]):[3,4];case 3:e.sent(),e.label=4;case 4:throw r.login(),t.createLiffError(i.INIT_FAILED,"Failed to parse feature_token or access_token");case 5:return[4,q(l,a.liffId)];case 6:if(!e.sent())throw r.login(),t.createLiffError(i.INIT_FAILED,"Failed to verify access_token");o.setFeatureToken(p),o.setAccessToken(l),e.label=7;case 7:return[4,S(C,w)];case 8:return(T=e.sent())?(o.setMST(T),[4,f.getAppData({mst:T})]):[3,10];case 9:(m=e.sent().data)&&o.setAppData(JSON.stringify(m)),e.label=10;case 10:return v&&!o.getIDToken()&&o.setIDToken(v),v&&I&&!o.getDecodedIDToken()?[4,L(v,I)]:[3,12];case 11:(k=e.sent())&&o.setDecodedIDToken(k),e.label=12;case 12:return[2]}}))}))}function U(r){return e.__awaiter(this,void 0,void 0,(function(){var n,a,s,l,c,f,d;return e.__generator(this,(function(e){switch(e.label){case 0:return n=u.getEndPoint("apps"),a=n+"/"+r+"/contextToken",s=o.getAccessToken(),l={"Content-Type":"application/json",Accept:"application/json"},s&&(l.Authorization="Bearer "+s),[4,u.fetch(a,{headers:l})];case 1:if(c=e.sent(),!(f=c.contextToken))throw t.createLiffError(i.INIT_FAILED,"Can not get context from server.");if(!(d=E(f)))throw t.createLiffError(i.INIT_FAILED,"Invalid context token.");return[2,d]}}))}))}function K(){return e.__awaiter(this,void 0,void 0,(function(){var r,n;return e.__generator(this,(function(e){switch(e.label){case 0:if(!(r=o.getConfig().liffId))throw t.createLiffError(i.INIT_FAILED,"Invalid LIFF ID.");return[4,U(r)];case 1:return n=e.sent(),o.setContext(n),[2]}}))}))}function P(r){return e.__awaiter(this,void 0,void 0,(function(){var n,i,a,s=this;return e.__generator(this,(function(l){switch(l.label){case 0:n=function(){return e.__awaiter(s,void 0,void 0,(function(){var n,i,a,s,l,c;return e.__generator(this,(function(e){switch(e.label){case 0:return[4,(f=o.getConfig(),d=t.qs.parse(window.location.search),g=o.getLoginTmp(),h={grant_type:"authorization_code",client_id:d.liffClientId,appId:f.liffId,code:d.code,code_verifier:g.codeVerifier,redirect_uri:f.redirectUri||d.liffRedirectUri,id_token_key_type:"JWK"},_=t.qs.stringify(h),u.fetch(u.getEndPoint("token"),{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8"},body:_}))];case 1:return n=e.sent(),i=n.access_token,a=n.id_token,s=n.expires_in,o.setClientId(r),o.setAccessToken(i),o.setExpireTime(new Date(Date.now()+1e3*s)),o.removeLoginTmp(),a?(o.setIDToken(a),[4,L(a,r)]):[3,3];case 2:(l=e.sent())&&o.setDecodedIDToken(l),e.label=3;case 3:return(c=t.qs.parse(location.hash).context_token)?(o.setContext(E(c)),[3,6]):[3,4];case 4:return[4,K()];case 5:e.sent(),e.label=6;case 6:return[2]}var f,d,g,h,_}))}))},l.label=1;case 1:return l.trys.push([1,3,,4]),[4,n()];case 2:return l.sent(),[3,4];case 3:throw i=l.sent(),a=i,o.removeLoginTmp(),a;case 4:return[2]}}))}))}var W=new(function(){function r(){var e=this;this.getAndValidateContext=function(){var e=o.getContext();if(!e)throw t.createLiffError(i.INIT_FAILED,"Could not get Context from server.");if(!e.endpointUrl)throw t.createLiffError(i.INIT_FAILED,"Could not get endpointUrl from server.");if(!e.permanentLinkPattern)throw t.createLiffError(i.INIT_FAILED,"Could not get permanentLinkPattern from server.");return e},this.decodeState=function(t){var r=e.getAndValidateContext();t=t.replace(/\n/g,"%0D%0A");var n=!r.endpointUrl.startsWith("/?")&&r.endpointUrl.includes("/?")||!r.endpointUrl.startsWith("/#")&&r.endpointUrl.includes("/#")||r.endpointUrl.endsWith("/")||!t.startsWith("/?")&&t.includes("/?")||!t.startsWith("/#")&&t.includes("/#")||t.endsWith("/"),o=new URL(r.endpointUrl),i=o.origin,a=o.pathname,s=o.search,l=new URL(""+i+e.attachSlashAtStart(t)),c=l.pathname,f=l.search,u=l.hash,d=""+s+(s?f.replace(/\?/g,"&"):f),g=(""+a+e.attachSlashAtStart(c)).replace("//","/");return(g=e.attachSlashAtStart(""+g)).endsWith("/")&&!n&&(g=g.substring(0,g.length-1)),(""+i+g+d+u).replace(/%0D%0A/g,"\n")}}return r.prototype.attachSlashAtStart=function(e){return(e&&e.length>0&&!e.startsWith("/")?"/":"")+e},r.prototype.invoke=function(){return e.__awaiter(this,void 0,void 0,(function(){var r,n,o,a,s;return e.__generator(this,(function(e){switch(e.label){case 0:if(r=t.qs.parse(window.location.search),"string"!=typeof(n=r["liff.state"]))return[2];e.label=1;case 1:return e.trys.push([1,4,,5]),o=location.href,(a=this.decodeState(n))===o?[3,3]:(r["liff.hback"]?location.replace(t.addParamsToUrl(a,{"liff.hback":r["liff.hback"]})):location.replace(a),[4,new Promise((function(){}))]);case 2:e.sent(),e.label=3;case 3:return[3,5];case 4:if((s=e.sent()).code===i.INIT_FAILED)throw s;return d.logger.debug(s),[3,5];case 5:return[2]}}))}))},r}());function V(r,a,u){return e.__awaiter(this,void 0,void 0,(function(){var d;return e.__generator(this,(function(e){switch(e.label){case 0:if(!u.liffId)throw t.createLiffError(i.INVALID_CONFIG,"liffId is necessary for liff.init()");return o.setConfig(u),!s.isInClient()&&n.isLoggedIn()&&(o.getExpireTime()||l.logout()),d=t.qs.parse(window.location.search),!c.isSubWindow()||s.isInClient()?[3,2]:[4,new Promise((function(e){f.getMainWindowOrigin()?e():window.addEventListener("message",(function t(r){var n=r.data,a=r.source,s=r.origin;if(n){var l=n.type,c=n.message;l===i.SUB_WINDOW_HEALTH_CHECK_MESSAGE&&(window.removeEventListener("message",t),c&&o.setAppData(c),f.setMainWindowOrigin(s),a&&a.postMessage&&a.postMessage({status:i.SUB_WINDOW_HEALTH_CHECK_MESSAGE},s),e())}}))}))];case 1:e.sent(),e.label=2;case 2:if(d.error&&d.liffOAuth2Error)throw _=d.error,p=d.error_description,v=_+": "+p.replace(/\+/g," "),t.createLiffError(i.INIT_FAILED,v);return g=d.code,h=o.getLoginTmp(),Boolean(g&&!n.isLoggedIn()&&h&&h.codeVerifier)?[4,P(d.liffClientId)]:[3,4];case 3:e.sent(),e.label=4;case 4:return s.isInClient()?[4,M(r,u)]:[3,6];case 5:return e.sent(),[3,8];case 6:return n.isLoggedIn()?[3,8]:[4,K()];case 7:e.sent(),e.label=8;case 8:return[4,W.invoke()];case 9:return e.sent(),[4,a.runHook("beforeInitFinished")];case 10:return e.sent(),t.replaceUrlCredentialRemoved(window.location.href),[2]}var g,h,_,p,v}))}))}var H=function(){function a(e){this.moduleDriver=e}return Object.defineProperty(a.prototype,"name",{get:function(){return"init"},enumerable:!1,configurable:!0}),a.prototype.install=function(e){var t=e.liff;return this.liff=t,this.init.bind(this)},a.prototype.init=function(a,s,l){return e.__awaiter(this,void 0,void 0,(function(){var c;return e.__generator(this,(function(e){switch(e.label){case 0:f=this.liff,window&&!window.liff&&(window.liff=f),e.label=1;case 1:return e.trys.push([1,9,,11]),[4,Promise.all([T(this.liff),V(this.liff,this.moduleDriver,a)])];case 2:return e.sent(),w(),[4,this.moduleDriver.runHook("beforeInitSuccess")];case 3:if(e.sent(),!a.withLoginOnExternalBrowser||n.isLoggedIn())return[3,7];if(!o.getAutologinAttempt())return[3,4];throw t.createLiffError(i.INIT_FAILED,"Auto login failure");case 4:return o.setAutologinAttempt(),this.liff.login(),[4,new Promise((function(){}))];case 5:e.sent(),e.label=6;case 6:return[3,8];case 7:a.withLoginOnExternalBrowser&&o.clearAutologinAttempt(),e.label=8;case 8:return"function"==typeof s&&s(),r.done(),[3,11];case 9:return c=e.sent(),[4,this.moduleDriver.runHook("initError",c)];case 10:throw e.sent(),"function"==typeof l&&l(c),c;case 11:return[2]}var f}))}))},a}();exports.InitModule=H; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),t=require("@liff/util"),r=require("@liff/ready"),n=require("@liff/is-logged-in"),o=require("@liff/store"),i=require("@liff/consts"),a=require("@liff/extensions"),s=require("@liff/is-in-client"),l=require("@liff/logout"),c=require("@liff/is-sub-window"),f=require("@liff/sub-window"),u=require("@liff/server-api"),d=require("@liff/logger"),g=require("@liff/get-line-version"),h=require("@liff/native-bridge"),_=require("@liff/is-api-available"),p=require("@liff/get-os"),v={iconColor:"#111111",statusBarColor:"BLACK",titleTextColor:"#111111",titleSubtextColor:"#B7B7B7",titleButtonColor:"#111111",titleBackgroundColor:"#FFFFFF",progressBarColor:"#06C755",progressBackgroundColor:"#FFFFFF",titleButtonAreaBackgroundColor:"#1FFFFFFF",titleButtonAreaBorderColor:"#26000000",baseBackgroundColor:"#FFFFFF",baseTextColor:"#000000",lightButtonBorderColor:"rgba(0, 0, 0, 0.15)"},I={iconColor:"#FFFFFF",statusBarColor:"WHITE",titleTextColor:"#FFFFFF",titleSubtextColor:"#949494",titleButtonColor:"#FFFFFF",titleBackgroundColor:"#111111",progressBarColor:"#06C755",progressBackgroundColor:"#111111",titleButtonAreaBackgroundColor:"#1FFFFFFF",titleButtonAreaBorderColor:"#26000000",baseBackgroundColor:"#000000",baseTextColor:"#FFFFFF",lightButtonBorderColor:"rgba(255, 255, 255, 0.5)"};function w(){var e;F("color-scheme",((null==(e=o.getContext())?void 0:e.menuColorSetting)||{adaptableColorSchemes:["light"]}).adaptableColorSchemes.join(" "));var t=window.matchMedia("(prefers-color-scheme: dark)");b({matches:null==t?void 0:t.matches,media:null==t?void 0:t.media}),t.addEventListener?t.addEventListener("change",b):t.addListener&&t.addListener(b)}function b(t){var r=o.getContext(),n=(null==r?void 0:r.menuColorSetting)||{adaptableColorSchemes:["light"],lightModeColor:v,darkModeColor:I},i=n.adaptableColorSchemes,a=n.lightModeColor,s=n.darkModeColor,l=i.includes("dark");t.matches&&l?C(e.__assign(e.__assign({},I),s)):C(e.__assign(e.__assign({},v),a))}function C(e){var r=e.iconColor,n=e.statusBarColor,o=e.titleTextColor,i=e.titleSubtextColor,a=e.titleButtonColor,s=e.titleBackgroundColor,l=e.progressBarColor,c=e.progressBackgroundColor,f=e.titleButtonAreaBackgroundColor,u=e.titleButtonAreaBorderColor,d=e.baseBackgroundColor,g=e.baseTextColor,h=e.lightButtonBorderColor;F("--liff-base-background-color",d),F("--liff-base-text-color",g),F("--liff-base-background-rgb-color",t.convertHexToRgb(d)),F("--liff-base-text-rgb-color",t.convertHexToRgb(g)),F("--liff-light-button-border-color",h),F("--liff-title-text-color",o),F("--liff-title-background-color",s),F("--liff-title-button-color",a),F("--liff-icon-color",r),F("--liff-status-bar-color",n),F("--liff-title-subtext-color",i),F("--liff-progress-bar-color",l),F("--liff-progress-background-color",c),F("--liff-title-button-area-background-color",t.convertArgbToRgba(f)),F("--liff-title-button-area-border-color",t.convertArgbToRgba(u))}function F(e,t){document.documentElement.style.setProperty(e,t)}function T(t){return e.__awaiter(this,void 0,void 0,(function(){return e.__generator(this,(function(e){switch(e.label){case 0:return[4,a.load()];case 1:return e.sent().install(t),[2]}}))}))}function m(){return e.__awaiter(this,void 0,void 0,(function(){return e.__generator(this,(function(e){switch(e.label){case 0:return[4,u.fetch(u.getEndPoint("certs"))];case 1:return[2,e.sent()]}}))}))}function k(t,r,n){return e.__awaiter(this,void 0,void 0,(function(){var o;return e.__generator(this,(function(e){switch(e.label){case 0:return[4,crypto.subtle.importKey("jwk",t,{name:"ECDSA",namedCurve:"P-256"},!1,["verify"])];case 1:return o=e.sent(),[4,crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,n,r)];case 2:return[2,e.sent()]}}))}))}function L(r,n){return e.__awaiter(this,void 0,void 0,(function(){var o,a,s,l,c,f,u,d,g,h,_,p,v,I,w,b;return e.__generator(this,(function(C){switch(C.label){case 0:return o=r.split("."),a=e.__read(o,3),s=a[0],l=a[1],c=a[2],f=JSON.parse(t.base64Url.decode(s)),u=JSON.parse(t.base64Url.decodeUnicode(l)),d=t.convertArrayBuffer(t.base64Url.decode(c)),g=t.convertArrayBuffer(s+"."+l),[4,m()];case 1:if(h=C.sent(),!(_=h.keys.find((function(e){return e.kid===f.kid}))))return[3,6];if(delete _.alg,"ES256"!==f.alg)throw t.createLiffError(i.INVALID_ID_TOKEN,'Invalid "alg" value in ID_TOKEN');p=void 0,C.label=2;case 2:return C.trys.push([2,4,,5]),[4,k(_,g,d)];case 3:return p=C.sent(),[3,5];case 4:throw v=C.sent(),t.createLiffError(i.INVALID_ID_TOKEN,"Failed to use Crypto API to verify ID_TOKEN: "+v);case 5:if(p){if(I="https://access.line.me"!==u.iss,w=u.aud!==n,b=1e3*u.exp<Date.now(),I)throw t.createLiffError(i.INVALID_ID_TOKEN,'Invalid "iss" value in ID_TOKEN');if(w)throw t.createLiffError(i.INVALID_ID_TOKEN,'Invalid "aud" value in ID_TOKEN');if(b)throw t.createLiffError(i.INVALID_ID_TOKEN,'Invalid "exp" value in ID_TOKEN');return[2,u]}throw t.createLiffError(i.INVALID_ID_TOKEN,"Invalid signature in ID_TOKEN");case 6:throw t.createLiffError(i.INVALID_ID_TOKEN,'Invalid "kid" value in ID_TOKEN');case 7:return[2]}}))}))}function E(e){var t=e.split(".");if(t[1])try{var r=t[1].replace(/-/g,"+").replace(/_/g,"/");return JSON.parse(window.atob(r))}catch(n){return null}return null}function A(e){var r=e.pathname,n=e.query,o="liff://"+r+(n?"?"+t.qs.stringify(n):"");location.href=o}var D=null;function y(){"boolean"==typeof D&&d.logger.warn("liff.init is not expected to be called more than once"),D=!!o.getIsSubsequentLiffApp()||!(!s.isInClient()||t.qs.parse(window.location.hash).feature_token||o.getFeatureToken())&&(o.setIsSubsequentLiffApp(!0),!0)}function B(){return Boolean(D)}function S(t,r){return e.__awaiter(this,void 0,void 0,(function(){var n;return e.__generator(this,(function(e){switch(e.label){case 0:return(n=o.getMST())?[2,n]:t&&r?[4,f.getMSTByMSIT({msit:t,mstVerifier:r})]:[3,2];case 1:return[2,e.sent().mst];case 2:return[2,null]}}))}))}function x(e){return u.fetch(u.getEndPoint("apps")+"/"+e+"/featureToken")}function N(r){return e.__awaiter(this,void 0,void 0,(function(){var i,a,s,l;return e.__generator(this,(function(e){switch(e.label){case 0:return i=t.qs.parse(window.location.hash),a=t.objectAssignKeyOnlyWithValue({access_token:o.getAccessToken(),context_token:o.getRawContext(),feature_token:o.getFeatureToken(),id_token:o.getIDToken(),client_id:o.getClientId(),mst_challenge:o.getMSTChallenge(),mst_verifier:o.getMSTVerifier(),msit:o.getMSIT()},i),B()?n.isLoggedIn()?[4,x(r)]:[3,2]:[3,3];case 1:s=e.sent().featureToken,a.feature_token||(a.feature_token=s),e.label=2;case 2:(l=t.extractChannelIdFromLiffId(r))&&(a.client_id=l),e.label=3;case 3:return[2,a]}}))}))}function O(e){if(e.persisted&&_.isApiAvailable("multipleLiffTransition"))if("ios"===p.getOS())window.location.reload();else{var r=o.getConfig().liffId,n=o.getFeatureToken();if(!r)throw t.createLiffError(i.INIT_FAILED,"Invalid LIFF ID.");if(!n)throw t.createLiffError(i.FORBIDDEN,"Invalid featureToken for client features");A({pathname:"app/"+r,query:{feature_token:n}})}}function q(r,n){return e.__awaiter(this,void 0,void 0,(function(){var o,i;return e.__generator(this,(function(e){switch(e.label){case 0:return[4,u.verifyAccessToken(r)];case 1:return o=e.sent().client_id,i=t.extractChannelIdFromLiffId(n),[2,o===i]}}))}))}function M(r,a){return e.__awaiter(this,void 0,void 0,(function(){var s,l,u,p,v,I,w,b,C,F,T,m,k;return e.__generator(this,(function(e){switch(e.label){case 0:return[4,new Promise((function(e){var r=g.getLineVersion();if(!r||t.compareVersion(r,"9.5.0")<0)e();else if(window._liff&&window._liff.features)e();else{d.logger.debug("cannot find window._liff.features, listen to ready event");var n=function(){d.logger.debug("ready event is fired"),h.removeListener("ready",n),e()};h.addListener("ready",n)}}))];case 1:return e.sent(),y(),[4,N(a.liffId)];case 2:return s=e.sent(),l=s.access_token,u=s.context_token,p=s.feature_token,v=s.id_token,I=s.client_id,w=s.mst_verifier,b=s.mst_challenge,C=s.msit,u&&o.setContext(E(u)),!c.isSubWindow()&&p&&(!function(e,t){_.isApiAvailable("multipleLiffTransition")&&A({pathname:"app/"+e,query:{feature_token:t}})}(a.liffId,p),B()&&o.setFeatureToken(p)),b&&o.setMSTChallenge(b),w&&o.setMSTVerifier(w),I&&o.setClientId(I),C&&o.setMSIT(C),window.addEventListener("pageshow",O),n.isLoggedIn()?[3,7]:p&&l?[3,5]:B()?(F=t.addParamsToUrl(location.href,{"liff.hback":"2"}),r.login({redirectUri:F}),[4,new Promise((function(){}))]):[3,4];case 3:e.sent(),e.label=4;case 4:throw r.login(),t.createLiffError(i.INIT_FAILED,"Failed to parse feature_token or access_token");case 5:return[4,q(l,a.liffId)];case 6:if(!e.sent())throw r.login(),t.createLiffError(i.INIT_FAILED,"Failed to verify access_token");o.setFeatureToken(p),o.setAccessToken(l),e.label=7;case 7:return[4,S(C,w)];case 8:return(T=e.sent())?(o.setMST(T),[4,f.getAppData({mst:T})]):[3,10];case 9:(m=e.sent().data)&&o.setAppData(JSON.stringify(m)),e.label=10;case 10:return v&&!o.getIDToken()&&o.setIDToken(v),v&&I&&!o.getDecodedIDToken()?[4,L(v,I)]:[3,12];case 11:(k=e.sent())&&o.setDecodedIDToken(k),e.label=12;case 12:return[2]}}))}))}function U(r){return e.__awaiter(this,void 0,void 0,(function(){var n,a,s,l,c,f,d;return e.__generator(this,(function(e){switch(e.label){case 0:return n=u.getEndPoint("apps"),a=n+"/"+r+"/contextToken",s=o.getAccessToken(),l={"Content-Type":"application/json",Accept:"application/json"},s&&(l.Authorization="Bearer "+s),[4,u.fetch(a,{headers:l})];case 1:if(c=e.sent(),!(f=c.contextToken))throw t.createLiffError(i.INIT_FAILED,"Can not get context from server.");if(!(d=E(f)))throw t.createLiffError(i.INIT_FAILED,"Invalid context token.");return[2,d]}}))}))}function K(){return e.__awaiter(this,void 0,void 0,(function(){var r,n;return e.__generator(this,(function(e){switch(e.label){case 0:if(!(r=o.getConfig().liffId))throw t.createLiffError(i.INIT_FAILED,"Invalid LIFF ID.");return[4,U(r)];case 1:return n=e.sent(),o.setContext(n),[2]}}))}))}function P(r){return e.__awaiter(this,void 0,void 0,(function(){var n,i,a,s=this;return e.__generator(this,(function(l){switch(l.label){case 0:n=function(){return e.__awaiter(s,void 0,void 0,(function(){var n,i,a,s,l,c;return e.__generator(this,(function(e){switch(e.label){case 0:return[4,(f=o.getConfig(),d=t.qs.parse(window.location.search),g=o.getLoginTmp(),h={grant_type:"authorization_code",client_id:d.liffClientId,appId:f.liffId,code:d.code,code_verifier:g.codeVerifier,redirect_uri:f.redirectUri||d.liffRedirectUri,id_token_key_type:"JWK"},_=t.qs.stringify(h),u.fetch(u.getEndPoint("token"),{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8"},body:_}))];case 1:return n=e.sent(),i=n.access_token,a=n.id_token,s=n.expires_in,o.setClientId(r),o.setAccessToken(i),o.setExpireTime(new Date(Date.now()+1e3*s)),o.removeLoginTmp(),a?(o.setIDToken(a),[4,L(a,r)]):[3,3];case 2:(l=e.sent())&&o.setDecodedIDToken(l),e.label=3;case 3:return(c=t.qs.parse(location.hash).context_token)?(o.setContext(E(c)),[3,6]):[3,4];case 4:return[4,K()];case 5:e.sent(),e.label=6;case 6:return[2]}var f,d,g,h,_}))}))},l.label=1;case 1:return l.trys.push([1,3,,4]),[4,n()];case 2:return l.sent(),[3,4];case 3:throw i=l.sent(),a=i,o.removeLoginTmp(),a;case 4:return[2]}}))}))}var W=new(function(){function r(){var e=this;this.getAndValidateContext=function(){var e=o.getContext();if(!e)throw t.createLiffError(i.INIT_FAILED,"Could not get Context from server.");if(!e.endpointUrl)throw t.createLiffError(i.INIT_FAILED,"Could not get endpointUrl from server.");if(!e.permanentLinkPattern)throw t.createLiffError(i.INIT_FAILED,"Could not get permanentLinkPattern from server.");return e},this.decodeState=function(t){var r=e.getAndValidateContext();t=t.replace(/\n/g,"%0D%0A");var n=!r.endpointUrl.startsWith("/?")&&r.endpointUrl.includes("/?")||!r.endpointUrl.startsWith("/#")&&r.endpointUrl.includes("/#")||r.endpointUrl.endsWith("/")||!t.startsWith("/?")&&t.includes("/?")||!t.startsWith("/#")&&t.includes("/#")||t.endsWith("/"),o=new URL(r.endpointUrl),i=o.origin,a=o.pathname,s=o.search,l=new URL(""+i+e.attachSlashAtStart(t)),c=l.pathname,f=l.search,u=l.hash,d=""+s+(s?f.replace(/\?/g,"&"):f),g=(""+a+e.attachSlashAtStart(c)).replace("//","/");return(g=e.attachSlashAtStart(""+g)).endsWith("/")&&!n&&(g=g.substring(0,g.length-1)),(""+i+g+d+u).replace(/%0D%0A/g,"\n")}}return r.prototype.attachSlashAtStart=function(e){return(e&&e.length>0&&!e.startsWith("/")?"/":"")+e},r.prototype.invoke=function(){return e.__awaiter(this,void 0,void 0,(function(){var r,n,o,a,s;return e.__generator(this,(function(e){switch(e.label){case 0:if(r=t.qs.parse(window.location.search),"string"!=typeof(n=r["liff.state"]))return[2];e.label=1;case 1:return e.trys.push([1,4,,5]),o=location.href,(a=this.decodeState(n))===o?[3,3]:(r["liff.hback"]?location.replace(t.addParamsToUrl(a,{"liff.hback":r["liff.hback"]})):location.replace(a),[4,new Promise((function(){}))]);case 2:e.sent(),e.label=3;case 3:return[3,5];case 4:if((s=e.sent()).code===i.INIT_FAILED)throw s;return d.logger.debug(s),[3,5];case 5:return[2]}}))}))},r}());function V(r,a,u){return e.__awaiter(this,void 0,void 0,(function(){var d;return e.__generator(this,(function(e){switch(e.label){case 0:if(!u.liffId)throw t.createLiffError(i.INVALID_CONFIG,"liffId is necessary for liff.init()");return o.setConfig(u),!s.isInClient()&&n.isLoggedIn()&&(o.getExpireTime()||l.logout()),d=t.qs.parse(window.location.search),!c.isSubWindow()||s.isInClient()?[3,2]:[4,new Promise((function(e){f.getMainWindowOrigin()?e():window.addEventListener("message",(function t(r){var n=r.data,a=r.source,s=r.origin;if(n){var l=n.type,c=n.message;l===i.SUB_WINDOW_HEALTH_CHECK_MESSAGE&&(window.removeEventListener("message",t),c&&o.setAppData(c),f.setMainWindowOrigin(s),a&&a.postMessage&&a.postMessage({status:i.SUB_WINDOW_HEALTH_CHECK_MESSAGE},s),e())}}))}))];case 1:e.sent(),e.label=2;case 2:if(d.error&&d.liffOAuth2Error)throw _=d.error,p=d.error_description,v=_+": "+p.replace(/\+/g," "),t.createLiffError(i.INIT_FAILED,v);return g=d.code,h=o.getLoginTmp(),Boolean(g&&!n.isLoggedIn()&&h&&h.codeVerifier)?[4,P(d.liffClientId)]:[3,4];case 3:e.sent(),e.label=4;case 4:return s.isInClient()?[4,M(r,u)]:[3,6];case 5:return e.sent(),[3,8];case 6:return n.isLoggedIn()?[3,8]:[4,K()];case 7:e.sent(),e.label=8;case 8:return[4,W.invoke()];case 9:return e.sent(),[4,a.runHook("beforeInitFinished")];case 10:return e.sent(),t.replaceUrlCredentialRemoved(window.location.href),[2]}var g,h,_,p,v}))}))}var H=function(){function a(e){this.moduleDriver=e}return Object.defineProperty(a.prototype,"name",{get:function(){return"init"},enumerable:!1,configurable:!0}),a.prototype.install=function(e){var t=e.liff;return this.liff=t,this.init.bind(this)},a.prototype.init=function(a,s,l){return e.__awaiter(this,void 0,void 0,(function(){var c;return e.__generator(this,(function(e){switch(e.label){case 0:f=this.liff,window&&!window.liff&&(window.liff=f),e.label=1;case 1:return e.trys.push([1,9,,11]),[4,Promise.all([T(this.liff),V(this.liff,this.moduleDriver,a)])];case 2:return e.sent(),w(),[4,this.moduleDriver.runHook("beforeInitSuccess")];case 3:if(e.sent(),!a.withLoginOnExternalBrowser||n.isLoggedIn())return[3,7];if(!o.getAutologinAttempt())return[3,4];throw t.createLiffError(i.INIT_FAILED,"Auto login failure");case 4:return o.setAutologinAttempt(),this.liff.login(),[4,new Promise((function(){}))];case 5:e.sent(),e.label=6;case 6:return[3,8];case 7:a.withLoginOnExternalBrowser&&o.clearAutologinAttempt(),e.label=8;case 8:return"function"==typeof s&&s(),r.done(),[3,11];case 9:return c=e.sent(),[4,this.moduleDriver.runHook("initError",c)];case 10:throw e.sent(),"function"==typeof l&&l(c),c;case 11:return[2]}var f}))}))},a}();exports.InitModule=H; |
@@ -1,1 +0,1 @@ | ||
import{__assign as e,__awaiter as t,__generator as r,__read as n}from"tslib";import{convertHexToRgb as o,convertArgbToRgba as i,createLiffError as a,base64Url as s,convertArrayBuffer as l,compareVersion as c,qs as u,extractChannelIdFromLiffId as f,objectAssignKeyOnlyWithValue as d,addParamsToUrl as h,replaceUrlCredentialRemoved as p}from"@liff/util";import{done as v}from"@liff/ready";import{isLoggedIn as m}from"@liff/is-logged-in";import{getContext as w,getLoginTmp as g,getExpireTime as b,getIsSubsequentLiffApp as C,getFeatureToken as k,setIsSubsequentLiffApp as F,getMST as _,getAccessToken as y,getRawContext as B,getIDToken as I,getClientId as x,getMSTChallenge as S,getMSTVerifier as T,getMSIT as A,getConfig as E,setDecodedIDToken as D,setAppData as L,setMST as O,setFeatureToken as U,setAccessToken as P,setContext as N,setMSTChallenge as K,setMSTVerifier as W,setClientId as M,setMSIT as j,setIDToken as H,getDecodedIDToken as J,removeLoginTmp as V,setExpireTime as q,setConfig as R,clearAutologinAttempt as z,setAutologinAttempt as G,getAutologinAttempt as Q}from"@liff/store";import{INIT_FAILED as X,INVALID_ID_TOKEN as Y,FORBIDDEN as Z,SUB_WINDOW_HEALTH_CHECK_MESSAGE as $,INVALID_CONFIG as ee}from"@liff/consts";import{load as te}from"@liff/extensions";import{isInClient as re}from"@liff/is-in-client";import{logout as ne}from"@liff/logout";import{isSubWindow as oe}from"@liff/is-sub-window";import{getMSTByMSIT as ie,getAppData as ae,getMainWindowOrigin as se,setMainWindowOrigin as le}from"@liff/sub-window";import{fetch as ce,getEndPoint as ue,verifyAccessToken as fe}from"@liff/server-api";import{logger as de}from"@liff/logger";import{getLineVersion as he}from"@liff/get-line-version";import{addListener as pe,removeListener as ve}from"@liff/native-bridge";import{isApiAvailable as me}from"@liff/is-api-available";import{getOS as we}from"@liff/get-os";var ge={iconColor:"#111111",statusBarColor:"BLACK",titleTextColor:"#111111",titleSubtextColor:"#B7B7B7",titleButtonColor:"#111111",titleBackgroundColor:"#FFFFFF",progressBarColor:"#06C755",progressBackgroundColor:"#FFFFFF",titleButtonAreaBackgroundColor:"#1FFFFFFF",titleButtonAreaBorderColor:"#26000000",baseBackgroundColor:"#FFFFFF",baseTextColor:"#000000",lightButtonBorderColor:"rgba(0, 0, 0, 0.15)"},be={iconColor:"#FFFFFF",statusBarColor:"WHITE",titleTextColor:"#FFFFFF",titleSubtextColor:"#949494",titleButtonColor:"#FFFFFF",titleBackgroundColor:"#111111",progressBarColor:"#06C755",progressBackgroundColor:"#111111",titleButtonAreaBackgroundColor:"#1FFFFFFF",titleButtonAreaBorderColor:"#26000000",baseBackgroundColor:"#000000",baseTextColor:"#FFFFFF",lightButtonBorderColor:"rgba(255, 255, 255, 0.5)"};function Ce(){var e;_e("color-scheme",((null==(e=w())?void 0:e.menuColorSetting)||{adaptableColorSchemes:["light"]}).adaptableColorSchemes.join(" "));var t=window.matchMedia("(prefers-color-scheme: dark)");ke({matches:null==t?void 0:t.matches,media:null==t?void 0:t.media}),t.addEventListener?t.addEventListener("change",ke):t.addListener&&t.addListener(ke)}function ke(t){var r=w(),n=(null==r?void 0:r.menuColorSetting)||{adaptableColorSchemes:["light"],lightModeColor:ge,darkModeColor:be},o=n.adaptableColorSchemes,i=n.lightModeColor,a=n.darkModeColor,s=o.includes("dark");t.matches&&s?Fe(e(e({},be),a)):Fe(e(e({},ge),i))}function Fe(e){var t=e.iconColor,r=e.statusBarColor,n=e.titleTextColor,a=e.titleSubtextColor,s=e.titleButtonColor,l=e.titleBackgroundColor,c=e.progressBarColor,u=e.progressBackgroundColor,f=e.titleButtonAreaBackgroundColor,d=e.titleButtonAreaBorderColor,h=e.baseBackgroundColor,p=e.baseTextColor,v=e.lightButtonBorderColor;_e("--liff-base-background-color",h),_e("--liff-base-text-color",p),_e("--liff-base-background-rgb-color",o(h)),_e("--liff-base-text-rgb-color",o(p)),_e("--liff-light-button-border-color",v),_e("--liff-title-text-color",n),_e("--liff-title-background-color",l),_e("--liff-title-button-color",s),_e("--liff-icon-color",t),_e("--liff-status-bar-color",r),_e("--liff-title-subtext-color",a),_e("--liff-progress-bar-color",c),_e("--liff-progress-background-color",u),_e("--liff-title-button-area-background-color",i(f)),_e("--liff-title-button-area-border-color",i(d))}function _e(e,t){document.documentElement.style.setProperty(e,t)}function ye(e){return t(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,te()];case 1:return t.sent().install(e),[2]}}))}))}function Be(){return t(this,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,ce(ue("certs"))];case 1:return[2,e.sent()]}}))}))}function Ie(e,n,o){return t(this,void 0,void 0,(function(){var t;return r(this,(function(r){switch(r.label){case 0:return[4,crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:"P-256"},!1,["verify"])];case 1:return t=r.sent(),[4,crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},t,o,n)];case 2:return[2,r.sent()]}}))}))}function xe(e,o){return t(this,void 0,void 0,(function(){var t,i,c,u,f,d,h,p,v,m,w,g,b,C,k,F;return r(this,(function(r){switch(r.label){case 0:return t=e.split("."),i=n(t,3),c=i[0],u=i[1],f=i[2],d=JSON.parse(s.decode(c)),h=JSON.parse(s.decodeUnicode(u)),p=l(s.decode(f)),v=l(c+"."+u),[4,Be()];case 1:if(m=r.sent(),!(w=m.keys.find((function(e){return e.kid===d.kid}))))return[3,6];if(delete w.alg,"ES256"!==d.alg)throw a(Y,'Invalid "alg" value in ID_TOKEN');g=void 0,r.label=2;case 2:return r.trys.push([2,4,,5]),[4,Ie(w,v,p)];case 3:return g=r.sent(),[3,5];case 4:throw b=r.sent(),a(Y,"Failed to use Crypto API to verify ID_TOKEN: "+b);case 5:if(g){if(C="https://access.line.me"!==h.iss,k=h.aud!==o,F=1e3*h.exp<Date.now(),C)throw a(Y,'Invalid "iss" value in ID_TOKEN');if(k)throw a(Y,'Invalid "aud" value in ID_TOKEN');if(F)throw a(Y,'Invalid "exp" value in ID_TOKEN');return[2,h]}throw a(Y,"Invalid signature in ID_TOKEN");case 6:throw a(Y,'Invalid "kid" value in ID_TOKEN');case 7:return[2]}}))}))}function Se(e){var t=e.split(".");if(t[1])try{var r=t[1].replace(/-/g,"+").replace(/_/g,"/");return JSON.parse(window.atob(r))}catch(n){return null}return null}function Te(e){var t=e.pathname,r=e.query,n="liff://"+t+(r?"?"+u.stringify(r):"");location.href=n}var Ae=null;function Ee(){"boolean"==typeof Ae&&de.warn("liff.init is not expected to be called more than once"),Ae=!!C()||!(!re()||u.parse(window.location.hash).feature_token||k())&&(F(!0),!0)}function De(){return Boolean(Ae)}function Le(e,n){return t(this,void 0,void 0,(function(){var t;return r(this,(function(r){switch(r.label){case 0:return(t=_())?[2,t]:e&&n?[4,ie({msit:e,mstVerifier:n})]:[3,2];case 1:return[2,r.sent().mst];case 2:return[2,null]}}))}))}function Oe(e){return ce(ue("apps")+"/"+e+"/featureToken")}function Ue(e){return t(this,void 0,void 0,(function(){var t,n,o,i,a,s,l;return r(this,(function(r){switch(r.label){case 0:return t=u.parse(window.location.hash),n=d({access_token:y(),context_token:B(),feature_token:k(),id_token:I(),client_id:x(),mst_challenge:S(),mst_verifier:T(),msit:A()},t),De()?m()?[4,Oe(e)]:[3,2]:[3,3];case 1:i=r.sent(),a=i.featureToken,s=i.features,o=s,n.feature_token||(n.feature_token=a),r.label=2;case 2:(l=f(e))&&(n.client_id=l),r.label=3;case 3:return[2,{credentials:n,features:o}]}}))}))}function Pe(e){if(e.persisted&&me("multipleLiffTransition"))if("ios"===we())window.location.reload();else{var t=E().liffId,r=k();if(!t)throw a(X,"Invalid LIFF ID.");if(!r)throw a(Z,"Invalid featureToken for client features");Te({pathname:"app/"+t,query:{feature_token:r}})}}function Ne(e,n){return t(this,void 0,void 0,(function(){var t,o;return r(this,(function(r){switch(r.label){case 0:return[4,fe(e)];case 1:return t=r.sent().client_id,o=f(n),[2,t===o]}}))}))}function Ke(e,n){return t(this,void 0,void 0,(function(){var t,o,i,s,l,u,f,d,p,v,w,g,b;return r(this,(function(r){switch(r.label){case 0:return[4,new Promise((function(e){var t=he();if(!t||c(t,"9.5.0")<0)e();else if(window._liff&&window._liff.features)e();else{de.debug("cannot find window._liff.features, listen to ready event");var r=function(){de.debug("ready event is fired"),ve("ready",r),e()};pe("ready",r)}}))];case 1:return r.sent(),Ee(),[4,Ue(n.liffId)];case 2:return t=r.sent().credentials,o=t.access_token,i=t.context_token,s=t.feature_token,l=t.id_token,u=t.client_id,f=t.mst_verifier,d=t.mst_challenge,p=t.msit,!oe()&&s&&(!function(e,t){me("multipleLiffTransition")&&Te({pathname:"app/"+e,query:{feature_token:t}})}(n.liffId,s),De()&&U(s)),i&&N(Se(i)),d&&K(d),f&&W(f),u&&M(u),p&&j(p),window.addEventListener("pageshow",Pe),m()?[3,7]:s&&o?[3,5]:De()?(v=h(location.href,{"liff.hback":"2"}),e.login({redirectUri:v}),[4,new Promise((function(){}))]):[3,4];case 3:r.sent(),r.label=4;case 4:throw e.login(),a(X,"Failed to parse feature_token or access_token");case 5:return[4,Ne(o,n.liffId)];case 6:if(!r.sent())throw e.login(),a(X,"Failed to verify access_token");U(s),P(o),r.label=7;case 7:return[4,Le(p,f)];case 8:return(w=r.sent())?(O(w),[4,ae({mst:w})]):[3,10];case 9:(g=r.sent().data)&&L(JSON.stringify(g)),r.label=10;case 10:return l&&!I()&&H(l),l&&u&&!J()?[4,xe(l,u)]:[3,12];case 11:(b=r.sent())&&D(b),r.label=12;case 12:return[2]}}))}))}function We(e){return t(this,void 0,void 0,(function(){var t,n,o,i,s,l,c;return r(this,(function(r){switch(r.label){case 0:return t=ue("apps"),n=t+"/"+e+"/contextToken",o=y(),i={"Content-Type":"application/json",Accept:"application/json"},o&&(i.Authorization="Bearer "+o),[4,ce(n,{headers:i})];case 1:if(s=r.sent(),!(l=s.contextToken))throw a(X,"Can not get context from server.");if(!(c=Se(l)))throw a(X,"Invalid context token.");return[2,c]}}))}))}function Me(){return t(this,void 0,void 0,(function(){var e,t;return r(this,(function(r){switch(r.label){case 0:if(!(e=E().liffId))throw a(X,"Invalid LIFF ID.");return[4,We(e)];case 1:return t=r.sent(),N(t),[2]}}))}))}function je(e){return t(this,void 0,void 0,(function(){var n,o,i,a=this;return r(this,(function(s){switch(s.label){case 0:n=function(){return t(a,void 0,void 0,(function(){var t,n,o,i,a,s;return r(this,(function(r){switch(r.label){case 0:return[4,(l=E(),c=u.parse(window.location.search),f=g(),d={grant_type:"authorization_code",client_id:c.liffClientId,appId:l.liffId,code:c.code,code_verifier:f.codeVerifier,redirect_uri:l.redirectUri||c.liffRedirectUri,id_token_key_type:"JWK"},h=u.stringify(d),ce(ue("token"),{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8"},body:h}))];case 1:return t=r.sent(),n=t.access_token,o=t.id_token,i=t.expires_in,M(e),P(n),q(new Date(Date.now()+1e3*i)),V(),o?(H(o),[4,xe(o,e)]):[3,3];case 2:(a=r.sent())&&D(a),r.label=3;case 3:return(s=u.parse(location.hash).context_token)?(N(Se(s)),[3,6]):[3,4];case 4:return[4,Me()];case 5:r.sent(),r.label=6;case 6:return[2]}var l,c,f,d,h}))}))},s.label=1;case 1:return s.trys.push([1,3,,4]),[4,n()];case 2:return s.sent(),[3,4];case 3:throw o=s.sent(),i=o,V(),i;case 4:return[2]}}))}))}var He=new(function(){function e(){var e=this;this.getAndValidateContext=function(){var e=w();if(!e)throw a(X,"Could not get Context from server.");if(!e.endpointUrl)throw a(X,"Could not get endpointUrl from server.");if(!e.permanentLinkPattern)throw a(X,"Could not get permanentLinkPattern from server.");return e},this.decodeState=function(t){var r=e.getAndValidateContext();t=t.replace(/\n/g,"%0D%0A");var n=!r.endpointUrl.startsWith("/?")&&r.endpointUrl.includes("/?")||!r.endpointUrl.startsWith("/#")&&r.endpointUrl.includes("/#")||r.endpointUrl.endsWith("/")||!t.startsWith("/?")&&t.includes("/?")||!t.startsWith("/#")&&t.includes("/#")||t.endsWith("/"),o=new URL(r.endpointUrl),i=o.origin,a=o.pathname,s=o.search,l=new URL(""+i+e.attachSlashAtStart(t)),c=l.pathname,u=l.search,f=l.hash,d=""+s+(s?u.replace(/\?/g,"&"):u),h=(""+a+e.attachSlashAtStart(c)).replace("//","/");return(h=e.attachSlashAtStart(""+h)).endsWith("/")&&!n&&(h=h.substring(0,h.length-1)),(""+i+h+d+f).replace(/%0D%0A/g,"\n")}}return e.prototype.attachSlashAtStart=function(e){return(e&&e.length>0&&!e.startsWith("/")?"/":"")+e},e.prototype.invoke=function(){return t(this,void 0,void 0,(function(){var e,t,n,o,i;return r(this,(function(r){switch(r.label){case 0:if(e=u.parse(window.location.search),"string"!=typeof(t=e["liff.state"]))return[2];r.label=1;case 1:return r.trys.push([1,4,,5]),n=location.href,(o=this.decodeState(t))===n?[3,3]:(e["liff.hback"]?location.replace(h(o,{"liff.hback":e["liff.hback"]})):location.replace(o),[4,new Promise((function(){}))]);case 2:r.sent(),r.label=3;case 3:return[3,5];case 4:if((i=r.sent()).code===X)throw i;return de.debug(i),[3,5];case 5:return[2]}}))}))},e}());function Je(e,n,o){return t(this,void 0,void 0,(function(){var t;return r(this,(function(r){switch(r.label){case 0:if(!o.liffId)throw a(ee,"liffId is necessary for liff.init()");return R(o),!re()&&m()&&(b()||ne()),t=u.parse(window.location.search),!oe()||re()?[3,2]:[4,new Promise((function(e){se()?e():window.addEventListener("message",(function t(r){var n=r.data,o=r.source,i=r.origin;if(n){var a=n.type,s=n.message;a===$&&(window.removeEventListener("message",t),s&&L(s),le(i),o&&o.postMessage&&o.postMessage({status:$},i),e())}}))}))];case 1:r.sent(),r.label=2;case 2:if(t.error&&t.liffOAuth2Error)throw l=t.error,c=t.error_description,f=c.replace(/\+/g," "),a(X,l+": "+f);return i=t.code,s=g(),Boolean(i&&!m()&&s&&s.codeVerifier)?[4,je(t.liffClientId)]:[3,4];case 3:r.sent(),r.label=4;case 4:return re()?[4,Ke(e,o)]:[3,6];case 5:return r.sent(),[3,8];case 6:return m()?[3,8]:[4,Me()];case 7:r.sent(),r.label=8;case 8:return[4,He.invoke()];case 9:return r.sent(),[4,n.runHook("beforeInitFinished")];case 10:return r.sent(),p(window.location.href),[2]}var i,s,l,c,f}))}))}var Ve=function(){function e(e){this.moduleDriver=e}return Object.defineProperty(e.prototype,"name",{get:function(){return"init"},enumerable:!1,configurable:!0}),e.prototype.install=function(e){var t=e.liff;return this.liff=t,this.init.bind(this)},e.prototype.init=function(e,n,o){return t(this,void 0,void 0,(function(){var t;return r(this,(function(r){switch(r.label){case 0:i=this.liff,window&&!window.liff&&(window.liff=i),r.label=1;case 1:return r.trys.push([1,9,,11]),[4,Promise.all([ye(this.liff),Je(this.liff,this.moduleDriver,e)])];case 2:return r.sent(),Ce(),[4,this.moduleDriver.runHook("beforeInitSuccess")];case 3:if(r.sent(),!e.withLoginOnExternalBrowser||m())return[3,7];if(!Q())return[3,4];throw a(X,"Auto login failure");case 4:return G(),this.liff.login(),[4,new Promise((function(){}))];case 5:r.sent(),r.label=6;case 6:return[3,8];case 7:e.withLoginOnExternalBrowser&&z(),r.label=8;case 8:return"function"==typeof n&&n(),v(),[3,11];case 9:return t=r.sent(),[4,this.moduleDriver.runHook("initError",t)];case 10:throw r.sent(),"function"==typeof o&&o(t),t;case 11:return[2]}var i}))}))},e}();export{Ve as InitModule}; | ||
import{__assign as e,__awaiter as t,__generator as r,__read as n}from"tslib";import{convertHexToRgb as o,convertArgbToRgba as i,createLiffError as a,base64Url as s,convertArrayBuffer as l,compareVersion as c,qs as u,extractChannelIdFromLiffId as f,objectAssignKeyOnlyWithValue as d,addParamsToUrl as h,replaceUrlCredentialRemoved as p}from"@liff/util";import{done as v}from"@liff/ready";import{isLoggedIn as m}from"@liff/is-logged-in";import{getContext as w,getLoginTmp as g,getExpireTime as b,getIsSubsequentLiffApp as C,getFeatureToken as k,setIsSubsequentLiffApp as F,getMST as _,getAccessToken as y,getRawContext as B,getIDToken as I,getClientId as x,getMSTChallenge as S,getMSTVerifier as T,getMSIT as A,getConfig as E,setDecodedIDToken as D,setAppData as L,setMST as O,setFeatureToken as U,setAccessToken as P,setContext as N,setMSTChallenge as K,setMSTVerifier as W,setClientId as M,setMSIT as j,setIDToken as H,getDecodedIDToken as J,removeLoginTmp as V,setExpireTime as q,setConfig as R,clearAutologinAttempt as z,setAutologinAttempt as G,getAutologinAttempt as Q}from"@liff/store";import{INIT_FAILED as X,INVALID_ID_TOKEN as Y,FORBIDDEN as Z,SUB_WINDOW_HEALTH_CHECK_MESSAGE as $,INVALID_CONFIG as ee}from"@liff/consts";import{load as te}from"@liff/extensions";import{isInClient as re}from"@liff/is-in-client";import{logout as ne}from"@liff/logout";import{isSubWindow as oe}from"@liff/is-sub-window";import{getMSTByMSIT as ie,getAppData as ae,getMainWindowOrigin as se,setMainWindowOrigin as le}from"@liff/sub-window";import{fetch as ce,getEndPoint as ue,verifyAccessToken as fe}from"@liff/server-api";import{logger as de}from"@liff/logger";import{getLineVersion as he}from"@liff/get-line-version";import{addListener as pe,removeListener as ve}from"@liff/native-bridge";import{isApiAvailable as me}from"@liff/is-api-available";import{getOS as we}from"@liff/get-os";var ge={iconColor:"#111111",statusBarColor:"BLACK",titleTextColor:"#111111",titleSubtextColor:"#B7B7B7",titleButtonColor:"#111111",titleBackgroundColor:"#FFFFFF",progressBarColor:"#06C755",progressBackgroundColor:"#FFFFFF",titleButtonAreaBackgroundColor:"#1FFFFFFF",titleButtonAreaBorderColor:"#26000000",baseBackgroundColor:"#FFFFFF",baseTextColor:"#000000",lightButtonBorderColor:"rgba(0, 0, 0, 0.15)"},be={iconColor:"#FFFFFF",statusBarColor:"WHITE",titleTextColor:"#FFFFFF",titleSubtextColor:"#949494",titleButtonColor:"#FFFFFF",titleBackgroundColor:"#111111",progressBarColor:"#06C755",progressBackgroundColor:"#111111",titleButtonAreaBackgroundColor:"#1FFFFFFF",titleButtonAreaBorderColor:"#26000000",baseBackgroundColor:"#000000",baseTextColor:"#FFFFFF",lightButtonBorderColor:"rgba(255, 255, 255, 0.5)"};function Ce(){var e;_e("color-scheme",((null==(e=w())?void 0:e.menuColorSetting)||{adaptableColorSchemes:["light"]}).adaptableColorSchemes.join(" "));var t=window.matchMedia("(prefers-color-scheme: dark)");ke({matches:null==t?void 0:t.matches,media:null==t?void 0:t.media}),t.addEventListener?t.addEventListener("change",ke):t.addListener&&t.addListener(ke)}function ke(t){var r=w(),n=(null==r?void 0:r.menuColorSetting)||{adaptableColorSchemes:["light"],lightModeColor:ge,darkModeColor:be},o=n.adaptableColorSchemes,i=n.lightModeColor,a=n.darkModeColor,s=o.includes("dark");t.matches&&s?Fe(e(e({},be),a)):Fe(e(e({},ge),i))}function Fe(e){var t=e.iconColor,r=e.statusBarColor,n=e.titleTextColor,a=e.titleSubtextColor,s=e.titleButtonColor,l=e.titleBackgroundColor,c=e.progressBarColor,u=e.progressBackgroundColor,f=e.titleButtonAreaBackgroundColor,d=e.titleButtonAreaBorderColor,h=e.baseBackgroundColor,p=e.baseTextColor,v=e.lightButtonBorderColor;_e("--liff-base-background-color",h),_e("--liff-base-text-color",p),_e("--liff-base-background-rgb-color",o(h)),_e("--liff-base-text-rgb-color",o(p)),_e("--liff-light-button-border-color",v),_e("--liff-title-text-color",n),_e("--liff-title-background-color",l),_e("--liff-title-button-color",s),_e("--liff-icon-color",t),_e("--liff-status-bar-color",r),_e("--liff-title-subtext-color",a),_e("--liff-progress-bar-color",c),_e("--liff-progress-background-color",u),_e("--liff-title-button-area-background-color",i(f)),_e("--liff-title-button-area-border-color",i(d))}function _e(e,t){document.documentElement.style.setProperty(e,t)}function ye(e){return t(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,te()];case 1:return t.sent().install(e),[2]}}))}))}function Be(){return t(this,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,ce(ue("certs"))];case 1:return[2,e.sent()]}}))}))}function Ie(e,n,o){return t(this,void 0,void 0,(function(){var t;return r(this,(function(r){switch(r.label){case 0:return[4,crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:"P-256"},!1,["verify"])];case 1:return t=r.sent(),[4,crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},t,o,n)];case 2:return[2,r.sent()]}}))}))}function xe(e,o){return t(this,void 0,void 0,(function(){var t,i,c,u,f,d,h,p,v,m,w,g,b,C,k,F;return r(this,(function(r){switch(r.label){case 0:return t=e.split("."),i=n(t,3),c=i[0],u=i[1],f=i[2],d=JSON.parse(s.decode(c)),h=JSON.parse(s.decodeUnicode(u)),p=l(s.decode(f)),v=l(c+"."+u),[4,Be()];case 1:if(m=r.sent(),!(w=m.keys.find((function(e){return e.kid===d.kid}))))return[3,6];if(delete w.alg,"ES256"!==d.alg)throw a(Y,'Invalid "alg" value in ID_TOKEN');g=void 0,r.label=2;case 2:return r.trys.push([2,4,,5]),[4,Ie(w,v,p)];case 3:return g=r.sent(),[3,5];case 4:throw b=r.sent(),a(Y,"Failed to use Crypto API to verify ID_TOKEN: "+b);case 5:if(g){if(C="https://access.line.me"!==h.iss,k=h.aud!==o,F=1e3*h.exp<Date.now(),C)throw a(Y,'Invalid "iss" value in ID_TOKEN');if(k)throw a(Y,'Invalid "aud" value in ID_TOKEN');if(F)throw a(Y,'Invalid "exp" value in ID_TOKEN');return[2,h]}throw a(Y,"Invalid signature in ID_TOKEN");case 6:throw a(Y,'Invalid "kid" value in ID_TOKEN');case 7:return[2]}}))}))}function Se(e){var t=e.split(".");if(t[1])try{var r=t[1].replace(/-/g,"+").replace(/_/g,"/");return JSON.parse(window.atob(r))}catch(n){return null}return null}function Te(e){var t=e.pathname,r=e.query,n="liff://"+t+(r?"?"+u.stringify(r):"");location.href=n}var Ae=null;function Ee(){"boolean"==typeof Ae&&de.warn("liff.init is not expected to be called more than once"),Ae=!!C()||!(!re()||u.parse(window.location.hash).feature_token||k())&&(F(!0),!0)}function De(){return Boolean(Ae)}function Le(e,n){return t(this,void 0,void 0,(function(){var t;return r(this,(function(r){switch(r.label){case 0:return(t=_())?[2,t]:e&&n?[4,ie({msit:e,mstVerifier:n})]:[3,2];case 1:return[2,r.sent().mst];case 2:return[2,null]}}))}))}function Oe(e){return ce(ue("apps")+"/"+e+"/featureToken")}function Ue(e){return t(this,void 0,void 0,(function(){var t,n,o,i;return r(this,(function(r){switch(r.label){case 0:return t=u.parse(window.location.hash),n=d({access_token:y(),context_token:B(),feature_token:k(),id_token:I(),client_id:x(),mst_challenge:S(),mst_verifier:T(),msit:A()},t),De()?m()?[4,Oe(e)]:[3,2]:[3,3];case 1:o=r.sent().featureToken,n.feature_token||(n.feature_token=o),r.label=2;case 2:(i=f(e))&&(n.client_id=i),r.label=3;case 3:return[2,n]}}))}))}function Pe(e){if(e.persisted&&me("multipleLiffTransition"))if("ios"===we())window.location.reload();else{var t=E().liffId,r=k();if(!t)throw a(X,"Invalid LIFF ID.");if(!r)throw a(Z,"Invalid featureToken for client features");Te({pathname:"app/"+t,query:{feature_token:r}})}}function Ne(e,n){return t(this,void 0,void 0,(function(){var t,o;return r(this,(function(r){switch(r.label){case 0:return[4,fe(e)];case 1:return t=r.sent().client_id,o=f(n),[2,t===o]}}))}))}function Ke(e,n){return t(this,void 0,void 0,(function(){var t,o,i,s,l,u,f,d,p,v,w,g,b;return r(this,(function(r){switch(r.label){case 0:return[4,new Promise((function(e){var t=he();if(!t||c(t,"9.5.0")<0)e();else if(window._liff&&window._liff.features)e();else{de.debug("cannot find window._liff.features, listen to ready event");var r=function(){de.debug("ready event is fired"),ve("ready",r),e()};pe("ready",r)}}))];case 1:return r.sent(),Ee(),[4,Ue(n.liffId)];case 2:return t=r.sent(),o=t.access_token,i=t.context_token,s=t.feature_token,l=t.id_token,u=t.client_id,f=t.mst_verifier,d=t.mst_challenge,p=t.msit,i&&N(Se(i)),!oe()&&s&&(!function(e,t){me("multipleLiffTransition")&&Te({pathname:"app/"+e,query:{feature_token:t}})}(n.liffId,s),De()&&U(s)),d&&K(d),f&&W(f),u&&M(u),p&&j(p),window.addEventListener("pageshow",Pe),m()?[3,7]:s&&o?[3,5]:De()?(v=h(location.href,{"liff.hback":"2"}),e.login({redirectUri:v}),[4,new Promise((function(){}))]):[3,4];case 3:r.sent(),r.label=4;case 4:throw e.login(),a(X,"Failed to parse feature_token or access_token");case 5:return[4,Ne(o,n.liffId)];case 6:if(!r.sent())throw e.login(),a(X,"Failed to verify access_token");U(s),P(o),r.label=7;case 7:return[4,Le(p,f)];case 8:return(w=r.sent())?(O(w),[4,ae({mst:w})]):[3,10];case 9:(g=r.sent().data)&&L(JSON.stringify(g)),r.label=10;case 10:return l&&!I()&&H(l),l&&u&&!J()?[4,xe(l,u)]:[3,12];case 11:(b=r.sent())&&D(b),r.label=12;case 12:return[2]}}))}))}function We(e){return t(this,void 0,void 0,(function(){var t,n,o,i,s,l,c;return r(this,(function(r){switch(r.label){case 0:return t=ue("apps"),n=t+"/"+e+"/contextToken",o=y(),i={"Content-Type":"application/json",Accept:"application/json"},o&&(i.Authorization="Bearer "+o),[4,ce(n,{headers:i})];case 1:if(s=r.sent(),!(l=s.contextToken))throw a(X,"Can not get context from server.");if(!(c=Se(l)))throw a(X,"Invalid context token.");return[2,c]}}))}))}function Me(){return t(this,void 0,void 0,(function(){var e,t;return r(this,(function(r){switch(r.label){case 0:if(!(e=E().liffId))throw a(X,"Invalid LIFF ID.");return[4,We(e)];case 1:return t=r.sent(),N(t),[2]}}))}))}function je(e){return t(this,void 0,void 0,(function(){var n,o,i,a=this;return r(this,(function(s){switch(s.label){case 0:n=function(){return t(a,void 0,void 0,(function(){var t,n,o,i,a,s;return r(this,(function(r){switch(r.label){case 0:return[4,(l=E(),c=u.parse(window.location.search),f=g(),d={grant_type:"authorization_code",client_id:c.liffClientId,appId:l.liffId,code:c.code,code_verifier:f.codeVerifier,redirect_uri:l.redirectUri||c.liffRedirectUri,id_token_key_type:"JWK"},h=u.stringify(d),ce(ue("token"),{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8"},body:h}))];case 1:return t=r.sent(),n=t.access_token,o=t.id_token,i=t.expires_in,M(e),P(n),q(new Date(Date.now()+1e3*i)),V(),o?(H(o),[4,xe(o,e)]):[3,3];case 2:(a=r.sent())&&D(a),r.label=3;case 3:return(s=u.parse(location.hash).context_token)?(N(Se(s)),[3,6]):[3,4];case 4:return[4,Me()];case 5:r.sent(),r.label=6;case 6:return[2]}var l,c,f,d,h}))}))},s.label=1;case 1:return s.trys.push([1,3,,4]),[4,n()];case 2:return s.sent(),[3,4];case 3:throw o=s.sent(),i=o,V(),i;case 4:return[2]}}))}))}var He=new(function(){function e(){var e=this;this.getAndValidateContext=function(){var e=w();if(!e)throw a(X,"Could not get Context from server.");if(!e.endpointUrl)throw a(X,"Could not get endpointUrl from server.");if(!e.permanentLinkPattern)throw a(X,"Could not get permanentLinkPattern from server.");return e},this.decodeState=function(t){var r=e.getAndValidateContext();t=t.replace(/\n/g,"%0D%0A");var n=!r.endpointUrl.startsWith("/?")&&r.endpointUrl.includes("/?")||!r.endpointUrl.startsWith("/#")&&r.endpointUrl.includes("/#")||r.endpointUrl.endsWith("/")||!t.startsWith("/?")&&t.includes("/?")||!t.startsWith("/#")&&t.includes("/#")||t.endsWith("/"),o=new URL(r.endpointUrl),i=o.origin,a=o.pathname,s=o.search,l=new URL(""+i+e.attachSlashAtStart(t)),c=l.pathname,u=l.search,f=l.hash,d=""+s+(s?u.replace(/\?/g,"&"):u),h=(""+a+e.attachSlashAtStart(c)).replace("//","/");return(h=e.attachSlashAtStart(""+h)).endsWith("/")&&!n&&(h=h.substring(0,h.length-1)),(""+i+h+d+f).replace(/%0D%0A/g,"\n")}}return e.prototype.attachSlashAtStart=function(e){return(e&&e.length>0&&!e.startsWith("/")?"/":"")+e},e.prototype.invoke=function(){return t(this,void 0,void 0,(function(){var e,t,n,o,i;return r(this,(function(r){switch(r.label){case 0:if(e=u.parse(window.location.search),"string"!=typeof(t=e["liff.state"]))return[2];r.label=1;case 1:return r.trys.push([1,4,,5]),n=location.href,(o=this.decodeState(t))===n?[3,3]:(e["liff.hback"]?location.replace(h(o,{"liff.hback":e["liff.hback"]})):location.replace(o),[4,new Promise((function(){}))]);case 2:r.sent(),r.label=3;case 3:return[3,5];case 4:if((i=r.sent()).code===X)throw i;return de.debug(i),[3,5];case 5:return[2]}}))}))},e}());function Je(e,n,o){return t(this,void 0,void 0,(function(){var t;return r(this,(function(r){switch(r.label){case 0:if(!o.liffId)throw a(ee,"liffId is necessary for liff.init()");return R(o),!re()&&m()&&(b()||ne()),t=u.parse(window.location.search),!oe()||re()?[3,2]:[4,new Promise((function(e){se()?e():window.addEventListener("message",(function t(r){var n=r.data,o=r.source,i=r.origin;if(n){var a=n.type,s=n.message;a===$&&(window.removeEventListener("message",t),s&&L(s),le(i),o&&o.postMessage&&o.postMessage({status:$},i),e())}}))}))];case 1:r.sent(),r.label=2;case 2:if(t.error&&t.liffOAuth2Error)throw l=t.error,c=t.error_description,f=c.replace(/\+/g," "),a(X,l+": "+f);return i=t.code,s=g(),Boolean(i&&!m()&&s&&s.codeVerifier)?[4,je(t.liffClientId)]:[3,4];case 3:r.sent(),r.label=4;case 4:return re()?[4,Ke(e,o)]:[3,6];case 5:return r.sent(),[3,8];case 6:return m()?[3,8]:[4,Me()];case 7:r.sent(),r.label=8;case 8:return[4,He.invoke()];case 9:return r.sent(),[4,n.runHook("beforeInitFinished")];case 10:return r.sent(),p(window.location.href),[2]}var i,s,l,c,f}))}))}var Ve=function(){function e(e){this.moduleDriver=e}return Object.defineProperty(e.prototype,"name",{get:function(){return"init"},enumerable:!1,configurable:!0}),e.prototype.install=function(e){var t=e.liff;return this.liff=t,this.init.bind(this)},e.prototype.init=function(e,n,o){return t(this,void 0,void 0,(function(){var t;return r(this,(function(r){switch(r.label){case 0:i=this.liff,window&&!window.liff&&(window.liff=i),r.label=1;case 1:return r.trys.push([1,9,,11]),[4,Promise.all([ye(this.liff),Je(this.liff,this.moduleDriver,e)])];case 2:return r.sent(),Ce(),[4,this.moduleDriver.runHook("beforeInitSuccess")];case 3:if(r.sent(),!e.withLoginOnExternalBrowser||m())return[3,7];if(!Q())return[3,4];throw a(X,"Auto login failure");case 4:return G(),this.liff.login(),[4,new Promise((function(){}))];case 5:r.sent(),r.label=6;case 6:return[3,8];case 7:e.withLoginOnExternalBrowser&&z(),r.label=8;case 8:return"function"==typeof n&&n(),v(),[3,11];case 9:return t=r.sent(),[4,this.moduleDriver.runHook("initError",t)];case 10:throw r.sent(),"function"==typeof o&&o(t),t;case 11:return[2]}var i}))}))},e}();export{Ve as InitModule}; |
{ | ||
"name": "@liff/init", | ||
"version": "2.17.0", | ||
"version": "2.18.0", | ||
"description": "@liff/init", | ||
@@ -34,23 +34,23 @@ "license": "SEE LICENSE IN README.md", | ||
"dependencies": { | ||
"@liff/consts": "2.17.0", | ||
"@liff/extensions": "2.17.0", | ||
"@liff/get-line-version": "2.17.0", | ||
"@liff/get-os": "2.17.0", | ||
"@liff/is-api-available": "2.17.0", | ||
"@liff/is-in-client": "2.17.0", | ||
"@liff/is-logged-in": "2.17.0", | ||
"@liff/is-sub-window": "2.17.0", | ||
"@liff/logger": "2.17.0", | ||
"@liff/login": "2.17.0", | ||
"@liff/logout": "2.17.0", | ||
"@liff/native-bridge": "2.17.0", | ||
"@liff/ready": "2.17.0", | ||
"@liff/server-api": "2.17.0", | ||
"@liff/store": "2.17.0", | ||
"@liff/sub-window": "2.17.0", | ||
"@liff/types": "2.17.0", | ||
"@liff/use": "2.17.0", | ||
"@liff/util": "2.17.0" | ||
"@liff/consts": "2.18.0", | ||
"@liff/extensions": "2.18.0", | ||
"@liff/get-line-version": "2.18.0", | ||
"@liff/get-os": "2.18.0", | ||
"@liff/is-api-available": "2.18.0", | ||
"@liff/is-in-client": "2.18.0", | ||
"@liff/is-logged-in": "2.18.0", | ||
"@liff/is-sub-window": "2.18.0", | ||
"@liff/logger": "2.18.0", | ||
"@liff/login": "2.18.0", | ||
"@liff/logout": "2.18.0", | ||
"@liff/native-bridge": "2.18.0", | ||
"@liff/ready": "2.18.0", | ||
"@liff/server-api": "2.18.0", | ||
"@liff/store": "2.18.0", | ||
"@liff/sub-window": "2.18.0", | ||
"@liff/types": "2.18.0", | ||
"@liff/use": "2.18.0", | ||
"@liff/util": "2.18.0" | ||
}, | ||
"gitHead": "fa845ce90b5b2a7b64f3aca5c9584cb3907e41de" | ||
"gitHead": "a9aaa2e9b0a5feab47ffa25e48514f9ce83ea42b" | ||
} |
39681
309
+ Added@liff/add-to-home-screen@2.18.0(transitive)
+ Added@liff/check-availability@2.18.0(transitive)
+ Added@liff/close-window@2.18.0(transitive)
+ Added@liff/consts@2.18.0(transitive)
+ Added@liff/extensions@2.18.0(transitive)
+ Added@liff/get-advertising-id@2.18.0(transitive)
+ Added@liff/get-line-version@2.18.0(transitive)
+ Added@liff/get-os@2.18.0(transitive)
+ Added@liff/get-version@2.18.0(transitive)
+ Added@liff/is-api-available@2.18.0(transitive)
+ Added@liff/is-in-client@2.18.0(transitive)
+ Added@liff/is-logged-in@2.18.0(transitive)
+ Added@liff/is-sub-window@2.18.0(transitive)
+ Added@liff/logger@2.18.0(transitive)
+ Added@liff/login@2.18.0(transitive)
+ Added@liff/logout@2.18.0(transitive)
+ Added@liff/native-bridge@2.18.0(transitive)
+ Added@liff/open-window@2.18.0(transitive)
+ Added@liff/ready@2.18.0(transitive)
+ Added@liff/scan-code@2.18.0(transitive)
+ Added@liff/server-api@2.18.0(transitive)
+ Added@liff/store@2.18.0(transitive)
+ Added@liff/sub-window@2.18.0(transitive)
+ Added@liff/types@2.18.0(transitive)
+ Added@liff/use@2.18.0(transitive)
+ Added@liff/util@2.18.0(transitive)
- Removed@liff/add-to-home-screen@2.17.0(transitive)
- Removed@liff/check-availability@2.17.0(transitive)
- Removed@liff/close-window@2.17.0(transitive)
- Removed@liff/consts@2.17.0(transitive)
- Removed@liff/extensions@2.17.0(transitive)
- Removed@liff/get-advertising-id@2.17.0(transitive)
- Removed@liff/get-line-version@2.17.0(transitive)
- Removed@liff/get-os@2.17.0(transitive)
- Removed@liff/get-version@2.17.0(transitive)
- Removed@liff/is-api-available@2.17.0(transitive)
- Removed@liff/is-in-client@2.17.0(transitive)
- Removed@liff/is-logged-in@2.17.0(transitive)
- Removed@liff/is-sub-window@2.17.0(transitive)
- Removed@liff/logger@2.17.0(transitive)
- Removed@liff/login@2.17.0(transitive)
- Removed@liff/logout@2.17.0(transitive)
- Removed@liff/native-bridge@2.17.0(transitive)
- Removed@liff/open-window@2.17.0(transitive)
- Removed@liff/ready@2.17.0(transitive)
- Removed@liff/scan-code@2.17.0(transitive)
- Removed@liff/server-api@2.17.0(transitive)
- Removed@liff/store@2.17.0(transitive)
- Removed@liff/sub-window@2.17.0(transitive)
- Removed@liff/types@2.17.0(transitive)
- Removed@liff/use@2.17.0(transitive)
- Removed@liff/util@2.17.0(transitive)
Updated@liff/consts@2.18.0
Updated@liff/extensions@2.18.0
Updated@liff/get-os@2.18.0
Updated@liff/is-in-client@2.18.0
Updated@liff/is-logged-in@2.18.0
Updated@liff/is-sub-window@2.18.0
Updated@liff/logger@2.18.0
Updated@liff/login@2.18.0
Updated@liff/logout@2.18.0
Updated@liff/native-bridge@2.18.0
Updated@liff/ready@2.18.0
Updated@liff/server-api@2.18.0
Updated@liff/store@2.18.0
Updated@liff/sub-window@2.18.0
Updated@liff/types@2.18.0
Updated@liff/use@2.18.0
Updated@liff/util@2.18.0