@caatinga/core 0.2.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/dist/index.cjs ADDED
@@ -0,0 +1,1104 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ CAATINGA_CORE_VERSION: () => CAATINGA_CORE_VERSION,
34
+ CaatingaArtifactsSchema: () => CaatingaArtifactsSchema,
35
+ CaatingaConfigSchema: () => CaatingaConfigSchema,
36
+ CaatingaError: () => CaatingaError,
37
+ CaatingaErrorCode: () => CaatingaErrorCode,
38
+ STELLAR_CLI_MIN_VERSION: () => STELLAR_CLI_MIN_VERSION,
39
+ STELLAR_CLI_TESTED_MAX_VERSION: () => STELLAR_CLI_TESTED_MAX_VERSION,
40
+ TemplateManifestSchema: () => TemplateManifestSchema,
41
+ WELL_KNOWN_NETWORKS: () => WELL_KNOWN_NETWORKS,
42
+ assertSupportedStellarCliVersion: () => assertSupportedStellarCliVersion,
43
+ buildContract: () => buildContract,
44
+ buildDependencyGraph: () => buildDependencyGraph,
45
+ checkBinary: () => checkBinary,
46
+ createInitialArtifacts: () => createInitialArtifacts,
47
+ createProjectFromTemplate: () => createProjectFromTemplate,
48
+ defineConfig: () => defineConfig,
49
+ deployContract: () => deployContract,
50
+ deployContractGraph: () => deployContractGraph,
51
+ generateBindings: () => generateBindings,
52
+ invokeContract: () => invokeContract,
53
+ isTransientTestnetSmokeFailure: () => isTransientTestnetSmokeFailure,
54
+ loadConfig: () => loadConfig,
55
+ parseContractId: () => parseContractId,
56
+ parseInvokeTarget: () => parseInvokeTarget,
57
+ parseStellarCliVersion: () => parseStellarCliVersion,
58
+ readArtifacts: () => readArtifacts,
59
+ resolveContract: () => resolveContract,
60
+ resolveDeployArgs: () => resolveDeployArgs,
61
+ resolveDeployOrder: () => resolveDeployOrder,
62
+ resolveNetwork: () => resolveNetwork,
63
+ runCommand: () => runCommand,
64
+ toCaatingaError: () => toCaatingaError,
65
+ updateArtifact: () => updateArtifact,
66
+ writeArtifacts: () => writeArtifacts
67
+ });
68
+ module.exports = __toCommonJS(index_exports);
69
+
70
+ // src/errors/CaatingaErrorCode.ts
71
+ var CaatingaErrorCode = {
72
+ CONFIG_NOT_FOUND: "CAATINGA_CONFIG_NOT_FOUND",
73
+ INVALID_CONFIG: "CAATINGA_INVALID_CONFIG",
74
+ COMMAND_FAILED: "CAATINGA_COMMAND_FAILED",
75
+ UNEXPECTED_ERROR: "CAATINGA_UNEXPECTED_ERROR",
76
+ STELLAR_CLI_NOT_FOUND: "CAATINGA_STELLAR_CLI_NOT_FOUND",
77
+ STELLAR_CLI_VERSION_PARSE_FAILED: "CAATINGA_STELLAR_CLI_VERSION_PARSE_FAILED",
78
+ UNSUPPORTED_CLI_VERSION: "CAATINGA_UNSUPPORTED_CLI_VERSION",
79
+ UNTESTED_CLI_VERSION: "CAATINGA_UNTESTED_CLI_VERSION",
80
+ RUST_NOT_FOUND: "CAATINGA_RUST_NOT_FOUND",
81
+ RUST_TARGET_NOT_FOUND: "CAATINGA_RUST_TARGET_NOT_FOUND",
82
+ DEPLOY_FAILED: "CAATINGA_DEPLOY_FAILED",
83
+ BUILD_FAILED: "CAATINGA_BUILD_FAILED",
84
+ BINDINGS_FAILED: "CAATINGA_BINDINGS_FAILED",
85
+ INVOKE_FAILED: "CAATINGA_INVOKE_FAILED",
86
+ CONTRACT_NOT_FOUND: "CAATINGA_CONTRACT_NOT_FOUND",
87
+ NETWORK_NOT_FOUND: "CAATINGA_NETWORK_NOT_FOUND",
88
+ ARTIFACT_NOT_FOUND: "CAATINGA_ARTIFACT_NOT_FOUND",
89
+ ARTIFACT_INVALID: "CAATINGA_ARTIFACT_INVALID",
90
+ CONTRACT_ID_NOT_FOUND: "CAATINGA_CONTRACT_ID_NOT_FOUND",
91
+ CONTRACT_ARTIFACT_NOT_FOUND: "CAATINGA_CONTRACT_ARTIFACT_NOT_FOUND",
92
+ CONTRACT_DEPENDENCY_NOT_FOUND: "CAATINGA_CONTRACT_DEPENDENCY_NOT_FOUND",
93
+ CONTRACT_DEPENDENCY_CYCLE: "CAATINGA_CONTRACT_DEPENDENCY_CYCLE",
94
+ CONTRACT_DEPENDENCY_ARTIFACT_NOT_FOUND: "CAATINGA_CONTRACT_DEPENDENCY_ARTIFACT_NOT_FOUND",
95
+ DEPLOY_ARG_PLACEHOLDER_INVALID: "CAATINGA_DEPLOY_ARG_PLACEHOLDER_INVALID",
96
+ DEPLOY_ARG_PLACEHOLDER_UNRESOLVED: "CAATINGA_DEPLOY_ARG_PLACEHOLDER_UNRESOLVED",
97
+ BINDING_CLIENT_NOT_FOUND: "CAATINGA_BINDING_CLIENT_NOT_FOUND",
98
+ BINDING_METHOD_NOT_FOUND: "CAATINGA_BINDING_METHOD_NOT_FOUND",
99
+ XDR_BUILD_FAILED: "CAATINGA_XDR_BUILD_FAILED",
100
+ XDR_PREPARE_FAILED: "CAATINGA_XDR_PREPARE_FAILED",
101
+ XDR_SIGN_FAILED: "CAATINGA_XDR_SIGN_FAILED",
102
+ XDR_SUBMIT_FAILED: "CAATINGA_XDR_SUBMIT_FAILED",
103
+ XDR_RESULT_FAILED: "CAATINGA_XDR_RESULT_FAILED",
104
+ WALLET_NOT_CONNECTED: "CAATINGA_WALLET_NOT_CONNECTED",
105
+ SOURCE_ACCOUNT_REQUIRED: "CAATINGA_SOURCE_ACCOUNT_REQUIRED",
106
+ UNSAFE_SOURCE_ACCOUNT: "CAATINGA_UNSAFE_SOURCE_ACCOUNT",
107
+ INVOKE_TARGET_INVALID: "CAATINGA_INVOKE_TARGET_INVALID",
108
+ TEMPLATE_NOT_FOUND: "CAATINGA_TEMPLATE_NOT_FOUND",
109
+ INVALID_TEMPLATE_MANIFEST: "CAATINGA_INVALID_TEMPLATE_MANIFEST",
110
+ TEMPLATE_MANIFEST_NOT_FOUND: "CAATINGA_TEMPLATE_MANIFEST_NOT_FOUND",
111
+ TEMPLATE_INCOMPATIBLE: "CAATINGA_TEMPLATE_INCOMPATIBLE"
112
+ };
113
+
114
+ // src/errors/CaatingaError.ts
115
+ var CaatingaError = class extends Error {
116
+ constructor(message, code, hint, cause) {
117
+ super(message);
118
+ this.code = code;
119
+ this.hint = hint;
120
+ this.cause = cause;
121
+ this.name = "CaatingaError";
122
+ }
123
+ code;
124
+ hint;
125
+ cause;
126
+ };
127
+ function toCaatingaError(error) {
128
+ if (error instanceof CaatingaError) {
129
+ return error;
130
+ }
131
+ if (error instanceof Error) {
132
+ return new CaatingaError(error.message, CaatingaErrorCode.UNEXPECTED_ERROR, void 0, error);
133
+ }
134
+ return new CaatingaError("An unexpected error occurred.", CaatingaErrorCode.UNEXPECTED_ERROR);
135
+ }
136
+
137
+ // src/version.ts
138
+ var CAATINGA_CORE_VERSION = "0.2.0";
139
+
140
+ // src/config/config.schema.ts
141
+ var import_zod = require("zod");
142
+ var DeployArgValueSchema = import_zod.z.union([import_zod.z.string(), import_zod.z.number(), import_zod.z.boolean()]);
143
+ var ContractConfigSchema = import_zod.z.object({
144
+ path: import_zod.z.string().min(1),
145
+ wasm: import_zod.z.string().min(1),
146
+ dependsOn: import_zod.z.array(import_zod.z.string().min(1)).default([]),
147
+ deployArgs: import_zod.z.record(import_zod.z.string().min(1), DeployArgValueSchema).default({})
148
+ });
149
+ var NetworkConfigSchema = import_zod.z.object({
150
+ rpcUrl: import_zod.z.string().url(),
151
+ networkPassphrase: import_zod.z.string().min(1)
152
+ });
153
+ var CaatingaConfigSchema = import_zod.z.object({
154
+ project: import_zod.z.string().min(1),
155
+ defaultNetwork: import_zod.z.string().min(1).default("testnet"),
156
+ contracts: import_zod.z.record(import_zod.z.string().min(1), ContractConfigSchema).refine(
157
+ (contracts) => Object.keys(contracts).length > 0,
158
+ "At least one contract must be configured."
159
+ ),
160
+ networks: import_zod.z.record(import_zod.z.string().min(1), NetworkConfigSchema).refine(
161
+ (networks) => Object.keys(networks).length > 0,
162
+ "At least one network must be configured."
163
+ ),
164
+ frontend: import_zod.z.object({
165
+ framework: import_zod.z.enum(["vite-react", "next", "astro"]).default("vite-react"),
166
+ bindingsOutput: import_zod.z.string().min(1)
167
+ })
168
+ });
169
+
170
+ // src/config/define-config.ts
171
+ function defineConfig(config) {
172
+ return config;
173
+ }
174
+
175
+ // src/config/load-config.ts
176
+ var import_promises = require("fs/promises");
177
+ var import_node_path = __toESM(require("path"), 1);
178
+ var import_jiti = require("jiti");
179
+ var import_zod2 = require("zod");
180
+ var import_meta = {};
181
+ async function loadConfig(options = {}) {
182
+ const cwd = options.cwd ?? process.cwd();
183
+ const configPath = import_node_path.default.resolve(cwd, options.configPath ?? "caatinga.config.ts");
184
+ try {
185
+ await (0, import_promises.access)(configPath);
186
+ } catch {
187
+ throw new CaatingaError(
188
+ "caatinga.config.ts was not found.",
189
+ CaatingaErrorCode.CONFIG_NOT_FOUND,
190
+ "Run this command from a Caatinga project root, or create a caatinga.config.ts file."
191
+ );
192
+ }
193
+ try {
194
+ const jiti = (0, import_jiti.createJiti)(import_meta.url);
195
+ const loaded = await jiti.import(configPath, { default: true });
196
+ return CaatingaConfigSchema.parse(loaded);
197
+ } catch (error) {
198
+ if (error instanceof import_zod2.z.ZodError) {
199
+ throw new CaatingaError(
200
+ "caatinga.config.ts is invalid.",
201
+ CaatingaErrorCode.INVALID_CONFIG,
202
+ error.issues.map((issue) => `${issue.path.join(".")}: ${issue.message}`).join("; ")
203
+ );
204
+ }
205
+ throw error;
206
+ }
207
+ }
208
+
209
+ // src/artifacts/artifact.schema.ts
210
+ var import_zod3 = require("zod");
211
+ var ContractArtifactSchema = import_zod3.z.object({
212
+ contractId: import_zod3.z.string().min(1),
213
+ wasmHash: import_zod3.z.string().min(1),
214
+ deployedAt: import_zod3.z.string().datetime(),
215
+ sourcePath: import_zod3.z.string().min(1),
216
+ wasmPath: import_zod3.z.string().min(1),
217
+ dependencies: import_zod3.z.array(import_zod3.z.string().min(1)).default([]),
218
+ resolvedDeployArgs: import_zod3.z.record(import_zod3.z.string().min(1), import_zod3.z.union([import_zod3.z.string(), import_zod3.z.number(), import_zod3.z.boolean()])).default({})
219
+ });
220
+ var NetworkArtifactsSchema = import_zod3.z.object({
221
+ contracts: import_zod3.z.record(import_zod3.z.string().min(1), ContractArtifactSchema).default({}),
222
+ dependencyGraph: import_zod3.z.record(import_zod3.z.string().min(1), import_zod3.z.array(import_zod3.z.string().min(1))).default({})
223
+ });
224
+ var CaatingaArtifactsSchema = import_zod3.z.object({
225
+ project: import_zod3.z.string().min(1),
226
+ version: import_zod3.z.literal(1),
227
+ networks: import_zod3.z.record(import_zod3.z.string().min(1), NetworkArtifactsSchema).default({})
228
+ });
229
+
230
+ // src/artifacts/read-artifacts.ts
231
+ var import_promises2 = require("fs/promises");
232
+ var import_node_path2 = __toESM(require("path"), 1);
233
+ var import_zod4 = require("zod");
234
+ async function readArtifacts(cwd = process.cwd()) {
235
+ const artifactsPath = import_node_path2.default.resolve(cwd, "caatinga.artifacts.json");
236
+ try {
237
+ const json = await (0, import_promises2.readFile)(artifactsPath, "utf8");
238
+ return CaatingaArtifactsSchema.parse(JSON.parse(json));
239
+ } catch (error) {
240
+ if (error.code === "ENOENT") {
241
+ throw new CaatingaError(
242
+ "caatinga.artifacts.json was not found.",
243
+ CaatingaErrorCode.ARTIFACT_NOT_FOUND,
244
+ "Run caatinga init, or create the artifacts file before deploying or generating bindings."
245
+ );
246
+ }
247
+ if (error instanceof SyntaxError || error instanceof import_zod4.z.ZodError) {
248
+ throw new CaatingaError(
249
+ "caatinga.artifacts.json is invalid.",
250
+ CaatingaErrorCode.ARTIFACT_INVALID,
251
+ "Fix the JSON shape before running Caatinga commands."
252
+ );
253
+ }
254
+ throw error;
255
+ }
256
+ }
257
+
258
+ // src/artifacts/write-artifacts.ts
259
+ var import_promises3 = require("fs/promises");
260
+ var import_node_path3 = __toESM(require("path"), 1);
261
+ async function writeArtifacts(artifacts, cwd = process.cwd()) {
262
+ const artifactsPath = import_node_path3.default.resolve(cwd, "caatinga.artifacts.json");
263
+ await (0, import_promises3.mkdir)(import_node_path3.default.dirname(artifactsPath), { recursive: true });
264
+ await (0, import_promises3.writeFile)(artifactsPath, `${JSON.stringify(artifacts, null, 2)}
265
+ `, "utf8");
266
+ return artifactsPath;
267
+ }
268
+ function createInitialArtifacts(project) {
269
+ return {
270
+ project,
271
+ version: 1,
272
+ networks: {}
273
+ };
274
+ }
275
+
276
+ // src/artifacts/update-artifact.ts
277
+ function updateArtifact(artifacts, networkName, contractName, contractArtifact, networkExtras) {
278
+ const existingNetwork = artifacts.networks[networkName] ?? { contracts: {}, dependencyGraph: {} };
279
+ return {
280
+ ...artifacts,
281
+ networks: {
282
+ ...artifacts.networks,
283
+ [networkName]: {
284
+ ...existingNetwork,
285
+ dependencyGraph: networkExtras?.dependencyGraph ?? existingNetwork.dependencyGraph ?? {},
286
+ contracts: {
287
+ ...existingNetwork.contracts,
288
+ [contractName]: contractArtifact
289
+ }
290
+ }
291
+ }
292
+ };
293
+ }
294
+
295
+ // src/networks/networks.ts
296
+ var WELL_KNOWN_NETWORKS = {
297
+ testnet: {
298
+ rpcUrl: "https://soroban-testnet.stellar.org",
299
+ networkPassphrase: "Test SDF Network ; September 2015"
300
+ },
301
+ mainnet: {
302
+ rpcUrl: "https://mainnet.sorobanrpc.com",
303
+ networkPassphrase: "Public Global Stellar Network ; September 2015"
304
+ }
305
+ };
306
+
307
+ // src/networks/resolve-network.ts
308
+ function resolveNetwork(config, networkName) {
309
+ const name = networkName ?? config.defaultNetwork;
310
+ const network = config.networks[name];
311
+ if (!network) {
312
+ throw new CaatingaError(
313
+ `Network "${name}" is not configured.`,
314
+ CaatingaErrorCode.NETWORK_NOT_FOUND,
315
+ `Add "${name}" to caatinga.config.ts networks, or pass a configured --network value.`
316
+ );
317
+ }
318
+ return { name, config: network };
319
+ }
320
+
321
+ // src/shell/run-command.ts
322
+ var import_execa = require("execa");
323
+
324
+ // src/stellar-cli/version.ts
325
+ var import_semver = __toESM(require("semver"), 1);
326
+ var STELLAR_CLI_MIN_VERSION = "22.0.0";
327
+ var STELLAR_CLI_TESTED_MAX_VERSION = "25.2.0";
328
+ var STELLAR_CLI_SEMVER_REGEX = /\b(\d+\.\d+\.\d+(?:-[0-9A-Za-z-.]+)?(?:\+[0-9A-Za-z-.]+)?)\b/;
329
+ function parseStellarCliVersion(output) {
330
+ const match = output.match(STELLAR_CLI_SEMVER_REGEX);
331
+ const version = match?.[1];
332
+ if (!version || !import_semver.default.valid(version)) {
333
+ throw new CaatingaError(
334
+ "Could not parse Stellar CLI version from command output.",
335
+ CaatingaErrorCode.STELLAR_CLI_VERSION_PARSE_FAILED,
336
+ "Run `stellar --version` and verify that the output includes a semantic version."
337
+ );
338
+ }
339
+ return version;
340
+ }
341
+ function assertSupportedStellarCliVersion(input) {
342
+ const normalizedVersion = import_semver.default.valid(input.version);
343
+ if (!normalizedVersion) {
344
+ throw new CaatingaError(
345
+ "Could not parse Stellar CLI version.",
346
+ CaatingaErrorCode.STELLAR_CLI_VERSION_PARSE_FAILED,
347
+ "Use a semantic version such as 22.0.1."
348
+ );
349
+ }
350
+ if (import_semver.default.lt(normalizedVersion, STELLAR_CLI_MIN_VERSION)) {
351
+ throw new CaatingaError(
352
+ `Stellar CLI ${normalizedVersion} is below the supported minimum ${STELLAR_CLI_MIN_VERSION}.`,
353
+ CaatingaErrorCode.UNSUPPORTED_CLI_VERSION,
354
+ `Install Stellar CLI ${STELLAR_CLI_MIN_VERSION} or newer.`
355
+ );
356
+ }
357
+ if (!input.allowUntested && import_semver.default.gt(normalizedVersion, STELLAR_CLI_TESTED_MAX_VERSION)) {
358
+ throw new CaatingaError(
359
+ `Stellar CLI ${normalizedVersion} is newer than the tested maximum ${STELLAR_CLI_TESTED_MAX_VERSION}.`,
360
+ CaatingaErrorCode.UNTESTED_CLI_VERSION,
361
+ "Pass --allow-untested-stellar-cli only after accepting the compatibility risk."
362
+ );
363
+ }
364
+ return normalizedVersion;
365
+ }
366
+
367
+ // src/stellar-cli/check-stellar-cli-version.ts
368
+ async function checkStellarCliVersion(input) {
369
+ try {
370
+ const result = await runCommand("stellar", ["--version"], {
371
+ skipStellarVersionCheck: true
372
+ });
373
+ const output = result.all || result.stdout || result.stderr;
374
+ return assertSupportedStellarCliVersion({
375
+ version: parseStellarCliVersion(output),
376
+ allowUntested: input.allowUntested
377
+ });
378
+ } catch (error) {
379
+ if (typeof error === "object" && error && "code" in error && error.code === "ENOENT") {
380
+ throw new CaatingaError(
381
+ "Stellar CLI was not found.",
382
+ CaatingaErrorCode.STELLAR_CLI_NOT_FOUND,
383
+ "Install Stellar CLI before running Caatinga-backed commands.",
384
+ error
385
+ );
386
+ }
387
+ throw error;
388
+ }
389
+ }
390
+
391
+ // src/shell/run-command.ts
392
+ async function runCommand(command, args, options = {}) {
393
+ try {
394
+ if (command === "stellar" && !options.skipStellarVersionCheck) {
395
+ await checkStellarCliVersion({
396
+ allowUntested: options.allowUntestedStellarCli === true
397
+ });
398
+ }
399
+ const result = await (0, import_execa.execa)(command, args, {
400
+ cwd: options.cwd,
401
+ env: options.env,
402
+ all: true,
403
+ reject: true
404
+ });
405
+ return {
406
+ stdout: result.stdout,
407
+ stderr: result.stderr,
408
+ all: result.all ?? ""
409
+ };
410
+ } catch (error) {
411
+ if (error instanceof CaatingaError) {
412
+ throw error;
413
+ }
414
+ if (command === "stellar" && typeof error === "object" && error && "code" in error && error.code === "ENOENT") {
415
+ throw new CaatingaError(
416
+ "Stellar CLI was not found.",
417
+ CaatingaErrorCode.STELLAR_CLI_NOT_FOUND,
418
+ "Install Stellar CLI before running Caatinga-backed commands.",
419
+ error
420
+ );
421
+ }
422
+ const output = typeof error === "object" && error && "all" in error ? String(error.all) : void 0;
423
+ throw new CaatingaError(
424
+ `Command failed: ${command} ${args.join(" ")}`,
425
+ options.failureCode ?? CaatingaErrorCode.COMMAND_FAILED,
426
+ output || "Re-run the command with the underlying tool directly for full diagnostics.",
427
+ error
428
+ );
429
+ }
430
+ }
431
+
432
+ // src/shell/check-binary.ts
433
+ async function checkBinary(binary, hint, options = {}) {
434
+ try {
435
+ await runCommand(binary, ["--version"], options);
436
+ } catch (error) {
437
+ if (error instanceof CaatingaError) {
438
+ throw error;
439
+ }
440
+ const code = binary === "stellar" ? CaatingaErrorCode.STELLAR_CLI_NOT_FOUND : binary === "rustc" ? CaatingaErrorCode.RUST_NOT_FOUND : CaatingaErrorCode.COMMAND_FAILED;
441
+ throw new CaatingaError(`${binary} was not found.`, code, hint, error);
442
+ }
443
+ }
444
+
445
+ // src/stellar-cli/parse-contract-id.ts
446
+ var CONTRACT_ID_REGEX = /\bC[A-Z0-9]{55}\b/;
447
+ function parseContractId(output) {
448
+ const match = output.match(CONTRACT_ID_REGEX);
449
+ if (!match) {
450
+ throw new CaatingaError(
451
+ "Could not find contract ID in Stellar CLI output.",
452
+ CaatingaErrorCode.CONTRACT_ID_NOT_FOUND,
453
+ "Check whether the Stellar CLI output format changed."
454
+ );
455
+ }
456
+ return match[0];
457
+ }
458
+
459
+ // src/contracts/resolve-contract.ts
460
+ var import_node_path4 = __toESM(require("path"), 1);
461
+ function resolveContract(config, contractName, cwd = process.cwd()) {
462
+ const contract = config.contracts[contractName];
463
+ if (!contract) {
464
+ throw new CaatingaError(
465
+ `Contract "${contractName}" is not configured.`,
466
+ CaatingaErrorCode.CONTRACT_NOT_FOUND,
467
+ `Add "${contractName}" to caatinga.config.ts contracts, or pass a configured contract name.`
468
+ );
469
+ }
470
+ return {
471
+ name: contractName,
472
+ config: contract,
473
+ sourcePath: import_node_path4.default.resolve(cwd, contract.path),
474
+ wasmPath: import_node_path4.default.resolve(cwd, contract.wasm)
475
+ };
476
+ }
477
+
478
+ // src/contracts/wasm.ts
479
+ var import_node_crypto = require("crypto");
480
+ var import_promises4 = require("fs/promises");
481
+ async function assertWasmExists(wasmPath) {
482
+ try {
483
+ await (0, import_promises4.access)(wasmPath);
484
+ } catch {
485
+ throw new CaatingaError(
486
+ `WASM output was not found at ${wasmPath}.`,
487
+ CaatingaErrorCode.ARTIFACT_NOT_FOUND,
488
+ "Run caatinga build before deploy or generate."
489
+ );
490
+ }
491
+ }
492
+ async function hashWasm(wasmPath) {
493
+ const bytes = await (0, import_promises4.readFile)(wasmPath);
494
+ return (0, import_node_crypto.createHash)("sha256").update(bytes).digest("hex");
495
+ }
496
+
497
+ // src/contracts/build-contract.ts
498
+ var RUST_WASM_TARGET = "wasm32-unknown-unknown";
499
+ var MISSING_WASM_TARGET_HINT_SUBSTRINGS = [
500
+ "not installed",
501
+ "not found",
502
+ "needs to be installed",
503
+ "add the",
504
+ "rustup target"
505
+ ];
506
+ function isMissingRustWasmTargetError(error) {
507
+ if (!(error instanceof CaatingaError)) {
508
+ return false;
509
+ }
510
+ const parts = [
511
+ error.message,
512
+ error.hint ?? "",
513
+ error.cause === void 0 ? "" : String(error.cause)
514
+ ];
515
+ const haystack = parts.join("\n").toLowerCase();
516
+ if (!haystack.includes(RUST_WASM_TARGET)) {
517
+ return false;
518
+ }
519
+ return MISSING_WASM_TARGET_HINT_SUBSTRINGS.some((needle) => haystack.includes(needle));
520
+ }
521
+ async function buildContract(options) {
522
+ const cwd = options.cwd ?? process.cwd();
523
+ const contract = resolveContract(options.config, options.contractName, cwd);
524
+ await checkBinary("rustc", "Install Rust before running caatinga build.");
525
+ await checkBinary("stellar", "Install Stellar CLI before running caatinga build.", {
526
+ allowUntestedStellarCli: options.allowUntestedStellarCli
527
+ });
528
+ let result;
529
+ try {
530
+ result = await runCommand("stellar", ["contract", "build"], {
531
+ cwd: contract.sourcePath,
532
+ allowUntestedStellarCli: options.allowUntestedStellarCli,
533
+ failureCode: CaatingaErrorCode.BUILD_FAILED
534
+ });
535
+ } catch (error) {
536
+ if (error instanceof CaatingaError && error.code === CaatingaErrorCode.BUILD_FAILED && isMissingRustWasmTargetError(error)) {
537
+ throw new CaatingaError(
538
+ `Required Rust wasm target "${RUST_WASM_TARGET}" is missing.`,
539
+ CaatingaErrorCode.RUST_TARGET_NOT_FOUND,
540
+ `Run \`rustup target add ${RUST_WASM_TARGET}\` and retry the build.`,
541
+ error
542
+ );
543
+ }
544
+ throw error;
545
+ }
546
+ await assertWasmExists(contract.wasmPath);
547
+ return {
548
+ contract,
549
+ output: result.all || result.stdout
550
+ };
551
+ }
552
+
553
+ // src/contracts/deploy-contract.ts
554
+ var import_node_path5 = __toESM(require("path"), 1);
555
+
556
+ // src/contracts/dependency-graph.ts
557
+ function buildDependencyGraph(contracts) {
558
+ const graph = {};
559
+ for (const name of Object.keys(contracts)) {
560
+ graph[name] = [...contracts[name].dependsOn];
561
+ }
562
+ return graph;
563
+ }
564
+
565
+ // src/contracts/resolve-deploy-args.ts
566
+ var CONTRACT_ID_PLACEHOLDER = /^\$\{contracts\.([A-Za-z0-9_-]+)\.contractId\}$/;
567
+ function resolveDeployArgs(input) {
568
+ const resolved = {};
569
+ for (const [key, value] of Object.entries(input.deployArgs)) {
570
+ if (typeof value !== "string" || !value.includes("${")) {
571
+ resolved[key] = value;
572
+ continue;
573
+ }
574
+ const match = value.match(CONTRACT_ID_PLACEHOLDER);
575
+ if (!match) {
576
+ throw new CaatingaError(
577
+ `Deploy arg "${key}" contains an unsupported placeholder.`,
578
+ CaatingaErrorCode.DEPLOY_ARG_PLACEHOLDER_INVALID,
579
+ "Use only ${contracts.<contractName>.contractId}."
580
+ );
581
+ }
582
+ const contractName = match[1];
583
+ const contractArtifact = input.artifacts.networks[input.network]?.contracts[contractName];
584
+ if (!contractArtifact?.contractId) {
585
+ throw new CaatingaError(
586
+ `No dependency artifact found for "${contractName}" on "${input.network}".`,
587
+ CaatingaErrorCode.CONTRACT_DEPENDENCY_ARTIFACT_NOT_FOUND,
588
+ "Deploy the dependency first or run deploy without --no-deps."
589
+ );
590
+ }
591
+ resolved[key] = contractArtifact.contractId;
592
+ }
593
+ return resolved;
594
+ }
595
+
596
+ // src/contracts/source-account.ts
597
+ function assertSafeSourceAccount(source) {
598
+ if (!source) {
599
+ throw new CaatingaError(
600
+ "A source account or Stellar CLI identity is required.",
601
+ CaatingaErrorCode.SOURCE_ACCOUNT_REQUIRED,
602
+ "Pass --source alice or --source G...; do not pass secret keys or seed phrases."
603
+ );
604
+ }
605
+ if (source.startsWith("S") || source.trim().includes(" ")) {
606
+ throw new CaatingaError(
607
+ "Refusing to accept a likely secret key or seed phrase as --source.",
608
+ CaatingaErrorCode.UNSAFE_SOURCE_ACCOUNT,
609
+ "Use a Stellar CLI identity alias or public account address instead."
610
+ );
611
+ }
612
+ return source;
613
+ }
614
+
615
+ // src/contracts/deploy-contract.ts
616
+ function toSnakeCaseFlag(key) {
617
+ return key.replace(/([A-Z])/g, "_$1").replace(/^_/, "").toLowerCase();
618
+ }
619
+ function formatConstructorCliArgs(resolved) {
620
+ const entries = Object.entries(resolved);
621
+ if (entries.length === 0) {
622
+ return [];
623
+ }
624
+ const tail = ["--"];
625
+ for (const [key, value] of entries) {
626
+ tail.push(`--${toSnakeCaseFlag(key)}`, String(value));
627
+ }
628
+ return tail;
629
+ }
630
+ async function deployContract(options) {
631
+ const cwd = options.cwd ?? process.cwd();
632
+ const contract = resolveContract(options.config, options.contractName, cwd);
633
+ const network = resolveNetwork(options.config, options.networkName);
634
+ const source = assertSafeSourceAccount(options.source);
635
+ await checkBinary("stellar", "Install Stellar CLI before running caatinga deploy.", {
636
+ allowUntestedStellarCli: options.allowUntestedStellarCli
637
+ });
638
+ await assertWasmExists(contract.wasmPath);
639
+ const artifactsBefore = await readArtifacts(cwd);
640
+ const existing = artifactsBefore.networks[network.name]?.contracts[contract.name];
641
+ if (existing?.contractId && !options.force) {
642
+ return {
643
+ contract,
644
+ network,
645
+ contractId: existing.contractId,
646
+ artifactsPath: import_node_path5.default.resolve(cwd, "caatinga.artifacts.json"),
647
+ output: "",
648
+ skipped: true
649
+ };
650
+ }
651
+ const rawDeployArgs = contract.config.deployArgs;
652
+ const hasConfiguredArgs = Object.keys(rawDeployArgs).length > 0;
653
+ let resolvedDeployArgs;
654
+ if (options.resolvedDeployArgs !== void 0) {
655
+ resolvedDeployArgs = options.resolvedDeployArgs;
656
+ } else if (hasConfiguredArgs) {
657
+ resolvedDeployArgs = resolveDeployArgs({
658
+ deployArgs: rawDeployArgs,
659
+ artifacts: artifactsBefore,
660
+ network: network.name
661
+ });
662
+ } else {
663
+ resolvedDeployArgs = {};
664
+ }
665
+ for (const value of Object.values(resolvedDeployArgs)) {
666
+ if (typeof value === "string" && value.includes("${")) {
667
+ throw new CaatingaError(
668
+ `Deploy args for "${contract.name}" still contain unresolved placeholders.`,
669
+ CaatingaErrorCode.DEPLOY_ARG_PLACEHOLDER_UNRESOLVED,
670
+ "Deploy dependencies first or fix deployArgs templates."
671
+ );
672
+ }
673
+ }
674
+ const constructorArgs = formatConstructorCliArgs(resolvedDeployArgs);
675
+ const stellarArgs = [
676
+ "contract",
677
+ "deploy",
678
+ "--wasm",
679
+ contract.wasmPath,
680
+ "--source-account",
681
+ source,
682
+ "--rpc-url",
683
+ network.config.rpcUrl,
684
+ "--network-passphrase",
685
+ network.config.networkPassphrase,
686
+ ...constructorArgs
687
+ ];
688
+ const result = await runCommand("stellar", stellarArgs, {
689
+ cwd,
690
+ allowUntestedStellarCli: options.allowUntestedStellarCli,
691
+ failureCode: CaatingaErrorCode.DEPLOY_FAILED
692
+ });
693
+ const output = result.all || `${result.stdout}
694
+ ${result.stderr}`;
695
+ const contractId = parseContractId(output);
696
+ const wasmHash = await hashWasm(contract.wasmPath);
697
+ const dependencyGraph = buildDependencyGraph(options.config.contracts);
698
+ const dependencies = options.dependencies ?? contract.config.dependsOn;
699
+ const nextArtifacts = updateArtifact(
700
+ artifactsBefore,
701
+ network.name,
702
+ contract.name,
703
+ {
704
+ contractId,
705
+ wasmHash,
706
+ deployedAt: (/* @__PURE__ */ new Date()).toISOString(),
707
+ sourcePath: contract.config.path,
708
+ wasmPath: contract.config.wasm,
709
+ dependencies,
710
+ resolvedDeployArgs
711
+ },
712
+ { dependencyGraph }
713
+ );
714
+ const artifactsPath = await writeArtifacts(nextArtifacts, cwd);
715
+ return {
716
+ contract,
717
+ network,
718
+ contractId,
719
+ artifactsPath,
720
+ output,
721
+ skipped: false
722
+ };
723
+ }
724
+
725
+ // src/contracts/resolve-deploy-order.ts
726
+ function resolveDeployOrder(input) {
727
+ const order = [];
728
+ const state = /* @__PURE__ */ new Map();
729
+ const selected = input.selectedContract ? [input.selectedContract] : Object.keys(input.contracts);
730
+ for (const contractName of selected) {
731
+ visit(contractName, []);
732
+ }
733
+ return order;
734
+ function visit(contractName, stack) {
735
+ const contract = input.contracts[contractName];
736
+ if (!contract) {
737
+ throw new CaatingaError(
738
+ `Contract dependency "${contractName}" was not found.`,
739
+ CaatingaErrorCode.CONTRACT_DEPENDENCY_NOT_FOUND,
740
+ "Add the dependency to caatinga.config.ts or remove it from dependsOn."
741
+ );
742
+ }
743
+ if (state.get(contractName) === "visited") {
744
+ return;
745
+ }
746
+ if (state.get(contractName) === "visiting") {
747
+ throw new CaatingaError(
748
+ `Contract dependency cycle detected: ${[...stack, contractName].join(" -> ")}.`,
749
+ CaatingaErrorCode.CONTRACT_DEPENDENCY_CYCLE,
750
+ "Remove the cycle from dependsOn."
751
+ );
752
+ }
753
+ state.set(contractName, "visiting");
754
+ if (input.includeDependencies) {
755
+ for (const dependency of contract.dependsOn) {
756
+ visit(dependency, [...stack, contractName]);
757
+ }
758
+ } else if (contract.dependsOn.length > 0 && input.selectedContract === contractName) {
759
+ for (const dependency of contract.dependsOn) {
760
+ if (!input.contracts[dependency]) {
761
+ throw new CaatingaError(
762
+ `Contract dependency "${dependency}" was not found.`,
763
+ CaatingaErrorCode.CONTRACT_DEPENDENCY_NOT_FOUND,
764
+ "Add the dependency to caatinga.config.ts or remove it from dependsOn."
765
+ );
766
+ }
767
+ }
768
+ }
769
+ state.set(contractName, "visited");
770
+ if (!order.includes(contractName)) {
771
+ order.push(contractName);
772
+ }
773
+ }
774
+ }
775
+
776
+ // src/contracts/deploy-contract-graph.ts
777
+ async function deployContractGraph(options) {
778
+ const cwd = options.cwd ?? process.cwd();
779
+ const network = resolveNetwork(options.config, options.networkName);
780
+ const order = resolveDeployOrder({
781
+ contracts: options.config.contracts,
782
+ selectedContract: options.contractName,
783
+ includeDependencies: options.includeDependencies
784
+ });
785
+ const deployedContracts = [];
786
+ for (const contractName of order) {
787
+ const artifacts = await readArtifacts(cwd);
788
+ const existing = artifacts.networks[network.name]?.contracts[contractName];
789
+ const contractConfig = options.config.contracts[contractName];
790
+ const resolvedDeployArgs = resolveDeployArgs({
791
+ deployArgs: contractConfig.deployArgs,
792
+ artifacts,
793
+ network: network.name
794
+ });
795
+ if (existing?.contractId && !options.force) {
796
+ deployedContracts.push({ name: contractName, contractId: existing.contractId });
797
+ continue;
798
+ }
799
+ const result = await deployContract({
800
+ config: options.config,
801
+ contractName,
802
+ networkName: network.name,
803
+ source: options.source,
804
+ cwd,
805
+ allowUntestedStellarCli: options.allowUntestedStellarCli,
806
+ force: options.force,
807
+ resolvedDeployArgs,
808
+ dependencies: contractConfig.dependsOn
809
+ });
810
+ deployedContracts.push({ name: contractName, contractId: result.contractId });
811
+ }
812
+ return {
813
+ network,
814
+ deployedContracts
815
+ };
816
+ }
817
+
818
+ // src/contracts/generate-bindings.ts
819
+ var import_promises5 = require("fs/promises");
820
+ var import_node_path6 = __toESM(require("path"), 1);
821
+ async function generateBindings(options) {
822
+ const cwd = options.cwd ?? process.cwd();
823
+ const network = resolveNetwork(options.config, options.networkName);
824
+ const artifacts = await readArtifacts(cwd);
825
+ const contractArtifact = artifacts.networks[network.name]?.contracts[options.contractName];
826
+ if (!contractArtifact) {
827
+ throw new CaatingaError(
828
+ `No deployed artifact found for "${options.contractName}" on "${network.name}".`,
829
+ CaatingaErrorCode.ARTIFACT_NOT_FOUND,
830
+ "Run caatinga deploy for this contract and network before generating bindings."
831
+ );
832
+ }
833
+ await checkBinary("stellar", "Install Stellar CLI before running caatinga generate.", {
834
+ allowUntestedStellarCli: options.allowUntestedStellarCli
835
+ });
836
+ const outputDir = import_node_path6.default.resolve(cwd, options.config.frontend.bindingsOutput, options.contractName);
837
+ await (0, import_promises5.mkdir)(outputDir, { recursive: true });
838
+ const result = await runCommand("stellar", [
839
+ "contract",
840
+ "bindings",
841
+ "typescript",
842
+ "--contract-id",
843
+ contractArtifact.contractId,
844
+ "--output-dir",
845
+ outputDir,
846
+ "--overwrite",
847
+ "--rpc-url",
848
+ network.config.rpcUrl,
849
+ "--network-passphrase",
850
+ network.config.networkPassphrase
851
+ ], {
852
+ cwd,
853
+ allowUntestedStellarCli: options.allowUntestedStellarCli,
854
+ failureCode: CaatingaErrorCode.BINDINGS_FAILED
855
+ });
856
+ return {
857
+ contractName: options.contractName,
858
+ network,
859
+ outputDir,
860
+ output: result.all || result.stdout
861
+ };
862
+ }
863
+
864
+ // src/contracts/invoke-contract.ts
865
+ function parseInvokeTarget(target) {
866
+ const [contractName, method, extra] = target.split(".");
867
+ if (!contractName || !method || extra) {
868
+ throw new CaatingaError(
869
+ `Invalid invoke target "${target}".`,
870
+ CaatingaErrorCode.INVOKE_TARGET_INVALID,
871
+ "Use the format contract.method, for example counter.increment."
872
+ );
873
+ }
874
+ return { contractName, method };
875
+ }
876
+ async function invokeContract(options) {
877
+ const cwd = options.cwd ?? process.cwd();
878
+ const network = resolveNetwork(options.config, options.networkName);
879
+ const target = parseInvokeTarget(options.target);
880
+ const source = assertSafeSourceAccount(options.source);
881
+ const artifacts = await readArtifacts(cwd);
882
+ const contractArtifact = artifacts.networks[network.name]?.contracts[target.contractName];
883
+ if (!contractArtifact) {
884
+ throw new CaatingaError(
885
+ `No deployed artifact found for "${target.contractName}" on "${network.name}".`,
886
+ CaatingaErrorCode.ARTIFACT_NOT_FOUND,
887
+ "Run caatinga deploy for this contract and network before invoking it."
888
+ );
889
+ }
890
+ await checkBinary("stellar", "Install Stellar CLI before running caatinga invoke.", {
891
+ allowUntestedStellarCli: options.allowUntestedStellarCli
892
+ });
893
+ const result = await runCommand("stellar", [
894
+ "contract",
895
+ "invoke",
896
+ "--id",
897
+ contractArtifact.contractId,
898
+ "--source-account",
899
+ source,
900
+ "--rpc-url",
901
+ network.config.rpcUrl,
902
+ "--network-passphrase",
903
+ network.config.networkPassphrase,
904
+ "--",
905
+ target.method,
906
+ ...options.args ?? []
907
+ ], {
908
+ cwd,
909
+ allowUntestedStellarCli: options.allowUntestedStellarCli,
910
+ failureCode: CaatingaErrorCode.INVOKE_FAILED
911
+ });
912
+ return {
913
+ target,
914
+ network,
915
+ result: result.stdout || result.all
916
+ };
917
+ }
918
+
919
+ // src/templates/create-project-from-template.ts
920
+ var import_promises6 = require("fs/promises");
921
+ var import_node_path7 = __toESM(require("path"), 1);
922
+ var import_zod6 = require("zod");
923
+
924
+ // src/templates/template-manifest.schema.ts
925
+ var import_zod5 = require("zod");
926
+ var import_semver2 = __toESM(require("semver"), 1);
927
+ var CURRENT_TEMPLATE_VERSION = 1;
928
+ var TemplateManifestSchema = import_zod5.z.object({
929
+ name: import_zod5.z.string().min(1),
930
+ version: import_zod5.z.string().min(1),
931
+ description: import_zod5.z.string().optional(),
932
+ caatinga: import_zod5.z.object({
933
+ compatibleCore: import_zod5.z.string().min(1),
934
+ templateVersion: import_zod5.z.number().int().positive()
935
+ }),
936
+ frontend: import_zod5.z.object({
937
+ framework: import_zod5.z.enum(["vite-react", "next", "astro"]),
938
+ packageManager: import_zod5.z.enum(["npm", "pnpm", "yarn", "bun"]).default("npm")
939
+ }),
940
+ contracts: import_zod5.z.object({
941
+ path: import_zod5.z.string(),
942
+ default: import_zod5.z.string().optional()
943
+ }),
944
+ files: import_zod5.z.object({
945
+ config: import_zod5.z.string().default("caatinga.config.ts"),
946
+ artifacts: import_zod5.z.string().default("caatinga.artifacts.json")
947
+ })
948
+ });
949
+ function isCoreVersionCompatible(range, coreVersion = CAATINGA_CORE_VERSION) {
950
+ return import_semver2.default.satisfies(coreVersion, range);
951
+ }
952
+
953
+ // src/templates/create-project-from-template.ts
954
+ async function createProjectFromTemplate(options) {
955
+ const targetDir = import_node_path7.default.resolve(options.targetDir);
956
+ const templateDir = import_node_path7.default.resolve(options.templateDir);
957
+ try {
958
+ await (0, import_promises6.stat)(templateDir);
959
+ } catch {
960
+ throw new CaatingaError(
961
+ `Template directory was not found: ${templateDir}`,
962
+ CaatingaErrorCode.TEMPLATE_NOT_FOUND,
963
+ "Use a bundled Caatinga template or set CAATINGA_TEMPLATES_DIR for local development."
964
+ );
965
+ }
966
+ const manifest = await readTemplateManifest(templateDir);
967
+ await (0, import_promises6.mkdir)(targetDir, { recursive: true });
968
+ await (0, import_promises6.cp)(templateDir, targetDir, {
969
+ recursive: true,
970
+ force: false,
971
+ errorOnExist: true
972
+ });
973
+ await replaceTemplateVariables(targetDir, options.projectName);
974
+ await writeArtifacts(createInitialArtifacts(options.projectName), targetDir);
975
+ return { targetDir, template: manifest };
976
+ }
977
+ async function readTemplateManifest(templateDir) {
978
+ const manifestPath = import_node_path7.default.join(templateDir, "caatinga.template.json");
979
+ try {
980
+ const rawManifest = await (0, import_promises6.readFile)(manifestPath, "utf8");
981
+ const manifest = TemplateManifestSchema.parse(JSON.parse(rawManifest));
982
+ if (manifest.caatinga.templateVersion !== CURRENT_TEMPLATE_VERSION) {
983
+ throw new CaatingaError(
984
+ "Template is not compatible with this Caatinga version.",
985
+ CaatingaErrorCode.TEMPLATE_INCOMPATIBLE,
986
+ "Use a compatible template version or upgrade Caatinga."
987
+ );
988
+ }
989
+ if (!isCoreVersionCompatible(manifest.caatinga.compatibleCore)) {
990
+ throw new CaatingaError(
991
+ "Template is not compatible with this Caatinga version.",
992
+ CaatingaErrorCode.TEMPLATE_INCOMPATIBLE,
993
+ "Use a compatible template version or upgrade Caatinga."
994
+ );
995
+ }
996
+ return manifest;
997
+ } catch (error) {
998
+ if (error.code === "ENOENT") {
999
+ throw new CaatingaError(
1000
+ "Template manifest was not found.",
1001
+ CaatingaErrorCode.TEMPLATE_MANIFEST_NOT_FOUND,
1002
+ "Add a caatinga.template.json file to the template root."
1003
+ );
1004
+ }
1005
+ if (error instanceof CaatingaError) {
1006
+ throw error;
1007
+ }
1008
+ if (error instanceof SyntaxError || error instanceof import_zod6.z.ZodError) {
1009
+ throw new CaatingaError(
1010
+ "Template manifest is invalid.",
1011
+ CaatingaErrorCode.INVALID_TEMPLATE_MANIFEST,
1012
+ "Fix caatinga.template.json so it is valid JSON and matches the template manifest schema."
1013
+ );
1014
+ }
1015
+ throw error;
1016
+ }
1017
+ }
1018
+ async function replaceTemplateVariables(dir, projectName) {
1019
+ const entries = await (0, import_promises6.readdir)(dir);
1020
+ await Promise.all(entries.map(async (entry) => {
1021
+ const entryPath = import_node_path7.default.join(dir, entry);
1022
+ const entryStat = await (0, import_promises6.stat)(entryPath);
1023
+ if (entryStat.isDirectory()) {
1024
+ await replaceTemplateVariables(entryPath, projectName);
1025
+ return;
1026
+ }
1027
+ if (!isTextTemplateFile(entryPath)) {
1028
+ return;
1029
+ }
1030
+ const content = await (0, import_promises6.readFile)(entryPath, "utf8");
1031
+ await (0, import_promises6.writeFile)(entryPath, content.replaceAll("__PROJECT_NAME__", projectName), "utf8");
1032
+ }));
1033
+ }
1034
+ function isTextTemplateFile(filePath) {
1035
+ return [
1036
+ ".json",
1037
+ ".md",
1038
+ ".rs",
1039
+ ".toml",
1040
+ ".ts",
1041
+ ".tsx",
1042
+ ".css",
1043
+ ".html"
1044
+ ].includes(import_node_path7.default.extname(filePath));
1045
+ }
1046
+
1047
+ // src/ci/is-transient-testnet-smoke-failure.ts
1048
+ var NO_RETRY_CAATINGA_SUBSTRINGS = [
1049
+ "CAATINGA_UNSUPPORTED_CLI_VERSION",
1050
+ "CAATINGA_UNTESTED_CLI_VERSION",
1051
+ "CAATINGA_STELLAR_CLI_VERSION_PARSE_FAILED",
1052
+ "CAATINGA_STELLAR_CLI_NOT_FOUND",
1053
+ "CAATINGA_INVALID_CONFIG",
1054
+ "CAATINGA_CONFIG_NOT_FOUND"
1055
+ ];
1056
+ var TRANSIENT_PATTERN = /timeout|i\/o timeout|econnreset|connection reset|503|502|429|rate limit|temporar|bad gateway|fetch failed|network error|unavailable/i;
1057
+ function isTransientTestnetSmokeFailure(logText) {
1058
+ if (!logText.trim()) {
1059
+ return false;
1060
+ }
1061
+ for (const marker of NO_RETRY_CAATINGA_SUBSTRINGS) {
1062
+ if (logText.includes(marker)) {
1063
+ return false;
1064
+ }
1065
+ }
1066
+ return TRANSIENT_PATTERN.test(logText);
1067
+ }
1068
+ // Annotate the CommonJS export names for ESM import in node:
1069
+ 0 && (module.exports = {
1070
+ CAATINGA_CORE_VERSION,
1071
+ CaatingaArtifactsSchema,
1072
+ CaatingaConfigSchema,
1073
+ CaatingaError,
1074
+ CaatingaErrorCode,
1075
+ STELLAR_CLI_MIN_VERSION,
1076
+ STELLAR_CLI_TESTED_MAX_VERSION,
1077
+ TemplateManifestSchema,
1078
+ WELL_KNOWN_NETWORKS,
1079
+ assertSupportedStellarCliVersion,
1080
+ buildContract,
1081
+ buildDependencyGraph,
1082
+ checkBinary,
1083
+ createInitialArtifacts,
1084
+ createProjectFromTemplate,
1085
+ defineConfig,
1086
+ deployContract,
1087
+ deployContractGraph,
1088
+ generateBindings,
1089
+ invokeContract,
1090
+ isTransientTestnetSmokeFailure,
1091
+ loadConfig,
1092
+ parseContractId,
1093
+ parseInvokeTarget,
1094
+ parseStellarCliVersion,
1095
+ readArtifacts,
1096
+ resolveContract,
1097
+ resolveDeployArgs,
1098
+ resolveDeployOrder,
1099
+ resolveNetwork,
1100
+ runCommand,
1101
+ toCaatingaError,
1102
+ updateArtifact,
1103
+ writeArtifacts
1104
+ });