@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/CHANGELOG.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0 (2025-04-02)
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
- **Parser**: Full Arazzo 1.0.1 YAML parser with validation
|
|
8
|
+
- **Runtime Executor**: Execute workflows with dynamic token passing, interactive grant handling, and dynamic server URL resolution
|
|
9
|
+
- **Code Generator**: Generate typed TypeScript SDK from Arazzo specs
|
|
10
|
+
- **CLI**: `generate`, `validate`, and `inspect` commands
|
|
11
|
+
- **GNAP Integration**: Automatic token capture and injection for Open Payments workflows
|
|
12
|
+
- **Interactive Grants**: Pause/resume support for GNAP consent flows
|
|
13
|
+
- **Dynamic Discovery**: Wallet address resolution auto-updates server URLs
|
package/README.md
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
# @flarcos/arazzo-sdk
|
|
2
|
+
|
|
3
|
+
Parse [Arazzo 1.0.1](https://spec.openapis.org/arazzo/v1.0.1) workflow specifications and generate typed TypeScript SDKs for the [Open Payments API](https://openpayments.dev).
|
|
4
|
+
|
|
5
|
+
**Turn 9 sequential API calls into one function call:**
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { OpenPaymentsClient } from '@flarcos/arazzo-sdk/generated';
|
|
9
|
+
|
|
10
|
+
const client = new OpenPaymentsClient({
|
|
11
|
+
serverUrls: {
|
|
12
|
+
walletAddressServer: 'https://wallet.example.com',
|
|
13
|
+
resourceServer: 'https://wallet.example.com',
|
|
14
|
+
authServer: 'https://auth.wallet.example.com',
|
|
15
|
+
},
|
|
16
|
+
gnapConfig: {
|
|
17
|
+
clientWalletAddress: 'https://wallet.example.com/me',
|
|
18
|
+
privateKey: myPrivateKey,
|
|
19
|
+
keyId: 'my-key-id',
|
|
20
|
+
},
|
|
21
|
+
interactionHandler: async ({ redirectUrl }) => {
|
|
22
|
+
// Redirect user for consent, return the interact_ref
|
|
23
|
+
return await redirectUserForConsent(redirectUrl);
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const payment = await client.oneTimePaymentFixedReceive({
|
|
28
|
+
recipientWalletAddressUrl: 'https://wallet.example.com/alice',
|
|
29
|
+
senderWalletAddressUrl: 'https://wallet.example.com/bob',
|
|
30
|
+
amount: '2500',
|
|
31
|
+
assetCode: 'USD',
|
|
32
|
+
assetScale: 2,
|
|
33
|
+
clientWalletAddress: 'https://wallet.example.com/me',
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
console.log(payment.outgoingPaymentId); // fully typed
|
|
37
|
+
console.log(payment.debitAmount); // { value, assetCode, assetScale }
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Features
|
|
41
|
+
|
|
42
|
+
- **Code Generator** — Parse Arazzo YAML → emit typed TypeScript SDK
|
|
43
|
+
- **Runtime Executor** — Execute workflows dynamically without code generation
|
|
44
|
+
- **CLI Tool** — `generate`, `validate`, and `inspect` commands
|
|
45
|
+
- **Dynamic Token Passing** — Automatically captures GNAP tokens from grant steps and injects them into subsequent resource server calls
|
|
46
|
+
- **Interactive Grant Handling** — Pauses for user consent on interactive grants, then resumes automatically
|
|
47
|
+
- **Dynamic Server Discovery** — Resolves `authServer` and `resourceServer` URLs from wallet address lookups
|
|
48
|
+
- **GNAP Integration** — Wires up [`@flarcos/kiota-authentication-gnap`](../kiota-authentication-gnap) for RFC 9635 auth
|
|
49
|
+
|
|
50
|
+
## Installation
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
npm install @flarcos/arazzo-sdk
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## CLI Usage
|
|
57
|
+
|
|
58
|
+
### Generate SDK
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
# Generate typed TypeScript SDK from Arazzo workflow files
|
|
62
|
+
arazzo-sdk generate -i "arazzo/*.arazzo.yaml" -o src/generated/
|
|
63
|
+
|
|
64
|
+
# Generate types only (no client class)
|
|
65
|
+
arazzo-sdk generate -i "arazzo/*.arazzo.yaml" -o src/generated/ --types-only
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Validate
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
# Validate Arazzo files for spec compliance
|
|
72
|
+
arazzo-sdk validate -i "arazzo/*.arazzo.yaml"
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Inspect
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
# Display workflow structure, inputs, steps, and outputs
|
|
79
|
+
arazzo-sdk inspect -i "arazzo/one-time-payment-fixed-receive.arazzo.yaml"
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Output:
|
|
83
|
+
```
|
|
84
|
+
📄 Open Payments — One-Time Payment (Fixed Receive) (v1.0.0)
|
|
85
|
+
Arazzo: 1.0.1
|
|
86
|
+
Sources: walletAddressServer, resourceServer, authServer
|
|
87
|
+
|
|
88
|
+
📋 Workflow: oneTimePaymentFixedReceive
|
|
89
|
+
Inputs:
|
|
90
|
+
- recipientWalletAddressUrl: string (required)
|
|
91
|
+
- senderWalletAddressUrl: string (required)
|
|
92
|
+
- amount: string (required)
|
|
93
|
+
...
|
|
94
|
+
Steps:
|
|
95
|
+
getRecipientWalletAddress → walletAddressServer.get-wallet-address
|
|
96
|
+
requestIncomingPaymentGrant → authServer.post-request
|
|
97
|
+
createIncomingPayment → resourceServer.create-incoming-payment
|
|
98
|
+
...
|
|
99
|
+
Outputs:
|
|
100
|
+
- outgoingPaymentId: $steps.createOutgoingPayment.outputs.outgoingPaymentId
|
|
101
|
+
- debitAmount: $steps.createQuote.outputs.debitAmount
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Generated Workflows
|
|
105
|
+
|
|
106
|
+
| Method | Description | Steps |
|
|
107
|
+
|--------|-------------|-------|
|
|
108
|
+
| `oneTimePaymentFixedReceive()` | Fixed receive amount payment | 9 |
|
|
109
|
+
| `oneTimePaymentFixedSend()` | Fixed send amount payment | 9 |
|
|
110
|
+
| `setupRecurringPayment()` | Recurring payment with interval limits | 9 |
|
|
111
|
+
| `listIncomingPayments()` | Paginated incoming payment listing | 3 |
|
|
112
|
+
| `listOutgoingPayments()` | Paginated outgoing payment listing | 3 |
|
|
113
|
+
| `getPaymentDetails()` | Get specific payment details | 4 |
|
|
114
|
+
| `rotateAccessToken()` | Rotate a GNAP access token | 1 |
|
|
115
|
+
| `revokeAccessToken()` | Revoke a GNAP access token | 1 |
|
|
116
|
+
| `cancelGrant()` | Cancel an active grant | 1 |
|
|
117
|
+
|
|
118
|
+
## Programmatic API
|
|
119
|
+
|
|
120
|
+
### Parser
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
import { parseArazzoFile, extractOperationIds } from '@flarcos/arazzo-sdk';
|
|
124
|
+
|
|
125
|
+
const parsed = parseArazzoFile('arazzo/one-time-payment-fixed-receive.arazzo.yaml');
|
|
126
|
+
|
|
127
|
+
console.log(parsed.document.workflows[0].workflowId);
|
|
128
|
+
// → 'oneTimePaymentFixedReceive'
|
|
129
|
+
|
|
130
|
+
const opIds = extractOperationIds(parsed.document);
|
|
131
|
+
// → ['walletAddressServer.get-wallet-address', 'authServer.post-request', ...]
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Runtime Executor
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
import { executeWorkflow } from '@flarcos/arazzo-sdk';
|
|
138
|
+
|
|
139
|
+
const result = await executeWorkflow(workflow, {
|
|
140
|
+
inputs: { recipientWalletAddressUrl: '...', amount: '2500' },
|
|
141
|
+
serverUrls: {
|
|
142
|
+
walletAddressServer: 'https://wallet.example.com',
|
|
143
|
+
resourceServer: 'https://wallet.example.com',
|
|
144
|
+
authServer: 'https://auth.wallet.example.com',
|
|
145
|
+
},
|
|
146
|
+
interactionHandler: async ({ redirectUrl }) => {
|
|
147
|
+
return await getConsentFromUser(redirectUrl);
|
|
148
|
+
},
|
|
149
|
+
hooks: {
|
|
150
|
+
beforeStep: (stepId, request) => {
|
|
151
|
+
console.log(`→ ${stepId}: ${request.method} ${request.url}`);
|
|
152
|
+
},
|
|
153
|
+
afterStep: (stepId, result) => {
|
|
154
|
+
console.log(`← ${stepId}: ${result.response.status}`);
|
|
155
|
+
},
|
|
156
|
+
onTokenAcquired: (stepId, token, type) => {
|
|
157
|
+
console.log(`🔑 ${stepId}: acquired ${type}`);
|
|
158
|
+
},
|
|
159
|
+
onServerResolved: (stepId, servers) => {
|
|
160
|
+
console.log(`🌐 ${stepId}: resolved`, servers);
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Code Generator
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
import { parseArazzoFiles } from '@flarcos/arazzo-sdk';
|
|
170
|
+
import { generateSDK } from '@flarcos/arazzo-sdk';
|
|
171
|
+
|
|
172
|
+
const parsed = parseArazzoFiles(['workflow1.arazzo.yaml', 'workflow2.arazzo.yaml']);
|
|
173
|
+
|
|
174
|
+
generateSDK(parsed, {
|
|
175
|
+
outputDir: 'src/generated',
|
|
176
|
+
className: 'MyPaymentsClient',
|
|
177
|
+
});
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## How Token Passing Works
|
|
181
|
+
|
|
182
|
+
The executor automatically manages GNAP tokens across steps:
|
|
183
|
+
|
|
184
|
+
```
|
|
185
|
+
Step 2: requestIncomingPaymentGrant (authServer)
|
|
186
|
+
→ Response: { access_token: { value: "tok_abc" } }
|
|
187
|
+
→ Executor captures "tok_abc" as current token
|
|
188
|
+
|
|
189
|
+
Step 3: createIncomingPayment (resourceServer)
|
|
190
|
+
→ Executor injects: Authorization: GNAP tok_abc
|
|
191
|
+
→ Token used automatically, no manual wiring needed
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
Token capture triggers on any step output matching `*AccessToken` or `accessToken`.
|
|
195
|
+
|
|
196
|
+
## How Interactive Grants Work
|
|
197
|
+
|
|
198
|
+
When a step returns `interact.redirect`, the executor pauses:
|
|
199
|
+
|
|
200
|
+
```
|
|
201
|
+
Step 7: requestOutgoingPaymentGrant (authServer)
|
|
202
|
+
→ Response: { interact: { redirect: "https://auth.example.com/consent/..." } }
|
|
203
|
+
→ Executor calls your interactionHandler(redirectUrl)
|
|
204
|
+
→ You redirect the user, collect consent, return interact_ref
|
|
205
|
+
→ Executor stores interact_ref and continues
|
|
206
|
+
|
|
207
|
+
Step 8: continueOutgoingPaymentGrant (authServer)
|
|
208
|
+
→ Executor injects interact_ref into the request body
|
|
209
|
+
→ Grant finalized, outgoing payment token acquired
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## How Dynamic Server Resolution Works
|
|
213
|
+
|
|
214
|
+
Wallet address resolution steps automatically update server URLs:
|
|
215
|
+
|
|
216
|
+
```
|
|
217
|
+
Step 1: getRecipientWalletAddress (walletAddressServer)
|
|
218
|
+
→ Response: { authServer: "https://auth.recipient.com", resourceServer: "https://rs.recipient.com" }
|
|
219
|
+
→ Executor updates serverUrls.authServer and serverUrls.resourceServer
|
|
220
|
+
→ All subsequent steps use the discovered URLs
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
## Project Structure
|
|
224
|
+
|
|
225
|
+
```
|
|
226
|
+
arazzo-sdk/
|
|
227
|
+
├── src/
|
|
228
|
+
│ ├── index.ts # Public exports
|
|
229
|
+
│ ├── cli.ts # CLI entry point
|
|
230
|
+
│ ├── parser/
|
|
231
|
+
│ │ ├── types.ts # Arazzo 1.0.1 type definitions
|
|
232
|
+
│ │ └── arazzo-parser.ts # YAML → typed AST
|
|
233
|
+
│ ├── generator/
|
|
234
|
+
│ │ ├── type-mapper.ts # JSON Schema → TypeScript
|
|
235
|
+
│ │ ├── templates.ts # Code generation templates
|
|
236
|
+
│ │ └── codegen.ts # AST → TypeScript source
|
|
237
|
+
│ ├── runtime/
|
|
238
|
+
│ │ ├── types.ts # Runtime types
|
|
239
|
+
│ │ ├── expression-resolver.ts # $inputs, $steps, $response
|
|
240
|
+
│ │ ├── http-client.ts # Fetch + GNAP auth
|
|
241
|
+
│ │ └── workflow-executor.ts # Step execution engine
|
|
242
|
+
│ └── generated/
|
|
243
|
+
│ └── open-payments-client.ts # Generated SDK
|
|
244
|
+
└── test/
|
|
245
|
+
├── parser.test.ts
|
|
246
|
+
├── expression-resolver.test.ts
|
|
247
|
+
└── codegen.test.ts
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
## License
|
|
251
|
+
|
|
252
|
+
Apache-2.0
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Arazzo SDK CLI
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* arazzo-sdk generate --input <glob> --output <dir> [--class-name <name>]
|
|
7
|
+
* arazzo-sdk validate --input <glob>
|
|
8
|
+
* arazzo-sdk inspect --input <file>
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=cli.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA;;;;;;;GAOG"}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Arazzo SDK CLI
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* arazzo-sdk generate --input <glob> --output <dir> [--class-name <name>]
|
|
7
|
+
* arazzo-sdk validate --input <glob>
|
|
8
|
+
* arazzo-sdk inspect --input <file>
|
|
9
|
+
*/
|
|
10
|
+
import { parseArgs } from 'node:util';
|
|
11
|
+
import { glob } from 'glob';
|
|
12
|
+
import { parseArazzoFile, extractOperationIds } from './parser/arazzo-parser.js';
|
|
13
|
+
import { generateSDK, generateTypes } from './generator/codegen.js';
|
|
14
|
+
const { values, positionals } = parseArgs({
|
|
15
|
+
args: process.argv.slice(2),
|
|
16
|
+
options: {
|
|
17
|
+
input: { type: 'string', short: 'i' },
|
|
18
|
+
output: { type: 'string', short: 'o' },
|
|
19
|
+
'class-name': { type: 'string' },
|
|
20
|
+
'types-only': { type: 'boolean' },
|
|
21
|
+
help: { type: 'boolean', short: 'h' },
|
|
22
|
+
},
|
|
23
|
+
allowPositionals: true,
|
|
24
|
+
strict: false,
|
|
25
|
+
});
|
|
26
|
+
const command = positionals[0] || 'help';
|
|
27
|
+
async function main() {
|
|
28
|
+
switch (command) {
|
|
29
|
+
case 'generate':
|
|
30
|
+
await runGenerate();
|
|
31
|
+
break;
|
|
32
|
+
case 'validate':
|
|
33
|
+
await runValidate();
|
|
34
|
+
break;
|
|
35
|
+
case 'inspect':
|
|
36
|
+
await runInspect();
|
|
37
|
+
break;
|
|
38
|
+
case 'help':
|
|
39
|
+
default:
|
|
40
|
+
printHelp();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// ─── Generate Command ───
|
|
44
|
+
async function runGenerate() {
|
|
45
|
+
const inputGlob = values.input;
|
|
46
|
+
const outputDir = values.output;
|
|
47
|
+
if (!inputGlob || !outputDir) {
|
|
48
|
+
console.error('Error: --input and --output are required for generate');
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
const files = await glob(inputGlob);
|
|
52
|
+
if (files.length === 0) {
|
|
53
|
+
console.error(`Error: No files matched pattern "${inputGlob}"`);
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
console.log(`📋 Parsing ${files.length} Arazzo file(s)...`);
|
|
57
|
+
const parsed = [];
|
|
58
|
+
for (const file of files) {
|
|
59
|
+
try {
|
|
60
|
+
const result = parseArazzoFile(file);
|
|
61
|
+
console.log(` ✅ ${file} — ${result.document.workflows.length} workflow(s)`);
|
|
62
|
+
parsed.push(result);
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
console.error(` ❌ ${file}: ${error instanceof Error ? error.message : error}`);
|
|
66
|
+
process.exit(1);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const className = values['class-name'] || 'OpenPaymentsClient';
|
|
70
|
+
const typesOnly = values['types-only'];
|
|
71
|
+
console.log(`\n⚡ Generating ${typesOnly ? 'types' : 'SDK'}...`);
|
|
72
|
+
if (typesOnly) {
|
|
73
|
+
generateTypes(parsed, { outputDir, className });
|
|
74
|
+
console.log(` 📦 Types written to ${outputDir}/types.ts`);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
generateSDK(parsed, { outputDir, className });
|
|
78
|
+
console.log(` 📦 SDK written to ${outputDir}/open-payments-client.ts`);
|
|
79
|
+
}
|
|
80
|
+
// Count totals
|
|
81
|
+
let totalWorkflows = 0;
|
|
82
|
+
let totalSteps = 0;
|
|
83
|
+
for (const p of parsed) {
|
|
84
|
+
for (const w of p.document.workflows) {
|
|
85
|
+
totalWorkflows++;
|
|
86
|
+
totalSteps += w.steps.length;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
console.log(`\n✨ Generated ${totalWorkflows} workflow(s), ${totalSteps} step(s)`);
|
|
90
|
+
}
|
|
91
|
+
// ─── Validate Command ───
|
|
92
|
+
async function runValidate() {
|
|
93
|
+
const inputGlob = values.input;
|
|
94
|
+
if (!inputGlob) {
|
|
95
|
+
console.error('Error: --input is required for validate');
|
|
96
|
+
process.exit(1);
|
|
97
|
+
}
|
|
98
|
+
const files = await glob(inputGlob);
|
|
99
|
+
if (files.length === 0) {
|
|
100
|
+
console.error(`Error: No files matched pattern "${inputGlob}"`);
|
|
101
|
+
process.exit(1);
|
|
102
|
+
}
|
|
103
|
+
console.log(`🔍 Validating ${files.length} Arazzo file(s)...\n`);
|
|
104
|
+
let hasErrors = false;
|
|
105
|
+
for (const file of files) {
|
|
106
|
+
try {
|
|
107
|
+
const result = parseArazzoFile(file);
|
|
108
|
+
const workflowCount = result.document.workflows.length;
|
|
109
|
+
const stepCount = result.document.workflows.reduce((acc, w) => acc + w.steps.length, 0);
|
|
110
|
+
console.log(` ✅ ${file} — v${result.document.arazzo}, ${workflowCount} workflow(s), ${stepCount} step(s)`);
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
hasErrors = true;
|
|
114
|
+
console.error(` ❌ ${file}: ${error instanceof Error ? error.message : error}`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (hasErrors) {
|
|
118
|
+
console.error('\n❌ Validation failed');
|
|
119
|
+
process.exit(1);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
console.log('\n✅ All files valid');
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
// ─── Inspect Command ───
|
|
126
|
+
async function runInspect() {
|
|
127
|
+
const inputGlob = values.input;
|
|
128
|
+
if (!inputGlob) {
|
|
129
|
+
console.error('Error: --input is required for inspect');
|
|
130
|
+
process.exit(1);
|
|
131
|
+
}
|
|
132
|
+
const files = await glob(inputGlob);
|
|
133
|
+
if (files.length === 0) {
|
|
134
|
+
console.error(`Error: No files matched pattern "${inputGlob}"`);
|
|
135
|
+
process.exit(1);
|
|
136
|
+
}
|
|
137
|
+
for (const file of files) {
|
|
138
|
+
try {
|
|
139
|
+
const result = parseArazzoFile(file);
|
|
140
|
+
const doc = result.document;
|
|
141
|
+
console.log(`\n📄 ${doc.info.title} (v${doc.info.version})`);
|
|
142
|
+
console.log(` Arazzo: ${doc.arazzo}`);
|
|
143
|
+
console.log(` Sources: ${doc.sourceDescriptions.map((s) => s.name).join(', ')}`);
|
|
144
|
+
for (const workflow of doc.workflows) {
|
|
145
|
+
console.log(`\n 📋 Workflow: ${workflow.workflowId}`);
|
|
146
|
+
if (workflow.summary) {
|
|
147
|
+
console.log(` Summary: ${workflow.summary}`);
|
|
148
|
+
}
|
|
149
|
+
// Inputs
|
|
150
|
+
if (workflow.inputs?.properties) {
|
|
151
|
+
const required = workflow.inputs.required || [];
|
|
152
|
+
console.log(' Inputs:');
|
|
153
|
+
for (const [name, prop] of Object.entries(workflow.inputs.properties)) {
|
|
154
|
+
const req = required.includes(name) ? ' (required)' : '';
|
|
155
|
+
console.log(` - ${name}: ${prop.type}${req}`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
// Steps
|
|
159
|
+
console.log(' Steps:');
|
|
160
|
+
for (const step of workflow.steps) {
|
|
161
|
+
const target = step.operationId || step.workflowId || 'unknown';
|
|
162
|
+
console.log(` ${step.stepId} → ${target}`);
|
|
163
|
+
}
|
|
164
|
+
// Outputs
|
|
165
|
+
if (workflow.outputs) {
|
|
166
|
+
console.log(' Outputs:');
|
|
167
|
+
for (const [name, expr] of Object.entries(workflow.outputs)) {
|
|
168
|
+
console.log(` - ${name}: ${expr}`);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
// Operation IDs
|
|
173
|
+
const opIds = extractOperationIds(doc);
|
|
174
|
+
console.log(`\n 🔗 Operation IDs referenced: ${opIds.join(', ')}`);
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
console.error(` ❌ ${file}: ${error instanceof Error ? error.message : error}`);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
// ─── Help ───
|
|
182
|
+
function printHelp() {
|
|
183
|
+
console.log(`
|
|
184
|
+
Arazzo SDK — Generate TypeScript SDKs from Arazzo workflow specifications
|
|
185
|
+
|
|
186
|
+
USAGE:
|
|
187
|
+
arazzo-sdk <command> [options]
|
|
188
|
+
|
|
189
|
+
COMMANDS:
|
|
190
|
+
generate Generate TypeScript SDK from Arazzo files
|
|
191
|
+
validate Validate Arazzo files for correctness
|
|
192
|
+
inspect Display workflow structure and details
|
|
193
|
+
help Show this help message
|
|
194
|
+
|
|
195
|
+
OPTIONS:
|
|
196
|
+
--input, -i Glob pattern for input Arazzo files (required)
|
|
197
|
+
--output, -o Output directory for generated code (generate only)
|
|
198
|
+
--class-name Custom class name (default: OpenPaymentsClient)
|
|
199
|
+
--types-only Generate only TypeScript interfaces, no client class
|
|
200
|
+
--help, -h Show this help message
|
|
201
|
+
|
|
202
|
+
EXAMPLES:
|
|
203
|
+
arazzo-sdk generate -i "arazzo/*.arazzo.yaml" -o src/generated/
|
|
204
|
+
arazzo-sdk validate -i "arazzo/*.arazzo.yaml"
|
|
205
|
+
arazzo-sdk inspect -i "arazzo/one-time-payment-fixed-receive.arazzo.yaml"
|
|
206
|
+
`);
|
|
207
|
+
}
|
|
208
|
+
main().catch((error) => {
|
|
209
|
+
console.error('Fatal error:', error);
|
|
210
|
+
process.exit(1);
|
|
211
|
+
});
|
|
212
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA;;;;;;;GAOG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AACjF,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAGpE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,SAAS,CAAC;IACxC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAC3B,OAAO,EAAE;QACP,KAAK,EAAE,EAAE,I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