idpay-b2b-sdk 0.0.2 → 0.0.4

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.js ADDED
@@ -0,0 +1 @@
1
+ import{EVENT_TYPES as r,trackEvent as i,clientBoxControl as n}from"https://idpay.unico.io/sdk-assets/index.js";var l=null,c="IFRAME",p=()=>{let t=document.createElement("link");t.setAttribute("href","https://fonts.googleapis.com/css2?family=Atkinson+Hyperlegible:wght@400;700&display=swap"),t.setAttribute("rel","stylesheet");let s=new Promise(o=>{t.onload=o}),e=document.createElement("link");e.setAttribute("href","https://idpay.unico.io/sdk-assets/assets/styles.css"),e.setAttribute("rel","stylesheet");let a=new Promise(o=>{e.onload=o});return document.head.appendChild(t),document.head.appendChild(e),Promise.all([s,a])},m=async t=>{i(r.INITIALIZE),l=t?.type,l===c&&(await p(),n.create())},y=({transactionId:t,onFinish:s})=>{i(r.START_FLOW,{transactionId:t}),l===c?n.open({transactionId:t,onFinish:s}):n.redirect(t)},h={init:m,start:y};export{h as IDPaySDK};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "idpay-b2b-sdk",
3
- "version": "0.0.2",
4
- "type": "commonjs",
3
+ "version": "0.0.4",
4
+ "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/acesso-io/transactional-management.git",
@@ -9,5 +9,7 @@
9
9
  },
10
10
  "publishConfig": {
11
11
  "registry": "https://registry.npmjs.org"
12
- }
12
+ },
13
+ "module": "index.js",
14
+ "main": "index.js"
13
15
  }
package/.eslintrc.json DELETED
@@ -1,18 +0,0 @@
1
- {
2
- "extends": ["../../../../.eslintrc.json"],
3
- "ignorePatterns": ["!**/*"],
4
- "overrides": [
5
- {
6
- "files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
7
- "rules": {}
8
- },
9
- {
10
- "files": ["*.ts", "*.tsx"],
11
- "rules": {}
12
- },
13
- {
14
- "files": ["*.js", "*.jsx"],
15
- "rules": {}
16
- }
17
- ]
18
- }
package/jest.config.js DELETED
@@ -1,14 +0,0 @@
1
- /* eslint-disable */
2
- module.exports = {
3
- displayName: 'idpay-b2b-sdk',
4
- preset: '../../../jest.preset.js',
5
- transform: {
6
- '^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/idpay-b2b-sdk/tsconfig.spec.json' }],
7
- },
8
- moduleFileExtensions: ['ts', 'js', 'html'],
9
- rootDir: '..',
10
- moduleNameMapper: {
11
- "https://idpay.unico.io/sdk-assets/index.js": "<rootDir>/sdk-assets/src/index.js"
12
- },
13
- coverageDirectory: '../../../coverage/libs/pay/sdk/idpay-b2b-sdk',
14
- };
package/project.json DELETED
@@ -1,48 +0,0 @@
1
- {
2
- "name": "idpay-b2b-sdk",
3
- "$schema": "../../../../node_modules/nx/schemas/project-schema.json",
4
- "sourceRoot": "libs/pay/sdk/idpay-b2b-sdk/src",
5
- "projectType": "library",
6
- "targets": {
7
- "build": {
8
- "executor": "@nrwl/esbuild:esbuild",
9
- "outputs": ["{options.outputPath}"],
10
- "options": {
11
- "outputPath": "dist/libs/pay/sdk/idpay-b2b-sdk",
12
- "main": "libs/pay/sdk/idpay-b2b-sdk/src/index.js",
13
- "tsConfig": "libs/pay/sdk/idpay-b2b-sdk/tsconfig.lib.json",
14
- "assets": ["libs/pay/sdk/idpay-b2b-sdk/*.md"],
15
- "minify": true
16
- }
17
- },
18
- "publish": {
19
- "executor": "nx:run-commands",
20
- "options": {
21
- "command": "npm publish dist/libs/pay/sdk/idpay-b2b-sdk"
22
- },
23
- "dependsOn": ["build"]
24
- },
25
- "lint": {
26
- "executor": "@nrwl/linter:eslint",
27
- "outputs": ["{options.outputFile}"],
28
- "options": {
29
- "lintFilePatterns": ["libs/pay/sdk/idpay-b2b-sdk/**/*.js"]
30
- }
31
- },
32
- "test": {
33
- "executor": "@nrwl/jest:jest",
34
- "outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
35
- "options": {
36
- "jestConfig": "libs/pay/sdk/idpay-b2b-sdk/jest.config.js",
37
- "passWithNoTests": true
38
- },
39
- "configurations": {
40
- "ci": {
41
- "ci": true,
42
- "codeCoverage": true
43
- }
44
- }
45
- }
46
- },
47
- "tags": []
48
- }
package/src/index.js DELETED
@@ -1 +0,0 @@
1
- export * from './lib';
package/src/lib/index.js DELETED
@@ -1,57 +0,0 @@
1
- import {
2
- EVENT_TYPES,
3
- trackEvent,
4
- clientBoxControl
5
- } from 'https://idpay.unico.io/sdk-assets/index.js';
6
-
7
- let _type = null;
8
-
9
- const TYPE__IFRAME = 'IFRAME';
10
-
11
- const _createStyles = () => {
12
- const font = document.createElement('link');
13
- font.setAttribute('href', 'https://fonts.googleapis.com/css2?family=Atkinson+Hyperlegible:wght@400;700&display=swap');
14
- font.setAttribute('rel', 'stylesheet');
15
-
16
- const prmFont = new Promise(resolve => {
17
- font.onload = resolve;
18
- });
19
-
20
- const style = document.createElement('link');
21
- style.setAttribute('href', 'https://idpay.unico.io/sdk-assets/assets/styles.css');
22
- style.setAttribute('rel', 'stylesheet');
23
-
24
- const prmStyle = new Promise(resolve => {
25
- style.onload = resolve;
26
- });
27
-
28
- document.head.appendChild(font);
29
- document.head.appendChild(style);
30
-
31
- return Promise.all([prmFont, prmStyle]);
32
- }
33
-
34
- const init = async options => {
35
- trackEvent(EVENT_TYPES.INITIALIZE);
36
-
37
- _type = options?.type;
38
-
39
- if (_type === TYPE__IFRAME) {
40
- await _createStyles();
41
-
42
- clientBoxControl.create();
43
- }
44
- }
45
-
46
- const startPayFlow = ({ transactionId, onFinish }) => {
47
- trackEvent(EVENT_TYPES.START_FLOW, { transactionId });
48
-
49
- if (_type === TYPE__IFRAME) {
50
- clientBoxControl.open({ transactionId, onFinish });
51
- }
52
- else {
53
- clientBoxControl.redirect(transactionId);
54
- }
55
- }
56
-
57
- export const IDPaySDK = { init, start: startPayFlow };
@@ -1,72 +0,0 @@
1
- /* eslint-disable no-undef */
2
- import { waitFor } from '@testing-library/react';
3
- import { IDPaySDK } from '.';
4
- import {
5
- clientBoxControl,
6
- trackEvent,
7
- } from 'https://idpay.unico.io/sdk-assets/index.js';
8
-
9
- jest.mock('https://idpay.unico.io/sdk-assets/index.js', () => ({
10
- EVENT_TYPES: {
11
- INITIALIZE: 'FAKE_INITIALIZE'
12
- },
13
- trackEvent: jest.fn(),
14
- clientBoxControl: {
15
- create: jest.fn(),
16
- }
17
- }));
18
-
19
- const create = jest.fn();
20
-
21
- describe('IDPay B2B SDK', () => {
22
-
23
- beforeEach(() => {
24
- clientBoxControl.create = create;
25
- });
26
-
27
- describe('init', () => {
28
-
29
- it('should track event initialize, create styles and call clientBoxControl create correctly', async () => {
30
- const setAttributeFn = jest.fn();
31
-
32
- const fakeFont = {
33
- src: '',
34
- id: 'font',
35
- setAttribute: setAttributeFn,
36
- };
37
-
38
- const fakeStyle = {
39
- src: '',
40
- id: 'style',
41
- setAttribute: setAttributeFn,
42
- };
43
-
44
- const createElementSpy = jest.spyOn(document, 'createElement')
45
- .mockReturnValueOnce(fakeFont)
46
- .mockReturnValueOnce(fakeStyle);
47
-
48
- const appendChildSpy = jest.spyOn(document.head, 'appendChild').mockImplementation(() => {/* */});
49
-
50
- IDPaySDK.init({ type: 'IFRAME' });
51
-
52
- await waitFor(() => {
53
- expect(trackEvent).toHaveBeenCalledWith('FAKE_INITIALIZE');
54
-
55
- /* font */
56
- expect(createElementSpy).toHaveBeenNthCalledWith(1, 'link');
57
- expect(setAttributeFn).toHaveBeenNthCalledWith(1, 'href', 'https://fonts.googleapis.com/css2?family=Atkinson+Hyperlegible:wght@400;700&display=swap');
58
- expect(setAttributeFn).toHaveBeenNthCalledWith(2, 'rel', 'stylesheet');
59
-
60
- /* style */
61
- expect(createElementSpy).toHaveBeenNthCalledWith(2, 'link');
62
- expect(setAttributeFn).toHaveBeenNthCalledWith(3, 'href', 'https://idpay.unico.io/sdk-assets/assets/styles.css');
63
- expect(setAttributeFn).toHaveBeenNthCalledWith(4, 'rel', 'stylesheet');
64
-
65
- expect(appendChildSpy).toHaveBeenNthCalledWith(1, fakeFont);
66
- expect(appendChildSpy).toHaveBeenNthCalledWith(2, fakeStyle);
67
- });
68
- });
69
-
70
- });
71
-
72
- });
package/tsconfig.json DELETED
@@ -1,23 +0,0 @@
1
- {
2
- "extends": "../../../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "module": "commonjs",
5
- "allowJs": true,
6
- "forceConsistentCasingInFileNames": true,
7
- "strict": true,
8
- "noImplicitOverride": true,
9
- "noPropertyAccessFromIndexSignature": true,
10
- "noImplicitReturns": true,
11
- "noFallthroughCasesInSwitch": true
12
- },
13
- "files": [],
14
- "include": [],
15
- "references": [
16
- {
17
- "path": "./tsconfig.lib.json"
18
- },
19
- {
20
- "path": "./tsconfig.spec.json"
21
- }
22
- ]
23
- }
package/tsconfig.lib.json DELETED
@@ -1,16 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "../../../../dist/out-tsc",
5
- "declaration": true,
6
- "types": ["node"]
7
- },
8
- "include": ["src/**/*.ts", "src/**/*.js"],
9
- "exclude": [
10
- "jest.config.ts",
11
- "src/**/*.spec.ts",
12
- "src/**/*.test.ts",
13
- "src/**/*.spec.js",
14
- "src/**/*.test.js"
15
- ]
16
- }
@@ -1,14 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "../../../../dist/out-tsc",
5
- "module": "commonjs",
6
- "types": ["jest", "node"]
7
- },
8
- "include": [
9
- "jest.config.ts",
10
- "src/**/*.test.ts",
11
- "src/**/*.spec.ts",
12
- "src/**/*.d.ts"
13
- ]
14
- }