@btsd/aitu-bridge 0.3.60 → 0.5.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,9 @@ 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>;
177
+ readNFCData: () => Promise<string>;
180
178
  }
181
179
 
182
180
  const invokeMethod = 'invoke';
@@ -202,7 +200,7 @@ const setHeaderMenuItemClickHandlerMethod = 'setHeaderMenuItemClickHandler';
202
200
  const setCustomBackArrowModeMethod = 'setCustomBackArrowMode';
203
201
  const getCustomBackArrowModeMethod = 'getCustomBackArrowMode';
204
202
  const setCustomBackArrowVisibleMethod = 'setCustomBackArrowVisible';
205
- const openPaymentMethod = 'openPayment'
203
+ const openPaymentMethod = 'openPayment';
206
204
  const setCustomBackArrowOnClickHandlerMethod = 'setCustomBackArrowOnClickHandler';
207
205
  const checkBiometryMethod = 'checkBiometry';
208
206
  const openExternalUrlMethod = 'openExternalUrl';
@@ -214,7 +212,7 @@ const getUserStepInfoMethod = 'getUserStepInfo';
214
212
 
215
213
  const android = typeof window !== 'undefined' && (window as any).AndroidBridge;
216
214
  const ios = typeof window !== 'undefined' && (window as any).webkit && (window as any).webkit.messageHandlers;
217
- const web = typeof window !== 'undefined' && (window.top !== window) && WebBridge;
215
+ const web = typeof window !== 'undefined' && window.top !== window && WebBridge;
218
216
 
219
217
  const buildBridge = (): AituBridge => {
220
218
  const subs = [];
@@ -222,7 +220,7 @@ const buildBridge = (): AituBridge => {
222
220
  if (typeof window !== 'undefined') {
223
221
  window.addEventListener('aituEvents', (e: any) => {
224
222
  [...subs].map((fn) => fn.call(null, e));
225
- })
223
+ });
226
224
  }
227
225
 
228
226
  const invoke = (reqId, method, data = {}) => {
@@ -234,7 +232,7 @@ const buildBridge = (): AituBridge => {
234
232
  } else if (isIos) {
235
233
  ios[invokeMethod].postMessage({ reqId, method, data });
236
234
  } else if (web) {
237
- web.execute(invokeMethod, reqId, method, data)
235
+ web.execute(invokeMethod, reqId, method, data);
238
236
  } else if (typeof window !== 'undefined') {
239
237
  console.log('--invoke-isUnknown');
240
238
  }
@@ -253,7 +251,7 @@ const buildBridge = (): AituBridge => {
253
251
  } else if (typeof window !== 'undefined') {
254
252
  console.log('--storage-isUnknown');
255
253
  }
256
- }
254
+ };
257
255
 
258
256
  const getGeo = (reqId) => {
259
257
  const isAndroid = android && android[getGeoMethod];
@@ -268,7 +266,7 @@ const buildBridge = (): AituBridge => {
268
266
  } else if (typeof window !== 'undefined') {
269
267
  console.log('--getGeo-isUnknown');
270
268
  }
271
- }
269
+ };
272
270
 
273
271
  const getQr = (reqId) => {
274
272
  const isAndroid = android && android[getQrMethod];
@@ -283,7 +281,7 @@ const buildBridge = (): AituBridge => {
283
281
  } else if (typeof window !== 'undefined') {
284
282
  console.log('--getQr-isUnknown');
285
283
  }
286
- }
284
+ };
287
285
 
288
286
  const getSMSCode = (reqId) => {
289
287
  const isAndroid = android && android[getSMSCodeMethod];
@@ -298,7 +296,7 @@ const buildBridge = (): AituBridge => {
298
296
  } else if (typeof window !== 'undefined') {
299
297
  console.log('--getSMSCode-isUnknown');
300
298
  }
301
- }
299
+ };
302
300
 
303
301
  const selectContact = (reqId) => {
304
302
  const isAndroid = android && android[selectContactMethod];
@@ -313,7 +311,7 @@ const buildBridge = (): AituBridge => {
313
311
  } else if (typeof window !== 'undefined') {
314
312
  console.log('--selectContact-isUnknown');
315
313
  }
316
- }
314
+ };
317
315
 
318
316
  const openSettings = (reqId) => {
319
317
  const isAndroid = android && android[openSettingsMethod];
@@ -328,7 +326,7 @@ const buildBridge = (): AituBridge => {
328
326
  } else if (typeof window !== 'undefined') {
329
327
  console.log('--openSettings-isUnknown');
330
328
  }
331
- }
329
+ };
332
330
 
333
331
  const closeApplication = (reqId) => {
334
332
  const isAndroid = android && android[closeApplicationMethod];
@@ -343,7 +341,7 @@ const buildBridge = (): AituBridge => {
343
341
  } else if (typeof window !== 'undefined') {
344
342
  console.log('--closeApplication-isUnknown');
345
343
  }
346
- }
344
+ };
347
345
 
348
346
  const share = (reqId, text) => {
349
347
  const isAndroid = android && android[shareMethod];
@@ -358,7 +356,7 @@ const buildBridge = (): AituBridge => {
358
356
  } else if (typeof window !== 'undefined') {
359
357
  console.log('--share-isUnknown');
360
358
  }
361
- }
359
+ };
362
360
 
363
361
  const setTitle = (reqId, text) => {
364
362
  const isAndroid = android && android[setTitleMethod];
@@ -373,7 +371,7 @@ const buildBridge = (): AituBridge => {
373
371
  } else if (typeof window !== 'undefined') {
374
372
  console.log('--setTitle-isUnknown');
375
373
  }
376
- }
374
+ };
377
375
 
378
376
  const copyToClipboard = (reqId, text) => {
379
377
  const isAndroid = android && android[copyToClipboardMethod];
@@ -388,7 +386,7 @@ const buildBridge = (): AituBridge => {
388
386
  } else if (typeof window !== 'undefined') {
389
387
  console.log('--copyToClipboard-isUnknown');
390
388
  }
391
- }
389
+ };
392
390
 
393
391
  const enableScreenCapture = (reqId) => {
394
392
  const isAndroid = android && android[enableScreenCaptureMethod];
@@ -403,7 +401,7 @@ const buildBridge = (): AituBridge => {
403
401
  } else if (typeof window !== 'undefined') {
404
402
  console.log('--enableScreenCapture-isUnknown');
405
403
  }
406
- }
404
+ };
407
405
 
408
406
  const disableScreenCapture = (reqId) => {
409
407
  const isAndroid = android && android[disableScreenCaptureMethod];
@@ -418,7 +416,7 @@ const buildBridge = (): AituBridge => {
418
416
  } else if (typeof window !== 'undefined') {
419
417
  console.log('--disableScreenCapture-isUnknown');
420
418
  }
421
- }
419
+ };
422
420
 
423
421
  const shareImage = (reqId, text, image) => {
424
422
  // !!!======================!!!
@@ -455,7 +453,7 @@ const buildBridge = (): AituBridge => {
455
453
  } else if (typeof window !== 'undefined') {
456
454
  console.log('--shareFile-isUnknown');
457
455
  }
458
- }
456
+ };
459
457
 
460
458
  const shareFile = (reqId, text, filename, base64Data) => {
461
459
  const isAndroid = android && android[shareFileMethod];
@@ -470,7 +468,7 @@ const buildBridge = (): AituBridge => {
470
468
  } else if (typeof window !== 'undefined') {
471
469
  console.log('--shareFile-isUnknown');
472
470
  }
473
- }
471
+ };
474
472
 
475
473
  const enableNotifications = () => invokePromise(EInvokeRequest.enableNotifications);
476
474
 
@@ -520,12 +518,12 @@ const buildBridge = (): AituBridge => {
520
518
  } else if (typeof window !== 'undefined') {
521
519
  console.log('--vibrate-isUnknown');
522
520
  }
523
- }
521
+ };
524
522
 
525
523
  const isSupported = () => {
526
524
  const iosSup = ios && (window as any).webkit.messageHandlers.invoke;
527
525
  return Boolean(android || iosSup || web);
528
- }
526
+ };
529
527
 
530
528
  // TODO: implement web support
531
529
  const supports = (method) =>
@@ -535,7 +533,26 @@ const buildBridge = (): AituBridge => {
535
533
 
536
534
  const sub = (listener: any) => {
537
535
  subs.push(listener);
538
- }
536
+ };
537
+
538
+ const createMethod = <Params extends unknown[], Result>(name: string, transform?: (args: Params) => Record<string, Params[number]>) => {
539
+ const method = (reqId: string, ...args: Params) => {
540
+ const isAndroid = android && android[name];
541
+ const isIos = ios && ios[name];
542
+
543
+ if (isAndroid) {
544
+ android[name](reqId, ...args);
545
+ } else if (isIos) {
546
+ ios[name].postMessage({ reqId, ...transform?.(args) });
547
+ } else if (web) {
548
+ web.execute(name as unknown as keyof AituBridge, reqId, ...args);
549
+ } else if (typeof window !== 'undefined') {
550
+ console.log(`--${name}-isUnknown`);
551
+ }
552
+ };
553
+
554
+ return promisifyMethod(method, name, sub) as (...args: Params) => Promise<Result>;
555
+ };
539
556
 
540
557
  const setHeaderMenuItems = (reqId, items: Array<HeaderMenuItem>) => {
541
558
  if (items.length > MAX_HEADER_MENU_ITEMS_COUNT) {
@@ -557,7 +574,7 @@ const buildBridge = (): AituBridge => {
557
574
  } else if (typeof window !== 'undefined') {
558
575
  console.log('--setHeaderMenuItems-isUnknown');
559
576
  }
560
- }
577
+ };
561
578
 
562
579
  const setHeaderMenuItemClickHandler = (handler: HeaderMenuItemClickHandlerType) => {
563
580
  const isAndroid = android && android[setHeaderMenuItemClickHandlerMethod];
@@ -568,7 +585,7 @@ const buildBridge = (): AituBridge => {
568
585
  } else if (typeof window !== 'undefined') {
569
586
  console.log('--setHeaderMenuItemClickHandler-isUnknown');
570
587
  }
571
- }
588
+ };
572
589
 
573
590
  /**
574
591
  * @deprecated данный метод не рекомендуется использовать
@@ -587,7 +604,7 @@ const buildBridge = (): AituBridge => {
587
604
  } else if (typeof window !== 'undefined') {
588
605
  console.log('--setCustomBackArrowMode-isUnknown');
589
606
  }
590
- }
607
+ };
591
608
 
592
609
  /**
593
610
  * @deprecated данный метод не рекомендуется использовать
@@ -606,7 +623,7 @@ const buildBridge = (): AituBridge => {
606
623
  } else if (typeof window !== 'undefined') {
607
624
  console.log('--getCustomBackArrowMode-isUnknown');
608
625
  }
609
- }
626
+ };
610
627
 
611
628
  /**
612
629
  * @deprecated данный метод не рекомендуется использовать
@@ -625,7 +642,7 @@ const buildBridge = (): AituBridge => {
625
642
  } else if (typeof window !== 'undefined') {
626
643
  console.log('--setCustomBackArrowVisible-isUnknown');
627
644
  }
628
- }
645
+ };
629
646
 
630
647
  const setCustomBackArrowOnClickHandler = (handler: BackArrowClickHandlerType) => {
631
648
  const isAndroid = android && android[setCustomBackArrowOnClickHandlerMethod];
@@ -636,7 +653,7 @@ const buildBridge = (): AituBridge => {
636
653
  } else if (typeof window !== 'undefined') {
637
654
  console.log('--setCustomBackArrowOnClickHandler-isUnknown');
638
655
  }
639
- }
656
+ };
640
657
 
641
658
  const openPayment = (reqId, transactionId: string) => {
642
659
  const isAndroid = android && android[openPaymentMethod];
@@ -649,7 +666,7 @@ const buildBridge = (): AituBridge => {
649
666
  } else {
650
667
  console.log('--openPayment-isUnknown');
651
668
  }
652
- }
669
+ };
653
670
 
654
671
  const checkBiometry = (reqId) => {
655
672
  const isAndroid = android && android[checkBiometryMethod];
@@ -664,7 +681,7 @@ const buildBridge = (): AituBridge => {
664
681
  } else if (typeof window !== 'undefined') {
665
682
  console.log('--checkBiometry-isUnknown');
666
683
  }
667
- }
684
+ };
668
685
 
669
686
  const openExternalUrl = (reqId, url: string) => {
670
687
  const isAndroid = android && android[openExternalUrlMethod];
@@ -675,7 +692,7 @@ const buildBridge = (): AituBridge => {
675
692
  } else if (isIos) {
676
693
  ios[openExternalUrlMethod].postMessage({ reqId, url });
677
694
  } else {
678
- console.log("--openExternalUrlMethod-isUnknown");
695
+ console.log('--openExternalUrlMethod-isUnknown');
679
696
  }
680
697
  };
681
698
 
@@ -692,7 +709,7 @@ const buildBridge = (): AituBridge => {
692
709
  } else if (typeof window !== 'undefined') {
693
710
  console.log('--enableSwipeBack-isUnknown');
694
711
  }
695
- }
712
+ };
696
713
 
697
714
  const disableSwipeBack = (reqId) => {
698
715
  const isAndroid = android && android[disableSwipeBackMethod];
@@ -707,7 +724,7 @@ const buildBridge = (): AituBridge => {
707
724
  } else if (typeof window !== 'undefined') {
708
725
  console.log('--disableSwipeBack-isUnknown');
709
726
  }
710
- }
727
+ };
711
728
 
712
729
  const setNavigationItemMode = (reqId, mode: NavigationItemMode) => {
713
730
  const isAndroid = android && android[setNavigationItemModeMethod];
@@ -722,7 +739,7 @@ const buildBridge = (): AituBridge => {
722
739
  } else if (typeof window !== 'undefined') {
723
740
  console.log('--setNavigationItemMode-isUnknown');
724
741
  }
725
- }
742
+ };
726
743
 
727
744
  const getNavigationItemMode = (reqId) => {
728
745
  const isAndroid = android && android[getNavigationItemModeMethod];
@@ -737,7 +754,7 @@ const buildBridge = (): AituBridge => {
737
754
  } else if (typeof window !== 'undefined') {
738
755
  console.log('--getNavigationItemMode-isUnknown');
739
756
  }
740
- }
757
+ };
741
758
 
742
759
  const getUserStepInfo = (reqId) => {
743
760
  const isAndroid = android && android[getUserStepInfoMethod];
@@ -752,7 +769,7 @@ const buildBridge = (): AituBridge => {
752
769
  } else if (typeof window !== 'undefined') {
753
770
  console.log('--getUserStepInfo-isUnknown');
754
771
  }
755
- }
772
+ };
756
773
 
757
774
  const invokePromise = promisifyInvoke(invoke, sub);
758
775
  const storagePromise = promisifyStorage(storage, sub);
@@ -782,6 +799,11 @@ const buildBridge = (): AituBridge => {
782
799
  const setNavigationItemModePromise = promisifyMethod(setNavigationItemMode, setNavigationItemModeMethod, sub);
783
800
  const getNavigationItemModePromise = promisifyMethod(getNavigationItemMode, getNavigationItemModeMethod, sub);
784
801
  const getUserStepInfoPromise = promisifyMethod(getUserStepInfo, getUserStepInfoMethod, sub);
802
+ const isESimSupported = createMethod<never, ResponseType>('isESimSupported');
803
+ const activateESim = createMethod<[activationCode: string], ResponseType>('activateESim', ([activationCode]) => ({
804
+ activationCode,
805
+ }));
806
+ const readNFCData = createMethod<never, string>('readNFCData');
785
807
 
786
808
  return {
787
809
  version: String(LIB_VERSION),
@@ -794,15 +816,12 @@ const buildBridge = (): AituBridge => {
794
816
  getGeo: getGeoPromise,
795
817
  getQr: getQrPromise,
796
818
  getSMSCode: getSMSCodePromise,
797
- getUserProfile: (id: string) =>
798
- invokePromise(EInvokeRequest.getUserProfile, { id }),
819
+ getUserProfile: (id: string) => invokePromise(EInvokeRequest.getUserProfile, { id }),
799
820
  selectContact: selectContactPromise,
800
821
  enableNotifications,
801
822
  disableNotifications,
802
- enablePrivateMessaging: (appId: string) =>
803
- invokePromise(EInvokeRequest.enablePrivateMessaging, { appId }),
804
- disablePrivateMessaging: (appId: string) =>
805
- invokePromise(EInvokeRequest.disablePrivateMessaging, { appId }),
823
+ enablePrivateMessaging: (appId: string) => invokePromise(EInvokeRequest.enablePrivateMessaging, { appId }),
824
+ disablePrivateMessaging: (appId: string) => invokePromise(EInvokeRequest.disablePrivateMessaging, { appId }),
806
825
  openSettings: openSettingsPromise,
807
826
  closeApplication: closeApplicationPromise,
808
827
  setTitle: setTitlePromise,
@@ -831,8 +850,11 @@ const buildBridge = (): AituBridge => {
831
850
  setNavigationItemMode: setNavigationItemModePromise,
832
851
  getNavigationItemMode: getNavigationItemModePromise,
833
852
  getUserStepInfo: getUserStepInfoPromise,
853
+ isESimSupported,
854
+ activateESim,
855
+ readNFCData,
834
856
  };
835
- }
857
+ };
836
858
 
837
859
  const bridge = buildBridge();
838
860
 
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const LIB_VERSION = "0.3.60";
1
+ export const LIB_VERSION = "0.5.0";