@novasamatech/product-sdk 0.6.5 → 0.6.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/dist/chat.d.ts +11 -7
- package/dist/chat.js +32 -7
- package/dist/createPapiProvider.d.ts +1 -5
- package/dist/createPapiProvider.js +11 -6
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/injectSpektrExtension.js +4 -4
- package/package.json +3 -5
package/dist/chat.d.ts
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
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
2
|
import { CustomRendererNode } from '@novasamatech/host-api';
|
|
3
3
|
export type ChatMessageContent = CodecType<typeof ChatMessageContentCodec>;
|
|
4
|
-
export type
|
|
4
|
+
export type ChatReceivedAction = CodecType<typeof ReceivedChatActionCodec>;
|
|
5
5
|
export type ChatRoomRegistrationResult = CodecType<typeof ChatRoomRegistrationStatusCodec>;
|
|
6
6
|
export type ChatBotRegistrationResult = CodecType<typeof ChatBotRegistrationStatusCodec>;
|
|
7
7
|
export type ChatRoom = CodecType<typeof ChatRoomCodec>;
|
|
8
|
+
export type ChatCustomMessageRenderer = (params: ChatCustomMessageRendererParams, render: (node: CodecType<typeof CustomRendererNode>) => void) => VoidFunction;
|
|
9
|
+
export type ChatCustomMessageRendererParams<T = Uint8Array> = {
|
|
10
|
+
messageId: string;
|
|
11
|
+
messageType: string;
|
|
12
|
+
payload: T;
|
|
13
|
+
subscribeActions(callback: (actionId: string, payload: Uint8Array | undefined) => void): VoidFunction;
|
|
14
|
+
};
|
|
8
15
|
export declare const createProductChatManager: (transport?: Transport) => {
|
|
9
16
|
registerRoom(params: {
|
|
10
17
|
roomId: string;
|
|
@@ -20,10 +27,7 @@ export declare const createProductChatManager: (transport?: Transport) => {
|
|
|
20
27
|
messageId: string;
|
|
21
28
|
}>;
|
|
22
29
|
subscribeChatList(callback: (rooms: ChatRoom[]) => void): import("@novasamatech/host-api").Subscription;
|
|
23
|
-
subscribeAction(callback: (action:
|
|
24
|
-
onCustomMessageRenderingRequest(callback:
|
|
25
|
-
messageId: string;
|
|
26
|
-
messageType: string;
|
|
27
|
-
payload: Uint8Array;
|
|
28
|
-
}, render: (node: CodecType<typeof CustomRendererNode>) => void) => VoidFunction): VoidFunction;
|
|
30
|
+
subscribeAction(callback: (action: ChatReceivedAction) => void): import("@novasamatech/host-api").Subscription;
|
|
31
|
+
onCustomMessageRenderingRequest(callback: ChatCustomMessageRenderer): VoidFunction;
|
|
29
32
|
};
|
|
33
|
+
export declare function matchChatCustomRenderers(map: Record<string, ChatCustomMessageRenderer>): ChatCustomMessageRenderer;
|
package/dist/chat.js
CHANGED
|
@@ -77,16 +77,41 @@ export const createProductChatManager = (transport = sandboxTransport) => {
|
|
|
77
77
|
},
|
|
78
78
|
onCustomMessageRenderingRequest(callback) {
|
|
79
79
|
return transport.handleSubscription('product_chat_custom_message_render_subscribe', (params, send, interrupt) => {
|
|
80
|
-
if (params.tag
|
|
81
|
-
|
|
80
|
+
if (params.tag !== 'v1') {
|
|
81
|
+
// unsupported version
|
|
82
|
+
interrupt();
|
|
83
|
+
return () => {
|
|
84
|
+
/* empty */
|
|
85
|
+
};
|
|
82
86
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
87
|
+
const { messageId, messageType, payload } = params.value;
|
|
88
|
+
return callback({
|
|
89
|
+
messageId,
|
|
90
|
+
messageType,
|
|
91
|
+
payload,
|
|
92
|
+
subscribeActions(callback) {
|
|
93
|
+
const actionsSubscription = hostApi.chatActionSubscribe(enumValue('v1', undefined), action => {
|
|
94
|
+
if (action.tag === 'v1' &&
|
|
95
|
+
action.value.payload.tag === 'ActionTriggered' &&
|
|
96
|
+
action.value.payload.value.messageId === messageId) {
|
|
97
|
+
callback(action.value.payload.value.actionId, action.value.payload.value.payload);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
return actionsSubscription.unsubscribe;
|
|
101
|
+
},
|
|
102
|
+
}, node => send(enumValue('v1', node)));
|
|
88
103
|
});
|
|
89
104
|
},
|
|
90
105
|
};
|
|
91
106
|
return chat;
|
|
92
107
|
};
|
|
108
|
+
export function matchChatCustomRenderers(map) {
|
|
109
|
+
return (params, render) => {
|
|
110
|
+
const { messageType } = params;
|
|
111
|
+
const renderer = map[messageType];
|
|
112
|
+
if (!renderer) {
|
|
113
|
+
throw new Error(`Renderer for message type ${messageType} is not defined`);
|
|
114
|
+
}
|
|
115
|
+
return renderer(params, render);
|
|
116
|
+
};
|
|
117
|
+
}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import type { HexString, Transport } from '@novasamatech/host-api';
|
|
2
2
|
import type { JsonRpcProvider } from '@polkadot-api/json-rpc-provider';
|
|
3
|
-
type Params = {
|
|
4
|
-
chainId: HexString;
|
|
5
|
-
fallback: JsonRpcProvider;
|
|
6
|
-
};
|
|
7
3
|
type InternalParams = {
|
|
8
4
|
transport?: Transport;
|
|
9
5
|
};
|
|
10
|
-
export declare function createPapiProvider(
|
|
6
|
+
export declare function createPapiProvider(genesisHash: HexString, internal?: InternalParams): JsonRpcProvider;
|
|
11
7
|
export {};
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { createHostApi, enumValue, unwrapResultOrThrow } from '@novasamatech/host-api';
|
|
2
2
|
import { getSyncProvider } from '@polkadot-api/json-rpc-provider-proxy';
|
|
3
3
|
import { defaultTransport } from './defaultTransport.js';
|
|
4
|
-
export function createPapiProvider(
|
|
4
|
+
export function createPapiProvider(genesisHash, internal) {
|
|
5
5
|
const version = 'v1';
|
|
6
6
|
const transport = internal?.transport ?? defaultTransport;
|
|
7
|
-
if (!transport.isCorrectEnvironment())
|
|
8
|
-
|
|
7
|
+
if (!transport.isCorrectEnvironment()) {
|
|
8
|
+
throw new Error('PapiProvider can only be used in a product environment');
|
|
9
|
+
}
|
|
9
10
|
const hostApi = createHostApi(transport);
|
|
10
11
|
const spektrProvider = onMessage => {
|
|
11
|
-
const subscription = hostApi.
|
|
12
|
+
const subscription = hostApi.jsonrpcMessageSubscribe(enumValue(version, genesisHash), payload => {
|
|
12
13
|
switch (payload.tag) {
|
|
13
14
|
case version:
|
|
14
15
|
onMessage(payload.value);
|
|
@@ -19,7 +20,7 @@ export function createPapiProvider({ chainId: genesisHash, fallback }, internal)
|
|
|
19
20
|
});
|
|
20
21
|
return {
|
|
21
22
|
send(message) {
|
|
22
|
-
hostApi.
|
|
23
|
+
hostApi.jsonrpcMessageSend(enumValue(version, [genesisHash, message]));
|
|
23
24
|
},
|
|
24
25
|
disconnect() {
|
|
25
26
|
subscription.unsubscribe();
|
|
@@ -47,5 +48,9 @@ export function createPapiProvider({ chainId: genesisHash, fallback }, internal)
|
|
|
47
48
|
});
|
|
48
49
|
});
|
|
49
50
|
}
|
|
50
|
-
return getSyncProvider(() => checkIfReady().then(ready =>
|
|
51
|
+
return getSyncProvider(() => checkIfReady().then(ready => {
|
|
52
|
+
if (ready)
|
|
53
|
+
return spektrProvider;
|
|
54
|
+
throw new Error(`Chain ${genesisHash} not supported by host`);
|
|
55
|
+
}));
|
|
51
56
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,8 +4,8 @@ export { hostApi } from './hostApi.js';
|
|
|
4
4
|
export { createMetaProvider, metaProvider } from './metaProvider.js';
|
|
5
5
|
export { createNonProductExtensionEnableFactory, injectSpektrExtension } from './injectWeb3.js';
|
|
6
6
|
export { createPapiProvider } from './papiProvider.js';
|
|
7
|
-
export type { ChatBotRegistrationResult, ChatMessageContent, ChatRoom, ChatRoomRegistrationResult,
|
|
8
|
-
export { createProductChatManager } from './chat.js';
|
|
7
|
+
export type { ChatBotRegistrationResult, ChatCustomMessageRenderer, ChatCustomMessageRendererParams, ChatMessageContent, ChatReceivedAction, ChatRoom, ChatRoomRegistrationResult, } from './chat.js';
|
|
8
|
+
export { createProductChatManager, matchChatCustomRenderers } from './chat.js';
|
|
9
9
|
export type { ProductAccountId, SignedStatement, Statement, Topic } from './statementStore.js';
|
|
10
10
|
export { createStatementStore } from './statementStore.js';
|
|
11
11
|
export type { AccountConnectionStatus, ProductAccount } from './accounts.js';
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ export { hostApi } from './hostApi.js';
|
|
|
4
4
|
export { createMetaProvider, metaProvider } from './metaProvider.js';
|
|
5
5
|
export { createNonProductExtensionEnableFactory, injectSpektrExtension } from './injectWeb3.js';
|
|
6
6
|
export { createPapiProvider } from './papiProvider.js';
|
|
7
|
-
export { createProductChatManager } from './chat.js';
|
|
7
|
+
export { createProductChatManager, matchChatCustomRenderers } from './chat.js';
|
|
8
8
|
export { createStatementStore } from './statementStore.js';
|
|
9
9
|
export { createAccountsProvider } from './accounts.js';
|
|
10
10
|
export { createLocalStorage, hostLocalStorage } from './localStorage.js';
|
|
@@ -12,7 +12,7 @@ export async function createExtensionEnableFactory(transport) {
|
|
|
12
12
|
const accountId = AccountId();
|
|
13
13
|
async function enable() {
|
|
14
14
|
async function getAccounts() {
|
|
15
|
-
const response = await hostApi.
|
|
15
|
+
const response = await hostApi.getNonProductAccounts(enumValue('v1', undefined));
|
|
16
16
|
return response.match(response => {
|
|
17
17
|
assertEnumVariant(response, 'v1', UNSUPPORTED_VERSION_ERROR);
|
|
18
18
|
return response.value.map(account => ({
|
|
@@ -51,7 +51,7 @@ export async function createExtensionEnableFactory(transport) {
|
|
|
51
51
|
value: raw.data,
|
|
52
52
|
},
|
|
53
53
|
};
|
|
54
|
-
const response = await hostApi.
|
|
54
|
+
const response = await hostApi.signRaw(enumValue('v1', payload));
|
|
55
55
|
return response.match(response => {
|
|
56
56
|
assertEnumVariant(response, 'v1', UNSUPPORTED_VERSION_ERROR);
|
|
57
57
|
return {
|
|
@@ -73,7 +73,7 @@ export async function createExtensionEnableFactory(transport) {
|
|
|
73
73
|
withSignedTransaction: payload.withSignedTransaction,
|
|
74
74
|
metadataHash: payload.metadataHash,
|
|
75
75
|
};
|
|
76
|
-
const response = await hostApi.
|
|
76
|
+
const response = await hostApi.signPayload(enumValue('v1', codecPayload));
|
|
77
77
|
return response.match(response => {
|
|
78
78
|
assertEnumVariant(response, 'v1', UNSUPPORTED_VERSION_ERROR);
|
|
79
79
|
return {
|
|
@@ -87,7 +87,7 @@ export async function createExtensionEnableFactory(transport) {
|
|
|
87
87
|
});
|
|
88
88
|
},
|
|
89
89
|
async createTransaction(payload) {
|
|
90
|
-
const response = await hostApi.
|
|
90
|
+
const response = await hostApi.createTransactionWithNonProductAccount(enumValue('v1', payload));
|
|
91
91
|
return response.match(response => {
|
|
92
92
|
assertEnumVariant(response, 'v1', UNSUPPORTED_VERSION_ERROR);
|
|
93
93
|
return toHex(response.value);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@novasamatech/product-sdk",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.6.
|
|
4
|
+
"version": "0.6.6-0",
|
|
5
5
|
"description": "Polkadot product SDK: integrate and run your product inside Polkadot browser.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"repository": {
|
|
@@ -9,9 +9,7 @@
|
|
|
9
9
|
"url": "git+https://github.com/Polkadot-Community-Foundation/triangle-js-sdks.git"
|
|
10
10
|
},
|
|
11
11
|
"keywords": [
|
|
12
|
-
"polkadot"
|
|
13
|
-
"spektr",
|
|
14
|
-
"dapp"
|
|
12
|
+
"polkadot"
|
|
15
13
|
],
|
|
16
14
|
"main": "dist/index.js",
|
|
17
15
|
"exports": {
|
|
@@ -30,7 +28,7 @@
|
|
|
30
28
|
"@polkadot-api/substrate-bindings": "^0.17.0",
|
|
31
29
|
"@polkadot-api/json-rpc-provider": "^0.0.4",
|
|
32
30
|
"@polkadot-api/json-rpc-provider-proxy": "^0.2.7",
|
|
33
|
-
"@novasamatech/host-api": "0.6.
|
|
31
|
+
"@novasamatech/host-api": "0.6.6-0"
|
|
34
32
|
},
|
|
35
33
|
"publishConfig": {
|
|
36
34
|
"access": "public"
|