@astrale-os/kernel-client 0.6.0-beta.68 → 0.6.0-beta.69

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.
@@ -12,6 +12,8 @@ export interface AuthApi {
12
12
  whoami(options?: RequestOptions): Promise<Identity & Authentication>;
13
13
  whois(input: WhoisInput, options?: RequestOptions): Promise<(Identity & Authentication) | null>;
14
14
  can(input: PolicyDecisionInput, options?: RequestOptions): Promise<boolean>;
15
+ /** One ordered decision per check; batches above the Kernel bound are split and rejoined. */
16
+ can(input: readonly PolicyDecisionInput[], options?: RequestOptions): Promise<readonly boolean[]>;
15
17
  impersonate(input: ImpersonateOptions, options?: RequestOptions): Promise<MintedCredential>;
16
18
  mint(input: MintOptions, options?: RequestOptions): Promise<MintedCredential>;
17
19
  delegate(identity: IdentityId, input: DelegateOptions, options?: RequestOptions): Promise<MintedCredential>;
@@ -9,5 +9,8 @@ export interface PolicyDecisionInput {
9
9
  }
10
10
  export declare const IDENTITY_CAN_PATH: NodePath;
11
11
  export declare function authorizationApi(call: AuthCall): Readonly<{
12
- can(input: PolicyDecisionInput, options?: RequestOptions): Promise<boolean>;
12
+ can: {
13
+ (input: PolicyDecisionInput, options?: RequestOptions): Promise<boolean>;
14
+ (input: readonly PolicyDecisionInput[], options?: RequestOptions): Promise<readonly boolean[]>;
15
+ };
13
16
  }>;
@@ -1,14 +1,34 @@
1
1
  import { Path } from '@astrale-os/kernel-core/path';
2
+ import { MAXIMUM_CHECKS } from '@astrale-os/kernel-core/schema/kernel/syscalls/contracts';
2
3
  import { identity } from '@astrale-os/kernel-core/schema/kernel/syscalls/references';
3
4
  const identityOwner = Path.project(identity.whoami.owner);
4
5
  export const IDENTITY_CAN_PATH = Path.staticMethod(identityOwner, identity.can.name).raw;
5
6
  export function authorizationApi(call) {
6
- return Object.freeze({
7
- async can(input, options) {
8
- const output = (await call(IDENTITY_CAN_PATH, Object.freeze({ policy: policyPath(input.policy), object: input.object }), options));
7
+ async function can(input, options) {
8
+ if (!isBatch(input)) {
9
+ const output = (await call(IDENTITY_CAN_PATH, check(input), options));
9
10
  return output.allowed;
10
- },
11
- });
11
+ }
12
+ const batches = [];
13
+ for (let offset = 0; offset < input.length; offset += MAXIMUM_CHECKS) {
14
+ batches.push(input.slice(offset, offset + MAXIMUM_CHECKS));
15
+ }
16
+ const decided = await Promise.all(batches.map(async (batch) => {
17
+ const output = (await call(IDENTITY_CAN_PATH, Object.freeze({ checks: batch.map(check) }), options));
18
+ if (output.decisions.length !== batch.length) {
19
+ throw new TypeError('Identity.can answered a different number of decisions.');
20
+ }
21
+ return output.decisions.map(({ allowed }) => allowed);
22
+ }));
23
+ return Object.freeze(decided.flat());
24
+ }
25
+ return Object.freeze({ can });
26
+ }
27
+ function isBatch(input) {
28
+ return Array.isArray(input);
29
+ }
30
+ function check(input) {
31
+ return Object.freeze({ policy: policyPath(input.policy), object: input.object });
12
32
  }
13
33
  function policyPath(input) {
14
34
  return input instanceof Path || typeof input === 'string'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrale-os/kernel-client",
3
- "version": "0.6.0-beta.68",
3
+ "version": "0.6.0-beta.69",
4
4
  "description": "Universal Client — protocol-first, transport-agnostic",
5
5
  "keywords": [
6
6
  "astrale",
@@ -65,14 +65,14 @@
65
65
  "access": "public"
66
66
  },
67
67
  "dependencies": {
68
- "@astrale-os/kernel-core": "0.9.0-beta.51",
69
- "@astrale-os/kernel-dsl": "0.2.0-beta.36",
70
- "@astrale-os/kernel-protocol": "0.5.0-beta.57",
68
+ "@astrale-os/kernel-core": "0.9.0-beta.52",
69
+ "@astrale-os/kernel-dsl": "0.2.0-beta.37",
70
+ "@astrale-os/kernel-protocol": "0.5.0-beta.58",
71
71
  "@tanstack/pacer": "0.20.1",
72
72
  "msgpackr": "^2.0.5"
73
73
  },
74
74
  "devDependencies": {
75
- "@astrale-os/kernel-server": "0.5.0-beta.59",
75
+ "@astrale-os/kernel-server": "0.5.0-beta.60",
76
76
  "@astrale/typescript-config": "npm:@jsr/astrale__typescript-config@~1.1.0",
77
77
  "@types/node": "^22.0.0",
78
78
  "typescript": "7.0.2",