attio 0.0.1-experimental.20250403 → 0.0.1-experimental.20250407

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 (55) hide show
  1. package/lib/api/api.js +98 -0
  2. package/lib/api/fetcher.js +65 -0
  3. package/lib/api/schemas.js +76 -0
  4. package/lib/{api → auth}/auth.js +5 -3
  5. package/lib/{api → auth}/keychain.js +1 -1
  6. package/lib/build/client/generate-client-entry.js +14 -4
  7. package/lib/build/server/generate-server-entry.js +24 -15
  8. package/lib/commands/build/build-javascript.js +13 -17
  9. package/lib/commands/build/validate-typescript.js +7 -14
  10. package/lib/commands/build.js +29 -12
  11. package/lib/commands/dev/boot.js +38 -11
  12. package/lib/commands/dev/bundle-javascript.js +29 -28
  13. package/lib/commands/dev/graphql-code-gen.js +1 -1
  14. package/lib/commands/dev/onboarding.js +19 -5
  15. package/lib/commands/dev/prepare-build-contexts.js +163 -32
  16. package/lib/{api → commands/dev}/start-graphql-server.js +2 -2
  17. package/lib/commands/dev/upload.js +34 -6
  18. package/lib/commands/dev/validate-typescript.js +3 -13
  19. package/lib/commands/dev.js +49 -3
  20. package/lib/commands/init/create-project.js +45 -18
  21. package/lib/commands/init.js +28 -4
  22. package/lib/commands/login.js +1 -1
  23. package/lib/commands/logout.js +1 -1
  24. package/lib/commands/version/create/bundle-javascript.js +28 -0
  25. package/lib/commands/version/create.js +84 -34
  26. package/lib/commands/version/list.js +23 -6
  27. package/lib/commands/whoami.js +12 -4
  28. package/lib/spinners/determine-workspace.spinner.js +58 -0
  29. package/lib/{api → spinners}/get-app-info.spinner.js +2 -2
  30. package/lib/spinners/get-app-slug-from-package-json.js +46 -0
  31. package/lib/{api → spinners}/get-versions.spinner.js +2 -4
  32. package/lib/util/copy-with-replace.js +40 -18
  33. package/lib/util/create-directory.js +21 -14
  34. package/lib/util/find-available-port.js +1 -1
  35. package/lib/util/load-attio-cli-version.js +86 -0
  36. package/lib/util/spinner.js +4 -1
  37. package/lib/util/upload-bundle.js +3 -2
  38. package/package.json +2 -1
  39. package/lib/api/api-fetch.js +0 -32
  40. package/lib/api/complete-bundle-upload.js +0 -8
  41. package/lib/api/complete-prod-bundle-upload.js +0 -8
  42. package/lib/api/create-dev-version.js +0 -17
  43. package/lib/api/create-version.js +0 -19
  44. package/lib/api/determine-workspace.spinner.js +0 -32
  45. package/lib/api/fetch-app-info.js +0 -20
  46. package/lib/api/fetch-installation.js +0 -9
  47. package/lib/api/fetch-versions.js +0 -17
  48. package/lib/api/fetch-workspaces.js +0 -25
  49. package/lib/api/get-app-slug-from-package-json.js +0 -27
  50. package/lib/api/start-upload.js +0 -11
  51. package/lib/api/whoami.js +0 -15
  52. package/lib/commands/dev/build-javascript.js +0 -47
  53. package/lib/util/load-attio-cli-package-json.js +0 -27
  54. /package/lib/{api → auth}/ensure-authed.js +0 -0
  55. /package/lib/{api → util}/hard-exit.js +0 -0
@@ -1,17 +0,0 @@
1
- import { z } from "zod";
2
- import { apiFetch } from "./api-fetch.js";
3
- const createDevVersionSchema = z.object({
4
- app_id: z.string(),
5
- app_dev_version_id: z.string(),
6
- });
7
- export async function createDevVersion({ appId, cliVersion, targetWorkspaceId, environmentVariables, }) {
8
- return await apiFetch("creating dev version", `apps/${appId}/dev-versions`, {
9
- method: "POST",
10
- body: JSON.stringify({
11
- major: 1,
12
- target_workspace_id: targetWorkspaceId,
13
- environment_variables: environmentVariables,
14
- cli_version: cliVersion,
15
- }),
16
- }, createDevVersionSchema);
17
- }
@@ -1,19 +0,0 @@
1
- import { z } from "zod";
2
- import { apiFetch } from "./api-fetch.js";
3
- const createVersionSchema = z.object({
4
- app_id: z.string(),
5
- major: z.number(),
6
- minor: z.number(),
7
- app_prod_version_bundle_id: z.string(),
8
- client_bundle_upload_url: z.string(),
9
- server_bundle_upload_url: z.string(),
10
- });
11
- export async function createVersion({ appId, major, cliVersion, }) {
12
- return await apiFetch("creating version", `apps/${appId}/prod-versions`, {
13
- method: "POST",
14
- body: JSON.stringify({
15
- major,
16
- cli_version: cliVersion,
17
- }),
18
- }, createVersionSchema);
19
- }
@@ -1,32 +0,0 @@
1
- import { select } from "@inquirer/prompts";
2
- import { fetchWorkspaces } from "./fetch-workspaces.js";
3
- import { APP } from "../env.js";
4
- import { spinnerify } from "../util/spinner.js";
5
- import { hardExit } from "./hard-exit.js";
6
- export async function determineWorkspace(workspaceSlug) {
7
- const workspaces = await spinnerify("Loading workspaces...", "Workspaces loaded", fetchWorkspaces);
8
- const workspace = workspaces.find((workspace) => workspace.slug === workspaceSlug);
9
- if (workspace) {
10
- process.stdout.write(`Using workspace: ${workspace.name}`);
11
- return workspace;
12
- }
13
- if (workspaces.length === 0) {
14
- hardExit(`You are not the admin of any workspaces. Either request permission from an existing workspace or create your own.
15
-
16
- ${APP}/welcome/workspace-details
17
- `);
18
- }
19
- if (workspaces.length === 1) {
20
- process.stdout.write(`Using workspace: ${workspaces[0].name}`);
21
- return workspaces[0];
22
- }
23
- const choice = await select({
24
- message: "Choose a workspace",
25
- choices: workspaces.map((workspace) => ({
26
- name: workspace.name,
27
- value: workspace,
28
- })),
29
- });
30
- process.stdout.write(`Using workspace: ${choice.name}`);
31
- return choice;
32
- }
@@ -1,20 +0,0 @@
1
- import { z } from "zod";
2
- import { apiFetch } from "./api-fetch.js";
3
- const appInfoSchema = z.object({
4
- app: z.object({
5
- app_id: z.string().uuid(),
6
- title: z.string(),
7
- }),
8
- });
9
- const TEST_APP_INFO = appInfoSchema.parse({
10
- app: {
11
- app_id: "0cbafb09-2ef7-473c-a048-08a5d190a395",
12
- title: "Test App",
13
- },
14
- });
15
- export async function fetchAppInfo(appSlug) {
16
- if (process.env.NODE_ENV === "test") {
17
- return TEST_APP_INFO.app;
18
- }
19
- return (await apiFetch("fetching app info", `apps/by-slug/${appSlug}`, { method: "GET" }, appInfoSchema)).app;
20
- }
@@ -1,9 +0,0 @@
1
- import { z } from "zod";
2
- import { apiFetch } from "./api-fetch.js";
3
- const installationSchema = z.object({
4
- app_id: z.string(),
5
- workspace_id: z.string(),
6
- });
7
- export async function fetchInstallation({ appId, workspaceId, }) {
8
- return await apiFetch("fetching installation", `apps/${appId}/workspace/${workspaceId}/dev-installation`, { method: "GET" }, installationSchema, "null-on-404");
9
- }
@@ -1,17 +0,0 @@
1
- import { z } from "zod";
2
- import { apiFetch } from "./api-fetch.js";
3
- const versionSchema = z.object({
4
- major: z.number(),
5
- minor: z.number(),
6
- created_at: z.string(),
7
- released_at: z.string().nullable().optional(),
8
- is_published: z.boolean(),
9
- num_installations: z.number(),
10
- publication_status: z.enum(["private", "in_review", "published", "rejected"]),
11
- });
12
- const versionsSchema = z.object({
13
- app_prod_versions: z.array(versionSchema),
14
- });
15
- export async function fetchVersions(appId) {
16
- return (await apiFetch("fetching versions", `apps/${appId}/prod-versions`, { method: "GET" }, versionsSchema)).app_prod_versions;
17
- }
@@ -1,25 +0,0 @@
1
- import { z } from "zod";
2
- import { apiFetch } from "./api-fetch.js";
3
- const isTest = process.env.NODE_ENV === "test";
4
- const workspaceResponseSchema = z.object({
5
- workspace_id: z.string().uuid(),
6
- slug: z.string(),
7
- name: z.string(),
8
- logo_url: z.string().nullable(),
9
- });
10
- const TEST_WORKSPACE = workspaceResponseSchema.parse({
11
- workspace_id: "a85e3bcf-a9a2-4df9-9e92-e708bf98d238",
12
- slug: "test-slug",
13
- name: "Test Workspace",
14
- logo_url: null,
15
- });
16
- const listDevWorkspacesResponseSchema = z.object({
17
- workspaces: z.array(workspaceResponseSchema),
18
- accurate_at: z.string().datetime(),
19
- });
20
- export async function fetchWorkspaces() {
21
- if (isTest) {
22
- return [TEST_WORKSPACE];
23
- }
24
- return (await apiFetch("fetching workspaces", "dev-workspaces", { method: "GET" }, listDevWorkspacesResponseSchema)).workspaces;
25
- }
@@ -1,27 +0,0 @@
1
- import { readFileSync } from "fs";
2
- import { join } from "path";
3
- import { z } from "zod";
4
- import { hardExit } from "./hard-exit.js";
5
- const packageJsonSchema = z.object({
6
- name: z.string({
7
- required_error: "No name field found in package.json",
8
- invalid_type_error: "name must be a string in package.json",
9
- }),
10
- });
11
- export async function getAppSlugFromPackageJson() {
12
- try {
13
- const packageJsonPath = join(process.cwd(), "package.json");
14
- const packageJsonRaw = JSON.parse(readFileSync(packageJsonPath, "utf8"));
15
- const result = packageJsonSchema.safeParse(packageJsonRaw);
16
- if (!result.success) {
17
- return hardExit(result.error.issues[0]?.message || "Malformed package.json");
18
- }
19
- return result.data.name;
20
- }
21
- catch (error) {
22
- if (error instanceof SyntaxError) {
23
- return hardExit("Invalid JSON in package.json");
24
- }
25
- return hardExit("Failed to read package.json");
26
- }
27
- }
@@ -1,11 +0,0 @@
1
- import { z } from "zod";
2
- import { apiFetch } from "./api-fetch.js";
3
- const startUploadSchema = z.object({
4
- app_dev_version_id: z.string().uuid(),
5
- app_dev_version_bundle_id: z.string().uuid(),
6
- client_bundle_upload_url: z.string().url(),
7
- server_bundle_upload_url: z.string().url(),
8
- });
9
- export async function startUpload({ appId, devVersionId, }) {
10
- return await apiFetch("starting upload", `apps/${appId}/dev-versions/${devVersionId}/bundles`, { method: "POST" }, startUploadSchema);
11
- }
package/lib/api/whoami.js DELETED
@@ -1,15 +0,0 @@
1
- import { z } from "zod";
2
- import { apiFetch } from "./api-fetch.js";
3
- import { APP } from "../env.js";
4
- const whoamiSchema = z.object({
5
- user: z.object({
6
- id: z.string(),
7
- email_address: z.string(),
8
- name: z.object({
9
- full: z.string(),
10
- }),
11
- }),
12
- });
13
- export async function whoami() {
14
- return (await apiFetch("fetching current user", `${APP}/api/auth/whoami`, { method: "GET" }, whoamiSchema)).user;
15
- }
@@ -1,47 +0,0 @@
1
- import chokidar from "chokidar";
2
- import notifier from "node-notifier";
3
- import { errorsAndWarningsSchema } from "../../build.js";
4
- import { prepareBuildContexts } from "./prepare-build-contexts.js";
5
- import { printJsError } from "../../util/typescript.js";
6
- const notify = (errors) => {
7
- const totalErrors = (errors.errors?.length || 0) + (errors.warnings?.length || 0);
8
- notifier.notify({
9
- title: `JavaScript ${totalErrors === 1 ? "Error" : "Errors"}`,
10
- message: `There ${totalErrors === 1 ? "was one error" : `were ${totalErrors} errors`} in your JavaScript code`,
11
- });
12
- };
13
- export function buildJavaScript(onSuccess) {
14
- const watcher = chokidar.watch(["src/**/*.{js,jsx,ts,tsx}"], {
15
- ignored: ["**/node_modules/**", "**/dist/**", "**/*.graphql.d.ts", "**/*.gql.d.ts"],
16
- cwd: ".",
17
- });
18
- let buildContexts;
19
- async function handleBuild() {
20
- try {
21
- if (!buildContexts) {
22
- buildContexts = await prepareBuildContexts("in-memory");
23
- }
24
- const results = await Promise.all(buildContexts.map(async (context) => context.rebuild()));
25
- const bundles = results.map((result) => result.outputFiles[0].text);
26
- onSuccess?.(bundles);
27
- }
28
- catch (error) {
29
- const errors = errorsAndWarningsSchema.parse(error);
30
- errors.errors?.forEach((error) => printJsError(error, "error"));
31
- errors.warnings?.forEach((warning) => printJsError(warning, "warning"));
32
- notify(errors);
33
- }
34
- }
35
- watcher.on("ready", () => {
36
- handleBuild();
37
- watcher.on("all", (event) => {
38
- if (event === "add" || event === "change" || event === "unlink") {
39
- handleBuild();
40
- }
41
- });
42
- });
43
- return async () => {
44
- await Promise.all(buildContexts?.map(async (context) => context.dispose()) ?? []);
45
- await watcher.close();
46
- };
47
- }
@@ -1,27 +0,0 @@
1
- import { readFileSync } from "fs";
2
- import { findUpSync } from "find-up-simple";
3
- import { z } from "zod";
4
- import { fileURLToPath } from "url";
5
- import { hardExit } from "../api/hard-exit.js";
6
- const FILE_NAME = "package.json";
7
- const packageJsonSchema = z.object({
8
- version: z.string(),
9
- name: z.literal("attio"),
10
- });
11
- let packageJson;
12
- export function loadAttioCliPackageJson() {
13
- if (packageJson === undefined) {
14
- const packageJsonPath = findUpSync(FILE_NAME, { cwd: fileURLToPath(import.meta.url) });
15
- if (packageJsonPath === undefined) {
16
- hardExit("Failed to find package.json");
17
- }
18
- try {
19
- const packageJsonContent = JSON.parse(readFileSync(packageJsonPath, "utf8"));
20
- packageJson = packageJsonSchema.parse(packageJsonContent);
21
- }
22
- catch (error) {
23
- hardExit("Failed to find version in package.json");
24
- }
25
- }
26
- return packageJson;
27
- }
File without changes
File without changes