@lukoweb/apitogo 0.2.43 → 0.2.45

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.
@@ -1,8 +1,10 @@
1
1
  import type { UseMutationResult } from "@tanstack/react-query";
2
2
  import type { PlaygroundResult } from "../Playground.js";
3
- export declare const ResultPanel: ({ queryMutation, showLongRunningWarning, onCancel, tip, isFinished, progress, }: {
3
+ export declare const ResultPanel: ({ queryMutation, showLongRunningWarning, isWarmingUp, hasIdentities, onCancel, tip, isFinished, progress, }: {
4
4
  queryMutation: UseMutationResult<PlaygroundResult, Error, any>;
5
5
  showLongRunningWarning?: boolean;
6
+ isWarmingUp?: boolean;
7
+ hasIdentities?: boolean;
6
8
  onCancel?: () => void;
7
9
  isFinished: boolean;
8
10
  progress: number;
@@ -0,0 +1,5 @@
1
+ export declare const WARM_UP_STATUSES: number[];
2
+ export declare function fetchWithWarmUpRetry(request: Request, init: RequestInit, options?: {
3
+ delayMs?: number;
4
+ onRetry?: () => void;
5
+ }): Promise<Response>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lukoweb/apitogo",
3
- "version": "0.2.43",
3
+ "version": "0.2.45",
4
4
  "type": "module",
5
5
  "sideEffects": [
6
6
  "**/*.css",
@@ -9,6 +9,11 @@ export const FULL_SERVER_SOURCE = "server";
9
9
  export const FULL_SERVER_RUNTIME = "nodejs";
10
10
  export const FULL_SERVER_RUNTIME_VERSION = "NODE_22_LTS";
11
11
  export const FULL_SERVER_HEALTH_PATH = "/health";
12
+ /**
13
+ * How long the gateway waits for the API. A hosted API that was idle takes longer than the default 30 seconds to wake
14
+ * up, so the first call after a quiet spell would end in a timeout; 120 is the most the platform allows.
15
+ */
16
+ export const FULL_SERVER_TIMEOUT_SECONDS = 120;
12
17
 
13
18
  const packageName = (name: string) =>
14
19
  `${
@@ -11,6 +11,7 @@ import path from "node:path";
11
11
  import { ApitogoError } from "../../lib/util/invariant.js";
12
12
  import {
13
13
  FULL_SERVER_HEALTH_PATH,
14
+ FULL_SERVER_TIMEOUT_SECONDS,
14
15
  FULL_SERVER_RUNTIME,
15
16
  FULL_SERVER_RUNTIME_VERSION,
16
17
  FULL_SERVER_SOURCE,
@@ -462,18 +463,19 @@ async function buildPortal(
462
463
 
463
464
  /**
464
465
  * A managed gateway runs the code in its source folder, and a new project has none. The folder is made (a `.gitkeep`
465
- * keeps it in git) and the user is told it is empty; the full template writes a small Node.js server there instead.
466
- * A folder that has files is left as it is. Returns whether the sample server was written.
466
+ * keeps it in git) and the user is told it is empty; with `writeSample` (the full template's own API) a small Node.js
467
+ * server is written there instead. A folder that has files is left as it is. Returns whether the sample was written.
467
468
  */
468
469
  async function createSourceFolder(
469
470
  context: Context,
470
471
  sourcePath: string,
471
472
  runtime: Runtime,
473
+ writeSample: boolean,
472
474
  ): Promise<boolean> {
473
475
  const folder = path.join(context.dir, sourcePath);
474
476
  const entries = await readdir(folder).catch(() => [] as string[]);
475
477
  if (entries.some((name) => name !== ".gitkeep")) return false;
476
- if (context.options.template === "full" && runtime === FULL_SERVER_RUNTIME) {
478
+ if (writeSample && runtime === FULL_SERVER_RUNTIME) {
477
479
  for (const [file, content] of Object.entries(
478
480
  fullServerFiles(context.resolved.project.name),
479
481
  ))
@@ -494,11 +496,35 @@ async function buildGateway(
494
496
  const { options, dir, resolved } = context;
495
497
  const o = options.gateway ?? {};
496
498
  const ask = options.ask;
497
- // The full template runs a backend of its own, so it asks nothing about the origin.
498
- const full = options.template === "full" && !o.url && o.origin !== "proxy";
499
+ const fullTemplate = options.template === "full";
500
+ // `full`: the platform runs the sample Node.js API in `server/`. That is what a script gets; in a terminal the full
501
+ // template asks first, because the user may have code of their own or an API that already runs somewhere else.
502
+ let full = fullTemplate && !o.url && o.origin !== "proxy";
499
503
  let mode =
500
504
  o.origin ??
501
- (o.url ? "proxy" : o.source || o.runtime || full ? "managed" : undefined);
505
+ (o.url ? "proxy" : o.source || o.runtime ? "managed" : undefined);
506
+ if (fullTemplate && !mode && ask) {
507
+ const answer = await ask.choose("Where is your API?", [
508
+ {
509
+ value: "sample" as const,
510
+ label:
511
+ "I have none yet: create a small Node.js API in server/, ready to deploy",
512
+ },
513
+ {
514
+ value: "own" as const,
515
+ label:
516
+ "My code is in this project (Node.js, Python or .NET): the platform runs it",
517
+ },
518
+ {
519
+ value: "proxy" as const,
520
+ label:
521
+ "It already runs somewhere else: the gateway forwards calls to its https address",
522
+ },
523
+ ]);
524
+ full = answer === "sample";
525
+ mode = answer === "proxy" ? "proxy" : "managed";
526
+ }
527
+ if (!mode && full) mode = "managed";
502
528
  if (!mode && ask) {
503
529
  mode = await ask.choose("How does the gateway reach your API?", [
504
530
  {
@@ -575,7 +601,7 @@ async function buildGateway(
575
601
  );
576
602
  }
577
603
  const sourcePath = insideProject(dir, source, "Source folder");
578
- sampleServer = await createSourceFolder(context, sourcePath, runtime);
604
+ sampleServer = await createSourceFolder(context, sourcePath, runtime, full);
579
605
  origin = {
580
606
  mode,
581
607
  source: sourcePath,
@@ -583,6 +609,8 @@ async function buildGateway(
583
609
  runtimeVersion,
584
610
  ...(o.exclude?.length ? { exclude: o.exclude } : {}),
585
611
  ...(sampleServer ? { healthPath: FULL_SERVER_HEALTH_PATH } : {}),
612
+ // A full project's API is hosted by the platform and sleeps when idle; the first call must outlast its start.
613
+ ...(fullTemplate ? { timeoutSeconds: FULL_SERVER_TIMEOUT_SECONDS } : {}),
586
614
  };
587
615
  }
588
616