@madewithremy/admin 0.1.13 → 0.1.14

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.d.ts CHANGED
@@ -1873,7 +1873,8 @@ interface DataSourcesDocumentStatus {
1873
1873
  }
1874
1874
  /**
1875
1875
  * GET /datasources/documents — one page of per-document ingest state for one
1876
- * pipeline, oldest first.
1876
+ * pipeline, oldest first unless `order=newest`; `status=error` is the failures,
1877
+ * newest failure first; `filename` a prefix.
1877
1878
  *
1878
1879
  * `pipelineVersion` is absent when the data source does not exist (returns `{ documents: [] }`).
1879
1880
  * `candidate=true` watches a migration in progress. `nextCursor` is set when
@@ -2152,13 +2153,18 @@ interface DataSourcesPromoteResult {
2152
2153
  interface DataSourcesDropResult {
2153
2154
  dropped: number;
2154
2155
  }
2155
- /** POST /datasources/delete — delete every version, document, and byte. */
2156
+ /**
2157
+ * POST /datasources/delete — delete every version, document, and byte. The
2158
+ * source is gone to every reader when this returns; its rows and objects are
2159
+ * removed by a background job, which `purging` says.
2160
+ */
2156
2161
  interface DataSourcesDeleteResult {
2157
2162
  deleted: true;
2158
- /** Number of documents removed. */
2163
+ /** Number of documents being removed. */
2159
2164
  documents: number;
2160
- /** Number of pipeline versions dropped. */
2165
+ /** Number of pipeline versions being dropped. */
2161
2166
  versions: number;
2167
+ purging: boolean;
2162
2168
  }
2163
2169
  /**
2164
2170
  * POST /datasources/documents/delete — always responds 204 (empty body).
@@ -2316,13 +2322,20 @@ interface WaitForCandidateParams {
2316
2322
  }
2317
2323
  interface WaitForCandidateResult {
2318
2324
  status: 'ready' | 'error' | 'timeout';
2325
+ /** The candidate's build counts when the wait ended; null when it had no candidate. */
2326
+ counts: DataSourcesBuildProgress | null;
2327
+ /** The failed documents, first page, when any failed. */
2319
2328
  documents: SummarizedDocument[];
2320
2329
  /** Present only on status === 'timeout'. */
2321
2330
  error?: string;
2322
2331
  }
2332
+ /** Failed documents fetched for a status or a candidate wait. */
2333
+ declare const FAILURES_PAGE = 50;
2323
2334
  /**
2324
2335
  * Poll a candidate version (`revectorize`) until every document has built.
2325
- * `error` means at least one failed; `promote` with `force` accepts that.
2336
+ * Reads the candidate's counts from the source list — one row, whatever the
2337
+ * corpus holds — and fetches the failures only at the end. `error` means at
2338
+ * least one failed; `promote` with `force` accepts that.
2326
2339
  */
2327
2340
  declare function waitForCandidate(ctx: AdminContext, params: WaitForCandidateParams): Promise<WaitForCandidateResult>;
2328
2341
  interface DocumentsParams {
@@ -2336,11 +2349,19 @@ interface DocumentsParams {
2336
2349
  limit?: number;
2337
2350
  /** `nextCursor` from the previous page. */
2338
2351
  cursor?: string;
2352
+ /** By the time the document was added; oldest first unless said otherwise. */
2353
+ order?: 'oldest' | 'newest';
2354
+ /** The failed builds only, newest failure first. */
2355
+ status?: 'error';
2356
+ /** Filenames starting with this. */
2357
+ filename?: string;
2339
2358
  }
2340
2359
  /** The server's cap on `ids` per request; `allDocuments` chunks to it. */
2341
2360
  declare const DOCUMENTS_IDS_MAX = 200;
2342
2361
  /**
2343
- * Fetch one page of per-document ingest state for one pipeline, oldest first.
2362
+ * Fetch one page of per-document ingest state for one pipeline, oldest first
2363
+ * unless `order` says otherwise; `status: 'error'` narrows to the failures and
2364
+ * `filename` to a name prefix.
2344
2365
  *
2345
2366
  * Returns an empty document list when the data source does not exist yet.
2346
2367
  * Pass `candidate: true` to watch a revectorization in progress. Follow
@@ -2348,6 +2369,7 @@ declare const DOCUMENTS_IDS_MAX = 200;
2348
2369
  *
2349
2370
  * @example
2350
2371
  * const { documents, nextCursor } = await admin.dataSources.documents({ slug: 'policies' });
2372
+ * const failed = await admin.dataSources.documents({ slug: 'policies', status: 'error' });
2351
2373
  */
2352
2374
  declare function documents(ctx: AdminContext, params: DocumentsParams): Promise<DataSourcesDocumentsResult>;
2353
2375
  /**
@@ -2666,6 +2688,7 @@ type dataSources_CreateParams = CreateParams;
2666
2688
  declare const dataSources_DOCUMENTS_IDS_MAX: typeof DOCUMENTS_IDS_MAX;
2667
2689
  type dataSources_DocumentsParams = DocumentsParams;
2668
2690
  type dataSources_DropParams = DropParams;
2691
+ declare const dataSources_FAILURES_PAGE: typeof FAILURES_PAGE;
2669
2692
  type dataSources_MoveParams = MoveParams;
2670
2693
  type dataSources_PromoteParams = PromoteParams;
2671
2694
  type dataSources_RevectorizeParams = RevectorizeParams;
@@ -2698,7 +2721,7 @@ declare const dataSources_waitForCandidate: typeof waitForCandidate;
2698
2721
  declare const dataSources_waitForIngest: typeof waitForIngest;
2699
2722
  declare const dataSources_waitForMove: typeof waitForMove;
2700
2723
  declare namespace dataSources {
2701
- export { type dataSources_AddDocumentParams as AddDocumentParams, type dataSources_AddDocumentResult as AddDocumentResult, type dataSources_ConfigSetParams as ConfigSetParams, type dataSources_CreateParams as CreateParams, DEFAULT_WAIT_TIMEOUT_MS$3 as DEFAULT_WAIT_TIMEOUT_MS, dataSources_DOCUMENTS_IDS_MAX as DOCUMENTS_IDS_MAX, type dataSources_DocumentsParams as DocumentsParams, type dataSources_DropParams as DropParams, type dataSources_MoveParams as MoveParams, type dataSources_PromoteParams as PromoteParams, type dataSources_RevectorizeParams as RevectorizeParams, type dataSources_RmParams as RmParams, type dataSources_RmWhereParams as RmWhereParams, type dataSources_SearchParams as SearchParams, type dataSources_SummarizedDocument as SummarizedDocument, type dataSources_WaitForCandidateParams as WaitForCandidateParams, type dataSources_WaitForCandidateResult as WaitForCandidateResult, type dataSources_WaitForIngestParams as WaitForIngestParams, type dataSources_WaitForIngestResult as WaitForIngestResult, type dataSources_WaitForMoveParams as WaitForMoveParams, type dataSources_WaitForMoveResult as WaitForMoveResult, dataSources_addDocument as addDocument, dataSources_allDocuments as allDocuments, dataSources_configGet as configGet, dataSources_configSet as configSet, create$1 as create, dataSources_deleteSource as deleteSource, dataSources_documents as documents, dataSources_drop as drop, list$8 as list, dataSources_move as move, dataSources_promote as promote, dataSources_revectorize as revectorize, dataSources_rm as rm, dataSources_rmWhere as rmWhere, dataSources_rmWhereAll as rmWhereAll, dataSources_search as search, dataSources_summarize as summarize, dataSources_waitForCandidate as waitForCandidate, dataSources_waitForIngest as waitForIngest, dataSources_waitForMove as waitForMove };
2724
+ export { type dataSources_AddDocumentParams as AddDocumentParams, type dataSources_AddDocumentResult as AddDocumentResult, type dataSources_ConfigSetParams as ConfigSetParams, type dataSources_CreateParams as CreateParams, DEFAULT_WAIT_TIMEOUT_MS$3 as DEFAULT_WAIT_TIMEOUT_MS, dataSources_DOCUMENTS_IDS_MAX as DOCUMENTS_IDS_MAX, type dataSources_DocumentsParams as DocumentsParams, type dataSources_DropParams as DropParams, dataSources_FAILURES_PAGE as FAILURES_PAGE, type dataSources_MoveParams as MoveParams, type dataSources_PromoteParams as PromoteParams, type dataSources_RevectorizeParams as RevectorizeParams, type dataSources_RmParams as RmParams, type dataSources_RmWhereParams as RmWhereParams, type dataSources_SearchParams as SearchParams, type dataSources_SummarizedDocument as SummarizedDocument, type dataSources_WaitForCandidateParams as WaitForCandidateParams, type dataSources_WaitForCandidateResult as WaitForCandidateResult, type dataSources_WaitForIngestParams as WaitForIngestParams, type dataSources_WaitForIngestResult as WaitForIngestResult, type dataSources_WaitForMoveParams as WaitForMoveParams, type dataSources_WaitForMoveResult as WaitForMoveResult, dataSources_addDocument as addDocument, dataSources_allDocuments as allDocuments, dataSources_configGet as configGet, dataSources_configSet as configSet, create$1 as create, dataSources_deleteSource as deleteSource, dataSources_documents as documents, dataSources_drop as drop, list$8 as list, dataSources_move as move, dataSources_promote as promote, dataSources_revectorize as revectorize, dataSources_rm as rm, dataSources_rmWhere as rmWhere, dataSources_rmWhereAll as rmWhereAll, dataSources_search as search, dataSources_summarize as summarize, dataSources_waitForCandidate as waitForCandidate, dataSources_waitForIngest as waitForIngest, dataSources_waitForMove as waitForMove };
2702
2725
  }
2703
2726
 
2704
2727
  /**
@@ -2950,9 +2973,15 @@ declare const DEFAULT_WAIT_TIMEOUT_MS$1: number;
2950
2973
  * Warm a source's index if it is cold. A search on a large cold index answers
2951
2974
  * `index_warming` until the reload lands; call this before a demo, or after an
2952
2975
  * eviction you know about. Answers `resident: true` when nothing was needed.
2976
+ *
2977
+ * With `since`, refill instead: copy every document built at or after that
2978
+ * time into the index whether or not it is resident. What a dedicated
2979
+ * instance needs after restoring from a snapshot taken then; the platform
2980
+ * does this on its own when it sees the restore, this is the by-hand path.
2953
2981
  */
2954
2982
  declare function hydrate(ctx: AdminContext, params: {
2955
2983
  slug: string;
2984
+ since?: string;
2956
2985
  }): Promise<DataSourcesHydrateResult>;
2957
2986
  /**
2958
2987
  * Recreate a dedicated source's collection with the platform's current shape
@@ -4555,6 +4584,16 @@ interface InfraResource {
4555
4584
  resizingTo: InfraOffering | null;
4556
4585
  /** When the last verified snapshot was taken; null if never. */
4557
4586
  lastSnapshotAt: string | null;
4587
+ /**
4588
+ * What this resource has actually been charged, from the ledger's own
4589
+ * writes, with the hours at each rate beside it. Rates are on `offering`.
4590
+ */
4591
+ billing: {
4592
+ activeHours: number;
4593
+ hibernatedHours: number;
4594
+ billedDollars: number;
4595
+ lastBilledAt: string | null;
4596
+ };
4558
4597
  activatedAt: string | null;
4559
4598
  hibernatedAt: string | null;
4560
4599
  destroyedAt: string | null;
@@ -4571,6 +4610,23 @@ interface InfraEvent {
4571
4610
  reason: string | null;
4572
4611
  createdAt: string;
4573
4612
  }
4613
+ /**
4614
+ * One line of the platform's narration of a resource: a step reported while
4615
+ * a transition ran ("Waiting for capacity", "Restoring collections 2/3"), a
4616
+ * failed attempt, or a failure with what Kubernetes said about the pod at the
4617
+ * time (`data`). Not the instance's own stdout.
4618
+ */
4619
+ interface InfraLogLine {
4620
+ id: string;
4621
+ phase: InfraPhase;
4622
+ level: 'info' | 'warn' | 'error';
4623
+ message: string;
4624
+ data: {
4625
+ podEvents: string[];
4626
+ logTail: string[];
4627
+ } | null;
4628
+ createdAt: string;
4629
+ }
4574
4630
  /** GET /infra */
4575
4631
  interface InfraListResult {
4576
4632
  resources: InfraResource[];
@@ -4582,12 +4638,19 @@ interface InfraListResult {
4582
4638
  interface InfraGetResult {
4583
4639
  resource: InfraResource;
4584
4640
  events: InfraEvent[];
4641
+ /** The newest 200 narration lines, oldest first; `logs()` pages further. */
4642
+ logs: InfraLogLine[];
4585
4643
  attachedSources: {
4586
4644
  id: string;
4587
4645
  slug: string;
4588
4646
  name: string | null;
4589
4647
  }[];
4590
4648
  }
4649
+ /** GET /infra/:id/logs */
4650
+ interface InfraLogsResult {
4651
+ /** Oldest first. */
4652
+ logs: InfraLogLine[];
4653
+ }
4591
4654
  /** POST /infra, /infra/:id/{hibernate,resume,destroy,rename,resize} */
4592
4655
  interface InfraResourceResult {
4593
4656
  resource: InfraResource;
@@ -4625,6 +4688,23 @@ interface GetParams {
4625
4688
  * @throws AdminApiError `resource_not_found` (404).
4626
4689
  */
4627
4690
  declare function get$4(ctx: AdminContext, params: GetParams): Promise<InfraGetResult>;
4691
+ interface LogsParams {
4692
+ /** Resource id. */
4693
+ id: string;
4694
+ /** Continue after this line id (the last line of a previous page). */
4695
+ after?: string;
4696
+ /** Lines per page; without `after`, the newest this many. Max 500. */
4697
+ limit?: number;
4698
+ }
4699
+ /**
4700
+ * The platform's narration of a resource, oldest first: the steps a
4701
+ * transition went through, failed attempts, and failures with the pod's
4702
+ * events and a warnings-and-errors tail of the instance log. Not the
4703
+ * instance's own stdout.
4704
+ *
4705
+ * @throws AdminApiError `resource_not_found` (404).
4706
+ */
4707
+ declare function logs(ctx: AdminContext, params: LogsParams): Promise<InfraLogsResult>;
4628
4708
  interface ProvisionParams {
4629
4709
  /** Offering id from `list().offerings`, e.g. `retrieval.small`. */
4630
4710
  offeringId: string;
@@ -4741,6 +4821,7 @@ declare function waitForPhase(ctx: AdminContext, params: WaitForPhaseParams): Pr
4741
4821
  declare const infra_DEFAULT_WAIT_TIMEOUT_MS: typeof DEFAULT_WAIT_TIMEOUT_MS;
4742
4822
  type infra_GetParams = GetParams;
4743
4823
  type infra_ListParams = ListParams;
4824
+ type infra_LogsParams = LogsParams;
4744
4825
  type infra_ProvisionParams = ProvisionParams;
4745
4826
  type infra_RenameParams = RenameParams;
4746
4827
  type infra_ResizeParams = ResizeParams;
@@ -4749,13 +4830,14 @@ type infra_WaitForPhaseParams = WaitForPhaseParams;
4749
4830
  type infra_WaitForPhaseResult = WaitForPhaseResult;
4750
4831
  declare const infra_destroy: typeof destroy;
4751
4832
  declare const infra_hibernate: typeof hibernate;
4833
+ declare const infra_logs: typeof logs;
4752
4834
  declare const infra_provision: typeof provision;
4753
4835
  declare const infra_rename: typeof rename;
4754
4836
  declare const infra_resize: typeof resize;
4755
4837
  declare const infra_resume: typeof resume;
4756
4838
  declare const infra_waitForPhase: typeof waitForPhase;
4757
4839
  declare namespace infra {
4758
- export { infra_DEFAULT_WAIT_TIMEOUT_MS as DEFAULT_WAIT_TIMEOUT_MS, type infra_GetParams as GetParams, type infra_ListParams as ListParams, type infra_ProvisionParams as ProvisionParams, type infra_RenameParams as RenameParams, type infra_ResizeParams as ResizeParams, type infra_ResourceIdParams as ResourceIdParams, type infra_WaitForPhaseParams as WaitForPhaseParams, type infra_WaitForPhaseResult as WaitForPhaseResult, infra_destroy as destroy, get$4 as get, infra_hibernate as hibernate, list$6 as list, infra_provision as provision, infra_rename as rename, infra_resize as resize, infra_resume as resume, infra_waitForPhase as waitForPhase };
4840
+ export { infra_DEFAULT_WAIT_TIMEOUT_MS as DEFAULT_WAIT_TIMEOUT_MS, type infra_GetParams as GetParams, type infra_ListParams as ListParams, type infra_LogsParams as LogsParams, type infra_ProvisionParams as ProvisionParams, type infra_RenameParams as RenameParams, type infra_ResizeParams as ResizeParams, type infra_ResourceIdParams as ResourceIdParams, type infra_WaitForPhaseParams as WaitForPhaseParams, type infra_WaitForPhaseResult as WaitForPhaseResult, infra_destroy as destroy, get$4 as get, infra_hibernate as hibernate, list$6 as list, infra_logs as logs, infra_provision as provision, infra_rename as rename, infra_resize as resize, infra_resume as resume, infra_waitForPhase as waitForPhase };
4759
4841
  }
4760
4842
 
4761
4843
  /**
package/dist/index.js CHANGED
@@ -361,6 +361,7 @@ var dataSources_exports = {};
361
361
  __export(dataSources_exports, {
362
362
  DEFAULT_WAIT_TIMEOUT_MS: () => DEFAULT_WAIT_TIMEOUT_MS,
363
363
  DOCUMENTS_IDS_MAX: () => DOCUMENTS_IDS_MAX,
364
+ FAILURES_PAGE: () => FAILURES_PAGE,
364
365
  addDocument: () => addDocument,
365
366
  allDocuments: () => allDocuments,
366
367
  configGet: () => configGet,
@@ -552,33 +553,48 @@ async function waitForIngest(ctx, params) {
552
553
  documents: tracked.map(summarize)
553
554
  };
554
555
  }
556
+ var FAILURES_PAGE = 50;
555
557
  async function waitForCandidate(ctx, params) {
556
558
  const timeoutMs = params.timeoutMs ?? DEFAULT_WAIT_TIMEOUT_MS;
557
- const pendingOf = (docs2) => docs2.filter((d) => d.status === "processing");
558
559
  const outcome = await pollUntil(
559
- () => allDocuments(ctx, { slug: params.slug, candidate: true }),
560
- (docs2) => pendingOf(docs2).length === 0,
560
+ async () => {
561
+ const { dataSources } = await list3(ctx);
562
+ const source = dataSources.find((s) => s.slug === params.slug);
563
+ if (!source) {
564
+ throw new Error(`Data source "${params.slug}" not found.`);
565
+ }
566
+ return source.candidate?.progress ?? null;
567
+ },
568
+ (progress) => progress === null || progress.processing === 0,
561
569
  {
562
570
  timeoutMs,
563
571
  pollMs: POLL_MS,
564
- describe: (docs2, start2) => `rebuilding\u2026 ${docs2.length - pendingOf(docs2).length}/${docs2.length} done (${elapsedSeconds(start2)}s)`,
572
+ describe: (progress, start2) => progress ? `rebuilding\u2026 ${progress.done}/${progress.total} done (${elapsedSeconds(start2)}s)` : `rebuilding\u2026 (${elapsedSeconds(start2)}s)`,
565
573
  onProgress: params.onProgress
566
574
  }
567
575
  );
568
- const docs = outcome.value;
576
+ const counts = outcome.value;
577
+ const failed = counts && counts.error > 0 ? (await documents(ctx, {
578
+ slug: params.slug,
579
+ candidate: true,
580
+ status: "error",
581
+ limit: FAILURES_PAGE
582
+ })).documents.map(summarize) : [];
569
583
  if (!outcome.settled) {
570
584
  return {
571
585
  status: "timeout",
572
- documents: docs.map(summarize),
586
+ counts,
587
+ documents: failed,
573
588
  error: timedOut(
574
589
  timeoutMs,
575
- `with ${pendingOf(docs).length} document(s) still building`
590
+ `with ${counts?.processing ?? 0} document(s) still building`
576
591
  )
577
592
  };
578
593
  }
579
594
  return {
580
- status: docs.some((d) => d.status === "error") ? "error" : "ready",
581
- documents: docs.map(summarize)
595
+ status: counts && counts.error > 0 ? "error" : "ready",
596
+ counts,
597
+ documents: failed
582
598
  };
583
599
  }
584
600
  var DOCUMENTS_IDS_MAX = 200;
@@ -591,7 +607,10 @@ function documents(ctx, params) {
591
607
  candidate: params.candidate || void 0,
592
608
  ids: params.ids?.length ? params.ids.join(",") : void 0,
593
609
  limit: params.limit,
594
- cursor: params.cursor
610
+ cursor: params.cursor,
611
+ order: params.order,
612
+ status: params.status,
613
+ filename: params.filename
595
614
  })}`
596
615
  );
597
616
  }
@@ -609,7 +628,10 @@ async function allDocuments(ctx, params) {
609
628
  candidate: params.candidate,
610
629
  ids,
611
630
  limit: 1e3,
612
- cursor
631
+ cursor,
632
+ order: params.order,
633
+ status: params.status,
634
+ filename: params.filename
613
635
  });
614
636
  out.push(...page.documents ?? []);
615
637
  cursor = page.nextCursor ?? void 0;
@@ -1051,7 +1073,7 @@ function hydrate(ctx, params) {
1051
1073
  ctx,
1052
1074
  "POST",
1053
1075
  `${base4(ctx.appId)}/hydrate`,
1054
- { slug: params.slug }
1076
+ { slug: params.slug, ...params.since ? { since: params.since } : {} }
1055
1077
  );
1056
1078
  }
1057
1079
  function reindex(ctx, params) {
@@ -1862,6 +1884,7 @@ __export(infra_exports, {
1862
1884
  get: () => get7,
1863
1885
  hibernate: () => hibernate,
1864
1886
  list: () => list7,
1887
+ logs: () => logs,
1865
1888
  provision: () => provision,
1866
1889
  rename: () => rename,
1867
1890
  resize: () => resize,
@@ -1887,6 +1910,21 @@ function get7(ctx, params) {
1887
1910
  `${base6(ctx.appId)}/${encodeURIComponent(params.id)}`
1888
1911
  );
1889
1912
  }
1913
+ function logs(ctx, params) {
1914
+ const query3 = new URLSearchParams();
1915
+ if (params.after) {
1916
+ query3.set("after", params.after);
1917
+ }
1918
+ if (params.limit) {
1919
+ query3.set("limit", String(params.limit));
1920
+ }
1921
+ const search2 = query3.toString();
1922
+ return call(
1923
+ ctx,
1924
+ "GET",
1925
+ `${base6(ctx.appId)}/${encodeURIComponent(params.id)}/logs${search2 ? `?${search2}` : ""}`
1926
+ );
1927
+ }
1890
1928
  function provision(ctx, params) {
1891
1929
  return call(ctx, "POST", base6(ctx.appId), {
1892
1930
  offeringId: params.offeringId,