@getmagical/cli 0.2.1 → 0.2.2
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/index.js +54 -51
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -16240,6 +16240,30 @@ import { Command as Command2, InvalidArgumentError as InvalidArgumentError2, Opt
|
|
|
16240
16240
|
|
|
16241
16241
|
// src/api.ts
|
|
16242
16242
|
import { z as z23 } from "zod";
|
|
16243
|
+
|
|
16244
|
+
// src/version.ts
|
|
16245
|
+
import fs from "node:fs";
|
|
16246
|
+
import path from "node:path";
|
|
16247
|
+
import { fileURLToPath } from "node:url";
|
|
16248
|
+
var packageManifestPath = path.resolve(
|
|
16249
|
+
path.dirname(fileURLToPath(import.meta.url)),
|
|
16250
|
+
"../package.json"
|
|
16251
|
+
);
|
|
16252
|
+
var packageManifestResult = safeJsonParse(
|
|
16253
|
+
fs.readFileSync(packageManifestPath, "utf8")
|
|
16254
|
+
);
|
|
16255
|
+
if (isErr(packageManifestResult)) {
|
|
16256
|
+
throw new Error(`Failed to parse ${packageManifestPath}.`, {
|
|
16257
|
+
cause: packageManifestResult.error.cause
|
|
16258
|
+
});
|
|
16259
|
+
}
|
|
16260
|
+
var cliPackageVersion = packageManifestResult.value.version;
|
|
16261
|
+
if (typeof cliPackageVersion !== "string" || cliPackageVersion.length === 0) {
|
|
16262
|
+
throw new Error(`Expected a version in ${packageManifestPath}.`);
|
|
16263
|
+
}
|
|
16264
|
+
var CLI_VERSION = cliPackageVersion;
|
|
16265
|
+
|
|
16266
|
+
// src/api.ts
|
|
16243
16267
|
var OTTO_AUTHORIZATION_HEADER_NAME = "X-Otto-Authorization";
|
|
16244
16268
|
var OTTO_AUTHORIZATION_ISSUER = "magical:otto";
|
|
16245
16269
|
var workosOrganizationsResponseSchema = z23.object({
|
|
@@ -16375,6 +16399,7 @@ function createMagicalApiClient({
|
|
|
16375
16399
|
...organizationId ? { organizationId } : {}
|
|
16376
16400
|
});
|
|
16377
16401
|
headers.set("x-magical-client", "mgcl");
|
|
16402
|
+
headers.set("x-magical-client-version", CLI_VERSION);
|
|
16378
16403
|
const response = await fetchFn(url, {
|
|
16379
16404
|
...init,
|
|
16380
16405
|
headers
|
|
@@ -16520,7 +16545,7 @@ function createMagicalApiClient({
|
|
|
16520
16545
|
|
|
16521
16546
|
// src/config.ts
|
|
16522
16547
|
import os from "node:os";
|
|
16523
|
-
import
|
|
16548
|
+
import path2 from "node:path";
|
|
16524
16549
|
var DEFAULT_MAGICAL_API_URL = "https://api-agt.getmagical.io";
|
|
16525
16550
|
var DEFAULT_WORKOS_API_URL = "https://api.workos.com";
|
|
16526
16551
|
var DEFAULT_WORKOS_CLIENT_ID = "client_01JJZ6XJ1RF248P20WF63M4VAM";
|
|
@@ -16539,33 +16564,33 @@ function resolvePlatformConfigDirectory() {
|
|
|
16539
16564
|
return customConfigDirectory;
|
|
16540
16565
|
}
|
|
16541
16566
|
if (process.platform === "darwin") {
|
|
16542
|
-
return
|
|
16567
|
+
return path2.join(os.homedir(), "Library", "Application Support");
|
|
16543
16568
|
}
|
|
16544
16569
|
if (process.platform === "win32") {
|
|
16545
16570
|
const appDataDirectory = process.env["APPDATA"];
|
|
16546
|
-
return appDataDirectory ??
|
|
16571
|
+
return appDataDirectory ?? path2.join(os.homedir(), "AppData", "Roaming");
|
|
16547
16572
|
}
|
|
16548
|
-
return process.env["XDG_CONFIG_HOME"] ??
|
|
16573
|
+
return process.env["XDG_CONFIG_HOME"] ?? path2.join(os.homedir(), ".config");
|
|
16549
16574
|
}
|
|
16550
16575
|
function resolveRefreshTokenStoreKind() {
|
|
16551
16576
|
return process.env["MAGICAL_CLI_REFRESH_TOKEN_STORE"] === "file" ? "file" : "keytar";
|
|
16552
16577
|
}
|
|
16553
16578
|
function getRuntimeConfig() {
|
|
16554
|
-
const configDirectory =
|
|
16579
|
+
const configDirectory = path2.join(
|
|
16555
16580
|
resolvePlatformConfigDirectory(),
|
|
16556
16581
|
CLI_CONFIG_DIRECTORY_NAME
|
|
16557
16582
|
);
|
|
16558
16583
|
return {
|
|
16559
|
-
accessTokenFilePath:
|
|
16584
|
+
accessTokenFilePath: path2.join(configDirectory, CLI_ACCESS_TOKEN_FILE_NAME),
|
|
16560
16585
|
cliDistTag: process.env["MAGICAL_CLI_DIST_TAG"] ?? DEFAULT_CLI_DIST_TAG,
|
|
16561
16586
|
magicalApiUrl: DEFAULT_MAGICAL_API_URL,
|
|
16562
16587
|
npmRegistryUrl: process.env["MAGICAL_CLI_NPM_REGISTRY_URL"] ?? DEFAULT_CLI_NPM_REGISTRY_URL,
|
|
16563
|
-
refreshTokenFilePath:
|
|
16588
|
+
refreshTokenFilePath: path2.join(
|
|
16564
16589
|
configDirectory,
|
|
16565
16590
|
CLI_REFRESH_TOKEN_FILE_NAME
|
|
16566
16591
|
),
|
|
16567
16592
|
refreshTokenStoreKind: resolveRefreshTokenStoreKind(),
|
|
16568
|
-
stateFilePath:
|
|
16593
|
+
stateFilePath: path2.join(configDirectory, CLI_STATE_FILE_NAME),
|
|
16569
16594
|
workosApiUrl: DEFAULT_WORKOS_API_URL,
|
|
16570
16595
|
workosClientId: DEFAULT_WORKOS_CLIENT_ID,
|
|
16571
16596
|
keychainServiceName: DEFAULT_KEYCHAIN_SERVICE_NAME
|
|
@@ -16577,7 +16602,7 @@ function requireWorkosClientId(config) {
|
|
|
16577
16602
|
|
|
16578
16603
|
// src/settings.ts
|
|
16579
16604
|
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
16580
|
-
import
|
|
16605
|
+
import path3 from "node:path";
|
|
16581
16606
|
import { z as z24 } from "zod";
|
|
16582
16607
|
var cliSettingsSchema = z24.object({
|
|
16583
16608
|
env: z24.object({
|
|
@@ -16593,7 +16618,7 @@ function hasCliSettingsOverrides(settings) {
|
|
|
16593
16618
|
return settings.env.baseUrl !== void 0;
|
|
16594
16619
|
}
|
|
16595
16620
|
function resolveSettingsFilePath(stateFilePath) {
|
|
16596
|
-
return
|
|
16621
|
+
return path3.join(path3.dirname(stateFilePath), CLI_SETTINGS_FILE_NAME);
|
|
16597
16622
|
}
|
|
16598
16623
|
function resolveConfiguredApiBaseUrl({
|
|
16599
16624
|
defaultApiBaseUrl,
|
|
@@ -16638,7 +16663,7 @@ function createFileSettingsStore(stateFilePath) {
|
|
|
16638
16663
|
await rm(settingsFilePath, { force: true });
|
|
16639
16664
|
return;
|
|
16640
16665
|
}
|
|
16641
|
-
await mkdir(
|
|
16666
|
+
await mkdir(path3.dirname(settingsFilePath), { recursive: true });
|
|
16642
16667
|
await writeFile(
|
|
16643
16668
|
settingsFilePath,
|
|
16644
16669
|
`${JSON.stringify(settings, null, 2)}
|
|
@@ -16920,9 +16945,9 @@ function isExpiredAccessTokenClaims(claims) {
|
|
|
16920
16945
|
|
|
16921
16946
|
// src/self-update.ts
|
|
16922
16947
|
import { spawn as spawn2 } from "node:child_process";
|
|
16923
|
-
import
|
|
16924
|
-
import
|
|
16925
|
-
import { fileURLToPath } from "node:url";
|
|
16948
|
+
import fs2 from "node:fs";
|
|
16949
|
+
import path4 from "node:path";
|
|
16950
|
+
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
16926
16951
|
var CLI_PACKAGE_NAME = "@getmagical/cli";
|
|
16927
16952
|
var DEFAULT_CLI_DIST_TAG2 = "latest";
|
|
16928
16953
|
var DEFAULT_NPM_REGISTRY_URL = "https://registry.npmjs.org/";
|
|
@@ -16932,9 +16957,9 @@ function resolveInstalledPackageRoot({
|
|
|
16932
16957
|
packageName
|
|
16933
16958
|
}) {
|
|
16934
16959
|
const packagePathSegments = packageName.split("/");
|
|
16935
|
-
let currentPath =
|
|
16960
|
+
let currentPath = path4.dirname(entryFilePath);
|
|
16936
16961
|
for (; ; ) {
|
|
16937
|
-
const currentPathSegments = currentPath.split(
|
|
16962
|
+
const currentPathSegments = currentPath.split(path4.sep).filter(Boolean);
|
|
16938
16963
|
const currentPackageSegments = currentPathSegments.slice(
|
|
16939
16964
|
-packagePathSegments.length
|
|
16940
16965
|
);
|
|
@@ -16943,7 +16968,7 @@ function resolveInstalledPackageRoot({
|
|
|
16943
16968
|
)) {
|
|
16944
16969
|
return currentPath;
|
|
16945
16970
|
}
|
|
16946
|
-
const parentPath =
|
|
16971
|
+
const parentPath = path4.dirname(currentPath);
|
|
16947
16972
|
if (parentPath === currentPath) {
|
|
16948
16973
|
return null;
|
|
16949
16974
|
}
|
|
@@ -16953,14 +16978,14 @@ function resolveInstalledPackageRoot({
|
|
|
16953
16978
|
function resolveInstallPrefixFromPackageRoot(packageRootPath) {
|
|
16954
16979
|
let currentPath = packageRootPath;
|
|
16955
16980
|
for (; ; ) {
|
|
16956
|
-
if (
|
|
16957
|
-
const nodeModulesParentPath =
|
|
16958
|
-
if (
|
|
16959
|
-
return
|
|
16981
|
+
if (path4.basename(currentPath) === "node_modules") {
|
|
16982
|
+
const nodeModulesParentPath = path4.dirname(currentPath);
|
|
16983
|
+
if (path4.basename(nodeModulesParentPath) === "lib") {
|
|
16984
|
+
return path4.dirname(nodeModulesParentPath);
|
|
16960
16985
|
}
|
|
16961
16986
|
return nodeModulesParentPath;
|
|
16962
16987
|
}
|
|
16963
|
-
const parentPath =
|
|
16988
|
+
const parentPath = path4.dirname(currentPath);
|
|
16964
16989
|
if (parentPath === currentPath) {
|
|
16965
16990
|
return null;
|
|
16966
16991
|
}
|
|
@@ -16977,13 +17002,13 @@ function resolveManagedNpmCommand(installPrefix) {
|
|
|
16977
17002
|
if (process.platform === "win32") {
|
|
16978
17003
|
return null;
|
|
16979
17004
|
}
|
|
16980
|
-
const managedNodeExecutable =
|
|
17005
|
+
const managedNodeExecutable = path4.join(
|
|
16981
17006
|
installPrefix,
|
|
16982
17007
|
MANAGED_NODE_SUBPATH,
|
|
16983
17008
|
"bin",
|
|
16984
17009
|
"node"
|
|
16985
17010
|
);
|
|
16986
|
-
const managedNpmCli =
|
|
17011
|
+
const managedNpmCli = path4.join(
|
|
16987
17012
|
installPrefix,
|
|
16988
17013
|
MANAGED_NODE_SUBPATH,
|
|
16989
17014
|
"lib",
|
|
@@ -16992,7 +17017,7 @@ function resolveManagedNpmCommand(installPrefix) {
|
|
|
16992
17017
|
"bin",
|
|
16993
17018
|
"npm-cli.js"
|
|
16994
17019
|
);
|
|
16995
|
-
if (!
|
|
17020
|
+
if (!fs2.existsSync(managedNodeExecutable) || !fs2.existsSync(managedNpmCli)) {
|
|
16996
17021
|
return null;
|
|
16997
17022
|
}
|
|
16998
17023
|
return {
|
|
@@ -17054,7 +17079,7 @@ async function installPublishedCli({
|
|
|
17054
17079
|
}
|
|
17055
17080
|
async function selfUpdateInstalledCli({
|
|
17056
17081
|
distTag = DEFAULT_CLI_DIST_TAG2,
|
|
17057
|
-
entryFilePath =
|
|
17082
|
+
entryFilePath = fileURLToPath2(import.meta.url),
|
|
17058
17083
|
packageName = CLI_PACKAGE_NAME,
|
|
17059
17084
|
registryUrl = DEFAULT_NPM_REGISTRY_URL
|
|
17060
17085
|
} = {}) {
|
|
@@ -17182,7 +17207,7 @@ ${formatExamples("Examples", [
|
|
|
17182
17207
|
|
|
17183
17208
|
// src/state.ts
|
|
17184
17209
|
import { mkdir as mkdir2, readFile as readFile3, rm as rm3, writeFile as writeFile2 } from "node:fs/promises";
|
|
17185
|
-
import
|
|
17210
|
+
import path5 from "node:path";
|
|
17186
17211
|
import { z as z25 } from "zod";
|
|
17187
17212
|
var cliAccountSchema = z25.object({
|
|
17188
17213
|
clientId: z25.string().min(1),
|
|
@@ -17225,7 +17250,7 @@ function createFileStateStore(stateFilePath) {
|
|
|
17225
17250
|
}
|
|
17226
17251
|
},
|
|
17227
17252
|
async save(state) {
|
|
17228
|
-
await mkdir2(
|
|
17253
|
+
await mkdir2(path5.dirname(stateFilePath), { recursive: true });
|
|
17229
17254
|
await writeFile2(stateFilePath, `${JSON.stringify(state, null, 2)}
|
|
17230
17255
|
`);
|
|
17231
17256
|
}
|
|
@@ -17253,7 +17278,7 @@ function createFileRefreshTokenStore(refreshTokenFilePath) {
|
|
|
17253
17278
|
}
|
|
17254
17279
|
}
|
|
17255
17280
|
async function saveRefreshTokens(refreshTokens) {
|
|
17256
|
-
await mkdir2(
|
|
17281
|
+
await mkdir2(path5.dirname(refreshTokenFilePath), { recursive: true });
|
|
17257
17282
|
await writeFile2(
|
|
17258
17283
|
refreshTokenFilePath,
|
|
17259
17284
|
`${JSON.stringify(refreshTokens, null, 2)}
|
|
@@ -17290,28 +17315,6 @@ function buildRefreshTokenKey(account) {
|
|
|
17290
17315
|
return `${account.clientId}:${account.userId}`;
|
|
17291
17316
|
}
|
|
17292
17317
|
|
|
17293
|
-
// src/version.ts
|
|
17294
|
-
import fs2 from "node:fs";
|
|
17295
|
-
import path5 from "node:path";
|
|
17296
|
-
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
17297
|
-
var packageManifestPath = path5.resolve(
|
|
17298
|
-
path5.dirname(fileURLToPath2(import.meta.url)),
|
|
17299
|
-
"../package.json"
|
|
17300
|
-
);
|
|
17301
|
-
var packageManifestResult = safeJsonParse(
|
|
17302
|
-
fs2.readFileSync(packageManifestPath, "utf8")
|
|
17303
|
-
);
|
|
17304
|
-
if (isErr(packageManifestResult)) {
|
|
17305
|
-
throw new Error(`Failed to parse ${packageManifestPath}.`, {
|
|
17306
|
-
cause: packageManifestResult.error.cause
|
|
17307
|
-
});
|
|
17308
|
-
}
|
|
17309
|
-
var cliPackageVersion = packageManifestResult.value.version;
|
|
17310
|
-
if (typeof cliPackageVersion !== "string" || cliPackageVersion.length === 0) {
|
|
17311
|
-
throw new Error(`Expected a version in ${packageManifestPath}.`);
|
|
17312
|
-
}
|
|
17313
|
-
var CLI_VERSION = cliPackageVersion;
|
|
17314
|
-
|
|
17315
17318
|
// src/workos-auth.ts
|
|
17316
17319
|
import { z as z26 } from "zod";
|
|
17317
17320
|
var DEFAULT_DEVICE_POLL_INTERVAL_SECONDS = 5;
|