@objectstack/cli 4.0.4 → 4.1.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/README.md +44 -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/cloud/login.d.ts +16 -0
- package/dist/commands/cloud/login.d.ts.map +1 -0
- package/dist/commands/cloud/login.js +166 -0
- package/dist/commands/cloud/login.js.map +1 -0
- package/dist/commands/cloud/logout.d.ts +15 -0
- package/dist/commands/cloud/logout.d.ts.map +1 -0
- package/dist/commands/cloud/logout.js +51 -0
- package/dist/commands/cloud/logout.js.map +1 -0
- package/dist/commands/cloud/whoami.d.ts +15 -0
- package/dist/commands/cloud/whoami.d.ts.map +1 -0
- package/dist/commands/cloud/whoami.js +81 -0
- package/dist/commands/cloud/whoami.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 +9 -0
- package/dist/commands/dev.d.ts.map +1 -1
- package/dist/commands/dev.js +116 -22
- 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/package/publish.d.ts +32 -0
- package/dist/commands/package/publish.d.ts.map +1 -0
- package/dist/commands/package/publish.js +324 -0
- package/dist/commands/package/publish.js.map +1 -0
- 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 +17 -0
- package/dist/commands/publish.d.ts.map +1 -0
- package/dist/commands/publish.js +135 -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/rollback.d.ts +13 -0
- package/dist/commands/rollback.d.ts.map +1 -0
- package/dist/commands/rollback.js +77 -0
- package/dist/commands/rollback.js.map +1 -0
- package/dist/commands/serve.d.ts +22 -0
- package/dist/commands/serve.d.ts.map +1 -1
- package/dist/commands/serve.js +1173 -58
- package/dist/commands/serve.js.map +1 -1
- package/dist/commands/start.d.ts +18 -0
- package/dist/commands/start.d.ts.map +1 -0
- package/dist/commands/start.js +112 -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 +11 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -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/auth-flows.d.ts +31 -0
- package/dist/utils/auth-flows.d.ts.map +1 -0
- package/dist/utils/auth-flows.js +151 -0
- package/dist/utils/auth-flows.js.map +1 -0
- 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/cloud-config.d.ts +24 -0
- package/dist/utils/cloud-config.d.ts.map +1 -0
- package/dist/utils/cloud-config.js +75 -0
- package/dist/utils/cloud-config.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 +33 -0
- package/dist/utils/console.d.ts.map +1 -0
- package/dist/utils/console.js +172 -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 +24 -9
- package/dist/utils/studio.js.map +1 -1
- package/package.json +60 -22
- package/.turbo/turbo-build.log +0 -4
- package/CHANGELOG.md +0 -821
- 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
|
@@ -4,13 +4,18 @@ import { ObjectStackClient } from '@objectstack/client';
|
|
|
4
4
|
*/
|
|
5
5
|
export interface ApiClientOptions {
|
|
6
6
|
/**
|
|
7
|
-
* Server URL (defaults to
|
|
7
|
+
* Server URL (defaults to OS_CLOUD_URL env var or http://localhost:3000)
|
|
8
8
|
*/
|
|
9
9
|
url?: string;
|
|
10
10
|
/**
|
|
11
|
-
* Authentication token (defaults to stored credentials or
|
|
11
|
+
* Authentication token (defaults to stored credentials or OS_TOKEN env var)
|
|
12
12
|
*/
|
|
13
13
|
token?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Explicit project id. Overrides the stored `activeProjectId` from
|
|
16
|
+
* `~/.objectstack/credentials.json` (written by `os projects switch`).
|
|
17
|
+
*/
|
|
18
|
+
projectId?: string;
|
|
14
19
|
/**
|
|
15
20
|
* Enable debug logging
|
|
16
21
|
*/
|
|
@@ -23,14 +28,15 @@ export interface ApiClientOptions {
|
|
|
23
28
|
export interface ApiClientResult {
|
|
24
29
|
client: ObjectStackClient;
|
|
25
30
|
token?: string;
|
|
31
|
+
projectId?: string;
|
|
26
32
|
}
|
|
27
33
|
/**
|
|
28
34
|
* Create an authenticated ObjectStack API client for CLI commands.
|
|
29
35
|
*
|
|
30
36
|
* Resolves configuration in this priority order:
|
|
31
37
|
* 1. Explicit options passed to the function
|
|
32
|
-
* 2. Environment variables (
|
|
33
|
-
* 3. Stored credentials from `os
|
|
38
|
+
* 2. Environment variables (OS_CLOUD_URL, OS_TOKEN)
|
|
39
|
+
* 3. Stored credentials from `os login`
|
|
34
40
|
* 4. Defaults (http://localhost:3000)
|
|
35
41
|
*/
|
|
36
42
|
export declare function createApiClient(options?: ApiClientOptions): Promise<ApiClientResult>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-client.d.ts","sourceRoot":"","sources":["../../src/utils/api-client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAGxD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,iBAAiB,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"api-client.d.ts","sourceRoot":"","sources":["../../src/utils/api-client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAGxD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,iBAAiB,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;GAQG;AACH,wBAAsB,eAAe,CAAC,OAAO,GAAE,gBAAqB,GAAG,OAAO,CAAC,eAAe,CAAC,CAyC9F;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAMhD"}
|
package/dist/utils/api-client.js
CHANGED
|
@@ -6,17 +6,19 @@ import { readAuthConfig } from './auth-config.js';
|
|
|
6
6
|
*
|
|
7
7
|
* Resolves configuration in this priority order:
|
|
8
8
|
* 1. Explicit options passed to the function
|
|
9
|
-
* 2. Environment variables (
|
|
10
|
-
* 3. Stored credentials from `os
|
|
9
|
+
* 2. Environment variables (OS_CLOUD_URL, OS_TOKEN)
|
|
10
|
+
* 3. Stored credentials from `os login`
|
|
11
11
|
* 4. Defaults (http://localhost:3000)
|
|
12
12
|
*/
|
|
13
13
|
export async function createApiClient(options = {}) {
|
|
14
14
|
// Resolve server URL (without applying defaults yet)
|
|
15
|
-
let baseUrl = options.url || process.env.
|
|
15
|
+
let baseUrl = options.url || process.env.OS_CLOUD_URL;
|
|
16
16
|
// Resolve authentication token
|
|
17
|
-
let token = options.token || process.env.
|
|
17
|
+
let token = options.token || process.env.OS_TOKEN;
|
|
18
|
+
// Resolve active project id (explicit > env > stored credentials)
|
|
19
|
+
let projectId = options.projectId || process.env.OS_PROJECT_ID;
|
|
18
20
|
// If URL or token is missing, try to load from stored credentials
|
|
19
|
-
if (!baseUrl || !token) {
|
|
21
|
+
if (!baseUrl || !token || !projectId) {
|
|
20
22
|
try {
|
|
21
23
|
const authConfig = await readAuthConfig();
|
|
22
24
|
if (!token && authConfig.token) {
|
|
@@ -25,6 +27,9 @@ export async function createApiClient(options = {}) {
|
|
|
25
27
|
if (!baseUrl && authConfig.url) {
|
|
26
28
|
baseUrl = authConfig.url;
|
|
27
29
|
}
|
|
30
|
+
if (!projectId && authConfig.activeProjectId) {
|
|
31
|
+
projectId = authConfig.activeProjectId;
|
|
32
|
+
}
|
|
28
33
|
}
|
|
29
34
|
catch {
|
|
30
35
|
// No stored credentials - commands will fail if auth is required
|
|
@@ -37,9 +42,10 @@ export async function createApiClient(options = {}) {
|
|
|
37
42
|
const client = new ObjectStackClient({
|
|
38
43
|
baseUrl,
|
|
39
44
|
token,
|
|
45
|
+
projectId,
|
|
40
46
|
debug: options.debug || false,
|
|
41
47
|
});
|
|
42
|
-
return { client, token };
|
|
48
|
+
return { client, token, projectId };
|
|
43
49
|
}
|
|
44
50
|
/**
|
|
45
51
|
* Ensure authentication is present, throwing an error if not.
|
|
@@ -47,7 +53,7 @@ export async function createApiClient(options = {}) {
|
|
|
47
53
|
*/
|
|
48
54
|
export function requireAuth(token) {
|
|
49
55
|
if (!token) {
|
|
50
|
-
throw new Error('Authentication required. Please run `os
|
|
56
|
+
throw new Error('Authentication required. Please run `os login` or set OS_TOKEN environment variable.');
|
|
51
57
|
}
|
|
52
58
|
}
|
|
53
59
|
//# sourceMappingURL=api-client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-client.js","sourceRoot":"","sources":["../../src/utils/api-client.ts"],"names":[],"mappings":"AAAA,yEAAyE;AAEzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"api-client.js","sourceRoot":"","sources":["../../src/utils/api-client.ts"],"names":[],"mappings":"AAAA,yEAAyE;AAEzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAmClD;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,UAA4B,EAAE;IAClE,qDAAqD;IACrD,IAAI,OAAO,GAAG,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC;IAEtD,+BAA+B;IAC/B,IAAI,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC;IAElD,kEAAkE;IAClE,IAAI,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;IAE/D,kEAAkE;IAClE,IAAI,CAAC,OAAO,IAAI,CAAC,KAAK,IAAI,CAAC,SAAS,EAAE,CAAC;QACrC,IAAI,CAAC;YACH,MAAM,UAAU,GAAG,MAAM,cAAc,EAAE,CAAC;YAC1C,IAAI,CAAC,KAAK,IAAI,UAAU,CAAC,KAAK,EAAE,CAAC;gBAC/B,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC;YAC3B,CAAC;YACD,IAAI,CAAC,OAAO,IAAI,UAAU,CAAC,GAAG,EAAE,CAAC;gBAC/B,OAAO,GAAG,UAAU,CAAC,GAAG,CAAC;YAC3B,CAAC;YACD,IAAI,CAAC,SAAS,IAAI,UAAU,CAAC,eAAe,EAAE,CAAC;gBAC7C,SAAS,GAAG,UAAU,CAAC,eAAe,CAAC;YACzC,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,iEAAiE;QACnE,CAAC;IACH,CAAC;IAED,wDAAwD;IACxD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,GAAG,uBAAuB,CAAC;IACpC,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,iBAAiB,CAAC;QACnC,OAAO;QACP,KAAK;QACL,SAAS;QACT,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,KAAK;KAC9B,CAAC,CAAC;IAEH,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;AACtC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CACb,sFAAsF,CACvF,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -26,6 +26,12 @@ export interface AuthConfig {
|
|
|
26
26
|
* Timestamp when credentials were last used
|
|
27
27
|
*/
|
|
28
28
|
lastUsedAt?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Active project id for subsequent CLI calls. Set via `os projects switch`;
|
|
31
|
+
* read by `createApiClient` so every command lands in the right project
|
|
32
|
+
* without an explicit flag.
|
|
33
|
+
*/
|
|
34
|
+
activeProjectId?: string;
|
|
29
35
|
}
|
|
30
36
|
/**
|
|
31
37
|
* Get the path to the credentials file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-config.d.ts","sourceRoot":"","sources":["../../src/utils/auth-config.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"auth-config.d.ts","sourceRoot":"","sources":["../../src/utils/auth-config.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAE3C;AAED;;GAEG;AACH,wBAAsB,cAAc,IAAI,OAAO,CAAC,UAAU,CAAC,CAW1D;AAED;;GAEG;AACH,wBAAsB,eAAe,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBvE;AAED;;GAEG;AACH,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAUtD;AAED;;GAEG;AACH,wBAAsB,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC,CAQrD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-config.js","sourceRoot":"","sources":["../../src/utils/auth-config.ts"],"names":[],"mappings":"AAAA,yEAAyE;AAEzE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"auth-config.js","sourceRoot":"","sources":["../../src/utils/auth-config.ts"],"names":[],"mappings":"AAAA,yEAAyE;AAEzE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAsCrE;;GAEG;AACH,MAAM,UAAU,kBAAkB;IAChC,OAAO,IAAI,CAAC,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,CAAC,CAAC;AAC7D,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc;IAClC,MAAM,IAAI,GAAG,kBAAkB,EAAE,CAAC;IAClC,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAC9C,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAe,CAAC;IAC3C,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CAAC,gEAAgE,CAAC,CAAC;QACpF,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,+BAA+B,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IAClE,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,MAAkB;IACtD,MAAM,IAAI,GAAG,k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
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface AuthFlowUser {
|
|
2
|
+
id?: string;
|
|
3
|
+
email?: string;
|
|
4
|
+
}
|
|
5
|
+
export interface AuthFlowResult {
|
|
6
|
+
token: string;
|
|
7
|
+
user?: AuthFlowUser;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Email + password authentication (CI / non-interactive path).
|
|
11
|
+
*/
|
|
12
|
+
export declare function loginWithPassword(url: string, email: string, password: string): Promise<AuthFlowResult>;
|
|
13
|
+
export interface BrowserFlowOptions {
|
|
14
|
+
/** OAuth client id; defaults to `OS_CLI_CLIENT_ID` env or `objectstack-cli`. */
|
|
15
|
+
clientId?: string;
|
|
16
|
+
/** If true, only print the verification URL — do not launch a browser. */
|
|
17
|
+
noBrowser?: boolean;
|
|
18
|
+
/** Suppress all human-readable stdout (callers using --json). */
|
|
19
|
+
silent?: boolean;
|
|
20
|
+
/** Override the spinner / verification-URL printer for custom UI. */
|
|
21
|
+
onDeviceCode?: (info: {
|
|
22
|
+
verificationUrl: string;
|
|
23
|
+
userCode: string;
|
|
24
|
+
expiresIn: number;
|
|
25
|
+
}) => void;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* RFC 8628 OAuth 2.0 Device Authorization Grant.
|
|
29
|
+
*/
|
|
30
|
+
export declare function loginWithBrowser(url: string, opts?: BrowserFlowOptions): Promise<AuthFlowResult>;
|
|
31
|
+
//# sourceMappingURL=auth-flows.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-flows.d.ts","sourceRoot":"","sources":["../../src/utils/auth-flows.ts"],"names":[],"mappings":"AAqBA,MAAM,WAAW,YAAY;IAC3B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,YAAY,CAAC;CACrB;AAED;;GAEG;AACH,wBAAsB,iBAAiB,CACrC,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,cAAc,CAAC,CAezB;AAmBD,MAAM,WAAW,kBAAkB;IACjC,gFAAgF;IAChF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,0EAA0E;IAC1E,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,iEAAiE;IACjE,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,qEAAqE;IACrE,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE;QACpB,eAAe,EAAE,MAAM,CAAC;QACxB,QAAQ,EAAE,MAAM,CAAC;QACjB,SAAS,EAAE,MAAM,CAAC;KACnB,KAAK,IAAI,CAAC;CACZ;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,MAAM,EACX,IAAI,GAAE,kBAAuB,GAC5B,OAAO,CAAC,cAAc,CAAC,CAiHzB"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
|
|
2
|
+
/**
|
|
3
|
+
* Shared authentication flows for CLI login commands.
|
|
4
|
+
*
|
|
5
|
+
* Two commands consume this module:
|
|
6
|
+
* - `os login` — log in to a runtime ObjectOS instance.
|
|
7
|
+
* - `os cloud login` — log in to the hosted ObjectStack Cloud control plane.
|
|
8
|
+
*
|
|
9
|
+
* The flows themselves are identical (both target ObjectStack servers
|
|
10
|
+
* speaking the same plugin-auth endpoints); only the credential storage
|
|
11
|
+
* destination differs, which is the caller's responsibility.
|
|
12
|
+
*
|
|
13
|
+
* These helpers are intentionally side-effect-free with respect to disk
|
|
14
|
+
* I/O so callers can persist the resulting token wherever they need to.
|
|
15
|
+
* They DO write to stdout for the interactive device-flow UX; pass
|
|
16
|
+
* `silent: true` to suppress all human-readable output (used by `--json`).
|
|
17
|
+
*/
|
|
18
|
+
import { ObjectStackClient } from '@objectstack/client';
|
|
19
|
+
/**
|
|
20
|
+
* Email + password authentication (CI / non-interactive path).
|
|
21
|
+
*/
|
|
22
|
+
export async function loginWithPassword(url, email, password) {
|
|
23
|
+
const client = new ObjectStackClient({ baseUrl: url });
|
|
24
|
+
const response = await client.auth.login({ type: 'email', email, password });
|
|
25
|
+
if (!response.data?.token && !response.data?.user) {
|
|
26
|
+
throw new Error('Login failed: Invalid response from server');
|
|
27
|
+
}
|
|
28
|
+
const token = response.data?.token || response.token;
|
|
29
|
+
if (!token)
|
|
30
|
+
throw new Error('Login failed: No token received from server');
|
|
31
|
+
return {
|
|
32
|
+
token,
|
|
33
|
+
user: response.data?.user ? { id: response.data.user.id, email: response.data.user.email } : { email },
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Open a URL in the system default browser (best-effort, cross-platform).
|
|
38
|
+
*/
|
|
39
|
+
async function openBrowser(url) {
|
|
40
|
+
const { exec } = await import('node:child_process');
|
|
41
|
+
const platform = process.platform;
|
|
42
|
+
const cmd = platform === 'darwin'
|
|
43
|
+
? `open "${url}"`
|
|
44
|
+
: platform === 'win32'
|
|
45
|
+
? `start "" "${url}"`
|
|
46
|
+
: `xdg-open "${url}"`;
|
|
47
|
+
exec(cmd, () => {
|
|
48
|
+
/* best-effort */
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* RFC 8628 OAuth 2.0 Device Authorization Grant.
|
|
53
|
+
*/
|
|
54
|
+
export async function loginWithBrowser(url, opts = {}) {
|
|
55
|
+
const clientId = opts.clientId ?? process.env.OS_CLI_CLIENT_ID ?? 'objectstack-cli';
|
|
56
|
+
const silent = !!opts.silent;
|
|
57
|
+
// RFC 8628 §3.1 — Device Authorization Request
|
|
58
|
+
const res = await globalThis.fetch(`${url}/api/v1/auth/device/code`, {
|
|
59
|
+
method: 'POST',
|
|
60
|
+
headers: { 'Content-Type': 'application/json' },
|
|
61
|
+
body: JSON.stringify({ client_id: clientId, scope: 'openid profile email' }),
|
|
62
|
+
});
|
|
63
|
+
if (!res.ok) {
|
|
64
|
+
const err = await res.json().catch(() => ({}));
|
|
65
|
+
throw new Error(`Device request failed (${res.status}): ${err?.error_description || err?.message || res.statusText}`);
|
|
66
|
+
}
|
|
67
|
+
const deviceData = (await res.json());
|
|
68
|
+
const { device_code, user_code, verification_uri, verification_uri_complete, expires_in, interval = 5 } = deviceData ?? {};
|
|
69
|
+
if (!device_code || !user_code || !verification_uri) {
|
|
70
|
+
throw new Error('Server did not return RFC 8628 device authorization fields. Use `--email <email> --password <password>` instead.');
|
|
71
|
+
}
|
|
72
|
+
const verificationUrl = verification_uri_complete || `${verification_uri}?user_code=${encodeURIComponent(user_code)}`;
|
|
73
|
+
if (opts.onDeviceCode) {
|
|
74
|
+
opts.onDeviceCode({ verificationUrl, userCode: user_code, expiresIn: expires_in ?? 600 });
|
|
75
|
+
}
|
|
76
|
+
else if (!silent) {
|
|
77
|
+
console.log(' To authorize this CLI, visit:');
|
|
78
|
+
console.log('');
|
|
79
|
+
console.log(` ${verificationUrl}`);
|
|
80
|
+
console.log('');
|
|
81
|
+
console.log(` User code: ${user_code}`);
|
|
82
|
+
console.log('');
|
|
83
|
+
}
|
|
84
|
+
if (!opts.noBrowser && !silent) {
|
|
85
|
+
await openBrowser(verificationUrl);
|
|
86
|
+
console.log(' (Browser opened automatically. Press Ctrl+C to cancel.)');
|
|
87
|
+
console.log('');
|
|
88
|
+
}
|
|
89
|
+
// RFC 8628 §3.4 — Device Access Token Request (poll)
|
|
90
|
+
let pollMs = (interval || 5) * 1000;
|
|
91
|
+
const expiryTime = Date.now() + (expires_in || 600) * 1000;
|
|
92
|
+
let spinner = 0;
|
|
93
|
+
const spinChars = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
|
|
94
|
+
while (Date.now() < expiryTime) {
|
|
95
|
+
await new Promise((r) => setTimeout(r, pollMs));
|
|
96
|
+
const pollRes = await globalThis.fetch(`${url}/api/v1/auth/device/token`, {
|
|
97
|
+
method: 'POST',
|
|
98
|
+
headers: { 'Content-Type': 'application/json' },
|
|
99
|
+
body: JSON.stringify({
|
|
100
|
+
grant_type: 'urn:ietf:params:oauth:grant-type:device_code',
|
|
101
|
+
device_code,
|
|
102
|
+
client_id: clientId,
|
|
103
|
+
}),
|
|
104
|
+
});
|
|
105
|
+
const pollJson = (await pollRes.json());
|
|
106
|
+
if (pollRes.ok && pollJson?.access_token) {
|
|
107
|
+
const accessToken = pollJson.access_token;
|
|
108
|
+
// Resolve user info via /get-session (device-token response omits user details per RFC 8628)
|
|
109
|
+
let user;
|
|
110
|
+
try {
|
|
111
|
+
const sessionRes = await globalThis.fetch(`${url}/api/v1/auth/get-session`, {
|
|
112
|
+
headers: { Authorization: `Bearer ${accessToken}` },
|
|
113
|
+
});
|
|
114
|
+
if (sessionRes.ok) {
|
|
115
|
+
const sessionData = (await sessionRes.json());
|
|
116
|
+
const u = sessionData?.user ?? sessionData?.data?.user;
|
|
117
|
+
if (u)
|
|
118
|
+
user = { id: u.id, email: u.email };
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
// best-effort
|
|
123
|
+
}
|
|
124
|
+
if (!silent)
|
|
125
|
+
process.stdout.write('\r\x1b[K');
|
|
126
|
+
return { token: accessToken, user };
|
|
127
|
+
}
|
|
128
|
+
// Standard RFC 8628 error codes
|
|
129
|
+
const errCode = pollJson?.error;
|
|
130
|
+
if (errCode === 'authorization_pending') {
|
|
131
|
+
// keep polling
|
|
132
|
+
}
|
|
133
|
+
else if (errCode === 'slow_down') {
|
|
134
|
+
pollMs += 5000;
|
|
135
|
+
}
|
|
136
|
+
else if (errCode === 'expired_token' || errCode === 'access_denied' || errCode === 'invalid_grant') {
|
|
137
|
+
throw new Error(errCode === 'access_denied'
|
|
138
|
+
? 'Login denied by user.'
|
|
139
|
+
: 'Login timed out or device code is no longer valid. Please retry.');
|
|
140
|
+
}
|
|
141
|
+
else if (!pollRes.ok) {
|
|
142
|
+
throw new Error(`Polling failed (${pollRes.status}): ${pollJson?.error_description || pollJson?.message || pollRes.statusText}`);
|
|
143
|
+
}
|
|
144
|
+
if (!silent) {
|
|
145
|
+
process.stdout.write(`\r ${spinChars[spinner % spinChars.length]} Waiting for browser approval...`);
|
|
146
|
+
spinner++;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
throw new Error('Login timed out.');
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=auth-flows.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-flows.js","sourceRoot":"","sources":["../../src/utils/auth-flows.ts"],"names":[],"mappings":"AAAA,yEAAyE;AAEzE;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAYxD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,GAAW,EACX,KAAa,EACb,QAAgB;IAEhB,MAAM,MAAM,GAAG,IAAI,iBAAiB,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC;IACvD,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;IAE7E,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC;QAClD,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,CAAC;IAED,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,EAAE,KAAK,IAAK,QAAgB,CAAC,KAAK,CAAC;IAC9D,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;IAE3E,OAAO;QACL,KAAK;QACL,IAAI,EAAE,QAAQ,C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eAAe;gBACzB,CAAC,CAAC,uBAAuB;gBACzB,CAAC,CAAC,kEAAkE,CACvE,CAAC;QACJ,CAAC;aAAM,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CACb,mBAAmB,OAAO,CAAC,MAAM,MAAM,QAAQ,EAAE,iBAAiB,IAAI,QAAQ,EAAE,OAAO,IAAI,OAAO,CAAC,UAAU,EAAE,CAChH,CAAC;QACJ,CAAC;QAED,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,SAAS,CAAC,OAAO,GAAG,SAAS,CAAC,MAAM,CAAC,kCAAkC,CAAC,CAAC;YACrG,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build a single ESM bundle that re-exports every inline handler function
|
|
3
|
+
* collected by `lowerCallables`. The bundle is the second half of the
|
|
4
|
+
* "two-product" build (alongside `objectstack.json`):
|
|
5
|
+
*
|
|
6
|
+
* dist/
|
|
7
|
+
* ├── objectstack.json
|
|
8
|
+
* └── objectstack-runtime.{contenthash}.mjs ← THIS
|
|
9
|
+
*
|
|
10
|
+
* At runtime, `StandaloneStack` (and `MultiProjectPlugin`) dynamic-import
|
|
11
|
+
* the mjs and merge `module.functions` into the bundle before
|
|
12
|
+
* `bindHooks(...)` runs — so string-named handlers resolve to real code
|
|
13
|
+
* even though the JSON artifact is pure metadata.
|
|
14
|
+
*/
|
|
15
|
+
export interface BuildRuntimeOptions {
|
|
16
|
+
/** Absolute path to the user's `objectstack.config.{ts,js,mjs}`. */
|
|
17
|
+
sourceConfigPath: string;
|
|
18
|
+
/** Lowered handler refs (`name → handlerName`) — mirrors `LoweringResult.functions`. */
|
|
19
|
+
refs: string[];
|
|
20
|
+
/** Output directory (e.g. `<cwd>/dist`). Created if missing. */
|
|
21
|
+
outputDir: string;
|
|
22
|
+
/** Base file name without hash, e.g. `objectstack-runtime`. */
|
|
23
|
+
baseName?: string;
|
|
24
|
+
/** External package names to mark as external (`@objectstack/*` etc.). */
|
|
25
|
+
externalPackages?: string[];
|
|
26
|
+
}
|
|
27
|
+
export interface BuildRuntimeResult {
|
|
28
|
+
/** Absolute path to the emitted mjs. */
|
|
29
|
+
outputPath: string;
|
|
30
|
+
/** File name (relative to outputDir) — embedded in objectstack.json. */
|
|
31
|
+
outputFileName: string;
|
|
32
|
+
/** Content hash (sha256, first 16 hex chars). */
|
|
33
|
+
hash: string;
|
|
34
|
+
/** Bundle size in bytes. */
|
|
35
|
+
size: number;
|
|
36
|
+
}
|
|
37
|
+
export declare function buildRuntimeBundle(opts: BuildRuntimeOptions): Promise<BuildRuntimeResult>;
|
|
38
|
+
/** Best-effort cleanup of stale `objectstack-runtime.*.mjs` files. */
|
|
39
|
+
export declare function cleanupOldRuntimeBundles(outputDir: string, keepFileName: string, baseName?: string): number;
|
|
40
|
+
/** Reuse: read an existing bundle and recompute its size for stats. */
|
|
41
|
+
export declare function statBundle(outputPath: string): {
|
|
42
|
+
size: number;
|
|
43
|
+
} | null;
|
|
44
|
+
export declare const runtimeBundlePathRelative: (outputDir: string, file: string) => string;
|
|
45
|
+
//# sourceMappingURL=build-runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-runtime.d.ts","sourceRoot":"","sources":["../../src/utils/build-runtime.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;GAaG;AAEH,MAAM,WAAW,mBAAmB;IAClC,oEAAoE;IACpE,gBAAgB,EAAE,MAAM,CAAC;IACzB,wFAAwF;IACxF,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,gEAAgE;IAChE,SAAS,EAAE,MAAM,CAAC;IAClB,+DAA+D;IAC/D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,0EAA0E;IAC1E,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC7B;AAED,MAAM,WAAW,kBAAkB;IACjC,wCAAwC;IACxC,UAAU,EAAE,MAAM,CAAC;IACnB,wEAAwE;IACxE,cAAc,EAAE,MAAM,CAAC;IACvB,iDAAiD;IACjD,IAAI,EAAE,MAAM,CAAC;IACb,4BAA4B;IAC5B,IAAI,EAAE,MAAM,CAAC;CACd;AA6DD,wBAAsB,kBAAkB,CAAC,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CA4D/F;AAED,sEAAsE;AACtE,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,SAAe,GAAG,MAAM,CAejH;AAED,uEAAuE;AACvE,wBAAgB,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAOtE;AAED,eAAO,MAAM,yBAAyB,GAAI,WAAW,MAAM,EAAE,MAAM,MAAM,KAAG,MACf,CAAC"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { mkdirSync, writeFileSync, readFileSync, existsSync, unlinkSync, readdirSync } from 'node:fs';
|
|
4
|
+
import { dirname, basename, resolve as resolvePath, relative, sep as PATH_SEP } from 'node:path';
|
|
5
|
+
const DEFAULT_BASE = 'objectstack-runtime';
|
|
6
|
+
/**
|
|
7
|
+
* Generate the entry source that re-extracts callable handlers from the
|
|
8
|
+
* compiled config. We bundle the user's config transitively (so every
|
|
9
|
+
* `*.hook.ts` import is captured), then walk the same shape the lowering
|
|
10
|
+
* pass walked and re-export the matching handlers under the same string
|
|
11
|
+
* keys. The runtime side merges this map into `bundle.functions`.
|
|
12
|
+
*/
|
|
13
|
+
function generateEntrySource(sourceConfigPath, refs, entryDir) {
|
|
14
|
+
// Use a POSIX-style relative path so esbuild's resolver bundles the
|
|
15
|
+
// user's config + every transitively-imported `*.hook.ts` into the
|
|
16
|
+
// emitted ESM. A `file://` URL would be treated as external.
|
|
17
|
+
let importPath = relative(entryDir, sourceConfigPath).split(PATH_SEP).join('/');
|
|
18
|
+
if (!importPath.startsWith('.'))
|
|
19
|
+
importPath = './' + importPath;
|
|
20
|
+
const refLiteral = JSON.stringify(refs);
|
|
21
|
+
return `// AUTO-GENERATED by @objectstack/cli — do not edit.
|
|
22
|
+
import config from ${JSON.stringify(importPath)};
|
|
23
|
+
|
|
24
|
+
const REFS = new Set(${refLiteral});
|
|
25
|
+
|
|
26
|
+
function collect(cfg) {
|
|
27
|
+
const out = Object.create(null);
|
|
28
|
+
if (!cfg || typeof cfg !== 'object') return out;
|
|
29
|
+
// Hooks: { name, handler }
|
|
30
|
+
if (Array.isArray(cfg.hooks)) {
|
|
31
|
+
for (const h of cfg.hooks) {
|
|
32
|
+
if (h && typeof h === 'object' && typeof h.handler === 'function' && typeof h.name === 'string') {
|
|
33
|
+
if (REFS.has(h.name)) out[h.name] = h.handler;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
// Top-level functions map
|
|
38
|
+
if (cfg.functions && !Array.isArray(cfg.functions) && typeof cfg.functions === 'object') {
|
|
39
|
+
for (const [k, v] of Object.entries(cfg.functions)) {
|
|
40
|
+
if (typeof v === 'function' && REFS.has(k)) out[k] = v;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// Top-level functions array
|
|
44
|
+
if (Array.isArray(cfg.functions)) {
|
|
45
|
+
for (const entry of cfg.functions) {
|
|
46
|
+
if (entry && typeof entry === 'object' && typeof entry.handler === 'function' && typeof entry.name === 'string') {
|
|
47
|
+
if (REFS.has(entry.name)) out[entry.name] = entry.handler;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const cfg = config && typeof config === 'object' && 'default' in config ? config.default : config;
|
|
55
|
+
export const functions = collect(cfg);
|
|
56
|
+
export const meta = {
|
|
57
|
+
builtAt: new Date().toISOString(),
|
|
58
|
+
refCount: ${refs.length},
|
|
59
|
+
};
|
|
60
|
+
`;
|
|
61
|
+
}
|
|
62
|
+
export async function buildRuntimeBundle(opts) {
|
|
63
|
+
const { sourceConfigPath, refs, outputDir } = opts;
|
|
64
|
+
const baseName = opts.baseName ?? DEFAULT_BASE;
|
|
65
|
+
if (!existsSync(outputDir))
|
|
66
|
+
mkdirSync(outputDir, { recursive: true });
|
|
67
|
+
const entryDir = dirname(sourceConfigPath);
|
|
68
|
+
const entryPath = resolvePath(entryDir, `.${baseName}.entry.${process.pid}.${Date.now()}.mjs`);
|
|
69
|
+
writeFileSync(entryPath, generateEntrySource(sourceConfigPath, refs, entryDir));
|
|
70
|
+
let esbuild;
|
|
71
|
+
try {
|
|
72
|
+
esbuild = await import('esbuild');
|
|
73
|
+
}
|
|
74
|
+
catch (err) {
|
|
75
|
+
try {
|
|
76
|
+
unlinkSync(entryPath);
|
|
77
|
+
}
|
|
78
|
+
catch { /* noop */ }
|
|
79
|
+
throw new Error(`[build-runtime] esbuild is required to bundle declarative handlers but is not installed: ${err.message}`);
|
|
80
|
+
}
|
|
81
|
+
// Bundle to an in-memory buffer first so we can hash, then rename.
|
|
82
|
+
let result;
|
|
83
|
+
try {
|
|
84
|
+
result = await esbuild.build({
|
|
85
|
+
entryPoints: [entryPath],
|
|
86
|
+
bundle: true,
|
|
87
|
+
format: 'esm',
|
|
88
|
+
platform: 'node',
|
|
89
|
+
target: 'node18',
|
|
90
|
+
write: false,
|
|
91
|
+
sourcemap: 'inline',
|
|
92
|
+
packages: 'external',
|
|
93
|
+
logLevel: 'silent',
|
|
94
|
+
legalComments: 'none',
|
|
95
|
+
resolveExtensions: ['.ts', '.tsx', '.mjs', '.js', '.cjs', '.json'],
|
|
96
|
+
loader: { '.ts': 'ts', '.tsx': 'tsx' },
|
|
97
|
+
banner: { js: '// @generated by @objectstack/cli — do not edit.' },
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
finally {
|
|
101
|
+
try {
|
|
102
|
+
unlinkSync(entryPath);
|
|
103
|
+
}
|
|
104
|
+
catch { /* noop */ }
|
|
105
|
+
}
|
|
106
|
+
const out = result.outputFiles?.[0];
|
|
107
|
+
if (!out)
|
|
108
|
+
throw new Error('[build-runtime] esbuild produced no output');
|
|
109
|
+
const code = out.text;
|
|
110
|
+
const hash = createHash('sha256').update(code).digest('hex').slice(0, 16);
|
|
111
|
+
const fileName = `${baseName}.${hash}.mjs`;
|
|
112
|
+
const outputPath = resolvePath(outputDir, fileName);
|
|
113
|
+
writeFileSync(outputPath, code);
|
|
114
|
+
return {
|
|
115
|
+
outputPath,
|
|
116
|
+
outputFileName: fileName,
|
|
117
|
+
hash,
|
|
118
|
+
size: Buffer.byteLength(code, 'utf8'),
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/** Best-effort cleanup of stale `objectstack-runtime.*.mjs` files. */
|
|
122
|
+
export function cleanupOldRuntimeBundles(outputDir, keepFileName, baseName = DEFAULT_BASE) {
|
|
123
|
+
if (!existsSync(outputDir))
|
|
124
|
+
return 0;
|
|
125
|
+
let removed = 0;
|
|
126
|
+
try {
|
|
127
|
+
const re = new RegExp(`^${baseName}\\.[a-f0-9]+\\.mjs(\\.map)?$`);
|
|
128
|
+
for (const f of readdirSync(outputDir)) {
|
|
129
|
+
if (!re.test(f))
|
|
130
|
+
continue;
|
|
131
|
+
if (f === keepFileName)
|
|
132
|
+
continue;
|
|
133
|
+
try {
|
|
134
|
+
unlinkSync(resolvePath(outputDir, f));
|
|
135
|
+
removed += 1;
|
|
136
|
+
}
|
|
137
|
+
catch { /* noop */ }
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
catch { /* noop */ }
|
|
141
|
+
return removed;
|
|
142
|
+
}
|
|
143
|
+
/** Reuse: read an existing bundle and recompute its size for stats. */
|
|
144
|
+
export function statBundle(outputPath) {
|
|
145
|
+
try {
|
|
146
|
+
const buf = readFileSync(outputPath);
|
|
147
|
+
return { size: buf.byteLength };
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
export const runtimeBundlePathRelative = (outputDir, file) => relative(outputDir, resolvePath(outputDir, basename(file)));
|
|
154
|
+
//# sourceMappingURL=build-runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-runtime.js","sourceRoot":"","sources":["../../src/utils/build-runtime.ts"],"names":[],"mappings":"AAAA,yEAAyE;AAEzE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtG,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,IAAI,WAAW,EAAE,QAAQ,EAAE,GAAG,IAAI,QAAQ,EAAE,MAAM,WAAW,CAAC;AAyCjG,MAAM,YAAY,GAAG,qBAAqB,CAAC;AAE3C;;;;;;GAMG;AACH,SAAS,mBAAmB,CAAC,gBAAwB,EAAE,IAAc,EAAE,QAAgB;IACrF,oEAAoE;IACpE,mEAAmE;IACnE,6DAA6D;IAC7D,IAAI,UAAU,GAAG,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAChF,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,UAAU,GAAG,IAAI,GAAG,UAAU,CAAC;IAChE,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAExC,OAAO;qBACY,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC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DEFAULT_CLOUD_URL = "https://cloud.objectos.app";
|
|
3
|
+
export interface CloudConfig {
|
|
4
|
+
/** Base URL of the cloud control plane (defaults to `https://cloud.objectos.app`). */
|
|
5
|
+
url: string;
|
|
6
|
+
/** Bearer token returned by the device or password flow. */
|
|
7
|
+
token: string;
|
|
8
|
+
/** Authenticated user's email, for display. */
|
|
9
|
+
email?: string;
|
|
10
|
+
/** Authenticated user's id. */
|
|
11
|
+
userId?: string;
|
|
12
|
+
/** Active organization id chosen for publishing. */
|
|
13
|
+
activeOrgId?: string;
|
|
14
|
+
/** ISO timestamp when the credential was created. */
|
|
15
|
+
createdAt: string;
|
|
16
|
+
/** ISO timestamp of last use (best-effort). */
|
|
17
|
+
lastUsedAt?: string;
|
|
18
|
+
}
|
|
19
|
+
export declare function getCloudCredentialsPath(): string;
|
|
20
|
+
export declare function readCloudConfig(): Promise<CloudConfig>;
|
|
21
|
+
export declare function tryReadCloudConfig(): Promise<CloudConfig | undefined>;
|
|
22
|
+
export declare function writeCloudConfig(config: CloudConfig): Promise<void>;
|
|
23
|
+
export declare function deleteCloudConfig(): Promise<void>;
|
|
24
|
+
//# sourceMappingURL=cloud-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloud-config.d.ts","sourceRoot":"","sources":["../../src/utils/cloud-config.ts"],"names":[],"mappings":"AA4BA,sCAAsC;AACtC,eAAO,MAAM,iBAAiB,+BAA+B,CAAC;AAE9D,MAAM,WAAW,WAAW;IAC1B,sFAAsF;IACtF,GAAG,EAAE,MAAM,CAAC;IACZ,4DAA4D;IAC5D,KAAK,EAAE,MAAM,CAAC;IACd,+CAA+C;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,+BAA+B;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oDAAoD;IACpD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,qDAAqD;IACrD,SAAS,EAAE,MAAM,CAAC;IAClB,+CAA+C;IAC/C,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,wBAAgB,uBAAuB,IAAI,MAAM,CAEhD;AAED,wBAAsB,eAAe,IAAI,OAAO,CAAC,WAAW,CAAC,CAW5D;AAED,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,CAM3E;AAED,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAWzE;AAED,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC,CASvD"}
|