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

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/src/runtime.ts CHANGED
@@ -594,13 +594,12 @@ export function createProviderService(
594
594
  await provider.execute(
595
595
  request.operation,
596
596
  objectFromUnknown(request.params),
597
- providerRequest(
598
- request.token,
599
- request.connectionParams,
600
- request.context,
601
- request.invocationToken,
602
- request.idempotencyKey,
603
- ),
597
+ providerRequest(
598
+ request.token,
599
+ request.connectionParams,
600
+ request.context,
601
+ request.idempotencyKey,
602
+ ),
604
603
  ),
605
604
  );
606
605
  },
@@ -828,7 +827,6 @@ function providerRequest(
828
827
  token: string,
829
828
  connectionParams: Record<string, string>,
830
829
  requestContext?: ProtoRequestContext,
831
- invocationToken = "",
832
830
  idempotencyKey = "",
833
831
  ): Request {
834
832
  const credential = requestContext?.credential;
@@ -859,7 +857,6 @@ function providerRequest(
859
857
  host: {
860
858
  publicBaseUrl: host?.publicBaseUrl ?? "",
861
859
  },
862
- invocationToken,
863
860
  __requestContext: requestContext,
864
861
  idempotencyKey: idempotencyKey.trim(),
865
862
  };
@@ -13,7 +13,6 @@ 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";
17
16
  import type { Request, SubjectInput } from "./api.ts";
18
17
  import { jsonFromValue, structFromObject, type JsonObjectInput } from "./protocol.ts";
19
18
  import {
@@ -185,17 +184,13 @@ export interface Workflow {
185
184
  */
186
185
  class WorkflowImpl implements Workflow {
187
186
  private readonly client: Client<typeof WorkflowProviderService>;
188
- private readonly invocationContext: ReturnType<typeof hostInvocationContext>;
187
+ private readonly context: Request["__requestContext"];
189
188
  private readonly idempotencyKey: string;
190
189
 
191
190
  constructor(request: Request);
192
- constructor(invocationToken: string);
193
- constructor(requestOrToken: Request | string) {
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();
191
+ constructor(request: Request) {
192
+ this.context = request.__requestContext;
193
+ this.idempotencyKey = request.idempotencyKey.trim();
199
194
 
200
195
  const target = process.env[ENV_HOST_SERVICE_SOCKET]?.trim();
201
196
  if (!target) {
@@ -222,7 +217,7 @@ class WorkflowImpl implements Workflow {
222
217
  await this.client.applyDefinition({
223
218
  providerName: request.providerName,
224
219
  spec: workflowDefinitionSpecToProto(request.spec),
225
- ...this.invocationContext,
220
+ context: this.context,
226
221
  idempotencyKey: request.idempotencyKey?.trim() || this.idempotencyKey,
227
222
  requestedBySubjectId: request.requestedBySubjectId ?? "",
228
223
  }),
@@ -239,7 +234,7 @@ class WorkflowImpl implements Workflow {
239
234
  workflowDefinitionFromProto(
240
235
  await this.client.getDefinition({
241
236
  definitionId: request.definitionId,
242
- ...this.invocationContext,
237
+ context: this.context,
243
238
  }),
244
239
  ),
245
240
  "Workflow.getDefinition returned no definition",
@@ -251,7 +246,7 @@ class WorkflowImpl implements Workflow {
251
246
  _request: WorkflowListDefinitions = {},
252
247
  ): Promise<readonly WorkflowDefinition[]> {
253
248
  const response = await this.client.listDefinitions({
254
- ...this.invocationContext,
249
+ context: this.context,
255
250
  });
256
251
  return response.definitions.map((definition) =>
257
252
  requireDefinition(workflowDefinitionFromProto(definition), "Workflow.listDefinitions returned an empty definition")
@@ -267,7 +262,7 @@ class WorkflowImpl implements Workflow {
267
262
  await this.client.setDefinitionPaused({
268
263
  definitionId: request.definitionId,
269
264
  paused: request.paused,
270
- ...this.invocationContext,
265
+ context: this.context,
271
266
  requestedBySubjectId: request.requestedBySubjectId ?? "",
272
267
  }),
273
268
  ),
@@ -285,7 +280,7 @@ class WorkflowImpl implements Workflow {
285
280
  definitionId: request.definitionId,
286
281
  activationId: request.activationId,
287
282
  paused: request.paused,
288
- ...this.invocationContext,
283
+ context: this.context,
289
284
  requestedBySubjectId: request.requestedBySubjectId ?? "",
290
285
  }),
291
286
  ),
@@ -299,7 +294,7 @@ class WorkflowImpl implements Workflow {
299
294
  ): Promise<void> {
300
295
  await this.client.deleteDefinition({
301
296
  definitionId: request.definitionId,
302
- ...this.invocationContext,
297
+ context: this.context,
303
298
  });
304
299
  }
305
300
 
@@ -316,7 +311,7 @@ class WorkflowImpl implements Workflow {
316
311
  input: structFromObject(request.input),
317
312
  idempotencyKey: request.idempotencyKey?.trim() || this.idempotencyKey,
318
313
  workflowKey: request.workflowKey ?? "",
319
- ...this.invocationContext,
314
+ context: this.context,
320
315
  createdBySubjectId: request.createdBySubjectId ?? "",
321
316
  runAs: subjectToProto(request.runAs),
322
317
  }),
@@ -333,7 +328,7 @@ class WorkflowImpl implements Workflow {
333
328
  workflowRunFromProto(
334
329
  await this.client.getRun({
335
330
  runId: request.runId,
336
- ...this.invocationContext,
331
+ context: this.context,
337
332
  }),
338
333
  ),
339
334
  "Workflow.getRun returned no run",
@@ -349,7 +344,7 @@ class WorkflowImpl implements Workflow {
349
344
  pageToken: request.pageToken ?? "",
350
345
  status: request.status ?? 0,
351
346
  targetApp: request.targetApp ?? "",
352
- ...this.invocationContext,
347
+ context: this.context,
353
348
  });
354
349
  return {
355
350
  runs: response.runs.map((run) => requireRun(workflowRunFromProto(run), "Workflow.listRuns returned an empty run")),
@@ -363,7 +358,7 @@ class WorkflowImpl implements Workflow {
363
358
  ): Promise<readonly WorkflowRunEvent[]> {
364
359
  const response = await this.client.getRunEvents({
365
360
  runId: request.runId,
366
- ...this.invocationContext,
361
+ context: this.context,
367
362
  });
368
363
  return response.events.map((event) =>
369
364
  requireRunEvent(workflowRunEventFromProto(event), "Workflow.getRunEvents returned an empty event")
@@ -376,7 +371,7 @@ class WorkflowImpl implements Workflow {
376
371
  ): Promise<GetWorkflowProviderRunOutputResponse> {
377
372
  const response = await this.client.getRunOutput({
378
373
  runId: request.runId,
379
- ...this.invocationContext,
374
+ context: this.context,
380
375
  });
381
376
  return {
382
377
  output: response.output === undefined
@@ -394,7 +389,7 @@ class WorkflowImpl implements Workflow {
394
389
  await this.client.cancelRun({
395
390
  runId: request.runId,
396
391
  reason: request.reason ?? "",
397
- ...this.invocationContext,
392
+ context: this.context,
398
393
  }),
399
394
  ),
400
395
  "Workflow.cancelRun returned no run",
@@ -410,7 +405,7 @@ class WorkflowImpl implements Workflow {
410
405
  await this.client.signalRun({
411
406
  runId: request.runId,
412
407
  signal: workflowSignalToProto(request.signal),
413
- ...this.invocationContext,
408
+ context: this.context,
414
409
  }),
415
410
  ),
416
411
  "Workflow.signalRun returned no response",
@@ -431,7 +426,7 @@ class WorkflowImpl implements Workflow {
431
426
  input: structFromObject(request.input),
432
427
  idempotencyKey: request.idempotencyKey?.trim() || this.idempotencyKey,
433
428
  signal: workflowSignalToProto(request.signal),
434
- ...this.invocationContext,
429
+ context: this.context,
435
430
  createdBySubjectId: request.createdBySubjectId ?? "",
436
431
  runAs: subjectToProto(request.runAs),
437
432
  }),
@@ -450,7 +445,7 @@ class WorkflowImpl implements Workflow {
450
445
  appName: request.appName ?? "",
451
446
  event: workflowEventToProto(request.event),
452
447
  deliveredBySubjectId: request.deliveredBySubjectId ?? "",
453
- ...this.invocationContext,
448
+ context: this.context,
454
449
  providerName: request.providerName ?? "",
455
450
  }),
456
451
  ),
package/src/workflow.ts CHANGED
@@ -410,18 +410,15 @@ export interface ApplyWorkflowProviderDefinitionRequest {
410
410
  spec?: WorkflowDefinitionSpec | undefined;
411
411
  idempotencyKey?: string | undefined;
412
412
  requestedBySubjectId?: string | undefined;
413
- invocationToken?: string | undefined;
414
413
  context?: ProtoRequestContext | undefined;
415
414
  }
416
415
 
417
416
  export interface GetWorkflowProviderDefinitionRequest {
418
417
  definitionId: string;
419
- invocationToken?: string | undefined;
420
418
  context?: ProtoRequestContext | undefined;
421
419
  }
422
420
 
423
421
  export interface ListWorkflowProviderDefinitionsRequest {
424
- invocationToken?: string | undefined;
425
422
  context?: ProtoRequestContext | undefined;
426
423
  }
427
424
 
@@ -429,7 +426,6 @@ export interface SetWorkflowProviderDefinitionPausedRequest {
429
426
  definitionId: string;
430
427
  paused: boolean;
431
428
  requestedBySubjectId?: string | undefined;
432
- invocationToken?: string | undefined;
433
429
  context?: ProtoRequestContext | undefined;
434
430
  }
435
431
 
@@ -438,13 +434,11 @@ export interface SetWorkflowProviderActivationPausedRequest {
438
434
  activationId: string;
439
435
  paused: boolean;
440
436
  requestedBySubjectId?: string | undefined;
441
- invocationToken?: string | undefined;
442
437
  context?: ProtoRequestContext | undefined;
443
438
  }
444
439
 
445
440
  export interface DeleteWorkflowProviderDefinitionRequest {
446
441
  definitionId: string;
447
- invocationToken?: string | undefined;
448
442
  context?: ProtoRequestContext | undefined;
449
443
  }
450
444
 
@@ -456,13 +450,11 @@ export interface StartWorkflowProviderRunRequest {
456
450
  createdBySubjectId?: string | undefined;
457
451
  runAs?: SubjectInput | undefined;
458
452
  workflowKey?: string | undefined;
459
- invocationToken?: string | undefined;
460
453
  context?: ProtoRequestContext | undefined;
461
454
  }
462
455
 
463
456
  export interface GetWorkflowProviderRunRequest {
464
457
  runId: string;
465
- invocationToken?: string | undefined;
466
458
  context?: ProtoRequestContext | undefined;
467
459
  }
468
460
 
@@ -471,33 +463,28 @@ export interface ListWorkflowProviderRunsRequest {
471
463
  pageToken?: string | undefined;
472
464
  status?: WorkflowRunStatus | undefined;
473
465
  targetApp?: string | undefined;
474
- invocationToken?: string | undefined;
475
466
  context?: ProtoRequestContext | undefined;
476
467
  }
477
468
 
478
469
  export interface GetWorkflowProviderRunEventsRequest {
479
470
  runId: string;
480
- invocationToken?: string | undefined;
481
471
  context?: ProtoRequestContext | undefined;
482
472
  }
483
473
 
484
474
  export interface GetWorkflowProviderRunOutputRequest {
485
475
  runId: string;
486
- invocationToken?: string | undefined;
487
476
  context?: ProtoRequestContext | undefined;
488
477
  }
489
478
 
490
479
  export interface CancelWorkflowProviderRunRequest {
491
480
  runId: string;
492
481
  reason: string;
493
- invocationToken?: string | undefined;
494
482
  context?: ProtoRequestContext | undefined;
495
483
  }
496
484
 
497
485
  export interface SignalWorkflowProviderRunRequest {
498
486
  runId: string;
499
487
  signal?: WorkflowSignal | undefined;
500
- invocationToken?: string | undefined;
501
488
  context?: ProtoRequestContext | undefined;
502
489
  }
503
490
 
@@ -510,7 +497,6 @@ export interface SignalOrStartWorkflowProviderRunRequest {
510
497
  createdBySubjectId?: string | undefined;
511
498
  runAs?: SubjectInput | undefined;
512
499
  signal?: WorkflowSignal | undefined;
513
- invocationToken?: string | undefined;
514
500
  context?: ProtoRequestContext | undefined;
515
501
  }
516
502
 
@@ -525,7 +511,6 @@ export interface DeliverWorkflowProviderEventRequest {
525
511
  appName?: string | undefined;
526
512
  event?: WorkflowEvent | undefined;
527
513
  deliveredBySubjectId?: string | undefined;
528
- invocationToken?: string | undefined;
529
514
  context?: ProtoRequestContext | undefined;
530
515
  }
531
516
 
@@ -1608,29 +1593,28 @@ function applyWorkflowProviderDefinitionRequestFromProto(input: ProtoApplyWorkfl
1608
1593
  spec: workflowDefinitionSpecFromProto(input.spec),
1609
1594
  idempotencyKey: input.idempotencyKey,
1610
1595
  requestedBySubjectId: input.requestedBySubjectId,
1611
- invocationToken: input.invocationToken,
1612
1596
  context: input.context,
1613
1597
  };
1614
1598
  }
1615
1599
 
1616
1600
  function getWorkflowProviderDefinitionRequestFromProto(input: ProtoGetWorkflowProviderDefinitionRequest): GetWorkflowProviderDefinitionRequest {
1617
- return { definitionId: input.definitionId, invocationToken: input.invocationToken, context: input.context };
1601
+ return { definitionId: input.definitionId, context: input.context };
1618
1602
  }
1619
1603
 
1620
1604
  function listWorkflowProviderDefinitionsRequestFromProto(input: ProtoListWorkflowProviderDefinitionsRequest): ListWorkflowProviderDefinitionsRequest {
1621
- return { invocationToken: input.invocationToken, context: input.context };
1605
+ return { context: input.context };
1622
1606
  }
1623
1607
 
1624
1608
  function setWorkflowProviderDefinitionPausedRequestFromProto(input: ProtoSetWorkflowProviderDefinitionPausedRequest): SetWorkflowProviderDefinitionPausedRequest {
1625
- return { definitionId: input.definitionId, paused: input.paused, requestedBySubjectId: input.requestedBySubjectId, invocationToken: input.invocationToken, context: input.context };
1609
+ return { definitionId: input.definitionId, paused: input.paused, requestedBySubjectId: input.requestedBySubjectId, context: input.context };
1626
1610
  }
1627
1611
 
1628
1612
  function setWorkflowProviderActivationPausedRequestFromProto(input: ProtoSetWorkflowProviderActivationPausedRequest): SetWorkflowProviderActivationPausedRequest {
1629
- return { definitionId: input.definitionId, activationId: input.activationId, paused: input.paused, requestedBySubjectId: input.requestedBySubjectId, invocationToken: input.invocationToken, context: input.context };
1613
+ return { definitionId: input.definitionId, activationId: input.activationId, paused: input.paused, requestedBySubjectId: input.requestedBySubjectId, context: input.context };
1630
1614
  }
1631
1615
 
1632
1616
  function deleteWorkflowProviderDefinitionRequestFromProto(input: ProtoDeleteWorkflowProviderDefinitionRequest): DeleteWorkflowProviderDefinitionRequest {
1633
- return { definitionId: input.definitionId, invocationToken: input.invocationToken, context: input.context };
1617
+ return { definitionId: input.definitionId, context: input.context };
1634
1618
  }
1635
1619
 
1636
1620
  function startWorkflowProviderRunRequestFromProto(input: ProtoStartWorkflowProviderRunRequest): StartWorkflowProviderRunRequest {
@@ -1642,13 +1626,12 @@ function startWorkflowProviderRunRequestFromProto(input: ProtoStartWorkflowProvi
1642
1626
  createdBySubjectId: input.createdBySubjectId,
1643
1627
  runAs: subjectInputFromProto(input.runAs),
1644
1628
  workflowKey: input.workflowKey,
1645
- invocationToken: input.invocationToken,
1646
1629
  context: input.context,
1647
1630
  };
1648
1631
  }
1649
1632
 
1650
1633
  function getWorkflowProviderRunRequestFromProto(input: ProtoGetWorkflowProviderRunRequest): GetWorkflowProviderRunRequest {
1651
- return { runId: input.runId, invocationToken: input.invocationToken, context: input.context };
1634
+ return { runId: input.runId, context: input.context };
1652
1635
  }
1653
1636
 
1654
1637
  function listWorkflowProviderRunsRequestFromProto(input: ProtoListWorkflowProviderRunsRequest): ListWorkflowProviderRunsRequest {
@@ -1657,25 +1640,24 @@ function listWorkflowProviderRunsRequestFromProto(input: ProtoListWorkflowProvid
1657
1640
  pageToken: input.pageToken,
1658
1641
  status: input.status as WorkflowRunStatus,
1659
1642
  targetApp: input.targetApp,
1660
- invocationToken: input.invocationToken,
1661
1643
  context: input.context,
1662
1644
  };
1663
1645
  }
1664
1646
 
1665
1647
  function getWorkflowProviderRunEventsRequestFromProto(input: ProtoGetWorkflowProviderRunEventsRequest): GetWorkflowProviderRunEventsRequest {
1666
- return { runId: input.runId, invocationToken: input.invocationToken, context: input.context };
1648
+ return { runId: input.runId, context: input.context };
1667
1649
  }
1668
1650
 
1669
1651
  function getWorkflowProviderRunOutputRequestFromProto(input: ProtoGetWorkflowProviderRunOutputRequest): GetWorkflowProviderRunOutputRequest {
1670
- return { runId: input.runId, invocationToken: input.invocationToken, context: input.context };
1652
+ return { runId: input.runId, context: input.context };
1671
1653
  }
1672
1654
 
1673
1655
  function cancelWorkflowProviderRunRequestFromProto(input: ProtoCancelWorkflowProviderRunRequest): CancelWorkflowProviderRunRequest {
1674
- return { runId: input.runId, reason: input.reason, invocationToken: input.invocationToken, context: input.context };
1656
+ return { runId: input.runId, reason: input.reason, context: input.context };
1675
1657
  }
1676
1658
 
1677
1659
  function signalWorkflowProviderRunRequestFromProto(input: ProtoSignalWorkflowProviderRunRequest): SignalWorkflowProviderRunRequest {
1678
- return { runId: input.runId, signal: workflowSignalFromProto(input.signal), invocationToken: input.invocationToken, context: input.context };
1660
+ return { runId: input.runId, signal: workflowSignalFromProto(input.signal), context: input.context };
1679
1661
  }
1680
1662
 
1681
1663
  function signalOrStartWorkflowProviderRunRequestFromProto(input: ProtoSignalOrStartWorkflowProviderRunRequest): SignalOrStartWorkflowProviderRunRequest {
@@ -1688,7 +1670,6 @@ function signalOrStartWorkflowProviderRunRequestFromProto(input: ProtoSignalOrSt
1688
1670
  createdBySubjectId: input.createdBySubjectId,
1689
1671
  runAs: subjectInputFromProto(input.runAs),
1690
1672
  signal: workflowSignalFromProto(input.signal),
1691
- invocationToken: input.invocationToken,
1692
1673
  context: input.context,
1693
1674
  };
1694
1675
  }
@@ -1698,7 +1679,6 @@ function deliverWorkflowProviderEventRequestFromProto(input: ProtoDeliverWorkflo
1698
1679
  appName: input.appName,
1699
1680
  event: workflowEventFromProto(input.event),
1700
1681
  deliveredBySubjectId: input.deliveredBySubjectId,
1701
- invocationToken: input.invocationToken,
1702
1682
  context: input.context,
1703
1683
  };
1704
1684
  }
@@ -1722,7 +1702,6 @@ export interface WorkflowExecutionRequest {
1722
1702
  input?: Record<string, JsonInput> | undefined;
1723
1703
  metadata?: Record<string, JsonInput> | undefined;
1724
1704
  createdBySubjectId?: string | undefined;
1725
- invocationToken?: string | undefined;
1726
1705
  signals?: readonly WorkflowSignal[] | undefined;
1727
1706
  steps?: Record<string, { inputs?: Record<string, unknown>; outputs?: unknown }> | undefined;
1728
1707
  }
@@ -1,28 +0,0 @@
1
- import type { Request } from "./api.ts";
2
-
3
- export function hostInvocationContext(requestOrToken: Request | string) {
4
- const invocationToken = (
5
- typeof requestOrToken === "string"
6
- ? requestOrToken
7
- : requestOrToken.invocationToken
8
- ).trim();
9
- if (typeof requestOrToken === "string") {
10
- return { invocationToken, context: undefined };
11
- }
12
- const providerName =
13
- stringValue(requestOrToken.workflow.providerName) ||
14
- stringValue(requestOrToken.workflow.provider);
15
- const runId = stringValue(requestOrToken.workflow.runId);
16
- const workflow =
17
- providerName && runId
18
- ? { provider: providerName, providerName, runId }
19
- : undefined;
20
- return {
21
- invocationToken,
22
- ...(workflow === undefined ? {} : { workflow }),
23
- context: requestOrToken.__requestContext,
24
- };
25
- }
26
-
27
- const stringValue = (value: unknown) =>
28
- typeof value === "string" ? value.trim() : "";