@novasamatech/product-sdk 0.5.5 → 0.6.1

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
@@ -132,6 +132,29 @@ const subscriber = chat.subscribeAction((action) => {
132
132
  const chatListSubscriber = chat.subscribeChatList((rooms) => {
133
133
  console.log('Chat rooms updated:', rooms);
134
134
  });
135
+
136
+ // Sending a custom message
137
+ await chat.sendMessage('my-product-room', {
138
+ tag: 'Custom',
139
+ value: { messageType: 'my-custom-type', payload: new Uint8Array([/* ... */]) }
140
+ });
141
+
142
+ // Handling custom message rendering requests from host
143
+ const unsubscribeRenderer = chat.onCustomMessageRenderingRequest((messageType, payload, render) => {
144
+ // Build a CustomRendererNode tree and pass it to render()
145
+ render({
146
+ tag: 'Text',
147
+ value: {
148
+ modifiers: undefined,
149
+ props: { style: undefined, color: undefined },
150
+ children: [{ tag: 'String', value: 'Custom message content' }],
151
+ },
152
+ });
153
+
154
+ return () => {
155
+ // cleanup when subscription ends
156
+ };
157
+ });
135
158
  ```
136
159
 
137
160
  **Note:** Messages sent before registration will be queued and sent automatically after successful registration.
@@ -214,6 +237,12 @@ if (nonProductAccountsResult.isOk()) {
214
237
  console.log('Non-product accounts:', nonProductAccountsResult.value);
215
238
  }
216
239
 
240
+ // Subscribe to account connection status changes
241
+ const unsubscribe = accountsProvider.subscribeAccountConnectionStatus((status) => {
242
+ // status: 'connected' | 'disconnected'
243
+ console.log('Account connection status:', status);
244
+ });
245
+
217
246
  // Create a signer for a product account (for use with PAPI)
218
247
  const account: ProductAccount = {
219
248
  dotNsIdentifier: 'product.dot',
@@ -1,4 +1,4 @@
1
- import type { CodecType, Transport } from '@novasamatech/host-api';
1
+ import type { AccountConnectionStatus as AccountConnectionStatusCodec, CodecType, Transport } from '@novasamatech/host-api';
2
2
  import { RingLocation } from '@novasamatech/host-api';
3
3
  import type { PolkadotSigner } from 'polkadot-api';
4
4
  export type ProductAccount = {
@@ -6,6 +6,7 @@ export type ProductAccount = {
6
6
  derivationIndex: number;
7
7
  publicKey: Uint8Array;
8
8
  };
9
+ export type AccountConnectionStatus = CodecType<typeof AccountConnectionStatusCodec>;
9
10
  export declare const createAccountsProvider: (transport?: Transport) => {
10
11
  getProductAccount(dotNsIdentifier: string, derivationIndex?: number): import("neverthrow").ResultAsync<{
11
12
  publicKey: Uint8Array<ArrayBufferLike>;
@@ -37,5 +38,6 @@ export declare const createAccountsProvider: (transport?: Transport) => {
37
38
  reason: string;
38
39
  }, "CreateProofErr::Unknown">>;
39
40
  getProductAccountSigner(account: ProductAccount): PolkadotSigner;
41
+ subscribeAccountConnectionStatus(callback: (status: AccountConnectionStatus) => void): import("@novasamatech/host-api").Subscription;
40
42
  getNonProductAccountSigner(account: ProductAccount): PolkadotSigner;
41
43
  };
package/dist/accounts.js CHANGED
@@ -111,6 +111,13 @@ export const createAccountsProvider = (transport = sandboxTransport) => {
111
111
  });
112
112
  });
113
113
  },
114
+ subscribeAccountConnectionStatus(callback) {
115
+ return hostApi.accountConnectionStatusSubscribe(enumValue('v1', undefined), status => {
116
+ if (status.tag === 'v1') {
117
+ callback(status.value);
118
+ }
119
+ });
120
+ },
114
121
  getNonProductAccountSigner(account) {
115
122
  return getPolkadotSignerFromPjs(toHex(account.publicKey), async (payload) => {
116
123
  const codecPayload = {
package/dist/chat.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { ChatBotRegistrationStatus as ChatBotRegistrationStatusCodec, ChatMessageContent as ChatMessageContentCodec, ChatRoom as ChatRoomCodec, ChatRoomRegistrationStatus as ChatRoomRegistrationStatusCodec, CodecType, ReceivedChatAction as ReceivedChatActionCodec, Transport } from '@novasamatech/host-api';
2
+ import { CustomRendererNode } from '@novasamatech/host-api';
2
3
  export type ChatMessageContent = CodecType<typeof ChatMessageContentCodec>;
3
4
  export type ReceivedChatAction = CodecType<typeof ReceivedChatActionCodec>;
4
5
  export type ChatRoomRegistrationResult = CodecType<typeof ChatRoomRegistrationStatusCodec>;
@@ -20,4 +21,5 @@ export declare const createProductChatManager: (transport?: Transport) => {
20
21
  }>;
21
22
  subscribeChatList(callback: (rooms: ChatRoom[]) => void): import("@novasamatech/host-api").Subscription;
22
23
  subscribeAction(callback: (action: ReceivedChatAction) => void): import("@novasamatech/host-api").Subscription;
24
+ onCustomMessageRenderingRequest(callback: (messageType: string, payload: Uint8Array, render: (node: CodecType<typeof CustomRendererNode>) => void) => VoidFunction): VoidFunction;
23
25
  };
package/dist/chat.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createHostApi, enumValue } from '@novasamatech/host-api';
1
+ import { CustomRendererNode, createHostApi, enumValue } from '@novasamatech/host-api';
2
2
  import { sandboxTransport } from './sandboxTransport.js';
3
3
  export const createProductChatManager = (transport = sandboxTransport) => {
4
4
  const hostApi = createHostApi(transport);
@@ -75,6 +75,18 @@ export const createProductChatManager = (transport = sandboxTransport) => {
75
75
  }
76
76
  });
77
77
  },
78
+ onCustomMessageRenderingRequest(callback) {
79
+ return transport.handleSubscription('product_chat_custom_message_render_subscribe', (params, send, interrupt) => {
80
+ if (params.tag === 'v1') {
81
+ return callback(params.value.messageType, params.value.payload, node => send(enumValue('v1', node)));
82
+ }
83
+ // unsupported version
84
+ interrupt();
85
+ return () => {
86
+ /* empty */
87
+ };
88
+ });
89
+ },
78
90
  };
79
91
  return chat;
80
92
  };
package/dist/index.d.ts CHANGED
@@ -8,7 +8,7 @@ export type { ChatBotRegistrationResult, ChatMessageContent, ChatRoom, ChatRoomR
8
8
  export { createProductChatManager } from './chat.js';
9
9
  export type { ProductAccountId, SignedStatement, Statement, Topic } from './statementStore.js';
10
10
  export { createStatementStore } from './statementStore.js';
11
- export type { ProductAccount } from './accounts.js';
11
+ export type { AccountConnectionStatus, ProductAccount } from './accounts.js';
12
12
  export { createAccountsProvider } from './accounts.js';
13
13
  export { createLocalStorage, hostLocalStorage } from './localStorage.js';
14
14
  export { createPreimageManager, preimageManager } from './preimage.js';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@novasamatech/product-sdk",
3
3
  "type": "module",
4
- "version": "0.5.5",
4
+ "version": "0.6.1",
5
5
  "description": "Polkadot product SDK: integrate and run your product inside Polkadot browser.",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
@@ -30,7 +30,7 @@
30
30
  "@polkadot-api/substrate-bindings": "^0.17.0",
31
31
  "@polkadot-api/json-rpc-provider": "^0.0.4",
32
32
  "@polkadot-api/json-rpc-provider-proxy": "^0.2.7",
33
- "@novasamatech/host-api": "0.5.5"
33
+ "@novasamatech/host-api": "0.6.1"
34
34
  },
35
35
  "publishConfig": {
36
36
  "access": "public"