@novasamatech/host-container 0.7.2-2 → 0.7.3

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
@@ -102,6 +102,8 @@ container.handlePermission(async (permission, { ok, err }) => {
102
102
 
103
103
  ### handlePushNotification
104
104
 
105
+ Gated by the `Notifications` device permission: the container consults `handleDevicePermission` with `'Notifications'` before invoking this handler. If the device permission is denied or errors, the handler is skipped and the request fails.
106
+
105
107
  ```ts
106
108
  container.handlePushNotification(async (notification, { ok, err }) => {
107
109
  await showNotification(notification);
@@ -1,4 +1,4 @@
1
- import { ChatBotRegistrationErr, ChatMessagePostingErr, ChatRoomRegistrationErr, CreateProofErr, CreateTransactionErr, DeriveEntropyErr, GenericError, LoginErr, NavigateToErr, PaymentBalanceErr, PaymentRequestErr, PaymentStatusErr, PaymentTopUpErr, PreimageSubmitErr, RemotePermission, RequestCredentialsErr, SigningErr, StatementProofErr, StorageErr, createTransport, enumValue, isEnumVariant, resultErr, resultOk, } from '@novasamatech/host-api';
1
+ import { ChatBotRegistrationErr, ChatMessagePostingErr, ChatRoomRegistrationErr, CreateProofErr, CreateTransactionErr, DeriveEntropyErr, DevicePermission, GenericError, LoginErr, NavigateToErr, PaymentBalanceErr, PaymentRequestErr, PaymentStatusErr, PaymentTopUpErr, PreimageSubmitErr, RemotePermission, RequestCredentialsErr, SigningErr, StatementProofErr, StorageErr, createTransport, enumValue, isEnumVariant, resultErr, resultOk, } from '@novasamatech/host-api';
2
2
  import { err, errAsync, ok, okAsync } from 'neverthrow';
3
3
  import { createChainConnectionManager } from './chainConnectionManager.js';
4
4
  const UNSUPPORTED_MESSAGE_FORMAT_ERROR = 'Unsupported message format';
@@ -61,14 +61,14 @@ export function createContainer(provider) {
61
61
  return makeRequestSlot(method, handler);
62
62
  }
63
63
  function makeInterruptSlot(method, makeDefaultInterrupt) {
64
- // Cast needed: the default handler ignores typed params/send which TypeScript can't verify
65
- // matches the generic Method's subscription type without evaluating template literal types.
66
- const defaultHandler = ((_params, _send, interrupt) => {
64
+ const defaultHandler = (_params, _send, interrupt) => {
65
+ // Cast needed: the default handler ignores typed params/send which TypeScript can't verify
66
+ // matches the generic Method's subscription type without evaluating template literal types.
67
67
  queueMicrotask(() => interrupt(makeDefaultInterrupt()));
68
68
  return () => {
69
69
  /* nothing to clean up */
70
70
  };
71
- });
71
+ };
72
72
  const update = makeSubscriptionSlot(method, defaultHandler);
73
73
  return { update, makeDefaultInterrupt };
74
74
  }
@@ -100,6 +100,34 @@ export function createContainer(provider) {
100
100
  call: (...args) => current(...args),
101
101
  };
102
102
  }
103
+ function makeDevicePermissionGatedRequestSlot(method, permissionVariant, makeError) {
104
+ const defaultHandler = async () => enumValue('v1', resultErr(makeError()));
105
+ let current = defaultHandler;
106
+ let version = 0;
107
+ transport.handleRequest(method, async (params) => {
108
+ const permissionResponse = await handleDevicePermissionSlot.call(enumValue('v1', permissionVariant));
109
+ const permissionGranted = isEnumVariant(permissionResponse, 'v1') &&
110
+ permissionResponse.value.success === true &&
111
+ permissionResponse.value.value === true;
112
+ if (!permissionGranted) {
113
+ return enumValue('v1', resultErr(makeError()));
114
+ }
115
+ return current(params);
116
+ });
117
+ return {
118
+ update: handler => {
119
+ current = handler;
120
+ const myVersion = ++version;
121
+ return () => {
122
+ if (myVersion !== version)
123
+ return;
124
+ version++;
125
+ current = defaultHandler;
126
+ };
127
+ },
128
+ call: (...args) => current(...args),
129
+ };
130
+ }
103
131
  function handleV1Request(slot, makeError, handler) {
104
132
  init();
105
133
  const version = 'v1';
@@ -148,7 +176,7 @@ export function createContainer(provider) {
148
176
  const handleFeatureSupportedSlot = makeNotImplementedSlot('host_feature_supported', () => new GenericError({ reason: NOT_IMPLEMENTED }));
149
177
  const handleDevicePermissionSlot = makeNotImplementedSlot('host_device_permission', () => new GenericError({ reason: NOT_IMPLEMENTED }));
150
178
  const handleRemotePermissionSlot = makeNotImplementedSlot('remote_permission', () => new GenericError({ reason: NOT_IMPLEMENTED }));
151
- const handlePushNotificationSlot = makeNotImplementedSlot('host_push_notification', () => new GenericError({ reason: NOT_IMPLEMENTED }));
179
+ const handlePushNotificationSlot = makeDevicePermissionGatedRequestSlot('host_push_notification', 'Notifications', () => new GenericError({ reason: NOT_IMPLEMENTED }));
152
180
  const handleNavigateToSlot = makeNotImplementedSlot('host_navigate_to', () => new NavigateToErr.Unknown({ reason: NOT_IMPLEMENTED }));
153
181
  const handleChatCreateRoomSlot = makeNotImplementedSlot('host_chat_create_room', () => new ChatRoomRegistrationErr.Unknown({ reason: NOT_IMPLEMENTED }));
154
182
  const handleChatBotRegistrationSlot = makeNotImplementedSlot('host_chat_register_bot', () => new ChatBotRegistrationErr.Unknown({ reason: NOT_IMPLEMENTED }));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@novasamatech/host-container",
3
3
  "type": "module",
4
- "version": "0.7.2-2",
4
+ "version": "0.7.3",
5
5
  "description": "Host container for hosting and managing products within the Polkadot ecosystem.",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
@@ -27,7 +27,7 @@
27
27
  "dependencies": {
28
28
  "@noble/hashes": "2.2.0",
29
29
  "polkadot-api": ">=2",
30
- "@novasamatech/host-api": "0.7.2-2",
30
+ "@novasamatech/host-api": "0.7.3",
31
31
  "nanoid": "5.1.9",
32
32
  "neverthrow": "^8.2.0"
33
33
  },