@valon-technologies/gestalt 0.0.1-alpha.10 → 0.0.1-alpha.12
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/gen/v1/plugin_pb.ts +231 -13
- package/gen/v1/workflow_pb.ts +274 -7
- package/package.json +1 -1
- package/src/authorization.ts +138 -0
- package/src/cache.ts +69 -9
- package/src/http-subject.ts +113 -0
- package/src/index.ts +55 -0
- package/src/indexeddb.ts +59 -6
- package/src/invoker.ts +87 -9
- package/src/manifest-metadata.ts +106 -0
- package/src/plugin.ts +202 -0
- package/src/runtime.ts +94 -3
- package/src/s3.ts +11 -4
- package/src/workflow-manager.ts +95 -0
package/src/plugin.ts
CHANGED
|
@@ -7,6 +7,15 @@ import {
|
|
|
7
7
|
schemaToParameters,
|
|
8
8
|
writeCatalogYaml,
|
|
9
9
|
} from "./catalog.ts";
|
|
10
|
+
import {
|
|
11
|
+
type HTTPAck,
|
|
12
|
+
type HTTPBinding,
|
|
13
|
+
type HTTPRequestBody,
|
|
14
|
+
type HTTPSecurityScheme,
|
|
15
|
+
type PluginManifestMetadata,
|
|
16
|
+
hasPluginManifestMetadata,
|
|
17
|
+
writeManifestMetadataYaml,
|
|
18
|
+
} from "./manifest-metadata.ts";
|
|
10
19
|
import {
|
|
11
20
|
errorMessage,
|
|
12
21
|
type MaybePromise,
|
|
@@ -14,7 +23,15 @@ import {
|
|
|
14
23
|
type Request,
|
|
15
24
|
responseBrand,
|
|
16
25
|
type Response,
|
|
26
|
+
type Subject,
|
|
17
27
|
} from "./api.ts";
|
|
28
|
+
import {
|
|
29
|
+
cloneHTTPSubjectRequest,
|
|
30
|
+
cloneHTTPSubjectResolutionContext,
|
|
31
|
+
type HTTPSubjectRequest,
|
|
32
|
+
type HTTPSubjectResolutionContext,
|
|
33
|
+
type HTTPSubjectResolver,
|
|
34
|
+
} from "./http-subject.ts";
|
|
18
35
|
import { RuntimeProvider, type RuntimeProviderOptions } from "./provider.ts";
|
|
19
36
|
import type { Schema } from "./schema.ts";
|
|
20
37
|
|
|
@@ -82,6 +99,9 @@ export interface PluginDefinitionOptions extends RuntimeProviderOptions {
|
|
|
82
99
|
connectionMode?: ConnectionMode;
|
|
83
100
|
authTypes?: string[];
|
|
84
101
|
connectionParams?: Record<string, ConnectionParamDefinition>;
|
|
102
|
+
securitySchemes?: Record<string, HTTPSecurityScheme>;
|
|
103
|
+
http?: Record<string, HTTPBinding>;
|
|
104
|
+
resolveHTTPSubject?: HTTPSubjectResolver;
|
|
85
105
|
iconSvg?: string;
|
|
86
106
|
operations: Array<OperationDefinition<any, any>>;
|
|
87
107
|
sessionCatalog?: SessionCatalogHandler;
|
|
@@ -134,8 +154,11 @@ export class PluginProvider extends RuntimeProvider {
|
|
|
134
154
|
readonly connectionMode: ConnectionMode;
|
|
135
155
|
readonly authTypes: string[];
|
|
136
156
|
readonly connectionParams: Record<string, ConnectionParamDefinition>;
|
|
157
|
+
readonly securitySchemes: Record<string, HTTPSecurityScheme>;
|
|
158
|
+
readonly http: Record<string, HTTPBinding>;
|
|
137
159
|
|
|
138
160
|
private readonly sessionCatalogHandler: SessionCatalogHandler | undefined;
|
|
161
|
+
private readonly httpSubjectResolver: HTTPSubjectResolver | undefined;
|
|
139
162
|
private readonly operations = new Map<string, OperationDefinition<any, any>>();
|
|
140
163
|
|
|
141
164
|
constructor(options: PluginDefinitionOptions) {
|
|
@@ -144,6 +167,9 @@ export class PluginProvider extends RuntimeProvider {
|
|
|
144
167
|
this.connectionMode = options.connectionMode ?? "unspecified";
|
|
145
168
|
this.authTypes = [...(options.authTypes ?? [])];
|
|
146
169
|
this.connectionParams = normalizeConnectionParams(options.connectionParams);
|
|
170
|
+
this.securitySchemes = normalizeHTTPSecuritySchemes(options.securitySchemes);
|
|
171
|
+
this.http = normalizeHTTPBindings(options.http);
|
|
172
|
+
this.httpSubjectResolver = options.resolveHTTPSubject;
|
|
147
173
|
this.sessionCatalogHandler = options.sessionCatalog;
|
|
148
174
|
|
|
149
175
|
for (const rawEntry of options.operations) {
|
|
@@ -174,6 +200,20 @@ export class PluginProvider extends RuntimeProvider {
|
|
|
174
200
|
return await this.sessionCatalogHandler?.(request);
|
|
175
201
|
}
|
|
176
202
|
|
|
203
|
+
/**
|
|
204
|
+
* Resolves the concrete Gestalt subject for a verified hosted HTTP request,
|
|
205
|
+
* if the plugin opts into subject resolution.
|
|
206
|
+
*/
|
|
207
|
+
async resolveHTTPSubject(
|
|
208
|
+
request: HTTPSubjectRequest,
|
|
209
|
+
context: HTTPSubjectResolutionContext,
|
|
210
|
+
): Promise<Subject | null | undefined> {
|
|
211
|
+
return await this.httpSubjectResolver?.(
|
|
212
|
+
cloneHTTPSubjectRequest(request),
|
|
213
|
+
cloneHTTPSubjectResolutionContext(context),
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
|
|
177
217
|
/**
|
|
178
218
|
* Returns the static catalog emitted during provider startup.
|
|
179
219
|
*/
|
|
@@ -255,6 +295,38 @@ export class PluginProvider extends RuntimeProvider {
|
|
|
255
295
|
return catalogToJson(this.staticCatalog());
|
|
256
296
|
}
|
|
257
297
|
|
|
298
|
+
/**
|
|
299
|
+
* Returns generated manifest-backed HTTP/security metadata for the provider.
|
|
300
|
+
*/
|
|
301
|
+
staticManifestMetadata(): PluginManifestMetadata {
|
|
302
|
+
const metadata: PluginManifestMetadata = {};
|
|
303
|
+
if (Object.keys(this.securitySchemes).length > 0) {
|
|
304
|
+
metadata.securitySchemes = cloneHTTPSecuritySchemes(this.securitySchemes);
|
|
305
|
+
}
|
|
306
|
+
if (Object.keys(this.http).length > 0) {
|
|
307
|
+
metadata.http = cloneHTTPBindings(this.http);
|
|
308
|
+
}
|
|
309
|
+
return metadata;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Reports whether the provider emits manifest metadata in addition to catalog metadata.
|
|
314
|
+
*/
|
|
315
|
+
supportsManifestMetadata(): boolean {
|
|
316
|
+
return hasPluginManifestMetadata(this.staticManifestMetadata());
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Writes generated manifest metadata to disk as YAML.
|
|
321
|
+
*/
|
|
322
|
+
writeManifestMetadata(path: string): void {
|
|
323
|
+
const metadata = this.staticManifestMetadata();
|
|
324
|
+
if (!hasPluginManifestMetadata(metadata)) {
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
writeManifestMetadataYaml(path, metadata);
|
|
328
|
+
}
|
|
329
|
+
|
|
258
330
|
/**
|
|
259
331
|
* Executes an operation against validated input and request metadata.
|
|
260
332
|
*/
|
|
@@ -349,6 +421,136 @@ function normalizeConnectionParams(
|
|
|
349
421
|
return output;
|
|
350
422
|
}
|
|
351
423
|
|
|
424
|
+
function normalizeHTTPSecuritySchemes(
|
|
425
|
+
input: Record<string, HTTPSecurityScheme> | undefined,
|
|
426
|
+
): Record<string, HTTPSecurityScheme> {
|
|
427
|
+
const output: Record<string, HTTPSecurityScheme> = {};
|
|
428
|
+
for (const [key, value] of Object.entries(input ?? {})) {
|
|
429
|
+
output[key] = cloneHTTPSecurityScheme(value);
|
|
430
|
+
}
|
|
431
|
+
return output;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
function cloneHTTPSecuritySchemes(
|
|
435
|
+
input: Record<string, HTTPSecurityScheme>,
|
|
436
|
+
): Record<string, HTTPSecurityScheme> {
|
|
437
|
+
const output: Record<string, HTTPSecurityScheme> = {};
|
|
438
|
+
for (const [key, value] of Object.entries(input)) {
|
|
439
|
+
output[key] = cloneHTTPSecurityScheme(value);
|
|
440
|
+
}
|
|
441
|
+
return output;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
function cloneHTTPSecurityScheme(value: HTTPSecurityScheme): HTTPSecurityScheme {
|
|
445
|
+
const output: HTTPSecurityScheme = {};
|
|
446
|
+
if (value.type !== undefined) {
|
|
447
|
+
output.type = value.type;
|
|
448
|
+
}
|
|
449
|
+
if (value.description !== undefined) {
|
|
450
|
+
output.description = value.description;
|
|
451
|
+
}
|
|
452
|
+
if (value.signatureHeader !== undefined) {
|
|
453
|
+
output.signatureHeader = value.signatureHeader;
|
|
454
|
+
}
|
|
455
|
+
if (value.signaturePrefix !== undefined) {
|
|
456
|
+
output.signaturePrefix = value.signaturePrefix;
|
|
457
|
+
}
|
|
458
|
+
if (value.payloadTemplate !== undefined) {
|
|
459
|
+
output.payloadTemplate = value.payloadTemplate;
|
|
460
|
+
}
|
|
461
|
+
if (value.timestampHeader !== undefined) {
|
|
462
|
+
output.timestampHeader = value.timestampHeader;
|
|
463
|
+
}
|
|
464
|
+
if (value.maxAgeSeconds !== undefined) {
|
|
465
|
+
output.maxAgeSeconds = value.maxAgeSeconds;
|
|
466
|
+
}
|
|
467
|
+
if (value.name !== undefined) {
|
|
468
|
+
output.name = value.name;
|
|
469
|
+
}
|
|
470
|
+
if (value.in !== undefined) {
|
|
471
|
+
output.in = value.in;
|
|
472
|
+
}
|
|
473
|
+
if (value.scheme !== undefined) {
|
|
474
|
+
output.scheme = value.scheme;
|
|
475
|
+
}
|
|
476
|
+
if (value.secret) {
|
|
477
|
+
output.secret = {
|
|
478
|
+
...value.secret,
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
return output;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
function normalizeHTTPBindings(
|
|
485
|
+
input: Record<string, HTTPBinding> | undefined,
|
|
486
|
+
): Record<string, HTTPBinding> {
|
|
487
|
+
const output: Record<string, HTTPBinding> = {};
|
|
488
|
+
for (const [key, value] of Object.entries(input ?? {})) {
|
|
489
|
+
output[key] = cloneHTTPBinding(value);
|
|
490
|
+
}
|
|
491
|
+
return output;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
function cloneHTTPBindings(
|
|
495
|
+
input: Record<string, HTTPBinding>,
|
|
496
|
+
): Record<string, HTTPBinding> {
|
|
497
|
+
const output: Record<string, HTTPBinding> = {};
|
|
498
|
+
for (const [key, value] of Object.entries(input)) {
|
|
499
|
+
output[key] = cloneHTTPBinding(value);
|
|
500
|
+
}
|
|
501
|
+
return output;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
function cloneHTTPBinding(value: HTTPBinding): HTTPBinding {
|
|
505
|
+
const output: HTTPBinding = {
|
|
506
|
+
path: value.path,
|
|
507
|
+
method: value.method,
|
|
508
|
+
security: value.security,
|
|
509
|
+
target: value.target,
|
|
510
|
+
};
|
|
511
|
+
if (value.requestBody) {
|
|
512
|
+
output.requestBody = cloneHTTPRequestBody(value.requestBody);
|
|
513
|
+
}
|
|
514
|
+
if (value.ack) {
|
|
515
|
+
output.ack = cloneHTTPAck(value.ack);
|
|
516
|
+
}
|
|
517
|
+
return output;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
function cloneHTTPRequestBody(value: HTTPRequestBody): HTTPRequestBody {
|
|
521
|
+
const output: HTTPRequestBody = {};
|
|
522
|
+
if (value.required !== undefined) {
|
|
523
|
+
output.required = value.required;
|
|
524
|
+
}
|
|
525
|
+
if (value.content) {
|
|
526
|
+
output.content = {};
|
|
527
|
+
for (const key of Object.keys(value.content)) {
|
|
528
|
+
output.content[key] = {};
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
return output;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
function cloneHTTPAck(value: HTTPAck): HTTPAck {
|
|
535
|
+
const output: HTTPAck = {};
|
|
536
|
+
if (value.status !== undefined) {
|
|
537
|
+
output.status = value.status;
|
|
538
|
+
}
|
|
539
|
+
if (value.headers) {
|
|
540
|
+
output.headers = {
|
|
541
|
+
...value.headers,
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
if (value.body !== undefined) {
|
|
545
|
+
output.body = cloneHTTPBodyValue(value.body);
|
|
546
|
+
}
|
|
547
|
+
return output;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
function cloneHTTPBodyValue<T>(value: T): T {
|
|
551
|
+
return structuredClone(value);
|
|
552
|
+
}
|
|
553
|
+
|
|
352
554
|
function isResponse(value: unknown): value is Response<unknown> {
|
|
353
555
|
if (typeof value !== "object" || value === null) {
|
|
354
556
|
return false;
|
package/src/runtime.ts
CHANGED
|
@@ -40,9 +40,12 @@ import {
|
|
|
40
40
|
CatalogSchema as ProtoCatalogSchema,
|
|
41
41
|
ConnectionMode as ProviderConnectionMode,
|
|
42
42
|
GetSessionCatalogResponseSchema,
|
|
43
|
+
ResolveHTTPSubjectResponseSchema,
|
|
43
44
|
OperationResultSchema,
|
|
44
45
|
ProviderMetadataSchema,
|
|
46
|
+
type HTTPSubjectRequest as ProtoHTTPSubjectRequest,
|
|
45
47
|
type RequestContext as ProtoRequestContext,
|
|
48
|
+
type ResolveHTTPSubjectRequest as ProtoResolveHTTPSubjectRequest,
|
|
46
49
|
IntegrationProvider as IntegrationProviderService,
|
|
47
50
|
StartProviderResponseSchema,
|
|
48
51
|
type ExecuteRequest,
|
|
@@ -68,6 +71,11 @@ import {
|
|
|
68
71
|
import { CacheProvider, isCacheProvider } from "./cache.ts";
|
|
69
72
|
import { SecretsProvider, isSecretsProvider } from "./secrets.ts";
|
|
70
73
|
import { catalogToYaml, type Catalog } from "./catalog.ts";
|
|
74
|
+
import {
|
|
75
|
+
HTTPSubjectResolutionError,
|
|
76
|
+
type HTTPSubjectRequest,
|
|
77
|
+
type HTTPSubjectResolutionContext,
|
|
78
|
+
} from "./http-subject.ts";
|
|
71
79
|
import {
|
|
72
80
|
PluginProvider,
|
|
73
81
|
connectionModeToProtoValue,
|
|
@@ -106,6 +114,11 @@ export const ENV_PROVIDER_PARENT_PID = "GESTALT_PLUGIN_PARENT_PID";
|
|
|
106
114
|
* Environment variable used to request static catalog generation.
|
|
107
115
|
*/
|
|
108
116
|
export const ENV_WRITE_CATALOG = "GESTALT_PLUGIN_WRITE_CATALOG";
|
|
117
|
+
/**
|
|
118
|
+
* Environment variable used to request generated manifest metadata export.
|
|
119
|
+
*/
|
|
120
|
+
export const ENV_WRITE_MANIFEST_METADATA =
|
|
121
|
+
"GESTALT_PLUGIN_WRITE_MANIFEST_METADATA";
|
|
109
122
|
/**
|
|
110
123
|
* Protocol version currently implemented by the TypeScript runtime.
|
|
111
124
|
*/
|
|
@@ -288,13 +301,19 @@ export async function runLoadedProvider(
|
|
|
288
301
|
}
|
|
289
302
|
|
|
290
303
|
const catalogPath = process.env[ENV_WRITE_CATALOG];
|
|
291
|
-
|
|
304
|
+
const manifestMetadataPath = process.env[ENV_WRITE_MANIFEST_METADATA];
|
|
305
|
+
if (catalogPath || manifestMetadataPath) {
|
|
292
306
|
if (!isPluginProvider(provider)) {
|
|
293
307
|
throw new Error(
|
|
294
|
-
"static catalog generation
|
|
308
|
+
"static catalog and manifest metadata generation are only supported for plugin providers",
|
|
295
309
|
);
|
|
296
310
|
}
|
|
297
|
-
|
|
311
|
+
if (catalogPath) {
|
|
312
|
+
writeFileSync(catalogPath, catalogToYaml(provider.staticCatalog()), "utf8");
|
|
313
|
+
}
|
|
314
|
+
if (manifestMetadataPath && provider.supportsManifestMetadata()) {
|
|
315
|
+
provider.writeManifestMetadata(manifestMetadataPath);
|
|
316
|
+
}
|
|
298
317
|
return;
|
|
299
318
|
}
|
|
300
319
|
|
|
@@ -508,6 +527,36 @@ export function createProviderService(
|
|
|
508
527
|
),
|
|
509
528
|
);
|
|
510
529
|
},
|
|
530
|
+
async resolveHTTPSubject(request: ProtoResolveHTTPSubjectRequest) {
|
|
531
|
+
let subject;
|
|
532
|
+
try {
|
|
533
|
+
subject = await provider.resolveHTTPSubject(
|
|
534
|
+
providerHTTPSubjectRequest(request.request),
|
|
535
|
+
providerHTTPSubjectResolutionContext(request.context),
|
|
536
|
+
);
|
|
537
|
+
} catch (error) {
|
|
538
|
+
if (error instanceof HTTPSubjectResolutionError) {
|
|
539
|
+
return create(ResolveHTTPSubjectResponseSchema, {
|
|
540
|
+
rejectStatus: error.status,
|
|
541
|
+
rejectMessage: error.message,
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
throw new ConnectError(
|
|
545
|
+
`resolve http subject: ${errorMessage(error)}`,
|
|
546
|
+
Code.Unknown,
|
|
547
|
+
);
|
|
548
|
+
}
|
|
549
|
+
return create(ResolveHTTPSubjectResponseSchema, subject
|
|
550
|
+
? {
|
|
551
|
+
subject: {
|
|
552
|
+
id: subject.id,
|
|
553
|
+
kind: subject.kind,
|
|
554
|
+
displayName: subject.displayName,
|
|
555
|
+
authSource: subject.authSource,
|
|
556
|
+
},
|
|
557
|
+
}
|
|
558
|
+
: {});
|
|
559
|
+
},
|
|
511
560
|
async getSessionCatalog(request: GetSessionCatalogRequest) {
|
|
512
561
|
let catalog: Catalog | Record<string, unknown> | null | undefined;
|
|
513
562
|
try {
|
|
@@ -741,6 +790,48 @@ function providerRequest(
|
|
|
741
790
|
};
|
|
742
791
|
}
|
|
743
792
|
|
|
793
|
+
function providerHTTPSubjectRequest(
|
|
794
|
+
request?: ProtoHTTPSubjectRequest,
|
|
795
|
+
): HTTPSubjectRequest {
|
|
796
|
+
return {
|
|
797
|
+
binding: request?.binding ?? "",
|
|
798
|
+
method: request?.method ?? "",
|
|
799
|
+
path: request?.path ?? "",
|
|
800
|
+
contentType: request?.contentType ?? "",
|
|
801
|
+
headers: providerStringLists(request?.headers),
|
|
802
|
+
query: providerStringLists(request?.query),
|
|
803
|
+
params: objectFromUnknown(request?.params),
|
|
804
|
+
rawBody: new Uint8Array(request?.rawBody ?? new Uint8Array()),
|
|
805
|
+
securityScheme: request?.securityScheme ?? "",
|
|
806
|
+
verifiedSubject: request?.verifiedSubject ?? "",
|
|
807
|
+
verifiedClaims: {
|
|
808
|
+
...(request?.verifiedClaims ?? {}),
|
|
809
|
+
},
|
|
810
|
+
};
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
function providerHTTPSubjectResolutionContext(
|
|
814
|
+
requestContext?: ProtoRequestContext,
|
|
815
|
+
): HTTPSubjectResolutionContext {
|
|
816
|
+
const request = providerRequest("", {}, requestContext);
|
|
817
|
+
return {
|
|
818
|
+
subject: request.subject,
|
|
819
|
+
credential: request.credential,
|
|
820
|
+
access: request.access,
|
|
821
|
+
workflow: request.workflow,
|
|
822
|
+
};
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
function providerStringLists(
|
|
826
|
+
input: Record<string, { values?: string[] }> | undefined,
|
|
827
|
+
): Record<string, string[]> {
|
|
828
|
+
const output: Record<string, string[]> = {};
|
|
829
|
+
for (const [key, value] of Object.entries(input ?? {})) {
|
|
830
|
+
output[key] = [...(value.values ?? [])];
|
|
831
|
+
}
|
|
832
|
+
return output;
|
|
833
|
+
}
|
|
834
|
+
|
|
744
835
|
function providerRuntimeEntry(
|
|
745
836
|
kind: ProviderKind,
|
|
746
837
|
): ProviderRuntimeEntry {
|
package/src/s3.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { connect } from "node:net";
|
|
2
|
-
|
|
3
1
|
import { create } from "@bufbuild/protobuf";
|
|
4
2
|
import { EmptySchema } from "@bufbuild/protobuf/wkt";
|
|
5
3
|
import {
|
|
@@ -503,9 +501,9 @@ export class S3 {
|
|
|
503
501
|
throw new Error(`${envName} is not set`);
|
|
504
502
|
}
|
|
505
503
|
const transport = createGrpcTransport({
|
|
506
|
-
baseUrl:
|
|
504
|
+
baseUrl: unixSocketBaseUrl(socketPath),
|
|
507
505
|
nodeOptions: {
|
|
508
|
-
|
|
506
|
+
path: socketPath,
|
|
509
507
|
},
|
|
510
508
|
});
|
|
511
509
|
this.client = createClient(S3Service, transport);
|
|
@@ -740,6 +738,15 @@ export class S3Object {
|
|
|
740
738
|
}
|
|
741
739
|
}
|
|
742
740
|
|
|
741
|
+
function unixSocketBaseUrl(socketPath: string): string {
|
|
742
|
+
let hash = 0x811c9dc5;
|
|
743
|
+
for (const char of socketPath) {
|
|
744
|
+
hash ^= char.charCodeAt(0);
|
|
745
|
+
hash = Math.imul(hash, 0x01000193);
|
|
746
|
+
}
|
|
747
|
+
return `http://unix-${(hash >>> 0).toString(16)}.local`;
|
|
748
|
+
}
|
|
749
|
+
|
|
743
750
|
async function invokeS3Provider<T>(label: string, fn: () => Promise<T>): Promise<T> {
|
|
744
751
|
try {
|
|
745
752
|
return await fn();
|
package/src/workflow-manager.ts
CHANGED
|
@@ -6,37 +6,69 @@ import { createGrpcTransport } from "@connectrpc/connect-node";
|
|
|
6
6
|
|
|
7
7
|
import {
|
|
8
8
|
WorkflowManagerCreateScheduleRequestSchema,
|
|
9
|
+
WorkflowManagerCreateEventTriggerRequestSchema,
|
|
9
10
|
WorkflowManagerDeleteScheduleRequestSchema,
|
|
11
|
+
WorkflowManagerDeleteEventTriggerRequestSchema,
|
|
10
12
|
WorkflowManagerGetScheduleRequestSchema,
|
|
13
|
+
WorkflowManagerGetEventTriggerRequestSchema,
|
|
11
14
|
WorkflowManagerHost as WorkflowManagerHostService,
|
|
12
15
|
WorkflowManagerPauseScheduleRequestSchema,
|
|
16
|
+
WorkflowManagerPauseEventTriggerRequestSchema,
|
|
17
|
+
WorkflowManagerPublishEventRequestSchema,
|
|
13
18
|
WorkflowManagerResumeScheduleRequestSchema,
|
|
19
|
+
WorkflowManagerResumeEventTriggerRequestSchema,
|
|
14
20
|
WorkflowManagerUpdateScheduleRequestSchema,
|
|
21
|
+
WorkflowManagerUpdateEventTriggerRequestSchema,
|
|
15
22
|
type ManagedWorkflowSchedule,
|
|
23
|
+
type ManagedWorkflowEventTrigger,
|
|
24
|
+
type WorkflowEvent,
|
|
16
25
|
} from "../gen/v1/workflow_pb.ts";
|
|
17
26
|
import type { Request } from "./api.ts";
|
|
18
27
|
|
|
19
28
|
export const ENV_WORKFLOW_MANAGER_SOCKET = "GESTALT_WORKFLOW_MANAGER_SOCKET";
|
|
20
29
|
|
|
21
30
|
export type ManagedWorkflowScheduleMessage = ManagedWorkflowSchedule;
|
|
31
|
+
export type ManagedWorkflowEventTriggerMessage = ManagedWorkflowEventTrigger;
|
|
32
|
+
export type WorkflowEventMessage = WorkflowEvent;
|
|
22
33
|
export type WorkflowManagerCreateScheduleInput = MessageInitShape<
|
|
23
34
|
typeof WorkflowManagerCreateScheduleRequestSchema
|
|
24
35
|
>;
|
|
36
|
+
export type WorkflowManagerCreateTriggerInput = MessageInitShape<
|
|
37
|
+
typeof WorkflowManagerCreateEventTriggerRequestSchema
|
|
38
|
+
>;
|
|
25
39
|
export type WorkflowManagerGetScheduleInput = MessageInitShape<
|
|
26
40
|
typeof WorkflowManagerGetScheduleRequestSchema
|
|
27
41
|
>;
|
|
42
|
+
export type WorkflowManagerGetTriggerInput = MessageInitShape<
|
|
43
|
+
typeof WorkflowManagerGetEventTriggerRequestSchema
|
|
44
|
+
>;
|
|
28
45
|
export type WorkflowManagerUpdateScheduleInput = MessageInitShape<
|
|
29
46
|
typeof WorkflowManagerUpdateScheduleRequestSchema
|
|
30
47
|
>;
|
|
48
|
+
export type WorkflowManagerUpdateTriggerInput = MessageInitShape<
|
|
49
|
+
typeof WorkflowManagerUpdateEventTriggerRequestSchema
|
|
50
|
+
>;
|
|
31
51
|
export type WorkflowManagerDeleteScheduleInput = MessageInitShape<
|
|
32
52
|
typeof WorkflowManagerDeleteScheduleRequestSchema
|
|
33
53
|
>;
|
|
54
|
+
export type WorkflowManagerDeleteTriggerInput = MessageInitShape<
|
|
55
|
+
typeof WorkflowManagerDeleteEventTriggerRequestSchema
|
|
56
|
+
>;
|
|
34
57
|
export type WorkflowManagerPauseScheduleInput = MessageInitShape<
|
|
35
58
|
typeof WorkflowManagerPauseScheduleRequestSchema
|
|
36
59
|
>;
|
|
60
|
+
export type WorkflowManagerPauseTriggerInput = MessageInitShape<
|
|
61
|
+
typeof WorkflowManagerPauseEventTriggerRequestSchema
|
|
62
|
+
>;
|
|
37
63
|
export type WorkflowManagerResumeScheduleInput = MessageInitShape<
|
|
38
64
|
typeof WorkflowManagerResumeScheduleRequestSchema
|
|
39
65
|
>;
|
|
66
|
+
export type WorkflowManagerResumeTriggerInput = MessageInitShape<
|
|
67
|
+
typeof WorkflowManagerResumeEventTriggerRequestSchema
|
|
68
|
+
>;
|
|
69
|
+
export type WorkflowManagerPublishEventInput = MessageInitShape<
|
|
70
|
+
typeof WorkflowManagerPublishEventRequestSchema
|
|
71
|
+
>;
|
|
40
72
|
|
|
41
73
|
export class WorkflowManager {
|
|
42
74
|
private readonly client: Client<typeof WorkflowManagerHostService>;
|
|
@@ -116,6 +148,69 @@ export class WorkflowManager {
|
|
|
116
148
|
invocationToken: this.invocationToken,
|
|
117
149
|
});
|
|
118
150
|
}
|
|
151
|
+
|
|
152
|
+
async createTrigger(
|
|
153
|
+
request: WorkflowManagerCreateTriggerInput,
|
|
154
|
+
): Promise<ManagedWorkflowEventTriggerMessage> {
|
|
155
|
+
return await this.client.createEventTrigger({
|
|
156
|
+
...request,
|
|
157
|
+
invocationToken: this.invocationToken,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
async getTrigger(
|
|
162
|
+
request: WorkflowManagerGetTriggerInput,
|
|
163
|
+
): Promise<ManagedWorkflowEventTriggerMessage> {
|
|
164
|
+
return await this.client.getEventTrigger({
|
|
165
|
+
...request,
|
|
166
|
+
invocationToken: this.invocationToken,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
async updateTrigger(
|
|
171
|
+
request: WorkflowManagerUpdateTriggerInput,
|
|
172
|
+
): Promise<ManagedWorkflowEventTriggerMessage> {
|
|
173
|
+
return await this.client.updateEventTrigger({
|
|
174
|
+
...request,
|
|
175
|
+
invocationToken: this.invocationToken,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
async deleteTrigger(
|
|
180
|
+
request: WorkflowManagerDeleteTriggerInput,
|
|
181
|
+
): Promise<void> {
|
|
182
|
+
await this.client.deleteEventTrigger({
|
|
183
|
+
...request,
|
|
184
|
+
invocationToken: this.invocationToken,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
async pauseTrigger(
|
|
189
|
+
request: WorkflowManagerPauseTriggerInput,
|
|
190
|
+
): Promise<ManagedWorkflowEventTriggerMessage> {
|
|
191
|
+
return await this.client.pauseEventTrigger({
|
|
192
|
+
...request,
|
|
193
|
+
invocationToken: this.invocationToken,
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
async resumeTrigger(
|
|
198
|
+
request: WorkflowManagerResumeTriggerInput,
|
|
199
|
+
): Promise<ManagedWorkflowEventTriggerMessage> {
|
|
200
|
+
return await this.client.resumeEventTrigger({
|
|
201
|
+
...request,
|
|
202
|
+
invocationToken: this.invocationToken,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
async publishEvent(
|
|
207
|
+
request: WorkflowManagerPublishEventInput,
|
|
208
|
+
): Promise<WorkflowEventMessage> {
|
|
209
|
+
return await this.client.publishEvent({
|
|
210
|
+
...request,
|
|
211
|
+
invocationToken: this.invocationToken,
|
|
212
|
+
});
|
|
213
|
+
}
|
|
119
214
|
}
|
|
120
215
|
|
|
121
216
|
function normalizeInvocationToken(requestOrToken: Request | string): string {
|