@ebay-dt/bonfire-core 0.1.0-alpha.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/LICENSE +21 -0
- package/README.md +110 -0
- package/dist/auth-model.d.ts +24 -0
- package/dist/auth-model.d.ts.map +1 -0
- package/dist/auth-model.js +2 -0
- package/dist/auth-model.js.map +1 -0
- package/dist/config.d.ts +19 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +106 -0
- package/dist/config.js.map +1 -0
- package/dist/identity.d.ts +15 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +66 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/types.d.ts +4 -0
- package/dist/internal/types.d.ts.map +1 -0
- package/dist/internal/types.js +2 -0
- package/dist/internal/types.js.map +1 -0
- package/dist/internal/utils.d.ts +16 -0
- package/dist/internal/utils.d.ts.map +1 -0
- package/dist/internal/utils.js +29 -0
- package/dist/internal/utils.js.map +1 -0
- package/dist/lifecycle-input.d.ts +28 -0
- package/dist/lifecycle-input.d.ts.map +1 -0
- package/dist/lifecycle-input.js +104 -0
- package/dist/lifecycle-input.js.map +1 -0
- package/dist/lifecycle.d.ts +51 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +27 -0
- package/dist/lifecycle.js.map +1 -0
- package/dist/prototype-catalog.d.ts +22 -0
- package/dist/prototype-catalog.d.ts.map +1 -0
- package/dist/prototype-catalog.js +63 -0
- package/dist/prototype-catalog.js.map +1 -0
- package/dist/prototype-metadata.d.ts +21 -0
- package/dist/prototype-metadata.d.ts.map +1 -0
- package/dist/prototype-metadata.js +146 -0
- package/dist/prototype-metadata.js.map +1 -0
- package/dist/prototype-ref.d.ts +13 -0
- package/dist/prototype-ref.d.ts.map +1 -0
- package/dist/prototype-ref.js +138 -0
- package/dist/prototype-ref.js.map +1 -0
- package/package.json +43 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Bonfire contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# `@ebay-dt/bonfire-core`
|
|
2
|
+
|
|
3
|
+
Framework-neutral Bonfire contracts. It provides validated, frozen instance
|
|
4
|
+
configuration, app-specific session cookie names, runtime identity parsing, and
|
|
5
|
+
the serializable GitHub CLI login-page model.
|
|
6
|
+
|
|
7
|
+
## Configuration
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { defineConfig } from "@ebay-dt/bonfire-core";
|
|
11
|
+
|
|
12
|
+
const config = defineConfig({
|
|
13
|
+
appId: "my-app",
|
|
14
|
+
name: "My App",
|
|
15
|
+
auth: {
|
|
16
|
+
github: {
|
|
17
|
+
hostname: "github.com",
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
`appId` is used to derive an isolated session-cookie name. Hostnames are
|
|
24
|
+
normalized and validated as plain hostnames without protocols, ports, or paths.
|
|
25
|
+
Identity values and configuration are validated at runtime, and normalized
|
|
26
|
+
configuration is deeply frozen.
|
|
27
|
+
|
|
28
|
+
The package also exports the `BonfireIdentity` and
|
|
29
|
+
`GitHubCliLoginPageModel` types used by the Node, Next.js, and React packages.
|
|
30
|
+
|
|
31
|
+
## Prototype catalog contracts
|
|
32
|
+
|
|
33
|
+
Prototype references use a validated login and lowercase kebab-case slug:
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import {
|
|
37
|
+
definePrototypeRef,
|
|
38
|
+
getPrototypeUrl,
|
|
39
|
+
parsePrototypePath,
|
|
40
|
+
slugifyPrototypeTitle,
|
|
41
|
+
} from "@ebay-dt/bonfire-core";
|
|
42
|
+
|
|
43
|
+
const ref = definePrototypeRef({
|
|
44
|
+
login: "octocat",
|
|
45
|
+
slug: slugifyPrototypeTitle("Checkout Redesign")!,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
getPrototypeUrl(ref); // "/octocat/checkout-redesign"
|
|
49
|
+
parsePrototypePath("/octocat/checkout-redesign/details"); // ref
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Metadata uses `authorLogin` for the login corresponding to
|
|
53
|
+
`BonfireIdentity.login`; `authorName` corresponds to its nullable `name`.
|
|
54
|
+
Metadata is normalized, validated, and deeply frozen by
|
|
55
|
+
`parsePrototypeMetadata`. Unknown fields are discarded.
|
|
56
|
+
|
|
57
|
+
Catalog queries support `all`, `mine`, or a validated author login, with
|
|
58
|
+
`recent`, `alphabetical`, and `deployed` sorting:
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
import {
|
|
62
|
+
filterPrototypes,
|
|
63
|
+
sortPrototypes,
|
|
64
|
+
type PrototypeCatalogQuery,
|
|
65
|
+
} from "@ebay-dt/bonfire-core";
|
|
66
|
+
|
|
67
|
+
const query: PrototypeCatalogQuery = {
|
|
68
|
+
author: "all",
|
|
69
|
+
sort: "recent",
|
|
70
|
+
};
|
|
71
|
+
const visible = sortPrototypes(
|
|
72
|
+
filterPrototypes(summaries, query.author, currentLogin),
|
|
73
|
+
query.sort,
|
|
74
|
+
);
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Prototype lifecycle contracts
|
|
78
|
+
|
|
79
|
+
Lifecycle commands return stable, framework-neutral results. Failures contain
|
|
80
|
+
only a machine-readable code; adapters own user-facing messages:
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
import {
|
|
84
|
+
parseCreatePrototypeInput,
|
|
85
|
+
type LifecycleResult,
|
|
86
|
+
} from "@ebay-dt/bonfire-core";
|
|
87
|
+
|
|
88
|
+
const input = parseCreatePrototypeInput(formValue);
|
|
89
|
+
const result: LifecycleResult<unknown> = await create(input);
|
|
90
|
+
if (!result.ok) {
|
|
91
|
+
result.error.code; // "invalid-input", "git-failure", etc.
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Create and duplicate inputs normalize title/description and validate all
|
|
96
|
+
prototype references. Save and discard use the same normalized `PrototypeRef`
|
|
97
|
+
command input. Destination identity and slug are intentionally absent from
|
|
98
|
+
browser input; trusted services derive them from the authenticated identity and
|
|
99
|
+
normalized title. Create, duplicate, save, and discard are development-only
|
|
100
|
+
mutation contracts; production adapters remain public and read-only.
|
|
101
|
+
|
|
102
|
+
Dirty observation is represented by the finite `clean` and `dirty` statuses. It
|
|
103
|
+
is an observation of the repository, not durable client state.
|
|
104
|
+
Save and discard return explicit success values and never expose filesystem
|
|
105
|
+
paths, Git output, or framework values.
|
|
106
|
+
|
|
107
|
+
Lifecycle errors contain only stable codes, never filesystem paths, Git output,
|
|
108
|
+
GitHub CLI output, or secrets. Hosts own user-facing copy for codes such as
|
|
109
|
+
`invalid-input`, `already-exists`, `repository-busy`, `working-tree-conflict`,
|
|
110
|
+
`git-failure`, and `filesystem-failure`.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type GitHubCliLoginPageError = "gh_cli_failed" | "branch_prepare_failed";
|
|
2
|
+
export type GitHubCliLoginPageModel = {
|
|
3
|
+
/** App name shown in the login page. */
|
|
4
|
+
applicationName: string;
|
|
5
|
+
/** Configured GitHub or GitHub Enterprise hostname. */
|
|
6
|
+
githubHostname: string;
|
|
7
|
+
/** Endpoint invoked by the Continue button. */
|
|
8
|
+
loginUrl: string;
|
|
9
|
+
/** Endpoint polled during device authentication. */
|
|
10
|
+
statusUrl: string;
|
|
11
|
+
/** Destination after successful authentication. */
|
|
12
|
+
returnUrl: string;
|
|
13
|
+
/** GitHub device activation link. */
|
|
14
|
+
deviceUrl: string;
|
|
15
|
+
/** Safe fallback command for manually starting GitHub CLI login. */
|
|
16
|
+
fallbackCommand: string;
|
|
17
|
+
/** One-time device code, when the CLI provides one. */
|
|
18
|
+
deviceCode: string | null;
|
|
19
|
+
/** Whether the client should begin status polling. */
|
|
20
|
+
pollingActive: boolean;
|
|
21
|
+
/** Generic login failure state, if any. */
|
|
22
|
+
error: GitHubCliLoginPageError | null;
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=auth-model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-model.d.ts","sourceRoot":"","sources":["../src/auth-model.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,uBAAuB,GAAG,eAAe,GAAG,uBAAuB,CAAC;AAEhF,MAAM,MAAM,uBAAuB,GAAG;IACpC,wCAAwC;IACxC,eAAe,EAAE,MAAM,CAAC;IACxB,uDAAuD;IACvD,cAAc,EAAE,MAAM,CAAC;IACvB,+CAA+C;IAC/C,QAAQ,EAAE,MAAM,CAAC;IACjB,oDAAoD;IACpD,SAAS,EAAE,MAAM,CAAC;IAClB,mDAAmD;IACnD,SAAS,EAAE,MAAM,CAAC;IAClB,qCAAqC;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,oEAAoE;IACpE,eAAe,EAAE,MAAM,CAAC;IACxB,uDAAuD;IACvD,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,sDAAsD;IACtD,aAAa,EAAE,OAAO,CAAC;IACvB,2CAA2C;IAC3C,KAAK,EAAE,uBAAuB,GAAG,IAAI,CAAC;CACvC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-model.js","sourceRoot":"","sources":["../src/auth-model.ts"],"names":[],"mappings":""}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { DeepReadonly } from "./internal/types.js";
|
|
2
|
+
export type BonfireConfigInput = {
|
|
3
|
+
appId: string;
|
|
4
|
+
name: string;
|
|
5
|
+
auth: {
|
|
6
|
+
github: {
|
|
7
|
+
hostname: string;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export type BonfireConfig = DeepReadonly<BonfireConfigInput>;
|
|
12
|
+
export declare class BonfireConfigError extends Error {
|
|
13
|
+
readonly path: string;
|
|
14
|
+
constructor(path: string, message: string);
|
|
15
|
+
}
|
|
16
|
+
export declare function parseHostname(value: unknown): string;
|
|
17
|
+
export declare function defineConfig(input: BonfireConfigInput): BonfireConfig;
|
|
18
|
+
export declare function getSessionCookieName(appId: string): string;
|
|
19
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAQxD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE;QACJ,MAAM,EAAE;YACN,QAAQ,EAAE,MAAM,CAAC;SAClB,CAAC;KACH,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,YAAY,CAAC,kBAAkB,CAAC,CAAC;AAE7D,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,YAAY,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAIxC;CACF;AAsGD,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEpD;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,kBAAkB,GAAG,aAAa,CA8BrE;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,UAEjD"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { asRecord, deepFreeze, findUnknownKey, readRequiredString, } from "./internal/utils.js";
|
|
2
|
+
const APP_ID_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
3
|
+
const HOSTNAME_LABEL_PATTERN = /^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)$/;
|
|
4
|
+
const MAX_APP_ID_LENGTH = 63;
|
|
5
|
+
const MAX_HOSTNAME_LENGTH = 253;
|
|
6
|
+
const SESSION_COOKIE_PREFIX = "bf_session_";
|
|
7
|
+
export class BonfireConfigError extends Error {
|
|
8
|
+
path;
|
|
9
|
+
constructor(path, message) {
|
|
10
|
+
super(`Invalid Bonfire configuration at ${path}: ${message}`);
|
|
11
|
+
this.name = "BonfireConfigError";
|
|
12
|
+
this.path = path;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function configRecord(value, path) {
|
|
16
|
+
const record = asRecord(value);
|
|
17
|
+
if (record === null) {
|
|
18
|
+
throw new BonfireConfigError(path, "must be an object");
|
|
19
|
+
}
|
|
20
|
+
return record;
|
|
21
|
+
}
|
|
22
|
+
function configRequiredString(record, key, path) {
|
|
23
|
+
const result = readRequiredString(record, key);
|
|
24
|
+
if (result.status === "missing") {
|
|
25
|
+
throw new BonfireConfigError(`${path}.${key}`, "is required");
|
|
26
|
+
}
|
|
27
|
+
if (result.status === "invalid") {
|
|
28
|
+
throw new BonfireConfigError(`${path}.${key}`, "must be a string");
|
|
29
|
+
}
|
|
30
|
+
return result.value;
|
|
31
|
+
}
|
|
32
|
+
function rejectConfigUnknownKeys(record, allowedKeys, path) {
|
|
33
|
+
const unknownKey = findUnknownKey(record, allowedKeys);
|
|
34
|
+
if (unknownKey) {
|
|
35
|
+
throw new BonfireConfigError(`${path}.${unknownKey}`, "is not supported");
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function validateAppId(value, path) {
|
|
39
|
+
if (typeof value !== "string") {
|
|
40
|
+
throw new BonfireConfigError(path, "must be a string");
|
|
41
|
+
}
|
|
42
|
+
if (value.length === 0) {
|
|
43
|
+
throw new BonfireConfigError(path, "must not be empty");
|
|
44
|
+
}
|
|
45
|
+
if (value.length > MAX_APP_ID_LENGTH) {
|
|
46
|
+
throw new BonfireConfigError(path, `must be at most ${MAX_APP_ID_LENGTH} characters`);
|
|
47
|
+
}
|
|
48
|
+
if (!APP_ID_PATTERN.test(value)) {
|
|
49
|
+
throw new BonfireConfigError(path, "must contain lowercase letters, numbers, and single hyphens between segments");
|
|
50
|
+
}
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
function validateName(value, path) {
|
|
54
|
+
if (typeof value !== "string") {
|
|
55
|
+
throw new BonfireConfigError(path, "must be a string");
|
|
56
|
+
}
|
|
57
|
+
const normalized = value.trim();
|
|
58
|
+
if (normalized.length === 0) {
|
|
59
|
+
throw new BonfireConfigError(path, "must not be empty");
|
|
60
|
+
}
|
|
61
|
+
return normalized;
|
|
62
|
+
}
|
|
63
|
+
function validateHostname(value, path) {
|
|
64
|
+
if (typeof value !== "string") {
|
|
65
|
+
throw new BonfireConfigError(path, "must be a string");
|
|
66
|
+
}
|
|
67
|
+
const normalized = value.toLowerCase();
|
|
68
|
+
const labels = normalized.endsWith(".")
|
|
69
|
+
? normalized.slice(0, -1).split(".")
|
|
70
|
+
: normalized.split(".");
|
|
71
|
+
if (value.length === 0 ||
|
|
72
|
+
value !== value.trim() ||
|
|
73
|
+
value.length > MAX_HOSTNAME_LENGTH ||
|
|
74
|
+
labels.some((label) => !HOSTNAME_LABEL_PATTERN.test(label))) {
|
|
75
|
+
throw new BonfireConfigError(path, "must be a plain hostname without protocols, credentials, ports, paths, queries, fragments, or whitespace");
|
|
76
|
+
}
|
|
77
|
+
return normalized;
|
|
78
|
+
}
|
|
79
|
+
export function parseHostname(value) {
|
|
80
|
+
return validateHostname(value, "hostname");
|
|
81
|
+
}
|
|
82
|
+
export function defineConfig(input) {
|
|
83
|
+
const root = configRecord(input, "config");
|
|
84
|
+
rejectConfigUnknownKeys(root, ["appId", "name", "auth"], "config");
|
|
85
|
+
const appId = validateAppId(root.appId, "config.appId");
|
|
86
|
+
const name = validateName(configRequiredString(root, "name", "config"), "config.name");
|
|
87
|
+
const auth = configRecord(root.auth, "config.auth");
|
|
88
|
+
rejectConfigUnknownKeys(auth, ["github"], "config.auth");
|
|
89
|
+
const github = configRecord(auth.github, "config.auth.github");
|
|
90
|
+
rejectConfigUnknownKeys(github, ["hostname"], "config.auth.github");
|
|
91
|
+
const hostname = validateHostname(configRequiredString(github, "hostname", "config.auth.github"), "config.auth.github.hostname");
|
|
92
|
+
const normalized = {
|
|
93
|
+
appId,
|
|
94
|
+
name,
|
|
95
|
+
auth: {
|
|
96
|
+
github: {
|
|
97
|
+
hostname,
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
return deepFreeze(normalized);
|
|
102
|
+
}
|
|
103
|
+
export function getSessionCookieName(appId) {
|
|
104
|
+
return `${SESSION_COOKIE_PREFIX}${validateAppId(appId, "appId")}`;
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,UAAU,EACV,cAAc,EACd,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAG7B,MAAM,cAAc,GAAG,4BAA4B,CAAC;AACpD,MAAM,sBAAsB,GAAG,4CAA4C,CAAC;AAC5E,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAC7B,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAChC,MAAM,qBAAqB,GAAG,aAAa,CAAC;AAc5C,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAClC,IAAI,CAAS;IAEtB,YAAY,IAAY,EAAE,OAAe;QACvC,KAAK,CAAC,oCAAoC,IAAI,KAAK,OAAO,EAAE,CAAC,CAAC;QAC9D,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;QACjC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAED,SAAS,YAAY,CAAC,KAAc,EAAE,IAAY;IAChD,MAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC/B,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QACpB,MAAM,IAAI,kBAAkB,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC;IAC1D,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,oBAAoB,CAC3B,MAA+B,EAC/B,GAAW,EACX,IAAY;IAEZ,MAAM,MAAM,GAAG,kBAAkB,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC/C,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;QAChC,MAAM,IAAI,kBAAkB,CAAC,GAAG,IAAI,IAAI,GAAG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|
|
5
|
+
};
|
|
6
|
+
export declare class BonfireIdentityError extends Error {
|
|
7
|
+
readonly path: string;
|
|
8
|
+
constructor(path: string, message: string);
|
|
9
|
+
}
|
|
10
|
+
export declare function parseBonfireIdentity(value: unknown): {
|
|
11
|
+
login: string;
|
|
12
|
+
name: string | null;
|
|
13
|
+
avatar_url: string;
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=identity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,YAAY,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAIxC;CACF;AAwDD,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO;;;;EAyBlD"}
|
package/dist/identity.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { asRecord, findUnknownKey } from "./internal/utils.js";
|
|
2
|
+
export class BonfireIdentityError extends Error {
|
|
3
|
+
path;
|
|
4
|
+
constructor(path, message) {
|
|
5
|
+
super(`Invalid Bonfire identity at ${path}: ${message}`);
|
|
6
|
+
this.name = "BonfireIdentityError";
|
|
7
|
+
this.path = path;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
function parseLogin(value) {
|
|
11
|
+
if (typeof value !== "string") {
|
|
12
|
+
throw new BonfireIdentityError("identity.login", "must be a string");
|
|
13
|
+
}
|
|
14
|
+
if (value.length === 0 || /\s/.test(value)) {
|
|
15
|
+
throw new BonfireIdentityError("identity.login", "must be a nonempty GitHub login");
|
|
16
|
+
}
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
function parseName(record) {
|
|
20
|
+
if (!Object.hasOwn(record, "name"))
|
|
21
|
+
return null;
|
|
22
|
+
const value = record.name;
|
|
23
|
+
if (value === null)
|
|
24
|
+
return null;
|
|
25
|
+
if (typeof value !== "string") {
|
|
26
|
+
throw new BonfireIdentityError("identity.name", "must be a string or null");
|
|
27
|
+
}
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
function parseAvatarUrl(value) {
|
|
31
|
+
if (typeof value !== "string" ||
|
|
32
|
+
value.length === 0 ||
|
|
33
|
+
value !== value.trim()) {
|
|
34
|
+
throw new BonfireIdentityError("identity.avatar_url", "must be a valid HTTP(S) URL");
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
const url = new URL(value);
|
|
38
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
39
|
+
throw new Error("unsupported protocol");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
throw new BonfireIdentityError("identity.avatar_url", "must be a valid HTTP(S) URL");
|
|
44
|
+
}
|
|
45
|
+
return value;
|
|
46
|
+
}
|
|
47
|
+
export function parseBonfireIdentity(value) {
|
|
48
|
+
const record = asRecord(value);
|
|
49
|
+
if (record === null) {
|
|
50
|
+
throw new BonfireIdentityError("identity", "must be an object");
|
|
51
|
+
}
|
|
52
|
+
const unknownKey = findUnknownKey(record, ["login", "name", "avatar_url"]);
|
|
53
|
+
if (unknownKey) {
|
|
54
|
+
throw new BonfireIdentityError(`identity.${unknownKey}`, "is not supported");
|
|
55
|
+
}
|
|
56
|
+
const login = parseLogin(record.login);
|
|
57
|
+
const name = parseName(record);
|
|
58
|
+
const avatar_url = parseAvatarUrl(record.avatar_url);
|
|
59
|
+
const identity = {
|
|
60
|
+
login,
|
|
61
|
+
name,
|
|
62
|
+
avatar_url,
|
|
63
|
+
};
|
|
64
|
+
return identity;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=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QACJ,UAAU;KACe,CAAC;IAE5B,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { defineConfig, getSessionCookieName, parseHostname, type BonfireConfig, type BonfireConfigInput, } from "./config.js";
|
|
2
|
+
export { parseBonfireIdentity, BonfireIdentityError, type BonfireIdentity, } from "./identity.js";
|
|
3
|
+
export type { GitHubCliLoginPageModel } from "./auth-model.js";
|
|
4
|
+
export { definePrototypeRef, getPrototypeUrl, parsePrototypePath, PrototypeRefError, slugifyPrototypeTitle, } from "./prototype-ref.js";
|
|
5
|
+
export type { PrototypeRef } from "./prototype-ref.js";
|
|
6
|
+
export { definePrototypeSummary, parsePrototypeMetadata, PrototypeMetadataError, type PrototypeMetadata, type PrototypeSummary, } from "./prototype-metadata.js";
|
|
7
|
+
export { filterPrototypes, getPrototypeAuthorOptions, sortPrototypes, type PrototypeAuthorOption, type PrototypeAuthorSelection, type PrototypeCatalogQuery, type PrototypeDashboardModel, type PrototypeSort, } from "./prototype-catalog.js";
|
|
8
|
+
export { AutomaticBranchSwitchSettingError, isLifecycleFailure, isLifecycleSuccess, parseAutomaticBranchSwitchSetting, lifecycleFailure, lifecycleSuccess, type AutomaticBranchSwitchMode, type BranchPreparationStatus, type BranchPreparationValue, type CreatePrototypeValue, type DirtyObservationStatus, type DirtyObservationValue, type DiscardPrototypeValue, type DuplicatePrototypeValue, type LifecycleError, type LifecycleErrorCode, type LifecyclePrototypeValue, type LifecycleRemoteStatus, type LifecycleResult, type SavePrototypeValue, } from "./lifecycle.js";
|
|
9
|
+
export { LifecycleInputError, parseCreatePrototypeInput, parseDiscardPrototypeInput, parseDuplicatePrototypeInput, parsePrototypeCommandInput, parseSavePrototypeInput, PROTOTYPE_DESCRIPTION_MAX_CODE_POINTS, PROTOTYPE_TITLE_MAX_CODE_POINTS, type CreatePrototypeInput, type DiscardPrototypeInput, type DuplicatePrototypeInput, type PrototypeCommandInput, type SavePrototypeInput, } from "./lifecycle-input.js";
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,oBAAoB,EACpB,aAAa,EACb,KAAK,aAAa,EAClB,KAAK,kBAAkB,GACxB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,KAAK,eAAe,GACrB,MAAM,eAAe,CAAC;AACvB,YAAY,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EACtB,sBAAsB,EACtB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,GACtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,gBAAgB,EAChB,yBAAyB,EACzB,cAAc,EACd,KAAK,qBAAqB,EAC1B,KAAK,wBAAwB,EAC7B,KAAK,qBAAqB,EAC1B,KAAK,uBAAuB,EAC5B,KAAK,aAAa,GACnB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,iCAAiC,EACjC,kBAAkB,EAClB,kBAAkB,EAClB,iCAAiC,EACjC,gBAAgB,EAChB,gBAAgB,EAChB,KAAK,yBAAyB,EAC9B,KAAK,uBAAuB,EAC5B,KAAK,sBAAsB,EAC3B,KAAK,oBAAoB,EACzB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC1B,KAAK,uBAAuB,EAC5B,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,EAC1B,KAAK,eAAe,EACpB,KAAK,kBAAkB,GACxB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,mBAAmB,EACnB,yBAAyB,EACzB,0BAA0B,EAC1B,4BAA4B,EAC5B,0BAA0B,EAC1B,uBAAuB,EACvB,qCAAqC,EACrC,+BAA+B,EAC/B,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,EAC1B,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,GACxB,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { defineConfig, getSessionCookieName, parseHostname, } from "./config.js";
|
|
2
|
+
export { parseBonfireIdentity, BonfireIdentityError, } from "./identity.js";
|
|
3
|
+
export { definePrototypeRef, getPrototypeUrl, parsePrototypePath, PrototypeRefError, slugifyPrototypeTitle, } from "./prototype-ref.js";
|
|
4
|
+
export { definePrototypeSummary, parsePrototypeMetadata, PrototypeMetadataError, } from "./prototype-metadata.js";
|
|
5
|
+
export { filterPrototypes, getPrototypeAuthorOptions, sortPrototypes, } from "./prototype-catalog.js";
|
|
6
|
+
export { AutomaticBranchSwitchSettingError, isLifecycleFailure, isLifecycleSuccess, parseAutomaticBranchSwitchSetting, lifecycleFailure, lifecycleSuccess, } from "./lifecycle.js";
|
|
7
|
+
export { LifecycleInputError, parseCreatePrototypeInput, parseDiscardPrototypeInput, parseDuplicatePrototypeInput, parsePrototypeCommandInput, parseSavePrototypeInput, PROTOTYPE_DESCRIPTION_MAX_CODE_POINTS, PROTOTYPE_TITLE_MAX_CODE_POINTS, } from "./lifecycle-input.js";
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,oBAAoB,EACpB,aAAa,GAGd,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,oBAAoB,EACpB,oBAAoB,GAErB,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EACtB,sBAAsB,GAGvB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,gBAAgB,EAChB,yBAAyB,EACzB,cAAc,GAMf,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,iCAAiC,EACjC,kBAAkB,EAClB,kBAAkB,EAClB,iCAAiC,EACjC,gBAAgB,EAChB,gBAAgB,GAejB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,mBAAmB,EACnB,yBAAyB,EACzB,0BAA0B,EAC1B,4BAA4B,EAC5B,0BAA0B,EAC1B,uBAAuB,EACvB,qCAAqC,EACrC,+BAA+B,GAMhC,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/internal/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,GACjE,CAAC,GACD,CAAC,SAAS,SAAS,OAAO,EAAE,GAC1B,aAAa,CAAC,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GACtC,CAAC,SAAS,MAAM,GACd;IAAE,QAAQ,EAAE,CAAC,IAAI,MAAM,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,GAC/C,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/internal/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type UnknownRecord = Record<string, unknown>;
|
|
2
|
+
export declare function isRecord(value: unknown): value is UnknownRecord;
|
|
3
|
+
export declare function asRecord(value: unknown): UnknownRecord | null;
|
|
4
|
+
export declare function findUnknownKey(record: UnknownRecord, allowedKeys: readonly string[]): string | undefined;
|
|
5
|
+
export type RequiredStringResult = {
|
|
6
|
+
status: "missing";
|
|
7
|
+
} | {
|
|
8
|
+
status: "invalid";
|
|
9
|
+
value: unknown;
|
|
10
|
+
} | {
|
|
11
|
+
status: "valid";
|
|
12
|
+
value: string;
|
|
13
|
+
};
|
|
14
|
+
export declare function readRequiredString(record: UnknownRecord, key: string): RequiredStringResult;
|
|
15
|
+
export declare function deepFreeze<T>(value: T): T;
|
|
16
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/internal/utils.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEpD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAE/D;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,aAAa,GAAG,IAAI,CAE7D;AAED,wBAAgB,cAAc,CAC5B,MAAM,EAAE,aAAa,EACrB,WAAW,EAAE,SAAS,MAAM,EAAE,GAC7B,MAAM,GAAG,SAAS,CAGpB;AAED,MAAM,MAAM,oBAAoB,GAC5B;IAAE,MAAM,EAAE,SAAS,CAAA;CAAE,GACrB;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GACrC;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvC,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,aAAa,EACrB,GAAG,EAAE,MAAM,GACV,oBAAoB,CAOtB;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAOzC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export function isRecord(value) {
|
|
2
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3
|
+
}
|
|
4
|
+
export function asRecord(value) {
|
|
5
|
+
return isRecord(value) ? value : null;
|
|
6
|
+
}
|
|
7
|
+
export function findUnknownKey(record, allowedKeys) {
|
|
8
|
+
const allowed = new Set(allowedKeys);
|
|
9
|
+
return Object.keys(record).find((key) => !allowed.has(key));
|
|
10
|
+
}
|
|
11
|
+
export function readRequiredString(record, key) {
|
|
12
|
+
if (!Object.hasOwn(record, key))
|
|
13
|
+
return { status: "missing" };
|
|
14
|
+
const value = record[key];
|
|
15
|
+
return typeof value === "string"
|
|
16
|
+
? { status: "valid", value }
|
|
17
|
+
: { status: "invalid", value };
|
|
18
|
+
}
|
|
19
|
+
export function deepFreeze(value) {
|
|
20
|
+
if (typeof value !== "object" || value === null)
|
|
21
|
+
return value;
|
|
22
|
+
if (Object.isFrozen(value))
|
|
23
|
+
return value;
|
|
24
|
+
Object.freeze(value);
|
|
25
|
+
for (const child of Object.values(value))
|
|
26
|
+
deepFreeze(child);
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/internal/utils.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AACxC,CAAC;AAED,MAAM,UAA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|
4
|
+
export type CreatePrototypeInput = {
|
|
5
|
+
title: string;
|
|
6
|
+
description: string | null;
|
|
7
|
+
};
|
|
8
|
+
export type DuplicatePrototypeInput = {
|
|
9
|
+
source: PrototypeRef;
|
|
10
|
+
title: string;
|
|
11
|
+
description: string | null;
|
|
12
|
+
};
|
|
13
|
+
export type PrototypeCommandInput = {
|
|
14
|
+
ref: PrototypeRef;
|
|
15
|
+
};
|
|
16
|
+
export type SavePrototypeInput = PrototypeCommandInput;
|
|
17
|
+
export type DiscardPrototypeInput = PrototypeCommandInput;
|
|
18
|
+
export declare class LifecycleInputError extends Error {
|
|
19
|
+
readonly code: "invalid-input";
|
|
20
|
+
readonly path: string;
|
|
21
|
+
constructor(path: string);
|
|
22
|
+
}
|
|
23
|
+
export declare function parseCreatePrototypeInput(value: unknown): CreatePrototypeInput;
|
|
24
|
+
export declare function parseDuplicatePrototypeInput(value: unknown): DuplicatePrototypeInput;
|
|
25
|
+
export declare function parsePrototypeCommandInput(value: unknown): PrototypeCommandInput;
|
|
26
|
+
export declare function parseSavePrototypeInput(value: unknown): SavePrototypeInput;
|
|
27
|
+
export declare function parseDiscardPrototypeInput(value: unknown): DiscardPrototypeInput;
|
|
28
|
+
//# sourceMappingURL=lifecycle-input.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle-input.d.ts","sourceRoot":"","sources":["../src/lifecycle-input.ts"],"names":[],"mappings":"AAMA,OAAO,EAIL,KAAK,YAAY,EAClB,MAAM,oBAAoB,CAAC;AAE5B,eAAO,MAAM,+BAA+B,MAAM,CAAC;AACnD,eAAO,MAAM,qCAAqC,OAAQ,CAAC;AAE3D,MAAM,MAAM,oBAAoB,GAAG;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,MAAM,EAAE,YAAY,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,GAAG,EAAE,YAAY,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,qBAAqB,CAAC;AACvD,MAAM,MAAM,qBAAqB,GAAG,qBAAqB,CAAC;AAE1D,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,QAAQ,CAAC,IAAI,EAAG,eAAe,CAAU;IACzC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,YAAY,IAAI,EAAE,MAAM,EAIvB;CACF;AAoED,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,OAAO,GACb,oBAAoB,CAQtB;AAED,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,OAAO,GACb,uBAAuB,CAazB;AAED,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,OAAO,GACb,qBAAqB,CAgBvB;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,kBAAkB,CAE1E;AAED,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,OAAO,GACb,qBAAqB,CAEvB"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { asRecord, deepFreeze, findUnknownKey, readRequiredString, } from "./internal/utils.js";
|
|
2
|
+
import { definePrototypeRef, PrototypeRefError, slugifyPrototypeTitle, } from "./prototype-ref.js";
|
|
3
|
+
export const PROTOTYPE_TITLE_MAX_CODE_POINTS = 200;
|
|
4
|
+
export const PROTOTYPE_DESCRIPTION_MAX_CODE_POINTS = 2_000;
|
|
5
|
+
export class LifecycleInputError extends Error {
|
|
6
|
+
code = "invalid-input";
|
|
7
|
+
path;
|
|
8
|
+
constructor(path) {
|
|
9
|
+
super("Invalid lifecycle input");
|
|
10
|
+
this.name = "LifecycleInputError";
|
|
11
|
+
this.path = path;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function requireRecord(value, path) {
|
|
15
|
+
const record = asRecord(value);
|
|
16
|
+
if (record === null)
|
|
17
|
+
throw new LifecycleInputError(path);
|
|
18
|
+
return record;
|
|
19
|
+
}
|
|
20
|
+
function rejectUnknownKey(record, allowedKeys, path) {
|
|
21
|
+
if (findUnknownKey(record, allowedKeys)) {
|
|
22
|
+
throw new LifecycleInputError(path);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function parseTitle(record) {
|
|
26
|
+
const result = readRequiredString(record, "title");
|
|
27
|
+
if (result.status !== "valid") {
|
|
28
|
+
throw new LifecycleInputError("title");
|
|
29
|
+
}
|
|
30
|
+
const title = result.value.trim();
|
|
31
|
+
if (title.length === 0 ||
|
|
32
|
+
Array.from(title).length > PROTOTYPE_TITLE_MAX_CODE_POINTS ||
|
|
33
|
+
slugifyPrototypeTitle(title) === null) {
|
|
34
|
+
throw new LifecycleInputError("title");
|
|
35
|
+
}
|
|
36
|
+
return title;
|
|
37
|
+
}
|
|
38
|
+
function parseDescription(record) {
|
|
39
|
+
if (!Object.hasOwn(record, "description") || record.description === null) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
if (typeof record.description !== "string") {
|
|
43
|
+
throw new LifecycleInputError("description");
|
|
44
|
+
}
|
|
45
|
+
const description = record.description.trim();
|
|
46
|
+
if (Array.from(description).length > PROTOTYPE_DESCRIPTION_MAX_CODE_POINTS) {
|
|
47
|
+
throw new LifecycleInputError("description");
|
|
48
|
+
}
|
|
49
|
+
return description.length === 0 ? null : description;
|
|
50
|
+
}
|
|
51
|
+
function parseSource(record) {
|
|
52
|
+
if (!Object.hasOwn(record, "source")) {
|
|
53
|
+
throw new LifecycleInputError("source");
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
return definePrototypeRef(record.source);
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
if (error instanceof PrototypeRefError) {
|
|
60
|
+
throw new LifecycleInputError("source");
|
|
61
|
+
}
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export function parseCreatePrototypeInput(value) {
|
|
66
|
+
const record = requireRecord(value, "createPrototypeInput");
|
|
67
|
+
rejectUnknownKey(record, ["title", "description"], "createPrototypeInput");
|
|
68
|
+
return deepFreeze({
|
|
69
|
+
title: parseTitle(record),
|
|
70
|
+
description: parseDescription(record),
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
export function parseDuplicatePrototypeInput(value) {
|
|
74
|
+
const record = requireRecord(value, "duplicatePrototypeInput");
|
|
75
|
+
rejectUnknownKey(record, ["source", "title", "description"], "duplicatePrototypeInput");
|
|
76
|
+
return deepFreeze({
|
|
77
|
+
source: parseSource(record),
|
|
78
|
+
title: parseTitle(record),
|
|
79
|
+
description: parseDescription(record),
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
export function parsePrototypeCommandInput(value) {
|
|
83
|
+
const record = requireRecord(value, "prototypeCommandInput");
|
|
84
|
+
rejectUnknownKey(record, ["ref"], "prototypeCommandInput");
|
|
85
|
+
if (!Object.hasOwn(record, "ref")) {
|
|
86
|
+
throw new LifecycleInputError("ref");
|
|
87
|
+
}
|
|
88
|
+
try {
|
|
89
|
+
return deepFreeze({ ref: definePrototypeRef(record.ref) });
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
if (error instanceof PrototypeRefError) {
|
|
93
|
+
throw new LifecycleInputError("ref");
|
|
94
|
+
}
|
|
95
|
+
throw error;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
export function parseSavePrototypeInput(value) {
|
|
99
|
+
return parsePrototypeCommandInput(value);
|
|
100
|
+
}
|
|
101
|
+
export function parseDiscardPrototypeInput(value) {
|
|
102
|
+
return parsePrototypeCommandInput(value);
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=lifecycle-input.js.map
|