attio 0.0.1-experimental.20250311 → 0.0.1-experimental.20250324

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 (51) hide show
  1. package/lib/api/add-connection-definition.js +2 -2
  2. package/lib/api/auth.js +114 -0
  3. package/lib/api/complete-bundle-upload.js +2 -2
  4. package/lib/api/complete-prod-bundle-upload.js +2 -2
  5. package/lib/api/create-dev-version.js +2 -2
  6. package/lib/api/create-version.js +2 -2
  7. package/lib/api/ensure-authed.js +24 -0
  8. package/lib/api/fetch-connections.js +2 -2
  9. package/lib/api/fetch-installation.js +2 -2
  10. package/lib/api/fetch-versions.js +2 -2
  11. package/lib/api/keychain.js +30 -0
  12. package/lib/api/load-app-id.js +9 -0
  13. package/lib/api/load-dev-slug.js +9 -0
  14. package/lib/api/make-headers.js +1 -1
  15. package/lib/api/remove-connection-definition.js +2 -2
  16. package/lib/api/start-upload.js +2 -2
  17. package/lib/api/whoami.js +21 -0
  18. package/lib/attio.js +6 -2
  19. package/lib/commands/login.js +11 -0
  20. package/lib/commands/logout.js +11 -0
  21. package/lib/commands/version/index.js +1 -3
  22. package/lib/commands/version/list.js +31 -17
  23. package/lib/commands/whoami.js +19 -0
  24. package/lib/graphql/graphql-error.js +3 -0
  25. package/lib/machines/actors.js +3 -1
  26. package/lib/machines/dev-machine.js +5 -2
  27. package/lib/machines/init-machine.js +14 -7
  28. package/lib/templates/javascript/src/cat-fact.jsx +16 -0
  29. package/lib/templates/javascript/src/get-cat-fact.server.js +6 -0
  30. package/lib/templates/javascript/src/hello-world-dialog.jsx +6 -5
  31. package/lib/templates/typescript/src/cat-fact.tsx +16 -0
  32. package/lib/templates/typescript/src/get-cat-fact.server.ts +6 -0
  33. package/lib/templates/typescript/src/hello-world-dialog.tsx +5 -4
  34. package/lib/tsconfig.tsbuildinfo +1 -1
  35. package/lib/util/load-developer-config.js +1 -0
  36. package/package.json +2 -1
  37. package/lib/api/publish-version.js +0 -15
  38. package/lib/commands/connection/add.js +0 -67
  39. package/lib/commands/connection/index.js +0 -9
  40. package/lib/commands/connection/list.js +0 -20
  41. package/lib/commands/connection/remove.js +0 -20
  42. package/lib/commands/version/publish.js +0 -48
  43. package/lib/machines/add-connection-machine.js +0 -559
  44. package/lib/machines/list-connections-machine.js +0 -174
  45. package/lib/machines/list-versions-machine.js +0 -151
  46. package/lib/machines/publish-version-machine.js +0 -230
  47. package/lib/machines/remove-connection-machine.js +0 -253
  48. package/lib/templates/javascript/src/advice.jsx +0 -16
  49. package/lib/templates/javascript/src/get-advice.server.js +0 -6
  50. package/lib/templates/typescript/src/advice.tsx +0 -16
  51. package/lib/templates/typescript/src/get-advice.server.ts +0 -6
@@ -1,174 +0,0 @@
1
- import { assign, setup, fromCallback } from "xstate";
2
- import { fetchConnections } from "../api/fetch-connections.js";
3
- import { emptyConfig } from "../schema.js";
4
- import { loadAppConfig, loadDeveloperConfig } from "./actors.js";
5
- import Table from "cli-table3";
6
- import { showError, printLogo } from "./actions.js";
7
- import { printInstallInstructions } from "../util/print-install-instructions.js";
8
- import boxen from "boxen";
9
- import chalk from "chalk";
10
- import Spinner from "tiny-spinner";
11
- export const listConnectionsMachine = setup({
12
- types: {
13
- context: {},
14
- events: {},
15
- },
16
- actors: {
17
- loadDeveloperConfig,
18
- loadAppConfig,
19
- loadConnections: fromCallback(({ sendBack, input }) => {
20
- const spinner = new Spinner();
21
- spinner.start("Loading connections...");
22
- fetchConnections({
23
- token: input.developer.token,
24
- devSlug: input.developer.slug,
25
- appId: input.config.id,
26
- major: input.config.major,
27
- })
28
- .then((connections) => {
29
- spinner.success("Connections loaded");
30
- sendBack({ type: "Connections Loaded", connections });
31
- })
32
- .catch((error) => {
33
- spinner.error("Error loading connections");
34
- sendBack({ type: "Error", error: error.message });
35
- });
36
- }),
37
- },
38
- actions: {
39
- printLogo,
40
- showError,
41
- showConfigInstructions: ({ context }) => printInstallInstructions(context.configError),
42
- showNoConnections: () => {
43
- process.stdout.write(chalk.red("This app has no connections.\n\n"));
44
- process.stdout.write("To add one, use:\n");
45
- process.stdout.write(boxen("attio connection add", {
46
- padding: 1,
47
- margin: 1,
48
- borderStyle: "round",
49
- }) + "\n");
50
- },
51
- showConnections: ({ context: { connections } }) => {
52
- const maxWidth = process.stdout.columns - 10;
53
- const table = new Table({
54
- head: ["Name", "Level", "Type"].map((h) => chalk.bold(h)),
55
- style: {
56
- head: [],
57
- border: [],
58
- },
59
- colWidths: [
60
- Math.floor(maxWidth * 0.5),
61
- Math.floor(maxWidth * 0.2),
62
- Math.floor(maxWidth * 0.3),
63
- ],
64
- colAligns: ["left", "center", "center"],
65
- wordWrap: true,
66
- wrapOnWordBoundary: true,
67
- });
68
- table.push(...connections.map((connection) => [
69
- connection.label,
70
- connection.global ? "Workspace" : "User",
71
- connection.connection_type === "secret" ? "Secret" : "OAuth2 Code",
72
- ]));
73
- process.stdout.write(table.toString());
74
- },
75
- setError: assign({
76
- error: (_, params) => params.error,
77
- }),
78
- setDeveloperConfig: assign({
79
- developer: (_, params) => params,
80
- }),
81
- setConfigError: assign({
82
- configError: (_, params) => params.configError,
83
- }),
84
- setConfig: assign({
85
- config: (_, params) => params.config,
86
- }),
87
- setConnections: assign({
88
- connections: (_, params) => params.connections,
89
- }),
90
- },
91
- guards: {
92
- "have connections": (_, params) => Boolean(params.connections && params.connections.length > 0),
93
- },
94
- }).createMachine({
95
- context: ({ input }) => ({
96
- developer: { slug: "", token: "" },
97
- config: emptyConfig,
98
- ...input,
99
- }),
100
- id: "List Connections Machine",
101
- states: {
102
- "Loading Developer Config": {
103
- invoke: {
104
- src: "loadDeveloperConfig",
105
- },
106
- on: {
107
- "Developer Config Loaded": {
108
- target: "Loading App Config",
109
- actions: { type: "setDeveloperConfig", params: ({ event }) => event },
110
- },
111
- "No Developer Config": {
112
- target: "Show config instructions",
113
- actions: { type: "setConfigError", params: ({ event }) => event },
114
- },
115
- },
116
- },
117
- "Show config instructions": {
118
- type: "final",
119
- entry: "showConfigInstructions",
120
- },
121
- "Loading App Config": {
122
- invoke: {
123
- src: "loadAppConfig",
124
- },
125
- on: {
126
- "Error": {
127
- target: "Error",
128
- actions: { type: "setError", params: ({ event }) => event },
129
- },
130
- "App Config Loaded": {
131
- target: "Loading Connections",
132
- actions: { type: "setConfig", params: ({ event }) => event },
133
- },
134
- },
135
- },
136
- "Error": {
137
- type: "final",
138
- entry: { type: "showError", params: ({ context }) => ({ error: context.error }) },
139
- },
140
- "Loading Connections": {
141
- invoke: {
142
- src: "loadConnections",
143
- input: ({ context }) => context,
144
- },
145
- on: {
146
- "Connections Loaded": [
147
- {
148
- target: "Display Connections",
149
- actions: { type: "setConnections", params: ({ event }) => event },
150
- guard: {
151
- type: "have connections",
152
- params: ({ event }) => event,
153
- },
154
- },
155
- "No Connections",
156
- ],
157
- "Error": {
158
- target: "Error",
159
- actions: { type: "setError", params: ({ event }) => event },
160
- },
161
- },
162
- },
163
- "No Connections": {
164
- type: "final",
165
- entry: "showNoConnections",
166
- },
167
- "Display Connections": {
168
- type: "final",
169
- entry: "showConnections",
170
- },
171
- },
172
- initial: "Loading Developer Config",
173
- entry: "printLogo",
174
- });
@@ -1,151 +0,0 @@
1
- import { assign, setup } from "xstate";
2
- import { emptyConfig } from "../schema.js";
3
- import { loadAppConfig, loadDeveloperConfig, fetchVersions } from "./actors.js";
4
- import formatDate from "date-fns/format/index.js";
5
- import { showError, printLogo } from "./actions.js";
6
- import { printInstallInstructions } from "../util/print-install-instructions.js";
7
- import Table from "cli-table3";
8
- import chalk from "chalk";
9
- import boxen from "boxen";
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
- export const listVersionsMachine = setup({
19
- types: {
20
- context: {},
21
- events: {},
22
- },
23
- actors: {
24
- fetchVersions,
25
- loadDeveloperConfig,
26
- loadAppConfig,
27
- },
28
- actions: {
29
- printLogo,
30
- showError,
31
- showConfigInstructions: ({ context }) => printInstallInstructions(context.configError),
32
- showVersions: ({ context }) => {
33
- if (context.versions.length === 0) {
34
- process.stdout.write(chalk.red("\nNo versions found.\n\n"));
35
- process.stdout.write("You can create a new version by running:\n");
36
- process.stdout.write(boxen("attio version create", {
37
- padding: 1,
38
- margin: 1,
39
- borderStyle: "round",
40
- }));
41
- return;
42
- }
43
- const table = new Table({
44
- head: ["Version", "Published", "Installations", "Created"].map((h) => chalk.bold(h)),
45
- style: {
46
- head: [],
47
- border: [],
48
- },
49
- colAligns: ["center", "center", "right", "left"],
50
- });
51
- table.push(...context.versions.map((version) => [
52
- `${version.major}.${version.minor}`,
53
- version.is_published ? "Yes" : "No",
54
- version.num_installations.toLocaleString(),
55
- formatDate(new Date(version.created_at), "MMMM d, yyyy, HH:mm"),
56
- ]));
57
- process.stdout.write(table.toString());
58
- },
59
- clearError: assign({
60
- error: () => undefined,
61
- }),
62
- setError: assign({
63
- error: (_, params) => params.error,
64
- }),
65
- setDeveloperConfig: assign({
66
- developer: (_, params) => params,
67
- }),
68
- setConfigError: assign({
69
- configError: (_, params) => params.configError,
70
- }),
71
- setConfig: assign({
72
- config: (_, params) => params.config,
73
- }),
74
- setVersions: assign({
75
- versions: (_, params) => params.versions,
76
- }),
77
- },
78
- }).createMachine({
79
- context: {
80
- developer: { slug: "", token: "" },
81
- config: emptyConfig,
82
- versions: [],
83
- },
84
- id: "List Versions Machine",
85
- states: {
86
- "Loading Developer Config": {
87
- invoke: {
88
- src: "loadDeveloperConfig",
89
- },
90
- on: {
91
- "Developer Config Loaded": {
92
- target: "Loading App Config",
93
- actions: { type: "setDeveloperConfig", params: ({ event }) => event },
94
- },
95
- "No Developer Config": {
96
- target: "Show config instructions",
97
- actions: { type: "setConfigError", params: ({ event }) => event },
98
- },
99
- },
100
- },
101
- "Show config instructions": {
102
- type: "final",
103
- entry: "showConfigInstructions",
104
- },
105
- "Loading App Config": {
106
- invoke: {
107
- src: "loadAppConfig",
108
- },
109
- on: {
110
- "Error": {
111
- target: "Error",
112
- actions: { type: "setError", params: ({ event }) => event },
113
- },
114
- "App Config Loaded": {
115
- target: "Fetching Versions",
116
- actions: { type: "setConfig", params: ({ event }) => event },
117
- reenter: true,
118
- },
119
- },
120
- },
121
- "Error": {
122
- type: "final",
123
- entry: { type: "showError", params: ({ context }) => ({ error: context.error }) },
124
- },
125
- "Fetching Versions": {
126
- on: {
127
- "Versions Fetched": {
128
- target: "Display Versions",
129
- actions: { type: "setVersions", params: ({ event }) => event },
130
- },
131
- "Error": {
132
- target: "Error",
133
- actions: { type: "setError", params: ({ event }) => event },
134
- },
135
- },
136
- invoke: {
137
- src: "fetchVersions",
138
- input: ({ context }) => ({
139
- developer: context.developer,
140
- config: context.config,
141
- }),
142
- },
143
- },
144
- "Display Versions": {
145
- type: "final",
146
- entry: "showVersions",
147
- },
148
- },
149
- initial: "Loading Developer Config",
150
- entry: "printLogo",
151
- });
@@ -1,230 +0,0 @@
1
- import { assign, setup, fromCallback } from "xstate";
2
- import { fetchPublishableVersions } from "../api/fetch-versions.js";
3
- import { publishVersion } from "../api/publish-version.js";
4
- import { emptyConfig } from "../schema.js";
5
- import { askWithTypedChoices, loadAppConfig, loadDeveloperConfig } from "./actors.js";
6
- import { printInstallInstructions } from "../util/print-install-instructions.js";
7
- import { printLogo, showError } from "./actions.js";
8
- import Spinner from "tiny-spinner";
9
- export const connectionTypes = [
10
- { value: "secret", label: "Secret" },
11
- { value: "oauth2-code", label: "OAuth2" },
12
- ];
13
- export const audiences = [
14
- { value: "workspace", label: "Workspace" },
15
- { value: "workspace-member", label: "Workspace Member" },
16
- ];
17
- export const publishVersionMachine = setup({
18
- types: {
19
- context: {},
20
- events: {},
21
- input: {},
22
- },
23
- actors: {
24
- askForVersion: askWithTypedChoices(),
25
- fetchVersions: fromCallback(({ sendBack, input: { developer: { token, slug: devSlug }, config, }, }) => {
26
- const getVersions = async () => {
27
- const spinner = new Spinner();
28
- spinner.start("Loading versions...");
29
- const versions = await fetchPublishableVersions({
30
- token,
31
- devSlug,
32
- appId: config.id,
33
- });
34
- spinner.success("Versions loaded");
35
- sendBack({ type: "Versions Fetched", versions });
36
- };
37
- getVersions();
38
- }),
39
- publishVersion: fromCallback(({ sendBack, input: { developer: { token, slug: devSlug }, config, major, minor, }, }) => {
40
- const add = async () => {
41
- const spinner = new Spinner();
42
- try {
43
- spinner.start(`Publishing version ${major}.${minor}...`);
44
- if (major === undefined || minor === undefined) {
45
- throw new Error("Major and minor must be provided");
46
- }
47
- await publishVersion({
48
- token,
49
- devSlug,
50
- appId: config.id,
51
- major,
52
- minor,
53
- });
54
- spinner.success(`Version ${major}.${minor} published successfully!`);
55
- sendBack({ type: "Success" });
56
- }
57
- catch (error) {
58
- spinner.error("Error publishing version");
59
- sendBack({ type: "Error", error: error.message });
60
- }
61
- };
62
- add();
63
- }),
64
- loadDeveloperConfig,
65
- loadAppConfig,
66
- },
67
- actions: {
68
- printLogo,
69
- showError,
70
- showConfigInstructions: ({ context }) => printInstallInstructions(context.configError),
71
- showNoUnpublishedVersions: () => {
72
- process.stdout.write("No unpublished versions found.\n");
73
- },
74
- clearError: assign({
75
- error: () => undefined,
76
- }),
77
- setError: assign({
78
- error: (_, params) => params.error,
79
- }),
80
- setDeveloperConfig: assign({
81
- developer: (_, params) => params,
82
- }),
83
- setConfigError: assign({
84
- configError: (_, params) => params.configError,
85
- }),
86
- setConfig: assign({
87
- config: (_, params) => params.config,
88
- }),
89
- setVersion: assign({
90
- major: (_, params) => params.output.major,
91
- minor: (_, params) => params.output.minor,
92
- }),
93
- setVersions: assign({
94
- versions: (_, params) => params.versions,
95
- }),
96
- },
97
- guards: {
98
- "have version": (_, params) => params.major !== undefined && params.minor !== undefined,
99
- "no unpublished versions": (_, params) => params.versions.length === 0,
100
- },
101
- }).createMachine({
102
- context: ({ input }) => ({
103
- developer: { slug: "", token: "" },
104
- config: emptyConfig,
105
- versions: [],
106
- major: input.major,
107
- minor: input.minor,
108
- }),
109
- id: "Publish Version Machine",
110
- states: {
111
- "Loading Developer Config": {
112
- invoke: {
113
- src: "loadDeveloperConfig",
114
- },
115
- on: {
116
- "Developer Config Loaded": {
117
- target: "Loading App Config",
118
- actions: { type: "setDeveloperConfig", params: ({ event }) => event },
119
- },
120
- "No Developer Config": {
121
- target: "Show config instructions",
122
- actions: { type: "setConfigError", params: ({ event }) => event },
123
- },
124
- },
125
- },
126
- "Show config instructions": {
127
- type: "final",
128
- entry: "showConfigInstructions",
129
- },
130
- "Loading App Config": {
131
- invoke: {
132
- src: "loadAppConfig",
133
- },
134
- on: {
135
- "Error": {
136
- target: "Error",
137
- actions: { type: "setError", params: ({ event }) => event },
138
- },
139
- "App Config Loaded": {
140
- target: "Do we have a version selected?",
141
- actions: { type: "setConfig", params: ({ event }) => event },
142
- reenter: true,
143
- },
144
- },
145
- },
146
- "Error": {
147
- type: "final",
148
- entry: { type: "showError", params: ({ context }) => ({ error: context.error }) },
149
- },
150
- "Success": {
151
- type: "final",
152
- },
153
- "Fetching Versions": {
154
- on: {
155
- "Versions Fetched": {
156
- target: "Ask for version",
157
- actions: { type: "setVersions", params: ({ event }) => event },
158
- },
159
- },
160
- invoke: {
161
- src: "fetchVersions",
162
- input: ({ context }) => ({
163
- developer: context.developer,
164
- config: context.config,
165
- }),
166
- },
167
- },
168
- "Do we have a version selected?": {
169
- always: [
170
- {
171
- target: "Publishing",
172
- guard: {
173
- type: "have version",
174
- params: ({ context }) => context,
175
- },
176
- },
177
- {
178
- target: "Fetching Versions",
179
- reenter: true,
180
- },
181
- ],
182
- },
183
- "Publishing": {
184
- invoke: {
185
- src: "publishVersion",
186
- input: ({ context }) => context,
187
- },
188
- on: {
189
- Success: {
190
- target: "Success",
191
- reenter: true,
192
- },
193
- Error: {
194
- target: "Error",
195
- actions: { type: "setError", params: ({ event }) => event },
196
- reenter: true,
197
- },
198
- },
199
- },
200
- "Ask for version": {
201
- always: {
202
- target: "No unpublished versions",
203
- guard: {
204
- type: "no unpublished versions",
205
- params: ({ context }) => context,
206
- },
207
- },
208
- invoke: {
209
- src: "askForVersion",
210
- input: ({ context }) => ({
211
- message: "Select a version to publish:",
212
- choices: context.versions.map((version) => ({
213
- name: `${version.major}.${version.minor}`,
214
- value: version,
215
- })),
216
- }),
217
- onDone: {
218
- target: "Publishing",
219
- actions: { type: "setVersion", params: ({ event }) => event },
220
- },
221
- },
222
- },
223
- "No unpublished versions": {
224
- type: "final",
225
- entry: "showNoUnpublishedVersions",
226
- },
227
- },
228
- initial: "Loading Developer Config",
229
- entry: "printLogo",
230
- });