@fragment-dev/cli 2026.9.10-2 → 2026.9.10-5

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/README.md CHANGED
@@ -290,7 +290,7 @@ FLAGS
290
290
  DESCRIPTION
291
291
  Generate GraphQL queries from your Schema for your SDK.
292
292
 
293
- This command generates a GraphQL query for each entry type in your ledger Schema.
293
+ This command generates a GraphQL query for each Ledger Entry type and each Payment type in your ledger Schema.
294
294
  Use this command with Fragment SDKs to create type-safe code to update your ledger.
295
295
 
296
296
  EXAMPLES
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  Schema,
3
3
  parseWithError
4
- } from "./chunk-R2HKKBEG.js";
4
+ } from "./chunk-RILSVR74.js";
5
5
  import {
6
6
  formatValidationErrors
7
7
  } from "./chunk-J6HLIC77.js";
@@ -1256,7 +1256,9 @@ mutation CreatePayment(
1256
1256
  payment {
1257
1257
  clientSecret
1258
1258
  ik
1259
- ledgerId
1259
+ ledger {
1260
+ id
1261
+ }
1260
1262
  status
1261
1263
  amount
1262
1264
  type
@@ -27,10 +27,10 @@ import {
27
27
  } from "./chunk-PISSWWTD.js";
28
28
  import {
29
29
  VerifySchema
30
- } from "./chunk-JD2S54X7.js";
30
+ } from "./chunk-BTKJKLCB.js";
31
31
  import {
32
32
  GenGraphQL
33
- } from "./chunk-BQZQLWCT.js";
33
+ } from "./chunk-KJFWVDCE.js";
34
34
  import {
35
35
  GetSchema
36
36
  } from "./chunk-T2BBIXGB.js";
@@ -2,7 +2,7 @@ import {
2
2
  extractSchemaMetadata,
3
3
  isJsonParseError,
4
4
  validateSchemaStructure
5
- } from "./chunk-DJCFTORW.js";
5
+ } from "./chunk-2LCTKBU3.js";
6
6
  import {
7
7
  DEFAULT_SCHEMA_PATH
8
8
  } from "./chunk-A4BSWX5D.js";
@@ -0,0 +1,424 @@
1
+ import {
2
+ BadRequestError,
3
+ CurrencyMatchInputSchema,
4
+ CurrencyModeSchema,
5
+ LedgerAccountTypeSchema,
6
+ ParameterizedString,
7
+ SafeStringSchema,
8
+ assert_default,
9
+ codes,
10
+ getStringParametersInternal,
11
+ z
12
+ } from "./chunk-65EVYD2Y.js";
13
+ import {
14
+ init_cjs_shims
15
+ } from "./chunk-7GH3YGSC.js";
16
+
17
+ // ../../libs/schema-validation/parameterization.ts
18
+ init_cjs_shims();
19
+ var fillParams = (obj, params = {}, options = {
20
+ allowMissing: false,
21
+ allowMissingInChildren: true
22
+ }) => {
23
+ if (typeof obj === "string") {
24
+ const tokens = obj.split(/(\{\{[^{}]+?\}\})/g);
25
+ const missingParams = /* @__PURE__ */ new Set();
26
+ const result = tokens.map((token) => {
27
+ const match = token.match(/\{\{([^{}]+?)\}\}/);
28
+ if (match) {
29
+ const param = match[1];
30
+ const paramValue = params[param];
31
+ if (paramValue === void 0 || paramValue === null) {
32
+ missingParams.add(param);
33
+ return token;
34
+ }
35
+ return paramValue;
36
+ }
37
+ return token;
38
+ }).join("");
39
+ if (!options.allowMissing) {
40
+ assert_default(!missingParams.size, BadRequestError, {
41
+ message: `Failed to fill all parameters: ${obj} -> ${result}`,
42
+ code: codes.parameterization_failed
43
+ });
44
+ }
45
+ return result;
46
+ }
47
+ if (typeof obj === "object" && obj !== null) {
48
+ if (Array.isArray(obj)) {
49
+ return obj.map((value) => fillParams(value, params, options));
50
+ }
51
+ return Object.fromEntries(
52
+ Object.entries(obj).map(([key, value]) => [
53
+ key,
54
+ fillParams(value, params, {
55
+ ...options,
56
+ allowMissing: key === "children" ? options.allowMissingInChildren : options.allowMissing
57
+ })
58
+ ])
59
+ );
60
+ }
61
+ return obj;
62
+ };
63
+ function getSchemaObjectParametersInternal(obj, parameters, includeChildren) {
64
+ if (typeof obj === "string") {
65
+ getStringParametersInternal(obj, parameters);
66
+ } else if (typeof obj === "object") {
67
+ for (const key in obj) {
68
+ if (key !== "templatePath" && (key !== "children" || includeChildren)) {
69
+ getSchemaObjectParametersInternal(
70
+ obj[key],
71
+ parameters,
72
+ includeChildren
73
+ );
74
+ }
75
+ }
76
+ }
77
+ }
78
+ function getSchemaObjectParameters(obj, includeChildren = false) {
79
+ const params = /* @__PURE__ */ new Set();
80
+ getSchemaObjectParametersInternal(obj, params, includeChildren);
81
+ return Array.from(params);
82
+ }
83
+
84
+ // ../../libs/path-utils/path.ts
85
+ init_cjs_shims();
86
+ var getStructuralPath = (path) => {
87
+ return path.split("/").map((part) => part.split(":")[0]).join("/");
88
+ };
89
+ var getInstanceValueByAccountPath = (path) => {
90
+ const parts = path.split("/");
91
+ const result = /* @__PURE__ */ new Map();
92
+ let workingSet = "";
93
+ for (let i = 0; i < parts.length; i++) {
94
+ const part = parts[i];
95
+ const [templateKey, templateValue] = part.split(":");
96
+ workingSet = workingSet ? `${workingSet}/${templateKey}` : templateKey;
97
+ result.set(workingSet, templateValue);
98
+ if (templateValue) {
99
+ workingSet = `${workingSet}:${templateValue}`;
100
+ }
101
+ }
102
+ return result;
103
+ };
104
+ var getSubpaths = (path) => path.split("/").reduce((acc, part) => {
105
+ const prev = acc[acc.length - 1];
106
+ const subPath = prev ? `${prev}/${part}` : part;
107
+ acc.push(subPath);
108
+ return acc;
109
+ }, []);
110
+ var getStructuralSubpaths = (path) => getSubpaths(getStructuralPath(path));
111
+
112
+ // ../../libs/types/tx.ts
113
+ init_cjs_shims();
114
+ var SchemaTxMatchInput = z.object({
115
+ id: z.optional(ParameterizedString),
116
+ externalId: z.optional(ParameterizedString)
117
+ });
118
+ var txTypes = ["credit", "debit"];
119
+ var TxTypeSchema = z.enum(txTypes);
120
+
121
+ // ../../libs/types/schemas.ts
122
+ init_cjs_shims();
123
+ var LedgerMigrationStatusSchema = z.enum([
124
+ "queued",
125
+ "started",
126
+ "failed",
127
+ "completed",
128
+ "skipped"
129
+ ]);
130
+ var SafeRecordKey = z.string().refine((v) => v !== "__proto__", "invalid parameter name");
131
+ var ParametersSchema = z.record(
132
+ SafeRecordKey,
133
+ z.string({
134
+ invalid_type_error: "Invalid parameter type. All parameters must be string-encoded values."
135
+ })
136
+ );
137
+ var EntryParametersSchema = z.record(
138
+ SafeRecordKey,
139
+ z.union([
140
+ z.string({
141
+ invalid_type_error: "Invalid parameter type. Parameters must be string-encoded values or arrays of objects with string values."
142
+ }),
143
+ z.array(z.record(SafeRecordKey, z.string()))
144
+ ])
145
+ );
146
+ var ConsistencyModeSchema = z.enum(["strong", "eventual"]);
147
+ var ConsistencyConfigSchema = (keys, extra) => {
148
+ const v = z.optional(ConsistencyModeSchema);
149
+ const schemaObject = Object.fromEntries(
150
+ keys.map((key) => [key, v])
151
+ );
152
+ return z.object({ ...extra, ...schemaObject });
153
+ };
154
+ var GroupConsistencyConfig = z.object({
155
+ key: SafeStringSchema,
156
+ ownBalanceUpdates: ConsistencyModeSchema
157
+ });
158
+ var AccountConsistencyConfigSchema = z.object({
159
+ lines: z.optional(ConsistencyModeSchema),
160
+ ownBalanceUpdates: z.optional(ConsistencyModeSchema),
161
+ totalBalanceUpdates: z.optional(ConsistencyModeSchema),
162
+ groups: z.optional(z.array(GroupConsistencyConfig))
163
+ });
164
+ var SchemaCurrencyMatchInput = z.object({
165
+ customCurrencyId: z.string().optional(),
166
+ code: z.string()
167
+ });
168
+ var SchemaLinkTypeList = [
169
+ "IncreaseLink",
170
+ "UnitLink",
171
+ "CustomLink",
172
+ "StripeLink"
173
+ ];
174
+ var SchemaLinkType = z.enum(SchemaLinkTypeList);
175
+ var SchemaExternalAccountMatchInput = z.object({
176
+ linkType: SchemaLinkType.optional(),
177
+ id: z.string().optional(),
178
+ externalId: z.string().optional(),
179
+ linkId: z.string().optional()
180
+ });
181
+ var SchemaPaymentInput = z.object({
182
+ enabled: z.boolean()
183
+ });
184
+ var SchemaLedgerEntityStatusSchema = z.enum([
185
+ "active",
186
+ "disabled",
187
+ "archived"
188
+ ]);
189
+ var BaseSchemaLedgerAccountInput = z.lazy(
190
+ () => z.object({
191
+ key: z.string(),
192
+ name: z.string().optional(),
193
+ type: LedgerAccountTypeSchema.optional(),
194
+ currency: SchemaCurrencyMatchInput.optional(),
195
+ currencyMode: CurrencyModeSchema.optional(),
196
+ template: z.boolean().optional(),
197
+ clearing: z.boolean().optional(),
198
+ children: z.array(BaseSchemaLedgerAccountInput).optional(),
199
+ linkedAccount: SchemaExternalAccountMatchInput.optional(),
200
+ payment: SchemaPaymentInput.optional(),
201
+ consistencyConfig: AccountConsistencyConfigSchema.optional(),
202
+ status: SchemaLedgerEntityStatusSchema.optional()
203
+ })
204
+ );
205
+ var BaseChartOfAccounts = z.object({
206
+ defaultConsistencyConfig: AccountConsistencyConfigSchema.optional(),
207
+ defaultCurrency: z.optional(CurrencyMatchInputSchema),
208
+ defaultCurrencyMode: CurrencyModeSchema.optional(),
209
+ accounts: z.array(BaseSchemaLedgerAccountInput)
210
+ });
211
+ var SchemaCondition = z.object({
212
+ ownBalance: z.object({
213
+ eq: z.string().optional(),
214
+ lte: z.string().optional(),
215
+ gte: z.string().optional()
216
+ }).optional(),
217
+ totalBalance: z.object({
218
+ eq: z.string().optional(),
219
+ lte: z.string().optional(),
220
+ gte: z.string().optional()
221
+ }).optional()
222
+ });
223
+ var PostLinesAsSchema = z.enum([
224
+ "raw_lines",
225
+ "net_amounts",
226
+ "skip_zero_lines"
227
+ ]);
228
+ var BaseSchemaLedgerEntryConditionInput = z.object({
229
+ account: z.object({ path: z.string() }).optional(),
230
+ postcondition: SchemaCondition.optional(),
231
+ precondition: SchemaCondition.optional(),
232
+ currency: SchemaCurrencyMatchInput.optional(),
233
+ repeated: z.object({
234
+ key: SafeStringSchema.refine((k) => k.trim().length >= 1, {
235
+ message: "repeated.key cannot be empty"
236
+ })
237
+ }).optional()
238
+ });
239
+ var BaseSchemaLedgerLineTagInput = z.object({
240
+ key: z.string(),
241
+ value: z.string()
242
+ });
243
+ var BaseSchemaLedgerEntryLineInput = z.object({
244
+ account: z.object({ path: z.string() }).optional(),
245
+ amount: z.string().optional(),
246
+ key: z.string(),
247
+ currency: SchemaCurrencyMatchInput.optional(),
248
+ description: z.string().optional(),
249
+ tx: SchemaTxMatchInput.optional(),
250
+ tags: z.array(BaseSchemaLedgerLineTagInput).optional(),
251
+ repeated: z.object({
252
+ key: SafeStringSchema.refine((k) => k.trim().length >= 1, {
253
+ message: "repeated.key cannot be empty"
254
+ })
255
+ }).optional()
256
+ });
257
+ var BaseSchemaLedgerEntryInput = z.object({
258
+ type: z.string(),
259
+ typeVersion: z.number().int().optional(),
260
+ description: z.string().optional(),
261
+ conditions: z.array(BaseSchemaLedgerEntryConditionInput).optional(),
262
+ lines: z.array(BaseSchemaLedgerEntryLineInput).optional(),
263
+ parameters: z.record(SafeRecordKey, z.string()).optional(),
264
+ tags: z.array(
265
+ z.object({
266
+ key: z.string(),
267
+ value: z.string()
268
+ })
269
+ ).optional(),
270
+ groups: z.array(
271
+ z.object({
272
+ key: SafeStringSchema,
273
+ value: z.string()
274
+ })
275
+ ).optional(),
276
+ status: SchemaLedgerEntityStatusSchema.optional(),
277
+ postLinesAs: PostLinesAsSchema.optional()
278
+ });
279
+ var BaseLedgerEntries = z.object({
280
+ types: z.array(BaseSchemaLedgerEntryInput)
281
+ });
282
+ var PaymentEventKey = {
283
+ /** Exit from the payer not yet having supplied a payment method at checkout. */
284
+ needs_payment_method_to_processing: "needs_payment_method_to_processing",
285
+ processing_to_settled: "processing_to_settled"
286
+ };
287
+ var PaymentEventKeySchema = z.nativeEnum(PaymentEventKey);
288
+ var PaymentTypeDirection = {
289
+ payin: "payin",
290
+ payout: "payout"
291
+ };
292
+ var PaymentTypeDirectionSchema = z.nativeEnum(PaymentTypeDirection);
293
+ var SystemLineKind = {
294
+ payment_settlement_line: "payment_settlement_line",
295
+ payment_fee_line: "payment_fee_line"
296
+ };
297
+ var SystemLineKindSchema = z.nativeEnum(SystemLineKind);
298
+ var SystemLineParameterName = {
299
+ payment_settlement_line: "settled_amount",
300
+ payment_fee_line: "fragment_fee_amount"
301
+ };
302
+ var SYSTEM_LINE_AMOUNT = {
303
+ [SystemLineKind.payment_settlement_line]: `{{${SystemLineParameterName.payment_settlement_line}}}`,
304
+ [SystemLineKind.payment_fee_line]: `-{{${SystemLineParameterName.payment_fee_line}}}`
305
+ };
306
+ var SYSTEM_PARAMETER_NAMES = new Set(
307
+ Object.values(SystemLineParameterName)
308
+ );
309
+ var BaseSchemaPaymentInput = z.object({
310
+ amount: z.string(),
311
+ direction: PaymentTypeDirectionSchema
312
+ });
313
+ var BaseSchemaPaymentEntryLineInput = BaseSchemaLedgerEntryLineInput.pick({
314
+ key: true,
315
+ currency: true,
316
+ description: true
317
+ }).extend({
318
+ account: z.object({ path: z.string() }),
319
+ amount: z.string(),
320
+ system: SystemLineKindSchema.optional()
321
+ });
322
+ var BaseSchemaPaymentEntryInput = z.object({
323
+ description: z.string().optional(),
324
+ lines: z.array(BaseSchemaPaymentEntryLineInput)
325
+ });
326
+ var SchemaPaymentTypeStatusSchema = z.enum(["active"]);
327
+ var BaseSchemaPaymentTypeInput = z.object({
328
+ type: z.string(),
329
+ typeVersion: z.number().int(),
330
+ status: SchemaPaymentTypeStatusSchema,
331
+ payment: BaseSchemaPaymentInput,
332
+ accounting: z.object({
333
+ needs_payment_method_to_processing: BaseSchemaPaymentEntryInput.optional(),
334
+ processing_to_settled: BaseSchemaPaymentEntryInput
335
+ })
336
+ });
337
+ var BaseSchemaPayments = z.object({
338
+ types: z.array(BaseSchemaPaymentTypeInput)
339
+ });
340
+ var SceneEntrySchema = z.object({
341
+ type: z.string(),
342
+ typeVersion: z.number().int().positive().optional(),
343
+ parameters: z.record(SafeRecordKey, z.string())
344
+ });
345
+ var ScenePaymentSchema = z.object({
346
+ ik: z.string(),
347
+ type: z.string(),
348
+ typeVersion: z.number().int().positive().optional(),
349
+ parameters: z.record(SafeRecordKey, z.string())
350
+ });
351
+ var SceneLedgerEventSchema = z.object({
352
+ eventType: z.literal("entry"),
353
+ entry: SceneEntrySchema
354
+ });
355
+ var ScenePaymentEventSchema = z.object({
356
+ eventType: z.literal("payment"),
357
+ payment: z.object({
358
+ ik: z.string(),
359
+ event: PaymentEventKeySchema
360
+ })
361
+ });
362
+ var SceneEventSchema = z.discriminatedUnion("eventType", [
363
+ SceneLedgerEventSchema,
364
+ ScenePaymentEventSchema
365
+ ]);
366
+ var BaseScene = z.object({
367
+ name: z.string(),
368
+ events: z.array(SceneEventSchema),
369
+ payments: z.array(ScenePaymentSchema).optional()
370
+ });
371
+ var EntryKey = z.object({
372
+ type: SafeStringSchema,
373
+ typeVersion: z.number().int().positive()
374
+ });
375
+ var SchemaLedgerAccountMatchInput = z.object({
376
+ path: ParameterizedString
377
+ });
378
+ var GroupReconciliationParameters = z.object({
379
+ clearingAccountPath: SchemaLedgerAccountMatchInput
380
+ });
381
+ var SchemaEntryGroup = z.object({
382
+ key: SafeStringSchema,
383
+ description: z.string().optional(),
384
+ reconciliation: GroupReconciliationParameters.optional()
385
+ });
386
+ var BaseSchema = z.object({
387
+ name: z.string().optional(),
388
+ key: z.string(),
389
+ chartOfAccounts: BaseChartOfAccounts,
390
+ ledgerEntries: BaseLedgerEntries.optional(),
391
+ payments: BaseSchemaPayments.optional(),
392
+ groups: z.array(SchemaEntryGroup).optional(),
393
+ scenes: z.array(BaseScene).optional(),
394
+ consistencyConfig: z.optional(
395
+ z.object({
396
+ entries: ConsistencyModeSchema.optional()
397
+ })
398
+ )
399
+ });
400
+
401
+ export {
402
+ fillParams,
403
+ getSchemaObjectParameters,
404
+ SchemaTxMatchInput,
405
+ ConsistencyConfigSchema,
406
+ AccountConsistencyConfigSchema,
407
+ SchemaLedgerEntityStatusSchema,
408
+ BaseChartOfAccounts,
409
+ PostLinesAsSchema,
410
+ PaymentEventKey,
411
+ PaymentEventKeySchema,
412
+ PaymentTypeDirection,
413
+ PaymentTypeDirectionSchema,
414
+ SystemLineKind,
415
+ SystemLineKindSchema,
416
+ SYSTEM_LINE_AMOUNT,
417
+ SYSTEM_PARAMETER_NAMES,
418
+ SchemaPaymentTypeStatusSchema,
419
+ SchemaEntryGroup,
420
+ getStructuralPath,
421
+ getInstanceValueByAccountPath,
422
+ getSubpaths,
423
+ getStructuralSubpaths
424
+ };
@@ -2,12 +2,13 @@ import {
2
2
  generateQueriesFileContent,
3
3
  generateQueryFiles,
4
4
  schemaToEntryDefinitions,
5
+ schemaToPaymentDefinitions,
5
6
  validateOutputName
6
- } from "./chunk-KNG7UK5V.js";
7
+ } from "./chunk-QUNR5ZC3.js";
7
8
  import {
8
9
  Schema,
9
10
  parseWithError
10
- } from "./chunk-R2HKKBEG.js";
11
+ } from "./chunk-RILSVR74.js";
11
12
  import {
12
13
  formatValidationErrors,
13
14
  logValidationErrors
@@ -41,7 +42,7 @@ var GenGraphQL = class _GenGraphQL extends FragmentCommand {
41
42
  this.summary = "Generate GraphQL queries from your Schema for your SDK.";
42
43
  }
43
44
  static {
44
- this.description = `This command generates a GraphQL query for each entry type in your ledger Schema.
45
+ this.description = `This command generates a GraphQL query for each Ledger Entry type and each Payment type in your ledger Schema.
45
46
  Use this command with Fragment SDKs to create type-safe code to update your ledger.`;
46
47
  }
47
48
  static {
@@ -137,8 +138,12 @@ ${import_chalk.default.gray("Schema file:")} ${path}`);
137
138
  schema: validatedSchema,
138
139
  includeRuntimeArgs: flags["include-runtime-args"]
139
140
  });
141
+ const paymentDefinitions = schemaToPaymentDefinitions({
142
+ schema: validatedSchema
143
+ });
140
144
  const generateQueryParams = {
141
145
  definitions: entryDefinitions,
146
+ paymentDefinitions,
142
147
  includeStandardQueries: flags["include-standard-queries"]
143
148
  };
144
149
  if (flags["output-file-per-query"]) {