New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@vkontakte/superappkit

Package Overview
Dependencies
Maintainers
4
Versions
408
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vkontakte/superappkit - npm Package Compare versions

Comparing version 1.11.0-beta-1 to 1.11.0

dist/common/types.d.ts

4

dist/common/bridge.d.ts
interface BridgeMessageData<H> {
handler: H;
params: Record<string, any>;
params: {
[index: string]: any;
};
}

@@ -5,0 +7,0 @@ export interface BridgeMessage<H> extends BridgeMessageData<H> {

@@ -6,3 +6,3 @@ export declare const VERSION = "0.0.2";

export declare const ALLOWED_DOMAIN = ".vk.com";
export declare const VKPAY_APP_ID = 6217559;
export declare const SMALL_TABLET_SIZE = 768;
export declare const ALLOWED_APP_SETTINGS_KEYS: string[];

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

import { FrameSettings } from '#/common/types';
export declare type URLParams = {

@@ -12,5 +13,5 @@ [key: string]: string | number;

export declare function makeParams(params: URLParams): string;
export declare function parseParams(query: string): Record<string, any>;
export declare function hasAllowedAppSettingsParams(appSettings: AppSettings): boolean;
export declare function filterAllowedAppSettings(appSettings: AppSettings): AppSettings;
export declare function makeAppSettingsString(appSettings: AppSettings): string;
export declare function makeFrame(src?: string, frameSettings?: FrameSettings): HTMLIFrameElement;

@@ -1,50 +0,12 @@

import { URLParams } from '#/common/utils';
export declare type VKSilentAuthPayload = {
auth: number;
token: string;
ttl: number;
type: string;
user: {
id: number;
first_name: string;
last_name: string;
avatar: string;
phone: string;
};
uuid: string;
};
export declare type VKAuthSuccessResult = {
provider: 'vk';
payload: VKSilentAuthPayload;
};
export interface VKOAuthCallback {
provider: 'fb' | 'google';
}
export declare type VKUserVisibleAuthResult = VKAuthSuccessResult | VKOAuthCallback;
export interface ExtendTokenParams {
name: 'extend_token';
token: string;
params: {
extend_token_hash: string;
};
}
export declare type AuthAction = ExtendTokenParams;
export declare type RedirectAuthParams = {
url: string;
state?: string;
screen?: 'phone';
action?: AuthAction;
};
export declare type UserVisibleAuthParams = {
screen?: 'phone';
action?: AuthAction;
};
import { AuthButtonParams, AuthButtonType, RedirectAuthParams, UserVisibleAuthParams, VKAuthSuccessResult, VKOneTapAuthResult, VKUserVisibleAuthResult } from './types';
declare class Connect {
private readonly flags;
readonly silentAuth: () => Promise<VKAuthSuccessResult>;
readonly oneTapAuth: (oneTapAuthType: AuthButtonType, params: AuthButtonParams) => VKOneTapAuthResult | null;
private readonly userDataPolicy;
private readonly captcha;
readonly userVisibleAuth: (params?: UserVisibleAuthParams | undefined) => Promise<VKUserVisibleAuthResult>;
readonly redirectAuth: (params: RedirectAuthParams) => void;
readonly makeAuthUrl: (params: URLParams) => string;
}
declare const _default: Connect;
export default _default;

@@ -1,2 +0,8 @@

import { AuthAction } from '#/connect';
import { AuthAction, AdaptivitySwitchObserver, VKOneTapAuthOptions, ButtonOneTapAuthOptions } from '#/connect/types';
import { URLParams } from '#/common/utils';
export declare function makeAuthActionString(authAction?: AuthAction): string;
export declare function makeAdaptivitySwitchObserver(): AdaptivitySwitchObserver;
export declare const CONNECT_AUTH_RESPONSE_TYPE = "silent_token";
export declare function makeAuthUrl(params: URLParams, authPage?: string): string;
export declare function getFloatingOneTapAuthOptions(isAdaptive: boolean): VKOneTapAuthOptions;
export declare function getButtonOneTapAuthOptions(options: ButtonOneTapAuthOptions): VKOneTapAuthOptions;

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

"use strict";function e(n){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(n)}function n(n){return n&&"object"===e(n)&&"default"in n?n.default:n}Object.defineProperty(exports,"__esModule",{value:!0});var t=n(require("@babel/runtime/helpers/typeof"));require("@babel/runtime/helpers/toConsumableArray");var o=n(require("@babel/runtime/helpers/defineProperty"));function r(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}function i(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function a(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);n&&(o=o.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,o)}return t}function s(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{};n%2?a(Object(t),!0).forEach((function(n){i(e,n,t[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):a(Object(t)).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}))}return e}require("@babel/runtime/helpers/classCallCheck"),require("@babel/runtime/helpers/createClass");var c,p="ModuleSymbhasOwnPr-0123456789ABCDEFGHNRVfgctiUvz_KqYTJkLxpZXIjQW",u=function(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:21,n="",t=e;t--;)n+=p[64*Math.random()|0];return n},d=["agreements","promo","vkc_behavior","vkc_auth_action","vkc_brand"];!function(e){e[e.UNKNOWN=1]="UNKNOWN",e[e.MISSING_PARAM=2]="MISSING_PARAM",e[e.CONNECTION_LOST=3]="CONNECTION_LOST",e[e.USER_DENIED=4]="USER_DENIED",e[e.INVALID_PARAMS=5]="INVALID_PARAMS",e[e.CUSTOM=6]="CUSTOM",e[e.CONNECT_WINDOW_CLOSED=7]="CONNECT_WINDOW_CLOSED",e[e.CONNECT_WINDOW_NOT_OPENED=8]="CONNECT_WINDOW_NOT_OPENED",e[e.CONNECT_DOMAIN_NOT_ALLOWED=9]="CONNECT_DOMAIN_NOT_ALLOWED",e[e.CONNECT_UNKNOWN_SDK_MESSAGE=10]="CONNECT_UNKNOWN_SDK_MESSAGE",e[e.OLD_MISSING_PARAM=100]="OLD_MISSING_PARAM"}(c||(c={}));var l=function(){return"No params passed for load app!"},f=function(){return"Connect window was closed."},h=function(){return"Connect window was not opened."},m=function(e){return'URL domain "'.concat(e,'" is not allowed.')},v=function(e){return"This SDK message is unknown: ".concat(e)},g=!("undefined"==typeof window||!window.document||!window.document.createElement),O=g&&!!window.addEventListener,A=function(){};if(O)try{var y=Object.defineProperty({},"passive",{get:function(){!0}});window.addEventListener("test",A,y),window.removeEventListener("test",A,y)}catch(e){}!function(){if(!g)return!1;var e=!1;try{document.createElement("div").scrollTo({top:0,get behavior(){return e=!0,"smooth"}})}catch(e){}}();function E(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);n&&(o=o.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,o)}return t}function _(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{};n%2?E(Object(t),!0).forEach((function(n){o(e,n,t[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):E(Object(t)).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}))}return e}var b={parse:function(e){if("string"!=typeof e)return{};if(!(e=e.trim().replace(/^[?#&]/,"")))return{};var n=/\?(.+)$/gi.exec(e);return(n?n[1]:e).split("&").reduce((function(e,n){var t=n.split("=");return t[1]&&(e[t[0]]=decodeURIComponent(t[1])),e}),{})},stringify:function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if("object"!==t(e)||null===e)return"";n=_({encode:!0},n);var o=function(e){return n.encode?encodeURIComponent(e):String(e)};return Object.keys(e).reduce((function(t,r){var i=e[r];return void 0===i?t:null===i?(n.skipNull||t.push([o(r),""].join("=")),t):Array.isArray(i)?(i.map((function(e){t.push("".concat(o(r),"[]=").concat(o(e)))})).join(),t):(t.push([o(r),o(i)].join("=")),t)}),[]).join("&")}};function P(e){return b.stringify(e)}function w(e){return Object.keys(e).filter((function(e){return d.includes(e)}))}function N(e){var n=function(e){return w(e).reduce((function(n,t){return n[t]=e[t],n}),{})}(e);return btoa(JSON.stringify(n))}var S=["extend_token"];function k(e){return e&&S.includes(e.name)?btoa(JSON.stringify(e)):""}function D(e){return e=e||Object.create(null),{on:function(n,t){(e[n]||(e[n]=[])).push(t)},off:function(n,t){e[n]&&e[n].splice(e[n].indexOf(t)>>>0,1)},emit:function(n,t){(e[n]||[]).slice().map((function(e){e(t)})),(e["*"]||[]).slice().map((function(e){e(n,t)}))}}}var T,M,C,I={appId:0,superAppToken:"",loginDomain:"login.vk.com",oauthDomain:"oauth.vk.com",connectDomain:"connect.vk.com",_debug:!1},R={},j={events:D(),init:function(e){if(!e.appId)throw new Error("appId required");I.appId=e.appId,I.superAppToken=e.superAppToken||"",I.loginDomain=e.loginDomain||"login.vk.com",I.oauthDomain=e.oauthDomain||"oauth.vk.com",I.connectDomain=e.connectDomain||"connect.vk.com",I.appSettings=e.appSettings,I._debug=!!e._debug},get:function(){return I},setSuperAppToken:function(e){I.superAppToken=e,j.events.emit("superAppToken",e)},onRequestSuperAppToken:function(e){R.superAppToken=e},_requestSuperAppToken:function(){var e;R.superAppToken&&(e=R.superAppToken()),e&&e.then((function(e){return j.setSuperAppToken(e)})).catch(console.error)},onAuth:function(e){R.auth=e},_requestAuth:function(){var e;R.auth&&(e=R.auth()),e&&e.then((function(e){return j.setSuperAppToken(e)})).catch(console.error)},onOpenApp:function(e){R.openApp=e},_openApp:function(e){R.openApp&&R.openApp(e.app)}},L=new function e(){var n=this;r(this,e),i(this,"flags",null),i(this,"silentAuth",(function(){var e=j.get(),n=e.loginDomain,t=e.appId,o=u(),r="https://".concat(n,"/?act=connect&app_id=").concat(t,"&response_type=").concat("silent_token","&uuid=").concat(o,"&v=").concat("0.0.2"),i=new XMLHttpRequest;return i.open("GET",r,!0),i.responseType="json",i.withCredentials=!0,new Promise((function(e,n){i.onload=function(){i.response?e({provider:"vk",payload:i.response}):n()},i.onerror=function(){n()},i.send()}))})),i(this,"userVisibleAuth",(function(e){var t=u(),o={origin:location.protocol+"//"+location.host,uuid:t};(null==e?void 0:e.screen)&&(o.screen=e.screen);var r=k(null==e?void 0:e.action);r&&(o.action=r);var i=n.makeAuthUrl(o);n.flags&&(i="".concat(i,"#").concat(P(n.flags)));var a=screen.height/2-280,s=screen.width/2-410,p=window.open(i,"_blank","top=".concat(a,",left=").concat(s,",width=").concat(820,",height=").concat(560,",location"));if(!p){var d={code:c.CONNECT_WINDOW_NOT_OPENED,reason:h()};return Promise.reject(d)}return new Promise((function(e,n){var o=setInterval((function(){if(!p||p.closed){window.removeEventListener("message",r),clearInterval(o);var e={code:c.CONNECT_WINDOW_CLOSED,reason:f()};n(e)}}),1e3);function r(i){if(i.source===p&&p)if(window.removeEventListener("message",r),clearInterval(o),".vk.com"===i.origin.slice(i.origin.length-".vk.com".length))if(i.data.action==="vk_connect_response"+t){var a=i.data.payload;p.close(),e({provider:"vk",payload:a})}else if(i.data.action==="oauth_callback"+t)e({provider:i.data.payload.name}),p.close();else{p.close();var s={code:c.CONNECT_UNKNOWN_SDK_MESSAGE,reason:v(JSON.stringify(i.data))};n(s)}else{p.close();var u={code:c.CONNECT_DOMAIN_NOT_ALLOWED,reason:m(i.origin)};n(u)}}window.addEventListener("message",r)}))})),i(this,"redirectAuth",(function(e){var t=u(),o={redirect_uri:e.url,uuid:t};(null==e?void 0:e.state)&&(o.redirect_state=e.state),(null==e?void 0:e.screen)&&(o.screen=e.screen);var r=k(null==e?void 0:e.action);r&&(o.action=r);var i=n.makeAuthUrl(o);location.assign(i)})),i(this,"makeAuthUrl",(function(e){var n=j.get(),t=n.appId,o=n.connectDomain,r=n.appSettings,i=s({app_id:t,response_type:"silent_token",v:"0.0.2"},e);r&&function(e){var n;return Boolean(null===(n=w(e))||void 0===n?void 0:n.length)}(r)&&(i.app_settings=N(r));var a=P(i);return"https://".concat(o,"/auth?").concat(a)}))};!function(e){e.APP_CLOSE="VKWebAppClose",e.APP_READY="VKSDKMiniAppReady",e.RESIZE="VKSDKMiniAppResize",e.APP_INIT_CONFIG="VKSDKMiniAppInitConfig",e.OPEN_APP="VKWebAppOpenApp",e.OPEN_PAY_FORM="VKWebAppOpenPayForm",e.ACTION_DONE="VKWebAppActionDone"}(T||(T={})),(M=exports.MiniAppEvents||(exports.MiniAppEvents={})).OPEN="open",M.HIDE="hide",M.CLOSE="close",M.SHOW="show",M.MESSAGE="message",M.CREATE_APP="createapp",function(e){e.SUPERAPP_TOKEN="VKSDKGeneralSuperAppToken",e.AUTH_NEEDED="VKSDKGeneralAuthNeeded",e.OPEN_APP="VKSDKGeneralOpenApp"}(C||(C={}));var K,U=function e(n){var t=this;r(this,e),i(this,"handler",(function(){return{}})),i(this,"config",void 0),i(this,"destroy",(function(){delete t.config,window.removeEventListener("message",t.handleMessage)})),i(this,"onMessage",(function(e){t.handler=e})),i(this,"sendMessage",(function(e){t.config.iframe.contentWindow.postMessage(s({type:"vk-sak-sdk"},e),t.config.origin)})),i(this,"handleMessage",(function(e){t.config.origin&&e.origin===t.config.origin&&e.source===t.config.iframe.contentWindow&&e.data&&"vk-sak-sdk"===e.data.type&&t.handler(e.data)})),this.config=n,window.addEventListener("message",this.handleMessage)};!function(e){e.INIT="ConnectProfileInit"}(K||(K={}));exports.Config=j,exports.Connect=L,exports.MiniApp=function e(n){var t=this;r(this,e),i(this,"events",void 0),i(this,"iframe",void 0),i(this,"bridge",void 0),i(this,"loading",void 0),i(this,"readyPromiseResolve",null),i(this,"readyPromise",null),i(this,"bodyOverflowValue",""),i(this,"params",void 0),i(this,"child",null),i(this,"open",(function(e,n){return t.loading?(t.iframe.src=t.getMiniAppUrl(e,n),t.loading=new Promise((function(e){t.iframe.onload=function(){t.iframe.onload=null,e()}})),t.readyPromise=new Promise((function(e){return t.readyPromiseResolve=e}))):t.preload(e,n).catch(console.error),t.iframe.style.display="block",t.bodyOverflowValue=window.document.body.style.overflow,window.document.body.style.overflow="hidden",t.loading.then(t.handleResize).catch(console.error),t.events.emit(exports.MiniAppEvents.OPEN),t.readyPromise})),i(this,"hide",(function(){t.iframe.style.display="none",window.document.body.style.overflow=t.bodyOverflowValue,t.events.emit(exports.MiniAppEvents.HIDE)})),i(this,"close",(function(){window.document.body.style.overflowX="",j.events.off("superAppToken",t.onSuperAppToken),t.iframe&&t.iframe.remove(),t.bridge&&t.bridge.destroy(),delete t.iframe,delete t.bridge,window.removeEventListener("resize",t.handleResize),t.events.emit(exports.MiniAppEvents.CLOSE)})),i(this,"show",(function(){if(!t.loading)throw new Error('App is not loaded, use "open" or "preload" methods');t.iframe.style.display="block",window.document.body.style.overflow=t.bodyOverflowValue,t.events.emit(exports.MiniAppEvents.SHOW)})),i(this,"preload",(function(e,n){var o=document.createElement("iframe"),r=window.innerHeight,i=isFinite(t.params.zIndex)?t.params.zIndex:999999;return o.src=t.getMiniAppUrl(e,n),o.style.cssText="\n display: none;\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: ".concat(r,"px;\n min-height: ").concat(r,"px;\n border: none;\n z-index: ").concat(i,";\n "),t.iframe=o,document.body.appendChild(t.iframe),j.events.on("superAppToken",t.onSuperAppToken),t.bridge=new U({iframe:t.iframe,origin:"https://"+j.get().connectDomain}),t.bridge.onMessage(t.handleMessage),window.addEventListener("resize",t.handleResize),t.loading=new Promise((function(e){o.onload=function(){o.onload=null,e()}})),t.readyPromise=new Promise((function(e){return t.readyPromiseResolve=e})),t.loading})),i(this,"sendMessage",(function(e){t.bridge.sendMessage(e)})),i(this,"onSuperAppToken",(function(e){t.bridge.sendMessage({handler:C.SUPERAPP_TOKEN,params:{result:e}})})),i(this,"handleMessage",(function(e){switch(e.handler){case T.APP_CLOSE:t.hide();break;case T.APP_READY:t.resolveReadyPromise(),t.handleUpdateConfig();break;case T.OPEN_APP:t.openMiniapp(e.params);break;case T.OPEN_PAY_FORM:t.openPayForm(e.params);break;case C.SUPERAPP_TOKEN:j._requestSuperAppToken();break;case C.AUTH_NEEDED:j._requestAuth();break;default:t.events.emit(exports.MiniAppEvents.MESSAGE,e)}})),i(this,"handleResize",(function(){if(t.iframe){var e=innerWidth,n=innerHeight;t.iframe.style.height="".concat(n,"px"),t.iframe.style.minHeight="".concat(n,"px"),t.bridge.sendMessage({handler:T.RESIZE,params:{viewport_width:e,viewport_height:n}})}})),i(this,"handleUpdateConfig",(function(){t.bridge.sendMessage({handler:T.APP_INIT_CONFIG,params:{fullMode:t.params.fullMode}})})),i(this,"getMiniAppUrl",(function(e,n){var o=j.get(),r=o.connectDomain,i=o.appId,a=o.superAppToken,s=o._debug,c=P({app:t.params.app,host_app_id:i,debug:s?"1":"",localhost:s?"1":"",superapp_token:a,app_query:e?JSON.stringify(e):"",app_hash:n||""});return"https://".concat(r,"/mini_app?").concat(c)})),i(this,"resolveReadyPromise",(function(){t.readyPromise&&t.readyPromiseResolve&&(t.readyPromiseResolve(),t.readyPromise=null,t.readyPromiseResolve=null)})),i(this,"openMiniapp",(function(n){t.child=new e({app:n.app_id}),t.events.emit(exports.MiniAppEvents.CREATE_APP,{app:t.child,location:n.location})})),i(this,"openPayForm",(function(n){var o=s({},n.params);o.data&&(o.data=JSON.stringify(o.data));var r=s({},o,{app_id:n.app_id,action:n.action}),i=new e({app:6217559});i.open(r).then((function(){return t.hide()})).catch(console.error),i.events.on(exports.MiniAppEvents.MESSAGE,(function(e){t.handleVKPayFormMessage(e),i.close(),t.show()})),i.events.on(exports.MiniAppEvents.HIDE,(function(){i.close(),t.close()}))})),i(this,"handleVKPayFormMessage",(function(e){e.handler===T.ACTION_DONE&&t.sendMessage(e)})),this.params=s({},n,{app:"number"==typeof n.app?"app".concat(n.app):n.app}),this.events=D()},exports.Profile=function e(){var n=this;r(this,e),i(this,"iframe",void 0),i(this,"config",void 0),i(this,"bridge",void 0),i(this,"iframeLoadPromise",void 0),i(this,"load",(function(e){if(!e.container)throw new Error("container is null");if(!e)throw new Error(l());return n.iframe||n.preload(e),n.iframeLoadPromise})),i(this,"remove",(function(){n.iframe&&n.iframe.parentNode&&n.iframe.parentNode.removeChild(n.iframe),n.destroy()})),i(this,"preload",(function(e){n.config=e;var t=document.createElement("iframe");t.style.border="none",t.style.width="100%",t.style.height="100%",t.style.minHeight="100%",e.container.appendChild(t),n.setup(t)})),i(this,"setup",(function(e){j.events.on("superAppToken",n.onSuperAppToken),e.src=n.getProfileUrl(),n.iframe=e,n.iframeLoadPromise=new Promise((function(n){e.onload=function(){return n(e)}})),n.bridge=new U({iframe:n.iframe,origin:"https://"+j.get().connectDomain}),n.bridge.onMessage(n.handleMessage)})),i(this,"destroy",(function(){j.events.off("superAppToken",n.onSuperAppToken),n.bridge.destroy(),delete n.iframe,delete n.iframeLoadPromise,delete n.bridge})),i(this,"onSuperAppToken",(function(e){if(e&&n.iframe){var t=n.iframe;n.destroy(),n.setup(t)}})),i(this,"handleMessage",(function(e){switch(e.handler){case K.INIT:n.handleInitApp().catch(console.error);break;case C.SUPERAPP_TOKEN:j._requestSuperAppToken();break;case C.AUTH_NEEDED:j._requestAuth();break;case C.OPEN_APP:j._openApp(e.params)}})),i(this,"handleInitApp",(function(){return Promise.resolve()})),i(this,"getProfileUrl",(function(){var e=j.get(),t=e.connectDomain,o=e.appId,r=e.superAppToken,i=e._debug,a=n.config.widgets,s=P({host_app_id:o,debug:i?"1":"",localhost:i?"1":"",superapp_token:r,widgets:a?a.join(","):""});return"https://".concat(t,"/super_profile?").concat(s)}))};
"use strict";function e(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}function n(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function t(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);n&&(o=o.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,o)}return t}function o(e){for(var o=1;o<arguments.length;o++){var i=null!=arguments[o]?arguments[o]:{};o%2?t(Object(i),!0).forEach((function(t){n(e,t,i[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):t(Object(i)).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(i,n))}))}return e}Object.defineProperty(exports,"__esModule",{value:!0});var i,a="ModuleSymbhasOwnPr-0123456789ABCDEFGHNRVfgctiUvz_KqYTJkLxpZXIjQW",r=function(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:21,n="",t=e;t--;)n+=a[64*Math.random()|0];return n},s=["agreements","promo","vkc_behavior","vkc_auth_action","vkc_brand"];!function(e){e[e.UNKNOWN=1]="UNKNOWN",e[e.MISSING_PARAM=2]="MISSING_PARAM",e[e.CONNECTION_LOST=3]="CONNECTION_LOST",e[e.USER_DENIED=4]="USER_DENIED",e[e.INVALID_PARAMS=5]="INVALID_PARAMS",e[e.CUSTOM=6]="CUSTOM",e[e.CONNECT_WINDOW_CLOSED=7]="CONNECT_WINDOW_CLOSED",e[e.CONNECT_WINDOW_NOT_OPENED=8]="CONNECT_WINDOW_NOT_OPENED",e[e.CONNECT_DOMAIN_NOT_ALLOWED=9]="CONNECT_DOMAIN_NOT_ALLOWED",e[e.CONNECT_UNKNOWN_SDK_MESSAGE=10]="CONNECT_UNKNOWN_SDK_MESSAGE",e[e.OLD_MISSING_PARAM=100]="OLD_MISSING_PARAM"}(i||(i={}));var c=function(){return"No params passed for load app!"},p=function(){return"Connect window was closed."},d=function(){return"Connect window was not opened."},u=function(e){return'URL domain "'.concat(e,'" is not allowed.')},l=function(e){return"This SDK message is unknown: ".concat(e)};function h(e){return Object.keys(e).map((function(n){var t=e[n];return n=encodeURIComponent(n),t=encodeURIComponent(t),"".concat(n,"=").concat(t)}),[]).join("&")}function f(e){return Object.keys(e).filter((function(e){return s.includes(e)}))}function m(e){var n;return Boolean(null===(n=f(e))||void 0===n?void 0:n.length)}function g(e){var n=function(e){return f(e).reduce((function(n,t){return n[t]=e[t],n}),{})}(e);return btoa(JSON.stringify(n))}function A(e,n){var t,o=document.createElement("iframe");for(var i in e&&(o.src=e),o.style.cssText=null!==(t=null==n?void 0:n.cssText)&&void 0!==t?t:"",o.width="100%",o.height="100%",o.style.border="none",null==n?void 0:n.properties){var a;if(n&&n.properties.hasOwnProperty(i))o[i]=null!==(a=n.properties[i])&&void 0!==a?a:""}return o}function _(e){return e=e||Object.create(null),{on:function(n,t){(e[n]||(e[n]=[])).push(t)},off:function(n,t){e[n]&&e[n].splice(e[n].indexOf(t)>>>0,1)},emit:function(n,t){(e[n]||[]).slice().map((function(e){e(t)})),(e["*"]||[]).slice().map((function(e){e(n,t)}))}}}var v={appId:0,superAppToken:"",loginDomain:"login.vk.com",oauthDomain:"oauth.vk.com",connectDomain:"connect.vk.com",_debug:!1},O={},y={events:_(),init:function(e){if(!e.appId)throw new Error("appId required");v.appId=e.appId,v.superAppToken=e.superAppToken||"",v.loginDomain=e.loginDomain||"login.vk.com",v.oauthDomain=e.oauthDomain||"oauth.vk.com",v.connectDomain=e.connectDomain||"connect.vk.com",v.appSettings=e.appSettings,v._debug=!!e._debug},get:function(){return v},setSuperAppToken:function(e){v.superAppToken=e,y.events.emit("superAppToken",e)},onRequestSuperAppToken:function(e){O.superAppToken=e},_requestSuperAppToken:function(){var e;O.superAppToken&&(e=O.superAppToken()),e&&e.then((function(e){return y.setSuperAppToken(e)})).catch(console.error)},onAuth:function(e){O.auth=e},_requestAuth:function(){var e;O.auth&&(e=O.auth()),e&&e.then((function(e){return y.setSuperAppToken(e)})).catch(console.error)},onOpenApp:function(e){O.openApp=e},_openApp:function(e){O.openApp&&O.openApp(e.app)}},E=["extend_token"];function S(e){return e&&E.includes(e.name)?btoa(JSON.stringify(e)):""}function w(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"auth",t=y.get(),i=t.appId,a=t.connectDomain,r=t.appSettings,s=o({app_id:i,response_type:"silent_token",v:"0.0.2"},e);r&&m(r)&&(s.app_settings=g(r));var c=h(s);return"https://".concat(a,"/").concat(n,"?").concat(c)}var T,D,P,N,C,b=function t(i){var a=this;e(this,t),n(this,"handler",(function(){return{}})),n(this,"config",void 0),n(this,"destroy",(function(){delete a.config,window.removeEventListener("message",a.handleMessage)})),n(this,"onMessage",(function(e){a.handler=e})),n(this,"sendMessage",(function(e){a.config.iframe.contentWindow.postMessage(o({type:"vk-sak-sdk"},e),a.config.origin)})),n(this,"handleMessage",(function(e){a.config.origin&&e.origin===a.config.origin&&e.source===a.config.iframe.contentWindow&&e.data&&"vk-sak-sdk"===e.data.type&&(console.info("[received from ui]",e.data),a.handler(e.data))})),this.config=i,window.addEventListener("message",this.handleMessage)};!function(e){e.SHOW_DATA_POLICY="VKSDKOneTapAuthConnectDataPolicy",e.HIDE_DATA_POLICY="VKSDKOneTapAuthDataPolicyClose",e.DATA_POLICY_RESULT="VKSDKOneTapAuthDataPolicyResult",e.SHOW_CAPTCHA="VKSDKOneTapAuthDataPolicyShowCaptcha"}(T||(T={})),function(e){e.CAPTCHA_SUCCESS="VKSDKAuthCaptchaSuccess",e.CAPTCHA_FAIL="VKSDKAuthCaptchaFail"}(D||(D={})),function(e){e.PHONE_VALIDATION_NEEDED="VKSDKOneTapAuthPhoneValidationNeeded",e.FULL_AUTH_NEEDED="VKSDKOneTapAuthFullAuthNeeded",e.AUTH_DATA_LOADED="VKSDKOneTapAuthDataLoaded",e.NOT_AUTHORIZED="VKSDKOneTapAuthNotAuthorized",e.LOGIN_SUCCESS="VKSDKOneTapAuthLoginSuccess",e.RESIZE_FRAME="VKSDKOneTapResizeFrame",e.SHOW_CAPTCHA="VKSDKOneTapShowCaptcha",e.VALIDATE_CAPTCHA="VKSDKOneTapValidateCaptcha"}(P||(P={})),function(e){e.CLOSE_AUTH="VKSDKOneTapAuthClose"}(N||(N={})),function(e){e.SHOW_LOGIN="VKSDKButtonOneTapAuthShowLogin",e.SHOW_LOGIN_OPTIONS="VKSDKButtonOneTapAuthShowLoginOptions"}(C||(C={}));var k,I,L=new function t(){var a=this;e(this,t),n(this,"flags",null),n(this,"silentAuth",(function(){var e=y.get(),n=e.loginDomain,t=e.appId,o=r(),i="https://".concat(n,"/?act=connect&app_id=").concat(t,"&response_type=").concat("silent_token","&uuid=").concat(o,"&v=").concat("0.0.2"),a=new XMLHttpRequest;return a.open("GET",i,!0),a.responseType="json",a.withCredentials=!0,new Promise((function(e,n){a.onload=function(){a.response?e({provider:"vk",payload:a.response}):n()},a.onerror=function(){n()},a.send()}))})),n(this,"oneTapAuth",(function(e,n){if(!["floating","button"].includes(e))return null;var t,i,s=function(){var e,n=window.innerWidth,t=n<=768;return{destroy:function(){return window.removeEventListener("resize",e)},isAdaptive:function(){return t},observe:function(o){e=function(){var e=window.innerWidth;n>768&&e<=768?o(t=!0):n<=768&&e>768&&o(t=!1),n=e},window.addEventListener("resize",e)}}}(),c=null;switch(e){case"floating":t=s.isAdaptive(),i=t?"314px":"334px",c={pageUrl:"floating_one_tap_auth",pageUrlParams:{adaptive:t?1:0},frameStyles:t?"\n display: none;\n position: fixed;\n bottom: 0;\n right: 0;\n max-width: 100%;\n width: 100%;\n height: ".concat(i,";\n "):"\n display: none;\n position: fixed;\n top: 0;\n right: 0;\n max-width: 400px;\n width: 100%;\n height: ".concat(i,";\n ")};break;case"button":c=function(e){var n={},t=44;if(e){var o,i;n.show_agreements=null!==(o=e.showAgreements)&&void 0!==o?o:0,n.show_alternative_login=null!==(i=e.showAlternativeLogin)&&void 0!==i?i:0;t+=n.show_alternative_login?56:0,t+=n.show_agreements?80:0}return{pageUrl:"button_one_tap_auth",pageUrlParams:n,frameStyles:"\n height: ".concat(t,"px;\n ")}}(n.options)}if(!c)throw new Error("options were not set");var p=r(),d=o({origin:location.protocol+"//"+location.host,uuid:p},c.pageUrlParams),u=c.pageUrl,l=A(w(d,u),{cssText:c.frameStyles});switch(e){case"floating":s.observe((function(e){e?(l.style.maxWidth="100%",l.style.top="auto",l.style.bottom="0"):(l.style.maxWidth="400px",l.style.top="0",l.style.bottom="auto"),l.style.display="none",d=o({},d,{adaptive:e?1:0}),l.src=w(d,u)})),document.body.appendChild(l);break;case"button":var h=n.container;h&&h.appendChild(l)}var f=new b({iframe:l,origin:"https://"+y.get().connectDomain}),m=function(){f.sendMessage({handler:P.RESIZE_FRAME,params:{uuid:p}})};window.addEventListener("resize",m);var g=function(){l&&(l.remove(),l=null),window.removeEventListener("resize",m),s&&s.destroy(),f.destroy()},_=new Promise((function(t){f.onMessage((function(i){if(i.params.uuid===p)switch(i.handler){case P.FULL_AUTH_NEEDED:case P.PHONE_VALIDATION_NEEDED:a.userVisibleAuth().then((function(e){n.callback({type:P.LOGIN_SUCCESS,provider:"vk",payload:o({uuid:p},e.payload)})})).catch(console.error);break;case P.NOT_AUTHORIZED:"floating"===e&&(n.callback({type:i.handler,payload:{uuid:p,error:"not_authorized"}}),g()),t(i.handler);break;case P.AUTH_DATA_LOADED:"floating"===e&&(l.style.display="block"),f.sendMessage({handler:P.RESIZE_FRAME,params:{uuid:p}}),t(i.handler);break;case P.RESIZE_FRAME:l.style.height="".concat(i.params.height,"px");break;case P.LOGIN_SUCCESS:n.callback({type:i.handler,provider:"vk",payload:o({uuid:p},i.params)});break;case P.SHOW_CAPTCHA:var r=a.captcha(p,{captcha_sid:i.params.captcha_sid,captcha_img:i.params.captcha_img});r.show().then((function(e){f.sendMessage({handler:D.CAPTCHA_SUCCESS,params:o({uuid:p},e)})})).catch((function(){f.sendMessage({handler:D.CAPTCHA_FAIL,params:{uuid:p}}),r.destroy()}));break;case N.CLOSE_AUTH:n.callback({type:i.handler,payload:{uuid:p}}),g();break;case C.SHOW_LOGIN:case C.SHOW_LOGIN_OPTIONS:n.callback({type:i.handler,payload:{uuid:p}});break;case T.SHOW_DATA_POLICY:a.userDataPolicy(p).show().then((function(){n.callback({type:T.DATA_POLICY_RESULT,payload:{uuid:p,policyAccepted:!0}})})).catch((function(){n.callback({type:T.DATA_POLICY_RESULT,payload:{uuid:p,policyAccepted:!1}})}))}}))}));return{getFrame:function(){return l},destroy:g,authReadyPromise:_}})),n(this,"userDataPolicy",(function(e){var n=w({origin:location.protocol+"//"+location.host,uuid:e},"user_data_policy"),t=window.innerHeight,i="\n display: none;\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: ".concat(t,"px;\n min-height: ").concat(t,"px;\n border: none;\n z-index: 99999;\n "),r=A(n,{properties:{height:"".concat(t,"px")},cssText:i});document.body.appendChild(r);var s=new b({iframe:r,origin:"https://"+y.get().connectDomain}),c=function(){document.body.removeChild(r),s.destroy()},p=function(){r.style.display="none"};return{show:function(){return r.style.display="block",new Promise((function(n,t){s.onMessage((function(i){switch(i.handler){case T.HIDE_DATA_POLICY:c(),n();break;case T.SHOW_CAPTCHA:var d=a.captcha(e,{captcha_sid:i.params.captcha_sid,captcha_img:i.params.captcha_img});d.show().then((function(n){s.sendMessage({handler:D.CAPTCHA_SUCCESS,params:o({uuid:e},n)}),r.style.display="block"})).catch((function(){s.sendMessage({handler:D.CAPTCHA_FAIL,params:{uuid:e}}),d.destroy()})),p();break;default:t()}}))}))},hide:p,destroy:c}})),n(this,"captcha",(function(e,n){var t=w(o({origin:location.protocol+"//"+location.host,uuid:e},n),"auth_captcha"),i=window.innerHeight,a=A(t,{cssText:"\n display: none;\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: ".concat(i,"px;\n min-height: ").concat(i,"px;\n border: none;\n z-index: 99999;\n ")});document.body.appendChild(a);var r=new b({iframe:a,origin:"https://"+y.get().connectDomain}),s=function(){document.body.removeChild(a),r.destroy()};return{show:function(){return a.style.display="block",new Promise((function(e,n){r.onMessage((function(t){switch(t.handler){case D.CAPTCHA_SUCCESS:e(t.params),s();break;default:n(),s()}}))}))},destroy:s}})),n(this,"userVisibleAuth",(function(e){var n=r(),t={origin:location.protocol+"//"+location.host,uuid:n};(null==e?void 0:e.screen)&&(t.screen=e.screen);var o=S(null==e?void 0:e.action);o&&(t.action=o);var s=w(t);a.flags&&(s="".concat(s,"#").concat(h(a.flags)));var c=screen.height/2-280,f=screen.width/2-410,m=window.open(s,"_blank","top=".concat(c,",left=").concat(f,",width=").concat(820,",height=").concat(560,",location"));if(!m){var g={code:i.CONNECT_WINDOW_NOT_OPENED,reason:d()};return Promise.reject(g)}return new Promise((function(e,t){var o=setInterval((function(){if(!m||m.closed){window.removeEventListener("message",a),clearInterval(o);var e={code:i.CONNECT_WINDOW_CLOSED,reason:p()};t(e)}}),1e3);function a(r){if(r.source===m&&m)if(window.removeEventListener("message",a),clearInterval(o),".vk.com"===r.origin.slice(r.origin.length-".vk.com".length))if(r.data.action==="vk_connect_response"+n){var s=r.data.payload;m.close(),e({provider:"vk",payload:s})}else if(r.data.action==="oauth_callback"+n)e({provider:r.data.payload.name}),m.close();else{m.close();var c={code:i.CONNECT_UNKNOWN_SDK_MESSAGE,reason:l(JSON.stringify(r.data))};t(c)}else{m.close();var p={code:i.CONNECT_DOMAIN_NOT_ALLOWED,reason:u(r.origin)};t(p)}}window.addEventListener("message",a)}))})),n(this,"redirectAuth",(function(e){var n=r(),t={redirect_uri:e.url,uuid:n};(null==e?void 0:e.state)&&(t.redirect_state=e.state),(null==e?void 0:e.screen)&&(t.screen=e.screen);var o=S(null==e?void 0:e.action);o&&(t.action=o);var i=w(t);location.assign(i)}))};!function(e){e.APP_HIDE="VKSDKMiniAppHide",e.APP_READY="VKSDKMiniAppReady",e.RESIZE="VKSDKMiniAppResize",e.APP_INIT_CONFIG="VKSDKMiniAppInitConfig"}(k||(k={})),function(e){e.SUPERAPP_TOKEN="VKSDKGeneralSuperAppToken",e.AUTH_NEEDED="VKSDKGeneralAuthNeeded",e.OPEN_APP="VKSDKGeneralOpenApp"}(I||(I={}));var K;!function(e){e.INIT="ConnectProfileInit"}(K||(K={}));var M={OneTapAuthEventsSDK:P,FloatingOneTapAuthEventsSDK:N,ButtonOneTapAuthEventsSDK:C,DataPolicyEventsSDK:T,AuthCaptchaEventsSDK:D};exports.Config=y,exports.Connect=L,exports.ConnectEvents=M,exports.MiniApp=function t(i){var a=this;e(this,t),n(this,"iframe",void 0),n(this,"bridge",void 0),n(this,"loading",void 0),n(this,"readyPromiseResolve",null),n(this,"readyPromise",null),n(this,"bodyOverflowValue",""),n(this,"params",void 0),n(this,"events",void 0),n(this,"open",(function(e,n){return a.loading?(a.iframe.src=a.getMiniAppUrl(e,n),a.loading=new Promise((function(e){a.iframe.onload=function(){a.iframe.onload=null,e()}})),a.readyPromise=new Promise((function(e){return a.readyPromiseResolve=e}))):a.preload(e,n).catch(console.error),a.iframe.style.display="block",a.bodyOverflowValue=window.document.body.style.overflow,window.document.body.style.overflow="hidden",a.loading.then(a.handleResize).catch(console.error),a.readyPromise})),n(this,"hide",(function(){a.events.emit("hide"),a.iframe.style.display="none",window.document.body.style.overflow=a.bodyOverflowValue})),n(this,"close",(function(){window.document.body.style.overflowX="",y.events.off("superAppToken",a.onSuperAppToken),a.iframe.remove(),a.bridge.destroy(),delete a.iframe,delete a.bridge,window.removeEventListener("resize",a.handleResize)})),n(this,"preload",(function(e,n){var t=document.createElement("iframe"),o=window.innerHeight,i=isFinite(a.params.zIndex)?a.params.zIndex:999999;return t.src=a.getMiniAppUrl(e,n),t.style.cssText="\n display: none;\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: ".concat(o,"px;\n min-height: ").concat(o,"px;\n border: none;\n z-index: ").concat(i,";\n "),a.iframe=t,document.body.appendChild(a.iframe),y.events.on("superAppToken",a.onSuperAppToken),a.bridge=new b({iframe:a.iframe,origin:"https://"+y.get().connectDomain}),a.bridge.onMessage(a.handleMessage),window.addEventListener("resize",a.handleResize),a.loading=new Promise((function(e){t.onload=function(){t.onload=null,e()}})),a.readyPromise=new Promise((function(e){return a.readyPromiseResolve=e})),a.loading})),n(this,"onSuperAppToken",(function(e){a.bridge.sendMessage({handler:I.SUPERAPP_TOKEN,params:{result:e}})})),n(this,"handleMessage",(function(e){switch(e.handler){case k.APP_HIDE:a.hide();break;case k.APP_READY:a.resolveReadyPromise(),a.handleUpdateConfig();break;case I.SUPERAPP_TOKEN:y._requestSuperAppToken();break;case I.AUTH_NEEDED:y._requestAuth()}})),n(this,"handleResize",(function(){if(a.iframe){var e=innerWidth,n=innerHeight;a.iframe.style.height="".concat(n,"px"),a.iframe.style.minHeight="".concat(n,"px"),a.bridge.sendMessage({handler:k.RESIZE,params:{viewport_width:e,viewport_height:n}})}})),n(this,"handleUpdateConfig",(function(){a.bridge.sendMessage({handler:k.APP_INIT_CONFIG,params:{fullMode:a.params.fullMode}})})),n(this,"getMiniAppUrl",(function(e,n){var t=y.get(),o=t.connectDomain,i=t.appId,r=t.superAppToken,s=t._debug,c=h({app:a.params.app,host_app_id:i,debug:s?"1":"",localhost:s?"1":"",superapp_token:r,app_query:e?JSON.stringify(e):"",app_hash:n||""});return"https://".concat(o,"/mini_app?").concat(c)})),n(this,"resolveReadyPromise",(function(){a.readyPromise&&a.readyPromiseResolve&&(a.readyPromiseResolve(),a.readyPromise=null,a.readyPromiseResolve=null)})),this.params=o({},i,{app:"number"==typeof i.app?"app".concat(i.app):i.app}),this.events=_()},exports.Profile=function t(){var o=this;e(this,t),n(this,"iframe",void 0),n(this,"config",void 0),n(this,"bridge",void 0),n(this,"iframeLoadPromise",void 0),n(this,"load",(function(e){if(!e.container)throw new Error("container is null");if(!e)throw new Error(c());return o.iframe||o.preload(e),o.iframeLoadPromise})),n(this,"remove",(function(){o.iframe&&o.iframe.parentNode&&o.iframe.parentNode.removeChild(o.iframe),o.destroy()})),n(this,"preload",(function(e){o.config=e;var n=document.createElement("iframe");n.style.border="none",n.style.width="100%",n.style.height="100%",n.style.minHeight="100%",e.container.appendChild(n),o.setup(n)})),n(this,"setup",(function(e){y.events.on("superAppToken",o.onSuperAppToken),e.src=o.getProfileUrl(),o.iframe=e,o.iframeLoadPromise=new Promise((function(n){e.onload=function(){return n(e)}})),o.bridge=new b({iframe:o.iframe,origin:"https://"+y.get().connectDomain}),o.bridge.onMessage(o.handleMessage)})),n(this,"destroy",(function(){y.events.off("superAppToken",o.onSuperAppToken),o.bridge.destroy(),delete o.iframe,delete o.iframeLoadPromise,delete o.bridge})),n(this,"onSuperAppToken",(function(e){if(e&&o.iframe){var n=o.iframe;o.destroy(),o.setup(n)}})),n(this,"handleMessage",(function(e){switch(e.handler){case K.INIT:o.handleInitApp().catch(console.error);break;case I.SUPERAPP_TOKEN:y._requestSuperAppToken();break;case I.AUTH_NEEDED:y._requestAuth();break;case I.OPEN_APP:y._openApp(e.params)}})),n(this,"handleInitApp",(function(){return Promise.resolve()})),n(this,"getProfileUrl",(function(){var e=y.get(),n=e.connectDomain,t=e.appId,i=e.superAppToken,a=e._debug,r=o.config.widgets,s=h({host_app_id:t,debug:a?"1":"",localhost:a?"1":"",superapp_token:i,widgets:r?r.join(","):""});return"https://".concat(n,"/super_profile?").concat(s)}))};

@@ -5,3 +5,10 @@ import Connect from './connect';

import Config from './config';
import { MiniAppEvents } from './miniapp/events';
export { Connect, MiniApp, MiniAppEvents, Profile, Config, };
import { OneTapAuthEventsSDK, FloatingOneTapAuthEventsSDK, ButtonOneTapAuthEventsSDK, DataPolicyEventsSDK, AuthCaptchaEventsSDK } from './connect/events';
declare const ConnectEvents: {
OneTapAuthEventsSDK: typeof OneTapAuthEventsSDK;
FloatingOneTapAuthEventsSDK: typeof FloatingOneTapAuthEventsSDK;
ButtonOneTapAuthEventsSDK: typeof ButtonOneTapAuthEventsSDK;
DataPolicyEventsSDK: typeof DataPolicyEventsSDK;
AuthCaptchaEventsSDK: typeof AuthCaptchaEventsSDK;
};
export { Connect, ConnectEvents, MiniApp, Profile, Config };

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

import e from"@babel/runtime/helpers/typeof";import"@babel/runtime/helpers/toConsumableArray";import n from"@babel/runtime/helpers/defineProperty";import"@babel/runtime/helpers/classCallCheck";import"@babel/runtime/helpers/createClass";function t(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}function o(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function r(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);n&&(o=o.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,o)}return t}function i(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{};n%2?r(Object(t),!0).forEach((function(n){o(e,n,t[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):r(Object(t)).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}))}return e}var a,s="ModuleSymbhasOwnPr-0123456789ABCDEFGHNRVfgctiUvz_KqYTJkLxpZXIjQW",c=function(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:21,n="",t=e;t--;)n+=s[64*Math.random()|0];return n},p=["agreements","promo","vkc_behavior","vkc_auth_action","vkc_brand"];!function(e){e[e.UNKNOWN=1]="UNKNOWN",e[e.MISSING_PARAM=2]="MISSING_PARAM",e[e.CONNECTION_LOST=3]="CONNECTION_LOST",e[e.USER_DENIED=4]="USER_DENIED",e[e.INVALID_PARAMS=5]="INVALID_PARAMS",e[e.CUSTOM=6]="CUSTOM",e[e.CONNECT_WINDOW_CLOSED=7]="CONNECT_WINDOW_CLOSED",e[e.CONNECT_WINDOW_NOT_OPENED=8]="CONNECT_WINDOW_NOT_OPENED",e[e.CONNECT_DOMAIN_NOT_ALLOWED=9]="CONNECT_DOMAIN_NOT_ALLOWED",e[e.CONNECT_UNKNOWN_SDK_MESSAGE=10]="CONNECT_UNKNOWN_SDK_MESSAGE",e[e.OLD_MISSING_PARAM=100]="OLD_MISSING_PARAM"}(a||(a={}));var u=function(){return"No params passed for load app!"},d=function(){return"Connect window was closed."},l=function(){return"Connect window was not opened."},f=function(e){return'URL domain "'.concat(e,'" is not allowed.')},h=function(e){return"This SDK message is unknown: ".concat(e)},m=!("undefined"==typeof window||!window.document||!window.document.createElement),v=m&&!!window.addEventListener,g=function(){};if(v)try{var O=Object.defineProperty({},"passive",{get:function(){!0}});window.addEventListener("test",g,O),window.removeEventListener("test",g,O)}catch(e){}!function(){if(!m)return!1;var e=!1;try{document.createElement("div").scrollTo({top:0,get behavior(){return e=!0,"smooth"}})}catch(e){}}();function _(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);n&&(o=o.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,o)}return t}function A(e){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?_(Object(o),!0).forEach((function(t){n(e,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):_(Object(o)).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(o,n))}))}return e}var E={parse:function(e){if("string"!=typeof e)return{};if(!(e=e.trim().replace(/^[?#&]/,"")))return{};var n=/\?(.+)$/gi.exec(e);return(n?n[1]:e).split("&").reduce((function(e,n){var t=n.split("=");return t[1]&&(e[t[0]]=decodeURIComponent(t[1])),e}),{})},stringify:function(n){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if("object"!==e(n)||null===n)return"";t=A({encode:!0},t);var o=function(e){return t.encode?encodeURIComponent(e):String(e)};return Object.keys(n).reduce((function(e,r){var i=n[r];return void 0===i?e:null===i?(t.skipNull||e.push([o(r),""].join("=")),e):Array.isArray(i)?(i.map((function(n){e.push("".concat(o(r),"[]=").concat(o(n)))})).join(),e):(e.push([o(r),o(i)].join("=")),e)}),[]).join("&")}};function w(e){return E.stringify(e)}function y(e){return Object.keys(e).filter((function(e){return p.includes(e)}))}function P(e){var n=function(e){return y(e).reduce((function(n,t){return n[t]=e[t],n}),{})}(e);return btoa(JSON.stringify(n))}var b=["extend_token"];function N(e){return e&&b.includes(e.name)?btoa(JSON.stringify(e)):""}function S(e){return e=e||Object.create(null),{on:function(n,t){(e[n]||(e[n]=[])).push(t)},off:function(n,t){e[n]&&e[n].splice(e[n].indexOf(t)>>>0,1)},emit:function(n,t){(e[n]||[]).slice().map((function(e){e(t)})),(e["*"]||[]).slice().map((function(e){e(n,t)}))}}}var k,D,T,C={appId:0,superAppToken:"",loginDomain:"login.vk.com",oauthDomain:"oauth.vk.com",connectDomain:"connect.vk.com",_debug:!1},I={},M={events:S(),init:function(e){if(!e.appId)throw new Error("appId required");C.appId=e.appId,C.superAppToken=e.superAppToken||"",C.loginDomain=e.loginDomain||"login.vk.com",C.oauthDomain=e.oauthDomain||"oauth.vk.com",C.connectDomain=e.connectDomain||"connect.vk.com",C.appSettings=e.appSettings,C._debug=!!e._debug},get:function(){return C},setSuperAppToken:function(e){C.superAppToken=e,M.events.emit("superAppToken",e)},onRequestSuperAppToken:function(e){I.superAppToken=e},_requestSuperAppToken:function(){var e;I.superAppToken&&(e=I.superAppToken()),e&&e.then((function(e){return M.setSuperAppToken(e)})).catch(console.error)},onAuth:function(e){I.auth=e},_requestAuth:function(){var e;I.auth&&(e=I.auth()),e&&e.then((function(e){return M.setSuperAppToken(e)})).catch(console.error)},onOpenApp:function(e){I.openApp=e},_openApp:function(e){I.openApp&&I.openApp(e.app)}},R=new function e(){var n=this;t(this,e),o(this,"flags",null),o(this,"silentAuth",(function(){var e=M.get(),n=e.loginDomain,t=e.appId,o=c(),r="https://".concat(n,"/?act=connect&app_id=").concat(t,"&response_type=").concat("silent_token","&uuid=").concat(o,"&v=").concat("0.0.2"),i=new XMLHttpRequest;return i.open("GET",r,!0),i.responseType="json",i.withCredentials=!0,new Promise((function(e,n){i.onload=function(){i.response?e({provider:"vk",payload:i.response}):n()},i.onerror=function(){n()},i.send()}))})),o(this,"userVisibleAuth",(function(e){var t=c(),o={origin:location.protocol+"//"+location.host,uuid:t};(null==e?void 0:e.screen)&&(o.screen=e.screen);var r=N(null==e?void 0:e.action);r&&(o.action=r);var i=n.makeAuthUrl(o);n.flags&&(i="".concat(i,"#").concat(w(n.flags)));var s=screen.height/2-280,p=screen.width/2-410,u=window.open(i,"_blank","top=".concat(s,",left=").concat(p,",width=").concat(820,",height=").concat(560,",location"));if(!u){var m={code:a.CONNECT_WINDOW_NOT_OPENED,reason:l()};return Promise.reject(m)}return new Promise((function(e,n){var o=setInterval((function(){if(!u||u.closed){window.removeEventListener("message",r),clearInterval(o);var e={code:a.CONNECT_WINDOW_CLOSED,reason:d()};n(e)}}),1e3);function r(i){if(i.source===u&&u)if(window.removeEventListener("message",r),clearInterval(o),".vk.com"===i.origin.slice(i.origin.length-".vk.com".length))if(i.data.action==="vk_connect_response"+t){var s=i.data.payload;u.close(),e({provider:"vk",payload:s})}else if(i.data.action==="oauth_callback"+t)e({provider:i.data.payload.name}),u.close();else{u.close();var c={code:a.CONNECT_UNKNOWN_SDK_MESSAGE,reason:h(JSON.stringify(i.data))};n(c)}else{u.close();var p={code:a.CONNECT_DOMAIN_NOT_ALLOWED,reason:f(i.origin)};n(p)}}window.addEventListener("message",r)}))})),o(this,"redirectAuth",(function(e){var t=c(),o={redirect_uri:e.url,uuid:t};(null==e?void 0:e.state)&&(o.redirect_state=e.state),(null==e?void 0:e.screen)&&(o.screen=e.screen);var r=N(null==e?void 0:e.action);r&&(o.action=r);var i=n.makeAuthUrl(o);location.assign(i)})),o(this,"makeAuthUrl",(function(e){var n=M.get(),t=n.appId,o=n.connectDomain,r=n.appSettings,a=i({app_id:t,response_type:"silent_token",v:"0.0.2"},e);r&&function(e){var n;return Boolean(null===(n=y(e))||void 0===n?void 0:n.length)}(r)&&(a.app_settings=P(r));var s=w(a);return"https://".concat(o,"/auth?").concat(s)}))};!function(e){e.APP_CLOSE="VKWebAppClose",e.APP_READY="VKSDKMiniAppReady",e.RESIZE="VKSDKMiniAppResize",e.APP_INIT_CONFIG="VKSDKMiniAppInitConfig",e.OPEN_APP="VKWebAppOpenApp",e.OPEN_PAY_FORM="VKWebAppOpenPayForm",e.ACTION_DONE="VKWebAppActionDone"}(k||(k={})),function(e){e.OPEN="open",e.HIDE="hide",e.CLOSE="close",e.SHOW="show",e.MESSAGE="message",e.CREATE_APP="createapp"}(D||(D={})),function(e){e.SUPERAPP_TOKEN="VKSDKGeneralSuperAppToken",e.AUTH_NEEDED="VKSDKGeneralAuthNeeded",e.OPEN_APP="VKSDKGeneralOpenApp"}(T||(T={}));var j,L=function e(n){var r=this;t(this,e),o(this,"handler",(function(){return{}})),o(this,"config",void 0),o(this,"destroy",(function(){delete r.config,window.removeEventListener("message",r.handleMessage)})),o(this,"onMessage",(function(e){r.handler=e})),o(this,"sendMessage",(function(e){r.config.iframe.contentWindow.postMessage(i({type:"vk-sak-sdk"},e),r.config.origin)})),o(this,"handleMessage",(function(e){r.config.origin&&e.origin===r.config.origin&&e.source===r.config.iframe.contentWindow&&e.data&&"vk-sak-sdk"===e.data.type&&r.handler(e.data)})),this.config=n,window.addEventListener("message",this.handleMessage)},K=function e(n){var r=this;t(this,e),o(this,"events",void 0),o(this,"iframe",void 0),o(this,"bridge",void 0),o(this,"loading",void 0),o(this,"readyPromiseResolve",null),o(this,"readyPromise",null),o(this,"bodyOverflowValue",""),o(this,"params",void 0),o(this,"child",null),o(this,"open",(function(e,n){return r.loading?(r.iframe.src=r.getMiniAppUrl(e,n),r.loading=new Promise((function(e){r.iframe.onload=function(){r.iframe.onload=null,e()}})),r.readyPromise=new Promise((function(e){return r.readyPromiseResolve=e}))):r.preload(e,n).catch(console.error),r.iframe.style.display="block",r.bodyOverflowValue=window.document.body.style.overflow,window.document.body.style.overflow="hidden",r.loading.then(r.handleResize).catch(console.error),r.events.emit(D.OPEN),r.readyPromise})),o(this,"hide",(function(){r.iframe.style.display="none",window.document.body.style.overflow=r.bodyOverflowValue,r.events.emit(D.HIDE)})),o(this,"close",(function(){window.document.body.style.overflowX="",M.events.off("superAppToken",r.onSuperAppToken),r.iframe&&r.iframe.remove(),r.bridge&&r.bridge.destroy(),delete r.iframe,delete r.bridge,window.removeEventListener("resize",r.handleResize),r.events.emit(D.CLOSE)})),o(this,"show",(function(){if(!r.loading)throw new Error('App is not loaded, use "open" or "preload" methods');r.iframe.style.display="block",window.document.body.style.overflow=r.bodyOverflowValue,r.events.emit(D.SHOW)})),o(this,"preload",(function(e,n){var t=document.createElement("iframe"),o=window.innerHeight,i=isFinite(r.params.zIndex)?r.params.zIndex:999999;return t.src=r.getMiniAppUrl(e,n),t.style.cssText="\n display: none;\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: ".concat(o,"px;\n min-height: ").concat(o,"px;\n border: none;\n z-index: ").concat(i,";\n "),r.iframe=t,document.body.appendChild(r.iframe),M.events.on("superAppToken",r.onSuperAppToken),r.bridge=new L({iframe:r.iframe,origin:"https://"+M.get().connectDomain}),r.bridge.onMessage(r.handleMessage),window.addEventListener("resize",r.handleResize),r.loading=new Promise((function(e){t.onload=function(){t.onload=null,e()}})),r.readyPromise=new Promise((function(e){return r.readyPromiseResolve=e})),r.loading})),o(this,"sendMessage",(function(e){r.bridge.sendMessage(e)})),o(this,"onSuperAppToken",(function(e){r.bridge.sendMessage({handler:T.SUPERAPP_TOKEN,params:{result:e}})})),o(this,"handleMessage",(function(e){switch(e.handler){case k.APP_CLOSE:r.hide();break;case k.APP_READY:r.resolveReadyPromise(),r.handleUpdateConfig();break;case k.OPEN_APP:r.openMiniapp(e.params);break;case k.OPEN_PAY_FORM:r.openPayForm(e.params);break;case T.SUPERAPP_TOKEN:M._requestSuperAppToken();break;case T.AUTH_NEEDED:M._requestAuth();break;default:r.events.emit(D.MESSAGE,e)}})),o(this,"handleResize",(function(){if(r.iframe){var e=innerWidth,n=innerHeight;r.iframe.style.height="".concat(n,"px"),r.iframe.style.minHeight="".concat(n,"px"),r.bridge.sendMessage({handler:k.RESIZE,params:{viewport_width:e,viewport_height:n}})}})),o(this,"handleUpdateConfig",(function(){r.bridge.sendMessage({handler:k.APP_INIT_CONFIG,params:{fullMode:r.params.fullMode}})})),o(this,"getMiniAppUrl",(function(e,n){var t=M.get(),o=t.connectDomain,i=t.appId,a=t.superAppToken,s=t._debug,c=w({app:r.params.app,host_app_id:i,debug:s?"1":"",localhost:s?"1":"",superapp_token:a,app_query:e?JSON.stringify(e):"",app_hash:n||""});return"https://".concat(o,"/mini_app?").concat(c)})),o(this,"resolveReadyPromise",(function(){r.readyPromise&&r.readyPromiseResolve&&(r.readyPromiseResolve(),r.readyPromise=null,r.readyPromiseResolve=null)})),o(this,"openMiniapp",(function(n){r.child=new e({app:n.app_id}),r.events.emit(D.CREATE_APP,{app:r.child,location:n.location})})),o(this,"openPayForm",(function(n){var t=i({},n.params);t.data&&(t.data=JSON.stringify(t.data));var o=i({},t,{app_id:n.app_id,action:n.action}),a=new e({app:6217559});a.open(o).then((function(){return r.hide()})).catch(console.error),a.events.on(D.MESSAGE,(function(e){r.handleVKPayFormMessage(e),a.close(),r.show()})),a.events.on(D.HIDE,(function(){a.close(),r.close()}))})),o(this,"handleVKPayFormMessage",(function(e){e.handler===k.ACTION_DONE&&r.sendMessage(e)})),this.params=i({},n,{app:"number"==typeof n.app?"app".concat(n.app):n.app}),this.events=S()};!function(e){e.INIT="ConnectProfileInit"}(j||(j={}));var U=function e(){var n=this;t(this,e),o(this,"iframe",void 0),o(this,"config",void 0),o(this,"bridge",void 0),o(this,"iframeLoadPromise",void 0),o(this,"load",(function(e){if(!e.container)throw new Error("container is null");if(!e)throw new Error(u());return n.iframe||n.preload(e),n.iframeLoadPromise})),o(this,"remove",(function(){n.iframe&&n.iframe.parentNode&&n.iframe.parentNode.removeChild(n.iframe),n.destroy()})),o(this,"preload",(function(e){n.config=e;var t=document.createElement("iframe");t.style.border="none",t.style.width="100%",t.style.height="100%",t.style.minHeight="100%",e.container.appendChild(t),n.setup(t)})),o(this,"setup",(function(e){M.events.on("superAppToken",n.onSuperAppToken),e.src=n.getProfileUrl(),n.iframe=e,n.iframeLoadPromise=new Promise((function(n){e.onload=function(){return n(e)}})),n.bridge=new L({iframe:n.iframe,origin:"https://"+M.get().connectDomain}),n.bridge.onMessage(n.handleMessage)})),o(this,"destroy",(function(){M.events.off("superAppToken",n.onSuperAppToken),n.bridge.destroy(),delete n.iframe,delete n.iframeLoadPromise,delete n.bridge})),o(this,"onSuperAppToken",(function(e){if(e&&n.iframe){var t=n.iframe;n.destroy(),n.setup(t)}})),o(this,"handleMessage",(function(e){switch(e.handler){case j.INIT:n.handleInitApp().catch(console.error);break;case T.SUPERAPP_TOKEN:M._requestSuperAppToken();break;case T.AUTH_NEEDED:M._requestAuth();break;case T.OPEN_APP:M._openApp(e.params)}})),o(this,"handleInitApp",(function(){return Promise.resolve()})),o(this,"getProfileUrl",(function(){var e=M.get(),t=e.connectDomain,o=e.appId,r=e.superAppToken,i=e._debug,a=n.config.widgets,s=w({host_app_id:o,debug:i?"1":"",localhost:i?"1":"",superapp_token:r,widgets:a?a.join(","):""});return"https://".concat(t,"/super_profile?").concat(s)}))};export{M as Config,R as Connect,K as MiniApp,D as MiniAppEvents,U as Profile};
function e(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}function n(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function t(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);n&&(o=o.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,o)}return t}function o(e){for(var o=1;o<arguments.length;o++){var i=null!=arguments[o]?arguments[o]:{};o%2?t(Object(i),!0).forEach((function(t){n(e,t,i[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):t(Object(i)).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(i,n))}))}return e}var i,a="ModuleSymbhasOwnPr-0123456789ABCDEFGHNRVfgctiUvz_KqYTJkLxpZXIjQW",r=function(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:21,n="",t=e;t--;)n+=a[64*Math.random()|0];return n},s=["agreements","promo","vkc_behavior","vkc_auth_action","vkc_brand"];!function(e){e[e.UNKNOWN=1]="UNKNOWN",e[e.MISSING_PARAM=2]="MISSING_PARAM",e[e.CONNECTION_LOST=3]="CONNECTION_LOST",e[e.USER_DENIED=4]="USER_DENIED",e[e.INVALID_PARAMS=5]="INVALID_PARAMS",e[e.CUSTOM=6]="CUSTOM",e[e.CONNECT_WINDOW_CLOSED=7]="CONNECT_WINDOW_CLOSED",e[e.CONNECT_WINDOW_NOT_OPENED=8]="CONNECT_WINDOW_NOT_OPENED",e[e.CONNECT_DOMAIN_NOT_ALLOWED=9]="CONNECT_DOMAIN_NOT_ALLOWED",e[e.CONNECT_UNKNOWN_SDK_MESSAGE=10]="CONNECT_UNKNOWN_SDK_MESSAGE",e[e.OLD_MISSING_PARAM=100]="OLD_MISSING_PARAM"}(i||(i={}));var c=function(){return"No params passed for load app!"},p=function(){return"Connect window was closed."},d=function(){return"Connect window was not opened."},u=function(e){return'URL domain "'.concat(e,'" is not allowed.')},l=function(e){return"This SDK message is unknown: ".concat(e)};function h(e){return Object.keys(e).map((function(n){var t=e[n];return n=encodeURIComponent(n),t=encodeURIComponent(t),"".concat(n,"=").concat(t)}),[]).join("&")}function f(e){return Object.keys(e).filter((function(e){return s.includes(e)}))}function m(e){var n;return Boolean(null===(n=f(e))||void 0===n?void 0:n.length)}function g(e){var n=function(e){return f(e).reduce((function(n,t){return n[t]=e[t],n}),{})}(e);return btoa(JSON.stringify(n))}function A(e,n){var t,o=document.createElement("iframe");for(var i in e&&(o.src=e),o.style.cssText=null!==(t=null==n?void 0:n.cssText)&&void 0!==t?t:"",o.width="100%",o.height="100%",o.style.border="none",null==n?void 0:n.properties){var a;if(n&&n.properties.hasOwnProperty(i))o[i]=null!==(a=n.properties[i])&&void 0!==a?a:""}return o}function _(e){return e=e||Object.create(null),{on:function(n,t){(e[n]||(e[n]=[])).push(t)},off:function(n,t){e[n]&&e[n].splice(e[n].indexOf(t)>>>0,1)},emit:function(n,t){(e[n]||[]).slice().map((function(e){e(t)})),(e["*"]||[]).slice().map((function(e){e(n,t)}))}}}var v={appId:0,superAppToken:"",loginDomain:"login.vk.com",oauthDomain:"oauth.vk.com",connectDomain:"connect.vk.com",_debug:!1},O={},y={events:_(),init:function(e){if(!e.appId)throw new Error("appId required");v.appId=e.appId,v.superAppToken=e.superAppToken||"",v.loginDomain=e.loginDomain||"login.vk.com",v.oauthDomain=e.oauthDomain||"oauth.vk.com",v.connectDomain=e.connectDomain||"connect.vk.com",v.appSettings=e.appSettings,v._debug=!!e._debug},get:function(){return v},setSuperAppToken:function(e){v.superAppToken=e,y.events.emit("superAppToken",e)},onRequestSuperAppToken:function(e){O.superAppToken=e},_requestSuperAppToken:function(){var e;O.superAppToken&&(e=O.superAppToken()),e&&e.then((function(e){return y.setSuperAppToken(e)})).catch(console.error)},onAuth:function(e){O.auth=e},_requestAuth:function(){var e;O.auth&&(e=O.auth()),e&&e.then((function(e){return y.setSuperAppToken(e)})).catch(console.error)},onOpenApp:function(e){O.openApp=e},_openApp:function(e){O.openApp&&O.openApp(e.app)}},S=["extend_token"];function E(e){return e&&S.includes(e.name)?btoa(JSON.stringify(e)):""}function w(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"auth",t=y.get(),i=t.appId,a=t.connectDomain,r=t.appSettings,s=o({app_id:i,response_type:"silent_token",v:"0.0.2"},e);r&&m(r)&&(s.app_settings=g(r));var c=h(s);return"https://".concat(a,"/").concat(n,"?").concat(c)}var T,D,P,N,C,b=function t(i){var a=this;e(this,t),n(this,"handler",(function(){return{}})),n(this,"config",void 0),n(this,"destroy",(function(){delete a.config,window.removeEventListener("message",a.handleMessage)})),n(this,"onMessage",(function(e){a.handler=e})),n(this,"sendMessage",(function(e){a.config.iframe.contentWindow.postMessage(o({type:"vk-sak-sdk"},e),a.config.origin)})),n(this,"handleMessage",(function(e){a.config.origin&&e.origin===a.config.origin&&e.source===a.config.iframe.contentWindow&&e.data&&"vk-sak-sdk"===e.data.type&&(console.info("[received from ui]",e.data),a.handler(e.data))})),this.config=i,window.addEventListener("message",this.handleMessage)};!function(e){e.SHOW_DATA_POLICY="VKSDKOneTapAuthConnectDataPolicy",e.HIDE_DATA_POLICY="VKSDKOneTapAuthDataPolicyClose",e.DATA_POLICY_RESULT="VKSDKOneTapAuthDataPolicyResult",e.SHOW_CAPTCHA="VKSDKOneTapAuthDataPolicyShowCaptcha"}(T||(T={})),function(e){e.CAPTCHA_SUCCESS="VKSDKAuthCaptchaSuccess",e.CAPTCHA_FAIL="VKSDKAuthCaptchaFail"}(D||(D={})),function(e){e.PHONE_VALIDATION_NEEDED="VKSDKOneTapAuthPhoneValidationNeeded",e.FULL_AUTH_NEEDED="VKSDKOneTapAuthFullAuthNeeded",e.AUTH_DATA_LOADED="VKSDKOneTapAuthDataLoaded",e.NOT_AUTHORIZED="VKSDKOneTapAuthNotAuthorized",e.LOGIN_SUCCESS="VKSDKOneTapAuthLoginSuccess",e.RESIZE_FRAME="VKSDKOneTapResizeFrame",e.SHOW_CAPTCHA="VKSDKOneTapShowCaptcha",e.VALIDATE_CAPTCHA="VKSDKOneTapValidateCaptcha"}(P||(P={})),function(e){e.CLOSE_AUTH="VKSDKOneTapAuthClose"}(N||(N={})),function(e){e.SHOW_LOGIN="VKSDKButtonOneTapAuthShowLogin",e.SHOW_LOGIN_OPTIONS="VKSDKButtonOneTapAuthShowLoginOptions"}(C||(C={}));var k,I,L=new function t(){var a=this;e(this,t),n(this,"flags",null),n(this,"silentAuth",(function(){var e=y.get(),n=e.loginDomain,t=e.appId,o=r(),i="https://".concat(n,"/?act=connect&app_id=").concat(t,"&response_type=").concat("silent_token","&uuid=").concat(o,"&v=").concat("0.0.2"),a=new XMLHttpRequest;return a.open("GET",i,!0),a.responseType="json",a.withCredentials=!0,new Promise((function(e,n){a.onload=function(){a.response?e({provider:"vk",payload:a.response}):n()},a.onerror=function(){n()},a.send()}))})),n(this,"oneTapAuth",(function(e,n){if(!["floating","button"].includes(e))return null;var t,i,s=function(){var e,n=window.innerWidth,t=n<=768;return{destroy:function(){return window.removeEventListener("resize",e)},isAdaptive:function(){return t},observe:function(o){e=function(){var e=window.innerWidth;n>768&&e<=768?o(t=!0):n<=768&&e>768&&o(t=!1),n=e},window.addEventListener("resize",e)}}}(),c=null;switch(e){case"floating":t=s.isAdaptive(),i=t?"314px":"334px",c={pageUrl:"floating_one_tap_auth",pageUrlParams:{adaptive:t?1:0},frameStyles:t?"\n display: none;\n position: fixed;\n bottom: 0;\n right: 0;\n max-width: 100%;\n width: 100%;\n height: ".concat(i,";\n "):"\n display: none;\n position: fixed;\n top: 0;\n right: 0;\n max-width: 400px;\n width: 100%;\n height: ".concat(i,";\n ")};break;case"button":c=function(e){var n={},t=44;if(e){var o,i;n.show_agreements=null!==(o=e.showAgreements)&&void 0!==o?o:0,n.show_alternative_login=null!==(i=e.showAlternativeLogin)&&void 0!==i?i:0;t+=n.show_alternative_login?56:0,t+=n.show_agreements?80:0}return{pageUrl:"button_one_tap_auth",pageUrlParams:n,frameStyles:"\n height: ".concat(t,"px;\n ")}}(n.options)}if(!c)throw new Error("options were not set");var p=r(),d=o({origin:location.protocol+"//"+location.host,uuid:p},c.pageUrlParams),u=c.pageUrl,l=A(w(d,u),{cssText:c.frameStyles});switch(e){case"floating":s.observe((function(e){e?(l.style.maxWidth="100%",l.style.top="auto",l.style.bottom="0"):(l.style.maxWidth="400px",l.style.top="0",l.style.bottom="auto"),l.style.display="none",d=o({},d,{adaptive:e?1:0}),l.src=w(d,u)})),document.body.appendChild(l);break;case"button":var h=n.container;h&&h.appendChild(l)}var f=new b({iframe:l,origin:"https://"+y.get().connectDomain}),m=function(){f.sendMessage({handler:P.RESIZE_FRAME,params:{uuid:p}})};window.addEventListener("resize",m);var g=function(){l&&(l.remove(),l=null),window.removeEventListener("resize",m),s&&s.destroy(),f.destroy()},_=new Promise((function(t){f.onMessage((function(i){if(i.params.uuid===p)switch(i.handler){case P.FULL_AUTH_NEEDED:case P.PHONE_VALIDATION_NEEDED:a.userVisibleAuth().then((function(e){n.callback({type:P.LOGIN_SUCCESS,provider:"vk",payload:o({uuid:p},e.payload)})})).catch(console.error);break;case P.NOT_AUTHORIZED:"floating"===e&&(n.callback({type:i.handler,payload:{uuid:p,error:"not_authorized"}}),g()),t(i.handler);break;case P.AUTH_DATA_LOADED:"floating"===e&&(l.style.display="block"),f.sendMessage({handler:P.RESIZE_FRAME,params:{uuid:p}}),t(i.handler);break;case P.RESIZE_FRAME:l.style.height="".concat(i.params.height,"px");break;case P.LOGIN_SUCCESS:n.callback({type:i.handler,provider:"vk",payload:o({uuid:p},i.params)});break;case P.SHOW_CAPTCHA:var r=a.captcha(p,{captcha_sid:i.params.captcha_sid,captcha_img:i.params.captcha_img});r.show().then((function(e){f.sendMessage({handler:D.CAPTCHA_SUCCESS,params:o({uuid:p},e)})})).catch((function(){f.sendMessage({handler:D.CAPTCHA_FAIL,params:{uuid:p}}),r.destroy()}));break;case N.CLOSE_AUTH:n.callback({type:i.handler,payload:{uuid:p}}),g();break;case C.SHOW_LOGIN:case C.SHOW_LOGIN_OPTIONS:n.callback({type:i.handler,payload:{uuid:p}});break;case T.SHOW_DATA_POLICY:a.userDataPolicy(p).show().then((function(){n.callback({type:T.DATA_POLICY_RESULT,payload:{uuid:p,policyAccepted:!0}})})).catch((function(){n.callback({type:T.DATA_POLICY_RESULT,payload:{uuid:p,policyAccepted:!1}})}))}}))}));return{getFrame:function(){return l},destroy:g,authReadyPromise:_}})),n(this,"userDataPolicy",(function(e){var n=w({origin:location.protocol+"//"+location.host,uuid:e},"user_data_policy"),t=window.innerHeight,i="\n display: none;\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: ".concat(t,"px;\n min-height: ").concat(t,"px;\n border: none;\n z-index: 99999;\n "),r=A(n,{properties:{height:"".concat(t,"px")},cssText:i});document.body.appendChild(r);var s=new b({iframe:r,origin:"https://"+y.get().connectDomain}),c=function(){document.body.removeChild(r),s.destroy()},p=function(){r.style.display="none"};return{show:function(){return r.style.display="block",new Promise((function(n,t){s.onMessage((function(i){switch(i.handler){case T.HIDE_DATA_POLICY:c(),n();break;case T.SHOW_CAPTCHA:var d=a.captcha(e,{captcha_sid:i.params.captcha_sid,captcha_img:i.params.captcha_img});d.show().then((function(n){s.sendMessage({handler:D.CAPTCHA_SUCCESS,params:o({uuid:e},n)}),r.style.display="block"})).catch((function(){s.sendMessage({handler:D.CAPTCHA_FAIL,params:{uuid:e}}),d.destroy()})),p();break;default:t()}}))}))},hide:p,destroy:c}})),n(this,"captcha",(function(e,n){var t=w(o({origin:location.protocol+"//"+location.host,uuid:e},n),"auth_captcha"),i=window.innerHeight,a=A(t,{cssText:"\n display: none;\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: ".concat(i,"px;\n min-height: ").concat(i,"px;\n border: none;\n z-index: 99999;\n ")});document.body.appendChild(a);var r=new b({iframe:a,origin:"https://"+y.get().connectDomain}),s=function(){document.body.removeChild(a),r.destroy()};return{show:function(){return a.style.display="block",new Promise((function(e,n){r.onMessage((function(t){switch(t.handler){case D.CAPTCHA_SUCCESS:e(t.params),s();break;default:n(),s()}}))}))},destroy:s}})),n(this,"userVisibleAuth",(function(e){var n=r(),t={origin:location.protocol+"//"+location.host,uuid:n};(null==e?void 0:e.screen)&&(t.screen=e.screen);var o=E(null==e?void 0:e.action);o&&(t.action=o);var s=w(t);a.flags&&(s="".concat(s,"#").concat(h(a.flags)));var c=screen.height/2-280,f=screen.width/2-410,m=window.open(s,"_blank","top=".concat(c,",left=").concat(f,",width=").concat(820,",height=").concat(560,",location"));if(!m){var g={code:i.CONNECT_WINDOW_NOT_OPENED,reason:d()};return Promise.reject(g)}return new Promise((function(e,t){var o=setInterval((function(){if(!m||m.closed){window.removeEventListener("message",a),clearInterval(o);var e={code:i.CONNECT_WINDOW_CLOSED,reason:p()};t(e)}}),1e3);function a(r){if(r.source===m&&m)if(window.removeEventListener("message",a),clearInterval(o),".vk.com"===r.origin.slice(r.origin.length-".vk.com".length))if(r.data.action==="vk_connect_response"+n){var s=r.data.payload;m.close(),e({provider:"vk",payload:s})}else if(r.data.action==="oauth_callback"+n)e({provider:r.data.payload.name}),m.close();else{m.close();var c={code:i.CONNECT_UNKNOWN_SDK_MESSAGE,reason:l(JSON.stringify(r.data))};t(c)}else{m.close();var p={code:i.CONNECT_DOMAIN_NOT_ALLOWED,reason:u(r.origin)};t(p)}}window.addEventListener("message",a)}))})),n(this,"redirectAuth",(function(e){var n=r(),t={redirect_uri:e.url,uuid:n};(null==e?void 0:e.state)&&(t.redirect_state=e.state),(null==e?void 0:e.screen)&&(t.screen=e.screen);var o=E(null==e?void 0:e.action);o&&(t.action=o);var i=w(t);location.assign(i)}))};!function(e){e.APP_HIDE="VKSDKMiniAppHide",e.APP_READY="VKSDKMiniAppReady",e.RESIZE="VKSDKMiniAppResize",e.APP_INIT_CONFIG="VKSDKMiniAppInitConfig"}(k||(k={})),function(e){e.SUPERAPP_TOKEN="VKSDKGeneralSuperAppToken",e.AUTH_NEEDED="VKSDKGeneralAuthNeeded",e.OPEN_APP="VKSDKGeneralOpenApp"}(I||(I={}));var K,M=function t(i){var a=this;e(this,t),n(this,"iframe",void 0),n(this,"bridge",void 0),n(this,"loading",void 0),n(this,"readyPromiseResolve",null),n(this,"readyPromise",null),n(this,"bodyOverflowValue",""),n(this,"params",void 0),n(this,"events",void 0),n(this,"open",(function(e,n){return a.loading?(a.iframe.src=a.getMiniAppUrl(e,n),a.loading=new Promise((function(e){a.iframe.onload=function(){a.iframe.onload=null,e()}})),a.readyPromise=new Promise((function(e){return a.readyPromiseResolve=e}))):a.preload(e,n).catch(console.error),a.iframe.style.display="block",a.bodyOverflowValue=window.document.body.style.overflow,window.document.body.style.overflow="hidden",a.loading.then(a.handleResize).catch(console.error),a.readyPromise})),n(this,"hide",(function(){a.events.emit("hide"),a.iframe.style.display="none",window.document.body.style.overflow=a.bodyOverflowValue})),n(this,"close",(function(){window.document.body.style.overflowX="",y.events.off("superAppToken",a.onSuperAppToken),a.iframe.remove(),a.bridge.destroy(),delete a.iframe,delete a.bridge,window.removeEventListener("resize",a.handleResize)})),n(this,"preload",(function(e,n){var t=document.createElement("iframe"),o=window.innerHeight,i=isFinite(a.params.zIndex)?a.params.zIndex:999999;return t.src=a.getMiniAppUrl(e,n),t.style.cssText="\n display: none;\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: ".concat(o,"px;\n min-height: ").concat(o,"px;\n border: none;\n z-index: ").concat(i,";\n "),a.iframe=t,document.body.appendChild(a.iframe),y.events.on("superAppToken",a.onSuperAppToken),a.bridge=new b({iframe:a.iframe,origin:"https://"+y.get().connectDomain}),a.bridge.onMessage(a.handleMessage),window.addEventListener("resize",a.handleResize),a.loading=new Promise((function(e){t.onload=function(){t.onload=null,e()}})),a.readyPromise=new Promise((function(e){return a.readyPromiseResolve=e})),a.loading})),n(this,"onSuperAppToken",(function(e){a.bridge.sendMessage({handler:I.SUPERAPP_TOKEN,params:{result:e}})})),n(this,"handleMessage",(function(e){switch(e.handler){case k.APP_HIDE:a.hide();break;case k.APP_READY:a.resolveReadyPromise(),a.handleUpdateConfig();break;case I.SUPERAPP_TOKEN:y._requestSuperAppToken();break;case I.AUTH_NEEDED:y._requestAuth()}})),n(this,"handleResize",(function(){if(a.iframe){var e=innerWidth,n=innerHeight;a.iframe.style.height="".concat(n,"px"),a.iframe.style.minHeight="".concat(n,"px"),a.bridge.sendMessage({handler:k.RESIZE,params:{viewport_width:e,viewport_height:n}})}})),n(this,"handleUpdateConfig",(function(){a.bridge.sendMessage({handler:k.APP_INIT_CONFIG,params:{fullMode:a.params.fullMode}})})),n(this,"getMiniAppUrl",(function(e,n){var t=y.get(),o=t.connectDomain,i=t.appId,r=t.superAppToken,s=t._debug,c=h({app:a.params.app,host_app_id:i,debug:s?"1":"",localhost:s?"1":"",superapp_token:r,app_query:e?JSON.stringify(e):"",app_hash:n||""});return"https://".concat(o,"/mini_app?").concat(c)})),n(this,"resolveReadyPromise",(function(){a.readyPromise&&a.readyPromiseResolve&&(a.readyPromiseResolve(),a.readyPromise=null,a.readyPromiseResolve=null)})),this.params=o({},i,{app:"number"==typeof i.app?"app".concat(i.app):i.app}),this.events=_()};!function(e){e.INIT="ConnectProfileInit"}(K||(K={}));var U=function t(){var o=this;e(this,t),n(this,"iframe",void 0),n(this,"config",void 0),n(this,"bridge",void 0),n(this,"iframeLoadPromise",void 0),n(this,"load",(function(e){if(!e.container)throw new Error("container is null");if(!e)throw new Error(c());return o.iframe||o.preload(e),o.iframeLoadPromise})),n(this,"remove",(function(){o.iframe&&o.iframe.parentNode&&o.iframe.parentNode.removeChild(o.iframe),o.destroy()})),n(this,"preload",(function(e){o.config=e;var n=document.createElement("iframe");n.style.border="none",n.style.width="100%",n.style.height="100%",n.style.minHeight="100%",e.container.appendChild(n),o.setup(n)})),n(this,"setup",(function(e){y.events.on("superAppToken",o.onSuperAppToken),e.src=o.getProfileUrl(),o.iframe=e,o.iframeLoadPromise=new Promise((function(n){e.onload=function(){return n(e)}})),o.bridge=new b({iframe:o.iframe,origin:"https://"+y.get().connectDomain}),o.bridge.onMessage(o.handleMessage)})),n(this,"destroy",(function(){y.events.off("superAppToken",o.onSuperAppToken),o.bridge.destroy(),delete o.iframe,delete o.iframeLoadPromise,delete o.bridge})),n(this,"onSuperAppToken",(function(e){if(e&&o.iframe){var n=o.iframe;o.destroy(),o.setup(n)}})),n(this,"handleMessage",(function(e){switch(e.handler){case K.INIT:o.handleInitApp().catch(console.error);break;case I.SUPERAPP_TOKEN:y._requestSuperAppToken();break;case I.AUTH_NEEDED:y._requestAuth();break;case I.OPEN_APP:y._openApp(e.params)}})),n(this,"handleInitApp",(function(){return Promise.resolve()})),n(this,"getProfileUrl",(function(){var e=y.get(),n=e.connectDomain,t=e.appId,i=e.superAppToken,a=e._debug,r=o.config.widgets,s=h({host_app_id:t,debug:a?"1":"",localhost:a?"1":"",superapp_token:i,widgets:r?r.join(","):""});return"https://".concat(n,"/super_profile?").concat(s)}))},R={OneTapAuthEventsSDK:P,FloatingOneTapAuthEventsSDK:N,ButtonOneTapAuthEventsSDK:C,DataPolicyEventsSDK:T,AuthCaptchaEventsSDK:D};export{y as Config,L as Connect,R as ConnectEvents,M as MiniApp,U as Profile};

@@ -1,17 +0,6 @@

export declare enum MiniAppHostEvents {
APP_CLOSE = "VKWebAppClose",
export declare enum MiniAppEvents {
APP_HIDE = "VKSDKMiniAppHide",
APP_READY = "VKSDKMiniAppReady",
RESIZE = "VKSDKMiniAppResize",
APP_INIT_CONFIG = "VKSDKMiniAppInitConfig",
OPEN_APP = "VKWebAppOpenApp",
OPEN_PAY_FORM = "VKWebAppOpenPayForm",
ACTION_DONE = "VKWebAppActionDone"
APP_INIT_CONFIG = "VKSDKMiniAppInitConfig"
}
export declare enum MiniAppEvents {
OPEN = "open",
HIDE = "hide",
CLOSE = "close",
SHOW = "show",
MESSAGE = "message",
CREATE_APP = "createapp"
}
import { Emitter } from 'mitt';
import { BridgeMessage } from '#/common/bridge';
import { MiniAppLoadParams } from './types';
export declare type MiniAppLoadParams = {
app: string | number;
zIndex?: number;
fullMode?: boolean;
};
declare type OpenMiniAppQuery = {
[index: string]: any;
};
export default class MiniApp {
readonly events: Emitter;
private iframe;

@@ -13,10 +18,8 @@ private bridge;

private readonly params;
private child;
readonly events: Emitter;
constructor(params: MiniAppLoadParams);
readonly open: (query?: Record<string, any> | undefined, hash?: string | undefined) => Promise<void>;
readonly open: (query?: OpenMiniAppQuery | undefined, hash?: string | undefined) => Promise<void>;
readonly hide: () => void;
readonly close: () => void;
readonly show: () => void;
readonly preload: (query?: Record<string, any> | undefined, hash?: string | undefined) => Promise<void>;
readonly sendMessage: (message: BridgeMessage<string>) => void;
readonly preload: (query?: OpenMiniAppQuery | undefined, hash?: string | undefined) => Promise<void>;
private readonly onSuperAppToken;

@@ -28,5 +31,3 @@ private readonly handleMessage;

private readonly resolveReadyPromise;
private readonly openMiniapp;
private readonly openPayForm;
private readonly handleVKPayFormMessage;
}
export {};
{
"name": "@vkontakte/superappkit",
"version": "1.11.0-beta-1",
"version": "1.11.0",
"description": "VK SuperAppKit",

@@ -14,3 +14,3 @@ "main": "dist/index-cjs.js",

"test": "karma start karma.config.js",
"lint": "eslint --cache \"./**/*.{ts,tsx}\"",
"lint": "eslint --cache './**/*.{ts,tsx}'",
"lint-staged": "lint-staged",

@@ -45,3 +45,2 @@ "clear": "rm -rf dist",

"@babel/preset-typescript": "^7.8.3",
"@babel/runtime": "^7.13.10",
"@rollup/plugin-alias": "^3.1.0",

@@ -86,5 +85,3 @@ "@rollup/plugin-babel": "^5.2.0",

},
"dependencies": {
"@vkontakte/vkjs": "^0.20.0"
}
"dependencies": {}
}
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc