attio 0.0.1-experimental.20241011.3 → 0.0.1-experimental.20241011.4

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.
@@ -3,7 +3,7 @@ import { API } from "../env.js";
3
3
  import { handleError } from "./handle-error.js";
4
4
  import { makeHeaders } from "./make-headers.js";
5
5
  const connectionDefinitionsResponseSchema = z.object({
6
- connection_definitions: z.record(z.string(), z.object({
6
+ values: z.array(z.object({
7
7
  label: z.string(),
8
8
  connection_type: z.enum(["oauth2-code", "secret"]),
9
9
  description: z.string().nullable(),
@@ -16,5 +16,5 @@ export async function fetchConnections({ token, devSlug, appId, major, }) {
16
16
  headers: makeHeaders(token),
17
17
  });
18
18
  await handleError(response);
19
- return connectionDefinitionsResponseSchema.parse(await response.json()).connection_definitions;
19
+ return connectionDefinitionsResponseSchema.parse(await response.json()).values;
20
20
  }
@@ -1,8 +1,8 @@
1
1
  import { API } from "../env.js";
2
2
  import { handleError } from "./handle-error.js";
3
3
  import { makeHeaders } from "./make-headers.js";
4
- export async function removeConnectionDefinition({ token, devSlug, appId, slug, major, }) {
5
- const response = await fetch(`${API}/developer-portal/accounts/${devSlug}/apps/${appId}/versions/${major}/connection-definitions/${slug}`, {
4
+ export async function removeConnectionDefinition({ token, devSlug, appId, global, major, }) {
5
+ const response = await fetch(`${API}/developer-portal/accounts/${devSlug}/apps/${appId}/versions/${major}/connection-definitions/${global ? "workspace" : "user"}/remove`, {
6
6
  method: "DELETE",
7
7
  headers: makeHeaders(token),
8
8
  });
@@ -42,8 +42,7 @@ export default function ListConnections({ options: { dev } }) {
42
42
  snapshot.matches("Display Connections") &&
43
43
  snapshot.context.connections &&
44
44
  snapshot.context.connections && (React.createElement(Box, null,
45
- React.createElement(Table, { rows: Object.entries(snapshot.context.connections).map(([slug, connection]) => ({
46
- Slug: slug,
45
+ React.createElement(Table, { rows: snapshot.context.connections.map((connection) => ({
47
46
  Label: connection.label,
48
47
  Global: connection.global ? "Yes" : "No",
49
48
  Type: connectionTypeNames[connection.connection_type],
@@ -37,17 +37,17 @@ export default function RemoveConnection({ options: { dev } }) {
37
37
  React.createElement(Box, null,
38
38
  React.createElement(Text, null, "Which connection would you like to remove?")),
39
39
  React.createElement(Box, null,
40
- React.createElement(Select, { items: Object.entries(snapshot.context.connections).map(([slug, value]) => ({
41
- value: slug,
42
- label: value.label,
43
- })), onSelect: (slug) => send({ type: "Connection Chosen", slug }) })))),
40
+ React.createElement(Select, { items: snapshot.context.connections.map((connection) => ({
41
+ value: connection.global,
42
+ label: connection.label,
43
+ })), onSelect: (global) => send({ type: "Connection Chosen", global }) })))),
44
44
  snapshot.matches("Confirm Removal") &&
45
- snapshot.context.chosenConnectionSlug &&
45
+ snapshot.context.global !== undefined &&
46
46
  snapshot.context.connections && (React.createElement(Box, { flexDirection: "column" },
47
47
  React.createElement(Box, null,
48
48
  React.createElement(Text, null,
49
49
  "Are you sure you want to remove \"",
50
- snapshot.context.connections[snapshot.context.chosenConnectionSlug].label,
50
+ snapshot.context.connections.find(({ global }) => global === snapshot.context.global).label,
51
51
  "\"?")),
52
52
  React.createElement(Box, null,
53
53
  React.createElement(Select, { items: [
@@ -3,7 +3,6 @@ import { assign, setup, fromCallback } from "xstate";
3
3
  import { addConnectionDefinition } from "../api/add-connection-definition.js";
4
4
  import { fetchConnections } from "../api/fetch-connections.js";
5
5
  import { options } from "../commands/connection/add.js";
6
- import { updateAppConfig } from "../util/app-config.js";
7
6
  import { slugifyExtension } from "../util/slugify-extension.js";
8
7
  import { loadAppConfig, loadDeveloperConfig } from "./actors.js";
9
8
  export const connectionTypes = [
@@ -36,10 +35,6 @@ export const addConnectionMachine = setup({
36
35
  clientSecret,
37
36
  scopes,
38
37
  });
39
- updateAppConfig((config) => ({
40
- ...config,
41
- connectionType: connection_type,
42
- }));
43
38
  sendBack({ type: "Success" });
44
39
  }
45
40
  catch (error) {
@@ -77,18 +72,18 @@ export const addConnectionMachine = setup({
77
72
  }
78
73
  };
79
74
  }),
80
- "validateKey": fromCallback(({ sendBack, input: { key, developer, config } }) => {
75
+ "validateGlobal": fromCallback(({ sendBack, input: { developer, config, global } }) => {
81
76
  fetchConnections({
82
77
  token: developer.token,
83
78
  devSlug: developer.slug,
84
79
  appId: config.id,
85
80
  major: config.major,
86
81
  }).then((connections) => {
87
- if (connections[key]) {
88
- sendBack({ type: "Key Taken" });
82
+ if (connections.some((connection) => connection.global === global)) {
83
+ sendBack({ type: "Global Taken" });
89
84
  }
90
85
  else {
91
- sendBack({ type: "Valid Key" });
86
+ sendBack({ type: "Valid Global" });
92
87
  }
93
88
  });
94
89
  }),
@@ -190,8 +185,8 @@ export const addConnectionMachine = setup({
190
185
  setAppConfig: assign({
191
186
  config: (_, params) => params.config,
192
187
  }),
193
- setKeyTaken: assign({
194
- error: () => "Key taken",
188
+ setGlobalTaken: assign({
189
+ error: () => "Global taken",
195
190
  }),
196
191
  slugifyLabel: assign({
197
192
  key: (_, params) => slugifyExtension(params.label, true),
@@ -457,7 +452,9 @@ export const addConnectionMachine = setup({
457
452
  "Do we have a key?": {
458
453
  always: [
459
454
  {
460
- target: "Validating Key",
455
+ target: "Do we have a description?",
456
+ reenter: true,
457
+ actions: "clearError",
461
458
  guard: { type: "have key", params: ({ context }) => context },
462
459
  },
463
460
  {
@@ -469,35 +466,14 @@ export const addConnectionMachine = setup({
469
466
  },
470
467
  ],
471
468
  },
472
- "Validating Key": {
473
- on: {
474
- "Key Taken": {
475
- target: "Ask for key",
476
- actions: "setKeyTaken",
477
- },
478
- "Valid Key": {
479
- target: "Do we have a description?",
480
- reenter: true,
481
- actions: "clearError",
482
- },
483
- },
484
- invoke: {
485
- src: "validateKey",
486
- input: ({ context }) => ({
487
- key: context.key,
488
- developer: context.developer,
489
- config: context.config,
490
- }),
491
- },
492
- },
493
469
  "Ask for key": {
494
470
  on: {
495
471
  "Update Key": {
496
472
  actions: { type: "setKey", params: ({ event }) => event },
497
473
  },
498
- "Submit": "Validating Key",
474
+ "Submit": "Do we have a description?",
499
475
  "Previous": "Ask for label",
500
- "Next": "Validating Key",
476
+ "Next": "Do we have a description?",
501
477
  },
502
478
  },
503
479
  "Do we have a connection type?": {
@@ -560,7 +536,7 @@ export const addConnectionMachine = setup({
560
536
  "Do we have global?": {
561
537
  always: [
562
538
  {
563
- target: "Split on connection type",
539
+ target: "Validating Global",
564
540
  guard: { type: "have global", params: ({ context }) => context },
565
541
  reenter: true,
566
542
  },
@@ -612,18 +588,38 @@ export const addConnectionMachine = setup({
612
588
  "Ask for global": {
613
589
  on: {
614
590
  "Choose Global": {
615
- target: "Split on connection type",
591
+ target: "Validating Global",
616
592
  actions: { type: "setGlobal", params: ({ event }) => event },
617
593
  reenter: true,
618
594
  },
619
595
  "Previous": "Ask for description",
620
596
  "Next": {
621
- target: "Split on connection type",
597
+ target: "Validating Global",
622
598
  guard: { type: "have global", params: ({ context }) => context },
623
599
  reenter: true,
624
600
  },
625
601
  },
626
602
  },
603
+ "Validating Global": {
604
+ on: {
605
+ "Global Taken": {
606
+ target: "Ask for global",
607
+ actions: "setGlobalTaken",
608
+ },
609
+ "Valid Global": {
610
+ target: "Split on connection type",
611
+ reenter: true,
612
+ },
613
+ },
614
+ invoke: {
615
+ src: "validateGlobal",
616
+ input: ({ context }) => ({
617
+ global: context.global,
618
+ developer: context.developer,
619
+ config: context.config,
620
+ }),
621
+ },
622
+ },
627
623
  },
628
624
  initial: "Loading Developer Config",
629
625
  invoke: {
@@ -39,7 +39,7 @@ export const listConnectionsMachine = setup({
39
39
  }),
40
40
  },
41
41
  guards: {
42
- "have connections": (_, params) => Boolean(params.connections && Object.keys(params.connections).length > 0),
42
+ "have connections": (_, params) => Boolean(params.connections && params.connections.length > 0),
43
43
  },
44
44
  }).createMachine({
45
45
  context: ({ input }) => ({
@@ -2,7 +2,6 @@ import { assign, setup, fromCallback } from "xstate";
2
2
  import { fetchConnections } from "../api/fetch-connections.js";
3
3
  import { removeConnectionDefinition } from "../api/remove-connection-definition.js";
4
4
  import { emptyConfig } from "../schema.js";
5
- import { updateAppConfig } from "../util/app-config.js";
6
5
  import { loadAppConfig, loadDeveloperConfig } from "./actors.js";
7
6
  export const removeConnectionMachine = setup({
8
7
  types: {
@@ -17,13 +16,9 @@ export const removeConnectionMachine = setup({
17
16
  token: input.developer.token,
18
17
  devSlug: input.developer.slug,
19
18
  appId: input.config.id,
20
- slug: input.chosenConnectionSlug,
19
+ global: input.global,
21
20
  major: input.config.major,
22
21
  });
23
- updateAppConfig((config) => ({
24
- ...config,
25
- connection: null,
26
- }));
27
22
  sendBack({ type: "Success" });
28
23
  }
29
24
  catch (error) {
@@ -64,16 +59,16 @@ export const removeConnectionMachine = setup({
64
59
  setConnections: assign({
65
60
  connections: (_, params) => params.connections,
66
61
  }),
67
- setConnection: assign({
68
- chosenConnectionSlug: (_, params) => params.slug,
62
+ setGlobal: assign({
63
+ global: (_, params) => params.global,
69
64
  }),
70
65
  setOnlyConnection: assign({
71
- chosenConnectionSlug: (_, params) => Object.keys(params.connections)[0],
66
+ global: (_, params) => params.connections[0].global,
72
67
  }),
73
68
  },
74
69
  guards: {
75
- "have more than one connection": (_, params) => Boolean(params.connections && Object.keys(params.connections).length > 1),
76
- "have only one connection": (_, params) => Boolean(params.connections && Object.keys(params.connections).length === 1),
70
+ "have more than one connection": (_, params) => Boolean(params.connections && params.connections.length > 1),
71
+ "have only one connection": (_, params) => Boolean(params.connections && params.connections.length === 1),
77
72
  },
78
73
  }).createMachine({
79
74
  context: ({ input }) => ({
@@ -125,7 +120,7 @@ export const removeConnectionMachine = setup({
125
120
  input: ({ context }) => ({
126
121
  developer: context.developer,
127
122
  config: context.config,
128
- chosenConnectionSlug: context.chosenConnectionSlug,
123
+ global: context.global,
129
124
  }),
130
125
  },
131
126
  on: {
@@ -187,7 +182,12 @@ export const removeConnectionMachine = setup({
187
182
  on: {
188
183
  "Connection Chosen": {
189
184
  target: "Confirm Removal",
190
- actions: { type: "setConnection", params: ({ event }) => event },
185
+ actions: {
186
+ type: "setGlobal",
187
+ params: ({ event }) => ({
188
+ global: event.global,
189
+ }),
190
+ },
191
191
  reenter: true,
192
192
  },
193
193
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "attio",
3
- "version": "0.0.1-experimental.20241011.3",
3
+ "version": "0.0.1-experimental.20241011.4",
4
4
  "bin": "lib/attio.js",
5
5
  "type": "module",
6
6
  "files": [