idpay-b2b-sdk 0.0.21 → 0.0.22-beta.2

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/index.esm.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./src/index";
@@ -37,7 +37,7 @@ const _createStyles = ({
37
37
  };
38
38
  const _getEnvHost = (env = ENV_PROD) => _HOSTS[env];
39
39
  const init = async options => {
40
- console.log('init', options);
40
+ const token = options?.token;
41
41
  const host = options?.useCurrentOrigin ? window.location.origin : _getEnvHost(options?.env);
42
42
  await _createScript({
43
43
  host
@@ -49,7 +49,8 @@ const init = async options => {
49
49
  host
50
50
  });
51
51
  IDPaySDKAssets.clientBoxControl.create({
52
- host
52
+ host,
53
+ token
53
54
  });
54
55
  }
55
56
  _initialized = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "idpay-b2b-sdk",
3
- "version": "0.0.21",
3
+ "version": "0.0.22-beta.2",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -8,9 +8,9 @@
8
8
  "directory": "libs/pay/sdk/idpay-b2b-sdk"
9
9
  },
10
10
  "publishConfig": {
11
- "registry": "https://registry.npmjs.org"
11
+ "registry": "https://registry.npmjs.org",
12
+ "tag": "beta"
12
13
  },
13
- "module": "./index.js",
14
- "main": "./index.js",
15
- "types": "./src/index.d.ts"
14
+ "module": "./index.esm.js",
15
+ "main": "./index.esm.js"
16
16
  }
package/index.cjs DELETED
@@ -1,140 +0,0 @@
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 _await(value, then, direct) {
8
- if (direct) {
9
- return then ? then(value) : value;
10
- }
11
- if (!value || !value.then) {
12
- value = Promise.resolve(value);
13
- }
14
- return then ? value.then(then) : value;
15
- }
16
- /* eslint-disable no-undef */
17
-
18
- let _type;
19
- function _invoke(body, then) {
20
- var result = body();
21
- if (result && result.then) {
22
- return result.then(then);
23
- }
24
- return then(result);
25
- }
26
- let _initialized = false;
27
- function _async(f) {
28
- return function () {
29
- for (var args = [], i = 0; i < arguments.length; i++) {
30
- args[i] = arguments[i];
31
- }
32
- try {
33
- return Promise.resolve(f.apply(this, args));
34
- } catch (e) {
35
- return Promise.reject(e);
36
- }
37
- };
38
- }
39
- let _openWhileInitializing = false;
40
- const TYPE__IFRAME = 'IFRAME';
41
- const ENV_DEV = 'dev';
42
- const ENV_UAT = 'uat';
43
- const ENV_PROD = 'prod';
44
- const _HOSTS = {
45
- [ENV_DEV]: 'https://idpay-dev.unico.io',
46
- [ENV_UAT]: 'https://idpay-uat.unico.io',
47
- [ENV_PROD]: 'https://idpay.unico.io'
48
- };
49
- const _createScript = ({
50
- host
51
- }) => {
52
- const script = document.createElement('script');
53
- script.src = `${host}/sdk-assets/index.js`;
54
- const prmScript = new Promise(resolve => {
55
- script.onload = resolve;
56
- });
57
- document.body.appendChild(script);
58
- return Promise.all([prmScript]);
59
- };
60
- const _createStyles = ({
61
- host
62
- }) => {
63
- const style = document.createElement('link');
64
- style.setAttribute('href', `${host}/sdk-assets/assets/styles.css`);
65
- style.setAttribute('rel', 'stylesheet');
66
- const prmStyle = new Promise(resolve => {
67
- style.onload = resolve;
68
- });
69
- document.head.appendChild(style);
70
- return Promise.all([prmStyle]);
71
- };
72
- const _getEnvHost = (env = ENV_PROD) => _HOSTS[env];
73
- const init = _async(function (options) {
74
- console.log('init', options);
75
- const host = options?.useCurrentOrigin ? window.location.origin : _getEnvHost(options?.env);
76
- return _await(_createScript({
77
- host
78
- }), function () {
79
- IDPaySDKAssets.trackEvent(IDPaySDKAssets.EVENT_TYPES.INITIALIZE);
80
- _type = options?.type;
81
- return _invoke(function () {
82
- if (_type === TYPE__IFRAME) {
83
- return _await(_createStyles({
84
- host
85
- }), function () {
86
- IDPaySDKAssets.clientBoxControl.create({
87
- host
88
- });
89
- });
90
- }
91
- }, function () {
92
- _initialized = true;
93
- if (_openWhileInitializing) {
94
- startPayFlow(_openWhileInitializing);
95
- }
96
- });
97
- });
98
- });
99
- const startPayFlow = ({
100
- transactionId,
101
- token,
102
- onFinish
103
- }) => {
104
- console.log('startPayFlow', {
105
- transactionId,
106
- token,
107
- onFinish
108
- });
109
- if (!_initialized) {
110
- _openWhileInitializing = {
111
- transactionId,
112
- token,
113
- onFinish
114
- };
115
- return;
116
- }
117
- IDPaySDKAssets.trackEvent(IDPaySDKAssets.EVENT_TYPES.START_FLOW, {
118
- transactionId,
119
- token
120
- });
121
- if (_type === TYPE__IFRAME) {
122
- IDPaySDKAssets.clientBoxControl.open({
123
- transactionId,
124
- token,
125
- onFinish
126
- });
127
- } else {
128
- IDPaySDKAssets.clientBoxControl.redirect(transactionId, token);
129
- }
130
- };
131
- const IDPaySDK = {
132
- init,
133
- open: startPayFlow
134
- };
135
-
136
- exports.IDPaySDK = IDPaySDK;
137
-
138
- Object.defineProperty(exports, '__esModule', { value: true });
139
-
140
- }));