@parity/product-sdk-host 0.10.3 → 0.11.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/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { JsonRpcProvider } from 'polkadot-api';
2
2
  import * as _novasamatech_host_api from '@novasamatech/host-api';
3
- import { Subscription, Transport, CodecType, AllocatableResource as AllocatableResource$1, AllocationOutcome as AllocationOutcome$1, RemotePermission as RemotePermission$1, DevicePermission } from '@novasamatech/host-api';
3
+ import { Subscription, Transport, CodecType, AllocatableResource as AllocatableResource$1, AllocationOutcome as AllocationOutcome$1, RemotePermission as RemotePermission$1, DevicePermission, HexString } from '@novasamatech/host-api';
4
4
  export { HexString, PushNotificationError, assertEnumVariant, enumValue, fromHex, isEnumVariant, resultErr, resultOk, toHex, unwrapResultOrThrow } from '@novasamatech/host-api';
5
5
  import * as _novasamatech_host_api_wrapper from '@novasamatech/host-api-wrapper';
6
6
  import { hostLocalStorage, createStatementStore, ProductAccountId as ProductAccountId$1, SignedStatement as SignedStatement$1, Statement as Statement$1, StatementTopicFilter as StatementTopicFilter$1, StatementsPage as StatementsPage$1, Topic as Topic$1, createAccountsProvider, preimageManager, ThemeMode as ThemeMode$1, createThemeProvider, ChatBotRegistrationResult as ChatBotRegistrationResult$1, ChatCustomMessageRenderer as ChatCustomMessageRenderer$1, ChatCustomMessageRendererParams as ChatCustomMessageRendererParams$1, createProductChatManager, ChatMessageContent as ChatMessageContent$1, ChatReceivedAction as ChatReceivedAction$1, ChatRoom as ChatRoom$1, ChatRoomRegistrationResult as ChatRoomRegistrationResult$1, PaymentBalance as PaymentBalance$1, paymentManager, PaymentStatus as PaymentStatus$1, TopUpSource as TopUpSource$1, notificationManager } from '@novasamatech/host-api-wrapper';
@@ -801,4 +801,229 @@ type PushNotificationInput = Parameters<NotificationManager["push"]>[0];
801
801
  */
802
802
  declare function getNotificationManager(): Promise<NotificationManager | null>;
803
803
 
804
- export { type AccountsProvider, type AllocatableResource, type AllocatableResourceTag, type AllocationOutcome, type AllocationOutcomeTag, BULLETIN_RPCS, ChainNotSupportedError, type ChatBotRegistrationResult, type ChatCustomMessageRenderer, type ChatCustomMessageRendererParams, type ChatManager, type ChatMessageContent, type ChatReceivedAction, type ChatRoom, type ChatRoomRegistrationResult, type ContextualAlias, DEFAULT_BULLETIN_ENDPOINT, type DevicePermissionKind, type HostAccount, type HostLocalStorage, type HostStatementStore, type HostSubscription, type NotificationId, type NotificationManager, type PaymentBalance, type PaymentManager, type PaymentStatus, type PreimageManager, type ProductAccount, type ProductAccountId, type PushNotificationInput, type RemotePermission, type RemotePermissionItem, type RemotePermissionTag, type ResultAsync, type SignedStatement, type Statement, type StatementProof, type StatementTopicFilter, type StatementsPage, type ThemeMode, type ThemeName, type ThemeProvider, type ThemeVariant, type TopUpSource, type Topic, type TruApi, createHostLocalStorage, createHostPreimageManager, createProofAuthorized, deriveEntropy, formatHostError, getAccountsProvider, getChatManager, getHostLocalStorage, getHostProvider, getNotificationManager, getPaymentManager, getPreimageManager, getStatementStore, getThemeProvider, getTruApi, isInsideContainer, isInsideContainerSync, matchChatCustomRenderers, requestDevicePermission, requestPermission, requestResourceAllocation };
804
+ /**
805
+ * Higher-level wrapper for the host's deep-link navigation.
806
+ *
807
+ * `hostApi.navigateTo` is reachable via {@link getTruApi}, but consumers have
808
+ * to wrap the URL in the versioned envelope (`enumValue("v1", ...)`) and
809
+ * unwrap the neverthrow `ResultAsync` themselves. {@link navigateTo} collapses
810
+ * that to a throw-on-error Promise that matches the shape of
811
+ * {@link requestPermission} and {@link deriveEntropy}.
812
+ *
813
+ * @module
814
+ */
815
+ /**
816
+ * Ask the host to navigate to a URL (deep link or external link).
817
+ *
818
+ * Builds the `v1` envelope, calls `hostApi.navigateTo`, and unwraps the
819
+ * response. The host resolves the destination itself — a `dot`-suffixed
820
+ * deep link (e.g. `"https://search.dot"`) routes to another app/route inside
821
+ * the container, an `https://` URL opens externally.
822
+ *
823
+ * @param url - The URL to navigate to.
824
+ * @throws If the host is unavailable, denies the navigation
825
+ * (`NavigateToErr::PermissionDenied`), or fails for any other reason
826
+ * (`NavigateToErr::Unknown`).
827
+ *
828
+ * @example
829
+ * ```ts
830
+ * import { navigateTo } from "@parity/product-sdk-host";
831
+ *
832
+ * await navigateTo("https://search.dot");
833
+ * ```
834
+ */
835
+ declare function navigateTo(url: string): Promise<void>;
836
+
837
+ /**
838
+ * Higher-level wrappers for the host's feature-support probe.
839
+ *
840
+ * `hostApi.featureSupported` is reachable via {@link getTruApi}, but consumers
841
+ * have to wrap the feature in the versioned envelope (`enumValue("v1", ...)`)
842
+ * and unwrap the neverthrow `ResultAsync` themselves. {@link featureSupported}
843
+ * collapses that to a throw-on-error Promise; {@link isChainSupported} is a
844
+ * convenience over the only feature variant the host exposes today (`Chain`).
845
+ *
846
+ * @module
847
+ */
848
+
849
+ /**
850
+ * A feature the host can be probed for via {@link featureSupported}.
851
+ *
852
+ * As of `host-api` v0.8 the only variant is `Chain`, carrying the chain's
853
+ * `0x`-prefixed genesis hash. Modeled locally (rather than derived from an
854
+ * upstream codec) because the protocol exposes the feature only inline; new
855
+ * variants surface here as a widening of the union.
856
+ */
857
+ type Feature = {
858
+ tag: "Chain";
859
+ value: HexString;
860
+ };
861
+ /**
862
+ * Probe the host for support of a specific feature.
863
+ *
864
+ * Builds the `v1` envelope, calls `hostApi.featureSupported`, unwraps the
865
+ * response, and returns the host's boolean answer.
866
+ *
867
+ * @param feature - The feature to probe for.
868
+ * @returns `true` if the host supports the feature, `false` otherwise.
869
+ * @throws If the host is unavailable or the probe fails (`GenericError`).
870
+ *
871
+ * @example
872
+ * ```ts
873
+ * import { featureSupported } from "@parity/product-sdk-host";
874
+ *
875
+ * const ok = await featureSupported({ tag: "Chain", value: genesisHash });
876
+ * ```
877
+ */
878
+ declare function featureSupported(feature: Feature): Promise<boolean>;
879
+ /**
880
+ * Convenience probe: is the chain with the given genesis hash supported by the
881
+ * host? Wraps {@link featureSupported} for the `Chain` feature variant.
882
+ *
883
+ * @param genesisHash - The chain's `0x`-prefixed genesis hash.
884
+ * @returns `true` if the host supports the chain, `false` otherwise.
885
+ * @throws If the host is unavailable or the probe fails.
886
+ *
887
+ * @example
888
+ * ```ts
889
+ * import { isChainSupported } from "@parity/product-sdk-host";
890
+ *
891
+ * if (!(await isChainSupported(genesisHash))) {
892
+ * tellUserChainUnavailable();
893
+ * }
894
+ * ```
895
+ */
896
+ declare function isChainSupported(genesisHash: HexString): Promise<boolean>;
897
+
898
+ /**
899
+ * Higher-level wrapper for the host's chain-spec lookups.
900
+ *
901
+ * The host exposes three separate chain-spec calls — `chainSpecGenesisHash`,
902
+ * `chainSpecChainName`, and `chainSpecProperties` — each reachable via
903
+ * {@link getTruApi} but each requiring its own `enumValue("v1", ...)` wrap
904
+ * and neverthrow `ResultAsync` unwrap. {@link getChainSpec} fetches all three
905
+ * in one call and returns a single struct so callers read whichever field
906
+ * they need, matching the JSON-RPC `chainSpec_v1_*` family they mirror.
907
+ *
908
+ * @module
909
+ */
910
+
911
+ /**
912
+ * Chain SS58/token properties as reported by the host's
913
+ * `chainSpecProperties` call.
914
+ *
915
+ * The host returns this as a JSON string (mirroring the substrate
916
+ * `chainSpec_v1_properties` JSON-RPC, whose payload is an open-ended object).
917
+ * {@link getChainSpec} parses it into {@link properties} and also surfaces the
918
+ * untouched JSON as {@link propertiesRaw}. The well-known substrate fields are
919
+ * typed for convenience; the index signature keeps any chain-specific extras
920
+ * reachable without `any` at the call site.
921
+ */
922
+ interface ChainProperties {
923
+ /** Address prefix used for SS58 encoding (e.g. `0` for Polkadot). */
924
+ ss58Format?: number;
925
+ /** Decimal places of the chain's native token(s). */
926
+ tokenDecimals?: number | number[];
927
+ /** Ticker symbol(s) of the chain's native token(s). */
928
+ tokenSymbol?: string | string[];
929
+ /** Chain-specific extras passed through verbatim from the JSON payload. */
930
+ [key: string]: unknown;
931
+ }
932
+ /**
933
+ * Combined chain-spec view returned by {@link getChainSpec}.
934
+ */
935
+ interface ChainSpec {
936
+ /** The chain's `0x`-prefixed genesis hash, as reported by the host. */
937
+ genesisHash: HexString;
938
+ /** Human-readable chain name (e.g. `"Polkadot"`). */
939
+ name: string;
940
+ /**
941
+ * Parsed chain properties, or `null` if the host's JSON payload couldn't
942
+ * be parsed. Inspect {@link propertiesRaw} for the original string.
943
+ */
944
+ properties: ChainProperties | null;
945
+ /** The untouched JSON string the host returned for properties. */
946
+ propertiesRaw: string;
947
+ }
948
+ /**
949
+ * Fetch a chain's full spec (genesis hash, name, and properties) from the host
950
+ * in one call.
951
+ *
952
+ * Issues the three underlying `chainSpec*` requests concurrently, unwraps each
953
+ * `v1` envelope, and parses the properties JSON. Note the `genesisHash` in the
954
+ * result is the value the host echoes back from `chainSpecGenesisHash` for the
955
+ * looked-up chain — pass the chain's known genesis hash as the lookup key.
956
+ *
957
+ * @param genesisHash - The `0x`-prefixed genesis hash identifying the chain.
958
+ * @returns The combined {@link ChainSpec}, or `null` if the host is
959
+ * unavailable (running outside a container).
960
+ * @throws If any of the underlying host calls fail (`GenericError`).
961
+ *
962
+ * @example
963
+ * ```ts
964
+ * import { getChainSpec } from "@parity/product-sdk-host";
965
+ *
966
+ * const spec = await getChainSpec(genesisHash);
967
+ * if (spec) {
968
+ * console.log(spec.name, spec.properties?.tokenSymbol);
969
+ * }
970
+ * ```
971
+ */
972
+ declare function getChainSpec(genesisHash: HexString): Promise<ChainSpec | null>;
973
+
974
+ /**
975
+ * Higher-level wrappers for the host's transaction broadcast lifecycle.
976
+ *
977
+ * `hostApi.chainTransactionBroadcast` / `hostApi.chainTransactionStop` are
978
+ * reachable via {@link getTruApi}, but consumers have to build the versioned
979
+ * envelope (`enumValue("v1", ...)`) and unwrap the neverthrow `ResultAsync`
980
+ * themselves. {@link broadcastTransaction} and {@link stopTransaction}
981
+ * collapse that to throw-on-error Promises, mirroring the JSON-RPC
982
+ * `transaction_v1_broadcast` / `transaction_v1_stop` pair they wrap.
983
+ *
984
+ * @module
985
+ */
986
+
987
+ /**
988
+ * Broadcast a signed transaction to the network via the host.
989
+ *
990
+ * Builds the `v1` envelope, calls `hostApi.chainTransactionBroadcast`, and
991
+ * unwraps the response. The host keeps re-broadcasting until the transaction
992
+ * is finalized/dropped or {@link stopTransaction} is called with the returned
993
+ * operation id.
994
+ *
995
+ * @param genesisHash - The `0x`-prefixed genesis hash of the target chain.
996
+ * @param transaction - The `0x`-prefixed SCALE-encoded signed transaction.
997
+ * @returns The operation id to pass to {@link stopTransaction}, or `null` if
998
+ * the host accepted the broadcast without issuing one.
999
+ * @throws If the host is unavailable or the broadcast fails (`GenericError`).
1000
+ *
1001
+ * @example
1002
+ * ```ts
1003
+ * import { broadcastTransaction, stopTransaction } from "@parity/product-sdk-host";
1004
+ *
1005
+ * const operationId = await broadcastTransaction(genesisHash, signedTx);
1006
+ * // later, to stop re-broadcasting:
1007
+ * if (operationId) await stopTransaction(genesisHash, operationId);
1008
+ * ```
1009
+ */
1010
+ declare function broadcastTransaction(genesisHash: HexString, transaction: HexString): Promise<string | null>;
1011
+ /**
1012
+ * Stop an in-flight broadcast started by {@link broadcastTransaction}.
1013
+ *
1014
+ * Builds the `v1` envelope, calls `hostApi.chainTransactionStop`, and unwraps
1015
+ * the response.
1016
+ *
1017
+ * @param genesisHash - The `0x`-prefixed genesis hash of the target chain.
1018
+ * @param operationId - The operation id returned by
1019
+ * {@link broadcastTransaction}.
1020
+ * @throws If the host is unavailable or the stop fails (`GenericError`).
1021
+ *
1022
+ * @example
1023
+ * ```ts
1024
+ * await stopTransaction(genesisHash, operationId);
1025
+ * ```
1026
+ */
1027
+ declare function stopTransaction(genesisHash: HexString, operationId: string): Promise<void>;
1028
+
1029
+ export { type AccountsProvider, type AllocatableResource, type AllocatableResourceTag, type AllocationOutcome, type AllocationOutcomeTag, BULLETIN_RPCS, ChainNotSupportedError, type ChainProperties, type ChainSpec, type ChatBotRegistrationResult, type ChatCustomMessageRenderer, type ChatCustomMessageRendererParams, type ChatManager, type ChatMessageContent, type ChatReceivedAction, type ChatRoom, type ChatRoomRegistrationResult, type ContextualAlias, DEFAULT_BULLETIN_ENDPOINT, type DevicePermissionKind, type Feature, type HostAccount, type HostLocalStorage, type HostStatementStore, type HostSubscription, type NotificationId, type NotificationManager, type PaymentBalance, type PaymentManager, type PaymentStatus, type PreimageManager, type ProductAccount, type ProductAccountId, type PushNotificationInput, type RemotePermission, type RemotePermissionItem, type RemotePermissionTag, type ResultAsync, type SignedStatement, type Statement, type StatementProof, type StatementTopicFilter, type StatementsPage, type ThemeMode, type ThemeName, type ThemeProvider, type ThemeVariant, type TopUpSource, type Topic, type TruApi, broadcastTransaction, createHostLocalStorage, createHostPreimageManager, createProofAuthorized, deriveEntropy, featureSupported, formatHostError, getAccountsProvider, getChainSpec, getChatManager, getHostLocalStorage, getHostProvider, getNotificationManager, getPaymentManager, getPreimageManager, getStatementStore, getThemeProvider, getTruApi, isChainSupported, isInsideContainer, isInsideContainerSync, matchChatCustomRenderers, navigateTo, requestDevicePermission, requestPermission, requestResourceAllocation, stopTransaction };
package/dist/index.js CHANGED
@@ -296,7 +296,110 @@ async function getNotificationManager() {
296
296
  return null;
297
297
  }
298
298
  }
299
+ var log9 = createLogger("host:navigation");
300
+ async function navigateTo(url) {
301
+ const truApi = await getTruApi();
302
+ if (!truApi) {
303
+ throw new Error("navigateTo: TruAPI unavailable");
304
+ }
305
+ log9.debug("navigateTo", { url });
306
+ await truApi.navigateTo(enumValue("v1", url)).match(
307
+ (_envelope) => void 0,
308
+ (err) => {
309
+ throw new Error(`navigateTo failed: ${formatHostError(err)}`, { cause: err });
310
+ }
311
+ );
312
+ }
313
+ var log10 = createLogger("host:features");
314
+ async function featureSupported(feature) {
315
+ const truApi = await getTruApi();
316
+ if (!truApi) {
317
+ throw new Error("featureSupported: TruAPI unavailable");
318
+ }
319
+ log10.debug("featureSupported", { tag: feature.tag });
320
+ return await truApi.featureSupported(enumValue("v1", feature)).match(
321
+ (envelope) => envelope.value,
322
+ (err) => {
323
+ throw new Error(`featureSupported failed: ${formatHostError(err)}`, { cause: err });
324
+ }
325
+ );
326
+ }
327
+ async function isChainSupported(genesisHash) {
328
+ return await featureSupported({ tag: "Chain", value: genesisHash });
329
+ }
330
+ var log11 = createLogger("host:chain-spec");
331
+ async function getChainSpec(genesisHash) {
332
+ const truApi = await getTruApi();
333
+ if (!truApi) {
334
+ log11.debug("getChainSpec: TruAPI unavailable");
335
+ return null;
336
+ }
337
+ log11.debug("getChainSpec", { genesisHash });
338
+ const [resolvedGenesisHash, name, propertiesRaw] = await Promise.all([
339
+ truApi.chainSpecGenesisHash(enumValue("v1", genesisHash)).match(
340
+ (envelope) => envelope.value,
341
+ (err) => {
342
+ throw new Error(`getChainSpec (genesisHash) failed: ${formatHostError(err)}`, {
343
+ cause: err
344
+ });
345
+ }
346
+ ),
347
+ truApi.chainSpecChainName(enumValue("v1", genesisHash)).match(
348
+ (envelope) => envelope.value,
349
+ (err) => {
350
+ throw new Error(`getChainSpec (chainName) failed: ${formatHostError(err)}`, {
351
+ cause: err
352
+ });
353
+ }
354
+ ),
355
+ truApi.chainSpecProperties(enumValue("v1", genesisHash)).match(
356
+ (envelope) => envelope.value,
357
+ (err) => {
358
+ throw new Error(`getChainSpec (properties) failed: ${formatHostError(err)}`, {
359
+ cause: err
360
+ });
361
+ }
362
+ )
363
+ ]);
364
+ let properties;
365
+ try {
366
+ properties = JSON.parse(propertiesRaw);
367
+ } catch (err) {
368
+ log11.debug("getChainSpec: properties JSON parse failed", err);
369
+ properties = null;
370
+ }
371
+ return { genesisHash: resolvedGenesisHash, name, properties, propertiesRaw };
372
+ }
373
+ var log12 = createLogger("host:chain-transaction");
374
+ async function broadcastTransaction(genesisHash, transaction) {
375
+ const truApi = await getTruApi();
376
+ if (!truApi) {
377
+ throw new Error("broadcastTransaction: TruAPI unavailable");
378
+ }
379
+ log12.debug("broadcastTransaction", { genesisHash });
380
+ return await truApi.chainTransactionBroadcast(enumValue("v1", { genesisHash, transaction })).match(
381
+ (envelope) => envelope.value,
382
+ (err) => {
383
+ throw new Error(`broadcastTransaction failed: ${formatHostError(err)}`, {
384
+ cause: err
385
+ });
386
+ }
387
+ );
388
+ }
389
+ async function stopTransaction(genesisHash, operationId) {
390
+ const truApi = await getTruApi();
391
+ if (!truApi) {
392
+ throw new Error("stopTransaction: TruAPI unavailable");
393
+ }
394
+ log12.debug("stopTransaction", { genesisHash, operationId });
395
+ await truApi.chainTransactionStop(enumValue("v1", { genesisHash, operationId })).match(
396
+ (_envelope) => void 0,
397
+ (err) => {
398
+ throw new Error(`stopTransaction failed: ${formatHostError(err)}`, { cause: err });
399
+ }
400
+ );
401
+ }
299
402
 
300
- export { BULLETIN_RPCS, ChainNotSupportedError, DEFAULT_BULLETIN_ENDPOINT, createHostLocalStorage, createHostPreimageManager, createProofAuthorized, deriveEntropy, formatHostError, getAccountsProvider, getChatManager, getHostLocalStorage, getHostProvider, getNotificationManager, getPaymentManager, getPreimageManager, getStatementStore, getThemeProvider, getTruApi, isInsideContainer, isInsideContainerSync, matchChatCustomRenderers, requestDevicePermission, requestPermission, requestResourceAllocation };
403
+ export { BULLETIN_RPCS, ChainNotSupportedError, DEFAULT_BULLETIN_ENDPOINT, broadcastTransaction, createHostLocalStorage, createHostPreimageManager, createProofAuthorized, deriveEntropy, featureSupported, formatHostError, getAccountsProvider, getChainSpec, getChatManager, getHostLocalStorage, getHostProvider, getNotificationManager, getPaymentManager, getPreimageManager, getStatementStore, getThemeProvider, getTruApi, isChainSupported, isInsideContainer, isInsideContainerSync, matchChatCustomRenderers, navigateTo, requestDevicePermission, requestPermission, requestResourceAllocation, stopTransaction };
301
404
  //# sourceMappingURL=index.js.map
302
405
  //# sourceMappingURL=index.js.map