natively 1.0.0 → 1.3.7

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 CHANGED
@@ -1 +1,24 @@
1
1
  # natively-sdk
2
+
3
+ ### Installation
4
+
5
+ Add to the website page header:
6
+
7
+ ```
8
+ <script src="https://cdn.jsdelivr.net/npm/natively@1.0.0/natively-frontend.min.js"></script>
9
+ ```
10
+
11
+ ### Usage
12
+
13
+ ```
14
+ // Elements (with callback from the App)
15
+ const notifications = new NativelyNotifications();
16
+ const playerId_callback = function(resp) {
17
+ console.log(resp);
18
+ console.log(resp.playerId);
19
+ };
20
+ notifications.getOneSignalId(playerId_callback);
21
+
22
+ // Actions (without callback from the App)
23
+ window.natively.shareText("Hello world!");
24
+ ```
@@ -162,6 +162,11 @@ window.natively = {
162
162
  window.natively.trigger(undefined, 1, undefined, "app_pull", params);
163
163
  },
164
164
 
165
+ setAppOrientation(orientation) {
166
+ const params = { orientation };
167
+ window.natively.trigger(undefined, 3, undefined, "app_orientation", params);
168
+ },
169
+
165
170
  setAppStatusBarStyleIOS(style) {
166
171
  const params = { style };
167
172
  window.natively.trigger(
@@ -268,6 +273,7 @@ class NativelyNotifications {
268
273
  }
269
274
  }
270
275
 
276
+ // Legacy use Natively Location
271
277
  class NativelyGeolocation {
272
278
  constructor() {
273
279
  const id = generateID();
@@ -280,13 +286,27 @@ class NativelyGeolocation {
280
286
  window.natively.trigger(id, 0, geo_register_callback, "geo_register");
281
287
  };
282
288
  this.getPermissionStatus = function (geo_permission_callback) {
283
- window.natively.trigger(
284
- id,
285
- 0,
286
- geo_permission_callback,
287
- "geo_permission"
288
- );
289
- }
289
+ window.natively.trigger(id, 0, geo_permission_callback, "geo_permission");
290
+ };
291
+ }
292
+ }
293
+
294
+ class NativelyLocation {
295
+ constructor() {
296
+ const id = generateID();
297
+ this.current = function (accuracy, location_callback) {
298
+ window.natively.trigger(id, 3, location_callback, "location_current", {
299
+ accuracy,
300
+ });
301
+ };
302
+ this.start = function (accuracy, location_callback) {
303
+ window.natively.trigger(id, 3, location_callback, "location_start", {
304
+ accuracy,
305
+ });
306
+ };
307
+ this.stop = function () {
308
+ window.natively.trigger(id, 3, undefined, "location_stop", {});
309
+ };
290
310
  }
291
311
  }
292
312
 
@@ -457,31 +477,28 @@ class NativelyScanner {
457
477
  class NativelyPurchases {
458
478
  constructor() {
459
479
  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
- );
480
+ this.login = function (login, login_callback) {
481
+ window.natively.trigger(id, 3, login_callback, "purchases_login", {
482
+ login,
483
+ });
468
484
  };
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 };
485
+ this.logout = function (logout_callback) {
486
+ window.natively.trigger(id, 3, logout_callback, "purchases_logout", {});
487
+ };
488
+ this.customerId = function (customer_id_callback) {
477
489
  window.natively.trigger(
478
490
  id,
479
491
  3,
480
- inapp_purchase_callback,
481
- "inapp_purchase",
482
- params
492
+ customer_id_callback,
493
+ "purchases_customerid",
494
+ {}
483
495
  );
484
496
  };
497
+ this.purchasePackage = function (packageId, purchase_callback) {
498
+ window.natively.trigger(id, 3, purchase_callback, "purchases_package", {
499
+ packageId,
500
+ });
501
+ };
485
502
  }
486
503
  }
487
504
 
@@ -1 +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)}}}
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)},setAppOrientation(e){const t={orientation:e};window.natively.trigger(void 0,3,void 0,"app_orientation",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 NativelyLocation{constructor(){const e=generateID();this.current=function(t,i){window.natively.trigger(e,3,i,"location_current",{accuracy:t})},this.start=function(t,i){window.natively.trigger(e,3,i,"location_start",{accuracy:t})},this.stop=function(){window.natively.trigger(e,3,void 0,"location_stop",{})}}}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.login=function(t,i){window.natively.trigger(e,3,i,"purchases_login",{login:t})},this.logout=function(t){window.natively.trigger(e,3,t,"purchases_logout",{})},this.customerId=function(t){window.natively.trigger(e,3,t,"purchases_customerid",{})},this.purchasePackage=function(t,i){window.natively.trigger(e,3,i,"purchases_package",{packageId:t})}}}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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "natively",
3
- "version": "1.0.0",
3
+ "version": "1.3.7",
4
4
  "description": "",
5
5
  "main": "natively-frontend.min.js",
6
6
  "scripts": {
@@ -1,10 +0,0 @@
1
- {
2
- "folders": [
3
- {
4
- "path": "."
5
- }
6
- ],
7
- "settings": {
8
- "es6-css-minify.autoprefixer": {}
9
- }
10
- }