@sidekickdb/cli 2.0.1 → 3.0.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/.turbo/turbo-build.log +1 -1
- package/README.md +4 -4
- package/__tests__/appCommands.test.ts +8 -8
- package/__tests__/auth.test.ts +11 -65
- package/__tests__/authClientAddApple.test.ts +3 -3
- package/__tests__/authClientAddClerk.test.ts +8 -13
- package/__tests__/authClientAddGithub.test.ts +5 -5
- package/__tests__/authClientAddGoogle.test.ts +3 -3
- package/__tests__/authClientAddLinkedin.test.ts +3 -3
- package/__tests__/authClientList.test.ts +4 -3
- package/__tests__/authClientUpdate.test.ts +6 -8
- package/__tests__/authOriginManagement.test.ts +11 -11
- package/__tests__/backups.test.ts +2 -2
- package/__tests__/config.test.ts +34 -34
- package/__tests__/configAliases.test.ts +27 -215
- package/__tests__/configFileNames.test.ts +118 -0
- package/__tests__/e2e/cli.e2e.test.ts +102 -102
- package/__tests__/e2e/helpers.ts +5 -5
- package/__tests__/effectHelpers.ts +3 -3
- package/__tests__/emailVerification.test.ts +31 -0
- package/__tests__/oldConfigFiles.test.ts +254 -0
- package/__tests__/webhooks.test.ts +2 -2
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +6 -43
- package/dist/auth/index.js.map +1 -1
- package/dist/commands/app/delete.d.ts +2 -2
- package/dist/commands/app/delete.d.ts.map +1 -1
- package/dist/commands/app/delete.js +2 -2
- package/dist/commands/app/delete.js.map +1 -1
- package/dist/commands/app/list.d.ts +2 -2
- package/dist/commands/app/list.d.ts.map +1 -1
- package/dist/commands/app/list.js +2 -2
- package/dist/commands/app/list.js.map +1 -1
- package/dist/commands/auth/client/add.d.ts +1 -1
- package/dist/commands/auth/client/add.d.ts.map +1 -1
- package/dist/commands/auth/client/delete.d.ts +2 -2
- package/dist/commands/auth/client/delete.d.ts.map +1 -1
- package/dist/commands/auth/client/delete.js +2 -2
- package/dist/commands/auth/client/delete.js.map +1 -1
- package/dist/commands/auth/client/list.d.ts +1 -1
- package/dist/commands/auth/client/list.d.ts.map +1 -1
- package/dist/commands/auth/client/update.d.ts +1 -1
- package/dist/commands/auth/client/update.d.ts.map +1 -1
- package/dist/commands/auth/email/pull.d.ts +4 -4
- package/dist/commands/auth/email/pull.d.ts.map +1 -1
- package/dist/commands/auth/email/pull.js +5 -2
- package/dist/commands/auth/email/pull.js.map +1 -1
- package/dist/commands/auth/email/push.d.ts +2 -2
- package/dist/commands/auth/email/push.d.ts.map +1 -1
- package/dist/commands/auth/email/push.js +3 -3
- package/dist/commands/auth/email/push.js.map +1 -1
- package/dist/commands/auth/email/resend.d.ts +1 -1
- package/dist/commands/auth/email/resend.d.ts.map +1 -1
- package/dist/commands/auth/email/reset.d.ts +2 -2
- package/dist/commands/auth/email/reset.d.ts.map +1 -1
- package/dist/commands/auth/email/reset.js +3 -3
- package/dist/commands/auth/email/reset.js.map +1 -1
- package/dist/commands/auth/email/status.d.ts +4 -4
- package/dist/commands/auth/email/status.d.ts.map +1 -1
- package/dist/commands/auth/email/status.js +4 -4
- package/dist/commands/auth/email/status.js.map +1 -1
- package/dist/commands/auth/email/verify.d.ts +1 -1
- package/dist/commands/auth/email/verify.d.ts.map +1 -1
- package/dist/commands/auth/email/verify.js +1 -1
- package/dist/commands/auth/email/verify.js.map +1 -1
- package/dist/commands/auth/origin/add.d.ts +1 -1
- package/dist/commands/auth/origin/add.d.ts.map +1 -1
- package/dist/commands/auth/origin/delete.d.ts +1 -1
- package/dist/commands/auth/origin/delete.d.ts.map +1 -1
- package/dist/commands/auth/origin/list.d.ts +1 -1
- package/dist/commands/auth/origin/list.d.ts.map +1 -1
- package/dist/commands/claim.d.ts +2 -2
- package/dist/commands/claim.d.ts.map +1 -1
- package/dist/commands/claim.js +2 -2
- package/dist/commands/claim.js.map +1 -1
- package/dist/commands/info.js +2 -2
- package/dist/commands/info.js.map +1 -1
- package/dist/commands/init.d.ts +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +3 -0
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/initWithoutFiles.d.ts.map +1 -1
- package/dist/commands/initWithoutFiles.js +7 -3
- package/dist/commands/initWithoutFiles.js.map +1 -1
- package/dist/commands/login.d.ts +1 -1
- package/dist/commands/login.d.ts.map +1 -1
- package/dist/commands/pull.d.ts +1 -1
- package/dist/commands/pull.d.ts.map +1 -1
- package/dist/commands/pull.js +4 -0
- package/dist/commands/pull.js.map +1 -1
- package/dist/commands/push.d.ts +1 -1
- package/dist/commands/push.d.ts.map +1 -1
- package/dist/commands/push.js +4 -0
- package/dist/commands/push.js.map +1 -1
- package/dist/commands/query.d.ts +1 -1
- package/dist/commands/query.d.ts.map +1 -1
- package/dist/commands/query.js +2 -2
- package/dist/commands/query.js.map +1 -1
- package/dist/context/authToken.d.ts +2 -2
- package/dist/context/authToken.d.ts.map +1 -1
- package/dist/context/authToken.js +6 -4
- package/dist/context/authToken.js.map +1 -1
- package/dist/context/currentApp.d.ts +3 -3
- package/dist/context/currentApp.d.ts.map +1 -1
- package/dist/context/currentApp.js +20 -20
- package/dist/context/currentApp.js.map +1 -1
- package/dist/context/globalOpts.d.ts +1 -1
- package/dist/context/globalOpts.js +1 -1
- package/dist/context/globalOpts.js.map +1 -1
- package/dist/context/platformApi.d.ts +3 -3
- package/dist/context/platformApi.d.ts.map +1 -1
- package/dist/context/platformApi.js +3 -3
- package/dist/context/platformApi.js.map +1 -1
- package/dist/context/projectInfo.d.ts +4 -4
- package/dist/context/projectInfo.d.ts.map +1 -1
- package/dist/context/projectInfo.js +12 -18
- package/dist/context/projectInfo.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +42 -49
- package/dist/index.js.map +1 -1
- package/dist/layer.d.ts +4 -4
- package/dist/layer.d.ts.map +1 -1
- package/dist/layer.js +7 -7
- package/dist/layer.js.map +1 -1
- package/dist/lib/backupDownload.js +1 -1
- package/dist/lib/backupDownload.js.map +1 -1
- package/dist/lib/config.d.ts +2 -2
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +21 -23
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/createApp.d.ts +2 -2
- package/dist/lib/createApp.d.ts.map +1 -1
- package/dist/lib/createApp.js +2 -2
- package/dist/lib/createApp.js.map +1 -1
- package/dist/lib/email.d.ts +38 -6
- package/dist/lib/email.d.ts.map +1 -1
- package/dist/lib/email.js +22 -13
- package/dist/lib/email.js.map +1 -1
- package/dist/lib/handleEnv.js +4 -4
- package/dist/lib/handleEnv.js.map +1 -1
- package/dist/lib/http.d.ts +13 -13
- package/dist/lib/http.d.ts.map +1 -1
- package/dist/lib/http.js +12 -12
- package/dist/lib/http.js.map +1 -1
- package/dist/lib/login.d.ts +4 -4
- package/dist/lib/login.d.ts.map +1 -1
- package/dist/lib/login.js +4 -4
- package/dist/lib/login.js.map +1 -1
- package/dist/lib/oauth.d.ts +10 -10
- package/dist/lib/oauth.d.ts.map +1 -1
- package/dist/lib/oauth.js +7 -7
- package/dist/lib/oauth.js.map +1 -1
- package/dist/lib/platformApi.d.ts +2 -2
- package/dist/lib/platformApi.d.ts.map +1 -1
- package/dist/lib/platformApi.js +2 -2
- package/dist/lib/platformApi.js.map +1 -1
- package/dist/lib/pullPerms.d.ts +2 -2
- package/dist/lib/pullPerms.d.ts.map +1 -1
- package/dist/lib/pullPerms.js +7 -4
- package/dist/lib/pullPerms.js.map +1 -1
- package/dist/lib/pullSchema.d.ts +2 -2
- package/dist/lib/pullSchema.d.ts.map +1 -1
- package/dist/lib/pullSchema.js +8 -5
- package/dist/lib/pullSchema.js.map +1 -1
- package/dist/lib/pushPerms.d.ts +2 -2
- package/dist/lib/pushPerms.d.ts.map +1 -1
- package/dist/lib/pushPerms.js +6 -3
- package/dist/lib/pushPerms.js.map +1 -1
- package/dist/lib/pushSchema.d.ts +2 -2
- package/dist/lib/pushSchema.d.ts.map +1 -1
- package/dist/lib/pushSchema.js +18 -7
- package/dist/lib/pushSchema.js.map +1 -1
- package/dist/lib/webhooks.d.ts +1 -1
- package/dist/lib/webhooks.d.ts.map +1 -1
- package/dist/old.js +9 -9
- package/dist/old.js.map +1 -1
- package/dist/renderSchemaPlan.d.ts +2 -2
- package/dist/renderSchemaPlan.d.ts.map +1 -1
- package/dist/renderSchemaPlan.js.map +1 -1
- package/dist/util/findConfigCandidates.d.ts +0 -20
- package/dist/util/findConfigCandidates.d.ts.map +1 -1
- package/dist/util/findConfigCandidates.js +44 -63
- package/dist/util/findConfigCandidates.js.map +1 -1
- package/dist/util/getAppName.d.ts +2 -2
- package/dist/util/getAppName.d.ts.map +1 -1
- package/dist/util/getAppName.js +2 -2
- package/dist/util/getAppName.js.map +1 -1
- package/dist/util/isHeadlessEnvironment.js +1 -1
- package/dist/util/isHeadlessEnvironment.js.map +1 -1
- package/dist/util/loadConfig.d.ts.map +1 -1
- package/dist/util/loadConfig.js +4 -11
- package/dist/util/loadConfig.js.map +1 -1
- package/dist/util/loadEnv.d.ts.map +1 -1
- package/dist/util/loadEnv.js +0 -6
- package/dist/util/loadEnv.js.map +1 -1
- package/dist/util/oldConfigFiles.d.ts +30 -0
- package/dist/util/oldConfigFiles.d.ts.map +1 -0
- package/dist/util/oldConfigFiles.js +104 -0
- package/dist/util/oldConfigFiles.js.map +1 -0
- package/dist/util/projectDir.d.ts +1 -1
- package/dist/util/projectDir.d.ts.map +1 -1
- package/dist/util/projectDir.js +6 -9
- package/dist/util/projectDir.js.map +1 -1
- package/dist/util/sidekickConfig.d.ts +9 -0
- package/dist/util/sidekickConfig.d.ts.map +1 -0
- package/dist/util/sidekickConfig.js +18 -0
- package/dist/util/sidekickConfig.js.map +1 -0
- package/package.json +5 -6
- package/src/auth/index.ts +6 -54
- package/src/commands/app/delete.ts +2 -2
- package/src/commands/app/list.ts +2 -2
- package/src/commands/auth/client/delete.ts +2 -2
- package/src/commands/auth/email/pull.ts +5 -2
- package/src/commands/auth/email/push.ts +3 -3
- package/src/commands/auth/email/reset.ts +5 -3
- package/src/commands/auth/email/status.ts +4 -4
- package/src/commands/auth/email/verify.ts +1 -1
- package/src/commands/claim.ts +2 -2
- package/src/commands/info.ts +2 -2
- package/src/commands/init.ts +3 -0
- package/src/commands/initWithoutFiles.ts +13 -6
- package/src/commands/pull.ts +6 -0
- package/src/commands/push.ts +6 -0
- package/src/commands/query.ts +2 -2
- package/src/context/authToken.ts +9 -5
- package/src/context/currentApp.ts +20 -20
- package/src/context/globalOpts.ts +1 -1
- package/src/context/platformApi.ts +3 -3
- package/src/context/projectInfo.ts +13 -20
- package/src/index.ts +42 -52
- package/src/layer.ts +10 -10
- package/src/lib/backupDownload.ts +1 -1
- package/src/lib/config.ts +21 -23
- package/src/lib/createApp.ts +2 -2
- package/src/lib/email.ts +30 -15
- package/src/lib/handleEnv.ts +4 -4
- package/src/lib/http.ts +28 -24
- package/src/lib/login.ts +4 -4
- package/src/lib/oauth.ts +7 -7
- package/src/lib/platformApi.ts +2 -2
- package/src/lib/pullPerms.ts +7 -4
- package/src/lib/pullSchema.ts +9 -6
- package/src/lib/pushPerms.ts +6 -3
- package/src/lib/pushSchema.ts +19 -7
- package/src/old.js +9 -9
- package/src/renderSchemaPlan.ts +3 -3
- package/src/util/findConfigCandidates.ts +45 -71
- package/src/util/getAppName.ts +2 -2
- package/src/util/isHeadlessEnvironment.ts +1 -1
- package/src/util/loadConfig.ts +4 -12
- package/src/util/loadEnv.ts +0 -8
- package/src/util/oldConfigFiles.ts +132 -0
- package/src/util/projectDir.ts +7 -9
- package/src/util/sidekickConfig.ts +25 -0
- package/__tests__/legacyPackageCompat.test.ts +0 -104
- package/dist/util/envAliases.d.ts +0 -25
- package/dist/util/envAliases.d.ts.map +0 -1
- package/dist/util/envAliases.js +0 -47
- package/dist/util/envAliases.js.map +0 -1
- package/dist/util/instantConfig.d.ts +0 -9
- package/dist/util/instantConfig.d.ts.map +0 -1
- package/dist/util/instantConfig.js +0 -13
- package/dist/util/instantConfig.js.map +0 -1
- package/src/util/envAliases.ts +0 -53
- package/src/util/instantConfig.ts +0 -21
package/__tests__/config.test.ts
CHANGED
|
@@ -2,11 +2,11 @@ import { Effect } from 'effect';
|
|
|
2
2
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
3
3
|
|
|
4
4
|
const mocks = vi.hoisted(() => ({
|
|
5
|
-
|
|
5
|
+
readSidekickConfigFile: vi.fn(),
|
|
6
6
|
}));
|
|
7
7
|
|
|
8
|
-
vi.mock('../src/util/
|
|
9
|
-
|
|
8
|
+
vi.mock('../src/util/sidekickConfig.ts', () => ({
|
|
9
|
+
readSidekickConfigFile: mocks.readSidekickConfigFile,
|
|
10
10
|
}));
|
|
11
11
|
|
|
12
12
|
import {
|
|
@@ -19,10 +19,10 @@ import {
|
|
|
19
19
|
} from '../src/lib/config.ts';
|
|
20
20
|
|
|
21
21
|
beforeEach(() => {
|
|
22
|
-
vi.stubEnv('
|
|
23
|
-
vi.stubEnv('
|
|
24
|
-
vi.stubEnv('
|
|
25
|
-
mocks.
|
|
22
|
+
vi.stubEnv('SIDEKICK_CLI_API_URI', undefined);
|
|
23
|
+
vi.stubEnv('SIDEKICK_CLI_DASH_URI', undefined);
|
|
24
|
+
vi.stubEnv('SIDEKICK_CLI_DEV', undefined);
|
|
25
|
+
mocks.readSidekickConfigFile.mockResolvedValue({});
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
afterEach(() => {
|
|
@@ -31,19 +31,19 @@ afterEach(() => {
|
|
|
31
31
|
});
|
|
32
32
|
|
|
33
33
|
describe('dashboard URL configuration', () => {
|
|
34
|
-
it('reads dashURI from
|
|
35
|
-
mocks.
|
|
36
|
-
dashURI: 'https://dash.
|
|
34
|
+
it('reads dashURI from sidekick.config.ts', async () => {
|
|
35
|
+
mocks.readSidekickConfigFile.mockResolvedValue({
|
|
36
|
+
dashURI: 'https://dash.sidekick.example',
|
|
37
37
|
});
|
|
38
38
|
|
|
39
39
|
await expect(Effect.runPromise(getDashUrl)).resolves.toBe(
|
|
40
|
-
'https://dash.
|
|
40
|
+
'https://dash.sidekick.example',
|
|
41
41
|
);
|
|
42
42
|
});
|
|
43
43
|
|
|
44
|
-
it('prefers
|
|
45
|
-
vi.stubEnv('
|
|
46
|
-
mocks.
|
|
44
|
+
it('prefers SIDEKICK_CLI_DASH_URI over sidekick.config.ts', async () => {
|
|
45
|
+
vi.stubEnv('SIDEKICK_CLI_DASH_URI', 'https://dash.env.example');
|
|
46
|
+
mocks.readSidekickConfigFile.mockResolvedValue({
|
|
47
47
|
dashURI: 'https://dash.config.example',
|
|
48
48
|
});
|
|
49
49
|
|
|
@@ -55,10 +55,10 @@ describe('dashboard URL configuration', () => {
|
|
|
55
55
|
|
|
56
56
|
describe('OAuth callback URL configuration', () => {
|
|
57
57
|
it('uses the configured API URL', async () => {
|
|
58
|
-
vi.stubEnv('
|
|
58
|
+
vi.stubEnv('SIDEKICK_CLI_API_URI', 'https://api.sidekick.example/');
|
|
59
59
|
|
|
60
60
|
await expect(Effect.runPromise(getOAuthCallbackUrl)).resolves.toBe(
|
|
61
|
-
'https://api.
|
|
61
|
+
'https://api.sidekick.example/runtime/oauth/callback',
|
|
62
62
|
);
|
|
63
63
|
});
|
|
64
64
|
});
|
|
@@ -68,21 +68,21 @@ describe('API URL configuration', () => {
|
|
|
68
68
|
await expect(Effect.runPromise(getBaseUrl)).rejects.toThrow(
|
|
69
69
|
missingApiUrlMessage,
|
|
70
70
|
);
|
|
71
|
-
expect(missingApiUrlMessage).toContain('
|
|
72
|
-
expect(missingApiUrlMessage).toContain('
|
|
71
|
+
expect(missingApiUrlMessage).toContain('SIDEKICK_CLI_API_URI');
|
|
72
|
+
expect(missingApiUrlMessage).toContain('sidekick.config.ts');
|
|
73
73
|
});
|
|
74
74
|
|
|
75
|
-
it('treats a blank
|
|
76
|
-
vi.stubEnv('
|
|
75
|
+
it('treats a blank SIDEKICK_CLI_API_URI as unset', async () => {
|
|
76
|
+
vi.stubEnv('SIDEKICK_CLI_API_URI', ' ');
|
|
77
77
|
|
|
78
78
|
await expect(Effect.runPromise(getBaseUrl)).rejects.toThrow(
|
|
79
79
|
missingApiUrlMessage,
|
|
80
80
|
);
|
|
81
81
|
});
|
|
82
82
|
|
|
83
|
-
it('falls back to
|
|
84
|
-
vi.stubEnv('
|
|
85
|
-
mocks.
|
|
83
|
+
it('falls back to sidekick.config.ts when SIDEKICK_CLI_API_URI is blank', async () => {
|
|
84
|
+
vi.stubEnv('SIDEKICK_CLI_API_URI', ' ');
|
|
85
|
+
mocks.readSidekickConfigFile.mockResolvedValue({
|
|
86
86
|
apiURI: 'https://api.config.example',
|
|
87
87
|
});
|
|
88
88
|
|
|
@@ -91,16 +91,16 @@ describe('API URL configuration', () => {
|
|
|
91
91
|
);
|
|
92
92
|
});
|
|
93
93
|
|
|
94
|
-
it('uses
|
|
95
|
-
vi.stubEnv('
|
|
94
|
+
it('uses SIDEKICK_CLI_API_URI unchanged', async () => {
|
|
95
|
+
vi.stubEnv('SIDEKICK_CLI_API_URI', 'https://api.env.example/');
|
|
96
96
|
|
|
97
97
|
await expect(Effect.runPromise(getBaseUrl)).resolves.toBe(
|
|
98
98
|
'https://api.env.example/',
|
|
99
99
|
);
|
|
100
100
|
});
|
|
101
101
|
|
|
102
|
-
it('reads apiURI from
|
|
103
|
-
mocks.
|
|
102
|
+
it('reads apiURI from sidekick.config.ts', async () => {
|
|
103
|
+
mocks.readSidekickConfigFile.mockResolvedValue({
|
|
104
104
|
apiURI: 'https://api.config.example',
|
|
105
105
|
});
|
|
106
106
|
|
|
@@ -110,7 +110,7 @@ describe('API URL configuration', () => {
|
|
|
110
110
|
});
|
|
111
111
|
|
|
112
112
|
it('uses the local server in CLI dev mode', async () => {
|
|
113
|
-
vi.stubEnv('
|
|
113
|
+
vi.stubEnv('SIDEKICK_CLI_DEV', 'true');
|
|
114
114
|
|
|
115
115
|
await expect(Effect.runPromise(getBaseUrl)).resolves.toBe(
|
|
116
116
|
'http://localhost:8888',
|
|
@@ -123,11 +123,11 @@ describe('dashboard URL without configuration', () => {
|
|
|
123
123
|
await expect(Effect.runPromise(getDashUrl)).rejects.toThrow(
|
|
124
124
|
missingDashUrlMessage,
|
|
125
125
|
);
|
|
126
|
-
expect(missingDashUrlMessage).toContain('
|
|
126
|
+
expect(missingDashUrlMessage).toContain('SIDEKICK_CLI_DASH_URI');
|
|
127
127
|
});
|
|
128
128
|
|
|
129
|
-
it('treats a blank
|
|
130
|
-
vi.stubEnv('
|
|
129
|
+
it('treats a blank SIDEKICK_CLI_DASH_URI as unset', async () => {
|
|
130
|
+
vi.stubEnv('SIDEKICK_CLI_DASH_URI', ' ');
|
|
131
131
|
|
|
132
132
|
await expect(Effect.runPromise(getDashUrl)).rejects.toThrow(
|
|
133
133
|
missingDashUrlMessage,
|
|
@@ -140,7 +140,7 @@ describe('dashboard URL without configuration', () => {
|
|
|
140
140
|
});
|
|
141
141
|
|
|
142
142
|
it('uses the local dashboard in CLI dev mode', async () => {
|
|
143
|
-
vi.stubEnv('
|
|
143
|
+
vi.stubEnv('SIDEKICK_CLI_DEV', 'true');
|
|
144
144
|
|
|
145
145
|
await expect(Effect.runPromise(getDashUrl)).resolves.toBe(
|
|
146
146
|
'http://localhost:3000',
|
|
@@ -149,9 +149,9 @@ describe('dashboard URL without configuration', () => {
|
|
|
149
149
|
});
|
|
150
150
|
|
|
151
151
|
describe('indexing job dashboard links', () => {
|
|
152
|
-
it('reads dashURI from
|
|
152
|
+
it('reads dashURI from sidekick.config.ts', async () => {
|
|
153
153
|
const { readDashOrigin } = await import('../src/old.js');
|
|
154
|
-
mocks.
|
|
154
|
+
mocks.readSidekickConfigFile.mockResolvedValue({
|
|
155
155
|
dashURI: 'https://dash.config.example',
|
|
156
156
|
});
|
|
157
157
|
await expect(readDashOrigin()).resolves.toBe('https://dash.config.example');
|
|
@@ -2,231 +2,43 @@ import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
|
2
2
|
import { tmpdir } from 'node:os';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
envNameForDisplay,
|
|
8
|
-
legacyEnvName,
|
|
9
|
-
} from '../src/util/envAliases.ts';
|
|
10
|
-
import {
|
|
11
|
-
getEmailReadCandidates,
|
|
12
|
-
getPermsReadCandidates,
|
|
13
|
-
getSchemaReadCandidates,
|
|
14
|
-
withSidekickFileNames,
|
|
15
|
-
} from '../src/util/findConfigCandidates.ts';
|
|
16
|
-
import { readInstantConfigFile } from '../src/util/instantConfig.ts';
|
|
5
|
+
import { getSchemaReadCandidates } from '../src/util/findConfigCandidates.ts';
|
|
6
|
+
import { loadEnv } from '../src/util/loadEnv.ts';
|
|
17
7
|
|
|
18
|
-
describe('
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
expect(legacyEnvName('SIDEKICK_SCHEMA_FILE_PATH')).toBe(
|
|
23
|
-
'INSTANT_SCHEMA_FILE_PATH',
|
|
24
|
-
);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
test('keeps a framework prefix', () => {
|
|
28
|
-
expect(legacyEnvName('NEXT_PUBLIC_SIDEKICK_APP_ID')).toBe(
|
|
29
|
-
'NEXT_PUBLIC_INSTANT_APP_ID',
|
|
30
|
-
);
|
|
31
|
-
expect(legacyEnvName('VITE_SIDEKICK_APP_ID')).toBe('VITE_INSTANT_APP_ID');
|
|
32
|
-
expect(legacyEnvName('PUBLIC_SIDEKICK_APP_ID')).toBe(
|
|
33
|
-
'PUBLIC_INSTANT_APP_ID',
|
|
34
|
-
);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test('ignores every other name', () => {
|
|
38
|
-
expect(legacyEnvName('INSTANT_APP_ID')).toBeNull();
|
|
39
|
-
expect(legacyEnvName('PATH')).toBeNull();
|
|
40
|
-
expect(legacyEnvName('SIDEKICK')).toBeNull();
|
|
41
|
-
expect(legacyEnvName('SIDEKICK_')).toBeNull();
|
|
42
|
-
expect(legacyEnvName('MYSIDEKICK_APP_ID')).toBeNull();
|
|
43
|
-
expect(legacyEnvName('sidekick_app_id')).toBeNull();
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
describe('applyEnvAliases', () => {
|
|
48
|
-
test('a SIDEKICK_ variable sets its INSTANT_ name', () => {
|
|
49
|
-
const env: Record<string, string | undefined> = {
|
|
50
|
-
SIDEKICK_CLI_API_URI: 'https://new.example',
|
|
51
|
-
NEXT_PUBLIC_SIDEKICK_APP_ID: 'new-app',
|
|
52
|
-
PATH: '/bin',
|
|
53
|
-
};
|
|
54
|
-
expect(applyEnvAliases(env)).toEqual({
|
|
55
|
-
INSTANT_CLI_API_URI: 'SIDEKICK_CLI_API_URI',
|
|
56
|
-
NEXT_PUBLIC_INSTANT_APP_ID: 'NEXT_PUBLIC_SIDEKICK_APP_ID',
|
|
57
|
-
});
|
|
58
|
-
expect(env.INSTANT_CLI_API_URI).toBe('https://new.example');
|
|
59
|
-
expect(env.NEXT_PUBLIC_INSTANT_APP_ID).toBe('new-app');
|
|
60
|
-
expect(env.PATH).toBe('/bin');
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
test('the SIDEKICK_ name wins when both are set', () => {
|
|
64
|
-
const env: Record<string, string | undefined> = {
|
|
65
|
-
INSTANT_APP_ID: 'old-app',
|
|
66
|
-
SIDEKICK_APP_ID: 'new-app',
|
|
67
|
-
};
|
|
68
|
-
applyEnvAliases(env);
|
|
69
|
-
expect(env.INSTANT_APP_ID).toBe('new-app');
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test('a blank SIDEKICK_ value counts as unset', () => {
|
|
73
|
-
const env: Record<string, string | undefined> = {
|
|
74
|
-
INSTANT_APP_ID: 'old-app',
|
|
75
|
-
SIDEKICK_APP_ID: ' ',
|
|
76
|
-
SIDEKICK_ADMIN_TOKEN: '',
|
|
77
|
-
};
|
|
78
|
-
expect(applyEnvAliases(env)).toEqual({});
|
|
79
|
-
expect(env.INSTANT_APP_ID).toBe('old-app');
|
|
80
|
-
expect('INSTANT_ADMIN_TOKEN' in env).toBe(false);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
test('the INSTANT_ names keep working on their own', () => {
|
|
84
|
-
const env: Record<string, string | undefined> = {
|
|
85
|
-
INSTANT_APP_ID: 'old-app',
|
|
86
|
-
};
|
|
87
|
-
expect(applyEnvAliases(env)).toEqual({});
|
|
88
|
-
expect(env).toEqual({ INSTANT_APP_ID: 'old-app' });
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
describe('on process.env', () => {
|
|
92
|
-
afterEach(() => {
|
|
93
|
-
vi.unstubAllEnvs();
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
test('messages show the name the value was set under', () => {
|
|
97
|
-
vi.stubEnv('SIDEKICK_PERMS_FILE_PATH', 'perms/custom.ts');
|
|
98
|
-
vi.stubEnv('INSTANT_PERMS_FILE_PATH', undefined);
|
|
99
|
-
vi.stubEnv('INSTANT_EMAIL_FILE_PATH', 'email/custom.ts');
|
|
100
|
-
applyEnvAliases();
|
|
101
|
-
|
|
102
|
-
expect(process.env.INSTANT_PERMS_FILE_PATH).toBe('perms/custom.ts');
|
|
103
|
-
expect(envNameForDisplay('INSTANT_PERMS_FILE_PATH')).toBe(
|
|
104
|
-
'SIDEKICK_PERMS_FILE_PATH',
|
|
105
|
-
);
|
|
106
|
-
expect(envNameForDisplay('INSTANT_EMAIL_FILE_PATH')).toBe(
|
|
107
|
-
'INSTANT_EMAIL_FILE_PATH',
|
|
108
|
-
);
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
describe('sidekick.* config file names', () => {
|
|
114
|
-
const transform = (code: string) => code;
|
|
115
|
-
|
|
116
|
-
test('each instant.* candidate gets a sidekick.* one, listed first', () => {
|
|
117
|
-
const candidates = [
|
|
118
|
-
{ files: 'instant.schema', extensions: ['ts'], transform },
|
|
119
|
-
{ files: 'src/lib/instant.schema', extensions: ['ts'], transform },
|
|
120
|
-
{ files: 'app/instant.schema', extensions: ['ts'], transform },
|
|
121
|
-
];
|
|
122
|
-
expect(withSidekickFileNames(candidates).map((c) => c.files)).toEqual([
|
|
123
|
-
'sidekick.schema',
|
|
124
|
-
'src/lib/sidekick.schema',
|
|
125
|
-
'app/sidekick.schema',
|
|
126
|
-
'instant.schema',
|
|
127
|
-
'src/lib/instant.schema',
|
|
128
|
-
'app/instant.schema',
|
|
129
|
-
]);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
test('only the file name changes', () => {
|
|
133
|
-
const candidates = [
|
|
134
|
-
{ files: 'src/instant.app/instant.perms', transform },
|
|
135
|
-
{ files: 'my-instant.email', transform },
|
|
136
|
-
];
|
|
137
|
-
expect(withSidekickFileNames(candidates).map((c) => c.files)).toEqual([
|
|
138
|
-
'src/instant.app/sidekick.perms',
|
|
139
|
-
'src/instant.app/instant.perms',
|
|
140
|
-
'my-instant.email',
|
|
141
|
-
]);
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
describe('read candidates', () => {
|
|
145
|
-
beforeEach(() => {
|
|
146
|
-
vi.stubEnv('INSTANT_SCHEMA_FILE_PATH', undefined);
|
|
147
|
-
vi.stubEnv('INSTANT_PERMS_FILE_PATH', undefined);
|
|
148
|
-
vi.stubEnv('INSTANT_EMAIL_FILE_PATH', undefined);
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
afterEach(() => {
|
|
152
|
-
vi.unstubAllEnvs();
|
|
153
|
-
vi.restoreAllMocks();
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
test.each([
|
|
157
|
-
['schema', getSchemaReadCandidates],
|
|
158
|
-
['perms', getPermsReadCandidates],
|
|
159
|
-
['email', () => getEmailReadCandidates()],
|
|
160
|
-
] as const)('%s: sidekick.* comes before instant.*', (kind, candidates) => {
|
|
161
|
-
const files = candidates().map((c) => c.files);
|
|
162
|
-
const firstLegacy = files.findIndex((f) => f.includes('instant.'));
|
|
163
|
-
|
|
164
|
-
expect(files[0]).toBe(`sidekick.${kind}`);
|
|
165
|
-
expect(files).toContain(`app/sidekick.${kind}`);
|
|
166
|
-
expect(files).toContain(`instant.${kind}`);
|
|
167
|
-
expect(files).toContain(`app/instant.${kind}`);
|
|
168
|
-
expect(firstLegacy).toBeGreaterThan(0);
|
|
169
|
-
expect(
|
|
170
|
-
files.slice(firstLegacy).some((f) => f.includes('sidekick.')),
|
|
171
|
-
).toBe(false);
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
test('an explicit path is used as it is', () => {
|
|
175
|
-
vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
176
|
-
vi.stubEnv('INSTANT_SCHEMA_FILE_PATH', 'db/instant.schema.ts');
|
|
177
|
-
expect(getSchemaReadCandidates().map((c) => c.files)).toEqual([
|
|
178
|
-
'db/instant.schema.ts',
|
|
179
|
-
]);
|
|
180
|
-
});
|
|
181
|
-
});
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
describe('sidekick.config', () => {
|
|
8
|
+
describe('environment variable names', () => {
|
|
9
|
+
// The prefix from before the rename, spelled in two parts so that the
|
|
10
|
+
// rename leaves it alone.
|
|
11
|
+
const OLD = 'INSTANT' + '_';
|
|
185
12
|
let dir: string;
|
|
186
13
|
let cwd: { mockRestore: () => void };
|
|
187
14
|
|
|
188
15
|
beforeEach(() => {
|
|
189
|
-
dir = mkdtempSync(join(tmpdir(), 'sidekick-cli-
|
|
190
|
-
writeFileSync(join(dir, 'package.json'), '{"name":"config-test"}');
|
|
16
|
+
dir = mkdtempSync(join(tmpdir(), 'sidekick-cli-env-'));
|
|
191
17
|
cwd = vi.spyOn(process, 'cwd').mockReturnValue(dir);
|
|
192
18
|
});
|
|
193
19
|
|
|
194
20
|
afterEach(() => {
|
|
195
21
|
cwd.mockRestore();
|
|
196
22
|
rmSync(dir, { recursive: true, force: true });
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
test('sidekick.config wins over instant.config', async () => {
|
|
220
|
-
writeFileSync(
|
|
221
|
-
join(dir, 'instant.config.json'),
|
|
222
|
-
JSON.stringify({ apiURI: 'https://old.example' }),
|
|
223
|
-
);
|
|
224
|
-
writeFileSync(
|
|
225
|
-
join(dir, 'sidekick.config.json'),
|
|
226
|
-
JSON.stringify({ apiURI: 'https://new.example' }),
|
|
227
|
-
);
|
|
228
|
-
expect(await readInstantConfigFile()).toEqual({
|
|
229
|
-
apiURI: 'https://new.example',
|
|
230
|
-
});
|
|
23
|
+
vi.unstubAllEnvs();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('loading the env files copies no old name onto a new one', () => {
|
|
27
|
+
vi.stubEnv('SIDEKICK_CLI_API_URI', undefined);
|
|
28
|
+
vi.stubEnv('SIDEKICK_APP_ID', undefined);
|
|
29
|
+
// Stubbed so that unstubAllEnvs removes what the .env file sets.
|
|
30
|
+
vi.stubEnv(`${OLD}CLI_API_URI`, undefined);
|
|
31
|
+
vi.stubEnv(`${OLD}APP_ID`, 'old-app');
|
|
32
|
+
writeFileSync(join(dir, '.env'), `${OLD}CLI_API_URI=https://old.example\n`);
|
|
33
|
+
loadEnv();
|
|
34
|
+
expect(process.env[`${OLD}CLI_API_URI`]).toBe('https://old.example');
|
|
35
|
+
expect(process.env.SIDEKICK_CLI_API_URI).toBeUndefined();
|
|
36
|
+
expect(process.env.SIDEKICK_APP_ID).toBeUndefined();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('the variable name from before the rename is not read', () => {
|
|
40
|
+
// Spelled in two parts so that the rename leaves it alone.
|
|
41
|
+
vi.stubEnv('INSTANT' + '_SCHEMA_FILE_PATH', 'db/sidekick.schema.ts');
|
|
42
|
+
expect(getSchemaReadCandidates()[0].files).toBe('sidekick.schema');
|
|
231
43
|
});
|
|
232
44
|
});
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
|
|
5
|
+
import { getSidekickModuleName } from '../src/context/projectInfo.ts';
|
|
6
|
+
import {
|
|
7
|
+
getEmailPathToWrite,
|
|
8
|
+
getEmailReadCandidates,
|
|
9
|
+
getPermsPathToWrite,
|
|
10
|
+
getPermsReadCandidates,
|
|
11
|
+
getSchemaPathToWrite,
|
|
12
|
+
getSchemaReadCandidates,
|
|
13
|
+
} from '../src/util/findConfigCandidates.ts';
|
|
14
|
+
import { readSidekickConfigFile } from '../src/util/sidekickConfig.ts';
|
|
15
|
+
import { readLocalPermsFile } from '../src/old.js';
|
|
16
|
+
|
|
17
|
+
// The file name prefix and the package scope from before the rename, spelled
|
|
18
|
+
// in two parts so that the rename leaves them alone.
|
|
19
|
+
const OLD = 'ins' + 'tant.';
|
|
20
|
+
const OLD_SCOPE = '@ins' + 'tantdb/';
|
|
21
|
+
|
|
22
|
+
let dir: string;
|
|
23
|
+
let cwd: { mockRestore: () => void };
|
|
24
|
+
|
|
25
|
+
beforeEach(() => {
|
|
26
|
+
dir = mkdtempSync(join(tmpdir(), 'sidekick-cli-files-'));
|
|
27
|
+
writeFileSync(join(dir, 'package.json'), '{"name":"files-test"}');
|
|
28
|
+
cwd = vi.spyOn(process, 'cwd').mockReturnValue(dir);
|
|
29
|
+
vi.stubEnv('SIDEKICK_SCHEMA_FILE_PATH', undefined);
|
|
30
|
+
vi.stubEnv('SIDEKICK_PERMS_FILE_PATH', undefined);
|
|
31
|
+
vi.stubEnv('SIDEKICK_EMAIL_FILE_PATH', undefined);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
afterEach(() => {
|
|
35
|
+
cwd.mockRestore();
|
|
36
|
+
vi.unstubAllEnvs();
|
|
37
|
+
rmSync(dir, { recursive: true, force: true });
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe('sidekick.* file names', () => {
|
|
41
|
+
test.each([
|
|
42
|
+
['schema', getSchemaReadCandidates],
|
|
43
|
+
['perms', getPermsReadCandidates],
|
|
44
|
+
['email', () => getEmailReadCandidates()],
|
|
45
|
+
] as const)('%s: only sidekick.* files are read', (kind, candidates) => {
|
|
46
|
+
mkdirSync(join(dir, 'src', 'lib'), { recursive: true });
|
|
47
|
+
mkdirSync(join(dir, 'lib'));
|
|
48
|
+
const files = candidates().map((c) => c.files);
|
|
49
|
+
|
|
50
|
+
expect(files[0]).toBe(`sidekick.${kind}`);
|
|
51
|
+
expect(files).toContain(join('src', 'lib', `sidekick.${kind}`));
|
|
52
|
+
expect(files).toContain(join('lib', `sidekick.${kind}`));
|
|
53
|
+
expect(files).toContain(`app/sidekick.${kind}`);
|
|
54
|
+
expect(files.every((f) => f.endsWith(`sidekick.${kind}`))).toBe(true);
|
|
55
|
+
expect(files.some((f) => f.includes(OLD))).toBe(false);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('new files get sidekick.* names', () => {
|
|
59
|
+
expect(getSchemaPathToWrite()).toBe('sidekick.schema.ts');
|
|
60
|
+
expect(getPermsPathToWrite()).toBe('sidekick.perms.ts');
|
|
61
|
+
expect(getEmailPathToWrite()).toBe('sidekick.email.ts');
|
|
62
|
+
|
|
63
|
+
mkdirSync(join(dir, 'src'));
|
|
64
|
+
expect(getSchemaPathToWrite()).toBe(join('src', 'sidekick.schema.ts'));
|
|
65
|
+
expect(getPermsPathToWrite()).toBe(join('src', 'sidekick.perms.ts'));
|
|
66
|
+
expect(getEmailPathToWrite()).toBe(join('src', 'sidekick.email.ts'));
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test('a perms file under the old name is not read', async () => {
|
|
70
|
+
const perms = 'export default { todos: { allow: { view: "true" } } };\n';
|
|
71
|
+
writeFileSync(join(dir, `${OLD}perms.js`), perms);
|
|
72
|
+
expect(await readLocalPermsFile()).toBeUndefined();
|
|
73
|
+
|
|
74
|
+
writeFileSync(join(dir, 'sidekick.perms.js'), perms);
|
|
75
|
+
expect(await readLocalPermsFile()).toEqual({
|
|
76
|
+
path: 'sidekick.perms.js',
|
|
77
|
+
perms: { todos: { allow: { view: 'true' } } },
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe('sidekick.config', () => {
|
|
83
|
+
test('sidekick.config.json is read', async () => {
|
|
84
|
+
writeFileSync(
|
|
85
|
+
join(dir, 'sidekick.config.json'),
|
|
86
|
+
JSON.stringify({ apiURI: 'https://new.example' }),
|
|
87
|
+
);
|
|
88
|
+
expect(await readSidekickConfigFile()).toEqual({
|
|
89
|
+
apiURI: 'https://new.example',
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test('a config file under the old name is not read', async () => {
|
|
94
|
+
writeFileSync(
|
|
95
|
+
join(dir, `${OLD}config.json`),
|
|
96
|
+
JSON.stringify({ apiURI: 'https://old.example' }),
|
|
97
|
+
);
|
|
98
|
+
// It stops with a message instead (oldConfigFiles.test.ts).
|
|
99
|
+
await expect(readSidekickConfigFile()).rejects.toThrow('Rename it to');
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
describe('SDK detection', () => {
|
|
104
|
+
test('a project on @sidekickdb/* resolves to it', () => {
|
|
105
|
+
expect(
|
|
106
|
+
getSidekickModuleName({ dependencies: { '@sidekickdb/core': '^2.0.0' } }),
|
|
107
|
+
).toBe('@sidekickdb/core');
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test('packages under the old scope are not detected', () => {
|
|
111
|
+
expect(
|
|
112
|
+
getSidekickModuleName({
|
|
113
|
+
dependencies: { [`${OLD_SCOPE}react`]: '^0.22.0' },
|
|
114
|
+
devDependencies: { [`${OLD_SCOPE}admin`]: '*' },
|
|
115
|
+
}),
|
|
116
|
+
).toBeUndefined();
|
|
117
|
+
});
|
|
118
|
+
});
|