@parity/product-sdk-host 0.18.0 → 0.19.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/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { JsonRpcProvider, PolkadotSigner } from 'polkadot-api';
2
- import { Topic, RemoteStatementStoreSubscribeItem, Statement, StatementProof, SignedStatement, HexString, scale, TrUApiClient, AllocatableResource, AllocationOutcome, VersionedHostGetUserIdError, HostRequestLoginResponse, VersionedHostRequestLoginError, ProductAccountId, ProductAccount as ProductAccount$1, VersionedHostAccountGetError, RingLocation, VersionedHostAccountRegisterRingVrfKeyError, RingVrfKeyDisclosure, RegisteredRingVrfKey as RegisteredRingVrfKey$1, VersionedHostAccountListRingVrfKeysError, ProductProofContext, ContextualAlias as ContextualAlias$1, VersionedHostAccountGetAliasError, LegacyAccount, VersionedHostGetLegacyAccountsError, HostAccountCreateProofResponse, VersionedHostAccountCreateProofError, VersionedHostAccountRingVrfSignError, VrfTranscriptItem as VrfTranscriptItem$1, VrfSignature as VrfSignature$1, VersionedHostAccountSignVrfError, HostAccountConnectionStatusSubscribeItem, HostDevicePermissionRequest, RemotePermission, HostThemeSubscribeItem, ChatBotRegistrationStatus, HostChatCreateRoomRequest, ChatRoomRegistrationStatus, HostChatRegisterBotRequest, ChatMessageContent, ChatRoom, HostChatActionSubscribeItem, HostPaymentBalanceSubscribeItem, CoinPaymentPurseId, Balance, PaymentTopUpSource, HostPaymentStatusSubscribeItem, HostPushNotificationRequest, NotificationId } from '@parity/truapi';
2
+ import { Topic, RemoteStatementStoreSubscribeItem, Statement, StatementProof, SignedStatement, HexString, scale, TrUApiClient, AllocatableResource, AllocationOutcome, VersionedHostGetUserIdError, HostRequestLoginResponse, VersionedHostRequestLoginError, ProductAccountId, ProductAccount as ProductAccount$1, VersionedHostAccountGetError, RingLocation, VersionedHostAccountRegisterRingVrfKeyError, RingVrfKeyDisclosure, RegisteredRingVrfKey as RegisteredRingVrfKey$1, VersionedHostAccountListRingVrfKeysError, ProductProofContext, ContextualAlias as ContextualAlias$1, VersionedHostAccountGetAliasError, LegacyAccount, VersionedHostGetLegacyAccountsError, HostAccountCreateProofResponse, VersionedHostAccountCreateProofError, VersionedHostAccountRingVrfSignError, VrfTranscriptItem as VrfTranscriptItem$1, VrfSignature as VrfSignature$1, VersionedHostAccountSignVrfError, HostAccountConnectionStatusSubscribeItem, HostDevicePermissionRequest, RemotePermission, HostThemeSubscribeItem, HostLocaleSubscribeItem, ChatBotRegistrationStatus, HostChatCreateRoomRequest, ChatRoomRegistrationStatus, HostChatRegisterBotRequest, ChatMessageContent, ChatRoom, HostChatActionSubscribeItem, HostPaymentBalanceSubscribeItem, CoinPaymentPurseId, Balance, PaymentTopUpSource, HostPaymentStatusSubscribeItem, HostPushNotificationRequest, NotificationId } from '@parity/truapi';
3
3
  export { AllocatableResource, AllocationOutcome, ChatMessageContent, ChatRoom, DerivationIndex, HexString, HostPaymentBalanceSubscribeItem, HostPaymentStatusSubscribeItem, NotificationId, PaymentTopUpSource, ProductAccountId, ProductProofContext, HostPushNotificationError as PushNotificationError, RemotePermission, RingLocation, RingVrfKeyDisclosure, SignedStatement, Statement, StatementProof, ThemeName, ThemeVariant, Topic } from '@parity/truapi';
4
4
  import { SdkError } from '@parity/product-sdk-errors';
5
5
  export { SdkError, isSdkError } from '@parity/product-sdk-errors';
@@ -729,6 +729,54 @@ interface ThemeProvider {
729
729
  */
730
730
  declare function getThemeProvider(): Promise<ThemeProvider | null>;
731
731
 
732
+ /**
733
+ * Higher-level wrapper for the host's locale subscription, backed by
734
+ * `truApi.locale.subscribe`.
735
+ *
736
+ * `getLocaleProvider` returns a handle whose `subscribeLocale(cb)` delivers a
737
+ * typed {@link LocaleInfo} — a `{ languageTag }` struct carrying a BCP 47 tag
738
+ * such as `"en"`, `"pt-BR"` or `"zh-Hans"` — and yields a
739
+ * {@link HostSubscription} (`unsubscribe` + `onInterrupt`).
740
+ *
741
+ * @module
742
+ */
743
+
744
+ /**
745
+ * Host locale value. A `{ languageTag }` struct re-exported from
746
+ * `@parity/truapi`.
747
+ */
748
+ type LocaleInfo = HostLocaleSubscribeItem;
749
+ /**
750
+ * Host locale provider handle. `subscribeLocale(callback)` receives a typed
751
+ * {@link LocaleInfo} on every change and returns a {@link HostSubscription}.
752
+ */
753
+ interface LocaleProvider {
754
+ subscribeLocale(callback: (locale: LocaleInfo) => void): HostSubscription;
755
+ }
756
+ /**
757
+ * Get the host locale provider, backed by `truApi.locale.*`. Returns `null`
758
+ * when running outside a host container.
759
+ *
760
+ * The tag is whatever the host reports; a product that ships no catalog entry
761
+ * for it chooses its own fallback.
762
+ *
763
+ * @returns The locale provider, or `null` if unavailable.
764
+ *
765
+ * @example
766
+ * ```ts
767
+ * import { getLocaleProvider } from "@parity/product-sdk-host";
768
+ *
769
+ * const provider = await getLocaleProvider();
770
+ * if (provider) {
771
+ * const sub = provider.subscribeLocale((locale) => {
772
+ * i18n.activate(SUPPORTED.has(locale.languageTag) ? locale.languageTag : "en");
773
+ * });
774
+ * // sub.unsubscribe() to stop listening
775
+ * }
776
+ * ```
777
+ */
778
+ declare function getLocaleProvider(): Promise<LocaleProvider | null>;
779
+
732
780
  /**
733
781
  * Higher-level wrapper for the host's entropy derivation (RFC-0007).
734
782
  *
@@ -1143,4 +1191,4 @@ declare function broadcastTransaction(genesisHash: HexString, transaction: HexSt
1143
1191
  */
1144
1192
  declare function stopTransaction(genesisHash: HexString, operationId: string): Promise<Result<void, HostError>>;
1145
1193
 
1146
- export { type AccountsProvider, BULLETIN_RPCS, ChainNotSupportedError, type ChainProperties, type ChainSpec, type ChatBotRegistrationResult, type ChatManager, type ChatReceivedAction, type ChatRoomRegistrationResult, type ContextualAlias, DEFAULT_BULLETIN_ENDPOINT, type DevicePermissionKind, type Feature, type HostAccount, HostCallFailedError, HostError, type HostErrorPayload, type HostLocalStorage, HostResponseDecodeError, type HostStatementStore, type HostSubscription, HostUnavailableError, type NotificationManager, type PaymentManager, type PreimageManager, type ProductAccount, type ProductAccountLookup, type PushNotificationInput, type RegisteredRingVrfKey, type RemotePermissionItem, type ResultAsync, type RingVRFProof, type RingVrfKeyHandle, type RingVrfPublicKey, type StatementTopicFilter, type StatementsPage, type ThemeMode, type ThemeProvider, type TruApi, type VrfSignature, type VrfTranscriptItem, type WithDecodeError, broadcastTransaction, createHostLocalStorage, createHostPreimageManager, createProofAuthorized, deriveEntropy, featureSupported, findRingVrfKeyHandle, formatHostError, fromHex, getAccountsProvider, getChainSpec, getChatManager, getHostLocalStorage, getHostProvider, getNotificationManager, getPaymentManager, getPreimageManager, getStatementStore, getThemeProvider, getTruApi, isChainSupported, isHostError, isInsideContainer, navigateTo, requestDevicePermission, requestPermission, requestResourceAllocation, stopTransaction, toHex };
1194
+ export { type AccountsProvider, BULLETIN_RPCS, ChainNotSupportedError, type ChainProperties, type ChainSpec, type ChatBotRegistrationResult, type ChatManager, type ChatReceivedAction, type ChatRoomRegistrationResult, type ContextualAlias, DEFAULT_BULLETIN_ENDPOINT, type DevicePermissionKind, type Feature, type HostAccount, HostCallFailedError, HostError, type HostErrorPayload, type HostLocalStorage, HostResponseDecodeError, type HostStatementStore, type HostSubscription, HostUnavailableError, type LocaleInfo, type LocaleProvider, type NotificationManager, type PaymentManager, type PreimageManager, type ProductAccount, type ProductAccountLookup, type PushNotificationInput, type RegisteredRingVrfKey, type RemotePermissionItem, type ResultAsync, type RingVRFProof, type RingVrfKeyHandle, type RingVrfPublicKey, type StatementTopicFilter, type StatementsPage, type ThemeMode, type ThemeProvider, type TruApi, type VrfSignature, type VrfTranscriptItem, type WithDecodeError, broadcastTransaction, createHostLocalStorage, createHostPreimageManager, createProofAuthorized, deriveEntropy, featureSupported, findRingVrfKeyHandle, formatHostError, fromHex, getAccountsProvider, getChainSpec, getChatManager, getHostLocalStorage, getHostProvider, getLocaleProvider, getNotificationManager, getPaymentManager, getPreimageManager, getStatementStore, getThemeProvider, getTruApi, isChainSupported, isHostError, isInsideContainer, navigateTo, requestDevicePermission, requestPermission, requestResourceAllocation, stopTransaction, toHex };
package/dist/index.js CHANGED
@@ -803,25 +803,23 @@ function sameRingLocation(a, b) {
803
803
  function findRingVrfKeyHandle(keys, ring) {
804
804
  return keys.find((key) => key.rings.some((candidate) => sameRingLocation(candidate, ring)))?.handle;
805
805
  }
806
- var GENERAL_TX_EXT_VERSION = 5;
807
- function selectHostTxExtVersion(formatVersions, txExtVersions) {
806
+ var V5_FORMAT_SELECTOR = 5;
807
+ function selectHostTxExtVersion(formatVersions) {
808
808
  if (formatVersions.length === 0) {
809
809
  throw new Error("No extrinsic version found in metadata");
810
810
  }
811
811
  if (formatVersions.includes(4)) {
812
812
  return 0;
813
813
  }
814
- if (txExtVersions.includes(GENERAL_TX_EXT_VERSION)) {
815
- return GENERAL_TX_EXT_VERSION;
814
+ if (formatVersions.includes(5)) {
815
+ return V5_FORMAT_SELECTOR;
816
816
  }
817
817
  throw new Error(
818
- `Runtime offers no V4 extrinsic and no transaction-extension version ${GENERAL_TX_EXT_VERSION} (supported: ${txExtVersions.join(", ") || "none"}); cannot select a txExtVersion the host can assemble.`
818
+ `Runtime offers no extrinsic format 4 or 5 (offers: ${formatVersions.join(", ")}); the host protocol has no txExtVersion for it.`
819
819
  );
820
820
  }
821
821
  function deriveTxExtVersion(metadata) {
822
- const extrinsic = unifyMetadata(decAnyMetadata(metadata)).extrinsic;
823
- const txExtVersions = Object.keys(extrinsic.signedExtensions).map(Number);
824
- return selectHostTxExtVersion(extrinsic.version, txExtVersions);
822
+ return selectHostTxExtVersion(unifyMetadata(decAnyMetadata(metadata)).extrinsic.version);
825
823
  }
826
824
  var deps = { deriveTxExtVersion };
827
825
  function toHostExtensions(signedExtensions) {
@@ -1073,6 +1071,19 @@ async function getThemeProvider() {
1073
1071
  const client = await getClient();
1074
1072
  return client ? adaptThemeProvider(client) : null;
1075
1073
  }
1074
+
1075
+ // src/locale.ts
1076
+ function adaptLocaleProvider(client) {
1077
+ return {
1078
+ subscribeLocale(callback) {
1079
+ return subscribeWithInterrupt(client.locale.subscribe(), callback);
1080
+ }
1081
+ };
1082
+ }
1083
+ async function getLocaleProvider() {
1084
+ const client = await getClient();
1085
+ return client ? adaptLocaleProvider(client) : null;
1086
+ }
1076
1087
  var log5 = createLogger("host:entropy");
1077
1088
  async function deriveEntropy(key) {
1078
1089
  const truApi = await getTruApi();
@@ -1286,6 +1297,6 @@ async function stopTransaction(genesisHash, operationId) {
1286
1297
  );
1287
1298
  }
1288
1299
 
1289
- export { BULLETIN_RPCS, ChainNotSupportedError, DEFAULT_BULLETIN_ENDPOINT, HostCallFailedError, HostError, HostResponseDecodeError, HostUnavailableError, broadcastTransaction, createHostLocalStorage, createHostPreimageManager, createProofAuthorized, deriveEntropy, featureSupported, findRingVrfKeyHandle, formatHostError, fromHex, getAccountsProvider, getChainSpec, getChatManager, getHostChainInfo, getHostLocalStorage, getHostProvider, getNotificationManager, getPaymentManager, getPreimageManager, getStatementStore, getThemeProvider, getTruApi, isChainSupported, isHostError, isInsideContainer, navigateTo, requestDevicePermission, requestPermission, requestResourceAllocation, stopTransaction, toHex };
1300
+ export { BULLETIN_RPCS, ChainNotSupportedError, DEFAULT_BULLETIN_ENDPOINT, HostCallFailedError, HostError, HostResponseDecodeError, HostUnavailableError, broadcastTransaction, createHostLocalStorage, createHostPreimageManager, createProofAuthorized, deriveEntropy, featureSupported, findRingVrfKeyHandle, formatHostError, fromHex, getAccountsProvider, getChainSpec, getChatManager, getHostChainInfo, getHostLocalStorage, getHostProvider, getLocaleProvider, getNotificationManager, getPaymentManager, getPreimageManager, getStatementStore, getThemeProvider, getTruApi, isChainSupported, isHostError, isInsideContainer, navigateTo, requestDevicePermission, requestPermission, requestResourceAllocation, stopTransaction, toHex };
1290
1301
  //# sourceMappingURL=index.js.map
1291
1302
  //# sourceMappingURL=index.js.map