@pithy-sh/core 0.6.0 → 0.6.2
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/capability/manifest.d.ts +13 -2
- package/dist/capability/manifest.d.ts.map +1 -1
- package/dist/capability/manifest.js +15 -6
- package/dist/error/http.d.ts +84 -0
- package/dist/error/http.d.ts.map +1 -1
- package/dist/error/payload.d.ts +168 -0
- package/dist/error/payload.d.ts.map +1 -1
- package/dist/error/payload.js +56 -0
- package/dist/image/storedImage.d.ts +150 -0
- package/dist/image/storedImage.d.ts.map +1 -0
- package/dist/image/storedImage.js +181 -0
- package/dist/logger/record.d.ts +49 -0
- package/dist/logger/record.d.ts.map +1 -1
- package/dist/naming/provisionScope.d.ts +33 -9
- package/dist/naming/provisionScope.d.ts.map +1 -1
- package/dist/naming/provisionScope.js +26 -8
- package/dist/seed/devLogin.d.ts +16 -9
- package/dist/seed/devLogin.d.ts.map +1 -1
- package/dist/seed/devLogin.js +21 -14
- package/dist/version.generated.d.ts +1 -1
- package/dist/version.generated.js +1 -1
- package/package.json +1 -1
- package/src/naming/provisionScope.ts +34 -10
- package/src/version.generated.ts +1 -1
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
/**
|
|
5
|
+
* What may be stored as an image, and how it is served — stated once, for every capability that holds
|
|
6
|
+
* a small picture in a column.
|
|
7
|
+
*
|
|
8
|
+
* Two capabilities hold one: `@pithy-sh/auth` keeps a person's face, `@pithy-sh/organization` keeps an
|
|
9
|
+
* account's mark. They are the same object at different scales, and **two answers to *what may be
|
|
10
|
+
* stored as an image* is one of them being wrong.** So the allowlist, the ceiling, the derived byte
|
|
11
|
+
* figure and the serving split live here and are imported, exactly as `normalizeAddress` moved here in
|
|
12
|
+
* `#280`.
|
|
13
|
+
*
|
|
14
|
+
* ## Stored, not linked
|
|
15
|
+
*
|
|
16
|
+
* A remote URL means the page fetching an attacker-chosen host from a screen listing people, leaking
|
|
17
|
+
* the viewer's IP and referrer before they had done anything, and it needs a CSP hole to render at all.
|
|
18
|
+
* A bounded `data:` URL in a column has no third party in it.
|
|
19
|
+
*
|
|
20
|
+
* ## Rendered through `<img>`, never inlined
|
|
21
|
+
*
|
|
22
|
+
* A browser disables scripting inside an `<img>` by specification, and that is the entire basis for
|
|
23
|
+
* accepting SVG here at all. Nothing in the kit writes one of these values into a document.
|
|
24
|
+
*
|
|
25
|
+
* ## Rasters get a URL, vectors never do — and that is the security answer, not a mitigation
|
|
26
|
+
*
|
|
27
|
+
* A `data:` URL has one property it cannot have: **it cannot be cached.** It is inline in the response
|
|
28
|
+
* body, so a roster of twenty faces re-sends twenty images on every read, forever. Serving from the
|
|
29
|
+
* app's own origin fixes that and costs one real hazard — **an SVG fetched by *navigation* runs script
|
|
30
|
+
* in the origin that served it.** An `<img src>` is inert; a URL is navigable.
|
|
31
|
+
*
|
|
32
|
+
* So a vector never gets a URL. {@link storedImageBytes} answers null for one, the serving route 404s
|
|
33
|
+
* on null, and there is no arrangement of ids and versions that makes the origin return an SVG. The
|
|
34
|
+
* class of attack is removed rather than managed with headers, and there is no header anybody has to
|
|
35
|
+
* keep right.
|
|
36
|
+
*/
|
|
37
|
+
/**
|
|
38
|
+
* The image types a stored picture may be.
|
|
39
|
+
*
|
|
40
|
+
* Three rasters and one vector. The vector is here because `<img>` renders it inertly and a mark drawn
|
|
41
|
+
* as one is a few hundred bytes; every rule below that treats it differently is treating *navigability*
|
|
42
|
+
* differently, not the format.
|
|
43
|
+
*/
|
|
44
|
+
export declare const STORED_IMAGE_TYPES: readonly ["image/png", "image/jpeg", "image/webp", "image/svg+xml"];
|
|
45
|
+
/** One of {@link STORED_IMAGE_TYPES}. */
|
|
46
|
+
export type StoredImageType = (typeof STORED_IMAGE_TYPES)[number];
|
|
47
|
+
/**
|
|
48
|
+
* The types that stay inline whatever else happens.
|
|
49
|
+
*
|
|
50
|
+
* One entry, and the module note argues it at length. Written as a list rather than as a comparison so
|
|
51
|
+
* that a second scriptable format added to {@link STORED_IMAGE_TYPES} one day is added here too, next
|
|
52
|
+
* to the reason.
|
|
53
|
+
*/
|
|
54
|
+
export declare const INLINE_IMAGE_TYPES: readonly string[];
|
|
55
|
+
/**
|
|
56
|
+
* The ceiling on a stored image, in characters of `data:` URL.
|
|
57
|
+
*
|
|
58
|
+
* 32KB of base64, which is about 24KB of image. A face drawn at 34px does not need more, and the
|
|
59
|
+
* ceiling is what stops one row making every read expensive: the record, the account menu and the
|
|
60
|
+
* chooser all carry it.
|
|
61
|
+
*/
|
|
62
|
+
export declare const MAX_STORED_IMAGE_CHARS: number;
|
|
63
|
+
/**
|
|
64
|
+
* The longest `data:<type>;base64,` a stored image can begin with, in characters.
|
|
65
|
+
*
|
|
66
|
+
* Derived from the allowlist rather than written down, so a longer type name added above cannot leave a
|
|
67
|
+
* ceiling below it stale. `image/svg+xml` is the long one today, at 26 characters.
|
|
68
|
+
*/
|
|
69
|
+
export declare const LONGEST_STORED_IMAGE_PREFIX: number;
|
|
70
|
+
/**
|
|
71
|
+
* The largest file a browser may encode into that ceiling, in bytes of image.
|
|
72
|
+
*
|
|
73
|
+
* **Not `MAX_STORED_IMAGE_CHARS * 3 / 4`, and the difference is a bug that shipped once.** That is the
|
|
74
|
+
* base64 inverse, and it silently assumes the stored string is base64 and nothing else. It is not: it
|
|
75
|
+
* is `data:<type>;base64,` and *then* the base64. A file at the plain inverse encodes to 22–26
|
|
76
|
+
* characters more than the column will take, so it passes a picker's own check and is refused by Zod —
|
|
77
|
+
* the person gets a validator's sentence where the product had written them one of its own.
|
|
78
|
+
*
|
|
79
|
+
* Base64 is four characters per three bytes and rounds up to a whole group, so the arithmetic runs
|
|
80
|
+
* backwards from the characters left after the prefix: `floor((chars - prefix) / 4)` groups, three
|
|
81
|
+
* bytes each. Derived from the *longest* prefix, because one ceiling has to hold for every type a
|
|
82
|
+
* picker offers and the tightest constraint is the one that binds.
|
|
83
|
+
*
|
|
84
|
+
* **This is the figure a client-side picker checks a file against before encoding it.** The column
|
|
85
|
+
* enforces {@link MAX_STORED_IMAGE_CHARS} on the whole string, which is the bound that matters; this is
|
|
86
|
+
* the same fact stated as bytes of image, so a picker and a column cannot disagree.
|
|
87
|
+
*/
|
|
88
|
+
export declare const MAX_STORED_IMAGE_BYTES: number;
|
|
89
|
+
/**
|
|
90
|
+
* A stored image, validated at the column and therefore at every boundary that decodes a row.
|
|
91
|
+
*
|
|
92
|
+
* **The pattern is an allowlist of types, not a check that the string starts with `data:`.**
|
|
93
|
+
* `data:text/html` is a `data:` URL too, and the difference between the two is the whole of what makes
|
|
94
|
+
* this column safe to render. Anchored at both ends, so nothing follows the payload.
|
|
95
|
+
*/
|
|
96
|
+
export declare const StoredImage: z.ZodString;
|
|
97
|
+
export type StoredImage = z.output<typeof StoredImage>;
|
|
98
|
+
/** The type a stored image declares, or null when it is not a value this rule accepts. */
|
|
99
|
+
export declare function typeOfStoredImage(stored: string): StoredImageType | null;
|
|
100
|
+
/**
|
|
101
|
+
* What a screen should draw this image from.
|
|
102
|
+
*
|
|
103
|
+
* A URL for a raster, the stored value itself for a vector, and null for nothing. The caller renders
|
|
104
|
+
* whichever it gets through the same `<img src>`, so no screen has to know which it was handed.
|
|
105
|
+
*
|
|
106
|
+
* `path` is the route the owning capability serves bytes from, already carrying whatever identifies the
|
|
107
|
+
* subject — this function appends only the version, because the version is the half that has to be
|
|
108
|
+
* right for `immutable` to be honest.
|
|
109
|
+
*
|
|
110
|
+
* The version is the owning row's `updatedAt`: the URL changes whenever the image can have changed, so
|
|
111
|
+
* the response may be `immutable` and a browser never revalidates. It over-invalidates slightly — a
|
|
112
|
+
* rename busts a picture that did not change — which is one wasted fetch on a rare action, against a
|
|
113
|
+
* hash column and a migration to carry it.
|
|
114
|
+
*/
|
|
115
|
+
export declare function storedImageSource(stored: string | null, path: string, version: Date | number): string | null;
|
|
116
|
+
/** A stored image decoded into what a response body needs. */
|
|
117
|
+
export interface StoredImageBytes {
|
|
118
|
+
/** The `Content-Type` to serve it as. Always one of {@link STORED_IMAGE_TYPES}, never sniffed. */
|
|
119
|
+
readonly type: StoredImageType;
|
|
120
|
+
/** The image itself. */
|
|
121
|
+
readonly body: Uint8Array;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Decode a stored image for serving, or null when it must not be served.
|
|
125
|
+
*
|
|
126
|
+
* **Null for a vector, and that is the gate rather than a caution.** The route asks this and answers
|
|
127
|
+
* 404 when it gets null, so there is no arrangement of ids and versions that makes the origin return an
|
|
128
|
+
* SVG. The module note gives the reason.
|
|
129
|
+
*
|
|
130
|
+
* Null too for anything the allowlist does not match, which the column should have refused on the way
|
|
131
|
+
* in — this is the second place that is true, and a value that reached the column past a bug does not
|
|
132
|
+
* get served out of it.
|
|
133
|
+
*/
|
|
134
|
+
export declare function storedImageBytes(stored: string | null): StoredImageBytes | null;
|
|
135
|
+
/**
|
|
136
|
+
* The headers a served image carries.
|
|
137
|
+
*
|
|
138
|
+
* **`immutable`, which is only honest because the URL carries a version.** {@link storedImageSource}
|
|
139
|
+
* puts the owning row's `updatedAt` in the query, so a changed image is a different URL and a browser
|
|
140
|
+
* that never revalidates can never show a stale one.
|
|
141
|
+
*
|
|
142
|
+
* **`private`, because the fetch is authorized against a session.** A shared cache holding this would
|
|
143
|
+
* be one person's face served to whoever asked next.
|
|
144
|
+
*
|
|
145
|
+
* **`nosniff`, because the type is the allowlist's and must not be re-guessed.** Content sniffing is
|
|
146
|
+
* how a file served as an image gets treated as something else, and the whole safety of this route is
|
|
147
|
+
* that the type is one of three rasters.
|
|
148
|
+
*/
|
|
149
|
+
export declare const STORED_IMAGE_HEADERS: Readonly<Record<string, string>>;
|
|
150
|
+
//# sourceMappingURL=storedImage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storedImage.d.ts","sourceRoot":"","sources":["../../src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,GAAG,gBAAgB,GAAG,IAAI,CAe/E;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAGjE,CAAC"}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
//#region src/image/storedImage.ts
|
|
5
|
+
/**
|
|
6
|
+
* What may be stored as an image, and how it is served — stated once, for every capability that holds
|
|
7
|
+
* a small picture in a column.
|
|
8
|
+
*
|
|
9
|
+
* Two capabilities hold one: `@pithy-sh/auth` keeps a person's face, `@pithy-sh/organization` keeps an
|
|
10
|
+
* account's mark. They are the same object at different scales, and **two answers to *what may be
|
|
11
|
+
* stored as an image* is one of them being wrong.** So the allowlist, the ceiling, the derived byte
|
|
12
|
+
* figure and the serving split live here and are imported, exactly as `normalizeAddress` moved here in
|
|
13
|
+
* `#280`.
|
|
14
|
+
*
|
|
15
|
+
* ## Stored, not linked
|
|
16
|
+
*
|
|
17
|
+
* A remote URL means the page fetching an attacker-chosen host from a screen listing people, leaking
|
|
18
|
+
* the viewer's IP and referrer before they had done anything, and it needs a CSP hole to render at all.
|
|
19
|
+
* A bounded `data:` URL in a column has no third party in it.
|
|
20
|
+
*
|
|
21
|
+
* ## Rendered through `<img>`, never inlined
|
|
22
|
+
*
|
|
23
|
+
* A browser disables scripting inside an `<img>` by specification, and that is the entire basis for
|
|
24
|
+
* accepting SVG here at all. Nothing in the kit writes one of these values into a document.
|
|
25
|
+
*
|
|
26
|
+
* ## Rasters get a URL, vectors never do — and that is the security answer, not a mitigation
|
|
27
|
+
*
|
|
28
|
+
* A `data:` URL has one property it cannot have: **it cannot be cached.** It is inline in the response
|
|
29
|
+
* body, so a roster of twenty faces re-sends twenty images on every read, forever. Serving from the
|
|
30
|
+
* app's own origin fixes that and costs one real hazard — **an SVG fetched by *navigation* runs script
|
|
31
|
+
* in the origin that served it.** An `<img src>` is inert; a URL is navigable.
|
|
32
|
+
*
|
|
33
|
+
* So a vector never gets a URL. {@link storedImageBytes} answers null for one, the serving route 404s
|
|
34
|
+
* on null, and there is no arrangement of ids and versions that makes the origin return an SVG. The
|
|
35
|
+
* class of attack is removed rather than managed with headers, and there is no header anybody has to
|
|
36
|
+
* keep right.
|
|
37
|
+
*/
|
|
38
|
+
/**
|
|
39
|
+
* The image types a stored picture may be.
|
|
40
|
+
*
|
|
41
|
+
* Three rasters and one vector. The vector is here because `<img>` renders it inertly and a mark drawn
|
|
42
|
+
* as one is a few hundred bytes; every rule below that treats it differently is treating *navigability*
|
|
43
|
+
* differently, not the format.
|
|
44
|
+
*/
|
|
45
|
+
const STORED_IMAGE_TYPES = [
|
|
46
|
+
"image/png",
|
|
47
|
+
"image/jpeg",
|
|
48
|
+
"image/webp",
|
|
49
|
+
"image/svg+xml"
|
|
50
|
+
];
|
|
51
|
+
/**
|
|
52
|
+
* The types that stay inline whatever else happens.
|
|
53
|
+
*
|
|
54
|
+
* One entry, and the module note argues it at length. Written as a list rather than as a comparison so
|
|
55
|
+
* that a second scriptable format added to {@link STORED_IMAGE_TYPES} one day is added here too, next
|
|
56
|
+
* to the reason.
|
|
57
|
+
*/
|
|
58
|
+
const INLINE_IMAGE_TYPES = ["image/svg+xml"];
|
|
59
|
+
/**
|
|
60
|
+
* The ceiling on a stored image, in characters of `data:` URL.
|
|
61
|
+
*
|
|
62
|
+
* 32KB of base64, which is about 24KB of image. A face drawn at 34px does not need more, and the
|
|
63
|
+
* ceiling is what stops one row making every read expensive: the record, the account menu and the
|
|
64
|
+
* chooser all carry it.
|
|
65
|
+
*/
|
|
66
|
+
const MAX_STORED_IMAGE_CHARS = 32768;
|
|
67
|
+
/**
|
|
68
|
+
* The longest `data:<type>;base64,` a stored image can begin with, in characters.
|
|
69
|
+
*
|
|
70
|
+
* Derived from the allowlist rather than written down, so a longer type name added above cannot leave a
|
|
71
|
+
* ceiling below it stale. `image/svg+xml` is the long one today, at 26 characters.
|
|
72
|
+
*/
|
|
73
|
+
const LONGEST_STORED_IMAGE_PREFIX = Math.max(...STORED_IMAGE_TYPES.map((type) => `data:${type};base64,`.length));
|
|
74
|
+
/**
|
|
75
|
+
* The largest file a browser may encode into that ceiling, in bytes of image.
|
|
76
|
+
*
|
|
77
|
+
* **Not `MAX_STORED_IMAGE_CHARS * 3 / 4`, and the difference is a bug that shipped once.** That is the
|
|
78
|
+
* base64 inverse, and it silently assumes the stored string is base64 and nothing else. It is not: it
|
|
79
|
+
* is `data:<type>;base64,` and *then* the base64. A file at the plain inverse encodes to 22–26
|
|
80
|
+
* characters more than the column will take, so it passes a picker's own check and is refused by Zod —
|
|
81
|
+
* the person gets a validator's sentence where the product had written them one of its own.
|
|
82
|
+
*
|
|
83
|
+
* Base64 is four characters per three bytes and rounds up to a whole group, so the arithmetic runs
|
|
84
|
+
* backwards from the characters left after the prefix: `floor((chars - prefix) / 4)` groups, three
|
|
85
|
+
* bytes each. Derived from the *longest* prefix, because one ceiling has to hold for every type a
|
|
86
|
+
* picker offers and the tightest constraint is the one that binds.
|
|
87
|
+
*
|
|
88
|
+
* **This is the figure a client-side picker checks a file against before encoding it.** The column
|
|
89
|
+
* enforces {@link MAX_STORED_IMAGE_CHARS} on the whole string, which is the bound that matters; this is
|
|
90
|
+
* the same fact stated as bytes of image, so a picker and a column cannot disagree.
|
|
91
|
+
*/
|
|
92
|
+
const MAX_STORED_IMAGE_BYTES = 3 * Math.floor((MAX_STORED_IMAGE_CHARS - LONGEST_STORED_IMAGE_PREFIX) / 4);
|
|
93
|
+
/** `data:<type>;base64,<payload>` and nothing else — no bare URL, no `data:text/html`, no charset games. */
|
|
94
|
+
const STORED_IMAGE_PATTERN = new RegExp(`^data:(?:${STORED_IMAGE_TYPES.join("|").replace(/\+/g, "\\+")});base64,[A-Za-z0-9+/]+=*$`);
|
|
95
|
+
/**
|
|
96
|
+
* A stored image, validated at the column and therefore at every boundary that decodes a row.
|
|
97
|
+
*
|
|
98
|
+
* **The pattern is an allowlist of types, not a check that the string starts with `data:`.**
|
|
99
|
+
* `data:text/html` is a `data:` URL too, and the difference between the two is the whole of what makes
|
|
100
|
+
* this column safe to render. Anchored at both ends, so nothing follows the payload.
|
|
101
|
+
*/
|
|
102
|
+
const StoredImage = z.string().max(MAX_STORED_IMAGE_CHARS).regex(STORED_IMAGE_PATTERN).describe("An image held as a base64 `data:` URL of an allowed type, bounded to 32KB. Stored rather than linked, and rendered only through `<img>` — see `@pithy-sh/core/src/image/storedImage`.");
|
|
103
|
+
/** The `data:` prefix a stored image of `type` begins with. */
|
|
104
|
+
function prefixOf(type) {
|
|
105
|
+
return `data:${type};base64,`;
|
|
106
|
+
}
|
|
107
|
+
/** The type a stored image declares, or null when it is not a value this rule accepts. */
|
|
108
|
+
function typeOfStoredImage(stored) {
|
|
109
|
+
return STORED_IMAGE_TYPES.find((type) => stored.startsWith(prefixOf(type))) ?? null;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* What a screen should draw this image from.
|
|
113
|
+
*
|
|
114
|
+
* A URL for a raster, the stored value itself for a vector, and null for nothing. The caller renders
|
|
115
|
+
* whichever it gets through the same `<img src>`, so no screen has to know which it was handed.
|
|
116
|
+
*
|
|
117
|
+
* `path` is the route the owning capability serves bytes from, already carrying whatever identifies the
|
|
118
|
+
* subject — this function appends only the version, because the version is the half that has to be
|
|
119
|
+
* right for `immutable` to be honest.
|
|
120
|
+
*
|
|
121
|
+
* The version is the owning row's `updatedAt`: the URL changes whenever the image can have changed, so
|
|
122
|
+
* the response may be `immutable` and a browser never revalidates. It over-invalidates slightly — a
|
|
123
|
+
* rename busts a picture that did not change — which is one wasted fetch on a rare action, against a
|
|
124
|
+
* hash column and a migration to carry it.
|
|
125
|
+
*/
|
|
126
|
+
function storedImageSource(stored, path, version) {
|
|
127
|
+
if (stored === null) return null;
|
|
128
|
+
const type = typeOfStoredImage(stored);
|
|
129
|
+
if (type === null) return null;
|
|
130
|
+
if (INLINE_IMAGE_TYPES.includes(type)) return stored;
|
|
131
|
+
return `${path}?v=${version instanceof Date ? version.getTime() : version}`;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Decode a stored image for serving, or null when it must not be served.
|
|
135
|
+
*
|
|
136
|
+
* **Null for a vector, and that is the gate rather than a caution.** The route asks this and answers
|
|
137
|
+
* 404 when it gets null, so there is no arrangement of ids and versions that makes the origin return an
|
|
138
|
+
* SVG. The module note gives the reason.
|
|
139
|
+
*
|
|
140
|
+
* Null too for anything the allowlist does not match, which the column should have refused on the way
|
|
141
|
+
* in — this is the second place that is true, and a value that reached the column past a bug does not
|
|
142
|
+
* get served out of it.
|
|
143
|
+
*/
|
|
144
|
+
function storedImageBytes(stored) {
|
|
145
|
+
if (stored === null) return null;
|
|
146
|
+
const type = typeOfStoredImage(stored);
|
|
147
|
+
if (type === null || INLINE_IMAGE_TYPES.includes(type)) return null;
|
|
148
|
+
const payload = stored.slice(prefixOf(type).length);
|
|
149
|
+
let binary;
|
|
150
|
+
try {
|
|
151
|
+
binary = atob(payload);
|
|
152
|
+
} catch {
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
const body = new Uint8Array(binary.length);
|
|
156
|
+
for (let at = 0; at < binary.length; at += 1) body[at] = binary.charCodeAt(at);
|
|
157
|
+
return {
|
|
158
|
+
type,
|
|
159
|
+
body
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* The headers a served image carries.
|
|
164
|
+
*
|
|
165
|
+
* **`immutable`, which is only honest because the URL carries a version.** {@link storedImageSource}
|
|
166
|
+
* puts the owning row's `updatedAt` in the query, so a changed image is a different URL and a browser
|
|
167
|
+
* that never revalidates can never show a stale one.
|
|
168
|
+
*
|
|
169
|
+
* **`private`, because the fetch is authorized against a session.** A shared cache holding this would
|
|
170
|
+
* be one person's face served to whoever asked next.
|
|
171
|
+
*
|
|
172
|
+
* **`nosniff`, because the type is the allowlist's and must not be re-guessed.** Content sniffing is
|
|
173
|
+
* how a file served as an image gets treated as something else, and the whole safety of this route is
|
|
174
|
+
* that the type is one of three rasters.
|
|
175
|
+
*/
|
|
176
|
+
const STORED_IMAGE_HEADERS = {
|
|
177
|
+
"cache-control": "private, max-age=31536000, immutable",
|
|
178
|
+
"x-content-type-options": "nosniff"
|
|
179
|
+
};
|
|
180
|
+
//#endregion
|
|
181
|
+
export { INLINE_IMAGE_TYPES, LONGEST_STORED_IMAGE_PREFIX, MAX_STORED_IMAGE_BYTES, MAX_STORED_IMAGE_CHARS, STORED_IMAGE_HEADERS, STORED_IMAGE_TYPES, StoredImage, storedImageBytes, storedImageSource, typeOfStoredImage };
|
package/dist/logger/record.d.ts
CHANGED
|
@@ -798,6 +798,55 @@ export declare const LogRecord: z.ZodObject<{
|
|
|
798
798
|
detail: z.ZodOptional<z.ZodString>;
|
|
799
799
|
code: z.ZodLiteral<"controlplane/key_conflict">;
|
|
800
800
|
status: z.ZodLiteral<409>;
|
|
801
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
802
|
+
message: z.ZodString;
|
|
803
|
+
params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
|
|
804
|
+
action: z.ZodOptional<z.ZodString>;
|
|
805
|
+
detail: z.ZodOptional<z.ZodString>;
|
|
806
|
+
code: z.ZodLiteral<"organization/not_found">;
|
|
807
|
+
status: z.ZodLiteral<404>;
|
|
808
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
809
|
+
message: z.ZodString;
|
|
810
|
+
params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
|
|
811
|
+
action: z.ZodOptional<z.ZodString>;
|
|
812
|
+
detail: z.ZodOptional<z.ZodString>;
|
|
813
|
+
code: z.ZodLiteral<"organization/forbidden">;
|
|
814
|
+
status: z.ZodLiteral<403>;
|
|
815
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
816
|
+
message: z.ZodString;
|
|
817
|
+
params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
|
|
818
|
+
action: z.ZodOptional<z.ZodString>;
|
|
819
|
+
detail: z.ZodOptional<z.ZodString>;
|
|
820
|
+
code: z.ZodLiteral<"organization/invalid_role_catalog">;
|
|
821
|
+
status: z.ZodLiteral<400>;
|
|
822
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
823
|
+
message: z.ZodString;
|
|
824
|
+
params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
|
|
825
|
+
action: z.ZodOptional<z.ZodString>;
|
|
826
|
+
detail: z.ZodOptional<z.ZodString>;
|
|
827
|
+
code: z.ZodLiteral<"organization/invitation_invalid">;
|
|
828
|
+
status: z.ZodLiteral<400>;
|
|
829
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
830
|
+
message: z.ZodString;
|
|
831
|
+
params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
|
|
832
|
+
action: z.ZodOptional<z.ZodString>;
|
|
833
|
+
detail: z.ZodOptional<z.ZodString>;
|
|
834
|
+
code: z.ZodLiteral<"organization/last_administrator">;
|
|
835
|
+
status: z.ZodLiteral<409>;
|
|
836
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
837
|
+
message: z.ZodString;
|
|
838
|
+
params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
|
|
839
|
+
action: z.ZodOptional<z.ZodString>;
|
|
840
|
+
detail: z.ZodOptional<z.ZodString>;
|
|
841
|
+
code: z.ZodLiteral<"organization/slug_taken">;
|
|
842
|
+
status: z.ZodLiteral<409>;
|
|
843
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
844
|
+
message: z.ZodString;
|
|
845
|
+
params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
|
|
846
|
+
action: z.ZodOptional<z.ZodString>;
|
|
847
|
+
detail: z.ZodOptional<z.ZodString>;
|
|
848
|
+
code: z.ZodLiteral<"organization/nomination_invalid">;
|
|
849
|
+
status: z.ZodLiteral<400>;
|
|
801
850
|
}, z.core.$strip>, z.ZodObject<{
|
|
802
851
|
message: z.ZodString;
|
|
803
852
|
params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"record.d.ts","sourceRoot":"","sources":["../../src/logger/record.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;;;;GAKG;AAEH,4GAA4G;AAC5G,eAAO,MAAM,QAAQ;;;;;EAE4F,CAAC;AAClH,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,QAAQ,CAAC,CAAC;AAEjD;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAgD,CAAC;AAEtG;;;;GAIG;AACH,eAAO,MAAM,SAAS,wCAEsF,CAAC;AAC7G,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,SAAS,CAAC,CAAC;AAEnD;;;;;GAKG;AACH,eAAO,MAAM,SAAS
|
|
1
|
+
{"version":3,"file":"record.d.ts","sourceRoot":"","sources":["../../src/logger/record.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;;;;GAKG;AAEH,4GAA4G;AAC5G,eAAO,MAAM,QAAQ;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAW+E,CAAC;AACtG,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,SAAS,CAAC,CAAC;AAmBnD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,CAMzD"}
|
|
@@ -118,8 +118,14 @@ export interface ProvisionScope {
|
|
|
118
118
|
* is created, judged to be the project's, kept out of the teardown record, and orphaned.
|
|
119
119
|
*/
|
|
120
120
|
readonly honorsGlobal: boolean;
|
|
121
|
-
/**
|
|
122
|
-
|
|
121
|
+
/**
|
|
122
|
+
* The script name a Worker deploys under in this scope.
|
|
123
|
+
*
|
|
124
|
+
* `declared` is the name that scope's stanza already carries, when it carries one. A scope may honor it
|
|
125
|
+
* or compose its own; see {@link environmentScope} and {@link featureScope}, which answer differently
|
|
126
|
+
* and say why. Passing it is how a caller asks the scope rather than deciding for itself.
|
|
127
|
+
*/
|
|
128
|
+
worker(worker: string, declared?: string): string;
|
|
123
129
|
/**
|
|
124
130
|
* This scope's CF Secrets Store entry name for a declared secret.
|
|
125
131
|
*
|
|
@@ -165,13 +171,25 @@ export declare function bindingResourceName(project: string, binding: string, ki
|
|
|
165
171
|
* every name below, so an illegal one must fail before anything is created rather than at the fourth
|
|
166
172
|
* getter that happened to use it.
|
|
167
173
|
*
|
|
168
|
-
* **A
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
*
|
|
174
|
+
* **A declared name wins; the fallback is wrangler's own, `<script>-<env>`.**
|
|
175
|
+
*
|
|
176
|
+
* This reverses the rule that stood here until #580, and the reversal is worth reading rather than
|
|
177
|
+
* assuming. The old rule *recomputed* `<script>-<env>` on every provision and wrote it over whatever the
|
|
178
|
+
* stanza said, on the argument that wrangler has always appended the environment to the top-level `name`,
|
|
179
|
+
* so every project that ever deployed is already at that address.
|
|
180
|
+
*
|
|
181
|
+
* That argument is still true about the **fallback**, and the fallback is unchanged: a stanza that names
|
|
182
|
+
* nothing gets `<script>-<env>` and every existing adopter deploys exactly where they always did. What was
|
|
183
|
+
* wrong was recomputing over a name somebody wrote down. Since #580 the starter template writes one —
|
|
184
|
+
* `<project>-<env>-<worker>`, the shape every other resource here takes — so recompute would have made the
|
|
185
|
+
* template's stamp pointless, and worse: it would have silently renamed the Worker of every project that
|
|
186
|
+
* had taken the new shape, on their next `pithy provision`. A Worker script is a `refuse`-policy namespace
|
|
187
|
+
* precisely because renaming one orphans the deployment, its routes, and every `service` binding pointing
|
|
188
|
+
* at it. Doing that as a side effect of provisioning is the failure the old rule was written to prevent,
|
|
189
|
+
* arriving from the other direction.
|
|
190
|
+
*
|
|
191
|
+
* So the name is read, not composed, when the file already holds one — and written out when it does not,
|
|
192
|
+
* so a service binding and a deploy still agree on one string that is in the file.
|
|
175
193
|
*/
|
|
176
194
|
export declare function environmentScope(project: string, environment: string): ProvisionScope;
|
|
177
195
|
/**
|
|
@@ -193,6 +211,12 @@ export declare function environmentScope(project: string, environment: string):
|
|
|
193
211
|
* `resource` is ignored for the same reason it is moot: a feature's `<thing>` segment is the binding plus
|
|
194
212
|
* the kind, and the whole name is recomputed on teardown rather than looked up, so nothing outside the
|
|
195
213
|
* feature reads the string.
|
|
214
|
+
*
|
|
215
|
+
* **And a declared Worker name is ignored here too — the other half of the #580 asymmetry.** A declared
|
|
216
|
+
* environment's script name is the adopter's, written in a tracked file, and provisioning reads it. A
|
|
217
|
+
* feature's is the kit's: it is composed from the branch, written into a generated config nobody commits,
|
|
218
|
+
* and **recomputed on teardown**. Honoring a declared one would leave `pithy feature destroy` computing a
|
|
219
|
+
* name the deployment does not answer to, which is a Worker nothing deletes.
|
|
196
220
|
*/
|
|
197
221
|
export declare function featureScope(identity: FeatureIdentity): ProvisionScope;
|
|
198
222
|
//# sourceMappingURL=provisionScope.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provisionScope.d.ts","sourceRoot":"","sources":["../../src/naming/provisionScope.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,mBAAmB,EAIzB,MAAM,WAAW,CAAC;AAGnB;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH;;;;;;GAMG;AACH,MAAM,MAAM,eAAe,GAAG,aAAa,GAAG,QAAQ,CAAC;AAEvD;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,aAAa;IAC5B;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,eAAe,CAAC;IACjC;;;OAGG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,mBAAoB,SAAQ,aAAa;IACxD,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;CAC1B;AAED,uFAAuF;AACvF,MAAM,WAAW,cAAc;IAC7B,6FAA6F;IAC7F,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB;;;;;;;;;;;;;;OAcG;IACH,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,mBAAmB,EAAE,MAAM,EAAE,aAAa,GAAG,MAAM,CAAC;IACpF;;;;;;;;;OASG;IACH,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;IAC/B
|
|
1
|
+
{"version":3,"file":"provisionScope.d.ts","sourceRoot":"","sources":["../../src/naming/provisionScope.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KA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mB,CACjC,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,mBAAmB,EACzB,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,GAChC,MAAM,CAAC;AAsBV;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,cAAc,CAerF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,eAAe,GAAG,cAAc,CAatE"}
|
|
@@ -38,13 +38,25 @@ function bindingResourceName(project, binding, kind, naming, scoped) {
|
|
|
38
38
|
* every name below, so an illegal one must fail before anything is created rather than at the fourth
|
|
39
39
|
* getter that happened to use it.
|
|
40
40
|
*
|
|
41
|
-
* **A
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
41
|
+
* **A declared name wins; the fallback is wrangler's own, `<script>-<env>`.**
|
|
42
|
+
*
|
|
43
|
+
* This reverses the rule that stood here until #580, and the reversal is worth reading rather than
|
|
44
|
+
* assuming. The old rule *recomputed* `<script>-<env>` on every provision and wrote it over whatever the
|
|
45
|
+
* stanza said, on the argument that wrangler has always appended the environment to the top-level `name`,
|
|
46
|
+
* so every project that ever deployed is already at that address.
|
|
47
|
+
*
|
|
48
|
+
* That argument is still true about the **fallback**, and the fallback is unchanged: a stanza that names
|
|
49
|
+
* nothing gets `<script>-<env>` and every existing adopter deploys exactly where they always did. What was
|
|
50
|
+
* wrong was recomputing over a name somebody wrote down. Since #580 the starter template writes one —
|
|
51
|
+
* `<project>-<env>-<worker>`, the shape every other resource here takes — so recompute would have made the
|
|
52
|
+
* template's stamp pointless, and worse: it would have silently renamed the Worker of every project that
|
|
53
|
+
* had taken the new shape, on their next `pithy provision`. A Worker script is a `refuse`-policy namespace
|
|
54
|
+
* precisely because renaming one orphans the deployment, its routes, and every `service` binding pointing
|
|
55
|
+
* at it. Doing that as a side effect of provisioning is the failure the old rule was written to prevent,
|
|
56
|
+
* arriving from the other direction.
|
|
57
|
+
*
|
|
58
|
+
* So the name is read, not composed, when the file already holds one — and written out when it does not,
|
|
59
|
+
* so a service binding and a deploy still agree on one string that is in the file.
|
|
48
60
|
*/
|
|
49
61
|
function environmentScope(project, environment) {
|
|
50
62
|
assertValidEnvironment(environment);
|
|
@@ -54,7 +66,7 @@ function environmentScope(project, environment) {
|
|
|
54
66
|
source: true,
|
|
55
67
|
honorsGlobal: true,
|
|
56
68
|
resource: (binding, kind, naming) => bindingResourceName(project, binding, kind, naming, (thing) => names[KIND_NAMER[kind]](thing)),
|
|
57
|
-
worker: (worker) => `${worker}-${environment}`,
|
|
69
|
+
worker: (worker, declared) => declared ?? `${worker}-${environment}`,
|
|
58
70
|
secretEntry: (secret, secretScope) => secretEntryName(project, secret, secretScope, () => names.secretEntry(secret))
|
|
59
71
|
};
|
|
60
72
|
}
|
|
@@ -77,6 +89,12 @@ function environmentScope(project, environment) {
|
|
|
77
89
|
* `resource` is ignored for the same reason it is moot: a feature's `<thing>` segment is the binding plus
|
|
78
90
|
* the kind, and the whole name is recomputed on teardown rather than looked up, so nothing outside the
|
|
79
91
|
* feature reads the string.
|
|
92
|
+
*
|
|
93
|
+
* **And a declared Worker name is ignored here too — the other half of the #580 asymmetry.** A declared
|
|
94
|
+
* environment's script name is the adopter's, written in a tracked file, and provisioning reads it. A
|
|
95
|
+
* feature's is the kit's: it is composed from the branch, written into a generated config nobody commits,
|
|
96
|
+
* and **recomputed on teardown**. Honoring a declared one would leave `pithy feature destroy` computing a
|
|
97
|
+
* name the deployment does not answer to, which is a Worker nothing deletes.
|
|
80
98
|
*/
|
|
81
99
|
function featureScope(identity) {
|
|
82
100
|
return {
|
package/dist/seed/devLogin.d.ts
CHANGED
|
@@ -9,10 +9,16 @@ import { z } from "zod";
|
|
|
9
9
|
* the seam they already share, so the shape is stated once instead of being duplicated (and drifting) at
|
|
10
10
|
* both ends.
|
|
11
11
|
*
|
|
12
|
-
* **The file holds a live credential.** A signed
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
12
|
+
* **The file holds a live credential.** A signed claim for a local database is a way in for anyone who
|
|
13
|
+
* can read it, which is why it is written under `logs/` — gitignored by the starter template, so it can
|
|
14
|
+
* never be committed — and why nothing here is ever put in a `PithyError` (the payload reaches logs
|
|
15
|
+
* verbatim).
|
|
16
|
+
*
|
|
17
|
+
* **It used to hold a session cookie, and now it holds a claim — `#572`.** The difference is what
|
|
18
|
+
* survives: a cookie names a row in `pithy_auth_sessions`, so signing out of the app revoked it and the
|
|
19
|
+
* dev login 404'd until somebody reseeded. A claim names a *user*, signed with the session secret, and
|
|
20
|
+
* the route exchanges it for a fresh session on every open. Sign-out then revokes the session it should
|
|
21
|
+
* revoke and leaves the way back in alone.
|
|
16
22
|
*/
|
|
17
23
|
/** The directory seed artifacts are written to, relative to the project root. Gitignored, so transient. */
|
|
18
24
|
export declare const SEED_ARTIFACT_DIR = "logs";
|
|
@@ -32,11 +38,13 @@ export declare const DEV_LOGIN_PATH = "logs/dev-login.json";
|
|
|
32
38
|
* anything the kit serves that is not part of a capability's public surface lives under this prefix, so
|
|
33
39
|
* a route added here can never collide with an application path someone already shipped.
|
|
34
40
|
*
|
|
35
|
-
* Registered **only** in a `dev` composition, and never under CI. It mints an authenticated session
|
|
36
|
-
*
|
|
37
|
-
* registration rather than inside the handler.
|
|
41
|
+
* Registered **only** in a `dev` composition, and never under CI. It mints an authenticated session for
|
|
42
|
+
* whoever presents a claim this project's own secret signed, which is the whole risk of the feature and
|
|
43
|
+
* the reason its gates live at registration rather than inside the handler.
|
|
38
44
|
*/
|
|
39
45
|
export declare const DEV_LOGIN_ROUTE = "/__pithy/dev-login";
|
|
46
|
+
/** The query parameter {@link DEV_LOGIN_ROUTE} takes the claim in. Spelled once, read by both ends. */
|
|
47
|
+
export declare const DEV_LOGIN_CLAIM_PARAM = "t";
|
|
40
48
|
/**
|
|
41
49
|
* A seeded dev login — everything a browser needs to be signed in as a seeded user, and nothing else.
|
|
42
50
|
* `z.input` is the JSON on disk (dates as ISO-8601 strings); `z.output` is the app shape.
|
|
@@ -44,8 +52,7 @@ export declare const DEV_LOGIN_ROUTE = "/__pithy/dev-login";
|
|
|
44
52
|
export declare const DevLogin: z.ZodObject<{
|
|
45
53
|
email: z.ZodString;
|
|
46
54
|
userId: z.ZodString;
|
|
47
|
-
|
|
48
|
-
cookieValue: z.ZodString;
|
|
55
|
+
claim: z.ZodString;
|
|
49
56
|
expiresAt: z.ZodCodec<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate]>, z.ZodDate>;
|
|
50
57
|
}, z.core.$strip>;
|
|
51
58
|
export type DevLogin = z.output<typeof DevLogin>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devLogin.d.ts","sourceRoot":"","sources":["../../src/seed/devLogin.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB
|
|
1
|
+
{"version":3,"file":"devLogin.d.ts","sourceRoot":"","sources":["../../src/seed/devLogin.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;;;;;;;;;;;;;;;;;GAkBG;AAEH,2GAA2G;AAC3G,eAAO,MAAM,iBAAiB,SAAS,CAAC;AAExC,gHAAgH;AAChH,eAAO,MAAM,cAAc,mBAAmB,CAAC;AAE/C,uGAAuG;AACvG,eAAO,MAAM,cAAc,wBAA2C,CAAC;AAEvE;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,eAAe,uBAAuB,CAAC;AAEpD,uGAAuG;AACvG,eAAO,MAAM,qBAAqB,MAAM,CAAC;AAEzC;;;GAGG;AACH,eAAO,MAAM,QAAQ;;;;;iBAWqF,CAAC;AAC3G,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,QAAQ,CAAC,CAAC"}
|