@btsd/aitu-bridge 0.2.6 → 0.2.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ declare enum EInvokeRequest {
2
2
  getMe = "GetMe",
3
3
  getPhone = "GetPhone",
4
4
  getContacts = "GetContacts",
5
+ getUserProfile = "GetUserProfile",
5
6
  enableNotifications = "AllowNotifications",
6
7
  disableNotifications = "DisableNotifications"
7
8
  }
@@ -42,6 +43,13 @@ interface SelectContactResponse {
42
43
  name: string;
43
44
  lastname: string;
44
45
  }
46
+ interface GetUserProfileResponse {
47
+ name: string;
48
+ lastname?: string;
49
+ phone?: string;
50
+ avatar?: string;
51
+ avatarThumb?: string;
52
+ }
45
53
  declare type OpenSettingsResponse = 'success' | 'failed';
46
54
  declare type ShareResponse = 'success' | 'failed';
47
55
  declare type CopyToClipboardResponse = 'success' | 'failed';
@@ -62,6 +70,7 @@ interface AituBridge {
62
70
  selectContact: () => Promise<SelectContactResponse>;
63
71
  getQr: () => Promise<string>;
64
72
  getSMSCode: () => Promise<string>;
73
+ getUserProfile: (userId: string) => Promise<GetUserProfileResponse>;
65
74
  share: (text: string) => Promise<ShareResponse>;
66
75
  setTitle: (text: string) => Promise<ResponseType>;
67
76
  copyToClipboard: (text: string) => Promise<CopyToClipboardResponse>;
@@ -72,10 +81,13 @@ interface AituBridge {
72
81
  openSettings: () => Promise<OpenSettingsResponse>;
73
82
  closeApplication: () => Promise<ResponseType>;
74
83
  setShakeHandler: (handler: any) => void;
84
+ setTabActiveHandler: (handler: (tabname: string) => void) => void;
75
85
  vibrate: (pattern: number[]) => Promise<VibratePattern>;
76
86
  isSupported: () => boolean;
77
87
  supports: (method: string) => boolean;
78
88
  sub: any;
89
+ enableScreenCapture: () => Promise<{}>;
90
+ disableScreenCapture: () => Promise<{}>;
79
91
  }
80
92
  declare const bridge: AituBridge;
81
93
  export default bridge;
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- function e(e,n){var t,o,i=(t={current:0,next:function(){return++this.current}},o={},{add:function(e,n){var i=null!=n?n:t.next();return o[i]=e,i},resolve:function(e,n,t,i){var r=o[e];r&&(t(i)?r.resolve(n):r.reject(i),o[e]=null)}});return n(function(e){if(e.detail&&"reqId"in e.detail){var n=e.detail,t=n.reqId;t&&i.resolve(t,n.data,function(e){return!e},n.error)}}),function(){var n=arguments;return new Promise(function(t,o){var r=i.add({resolve:t,reject:o});e.apply(void 0,[r].concat([].slice.call(n)))})}}var n;!function(e){e.getMe="GetMe",e.getPhone="GetPhone",e.getContacts="GetContacts",e.enableNotifications="AllowNotifications",e.disableNotifications="DisableNotifications"}(n||(n={}));var t="invoke",o="storage",i="undefined"!=typeof window&&window.AndroidBridge,r="undefined"!=typeof window&&window.webkit&&window.webkit.messageHandlers,a="undefined"!=typeof window&&window.top!==window&&(window.WebBridge=window.WebBridge||{});if(a){var s=window.AITU_ORIGIN||"https://aitu.io";[t,o].forEach(function(e){a[e]||(a[e]=function(){return window.top.postMessage(JSON.stringify({method:e,payload:[].slice.call(arguments)}),s)})}),window.addEventListener("message",function(e){if(e.origin===s&&e.data)try{var n=JSON.parse(e.data);window.dispatchEvent(new CustomEvent("aituEvents",{detail:n}))}catch(e){}})}var d=function(){var s=[];"undefined"!=typeof window&&window.addEventListener("aituEvents",function(e){[].concat(s).map(function(n){return n.call(null,e)})});var d,c,l,u=function(e){s.push(e)},f=(d={current:0,next:function(){return++this.current}},c={},l={add:function(e,n){var t=null!=n?n:d.next();return c[t]=e,t},resolve:function(e,n,t,o){var i=c[e];i&&(t(o)?i.resolve(n):i.reject(o),c[e]=null)}},u(function(e){if(e.detail&&"reqId"in e.detail){var n=e.detail,t=n.reqId;t&&l.resolve(t,n.data,function(e){return!e},n.error)}}),function(e,n){return void 0===n&&(n={}),new Promise(function(o,s){!function(e,n,o){void 0===o&&(o={});var s=r&&r[t],d=a&&a[t];i&&i[t]?i[t](e,n,JSON.stringify(o)):s?r[t].postMessage({reqId:e,method:n,data:o}):d?a[t](e,n,o):"undefined"!=typeof window&&console.log("--invoke-isUnknown")}(l.add({resolve:o,reject:s},n.reqId),e,n)})}),g=function(e,n){var t,o,i=(t={current:0,next:function(){return++this.current}},o={},{add:function(e,n){var i="s"+(null!=n?n:t.next());return o[i]=e,i},resolve:function(e,n,t,i){var r=o[e];r&&(t(i)?r.resolve(n):r.reject(i),o[e]=null)}});return n(function(e){if(e.detail&&"reqId"in e.detail){var n=e.detail,t=n.reqId;t&&i.resolve(t,n.data,function(e){return!e},n.error)}}),{setItem:function(n,t){return new Promise(function(o,r){var a=i.add({resolve:o,reject:r});e(a,"setItem",{keyName:n,keyValue:t})})},getItem:function(n){return new Promise(function(t,o){var r=i.add({resolve:t,reject:o});e(r,"getItem",{keyName:n})})},clear:function(){return new Promise(function(n,t){var o=i.add({resolve:n,reject:t});e(o,"clear",{})})}}}(function(e,n,t){void 0===t&&(t={});var s=r&&r[o],d=a&&a[o];i&&i[o]?i[o](e,n,JSON.stringify(t)):s?r[o].postMessage({reqId:e,method:n,data:t}):d?a[o](e,n,t):"undefined"!=typeof window&&console.log("--storage-isUnknown")},u),p=e(function(e){var n=r&&r.getGeo;i&&i.getGeo?i.getGeo(e):n?r.getGeo.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getGeo-isWeb")},u),w=e(function(e){var n=r&&r.getQr;i&&i.getQr?i.getQr(e):n?r.getQr.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getQr-isWeb")},u),v=e(function(e){var n=r&&r.getSMSCode;i&&i.getSMSCode?i.getSMSCode(e):n?r.getSMSCode.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getSMSCode-isWeb")},u),b=e(function(e){var n=r&&r.selectContact;i&&i.selectContact?i.selectContact(e):n?r.selectContact.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--selectContact-isWeb")},u),h=e(function(e){var n=r&&r.openSettings;i&&i.openSettings?i.openSettings(e):n?r.openSettings.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--openSettings-isWeb")},u),y=e(function(e){var n=r&&r.closeApplication;i&&i.closeApplication?i.closeApplication(e):n?r.closeApplication.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--closeApplication-isWeb")},u),I=e(function(e,n){var t=r&&r.share;i&&i.share?i.share(e,n):t?r.share.postMessage({reqId:e,text:n}):"undefined"!=typeof window&&console.log("--share-isWeb")},u),S=e(function(e,n){var t=r&&r.setTitle;i&&i.setTitle?i.setTitle(e,n):t?r.setTitle.postMessage({reqId:e,text:n}):"undefined"!=typeof window&&console.log("--setTitle-isWeb")},u),m=e(function(e,n){var t=r&&r.copyToClipboard;i&&i.copyToClipboard?i.copyToClipboard(e,n):t?r.copyToClipboard.postMessage({reqId:e,text:n}):"undefined"!=typeof window&&console.log("--copyToClipboard-isWeb")},u),M=e(function(e,n,t){var o=r&&r.shareFile,a=t;i&&i.shareFile?i.shareFile(e,n,"image",a):o?r.shareFile.postMessage({reqId:e,text:n,filename:"image",base64Data:a}):"undefined"!=typeof window&&console.log("--shareFile-isWeb")},u),C=e(function(e,n,t,o){var a=r&&r.shareFile;i&&i.shareFile?i.shareFile(e,n,t,o):a?r.shareFile.postMessage({reqId:e,text:n,filename:t,base64Data:o}):"undefined"!=typeof window&&console.log("--shareFile-isWeb")},u),q=e(function(e,n){if(!Array.isArray(n)||n.some(function(e){return e<1||e!==Math.floor(e)})||n.reduce(function(e,n){return e+n})>1e4)console.error("Pattern should be an array of positive integers no longer than 10000ms total");else{var t=r&&r.vibrate;i&&i.vibrate?i.vibrate(e,JSON.stringify(n)):t?r.vibrate.postMessage({reqId:e,pattern:n}):"undefined"!=typeof window&&console.log("--vibrate-isWeb")}},u);return{copyToClipboard:m,invoke:f,storage:g,getMe:function(){return f(n.getMe)},getPhone:function(){return f(n.getPhone)},getContacts:function(){return f(n.getContacts)},getGeo:p,getQr:w,getSMSCode:v,selectContact:b,enableNotifications:function(){return f(n.enableNotifications)},disableNotifications:function(){return f(n.disableNotifications)},openSettings:h,closeApplication:y,setTitle:S,share:I,shareImage:M,shareFile:C,setShakeHandler:function(e){i&&i.setShakeHandler||r&&r.setShakeHandler?window.onAituBridgeShake=e:"undefined"!=typeof window&&console.log("--setShakeHandler-isWeb")},vibrate:q,isSupported:function(){var e=r&&window.webkit.messageHandlers.invoke;return Boolean(i||e||a)},supports:function(e){return i&&"function"==typeof i[e]||r&&r[e]&&"function"==typeof r[e].postMessage||a&&"function"==typeof a[e]},sub:u}}();module.exports=d;
1
+ function e(e,n){var t,o,i=(t={current:0,next:function(){return++this.current}},o={},{add:function(e,n){var i=null!=n?n:t.next();return o[i]=e,i},resolve:function(e,n,t,i){var r=o[e];r&&(t(i)?r.resolve(n):r.reject(i),o[e]=null)}});return n(function(e){if(e.detail&&"reqId"in e.detail){var n=e.detail,t=n.reqId;t&&i.resolve(t,n.data,function(e){return!e},n.error)}}),function(){var n=arguments;return new Promise(function(t,o){var r=i.add({resolve:t,reject:o});e.apply(void 0,[r].concat([].slice.call(n)))})}}var n;!function(e){e.getMe="GetMe",e.getPhone="GetPhone",e.getContacts="GetContacts",e.getUserProfile="GetUserProfile",e.enableNotifications="AllowNotifications",e.disableNotifications="DisableNotifications"}(n||(n={}));var t="invoke",o="storage",i="undefined"!=typeof window&&window.AndroidBridge,r="undefined"!=typeof window&&window.webkit&&window.webkit.messageHandlers,a="undefined"!=typeof window&&window.top!==window&&(window.WebBridge=window.WebBridge||{});if(a){var s=window.AITU_ORIGIN||"https://aitu.io";[t,o].forEach(function(e){a[e]||(a[e]=function(){return window.top.postMessage(JSON.stringify({method:e,payload:[].slice.call(arguments)}),s)})}),window.addEventListener("message",function(e){if(e.origin===s&&e.data)try{var n=JSON.parse(e.data);window.dispatchEvent(new CustomEvent("aituEvents",{detail:n}))}catch(e){}})}var d=function(){var s=[];"undefined"!=typeof window&&window.addEventListener("aituEvents",function(e){[].concat(s).map(function(n){return n.call(null,e)})});var d,l,c,u=function(e){s.push(e)},f=(d={current:0,next:function(){return++this.current}},l={},c={add:function(e,n){var t=null!=n?n:d.next();return l[t]=e,t},resolve:function(e,n,t,o){var i=l[e];i&&(t(o)?i.resolve(n):i.reject(o),l[e]=null)}},u(function(e){if(e.detail&&"reqId"in e.detail){var n=e.detail,t=n.reqId;t&&c.resolve(t,n.data,function(e){return!e},n.error)}}),function(e,n){return void 0===n&&(n={}),new Promise(function(o,s){!function(e,n,o){void 0===o&&(o={});var s=r&&r[t],d=a&&a[t];i&&i[t]?i[t](e,n,JSON.stringify(o)):s?r[t].postMessage({reqId:e,method:n,data:o}):d?a[t](e,n,o):"undefined"!=typeof window&&console.log("--invoke-isUnknown")}(c.add({resolve:o,reject:s},n.reqId),e,n)})}),p=function(e,n){var t,o,i=(t={current:0,next:function(){return++this.current}},o={},{add:function(e,n){var i="s"+(null!=n?n:t.next());return o[i]=e,i},resolve:function(e,n,t,i){var r=o[e];r&&(t(i)?r.resolve(n):r.reject(i),o[e]=null)}});return n(function(e){if(e.detail&&"reqId"in e.detail){var n=e.detail,t=n.reqId;t&&i.resolve(t,n.data,function(e){return!e},n.error)}}),{setItem:function(n,t){return new Promise(function(o,r){var a=i.add({resolve:o,reject:r});e(a,"setItem",{keyName:n,keyValue:t})})},getItem:function(n){return new Promise(function(t,o){var r=i.add({resolve:t,reject:o});e(r,"getItem",{keyName:n})})},clear:function(){return new Promise(function(n,t){var o=i.add({resolve:n,reject:t});e(o,"clear",{})})}}}(function(e,n,t){void 0===t&&(t={});var s=r&&r[o],d=a&&a[o];i&&i[o]?i[o](e,n,JSON.stringify(t)):s?r[o].postMessage({reqId:e,method:n,data:t}):d?a[o](e,n,t):"undefined"!=typeof window&&console.log("--storage-isUnknown")},u),g=e(function(e){var n=r&&r.getGeo;i&&i.getGeo?i.getGeo(e):n?r.getGeo.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getGeo-isWeb")},u),w=e(function(e){var n=r&&r.getQr;i&&i.getQr?i.getQr(e):n?r.getQr.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getQr-isWeb")},u),v=e(function(e){var n=r&&r.getSMSCode;i&&i.getSMSCode?i.getSMSCode(e):n?r.getSMSCode.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getSMSCode-isWeb")},u),b=e(function(e){var n=r&&r.selectContact;i&&i.selectContact?i.selectContact(e):n?r.selectContact.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--selectContact-isWeb")},u),h=e(function(e){var n=r&&r.openSettings;i&&i.openSettings?i.openSettings(e):n?r.openSettings.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--openSettings-isWeb")},u),y=e(function(e){var n=r&&r.closeApplication;i&&i.closeApplication?i.closeApplication(e):n?r.closeApplication.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--closeApplication-isWeb")},u),S=e(function(e,n){var t=r&&r.share;i&&i.share?i.share(e,n):t?r.share.postMessage({reqId:e,text:n}):"undefined"!=typeof window&&console.log("--share-isWeb")},u),M=e(function(e,n){var t=r&&r.setTitle;i&&i.setTitle?i.setTitle(e,n):t?r.setTitle.postMessage({reqId:e,text:n}):"undefined"!=typeof window&&console.log("--setTitle-isWeb")},u),C=e(function(e,n){var t=r&&r.copyToClipboard;i&&i.copyToClipboard?i.copyToClipboard(e,n):t?r.copyToClipboard.postMessage({reqId:e,text:n}):"undefined"!=typeof window&&console.log("--copyToClipboard-isWeb")},u),I=e(function(e,n,t){var o=i&&i.shareFile,a=r&&r.shareFile,s="image."+t.split(";")[0].split("/")[1],d=t.substr(t.indexOf(",")+1);o?i.shareFile(e,n,s,d):a?r.shareFile.postMessage({reqId:e,text:n,filename:s,base64Data:d}):"undefined"!=typeof window&&console.log("--shareFile-isWeb")},u),m=e(function(e,n,t,o){var a=r&&r.shareFile;i&&i.shareFile?i.shareFile(e,n,t,o):a?r.shareFile.postMessage({reqId:e,text:n,filename:t,base64Data:o}):"undefined"!=typeof window&&console.log("--shareFile-isWeb")},u),q=e(function(e,n){if(!Array.isArray(n)||n.some(function(e){return e<1||e!==Math.floor(e)})||n.reduce(function(e,n){return e+n})>1e4)console.error("Pattern should be an array of positive integers no longer than 10000ms total");else{var t=r&&r.vibrate;i&&i.vibrate?i.vibrate(e,JSON.stringify(n)):t?r.vibrate.postMessage({reqId:e,pattern:n}):"undefined"!=typeof window&&console.log("--vibrate-isWeb")}},u),A=e(function(){var e=r&&r.enableScreenCaptureMethod;i&&i.enableScreenCaptureMethod?i.enableScreenCaptureMethod():e?r.enableScreenCaptureMethod.postMessage({}):"undefined"!=typeof window&&console.log("--enableScreenCapture-isWeb")},u),T=e(function(){var e=r&&r.disableScreenCaptureMethod;i&&i.disableScreenCaptureMethod?i.disableScreenCaptureMethod():e?r.disableScreenCaptureMethod.postMessage({}):"undefined"!=typeof window&&console.log("--disableScreenCapture-isWeb")},u);return{copyToClipboard:C,invoke:f,storage:p,getMe:function(){return f(n.getMe)},getPhone:function(){return f(n.getPhone)},getContacts:function(){return f(n.getContacts)},getGeo:g,getQr:w,getSMSCode:v,getUserProfile:function(e){return f(n.getUserProfile,{id:e})},selectContact:b,enableNotifications:function(){return f(n.enableNotifications)},disableNotifications:function(){return f(n.disableNotifications)},openSettings:h,closeApplication:y,setTitle:M,share:S,shareImage:I,shareFile:m,setShakeHandler:function(e){i&&i.setShakeHandler||r&&r.setShakeHandler?window.onAituBridgeShake=e:"undefined"!=typeof window&&console.log("--setShakeHandler-isWeb")},setTabActiveHandler:function(e){i&&i.setTabActiveHandler||r&&r.setTabActiveHandler?window.onAituBridgeTabActive=e:"undefined"!=typeof window&&console.log("--setTabActiveHandler-isWeb")},vibrate:q,isSupported:function(){var e=r&&window.webkit.messageHandlers.invoke;return Boolean(i||e||a)},supports:function(e){return i&&"function"==typeof i[e]||r&&r[e]&&"function"==typeof r[e].postMessage||a&&"function"==typeof a[e]},sub:u,enableScreenCapture:A,disableScreenCapture:T}}();module.exports=d;
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/promisifyMethod.ts","../src/index.ts","../src/promisifyInvoke.ts","../src/promisifyStorage.ts"],"sourcesContent":["function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n}\n\nfunction createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n\n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n\n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const methodId = id;\n promiseControllers[methodId] = controller;\n return methodId;\n },\n\n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n\n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n\n promiseControllers[reqId] = null;\n }\n },\n };\n}\n\nfunction promisifyMethod(method, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n\n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n\n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n\n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return function promisifiedFunc(...args: any[]): Promise<any | void> {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n\n method(reqId, ...args);\n });\n };\n}\n\nexport default promisifyMethod;\n","import promisifyInvoke from './promisifyInvoke';\nimport promisifyStorage from './promisifyStorage';\nimport promisifyMethod from './promisifyMethod';\n\nenum EInvokeRequest {\n getMe = 'GetMe',\n getPhone = 'GetPhone',\n getContacts = 'GetContacts',\n enableNotifications = 'AllowNotifications',\n disableNotifications = 'DisableNotifications'\n}\n\ntype SetItemType = (keyName: string, keyValue: string) => Promise<void>;\ntype GetItemType = (keyName: string) => Promise<string | null>;\ntype ClearType = () => Promise<void>;\n\ninterface GetPhoneResponse {\n phone: string;\n sign: string;\n}\n\ninterface GetMeResponse {\n name: string;\n lastname: string;\n id: string;\n avatar?: string;\n avatarThumb?: string;\n sign: string;\n}\n\ninterface ResponseObject {\n phone?: string;\n name?: string;\n lastname?: string;\n}\n\ninterface GetGeoResponse {\n latitude: number;\n longitude: number;\n}\n\ninterface GetContactsResponse {\n contacts: Array<{\n first_name: string;\n last_name: string;\n phone: string;\n }>;\n sign: string;\n}\n\ninterface SelectContactResponse {\n phone: string;\n name: string;\n lastname: string;\n}\n\ntype OpenSettingsResponse = 'success' | 'failed';\ntype ShareResponse = 'success' | 'failed';\ntype CopyToClipboardResponse = 'success' | 'failed';\ntype VibrateResponse = 'success' | 'failed';\n// todo: remove duplicates\ntype ResponseType = 'success' | 'failed';\n\ntype BridgeInvoke<T extends EInvokeRequest, R> = (method: T, data?: {}) => Promise<R>;\n\ninterface BridgeStorage {\n setItem: SetItemType,\n getItem: GetItemType,\n clear: ClearType\n}\n\ninterface AituBridge {\n invoke: BridgeInvoke<EInvokeRequest, ResponseObject>;\n storage: BridgeStorage;\n getMe: () => Promise<GetMeResponse>;\n getPhone: () => Promise<GetPhoneResponse>;\n getContacts: () => Promise<GetContactsResponse>;\n getGeo: () => Promise<GetGeoResponse>;\n selectContact: () => Promise<SelectContactResponse>;\n getQr: () => Promise<string>;\n getSMSCode: () => Promise<string>;\n share: (text: string) => Promise<ShareResponse>;\n setTitle: (text: string) => Promise<ResponseType>;\n copyToClipboard: (text: string) => Promise<CopyToClipboardResponse>;\n shareImage: (text: string, image: string) => Promise<ShareResponse>;\n shareFile: (text: string, filename: string, base64Data: string) => Promise<ShareResponse>;\n enableNotifications: () => Promise<{}>;\n disableNotifications: () => Promise<{}>;\n openSettings: () => Promise<OpenSettingsResponse>;\n closeApplication: () => Promise<ResponseType>;\n setShakeHandler: (handler: any) => void;\n vibrate: (pattern: number[]) => Promise<VibratePattern>;\n isSupported: () => boolean;\n supports: (method: string) => boolean;\n sub: any;\n}\n\nconst invokeMethod = 'invoke';\nconst storageMethod = 'storage';\nconst getGeoMethod = 'getGeo';\nconst getQrMethod = 'getQr';\nconst getSMSCodeMethod = 'getSMSCode';\nconst selectContactMethod = 'selectContact';\nconst openSettingsMethod = 'openSettings';\nconst closeApplicationMethod = 'closeApplication';\nconst shareMethod = 'share';\nconst setTitleMethod = 'setTitle';\nconst copyToClipboardMethod = 'copyToClipboard';\nconst shareImageMethod = 'shareImage';\nconst shareFileMethod = 'shareFile';\nconst setShakeHandlerMethod = 'setShakeHandler';\nconst vibrateMethod = 'vibrate';\n\nconst android = typeof window !== 'undefined' && (window as any).AndroidBridge;\nconst ios = typeof window !== 'undefined' && (window as any).webkit && (window as any).webkit.messageHandlers;\nconst web = typeof window !== 'undefined' && (window.top !== window) && ((window as any).WebBridge = (window as any).WebBridge || {});\n\nif (web) {\n const aituOrigin = (window as any).AITU_ORIGIN || 'https://aitu.io';\n\n [invokeMethod, storageMethod].forEach((method) => {\n if (!web[method]) {\n web[method] = (...args) => window.top.postMessage(JSON.stringify({\n method,\n payload: args,\n }), aituOrigin);\n }\n });\n\n window.addEventListener('message', (event) => {\n if (event.origin === aituOrigin && event.data) {\n try {\n const detail = JSON.parse(event.data);\n window.dispatchEvent(new CustomEvent('aituEvents', { detail }));\n } catch(e) {}\n }\n });\n}\n\nconst buildBridge = (): AituBridge => {\n const subs = [];\n\n if (typeof window !== 'undefined') {\n window.addEventListener('aituEvents', (e: any) => {\n [...subs].map((fn) => fn.call(null, e));\n })\n }\n\n const invoke = (reqId, method, data = {}) => {\n const isAndroid = android && android[invokeMethod];\n const isIos = ios && ios[invokeMethod];\n const isWeb = web && web[invokeMethod];\n\n if (isAndroid) {\n android[invokeMethod](reqId, method, JSON.stringify(data));\n } else if (isIos) {\n ios[invokeMethod].postMessage({ reqId, method, data });\n } else if (isWeb) {\n web[invokeMethod](reqId, method, data);\n } else if (typeof window !== 'undefined') {\n console.log('--invoke-isUnknown');\n }\n };\n\n const storage = (reqId, method, data = {}) => {\n const isAndroid = android && android[storageMethod];\n const isIos = ios && ios[storageMethod];\n const isWeb = web && web[storageMethod];\n\n if (isAndroid) {\n android[storageMethod](reqId, method, JSON.stringify(data));\n } else if (isIos) {\n ios[storageMethod].postMessage({ reqId, method, data });\n } else if (isWeb) {\n web[storageMethod](reqId, method, data);\n } else if (typeof window !== 'undefined') {\n console.log('--storage-isUnknown');\n }\n }\n\n const getGeo = (reqId) => {\n const isAndroid = android && android[getGeoMethod];\n const isIos = ios && ios[getGeoMethod];\n\n if (isAndroid) {\n android[getGeoMethod](reqId);\n } else if (isIos) {\n ios[getGeoMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getGeo-isWeb');\n }\n }\n\n const getQr = (reqId) => {\n const isAndroid = android && android[getQrMethod];\n const isIos = ios && ios[getQrMethod];\n\n if (isAndroid) {\n android[getQrMethod](reqId);\n } else if (isIos) {\n ios[getQrMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getQr-isWeb');\n }\n }\n\n const getSMSCode = (reqId) => {\n const isAndroid = android && android[getSMSCodeMethod];\n const isIos = ios && ios[getSMSCodeMethod];\n\n if (isAndroid) {\n android[getSMSCodeMethod](reqId);\n } else if (isIos) {\n ios[getSMSCodeMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getSMSCode-isWeb');\n }\n }\n\n const selectContact = (reqId) => {\n const isAndroid = android && android[selectContactMethod];\n const isIos = ios && ios[selectContactMethod];\n\n if (isAndroid) {\n android[selectContactMethod](reqId);\n } else if (isIos) {\n ios[selectContactMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--selectContact-isWeb');\n }\n }\n\n const openSettings = (reqId) => {\n const isAndroid = android && android[openSettingsMethod];\n const isIos = ios && ios[openSettingsMethod];\n\n if (isAndroid) {\n android[openSettingsMethod](reqId);\n } else if (isIos) {\n ios[openSettingsMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--openSettings-isWeb');\n }\n }\n\n const closeApplication = (reqId) => {\n const isAndroid = android && android[closeApplicationMethod];\n const isIos = ios && ios[closeApplicationMethod];\n\n if (isAndroid) {\n android[closeApplicationMethod](reqId);\n } else if (isIos) {\n ios[closeApplicationMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--closeApplication-isWeb');\n }\n }\n\n const share = (reqId, text) => {\n const isAndroid = android && android[shareMethod];\n const isIos = ios && ios[shareMethod];\n\n if (isAndroid) {\n android[shareMethod](reqId, text);\n } else if (isIos) {\n ios[shareMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--share-isWeb');\n }\n }\n\n const setTitle = (reqId, text) => {\n const isAndroid = android && android[setTitleMethod];\n const isIos = ios && ios[setTitleMethod];\n\n if (isAndroid) {\n android[setTitleMethod](reqId, text);\n } else if (isIos) {\n ios[setTitleMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--setTitle-isWeb');\n }\n }\n\n const copyToClipboard = (reqId, text) => {\n const isAndroid = android && android[copyToClipboardMethod];\n const isIos = ios && ios[copyToClipboardMethod];\n\n if (isAndroid) {\n android[copyToClipboardMethod](reqId, text);\n } else if (isIos) {\n ios[copyToClipboardMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--copyToClipboard-isWeb');\n }\n }\n\n const shareImage = (reqId, text, image) => {\n // !!!======================!!!\n // !!!===== Deprecated =====!!!\n // !!!======================!!!\n\n // const isAndroid = android && android[shareImageMethod];\n // const isIos = ios && ios[shareImageMethod];\n\n // if (isAndroid) {\n // android[shareImageMethod](reqId, text, image);\n // } else if (isIos) {\n // ios[shareImageMethod].postMessage({ reqId, text, image });\n // } else if (typeof window !== 'undefined') {\n // console.log('--shareImage-isWeb');\n // }\n\n // new one - fallback to shareFile\n const isAndroid = android && android[shareFileMethod];\n const isIos = ios && ios[shareFileMethod];\n\n const filename = 'image';\n const base64Data = image;\n\n if (isAndroid) {\n android[shareFileMethod](reqId, text, filename, base64Data);\n } else if (isIos) {\n ios[shareFileMethod].postMessage({ reqId, text, filename, base64Data });\n } else if (typeof window !== 'undefined') {\n console.log('--shareFile-isWeb');\n }\n }\n\n const shareFile = (reqId, text, filename, base64Data) => {\n const isAndroid = android && android[shareFileMethod];\n const isIos = ios && ios[shareFileMethod];\n\n if (isAndroid) {\n android[shareFileMethod](reqId, text, filename, base64Data);\n } else if (isIos) {\n ios[shareFileMethod].postMessage({ reqId, text, filename, base64Data });\n } else if (typeof window !== 'undefined') {\n console.log('--shareFile-isWeb');\n }\n }\n\n const enableNotifications = () => invokePromise(EInvokeRequest.enableNotifications);\n\n const disableNotifications = () => invokePromise(EInvokeRequest.disableNotifications);\n\n const setShakeHandler = (handler) => {\n const isAndroid = android && android[setShakeHandlerMethod];\n const isIos = ios && ios[setShakeHandlerMethod];\n\n if (isAndroid || isIos) {\n (window as any).onAituBridgeShake = handler;\n } else if (typeof window !== 'undefined') {\n console.log('--setShakeHandler-isWeb');\n }\n };\n\n const vibrate = (reqId, pattern) => {\n if (\n !Array.isArray(pattern) ||\n pattern.some((timing) => timing < 1 || timing !== Math.floor(timing)) ||\n pattern.reduce((total, timing) => total + timing) > 10000\n ) {\n console.error('Pattern should be an array of positive integers no longer than 10000ms total');\n return;\n }\n\n const isAndroid = android && android[vibrateMethod];\n const isIos = ios && ios[vibrateMethod];\n\n if (isAndroid) {\n android[vibrateMethod](reqId, JSON.stringify(pattern));\n } else if (isIos) {\n ios[vibrateMethod].postMessage({ reqId, pattern });\n } else if (typeof window !== 'undefined') {\n console.log('--vibrate-isWeb');\n }\n }\n\n const isSupported = () => {\n const iosSup = ios && (window as any).webkit.messageHandlers.invoke;\n return Boolean(android || iosSup || web);\n }\n\n const supports = (method) =>\n (android && typeof android[method] === 'function') ||\n (ios && ios[method] && typeof ios[method].postMessage === 'function') ||\n (web && typeof web[method] === 'function');\n\n const sub = (listener: any) => {\n subs.push(listener);\n }\n\n const invokePromise = promisifyInvoke(invoke, sub);\n const storagePromise = promisifyStorage(storage, sub);\n const getGeoPromise = promisifyMethod(getGeo, sub);\n const getQrPromise = promisifyMethod(getQr, sub);\n const getSMSCodePromise = promisifyMethod(getSMSCode, sub);\n const selectContactPromise = promisifyMethod(selectContact, sub);\n const openSettingsPromise = promisifyMethod(openSettings, sub);\n const closeApplicationPromise = promisifyMethod(closeApplication, sub);\n const sharePromise = promisifyMethod(share, sub);\n const setTitlePromise = promisifyMethod(setTitle, sub);\n const copyToClipboardPromise = promisifyMethod(copyToClipboard, sub);\n const shareImagePromise = promisifyMethod(shareImage, sub);\n const shareFilePromise = promisifyMethod(shareFile, sub);\n const vibratePromise = promisifyMethod(vibrate, sub);\n\n return {\n copyToClipboard: copyToClipboardPromise,\n invoke: invokePromise,\n storage: storagePromise,\n getMe: () => invokePromise(EInvokeRequest.getMe),\n getPhone: () => invokePromise(EInvokeRequest.getPhone),\n getContacts: () => invokePromise(EInvokeRequest.getContacts),\n getGeo: getGeoPromise,\n getQr: getQrPromise,\n getSMSCode: getSMSCodePromise,\n selectContact: selectContactPromise,\n enableNotifications,\n disableNotifications,\n openSettings: openSettingsPromise,\n closeApplication: closeApplicationPromise,\n setTitle: setTitlePromise,\n share: sharePromise,\n shareImage: shareImagePromise,\n shareFile: shareFilePromise,\n setShakeHandler,\n vibrate: vibratePromise,\n isSupported,\n supports,\n sub\n }\n}\n\nconst bridge = buildBridge();\n\nexport default bridge;\n","function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n}\n\nfunction createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n\n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n\n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const invokeId = id;\n promiseControllers[invokeId] = controller;\n return invokeId;\n },\n\n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n\n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n\n promiseControllers[reqId] = null;\n }\n },\n };\n}\n\nfunction promisifyInvoke(invoke, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n\n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n\n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n\n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return function promisifiedFunc(method: any, props: any = {}): Promise<any | void> {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject }, props.reqId);\n\n invoke(reqId, method, props);\n });\n };\n}\n\nexport default promisifyInvoke;\n","function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n }\n \n function createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n \n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n \n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const storageId = `s${id}`;\n promiseControllers[storageId] = controller;\n return storageId;\n },\n \n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n \n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n \n promiseControllers[reqId] = null;\n }\n },\n };\n }\n \n function promisifyStorage(storage, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n \n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n \n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n \n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return {\n setItem: (keyName: string, keyValue: string): Promise<void> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'setItem', { keyName, keyValue });\n });\n },\n getItem: (keyName: string): Promise<string | null> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'getItem', { keyName });\n });\n },\n clear: (): Promise<void> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'clear', {});\n });\n },\n }\n }\n \n export default promisifyStorage;\n "],"names":["promisifyMethod","method","subscribe","counter","promiseControllers","requestResolver","current","next","this","add","controller","customId","methodId","resolve","reqId","data","isSuccess","error","requestPromise","reject","event","detail","Promise","EInvokeRequest","invokeMethod","storageMethod","android","window","AndroidBridge","ios","webkit","messageHandlers","web","top","WebBridge","aituOrigin","AITU_ORIGIN","forEach","postMessage","JSON","stringify","payload","addEventListener","origin","parse","dispatchEvent","CustomEvent","e","bridge","subs","map","fn","call","sub","listener","push","invokePromise","invokeId","props","isIos","isWeb","console","log","invoke","storagePromise","storage","storageId","setItem","keyName","keyValue","getItem","clear","promisifyStorage","getGeoPromise","getQrPromise","getSMSCodePromise","selectContactPromise","openSettingsPromise","closeApplicationPromise","sharePromise","text","setTitlePromise","copyToClipboardPromise","shareImagePromise","image","base64Data","filename","shareFilePromise","vibratePromise","pattern","Array","isArray","some","timing","Math","floor","reduce","total","copyToClipboard","getMe","getPhone","getContacts","getGeo","getQr","getSMSCode","selectContact","enableNotifications","disableNotifications","openSettings","closeApplication","setTitle","share","shareImage","shareFile","setShakeHandler","handler","onAituBridgeShake","vibrate","isSupported","iosSup","Boolean","supports","buildBridge"],"mappings":"AA0CA,SAASA,EAAgBC,EAAQC,GAC/B,IA5BMC,EACAC,EA2BAC,GA5BAF,EAdC,CACLG,QAAS,EACTC,gBACE,QAASC,KAAKF,UAYZF,EAA+D,GAE9D,CACLK,aAAIC,EAA+BC,GACjC,IACMC,EADiB,MAAZD,EAAmBA,EAAWR,EAAQI,OAGjD,OADAH,EAAmBQ,GAAYF,EACxBE,GAGTC,iBAAWC,EAAwBC,EAASC,EAAiCC,GAC3E,IAAMC,EAAiBd,EAAmBU,GAEtCI,I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D,QAAS7B,EACT8B,YAlDkB,WAClB,IAAMC,EAAS1F,GAAQF,OAAeG,OAAOC,gBAAgBgC,OAC7D,OAAOyD,QAAQ9F,GAAW6F,GAAUvF,IAiDpCyF,SA9Ce,SAACxH,UACfyB,GAAsC,mBAApBA,EAAQzB,IAC1B4B,GAAOA,EAAI5B,IAA8C,mBAA5B4B,EAAI5B,GAAQqC,aACzCN,GAA8B,mBAAhBA,EAAI/B,IA4CnBoD,IAAAA,GAIWqE"}
1
+ {"version":3,"file":"index.js","sources":["../src/promisifyMethod.ts","../src/index.ts","../src/promisifyInvoke.ts","../src/promisifyStorage.ts"],"sourcesContent":["function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n}\n\nfunction createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n\n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n\n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const methodId = id;\n promiseControllers[methodId] = controller;\n return methodId;\n },\n\n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n\n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n\n promiseControllers[reqId] = null;\n }\n },\n };\n}\n\nfunction promisifyMethod(method, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n\n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n\n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n\n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return function promisifiedFunc(...args: any[]): Promise<any | void> {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n\n method(reqId, ...args);\n });\n };\n}\n\nexport default promisifyMethod;\n","import promisifyInvoke from './promisifyInvoke';\nimport promisifyStorage from './promisifyStorage';\nimport promisifyMethod from './promisifyMethod';\n\nenum EInvokeRequest {\n getMe = 'GetMe',\n getPhone = 'GetPhone',\n getContacts = 'GetContacts',\n getUserProfile = 'GetUserProfile',\n enableNotifications = 'AllowNotifications',\n disableNotifications = 'DisableNotifications'\n}\n\ntype SetItemType = (keyName: string, keyValue: string) => Promise<void>;\ntype GetItemType = (keyName: string) => Promise<string | null>;\ntype ClearType = () => Promise<void>;\n\ninterface GetPhoneResponse {\n phone: string;\n sign: string;\n}\n\ninterface GetMeResponse {\n name: string;\n lastname: string;\n id: string;\n avatar?: string;\n avatarThumb?: string;\n sign: string;\n}\n\ninterface ResponseObject {\n phone?: string;\n name?: string;\n lastname?: string;\n}\n\ninterface GetGeoResponse {\n latitude: number;\n longitude: number;\n}\n\ninterface GetContactsResponse {\n contacts: Array<{\n first_name: string;\n last_name: string;\n phone: string;\n }>;\n sign: string;\n}\n\ninterface SelectContactResponse {\n phone: string;\n name: string;\n lastname: string;\n}\n\ninterface GetUserProfileResponse {\n name: string;\n lastname?: string;\n phone?: string;\n avatar?: string;\n avatarThumb?: string;\n}\n\ntype OpenSettingsResponse = 'success' | 'failed';\ntype ShareResponse = 'success' | 'failed';\ntype CopyToClipboardResponse = 'success' | 'failed';\ntype VibrateResponse = 'success' | 'failed';\n// todo: remove duplicates\ntype ResponseType = 'success' | 'failed';\n\ntype BridgeInvoke<T extends EInvokeRequest, R> = (method: T, data?: {}) => Promise<R>;\n\ninterface BridgeStorage {\n setItem: SetItemType,\n getItem: GetItemType,\n clear: ClearType\n}\n\ninterface AituBridge {\n invoke: BridgeInvoke<EInvokeRequest, ResponseObject>;\n storage: BridgeStorage;\n getMe: () => Promise<GetMeResponse>;\n getPhone: () => Promise<GetPhoneResponse>;\n getContacts: () => Promise<GetContactsResponse>;\n getGeo: () => Promise<GetGeoResponse>;\n selectContact: () => Promise<SelectContactResponse>;\n getQr: () => Promise<string>;\n getSMSCode: () => Promise<string>;\n getUserProfile: (userId: string) => Promise<GetUserProfileResponse>;\n share: (text: string) => Promise<ShareResponse>;\n setTitle: (text: string) => Promise<ResponseType>;\n copyToClipboard: (text: string) => Promise<CopyToClipboardResponse>;\n shareImage: (text: string, image: string) => Promise<ShareResponse>;\n shareFile: (text: string, filename: string, base64Data: string) => Promise<ShareResponse>;\n enableNotifications: () => Promise<{}>;\n disableNotifications: () => Promise<{}>;\n openSettings: () => Promise<OpenSettingsResponse>;\n closeApplication: () => Promise<ResponseType>;\n setShakeHandler: (handler: any) => void;\n setTabActiveHandler: (handler: (tabname: string) => void) => void;\n vibrate: (pattern: number[]) => Promise<VibratePattern>;\n isSupported: () => boolean;\n supports: (method: string) => boolean;\n sub: any;\n enableScreenCapture: () => Promise<{}>;\n disableScreenCapture: () => Promise<{}>;\n}\n\nconst invokeMethod = 'invoke';\nconst storageMethod = 'storage';\nconst getGeoMethod = 'getGeo';\nconst getQrMethod = 'getQr';\nconst getSMSCodeMethod = 'getSMSCode';\nconst selectContactMethod = 'selectContact';\nconst openSettingsMethod = 'openSettings';\nconst closeApplicationMethod = 'closeApplication';\nconst shareMethod = 'share';\nconst setTitleMethod = 'setTitle';\nconst copyToClipboardMethod = 'copyToClipboard';\nconst shareImageMethod = 'shareImage';\nconst shareFileMethod = 'shareFile';\nconst setShakeHandlerMethod = 'setShakeHandler';\nconst vibrateMethod = 'vibrate';\nconst enableScreenCaptureMethod = 'enableScreenCaptureMethod';\nconst disableScreenCaptureMethod = 'disableScreenCaptureMethod';\nconst setTabActiveHandlerMethod = 'setTabActiveHandler';\n\nconst android = typeof window !== 'undefined' && (window as any).AndroidBridge;\nconst ios = typeof window !== 'undefined' && (window as any).webkit && (window as any).webkit.messageHandlers;\nconst web = typeof window !== 'undefined' && (window.top !== window) && ((window as any).WebBridge = (window as any).WebBridge || {});\n\nif (web) {\n const aituOrigin = (window as any).AITU_ORIGIN || 'https://aitu.io';\n\n [invokeMethod, storageMethod].forEach((method) => {\n if (!web[method]) {\n web[method] = (...args) => window.top.postMessage(JSON.stringify({\n method,\n payload: args,\n }), aituOrigin);\n }\n });\n\n window.addEventListener('message', (event) => {\n if (event.origin === aituOrigin && event.data) {\n try {\n const detail = JSON.parse(event.data);\n window.dispatchEvent(new CustomEvent('aituEvents', { detail }));\n } catch (e) { }\n }\n });\n}\n\nconst buildBridge = (): AituBridge => {\n const subs = [];\n\n if (typeof window !== 'undefined') {\n window.addEventListener('aituEvents', (e: any) => {\n [...subs].map((fn) => fn.call(null, e));\n })\n }\n\n const invoke = (reqId, method, data = {}) => {\n const isAndroid = android && android[invokeMethod];\n const isIos = ios && ios[invokeMethod];\n const isWeb = web && web[invokeMethod];\n\n if (isAndroid) {\n android[invokeMethod](reqId, method, JSON.stringify(data));\n } else if (isIos) {\n ios[invokeMethod].postMessage({ reqId, method, data });\n } else if (isWeb) {\n web[invokeMethod](reqId, method, data);\n } else if (typeof window !== 'undefined') {\n console.log('--invoke-isUnknown');\n }\n };\n\n const storage = (reqId, method, data = {}) => {\n const isAndroid = android && android[storageMethod];\n const isIos = ios && ios[storageMethod];\n const isWeb = web && web[storageMethod];\n\n if (isAndroid) {\n android[storageMethod](reqId, method, JSON.stringify(data));\n } else if (isIos) {\n ios[storageMethod].postMessage({ reqId, method, data });\n } else if (isWeb) {\n web[storageMethod](reqId, method, data);\n } else if (typeof window !== 'undefined') {\n console.log('--storage-isUnknown');\n }\n }\n\n const getGeo = (reqId) => {\n const isAndroid = android && android[getGeoMethod];\n const isIos = ios && ios[getGeoMethod];\n\n if (isAndroid) {\n android[getGeoMethod](reqId);\n } else if (isIos) {\n ios[getGeoMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getGeo-isWeb');\n }\n }\n\n const getQr = (reqId) => {\n const isAndroid = android && android[getQrMethod];\n const isIos = ios && ios[getQrMethod];\n\n if (isAndroid) {\n android[getQrMethod](reqId);\n } else if (isIos) {\n ios[getQrMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getQr-isWeb');\n }\n }\n\n const getSMSCode = (reqId) => {\n const isAndroid = android && android[getSMSCodeMethod];\n const isIos = ios && ios[getSMSCodeMethod];\n\n if (isAndroid) {\n android[getSMSCodeMethod](reqId);\n } else if (isIos) {\n ios[getSMSCodeMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getSMSCode-isWeb');\n }\n }\n\n const selectContact = (reqId) => {\n const isAndroid = android && android[selectContactMethod];\n const isIos = ios && ios[selectContactMethod];\n\n if (isAndroid) {\n android[selectContactMethod](reqId);\n } else if (isIos) {\n ios[selectContactMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--selectContact-isWeb');\n }\n }\n\n const openSettings = (reqId) => {\n const isAndroid = android && android[openSettingsMethod];\n const isIos = ios && ios[openSettingsMethod];\n\n if (isAndroid) {\n android[openSettingsMethod](reqId);\n } else if (isIos) {\n ios[openSettingsMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--openSettings-isWeb');\n }\n }\n\n const closeApplication = (reqId) => {\n const isAndroid = android && android[closeApplicationMethod];\n const isIos = ios && ios[closeApplicationMethod];\n\n if (isAndroid) {\n android[closeApplicationMethod](reqId);\n } else if (isIos) {\n ios[closeApplicationMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--closeApplication-isWeb');\n }\n }\n\n const share = (reqId, text) => {\n const isAndroid = android && android[shareMethod];\n const isIos = ios && ios[shareMethod];\n\n if (isAndroid) {\n android[shareMethod](reqId, text);\n } else if (isIos) {\n ios[shareMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--share-isWeb');\n }\n }\n\n const setTitle = (reqId, text) => {\n const isAndroid = android && android[setTitleMethod];\n const isIos = ios && ios[setTitleMethod];\n\n if (isAndroid) {\n android[setTitleMethod](reqId, text);\n } else if (isIos) {\n ios[setTitleMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--setTitle-isWeb');\n }\n }\n\n const copyToClipboard = (reqId, text) => {\n const isAndroid = android && android[copyToClipboardMethod];\n const isIos = ios && ios[copyToClipboardMethod];\n\n if (isAndroid) {\n android[copyToClipboardMethod](reqId, text);\n } else if (isIos) {\n ios[copyToClipboardMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--copyToClipboard-isWeb');\n }\n }\n\n const enableScreenCapture = () => {\n const isAndroid = android && android[enableScreenCaptureMethod];\n const isIos = ios && ios[enableScreenCaptureMethod];\n\n if (isAndroid) {\n android[enableScreenCaptureMethod]();\n } else if (isIos) {\n ios[enableScreenCaptureMethod].postMessage({});\n } else if (typeof window !== 'undefined') {\n console.log('--enableScreenCapture-isWeb');\n }\n }\n\n const disableScreenCapture = () => {\n const isAndroid = android && android[disableScreenCaptureMethod];\n const isIos = ios && ios[disableScreenCaptureMethod];\n\n if (isAndroid) {\n android[disableScreenCaptureMethod]();\n } else if (isIos) {\n ios[disableScreenCaptureMethod].postMessage({});\n } else if (typeof window !== 'undefined') {\n console.log('--disableScreenCapture-isWeb');\n }\n }\n\n const shareImage = (reqId, text, image) => {\n // !!!======================!!!\n // !!!===== Deprecated =====!!!\n // !!!======================!!!\n\n // const isAndroid = android && android[shareImageMethod];\n // const isIos = ios && ios[shareImageMethod];\n\n // if (isAndroid) {\n // android[shareImageMethod](reqId, text, image);\n // } else if (isIos) {\n // ios[shareImageMethod].postMessage({ reqId, text, image });\n // } else if (typeof window !== 'undefined') {\n // console.log('--shareImage-isWeb');\n // }\n\n // new one - fallback to shareFile\n const isAndroid = android && android[shareFileMethod];\n const isIos = ios && ios[shareFileMethod];\n\n // get extension from base64 mime type and merge with name\n const ext = image.split(';')[0].split('/')[1];\n const filename = 'image.' + ext;\n // remove mime type\n const base64Data = image.substr(image.indexOf(',') + 1);\n\n if (isAndroid) {\n android[shareFileMethod](reqId, text, filename, base64Data);\n } else if (isIos) {\n ios[shareFileMethod].postMessage({ reqId, text, filename, base64Data });\n } else if (typeof window !== 'undefined') {\n console.log('--shareFile-isWeb');\n }\n }\n\n const shareFile = (reqId, text, filename, base64Data) => {\n const isAndroid = android && android[shareFileMethod];\n const isIos = ios && ios[shareFileMethod];\n\n if (isAndroid) {\n android[shareFileMethod](reqId, text, filename, base64Data);\n } else if (isIos) {\n ios[shareFileMethod].postMessage({ reqId, text, filename, base64Data });\n } else if (typeof window !== 'undefined') {\n console.log('--shareFile-isWeb');\n }\n }\n\n const enableNotifications = () => invokePromise(EInvokeRequest.enableNotifications);\n\n const disableNotifications = () => invokePromise(EInvokeRequest.disableNotifications);\n\n const setShakeHandler = (handler) => {\n const isAndroid = android && android[setShakeHandlerMethod];\n const isIos = ios && ios[setShakeHandlerMethod];\n\n if (isAndroid || isIos) {\n (window as any).onAituBridgeShake = handler;\n } else if (typeof window !== 'undefined') {\n console.log('--setShakeHandler-isWeb');\n }\n };\n\n const setTabActiveHandler = (handler: (tabname: string) => void) => {\n const isAndroid = android && android[setTabActiveHandlerMethod];\n const isIos = ios && ios[setTabActiveHandlerMethod];\n\n if (isAndroid || isIos) {\n (window as any).onAituBridgeTabActive = handler;\n } else if (typeof window !== 'undefined') {\n console.log('--setTabActiveHandler-isWeb');\n }\n };\n\n const vibrate = (reqId, pattern) => {\n if (\n !Array.isArray(pattern) ||\n pattern.some((timing) => timing < 1 || timing !== Math.floor(timing)) ||\n pattern.reduce((total, timing) => total + timing) > 10000\n ) {\n console.error('Pattern should be an array of positive integers no longer than 10000ms total');\n return;\n }\n\n const isAndroid = android && android[vibrateMethod];\n const isIos = ios && ios[vibrateMethod];\n\n if (isAndroid) {\n android[vibrateMethod](reqId, JSON.stringify(pattern));\n } else if (isIos) {\n ios[vibrateMethod].postMessage({ reqId, pattern });\n } else if (typeof window !== 'undefined') {\n console.log('--vibrate-isWeb');\n }\n }\n\n const isSupported = () => {\n const iosSup = ios && (window as any).webkit.messageHandlers.invoke;\n return Boolean(android || iosSup || web);\n }\n\n const supports = (method) =>\n (android && typeof android[method] === 'function') ||\n (ios && ios[method] && typeof ios[method].postMessage === 'function') ||\n (web && typeof web[method] === 'function');\n\n const sub = (listener: any) => {\n subs.push(listener);\n }\n\n const invokePromise = promisifyInvoke(invoke, sub);\n const storagePromise = promisifyStorage(storage, sub);\n const getGeoPromise = promisifyMethod(getGeo, sub);\n const getQrPromise = promisifyMethod(getQr, sub);\n const getSMSCodePromise = promisifyMethod(getSMSCode, sub);\n const selectContactPromise = promisifyMethod(selectContact, sub);\n const openSettingsPromise = promisifyMethod(openSettings, sub);\n const closeApplicationPromise = promisifyMethod(closeApplication, sub);\n const sharePromise = promisifyMethod(share, sub);\n const setTitlePromise = promisifyMethod(setTitle, sub);\n const copyToClipboardPromise = promisifyMethod(copyToClipboard, sub);\n const shareImagePromise = promisifyMethod(shareImage, sub);\n const shareFilePromise = promisifyMethod(shareFile, sub);\n const vibratePromise = promisifyMethod(vibrate, sub);\n const enableScreenCapturePromise = promisifyMethod(enableScreenCapture, sub);\n const disableScreenCapturePromise = promisifyMethod(disableScreenCapture, sub);\n\n return {\n copyToClipboard: copyToClipboardPromise,\n invoke: invokePromise,\n storage: storagePromise,\n getMe: () => invokePromise(EInvokeRequest.getMe),\n getPhone: () => invokePromise(EInvokeRequest.getPhone),\n getContacts: () => invokePromise(EInvokeRequest.getContacts),\n getGeo: getGeoPromise,\n getQr: getQrPromise,\n getSMSCode: getSMSCodePromise,\n getUserProfile: (id: string) => invokePromise(EInvokeRequest.getUserProfile, { id }),\n selectContact: selectContactPromise,\n enableNotifications,\n disableNotifications,\n openSettings: openSettingsPromise,\n closeApplication: closeApplicationPromise,\n setTitle: setTitlePromise,\n share: sharePromise,\n shareImage: shareImagePromise,\n shareFile: shareFilePromise,\n setShakeHandler,\n setTabActiveHandler,\n vibrate: vibratePromise,\n isSupported,\n supports,\n sub,\n enableScreenCapture: enableScreenCapturePromise,\n disableScreenCapture: disableScreenCapturePromise\n }\n}\n\nconst bridge = buildBridge();\n\nexport default bridge;\n","function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n}\n\nfunction createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n\n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n\n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const invokeId = id;\n promiseControllers[invokeId] = controller;\n return invokeId;\n },\n\n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n\n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n\n promiseControllers[reqId] = null;\n }\n },\n };\n}\n\nfunction promisifyInvoke(invoke, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n\n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n\n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n\n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return function promisifiedFunc(method: any, props: any = {}): Promise<any | void> {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject }, props.reqId);\n\n invoke(reqId, method, props);\n });\n };\n}\n\nexport default promisifyInvoke;\n","function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n }\n \n function createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n \n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n \n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const storageId = `s${id}`;\n promiseControllers[storageId] = controller;\n return storageId;\n },\n \n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n \n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n \n promiseControllers[reqId] = null;\n }\n },\n };\n }\n \n function promisifyStorage(storage, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n \n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n \n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n \n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return {\n setItem: (keyName: string, keyValue: string): Promise<void> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'setItem', { keyName, keyValue });\n });\n },\n getItem: (keyName: string): Promise<string | null> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'getItem', { keyName });\n });\n },\n clear: (): Promise<void> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'clear', {});\n });\n },\n }\n }\n \n export default promisifyStorage;\n "],"names":["promisifyMethod","method","subscribe","counter","promiseControllers","requestResolver","current","next","this","add","controller","customId","methodId","resolve","reqId","data","isSuccess","error","requestPromise","reject","event","detail","Promise","EInvokeRequest","invokeMethod","storageMethod","android","window","AndroidBridge","ios","webkit","messageHandlers","web","top","WebBridge","aituOrigin","AITU_ORIGIN","forEach","postMessage","JSON","stringify","payload","addEventListener","origin","parse","dispatchEvent","CustomEvent","e","bridge","subs","map","fn","call","sub","listener","push","invokePromise","invokeId","props","isIos","isWeb","console","log","invoke","storagePromise","storage","storageId","setItem","keyName","keyValue","getItem","clear","promisifyStorage","getGeoPromise","getQrPromise","getSMSCodePromise","selectContactPromise","openSettingsPromise","closeApplicationPromise","sharePromise","text","setTitlePromise","copyToClipboardPromise","shareImagePromise","image","isAndroid","filename","split","base64Data","substr","indexOf","shareFilePromise","vibratePromise","pattern","Array","isArray","some","timing","Math","floor","reduce","total","enableScreenCapturePromise","disableScreenCapturePromise","copyToClipboard","getMe","getPhone","getContacts","getGeo","getQr","getSMSCode","getUserProfile","id","selectContact","enableNotifications","disableNotifications","openSettings","closeApplication","setTitle","share","shareImage","shareFile","setShakeHandler","handler","onAituBridgeShake","setTabActiveHandler","onAituBridgeTabActive","vibrate","isSupported","iosSup","Boolean","supports","enableScreenCapture","disableScreenCapture","buildBridge"],"mappings":"AA0CA,SAASA,EAAgBC,EAAQC,GAC/B,IA5BMC,EACAC,EA2BAC,GA5BAF,EAdC,CACLG,QAAS,EACTC,gBACE,QAASC,KAAKF,UAYZF,EAA+D,GAE9D,CACLK,aAAIC,EAA+BC,GACjC,IACMC,EADiB,MAAZD,EAAmBA,EAAWR,EAAQI,OAGjD,OADAH,EAAmBQ,GAAYF,EACxBE,GAGTC,iBAAWC,EAAwBC,EAASC,EAAiCC,GAC3E,IAAMC,EAAiBd,EAAmBU,GAEtCI,IACEF,EAAUC,GACZC,EAAeL,QAAQE,GAEvBG,EAAeC,OAAOF,GAGxBb,EAAmBU,GAAS,SAuBlC,OAdAZ,EAAU,SAACkB,GACT,GAAKA,EAAMC,QAIP,UAAWD,EAAMC,OAAQ,OACID,EAAMC,OAA7BP,IAAAA,MAEJA,GACFT,EAAgBQ,QAAQC,IAHXC,KAGwB,SAACE,UAAYA,KAH/BA,qCASvB,WAAWK,QAAQ,SAACT,EAASM,GAC3B,IAAML,EAAQT,EAAgBI,IAAI,CAAEI,QAAAA,EAASM,OAAAA,IAE7ClB,gBAAOa,gCC3Db,IAAKS,GAAL,SAAKA,GACHA,gBACAA,sBACAA,4BACAA,kCACAA,2CACAA,8CANF,CAAKA,IAAAA,OA0GL,IAAMC,EAAe,SACfC,EAAgB,UAkBhBC,EAA4B,oBAAXC,QAA2BA,OAAeC,cAC3DC,EAAwB,oBAAXF,QAA2BA,OAAeG,QAAWH,OAAeG,OAAOC,gBACxFC,EAAwB,oBAAXL,QAA2BA,OAAOM,MAAQN,SAAaA,OAAeO,UAAaP,OAAeO,WAAa,IAElI,GAAIF,EAAK,CACP,IAAMG,EAAcR,OAAeS,aAAe,kBAElD,CAACZ,EAAcC,GAAeY,QAAQ,SAACpC,GAChC+B,EAAI/B,KACP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UjG,IAqDpCmG,SAlDe,SAAClI,UACfyB,GAAsC,mBAApBA,EAAQzB,IAC1B4B,GAAOA,EAAI5B,IAA8C,mBAA5B4B,EAAI5B,GAAQqC,aACzCN,GAA8B,mBAAhBA,EAAI/B,IAgDnBoD,IAAAA,EACA+E,oBAAqB9B,EACrB+B,qBAAsB9B,GAIX+B"}
@@ -1,2 +1,2 @@
1
- function e(e,t){const o=function(){const e={current:0,next(){return++this.current}},t={};return{add(o,n){const s=null!=n?n:e.next();return t[s]=o,s},resolve(e,o,n,s){const i=t[e];i&&(n(s)?i.resolve(o):i.reject(s),t[e]=null)}}}();return t(e=>{if(e.detail&&"reqId"in e.detail){const{reqId:t,data:n,error:s}=e.detail;t&&o.resolve(t,n,e=>!e,s)}}),function(...t){return new Promise((n,s)=>{const i=o.add({resolve:n,reject:s});e(i,...t)})}}var t;!function(e){e.getMe="GetMe",e.getPhone="GetPhone",e.getContacts="GetContacts",e.enableNotifications="AllowNotifications",e.disableNotifications="DisableNotifications"}(t||(t={}));const o="invoke",n="storage",s="undefined"!=typeof window&&window.AndroidBridge,i="undefined"!=typeof window&&window.webkit&&window.webkit.messageHandlers,r="undefined"!=typeof window&&window.top!==window&&(window.WebBridge=window.WebBridge||{});if(r){const e=window.AITU_ORIGIN||"https://aitu.io";[o,n].forEach(t=>{r[t]||(r[t]=(...o)=>window.top.postMessage(JSON.stringify({method:t,payload:o}),e))}),window.addEventListener("message",t=>{if(t.origin===e&&t.data)try{const e=JSON.parse(t.data);window.dispatchEvent(new CustomEvent("aituEvents",{detail:e}))}catch(e){}})}const a=(()=>{const a=[];"undefined"!=typeof window&&window.addEventListener("aituEvents",e=>{[...a].map(t=>t.call(null,e))});const d=e=>{a.push(e)},l=function(e,t){const n=function(){const e={current:0,next(){return++this.current}},t={};return{add(o,n){const s=null!=n?n:e.next();return t[s]=o,s},resolve(e,o,n,s){const i=t[e];i&&(n(s)?i.resolve(o):i.reject(s),t[e]=null)}}}();return t(e=>{if(e.detail&&"reqId"in e.detail){const{reqId:t,data:o,error:s}=e.detail;t&&n.resolve(t,o,e=>!e,s)}}),function(e,t={}){return new Promise((a,d)=>{((e,t,n={})=>{const a=i&&i[o],d=r&&r[o];s&&s[o]?s[o](e,t,JSON.stringify(n)):a?i[o].postMessage({reqId:e,method:t,data:n}):d?r[o](e,t,n):"undefined"!=typeof window&&console.log("--invoke-isUnknown")})(n.add({resolve:a,reject:d},t.reqId),e,t)})}}(0,d),c=function(e,t){const o=function(){const e={current:0,next(){return++this.current}},t={};return{add(o,n){const s="s"+(null!=n?n:e.next());return t[s]=o,s},resolve(e,o,n,s){const i=t[e];i&&(n(s)?i.resolve(o):i.reject(s),t[e]=null)}}}();return t(e=>{if(e.detail&&"reqId"in e.detail){const{reqId:t,data:n,error:s}=e.detail;t&&o.resolve(t,n,e=>!e,s)}}),{setItem:(t,n)=>new Promise((s,i)=>{const r=o.add({resolve:s,reject:i});e(r,"setItem",{keyName:t,keyValue:n})}),getItem:t=>new Promise((n,s)=>{const i=o.add({resolve:n,reject:s});e(i,"getItem",{keyName:t})}),clear:()=>new Promise((t,n)=>{const s=o.add({resolve:t,reject:n});e(s,"clear",{})})}}((e,t,o={})=>{const a=i&&i[n],d=r&&r[n];s&&s[n]?s[n](e,t,JSON.stringify(o)):a?i[n].postMessage({reqId:e,method:t,data:o}):d?r[n](e,t,o):"undefined"!=typeof window&&console.log("--storage-isUnknown")},d),g=e(e=>{const t=i&&i.getGeo;s&&s.getGeo?s.getGeo(e):t?i.getGeo.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getGeo-isWeb")},d),p=e(e=>{const t=i&&i.getQr;s&&s.getQr?s.getQr(e):t?i.getQr.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getQr-isWeb")},d),w=e(e=>{const t=i&&i.getSMSCode;s&&s.getSMSCode?s.getSMSCode(e):t?i.getSMSCode.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getSMSCode-isWeb")},d),f=e(e=>{const t=i&&i.selectContact;s&&s.selectContact?s.selectContact(e):t?i.selectContact.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--selectContact-isWeb")},d),u=e(e=>{const t=i&&i.openSettings;s&&s.openSettings?s.openSettings(e):t?i.openSettings.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--openSettings-isWeb")},d),b=e(e=>{const t=i&&i.closeApplication;s&&s.closeApplication?s.closeApplication(e):t?i.closeApplication.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--closeApplication-isWeb")},d),h=e((e,t)=>{const o=i&&i.share;s&&s.share?s.share(e,t):o?i.share.postMessage({reqId:e,text:t}):"undefined"!=typeof window&&console.log("--share-isWeb")},d),y=e((e,t)=>{const o=i&&i.setTitle;s&&s.setTitle?s.setTitle(e,t):o?i.setTitle.postMessage({reqId:e,text:t}):"undefined"!=typeof window&&console.log("--setTitle-isWeb")},d),v=e((e,t)=>{const o=i&&i.copyToClipboard;s&&s.copyToClipboard?s.copyToClipboard(e,t):o?i.copyToClipboard.postMessage({reqId:e,text:t}):"undefined"!=typeof window&&console.log("--copyToClipboard-isWeb")},d),I=e((e,t,o)=>{const n=i&&i.shareFile,r=o;s&&s.shareFile?s.shareFile(e,t,"image",r):n?i.shareFile.postMessage({reqId:e,text:t,filename:"image",base64Data:r}):"undefined"!=typeof window&&console.log("--shareFile-isWeb")},d),S=e((e,t,o,n)=>{const r=i&&i.shareFile;s&&s.shareFile?s.shareFile(e,t,o,n):r?i.shareFile.postMessage({reqId:e,text:t,filename:o,base64Data:n}):"undefined"!=typeof window&&console.log("--shareFile-isWeb")},d),M=e((e,t)=>{if(!Array.isArray(t)||t.some(e=>e<1||e!==Math.floor(e))||t.reduce((e,t)=>e+t)>1e4)return void console.error("Pattern should be an array of positive integers no longer than 10000ms total");const o=i&&i.vibrate;s&&s.vibrate?s.vibrate(e,JSON.stringify(t)):o?i.vibrate.postMessage({reqId:e,pattern:t}):"undefined"!=typeof window&&console.log("--vibrate-isWeb")},d);return{copyToClipboard:v,invoke:l,storage:c,getMe:()=>l(t.getMe),getPhone:()=>l(t.getPhone),getContacts:()=>l(t.getContacts),getGeo:g,getQr:p,getSMSCode:w,selectContact:f,enableNotifications:()=>l(t.enableNotifications),disableNotifications:()=>l(t.disableNotifications),openSettings:u,closeApplication:b,setTitle:y,share:h,shareImage:I,shareFile:S,setShakeHandler:e=>{s&&s.setShakeHandler||i&&i.setShakeHandler?window.onAituBridgeShake=e:"undefined"!=typeof window&&console.log("--setShakeHandler-isWeb")},vibrate:M,isSupported:()=>{const e=i&&window.webkit.messageHandlers.invoke;return Boolean(s||e||r)},supports:e=>s&&"function"==typeof s[e]||i&&i[e]&&"function"==typeof i[e].postMessage||r&&"function"==typeof r[e],sub:d}})();export default a;
1
+ function e(e,t){const o=function(){const e={current:0,next(){return++this.current}},t={};return{add(o,n){const s=null!=n?n:e.next();return t[s]=o,s},resolve(e,o,n,s){const i=t[e];i&&(n(s)?i.resolve(o):i.reject(s),t[e]=null)}}}();return t(e=>{if(e.detail&&"reqId"in e.detail){const{reqId:t,data:n,error:s}=e.detail;t&&o.resolve(t,n,e=>!e,s)}}),function(...t){return new Promise((n,s)=>{const i=o.add({resolve:n,reject:s});e(i,...t)})}}var t;!function(e){e.getMe="GetMe",e.getPhone="GetPhone",e.getContacts="GetContacts",e.getUserProfile="GetUserProfile",e.enableNotifications="AllowNotifications",e.disableNotifications="DisableNotifications"}(t||(t={}));const o="invoke",n="storage",s="undefined"!=typeof window&&window.AndroidBridge,i="undefined"!=typeof window&&window.webkit&&window.webkit.messageHandlers,r="undefined"!=typeof window&&window.top!==window&&(window.WebBridge=window.WebBridge||{});if(r){const e=window.AITU_ORIGIN||"https://aitu.io";[o,n].forEach(t=>{r[t]||(r[t]=(...o)=>window.top.postMessage(JSON.stringify({method:t,payload:o}),e))}),window.addEventListener("message",t=>{if(t.origin===e&&t.data)try{const e=JSON.parse(t.data);window.dispatchEvent(new CustomEvent("aituEvents",{detail:e}))}catch(e){}})}const a=(()=>{const a=[];"undefined"!=typeof window&&window.addEventListener("aituEvents",e=>{[...a].map(t=>t.call(null,e))});const d=e=>{a.push(e)},l=function(e,t){const n=function(){const e={current:0,next(){return++this.current}},t={};return{add(o,n){const s=null!=n?n:e.next();return t[s]=o,s},resolve(e,o,n,s){const i=t[e];i&&(n(s)?i.resolve(o):i.reject(s),t[e]=null)}}}();return t(e=>{if(e.detail&&"reqId"in e.detail){const{reqId:t,data:o,error:s}=e.detail;t&&n.resolve(t,o,e=>!e,s)}}),function(e,t={}){return new Promise((a,d)=>{((e,t,n={})=>{const a=i&&i[o],d=r&&r[o];s&&s[o]?s[o](e,t,JSON.stringify(n)):a?i[o].postMessage({reqId:e,method:t,data:n}):d?r[o](e,t,n):"undefined"!=typeof window&&console.log("--invoke-isUnknown")})(n.add({resolve:a,reject:d},t.reqId),e,t)})}}(0,d),c=function(e,t){const o=function(){const e={current:0,next(){return++this.current}},t={};return{add(o,n){const s="s"+(null!=n?n:e.next());return t[s]=o,s},resolve(e,o,n,s){const i=t[e];i&&(n(s)?i.resolve(o):i.reject(s),t[e]=null)}}}();return t(e=>{if(e.detail&&"reqId"in e.detail){const{reqId:t,data:n,error:s}=e.detail;t&&o.resolve(t,n,e=>!e,s)}}),{setItem:(t,n)=>new Promise((s,i)=>{const r=o.add({resolve:s,reject:i});e(r,"setItem",{keyName:t,keyValue:n})}),getItem:t=>new Promise((n,s)=>{const i=o.add({resolve:n,reject:s});e(i,"getItem",{keyName:t})}),clear:()=>new Promise((t,n)=>{const s=o.add({resolve:t,reject:n});e(s,"clear",{})})}}((e,t,o={})=>{const a=i&&i[n],d=r&&r[n];s&&s[n]?s[n](e,t,JSON.stringify(o)):a?i[n].postMessage({reqId:e,method:t,data:o}):d?r[n](e,t,o):"undefined"!=typeof window&&console.log("--storage-isUnknown")},d),p=e(e=>{const t=i&&i.getGeo;s&&s.getGeo?s.getGeo(e):t?i.getGeo.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getGeo-isWeb")},d),g=e(e=>{const t=i&&i.getQr;s&&s.getQr?s.getQr(e):t?i.getQr.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getQr-isWeb")},d),u=e(e=>{const t=i&&i.getSMSCode;s&&s.getSMSCode?s.getSMSCode(e):t?i.getSMSCode.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getSMSCode-isWeb")},d),f=e(e=>{const t=i&&i.selectContact;s&&s.selectContact?s.selectContact(e):t?i.selectContact.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--selectContact-isWeb")},d),w=e(e=>{const t=i&&i.openSettings;s&&s.openSettings?s.openSettings(e):t?i.openSettings.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--openSettings-isWeb")},d),b=e(e=>{const t=i&&i.closeApplication;s&&s.closeApplication?s.closeApplication(e):t?i.closeApplication.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--closeApplication-isWeb")},d),h=e((e,t)=>{const o=i&&i.share;s&&s.share?s.share(e,t):o?i.share.postMessage({reqId:e,text:t}):"undefined"!=typeof window&&console.log("--share-isWeb")},d),y=e((e,t)=>{const o=i&&i.setTitle;s&&s.setTitle?s.setTitle(e,t):o?i.setTitle.postMessage({reqId:e,text:t}):"undefined"!=typeof window&&console.log("--setTitle-isWeb")},d),S=e((e,t)=>{const o=i&&i.copyToClipboard;s&&s.copyToClipboard?s.copyToClipboard(e,t):o?i.copyToClipboard.postMessage({reqId:e,text:t}):"undefined"!=typeof window&&console.log("--copyToClipboard-isWeb")},d),v=e((e,t,o)=>{const n=s&&s.shareFile,r=i&&i.shareFile,a="image."+o.split(";")[0].split("/")[1],d=o.substr(o.indexOf(",")+1);n?s.shareFile(e,t,a,d):r?i.shareFile.postMessage({reqId:e,text:t,filename:a,base64Data:d}):"undefined"!=typeof window&&console.log("--shareFile-isWeb")},d),M=e((e,t,o,n)=>{const r=i&&i.shareFile;s&&s.shareFile?s.shareFile(e,t,o,n):r?i.shareFile.postMessage({reqId:e,text:t,filename:o,base64Data:n}):"undefined"!=typeof window&&console.log("--shareFile-isWeb")},d),C=e((e,t)=>{if(!Array.isArray(t)||t.some(e=>e<1||e!==Math.floor(e))||t.reduce((e,t)=>e+t)>1e4)return void console.error("Pattern should be an array of positive integers no longer than 10000ms total");const o=i&&i.vibrate;s&&s.vibrate?s.vibrate(e,JSON.stringify(t)):o?i.vibrate.postMessage({reqId:e,pattern:t}):"undefined"!=typeof window&&console.log("--vibrate-isWeb")},d),I=e(()=>{const e=i&&i.enableScreenCaptureMethod;s&&s.enableScreenCaptureMethod?s.enableScreenCaptureMethod():e?i.enableScreenCaptureMethod.postMessage({}):"undefined"!=typeof window&&console.log("--enableScreenCapture-isWeb")},d),m=e(()=>{const e=i&&i.disableScreenCaptureMethod;s&&s.disableScreenCaptureMethod?s.disableScreenCaptureMethod():e?i.disableScreenCaptureMethod.postMessage({}):"undefined"!=typeof window&&console.log("--disableScreenCapture-isWeb")},d);return{copyToClipboard:S,invoke:l,storage:c,getMe:()=>l(t.getMe),getPhone:()=>l(t.getPhone),getContacts:()=>l(t.getContacts),getGeo:p,getQr:g,getSMSCode:u,getUserProfile:e=>l(t.getUserProfile,{id:e}),selectContact:f,enableNotifications:()=>l(t.enableNotifications),disableNotifications:()=>l(t.disableNotifications),openSettings:w,closeApplication:b,setTitle:y,share:h,shareImage:v,shareFile:M,setShakeHandler:e=>{s&&s.setShakeHandler||i&&i.setShakeHandler?window.onAituBridgeShake=e:"undefined"!=typeof window&&console.log("--setShakeHandler-isWeb")},setTabActiveHandler:e=>{s&&s.setTabActiveHandler||i&&i.setTabActiveHandler?window.onAituBridgeTabActive=e:"undefined"!=typeof window&&console.log("--setTabActiveHandler-isWeb")},vibrate:C,isSupported:()=>{const e=i&&window.webkit.messageHandlers.invoke;return Boolean(s||e||r)},supports:e=>s&&"function"==typeof s[e]||i&&i[e]&&"function"==typeof i[e].postMessage||r&&"function"==typeof r[e],sub:d,enableScreenCapture:I,disableScreenCapture:m}})();export default a;
2
2
  //# sourceMappingURL=index.modern.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.modern.js","sources":["../src/promisifyMethod.ts","../src/index.ts","../src/promisifyInvoke.ts","../src/promisifyStorage.ts"],"sourcesContent":["function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n}\n\nfunction createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n\n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n\n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const methodId = id;\n promiseControllers[methodId] = controller;\n return methodId;\n },\n\n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n\n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n\n promiseControllers[reqId] = null;\n }\n },\n };\n}\n\nfunction promisifyMethod(method, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n\n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n\n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n\n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return function promisifiedFunc(...args: any[]): Promise<any | void> {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n\n method(reqId, ...args);\n });\n };\n}\n\nexport default promisifyMethod;\n","import promisifyInvoke from './promisifyInvoke';\nimport promisifyStorage from './promisifyStorage';\nimport promisifyMethod from './promisifyMethod';\n\nenum EInvokeRequest {\n getMe = 'GetMe',\n getPhone = 'GetPhone',\n getContacts = 'GetContacts',\n enableNotifications = 'AllowNotifications',\n disableNotifications = 'DisableNotifications'\n}\n\ntype SetItemType = (keyName: string, keyValue: string) => Promise<void>;\ntype GetItemType = (keyName: string) => Promise<string | null>;\ntype ClearType = () => Promise<void>;\n\ninterface GetPhoneResponse {\n phone: string;\n sign: string;\n}\n\ninterface GetMeResponse {\n name: string;\n lastname: string;\n id: string;\n avatar?: string;\n avatarThumb?: string;\n sign: string;\n}\n\ninterface ResponseObject {\n phone?: string;\n name?: string;\n lastname?: string;\n}\n\ninterface GetGeoResponse {\n latitude: number;\n longitude: number;\n}\n\ninterface GetContactsResponse {\n contacts: Array<{\n first_name: string;\n last_name: string;\n phone: string;\n }>;\n sign: string;\n}\n\ninterface SelectContactResponse {\n phone: string;\n name: string;\n lastname: string;\n}\n\ntype OpenSettingsResponse = 'success' | 'failed';\ntype ShareResponse = 'success' | 'failed';\ntype CopyToClipboardResponse = 'success' | 'failed';\ntype VibrateResponse = 'success' | 'failed';\n// todo: remove duplicates\ntype ResponseType = 'success' | 'failed';\n\ntype BridgeInvoke<T extends EInvokeRequest, R> = (method: T, data?: {}) => Promise<R>;\n\ninterface BridgeStorage {\n setItem: SetItemType,\n getItem: GetItemType,\n clear: ClearType\n}\n\ninterface AituBridge {\n invoke: BridgeInvoke<EInvokeRequest, ResponseObject>;\n storage: BridgeStorage;\n getMe: () => Promise<GetMeResponse>;\n getPhone: () => Promise<GetPhoneResponse>;\n getContacts: () => Promise<GetContactsResponse>;\n getGeo: () => Promise<GetGeoResponse>;\n selectContact: () => Promise<SelectContactResponse>;\n getQr: () => Promise<string>;\n getSMSCode: () => Promise<string>;\n share: (text: string) => Promise<ShareResponse>;\n setTitle: (text: string) => Promise<ResponseType>;\n copyToClipboard: (text: string) => Promise<CopyToClipboardResponse>;\n shareImage: (text: string, image: string) => Promise<ShareResponse>;\n shareFile: (text: string, filename: string, base64Data: string) => Promise<ShareResponse>;\n enableNotifications: () => Promise<{}>;\n disableNotifications: () => Promise<{}>;\n openSettings: () => Promise<OpenSettingsResponse>;\n closeApplication: () => Promise<ResponseType>;\n setShakeHandler: (handler: any) => void;\n vibrate: (pattern: number[]) => Promise<VibratePattern>;\n isSupported: () => boolean;\n supports: (method: string) => boolean;\n sub: any;\n}\n\nconst invokeMethod = 'invoke';\nconst storageMethod = 'storage';\nconst getGeoMethod = 'getGeo';\nconst getQrMethod = 'getQr';\nconst getSMSCodeMethod = 'getSMSCode';\nconst selectContactMethod = 'selectContact';\nconst openSettingsMethod = 'openSettings';\nconst closeApplicationMethod = 'closeApplication';\nconst shareMethod = 'share';\nconst setTitleMethod = 'setTitle';\nconst copyToClipboardMethod = 'copyToClipboard';\nconst shareImageMethod = 'shareImage';\nconst shareFileMethod = 'shareFile';\nconst setShakeHandlerMethod = 'setShakeHandler';\nconst vibrateMethod = 'vibrate';\n\nconst android = typeof window !== 'undefined' && (window as any).AndroidBridge;\nconst ios = typeof window !== 'undefined' && (window as any).webkit && (window as any).webkit.messageHandlers;\nconst web = typeof window !== 'undefined' && (window.top !== window) && ((window as any).WebBridge = (window as any).WebBridge || {});\n\nif (web) {\n const aituOrigin = (window as any).AITU_ORIGIN || 'https://aitu.io';\n\n [invokeMethod, storageMethod].forEach((method) => {\n if (!web[method]) {\n web[method] = (...args) => window.top.postMessage(JSON.stringify({\n method,\n payload: args,\n }), aituOrigin);\n }\n });\n\n window.addEventListener('message', (event) => {\n if (event.origin === aituOrigin && event.data) {\n try {\n const detail = JSON.parse(event.data);\n window.dispatchEvent(new CustomEvent('aituEvents', { detail }));\n } catch(e) {}\n }\n });\n}\n\nconst buildBridge = (): AituBridge => {\n const subs = [];\n\n if (typeof window !== 'undefined') {\n window.addEventListener('aituEvents', (e: any) => {\n [...subs].map((fn) => fn.call(null, e));\n })\n }\n\n const invoke = (reqId, method, data = {}) => {\n const isAndroid = android && android[invokeMethod];\n const isIos = ios && ios[invokeMethod];\n const isWeb = web && web[invokeMethod];\n\n if (isAndroid) {\n android[invokeMethod](reqId, method, JSON.stringify(data));\n } else if (isIos) {\n ios[invokeMethod].postMessage({ reqId, method, data });\n } else if (isWeb) {\n web[invokeMethod](reqId, method, data);\n } else if (typeof window !== 'undefined') {\n console.log('--invoke-isUnknown');\n }\n };\n\n const storage = (reqId, method, data = {}) => {\n const isAndroid = android && android[storageMethod];\n const isIos = ios && ios[storageMethod];\n const isWeb = web && web[storageMethod];\n\n if (isAndroid) {\n android[storageMethod](reqId, method, JSON.stringify(data));\n } else if (isIos) {\n ios[storageMethod].postMessage({ reqId, method, data });\n } else if (isWeb) {\n web[storageMethod](reqId, method, data);\n } else if (typeof window !== 'undefined') {\n console.log('--storage-isUnknown');\n }\n }\n\n const getGeo = (reqId) => {\n const isAndroid = android && android[getGeoMethod];\n const isIos = ios && ios[getGeoMethod];\n\n if (isAndroid) {\n android[getGeoMethod](reqId);\n } else if (isIos) {\n ios[getGeoMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getGeo-isWeb');\n }\n }\n\n const getQr = (reqId) => {\n const isAndroid = android && android[getQrMethod];\n const isIos = ios && ios[getQrMethod];\n\n if (isAndroid) {\n android[getQrMethod](reqId);\n } else if (isIos) {\n ios[getQrMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getQr-isWeb');\n }\n }\n\n const getSMSCode = (reqId) => {\n const isAndroid = android && android[getSMSCodeMethod];\n const isIos = ios && ios[getSMSCodeMethod];\n\n if (isAndroid) {\n android[getSMSCodeMethod](reqId);\n } else if (isIos) {\n ios[getSMSCodeMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getSMSCode-isWeb');\n }\n }\n\n const selectContact = (reqId) => {\n const isAndroid = android && android[selectContactMethod];\n const isIos = ios && ios[selectContactMethod];\n\n if (isAndroid) {\n android[selectContactMethod](reqId);\n } else if (isIos) {\n ios[selectContactMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--selectContact-isWeb');\n }\n }\n\n const openSettings = (reqId) => {\n const isAndroid = android && android[openSettingsMethod];\n const isIos = ios && ios[openSettingsMethod];\n\n if (isAndroid) {\n android[openSettingsMethod](reqId);\n } else if (isIos) {\n ios[openSettingsMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--openSettings-isWeb');\n }\n }\n\n const closeApplication = (reqId) => {\n const isAndroid = android && android[closeApplicationMethod];\n const isIos = ios && ios[closeApplicationMethod];\n\n if (isAndroid) {\n android[closeApplicationMethod](reqId);\n } else if (isIos) {\n ios[closeApplicationMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--closeApplication-isWeb');\n }\n }\n\n const share = (reqId, text) => {\n const isAndroid = android && android[shareMethod];\n const isIos = ios && ios[shareMethod];\n\n if (isAndroid) {\n android[shareMethod](reqId, text);\n } else if (isIos) {\n ios[shareMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--share-isWeb');\n }\n }\n\n const setTitle = (reqId, text) => {\n const isAndroid = android && android[setTitleMethod];\n const isIos = ios && ios[setTitleMethod];\n\n if (isAndroid) {\n android[setTitleMethod](reqId, text);\n } else if (isIos) {\n ios[setTitleMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--setTitle-isWeb');\n }\n }\n\n const copyToClipboard = (reqId, text) => {\n const isAndroid = android && android[copyToClipboardMethod];\n const isIos = ios && ios[copyToClipboardMethod];\n\n if (isAndroid) {\n android[copyToClipboardMethod](reqId, text);\n } else if (isIos) {\n ios[copyToClipboardMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--copyToClipboard-isWeb');\n }\n }\n\n const shareImage = (reqId, text, image) => {\n // !!!======================!!!\n // !!!===== Deprecated =====!!!\n // !!!======================!!!\n\n // const isAndroid = android && android[shareImageMethod];\n // const isIos = ios && ios[shareImageMethod];\n\n // if (isAndroid) {\n // android[shareImageMethod](reqId, text, image);\n // } else if (isIos) {\n // ios[shareImageMethod].postMessage({ reqId, text, image });\n // } else if (typeof window !== 'undefined') {\n // console.log('--shareImage-isWeb');\n // }\n\n // new one - fallback to shareFile\n const isAndroid = android && android[shareFileMethod];\n const isIos = ios && ios[shareFileMethod];\n\n const filename = 'image';\n const base64Data = image;\n\n if (isAndroid) {\n android[shareFileMethod](reqId, text, filename, base64Data);\n } else if (isIos) {\n ios[shareFileMethod].postMessage({ reqId, text, filename, base64Data });\n } else if (typeof window !== 'undefined') {\n console.log('--shareFile-isWeb');\n }\n }\n\n const shareFile = (reqId, text, filename, base64Data) => {\n const isAndroid = android && android[shareFileMethod];\n const isIos = ios && ios[shareFileMethod];\n\n if (isAndroid) {\n android[shareFileMethod](reqId, text, filename, base64Data);\n } else if (isIos) {\n ios[shareFileMethod].postMessage({ reqId, text, filename, base64Data });\n } else if (typeof window !== 'undefined') {\n console.log('--shareFile-isWeb');\n }\n }\n\n const enableNotifications = () => invokePromise(EInvokeRequest.enableNotifications);\n\n const disableNotifications = () => invokePromise(EInvokeRequest.disableNotifications);\n\n const setShakeHandler = (handler) => {\n const isAndroid = android && android[setShakeHandlerMethod];\n const isIos = ios && ios[setShakeHandlerMethod];\n\n if (isAndroid || isIos) {\n (window as any).onAituBridgeShake = handler;\n } else if (typeof window !== 'undefined') {\n console.log('--setShakeHandler-isWeb');\n }\n };\n\n const vibrate = (reqId, pattern) => {\n if (\n !Array.isArray(pattern) ||\n pattern.some((timing) => timing < 1 || timing !== Math.floor(timing)) ||\n pattern.reduce((total, timing) => total + timing) > 10000\n ) {\n console.error('Pattern should be an array of positive integers no longer than 10000ms total');\n return;\n }\n\n const isAndroid = android && android[vibrateMethod];\n const isIos = ios && ios[vibrateMethod];\n\n if (isAndroid) {\n android[vibrateMethod](reqId, JSON.stringify(pattern));\n } else if (isIos) {\n ios[vibrateMethod].postMessage({ reqId, pattern });\n } else if (typeof window !== 'undefined') {\n console.log('--vibrate-isWeb');\n }\n }\n\n const isSupported = () => {\n const iosSup = ios && (window as any).webkit.messageHandlers.invoke;\n return Boolean(android || iosSup || web);\n }\n\n const supports = (method) =>\n (android && typeof android[method] === 'function') ||\n (ios && ios[method] && typeof ios[method].postMessage === 'function') ||\n (web && typeof web[method] === 'function');\n\n const sub = (listener: any) => {\n subs.push(listener);\n }\n\n const invokePromise = promisifyInvoke(invoke, sub);\n const storagePromise = promisifyStorage(storage, sub);\n const getGeoPromise = promisifyMethod(getGeo, sub);\n const getQrPromise = promisifyMethod(getQr, sub);\n const getSMSCodePromise = promisifyMethod(getSMSCode, sub);\n const selectContactPromise = promisifyMethod(selectContact, sub);\n const openSettingsPromise = promisifyMethod(openSettings, sub);\n const closeApplicationPromise = promisifyMethod(closeApplication, sub);\n const sharePromise = promisifyMethod(share, sub);\n const setTitlePromise = promisifyMethod(setTitle, sub);\n const copyToClipboardPromise = promisifyMethod(copyToClipboard, sub);\n const shareImagePromise = promisifyMethod(shareImage, sub);\n const shareFilePromise = promisifyMethod(shareFile, sub);\n const vibratePromise = promisifyMethod(vibrate, sub);\n\n return {\n copyToClipboard: copyToClipboardPromise,\n invoke: invokePromise,\n storage: storagePromise,\n getMe: () => invokePromise(EInvokeRequest.getMe),\n getPhone: () => invokePromise(EInvokeRequest.getPhone),\n getContacts: () => invokePromise(EInvokeRequest.getContacts),\n getGeo: getGeoPromise,\n getQr: getQrPromise,\n getSMSCode: getSMSCodePromise,\n selectContact: selectContactPromise,\n enableNotifications,\n disableNotifications,\n openSettings: openSettingsPromise,\n closeApplication: closeApplicationPromise,\n setTitle: setTitlePromise,\n share: sharePromise,\n shareImage: shareImagePromise,\n shareFile: shareFilePromise,\n setShakeHandler,\n vibrate: vibratePromise,\n isSupported,\n supports,\n sub\n }\n}\n\nconst bridge = buildBridge();\n\nexport default bridge;\n","function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n}\n\nfunction createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n\n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n\n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const invokeId = id;\n promiseControllers[invokeId] = controller;\n return invokeId;\n },\n\n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n\n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n\n promiseControllers[reqId] = null;\n }\n },\n };\n}\n\nfunction promisifyInvoke(invoke, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n\n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n\n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n\n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return function promisifiedFunc(method: any, props: any = {}): Promise<any | void> {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject }, props.reqId);\n\n invoke(reqId, method, props);\n });\n };\n}\n\nexport default promisifyInvoke;\n","function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n }\n \n function createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n \n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n \n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const storageId = `s${id}`;\n promiseControllers[storageId] = controller;\n return storageId;\n },\n \n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n \n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n \n promiseControllers[reqId] = null;\n }\n },\n };\n }\n \n function promisifyStorage(storage, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n \n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n \n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n \n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return {\n setItem: (keyName: string, keyValue: string): Promise<void> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'setItem', { keyName, keyValue });\n });\n },\n getItem: (keyName: string): Promise<string | null> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'getItem', { keyName });\n });\n },\n clear: (): Promise<void> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'clear', {});\n });\n },\n }\n }\n \n export default promisifyStorage;\n "],"names":["promisifyMethod","method","subscribe","requestResolver","counter","current","next","this","promiseControllers","add","controller","customId","methodId","resolve","reqId","data","isSuccess","error","requestPromise","reject","createRequestResolver","event","detail","args","Promise","EInvokeRequest","invokeMethod","storageMethod","android","window","AndroidBridge","ios","webkit","messageHandlers","web","top","WebBridge","aituOrigin","AITU_ORIGIN","forEach","postMessage","JSON","stringify","payload","addEventListener","origin","parse","dispatchEvent","CustomEvent","e","bridge","subs","map","fn","call","sub","listener","push","invokePromise","invoke","invokeId","props","isIos","isWeb","console","log","promisifyInvoke","storagePromise","storage","storageId","setItem","keyName","keyValue","getItem","clear","promisifyStorage","getGeoPromise","getQrPromise","getSMSCodePromise","selectContactPromise","openSettingsPromise","closeApplicationPromise","sharePromise","text","setTitlePromise","copyToClipboardPromise","shareImagePromise","image","base64Data","filename","shareFilePromise","vibratePromise","pattern","Array","isArray","some","timing","Math","floor","reduce","total","copyToClipboard","getMe","getPhone","getContacts","getGeo","getQr","getSMSCode","selectContact","enableNotifications","disableNotifications","openSettings","closeApplication","setTitle","share","shareImage","shareFile","setShakeHandler","handler","onAituBridgeShake","vibrate","isSupported","iosSup","Boolean","supports","buildBridge"],"mappings":"AA0CA,SAASA,EAAgBC,EAAQC,GAC/B,MAAMC,EAlCR,WAME,MAAMC,EAdC,CACLC,QAAS,EACTC,OACE,QAASC,KAAKF,UAYZG,EAA+D,GAErE,MAAO,CACLC,IAAIC,EAA+BC,GACjC,MACMC,EADiB,MAAZD,EAAmBA,EAAWP,EAAQE,OAGjD,OADAE,EAAmBI,GAAYF,EACxBE,GAGTC,QAAWC,EAAwBC,EAASC,EAAiCC,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Ae0F,kBAAoBD,EACT,oBAAXzF,QAChBmC,QAAQC,IAAI,4BA2EduD,QAAS7B,EACT8B,YAlDkB,KAClB,MAAMC,EAAS3F,GAAQF,OAAeG,OAAOC,gBAAgB0B,OAC7D,OAAOgE,QAAQ/F,GAAW8F,GAAUxF,IAiDpC0F,SA9CgB3H,GACf2B,GAAsC,mBAApBA,EAAQ3B,IAC1B8B,GAAOA,EAAI9B,IAA8C,mBAA5B8B,EAAI9B,GAAQuC,aACzCN,GAA8B,mBAAhBA,EAAIjC,GA4CnBsD,IAAAA,IAIWsE"}
1
+ {"version":3,"file":"index.modern.js","sources":["../src/promisifyMethod.ts","../src/index.ts","../src/promisifyInvoke.ts","../src/promisifyStorage.ts"],"sourcesContent":["function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n}\n\nfunction createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n\n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n\n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const methodId = id;\n promiseControllers[methodId] = controller;\n return methodId;\n },\n\n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n\n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n\n promiseControllers[reqId] = null;\n }\n },\n };\n}\n\nfunction promisifyMethod(method, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n\n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n\n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n\n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return function promisifiedFunc(...args: any[]): Promise<any | void> {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n\n method(reqId, ...args);\n });\n };\n}\n\nexport default promisifyMethod;\n","import promisifyInvoke from './promisifyInvoke';\nimport promisifyStorage from './promisifyStorage';\nimport promisifyMethod from './promisifyMethod';\n\nenum EInvokeRequest {\n getMe = 'GetMe',\n getPhone = 'GetPhone',\n getContacts = 'GetContacts',\n getUserProfile = 'GetUserProfile',\n enableNotifications = 'AllowNotifications',\n disableNotifications = 'DisableNotifications'\n}\n\ntype SetItemType = (keyName: string, keyValue: string) => Promise<void>;\ntype GetItemType = (keyName: string) => Promise<string | null>;\ntype ClearType = () => Promise<void>;\n\ninterface GetPhoneResponse {\n phone: string;\n sign: string;\n}\n\ninterface GetMeResponse {\n name: string;\n lastname: string;\n id: string;\n avatar?: string;\n avatarThumb?: string;\n sign: string;\n}\n\ninterface ResponseObject {\n phone?: string;\n name?: string;\n lastname?: string;\n}\n\ninterface GetGeoResponse {\n latitude: number;\n longitude: number;\n}\n\ninterface GetContactsResponse {\n contacts: Array<{\n first_name: string;\n last_name: string;\n phone: string;\n }>;\n sign: string;\n}\n\ninterface SelectContactResponse {\n phone: string;\n name: string;\n lastname: string;\n}\n\ninterface GetUserProfileResponse {\n name: string;\n lastname?: string;\n phone?: string;\n avatar?: string;\n avatarThumb?: string;\n}\n\ntype OpenSettingsResponse = 'success' | 'failed';\ntype ShareResponse = 'success' | 'failed';\ntype CopyToClipboardResponse = 'success' | 'failed';\ntype VibrateResponse = 'success' | 'failed';\n// todo: remove duplicates\ntype ResponseType = 'success' | 'failed';\n\ntype BridgeInvoke<T extends EInvokeRequest, R> = (method: T, data?: {}) => Promise<R>;\n\ninterface BridgeStorage {\n setItem: SetItemType,\n getItem: GetItemType,\n clear: ClearType\n}\n\ninterface AituBridge {\n invoke: BridgeInvoke<EInvokeRequest, ResponseObject>;\n storage: BridgeStorage;\n getMe: () => Promise<GetMeResponse>;\n getPhone: () => Promise<GetPhoneResponse>;\n getContacts: () => Promise<GetContactsResponse>;\n getGeo: () => Promise<GetGeoResponse>;\n selectContact: () => Promise<SelectContactResponse>;\n getQr: () => Promise<string>;\n getSMSCode: () => Promise<string>;\n getUserProfile: (userId: string) => Promise<GetUserProfileResponse>;\n share: (text: string) => Promise<ShareResponse>;\n setTitle: (text: string) => Promise<ResponseType>;\n copyToClipboard: (text: string) => Promise<CopyToClipboardResponse>;\n shareImage: (text: string, image: string) => Promise<ShareResponse>;\n shareFile: (text: string, filename: string, base64Data: string) => Promise<ShareResponse>;\n enableNotifications: () => Promise<{}>;\n disableNotifications: () => Promise<{}>;\n openSettings: () => Promise<OpenSettingsResponse>;\n closeApplication: () => Promise<ResponseType>;\n setShakeHandler: (handler: any) => void;\n setTabActiveHandler: (handler: (tabname: string) => void) => void;\n vibrate: (pattern: number[]) => Promise<VibratePattern>;\n isSupported: () => boolean;\n supports: (method: string) => boolean;\n sub: any;\n enableScreenCapture: () => Promise<{}>;\n disableScreenCapture: () => Promise<{}>;\n}\n\nconst invokeMethod = 'invoke';\nconst storageMethod = 'storage';\nconst getGeoMethod = 'getGeo';\nconst getQrMethod = 'getQr';\nconst getSMSCodeMethod = 'getSMSCode';\nconst selectContactMethod = 'selectContact';\nconst openSettingsMethod = 'openSettings';\nconst closeApplicationMethod = 'closeApplication';\nconst shareMethod = 'share';\nconst setTitleMethod = 'setTitle';\nconst copyToClipboardMethod = 'copyToClipboard';\nconst shareImageMethod = 'shareImage';\nconst shareFileMethod = 'shareFile';\nconst setShakeHandlerMethod = 'setShakeHandler';\nconst vibrateMethod = 'vibrate';\nconst enableScreenCaptureMethod = 'enableScreenCaptureMethod';\nconst disableScreenCaptureMethod = 'disableScreenCaptureMethod';\nconst setTabActiveHandlerMethod = 'setTabActiveHandler';\n\nconst android = typeof window !== 'undefined' && (window as any).AndroidBridge;\nconst ios = typeof window !== 'undefined' && (window as any).webkit && (window as any).webkit.messageHandlers;\nconst web = typeof window !== 'undefined' && (window.top !== window) && ((window as any).WebBridge = (window as any).WebBridge || {});\n\nif (web) {\n const aituOrigin = (window as any).AITU_ORIGIN || 'https://aitu.io';\n\n [invokeMethod, storageMethod].forEach((method) => {\n if (!web[method]) {\n web[method] = (...args) => window.top.postMessage(JSON.stringify({\n method,\n payload: args,\n }), aituOrigin);\n }\n });\n\n window.addEventListener('message', (event) => {\n if (event.origin === aituOrigin && event.data) {\n try {\n const detail = JSON.parse(event.data);\n window.dispatchEvent(new CustomEvent('aituEvents', { detail }));\n } catch (e) { }\n }\n });\n}\n\nconst buildBridge = (): AituBridge => {\n const subs = [];\n\n if (typeof window !== 'undefined') {\n window.addEventListener('aituEvents', (e: any) => {\n [...subs].map((fn) => fn.call(null, e));\n })\n }\n\n const invoke = (reqId, method, data = {}) => {\n const isAndroid = android && android[invokeMethod];\n const isIos = ios && ios[invokeMethod];\n const isWeb = web && web[invokeMethod];\n\n if (isAndroid) {\n android[invokeMethod](reqId, method, JSON.stringify(data));\n } else if (isIos) {\n ios[invokeMethod].postMessage({ reqId, method, data });\n } else if (isWeb) {\n web[invokeMethod](reqId, method, data);\n } else if (typeof window !== 'undefined') {\n console.log('--invoke-isUnknown');\n }\n };\n\n const storage = (reqId, method, data = {}) => {\n const isAndroid = android && android[storageMethod];\n const isIos = ios && ios[storageMethod];\n const isWeb = web && web[storageMethod];\n\n if (isAndroid) {\n android[storageMethod](reqId, method, JSON.stringify(data));\n } else if (isIos) {\n ios[storageMethod].postMessage({ reqId, method, data });\n } else if (isWeb) {\n web[storageMethod](reqId, method, data);\n } else if (typeof window !== 'undefined') {\n console.log('--storage-isUnknown');\n }\n }\n\n const getGeo = (reqId) => {\n const isAndroid = android && android[getGeoMethod];\n const isIos = ios && ios[getGeoMethod];\n\n if (isAndroid) {\n android[getGeoMethod](reqId);\n } else if (isIos) {\n ios[getGeoMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getGeo-isWeb');\n }\n }\n\n const getQr = (reqId) => {\n const isAndroid = android && android[getQrMethod];\n const isIos = ios && ios[getQrMethod];\n\n if (isAndroid) {\n android[getQrMethod](reqId);\n } else if (isIos) {\n ios[getQrMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getQr-isWeb');\n }\n }\n\n const getSMSCode = (reqId) => {\n const isAndroid = android && android[getSMSCodeMethod];\n const isIos = ios && ios[getSMSCodeMethod];\n\n if (isAndroid) {\n android[getSMSCodeMethod](reqId);\n } else if (isIos) {\n ios[getSMSCodeMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getSMSCode-isWeb');\n }\n }\n\n const selectContact = (reqId) => {\n const isAndroid = android && android[selectContactMethod];\n const isIos = ios && ios[selectContactMethod];\n\n if (isAndroid) {\n android[selectContactMethod](reqId);\n } else if (isIos) {\n ios[selectContactMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--selectContact-isWeb');\n }\n }\n\n const openSettings = (reqId) => {\n const isAndroid = android && android[openSettingsMethod];\n const isIos = ios && ios[openSettingsMethod];\n\n if (isAndroid) {\n android[openSettingsMethod](reqId);\n } else if (isIos) {\n ios[openSettingsMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--openSettings-isWeb');\n }\n }\n\n const closeApplication = (reqId) => {\n const isAndroid = android && android[closeApplicationMethod];\n const isIos = ios && ios[closeApplicationMethod];\n\n if (isAndroid) {\n android[closeApplicationMethod](reqId);\n } else if (isIos) {\n ios[closeApplicationMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--closeApplication-isWeb');\n }\n }\n\n const share = (reqId, text) => {\n const isAndroid = android && android[shareMethod];\n const isIos = ios && ios[shareMethod];\n\n if (isAndroid) {\n android[shareMethod](reqId, text);\n } else if (isIos) {\n ios[shareMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--share-isWeb');\n }\n }\n\n const setTitle = (reqId, text) => {\n const isAndroid = android && android[setTitleMethod];\n const isIos = ios && ios[setTitleMethod];\n\n if (isAndroid) {\n android[setTitleMethod](reqId, text);\n } else if (isIos) {\n ios[setTitleMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--setTitle-isWeb');\n }\n }\n\n const copyToClipboard = (reqId, text) => {\n const isAndroid = android && android[copyToClipboardMethod];\n const isIos = ios && ios[copyToClipboardMethod];\n\n if (isAndroid) {\n android[copyToClipboardMethod](reqId, text);\n } else if (isIos) {\n ios[copyToClipboardMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--copyToClipboard-isWeb');\n }\n }\n\n const enableScreenCapture = () => {\n const isAndroid = android && android[enableScreenCaptureMethod];\n const isIos = ios && ios[enableScreenCaptureMethod];\n\n if (isAndroid) {\n android[enableScreenCaptureMethod]();\n } else if (isIos) {\n ios[enableScreenCaptureMethod].postMessage({});\n } else if (typeof window !== 'undefined') {\n console.log('--enableScreenCapture-isWeb');\n }\n }\n\n const disableScreenCapture = () => {\n const isAndroid = android && android[disableScreenCaptureMethod];\n const isIos = ios && ios[disableScreenCaptureMethod];\n\n if (isAndroid) {\n android[disableScreenCaptureMethod]();\n } else if (isIos) {\n ios[disableScreenCaptureMethod].postMessage({});\n } else if (typeof window !== 'undefined') {\n console.log('--disableScreenCapture-isWeb');\n }\n }\n\n const shareImage = (reqId, text, image) => {\n // !!!======================!!!\n // !!!===== Deprecated =====!!!\n // !!!======================!!!\n\n // const isAndroid = android && android[shareImageMethod];\n // const isIos = ios && ios[shareImageMethod];\n\n // if (isAndroid) {\n // android[shareImageMethod](reqId, text, image);\n // } else if (isIos) {\n // ios[shareImageMethod].postMessage({ reqId, text, image });\n // } else if (typeof window !== 'undefined') {\n // console.log('--shareImage-isWeb');\n // }\n\n // new one - fallback to shareFile\n const isAndroid = android && android[shareFileMethod];\n const isIos = ios && ios[shareFileMethod];\n\n // get extension from base64 mime type and merge with name\n const ext = image.split(';')[0].split('/')[1];\n const filename = 'image.' + ext;\n // remove mime type\n const base64Data = image.substr(image.indexOf(',') + 1);\n\n if (isAndroid) {\n android[shareFileMethod](reqId, text, filename, base64Data);\n } else if (isIos) {\n ios[shareFileMethod].postMessage({ reqId, text, filename, base64Data });\n } else if (typeof window !== 'undefined') {\n console.log('--shareFile-isWeb');\n }\n }\n\n const shareFile = (reqId, text, filename, base64Data) => {\n const isAndroid = android && android[shareFileMethod];\n const isIos = ios && ios[shareFileMethod];\n\n if (isAndroid) {\n android[shareFileMethod](reqId, text, filename, base64Data);\n } else if (isIos) {\n ios[shareFileMethod].postMessage({ reqId, text, filename, base64Data });\n } else if (typeof window !== 'undefined') {\n console.log('--shareFile-isWeb');\n }\n }\n\n const enableNotifications = () => invokePromise(EInvokeRequest.enableNotifications);\n\n const disableNotifications = () => invokePromise(EInvokeRequest.disableNotifications);\n\n const setShakeHandler = (handler) => {\n const isAndroid = android && android[setShakeHandlerMethod];\n const isIos = ios && ios[setShakeHandlerMethod];\n\n if (isAndroid || isIos) {\n (window as any).onAituBridgeShake = handler;\n } else if (typeof window !== 'undefined') {\n console.log('--setShakeHandler-isWeb');\n }\n };\n\n const setTabActiveHandler = (handler: (tabname: string) => void) => {\n const isAndroid = android && android[setTabActiveHandlerMethod];\n const isIos = ios && ios[setTabActiveHandlerMethod];\n\n if (isAndroid || isIos) {\n (window as any).onAituBridgeTabActive = handler;\n } else if (typeof window !== 'undefined') {\n console.log('--setTabActiveHandler-isWeb');\n }\n };\n\n const vibrate = (reqId, pattern) => {\n if (\n !Array.isArray(pattern) ||\n pattern.some((timing) => timing < 1 || timing !== Math.floor(timing)) ||\n pattern.reduce((total, timing) => total + timing) > 10000\n ) {\n console.error('Pattern should be an array of positive integers no longer than 10000ms total');\n return;\n }\n\n const isAndroid = android && android[vibrateMethod];\n const isIos = ios && ios[vibrateMethod];\n\n if (isAndroid) {\n android[vibrateMethod](reqId, JSON.stringify(pattern));\n } else if (isIos) {\n ios[vibrateMethod].postMessage({ reqId, pattern });\n } else if (typeof window !== 'undefined') {\n console.log('--vibrate-isWeb');\n }\n }\n\n const isSupported = () => {\n const iosSup = ios && (window as any).webkit.messageHandlers.invoke;\n return Boolean(android || iosSup || web);\n }\n\n const supports = (method) =>\n (android && typeof android[method] === 'function') ||\n (ios && ios[method] && typeof ios[method].postMessage === 'function') ||\n (web && typeof web[method] === 'function');\n\n const sub = (listener: any) => {\n subs.push(listener);\n }\n\n const invokePromise = promisifyInvoke(invoke, sub);\n const storagePromise = promisifyStorage(storage, sub);\n const getGeoPromise = promisifyMethod(getGeo, sub);\n const getQrPromise = promisifyMethod(getQr, sub);\n const getSMSCodePromise = promisifyMethod(getSMSCode, sub);\n const selectContactPromise = promisifyMethod(selectContact, sub);\n const openSettingsPromise = promisifyMethod(openSettings, sub);\n const closeApplicationPromise = promisifyMethod(closeApplication, sub);\n const sharePromise = promisifyMethod(share, sub);\n const setTitlePromise = promisifyMethod(setTitle, sub);\n const copyToClipboardPromise = promisifyMethod(copyToClipboard, sub);\n const shareImagePromise = promisifyMethod(shareImage, sub);\n const shareFilePromise = promisifyMethod(shareFile, sub);\n const vibratePromise = promisifyMethod(vibrate, sub);\n const enableScreenCapturePromise = promisifyMethod(enableScreenCapture, sub);\n const disableScreenCapturePromise = promisifyMethod(disableScreenCapture, sub);\n\n return {\n copyToClipboard: copyToClipboardPromise,\n invoke: invokePromise,\n storage: storagePromise,\n getMe: () => invokePromise(EInvokeRequest.getMe),\n getPhone: () => invokePromise(EInvokeRequest.getPhone),\n getContacts: () => invokePromise(EInvokeRequest.getContacts),\n getGeo: getGeoPromise,\n getQr: getQrPromise,\n getSMSCode: getSMSCodePromise,\n getUserProfile: (id: string) => invokePromise(EInvokeRequest.getUserProfile, { id }),\n selectContact: selectContactPromise,\n enableNotifications,\n disableNotifications,\n openSettings: openSettingsPromise,\n closeApplication: closeApplicationPromise,\n setTitle: setTitlePromise,\n share: sharePromise,\n shareImage: shareImagePromise,\n shareFile: shareFilePromise,\n setShakeHandler,\n setTabActiveHandler,\n vibrate: vibratePromise,\n isSupported,\n supports,\n sub,\n enableScreenCapture: enableScreenCapturePromise,\n disableScreenCapture: disableScreenCapturePromise\n }\n}\n\nconst bridge = buildBridge();\n\nexport default bridge;\n","function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n}\n\nfunction createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n\n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n\n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const invokeId = id;\n promiseControllers[invokeId] = controller;\n return invokeId;\n },\n\n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n\n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n\n promiseControllers[reqId] = null;\n }\n },\n };\n}\n\nfunction promisifyInvoke(invoke, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n\n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n\n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n\n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return function promisifiedFunc(method: any, props: any = {}): Promise<any | void> {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject }, props.reqId);\n\n invoke(reqId, method, props);\n });\n };\n}\n\nexport default promisifyInvoke;\n","function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n }\n \n function createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n \n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n \n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const storageId = `s${id}`;\n promiseControllers[storageId] = controller;\n return storageId;\n },\n \n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n \n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n \n promiseControllers[reqId] = null;\n }\n },\n };\n }\n \n function promisifyStorage(storage, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n \n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n \n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n \n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return {\n setItem: (keyName: string, keyValue: string): Promise<void> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'setItem', { keyName, keyValue });\n });\n },\n getItem: (keyName: string): Promise<string | null> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'getItem', { keyName });\n });\n },\n clear: (): Promise<void> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'clear', {});\n });\n },\n }\n }\n \n export default promisifyStorage;\n "],"names":["promisifyMethod","method","subscribe","requestResolver","counter","current","next","this","promiseControllers","add","controller","customId","methodId","resolve","reqId","data","isSuccess","error","requestPromise","reject","createRequestResolver","event","detail","args","Promise","EInvokeRequest","invokeMethod","storageMethod","android","window","AndroidBridge","ios","webkit","messageHandlers","web","top","WebBridge","aituOrigin","AITU_ORIGIN","forEach","postMessage","JSON","stringify","payload","addEventListener","origin","parse","dispatchEvent","CustomEvent","e","bridge","subs","map","fn","call","sub","listener","push","invokePromise","invoke","invokeId","props","isIos","isWeb","console","log","promisifyInvoke","storagePromise","storage","storageId","setItem","keyName","keyValue","getItem","clear","promisifyStorage","getGeoPromise","getQrPromise","getSMSCodePromise","selectContactPromise","openSettingsPromise","closeApplicationPromise","sharePromise","text","setTitlePromise","copyToClipboardPromise","shareImagePromise","image","isAndroid","filename","split","base64Data","substr","indexOf","shareFilePromise","vibratePromise","pattern","Array","isArray","some","timing","Math","floor","reduce","total","enableScreenCapturePromise","disableScreenCapturePromise","copyToClipboard","getMe","getPhone","getContacts","getGeo","getQr","getSMSCode","getUserProfile","id","selectContact","enableNotifications","disableNotifications","openSettings","closeApplication","setTitle","share","shareImage","shareFile","setShakeHandler","handler","onAituBridgeShake","setTabActiveHandler","onAituBridgeTabActive","vibrate","isSupported","iosSup","Boolean","supports","enableScreenCapture","disableScreenCapture","buildBridge"],"mappings":"AA0CA,SAASA,EAAgBC,EAAQC,GAC/B,MAAMC,EAlCR,WAME,MAAMC,EAdC,CACLC,QAAS,EACTC,OACE,QAASC,KAAKF,UAYZG,EAA+D,GAErE,MAAO,CACLC,IAAIC,EAA+BC,GACjC,MACMC,EADiB,MAAZD,EAAmBA,EAAWP,EAAQE,OAGjD,OADAE,EAAmBI,GAAYF,EACxBE,GAGTC,QAAWC,EAAwBC,EAASC,EAAiCC,GAC3E,MAAMC,EAAiBV,EAAmBM,GAEtCI,IACEF,EAAUC,GACZC,EAAeL,QAAQE,GAEvBG,EAAeC,OAAOF,GAGxBT,EAAmBM,GAAS,QAOVM,GAgBxB,OAdAlB,EAAWmB,IACT,GAAKA,EAAMC,QAIP,UAAWD,EAAMC,OAAQ,CAC3B,MAAMR,MAAEA,EAAFC,KAASA,EAATE,MAAeA,GAAUI,EAAMC,OAEjCR,GACFX,EAAgBU,QAAQC,EAAOC,EAAOE,IAAYA,EAAQA,kBAK7BM,GACjC,WAAWC,QAAQ,CAACX,EAASM,KAC3B,MAAML,EAAQX,EAAgBM,IAAI,CAAEI,QAAAA,EAASM,OAAAA,IAE7ClB,EAAOa,KAAUS,MC3DvB,IAAKE,GAAL,SAAKA,GACHA,gBACAA,sBACAA,4BACAA,kCACAA,2CACAA,8CANF,CAAKA,IAAAA,OA0GL,MAAMC,EAAe,SACfC,EAAgB,UAkBhBC,EAA4B,oBAAXC,QAA2BA,OAAeC,cAC3DC,EAAwB,oBAAXF,QAA2BA,OAAeG,QAAWH,OAAeG,OAAOC,gBACxFC,EAAwB,oBAAXL,QAA2BA,OAAOM,MAAQN,SAAaA,OAAeO,UAAaP,OAAeO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KAClB,MAAMC,EAASrG,GAAQF,OAAeG,OAAOC,gBAAgB0B,OAC7D,OAAO0E,QAAQzG,GAAWwG,GAAUlG,IAqDpCoG,SAlDgBrI,GACf2B,GAAsC,mBAApBA,EAAQ3B,IAC1B8B,GAAOA,EAAI9B,IAA8C,mBAA5B8B,EAAI9B,GAAQuC,aACzCN,GAA8B,mBAAhBA,EAAIjC,GAgDnBsD,IAAAA,EACAgF,oBAAqB9B,EACrB+B,qBAAsB9B,IAIX+B"}
@@ -1,2 +1,2 @@
1
- function e(e,n){var t,o,i=(t={current:0,next:function(){return++this.current}},o={},{add:function(e,n){var i=null!=n?n:t.next();return o[i]=e,i},resolve:function(e,n,t,i){var r=o[e];r&&(t(i)?r.resolve(n):r.reject(i),o[e]=null)}});return n(function(e){if(e.detail&&"reqId"in e.detail){var n=e.detail,t=n.reqId;t&&i.resolve(t,n.data,function(e){return!e},n.error)}}),function(){var n=arguments;return new Promise(function(t,o){var r=i.add({resolve:t,reject:o});e.apply(void 0,[r].concat([].slice.call(n)))})}}var n;!function(e){e.getMe="GetMe",e.getPhone="GetPhone",e.getContacts="GetContacts",e.enableNotifications="AllowNotifications",e.disableNotifications="DisableNotifications"}(n||(n={}));var t="invoke",o="storage",i="undefined"!=typeof window&&window.AndroidBridge,r="undefined"!=typeof window&&window.webkit&&window.webkit.messageHandlers,a="undefined"!=typeof window&&window.top!==window&&(window.WebBridge=window.WebBridge||{});if(a){var s=window.AITU_ORIGIN||"https://aitu.io";[t,o].forEach(function(e){a[e]||(a[e]=function(){return window.top.postMessage(JSON.stringify({method:e,payload:[].slice.call(arguments)}),s)})}),window.addEventListener("message",function(e){if(e.origin===s&&e.data)try{var n=JSON.parse(e.data);window.dispatchEvent(new CustomEvent("aituEvents",{detail:n}))}catch(e){}})}var d=function(){var s=[];"undefined"!=typeof window&&window.addEventListener("aituEvents",function(e){[].concat(s).map(function(n){return n.call(null,e)})});var d,c,l,u=function(e){s.push(e)},f=(d={current:0,next:function(){return++this.current}},c={},l={add:function(e,n){var t=null!=n?n:d.next();return c[t]=e,t},resolve:function(e,n,t,o){var i=c[e];i&&(t(o)?i.resolve(n):i.reject(o),c[e]=null)}},u(function(e){if(e.detail&&"reqId"in e.detail){var n=e.detail,t=n.reqId;t&&l.resolve(t,n.data,function(e){return!e},n.error)}}),function(e,n){return void 0===n&&(n={}),new Promise(function(o,s){!function(e,n,o){void 0===o&&(o={});var s=r&&r[t],d=a&&a[t];i&&i[t]?i[t](e,n,JSON.stringify(o)):s?r[t].postMessage({reqId:e,method:n,data:o}):d?a[t](e,n,o):"undefined"!=typeof window&&console.log("--invoke-isUnknown")}(l.add({resolve:o,reject:s},n.reqId),e,n)})}),g=function(e,n){var t,o,i=(t={current:0,next:function(){return++this.current}},o={},{add:function(e,n){var i="s"+(null!=n?n:t.next());return o[i]=e,i},resolve:function(e,n,t,i){var r=o[e];r&&(t(i)?r.resolve(n):r.reject(i),o[e]=null)}});return n(function(e){if(e.detail&&"reqId"in e.detail){var n=e.detail,t=n.reqId;t&&i.resolve(t,n.data,function(e){return!e},n.error)}}),{setItem:function(n,t){return new Promise(function(o,r){var a=i.add({resolve:o,reject:r});e(a,"setItem",{keyName:n,keyValue:t})})},getItem:function(n){return new Promise(function(t,o){var r=i.add({resolve:t,reject:o});e(r,"getItem",{keyName:n})})},clear:function(){return new Promise(function(n,t){var o=i.add({resolve:n,reject:t});e(o,"clear",{})})}}}(function(e,n,t){void 0===t&&(t={});var s=r&&r[o],d=a&&a[o];i&&i[o]?i[o](e,n,JSON.stringify(t)):s?r[o].postMessage({reqId:e,method:n,data:t}):d?a[o](e,n,t):"undefined"!=typeof window&&console.log("--storage-isUnknown")},u),p=e(function(e){var n=r&&r.getGeo;i&&i.getGeo?i.getGeo(e):n?r.getGeo.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getGeo-isWeb")},u),w=e(function(e){var n=r&&r.getQr;i&&i.getQr?i.getQr(e):n?r.getQr.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getQr-isWeb")},u),v=e(function(e){var n=r&&r.getSMSCode;i&&i.getSMSCode?i.getSMSCode(e):n?r.getSMSCode.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getSMSCode-isWeb")},u),b=e(function(e){var n=r&&r.selectContact;i&&i.selectContact?i.selectContact(e):n?r.selectContact.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--selectContact-isWeb")},u),h=e(function(e){var n=r&&r.openSettings;i&&i.openSettings?i.openSettings(e):n?r.openSettings.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--openSettings-isWeb")},u),y=e(function(e){var n=r&&r.closeApplication;i&&i.closeApplication?i.closeApplication(e):n?r.closeApplication.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--closeApplication-isWeb")},u),I=e(function(e,n){var t=r&&r.share;i&&i.share?i.share(e,n):t?r.share.postMessage({reqId:e,text:n}):"undefined"!=typeof window&&console.log("--share-isWeb")},u),S=e(function(e,n){var t=r&&r.setTitle;i&&i.setTitle?i.setTitle(e,n):t?r.setTitle.postMessage({reqId:e,text:n}):"undefined"!=typeof window&&console.log("--setTitle-isWeb")},u),M=e(function(e,n){var t=r&&r.copyToClipboard;i&&i.copyToClipboard?i.copyToClipboard(e,n):t?r.copyToClipboard.postMessage({reqId:e,text:n}):"undefined"!=typeof window&&console.log("--copyToClipboard-isWeb")},u),m=e(function(e,n,t){var o=r&&r.shareFile,a=t;i&&i.shareFile?i.shareFile(e,n,"image",a):o?r.shareFile.postMessage({reqId:e,text:n,filename:"image",base64Data:a}):"undefined"!=typeof window&&console.log("--shareFile-isWeb")},u),C=e(function(e,n,t,o){var a=r&&r.shareFile;i&&i.shareFile?i.shareFile(e,n,t,o):a?r.shareFile.postMessage({reqId:e,text:n,filename:t,base64Data:o}):"undefined"!=typeof window&&console.log("--shareFile-isWeb")},u),q=e(function(e,n){if(!Array.isArray(n)||n.some(function(e){return e<1||e!==Math.floor(e)})||n.reduce(function(e,n){return e+n})>1e4)console.error("Pattern should be an array of positive integers no longer than 10000ms total");else{var t=r&&r.vibrate;i&&i.vibrate?i.vibrate(e,JSON.stringify(n)):t?r.vibrate.postMessage({reqId:e,pattern:n}):"undefined"!=typeof window&&console.log("--vibrate-isWeb")}},u);return{copyToClipboard:M,invoke:f,storage:g,getMe:function(){return f(n.getMe)},getPhone:function(){return f(n.getPhone)},getContacts:function(){return f(n.getContacts)},getGeo:p,getQr:w,getSMSCode:v,selectContact:b,enableNotifications:function(){return f(n.enableNotifications)},disableNotifications:function(){return f(n.disableNotifications)},openSettings:h,closeApplication:y,setTitle:S,share:I,shareImage:m,shareFile:C,setShakeHandler:function(e){i&&i.setShakeHandler||r&&r.setShakeHandler?window.onAituBridgeShake=e:"undefined"!=typeof window&&console.log("--setShakeHandler-isWeb")},vibrate:q,isSupported:function(){var e=r&&window.webkit.messageHandlers.invoke;return Boolean(i||e||a)},supports:function(e){return i&&"function"==typeof i[e]||r&&r[e]&&"function"==typeof r[e].postMessage||a&&"function"==typeof a[e]},sub:u}}();export default d;
1
+ function e(e,n){var t,o,i=(t={current:0,next:function(){return++this.current}},o={},{add:function(e,n){var i=null!=n?n:t.next();return o[i]=e,i},resolve:function(e,n,t,i){var r=o[e];r&&(t(i)?r.resolve(n):r.reject(i),o[e]=null)}});return n(function(e){if(e.detail&&"reqId"in e.detail){var n=e.detail,t=n.reqId;t&&i.resolve(t,n.data,function(e){return!e},n.error)}}),function(){var n=arguments;return new Promise(function(t,o){var r=i.add({resolve:t,reject:o});e.apply(void 0,[r].concat([].slice.call(n)))})}}var n;!function(e){e.getMe="GetMe",e.getPhone="GetPhone",e.getContacts="GetContacts",e.getUserProfile="GetUserProfile",e.enableNotifications="AllowNotifications",e.disableNotifications="DisableNotifications"}(n||(n={}));var t="invoke",o="storage",i="undefined"!=typeof window&&window.AndroidBridge,r="undefined"!=typeof window&&window.webkit&&window.webkit.messageHandlers,a="undefined"!=typeof window&&window.top!==window&&(window.WebBridge=window.WebBridge||{});if(a){var s=window.AITU_ORIGIN||"https://aitu.io";[t,o].forEach(function(e){a[e]||(a[e]=function(){return window.top.postMessage(JSON.stringify({method:e,payload:[].slice.call(arguments)}),s)})}),window.addEventListener("message",function(e){if(e.origin===s&&e.data)try{var n=JSON.parse(e.data);window.dispatchEvent(new CustomEvent("aituEvents",{detail:n}))}catch(e){}})}var d=function(){var s=[];"undefined"!=typeof window&&window.addEventListener("aituEvents",function(e){[].concat(s).map(function(n){return n.call(null,e)})});var d,l,c,u=function(e){s.push(e)},f=(d={current:0,next:function(){return++this.current}},l={},c={add:function(e,n){var t=null!=n?n:d.next();return l[t]=e,t},resolve:function(e,n,t,o){var i=l[e];i&&(t(o)?i.resolve(n):i.reject(o),l[e]=null)}},u(function(e){if(e.detail&&"reqId"in e.detail){var n=e.detail,t=n.reqId;t&&c.resolve(t,n.data,function(e){return!e},n.error)}}),function(e,n){return void 0===n&&(n={}),new Promise(function(o,s){!function(e,n,o){void 0===o&&(o={});var s=r&&r[t],d=a&&a[t];i&&i[t]?i[t](e,n,JSON.stringify(o)):s?r[t].postMessage({reqId:e,method:n,data:o}):d?a[t](e,n,o):"undefined"!=typeof window&&console.log("--invoke-isUnknown")}(c.add({resolve:o,reject:s},n.reqId),e,n)})}),p=function(e,n){var t,o,i=(t={current:0,next:function(){return++this.current}},o={},{add:function(e,n){var i="s"+(null!=n?n:t.next());return o[i]=e,i},resolve:function(e,n,t,i){var r=o[e];r&&(t(i)?r.resolve(n):r.reject(i),o[e]=null)}});return n(function(e){if(e.detail&&"reqId"in e.detail){var n=e.detail,t=n.reqId;t&&i.resolve(t,n.data,function(e){return!e},n.error)}}),{setItem:function(n,t){return new Promise(function(o,r){var a=i.add({resolve:o,reject:r});e(a,"setItem",{keyName:n,keyValue:t})})},getItem:function(n){return new Promise(function(t,o){var r=i.add({resolve:t,reject:o});e(r,"getItem",{keyName:n})})},clear:function(){return new Promise(function(n,t){var o=i.add({resolve:n,reject:t});e(o,"clear",{})})}}}(function(e,n,t){void 0===t&&(t={});var s=r&&r[o],d=a&&a[o];i&&i[o]?i[o](e,n,JSON.stringify(t)):s?r[o].postMessage({reqId:e,method:n,data:t}):d?a[o](e,n,t):"undefined"!=typeof window&&console.log("--storage-isUnknown")},u),g=e(function(e){var n=r&&r.getGeo;i&&i.getGeo?i.getGeo(e):n?r.getGeo.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getGeo-isWeb")},u),w=e(function(e){var n=r&&r.getQr;i&&i.getQr?i.getQr(e):n?r.getQr.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getQr-isWeb")},u),v=e(function(e){var n=r&&r.getSMSCode;i&&i.getSMSCode?i.getSMSCode(e):n?r.getSMSCode.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getSMSCode-isWeb")},u),b=e(function(e){var n=r&&r.selectContact;i&&i.selectContact?i.selectContact(e):n?r.selectContact.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--selectContact-isWeb")},u),h=e(function(e){var n=r&&r.openSettings;i&&i.openSettings?i.openSettings(e):n?r.openSettings.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--openSettings-isWeb")},u),y=e(function(e){var n=r&&r.closeApplication;i&&i.closeApplication?i.closeApplication(e):n?r.closeApplication.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--closeApplication-isWeb")},u),S=e(function(e,n){var t=r&&r.share;i&&i.share?i.share(e,n):t?r.share.postMessage({reqId:e,text:n}):"undefined"!=typeof window&&console.log("--share-isWeb")},u),M=e(function(e,n){var t=r&&r.setTitle;i&&i.setTitle?i.setTitle(e,n):t?r.setTitle.postMessage({reqId:e,text:n}):"undefined"!=typeof window&&console.log("--setTitle-isWeb")},u),C=e(function(e,n){var t=r&&r.copyToClipboard;i&&i.copyToClipboard?i.copyToClipboard(e,n):t?r.copyToClipboard.postMessage({reqId:e,text:n}):"undefined"!=typeof window&&console.log("--copyToClipboard-isWeb")},u),I=e(function(e,n,t){var o=i&&i.shareFile,a=r&&r.shareFile,s="image."+t.split(";")[0].split("/")[1],d=t.substr(t.indexOf(",")+1);o?i.shareFile(e,n,s,d):a?r.shareFile.postMessage({reqId:e,text:n,filename:s,base64Data:d}):"undefined"!=typeof window&&console.log("--shareFile-isWeb")},u),m=e(function(e,n,t,o){var a=r&&r.shareFile;i&&i.shareFile?i.shareFile(e,n,t,o):a?r.shareFile.postMessage({reqId:e,text:n,filename:t,base64Data:o}):"undefined"!=typeof window&&console.log("--shareFile-isWeb")},u),q=e(function(e,n){if(!Array.isArray(n)||n.some(function(e){return e<1||e!==Math.floor(e)})||n.reduce(function(e,n){return e+n})>1e4)console.error("Pattern should be an array of positive integers no longer than 10000ms total");else{var t=r&&r.vibrate;i&&i.vibrate?i.vibrate(e,JSON.stringify(n)):t?r.vibrate.postMessage({reqId:e,pattern:n}):"undefined"!=typeof window&&console.log("--vibrate-isWeb")}},u),A=e(function(){var e=r&&r.enableScreenCaptureMethod;i&&i.enableScreenCaptureMethod?i.enableScreenCaptureMethod():e?r.enableScreenCaptureMethod.postMessage({}):"undefined"!=typeof window&&console.log("--enableScreenCapture-isWeb")},u),T=e(function(){var e=r&&r.disableScreenCaptureMethod;i&&i.disableScreenCaptureMethod?i.disableScreenCaptureMethod():e?r.disableScreenCaptureMethod.postMessage({}):"undefined"!=typeof window&&console.log("--disableScreenCapture-isWeb")},u);return{copyToClipboard:C,invoke:f,storage:p,getMe:function(){return f(n.getMe)},getPhone:function(){return f(n.getPhone)},getContacts:function(){return f(n.getContacts)},getGeo:g,getQr:w,getSMSCode:v,getUserProfile:function(e){return f(n.getUserProfile,{id:e})},selectContact:b,enableNotifications:function(){return f(n.enableNotifications)},disableNotifications:function(){return f(n.disableNotifications)},openSettings:h,closeApplication:y,setTitle:M,share:S,shareImage:I,shareFile:m,setShakeHandler:function(e){i&&i.setShakeHandler||r&&r.setShakeHandler?window.onAituBridgeShake=e:"undefined"!=typeof window&&console.log("--setShakeHandler-isWeb")},setTabActiveHandler:function(e){i&&i.setTabActiveHandler||r&&r.setTabActiveHandler?window.onAituBridgeTabActive=e:"undefined"!=typeof window&&console.log("--setTabActiveHandler-isWeb")},vibrate:q,isSupported:function(){var e=r&&window.webkit.messageHandlers.invoke;return Boolean(i||e||a)},supports:function(e){return i&&"function"==typeof i[e]||r&&r[e]&&"function"==typeof r[e].postMessage||a&&"function"==typeof a[e]},sub:u,enableScreenCapture:A,disableScreenCapture:T}}();export default d;
2
2
  //# sourceMappingURL=index.module.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.module.js","sources":["../src/promisifyMethod.ts","../src/index.ts","../src/promisifyInvoke.ts","../src/promisifyStorage.ts"],"sourcesContent":["function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n}\n\nfunction createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n\n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n\n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const methodId = id;\n promiseControllers[methodId] = controller;\n return methodId;\n },\n\n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n\n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n\n promiseControllers[reqId] = null;\n }\n },\n };\n}\n\nfunction promisifyMethod(method, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n\n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n\n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n\n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return function promisifiedFunc(...args: any[]): Promise<any | void> {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n\n method(reqId, ...args);\n });\n };\n}\n\nexport default promisifyMethod;\n","import promisifyInvoke from './promisifyInvoke';\nimport promisifyStorage from './promisifyStorage';\nimport promisifyMethod from './promisifyMethod';\n\nenum EInvokeRequest {\n getMe = 'GetMe',\n getPhone = 'GetPhone',\n getContacts = 'GetContacts',\n enableNotifications = 'AllowNotifications',\n disableNotifications = 'DisableNotifications'\n}\n\ntype SetItemType = (keyName: string, keyValue: string) => Promise<void>;\ntype GetItemType = (keyName: string) => Promise<string | null>;\ntype ClearType = () => Promise<void>;\n\ninterface GetPhoneResponse {\n phone: string;\n sign: string;\n}\n\ninterface GetMeResponse {\n name: string;\n lastname: string;\n id: string;\n avatar?: string;\n avatarThumb?: string;\n sign: string;\n}\n\ninterface ResponseObject {\n phone?: string;\n name?: string;\n lastname?: string;\n}\n\ninterface GetGeoResponse {\n latitude: number;\n longitude: number;\n}\n\ninterface GetContactsResponse {\n contacts: Array<{\n first_name: string;\n last_name: string;\n phone: string;\n }>;\n sign: string;\n}\n\ninterface SelectContactResponse {\n phone: string;\n name: string;\n lastname: string;\n}\n\ntype OpenSettingsResponse = 'success' | 'failed';\ntype ShareResponse = 'success' | 'failed';\ntype CopyToClipboardResponse = 'success' | 'failed';\ntype VibrateResponse = 'success' | 'failed';\n// todo: remove duplicates\ntype ResponseType = 'success' | 'failed';\n\ntype BridgeInvoke<T extends EInvokeRequest, R> = (method: T, data?: {}) => Promise<R>;\n\ninterface BridgeStorage {\n setItem: SetItemType,\n getItem: GetItemType,\n clear: ClearType\n}\n\ninterface AituBridge {\n invoke: BridgeInvoke<EInvokeRequest, ResponseObject>;\n storage: BridgeStorage;\n getMe: () => Promise<GetMeResponse>;\n getPhone: () => Promise<GetPhoneResponse>;\n getContacts: () => Promise<GetContactsResponse>;\n getGeo: () => Promise<GetGeoResponse>;\n selectContact: () => Promise<SelectContactResponse>;\n getQr: () => Promise<string>;\n getSMSCode: () => Promise<string>;\n share: (text: string) => Promise<ShareResponse>;\n setTitle: (text: string) => Promise<ResponseType>;\n copyToClipboard: (text: string) => Promise<CopyToClipboardResponse>;\n shareImage: (text: string, image: string) => Promise<ShareResponse>;\n shareFile: (text: string, filename: string, base64Data: string) => Promise<ShareResponse>;\n enableNotifications: () => Promise<{}>;\n disableNotifications: () => Promise<{}>;\n openSettings: () => Promise<OpenSettingsResponse>;\n closeApplication: () => Promise<ResponseType>;\n setShakeHandler: (handler: any) => void;\n vibrate: (pattern: number[]) => Promise<VibratePattern>;\n isSupported: () => boolean;\n supports: (method: string) => boolean;\n sub: any;\n}\n\nconst invokeMethod = 'invoke';\nconst storageMethod = 'storage';\nconst getGeoMethod = 'getGeo';\nconst getQrMethod = 'getQr';\nconst getSMSCodeMethod = 'getSMSCode';\nconst selectContactMethod = 'selectContact';\nconst openSettingsMethod = 'openSettings';\nconst closeApplicationMethod = 'closeApplication';\nconst shareMethod = 'share';\nconst setTitleMethod = 'setTitle';\nconst copyToClipboardMethod = 'copyToClipboard';\nconst shareImageMethod = 'shareImage';\nconst shareFileMethod = 'shareFile';\nconst setShakeHandlerMethod = 'setShakeHandler';\nconst vibrateMethod = 'vibrate';\n\nconst android = typeof window !== 'undefined' && (window as any).AndroidBridge;\nconst ios = typeof window !== 'undefined' && (window as any).webkit && (window as any).webkit.messageHandlers;\nconst web = typeof window !== 'undefined' && (window.top !== window) && ((window as any).WebBridge = (window as any).WebBridge || {});\n\nif (web) {\n const aituOrigin = (window as any).AITU_ORIGIN || 'https://aitu.io';\n\n [invokeMethod, storageMethod].forEach((method) => {\n if (!web[method]) {\n web[method] = (...args) => window.top.postMessage(JSON.stringify({\n method,\n payload: args,\n }), aituOrigin);\n }\n });\n\n window.addEventListener('message', (event) => {\n if (event.origin === aituOrigin && event.data) {\n try {\n const detail = JSON.parse(event.data);\n window.dispatchEvent(new CustomEvent('aituEvents', { detail }));\n } catch(e) {}\n }\n });\n}\n\nconst buildBridge = (): AituBridge => {\n const subs = [];\n\n if (typeof window !== 'undefined') {\n window.addEventListener('aituEvents', (e: any) => {\n [...subs].map((fn) => fn.call(null, e));\n })\n }\n\n const invoke = (reqId, method, data = {}) => {\n const isAndroid = android && android[invokeMethod];\n const isIos = ios && ios[invokeMethod];\n const isWeb = web && web[invokeMethod];\n\n if (isAndroid) {\n android[invokeMethod](reqId, method, JSON.stringify(data));\n } else if (isIos) {\n ios[invokeMethod].postMessage({ reqId, method, data });\n } else if (isWeb) {\n web[invokeMethod](reqId, method, data);\n } else if (typeof window !== 'undefined') {\n console.log('--invoke-isUnknown');\n }\n };\n\n const storage = (reqId, method, data = {}) => {\n const isAndroid = android && android[storageMethod];\n const isIos = ios && ios[storageMethod];\n const isWeb = web && web[storageMethod];\n\n if (isAndroid) {\n android[storageMethod](reqId, method, JSON.stringify(data));\n } else if (isIos) {\n ios[storageMethod].postMessage({ reqId, method, data });\n } else if (isWeb) {\n web[storageMethod](reqId, method, data);\n } else if (typeof window !== 'undefined') {\n console.log('--storage-isUnknown');\n }\n }\n\n const getGeo = (reqId) => {\n const isAndroid = android && android[getGeoMethod];\n const isIos = ios && ios[getGeoMethod];\n\n if (isAndroid) {\n android[getGeoMethod](reqId);\n } else if (isIos) {\n ios[getGeoMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getGeo-isWeb');\n }\n }\n\n const getQr = (reqId) => {\n const isAndroid = android && android[getQrMethod];\n const isIos = ios && ios[getQrMethod];\n\n if (isAndroid) {\n android[getQrMethod](reqId);\n } else if (isIos) {\n ios[getQrMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getQr-isWeb');\n }\n }\n\n const getSMSCode = (reqId) => {\n const isAndroid = android && android[getSMSCodeMethod];\n const isIos = ios && ios[getSMSCodeMethod];\n\n if (isAndroid) {\n android[getSMSCodeMethod](reqId);\n } else if (isIos) {\n ios[getSMSCodeMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getSMSCode-isWeb');\n }\n }\n\n const selectContact = (reqId) => {\n const isAndroid = android && android[selectContactMethod];\n const isIos = ios && ios[selectContactMethod];\n\n if (isAndroid) {\n android[selectContactMethod](reqId);\n } else if (isIos) {\n ios[selectContactMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--selectContact-isWeb');\n }\n }\n\n const openSettings = (reqId) => {\n const isAndroid = android && android[openSettingsMethod];\n const isIos = ios && ios[openSettingsMethod];\n\n if (isAndroid) {\n android[openSettingsMethod](reqId);\n } else if (isIos) {\n ios[openSettingsMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--openSettings-isWeb');\n }\n }\n\n const closeApplication = (reqId) => {\n const isAndroid = android && android[closeApplicationMethod];\n const isIos = ios && ios[closeApplicationMethod];\n\n if (isAndroid) {\n android[closeApplicationMethod](reqId);\n } else if (isIos) {\n ios[closeApplicationMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--closeApplication-isWeb');\n }\n }\n\n const share = (reqId, text) => {\n const isAndroid = android && android[shareMethod];\n const isIos = ios && ios[shareMethod];\n\n if (isAndroid) {\n android[shareMethod](reqId, text);\n } else if (isIos) {\n ios[shareMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--share-isWeb');\n }\n }\n\n const setTitle = (reqId, text) => {\n const isAndroid = android && android[setTitleMethod];\n const isIos = ios && ios[setTitleMethod];\n\n if (isAndroid) {\n android[setTitleMethod](reqId, text);\n } else if (isIos) {\n ios[setTitleMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--setTitle-isWeb');\n }\n }\n\n const copyToClipboard = (reqId, text) => {\n const isAndroid = android && android[copyToClipboardMethod];\n const isIos = ios && ios[copyToClipboardMethod];\n\n if (isAndroid) {\n android[copyToClipboardMethod](reqId, text);\n } else if (isIos) {\n ios[copyToClipboardMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--copyToClipboard-isWeb');\n }\n }\n\n const shareImage = (reqId, text, image) => {\n // !!!======================!!!\n // !!!===== Deprecated =====!!!\n // !!!======================!!!\n\n // const isAndroid = android && android[shareImageMethod];\n // const isIos = ios && ios[shareImageMethod];\n\n // if (isAndroid) {\n // android[shareImageMethod](reqId, text, image);\n // } else if (isIos) {\n // ios[shareImageMethod].postMessage({ reqId, text, image });\n // } else if (typeof window !== 'undefined') {\n // console.log('--shareImage-isWeb');\n // }\n\n // new one - fallback to shareFile\n const isAndroid = android && android[shareFileMethod];\n const isIos = ios && ios[shareFileMethod];\n\n const filename = 'image';\n const base64Data = image;\n\n if (isAndroid) {\n android[shareFileMethod](reqId, text, filename, base64Data);\n } else if (isIos) {\n ios[shareFileMethod].postMessage({ reqId, text, filename, base64Data });\n } else if (typeof window !== 'undefined') {\n console.log('--shareFile-isWeb');\n }\n }\n\n const shareFile = (reqId, text, filename, base64Data) => {\n const isAndroid = android && android[shareFileMethod];\n const isIos = ios && ios[shareFileMethod];\n\n if (isAndroid) {\n android[shareFileMethod](reqId, text, filename, base64Data);\n } else if (isIos) {\n ios[shareFileMethod].postMessage({ reqId, text, filename, base64Data });\n } else if (typeof window !== 'undefined') {\n console.log('--shareFile-isWeb');\n }\n }\n\n const enableNotifications = () => invokePromise(EInvokeRequest.enableNotifications);\n\n const disableNotifications = () => invokePromise(EInvokeRequest.disableNotifications);\n\n const setShakeHandler = (handler) => {\n const isAndroid = android && android[setShakeHandlerMethod];\n const isIos = ios && ios[setShakeHandlerMethod];\n\n if (isAndroid || isIos) {\n (window as any).onAituBridgeShake = handler;\n } else if (typeof window !== 'undefined') {\n console.log('--setShakeHandler-isWeb');\n }\n };\n\n const vibrate = (reqId, pattern) => {\n if (\n !Array.isArray(pattern) ||\n pattern.some((timing) => timing < 1 || timing !== Math.floor(timing)) ||\n pattern.reduce((total, timing) => total + timing) > 10000\n ) {\n console.error('Pattern should be an array of positive integers no longer than 10000ms total');\n return;\n }\n\n const isAndroid = android && android[vibrateMethod];\n const isIos = ios && ios[vibrateMethod];\n\n if (isAndroid) {\n android[vibrateMethod](reqId, JSON.stringify(pattern));\n } else if (isIos) {\n ios[vibrateMethod].postMessage({ reqId, pattern });\n } else if (typeof window !== 'undefined') {\n console.log('--vibrate-isWeb');\n }\n }\n\n const isSupported = () => {\n const iosSup = ios && (window as any).webkit.messageHandlers.invoke;\n return Boolean(android || iosSup || web);\n }\n\n const supports = (method) =>\n (android && typeof android[method] === 'function') ||\n (ios && ios[method] && typeof ios[method].postMessage === 'function') ||\n (web && typeof web[method] === 'function');\n\n const sub = (listener: any) => {\n subs.push(listener);\n }\n\n const invokePromise = promisifyInvoke(invoke, sub);\n const storagePromise = promisifyStorage(storage, sub);\n const getGeoPromise = promisifyMethod(getGeo, sub);\n const getQrPromise = promisifyMethod(getQr, sub);\n const getSMSCodePromise = promisifyMethod(getSMSCode, sub);\n const selectContactPromise = promisifyMethod(selectContact, sub);\n const openSettingsPromise = promisifyMethod(openSettings, sub);\n const closeApplicationPromise = promisifyMethod(closeApplication, sub);\n const sharePromise = promisifyMethod(share, sub);\n const setTitlePromise = promisifyMethod(setTitle, sub);\n const copyToClipboardPromise = promisifyMethod(copyToClipboard, sub);\n const shareImagePromise = promisifyMethod(shareImage, sub);\n const shareFilePromise = promisifyMethod(shareFile, sub);\n const vibratePromise = promisifyMethod(vibrate, sub);\n\n return {\n copyToClipboard: copyToClipboardPromise,\n invoke: invokePromise,\n storage: storagePromise,\n getMe: () => invokePromise(EInvokeRequest.getMe),\n getPhone: () => invokePromise(EInvokeRequest.getPhone),\n getContacts: () => invokePromise(EInvokeRequest.getContacts),\n getGeo: getGeoPromise,\n getQr: getQrPromise,\n getSMSCode: getSMSCodePromise,\n selectContact: selectContactPromise,\n enableNotifications,\n disableNotifications,\n openSettings: openSettingsPromise,\n closeApplication: closeApplicationPromise,\n setTitle: setTitlePromise,\n share: sharePromise,\n shareImage: shareImagePromise,\n shareFile: shareFilePromise,\n setShakeHandler,\n vibrate: vibratePromise,\n isSupported,\n supports,\n sub\n }\n}\n\nconst bridge = buildBridge();\n\nexport default bridge;\n","function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n}\n\nfunction createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n\n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n\n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const invokeId = id;\n promiseControllers[invokeId] = controller;\n return invokeId;\n },\n\n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n\n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n\n promiseControllers[reqId] = null;\n }\n },\n };\n}\n\nfunction promisifyInvoke(invoke, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n\n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n\n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n\n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return function promisifiedFunc(method: any, props: any = {}): Promise<any | void> {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject }, props.reqId);\n\n invoke(reqId, method, props);\n });\n };\n}\n\nexport default promisifyInvoke;\n","function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n }\n \n function createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n \n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n \n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const storageId = `s${id}`;\n promiseControllers[storageId] = controller;\n return storageId;\n },\n \n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n \n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n \n promiseControllers[reqId] = null;\n }\n },\n };\n }\n \n function promisifyStorage(storage, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n \n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n \n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n \n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return {\n setItem: (keyName: string, keyValue: string): Promise<void> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'setItem', { keyName, keyValue });\n });\n },\n getItem: (keyName: string): Promise<string | null> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'getItem', { keyName });\n });\n },\n clear: (): Promise<void> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'clear', {});\n });\n },\n }\n }\n \n export default promisifyStorage;\n "],"names":["promisifyMethod","method","subscribe","counter","promiseControllers","requestResolver","current","next","this","add","controller","customId","methodId","resolve","reqId","data","isSuccess","error","requestPromise","reject","event","detail","Promise","EInvokeRequest","invokeMethod","storageMethod","android","window","AndroidBridge","ios","webkit","messageHandlers","web","top","WebBridge","aituOrigin","AITU_ORIGIN","forEach","postMessage","JSON","stringify","payload","addEventListener","origin","parse","dispatchEvent","CustomEvent","e","bridge","subs","map","fn","call","sub","listener","push","invokePromise","invokeId","props","isIos","isWeb","console","log","invoke","storagePromise","storage","storageId","setItem","keyName","keyValue","getItem","clear","promisifyStorage","getGeoPromise","getQrPromise","getSMSCodePromise","selectContactPromise","openSettingsPromise","closeApplicationPromise","sharePromise","text","setTitlePromise","copyToClipboardPromise","shareImagePromise","image","base64Data","filename","shareFilePromise","vibratePromise","pattern","Array","isArray","some","timing","Math","floor","reduce","total","copyToClipboard","getMe","getPhone","getContacts","getGeo","getQr","getSMSCode","selectContact","enableNotifications","disableNotifications","openSettings","closeApplication","setTitle","share","shareImage","shareFile","setShakeHandler","handler","onAituBridgeShake","vibrate","isSupported","iosSup","Boolean","supports","buildBridge"],"mappings":"AA0CA,SAASA,EAAgBC,EAAQC,GAC/B,I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8E7DC,qBA5E2B,kBAAMnD,EAAcjC,EAAeoF,uBA6E9DC,aAAc/B,EACdgC,iBAAkB/B,EAClBgC,SAAU7B,EACV8B,MAAOhC,EACPiC,WAAY7B,EACZ8B,UAAW1B,EACX2B,gBAjFsB,SAACC,GACLzF,GAAWA,EAAO,iBACtBG,GAAOA,EAAG,gBAGrBF,OAAeyF,kBAAoBD,EACT,oBAAXxF,QAChBkC,QAAQC,IAAI,4BA2EduD,QAAS7B,EACT8B,YAlDkB,WAClB,IAAMC,EAAS1F,GAAQF,OAAeG,OAAOC,gBAAgBgC,OAC7D,OAAOyD,QAAQ9F,GAAW6F,GAAUvF,IAiDpCyF,SA9Ce,SAACxH,UACfyB,GAAsC,mBAApBA,EAAQzB,IAC1B4B,GAAOA,EAAI5B,IAA8C,mBAA5B4B,EAAI5B,GAAQqC,aACzCN,GAA8B,mBAAhBA,EAAI/B,IA4CnBoD,IAAAA,GAIWqE"}
1
+ {"version":3,"file":"index.module.js","sources":["../src/promisifyMethod.ts","../src/index.ts","../src/promisifyInvoke.ts","../src/promisifyStorage.ts"],"sourcesContent":["function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n}\n\nfunction createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n\n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n\n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const methodId = id;\n promiseControllers[methodId] = controller;\n return methodId;\n },\n\n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n\n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n\n promiseControllers[reqId] = null;\n }\n },\n };\n}\n\nfunction promisifyMethod(method, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n\n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n\n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n\n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return function promisifiedFunc(...args: any[]): Promise<any | void> {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n\n method(reqId, ...args);\n });\n };\n}\n\nexport default promisifyMethod;\n","import promisifyInvoke from './promisifyInvoke';\nimport promisifyStorage from './promisifyStorage';\nimport promisifyMethod from './promisifyMethod';\n\nenum EInvokeRequest {\n getMe = 'GetMe',\n getPhone = 'GetPhone',\n getContacts = 'GetContacts',\n getUserProfile = 'GetUserProfile',\n enableNotifications = 'AllowNotifications',\n disableNotifications = 'DisableNotifications'\n}\n\ntype SetItemType = (keyName: string, keyValue: string) => Promise<void>;\ntype GetItemType = (keyName: string) => Promise<string | null>;\ntype ClearType = () => Promise<void>;\n\ninterface GetPhoneResponse {\n phone: string;\n sign: string;\n}\n\ninterface GetMeResponse {\n name: string;\n lastname: string;\n id: string;\n avatar?: string;\n avatarThumb?: string;\n sign: string;\n}\n\ninterface ResponseObject {\n phone?: string;\n name?: string;\n lastname?: string;\n}\n\ninterface GetGeoResponse {\n latitude: number;\n longitude: number;\n}\n\ninterface GetContactsResponse {\n contacts: Array<{\n first_name: string;\n last_name: string;\n phone: string;\n }>;\n sign: string;\n}\n\ninterface SelectContactResponse {\n phone: string;\n name: string;\n lastname: string;\n}\n\ninterface GetUserProfileResponse {\n name: string;\n lastname?: string;\n phone?: string;\n avatar?: string;\n avatarThumb?: string;\n}\n\ntype OpenSettingsResponse = 'success' | 'failed';\ntype ShareResponse = 'success' | 'failed';\ntype CopyToClipboardResponse = 'success' | 'failed';\ntype VibrateResponse = 'success' | 'failed';\n// todo: remove duplicates\ntype ResponseType = 'success' | 'failed';\n\ntype BridgeInvoke<T extends EInvokeRequest, R> = (method: T, data?: {}) => Promise<R>;\n\ninterface BridgeStorage {\n setItem: SetItemType,\n getItem: GetItemType,\n clear: ClearType\n}\n\ninterface AituBridge {\n invoke: BridgeInvoke<EInvokeRequest, ResponseObject>;\n storage: BridgeStorage;\n getMe: () => Promise<GetMeResponse>;\n getPhone: () => Promise<GetPhoneResponse>;\n getContacts: () => Promise<GetContactsResponse>;\n getGeo: () => Promise<GetGeoResponse>;\n selectContact: () => Promise<SelectContactResponse>;\n getQr: () => Promise<string>;\n getSMSCode: () => Promise<string>;\n getUserProfile: (userId: string) => Promise<GetUserProfileResponse>;\n share: (text: string) => Promise<ShareResponse>;\n setTitle: (text: string) => Promise<ResponseType>;\n copyToClipboard: (text: string) => Promise<CopyToClipboardResponse>;\n shareImage: (text: string, image: string) => Promise<ShareResponse>;\n shareFile: (text: string, filename: string, base64Data: string) => Promise<ShareResponse>;\n enableNotifications: () => Promise<{}>;\n disableNotifications: () => Promise<{}>;\n openSettings: () => Promise<OpenSettingsResponse>;\n closeApplication: () => Promise<ResponseType>;\n setShakeHandler: (handler: any) => void;\n setTabActiveHandler: (handler: (tabname: string) => void) => void;\n vibrate: (pattern: number[]) => Promise<VibratePattern>;\n isSupported: () => boolean;\n supports: (method: string) => boolean;\n sub: any;\n enableScreenCapture: () => Promise<{}>;\n disableScreenCapture: () => Promise<{}>;\n}\n\nconst invokeMethod = 'invoke';\nconst storageMethod = 'storage';\nconst getGeoMethod = 'getGeo';\nconst getQrMethod = 'getQr';\nconst getSMSCodeMethod = 'getSMSCode';\nconst selectContactMethod = 'selectContact';\nconst openSettingsMethod = 'openSettings';\nconst closeApplicationMethod = 'closeApplication';\nconst shareMethod = 'share';\nconst setTitleMethod = 'setTitle';\nconst copyToClipboardMethod = 'copyToClipboard';\nconst shareImageMethod = 'shareImage';\nconst shareFileMethod = 'shareFile';\nconst setShakeHandlerMethod = 'setShakeHandler';\nconst vibrateMethod = 'vibrate';\nconst enableScreenCaptureMethod = 'enableScreenCaptureMethod';\nconst disableScreenCaptureMethod = 'disableScreenCaptureMethod';\nconst setTabActiveHandlerMethod = 'setTabActiveHandler';\n\nconst android = typeof window !== 'undefined' && (window as any).AndroidBridge;\nconst ios = typeof window !== 'undefined' && (window as any).webkit && (window as any).webkit.messageHandlers;\nconst web = typeof window !== 'undefined' && (window.top !== window) && ((window as any).WebBridge = (window as any).WebBridge || {});\n\nif (web) {\n const aituOrigin = (window as any).AITU_ORIGIN || 'https://aitu.io';\n\n [invokeMethod, storageMethod].forEach((method) => {\n if (!web[method]) {\n web[method] = (...args) => window.top.postMessage(JSON.stringify({\n method,\n payload: args,\n }), aituOrigin);\n }\n });\n\n window.addEventListener('message', (event) => {\n if (event.origin === aituOrigin && event.data) {\n try {\n const detail = JSON.parse(event.data);\n window.dispatchEvent(new CustomEvent('aituEvents', { detail }));\n } catch (e) { }\n }\n });\n}\n\nconst buildBridge = (): AituBridge => {\n const subs = [];\n\n if (typeof window !== 'undefined') {\n window.addEventListener('aituEvents', (e: any) => {\n [...subs].map((fn) => fn.call(null, e));\n })\n }\n\n const invoke = (reqId, method, data = {}) => {\n const isAndroid = android && android[invokeMethod];\n const isIos = ios && ios[invokeMethod];\n const isWeb = web && web[invokeMethod];\n\n if (isAndroid) {\n android[invokeMethod](reqId, method, JSON.stringify(data));\n } else if (isIos) {\n ios[invokeMethod].postMessage({ reqId, method, data });\n } else if (isWeb) {\n web[invokeMethod](reqId, method, data);\n } else if (typeof window !== 'undefined') {\n console.log('--invoke-isUnknown');\n }\n };\n\n const storage = (reqId, method, data = {}) => {\n const isAndroid = android && android[storageMethod];\n const isIos = ios && ios[storageMethod];\n const isWeb = web && web[storageMethod];\n\n if (isAndroid) {\n android[storageMethod](reqId, method, JSON.stringify(data));\n } else if (isIos) {\n ios[storageMethod].postMessage({ reqId, method, data });\n } else if (isWeb) {\n web[storageMethod](reqId, method, data);\n } else if (typeof window !== 'undefined') {\n console.log('--storage-isUnknown');\n }\n }\n\n const getGeo = (reqId) => {\n const isAndroid = android && android[getGeoMethod];\n const isIos = ios && ios[getGeoMethod];\n\n if (isAndroid) {\n android[getGeoMethod](reqId);\n } else if (isIos) {\n ios[getGeoMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getGeo-isWeb');\n }\n }\n\n const getQr = (reqId) => {\n const isAndroid = android && android[getQrMethod];\n const isIos = ios && ios[getQrMethod];\n\n if (isAndroid) {\n android[getQrMethod](reqId);\n } else if (isIos) {\n ios[getQrMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getQr-isWeb');\n }\n }\n\n const getSMSCode = (reqId) => {\n const isAndroid = android && android[getSMSCodeMethod];\n const isIos = ios && ios[getSMSCodeMethod];\n\n if (isAndroid) {\n android[getSMSCodeMethod](reqId);\n } else if (isIos) {\n ios[getSMSCodeMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getSMSCode-isWeb');\n }\n }\n\n const selectContact = (reqId) => {\n const isAndroid = android && android[selectContactMethod];\n const isIos = ios && ios[selectContactMethod];\n\n if (isAndroid) {\n android[selectContactMethod](reqId);\n } else if (isIos) {\n ios[selectContactMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--selectContact-isWeb');\n }\n }\n\n const openSettings = (reqId) => {\n const isAndroid = android && android[openSettingsMethod];\n const isIos = ios && ios[openSettingsMethod];\n\n if (isAndroid) {\n android[openSettingsMethod](reqId);\n } else if (isIos) {\n ios[openSettingsMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--openSettings-isWeb');\n }\n }\n\n const closeApplication = (reqId) => {\n const isAndroid = android && android[closeApplicationMethod];\n const isIos = ios && ios[closeApplicationMethod];\n\n if (isAndroid) {\n android[closeApplicationMethod](reqId);\n } else if (isIos) {\n ios[closeApplicationMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--closeApplication-isWeb');\n }\n }\n\n const share = (reqId, text) => {\n const isAndroid = android && android[shareMethod];\n const isIos = ios && ios[shareMethod];\n\n if (isAndroid) {\n android[shareMethod](reqId, text);\n } else if (isIos) {\n ios[shareMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--share-isWeb');\n }\n }\n\n const setTitle = (reqId, text) => {\n const isAndroid = android && android[setTitleMethod];\n const isIos = ios && ios[setTitleMethod];\n\n if (isAndroid) {\n android[setTitleMethod](reqId, text);\n } else if (isIos) {\n ios[setTitleMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--setTitle-isWeb');\n }\n }\n\n const copyToClipboard = (reqId, text) => {\n const isAndroid = android && android[copyToClipboardMethod];\n const isIos = ios && ios[copyToClipboardMethod];\n\n if (isAndroid) {\n android[copyToClipboardMethod](reqId, text);\n } else if (isIos) {\n ios[copyToClipboardMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--copyToClipboard-isWeb');\n }\n }\n\n const enableScreenCapture = () => {\n const isAndroid = android && android[enableScreenCaptureMethod];\n const isIos = ios && ios[enableScreenCaptureMethod];\n\n if (isAndroid) {\n android[enableScreenCaptureMethod]();\n } else if (isIos) {\n ios[enableScreenCaptureMethod].postMessage({});\n } else if (typeof window !== 'undefined') {\n console.log('--enableScreenCapture-isWeb');\n }\n }\n\n const disableScreenCapture = () => {\n const isAndroid = android && android[disableScreenCaptureMethod];\n const isIos = ios && ios[disableScreenCaptureMethod];\n\n if (isAndroid) {\n android[disableScreenCaptureMethod]();\n } else if (isIos) {\n ios[disableScreenCaptureMethod].postMessage({});\n } else if (typeof window !== 'undefined') {\n console.log('--disableScreenCapture-isWeb');\n }\n }\n\n const shareImage = (reqId, text, image) => {\n // !!!======================!!!\n // !!!===== Deprecated =====!!!\n // !!!======================!!!\n\n // const isAndroid = android && android[shareImageMethod];\n // const isIos = ios && ios[shareImageMethod];\n\n // if (isAndroid) {\n // android[shareImageMethod](reqId, text, image);\n // } else if (isIos) {\n // ios[shareImageMethod].postMessage({ reqId, text, image });\n // } else if (typeof window !== 'undefined') {\n // console.log('--shareImage-isWeb');\n // }\n\n // new one - fallback to shareFile\n const isAndroid = android && android[shareFileMethod];\n const isIos = ios && ios[shareFileMethod];\n\n // get extension from base64 mime type and merge with name\n const ext = image.split(';')[0].split('/')[1];\n const filename = 'image.' + ext;\n // remove mime type\n const base64Data = image.substr(image.indexOf(',') + 1);\n\n if (isAndroid) {\n android[shareFileMethod](reqId, text, filename, base64Data);\n } else if (isIos) {\n ios[shareFileMethod].postMessage({ reqId, text, filename, base64Data });\n } else if (typeof window !== 'undefined') {\n console.log('--shareFile-isWeb');\n }\n }\n\n const shareFile = (reqId, text, filename, base64Data) => {\n const isAndroid = android && android[shareFileMethod];\n const isIos = ios && ios[shareFileMethod];\n\n if (isAndroid) {\n android[shareFileMethod](reqId, text, filename, base64Data);\n } else if (isIos) {\n ios[shareFileMethod].postMessage({ reqId, text, filename, base64Data });\n } else if (typeof window !== 'undefined') {\n console.log('--shareFile-isWeb');\n }\n }\n\n const enableNotifications = () => invokePromise(EInvokeRequest.enableNotifications);\n\n const disableNotifications = () => invokePromise(EInvokeRequest.disableNotifications);\n\n const setShakeHandler = (handler) => {\n const isAndroid = android && android[setShakeHandlerMethod];\n const isIos = ios && ios[setShakeHandlerMethod];\n\n if (isAndroid || isIos) {\n (window as any).onAituBridgeShake = handler;\n } else if (typeof window !== 'undefined') {\n console.log('--setShakeHandler-isWeb');\n }\n };\n\n const setTabActiveHandler = (handler: (tabname: string) => void) => {\n const isAndroid = android && android[setTabActiveHandlerMethod];\n const isIos = ios && ios[setTabActiveHandlerMethod];\n\n if (isAndroid || isIos) {\n (window as any).onAituBridgeTabActive = handler;\n } else if (typeof window !== 'undefined') {\n console.log('--setTabActiveHandler-isWeb');\n }\n };\n\n const vibrate = (reqId, pattern) => {\n if (\n !Array.isArray(pattern) ||\n pattern.some((timing) => timing < 1 || timing !== Math.floor(timing)) ||\n pattern.reduce((total, timing) => total + timing) > 10000\n ) {\n console.error('Pattern should be an array of positive integers no longer than 10000ms total');\n return;\n }\n\n const isAndroid = android && android[vibrateMethod];\n const isIos = ios && ios[vibrateMethod];\n\n if (isAndroid) {\n android[vibrateMethod](reqId, JSON.stringify(pattern));\n } else if (isIos) {\n ios[vibrateMethod].postMessage({ reqId, pattern });\n } else if (typeof window !== 'undefined') {\n console.log('--vibrate-isWeb');\n }\n }\n\n const isSupported = () => {\n const iosSup = ios && (window as any).webkit.messageHandlers.invoke;\n return Boolean(android || iosSup || web);\n }\n\n const supports = (method) =>\n (android && typeof android[method] === 'function') ||\n (ios && ios[method] && typeof ios[method].postMessage === 'function') ||\n (web && typeof web[method] === 'function');\n\n const sub = (listener: any) => {\n subs.push(listener);\n }\n\n const invokePromise = promisifyInvoke(invoke, sub);\n const storagePromise = promisifyStorage(storage, sub);\n const getGeoPromise = promisifyMethod(getGeo, sub);\n const getQrPromise = promisifyMethod(getQr, sub);\n const getSMSCodePromise = promisifyMethod(getSMSCode, sub);\n const selectContactPromise = promisifyMethod(selectContact, sub);\n const openSettingsPromise = promisifyMethod(openSettings, sub);\n const closeApplicationPromise = promisifyMethod(closeApplication, sub);\n const sharePromise = promisifyMethod(share, sub);\n const setTitlePromise = promisifyMethod(setTitle, sub);\n const copyToClipboardPromise = promisifyMethod(copyToClipboard, sub);\n const shareImagePromise = promisifyMethod(shareImage, sub);\n const shareFilePromise = promisifyMethod(shareFile, sub);\n const vibratePromise = promisifyMethod(vibrate, sub);\n const enableScreenCapturePromise = promisifyMethod(enableScreenCapture, sub);\n const disableScreenCapturePromise = promisifyMethod(disableScreenCapture, sub);\n\n return {\n copyToClipboard: copyToClipboardPromise,\n invoke: invokePromise,\n storage: storagePromise,\n getMe: () => invokePromise(EInvokeRequest.getMe),\n getPhone: () => invokePromise(EInvokeRequest.getPhone),\n getContacts: () => invokePromise(EInvokeRequest.getContacts),\n getGeo: getGeoPromise,\n getQr: getQrPromise,\n getSMSCode: getSMSCodePromise,\n getUserProfile: (id: string) => invokePromise(EInvokeRequest.getUserProfile, { id }),\n selectContact: selectContactPromise,\n enableNotifications,\n disableNotifications,\n openSettings: openSettingsPromise,\n closeApplication: closeApplicationPromise,\n setTitle: setTitlePromise,\n share: sharePromise,\n shareImage: shareImagePromise,\n shareFile: shareFilePromise,\n setShakeHandler,\n setTabActiveHandler,\n vibrate: vibratePromise,\n isSupported,\n supports,\n sub,\n enableScreenCapture: enableScreenCapturePromise,\n disableScreenCapture: disableScreenCapturePromise\n }\n}\n\nconst bridge = buildBridge();\n\nexport default bridge;\n","function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n}\n\nfunction createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n\n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n\n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const invokeId = id;\n promiseControllers[invokeId] = controller;\n return invokeId;\n },\n\n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n\n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n\n promiseControllers[reqId] = null;\n }\n },\n };\n}\n\nfunction promisifyInvoke(invoke, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n\n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n\n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n\n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return function promisifiedFunc(method: any, props: any = {}): Promise<any | void> {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject }, props.reqId);\n\n invoke(reqId, method, props);\n });\n };\n}\n\nexport default promisifyInvoke;\n","function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n }\n \n function createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n \n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n \n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const storageId = `s${id}`;\n promiseControllers[storageId] = controller;\n return storageId;\n },\n \n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n \n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n \n promiseControllers[reqId] = null;\n }\n },\n };\n }\n \n function promisifyStorage(storage, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n \n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n \n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n \n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return {\n setItem: (keyName: string, keyValue: string): Promise<void> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'setItem', { keyName, keyValue });\n });\n },\n getItem: (keyName: string): Promise<string | null> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'getItem', { keyName });\n });\n },\n clear: (): Promise<void> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'clear', {});\n });\n },\n }\n }\n \n export default promisifyStorage;\n "],"names":["promisifyMethod","method","subscribe","counter","promiseControllers","requestResolver","current","next","this","add","controller","customId","methodId","resolve","reqId","data","isSuccess","error","requestPromise","reject","event","detail","Promise","EInvokeRequest","invokeMethod","storageMethod","android","window","AndroidBridge","ios","webkit","messageHandlers","web","top","WebBridge","aituOrigin","AITU_ORIGIN","forEach","postMessage","JSON","stringify","payload","addEventListener","origin","parse","dispatchEvent","CustomEvent","e","bridge","subs","map","fn","call","sub","listener","push","invokePromise","invokeId","props","isIos","isWeb","console","log","invoke","storagePromise","storage","storageId","setItem","keyName","keyValue","getItem","clear","promisifyStorage","getGeoPromise","getQrPromise","getSMSCodePromise","selectContactPromise","openSettingsPromise","closeApplicationPromise","sharePromise","text","setTitlePromise","copyToClipboardPromise","shareImagePromise","image","isAndroid","filename","split","base64Data","substr","indexOf","shareFilePromise","vibratePromise","pattern","Array","isArray","some","timing","Math","floor","reduce","total","enableScreenCapturePromise","disableScreenCapturePromise","copyToClipboard","getMe","getPhone","getContacts","getGeo","getQr","getSMSCode","getUserProfile","id","selectContact","enableNotifications","disableNotifications","openSettings","closeApplication","setTitle","share","shareImage","shareFile","setShakeHandler","handler","onAituBridgeShake","setTabActiveHandler","onAituBridgeTabActive","vibrate","isSupported","iosSup","Boolean","supports","enableScreenCapture","disableScreenCapture","buildBridge"],"mappings":"AA0CA,SAASA,EAAgBC,EAAQC,GAC/B,IA5BMC,EACAC,EA2BAC,GA5BAF,EAdC,CACLG,QAAS,EACTC,gBACE,QAASC,KAAKF,UAYZF,EAA+D,GAE9D,CACLK,aAAIC,EAA+BC,GACjC,IACMC,EADiB,MAAZD,EAAmBA,EAAWR,EAAQI,OAGjD,OADAH,EAAmBQ,GAAYF,EACxBE,GAGTC,iBAAWC,EAAwBC,EAASC,EAAiCC,GAC3E,IAAMC,EAAiBd,EAAmBU,GAEtCI,IACEF,EAAUC,GACZC,EAAeL,QAAQE,GAEvBG,EAAeC,OAAOF,GAGxBb,EAAmBU,GAAS,SAuBlC,OAdAZ,EAAU,SAACkB,GACT,GAAKA,EAAMC,QAIP,UAAWD,EAAMC,OAAQ,OACID,EAAMC,OAA7BP,IAAAA,MAEJA,GACFT,EAAgBQ,QAAQC,IAHXC,KAGwB,SAACE,UAAYA,KAH/BA,qCASvB,WAAWK,QAAQ,SAACT,EAASM,GAC3B,IAAML,EAAQT,EAAgBI,IAAI,CAAEI,QAAAA,EAASM,OAAAA,IAE7ClB,gBAAOa,gCC3Db,IAAKS,GAAL,SAAKA,GACHA,gBACAA,sBACAA,4BACAA,kCACAA,2CACAA,8CANF,CAAKA,IAAAA,OA0GL,IAAMC,EAAe,SACfC,EAAgB,UAkBhBC,EAA4B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,oBAAXhG,QAChBkC,QAAQC,IAAI,4BAyFd+D,oBArF0B,SAACF,GACTjG,GAAWA,EAAO,qBACtBG,GAAOA,EAAG,oBAGrBF,OAAemG,sBAAwBH,EACb,oBAAXhG,QAChBkC,QAAQC,IAAI,gCA+EdiE,QAASnC,EACToC,YAtDkB,WAClB,IAAMC,EAASpG,GAAQF,OAAeG,OAAOC,gBAAgBgC,OAC7D,OAAOmE,QAAQxG,GAAWuG,GAAUjG,IAqDpCmG,SAlDe,SAAClI,UACfyB,GAAsC,mBAApBA,EAAQzB,IAC1B4B,GAAOA,EAAI5B,IAA8C,mBAA5B4B,EAAI5B,GAAQqC,aACzCN,GAA8B,mBAAhBA,EAAI/B,IAgDnBoD,IAAAA,EACA+E,oBAAqB9B,EACrB+B,qBAAsB9B,GAIX+B"}
package/dist/index.umd.js CHANGED
@@ -1,2 +1,2 @@
1
- !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e=e||self).aituBridge=n()}(this,function(){function e(e,n){var t,o,i=(t={current:0,next:function(){return++this.current}},o={},{add:function(e,n){var i=null!=n?n:t.next();return o[i]=e,i},resolve:function(e,n,t,i){var r=o[e];r&&(t(i)?r.resolve(n):r.reject(i),o[e]=null)}});return n(function(e){if(e.detail&&"reqId"in e.detail){var n=e.detail,t=n.reqId;t&&i.resolve(t,n.data,function(e){return!e},n.error)}}),function(){var n=arguments;return new Promise(function(t,o){var r=i.add({resolve:t,reject:o});e.apply(void 0,[r].concat([].slice.call(n)))})}}var n;!function(e){e.getMe="GetMe",e.getPhone="GetPhone",e.getContacts="GetContacts",e.enableNotifications="AllowNotifications",e.disableNotifications="DisableNotifications"}(n||(n={}));var t="invoke",o="storage",i="undefined"!=typeof window&&window.AndroidBridge,r="undefined"!=typeof window&&window.webkit&&window.webkit.messageHandlers,a="undefined"!=typeof window&&window.top!==window&&(window.WebBridge=window.WebBridge||{});if(a){var s=window.AITU_ORIGIN||"https://aitu.io";[t,o].forEach(function(e){a[e]||(a[e]=function(){return window.top.postMessage(JSON.stringify({method:e,payload:[].slice.call(arguments)}),s)})}),window.addEventListener("message",function(e){if(e.origin===s&&e.data)try{var n=JSON.parse(e.data);window.dispatchEvent(new CustomEvent("aituEvents",{detail:n}))}catch(e){}})}return function(){var s=[];"undefined"!=typeof window&&window.addEventListener("aituEvents",function(e){[].concat(s).map(function(n){return n.call(null,e)})});var d,c,l,u=function(e){s.push(e)},f=(d={current:0,next:function(){return++this.current}},c={},l={add:function(e,n){var t=null!=n?n:d.next();return c[t]=e,t},resolve:function(e,n,t,o){var i=c[e];i&&(t(o)?i.resolve(n):i.reject(o),c[e]=null)}},u(function(e){if(e.detail&&"reqId"in e.detail){var n=e.detail,t=n.reqId;t&&l.resolve(t,n.data,function(e){return!e},n.error)}}),function(e,n){return void 0===n&&(n={}),new Promise(function(o,s){!function(e,n,o){void 0===o&&(o={});var s=r&&r[t],d=a&&a[t];i&&i[t]?i[t](e,n,JSON.stringify(o)):s?r[t].postMessage({reqId:e,method:n,data:o}):d?a[t](e,n,o):"undefined"!=typeof window&&console.log("--invoke-isUnknown")}(l.add({resolve:o,reject:s},n.reqId),e,n)})}),p=function(e,n){var t,o,i=(t={current:0,next:function(){return++this.current}},o={},{add:function(e,n){var i="s"+(null!=n?n:t.next());return o[i]=e,i},resolve:function(e,n,t,i){var r=o[e];r&&(t(i)?r.resolve(n):r.reject(i),o[e]=null)}});return n(function(e){if(e.detail&&"reqId"in e.detail){var n=e.detail,t=n.reqId;t&&i.resolve(t,n.data,function(e){return!e},n.error)}}),{setItem:function(n,t){return new Promise(function(o,r){var a=i.add({resolve:o,reject:r});e(a,"setItem",{keyName:n,keyValue:t})})},getItem:function(n){return new Promise(function(t,o){var r=i.add({resolve:t,reject:o});e(r,"getItem",{keyName:n})})},clear:function(){return new Promise(function(n,t){var o=i.add({resolve:n,reject:t});e(o,"clear",{})})}}}(function(e,n,t){void 0===t&&(t={});var s=r&&r[o],d=a&&a[o];i&&i[o]?i[o](e,n,JSON.stringify(t)):s?r[o].postMessage({reqId:e,method:n,data:t}):d?a[o](e,n,t):"undefined"!=typeof window&&console.log("--storage-isUnknown")},u),g=e(function(e){var n=r&&r.getGeo;i&&i.getGeo?i.getGeo(e):n?r.getGeo.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getGeo-isWeb")},u),w=e(function(e){var n=r&&r.getQr;i&&i.getQr?i.getQr(e):n?r.getQr.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getQr-isWeb")},u),v=e(function(e){var n=r&&r.getSMSCode;i&&i.getSMSCode?i.getSMSCode(e):n?r.getSMSCode.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getSMSCode-isWeb")},u),y=e(function(e){var n=r&&r.selectContact;i&&i.selectContact?i.selectContact(e):n?r.selectContact.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--selectContact-isWeb")},u),b=e(function(e){var n=r&&r.openSettings;i&&i.openSettings?i.openSettings(e):n?r.openSettings.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--openSettings-isWeb")},u),h=e(function(e){var n=r&&r.closeApplication;i&&i.closeApplication?i.closeApplication(e):n?r.closeApplication.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--closeApplication-isWeb")},u),m=e(function(e,n){var t=r&&r.share;i&&i.share?i.share(e,n):t?r.share.postMessage({reqId:e,text:n}):"undefined"!=typeof window&&console.log("--share-isWeb")},u),I=e(function(e,n){var t=r&&r.setTitle;i&&i.setTitle?i.setTitle(e,n):t?r.setTitle.postMessage({reqId:e,text:n}):"undefined"!=typeof window&&console.log("--setTitle-isWeb")},u),S=e(function(e,n){var t=r&&r.copyToClipboard;i&&i.copyToClipboard?i.copyToClipboard(e,n):t?r.copyToClipboard.postMessage({reqId:e,text:n}):"undefined"!=typeof window&&console.log("--copyToClipboard-isWeb")},u),M=e(function(e,n,t){var o=r&&r.shareFile,a=t;i&&i.shareFile?i.shareFile(e,n,"image",a):o?r.shareFile.postMessage({reqId:e,text:n,filename:"image",base64Data:a}):"undefined"!=typeof window&&console.log("--shareFile-isWeb")},u),C=e(function(e,n,t,o){var a=r&&r.shareFile;i&&i.shareFile?i.shareFile(e,n,t,o):a?r.shareFile.postMessage({reqId:e,text:n,filename:t,base64Data:o}):"undefined"!=typeof window&&console.log("--shareFile-isWeb")},u),q=e(function(e,n){if(!Array.isArray(n)||n.some(function(e){return e<1||e!==Math.floor(e)})||n.reduce(function(e,n){return e+n})>1e4)console.error("Pattern should be an array of positive integers no longer than 10000ms total");else{var t=r&&r.vibrate;i&&i.vibrate?i.vibrate(e,JSON.stringify(n)):t?r.vibrate.postMessage({reqId:e,pattern:n}):"undefined"!=typeof window&&console.log("--vibrate-isWeb")}},u);return{copyToClipboard:S,invoke:f,storage:p,getMe:function(){return f(n.getMe)},getPhone:function(){return f(n.getPhone)},getContacts:function(){return f(n.getContacts)},getGeo:g,getQr:w,getSMSCode:v,selectContact:y,enableNotifications:function(){return f(n.enableNotifications)},disableNotifications:function(){return f(n.disableNotifications)},openSettings:b,closeApplication:h,setTitle:I,share:m,shareImage:M,shareFile:C,setShakeHandler:function(e){i&&i.setShakeHandler||r&&r.setShakeHandler?window.onAituBridgeShake=e:"undefined"!=typeof window&&console.log("--setShakeHandler-isWeb")},vibrate:q,isSupported:function(){var e=r&&window.webkit.messageHandlers.invoke;return Boolean(i||e||a)},supports:function(e){return i&&"function"==typeof i[e]||r&&r[e]&&"function"==typeof r[e].postMessage||a&&"function"==typeof a[e]},sub:u}}()});
1
+ !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e=e||self).aituBridge=n()}(this,function(){function e(e,n){var t,o,i=(t={current:0,next:function(){return++this.current}},o={},{add:function(e,n){var i=null!=n?n:t.next();return o[i]=e,i},resolve:function(e,n,t,i){var r=o[e];r&&(t(i)?r.resolve(n):r.reject(i),o[e]=null)}});return n(function(e){if(e.detail&&"reqId"in e.detail){var n=e.detail,t=n.reqId;t&&i.resolve(t,n.data,function(e){return!e},n.error)}}),function(){var n=arguments;return new Promise(function(t,o){var r=i.add({resolve:t,reject:o});e.apply(void 0,[r].concat([].slice.call(n)))})}}var n;!function(e){e.getMe="GetMe",e.getPhone="GetPhone",e.getContacts="GetContacts",e.getUserProfile="GetUserProfile",e.enableNotifications="AllowNotifications",e.disableNotifications="DisableNotifications"}(n||(n={}));var t="invoke",o="storage",i="undefined"!=typeof window&&window.AndroidBridge,r="undefined"!=typeof window&&window.webkit&&window.webkit.messageHandlers,a="undefined"!=typeof window&&window.top!==window&&(window.WebBridge=window.WebBridge||{});if(a){var s=window.AITU_ORIGIN||"https://aitu.io";[t,o].forEach(function(e){a[e]||(a[e]=function(){return window.top.postMessage(JSON.stringify({method:e,payload:[].slice.call(arguments)}),s)})}),window.addEventListener("message",function(e){if(e.origin===s&&e.data)try{var n=JSON.parse(e.data);window.dispatchEvent(new CustomEvent("aituEvents",{detail:n}))}catch(e){}})}return function(){var s=[];"undefined"!=typeof window&&window.addEventListener("aituEvents",function(e){[].concat(s).map(function(n){return n.call(null,e)})});var d,c,l,u=function(e){s.push(e)},f=(d={current:0,next:function(){return++this.current}},c={},l={add:function(e,n){var t=null!=n?n:d.next();return c[t]=e,t},resolve:function(e,n,t,o){var i=c[e];i&&(t(o)?i.resolve(n):i.reject(o),c[e]=null)}},u(function(e){if(e.detail&&"reqId"in e.detail){var n=e.detail,t=n.reqId;t&&l.resolve(t,n.data,function(e){return!e},n.error)}}),function(e,n){return void 0===n&&(n={}),new Promise(function(o,s){!function(e,n,o){void 0===o&&(o={});var s=r&&r[t],d=a&&a[t];i&&i[t]?i[t](e,n,JSON.stringify(o)):s?r[t].postMessage({reqId:e,method:n,data:o}):d?a[t](e,n,o):"undefined"!=typeof window&&console.log("--invoke-isUnknown")}(l.add({resolve:o,reject:s},n.reqId),e,n)})}),p=function(e,n){var t,o,i=(t={current:0,next:function(){return++this.current}},o={},{add:function(e,n){var i="s"+(null!=n?n:t.next());return o[i]=e,i},resolve:function(e,n,t,i){var r=o[e];r&&(t(i)?r.resolve(n):r.reject(i),o[e]=null)}});return n(function(e){if(e.detail&&"reqId"in e.detail){var n=e.detail,t=n.reqId;t&&i.resolve(t,n.data,function(e){return!e},n.error)}}),{setItem:function(n,t){return new Promise(function(o,r){var a=i.add({resolve:o,reject:r});e(a,"setItem",{keyName:n,keyValue:t})})},getItem:function(n){return new Promise(function(t,o){var r=i.add({resolve:t,reject:o});e(r,"getItem",{keyName:n})})},clear:function(){return new Promise(function(n,t){var o=i.add({resolve:n,reject:t});e(o,"clear",{})})}}}(function(e,n,t){void 0===t&&(t={});var s=r&&r[o],d=a&&a[o];i&&i[o]?i[o](e,n,JSON.stringify(t)):s?r[o].postMessage({reqId:e,method:n,data:t}):d?a[o](e,n,t):"undefined"!=typeof window&&console.log("--storage-isUnknown")},u),g=e(function(e){var n=r&&r.getGeo;i&&i.getGeo?i.getGeo(e):n?r.getGeo.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getGeo-isWeb")},u),w=e(function(e){var n=r&&r.getQr;i&&i.getQr?i.getQr(e):n?r.getQr.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getQr-isWeb")},u),v=e(function(e){var n=r&&r.getSMSCode;i&&i.getSMSCode?i.getSMSCode(e):n?r.getSMSCode.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getSMSCode-isWeb")},u),b=e(function(e){var n=r&&r.selectContact;i&&i.selectContact?i.selectContact(e):n?r.selectContact.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--selectContact-isWeb")},u),h=e(function(e){var n=r&&r.openSettings;i&&i.openSettings?i.openSettings(e):n?r.openSettings.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--openSettings-isWeb")},u),y=e(function(e){var n=r&&r.closeApplication;i&&i.closeApplication?i.closeApplication(e):n?r.closeApplication.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--closeApplication-isWeb")},u),S=e(function(e,n){var t=r&&r.share;i&&i.share?i.share(e,n):t?r.share.postMessage({reqId:e,text:n}):"undefined"!=typeof window&&console.log("--share-isWeb")},u),M=e(function(e,n){var t=r&&r.setTitle;i&&i.setTitle?i.setTitle(e,n):t?r.setTitle.postMessage({reqId:e,text:n}):"undefined"!=typeof window&&console.log("--setTitle-isWeb")},u),C=e(function(e,n){var t=r&&r.copyToClipboard;i&&i.copyToClipboard?i.copyToClipboard(e,n):t?r.copyToClipboard.postMessage({reqId:e,text:n}):"undefined"!=typeof window&&console.log("--copyToClipboard-isWeb")},u),I=e(function(e,n,t){var o=i&&i.shareFile,a=r&&r.shareFile,s="image."+t.split(";")[0].split("/")[1],d=t.substr(t.indexOf(",")+1);o?i.shareFile(e,n,s,d):a?r.shareFile.postMessage({reqId:e,text:n,filename:s,base64Data:d}):"undefined"!=typeof window&&console.log("--shareFile-isWeb")},u),m=e(function(e,n,t,o){var a=r&&r.shareFile;i&&i.shareFile?i.shareFile(e,n,t,o):a?r.shareFile.postMessage({reqId:e,text:n,filename:t,base64Data:o}):"undefined"!=typeof window&&console.log("--shareFile-isWeb")},u),q=e(function(e,n){if(!Array.isArray(n)||n.some(function(e){return e<1||e!==Math.floor(e)})||n.reduce(function(e,n){return e+n})>1e4)console.error("Pattern should be an array of positive integers no longer than 10000ms total");else{var t=r&&r.vibrate;i&&i.vibrate?i.vibrate(e,JSON.stringify(n)):t?r.vibrate.postMessage({reqId:e,pattern:n}):"undefined"!=typeof window&&console.log("--vibrate-isWeb")}},u),A=e(function(){var e=r&&r.enableScreenCaptureMethod;i&&i.enableScreenCaptureMethod?i.enableScreenCaptureMethod():e?r.enableScreenCaptureMethod.postMessage({}):"undefined"!=typeof window&&console.log("--enableScreenCapture-isWeb")},u),T=e(function(){var e=r&&r.disableScreenCaptureMethod;i&&i.disableScreenCaptureMethod?i.disableScreenCaptureMethod():e?r.disableScreenCaptureMethod.postMessage({}):"undefined"!=typeof window&&console.log("--disableScreenCapture-isWeb")},u);return{copyToClipboard:C,invoke:f,storage:p,getMe:function(){return f(n.getMe)},getPhone:function(){return f(n.getPhone)},getContacts:function(){return f(n.getContacts)},getGeo:g,getQr:w,getSMSCode:v,getUserProfile:function(e){return f(n.getUserProfile,{id:e})},selectContact:b,enableNotifications:function(){return f(n.enableNotifications)},disableNotifications:function(){return f(n.disableNotifications)},openSettings:h,closeApplication:y,setTitle:M,share:S,shareImage:I,shareFile:m,setShakeHandler:function(e){i&&i.setShakeHandler||r&&r.setShakeHandler?window.onAituBridgeShake=e:"undefined"!=typeof window&&console.log("--setShakeHandler-isWeb")},setTabActiveHandler:function(e){i&&i.setTabActiveHandler||r&&r.setTabActiveHandler?window.onAituBridgeTabActive=e:"undefined"!=typeof window&&console.log("--setTabActiveHandler-isWeb")},vibrate:q,isSupported:function(){var e=r&&window.webkit.messageHandlers.invoke;return Boolean(i||e||a)},supports:function(e){return i&&"function"==typeof i[e]||r&&r[e]&&"function"==typeof r[e].postMessage||a&&"function"==typeof a[e]},sub:u,enableScreenCapture:A,disableScreenCapture:T}}()});
2
2
  //# sourceMappingURL=index.umd.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.umd.js","sources":["../src/promisifyMethod.ts","../src/index.ts","../src/promisifyInvoke.ts","../src/promisifyStorage.ts"],"sourcesContent":["function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n}\n\nfunction createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n\n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n\n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const methodId = id;\n promiseControllers[methodId] = controller;\n return methodId;\n },\n\n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n\n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n\n promiseControllers[reqId] = null;\n }\n },\n };\n}\n\nfunction promisifyMethod(method, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n\n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n\n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n\n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return function promisifiedFunc(...args: any[]): Promise<any | void> {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n\n method(reqId, ...args);\n });\n };\n}\n\nexport default promisifyMethod;\n","import promisifyInvoke from './promisifyInvoke';\nimport promisifyStorage from './promisifyStorage';\nimport promisifyMethod from './promisifyMethod';\n\nenum EInvokeRequest {\n getMe = 'GetMe',\n getPhone = 'GetPhone',\n getContacts = 'GetContacts',\n enableNotifications = 'AllowNotifications',\n disableNotifications = 'DisableNotifications'\n}\n\ntype SetItemType = (keyName: string, keyValue: string) => Promise<void>;\ntype GetItemType = (keyName: string) => Promise<string | null>;\ntype ClearType = () => Promise<void>;\n\ninterface GetPhoneResponse {\n phone: string;\n sign: string;\n}\n\ninterface GetMeResponse {\n name: string;\n lastname: string;\n id: string;\n avatar?: string;\n avatarThumb?: string;\n sign: string;\n}\n\ninterface ResponseObject {\n phone?: string;\n name?: string;\n lastname?: string;\n}\n\ninterface GetGeoResponse {\n latitude: number;\n longitude: number;\n}\n\ninterface GetContactsResponse {\n contacts: Array<{\n first_name: string;\n last_name: string;\n phone: string;\n }>;\n sign: string;\n}\n\ninterface SelectContactResponse {\n phone: string;\n name: string;\n lastname: string;\n}\n\ntype OpenSettingsResponse = 'success' | 'failed';\ntype ShareResponse = 'success' | 'failed';\ntype CopyToClipboardResponse = 'success' | 'failed';\ntype VibrateResponse = 'success' | 'failed';\n// todo: remove duplicates\ntype ResponseType = 'success' | 'failed';\n\ntype BridgeInvoke<T extends EInvokeRequest, R> = (method: T, data?: {}) => Promise<R>;\n\ninterface BridgeStorage {\n setItem: SetItemType,\n getItem: GetItemType,\n clear: ClearType\n}\n\ninterface AituBridge {\n invoke: BridgeInvoke<EInvokeRequest, ResponseObject>;\n storage: BridgeStorage;\n getMe: () => Promise<GetMeResponse>;\n getPhone: () => Promise<GetPhoneResponse>;\n getContacts: () => Promise<GetContactsResponse>;\n getGeo: () => Promise<GetGeoResponse>;\n selectContact: () => Promise<SelectContactResponse>;\n getQr: () => Promise<string>;\n getSMSCode: () => Promise<string>;\n share: (text: string) => Promise<ShareResponse>;\n setTitle: (text: string) => Promise<ResponseType>;\n copyToClipboard: (text: string) => Promise<CopyToClipboardResponse>;\n shareImage: (text: string, image: string) => Promise<ShareResponse>;\n shareFile: (text: string, filename: string, base64Data: string) => Promise<ShareResponse>;\n enableNotifications: () => Promise<{}>;\n disableNotifications: () => Promise<{}>;\n openSettings: () => Promise<OpenSettingsResponse>;\n closeApplication: () => Promise<ResponseType>;\n setShakeHandler: (handler: any) => void;\n vibrate: (pattern: number[]) => Promise<VibratePattern>;\n isSupported: () => boolean;\n supports: (method: string) => boolean;\n sub: any;\n}\n\nconst invokeMethod = 'invoke';\nconst storageMethod = 'storage';\nconst getGeoMethod = 'getGeo';\nconst getQrMethod = 'getQr';\nconst getSMSCodeMethod = 'getSMSCode';\nconst selectContactMethod = 'selectContact';\nconst openSettingsMethod = 'openSettings';\nconst closeApplicationMethod = 'closeApplication';\nconst shareMethod = 'share';\nconst setTitleMethod = 'setTitle';\nconst copyToClipboardMethod = 'copyToClipboard';\nconst shareImageMethod = 'shareImage';\nconst shareFileMethod = 'shareFile';\nconst setShakeHandlerMethod = 'setShakeHandler';\nconst vibrateMethod = 'vibrate';\n\nconst android = typeof window !== 'undefined' && (window as any).AndroidBridge;\nconst ios = typeof window !== 'undefined' && (window as any).webkit && (window as any).webkit.messageHandlers;\nconst web = typeof window !== 'undefined' && (window.top !== window) && ((window as any).WebBridge = (window as any).WebBridge || {});\n\nif (web) {\n const aituOrigin = (window as any).AITU_ORIGIN || 'https://aitu.io';\n\n [invokeMethod, storageMethod].forEach((method) => {\n if (!web[method]) {\n web[method] = (...args) => window.top.postMessage(JSON.stringify({\n method,\n payload: args,\n }), aituOrigin);\n }\n });\n\n window.addEventListener('message', (event) => {\n if (event.origin === aituOrigin && event.data) {\n try {\n const detail = JSON.parse(event.data);\n window.dispatchEvent(new CustomEvent('aituEvents', { detail }));\n } catch(e) {}\n }\n });\n}\n\nconst buildBridge = (): AituBridge => {\n const subs = [];\n\n if (typeof window !== 'undefined') {\n window.addEventListener('aituEvents', (e: any) => {\n [...subs].map((fn) => fn.call(null, e));\n })\n }\n\n const invoke = (reqId, method, data = {}) => {\n const isAndroid = android && android[invokeMethod];\n const isIos = ios && ios[invokeMethod];\n const isWeb = web && web[invokeMethod];\n\n if (isAndroid) {\n android[invokeMethod](reqId, method, JSON.stringify(data));\n } else if (isIos) {\n ios[invokeMethod].postMessage({ reqId, method, data });\n } else if (isWeb) {\n web[invokeMethod](reqId, method, data);\n } else if (typeof window !== 'undefined') {\n console.log('--invoke-isUnknown');\n }\n };\n\n const storage = (reqId, method, data = {}) => {\n const isAndroid = android && android[storageMethod];\n const isIos = ios && ios[storageMethod];\n const isWeb = web && web[storageMethod];\n\n if (isAndroid) {\n android[storageMethod](reqId, method, JSON.stringify(data));\n } else if (isIos) {\n ios[storageMethod].postMessage({ reqId, method, data });\n } else if (isWeb) {\n web[storageMethod](reqId, method, data);\n } else if (typeof window !== 'undefined') {\n console.log('--storage-isUnknown');\n }\n }\n\n const getGeo = (reqId) => {\n const isAndroid = android && android[getGeoMethod];\n const isIos = ios && ios[getGeoMethod];\n\n if (isAndroid) {\n android[getGeoMethod](reqId);\n } else if (isIos) {\n ios[getGeoMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getGeo-isWeb');\n }\n }\n\n const getQr = (reqId) => {\n const isAndroid = android && android[getQrMethod];\n const isIos = ios && ios[getQrMethod];\n\n if (isAndroid) {\n android[getQrMethod](reqId);\n } else if (isIos) {\n ios[getQrMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getQr-isWeb');\n }\n }\n\n const getSMSCode = (reqId) => {\n const isAndroid = android && android[getSMSCodeMethod];\n const isIos = ios && ios[getSMSCodeMethod];\n\n if (isAndroid) {\n android[getSMSCodeMethod](reqId);\n } else if (isIos) {\n ios[getSMSCodeMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getSMSCode-isWeb');\n }\n }\n\n const selectContact = (reqId) => {\n const isAndroid = android && android[selectContactMethod];\n const isIos = ios && ios[selectContactMethod];\n\n if (isAndroid) {\n android[selectContactMethod](reqId);\n } else if (isIos) {\n ios[selectContactMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--selectContact-isWeb');\n }\n }\n\n const openSettings = (reqId) => {\n const isAndroid = android && android[openSettingsMethod];\n const isIos = ios && ios[openSettingsMethod];\n\n if (isAndroid) {\n android[openSettingsMethod](reqId);\n } else if (isIos) {\n ios[openSettingsMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--openSettings-isWeb');\n }\n }\n\n const closeApplication = (reqId) => {\n const isAndroid = android && android[closeApplicationMethod];\n const isIos = ios && ios[closeApplicationMethod];\n\n if (isAndroid) {\n android[closeApplicationMethod](reqId);\n } else if (isIos) {\n ios[closeApplicationMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--closeApplication-isWeb');\n }\n }\n\n const share = (reqId, text) => {\n const isAndroid = android && android[shareMethod];\n const isIos = ios && ios[shareMethod];\n\n if (isAndroid) {\n android[shareMethod](reqId, text);\n } else if (isIos) {\n ios[shareMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--share-isWeb');\n }\n }\n\n const setTitle = (reqId, text) => {\n const isAndroid = android && android[setTitleMethod];\n const isIos = ios && ios[setTitleMethod];\n\n if (isAndroid) {\n android[setTitleMethod](reqId, text);\n } else if (isIos) {\n ios[setTitleMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--setTitle-isWeb');\n }\n }\n\n const copyToClipboard = (reqId, text) => {\n const isAndroid = android && android[copyToClipboardMethod];\n const isIos = ios && ios[copyToClipboardMethod];\n\n if (isAndroid) {\n android[copyToClipboardMethod](reqId, text);\n } else if (isIos) {\n ios[copyToClipboardMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--copyToClipboard-isWeb');\n }\n }\n\n const shareImage = (reqId, text, image) => {\n // !!!======================!!!\n // !!!===== Deprecated =====!!!\n // !!!======================!!!\n\n // const isAndroid = android && android[shareImageMethod];\n // const isIos = ios && ios[shareImageMethod];\n\n // if (isAndroid) {\n // android[shareImageMethod](reqId, text, image);\n // } else if (isIos) {\n // ios[shareImageMethod].postMessage({ reqId, text, image });\n // } else if (typeof window !== 'undefined') {\n // console.log('--shareImage-isWeb');\n // }\n\n // new one - fallback to shareFile\n const isAndroid = android && android[shareFileMethod];\n const isIos = ios && ios[shareFileMethod];\n\n const filename = 'image';\n const base64Data = image;\n\n if (isAndroid) {\n android[shareFileMethod](reqId, text, filename, base64Data);\n } else if (isIos) {\n ios[shareFileMethod].postMessage({ reqId, text, filename, base64Data });\n } else if (typeof window !== 'undefined') {\n console.log('--shareFile-isWeb');\n }\n }\n\n const shareFile = (reqId, text, filename, base64Data) => {\n const isAndroid = android && android[shareFileMethod];\n const isIos = ios && ios[shareFileMethod];\n\n if (isAndroid) {\n android[shareFileMethod](reqId, text, filename, base64Data);\n } else if (isIos) {\n ios[shareFileMethod].postMessage({ reqId, text, filename, base64Data });\n } else if (typeof window !== 'undefined') {\n console.log('--shareFile-isWeb');\n }\n }\n\n const enableNotifications = () => invokePromise(EInvokeRequest.enableNotifications);\n\n const disableNotifications = () => invokePromise(EInvokeRequest.disableNotifications);\n\n const setShakeHandler = (handler) => {\n const isAndroid = android && android[setShakeHandlerMethod];\n const isIos = ios && ios[setShakeHandlerMethod];\n\n if (isAndroid || isIos) {\n (window as any).onAituBridgeShake = handler;\n } else if (typeof window !== 'undefined') {\n console.log('--setShakeHandler-isWeb');\n }\n };\n\n const vibrate = (reqId, pattern) => {\n if (\n !Array.isArray(pattern) ||\n pattern.some((timing) => timing < 1 || timing !== Math.floor(timing)) ||\n pattern.reduce((total, timing) => total + timing) > 10000\n ) {\n console.error('Pattern should be an array of positive integers no longer than 10000ms total');\n return;\n }\n\n const isAndroid = android && android[vibrateMethod];\n const isIos = ios && ios[vibrateMethod];\n\n if (isAndroid) {\n android[vibrateMethod](reqId, JSON.stringify(pattern));\n } else if (isIos) {\n ios[vibrateMethod].postMessage({ reqId, pattern });\n } else if (typeof window !== 'undefined') {\n console.log('--vibrate-isWeb');\n }\n }\n\n const isSupported = () => {\n const iosSup = ios && (window as any).webkit.messageHandlers.invoke;\n return Boolean(android || iosSup || web);\n }\n\n const supports = (method) =>\n (android && typeof android[method] === 'function') ||\n (ios && ios[method] && typeof ios[method].postMessage === 'function') ||\n (web && typeof web[method] === 'function');\n\n const sub = (listener: any) => {\n subs.push(listener);\n }\n\n const invokePromise = promisifyInvoke(invoke, sub);\n const storagePromise = promisifyStorage(storage, sub);\n const getGeoPromise = promisifyMethod(getGeo, sub);\n const getQrPromise = promisifyMethod(getQr, sub);\n const getSMSCodePromise = promisifyMethod(getSMSCode, sub);\n const selectContactPromise = promisifyMethod(selectContact, sub);\n const openSettingsPromise = promisifyMethod(openSettings, sub);\n const closeApplicationPromise = promisifyMethod(closeApplication, sub);\n const sharePromise = promisifyMethod(share, sub);\n const setTitlePromise = promisifyMethod(setTitle, sub);\n const copyToClipboardPromise = promisifyMethod(copyToClipboard, sub);\n const shareImagePromise = promisifyMethod(shareImage, sub);\n const shareFilePromise = promisifyMethod(shareFile, sub);\n const vibratePromise = promisifyMethod(vibrate, sub);\n\n return {\n copyToClipboard: copyToClipboardPromise,\n invoke: invokePromise,\n storage: storagePromise,\n getMe: () => invokePromise(EInvokeRequest.getMe),\n getPhone: () => invokePromise(EInvokeRequest.getPhone),\n getContacts: () => invokePromise(EInvokeRequest.getContacts),\n getGeo: getGeoPromise,\n getQr: getQrPromise,\n getSMSCode: getSMSCodePromise,\n selectContact: selectContactPromise,\n enableNotifications,\n disableNotifications,\n openSettings: openSettingsPromise,\n closeApplication: closeApplicationPromise,\n setTitle: setTitlePromise,\n share: sharePromise,\n shareImage: shareImagePromise,\n shareFile: shareFilePromise,\n setShakeHandler,\n vibrate: vibratePromise,\n isSupported,\n supports,\n sub\n }\n}\n\nconst bridge = buildBridge();\n\nexport default bridge;\n","function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n}\n\nfunction createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n\n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n\n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const invokeId = id;\n promiseControllers[invokeId] = controller;\n return invokeId;\n },\n\n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n\n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n\n promiseControllers[reqId] = null;\n }\n },\n };\n}\n\nfunction promisifyInvoke(invoke, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n\n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n\n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n\n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return function promisifiedFunc(method: any, props: any = {}): Promise<any | void> {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject }, props.reqId);\n\n invoke(reqId, method, props);\n });\n };\n}\n\nexport default promisifyInvoke;\n","function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n }\n \n function createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n \n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n \n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const storageId = `s${id}`;\n promiseControllers[storageId] = controller;\n return storageId;\n },\n \n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n \n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n \n promiseControllers[reqId] = null;\n }\n },\n };\n }\n \n function promisifyStorage(storage, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n \n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n \n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n \n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return {\n setItem: (keyName: string, keyValue: string): Promise<void> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'setItem', { keyName, keyValue });\n });\n },\n getItem: (keyName: string): Promise<string | null> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'getItem', { keyName });\n });\n },\n clear: (): Promise<void> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'clear', {});\n });\n },\n }\n }\n \n export default promisifyStorage;\n "],"names":["promisifyMethod","method","subscribe","counter","promiseControllers","requestResolver","current","next","this","add","controller","customId","methodId","resolve","reqId","data","isSuccess","error","requestPromise","reject","event","detail","Promise","EInvokeRequest","invokeMethod","storageMethod","android","window","AndroidBridge","ios","webkit","messageHandlers","web","top","WebBridge","aituOrigin","AITU_ORIGIN","forEach","postMessage","JSON","stringify","payload","addEventListener","origin","parse","dispatchEvent","CustomEvent","e","subs","map","fn","call","sub","listener","push","invokePromise","invokeId","props","isIos","isWeb","console","log","invoke","storagePromise","storage","storageId","setItem","keyName","keyValue","getItem","clear","promisifyStorage","getGeoPromise","getQrPromise","getSMSCodePromise","selectContactPromise","openSettingsPromise","closeApplicationPromise","sharePromise","text","setTitlePromise","copyToClipboardPromise","shareImagePromise","image","base64Data","filename","shareFilePromise","vibratePromise","pattern","Array","isArray","some","timing","Math","floor","reduce","total","copyToClipboard","getMe","getPhone","getContacts","getGeo","getQr","getSMSCode","selectContact","enableNotifications","disableNotifications","openSettings","closeApplication","setTitle","share","shareImage","shareFile","setShakeHandler","handler","onAituBridgeShake","vibrate","isSupported","iosSup","Boolean","supports","buildBridge"],"mappings":"mLA0CA,SAASA,EAAgBC,EAAQC,GAC/B,IA5BMC,EACAC,EA2BAC,GA5BAF,EAdC,CACLG,QAAS,EACTC,gBACE,QAASC,KAAKF,UAYZF,EAA+D,GAE9D,CACLK,aAAIC,EAA+BC,GACjC,IACMC,EADiB,MAAZD,EAAmBA,EAAWR,EAAQI,OAGjD,OADAH,EAAmBQ,GAAYF,EACxBE,GAGTC,iBAAWC,EAAwBC,EAASC,EAAiCC,GAC3E,IAAMC,EAAiBd,EAAmBU,GAEtCI,IACEF,EAAUC,GACZC,EAAeL,QAAQE,GAEvBG,EAAeC,OAAOF,GAGxBb,EAAmBU,GAAS,SAuBlC,OAdAZ,EAAU,SAACkB,GACT,GAAKA,EAAMC,QAIP,UAAWD,EAAMC,OAAQ,OACID,EAAMC,OAA7BP,IAAAA,MAEJA,GACFT,EAAgBQ,QAAQC,IAHXC,KAGwB,SAACE,UAAYA,KAH/BA,qCASvB,WAAWK,QAAQ,SAACT,EAASM,GAC3B,IAAML,EAAQT,EAAgBI,IAAI,CAAEI,QAAAA,EAASM,OAAAA,IAE7ClB,gBAAOa,gCC3Db,IAAKS,GAAL,SAAKA,GACHA,gBACAA,sBACAA,4BACAA,2CACAA,8CALF,CAAKA,IAAAA,OA6FL,IAAMC,EAAe,SACfC,EAAgB,UAehBC,EAA4B,oBAAXC,QAA2BA,OAAeC,cAC3DC,EAAwB,oBAAXF,QAA2BA,OAAeG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YAAY,CAAExB,MAAAA,EAAO0E,QAAAA,IACb,oBAAX7D,QAChBiC,QAAQC,IAAI,qBA+BgCT,GAEhD,MAAO,CACL6C,gBAAiBhB,EACjBnB,OAAQP,EACRS,QAASD,EACTmC,MAAO,kBAAM3C,EAAchC,EAAe2E,QAC1CC,SAAU,kBAAM5C,EAAchC,EAAe4E,WAC7CC,YAAa,kBAAM7C,EAAchC,EAAe6E,cAChDC,OAAQ7B,EACR8B,MAAO7B,EACP8B,WAAY7B,EACZ8B,cAAe7B,EACf8B,oBA7E0B,kBAAMlD,EAAchC,EAAekF,sBA8E7DC,qBA5E2B,kBAAMnD,EAAchC,EAAemF,uBA6E9DC,aAAc/B,EACdgC,iBAAkB/B,EAClBgC,SAAU7B,EACV8B,MAAOhC,EACPiC,WAAY7B,EACZ8B,UAAW1B,EACX2B,gBAjFsB,SAACC,GACLxF,GAAWA,EAAO,iBACtBG,GAAOA,EAAG,gBAGrBF,OAAewF,kBAAoBD,EACT,oBAAXvF,QAChBiC,QAAQC,IAAI,4BA2EduD,QAAS7B,EACT8B,YAlDkB,WAClB,IAAMC,EAASzF,GAAQF,OAAeG,OAAOC,gBAAgB+B,OAC7D,OAAOyD,QAAQ7F,GAAW4F,GAAUtF,IAiDpCwF,SA9Ce,SAACvH,UACfyB,GAAsC,mBAApBA,EAAQzB,IAC1B4B,GAAOA,EAAI5B,IAA8C,mBAA5B4B,EAAI5B,GAAQqC,aACzCN,GAA8B,mBAAhBA,EAAI/B,IA4CnBmD,IAAAA,GAIWqE"}
1
+ {"version":3,"file":"index.umd.js","sources":["../src/promisifyMethod.ts","../src/index.ts","../src/promisifyInvoke.ts","../src/promisifyStorage.ts"],"sourcesContent":["function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n}\n\nfunction createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n\n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n\n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const methodId = id;\n promiseControllers[methodId] = controller;\n return methodId;\n },\n\n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n\n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n\n promiseControllers[reqId] = null;\n }\n },\n };\n}\n\nfunction promisifyMethod(method, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n\n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n\n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n\n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return function promisifiedFunc(...args: any[]): Promise<any | void> {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n\n method(reqId, ...args);\n });\n };\n}\n\nexport default promisifyMethod;\n","import promisifyInvoke from './promisifyInvoke';\nimport promisifyStorage from './promisifyStorage';\nimport promisifyMethod from './promisifyMethod';\n\nenum EInvokeRequest {\n getMe = 'GetMe',\n getPhone = 'GetPhone',\n getContacts = 'GetContacts',\n getUserProfile = 'GetUserProfile',\n enableNotifications = 'AllowNotifications',\n disableNotifications = 'DisableNotifications'\n}\n\ntype SetItemType = (keyName: string, keyValue: string) => Promise<void>;\ntype GetItemType = (keyName: string) => Promise<string | null>;\ntype ClearType = () => Promise<void>;\n\ninterface GetPhoneResponse {\n phone: string;\n sign: string;\n}\n\ninterface GetMeResponse {\n name: string;\n lastname: string;\n id: string;\n avatar?: string;\n avatarThumb?: string;\n sign: string;\n}\n\ninterface ResponseObject {\n phone?: string;\n name?: string;\n lastname?: string;\n}\n\ninterface GetGeoResponse {\n latitude: number;\n longitude: number;\n}\n\ninterface GetContactsResponse {\n contacts: Array<{\n first_name: string;\n last_name: string;\n phone: string;\n }>;\n sign: string;\n}\n\ninterface SelectContactResponse {\n phone: string;\n name: string;\n lastname: string;\n}\n\ninterface GetUserProfileResponse {\n name: string;\n lastname?: string;\n phone?: string;\n avatar?: string;\n avatarThumb?: string;\n}\n\ntype OpenSettingsResponse = 'success' | 'failed';\ntype ShareResponse = 'success' | 'failed';\ntype CopyToClipboardResponse = 'success' | 'failed';\ntype VibrateResponse = 'success' | 'failed';\n// todo: remove duplicates\ntype ResponseType = 'success' | 'failed';\n\ntype BridgeInvoke<T extends EInvokeRequest, R> = (method: T, data?: {}) => Promise<R>;\n\ninterface BridgeStorage {\n setItem: SetItemType,\n getItem: GetItemType,\n clear: ClearType\n}\n\ninterface AituBridge {\n invoke: BridgeInvoke<EInvokeRequest, ResponseObject>;\n storage: BridgeStorage;\n getMe: () => Promise<GetMeResponse>;\n getPhone: () => Promise<GetPhoneResponse>;\n getContacts: () => Promise<GetContactsResponse>;\n getGeo: () => Promise<GetGeoResponse>;\n selectContact: () => Promise<SelectContactResponse>;\n getQr: () => Promise<string>;\n getSMSCode: () => Promise<string>;\n getUserProfile: (userId: string) => Promise<GetUserProfileResponse>;\n share: (text: string) => Promise<ShareResponse>;\n setTitle: (text: string) => Promise<ResponseType>;\n copyToClipboard: (text: string) => Promise<CopyToClipboardResponse>;\n shareImage: (text: string, image: string) => Promise<ShareResponse>;\n shareFile: (text: string, filename: string, base64Data: string) => Promise<ShareResponse>;\n enableNotifications: () => Promise<{}>;\n disableNotifications: () => Promise<{}>;\n openSettings: () => Promise<OpenSettingsResponse>;\n closeApplication: () => Promise<ResponseType>;\n setShakeHandler: (handler: any) => void;\n setTabActiveHandler: (handler: (tabname: string) => void) => void;\n vibrate: (pattern: number[]) => Promise<VibratePattern>;\n isSupported: () => boolean;\n supports: (method: string) => boolean;\n sub: any;\n enableScreenCapture: () => Promise<{}>;\n disableScreenCapture: () => Promise<{}>;\n}\n\nconst invokeMethod = 'invoke';\nconst storageMethod = 'storage';\nconst getGeoMethod = 'getGeo';\nconst getQrMethod = 'getQr';\nconst getSMSCodeMethod = 'getSMSCode';\nconst selectContactMethod = 'selectContact';\nconst openSettingsMethod = 'openSettings';\nconst closeApplicationMethod = 'closeApplication';\nconst shareMethod = 'share';\nconst setTitleMethod = 'setTitle';\nconst copyToClipboardMethod = 'copyToClipboard';\nconst shareImageMethod = 'shareImage';\nconst shareFileMethod = 'shareFile';\nconst setShakeHandlerMethod = 'setShakeHandler';\nconst vibrateMethod = 'vibrate';\nconst enableScreenCaptureMethod = 'enableScreenCaptureMethod';\nconst disableScreenCaptureMethod = 'disableScreenCaptureMethod';\nconst setTabActiveHandlerMethod = 'setTabActiveHandler';\n\nconst android = typeof window !== 'undefined' && (window as any).AndroidBridge;\nconst ios = typeof window !== 'undefined' && (window as any).webkit && (window as any).webkit.messageHandlers;\nconst web = typeof window !== 'undefined' && (window.top !== window) && ((window as any).WebBridge = (window as any).WebBridge || {});\n\nif (web) {\n const aituOrigin = (window as any).AITU_ORIGIN || 'https://aitu.io';\n\n [invokeMethod, storageMethod].forEach((method) => {\n if (!web[method]) {\n web[method] = (...args) => window.top.postMessage(JSON.stringify({\n method,\n payload: args,\n }), aituOrigin);\n }\n });\n\n window.addEventListener('message', (event) => {\n if (event.origin === aituOrigin && event.data) {\n try {\n const detail = JSON.parse(event.data);\n window.dispatchEvent(new CustomEvent('aituEvents', { detail }));\n } catch (e) { }\n }\n });\n}\n\nconst buildBridge = (): AituBridge => {\n const subs = [];\n\n if (typeof window !== 'undefined') {\n window.addEventListener('aituEvents', (e: any) => {\n [...subs].map((fn) => fn.call(null, e));\n })\n }\n\n const invoke = (reqId, method, data = {}) => {\n const isAndroid = android && android[invokeMethod];\n const isIos = ios && ios[invokeMethod];\n const isWeb = web && web[invokeMethod];\n\n if (isAndroid) {\n android[invokeMethod](reqId, method, JSON.stringify(data));\n } else if (isIos) {\n ios[invokeMethod].postMessage({ reqId, method, data });\n } else if (isWeb) {\n web[invokeMethod](reqId, method, data);\n } else if (typeof window !== 'undefined') {\n console.log('--invoke-isUnknown');\n }\n };\n\n const storage = (reqId, method, data = {}) => {\n const isAndroid = android && android[storageMethod];\n const isIos = ios && ios[storageMethod];\n const isWeb = web && web[storageMethod];\n\n if (isAndroid) {\n android[storageMethod](reqId, method, JSON.stringify(data));\n } else if (isIos) {\n ios[storageMethod].postMessage({ reqId, method, data });\n } else if (isWeb) {\n web[storageMethod](reqId, method, data);\n } else if (typeof window !== 'undefined') {\n console.log('--storage-isUnknown');\n }\n }\n\n const getGeo = (reqId) => {\n const isAndroid = android && android[getGeoMethod];\n const isIos = ios && ios[getGeoMethod];\n\n if (isAndroid) {\n android[getGeoMethod](reqId);\n } else if (isIos) {\n ios[getGeoMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getGeo-isWeb');\n }\n }\n\n const getQr = (reqId) => {\n const isAndroid = android && android[getQrMethod];\n const isIos = ios && ios[getQrMethod];\n\n if (isAndroid) {\n android[getQrMethod](reqId);\n } else if (isIos) {\n ios[getQrMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getQr-isWeb');\n }\n }\n\n const getSMSCode = (reqId) => {\n const isAndroid = android && android[getSMSCodeMethod];\n const isIos = ios && ios[getSMSCodeMethod];\n\n if (isAndroid) {\n android[getSMSCodeMethod](reqId);\n } else if (isIos) {\n ios[getSMSCodeMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getSMSCode-isWeb');\n }\n }\n\n const selectContact = (reqId) => {\n const isAndroid = android && android[selectContactMethod];\n const isIos = ios && ios[selectContactMethod];\n\n if (isAndroid) {\n android[selectContactMethod](reqId);\n } else if (isIos) {\n ios[selectContactMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--selectContact-isWeb');\n }\n }\n\n const openSettings = (reqId) => {\n const isAndroid = android && android[openSettingsMethod];\n const isIos = ios && ios[openSettingsMethod];\n\n if (isAndroid) {\n android[openSettingsMethod](reqId);\n } else if (isIos) {\n ios[openSettingsMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--openSettings-isWeb');\n }\n }\n\n const closeApplication = (reqId) => {\n const isAndroid = android && android[closeApplicationMethod];\n const isIos = ios && ios[closeApplicationMethod];\n\n if (isAndroid) {\n android[closeApplicationMethod](reqId);\n } else if (isIos) {\n ios[closeApplicationMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--closeApplication-isWeb');\n }\n }\n\n const share = (reqId, text) => {\n const isAndroid = android && android[shareMethod];\n const isIos = ios && ios[shareMethod];\n\n if (isAndroid) {\n android[shareMethod](reqId, text);\n } else if (isIos) {\n ios[shareMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--share-isWeb');\n }\n }\n\n const setTitle = (reqId, text) => {\n const isAndroid = android && android[setTitleMethod];\n const isIos = ios && ios[setTitleMethod];\n\n if (isAndroid) {\n android[setTitleMethod](reqId, text);\n } else if (isIos) {\n ios[setTitleMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--setTitle-isWeb');\n }\n }\n\n const copyToClipboard = (reqId, text) => {\n const isAndroid = android && android[copyToClipboardMethod];\n const isIos = ios && ios[copyToClipboardMethod];\n\n if (isAndroid) {\n android[copyToClipboardMethod](reqId, text);\n } else if (isIos) {\n ios[copyToClipboardMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--copyToClipboard-isWeb');\n }\n }\n\n const enableScreenCapture = () => {\n const isAndroid = android && android[enableScreenCaptureMethod];\n const isIos = ios && ios[enableScreenCaptureMethod];\n\n if (isAndroid) {\n android[enableScreenCaptureMethod]();\n } else if (isIos) {\n ios[enableScreenCaptureMethod].postMessage({});\n } else if (typeof window !== 'undefined') {\n console.log('--enableScreenCapture-isWeb');\n }\n }\n\n const disableScreenCapture = () => {\n const isAndroid = android && android[disableScreenCaptureMethod];\n const isIos = ios && ios[disableScreenCaptureMethod];\n\n if (isAndroid) {\n android[disableScreenCaptureMethod]();\n } else if (isIos) {\n ios[disableScreenCaptureMethod].postMessage({});\n } else if (typeof window !== 'undefined') {\n console.log('--disableScreenCapture-isWeb');\n }\n }\n\n const shareImage = (reqId, text, image) => {\n // !!!======================!!!\n // !!!===== Deprecated =====!!!\n // !!!======================!!!\n\n // const isAndroid = android && android[shareImageMethod];\n // const isIos = ios && ios[shareImageMethod];\n\n // if (isAndroid) {\n // android[shareImageMethod](reqId, text, image);\n // } else if (isIos) {\n // ios[shareImageMethod].postMessage({ reqId, text, image });\n // } else if (typeof window !== 'undefined') {\n // console.log('--shareImage-isWeb');\n // }\n\n // new one - fallback to shareFile\n const isAndroid = android && android[shareFileMethod];\n const isIos = ios && ios[shareFileMethod];\n\n // get extension from base64 mime type and merge with name\n const ext = image.split(';')[0].split('/')[1];\n const filename = 'image.' + ext;\n // remove mime type\n const base64Data = image.substr(image.indexOf(',') + 1);\n\n if (isAndroid) {\n android[shareFileMethod](reqId, text, filename, base64Data);\n } else if (isIos) {\n ios[shareFileMethod].postMessage({ reqId, text, filename, base64Data });\n } else if (typeof window !== 'undefined') {\n console.log('--shareFile-isWeb');\n }\n }\n\n const shareFile = (reqId, text, filename, base64Data) => {\n const isAndroid = android && android[shareFileMethod];\n const isIos = ios && ios[shareFileMethod];\n\n if (isAndroid) {\n android[shareFileMethod](reqId, text, filename, base64Data);\n } else if (isIos) {\n ios[shareFileMethod].postMessage({ reqId, text, filename, base64Data });\n } else if (typeof window !== 'undefined') {\n console.log('--shareFile-isWeb');\n }\n }\n\n const enableNotifications = () => invokePromise(EInvokeRequest.enableNotifications);\n\n const disableNotifications = () => invokePromise(EInvokeRequest.disableNotifications);\n\n const setShakeHandler = (handler) => {\n const isAndroid = android && android[setShakeHandlerMethod];\n const isIos = ios && ios[setShakeHandlerMethod];\n\n if (isAndroid || isIos) {\n (window as any).onAituBridgeShake = handler;\n } else if (typeof window !== 'undefined') {\n console.log('--setShakeHandler-isWeb');\n }\n };\n\n const setTabActiveHandler = (handler: (tabname: string) => void) => {\n const isAndroid = android && android[setTabActiveHandlerMethod];\n const isIos = ios && ios[setTabActiveHandlerMethod];\n\n if (isAndroid || isIos) {\n (window as any).onAituBridgeTabActive = handler;\n } else if (typeof window !== 'undefined') {\n console.log('--setTabActiveHandler-isWeb');\n }\n };\n\n const vibrate = (reqId, pattern) => {\n if (\n !Array.isArray(pattern) ||\n pattern.some((timing) => timing < 1 || timing !== Math.floor(timing)) ||\n pattern.reduce((total, timing) => total + timing) > 10000\n ) {\n console.error('Pattern should be an array of positive integers no longer than 10000ms total');\n return;\n }\n\n const isAndroid = android && android[vibrateMethod];\n const isIos = ios && ios[vibrateMethod];\n\n if (isAndroid) {\n android[vibrateMethod](reqId, JSON.stringify(pattern));\n } else if (isIos) {\n ios[vibrateMethod].postMessage({ reqId, pattern });\n } else if (typeof window !== 'undefined') {\n console.log('--vibrate-isWeb');\n }\n }\n\n const isSupported = () => {\n const iosSup = ios && (window as any).webkit.messageHandlers.invoke;\n return Boolean(android || iosSup || web);\n }\n\n const supports = (method) =>\n (android && typeof android[method] === 'function') ||\n (ios && ios[method] && typeof ios[method].postMessage === 'function') ||\n (web && typeof web[method] === 'function');\n\n const sub = (listener: any) => {\n subs.push(listener);\n }\n\n const invokePromise = promisifyInvoke(invoke, sub);\n const storagePromise = promisifyStorage(storage, sub);\n const getGeoPromise = promisifyMethod(getGeo, sub);\n const getQrPromise = promisifyMethod(getQr, sub);\n const getSMSCodePromise = promisifyMethod(getSMSCode, sub);\n const selectContactPromise = promisifyMethod(selectContact, sub);\n const openSettingsPromise = promisifyMethod(openSettings, sub);\n const closeApplicationPromise = promisifyMethod(closeApplication, sub);\n const sharePromise = promisifyMethod(share, sub);\n const setTitlePromise = promisifyMethod(setTitle, sub);\n const copyToClipboardPromise = promisifyMethod(copyToClipboard, sub);\n const shareImagePromise = promisifyMethod(shareImage, sub);\n const shareFilePromise = promisifyMethod(shareFile, sub);\n const vibratePromise = promisifyMethod(vibrate, sub);\n const enableScreenCapturePromise = promisifyMethod(enableScreenCapture, sub);\n const disableScreenCapturePromise = promisifyMethod(disableScreenCapture, sub);\n\n return {\n copyToClipboard: copyToClipboardPromise,\n invoke: invokePromise,\n storage: storagePromise,\n getMe: () => invokePromise(EInvokeRequest.getMe),\n getPhone: () => invokePromise(EInvokeRequest.getPhone),\n getContacts: () => invokePromise(EInvokeRequest.getContacts),\n getGeo: getGeoPromise,\n getQr: getQrPromise,\n getSMSCode: getSMSCodePromise,\n getUserProfile: (id: string) => invokePromise(EInvokeRequest.getUserProfile, { id }),\n selectContact: selectContactPromise,\n enableNotifications,\n disableNotifications,\n openSettings: openSettingsPromise,\n closeApplication: closeApplicationPromise,\n setTitle: setTitlePromise,\n share: sharePromise,\n shareImage: shareImagePromise,\n shareFile: shareFilePromise,\n setShakeHandler,\n setTabActiveHandler,\n vibrate: vibratePromise,\n isSupported,\n supports,\n sub,\n enableScreenCapture: enableScreenCapturePromise,\n disableScreenCapture: disableScreenCapturePromise\n }\n}\n\nconst bridge = buildBridge();\n\nexport default bridge;\n","function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n}\n\nfunction createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n\n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n\n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const invokeId = id;\n promiseControllers[invokeId] = controller;\n return invokeId;\n },\n\n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n\n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n\n promiseControllers[reqId] = null;\n }\n },\n };\n}\n\nfunction promisifyInvoke(invoke, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n\n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n\n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n\n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return function promisifiedFunc(method: any, props: any = {}): Promise<any | void> {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject }, props.reqId);\n\n invoke(reqId, method, props);\n });\n };\n}\n\nexport default promisifyInvoke;\n","function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n }\n \n function createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n \n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n \n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const storageId = `s${id}`;\n promiseControllers[storageId] = controller;\n return storageId;\n },\n \n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n \n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n \n promiseControllers[reqId] = null;\n }\n },\n };\n }\n \n function promisifyStorage(storage, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n \n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n \n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n \n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return {\n setItem: (keyName: string, keyValue: string): Promise<void> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'setItem', { keyName, keyValue });\n });\n },\n getItem: (keyName: string): Promise<string | null> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'getItem', { keyName });\n });\n },\n clear: (): Promise<void> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'clear', {});\n });\n },\n }\n }\n \n export default promisifyStorage;\n "],"names":["promisifyMethod","method","subscribe","counter","promiseControllers","requestResolver","current","next","this","add","controller","customId","methodId","resolve","reqId","data","isSuccess","error","requestPromise","reject","event","detail","Promise","EInvokeRequest","invokeMethod","storageMethod","android","window","AndroidBridge","ios","webkit","messageHandlers","web","top","WebBridge","aituOrigin","AITU_ORIGIN","forEach","postMessage","JSON","stringify","payload","addEventListener","origin","parse","dispatchEvent","CustomEvent","e","subs","map","fn","call","sub","listener","push","invokePromise","invokeId","props","isIos","isWeb","console","log","invoke","storagePromise","storage","storageId","setItem","keyName","keyValue","getItem","clear","promisifyStorage","getGeoPromise","getQrPromise","getSMSCodePromise","selectContactPromise","openSettingsPromise","closeApplicationPromise","sharePromise","text","setTitlePromise","copyToClipboardPromise","shareImagePromise","image","isAndroid","filename","split","base64Data","substr","indexOf","shareFilePromise","vibratePromise","pattern","Array","isArray","some","timing","Math","floor","reduce","total","enableScreenCapturePromise","disableScreenCapturePromise","copyToClipboard","getMe","getPhone","getContacts","getGeo","getQr","getSMSCode","getUserProfile","id","selectContact","enableNotifications","disableNotifications","openSettings","closeApplication","setTitle","share","shareImage","shareFile","setShakeHandler","handler","onAituBridgeShake","setTabActiveHandler","onAituBridgeTabActive","vibrate","isSupported","iosSup","Boolean","supports","enableScreenCapture","disableScreenCapture","buildBridge"],"mappings":"mLA0CA,SAASA,EAAgBC,EAAQC,GAC/B,IA5BMC,EACAC,EA2BAC,GA5BAF,EAdC,CACLG,QAAS,EACTC,gBACE,QAASC,KAAKF,UAYZF,EAA+D,GAE9D,CACLK,aAAIC,EAA+BC,GACjC,IACMC,EADiB,MAAZD,EAAmBA,EAAWR,EAAQI,OAGjD,OADAH,EAAmBQ,GAAYF,EACxBE,GAGTC,iBAAWC,EAAwBC,EAASC,EAAiCC,GAC3E,IAAMC,EAAiBd,EAAmBU,GAEtCI,IACEF,EAAUC,GACZC,EAAeL,QAAQE,GAEvBG,EAAeC,OAAOF,GAGxBb,EAAmBU,GAAS,SAuBlC,OAdAZ,EAAU,SAACkB,GACT,GAAKA,EAAMC,QAIP,UAAWD,E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,EAAchC,EAAeuF,eAAgB,CAAEC,GAAAA,KAC/EC,cAAerC,EACfsC,oBA3F0B,kBAAM1D,EAAchC,EAAe0F,sBA4F7DC,qBA1F2B,kBAAM3D,EAAchC,EAAe2F,uBA2F9DC,aAAcvC,EACdwC,iBAAkBvC,EAClBwC,SAAUrC,EACVsC,MAAOxC,EACPyC,WAAYrC,EACZsC,UAAW9B,EACX+B,gBA/FsB,SAACC,GACLhG,GAAWA,EAAO,iBACtBG,GAAOA,EAAG,gBAGrBF,OAAegG,kBAAoBD,EACT,oBAAX/F,QAChBiC,QAAQC,IAAI,4BAyFd+D,oBArF0B,SAACF,GACThG,GAAWA,EAAO,qBACtBG,GAAOA,EAAG,oBAGrBF,OAAekG,sBAAwBH,EACb,oBAAX/F,QAChBiC,QAAQC,IAAI,gCA+EdiE,QAASnC,EACToC,YAtDkB,WAClB,IAAMC,EAASnG,GAAQF,OAAeG,OAAOC,gBAAgB+B,OAC7D,OAAOmE,QAAQvG,GAAWsG,GAAUhG,IAqDpCkG,SAlDe,SAACjI,UACfyB,GAAsC,mBAApBA,EAAQzB,IAC1B4B,GAAOA,EAAI5B,IAA8C,mBAA5B4B,EAAI5B,GAAQqC,aACzCN,GAA8B,mBAAhBA,EAAI/B,IAgDnBmD,IAAAA,EACA+E,oBAAqB9B,EACrB+B,qBAAsB9B,GAIX+B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@btsd/aitu-bridge",
3
- "version": "0.2.6",
3
+ "version": "0.2.10",
4
4
  "description": "",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/index.js",
package/src/index.ts CHANGED
@@ -6,6 +6,7 @@ enum EInvokeRequest {
6
6
  getMe = 'GetMe',
7
7
  getPhone = 'GetPhone',
8
8
  getContacts = 'GetContacts',
9
+ getUserProfile = 'GetUserProfile',
9
10
  enableNotifications = 'AllowNotifications',
10
11
  disableNotifications = 'DisableNotifications'
11
12
  }
@@ -54,6 +55,14 @@ interface SelectContactResponse {
54
55
  lastname: string;
55
56
  }
56
57
 
58
+ interface GetUserProfileResponse {
59
+ name: string;
60
+ lastname?: string;
61
+ phone?: string;
62
+ avatar?: string;
63
+ avatarThumb?: string;
64
+ }
65
+
57
66
  type OpenSettingsResponse = 'success' | 'failed';
58
67
  type ShareResponse = 'success' | 'failed';
59
68
  type CopyToClipboardResponse = 'success' | 'failed';
@@ -79,6 +88,7 @@ interface AituBridge {
79
88
  selectContact: () => Promise<SelectContactResponse>;
80
89
  getQr: () => Promise<string>;
81
90
  getSMSCode: () => Promise<string>;
91
+ getUserProfile: (userId: string) => Promise<GetUserProfileResponse>;
82
92
  share: (text: string) => Promise<ShareResponse>;
83
93
  setTitle: (text: string) => Promise<ResponseType>;
84
94
  copyToClipboard: (text: string) => Promise<CopyToClipboardResponse>;
@@ -89,10 +99,13 @@ interface AituBridge {
89
99
  openSettings: () => Promise<OpenSettingsResponse>;
90
100
  closeApplication: () => Promise<ResponseType>;
91
101
  setShakeHandler: (handler: any) => void;
102
+ setTabActiveHandler: (handler: (tabname: string) => void) => void;
92
103
  vibrate: (pattern: number[]) => Promise<VibratePattern>;
93
104
  isSupported: () => boolean;
94
105
  supports: (method: string) => boolean;
95
106
  sub: any;
107
+ enableScreenCapture: () => Promise<{}>;
108
+ disableScreenCapture: () => Promise<{}>;
96
109
  }
97
110
 
98
111
  const invokeMethod = 'invoke';
@@ -110,6 +123,9 @@ const shareImageMethod = 'shareImage';
110
123
  const shareFileMethod = 'shareFile';
111
124
  const setShakeHandlerMethod = 'setShakeHandler';
112
125
  const vibrateMethod = 'vibrate';
126
+ const enableScreenCaptureMethod = 'enableScreenCaptureMethod';
127
+ const disableScreenCaptureMethod = 'disableScreenCaptureMethod';
128
+ const setTabActiveHandlerMethod = 'setTabActiveHandler';
113
129
 
114
130
  const android = typeof window !== 'undefined' && (window as any).AndroidBridge;
115
131
  const ios = typeof window !== 'undefined' && (window as any).webkit && (window as any).webkit.messageHandlers;
@@ -132,7 +148,7 @@ if (web) {
132
148
  try {
133
149
  const detail = JSON.parse(event.data);
134
150
  window.dispatchEvent(new CustomEvent('aituEvents', { detail }));
135
- } catch(e) {}
151
+ } catch (e) { }
136
152
  }
137
153
  });
138
154
  }
@@ -282,7 +298,7 @@ const buildBridge = (): AituBridge => {
282
298
  }
283
299
  }
284
300
 
285
- const copyToClipboard = (reqId, text) => {
301
+ const copyToClipboard = (reqId, text) => {
286
302
  const isAndroid = android && android[copyToClipboardMethod];
287
303
  const isIos = ios && ios[copyToClipboardMethod];
288
304
 
@@ -295,6 +311,32 @@ const buildBridge = (): AituBridge => {
295
311
  }
296
312
  }
297
313
 
314
+ const enableScreenCapture = () => {
315
+ const isAndroid = android && android[enableScreenCaptureMethod];
316
+ const isIos = ios && ios[enableScreenCaptureMethod];
317
+
318
+ if (isAndroid) {
319
+ android[enableScreenCaptureMethod]();
320
+ } else if (isIos) {
321
+ ios[enableScreenCaptureMethod].postMessage({});
322
+ } else if (typeof window !== 'undefined') {
323
+ console.log('--enableScreenCapture-isWeb');
324
+ }
325
+ }
326
+
327
+ const disableScreenCapture = () => {
328
+ const isAndroid = android && android[disableScreenCaptureMethod];
329
+ const isIos = ios && ios[disableScreenCaptureMethod];
330
+
331
+ if (isAndroid) {
332
+ android[disableScreenCaptureMethod]();
333
+ } else if (isIos) {
334
+ ios[disableScreenCaptureMethod].postMessage({});
335
+ } else if (typeof window !== 'undefined') {
336
+ console.log('--disableScreenCapture-isWeb');
337
+ }
338
+ }
339
+
298
340
  const shareImage = (reqId, text, image) => {
299
341
  // !!!======================!!!
300
342
  // !!!===== Deprecated =====!!!
@@ -315,8 +357,11 @@ const buildBridge = (): AituBridge => {
315
357
  const isAndroid = android && android[shareFileMethod];
316
358
  const isIos = ios && ios[shareFileMethod];
317
359
 
318
- const filename = 'image';
319
- const base64Data = image;
360
+ // get extension from base64 mime type and merge with name
361
+ const ext = image.split(';')[0].split('/')[1];
362
+ const filename = 'image.' + ext;
363
+ // remove mime type
364
+ const base64Data = image.substr(image.indexOf(',') + 1);
320
365
 
321
366
  if (isAndroid) {
322
367
  android[shareFileMethod](reqId, text, filename, base64Data);
@@ -355,6 +400,17 @@ const buildBridge = (): AituBridge => {
355
400
  }
356
401
  };
357
402
 
403
+ const setTabActiveHandler = (handler: (tabname: string) => void) => {
404
+ const isAndroid = android && android[setTabActiveHandlerMethod];
405
+ const isIos = ios && ios[setTabActiveHandlerMethod];
406
+
407
+ if (isAndroid || isIos) {
408
+ (window as any).onAituBridgeTabActive = handler;
409
+ } else if (typeof window !== 'undefined') {
410
+ console.log('--setTabActiveHandler-isWeb');
411
+ }
412
+ };
413
+
358
414
  const vibrate = (reqId, pattern) => {
359
415
  if (
360
416
  !Array.isArray(pattern) ||
@@ -405,6 +461,8 @@ const buildBridge = (): AituBridge => {
405
461
  const shareImagePromise = promisifyMethod(shareImage, sub);
406
462
  const shareFilePromise = promisifyMethod(shareFile, sub);
407
463
  const vibratePromise = promisifyMethod(vibrate, sub);
464
+ const enableScreenCapturePromise = promisifyMethod(enableScreenCapture, sub);
465
+ const disableScreenCapturePromise = promisifyMethod(disableScreenCapture, sub);
408
466
 
409
467
  return {
410
468
  copyToClipboard: copyToClipboardPromise,
@@ -416,6 +474,7 @@ const buildBridge = (): AituBridge => {
416
474
  getGeo: getGeoPromise,
417
475
  getQr: getQrPromise,
418
476
  getSMSCode: getSMSCodePromise,
477
+ getUserProfile: (id: string) => invokePromise(EInvokeRequest.getUserProfile, { id }),
419
478
  selectContact: selectContactPromise,
420
479
  enableNotifications,
421
480
  disableNotifications,
@@ -426,10 +485,13 @@ const buildBridge = (): AituBridge => {
426
485
  shareImage: shareImagePromise,
427
486
  shareFile: shareFilePromise,
428
487
  setShakeHandler,
488
+ setTabActiveHandler,
429
489
  vibrate: vibratePromise,
430
490
  isSupported,
431
491
  supports,
432
- sub
492
+ sub,
493
+ enableScreenCapture: enableScreenCapturePromise,
494
+ disableScreenCapture: disableScreenCapturePromise
433
495
  }
434
496
  }
435
497