@plitzi/sdk-server 0.39.4 → 0.39.6
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/CHANGELOG.md +21 -0
- package/README.md +1 -1
- package/dist/adapters/cloudAdapters.d.ts +7 -0
- package/dist/adapters/space/index.d.ts +2 -0
- package/dist/adapters/space/resolvers.d.ts +14 -3
- package/dist/adapters/space/snapshotPreview.d.ts +45 -0
- package/dist/adapters/space/types.d.ts +4 -1
- package/dist/cache.js +1 -1
- package/dist/chunks/{buildBody-BSC0UbjP.js → buildBody-Bm398uxH.js} +600 -63
- package/dist/chunks/{core-w7FIMpgv.js → core-CoKORAOg.js} +149 -23
- package/dist/chunks/{createServer-BQ0KE0Qu.js → createServer-BSmQqzwb.js} +31 -607
- package/dist/chunks/{platform-C0AVlwpB.js → platform-BTssQQXp.js} +1 -1
- package/dist/chunks/sdkAssets-CXGoc_WE.js +60 -0
- package/dist/chunks/{token-CBUubxtm.js → token-XEz1n4jp.js} +1 -1
- package/dist/chunks/views/template.ejs +5 -0
- package/dist/core/services/robotsTxt.d.ts +3 -1
- package/dist/deploy/aws/s3.d.ts +51 -0
- package/dist/deploy/aws/sigv4.d.ts +33 -0
- package/dist/deploy/contentType.d.ts +2 -0
- package/dist/deploy/fingerprint.d.ts +18 -0
- package/dist/deploy/folder.d.ts +6 -0
- package/dist/deploy/ftp.d.ts +27 -0
- package/dist/deploy/sdkFiles.d.ts +11 -0
- package/dist/deploy/spaShell.d.ts +35 -0
- package/dist/deploy/staticSite.d.ts +44 -0
- package/dist/deploy/types.d.ts +58 -0
- package/dist/deploy/zip.d.ts +8 -0
- package/dist/deploy.d.ts +24 -0
- package/dist/deploy.js +938 -0
- package/dist/handlers.js +1 -1
- package/dist/helpers/ownVersion.d.ts +1 -0
- package/dist/index.js +3 -3
- package/dist/oauth.js +1 -1
- package/dist/platform.js +1 -1
- package/dist/project.js +3 -3
- package/dist/spaces.d.ts +2 -2
- package/dist/spaces.js +1 -1
- package/dist/ssr.d.ts +1 -1
- package/dist/ssr.js +1 -1
- package/package.json +15 -13
- package/skills/plitzi-authoring/reference/authoring-errors.md +8 -4
- package/skills/plitzi-authoring/reference/efficiency.md +2 -1
- package/skills/plitzi-authoring/reference/layouts.md +2 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as createServer } from "./createServer-
|
|
1
|
+
import { t as createServer } from "./createServer-BSmQqzwb.js";
|
|
2
2
|
import { dataDirLookup } from "@plitzi/sdk-kernel/data";
|
|
3
3
|
import { createPageEngine } from "@plitzi/sdk-actions/worker";
|
|
4
4
|
// src/core/platform.ts
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { statSync } from "node:fs";
|
|
4
|
+
// src/core/sdkAssets.ts
|
|
5
|
+
/** Where the rendered page is told to fetch the SDK bundle from. Emitted by the render, so it is also served. */
|
|
6
|
+
var SDK_ASSETS_PREFIX = "/sdk-assets";
|
|
7
|
+
var resolvedSdkDir;
|
|
8
|
+
/**
|
|
9
|
+
* The SDK's built output, resolved through the module system rather than guessed from `process.cwd()`.
|
|
10
|
+
*
|
|
11
|
+
* The rendered page asks for `/sdk-assets/plitzi-sdk.js` — the server puts that URL there itself — so the server is
|
|
12
|
+
* also what should answer it. It used to be a mount every deployment had to declare, and forgetting it produced no
|
|
13
|
+
* error at all: the asset requests fell through to the page renderer, which answered each one with a 200 and an HTML
|
|
14
|
+
* document. The browser then refused them for their MIME type and the page stayed blank. A missing line of config
|
|
15
|
+
* that looks like a broken SDK is not a choice worth offering.
|
|
16
|
+
*
|
|
17
|
+
* Returns undefined if the SDK is not installed, which is legitimate: a server rendering `ssrOnly` pages, or one
|
|
18
|
+
* whose deployment serves the bundle from a CDN, needs none of this.
|
|
19
|
+
*/
|
|
20
|
+
var resolveSdkAssetsDir = () => {
|
|
21
|
+
if (resolvedSdkDir) return resolvedSdkDir.dir;
|
|
22
|
+
try {
|
|
23
|
+
const require = createRequire(import.meta.url);
|
|
24
|
+
resolvedSdkDir = { dir: path.dirname(require.resolve("@plitzi/plitzi-sdk/plitzi-sdk.css")) };
|
|
25
|
+
} catch {
|
|
26
|
+
resolvedSdkDir = { dir: void 0 };
|
|
27
|
+
}
|
|
28
|
+
return resolvedSdkDir.dir;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* A cache-buster for the SDK URLs, taken from the bundle's own mtime.
|
|
32
|
+
*
|
|
33
|
+
* The assets are served with a long `Cache-Control`, so something has to change in the URL when the bundle does or
|
|
34
|
+
* browsers keep the old one. Since the version a deployment runs IS the version of this package, the server can work
|
|
35
|
+
* it out — nobody should have to compute it and pass it in, and forgetting to is a stale bundle nobody can explain.
|
|
36
|
+
*/
|
|
37
|
+
var cachedVersion;
|
|
38
|
+
var sdkAssetVersion = () => {
|
|
39
|
+
if (cachedVersion !== void 0) return cachedVersion;
|
|
40
|
+
const dir = resolveSdkAssetsDir();
|
|
41
|
+
try {
|
|
42
|
+
cachedVersion = dir ? Math.floor(statSync(path.join(dir, "plitzi-sdk.js")).mtimeMs).toString(36) : "";
|
|
43
|
+
} catch {
|
|
44
|
+
cachedVersion = "";
|
|
45
|
+
}
|
|
46
|
+
return cachedVersion;
|
|
47
|
+
};
|
|
48
|
+
var pageAssets = (assetVersion) => {
|
|
49
|
+
const version = assetVersion ?? sdkAssetVersion();
|
|
50
|
+
const v = version ? `?v=${version}` : "";
|
|
51
|
+
return {
|
|
52
|
+
jsPath: `${SDK_ASSETS_PREFIX}/plitzi-sdk.js${v}`,
|
|
53
|
+
cssPath: `${SDK_ASSETS_PREFIX}/plitzi-sdk.css${v}`,
|
|
54
|
+
iconsCssPath: `${SDK_ASSETS_PREFIX}/plitzi-sdk-icons.css${v}`,
|
|
55
|
+
devToolsCssPath: `${SDK_ASSETS_PREFIX}/plitzi-sdk-devtools.css${v}`,
|
|
56
|
+
vendorJsPath: `${SDK_ASSETS_PREFIX}/plitzi-sdk-vendor.js${v}`,
|
|
57
|
+
devVendorJsPath: `${SDK_ASSETS_PREFIX}/plitzi-sdk-dev-vendor.js${v}`
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
export { pageAssets as n, resolveSdkAssetsDir as r, SDK_ASSETS_PREFIX as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { b as escapeHtml } from "./core-CoKORAOg.js";
|
|
2
2
|
import { forwardedIp, requestAuthority, requestOrigin } from "@plitzi/sdk-kernel/http";
|
|
3
3
|
import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
|
|
4
4
|
// src/core/oauth/consentPage.ts
|
|
@@ -128,6 +128,11 @@
|
|
|
128
128
|
<script<%- locals.nonce ? ` nonce="${locals.nonce}"` : '' %>>
|
|
129
129
|
<%- inline('motionSeen.js') %>
|
|
130
130
|
</script>
|
|
131
|
+
<%# What the page's elements asked to run as it is parsed, before it paints (SSRRenderResult.prePaint): drawn by
|
|
132
|
+
what only the browser knows. Each is the element's own, closed so that no `</script` in it ends this one. %>
|
|
133
|
+
<% for (const [name, source] of Object.entries(locals.prePaint || {})) { %>
|
|
134
|
+
<script data-pre-paint="<%= name %>"<%- locals.nonce ? ` nonce="${locals.nonce}"` : '' %>><%- source.replace(/<\/(script)/gi, '<\\/$1') %></script>
|
|
135
|
+
<% } %>
|
|
131
136
|
<% if (!locals.ssrOnly) { %>
|
|
132
137
|
<%# The payload is data, so it travels as JSON: parsing it as a JavaScript literal cost the browser several times
|
|
133
138
|
what JSON.parse does, on megabytes of it. Escaped by the server — no `<` reaches this block. %>
|
|
@@ -2,10 +2,12 @@ import { SSRContext } from '../http/pageContext';
|
|
|
2
2
|
import { Stage } from '@plitzi/sdk-kernel/http';
|
|
3
3
|
/** What a space that says nothing answers: everything may be crawled. */
|
|
4
4
|
export declare const DEFAULT_ROBOTS_TXT = "User-agent: *\nAllow: /\n";
|
|
5
|
+
/** What an address made for people, never for search, answers (a snapshot's preview): nothing may be crawled. */
|
|
6
|
+
export declare const NOINDEX_ROBOTS_TXT = "User-agent: *\nDisallow: /\n";
|
|
5
7
|
/**
|
|
6
8
|
* `/robots.txt`: the space's own (`settings.robotsTxt`) or one that lets crawlers read everything, then a `Disallow: /`
|
|
7
9
|
* for each AI crawler of the kinds the space keeps out (`settings.blockAiCrawlers`), and the address of its sitemap
|
|
8
|
-
* unless its own text names one. Never the space's page for an address it has none for: a crawler reads a 404 page as
|
|
10
|
+
* unless its own text names one — and on an address that is never for search (`noindex`), nothing at all. Never the space's page for an address it has none for: a crawler reads a 404 page as
|
|
9
11
|
* "no rules", and an HTML page as rules it cannot parse.
|
|
10
12
|
*/
|
|
11
13
|
export declare const robotsTxtStage: Stage<SSRContext>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { AwsCredentials } from './sigv4';
|
|
2
|
+
import { DeployLog, SiteFile, SiteUploader } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* A site written to an S3 bucket — AWS's, or any storage that speaks its API (Cloudflare R2, MinIO, SeaweedFS) — and,
|
|
5
|
+
* when a CloudFront distribution fronts it, switched there in one step: each deploy is written under a
|
|
6
|
+
* prefix of its own, then the distribution's origin is pointed at that prefix, so a visitor sees the old site or the
|
|
7
|
+
* new one, never half of each; going back is pointing it at the previous prefix again. Without a distribution the files
|
|
8
|
+
* are replaced where they are, one by one, and the log says so before it starts.
|
|
9
|
+
*/
|
|
10
|
+
export interface S3Target {
|
|
11
|
+
bucket: string;
|
|
12
|
+
region: string;
|
|
13
|
+
credentials: AwsCredentials;
|
|
14
|
+
/** A storage other than AWS's (`https://<account>.r2.cloudflarestorage.com`): addressed path-style. */
|
|
15
|
+
endpoint?: string;
|
|
16
|
+
/** Where the site lives in the bucket, without slashes at its ends; the bucket's root when left out. */
|
|
17
|
+
prefix?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface CloudFrontTarget {
|
|
20
|
+
distributionId: string;
|
|
21
|
+
credentials: AwsCredentials;
|
|
22
|
+
/** CloudFront's API, when it is not AWS's own address (a test's). */
|
|
23
|
+
endpoint?: string;
|
|
24
|
+
}
|
|
25
|
+
/** The address of an object, virtual-hosted on AWS and path-style elsewhere. */
|
|
26
|
+
export declare const objectUrl: ({ bucket, region, endpoint }: S3Target, key: string) => URL;
|
|
27
|
+
/** Writes one object. */
|
|
28
|
+
export declare const putObject: (target: S3Target, key: string, file: Pick<SiteFile, "body" | "type" | "cache">, signal?: AbortSignal) => Promise<void>;
|
|
29
|
+
/** Every file written under `prefix`, a few at a time; the immutable ones a bucket already holds are left as they are. */
|
|
30
|
+
export declare const putFiles: (target: S3Target, prefix: string, files: SiteFile[], log: DeployLog, signal?: AbortSignal) => Promise<{
|
|
31
|
+
written: number;
|
|
32
|
+
kept: number;
|
|
33
|
+
bytes: number;
|
|
34
|
+
}>;
|
|
35
|
+
/** Asks CloudFront to forget what it keeps of `paths` (`/*`: everything), so the next visitor gets the new site. */
|
|
36
|
+
export declare const invalidateCloudFront: ({ distributionId, credentials, endpoint }: CloudFrontTarget, paths: string[], reference: string, signal?: AbortSignal) => Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Points the distribution's origin for `bucket` at `originPath`: what makes a deploy written under its own prefix the
|
|
39
|
+
* site, in one step. The rest of the distribution's configuration is sent back as CloudFront gave it.
|
|
40
|
+
*/
|
|
41
|
+
export declare const pointCloudFront: ({ distributionId, credentials, endpoint }: CloudFrontTarget, bucket: string, originPath: string, signal?: AbortSignal) => Promise<{
|
|
42
|
+
previous: string;
|
|
43
|
+
}>;
|
|
44
|
+
/**
|
|
45
|
+
* An uploader for a bucket: with a distribution, every deploy under `deploys/<reference>` and the distribution switched
|
|
46
|
+
* to it; without one, the files written over the site's.
|
|
47
|
+
*/
|
|
48
|
+
export declare const s3Uploader: (target: S3Target, options: {
|
|
49
|
+
cloudFront?: CloudFrontTarget;
|
|
50
|
+
reference: string;
|
|
51
|
+
}) => SiteUploader;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AWS Signature Version 4, for the few calls a deploy makes (S3 and the storages that speak it — R2, MinIO,
|
|
3
|
+
* SeaweedFS —, CloudFront, Amplify): a request signed here is one `fetch`, with no SDK to install for a server that
|
|
4
|
+
* otherwise never talks to AWS.
|
|
5
|
+
*/
|
|
6
|
+
export interface AwsCredentials {
|
|
7
|
+
accessKeyId: string;
|
|
8
|
+
secretAccessKey: string;
|
|
9
|
+
/** A temporary credential's (an assumed role's). */
|
|
10
|
+
sessionToken?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface AwsRequest {
|
|
13
|
+
method: string;
|
|
14
|
+
url: URL;
|
|
15
|
+
headers?: Record<string, string>;
|
|
16
|
+
body?: Uint8Array | string;
|
|
17
|
+
region: string;
|
|
18
|
+
/** `s3`, `cloudfront`, `amplify`… */
|
|
19
|
+
service: string;
|
|
20
|
+
credentials: AwsCredentials;
|
|
21
|
+
/** The moment it is signed at; now when left out. */
|
|
22
|
+
now?: Date;
|
|
23
|
+
}
|
|
24
|
+
/** RFC 3986's unreserved characters left as they are, everything else percent-encoded — what SigV4 asks. */
|
|
25
|
+
export declare const awsEncode: (value: string) => string;
|
|
26
|
+
/** The headers a request is sent with, signed: its own, plus `host`, `x-amz-date`, the payload's digest and `authorization`. */
|
|
27
|
+
export declare const signAws: ({ method, url, headers, body, region, service, credentials, now }: AwsRequest) => Record<string, string>;
|
|
28
|
+
/** What AWS answered when it refused, in its own words — the `<Message>` of its XML, or the `message` of its JSON. */
|
|
29
|
+
export declare const awsRefusal: (response: Response, doing: string) => Promise<Error>;
|
|
30
|
+
/** A signed request, sent. */
|
|
31
|
+
export declare const awsFetch: (request: AwsRequest & {
|
|
32
|
+
signal?: AbortSignal;
|
|
33
|
+
}) => Promise<Response>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { FingerprintParts } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Does this publish need a deploy? A build is described part by part — the SDK it loads, the fonts it
|
|
4
|
+
* links, the environment it names — each a digest, computed without building anything, so a target's last deploy and
|
|
5
|
+
* the revision about to be published can be compared before the person confirms, and the parts that differ said.
|
|
6
|
+
*/
|
|
7
|
+
/** A digest of anything JSON can say, the same for the same value whatever the order of its keys. */
|
|
8
|
+
export declare const digestOf: (value: unknown) => string;
|
|
9
|
+
/** The fingerprint of a build, whole: one digest of every part. */
|
|
10
|
+
export declare const fingerprintOf: (parts: FingerprintParts) => {
|
|
11
|
+
digest: string;
|
|
12
|
+
parts: FingerprintParts;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* The parts of `next` that differ from `deployed` — what a deploy would change, by name, in the order `next` lists
|
|
16
|
+
* them. A part only one side has is a difference too: a build that bakes something new in has changed.
|
|
17
|
+
*/
|
|
18
|
+
export declare const fingerprintChanges: (deployed: FingerprintParts, next: FingerprintParts) => string[];
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { SiteUploader } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* A site written into a folder of this machine — what `plitzi build --spa|--static` leaves for a customer's own CI to
|
|
4
|
+
* ship, and the simplest provider to try a build with. A path that would leave the folder is refused, never written.
|
|
5
|
+
*/
|
|
6
|
+
export declare const folderUploader: (folder: string) => SiteUploader;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { SiteUploader } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* A site written to a host by FTP (the oldest of them, kept for the hosts that offer nothing else): every
|
|
4
|
+
* file stored over a passive data connection, over TLS when the host offers it (`explicit`, AUTH TLS on port 21) or
|
|
5
|
+
* asks for it (`implicit`, port 990). Files are replaced one by one — not atomic, said before the first deploy and in
|
|
6
|
+
* every log — and a file the site no longer has is left on the host.
|
|
7
|
+
*/
|
|
8
|
+
export interface FtpTarget {
|
|
9
|
+
host: string;
|
|
10
|
+
port?: number;
|
|
11
|
+
user: string;
|
|
12
|
+
password: string;
|
|
13
|
+
/** `explicit` (AUTH TLS, the default), `implicit` (TLS from the first byte), or `none` — the password in the clear. */
|
|
14
|
+
secure?: 'explicit' | 'implicit' | 'none';
|
|
15
|
+
/** The folder the site goes into, from the account's home. */
|
|
16
|
+
folder?: string;
|
|
17
|
+
/** Accept a certificate no authority vouches for (a host's own): said in the log when used. */
|
|
18
|
+
allowSelfSigned?: boolean;
|
|
19
|
+
/** How long one answer is waited for. */
|
|
20
|
+
timeoutMs?: number;
|
|
21
|
+
}
|
|
22
|
+
/** The data address a `227 Entering Passive Mode (h1,h2,h3,h4,p1,p2)` answer names. */
|
|
23
|
+
export declare const passiveAddress: (text: string) => {
|
|
24
|
+
host: string;
|
|
25
|
+
port: number;
|
|
26
|
+
};
|
|
27
|
+
export declare const ftpUploader: (target: FtpTarget) => SiteUploader;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BuildVersions, SiteFile } from './types';
|
|
2
|
+
export interface SdkFiles {
|
|
3
|
+
/** The folder they live under, relative to the site's root: `_plitzi/sdk-<digest>`. */
|
|
4
|
+
folder: string;
|
|
5
|
+
digest: string;
|
|
6
|
+
files: SiteFile[];
|
|
7
|
+
}
|
|
8
|
+
/** The SDK's files, read once a process — the installed SDK cannot change while it runs. */
|
|
9
|
+
export declare const sdkFiles: () => SdkFiles;
|
|
10
|
+
/** The versions a build made here bakes in (§5.2): the SDK beside this server, its React, and this server. */
|
|
11
|
+
export declare const buildVersions: () => BuildVersions;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { BuiltSite, FingerprintParts } from './types';
|
|
2
|
+
import { Environment, FontHead } from '@plitzi/sdk-shared';
|
|
3
|
+
/** Where the SDK asks the platform, as the space's page server and APIs answer: the SDK's `server` setting. */
|
|
4
|
+
export interface SpaServers {
|
|
5
|
+
/** The page server that answers `/_plitzi/space.json` with the space's public key. */
|
|
6
|
+
ssrServer: string;
|
|
7
|
+
apiServer: string;
|
|
8
|
+
serverUrl: string;
|
|
9
|
+
websocketServer: string;
|
|
10
|
+
subscriptionServer: string;
|
|
11
|
+
}
|
|
12
|
+
export interface SpaShellInput {
|
|
13
|
+
/** The space's public `render` key, whose origins name the site's domain. */
|
|
14
|
+
webKey: string;
|
|
15
|
+
environment: Exclude<Environment, 'main'>;
|
|
16
|
+
servers: SpaServers;
|
|
17
|
+
/** What the document's head says before the SDK takes over. */
|
|
18
|
+
head: {
|
|
19
|
+
title: string;
|
|
20
|
+
/** BCP 47. */
|
|
21
|
+
lang: string;
|
|
22
|
+
/** An address or a `data:` URL. */
|
|
23
|
+
favicon: string;
|
|
24
|
+
fonts: FontHead;
|
|
25
|
+
};
|
|
26
|
+
/** The path the site is served under — `/` on its own domain, `/repo/` on a GitHub Pages project site. */
|
|
27
|
+
basePath?: string;
|
|
28
|
+
}
|
|
29
|
+
/** What an SPA bakes in, part by part (§5.1): what its fingerprint is made of, and the reasons a deploy is needed. */
|
|
30
|
+
export declare const spaFingerprintParts: (input: SpaShellInput, sdkDigest?: string) => FingerprintParts;
|
|
31
|
+
/**
|
|
32
|
+
* The SPA, built: `index.html`, the same page as `404.html` — a static host answers an address it has no file for with
|
|
33
|
+
* it, so a link into the site opens its page instead of the host's error — and the SDK's files.
|
|
34
|
+
*/
|
|
35
|
+
export declare const buildSpaShell: (input: SpaShellInput) => BuiltSite;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { BuiltSite, DeployLog } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* A space prerendered: every page a page server draws, read from it as a browser would and kept
|
|
4
|
+
* as HTML, with every file of the same origin those pages load — the SDK, the stylesheets, the fonts, the images —
|
|
5
|
+
* beside them at the paths they are asked for. The pages are the content, so every publish of one is a deploy.
|
|
6
|
+
*
|
|
7
|
+
* Which pages: the routes it is given, and every internal link found in them, followed (§14 decision 2). A route with
|
|
8
|
+
* parameters that no page links to is not guessed: it is reported by name, never left out silently.
|
|
9
|
+
*/
|
|
10
|
+
/** What the page server answered for one path. */
|
|
11
|
+
export interface FetchedPage {
|
|
12
|
+
status: number;
|
|
13
|
+
/** Its media type, as the `Content-Type` said. */
|
|
14
|
+
type: string;
|
|
15
|
+
body: Uint8Array;
|
|
16
|
+
}
|
|
17
|
+
export interface StaticSiteInput {
|
|
18
|
+
/** Asks the page server for a path of the site (`/menu`, `/sdk-assets/plitzi-sdk.js?v=1`), as a visitor's browser would. */
|
|
19
|
+
fetchPage: (path: string) => Promise<FetchedPage>;
|
|
20
|
+
/** The routes to start from: the space's pages, `/blog/:slug` included — a pattern is only reported, never fetched. */
|
|
21
|
+
routes: string[];
|
|
22
|
+
/** The addresses of a parameterised route to prerender, listed by the target (`/blog/hello`). */
|
|
23
|
+
extraPaths?: string[];
|
|
24
|
+
/** At most this many pages. */
|
|
25
|
+
maxPages?: number;
|
|
26
|
+
log: DeployLog;
|
|
27
|
+
signal?: AbortSignal;
|
|
28
|
+
/** What the deploy is built from, for its fingerprint (`production@12`). */
|
|
29
|
+
version: string;
|
|
30
|
+
}
|
|
31
|
+
export interface StaticSite extends BuiltSite {
|
|
32
|
+
/** Routes with parameters no page linked to and the target did not list: not prerendered. */
|
|
33
|
+
unreached: string[];
|
|
34
|
+
}
|
|
35
|
+
/** The file a path is kept as: `/` → `index.html`, `/menu` → `menu/index.html`, `/a.js?v=1` → `a.js`. */
|
|
36
|
+
export declare const fileOf: (path: string, html: boolean) => string;
|
|
37
|
+
/** The pages an HTML document links to, and the files it loads (scripts, stylesheets, images, the import map's). */
|
|
38
|
+
export declare const linksOf: (html: string) => {
|
|
39
|
+
pages: string[];
|
|
40
|
+
files: string[];
|
|
41
|
+
};
|
|
42
|
+
/** The files a stylesheet loads (`url(...)`, `@import`), resolved against where it is. */
|
|
43
|
+
export declare const cssFilesOf: (css: string, at: string) => string[];
|
|
44
|
+
export declare const buildStaticSite: ({ fetchPage, routes, extraPaths, maxPages, log, signal, version }: StaticSiteInput) => Promise<StaticSite>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a deploy is made of, whatever builds it and wherever it goes: a site is a list of files at paths
|
|
3
|
+
* relative to its root, and a provider is what puts that list somewhere a visitor's browser reaches.
|
|
4
|
+
*/
|
|
5
|
+
/** One file of a site: where it is served from (no leading slash), what it holds and how it is served. */
|
|
6
|
+
export interface SiteFile {
|
|
7
|
+
path: string;
|
|
8
|
+
body: Uint8Array;
|
|
9
|
+
/** Its media type, as the host should answer it (`contentTypeOf`). */
|
|
10
|
+
type: string;
|
|
11
|
+
/**
|
|
12
|
+
* How long a browser may keep it: `immutable` for a file whose name changes with its content (the SDK's, the fonts),
|
|
13
|
+
* `revalidate` for one at a fixed address (`index.html`), which must be asked for again after every deploy.
|
|
14
|
+
*/
|
|
15
|
+
cache: 'immutable' | 'revalidate';
|
|
16
|
+
}
|
|
17
|
+
/** A line of a deploy's log, said as it happens. Every write a provider makes says what it did; nothing is silent. */
|
|
18
|
+
export type DeployLog = (line: string, level?: 'info' | 'warn' | 'error') => void;
|
|
19
|
+
/** What a provider answers once the site is where it goes. */
|
|
20
|
+
export interface UploadResult {
|
|
21
|
+
/** Files written (or found already there, by digest). */
|
|
22
|
+
files: number;
|
|
23
|
+
bytes: number;
|
|
24
|
+
/** Where the site can be seen now, when the provider says (a deploy's own address on Netlify, Vercel, Pages). */
|
|
25
|
+
url?: string;
|
|
26
|
+
/** The provider's own name for this deploy (a commit, a deploy id, the prefix written), to go back to it. */
|
|
27
|
+
reference?: string;
|
|
28
|
+
}
|
|
29
|
+
/** Puts a site somewhere: one per provider, given its credential and settings by whoever builds it. */
|
|
30
|
+
export interface SiteUploader {
|
|
31
|
+
/** Its name in a log: `S3 bucket acme-site`, `GitHub acme/site@gh-pages`. */
|
|
32
|
+
readonly name: string;
|
|
33
|
+
/** Whether the switch to the new site is one step a visitor never sees half-done (§6 "Atomic switch"). */
|
|
34
|
+
readonly atomic: boolean;
|
|
35
|
+
upload: (files: SiteFile[], log: DeployLog, signal?: AbortSignal) => Promise<UploadResult>;
|
|
36
|
+
}
|
|
37
|
+
/** The versions a build bakes in: what the site runs until it is deployed again. */
|
|
38
|
+
export interface BuildVersions {
|
|
39
|
+
/** `@plitzi/plitzi-sdk`. */
|
|
40
|
+
sdk: string;
|
|
41
|
+
react: string;
|
|
42
|
+
/** `@plitzi/sdk-server`, which built it. */
|
|
43
|
+
sdkServer: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* What a build baked in, part by part, each a digest: two builds of the same revision for the same target agree on every
|
|
47
|
+
* part, and the parts that differ are the reasons a target needs a deploy ("the fonts changed, the SDK is newer").
|
|
48
|
+
*/
|
|
49
|
+
export type FingerprintParts = Record<string, string>;
|
|
50
|
+
/** A site ready to upload: its files, what each part of it was built from, and the versions it runs. */
|
|
51
|
+
export interface BuiltSite {
|
|
52
|
+
files: SiteFile[];
|
|
53
|
+
fingerprint: {
|
|
54
|
+
digest: string;
|
|
55
|
+
parts: FingerprintParts;
|
|
56
|
+
};
|
|
57
|
+
versions: BuildVersions;
|
|
58
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SiteFile } from './types';
|
|
2
|
+
/** A site's files as one zip, the same bytes for the same files. */
|
|
3
|
+
export declare const zipFiles: (files: SiteFile[]) => Uint8Array;
|
|
4
|
+
/**
|
|
5
|
+
* The files of a zip this module wrote (or any zip of the same subset: no ZIP64, no encryption, stored or deflated).
|
|
6
|
+
* Anything else is refused with what it is, never read half.
|
|
7
|
+
*/
|
|
8
|
+
export declare const unzipFiles: (zip: Uint8Array, cache?: (path: string) => SiteFile["cache"]) => SiteFile[];
|
package/dist/deploy.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A space's site built and put where it is served: the SPA shell and its fingerprint, the versions a build
|
|
3
|
+
* bakes in, a site as a zip and back, and the uploaders a self-hoster's deployment or the CLI hands a credential —
|
|
4
|
+
* an S3 bucket (AWS, R2, any storage that speaks its API) with CloudFront, an FTP host, a folder — and a site
|
|
5
|
+
* prerendered from any page server. A server that never deploys never
|
|
6
|
+
* loads it.
|
|
7
|
+
*/
|
|
8
|
+
export { signAws, awsFetch, awsEncode, awsRefusal } from './deploy/aws/sigv4';
|
|
9
|
+
export { invalidateCloudFront, objectUrl, pointCloudFront, putFiles, putObject, s3Uploader } from './deploy/aws/s3';
|
|
10
|
+
export { contentTypeOf } from './deploy/contentType';
|
|
11
|
+
export { digestOf, fingerprintChanges, fingerprintOf } from './deploy/fingerprint';
|
|
12
|
+
export { folderUploader } from './deploy/folder';
|
|
13
|
+
export { ftpUploader, passiveAddress } from './deploy/ftp';
|
|
14
|
+
export { buildVersions, sdkFiles } from './deploy/sdkFiles';
|
|
15
|
+
export { buildSpaShell, spaFingerprintParts } from './deploy/spaShell';
|
|
16
|
+
export { buildStaticSite, cssFilesOf, fileOf, linksOf } from './deploy/staticSite';
|
|
17
|
+
export { unzipFiles, zipFiles } from './deploy/zip';
|
|
18
|
+
export type { AwsCredentials, AwsRequest } from './deploy/aws/sigv4';
|
|
19
|
+
export type { CloudFrontTarget, S3Target } from './deploy/aws/s3';
|
|
20
|
+
export type { FtpTarget } from './deploy/ftp';
|
|
21
|
+
export type { SdkFiles } from './deploy/sdkFiles';
|
|
22
|
+
export type { FetchedPage, StaticSite, StaticSiteInput } from './deploy/staticSite';
|
|
23
|
+
export type { SpaServers, SpaShellInput } from './deploy/spaShell';
|
|
24
|
+
export type { BuildVersions, BuiltSite, DeployLog, FingerprintParts, SiteFile, SiteUploader, UploadResult } from './deploy/types';
|