idpay-b2b-sdk 0.0.17 → 0.0.19

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 (3) hide show
  1. package/index.cjs +23 -14
  2. package/index.js +18 -7
  3. package/package.json +1 -1
package/index.cjs CHANGED
@@ -4,16 +4,14 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.IdpayB2bSdk = {}));
5
5
  })(this, (function (exports) { 'use strict';
6
6
 
7
- function _call(body, then, direct) {
7
+ function _await(value, then, direct) {
8
8
  if (direct) {
9
- return then ? then(body()) : body();
9
+ return then ? then(value) : value;
10
10
  }
11
- try {
12
- var result = Promise.resolve(body());
13
- return then ? result.then(then) : result;
14
- } catch (e) {
15
- return Promise.reject(e);
11
+ if (!value || !value.then) {
12
+ value = Promise.resolve(value);
16
13
  }
14
+ return then ? value.then(then) : value;
17
15
  }
18
16
  /* eslint-disable no-undef */
19
17
 
@@ -40,18 +38,22 @@
40
38
  }
41
39
  let _openWhileInitializing = false;
42
40
  const TYPE__IFRAME = 'IFRAME';
43
- const _createScript = () => {
41
+ const _createScript = ({
42
+ host
43
+ }) => {
44
44
  const script = document.createElement('script');
45
- script.src = 'https://idpay.unico.io/sdk-assets/index.js';
45
+ script.src = `${host}/sdk-assets/index.js`;
46
46
  const prmScript = new Promise(resolve => {
47
47
  script.onload = resolve;
48
48
  });
49
49
  document.body.appendChild(script);
50
50
  return Promise.all([prmScript]);
51
51
  };
52
- const _createStyles = () => {
52
+ const _createStyles = ({
53
+ host
54
+ }) => {
53
55
  const style = document.createElement('link');
54
- style.setAttribute('href', 'https://idpay.unico.io/sdk-assets/assets/styles.css');
56
+ style.setAttribute('href', `${host}/sdk-assets/assets/styles.css`);
55
57
  style.setAttribute('rel', 'stylesheet');
56
58
  const prmStyle = new Promise(resolve => {
57
59
  style.onload = resolve;
@@ -61,13 +63,20 @@
61
63
  };
62
64
  const init = _async(function (options) {
63
65
  console.log('init', options);
64
- return _call(_createScript, function () {
66
+ const host = options?.useCurrentOrigin ? window.location.origin : 'https://idpay.unico.io';
67
+ return _await(_createScript({
68
+ host
69
+ }), function () {
65
70
  IDPaySDKAssets.trackEvent(IDPaySDKAssets.EVENT_TYPES.INITIALIZE);
66
71
  _type = options?.type;
67
72
  return _invoke(function () {
68
73
  if (_type === TYPE__IFRAME) {
69
- return _call(_createStyles, function () {
70
- IDPaySDKAssets.clientBoxControl.create();
74
+ return _await(_createStyles({
75
+ host
76
+ }), function () {
77
+ IDPaySDKAssets.clientBoxControl.create({
78
+ host
79
+ });
71
80
  });
72
81
  }
73
82
  }, function () {
package/index.js CHANGED
@@ -4,18 +4,22 @@ let _type;
4
4
  let _initialized = false;
5
5
  let _openWhileInitializing = false;
6
6
  const TYPE__IFRAME = 'IFRAME';
7
- const _createScript = () => {
7
+ const _createScript = ({
8
+ host
9
+ }) => {
8
10
  const script = document.createElement('script');
9
- script.src = 'https://idpay.unico.io/sdk-assets/index.js';
11
+ script.src = `${host}/sdk-assets/index.js`;
10
12
  const prmScript = new Promise(resolve => {
11
13
  script.onload = resolve;
12
14
  });
13
15
  document.body.appendChild(script);
14
16
  return Promise.all([prmScript]);
15
17
  };
16
- const _createStyles = () => {
18
+ const _createStyles = ({
19
+ host
20
+ }) => {
17
21
  const style = document.createElement('link');
18
- style.setAttribute('href', 'https://idpay.unico.io/sdk-assets/assets/styles.css');
22
+ style.setAttribute('href', `${host}/sdk-assets/assets/styles.css`);
19
23
  style.setAttribute('rel', 'stylesheet');
20
24
  const prmStyle = new Promise(resolve => {
21
25
  style.onload = resolve;
@@ -25,12 +29,19 @@ const _createStyles = () => {
25
29
  };
26
30
  const init = async options => {
27
31
  console.log('init', options);
28
- await _createScript();
32
+ const host = options?.useCurrentOrigin ? window.location.origin : 'https://idpay.unico.io';
33
+ await _createScript({
34
+ host
35
+ });
29
36
  IDPaySDKAssets.trackEvent(IDPaySDKAssets.EVENT_TYPES.INITIALIZE);
30
37
  _type = options?.type;
31
38
  if (_type === TYPE__IFRAME) {
32
- await _createStyles();
33
- IDPaySDKAssets.clientBoxControl.create();
39
+ await _createStyles({
40
+ host
41
+ });
42
+ IDPaySDKAssets.clientBoxControl.create({
43
+ host
44
+ });
34
45
  }
35
46
  _initialized = true;
36
47
  if (_openWhileInitializing) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "idpay-b2b-sdk",
3
- "version": "0.0.17",
3
+ "version": "0.0.19",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",