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