instant-cli 1.0.56 → 1.0.57
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/__tests__/auth.test.ts +128 -0
- package/__tests__/config.test.ts +47 -0
- package/dist/auth/index.d.ts +4 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +103 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/commands/auth/client/add.d.ts +1 -1
- package/dist/commands/auth/client/delete.d.ts +1 -1
- package/dist/commands/auth/client/list.d.ts +1 -1
- package/dist/commands/auth/client/update.d.ts +1 -1
- package/dist/commands/auth/email/pull.d.ts +2 -2
- package/dist/commands/auth/email/push.d.ts +1 -1
- package/dist/commands/auth/email/reset.d.ts +1 -1
- package/dist/commands/auth/email/status.d.ts +2 -2
- package/dist/commands/auth/email/verify.d.ts +1 -1
- package/dist/commands/auth/origin/add.d.ts +1 -1
- package/dist/commands/auth/origin/delete.d.ts +1 -1
- package/dist/commands/auth/origin/list.d.ts +1 -1
- package/dist/commands/info.d.ts +1 -1
- package/dist/commands/init.d.ts +1 -1
- package/dist/commands/login.d.ts +1 -1
- package/dist/commands/login.d.ts.map +1 -1
- package/dist/commands/login.js +2 -2
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/logout.d.ts +1 -2
- package/dist/commands/logout.d.ts.map +1 -1
- package/dist/commands/logout.js +9 -16
- package/dist/commands/logout.js.map +1 -1
- package/dist/commands/pull.d.ts +1 -1
- package/dist/commands/push.d.ts +1 -1
- package/dist/commands/query.d.ts +1 -1
- package/dist/context/authToken.d.ts +2 -3
- package/dist/context/authToken.d.ts.map +1 -1
- package/dist/context/authToken.js +4 -17
- package/dist/context/authToken.js.map +1 -1
- package/dist/context/currentApp.d.ts +1 -1
- package/dist/layer.d.ts +2 -2
- package/dist/layer.d.ts.map +1 -1
- package/dist/lib/config.d.ts +5 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/dist/lib/config.js +37 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/createApp.d.ts +1 -1
- package/dist/lib/email.d.ts +1 -1
- package/dist/lib/handleEnv.d.ts +1 -1
- package/dist/lib/http.d.ts +3 -6
- package/dist/lib/http.d.ts.map +1 -1
- package/dist/lib/http.js +3 -36
- package/dist/lib/http.js.map +1 -1
- package/dist/lib/login.d.ts +3 -4
- package/dist/lib/login.d.ts.map +1 -1
- package/dist/lib/login.js +5 -6
- package/dist/lib/login.js.map +1 -1
- package/dist/lib/oauth.d.ts +9 -9
- package/dist/lib/pullPerms.d.ts +1 -1
- package/dist/lib/pullSchema.d.ts +1 -1
- package/dist/lib/pushPerms.d.ts +1 -1
- package/dist/lib/pushSchema.d.ts +1 -1
- package/dist/old.d.ts +1 -1
- package/dist/old.d.ts.map +1 -1
- package/dist/old.js +6 -7
- package/dist/old.js.map +1 -1
- package/dist/util/getAppName.d.ts +1 -1
- package/package.json +10 -4
- package/src/auth/index.ts +125 -0
- package/src/commands/login.ts +2 -2
- package/src/commands/logout.ts +17 -18
- package/src/context/authToken.ts +6 -21
- package/src/lib/config.ts +68 -0
- package/src/lib/http.ts +4 -68
- package/src/lib/login.ts +5 -11
- package/src/old.js +6 -10
- package/dist/util/getAuthPaths.d.ts +0 -5
- package/dist/util/getAuthPaths.d.ts.map +0 -1
- package/dist/util/getAuthPaths.js +0 -10
- package/dist/util/getAuthPaths.js.map +0 -1
- package/src/util/getAuthPaths.ts +0 -12
package/src/lib/http.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { HttpClient, HttpClientRequest } from '@effect/platform';
|
|
2
2
|
import { version } from '@instantdb/version';
|
|
3
|
-
import {
|
|
3
|
+
import { Context, Data, Effect, Layer, Schema } from 'effect';
|
|
4
4
|
import { AuthToken } from '../context/authToken.ts';
|
|
5
5
|
import { TimeoutException } from 'effect/Cause';
|
|
6
6
|
import { RequestError } from '@effect/platform/HttpClientError';
|
|
7
|
-
import {
|
|
8
|
-
|
|
7
|
+
import { getBaseUrl } from './config.ts';
|
|
8
|
+
|
|
9
|
+
export { getBaseUrl, getDashUrl } from './config.ts';
|
|
9
10
|
|
|
10
11
|
export class InstantHttp extends Context.Tag(
|
|
11
12
|
'instant-cli/new/lib/http/InstantHttp',
|
|
@@ -49,15 +50,6 @@ class InstantTypicalHttpErrorResponse extends Schema.Struct({
|
|
|
49
50
|
),
|
|
50
51
|
}) {}
|
|
51
52
|
|
|
52
|
-
const HttpUrl = Schema.URL.pipe(
|
|
53
|
-
Schema.filter(
|
|
54
|
-
(url) =>
|
|
55
|
-
url.protocol === 'http:' ||
|
|
56
|
-
url.protocol === 'https:' ||
|
|
57
|
-
'Expected an HTTP(S) URL',
|
|
58
|
-
),
|
|
59
|
-
);
|
|
60
|
-
|
|
61
53
|
export const InstantHttpLive = Layer.effect(
|
|
62
54
|
InstantHttp,
|
|
63
55
|
Effect.gen(function* () {
|
|
@@ -134,59 +126,3 @@ export const InstantHttpAuthedLive = Layer.effect(
|
|
|
134
126
|
);
|
|
135
127
|
}),
|
|
136
128
|
);
|
|
137
|
-
|
|
138
|
-
export const getBaseUrl = Effect.gen(function* () {
|
|
139
|
-
const setEnv = yield* Config.string('INSTANT_CLI_API_URI').pipe(
|
|
140
|
-
Config.option,
|
|
141
|
-
);
|
|
142
|
-
const dev = yield* Config.boolean('INSTANT_CLI_DEV').pipe(
|
|
143
|
-
Config.withDefault(false),
|
|
144
|
-
);
|
|
145
|
-
|
|
146
|
-
if (Option.isSome(setEnv)) {
|
|
147
|
-
return setEnv.value;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const instantConfig = yield* Effect.tryPromise(readInstantConfigFile);
|
|
151
|
-
if (instantConfig?.apiURI !== undefined) {
|
|
152
|
-
yield* Schema.decodeUnknown(HttpUrl)(instantConfig.apiURI).pipe(
|
|
153
|
-
Effect.mapError(() =>
|
|
154
|
-
BadArgsError.make({
|
|
155
|
-
message:
|
|
156
|
-
'Invalid apiURI in instant.config.ts. Expected a valid HTTP(S) URL.',
|
|
157
|
-
}),
|
|
158
|
-
),
|
|
159
|
-
);
|
|
160
|
-
return instantConfig.apiURI;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
return dev ? 'http://localhost:8888' : 'https://api.instantdb.com';
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
export const getDashUrl = Effect.gen(function* () {
|
|
167
|
-
const setEnv = yield* Config.string('INSTANT_CLI_DASH_URI').pipe(
|
|
168
|
-
Config.option,
|
|
169
|
-
);
|
|
170
|
-
const dev = yield* Config.boolean('INSTANT_CLI_DEV').pipe(
|
|
171
|
-
Config.withDefault(false),
|
|
172
|
-
);
|
|
173
|
-
|
|
174
|
-
if (Option.isSome(setEnv)) {
|
|
175
|
-
return setEnv.value;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
const instantConfig = yield* Effect.tryPromise(readInstantConfigFile);
|
|
179
|
-
if (instantConfig?.dashURI !== undefined) {
|
|
180
|
-
yield* Schema.decodeUnknown(HttpUrl)(instantConfig.dashURI).pipe(
|
|
181
|
-
Effect.mapError(() =>
|
|
182
|
-
BadArgsError.make({
|
|
183
|
-
message:
|
|
184
|
-
'Invalid dashURI in instant.config.ts. Expected a valid HTTP(S) URL.',
|
|
185
|
-
}),
|
|
186
|
-
),
|
|
187
|
-
);
|
|
188
|
-
return instantConfig.dashURI;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
return dev ? 'http://localhost:3000' : 'https://instantdb.com';
|
|
192
|
-
});
|
package/src/lib/login.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { Effect, Schedule, Schema } from 'effect';
|
|
2
2
|
import { InstantHttp, withCommand } from './http.ts';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
FileSystem,
|
|
7
|
-
} from '@effect/platform';
|
|
8
|
-
import { getAuthPaths } from '../util/getAuthPaths.ts';
|
|
3
|
+
import { HttpClientRequest, HttpClientResponse } from '@effect/platform';
|
|
4
|
+
import { writeAuthToken } from '../auth/index.ts';
|
|
5
|
+
import { getBaseUrl } from './config.ts';
|
|
9
6
|
|
|
10
7
|
const LoginInfo = Schema.Struct({
|
|
11
8
|
secret: Schema.String,
|
|
@@ -46,9 +43,6 @@ export const waitForAuthToken = Effect.fn(function* (secret: string) {
|
|
|
46
43
|
});
|
|
47
44
|
|
|
48
45
|
export const saveConfigAuthToken = Effect.fn(function* (token: string) {
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
const fs = yield* FileSystem.FileSystem;
|
|
52
|
-
yield* fs.makeDirectory(authPaths.appConfigDirPath, { recursive: true });
|
|
53
|
-
yield* fs.writeFileString(authPaths.authConfigFilePath, token);
|
|
46
|
+
const apiURI = yield* getBaseUrl;
|
|
47
|
+
yield* Effect.tryPromise(() => writeAuthToken(apiURI, token));
|
|
54
48
|
});
|
package/src/old.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import boxen from 'boxen';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
3
|
import { program } from '@commander-js/extra-typings';
|
|
4
|
-
import { readFile } from 'node:fs/promises';
|
|
5
4
|
import path from 'node:path';
|
|
5
|
+
import { readAuthToken } from './auth/index.ts';
|
|
6
6
|
import { UI } from './ui/index.ts';
|
|
7
7
|
import { deferred, renderUnwrap } from './ui/lib.ts';
|
|
8
8
|
import {
|
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
getPermsReadCandidates,
|
|
11
11
|
getSchemaReadCandidates,
|
|
12
12
|
} from './util/findConfigCandidates.ts';
|
|
13
|
-
import { getAuthPaths } from './util/getAuthPaths.ts';
|
|
14
13
|
import { loadConfig } from './util/loadConfig.ts';
|
|
15
14
|
import { ResolveRenamePrompt } from './util/renamePrompt.ts';
|
|
16
15
|
import version from './version.js';
|
|
@@ -331,7 +330,7 @@ async function fetchJson({
|
|
|
331
330
|
let authToken = null;
|
|
332
331
|
if (withAuth) {
|
|
333
332
|
authToken =
|
|
334
|
-
providedAuthToken ?? (await readConfigAuthTokenWithErrorLogging());
|
|
333
|
+
providedAuthToken ?? (await readConfigAuthTokenWithErrorLogging(apiURI));
|
|
335
334
|
if (!authToken) {
|
|
336
335
|
return { ok: false, data: undefined };
|
|
337
336
|
}
|
|
@@ -436,7 +435,7 @@ export async function readLocalEmailFile(emailPath) {
|
|
|
436
435
|
return { path: relativePath, email: res.config };
|
|
437
436
|
}
|
|
438
437
|
|
|
439
|
-
async function readConfigAuthToken(allowAdminToken = true) {
|
|
438
|
+
async function readConfigAuthToken(apiURI, allowAdminToken = true) {
|
|
440
439
|
const options = program.opts();
|
|
441
440
|
// @ts-expect-error command opts type is unknown
|
|
442
441
|
if (typeof options.token === 'string') {
|
|
@@ -458,10 +457,7 @@ async function readConfigAuthToken(allowAdminToken = true) {
|
|
|
458
457
|
}
|
|
459
458
|
}
|
|
460
459
|
|
|
461
|
-
const authToken = await
|
|
462
|
-
getAuthPaths().authConfigFilePath,
|
|
463
|
-
'utf-8',
|
|
464
|
-
).catch(() => null);
|
|
460
|
+
const authToken = await readAuthToken(apiURI).catch(() => null);
|
|
465
461
|
|
|
466
462
|
if (authToken) {
|
|
467
463
|
return authToken;
|
|
@@ -470,8 +466,8 @@ async function readConfigAuthToken(allowAdminToken = true) {
|
|
|
470
466
|
return null;
|
|
471
467
|
}
|
|
472
468
|
|
|
473
|
-
export async function readConfigAuthTokenWithErrorLogging() {
|
|
474
|
-
const token = await readConfigAuthToken();
|
|
469
|
+
export async function readConfigAuthTokenWithErrorLogging(apiURI) {
|
|
470
|
+
const token = await readConfigAuthToken(apiURI);
|
|
475
471
|
if (!token) {
|
|
476
472
|
error(
|
|
477
473
|
`Looks like you are not logged in. Please log in with ${chalk.green('`instant-cli login`')}`,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getAuthPaths.d.ts","sourceRoot":"","sources":["../../src/util/getAuthPaths.ts"],"names":[],"mappings":"AAKA,wBAAgB,YAAY;;;EAM3B"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import envPaths from 'env-paths';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
const dev = Boolean(process.env.INSTANT_CLI_DEV);
|
|
4
|
-
export function getAuthPaths() {
|
|
5
|
-
const key = `instantdb-${dev ? 'dev' : 'prod'}`;
|
|
6
|
-
const { config: appConfigDirPath } = envPaths(key);
|
|
7
|
-
const authConfigFilePath = join(appConfigDirPath, 'a');
|
|
8
|
-
return { authConfigFilePath, appConfigDirPath };
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=getAuthPaths.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getAuthPaths.js","sourceRoot":"","sources":["../../src/util/getAuthPaths.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,MAAM,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;AAEjD,MAAM,UAAU,YAAY;IAC1B,MAAM,GAAG,GAAG,aAAa,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IAChD,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;IACnD,MAAM,kBAAkB,GAAG,IAAI,CAAC,gBAAgB,EAAE,GAAG,CAAC,CAAC;IAEvD,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,CAAC;AAClD,CAAC","sourcesContent":["import envPaths from 'env-paths';\nimport { join } from 'node:path';\n\nconst dev = Boolean(process.env.INSTANT_CLI_DEV);\n\nexport function getAuthPaths() {\n const key = `instantdb-${dev ? 'dev' : 'prod'}`;\n const { config: appConfigDirPath } = envPaths(key);\n const authConfigFilePath = join(appConfigDirPath, 'a');\n\n return { authConfigFilePath, appConfigDirPath };\n}\n"]}
|
package/src/util/getAuthPaths.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import envPaths from 'env-paths';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
|
|
4
|
-
const dev = Boolean(process.env.INSTANT_CLI_DEV);
|
|
5
|
-
|
|
6
|
-
export function getAuthPaths() {
|
|
7
|
-
const key = `instantdb-${dev ? 'dev' : 'prod'}`;
|
|
8
|
-
const { config: appConfigDirPath } = envPaths(key);
|
|
9
|
-
const authConfigFilePath = join(appConfigDirPath, 'a');
|
|
10
|
-
|
|
11
|
-
return { authConfigFilePath, appConfigDirPath };
|
|
12
|
-
}
|