@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/src/lib/config.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Config, Effect, Option, Schema } from 'effect';
|
|
2
2
|
import { oauthCallbackURL } from '@sidekickdb/platform';
|
|
3
3
|
import { BadArgsError } from '../errors.ts';
|
|
4
|
-
import {
|
|
4
|
+
import { readSidekickConfigFile } from '../util/sidekickConfig.ts';
|
|
5
5
|
|
|
6
6
|
const HttpUrl = Schema.URL.pipe(
|
|
7
7
|
Schema.filter(
|
|
@@ -14,21 +14,19 @@ const HttpUrl = Schema.URL.pipe(
|
|
|
14
14
|
|
|
15
15
|
export const missingApiUrlMessage =
|
|
16
16
|
'No SidekickDB server URL configured. Set the SIDEKICK_CLI_API_URI ' +
|
|
17
|
-
'environment variable (for example SIDEKICK_CLI_API_URI=https://sidekick.example.com
|
|
18
|
-
'
|
|
19
|
-
'or add `apiURI` to sidekick.config.ts or instant.config.ts. SidekickDB has no default server.';
|
|
17
|
+
'environment variable (for example SIDEKICK_CLI_API_URI=https://sidekick.example.com) ' +
|
|
18
|
+
'or add `apiURI` to sidekick.config.ts. SidekickDB has no default server.';
|
|
20
19
|
|
|
21
20
|
export const missingDashUrlMessage =
|
|
22
21
|
'No SidekickDB dashboard URL configured. Set the SIDEKICK_CLI_DASH_URI ' +
|
|
23
|
-
'environment variable (for example SIDEKICK_CLI_DASH_URI=https://dash.sidekick.example.com
|
|
24
|
-
'
|
|
25
|
-
'or add `dashURI` to sidekick.config.ts or instant.config.ts. SidekickDB has no default dashboard.';
|
|
22
|
+
'environment variable (for example SIDEKICK_CLI_DASH_URI=https://dash.sidekick.example.com) ' +
|
|
23
|
+
'or add `dashURI` to sidekick.config.ts. SidekickDB has no default dashboard.';
|
|
26
24
|
|
|
27
25
|
export const getBaseUrl = Effect.gen(function* () {
|
|
28
|
-
const setEnv = yield* Config.string('
|
|
26
|
+
const setEnv = yield* Config.string('SIDEKICK_CLI_API_URI').pipe(
|
|
29
27
|
Config.option,
|
|
30
28
|
);
|
|
31
|
-
const dev = yield* Config.boolean('
|
|
29
|
+
const dev = yield* Config.boolean('SIDEKICK_CLI_DEV').pipe(
|
|
32
30
|
Config.withDefault(false),
|
|
33
31
|
);
|
|
34
32
|
|
|
@@ -37,17 +35,17 @@ export const getBaseUrl = Effect.gen(function* () {
|
|
|
37
35
|
return setEnv.value;
|
|
38
36
|
}
|
|
39
37
|
|
|
40
|
-
const
|
|
41
|
-
if (
|
|
42
|
-
yield* Schema.decodeUnknown(HttpUrl)(
|
|
38
|
+
const sidekickConfig = yield* Effect.tryPromise(readSidekickConfigFile);
|
|
39
|
+
if (sidekickConfig?.apiURI !== undefined) {
|
|
40
|
+
yield* Schema.decodeUnknown(HttpUrl)(sidekickConfig.apiURI).pipe(
|
|
43
41
|
Effect.mapError(() =>
|
|
44
42
|
BadArgsError.make({
|
|
45
43
|
message:
|
|
46
|
-
'Invalid apiURI in
|
|
44
|
+
'Invalid apiURI in sidekick.config.ts. Expected a valid HTTP(S) URL.',
|
|
47
45
|
}),
|
|
48
46
|
),
|
|
49
47
|
);
|
|
50
|
-
return
|
|
48
|
+
return sidekickConfig.apiURI;
|
|
51
49
|
}
|
|
52
50
|
|
|
53
51
|
if (dev) {
|
|
@@ -62,14 +60,14 @@ export const getOAuthCallbackUrl = getBaseUrl.pipe(
|
|
|
62
60
|
);
|
|
63
61
|
|
|
64
62
|
/**
|
|
65
|
-
* Dashboard URL from
|
|
66
|
-
*
|
|
63
|
+
* Dashboard URL from SIDEKICK_CLI_DASH_URI, sidekick.config.ts or
|
|
64
|
+
* SIDEKICK_CLI_DEV, or `Option.none()` when none of them is set.
|
|
67
65
|
*/
|
|
68
66
|
export const getOptionalDashUrl = Effect.gen(function* () {
|
|
69
|
-
const setEnv = yield* Config.string('
|
|
67
|
+
const setEnv = yield* Config.string('SIDEKICK_CLI_DASH_URI').pipe(
|
|
70
68
|
Config.option,
|
|
71
69
|
);
|
|
72
|
-
const dev = yield* Config.boolean('
|
|
70
|
+
const dev = yield* Config.boolean('SIDEKICK_CLI_DEV').pipe(
|
|
73
71
|
Config.withDefault(false),
|
|
74
72
|
);
|
|
75
73
|
|
|
@@ -78,17 +76,17 @@ export const getOptionalDashUrl = Effect.gen(function* () {
|
|
|
78
76
|
return Option.some(setEnv.value);
|
|
79
77
|
}
|
|
80
78
|
|
|
81
|
-
const
|
|
82
|
-
if (
|
|
83
|
-
yield* Schema.decodeUnknown(HttpUrl)(
|
|
79
|
+
const sidekickConfig = yield* Effect.tryPromise(readSidekickConfigFile);
|
|
80
|
+
if (sidekickConfig?.dashURI !== undefined) {
|
|
81
|
+
yield* Schema.decodeUnknown(HttpUrl)(sidekickConfig.dashURI).pipe(
|
|
84
82
|
Effect.mapError(() =>
|
|
85
83
|
BadArgsError.make({
|
|
86
84
|
message:
|
|
87
|
-
'Invalid dashURI in
|
|
85
|
+
'Invalid dashURI in sidekick.config.ts. Expected a valid HTTP(S) URL.',
|
|
88
86
|
}),
|
|
89
87
|
),
|
|
90
88
|
);
|
|
91
|
-
return Option.some(
|
|
89
|
+
return Option.some(sidekickConfig.dashURI);
|
|
92
90
|
}
|
|
93
91
|
|
|
94
92
|
if (dev) {
|
package/src/lib/createApp.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import { Data, Effect, Schema } from 'effect';
|
|
3
|
-
import {
|
|
3
|
+
import { SidekickHttpAuthed } from './http.ts';
|
|
4
4
|
import { HttpClientRequest, HttpClientResponse } from '@effect/platform';
|
|
5
5
|
|
|
6
6
|
export class CreateAppError extends Data.TaggedError('CreateAppError')<{
|
|
@@ -9,7 +9,7 @@ export class CreateAppError extends Data.TaggedError('CreateAppError')<{
|
|
|
9
9
|
|
|
10
10
|
export const createApp = Effect.fn(
|
|
11
11
|
function* (title: string, orgId?: string) {
|
|
12
|
-
const http = yield*
|
|
12
|
+
const http = yield* SidekickHttpAuthed;
|
|
13
13
|
const id = randomUUID();
|
|
14
14
|
const token = randomUUID();
|
|
15
15
|
const app = { id, title, admin_token: token, org_id: orgId };
|
package/src/lib/email.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { HttpBody
|
|
1
|
+
import { HttpBody } from '@effect/platform';
|
|
2
2
|
import { Effect, Schema } from 'effect';
|
|
3
3
|
import { CurrentApp } from '../context/currentApp.ts';
|
|
4
4
|
import { BadArgsError } from '../errors.ts';
|
|
5
5
|
import { readLocalEmailFile } from '../old.js';
|
|
6
|
-
import {
|
|
6
|
+
import { SidekickHttpAuthed } from './http.ts';
|
|
7
|
+
import { failOnOldConfigFiles } from '../util/oldConfigFiles.ts';
|
|
7
8
|
|
|
8
9
|
export const EmailConfig = Schema.Struct({
|
|
9
10
|
authEmail: Schema.Struct({
|
|
@@ -22,38 +23,40 @@ export class NoEmailFileFound extends Schema.TaggedError<NoEmailFileFound>(
|
|
|
22
23
|
|
|
23
24
|
export const readEmailConfig = (emailPath?: string) =>
|
|
24
25
|
Effect.gen(function* () {
|
|
26
|
+
// SidekickDB: stop when only an old-named email file exists.
|
|
27
|
+
yield* failOnOldConfigFiles(['email'], emailPath);
|
|
25
28
|
const emailFile = yield* Effect.tryPromise({
|
|
26
29
|
try: () => readLocalEmailFile(emailPath),
|
|
27
30
|
catch: (e) =>
|
|
28
31
|
BadArgsError.make({
|
|
29
|
-
message: `Error reading
|
|
32
|
+
message: `Error reading sidekick.email.ts file: ${e}`,
|
|
30
33
|
}),
|
|
31
34
|
});
|
|
32
35
|
|
|
33
36
|
if (!emailFile) {
|
|
34
37
|
return yield* NoEmailFileFound.make({
|
|
35
38
|
message:
|
|
36
|
-
"We couldn't find your `
|
|
39
|
+
"We couldn't find your `sidekick.email.ts` file. Make sure it's in the root directory. (Hint: You can use an SIDEKICK_EMAIL_FILE_PATH environment variable to specify it.)",
|
|
37
40
|
});
|
|
38
41
|
}
|
|
39
42
|
|
|
40
43
|
return yield* Schema.decodeUnknown(EmailConfig)(emailFile.email).pipe(
|
|
41
44
|
Effect.catchTag('ParseError', (e) =>
|
|
42
45
|
BadArgsError.make({
|
|
43
|
-
message: `Invalid
|
|
46
|
+
message: `Invalid sidekick.email.ts file: ${e.message}`,
|
|
44
47
|
}),
|
|
45
48
|
),
|
|
46
49
|
);
|
|
47
50
|
});
|
|
48
51
|
|
|
49
52
|
export const sendSenderVerification = Effect.gen(function* () {
|
|
50
|
-
const http = yield*
|
|
53
|
+
const http = yield* SidekickHttpAuthed;
|
|
51
54
|
const { appId } = yield* CurrentApp;
|
|
52
55
|
yield* http.post(`/dash/apps/${appId}/sender-verification/send-magic-code`);
|
|
53
56
|
});
|
|
54
57
|
|
|
55
58
|
export const submitVerification = Effect.fn(function* (code: string) {
|
|
56
|
-
const http = yield*
|
|
59
|
+
const http = yield* SidekickHttpAuthed;
|
|
57
60
|
const { appId } = yield* CurrentApp;
|
|
58
61
|
yield* http.post(
|
|
59
62
|
`/dash/apps/${appId}/sender-verification/verify-magic-code`,
|
|
@@ -63,8 +66,8 @@ export const submitVerification = Effect.fn(function* (code: string) {
|
|
|
63
66
|
);
|
|
64
67
|
});
|
|
65
68
|
|
|
66
|
-
const VerificationSchema = Schema.Struct({
|
|
67
|
-
|
|
69
|
+
export const VerificationSchema = Schema.Struct({
|
|
70
|
+
server: Schema.Struct({
|
|
68
71
|
'verified?': Schema.Boolean.pipe(Schema.NullishOr),
|
|
69
72
|
}),
|
|
70
73
|
verification: Schema.Struct({
|
|
@@ -80,14 +83,26 @@ const VerificationSchema = Schema.Struct({
|
|
|
80
83
|
}).pipe(Schema.NullishOr),
|
|
81
84
|
});
|
|
82
85
|
|
|
86
|
+
// SidekickDB: a response this CLI cannot read (for example one without the
|
|
87
|
+
// `server` key, from a server of another release) says so instead of
|
|
88
|
+
// printing a schema error.
|
|
89
|
+
export const decodeVerification = (body: unknown) =>
|
|
90
|
+
Schema.decodeUnknown(VerificationSchema)(body).pipe(
|
|
91
|
+
Effect.mapError(
|
|
92
|
+
() =>
|
|
93
|
+
new BadArgsError({
|
|
94
|
+
message:
|
|
95
|
+
'The server answered the sender verification request in a form this CLI does not read. Use a CLI from the same release as the server.',
|
|
96
|
+
}),
|
|
97
|
+
),
|
|
98
|
+
);
|
|
99
|
+
|
|
83
100
|
export const getVerification = Effect.gen(function* () {
|
|
84
|
-
const http = yield*
|
|
101
|
+
const http = yield* SidekickHttpAuthed;
|
|
85
102
|
const { appId } = yield* CurrentApp;
|
|
86
103
|
|
|
87
|
-
const
|
|
104
|
+
const body = yield* http
|
|
88
105
|
.get(`/dash/apps/${appId}/sender-verification`)
|
|
89
|
-
.pipe(
|
|
90
|
-
|
|
91
|
-
);
|
|
92
|
-
return response;
|
|
106
|
+
.pipe(Effect.flatMap((res) => res.json));
|
|
107
|
+
return yield* decodeVerification(body);
|
|
93
108
|
});
|
package/src/lib/handleEnv.ts
CHANGED
|
@@ -30,7 +30,7 @@ export const handleEnv = Effect.fn(function* (app: CurrentAppInfo) {
|
|
|
30
30
|
envFile !== '.env' ? chalk.green(' (will create `' + envFile + '`)') : '';
|
|
31
31
|
const promptText = [
|
|
32
32
|
`Looks like you don't have a ${chalk.green(`\`${envFile}\``)} file yet.`,
|
|
33
|
-
`If we set ${chalk.green(envName)} & ${chalk.green('
|
|
33
|
+
`If we set ${chalk.green(envName)} & ${chalk.green('SIDEKICK_APP_ADMIN_TOKEN')}, we can remember the app that you chose for all`,
|
|
34
34
|
'future commands.',
|
|
35
35
|
'Want us to create this env file for you?' + saveExtraInfo,
|
|
36
36
|
].join('\n');
|
|
@@ -56,7 +56,7 @@ export const handleEnv = Effect.fn(function* (app: CurrentAppInfo) {
|
|
|
56
56
|
const content =
|
|
57
57
|
[
|
|
58
58
|
[envName, app.appId],
|
|
59
|
-
['
|
|
59
|
+
['SIDEKICK_APP_ADMIN_TOKEN', app.adminToken],
|
|
60
60
|
]
|
|
61
61
|
.map(([k, v]) => `${k}=${v}`)
|
|
62
62
|
.join('\n') + '\n';
|
|
@@ -121,6 +121,6 @@ function printDotEnvInfo(
|
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
function appDashUrl(id: string,
|
|
125
|
-
return `${
|
|
124
|
+
function appDashUrl(id: string, sidekickOrigin: string) {
|
|
125
|
+
return `${sidekickOrigin}/dash?s=main&t=home&app=${id}`;
|
|
126
126
|
}
|
package/src/lib/http.ts
CHANGED
|
@@ -8,41 +8,45 @@ import { getBaseUrl } from './config.ts';
|
|
|
8
8
|
|
|
9
9
|
export { getBaseUrl, getDashUrl } from './config.ts';
|
|
10
10
|
|
|
11
|
-
export class
|
|
12
|
-
'
|
|
11
|
+
export class SidekickHttp extends Context.Tag(
|
|
12
|
+
'sidekick-cli/new/lib/http/SidekickHttp',
|
|
13
13
|
)<
|
|
14
|
-
|
|
15
|
-
HttpClient.HttpClient.With<
|
|
14
|
+
SidekickHttp,
|
|
15
|
+
HttpClient.HttpClient.With<
|
|
16
|
+
SidekickHttpError | TimeoutException | RequestError
|
|
17
|
+
>
|
|
16
18
|
>() {}
|
|
17
19
|
|
|
18
|
-
export class
|
|
19
|
-
'
|
|
20
|
+
export class SidekickHttpAuthed extends Context.Tag(
|
|
21
|
+
'sidekick-cli/new/lib/http/SidekickHttpAuthed',
|
|
20
22
|
)<
|
|
21
|
-
|
|
22
|
-
HttpClient.HttpClient.With<
|
|
23
|
+
SidekickHttpAuthed,
|
|
24
|
+
HttpClient.HttpClient.With<
|
|
25
|
+
SidekickHttpError | TimeoutException | RequestError
|
|
26
|
+
>
|
|
23
27
|
>() {}
|
|
24
28
|
|
|
25
|
-
export class
|
|
29
|
+
export class SidekickHttpError extends Data.TaggedError('SidekickHttpError')<
|
|
26
30
|
{
|
|
27
31
|
methodAndUrl: string;
|
|
28
|
-
} & typeof
|
|
32
|
+
} & typeof SidekickTypicalHttpErrorResponse.Type
|
|
29
33
|
> {}
|
|
30
34
|
|
|
31
35
|
// Pipe on an http client to set the command header
|
|
32
36
|
export const withCommand = (command: string) => {
|
|
33
37
|
return (
|
|
34
38
|
client: HttpClient.HttpClient.With<
|
|
35
|
-
|
|
39
|
+
SidekickHttpError | TimeoutException | RequestError
|
|
36
40
|
>,
|
|
37
41
|
) =>
|
|
38
42
|
client.pipe(
|
|
39
43
|
HttpClient.mapRequest((r) =>
|
|
40
|
-
r.pipe(HttpClientRequest.setHeader(`X-
|
|
44
|
+
r.pipe(HttpClientRequest.setHeader(`X-Sidekick-Command`, command)),
|
|
41
45
|
),
|
|
42
46
|
);
|
|
43
47
|
};
|
|
44
48
|
|
|
45
|
-
class
|
|
49
|
+
class SidekickTypicalHttpErrorResponse extends Schema.Struct({
|
|
46
50
|
message: Schema.String,
|
|
47
51
|
type: Schema.String.pipe(Schema.optional),
|
|
48
52
|
hint: Schema.Record({ key: Schema.String, value: Schema.Any }).pipe(
|
|
@@ -50,8 +54,8 @@ class InstantTypicalHttpErrorResponse extends Schema.Struct({
|
|
|
50
54
|
),
|
|
51
55
|
}) {}
|
|
52
56
|
|
|
53
|
-
export const
|
|
54
|
-
|
|
57
|
+
export const SidekickHttpLive = Layer.effect(
|
|
58
|
+
SidekickHttp,
|
|
55
59
|
Effect.gen(function* () {
|
|
56
60
|
const client = yield* HttpClient.HttpClient;
|
|
57
61
|
const baseUrl = yield* getBaseUrl;
|
|
@@ -59,24 +63,24 @@ export const InstantHttpLive = Layer.effect(
|
|
|
59
63
|
HttpClient.mapRequest((r) =>
|
|
60
64
|
r.pipe(
|
|
61
65
|
HttpClientRequest.prependUrl(baseUrl),
|
|
62
|
-
HttpClientRequest.setHeader('X-
|
|
63
|
-
HttpClientRequest.setHeader('X-
|
|
66
|
+
HttpClientRequest.setHeader('X-Sidekick-Source', 'sidekick-cli'),
|
|
67
|
+
HttpClientRequest.setHeader('X-Sidekick-Version', version),
|
|
64
68
|
),
|
|
65
69
|
),
|
|
66
70
|
HttpClient.transformResponse((r) => r.pipe(Effect.timeout('5 minutes'))),
|
|
67
71
|
HttpClient.filterStatusOk, // makes non 2xx http codes error
|
|
68
|
-
// parses the non 2xx errors into known
|
|
72
|
+
// parses the non 2xx errors into known SidekickDB error shape
|
|
69
73
|
HttpClient.transformResponse((r) =>
|
|
70
74
|
r.pipe(
|
|
71
75
|
Effect.catchTag('ResponseError', (requestError) =>
|
|
72
76
|
Effect.gen(function* () {
|
|
73
77
|
const jsonBody = yield* requestError.response.json.pipe(
|
|
74
78
|
Effect.andThen(
|
|
75
|
-
Schema.decodeUnknown(
|
|
79
|
+
Schema.decodeUnknown(SidekickTypicalHttpErrorResponse),
|
|
76
80
|
),
|
|
77
81
|
Effect.mapError(
|
|
78
82
|
(e) =>
|
|
79
|
-
new
|
|
83
|
+
new SidekickHttpError({
|
|
80
84
|
message:
|
|
81
85
|
'Error making request to ' + requestError.methodAndUrl,
|
|
82
86
|
type: e._tag,
|
|
@@ -94,7 +98,7 @@ export const InstantHttpLive = Layer.effect(
|
|
|
94
98
|
message = jsonBody.hint.message;
|
|
95
99
|
}
|
|
96
100
|
|
|
97
|
-
return yield* new
|
|
101
|
+
return yield* new SidekickHttpError({
|
|
98
102
|
message: message,
|
|
99
103
|
methodAndUrl: requestError.methodAndUrl,
|
|
100
104
|
hint: jsonBody.hint,
|
|
@@ -108,10 +112,10 @@ export const InstantHttpLive = Layer.effect(
|
|
|
108
112
|
}),
|
|
109
113
|
);
|
|
110
114
|
|
|
111
|
-
export const
|
|
112
|
-
|
|
115
|
+
export const SidekickHttpAuthedLive = Layer.effect(
|
|
116
|
+
SidekickHttpAuthed,
|
|
113
117
|
Effect.gen(function* () {
|
|
114
|
-
const http = yield*
|
|
118
|
+
const http = yield* SidekickHttp;
|
|
115
119
|
const authToken = yield* AuthToken;
|
|
116
120
|
return http.pipe(
|
|
117
121
|
HttpClient.mapRequestEffect((r) =>
|
package/src/lib/login.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Effect, Schedule, Schema } from 'effect';
|
|
2
|
-
import {
|
|
2
|
+
import { SidekickHttp, withCommand } from './http.ts';
|
|
3
3
|
import { HttpClientRequest, HttpClientResponse } from '@effect/platform';
|
|
4
4
|
import { writeAuthToken } from '../auth/index.ts';
|
|
5
5
|
import { getBaseUrl } from './config.ts';
|
|
@@ -15,7 +15,7 @@ const TokenResult = Schema.Struct({
|
|
|
15
15
|
});
|
|
16
16
|
|
|
17
17
|
export const getLoginTicketAndSecret = Effect.gen(function* () {
|
|
18
|
-
const http = yield*
|
|
18
|
+
const http = yield* SidekickHttp;
|
|
19
19
|
const res = yield* http
|
|
20
20
|
.pipe(withCommand('login'))
|
|
21
21
|
.post('/dash/cli/auth/register')
|
|
@@ -24,7 +24,7 @@ export const getLoginTicketAndSecret = Effect.gen(function* () {
|
|
|
24
24
|
});
|
|
25
25
|
|
|
26
26
|
export const waitForAuthToken = Effect.fn(function* (secret: string) {
|
|
27
|
-
const http = (yield*
|
|
27
|
+
const http = (yield* SidekickHttp).pipe(withCommand('login'));
|
|
28
28
|
const res = yield* HttpClientRequest.post('/dash/cli/auth/check').pipe(
|
|
29
29
|
HttpClientRequest.bodyUnsafeJson({
|
|
30
30
|
secret,
|
|
@@ -33,7 +33,7 @@ export const waitForAuthToken = Effect.fn(function* (secret: string) {
|
|
|
33
33
|
Effect.flatMap(HttpClientResponse.schemaBodyJson(TokenResult)),
|
|
34
34
|
Effect.retry({
|
|
35
35
|
while: (e) =>
|
|
36
|
-
e._tag === '
|
|
36
|
+
e._tag === 'SidekickHttpError' &&
|
|
37
37
|
e.hint?.errors?.at(0)?.issue === 'waiting-for-user',
|
|
38
38
|
schedule: Schedule.fixed('1 seconds'),
|
|
39
39
|
times: 120,
|
package/src/lib/oauth.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { HttpBody, HttpClientResponse } from '@effect/platform';
|
|
2
2
|
import { Effect, Schema } from 'effect';
|
|
3
3
|
import { CurrentApp } from '../context/currentApp.ts';
|
|
4
|
-
import {
|
|
4
|
+
import { SidekickHttpAuthed, withCommand } from './http.ts';
|
|
5
5
|
import { validateRequired } from './ui.ts';
|
|
6
6
|
import { UI } from '../ui/index.ts';
|
|
7
7
|
import { BadArgsError } from '../errors.ts';
|
|
@@ -87,7 +87,7 @@ export const AppsAuthResponse = Schema.Struct({
|
|
|
87
87
|
});
|
|
88
88
|
|
|
89
89
|
export const getAppsAuth = Effect.fn(function* () {
|
|
90
|
-
const http = (yield*
|
|
90
|
+
const http = (yield* SidekickHttpAuthed).pipe(withCommand('auth'));
|
|
91
91
|
const targetAppId = (yield* CurrentApp).appId;
|
|
92
92
|
|
|
93
93
|
return yield* http
|
|
@@ -99,7 +99,7 @@ export const addOAuthProvider = Effect.fn(function* (params: {
|
|
|
99
99
|
appId?: string;
|
|
100
100
|
providerName: string;
|
|
101
101
|
}) {
|
|
102
|
-
const http = (yield*
|
|
102
|
+
const http = (yield* SidekickHttpAuthed).pipe(withCommand('auth'));
|
|
103
103
|
const targetAppId = params.appId ?? (yield* CurrentApp).appId;
|
|
104
104
|
|
|
105
105
|
return yield* http
|
|
@@ -128,7 +128,7 @@ export const addOAuthClient = Effect.fn(function* (params: {
|
|
|
128
128
|
meta?: unknown;
|
|
129
129
|
useSharedCredentials?: boolean;
|
|
130
130
|
}) {
|
|
131
|
-
const http = (yield*
|
|
131
|
+
const http = (yield* SidekickHttpAuthed).pipe(withCommand('auth'));
|
|
132
132
|
const targetAppId = params.appId ?? (yield* CurrentApp).appId;
|
|
133
133
|
|
|
134
134
|
return yield* http
|
|
@@ -160,7 +160,7 @@ export const updateOAuthClient = Effect.fn(function* (params: {
|
|
|
160
160
|
meta?: unknown;
|
|
161
161
|
useSharedCredentials?: boolean | null;
|
|
162
162
|
}) {
|
|
163
|
-
const http = (yield*
|
|
163
|
+
const http = (yield* SidekickHttpAuthed).pipe(withCommand('auth'));
|
|
164
164
|
const targetAppId = (yield* CurrentApp).appId;
|
|
165
165
|
|
|
166
166
|
return yield* http
|
|
@@ -274,7 +274,7 @@ export const findClientByIdOrName = Effect.fn(function* (params: {
|
|
|
274
274
|
});
|
|
275
275
|
|
|
276
276
|
export const removeAuthorizedOrigin = Effect.fn(function* (originId: string) {
|
|
277
|
-
const http = (yield*
|
|
277
|
+
const http = (yield* SidekickHttpAuthed).pipe(
|
|
278
278
|
withCommand('auth origin delete'),
|
|
279
279
|
);
|
|
280
280
|
const { appId } = yield* CurrentApp;
|
|
@@ -292,7 +292,7 @@ export const addAuthorizedOrigin = Effect.fn(function* (params: {
|
|
|
292
292
|
service: Schema.Schema.Type<typeof AuthorizedOriginService>;
|
|
293
293
|
params: string[];
|
|
294
294
|
}) {
|
|
295
|
-
const http = (yield*
|
|
295
|
+
const http = (yield* SidekickHttpAuthed).pipe(withCommand('auth origin add'));
|
|
296
296
|
const { appId } = yield* CurrentApp;
|
|
297
297
|
|
|
298
298
|
return yield* http
|
package/src/lib/platformApi.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Effect } from 'effect';
|
|
2
|
-
import { PlatformApi as
|
|
2
|
+
import { PlatformApi as SidekickPlatformApi } from '@sidekickdb/platform';
|
|
3
3
|
import { AuthToken } from '../context/authToken.ts';
|
|
4
4
|
import { getBaseUrl } from './config.ts';
|
|
5
5
|
|
|
@@ -7,5 +7,5 @@ export const getAuthedPlatformApi = Effect.gen(function* () {
|
|
|
7
7
|
const apiURI = yield* getBaseUrl;
|
|
8
8
|
const authToken = yield* AuthToken;
|
|
9
9
|
const token = yield* authToken.getAuthToken;
|
|
10
|
-
return new
|
|
10
|
+
return new SidekickPlatformApi({ apiURI, auth: { token } });
|
|
11
11
|
});
|
package/src/lib/pullPerms.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Effect, Option, Schema } from 'effect';
|
|
2
2
|
import { CurrentApp } from '../context/currentApp.ts';
|
|
3
|
-
import {
|
|
3
|
+
import { SidekickHttpAuthed, withCommand } from './http.ts';
|
|
4
4
|
import { HttpClientResponse } from '@effect/platform';
|
|
5
5
|
import { readLocalPermsFile } from '../old.js';
|
|
6
6
|
import { getPermsPathToWrite } from '../util/findConfigCandidates.ts';
|
|
@@ -10,11 +10,14 @@ import { writeTypescript } from './pullSchema.ts';
|
|
|
10
10
|
import { generatePermsTypescriptFile } from '@sidekickdb/platform';
|
|
11
11
|
import { ProjectInfo } from '../context/projectInfo.ts';
|
|
12
12
|
import { Path } from '@effect/platform';
|
|
13
|
+
import { failOnOldConfigFiles } from '../util/oldConfigFiles.ts';
|
|
13
14
|
|
|
14
15
|
export const pullPerms = Effect.gen(function* () {
|
|
16
|
+
// SidekickDB: stop when only an old-named perms file exists.
|
|
17
|
+
yield* failOnOldConfigFiles(['perms']);
|
|
15
18
|
yield* Effect.log('\nPulling perms...');
|
|
16
19
|
const { appId } = yield* CurrentApp;
|
|
17
|
-
const http = yield*
|
|
20
|
+
const http = yield* SidekickHttpAuthed;
|
|
18
21
|
const permsResponse = yield* http
|
|
19
22
|
.pipe(withCommand('pull'))
|
|
20
23
|
.get(`/dash/apps/${appId}/perms/pull`)
|
|
@@ -37,10 +40,10 @@ export const pullPerms = Effect.gen(function* () {
|
|
|
37
40
|
});
|
|
38
41
|
if (!shouldContinue) return;
|
|
39
42
|
}
|
|
40
|
-
const {
|
|
43
|
+
const { sidekickModuleName, pkgDir } = yield* ProjectInfo;
|
|
41
44
|
const fileContent = generatePermsTypescriptFile(
|
|
42
45
|
permsResponse?.perms || {},
|
|
43
|
-
|
|
46
|
+
sidekickModuleName,
|
|
44
47
|
);
|
|
45
48
|
|
|
46
49
|
const path = yield* Path.Path;
|
package/src/lib/pullSchema.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FileSystem, HttpClientResponse, Path } from '@effect/platform';
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
apiSchemaToSidekickSchemaDef,
|
|
4
4
|
generateSchemaTypescriptFile,
|
|
5
5
|
} from '@sidekickdb/platform';
|
|
6
6
|
import { Effect, Schema } from 'effect';
|
|
@@ -10,10 +10,11 @@ import { UI } from '../ui/index.ts';
|
|
|
10
10
|
import { getSchemaPathToWrite } from '../util/findConfigCandidates.ts';
|
|
11
11
|
import { CurrentApp } from '../context/currentApp.ts';
|
|
12
12
|
import { ProjectInfo } from '../context/projectInfo.ts';
|
|
13
|
-
import {
|
|
13
|
+
import { SidekickHttpAuthed, withCommand } from './http.ts';
|
|
14
14
|
import { promptOk } from './ui.ts';
|
|
15
15
|
import { ReadSchemaFileError } from './pushSchema.ts';
|
|
16
16
|
import { mergeSchema, MergeSchemaError } from '../util/mergeSchema.ts';
|
|
17
|
+
import { failOnOldConfigFiles } from '../util/oldConfigFiles.ts';
|
|
17
18
|
|
|
18
19
|
export const pullSchema = ({
|
|
19
20
|
experimentalTypePreservation,
|
|
@@ -21,9 +22,11 @@ export const pullSchema = ({
|
|
|
21
22
|
experimentalTypePreservation?: boolean;
|
|
22
23
|
}) =>
|
|
23
24
|
Effect.gen(function* () {
|
|
25
|
+
// SidekickDB: stop when only an old-named schema file exists.
|
|
26
|
+
yield* failOnOldConfigFiles(['schema']);
|
|
24
27
|
yield* Effect.log('Pulling schema...');
|
|
25
28
|
const { appId } = yield* CurrentApp;
|
|
26
|
-
const http = yield*
|
|
29
|
+
const http = yield* SidekickHttpAuthed;
|
|
27
30
|
|
|
28
31
|
const schemaResponse = yield* http
|
|
29
32
|
.pipe(withCommand('pull'))
|
|
@@ -48,7 +51,7 @@ export const pullSchema = ({
|
|
|
48
51
|
);
|
|
49
52
|
const shortSchemaPath = getSchemaPathToWrite(prevSchemaFile?.path);
|
|
50
53
|
const path = yield* Path.Path;
|
|
51
|
-
const { pkgDir,
|
|
54
|
+
const { pkgDir, sidekickModuleName } = yield* ProjectInfo;
|
|
52
55
|
const schemaPath = path.join(pkgDir, shortSchemaPath);
|
|
53
56
|
|
|
54
57
|
if (prevSchemaFile) {
|
|
@@ -62,8 +65,8 @@ export const pullSchema = ({
|
|
|
62
65
|
|
|
63
66
|
let newSchemaContent = generateSchemaTypescriptFile(
|
|
64
67
|
prevSchemaFile?.schema,
|
|
65
|
-
|
|
66
|
-
|
|
68
|
+
apiSchemaToSidekickSchemaDef(schemaResponse.schema),
|
|
69
|
+
sidekickModuleName,
|
|
67
70
|
);
|
|
68
71
|
|
|
69
72
|
if (prevSchemaFile && experimentalTypePreservation) {
|
package/src/lib/pushPerms.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Effect, Option, Schema } from 'effect';
|
|
2
2
|
import jsonDiff from 'json-diff';
|
|
3
3
|
import { readLocalPermsFile } from '../old.js';
|
|
4
|
-
import {
|
|
4
|
+
import { SidekickHttpAuthed, withCommand } from './http.ts';
|
|
5
5
|
import {
|
|
6
6
|
HttpClient,
|
|
7
7
|
HttpClientRequest,
|
|
@@ -11,6 +11,7 @@ import { CurrentApp } from '../context/currentApp.ts';
|
|
|
11
11
|
import { promptOk } from './ui.ts';
|
|
12
12
|
import boxen from 'boxen';
|
|
13
13
|
import chalk from 'chalk';
|
|
14
|
+
import { failOnOldConfigFiles } from '../util/oldConfigFiles.ts';
|
|
14
15
|
|
|
15
16
|
export class NoPermsFileError extends Schema.TaggedError<NoPermsFileError>(
|
|
16
17
|
'NoPermsFileError',
|
|
@@ -23,15 +24,17 @@ const PullPermsResponse = Schema.Struct({
|
|
|
23
24
|
});
|
|
24
25
|
|
|
25
26
|
export const pushPerms = Effect.gen(function* () {
|
|
27
|
+
// SidekickDB: stop when only an old-named perms file exists.
|
|
28
|
+
yield* failOnOldConfigFiles(['perms']);
|
|
26
29
|
yield* Effect.log('Planning perms...');
|
|
27
30
|
const { appId } = yield* CurrentApp;
|
|
28
|
-
const http = yield*
|
|
31
|
+
const http = yield* SidekickHttpAuthed;
|
|
29
32
|
|
|
30
33
|
const permsFile = yield* Effect.tryPromise(readLocalPermsFile).pipe(
|
|
31
34
|
Effect.flatMap(Option.fromNullable),
|
|
32
35
|
Effect.mapError(() =>
|
|
33
36
|
NoPermsFileError.make({
|
|
34
|
-
message: `We couldn't find your ${chalk.yellow('`
|
|
37
|
+
message: `We couldn't find your ${chalk.yellow('`sidekick.perms.ts`')} file. Make sure it's in the root directory. (Hint: You can use an SIDEKICK_PERMS_FILE_PATH environment variable to specify it.)`,
|
|
35
38
|
}),
|
|
36
39
|
),
|
|
37
40
|
);
|