@novasamatech/host-container 0.5.4 → 0.6.0
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 +92 -7
- package/dist/createContainer.js +113 -33
- package/dist/types.d.ts +30 -22
- package/dist/types.js +1 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -49,10 +49,10 @@ document.body.appendChild(webview);
|
|
|
49
49
|
|
|
50
50
|
## API reference
|
|
51
51
|
|
|
52
|
-
###
|
|
52
|
+
### handleFeatureSupported
|
|
53
53
|
|
|
54
54
|
```ts
|
|
55
|
-
container.
|
|
55
|
+
container.handleFeatureSupported((params, { ok, err }) => {
|
|
56
56
|
if (params.tag === 'Chat') {
|
|
57
57
|
return ok(supportedChains.has(params.value));
|
|
58
58
|
}
|
|
@@ -60,6 +60,48 @@ container.handleFeature((params, { ok, err }) => {
|
|
|
60
60
|
});
|
|
61
61
|
```
|
|
62
62
|
|
|
63
|
+
### handleDevicePermission
|
|
64
|
+
|
|
65
|
+
```ts
|
|
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);
|
|
82
|
+
}
|
|
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);
|
|
93
|
+
});
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### handleNavigateTo
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
container.handleNavigateTo(async (url, { ok, err }) => {
|
|
100
|
+
await navigate(url);
|
|
101
|
+
return ok(undefined);
|
|
102
|
+
});
|
|
103
|
+
```
|
|
104
|
+
|
|
63
105
|
### handleLocalStorageRead
|
|
64
106
|
|
|
65
107
|
```ts
|
|
@@ -91,6 +133,16 @@ container.handleLocalStorageClear(async (key, { ok, err }) => {
|
|
|
91
133
|
});
|
|
92
134
|
```
|
|
93
135
|
|
|
136
|
+
### handleAccountConnectionStatusSubscribe
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
container.handleAccountConnectionStatusSubscribe((_, send, interrupt) => {
|
|
140
|
+
const listener = (status) => send(status);
|
|
141
|
+
accountService.on('connectionStatusChange', listener);
|
|
142
|
+
return () => accountService.off('connectionStatusChange', listener);
|
|
143
|
+
});
|
|
144
|
+
```
|
|
145
|
+
|
|
94
146
|
### handleAccountGet
|
|
95
147
|
|
|
96
148
|
```ts
|
|
@@ -198,7 +250,14 @@ container.handleChatCreateRoom(async (room, { ok, err }) => {
|
|
|
198
250
|
});
|
|
199
251
|
```
|
|
200
252
|
|
|
201
|
-
|
|
253
|
+
### handleChatBotRegistration
|
|
254
|
+
|
|
255
|
+
```ts
|
|
256
|
+
container.handleChatBotRegistration(async (bot, { ok, err }) => {
|
|
257
|
+
await chatService.registerBot(bot);
|
|
258
|
+
return ok(undefined);
|
|
259
|
+
});
|
|
260
|
+
```
|
|
202
261
|
|
|
203
262
|
### handleChatListSubscribe
|
|
204
263
|
|
|
@@ -229,13 +288,16 @@ container.handleChatActionSubscribe((_, send, interrupt) => {
|
|
|
229
288
|
});
|
|
230
289
|
```
|
|
231
290
|
|
|
232
|
-
###
|
|
291
|
+
### renderChatCustomMessage
|
|
233
292
|
|
|
234
293
|
```ts
|
|
235
|
-
container.
|
|
236
|
-
|
|
237
|
-
|
|
294
|
+
const subscription = container.renderChatCustomMessage('my-custom-type', payload, (node) => {
|
|
295
|
+
// node is a CustomRendererNode tree describing the UI to render
|
|
296
|
+
console.log('Render custom message:', node);
|
|
238
297
|
});
|
|
298
|
+
|
|
299
|
+
// Unsubscribe when done
|
|
300
|
+
subscription.unsubscribe();
|
|
239
301
|
```
|
|
240
302
|
|
|
241
303
|
### handleStatementStoreSubscribe
|
|
@@ -274,6 +336,29 @@ container.handleStatementStoreSubmit(async (statement, { ok, err }) => {
|
|
|
274
336
|
});
|
|
275
337
|
```
|
|
276
338
|
|
|
339
|
+
### handlePreimageLookupSubscribe
|
|
340
|
+
|
|
341
|
+
```ts
|
|
342
|
+
container.handlePreimageLookupSubscribe((key, send, interrupt) => {
|
|
343
|
+
const listener = (value) => send(value);
|
|
344
|
+
preimageService.subscribe(key, listener);
|
|
345
|
+
return () => preimageService.unsubscribe(key, listener);
|
|
346
|
+
});
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
### handlePreimageSubmit
|
|
350
|
+
|
|
351
|
+
```ts
|
|
352
|
+
container.handlePreimageSubmit(async (preimage, { ok, err }) => {
|
|
353
|
+
try {
|
|
354
|
+
const key = await preimageService.submit(preimage);
|
|
355
|
+
return ok(key);
|
|
356
|
+
} catch (e) {
|
|
357
|
+
return err({ tag: 'Unknown', value: { reason: e.message } });
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
```
|
|
361
|
+
|
|
277
362
|
### handleChainConnection
|
|
278
363
|
|
|
279
364
|
```ts
|
package/dist/createContainer.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChatBotRegistrationErr, 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)
|
|
@@ -65,9 +113,21 @@ export function createContainer(provider) {
|
|
|
65
113
|
.unwrapOr(enumValue(version, resultErr(error)));
|
|
66
114
|
});
|
|
67
115
|
},
|
|
116
|
+
handleAccountConnectionStatusSubscribe(handler) {
|
|
117
|
+
init();
|
|
118
|
+
return transport.handleSubscription('host_account_connection_status_subscribe', (params, send, interrupt) => {
|
|
119
|
+
const version = 'v1';
|
|
120
|
+
return guardVersion(params, version, null)
|
|
121
|
+
.map(params => handler(params, payload => send(enumValue(version, payload)), interrupt))
|
|
122
|
+
.orTee(interrupt)
|
|
123
|
+
.unwrapOr(() => {
|
|
124
|
+
/* empty */
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
},
|
|
68
128
|
handleAccountGet(handler) {
|
|
69
129
|
init();
|
|
70
|
-
return transport.handleRequest('
|
|
130
|
+
return transport.handleRequest('host_account_get', async (params) => {
|
|
71
131
|
const version = 'v1';
|
|
72
132
|
const error = new RequestCredentialsErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
|
|
73
133
|
return guardVersion(params, version, error)
|
|
@@ -79,7 +139,7 @@ export function createContainer(provider) {
|
|
|
79
139
|
},
|
|
80
140
|
handleAccountGetAlias(handler) {
|
|
81
141
|
init();
|
|
82
|
-
return transport.handleRequest('
|
|
142
|
+
return transport.handleRequest('host_account_get_alias', async (params) => {
|
|
83
143
|
const version = 'v1';
|
|
84
144
|
const error = new RequestCredentialsErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
|
|
85
145
|
return guardVersion(params, version, error)
|
|
@@ -91,7 +151,7 @@ export function createContainer(provider) {
|
|
|
91
151
|
},
|
|
92
152
|
handleAccountCreateProof(handler) {
|
|
93
153
|
init();
|
|
94
|
-
return transport.handleRequest('
|
|
154
|
+
return transport.handleRequest('host_account_create_proof', async (params) => {
|
|
95
155
|
const version = 'v1';
|
|
96
156
|
const error = new CreateProofErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
|
|
97
157
|
return guardVersion(params, version, error)
|
|
@@ -103,7 +163,7 @@ export function createContainer(provider) {
|
|
|
103
163
|
},
|
|
104
164
|
handleGetNonProductAccounts(handler) {
|
|
105
165
|
init();
|
|
106
|
-
return transport.handleRequest('
|
|
166
|
+
return transport.handleRequest('host_get_non_product_accounts', async (params) => {
|
|
107
167
|
const version = 'v1';
|
|
108
168
|
const error = new RequestCredentialsErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
|
|
109
169
|
return guardVersion(params, version, error)
|
|
@@ -115,7 +175,7 @@ export function createContainer(provider) {
|
|
|
115
175
|
},
|
|
116
176
|
handleCreateTransaction(handler) {
|
|
117
177
|
init();
|
|
118
|
-
return transport.handleRequest('
|
|
178
|
+
return transport.handleRequest('host_create_transaction', async (params) => {
|
|
119
179
|
const version = 'v1';
|
|
120
180
|
const error = new CreateTransactionErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
|
|
121
181
|
return guardVersion(params, version, error)
|
|
@@ -127,7 +187,7 @@ export function createContainer(provider) {
|
|
|
127
187
|
},
|
|
128
188
|
handleCreateTransactionWithNonProductAccount(handler) {
|
|
129
189
|
init();
|
|
130
|
-
return transport.handleRequest('
|
|
190
|
+
return transport.handleRequest('host_create_transaction_with_non_product_account', async (params) => {
|
|
131
191
|
const version = 'v1';
|
|
132
192
|
const error = new CreateTransactionErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
|
|
133
193
|
return guardVersion(params, version, error)
|
|
@@ -139,7 +199,7 @@ export function createContainer(provider) {
|
|
|
139
199
|
},
|
|
140
200
|
handleSignRaw(handler) {
|
|
141
201
|
init();
|
|
142
|
-
return transport.handleRequest('
|
|
202
|
+
return transport.handleRequest('host_sign_raw', async (params) => {
|
|
143
203
|
const version = 'v1';
|
|
144
204
|
const error = new SigningErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
|
|
145
205
|
return guardVersion(params, version, error)
|
|
@@ -151,7 +211,7 @@ export function createContainer(provider) {
|
|
|
151
211
|
},
|
|
152
212
|
handleSignPayload(handler) {
|
|
153
213
|
init();
|
|
154
|
-
return transport.handleRequest('
|
|
214
|
+
return transport.handleRequest('host_sign_payload', async (params) => {
|
|
155
215
|
const version = 'v1';
|
|
156
216
|
const error = new SigningErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
|
|
157
217
|
return guardVersion(params, version, error)
|
|
@@ -163,7 +223,7 @@ export function createContainer(provider) {
|
|
|
163
223
|
},
|
|
164
224
|
handleChatCreateRoom(handler) {
|
|
165
225
|
init();
|
|
166
|
-
return transport.handleRequest('
|
|
226
|
+
return transport.handleRequest('host_chat_create_room', async (params) => {
|
|
167
227
|
const version = 'v1';
|
|
168
228
|
const error = new ChatRoomRegistrationErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
|
|
169
229
|
return guardVersion(params, version, error)
|
|
@@ -175,7 +235,7 @@ export function createContainer(provider) {
|
|
|
175
235
|
},
|
|
176
236
|
handleChatBotRegistration(handler) {
|
|
177
237
|
init();
|
|
178
|
-
return transport.handleRequest('
|
|
238
|
+
return transport.handleRequest('host_chat_register_bot', async (params) => {
|
|
179
239
|
const version = 'v1';
|
|
180
240
|
const error = new ChatBotRegistrationErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
|
|
181
241
|
return guardVersion(params, version, error)
|
|
@@ -187,7 +247,7 @@ export function createContainer(provider) {
|
|
|
187
247
|
},
|
|
188
248
|
handleChatListSubscribe(handler) {
|
|
189
249
|
init();
|
|
190
|
-
return transport.handleSubscription('
|
|
250
|
+
return transport.handleSubscription('host_chat_list_subscribe', (params, send, interrupt) => {
|
|
191
251
|
const version = 'v1';
|
|
192
252
|
return guardVersion(params, version, null)
|
|
193
253
|
.map(params => handler(params, payload => send(enumValue(version, payload)), interrupt))
|
|
@@ -199,7 +259,7 @@ export function createContainer(provider) {
|
|
|
199
259
|
},
|
|
200
260
|
handleChatPostMessage(handler) {
|
|
201
261
|
init();
|
|
202
|
-
return transport.handleRequest('
|
|
262
|
+
return transport.handleRequest('host_chat_post_message', async (params) => {
|
|
203
263
|
const version = 'v1';
|
|
204
264
|
const error = new ChatMessagePostingErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
|
|
205
265
|
return guardVersion(params, version, error)
|
|
@@ -211,7 +271,7 @@ export function createContainer(provider) {
|
|
|
211
271
|
},
|
|
212
272
|
handleChatActionSubscribe(handler) {
|
|
213
273
|
init();
|
|
214
|
-
return transport.handleSubscription('
|
|
274
|
+
return transport.handleSubscription('host_chat_action_subscribe', (params, send, interrupt) => {
|
|
215
275
|
const version = 'v1';
|
|
216
276
|
return guardVersion(params, version, null)
|
|
217
277
|
.map(params => handler(params, payload => send(enumValue(version, payload)), interrupt))
|
|
@@ -221,21 +281,17 @@ export function createContainer(provider) {
|
|
|
221
281
|
});
|
|
222
282
|
});
|
|
223
283
|
},
|
|
224
|
-
|
|
284
|
+
renderChatCustomMessage(messageType, payload, callback) {
|
|
225
285
|
init();
|
|
226
|
-
return transport.
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
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)));
|
|
286
|
+
return transport.subscribe('product_chat_custom_message_render_subscribe', enumValue('v1', { messageType, payload }), value => {
|
|
287
|
+
if (value.tag === 'v1') {
|
|
288
|
+
callback(value.value);
|
|
289
|
+
}
|
|
234
290
|
});
|
|
235
291
|
},
|
|
236
292
|
handleStatementStoreSubscribe(handler) {
|
|
237
293
|
init();
|
|
238
|
-
return transport.handleSubscription('
|
|
294
|
+
return transport.handleSubscription('remote_statement_store_subscribe', (params, send, interrupt) => {
|
|
239
295
|
const version = 'v1';
|
|
240
296
|
return guardVersion(params, version, null)
|
|
241
297
|
.map(params => handler(params, payload => send(enumValue(version, payload)), interrupt))
|
|
@@ -247,7 +303,7 @@ export function createContainer(provider) {
|
|
|
247
303
|
},
|
|
248
304
|
handleStatementStoreCreateProof(handler) {
|
|
249
305
|
init();
|
|
250
|
-
return transport.handleRequest('
|
|
306
|
+
return transport.handleRequest('remote_statement_store_create_proof', async (params) => {
|
|
251
307
|
const version = 'v1';
|
|
252
308
|
const error = new StatementProofErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
|
|
253
309
|
return guardVersion(params, version, error)
|
|
@@ -259,7 +315,7 @@ export function createContainer(provider) {
|
|
|
259
315
|
},
|
|
260
316
|
handleStatementStoreSubmit(handler) {
|
|
261
317
|
init();
|
|
262
|
-
return transport.handleRequest('
|
|
318
|
+
return transport.handleRequest('remote_statement_store_submit', async (params) => {
|
|
263
319
|
const version = 'v1';
|
|
264
320
|
const error = new GenericError({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
|
|
265
321
|
return guardVersion(params, version, error)
|
|
@@ -269,9 +325,33 @@ export function createContainer(provider) {
|
|
|
269
325
|
.unwrapOr(enumValue(version, resultErr(error)));
|
|
270
326
|
});
|
|
271
327
|
},
|
|
328
|
+
handlePreimageLookupSubscribe(handler) {
|
|
329
|
+
init();
|
|
330
|
+
return transport.handleSubscription('remote_preimage_lookup_subscribe', (params, send, interrupt) => {
|
|
331
|
+
const version = 'v1';
|
|
332
|
+
return guardVersion(params, version, null)
|
|
333
|
+
.map(params => handler(params, payload => send(enumValue(version, payload)), interrupt))
|
|
334
|
+
.orTee(interrupt)
|
|
335
|
+
.unwrapOr(() => {
|
|
336
|
+
/* empty */
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
},
|
|
340
|
+
handlePreimageSubmit(handler) {
|
|
341
|
+
init();
|
|
342
|
+
return transport.handleRequest('remote_preimage_submit', async (params) => {
|
|
343
|
+
const version = 'v1';
|
|
344
|
+
const error = new PreimageSubmitErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
|
|
345
|
+
return guardVersion(params, version, error)
|
|
346
|
+
.asyncMap(async (params) => handler(params, { ok: (okAsync), err: (errAsync) }))
|
|
347
|
+
.andThen(r => r.map(r => enumValue(version, resultOk(r))))
|
|
348
|
+
.orElse(r => ok(enumValue(version, resultErr(r))))
|
|
349
|
+
.unwrapOr(enumValue(version, resultErr(error)));
|
|
350
|
+
});
|
|
351
|
+
},
|
|
272
352
|
handleChainConnection(factory) {
|
|
273
353
|
init();
|
|
274
|
-
return transport.handleSubscription('
|
|
354
|
+
return transport.handleSubscription('host_jsonrpc_message_subscribe', (params, send) => {
|
|
275
355
|
assertEnumVariant(params, 'v1', UNSUPPORTED_MESSAGE_FORMAT_ERROR);
|
|
276
356
|
const genesisHash = params.value;
|
|
277
357
|
const provider = factory(params.value);
|
|
@@ -286,7 +366,7 @@ export function createContainer(provider) {
|
|
|
286
366
|
unsubscribeDestroy();
|
|
287
367
|
connection.disconnect();
|
|
288
368
|
});
|
|
289
|
-
const unsubRequests = transport.handleRequest('
|
|
369
|
+
const unsubRequests = transport.handleRequest('host_jsonrpc_message_send', async (message) => {
|
|
290
370
|
assertEnumVariant(message, 'v1', UNSUPPORTED_MESSAGE_FORMAT_ERROR);
|
|
291
371
|
const [requestedGenesisHash, payload] = message.value;
|
|
292
372
|
if (requestedGenesisHash === genesisHash) {
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { Codec, CodecType, ConnectionStatus, HexString, HostApiProtocol, VersionedProtocolRequest, VersionedProtocolSubscription } from '@novasamatech/host-api';
|
|
1
|
+
import type { Codec, CodecType, ConnectionStatus, HexString, HostApiProtocol, Subscription, VersionedProtocolRequest, VersionedProtocolSubscription } from '@novasamatech/host-api';
|
|
2
|
+
import { CustomRendererNode } from '@novasamatech/host-api';
|
|
2
3
|
import type { JsonRpcProvider } from '@polkadot-api/json-rpc-provider';
|
|
3
4
|
import type { ResultAsync, errAsync } from 'neverthrow';
|
|
4
5
|
import { okAsync } from 'neverthrow';
|
|
@@ -50,27 +51,34 @@ type InferRequestHandler<V extends string, T extends VersionedProtocolRequest> =
|
|
|
50
51
|
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
52
|
type InferHandler<V extends string, T extends VersionedProtocolRequest | VersionedProtocolSubscription> = T extends VersionedProtocolRequest ? InferRequestHandler<V, T> : T extends VersionedProtocolSubscription ? InferSubscribeHandler<V, T> : never;
|
|
52
53
|
export type Container = {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
54
|
+
handleFeatureSupported: InferHandler<'v1', HostApiProtocol['host_feature_supported']>;
|
|
55
|
+
handleDevicePermission: InferHandler<'v1', HostApiProtocol['host_device_permission']>;
|
|
56
|
+
handlePermission: InferHandler<'v1', HostApiProtocol['remote_permission']>;
|
|
57
|
+
handlePushNotification: InferHandler<'v1', HostApiProtocol['host_push_notification']>;
|
|
58
|
+
handleNavigateTo: InferHandler<'v1', HostApiProtocol['host_navigate_to']>;
|
|
59
|
+
handleLocalStorageRead: InferHandler<'v1', HostApiProtocol['host_local_storage_read']>;
|
|
60
|
+
handleLocalStorageWrite: InferHandler<'v1', HostApiProtocol['host_local_storage_write']>;
|
|
61
|
+
handleLocalStorageClear: InferHandler<'v1', HostApiProtocol['host_local_storage_clear']>;
|
|
62
|
+
handleAccountConnectionStatusSubscribe: InferHandler<'v1', HostApiProtocol['host_account_connection_status_subscribe']>;
|
|
63
|
+
handleAccountGet: InferHandler<'v1', HostApiProtocol['host_account_get']>;
|
|
64
|
+
handleAccountGetAlias: InferHandler<'v1', HostApiProtocol['host_account_get_alias']>;
|
|
65
|
+
handleAccountCreateProof: InferHandler<'v1', HostApiProtocol['host_account_create_proof']>;
|
|
66
|
+
handleGetNonProductAccounts: InferHandler<'v1', HostApiProtocol['host_get_non_product_accounts']>;
|
|
67
|
+
handleCreateTransaction: InferHandler<'v1', HostApiProtocol['host_create_transaction']>;
|
|
68
|
+
handleCreateTransactionWithNonProductAccount: InferHandler<'v1', HostApiProtocol['host_create_transaction_with_non_product_account']>;
|
|
69
|
+
handleSignRaw: InferHandler<'v1', HostApiProtocol['host_sign_raw']>;
|
|
70
|
+
handleSignPayload: InferHandler<'v1', HostApiProtocol['host_sign_payload']>;
|
|
71
|
+
handleChatCreateRoom: InferHandler<'v1', HostApiProtocol['host_chat_create_room']>;
|
|
72
|
+
handleChatBotRegistration: InferHandler<'v1', HostApiProtocol['host_chat_register_bot']>;
|
|
73
|
+
handleChatListSubscribe: InferHandler<'v1', HostApiProtocol['host_chat_list_subscribe']>;
|
|
74
|
+
handleChatPostMessage: InferHandler<'v1', HostApiProtocol['host_chat_post_message']>;
|
|
75
|
+
handleChatActionSubscribe: InferHandler<'v1', HostApiProtocol['host_chat_action_subscribe']>;
|
|
76
|
+
renderChatCustomMessage(messageType: string, payload: Uint8Array, callback: (node: CodecType<typeof CustomRendererNode>) => void): Subscription;
|
|
77
|
+
handleStatementStoreSubscribe: InferHandler<'v1', HostApiProtocol['remote_statement_store_subscribe']>;
|
|
78
|
+
handleStatementStoreCreateProof: InferHandler<'v1', HostApiProtocol['remote_statement_store_create_proof']>;
|
|
79
|
+
handleStatementStoreSubmit: InferHandler<'v1', HostApiProtocol['remote_statement_store_submit']>;
|
|
80
|
+
handlePreimageLookupSubscribe: InferHandler<'v1', HostApiProtocol['remote_preimage_lookup_subscribe']>;
|
|
81
|
+
handlePreimageSubmit: InferHandler<'v1', HostApiProtocol['remote_preimage_submit']>;
|
|
74
82
|
handleChainConnection: (factory: (genesisHash: HexString) => JsonRpcProvider | null) => VoidFunction;
|
|
75
83
|
isReady(): Promise<boolean>;
|
|
76
84
|
dispose(): void;
|
package/dist/types.js
CHANGED
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@novasamatech/host-container",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.6.0",
|
|
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.
|
|
31
|
+
"@novasamatech/host-api": "0.6.0",
|
|
32
32
|
"nanoid": "5.1.6"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|