@objectstack/cli 4.0.3 → 4.0.5
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/README.md +12 -25
- package/dist/commands/build.d.ts +5 -0
- package/dist/commands/build.d.ts.map +1 -0
- package/dist/commands/build.js +6 -0
- package/dist/commands/build.js.map +1 -0
- package/dist/commands/compile.d.ts +3 -0
- package/dist/commands/compile.d.ts.map +1 -1
- package/dist/commands/compile.js +128 -6
- package/dist/commands/compile.js.map +1 -1
- package/dist/commands/create.js +1 -1
- package/dist/commands/data/create.js +2 -2
- package/dist/commands/data/create.js.map +1 -1
- package/dist/commands/data/delete.js +2 -2
- package/dist/commands/data/delete.js.map +1 -1
- package/dist/commands/data/get.js +2 -2
- package/dist/commands/data/get.js.map +1 -1
- package/dist/commands/data/query.js +2 -2
- package/dist/commands/data/query.js.map +1 -1
- package/dist/commands/data/update.js +2 -2
- package/dist/commands/data/update.js.map +1 -1
- package/dist/commands/dev.d.ts +3 -0
- package/dist/commands/dev.d.ts.map +1 -1
- package/dist/commands/dev.js +48 -19
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/generate.js +9 -9
- package/dist/commands/generate.js.map +1 -1
- package/dist/commands/i18n/check.d.ts +18 -0
- package/dist/commands/i18n/check.d.ts.map +1 -0
- package/dist/commands/i18n/check.js +153 -0
- package/dist/commands/i18n/check.js.map +1 -0
- package/dist/commands/init.js +2 -2
- package/dist/commands/lint.d.ts +3 -0
- package/dist/commands/lint.d.ts.map +1 -1
- package/dist/commands/lint.js +24 -0
- package/dist/commands/lint.js.map +1 -1
- package/dist/commands/login.d.ts +17 -0
- package/dist/commands/login.d.ts.map +1 -0
- package/dist/commands/login.js +313 -0
- package/dist/commands/login.js.map +1 -0
- package/dist/commands/logout.d.ts.map +1 -0
- package/dist/commands/{auth/logout.js → logout.js} +14 -2
- package/dist/commands/logout.js.map +1 -0
- package/dist/commands/meta/delete.js +2 -2
- package/dist/commands/meta/delete.js.map +1 -1
- package/dist/commands/meta/get.js +2 -2
- package/dist/commands/meta/get.js.map +1 -1
- package/dist/commands/meta/list.js +2 -2
- package/dist/commands/meta/list.js.map +1 -1
- package/dist/commands/meta/register.js +2 -2
- package/dist/commands/meta/register.js.map +1 -1
- package/dist/commands/projects/bind.d.ts +30 -0
- package/dist/commands/projects/bind.d.ts.map +1 -0
- package/dist/commands/projects/bind.js +132 -0
- package/dist/commands/projects/bind.js.map +1 -0
- package/dist/commands/projects/create.d.ts +28 -0
- package/dist/commands/projects/create.d.ts.map +1 -0
- package/dist/commands/projects/create.js +120 -0
- package/dist/commands/projects/create.js.map +1 -0
- package/dist/commands/projects/list.d.ts +21 -0
- package/dist/commands/projects/list.d.ts.map +1 -0
- package/dist/commands/projects/list.js +79 -0
- package/dist/commands/projects/list.js.map +1 -0
- package/dist/commands/projects/projects.test.d.ts +2 -0
- package/dist/commands/projects/projects.test.d.ts.map +1 -0
- package/dist/commands/projects/projects.test.js +56 -0
- package/dist/commands/projects/projects.test.js.map +1 -0
- package/dist/commands/projects/show.d.ts +21 -0
- package/dist/commands/projects/show.d.ts.map +1 -0
- package/dist/commands/projects/show.js +72 -0
- package/dist/commands/projects/show.js.map +1 -0
- package/dist/commands/projects/switch.d.ts +24 -0
- package/dist/commands/projects/switch.d.ts.map +1 -0
- package/dist/commands/projects/switch.js +64 -0
- package/dist/commands/projects/switch.js.map +1 -0
- package/dist/commands/publish.d.ts +14 -0
- package/dist/commands/publish.d.ts.map +1 -0
- package/dist/commands/publish.js +91 -0
- package/dist/commands/publish.js.map +1 -0
- package/dist/commands/{auth/login.d.ts → register.d.ts} +3 -2
- package/dist/commands/register.d.ts.map +1 -0
- package/dist/commands/{auth/login.js → register.js} +44 -61
- package/dist/commands/register.js.map +1 -0
- package/dist/commands/serve.d.ts +8 -0
- package/dist/commands/serve.d.ts.map +1 -1
- package/dist/commands/serve.js +606 -44
- package/dist/commands/serve.js.map +1 -1
- package/dist/commands/start.d.ts +11 -0
- package/dist/commands/start.d.ts.map +1 -0
- package/dist/commands/start.js +43 -0
- package/dist/commands/start.js.map +1 -0
- package/dist/commands/whoami.d.ts.map +1 -0
- package/dist/commands/{auth/whoami.js → whoami.js} +5 -5
- package/dist/commands/whoami.js.map +1 -0
- package/dist/index.d.ts +7 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -5
- package/dist/index.js.map +1 -1
- package/dist/utils/account.d.ts +31 -0
- package/dist/utils/account.d.ts.map +1 -0
- package/dist/utils/account.js +154 -0
- package/dist/utils/account.js.map +1 -0
- package/dist/utils/api-client.d.ts +10 -4
- package/dist/utils/api-client.d.ts.map +1 -1
- package/dist/utils/api-client.js +13 -7
- package/dist/utils/api-client.js.map +1 -1
- package/dist/utils/auth-config.d.ts +6 -0
- package/dist/utils/auth-config.d.ts.map +1 -1
- package/dist/utils/auth-config.js.map +1 -1
- package/dist/utils/build-runtime.d.ts +45 -0
- package/dist/utils/build-runtime.d.ts.map +1 -0
- package/dist/utils/build-runtime.js +154 -0
- package/dist/utils/build-runtime.js.map +1 -0
- package/dist/utils/config.d.ts.map +1 -1
- package/dist/utils/config.js +17 -2
- package/dist/utils/config.js.map +1 -1
- package/dist/utils/console.d.ts +32 -0
- package/dist/utils/console.d.ts.map +1 -0
- package/dist/utils/console.js +169 -0
- package/dist/utils/console.js.map +1 -0
- package/dist/utils/extract-hook-body.d.ts +13 -0
- package/dist/utils/extract-hook-body.d.ts.map +1 -0
- package/dist/utils/extract-hook-body.js +175 -0
- package/dist/utils/extract-hook-body.js.map +1 -0
- package/dist/utils/format.d.ts +8 -0
- package/dist/utils/format.d.ts.map +1 -1
- package/dist/utils/format.js +15 -2
- package/dist/utils/format.js.map +1 -1
- package/dist/utils/i18n-coverage.d.ts +61 -0
- package/dist/utils/i18n-coverage.d.ts.map +1 -0
- package/dist/utils/i18n-coverage.js +176 -0
- package/dist/utils/i18n-coverage.js.map +1 -0
- package/dist/utils/lower-callables.d.ts +17 -0
- package/dist/utils/lower-callables.d.ts.map +1 -0
- package/dist/utils/lower-callables.js +181 -0
- package/dist/utils/lower-callables.js.map +1 -0
- package/dist/utils/plugin-detection.d.ts +1 -0
- package/dist/utils/plugin-detection.d.ts.map +1 -1
- package/dist/utils/plugin-detection.js +41 -0
- package/dist/utils/plugin-detection.js.map +1 -1
- package/dist/utils/studio.d.ts +1 -0
- package/dist/utils/studio.d.ts.map +1 -1
- package/dist/utils/studio.js +25 -9
- package/dist/utils/studio.js.map +1 -1
- package/package.json +55 -21
- package/.turbo/turbo-build.log +0 -4
- package/CHANGELOG.md +0 -805
- package/bin/run-dev.js +0 -5
- package/dist/commands/auth/login.d.ts.map +0 -1
- package/dist/commands/auth/login.js.map +0 -1
- package/dist/commands/auth/logout.d.ts.map +0 -1
- package/dist/commands/auth/logout.js.map +0 -1
- package/dist/commands/auth/whoami.d.ts.map +0 -1
- package/dist/commands/auth/whoami.js.map +0 -1
- package/dist/commands/codemod/v2-to-v3.d.ts +0 -10
- package/dist/commands/codemod/v2-to-v3.d.ts.map +0 -1
- package/dist/commands/codemod/v2-to-v3.js +0 -145
- package/dist/commands/codemod/v2-to-v3.js.map +0 -1
- package/dist/commands/plugin/add.d.ts +0 -22
- package/dist/commands/plugin/add.d.ts.map +0 -1
- package/dist/commands/plugin/add.js +0 -93
- package/dist/commands/plugin/add.js.map +0 -1
- package/dist/commands/plugin/build.d.ts +0 -29
- package/dist/commands/plugin/build.d.ts.map +0 -1
- package/dist/commands/plugin/build.js +0 -170
- package/dist/commands/plugin/build.js.map +0 -1
- package/dist/commands/plugin/info.d.ts +0 -10
- package/dist/commands/plugin/info.d.ts.map +0 -1
- package/dist/commands/plugin/info.js +0 -65
- package/dist/commands/plugin/info.js.map +0 -1
- package/dist/commands/plugin/list.d.ts +0 -13
- package/dist/commands/plugin/list.d.ts.map +0 -1
- package/dist/commands/plugin/list.js +0 -78
- package/dist/commands/plugin/list.js.map +0 -1
- package/dist/commands/plugin/publish.d.ts +0 -27
- package/dist/commands/plugin/publish.d.ts.map +0 -1
- package/dist/commands/plugin/publish.js +0 -152
- package/dist/commands/plugin/publish.js.map +0 -1
- package/dist/commands/plugin/remove.d.ts +0 -20
- package/dist/commands/plugin/remove.d.ts.map +0 -1
- package/dist/commands/plugin/remove.js +0 -79
- package/dist/commands/plugin/remove.js.map +0 -1
- package/dist/commands/plugin/validate.d.ts +0 -23
- package/dist/commands/plugin/validate.d.ts.map +0 -1
- package/dist/commands/plugin/validate.js +0 -251
- package/dist/commands/plugin/validate.js.map +0 -1
- package/src/bin.ts +0 -13
- package/src/commands/auth/login.ts +0 -188
- package/src/commands/auth/logout.ts +0 -51
- package/src/commands/auth/whoami.ts +0 -85
- package/src/commands/codemod/v2-to-v3.ts +0 -171
- package/src/commands/compile.ts +0 -114
- package/src/commands/create.ts +0 -281
- package/src/commands/data/create.ts +0 -110
- package/src/commands/data/delete.ts +0 -84
- package/src/commands/data/get.ts +0 -84
- package/src/commands/data/query.ts +0 -127
- package/src/commands/data/update.ts +0 -114
- package/src/commands/dev.ts +0 -83
- package/src/commands/diff.ts +0 -294
- package/src/commands/doctor.ts +0 -572
- package/src/commands/explain.ts +0 -412
- package/src/commands/generate.ts +0 -924
- package/src/commands/info.ts +0 -124
- package/src/commands/init.ts +0 -327
- package/src/commands/lint.ts +0 -315
- package/src/commands/meta/delete.ts +0 -79
- package/src/commands/meta/get.ts +0 -73
- package/src/commands/meta/list.ts +0 -105
- package/src/commands/meta/register.ts +0 -97
- package/src/commands/plugin/add.ts +0 -112
- package/src/commands/plugin/build.ts +0 -193
- package/src/commands/plugin/info.ts +0 -79
- package/src/commands/plugin/list.ts +0 -93
- package/src/commands/plugin/publish.ts +0 -176
- package/src/commands/plugin/remove.ts +0 -97
- package/src/commands/plugin/validate.ts +0 -268
- package/src/commands/serve.ts +0 -411
- package/src/commands/studio.ts +0 -52
- package/src/commands/test.ts +0 -135
- package/src/commands/validate.ts +0 -143
- package/src/index.ts +0 -22
- package/src/utils/api-client.ts +0 -88
- package/src/utils/auth-config.ts +0 -107
- package/src/utils/config.ts +0 -80
- package/src/utils/format.ts +0 -267
- package/src/utils/output-formatter.ts +0 -91
- package/src/utils/plugin-detection.ts +0 -16
- package/src/utils/plugin-helpers.ts +0 -37
- package/src/utils/studio.ts +0 -350
- package/test/commands.test.ts +0 -128
- package/test/create.test.ts +0 -25
- package/test/plugin-commands.test.ts +0 -44
- package/test/plugin.test.ts +0 -169
- package/test/remote-api-commands.test.ts +0 -188
- package/test/remote-api-utils.test.ts +0 -196
- package/test/serve-host-config.test.ts +0 -77
- package/tsconfig.build.json +0 -20
- package/tsconfig.json +0 -25
- package/tsup.config.ts +0 -23
- /package/dist/commands/{auth/logout.d.ts → logout.d.ts} +0 -0
- /package/dist/commands/{auth/whoami.d.ts → whoami.d.ts} +0 -0
package/src/commands/validate.ts
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
|
|
2
|
-
|
|
3
|
-
import { Args, Command, Flags } from '@oclif/core';
|
|
4
|
-
import chalk from 'chalk';
|
|
5
|
-
import { ZodError } from 'zod';
|
|
6
|
-
import { ObjectStackDefinitionSchema, normalizeStackInput } from '@objectstack/spec';
|
|
7
|
-
import { loadConfig } from '../utils/config.js';
|
|
8
|
-
import {
|
|
9
|
-
printHeader,
|
|
10
|
-
printKV,
|
|
11
|
-
printSuccess,
|
|
12
|
-
printError,
|
|
13
|
-
printStep,
|
|
14
|
-
createTimer,
|
|
15
|
-
formatZodErrors,
|
|
16
|
-
collectMetadataStats,
|
|
17
|
-
printMetadataStats,
|
|
18
|
-
} from '../utils/format.js';
|
|
19
|
-
|
|
20
|
-
export default class Validate extends Command {
|
|
21
|
-
static override description = 'Validate ObjectStack configuration against the protocol schema';
|
|
22
|
-
|
|
23
|
-
static override args = {
|
|
24
|
-
config: Args.string({ description: 'Configuration file path', required: false }),
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
static override flags = {
|
|
28
|
-
strict: Flags.boolean({ description: 'Treat warnings as errors' }),
|
|
29
|
-
json: Flags.boolean({ description: 'Output results as JSON' }),
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
async run(): Promise<void> {
|
|
33
|
-
const { args, flags } = await this.parse(Validate);
|
|
34
|
-
|
|
35
|
-
const timer = createTimer();
|
|
36
|
-
|
|
37
|
-
if (!flags.json) {
|
|
38
|
-
printHeader('Validate');
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
try {
|
|
42
|
-
// 1. Load configuration
|
|
43
|
-
if (!flags.json) printStep('Loading configuration...');
|
|
44
|
-
const { config, absolutePath, duration } = await loadConfig(args.config);
|
|
45
|
-
|
|
46
|
-
if (!flags.json) {
|
|
47
|
-
printKV('Config', absolutePath);
|
|
48
|
-
printKV('Load time', `${duration}ms`);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// 2. Normalize map-formatted stack definition and validate against schema
|
|
52
|
-
if (!flags.json) printStep('Validating against ObjectStack Protocol...');
|
|
53
|
-
const normalized = normalizeStackInput(config as Record<string, unknown>);
|
|
54
|
-
const result = ObjectStackDefinitionSchema.safeParse(normalized);
|
|
55
|
-
|
|
56
|
-
if (!result.success) {
|
|
57
|
-
if (flags.json) {
|
|
58
|
-
console.log(JSON.stringify({
|
|
59
|
-
valid: false,
|
|
60
|
-
errors: (result.error as unknown as ZodError).issues,
|
|
61
|
-
duration: timer.elapsed(),
|
|
62
|
-
}, null, 2));
|
|
63
|
-
this.exit(1);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
console.log('');
|
|
67
|
-
printError('Validation failed');
|
|
68
|
-
formatZodErrors(result.error as unknown as ZodError);
|
|
69
|
-
this.exit(1);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// 3. Collect and display stats
|
|
73
|
-
const stats = collectMetadataStats(config);
|
|
74
|
-
|
|
75
|
-
if (flags.json) {
|
|
76
|
-
console.log(JSON.stringify({
|
|
77
|
-
valid: true,
|
|
78
|
-
manifest: config.manifest,
|
|
79
|
-
stats,
|
|
80
|
-
duration: timer.elapsed(),
|
|
81
|
-
}, null, 2));
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// 4. Warnings (non-blocking)
|
|
86
|
-
const warnings: string[] = [];
|
|
87
|
-
|
|
88
|
-
if (stats.objects === 0) {
|
|
89
|
-
warnings.push('No objects defined — this stack has no data model');
|
|
90
|
-
}
|
|
91
|
-
if (stats.apps === 0 && stats.plugins === 0) {
|
|
92
|
-
warnings.push('No apps or plugins defined — this stack may not do much');
|
|
93
|
-
}
|
|
94
|
-
if (!config.manifest?.id) {
|
|
95
|
-
warnings.push('Missing manifest.id — required for deployment');
|
|
96
|
-
}
|
|
97
|
-
if (!config.manifest?.namespace) {
|
|
98
|
-
warnings.push('Missing manifest.namespace — required for multi-app hosting');
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// 5. Display results
|
|
102
|
-
console.log('');
|
|
103
|
-
printSuccess(`Validation passed ${chalk.dim(`(${timer.display()})`)}`);
|
|
104
|
-
console.log('');
|
|
105
|
-
|
|
106
|
-
if (config.manifest) {
|
|
107
|
-
console.log(` ${chalk.bold(config.manifest.name || config.manifest.id || 'Unnamed')} ${chalk.dim(`v${config.manifest.version || '0.0.0'}`)}`);
|
|
108
|
-
if (config.manifest.description) {
|
|
109
|
-
console.log(chalk.dim(` ${config.manifest.description}`));
|
|
110
|
-
}
|
|
111
|
-
console.log('');
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
printMetadataStats(stats);
|
|
115
|
-
|
|
116
|
-
if (warnings.length > 0) {
|
|
117
|
-
console.log('');
|
|
118
|
-
for (const w of warnings) {
|
|
119
|
-
console.log(chalk.yellow(` ⚠ ${w}`));
|
|
120
|
-
}
|
|
121
|
-
if (flags.strict) {
|
|
122
|
-
console.log('');
|
|
123
|
-
printError('Strict mode: warnings treated as errors');
|
|
124
|
-
this.exit(1);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
console.log('');
|
|
129
|
-
} catch (error: any) {
|
|
130
|
-
if (flags.json) {
|
|
131
|
-
console.log(JSON.stringify({
|
|
132
|
-
valid: false,
|
|
133
|
-
error: error.message,
|
|
134
|
-
duration: timer.elapsed(),
|
|
135
|
-
}, null, 2));
|
|
136
|
-
this.exit(1);
|
|
137
|
-
}
|
|
138
|
-
console.log('');
|
|
139
|
-
printError(error.message || String(error));
|
|
140
|
-
this.exit(1);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
|
|
2
|
-
|
|
3
|
-
// ─── oclif Command Classes ──────────────────────────────────────────
|
|
4
|
-
// Each command is auto-discovered by oclif from `src/commands/`.
|
|
5
|
-
// These re-exports provide programmatic access for testing and integration.
|
|
6
|
-
|
|
7
|
-
export { default as CompileCommand } from './commands/compile.js';
|
|
8
|
-
export { default as ValidateCommand } from './commands/validate.js';
|
|
9
|
-
export { default as InfoCommand } from './commands/info.js';
|
|
10
|
-
export { default as InitCommand } from './commands/init.js';
|
|
11
|
-
export { default as GenerateCommand } from './commands/generate.js';
|
|
12
|
-
export { default as CreateCommand } from './commands/create.js';
|
|
13
|
-
export { default as DevCommand } from './commands/dev.js';
|
|
14
|
-
export { default as ServeCommand } from './commands/serve.js';
|
|
15
|
-
export { default as TestCommand } from './commands/test.js';
|
|
16
|
-
export { default as DoctorCommand } from './commands/doctor.js';
|
|
17
|
-
|
|
18
|
-
// ─── Plugin topic subcommands ───────────────────────────────────────
|
|
19
|
-
export { default as PluginListCommand } from './commands/plugin/list.js';
|
|
20
|
-
export { default as PluginInfoCommand } from './commands/plugin/info.js';
|
|
21
|
-
export { default as PluginAddCommand } from './commands/plugin/add.js';
|
|
22
|
-
export { default as PluginRemoveCommand } from './commands/plugin/remove.js';
|
package/src/utils/api-client.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
|
|
2
|
-
|
|
3
|
-
import { ObjectStackClient } from '@objectstack/client';
|
|
4
|
-
import { readAuthConfig } from './auth-config.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* API client configuration options for CLI commands
|
|
8
|
-
*/
|
|
9
|
-
export interface ApiClientOptions {
|
|
10
|
-
/**
|
|
11
|
-
* Server URL (defaults to OBJECTSTACK_URL env var or http://localhost:3000)
|
|
12
|
-
*/
|
|
13
|
-
url?: string;
|
|
14
|
-
/**
|
|
15
|
-
* Authentication token (defaults to stored credentials or OBJECTSTACK_TOKEN env var)
|
|
16
|
-
*/
|
|
17
|
-
token?: string;
|
|
18
|
-
/**
|
|
19
|
-
* Enable debug logging
|
|
20
|
-
*/
|
|
21
|
-
debug?: boolean;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Result returned by createApiClient — exposes the resolved token so commands
|
|
26
|
-
* can call requireAuth() without accessing private client fields.
|
|
27
|
-
*/
|
|
28
|
-
export interface ApiClientResult {
|
|
29
|
-
client: ObjectStackClient;
|
|
30
|
-
token?: string;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Create an authenticated ObjectStack API client for CLI commands.
|
|
35
|
-
*
|
|
36
|
-
* Resolves configuration in this priority order:
|
|
37
|
-
* 1. Explicit options passed to the function
|
|
38
|
-
* 2. Environment variables (OBJECTSTACK_URL, OBJECTSTACK_TOKEN)
|
|
39
|
-
* 3. Stored credentials from `os auth login`
|
|
40
|
-
* 4. Defaults (http://localhost:3000)
|
|
41
|
-
*/
|
|
42
|
-
export async function createApiClient(options: ApiClientOptions = {}): Promise<ApiClientResult> {
|
|
43
|
-
// Resolve server URL (without applying defaults yet)
|
|
44
|
-
let baseUrl = options.url || process.env.OBJECTSTACK_URL;
|
|
45
|
-
|
|
46
|
-
// Resolve authentication token
|
|
47
|
-
let token = options.token || process.env.OBJECTSTACK_TOKEN;
|
|
48
|
-
|
|
49
|
-
// If URL or token is missing, try to load from stored credentials
|
|
50
|
-
if (!baseUrl || !token) {
|
|
51
|
-
try {
|
|
52
|
-
const authConfig = await readAuthConfig();
|
|
53
|
-
if (!token && authConfig.token) {
|
|
54
|
-
token = authConfig.token;
|
|
55
|
-
}
|
|
56
|
-
if (!baseUrl && authConfig.url) {
|
|
57
|
-
baseUrl = authConfig.url;
|
|
58
|
-
}
|
|
59
|
-
} catch {
|
|
60
|
-
// No stored credentials - commands will fail if auth is required
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// Apply final default for baseUrl if still not resolved
|
|
65
|
-
if (!baseUrl) {
|
|
66
|
-
baseUrl = 'http://localhost:3000';
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const client = new ObjectStackClient({
|
|
70
|
-
baseUrl,
|
|
71
|
-
token,
|
|
72
|
-
debug: options.debug || false,
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
return { client, token };
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Ensure authentication is present, throwing an error if not.
|
|
80
|
-
* Use this in commands that require authentication.
|
|
81
|
-
*/
|
|
82
|
-
export function requireAuth(token?: string): void {
|
|
83
|
-
if (!token) {
|
|
84
|
-
throw new Error(
|
|
85
|
-
'Authentication required. Please run `os auth login` or set OBJECTSTACK_TOKEN environment variable.'
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
}
|
package/src/utils/auth-config.ts
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
|
|
2
|
-
|
|
3
|
-
import { homedir } from 'node:os';
|
|
4
|
-
import { join } from 'node:path';
|
|
5
|
-
import { readFile, writeFile, mkdir, chmod } from 'node:fs/promises';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Authentication configuration stored in ~/.objectstack/credentials.json
|
|
9
|
-
*/
|
|
10
|
-
export interface AuthConfig {
|
|
11
|
-
/**
|
|
12
|
-
* Server URL (base URL for the ObjectStack instance)
|
|
13
|
-
*/
|
|
14
|
-
url: string;
|
|
15
|
-
/**
|
|
16
|
-
* Authentication token (Bearer token)
|
|
17
|
-
*/
|
|
18
|
-
token: string;
|
|
19
|
-
/**
|
|
20
|
-
* User email (for display purposes)
|
|
21
|
-
*/
|
|
22
|
-
email?: string;
|
|
23
|
-
/**
|
|
24
|
-
* User ID
|
|
25
|
-
*/
|
|
26
|
-
userId?: string;
|
|
27
|
-
/**
|
|
28
|
-
* Timestamp when credentials were created
|
|
29
|
-
*/
|
|
30
|
-
createdAt: string;
|
|
31
|
-
/**
|
|
32
|
-
* Timestamp when credentials were last used
|
|
33
|
-
*/
|
|
34
|
-
lastUsedAt?: string;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Get the path to the credentials file
|
|
39
|
-
*/
|
|
40
|
-
export function getCredentialsPath(): string {
|
|
41
|
-
return join(homedir(), '.objectstack', 'credentials.json');
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Read stored authentication configuration
|
|
46
|
-
*/
|
|
47
|
-
export async function readAuthConfig(): Promise<AuthConfig> {
|
|
48
|
-
const path = getCredentialsPath();
|
|
49
|
-
try {
|
|
50
|
-
const content = await readFile(path, 'utf-8');
|
|
51
|
-
return JSON.parse(content) as AuthConfig;
|
|
52
|
-
} catch (error: any) {
|
|
53
|
-
if (error.code === 'ENOENT') {
|
|
54
|
-
throw new Error('No stored credentials found. Please run `os auth login` first.');
|
|
55
|
-
}
|
|
56
|
-
throw new Error(`Failed to read credentials: ${error.message}`);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Write authentication configuration
|
|
62
|
-
*/
|
|
63
|
-
export async function writeAuthConfig(config: AuthConfig): Promise<void> {
|
|
64
|
-
const path = getCredentialsPath();
|
|
65
|
-
const dir = join(homedir(), '.objectstack');
|
|
66
|
-
|
|
67
|
-
// Ensure directory exists
|
|
68
|
-
await mkdir(dir, { recursive: true });
|
|
69
|
-
|
|
70
|
-
// Write credentials file
|
|
71
|
-
await writeFile(path, JSON.stringify(config, null, 2), { mode: 0o600 });
|
|
72
|
-
|
|
73
|
-
// Explicitly enforce permissions in case the file already existed with broader perms
|
|
74
|
-
try {
|
|
75
|
-
await chmod(path, 0o600);
|
|
76
|
-
} catch {
|
|
77
|
-
// Best-effort — platforms that don't support chmod will silently continue
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Delete stored authentication configuration
|
|
83
|
-
*/
|
|
84
|
-
export async function deleteAuthConfig(): Promise<void> {
|
|
85
|
-
const path = getCredentialsPath();
|
|
86
|
-
try {
|
|
87
|
-
const { unlink } = await import('node:fs/promises');
|
|
88
|
-
await unlink(path);
|
|
89
|
-
} catch (error: any) {
|
|
90
|
-
if (error.code !== 'ENOENT') {
|
|
91
|
-
throw new Error(`Failed to delete credentials: ${error.message}`);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Update last used timestamp
|
|
98
|
-
*/
|
|
99
|
-
export async function touchAuthConfig(): Promise<void> {
|
|
100
|
-
try {
|
|
101
|
-
const config = await readAuthConfig();
|
|
102
|
-
config.lastUsedAt = new Date().toISOString();
|
|
103
|
-
await writeAuthConfig(config);
|
|
104
|
-
} catch {
|
|
105
|
-
// Ignore errors - this is best-effort
|
|
106
|
-
}
|
|
107
|
-
}
|
package/src/utils/config.ts
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
|
|
2
|
-
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import fs from 'fs';
|
|
5
|
-
import chalk from 'chalk';
|
|
6
|
-
import { bundleRequire } from 'bundle-require';
|
|
7
|
-
import { printError } from './format.js';
|
|
8
|
-
|
|
9
|
-
export interface LoadedConfig {
|
|
10
|
-
config: any;
|
|
11
|
-
absolutePath: string;
|
|
12
|
-
duration: number;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Resolve the config file path. Supports:
|
|
17
|
-
* - explicit path (objectstack.config.ts)
|
|
18
|
-
* - auto-detection (searches for objectstack.config.{ts,js,mjs})
|
|
19
|
-
*/
|
|
20
|
-
export function resolveConfigPath(source?: string): string {
|
|
21
|
-
if (source) {
|
|
22
|
-
const abs = path.resolve(process.cwd(), source);
|
|
23
|
-
if (!fs.existsSync(abs)) {
|
|
24
|
-
printError(`Config file not found: ${chalk.white(abs)}`);
|
|
25
|
-
console.log('');
|
|
26
|
-
console.log(chalk.dim(' Hint: Run this command from a directory with objectstack.config.ts'));
|
|
27
|
-
console.log(chalk.dim(' Or specify the path: objectstack <command> path/to/config.ts'));
|
|
28
|
-
process.exit(1);
|
|
29
|
-
}
|
|
30
|
-
return abs;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Auto-detect
|
|
34
|
-
const candidates = [
|
|
35
|
-
'objectstack.config.ts',
|
|
36
|
-
'objectstack.config.js',
|
|
37
|
-
'objectstack.config.mjs',
|
|
38
|
-
];
|
|
39
|
-
|
|
40
|
-
for (const candidate of candidates) {
|
|
41
|
-
const abs = path.resolve(process.cwd(), candidate);
|
|
42
|
-
if (fs.existsSync(abs)) return abs;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
printError('No objectstack.config.{ts,js,mjs} found in current directory');
|
|
46
|
-
console.log('');
|
|
47
|
-
console.log(chalk.dim(' Hint: Run `objectstack init` to create a new project'));
|
|
48
|
-
process.exit(1);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Load and bundle a config file using bundle-require.
|
|
53
|
-
* Returns the resolved config object and load time.
|
|
54
|
-
*/
|
|
55
|
-
export async function loadConfig(source?: string): Promise<LoadedConfig> {
|
|
56
|
-
const absolutePath = resolveConfigPath(source);
|
|
57
|
-
const start = Date.now();
|
|
58
|
-
|
|
59
|
-
const { mod } = await bundleRequire({
|
|
60
|
-
filepath: absolutePath,
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
const config = mod.default || mod;
|
|
64
|
-
if (!config) {
|
|
65
|
-
throw new Error(`No default export found in ${path.basename(absolutePath)}`);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return {
|
|
69
|
-
config,
|
|
70
|
-
absolutePath,
|
|
71
|
-
duration: Date.now() - start,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Check whether a file exists at the given path (relative to cwd).
|
|
77
|
-
*/
|
|
78
|
-
export function configExists(name: string = 'objectstack.config.ts'): boolean {
|
|
79
|
-
return fs.existsSync(path.resolve(process.cwd(), name));
|
|
80
|
-
}
|