@rnsk/toolkits 0.0.9 → 0.0.10

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 (132) hide show
  1. package/README.md +7 -1
  2. package/dist/index.d.ts +7 -1
  3. package/dist/index.js +13 -1
  4. package/dist/toolkits/hacker-news/icon.d.ts +5 -0
  5. package/dist/toolkits/hacker-news/icon.js +9 -0
  6. package/dist/toolkits/hacker-news/manifest.d.ts +3 -0
  7. package/dist/toolkits/hacker-news/manifest.js +25 -0
  8. package/dist/toolkits/hacker-news/tools/client.d.ts +8 -0
  9. package/dist/toolkits/hacker-news/tools/client.js +51 -0
  10. package/dist/toolkits/hacker-news/tools/index.d.ts +89 -0
  11. package/dist/toolkits/hacker-news/tools/index.js +22 -0
  12. package/dist/toolkits/hacker-news/tools/items.d.ts +42 -0
  13. package/dist/toolkits/hacker-news/tools/items.js +126 -0
  14. package/dist/toolkits/hacker-news/tools/search.d.ts +12 -0
  15. package/dist/toolkits/hacker-news/tools/search.js +40 -0
  16. package/dist/toolkits/hacker-news/tools/stories.d.ts +25 -0
  17. package/dist/toolkits/hacker-news/tools/stories.js +98 -0
  18. package/dist/toolkits/hostinger/icon.d.ts +5 -0
  19. package/dist/toolkits/hostinger/icon.js +6 -0
  20. package/dist/toolkits/hostinger/manifest.d.ts +3 -0
  21. package/dist/toolkits/hostinger/manifest.js +36 -0
  22. package/dist/toolkits/hostinger/tools/billing.d.ts +12 -0
  23. package/dist/toolkits/hostinger/tools/billing.js +35 -0
  24. package/dist/toolkits/hostinger/tools/client.d.ts +6 -0
  25. package/dist/toolkits/hostinger/tools/client.js +57 -0
  26. package/dist/toolkits/hostinger/tools/dns.d.ts +22 -0
  27. package/dist/toolkits/hostinger/tools/dns.js +47 -0
  28. package/dist/toolkits/hostinger/tools/domains.d.ts +21 -0
  29. package/dist/toolkits/hostinger/tools/domains.js +62 -0
  30. package/dist/toolkits/hostinger/tools/hosting.d.ts +17 -0
  31. package/dist/toolkits/hostinger/tools/hosting.js +38 -0
  32. package/dist/toolkits/hostinger/tools/index.d.ts +179 -0
  33. package/dist/toolkits/hostinger/tools/index.js +35 -0
  34. package/dist/toolkits/hostinger/tools/vps.d.ts +27 -0
  35. package/dist/toolkits/hostinger/tools/vps.js +77 -0
  36. package/dist/toolkits/hostinger/tools/whois.d.ts +33 -0
  37. package/dist/toolkits/hostinger/tools/whois.js +85 -0
  38. package/dist/toolkits/hugging-face/icon.d.ts +5 -0
  39. package/dist/toolkits/hugging-face/icon.js +6 -0
  40. package/dist/toolkits/hugging-face/manifest.d.ts +3 -0
  41. package/dist/toolkits/hugging-face/manifest.js +42 -0
  42. package/dist/toolkits/hugging-face/tools/client.d.ts +93 -0
  43. package/dist/toolkits/hugging-face/tools/client.js +192 -0
  44. package/dist/toolkits/hugging-face/tools/datasets-viewer.d.ts +65 -0
  45. package/dist/toolkits/hugging-face/tools/datasets-viewer.js +150 -0
  46. package/dist/toolkits/hugging-face/tools/datasets.d.ts +160 -0
  47. package/dist/toolkits/hugging-face/tools/datasets.js +383 -0
  48. package/dist/toolkits/hugging-face/tools/discussions.d.ts +68 -0
  49. package/dist/toolkits/hugging-face/tools/discussions.js +144 -0
  50. package/dist/toolkits/hugging-face/tools/index.d.ts +523 -0
  51. package/dist/toolkits/hugging-face/tools/index.js +163 -0
  52. package/dist/toolkits/hugging-face/tools/inference.d.ts +42 -0
  53. package/dist/toolkits/hugging-face/tools/inference.js +86 -0
  54. package/dist/toolkits/hugging-face/tools/models.d.ts +117 -0
  55. package/dist/toolkits/hugging-face/tools/models.js +273 -0
  56. package/dist/toolkits/hugging-face/tools/papers.d.ts +37 -0
  57. package/dist/toolkits/hugging-face/tools/papers.js +91 -0
  58. package/dist/toolkits/hugging-face/tools/repos.d.ts +96 -0
  59. package/dist/toolkits/hugging-face/tools/repos.js +201 -0
  60. package/dist/toolkits/hugging-face/tools/settings.d.ts +53 -0
  61. package/dist/toolkits/hugging-face/tools/settings.js +88 -0
  62. package/dist/toolkits/hugging-face/tools/spaces.d.ts +245 -0
  63. package/dist/toolkits/hugging-face/tools/spaces.js +468 -0
  64. package/dist/toolkits/hugging-face/tools/sql.d.ts +21 -0
  65. package/dist/toolkits/hugging-face/tools/sql.js +47 -0
  66. package/dist/toolkits/hugging-face/tools/users.d.ts +60 -0
  67. package/dist/toolkits/hugging-face/tools/users.js +132 -0
  68. package/dist/toolkits/hugging-face/tools/webhooks.d.ts +35 -0
  69. package/dist/toolkits/hugging-face/tools/webhooks.js +87 -0
  70. package/dist/toolkits/jira/icon.d.ts +5 -0
  71. package/dist/toolkits/jira/icon.js +6 -0
  72. package/dist/toolkits/jira/manifest.d.ts +3 -0
  73. package/dist/toolkits/jira/manifest.js +53 -0
  74. package/dist/toolkits/jira/tools/boards.d.ts +52 -0
  75. package/dist/toolkits/jira/tools/boards.js +104 -0
  76. package/dist/toolkits/jira/tools/client.d.ts +23 -0
  77. package/dist/toolkits/jira/tools/client.js +270 -0
  78. package/dist/toolkits/jira/tools/index.d.ts +1280 -0
  79. package/dist/toolkits/jira/tools/index.js +119 -0
  80. package/dist/toolkits/jira/tools/issue-fields.d.ts +10 -0
  81. package/dist/toolkits/jira/tools/issue-fields.js +111 -0
  82. package/dist/toolkits/jira/tools/issues.d.ts +304 -0
  83. package/dist/toolkits/jira/tools/issues.js +593 -0
  84. package/dist/toolkits/jira/tools/meta.d.ts +212 -0
  85. package/dist/toolkits/jira/tools/meta.js +369 -0
  86. package/dist/toolkits/jira/tools/projects.d.ts +130 -0
  87. package/dist/toolkits/jira/tools/projects.js +263 -0
  88. package/dist/toolkits/jira/tools/search.d.ts +90 -0
  89. package/dist/toolkits/jira/tools/search.js +181 -0
  90. package/dist/toolkits/jira/tools/users.d.ts +114 -0
  91. package/dist/toolkits/jira/tools/users.js +221 -0
  92. package/dist/toolkits/neo4j/icon.d.ts +5 -0
  93. package/dist/toolkits/neo4j/icon.js +6 -0
  94. package/dist/toolkits/neo4j/manifest.d.ts +3 -0
  95. package/dist/toolkits/neo4j/manifest.js +33 -0
  96. package/dist/toolkits/neo4j/tools/analytics.d.ts +21 -0
  97. package/dist/toolkits/neo4j/tools/analytics.js +91 -0
  98. package/dist/toolkits/neo4j/tools/client.d.ts +6 -0
  99. package/dist/toolkits/neo4j/tools/client.js +105 -0
  100. package/dist/toolkits/neo4j/tools/index.d.ts +198 -0
  101. package/dist/toolkits/neo4j/tools/index.js +30 -0
  102. package/dist/toolkits/neo4j/tools/instances.d.ts +47 -0
  103. package/dist/toolkits/neo4j/tools/instances.js +127 -0
  104. package/dist/toolkits/neo4j/tools/projects.d.ts +44 -0
  105. package/dist/toolkits/neo4j/tools/projects.js +110 -0
  106. package/dist/toolkits/neo4j/tools/snapshots.d.ts +20 -0
  107. package/dist/toolkits/neo4j/tools/snapshots.js +57 -0
  108. package/dist/toolkits/neon/icon.d.ts +5 -0
  109. package/dist/toolkits/neon/icon.js +8 -0
  110. package/dist/toolkits/neon/manifest.d.ts +3 -0
  111. package/dist/toolkits/neon/manifest.js +36 -0
  112. package/dist/toolkits/neon/tools/auth.d.ts +115 -0
  113. package/dist/toolkits/neon/tools/auth.js +286 -0
  114. package/dist/toolkits/neon/tools/branches.d.ts +189 -0
  115. package/dist/toolkits/neon/tools/branches.js +465 -0
  116. package/dist/toolkits/neon/tools/client.d.ts +10 -0
  117. package/dist/toolkits/neon/tools/client.js +69 -0
  118. package/dist/toolkits/neon/tools/dataapi.d.ts +42 -0
  119. package/dist/toolkits/neon/tools/dataapi.js +111 -0
  120. package/dist/toolkits/neon/tools/endpoints.d.ts +59 -0
  121. package/dist/toolkits/neon/tools/endpoints.js +163 -0
  122. package/dist/toolkits/neon/tools/index.d.ts +976 -0
  123. package/dist/toolkits/neon/tools/index.js +130 -0
  124. package/dist/toolkits/neon/tools/meta.d.ts +4 -0
  125. package/dist/toolkits/neon/tools/meta.js +16 -0
  126. package/dist/toolkits/neon/tools/orgs.d.ts +112 -0
  127. package/dist/toolkits/neon/tools/orgs.js +303 -0
  128. package/dist/toolkits/neon/tools/projects.d.ts +177 -0
  129. package/dist/toolkits/neon/tools/projects.js +468 -0
  130. package/dist/toolkits/neon/tools/snapshots.d.ts +24 -0
  131. package/dist/toolkits/neon/tools/snapshots.js +67 -0
  132. package/package.json +1 -1
@@ -0,0 +1,270 @@
1
+ // @ts-nocheck
2
+ const ATLASSIAN_API = 'https://api.atlassian.com';
3
+ const cloudCache = new Map();
4
+ export async function getCloudId(token, hint) {
5
+ if (hint)
6
+ return hint;
7
+ if (cloudCache.has(token))
8
+ return cloudCache.get(token);
9
+ const response = await fetch(`${ATLASSIAN_API}/oauth/token/accessible-resources`, {
10
+ headers: { Authorization: `Bearer ${token}`, Accept: 'application/json' },
11
+ });
12
+ if (!response.ok)
13
+ return null;
14
+ const sites = await response.json().catch(() => []);
15
+ const id = Array.isArray(sites) && sites.length > 0 ? sites[0].id : null;
16
+ if (id)
17
+ cloudCache.set(token, id);
18
+ return id;
19
+ }
20
+ function withQuery(url, query = {}) {
21
+ const params = new URLSearchParams();
22
+ for (const [key, value] of Object.entries(query)) {
23
+ if (value === undefined || value === null || value === '')
24
+ continue;
25
+ if (Array.isArray(value)) {
26
+ if (value.length === 0)
27
+ continue;
28
+ params.append(key, value.join(','));
29
+ }
30
+ else {
31
+ params.append(key, String(value));
32
+ }
33
+ }
34
+ const qs = params.toString();
35
+ return qs ? `${url}?${qs}` : url;
36
+ }
37
+ async function parseBody(response) {
38
+ const text = await response.text();
39
+ if (!text)
40
+ return { success: true };
41
+ try {
42
+ return JSON.parse(text);
43
+ }
44
+ catch {
45
+ return { raw: text };
46
+ }
47
+ }
48
+ export async function jira(token, { cloudId, api = 'api/3', path, method = 'GET', query, body, headers = {} }) {
49
+ if (!token)
50
+ return { error: 'Jira token is required. Connect Jira first.' };
51
+ const cid = await getCloudId(token, cloudId);
52
+ if (!cid)
53
+ return { error: 'Could not determine your Jira Cloud site. Reconnect Jira and try again.' };
54
+ const url = withQuery(`${ATLASSIAN_API}/ex/jira/${cid}/rest/${api}${path}`, query);
55
+ try {
56
+ const response = await fetch(url, {
57
+ method,
58
+ headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json', Accept: 'application/json', ...headers },
59
+ body: body !== undefined ? (typeof body === 'string' ? body : JSON.stringify(body)) : undefined,
60
+ });
61
+ if (!response.ok) {
62
+ const details = await parseBody(response).catch(() => ({}));
63
+ return { error: `Jira API request failed with status ${response.status}`, details };
64
+ }
65
+ if (response.status === 204)
66
+ return { success: true };
67
+ return await parseBody(response);
68
+ }
69
+ catch (error) {
70
+ return { error: 'Error calling Jira API', message: error instanceof Error ? error.message : 'Unknown error' };
71
+ }
72
+ }
73
+ // --- Markdown subset to Atlassian Document Format ---
74
+ function inlineNodes(text) {
75
+ const nodes = [];
76
+ const pattern = /(\*\*.+?\*\*|__.+?__|\*[^*]+?\*|_[^_]+?_|`[^`]+?`|\[[^\]]+?\]\([^)]+?\))/g;
77
+ let last = 0;
78
+ let match;
79
+ const pushText = (t) => {
80
+ if (t)
81
+ nodes.push({ type: 'text', text: t });
82
+ };
83
+ while ((match = pattern.exec(text)) !== null) {
84
+ pushText(text.slice(last, match.index));
85
+ const tok = match[0];
86
+ if (tok.startsWith('**') || tok.startsWith('__')) {
87
+ nodes.push({ type: 'text', text: tok.slice(2, -2), marks: [{ type: 'strong' }] });
88
+ }
89
+ else if (tok.startsWith('*') || tok.startsWith('_')) {
90
+ nodes.push({ type: 'text', text: tok.slice(1, -1), marks: [{ type: 'em' }] });
91
+ }
92
+ else if (tok.startsWith('`')) {
93
+ nodes.push({ type: 'text', text: tok.slice(1, -1), marks: [{ type: 'code' }] });
94
+ }
95
+ else {
96
+ const m = /^\[([^\]]+?)\]\(([^)]+?)\)$/.exec(tok);
97
+ if (m)
98
+ nodes.push({ type: 'text', text: m[1], marks: [{ type: 'link', attrs: { href: m[2] } }] });
99
+ else
100
+ pushText(tok);
101
+ }
102
+ last = match.index + tok.length;
103
+ }
104
+ pushText(text.slice(last));
105
+ return nodes.length > 0 ? nodes : [{ type: 'text', text }];
106
+ }
107
+ export function mdToAdf(input) {
108
+ if (input === undefined || input === null)
109
+ return undefined;
110
+ if (typeof input !== 'string')
111
+ return input;
112
+ const lines = input.split('\n');
113
+ const content = [];
114
+ let i = 0;
115
+ const para = (t) => ({ type: 'paragraph', content: inlineNodes(t) });
116
+ while (i < lines.length) {
117
+ const line = lines[i];
118
+ if (/^\s*$/.test(line)) {
119
+ i++;
120
+ continue;
121
+ }
122
+ const fence = /^```(\w*)\s*$/.exec(line);
123
+ if (fence) {
124
+ const buf = [];
125
+ i++;
126
+ while (i < lines.length && !/^```\s*$/.test(lines[i]))
127
+ buf.push(lines[i++]);
128
+ i++;
129
+ content.push({ type: 'codeBlock', attrs: fence[1] ? { language: fence[1] } : {}, content: [{ type: 'text', text: buf.join('\n') }] });
130
+ continue;
131
+ }
132
+ const heading = /^(#{1,6})\s+(.*)$/.exec(line);
133
+ if (heading) {
134
+ content.push({ type: 'heading', attrs: { level: heading[1].length }, content: inlineNodes(heading[2]) });
135
+ i++;
136
+ continue;
137
+ }
138
+ const quote = /^>\s?(.*)$/.exec(line);
139
+ if (quote) {
140
+ const buf = [quote[1]];
141
+ i++;
142
+ while (i < lines.length && /^>\s?(.*)$/.test(lines[i]))
143
+ buf.push(/^>\s?(.*)$/.exec(lines[i])[1]), i++;
144
+ content.push({ type: 'blockquote', content: buf.map((t) => para(t)) });
145
+ continue;
146
+ }
147
+ const bullet = /^\s*[-*+]\s+(.*)$/.exec(line);
148
+ if (bullet) {
149
+ const items = [];
150
+ while (i < lines.length) {
151
+ const m = /^\s*[-*+]\s+(.*)$/.exec(lines[i]);
152
+ if (!m)
153
+ break;
154
+ items.push({ type: 'listItem', content: [para(m[1])] });
155
+ i++;
156
+ }
157
+ content.push({ type: 'bulletList', content: items });
158
+ continue;
159
+ }
160
+ const ordered = /^\s*\d+[.)]\s+(.*)$/.exec(line);
161
+ if (ordered) {
162
+ const items = [];
163
+ while (i < lines.length) {
164
+ const m = /^\s*\d+[.)]\s+(.*)$/.exec(lines[i]);
165
+ if (!m)
166
+ break;
167
+ items.push({ type: 'listItem', content: [para(m[1])] });
168
+ i++;
169
+ }
170
+ content.push({ type: 'orderedList', content: items });
171
+ continue;
172
+ }
173
+ content.push(para(line));
174
+ i++;
175
+ }
176
+ return { type: 'doc', version: 1, content: content.length > 0 ? content : [para('')] };
177
+ }
178
+ // --- lookups ---
179
+ export async function findAccountId(token, cloudId, nameOrEmail) {
180
+ if (!nameOrEmail)
181
+ return null;
182
+ const users = await jira(token, { cloudId, path: '/user/search', query: { query: nameOrEmail, maxResults: 5 } });
183
+ if (!Array.isArray(users) || users.length === 0)
184
+ return null;
185
+ const human = users.find((u) => u.accountType !== 'app') ?? users[0];
186
+ return human?.accountId ?? null;
187
+ }
188
+ export async function resolveAssignee(token, cloudId, accountId, nameOrEmail) {
189
+ if (accountId)
190
+ return accountId;
191
+ if (!nameOrEmail)
192
+ return undefined;
193
+ return (await findAccountId(token, cloudId, nameOrEmail)) ?? undefined;
194
+ }
195
+ export async function getTransitionId(token, cloudId, issueIdOrKey, idOrName) {
196
+ if (/^\d+$/.test(String(idOrName)))
197
+ return String(idOrName);
198
+ const data = await jira(token, { cloudId, path: `/issue/${encodeURIComponent(issueIdOrKey)}/transitions` });
199
+ const list = data?.transitions ?? [];
200
+ const hit = list.find((t) => t.name?.toLowerCase() === String(idOrName).toLowerCase());
201
+ return hit ? String(hit.id) : null;
202
+ }
203
+ export async function uploadAttachment(token, cloudId, issueKey, { fileName, fileContent, mimeType }) {
204
+ if (!token)
205
+ return { error: 'Jira token is required. Connect Jira first.' };
206
+ const cid = await getCloudId(token, cloudId);
207
+ if (!cid)
208
+ return { error: 'Could not determine your Jira Cloud site. Reconnect Jira and try again.' };
209
+ try {
210
+ const bytes = Buffer.from(fileContent, 'base64');
211
+ const form = new FormData();
212
+ form.append('file', new Blob([bytes], { type: mimeType ?? 'application/octet-stream' }), fileName);
213
+ const response = await fetch(`${ATLASSIAN_API}/ex/jira/${cid}/rest/api/3/issue/${encodeURIComponent(issueKey)}/attachments`, {
214
+ method: 'POST',
215
+ headers: { Authorization: `Bearer ${token}`, Accept: 'application/json', 'X-Atlassian-Token': 'no-check' },
216
+ body: form,
217
+ });
218
+ if (!response.ok) {
219
+ const details = await parseBody(response).catch(() => ({}));
220
+ return { error: `Jira API request failed with status ${response.status}`, details };
221
+ }
222
+ return await parseBody(response);
223
+ }
224
+ catch (error) {
225
+ return { error: 'Error uploading attachment to Jira', message: error instanceof Error ? error.message : 'Unknown error' };
226
+ }
227
+ }
228
+ // --- structured-filter search to JQL ---
229
+ function qv(value, numeric = false) {
230
+ if (value === undefined || value === null)
231
+ return null;
232
+ if (numeric && /^-?\d+$/.test(String(value)))
233
+ return String(value);
234
+ return `"${String(value).replace(/"/g, '\\"')}"`;
235
+ }
236
+ export function buildSearchJql(f) {
237
+ const clauses = [];
238
+ if (f.projectKey)
239
+ clauses.push(`project = ${qv(f.projectKey)}`);
240
+ if (f.assignee) {
241
+ if (f.assignee === 'unassigned')
242
+ clauses.push('assignee is EMPTY');
243
+ else
244
+ clauses.push(`assignee = ${qv(f.assignee)}`);
245
+ }
246
+ if (f.statusIdOrName)
247
+ clauses.push(`status = ${qv(f.statusIdOrName, true)}`);
248
+ if (f.priorityIdOrName)
249
+ clauses.push(`priority = ${qv(f.priorityIdOrName, true)}`);
250
+ if (f.issueTypeIdOrName)
251
+ clauses.push(`issuetype = ${qv(f.issueTypeIdOrName, true)}`);
252
+ if (f.labels && f.labels.length > 0)
253
+ clauses.push(`labels in (${f.labels.map((l) => qv(l)).join(', ')})`);
254
+ if (f.textSearch)
255
+ clauses.push(`text ~ ${qv(f.textSearch)}`);
256
+ if (f.sprintIdOrName)
257
+ clauses.push(`sprint = ${qv(f.sprintIdOrName, true)}`);
258
+ const date = (field, v) => (v ? `${field} >= ${qv(v)}` : null);
259
+ const dateBefore = (field, v) => (v ? `${field} <= ${qv(v)}` : null);
260
+ for (const c of [date('created', f.createdAfter), date('updated', f.updatedAfter), dateBefore('created', f.createdBefore), dateBefore('updated', f.updatedBefore)]) {
261
+ if (c)
262
+ clauses.push(c);
263
+ }
264
+ let jql = clauses.join(' AND ');
265
+ if (f.preservedOrderBy)
266
+ jql += (jql ? ' ' : '') + f.preservedOrderBy;
267
+ return jql;
268
+ }
269
+ export { ATLASSIAN_API };
270
+ //# sourceMappingURL=client.js.map