@sidekickdb/cli 2.0.0 → 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.
Files changed (265) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/README.md +5 -5
  3. package/__tests__/appCommands.test.ts +8 -8
  4. package/__tests__/auth.test.ts +11 -65
  5. package/__tests__/authClientAddApple.test.ts +3 -3
  6. package/__tests__/authClientAddClerk.test.ts +8 -13
  7. package/__tests__/authClientAddGithub.test.ts +5 -5
  8. package/__tests__/authClientAddGoogle.test.ts +3 -3
  9. package/__tests__/authClientAddLinkedin.test.ts +3 -3
  10. package/__tests__/authClientList.test.ts +4 -3
  11. package/__tests__/authClientUpdate.test.ts +6 -8
  12. package/__tests__/authOriginManagement.test.ts +11 -11
  13. package/__tests__/backups.test.ts +2 -2
  14. package/__tests__/config.test.ts +34 -34
  15. package/__tests__/configAliases.test.ts +27 -215
  16. package/__tests__/configFileNames.test.ts +118 -0
  17. package/__tests__/e2e/cli.e2e.test.ts +102 -102
  18. package/__tests__/e2e/helpers.ts +5 -5
  19. package/__tests__/effectHelpers.ts +3 -3
  20. package/__tests__/emailVerification.test.ts +31 -0
  21. package/__tests__/oldConfigFiles.test.ts +254 -0
  22. package/__tests__/webhooks.test.ts +2 -2
  23. package/dist/auth/index.d.ts.map +1 -1
  24. package/dist/auth/index.js +6 -43
  25. package/dist/auth/index.js.map +1 -1
  26. package/dist/commands/app/delete.d.ts +2 -2
  27. package/dist/commands/app/delete.d.ts.map +1 -1
  28. package/dist/commands/app/delete.js +2 -2
  29. package/dist/commands/app/delete.js.map +1 -1
  30. package/dist/commands/app/list.d.ts +2 -2
  31. package/dist/commands/app/list.d.ts.map +1 -1
  32. package/dist/commands/app/list.js +2 -2
  33. package/dist/commands/app/list.js.map +1 -1
  34. package/dist/commands/auth/client/add.d.ts +1 -1
  35. package/dist/commands/auth/client/add.d.ts.map +1 -1
  36. package/dist/commands/auth/client/delete.d.ts +2 -2
  37. package/dist/commands/auth/client/delete.d.ts.map +1 -1
  38. package/dist/commands/auth/client/delete.js +2 -2
  39. package/dist/commands/auth/client/delete.js.map +1 -1
  40. package/dist/commands/auth/client/list.d.ts +1 -1
  41. package/dist/commands/auth/client/list.d.ts.map +1 -1
  42. package/dist/commands/auth/client/update.d.ts +1 -1
  43. package/dist/commands/auth/client/update.d.ts.map +1 -1
  44. package/dist/commands/auth/email/pull.d.ts +4 -4
  45. package/dist/commands/auth/email/pull.d.ts.map +1 -1
  46. package/dist/commands/auth/email/pull.js +5 -2
  47. package/dist/commands/auth/email/pull.js.map +1 -1
  48. package/dist/commands/auth/email/push.d.ts +2 -2
  49. package/dist/commands/auth/email/push.d.ts.map +1 -1
  50. package/dist/commands/auth/email/push.js +3 -3
  51. package/dist/commands/auth/email/push.js.map +1 -1
  52. package/dist/commands/auth/email/resend.d.ts +1 -1
  53. package/dist/commands/auth/email/resend.d.ts.map +1 -1
  54. package/dist/commands/auth/email/reset.d.ts +2 -2
  55. package/dist/commands/auth/email/reset.d.ts.map +1 -1
  56. package/dist/commands/auth/email/reset.js +3 -3
  57. package/dist/commands/auth/email/reset.js.map +1 -1
  58. package/dist/commands/auth/email/status.d.ts +4 -4
  59. package/dist/commands/auth/email/status.d.ts.map +1 -1
  60. package/dist/commands/auth/email/status.js +4 -4
  61. package/dist/commands/auth/email/status.js.map +1 -1
  62. package/dist/commands/auth/email/verify.d.ts +1 -1
  63. package/dist/commands/auth/email/verify.d.ts.map +1 -1
  64. package/dist/commands/auth/email/verify.js +1 -1
  65. package/dist/commands/auth/email/verify.js.map +1 -1
  66. package/dist/commands/auth/origin/add.d.ts +1 -1
  67. package/dist/commands/auth/origin/add.d.ts.map +1 -1
  68. package/dist/commands/auth/origin/delete.d.ts +1 -1
  69. package/dist/commands/auth/origin/delete.d.ts.map +1 -1
  70. package/dist/commands/auth/origin/list.d.ts +1 -1
  71. package/dist/commands/auth/origin/list.d.ts.map +1 -1
  72. package/dist/commands/claim.d.ts +2 -2
  73. package/dist/commands/claim.d.ts.map +1 -1
  74. package/dist/commands/claim.js +2 -2
  75. package/dist/commands/claim.js.map +1 -1
  76. package/dist/commands/info.js +2 -2
  77. package/dist/commands/info.js.map +1 -1
  78. package/dist/commands/init.d.ts +1 -1
  79. package/dist/commands/init.d.ts.map +1 -1
  80. package/dist/commands/init.js +3 -0
  81. package/dist/commands/init.js.map +1 -1
  82. package/dist/commands/initWithoutFiles.d.ts.map +1 -1
  83. package/dist/commands/initWithoutFiles.js +7 -3
  84. package/dist/commands/initWithoutFiles.js.map +1 -1
  85. package/dist/commands/login.d.ts +1 -1
  86. package/dist/commands/login.d.ts.map +1 -1
  87. package/dist/commands/pull.d.ts +1 -1
  88. package/dist/commands/pull.d.ts.map +1 -1
  89. package/dist/commands/pull.js +4 -0
  90. package/dist/commands/pull.js.map +1 -1
  91. package/dist/commands/push.d.ts +1 -1
  92. package/dist/commands/push.d.ts.map +1 -1
  93. package/dist/commands/push.js +4 -0
  94. package/dist/commands/push.js.map +1 -1
  95. package/dist/commands/query.d.ts +1 -1
  96. package/dist/commands/query.d.ts.map +1 -1
  97. package/dist/commands/query.js +2 -2
  98. package/dist/commands/query.js.map +1 -1
  99. package/dist/context/authToken.d.ts +2 -2
  100. package/dist/context/authToken.d.ts.map +1 -1
  101. package/dist/context/authToken.js +6 -4
  102. package/dist/context/authToken.js.map +1 -1
  103. package/dist/context/currentApp.d.ts +3 -3
  104. package/dist/context/currentApp.d.ts.map +1 -1
  105. package/dist/context/currentApp.js +20 -20
  106. package/dist/context/currentApp.js.map +1 -1
  107. package/dist/context/globalOpts.d.ts +1 -1
  108. package/dist/context/globalOpts.js +1 -1
  109. package/dist/context/globalOpts.js.map +1 -1
  110. package/dist/context/platformApi.d.ts +3 -3
  111. package/dist/context/platformApi.d.ts.map +1 -1
  112. package/dist/context/platformApi.js +3 -3
  113. package/dist/context/platformApi.js.map +1 -1
  114. package/dist/context/projectInfo.d.ts +4 -4
  115. package/dist/context/projectInfo.d.ts.map +1 -1
  116. package/dist/context/projectInfo.js +12 -18
  117. package/dist/context/projectInfo.js.map +1 -1
  118. package/dist/index.d.ts.map +1 -1
  119. package/dist/index.js +42 -49
  120. package/dist/index.js.map +1 -1
  121. package/dist/layer.d.ts +4 -4
  122. package/dist/layer.d.ts.map +1 -1
  123. package/dist/layer.js +7 -7
  124. package/dist/layer.js.map +1 -1
  125. package/dist/lib/backupDownload.js +1 -1
  126. package/dist/lib/backupDownload.js.map +1 -1
  127. package/dist/lib/config.d.ts +2 -2
  128. package/dist/lib/config.d.ts.map +1 -1
  129. package/dist/lib/config.js +21 -23
  130. package/dist/lib/config.js.map +1 -1
  131. package/dist/lib/createApp.d.ts +2 -2
  132. package/dist/lib/createApp.d.ts.map +1 -1
  133. package/dist/lib/createApp.js +2 -2
  134. package/dist/lib/createApp.js.map +1 -1
  135. package/dist/lib/email.d.ts +38 -6
  136. package/dist/lib/email.d.ts.map +1 -1
  137. package/dist/lib/email.js +22 -13
  138. package/dist/lib/email.js.map +1 -1
  139. package/dist/lib/handleEnv.js +4 -4
  140. package/dist/lib/handleEnv.js.map +1 -1
  141. package/dist/lib/http.d.ts +13 -13
  142. package/dist/lib/http.d.ts.map +1 -1
  143. package/dist/lib/http.js +12 -12
  144. package/dist/lib/http.js.map +1 -1
  145. package/dist/lib/login.d.ts +4 -4
  146. package/dist/lib/login.d.ts.map +1 -1
  147. package/dist/lib/login.js +4 -4
  148. package/dist/lib/login.js.map +1 -1
  149. package/dist/lib/oauth.d.ts +10 -10
  150. package/dist/lib/oauth.d.ts.map +1 -1
  151. package/dist/lib/oauth.js +7 -7
  152. package/dist/lib/oauth.js.map +1 -1
  153. package/dist/lib/platformApi.d.ts +2 -2
  154. package/dist/lib/platformApi.d.ts.map +1 -1
  155. package/dist/lib/platformApi.js +2 -2
  156. package/dist/lib/platformApi.js.map +1 -1
  157. package/dist/lib/pullPerms.d.ts +2 -2
  158. package/dist/lib/pullPerms.d.ts.map +1 -1
  159. package/dist/lib/pullPerms.js +7 -4
  160. package/dist/lib/pullPerms.js.map +1 -1
  161. package/dist/lib/pullSchema.d.ts +2 -2
  162. package/dist/lib/pullSchema.d.ts.map +1 -1
  163. package/dist/lib/pullSchema.js +8 -5
  164. package/dist/lib/pullSchema.js.map +1 -1
  165. package/dist/lib/pushPerms.d.ts +2 -2
  166. package/dist/lib/pushPerms.d.ts.map +1 -1
  167. package/dist/lib/pushPerms.js +6 -3
  168. package/dist/lib/pushPerms.js.map +1 -1
  169. package/dist/lib/pushSchema.d.ts +2 -2
  170. package/dist/lib/pushSchema.d.ts.map +1 -1
  171. package/dist/lib/pushSchema.js +18 -7
  172. package/dist/lib/pushSchema.js.map +1 -1
  173. package/dist/lib/webhooks.d.ts +1 -1
  174. package/dist/lib/webhooks.d.ts.map +1 -1
  175. package/dist/old.js +9 -9
  176. package/dist/old.js.map +1 -1
  177. package/dist/renderSchemaPlan.d.ts +2 -2
  178. package/dist/renderSchemaPlan.d.ts.map +1 -1
  179. package/dist/renderSchemaPlan.js.map +1 -1
  180. package/dist/util/findConfigCandidates.d.ts +0 -20
  181. package/dist/util/findConfigCandidates.d.ts.map +1 -1
  182. package/dist/util/findConfigCandidates.js +44 -63
  183. package/dist/util/findConfigCandidates.js.map +1 -1
  184. package/dist/util/getAppName.d.ts +2 -2
  185. package/dist/util/getAppName.d.ts.map +1 -1
  186. package/dist/util/getAppName.js +2 -2
  187. package/dist/util/getAppName.js.map +1 -1
  188. package/dist/util/isHeadlessEnvironment.js +1 -1
  189. package/dist/util/isHeadlessEnvironment.js.map +1 -1
  190. package/dist/util/loadConfig.d.ts.map +1 -1
  191. package/dist/util/loadConfig.js +4 -11
  192. package/dist/util/loadConfig.js.map +1 -1
  193. package/dist/util/loadEnv.d.ts.map +1 -1
  194. package/dist/util/loadEnv.js +0 -6
  195. package/dist/util/loadEnv.js.map +1 -1
  196. package/dist/util/oldConfigFiles.d.ts +30 -0
  197. package/dist/util/oldConfigFiles.d.ts.map +1 -0
  198. package/dist/util/oldConfigFiles.js +104 -0
  199. package/dist/util/oldConfigFiles.js.map +1 -0
  200. package/dist/util/projectDir.d.ts +1 -1
  201. package/dist/util/projectDir.d.ts.map +1 -1
  202. package/dist/util/projectDir.js +6 -9
  203. package/dist/util/projectDir.js.map +1 -1
  204. package/dist/util/sidekickConfig.d.ts +9 -0
  205. package/dist/util/sidekickConfig.d.ts.map +1 -0
  206. package/dist/util/sidekickConfig.js +18 -0
  207. package/dist/util/sidekickConfig.js.map +1 -0
  208. package/package.json +6 -7
  209. package/src/auth/index.ts +6 -54
  210. package/src/commands/app/delete.ts +2 -2
  211. package/src/commands/app/list.ts +2 -2
  212. package/src/commands/auth/client/delete.ts +2 -2
  213. package/src/commands/auth/email/pull.ts +5 -2
  214. package/src/commands/auth/email/push.ts +3 -3
  215. package/src/commands/auth/email/reset.ts +5 -3
  216. package/src/commands/auth/email/status.ts +4 -4
  217. package/src/commands/auth/email/verify.ts +1 -1
  218. package/src/commands/claim.ts +2 -2
  219. package/src/commands/info.ts +2 -2
  220. package/src/commands/init.ts +3 -0
  221. package/src/commands/initWithoutFiles.ts +13 -6
  222. package/src/commands/pull.ts +6 -0
  223. package/src/commands/push.ts +6 -0
  224. package/src/commands/query.ts +2 -2
  225. package/src/context/authToken.ts +9 -5
  226. package/src/context/currentApp.ts +20 -20
  227. package/src/context/globalOpts.ts +1 -1
  228. package/src/context/platformApi.ts +3 -3
  229. package/src/context/projectInfo.ts +13 -20
  230. package/src/index.ts +42 -52
  231. package/src/layer.ts +10 -10
  232. package/src/lib/backupDownload.ts +1 -1
  233. package/src/lib/config.ts +21 -23
  234. package/src/lib/createApp.ts +2 -2
  235. package/src/lib/email.ts +30 -15
  236. package/src/lib/handleEnv.ts +4 -4
  237. package/src/lib/http.ts +28 -24
  238. package/src/lib/login.ts +4 -4
  239. package/src/lib/oauth.ts +7 -7
  240. package/src/lib/platformApi.ts +2 -2
  241. package/src/lib/pullPerms.ts +7 -4
  242. package/src/lib/pullSchema.ts +9 -6
  243. package/src/lib/pushPerms.ts +6 -3
  244. package/src/lib/pushSchema.ts +19 -7
  245. package/src/old.js +9 -9
  246. package/src/renderSchemaPlan.ts +3 -3
  247. package/src/util/findConfigCandidates.ts +45 -71
  248. package/src/util/getAppName.ts +2 -2
  249. package/src/util/isHeadlessEnvironment.ts +1 -1
  250. package/src/util/loadConfig.ts +4 -12
  251. package/src/util/loadEnv.ts +0 -8
  252. package/src/util/oldConfigFiles.ts +132 -0
  253. package/src/util/projectDir.ts +7 -9
  254. package/src/util/sidekickConfig.ts +25 -0
  255. package/__tests__/legacyPackageCompat.test.ts +0 -104
  256. package/dist/util/envAliases.d.ts +0 -25
  257. package/dist/util/envAliases.d.ts.map +0 -1
  258. package/dist/util/envAliases.js +0 -47
  259. package/dist/util/envAliases.js.map +0 -1
  260. package/dist/util/instantConfig.d.ts +0 -9
  261. package/dist/util/instantConfig.d.ts.map +0 -1
  262. package/dist/util/instantConfig.js +0 -13
  263. package/dist/util/instantConfig.js.map +0 -1
  264. package/src/util/envAliases.ts +0 -53
  265. package/src/util/instantConfig.ts +0 -21
@@ -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
- readInstantConfigFile: vi.fn(),
5
+ readSidekickConfigFile: vi.fn(),
6
6
  }));
7
7
 
8
- vi.mock('../src/util/instantConfig.ts', () => ({
9
- readInstantConfigFile: mocks.readInstantConfigFile,
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('INSTANT_CLI_API_URI', undefined);
23
- vi.stubEnv('INSTANT_CLI_DASH_URI', undefined);
24
- vi.stubEnv('INSTANT_CLI_DEV', undefined);
25
- mocks.readInstantConfigFile.mockResolvedValue({});
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 instant.config.ts', async () => {
35
- mocks.readInstantConfigFile.mockResolvedValue({
36
- dashURI: 'https://dash.instant.example',
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.instant.example',
40
+ 'https://dash.sidekick.example',
41
41
  );
42
42
  });
43
43
 
44
- it('prefers INSTANT_CLI_DASH_URI over instant.config.ts', async () => {
45
- vi.stubEnv('INSTANT_CLI_DASH_URI', 'https://dash.env.example');
46
- mocks.readInstantConfigFile.mockResolvedValue({
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('INSTANT_CLI_API_URI', 'https://api.instant.example/');
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.instant.example/runtime/oauth/callback',
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('INSTANT_CLI_API_URI');
72
- expect(missingApiUrlMessage).toContain('instant.config.ts');
71
+ expect(missingApiUrlMessage).toContain('SIDEKICK_CLI_API_URI');
72
+ expect(missingApiUrlMessage).toContain('sidekick.config.ts');
73
73
  });
74
74
 
75
- it('treats a blank INSTANT_CLI_API_URI as unset', async () => {
76
- vi.stubEnv('INSTANT_CLI_API_URI', ' ');
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 instant.config.ts when INSTANT_CLI_API_URI is blank', async () => {
84
- vi.stubEnv('INSTANT_CLI_API_URI', ' ');
85
- mocks.readInstantConfigFile.mockResolvedValue({
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 INSTANT_CLI_API_URI unchanged', async () => {
95
- vi.stubEnv('INSTANT_CLI_API_URI', 'https://api.env.example/');
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 instant.config.ts', async () => {
103
- mocks.readInstantConfigFile.mockResolvedValue({
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('INSTANT_CLI_DEV', 'true');
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('INSTANT_CLI_DASH_URI');
126
+ expect(missingDashUrlMessage).toContain('SIDEKICK_CLI_DASH_URI');
127
127
  });
128
128
 
129
- it('treats a blank INSTANT_CLI_DASH_URI as unset', async () => {
130
- vi.stubEnv('INSTANT_CLI_DASH_URI', ' ');
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('INSTANT_CLI_DEV', 'true');
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 instant.config.ts', async () => {
152
+ it('reads dashURI from sidekick.config.ts', async () => {
153
153
  const { readDashOrigin } = await import('../src/old.js');
154
- mocks.readInstantConfigFile.mockResolvedValue({
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
- applyEnvAliases,
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('legacyEnvName', () => {
19
- test('maps SIDEKICK_ names onto INSTANT_ names', () => {
20
- expect(legacyEnvName('SIDEKICK_APP_ID')).toBe('INSTANT_APP_ID');
21
- expect(legacyEnvName('SIDEKICK_CLI_API_URI')).toBe('INSTANT_CLI_API_URI');
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-config-'));
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
- test('instant.config.json still works', async () => {
200
- writeFileSync(
201
- join(dir, 'instant.config.json'),
202
- JSON.stringify({ apiURI: 'https://old.example' }),
203
- );
204
- expect(await readInstantConfigFile()).toEqual({
205
- apiURI: 'https://old.example',
206
- });
207
- });
208
-
209
- test('sidekick.config.json is read', async () => {
210
- writeFileSync(
211
- join(dir, 'sidekick.config.json'),
212
- JSON.stringify({ apiURI: 'https://new.example' }),
213
- );
214
- expect(await readInstantConfigFile()).toEqual({
215
- apiURI: 'https://new.example',
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
+ });