inflight-cli 2.3.0 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/netlify.js +17 -10
- package/dist/commands/share.js +22 -0
- package/dist/lib/netlify.d.ts +1 -1
- package/dist/lib/netlify.js +3 -2
- package/dist/providers/netlify.js +2 -2
- package/package.json +1 -1
package/dist/commands/netlify.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readNetlifyConfig } from "../lib/config.js";
|
|
2
2
|
import { getGitInfo, parseGitRepo, getGitRoot } from "../lib/git.js";
|
|
3
|
-
import { getNetlifyToken, getNetlifyDeploys, getNetlifySites, readLocalNetlifySite, matchSitesByRepo, } from "../lib/netlify.js";
|
|
3
|
+
import { getNetlifyToken, getNetlifyDeploys, getNetlifySites, getNetlifySiteById, readLocalNetlifySite, matchSitesByRepo, } from "../lib/netlify.js";
|
|
4
4
|
// --- Action handlers ---
|
|
5
5
|
async function listSites() {
|
|
6
6
|
const token = requireNetlifyToken();
|
|
@@ -17,16 +17,23 @@ async function listSites() {
|
|
|
17
17
|
* Priority: explicit flag → .netlify/state.json → git remote match → saved global config → error
|
|
18
18
|
*/
|
|
19
19
|
async function resolveSite(opts) {
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
const token = requireNetlifyToken();
|
|
21
|
+
if (opts.site) {
|
|
22
|
+
const detail = await getNetlifySiteById(token, opts.site);
|
|
23
|
+
if (detail)
|
|
24
|
+
return { siteId: detail.id, siteName: detail.name };
|
|
25
|
+
return { siteId: opts.site, siteName: opts.site };
|
|
26
|
+
}
|
|
22
27
|
const cwd = process.cwd();
|
|
23
28
|
const gitRoot = getGitRoot(cwd);
|
|
24
29
|
if (gitRoot) {
|
|
25
30
|
const local = readLocalNetlifySite(gitRoot);
|
|
26
|
-
if (local)
|
|
27
|
-
|
|
31
|
+
if (local) {
|
|
32
|
+
const detail = await getNetlifySiteById(token, local.siteId);
|
|
33
|
+
if (detail)
|
|
34
|
+
return { siteId: detail.id, siteName: detail.name };
|
|
35
|
+
}
|
|
28
36
|
}
|
|
29
|
-
const token = requireNetlifyToken();
|
|
30
37
|
const gitInfo = getGitInfo(cwd);
|
|
31
38
|
if (gitInfo.remoteUrl) {
|
|
32
39
|
const gitRepo = parseGitRepo(gitInfo.remoteUrl);
|
|
@@ -35,14 +42,14 @@ async function resolveSite(opts) {
|
|
|
35
42
|
const allSites = await getNetlifySites(token);
|
|
36
43
|
const matches = matchSitesByRepo(allSites, gitRepo.owner, gitRepo.name);
|
|
37
44
|
if (matches.length === 1)
|
|
38
|
-
return matches[0].id;
|
|
45
|
+
return { siteId: matches[0].id, siteName: matches[0].name };
|
|
39
46
|
}
|
|
40
47
|
catch { }
|
|
41
48
|
}
|
|
42
49
|
}
|
|
43
50
|
const config = readNetlifyConfig();
|
|
44
51
|
if (config)
|
|
45
|
-
return config.siteId;
|
|
52
|
+
return { siteId: config.siteId, siteName: config.siteName };
|
|
46
53
|
console.log(JSON.stringify({
|
|
47
54
|
error: "netlify_not_configured",
|
|
48
55
|
message: "Could not auto-detect Netlify site. Run 'inflight netlify sites' to list available sites, then pass --site to 'inflight netlify deploys'.",
|
|
@@ -51,8 +58,8 @@ async function resolveSite(opts) {
|
|
|
51
58
|
}
|
|
52
59
|
async function listDeploys(opts) {
|
|
53
60
|
const token = requireNetlifyToken();
|
|
54
|
-
const siteId = await resolveSite(opts);
|
|
55
|
-
const deploys = await getNetlifyDeploys(token, siteId);
|
|
61
|
+
const { siteId, siteName } = await resolveSite(opts);
|
|
62
|
+
const deploys = await getNetlifyDeploys(token, siteId, siteName);
|
|
56
63
|
console.log(JSON.stringify({ deploys }));
|
|
57
64
|
}
|
|
58
65
|
/** Gets token silently, exits with JSON error if unavailable. */
|
package/dist/commands/share.js
CHANGED
|
@@ -22,6 +22,15 @@ function formatRelativeTime(timestampMs) {
|
|
|
22
22
|
return `${days}d ago`;
|
|
23
23
|
return new Date(timestampMs).toLocaleDateString("en-US", { month: "short", day: "numeric" });
|
|
24
24
|
}
|
|
25
|
+
function isLocalhostUrl(url) {
|
|
26
|
+
try {
|
|
27
|
+
const hostname = new URL(url.startsWith("http") ? url : `https://${url}`).hostname;
|
|
28
|
+
return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "0.0.0.0" || hostname === "[::1]";
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
25
34
|
/**
|
|
26
35
|
* Checks local git state and prompts the user to commit/push if needed.
|
|
27
36
|
* Returns { justPushed: true } if changes were pushed, { justPushed: false } otherwise.
|
|
@@ -250,6 +259,16 @@ export async function shareCommand(opts = {}) {
|
|
|
250
259
|
if (!stagingUrl.startsWith("http")) {
|
|
251
260
|
stagingUrl = `https://${stagingUrl}`;
|
|
252
261
|
}
|
|
262
|
+
if (isLocalhostUrl(stagingUrl)) {
|
|
263
|
+
const message = "Inflight needs a hosted URL — localhost isn't accessible to your team. Deploy to Vercel, Netlify, or another hosting provider first.";
|
|
264
|
+
if (opts.json) {
|
|
265
|
+
console.log(JSON.stringify({ error: "localhost_url", message }));
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
p.log.error(message);
|
|
269
|
+
}
|
|
270
|
+
process.exit(1);
|
|
271
|
+
}
|
|
253
272
|
const result = await apiCreateVersion({
|
|
254
273
|
apiKey: auth.apiKey,
|
|
255
274
|
workspaceId,
|
|
@@ -309,6 +328,9 @@ export async function shareCommand(opts = {}) {
|
|
|
309
328
|
catch {
|
|
310
329
|
return "Must be a valid URL";
|
|
311
330
|
}
|
|
331
|
+
if (isLocalhostUrl(v)) {
|
|
332
|
+
return "Inflight needs a hosted URL — localhost isn't accessible to your team. Deploy to Vercel, Netlify, or another hosting provider first.";
|
|
333
|
+
}
|
|
312
334
|
},
|
|
313
335
|
});
|
|
314
336
|
if (p.isCancel(input)) {
|
package/dist/lib/netlify.d.ts
CHANGED
|
@@ -55,7 +55,7 @@ export declare function getNetlifyUser(token: string): Promise<{
|
|
|
55
55
|
} | null>;
|
|
56
56
|
export declare function getNetlifySites(token: string): Promise<NetlifySite[]>;
|
|
57
57
|
export declare function getNetlifySiteById(token: string, siteId: string): Promise<NetlifySite | null>;
|
|
58
|
-
export declare function getNetlifyDeploys(token: string, siteId: string, opts?: {
|
|
58
|
+
export declare function getNetlifyDeploys(token: string, siteId: string, siteName: string, opts?: {
|
|
59
59
|
branch?: string;
|
|
60
60
|
limit?: number;
|
|
61
61
|
}): Promise<NetlifyDeploy[]>;
|
package/dist/lib/netlify.js
CHANGED
|
@@ -160,7 +160,7 @@ export async function getNetlifySiteById(token, siteId) {
|
|
|
160
160
|
return null;
|
|
161
161
|
return (await res.json());
|
|
162
162
|
}
|
|
163
|
-
export async function getNetlifyDeploys(token, siteId, opts) {
|
|
163
|
+
export async function getNetlifyDeploys(token, siteId, siteName, opts) {
|
|
164
164
|
const params = new URLSearchParams({ per_page: String(opts?.limit ?? 20) });
|
|
165
165
|
if (opts?.branch)
|
|
166
166
|
params.set("branch", opts.branch);
|
|
@@ -176,7 +176,8 @@ export async function getNetlifyDeploys(token, siteId, opts) {
|
|
|
176
176
|
branch: d.branch,
|
|
177
177
|
commitRef: d.commit_ref?.slice(0, 7) ?? null,
|
|
178
178
|
commitMessage: d.title,
|
|
179
|
-
|
|
179
|
+
// Construct the immutable per-deploy permalink
|
|
180
|
+
deploySslUrl: `https://${d.id}--${siteName}.netlify.app`,
|
|
180
181
|
context: d.context,
|
|
181
182
|
createdAt: new Date(d.created_at).getTime(),
|
|
182
183
|
}));
|
|
@@ -141,7 +141,7 @@ export async function resolveNetlifyUrl(cwd, gitInfo, opts) {
|
|
|
141
141
|
const localRepoPath = gitRepo ? `${gitRepo.owner}/${gitRepo.name}`.toLowerCase() : null;
|
|
142
142
|
const repoMatches = site.repoPath && localRepoPath ? site.repoPath.toLowerCase() === localRepoPath : false;
|
|
143
143
|
// Only filter by branch if we're in the matching repo — otherwise show all deploys
|
|
144
|
-
let deploys = await getNetlifyDeploys(token, site.siteId, {
|
|
144
|
+
let deploys = await getNetlifyDeploys(token, site.siteId, site.siteName, {
|
|
145
145
|
branch: repoMatches ? (gitInfo.branch ?? undefined) : undefined,
|
|
146
146
|
});
|
|
147
147
|
let commitDeploy = repoMatches ? deploys.find((d) => d.commitRef === commitSha) : undefined;
|
|
@@ -151,7 +151,7 @@ export async function resolveNetlifyUrl(cwd, gitInfo, opts) {
|
|
|
151
151
|
pollSpinner.start("Waiting for Netlify deployment...");
|
|
152
152
|
for (let i = 0; i < 30; i++) {
|
|
153
153
|
await new Promise((r) => setTimeout(r, 2000));
|
|
154
|
-
deploys = await getNetlifyDeploys(token, site.siteId, {
|
|
154
|
+
deploys = await getNetlifyDeploys(token, site.siteId, site.siteName, {
|
|
155
155
|
branch: repoMatches ? (gitInfo.branch ?? undefined) : undefined,
|
|
156
156
|
});
|
|
157
157
|
commitDeploy = deploys.find((d) => d.commitRef === commitSha);
|