attio 0.0.1-experimental.20250328 → 0.0.1-experimental.20250401

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 (40) hide show
  1. package/lib/api/auth.js +1 -3
  2. package/lib/api/determine-workspace.spinner.js +39 -0
  3. package/lib/api/ensure-authed.js +8 -1
  4. package/lib/api/{get-app-info.js → fetch-app-info.js} +1 -1
  5. package/lib/api/fetch-workspaces.js +11 -0
  6. package/lib/api/get-app-info.spinner.js +18 -0
  7. package/lib/api/get-app-slug-from-package-json.js +26 -0
  8. package/lib/api/get-versions.spinner.js +21 -0
  9. package/lib/commands/build/build-javascript.js +24 -0
  10. package/lib/commands/build/validate-typescript.js +30 -0
  11. package/lib/commands/build.js +32 -16
  12. package/lib/commands/dev/boot.js +4 -4
  13. package/lib/commands/dev/build-javascript.js +2 -2
  14. package/lib/commands/dev/bundle-javascript.js +1 -1
  15. package/lib/commands/dev/prepare-build-contexts.js +3 -3
  16. package/lib/commands/dev/upload.js +2 -3
  17. package/lib/commands/dev.js +9 -6
  18. package/lib/commands/init/ask-language.js +11 -0
  19. package/lib/commands/init/boot.js +14 -0
  20. package/lib/commands/init/create-project.js +50 -0
  21. package/lib/commands/init.js +21 -16
  22. package/lib/commands/login.js +2 -0
  23. package/lib/commands/logout.js +2 -0
  24. package/lib/commands/version/create/boot.js +9 -0
  25. package/lib/commands/version/create.js +71 -15
  26. package/lib/commands/version/list.js +4 -2
  27. package/lib/commands/whoami.js +2 -1
  28. package/lib/util/print-message.js +3 -2
  29. package/lib/util/spinner.js +46 -0
  30. package/package.json +1 -5
  31. package/lib/machines/actions.js +0 -8
  32. package/lib/machines/actors.js +0 -123
  33. package/lib/machines/build-machine.js +0 -192
  34. package/lib/machines/build-orchestrator.js +0 -1
  35. package/lib/machines/code-gen-machine.js +0 -97
  36. package/lib/machines/create-version-machine.js +0 -308
  37. package/lib/machines/env-machine.js +0 -82
  38. package/lib/machines/init-machine.js +0 -192
  39. package/lib/machines/js-machine.js +0 -231
  40. package/lib/machines/ts-machine.js +0 -105
@@ -1,308 +0,0 @@
1
- import { assign, setup, fromPromise } from "xstate";
2
- import chalk from "chalk";
3
- import { completeProdBundleUpload } from "../api/complete-prod-bundle-upload.js";
4
- import { createVersion } from "../api/create-version.js";
5
- import { authenticate, confirm, fetchVersions, loadAppInfo, loadAppSlug } from "./actors.js";
6
- import { jsMachine } from "./js-machine.js";
7
- import { printLogo, showActorError } from "./actions.js";
8
- import Spinner from "tiny-spinner";
9
- import { loadAttioCliPackageJson } from "../util/load-attio-cli-package-json.js";
10
- export const connectionTypes = [
11
- { value: "secret", label: "Secret" },
12
- { value: "oauth2-code", label: "OAuth2" },
13
- ];
14
- export const audiences = [
15
- { value: "workspace", label: "Workspace" },
16
- { value: "workspace-member", label: "Workspace Member" },
17
- ];
18
- const bundlingSpinner = new Spinner();
19
- export const createVersionMachine = setup({
20
- types: {
21
- context: {},
22
- events: {},
23
- children: {},
24
- },
25
- guards: {
26
- "confirmed": (_, params) => params.output,
27
- "is major": (_, params) => params.output === "major",
28
- "no major version": (_, params) => params.versions.length === 0,
29
- },
30
- actors: {
31
- confirm,
32
- fetchVersions,
33
- javascript: jsMachine,
34
- createVersion: fromPromise(async ({ input: { token, appInfo, upgradeType, versions } }) => {
35
- const spinner = new Spinner();
36
- spinner.start("Creating version...");
37
- try {
38
- const packageJson = loadAttioCliPackageJson();
39
- if (typeof packageJson === "string")
40
- throw packageJson;
41
- const major = Math.max(...versions.map((version) => version.major), 1);
42
- const version = await createVersion({
43
- token,
44
- appId: appInfo.app_id,
45
- major: upgradeType === "initial" ? 1 : major,
46
- cliVersion: packageJson.version,
47
- });
48
- spinner.success("Version created");
49
- return version;
50
- }
51
- catch (error) {
52
- spinner.error("Error creating version");
53
- throw error;
54
- }
55
- finally {
56
- spinner.stop();
57
- }
58
- }),
59
- authenticate,
60
- loadAppInfo,
61
- loadAppSlug: loadAppSlug,
62
- upload: fromPromise(async ({ input: { token, jsContents, version: { app_id: appId, client_bundle_upload_url, server_bundle_upload_url, major, minor, app_prod_version_bundle_id: bundleId, }, }, }) => {
63
- const uploadSpinner = new Spinner();
64
- try {
65
- uploadSpinner.start("Uploading...");
66
- const [clientBundle, serverBundle] = jsContents;
67
- await Promise.all([
68
- fetch(client_bundle_upload_url, {
69
- method: "PUT",
70
- body: clientBundle,
71
- headers: {
72
- "Content-Type": "text/javascript",
73
- "Content-Length": String(Buffer.from(clientBundle).length),
74
- },
75
- }),
76
- fetch(server_bundle_upload_url, {
77
- method: "PUT",
78
- body: serverBundle,
79
- headers: {
80
- "Content-Type": "text/javascript",
81
- "Content-Length": String(Buffer.from(serverBundle).length),
82
- },
83
- }),
84
- ]);
85
- uploadSpinner.success("Upload complete");
86
- const signSpinner = new Spinner();
87
- signSpinner.start("Signing bundles...");
88
- await completeProdBundleUpload({
89
- token,
90
- appId,
91
- major,
92
- minor,
93
- bundleId,
94
- });
95
- signSpinner.success("Bundles signed");
96
- process.stdout.write(`\nVersion ${chalk.green(`${major}.${minor}`)} created!\n\n`);
97
- }
98
- catch (error) {
99
- uploadSpinner.error("Upload failed");
100
- throw error;
101
- }
102
- finally {
103
- uploadSpinner.stop();
104
- }
105
- }),
106
- },
107
- actions: {
108
- printLogo,
109
- showActorError,
110
- startBundlingSpinner: () => {
111
- bundlingSpinner.start("Bundling JavaScript...");
112
- },
113
- successBundlingSpinner: () => {
114
- bundlingSpinner.success("Bundling complete");
115
- },
116
- errorBundlingSpinner: () => {
117
- bundlingSpinner.error("Bundling failed");
118
- },
119
- setUpgradeType: assign({
120
- upgradeType: (_, params) => params.output,
121
- }),
122
- setVersions: assign({
123
- versions: (_, params) => params.output,
124
- }),
125
- setJsContents: assign({
126
- jsContents: (_, params) => params.contents,
127
- }),
128
- setVersion: assign({
129
- version: (_, params) => params.output,
130
- }),
131
- setToken: assign({
132
- token: (_, params) => params.output,
133
- }),
134
- setAppSlug: assign({
135
- appSlug: (_, params) => params.output,
136
- }),
137
- setAppInfo: assign({
138
- appInfo: (_, params) => params.output,
139
- }),
140
- },
141
- }).createMachine({
142
- context: {
143
- token: "",
144
- appSlug: "",
145
- upgradeType: "minor",
146
- versions: [],
147
- },
148
- id: "Create Version Machine",
149
- states: {
150
- "Authenticate": {
151
- invoke: {
152
- src: "authenticate",
153
- onDone: {
154
- target: "Loading App Slug",
155
- actions: { type: "setToken", params: ({ event }) => event },
156
- },
157
- onError: {
158
- target: "Error",
159
- actions: { type: "showActorError", params: ({ event }) => event },
160
- },
161
- },
162
- },
163
- "Error": {
164
- type: "final",
165
- },
166
- "Creating version": {
167
- invoke: {
168
- src: "createVersion",
169
- input: ({ context }) => ({
170
- token: context.token,
171
- appSlug: context.appSlug,
172
- upgradeType: context.upgradeType,
173
- appInfo: context.appInfo,
174
- versions: context.versions,
175
- }),
176
- onDone: {
177
- target: "Uploading",
178
- actions: { type: "setVersion", params: ({ event }) => event },
179
- },
180
- onError: {
181
- target: "Error",
182
- actions: { type: "showActorError", params: ({ event }) => event },
183
- },
184
- },
185
- },
186
- "Success": {
187
- type: "final",
188
- },
189
- "JavaScript": {
190
- invoke: {
191
- src: "javascript",
192
- id: "javascript",
193
- input: ({ self }) => ({
194
- parentRef: self,
195
- write: false,
196
- }),
197
- },
198
- on: {
199
- "JavaScript Success": {
200
- target: "Fetching Versions",
201
- actions: [
202
- { type: "setJsContents", params: ({ event }) => event },
203
- "successBundlingSpinner",
204
- ],
205
- reenter: true,
206
- },
207
- "JavaScript Error": ".Build Error",
208
- },
209
- states: {
210
- "Build Error": {
211
- type: "final",
212
- entry: "errorBundlingSpinner",
213
- },
214
- "Building": {},
215
- },
216
- initial: "Building",
217
- entry: "startBundlingSpinner",
218
- },
219
- "Uploading": {
220
- invoke: {
221
- src: "upload",
222
- input: ({ context }) => ({
223
- token: context.token,
224
- version: context.version,
225
- jsContents: context.jsContents,
226
- }),
227
- onDone: "Success",
228
- onError: {
229
- target: "Error",
230
- actions: { type: "showActorError", params: ({ event }) => event },
231
- },
232
- },
233
- },
234
- "Determine if first version": {
235
- always: [
236
- {
237
- target: "Creating version",
238
- guard: { type: "no major version", params: ({ context }) => context },
239
- reenter: true,
240
- actions: {
241
- type: "setUpgradeType",
242
- params: { output: "initial" },
243
- },
244
- description: `We're publishing v1.0`,
245
- },
246
- {
247
- target: "Creating version",
248
- actions: {
249
- type: "setUpgradeType",
250
- params: { output: "minor" },
251
- },
252
- reenter: true,
253
- description: `It's a minor version`,
254
- },
255
- ],
256
- },
257
- "Fetching Versions": {
258
- invoke: {
259
- src: "fetchVersions",
260
- input: ({ context }) => ({
261
- token: context.token,
262
- appInfo: context.appInfo,
263
- }),
264
- onDone: {
265
- target: "Determine if first version",
266
- actions: {
267
- type: "setVersions",
268
- params: ({ event }) => event,
269
- },
270
- },
271
- onError: {
272
- target: "Error",
273
- actions: { type: "showActorError", params: ({ event }) => event },
274
- },
275
- },
276
- },
277
- "Loading App Slug": {
278
- invoke: {
279
- src: "loadAppSlug",
280
- onDone: {
281
- target: "Loading App Info",
282
- actions: { type: "setAppSlug", params: ({ event }) => event },
283
- reenter: true,
284
- },
285
- onError: {
286
- target: "Error",
287
- actions: { type: "showActorError", params: ({ event }) => event },
288
- },
289
- },
290
- },
291
- "Loading App Info": {
292
- invoke: {
293
- src: "loadAppInfo",
294
- input: ({ context }) => context,
295
- onDone: {
296
- target: "JavaScript",
297
- actions: { type: "setAppInfo", params: ({ event }) => event },
298
- },
299
- onError: {
300
- target: "Error",
301
- actions: { type: "showActorError", params: ({ event }) => event },
302
- },
303
- },
304
- },
305
- },
306
- initial: "Authenticate",
307
- entry: "printLogo",
308
- });
@@ -1,82 +0,0 @@
1
- import { sendTo, assign, setup, fromCallback } from "xstate";
2
- import { loadEnv } from "../util/load-env.js";
3
- import { updateEnvTypes } from "../util/update-env-types.js";
4
- export const envMachine = setup({
5
- types: {
6
- context: {},
7
- events: {},
8
- input: {},
9
- },
10
- guards: {
11
- "variables have changed": (_, params) => JSON.stringify(params.previousVariables) !== JSON.stringify(params.newVariables),
12
- },
13
- actors: {
14
- loadEnvironmentVariables: fromCallback(({ sendBack }) => {
15
- loadEnv()
16
- .then((variables) => sendBack({ type: "Environment Variables Loaded", variables }))
17
- .catch(() => sendBack({ type: "Error" }));
18
- }),
19
- updateTypes: fromCallback(({ sendBack, input: { variables } }) => {
20
- updateEnvTypes(variables)
21
- .then(() => sendBack({ type: "Types Updated" }))
22
- .catch(() => sendBack({ type: "Error" }));
23
- }),
24
- },
25
- actions: {
26
- setVariables: assign({
27
- variables: (_, params) => params.variables,
28
- }),
29
- raiseDone: sendTo(({ context }) => context.parentRef, { type: "Done" }),
30
- },
31
- }).createMachine({
32
- id: "Environment Variable Machine",
33
- context: ({ input }) => ({
34
- variables: null,
35
- parentRef: input.parentRef,
36
- }),
37
- states: {
38
- "Load Environment Variables": {
39
- on: {
40
- "Environment Variables Loaded": [
41
- {
42
- target: "Updating Types",
43
- guard: {
44
- type: "variables have changed",
45
- params: ({ context, event }) => ({
46
- previousVariables: context.variables,
47
- newVariables: event.variables,
48
- }),
49
- },
50
- actions: { type: "setVariables", params: ({ event }) => event },
51
- },
52
- {
53
- target: "Done",
54
- reenter: true,
55
- },
56
- ],
57
- "Error": "Errored",
58
- },
59
- invoke: {
60
- src: "loadEnvironmentVariables",
61
- },
62
- },
63
- "Updating Types": {
64
- on: {
65
- "Types Updated": "Done",
66
- },
67
- invoke: {
68
- src: "updateTypes",
69
- input: ({ context }) => ({ variables: context.variables ?? {} }),
70
- },
71
- },
72
- "Done": {
73
- entry: "raiseDone",
74
- },
75
- "Errored": {},
76
- },
77
- initial: "Load Environment Variables",
78
- on: {
79
- Change: ".Load Environment Variables",
80
- },
81
- description: `Looks for a .env file and updates types in "node_modules/attio/server" to match.`,
82
- });
@@ -1,192 +0,0 @@
1
- import { existsSync } from "fs";
2
- import Spinner from "tiny-spinner";
3
- import path, { join } from "path";
4
- import { fileURLToPath } from "url";
5
- import { assign, setup, fromPromise } from "xstate";
6
- import { copyWithTransform } from "../util/copy-with-replace.js";
7
- import { createDirectory } from "../util/create-directory.js";
8
- import { canWrite } from "../util/validate-slug.js";
9
- import { ask, askWithChoices, authenticate, loadAppInfo } from "./actors.js";
10
- import { printLogo, showActorError } from "./actions.js";
11
- import chalk from "chalk";
12
- import boxen from "boxen";
13
- export const languages = [
14
- { name: "TypeScript (recommended)", value: "typescript" },
15
- { name: "JavaScript", value: "javascript" },
16
- ];
17
- export const initMachine = setup({
18
- types: {
19
- context: {},
20
- input: {},
21
- },
22
- actors: {
23
- ask,
24
- askWithChoices,
25
- createProject: fromPromise(async ({ input }) => {
26
- const { appSlug, appInfo, language } = input;
27
- const spinner = new Spinner();
28
- try {
29
- if (existsSync(join(process.cwd(), appSlug))) {
30
- throw new Error(`Directory "${appSlug}" already exists`);
31
- }
32
- if (!canWrite(process.cwd())) {
33
- throw new Error("Write access denied to current directory");
34
- }
35
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
36
- const projectDir = createDirectory(appSlug);
37
- const templatesDir = path.resolve(__dirname, "../templates", language);
38
- const commonDir = path.resolve(__dirname, "../templates", "common");
39
- const transform = (contents) => contents
40
- .replaceAll("title-to-be-replaced", appInfo.title)
41
- .replaceAll("id-to-be-replaced", appInfo.app_id)
42
- .replaceAll("slug-to-be-replaced", appSlug);
43
- spinner.start("Creating project...");
44
- await Promise.all([
45
- copyWithTransform(templatesDir, projectDir, transform),
46
- copyWithTransform(commonDir, projectDir, transform),
47
- ]);
48
- spinner.success("Project created");
49
- }
50
- catch (error) {
51
- spinner.error("Error creating project");
52
- throw error;
53
- }
54
- finally {
55
- spinner.stop();
56
- }
57
- }),
58
- authenticate,
59
- loadAppInfo,
60
- },
61
- actions: {
62
- printLogo,
63
- showActorError,
64
- showInstructions: (_, params) => {
65
- process.stdout.write("\n" + chalk.green(`SUCCESS!! 🎉 Your app directory has been created.`) + "\n");
66
- process.stdout.write("\nTo get started, run:\n");
67
- process.stdout.write(boxen(`cd ${params.appSlug}\nnpm install\nnpm run dev`, {
68
- padding: 1,
69
- margin: 1,
70
- borderStyle: "round",
71
- }) + "\n");
72
- process.stdout.write(`(${chalk.yellow("yarn")}, ${chalk.yellow("pnpm")}, and ${chalk.yellow("bun")} also work!)\n`);
73
- },
74
- setLanguage: assign({
75
- language: (_, params) => params.output,
76
- }),
77
- setAppInfo: assign({
78
- appInfo: (_, params) => params.output,
79
- }),
80
- setToken: assign({
81
- token: (_, params) => params.output,
82
- }),
83
- },
84
- guards: {
85
- "app exists": (_, params) => Boolean(params.output),
86
- "have language": (_, params) => Boolean(params.language),
87
- },
88
- }).createMachine({
89
- context: ({ input }) => ({
90
- appId: "",
91
- token: "",
92
- ...input,
93
- }),
94
- id: "Init Machine",
95
- states: {
96
- "Ask for language": {
97
- invoke: {
98
- src: "askWithChoices",
99
- input: {
100
- message: "What language would you like to use?",
101
- choices: languages,
102
- },
103
- onDone: {
104
- target: "Creating Project",
105
- actions: {
106
- type: "setLanguage",
107
- params: ({ event }) => event,
108
- },
109
- reenter: true,
110
- },
111
- },
112
- },
113
- "Creating Project": {
114
- invoke: {
115
- src: "createProject",
116
- input: ({ context }) => ({
117
- language: context.language,
118
- appInfo: context.appInfo,
119
- appSlug: context.appSlug,
120
- }),
121
- onDone: "Success",
122
- onError: {
123
- target: "Error",
124
- actions: { type: "showActorError", params: ({ event }) => event },
125
- },
126
- },
127
- },
128
- "Error": {
129
- type: "final",
130
- },
131
- "Success": {
132
- type: "final",
133
- entry: {
134
- type: "showInstructions",
135
- params: ({ context }) => ({
136
- appSlug: context.appSlug,
137
- title: context.appInfo.title,
138
- }),
139
- },
140
- },
141
- "Do we need language?": {
142
- always: [
143
- {
144
- target: "Creating Project",
145
- guard: { type: "have language", params: ({ context }) => context },
146
- reenter: true,
147
- description: `language may have been provided by CLI option`,
148
- },
149
- "Ask for language",
150
- ],
151
- },
152
- "Loading App Info": {
153
- invoke: [
154
- {
155
- src: "loadAppInfo",
156
- input: ({ context }) => context,
157
- onDone: {
158
- target: "Do we need language?",
159
- guard: { type: "app exists", params: ({ event }) => event },
160
- actions: {
161
- type: "setAppInfo",
162
- params: ({ event }) => event,
163
- },
164
- },
165
- onError: {
166
- target: "Error",
167
- actions: {
168
- type: "showActorError",
169
- params: ({ event }) => event,
170
- },
171
- },
172
- },
173
- ],
174
- },
175
- "Authenticate": {
176
- invoke: {
177
- src: "authenticate",
178
- onError: {
179
- target: "Error",
180
- reenter: true,
181
- actions: { type: "showActorError", params: ({ event }) => event },
182
- },
183
- onDone: {
184
- target: "Loading App Info",
185
- actions: { type: "setToken", params: ({ event }) => event },
186
- },
187
- },
188
- },
189
- },
190
- initial: "Authenticate",
191
- entry: "printLogo",
192
- });