@pipelex/sdk 0.64.0 → 0.66.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/README.md +17 -1
- package/dist/cli/script.d.ts +1 -1
- package/dist/client.d.ts +233 -9
- package/dist/client.js +325 -24
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js.map +1 -1
- package/dist/method-layouts.d.ts +51 -20
- package/dist/method-layouts.js +23 -17
- package/dist/method-layouts.js.map +1 -1
- package/dist/method-showcases.d.ts +169 -0
- package/dist/method-showcases.js +139 -0
- package/dist/method-showcases.js.map +1 -0
- package/dist/product-models.d.ts +37 -5
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/architecture.md +4 -2
- package/docs/errors.md +1 -1
- package/docs/method-copy.md +1 -1
- package/docs/method-examples.md +1 -0
- package/docs/method-layouts.md +52 -9
- package/docs/method-showcases.md +100 -0
- package/docs/public-methods.md +1 -0
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// client and the MTHDS runners cannot disagree about what they reject.
|
|
4
4
|
import { assertOneMethodSource, buildProblem, isProblem, parseJsonBody, readProblemBody, } from "mthds/protocol";
|
|
5
5
|
import { LAYOUT_INPUT_MEMBERS, PROVENANCE_INPUT_MEMBERS, methodLayoutFault, readMethodLayout, readMethodLayouts, } from "./method-layouts.js";
|
|
6
|
+
import { methodShowcaseDetailFault, methodShowcaseFreezeFault, readMethodShowcaseSummaries, } from "./method-showcases.js";
|
|
6
7
|
import { assertArtifactSelection, assertWaitOptions, pollUntilResult, readRunDegradation, RUN_STATUSES, runProgressFault, runStatusFilter, selectionIncludesMainStuff, throwIfAborted, withCheckedProgressHealth, } from "./runs.js";
|
|
7
8
|
import { ABORT_TIMEOUT, ApiResponseError, argumentInvalidProblem, ApiUnreachableError, MissingMainStuffError, PagingNotTerminatingError, PipelineExecuteTimeoutError, ProblemError, RequestArgumentError, RunLifecycleUnavailableError, RunStillRunningError, } from "./errors.js";
|
|
8
9
|
import { isPlainObject } from "./records.js";
|
|
@@ -313,6 +314,23 @@ function checkRunListQuery(call, query) {
|
|
|
313
314
|
return;
|
|
314
315
|
throw argumentRefusal(call, RUN_LIST_QUERY_ARGUMENT, describeNumberArgument(query), "not_an_object");
|
|
315
316
|
}
|
|
317
|
+
/** What each argument of a showcase call is, as a refusal of it names it. */
|
|
318
|
+
const SHOWCASE_ID_ARGUMENT = {
|
|
319
|
+
name: "showcase_id",
|
|
320
|
+
what: "a showcase id, the showcase's non-empty `showcase_id`",
|
|
321
|
+
};
|
|
322
|
+
const SHOWCASE_VERSION_ARGUMENT = {
|
|
323
|
+
name: "version",
|
|
324
|
+
what: "a version number, the published version whose showcases to read, a positive integer",
|
|
325
|
+
};
|
|
326
|
+
const SHOWCASE_RUN_ID_ARGUMENT = {
|
|
327
|
+
name: "run_id",
|
|
328
|
+
what: "a run id, the non-empty `pipeline_run_id` of the completed run to freeze",
|
|
329
|
+
};
|
|
330
|
+
const SHOWCASE_NAME_ARGUMENT = {
|
|
331
|
+
name: "name",
|
|
332
|
+
what: "a name for the showcase, a non-empty string",
|
|
333
|
+
};
|
|
316
334
|
/** What each argument of a method copy is, as a refusal of it names it. */
|
|
317
335
|
const COPY_DESTINATION_ARGUMENT = {
|
|
318
336
|
name: "destination_org_id",
|
|
@@ -332,6 +350,14 @@ const LAYOUT_VERSION_ARGUMENT = {
|
|
|
332
350
|
name: "version",
|
|
333
351
|
what: "a version number, the published version the layout was designed for, a positive integer",
|
|
334
352
|
};
|
|
353
|
+
const LAYOUT_LIST_VERSION_ARGUMENT = {
|
|
354
|
+
name: "version",
|
|
355
|
+
what: "a version number, the published version whose layouts to read, a positive integer",
|
|
356
|
+
};
|
|
357
|
+
const LAYOUTS_OFF_CATALOGS_ARGUMENT = {
|
|
358
|
+
name: "catalogs",
|
|
359
|
+
what: "the ids of the catalogs to switch off as an array, the whole list, empty for none",
|
|
360
|
+
};
|
|
335
361
|
const LAYOUT_ARGUMENT = {
|
|
336
362
|
name: "layout",
|
|
337
363
|
what: "the layout to store as an object, a MethodLayoutInput",
|
|
@@ -453,6 +479,16 @@ function methodExamplePath(methodId, exampleId, call) {
|
|
|
453
479
|
const path = methodPath(methodId, call);
|
|
454
480
|
return `${path}/examples/${idPathSegment(exampleId, call, EXAMPLE_ID_ARGUMENT)}`;
|
|
455
481
|
}
|
|
482
|
+
/**
|
|
483
|
+
* The path of a published version's showcases, `methods/{id}/versions/{n}/showcases`, for a bare
|
|
484
|
+
* catalog id and a positive integer version, each refused before anything is sent.
|
|
485
|
+
*/
|
|
486
|
+
function methodVersionShowcasesPath(methodId, version, call) {
|
|
487
|
+
if (!Number.isSafeInteger(version) || version < 1) {
|
|
488
|
+
throw argumentRefusal(call, SHOWCASE_VERSION_ARGUMENT, describeNumberArgument(version), "not_a_positive_integer");
|
|
489
|
+
}
|
|
490
|
+
return `${methodPath(methodId, call)}/versions/${version}/showcases`;
|
|
491
|
+
}
|
|
456
492
|
const isString = (value) => typeof value === "string";
|
|
457
493
|
/** The states an archive is in, the field a caller branches on, in the order a refusal lists them. */
|
|
458
494
|
const FILE_ARCHIVE_STATES = ["queued", "building", "ready", "failed"];
|
|
@@ -490,7 +526,8 @@ function fileLinkTarget(value) {
|
|
|
490
526
|
* Python SDK's model requires, held to the same strict types it holds them to, so both SDKs refuse
|
|
491
527
|
* the same answers, the ones a caller acts on (`example_id`, `inputs`, `input_revision`,
|
|
492
528
|
* `latest_run_id`) among them. `latest_run_id` must be present, `null` saying there is no latest
|
|
493
|
-
* run
|
|
529
|
+
* run; `showcase_id` may be absent, since a platform that predates it does not send it, and is held
|
|
530
|
+
* to its type when it is there; and `input_revision` must be a safe integer, so a string, a boolean, a fraction and an
|
|
494
531
|
* integer past the safe range, which `parseExactJson` reads as a `bigint`, are each refused by
|
|
495
532
|
* both. The one spelling they read apart is a revision of `2.0`: JavaScript reads it as the number
|
|
496
533
|
* `2` and cannot tell it from `2`, while the Python SDK refuses the float.
|
|
@@ -506,6 +543,10 @@ const METHOD_EXAMPLE_FIELDS = {
|
|
|
506
543
|
inputs: ["an object", isPlainObject],
|
|
507
544
|
input_revision: ["an integer", (value) => Number.isSafeInteger(value)],
|
|
508
545
|
latest_run_id: ["a string or null", (value) => value === null || isString(value)],
|
|
546
|
+
showcase_id: [
|
|
547
|
+
"a string or null",
|
|
548
|
+
(value) => value === undefined || value === null || isString(value),
|
|
549
|
+
],
|
|
509
550
|
created_by_user_id: ["a string", isString],
|
|
510
551
|
created_at: ["a string", isString],
|
|
511
552
|
updated_at: ["a string", isString],
|
|
@@ -601,7 +642,8 @@ export class PipelexApiClient {
|
|
|
601
642
|
* whose errors then say whether it may have (see `RunCreation`).
|
|
602
643
|
* `idempotencyKey`, already checked by `idempotencyKeyOf`, is sent as the
|
|
603
644
|
* `Idempotency-Key` header; only `start`, `copyMethod`, `storeMethodLayout`,
|
|
604
|
-
* `
|
|
645
|
+
* `setMethodLayoutsOff`, `freezeMethodShowcase`, `withdrawMethodShowcase`, `rotateWebhookSecret`
|
|
646
|
+
* and `replayRunWebhookDelivery` pass one.
|
|
605
647
|
*/
|
|
606
648
|
async requestRaw(method, url, options = {}) {
|
|
607
649
|
const hasBody = options.body !== undefined;
|
|
@@ -718,7 +760,7 @@ export class PipelexApiClient {
|
|
|
718
760
|
}
|
|
719
761
|
/**
|
|
720
762
|
* A methods-catalog route answering one stored method (`createMethod`, `writeDraft`,
|
|
721
|
-
* `renameMethod`), read as `readObjectAnswer` reads it.
|
|
763
|
+
* `renameMethod`, `setMethodLayoutsOff`), read as `readObjectAnswer` reads it.
|
|
722
764
|
*/
|
|
723
765
|
async requestMethodData(method, endpoint, body, options = {}) {
|
|
724
766
|
const res = await this.requestProductAnswer(method, endpoint, body, options);
|
|
@@ -2545,7 +2587,7 @@ export class PipelexApiClient {
|
|
|
2545
2587
|
* `refused` with a `reason`, a `message` and the runner's `validation` verdict, whose problem
|
|
2546
2588
|
* items are read member by member as `validate` reads them. The reason is `invalid`, or
|
|
2547
2589
|
* `not_runnable` for a draft that validates with pending signatures, and for a public method
|
|
2548
|
-
* also `thumbnail_missing`, `thumbnail_invalid` or `
|
|
2590
|
+
* also `thumbnail_missing`, `thumbnail_invalid`, `storage_reference` or `showcase_missing` (see
|
|
2549
2591
|
* `MethodPublishRefusalReason`); a reason this SDK does not know is passed through as its raw
|
|
2550
2592
|
* string, still a verdict, so show its `message`. Every arm carries the `method`. A publish
|
|
2551
2593
|
* moves no token.
|
|
@@ -2663,8 +2705,8 @@ export class PipelexApiClient {
|
|
|
2663
2705
|
*
|
|
2664
2706
|
* A layout is a data file a producer designed over the version's input-form descriptor, in the
|
|
2665
2707
|
* vocabulary of a catalog of components. The platform stores it beside the method, keyed by the
|
|
2666
|
-
* content it was designed for, and hands it back on every validate
|
|
2667
|
-
* that names `layouts` among its `views` and resolves the same tree
|
|
2708
|
+
* content it was designed for, and hands it back through `listMethodLayouts` and on every validate
|
|
2709
|
+
* of the method by `method_id` that names `layouts` among its `views` and resolves the same tree
|
|
2668
2710
|
* (`PipelexValidationReport.layouts`). It never produces, parses or judges one.
|
|
2669
2711
|
*
|
|
2670
2712
|
* `layout.tree_digest` must be the digest of the tree `version` holds, its
|
|
@@ -2677,12 +2719,13 @@ export class PipelexApiClient {
|
|
|
2677
2719
|
* (`MethodLayoutWriteOptions`). A content keeps at most 16
|
|
2678
2720
|
* layouts, every pipe, catalog and prompt hash together; past the bound a write removes first what
|
|
2679
2721
|
* newer prompts of the same pipe and catalog superseded (see `docs/method-layouts.md`).
|
|
2722
|
+
* `layout.sample_json` keeps a written sample with the layout, never a run's output.
|
|
2680
2723
|
*
|
|
2681
2724
|
* The write changes the method, so it takes an `admin` or a `member` of the method's
|
|
2682
2725
|
* organization. Takes a bare catalog id, as `getMethod` does, and the version number. Sends the
|
|
2683
2726
|
* members of `MethodLayoutInput` and nothing else, the route's body being closed at both levels,
|
|
2684
|
-
* and leaves out each optional provenance member that is `null` or omitted, for
|
|
2685
|
-
* default. Throws `RequestArgumentError` before any request for a `version` that is not a positive
|
|
2727
|
+
* and leaves out `sample_json` and each optional provenance member that is `null` or omitted, for
|
|
2728
|
+
* the platform's default. Throws `RequestArgumentError` before any request for a `version` that is not a positive
|
|
2686
2729
|
* integer and for a `layout` or a `provenance` that is not an object; every other member is sent
|
|
2687
2730
|
* as given. Throws `ApiResponseError` when the platform refuses the write, which stores nothing:
|
|
2688
2731
|
* `422` `request.invalid` for a member breaking its shape or bound, naming it in `params.field`
|
|
@@ -2716,6 +2759,260 @@ export class PipelexApiClient {
|
|
|
2716
2759
|
}
|
|
2717
2760
|
return stored;
|
|
2718
2761
|
}
|
|
2762
|
+
/**
|
|
2763
|
+
* The layouts stored for the content of a published version of a method —
|
|
2764
|
+
* `GET /v1/methods/{id}/versions/{n}/layouts` — newest first, at most 16, `items` empty when none
|
|
2765
|
+
* is stored. It touches only the platform's database and calls no runner, so it costs a host far
|
|
2766
|
+
* less than the `layouts` view of `validate`, which dry-runs every pipe of the method.
|
|
2767
|
+
*
|
|
2768
|
+
* It answers what is stored whatever `layouts_off` says: the switch is the host's to honour.
|
|
2769
|
+
* Another organization's public method reads too, with the layouts its builders stored, and a
|
|
2770
|
+
* `runner` reads what it is shown. Takes a bare catalog id, as `getMethod` does, and the version
|
|
2771
|
+
* number. `options.signal` cancels the read. Throws `RequestArgumentError` for a `version` that is
|
|
2772
|
+
* not a positive integer, before any request.
|
|
2773
|
+
*
|
|
2774
|
+
* Throws `ApiResponseError`: `404` `pipelex.catalog.not_found` for an unknown method or another
|
|
2775
|
+
* organization's internal one, its `params.resource` `method`, and for a version the method never
|
|
2776
|
+
* published, its `params.resource` `version`; `409` `pipelex.catalog.being_deleted` while the
|
|
2777
|
+
* erasure of the caller's own method is pending, under way or stopped; `500` `runtime.unexpected`
|
|
2778
|
+
* for a version stored before methods were trees, which names no tree. An answer whose `items` is
|
|
2779
|
+
* not an array is an answer the SDK cannot read, thrown as an `ApiResponseError` too; an entry
|
|
2780
|
+
* that does not read as a layout is left out (`readMethodLayouts`), so one layout it cannot read
|
|
2781
|
+
* never costs the caller the others.
|
|
2782
|
+
*/
|
|
2783
|
+
async listMethodLayouts(methodId, version, options = {}) {
|
|
2784
|
+
const call = "listMethodLayouts";
|
|
2785
|
+
if (!Number.isSafeInteger(version) || version < 1) {
|
|
2786
|
+
throw argumentRefusal(call, LAYOUT_LIST_VERSION_ARGUMENT, describeNumberArgument(version), "not_a_positive_integer");
|
|
2787
|
+
}
|
|
2788
|
+
const endpoint = `${methodPath(methodId, call)}/versions/${version}/layouts`;
|
|
2789
|
+
return this.requestMethodLayoutList(endpoint, options);
|
|
2790
|
+
}
|
|
2791
|
+
/**
|
|
2792
|
+
* The layouts stored for the content of a method's draft — `GET /v1/methods/{id}/draft/layouts` —
|
|
2793
|
+
* newest first, `items` empty for an empty draft or a draft none was designed for. A layout is
|
|
2794
|
+
* keyed by its content, so a draft holding a published tree finds that tree's layouts here, and a
|
|
2795
|
+
* builder sees the designs of what it is editing.
|
|
2796
|
+
*
|
|
2797
|
+
* It reads for the organization that holds the method alone, since a draft is its holder's. Takes
|
|
2798
|
+
* a bare catalog id, as `getMethod` does. `options.signal` cancels the read. Throws
|
|
2799
|
+
* `ApiResponseError`: `404` `pipelex.catalog.not_found` for a method the organization does not
|
|
2800
|
+
* hold, another organization's public one included, and `409` `pipelex.catalog.being_deleted`
|
|
2801
|
+
* while its erasure is pending, under way or stopped. An answer whose `items` is not an array is
|
|
2802
|
+
* an answer the SDK cannot read, thrown as an `ApiResponseError` too; an entry that does not read
|
|
2803
|
+
* as a layout is left out (`readMethodLayouts`).
|
|
2804
|
+
*/
|
|
2805
|
+
async listMethodDraftLayouts(methodId, options = {}) {
|
|
2806
|
+
const endpoint = `${methodPath(methodId, "listMethodDraftLayouts")}/draft/layouts`;
|
|
2807
|
+
return this.requestMethodLayoutList(endpoint, options);
|
|
2808
|
+
}
|
|
2809
|
+
/** The `{items}` of a route answering layouts, each entry read as `readMethodLayouts` reads it. */
|
|
2810
|
+
async requestMethodLayoutList(endpoint, options) {
|
|
2811
|
+
const res = await this.requestProductAnswer("GET", endpoint, undefined, {
|
|
2812
|
+
signal: options.signal,
|
|
2813
|
+
});
|
|
2814
|
+
const answer = this.readObjectAnswer("GET", endpoint, res);
|
|
2815
|
+
if (!Array.isArray(answer.items)) {
|
|
2816
|
+
throw this.unreadableAnswer("GET", `/${API_PREFIX}/${endpoint}`, res, "a list of layouts whose `items` is not an array");
|
|
2817
|
+
}
|
|
2818
|
+
return { ...answer, items: readMethodLayouts(answer.items) };
|
|
2819
|
+
}
|
|
2820
|
+
/**
|
|
2821
|
+
* Freeze a completed run of a method into a showcase — `POST /v1/methods/{id}/showcases` — and
|
|
2822
|
+
* answer what the freeze did.
|
|
2823
|
+
*
|
|
2824
|
+
* A showcase is real output, frozen: the run's inputs, its main output, the forms and contracts
|
|
2825
|
+
* that describe them, and a private copy of every stored file they name. It is keyed by the
|
|
2826
|
+
* digest of the run's tree, so a builder freezes a run of the draft before publishing it, and
|
|
2827
|
+
* another organization reads it only through a published version holding that tree. The run must
|
|
2828
|
+
* be this method's, completed and with stored results, and its tree must be the draft's or the
|
|
2829
|
+
* latest published version's.
|
|
2830
|
+
*
|
|
2831
|
+
* The answer is a `MethodShowcaseFreezeResult`, a `200` discriminated on `outcome` — branch on it:
|
|
2832
|
+
* `frozen` with the new `showcase`; `unchanged` with the one that stands, when this run is already
|
|
2833
|
+
* a showcase, whatever has happened to its tree since, the name in the request being ignored; or
|
|
2834
|
+
* `refused` with a `reason` and a `message`, nothing written (`MethodShowcaseRefusalReason`, read
|
|
2835
|
+
* open, so a later reason arrives as its raw string).
|
|
2836
|
+
*
|
|
2837
|
+
* The write changes the method, so it takes an `admin` or a `member` of the method's organization.
|
|
2838
|
+
* Takes a bare catalog id, as `getMethod` does. Sends `run_id` and `name` and nothing else, the
|
|
2839
|
+
* body being closed. `options.idempotencyKey` is sent as the `Idempotency-Key` header
|
|
2840
|
+
* (`MethodShowcaseWriteOptions`). Throws `RequestArgumentError` before any request for a `run_id`
|
|
2841
|
+
* or a `name` that is not a non-empty string, and for a malformed idempotency key. Throws
|
|
2842
|
+
* `ApiResponseError` when no verdict was produced: `403` `auth.forbidden` for a `runner`; `404`
|
|
2843
|
+
* `pipelex.catalog.not_found` for a method the organization does not hold; `409`
|
|
2844
|
+
* `pipelex.catalog.being_deleted` while its erasure is pending, under way or stopped; `422`
|
|
2845
|
+
* `request.invalid` for a body that does not validate; and `503` `runtime.unavailable`, with
|
|
2846
|
+
* `retry` `yes`, past the freeze's deadline. An answer that is none of the verdict's arms is an
|
|
2847
|
+
* answer the SDK cannot read, thrown as an `ApiResponseError` too.
|
|
2848
|
+
*/
|
|
2849
|
+
async freezeMethodShowcase(methodId, input, options = {}) {
|
|
2850
|
+
const call = "freezeMethodShowcase";
|
|
2851
|
+
const endpoint = `${methodPath(methodId, call)}/showcases`;
|
|
2852
|
+
const { run_id: runId, name } = input ?? {};
|
|
2853
|
+
const body = {
|
|
2854
|
+
run_id: requireNonEmptyId(runId, call, SHOWCASE_RUN_ID_ARGUMENT),
|
|
2855
|
+
name: requireNonEmptyId(name, call, SHOWCASE_NAME_ARGUMENT),
|
|
2856
|
+
};
|
|
2857
|
+
const idempotencyKey = idempotencyKeyOf(options, "freeze the showcase");
|
|
2858
|
+
const res = await this.requestProductAnswer("POST", endpoint, body, { idempotencyKey });
|
|
2859
|
+
const answer = this.readObjectAnswer("POST", endpoint, res);
|
|
2860
|
+
const fault = methodShowcaseFreezeFault(answer);
|
|
2861
|
+
if (fault !== null) {
|
|
2862
|
+
throw this.unreadableAnswer("POST", `/${API_PREFIX}/${endpoint}`, res, fault);
|
|
2863
|
+
}
|
|
2864
|
+
return answer;
|
|
2865
|
+
}
|
|
2866
|
+
/**
|
|
2867
|
+
* Withdraw a showcase — `DELETE /v1/methods/{id}/showcases/{showcase_id}`. The platform answers
|
|
2868
|
+
* `204`, the row going first, so every read closes at once, and then its stored document and
|
|
2869
|
+
* files. It runs no check, even on a public method's last showcase, because taking down something
|
|
2870
|
+
* published by mistake is never refused; the method then stays public and its next publish needs
|
|
2871
|
+
* a showcase. What another organization already copied stays theirs.
|
|
2872
|
+
*
|
|
2873
|
+
* `options.idempotencyKey` is sent as the `Idempotency-Key` header, so a withdrawal whose answer
|
|
2874
|
+
* was lost is sent again under the same key and answered as the first was
|
|
2875
|
+
* (`MethodShowcaseWriteOptions`). Throws `RequestArgumentError` before any request for a showcase
|
|
2876
|
+
* id that is empty, `.` or `..`, or holds a lone surrogate, and for a malformed idempotency key.
|
|
2877
|
+
* Throws `ApiResponseError`: `404` `pipelex.catalog.not_found`, its `params.resource` `example`,
|
|
2878
|
+
* when there is no such showcase, one already withdrawn included; `403` `auth.forbidden` for a
|
|
2879
|
+
* `runner`; and `422` `request.invalid` for an id that is not one a showcase can have.
|
|
2880
|
+
*/
|
|
2881
|
+
async withdrawMethodShowcase(methodId, showcaseId, options = {}) {
|
|
2882
|
+
const call = "withdrawMethodShowcase";
|
|
2883
|
+
const endpoint = `${methodPath(methodId, call)}/showcases/${idPathSegment(showcaseId, call, SHOWCASE_ID_ARGUMENT)}`;
|
|
2884
|
+
const idempotencyKey = idempotencyKeyOf(options, "withdraw the showcase");
|
|
2885
|
+
await this.requestProduct("DELETE", endpoint, undefined, { idempotencyKey });
|
|
2886
|
+
}
|
|
2887
|
+
/**
|
|
2888
|
+
* Every showcase of a method the caller's organization holds, across every tree, each naming its
|
|
2889
|
+
* digest, oldest first — `GET /v1/methods/{id}/showcases`.
|
|
2890
|
+
*
|
|
2891
|
+
* It reads for the holding organization's members alone: another organization reads a `404`,
|
|
2892
|
+
* public method or not, and reads a public method's showcases through
|
|
2893
|
+
* `listMethodVersionShowcases`. Takes a bare catalog id, as `getMethod` does. `options.signal`
|
|
2894
|
+
* cancels the read. Throws `ApiResponseError`: `404` `pipelex.catalog.not_found` for a method the
|
|
2895
|
+
* organization does not hold and `409` `pipelex.catalog.being_deleted` while its erasure is
|
|
2896
|
+
* pending, under way or stopped. An answer whose `items` is not an array is an answer the SDK
|
|
2897
|
+
* cannot read, thrown as an `ApiResponseError` too; an entry that does not read as a summary is
|
|
2898
|
+
* left out (`readMethodShowcaseSummaries`).
|
|
2899
|
+
*/
|
|
2900
|
+
async listMethodShowcases(methodId, options = {}) {
|
|
2901
|
+
const endpoint = `${methodPath(methodId, "listMethodShowcases")}/showcases`;
|
|
2902
|
+
return this.requestMethodShowcaseList(endpoint, options);
|
|
2903
|
+
}
|
|
2904
|
+
/**
|
|
2905
|
+
* One showcase of a method the caller's organization holds, in full, with a short-lived link to
|
|
2906
|
+
* each of its files — `GET /v1/methods/{id}/showcases/{showcase_id}`. Read with `parseExactJson`,
|
|
2907
|
+
* so an integer past `Number.MAX_SAFE_INTEGER` in its document is a `bigint`.
|
|
2908
|
+
*
|
|
2909
|
+
* It reads for the holding organization's members alone. Takes a bare catalog id, as `getMethod`
|
|
2910
|
+
* does, and refuses a showcase id as `withdrawMethodShowcase` does, before any request. Throws
|
|
2911
|
+
* `ApiResponseError`: `404` `pipelex.catalog.not_found` for a method the organization does not
|
|
2912
|
+
* hold and for a showcase it does not have, the latter's `params.resource` being `example`, and
|
|
2913
|
+
* `409` `pipelex.catalog.being_deleted` while its erasure is pending, under way or stopped. An
|
|
2914
|
+
* answer that does not read as a detail (`methodShowcaseDetailFault`) is an answer the SDK cannot
|
|
2915
|
+
* read, thrown as an `ApiResponseError` too, its signed links redacted.
|
|
2916
|
+
*/
|
|
2917
|
+
async getMethodShowcase(methodId, showcaseId, options = {}) {
|
|
2918
|
+
const call = "getMethodShowcase";
|
|
2919
|
+
const endpoint = `${methodPath(methodId, call)}/showcases/${idPathSegment(showcaseId, call, SHOWCASE_ID_ARGUMENT)}`;
|
|
2920
|
+
return this.requestMethodShowcaseDetail(endpoint, options);
|
|
2921
|
+
}
|
|
2922
|
+
/**
|
|
2923
|
+
* The showcases of the tree a published version holds, oldest first —
|
|
2924
|
+
* `GET /v1/methods/{id}/versions/{n}/showcases` — for every reader of that version, another
|
|
2925
|
+
* organization's on a public method included. `items` is empty when none is frozen. A showcase of
|
|
2926
|
+
* a tree no published version holds is never read through this route.
|
|
2927
|
+
*
|
|
2928
|
+
* Takes a bare catalog id, as `getMethod` does, and the version number. `options.signal` cancels
|
|
2929
|
+
* the read. Throws `RequestArgumentError` for a `version` that is not a positive integer, before
|
|
2930
|
+
* any request. Throws `ApiResponseError`: `404` `pipelex.catalog.not_found` for an unknown method
|
|
2931
|
+
* or another organization's internal one, its `params.resource` `method`, and for a version the
|
|
2932
|
+
* method never published, its `params.resource` `version`; and `409`
|
|
2933
|
+
* `pipelex.catalog.being_deleted` while the erasure of the caller's own method is pending, under
|
|
2934
|
+
* way or stopped. An answer whose `items` is not an array is an answer the SDK cannot read, thrown
|
|
2935
|
+
* as an `ApiResponseError` too; an entry that does not read as a summary is left out.
|
|
2936
|
+
*/
|
|
2937
|
+
async listMethodVersionShowcases(methodId, version, options = {}) {
|
|
2938
|
+
const endpoint = methodVersionShowcasesPath(methodId, version, "listMethodVersionShowcases");
|
|
2939
|
+
return this.requestMethodShowcaseList(endpoint, options);
|
|
2940
|
+
}
|
|
2941
|
+
/**
|
|
2942
|
+
* One showcase of the tree a published version holds, in full, with a short-lived link to each of
|
|
2943
|
+
* its files — `GET /v1/methods/{id}/versions/{n}/showcases/{showcase_id}`. Read with
|
|
2944
|
+
* `parseExactJson`, so an integer past `Number.MAX_SAFE_INTEGER` in its document is a `bigint`. A
|
|
2945
|
+
* showcase of another tree reads as not found.
|
|
2946
|
+
*
|
|
2947
|
+
* The refusals are `listMethodVersionShowcases`'s, and a showcase that tree does not hold is a
|
|
2948
|
+
* `404` `pipelex.catalog.not_found` whose `params.resource` is `example`. The showcase id is
|
|
2949
|
+
* refused as `withdrawMethodShowcase` refuses it. An answer that does not read as a detail is an
|
|
2950
|
+
* answer the SDK cannot read, thrown as an `ApiResponseError` too, its signed links redacted.
|
|
2951
|
+
*/
|
|
2952
|
+
async getMethodVersionShowcase(methodId, version, showcaseId, options = {}) {
|
|
2953
|
+
const call = "getMethodVersionShowcase";
|
|
2954
|
+
const list = methodVersionShowcasesPath(methodId, version, call);
|
|
2955
|
+
const endpoint = `${list}/${idPathSegment(showcaseId, call, SHOWCASE_ID_ARGUMENT)}`;
|
|
2956
|
+
return this.requestMethodShowcaseDetail(endpoint, options);
|
|
2957
|
+
}
|
|
2958
|
+
/** The `{items}` of a route answering showcase summaries, each read as `readMethodShowcaseSummaries` reads it. */
|
|
2959
|
+
async requestMethodShowcaseList(endpoint, options) {
|
|
2960
|
+
const res = await this.requestProductAnswer("GET", endpoint, undefined, {
|
|
2961
|
+
signal: options.signal,
|
|
2962
|
+
});
|
|
2963
|
+
const answer = this.readObjectAnswer("GET", endpoint, res);
|
|
2964
|
+
if (!Array.isArray(answer.items)) {
|
|
2965
|
+
throw this.unreadableAnswer("GET", `/${API_PREFIX}/${endpoint}`, res, "a list of showcases whose `items` is not an array");
|
|
2966
|
+
}
|
|
2967
|
+
return { ...answer, items: readMethodShowcaseSummaries(answer.items) };
|
|
2968
|
+
}
|
|
2969
|
+
/** A route answering one showcase in full, its answer read exactly and any error's links redacted. */
|
|
2970
|
+
async requestMethodShowcaseDetail(endpoint, options) {
|
|
2971
|
+
const res = withLinks(await this.requestProductAnswer("GET", endpoint, undefined, { signal: options.signal }));
|
|
2972
|
+
const answer = this.readObjectAnswer("GET", endpoint, res, {}, parseExactJson);
|
|
2973
|
+
const fault = methodShowcaseDetailFault(answer);
|
|
2974
|
+
if (fault !== null) {
|
|
2975
|
+
throw this.unreadableAnswer("GET", `/${API_PREFIX}/${endpoint}`, res, `a showcase ${fault}`);
|
|
2976
|
+
}
|
|
2977
|
+
return answer;
|
|
2978
|
+
}
|
|
2979
|
+
/**
|
|
2980
|
+
* Set which catalogs of a method have their layouts switched off —
|
|
2981
|
+
* `PUT /v1/methods/{id}/layouts-off` — and return the method, its `layouts_off` the list as held.
|
|
2982
|
+
*
|
|
2983
|
+
* `catalogs` is the whole list and replaces the one held, each catalog id once, at most 8, empty
|
|
2984
|
+
* when every design is on: to change one, read `layouts_off` and write the new list. The switch
|
|
2985
|
+
* acts at once, with no publish, and holds across every publish. A layout switched off is kept,
|
|
2986
|
+
* and `listMethodLayouts` still answers it; a host draws the plain page instead. Like a rename, it
|
|
2987
|
+
* never moves the draft token, so the `updated_at` a caller holds stays valid.
|
|
2988
|
+
*
|
|
2989
|
+
* The last write to land is the one held. `options.idempotencyKey` is sent as the
|
|
2990
|
+
* `Idempotency-Key` header, so a write whose answer was lost is sent again under the same key and
|
|
2991
|
+
* answered as the first was (`MethodLayoutsOffOptions`).
|
|
2992
|
+
*
|
|
2993
|
+
* The write changes the method, so it takes an `admin` or a `member` of the method's
|
|
2994
|
+
* organization. Takes a bare catalog id, as `getMethod` does. Throws `RequestArgumentError` before
|
|
2995
|
+
* any request for `catalogs` that is not an array; its entries are sent as given. Throws
|
|
2996
|
+
* `ApiResponseError`: `404` `pipelex.catalog.not_found` for an unknown method or another
|
|
2997
|
+
* organization's, a public one included; `403` `auth.forbidden` naming the `member` requirement
|
|
2998
|
+
* for a `runner` or a caller with no recognised role; `409` `pipelex.catalog.being_deleted` while
|
|
2999
|
+
* the method's erasure is pending, under way or stopped; `413` `request.too_large` for a list that
|
|
3000
|
+
* would leave the method too large to publish, which a list that does not grow never is; and
|
|
3001
|
+
* `422` `request.invalid` for more than 8 catalogs, a catalog named twice or one that is not a
|
|
3002
|
+
* slug. Under an idempotency key, `409` `request.idempotency_conflict` for the key sent with a
|
|
3003
|
+
* different list and `409` `request.idempotency_key_in_use` while its earlier request is still
|
|
3004
|
+
* being handled; a key that is not 1 to 255 visible ASCII characters is a `RequestArgumentError`
|
|
3005
|
+
* before any request.
|
|
3006
|
+
*/
|
|
3007
|
+
async setMethodLayoutsOff(methodId, catalogs, options = {}) {
|
|
3008
|
+
const call = "setMethodLayoutsOff";
|
|
3009
|
+
const endpoint = `${methodPath(methodId, call)}/layouts-off`;
|
|
3010
|
+
if (!Array.isArray(catalogs)) {
|
|
3011
|
+
throw argumentRefusal(call, LAYOUTS_OFF_CATALOGS_ARGUMENT, describeNumberArgument(catalogs), "not_a_list");
|
|
3012
|
+
}
|
|
3013
|
+
const idempotencyKey = idempotencyKeyOf(options, "set the layouts off");
|
|
3014
|
+
return this.requestMethodData("PUT", endpoint, { catalogs }, { idempotencyKey });
|
|
3015
|
+
}
|
|
2719
3016
|
/**
|
|
2720
3017
|
* Copy a method into an organization the caller may change methods in —
|
|
2721
3018
|
* `POST /v1/methods/{id}/copy`: the method's own organization for a duplicate, another team, or
|
|
@@ -2735,7 +3032,8 @@ export class PipelexApiClient {
|
|
|
2735
3032
|
* is refused with a `422` `request.invalid` naming it.
|
|
2736
3033
|
*
|
|
2737
3034
|
* The answer is a `MethodCopyResult` discriminated on `outcome` — branch on it: `copied` with
|
|
2738
|
-
* the copy as `method`, `examples_copied` and
|
|
3035
|
+
* the copy as `method`, `examples_copied`, `stored_files_copied` and the counts reserved for
|
|
3036
|
+
* showcases, `showcases_copied` and `layouts_copied`; `refused` with the
|
|
2739
3037
|
* `reason` `bundle_names_other_storage`, a `message` and every `references` entry (`{ path, uri
|
|
2740
3038
|
* }`) a `.mthds` file of the tree holds that the destination cannot read and, in a duplicate,
|
|
2741
3039
|
* that names a file under the original's run files, which erasing the original would remove,
|
|
@@ -4483,14 +4781,15 @@ const MAX_IDEMPOTENCY_KEY_LENGTH = 255;
|
|
|
4483
4781
|
*/
|
|
4484
4782
|
const VISIBLE_ASCII = /^[\x21-\x7E]+$/;
|
|
4485
4783
|
/**
|
|
4486
|
-
* The idempotency key a start, a method copy, a layout write, a
|
|
4487
|
-
* replay sends, or
|
|
4784
|
+
* The idempotency key a start, a method copy, a layout write, a write of the layouts switched off,
|
|
4785
|
+
* a showcase write, a secret rotation or a delivery replay sends, or
|
|
4488
4786
|
* `undefined` when the options carry none (absent or `null`). A key that is not a string of 1 to
|
|
4489
4787
|
* 255 visible ASCII characters is refused with a `RequestArgumentError` rather than dropped, an
|
|
4490
4788
|
* empty one included, since a request sent without the key its caller gave would lose the
|
|
4491
4789
|
* protection the caller asked for without a word. `request` says what the request does, as the
|
|
4492
4790
|
* refusal's last sentence names it ("start the run", "copy the method", "store the layout",
|
|
4493
|
-
* "
|
|
4791
|
+
* "set the layouts off", "freeze the showcase", "withdraw the showcase", "rotate the secret",
|
|
4792
|
+
* "replay the delivery"). The message never quotes the key, which a caller may derive from
|
|
4494
4793
|
* something private. The Python SDK holds a key to the same rule, in the same words.
|
|
4495
4794
|
*/
|
|
4496
4795
|
function idempotencyKeyOf(options, request = "start the run") {
|
|
@@ -4871,10 +5170,20 @@ function withReadLayouts(answer) {
|
|
|
4871
5170
|
read.layouts = layouts;
|
|
4872
5171
|
return read;
|
|
4873
5172
|
}
|
|
5173
|
+
/** `source`'s members that `members` lists, each `optional` one left out when `null` or omitted. */
|
|
5174
|
+
function sentMembers(members, source) {
|
|
5175
|
+
const sent = {};
|
|
5176
|
+
for (const [member, presence] of Object.entries(members)) {
|
|
5177
|
+
const value = source[member];
|
|
5178
|
+
if (presence === "required" || value != null)
|
|
5179
|
+
sent[member] = value;
|
|
5180
|
+
}
|
|
5181
|
+
return sent;
|
|
5182
|
+
}
|
|
4874
5183
|
/**
|
|
4875
5184
|
* The body `storeMethodLayout` sends for `layout`: the members of `MethodLayoutInput` and nothing
|
|
4876
|
-
* else, since the route's body is closed at both levels, each provenance member
|
|
4877
|
-
* omitted left out for the platform's default. The members are `LAYOUT_INPUT_MEMBERS` and
|
|
5185
|
+
* else, since the route's body is closed at both levels, `sample_json` and each provenance member
|
|
5186
|
+
* that is `null` or omitted left out for the platform's default. The members are `LAYOUT_INPUT_MEMBERS` and
|
|
4878
5187
|
* `PROVENANCE_INPUT_MEMBERS`, which the build holds to the interfaces. A layout or a provenance that is not an object is
|
|
4879
5188
|
* refused with `RequestArgumentError` before anything is sent; every other member is sent as given,
|
|
4880
5189
|
* for the platform to hold to its shapes, its `422` naming the member it refuses.
|
|
@@ -4887,16 +5196,8 @@ function methodLayoutBody(layout, call) {
|
|
|
4887
5196
|
if (!isPlainObject(provenance)) {
|
|
4888
5197
|
throw argumentRefusal(call, LAYOUT_PROVENANCE_ARGUMENT, describeNumberArgument(provenance), "not_an_object");
|
|
4889
5198
|
}
|
|
4890
|
-
const
|
|
4891
|
-
|
|
4892
|
-
const value = provenance[member];
|
|
4893
|
-
if (presence === "required" || value != null)
|
|
4894
|
-
sentProvenance[member] = value;
|
|
4895
|
-
}
|
|
4896
|
-
const body = {};
|
|
4897
|
-
for (const member of Object.keys(LAYOUT_INPUT_MEMBERS))
|
|
4898
|
-
body[member] = layout[member];
|
|
4899
|
-
body.provenance = sentProvenance;
|
|
5199
|
+
const body = sentMembers(LAYOUT_INPUT_MEMBERS, layout);
|
|
5200
|
+
body.provenance = sentMembers(PROVENANCE_INPUT_MEMBERS, provenance);
|
|
4900
5201
|
return body;
|
|
4901
5202
|
}
|
|
4902
5203
|
/**
|