@btsd/aitu-bridge 0.3.59 → 0.4.0

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/src/index.ts CHANGED
@@ -1,12 +1,9 @@
1
1
  import { LIB_VERSION } from './version';
2
2
 
3
- import {
4
- promisifyMethod,
5
- promisifyStorage,
6
- promisifyInvoke,
7
- } from './utils'
3
+ import { promisifyMethod, promisifyStorage, promisifyInvoke } from './utils';
8
4
 
9
5
  import WebBridge from './webBridge';
6
+ export * from './error';
10
7
 
11
8
  enum EInvokeRequest {
12
9
  getMe = 'GetMe',
@@ -79,25 +76,25 @@ export interface GetUserProfileResponse {
79
76
  const MAX_HEADER_MENU_ITEMS_COUNT = 3;
80
77
 
81
78
  export enum HeaderMenuIcon {
82
- Search = "Search",
83
- ShoppingCart = "ShoppingCart",
84
- Menu = "Menu",
85
- Share = "Share",
86
- Notifications = "Notifications",
87
- Help = "Help",
88
- Error = "Error",
89
- Person = "Person",
90
- Sort = "Sort",
91
- Filter = "Filter",
92
- Close = "Close",
93
- SystemNotifications = "SystemNotifications"
79
+ Search = 'Search',
80
+ ShoppingCart = 'ShoppingCart',
81
+ Menu = 'Menu',
82
+ Share = 'Share',
83
+ Notifications = 'Notifications',
84
+ Help = 'Help',
85
+ Error = 'Error',
86
+ Person = 'Person',
87
+ Sort = 'Sort',
88
+ Filter = 'Filter',
89
+ Close = 'Close',
90
+ SystemNotifications = 'SystemNotifications',
94
91
  }
95
92
 
96
93
  export enum NavigationItemMode {
97
- SystemBackArrow = "SystemBackArrow",
98
- CustomBackArrow = "CustomBackArrow",
99
- NoItem = "NoItem",
100
- UserProfile = "UserProfile",
94
+ SystemBackArrow = 'SystemBackArrow',
95
+ CustomBackArrow = 'CustomBackArrow',
96
+ NoItem = 'NoItem',
97
+ UserProfile = 'UserProfile',
101
98
  }
102
99
 
103
100
  export interface HeaderMenuItem {
@@ -118,7 +115,6 @@ export interface UserStepInfoResponse {
118
115
  type OpenSettingsResponse = 'success' | 'failed';
119
116
  type ShareResponse = 'success' | 'failed';
120
117
  type CopyToClipboardResponse = 'success' | 'failed';
121
- type VibrateResponse = 'success' | 'failed';
122
118
  // todo: remove duplicates
123
119
  type ResponseType = 'success' | 'failed';
124
120
  type BiometryResponse = 'success' | 'failed' | 'unavailable' | 'cancelled';
@@ -126,9 +122,9 @@ type BiometryResponse = 'success' | 'failed' | 'unavailable' | 'cancelled';
126
122
  type BridgeInvoke<T extends EInvokeRequest, R> = (method: T, data?: {}) => Promise<R>;
127
123
 
128
124
  interface BridgeStorage {
129
- setItem: SetItemType,
130
- getItem: GetItemType,
131
- clear: ClearType
125
+ setItem: SetItemType;
126
+ getItem: GetItemType;
127
+ clear: ClearType;
132
128
  }
133
129
 
134
130
  export interface AituBridge {
@@ -176,6 +172,8 @@ export interface AituBridge {
176
172
  setNavigationItemMode: (mode: NavigationItemMode) => Promise<void>;
177
173
  getNavigationItemMode: () => Promise<NavigationItemMode>;
178
174
  getUserStepInfo: () => Promise<UserStepInfoResponse>;
175
+ isESimSupported: () => Promise<ResponseType>;
176
+ activateESim: (activationCode: string) => Promise<ResponseType>;
179
177
  }
180
178
 
181
179
  const invokeMethod = 'invoke';
@@ -201,7 +199,7 @@ const setHeaderMenuItemClickHandlerMethod = 'setHeaderMenuItemClickHandler';
201
199
  const setCustomBackArrowModeMethod = 'setCustomBackArrowMode';
202
200
  const getCustomBackArrowModeMethod = 'getCustomBackArrowMode';
203
201
  const setCustomBackArrowVisibleMethod = 'setCustomBackArrowVisible';
204
- const openPaymentMethod = 'openPayment'
202
+ const openPaymentMethod = 'openPayment';
205
203
  const setCustomBackArrowOnClickHandlerMethod = 'setCustomBackArrowOnClickHandler';
206
204
  const checkBiometryMethod = 'checkBiometry';
207
205
  const openExternalUrlMethod = 'openExternalUrl';
@@ -213,7 +211,7 @@ const getUserStepInfoMethod = 'getUserStepInfo';
213
211
 
214
212
  const android = typeof window !== 'undefined' && (window as any).AndroidBridge;
215
213
  const ios = typeof window !== 'undefined' && (window as any).webkit && (window as any).webkit.messageHandlers;
216
- const web = typeof window !== 'undefined' && (window.top !== window) && WebBridge;
214
+ const web = typeof window !== 'undefined' && window.top !== window && WebBridge;
217
215
 
218
216
  const buildBridge = (): AituBridge => {
219
217
  const subs = [];
@@ -221,7 +219,7 @@ const buildBridge = (): AituBridge => {
221
219
  if (typeof window !== 'undefined') {
222
220
  window.addEventListener('aituEvents', (e: any) => {
223
221
  [...subs].map((fn) => fn.call(null, e));
224
- })
222
+ });
225
223
  }
226
224
 
227
225
  const invoke = (reqId, method, data = {}) => {
@@ -233,7 +231,7 @@ const buildBridge = (): AituBridge => {
233
231
  } else if (isIos) {
234
232
  ios[invokeMethod].postMessage({ reqId, method, data });
235
233
  } else if (web) {
236
- web.execute(invokeMethod, reqId, method, data)
234
+ web.execute(invokeMethod, reqId, method, data);
237
235
  } else if (typeof window !== 'undefined') {
238
236
  console.log('--invoke-isUnknown');
239
237
  }
@@ -252,7 +250,7 @@ const buildBridge = (): AituBridge => {
252
250
  } else if (typeof window !== 'undefined') {
253
251
  console.log('--storage-isUnknown');
254
252
  }
255
- }
253
+ };
256
254
 
257
255
  const getGeo = (reqId) => {
258
256
  const isAndroid = android && android[getGeoMethod];
@@ -267,7 +265,7 @@ const buildBridge = (): AituBridge => {
267
265
  } else if (typeof window !== 'undefined') {
268
266
  console.log('--getGeo-isUnknown');
269
267
  }
270
- }
268
+ };
271
269
 
272
270
  const getQr = (reqId) => {
273
271
  const isAndroid = android && android[getQrMethod];
@@ -282,7 +280,7 @@ const buildBridge = (): AituBridge => {
282
280
  } else if (typeof window !== 'undefined') {
283
281
  console.log('--getQr-isUnknown');
284
282
  }
285
- }
283
+ };
286
284
 
287
285
  const getSMSCode = (reqId) => {
288
286
  const isAndroid = android && android[getSMSCodeMethod];
@@ -297,7 +295,7 @@ const buildBridge = (): AituBridge => {
297
295
  } else if (typeof window !== 'undefined') {
298
296
  console.log('--getSMSCode-isUnknown');
299
297
  }
300
- }
298
+ };
301
299
 
302
300
  const selectContact = (reqId) => {
303
301
  const isAndroid = android && android[selectContactMethod];
@@ -312,7 +310,7 @@ const buildBridge = (): AituBridge => {
312
310
  } else if (typeof window !== 'undefined') {
313
311
  console.log('--selectContact-isUnknown');
314
312
  }
315
- }
313
+ };
316
314
 
317
315
  const openSettings = (reqId) => {
318
316
  const isAndroid = android && android[openSettingsMethod];
@@ -327,7 +325,7 @@ const buildBridge = (): AituBridge => {
327
325
  } else if (typeof window !== 'undefined') {
328
326
  console.log('--openSettings-isUnknown');
329
327
  }
330
- }
328
+ };
331
329
 
332
330
  const closeApplication = (reqId) => {
333
331
  const isAndroid = android && android[closeApplicationMethod];
@@ -342,7 +340,7 @@ const buildBridge = (): AituBridge => {
342
340
  } else if (typeof window !== 'undefined') {
343
341
  console.log('--closeApplication-isUnknown');
344
342
  }
345
- }
343
+ };
346
344
 
347
345
  const share = (reqId, text) => {
348
346
  const isAndroid = android && android[shareMethod];
@@ -357,7 +355,7 @@ const buildBridge = (): AituBridge => {
357
355
  } else if (typeof window !== 'undefined') {
358
356
  console.log('--share-isUnknown');
359
357
  }
360
- }
358
+ };
361
359
 
362
360
  const setTitle = (reqId, text) => {
363
361
  const isAndroid = android && android[setTitleMethod];
@@ -372,7 +370,7 @@ const buildBridge = (): AituBridge => {
372
370
  } else if (typeof window !== 'undefined') {
373
371
  console.log('--setTitle-isUnknown');
374
372
  }
375
- }
373
+ };
376
374
 
377
375
  const copyToClipboard = (reqId, text) => {
378
376
  const isAndroid = android && android[copyToClipboardMethod];
@@ -387,7 +385,7 @@ const buildBridge = (): AituBridge => {
387
385
  } else if (typeof window !== 'undefined') {
388
386
  console.log('--copyToClipboard-isUnknown');
389
387
  }
390
- }
388
+ };
391
389
 
392
390
  const enableScreenCapture = (reqId) => {
393
391
  const isAndroid = android && android[enableScreenCaptureMethod];
@@ -402,7 +400,7 @@ const buildBridge = (): AituBridge => {
402
400
  } else if (typeof window !== 'undefined') {
403
401
  console.log('--enableScreenCapture-isUnknown');
404
402
  }
405
- }
403
+ };
406
404
 
407
405
  const disableScreenCapture = (reqId) => {
408
406
  const isAndroid = android && android[disableScreenCaptureMethod];
@@ -417,7 +415,7 @@ const buildBridge = (): AituBridge => {
417
415
  } else if (typeof window !== 'undefined') {
418
416
  console.log('--disableScreenCapture-isUnknown');
419
417
  }
420
- }
418
+ };
421
419
 
422
420
  const shareImage = (reqId, text, image) => {
423
421
  // !!!======================!!!
@@ -454,7 +452,7 @@ const buildBridge = (): AituBridge => {
454
452
  } else if (typeof window !== 'undefined') {
455
453
  console.log('--shareFile-isUnknown');
456
454
  }
457
- }
455
+ };
458
456
 
459
457
  const shareFile = (reqId, text, filename, base64Data) => {
460
458
  const isAndroid = android && android[shareFileMethod];
@@ -469,7 +467,7 @@ const buildBridge = (): AituBridge => {
469
467
  } else if (typeof window !== 'undefined') {
470
468
  console.log('--shareFile-isUnknown');
471
469
  }
472
- }
470
+ };
473
471
 
474
472
  const enableNotifications = () => invokePromise(EInvokeRequest.enableNotifications);
475
473
 
@@ -519,12 +517,12 @@ const buildBridge = (): AituBridge => {
519
517
  } else if (typeof window !== 'undefined') {
520
518
  console.log('--vibrate-isUnknown');
521
519
  }
522
- }
520
+ };
523
521
 
524
522
  const isSupported = () => {
525
523
  const iosSup = ios && (window as any).webkit.messageHandlers.invoke;
526
524
  return Boolean(android || iosSup || web);
527
- }
525
+ };
528
526
 
529
527
  // TODO: implement web support
530
528
  const supports = (method) =>
@@ -534,7 +532,26 @@ const buildBridge = (): AituBridge => {
534
532
 
535
533
  const sub = (listener: any) => {
536
534
  subs.push(listener);
537
- }
535
+ };
536
+
537
+ const createMethod = <Params extends unknown[], Result>(name: string, transform?: (args: Params) => Record<string, Params[number]>) => {
538
+ const method = (reqId: string, ...args: Params) => {
539
+ const isAndroid = android && android[name];
540
+ const isIos = ios && ios[name];
541
+
542
+ if (isAndroid) {
543
+ android[name](reqId, ...args);
544
+ } else if (isIos) {
545
+ ios[name].postMessage({ reqId, ...transform?.(args) });
546
+ } else if (web) {
547
+ web.execute(name as unknown as keyof AituBridge, reqId, ...args);
548
+ } else if (typeof window !== 'undefined') {
549
+ console.log(`--${name}-isUnknown`);
550
+ }
551
+ };
552
+
553
+ return promisifyMethod(method, name, sub) as (...args: Params) => Promise<Result>;
554
+ };
538
555
 
539
556
  const setHeaderMenuItems = (reqId, items: Array<HeaderMenuItem>) => {
540
557
  if (items.length > MAX_HEADER_MENU_ITEMS_COUNT) {
@@ -556,7 +573,7 @@ const buildBridge = (): AituBridge => {
556
573
  } else if (typeof window !== 'undefined') {
557
574
  console.log('--setHeaderMenuItems-isUnknown');
558
575
  }
559
- }
576
+ };
560
577
 
561
578
  const setHeaderMenuItemClickHandler = (handler: HeaderMenuItemClickHandlerType) => {
562
579
  const isAndroid = android && android[setHeaderMenuItemClickHandlerMethod];
@@ -567,7 +584,7 @@ const buildBridge = (): AituBridge => {
567
584
  } else if (typeof window !== 'undefined') {
568
585
  console.log('--setHeaderMenuItemClickHandler-isUnknown');
569
586
  }
570
- }
587
+ };
571
588
 
572
589
  /**
573
590
  * @deprecated данный метод не рекомендуется использовать
@@ -586,7 +603,7 @@ const buildBridge = (): AituBridge => {
586
603
  } else if (typeof window !== 'undefined') {
587
604
  console.log('--setCustomBackArrowMode-isUnknown');
588
605
  }
589
- }
606
+ };
590
607
 
591
608
  /**
592
609
  * @deprecated данный метод не рекомендуется использовать
@@ -605,7 +622,7 @@ const buildBridge = (): AituBridge => {
605
622
  } else if (typeof window !== 'undefined') {
606
623
  console.log('--getCustomBackArrowMode-isUnknown');
607
624
  }
608
- }
625
+ };
609
626
 
610
627
  /**
611
628
  * @deprecated данный метод не рекомендуется использовать
@@ -624,7 +641,7 @@ const buildBridge = (): AituBridge => {
624
641
  } else if (typeof window !== 'undefined') {
625
642
  console.log('--setCustomBackArrowVisible-isUnknown');
626
643
  }
627
- }
644
+ };
628
645
 
629
646
  const setCustomBackArrowOnClickHandler = (handler: BackArrowClickHandlerType) => {
630
647
  const isAndroid = android && android[setCustomBackArrowOnClickHandlerMethod];
@@ -635,7 +652,7 @@ const buildBridge = (): AituBridge => {
635
652
  } else if (typeof window !== 'undefined') {
636
653
  console.log('--setCustomBackArrowOnClickHandler-isUnknown');
637
654
  }
638
- }
655
+ };
639
656
 
640
657
  const openPayment = (reqId, transactionId: string) => {
641
658
  const isAndroid = android && android[openPaymentMethod];
@@ -648,7 +665,7 @@ const buildBridge = (): AituBridge => {
648
665
  } else {
649
666
  console.log('--openPayment-isUnknown');
650
667
  }
651
- }
668
+ };
652
669
 
653
670
  const checkBiometry = (reqId) => {
654
671
  const isAndroid = android && android[checkBiometryMethod];
@@ -663,7 +680,7 @@ const buildBridge = (): AituBridge => {
663
680
  } else if (typeof window !== 'undefined') {
664
681
  console.log('--checkBiometry-isUnknown');
665
682
  }
666
- }
683
+ };
667
684
 
668
685
  const openExternalUrl = (reqId, url: string) => {
669
686
  const isAndroid = android && android[openExternalUrlMethod];
@@ -674,7 +691,7 @@ const buildBridge = (): AituBridge => {
674
691
  } else if (isIos) {
675
692
  ios[openExternalUrlMethod].postMessage({ reqId, url });
676
693
  } else {
677
- console.log("--openExternalUrlMethod-isUnknown");
694
+ console.log('--openExternalUrlMethod-isUnknown');
678
695
  }
679
696
  };
680
697
 
@@ -691,7 +708,7 @@ const buildBridge = (): AituBridge => {
691
708
  } else if (typeof window !== 'undefined') {
692
709
  console.log('--enableSwipeBack-isUnknown');
693
710
  }
694
- }
711
+ };
695
712
 
696
713
  const disableSwipeBack = (reqId) => {
697
714
  const isAndroid = android && android[disableSwipeBackMethod];
@@ -706,7 +723,7 @@ const buildBridge = (): AituBridge => {
706
723
  } else if (typeof window !== 'undefined') {
707
724
  console.log('--disableSwipeBack-isUnknown');
708
725
  }
709
- }
726
+ };
710
727
 
711
728
  const setNavigationItemMode = (reqId, mode: NavigationItemMode) => {
712
729
  const isAndroid = android && android[setNavigationItemModeMethod];
@@ -721,7 +738,7 @@ const buildBridge = (): AituBridge => {
721
738
  } else if (typeof window !== 'undefined') {
722
739
  console.log('--setNavigationItemMode-isUnknown');
723
740
  }
724
- }
741
+ };
725
742
 
726
743
  const getNavigationItemMode = (reqId) => {
727
744
  const isAndroid = android && android[getNavigationItemModeMethod];
@@ -736,7 +753,7 @@ const buildBridge = (): AituBridge => {
736
753
  } else if (typeof window !== 'undefined') {
737
754
  console.log('--getNavigationItemMode-isUnknown');
738
755
  }
739
- }
756
+ };
740
757
 
741
758
  const getUserStepInfo = (reqId) => {
742
759
  const isAndroid = android && android[getUserStepInfoMethod];
@@ -751,7 +768,7 @@ const buildBridge = (): AituBridge => {
751
768
  } else if (typeof window !== 'undefined') {
752
769
  console.log('--getUserStepInfo-isUnknown');
753
770
  }
754
- }
771
+ };
755
772
 
756
773
  const invokePromise = promisifyInvoke(invoke, sub);
757
774
  const storagePromise = promisifyStorage(storage, sub);
@@ -781,6 +798,10 @@ const buildBridge = (): AituBridge => {
781
798
  const setNavigationItemModePromise = promisifyMethod(setNavigationItemMode, setNavigationItemModeMethod, sub);
782
799
  const getNavigationItemModePromise = promisifyMethod(getNavigationItemMode, getNavigationItemModeMethod, sub);
783
800
  const getUserStepInfoPromise = promisifyMethod(getUserStepInfo, getUserStepInfoMethod, sub);
801
+ const isESimSupported = createMethod<never, ResponseType>('isESimSupported');
802
+ const activateESim = createMethod<[activationCode: string], ResponseType>('activateESim', ([activationCode]) => ({
803
+ activationCode,
804
+ }));
784
805
 
785
806
  return {
786
807
  version: String(LIB_VERSION),
@@ -793,15 +814,12 @@ const buildBridge = (): AituBridge => {
793
814
  getGeo: getGeoPromise,
794
815
  getQr: getQrPromise,
795
816
  getSMSCode: getSMSCodePromise,
796
- getUserProfile: (id: string) =>
797
- invokePromise(EInvokeRequest.getUserProfile, { id }),
817
+ getUserProfile: (id: string) => invokePromise(EInvokeRequest.getUserProfile, { id }),
798
818
  selectContact: selectContactPromise,
799
819
  enableNotifications,
800
820
  disableNotifications,
801
- enablePrivateMessaging: (appId: string) =>
802
- invokePromise(EInvokeRequest.enablePrivateMessaging, { appId }),
803
- disablePrivateMessaging: (appId: string) =>
804
- invokePromise(EInvokeRequest.disablePrivateMessaging, { appId }),
821
+ enablePrivateMessaging: (appId: string) => invokePromise(EInvokeRequest.enablePrivateMessaging, { appId }),
822
+ disablePrivateMessaging: (appId: string) => invokePromise(EInvokeRequest.disablePrivateMessaging, { appId }),
805
823
  openSettings: openSettingsPromise,
806
824
  closeApplication: closeApplicationPromise,
807
825
  setTitle: setTitlePromise,
@@ -830,8 +848,10 @@ const buildBridge = (): AituBridge => {
830
848
  setNavigationItemMode: setNavigationItemModePromise,
831
849
  getNavigationItemMode: getNavigationItemModePromise,
832
850
  getUserStepInfo: getUserStepInfoPromise,
851
+ isESimSupported,
852
+ activateESim,
833
853
  };
834
- }
854
+ };
835
855
 
836
856
  const bridge = buildBridge();
837
857
 
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const LIB_VERSION = "0.3.59";
1
+ export const LIB_VERSION = "0.4.0";