@notabene/javascript-sdk 2.0.0-next.10 → 2.0.0-next.12

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/src/notabene.ts CHANGED
@@ -4,6 +4,8 @@ import type {
4
4
  AgentType,
5
5
  CallbackOptions,
6
6
  ComponentMessage,
7
+ ConnectionRequest,
8
+ ConnectionResponse,
7
9
  Counterparty,
8
10
  DeclarationProof,
9
11
  Deposit,
@@ -34,6 +36,8 @@ export type {
34
36
  CMType,
35
37
  ComponentMessage,
36
38
  EmbeddedComponent,
39
+ ConnectionRequest,
40
+ ConnectionResponse,
37
41
  HostMessage,
38
42
  Theme,
39
43
  Counterparty,
@@ -60,27 +64,54 @@ export type {
60
64
  AgentType,
61
65
  OwnershipProof,
62
66
  TransactionOptions,
67
+ CallbackOptions,
63
68
  };
64
69
 
70
+ /**
71
+ * Configuration for the Notabene SDK
72
+ *
73
+ * @public
74
+ */
65
75
  /**
66
76
  * Configuration for the Notabene SDK
67
77
  *
68
78
  * @public
69
79
  */
70
80
  export interface NotabeneConfig {
81
+ /**
82
+ * The URL of the Notabene API node
83
+ */
71
84
  nodeUrl?: string;
85
+
86
+ /**
87
+ * The authentication token for the Notabene API
88
+ */
72
89
  authToken?: string;
90
+
91
+ /**
92
+ * The URL of the Notabene UX components
93
+ */
73
94
  uxUrl?: string;
95
+
96
+ /**
97
+ * Custom theme configuration for the UX components
98
+ */
74
99
  theme?: Theme;
100
+
101
+ /**
102
+ * The locale to use for the UX components
103
+ */
75
104
  locale?: string;
76
105
  }
77
-
78
106
  /**
79
107
  * Primary constructor for Notabene UX elements
80
108
  *
109
+ * This class provides methods to create and manage various Notabene components
110
+ * such as withdrawal assist, deposit assist, connect, and deposit request.
111
+ * It also handles URL generation and fragment decoding for these components.
112
+ *
81
113
  * @public
82
114
  */
83
-
84
115
  export default class Notabene {
85
116
  private nodeUrl?: string;
86
117
  private authToken?: string;
@@ -88,6 +119,11 @@ export default class Notabene {
88
119
  private theme?: Theme;
89
120
  private locale?: string;
90
121
 
122
+ /**
123
+ * Creates a new instance of the Notabene SDK
124
+ *
125
+ * @param config - Configuration options for the Notabene SDK
126
+ */
91
127
  constructor(config: NotabeneConfig) {
92
128
  this.uxUrl = config.uxUrl || 'https://connect.notabene.id';
93
129
  this.nodeUrl = config.nodeUrl;
@@ -96,9 +132,19 @@ export default class Notabene {
96
132
  this.locale = config.locale;
97
133
  }
98
134
 
99
- public componentUrl(
135
+ /**
136
+ * Generates a URL for a Notabene component
137
+ *
138
+ * @param path - The path of the component
139
+ * @param value - Transaction data
140
+ * @param configuration - Optional transaction configuration
141
+ * @param callbacks - Optional callback configuration
142
+ * @returns component URL
143
+ * @internal
144
+ */
145
+ componentUrl<V>(
100
146
  path: string,
101
- value: Partial<Transaction>,
147
+ value: V,
102
148
  configuration?: TransactionOptions,
103
149
  callbacks?: CallbackOptions,
104
150
  ): string {
@@ -128,50 +174,116 @@ export default class Notabene {
128
174
  return url.toString();
129
175
  }
130
176
 
131
- public createComponent(
177
+ /**
178
+ * Creates a new embedded component
179
+ *
180
+ * @param path - The path of the component
181
+ * @param value - Transaction data
182
+ * @param options - Optional transaction options
183
+ * @param callbacks - Optional callback configuration
184
+ * @returns A new EmbeddedComponent instance
185
+ * @internal
186
+ */
187
+ createComponent<V, R>(
132
188
  path: string,
133
- value: Partial<Transaction>,
189
+ value: V,
134
190
  options?: TransactionOptions,
135
191
  callbacks?: CallbackOptions,
136
192
  ) {
137
- return new EmbeddedComponent(
193
+ return new EmbeddedComponent<V, R>(
138
194
  this.componentUrl(path, value, options, callbacks),
139
195
  value,
140
196
  );
141
197
  }
142
198
 
199
+ /**
200
+ * Creates a withdrawal assist component
201
+ *
202
+ * @param value - Withdrawal transaction data
203
+ * @param options - Optional transaction options
204
+ * @param callbacks - Optional callback configuration
205
+ * @returns A new EmbeddedComponent instance for withdrawal assistance
206
+ */
143
207
  public createWithdrawalAssist(
144
208
  value: Partial<Withdrawal>,
145
209
  options?: TransactionOptions,
146
210
  callbacks?: CallbackOptions,
147
211
  ) {
148
- return this.createComponent('withdrawal-assist', value, options, callbacks);
212
+ return this.createComponent<
213
+ Partial<Withdrawal>,
214
+ TransactionResponse<Withdrawal>
215
+ >('withdrawal-assist', value, options, callbacks);
149
216
  }
150
217
 
218
+ /**
219
+ * Creates a deposit assist component
220
+ *
221
+ * @param value - Deposit transaction data
222
+ * @param options - Optional transaction options
223
+ * @param callbacks - Optional callback configuration
224
+ * @returns A new EmbeddedComponent instance for deposit assistance
225
+ * @alpha
226
+ */
151
227
  public createDepositAssist(
152
228
  value: Partial<Deposit>,
153
229
  options?: any,
154
230
  callbacks?: CallbackOptions,
155
231
  ) {
156
- return this.createComponent('deposit-assist', value, options, callbacks);
232
+ return this.createComponent<Partial<Deposit>, TransactionResponse<Deposit>>(
233
+ 'deposit-assist',
234
+ value,
235
+ options,
236
+ callbacks,
237
+ );
157
238
  }
158
239
 
159
- public createConnect(
160
- value: Partial<Withdrawal>,
240
+ /**
241
+ * Creates a connect component
242
+ *
243
+ * @param value - Connection request data
244
+ * @param options - Optional transaction options
245
+ * @param callbacks - Optional callback configuration
246
+ * @returns A new EmbeddedComponent instance for connection
247
+ */
248
+ public createConnectWallet(
249
+ value: ConnectionRequest,
161
250
  options?: TransactionOptions,
162
251
  callbacks?: CallbackOptions,
163
252
  ) {
164
- return this.createComponent('connect', value, options, callbacks);
253
+ return this.createComponent<ConnectionRequest, ConnectionResponse>(
254
+ 'connect',
255
+ value,
256
+ options,
257
+ callbacks,
258
+ );
165
259
  }
166
260
 
261
+ /**
262
+ * Creates a deposit request component
263
+ *
264
+ * @param value - Deposit request data
265
+ * @param options - Optional transaction options
266
+ * @param callbacks - Optional callback configuration
267
+ * @returns A new EmbeddedComponent instance for deposit requests
268
+ * @alpha
269
+ */
167
270
  public createDepositRequest(
168
- value: Partial<DepositRequest>,
271
+ value: DepositRequest,
169
272
  options?: TransactionOptions,
170
273
  callbacks?: CallbackOptions,
171
274
  ) {
172
- return this.createComponent('deposit-request', value, options, callbacks);
275
+ return this.createComponent<
276
+ DepositRequest,
277
+ TransactionResponse<DepositRequest>
278
+ >('deposit-request', value, options, callbacks);
173
279
  }
174
280
 
281
+ /**
282
+ * Decodes a URL fragment into an object
283
+ *
284
+ * @param fragment - The URL fragment to decode
285
+ * @returns An object containing the decoded key-value pairs
286
+ */
175
287
  public decodeFragmentToObject(fragment: string): Record<string, string> {
176
288
  const pairs = fragment.slice(1).split('&');
177
289
  return pairs.reduce(