idpay-b2b-sdk 0.0.14 → 0.0.17

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 (4) hide show
  1. package/index.cjs +117 -0
  2. package/index.js +72 -1
  3. package/package.json +4 -3
  4. package/README.md +0 -11
package/index.cjs ADDED
@@ -0,0 +1,117 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.IdpayB2bSdk = {}));
5
+ })(this, (function (exports) { 'use strict';
6
+
7
+ function _call(body, then, direct) {
8
+ if (direct) {
9
+ return then ? then(body()) : body();
10
+ }
11
+ try {
12
+ var result = Promise.resolve(body());
13
+ return then ? result.then(then) : result;
14
+ } catch (e) {
15
+ return Promise.reject(e);
16
+ }
17
+ }
18
+ /* eslint-disable no-undef */
19
+
20
+ let _type;
21
+ function _invoke(body, then) {
22
+ var result = body();
23
+ if (result && result.then) {
24
+ return result.then(then);
25
+ }
26
+ return then(result);
27
+ }
28
+ let _initialized = false;
29
+ function _async(f) {
30
+ return function () {
31
+ for (var args = [], i = 0; i < arguments.length; i++) {
32
+ args[i] = arguments[i];
33
+ }
34
+ try {
35
+ return Promise.resolve(f.apply(this, args));
36
+ } catch (e) {
37
+ return Promise.reject(e);
38
+ }
39
+ };
40
+ }
41
+ let _openWhileInitializing = false;
42
+ const TYPE__IFRAME = 'IFRAME';
43
+ const _createScript = () => {
44
+ const script = document.createElement('script');
45
+ script.src = 'https://idpay.unico.io/sdk-assets/index.js';
46
+ const prmScript = new Promise(resolve => {
47
+ script.onload = resolve;
48
+ });
49
+ document.body.appendChild(script);
50
+ return Promise.all([prmScript]);
51
+ };
52
+ const _createStyles = () => {
53
+ const style = document.createElement('link');
54
+ style.setAttribute('href', 'https://idpay.unico.io/sdk-assets/assets/styles.css');
55
+ style.setAttribute('rel', 'stylesheet');
56
+ const prmStyle = new Promise(resolve => {
57
+ style.onload = resolve;
58
+ });
59
+ document.head.appendChild(style);
60
+ return Promise.all([prmStyle]);
61
+ };
62
+ const init = _async(function (options) {
63
+ console.log('init', options);
64
+ return _call(_createScript, function () {
65
+ IDPaySDKAssets.trackEvent(IDPaySDKAssets.EVENT_TYPES.INITIALIZE);
66
+ _type = options?.type;
67
+ return _invoke(function () {
68
+ if (_type === TYPE__IFRAME) {
69
+ return _call(_createStyles, function () {
70
+ IDPaySDKAssets.clientBoxControl.create();
71
+ });
72
+ }
73
+ }, function () {
74
+ _initialized = true;
75
+ if (_openWhileInitializing) {
76
+ startPayFlow(_openWhileInitializing);
77
+ }
78
+ });
79
+ });
80
+ });
81
+ const startPayFlow = ({
82
+ transactionId,
83
+ onFinish
84
+ }) => {
85
+ console.log('startPayFlow', {
86
+ transactionId,
87
+ onFinish
88
+ });
89
+ if (!_initialized) {
90
+ _openWhileInitializing = {
91
+ transactionId,
92
+ onFinish
93
+ };
94
+ return;
95
+ }
96
+ IDPaySDKAssets.trackEvent(IDPaySDKAssets.EVENT_TYPES.START_FLOW, {
97
+ transactionId
98
+ });
99
+ if (_type === TYPE__IFRAME) {
100
+ IDPaySDKAssets.clientBoxControl.open({
101
+ transactionId,
102
+ onFinish
103
+ });
104
+ } else {
105
+ IDPaySDKAssets.clientBoxControl.redirect(transactionId);
106
+ }
107
+ };
108
+ const IDPaySDK = {
109
+ init,
110
+ open: startPayFlow
111
+ };
112
+
113
+ exports.IDPaySDK = IDPaySDK;
114
+
115
+ Object.defineProperty(exports, '__esModule', { value: true });
116
+
117
+ }));
package/index.js CHANGED
@@ -1 +1,72 @@
1
- var o,i=!1,n=!1,r="IFRAME",a=()=>{let e=document.createElement("script");e.src="https://idpay.unico.io/sdk-assets/index.js";let t=new Promise(s=>{e.onload=s});return document.body.appendChild(e),Promise.all([t])},c=()=>{let e=document.createElement("link");e.setAttribute("href","https://idpay.unico.io/sdk-assets/assets/styles.css"),e.setAttribute("rel","stylesheet");let t=new Promise(s=>{e.onload=s});return document.head.appendChild(e),Promise.all([t])},p=async e=>{await a(),IDPaySDKAssets.trackEvent(IDPaySDKAssets.EVENT_TYPES.INITIALIZE),o=e?.type,o===r&&(await c(),IDPaySDKAssets.clientBoxControl.create()),i=!0,n&&l(n)},l=({transactionId:e,onFinish:t})=>{if(!i){n={transactionId:e,onFinish:t};return}IDPaySDKAssets.trackEvent(IDPaySDKAssets.EVENT_TYPES.START_FLOW,{transactionId:e}),o===r?IDPaySDKAssets.clientBoxControl.open({transactionId:e,onFinish:t}):IDPaySDKAssets.clientBoxControl.redirect(e)},y={init:p,open:l};export{y as IDPaySDK};
1
+ /* eslint-disable no-undef */
2
+
3
+ let _type;
4
+ let _initialized = false;
5
+ let _openWhileInitializing = false;
6
+ const TYPE__IFRAME = 'IFRAME';
7
+ const _createScript = () => {
8
+ const script = document.createElement('script');
9
+ script.src = 'https://idpay.unico.io/sdk-assets/index.js';
10
+ const prmScript = new Promise(resolve => {
11
+ script.onload = resolve;
12
+ });
13
+ document.body.appendChild(script);
14
+ return Promise.all([prmScript]);
15
+ };
16
+ const _createStyles = () => {
17
+ const style = document.createElement('link');
18
+ style.setAttribute('href', 'https://idpay.unico.io/sdk-assets/assets/styles.css');
19
+ style.setAttribute('rel', 'stylesheet');
20
+ const prmStyle = new Promise(resolve => {
21
+ style.onload = resolve;
22
+ });
23
+ document.head.appendChild(style);
24
+ return Promise.all([prmStyle]);
25
+ };
26
+ const init = async options => {
27
+ console.log('init', options);
28
+ await _createScript();
29
+ IDPaySDKAssets.trackEvent(IDPaySDKAssets.EVENT_TYPES.INITIALIZE);
30
+ _type = options?.type;
31
+ if (_type === TYPE__IFRAME) {
32
+ await _createStyles();
33
+ IDPaySDKAssets.clientBoxControl.create();
34
+ }
35
+ _initialized = true;
36
+ if (_openWhileInitializing) {
37
+ startPayFlow(_openWhileInitializing);
38
+ }
39
+ };
40
+ const startPayFlow = ({
41
+ transactionId,
42
+ onFinish
43
+ }) => {
44
+ console.log('startPayFlow', {
45
+ transactionId,
46
+ onFinish
47
+ });
48
+ if (!_initialized) {
49
+ _openWhileInitializing = {
50
+ transactionId,
51
+ onFinish
52
+ };
53
+ return;
54
+ }
55
+ IDPaySDKAssets.trackEvent(IDPaySDKAssets.EVENT_TYPES.START_FLOW, {
56
+ transactionId
57
+ });
58
+ if (_type === TYPE__IFRAME) {
59
+ IDPaySDKAssets.clientBoxControl.open({
60
+ transactionId,
61
+ onFinish
62
+ });
63
+ } else {
64
+ IDPaySDKAssets.clientBoxControl.redirect(transactionId);
65
+ }
66
+ };
67
+ const IDPaySDK = {
68
+ init,
69
+ open: startPayFlow
70
+ };
71
+
72
+ export { IDPaySDK };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "idpay-b2b-sdk",
3
- "version": "0.0.14",
3
+ "version": "0.0.17",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -10,6 +10,7 @@
10
10
  "publishConfig": {
11
11
  "registry": "https://registry.npmjs.org"
12
12
  },
13
- "module": "index.js",
14
- "main": "index.js"
13
+ "module": "./index.js",
14
+ "main": "./index.js",
15
+ "types": "./src/index.d.ts"
15
16
  }
package/README.md DELETED
@@ -1,11 +0,0 @@
1
- # idpay-b2b-sdk
2
-
3
- This library was generated with [Nx](https://nx.dev).
4
-
5
- ## Building
6
-
7
- Run `nx build idpay-b2b-sdk` to build the library.
8
-
9
- ## Running unit tests
10
-
11
- Run `nx test idpay-b2b-sdk` to execute the unit tests via [Jest](https://jestjs.io).