@novasamatech/host-api 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 CHANGED
@@ -90,7 +90,7 @@ const hostApi = createHostApi(transport);
90
90
 
91
91
  // requesting data
92
92
 
93
- const storageValue = hostApi.storage_read(payload);
93
+ const storageValue = hostApi.localStorageRead(payload);
94
94
 
95
95
  storageValue.match(
96
96
  (data) => console.log('success:', data),
@@ -99,7 +99,7 @@ storageValue.match(
99
99
 
100
100
  // subscribing to events
101
101
 
102
- const subscription = hostApi.chat_action_subscribe(params, (action) => {
102
+ const subscription = hostApi.chatActionSubscribe(params, (action) => {
103
103
  console.log('action received:', action);
104
104
  });
105
105
 
@@ -109,3 +109,28 @@ subscription.onInterrupt(() => {
109
109
 
110
110
  subscription.unsubscribe();
111
111
  ```
112
+
113
+ ### Custom Renderer
114
+
115
+ The protocol includes a custom renderer system for building UI component trees that can be serialized and sent across the transport. This is used for rendering custom chat messages.
116
+
117
+ Available components: `Box`, `Column`, `Row`, `Spacer`, `Text`, `Button`, `TextField`. Each component supports optional `Modifiers` (margin, padding, background, border, dimensions) and can contain children.
118
+
119
+ ```typescript
120
+ import { CustomRendererNode } from '@novasamatech/host-api';
121
+ ```
122
+
123
+ ### Account Connection Status
124
+
125
+ Products can subscribe to account connection status changes:
126
+
127
+ ```typescript
128
+ const subscription = hostApi.accountConnectionStatusSubscribe(undefined, (status) => {
129
+ // status: 'connected' | 'disconnected'
130
+ console.log('connection status:', status);
131
+ });
132
+ ```
133
+
134
+ ### Custom Chat Messages
135
+
136
+ Chat messages now support a `Custom` content type that carries an arbitrary payload identified by `messageType`. Products can handle rendering of custom messages via the `productChatCustomMessageRenderSubscribe` subscription, which receives the message type and payload and expects a `CustomRendererNode` tree in response.
package/dist/hostApi.d.ts CHANGED
@@ -3,6 +3,7 @@ import type { Codec, CodecType } from 'scale-ts';
3
3
  import type { HostApiProtocol, VersionedProtocolRequest, VersionedProtocolSubscription } from './protocol/impl.js';
4
4
  import type { Subscription, Transport } from './types.js';
5
5
  type SnakeToCamelCase<S extends string> = S extends `${infer T}_${infer U}` ? `${T}${Capitalize<SnakeToCamelCase<U>>}` : S;
6
+ type StripNamespace<S extends string> = S extends `host_${infer Rest}` ? Rest : S extends `remote_${infer Rest}` ? Rest : S;
6
7
  type Value<T extends Codec<any> | Codec<never>> = T extends Codec<any> ? CodecType<T> : unknown;
7
8
  type UnwrapVersionedResult<T> = T extends {
8
9
  tag: infer Tag;
@@ -26,7 +27,7 @@ type InferRequestMethod<Method extends VersionedProtocolRequest> = (args: Value<
26
27
  type InferSubscribeMethod<Method extends VersionedProtocolSubscription> = (args: Value<Method['start']>, callback: (payload: Value<Method['receive']>) => void) => Subscription;
27
28
  type InferMethod<Method extends VersionedProtocolRequest | VersionedProtocolSubscription> = Method extends VersionedProtocolRequest ? InferRequestMethod<Method> : Method extends VersionedProtocolSubscription ? InferSubscribeMethod<Method> : never;
28
29
  export type HostApi = {
29
- [K in keyof HostApiProtocol as SnakeToCamelCase<K>]: InferMethod<HostApiProtocol[K]>;
30
+ [K in keyof HostApiProtocol as SnakeToCamelCase<StripNamespace<K>>]: InferMethod<HostApiProtocol[K]>;
30
31
  };
31
32
  export declare function createHostApi(transport: Transport): HostApi;
32
33
  export {};
package/dist/hostApi.js CHANGED
@@ -5,13 +5,15 @@ import { CreateProofErr, RequestCredentialsErr } from './protocol/v1/accounts.js
5
5
  import { ChatBotRegistrationErr, ChatMessagePostingErr, ChatRoomRegistrationErr } from './protocol/v1/chat.js';
6
6
  import { CreateTransactionErr } from './protocol/v1/createTransaction.js';
7
7
  import { HandshakeErr } from './protocol/v1/handshake.js';
8
+ import { StorageErr } from './protocol/v1/localStorage.js';
9
+ import { NavigateToErr } from './protocol/v1/navigation.js';
10
+ import { PreimageSubmitErr } from './protocol/v1/preimage.js';
8
11
  import { SigningErr } from './protocol/v1/sign.js';
9
12
  import { StatementProofErr } from './protocol/v1/statementStore.js';
10
- import { StorageErr } from './protocol/v1/storage.js';
11
13
  export function createHostApi(transport) {
12
14
  return {
13
15
  handshake(payload) {
14
- const response = fromPromise(transport.request('handshake', payload), e => ({
16
+ const response = fromPromise(transport.request('host_handshake', payload), e => ({
15
17
  tag: payload.tag,
16
18
  value: new HandshakeErr.Unknown({ reason: extractErrorMessage(e) }),
17
19
  }));
@@ -28,8 +30,8 @@ export function createHostApi(transport) {
28
30
  });
29
31
  });
30
32
  },
31
- feature(payload) {
32
- const response = fromPromise(transport.request('feature', payload), e => ({
33
+ featureSupported(payload) {
34
+ const response = fromPromise(transport.request('host_feature_supported', payload), e => ({
33
35
  tag: payload.tag,
34
36
  value: new GenericError({ reason: extractErrorMessage(e) }),
35
37
  }));
@@ -46,8 +48,80 @@ export function createHostApi(transport) {
46
48
  });
47
49
  });
48
50
  },
51
+ devicePermission(payload) {
52
+ const response = fromPromise(transport.request('host_device_permission', payload), e => ({
53
+ tag: payload.tag,
54
+ value: new GenericError({ reason: extractErrorMessage(e) }),
55
+ }));
56
+ return response.andThen(response => {
57
+ if (response.value.success) {
58
+ return okAsync({
59
+ tag: response.tag,
60
+ value: response.value.value,
61
+ });
62
+ }
63
+ return errAsync({
64
+ tag: response.tag,
65
+ value: response.value.value,
66
+ });
67
+ });
68
+ },
69
+ permission(payload) {
70
+ const response = fromPromise(transport.request('remote_permission', payload), e => ({
71
+ tag: payload.tag,
72
+ value: new GenericError({ reason: extractErrorMessage(e) }),
73
+ }));
74
+ return response.andThen(response => {
75
+ if (response.value.success) {
76
+ return okAsync({
77
+ tag: response.tag,
78
+ value: response.value.value,
79
+ });
80
+ }
81
+ return errAsync({
82
+ tag: response.tag,
83
+ value: response.value.value,
84
+ });
85
+ });
86
+ },
87
+ pushNotification(payload) {
88
+ const response = fromPromise(transport.request('host_push_notification', payload), e => ({
89
+ tag: payload.tag,
90
+ value: new GenericError({ reason: extractErrorMessage(e) }),
91
+ }));
92
+ return response.andThen(response => {
93
+ if (response.value.success) {
94
+ return okAsync({
95
+ tag: response.tag,
96
+ value: response.value.value,
97
+ });
98
+ }
99
+ return errAsync({
100
+ tag: response.tag,
101
+ value: response.value.value,
102
+ });
103
+ });
104
+ },
105
+ navigateTo(payload) {
106
+ const response = fromPromise(transport.request('host_navigate_to', payload), e => ({
107
+ tag: payload.tag,
108
+ value: new NavigateToErr.Unknown({ reason: extractErrorMessage(e) }),
109
+ }));
110
+ return response.andThen(response => {
111
+ if (response.value.success) {
112
+ return okAsync({
113
+ tag: response.tag,
114
+ value: response.value.value,
115
+ });
116
+ }
117
+ return errAsync({
118
+ tag: response.tag,
119
+ value: response.value.value,
120
+ });
121
+ });
122
+ },
49
123
  localStorageRead(payload) {
50
- const response = fromPromise(transport.request('local_storage_read', payload), e => ({
124
+ const response = fromPromise(transport.request('host_local_storage_read', payload), e => ({
51
125
  tag: payload.tag,
52
126
  value: new StorageErr.Unknown({ reason: extractErrorMessage(e) }),
53
127
  }));
@@ -65,7 +139,7 @@ export function createHostApi(transport) {
65
139
  });
66
140
  },
67
141
  localStorageWrite(payload) {
68
- const response = fromPromise(transport.request('local_storage_write', payload), e => ({
142
+ const response = fromPromise(transport.request('host_local_storage_write', payload), e => ({
69
143
  tag: payload.tag,
70
144
  value: new StorageErr.Unknown({ reason: extractErrorMessage(e) }),
71
145
  }));
@@ -83,7 +157,7 @@ export function createHostApi(transport) {
83
157
  });
84
158
  },
85
159
  localStorageClear(payload) {
86
- const response = fromPromise(transport.request('local_storage_clear', payload), e => ({
160
+ const response = fromPromise(transport.request('host_local_storage_clear', payload), e => ({
87
161
  tag: payload.tag,
88
162
  value: new StorageErr.Unknown({ reason: extractErrorMessage(e) }),
89
163
  }));
@@ -100,8 +174,11 @@ export function createHostApi(transport) {
100
174
  });
101
175
  });
102
176
  },
177
+ accountConnectionStatusSubscribe(args, callback) {
178
+ return transport.subscribe('host_account_connection_status_subscribe', args, callback);
179
+ },
103
180
  accountGet(payload) {
104
- const response = fromPromise(transport.request('account_get', payload), e => ({
181
+ const response = fromPromise(transport.request('host_account_get', payload), e => ({
105
182
  tag: payload.tag,
106
183
  value: new RequestCredentialsErr.Unknown({ reason: extractErrorMessage(e) }),
107
184
  }));
@@ -119,7 +196,7 @@ export function createHostApi(transport) {
119
196
  });
120
197
  },
121
198
  accountGetAlias(payload) {
122
- const response = fromPromise(transport.request('account_get_alias', payload), e => ({
199
+ const response = fromPromise(transport.request('host_account_get_alias', payload), e => ({
123
200
  tag: payload.tag,
124
201
  value: new RequestCredentialsErr.Unknown({ reason: extractErrorMessage(e) }),
125
202
  }));
@@ -137,7 +214,7 @@ export function createHostApi(transport) {
137
214
  });
138
215
  },
139
216
  accountCreateProof(payload) {
140
- const response = fromPromise(transport.request('account_create_proof', payload), e => ({
217
+ const response = fromPromise(transport.request('host_account_create_proof', payload), e => ({
141
218
  tag: payload.tag,
142
219
  value: new CreateProofErr.Unknown({ reason: extractErrorMessage(e) }),
143
220
  }));
@@ -155,7 +232,7 @@ export function createHostApi(transport) {
155
232
  });
156
233
  },
157
234
  getNonProductAccounts(payload) {
158
- const response = fromPromise(transport.request('get_non_product_accounts', payload), e => ({
235
+ const response = fromPromise(transport.request('host_get_non_product_accounts', payload), e => ({
159
236
  tag: payload.tag,
160
237
  value: new RequestCredentialsErr.Unknown({ reason: extractErrorMessage(e) }),
161
238
  }));
@@ -173,7 +250,7 @@ export function createHostApi(transport) {
173
250
  });
174
251
  },
175
252
  createTransaction(payload) {
176
- const response = fromPromise(transport.request('create_transaction', payload), e => ({
253
+ const response = fromPromise(transport.request('host_create_transaction', payload), e => ({
177
254
  tag: payload.tag,
178
255
  value: new CreateTransactionErr.Unknown({ reason: extractErrorMessage(e) }),
179
256
  }));
@@ -191,7 +268,7 @@ export function createHostApi(transport) {
191
268
  });
192
269
  },
193
270
  createTransactionWithNonProductAccount(payload) {
194
- const response = fromPromise(transport.request('create_transaction_with_non_product_account', payload), e => ({
271
+ const response = fromPromise(transport.request('host_create_transaction_with_non_product_account', payload), e => ({
195
272
  tag: payload.tag,
196
273
  value: new CreateTransactionErr.Unknown({ reason: extractErrorMessage(e) }),
197
274
  }));
@@ -209,7 +286,7 @@ export function createHostApi(transport) {
209
286
  });
210
287
  },
211
288
  signRaw(payload) {
212
- const response = fromPromise(transport.request('sign_raw', payload), e => ({
289
+ const response = fromPromise(transport.request('host_sign_raw', payload), e => ({
213
290
  tag: payload.tag,
214
291
  value: new SigningErr.Unknown({ reason: extractErrorMessage(e) }),
215
292
  }));
@@ -227,7 +304,7 @@ export function createHostApi(transport) {
227
304
  });
228
305
  },
229
306
  signPayload(payload) {
230
- const response = fromPromise(transport.request('sign_payload', payload), e => ({
307
+ const response = fromPromise(transport.request('host_sign_payload', payload), e => ({
231
308
  tag: payload.tag,
232
309
  value: new SigningErr.Unknown({ reason: extractErrorMessage(e) }),
233
310
  }));
@@ -245,10 +322,10 @@ export function createHostApi(transport) {
245
322
  });
246
323
  },
247
324
  chatListSubscribe(args, callback) {
248
- return transport.subscribe('chat_list_subscribe', args, callback);
325
+ return transport.subscribe('host_chat_list_subscribe', args, callback);
249
326
  },
250
327
  chatCreateRoom(payload) {
251
- const response = fromPromise(transport.request('chat_create_room', payload), e => ({
328
+ const response = fromPromise(transport.request('host_chat_create_room', payload), e => ({
252
329
  tag: payload.tag,
253
330
  value: new ChatRoomRegistrationErr.Unknown({ reason: extractErrorMessage(e) }),
254
331
  }));
@@ -266,7 +343,7 @@ export function createHostApi(transport) {
266
343
  });
267
344
  },
268
345
  chatRegisterBot(payload) {
269
- const response = fromPromise(transport.request('chat_register_bot', payload), e => ({
346
+ const response = fromPromise(transport.request('host_chat_register_bot', payload), e => ({
270
347
  tag: payload.tag,
271
348
  value: new ChatBotRegistrationErr.Unknown({ reason: extractErrorMessage(e) }),
272
349
  }));
@@ -284,7 +361,7 @@ export function createHostApi(transport) {
284
361
  });
285
362
  },
286
363
  chatPostMessage(payload) {
287
- const response = fromPromise(transport.request('chat_post_message', payload), e => ({
364
+ const response = fromPromise(transport.request('host_chat_post_message', payload), e => ({
288
365
  tag: payload.tag,
289
366
  value: new ChatMessagePostingErr.Unknown({ reason: extractErrorMessage(e) }),
290
367
  }));
@@ -302,12 +379,18 @@ export function createHostApi(transport) {
302
379
  });
303
380
  },
304
381
  chatActionSubscribe(args, callback) {
305
- return transport.subscribe('chat_action_subscribe', args, callback);
382
+ return transport.subscribe('host_chat_action_subscribe', args, callback);
383
+ },
384
+ productChatCustomMessageRenderSubscribe(args, callback) {
385
+ return transport.subscribe('product_chat_custom_message_render_subscribe', args, callback);
306
386
  },
307
- statementStoreQuery(payload) {
308
- const response = fromPromise(transport.request('statement_store_query', payload), e => ({
387
+ statementStoreSubscribe(args, callback) {
388
+ return transport.subscribe('remote_statement_store_subscribe', args, callback);
389
+ },
390
+ statementStoreCreateProof(payload) {
391
+ const response = fromPromise(transport.request('remote_statement_store_create_proof', payload), e => ({
309
392
  tag: payload.tag,
310
- value: new GenericError({ reason: extractErrorMessage(e) }),
393
+ value: new StatementProofErr.Unknown({ reason: extractErrorMessage(e) }),
311
394
  }));
312
395
  return response.andThen(response => {
313
396
  if (response.value.success) {
@@ -322,13 +405,10 @@ export function createHostApi(transport) {
322
405
  });
323
406
  });
324
407
  },
325
- statementStoreSubscribe(args, callback) {
326
- return transport.subscribe('statement_store_subscribe', args, callback);
327
- },
328
- statementStoreCreateProof(payload) {
329
- const response = fromPromise(transport.request('statement_store_create_proof', payload), e => ({
408
+ statementStoreSubmit(payload) {
409
+ const response = fromPromise(transport.request('remote_statement_store_submit', payload), e => ({
330
410
  tag: payload.tag,
331
- value: new StatementProofErr.Unknown({ reason: extractErrorMessage(e) }),
411
+ value: new GenericError({ reason: extractErrorMessage(e) }),
332
412
  }));
333
413
  return response.andThen(response => {
334
414
  if (response.value.success) {
@@ -343,10 +423,13 @@ export function createHostApi(transport) {
343
423
  });
344
424
  });
345
425
  },
346
- statementStoreSubmit(payload) {
347
- const response = fromPromise(transport.request('statement_store_submit', payload), e => ({
426
+ preimageLookupSubscribe(args, callback) {
427
+ return transport.subscribe('remote_preimage_lookup_subscribe', args, callback);
428
+ },
429
+ preimageSubmit(payload) {
430
+ const response = fromPromise(transport.request('remote_preimage_submit', payload), e => ({
348
431
  tag: payload.tag,
349
- value: new GenericError({ reason: extractErrorMessage(e) }),
432
+ value: new PreimageSubmitErr.Unknown({ reason: extractErrorMessage(e) }),
350
433
  }));
351
434
  return response.andThen(response => {
352
435
  if (response.value.success) {
@@ -362,7 +445,7 @@ export function createHostApi(transport) {
362
445
  });
363
446
  },
364
447
  jsonrpcMessageSend(payload) {
365
- const response = fromPromise(transport.request('jsonrpc_message_send', payload), e => ({
448
+ const response = fromPromise(transport.request('host_jsonrpc_message_send', payload), e => ({
366
449
  tag: payload.tag,
367
450
  value: new GenericError({ reason: extractErrorMessage(e) }),
368
451
  }));
@@ -380,7 +463,7 @@ export function createHostApi(transport) {
380
463
  });
381
464
  },
382
465
  jsonrpcMessageSubscribe(args, callback) {
383
- return transport.subscribe('jsonrpc_message_subscribe', args, callback);
466
+ return transport.subscribe('host_jsonrpc_message_subscribe', args, callback);
384
467
  },
385
468
  };
386
469
  }
package/dist/index.d.ts CHANGED
@@ -12,9 +12,15 @@ export type { HexString } from '@novasamatech/scale';
12
12
  export { assertEnumVariant, enumValue, fromHex, isEnumVariant, resultErr, resultOk, toHex, unwrapResultOrThrow, } from '@novasamatech/scale';
13
13
  export { GenericError } from './protocol/commonCodecs.js';
14
14
  export { CreateTransactionErr, VersionedPublicTxPayload } from './protocol/v1/createTransaction.js';
15
- export { Account, AccountId, CreateProofErr, ProductAccountId, RequestCredentialsErr, RingLocation, } from './protocol/v1/accounts.js';
15
+ export { Account, AccountConnectionStatus, AccountId, CreateProofErr, ProductAccountId, RequestCredentialsErr, RingLocation, } from './protocol/v1/accounts.js';
16
16
  export { ChatActionPayload, ChatBotRegistrationErr, ChatBotRegistrationStatus, ChatMessageContent, ChatMessagePostingErr, ChatRoom, ChatRoomRegistrationErr, ChatRoomRegistrationResult, ChatRoomRegistrationStatus, ReceivedChatAction, } from './protocol/v1/chat.js';
17
17
  export { HandshakeErr } from './protocol/v1/handshake.js';
18
18
  export { SigningErr } from './protocol/v1/sign.js';
19
19
  export { SignedStatement, Statement, StatementProofErr, Topic } from './protocol/v1/statementStore.js';
20
- export { StorageErr } from './protocol/v1/storage.js';
20
+ export { StorageErr } from './protocol/v1/localStorage.js';
21
+ export { DevicePermissionRequest } from './protocol/v1/devicePermission.js';
22
+ export { RemotePermissionRequest } from './protocol/v1/remotePermission.js';
23
+ export { PushNotification } from './protocol/v1/notification.js';
24
+ export { NavigateToErr } from './protocol/v1/navigation.js';
25
+ export { PreimageKey, PreimageSubmitErr, PreimageValue } from './protocol/v1/preimage.js';
26
+ export { CustomRendererNode } from './protocol/v1/customRenderer.js';
package/dist/index.js CHANGED
@@ -7,9 +7,15 @@ export { assertEnumVariant, enumValue, fromHex, isEnumVariant, resultErr, result
7
7
  // Codecs
8
8
  export { GenericError } from './protocol/commonCodecs.js';
9
9
  export { CreateTransactionErr, VersionedPublicTxPayload } from './protocol/v1/createTransaction.js';
10
- export { Account, AccountId, CreateProofErr, ProductAccountId, RequestCredentialsErr, RingLocation, } from './protocol/v1/accounts.js';
10
+ export { Account, AccountConnectionStatus, AccountId, CreateProofErr, ProductAccountId, RequestCredentialsErr, RingLocation, } from './protocol/v1/accounts.js';
11
11
  export { ChatActionPayload, ChatBotRegistrationErr, ChatBotRegistrationStatus, ChatMessageContent, ChatMessagePostingErr, ChatRoom, ChatRoomRegistrationErr, ChatRoomRegistrationResult, ChatRoomRegistrationStatus, ReceivedChatAction, } from './protocol/v1/chat.js';
12
12
  export { HandshakeErr } from './protocol/v1/handshake.js';
13
13
  export { SigningErr } from './protocol/v1/sign.js';
14
14
  export { SignedStatement, Statement, StatementProofErr, Topic } from './protocol/v1/statementStore.js';
15
- export { StorageErr } from './protocol/v1/storage.js';
15
+ export { StorageErr } from './protocol/v1/localStorage.js';
16
+ export { DevicePermissionRequest } from './protocol/v1/devicePermission.js';
17
+ export { RemotePermissionRequest } from './protocol/v1/remotePermission.js';
18
+ export { PushNotification } from './protocol/v1/notification.js';
19
+ export { NavigateToErr } from './protocol/v1/navigation.js';
20
+ export { PreimageKey, PreimageSubmitErr, PreimageValue } from './protocol/v1/preimage.js';
21
+ export { CustomRendererNode } from './protocol/v1/customRenderer.js';