@oatscenter/trellis 0.100.0-rc.6 → 0.100.0-rc.8

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.
Files changed (30) hide show
  1. package/auth/authority.js +25 -0
  2. package/auth/protocol_wasm/client/trellis_protocol_wasm_bg.wasm +0 -0
  3. package/auth/protocol_wasm/provider/trellis_protocol_wasm_bg.wasm +0 -0
  4. package/auth/protocol_wasm.d.ts +17 -0
  5. package/caller.d.ts +1 -1
  6. package/caller.js +7 -1
  7. package/generated.d.ts +1 -1
  8. package/generated_support.d.ts +8 -0
  9. package/internal_sdk/generated/apis/auth/mod.d.ts +10 -7
  10. package/internal_sdk/generated/apis/auth/mod.js +52 -31
  11. package/internal_sdk/generated/apis/core/mod.d.ts +5 -5
  12. package/internal_sdk/generated/apis/core/mod.js +33 -17
  13. package/internal_sdk/generated/apis/events/mod.d.ts +20 -15
  14. package/internal_sdk/generated/apis/events/mod.js +118 -67
  15. package/internal_sdk/generated/apis/health/mod.d.ts +8 -7
  16. package/internal_sdk/generated/apis/health/mod.js +50 -27
  17. package/internal_sdk/generated/apis/jobs/mod.d.ts +8 -7
  18. package/internal_sdk/generated/apis/jobs/mod.js +50 -27
  19. package/internal_sdk/generated/apis/state/mod.d.ts +13 -9
  20. package/internal_sdk/generated/apis/state/mod.js +69 -41
  21. package/internal_sdk/generated/package.json +2 -2
  22. package/internal_sdk/generated/participants/eventsRuntime/mod.js +1 -1
  23. package/internal_sdk/generated/participants/healthRuntime/mod.js +1 -1
  24. package/internal_sdk/generated/participants/jobsRuntime/mod.js +1 -1
  25. package/internal_sdk/generated/participants/platform/mod.js +1 -1
  26. package/package.json +2 -2
  27. package/portable.d.ts +1 -0
  28. package/service/mod.d.ts +2 -1
  29. package/service/runtime/service.d.ts +14 -12
  30. package/service/runtime/service.js +20 -11
package/auth/authority.js CHANGED
@@ -44,6 +44,30 @@ export class VerifiedAuthority {
44
44
  /** Verified logical caller identity usable by all SDK adapters. */
45
45
  get caller() {
46
46
  const authority = this.#entry.authority;
47
+ // Auth signs the user's own profile into a user principal's authority.
48
+ const profile = authority.principalKind === "user"
49
+ ? authority.extensions["trellis.user.v1"]
50
+ : undefined;
51
+ const text = (value) => typeof value === "string" ? value : undefined;
52
+ const user = profile !== null &&
53
+ typeof profile === "object" &&
54
+ !Array.isArray(profile) &&
55
+ typeof profile.displayName === "string"
56
+ ? {
57
+ displayName: profile.displayName,
58
+ ...(text(profile.givenName) && {
59
+ givenName: text(profile.givenName),
60
+ }),
61
+ ...(text(profile.familyName) && {
62
+ familyName: text(profile.familyName),
63
+ }),
64
+ ...(text(profile.email) && { email: text(profile.email) }),
65
+ emailVerified: profile.emailVerified === true,
66
+ ...(text(profile.avatarUrl) && {
67
+ avatarUrl: text(profile.avatarUrl),
68
+ }),
69
+ }
70
+ : undefined;
47
71
  return {
48
72
  authorityDigest: this.digest,
49
73
  principalId: authority.principalId,
@@ -57,6 +81,7 @@ export class VerifiedAuthority {
57
81
  oauthGrantId: authority.oauthGrantId,
58
82
  capabilities: authority.capabilities,
59
83
  apis: authority.apis,
84
+ ...(user && { user }),
60
85
  };
61
86
  }
62
87
  /** Time and observed retirement are checked again immediately before authorized work. */
@@ -172,6 +172,23 @@ export type AuthenticatedCaller = {
172
172
  oauthGrantId?: string;
173
173
  capabilities: CapabilityAuthority[];
174
174
  apis: AuthorityApi[];
175
+ /** The user's own profile, for user principals. */
176
+ user?: CallerUser;
177
+ };
178
+ /**
179
+ * Auth's profile of a user caller, as of the authority's issuance.
180
+ *
181
+ * Identification only: the stable key is `principalId`, and names and email
182
+ * are neither unique nor authorization.
183
+ */
184
+ export type CallerUser = {
185
+ displayName: string;
186
+ givenName?: string;
187
+ familyName?: string;
188
+ email?: string;
189
+ emailVerified: boolean;
190
+ /** Stable Trellis-hosted photo URL; a new photo gets a new URL. */
191
+ avatarUrl?: string;
175
192
  };
176
193
  /** Cryptographically authenticated request binding, before dispatch authorization. */
177
194
  export type VerifySessionRequestResult = {
package/caller.d.ts CHANGED
@@ -148,7 +148,7 @@ export type CallerRuntime<TContract extends GeneratedCaller> = CallerSelectedAct
148
148
  transfer: Trellis["transfer"];
149
149
  wait(): AsyncResult<void, BaseError>;
150
150
  };
151
- type OptionalCapability<TContract extends GeneratedCaller> = TContract["uses"][number]["optionalCapabilities"][number];
151
+ type OptionalCapability<TContract extends GeneratedCaller> = TContract["uses"][number]["optionalCapabilities"][number] | TContract["uses"][number]["actions"][number]["optionalCapabilities"][number];
152
152
  type OptionalResource<TContract extends GeneratedCaller> = {
153
153
  [Name in keyof CallerResources<TContract>]: CallerResources<TContract>[Name] extends {
154
154
  availability: "optional";
package/caller.js CHANGED
@@ -26,7 +26,13 @@ export function createCallerRuntime(session, contract, resources = {}) {
26
26
  runtime.connection.bindAuthorityAvailability(runtime.ownAuthority, (snapshot, installed) => {
27
27
  const capabilities = {};
28
28
  for (const selection of contract.uses) {
29
- for (const capability of selection.optionalCapabilities) {
29
+ // A requested group also reports each member that allows a selected
30
+ // action, so an app can gate on one member held without the group.
31
+ const keys = new Set([
32
+ ...selection.optionalCapabilities,
33
+ ...selection.actions.flatMap((action) => action.optionalCapabilities),
34
+ ]);
35
+ for (const capability of keys) {
30
36
  // An authority carries a group's members, not the group itself.
31
37
  capabilities[capability] =
32
38
  snapshot !== undefined &&
package/generated.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  /** Portable runtime support for generated Trellis packages. */
2
2
  export { TrellisError } from "./errors/TrellisError.ts";
3
- export { apiDescriptor, type AppRequestDescriptor, type Codec, codecs, type JsonValue, participantDescriptor, type SerializableErrorData, } from "./generated_support.ts";
3
+ export { apiDescriptor, type AppRequestDescriptor, type Codec, codecs, type DeclaredErrorOptions, type JsonValue, participantDescriptor, type SerializableErrorData, } from "./generated_support.ts";
4
4
  export type { ParticipantJobsFromResources, ParticipantKvFromResources, RuntimeApiFromGenerated, } from "./participant_runtime/participant.ts";
@@ -3,6 +3,14 @@ export type Codec<T> = Readonly<{
3
3
  decode(value: unknown): T;
4
4
  encode(value: T): unknown;
5
5
  }>;
6
+ /** Optional fields when constructing a generated declared error. */
7
+ export type DeclaredErrorOptions = ErrorOptions & {
8
+ /** Human-readable message; defaults to the declared error's name. */
9
+ message?: string;
10
+ context?: Record<string, unknown>;
11
+ id?: string;
12
+ traceId?: string;
13
+ };
6
14
  /** Serializable fields shared by generated declared errors. */
7
15
  export type SerializableErrorData = {
8
16
  id: string;
@@ -1,6 +1,6 @@
1
1
  // Generated by Trellis. Do not edit.
2
2
  import { TrellisError } from "@oatscenter/trellis/generated";
3
- import type { SerializableErrorData } from "@oatscenter/trellis/generated";
3
+ import type { DeclaredErrorOptions, SerializableErrorData } from "@oatscenter/trellis/generated";
4
4
  import * as Types0 from "../../types/_internal/p0.js";
5
5
  export type AuthErrorData = SerializableErrorData & {
6
6
  readonly type: "trellis.auth@v1::AuthError";
@@ -9,8 +9,9 @@ export declare class AuthError extends TrellisError<AuthErrorData> {
9
9
  static readonly type: "trellis.auth@v1::AuthError";
10
10
  static readonly payloadCodec: typeof Types0.AuthErrorDetailsCodec;
11
11
  override readonly name: "AuthError";
12
- readonly data: AuthErrorData;
13
- constructor(data: AuthErrorData);
12
+ readonly payload: Types0.AuthErrorDetails;
13
+ constructor(payload: Types0.AuthErrorDetails, options?: DeclaredErrorOptions);
14
+ get data(): AuthErrorData;
14
15
  static fromSerializable(data: unknown): AuthError;
15
16
  override toSerializable(): AuthErrorData;
16
17
  }
@@ -21,8 +22,9 @@ export declare class UnexpectedError extends TrellisError<UnexpectedErrorData> {
21
22
  static readonly type: "trellis.auth@v1::UnexpectedError";
22
23
  static readonly payloadCodec: typeof Types0.AuthErrorDetailsCodec;
23
24
  override readonly name: "UnexpectedError";
24
- readonly data: UnexpectedErrorData;
25
- constructor(data: UnexpectedErrorData);
25
+ readonly payload: Types0.AuthErrorDetails;
26
+ constructor(payload: Types0.AuthErrorDetails, options?: DeclaredErrorOptions);
27
+ get data(): UnexpectedErrorData;
26
28
  static fromSerializable(data: unknown): UnexpectedError;
27
29
  override toSerializable(): UnexpectedErrorData;
28
30
  }
@@ -33,8 +35,9 @@ export declare class ValidationError extends TrellisError<ValidationErrorData> {
33
35
  static readonly type: "trellis.auth@v1::ValidationError";
34
36
  static readonly payloadCodec: typeof Types0.AuthErrorDetailsCodec;
35
37
  override readonly name: "ValidationError";
36
- readonly data: ValidationErrorData;
37
- constructor(data: ValidationErrorData);
38
+ readonly payload: Types0.AuthErrorDetails;
39
+ constructor(payload: Types0.AuthErrorDetails, options?: DeclaredErrorOptions);
40
+ get data(): ValidationErrorData;
38
41
  static fromSerializable(data: unknown): ValidationError;
39
42
  override toSerializable(): ValidationErrorData;
40
43
  }