instant-cli 0.22.119-experimental.drewh-tanstack-start.21533425240.1 → 0.22.119-experimental.drewh-clief.21533757490.1

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 (103) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/dist/index.js +1 -1
  3. package/dist/index.js.map +1 -1
  4. package/dist/new/commands/init.d.ts +9 -0
  5. package/dist/new/commands/init.d.ts.map +1 -0
  6. package/dist/new/commands/init.js +9 -0
  7. package/dist/new/commands/init.js.map +1 -0
  8. package/dist/new/commands/initWithoutFiles.d.ts +10 -0
  9. package/dist/new/commands/initWithoutFiles.d.ts.map +1 -0
  10. package/dist/new/commands/initWithoutFiles.js +36 -0
  11. package/dist/new/commands/initWithoutFiles.js.map +1 -0
  12. package/dist/new/commands/login.d.ts +9 -0
  13. package/dist/new/commands/login.d.ts.map +1 -0
  14. package/dist/new/commands/login.js +51 -0
  15. package/dist/new/commands/login.js.map +1 -0
  16. package/dist/new/commands/logout.d.ts +4 -0
  17. package/dist/new/commands/logout.d.ts.map +1 -0
  18. package/dist/new/commands/logout.js +22 -0
  19. package/dist/new/commands/logout.js.map +1 -0
  20. package/dist/new/context/authToken.d.ts +19 -0
  21. package/dist/new/context/authToken.d.ts.map +1 -0
  22. package/dist/new/context/authToken.js +51 -0
  23. package/dist/new/context/authToken.js.map +1 -0
  24. package/dist/new/context/currentApp.d.ts +36 -0
  25. package/dist/new/context/currentApp.d.ts.map +1 -0
  26. package/dist/new/context/currentApp.js +145 -0
  27. package/dist/new/context/currentApp.js.map +1 -0
  28. package/dist/new/context/globalOpts.d.ts +11 -0
  29. package/dist/new/context/globalOpts.d.ts.map +1 -0
  30. package/dist/new/context/globalOpts.js +10 -0
  31. package/dist/new/context/globalOpts.js.map +1 -0
  32. package/dist/new/context/platformApi.d.ts +19 -0
  33. package/dist/new/context/platformApi.d.ts.map +1 -0
  34. package/dist/new/context/platformApi.js +24 -0
  35. package/dist/new/context/platformApi.js.map +1 -0
  36. package/dist/new/context/projectInfo.d.ts +25 -0
  37. package/dist/new/context/projectInfo.d.ts.map +1 -0
  38. package/dist/new/context/projectInfo.js +120 -0
  39. package/dist/new/context/projectInfo.js.map +1 -0
  40. package/dist/new/errors.d.ts +10 -0
  41. package/dist/new/errors.d.ts.map +1 -0
  42. package/dist/new/errors.js +6 -0
  43. package/dist/new/errors.js.map +1 -0
  44. package/dist/new/index.d.ts +17 -0
  45. package/dist/new/index.d.ts.map +1 -0
  46. package/dist/new/index.js +159 -0
  47. package/dist/new/index.js.map +1 -0
  48. package/dist/new/layer.d.ts +15 -0
  49. package/dist/new/layer.d.ts.map +1 -0
  50. package/dist/new/layer.js +41 -0
  51. package/dist/new/layer.js.map +1 -0
  52. package/dist/new/lib/createApp.d.ts +4 -0
  53. package/dist/new/lib/createApp.d.ts.map +1 -0
  54. package/dist/new/lib/createApp.js +13 -0
  55. package/dist/new/lib/createApp.js.map +1 -0
  56. package/dist/new/lib/handleEnv.d.ts +7 -0
  57. package/dist/new/lib/handleEnv.d.ts.map +1 -0
  58. package/dist/new/lib/handleEnv.js +88 -0
  59. package/dist/new/lib/handleEnv.js.map +1 -0
  60. package/dist/new/lib/http.d.ts +15 -0
  61. package/dist/new/lib/http.d.ts.map +1 -0
  62. package/dist/new/lib/http.js +32 -0
  63. package/dist/new/lib/http.js.map +1 -0
  64. package/dist/new/lib/login.d.ts +13 -0
  65. package/dist/new/lib/login.d.ts.map +1 -0
  66. package/dist/new/lib/login.js +36 -0
  67. package/dist/new/lib/login.js.map +1 -0
  68. package/dist/new/lib/ui.d.ts +16 -0
  69. package/dist/new/lib/ui.d.ts.map +1 -0
  70. package/dist/new/lib/ui.js +30 -0
  71. package/dist/new/lib/ui.js.map +1 -0
  72. package/dist/new/logging.d.ts +3 -0
  73. package/dist/new/logging.d.ts.map +1 -0
  74. package/dist/new/logging.js +8 -0
  75. package/dist/new/logging.js.map +1 -0
  76. package/dist/ui/index.d.ts +1 -1
  77. package/dist/ui/index.d.ts.map +1 -1
  78. package/dist/ui/index.js.map +1 -1
  79. package/dist/util/getAuthPaths.d.ts.map +1 -1
  80. package/dist/util/getAuthPaths.js.map +1 -1
  81. package/package.json +14 -5
  82. package/src/index.js +1 -1
  83. package/src/new/commands/init.ts +12 -0
  84. package/src/new/commands/initWithoutFiles.ts +44 -0
  85. package/src/new/commands/login.ts +73 -0
  86. package/src/new/commands/logout.ts +23 -0
  87. package/src/new/context/authToken.ts +77 -0
  88. package/src/new/context/currentApp.ts +207 -0
  89. package/src/new/context/globalOpts.ts +22 -0
  90. package/src/new/context/platformApi.ts +35 -0
  91. package/src/new/context/projectInfo.ts +172 -0
  92. package/src/new/errors.ts +7 -0
  93. package/src/new/index.ts +245 -0
  94. package/src/new/layer.ts +78 -0
  95. package/src/new/lib/createApp.ts +18 -0
  96. package/src/new/lib/handleEnv.ts +107 -0
  97. package/src/new/lib/http.ts +63 -0
  98. package/src/new/lib/login.ts +50 -0
  99. package/src/new/lib/ui.ts +45 -0
  100. package/src/new/logging.ts +9 -0
  101. package/src/ui/index.ts +1 -1
  102. package/src/util/getAuthPaths.ts +1 -0
  103. package/tsconfig.json +7 -2
@@ -0,0 +1,9 @@
1
+ import { Effect } from 'effect';
2
+ import { ProjectInfo } from '../context/projectInfo.js';
3
+ import { CurrentApp } from '../context/currentApp.js';
4
+ export declare const initCommand: (opts: {
5
+ app?: string | undefined;
6
+ package?: string | undefined;
7
+ title?: string | undefined;
8
+ }) => Effect.Effect<void, never, ProjectInfo | CurrentApp>;
9
+ //# sourceMappingURL=init.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../src/new/commands/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD,eAAO,MAAM,WAAW;;;;0DAMtB,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { Effect } from 'effect';
2
+ import { ProjectInfo } from '../context/projectInfo.js';
3
+ import { CurrentApp } from '../context/currentApp.js';
4
+ export const initCommand = Effect.fn(function* (opts) {
5
+ const projectInfo = yield* ProjectInfo;
6
+ const appinfo = yield* CurrentApp;
7
+ console.log(projectInfo, appinfo);
8
+ });
9
+ //# sourceMappingURL=init.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.js","sourceRoot":"","sources":["../../../src/new/commands/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,EAAE,CAAC,QAAQ,CAAC,EAC5C,IAAqC;IAErC,MAAM,WAAW,GAAG,KAAK,CAAC,CAAC,WAAW,CAAC;IACvC,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,UAAU,CAAC;IAClC,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;AACpC,CAAC,CAAC,CAAC","sourcesContent":["import { Effect } from 'effect';\nimport { ArgsFromCommand, initDef } from '../index.js';\nimport { ProjectInfo } from '../context/projectInfo.js';\nimport { CurrentApp } from '../context/currentApp.js';\n\nexport const initCommand = Effect.fn(function* (\n opts: ArgsFromCommand<typeof initDef>,\n) {\n const projectInfo = yield* ProjectInfo;\n const appinfo = yield* CurrentApp;\n console.log(projectInfo, appinfo);\n});\n"]}
@@ -0,0 +1,10 @@
1
+ import { Effect } from 'effect';
2
+ import { PlatformApi } from '../context/platformApi.js';
3
+ import { BadArgsError } from '../errors.js';
4
+ import { GlobalOpts } from '../context/globalOpts.js';
5
+ export declare const initWithoutFilesCommand: (opts: {
6
+ title?: string | undefined;
7
+ orgId?: string | undefined;
8
+ temp?: true | undefined;
9
+ }) => Effect.Effect<undefined, BadArgsError | import("@effect/platform/HttpClientError").HttpClientError | import("@effect/platform/HttpBody").HttpBodyError | import("../context/platformApi.js").PlatformApiError, GlobalOpts | import("../lib/http.js").InstantHttpAuthed | PlatformApi>;
10
+ //# sourceMappingURL=initWithoutFiles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initWithoutFiles.d.ts","sourceRoot":"","sources":["../../../src/new/commands/initWithoutFiles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAG5C,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD,eAAO,MAAM,uBAAuB;;;;2RAoClC,CAAC"}
@@ -0,0 +1,36 @@
1
+ import { Effect } from 'effect';
2
+ import { PlatformApi } from '../context/platformApi.js';
3
+ import { BadArgsError } from '../errors.js';
4
+ import { createApp } from '../lib/createApp.js';
5
+ import { GlobalOpts } from '../context/globalOpts.js';
6
+ export const initWithoutFilesCommand = Effect.fn(function* (opts) {
7
+ const { yes } = yield* GlobalOpts;
8
+ if (!opts?.title) {
9
+ return yield* BadArgsError.make({
10
+ message: 'Title is required for creating a new app without local files.',
11
+ });
12
+ }
13
+ if (opts.title.startsWith('-')) {
14
+ return yield* BadArgsError.make({
15
+ message: `Invalid title: "${opts.title}". Title cannot be a flag.`,
16
+ });
17
+ }
18
+ if (opts?.temp && opts?.orgId) {
19
+ return yield* BadArgsError.make({
20
+ message: 'Cannot use --temp and --org-id flags together.',
21
+ });
22
+ }
23
+ if (!opts.temp) {
24
+ const app = yield* createApp(opts.title, opts.orgId);
25
+ console.log(app);
26
+ }
27
+ else {
28
+ // TODO: fix formatting
29
+ const platform = yield* PlatformApi;
30
+ const app = yield* platform.use((api) => api.createTemporaryApp({
31
+ title: opts.title,
32
+ }));
33
+ console.log(app);
34
+ }
35
+ });
36
+ //# sourceMappingURL=initWithoutFiles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initWithoutFiles.js","sourceRoot":"","sources":["../../../src/new/commands/initWithoutFiles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD,MAAM,CAAC,MAAM,uBAAuB,GAAG,MAAM,CAAC,EAAE,CAAC,QAAQ,CAAC,EACxD,IAAiD;IAEjD,MAAM,EAAE,GAAG,EAAE,GAAG,KAAK,CAAC,CAAC,UAAU,CAAC;IAElC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC;QACjB,OAAO,KAAK,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC;YAC9B,OAAO,EAAE,+DAA+D;SACzE,CAAC,CAAC;IACL,CAAC;IAED,IAAI,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAC/B,OAAO,KAAK,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC;YAC9B,OAAO,EAAE,mBAAmB,IAAI,CAAC,KAAK,4BAA4B;SACnE,CAAC,CAAC;IACL,CAAC;IAED,IAAI,IAAI,EAAE,IAAI,IAAI,IAAI,EAAE,KAAK,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC;YAC9B,OAAO,EAAE,gDAAgD;SAC1D,CAAC,CAAC;IACL,CAAC;IAED,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QACf,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QACrD,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACnB,CAAC;SAAM,CAAC;QACN,uBAAuB;QACvB,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,WAAW,CAAC;QACpC,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CACtC,GAAG,CAAC,kBAAkB,CAAC;YACrB,KAAK,EAAE,IAAI,CAAC,KAAM;SACnB,CAAC,CACH,CAAC;QACF,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACnB,CAAC;AACH,CAAC,CAAC,CAAC","sourcesContent":["import { Effect } from 'effect';\nimport { PlatformApi } from '../context/platformApi.js';\nimport { BadArgsError } from '../errors.js';\nimport { ArgsFromCommand, initWithoutFilesDef } from '../index.js';\nimport { createApp } from '../lib/createApp.js';\nimport { GlobalOpts } from '../context/globalOpts.js';\n\nexport const initWithoutFilesCommand = Effect.fn(function* (\n opts: ArgsFromCommand<typeof initWithoutFilesDef>,\n) {\n const { yes } = yield* GlobalOpts;\n\n if (!opts?.title) {\n return yield* BadArgsError.make({\n message: 'Title is required for creating a new app without local files.',\n });\n }\n\n if (opts.title.startsWith('-')) {\n return yield* BadArgsError.make({\n message: `Invalid title: \"${opts.title}\". Title cannot be a flag.`,\n });\n }\n\n if (opts?.temp && opts?.orgId) {\n return yield* BadArgsError.make({\n message: 'Cannot use --temp and --org-id flags together.',\n });\n }\n\n if (!opts.temp) {\n const app = yield* createApp(opts.title, opts.orgId);\n console.log(app);\n } else {\n // TODO: fix formatting\n const platform = yield* PlatformApi;\n const app = yield* platform.use((api) =>\n api.createTemporaryApp({\n title: opts.title!,\n }),\n );\n console.log(app);\n }\n});\n"]}
@@ -0,0 +1,9 @@
1
+ import { Effect } from 'effect';
2
+ export declare const loginCommand: (opts: {
3
+ print?: true | undefined;
4
+ headless?: true | undefined;
5
+ }) => Effect.Effect<{
6
+ authToken: string;
7
+ source: "file";
8
+ }, import("effect/Cause").UnknownException | import("@effect/platform/HttpClientError").HttpClientError | import("effect/ParseResult").ParseError | import("@effect/platform/HttpBody").HttpBodyError | import("@effect/platform/Error").PlatformError | import("effect/ConfigError").ConfigError, import("../context/globalOpts.js").GlobalOpts | import("../lib/http.js").InstantHttp | import("@effect/platform/FileSystem").FileSystem>;
9
+ //# sourceMappingURL=login.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../../src/new/commands/login.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AA2BhC,eAAO,MAAM,YAAY;;;;;;2aA4CvB,CAAC"}
@@ -0,0 +1,51 @@
1
+ import chalk from 'chalk';
2
+ import { Effect } from 'effect';
3
+ import openInBrowser from 'open';
4
+ import { getDashUrl } from '../lib/http.js';
5
+ import { getLoginTicketAndSecret, saveConfigAuthToken, waitForAuthToken, } from '../lib/login.js';
6
+ import { promptOk } from '../lib/ui.js';
7
+ const isHeadLessEnvironment = (opts) => {
8
+ const noBrowserMode = Boolean(process.env.INSTANT_CLI_NO_BROWSER || process.env.CI || opts?.headless);
9
+ // Check for common headless environment indicators
10
+ return (noBrowserMode ||
11
+ process.env.TERM === 'dumb' ||
12
+ process.env.SSH_CONNECTION !== undefined ||
13
+ process.env.SSH_CLIENT !== undefined ||
14
+ (!process.env.DISPLAY && process.platform === 'linux') ||
15
+ process.env.WSL_DISTRO_NAME !== undefined);
16
+ };
17
+ export const loginCommand = Effect.fn(function* (opts) {
18
+ console.log("Let's log you in!");
19
+ const loginInfo = yield* getLoginTicketAndSecret;
20
+ const { secret, ticket } = loginInfo;
21
+ const dashOrigin = yield* getDashUrl;
22
+ console.log();
23
+ // TODO: flip these so rejecting the prompt prints url
24
+ if (isHeadLessEnvironment(opts)) {
25
+ console.log(`Open this URL in a browser to log in:\n ${dashOrigin}/dash?ticket=${ticket}\n`);
26
+ }
27
+ else {
28
+ const ok = yield* promptOk({
29
+ promptText: 'This will open instantdb.com in your browser, OK to proceed?',
30
+ }, true);
31
+ if (!ok) {
32
+ process.exit(1);
33
+ }
34
+ yield* Effect.tryPromise(() => openInBrowser(`${dashOrigin}/dash?ticket=${ticket}`));
35
+ }
36
+ console.log('Waiting for authentication...');
37
+ const result = yield* waitForAuthToken(secret);
38
+ const { token, email } = result;
39
+ if (opts.print) {
40
+ console.log(chalk.red('[Do not share] Your Instant auth token:', token));
41
+ }
42
+ else {
43
+ yield* saveConfigAuthToken(token);
44
+ console.log(chalk.green(`Successfully logged in as ${email}!`));
45
+ }
46
+ return {
47
+ authToken: token,
48
+ source: 'file',
49
+ };
50
+ });
51
+ //# sourceMappingURL=login.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"login.js","sourceRoot":"","sources":["../../../src/new/commands/login.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,aAAa,MAAM,MAAM,CAAC;AAEjC,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EACL,uBAAuB,EACvB,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,MAAM,qBAAqB,GAAG,CAAC,IAAsC,EAAE,EAAE;IACvE,MAAM,aAAa,GAAG,OAAO,CAC3B,OAAO,CAAC,GAAG,CAAC,sBAAsB,IAAI,OAAO,CAAC,GAAG,CAAC,EAAE,IAAI,IAAI,EAAE,QAAQ,CACvE,CAAC;IAEF,mDAAmD;IACnD,OAAO,CACL,aAAa;QACb,OAAO,CAAC,GAAG,CAAC,IAAI,KAAK,MAAM;QAC3B,OAAO,CAAC,GAAG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M,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;IAChC,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,yCAAyC,EAAE,KAAK,CAAC,CAAC,CAAC;IAC3E,CAAC;SAAM,CAAC;QACN,KAAK,CAAC,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC;QAClC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,6BAA6B,KAAK,GAAG,CAAC,CAAC,CAAC;IAClE,CAAC;IACD,OAAO;QACL,SAAS,EAAE,KAAK;QAChB,MAAM,EAAE,MAAe;KACxB,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["import chalk from 'chalk';\nimport { Effect } from 'effect';\nimport openInBrowser from 'open';\nimport { ArgsFromCommand, loginDef } from '../index.js';\nimport { getDashUrl } from '../lib/http.js';\nimport {\n getLoginTicketAndSecret,\n saveConfigAuthToken,\n waitForAuthToken,\n} from '../lib/login.js';\nimport { promptOk } from '../lib/ui.js';\n\nconst isHeadLessEnvironment = (opts: ArgsFromCommand<typeof loginDef>) => {\n const noBrowserMode = Boolean(\n process.env.INSTANT_CLI_NO_BROWSER || process.env.CI || opts?.headless,\n );\n\n // Check for common headless environment indicators\n return (\n noBrowserMode ||\n process.env.TERM === 'dumb' ||\n process.env.SSH_CONNECTION !== undefined ||\n process.env.SSH_CLIENT !== undefined ||\n (!process.env.DISPLAY && process.platform === 'linux') ||\n process.env.WSL_DISTRO_NAME !== undefined\n );\n};\n\nexport const loginCommand = Effect.fn(function* (\n opts: ArgsFromCommand<typeof loginDef>,\n) {\n console.log(\"Let's log you in!\");\n\n const loginInfo = yield* getLoginTicketAndSecret;\n const { secret, ticket } = loginInfo;\n const dashOrigin = yield* getDashUrl;\n console.log();\n // TODO: flip these so rejecting the prompt prints url\n if (isHeadLessEnvironment(opts)) {\n console.log(\n `Open this URL in a browser to log in:\\n ${dashOrigin}/dash?ticket=${ticket}\\n`,\n );\n } else {\n const ok = yield* promptOk(\n {\n promptText:\n 'This will open instantdb.com in your browser, OK to proceed?',\n },\n true,\n );\n if (!ok) {\n process.exit(1);\n }\n yield* Effect.tryPromise(() =>\n openInBrowser(`${dashOrigin}/dash?ticket=${ticket}`),\n );\n }\n\n console.log('Waiting for authentication...');\n\n const result = yield* waitForAuthToken(secret);\n const { token, email } = result;\n if (opts.print) {\n console.log(chalk.red('[Do not share] Your Instant auth token:', token));\n } else {\n yield* saveConfigAuthToken(token);\n console.log(chalk.green(`Successfully logged in as ${email}!`));\n }\n return {\n authToken: token,\n source: 'file' as const,\n };\n});\n"]}
@@ -0,0 +1,4 @@
1
+ import { Effect } from 'effect';
2
+ import { FileSystem } from '@effect/platform';
3
+ export declare const logoutCommand: () => Effect.Effect<void, never, FileSystem.FileSystem>;
4
+ //# sourceMappingURL=logout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logout.d.ts","sourceRoot":"","sources":["../../../src/new/commands/logout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAK9C,eAAO,MAAM,aAAa,yDAexB,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { Effect } from 'effect';
2
+ import { getAuthPaths } from '../../util/getAuthPaths.js';
3
+ import { FileSystem } from '@effect/platform';
4
+ import chalk from 'chalk';
5
+ import { SystemError } from '@effect/platform/Error';
6
+ import { error } from '../logging.js';
7
+ export const logoutCommand = Effect.fn(function* () {
8
+ const { authConfigFilePath } = getAuthPaths();
9
+ const fs = yield* FileSystem.FileSystem;
10
+ yield* Effect.match(fs.remove(authConfigFilePath), {
11
+ onFailure: (e) => {
12
+ if (e instanceof SystemError && e.reason === 'NotFound') {
13
+ console.log(chalk.green('You were already logged out!'));
14
+ }
15
+ else {
16
+ error('Failed to logout: ' + e.message);
17
+ }
18
+ },
19
+ onSuccess: () => console.log(chalk.green('Successfully logged out from Instant!')),
20
+ });
21
+ });
22
+ //# sourceMappingURL=logout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logout.js","sourceRoot":"","sources":["../../../src/new/commands/logout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,EAAE,CAAC,QAAQ,CAAC;IAC9C,MAAM,EAAE,kBAAkB,EAAE,GAAG,YAAY,EAAE,CAAC;IAC9C,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC;IAExC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,kBAAkB,CAAC,EAAE;QACjD,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE;YACf,IAAI,CAAC,YAAY,WAAW,IAAI,CAAC,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;gBACxD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAC,CAAC;YAC3D,CAAC;iBAAM,CAAC;gBACN,KAAK,CAAC,oBAAoB,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC;YAC1C,CAAC;QACH,CAAC;QACD,SAAS,EAAE,GAAG,EAAE,CACd,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,uCAAuC,CAAC,CAAC;KACpE,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { Effect } from 'effect';\nimport { getAuthPaths } from '../../util/getAuthPaths.js';\nimport { FileSystem } from '@effect/platform';\nimport chalk from 'chalk';\nimport { SystemError } from '@effect/platform/Error';\nimport { error } from '../logging.js';\n\nexport const logoutCommand = Effect.fn(function* () {\n const { authConfigFilePath } = getAuthPaths();\n const fs = yield* FileSystem.FileSystem;\n\n yield* Effect.match(fs.remove(authConfigFilePath), {\n onFailure: (e) => {\n if (e instanceof SystemError && e.reason === 'NotFound') {\n console.log(chalk.green('You were already logged out!'));\n } else {\n error('Failed to logout: ' + e.message);\n }\n },\n onSuccess: () =>\n console.log(chalk.green('Successfully logged out from Instant!')),\n });\n});\n"]}
@@ -0,0 +1,19 @@
1
+ import { FileSystem } from '@effect/platform';
2
+ import { Context, Layer, Schema } from 'effect';
3
+ declare const AuthToken_base: Context.TagClass<AuthToken, "instant-cli/new/context/authToken", {
4
+ authToken: string;
5
+ source: "env" | "opt" | "file";
6
+ }>;
7
+ export declare class AuthToken extends AuthToken_base {
8
+ }
9
+ declare const NotAuthedError_base: Schema.TaggedErrorClass<NotAuthedError, "NotAuthedError", {
10
+ readonly _tag: Schema.tag<"NotAuthedError">;
11
+ } & {
12
+ message: typeof Schema.String;
13
+ }>;
14
+ export declare class NotAuthedError extends NotAuthedError_base {
15
+ }
16
+ export declare const AuthTokenLive: Layer.Layer<AuthToken, import("@effect/platform/Error").PlatformError | import("effect/ConfigError").ConfigError | NotAuthedError, FileSystem.FileSystem>;
17
+ export declare const AuthTokenCoerceLive: Layer.Layer<AuthToken, import("effect/Cause").UnknownException | import("@effect/platform/HttpClientError").HttpClientError | import("effect/ParseResult").ParseError | import("@effect/platform/HttpBody").HttpBodyError | import("@effect/platform/Error").PlatformError | import("effect/ConfigError").ConfigError, import("./globalOpts.js").GlobalOpts | import("../lib/http.js").InstantHttp | FileSystem.FileSystem>;
18
+ export {};
19
+ //# sourceMappingURL=authToken.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authToken.d.ts","sourceRoot":"","sources":["../../../src/new/context/authToken.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EAAU,OAAO,EAAU,KAAK,EAAU,MAAM,EAAE,MAAM,QAAQ,CAAC;;eAQzD,MAAM;YACT,KAAK,GAAG,KAAK,GAAG,MAAM;;AAJlC,qBAAa,SAAU,SAAQ,cAM5B;CAAG;;;;;;AAEN,qBAAa,cAAe,SAAQ,mBAIlC;CAAG;AAmCL,eAAO,MAAM,aAAa,2JAA8C,CAAC;AAEzE,eAAO,MAAM,mBAAmB,6ZAU/B,CAAC"}
@@ -0,0 +1,51 @@
1
+ import { FileSystem } from '@effect/platform';
2
+ import { program } from 'commander';
3
+ import { Config, Context, Effect, Layer, Option, Schema } from 'effect';
4
+ import envPaths from 'env-paths';
5
+ import { join } from 'path';
6
+ import { loginCommand } from '../commands/login.js';
7
+ export class AuthToken extends Context.Tag('instant-cli/new/context/authToken')() {
8
+ }
9
+ export class NotAuthedError extends Schema.TaggedError('NotAuthedError')('NotAuthedError', {
10
+ message: Schema.String,
11
+ }) {
12
+ }
13
+ const authTokenGetEffect = Effect.gen(function* () {
14
+ const options = program.opts();
15
+ if (typeof options.token === 'string') {
16
+ return {
17
+ authToken: options.token,
18
+ source: 'opt',
19
+ };
20
+ }
21
+ const env = Option.getOrNull(yield* Config.string('INSTANT_CLI_AUTH_TOKEN').pipe(Config.option));
22
+ if (env) {
23
+ return {
24
+ authToken: env,
25
+ source: 'env',
26
+ };
27
+ }
28
+ const authPaths = yield* getAuthPaths;
29
+ const fs = yield* FileSystem.FileSystem;
30
+ const file = yield* fs.readFileString(authPaths.authConfigFilePath, 'utf8');
31
+ if (file) {
32
+ return {
33
+ authToken: file,
34
+ source: 'file',
35
+ };
36
+ }
37
+ return yield* NotAuthedError.make({ message: 'You are not logged in' });
38
+ });
39
+ export const AuthTokenLive = Layer.effect(AuthToken, authTokenGetEffect);
40
+ export const AuthTokenCoerceLive = Layer.effect(AuthToken, authTokenGetEffect.pipe(Effect.catchTag('NotAuthedError', () => loginCommand({
41
+ print: true,
42
+ headless: true,
43
+ }))));
44
+ const getAuthPaths = Effect.gen(function* () {
45
+ const dev = yield* Config.boolean('INSTANT_CLI_DEV').pipe(Config.withDefault(false));
46
+ const key = `instantdb-${dev ? 'dev' : 'prod'}`;
47
+ const { config: appConfigDirPath } = envPaths(key);
48
+ const authConfigFilePath = join(appConfigDirPath, 'a');
49
+ return { authConfigFilePath, appConfigDirPath };
50
+ });
51
+ //# sourceMappingURL=authToken.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authToken.js","sourceRoot":"","sources":["../../../src/new/context/authToken.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxE,OAAO,QAAQ,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,MAAM,OAAO,SAAU,SAAQ,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,EAM5E;CAAG;AAEN,MAAM,OAAO,cAAe,SAAQ,MAAM,CAAC,WAAW,CACpD,gBAAgB,CACjB,CAAC,gBAAgB,EAAE;IAClB,OAAO,EAAE,MAAM,CAAC,MAAM;CACvB,CAAC;CAAG;AAEL,MAAM,kBAAkB,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAC7C,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAC/B,IAAI,OAAO,OAAO,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;QACtC,OAAO;YACL,SAAS,EAAE,O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AK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC,IAAI,CACvD,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAC1B,CAAC;IACF,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;IACvD,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,CAAC;AAClD,CAAC,CAAC,CAAC","sourcesContent":["import { FileSystem } from '@effect/platform';\nimport { program } from 'commander';\nimport { Config, Context, Effect, Layer, Option, Schema } from 'effect';\nimport envPaths from 'env-paths';\nimport { join } from 'path';\nimport { loginCommand } from '../commands/login.js';\n\nexport class AuthToken extends Context.Tag('instant-cli/new/context/authToken')<\n AuthToken,\n {\n authToken: string;\n source: 'env' | 'opt' | 'file';\n }\n>() {}\n\nexport class NotAuthedError extends Schema.TaggedError<NotAuthedError>(\n 'NotAuthedError',\n)('NotAuthedError', {\n message: Schema.String,\n}) {}\n\nconst authTokenGetEffect = Effect.gen(function* () {\n const options = program.opts();\n if (typeof options.token === 'string') {\n return {\n authToken: options.token,\n source: 'opt' as 'env' | 'opt' | 'file',\n };\n }\n\n const env = Option.getOrNull(\n yield* Config.string('INSTANT_CLI_AUTH_TOKEN').pipe(Config.option),\n );\n if (env) {\n return {\n authToken: env,\n source: 'env' as 'env' | 'opt' | 'file',\n };\n }\n\n const authPaths = yield* getAuthPaths;\n const fs = yield* FileSystem.FileSystem;\n const file = yield* fs.readFileString(authPaths.authConfigFilePath, 'utf8');\n\n if (file) {\n return {\n authToken: file,\n source: 'file' as 'env' | 'opt' | 'file',\n };\n }\n\n return yield* NotAuthedError.make({ message: 'You are not logged in' });\n});\n\nexport const AuthTokenLive = Layer.effect(AuthToken, authTokenGetEffect);\n\nexport const AuthTokenCoerceLive = Layer.effect(\n AuthToken,\n authTokenGetEffect.pipe(\n Effect.catchTag('NotAuthedError', () =>\n loginCommand({\n print: true,\n headless: true,\n }),\n ),\n ),\n);\n\nconst getAuthPaths = Effect.gen(function* () {\n const dev = yield* Config.boolean('INSTANT_CLI_DEV').pipe(\n Config.withDefault(false),\n );\n const key = `instantdb-${dev ? 'dev' : 'prod'}`;\n const { config: appConfigDirPath } = envPaths(key);\n const authConfigFilePath = join(appConfigDirPath, 'a');\n return { authConfigFilePath, appConfigDirPath };\n});\n"]}
@@ -0,0 +1,36 @@
1
+ import { Context, Layer } from 'effect';
2
+ import { InstantHttpAuthed } from '../lib/http.js';
3
+ import { AuthToken } from './authToken.js';
4
+ import { GlobalOpts } from './globalOpts.js';
5
+ import { PlatformApi } from './platformApi.js';
6
+ export type CurrentAppInfo = {
7
+ appId: string;
8
+ adminToken?: string;
9
+ source: 'create' | 'import' | 'env' | 'flag' | 'ephemeral';
10
+ };
11
+ declare const CurrentApp_base: Context.TagClass<CurrentApp, "instant-cli/new/context/currentApp", CurrentAppInfo>;
12
+ export declare class CurrentApp extends CurrentApp_base {
13
+ }
14
+ declare const CurrentAppContextError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
15
+ readonly _tag: "CurrentAppContextError";
16
+ } & Readonly<A>;
17
+ export declare class CurrentAppContextError extends CurrentAppContextError_base<{
18
+ message: string;
19
+ }> {
20
+ }
21
+ declare const AppNotFoundError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
22
+ readonly _tag: "AppNotFoundError";
23
+ } & Readonly<A>;
24
+ export declare class AppNotFoundError extends AppNotFoundError_base<{
25
+ message: string;
26
+ }> {
27
+ }
28
+ export declare const potentialEnvs: Record<string, string>;
29
+ export declare const CurrentAppLive: (args: {
30
+ appId?: string;
31
+ coerce?: boolean;
32
+ title?: string;
33
+ applyEnv?: boolean;
34
+ }) => Layer.Layer<CurrentApp, import("../lib/ui.js").UIError | import("@effect/platform/HttpClientError").HttpClientError | import("effect/ParseResult").ParseError | import("@effect/platform/HttpBody").HttpBodyError | import("@effect/platform/Error").PlatformError | import("effect/ConfigError").ConfigError | CurrentAppContextError | AppNotFoundError, GlobalOpts | import("./projectInfo.js").ProjectInfo | import("@effect/platform/FileSystem").FileSystem | AuthToken | InstantHttpAuthed | import("@effect/platform/Path").Path | PlatformApi>;
35
+ export {};
36
+ //# sourceMappingURL=currentApp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"currentApp.d.ts","sourceRoot":"","sources":["../../../src/new/context/currentApp.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAgB,KAAK,EAAmB,MAAM,QAAQ,CAAC;AAGvE,OAAO,EAAc,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAE/D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,QAAQ,GAAG,QAAQ,GAAG,KAAK,GAAG,MAAM,GAAG,WAAW,CAAC;CAC5D,CAAC;;AAEF,qBAAa,UAAW,SAAQ,eAED;CAAG;;;;AAQlC,qBAAa,sBAAuB,SAAQ,4BAE1C;IACA,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;CAAG;;;;AAEL,qBAAa,gBAAiB,SAAQ,sBAAqC;IACzE,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;CAAG;AAEL,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAOhD,CAAC;AAGF,eAAO,MAAM,cAAc,GAAI,MAAM;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,4hBAoEE,CAAC"}
@@ -0,0 +1,145 @@
1
+ import { HttpClientRequest, HttpClientResponse } from '@effect/platform';
2
+ import { randomUUID } from 'crypto';
3
+ import { Context, Data, Effect, Layer, Runtime, Schema } from 'effect';
4
+ import { UI } from '../../ui/index.js';
5
+ import { handleEnv } from '../lib/handleEnv.js';
6
+ import { getBaseUrl, InstantHttpAuthed } from '../lib/http.js';
7
+ import { runUIEffect } from '../lib/ui.js';
8
+ import { AuthToken } from './authToken.js';
9
+ import { GlobalOpts } from './globalOpts.js';
10
+ import { PlatformApi } from './platformApi.js';
11
+ export class CurrentApp extends Context.Tag('instant-cli/new/context/currentApp')() {
12
+ }
13
+ function isUUID(uuid) {
14
+ const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
15
+ return uuidRegex.test(uuid);
16
+ }
17
+ export class CurrentAppContextError extends Data.TaggedError('CurrentAppContextError') {
18
+ }
19
+ export class AppNotFoundError extends Data.TaggedError('AppNotFoundError') {
20
+ }
21
+ export const potentialEnvs = {
22
+ catchall: 'INSTANT_APP_ID',
23
+ next: 'NEXT_PUBLIC_INSTANT_APP_ID',
24
+ svelte: 'PUBLIC_INSTANT_APP_ID',
25
+ vite: 'VITE_INSTANT_APP_ID',
26
+ expo: 'EXPO_PUBLIC_INSTANT_APP_ID',
27
+ nuxt: 'NUXT_PUBLIC_INSTANT_APP_ID',
28
+ };
29
+ // TODO: add instant.config.ts support
30
+ export const CurrentAppLive = (args) => Layer.effect(CurrentApp, Effect.gen(function* () {
31
+ if (args.appId) {
32
+ return {
33
+ appId: args.appId,
34
+ source: 'flag',
35
+ };
36
+ }
37
+ // Detect from ENV
38
+ const found = Object.keys(potentialEnvs)
39
+ .map((type) => {
40
+ const envName = potentialEnvs[type];
41
+ const value = process.env[envName];
42
+ return { type, envName, value };
43
+ })
44
+ .find(({ value }) => !!value);
45
+ if (found?.value && !isUUID(found.value)) {
46
+ return yield* new CurrentAppContextError({
47
+ message: `Invalid UUID: ${found.value}`,
48
+ });
49
+ }
50
+ else if (found?.value) {
51
+ return {
52
+ appId: found?.value,
53
+ source: 'env',
54
+ };
55
+ }
56
+ return yield* new AppNotFoundError({
57
+ message: 'No app found',
58
+ });
59
+ }).pipe(
60
+ // coerce into new app if app not found
61
+ Effect.catchTag('AppNotFoundError', () => Effect.gen(function* () {
62
+ if (!args.coerce)
63
+ return yield* new AppNotFoundError({ message: 'No app found' });
64
+ // coerce into a new app
65
+ const globalOpts = yield* GlobalOpts;
66
+ if (globalOpts.yes) {
67
+ if (!args.title) {
68
+ return yield* new CurrentAppContextError({
69
+ message: `Title is required when using --yes and no app is linked`,
70
+ });
71
+ }
72
+ else {
73
+ return yield* createApp(args.title);
74
+ }
75
+ }
76
+ return yield* promptImportOrCreateApp;
77
+ })),
78
+ // Handle save env
79
+ Effect.tap((app) => Effect.gen(function* () {
80
+ if (args.applyEnv &&
81
+ (app.source === 'import' || app.source == 'create')) {
82
+ yield* handleEnv(app);
83
+ }
84
+ }))));
85
+ const createApp = Effect.fn(function* (title, orgId) {
86
+ const id = randomUUID();
87
+ const token = randomUUID();
88
+ const app = { id, title, admin_token: token, org_id: orgId };
89
+ const http = yield* InstantHttpAuthed;
90
+ yield* HttpClientRequest.post('/dash/apps').pipe(HttpClientRequest.bodyJson(app), Effect.flatMap(http.execute));
91
+ return {
92
+ appId: id,
93
+ source: 'create',
94
+ adminToken: token,
95
+ };
96
+ });
97
+ const promptImportOrCreateApp = Effect.gen(function* () {
98
+ const api = yield* getSimpleApi;
99
+ const result = yield* runUIEffect(new UI.AppSelector({
100
+ allowEphemeral: true,
101
+ allowCreate: true,
102
+ api,
103
+ }));
104
+ return {
105
+ appId: result.appId,
106
+ source: result.approach,
107
+ adminToken: result.adminToken,
108
+ };
109
+ });
110
+ const getSimpleApi = Effect.gen(function* () {
111
+ const effectRuntime = yield* Effect.runtime();
112
+ const http = yield* InstantHttpAuthed;
113
+ const dashData = yield* http
114
+ .get('/dash')
115
+ .pipe(Effect.flatMap(HttpClientResponse.schemaBodyJson(Schema.Any)));
116
+ const platform = yield* PlatformApi;
117
+ const baseUrl = yield* getBaseUrl;
118
+ const { authToken } = yield* AuthToken;
119
+ return {
120
+ getDash: () => dashData,
121
+ createApp: async (title, orgId) => {
122
+ return Runtime.runPromise(effectRuntime, createApp(title, orgId).pipe(Effect.provideService(InstantHttpAuthed, http)));
123
+ },
124
+ createEphemeralApp: async (title) => {
125
+ return await Runtime.runPromise(effectRuntime, Effect.gen(function* () {
126
+ const platform = yield* PlatformApi;
127
+ const response = yield* platform.use((p) => p.createTemporaryApp({ title: title }), 'Error creating temporary app');
128
+ return {
129
+ appId: response.app.id,
130
+ adminToken: response.app.adminToken,
131
+ };
132
+ }).pipe(Effect.provideService(PlatformApi, platform)));
133
+ },
134
+ async getAppsForOrg(orgId) {
135
+ const response = await fetch(baseUrl + '/dash/orgs/' + orgId, {
136
+ headers: {
137
+ Authorization: `Bearer ${authToken}`,
138
+ },
139
+ });
140
+ const data = await response.json();
141
+ return { apps: data.apps };
142
+ },
143
+ };
144
+ });
145
+ //# sourceMappingURL=currentApp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"currentApp.js","sourceRoot":"","sources":["../../../src/new/context/currentApp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,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AChC,CAAC,CAAC,CAAC","sourcesContent":["import { HttpClientRequest, HttpClientResponse } from '@effect/platform';\nimport { randomUUID } from 'crypto';\nimport { Context, Data, Effect, Layer, Runtime, Schema } from 'effect';\nimport { UI } from '../../ui/index.js';\nimport { handleEnv } from '../lib/handleEnv.js';\nimport { getBaseUrl, InstantHttpAuthed } from '../lib/http.js';\nimport { runUIEffect } from '../lib/ui.js';\nimport { AuthToken } from './authToken.js';\nimport { GlobalOpts } from './globalOpts.js';\nimport { PlatformApi } from './platformApi.js';\n\nexport type CurrentAppInfo = {\n appId: string;\n adminToken?: string;\n source: 'create' | 'import' | 'env' | 'flag' | 'ephemeral';\n};\n\nexport class CurrentApp extends Context.Tag(\n 'instant-cli/new/context/currentApp',\n)<CurrentApp, CurrentAppInfo>() {}\n\nfunction isUUID(uuid) {\n const uuidRegex =\n /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;\n return uuidRegex.test(uuid);\n}\n\nexport class CurrentAppContextError extends Data.TaggedError(\n 'CurrentAppContextError',\n)<{\n message: string;\n}> {}\n\nexport class AppNotFoundError extends Data.TaggedError('AppNotFoundError')<{\n message: string;\n}> {}\n\nexport const potentialEnvs: Record<string, string> = {\n catchall: 'INSTANT_APP_ID',\n next: 'NEXT_PUBLIC_INSTANT_APP_ID',\n svelte: 'PUBLIC_INSTANT_APP_ID',\n vite: 'VITE_INSTANT_APP_ID',\n expo: 'EXPO_PUBLIC_INSTANT_APP_ID',\n nuxt: 'NUXT_PUBLIC_INSTANT_APP_ID',\n};\n\n// TODO: add instant.config.ts support\nexport const CurrentAppLive = (args: {\n appId?: string;\n coerce?: boolean;\n title?: string;\n applyEnv?: boolean;\n}) =>\n Layer.effect(\n CurrentApp,\n Effect.gen(function* () {\n if (args.appId) {\n return {\n appId: args.appId,\n source: 'flag' as const,\n };\n }\n\n // Detect from ENV\n const found = Object.keys(potentialEnvs)\n .map((type) => {\n const envName = potentialEnvs[type];\n const value = process.env[envName];\n return { type, envName, value };\n })\n .find(({ value }) => !!value);\n\n if (found?.value && !isUUID(found.value)) {\n return yield* new CurrentAppContextError({\n message: `Invalid UUID: ${found.value}`,\n });\n } else if (found?.value) {\n return {\n appId: found?.value,\n source: 'env' as const,\n };\n }\n return yield* new AppNotFoundError({\n message: 'No app found',\n });\n }).pipe(\n // coerce into new app if app not found\n Effect.catchTag('AppNotFoundError', () =>\n Effect.gen(function* () {\n if (!args.coerce)\n return yield* new AppNotFoundError({ message: 'No app found' });\n\n // coerce into a new app\n const globalOpts = yield* GlobalOpts;\n if (globalOpts.yes) {\n if (!args.title) {\n return yield* new CurrentAppContextError({\n message: `Title is required when using --yes and no app is linked`,\n });\n } else {\n return yield* createApp(args.title);\n }\n }\n\n return yield* promptImportOrCreateApp;\n }),\n ),\n\n // Handle save env\n Effect.tap((app) =>\n Effect.gen(function* () {\n if (\n args.applyEnv &&\n (app.source === 'import' || app.source == 'create')\n ) {\n yield* handleEnv(app);\n }\n }),\n ),\n ),\n );\n\nconst createApp = Effect.fn(function* (title: string, orgId?: string) {\n const id = randomUUID();\n const token = randomUUID();\n const app = { id, title, admin_token: token, org_id: orgId };\n\n const http = yield* InstantHttpAuthed;\n yield* HttpClientRequest.post('/dash/apps').pipe(\n HttpClientRequest.bodyJson(app),\n Effect.flatMap(http.execute),\n );\n return {\n appId: id,\n source: 'create',\n adminToken: token,\n } satisfies CurrentAppInfo;\n});\n\nconst promptImportOrCreateApp = Effect.gen(function* () {\n const api = yield* getSimpleApi;\n const result = yield* runUIEffect(\n new UI.AppSelector({\n allowEphemeral: true,\n allowCreate: true,\n api,\n }),\n );\n\n return {\n appId: result.appId,\n source: result.approach,\n adminToken: result.adminToken,\n } satisfies CurrentAppInfo;\n});\n\nconst getSimpleApi = Effect.gen(function* () {\n const effectRuntime = yield* Effect.runtime<never>();\n\n const http = yield* InstantHttpAuthed;\n const dashData = yield* http\n .get('/dash')\n .pipe(Effect.flatMap(HttpClientResponse.schemaBodyJson(Schema.Any)));\n const platform = yield* PlatformApi;\n\n const baseUrl = yield* getBaseUrl;\n const { authToken } = yield* AuthToken;\n\n return {\n getDash: () => dashData,\n createApp: async (title, orgId) => {\n return Runtime.runPromise(\n effectRuntime,\n createApp(title, orgId).pipe(\n Effect.provideService(InstantHttpAuthed, http),\n ),\n );\n },\n\n createEphemeralApp: async (title) => {\n return await Runtime.runPromise(\n effectRuntime,\n Effect.gen(function* () {\n const platform = yield* PlatformApi;\n const response = yield* platform.use(\n (p) => p.createTemporaryApp({ title: title }),\n 'Error creating temporary app',\n );\n return {\n appId: response.app.id,\n adminToken: response.app.adminToken,\n };\n }).pipe(Effect.provideService(PlatformApi, platform)),\n );\n },\n\n async getAppsForOrg(orgId) {\n const response = await fetch(baseUrl + '/dash/orgs/' + orgId, {\n headers: {\n Authorization: `Bearer ${authToken}`,\n },\n });\n const data = await response.json();\n return { apps: data.apps };\n },\n } satisfies UI.AppSelectorApi;\n});\n"]}
@@ -0,0 +1,11 @@
1
+ import { Context, Layer } from 'effect';
2
+ declare const GlobalOpts_base: Context.TagClass<GlobalOpts, "instant-cli/new/context/globalOpts", {
3
+ token?: string;
4
+ yes: boolean;
5
+ env?: string;
6
+ }>;
7
+ export declare class GlobalOpts extends GlobalOpts_base {
8
+ }
9
+ export declare const GlobalOptsLive: Layer.Layer<GlobalOpts, never, never>;
10
+ export {};
11
+ //# sourceMappingURL=globalOpts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"globalOpts.d.ts","sourceRoot":"","sources":["../../../src/new/context/globalOpts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAU,KAAK,EAAE,MAAM,QAAQ,CAAC;;YAOpC,MAAM;SACT,OAAO;UACN,MAAM;;AAPhB,qBAAa,UAAW,SAAQ,eAS7B;CAAG;AAEN,eAAO,MAAM,cAAc,uCAO1B,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { program } from 'commander';
2
+ import { Context, Effect, Layer } from 'effect';
3
+ export class GlobalOpts extends Context.Tag('instant-cli/new/context/globalOpts')() {
4
+ }
5
+ export const GlobalOptsLive = Layer.effect(GlobalOpts, Effect.gen(function* () {
6
+ return {
7
+ yes: program.optsWithGlobals()?.yes || false,
8
+ };
9
+ }));
10
+ //# sourceMappingURL=globalOpts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"globalOpts.js","sourceRoot":"","sources":["../../../src/new/context/globalOpts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAEhD,MAAM,OAAO,UAAW,SAAQ,OAAO,CAAC,GAAG,CACzC,oCAAoC,CACrC,EAOE;CAAG;AAEN,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,CAAC,MAAM,CACxC,UAAU,EACV,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,OAAO;QACL,GAAG,EAAE,OAAO,CAAC,eAAe,EAAE,EAAE,GAAG,IAAI,KAAK;KAC7C,CAAC;AACJ,CAAC,CAAC,CACH,CAAC","sourcesContent":["import { program } from 'commander';\nimport { Context, Effect, Layer } from 'effect';\n\nexport class GlobalOpts extends Context.Tag(\n 'instant-cli/new/context/globalOpts',\n)<\n GlobalOpts,\n {\n token?: string;\n yes: boolean;\n env?: string;\n }\n>() {}\n\nexport const GlobalOptsLive = Layer.effect(\n GlobalOpts,\n Effect.gen(function* () {\n return {\n yes: program.optsWithGlobals()?.yes || false,\n };\n }),\n);\n"]}
@@ -0,0 +1,19 @@
1
+ import { Effect } from 'effect';
2
+ import { PlatformApi as InstantPlatformApi } from '@instantdb/platform';
3
+ declare const PlatformApiError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
4
+ readonly _tag: "PlatformApiError";
5
+ } & Readonly<A>;
6
+ export declare class PlatformApiError extends PlatformApiError_base<{
7
+ message: string;
8
+ cause: unknown;
9
+ }> {
10
+ }
11
+ declare const PlatformApi_base: Effect.Service.Class<PlatformApi, "instant-cli/new/context/platformApi", {
12
+ readonly effect: Effect.Effect<{
13
+ use: <R>(fun: (api: InstantPlatformApi) => Promise<R>, errorMessage?: string) => Effect.Effect<R, PlatformApiError, never>;
14
+ }, import("effect/ConfigError").ConfigError, never>;
15
+ }>;
16
+ export declare class PlatformApi extends PlatformApi_base {
17
+ }
18
+ export {};
19
+ //# sourceMappingURL=platformApi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platformApi.d.ts","sourceRoot":"","sources":["../../../src/new/context/platformApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,MAAM,EAAU,MAAM,QAAQ,CAAC;AAE9C,OAAO,EAAE,WAAW,IAAI,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;;;;AAExE,qBAAa,gBAAiB,SAAQ,sBAAqC;IACzE,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,OAAO,CAAC;CAChB,CAAC;CAAG;;;cAYS,CAAC,OACA,CAAC,GAAG,oBAAkB,KAAK,OAAO,CAAC,CAAC,CAAC,iBAC3B,MAAM;;;AAZ/B,qBAAa,WAAY,SAAQ,gBAyBhC;CAAG"}
@@ -0,0 +1,24 @@
1
+ import { Data, Effect } from 'effect';
2
+ import { getBaseUrl } from '../lib/http.js';
3
+ import { PlatformApi as InstantPlatformApi } from '@instantdb/platform';
4
+ export class PlatformApiError extends Data.TaggedError('PlatformApiError') {
5
+ }
6
+ export class PlatformApi extends Effect.Service()('instant-cli/new/context/platformApi', {
7
+ effect: Effect.gen(function* () {
8
+ const origin = yield* getBaseUrl;
9
+ const apiClient = new InstantPlatformApi({
10
+ apiURI: origin,
11
+ });
12
+ return {
13
+ use: (fun, errorMessage) => Effect.tryPromise({
14
+ try: (_signal) => fun(apiClient),
15
+ catch: (e) => new PlatformApiError({
16
+ message: errorMessage || 'Error using platform api',
17
+ cause: e,
18
+ }),
19
+ }),
20
+ };
21
+ }),
22
+ }) {
23
+ }
24
+ //# sourceMappingURL=platformApi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platformApi.js","sourceRoot":"","sources":["../../../src/new/context/platformApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,WAAW,IAAI,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAExE,MAAM,OAAO,gBAAiB,SAAQ,IAAI,CAAC,WAAW,CAAC,kBAAkB,CAGvE;CAAG;AAEL,MAAM,OAAO,WAAY,SAAQ,MAAM,CAAC,OAAO,EAAe,CAC5D,qCAAqC,EACrC;IACE,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;QAC1B,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,UAAU,CAAC;QACjC,MAAM,SAAS,GAAG,IAAI,kBAAkB,CAAC;YACvC,MAAM,EAAE,MAAM;SACf,CAAC,CAAC;QAEH,OAAO;YACL,GAAG,EAAE,CACH,GAA0C,EAC1C,YAAqB,EACrB,EAAE,CACF,MAAM,CAAC,UAAU,CAAC;gBAChB,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC;gBAChC,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CACX,IAAI,gBAAgB,CAAC;oBACnB,OAAO,EAAE,YAAY,IAAI,0BAA0B;oBACnD,KAAK,EAAE,CAAC;iBACT,CAAC;aACL,CAAC;SACL,CAAC;IACJ,CAAC,CAAC;CACH,CACF;CAAG","sourcesContent":["import { Data, Effect, Schema } from 'effect';\nimport { getBaseUrl } from '../lib/http.js';\nimport { PlatformApi as InstantPlatformApi } from '@instantdb/platform';\n\nexport class PlatformApiError extends Data.TaggedError('PlatformApiError')<{\n message: string;\n cause: unknown;\n}> {}\n\nexport class PlatformApi extends Effect.Service<PlatformApi>()(\n 'instant-cli/new/context/platformApi',\n {\n effect: Effect.gen(function* () {\n const origin = yield* getBaseUrl;\n const apiClient = new InstantPlatformApi({\n apiURI: origin,\n });\n\n return {\n use: <R>(\n fun: (api: typeof apiClient) => Promise<R>,\n errorMessage?: string,\n ) =>\n Effect.tryPromise({\n try: (_signal) => fun(apiClient),\n catch: (e) =>\n new PlatformApiError({\n message: errorMessage || 'Error using platform api',\n cause: e,\n }),\n }),\n };\n }),\n },\n) {}\n"]}