@theholocron/holocron-plugin-netlify 2.0.0-alpha.1
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 +106 -0
- package/dist/index.d.mts +131 -0
- package/dist/index.mjs +208 -0
- package/package.json +67 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Newton Koumantzelis
|
|
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,106 @@
|
|
|
1
|
+
<!-- editorconfig-checker-disable-file -->
|
|
2
|
+
|
|
3
|
+
# `@theholocron/holocron-plugin-netlify`
|
|
4
|
+
|
|
5
|
+
Netlify plugin for [Holocron](../cli). Implements the
|
|
6
|
+
`deployment` capability against [`@theholocron/netlify-client`](https://github.com/theholocron/clients/tree/main/packages/netlify-client),
|
|
7
|
+
plus exports `verifyToken` + `AUTH_HINT` for use by `holocron auth`.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pnpm add -D @theholocron/holocron-plugin-netlify@alpha
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Auth
|
|
16
|
+
|
|
17
|
+
Token resolution order (matches the standard 4-step precedence set by
|
|
18
|
+
`docs/wiki/specifications/tech-auth-bootstrap.spec.md`):
|
|
19
|
+
|
|
20
|
+
1. `--token <TOKEN>` flag on the holocron invocation
|
|
21
|
+
2. `HOLOCRON_NETLIFY_TOKEN` env var (preferred — explicit intent)
|
|
22
|
+
3. `NETLIFY_AUTH_TOKEN` env var (Netlify-native)
|
|
23
|
+
4. **Keyring** — `com.theholocron.cli` service, account `netlify`
|
|
24
|
+
5. `AuthError` naming all four options + the bootstrap hint
|
|
25
|
+
|
|
26
|
+
## Setup
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
# Generate a Netlify API token (see vendor docs), then:
|
|
30
|
+
holocron auth set netlify <TOKEN>
|
|
31
|
+
holocron auth check netlify # verify
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Config
|
|
35
|
+
|
|
36
|
+
```jsonc
|
|
37
|
+
{
|
|
38
|
+
"providers": {
|
|
39
|
+
"deployment": "netlify",
|
|
40
|
+
},
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Plugin options, via the tuple form:
|
|
45
|
+
|
|
46
|
+
```jsonc
|
|
47
|
+
{
|
|
48
|
+
"providers": {
|
|
49
|
+
"deployment": [
|
|
50
|
+
"netlify",
|
|
51
|
+
{
|
|
52
|
+
// Required for ensureProject/listProjects — Netlify's
|
|
53
|
+
// create-site endpoint is scoped to /{account_slug}/sites.
|
|
54
|
+
"accountSlug": "iamnewton",
|
|
55
|
+
// Required for listEnvVars/setEnvVar — Netlify's env var API
|
|
56
|
+
// is scoped to /accounts/{account_id}/env, by id not slug.
|
|
57
|
+
// Non-secret identifier, safe to commit (same status as
|
|
58
|
+
// Vercel's teamId / Cloudflare's accountId elsewhere in this org).
|
|
59
|
+
"accountId": "6ac41cd9a87355ef3d13d261",
|
|
60
|
+
// Custom domain `holocron setup` attaches to the site.
|
|
61
|
+
"domain": "sentinel.theholocron.dev",
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
},
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## What's implemented
|
|
69
|
+
|
|
70
|
+
Thin wrapper over `@theholocron/netlify-client`'s `sites` / `deploys` /
|
|
71
|
+
`env` / `user` resources — see that package for the actual REST calls.
|
|
72
|
+
Verified against Netlify's real API, not only mocks: a live smoke test
|
|
73
|
+
(create a site, deploy real content via the client's in-memory zip
|
|
74
|
+
builder, poll to `ready`, fetch the live URL) using this plugin's own
|
|
75
|
+
built `createPlugin()` output.
|
|
76
|
+
|
|
77
|
+
- `listProjects` / `ensureProject` → `sites.list` / `sites.create`
|
|
78
|
+
- `deployFunction` → `deploys.createFromZip` — Netlify runs no build
|
|
79
|
+
step for a raw zip upload, so the caller (Sentinel's own stage-deploy
|
|
80
|
+
script) is responsible for already having resolved dependencies into
|
|
81
|
+
the file set, the same discipline Vercel's `deployFunction` path
|
|
82
|
+
requires via its own trimmed/pinned `package.json`.
|
|
83
|
+
- `getDeployment` → `deploys.get`
|
|
84
|
+
- `listEnvVars` / `setEnvVar` → `env.list` / `env.set`
|
|
85
|
+
- `ensureCustomDomain` → `sites.update({ custom_domain })`; returns a
|
|
86
|
+
CNAME record unconditionally (Netlify has no DNS-misconfiguration
|
|
87
|
+
check to consult the way Vercel does, so idempotency relies on
|
|
88
|
+
`Dns.upsertRecord()` being a safe no-op on an already-correct record)
|
|
89
|
+
|
|
90
|
+
Required by the `Deployment` interface but **not exercised by any
|
|
91
|
+
current consumer** (best-effort, see inline comments in
|
|
92
|
+
`src/capabilities/deployment.ts`):
|
|
93
|
+
|
|
94
|
+
- `updateProjectSettings` — Netlify has no direct equivalent of Vercel's
|
|
95
|
+
git-linked-project settings; no-ops to `sites.get`.
|
|
96
|
+
- `triggerDeployment` → `sites.triggerBuild`, untested against a real
|
|
97
|
+
git-linked Netlify site.
|
|
98
|
+
|
|
99
|
+
Not implemented: `listPreviewDeployments` / `deletePreviewDeployments`
|
|
100
|
+
(both optional on the interface) — no current consumer needs
|
|
101
|
+
branch-preview listing/cleanup.
|
|
102
|
+
|
|
103
|
+
## Status
|
|
104
|
+
|
|
105
|
+
Implemented for Sentinel's migration off Vercel
|
|
106
|
+
(`.notes/tech-sentinel-deploy-target-netlify.spec.md`, holocron#940).
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { NetlifyClient } from "@theholocron/netlify-client";
|
|
2
|
+
import { AuthError, DeployFunctionConfig, DeployFunctionResult, Deployment, DeploymentProject, DeploymentProjectSettings, DeploymentRecord, DeploymentTarget, DeploymentTrigger, DnsRecordRequest, ResolveTokenInput } from "@theholocron/cli";
|
|
3
|
+
//#region src/auth.d.ts
|
|
4
|
+
declare const resolveToken: (input?: ResolveTokenInput) => string;
|
|
5
|
+
//#endregion
|
|
6
|
+
//#region src/capabilities/deployment.d.ts
|
|
7
|
+
interface NetlifyDeploymentOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Required for `ensureProject` / `listProjects` (create/list use
|
|
10
|
+
* Netlify's `/{account_slug}/sites` path).
|
|
11
|
+
*/
|
|
12
|
+
accountSlug?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Required for `listEnvVars` / `setEnvVar` (Netlify's env var API is
|
|
15
|
+
* scoped to `/accounts/{account_id}/env`, by id — not slug).
|
|
16
|
+
*/
|
|
17
|
+
accountId?: string;
|
|
18
|
+
/** Custom domain `holocron setup` should attach to the site. */
|
|
19
|
+
domain?: string;
|
|
20
|
+
}
|
|
21
|
+
declare class NetlifyDeployment implements Deployment {
|
|
22
|
+
private readonly client;
|
|
23
|
+
private readonly opts;
|
|
24
|
+
readonly key: "deployment";
|
|
25
|
+
readonly providerName = "netlify";
|
|
26
|
+
readonly domain?: string;
|
|
27
|
+
constructor(client: () => NetlifyClient, opts?: NetlifyDeploymentOptions);
|
|
28
|
+
listProjects(): Promise<DeploymentProject[]>;
|
|
29
|
+
/** Create if missing, otherwise return existing — matched by exact name. */
|
|
30
|
+
ensureProject(input: {
|
|
31
|
+
name: string;
|
|
32
|
+
framework?: string;
|
|
33
|
+
repo?: string;
|
|
34
|
+
rootDirectory?: string;
|
|
35
|
+
}): Promise<DeploymentProject>;
|
|
36
|
+
/**
|
|
37
|
+
* Netlify has no direct equivalent of Vercel's git-linked project
|
|
38
|
+
* settings (`previewDeploymentsDisabled` / `gitProviderCreateDeployments`)
|
|
39
|
+
* — Sentinel's site isn't git-linked at all. Best-effort: return the
|
|
40
|
+
* project unchanged. Revisit if a future consumer needs a real mapping.
|
|
41
|
+
*/
|
|
42
|
+
updateProjectSettings(projectId: string, _settings: DeploymentProjectSettings): Promise<DeploymentProject>;
|
|
43
|
+
listEnvVars(projectId: string, target: DeploymentTarget): Promise<string[]>;
|
|
44
|
+
setEnvVar(projectId: string, target: DeploymentTarget, name: string, value: string): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* No Git integration in Sentinel's usage (file-based deploy only), but
|
|
47
|
+
* REQUIRED by the interface. Netlify's branch-triggered-build endpoint
|
|
48
|
+
* is the closest analog for a git-linked site; untested against a real
|
|
49
|
+
* git-linked Netlify site since no current consumer exercises this path.
|
|
50
|
+
*/
|
|
51
|
+
triggerDeployment(input: {
|
|
52
|
+
projectId: string;
|
|
53
|
+
branch: string;
|
|
54
|
+
target?: DeploymentTrigger;
|
|
55
|
+
}): Promise<DeploymentRecord>;
|
|
56
|
+
getDeployment(deploymentId: string): Promise<DeploymentRecord>;
|
|
57
|
+
/**
|
|
58
|
+
* Zips `config.files` (plain text, per the interface contract) and
|
|
59
|
+
* uploads it as a one-shot deploy. Netlify runs no build step for a
|
|
60
|
+
* raw zip upload — the caller (Sentinel's own stage-deploy script) is
|
|
61
|
+
* responsible for having already resolved dependencies into the file
|
|
62
|
+
* set, the same discipline Vercel's `deployFunction` path already
|
|
63
|
+
* requires via its own trimmed/pinned package.json.
|
|
64
|
+
*/
|
|
65
|
+
deployFunction(projectId: string, config: DeployFunctionConfig): Promise<DeployFunctionResult>;
|
|
66
|
+
/**
|
|
67
|
+
* Idempotent: PATCHing the same `custom_domain` twice is a no-op on
|
|
68
|
+
* Netlify's side. Unlike Vercel, Netlify's API has no DNS-misconfiguration
|
|
69
|
+
* check to consult — it's returned unconditionally once set, which is
|
|
70
|
+
* safe because `Dns.upsertRecord()` on the receiving end is itself
|
|
71
|
+
* idempotent (re-upserting an already-correct CNAME is a no-op there).
|
|
72
|
+
*/
|
|
73
|
+
ensureCustomDomain(projectId: string, hostname: string): Promise<DnsRecordRequest | null>;
|
|
74
|
+
private findSiteByName;
|
|
75
|
+
private requireAccountId;
|
|
76
|
+
}
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region src/verify-token.d.ts
|
|
79
|
+
/**
|
|
80
|
+
* `verifyToken` — plugin-level export used by `holocron auth set` +
|
|
81
|
+
* `holocron auth check`. Hits Netlify's `GET /user` (current token's
|
|
82
|
+
* identity) and translates the response into the normalized
|
|
83
|
+
* `VerifyTokenResult` shape.
|
|
84
|
+
*
|
|
85
|
+
* Kept as a standalone function (not a capability method) so the auth
|
|
86
|
+
* command can call it without initializing the full plugin — plugin
|
|
87
|
+
* construction requires an already-resolved token, which is exactly
|
|
88
|
+
* what we don't have yet at bootstrap time.
|
|
89
|
+
*/
|
|
90
|
+
interface VerifyTokenSuccess {
|
|
91
|
+
ok: true;
|
|
92
|
+
subject: string;
|
|
93
|
+
}
|
|
94
|
+
interface VerifyTokenFailure {
|
|
95
|
+
ok: false;
|
|
96
|
+
message: string;
|
|
97
|
+
}
|
|
98
|
+
type VerifyTokenResult = VerifyTokenSuccess | VerifyTokenFailure;
|
|
99
|
+
interface VerifyTokenOptions {
|
|
100
|
+
baseUrl?: string;
|
|
101
|
+
fetch?: typeof fetch;
|
|
102
|
+
}
|
|
103
|
+
declare function verifyToken(token: string, opts?: VerifyTokenOptions): Promise<VerifyTokenResult>;
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region src/index.d.ts
|
|
106
|
+
interface NetlifyPluginOptions extends ResolveTokenInput, NetlifyDeploymentOptions {
|
|
107
|
+
/** Override base URL for tests. */
|
|
108
|
+
baseUrl?: string;
|
|
109
|
+
/** Override `fetch` for tests. */
|
|
110
|
+
fetch?: typeof fetch;
|
|
111
|
+
}
|
|
112
|
+
interface PluginContext {
|
|
113
|
+
options: NetlifyPluginOptions;
|
|
114
|
+
/** Memoized client — the token is resolved on first use, not at plugin load. */
|
|
115
|
+
client: () => NetlifyClient;
|
|
116
|
+
}
|
|
117
|
+
declare function createContext(options: NetlifyPluginOptions): PluginContext;
|
|
118
|
+
declare function deployment(ctx: PluginContext): Deployment;
|
|
119
|
+
declare function createPlugin(options: NetlifyPluginOptions): {
|
|
120
|
+
name: string;
|
|
121
|
+
capabilities: {
|
|
122
|
+
deployment: () => Deployment;
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* One-line hint printed by `holocron auth set netlify` when no token is
|
|
127
|
+
* supplied or the supplied token is rejected.
|
|
128
|
+
*/
|
|
129
|
+
declare const AUTH_HINT: string;
|
|
130
|
+
//#endregion
|
|
131
|
+
export { AUTH_HINT, AuthError, NetlifyDeployment, type NetlifyDeploymentOptions, NetlifyPluginOptions, PluginContext, type ResolveTokenInput, type VerifyTokenFailure, type VerifyTokenResult, type VerifyTokenSuccess, createContext, createPlugin, deployment, resolveToken, verifyToken };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { createNetlifyClient } from "@theholocron/netlify-client";
|
|
2
|
+
import { AuthError, createResolveToken } from "@theholocron/cli";
|
|
3
|
+
import { ProviderApiError } from "@theholocron/http-client";
|
|
4
|
+
//#region src/auth.ts
|
|
5
|
+
const resolveToken = createResolveToken({
|
|
6
|
+
envName: "HOLOCRON_NETLIFY_TOKEN",
|
|
7
|
+
vendorEnvName: "NETLIFY_AUTH_TOKEN",
|
|
8
|
+
keyringService: "netlify",
|
|
9
|
+
errorMessage: "no Netlify token found. Pass --token <TOKEN>, set HOLOCRON_NETLIFY_TOKEN / NETLIFY_AUTH_TOKEN, or run: holocron auth set netlify <TOKEN>"
|
|
10
|
+
});
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/capabilities/deployment.ts
|
|
13
|
+
const TERMINAL_READY = /* @__PURE__ */ new Set(["ready", "current"]);
|
|
14
|
+
const TERMINAL_ERROR = /* @__PURE__ */ new Set(["error"]);
|
|
15
|
+
function toDeploymentProject(site) {
|
|
16
|
+
return {
|
|
17
|
+
id: site.id,
|
|
18
|
+
name: site.name,
|
|
19
|
+
gitLinked: false,
|
|
20
|
+
rootDirectory: null
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function toDeploymentRecord(deploy) {
|
|
24
|
+
const record = {
|
|
25
|
+
id: deploy.id,
|
|
26
|
+
url: deploy.ssl_url || deploy.url,
|
|
27
|
+
branch: deploy.branch,
|
|
28
|
+
status: TERMINAL_READY.has(deploy.state) ? "ready" : TERMINAL_ERROR.has(deploy.state) ? "error" : "building",
|
|
29
|
+
createdAt: deploy.created_at
|
|
30
|
+
};
|
|
31
|
+
if (deploy.error_message) record.errorMessage = deploy.error_message;
|
|
32
|
+
return record;
|
|
33
|
+
}
|
|
34
|
+
/** Netlify's deploy contexts map onto Holocron's `production` / `staging` as: production stays production, everything else is staging. */
|
|
35
|
+
function toNetlifyContext(target) {
|
|
36
|
+
return target === "production" ? "production" : "branch-deploy";
|
|
37
|
+
}
|
|
38
|
+
var NetlifyDeployment = class {
|
|
39
|
+
client;
|
|
40
|
+
opts;
|
|
41
|
+
key = "deployment";
|
|
42
|
+
providerName = "netlify";
|
|
43
|
+
domain;
|
|
44
|
+
constructor(client, opts = {}) {
|
|
45
|
+
this.client = client;
|
|
46
|
+
this.opts = opts;
|
|
47
|
+
if (opts.domain !== void 0) this.domain = opts.domain;
|
|
48
|
+
}
|
|
49
|
+
async listProjects() {
|
|
50
|
+
return (await this.client().sites.list()).map(toDeploymentProject);
|
|
51
|
+
}
|
|
52
|
+
/** Create if missing, otherwise return existing — matched by exact name. */
|
|
53
|
+
async ensureProject(input) {
|
|
54
|
+
const existing = await this.findSiteByName(input.name);
|
|
55
|
+
if (existing) return toDeploymentProject(existing);
|
|
56
|
+
const accountSlug = this.opts.accountSlug;
|
|
57
|
+
if (!accountSlug) throw new Error("@theholocron/holocron-plugin-netlify: ensureProject needs `accountSlug` in plugin options (Netlify's create-site endpoint is scoped to /{account_slug}/sites)");
|
|
58
|
+
try {
|
|
59
|
+
return toDeploymentProject(await this.client().sites.create(accountSlug, { name: input.name }));
|
|
60
|
+
} catch (err) {
|
|
61
|
+
if (err instanceof ProviderApiError && (err.status === 422 || err.status === 409)) {
|
|
62
|
+
const recheck = await this.findSiteByName(input.name);
|
|
63
|
+
if (recheck) return toDeploymentProject(recheck);
|
|
64
|
+
}
|
|
65
|
+
throw err;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Netlify has no direct equivalent of Vercel's git-linked project
|
|
70
|
+
* settings (`previewDeploymentsDisabled` / `gitProviderCreateDeployments`)
|
|
71
|
+
* — Sentinel's site isn't git-linked at all. Best-effort: return the
|
|
72
|
+
* project unchanged. Revisit if a future consumer needs a real mapping.
|
|
73
|
+
*/
|
|
74
|
+
async updateProjectSettings(projectId, _settings) {
|
|
75
|
+
return toDeploymentProject(await this.client().sites.get(projectId));
|
|
76
|
+
}
|
|
77
|
+
async listEnvVars(projectId, target) {
|
|
78
|
+
const accountId = this.requireAccountId();
|
|
79
|
+
const context = toNetlifyContext(target);
|
|
80
|
+
return (await this.client().env.list(accountId, projectId)).filter((v) => v.values.some((value) => value.context === context)).map((v) => v.key);
|
|
81
|
+
}
|
|
82
|
+
async setEnvVar(projectId, target, name, value) {
|
|
83
|
+
const accountId = this.requireAccountId();
|
|
84
|
+
await this.client().env.set(accountId, projectId, name, toNetlifyContext(target), value);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* No Git integration in Sentinel's usage (file-based deploy only), but
|
|
88
|
+
* REQUIRED by the interface. Netlify's branch-triggered-build endpoint
|
|
89
|
+
* is the closest analog for a git-linked site; untested against a real
|
|
90
|
+
* git-linked Netlify site since no current consumer exercises this path.
|
|
91
|
+
*/
|
|
92
|
+
async triggerDeployment(input) {
|
|
93
|
+
const build = await this.client().sites.triggerBuild(input.projectId);
|
|
94
|
+
if (!build.deploy_id) throw new Error("@theholocron/holocron-plugin-netlify: triggerDeployment got no deploy_id back from Netlify");
|
|
95
|
+
return toDeploymentRecord(await this.client().deploys.get(build.deploy_id));
|
|
96
|
+
}
|
|
97
|
+
async getDeployment(deploymentId) {
|
|
98
|
+
return toDeploymentRecord(await this.client().deploys.get(deploymentId));
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Zips `config.files` (plain text, per the interface contract) and
|
|
102
|
+
* uploads it as a one-shot deploy. Netlify runs no build step for a
|
|
103
|
+
* raw zip upload — the caller (Sentinel's own stage-deploy script) is
|
|
104
|
+
* responsible for having already resolved dependencies into the file
|
|
105
|
+
* set, the same discipline Vercel's `deployFunction` path already
|
|
106
|
+
* requires via its own trimmed/pinned package.json.
|
|
107
|
+
*/
|
|
108
|
+
async deployFunction(projectId, config) {
|
|
109
|
+
const deploy = await this.client().deploys.createFromZip(projectId, config.files, { draft: config.target === void 0 });
|
|
110
|
+
return {
|
|
111
|
+
deploymentId: deploy.id,
|
|
112
|
+
url: deploy.ssl_url || deploy.url
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Idempotent: PATCHing the same `custom_domain` twice is a no-op on
|
|
117
|
+
* Netlify's side. Unlike Vercel, Netlify's API has no DNS-misconfiguration
|
|
118
|
+
* check to consult — it's returned unconditionally once set, which is
|
|
119
|
+
* safe because `Dns.upsertRecord()` on the receiving end is itself
|
|
120
|
+
* idempotent (re-upserting an already-correct CNAME is a no-op there).
|
|
121
|
+
*/
|
|
122
|
+
async ensureCustomDomain(projectId, hostname) {
|
|
123
|
+
const site = await this.client().sites.get(projectId);
|
|
124
|
+
if (site.custom_domain !== hostname) await this.client().sites.update(projectId, { custom_domain: hostname });
|
|
125
|
+
const labels = hostname.split(".");
|
|
126
|
+
return {
|
|
127
|
+
zone: labels.length > 2 ? labels.slice(-2).join(".") : hostname,
|
|
128
|
+
record: {
|
|
129
|
+
type: "CNAME",
|
|
130
|
+
name: hostname,
|
|
131
|
+
content: new URL(site.ssl_url || site.url).hostname
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
async findSiteByName(name) {
|
|
136
|
+
return (await this.client().sites.list()).find((s) => s.name === name);
|
|
137
|
+
}
|
|
138
|
+
requireAccountId() {
|
|
139
|
+
if (!this.opts.accountId) throw new Error("@theholocron/holocron-plugin-netlify: env var methods need `accountId` in plugin options (Netlify's env API is scoped to /accounts/{account_id}/env)");
|
|
140
|
+
return this.opts.accountId;
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
//#endregion
|
|
144
|
+
//#region src/verify-token.ts
|
|
145
|
+
/**
|
|
146
|
+
* `verifyToken` — plugin-level export used by `holocron auth set` +
|
|
147
|
+
* `holocron auth check`. Hits Netlify's `GET /user` (current token's
|
|
148
|
+
* identity) and translates the response into the normalized
|
|
149
|
+
* `VerifyTokenResult` shape.
|
|
150
|
+
*
|
|
151
|
+
* Kept as a standalone function (not a capability method) so the auth
|
|
152
|
+
* command can call it without initializing the full plugin — plugin
|
|
153
|
+
* construction requires an already-resolved token, which is exactly
|
|
154
|
+
* what we don't have yet at bootstrap time.
|
|
155
|
+
*/
|
|
156
|
+
async function verifyToken(token, opts = {}) {
|
|
157
|
+
const client = createNetlifyClient({
|
|
158
|
+
token,
|
|
159
|
+
baseUrl: opts.baseUrl,
|
|
160
|
+
fetch: opts.fetch
|
|
161
|
+
});
|
|
162
|
+
try {
|
|
163
|
+
const user = await client.user.get();
|
|
164
|
+
return {
|
|
165
|
+
ok: true,
|
|
166
|
+
subject: `user @ ${user?.email ?? user?.full_name ?? user?.id ?? "unknown"}`
|
|
167
|
+
};
|
|
168
|
+
} catch (err) {
|
|
169
|
+
return {
|
|
170
|
+
ok: false,
|
|
171
|
+
message: err instanceof Error ? err.message : String(err)
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
//#endregion
|
|
176
|
+
//#region src/index.ts
|
|
177
|
+
function createContext(options) {
|
|
178
|
+
let client;
|
|
179
|
+
return {
|
|
180
|
+
options,
|
|
181
|
+
client: () => client ??= createNetlifyClient({
|
|
182
|
+
token: resolveToken(options),
|
|
183
|
+
baseUrl: options.baseUrl,
|
|
184
|
+
fetch: options.fetch
|
|
185
|
+
})
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
function deployment(ctx) {
|
|
189
|
+
const opts = {};
|
|
190
|
+
if (ctx.options.accountSlug !== void 0) opts.accountSlug = ctx.options.accountSlug;
|
|
191
|
+
if (ctx.options.accountId !== void 0) opts.accountId = ctx.options.accountId;
|
|
192
|
+
if (ctx.options.domain !== void 0) opts.domain = ctx.options.domain;
|
|
193
|
+
return new NetlifyDeployment(ctx.client, opts);
|
|
194
|
+
}
|
|
195
|
+
function createPlugin(options) {
|
|
196
|
+
const ctx = createContext(options);
|
|
197
|
+
return {
|
|
198
|
+
name: "@theholocron/holocron-plugin-netlify",
|
|
199
|
+
capabilities: { deployment: () => deployment(ctx) }
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* One-line hint printed by `holocron auth set netlify` when no token is
|
|
204
|
+
* supplied or the supplied token is rejected.
|
|
205
|
+
*/
|
|
206
|
+
const AUTH_HINT = "generate a Netlify Personal Access Token at https://app.netlify.com/user/applications#personal-access-tokens, then run: holocron auth set netlify <TOKEN>";
|
|
207
|
+
//#endregion
|
|
208
|
+
export { AUTH_HINT, AuthError, NetlifyDeployment, createContext, createPlugin, deployment, resolveToken, verifyToken };
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@theholocron/holocron-plugin-netlify",
|
|
3
|
+
"version": "2.0.0-alpha.1",
|
|
4
|
+
"description": "Holocron plugin for Netlify. Implements the deployment capability against Netlify's REST API, plus exports verifyToken + AUTH_HINT for `holocron auth`.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"deployment",
|
|
7
|
+
"holocron",
|
|
8
|
+
"netlify",
|
|
9
|
+
"plugin"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://github.com/theholocron/holocron/tree/main/packages/holocron-plugin-netlify#readme",
|
|
12
|
+
"bugs": "https://github.com/theholocron/holocron/issues",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/theholocron/holocron.git",
|
|
16
|
+
"directory": "packages/holocron-plugin-netlify"
|
|
17
|
+
},
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"author": "Newton Koumantzelis",
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"type": "module",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.mts",
|
|
25
|
+
"import": "./dist/index.mjs",
|
|
26
|
+
"default": "./dist/index.mjs"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"dist"
|
|
31
|
+
],
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@theholocron/http-client": "^1.36.0",
|
|
34
|
+
"@theholocron/netlify-client": "^1.36.0",
|
|
35
|
+
"@theholocron/tsconfig": "^8.4.5",
|
|
36
|
+
"@types/node": "^26",
|
|
37
|
+
"@vitest/coverage-v8": "^4.1.11",
|
|
38
|
+
"eslint": "^10.8.1",
|
|
39
|
+
"globals": "^17.11.0",
|
|
40
|
+
"tsdown": "^0.22.14",
|
|
41
|
+
"tsx": "4.23.12",
|
|
42
|
+
"typescript": "^5.9.3",
|
|
43
|
+
"vitest": "^4.1.11",
|
|
44
|
+
"@theholocron/cli": "5.0.0-alpha.109"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"@theholocron/netlify-client": "^1.36.0",
|
|
48
|
+
"@theholocron/cli": "5.0.0-alpha.109"
|
|
49
|
+
},
|
|
50
|
+
"peerDependenciesMeta": {
|
|
51
|
+
"@theholocron/netlify-client": {}
|
|
52
|
+
},
|
|
53
|
+
"engines": {
|
|
54
|
+
"node": ">=22"
|
|
55
|
+
},
|
|
56
|
+
"publishConfig": {
|
|
57
|
+
"access": "public"
|
|
58
|
+
},
|
|
59
|
+
"scripts": {
|
|
60
|
+
"delivery.build": "tsdown",
|
|
61
|
+
"sourceQuality.staticAnalysis": "holocron run sourceQuality.staticAnalysis --",
|
|
62
|
+
"test:watch": "vitest",
|
|
63
|
+
"validate": "tsx scripts/validate.mjs",
|
|
64
|
+
"verification.typeSafety": "holocron run verification.typeSafety --",
|
|
65
|
+
"verification.unitTests": "holocron run verification.unitTests --"
|
|
66
|
+
}
|
|
67
|
+
}
|