@valon-technologies/gestalt 0.0.1-alpha.34 → 0.0.1-alpha.35
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/package.json +1 -1
- package/src/authorization.ts +92 -0
- package/src/index.ts +2 -0
- package/src/workflow.ts +2 -2
package/package.json
CHANGED
package/src/authorization.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { create } from "@bufbuild/protobuf";
|
|
|
2
2
|
import {
|
|
3
3
|
Code,
|
|
4
4
|
ConnectError,
|
|
5
|
+
createClient,
|
|
6
|
+
type Client,
|
|
5
7
|
type ServiceImpl,
|
|
6
8
|
} from "@connectrpc/connect";
|
|
7
9
|
|
|
@@ -14,6 +16,7 @@ import {
|
|
|
14
16
|
DefaultAccessPolicy as ProtoDefaultAccessPolicy,
|
|
15
17
|
DeleteRelationshipResponseSchema,
|
|
16
18
|
GetActiveModelRefResponseSchema,
|
|
19
|
+
ListRelationshipsRequestSchema,
|
|
17
20
|
ListActiveModelResourceTypesResponseSchema,
|
|
18
21
|
ListRelationshipsResponseSchema,
|
|
19
22
|
ModelActionSchema,
|
|
@@ -39,6 +42,7 @@ import {
|
|
|
39
42
|
type DeleteRelationshipRequest as ProtoDeleteRelationshipRequest,
|
|
40
43
|
type ListActiveModelResourceTypesRequest as ProtoListActiveModelResourceTypesRequest,
|
|
41
44
|
type ListRelationshipsRequest as ProtoListRelationshipsRequest,
|
|
45
|
+
type ListRelationshipsResponse as ProtoListRelationshipsResponse,
|
|
42
46
|
type ModelAllowedTarget as ProtoModelAllowedTarget,
|
|
43
47
|
type Relationship as ProtoRelationship,
|
|
44
48
|
type RelationshipFilter as ProtoRelationshipFilter,
|
|
@@ -56,6 +60,12 @@ import {
|
|
|
56
60
|
timestampFromDate,
|
|
57
61
|
type JsonObjectInput,
|
|
58
62
|
} from "./protocol.ts";
|
|
63
|
+
import {
|
|
64
|
+
createHostServiceGrpcTransport,
|
|
65
|
+
hostServiceMetadataInterceptors,
|
|
66
|
+
parseHostServiceTarget,
|
|
67
|
+
requireHostServiceTarget,
|
|
68
|
+
} from "./host-service.ts";
|
|
59
69
|
|
|
60
70
|
export const RelationshipTargetType = {
|
|
61
71
|
UNSPECIFIED: ProtoRelationshipTargetType.UNSPECIFIED,
|
|
@@ -253,6 +263,54 @@ export interface ListActiveModelResourceTypesResponse {
|
|
|
253
263
|
modelId?: string | undefined;
|
|
254
264
|
}
|
|
255
265
|
|
|
266
|
+
export interface Authorization {
|
|
267
|
+
listRelationships(
|
|
268
|
+
request: ListRelationshipsRequest,
|
|
269
|
+
): Promise<ListRelationshipsResponse>;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
class AuthorizationImpl implements Authorization {
|
|
273
|
+
private readonly client: Client<typeof AuthorizationProviderService>;
|
|
274
|
+
|
|
275
|
+
constructor(target?: string, relayToken?: string) {
|
|
276
|
+
const host = target
|
|
277
|
+
? { target, token: relayToken?.trim() ?? "" }
|
|
278
|
+
: requireHostServiceTarget("authorization");
|
|
279
|
+
const transport = createHostServiceGrpcTransport(
|
|
280
|
+
parseHostServiceTarget("authorization", host.target),
|
|
281
|
+
hostServiceMetadataInterceptors(host.token, ""),
|
|
282
|
+
);
|
|
283
|
+
this.client = createClient(AuthorizationProviderService, transport);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
async listRelationships(
|
|
287
|
+
request: ListRelationshipsRequest,
|
|
288
|
+
): Promise<ListRelationshipsResponse> {
|
|
289
|
+
return listRelationshipsResponseFromProto(
|
|
290
|
+
await this.client.listRelationships(listRelationshipsRequestToProto(request)),
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
let sharedAuthorization:
|
|
296
|
+
| { target: string; token: string; client: Authorization }
|
|
297
|
+
| undefined;
|
|
298
|
+
|
|
299
|
+
export function Authorization(): Authorization {
|
|
300
|
+
const { target, token } = requireHostServiceTarget("authorization");
|
|
301
|
+
if (
|
|
302
|
+
sharedAuthorization &&
|
|
303
|
+
sharedAuthorization.target === target &&
|
|
304
|
+
sharedAuthorization.token === token
|
|
305
|
+
) {
|
|
306
|
+
return sharedAuthorization.client;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
const client = new AuthorizationImpl(target, token);
|
|
310
|
+
sharedAuthorization = { target, token, client };
|
|
311
|
+
return client;
|
|
312
|
+
}
|
|
313
|
+
|
|
256
314
|
export interface AuthorizationProviderOptions extends ProviderBaseOptions {
|
|
257
315
|
checkAccess: (request: CheckAccessRequest) => MaybePromise<CheckAccessResponse>;
|
|
258
316
|
checkAccessMany: (
|
|
@@ -516,6 +574,25 @@ function listRelationshipsRequestFromProto(
|
|
|
516
574
|
};
|
|
517
575
|
}
|
|
518
576
|
|
|
577
|
+
function listRelationshipsRequestToProto(
|
|
578
|
+
value: ListRelationshipsRequest,
|
|
579
|
+
) {
|
|
580
|
+
return create(ListRelationshipsRequestSchema, {
|
|
581
|
+
filter: relationshipFilterToProto(value.filter),
|
|
582
|
+
pageSize: value.pageSize ?? 0,
|
|
583
|
+
pageToken: value.pageToken ?? "",
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
function listRelationshipsResponseFromProto(
|
|
588
|
+
value: ProtoListRelationshipsResponse,
|
|
589
|
+
): ListRelationshipsResponse {
|
|
590
|
+
return {
|
|
591
|
+
relationships: value.relationships.map(relationshipFromProtoRequired),
|
|
592
|
+
nextPageToken: value.nextPageToken,
|
|
593
|
+
};
|
|
594
|
+
}
|
|
595
|
+
|
|
519
596
|
function listRelationshipsResponseToProto(
|
|
520
597
|
value: ListRelationshipsResponse | undefined,
|
|
521
598
|
) {
|
|
@@ -720,6 +797,21 @@ function relationshipFilterFromProto(
|
|
|
720
797
|
};
|
|
721
798
|
}
|
|
722
799
|
|
|
800
|
+
function relationshipFilterToProto(value: RelationshipFilter | undefined) {
|
|
801
|
+
if (!value) {
|
|
802
|
+
return undefined;
|
|
803
|
+
}
|
|
804
|
+
return {
|
|
805
|
+
target: relationshipTargetToProto(value.target),
|
|
806
|
+
relation: value.relation ?? "",
|
|
807
|
+
resource: resourceToProto(value.resource),
|
|
808
|
+
targetType: value.targetType ?? RelationshipTargetType.UNSPECIFIED,
|
|
809
|
+
targetEntityType: value.targetEntityType ?? "",
|
|
810
|
+
resourceType: value.resourceType ?? "",
|
|
811
|
+
sourceLayer: value.sourceLayer ?? SourceLayer.UNSPECIFIED,
|
|
812
|
+
};
|
|
813
|
+
}
|
|
814
|
+
|
|
723
815
|
function relationshipFromProto(
|
|
724
816
|
value: ProtoRelationship | undefined,
|
|
725
817
|
): Relationship | undefined {
|
package/src/index.ts
CHANGED
|
@@ -110,6 +110,7 @@ export {
|
|
|
110
110
|
type RuntimeLogWriterOptions,
|
|
111
111
|
} from "./runtime-log-host.ts";
|
|
112
112
|
export {
|
|
113
|
+
Authorization,
|
|
113
114
|
AuthorizationProvider,
|
|
114
115
|
DefaultAccessPolicy,
|
|
115
116
|
RelationshipTargetType,
|
|
@@ -119,6 +120,7 @@ export {
|
|
|
119
120
|
isAuthorizationProvider,
|
|
120
121
|
type AddRelationshipRequest,
|
|
121
122
|
type AddRelationshipResponse,
|
|
123
|
+
type Authorization as AuthorizationClient,
|
|
122
124
|
type AuthorizationAction,
|
|
123
125
|
type AuthorizationModel,
|
|
124
126
|
type AuthorizationModelRef,
|
package/src/workflow.ts
CHANGED
|
@@ -1766,11 +1766,11 @@ export function evaluateWorkflowValue(ctx: WorkflowEvalContext, input: WorkflowV
|
|
|
1766
1766
|
}
|
|
1767
1767
|
|
|
1768
1768
|
export function renderWorkflowTemplate(ctx: WorkflowEvalContext, template: string): string {
|
|
1769
|
-
return template.replace(/\$\$\{/g, "\u0000{").replace(/\$\{([^{}]+)\}/g, (_match, expr: string) => {
|
|
1769
|
+
return template.replace(/\$\$\{\{/g, "\u0000{{").replace(/\$\{\{([^{}]+)\}\}/g, (_match, expr: string) => {
|
|
1770
1770
|
const resolved = templateExpressionValue(ctx, expr.trim());
|
|
1771
1771
|
if (!resolved.ok) throw new WorkflowValueError(`template expression "${expr.trim()}" did not resolve`);
|
|
1772
1772
|
return renderTemplateValue(resolved.value);
|
|
1773
|
-
}).replace(/\u0000\{/g, "${");
|
|
1773
|
+
}).replace(/\u0000\{\{/g, "${{");
|
|
1774
1774
|
}
|
|
1775
1775
|
|
|
1776
1776
|
export function pathValue(value: unknown, path: string): { value: unknown; ok: boolean } {
|