@notabene/javascript-sdk 2.0.0-next.2 → 2.0.0-next.20

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 (64) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +281 -231
  3. package/dist/js/notabene.js +1 -0
  4. package/dist/notabene.cjs +1 -1
  5. package/dist/notabene.d.ts +1052 -209
  6. package/dist/notabene.js +275 -105
  7. package/dist/tsdoc-metadata.json +1 -1
  8. package/package.json +36 -26
  9. package/src/__tests__/notabene.test.ts +43 -0
  10. package/src/components/EmbeddedComponent.ts +141 -22
  11. package/src/components/__tests__/EmbeddedComponent.test.ts +73 -20
  12. package/src/ivms/types.ts +230 -152
  13. package/src/locales.ts +47 -0
  14. package/src/notabene.ts +243 -90
  15. package/src/types.ts +723 -144
  16. package/src/utils/MessageEventManager.ts +70 -12
  17. package/src/utils/__tests__/MessageEventManager.test.ts +13 -5
  18. package/src/utils/arbitraries.ts +9 -4
  19. package/.editorconfig +0 -10
  20. package/.gitlab-ci.yml +0 -85
  21. package/.husky/commit-msg +0 -4
  22. package/.husky/pre-commit +0 -4
  23. package/.husky/pre-push +0 -4
  24. package/.prettierrc +0 -4
  25. package/.releaserc.json +0 -16
  26. package/.vscode/extensions.json +0 -3
  27. package/.vscode/settings.json +0 -11
  28. package/.yarn/releases/yarn-berry.cjs +0 -925
  29. package/.yarnrc.yml +0 -3
  30. package/CODEOWNERS +0 -1
  31. package/api-extractor.json +0 -434
  32. package/eslint.config.js +0 -24
  33. package/etc/javascript-sdk.api.md +0 -363
  34. package/index.html +0 -137
  35. package/temp/javascript-sdk.api.json +0 -3509
  36. package/temp/javascript-sdk.api.md +0 -363
  37. package/ts-out/src/__tests__/notabene.test.d.ts +0 -1
  38. package/ts-out/src/__tests__/notabene.test.js +0 -88
  39. package/ts-out/src/arbitraries.d.ts +0 -4
  40. package/ts-out/src/arbitraries.js +0 -8
  41. package/ts-out/src/components/EmbeddedComponent.d.ts +0 -25
  42. package/ts-out/src/components/EmbeddedComponent.js +0 -87
  43. package/ts-out/src/components/__tests__/EmbeddedComponent.test.d.ts +0 -1
  44. package/ts-out/src/components/__tests__/EmbeddedComponent.test.js +0 -132
  45. package/ts-out/src/ivms/types.d.ts +0 -252
  46. package/ts-out/src/ivms/types.js +0 -1
  47. package/ts-out/src/notabene.d.ts +0 -35
  48. package/ts-out/src/notabene.js +0 -59
  49. package/ts-out/src/types.d.ts +0 -357
  50. package/ts-out/src/types.js +0 -85
  51. package/ts-out/src/utils/MessageEventManager.d.ts +0 -12
  52. package/ts-out/src/utils/MessageEventManager.js +0 -45
  53. package/ts-out/src/utils/__tests__/MessageEventManager.test.d.ts +0 -1
  54. package/ts-out/src/utils/__tests__/MessageEventManager.test.js +0 -73
  55. package/ts-out/src/utils/arbitraries.d.ts +0 -6
  56. package/ts-out/src/utils/arbitraries.js +0 -7
  57. package/ts-out/src/utils/caip.d.ts +0 -13
  58. package/ts-out/src/utils/caip.js +0 -15
  59. package/ts-out/src/utils/urls.d.ts +0 -1
  60. package/ts-out/src/utils/urls.js +0 -14
  61. package/ts-out/tsconfig.tsbuildinfo +0 -1
  62. package/tsconfig.json +0 -22
  63. package/tsconfig.tsbuildinfo +0 -1
  64. package/vite.config.js +0 -13
@@ -1,29 +1,76 @@
1
1
  import { ComponentMessage, HostMessage } from '../types';
2
2
 
3
- export type MessageCallback = (message: ComponentMessage) => void;
3
+ /**
4
+ * Callback function for handling component messages.
5
+ *
6
+ * @typeParam T - The type of data contained in the component message
7
+ * @param message - The message object containing the component data and type
8
+ * @public
9
+ */
4
10
 
5
- export class MessageEventManager {
6
- private listeners: Map<string, Set<MessageCallback>> = new Map();
11
+ export type MessageCallback<T> = (message: ComponentMessage<T>) => void;
12
+
13
+ /**
14
+ * Manages message event communication through MessagePorts.
15
+ *
16
+ * This class handles bidirectional communication between components using MessagePorts,
17
+ * allowing subscription to specific message types and dispatching messages to registered callbacks.
18
+ *
19
+ * @typeParam T - The type of data contained in messages received from components
20
+ * @typeParam O - The type of data contained in messages sent from the host
21
+ */
22
+
23
+ export class MessageEventManager<T, O> {
24
+ private listeners: Map<string, Set<MessageCallback<T>>> = new Map();
7
25
  private port?: MessagePort;
8
26
 
9
27
  constructor() {
10
28
  this.handleMessage = this.handleMessage.bind(this);
11
29
  }
12
30
 
31
+ /**
32
+ * Sets up the message port for communication.
33
+ *
34
+ * Initializes the MessagePort for receiving messages by setting up the message handler
35
+ * and starting the port.
36
+ *
37
+ * @param port - The MessagePort instance to use for communication
38
+ */
39
+
13
40
  setPort(port: MessagePort): void {
14
41
  this.port = port;
15
42
  this.port.onmessage = this.handleMessage;
16
43
  this.port.start();
17
44
  }
18
45
 
19
- on(messageType: string, callback: MessageCallback): void {
46
+ /**
47
+ * Registers a callback for a specific message type.
48
+ *
49
+ * When messages of the specified type are received, the callback will be executed
50
+ * with the message data.
51
+ *
52
+ * @param messageType - The type of message to listen for
53
+ * @param callback - The callback function to execute when matching messages are received
54
+ */
55
+
56
+ on(messageType: string, callback: MessageCallback<T>): void {
20
57
  if (!this.listeners.has(messageType)) {
21
58
  this.listeners.set(messageType, new Set());
22
59
  }
23
60
  this.listeners.get(messageType)!.add(callback);
24
61
  }
25
62
 
26
- off(messageType: string, callback: MessageCallback): void {
63
+ /**
64
+ * Removes a callback for a specific message type.
65
+ *
66
+ * If the callback is the last one registered for the message type,
67
+ * the message type entry will be removed entirely.
68
+ *
69
+ * @param messageType - The type of message to remove listener from
70
+ * @param callback - The callback function to remove
71
+ */
72
+
73
+ off(messageType: string, callback: MessageCallback<T>): void {
27
74
  const callbacks = this.listeners.get(messageType);
28
75
  if (callbacks) {
29
76
  callbacks.delete(callback);
@@ -33,8 +80,17 @@ export class MessageEventManager {
33
80
  }
34
81
  }
35
82
 
36
- private handleMessage(event: MessageEvent): void {
37
- console.log('received message', event.data);
83
+ /**
84
+ * Internal message handler for processing received messages.
85
+ *
86
+ * Validates incoming messages and dispatches them to registered callbacks
87
+ * based on the message type.
88
+ *
89
+ * @param event - The message event containing the component message
90
+ */
91
+
92
+ private handleMessage(event: MessageEvent<ComponentMessage<T>>): void {
93
+ // console.log('received message', event.data);
38
94
  const message = event.data;
39
95
  if (typeof message === 'object' && message !== null && 'type' in message) {
40
96
  const messageType = message.type as string;
@@ -45,11 +101,13 @@ export class MessageEventManager {
45
101
  }
46
102
  }
47
103
 
48
- // Method to send messages through the port
49
- send(message: HostMessage): void {
50
- if (!this.port) {
51
- throw new Error('No port set');
104
+ /**
105
+ * Sends a message through the message port
106
+ * @param message The host message to send
107
+ */
108
+ send(message: HostMessage<T, O>): void {
109
+ if (this.port) {
110
+ this.port.postMessage(message);
52
111
  }
53
- this.port.postMessage(message);
54
112
  }
55
113
  }
@@ -1,9 +1,14 @@
1
1
  import { beforeEach, describe, expect, it, vi } from 'vitest';
2
- import { HMType, UpdateValue } from '../../types';
2
+ import {
3
+ HMType,
4
+ type TransactionOptions,
5
+ type UpdateValue,
6
+ type Withdrawal,
7
+ } from '../../types';
3
8
  import { MessageEventManager } from '../MessageEventManager';
4
9
 
5
10
  describe('MessageEventManager', () => {
6
- let messageEventManager: MessageEventManager;
11
+ let messageEventManager: MessageEventManager<Withdrawal, TransactionOptions>;
7
12
  let mockPort: MessagePort;
8
13
 
9
14
  beforeEach(() => {
@@ -13,7 +18,10 @@ describe('MessageEventManager', () => {
13
18
  start: vi.fn(),
14
19
  } as unknown as MessagePort;
15
20
 
16
- messageEventManager = new MessageEventManager();
21
+ messageEventManager = new MessageEventManager<
22
+ Withdrawal,
23
+ TransactionOptions
24
+ >();
17
25
  });
18
26
 
19
27
  describe('setPort', () => {
@@ -73,9 +81,9 @@ describe('MessageEventManager', () => {
73
81
  });
74
82
 
75
83
  it('should send messages through the port', () => {
76
- const message: UpdateValue = {
84
+ const message: UpdateValue<Withdrawal, TransactionOptions> = {
77
85
  type: HMType.UPDATE,
78
- value: { asset: 'USDC' },
86
+ value: { requestId: 'id' },
79
87
  };
80
88
  messageEventManager.send(message);
81
89
 
@@ -7,15 +7,20 @@ import {
7
7
  CAIP2_MATCHER,
8
8
  } from './caip';
9
9
 
10
+ const LOCALE = new RegExp(/^[a-z]{2}(-[A-Z]{2})?$/);
11
+
10
12
  // Arbitraries
11
13
  export const arbitraryCAIP10 = (): fc.Arbitrary<CAIP10> =>
12
- fc.stringMatching(CAIP10_MATCHER);
14
+ fc.stringMatching(CAIP10_MATCHER) as fc.Arbitrary<CAIP10>;
13
15
 
14
16
  export const arbitraryCAIP2 = (): fc.Arbitrary<CAIP2> =>
15
- fc.stringMatching(CAIP2_MATCHER);
17
+ fc.stringMatching(CAIP2_MATCHER) as fc.Arbitrary<CAIP2>;
16
18
 
17
19
  export const arbitraryCAIP19 = (): fc.Arbitrary<CAIP19> =>
18
- fc.stringMatching(CAIP19_MATCHER);
20
+ fc.stringMatching(CAIP19_MATCHER) as fc.Arbitrary<CAIP19>;
19
21
 
20
22
  export const arbitraryCAIP220 = (): fc.Arbitrary<CAIP220> =>
21
- fc.stringMatching(CAIP220_MATCHER);
23
+ fc.stringMatching(CAIP220_MATCHER) as fc.Arbitrary<CAIP220>;
24
+
25
+ export const arbitraryLocale = (): fc.Arbitrary<string> =>
26
+ fc.stringMatching(LOCALE) as fc.Arbitrary<string>;
package/.editorconfig DELETED
@@ -1,10 +0,0 @@
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/.gitlab-ci.yml DELETED
@@ -1,85 +0,0 @@
1
- image: registry.gitlab.com/notabene/devops/build-node-18-image:latest
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
- artifacts:
16
- paths:
17
- - .yarn
18
- - .pnp.cjs
19
- - .pnp.loader.mjs
20
- script:
21
- - yarn
22
-
23
- lint:
24
- stage: lint
25
- needs:
26
- - install
27
- script:
28
- - yarn lint
29
-
30
- test:
31
- stage: test
32
- needs:
33
- - install
34
- script:
35
- - yarn test
36
-
37
- build:
38
- stage: build
39
- needs:
40
- - install
41
- script:
42
- - yarn build
43
- artifacts:
44
- paths:
45
- - dist
46
-
47
- publish-gitlab:
48
- stage: release
49
- needs:
50
- - install
51
- - build
52
- variables:
53
- GITLAB_USER_NAME: 'gitlab-ci'
54
- GITLAB_USER_EMAIL: 'gitlab-ci@example.com'
55
- before_script:
56
- - git config --global user.email "$GITLAB_USER_EMAIL"
57
- - git config --global user.name "$GITLAB_USER_NAME"
58
- - |
59
- {
60
- echo "@${CI_PROJECT_ROOT_NAMESPACE}:registry=${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/npm/"
61
- echo "${CI_API_V4_URL#https?}/projects/${CI_PROJECT_ID}/packages/npm/:_authToken=\${CI_JOB_TOKEN}"
62
- } | tee -a .npmrc
63
- script:
64
- - yarn semantic-release
65
- only:
66
- - master
67
-
68
- publish-npm:
69
- stage: release
70
- when: manual
71
- script:
72
- - yarn npm publish
73
- only:
74
- - tags
75
-
76
- publish-npm-next:
77
- stage: release
78
- needs:
79
- - install
80
- - build
81
- script:
82
- - yarn npm version prerelease
83
- - yarn npm publish --tag next
84
- only:
85
- - v2
package/.husky/commit-msg DELETED
@@ -1,4 +0,0 @@
1
- #!/bin/sh
2
- . "$(dirname "$0")/_/husky.sh"
3
-
4
- yarn commitlint -e "${1}"
package/.husky/pre-commit DELETED
@@ -1,4 +0,0 @@
1
- #!/bin/sh
2
- . "$(dirname "$0")/_/husky.sh"
3
-
4
- yarn lint-staged
package/.husky/pre-push DELETED
@@ -1,4 +0,0 @@
1
- #!/bin/sh
2
- . "$(dirname "$0")/_/husky.sh"
3
-
4
- yarn test --run
package/.prettierrc DELETED
@@ -1,4 +0,0 @@
1
- {
2
- "semi": true,
3
- "singleQuote": true
4
- }
package/.releaserc.json DELETED
@@ -1,16 +0,0 @@
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
- }
@@ -1,3 +0,0 @@
1
- {
2
- "recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode"]
3
- }
@@ -1,11 +0,0 @@
1
- {
2
- "search.exclude": {
3
- "**/.yarn": true,
4
- "**/.pnp.*": true
5
- },
6
- "typescript.enablePromptUseWorkspaceTsdk": true,
7
- "editor.defaultFormatter": "esbenp.prettier-vscode",
8
- "editor.codeActionsOnSave": {
9
- "source.fixAll.eslint": "explicit"
10
- }
11
- }