@novasamatech/host-container 0.5.4-9 → 0.5.4

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 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,6 +31,22 @@ 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
  ### handleFeature
@@ -42,32 +60,19 @@ container.handleFeature((params, { ok, err }) => {
42
60
  });
43
61
  ```
44
62
 
45
- ### handlePermissionRequest
63
+ ### handleLocalStorageRead
46
64
 
47
65
  ```ts
48
- container.handlePermissionRequest(async (params, { ok, err }) => {
49
- if (params.tag === 'ChainConnect') {
50
- // Show permission dialog to user
51
- const approved = await showPermissionDialog(params.value);
52
- return approved ? ok(undefined) : err({ tag: 'Rejected' });
53
- }
54
- return err({ tag: 'Unknown', value: { reason: 'Unsupported permission type' } });
55
- });
56
- ```
57
-
58
- ### handleStorageRead
59
-
60
- ```ts
61
- container.handleStorageRead(async (key, { ok, err }) => {
66
+ container.handleLocalStorageRead(async (key, { ok, err }) => {
62
67
  const value = await storage.get(key);
63
68
  return ok(value ?? null);
64
69
  });
65
70
  ```
66
71
 
67
- ### handleStorageWrite
72
+ ### handleLocalStorageWrite
68
73
 
69
74
  ```ts
70
- container.handleStorageWrite(async ([key, value], { ok, err }) => {
75
+ container.handleLocalStorageWrite(async ([key, value], { ok, err }) => {
71
76
  try {
72
77
  await storage.set(key, value);
73
78
  return ok(undefined);
@@ -77,10 +82,10 @@ container.handleStorageWrite(async ([key, value], { ok, err }) => {
77
82
  });
78
83
  ```
79
84
 
80
- ### handleStorageClear
85
+ ### handleLocalStorageClear
81
86
 
82
87
  ```ts
83
- container.handleStorageClear(async (key, { ok, err }) => {
88
+ container.handleLocalStorageClear(async (key, { ok, err }) => {
84
89
  await storage.delete(key);
85
90
  return ok(undefined);
86
91
  });
@@ -184,15 +189,27 @@ container.handleSignPayload(async (payload, { ok, err }) => {
184
189
  });
185
190
  ```
186
191
 
187
- ### handleChatCreateContact
192
+ ### handleChatCreateRoom
188
193
 
189
194
  ```ts
190
- container.handleChatCreateContact(async (contact, { ok, err }) => {
191
- await chatService.registerContact(contact);
195
+ container.handleChatCreateRoom(async (room, { ok, err }) => {
196
+ await chatService.registerRoom(room);
192
197
  return ok(undefined);
193
198
  });
194
199
  ```
195
200
 
201
+ ## handleChatBotRegistration
202
+
203
+ ### handleChatListSubscribe
204
+
205
+ ```ts
206
+ container.handleChatListSubscribe((_, send, interrupt) => {
207
+ const listener = (rooms) => send(rooms);
208
+ chatService.on('roomsUpdate', listener);
209
+ return () => chatService.off('roomsUpdate', listener);
210
+ });
211
+ ```
212
+
196
213
  ### handleChatPostMessage
197
214
 
198
215
  ```ts
@@ -212,6 +229,25 @@ container.handleChatActionSubscribe((_, send, interrupt) => {
212
229
  });
213
230
  ```
214
231
 
232
+ ### handleStatementStoreQuery
233
+
234
+ ```ts
235
+ container.handleStatementStoreQuery(async (query, { ok, err }) => {
236
+ const statements = await statementStore.query(query);
237
+ return ok(statements);
238
+ });
239
+ ```
240
+
241
+ ### handleStatementStoreSubscribe
242
+
243
+ ```ts
244
+ container.handleStatementStoreSubscribe((query, send, interrupt) => {
245
+ const listener = (statements) => send(statements);
246
+ statementStore.subscribe(query, listener);
247
+ return () => statementStore.unsubscribe(query, listener);
248
+ });
249
+ ```
250
+
215
251
  ### handleStatementStoreCreateProof
216
252
 
217
253
  ```ts
@@ -225,16 +261,34 @@ container.handleStatementStoreCreateProof(async ([[dotnsId, derivationIndex], st
225
261
  });
226
262
  ```
227
263
 
228
- ### handleJsonRpcMessageSubscribe
264
+ ### handleStatementStoreSubmit
265
+
266
+ ```ts
267
+ container.handleStatementStoreSubmit(async (statement, { ok, err }) => {
268
+ try {
269
+ await statementStore.submit(statement);
270
+ return ok(undefined);
271
+ } catch (e) {
272
+ return err({ tag: 'Unknown', value: { reason: e.message } });
273
+ }
274
+ });
275
+ ```
276
+
277
+ ### handleChainConnection
229
278
 
230
279
  ```ts
231
280
  import { getWsProvider } from 'polkadot-api/ws-provider';
232
281
 
233
- const provider = getWsProvider('wss://rpc.polkadot.io');
234
- container.handleJsonRpcMessageSubscribe(
235
- { genesisHash: '0x...' },
236
- provider
237
- );
282
+ const chains = new Map([
283
+ ['0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3', 'wss://rpc.polkadot.io'],
284
+ ['0xb0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe', 'wss://kusama-rpc.polkadot.io'],
285
+ ]);
286
+
287
+ container.handleChainConnection((genesisHash) => {
288
+ const endpoint = chains.get(genesisHash);
289
+ if (!endpoint) return null;
290
+ return getWsProvider(endpoint);
291
+ });
238
292
  ```
239
293
 
240
294
  ### isReady
@@ -252,41 +306,14 @@ if (ready) {
252
306
  container.dispose();
253
307
  ```
254
308
 
255
- ### subscribeConnectionStatus
309
+ ### subscribeProductConnectionStatus
256
310
 
257
311
  ```ts
258
- const unsubscribe = container.subscribeConnectionStatus((status) => {
312
+ const unsubscribe = container.subscribeProductConnectionStatus((status) => {
259
313
  console.log('Connection status:', status);
260
314
  });
261
315
  ```
262
316
 
263
- ## PAPI provider support
264
-
265
- Host container supports [PAPI](https://papi.how/) request redirection from product to host container.
266
- It can be useful to deduplicate socket connections or light client instances between multiple dapps.
267
-
268
- To support this feature, you should add two additional handlers to the container:
269
-
270
- ### Chain support check
271
- ```ts
272
- const genesisHash = '0x...';
273
-
274
- container.handleFeature(async (feature) => {
275
- return feature.tag === 'Chain' && feature.value === genesisHash;
276
- });
277
- ```
278
-
279
- ### Provider implementation
280
-
281
- ```ts
282
- import { getWsProvider } from 'polkadot-api/ws-provider';
283
-
284
- const genesisHash = '0x...';
285
- const provider = getWsProvider('wss://...');
286
-
287
- container.connectToPapiProvider(genesisHash, provider);
288
- ```
289
-
290
317
  ## Known pitfalls
291
318
 
292
319
  ### CSP error on iframe loading
@@ -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, 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) {
@@ -173,6 +173,18 @@ export function createContainer(provider) {
173
173
  .unwrapOr(enumValue(version, resultErr(error)));
174
174
  });
175
175
  },
176
+ handleChatBotRegistration(handler) {
177
+ init();
178
+ return transport.handleRequest('chat_register_bot', async (params) => {
179
+ const version = 'v1';
180
+ const error = new ChatBotRegistrationErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
181
+ return guardVersion(params, version, error)
182
+ .asyncMap(async (params) => handler(params, { ok: (okAsync), err: (errAsync) }))
183
+ .andThen(r => r.map(r => enumValue(version, resultOk(r))))
184
+ .orElse(r => ok(enumValue(version, resultErr(r))))
185
+ .unwrapOr(enumValue(version, resultErr(error)));
186
+ });
187
+ },
176
188
  handleChatListSubscribe(handler) {
177
189
  init();
178
190
  return transport.handleSubscription('chat_list_subscribe', (params, send, interrupt) => {
package/dist/types.d.ts CHANGED
@@ -63,6 +63,7 @@ export type Container = {
63
63
  handleSignRaw: InferHandler<'v1', HostApiProtocol['sign_raw']>;
64
64
  handleSignPayload: InferHandler<'v1', HostApiProtocol['sign_payload']>;
65
65
  handleChatCreateRoom: InferHandler<'v1', HostApiProtocol['chat_create_room']>;
66
+ handleChatBotRegistration: InferHandler<'v1', HostApiProtocol['chat_register_bot']>;
66
67
  handleChatListSubscribe: InferHandler<'v1', HostApiProtocol['chat_list_subscribe']>;
67
68
  handleChatPostMessage: InferHandler<'v1', HostApiProtocol['chat_post_message']>;
68
69
  handleChatActionSubscribe: InferHandler<'v1', HostApiProtocol['chat_action_subscribe']>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@novasamatech/host-container",
3
3
  "type": "module",
4
- "version": "0.5.4-9",
4
+ "version": "0.5.4",
5
5
  "description": "Host container for hosting and managing products within the Polkadot ecosystem.",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
@@ -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.4-9",
31
+ "@novasamatech/host-api": "0.5.4",
32
32
  "nanoid": "5.1.6"
33
33
  },
34
34
  "devDependencies": {