attio 0.0.1-experimental.20250303 → 0.0.1-experimental.20250321

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.
@@ -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,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
- });
@@ -1,253 +0,0 @@
1
- import { assign, setup, fromCallback } from "xstate";
2
- import { fetchConnections } from "../api/fetch-connections.js";
3
- import { removeConnectionDefinition } from "../api/remove-connection-definition.js";
4
- import { emptyConfig } from "../schema.js";
5
- import { askWithChoices, loadAppConfig, loadDeveloperConfig, confirm } from "./actors.js";
6
- import { printInstallInstructions } from "../util/print-install-instructions.js";
7
- import { showError, printLogo } from "./actions.js";
8
- import Spinner from "tiny-spinner";
9
- export const removeConnectionMachine = setup({
10
- types: {
11
- context: {},
12
- events: {},
13
- },
14
- actors: {
15
- askWithChoices,
16
- confirm,
17
- removeConnectionDefinition: fromCallback(({ sendBack, input }) => {
18
- const add = async () => {
19
- const spinner = new Spinner();
20
- try {
21
- spinner.start("Removing connection...");
22
- await removeConnectionDefinition({
23
- token: input.developer.token,
24
- devSlug: input.developer.slug,
25
- appId: input.config.id,
26
- global: input.global,
27
- major: input.config.major,
28
- });
29
- spinner.success("Connection removed");
30
- sendBack({ type: "Success" });
31
- }
32
- catch (error) {
33
- spinner.error("Error removing connection");
34
- sendBack({ type: "Error", error: error.message });
35
- }
36
- };
37
- add();
38
- }),
39
- loadDeveloperConfig,
40
- loadAppConfig,
41
- loadConnections: fromCallback(({ sendBack, input }) => {
42
- const spinner = new Spinner();
43
- spinner.start("Loading connections...");
44
- fetchConnections({
45
- token: input.developer.token,
46
- devSlug: input.developer.slug,
47
- appId: input.config.id,
48
- major: input.config.major,
49
- })
50
- .then((connections) => {
51
- spinner.success("Connections loaded");
52
- sendBack({ type: "Connections Loaded", connections });
53
- })
54
- .catch((error) => {
55
- spinner.error("Error loading connections");
56
- sendBack({ type: "Error", error: error.message });
57
- });
58
- }),
59
- },
60
- actions: {
61
- printLogo,
62
- showError,
63
- showConfigInstructions: ({ context }) => printInstallInstructions(context.configError),
64
- showCanceled: () => {
65
- process.stdout.write("No connection removed.\n\n");
66
- },
67
- showNoConnections: () => {
68
- process.stdout.write("This app has no connections to remove.\n\n");
69
- },
70
- clearError: assign({
71
- error: () => undefined,
72
- }),
73
- setError: assign({
74
- error: (_, params) => params.error,
75
- }),
76
- setDeveloperConfig: assign({
77
- developer: (_, params) => params,
78
- }),
79
- setConfigError: assign({
80
- configError: (_, params) => params.configError,
81
- }),
82
- setConfig: assign({
83
- config: (_, params) => params.config,
84
- }),
85
- setConnections: assign({
86
- connections: (_, params) => params.connections,
87
- }),
88
- setGlobal: assign({
89
- global: (_, params) => params.output === "true",
90
- }),
91
- setOnlyConnection: assign({
92
- global: (_, params) => params.connections[0].global,
93
- }),
94
- },
95
- guards: {
96
- "have more than one connection": (_, params) => Boolean(params.connections && params.connections.length > 1),
97
- "have only one connection": (_, params) => Boolean(params.connections && params.connections.length === 1),
98
- "confirmed": (_, params) => params.output,
99
- },
100
- }).createMachine({
101
- context: ({ input }) => ({
102
- developer: { slug: "", token: "" },
103
- config: emptyConfig,
104
- ...input,
105
- }),
106
- id: "Remove Connection Machine",
107
- states: {
108
- "Loading Developer Config": {
109
- invoke: {
110
- src: "loadDeveloperConfig",
111
- },
112
- on: {
113
- "Developer Config Loaded": {
114
- target: "Loading App Config",
115
- actions: { type: "setDeveloperConfig", params: ({ event }) => event },
116
- },
117
- "No Developer Config": {
118
- target: "Show config instructions",
119
- actions: { type: "setConfigError", params: ({ event }) => event },
120
- },
121
- },
122
- },
123
- "Show config instructions": {
124
- type: "final",
125
- entry: "showConfigInstructions",
126
- },
127
- "Loading App Config": {
128
- invoke: {
129
- src: "loadAppConfig",
130
- },
131
- on: {
132
- "Error": {
133
- target: "Error",
134
- actions: { type: "setError", params: ({ event }) => event },
135
- },
136
- "App Config Loaded": {
137
- target: "Loading Connections",
138
- actions: { type: "setConfig", params: ({ event }) => event },
139
- },
140
- },
141
- },
142
- "Error": {
143
- type: "final",
144
- entry: { type: "showError", params: ({ context }) => ({ error: context.error }) },
145
- },
146
- "Removing connection definition": {
147
- invoke: {
148
- src: "removeConnectionDefinition",
149
- input: ({ context }) => ({
150
- developer: context.developer,
151
- config: context.config,
152
- global: context.global,
153
- }),
154
- },
155
- on: {
156
- Success: "Success",
157
- Error: {
158
- target: "Error",
159
- actions: { type: "setError", params: ({ event }) => event },
160
- },
161
- },
162
- },
163
- "Success": {
164
- type: "final",
165
- },
166
- "Loading Connections": {
167
- invoke: {
168
- src: "loadConnections",
169
- input: ({ context }) => context,
170
- },
171
- on: {
172
- "Connections Loaded": [
173
- {
174
- target: "Choosing a Connection",
175
- actions: { type: "setConnections", params: ({ event }) => event },
176
- guard: {
177
- type: "have more than one connection",
178
- params: ({ event }) => event,
179
- },
180
- },
181
- {
182
- target: "Confirm Removal",
183
- guard: {
184
- type: "have only one connection",
185
- params: ({ event }) => event,
186
- },
187
- reenter: true,
188
- actions: [
189
- {
190
- type: "setConnections",
191
- params: ({ event }) => event,
192
- },
193
- {
194
- type: "setOnlyConnection",
195
- params: ({ event }) => event,
196
- },
197
- ],
198
- },
199
- "No Connections",
200
- ],
201
- "Error": {
202
- target: "Error",
203
- actions: { type: "setError", params: ({ event }) => event },
204
- },
205
- },
206
- },
207
- "No Connections": {
208
- type: "final",
209
- entry: "showNoConnections",
210
- },
211
- "Choosing a Connection": {
212
- invoke: {
213
- src: "askWithChoices",
214
- input: ({ context }) => ({
215
- message: "Which connection would you like to remove?",
216
- choices: context.connections.map((connection) => ({
217
- name: `${connection.label} (${connection.global ? "workspace" : "user"})`,
218
- value: connection.global ? "true" : "false",
219
- })),
220
- required: true,
221
- }),
222
- onDone: {
223
- target: "Confirm Removal",
224
- actions: { type: "setGlobal", params: ({ event }) => event },
225
- },
226
- },
227
- },
228
- "Confirm Removal": {
229
- invoke: {
230
- src: "confirm",
231
- input: ({ context }) => ({
232
- message: `Are you sure you want to remove "${context.connections[0].label}"?`,
233
- }),
234
- onDone: [
235
- {
236
- target: "Removing connection definition",
237
- guard: { type: "confirmed", params: ({ event }) => event },
238
- },
239
- {
240
- target: "Canceled",
241
- reenter: true,
242
- },
243
- ],
244
- },
245
- },
246
- "Canceled": {
247
- type: "final",
248
- entry: "showCanceled",
249
- },
250
- },
251
- initial: "Loading Developer Config",
252
- entry: "printLogo",
253
- });
@@ -1,16 +0,0 @@
1
- import React from "react"
2
- import {TextBlock, useAsyncCache} from "attio/client"
3
- import getAdvice from "./get-advice.server"
4
-
5
- export const Advice = ({recordId}) => {
6
- // By passing in the recordId, the result will be cached for each recordId
7
- const {
8
- values: {advice},
9
- // ^^^^^^– this key matches
10
- // vvvvvv– this key
11
- } = useAsyncCache({advice: [getAdvice, recordId]})
12
- // ^^^^^^^^^ ^^^^^^^^
13
- // async fn parameter(s)
14
-
15
- return <TextBlock align="center">{`"${advice}"`}</TextBlock>
16
- }
@@ -1,6 +0,0 @@
1
- export default async function getAdvice(recordId) {
2
- // We don't really need the recordId for this API, but this is how we could use a parameter
3
- const response = await fetch(`https://api.adviceslip.com/advice?${recordId}`)
4
- const data = await response.json()
5
- return data.slip.advice
6
- }