starti.app 1.0.13 → 1.0.15

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 ADDED
@@ -0,0 +1,18 @@
1
+ # starti.app API
2
+
3
+ ## When should I use this package?
4
+
5
+ You've bought a [start.app](https://starti.app) and want to integrate your website and the app.
6
+
7
+ This package allows you to talk to the app using an easy API.
8
+
9
+ ## How do I get started
10
+
11
+ Add the package to your project in one of two ways:
12
+
13
+ 1) Add the package using npm:
14
+ `npm install starti.app@1.0.12`
15
+
16
+ 2) Add the following line to your HTML file:
17
+ `<script crossorigin src="https://unpkg.com/starti.app@1.0.12/umd/main.js"></script>`
18
+
package/dist/app.d.ts CHANGED
@@ -1,11 +1,13 @@
1
1
  export declare const App: IApp;
2
+ declare type AppEvents = "appInForeground";
2
3
  export interface IApp {
3
- /** The event will be called whenever the app enters the foreground on the device and when the app starts og thus also enters the foreground on the device. */
4
- onAppInForeground?: () => void;
5
4
  /** Are the site running inside starti.app? Returns false if the site is loaded in a normal browser. */
6
5
  isStartiappLoaded(): boolean;
7
6
  /** Use this method to control which URL the app load when it is initialized. */
8
7
  setAppUrl: (url: string) => void;
9
8
  /** Returns the version number of the app (eg. 1.0.0). */
10
9
  version(): Promise<string>;
10
+ /** Listen for events */
11
+ addEventListener(type: AppEvents, callback: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
11
12
  }
13
+ export {};
package/dist/app.js CHANGED
@@ -1,33 +1,34 @@
1
1
  "use strict";
2
- var _a;
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.App = void 0;
5
- exports.App = (_a = class {
6
- static setStartiappIsLoaded() {
7
- this.startiappIsLoaded = true;
8
- }
9
- static isStartiappLoaded() {
10
- return this.startiappIsLoaded;
11
- }
12
- static setAppUrl(url) {
13
- // @ts-ignore
14
- AppIntegration.setAppUrl(url);
15
- }
16
- static version() {
17
- const promise = new Promise((resolve, reject) => {
18
- this.resolveString = resolve;
19
- // @ts-ignore
20
- AppIntegration.version();
21
- });
22
- return promise;
23
- }
24
- static appInForegroundEventRecievedEvent() {
25
- if (this.onAppInForeground)
26
- this.onAppInForeground();
27
- }
28
- static versionResult(result) {
29
- this.resolveString(result);
30
- }
31
- },
32
- _a.startiappIsLoaded = false,
33
- _a);
4
+ exports.App = new class extends EventTarget {
5
+ constructor() {
6
+ super(...arguments);
7
+ this.startiappIsLoaded = false;
8
+ }
9
+ setStartiappIsLoaded() {
10
+ this.startiappIsLoaded = true;
11
+ }
12
+ isStartiappLoaded() {
13
+ return this.startiappIsLoaded;
14
+ }
15
+ setAppUrl(url) {
16
+ AppIntegration.setAppUrl(url);
17
+ }
18
+ version() {
19
+ const promise = new Promise((resolve, reject) => {
20
+ this.resolveString = resolve;
21
+ AppIntegration.version();
22
+ });
23
+ return promise;
24
+ }
25
+ appInForegroundEventRecievedEvent() {
26
+ this.dispatchEvent(new CustomEvent('appInForeground'));
27
+ }
28
+ versionResult(result) {
29
+ this.resolveString(result);
30
+ }
31
+ addEventListener(type, callback, options) {
32
+ super.addEventListener(type, callback, options);
33
+ }
34
+ };
package/dist/index.d.ts CHANGED
@@ -1,15 +1,18 @@
1
1
  import { IApp } from './app';
2
2
  import { IPushNotification } from './pushnotification';
3
3
  import { IQrScanner } from './qrscanner';
4
- export default class startiapp {
4
+ declare const startiapp: {
5
5
  /** Basic calls to the app. */
6
- static App: IApp;
6
+ App: IApp;
7
7
  /** The QR- and barcode scanning functionality. */
8
- static QrScanner: IQrScanner;
8
+ QrScanner: IQrScanner;
9
9
  /** Access to push notifications using Firebase. */
10
- static PushNotification: IPushNotification;
11
- /** When all integrations in the app are ready we should call initialize(). */
12
- static onIntegrationsAreReady?: () => void;
10
+ PushNotification: IPushNotification;
13
11
  /** Call this method to initialize the starti.app API integration. This method should be called AFTER all integrations are ready (see onIntegrationsAreReady). */
14
- static initialize(): void;
15
- }
12
+ initialize(): void;
13
+ addEventListener(type: StartiappEvents, callback: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
14
+ dispatchEvent(event: Event): boolean;
15
+ removeEventListener(type: string, callback: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
16
+ };
17
+ declare type StartiappEvents = "integrationsAreReady";
18
+ export default startiapp;
package/dist/index.js CHANGED
@@ -6,25 +6,29 @@ const qrscanner_1 = require("./qrscanner");
6
6
  const untypedWindow = window;
7
7
  untypedWindow.appIntegrationsAreReady = () => {
8
8
  app_1.App.setStartiappIsLoaded();
9
- if (startiapp.onIntegrationsAreReady)
10
- startiapp.onIntegrationsAreReady();
9
+ startiapp.dispatchEvent(new CustomEvent('integrationsAreReady'));
11
10
  };
12
11
  untypedWindow.App = app_1.App;
13
12
  untypedWindow.QrScanner = qrscanner_1.QrScanner;
14
13
  untypedWindow.PushNotification = pushnotification_1.PushNotification;
15
- class startiapp {
14
+ const startiapp = new class extends EventTarget {
15
+ constructor() {
16
+ super(...arguments);
17
+ /** Basic calls to the app. */
18
+ this.App = app_1.App;
19
+ /** The QR- and barcode scanning functionality. */
20
+ this.QrScanner = qrscanner_1.QrScanner;
21
+ /** Access to push notifications using Firebase. */
22
+ this.PushNotification = pushnotification_1.PushNotification;
23
+ }
16
24
  /** Call this method to initialize the starti.app API integration. This method should be called AFTER all integrations are ready (see onIntegrationsAreReady). */
17
- static initialize() {
25
+ initialize() {
18
26
  if (app_1.App.isStartiappLoaded())
19
- // @ts-ignore
20
27
  AppIntegration.webAppIsReady();
21
28
  }
22
- }
29
+ addEventListener(type, callback, options) {
30
+ super.addEventListener(type, callback, options);
31
+ }
32
+ };
23
33
  exports.default = startiapp;
24
- /** Basic calls to the app. */
25
- startiapp.App = app_1.App;
26
- /** The QR- and barcode scanning functionality. */
27
- startiapp.QrScanner = qrscanner_1.QrScanner;
28
- /** Access to push notifications using Firebase. */
29
- startiapp.PushNotification = pushnotification_1.PushNotification;
30
34
  untypedWindow.startiapp = startiapp;
@@ -1,11 +1,11 @@
1
1
  export declare const PushNotification: IPushNotification;
2
+ declare type PushNotificationEvents = "tokenReceived" | "notificationReceived";
2
3
  export interface IPushNotification {
3
- /** Called with the token used to send push notifications to the current device. */
4
- onTokenReceived?: (token: string) => void;
5
- /** Called with the notification that has been received by the mobile. The content of notification is the content that has been sent from the backend. There will also be a special property called appWasLaunchedFromNotification which indicated wether the app entered the foreground because a notification as pressed on the device or wether the app already was in the foreground when the notification was received. */
6
- onNotificationReceived?: (notification: any) => void;
7
4
  /** This method should be called when the user want’s to receive push notifications. */
8
5
  initialize(): Promise<boolean>;
9
6
  /** This method returns the token which should be used to send push notifications. */
10
7
  getLastPublishedToken(): Promise<string>;
8
+ /** Listen for events */
9
+ addEventListener(type: PushNotificationEvents, callback: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
11
10
  }
11
+ export {};
@@ -1,36 +1,34 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PushNotification = void 0;
4
- const PushNotification = class {
5
- static initialize() {
4
+ exports.PushNotification = new class extends EventTarget {
5
+ initialize() {
6
6
  const promise = new Promise((resolve, reject) => {
7
7
  this.resolveBoolean = resolve;
8
- // @ts-ignore
9
8
  PushNotificationIntegration.initialize();
10
9
  });
11
10
  return promise;
12
11
  }
13
- static initializeResult(result) {
12
+ initializeResult(result) {
14
13
  this.resolveBoolean(result);
15
14
  }
16
- static getLastPublishedToken() {
15
+ getLastPublishedToken() {
17
16
  const promise = new Promise((resolve, reject) => {
18
17
  this.resolveString = resolve;
19
- // @ts-ignore
20
18
  PushNotificationIntegration.getLastPublishedToken();
21
19
  });
22
20
  return promise;
23
21
  }
24
- static getLastPublishedTokenResult(token) {
22
+ getLastPublishedTokenResult(token) {
25
23
  this.resolveString(token);
26
24
  }
27
- static tokenReceivedEvent(token) {
28
- if (this.onTokenReceived)
29
- this.onTokenReceived(token);
25
+ tokenReceivedEvent(token) {
26
+ this.dispatchEvent(new CustomEvent('tokenReceived', { detail: token }));
30
27
  }
31
- static notificationReceivedEvent(notification) {
32
- if (this.onNotificationReceived)
33
- this.onNotificationReceived(notification);
28
+ notificationReceivedEvent(notification) {
29
+ this.dispatchEvent(new CustomEvent('notificationReceived', { detail: notification }));
30
+ }
31
+ addEventListener(type, callback, options) {
32
+ super.addEventListener(type, callback, options);
34
33
  }
35
34
  };
36
- exports.PushNotification = PushNotification;
package/dist/qrscanner.js CHANGED
@@ -1,17 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.QrScanner = void 0;
4
- const QrScanner = class {
5
- static scan() {
4
+ exports.QrScanner = new class extends EventTarget {
5
+ scan() {
6
6
  const promise = new Promise((resolve, reject) => {
7
7
  this.resolve = resolve;
8
8
  try {
9
- const qrScannerIntegration = window.QrScannerIntegration;
10
- if (!qrScannerIntegration) {
9
+ if (!QrScannerIntegration) {
11
10
  resolve('Scanner virker kun i starti.app');
12
11
  return;
13
12
  }
14
- qrScannerIntegration.startQrCodeScanner();
13
+ QrScannerIntegration.startQrCodeScanner();
15
14
  }
16
15
  catch (e) {
17
16
  reject(e);
@@ -19,8 +18,7 @@ const QrScanner = class {
19
18
  });
20
19
  return promise;
21
20
  }
22
- static qrResultRecievedEvent(message) {
21
+ qrResultRecievedEvent(message) {
23
22
  this.resolve(message);
24
23
  }
25
24
  };
26
- exports.QrScanner = QrScanner;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starti.app",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
4
4
  "description": "Use this package for easy communication with the starti.app API.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -21,4 +21,4 @@
21
21
  "build:prod": "webpack --mode=production --node-env=production",
22
22
  "watch": "webpack --watch"
23
23
  }
24
- }
24
+ }
package/umd/main.js CHANGED
@@ -1 +1 @@
1
- !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var i=t();for(var n in i)("object"==typeof exports?exports:e)[n]=i[n]}}(self,(()=>(()=>{"use strict";var e={752:(e,t)=>{var i;Object.defineProperty(t,"__esModule",{value:!0}),t.App=void 0,t.App=((i=class{static setStartiappIsLoaded(){this.startiappIsLoaded=!0}static isStartiappLoaded(){return this.startiappIsLoaded}static setAppUrl(e){AppIntegration.setAppUrl(e)}static version(){return new Promise(((e,t)=>{this.resolveString=e,AppIntegration.version()}))}static appInForegroundEventRecievedEvent(){this.onAppInForeground&&this.onAppInForeground()}static versionResult(e){this.resolveString(e)}}).startiappIsLoaded=!1,i)},681:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PushNotification=void 0,t.PushNotification=class{static initialize(){return new Promise(((e,t)=>{this.resolveBoolean=e,PushNotificationIntegration.initialize()}))}static initializeResult(e){this.resolveBoolean(e)}static getLastPublishedToken(){return new Promise(((e,t)=>{this.resolveString=e,PushNotificationIntegration.getLastPublishedToken()}))}static getLastPublishedTokenResult(e){this.resolveString(e)}static tokenReceivedEvent(e){this.onTokenReceived&&this.onTokenReceived(e)}static notificationReceivedEvent(e){this.onNotificationReceived&&this.onNotificationReceived(e)}}},952:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.QrScanner=void 0,t.QrScanner=class{static scan(){return new Promise(((e,t)=>{this.resolve=e;try{const t=window.QrScannerIntegration;if(!t)return void e("Scanner virker kun i starti.app");t.startQrCodeScanner()}catch(e){t(e)}}))}static qrResultRecievedEvent(e){this.resolve(e)}}}},t={};function i(n){var o=t[n];if(void 0!==o)return o.exports;var r=t[n]={exports:{}};return e[n](r,r.exports,i),r.exports}var n={};return(()=>{var e=n;Object.defineProperty(e,"__esModule",{value:!0});const t=i(752),o=i(681),r=i(952),s=window;s.appIntegrationsAreReady=()=>{t.App.setStartiappIsLoaded(),a.onIntegrationsAreReady&&a.onIntegrationsAreReady()},s.App=t.App,s.QrScanner=r.QrScanner,s.PushNotification=o.PushNotification;class a{static initialize(){t.App.isStartiappLoaded()&&AppIntegration.webAppIsReady()}}e.default=a,a.App=t.App,a.QrScanner=r.QrScanner,a.PushNotification=o.PushNotification,s.startiapp=a})(),n})()));
1
+ !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var i in n)("object"==typeof exports?exports:e)[i]=n[i]}}(self,(()=>(()=>{"use strict";var e={752:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.App=void 0,t.App=new class extends EventTarget{constructor(){super(...arguments),this.startiappIsLoaded=!1}setStartiappIsLoaded(){this.startiappIsLoaded=!0}isStartiappLoaded(){return this.startiappIsLoaded}setAppUrl(e){AppIntegration.setAppUrl(e)}version(){return new Promise(((e,t)=>{this.resolveString=e,AppIntegration.version()}))}appInForegroundEventRecievedEvent(){this.dispatchEvent(new CustomEvent("appInForeground"))}versionResult(e){this.resolveString(e)}addEventListener(e,t,n){super.addEventListener(e,t,n)}}},681:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PushNotification=void 0,t.PushNotification=new class extends EventTarget{initialize(){return new Promise(((e,t)=>{this.resolveBoolean=e,PushNotificationIntegration.initialize()}))}initializeResult(e){this.resolveBoolean(e)}getLastPublishedToken(){return new Promise(((e,t)=>{this.resolveString=e,PushNotificationIntegration.getLastPublishedToken()}))}getLastPublishedTokenResult(e){this.resolveString(e)}tokenReceivedEvent(e){this.dispatchEvent(new CustomEvent("tokenReceived",{detail:e}))}notificationReceivedEvent(e){this.dispatchEvent(new CustomEvent("notificationReceived",{detail:e}))}addEventListener(e,t,n){super.addEventListener(e,t,n)}}},952:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.QrScanner=void 0,t.QrScanner=new class extends EventTarget{scan(){return new Promise(((e,t)=>{this.resolve=e;try{if(!QrScannerIntegration)return void e("Scanner virker kun i starti.app");QrScannerIntegration.startQrCodeScanner()}catch(e){t(e)}}))}qrResultRecievedEvent(e){this.resolve(e)}}}},t={};function n(i){var r=t[i];if(void 0!==r)return r.exports;var s=t[i]={exports:{}};return e[i](s,s.exports,n),s.exports}var i={};return(()=>{var e=i;Object.defineProperty(e,"__esModule",{value:!0});const t=n(752),r=n(681),s=n(952),o=window;o.appIntegrationsAreReady=()=>{t.App.setStartiappIsLoaded(),a.dispatchEvent(new CustomEvent("integrationsAreReady"))},o.App=t.App,o.QrScanner=s.QrScanner,o.PushNotification=r.PushNotification;const a=new class extends EventTarget{constructor(){super(...arguments),this.App=t.App,this.QrScanner=s.QrScanner,this.PushNotification=r.PushNotification}initialize(){t.App.isStartiappLoaded()&&AppIntegration.webAppIsReady()}addEventListener(e,t,n){super.addEventListener(e,t,n)}};e.default=a,o.startiapp=a})(),i})()));