@augno/sdk-mcp 0.10.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.
- package/LICENSE +201 -0
- package/README.md +103 -0
- package/auth.d.mts +6 -0
- package/auth.d.mts.map +1 -0
- package/auth.d.ts +6 -0
- package/auth.d.ts.map +1 -0
- package/auth.js +37 -0
- package/auth.js.map +1 -0
- package/auth.mjs +32 -0
- package/auth.mjs.map +1 -0
- package/code-tool-paths.cjs +8 -0
- package/code-tool-paths.cjs.map +1 -0
- package/code-tool-paths.d.cts +2 -0
- package/code-tool-paths.d.cts.map +1 -0
- package/code-tool-types.d.mts +14 -0
- package/code-tool-types.d.mts.map +1 -0
- package/code-tool-types.d.ts +14 -0
- package/code-tool-types.d.ts.map +1 -0
- package/code-tool-types.js +4 -0
- package/code-tool-types.js.map +1 -0
- package/code-tool-types.mjs +3 -0
- package/code-tool-types.mjs.map +1 -0
- package/code-tool-worker.d.mts +5 -0
- package/code-tool-worker.d.mts.map +1 -0
- package/code-tool-worker.d.ts +5 -0
- package/code-tool-worker.d.ts.map +1 -0
- package/code-tool-worker.js +486 -0
- package/code-tool-worker.js.map +1 -0
- package/code-tool-worker.mjs +448 -0
- package/code-tool-worker.mjs.map +1 -0
- package/code-tool.d.mts +21 -0
- package/code-tool.d.mts.map +1 -0
- package/code-tool.d.ts +21 -0
- package/code-tool.d.ts.map +1 -0
- package/code-tool.js +287 -0
- package/code-tool.js.map +1 -0
- package/code-tool.mjs +251 -0
- package/code-tool.mjs.map +1 -0
- package/http.d.mts +12 -0
- package/http.d.mts.map +1 -0
- package/http.d.ts +12 -0
- package/http.d.ts.map +1 -0
- package/http.js +190 -0
- package/http.js.map +1 -0
- package/http.mjs +182 -0
- package/http.mjs.map +1 -0
- package/index.d.mts +3 -0
- package/index.d.mts.map +1 -0
- package/index.d.ts +3 -0
- package/index.d.ts.map +1 -0
- package/index.js +60 -0
- package/index.js.map +1 -0
- package/index.mjs +58 -0
- package/index.mjs.map +1 -0
- package/instructions.d.mts +5 -0
- package/instructions.d.mts.map +1 -0
- package/instructions.d.ts +5 -0
- package/instructions.d.ts.map +1 -0
- package/instructions.js +47 -0
- package/instructions.js.map +1 -0
- package/instructions.mjs +41 -0
- package/instructions.mjs.map +1 -0
- package/logger.d.mts +7 -0
- package/logger.d.mts.map +1 -0
- package/logger.d.ts +7 -0
- package/logger.d.ts.map +1 -0
- package/logger.js +29 -0
- package/logger.js.map +1 -0
- package/logger.mjs +22 -0
- package/logger.mjs.map +1 -0
- package/methods.d.mts +10 -0
- package/methods.d.mts.map +1 -0
- package/methods.d.ts +10 -0
- package/methods.d.ts.map +1 -0
- package/methods.js +1385 -0
- package/methods.js.map +1 -0
- package/methods.mjs +1381 -0
- package/methods.mjs.map +1 -0
- package/options.d.mts +20 -0
- package/options.d.mts.map +1 -0
- package/options.d.ts +20 -0
- package/options.d.ts.map +1 -0
- package/options.js +121 -0
- package/options.js.map +1 -0
- package/options.mjs +114 -0
- package/options.mjs.map +1 -0
- package/package.json +216 -0
- package/server.d.mts +38 -0
- package/server.d.mts.map +1 -0
- package/server.d.ts +38 -0
- package/server.d.ts.map +1 -0
- package/server.js +162 -0
- package/server.js.map +1 -0
- package/server.mjs +152 -0
- package/server.mjs.map +1 -0
- package/src/auth.ts +42 -0
- package/src/code-tool-paths.cts +5 -0
- package/src/code-tool-types.ts +17 -0
- package/src/code-tool-worker.ts +499 -0
- package/src/code-tool.ts +316 -0
- package/src/http.ts +227 -0
- package/src/index.ts +67 -0
- package/src/instructions.ts +59 -0
- package/src/logger.ts +28 -0
- package/src/methods.ts +1406 -0
- package/src/options.ts +159 -0
- package/src/server.ts +202 -0
- package/src/stdio.ts +17 -0
- package/src/tsconfig.json +11 -0
- package/src/types.ts +126 -0
- package/src/util.ts +25 -0
- package/stdio.d.mts +3 -0
- package/stdio.d.mts.map +1 -0
- package/stdio.d.ts +3 -0
- package/stdio.d.ts.map +1 -0
- package/stdio.js +18 -0
- package/stdio.js.map +1 -0
- package/stdio.mjs +14 -0
- package/stdio.mjs.map +1 -0
- package/types.d.mts +65 -0
- package/types.d.mts.map +1 -0
- package/types.d.ts +65 -0
- package/types.d.ts.map +1 -0
- package/types.js +58 -0
- package/types.js.map +1 -0
- package/types.mjs +53 -0
- package/types.mjs.map +1 -0
- package/util.d.mts +4 -0
- package/util.d.mts.map +1 -0
- package/util.d.ts +4 -0
- package/util.d.ts.map +1 -0
- package/util.js +30 -0
- package/util.js.map +1 -0
- package/util.mjs +24 -0
- package/util.mjs.map +1 -0
|
@@ -0,0 +1,499 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import util from 'node:util';
|
|
5
|
+
import Fuse from 'fuse.js';
|
|
6
|
+
import ts from 'typescript';
|
|
7
|
+
import { WorkerOutput } from './code-tool-types';
|
|
8
|
+
import { Augno, ClientOptions } from '@augno/sdk';
|
|
9
|
+
|
|
10
|
+
async function tseval(code: string) {
|
|
11
|
+
return import('data:application/typescript;charset=utf-8;base64,' + Buffer.from(code).toString('base64'));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function getRunFunctionSource(code: string): {
|
|
15
|
+
type: 'declaration' | 'expression';
|
|
16
|
+
client: string | undefined;
|
|
17
|
+
code: string;
|
|
18
|
+
} | null {
|
|
19
|
+
const sourceFile = ts.createSourceFile('code.ts', code, ts.ScriptTarget.Latest, true);
|
|
20
|
+
const printer = ts.createPrinter();
|
|
21
|
+
|
|
22
|
+
for (const statement of sourceFile.statements) {
|
|
23
|
+
// Check for top-level function declarations
|
|
24
|
+
if (ts.isFunctionDeclaration(statement)) {
|
|
25
|
+
if (statement.name?.text === 'run') {
|
|
26
|
+
return {
|
|
27
|
+
type: 'declaration',
|
|
28
|
+
client: statement.parameters[0]?.name.getText(),
|
|
29
|
+
code: printer.printNode(ts.EmitHint.Unspecified, statement.body!, sourceFile),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Check for variable declarations: const run = () => {} or const run = function() {}
|
|
35
|
+
if (ts.isVariableStatement(statement)) {
|
|
36
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
37
|
+
if (
|
|
38
|
+
ts.isIdentifier(declaration.name) &&
|
|
39
|
+
declaration.name.text === 'run' &&
|
|
40
|
+
// Check if it's initialized with a function
|
|
41
|
+
declaration.initializer &&
|
|
42
|
+
(ts.isFunctionExpression(declaration.initializer) || ts.isArrowFunction(declaration.initializer))
|
|
43
|
+
) {
|
|
44
|
+
return {
|
|
45
|
+
type: 'expression',
|
|
46
|
+
client: declaration.initializer.parameters[0]?.name.getText(),
|
|
47
|
+
code: printer.printNode(ts.EmitHint.Unspecified, declaration.initializer, sourceFile),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function getTSDiagnostics(code: string): string[] {
|
|
58
|
+
const functionSource = getRunFunctionSource(code)!;
|
|
59
|
+
const codeWithImport = [
|
|
60
|
+
'import { Augno } from "@augno/sdk";',
|
|
61
|
+
functionSource.type === 'declaration' ?
|
|
62
|
+
`async function run(${functionSource.client}: Augno)`
|
|
63
|
+
: `const run: (${functionSource.client}: Augno) => Promise<unknown> =`,
|
|
64
|
+
functionSource.code,
|
|
65
|
+
].join('\n');
|
|
66
|
+
const sourcePath = path.resolve('code.ts');
|
|
67
|
+
const ast = ts.createSourceFile(sourcePath, codeWithImport, ts.ScriptTarget.Latest, true);
|
|
68
|
+
const options = ts.getDefaultCompilerOptions();
|
|
69
|
+
options.target = ts.ScriptTarget.Latest;
|
|
70
|
+
options.module = ts.ModuleKind.NodeNext;
|
|
71
|
+
options.moduleResolution = ts.ModuleResolutionKind.NodeNext;
|
|
72
|
+
const host = ts.createCompilerHost(options, true);
|
|
73
|
+
const newHost: typeof host = {
|
|
74
|
+
...host,
|
|
75
|
+
getSourceFile: (...args) => {
|
|
76
|
+
if (path.resolve(args[0]) === sourcePath) {
|
|
77
|
+
return ast;
|
|
78
|
+
}
|
|
79
|
+
return host.getSourceFile(...args);
|
|
80
|
+
},
|
|
81
|
+
readFile: (...args) => {
|
|
82
|
+
if (path.resolve(args[0]) === sourcePath) {
|
|
83
|
+
return codeWithImport;
|
|
84
|
+
}
|
|
85
|
+
return host.readFile(...args);
|
|
86
|
+
},
|
|
87
|
+
fileExists: (...args) => {
|
|
88
|
+
if (path.resolve(args[0]) === sourcePath) {
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
return host.fileExists(...args);
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
const program = ts.createProgram({
|
|
95
|
+
options,
|
|
96
|
+
rootNames: [sourcePath],
|
|
97
|
+
host: newHost,
|
|
98
|
+
});
|
|
99
|
+
const diagnostics = ts.getPreEmitDiagnostics(program, ast);
|
|
100
|
+
return diagnostics.map((d) => {
|
|
101
|
+
const message = ts.flattenDiagnosticMessageText(d.messageText, '\n');
|
|
102
|
+
if (!d.file || !d.start) return `- ${message}`;
|
|
103
|
+
const { line: lineNumber } = ts.getLineAndCharacterOfPosition(d.file, d.start);
|
|
104
|
+
const line = codeWithImport.split('\n').at(lineNumber)?.trim();
|
|
105
|
+
return line ? `- ${message}\n ${line}` : `- ${message}`;
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const fuse = new Fuse(
|
|
110
|
+
[
|
|
111
|
+
'client.auth.apiKeys.create',
|
|
112
|
+
'client.auth.apiKeys.delete',
|
|
113
|
+
'client.auth.apiKeys.list',
|
|
114
|
+
'client.auth.apiKeys.retrieve',
|
|
115
|
+
'client.auth.apiKeys.actions.rotate',
|
|
116
|
+
'client.core.retrieveSearch',
|
|
117
|
+
'client.core.sandboxes.create',
|
|
118
|
+
'client.core.sandboxes.delete',
|
|
119
|
+
'client.core.sandboxes.list',
|
|
120
|
+
'client.core.sandboxes.retrieve',
|
|
121
|
+
'client.core.requestLogs.list',
|
|
122
|
+
'client.core.requestLogs.retrieve',
|
|
123
|
+
'client.core.auditEvents.list',
|
|
124
|
+
'client.core.auditEvents.retrieve',
|
|
125
|
+
'client.core.auditEvents.retrieveResourceTypes',
|
|
126
|
+
'client.core.addresses.retrieveSuggestions',
|
|
127
|
+
'client.core.addresses.actions.validate',
|
|
128
|
+
'client.core.emailLogs.list',
|
|
129
|
+
'client.core.emailLogs.retrieve',
|
|
130
|
+
'client.catalog.units.create',
|
|
131
|
+
'client.catalog.units.delete',
|
|
132
|
+
'client.catalog.units.list',
|
|
133
|
+
'client.catalog.units.retrieve',
|
|
134
|
+
'client.catalog.units.update',
|
|
135
|
+
'client.catalog.unitGroups.create',
|
|
136
|
+
'client.catalog.unitGroups.delete',
|
|
137
|
+
'client.catalog.unitGroups.list',
|
|
138
|
+
'client.catalog.unitGroups.retrieve',
|
|
139
|
+
'client.catalog.unitGroups.update',
|
|
140
|
+
'client.catalog.unitGroups.units.create',
|
|
141
|
+
'client.catalog.unitGroups.units.delete',
|
|
142
|
+
'client.catalog.unitGroups.units.list',
|
|
143
|
+
'client.catalog.unitGroups.units.retrieve',
|
|
144
|
+
'client.catalog.unitGroups.units.update',
|
|
145
|
+
'client.catalog.properties.create',
|
|
146
|
+
'client.catalog.properties.delete',
|
|
147
|
+
'client.catalog.properties.list',
|
|
148
|
+
'client.catalog.properties.retrieve',
|
|
149
|
+
'client.catalog.properties.update',
|
|
150
|
+
'client.catalog.properties.attributes.create',
|
|
151
|
+
'client.catalog.properties.attributes.delete',
|
|
152
|
+
'client.catalog.properties.attributes.list',
|
|
153
|
+
'client.catalog.properties.attributes.retrieve',
|
|
154
|
+
'client.catalog.properties.attributes.update',
|
|
155
|
+
'client.catalog.items.changeCategory',
|
|
156
|
+
'client.catalog.items.list',
|
|
157
|
+
'client.catalog.items.retrieve',
|
|
158
|
+
'client.catalog.items.retrieveInventory',
|
|
159
|
+
'client.catalog.items.attributes.delete',
|
|
160
|
+
'client.catalog.items.attributes.update',
|
|
161
|
+
'client.catalog.itemCategories.changeUnitGroup',
|
|
162
|
+
'client.catalog.itemCategories.create',
|
|
163
|
+
'client.catalog.itemCategories.delete',
|
|
164
|
+
'client.catalog.itemCategories.list',
|
|
165
|
+
'client.catalog.itemCategories.retrieve',
|
|
166
|
+
'client.catalog.itemCategories.update',
|
|
167
|
+
'client.catalog.itemCategories.properties.delete',
|
|
168
|
+
'client.catalog.itemCategories.properties.update',
|
|
169
|
+
'client.catalog.materials.create',
|
|
170
|
+
'client.catalog.materials.delete',
|
|
171
|
+
'client.catalog.materials.list',
|
|
172
|
+
'client.catalog.materials.retrieve',
|
|
173
|
+
'client.catalog.materials.update',
|
|
174
|
+
'client.catalog.parts.create',
|
|
175
|
+
'client.catalog.parts.delete',
|
|
176
|
+
'client.catalog.parts.list',
|
|
177
|
+
'client.catalog.parts.retrieve',
|
|
178
|
+
'client.catalog.parts.update',
|
|
179
|
+
'client.catalog.productLines.create',
|
|
180
|
+
'client.catalog.productLines.delete',
|
|
181
|
+
'client.catalog.productLines.list',
|
|
182
|
+
'client.catalog.productLines.retrieve',
|
|
183
|
+
'client.catalog.productLines.update',
|
|
184
|
+
'client.catalog.products.changeProductLine',
|
|
185
|
+
'client.catalog.products.create',
|
|
186
|
+
'client.catalog.products.delete',
|
|
187
|
+
'client.catalog.products.list',
|
|
188
|
+
'client.catalog.products.retrieve',
|
|
189
|
+
'client.catalog.products.update',
|
|
190
|
+
'client.messaging.retrieveContacts',
|
|
191
|
+
'client.messaging.notifications.create',
|
|
192
|
+
'client.messaging.notifications.list',
|
|
193
|
+
'client.messaging.notifications.retrieve',
|
|
194
|
+
'client.messaging.notifications.retrieveUnreadCount',
|
|
195
|
+
'client.messaging.notifications.retrieveUnreadSummary',
|
|
196
|
+
'client.messaging.notifications.actions.dismiss',
|
|
197
|
+
'client.messaging.notifications.actions.markAllSeen',
|
|
198
|
+
'client.messaging.notifications.actions.read',
|
|
199
|
+
'client.messaging.notifications.actions.seen',
|
|
200
|
+
'client.messaging.announcements.list',
|
|
201
|
+
'client.messaging.announcements.retrieve',
|
|
202
|
+
'client.messaging.announcements.actions.dismiss',
|
|
203
|
+
'client.messaging.announcements.actions.read',
|
|
204
|
+
'client.messaging.announcements.actions.seen',
|
|
205
|
+
'client.messaging.conversations.create',
|
|
206
|
+
'client.messaging.conversations.list',
|
|
207
|
+
'client.messaging.conversations.retrieve',
|
|
208
|
+
'client.messaging.conversations.update',
|
|
209
|
+
'client.messaging.conversations.actions.archive',
|
|
210
|
+
'client.messaging.conversations.actions.assign',
|
|
211
|
+
'client.messaging.conversations.actions.hide',
|
|
212
|
+
'client.messaging.conversations.actions.leave',
|
|
213
|
+
'client.messaging.conversations.actions.mute',
|
|
214
|
+
'client.messaging.conversations.actions.read',
|
|
215
|
+
'client.messaging.conversations.actions.redact',
|
|
216
|
+
'client.messaging.conversations.actions.report',
|
|
217
|
+
'client.messaging.conversations.actions.setLegalHold',
|
|
218
|
+
'client.messaging.conversations.actions.setStatus',
|
|
219
|
+
'client.messaging.conversations.actions.unarchive',
|
|
220
|
+
'client.messaging.conversations.actions.unhide',
|
|
221
|
+
'client.messaging.conversations.actions.unmute',
|
|
222
|
+
'client.messaging.conversations.links.create',
|
|
223
|
+
'client.messaging.conversations.links.delete',
|
|
224
|
+
'client.messaging.conversations.links.list',
|
|
225
|
+
'client.messaging.conversations.messages.create',
|
|
226
|
+
'client.messaging.conversations.messages.list',
|
|
227
|
+
'client.messaging.conversations.participants.create',
|
|
228
|
+
'client.messaging.conversations.participants.delete',
|
|
229
|
+
'client.messaging.conversations.participants.actions.setRole',
|
|
230
|
+
'client.messaging.conversations.attachments.actions.uploadURL',
|
|
231
|
+
'client.messaging.messages.update',
|
|
232
|
+
'client.messaging.messages.actions.approveSend',
|
|
233
|
+
'client.messaging.messages.actions.cancel',
|
|
234
|
+
'client.messaging.messages.actions.reject',
|
|
235
|
+
'client.messaging.groups.create',
|
|
236
|
+
'client.messaging.groups.delete',
|
|
237
|
+
'client.messaging.groups.list',
|
|
238
|
+
'client.messaging.groups.retrieve',
|
|
239
|
+
'client.messaging.groups.update',
|
|
240
|
+
'client.messaging.groups.members.create',
|
|
241
|
+
'client.messaging.groups.members.delete',
|
|
242
|
+
'client.messaging.blocks.create',
|
|
243
|
+
'client.messaging.blocks.delete',
|
|
244
|
+
'client.messaging.blocks.list',
|
|
245
|
+
'client.messaging.preferences.list',
|
|
246
|
+
'client.messaging.preferences.update',
|
|
247
|
+
'client.messaging.emailDomains.create',
|
|
248
|
+
'client.messaging.emailDomains.list',
|
|
249
|
+
'client.messaging.emailDomains.retrieve',
|
|
250
|
+
'client.messaging.emailDomains.actions.verify',
|
|
251
|
+
'client.messaging.emailInboxes.create',
|
|
252
|
+
'client.messaging.emailInboxes.delete',
|
|
253
|
+
'client.messaging.emailInboxes.list',
|
|
254
|
+
'client.messaging.emailInboxes.retrieve',
|
|
255
|
+
'client.messaging.emailInboxes.update',
|
|
256
|
+
'client.sales.accountGroups.create',
|
|
257
|
+
'client.sales.accountGroups.delete',
|
|
258
|
+
'client.sales.accountGroups.list',
|
|
259
|
+
'client.sales.accountGroups.retrieve',
|
|
260
|
+
'client.sales.accountGroups.update',
|
|
261
|
+
'client.sales.addresses.create',
|
|
262
|
+
'client.sales.addresses.delete',
|
|
263
|
+
'client.sales.addresses.list',
|
|
264
|
+
'client.sales.addresses.retrieve',
|
|
265
|
+
'client.sales.addresses.update',
|
|
266
|
+
'client.sales.accountStatuses.list',
|
|
267
|
+
'client.sales.accountStatuses.retrieve',
|
|
268
|
+
'client.sales.priorities.list',
|
|
269
|
+
'client.sales.priorities.retrieve',
|
|
270
|
+
'client.sales.customers.create',
|
|
271
|
+
'client.sales.customers.delete',
|
|
272
|
+
'client.sales.customers.list',
|
|
273
|
+
'client.sales.customers.retrieve',
|
|
274
|
+
'client.sales.customers.update',
|
|
275
|
+
'client.sales.customers.actions.merge',
|
|
276
|
+
'client.sales.contacts.actions.findByEmail',
|
|
277
|
+
'client.sales.salesOrders.create',
|
|
278
|
+
'client.sales.salesOrders.list',
|
|
279
|
+
'client.sales.salesOrders.retrieveStatuses',
|
|
280
|
+
'client.finance.retrieveAdjustmentTypes',
|
|
281
|
+
'client.finance.retrieveTransactionMethods',
|
|
282
|
+
'client.finance.retrieveTransactionTypes',
|
|
283
|
+
'client.finance.paymentTerms.create',
|
|
284
|
+
'client.finance.paymentTerms.delete',
|
|
285
|
+
'client.finance.paymentTerms.list',
|
|
286
|
+
'client.finance.paymentTerms.retrieve',
|
|
287
|
+
'client.finance.paymentTerms.update',
|
|
288
|
+
'client.operations.shippingTerms.create',
|
|
289
|
+
'client.operations.shippingTerms.delete',
|
|
290
|
+
'client.operations.shippingTerms.list',
|
|
291
|
+
'client.operations.shippingTerms.retrieve',
|
|
292
|
+
'client.operations.shippingTerms.update',
|
|
293
|
+
'client.operations.carriers.create',
|
|
294
|
+
'client.operations.carriers.delete',
|
|
295
|
+
'client.operations.carriers.list',
|
|
296
|
+
'client.operations.carriers.retrieve',
|
|
297
|
+
'client.operations.carriers.update',
|
|
298
|
+
'client.operations.carriers.serviceLevels.create',
|
|
299
|
+
'client.operations.carriers.serviceLevels.delete',
|
|
300
|
+
'client.operations.carriers.serviceLevels.list',
|
|
301
|
+
'client.operations.carriers.serviceLevels.retrieve',
|
|
302
|
+
'client.operations.carriers.serviceLevels.update',
|
|
303
|
+
'client.operations.locations.create',
|
|
304
|
+
'client.operations.locations.delete',
|
|
305
|
+
'client.operations.locations.list',
|
|
306
|
+
'client.operations.locations.retrieve',
|
|
307
|
+
'client.operations.locations.update',
|
|
308
|
+
'client.operations.locationTypes.list',
|
|
309
|
+
'client.operations.locationTypes.retrieve',
|
|
310
|
+
'client.operations.scanningStations.create',
|
|
311
|
+
'client.operations.scanningStations.delete',
|
|
312
|
+
'client.operations.scanningStations.list',
|
|
313
|
+
'client.operations.scanningStations.retrieve',
|
|
314
|
+
'client.operations.scanningStations.update',
|
|
315
|
+
'client.identity.accountUsers.create',
|
|
316
|
+
'client.identity.accountUsers.list',
|
|
317
|
+
'client.identity.accountUsers.retrieve',
|
|
318
|
+
'client.identity.accountUsers.update',
|
|
319
|
+
'client.identity.accountUsers.actions.activate',
|
|
320
|
+
'client.identity.accountUsers.actions.disable',
|
|
321
|
+
'client.identity.accountUsers.actions.remove',
|
|
322
|
+
'client.identity.roles.create',
|
|
323
|
+
'client.identity.roles.delete',
|
|
324
|
+
'client.identity.roles.list',
|
|
325
|
+
'client.identity.roles.retrieve',
|
|
326
|
+
'client.identity.roles.update',
|
|
327
|
+
'client.settings.integrations.create',
|
|
328
|
+
'client.settings.integrations.delete',
|
|
329
|
+
'client.settings.integrations.list',
|
|
330
|
+
'client.settings.integrations.update',
|
|
331
|
+
],
|
|
332
|
+
{ threshold: 1, shouldSort: true },
|
|
333
|
+
);
|
|
334
|
+
|
|
335
|
+
function getMethodSuggestions(fullyQualifiedMethodName: string): string[] {
|
|
336
|
+
return fuse
|
|
337
|
+
.search(fullyQualifiedMethodName)
|
|
338
|
+
.map(({ item }) => item)
|
|
339
|
+
.slice(0, 5);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
const proxyToObj = new WeakMap<any, any>();
|
|
343
|
+
const objToProxy = new WeakMap<any, any>();
|
|
344
|
+
|
|
345
|
+
type ClientProxyConfig = {
|
|
346
|
+
path: string[];
|
|
347
|
+
isBelievedBad?: boolean;
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
function makeSdkProxy<T extends object>(obj: T, { path, isBelievedBad = false }: ClientProxyConfig): T {
|
|
351
|
+
let proxy: T = objToProxy.get(obj);
|
|
352
|
+
|
|
353
|
+
if (!proxy) {
|
|
354
|
+
proxy = new Proxy(obj, {
|
|
355
|
+
get(target, prop, receiver) {
|
|
356
|
+
const propPath = [...path, String(prop)];
|
|
357
|
+
const value = Reflect.get(target, prop, receiver);
|
|
358
|
+
|
|
359
|
+
if (isBelievedBad || (!(prop in target) && value === undefined)) {
|
|
360
|
+
// If we're accessing a path that doesn't exist, it will probably eventually error.
|
|
361
|
+
// Let's proxy it and mark it bad so that we can control the error message.
|
|
362
|
+
// We proxy an empty class so that an invocation or construction attempt is possible.
|
|
363
|
+
return makeSdkProxy(class {}, { path: propPath, isBelievedBad: true });
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
if (value !== null && (typeof value === 'object' || typeof value === 'function')) {
|
|
367
|
+
return makeSdkProxy(value, { path: propPath, isBelievedBad });
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
return value;
|
|
371
|
+
},
|
|
372
|
+
|
|
373
|
+
apply(target, thisArg, args) {
|
|
374
|
+
if (isBelievedBad || typeof target !== 'function') {
|
|
375
|
+
const fullyQualifiedMethodName = path.join('.');
|
|
376
|
+
const suggestions = getMethodSuggestions(fullyQualifiedMethodName);
|
|
377
|
+
throw new Error(
|
|
378
|
+
`${fullyQualifiedMethodName} is not a function. Did you mean: ${suggestions.join(', ')}`,
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
return Reflect.apply(target, proxyToObj.get(thisArg) ?? thisArg, args);
|
|
383
|
+
},
|
|
384
|
+
|
|
385
|
+
construct(target, args, newTarget) {
|
|
386
|
+
if (isBelievedBad || typeof target !== 'function') {
|
|
387
|
+
const fullyQualifiedMethodName = path.join('.');
|
|
388
|
+
const suggestions = getMethodSuggestions(fullyQualifiedMethodName);
|
|
389
|
+
throw new Error(
|
|
390
|
+
`${fullyQualifiedMethodName} is not a constructor. Did you mean: ${suggestions.join(', ')}`,
|
|
391
|
+
);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
return Reflect.construct(target, args, newTarget);
|
|
395
|
+
},
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
objToProxy.set(obj, proxy);
|
|
399
|
+
proxyToObj.set(proxy, obj);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
return proxy;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
function parseError(code: string, error: unknown): string | undefined {
|
|
406
|
+
if (!(error instanceof Error)) return;
|
|
407
|
+
const cause = error.cause instanceof Error ? `: ${error.cause.message}` : '';
|
|
408
|
+
const message = error.name ? `${error.name}: ${error.message}${cause}` : `${error.message}${cause}`;
|
|
409
|
+
try {
|
|
410
|
+
// Deno uses V8; the first "<anonymous>:LINE:COLUMN" is the top of stack.
|
|
411
|
+
const lineNumber = error.stack?.match(/<anonymous>:([0-9]+):[0-9]+/)?.[1];
|
|
412
|
+
// -1 for the zero-based indexing
|
|
413
|
+
const line =
|
|
414
|
+
lineNumber &&
|
|
415
|
+
code
|
|
416
|
+
.split('\n')
|
|
417
|
+
.at(parseInt(lineNumber, 10) - 1)
|
|
418
|
+
?.trim();
|
|
419
|
+
return line ? `${message}\n at line ${lineNumber}\n ${line}` : message;
|
|
420
|
+
} catch {
|
|
421
|
+
return message;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
const fetch = async (req: Request): Promise<Response> => {
|
|
426
|
+
const { opts, code } = (await req.json()) as { opts: ClientOptions; code: string };
|
|
427
|
+
|
|
428
|
+
const runFunctionSource = code ? getRunFunctionSource(code) : null;
|
|
429
|
+
if (!runFunctionSource) {
|
|
430
|
+
const message =
|
|
431
|
+
code ?
|
|
432
|
+
'The code is missing a top-level `run` function.'
|
|
433
|
+
: 'The code argument is missing. Provide one containing a top-level `run` function.';
|
|
434
|
+
return Response.json(
|
|
435
|
+
{
|
|
436
|
+
is_error: true,
|
|
437
|
+
result: `${message} Write code within this template:\n\n\`\`\`\nasync function run(client) {\n // Fill this out\n}\n\`\`\``,
|
|
438
|
+
log_lines: [],
|
|
439
|
+
err_lines: [],
|
|
440
|
+
} satisfies WorkerOutput,
|
|
441
|
+
{ status: 400, statusText: 'Code execution error' },
|
|
442
|
+
);
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
const diagnostics = getTSDiagnostics(code);
|
|
446
|
+
if (diagnostics.length > 0) {
|
|
447
|
+
return Response.json(
|
|
448
|
+
{
|
|
449
|
+
is_error: true,
|
|
450
|
+
result: `The code contains TypeScript diagnostics:\n${diagnostics.join('\n')}`,
|
|
451
|
+
log_lines: [],
|
|
452
|
+
err_lines: [],
|
|
453
|
+
} satisfies WorkerOutput,
|
|
454
|
+
{ status: 400, statusText: 'Code execution error' },
|
|
455
|
+
);
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
const client = new Augno({
|
|
459
|
+
...opts,
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
const log_lines: string[] = [];
|
|
463
|
+
const err_lines: string[] = [];
|
|
464
|
+
const originalConsole = globalThis.console;
|
|
465
|
+
globalThis.console = {
|
|
466
|
+
...originalConsole,
|
|
467
|
+
log: (...args: unknown[]) => {
|
|
468
|
+
log_lines.push(util.format(...args));
|
|
469
|
+
},
|
|
470
|
+
error: (...args: unknown[]) => {
|
|
471
|
+
err_lines.push(util.format(...args));
|
|
472
|
+
},
|
|
473
|
+
};
|
|
474
|
+
try {
|
|
475
|
+
let run_ = async (client: any) => {};
|
|
476
|
+
run_ = (await tseval(`${code}\nexport default run;`)).default;
|
|
477
|
+
const result = await run_(makeSdkProxy(client, { path: ['client'] }));
|
|
478
|
+
return Response.json({
|
|
479
|
+
is_error: false,
|
|
480
|
+
result,
|
|
481
|
+
log_lines,
|
|
482
|
+
err_lines,
|
|
483
|
+
} satisfies WorkerOutput);
|
|
484
|
+
} catch (e) {
|
|
485
|
+
return Response.json(
|
|
486
|
+
{
|
|
487
|
+
is_error: true,
|
|
488
|
+
result: parseError(code, e),
|
|
489
|
+
log_lines,
|
|
490
|
+
err_lines,
|
|
491
|
+
} satisfies WorkerOutput,
|
|
492
|
+
{ status: 400, statusText: 'Code execution error' },
|
|
493
|
+
);
|
|
494
|
+
} finally {
|
|
495
|
+
globalThis.console = originalConsole;
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
|
|
499
|
+
export default { fetch };
|