@notabene/javascript-sdk 1.10.6 → 1.10.14

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/.editorconfig ADDED
@@ -0,0 +1,10 @@
1
+ root = true
2
+
3
+ [*]
4
+ end_of_line = lf
5
+ insert_final_newline = true
6
+
7
+ [*.{js,json,yml}]
8
+ charset = utf-8
9
+ indent_style = space
10
+ indent_size = 2
package/.eslintignore ADDED
@@ -0,0 +1,3 @@
1
+ dist
2
+ .eslintrc.js
3
+ jest.config.js
package/.eslintrc.js ADDED
@@ -0,0 +1,13 @@
1
+ module.exports = {
2
+ root: true,
3
+ parser: '@typescript-eslint/parser',
4
+ plugins: ['@typescript-eslint'],
5
+ extends: [
6
+ 'eslint:recommended',
7
+ 'plugin:@typescript-eslint/recommended',
8
+ 'plugin:prettier/recommended',
9
+ ],
10
+ rules: {
11
+ '@typescript-eslint/ban-ts-comment': 'off',
12
+ },
13
+ };
package/.gitlab-ci.yml ADDED
@@ -0,0 +1,77 @@
1
+ image: registry.gitlab.com/notabene/devops/build-node-16-image
2
+
3
+ variables:
4
+ NPM_TOKEN: ${CI_JOB_TOKEN}
5
+
6
+ stages:
7
+ - install
8
+ - lint
9
+ - test
10
+ - build
11
+ - release
12
+
13
+ install:
14
+ stage: install
15
+ cache:
16
+ paths:
17
+ - .yarn
18
+ artifacts:
19
+ paths:
20
+ - .yarn
21
+ - .pnp.cjs
22
+ - .pnp.loader.mjs
23
+ script:
24
+ - yarn
25
+
26
+ lint:
27
+ stage: lint
28
+ needs:
29
+ - install
30
+ script:
31
+ - yarn lint
32
+
33
+ test:
34
+ stage: test
35
+ needs:
36
+ - install
37
+ script:
38
+ - yarn test
39
+
40
+ build:
41
+ stage: build
42
+ needs:
43
+ - install
44
+ script:
45
+ - yarn build
46
+ artifacts:
47
+ paths:
48
+ - dist
49
+
50
+ publish-gitlab:
51
+ stage: release
52
+ needs:
53
+ - install
54
+ - build
55
+ variables:
56
+ GITLAB_USER_NAME: 'gitlab-ci'
57
+ GITLAB_USER_EMAIL: 'gitlab-ci@example.com'
58
+ before_script:
59
+ - git config --global user.email "$GITLAB_USER_EMAIL"
60
+ - git config --global user.name "$GITLAB_USER_NAME"
61
+ - |
62
+ {
63
+ echo "@${CI_PROJECT_ROOT_NAMESPACE}:registry=${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/npm/"
64
+ echo "${CI_API_V4_URL#https?}/projects/${CI_PROJECT_ID}/packages/npm/:_authToken=\${CI_JOB_TOKEN}"
65
+ } | tee -a .npmrc
66
+ script:
67
+ - yarn semantic-release
68
+ only:
69
+ - master
70
+
71
+ publish-npm:
72
+ stage: release
73
+ when: manual
74
+ script:
75
+ - yarn npm publish
76
+ only:
77
+ - tags
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+ . "$(dirname "$0")/_/husky.sh"
3
+
4
+ yarn commitlint -e "${1}"
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+ . "$(dirname "$0")/_/husky.sh"
3
+
4
+ yarn lint-staged
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+ . "$(dirname "$0")/_/husky.sh"
3
+
4
+ yarn test
package/.nvmrc ADDED
@@ -0,0 +1 @@
1
+ v16
package/.prettierrc ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "semi": true,
3
+ "singleQuote": true
4
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "branches": ["master"],
3
+ "plugins": [
4
+ "@semantic-release/commit-analyzer",
5
+ "@semantic-release/release-notes-generator",
6
+ "@semantic-release/gitlab",
7
+ "@semantic-release/npm",
8
+ [
9
+ "@semantic-release/git",
10
+ {
11
+ "assets": ["package.json"],
12
+ "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
13
+ }
14
+ ]
15
+ ]
16
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "recommendations": [
3
+ "arcanis.vscode-zipfs",
4
+ "dbaeumer.vscode-eslint",
5
+ "esbenp.prettier-vscode"
6
+ ]
7
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "search.exclude": {
3
+ "**/.yarn": true,
4
+ "**/.pnp.*": true
5
+ },
6
+ "eslint.nodePath": ".yarn/sdks",
7
+ "prettier.prettierPath": ".yarn/sdks/prettier/index.js",
8
+ "typescript.tsdk": ".yarn/sdks/typescript/lib",
9
+ "typescript.enablePromptUseWorkspaceTsdk": true
10
+ }
package/jest.config.js ADDED
@@ -0,0 +1,5 @@
1
+ /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
2
+ module.exports = {
3
+ preset: 'ts-jest',
4
+ testEnvironment: 'node',
5
+ };
package/package.json CHANGED
@@ -8,7 +8,8 @@
8
8
  },
9
9
  "author": "Notabene <developers@notabene.id>",
10
10
  "license": "MIT",
11
- "version": "1.10.6",
11
+ "version": "1.10.14",
12
+ "main": "dist/index.js",
12
13
  "packageManager": "yarn@3.2.1",
13
14
  "browserslist": "> 0.5%, last 2 versions, not dead",
14
15
  "targets": {
@@ -32,9 +33,6 @@
32
33
  "process": false,
33
34
  "buffer": false
34
35
  },
35
- "files": [
36
- "dist"
37
- ],
38
36
  "scripts": {
39
37
  "prepare": "husky install",
40
38
  "watch": "parcel watch",
@@ -0,0 +1,34 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta http-equiv="X-UA-Compatible" content="IE=edge" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <title>Notabene JavaScript Test</title>
8
+ <script
9
+ id="notabene"
10
+ async
11
+ src="http://localhost:3002/js/notabene.js"
12
+ ></script>
13
+ <script>
14
+ var script = document.querySelector('#notabene');
15
+ script.addEventListener('load', function () {
16
+ const nb = new Notabene({
17
+ widget: 'http://widget.notabene.id',
18
+ container: '#container',
19
+ authToken: '{ACCESS_TOKEN}',
20
+ });
21
+ nb.renderWidget().then(() => {
22
+ nb.setTransaction({
23
+ asset: 'ETH',
24
+ beneficiaryAddress: '0x8d12a197cb00d4747a1fe03395095ce2a5cc6819',
25
+ amount: '2000000000',
26
+ });
27
+ });
28
+ });
29
+ </script>
30
+ </head>
31
+ <body>
32
+ <div id="container" />
33
+ </body>
34
+ </html>
File without changes
@@ -0,0 +1 @@
1
+ export { default as Notabene } from '../notabene';
@@ -0,0 +1,9 @@
1
+ import Notabene from '../notabene';
2
+
3
+ declare global {
4
+ interface Window {
5
+ Notabene: typeof Notabene;
6
+ }
7
+ }
8
+
9
+ window.Notabene = Notabene;
@@ -0,0 +1,249 @@
1
+ // @ts-ignore
2
+ import { dom, node } from 'jsx-pragmatic';
3
+ // @ts-ignore
4
+ import zoid from 'zoid';
5
+
6
+ interface Theme {
7
+ primaryColor: string;
8
+ secondaryColor: string;
9
+ fontFamily: string;
10
+ logo: string;
11
+ }
12
+ interface NotabeneConfig {
13
+ widget: string;
14
+ container: string;
15
+ authToken: string;
16
+ onValidStateChange(): void;
17
+ theme: Theme;
18
+ dictionary: { [key: string]: string };
19
+ }
20
+
21
+ interface Transaction {
22
+ amount: string;
23
+ beneficiaryAddress: string;
24
+ asset: string;
25
+ originatorDid?: string;
26
+ originatorVASPDid?: string;
27
+ beneficiaryVASPname?: string;
28
+ beneficiaryName?: string;
29
+ }
30
+
31
+ export default class Notabene {
32
+ private widget: zoid.ZoidComponent;
33
+ private popup: zoid.ZoidComponent;
34
+ private config: NotabeneConfig;
35
+ private tx: Transaction | undefined;
36
+ private onValidStateChange: (isValid: boolean) => void;
37
+ private widgetRendered: boolean;
38
+ private popupRendered: boolean;
39
+ private theme: Theme;
40
+ private dictionary: { [key: string]: string };
41
+
42
+ constructor(config: NotabeneConfig) {
43
+ this.config = config;
44
+ this.theme = this.config.theme;
45
+ this.dictionary = this.config.dictionary;
46
+ this.widget = this.buildWidget();
47
+ this.popup = this.buildPopup();
48
+ this.onValidStateChange = config.onValidStateChange;
49
+ this.widgetRendered = false;
50
+ this.popupRendered = false;
51
+ }
52
+
53
+ public async renderWidget(): Promise<void> {
54
+ if (!this.widget) return;
55
+ this.widgetRendered
56
+ ? console.error('Notabene: Widget is already rendered')
57
+ : await this.widget.render(this.config.container);
58
+ }
59
+
60
+ public async renderPopup(): Promise<void> {
61
+ if (!this.popup) return;
62
+
63
+ this.popupRendered
64
+ ? this.popup.show()
65
+ : await this.popup.render(this.config.container);
66
+ }
67
+
68
+ public setTransaction(tx: Transaction) {
69
+ this.tx = tx;
70
+ this.widget.updateProps({
71
+ transaction: tx,
72
+ });
73
+ this.popup.updateProps({
74
+ transaction: tx,
75
+ });
76
+ }
77
+
78
+ private getWidgetUrl(): string {
79
+ const url = new URL(this.config.widget);
80
+ url.hash = `authToken=${this.config.authToken}`;
81
+ return url.toString();
82
+ }
83
+
84
+ private getAdditionalInfoUrl(): string {
85
+ const url = new URL(this.config.widget);
86
+ url.search = 'popup=true';
87
+ url.hash = `authToken=${this.config.authToken}`;
88
+ return url.toString();
89
+ }
90
+
91
+ private buildWidget(): zoid.ZoidComponent {
92
+ if (!this.config.authToken) {
93
+ console.error('Notabene: authToken is required');
94
+ return;
95
+ }
96
+
97
+ const builtWidget = zoid.create({
98
+ tag: 'widget',
99
+ url: this.getWidgetUrl(),
100
+ dimensions: {
101
+ width: '440px',
102
+ height: '280px',
103
+ },
104
+ props: {
105
+ transaction: {
106
+ type: 'object',
107
+ required: false,
108
+ },
109
+ onRequireAdditionalInformation: {
110
+ type: 'function',
111
+ },
112
+ onValidStateChange: {
113
+ type: 'function',
114
+ },
115
+ storeTransaction: {
116
+ type: 'function',
117
+ },
118
+ theme: {
119
+ type: 'object',
120
+ required: false,
121
+ },
122
+ dictionary: {
123
+ type: 'object',
124
+ required: false,
125
+ },
126
+ },
127
+ })({
128
+ transaction: {},
129
+ theme: this.theme,
130
+ dictionary: this.dictionary,
131
+ onRequireAdditionalInformation: () => {
132
+ this.renderPopup();
133
+ },
134
+ onValidStateChange: (isValid: boolean) => {
135
+ this.onValidStateChange(isValid);
136
+ },
137
+ storeTransaction: (tx: Transaction) => {
138
+ this.setTransaction(tx);
139
+ },
140
+ });
141
+
142
+ builtWidget.event.on(zoid.EVENT.RENDERED, (err: any) => {
143
+ this.widgetRendered = true;
144
+ });
145
+
146
+ return builtWidget;
147
+ }
148
+
149
+ private buildPopup(): zoid.ZoidComponent {
150
+ if (!this.config.authToken) {
151
+ console.error('Notabene: authToken is required');
152
+ return;
153
+ }
154
+
155
+ const builtPopup = zoid.create({
156
+ tag: 'popup',
157
+ url: this.getAdditionalInfoUrl(),
158
+ children: () => {
159
+ return {
160
+ Transaction: this.tx,
161
+ };
162
+ },
163
+ dimensions: {
164
+ width: '608px',
165
+ height: '100%',
166
+ },
167
+ props: {
168
+ transaction: {
169
+ type: 'object',
170
+ required: false,
171
+ },
172
+ storeTransaction: {
173
+ type: 'function',
174
+ },
175
+ close: {
176
+ type: 'function',
177
+ },
178
+ theme: {
179
+ type: 'object',
180
+ required: false,
181
+ },
182
+ dictionary: {
183
+ type: 'object',
184
+ required: false,
185
+ },
186
+ },
187
+ containerTemplate: ({ uid, doc, frame, prerenderFrame }: any) => {
188
+ return node(
189
+ 'div',
190
+ { id: uid, class: 'nb-container' },
191
+ node(
192
+ 'style',
193
+ null,
194
+ `
195
+ #${uid}.container {
196
+ border: 5px solid red;
197
+ }
198
+ .nb-overlay {
199
+ position: fixed;
200
+ width: 100vw;
201
+ height: 100vh;
202
+ top: 0;
203
+ left: 0;
204
+ display: flex;
205
+ align-items: center;
206
+ justify-content: center;
207
+ background-color: rgba(0,0,0,0.5);
208
+ }
209
+ .nb-popup {
210
+ max-width: 608px;
211
+ width: 100%;
212
+ height: 100%;
213
+ }
214
+ .nb-preloader {
215
+ display: none;
216
+ }
217
+ `
218
+ ),
219
+ node(
220
+ 'div',
221
+ { class: 'nb-overlay' },
222
+ node('node', { el: frame, class: 'nb-popup' }),
223
+ node('node', { el: prerenderFrame, class: 'nb-preloader' })
224
+ )
225
+ ).render(dom({ doc }));
226
+ },
227
+ })({
228
+ transaction: this.tx,
229
+ storeTransaction: (tx: Transaction) => {
230
+ this.setTransaction(tx);
231
+ console.debug('Notabene: Transaction stored');
232
+ },
233
+ close: () => {
234
+ this.popup.close();
235
+ console.debug('Notabene: Popup closing');
236
+ },
237
+ theme: this.theme,
238
+ dictionary: this.dictionary,
239
+ });
240
+
241
+ builtPopup.event.on(zoid.EVENT.RENDERED, (err: any) => {
242
+ this.popupRendered = true;
243
+ });
244
+
245
+ return builtPopup;
246
+ }
247
+ }
248
+
249
+ window.Notabene = Notabene;
package/tsconfig.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2020",
4
+ "module": "ES2020",
5
+ "strict": true,
6
+ "esModuleInterop": true,
7
+ "forceConsistentCasingInFileNames": true,
8
+ "outDir": "./dist",
9
+ "declaration": true,
10
+ "moduleResolution": "node",
11
+ "sourceMap": false,
12
+ "baseUrl": "src",
13
+ "lib": ["dom", "es2016"]
14
+ },
15
+ "include": ["./src"],
16
+ "exclude": [".git", "node_modules"]
17
+ }