@novasamatech/host-container 0.6.8 → 0.6.10

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.
@@ -2,6 +2,7 @@ import { ChatBotRegistrationErr, ChatMessagePostingErr, ChatRoomRegistrationErr,
2
2
  import { err, errAsync, ok, okAsync } from 'neverthrow';
3
3
  import { createChainConnectionManager } from './chainConnectionManager.js';
4
4
  const UNSUPPORTED_MESSAGE_FORMAT_ERROR = 'Unsupported message format';
5
+ const NOT_IMPLEMENTED = 'Not implemented';
5
6
  function guardVersion(value, tag, error) {
6
7
  if (isEnumVariant(value, tag)) {
7
8
  return ok(value.value);
@@ -17,10 +18,163 @@ export function createContainer(provider) {
17
18
  // init status subscription
18
19
  transport.isReady();
19
20
  }
21
+ function makeRequestSlot(method, defaultHandler) {
22
+ let current = defaultHandler;
23
+ let version = 0;
24
+ transport.handleRequest(method, params => current(params));
25
+ return handler => {
26
+ current = handler;
27
+ const myVersion = ++version;
28
+ return () => {
29
+ if (myVersion !== version)
30
+ return;
31
+ version++;
32
+ current = defaultHandler;
33
+ };
34
+ };
35
+ }
36
+ function makeSubscriptionSlot(method, defaultHandler) {
37
+ let current = defaultHandler;
38
+ let version = 0;
39
+ transport.handleSubscription(method, (params, send, interrupt) => current(params, send, interrupt));
40
+ return handler => {
41
+ current = handler;
42
+ const myVersion = ++version;
43
+ return () => {
44
+ if (myVersion !== version)
45
+ return;
46
+ version++;
47
+ current = defaultHandler;
48
+ };
49
+ };
50
+ }
51
+ // account slots
52
+ const handleAccountGetSlot = makeRequestSlot('host_account_get', async () => {
53
+ const error = new RequestCredentialsErr.Unknown({ reason: NOT_IMPLEMENTED });
54
+ return enumValue('v1', resultErr(error));
55
+ });
56
+ const handleAccountGetAliasSlot = makeRequestSlot('host_account_get_alias', async () => {
57
+ const error = new RequestCredentialsErr.Unknown({ reason: NOT_IMPLEMENTED });
58
+ return enumValue('v1', resultErr(error));
59
+ });
60
+ const handleGetNonProductAccountsSlot = makeRequestSlot('host_get_non_product_accounts', async () => {
61
+ const error = new RequestCredentialsErr.Unknown({ reason: NOT_IMPLEMENTED });
62
+ return enumValue('v1', resultErr(error));
63
+ });
64
+ const handleAccountCreateProofSlot = makeRequestSlot('host_account_create_proof', async () => {
65
+ const error = new CreateProofErr.Unknown({ reason: NOT_IMPLEMENTED });
66
+ return enumValue('v1', resultErr(error));
67
+ });
68
+ // storage slots
69
+ const handleLocalStorageReadSlot = makeRequestSlot('host_local_storage_read', async () => {
70
+ const error = new StorageErr.Unknown({ reason: NOT_IMPLEMENTED });
71
+ return enumValue('v1', resultErr(error));
72
+ });
73
+ const handleLocalStorageWriteSlot = makeRequestSlot('host_local_storage_write', async () => {
74
+ const error = new StorageErr.Unknown({ reason: NOT_IMPLEMENTED });
75
+ return enumValue('v1', resultErr(error));
76
+ });
77
+ const handleLocalStorageClearSlot = makeRequestSlot('host_local_storage_clear', async () => {
78
+ const error = new StorageErr.Unknown({ reason: NOT_IMPLEMENTED });
79
+ return enumValue('v1', resultErr(error));
80
+ });
81
+ // signing slots
82
+ const handleSignRawSlot = makeRequestSlot('host_sign_raw', async () => {
83
+ const error = new SigningErr.Unknown({ reason: NOT_IMPLEMENTED });
84
+ return enumValue('v1', resultErr(error));
85
+ });
86
+ const handleSignPayloadSlot = makeRequestSlot('host_sign_payload', async () => {
87
+ const error = new SigningErr.Unknown({ reason: NOT_IMPLEMENTED });
88
+ return enumValue('v1', resultErr(error));
89
+ });
90
+ const handleCreateTransactionSlot = makeRequestSlot('host_create_transaction', async () => {
91
+ const error = new CreateTransactionErr.Unknown({ reason: NOT_IMPLEMENTED });
92
+ return enumValue('v1', resultErr(error));
93
+ });
94
+ const handleCreateTransactionWithNonProductAccountSlot = makeRequestSlot('host_create_transaction_with_non_product_account', async () => {
95
+ const error = new CreateTransactionErr.Unknown({ reason: NOT_IMPLEMENTED });
96
+ return enumValue('v1', resultErr(error));
97
+ });
98
+ const handleFeatureSupportedSlot = makeRequestSlot('host_feature_supported', async () => {
99
+ const error = new GenericError({ reason: NOT_IMPLEMENTED });
100
+ return enumValue('v1', resultErr(error));
101
+ });
102
+ const handleDevicePermissionSlot = makeRequestSlot('host_device_permission', async () => {
103
+ const error = new GenericError({ reason: NOT_IMPLEMENTED });
104
+ return enumValue('v1', resultErr(error));
105
+ });
106
+ const handlePermissionSlot = makeRequestSlot('remote_permission', async () => {
107
+ const error = new GenericError({ reason: NOT_IMPLEMENTED });
108
+ return enumValue('v1', resultErr(error));
109
+ });
110
+ const handlePushNotificationSlot = makeRequestSlot('host_push_notification', async () => {
111
+ const error = new GenericError({ reason: NOT_IMPLEMENTED });
112
+ return enumValue('v1', resultErr(error));
113
+ });
114
+ const handleNavigateToSlot = makeRequestSlot('host_navigate_to', async () => {
115
+ const error = new NavigateToErr.Unknown({ reason: NOT_IMPLEMENTED });
116
+ return enumValue('v1', resultErr(error));
117
+ });
118
+ const handleChatCreateRoomSlot = makeRequestSlot('host_chat_create_room', async () => {
119
+ const error = new ChatRoomRegistrationErr.Unknown({ reason: NOT_IMPLEMENTED });
120
+ return enumValue('v1', resultErr(error));
121
+ });
122
+ const handleChatBotRegistrationSlot = makeRequestSlot('host_chat_register_bot', async () => {
123
+ const error = new ChatBotRegistrationErr.Unknown({ reason: NOT_IMPLEMENTED });
124
+ return enumValue('v1', resultErr(error));
125
+ });
126
+ const handleChatPostMessageSlot = makeRequestSlot('host_chat_post_message', async () => {
127
+ const error = new ChatMessagePostingErr.Unknown({ reason: NOT_IMPLEMENTED });
128
+ return enumValue('v1', resultErr(error));
129
+ });
130
+ const handleStatementStoreSubmitSlot = makeRequestSlot('remote_statement_store_submit', async () => {
131
+ const error = new GenericError({ reason: NOT_IMPLEMENTED });
132
+ return enumValue('v1', resultErr(error));
133
+ });
134
+ const handleStatementStoreCreateProofSlot = makeRequestSlot('remote_statement_store_create_proof', async () => {
135
+ const error = new StatementProofErr.Unknown({ reason: NOT_IMPLEMENTED });
136
+ return enumValue('v1', resultErr(error));
137
+ });
138
+ const handlePreimageSubmitSlot = makeRequestSlot('remote_preimage_submit', async () => {
139
+ const error = new PreimageSubmitErr.Unknown({ reason: NOT_IMPLEMENTED });
140
+ return enumValue('v1', resultErr(error));
141
+ });
142
+ // subscription slots — default interrupts on next microtask so that
143
+ // the caller has a chance to register an onInterrupt listener first
144
+ const handleAccountConnectionStatusSubscribeSlot = makeSubscriptionSlot('host_account_connection_status_subscribe', (_params, _send, interrupt) => {
145
+ queueMicrotask(interrupt);
146
+ return () => {
147
+ /* nothing to clean up */
148
+ };
149
+ });
150
+ const handleChatListSubscribeSlot = makeSubscriptionSlot('host_chat_list_subscribe', (_params, _send, interrupt) => {
151
+ queueMicrotask(interrupt);
152
+ return () => {
153
+ /* nothing to clean up */
154
+ };
155
+ });
156
+ const handleChatActionSubscribeSlot = makeSubscriptionSlot('host_chat_action_subscribe', (_params, _send, interrupt) => {
157
+ queueMicrotask(interrupt);
158
+ return () => {
159
+ /* nothing to clean up */
160
+ };
161
+ });
162
+ const handleStatementStoreSubscribeSlot = makeSubscriptionSlot('remote_statement_store_subscribe', (_params, _send, interrupt) => {
163
+ queueMicrotask(interrupt);
164
+ return () => {
165
+ /* nothing to clean up */
166
+ };
167
+ });
168
+ const handlePreimageLookupSubscribeSlot = makeSubscriptionSlot('remote_preimage_lookup_subscribe', (_params, _send, interrupt) => {
169
+ queueMicrotask(interrupt);
170
+ return () => {
171
+ /* nothing to clean up */
172
+ };
173
+ });
20
174
  return {
21
175
  handleFeatureSupported(handler) {
22
176
  init();
23
- return transport.handleRequest('host_feature_supported', async (message) => {
177
+ return handleFeatureSupportedSlot(async (message) => {
24
178
  const version = 'v1';
25
179
  const error = new GenericError({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
26
180
  return guardVersion(message, version, error)
@@ -32,7 +186,7 @@ export function createContainer(provider) {
32
186
  },
33
187
  handleDevicePermission(handler) {
34
188
  init();
35
- return transport.handleRequest('host_device_permission', async (message) => {
189
+ return handleDevicePermissionSlot(async (message) => {
36
190
  const version = 'v1';
37
191
  const error = new GenericError({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
38
192
  return guardVersion(message, version, error)
@@ -44,7 +198,7 @@ export function createContainer(provider) {
44
198
  },
45
199
  handlePermission(handler) {
46
200
  init();
47
- return transport.handleRequest('remote_permission', async (message) => {
201
+ return handlePermissionSlot(async (message) => {
48
202
  const version = 'v1';
49
203
  const error = new GenericError({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
50
204
  return guardVersion(message, version, error)
@@ -56,7 +210,7 @@ export function createContainer(provider) {
56
210
  },
57
211
  handlePushNotification(handler) {
58
212
  init();
59
- return transport.handleRequest('host_push_notification', async (message) => {
213
+ return handlePushNotificationSlot(async (message) => {
60
214
  const version = 'v1';
61
215
  const error = new GenericError({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
62
216
  return guardVersion(message, version, error)
@@ -68,7 +222,7 @@ export function createContainer(provider) {
68
222
  },
69
223
  handleNavigateTo(handler) {
70
224
  init();
71
- return transport.handleRequest('host_navigate_to', async (message) => {
225
+ return handleNavigateToSlot(async (message) => {
72
226
  const version = 'v1';
73
227
  const error = new NavigateToErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
74
228
  return guardVersion(message, version, error)
@@ -80,7 +234,7 @@ export function createContainer(provider) {
80
234
  },
81
235
  handleLocalStorageRead(handler) {
82
236
  init();
83
- return transport.handleRequest('host_local_storage_read', async (message) => {
237
+ return handleLocalStorageReadSlot(async (message) => {
84
238
  const version = 'v1';
85
239
  const error = new StorageErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
86
240
  return guardVersion(message, version, error)
@@ -92,7 +246,7 @@ export function createContainer(provider) {
92
246
  },
93
247
  handleLocalStorageWrite(handler) {
94
248
  init();
95
- return transport.handleRequest('host_local_storage_write', async (message) => {
249
+ return handleLocalStorageWriteSlot(async (message) => {
96
250
  const version = 'v1';
97
251
  const error = new StorageErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
98
252
  return guardVersion(message, version, error)
@@ -104,7 +258,7 @@ export function createContainer(provider) {
104
258
  },
105
259
  handleLocalStorageClear(handler) {
106
260
  init();
107
- return transport.handleRequest('host_local_storage_clear', async (message) => {
261
+ return handleLocalStorageClearSlot(async (message) => {
108
262
  const version = 'v1';
109
263
  const error = new StorageErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
110
264
  return guardVersion(message, version, error)
@@ -116,7 +270,7 @@ export function createContainer(provider) {
116
270
  },
117
271
  handleAccountConnectionStatusSubscribe(handler) {
118
272
  init();
119
- return transport.handleSubscription('host_account_connection_status_subscribe', (params, send, interrupt) => {
273
+ return handleAccountConnectionStatusSubscribeSlot((params, send, interrupt) => {
120
274
  const version = 'v1';
121
275
  return guardVersion(params, version, null)
122
276
  .map(params => handler(params, payload => send(enumValue(version, payload)), interrupt))
@@ -128,7 +282,7 @@ export function createContainer(provider) {
128
282
  },
129
283
  handleAccountGet(handler) {
130
284
  init();
131
- return transport.handleRequest('host_account_get', async (params) => {
285
+ return handleAccountGetSlot(async (params) => {
132
286
  const version = 'v1';
133
287
  const error = new RequestCredentialsErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
134
288
  return guardVersion(params, version, error)
@@ -140,7 +294,7 @@ export function createContainer(provider) {
140
294
  },
141
295
  handleAccountGetAlias(handler) {
142
296
  init();
143
- return transport.handleRequest('host_account_get_alias', async (params) => {
297
+ return handleAccountGetAliasSlot(async (params) => {
144
298
  const version = 'v1';
145
299
  const error = new RequestCredentialsErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
146
300
  return guardVersion(params, version, error)
@@ -152,7 +306,7 @@ export function createContainer(provider) {
152
306
  },
153
307
  handleAccountCreateProof(handler) {
154
308
  init();
155
- return transport.handleRequest('host_account_create_proof', async (params) => {
309
+ return handleAccountCreateProofSlot(async (params) => {
156
310
  const version = 'v1';
157
311
  const error = new CreateProofErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
158
312
  return guardVersion(params, version, error)
@@ -164,7 +318,7 @@ export function createContainer(provider) {
164
318
  },
165
319
  handleGetNonProductAccounts(handler) {
166
320
  init();
167
- return transport.handleRequest('host_get_non_product_accounts', async (params) => {
321
+ return handleGetNonProductAccountsSlot(async (params) => {
168
322
  const version = 'v1';
169
323
  const error = new RequestCredentialsErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
170
324
  return guardVersion(params, version, error)
@@ -176,7 +330,7 @@ export function createContainer(provider) {
176
330
  },
177
331
  handleCreateTransaction(handler) {
178
332
  init();
179
- return transport.handleRequest('host_create_transaction', async (params) => {
333
+ return handleCreateTransactionSlot(async (params) => {
180
334
  const version = 'v1';
181
335
  const error = new CreateTransactionErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
182
336
  return guardVersion(params, version, error)
@@ -188,7 +342,7 @@ export function createContainer(provider) {
188
342
  },
189
343
  handleCreateTransactionWithNonProductAccount(handler) {
190
344
  init();
191
- return transport.handleRequest('host_create_transaction_with_non_product_account', async (params) => {
345
+ return handleCreateTransactionWithNonProductAccountSlot(async (params) => {
192
346
  const version = 'v1';
193
347
  const error = new CreateTransactionErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
194
348
  return guardVersion(params, version, error)
@@ -200,7 +354,7 @@ export function createContainer(provider) {
200
354
  },
201
355
  handleSignRaw(handler) {
202
356
  init();
203
- return transport.handleRequest('host_sign_raw', async (params) => {
357
+ return handleSignRawSlot(async (params) => {
204
358
  const version = 'v1';
205
359
  const error = new SigningErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
206
360
  return guardVersion(params, version, error)
@@ -212,7 +366,7 @@ export function createContainer(provider) {
212
366
  },
213
367
  handleSignPayload(handler) {
214
368
  init();
215
- return transport.handleRequest('host_sign_payload', async (params) => {
369
+ return handleSignPayloadSlot(async (params) => {
216
370
  const version = 'v1';
217
371
  const error = new SigningErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
218
372
  return guardVersion(params, version, error)
@@ -224,7 +378,7 @@ export function createContainer(provider) {
224
378
  },
225
379
  handleChatCreateRoom(handler) {
226
380
  init();
227
- return transport.handleRequest('host_chat_create_room', async (params) => {
381
+ return handleChatCreateRoomSlot(async (params) => {
228
382
  const version = 'v1';
229
383
  const error = new ChatRoomRegistrationErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
230
384
  return guardVersion(params, version, error)
@@ -236,7 +390,7 @@ export function createContainer(provider) {
236
390
  },
237
391
  handleChatBotRegistration(handler) {
238
392
  init();
239
- return transport.handleRequest('host_chat_register_bot', async (params) => {
393
+ return handleChatBotRegistrationSlot(async (params) => {
240
394
  const version = 'v1';
241
395
  const error = new ChatBotRegistrationErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
242
396
  return guardVersion(params, version, error)
@@ -248,7 +402,7 @@ export function createContainer(provider) {
248
402
  },
249
403
  handleChatListSubscribe(handler) {
250
404
  init();
251
- return transport.handleSubscription('host_chat_list_subscribe', (params, send, interrupt) => {
405
+ return handleChatListSubscribeSlot((params, send, interrupt) => {
252
406
  const version = 'v1';
253
407
  return guardVersion(params, version, null)
254
408
  .map(params => handler(params, payload => send(enumValue(version, payload)), interrupt))
@@ -260,7 +414,7 @@ export function createContainer(provider) {
260
414
  },
261
415
  handleChatPostMessage(handler) {
262
416
  init();
263
- return transport.handleRequest('host_chat_post_message', async (params) => {
417
+ return handleChatPostMessageSlot(async (params) => {
264
418
  const version = 'v1';
265
419
  const error = new ChatMessagePostingErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
266
420
  return guardVersion(params, version, error)
@@ -272,7 +426,7 @@ export function createContainer(provider) {
272
426
  },
273
427
  handleChatActionSubscribe(handler) {
274
428
  init();
275
- return transport.handleSubscription('host_chat_action_subscribe', (params, send, interrupt) => {
429
+ return handleChatActionSubscribeSlot((params, send, interrupt) => {
276
430
  const version = 'v1';
277
431
  return guardVersion(params, version, null)
278
432
  .map(params => handler(params, payload => send(enumValue(version, payload)), interrupt))
@@ -292,7 +446,7 @@ export function createContainer(provider) {
292
446
  },
293
447
  handleStatementStoreSubscribe(handler) {
294
448
  init();
295
- return transport.handleSubscription('remote_statement_store_subscribe', (params, send, interrupt) => {
449
+ return handleStatementStoreSubscribeSlot((params, send, interrupt) => {
296
450
  const version = 'v1';
297
451
  return guardVersion(params, version, null)
298
452
  .map(params => handler(params, payload => send(enumValue(version, payload)), interrupt))
@@ -304,7 +458,7 @@ export function createContainer(provider) {
304
458
  },
305
459
  handleStatementStoreCreateProof(handler) {
306
460
  init();
307
- return transport.handleRequest('remote_statement_store_create_proof', async (params) => {
461
+ return handleStatementStoreCreateProofSlot(async (params) => {
308
462
  const version = 'v1';
309
463
  const error = new StatementProofErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
310
464
  return guardVersion(params, version, error)
@@ -316,7 +470,7 @@ export function createContainer(provider) {
316
470
  },
317
471
  handleStatementStoreSubmit(handler) {
318
472
  init();
319
- return transport.handleRequest('remote_statement_store_submit', async (params) => {
473
+ return handleStatementStoreSubmitSlot(async (params) => {
320
474
  const version = 'v1';
321
475
  const error = new GenericError({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
322
476
  return guardVersion(params, version, error)
@@ -328,7 +482,7 @@ export function createContainer(provider) {
328
482
  },
329
483
  handlePreimageLookupSubscribe(handler) {
330
484
  init();
331
- return transport.handleSubscription('remote_preimage_lookup_subscribe', (params, send, interrupt) => {
485
+ return handlePreimageLookupSubscribeSlot((params, send, interrupt) => {
332
486
  const version = 'v1';
333
487
  return guardVersion(params, version, null)
334
488
  .map(params => handler(params, payload => send(enumValue(version, payload)), interrupt))
@@ -340,7 +494,7 @@ export function createContainer(provider) {
340
494
  },
341
495
  handlePreimageSubmit(handler) {
342
496
  init();
343
- return transport.handleRequest('remote_preimage_submit', async (params) => {
497
+ return handlePreimageSubmitSlot(async (params) => {
344
498
  const version = 'v1';
345
499
  const error = new PreimageSubmitErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
346
500
  return guardVersion(params, version, error)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@novasamatech/host-container",
3
3
  "type": "module",
4
- "version": "0.6.8",
4
+ "version": "0.6.10",
5
5
  "description": "Host container for hosting and managing products within the Polkadot ecosystem.",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
@@ -27,7 +27,7 @@
27
27
  "dependencies": {
28
28
  "@polkadot-api/utils": "^0.2.0",
29
29
  "@polkadot-api/json-rpc-provider": "^0.0.4",
30
- "@novasamatech/host-api": "0.6.8",
30
+ "@novasamatech/host-api": "0.6.10",
31
31
  "nanoid": "5.1.7"
32
32
  },
33
33
  "devDependencies": {