@novasamatech/host-container 0.5.4-9 → 0.5.5
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/README.md +143 -53
- package/dist/createContainer.js +107 -35
- package/dist/types.d.ts +26 -20
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -15,6 +15,8 @@ npm install @novasamatech/host-container --save -E
|
|
|
15
15
|
|
|
16
16
|
### Basic Container Setup
|
|
17
17
|
|
|
18
|
+
#### iframe
|
|
19
|
+
|
|
18
20
|
```ts
|
|
19
21
|
import { createContainer, createIframeProvider } from '@novasamatech/host-container';
|
|
20
22
|
|
|
@@ -29,12 +31,28 @@ const container = createContainer(provider);
|
|
|
29
31
|
document.body.appendChild(iframe);
|
|
30
32
|
```
|
|
31
33
|
|
|
34
|
+
#### webview
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { createContainer, createWebviewProvider } from '@novasamatech/host-container';
|
|
38
|
+
|
|
39
|
+
const webview = document.createElement('webview');
|
|
40
|
+
|
|
41
|
+
const provider = createWebviewProvider({
|
|
42
|
+
webview,
|
|
43
|
+
openDevTools: false,
|
|
44
|
+
});
|
|
45
|
+
const container = createContainer(provider);
|
|
46
|
+
|
|
47
|
+
document.body.appendChild(webview);
|
|
48
|
+
```
|
|
49
|
+
|
|
32
50
|
## API reference
|
|
33
51
|
|
|
34
|
-
###
|
|
52
|
+
### handleFeatureSupported
|
|
35
53
|
|
|
36
54
|
```ts
|
|
37
|
-
container.
|
|
55
|
+
container.handleFeatureSupported((params, { ok, err }) => {
|
|
38
56
|
if (params.tag === 'Chat') {
|
|
39
57
|
return ok(supportedChains.has(params.value));
|
|
40
58
|
}
|
|
@@ -42,32 +60,61 @@ container.handleFeature((params, { ok, err }) => {
|
|
|
42
60
|
});
|
|
43
61
|
```
|
|
44
62
|
|
|
45
|
-
###
|
|
63
|
+
### handleDevicePermission
|
|
46
64
|
|
|
47
65
|
```ts
|
|
48
|
-
container.
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
66
|
+
container.handleDevicePermission(async (request, { ok, err }) => {
|
|
67
|
+
const granted = await requestDevicePermission(request);
|
|
68
|
+
return ok(granted);
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### handlePermission
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
container.handlePermission(async (request, { ok, err }) => {
|
|
76
|
+
if (request.tag === 'ExternalRequest') {
|
|
77
|
+
const allowed = await checkExternalRequestPermission(request.value);
|
|
78
|
+
return ok(allowed);
|
|
79
|
+
}
|
|
80
|
+
if (request.tag === 'TransactionSubmit') {
|
|
81
|
+
return ok(true);
|
|
53
82
|
}
|
|
54
|
-
return
|
|
83
|
+
return ok(false);
|
|
84
|
+
});
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### handlePushNotification
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
container.handlePushNotification(async (notification, { ok, err }) => {
|
|
91
|
+
await showNotification(notification);
|
|
92
|
+
return ok(undefined);
|
|
55
93
|
});
|
|
56
94
|
```
|
|
57
95
|
|
|
58
|
-
###
|
|
96
|
+
### handleNavigateTo
|
|
59
97
|
|
|
60
98
|
```ts
|
|
61
|
-
container.
|
|
99
|
+
container.handleNavigateTo(async (url, { ok, err }) => {
|
|
100
|
+
await navigate(url);
|
|
101
|
+
return ok(undefined);
|
|
102
|
+
});
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### handleLocalStorageRead
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
container.handleLocalStorageRead(async (key, { ok, err }) => {
|
|
62
109
|
const value = await storage.get(key);
|
|
63
110
|
return ok(value ?? null);
|
|
64
111
|
});
|
|
65
112
|
```
|
|
66
113
|
|
|
67
|
-
###
|
|
114
|
+
### handleLocalStorageWrite
|
|
68
115
|
|
|
69
116
|
```ts
|
|
70
|
-
container.
|
|
117
|
+
container.handleLocalStorageWrite(async ([key, value], { ok, err }) => {
|
|
71
118
|
try {
|
|
72
119
|
await storage.set(key, value);
|
|
73
120
|
return ok(undefined);
|
|
@@ -77,10 +124,10 @@ container.handleStorageWrite(async ([key, value], { ok, err }) => {
|
|
|
77
124
|
});
|
|
78
125
|
```
|
|
79
126
|
|
|
80
|
-
###
|
|
127
|
+
### handleLocalStorageClear
|
|
81
128
|
|
|
82
129
|
```ts
|
|
83
|
-
container.
|
|
130
|
+
container.handleLocalStorageClear(async (key, { ok, err }) => {
|
|
84
131
|
await storage.delete(key);
|
|
85
132
|
return ok(undefined);
|
|
86
133
|
});
|
|
@@ -184,15 +231,34 @@ container.handleSignPayload(async (payload, { ok, err }) => {
|
|
|
184
231
|
});
|
|
185
232
|
```
|
|
186
233
|
|
|
187
|
-
###
|
|
234
|
+
### handleChatCreateRoom
|
|
188
235
|
|
|
189
236
|
```ts
|
|
190
|
-
container.
|
|
191
|
-
await chatService.
|
|
237
|
+
container.handleChatCreateRoom(async (room, { ok, err }) => {
|
|
238
|
+
await chatService.registerRoom(room);
|
|
192
239
|
return ok(undefined);
|
|
193
240
|
});
|
|
194
241
|
```
|
|
195
242
|
|
|
243
|
+
### handleChatBotRegistration
|
|
244
|
+
|
|
245
|
+
```ts
|
|
246
|
+
container.handleChatBotRegistration(async (bot, { ok, err }) => {
|
|
247
|
+
await chatService.registerBot(bot);
|
|
248
|
+
return ok(undefined);
|
|
249
|
+
});
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
### handleChatListSubscribe
|
|
253
|
+
|
|
254
|
+
```ts
|
|
255
|
+
container.handleChatListSubscribe((_, send, interrupt) => {
|
|
256
|
+
const listener = (rooms) => send(rooms);
|
|
257
|
+
chatService.on('roomsUpdate', listener);
|
|
258
|
+
return () => chatService.off('roomsUpdate', listener);
|
|
259
|
+
});
|
|
260
|
+
```
|
|
261
|
+
|
|
196
262
|
### handleChatPostMessage
|
|
197
263
|
|
|
198
264
|
```ts
|
|
@@ -212,6 +278,16 @@ container.handleChatActionSubscribe((_, send, interrupt) => {
|
|
|
212
278
|
});
|
|
213
279
|
```
|
|
214
280
|
|
|
281
|
+
### handleStatementStoreSubscribe
|
|
282
|
+
|
|
283
|
+
```ts
|
|
284
|
+
container.handleStatementStoreSubscribe((query, send, interrupt) => {
|
|
285
|
+
const listener = (statements) => send(statements);
|
|
286
|
+
statementStore.subscribe(query, listener);
|
|
287
|
+
return () => statementStore.unsubscribe(query, listener);
|
|
288
|
+
});
|
|
289
|
+
```
|
|
290
|
+
|
|
215
291
|
### handleStatementStoreCreateProof
|
|
216
292
|
|
|
217
293
|
```ts
|
|
@@ -225,66 +301,80 @@ container.handleStatementStoreCreateProof(async ([[dotnsId, derivationIndex], st
|
|
|
225
301
|
});
|
|
226
302
|
```
|
|
227
303
|
|
|
228
|
-
###
|
|
304
|
+
### handleStatementStoreSubmit
|
|
229
305
|
|
|
230
306
|
```ts
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
307
|
+
container.handleStatementStoreSubmit(async (statement, { ok, err }) => {
|
|
308
|
+
try {
|
|
309
|
+
await statementStore.submit(statement);
|
|
310
|
+
return ok(undefined);
|
|
311
|
+
} catch (e) {
|
|
312
|
+
return err({ tag: 'Unknown', value: { reason: e.message } });
|
|
313
|
+
}
|
|
314
|
+
});
|
|
238
315
|
```
|
|
239
316
|
|
|
240
|
-
###
|
|
317
|
+
### handlePreimageLookupSubscribe
|
|
241
318
|
|
|
242
319
|
```ts
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
320
|
+
container.handlePreimageLookupSubscribe((key, send, interrupt) => {
|
|
321
|
+
const listener = (value) => send(value);
|
|
322
|
+
preimageService.subscribe(key, listener);
|
|
323
|
+
return () => preimageService.unsubscribe(key, listener);
|
|
324
|
+
});
|
|
247
325
|
```
|
|
248
326
|
|
|
249
|
-
###
|
|
327
|
+
### handlePreimageSubmit
|
|
250
328
|
|
|
251
329
|
```ts
|
|
252
|
-
container.
|
|
330
|
+
container.handlePreimageSubmit(async (preimage, { ok, err }) => {
|
|
331
|
+
try {
|
|
332
|
+
const key = await preimageService.submit(preimage);
|
|
333
|
+
return ok(key);
|
|
334
|
+
} catch (e) {
|
|
335
|
+
return err({ tag: 'Unknown', value: { reason: e.message } });
|
|
336
|
+
}
|
|
337
|
+
});
|
|
253
338
|
```
|
|
254
339
|
|
|
255
|
-
###
|
|
340
|
+
### handleChainConnection
|
|
256
341
|
|
|
257
342
|
```ts
|
|
258
|
-
|
|
259
|
-
console.log('Connection status:', status);
|
|
260
|
-
});
|
|
261
|
-
```
|
|
343
|
+
import { getWsProvider } from 'polkadot-api/ws-provider';
|
|
262
344
|
|
|
263
|
-
|
|
345
|
+
const chains = new Map([
|
|
346
|
+
['0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3', 'wss://rpc.polkadot.io'],
|
|
347
|
+
['0xb0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe', 'wss://kusama-rpc.polkadot.io'],
|
|
348
|
+
]);
|
|
264
349
|
|
|
265
|
-
|
|
266
|
-
|
|
350
|
+
container.handleChainConnection((genesisHash) => {
|
|
351
|
+
const endpoint = chains.get(genesisHash);
|
|
352
|
+
if (!endpoint) return null;
|
|
353
|
+
return getWsProvider(endpoint);
|
|
354
|
+
});
|
|
355
|
+
```
|
|
267
356
|
|
|
268
|
-
|
|
357
|
+
### isReady
|
|
269
358
|
|
|
270
|
-
### Chain support check
|
|
271
359
|
```ts
|
|
272
|
-
const
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
});
|
|
360
|
+
const ready = await container.isReady();
|
|
361
|
+
if (ready) {
|
|
362
|
+
console.log('Container is ready');
|
|
363
|
+
}
|
|
277
364
|
```
|
|
278
365
|
|
|
279
|
-
###
|
|
366
|
+
### dispose
|
|
280
367
|
|
|
281
368
|
```ts
|
|
282
|
-
|
|
369
|
+
container.dispose();
|
|
370
|
+
```
|
|
283
371
|
|
|
284
|
-
|
|
285
|
-
const provider = getWsProvider('wss://...');
|
|
372
|
+
### subscribeProductConnectionStatus
|
|
286
373
|
|
|
287
|
-
|
|
374
|
+
```ts
|
|
375
|
+
const unsubscribe = container.subscribeProductConnectionStatus((status) => {
|
|
376
|
+
console.log('Connection status:', status);
|
|
377
|
+
});
|
|
288
378
|
```
|
|
289
379
|
|
|
290
380
|
## Known pitfalls
|
package/dist/createContainer.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChatMessagePostingErr, ChatRoomRegistrationErr, CreateProofErr, CreateTransactionErr, GenericError, RequestCredentialsErr, SigningErr, StatementProofErr, StorageErr, assertEnumVariant, createTransport, enumValue, isEnumVariant, resultErr, resultOk, } from '@novasamatech/host-api';
|
|
1
|
+
import { ChatBotRegistrationErr, ChatMessagePostingErr, ChatRoomRegistrationErr, CreateProofErr, CreateTransactionErr, GenericError, NavigateToErr, PreimageSubmitErr, RequestCredentialsErr, SigningErr, StatementProofErr, StorageErr, assertEnumVariant, createTransport, enumValue, isEnumVariant, resultErr, resultOk, } from '@novasamatech/host-api';
|
|
2
2
|
import { err, errAsync, ok, okAsync } from 'neverthrow';
|
|
3
3
|
const UNSUPPORTED_MESSAGE_FORMAT_ERROR = 'Unsupported message format';
|
|
4
4
|
function guardVersion(value, tag, error) {
|
|
@@ -17,9 +17,9 @@ export function createContainer(provider) {
|
|
|
17
17
|
transport.isReady();
|
|
18
18
|
}
|
|
19
19
|
return {
|
|
20
|
-
|
|
20
|
+
handleFeatureSupported(handler) {
|
|
21
21
|
init();
|
|
22
|
-
return transport.handleRequest('
|
|
22
|
+
return transport.handleRequest('host_feature_supported', async (message) => {
|
|
23
23
|
const version = 'v1';
|
|
24
24
|
const error = new GenericError({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
|
|
25
25
|
return guardVersion(message, version, error)
|
|
@@ -29,9 +29,57 @@ export function createContainer(provider) {
|
|
|
29
29
|
.unwrapOr(enumValue(version, resultErr(error)));
|
|
30
30
|
});
|
|
31
31
|
},
|
|
32
|
+
handleDevicePermission(handler) {
|
|
33
|
+
init();
|
|
34
|
+
return transport.handleRequest('host_device_permission', async (message) => {
|
|
35
|
+
const version = 'v1';
|
|
36
|
+
const error = new GenericError({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
|
|
37
|
+
return guardVersion(message, version, error)
|
|
38
|
+
.asyncMap(async (params) => handler(params, { ok: (okAsync), err: (errAsync) }))
|
|
39
|
+
.andThen(r => r.map(r => enumValue(version, resultOk(r))))
|
|
40
|
+
.orElse(r => ok(enumValue(version, resultErr(r))))
|
|
41
|
+
.unwrapOr(enumValue(version, resultErr(error)));
|
|
42
|
+
});
|
|
43
|
+
},
|
|
44
|
+
handlePermission(handler) {
|
|
45
|
+
init();
|
|
46
|
+
return transport.handleRequest('remote_permission', async (message) => {
|
|
47
|
+
const version = 'v1';
|
|
48
|
+
const error = new GenericError({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
|
|
49
|
+
return guardVersion(message, version, error)
|
|
50
|
+
.asyncMap(async (params) => handler(params, { ok: (okAsync), err: (errAsync) }))
|
|
51
|
+
.andThen(r => r.map(r => enumValue(version, resultOk(r))))
|
|
52
|
+
.orElse(r => ok(enumValue(version, resultErr(r))))
|
|
53
|
+
.unwrapOr(enumValue(version, resultErr(error)));
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
handlePushNotification(handler) {
|
|
57
|
+
init();
|
|
58
|
+
return transport.handleRequest('host_push_notification', async (message) => {
|
|
59
|
+
const version = 'v1';
|
|
60
|
+
const error = new GenericError({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
|
|
61
|
+
return guardVersion(message, version, error)
|
|
62
|
+
.asyncMap(async (params) => handler(params, { ok: (okAsync), err: (errAsync) }))
|
|
63
|
+
.andThen(r => r.map(r => enumValue(version, resultOk(r))))
|
|
64
|
+
.orElse(r => ok(enumValue(version, resultErr(r))))
|
|
65
|
+
.unwrapOr(enumValue(version, resultErr(error)));
|
|
66
|
+
});
|
|
67
|
+
},
|
|
68
|
+
handleNavigateTo(handler) {
|
|
69
|
+
init();
|
|
70
|
+
return transport.handleRequest('host_navigate_to', async (message) => {
|
|
71
|
+
const version = 'v1';
|
|
72
|
+
const error = new NavigateToErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
|
|
73
|
+
return guardVersion(message, version, error)
|
|
74
|
+
.asyncMap(async (params) => handler(params, { ok: (okAsync), err: (errAsync) }))
|
|
75
|
+
.andThen(r => r.map(r => enumValue(version, resultOk(r))))
|
|
76
|
+
.orElse(r => ok(enumValue(version, resultErr(r))))
|
|
77
|
+
.unwrapOr(enumValue(version, resultErr(error)));
|
|
78
|
+
});
|
|
79
|
+
},
|
|
32
80
|
handleLocalStorageRead(handler) {
|
|
33
81
|
init();
|
|
34
|
-
return transport.handleRequest('
|
|
82
|
+
return transport.handleRequest('host_local_storage_read', async (message) => {
|
|
35
83
|
const version = 'v1';
|
|
36
84
|
const error = new StorageErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
|
|
37
85
|
return guardVersion(message, version, error)
|
|
@@ -43,7 +91,7 @@ export function createContainer(provider) {
|
|
|
43
91
|
},
|
|
44
92
|
handleLocalStorageWrite(handler) {
|
|
45
93
|
init();
|
|
46
|
-
return transport.handleRequest('
|
|
94
|
+
return transport.handleRequest('host_local_storage_write', async (message) => {
|
|
47
95
|
const version = 'v1';
|
|
48
96
|
const error = new StorageErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
|
|
49
97
|
return guardVersion(message, version, error)
|
|
@@ -55,7 +103,7 @@ export function createContainer(provider) {
|
|
|
55
103
|
},
|
|
56
104
|
handleLocalStorageClear(handler) {
|
|
57
105
|
init();
|
|
58
|
-
return transport.handleRequest('
|
|
106
|
+
return transport.handleRequest('host_local_storage_clear', async (params) => {
|
|
59
107
|
const version = 'v1';
|
|
60
108
|
const error = new StorageErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
|
|
61
109
|
return guardVersion(params, version, error)
|
|
@@ -67,7 +115,7 @@ export function createContainer(provider) {
|
|
|
67
115
|
},
|
|
68
116
|
handleAccountGet(handler) {
|
|
69
117
|
init();
|
|
70
|
-
return transport.handleRequest('
|
|
118
|
+
return transport.handleRequest('host_account_get', async (params) => {
|
|
71
119
|
const version = 'v1';
|
|
72
120
|
const error = new RequestCredentialsErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
|
|
73
121
|
return guardVersion(params, version, error)
|
|
@@ -79,7 +127,7 @@ export function createContainer(provider) {
|
|
|
79
127
|
},
|
|
80
128
|
handleAccountGetAlias(handler) {
|
|
81
129
|
init();
|
|
82
|
-
return transport.handleRequest('
|
|
130
|
+
return transport.handleRequest('host_account_get_alias', async (params) => {
|
|
83
131
|
const version = 'v1';
|
|
84
132
|
const error = new RequestCredentialsErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
|
|
85
133
|
return guardVersion(params, version, error)
|
|
@@ -91,7 +139,7 @@ export function createContainer(provider) {
|
|
|
91
139
|
},
|
|
92
140
|
handleAccountCreateProof(handler) {
|
|
93
141
|
init();
|
|
94
|
-
return transport.handleRequest('
|
|
142
|
+
return transport.handleRequest('host_account_create_proof', async (params) => {
|
|
95
143
|
const version = 'v1';
|
|
96
144
|
const error = new CreateProofErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
|
|
97
145
|
return guardVersion(params, version, error)
|
|
@@ -103,7 +151,7 @@ export function createContainer(provider) {
|
|
|
103
151
|
},
|
|
104
152
|
handleGetNonProductAccounts(handler) {
|
|
105
153
|
init();
|
|
106
|
-
return transport.handleRequest('
|
|
154
|
+
return transport.handleRequest('host_get_non_product_accounts', async (params) => {
|
|
107
155
|
const version = 'v1';
|
|
108
156
|
const error = new RequestCredentialsErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
|
|
109
157
|
return guardVersion(params, version, error)
|
|
@@ -115,7 +163,7 @@ export function createContainer(provider) {
|
|
|
115
163
|
},
|
|
116
164
|
handleCreateTransaction(handler) {
|
|
117
165
|
init();
|
|
118
|
-
return transport.handleRequest('
|
|
166
|
+
return transport.handleRequest('host_create_transaction', async (params) => {
|
|
119
167
|
const version = 'v1';
|
|
120
168
|
const error = new CreateTransactionErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
|
|
121
169
|
return guardVersion(params, version, error)
|
|
@@ -127,7 +175,7 @@ export function createContainer(provider) {
|
|
|
127
175
|
},
|
|
128
176
|
handleCreateTransactionWithNonProductAccount(handler) {
|
|
129
177
|
init();
|
|
130
|
-
return transport.handleRequest('
|
|
178
|
+
return transport.handleRequest('host_create_transaction_with_non_product_account', async (params) => {
|
|
131
179
|
const version = 'v1';
|
|
132
180
|
const error = new CreateTransactionErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
|
|
133
181
|
return guardVersion(params, version, error)
|
|
@@ -139,7 +187,7 @@ export function createContainer(provider) {
|
|
|
139
187
|
},
|
|
140
188
|
handleSignRaw(handler) {
|
|
141
189
|
init();
|
|
142
|
-
return transport.handleRequest('
|
|
190
|
+
return transport.handleRequest('host_sign_raw', async (params) => {
|
|
143
191
|
const version = 'v1';
|
|
144
192
|
const error = new SigningErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
|
|
145
193
|
return guardVersion(params, version, error)
|
|
@@ -151,7 +199,7 @@ export function createContainer(provider) {
|
|
|
151
199
|
},
|
|
152
200
|
handleSignPayload(handler) {
|
|
153
201
|
init();
|
|
154
|
-
return transport.handleRequest('
|
|
202
|
+
return transport.handleRequest('host_sign_payload', async (params) => {
|
|
155
203
|
const version = 'v1';
|
|
156
204
|
const error = new SigningErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
|
|
157
205
|
return guardVersion(params, version, error)
|
|
@@ -163,7 +211,7 @@ export function createContainer(provider) {
|
|
|
163
211
|
},
|
|
164
212
|
handleChatCreateRoom(handler) {
|
|
165
213
|
init();
|
|
166
|
-
return transport.handleRequest('
|
|
214
|
+
return transport.handleRequest('host_chat_create_room', async (params) => {
|
|
167
215
|
const version = 'v1';
|
|
168
216
|
const error = new ChatRoomRegistrationErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
|
|
169
217
|
return guardVersion(params, version, error)
|
|
@@ -173,9 +221,21 @@ export function createContainer(provider) {
|
|
|
173
221
|
.unwrapOr(enumValue(version, resultErr(error)));
|
|
174
222
|
});
|
|
175
223
|
},
|
|
224
|
+
handleChatBotRegistration(handler) {
|
|
225
|
+
init();
|
|
226
|
+
return transport.handleRequest('host_chat_register_bot', async (params) => {
|
|
227
|
+
const version = 'v1';
|
|
228
|
+
const error = new ChatBotRegistrationErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
|
|
229
|
+
return guardVersion(params, version, error)
|
|
230
|
+
.asyncMap(async (params) => handler(params, { ok: (okAsync), err: (errAsync) }))
|
|
231
|
+
.andThen(r => r.map(r => enumValue(version, resultOk(r))))
|
|
232
|
+
.orElse(r => ok(enumValue(version, resultErr(r))))
|
|
233
|
+
.unwrapOr(enumValue(version, resultErr(error)));
|
|
234
|
+
});
|
|
235
|
+
},
|
|
176
236
|
handleChatListSubscribe(handler) {
|
|
177
237
|
init();
|
|
178
|
-
return transport.handleSubscription('
|
|
238
|
+
return transport.handleSubscription('host_chat_list_subscribe', (params, send, interrupt) => {
|
|
179
239
|
const version = 'v1';
|
|
180
240
|
return guardVersion(params, version, null)
|
|
181
241
|
.map(params => handler(params, payload => send(enumValue(version, payload)), interrupt))
|
|
@@ -187,7 +247,7 @@ export function createContainer(provider) {
|
|
|
187
247
|
},
|
|
188
248
|
handleChatPostMessage(handler) {
|
|
189
249
|
init();
|
|
190
|
-
return transport.handleRequest('
|
|
250
|
+
return transport.handleRequest('host_chat_post_message', async (params) => {
|
|
191
251
|
const version = 'v1';
|
|
192
252
|
const error = new ChatMessagePostingErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
|
|
193
253
|
return guardVersion(params, version, error)
|
|
@@ -199,7 +259,7 @@ export function createContainer(provider) {
|
|
|
199
259
|
},
|
|
200
260
|
handleChatActionSubscribe(handler) {
|
|
201
261
|
init();
|
|
202
|
-
return transport.handleSubscription('
|
|
262
|
+
return transport.handleSubscription('host_chat_action_subscribe', (params, send, interrupt) => {
|
|
203
263
|
const version = 'v1';
|
|
204
264
|
return guardVersion(params, version, null)
|
|
205
265
|
.map(params => handler(params, payload => send(enumValue(version, payload)), interrupt))
|
|
@@ -209,21 +269,9 @@ export function createContainer(provider) {
|
|
|
209
269
|
});
|
|
210
270
|
});
|
|
211
271
|
},
|
|
212
|
-
handleStatementStoreQuery(handler) {
|
|
213
|
-
init();
|
|
214
|
-
return transport.handleRequest('statement_store_query', async (params) => {
|
|
215
|
-
const version = 'v1';
|
|
216
|
-
const error = new GenericError({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
|
|
217
|
-
return guardVersion(params, version, error)
|
|
218
|
-
.asyncMap(async (params) => handler(params, { ok: (okAsync), err: (errAsync) }))
|
|
219
|
-
.andThen(r => r.map(r => enumValue(version, resultOk(r))))
|
|
220
|
-
.orElse(r => ok(enumValue(version, resultErr(r))))
|
|
221
|
-
.unwrapOr(enumValue(version, resultErr(error)));
|
|
222
|
-
});
|
|
223
|
-
},
|
|
224
272
|
handleStatementStoreSubscribe(handler) {
|
|
225
273
|
init();
|
|
226
|
-
return transport.handleSubscription('
|
|
274
|
+
return transport.handleSubscription('remote_statement_store_subscribe', (params, send, interrupt) => {
|
|
227
275
|
const version = 'v1';
|
|
228
276
|
return guardVersion(params, version, null)
|
|
229
277
|
.map(params => handler(params, payload => send(enumValue(version, payload)), interrupt))
|
|
@@ -235,7 +283,7 @@ export function createContainer(provider) {
|
|
|
235
283
|
},
|
|
236
284
|
handleStatementStoreCreateProof(handler) {
|
|
237
285
|
init();
|
|
238
|
-
return transport.handleRequest('
|
|
286
|
+
return transport.handleRequest('remote_statement_store_create_proof', async (params) => {
|
|
239
287
|
const version = 'v1';
|
|
240
288
|
const error = new StatementProofErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
|
|
241
289
|
return guardVersion(params, version, error)
|
|
@@ -247,7 +295,7 @@ export function createContainer(provider) {
|
|
|
247
295
|
},
|
|
248
296
|
handleStatementStoreSubmit(handler) {
|
|
249
297
|
init();
|
|
250
|
-
return transport.handleRequest('
|
|
298
|
+
return transport.handleRequest('remote_statement_store_submit', async (params) => {
|
|
251
299
|
const version = 'v1';
|
|
252
300
|
const error = new GenericError({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
|
|
253
301
|
return guardVersion(params, version, error)
|
|
@@ -257,9 +305,33 @@ export function createContainer(provider) {
|
|
|
257
305
|
.unwrapOr(enumValue(version, resultErr(error)));
|
|
258
306
|
});
|
|
259
307
|
},
|
|
308
|
+
handlePreimageLookupSubscribe(handler) {
|
|
309
|
+
init();
|
|
310
|
+
return transport.handleSubscription('remote_preimage_lookup_subscribe', (params, send, interrupt) => {
|
|
311
|
+
const version = 'v1';
|
|
312
|
+
return guardVersion(params, version, null)
|
|
313
|
+
.map(params => handler(params, payload => send(enumValue(version, payload)), interrupt))
|
|
314
|
+
.orTee(interrupt)
|
|
315
|
+
.unwrapOr(() => {
|
|
316
|
+
/* empty */
|
|
317
|
+
});
|
|
318
|
+
});
|
|
319
|
+
},
|
|
320
|
+
handlePreimageSubmit(handler) {
|
|
321
|
+
init();
|
|
322
|
+
return transport.handleRequest('remote_preimage_submit', async (params) => {
|
|
323
|
+
const version = 'v1';
|
|
324
|
+
const error = new PreimageSubmitErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
|
|
325
|
+
return guardVersion(params, version, error)
|
|
326
|
+
.asyncMap(async (params) => handler(params, { ok: (okAsync), err: (errAsync) }))
|
|
327
|
+
.andThen(r => r.map(r => enumValue(version, resultOk(r))))
|
|
328
|
+
.orElse(r => ok(enumValue(version, resultErr(r))))
|
|
329
|
+
.unwrapOr(enumValue(version, resultErr(error)));
|
|
330
|
+
});
|
|
331
|
+
},
|
|
260
332
|
handleChainConnection(factory) {
|
|
261
333
|
init();
|
|
262
|
-
return transport.handleSubscription('
|
|
334
|
+
return transport.handleSubscription('host_jsonrpc_message_subscribe', (params, send) => {
|
|
263
335
|
assertEnumVariant(params, 'v1', UNSUPPORTED_MESSAGE_FORMAT_ERROR);
|
|
264
336
|
const genesisHash = params.value;
|
|
265
337
|
const provider = factory(params.value);
|
|
@@ -274,7 +346,7 @@ export function createContainer(provider) {
|
|
|
274
346
|
unsubscribeDestroy();
|
|
275
347
|
connection.disconnect();
|
|
276
348
|
});
|
|
277
|
-
const unsubRequests = transport.handleRequest('
|
|
349
|
+
const unsubRequests = transport.handleRequest('host_jsonrpc_message_send', async (message) => {
|
|
278
350
|
assertEnumVariant(message, 'v1', UNSUPPORTED_MESSAGE_FORMAT_ERROR);
|
|
279
351
|
const [requestedGenesisHash, payload] = message.value;
|
|
280
352
|
if (requestedGenesisHash === genesisHash) {
|
package/dist/types.d.ts
CHANGED
|
@@ -50,26 +50,32 @@ type InferRequestHandler<V extends string, T extends VersionedProtocolRequest> =
|
|
|
50
50
|
type InferSubscribeHandler<V extends string, T extends VersionedProtocolSubscription> = (callback: (params: WithVersion<V, Value<T['start']>>, send: (payload: WithVersion<V, Value<T['receive']>>) => void, interrupt: VoidFunction) => VoidFunction) => VoidFunction;
|
|
51
51
|
type InferHandler<V extends string, T extends VersionedProtocolRequest | VersionedProtocolSubscription> = T extends VersionedProtocolRequest ? InferRequestHandler<V, T> : T extends VersionedProtocolSubscription ? InferSubscribeHandler<V, T> : never;
|
|
52
52
|
export type Container = {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
53
|
+
handleFeatureSupported: InferHandler<'v1', HostApiProtocol['host_feature_supported']>;
|
|
54
|
+
handleDevicePermission: InferHandler<'v1', HostApiProtocol['host_device_permission']>;
|
|
55
|
+
handlePermission: InferHandler<'v1', HostApiProtocol['remote_permission']>;
|
|
56
|
+
handlePushNotification: InferHandler<'v1', HostApiProtocol['host_push_notification']>;
|
|
57
|
+
handleNavigateTo: InferHandler<'v1', HostApiProtocol['host_navigate_to']>;
|
|
58
|
+
handleLocalStorageRead: InferHandler<'v1', HostApiProtocol['host_local_storage_read']>;
|
|
59
|
+
handleLocalStorageWrite: InferHandler<'v1', HostApiProtocol['host_local_storage_write']>;
|
|
60
|
+
handleLocalStorageClear: InferHandler<'v1', HostApiProtocol['host_local_storage_clear']>;
|
|
61
|
+
handleAccountGet: InferHandler<'v1', HostApiProtocol['host_account_get']>;
|
|
62
|
+
handleAccountGetAlias: InferHandler<'v1', HostApiProtocol['host_account_get_alias']>;
|
|
63
|
+
handleAccountCreateProof: InferHandler<'v1', HostApiProtocol['host_account_create_proof']>;
|
|
64
|
+
handleGetNonProductAccounts: InferHandler<'v1', HostApiProtocol['host_get_non_product_accounts']>;
|
|
65
|
+
handleCreateTransaction: InferHandler<'v1', HostApiProtocol['host_create_transaction']>;
|
|
66
|
+
handleCreateTransactionWithNonProductAccount: InferHandler<'v1', HostApiProtocol['host_create_transaction_with_non_product_account']>;
|
|
67
|
+
handleSignRaw: InferHandler<'v1', HostApiProtocol['host_sign_raw']>;
|
|
68
|
+
handleSignPayload: InferHandler<'v1', HostApiProtocol['host_sign_payload']>;
|
|
69
|
+
handleChatCreateRoom: InferHandler<'v1', HostApiProtocol['host_chat_create_room']>;
|
|
70
|
+
handleChatBotRegistration: InferHandler<'v1', HostApiProtocol['host_chat_register_bot']>;
|
|
71
|
+
handleChatListSubscribe: InferHandler<'v1', HostApiProtocol['host_chat_list_subscribe']>;
|
|
72
|
+
handleChatPostMessage: InferHandler<'v1', HostApiProtocol['host_chat_post_message']>;
|
|
73
|
+
handleChatActionSubscribe: InferHandler<'v1', HostApiProtocol['host_chat_action_subscribe']>;
|
|
74
|
+
handleStatementStoreSubscribe: InferHandler<'v1', HostApiProtocol['remote_statement_store_subscribe']>;
|
|
75
|
+
handleStatementStoreCreateProof: InferHandler<'v1', HostApiProtocol['remote_statement_store_create_proof']>;
|
|
76
|
+
handleStatementStoreSubmit: InferHandler<'v1', HostApiProtocol['remote_statement_store_submit']>;
|
|
77
|
+
handlePreimageLookupSubscribe: InferHandler<'v1', HostApiProtocol['remote_preimage_lookup_subscribe']>;
|
|
78
|
+
handlePreimageSubmit: InferHandler<'v1', HostApiProtocol['remote_preimage_submit']>;
|
|
73
79
|
handleChainConnection: (factory: (genesisHash: HexString) => JsonRpcProvider | null) => VoidFunction;
|
|
74
80
|
isReady(): Promise<boolean>;
|
|
75
81
|
dispose(): void;
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@novasamatech/host-container",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.5",
|
|
5
5
|
"description": "Host container for hosting and managing products within the Polkadot ecosystem.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/
|
|
9
|
+
"url": "git+https://github.com/Polkadot-Community-Foundation/triangle-js-sdks.git"
|
|
10
10
|
},
|
|
11
11
|
"keywords": [
|
|
12
12
|
"polkadot",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@polkadot-api/utils": "^0.2.0",
|
|
30
30
|
"@polkadot-api/json-rpc-provider": "^0.0.4",
|
|
31
|
-
"@novasamatech/host-api": "0.5.
|
|
31
|
+
"@novasamatech/host-api": "0.5.5",
|
|
32
32
|
"nanoid": "5.1.6"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|