@valon-technologies/gestalt 0.0.1-alpha.36 → 0.0.1-alpha.37

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.
@@ -13,6 +13,7 @@ import {
13
13
  ENV_HOST_SERVICE_SOCKET,
14
14
  ENV_HOST_SERVICE_TOKEN,
15
15
  } from "./host-service.ts";
16
+ import { hostInvocationContext } from "./invocation-context.ts";
16
17
  import type { Request, SubjectInput } from "./api.ts";
17
18
  import { jsonFromValue, structFromObject, type JsonObjectInput } from "./protocol.ts";
18
19
  import {
@@ -179,21 +180,22 @@ export interface Workflow {
179
180
  /**
180
181
  * Client for applying workflow definitions and controlling durable runs.
181
182
  *
182
- * The constructor accepts either a Gestalt request or an invocation token. Each
183
- * workflow call forwards that token to the workflow-provider facade. When
184
- * constructed from a request, mutating calls reuse the request idempotency key
185
- * unless the call provides one explicitly.
183
+ * Mutating calls reuse the request idempotency key unless the call provides one
184
+ * explicitly.
186
185
  */
187
186
  class WorkflowImpl implements Workflow {
188
187
  private readonly client: Client<typeof WorkflowProviderService>;
189
- private readonly invocationToken: string;
188
+ private readonly invocationContext: ReturnType<typeof hostInvocationContext>;
190
189
  private readonly idempotencyKey: string;
191
190
 
192
191
  constructor(request: Request);
193
192
  constructor(invocationToken: string);
194
193
  constructor(requestOrToken: Request | string) {
195
- this.invocationToken = normalizeInvocationToken(requestOrToken);
196
- this.idempotencyKey = normalizeIdempotencyKey(requestOrToken);
194
+ this.invocationContext = hostInvocationContext(requestOrToken);
195
+ if (typeof requestOrToken === "string" && !this.invocationContext.invocationToken) {
196
+ throw new Error("workflow: invocation token is not available");
197
+ }
198
+ this.idempotencyKey = typeof requestOrToken === "string" ? "" : requestOrToken.idempotencyKey.trim();
197
199
 
198
200
  const target = process.env[ENV_HOST_SERVICE_SOCKET]?.trim();
199
201
  if (!target) {
@@ -220,7 +222,7 @@ class WorkflowImpl implements Workflow {
220
222
  await this.client.applyDefinition({
221
223
  providerName: request.providerName,
222
224
  spec: workflowDefinitionSpecToProto(request.spec),
223
- invocationToken: this.invocationToken,
225
+ ...this.invocationContext,
224
226
  idempotencyKey: request.idempotencyKey?.trim() || this.idempotencyKey,
225
227
  requestedBySubjectId: request.requestedBySubjectId ?? "",
226
228
  }),
@@ -237,19 +239,19 @@ class WorkflowImpl implements Workflow {
237
239
  workflowDefinitionFromProto(
238
240
  await this.client.getDefinition({
239
241
  definitionId: request.definitionId,
240
- invocationToken: this.invocationToken,
242
+ ...this.invocationContext,
241
243
  }),
242
244
  ),
243
245
  "Workflow.getDefinition returned no definition",
244
246
  );
245
247
  }
246
248
 
247
- /** Lists workflow definitions visible to the current invocation token. */
249
+ /** Lists workflow definitions visible to the request context. */
248
250
  async listDefinitions(
249
251
  _request: WorkflowListDefinitions = {},
250
252
  ): Promise<readonly WorkflowDefinition[]> {
251
253
  const response = await this.client.listDefinitions({
252
- invocationToken: this.invocationToken,
254
+ ...this.invocationContext,
253
255
  });
254
256
  return response.definitions.map((definition) =>
255
257
  requireDefinition(workflowDefinitionFromProto(definition), "Workflow.listDefinitions returned an empty definition")
@@ -265,7 +267,7 @@ class WorkflowImpl implements Workflow {
265
267
  await this.client.setDefinitionPaused({
266
268
  definitionId: request.definitionId,
267
269
  paused: request.paused,
268
- invocationToken: this.invocationToken,
270
+ ...this.invocationContext,
269
271
  requestedBySubjectId: request.requestedBySubjectId ?? "",
270
272
  }),
271
273
  ),
@@ -283,7 +285,7 @@ class WorkflowImpl implements Workflow {
283
285
  definitionId: request.definitionId,
284
286
  activationId: request.activationId,
285
287
  paused: request.paused,
286
- invocationToken: this.invocationToken,
288
+ ...this.invocationContext,
287
289
  requestedBySubjectId: request.requestedBySubjectId ?? "",
288
290
  }),
289
291
  ),
@@ -297,7 +299,7 @@ class WorkflowImpl implements Workflow {
297
299
  ): Promise<void> {
298
300
  await this.client.deleteDefinition({
299
301
  definitionId: request.definitionId,
300
- invocationToken: this.invocationToken,
302
+ ...this.invocationContext,
301
303
  });
302
304
  }
303
305
 
@@ -314,7 +316,7 @@ class WorkflowImpl implements Workflow {
314
316
  input: structFromObject(request.input),
315
317
  idempotencyKey: request.idempotencyKey?.trim() || this.idempotencyKey,
316
318
  workflowKey: request.workflowKey ?? "",
317
- invocationToken: this.invocationToken,
319
+ ...this.invocationContext,
318
320
  createdBySubjectId: request.createdBySubjectId ?? "",
319
321
  runAs: subjectToProto(request.runAs),
320
322
  }),
@@ -331,14 +333,14 @@ class WorkflowImpl implements Workflow {
331
333
  workflowRunFromProto(
332
334
  await this.client.getRun({
333
335
  runId: request.runId,
334
- invocationToken: this.invocationToken,
336
+ ...this.invocationContext,
335
337
  }),
336
338
  ),
337
339
  "Workflow.getRun returned no run",
338
340
  );
339
341
  }
340
342
 
341
- /** Lists workflow runs visible to the current invocation token. */
343
+ /** Lists workflow runs visible to the request context. */
342
344
  async listRuns(
343
345
  request: WorkflowListRuns = {},
344
346
  ): Promise<{ runs: readonly WorkflowRun[]; nextPageToken?: string | undefined }> {
@@ -347,7 +349,7 @@ class WorkflowImpl implements Workflow {
347
349
  pageToken: request.pageToken ?? "",
348
350
  status: request.status ?? 0,
349
351
  targetApp: request.targetApp ?? "",
350
- invocationToken: this.invocationToken,
352
+ ...this.invocationContext,
351
353
  });
352
354
  return {
353
355
  runs: response.runs.map((run) => requireRun(workflowRunFromProto(run), "Workflow.listRuns returned an empty run")),
@@ -361,7 +363,7 @@ class WorkflowImpl implements Workflow {
361
363
  ): Promise<readonly WorkflowRunEvent[]> {
362
364
  const response = await this.client.getRunEvents({
363
365
  runId: request.runId,
364
- invocationToken: this.invocationToken,
366
+ ...this.invocationContext,
365
367
  });
366
368
  return response.events.map((event) =>
367
369
  requireRunEvent(workflowRunEventFromProto(event), "Workflow.getRunEvents returned an empty event")
@@ -374,7 +376,7 @@ class WorkflowImpl implements Workflow {
374
376
  ): Promise<GetWorkflowProviderRunOutputResponse> {
375
377
  const response = await this.client.getRunOutput({
376
378
  runId: request.runId,
377
- invocationToken: this.invocationToken,
379
+ ...this.invocationContext,
378
380
  });
379
381
  return {
380
382
  output: response.output === undefined
@@ -392,7 +394,7 @@ class WorkflowImpl implements Workflow {
392
394
  await this.client.cancelRun({
393
395
  runId: request.runId,
394
396
  reason: request.reason ?? "",
395
- invocationToken: this.invocationToken,
397
+ ...this.invocationContext,
396
398
  }),
397
399
  ),
398
400
  "Workflow.cancelRun returned no run",
@@ -408,7 +410,7 @@ class WorkflowImpl implements Workflow {
408
410
  await this.client.signalRun({
409
411
  runId: request.runId,
410
412
  signal: workflowSignalToProto(request.signal),
411
- invocationToken: this.invocationToken,
413
+ ...this.invocationContext,
412
414
  }),
413
415
  ),
414
416
  "Workflow.signalRun returned no response",
@@ -429,7 +431,7 @@ class WorkflowImpl implements Workflow {
429
431
  input: structFromObject(request.input),
430
432
  idempotencyKey: request.idempotencyKey?.trim() || this.idempotencyKey,
431
433
  signal: workflowSignalToProto(request.signal),
432
- invocationToken: this.invocationToken,
434
+ ...this.invocationContext,
433
435
  createdBySubjectId: request.createdBySubjectId ?? "",
434
436
  runAs: subjectToProto(request.runAs),
435
437
  }),
@@ -448,7 +450,7 @@ class WorkflowImpl implements Workflow {
448
450
  appName: request.appName ?? "",
449
451
  event: workflowEventToProto(request.event),
450
452
  deliveredBySubjectId: request.deliveredBySubjectId ?? "",
451
- invocationToken: this.invocationToken,
453
+ ...this.invocationContext,
452
454
  providerName: request.providerName ?? "",
453
455
  }),
454
456
  ),
@@ -459,25 +461,6 @@ class WorkflowImpl implements Workflow {
459
461
 
460
462
  export const Workflow = WorkflowImpl;
461
463
 
462
- function normalizeInvocationToken(requestOrToken: Request | string): string {
463
- const invocationToken =
464
- typeof requestOrToken === "string"
465
- ? requestOrToken
466
- : requestOrToken.invocationToken;
467
- const trimmed = invocationToken.trim();
468
- if (!trimmed) {
469
- throw new Error("workflow: invocation token is not available");
470
- }
471
- return trimmed;
472
- }
473
-
474
- function normalizeIdempotencyKey(requestOrToken: Request | string): string {
475
- if (typeof requestOrToken === "string") {
476
- return "";
477
- }
478
- return requestOrToken.idempotencyKey.trim();
479
- }
480
-
481
464
  function generationToBigInt(value: bigint | number | undefined): bigint {
482
465
  if (value === undefined) {
483
466
  return 0n;
package/src/workflow.ts CHANGED
@@ -18,9 +18,16 @@ import {
18
18
  type Request,
19
19
  type Subject,
20
20
  type SubjectInput,
21
+ type SubjectPermission,
21
22
  errorMessage,
22
23
  } from "./api.ts";
23
- import { SubjectContextSchema, type SubjectContext } from "./internal/gen/v1/app_pb.ts";
24
+ import {
25
+ SubjectContextSchema,
26
+ SubjectPermissionContextSchema,
27
+ type RequestContext as ProtoRequestContext,
28
+ type SubjectContext,
29
+ type SubjectPermissionContext,
30
+ } from "./internal/gen/v1/app_pb.ts";
24
31
  import {
25
32
  ApplyWorkflowProviderDefinitionRequestSchema,
26
33
  BoundWorkflowTargetSchema,
@@ -65,6 +72,7 @@ import {
65
72
  type ApplyWorkflowProviderDefinitionRequest as ProtoApplyWorkflowProviderDefinitionRequest,
66
73
  type BoundWorkflowTarget as ProtoBoundWorkflowTarget,
67
74
  type CancelWorkflowProviderRunRequest as ProtoCancelWorkflowProviderRunRequest,
75
+ type DeleteWorkflowProviderDefinitionRequest as ProtoDeleteWorkflowProviderDefinitionRequest,
68
76
  type DeliverWorkflowProviderEventRequest as ProtoDeliverWorkflowProviderEventRequest,
69
77
  type GetWorkflowProviderDefinitionRequest as ProtoGetWorkflowProviderDefinitionRequest,
70
78
  type GetWorkflowProviderRunEventsRequest as ProtoGetWorkflowProviderRunEventsRequest,
@@ -402,18 +410,27 @@ export interface ApplyWorkflowProviderDefinitionRequest {
402
410
  spec?: WorkflowDefinitionSpec | undefined;
403
411
  idempotencyKey?: string | undefined;
404
412
  requestedBySubjectId?: string | undefined;
413
+ invocationToken?: string | undefined;
414
+ context?: ProtoRequestContext | undefined;
405
415
  }
406
416
 
407
417
  export interface GetWorkflowProviderDefinitionRequest {
408
418
  definitionId: string;
419
+ invocationToken?: string | undefined;
420
+ context?: ProtoRequestContext | undefined;
409
421
  }
410
422
 
411
- export interface ListWorkflowProviderDefinitionsRequest {}
423
+ export interface ListWorkflowProviderDefinitionsRequest {
424
+ invocationToken?: string | undefined;
425
+ context?: ProtoRequestContext | undefined;
426
+ }
412
427
 
413
428
  export interface SetWorkflowProviderDefinitionPausedRequest {
414
429
  definitionId: string;
415
430
  paused: boolean;
416
431
  requestedBySubjectId?: string | undefined;
432
+ invocationToken?: string | undefined;
433
+ context?: ProtoRequestContext | undefined;
417
434
  }
418
435
 
419
436
  export interface SetWorkflowProviderActivationPausedRequest {
@@ -421,10 +438,14 @@ export interface SetWorkflowProviderActivationPausedRequest {
421
438
  activationId: string;
422
439
  paused: boolean;
423
440
  requestedBySubjectId?: string | undefined;
441
+ invocationToken?: string | undefined;
442
+ context?: ProtoRequestContext | undefined;
424
443
  }
425
444
 
426
445
  export interface DeleteWorkflowProviderDefinitionRequest {
427
446
  definitionId: string;
447
+ invocationToken?: string | undefined;
448
+ context?: ProtoRequestContext | undefined;
428
449
  }
429
450
 
430
451
  export interface StartWorkflowProviderRunRequest {
@@ -435,10 +456,14 @@ export interface StartWorkflowProviderRunRequest {
435
456
  createdBySubjectId?: string | undefined;
436
457
  runAs?: SubjectInput | undefined;
437
458
  workflowKey?: string | undefined;
459
+ invocationToken?: string | undefined;
460
+ context?: ProtoRequestContext | undefined;
438
461
  }
439
462
 
440
463
  export interface GetWorkflowProviderRunRequest {
441
464
  runId: string;
465
+ invocationToken?: string | undefined;
466
+ context?: ProtoRequestContext | undefined;
442
467
  }
443
468
 
444
469
  export interface ListWorkflowProviderRunsRequest {
@@ -446,24 +471,34 @@ export interface ListWorkflowProviderRunsRequest {
446
471
  pageToken?: string | undefined;
447
472
  status?: WorkflowRunStatus | undefined;
448
473
  targetApp?: string | undefined;
474
+ invocationToken?: string | undefined;
475
+ context?: ProtoRequestContext | undefined;
449
476
  }
450
477
 
451
478
  export interface GetWorkflowProviderRunEventsRequest {
452
479
  runId: string;
480
+ invocationToken?: string | undefined;
481
+ context?: ProtoRequestContext | undefined;
453
482
  }
454
483
 
455
484
  export interface GetWorkflowProviderRunOutputRequest {
456
485
  runId: string;
486
+ invocationToken?: string | undefined;
487
+ context?: ProtoRequestContext | undefined;
457
488
  }
458
489
 
459
490
  export interface CancelWorkflowProviderRunRequest {
460
491
  runId: string;
461
492
  reason: string;
493
+ invocationToken?: string | undefined;
494
+ context?: ProtoRequestContext | undefined;
462
495
  }
463
496
 
464
497
  export interface SignalWorkflowProviderRunRequest {
465
498
  runId: string;
466
499
  signal?: WorkflowSignal | undefined;
500
+ invocationToken?: string | undefined;
501
+ context?: ProtoRequestContext | undefined;
467
502
  }
468
503
 
469
504
  export interface SignalOrStartWorkflowProviderRunRequest {
@@ -475,6 +510,8 @@ export interface SignalOrStartWorkflowProviderRunRequest {
475
510
  createdBySubjectId?: string | undefined;
476
511
  runAs?: SubjectInput | undefined;
477
512
  signal?: WorkflowSignal | undefined;
513
+ invocationToken?: string | undefined;
514
+ context?: ProtoRequestContext | undefined;
478
515
  }
479
516
 
480
517
  export interface SignalWorkflowRunResponse {
@@ -488,6 +525,8 @@ export interface DeliverWorkflowProviderEventRequest {
488
525
  appName?: string | undefined;
489
526
  event?: WorkflowEvent | undefined;
490
527
  deliveredBySubjectId?: string | undefined;
528
+ invocationToken?: string | undefined;
529
+ context?: ProtoRequestContext | undefined;
491
530
  }
492
531
 
493
532
  export function workflowText(input: WorkflowText | string = {}): WorkflowText {
@@ -910,8 +949,7 @@ export function createWorkflowProviderService(provider: WorkflowProvider): Workf
910
949
  ));
911
950
  },
912
951
  async listDefinitions(request) {
913
- const result = listDefinitionsResult(await invokeWorkflowProvider("list definitions", () => provider.listDefinitions({})));
914
- void request;
952
+ const result = listDefinitionsResult(await invokeWorkflowProvider("list definitions", () => provider.listDefinitions(listWorkflowProviderDefinitionsRequestFromProto(request))));
915
953
  return create(ListWorkflowProviderDefinitionsResponseSchema, {
916
954
  definitions: result.definitions.map(workflowDefinitionToProto),
917
955
  });
@@ -1570,23 +1608,29 @@ function applyWorkflowProviderDefinitionRequestFromProto(input: ProtoApplyWorkfl
1570
1608
  spec: workflowDefinitionSpecFromProto(input.spec),
1571
1609
  idempotencyKey: input.idempotencyKey,
1572
1610
  requestedBySubjectId: input.requestedBySubjectId,
1611
+ invocationToken: input.invocationToken,
1612
+ context: input.context,
1573
1613
  };
1574
1614
  }
1575
1615
 
1576
1616
  function getWorkflowProviderDefinitionRequestFromProto(input: ProtoGetWorkflowProviderDefinitionRequest): GetWorkflowProviderDefinitionRequest {
1577
- return { definitionId: input.definitionId };
1617
+ return { definitionId: input.definitionId, invocationToken: input.invocationToken, context: input.context };
1618
+ }
1619
+
1620
+ function listWorkflowProviderDefinitionsRequestFromProto(input: ProtoListWorkflowProviderDefinitionsRequest): ListWorkflowProviderDefinitionsRequest {
1621
+ return { invocationToken: input.invocationToken, context: input.context };
1578
1622
  }
1579
1623
 
1580
1624
  function setWorkflowProviderDefinitionPausedRequestFromProto(input: ProtoSetWorkflowProviderDefinitionPausedRequest): SetWorkflowProviderDefinitionPausedRequest {
1581
- return { definitionId: input.definitionId, paused: input.paused, requestedBySubjectId: input.requestedBySubjectId };
1625
+ return { definitionId: input.definitionId, paused: input.paused, requestedBySubjectId: input.requestedBySubjectId, invocationToken: input.invocationToken, context: input.context };
1582
1626
  }
1583
1627
 
1584
1628
  function setWorkflowProviderActivationPausedRequestFromProto(input: ProtoSetWorkflowProviderActivationPausedRequest): SetWorkflowProviderActivationPausedRequest {
1585
- return { definitionId: input.definitionId, activationId: input.activationId, paused: input.paused, requestedBySubjectId: input.requestedBySubjectId };
1629
+ return { definitionId: input.definitionId, activationId: input.activationId, paused: input.paused, requestedBySubjectId: input.requestedBySubjectId, invocationToken: input.invocationToken, context: input.context };
1586
1630
  }
1587
1631
 
1588
- function deleteWorkflowProviderDefinitionRequestFromProto(input: { definitionId: string }): DeleteWorkflowProviderDefinitionRequest {
1589
- return { definitionId: input.definitionId };
1632
+ function deleteWorkflowProviderDefinitionRequestFromProto(input: ProtoDeleteWorkflowProviderDefinitionRequest): DeleteWorkflowProviderDefinitionRequest {
1633
+ return { definitionId: input.definitionId, invocationToken: input.invocationToken, context: input.context };
1590
1634
  }
1591
1635
 
1592
1636
  function startWorkflowProviderRunRequestFromProto(input: ProtoStartWorkflowProviderRunRequest): StartWorkflowProviderRunRequest {
@@ -1598,11 +1642,13 @@ function startWorkflowProviderRunRequestFromProto(input: ProtoStartWorkflowProvi
1598
1642
  createdBySubjectId: input.createdBySubjectId,
1599
1643
  runAs: subjectInputFromProto(input.runAs),
1600
1644
  workflowKey: input.workflowKey,
1645
+ invocationToken: input.invocationToken,
1646
+ context: input.context,
1601
1647
  };
1602
1648
  }
1603
1649
 
1604
1650
  function getWorkflowProviderRunRequestFromProto(input: ProtoGetWorkflowProviderRunRequest): GetWorkflowProviderRunRequest {
1605
- return { runId: input.runId };
1651
+ return { runId: input.runId, invocationToken: input.invocationToken, context: input.context };
1606
1652
  }
1607
1653
 
1608
1654
  function listWorkflowProviderRunsRequestFromProto(input: ProtoListWorkflowProviderRunsRequest): ListWorkflowProviderRunsRequest {
@@ -1611,23 +1657,25 @@ function listWorkflowProviderRunsRequestFromProto(input: ProtoListWorkflowProvid
1611
1657
  pageToken: input.pageToken,
1612
1658
  status: input.status as WorkflowRunStatus,
1613
1659
  targetApp: input.targetApp,
1660
+ invocationToken: input.invocationToken,
1661
+ context: input.context,
1614
1662
  };
1615
1663
  }
1616
1664
 
1617
1665
  function getWorkflowProviderRunEventsRequestFromProto(input: ProtoGetWorkflowProviderRunEventsRequest): GetWorkflowProviderRunEventsRequest {
1618
- return { runId: input.runId };
1666
+ return { runId: input.runId, invocationToken: input.invocationToken, context: input.context };
1619
1667
  }
1620
1668
 
1621
1669
  function getWorkflowProviderRunOutputRequestFromProto(input: ProtoGetWorkflowProviderRunOutputRequest): GetWorkflowProviderRunOutputRequest {
1622
- return { runId: input.runId };
1670
+ return { runId: input.runId, invocationToken: input.invocationToken, context: input.context };
1623
1671
  }
1624
1672
 
1625
1673
  function cancelWorkflowProviderRunRequestFromProto(input: ProtoCancelWorkflowProviderRunRequest): CancelWorkflowProviderRunRequest {
1626
- return { runId: input.runId, reason: input.reason };
1674
+ return { runId: input.runId, reason: input.reason, invocationToken: input.invocationToken, context: input.context };
1627
1675
  }
1628
1676
 
1629
1677
  function signalWorkflowProviderRunRequestFromProto(input: ProtoSignalWorkflowProviderRunRequest): SignalWorkflowProviderRunRequest {
1630
- return { runId: input.runId, signal: workflowSignalFromProto(input.signal) };
1678
+ return { runId: input.runId, signal: workflowSignalFromProto(input.signal), invocationToken: input.invocationToken, context: input.context };
1631
1679
  }
1632
1680
 
1633
1681
  function signalOrStartWorkflowProviderRunRequestFromProto(input: ProtoSignalOrStartWorkflowProviderRunRequest): SignalOrStartWorkflowProviderRunRequest {
@@ -1640,6 +1688,8 @@ function signalOrStartWorkflowProviderRunRequestFromProto(input: ProtoSignalOrSt
1640
1688
  createdBySubjectId: input.createdBySubjectId,
1641
1689
  runAs: subjectInputFromProto(input.runAs),
1642
1690
  signal: workflowSignalFromProto(input.signal),
1691
+ invocationToken: input.invocationToken,
1692
+ context: input.context,
1643
1693
  };
1644
1694
  }
1645
1695
 
@@ -1648,6 +1698,8 @@ function deliverWorkflowProviderEventRequestFromProto(input: ProtoDeliverWorkflo
1648
1698
  appName: input.appName,
1649
1699
  event: workflowEventFromProto(input.event),
1650
1700
  deliveredBySubjectId: input.deliveredBySubjectId,
1701
+ invocationToken: input.invocationToken,
1702
+ context: input.context,
1651
1703
  };
1652
1704
  }
1653
1705
 
@@ -1844,6 +1896,9 @@ export function subjectToProto(input?: SubjectInput | Subject): SubjectContext |
1844
1896
  id: input.id ?? "",
1845
1897
  credentialSubjectId: input.credentialSubjectId ?? "",
1846
1898
  email: input.email ?? "",
1899
+ displayName: input.displayName ?? "",
1900
+ scopes: [...(input.scopes ?? [])],
1901
+ permissions: subjectPermissionsToProto(input.permissions),
1847
1902
  });
1848
1903
  }
1849
1904
 
@@ -1853,6 +1908,9 @@ export function subjectFromProto(input?: SubjectContext): Subject | undefined {
1853
1908
  id: input.id,
1854
1909
  credentialSubjectId: input.credentialSubjectId,
1855
1910
  email: input.email,
1911
+ displayName: input.displayName,
1912
+ scopes: [...input.scopes],
1913
+ permissions: subjectPermissionsFromProto(input.permissions),
1856
1914
  };
1857
1915
  }
1858
1916
 
@@ -1862,9 +1920,31 @@ export function subjectInputFromProto(input?: SubjectContext): SubjectInput | un
1862
1920
  id: input.id,
1863
1921
  credentialSubjectId: input.credentialSubjectId,
1864
1922
  email: input.email,
1923
+ displayName: input.displayName,
1924
+ scopes: [...input.scopes],
1925
+ permissions: subjectPermissionsFromProto(input.permissions),
1865
1926
  };
1866
1927
  }
1867
1928
 
1929
+ function subjectPermissionsFromProto(
1930
+ permissions: readonly SubjectPermissionContext[],
1931
+ ): SubjectPermission[] {
1932
+ return permissions.map((permission) => ({
1933
+ app: permission.app,
1934
+ operations: permission.allOperations ? [] : [...permission.operations],
1935
+ }));
1936
+ }
1937
+
1938
+ function subjectPermissionsToProto(
1939
+ permissions?: readonly SubjectPermission[] | undefined,
1940
+ ): SubjectPermissionContext[] {
1941
+ return permissions?.map((permission) => create(SubjectPermissionContextSchema, {
1942
+ app: permission.app,
1943
+ operations: [...permission.operations],
1944
+ allOperations: permission.operations.length === 0,
1945
+ })) ?? [];
1946
+ }
1947
+
1868
1948
  function listDefinitionsResult(value: readonly WorkflowDefinition[] | ListWorkflowProviderDefinitionsResponse): ListWorkflowProviderDefinitionsResponse {
1869
1949
  return "definitions" in value ? value : { definitions: value };
1870
1950
  }