natively 2.14.0 → 2.15.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.
Files changed (65) hide show
  1. package/README.md +62 -4
  2. package/dist/classes/Natively.d.ts +22 -0
  3. package/dist/classes/Natively.js +139 -0
  4. package/dist/classes/NativelyAdmobBanner.d.ts +16 -0
  5. package/dist/classes/NativelyAdmobBanner.js +53 -0
  6. package/dist/classes/NativelyAdmobInterstitial.d.ts +17 -0
  7. package/dist/classes/NativelyAdmobInterstitial.js +54 -0
  8. package/dist/classes/NativelyAppleSignInService.d.ts +4 -0
  9. package/dist/classes/NativelyAppleSignInService.js +13 -0
  10. package/dist/classes/NativelyAudioRecorder.d.ts +4 -0
  11. package/dist/classes/NativelyAudioRecorder.js +16 -0
  12. package/dist/classes/NativelyBiometrics.d.ts +11 -0
  13. package/dist/classes/NativelyBiometrics.js +40 -0
  14. package/dist/classes/NativelyCamera.d.ts +4 -0
  15. package/dist/classes/NativelyCamera.js +18 -0
  16. package/dist/classes/NativelyClipboard.d.ts +5 -0
  17. package/dist/classes/NativelyClipboard.js +18 -0
  18. package/dist/classes/NativelyContacts.d.ts +5 -0
  19. package/dist/classes/NativelyContacts.js +22 -0
  20. package/dist/classes/NativelyDatePicker.d.ts +4 -0
  21. package/dist/classes/NativelyDatePicker.js +19 -0
  22. package/dist/classes/NativelyFirebaseNotifications.d.ts +9 -0
  23. package/dist/classes/NativelyFirebaseNotifications.js +32 -0
  24. package/dist/classes/NativelyGeolocation.d.ts +6 -0
  25. package/dist/classes/NativelyGeolocation.js +23 -0
  26. package/dist/classes/NativelyHealth.d.ts +8 -0
  27. package/dist/classes/NativelyHealth.js +40 -0
  28. package/dist/classes/NativelyInfo.d.ts +11 -0
  29. package/dist/classes/NativelyInfo.js +33 -0
  30. package/dist/classes/NativelyLocation.d.ts +10 -0
  31. package/dist/classes/NativelyLocation.js +47 -0
  32. package/dist/classes/NativelyMediaPicker.d.ts +4 -0
  33. package/dist/classes/NativelyMediaPicker.js +13 -0
  34. package/dist/classes/NativelyMessage.d.ts +5 -0
  35. package/dist/classes/NativelyMessage.js +25 -0
  36. package/dist/classes/NativelyNFCService.d.ts +11 -0
  37. package/dist/classes/NativelyNFCService.js +39 -0
  38. package/dist/classes/NativelyNotifications.d.ts +6 -0
  39. package/dist/classes/NativelyNotifications.js +21 -0
  40. package/dist/classes/NativelyPurchases.d.ts +9 -0
  41. package/dist/classes/NativelyPurchases.js +36 -0
  42. package/dist/classes/NativelyScanner.d.ts +4 -0
  43. package/dist/classes/NativelyScanner.js +13 -0
  44. package/dist/classes/NativelyStorage.d.ts +7 -0
  45. package/dist/classes/NativelyStorage.js +29 -0
  46. package/dist/events.d.ts +1 -0
  47. package/dist/events.js +7 -0
  48. package/dist/hooks/useNatively.d.ts +2 -0
  49. package/dist/hooks/useNatively.js +2 -0
  50. package/dist/index.d.ts +27 -0
  51. package/dist/index.js +34 -0
  52. package/dist/inject.d.ts +1 -0
  53. package/dist/inject.js +7 -0
  54. package/dist/types.d.ts +12 -0
  55. package/dist/types.js +1 -0
  56. package/dist/utils/generateID.d.ts +1 -0
  57. package/dist/utils/generateID.js +1 -0
  58. package/dist/utils/globalThis.d.ts +2 -0
  59. package/dist/utils/globalThis.js +25 -0
  60. package/natively-frontend.min.js +1 -1
  61. package/package.json +36 -7
  62. package/.vscode/settings.json +0 -13
  63. package/natively-frontend.js +0 -977
  64. package/natively-frontend.min.mjs +0 -1
  65. package/natively-frontend.mjs +0 -979
@@ -1,979 +0,0 @@
1
- window.natively = {
2
- isDebug: false,
3
- min_app_version: 0,
4
- app_version: 0,
5
- injected: false,
6
- observers: [],
7
- isIOSApp: window.navigator.userAgent.includes("Natively/iOS"),
8
- isAndroidApp: window.navigator.userAgent.includes("Natively/Android"),
9
-
10
- setDebug: function (isDebug) {
11
- window.natively.isDebug = isDebug;
12
- },
13
-
14
- notify: function (min, current) {
15
- window.natively.injected = true;
16
- // Remove legacy min/current support later
17
- if (min) {
18
- window.natively.min_app_version = min;
19
- }
20
- if (current) {
21
- window.natively.app_version = current;
22
- }
23
- const observers = window.natively.observers;
24
- if (natively.isDebug) {
25
- console.log("[INFO] Notify observers: ", observers.length);
26
- }
27
- while (observers.length > 0) {
28
- const observer = observers.shift();
29
- observer();
30
- }
31
- },
32
-
33
- addObserver: function (fn) {
34
- if (window.natively.injected) {
35
- fn();
36
- } else {
37
- if (window.natively.isDebug) {
38
- console.log(`[DEBUG] addObserver: ${fn}`);
39
- }
40
- window.natively.observers.push(fn);
41
- }
42
- },
43
-
44
- trigger: function (respId, minVersion, callback, method, body) {
45
- const isTestVersion = window.natively.isDebug;
46
- if (!window.natively.injected) {
47
- window.natively.addObserver(() => {
48
- window.natively.trigger(respId, minVersion, callback, method, body);
49
- });
50
- return;
51
- }
52
- if (minVersion > window.natively.app_version) {
53
- if (isTestVersion) {
54
- alert(
55
- `[ERROR] Please rebuild the app to use this functionality. App Version: ${window.natively.app_version}, feature version: ${minVersion}`
56
- );
57
- }
58
- return;
59
- }
60
- if (callback) {
61
- let fullMethodName;
62
- if (respId) {
63
- fullMethodName = method + "_response" + "_" + respId;
64
- } else {
65
- fullMethodName = method + "_response";
66
- }
67
- window[fullMethodName] = function (resp, err) {
68
- $agent.response();
69
- if (err.message && isTestVersion) {
70
- alert(`[ERROR] Error message: ${err.message}`);
71
- return;
72
- }
73
- if (isTestVersion) {
74
- console.log(
75
- `[DEBUG] Callback method: ${fullMethodName}, body: ${JSON.stringify(
76
- resp
77
- )}, respId: ${respId}`
78
- );
79
- }
80
- callback(resp);
81
- };
82
- if (body) {
83
- body.response_id = respId;
84
- } else {
85
- body = { response_id: respId };
86
- }
87
- }
88
- if (isTestVersion) {
89
- console.log(
90
- `[DEBUG] Trigger method: ${method}, body: ${JSON.stringify(body)}`
91
- );
92
- }
93
- $agent.trigger(method, body);
94
- },
95
-
96
- openLogger: function () { // DEPRECATED after 2.14.0
97
- $agent.natively_logger();
98
- },
99
-
100
- openConsole: function () {
101
- window.natively.trigger(undefined, 22, undefined, "app_console");
102
- },
103
-
104
- closeApp: function () {
105
- window.natively.trigger(undefined, 11, undefined, "app_close");
106
- },
107
-
108
- showProgress: function (toggle) {
109
- window.natively.trigger(undefined, 11, undefined, "app_show_progress", { toggle });
110
- },
111
-
112
- shareImage(image_url) {
113
- window.natively.trigger(undefined, 0, undefined, "share_image", {
114
- url: image_url,
115
- });
116
- },
117
-
118
- shareText(text) {
119
- window.natively.trigger(undefined, 0, undefined, "share_text", {
120
- text,
121
- });
122
- },
123
-
124
- shareTextAndImage(text, image_url) {
125
- window.natively.trigger(undefined, 0, undefined, "share_text_and_image", {
126
- url: image_url,
127
- text,
128
- });
129
- },
130
-
131
- shareFile(file_url) {
132
- window.natively.trigger(undefined, 2, undefined, "share_file", {
133
- url: file_url,
134
- });
135
- },
136
-
137
- openExternalURL(url, external) {
138
- const params = {};
139
- params.url = typeof url === "undefined" ? "https://buildnatively.com" : url;
140
- const isExternal = typeof external === "undefined" ? false : external;
141
- params.view = isExternal ? "external" : "web";
142
- window.natively.trigger(undefined, 18, undefined, "open_link", params);
143
- },
144
-
145
- openExternalAppIOS(url) { // DEPRECATED after 2.14.0
146
- window.natively.trigger(undefined, 0, undefined, "open_app", {
147
- url,
148
- });
149
- },
150
-
151
- openExternalApp(url) {
152
- window.natively.trigger(undefined, 22, undefined, "open_app", {
153
- url,
154
- });
155
- },
156
-
157
- openAppSettings() {
158
- window.natively.trigger(undefined, 0, undefined, "open_appsettings");
159
- },
160
-
161
- hapticPatternIOS(pattern, delay) { // DEPRECATED after 2.14.0
162
- window.natively.trigger(undefined, 7, undefined, "haptic_pattern", {
163
- pattern,
164
- delay
165
- });
166
- },
167
-
168
- hapticImpactIOS(type) { // DEPRECATED after 2.14.0
169
- window.natively.trigger(undefined, 7, undefined, "haptic_impact", {
170
- type,
171
- });
172
- },
173
-
174
- hapticNotificationIOS(type) { // DEPRECATED after 2.14.0
175
- window.natively.trigger(undefined, 7, undefined, "haptic_notification", {
176
- type,
177
- });
178
- },
179
-
180
- hapticPattern(pattern, delay) {
181
- window.natively.trigger(undefined, 22, undefined, "haptic_pattern", {
182
- pattern,
183
- delay
184
- });
185
- },
186
-
187
- hapticImpact(type) {
188
- window.natively.trigger(undefined, 22, undefined, "haptic_impact", {
189
- type,
190
- });
191
- },
192
-
193
- hapticNotification(type) {
194
- window.natively.trigger(undefined, 22, undefined, "haptic_notification", {
195
- type,
196
- });
197
- },
198
-
199
- showAppToast(type, text) {
200
- const params = {};
201
- params.text = typeof text === "undefined" ? "" : text;
202
- params.type = typeof type === "undefined" ? "DEFAULT" : type;
203
- window.natively.trigger(undefined, 0, undefined, "show_toast", params);
204
- },
205
-
206
- showAppBanner(type, title, description) {
207
- const params = {};
208
- params.type = typeof type === "undefined" ? "INFO" : type;
209
- params.title = typeof title === "undefined" ? "" : title;
210
- params.description = typeof description === "undefined" ? "" : description;
211
- window.natively.trigger(undefined, 0, undefined, "show_banner", params);
212
- },
213
-
214
- requestAppReview() {
215
- window.natively.trigger(undefined, 0, undefined, "request_review");
216
- },
217
-
218
- setAppBackgroundColor(color) {
219
- const params = { color };
220
- window.natively.trigger(undefined, 1, undefined, "app_background", params);
221
- },
222
-
223
- setAppProgressColor(color) {
224
- const params = { color };
225
- window.natively.trigger(undefined, 1, undefined, "app_progress", params);
226
- },
227
-
228
- setAppSwipeNavigationIOS(toggle) { // DEPRECATED after 2.14.0
229
- const params = { toggle };
230
- window.natively.trigger(undefined, 1, undefined, "app_navigation", params);
231
- },
232
-
233
- setAppSwipeNavigation(toggle) {
234
- const params = { toggle };
235
- window.natively.trigger(undefined, 22, undefined, "app_navigation", params);
236
- },
237
-
238
- setAppPullToRefresh(toggle) {
239
- const params = { toggle };
240
- window.natively.trigger(undefined, 1, undefined, "app_pull", params);
241
- },
242
-
243
- setAppOrientation(orientation) {
244
- const params = { orientation };
245
- window.natively.trigger(undefined, 3, undefined, "app_orientation", params);
246
- },
247
-
248
- setAppStatusBarStyleIOS(style) { // DEPRECATED after 2.14.0
249
- const params = { style };
250
- window.natively.trigger(
251
- undefined,
252
- 2,
253
- undefined,
254
- "status_bar_style",
255
- params
256
- );
257
- },
258
-
259
- setAppStatusBarStyle(style) {
260
- const params = { style };
261
- window.natively.trigger(
262
- undefined,
263
- 22,
264
- undefined,
265
- "status_bar_style",
266
- params
267
- );
268
- },
269
-
270
- hideLoadingScreen() {
271
- const show_loader = false;
272
- const auto_hide = true;
273
- const params = { show_loader, auto_hide };
274
- window.natively.trigger(
275
- undefined,
276
- 17,
277
- undefined,
278
- "loading_screen",
279
- params
280
- );
281
- },
282
-
283
- showLoadingScreen(autoHide) {
284
- const show_loader = true;
285
- const auto_hide = typeof autoHide === "undefined" ? false : autoHide;
286
- const params = { show_loader, auto_hide };
287
- window.natively.trigger(
288
- undefined,
289
- 17,
290
- undefined,
291
- "loading_screen",
292
- params
293
- );
294
- },
295
-
296
- async sendPushNotification(appId, payload, player_ids, isPreview) {
297
- const filtered = player_ids.filter((id) => id.length > 0);
298
- const include_player_ids = [...new Set(filtered)];
299
- let notification = {
300
- app_id: isPreview
301
- ? // Natively Preview App ID
302
- "be83022a-1d08-45d0-a07a-0c3655666e17"
303
- : appId,
304
- include_player_ids,
305
- };
306
- if (payload.template_id) {
307
- notification.template_id = payload.template_id;
308
- } else {
309
- notification.headings = {};
310
- notification.headings.en = payload.title || "Empty Title";
311
- notification.contents = {};
312
- notification.contents.en = payload.message || "Empty Message";
313
- if (payload.subtitle) {
314
- notification.subtitle = {};
315
- notification.subtitle.en = payload.subtitle;
316
- }
317
- if (payload.redirect_url) {
318
- notification.url = payload.redirect_url;
319
- }
320
- }
321
- const options = {
322
- method: "POST",
323
- headers: { "Content-type": "application/json" },
324
- body: JSON.stringify(notification),
325
- };
326
- return await fetch("https://onesignal.com/api/v1/notifications", options);
327
- },
328
- };
329
-
330
- // Initial Setup
331
- // Remove legacy min/current support later
332
- window.natively.addObserver(() =>
333
- window.natively.trigger(
334
- undefined,
335
- 0,
336
- (resp) => {
337
- window.natively.min_app_version = resp.minSDKVersion;
338
- window.natively.app_version = resp.sdkVersion;
339
- },
340
- "app_info",
341
- {}
342
- )
343
- );
344
-
345
- class NativelyInfo {
346
- constructor() {
347
- const id = generateID();
348
- this.browserInfo = function () {
349
- const isNativeApp = typeof $agent !== "undefined";
350
- const isIOSApp = window.navigator.userAgent.includes("Natively/iOS");
351
- const isAndroidApp = window.navigator.userAgent.includes("Natively/Android");
352
- return { isNativeApp, isIOSApp, isAndroidApp };
353
- };
354
- this.getAppInfo = function (app_info_callback) {
355
- window.natively.trigger(id, 0, app_info_callback, "app_info");
356
- };
357
- this.connectivity = function (connectivity_callback) {
358
- window.natively.trigger(
359
- undefined,
360
- 0,
361
- connectivity_callback,
362
- "connectivity"
363
- );
364
- };
365
- // app_state_callback responsible for app state changes.
366
- // e.g. app is in background or foreground (available >= 2.12.2)
367
- this.app_state = function (app_state_callback) {
368
- window.natively.trigger(undefined, 19, app_state_callback, "app_state");
369
- };
370
- }
371
- }
372
-
373
- class NativelyClipboard {
374
- constructor() {
375
- const id = generateID();
376
- this.copy = function (text) {
377
- window.natively.trigger(undefined, 11, undefined, "clipboard_copy", { text });
378
- }
379
- this.paste = function (paste_callback) {
380
- window.natively.trigger(id, 11, paste_callback, "clipboard_paste");
381
- }
382
- }
383
- }
384
-
385
- // WebPage Caching Not Available
386
- class NativelyPagesCache {
387
- constructor() {
388
- const id = generateID();
389
- this.currentPageCached = function (current_page_cached_callback) {
390
- window.natively.trigger(id, 4, current_page_cached_callback, "current_page_cached");
391
- };
392
- this.storeCurrentPage = function (store_current_page_callback) {
393
- window.natively.trigger(id, 4, store_current_page_callback, "store_current_page");
394
- };
395
- this.resetCurrentPage = function (reset_current_page_callback) {
396
- window.natively.trigger(id, 4, reset_current_page_callback, "reset_current_page");
397
- };
398
- this.resetAll = function (reset_all_callback) {
399
- window.natively.trigger(id, 4, reset_all_callback, "reset_all");
400
- };
401
- }
402
- }
403
-
404
- class NativelyNotifications {
405
- constructor() {
406
- const id = generateID();
407
- this.getOneSignalId = function (onesignal_playerid_callback) {
408
- window.natively.trigger(
409
- id,
410
- 0,
411
- onesignal_playerid_callback,
412
- "onesignal_playerid"
413
- );
414
- };
415
- this.requestPermission = function (
416
- fallbackToSettings,
417
- push_register_callback
418
- ) {
419
- window.natively.trigger(id, 0, push_register_callback, "push_register", {
420
- fallbackToSettings,
421
- });
422
- };
423
- this.getPermissionStatus = function (push_permission_callback) {
424
- window.natively.trigger(
425
- id,
426
- 0,
427
- push_permission_callback,
428
- "push_permission"
429
- );
430
- };
431
- }
432
- }
433
-
434
- // Legacy use Natively Location
435
- class NativelyGeolocation {
436
- constructor() {
437
- const id = generateID();
438
- this.getUserGeolocation = function (distance, geolocation_callback) {
439
- window.natively.trigger(id, 0, geolocation_callback, "geolocation", {
440
- distance,
441
- });
442
- };
443
- this.requestPermission = function (geo_register_callback) {
444
- window.natively.trigger(id, 0, geo_register_callback, "geo_register");
445
- };
446
- this.getPermissionStatus = function (geo_permission_callback) {
447
- window.natively.trigger(id, 0, geo_permission_callback, "geo_permission");
448
- };
449
- }
450
- }
451
-
452
- class NativelyLocation {
453
- constructor() {
454
- const id = generateID();
455
- // minAccuracyIOS = 0 - 5000 m
456
- // accuracyTypeIOS = BestForNavigation,Best,NearestTenMeters,HundredMeters,Kilometer,ThreeKilometers
457
- // priority_android = HIGH or BALANCED
458
- this.current = function (minAccuracyIOS, accuracyTypeIOS, priority_android, location_callback) {
459
- window.natively.trigger(id, 12, location_callback, "location_current", {
460
- minAccuracy: minAccuracyIOS,
461
- accuracyType: accuracyTypeIOS,
462
- priority: priority_android
463
- });
464
- };
465
- // "AWLAYS" - background
466
- // "IN_USE" - foreground
467
- // "DENIED" - not determined or denied
468
- this.permission = function (location_permission_callback) {
469
- window.natively.trigger(id, 6, location_permission_callback, "location_permission");
470
- };
471
- this.start = function (interval, minAccuracyIOS, accuracyTypeIOS, priority_android, location_callback) {
472
- window.natively.trigger(id, 12, location_callback, "location_start", {
473
- minAccuracy: minAccuracyIOS,
474
- accuracyType: accuracyTypeIOS,
475
- priority: priority_android,
476
- interval
477
- });
478
- };
479
- this.stop = function () {
480
- window.natively.trigger(id, 3, undefined, "location_stop", {});
481
- };
482
- // minAccuracyIOS = 0 - 5000 m
483
- // accuracyTypeIOS = BestForNavigation,Best,NearestTenMeters,HundredMeters,Kilometer,ThreeKilometers
484
- // priority_android = HIGH or BALANCED
485
- // interval = in seconds e.g. 60 = 1 minute
486
- this.startBackground = function (interval, minAccuracyIOS, accuracyTypeIOS, priority_android, responseIdentifier, location_bg_callback) {
487
- const params = {};
488
- params.identifier = typeof responseIdentifier === "undefined" ? "empty" : responseIdentifier;
489
- params.interval = typeof interval === "undefined" ? 1000 * 60 : interval;
490
- params.minAccuracy = typeof minAccuracyIOS === "undefined" ? 50 : minAccuracyIOS;
491
- params.accuracyType = typeof accuracyTypeIOS === "undefined" ? "Best" : accuracyTypeIOS;
492
- params.priority = typeof priority_android === "undefined" ? "BALANCED" : priority_android;
493
- window.natively.trigger(id, 12, location_bg_callback, "location_start_bg", params);
494
- };
495
- this.statusBackground = function (location_bg_status_callback) {
496
- window.natively.trigger(id, 20, location_bg_status_callback, "location_status_bg", {});
497
- }
498
- this.stopBackground = function (location_bg_callback) {
499
- window.natively.trigger(id, 4, location_bg_callback, "location_stop_bg", {});
500
- };
501
- }
502
- }
503
-
504
- class NativelyMessage {
505
- constructor() {
506
- const id = generateID();
507
- this.sendSMS = function (body, recipient, send_sms_callback) {
508
- const params = {};
509
- params.body = typeof body === "undefined" ? "" : body;
510
- params.recipient = typeof recipient === "undefined" ? "" : recipient;
511
- window.natively.trigger(id, 0, send_sms_callback, "send_sms", params);
512
- };
513
- this.sendEmail = function (subject, body, recipient, send_email_callback) {
514
- const params = {};
515
- params.subject = typeof subject === "undefined" ? "" : subject;
516
- params.body = typeof body === "undefined" ? "" : body;
517
- params.recipient = typeof recipient === "undefined" ? "" : recipient;
518
- window.natively.trigger(id, 0, send_email_callback, "send_email", params);
519
- };
520
- }
521
- }
522
-
523
- class NativelyStorage {
524
- constructor() {
525
- const id = generateID();
526
- this.setStorageValue = function (key, value) {
527
- window.natively.trigger(id, 0, undefined, "set_storage_value", {
528
- key,
529
- value,
530
- });
531
- };
532
- this.getStorageValue = function (key, get_storage_value_callback) {
533
- window.natively.trigger(
534
- id,
535
- 0,
536
- get_storage_value_callback,
537
- "get_storage_value",
538
- { key }
539
- );
540
- };
541
- this.removeStorageValue = function (key) {
542
- window.natively.trigger(id, 0, undefined, "remove_storage_value", {
543
- key,
544
- });
545
- };
546
- this.resetStorage = function () {
547
- window.natively.trigger(id, 0, undefined, "reset_storage");
548
- };
549
- }
550
- }
551
-
552
- class NativelyBiometrics {
553
- constructor(allowPass) {
554
- this.allowPass = allowPass;
555
- const id = generateID();
556
- this.checkBiometricsSupport = function (biometrics_support_callback) {
557
- window.natively.trigger(
558
- id,
559
- 0,
560
- biometrics_support_callback,
561
- "biometrics_support",
562
- { allowPass }
563
- );
564
- };
565
- this.checkCredentials = function (biometrics_has_credentials_callback) {
566
- window.natively.trigger(
567
- id,
568
- 0,
569
- biometrics_has_credentials_callback,
570
- "biometrics_has_credentials"
571
- );
572
- };
573
- this.verifyUserIdentify = function (biometrics_verify_callback) {
574
- window.natively.trigger(
575
- id,
576
- 0,
577
- biometrics_verify_callback,
578
- "biometrics_verify",
579
- { allowPass }
580
- );
581
- };
582
- this.getUserCredentials = function (biometrics_auth_callback) {
583
- window.natively.trigger(
584
- id,
585
- 0,
586
- biometrics_auth_callback,
587
- "biometrics_auth",
588
- { allowPass }
589
- );
590
- };
591
- this.removeUserCredentials = function (
592
- biometrics_remove_credentials_callback
593
- ) {
594
- window.natively.trigger(
595
- id,
596
- 0,
597
- biometrics_remove_credentials_callback,
598
- "biometrics_remove_credentials"
599
- );
600
- };
601
- this.saveUserCredentials = function (
602
- login,
603
- password,
604
- biometrics_auth_callback
605
- ) {
606
- window.natively.trigger(
607
- id,
608
- 0,
609
- biometrics_auth_callback,
610
- "biometrics_auth",
611
- {
612
- allowPass,
613
- login,
614
- password,
615
- }
616
- );
617
- };
618
- }
619
- }
620
-
621
- class NativelyDatePicker {
622
- constructor() {
623
- const id = generateID();
624
- this.showDatePicker = function (
625
- title,
626
- description,
627
- type,
628
- style,
629
- datepicker_callback
630
- ) {
631
- let params = {};
632
- params.type = typeof type === "undefined" ? "DATE" : type;
633
- params.style = typeof style === "undefined" ? "LIGHT" : style;
634
- params.title = typeof title === "undefined" ? "" : title;
635
- params.description = typeof description === "undefined" ? "" : description;
636
- window.natively.trigger(id, 0, datepicker_callback, "datepicker", params);
637
- };
638
- }
639
- }
640
-
641
- class NativelyCamera {
642
- constructor() {
643
- const id = generateID();
644
- this.showCamera = function (type, quality, camera, open_camera_callback) {
645
- let params = {};
646
- params.type = typeof type === "undefined" ? "photo" : type;
647
- params.quality = typeof quality === "undefined" ? "high" : quality;
648
- params.camera = typeof camera === "undefined" ? "BACK" : camera;
649
- window.natively.trigger(
650
- id,
651
- 2,
652
- open_camera_callback,
653
- "open_camera",
654
- params
655
- );
656
- };
657
- }
658
- }
659
-
660
- class NativelyHealth {
661
- constructor() {
662
- const id = generateID();
663
- this.available = function (available_callback) {
664
- window.natively.trigger(id, 10, available_callback, "health_available", {});
665
- };
666
- this.requestAuthorization = function (write_data_types, read_data_types, request_callback) {
667
- window.natively.trigger(id, 10, request_callback, "health_register", {
668
- write_data_types,
669
- read_data_types
670
- });
671
- }
672
- // Write only
673
- this.permissionStatus = function (data_type, callback) {
674
- window.natively.trigger(id, 10, callback, "health_permission", {
675
- data_type
676
- });
677
- }
678
- this.getAllCharacteristics = function (callback) {
679
- window.natively.trigger(id, 10, callback, "health_get_all_characteristics", {});
680
- }
681
- this.getStatisticQuantity = function (data_type, interval, start_date, end_date, callback) {
682
- const obj = {
683
- data_type,
684
- interval
685
- };
686
- if (typeof start_date !== "undefined") {
687
- obj.start_date = start_date.getTime();
688
- }
689
- if (typeof end_date !== "undefined") {
690
- obj.end_date = end_date.getTime();
691
- }
692
- window.natively.trigger(id, 10, callback, "health_get_statistic_quantity", obj);
693
- }
694
- this.getDailySleepAnalysis = function (start_date, end_date, limit, callback) {
695
- const obj = { limit: limit || 100 };
696
- if (typeof start_date !== "undefined") {
697
- obj.start_date = start_date.getTime();
698
- }
699
- if (typeof end_date !== "undefined") {
700
- obj.end_date = end_date.getTime();
701
- }
702
- window.natively.trigger(id, 10, callback, "health_get_daily_sleep_analysis", obj);
703
- }
704
- this.getWorkouts = function (start_date, end_date, limit, callback) {
705
- const obj = { limit: limit || 100 };
706
- if (typeof start_date !== "undefined") {
707
- obj.start_date = start_date.getTime();
708
- }
709
- if (typeof end_date !== "undefined") {
710
- obj.end_date = end_date.getTime();
711
- }
712
- window.natively.trigger(id, 21, callback, "health_get_workouts", obj);
713
- }
714
- this.getActivitySummary = function (start_date, end_date, callback) {
715
- const obj = {};
716
- if (typeof start_date !== "undefined") {
717
- obj.start_date = start_date.getTime();
718
- }
719
- if (typeof end_date !== "undefined") {
720
- obj.end_date = end_date.getTime();
721
- }
722
- window.natively.trigger(id, 10, callback, "health_get_activity_summary", obj);
723
- }
724
- }
725
- }
726
-
727
- class NativelyScanner {
728
- constructor() {
729
- const id = generateID();
730
- this.showScanner = function (open_scanner_callback) {
731
- window.natively.trigger(id, 2, open_scanner_callback, "open_scanner", {});
732
- };
733
- }
734
- }
735
-
736
- class NativelyPurchases {
737
- constructor() {
738
- const id = generateID();
739
- this.login = function (login, customerEmail, login_callback) {
740
- const email = typeof customerEmail === "undefined" ? "" : customerEmail;
741
- window.natively.trigger(id, 3, login_callback, "purchases_login", {
742
- login,
743
- email
744
- });
745
- };
746
- this.logout = function (logout_callback) {
747
- window.natively.trigger(id, 3, logout_callback, "purchases_logout", {});
748
- };
749
- this.customerId = function (customer_id_callback) {
750
- window.natively.trigger(
751
- id,
752
- 3,
753
- customer_id_callback,
754
- "purchases_customerid",
755
- {}
756
- );
757
- };
758
- this.restore = function (restore_callback) {
759
- window.natively.trigger(id, 10, restore_callback, "purchases_restore", {});
760
- };
761
- this.purchasePackage = function (packageId, purchase_callback) {
762
- window.natively.trigger(id, 3, purchase_callback, "purchases_package", {
763
- packageId,
764
- });
765
- };
766
- this.packagePrice = function (packageId, purchase_callback) {
767
- window.natively.trigger(id, 8, purchase_callback, "purchases_price", {
768
- packageId,
769
- });
770
- };
771
- }
772
- }
773
-
774
- class NativelyContacts {
775
- constructor() {
776
- const id = generateID();
777
- this.getAllContacts = function (contacts_all_callback) {
778
- window.natively.trigger(id, 3, contacts_all_callback, "contacts_all", {});
779
- };
780
- this.createContact = function (
781
- firstName,
782
- lastName,
783
- email,
784
- phone,
785
- contacts_save_callback
786
- ) {
787
- let params = { firstName };
788
- params.lastName = typeof lastName === "undefined" ? "" : lastName;
789
- params.email = typeof email === "undefined" ? "" : email;
790
- params.phone = typeof phone === "undefined" ? "" : phone;
791
- window.natively.trigger(
792
- id,
793
- 3,
794
- contacts_save_callback,
795
- "contacts_save",
796
- params
797
- );
798
- };
799
- }
800
- }
801
-
802
- class NativelyMediaPicker {
803
- constructor() {
804
- const id = generateID();
805
- this.showMediaPicker = function (
806
- mediapicker_callback
807
- ) {
808
- window.natively.trigger(id, 8, mediapicker_callback, "mediapicker", {});
809
- };
810
- }
811
- }
812
-
813
- class NativelyAudioRecorder {
814
- constructor() {
815
- const id = generateID();
816
- this.showRecorder = function (
817
- max_duration,
818
- record_callback
819
- ) {
820
- let params = {}
821
- params.max_duration = typeof max_duration === "undefined" ? 0 : max_duration;
822
- window.natively.trigger(id, 13, record_callback, "record_start", params);
823
- };
824
- }
825
- }
826
-
827
- // >=2.9.0
828
- // Can be only one instance of NativelyAdmobBanner per page
829
- // Make sure to use this an not reload page a lot
830
- class NativelyAdmobBanner {
831
- constructor(
832
- config,
833
- setup_callback = undefined, // function(resp) { console.log(resp) }
834
- preload_ad = false, // Load ad on init
835
- preload_callback = undefined, // function(resp) { console.log(resp) }
836
- show_ad = false, // Show ad on init
837
- show_callback = undefined, // function(resp) { console.log(resp) }
838
- ) {
839
- const id = generateID();
840
- let params = {};
841
- if (window.natively.isAndroidApp) {
842
- params.unitId = (typeof config.androidUnitId === "undefined") ? "ca-app-pub-3940256099942544/6300978111" : config.androidUnitId;
843
- } else if (window.natively.isIOSApp) {
844
- params.unitId = (typeof config.iOSUnitId === "undefined") ? "ca-app-pub-3940256099942544/2934735716" : config.iOSUnitId;
845
- }
846
-
847
- params.position = (typeof config.position === "undefined") ? "BOTTOM" : config.position;
848
- params.sizeType = (typeof config.sizeType === "undefined") ? "AUTO" : config.sizeType;
849
- params.width = (typeof config.custom_width === "undefined") ? 320 : config.custom_width;
850
- params.height = (typeof config.custom_height === "undefined") ? 50 : config.custom_height;
851
- window.natively.trigger(id, 14, function (resp) {
852
- if (typeof setup_callback !== "undefined") {
853
- setup_callback(resp);
854
- }
855
- if (preload_ad) {
856
- window.natively.trigger(id, 14, function (resp) {
857
- if (typeof preload_callback !== "undefined") {
858
- preload_callback(resp);
859
- }
860
- if (show_ad) {
861
- window.natively.trigger(id, 14, show_callback, "bannerad_show", {});
862
- }
863
- }, "bannerad_load", {});
864
- }
865
- }, "bannerad_setup", params);
866
-
867
- this.loadAd = function (callback) {
868
- window.natively.trigger(id, 14, callback, "bannerad_load", {});
869
- };
870
- this.showBanner = function (callback) {
871
- window.natively.trigger(id, 14, callback, "bannerad_show", {});
872
- };
873
- this.hideBanner = function (callback) {
874
- window.natively.trigger(id, 14, callback, "bannerad_hide", {});
875
- };
876
- this.bannerIsReady = function (callback) {
877
- window.natively.trigger(id, 14, callback, "bannerad_ready", {});
878
- };
879
- this.bannerIsVisible = function (callback) {
880
- window.natively.trigger(id, 14, callback, "bannerad_visible", {});
881
- };
882
- }
883
- }
884
-
885
- // >=2.9.0
886
- // Can be only one instance of NativelyAdmobInterstitial per page
887
- // Make sure to use this an not reload page a lot
888
- class NativelyAdmobInterstitial {
889
- constructor(
890
- iOSUnitId = "ca-app-pub-3940256099942544/4411468910",
891
- androidUnitId = "ca-app-pub-3940256099942544/1033173712",
892
- setup_callback = undefined, // function(resp) { console.log(resp) }
893
- auto_ad_reload = false, // Reload ad after showing
894
- auto_ad_reload_callback = undefined, // function(resp) { console.log(resp) }
895
- ) {
896
- const id = generateID();
897
- let unitId;
898
- if (window.natively.isAndroidApp) {
899
- unitId = (typeof androidUnitId === "undefined") ? "ca-app-pub-3940256099942544/1033173712" : androidUnitId;
900
- } else if (window.natively.isIOSApp) {
901
- unitId = (typeof iOSUnitId === "undefined") ? "ca-app-pub-3940256099942544/4411468910" : iOSUnitId;
902
- }
903
-
904
- this.loadAd = function (callback) {
905
- const params = {};
906
- params.unitId = (typeof unitId === "undefined") ? "ca-app-pub-3940256099942544/4411468910" : unitId;
907
- window.natively.trigger(id, 14, callback, "interstitialad_setup", params);
908
- };
909
- this.showInterstitialAd = function (callback) {
910
- window.natively.trigger(id, 14, function (resp) {
911
- callback(resp);
912
- if (resp.event === "DID_DISMISS_AD" && auto_ad_reload) {
913
- const params = {};
914
- params.unitId = unitId;
915
- setTimeout(() => {
916
- window.natively.trigger(id, 14, auto_ad_reload_callback, "interstitialad_setup", params);
917
- }, 500);
918
- }
919
- }, "interstitialad_show", {});
920
- };
921
- this.interstitialIsReady = function (callback) {
922
- window.natively.trigger(id, 14, callback, "interstitialad_ready", {});
923
- };
924
- this.loadAd(setup_callback);
925
- }
926
- }
927
-
928
- // >=2.10.0
929
- class NativelyNFCService {
930
- constructor(
931
- readAlertMessage,
932
- writeAlertMessage,
933
- readDetectedMessage,
934
- writeDetectedMessage
935
- ) {
936
- const id = generateID();
937
- this.readAlertMessage = readAlertMessage;
938
- this.writeAlertMessage = writeAlertMessage;
939
- this.readDetectedMessage = readDetectedMessage;
940
- this.writeDetectedMessage = writeDetectedMessage;
941
- this.read = function (callback) {
942
- let params = {}
943
- params.alertMessage = typeof this.readAlertMessage === "undefined" ? "please set readAlertMessage" : this.readAlertMessage;
944
- params.detectedMessage = typeof this.readDetectedMessage === "undefined" ? "readDetectedMessage" : this.readDetectedMessage;
945
- window.natively.trigger(id, 15, callback, "nfc_read", params);
946
- };
947
- this.write = function (recordId, recordData, callback) {
948
- let params = {}
949
- params.alertMessage = typeof this.writeAlertMessage === "undefined" ? "please set writeAlertMessage" : this.writeAlertMessage;
950
- params.detectedMessage = typeof this.writeDetectedMessage === "undefined" ? "please set writeDetectedMessage" : this.writeDetectedMessage;
951
- params.recordData = typeof recordData === "undefined" ? "please set recordData" : recordData;
952
- params.recordId = typeof recordId === "undefined" ? "please set recordId" : recordId;
953
- window.natively.trigger(id, 15, callback, "nfc_write", params);
954
- };
955
- this.available = function (callback) {
956
- let params = {}
957
- window.natively.trigger(id, 15, callback, "nfc_available", params);
958
- };
959
- }
960
- }
961
-
962
- // >=2.11.0
963
- class NativelyAppleSignInService {
964
- constructor() {
965
- const id = generateID();
966
- this.signin = function (callback) {
967
- let params = {}
968
- window.natively.trigger(id, 16, callback, "apple_signin", params);
969
- };
970
- }
971
- }
972
-
973
-
974
-
975
- function generateID() {
976
- return Date.now().toString(36) + Math.random().toString(36).substring(2);
977
- }
978
-
979
- export { NativelyAdmobBanner, NativelyAdmobInterstitial, NativelyAppleSignInService, NativelyAudioRecorder, NativelyBiometrics, NativelyCamera, NativelyClipboard, NativelyContacts, NativelyDatePicker, NativelyGeolocation, NativelyHealth, NativelyInfo, NativelyLocation, NativelyMediaPicker, NativelyMessage, NativelyNFCService, NativelyNotifications, NativelyPagesCache, NativelyPurchases, NativelyScanner, NativelyStorage };