figmanage 1.0.1 → 1.2.0

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 (98) hide show
  1. package/README.md +74 -59
  2. package/dist/cli/analytics.d.ts +3 -0
  3. package/dist/cli/analytics.js +48 -0
  4. package/dist/cli/branching.d.ts +3 -0
  5. package/dist/cli/branching.js +56 -0
  6. package/dist/cli/comments.d.ts +3 -0
  7. package/dist/cli/comments.js +86 -0
  8. package/dist/cli/completion.d.ts +7 -0
  9. package/dist/cli/completion.js +160 -0
  10. package/dist/cli/components.d.ts +3 -0
  11. package/dist/cli/components.js +82 -0
  12. package/dist/cli/compound-commands.d.ts +14 -0
  13. package/dist/cli/compound-commands.js +291 -0
  14. package/dist/cli/export.d.ts +3 -0
  15. package/dist/cli/export.js +51 -0
  16. package/dist/cli/files.d.ts +3 -0
  17. package/dist/cli/files.js +156 -0
  18. package/dist/cli/format.js +147 -2
  19. package/dist/cli/helpers.d.ts +7 -0
  20. package/dist/cli/helpers.js +43 -0
  21. package/dist/cli/index.js +68 -89
  22. package/dist/cli/libraries.d.ts +3 -0
  23. package/dist/cli/libraries.js +26 -0
  24. package/dist/cli/navigate.d.ts +3 -0
  25. package/dist/cli/navigate.js +192 -0
  26. package/dist/cli/org.d.ts +3 -0
  27. package/dist/cli/org.js +227 -0
  28. package/dist/cli/permissions.d.ts +3 -0
  29. package/dist/cli/permissions.js +133 -0
  30. package/dist/cli/projects.d.ts +3 -0
  31. package/dist/cli/projects.js +110 -0
  32. package/dist/cli/reading.d.ts +3 -0
  33. package/dist/cli/reading.js +51 -0
  34. package/dist/cli/teams.d.ts +3 -0
  35. package/dist/cli/teams.js +56 -0
  36. package/dist/cli/variables.d.ts +3 -0
  37. package/dist/cli/variables.js +80 -0
  38. package/dist/cli/versions.d.ts +3 -0
  39. package/dist/cli/versions.js +46 -0
  40. package/dist/cli/webhooks.d.ts +3 -0
  41. package/dist/cli/webhooks.js +100 -0
  42. package/dist/operations/analytics.d.ts +10 -0
  43. package/dist/operations/analytics.js +15 -0
  44. package/dist/operations/branching.d.ts +24 -0
  45. package/dist/operations/branching.js +41 -0
  46. package/dist/operations/comments.d.ts +43 -0
  47. package/dist/operations/comments.js +65 -0
  48. package/dist/operations/components.d.ts +24 -0
  49. package/dist/operations/components.js +30 -0
  50. package/dist/operations/compound-manager.d.ts +101 -0
  51. package/dist/operations/compound-manager.js +629 -0
  52. package/dist/operations/compound.d.ts +102 -0
  53. package/dist/operations/compound.js +595 -0
  54. package/dist/operations/export.d.ts +19 -0
  55. package/dist/operations/export.js +27 -0
  56. package/dist/operations/files.d.ts +55 -0
  57. package/dist/operations/files.js +89 -0
  58. package/dist/operations/libraries.d.ts +5 -0
  59. package/dist/operations/libraries.js +10 -0
  60. package/dist/operations/navigate.d.ts +99 -0
  61. package/dist/operations/navigate.js +266 -0
  62. package/dist/operations/org.d.ts +95 -0
  63. package/dist/operations/org.js +205 -0
  64. package/dist/operations/permissions.d.ts +59 -0
  65. package/dist/operations/permissions.js +112 -0
  66. package/dist/operations/projects.d.ts +29 -0
  67. package/dist/operations/projects.js +40 -0
  68. package/dist/operations/reading.d.ts +12 -0
  69. package/dist/operations/reading.js +20 -0
  70. package/dist/operations/teams.d.ts +17 -0
  71. package/dist/operations/teams.js +17 -0
  72. package/dist/operations/variables.d.ts +17 -0
  73. package/dist/operations/variables.js +39 -0
  74. package/dist/operations/versions.d.ts +23 -0
  75. package/dist/operations/versions.js +27 -0
  76. package/dist/operations/webhooks.d.ts +25 -0
  77. package/dist/operations/webhooks.js +38 -0
  78. package/dist/tools/analytics.js +6 -16
  79. package/dist/tools/branching.js +7 -36
  80. package/dist/tools/comments.js +9 -56
  81. package/dist/tools/components.js +7 -19
  82. package/dist/tools/compound-manager.js +21 -644
  83. package/dist/tools/compound.js +32 -566
  84. package/dist/tools/export.js +4 -23
  85. package/dist/tools/files.js +21 -68
  86. package/dist/tools/libraries.js +4 -11
  87. package/dist/tools/navigate.js +23 -246
  88. package/dist/tools/org.js +29 -245
  89. package/dist/tools/permissions.js +18 -97
  90. package/dist/tools/projects.js +8 -27
  91. package/dist/tools/reading.js +5 -15
  92. package/dist/tools/teams.js +8 -16
  93. package/dist/tools/variables.js +13 -30
  94. package/dist/tools/versions.js +6 -24
  95. package/dist/tools/webhooks.js +7 -24
  96. package/package.json +1 -1
  97. package/dist/cli/commands.d.ts +0 -47
  98. package/dist/cli/commands.js +0 -1204
@@ -0,0 +1,38 @@
1
+ import { publicClient } from '../clients/public-api.js';
2
+ export async function listWebhooks(config, params) {
3
+ const res = await publicClient(config).get(`/v2/teams/${params.team_id}/webhooks`);
4
+ return res.data?.webhooks || [];
5
+ }
6
+ export async function createWebhook(config, params) {
7
+ const body = {
8
+ team_id: params.team_id,
9
+ event_type: params.event_type,
10
+ endpoint: params.endpoint,
11
+ passcode: params.passcode,
12
+ };
13
+ if (params.description)
14
+ body.description = params.description;
15
+ const res = await publicClient(config).post('/v2/webhooks', body);
16
+ const { passcode: _, ...safe } = res.data || {};
17
+ return safe;
18
+ }
19
+ export async function updateWebhook(config, params) {
20
+ const body = {};
21
+ if (params.event_type)
22
+ body.event_type = params.event_type;
23
+ if (params.endpoint)
24
+ body.endpoint = params.endpoint;
25
+ if (params.passcode)
26
+ body.passcode = params.passcode;
27
+ if (params.description)
28
+ body.description = params.description;
29
+ if (params.status)
30
+ body.status = params.status;
31
+ const res = await publicClient(config).put(`/v2/webhooks/${params.webhook_id}`, body);
32
+ const { passcode: _, ...safe } = res.data || {};
33
+ return safe;
34
+ }
35
+ export async function deleteWebhook(config, params) {
36
+ await publicClient(config).delete(`/v2/webhooks/${params.webhook_id}`);
37
+ }
38
+ //# sourceMappingURL=webhooks.js.map
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
- import { internalClient } from '../clients/internal-api.js';
3
- import { defineTool, toolResult, toolError, figmaId, requireOrgId } from './register.js';
2
+ import { defineTool, toolResult, toolError, figmaId } from './register.js';
3
+ import { libraryUsage, componentUsage } from '../operations/analytics.js';
4
4
  // -- library_usage --
5
5
  defineTool({
6
6
  toolset: 'analytics',
@@ -14,11 +14,8 @@ defineTool({
14
14
  },
15
15
  }, async ({ library_file_key, days }) => {
16
16
  try {
17
- const lookback = days ?? 30;
18
- const end_ts = Math.floor(Date.now() / 1000);
19
- const start_ts = end_ts - (lookback * 86400);
20
- const res = await internalClient(config).get(`/api/dsa/library/${library_file_key}/team_usage`, { params: { start_ts, end_ts } });
21
- return toolResult(JSON.stringify(res.data, null, 2));
17
+ const result = await libraryUsage(config, { library_file_key, days });
18
+ return toolResult(JSON.stringify(result, null, 2));
22
19
  }
23
20
  catch (e) {
24
21
  return toolError(`Failed to fetch library usage: ${e.response?.status || e.message}`);
@@ -39,15 +36,8 @@ defineTool({
39
36
  },
40
37
  }, async ({ component_key, org_id }) => {
41
38
  try {
42
- let orgId;
43
- try {
44
- orgId = requireOrgId(config, org_id);
45
- }
46
- catch (e) {
47
- return toolError(e.message);
48
- }
49
- const res = await internalClient(config).get(`/api/design_systems/component/${component_key}/file_usage`, { params: { org_id: orgId, fv: 4 } });
50
- return toolResult(JSON.stringify(res.data, null, 2));
39
+ const result = await componentUsage(config, { component_key, org_id });
40
+ return toolResult(JSON.stringify(result, null, 2));
51
41
  }
52
42
  catch (e) {
53
43
  return toolError(`Failed to fetch component usage: ${e.response?.status || e.message}`);
@@ -1,8 +1,6 @@
1
1
  import { z } from 'zod';
2
- import { hasCookie } from '../auth/client.js';
3
- import { publicClient } from '../clients/public-api.js';
4
- import { internalClient } from '../clients/internal-api.js';
5
2
  import { defineTool, toolResult, toolError, figmaId } from './register.js';
3
+ import { listBranches, createBranch, deleteBranch } from '../operations/branching.js';
6
4
  // -- list_branches --
7
5
  defineTool({
8
6
  toolset: 'branching',
@@ -15,28 +13,10 @@ defineTool({
15
13
  },
16
14
  }, async ({ file_key }) => {
17
15
  try {
18
- let branches;
19
- if (hasCookie(config)) {
20
- const res = await internalClient(config).get(`/api/files/${file_key}`);
21
- const f = res.data?.meta || res.data;
22
- branches = f.branches || [];
23
- }
24
- else {
25
- const res = await publicClient(config).get(`/v1/files/${file_key}`, {
26
- params: { branch_data: 'true', depth: '0' },
27
- });
28
- branches = res.data?.branches || [];
29
- }
30
- if (branches.length === 0)
16
+ const result = await listBranches(config, { file_key });
17
+ if (result.length === 0)
31
18
  return toolResult('No branches found.');
32
- const mapped = branches.map((b) => ({
33
- key: b.key,
34
- name: b.name,
35
- thumbnail_url: b.thumbnail_url || null,
36
- last_modified: b.last_modified || null,
37
- link_access: b.link_access || null,
38
- }));
39
- return toolResult(JSON.stringify(mapped, null, 2));
19
+ return toolResult(JSON.stringify(result, null, 2));
40
20
  }
41
21
  catch (e) {
42
22
  return toolError(`Failed to list branches: ${e.response?.status || e.message}`);
@@ -58,15 +38,8 @@ defineTool({
58
38
  },
59
39
  }, async ({ file_key, name }) => {
60
40
  try {
61
- const res = await internalClient(config).post(`/api/multiplayer/${file_key}/branch_create?name=${encodeURIComponent(name)}`);
62
- const meta = res.data?.meta || res.data || {};
63
- const file = meta.file || meta;
64
- const branchKey = file.key || file.file_key || null;
65
- return toolResult(JSON.stringify({
66
- key: branchKey,
67
- name,
68
- main_file_key: file_key,
69
- }, null, 2));
41
+ const result = await createBranch(config, { file_key, name });
42
+ return toolResult(JSON.stringify(result, null, 2));
70
43
  }
71
44
  catch (e) {
72
45
  return toolError(`Failed to create branch: ${e.response?.status || e.message}`);
@@ -89,9 +62,7 @@ defineTool({
89
62
  },
90
63
  }, async ({ branch_key }) => {
91
64
  try {
92
- await internalClient(config).delete('/api/files_batch', {
93
- data: { files: [{ key: branch_key }], trashed: true },
94
- });
65
+ await deleteBranch(config, { branch_key });
95
66
  return toolResult(`Archived branch ${branch_key}`);
96
67
  }
97
68
  catch (e) {
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
- import { publicClient } from '../clients/public-api.js';
3
2
  import { defineTool, toolResult, toolError, figmaId } from './register.js';
3
+ import { listComments, formatCommentsAsMarkdown, postComment, deleteComment, listCommentReactions, } from '../operations/comments.js';
4
4
  // -- list_comments --
5
5
  defineTool({
6
6
  toolset: 'comments',
@@ -14,40 +14,11 @@ defineTool({
14
14
  },
15
15
  }, async ({ file_key, as_md }) => {
16
16
  try {
17
- const res = await publicClient(config).get(`/v1/files/${file_key}/comments`);
18
- const comments = res.data?.comments || [];
17
+ const comments = await listComments(config, { file_key });
19
18
  if (as_md) {
20
- const threads = new Map();
21
- for (const c of comments) {
22
- const parentId = c.parent_id || c.id;
23
- if (!threads.has(parentId))
24
- threads.set(parentId, []);
25
- threads.get(parentId).push(c);
26
- }
27
- const lines = [];
28
- for (const [, thread] of threads) {
29
- thread.sort((a, b) => new Date(a.created_at).getTime() - new Date(b.created_at).getTime());
30
- for (const c of thread) {
31
- const indent = c.parent_id ? ' ' : '';
32
- const resolved = c.resolved_at ? ' [resolved]' : '';
33
- lines.push(`${indent}- **${c.user.handle}** (${c.created_at})${resolved}: ${c.message}`);
34
- }
35
- lines.push('');
36
- }
37
- return toolResult(lines.join('\n'));
19
+ return toolResult(formatCommentsAsMarkdown(comments));
38
20
  }
39
- const mapped = comments.map((c) => ({
40
- id: c.id,
41
- parent_id: c.parent_id || null,
42
- message: c.message,
43
- author: c.user?.handle,
44
- author_id: c.user?.id,
45
- created_at: c.created_at,
46
- resolved_at: c.resolved_at || null,
47
- node_id: c.client_meta?.node_id || c.client_meta?.node_offset?.node_id || null,
48
- order_id: c.order_id,
49
- }));
50
- return toolResult(JSON.stringify(mapped, null, 2));
21
+ return toolResult(JSON.stringify(comments, null, 2));
51
22
  }
52
23
  catch (e) {
53
24
  return toolError(`Failed to list comments: ${e.response?.status || e.message}`);
@@ -71,20 +42,8 @@ defineTool({
71
42
  },
72
43
  }, async ({ file_key, message, comment_id, node_id }) => {
73
44
  try {
74
- const body = { message };
75
- if (comment_id)
76
- body.comment_id = comment_id;
77
- if (node_id)
78
- body.client_meta = { node_id, node_offset: { x: 0, y: 0 } };
79
- const res = await publicClient(config).post(`/v1/files/${file_key}/comments`, body);
80
- const c = res.data;
81
- return toolResult(JSON.stringify({
82
- id: c.id,
83
- message: c.message,
84
- author: c.user?.handle,
85
- created_at: c.created_at,
86
- parent_id: c.parent_id || null,
87
- }, null, 2));
45
+ const result = await postComment(config, { file_key, message, comment_id, node_id });
46
+ return toolResult(JSON.stringify(result, null, 2));
88
47
  }
89
48
  catch (e) {
90
49
  return toolError(`Failed to post comment: ${e.response?.status || e.message}`);
@@ -107,7 +66,7 @@ defineTool({
107
66
  },
108
67
  }, async ({ file_key, comment_id }) => {
109
68
  try {
110
- await publicClient(config).delete(`/v1/files/${file_key}/comments/${comment_id}`);
69
+ await deleteComment(config, { file_key, comment_id });
111
70
  return toolResult(`Deleted comment ${comment_id}`);
112
71
  }
113
72
  catch (e) {
@@ -129,14 +88,8 @@ defineTool({
129
88
  },
130
89
  }, async ({ file_key, comment_id }) => {
131
90
  try {
132
- const res = await publicClient(config).get(`/v1/files/${file_key}/comments/${comment_id}/reactions`);
133
- const reactions = res.data?.reactions || [];
134
- const mapped = reactions.map((r) => ({
135
- emoji: r.emoji,
136
- user: r.user?.handle,
137
- created_at: r.created_at,
138
- }));
139
- return toolResult(JSON.stringify(mapped, null, 2));
91
+ const reactions = await listCommentReactions(config, { file_key, comment_id });
92
+ return toolResult(JSON.stringify(reactions, null, 2));
140
93
  }
141
94
  catch (e) {
142
95
  return toolError(`Failed to list reactions: ${e.response?.status || e.message}`);
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
- import { publicClient } from '../clients/public-api.js';
3
2
  import { defineTool, toolResult, toolError, figmaId } from './register.js';
3
+ import { listFileComponents, listFileStyles, listTeamComponents, listTeamStyles, } from '../operations/components.js';
4
4
  // -- list_file_components --
5
5
  defineTool({
6
6
  toolset: 'components',
@@ -13,8 +13,7 @@ defineTool({
13
13
  },
14
14
  }, async ({ file_key }) => {
15
15
  try {
16
- const res = await publicClient(config).get(`/v1/files/${file_key}/components`);
17
- const components = res.data?.meta?.components || [];
16
+ const components = await listFileComponents(config, { file_key });
18
17
  return toolResult(JSON.stringify(components, null, 2));
19
18
  }
20
19
  catch (e) {
@@ -35,8 +34,7 @@ defineTool({
35
34
  },
36
35
  }, async ({ file_key }) => {
37
36
  try {
38
- const res = await publicClient(config).get(`/v1/files/${file_key}/styles`);
39
- const styles = res.data?.meta?.styles || [];
37
+ const styles = await listFileStyles(config, { file_key });
40
38
  return toolResult(JSON.stringify(styles, null, 2));
41
39
  }
42
40
  catch (e) {
@@ -59,13 +57,8 @@ defineTool({
59
57
  },
60
58
  }, async ({ team_id, page_size, cursor }) => {
61
59
  try {
62
- const params = { page_size };
63
- if (cursor)
64
- params.after = cursor;
65
- const res = await publicClient(config).get(`/v1/teams/${team_id}/components`, { params });
66
- const components = res.data?.meta?.components || [];
67
- const pagination = res.data?.pagination || null;
68
- return toolResult(JSON.stringify({ components, pagination }, null, 2));
60
+ const result = await listTeamComponents(config, { team_id, page_size, cursor });
61
+ return toolResult(JSON.stringify(result, null, 2));
69
62
  }
70
63
  catch (e) {
71
64
  return toolError(`Failed to list team components: ${e.response?.status || e.message}`);
@@ -87,13 +80,8 @@ defineTool({
87
80
  },
88
81
  }, async ({ team_id, page_size, cursor }) => {
89
82
  try {
90
- const params = { page_size };
91
- if (cursor)
92
- params.after = cursor;
93
- const res = await publicClient(config).get(`/v1/teams/${team_id}/styles`, { params });
94
- const styles = res.data?.meta?.styles || [];
95
- const pagination = res.data?.pagination || null;
96
- return toolResult(JSON.stringify({ styles, pagination }, null, 2));
83
+ const result = await listTeamStyles(config, { team_id, page_size, cursor });
84
+ return toolResult(JSON.stringify(result, null, 2));
97
85
  }
98
86
  catch (e) {
99
87
  return toolError(`Failed to list team styles: ${e.response?.status || e.message}`);