@novasamatech/host-chat 0.8.9 → 0.8.10

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.
@@ -1,12 +1,15 @@
1
1
  import type { HexString } from '@novasamatech/scale';
2
2
  import type { LazyClient } from '@novasamatech/statement-store';
3
3
  import type { ResultAsync } from 'neverthrow';
4
+ interface Config {
5
+ identityEndpoint: string;
6
+ client: LazyClient;
7
+ }
4
8
  type AccountStatus = 'ASSIGNED' | 'PENDING';
5
9
  type AccountService = {
6
10
  search(query: string, status: AccountStatus): ResultAsync<SearchResponse, Error>;
7
11
  getConsumerInfo(address: string): ResultAsync<Identity | null, Error>;
8
12
  };
9
- type Network = 'paseo-next' | 'paseo-next-v2' | 'preview' | 'stable';
10
13
  type SearchResponse = {
11
14
  candidateAccountId: string;
12
15
  username: string;
@@ -33,5 +36,5 @@ export type Identity = {
33
36
  liteUsername: string;
34
37
  credibility: Credibility;
35
38
  };
36
- export declare const createAccountService: (network: Network, lazyClient: LazyClient) => AccountService;
39
+ export declare const createAccountService: (config: Config) => AccountService;
37
40
  export {};
@@ -2,8 +2,10 @@ import { toHex } from '@novasamatech/scale';
2
2
  import { AccountId } from '@polkadot-api/substrate-bindings';
3
3
  import { errAsync, fromPromise } from 'neverthrow';
4
4
  import { toError } from './helpers.js';
5
- export const createAccountService = (network, lazyClient) => {
6
- const networkConfig = NETWORK_CONFIGS[network];
5
+ export const createAccountService = (config) => {
6
+ const identityEndpoint = config.identityEndpoint.endsWith('/')
7
+ ? config.identityEndpoint
8
+ : `${config.identityEndpoint}/`;
7
9
  return {
8
10
  search(query, status) {
9
11
  // Build query string
@@ -11,7 +13,7 @@ export const createAccountService = (network, lazyClient) => {
11
13
  prefix: query,
12
14
  status,
13
15
  });
14
- const request = fromPromise(fetch(`${networkConfig.apiUrl}/usernames?${params}`, {
16
+ const request = fromPromise(fetch(`${identityEndpoint}usernames?${params}`, {
15
17
  method: 'GET',
16
18
  headers: { Accept: 'application/json' },
17
19
  }), toError);
@@ -25,7 +27,7 @@ export const createAccountService = (network, lazyClient) => {
25
27
  getConsumerInfo(address) {
26
28
  const textDecoder = new TextDecoder();
27
29
  const accountId = AccountId();
28
- const client = lazyClient.getClient();
30
+ const client = config.client.getClient();
29
31
  const api = client.getUnsafeApi();
30
32
  const consumerInfo = fromPromise(api.query.Resources?.Consumers?.getValue(address), toError);
31
33
  return consumerInfo.map(typedRaw => {
@@ -56,29 +58,3 @@ export const createAccountService = (network, lazyClient) => {
56
58
  },
57
59
  };
58
60
  };
59
- const NETWORK_CONFIGS = {
60
- stable: {
61
- id: 'stable',
62
- name: 'PoP Stable',
63
- wsUrl: 'wss://pop3-testnet.parity-lab.parity.io/people',
64
- apiUrl: 'https://polkadot-app.api.polkadotcommunity.foundation/api/v1',
65
- },
66
- preview: {
67
- id: 'preview',
68
- name: 'PoP Preview',
69
- wsUrl: 'wss://previewnet.substrate.dev/people',
70
- apiUrl: 'https://polkadot-app-stg.parity.io/api/v1',
71
- },
72
- 'paseo-next': {
73
- id: 'paseo-next',
74
- name: 'Paseo Next',
75
- wsUrl: 'wss://paseo-people-next-rpc.polkadot.io',
76
- apiUrl: 'https://identity-backend.parity-testnet.parity.io/api/v1',
77
- },
78
- 'paseo-next-v2': {
79
- id: 'paseo-next-v2',
80
- name: 'Paseo Next V2',
81
- wsUrl: 'wss://paseo-people-next-system-rpc.polkadot.io',
82
- apiUrl: 'https://identity-backend-next.parity-testnet.parity.io/api/v1',
83
- },
84
- };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@novasamatech/host-chat",
3
3
  "type": "module",
4
- "version": "0.8.9",
4
+ "version": "0.8.10",
5
5
  "description": "Host statement store chat integration",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
@@ -40,9 +40,9 @@
40
40
  "README.md"
41
41
  ],
42
42
  "dependencies": {
43
- "@novasamatech/scale": "0.8.9",
44
- "@novasamatech/statement-store": "0.8.9",
45
- "@novasamatech/storage-adapter": "0.8.9",
43
+ "@novasamatech/scale": "0.8.10",
44
+ "@novasamatech/statement-store": "0.8.10",
45
+ "@novasamatech/storage-adapter": "0.8.10",
46
46
  "nanoid": "5.1.11",
47
47
  "neverthrow": "^8.2.0"
48
48
  },