@lukoweb/apitogo 0.1.116 → 0.1.119

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/cli/cli.js CHANGED
@@ -5067,12 +5067,12 @@ async function loadZudokuConfigWithMeta(rootDir) {
5067
5067
  };
5068
5068
  return configWithMetadata;
5069
5069
  }
5070
- function findOutputPathOfServerConfig(output3) {
5071
- if (Array.isArray(output3)) {
5070
+ function findOutputPathOfServerConfig(output4) {
5071
+ if (Array.isArray(output4)) {
5072
5072
  throw new Error("Expected a single output, but got an array");
5073
5073
  }
5074
- if ("output" in output3) {
5075
- const result = output3.output.find(
5074
+ if ("output" in output4) {
5075
+ const result = output4.output.find(
5076
5076
  (o) => "isEntry" in o && o.isEntry && serverConfigOutputFiles.includes(o.fileName)
5077
5077
  );
5078
5078
  if (result) {
@@ -5471,7 +5471,8 @@ function printWarningToConsole(message) {
5471
5471
  console.error(message);
5472
5472
  }
5473
5473
  async function printCriticalFailureToConsoleAndExit(message) {
5474
- console.error(colors.bold(colors.red(message)));
5474
+ const text = typeof message === "string" && message.trim() === "" ? "Command failed with no further details." : message;
5475
+ console.error(colors.bold(colors.red(text)));
5475
5476
  await Sentry.close(MAX_WAIT_PENDING_TIME_MS).then(() => {
5476
5477
  process.exit(1);
5477
5478
  });
@@ -5801,7 +5802,7 @@ import {
5801
5802
  // package.json
5802
5803
  var package_default = {
5803
5804
  name: "@lukoweb/apitogo",
5804
- version: "0.1.116",
5805
+ version: "0.1.119",
5805
5806
  type: "module",
5806
5807
  sideEffects: [
5807
5808
  "**/*.css",
@@ -7632,13 +7633,13 @@ var generateCode = (schema2, filePath) => {
7632
7633
 
7633
7634
  // src/vite/api/SchemaManager.ts
7634
7635
  var FALLBACK_VERSION = "default";
7635
- var parseInputString = (input4) => {
7636
- const idx = input4.indexOf("?");
7636
+ var parseInputString = (input5) => {
7637
+ const idx = input5.indexOf("?");
7637
7638
  if (idx === -1)
7638
- return { filePath: input4, params: {} };
7639
+ return { filePath: input5, params: {} };
7639
7640
  return {
7640
- filePath: input4.slice(0, idx),
7641
- params: Object.fromEntries(new URLSearchParams(input4.slice(idx)))
7641
+ filePath: input5.slice(0, idx),
7642
+ params: Object.fromEntries(new URLSearchParams(input5.slice(idx)))
7642
7643
  };
7643
7644
  };
7644
7645
  var canonicalParams = (params) => Object.entries(params).sort(([a], [b]) => a.localeCompare(b)).map(([k, v]) => `${k}=${v}`).join("&");
@@ -7674,8 +7675,8 @@ var SchemaManager = class {
7674
7675
  ...processors
7675
7676
  ];
7676
7677
  }
7677
- getPathForFile = (input4, params) => {
7678
- const filePath = path11.resolve(this.config.__meta.rootDir, input4);
7678
+ getPathForFile = (input5, params) => {
7679
+ const filePath = path11.resolve(this.config.__meta.rootDir, input5);
7679
7680
  const apis = ensureArray(this.config.apis ?? []);
7680
7681
  for (const apiConfig of apis) {
7681
7682
  if (!apiConfig || apiConfig.type !== "file" || !apiConfig.path) continue;
@@ -7685,12 +7686,12 @@ var SchemaManager = class {
7685
7686
  if (match) return apiConfig.path;
7686
7687
  }
7687
7688
  };
7688
- processSchema = async (input4) => {
7689
- const filePath = path11.resolve(this.config.__meta.rootDir, input4.input);
7690
- const params = input4.params;
7691
- const configuredPath = this.getPathForFile(input4.input, params);
7689
+ processSchema = async (input5) => {
7690
+ const filePath = path11.resolve(this.config.__meta.rootDir, input5.input);
7691
+ const params = input5.params;
7692
+ const configuredPath = this.getPathForFile(input5.input, params);
7692
7693
  if (!configuredPath) {
7693
- console.warn(`No path found for file ${input4.input}`);
7694
+ console.warn(`No path found for file ${input5.input}`);
7694
7695
  return;
7695
7696
  }
7696
7697
  const parser = new $RefParser2();
@@ -7797,20 +7798,20 @@ var SchemaManager = class {
7797
7798
  if (apiConfig.type !== "file" || !apiConfig.path) continue;
7798
7799
  const inputs = normalizeInputs(apiConfig.input);
7799
7800
  if (inputs.length === 0) throw new Error("No schema found");
7800
- this.processedSchemas[apiConfig.path] = inputs.map((input4) => ({
7801
+ this.processedSchemas[apiConfig.path] = inputs.map((input5) => ({
7801
7802
  schema: {},
7802
7803
  version: "",
7803
- path: input4.path ?? "",
7804
- label: input4.label,
7805
- inputPath: path11.resolve(this.config.__meta.rootDir, input4.input),
7806
- params: input4.params,
7804
+ path: input5.path ?? "",
7805
+ label: input5.label,
7806
+ inputPath: path11.resolve(this.config.__meta.rootDir, input5.input),
7807
+ params: input5.params,
7807
7808
  importKey: "",
7808
7809
  downloadUrl: "",
7809
7810
  processedJsonPath: "",
7810
7811
  processedTime: 0
7811
7812
  }));
7812
7813
  const results = await Promise.allSettled(
7813
- inputs.map((input4) => this.processSchema(input4))
7814
+ inputs.map((input5) => this.processSchema(input5))
7814
7815
  );
7815
7816
  const errors = results.flatMap(
7816
7817
  (r) => r.status === "rejected" ? r.reason : []
@@ -7889,7 +7890,7 @@ import { readFile as readFile2 } from "node:fs/promises";
7889
7890
  import matter from "gray-matter";
7890
7891
  import { parse, stringify as stringify2 } from "yaml";
7891
7892
  var yaml = {
7892
- parse: (input4) => parse(input4) ?? {},
7893
+ parse: (input5) => parse(input5) ?? {},
7893
7894
  stringify: (obj) => stringify2(obj)
7894
7895
  };
7895
7896
  var readFrontmatter = async (filePath) => {
@@ -10162,25 +10163,25 @@ function generateOutput({
10162
10163
  });
10163
10164
  }
10164
10165
  }
10165
- const output3 = {
10166
+ const output4 = {
10166
10167
  version: 3,
10167
10168
  framework: {
10168
10169
  version: pkgJson.version
10169
10170
  },
10170
10171
  routes
10171
10172
  };
10172
- return output3;
10173
+ return output4;
10173
10174
  }
10174
10175
  async function writeOutput(dir, {
10175
10176
  config: config2,
10176
10177
  redirects,
10177
10178
  rewrites
10178
10179
  }) {
10179
- const output3 = generateOutput({ config: config2, redirects, rewrites });
10180
+ const output4 = generateOutput({ config: config2, redirects, rewrites });
10180
10181
  const outputDir = process.env.VERCEL ? path27.join(dir, ".vercel/output") : path27.join(dir, "dist/.output");
10181
10182
  await mkdir3(outputDir, { recursive: true });
10182
10183
  const outputFile = path27.join(outputDir, "config.json");
10183
- await writeFile4(outputFile, JSON.stringify(output3, null, 2), "utf-8");
10184
+ await writeFile4(outputFile, JSON.stringify(output4, null, 2), "utf-8");
10184
10185
  if (process.env.VERCEL) {
10185
10186
  console.log("Wrote Vercel output to", outputDir);
10186
10187
  }
@@ -10201,12 +10202,12 @@ init_invariant();
10201
10202
  init_joinUrl();
10202
10203
 
10203
10204
  // src/vite/reporter.ts
10204
- function writeLine(output3) {
10205
+ function writeLine(output4) {
10205
10206
  clearLine();
10206
- if (output3.length < process.stdout.columns) {
10207
- process.stdout.write(output3);
10207
+ if (output4.length < process.stdout.columns) {
10208
+ process.stdout.write(output4);
10208
10209
  } else {
10209
- process.stdout.write(output3.substring(0, process.stdout.columns - 1));
10210
+ process.stdout.write(output4.substring(0, process.stdout.columns - 1));
10210
10211
  }
10211
10212
  }
10212
10213
  function isTTY() {
@@ -10844,7 +10845,7 @@ async function parseErrorResponse(response) {
10844
10845
  } catch {
10845
10846
  bodyText = bodyText ?? await response.text().catch(() => void 0);
10846
10847
  }
10847
- const message = (problem ? formatProblemDetails(problem) : void 0) ?? bodyText?.trim() ?? `HTTP ${response.status} ${response.statusText}`;
10848
+ const message = (problem ? formatProblemDetails(problem) : void 0) || bodyText?.trim() || `HTTP ${response.status} ${response.statusText}`;
10848
10849
  return new PlatformApiError(message, response.status, problem);
10849
10850
  }
10850
10851
 
@@ -10876,7 +10877,7 @@ function isNetworkError(error) {
10876
10877
  const message = error.message.toLowerCase();
10877
10878
  return message.includes("fetch failed") || message.includes("network") || message.includes("econnreset") || message.includes("etimedout") || message.includes("socket hang up") || error.name === "AbortError" || error.name === "TypeError";
10878
10879
  }
10879
- async function fetchWithRetry(input4, init4, options) {
10880
+ async function fetchWithRetry(input5, init4, options) {
10880
10881
  const maxRetries = options?.maxRetries ?? 3;
10881
10882
  const baseDelayMs = options?.baseDelayMs ?? 1e3;
10882
10883
  const maxDelayMs = options?.maxDelayMs ?? 15e3;
@@ -10886,7 +10887,7 @@ async function fetchWithRetry(input4, init4, options) {
10886
10887
  let attempt = 0;
10887
10888
  while (true) {
10888
10889
  try {
10889
- const response = await fetch(input4, init4);
10890
+ const response = await fetch(input5, init4);
10890
10891
  const retriableStatus = isRetriableHttpStatus(response.status);
10891
10892
  const mayRetryStatus = retriableStatus && (isSafeMethod || response.status === 429 || retryMutatingOnServerError);
10892
10893
  if (mayRetryStatus && attempt < maxRetries) {
@@ -12762,15 +12763,15 @@ function runCommand(command2, args, cwd, env) {
12762
12763
  env: env ? { ...process.env, ...env } : process.env,
12763
12764
  shell: process.platform === "win32"
12764
12765
  });
12765
- let output3 = "";
12766
+ let output4 = "";
12766
12767
  child.stdout.on("data", (chunk) => {
12767
- output3 += chunk.toString();
12768
+ output4 += chunk.toString();
12768
12769
  });
12769
12770
  child.stderr.on("data", (chunk) => {
12770
- output3 += chunk.toString();
12771
+ output4 += chunk.toString();
12771
12772
  });
12772
12773
  child.on("error", reject);
12773
- child.on("close", (exitCode) => resolve({ exitCode, output: output3 }));
12774
+ child.on("close", (exitCode) => resolve({ exitCode, output: output4 }));
12774
12775
  });
12775
12776
  }
12776
12777
  async function runNpmInstall(sourceDirectory, options) {
@@ -13249,7 +13250,15 @@ async function checkPublishReadiness(client, _config, args) {
13249
13250
  // src/cli/check/handler.ts
13250
13251
  async function check(argv) {
13251
13252
  const sourceDirectory = path41.resolve(process.cwd(), argv.dir);
13252
- const config2 = loadConfig();
13253
+ let config2;
13254
+ try {
13255
+ config2 = loadConfig();
13256
+ } catch (error) {
13257
+ await printCriticalFailureToConsoleAndExit(
13258
+ error instanceof Error ? error.message : String(error)
13259
+ );
13260
+ return;
13261
+ }
13253
13262
  const client = new PlatformApiClient(config2);
13254
13263
  let result;
13255
13264
  try {
@@ -14419,15 +14428,15 @@ function runCommand2(command2, args, cwd) {
14419
14428
  env: process.env,
14420
14429
  shell: process.platform === "win32"
14421
14430
  });
14422
- let output3 = "";
14431
+ let output4 = "";
14423
14432
  child.stdout.on("data", (chunk) => {
14424
- output3 += chunk.toString();
14433
+ output4 += chunk.toString();
14425
14434
  });
14426
14435
  child.stderr.on("data", (chunk) => {
14427
- output3 += chunk.toString();
14436
+ output4 += chunk.toString();
14428
14437
  });
14429
14438
  child.on("error", reject);
14430
- child.on("close", (exitCode) => resolve({ exitCode, output: output3 }));
14439
+ child.on("close", (exitCode) => resolve({ exitCode, output: output4 }));
14431
14440
  });
14432
14441
  }
14433
14442
  function buildCreateApitogoCliArgs(invocationArgs, projectName, options) {
@@ -14613,10 +14622,10 @@ function patchApisConfig(content, config2) {
14613
14622
  const asArray = match[0].includes("apis: [");
14614
14623
  return content.replace(APIS_CONFIG_PATTERN, renderApisConfig(config2, asArray));
14615
14624
  }
14616
- function patchApitogoConfigOpenApiToFile(content, input4 = "./openapi.json") {
14625
+ function patchApitogoConfigOpenApiToFile(content, input5 = "./openapi.json") {
14617
14626
  return patchApisConfig(content, {
14618
14627
  type: "file",
14619
- input: input4,
14628
+ input: input5,
14620
14629
  path: "api"
14621
14630
  });
14622
14631
  }
@@ -14828,7 +14837,7 @@ async function discoverOpenApiByMode(siteDirectory, mode) {
14828
14837
  async function wireDevPortalOpenApi(sourceDirectory, openApiPath) {
14829
14838
  const resolvedSource = path47.resolve(sourceDirectory);
14830
14839
  const resolvedOpenApi = path47.resolve(openApiPath);
14831
- const input4 = toSiteRelativeOpenApiInput(resolvedSource, resolvedOpenApi);
14840
+ const input5 = toSiteRelativeOpenApiInput(resolvedSource, resolvedOpenApi);
14832
14841
  const validation = await validateOpenApiFile(resolvedOpenApi);
14833
14842
  if (!validation.valid) {
14834
14843
  return {
@@ -14842,7 +14851,7 @@ async function wireDevPortalOpenApi(sourceDirectory, openApiPath) {
14842
14851
  const raw = await readFile12(jsonConfigPath, "utf8");
14843
14852
  const siteConfig = JSON.parse(raw);
14844
14853
  const updated = applyOpenApiToSiteConfig(siteConfig, {
14845
- input: input4,
14854
+ input: input5,
14846
14855
  apiPath: "api"
14847
14856
  });
14848
14857
  await writeFile11(
@@ -14855,7 +14864,7 @@ async function wireDevPortalOpenApi(sourceDirectory, openApiPath) {
14855
14864
  const tsxConfigPath = path47.join(resolvedSource, "apitogo.config.tsx");
14856
14865
  const configContent = await readFile12(tsxConfigPath, "utf8");
14857
14866
  try {
14858
- const patched = patchApitogoConfigOpenApiToFile(configContent, input4);
14867
+ const patched = patchApitogoConfigOpenApiToFile(configContent, input5);
14859
14868
  await writeFile11(tsxConfigPath, patched);
14860
14869
  } catch (error) {
14861
14870
  return {
@@ -14868,13 +14877,13 @@ async function wireDevPortalOpenApi(sourceDirectory, openApiPath) {
14868
14877
  const manifest = await readManifest(resolvedSource) ?? createScaffoldManifest();
14869
14878
  manifest.backend = {
14870
14879
  ...manifest.backend,
14871
- openApiPath: input4
14880
+ openApiPath: input5
14872
14881
  };
14873
14882
  await writeManifest(resolvedSource, manifest);
14874
14883
  return {
14875
14884
  status: "succeeded",
14876
14885
  openApiPath: resolvedOpenApi,
14877
- openApiInput: input4,
14886
+ openApiInput: input5,
14878
14887
  openApiTitle: validation.title ?? null,
14879
14888
  openApiVersion: validation.version
14880
14889
  };
@@ -15295,12 +15304,12 @@ function mergeDocumentationNavigation(navigation, docRoutePaths, options) {
15295
15304
  }
15296
15305
  return [documentation, ...rest];
15297
15306
  }
15298
- function applyOpenApiToJsonConfig(config2, input4) {
15307
+ function applyOpenApiToJsonConfig(config2, input5) {
15299
15308
  const next = { ...config2 };
15300
15309
  next.apis = [
15301
15310
  {
15302
15311
  type: "file",
15303
- input: input4,
15312
+ input: input5,
15304
15313
  path: "api"
15305
15314
  }
15306
15315
  ];
@@ -15343,15 +15352,15 @@ function buildLimits(rateLimitCalls, monthlyQuota) {
15343
15352
  quota: { calls: monthlyQuota, renewalPeriodDays: 30 }
15344
15353
  };
15345
15354
  }
15346
- function buildPlanItemFromWizard(input4) {
15347
- const sku = input4.sku ?? slugifyPlanSku(input4.displayName);
15355
+ function buildPlanItemFromWizard(input5) {
15356
+ const sku = input5.sku ?? slugifyPlanSku(input5.displayName);
15348
15357
  const item = {
15349
15358
  sku,
15350
- displayName: input4.displayName,
15351
- priceAmount: input4.priceAmount,
15352
- limits: buildLimits(input4.rateLimitCalls, input4.monthlyQuota)
15359
+ displayName: input5.displayName,
15360
+ priceAmount: input5.priceAmount,
15361
+ limits: buildLimits(input5.rateLimitCalls, input5.monthlyQuota)
15353
15362
  };
15354
- if (input4.priceAmount > 0) {
15363
+ if (input5.priceAmount > 0) {
15355
15364
  item.priceCurrency = "usd";
15356
15365
  item.billingPeriod = "month";
15357
15366
  }
@@ -17030,13 +17039,13 @@ async function resolveActionKeysOrAllProjectActions(manifestPlan, existingPlan,
17030
17039
  var GATEWAY_PLAN_SORT_TEMP_OFFSET = 1e3;
17031
17040
  function buildGatewayPlanSortTargetsFromIds(manifestPlans, planIdsBySku, skuById) {
17032
17041
  const targets = [];
17033
- for (const [index, input4] of manifestPlans.entries()) {
17034
- const key = input4.sku.toLowerCase();
17042
+ for (const [index, input5] of manifestPlans.entries()) {
17043
+ const key = input5.sku.toLowerCase();
17035
17044
  const planId = planIdsBySku.get(key);
17036
17045
  if (!planId) {
17037
- throw new Error(`Gateway plan '${input4.sku}' was not found; upsert plans before reordering.`);
17046
+ throw new Error(`Gateway plan '${input5.sku}' was not found; upsert plans before reordering.`);
17038
17047
  }
17039
- const sku = skuById?.get(key)?.sku ?? input4.sku;
17048
+ const sku = skuById?.get(key)?.sku ?? input5.sku;
17040
17049
  targets.push({ planId, sku, sortOrder: index });
17041
17050
  }
17042
17051
  return targets;
@@ -17082,12 +17091,12 @@ async function upsertGatewayPlansFromManifest(client, config2, projectId, plans,
17082
17091
  return cachedProjectActionKeys;
17083
17092
  };
17084
17093
  for (const [index, inputRaw] of plans.entries()) {
17085
- const input4 = normalizePlanForGatewayApi(inputRaw);
17086
- const found = bySku.get(input4.sku.toLowerCase());
17094
+ const input5 = normalizePlanForGatewayApi(inputRaw);
17095
+ const found = bySku.get(input5.sku.toLowerCase());
17087
17096
  if (found) {
17088
17097
  if (options?.syncActionsOnly) {
17089
17098
  const actionKeys = await resolveActionKeysOrAllProjectActions(
17090
- input4,
17099
+ input5,
17091
17100
  found,
17092
17101
  projectActionKeys
17093
17102
  );
@@ -17100,29 +17109,29 @@ async function upsertGatewayPlansFromManifest(client, config2, projectId, plans,
17100
17109
  includedActionKeys: actionKeys
17101
17110
  });
17102
17111
  results.push(JSON.parse(patchedJson2));
17103
- planIdsBySku.set(input4.sku.toLowerCase(), found.id);
17112
+ planIdsBySku.set(input5.sku.toLowerCase(), found.id);
17104
17113
  continue;
17105
17114
  }
17106
17115
  const patchArgs = {
17107
17116
  projectId,
17108
17117
  planId: found.id,
17109
- displayName: input4.displayName,
17118
+ displayName: input5.displayName,
17110
17119
  isActive: true,
17111
- limitsJson: planLimitsForPlatform(input4),
17112
- priceAmount: input4.priceAmount,
17113
- priceCurrency: input4.priceCurrency,
17114
- billingPeriod: input4.billingPeriod ? normalizeBillingPeriod2(input4.billingPeriod) : void 0
17120
+ limitsJson: planLimitsForPlatform(input5),
17121
+ priceAmount: input5.priceAmount,
17122
+ priceCurrency: input5.priceCurrency,
17123
+ billingPeriod: input5.billingPeriod ? normalizeBillingPeriod2(input5.billingPeriod) : void 0
17115
17124
  };
17116
17125
  if (!options?.deferActionKeys) {
17117
17126
  patchArgs.includedActionKeys = await resolveActionKeysOrAllProjectActions(
17118
- input4,
17127
+ input5,
17119
17128
  found,
17120
17129
  projectActionKeys
17121
17130
  );
17122
17131
  }
17123
17132
  const patchedJson = await handlePatchGatewayPlan(client, config2, patchArgs);
17124
17133
  results.push(JSON.parse(patchedJson));
17125
- planIdsBySku.set(input4.sku.toLowerCase(), found.id);
17134
+ planIdsBySku.set(input5.sku.toLowerCase(), found.id);
17126
17135
  continue;
17127
17136
  }
17128
17137
  if (options?.syncActionsOnly) {
@@ -17130,19 +17139,19 @@ async function upsertGatewayPlansFromManifest(client, config2, projectId, plans,
17130
17139
  }
17131
17140
  const createdJson = await handleCreateGatewayPlan(client, config2, {
17132
17141
  projectId,
17133
- sku: input4.sku,
17134
- displayName: input4.displayName,
17135
- priceAmount: input4.priceAmount,
17136
- priceCurrency: input4.priceCurrency ?? "usd",
17137
- billingPeriod: normalizeBillingPeriod2(input4.billingPeriod),
17138
- limitsJson: planLimitsForPlatform(input4),
17139
- includedActionKeys: options?.deferActionKeys ? [] : await resolveActionKeysOrAllProjectActions(input4, void 0, projectActionKeys),
17142
+ sku: input5.sku,
17143
+ displayName: input5.displayName,
17144
+ priceAmount: input5.priceAmount,
17145
+ priceCurrency: input5.priceCurrency ?? "usd",
17146
+ billingPeriod: normalizeBillingPeriod2(input5.billingPeriod),
17147
+ limitsJson: planLimitsForPlatform(input5),
17148
+ includedActionKeys: options?.deferActionKeys ? [] : await resolveActionKeysOrAllProjectActions(input5, void 0, projectActionKeys),
17140
17149
  skipDefaultActions: true,
17141
17150
  sortOrder: index
17142
17151
  });
17143
17152
  const created = JSON.parse(createdJson);
17144
17153
  if (created.plan?.id) {
17145
- planIdsBySku.set(input4.sku.toLowerCase(), created.plan.id);
17154
+ planIdsBySku.set(input5.sku.toLowerCase(), created.plan.id);
17146
17155
  }
17147
17156
  results.push(created);
17148
17157
  }
@@ -18065,8 +18074,8 @@ async function prepareOpenApiServersForGatewayBuild(options) {
18065
18074
  try {
18066
18075
  const raw = await readFile16(path56.join(siteDirectory, APITOGO_CONFIG_FILENAME2), "utf8");
18067
18076
  const config2 = JSON.parse(raw);
18068
- const input4 = Array.isArray(config2.apis) ? config2.apis[0]?.input?.trim() : void 0;
18069
- openApiPath = resolveBackendOpenApiPath(input4, { siteDirectory });
18077
+ const input5 = Array.isArray(config2.apis) ? config2.apis[0]?.input?.trim() : void 0;
18078
+ openApiPath = resolveBackendOpenApiPath(input5, { siteDirectory });
18070
18079
  } catch {
18071
18080
  }
18072
18081
  }
@@ -18115,15 +18124,15 @@ function runDotnetPublish(projectDir, outputDir) {
18115
18124
  shell: process.platform === "win32"
18116
18125
  }
18117
18126
  );
18118
- let output3 = "";
18127
+ let output4 = "";
18119
18128
  child.stdout.on("data", (chunk) => {
18120
- output3 += chunk.toString();
18129
+ output4 += chunk.toString();
18121
18130
  });
18122
18131
  child.stderr.on("data", (chunk) => {
18123
- output3 += chunk.toString();
18132
+ output4 += chunk.toString();
18124
18133
  });
18125
18134
  child.on("error", reject);
18126
- child.on("close", (exitCode) => resolve({ exitCode, output: output3 }));
18135
+ child.on("close", (exitCode) => resolve({ exitCode, output: output4 }));
18127
18136
  });
18128
18137
  }
18129
18138
  async function findCsproj(projectDir) {
@@ -18210,12 +18219,12 @@ async function packageBackendDirectory(sourceDirectory) {
18210
18219
  `apitogo-backend-${Date.now()}-${Math.random().toString(36).slice(2)}.zip`
18211
18220
  );
18212
18221
  await new Promise((resolve, reject) => {
18213
- const output3 = createWriteStream2(zipPath);
18222
+ const output4 = createWriteStream2(zipPath);
18214
18223
  const archive = new ZipArchive({ zlib: { level: 6 } });
18215
- output3.on("close", () => resolve());
18224
+ output4.on("close", () => resolve());
18216
18225
  archive.on("error", reject);
18217
- output3.on("error", reject);
18218
- archive.pipe(output3);
18226
+ output4.on("error", reject);
18227
+ archive.pipe(output4);
18219
18228
  for (const rel of files) {
18220
18229
  archive.append(createReadStream2(path58.join(resolved, rel)), { name: rel.split(path58.sep).join("/") });
18221
18230
  }
@@ -19595,7 +19604,24 @@ async function resolveProjectIdForPublish(client, config2, args, wait, progress,
19595
19604
  const completedSteps = [];
19596
19605
  if (args.projectId) {
19597
19606
  const projectId = resolveProjectId(args.projectId, config2);
19598
- const project = await client.getProject(projectId);
19607
+ let project;
19608
+ try {
19609
+ project = await client.getProject(projectId);
19610
+ } catch (error) {
19611
+ if (isNotFoundError(error)) {
19612
+ return {
19613
+ blocked: true,
19614
+ payload: {
19615
+ status: "blocked",
19616
+ reason: "project_not_found",
19617
+ projectId,
19618
+ userMessage: `Project ${projectId} was not found. It may have been deleted, or it belongs to a different account than the one you're currently logged in as.`,
19619
+ nextStep: "create_or_fix_project"
19620
+ }
19621
+ };
19622
+ }
19623
+ throw error;
19624
+ }
19599
19625
  if (!isPlatformPlanUnselected(project.planTier)) {
19600
19626
  await ensureModulesProvisioned(
19601
19627
  client,
@@ -19609,7 +19635,7 @@ async function resolveProjectIdForPublish(client, config2, args, wait, progress,
19609
19635
  );
19610
19636
  }
19611
19637
  completedSteps.push({ step: "resolve_project", status: "succeeded", detail: { projectId } });
19612
- return { projectId, completedSteps };
19638
+ return { blocked: false, projectId, completedSteps };
19613
19639
  }
19614
19640
  if (!args.projectName?.trim()) {
19615
19641
  throw new Error("projectName is required when projectId is not provided.");
@@ -19631,7 +19657,7 @@ async function resolveProjectIdForPublish(client, config2, args, wait, progress,
19631
19657
  );
19632
19658
  const bootstrap = parseHandlerResult(bootstrapJson, "bootstrap_project");
19633
19659
  completedSteps.push({ step: "bootstrap_project", status: "succeeded", detail: bootstrap });
19634
- return { projectId: bootstrap.projectId, completedSteps };
19660
+ return { blocked: false, projectId: bootstrap.projectId, completedSteps };
19635
19661
  }
19636
19662
 
19637
19663
  // src/cli/platform/tools/dev-portal.ts
@@ -19660,12 +19686,12 @@ async function packageDirectoryAsTarGz(sourceDirectory, options) {
19660
19686
  `apitogo-docs-${Date.now()}-${Math.random().toString(36).slice(2)}.tgz`
19661
19687
  );
19662
19688
  await new Promise((resolve, reject) => {
19663
- const output3 = createWriteStream3(archivePath);
19689
+ const output4 = createWriteStream3(archivePath);
19664
19690
  const archive = new TarArchive({ gzip: true, gzipOptions: { level: 6 } });
19665
- output3.on("close", () => resolve());
19691
+ output4.on("close", () => resolve());
19666
19692
  archive.on("error", reject);
19667
- output3.on("error", reject);
19668
- archive.pipe(output3);
19693
+ output4.on("error", reject);
19694
+ archive.pipe(output4);
19669
19695
  for (const rel of files) {
19670
19696
  const entryName = entryPrefix + rel.split(path59.sep).join("/");
19671
19697
  archive.append(createReadStream3(path59.join(resolved, rel)), { name: entryName });
@@ -20547,13 +20573,13 @@ async function runApplyFromSiteDirectory(client, config2, args, progress) {
20547
20573
  const ledgerResume = resolveResumeStepFromLedger(ledger, PUBLISH_STEPS);
20548
20574
  const effectiveResumeFromStep = args.resumeFromStep ?? ledgerResume;
20549
20575
  let publicRouteWarnings = [];
20550
- if (shouldRunPublishStep("resolve_project", effectiveResumeFromStep, completedSteps)) {
20576
+ if (args.createNewProject || shouldRunPublishStep("resolve_project", effectiveResumeFromStep, completedSteps)) {
20551
20577
  const timer = new StepTimer();
20552
20578
  const resolved = await resolveProjectIdForPublish(
20553
20579
  client,
20554
20580
  config2,
20555
20581
  {
20556
- projectId: args.projectId ?? manifest.projectId,
20582
+ projectId: args.createNewProject ? void 0 : args.projectId ?? manifest.projectId,
20557
20583
  projectName: args.projectName ?? resolveProjectDisplayName(manifest)
20558
20584
  },
20559
20585
  wait,
@@ -20561,13 +20587,48 @@ async function runApplyFromSiteDirectory(client, config2, args, progress) {
20561
20587
  args.timeoutMs,
20562
20588
  args.pollIntervalMs
20563
20589
  );
20590
+ if (resolved.blocked) {
20591
+ return JSON.stringify(
20592
+ {
20593
+ ...resolved.payload,
20594
+ completedSteps,
20595
+ sourceDirectory: args.sourceDirectory
20596
+ },
20597
+ null,
20598
+ 2
20599
+ );
20600
+ }
20564
20601
  projectId = resolved.projectId;
20565
20602
  for (const step of resolved.completedSteps) {
20566
20603
  completedSteps.push(step);
20567
20604
  }
20568
20605
  recordStep("resolve_project", "succeeded", timer.finish({ projectId }));
20569
20606
  } else {
20570
- projectId = resolveProjectId(args.projectId ?? manifest.projectId, config2);
20607
+ const candidateProjectId = resolveProjectId(
20608
+ args.projectId ?? manifest.projectId,
20609
+ config2
20610
+ );
20611
+ try {
20612
+ await client.getProject(candidateProjectId);
20613
+ } catch (error) {
20614
+ if (isNotFoundError(error)) {
20615
+ return JSON.stringify(
20616
+ {
20617
+ status: "blocked",
20618
+ reason: "project_not_found",
20619
+ projectId: candidateProjectId,
20620
+ userMessage: `Project ${candidateProjectId} was not found. It may have been deleted, or it belongs to a different account than the one you're currently logged in as.`,
20621
+ nextStep: "create_or_fix_project",
20622
+ completedSteps,
20623
+ sourceDirectory: args.sourceDirectory
20624
+ },
20625
+ null,
20626
+ 2
20627
+ );
20628
+ }
20629
+ throw error;
20630
+ }
20631
+ projectId = candidateProjectId;
20571
20632
  recordStep("resolve_project", "skipped", new StepTimer().finish());
20572
20633
  }
20573
20634
  manifest.projectId = projectId;
@@ -21217,6 +21278,20 @@ function formatNonSuccessResultForHuman(parsed) {
21217
21278
  );
21218
21279
  return lines;
21219
21280
  }
21281
+ if (status2 === "blocked" && parsed.reason === "project_not_found") {
21282
+ const projectId = typeof parsed.projectId === "string" ? parsed.projectId : void 0;
21283
+ const lines = [
21284
+ typeof parsed.userMessage === "string" ? parsed.userMessage : `Deploy is blocked: project${projectId ? ` ${projectId}` : ""} was not found.`
21285
+ ];
21286
+ lines.push(
21287
+ "This usually means the project was deleted, or it belongs to a different account than the one you're logged in as.",
21288
+ "",
21289
+ "To fix this:",
21290
+ " Run `apitogo login` and confirm you're using the right account, then re-run `apitogo deploy`",
21291
+ ' Or create a new project: remove "projectId" from apitogo.config.json and re-run `apitogo deploy`'
21292
+ );
21293
+ return lines;
21294
+ }
21220
21295
  if (status2 === "blocked" && parsed.reason === "paid_gateway_plans_require_starter") {
21221
21296
  const lines = [];
21222
21297
  lines.push(
@@ -21376,6 +21451,33 @@ ${ensured.checkoutUrl}`
21376
21451
  return true;
21377
21452
  }
21378
21453
 
21454
+ // src/cli/apply/project-not-found-prompt.ts
21455
+ import { stdin as input4, stdout as output3 } from "node:process";
21456
+ import { createInterface as createInterface3 } from "node:readline/promises";
21457
+ async function resolveProjectNotFoundInteractively(payload, defaultProjectName) {
21458
+ const projectId = typeof payload.projectId === "string" ? payload.projectId : "";
21459
+ const message = typeof payload.userMessage === "string" ? payload.userMessage : `Project ${projectId} was not found.`;
21460
+ printWarningToConsole(message);
21461
+ printDiagnosticsToConsole(
21462
+ "This usually means the project was deleted, or it belongs to a different account than the one you're logged in as."
21463
+ );
21464
+ printDiagnosticsToConsole(
21465
+ "If that's unexpected, cancel here and run `apitogo login` to check your account."
21466
+ );
21467
+ printDiagnosticsToConsole("");
21468
+ const rl = createInterface3({ input: input4, output: output3 });
21469
+ try {
21470
+ const createAnswer = (await rl.question("Create a new project instead? [Y/n] ")).trim().toLowerCase();
21471
+ if (createAnswer === "n" || createAnswer === "no") {
21472
+ return null;
21473
+ }
21474
+ const nameAnswer = (await rl.question(`Project name [${defaultProjectName}]: `)).trim();
21475
+ return { projectName: nameAnswer || defaultProjectName };
21476
+ } finally {
21477
+ rl.close();
21478
+ }
21479
+ }
21480
+
21379
21481
  // src/cli/apply/handler.ts
21380
21482
  function normalizeOnly(only) {
21381
21483
  if (!only) return [];
@@ -21396,7 +21498,15 @@ function resultLooksFailed(payload) {
21396
21498
  }
21397
21499
  async function apply(argv) {
21398
21500
  const sourceDirectory = path63.resolve(process.cwd(), argv.dir);
21399
- const config2 = loadConfig();
21501
+ let config2;
21502
+ try {
21503
+ config2 = loadConfig();
21504
+ } catch (error) {
21505
+ await printCriticalFailureToConsoleAndExit(
21506
+ error instanceof Error ? error.message : String(error)
21507
+ );
21508
+ return;
21509
+ }
21400
21510
  const client = new PlatformApiClient(config2);
21401
21511
  let only;
21402
21512
  const onlyRaw = normalizeOnly(argv.only);
@@ -21412,18 +21522,22 @@ async function apply(argv) {
21412
21522
  }
21413
21523
  const platformPlan = argv.platformPlan?.trim();
21414
21524
  const progress = createConsoleProgressReporter();
21525
+ let effectiveProjectId = argv.projectId?.trim();
21526
+ let effectiveProjectName = argv.projectName?.trim();
21527
+ let createNewProject = false;
21415
21528
  const runOnce = (plan) => runApplyFromSiteDirectory(
21416
21529
  client,
21417
21530
  config2,
21418
21531
  {
21419
21532
  sourceDirectory,
21420
- projectId: argv.projectId?.trim(),
21421
- projectName: argv.projectName?.trim(),
21533
+ projectId: effectiveProjectId,
21534
+ projectName: effectiveProjectName,
21422
21535
  platformPlan: plan,
21423
21536
  only,
21424
21537
  force: argv.force,
21425
21538
  resumeFromStep: argv.resumeFrom?.trim(),
21426
- wait: argv.wait !== false
21539
+ wait: argv.wait !== false,
21540
+ createNewProject
21427
21541
  },
21428
21542
  progress
21429
21543
  );
@@ -21438,6 +21552,26 @@ async function apply(argv) {
21438
21552
  }
21439
21553
  let parsed = safeParseResult(result);
21440
21554
  const canPromptInteractively = !argv.json && Boolean(process.stdin.isTTY) && Boolean(process.stdout.isTTY);
21555
+ if (canPromptInteractively && parsed?.status === "blocked" && parsed.reason === "project_not_found") {
21556
+ const resolution = await resolveProjectNotFoundInteractively(
21557
+ parsed,
21558
+ path63.basename(sourceDirectory)
21559
+ );
21560
+ if (resolution) {
21561
+ effectiveProjectId = void 0;
21562
+ effectiveProjectName = resolution.projectName;
21563
+ createNewProject = true;
21564
+ try {
21565
+ result = await runOnce(platformPlan);
21566
+ } catch (error) {
21567
+ await printCriticalFailureToConsoleAndExit(
21568
+ error instanceof Error ? error.message : String(error)
21569
+ );
21570
+ return;
21571
+ }
21572
+ parsed = safeParseResult(result);
21573
+ }
21574
+ }
21441
21575
  if (canPromptInteractively && parsed?.status === "blocked" && parsed.reason === "platform_plan_unselected") {
21442
21576
  const resolved = await resolvePlatformPlanInteractively(
21443
21577
  client,
@@ -21852,10 +21986,10 @@ function siteRelative(siteDirectory, filePath) {
21852
21986
  function formatOpenApiDiscoveryLines(siteDirectory, openApiDiscovery) {
21853
21987
  const status2 = String(openApiDiscovery.status ?? "unknown");
21854
21988
  if (status2 === "wired") {
21855
- const input4 = typeof openApiDiscovery.openApiInput === "string" ? openApiDiscovery.openApiInput : typeof openApiDiscovery.openApiPath === "string" ? siteRelative(siteDirectory, openApiDiscovery.openApiPath) : "OpenAPI";
21989
+ const input5 = typeof openApiDiscovery.openApiInput === "string" ? openApiDiscovery.openApiInput : typeof openApiDiscovery.openApiPath === "string" ? siteRelative(siteDirectory, openApiDiscovery.openApiPath) : "OpenAPI";
21856
21990
  const title = typeof openApiDiscovery.openApiTitle === "string" ? ` (${openApiDiscovery.openApiTitle})` : "";
21857
21991
  const apiPath = typeof openApiDiscovery.apiReferencePath === "string" ? openApiDiscovery.apiReferencePath : "/api";
21858
- return [`OpenAPI: wired ${input4}${title} \u2192 ${apiPath}`];
21992
+ return [`OpenAPI: wired ${input5}${title} \u2192 ${apiPath}`];
21859
21993
  }
21860
21994
  if (status2 === "skipped") {
21861
21995
  return ["OpenAPI: search skipped"];
@@ -21907,23 +22041,23 @@ async function pathExists6(filePath) {
21907
22041
  }
21908
22042
  }
21909
22043
  async function wireOpenApiIntoJsonConfig(siteDirectory, openApiPath) {
21910
- const input4 = toSiteRelativeOpenApiInput(siteDirectory, openApiPath);
22044
+ const input5 = toSiteRelativeOpenApiInput(siteDirectory, openApiPath);
21911
22045
  const jsonConfigPath = path65.join(siteDirectory, "apitogo.config.json");
21912
22046
  const raw = await readFile19(jsonConfigPath, "utf8");
21913
22047
  const siteConfig = JSON.parse(raw);
21914
22048
  const updated = applyOpenApiToSiteConfig(siteConfig, {
21915
- input: input4,
22049
+ input: input5,
21916
22050
  apiPath: "api"
21917
22051
  });
21918
22052
  const backend = updated.backend && typeof updated.backend === "object" && !Array.isArray(updated.backend) ? { ...updated.backend } : {};
21919
- updated.backend = { ...backend, openApiPath: input4 };
22053
+ updated.backend = { ...backend, openApiPath: input5 };
21920
22054
  await writeFile18(
21921
22055
  jsonConfigPath,
21922
22056
  `${JSON.stringify(updated, null, 2)}
21923
22057
  `,
21924
22058
  "utf8"
21925
22059
  );
21926
- return { input: input4 };
22060
+ return { input: input5 };
21927
22061
  }
21928
22062
  async function discoverAndWireOpenApiLite(siteDirectory, mode) {
21929
22063
  if (mode === "none") {
@@ -21975,7 +22109,7 @@ async function discoverAndWireOpenApiLite(siteDirectory, mode) {
21975
22109
  };
21976
22110
  }
21977
22111
  try {
21978
- const { input: input4 } = await wireOpenApiIntoJsonConfig(
22112
+ const { input: input5 } = await wireOpenApiIntoJsonConfig(
21979
22113
  siteDirectory,
21980
22114
  selected.path
21981
22115
  );
@@ -21983,7 +22117,7 @@ async function discoverAndWireOpenApiLite(siteDirectory, mode) {
21983
22117
  openApiDiscovery: {
21984
22118
  status: "wired",
21985
22119
  openApiPath: selected.path,
21986
- openApiInput: input4,
22120
+ openApiInput: input5,
21987
22121
  openApiTitle: selected.title ?? null,
21988
22122
  openApiVersion: selected.version ?? null,
21989
22123
  apiReferencePath: "/api",
@@ -22377,7 +22511,15 @@ async function createProject(argv) {
22377
22511
  return;
22378
22512
  }
22379
22513
  const modules = (argv.modules ?? "apihub").split(",").map((m) => m.trim()).filter(Boolean);
22380
- const config2 = loadConfig();
22514
+ let config2;
22515
+ try {
22516
+ config2 = loadConfig();
22517
+ } catch (error) {
22518
+ await printCriticalFailureToConsoleAndExit(
22519
+ error instanceof Error ? error.message : String(error)
22520
+ );
22521
+ return;
22522
+ }
22381
22523
  const client = new PlatformApiClient(config2);
22382
22524
  let result;
22383
22525
  try {
@@ -22837,7 +22979,15 @@ var run_default = {
22837
22979
  import path70 from "node:path";
22838
22980
  async function status(argv) {
22839
22981
  const sourceDirectory = path70.resolve(process.cwd(), argv.dir);
22840
- const config2 = loadConfig();
22982
+ let config2;
22983
+ try {
22984
+ config2 = loadConfig();
22985
+ } catch (error) {
22986
+ await printCriticalFailureToConsoleAndExit(
22987
+ error instanceof Error ? error.message : String(error)
22988
+ );
22989
+ return;
22990
+ }
22841
22991
  const client = new PlatformApiClient(config2);
22842
22992
  let whoamiJson;
22843
22993
  try {
@@ -22933,7 +23083,15 @@ async function teardown(argv) {
22933
23083
  return;
22934
23084
  }
22935
23085
  const sourceDirectory = path71.resolve(process.cwd(), argv.dir);
22936
- const config2 = loadConfig();
23086
+ let config2;
23087
+ try {
23088
+ config2 = loadConfig();
23089
+ } catch (error) {
23090
+ await printCriticalFailureToConsoleAndExit(
23091
+ error instanceof Error ? error.message : String(error)
23092
+ );
23093
+ return;
23094
+ }
22937
23095
  const client = new PlatformApiClient(config2);
22938
23096
  let projectId = argv.projectId?.trim();
22939
23097
  if (!projectId) {
@@ -1,4 +1,4 @@
1
- import type { PlatformApiClient } from "../client/platform-api.js";
1
+ import { type PlatformApiClient } from "../client/platform-api.js";
2
2
  import { type ApitogoConfig } from "../config.js";
3
3
  import type { ProgressReporter } from "../helpers/progress.js";
4
4
  export interface StepRecord {
@@ -16,10 +16,15 @@ export declare function parseHandlerResult<T extends {
16
16
  }>(json: string, step: string): T;
17
17
  export declare function ensureModuleProvisioned(client: PlatformApiClient, config: ApitogoConfig, projectId: string, moduleType: string, wait: boolean, timeoutMs?: number, pollIntervalMs?: number, progress?: ProgressReporter): Promise<void>;
18
18
  export declare function ensureModulesProvisioned(client: PlatformApiClient, config: ApitogoConfig, projectId: string, moduleTypes: string[], wait: boolean, timeoutMs?: number, pollIntervalMs?: number, progress?: ProgressReporter): Promise<void>;
19
+ export type ResolveProjectIdResult = {
20
+ blocked: false;
21
+ projectId: string;
22
+ completedSteps: StepRecord[];
23
+ } | {
24
+ blocked: true;
25
+ payload: Record<string, unknown>;
26
+ };
19
27
  export declare function resolveProjectIdForPublish(client: PlatformApiClient, config: ApitogoConfig, args: {
20
28
  projectId?: string;
21
29
  projectName?: string;
22
- }, wait: boolean, progress?: ProgressReporter, timeoutMs?: number, pollIntervalMs?: number): Promise<{
23
- projectId: string;
24
- completedSteps: StepRecord[];
25
- }>;
30
+ }, wait: boolean, progress?: ProgressReporter, timeoutMs?: number, pollIntervalMs?: number): Promise<ResolveProjectIdResult>;
@@ -1,4 +1,4 @@
1
- import type { PlatformApiClient } from "../client/platform-api.js";
1
+ import { type PlatformApiClient } from "../client/platform-api.js";
2
2
  import { type ApitogoConfig } from "../config.js";
3
3
  import { type DevPortalLocalManifest } from "../helpers/dev-portal-manifest.js";
4
4
  import { type DevPortalLocalSecrets } from "../helpers/dev-portal-secrets.js";
@@ -23,6 +23,7 @@ export interface PublishDevPortalArgs {
23
23
  only?: ApplyResource[];
24
24
  force?: boolean;
25
25
  resumeFromStep?: PublishStepId;
26
+ createNewProject?: boolean;
26
27
  }
27
28
  export type ApplyFromSiteDirectoryArgs = PublishDevPortalArgs;
28
29
  export declare function validateManifestForPublish(manifest: DevPortalLocalManifest, secrets: DevPortalLocalSecrets, emailOptions?: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lukoweb/apitogo",
3
- "version": "0.1.116",
3
+ "version": "0.1.119",
4
4
  "type": "module",
5
5
  "sideEffects": [
6
6
  "**/*.css",