@epure-sh/cli 0.1.7 → 0.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.
- package/README.md +47 -59
- package/bin/epure-cli.js +2 -357
- package/lib/api-catalog.json +470 -0
- package/lib/api.js +41 -0
- package/lib/auth.js +175 -0
- package/lib/cli.js +146 -0
- package/lib/mcp.js +87 -0
- package/lib/operations.js +83 -0
- package/package.json +3 -2
|
@@ -0,0 +1,470 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"method": "GET",
|
|
4
|
+
"path": "/api/v1/agent/queue"
|
|
5
|
+
},
|
|
6
|
+
{
|
|
7
|
+
"method": "GET",
|
|
8
|
+
"path": "/api/v1/agent/issues/{id}"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"method": "PATCH",
|
|
12
|
+
"path": "/api/v1/agent/issues/{id}"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"method": "GET",
|
|
16
|
+
"path": "/api/v1/agent/issues/{id}/context"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"method": "POST",
|
|
20
|
+
"path": "/api/v1/agent/issues/{id}/snooze"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"method": "POST",
|
|
24
|
+
"path": "/api/v1/agent/issues/{id}/unsnooze"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"method": "GET",
|
|
28
|
+
"path": "/api/v1/agent/alerts"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"method": "GET",
|
|
32
|
+
"path": "/api/v1/agent/whoami"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"method": "GET",
|
|
36
|
+
"path": "/api/v1/agent-tokens"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"method": "POST",
|
|
40
|
+
"path": "/api/v1/agent-tokens"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"method": "POST",
|
|
44
|
+
"path": "/api/v1/agent-tokens/{id}/revoke"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"method": "GET",
|
|
48
|
+
"path": "/api/v1/alert-rules"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"method": "POST",
|
|
52
|
+
"path": "/api/v1/alert-rules"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"method": "PATCH",
|
|
56
|
+
"path": "/api/v1/alert-rules/{id}"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"method": "DELETE",
|
|
60
|
+
"path": "/api/v1/alert-rules/{id}"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"method": "GET",
|
|
64
|
+
"path": "/api/v1/alert-channels"
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"method": "POST",
|
|
68
|
+
"path": "/api/v1/alert-channels"
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"method": "DELETE",
|
|
72
|
+
"path": "/api/v1/alert-channels/{id}"
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"method": "PATCH",
|
|
76
|
+
"path": "/api/v1/alert-channels/{id}"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"method": "POST",
|
|
80
|
+
"path": "/api/v1/alert-channels/{id}/test"
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
"method": "POST",
|
|
84
|
+
"path": "/api/v1/alert-channels/{id}/ping"
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"method": "GET",
|
|
88
|
+
"path": "/api/v1/alerts/rules"
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"method": "POST",
|
|
92
|
+
"path": "/api/v1/alerts/rules"
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"method": "PATCH",
|
|
96
|
+
"path": "/api/v1/alerts/rules/{id}"
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"method": "DELETE",
|
|
100
|
+
"path": "/api/v1/alerts/rules/{id}"
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
"method": "GET",
|
|
104
|
+
"path": "/api/v1/alerts"
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"method": "POST",
|
|
108
|
+
"path": "/api/v1/alerts/simulate"
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
"method": "PATCH",
|
|
112
|
+
"path": "/api/v1/alerts/{id}"
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
"method": "POST",
|
|
116
|
+
"path": "/api/v1/alerts/test-email"
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
"method": "POST",
|
|
120
|
+
"path": "/api/v1/projects/{project_id}/alerts/simulate"
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
"method": "GET",
|
|
124
|
+
"path": "/api/v1/projects/{project_id}/email-alerts"
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
"method": "PATCH",
|
|
128
|
+
"path": "/api/v1/projects/{project_id}/email-alerts"
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
"method": "POST",
|
|
132
|
+
"path": "/api/v1/projects/{project_id}/alerts/test-email"
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
"method": "POST",
|
|
136
|
+
"path": "/api/v1/auth/register"
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
"method": "POST",
|
|
140
|
+
"path": "/api/v1/auth/login"
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
"method": "GET",
|
|
144
|
+
"path": "/api/v1/auth/config"
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
"method": "GET",
|
|
148
|
+
"path": "/api/v1/auth/google"
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
"method": "GET",
|
|
152
|
+
"path": "/api/v1/auth/google/callback"
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
"method": "GET",
|
|
156
|
+
"path": "/api/v1/auth/github"
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
"method": "GET",
|
|
160
|
+
"path": "/api/v1/auth/github/callback"
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
"method": "POST",
|
|
164
|
+
"path": "/api/v1/auth/magic-link"
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
"method": "GET",
|
|
168
|
+
"path": "/api/v1/auth/magic-link/verify"
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
"method": "GET",
|
|
172
|
+
"path": "/api/v1/auth/me"
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
"method": "GET",
|
|
176
|
+
"path": "/api/v1/auth/organizations"
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
"method": "POST",
|
|
180
|
+
"path": "/api/v1/auth/switch-org"
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
"method": "PATCH",
|
|
184
|
+
"path": "/api/v1/auth/profile"
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
"method": "PATCH",
|
|
188
|
+
"path": "/api/v1/auth/password"
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
"method": "GET",
|
|
192
|
+
"path": "/api/v1/auth/account/export"
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
"method": "DELETE",
|
|
196
|
+
"path": "/api/v1/auth/account"
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
"method": "POST",
|
|
200
|
+
"path": "/api/v1/auth/accept-invitation"
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
"method": "POST",
|
|
204
|
+
"path": "/api/v1/auth/logout"
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
"method": "GET",
|
|
208
|
+
"path": "/api/v1/projects/{project_id}/dsn-keys"
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
"method": "POST",
|
|
212
|
+
"path": "/api/v1/projects/{project_id}/dsn-keys"
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
"method": "POST",
|
|
216
|
+
"path": "/api/v1/dsn-keys/{id}/revoke"
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
"method": "POST",
|
|
220
|
+
"path": "/api/v1/projects/{project_id}/dsn-keys/rotate"
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
"method": "GET",
|
|
224
|
+
"path": "/api/v1/issues/{issue_id}/events"
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
"method": "GET",
|
|
228
|
+
"path": "/api/v1/issues/{issue_id}/releases"
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
"method": "GET",
|
|
232
|
+
"path": "/api/v1/issues/{issue_id}/timeline"
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
"method": "GET",
|
|
236
|
+
"path": "/api/v1/events/{event_id}/feedback"
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
"method": "GET",
|
|
240
|
+
"path": "/api/v1/issues"
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
"method": "POST",
|
|
244
|
+
"path": "/api/v1/issues/trends"
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
"method": "PATCH",
|
|
248
|
+
"path": "/api/v1/issues/bulk"
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
"method": "DELETE",
|
|
252
|
+
"path": "/api/v1/issues/bulk"
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
"method": "POST",
|
|
256
|
+
"path": "/api/v1/issues/merge"
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
"method": "POST",
|
|
260
|
+
"path": "/api/v1/issues/split"
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
"method": "GET",
|
|
264
|
+
"path": "/api/v1/issues/{id}/merged"
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
"method": "PATCH",
|
|
268
|
+
"path": "/api/v1/issues/{id}"
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
"method": "POST",
|
|
272
|
+
"path": "/api/v1/issues/{id}/snooze"
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
"method": "POST",
|
|
276
|
+
"path": "/api/v1/issues/{id}/unsnooze"
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
"method": "POST",
|
|
280
|
+
"path": "/api/v1/mcp"
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
"method": "GET",
|
|
284
|
+
"path": "/api/v1/mcp"
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
"method": "POST",
|
|
288
|
+
"path": "/api/v1/api/mcp"
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
"method": "GET",
|
|
292
|
+
"path": "/api/v1/api/mcp"
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
"method": "GET",
|
|
296
|
+
"path": "/api/v1/members"
|
|
297
|
+
},
|
|
298
|
+
{
|
|
299
|
+
"method": "PATCH",
|
|
300
|
+
"path": "/api/v1/members/{user_id}"
|
|
301
|
+
},
|
|
302
|
+
{
|
|
303
|
+
"method": "DELETE",
|
|
304
|
+
"path": "/api/v1/members/{user_id}"
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
"method": "GET",
|
|
308
|
+
"path": "/api/v1/invitations"
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
"method": "POST",
|
|
312
|
+
"path": "/api/v1/invitations"
|
|
313
|
+
},
|
|
314
|
+
{
|
|
315
|
+
"method": "DELETE",
|
|
316
|
+
"path": "/api/v1/invitations/{id}"
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
"method": "GET",
|
|
320
|
+
"path": "/api/v1/monitors"
|
|
321
|
+
},
|
|
322
|
+
{
|
|
323
|
+
"method": "POST",
|
|
324
|
+
"path": "/api/v1/monitors"
|
|
325
|
+
},
|
|
326
|
+
{
|
|
327
|
+
"method": "GET",
|
|
328
|
+
"path": "/api/v1/monitors/{id}"
|
|
329
|
+
},
|
|
330
|
+
{
|
|
331
|
+
"method": "PATCH",
|
|
332
|
+
"path": "/api/v1/monitors/{id}"
|
|
333
|
+
},
|
|
334
|
+
{
|
|
335
|
+
"method": "DELETE",
|
|
336
|
+
"path": "/api/v1/monitors/{id}"
|
|
337
|
+
},
|
|
338
|
+
{
|
|
339
|
+
"method": "POST",
|
|
340
|
+
"path": "/api/v1/monitors/{id}/check-ins"
|
|
341
|
+
},
|
|
342
|
+
{
|
|
343
|
+
"method": "GET",
|
|
344
|
+
"path": "/api/v1/oauth/info"
|
|
345
|
+
},
|
|
346
|
+
{
|
|
347
|
+
"method": "POST",
|
|
348
|
+
"path": "/api/v1/oauth/authorize"
|
|
349
|
+
},
|
|
350
|
+
{
|
|
351
|
+
"method": "GET",
|
|
352
|
+
"path": "/api/v1/oauth/device/verify"
|
|
353
|
+
},
|
|
354
|
+
{
|
|
355
|
+
"method": "POST",
|
|
356
|
+
"path": "/api/v1/oauth/device/approve"
|
|
357
|
+
},
|
|
358
|
+
{
|
|
359
|
+
"method": "GET",
|
|
360
|
+
"path": "/api/v1/user/connected-apps"
|
|
361
|
+
},
|
|
362
|
+
{
|
|
363
|
+
"method": "DELETE",
|
|
364
|
+
"path": "/api/v1/user/connected-apps/{id}"
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
"method": "GET",
|
|
368
|
+
"path": "/api/v1/privacy"
|
|
369
|
+
},
|
|
370
|
+
{
|
|
371
|
+
"method": "GET",
|
|
372
|
+
"path": "/api/v1/projects/{id}/privacy/export"
|
|
373
|
+
},
|
|
374
|
+
{
|
|
375
|
+
"method": "POST",
|
|
376
|
+
"path": "/api/v1/projects/{id}/privacy/erase"
|
|
377
|
+
},
|
|
378
|
+
{
|
|
379
|
+
"method": "POST",
|
|
380
|
+
"path": "/api/v1/projects/{id}/privacy/strip-identifiers"
|
|
381
|
+
},
|
|
382
|
+
{
|
|
383
|
+
"method": "GET",
|
|
384
|
+
"path": "/api/v1/projects"
|
|
385
|
+
},
|
|
386
|
+
{
|
|
387
|
+
"method": "POST",
|
|
388
|
+
"path": "/api/v1/projects"
|
|
389
|
+
},
|
|
390
|
+
{
|
|
391
|
+
"method": "PATCH",
|
|
392
|
+
"path": "/api/v1/projects/{id}"
|
|
393
|
+
},
|
|
394
|
+
{
|
|
395
|
+
"method": "DELETE",
|
|
396
|
+
"path": "/api/v1/projects/{id}"
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
"method": "GET",
|
|
400
|
+
"path": "/api/v1/projects/{id}/activity"
|
|
401
|
+
},
|
|
402
|
+
{
|
|
403
|
+
"method": "GET",
|
|
404
|
+
"path": "/api/v1/projects/{id}/velocity"
|
|
405
|
+
},
|
|
406
|
+
{
|
|
407
|
+
"method": "GET",
|
|
408
|
+
"path": "/api/v1/projects/{id}/noise-policy"
|
|
409
|
+
},
|
|
410
|
+
{
|
|
411
|
+
"method": "PUT",
|
|
412
|
+
"path": "/api/v1/projects/{id}/noise-policy"
|
|
413
|
+
},
|
|
414
|
+
{
|
|
415
|
+
"method": "POST",
|
|
416
|
+
"path": "/api/v1/projects/{id}/noise-policy/preview"
|
|
417
|
+
},
|
|
418
|
+
{
|
|
419
|
+
"method": "GET",
|
|
420
|
+
"path": "/api/v1/projects/{id}/ingest-outcomes"
|
|
421
|
+
},
|
|
422
|
+
{
|
|
423
|
+
"method": "GET",
|
|
424
|
+
"path": "/api/v1/releases"
|
|
425
|
+
},
|
|
426
|
+
{
|
|
427
|
+
"method": "GET",
|
|
428
|
+
"path": "/api/v1/setup"
|
|
429
|
+
},
|
|
430
|
+
{
|
|
431
|
+
"method": "PATCH",
|
|
432
|
+
"path": "/api/v1/setup"
|
|
433
|
+
},
|
|
434
|
+
{
|
|
435
|
+
"method": "GET",
|
|
436
|
+
"path": "/api/v1/setup/dsn"
|
|
437
|
+
},
|
|
438
|
+
{
|
|
439
|
+
"method": "POST",
|
|
440
|
+
"path": "/api/v1/setup/test-event"
|
|
441
|
+
},
|
|
442
|
+
{
|
|
443
|
+
"method": "GET",
|
|
444
|
+
"path": "/api/v1/stats"
|
|
445
|
+
},
|
|
446
|
+
{
|
|
447
|
+
"method": "GET",
|
|
448
|
+
"path": "/api/v1/webhooks"
|
|
449
|
+
},
|
|
450
|
+
{
|
|
451
|
+
"method": "POST",
|
|
452
|
+
"path": "/api/v1/webhooks"
|
|
453
|
+
},
|
|
454
|
+
{
|
|
455
|
+
"method": "PATCH",
|
|
456
|
+
"path": "/api/v1/webhooks/{id}"
|
|
457
|
+
},
|
|
458
|
+
{
|
|
459
|
+
"method": "DELETE",
|
|
460
|
+
"path": "/api/v1/webhooks/{id}"
|
|
461
|
+
},
|
|
462
|
+
{
|
|
463
|
+
"method": "POST",
|
|
464
|
+
"path": "/api/v1/webhooks/{id}/test"
|
|
465
|
+
},
|
|
466
|
+
{
|
|
467
|
+
"method": "POST",
|
|
468
|
+
"path": "/api/v1/webhooks/{id}/rotate-secret"
|
|
469
|
+
}
|
|
470
|
+
]
|
package/lib/api.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { ClientError, endpoint, getActiveCredentials, ensureValidToken, authRequired } = require('./auth');
|
|
3
|
+
const { catalog } = require('./operations');
|
|
4
|
+
function safePath(method, path) {
|
|
5
|
+
if (typeof path !== 'string' || !path.startsWith('/api/v1/') || /[\\?#]|%2f|%5c|%2e|\.{2}/i.test(path)) throw new ClientError('INVALID_PATH', 'Use an API path from epure api-catalog, without a query string.', 2);
|
|
6
|
+
const allowed = catalog.some(o => o.method === method && new RegExp(`^${o.path.replace(/\{[^}]+\}/g, '[^/]+')}$`).test(path));
|
|
7
|
+
// Auth identity is the OAuth Agent API, never browser login or PAT management.
|
|
8
|
+
if (!allowed) throw new ClientError('UNSUPPORTED_OPERATION', 'Unknown or excluded API operation. Run epure api-catalog.', 2);
|
|
9
|
+
}
|
|
10
|
+
async function apiRequest(instanceUrl, request = {}, signal) {
|
|
11
|
+
const url = endpoint(instanceUrl); const method = (request.method || 'GET').toUpperCase(); safePath(method, request.path);
|
|
12
|
+
const target = new URL(request.path, url);
|
|
13
|
+
if (target.origin !== url) throw new ClientError('INVALID_PATH', 'Cross-origin requests are forbidden.', 2);
|
|
14
|
+
for (const [k, v] of Object.entries(request.query || {})) if (v != null) target.searchParams.set(k, String(v));
|
|
15
|
+
const session = getActiveCredentials(url); if (!session?.refresh_token) throw authRequired();
|
|
16
|
+
let credential = await ensureValidToken(session);
|
|
17
|
+
async function send() {
|
|
18
|
+
const headers = { Authorization: `Bearer ${credential}`, Accept: 'application/json', 'User-Agent': 'epure-clients/0.2.0' }; let body;
|
|
19
|
+
if (request.files) {
|
|
20
|
+
body = new FormData(); for (const [k, v] of Object.entries(request.body || {})) body.append(k, String(v));
|
|
21
|
+
for (const f of request.files) body.append(f.field || 'file', new Blob([Buffer.from(f.base64, 'base64')], { type: f.contentType || 'application/octet-stream' }), f.filename);
|
|
22
|
+
} else if (request.body !== undefined && !['GET', 'HEAD'].includes(method)) { headers['Content-Type'] = 'application/json'; body = JSON.stringify(request.body); }
|
|
23
|
+
const controller = new AbortController(); const timer = setTimeout(() => controller.abort(), 30000);
|
|
24
|
+
const abort = () => controller.abort(); signal?.addEventListener('abort', abort, { once: true }); if (signal?.aborted) abort();
|
|
25
|
+
try { const response = await fetch(target, { method, headers, body, redirect: 'error', signal: controller.signal }); return { response, text: await response.text() }; }
|
|
26
|
+
catch { throw new ClientError(signal?.aborted ? 'CANCELLED' : 'NETWORK_ERROR', signal?.aborted ? 'Request cancelled.' : 'Request failed or timed out. Check the connection before retrying a write.', signal?.aborted ? 2 : 1); }
|
|
27
|
+
finally { clearTimeout(timer); signal?.removeEventListener('abort', abort); }
|
|
28
|
+
}
|
|
29
|
+
let reply = await send();
|
|
30
|
+
if (reply.response.status === 401) {
|
|
31
|
+
credential = await ensureValidToken({ ...session, access_token: credential }, true); reply = await send();
|
|
32
|
+
}
|
|
33
|
+
const { response, text } = reply; let data; try { data = JSON.parse(text); } catch { data = text || null; }
|
|
34
|
+
if (!response.ok) {
|
|
35
|
+
if (response.status === 401) throw authRequired();
|
|
36
|
+
const hint = response.status === 403 ? 'Your approved scopes or workspace role do not allow this action. Reauthorize with the required scope, or ask an administrator.' : response.status === 429 ? 'Rate limited. Retry after the server limit resets.' : 'Check the resource ID, arguments and instance.';
|
|
37
|
+
const e = new ClientError(response.status === 403 ? 'PERMISSION_DENIED' : `HTTP_${response.status}`, `HTTP ${response.status}. ${hint}`, response.status === 403 ? 5 : 1); e.status = response.status; throw e;
|
|
38
|
+
}
|
|
39
|
+
return { status: response.status, data };
|
|
40
|
+
}
|
|
41
|
+
module.exports = { apiRequest, safePath };
|