webtonative 1.0.74 → 1.0.75-beta.2

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.
Files changed (376) hide show
  1. package/.editorconfig +10 -0
  2. package/.prettierrc.json +7 -0
  3. package/README.md +31 -2
  4. package/build/ATTConsent/index.d.ts +17 -0
  5. package/build/ATTConsent/index.d.ts.map +1 -0
  6. package/build/ATTConsent/index.js +54 -0
  7. package/build/ATTConsent/index.js.map +1 -0
  8. package/build/ATTConsent/types.d.ts +15 -0
  9. package/build/ATTConsent/types.d.ts.map +1 -0
  10. package/build/ATTConsent/types.js +3 -0
  11. package/build/ATTConsent/types.js.map +1 -0
  12. package/build/AdMob/index.d.ts +31 -0
  13. package/build/AdMob/index.d.ts.map +1 -0
  14. package/build/AdMob/index.js +102 -0
  15. package/build/AdMob/index.js.map +1 -0
  16. package/build/AdMob/types.d.ts +25 -0
  17. package/build/AdMob/types.d.ts.map +1 -0
  18. package/build/AdMob/types.js +4 -0
  19. package/build/AdMob/types.js.map +1 -0
  20. package/build/AppReview/index.d.ts +7 -0
  21. package/build/AppReview/index.d.ts.map +1 -0
  22. package/build/AppReview/index.js +22 -0
  23. package/build/AppReview/index.js.map +1 -0
  24. package/build/AppReview/types.d.ts +8 -0
  25. package/build/AppReview/types.d.ts.map +1 -0
  26. package/build/AppReview/types.js +4 -0
  27. package/build/AppReview/types.js.map +1 -0
  28. package/build/AppsFlyer/index.d.ts +15 -0
  29. package/build/AppsFlyer/index.d.ts.map +1 -0
  30. package/build/AppsFlyer/index.js +43 -0
  31. package/build/AppsFlyer/index.js.map +1 -0
  32. package/build/AppsFlyer/types.d.ts +10 -0
  33. package/build/AppsFlyer/types.d.ts.map +1 -0
  34. package/build/AppsFlyer/types.js +3 -0
  35. package/build/AppsFlyer/types.js.map +1 -0
  36. package/build/BackgroundLocation/index.d.ts +12 -0
  37. package/build/BackgroundLocation/index.d.ts.map +1 -0
  38. package/build/BackgroundLocation/index.js +65 -0
  39. package/build/BackgroundLocation/index.js.map +1 -0
  40. package/build/BackgroundLocation/types.d.ts +32 -0
  41. package/build/BackgroundLocation/types.d.ts.map +1 -0
  42. package/build/BackgroundLocation/types.js +3 -0
  43. package/build/BackgroundLocation/types.js.map +1 -0
  44. package/build/Beacon/index.d.ts +7 -0
  45. package/build/Beacon/index.d.ts.map +1 -0
  46. package/build/Beacon/index.js +30 -0
  47. package/build/Beacon/index.js.map +1 -0
  48. package/build/Beacon/types.d.ts +19 -0
  49. package/build/Beacon/types.d.ts.map +1 -0
  50. package/build/Beacon/types.js +3 -0
  51. package/build/Beacon/types.js.map +1 -0
  52. package/build/Biometric/index.d.ts +27 -0
  53. package/build/Biometric/index.d.ts.map +1 -0
  54. package/build/Biometric/index.js +125 -0
  55. package/build/Biometric/index.js.map +1 -0
  56. package/build/Biometric/types.d.ts +24 -0
  57. package/build/Biometric/types.d.ts.map +1 -0
  58. package/build/Biometric/types.js +3 -0
  59. package/build/Biometric/types.js.map +1 -0
  60. package/build/Bluetooth/index.d.ts +17 -0
  61. package/build/Bluetooth/index.d.ts.map +1 -0
  62. package/build/Bluetooth/index.js +67 -0
  63. package/build/Bluetooth/index.js.map +1 -0
  64. package/build/Bluetooth/types.d.ts +34 -0
  65. package/build/Bluetooth/types.d.ts.map +1 -0
  66. package/build/Bluetooth/types.js +3 -0
  67. package/build/Bluetooth/types.js.map +1 -0
  68. package/build/BottomNavigation/index.d.ts +11 -0
  69. package/build/BottomNavigation/index.d.ts.map +1 -0
  70. package/build/BottomNavigation/index.js +41 -0
  71. package/build/BottomNavigation/index.js.map +1 -0
  72. package/build/BottomNavigation/types.d.ts +9 -0
  73. package/build/BottomNavigation/types.d.ts.map +1 -0
  74. package/build/BottomNavigation/types.js +3 -0
  75. package/build/BottomNavigation/types.js.map +1 -0
  76. package/build/Clipboard/index.d.ts +12 -0
  77. package/build/Clipboard/index.d.ts.map +1 -0
  78. package/build/Clipboard/index.js +45 -0
  79. package/build/Clipboard/index.js.map +1 -0
  80. package/build/Clipboard/types.d.ts +20 -0
  81. package/build/Clipboard/types.d.ts.map +1 -0
  82. package/build/Clipboard/types.js +4 -0
  83. package/build/Clipboard/types.js.map +1 -0
  84. package/build/Facebook/events.d.ts +13 -0
  85. package/build/Facebook/events.d.ts.map +1 -0
  86. package/build/Facebook/events.js +44 -0
  87. package/build/Facebook/events.js.map +1 -0
  88. package/build/Facebook/index.d.ts +3 -0
  89. package/build/Facebook/index.d.ts.map +1 -0
  90. package/build/Facebook/index.js +29 -0
  91. package/build/Facebook/index.js.map +1 -0
  92. package/build/Facebook/types.d.ts +22 -0
  93. package/build/Facebook/types.d.ts.map +1 -0
  94. package/build/Facebook/types.js +3 -0
  95. package/build/Facebook/types.js.map +1 -0
  96. package/build/Firebase/Analytics/index.d.ts +32 -0
  97. package/build/Firebase/Analytics/index.d.ts.map +1 -0
  98. package/build/Firebase/Analytics/index.js +110 -0
  99. package/build/Firebase/Analytics/index.js.map +1 -0
  100. package/build/Firebase/Messaging/index.d.ts +17 -0
  101. package/build/Firebase/Messaging/index.d.ts.map +1 -0
  102. package/build/Firebase/Messaging/index.js +64 -0
  103. package/build/Firebase/Messaging/index.js.map +1 -0
  104. package/build/Firebase/index.d.ts +4 -0
  105. package/build/Firebase/index.d.ts.map +1 -0
  106. package/build/Firebase/index.js +31 -0
  107. package/build/Firebase/index.js.map +1 -0
  108. package/build/Firebase/types.d.ts +58 -0
  109. package/build/Firebase/types.d.ts.map +1 -0
  110. package/build/Firebase/types.js +4 -0
  111. package/build/Firebase/types.js.map +1 -0
  112. package/build/FirebaseAnalytics/index.d.ts +3 -0
  113. package/build/FirebaseAnalytics/index.d.ts.map +1 -0
  114. package/build/FirebaseAnalytics/index.js +29 -0
  115. package/build/FirebaseAnalytics/index.js.map +1 -0
  116. package/build/Haptics/index.d.ts +7 -0
  117. package/build/Haptics/index.d.ts.map +1 -0
  118. package/build/Haptics/index.js +21 -0
  119. package/build/Haptics/index.js.map +1 -0
  120. package/build/Haptics/types.d.ts +8 -0
  121. package/build/Haptics/types.d.ts.map +1 -0
  122. package/build/Haptics/types.js +3 -0
  123. package/build/Haptics/types.js.map +1 -0
  124. package/build/InAppPurchase/index.d.ts +23 -0
  125. package/build/InAppPurchase/index.d.ts.map +1 -0
  126. package/build/InAppPurchase/index.js +81 -0
  127. package/build/InAppPurchase/index.js.map +1 -0
  128. package/build/InAppPurchase/types.d.ts +30 -0
  129. package/build/InAppPurchase/types.d.ts.map +1 -0
  130. package/build/InAppPurchase/types.js +3 -0
  131. package/build/InAppPurchase/types.js.map +1 -0
  132. package/build/InAppUpdate/index.d.ts +12 -0
  133. package/build/InAppUpdate/index.d.ts.map +1 -0
  134. package/build/InAppUpdate/index.js +39 -0
  135. package/build/InAppUpdate/index.js.map +1 -0
  136. package/build/InAppUpdate/types.d.ts +15 -0
  137. package/build/InAppUpdate/types.d.ts.map +1 -0
  138. package/build/InAppUpdate/types.js +3 -0
  139. package/build/InAppUpdate/types.js.map +1 -0
  140. package/build/MediaPlayer/index.d.ts +17 -0
  141. package/build/MediaPlayer/index.d.ts.map +1 -0
  142. package/build/MediaPlayer/index.js +56 -0
  143. package/build/MediaPlayer/index.js.map +1 -0
  144. package/build/MediaPlayer/types.d.ts +14 -0
  145. package/build/MediaPlayer/types.d.ts.map +1 -0
  146. package/build/MediaPlayer/types.js +3 -0
  147. package/build/MediaPlayer/types.js.map +1 -0
  148. package/build/NativeContacts/index.d.ts +12 -0
  149. package/build/NativeContacts/index.d.ts.map +1 -0
  150. package/build/NativeContacts/index.js +51 -0
  151. package/build/NativeContacts/index.js.map +1 -0
  152. package/build/NativeContacts/types.d.ts +14 -0
  153. package/build/NativeContacts/types.d.ts.map +1 -0
  154. package/build/NativeContacts/types.js +3 -0
  155. package/build/NativeContacts/types.js.map +1 -0
  156. package/build/Notification/index.d.ts +11 -0
  157. package/build/Notification/index.d.ts.map +1 -0
  158. package/build/Notification/index.js +42 -0
  159. package/build/Notification/index.js.map +1 -0
  160. package/build/Notification/types.d.ts +14 -0
  161. package/build/Notification/types.d.ts.map +1 -0
  162. package/build/Notification/types.js +3 -0
  163. package/build/Notification/types.js.map +1 -0
  164. package/build/OneSignal/index.d.ts +4 -0
  165. package/build/OneSignal/index.d.ts.map +1 -0
  166. package/build/OneSignal/index.js +59 -0
  167. package/build/OneSignal/index.js.map +1 -0
  168. package/build/OneSignal/types.d.ts +11 -0
  169. package/build/OneSignal/types.d.ts.map +1 -0
  170. package/build/OneSignal/types.js +4 -0
  171. package/build/OneSignal/types.js.map +1 -0
  172. package/build/Printing/index.d.ts +7 -0
  173. package/build/Printing/index.d.ts.map +1 -0
  174. package/build/Printing/index.js +20 -0
  175. package/build/Printing/index.js.map +1 -0
  176. package/build/Printing/types.d.ts +9 -0
  177. package/build/Printing/types.d.ts.map +1 -0
  178. package/build/Printing/types.js +3 -0
  179. package/build/Printing/types.js.map +1 -0
  180. package/build/README.md +33 -0
  181. package/build/Screen/index.d.ts +9 -0
  182. package/build/Screen/index.d.ts.map +1 -0
  183. package/build/Screen/index.js +35 -0
  184. package/build/Screen/index.js.map +1 -0
  185. package/build/Screen/types.d.ts +6 -0
  186. package/build/Screen/types.d.ts.map +1 -0
  187. package/build/Screen/types.js +4 -0
  188. package/build/Screen/types.js.map +1 -0
  189. package/build/Siri/index.d.ts +7 -0
  190. package/build/Siri/index.d.ts.map +1 -0
  191. package/build/Siri/index.js +26 -0
  192. package/build/Siri/index.js.map +1 -0
  193. package/build/Siri/types.d.ts +14 -0
  194. package/build/Siri/types.d.ts.map +1 -0
  195. package/build/Siri/types.js +3 -0
  196. package/build/Siri/types.js.map +1 -0
  197. package/build/SocialLogin/apple.d.ts +12 -0
  198. package/build/SocialLogin/apple.d.ts.map +1 -0
  199. package/build/SocialLogin/apple.js +32 -0
  200. package/build/SocialLogin/apple.js.map +1 -0
  201. package/build/SocialLogin/facebook.d.ts +22 -0
  202. package/build/SocialLogin/facebook.d.ts.map +1 -0
  203. package/build/SocialLogin/facebook.js +61 -0
  204. package/build/SocialLogin/facebook.js.map +1 -0
  205. package/build/SocialLogin/google.d.ts +22 -0
  206. package/build/SocialLogin/google.d.ts.map +1 -0
  207. package/build/SocialLogin/google.js +61 -0
  208. package/build/SocialLogin/google.js.map +1 -0
  209. package/build/SocialLogin/index.d.ts +17 -0
  210. package/build/SocialLogin/index.d.ts.map +1 -0
  211. package/build/SocialLogin/index.js +23 -0
  212. package/build/SocialLogin/index.js.map +1 -0
  213. package/build/SocialLogin/types.d.ts +39 -0
  214. package/build/SocialLogin/types.d.ts.map +1 -0
  215. package/build/SocialLogin/types.js +3 -0
  216. package/build/SocialLogin/types.js.map +1 -0
  217. package/build/Stripe/index.d.ts +3 -0
  218. package/build/Stripe/index.d.ts.map +1 -0
  219. package/build/Stripe/index.js +49 -0
  220. package/build/Stripe/index.js.map +1 -0
  221. package/build/Stripe/types.d.ts +32 -0
  222. package/build/Stripe/types.d.ts.map +1 -0
  223. package/build/Stripe/types.js +3 -0
  224. package/build/Stripe/types.js.map +1 -0
  225. package/build/VoiceSearch/index.d.ts +13 -0
  226. package/build/VoiceSearch/index.d.ts.map +1 -0
  227. package/build/VoiceSearch/index.js +34 -0
  228. package/build/VoiceSearch/index.js.map +1 -0
  229. package/build/VoiceSearch/types.d.ts +10 -0
  230. package/build/VoiceSearch/types.d.ts.map +1 -0
  231. package/build/VoiceSearch/types.js +3 -0
  232. package/build/VoiceSearch/types.js.map +1 -0
  233. package/build/barcode/barcode-scan.d.ts +16 -0
  234. package/build/barcode/barcode-scan.d.ts.map +1 -0
  235. package/build/barcode/barcode-scan.js +40 -0
  236. package/build/barcode/barcode-scan.js.map +1 -0
  237. package/build/barcode/barcode-types.d.ts +18 -0
  238. package/build/barcode/barcode-types.d.ts.map +1 -0
  239. package/build/barcode/barcode-types.js +3 -0
  240. package/build/barcode/barcode-types.js.map +1 -0
  241. package/build/barcode/formats.d.ts +18 -0
  242. package/build/barcode/formats.d.ts.map +1 -0
  243. package/build/barcode/formats.js +23 -0
  244. package/build/barcode/formats.js.map +1 -0
  245. package/build/barcode/index.d.ts +5 -0
  246. package/build/barcode/index.d.ts.map +1 -0
  247. package/build/barcode/index.js +13 -0
  248. package/build/barcode/index.js.map +1 -0
  249. package/build/barcode/types.d.ts +17 -0
  250. package/build/barcode/types.d.ts.map +1 -0
  251. package/build/barcode/types.js +22 -0
  252. package/build/barcode/types.js.map +1 -0
  253. package/build/index.d.ts +15 -0
  254. package/build/index.d.ts.map +1 -0
  255. package/build/index.js +110 -0
  256. package/build/index.js.map +1 -0
  257. package/build/package.json +155 -0
  258. package/build/types/index.d.ts +49 -0
  259. package/build/types/index.d.ts.map +1 -0
  260. package/build/types/index.js +4 -0
  261. package/build/types/index.js.map +1 -0
  262. package/build/utills.d.ts +12 -0
  263. package/build/utills.d.ts.map +1 -0
  264. package/build/utills.js +111 -0
  265. package/build/utills.js.map +1 -0
  266. package/build/webtonative.min.js +1 -0
  267. package/buildScript.ts +35 -0
  268. package/client.ts +106 -0
  269. package/index.d.ts +65 -0
  270. package/package.json +36 -31
  271. package/src/ATTConsent/index.ts +51 -0
  272. package/src/ATTConsent/types.ts +17 -0
  273. package/src/AdMob/index.ts +113 -0
  274. package/src/AdMob/types.ts +37 -0
  275. package/src/AppReview/index.ts +19 -0
  276. package/src/AppReview/types.ts +12 -0
  277. package/src/AppsFlyer/index.ts +46 -0
  278. package/src/AppsFlyer/types.ts +10 -0
  279. package/src/BackgroundLocation/index.ts +78 -0
  280. package/src/BackgroundLocation/types.ts +34 -0
  281. package/src/Beacon/index.ts +28 -0
  282. package/src/Beacon/types.ts +22 -0
  283. package/src/Biometric/index.ts +126 -0
  284. package/src/Biometric/types.ts +27 -0
  285. package/src/Bluetooth/index.ts +71 -0
  286. package/src/Bluetooth/types.ts +40 -0
  287. package/src/BottomNavigation/index.ts +39 -0
  288. package/src/BottomNavigation/types.ts +9 -0
  289. package/src/Clipboard/index.ts +48 -0
  290. package/src/Clipboard/types.ts +30 -0
  291. package/src/Facebook/events.ts +45 -0
  292. package/src/Facebook/index.ts +3 -0
  293. package/src/Facebook/types.ts +24 -0
  294. package/src/Firebase/Analytics/index.ts +127 -0
  295. package/src/Firebase/Messaging/index.ts +73 -0
  296. package/src/Firebase/index.ts +4 -0
  297. package/src/Firebase/types.ts +74 -0
  298. package/src/FirebaseAnalytics/index.ts +3 -0
  299. package/src/Haptics/index.ts +17 -0
  300. package/src/Haptics/types.ts +8 -0
  301. package/src/InAppPurchase/index.ts +92 -0
  302. package/src/InAppPurchase/types.ts +35 -0
  303. package/src/InAppUpdate/index.ts +40 -0
  304. package/src/InAppUpdate/types.ts +17 -0
  305. package/src/MediaPlayer/index.ts +56 -0
  306. package/src/MediaPlayer/types.ts +15 -0
  307. package/src/NativeContacts/index.ts +50 -0
  308. package/src/NativeContacts/types.ts +16 -0
  309. package/src/Notification/index.ts +41 -0
  310. package/src/Notification/types.ts +16 -0
  311. package/src/OneSignal/index.ts +54 -0
  312. package/src/OneSignal/types.ts +15 -0
  313. package/src/Printing/index.ts +17 -0
  314. package/src/Printing/types.ts +9 -0
  315. package/src/Screen/index.ts +34 -0
  316. package/src/Screen/types.ts +8 -0
  317. package/src/Siri/index.ts +23 -0
  318. package/src/Siri/types.ts +14 -0
  319. package/src/SocialLogin/apple.ts +31 -0
  320. package/src/SocialLogin/facebook.ts +64 -0
  321. package/src/SocialLogin/google.ts +64 -0
  322. package/src/SocialLogin/index.ts +20 -0
  323. package/src/SocialLogin/types.ts +52 -0
  324. package/src/Stripe/index.ts +54 -0
  325. package/src/Stripe/types.ts +37 -0
  326. package/src/VoiceSearch/index.ts +37 -0
  327. package/src/VoiceSearch/types.ts +12 -0
  328. package/src/barcode/barcode-scan.ts +59 -0
  329. package/src/barcode/barcode-types.ts +22 -0
  330. package/src/barcode/formats.ts +19 -0
  331. package/src/barcode/index.ts +5 -0
  332. package/src/barcode/types.ts +18 -0
  333. package/src/index.ts +105 -0
  334. package/src/types/index.ts +71 -0
  335. package/src/utills.ts +110 -0
  336. package/tsconfig.json +27 -0
  337. package/webpack.config.js +57 -0
  338. package/ATTConsent/index.js +0 -1
  339. package/AdMob/index.js +0 -1
  340. package/AppReview/index.js +0 -1
  341. package/AppsFlyer/index.js +0 -4
  342. package/BackgroundLocation/index.js +0 -4
  343. package/Beacon/index.js +0 -1
  344. package/Biometric/index.js +0 -1
  345. package/Bluetooth/index.js +0 -1
  346. package/BottomNavigation/index.js +0 -4
  347. package/Clipboard/index.js +0 -4
  348. package/Facebook/events.js +0 -4
  349. package/Facebook/index.js +0 -1
  350. package/Firebase/Analytics/index.js +0 -4
  351. package/Firebase/Messaging/index.js +0 -4
  352. package/Firebase/index.js +0 -1
  353. package/FirebaseAnalytics/index.js +0 -1
  354. package/Haptics/index.js +0 -1
  355. package/InAppPurchase/index.js +0 -1
  356. package/InAppUpdate/index.js +0 -1
  357. package/MediaPlayer/index.js +0 -7
  358. package/NativeContacts/index.js +0 -6
  359. package/Notification/index.js +0 -5
  360. package/OneSignal/index.js +0 -1
  361. package/Printing/index.js +0 -1
  362. package/Screen/index.js +0 -4
  363. package/Siri/index.js +0 -1
  364. package/SocialLogin/apple.js +0 -1
  365. package/SocialLogin/facebook.js +0 -9
  366. package/SocialLogin/google.js +0 -9
  367. package/SocialLogin/index.js +0 -1
  368. package/Stripe/index.js +0 -1
  369. package/VoiceSearch/index.js +0 -1
  370. package/barcode/barcode-scan.js +0 -1
  371. package/barcode/formats.js +0 -1
  372. package/barcode/index.js +0 -1
  373. package/barcode/types.js +0 -1
  374. package/index.js +0 -4
  375. package/utills.js +0 -1
  376. package/webtonative.min.js +0 -1
@@ -0,0 +1,64 @@
1
+ import { platform, registerCb, webToNative, webToNativeIos } from "../utills";
2
+ import { SocialLoginOptions, GoogleLoginResponse, GoogleLogoutResponse, GoogleIosMessage } from "./types";
3
+
4
+ /**
5
+ * This function handles native Google login
6
+ * @param options - Options for Google login
7
+ * @example wtn.socialLogin.google.login({
8
+ * callback:(data)=>{
9
+ * console.log(data);
10
+ * }
11
+ * });
12
+ */
13
+ export const login = (options: SocialLoginOptions): void => {
14
+ if (["ANDROID_APP", "IOS_APP"].includes(platform)) {
15
+ const { callback, scope } = options;
16
+
17
+ registerCb((response: GoogleLoginResponse) => {
18
+ const { type } = response;
19
+ if (type === "googleLoginToken") {
20
+ callback && callback(response);
21
+ }
22
+ });
23
+
24
+ platform === "ANDROID_APP" && webToNative.signInWithGoogle();
25
+
26
+ if (platform === "IOS_APP" && webToNativeIos) {
27
+ webToNativeIos.postMessage({
28
+ action: "googleSignIn",
29
+ scope,
30
+ } as GoogleIosMessage);
31
+ }
32
+ }
33
+ };
34
+
35
+ /**
36
+ * This function handles native Google logout
37
+ * @param options - Options for Google logout
38
+ * @example wtn.socialLogin.google.logout({
39
+ * callback:(data)=>{
40
+ * console.log(data);
41
+ * }
42
+ * });
43
+ */
44
+ export const logout = (options: SocialLoginOptions): void => {
45
+ if (["ANDROID_APP", "IOS_APP"].includes(platform)) {
46
+ const { callback, scope } = options;
47
+
48
+ registerCb((response: GoogleLogoutResponse) => {
49
+ const { type } = response;
50
+ if (type === "googleLogOut") {
51
+ callback && callback(response);
52
+ }
53
+ });
54
+
55
+ platform === "ANDROID_APP" && webToNative.signOutWithGoogle();
56
+
57
+ if (platform === "IOS_APP" && webToNativeIos) {
58
+ webToNativeIos.postMessage({
59
+ action: "googleSignOut",
60
+ scope,
61
+ } as GoogleIosMessage);
62
+ }
63
+ }
64
+ };
@@ -0,0 +1,20 @@
1
+ import { login as loginFacebook, logout as logoutFacebook } from "./facebook";
2
+ import { login as loginApple } from "./apple";
3
+ import { login as loginGoogle, logout as logoutGoogle } from "./google";
4
+
5
+ /**
6
+ * Social login module for Facebook, Google, and Apple authentication
7
+ */
8
+ export const socialLogin = {
9
+ facebook: {
10
+ login: loginFacebook,
11
+ logout: logoutFacebook,
12
+ },
13
+ google: {
14
+ login: loginGoogle,
15
+ logout: logoutGoogle,
16
+ },
17
+ apple: {
18
+ login: loginApple,
19
+ },
20
+ };
@@ -0,0 +1,52 @@
1
+ // Common types for social login
2
+ export interface SocialLoginResponse {
3
+ type: string;
4
+ [key: string]: any;
5
+ }
6
+
7
+ export interface SocialLoginCallback {
8
+ (response: SocialLoginResponse): void;
9
+ }
10
+
11
+ export interface SocialLoginOptions {
12
+ callback?: SocialLoginCallback;
13
+ scope?: string;
14
+ }
15
+
16
+ // Facebook types
17
+ export interface FacebookLoginResponse extends SocialLoginResponse {
18
+ type: 'fbLoginToken';
19
+ }
20
+
21
+ export interface FacebookLogoutResponse extends SocialLoginResponse {
22
+ type: 'fbLogOut';
23
+ }
24
+
25
+ export interface FacebookIosMessage {
26
+ action: 'fbSignIn' | 'fbSignOut';
27
+ scope?: string;
28
+ }
29
+
30
+ // Google types
31
+ export interface GoogleLoginResponse extends SocialLoginResponse {
32
+ type: 'googleLoginToken';
33
+ }
34
+
35
+ export interface GoogleLogoutResponse extends SocialLoginResponse {
36
+ type: 'googleLogOut';
37
+ }
38
+
39
+ export interface GoogleIosMessage {
40
+ action: 'googleSignIn' | 'googleSignOut';
41
+ scope?: string;
42
+ }
43
+
44
+ // Apple types
45
+ export interface AppleLoginResponse extends SocialLoginResponse {
46
+ type: 'appleLoginToken';
47
+ }
48
+
49
+ export interface AppleIosMessage {
50
+ action: 'appleSignIn';
51
+ scope?: string;
52
+ }
@@ -0,0 +1,54 @@
1
+ import { platform, webToNative, webToNativeIos, registerCb } from "../utills";
2
+ import { StripeOptions, StripePaymentData, StripeIosMessage } from "./types";
3
+
4
+ export const makeTapToPay = (options: StripeOptions): void => {
5
+ if (["ANDROID_APP", "IOS_APP"].includes(platform)) {
6
+ const {
7
+ callback,
8
+ apiUrl = null,
9
+ amount,
10
+ currency,
11
+ isSimulated = false,
12
+ captureMethod = "automatic",
13
+ connectionToken,
14
+ stripeLocationId,
15
+ clientSecret = null
16
+ } = options;
17
+
18
+ registerCb((response) => {
19
+ const { type } = response;
20
+ if (type === "makeTapToPayStripePayment") {
21
+ callback && callback(response);
22
+ }
23
+ });
24
+
25
+ let paymentData: StripePaymentData = {
26
+ secretToken: connectionToken,
27
+ amount,
28
+ currency,
29
+ isSimulated,
30
+ captureMethod,
31
+ locationId: stripeLocationId
32
+ };
33
+
34
+ if (apiUrl) {
35
+ paymentData.apiUrl = apiUrl;
36
+ }
37
+
38
+ if (clientSecret) {
39
+ paymentData.client_secret = clientSecret;
40
+ }
41
+
42
+ if (platform === "ANDROID_APP") {
43
+ webToNative.makeTapToPayStripePayment(JSON.stringify(paymentData));
44
+ }
45
+
46
+ if (platform === "IOS_APP" && webToNativeIos) {
47
+ const iosMessage: StripeIosMessage = {
48
+ "action": "makeTapToPayStripePayment",
49
+ ...paymentData
50
+ };
51
+ webToNativeIos.postMessage(iosMessage);
52
+ }
53
+ }
54
+ };
@@ -0,0 +1,37 @@
1
+ import { BaseCallback, BaseResponse } from "../types";
2
+
3
+ export interface StripeResponse extends BaseResponse {
4
+ type: "makeTapToPayStripePayment";
5
+ // Additional response properties can be added here based on actual response structure
6
+ }
7
+
8
+ export interface StripeCallback extends BaseCallback {
9
+ (response: StripeResponse): void;
10
+ }
11
+
12
+ export interface StripePaymentData {
13
+ secretToken: string;
14
+ amount: number;
15
+ currency: string;
16
+ isSimulated: boolean;
17
+ captureMethod: string;
18
+ locationId: string;
19
+ apiUrl?: string;
20
+ client_secret?: string;
21
+ }
22
+
23
+ export interface StripeOptions {
24
+ callback?: StripeCallback;
25
+ apiUrl?: string;
26
+ amount: number;
27
+ currency: string;
28
+ isSimulated?: boolean;
29
+ captureMethod?: string;
30
+ connectionToken: string;
31
+ stripeLocationId: string;
32
+ clientSecret?: string;
33
+ }
34
+
35
+ export interface StripeIosMessage extends StripePaymentData {
36
+ action: string;
37
+ }
@@ -0,0 +1,37 @@
1
+ import { webToNative, isNativeApp, registerCb } from "../utills";
2
+ import { VoiceSearchOptions, VoiceSearchCallback, VoiceSearchResponse } from "./types";
3
+
4
+ let voiceSearchCb: VoiceSearchCallback | null = null;
5
+
6
+ /**
7
+ * This function opens native voice search
8
+ * @param options Configuration options for voice search
9
+ * @example wtn.openVoiceSearch({
10
+ * onVoiceSearch:(value)=>{
11
+ * console.log(value);
12
+ * }
13
+ * });
14
+ */
15
+ const openVoiceSearch = (options: VoiceSearchOptions = {}): any => {
16
+ const { onVoiceSearch } = options;
17
+
18
+ registerCb((response) => {
19
+ const { type, results } = response as VoiceSearchResponse;
20
+ if (type === "VOICE_SEARCH_RESULT") {
21
+ voiceSearchCb && voiceSearchCb(results);
22
+ voiceSearchCb = null;
23
+ }
24
+ });
25
+
26
+ if (isNativeApp) {
27
+ webToNative.openVoiceSearch();
28
+ }
29
+
30
+ if (typeof onVoiceSearch === "function") {
31
+ voiceSearchCb = onVoiceSearch;
32
+ }
33
+
34
+ return this;
35
+ };
36
+
37
+ export default openVoiceSearch;
@@ -0,0 +1,12 @@
1
+ import { BaseResponse } from "../types";
2
+
3
+ export interface VoiceSearchResponse extends BaseResponse {
4
+ type: "VOICE_SEARCH_RESULT";
5
+ results: string;
6
+ }
7
+
8
+ export type VoiceSearchCallback = (results: string) => void;
9
+
10
+ export interface VoiceSearchOptions {
11
+ onVoiceSearch?: VoiceSearchCallback;
12
+ }
@@ -0,0 +1,59 @@
1
+ import {
2
+ isNativeApp,
3
+ platform,
4
+ webToNative,
5
+ registerCb,
6
+ webToNativeIos,
7
+ } from "../utills";
8
+ import Format from "./formats";
9
+
10
+ // Define interfaces for barcode scanner
11
+ interface BarcodeScanOptions {
12
+ onBarcodeSearch?: (value: string) => void;
13
+ format?: number;
14
+ }
15
+
16
+ interface BarcodeScanResponse {
17
+ type: string;
18
+ value: string;
19
+ [key: string]: any;
20
+ }
21
+
22
+ /**
23
+ * This function opens native barcode scanner from Android/Ios app.
24
+ * @param {object} options
25
+ * @example wtn.onScanner({
26
+ * onBarcodeSearch:(value)=>{
27
+ * console.log(value);
28
+ * }
29
+ * });
30
+ */
31
+ const BarcodeScan = (options: BarcodeScanOptions): void => {
32
+ if (["ANDROID_APP", "IOS_APP"].includes(platform)) {
33
+ const { onBarcodeSearch, format } = options;
34
+
35
+ registerCb((response: BarcodeScanResponse) => {
36
+ const { type, value } = response;
37
+ if (type === "BARCODE_SCAN") {
38
+ onBarcodeSearch && onBarcodeSearch(value);
39
+ }
40
+ });
41
+
42
+ if (platform === "ANDROID_APP" && webToNative.startScanner) {
43
+ webToNative.startScanner(
44
+ JSON.stringify({
45
+ formats: format ? [format] : [],
46
+ })
47
+ );
48
+ }
49
+
50
+ if (platform === "IOS_APP" && webToNativeIos) {
51
+ webToNativeIos.postMessage({
52
+ action: "barcodeScan",
53
+ barcodeFormat: format ? String(format) : String(Format.ALL_FORMATS),
54
+ });
55
+ }
56
+ }
57
+ };
58
+
59
+ export default BarcodeScan;
@@ -0,0 +1,22 @@
1
+ import { BaseResponse } from "../types";
2
+
3
+ export interface BarcodeScanResponse extends BaseResponse {
4
+ type: "BARCODE_SCAN";
5
+ value: string;
6
+ }
7
+
8
+ export type BarcodeScanCallback = (value: string) => void;
9
+
10
+ export interface BarcodeScanOptions {
11
+ onBarcodeSearch?: BarcodeScanCallback;
12
+ format?: number;
13
+ }
14
+
15
+ export interface BarcodeScanAndroidParams {
16
+ formats: number[];
17
+ }
18
+
19
+ export interface BarcodeScanIosMessage {
20
+ action: string;
21
+ barcodeFormat: string;
22
+ }
@@ -0,0 +1,19 @@
1
+ // Barcode formats
2
+ export enum BarcodeFormat {
3
+ ALL_FORMATS = 0,
4
+ CODE_128 = 1,
5
+ CODE_39 = 2,
6
+ CODE_93 = 4,
7
+ CODABAR = 8,
8
+ DATA_MATRIX = 16,
9
+ EAN_13 = 32,
10
+ EAN_8 = 64,
11
+ ITF = 128,
12
+ QR_CODE = 256,
13
+ UPC_A = 512,
14
+ UPC_E = 1024,
15
+ PDF417 = 2048,
16
+ AZTEC = 4096
17
+ }
18
+
19
+ export default BarcodeFormat;
@@ -0,0 +1,5 @@
1
+ import Format from "./formats";
2
+ import Types from "./types";
3
+ import BarcodeScan from "./barcode-scan";
4
+
5
+ export { Format, Types, BarcodeScan };
@@ -0,0 +1,18 @@
1
+ // Barcode types
2
+ export enum BarcodeType {
3
+ QR_CODE = 'QR_CODE',
4
+ DATA_MATRIX = 'DATA_MATRIX',
5
+ UPC_E = 'UPC_E',
6
+ UPC_A = 'UPC_A',
7
+ EAN_8 = 'EAN_8',
8
+ EAN_13 = 'EAN_13',
9
+ CODE_128 = 'CODE_128',
10
+ CODE_39 = 'CODE_39',
11
+ CODE_93 = 'CODE_93',
12
+ CODABAR = 'CODABAR',
13
+ ITF = 'ITF',
14
+ AZTEC = 'AZTEC',
15
+ PDF_417 = 'PDF_417'
16
+ }
17
+
18
+ export default BarcodeType;
package/src/index.ts ADDED
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Repository for webtonative javascript sdk. Build your android/ios app from https://webtonative.com.
3
+ * This is in beta phase.
4
+ * @example npm install webtonative
5
+ * import webtonative from "webtonative";
6
+ * const wtn = webtonative();
7
+ */
8
+ import { isNativeApp, webToNative, platform, webToNativeIos, registerCb } from "./utills";
9
+ import { StatusBarOptions, DownloadBlobFileOptions, CustomFileDownloadOptions } from "./types";
10
+
11
+ export const isAndroidApp: boolean = platform === "ANDROID_APP";
12
+ export const isIosApp: boolean = platform === "IOS_APP";
13
+
14
+ /**
15
+ * This function hides splash screen
16
+ * @example wtn.hideSplashScreen()
17
+ */
18
+ export const hideSplashScreen = (): void => {
19
+ isNativeApp && webToNative.hideSplashScreen && webToNative.hideSplashScreen();
20
+ };
21
+
22
+ export const statusBar = (options: StatusBarOptions): void => {
23
+ if (isNativeApp) {
24
+ if (isAndroidApp) {
25
+ webToNative.statusBar && webToNative.statusBar(JSON.stringify(options));
26
+ } else if (isIosApp) {
27
+ webToNativeIos && webToNativeIos.postMessage({
28
+ action: "statusBar",
29
+ color: options.color,
30
+ style: options.style,
31
+ });
32
+ }
33
+ }
34
+ };
35
+
36
+ export const downloadFile = (downloadUrl: string): void => {
37
+ if (isNativeApp) {
38
+ if (isAndroidApp) {
39
+ // Android implementation
40
+ } else if (isIosApp) {
41
+ webToNativeIos && webToNativeIos.postMessage({
42
+ action: "downloadFile",
43
+ downloadUrl,
44
+ });
45
+ }
46
+ }
47
+ };
48
+
49
+ export const downloadBlobFile = ({fileName, downloadUrl}: DownloadBlobFileOptions): void => {
50
+ if (["IOS_APP"].includes(platform)) {
51
+ isIosApp && webToNativeIos && webToNativeIos.postMessage({
52
+ action: "downloadBlobFile",
53
+ fileName,
54
+ url: downloadUrl,
55
+ });
56
+ }
57
+ };
58
+
59
+ export const customFileDownload = ({downloadUrl, fileName, isBlob, mimeType, cookies, userAgent, openFileAfterDownload}: CustomFileDownloadOptions): void => {
60
+ if (["ANDROID_APP"].includes(platform)) {
61
+ platform === "ANDROID_APP" && webToNative.downloadFile && webToNative.downloadFile(JSON.stringify({
62
+ url: downloadUrl,
63
+ fileName,
64
+ isBlob,
65
+ mimeType,
66
+ cookies,
67
+ userAgent,
68
+ openFileAfterDownload
69
+ }))
70
+ }
71
+ }
72
+
73
+ export const deviceInfo = (): Promise<any> => {
74
+ return new Promise((resolve, reject) => {
75
+ registerCb(
76
+ (results) => {
77
+ if (results) {
78
+ resolve(results);
79
+ } else {
80
+ reject({
81
+ err: "Error getting device info",
82
+ });
83
+ }
84
+ },
85
+ {
86
+ key: "deviceInfo",
87
+ }
88
+ );
89
+ if (platform === "ANDROID_APP") {
90
+ webToNative.getDeviceInfo && webToNative.getDeviceInfo();
91
+ } else if (platform === "IOS_APP") {
92
+ webToNativeIos && webToNativeIos.postMessage({
93
+ action: "deviceInfo",
94
+ });
95
+ } else {
96
+ reject("This function will work in Native App Powered By WebToNative");
97
+ }
98
+ });
99
+ };
100
+
101
+ export const showInAppReview = (): void => {
102
+ isNativeApp && webToNative.showInAppReview && webToNative.showInAppReview();
103
+ };
104
+
105
+ // Export all other functions from the original file
@@ -0,0 +1,71 @@
1
+ // Define common types used throughout the package
2
+
3
+ // Platform types
4
+ export type Platform = 'ANDROID_APP' | 'IOS_APP' | 'WEBSITE';
5
+
6
+ // Base response interface for all native responses
7
+ export interface BaseResponse {
8
+ type: string;
9
+ [key: string]: any;
10
+ }
11
+
12
+ // Base callback interface for all native callbacks
13
+ export interface BaseCallback {
14
+ (response: BaseResponse): void;
15
+ }
16
+
17
+ // Callback function types
18
+ export type CallbackFunction = (response: any) => void;
19
+
20
+ // Register callback options
21
+ export interface RegisterCallbackOptions {
22
+ key?: string;
23
+ ignoreDelete?: boolean;
24
+ }
25
+
26
+ // Status bar options
27
+ export interface StatusBarOptions {
28
+ color?: string;
29
+ style?: 'light' | 'dark';
30
+ }
31
+
32
+ // Download file options
33
+ export interface DownloadBlobFileOptions {
34
+ fileName: string;
35
+ downloadUrl: string;
36
+ }
37
+
38
+ // Custom file download options
39
+ export interface CustomFileDownloadOptions {
40
+ downloadUrl: string;
41
+ fileName: string;
42
+ isBlob?: boolean;
43
+ mimeType?: string;
44
+ cookies?: string;
45
+ userAgent?: string;
46
+ openFileAfterDownload?: boolean;
47
+ }
48
+
49
+ // Device info response
50
+ export interface DeviceInfoResponse {
51
+ [key: string]: any;
52
+ }
53
+
54
+ // Native interface
55
+ export interface WebToNativeInterface {
56
+ getAndroidVersion?: () => string;
57
+ hideSplashScreen?: () => void;
58
+ statusBar?: (options: string) => void;
59
+ downloadFile?: (options: string) => void;
60
+ getDeviceInfo?: () => void;
61
+ showInAppReview?: () => void;
62
+ startScanner?: (options: string) => void;
63
+ androidCBHook?: (results: string) => void;
64
+ androidAdMobCBHook?: (results: string) => void;
65
+ [key: string]: any;
66
+ }
67
+
68
+ // iOS interface
69
+ export interface WebToNativeIosInterface {
70
+ postMessage: (message: any) => void;
71
+ }
package/src/utills.ts ADDED
@@ -0,0 +1,110 @@
1
+ import { Platform, WebToNativeInterface, WebToNativeIosInterface, CallbackFunction, RegisterCallbackOptions } from './types';
2
+
3
+ const isClient: boolean = typeof window !== "undefined";
4
+ const webToNative: WebToNativeInterface = (isClient && (window as any).WebToNativeInterface) || {};
5
+ const webToNativeIos: WebToNativeIosInterface | false =
6
+ isClient &&
7
+ (window as any).webkit &&
8
+ (window as any).webkit.messageHandlers &&
9
+ (window as any).webkit.messageHandlers.webToNativeInterface;
10
+ const platform: Platform = webToNative.getAndroidVersion
11
+ ? "ANDROID_APP"
12
+ : webToNativeIos
13
+ ? "IOS_APP"
14
+ : "WEBSITE";
15
+ const isNativeApp: boolean = isClient && platform !== "WEBSITE";
16
+ const cbObj: Record<string | number, { cb: CallbackFunction; ignoreDelete?: boolean }> = {};
17
+ let counter: number = 1;
18
+ let abMobCb: CallbackFunction | null = null;
19
+ if (isNativeApp) {
20
+ webToNative.androidCBHook = (results: string) => {
21
+ var response: any = results;
22
+ try {
23
+ response = JSON.parse(results);
24
+ } catch (e) {
25
+ console.log(e);
26
+ }
27
+ const { type } = response;
28
+ for (var key in cbObj) {
29
+ const { cb, ignoreDelete = false } = cbObj[key];
30
+ if (response && response.reqType) {
31
+ if (key == response["reqType"]) {
32
+ cb(response);
33
+ if (!ignoreDelete) {
34
+ delete cbObj[key];
35
+ }
36
+ }
37
+ } else {
38
+ cb(response);
39
+ if (!ignoreDelete) {
40
+ delete cbObj[key];
41
+ }
42
+ }
43
+ }
44
+ };
45
+ (window as any).iOSAdMobCBHook = webToNative.androidAdMobCBHook = (results: string) => {
46
+ const responseObj = JSON.parse(results);
47
+ abMobCb && abMobCb(responseObj);
48
+ };
49
+ (window as any).iosCBHook = (results: string) => {
50
+ var response: any = results;
51
+ try {
52
+ response = JSON.parse(results);
53
+ } catch (e) {
54
+ console.log(e);
55
+ }
56
+ for (var key in cbObj) {
57
+ const { cb, ignoreDelete = false } = cbObj[key];
58
+ if (response && response.reqType) {
59
+ if (key == response["reqType"]) {
60
+ cb(response);
61
+ if (!ignoreDelete) {
62
+ delete cbObj[key];
63
+ }
64
+ }
65
+ } else {
66
+ cb(response);
67
+ if (!ignoreDelete) {
68
+ delete cbObj[key];
69
+ }
70
+ }
71
+ }
72
+ };
73
+ }
74
+
75
+ const registerCb = (cb: CallbackFunction, obj?: RegisterCallbackOptions) => {
76
+ if (typeof cb === "function") {
77
+ if (obj && obj.key) {
78
+ cbObj[obj["key"]] = { cb, ignoreDelete: obj.ignoreDelete ? true : false };
79
+ } else {
80
+ cbObj[counter] = { cb, ignoreDelete: obj && obj.ignoreDelete ? true : false };
81
+ counter += 1;
82
+ }
83
+ }
84
+ };
85
+ const registerForAbMobCb = (cb: CallbackFunction) => {
86
+ if (typeof cb === "function") {
87
+ abMobCb = cb;
88
+ }
89
+ };
90
+ const deRegisterForAbMobCb = () => {
91
+ if (abMobCb) {
92
+ abMobCb = null;
93
+ }
94
+ };
95
+
96
+ const deRegisterCbByKey = (key: string | number) => {
97
+ delete cbObj[key];
98
+ };
99
+
100
+ export {
101
+ webToNative,
102
+ isClient,
103
+ webToNativeIos,
104
+ platform,
105
+ isNativeApp,
106
+ registerCb,
107
+ registerForAbMobCb,
108
+ deRegisterForAbMobCb,
109
+ deRegisterCbByKey,
110
+ };