@flarcos/arazzo-sdk 0.1.0
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/CHANGELOG.md +13 -0
- package/README.md +252 -0
- package/dist/cli.d.ts +11 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +212 -0
- package/dist/cli.js.map +1 -0
- package/dist/generated/open-payments-client.d.ts +283 -0
- package/dist/generated/open-payments-client.d.ts.map +1 -0
- package/dist/generated/open-payments-client.js +1588 -0
- package/dist/generated/open-payments-client.js.map +1 -0
- package/dist/generator/codegen.d.ts +32 -0
- package/dist/generator/codegen.d.ts.map +1 -0
- package/dist/generator/codegen.js +127 -0
- package/dist/generator/codegen.js.map +1 -0
- package/dist/generator/templates.d.ts +27 -0
- package/dist/generator/templates.d.ts.map +1 -0
- package/dist/generator/templates.js +154 -0
- package/dist/generator/templates.js.map +1 -0
- package/dist/generator/type-mapper.d.ts +35 -0
- package/dist/generator/type-mapper.d.ts.map +1 -0
- package/dist/generator/type-mapper.js +145 -0
- package/dist/generator/type-mapper.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/parser/arazzo-parser.d.ts +38 -0
- package/dist/parser/arazzo-parser.d.ts.map +1 -0
- package/dist/parser/arazzo-parser.js +162 -0
- package/dist/parser/arazzo-parser.js.map +1 -0
- package/dist/parser/types.d.ts +115 -0
- package/dist/parser/types.d.ts.map +1 -0
- package/dist/parser/types.js +10 -0
- package/dist/parser/types.js.map +1 -0
- package/dist/runtime/expression-resolver.d.ts +59 -0
- package/dist/runtime/expression-resolver.d.ts.map +1 -0
- package/dist/runtime/expression-resolver.js +180 -0
- package/dist/runtime/expression-resolver.js.map +1 -0
- package/dist/runtime/http-client.d.ts +47 -0
- package/dist/runtime/http-client.d.ts.map +1 -0
- package/dist/runtime/http-client.js +126 -0
- package/dist/runtime/http-client.js.map +1 -0
- package/dist/runtime/types.d.ts +109 -0
- package/dist/runtime/types.d.ts.map +1 -0
- package/dist/runtime/types.js +7 -0
- package/dist/runtime/types.js.map +1 -0
- package/dist/runtime/workflow-executor.d.ts +33 -0
- package/dist/runtime/workflow-executor.d.ts.map +1 -0
- package/dist/runtime/workflow-executor.js +506 -0
- package/dist/runtime/workflow-executor.js.map +1 -0
- package/package.json +57 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @flarcos/arazzo-sdk
|
|
3
|
+
*
|
|
4
|
+
* Parse Arazzo 1.0.1 workflow specifications and generate typed
|
|
5
|
+
* TypeScript SDKs for Open Payments API workflows.
|
|
6
|
+
*
|
|
7
|
+
* This package provides:
|
|
8
|
+
* - **Parser**: Read Arazzo YAML files into typed ASTs
|
|
9
|
+
* - **Runtime**: Execute workflows dynamically at runtime
|
|
10
|
+
* - **Generator**: Generate typed TypeScript SDK code from Arazzo specs
|
|
11
|
+
* - **CLI**: Command-line tool for code generation and validation
|
|
12
|
+
*/
|
|
13
|
+
// ─── Parser ───
|
|
14
|
+
export { parseArazzoFile, parseArazzoFiles, parseArazzoContent, extractOperationIds, extractExpressions, splitOperationId, ArazzoParserError, } from './parser/arazzo-parser.js';
|
|
15
|
+
// ─── Runtime ───
|
|
16
|
+
export { executeWorkflow, WorkflowExecutionError } from './runtime/workflow-executor.js';
|
|
17
|
+
export { resolveExpression, resolveDeep, isExpression, extractExpressionRefs, ExpressionError, } from './runtime/expression-resolver.js';
|
|
18
|
+
export { FetchHttpClient, GnapAuthProvider, BearerAuthProvider, } from './runtime/http-client.js';
|
|
19
|
+
// ─── Generator ───
|
|
20
|
+
export { generateSDK, generateTypes } from './generator/codegen.js';
|
|
21
|
+
export { mapSchemaTypeToTS, generateInterface, generateOutputInterface, generateInterfaceProperties, toPascalCase, toCamelCase, } from './generator/type-mapper.js';
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,iBAAiB;AACjB,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,2BAA2B,CAAC;AAkBnC,kBAAkB;AAClB,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAEzF,OAAO,EACL,iBAAiB,EACjB,WAAW,EACX,YAAY,EACZ,qBAAqB,EACrB,eAAe,GAChB,MAAM,kCAAkC,CAAC;AAI1C,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,0BAA0B,CAAC;AAgBlC,oBAAoB;AACpB,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAGpE,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,uBAAuB,EACvB,2BAA2B,EAC3B,YAAY,EACZ,WAAW,GACZ,MAAM,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Arazzo YAML Parser
|
|
3
|
+
*
|
|
4
|
+
* Parses Arazzo 1.0.1 YAML workflow files into a typed AST.
|
|
5
|
+
* Validates required fields and resolves source description paths.
|
|
6
|
+
*/
|
|
7
|
+
import type { ArazzoDocument, ParsedWorkflow, WorkflowObject } from './types.js';
|
|
8
|
+
export declare class ArazzoParserError extends Error {
|
|
9
|
+
filePath: string;
|
|
10
|
+
context?: string | undefined;
|
|
11
|
+
constructor(message: string, filePath: string, context?: string | undefined);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Parse a single Arazzo YAML file into a typed AST.
|
|
15
|
+
*/
|
|
16
|
+
export declare function parseArazzoFile(filePath: string): ParsedWorkflow;
|
|
17
|
+
/**
|
|
18
|
+
* Parse multiple Arazzo YAML files.
|
|
19
|
+
*/
|
|
20
|
+
export declare function parseArazzoFiles(filePaths: string[]): ParsedWorkflow[];
|
|
21
|
+
/**
|
|
22
|
+
* Parse Arazzo YAML content from a string (useful for testing).
|
|
23
|
+
*/
|
|
24
|
+
export declare function parseArazzoContent(content: string, virtualPath?: string): ParsedWorkflow;
|
|
25
|
+
/**
|
|
26
|
+
* Extract all unique operationIds referenced across all workflows in a document.
|
|
27
|
+
*/
|
|
28
|
+
export declare function extractOperationIds(doc: ArazzoDocument): string[];
|
|
29
|
+
/**
|
|
30
|
+
* Extract all runtime expressions used in a workflow's outputs and step outputs.
|
|
31
|
+
*/
|
|
32
|
+
export declare function extractExpressions(workflow: WorkflowObject): string[];
|
|
33
|
+
/**
|
|
34
|
+
* Get the source name and operation name from a qualified operationId.
|
|
35
|
+
* e.g., "resourceServer.create-incoming-payment" → ["resourceServer", "create-incoming-payment"]
|
|
36
|
+
*/
|
|
37
|
+
export declare function splitOperationId(operationId: string): [string, string];
|
|
38
|
+
//# sourceMappingURL=arazzo-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arazzo-parser.d.ts","sourceRoot":"","sources":["../../src/parser/arazzo-parser.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EAEd,cAAc,EAEf,MAAM,YAAY,CAAC;AAEpB,qBAAa,iBAAkB,SAAQ,KAAK;IAGjC,QAAQ,EAAE,MAAM;IAChB,OAAO,CAAC,EAAE,MAAM;gBAFvB,OAAO,EAAE,MAAM,EACR,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,MAAM,YAAA;CAK1B;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc,CAchE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,cAAc,EAAE,CAEtE;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,EACf,WAAW,GAAE,MAAmB,GAC/B,cAAc,CAShB;AAyHD;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,cAAc,GAAG,MAAM,EAAE,CAUjE;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,cAAc,GAAG,MAAM,EAAE,CAgBrE;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAMtE"}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Arazzo YAML Parser
|
|
3
|
+
*
|
|
4
|
+
* Parses Arazzo 1.0.1 YAML workflow files into a typed AST.
|
|
5
|
+
* Validates required fields and resolves source description paths.
|
|
6
|
+
*/
|
|
7
|
+
import { readFileSync } from 'node:fs';
|
|
8
|
+
import { resolve, dirname } from 'node:path';
|
|
9
|
+
import { parse as parseYaml } from 'yaml';
|
|
10
|
+
export class ArazzoParserError extends Error {
|
|
11
|
+
filePath;
|
|
12
|
+
context;
|
|
13
|
+
constructor(message, filePath, context) {
|
|
14
|
+
super(`[ArazzoParser] ${filePath}: ${message}${context ? ` (${context})` : ''}`);
|
|
15
|
+
this.filePath = filePath;
|
|
16
|
+
this.context = context;
|
|
17
|
+
this.name = 'ArazzoParserError';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Parse a single Arazzo YAML file into a typed AST.
|
|
22
|
+
*/
|
|
23
|
+
export function parseArazzoFile(filePath) {
|
|
24
|
+
const absolutePath = resolve(filePath);
|
|
25
|
+
const content = readFileSync(absolutePath, 'utf-8');
|
|
26
|
+
const doc = parseYaml(content);
|
|
27
|
+
validateDocument(doc, absolutePath);
|
|
28
|
+
const resolvedSources = resolveSourceDescriptions(doc, absolutePath);
|
|
29
|
+
return {
|
|
30
|
+
document: doc,
|
|
31
|
+
filePath: absolutePath,
|
|
32
|
+
resolvedSources,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Parse multiple Arazzo YAML files.
|
|
37
|
+
*/
|
|
38
|
+
export function parseArazzoFiles(filePaths) {
|
|
39
|
+
return filePaths.map((fp) => parseArazzoFile(fp));
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Parse Arazzo YAML content from a string (useful for testing).
|
|
43
|
+
*/
|
|
44
|
+
export function parseArazzoContent(content, virtualPath = '<inline>') {
|
|
45
|
+
const doc = parseYaml(content);
|
|
46
|
+
validateDocument(doc, virtualPath);
|
|
47
|
+
return {
|
|
48
|
+
document: doc,
|
|
49
|
+
filePath: virtualPath,
|
|
50
|
+
resolvedSources: [],
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
// ─── Validation ───
|
|
54
|
+
function validateDocument(doc, filePath) {
|
|
55
|
+
if (!doc.arazzo) {
|
|
56
|
+
throw new ArazzoParserError('Missing required field "arazzo"', filePath);
|
|
57
|
+
}
|
|
58
|
+
if (!doc.arazzo.startsWith('1.')) {
|
|
59
|
+
throw new ArazzoParserError(`Unsupported Arazzo version "${doc.arazzo}". Only 1.x is supported.`, filePath);
|
|
60
|
+
}
|
|
61
|
+
if (!doc.info?.title) {
|
|
62
|
+
throw new ArazzoParserError('Missing required field "info.title"', filePath);
|
|
63
|
+
}
|
|
64
|
+
if (!doc.sourceDescriptions || doc.sourceDescriptions.length === 0) {
|
|
65
|
+
throw new ArazzoParserError('At least one sourceDescription is required', filePath);
|
|
66
|
+
}
|
|
67
|
+
if (!doc.workflows || doc.workflows.length === 0) {
|
|
68
|
+
throw new ArazzoParserError('At least one workflow is required', filePath);
|
|
69
|
+
}
|
|
70
|
+
// Validate each workflow
|
|
71
|
+
for (const workflow of doc.workflows) {
|
|
72
|
+
validateWorkflow(workflow, filePath);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function validateWorkflow(workflow, filePath) {
|
|
76
|
+
if (!workflow.workflowId) {
|
|
77
|
+
throw new ArazzoParserError('Workflow missing required "workflowId"', filePath);
|
|
78
|
+
}
|
|
79
|
+
if (!workflow.steps || workflow.steps.length === 0) {
|
|
80
|
+
throw new ArazzoParserError('Workflow must have at least one step', filePath, `workflowId: ${workflow.workflowId}`);
|
|
81
|
+
}
|
|
82
|
+
const stepIds = new Set();
|
|
83
|
+
for (const step of workflow.steps) {
|
|
84
|
+
validateStep(step, workflow.workflowId, filePath);
|
|
85
|
+
if (stepIds.has(step.stepId)) {
|
|
86
|
+
throw new ArazzoParserError(`Duplicate stepId "${step.stepId}"`, filePath, `workflowId: ${workflow.workflowId}`);
|
|
87
|
+
}
|
|
88
|
+
stepIds.add(step.stepId);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function validateStep(step, workflowId, filePath) {
|
|
92
|
+
if (!step.stepId) {
|
|
93
|
+
throw new ArazzoParserError('Step missing required "stepId"', filePath, `workflowId: ${workflowId}`);
|
|
94
|
+
}
|
|
95
|
+
// A step must have exactly one of: operationId, operationPath, or workflowId
|
|
96
|
+
const refs = [step.operationId, step.operationPath, step.workflowId].filter(Boolean);
|
|
97
|
+
if (refs.length === 0) {
|
|
98
|
+
throw new ArazzoParserError(`Step "${step.stepId}" must specify operationId, operationPath, or workflowId`, filePath, `workflowId: ${workflowId}`);
|
|
99
|
+
}
|
|
100
|
+
if (refs.length > 1) {
|
|
101
|
+
throw new ArazzoParserError(`Step "${step.stepId}" must specify only one of operationId, operationPath, or workflowId`, filePath, `workflowId: ${workflowId}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// ─── Source Resolution ───
|
|
105
|
+
function resolveSourceDescriptions(doc, filePath) {
|
|
106
|
+
const dir = dirname(filePath);
|
|
107
|
+
return doc.sourceDescriptions.map((sd) => {
|
|
108
|
+
// If it's a relative path, resolve against the arazzo file's directory
|
|
109
|
+
const absolutePath = sd.url.startsWith('http')
|
|
110
|
+
? sd.url
|
|
111
|
+
: resolve(dir, sd.url);
|
|
112
|
+
return {
|
|
113
|
+
name: sd.name,
|
|
114
|
+
absolutePath,
|
|
115
|
+
type: sd.type,
|
|
116
|
+
};
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
// ─── Utility Extractors ───
|
|
120
|
+
/**
|
|
121
|
+
* Extract all unique operationIds referenced across all workflows in a document.
|
|
122
|
+
*/
|
|
123
|
+
export function extractOperationIds(doc) {
|
|
124
|
+
const ids = new Set();
|
|
125
|
+
for (const workflow of doc.workflows) {
|
|
126
|
+
for (const step of workflow.steps) {
|
|
127
|
+
if (step.operationId) {
|
|
128
|
+
ids.add(step.operationId);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return Array.from(ids);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Extract all runtime expressions used in a workflow's outputs and step outputs.
|
|
136
|
+
*/
|
|
137
|
+
export function extractExpressions(workflow) {
|
|
138
|
+
const exprs = [];
|
|
139
|
+
// Workflow-level outputs
|
|
140
|
+
if (workflow.outputs) {
|
|
141
|
+
exprs.push(...Object.values(workflow.outputs));
|
|
142
|
+
}
|
|
143
|
+
// Step-level outputs
|
|
144
|
+
for (const step of workflow.steps) {
|
|
145
|
+
if (step.outputs) {
|
|
146
|
+
exprs.push(...Object.values(step.outputs));
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return exprs;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Get the source name and operation name from a qualified operationId.
|
|
153
|
+
* e.g., "resourceServer.create-incoming-payment" → ["resourceServer", "create-incoming-payment"]
|
|
154
|
+
*/
|
|
155
|
+
export function splitOperationId(operationId) {
|
|
156
|
+
const dotIndex = operationId.indexOf('.');
|
|
157
|
+
if (dotIndex === -1) {
|
|
158
|
+
return ['', operationId];
|
|
159
|
+
}
|
|
160
|
+
return [operationId.substring(0, dotIndex), operationId.substring(dotIndex + 1)];
|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definitions
|
|
3
|
+
*
|
|
4
|
+
* Typed interfaces for the complete Arazzo spec, used by the parser
|
|
5
|
+
* and code generator.
|
|
6
|
+
*
|
|
7
|
+
* @see https://spec.openapis.org/arazzo/v1.0.1
|
|
8
|
+
*/
|
|
9
|
+
export interface ArazzoDocument {
|
|
10
|
+
arazzo: string;
|
|
11
|
+
info: InfoObject;
|
|
12
|
+
sourceDescriptions: SourceDescription[];
|
|
13
|
+
workflows: WorkflowObject[];
|
|
14
|
+
components?: ComponentsObject;
|
|
15
|
+
}
|
|
16
|
+
export interface InfoObject {
|
|
17
|
+
title: string;
|
|
18
|
+
summary?: string;
|
|
19
|
+
description?: string;
|
|
20
|
+
version: string;
|
|
21
|
+
}
|
|
22
|
+
export interface SourceDescription {
|
|
23
|
+
name: string;
|
|
24
|
+
url: string;
|
|
25
|
+
type: 'openapi' | 'arazzo';
|
|
26
|
+
}
|
|
27
|
+
export interface WorkflowObject {
|
|
28
|
+
workflowId: string;
|
|
29
|
+
summary?: string;
|
|
30
|
+
description?: string;
|
|
31
|
+
inputs?: JsonSchemaObject;
|
|
32
|
+
parameters?: ParameterObject[];
|
|
33
|
+
steps: StepObject[];
|
|
34
|
+
outputs?: Record<string, string>;
|
|
35
|
+
successActions?: ActionObject[];
|
|
36
|
+
failureActions?: ActionObject[];
|
|
37
|
+
}
|
|
38
|
+
export interface StepObject {
|
|
39
|
+
stepId: string;
|
|
40
|
+
description?: string;
|
|
41
|
+
operationId?: string;
|
|
42
|
+
operationPath?: string;
|
|
43
|
+
workflowId?: string;
|
|
44
|
+
parameters?: ParameterObject[];
|
|
45
|
+
requestBody?: RequestBodyObject;
|
|
46
|
+
successCriteria?: SuccessCriterionObject[];
|
|
47
|
+
successActions?: ActionObject[];
|
|
48
|
+
failureActions?: ActionObject[];
|
|
49
|
+
outputs?: Record<string, string>;
|
|
50
|
+
}
|
|
51
|
+
export interface ParameterObject {
|
|
52
|
+
name: string;
|
|
53
|
+
in: 'path' | 'query' | 'header' | 'cookie' | 'body';
|
|
54
|
+
value: unknown;
|
|
55
|
+
}
|
|
56
|
+
export interface RequestBodyObject {
|
|
57
|
+
contentType?: string;
|
|
58
|
+
payload: Record<string, unknown>;
|
|
59
|
+
replacements?: PayloadReplacement[];
|
|
60
|
+
}
|
|
61
|
+
export interface PayloadReplacement {
|
|
62
|
+
target: string;
|
|
63
|
+
value: unknown;
|
|
64
|
+
}
|
|
65
|
+
export interface SuccessCriterionObject {
|
|
66
|
+
condition: string;
|
|
67
|
+
context?: string;
|
|
68
|
+
type?: 'simple' | 'regex' | 'jsonpath' | 'xpath';
|
|
69
|
+
}
|
|
70
|
+
export interface ActionObject {
|
|
71
|
+
name: string;
|
|
72
|
+
type: 'goto' | 'end';
|
|
73
|
+
workflowId?: string;
|
|
74
|
+
stepId?: string;
|
|
75
|
+
criteria?: CriterionObject[];
|
|
76
|
+
}
|
|
77
|
+
export interface CriterionObject {
|
|
78
|
+
condition: string;
|
|
79
|
+
context?: string;
|
|
80
|
+
type?: 'simple' | 'regex' | 'jsonpath' | 'xpath';
|
|
81
|
+
}
|
|
82
|
+
export interface ComponentsObject {
|
|
83
|
+
inputs?: Record<string, JsonSchemaObject>;
|
|
84
|
+
parameters?: Record<string, ParameterObject>;
|
|
85
|
+
successActions?: Record<string, ActionObject>;
|
|
86
|
+
failureActions?: Record<string, ActionObject>;
|
|
87
|
+
}
|
|
88
|
+
export interface JsonSchemaObject {
|
|
89
|
+
type: 'object' | 'string' | 'integer' | 'number' | 'boolean' | 'array';
|
|
90
|
+
required?: string[];
|
|
91
|
+
properties?: Record<string, JsonSchemaProperty>;
|
|
92
|
+
description?: string;
|
|
93
|
+
}
|
|
94
|
+
export interface JsonSchemaProperty {
|
|
95
|
+
type: 'string' | 'integer' | 'number' | 'boolean' | 'array' | 'object';
|
|
96
|
+
description?: string;
|
|
97
|
+
format?: string;
|
|
98
|
+
items?: JsonSchemaProperty;
|
|
99
|
+
properties?: Record<string, JsonSchemaProperty>;
|
|
100
|
+
required?: string[];
|
|
101
|
+
enum?: unknown[];
|
|
102
|
+
default?: unknown;
|
|
103
|
+
}
|
|
104
|
+
export interface ParsedWorkflow {
|
|
105
|
+
document: ArazzoDocument;
|
|
106
|
+
filePath: string;
|
|
107
|
+
/** Resolved source descriptions with absolute paths */
|
|
108
|
+
resolvedSources: ResolvedSource[];
|
|
109
|
+
}
|
|
110
|
+
export interface ResolvedSource {
|
|
111
|
+
name: string;
|
|
112
|
+
absolutePath: string;
|
|
113
|
+
type: 'openapi' | 'arazzo';
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/parser/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,UAAU,CAAC;IACjB,kBAAkB,EAAE,iBAAiB,EAAE,CAAC;IACxC,SAAS,EAAE,cAAc,EAAE,CAAC;IAC5B,UAAU,CAAC,EAAE,gBAAgB,CAAC;CAC/B;AAID,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;CACjB;AAID,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,SAAS,GAAG,QAAQ,CAAC;CAC5B;AAID,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B,UAAU,CAAC,EAAE,eAAe,EAAE,CAAC;IAC/B,KAAK,EAAE,UAAU,E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,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IAChD,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAID,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,cAAc,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,uDAAuD;IACvD,eAAe,EAAE,cAAc,EAAE,CAAC;CACnC;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,SAAS,GAAG,QAAQ,CAAC;CAC5B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/parser/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Arazzo Runtime Expression Resolver
|
|
3
|
+
*
|
|
4
|
+
* Resolves Arazzo runtime expressions against execution context.
|
|
5
|
+
* Supports the full Arazzo 1.0.1 expression syntax:
|
|
6
|
+
*
|
|
7
|
+
* $inputs.fieldName → workflow input values
|
|
8
|
+
* $steps.stepId.outputs.field → previous step outputs
|
|
9
|
+
* $statusCode → HTTP response status code
|
|
10
|
+
* $response.body → full response body
|
|
11
|
+
* $response.body.field → nested response body field
|
|
12
|
+
* $response.header.name → response header value
|
|
13
|
+
* $url → request URL
|
|
14
|
+
* $method → request HTTP method
|
|
15
|
+
*/
|
|
16
|
+
import type { StepResult } from './types.js';
|
|
17
|
+
export interface ExpressionContext {
|
|
18
|
+
/** Workflow inputs */
|
|
19
|
+
inputs: Record<string, unknown>;
|
|
20
|
+
/** Completed step results, keyed by stepId */
|
|
21
|
+
steps: Record<string, StepResult>;
|
|
22
|
+
/** Current step's response (available during output resolution) */
|
|
23
|
+
currentResponse?: {
|
|
24
|
+
status: number;
|
|
25
|
+
headers: Record<string, string>;
|
|
26
|
+
body: unknown;
|
|
27
|
+
};
|
|
28
|
+
/** Current request info */
|
|
29
|
+
currentRequest?: {
|
|
30
|
+
url: string;
|
|
31
|
+
method: string;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Resolve an Arazzo runtime expression against the given context.
|
|
36
|
+
*
|
|
37
|
+
* @param expression - The expression string (e.g., "$inputs.amount")
|
|
38
|
+
* @param context - The current execution context
|
|
39
|
+
* @returns The resolved value
|
|
40
|
+
*/
|
|
41
|
+
export declare function resolveExpression(expression: string, context: ExpressionContext): unknown;
|
|
42
|
+
/**
|
|
43
|
+
* Deep-resolve all expressions in an object/value tree.
|
|
44
|
+
* Walks arrays and objects recursively, resolving any string that starts with $.
|
|
45
|
+
*/
|
|
46
|
+
export declare function resolveDeep(value: unknown, context: ExpressionContext): unknown;
|
|
47
|
+
/**
|
|
48
|
+
* Check if a string contains an Arazzo runtime expression.
|
|
49
|
+
*/
|
|
50
|
+
export declare function isExpression(value: unknown): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Extract all expression references from a value tree.
|
|
53
|
+
*/
|
|
54
|
+
export declare function extractExpressionRefs(value: unknown): string[];
|
|
55
|
+
export declare class ExpressionError extends Error {
|
|
56
|
+
expression: string;
|
|
57
|
+
constructor(message: string, expression: string);
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=expression-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expression-resolver.d.ts","sourceRoot":"","sources":["../../src/runtime/expression-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,MAAM,WAAW,iBAAiB;IAChC,sBAAsB;IACtB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,8CAA8C;IAC9C,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAClC,mEAAmE;IACnE,eAAe,CAAC,EAAE;QAChB,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAChC,IAAI,EAAE,OAAO,CAAC;KACf,CAAC;IACF,2BAA2B;IAC3B,cAAc,CAAC,EAAE;QACf,GAAG,EAAE,MAAM,CAAC;QACZ,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAgCT;AAED;;;GAGG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAkBT;AAiHD;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAEpD;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,EAAE,CAgB9D;AAED,qBAAa,eAAgB,SAAQ,KAAK;IAG/B,UAAU,EAAE,MAAM;gBADzB,OAAO,EAAE,MAAM,EACR,UAAU,EAAE,MAAM;CAK5B"}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Arazzo Runtime Expression Resolver
|
|
3
|
+
*
|
|
4
|
+
* Resolves Arazzo runtime expressions against execution context.
|
|
5
|
+
* Supports the full Arazzo 1.0.1 expression syntax:
|
|
6
|
+
*
|
|
7
|
+
* $inputs.fieldName → workflow input values
|
|
8
|
+
* $steps.stepId.outputs.field → previous step outputs
|
|
9
|
+
* $statusCode → HTTP response status code
|
|
10
|
+
* $response.body → full response body
|
|
11
|
+
* $response.body.field → nested response body field
|
|
12
|
+
* $response.header.name → response header value
|
|
13
|
+
* $url → request URL
|
|
14
|
+
* $method → request HTTP method
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Resolve an Arazzo runtime expression against the given context.
|
|
18
|
+
*
|
|
19
|
+
* @param expression - The expression string (e.g., "$inputs.amount")
|
|
20
|
+
* @param context - The current execution context
|
|
21
|
+
* @returns The resolved value
|
|
22
|
+
*/
|
|
23
|
+
export function resolveExpression(expression, context) {
|
|
24
|
+
// Not a runtime expression — return as literal
|
|
25
|
+
if (typeof expression !== 'string' || !expression.startsWith('$')) {
|
|
26
|
+
return expression;
|
|
27
|
+
}
|
|
28
|
+
const parts = expression.split('.');
|
|
29
|
+
const root = parts[0];
|
|
30
|
+
switch (root) {
|
|
31
|
+
case '$inputs':
|
|
32
|
+
return resolveInputExpression(parts, context);
|
|
33
|
+
case '$steps':
|
|
34
|
+
return resolveStepExpression(parts, context);
|
|
35
|
+
case '$statusCode':
|
|
36
|
+
return context.currentResponse?.status;
|
|
37
|
+
case '$response':
|
|
38
|
+
return resolveResponseExpression(parts, context);
|
|
39
|
+
case '$url':
|
|
40
|
+
return context.currentRequest?.url;
|
|
41
|
+
case '$method':
|
|
42
|
+
return context.currentRequest?.method;
|
|
43
|
+
default:
|
|
44
|
+
// Not a recognized expression, return as-is
|
|
45
|
+
return expression;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Deep-resolve all expressions in an object/value tree.
|
|
50
|
+
* Walks arrays and objects recursively, resolving any string that starts with $.
|
|
51
|
+
*/
|
|
52
|
+
export function resolveDeep(value, context) {
|
|
53
|
+
if (typeof value === 'string') {
|
|
54
|
+
return resolveExpression(value, context);
|
|
55
|
+
}
|
|
56
|
+
if (Array.isArray(value)) {
|
|
57
|
+
return value.map((item) => resolveDeep(item, context));
|
|
58
|
+
}
|
|
59
|
+
if (value !== null && typeof value === 'object') {
|
|
60
|
+
const resolved = {};
|
|
61
|
+
for (const [key, val] of Object.entries(value)) {
|
|
62
|
+
resolved[key] = resolveDeep(val, context);
|
|
63
|
+
}
|
|
64
|
+
return resolved;
|
|
65
|
+
}
|
|
66
|
+
return value;
|
|
67
|
+
}
|
|
68
|
+
// ─── Internal Resolvers ───
|
|
69
|
+
function resolveInputExpression(parts, context) {
|
|
70
|
+
// $inputs.fieldName → context.inputs[fieldName]
|
|
71
|
+
if (parts.length < 2) {
|
|
72
|
+
return context.inputs;
|
|
73
|
+
}
|
|
74
|
+
return getNestedValue(context.inputs, parts.slice(1));
|
|
75
|
+
}
|
|
76
|
+
function resolveStepExpression(parts, context) {
|
|
77
|
+
// $steps.stepId.outputs.fieldName
|
|
78
|
+
if (parts.length < 2) {
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
const stepId = parts[1];
|
|
82
|
+
const stepResult = context.steps[stepId];
|
|
83
|
+
if (!stepResult) {
|
|
84
|
+
throw new ExpressionError(`Step "${stepId}" not found in context. Available: [${Object.keys(context.steps).join(', ')}]`, parts.join('.'));
|
|
85
|
+
}
|
|
86
|
+
if (parts.length === 2) {
|
|
87
|
+
return stepResult;
|
|
88
|
+
}
|
|
89
|
+
// $steps.stepId.outputs
|
|
90
|
+
if (parts[2] === 'outputs') {
|
|
91
|
+
if (parts.length === 3) {
|
|
92
|
+
return stepResult.outputs;
|
|
93
|
+
}
|
|
94
|
+
return getNestedValue(stepResult.outputs, parts.slice(3));
|
|
95
|
+
}
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
function resolveResponseExpression(parts, context) {
|
|
99
|
+
if (!context.currentResponse) {
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
if (parts.length === 1) {
|
|
103
|
+
return context.currentResponse;
|
|
104
|
+
}
|
|
105
|
+
const section = parts[1];
|
|
106
|
+
switch (section) {
|
|
107
|
+
case 'body': {
|
|
108
|
+
if (parts.length === 2) {
|
|
109
|
+
return context.currentResponse.body;
|
|
110
|
+
}
|
|
111
|
+
return getNestedValue(context.currentResponse.body, parts.slice(2));
|
|
112
|
+
}
|
|
113
|
+
case 'header': {
|
|
114
|
+
if (parts.length < 3) {
|
|
115
|
+
return context.currentResponse.headers;
|
|
116
|
+
}
|
|
117
|
+
const headerName = parts[2].toLowerCase();
|
|
118
|
+
// Case-insensitive header lookup
|
|
119
|
+
for (const [key, val] of Object.entries(context.currentResponse.headers)) {
|
|
120
|
+
if (key.toLowerCase() === headerName) {
|
|
121
|
+
return val;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
default:
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
// ─── Utilities ───
|
|
131
|
+
function getNestedValue(obj, path) {
|
|
132
|
+
let current = obj;
|
|
133
|
+
for (const key of path) {
|
|
134
|
+
if (current === null || current === undefined) {
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
if (typeof current === 'object') {
|
|
138
|
+
current = current[key];
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
return undefined;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return current;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Check if a string contains an Arazzo runtime expression.
|
|
148
|
+
*/
|
|
149
|
+
export function isExpression(value) {
|
|
150
|
+
return typeof value === 'string' && value.startsWith('$');
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Extract all expression references from a value tree.
|
|
154
|
+
*/
|
|
155
|
+
export function extractExpressionRefs(value) {
|
|
156
|
+
const refs = [];
|
|
157
|
+
if (typeof value === 'string' && value.startsWith('$')) {
|
|
158
|
+
refs.push(value);
|
|
159
|
+
}
|
|
160
|
+
else if (Array.isArray(value)) {
|
|
161
|
+
for (const item of value) {
|
|
162
|
+
refs.push(...extractExpressionRefs(item));
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
else if (value !== null && typeof value === 'object') {
|
|
166
|
+
for (const val of Object.values(value)) {
|
|
167
|
+
refs.push(...extractExpressionRefs(val));
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return refs;
|
|
171
|
+
}
|
|
172
|
+
export class ExpressionError extends Error {
|
|
173
|
+
expression;
|
|
174
|
+
constructor(message, expression) {
|
|
175
|
+
super(`[ExpressionResolver] ${message} (expression: ${expression})`);
|
|
176
|
+
this.expression = expression;
|
|
177
|
+
this.name = 'ExpressionError';
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
//# sourceMappingURL=expression-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expression-resolver.js","sourceRoot":"","sources":["../../src/runtime/expression-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAsBH;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAC/B,UAAkB,EAClB,OAA0B;IAE1B,+CAA+C;IAC/C,IAAI,OAAO,UAAU,KAAK,QAAQ,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAClE,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACpC,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;IAEtB,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,SAAS;YACZ,OAAO,sBAAsB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAEhD,KAAK,QAAQ;YACX,OAAO,qBAAqB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAE/C,KAAK,aAAa;YAChB,OAAO,OAAO,CAAC,eAAe,EAAE,MAAM,CAAC;QAEzC,KAAK,WAAW;YACd,OAAO,yBAAyB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAEnD,KAAK,MAAM;YACT,OAAO,OAAO,CAAC,cAAc,EAAE,GAAG,CAAC;QAErC,KAAK,SAAS;YACZ,OAAO,OAAO,CAAC,cAAc,EAAE,MA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