natively 1.0.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/README.md +1 -0
- package/natively-frontend.js +518 -0
- package/natively-frontend.min.js +1 -0
- package/natively-sdk.code-workspace +10 -0
- package/package.json +22 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# natively-sdk
|
|
@@ -0,0 +1,518 @@
|
|
|
1
|
+
window.natively = {
|
|
2
|
+
isDebug: false,
|
|
3
|
+
min_app_version: "",
|
|
4
|
+
app_version: "",
|
|
5
|
+
injected: false,
|
|
6
|
+
observers: [],
|
|
7
|
+
|
|
8
|
+
setDebug: function (isDebug) {
|
|
9
|
+
window.natively.isDebug = isDebug;
|
|
10
|
+
},
|
|
11
|
+
|
|
12
|
+
notify: function () {
|
|
13
|
+
window.natively.injected = true;
|
|
14
|
+
const observers = window.natively.observers;
|
|
15
|
+
if (natively.isDebug) {
|
|
16
|
+
console.log("[INFO] Notify observers: ", observers.length);
|
|
17
|
+
}
|
|
18
|
+
while (observers.length > 0) {
|
|
19
|
+
const observer = observers.shift();
|
|
20
|
+
observer();
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
addObserver: function (fn) {
|
|
25
|
+
if (window.natively.injected) {
|
|
26
|
+
fn();
|
|
27
|
+
} else {
|
|
28
|
+
if (window.natively.isDebug) {
|
|
29
|
+
console.log(`[DEBUG] addObserver: ${fn}`);
|
|
30
|
+
}
|
|
31
|
+
window.natively.observers.push(fn);
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
trigger: function (respId, minVersion, callback, method, body) {
|
|
36
|
+
const isTestVersion = window.natively.isDebug;
|
|
37
|
+
if (!window.natively.injected) {
|
|
38
|
+
window.natively.addObserver(() => {
|
|
39
|
+
window.natively.trigger(respId, minVersion, callback, method, body);
|
|
40
|
+
});
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (isTestVersion && minVersion > window.natively.app_version) {
|
|
44
|
+
alert(
|
|
45
|
+
`[ERROR] Please rebuild the app to use this functionality. App Version: ${window.natively.app_version}, feature version: ${minVersion}`
|
|
46
|
+
);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (callback) {
|
|
50
|
+
let fullMethodName;
|
|
51
|
+
if (respId) {
|
|
52
|
+
fullMethodName = method + "_response" + "_" + respId;
|
|
53
|
+
} else {
|
|
54
|
+
fullMethodName = method + "_response";
|
|
55
|
+
}
|
|
56
|
+
window[fullMethodName] = function (resp, err) {
|
|
57
|
+
$agent.response();
|
|
58
|
+
if (err.message && isTestVersion) {
|
|
59
|
+
alert(`[ERROR] Error message: ${err.message}`);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (isTestVersion) {
|
|
63
|
+
console.log(
|
|
64
|
+
`[DEBUG] Callback method: ${fullMethodName}, body: ${JSON.stringify(
|
|
65
|
+
resp
|
|
66
|
+
)}, respId: ${respId}`
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
callback(resp);
|
|
70
|
+
};
|
|
71
|
+
if (body) {
|
|
72
|
+
body.response_id = respId;
|
|
73
|
+
} else {
|
|
74
|
+
body = { response_id: respId };
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (isTestVersion) {
|
|
78
|
+
console.log(
|
|
79
|
+
`[DEBUG] Trigger method: ${method}, body: ${JSON.stringify(body)}`
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
$agent.trigger(method, body);
|
|
83
|
+
},
|
|
84
|
+
|
|
85
|
+
shareImage(image_url) {
|
|
86
|
+
window.natively.trigger(undefined, 0, undefined, "share_image", {
|
|
87
|
+
url: image_url,
|
|
88
|
+
});
|
|
89
|
+
},
|
|
90
|
+
|
|
91
|
+
shareText(text) {
|
|
92
|
+
window.natively.trigger(undefined, 0, undefined, "share_text", {
|
|
93
|
+
text,
|
|
94
|
+
});
|
|
95
|
+
},
|
|
96
|
+
|
|
97
|
+
shareTextAndImage(text, image_url) {
|
|
98
|
+
window.natively.trigger(undefined, 0, undefined, "share_text_and_image", {
|
|
99
|
+
url: image_url,
|
|
100
|
+
text,
|
|
101
|
+
});
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
shareFile(file_url) {
|
|
105
|
+
window.natively.trigger(undefined, 2, undefined, "share_file", {
|
|
106
|
+
url: file_url,
|
|
107
|
+
});
|
|
108
|
+
},
|
|
109
|
+
|
|
110
|
+
openExternalURL(url) {
|
|
111
|
+
window.natively.trigger(undefined, 0, undefined, "open_link", {
|
|
112
|
+
url,
|
|
113
|
+
});
|
|
114
|
+
},
|
|
115
|
+
|
|
116
|
+
openExternalAppIOS(url) {
|
|
117
|
+
window.natively.trigger(undefined, 0, undefined, "open_app", {
|
|
118
|
+
url,
|
|
119
|
+
});
|
|
120
|
+
},
|
|
121
|
+
|
|
122
|
+
openAppSettings() {
|
|
123
|
+
window.natively.trigger(undefined, 0, undefined, "open_appsettings");
|
|
124
|
+
},
|
|
125
|
+
|
|
126
|
+
showAppToast(type, text) {
|
|
127
|
+
const params = {};
|
|
128
|
+
params.text = typeof text === "undefined" ? "" : text;
|
|
129
|
+
params.type = typeof type === "undefined" ? type : "DEFAULT";
|
|
130
|
+
window.natively.trigger(undefined, 0, undefined, "show_toast", params);
|
|
131
|
+
},
|
|
132
|
+
|
|
133
|
+
showAppBanner(type, title, description) {
|
|
134
|
+
const params = {};
|
|
135
|
+
params.type = typeof type === "undefined" ? "INFO" : type;
|
|
136
|
+
params.title = typeof title === "undefined" ? "" : title;
|
|
137
|
+
params.description = typeof description === "undefined" ? "" : description;
|
|
138
|
+
window.natively.trigger(undefined, 0, undefined, "show_banner", params);
|
|
139
|
+
},
|
|
140
|
+
|
|
141
|
+
requestAppReview() {
|
|
142
|
+
window.natively.trigger(undefined, 0, undefined, "request_review");
|
|
143
|
+
},
|
|
144
|
+
|
|
145
|
+
setAppBackgroundColor(color) {
|
|
146
|
+
const params = { color };
|
|
147
|
+
window.natively.trigger(undefined, 1, undefined, "app_background", params);
|
|
148
|
+
},
|
|
149
|
+
|
|
150
|
+
setAppProgressColor(color) {
|
|
151
|
+
const params = { color };
|
|
152
|
+
window.natively.trigger(undefined, 1, undefined, "app_progress", params);
|
|
153
|
+
},
|
|
154
|
+
|
|
155
|
+
setAppSwipeNavigationIOS(toggle) {
|
|
156
|
+
const params = { toggle };
|
|
157
|
+
window.natively.trigger(undefined, 1, undefined, "app_navigation", params);
|
|
158
|
+
},
|
|
159
|
+
|
|
160
|
+
setAppPullToRefresh(toggle) {
|
|
161
|
+
const params = { toggle };
|
|
162
|
+
window.natively.trigger(undefined, 1, undefined, "app_pull", params);
|
|
163
|
+
},
|
|
164
|
+
|
|
165
|
+
setAppStatusBarStyleIOS(style) {
|
|
166
|
+
const params = { style };
|
|
167
|
+
window.natively.trigger(
|
|
168
|
+
undefined,
|
|
169
|
+
2,
|
|
170
|
+
undefined,
|
|
171
|
+
"status_bar_style",
|
|
172
|
+
params
|
|
173
|
+
);
|
|
174
|
+
},
|
|
175
|
+
|
|
176
|
+
async sendPushNotification(appId, payload, player_ids, isPreview) {
|
|
177
|
+
const filtered = player_ids.filter((id) => id.length > 0);
|
|
178
|
+
const include_player_ids = [...new Set(filtered)];
|
|
179
|
+
let notification = {
|
|
180
|
+
app_id: isPreview
|
|
181
|
+
? // Natively Preview App ID
|
|
182
|
+
"be83022a-1d08-45d0-a07a-0c3655666e17"
|
|
183
|
+
: appId,
|
|
184
|
+
include_player_ids,
|
|
185
|
+
};
|
|
186
|
+
if (payload.template_id) {
|
|
187
|
+
notification.template_id = payload.template_id;
|
|
188
|
+
} else {
|
|
189
|
+
notification.headings = {};
|
|
190
|
+
notification.headings.en = payload.title || "Empty Title";
|
|
191
|
+
notification.contents = {};
|
|
192
|
+
notification.contents.en = payload.message || "Empty Message";
|
|
193
|
+
if (payload.subtitle) {
|
|
194
|
+
notification.subtitle = {};
|
|
195
|
+
notification.subtitle.en = payload.subtitle;
|
|
196
|
+
}
|
|
197
|
+
if (payload.redirect_url) {
|
|
198
|
+
notification.url = payload.redirect_url;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
const options = {
|
|
202
|
+
method: "POST",
|
|
203
|
+
headers: { "Content-type": "application/json" },
|
|
204
|
+
body: JSON.stringify(notification),
|
|
205
|
+
};
|
|
206
|
+
return await fetch("https://onesignal.com/api/v1/notifications", options);
|
|
207
|
+
},
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
// Initial Setup
|
|
211
|
+
window.natively.addObserver(() =>
|
|
212
|
+
window.natively.trigger(
|
|
213
|
+
undefined,
|
|
214
|
+
0,
|
|
215
|
+
(resp) => {
|
|
216
|
+
window.natively.min_app_version = resp.minSDKVersion;
|
|
217
|
+
window.natively.app_version = resp.sdkVersion;
|
|
218
|
+
},
|
|
219
|
+
"app_info",
|
|
220
|
+
{}
|
|
221
|
+
)
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
class NativelyInfo {
|
|
225
|
+
constructor() {
|
|
226
|
+
const id = generateID();
|
|
227
|
+
this.getAppInfo = function (app_info_callback) {
|
|
228
|
+
window.natively.trigger(id, 0, app_info_callback, "app_info");
|
|
229
|
+
};
|
|
230
|
+
this.connectivity = function (connectivity_callback) {
|
|
231
|
+
window.natively.trigger(
|
|
232
|
+
undefined,
|
|
233
|
+
0,
|
|
234
|
+
connectivity_callback,
|
|
235
|
+
"connectivity"
|
|
236
|
+
);
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
class NativelyNotifications {
|
|
242
|
+
constructor() {
|
|
243
|
+
const id = generateID();
|
|
244
|
+
this.getOneSignalId = function (onesignal_playerid_callback) {
|
|
245
|
+
window.natively.trigger(
|
|
246
|
+
id,
|
|
247
|
+
0,
|
|
248
|
+
onesignal_playerid_callback,
|
|
249
|
+
"onesignal_playerid"
|
|
250
|
+
);
|
|
251
|
+
};
|
|
252
|
+
this.requestPermissionIOS = function (
|
|
253
|
+
fallbackToSettings,
|
|
254
|
+
push_register_callback
|
|
255
|
+
) {
|
|
256
|
+
window.natively.trigger(id, 0, push_register_callback, "push_register", {
|
|
257
|
+
fallbackToSettings,
|
|
258
|
+
});
|
|
259
|
+
};
|
|
260
|
+
this.getPermissionStatusIOS = function (push_permission_callback) {
|
|
261
|
+
window.natively.trigger(
|
|
262
|
+
id,
|
|
263
|
+
0,
|
|
264
|
+
push_permission_callback,
|
|
265
|
+
"push_permission"
|
|
266
|
+
);
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
class NativelyGeolocation {
|
|
272
|
+
constructor() {
|
|
273
|
+
const id = generateID();
|
|
274
|
+
this.getUserGeolocation = function (distance, geolocation_callback) {
|
|
275
|
+
window.natively.trigger(id, 0, geolocation_callback, "geolocation", {
|
|
276
|
+
distance,
|
|
277
|
+
});
|
|
278
|
+
};
|
|
279
|
+
this.requestPermission = function (geo_register_callback) {
|
|
280
|
+
window.natively.trigger(id, 0, geo_register_callback, "geo_register");
|
|
281
|
+
};
|
|
282
|
+
this.getPermissionStatus = function (geo_permission_callback) {
|
|
283
|
+
window.natively.trigger(
|
|
284
|
+
id,
|
|
285
|
+
0,
|
|
286
|
+
geo_permission_callback,
|
|
287
|
+
"geo_permission"
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
class NativelyMessage {
|
|
294
|
+
constructor() {
|
|
295
|
+
const id = generateID();
|
|
296
|
+
this.sendSMS = function (body, recipient, send_sms_callback) {
|
|
297
|
+
const params = {};
|
|
298
|
+
params.body = typeof body === undefined ? "" : body;
|
|
299
|
+
params.recipient = typeof recipient === undefined ? "" : recipient;
|
|
300
|
+
window.natively.trigger(id, 0, send_sms_callback, "send_sms", params);
|
|
301
|
+
};
|
|
302
|
+
this.sendEmail = function (subject, body, recipient, send_email_callback) {
|
|
303
|
+
const params = {};
|
|
304
|
+
params.subject = typeof subject === undefined ? "" : subject;
|
|
305
|
+
params.body = typeof body === undefined ? "" : body;
|
|
306
|
+
params.recipient = typeof recipient === undefined ? "" : recipient;
|
|
307
|
+
window.natively.trigger(id, 0, send_email_callback, "send_email", params);
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
class NativelyStorage {
|
|
313
|
+
constructor() {
|
|
314
|
+
const id = generateID();
|
|
315
|
+
this.setStorageValue = function (key, value) {
|
|
316
|
+
window.natively.trigger(id, 0, undefined, "set_storage_value", {
|
|
317
|
+
key,
|
|
318
|
+
value,
|
|
319
|
+
});
|
|
320
|
+
};
|
|
321
|
+
this.getStorageValue = function (key, get_storage_value_callback) {
|
|
322
|
+
window.natively.trigger(
|
|
323
|
+
id,
|
|
324
|
+
0,
|
|
325
|
+
get_storage_value_callback,
|
|
326
|
+
"get_storage_value",
|
|
327
|
+
{ key }
|
|
328
|
+
);
|
|
329
|
+
};
|
|
330
|
+
this.removeStorageValue = function (key) {
|
|
331
|
+
window.natively.trigger(id, 0, undefined, "remove_storage_value", {
|
|
332
|
+
key,
|
|
333
|
+
});
|
|
334
|
+
};
|
|
335
|
+
this.resetStorage = function () {
|
|
336
|
+
window.natively.trigger(id, 0, undefined, "reset_storage");
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
class NativelyBiometrics {
|
|
342
|
+
constructor(allowPass) {
|
|
343
|
+
this.allowPass = allowPass;
|
|
344
|
+
const id = generateID();
|
|
345
|
+
this.checkBiometricsSupport = function (biometrics_support_callback) {
|
|
346
|
+
window.natively.trigger(
|
|
347
|
+
id,
|
|
348
|
+
0,
|
|
349
|
+
biometrics_support_callback,
|
|
350
|
+
"biometrics_support",
|
|
351
|
+
{ allowPass }
|
|
352
|
+
);
|
|
353
|
+
};
|
|
354
|
+
this.checkCredentials = function (biometrics_has_credentials_callback) {
|
|
355
|
+
window.natively.trigger(
|
|
356
|
+
id,
|
|
357
|
+
0,
|
|
358
|
+
biometrics_has_credentials_callback,
|
|
359
|
+
"biometrics_has_credentials"
|
|
360
|
+
);
|
|
361
|
+
};
|
|
362
|
+
this.verifyUserIdentify = function (biometrics_verify_callback) {
|
|
363
|
+
window.natively.trigger(
|
|
364
|
+
id,
|
|
365
|
+
0,
|
|
366
|
+
biometrics_verify_callback,
|
|
367
|
+
"biometrics_verify",
|
|
368
|
+
{ allowPass }
|
|
369
|
+
);
|
|
370
|
+
};
|
|
371
|
+
this.getUserCredentials = function (biometrics_auth_callback) {
|
|
372
|
+
window.natively.trigger(
|
|
373
|
+
id,
|
|
374
|
+
0,
|
|
375
|
+
biometrics_auth_callback,
|
|
376
|
+
"biometrics_auth",
|
|
377
|
+
{ allowPass }
|
|
378
|
+
);
|
|
379
|
+
};
|
|
380
|
+
this.removeUserCredentials = function (
|
|
381
|
+
biometrics_remove_credentials_callback
|
|
382
|
+
) {
|
|
383
|
+
window.natively.trigger(
|
|
384
|
+
id,
|
|
385
|
+
0,
|
|
386
|
+
biometrics_remove_credentials_callback,
|
|
387
|
+
"biometrics_remove_credentials"
|
|
388
|
+
);
|
|
389
|
+
};
|
|
390
|
+
this.saveUserCredentials = function (
|
|
391
|
+
login,
|
|
392
|
+
password,
|
|
393
|
+
biometrics_auth_callback
|
|
394
|
+
) {
|
|
395
|
+
window.natively.trigger(
|
|
396
|
+
id,
|
|
397
|
+
0,
|
|
398
|
+
biometrics_auth_callback,
|
|
399
|
+
"biometrics_auth",
|
|
400
|
+
{
|
|
401
|
+
allowPass,
|
|
402
|
+
login,
|
|
403
|
+
password,
|
|
404
|
+
}
|
|
405
|
+
);
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
class NativelyDatePicker {
|
|
411
|
+
constructor() {
|
|
412
|
+
const id = generateID();
|
|
413
|
+
this.showDatePicker = function (
|
|
414
|
+
title,
|
|
415
|
+
description,
|
|
416
|
+
type,
|
|
417
|
+
style,
|
|
418
|
+
datepicker_callback
|
|
419
|
+
) {
|
|
420
|
+
let params = {};
|
|
421
|
+
params.type = typeof type === undefined ? "DATE" : type;
|
|
422
|
+
params.style = typeof style === undefined ? "LIGHT" : style;
|
|
423
|
+
params.title = typeof title === undefined ? "" : title;
|
|
424
|
+
params.description = typeof description === undefined ? "" : description;
|
|
425
|
+
window.natively.trigger(id, 0, datepicker_callback, "datepicker", params);
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
class NativelyCamera {
|
|
431
|
+
constructor() {
|
|
432
|
+
const id = generateID();
|
|
433
|
+
this.showCamera = function (type, quality, open_camera_callback) {
|
|
434
|
+
let params = {};
|
|
435
|
+
params.type = typeof type === undefined ? "photo" : type;
|
|
436
|
+
params.quality = typeof quality === undefined ? "high" : quality;
|
|
437
|
+
window.natively.trigger(
|
|
438
|
+
id,
|
|
439
|
+
2,
|
|
440
|
+
open_camera_callback,
|
|
441
|
+
"open_camera",
|
|
442
|
+
params
|
|
443
|
+
);
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
class NativelyScanner {
|
|
449
|
+
constructor() {
|
|
450
|
+
const id = generateID();
|
|
451
|
+
this.showScanner = function (open_scanner_callback) {
|
|
452
|
+
window.natively.trigger(id, 2, open_scanner_callback, "open_scanner", {});
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
class NativelyPurchases {
|
|
458
|
+
constructor() {
|
|
459
|
+
const id = generateID();
|
|
460
|
+
this.purchaseIOS = function (productId, inapp_purchase_callback) {
|
|
461
|
+
window.natively.trigger(
|
|
462
|
+
id,
|
|
463
|
+
3,
|
|
464
|
+
inapp_purchase_callback,
|
|
465
|
+
"inapp_purchase",
|
|
466
|
+
{ productId }
|
|
467
|
+
);
|
|
468
|
+
};
|
|
469
|
+
this.purchaseAndroid = function (
|
|
470
|
+
productType,
|
|
471
|
+
productId,
|
|
472
|
+
offerTag,
|
|
473
|
+
inapp_purchase_callback
|
|
474
|
+
) {
|
|
475
|
+
const tag = typeof offerTag === undefined ? "" : offerTag;
|
|
476
|
+
let params = { productId, productType, offerTag: tag };
|
|
477
|
+
window.natively.trigger(
|
|
478
|
+
id,
|
|
479
|
+
3,
|
|
480
|
+
inapp_purchase_callback,
|
|
481
|
+
"inapp_purchase",
|
|
482
|
+
params
|
|
483
|
+
);
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
class NativelyContacts {
|
|
489
|
+
constructor() {
|
|
490
|
+
const id = generateID();
|
|
491
|
+
this.getAllContacts = function (contacts_all_callback) {
|
|
492
|
+
window.natively.trigger(id, 3, contacts_all_callback, "contacts_all", {});
|
|
493
|
+
};
|
|
494
|
+
this.createContact = function (
|
|
495
|
+
firstName,
|
|
496
|
+
lastName,
|
|
497
|
+
email,
|
|
498
|
+
phone,
|
|
499
|
+
contacts_save_callback
|
|
500
|
+
) {
|
|
501
|
+
let params = { firstName };
|
|
502
|
+
params.lastName = typeof lastName === undefined ? "" : lastName;
|
|
503
|
+
params.email = typeof email === undefined ? "" : email;
|
|
504
|
+
params.phone = typeof phone === undefined ? "" : phone;
|
|
505
|
+
window.natively.trigger(
|
|
506
|
+
id,
|
|
507
|
+
3,
|
|
508
|
+
contacts_save_callback,
|
|
509
|
+
"contacts_save",
|
|
510
|
+
params
|
|
511
|
+
);
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
function generateID() {
|
|
517
|
+
return Date.now().toString(36) + Math.random().toString(36).substring(2);
|
|
518
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function generateID(){return Date.now().toString(36)+Math.random().toString(36).substring(2)}window.natively={isDebug:!1,min_app_version:"",app_version:"",injected:!1,observers:[],setDebug:function(e){window.natively.isDebug=e},notify:function(){window.natively.injected=!0;const e=window.natively.observers;for(natively.isDebug&&console.log("[INFO] Notify observers: ",e.length);e.length>0;){const t=e.shift();t()}},addObserver:function(e){window.natively.injected?e():(window.natively.isDebug&&console.log(`[DEBUG] addObserver: ${e}`),window.natively.observers.push(e))},trigger:function(e,t,i,n,o){const r=window.natively.isDebug;if(window.natively.injected)if(r&&t>window.natively.app_version)alert(`[ERROR] Please rebuild the app to use this functionality. App Version: ${window.natively.app_version}, feature version: ${t}`);else{if(i){let t;t=e?n+"_response_"+e:n+"_response",window[t]=function(n,o){$agent.response(),o.message&&r?alert(`[ERROR] Error message: ${o.message}`):(r&&console.log(`[DEBUG] Callback method: ${t}, body: ${JSON.stringify(n)}, respId: ${e}`),i(n))},o?o.response_id=e:o={response_id:e}}r&&console.log(`[DEBUG] Trigger method: ${n}, body: ${JSON.stringify(o)}`),$agent.trigger(n,o)}else window.natively.addObserver(()=>{window.natively.trigger(e,t,i,n,o)})},shareImage(e){window.natively.trigger(void 0,0,void 0,"share_image",{url:e})},shareText(e){window.natively.trigger(void 0,0,void 0,"share_text",{text:e})},shareTextAndImage(e,t){window.natively.trigger(void 0,0,void 0,"share_text_and_image",{url:t,text:e})},shareFile(e){window.natively.trigger(void 0,2,void 0,"share_file",{url:e})},openExternalURL(e){window.natively.trigger(void 0,0,void 0,"open_link",{url:e})},openExternalAppIOS(e){window.natively.trigger(void 0,0,void 0,"open_app",{url:e})},openAppSettings(){window.natively.trigger(void 0,0,void 0,"open_appsettings")},showAppToast(e,t){const i={};i.text=void 0===t?"":t,i.type=void 0===e?e:"DEFAULT",window.natively.trigger(void 0,0,void 0,"show_toast",i)},showAppBanner(e,t,i){const n={};n.type=void 0===e?"INFO":e,n.title=void 0===t?"":t,n.description=void 0===i?"":i,window.natively.trigger(void 0,0,void 0,"show_banner",n)},requestAppReview(){window.natively.trigger(void 0,0,void 0,"request_review")},setAppBackgroundColor(e){const t={color:e};window.natively.trigger(void 0,1,void 0,"app_background",t)},setAppProgressColor(e){const t={color:e};window.natively.trigger(void 0,1,void 0,"app_progress",t)},setAppSwipeNavigationIOS(e){const t={toggle:e};window.natively.trigger(void 0,1,void 0,"app_navigation",t)},setAppPullToRefresh(e){const t={toggle:e};window.natively.trigger(void 0,1,void 0,"app_pull",t)},setAppStatusBarStyleIOS(e){const t={style:e};window.natively.trigger(void 0,2,void 0,"status_bar_style",t)},async sendPushNotification(e,t,i,n){const o=i.filter(e=>e.length>0),r=[...new Set(o)];let s={app_id:n?"be83022a-1d08-45d0-a07a-0c3655666e17":e,include_player_ids:r};t.template_id?s.template_id=t.template_id:(s.headings={},s.headings.en=t.title||"Empty Title",s.contents={},s.contents.en=t.message||"Empty Message",t.subtitle&&(s.subtitle={},s.subtitle.en=t.subtitle),t.redirect_url&&(s.url=t.redirect_url));const a={method:"POST",headers:{"Content-type":"application/json"},body:JSON.stringify(s)};return await fetch("https://onesignal.com/api/v1/notifications",a)}},window.natively.addObserver(()=>window.natively.trigger(void 0,0,e=>{window.natively.min_app_version=e.minSDKVersion,window.natively.app_version=e.sdkVersion},"app_info",{}));class NativelyInfo{constructor(){const e=generateID();this.getAppInfo=function(t){window.natively.trigger(e,0,t,"app_info")},this.connectivity=function(e){window.natively.trigger(void 0,0,e,"connectivity")}}}class NativelyNotifications{constructor(){const e=generateID();this.getOneSignalId=function(t){window.natively.trigger(e,0,t,"onesignal_playerid")},this.requestPermissionIOS=function(t,i){window.natively.trigger(e,0,i,"push_register",{fallbackToSettings:t})},this.getPermissionStatusIOS=function(t){window.natively.trigger(e,0,t,"push_permission")}}}class NativelyGeolocation{constructor(){const e=generateID();this.getUserGeolocation=function(t,i){window.natively.trigger(e,0,i,"geolocation",{distance:t})},this.requestPermission=function(t){window.natively.trigger(e,0,t,"geo_register")},this.getPermissionStatus=function(t){window.natively.trigger(e,0,t,"geo_permission")}}}class NativelyMessage{constructor(){const e=generateID();this.sendSMS=function(t,i,n){const o={};o.body=void 0===typeof t?"":t,o.recipient=void 0===typeof i?"":i,window.natively.trigger(e,0,n,"send_sms",o)},this.sendEmail=function(t,i,n,o){const r={};r.subject=void 0===typeof t?"":t,r.body=void 0===typeof i?"":i,r.recipient=void 0===typeof n?"":n,window.natively.trigger(e,0,o,"send_email",r)}}}class NativelyStorage{constructor(){const e=generateID();this.setStorageValue=function(t,i){window.natively.trigger(e,0,void 0,"set_storage_value",{key:t,value:i})},this.getStorageValue=function(t,i){window.natively.trigger(e,0,i,"get_storage_value",{key:t})},this.removeStorageValue=function(t){window.natively.trigger(e,0,void 0,"remove_storage_value",{key:t})},this.resetStorage=function(){window.natively.trigger(e,0,void 0,"reset_storage")}}}class NativelyBiometrics{constructor(e){this.allowPass=e;const t=generateID();this.checkBiometricsSupport=function(i){window.natively.trigger(t,0,i,"biometrics_support",{allowPass:e})},this.checkCredentials=function(e){window.natively.trigger(t,0,e,"biometrics_has_credentials")},this.verifyUserIdentify=function(i){window.natively.trigger(t,0,i,"biometrics_verify",{allowPass:e})},this.getUserCredentials=function(i){window.natively.trigger(t,0,i,"biometrics_auth",{allowPass:e})},this.removeUserCredentials=function(e){window.natively.trigger(t,0,e,"biometrics_remove_credentials")},this.saveUserCredentials=function(i,n,o){window.natively.trigger(t,0,o,"biometrics_auth",{allowPass:e,login:i,password:n})}}}class NativelyDatePicker{constructor(){const e=generateID();this.showDatePicker=function(t,i,n,o,r){let s={};s.type=void 0===typeof n?"DATE":n,s.style=void 0===typeof o?"LIGHT":o,s.title=void 0===typeof t?"":t,s.description=void 0===typeof i?"":i,window.natively.trigger(e,0,r,"datepicker",s)}}}class NativelyCamera{constructor(){const e=generateID();this.showCamera=function(t,i,n){let o={};o.type=void 0===typeof t?"photo":t,o.quality=void 0===typeof i?"high":i,window.natively.trigger(e,2,n,"open_camera",o)}}}class NativelyScanner{constructor(){const e=generateID();this.showScanner=function(t){window.natively.trigger(e,2,t,"open_scanner",{})}}}class NativelyPurchases{constructor(){const e=generateID();this.purchaseIOS=function(t,i){window.natively.trigger(e,3,i,"inapp_purchase",{productId:t})},this.purchaseAndroid=function(t,i,n,o){const r=void 0===typeof n?"":n;let s={productId:i,productType:t,offerTag:r};window.natively.trigger(e,3,o,"inapp_purchase",s)}}}class NativelyContacts{constructor(){const e=generateID();this.getAllContacts=function(t){window.natively.trigger(e,3,t,"contacts_all",{})},this.createContact=function(t,i,n,o,r){let s={firstName:t};s.lastName=void 0===typeof i?"":i,s.email=void 0===typeof n?"":n,s.phone=void 0===typeof o?"":o,window.natively.trigger(e,3,r,"contacts_save",s)}}}
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "natively",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "natively-frontend.min.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/No-Code-No-Problem/natively-sdk.git"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"natively"
|
|
15
|
+
],
|
|
16
|
+
"author": "Roman Furman",
|
|
17
|
+
"license": "ISC",
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/No-Code-No-Problem/natively-sdk/issues"
|
|
20
|
+
},
|
|
21
|
+
"homepage": "https://github.com/No-Code-No-Problem/natively-sdk#readme"
|
|
22
|
+
}
|