Skip to content
Svartz v2.6.0

@svartz/plugin-submissions

48 exported symbols.

Classes

c CommitsUnavailableGitHub can't be asked right now: the shared pause holds, this reader's requests are spent, or GitHub failed.

Interfaces

i BrowserOptionsSettings the browser script receives.
i BuildDataWhat the build records for the server: never sent to the browser.
i CommitA commit on the content branch.
i CommitReaderReads one request's worth of commits. Make one per request with `commitReader`.
i CommitSourceWhat reading a vault's commits takes: JSON, for the reader's server data. Holds no secret, only where they are.
i DestinationResponse`GET <endpoint>/destination/?folder=<folder>&title=<title>` answers this for a new page.
i EditRequest`POST <endpoint>/edit/` takes this JSON body.
i ErrorResponseEvery failure answers with this JSON body; `message` is written for the reader.
i LinksResponse`GET <endpoint>/links/` answers this: the published notes, never password-protected or hidden ones, and the attachments the site publishes.
i LinkTargetA published note a wikilink can name. The Split preview resolves links to it by `slug`, `path` and `aliases`, as the build does, and links them to `href`.
i NewPageRequest`POST <endpoint>/new/` takes this JSON body. The server derives the file path from `folder` and `title`.
i RateLimitOptions
i RestoreOne page's content to commit back.
i RestorerCommits for one request. Make one per request with `restorer`.
i RouteHolderThe page holding a route: its slug, which permissions are checked on, and its URL below the deployment base, `null` when hidden.
i SavedEditsThe edits a vault's site saved among those asked about, each with the id of the account that saved it, or `null`.
i SourceResponse`GET <endpoint>/source/?page=<href>` answers this.
i SubmissionsOptions
i TurnstileOptionsThe submission guard. Every submission passes a rate limit, keyed by the signed-in identity or else the client's IP, and is refused when it has neither. When sign-in is required, anonymous submissions are refused; otherwise, when Turnstile is configured, they must also carry a token Cloudflare verifies. Runs before any GitHub call.
i VaultRecordsWhere a vault's sync keeps its records: the D1 binding, the repository, and the vault's folder in it.

Types

t CredentialsExactly one kind of GitHub credentials: a token, or a GitHub App.
t DestinationWhere a save goes for the reader asking: `commit` straight to the branch, so it goes live with the next deploy, or `pull-request`, for review. `null` when they can't save there as they are now, such as a guest who must sign in.
t EditResponse
t FileAtThe content at a commit, or why there is none to show.
t ModeWhich saves may commit. `permission` commits for whoever holds `submissions:commits:write` on the page and opens a pull request for the rest; `commit` refuses the rest instead; `pull-request` never commits.
t RestoredWhat `Restorer.restore` did: committed, or why not. `unchanged` when the branch already held the content, `changed` when its file isn't the one the caller read, `protected` when a rule for the branch refuses the commit, `busy` when the branch moved on meanwhile. Only `commit` moved the branch.
t RouteClaimsThe routes the last build allocated, which a note's frontmatter can claim: JSON, for server data.
t ServerOptionsThe plugin's server options, as written into the server bundle.

Functions

f changedFilesThe vault files each of `commits` (SHAs) changed, as vault paths, for those the mirror of the vault `records` describes holds with their files. In one query; none when the binding is missing.
f commitAttributionThe account a commit is authored as, with its linked GitHub account as co-author, and the App's bot that commits it.
f commitReaderReads commits for one vault. The answer makes a `CommitReader` per request; installation tokens and file contents are kept across requests in this worker. Pass `token` to share one `sourceToken` with a writer.
f commitSourceWhat reading the vault's commits takes, or `undefined` when no submissions plugin keeps its mirror. Call it from `emitArtifacts` with `enforce: "post"`: the vault's folder in the repository is what the submissions plugin's own `emitArtifacts` read from git.
f isVaultSubmissionWhether pull request `number` is a submission the site saved for the vault `records` describes: what that vault's `POST close/` accepts. `false` when the binding is missing. The moderation plugin asks before it offers Close.
f mirrorsCommitsWhether one of a vault's `plugins` is a submissions plugin keeping the GitHub mirror. For a plugin's `forVault`.
f mountAdds Edit to the page actions of every editable note, New page to the site actions of every page, Create your page to the account page of a reader without a user page, and Edit page to a submission in My submissions while it takes follow-up edits. The editor itself loads on first use, or at once when the reader comes back from signing in with a draft for this page. On a submission, it also keeps an unsent reply while its form posts.
f renderRevision`markdown` rendered as the note at `options.path`, ready to put in a page.
f restorerRestores a vault's pages. Only a GitHub App commits as an account, so with a token `commits` is false and every restore throws. `token` shares a `sourceToken` with the vault's commit reader.
f routeClaimsOfThe routes the vault's pages hold, hidden and protected ones included, which a page's frontmatter can claim: what `@svartz/plugin-submissions/restore` checks a restored revision against. From `emitArtifacts` with `enforce: "post"`, as `commitSource`; `undefined` without the submissions plugin.
f savedEditsWhich of `commits` (SHAs) and `pulls` (numbers) the site saved for the vault `records` describes, and the account behind each: whoever made the commit, or opened the pull request with its first save. `null` for a save by someone without an account. In one query; none are saved when the binding is missing.
f sourceTokenThe token `source`'s credentials authenticate with: the configured one, or the App's installation token, kept.
f submissionsLet readers edit any published Markdown note, or add one in a published folder, as a pull request on `repo`.
f wasPublicWhether the build would have published a note with `markdown`'s frontmatter, unprotected: not a draft, not private, in no password group. A revision it would have hidden stays hidden, though the page is public now. Frontmatter the build couldn't read counts as hidden.

Variables

v default
v GITHUB_PAGE_SIZECommits per page of GitHub's list, its most.
v MAX_FILE_BYTESFile content larger than this isn't read; a note the editor accepts is far smaller.
v MAX_GITHUB_READSGitHub requests one reader may make: what the costliest page, a diff of two revisions the mirror doesn't hold, needs. That is the default branch's name, when neither config nor the mirror knows it, then for each revision the check that the branch holds it, the commit, and the page's file at it.
v RECENT_PAGE_SIZECommits per page of `CommitReader.recent`.