freestyle-sandboxes 0.1.34 → 0.1.35
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/cli.mjs +51 -3
- package/index.cjs +10 -0
- package/index.d.cts +7 -0
- package/index.d.mts +7 -0
- package/index.mjs +10 -0
- package/package.json +1 -1
package/cli.mjs
CHANGED
|
@@ -499,6 +499,31 @@ function getDefaultTeamId() {
|
|
|
499
499
|
return stored?.defaultTeamId;
|
|
500
500
|
}
|
|
501
501
|
|
|
502
|
+
function normalizeCliProxyError(errorText) {
|
|
503
|
+
try {
|
|
504
|
+
const parsed = JSON.parse(errorText);
|
|
505
|
+
if (typeof parsed.code === "string" && typeof parsed.message === "string") {
|
|
506
|
+
return {
|
|
507
|
+
body: JSON.stringify(parsed),
|
|
508
|
+
contentType: "application/json"
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
const message = [parsed.error, parsed.message, parsed.reason].find(
|
|
512
|
+
(value) => typeof value === "string" && value.length > 0
|
|
513
|
+
);
|
|
514
|
+
if (message) {
|
|
515
|
+
return {
|
|
516
|
+
body: message,
|
|
517
|
+
contentType: "text/plain; charset=utf-8"
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
} catch {
|
|
521
|
+
}
|
|
522
|
+
return {
|
|
523
|
+
body: errorText || "Request failed",
|
|
524
|
+
contentType: "text/plain; charset=utf-8"
|
|
525
|
+
};
|
|
526
|
+
}
|
|
502
527
|
function createProxyFetch(accessToken, teamId) {
|
|
503
528
|
const dashboardApiUrl = process.env.FREESTYLE_DASHBOARD_URL || "https://dash.freestyle.sh";
|
|
504
529
|
return async (url, init) => {
|
|
@@ -522,9 +547,13 @@ function createProxyFetch(accessToken, teamId) {
|
|
|
522
547
|
});
|
|
523
548
|
if (!proxyResponse.ok) {
|
|
524
549
|
const errorText = await proxyResponse.text();
|
|
525
|
-
|
|
550
|
+
const normalizedError = normalizeCliProxyError(errorText);
|
|
551
|
+
return new Response(normalizedError.body, {
|
|
526
552
|
status: proxyResponse.status,
|
|
527
|
-
statusText: proxyResponse.statusText
|
|
553
|
+
statusText: proxyResponse.statusText,
|
|
554
|
+
headers: {
|
|
555
|
+
"Content-Type": normalizedError.contentType
|
|
556
|
+
}
|
|
528
557
|
});
|
|
529
558
|
}
|
|
530
559
|
const data = await proxyResponse.json();
|
|
@@ -1911,6 +1940,25 @@ const logoutCommand = {
|
|
|
1911
1940
|
}
|
|
1912
1941
|
};
|
|
1913
1942
|
|
|
1943
|
+
const whoamiCommand = {
|
|
1944
|
+
command: "whoami",
|
|
1945
|
+
describe: "Display information about the currently authenticated user",
|
|
1946
|
+
builder: (yargs) => yargs,
|
|
1947
|
+
handler: async (_argv) => {
|
|
1948
|
+
loadEnv();
|
|
1949
|
+
try {
|
|
1950
|
+
const client = await getFreestyleClient();
|
|
1951
|
+
const info = await client.whoami();
|
|
1952
|
+
console.log(`Account ID: ${info.accountId}`);
|
|
1953
|
+
if (info.identityId) {
|
|
1954
|
+
console.log(`Identity ID: ${info.identityId}`);
|
|
1955
|
+
}
|
|
1956
|
+
} catch (e) {
|
|
1957
|
+
handleError(e);
|
|
1958
|
+
}
|
|
1959
|
+
}
|
|
1960
|
+
};
|
|
1961
|
+
|
|
1914
1962
|
dotenv.config({ quiet: true });
|
|
1915
1963
|
yargs(hideBin(process.argv)).scriptName("freestyle").usage("$0 <command> [options]").option("team", {
|
|
1916
1964
|
type: "string",
|
|
@@ -1920,4 +1968,4 @@ yargs(hideBin(process.argv)).scriptName("freestyle").usage("$0 <command> [option
|
|
|
1920
1968
|
if (argv.team && typeof argv.team === "string") {
|
|
1921
1969
|
process.env.FREESTYLE_TEAM_ID = argv.team;
|
|
1922
1970
|
}
|
|
1923
|
-
}).command(vmCommand).command(gitCommand).command(domainsCommand).command(cronCommand).command(loginCommand).command(logoutCommand).command(deployCommand).command(runCommand).demandCommand(1, "You need to specify a command").help().alias("help", "h").version().alias("version", "v").strict().parse();
|
|
1971
|
+
}).command(vmCommand).command(gitCommand).command(domainsCommand).command(cronCommand).command(loginCommand).command(logoutCommand).command(whoamiCommand).command(deployCommand).command(runCommand).demandCommand(1, "You need to specify a command").help().alias("help", "h").version().alias("version", "v").strict().parse();
|
package/index.cjs
CHANGED
|
@@ -6994,6 +6994,16 @@ class Freestyle {
|
|
|
6994
6994
|
this.vms = new VmsNamespace(this);
|
|
6995
6995
|
this.cron = new CronNamespace(this._apiClient);
|
|
6996
6996
|
}
|
|
6997
|
+
/**
|
|
6998
|
+
* Returns information about the currently authenticated user or identity.
|
|
6999
|
+
*/
|
|
7000
|
+
async whoami() {
|
|
7001
|
+
const response = await this._apiClient.fetch("/auth/v1/whoami");
|
|
7002
|
+
if (!response.ok) {
|
|
7003
|
+
throw new Error(`Failed to get whoami: ${response.status} ${await response.text()}`);
|
|
7004
|
+
}
|
|
7005
|
+
return response.json();
|
|
7006
|
+
}
|
|
6997
7007
|
/**
|
|
6998
7008
|
* Helper method to make raw fetch requests to the API.
|
|
6999
7009
|
*/
|
package/index.d.cts
CHANGED
|
@@ -12535,6 +12535,13 @@ declare class Freestyle {
|
|
|
12535
12535
|
readonly vms: VmsNamespace;
|
|
12536
12536
|
readonly cron: CronNamespace;
|
|
12537
12537
|
constructor(options?: FreestyleOptions);
|
|
12538
|
+
/**
|
|
12539
|
+
* Returns information about the currently authenticated user or identity.
|
|
12540
|
+
*/
|
|
12541
|
+
whoami(): Promise<{
|
|
12542
|
+
accountId: string;
|
|
12543
|
+
identityId?: string;
|
|
12544
|
+
}>;
|
|
12538
12545
|
/**
|
|
12539
12546
|
* Helper method to make raw fetch requests to the API.
|
|
12540
12547
|
*/
|
package/index.d.mts
CHANGED
|
@@ -12535,6 +12535,13 @@ declare class Freestyle {
|
|
|
12535
12535
|
readonly vms: VmsNamespace;
|
|
12536
12536
|
readonly cron: CronNamespace;
|
|
12537
12537
|
constructor(options?: FreestyleOptions);
|
|
12538
|
+
/**
|
|
12539
|
+
* Returns information about the currently authenticated user or identity.
|
|
12540
|
+
*/
|
|
12541
|
+
whoami(): Promise<{
|
|
12542
|
+
accountId: string;
|
|
12543
|
+
identityId?: string;
|
|
12544
|
+
}>;
|
|
12538
12545
|
/**
|
|
12539
12546
|
* Helper method to make raw fetch requests to the API.
|
|
12540
12547
|
*/
|
package/index.mjs
CHANGED
|
@@ -6992,6 +6992,16 @@ class Freestyle {
|
|
|
6992
6992
|
this.vms = new VmsNamespace(this);
|
|
6993
6993
|
this.cron = new CronNamespace(this._apiClient);
|
|
6994
6994
|
}
|
|
6995
|
+
/**
|
|
6996
|
+
* Returns information about the currently authenticated user or identity.
|
|
6997
|
+
*/
|
|
6998
|
+
async whoami() {
|
|
6999
|
+
const response = await this._apiClient.fetch("/auth/v1/whoami");
|
|
7000
|
+
if (!response.ok) {
|
|
7001
|
+
throw new Error(`Failed to get whoami: ${response.status} ${await response.text()}`);
|
|
7002
|
+
}
|
|
7003
|
+
return response.json();
|
|
7004
|
+
}
|
|
6995
7005
|
/**
|
|
6996
7006
|
* Helper method to make raw fetch requests to the API.
|
|
6997
7007
|
*/
|