@wakata-dev/api-client 0.1.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/dist/index.js ADDED
@@ -0,0 +1,535 @@
1
+ import { createClient, createConfig, formDataBodySerializer } from '@hey-api/client-fetch';
2
+
3
+ // src/client.ts
4
+
5
+ // src/errors.ts
6
+ var WakataApiError = class extends Error {
7
+ constructor(args) {
8
+ super(args.message);
9
+ this.name = "WakataApiError";
10
+ this.code = args.code;
11
+ this.statusCode = args.statusCode;
12
+ this.requestId = args.requestId;
13
+ this.docsUrl = args.docsUrl;
14
+ this.param = args.param;
15
+ this.details = args.details;
16
+ Object.setPrototypeOf(this, new.target.prototype);
17
+ }
18
+ };
19
+ var WakataValidationError = class extends WakataApiError {
20
+ constructor() {
21
+ super(...arguments);
22
+ this.name = "WakataValidationError";
23
+ }
24
+ };
25
+ var WakataAuthError = class extends WakataApiError {
26
+ constructor() {
27
+ super(...arguments);
28
+ this.name = "WakataAuthError";
29
+ }
30
+ };
31
+ var WakataPermissionError = class extends WakataApiError {
32
+ constructor() {
33
+ super(...arguments);
34
+ this.name = "WakataPermissionError";
35
+ }
36
+ };
37
+ var WakataNotFoundError = class extends WakataApiError {
38
+ constructor() {
39
+ super(...arguments);
40
+ this.name = "WakataNotFoundError";
41
+ }
42
+ };
43
+ var WakataConflictError = class extends WakataApiError {
44
+ constructor() {
45
+ super(...arguments);
46
+ this.name = "WakataConflictError";
47
+ }
48
+ };
49
+ var WakataRateLimitError = class extends WakataApiError {
50
+ constructor(args) {
51
+ super(args);
52
+ this.name = "WakataRateLimitError";
53
+ this.retryAfterSeconds = args.retryAfterSeconds;
54
+ }
55
+ };
56
+ var WakataServerError = class extends WakataApiError {
57
+ constructor() {
58
+ super(...arguments);
59
+ this.name = "WakataServerError";
60
+ }
61
+ };
62
+ function mapApiError(statusCode, envelope, fallbackRequestId, retryAfterSeconds) {
63
+ const code = envelope?.code ?? "unknown_error";
64
+ const message = envelope?.message ?? `Wakata API returned HTTP ${statusCode}`;
65
+ const requestId = envelope?.request_id ?? fallbackRequestId;
66
+ const docsUrl = envelope?.docs_url;
67
+ const param = envelope?.param;
68
+ const details = envelope?.details;
69
+ const base = {
70
+ code,
71
+ statusCode,
72
+ requestId,
73
+ docsUrl,
74
+ param,
75
+ details,
76
+ message
77
+ };
78
+ if (statusCode === 429) {
79
+ return new WakataRateLimitError({
80
+ ...base,
81
+ retryAfterSeconds
82
+ });
83
+ }
84
+ if (statusCode === 401) return new WakataAuthError(base);
85
+ if (statusCode === 403) return new WakataPermissionError(base);
86
+ if (statusCode === 404) return new WakataNotFoundError(base);
87
+ if (statusCode === 409) return new WakataConflictError(base);
88
+ if (statusCode >= 500) return new WakataServerError(base);
89
+ if (statusCode >= 400 && details && details.length > 0) {
90
+ return new WakataValidationError(base);
91
+ }
92
+ return new WakataApiError(base);
93
+ }
94
+
95
+ // src/idempotency.ts
96
+ function generateIdempotencyKey() {
97
+ const c = typeof globalThis !== "undefined" ? globalThis.crypto : void 0;
98
+ let uuid;
99
+ if (c && typeof c.randomUUID === "function") {
100
+ uuid = c.randomUUID();
101
+ } else if (c && typeof c.getRandomValues === "function") {
102
+ const bytes = new Uint8Array(16);
103
+ c.getRandomValues(bytes);
104
+ bytes[6] = (bytes[6] ?? 0) & 15 | 64;
105
+ bytes[8] = (bytes[8] ?? 0) & 63 | 128;
106
+ const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join(
107
+ ""
108
+ );
109
+ uuid = `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20, 32)}`;
110
+ } else {
111
+ uuid = Date.now().toString(16) + "-" + Math.random().toString(16).slice(2, 14).padEnd(12, "0");
112
+ }
113
+ return `wak_idem_${uuid.replace(/-/g, "")}`;
114
+ }
115
+ var client = createClient(createConfig({
116
+ baseUrl: "https://lrfq4vihdi.execute-api.ap-southeast-2.amazonaws.com"
117
+ }));
118
+
119
+ // src/generated/sdk.gen.ts
120
+ var assetControllerCreateAssetPublic = (options) => {
121
+ return (options.client ?? client).post({
122
+ security: [
123
+ {
124
+ scheme: "bearer",
125
+ type: "http"
126
+ }
127
+ ],
128
+ url: "/api/v1/public/asset",
129
+ ...options,
130
+ headers: {
131
+ "Content-Type": "application/json",
132
+ ...options?.headers
133
+ }
134
+ });
135
+ };
136
+ var assetControllerListAssets = (options) => {
137
+ return (options?.client ?? client).get({
138
+ security: [
139
+ {
140
+ scheme: "bearer",
141
+ type: "http"
142
+ }
143
+ ],
144
+ url: "/api/v1/asset/list",
145
+ ...options
146
+ });
147
+ };
148
+ var assetControllerGetAsset = (options) => {
149
+ return (options.client ?? client).get({
150
+ security: [
151
+ {
152
+ scheme: "bearer",
153
+ type: "http"
154
+ }
155
+ ],
156
+ url: "/api/v1/asset/{id}",
157
+ ...options
158
+ });
159
+ };
160
+ var assetControllerUpdateAsset = (options) => {
161
+ return (options.client ?? client).patch({
162
+ security: [
163
+ {
164
+ scheme: "bearer",
165
+ type: "http"
166
+ }
167
+ ],
168
+ url: "/api/v1/asset/{id}",
169
+ ...options,
170
+ headers: {
171
+ "Content-Type": "application/json",
172
+ ...options?.headers
173
+ }
174
+ });
175
+ };
176
+ var userControllerListUsers = (options) => {
177
+ return (options?.client ?? client).get({
178
+ security: [
179
+ {
180
+ scheme: "bearer",
181
+ type: "http"
182
+ }
183
+ ],
184
+ url: "/api/v1/user/list",
185
+ ...options
186
+ });
187
+ };
188
+ var userControllerGetUser = (options) => {
189
+ return (options.client ?? client).get({
190
+ security: [
191
+ {
192
+ scheme: "bearer",
193
+ type: "http"
194
+ }
195
+ ],
196
+ url: "/api/v1/user/{id}",
197
+ ...options
198
+ });
199
+ };
200
+ var userControllerUpdateUser = (options) => {
201
+ return (options.client ?? client).patch({
202
+ ...formDataBodySerializer,
203
+ security: [
204
+ {
205
+ scheme: "bearer",
206
+ type: "http"
207
+ }
208
+ ],
209
+ url: "/api/v1/user/{id}",
210
+ ...options,
211
+ headers: {
212
+ "Content-Type": null,
213
+ ...options?.headers
214
+ }
215
+ });
216
+ };
217
+ var userControllerCreateUser = (options) => {
218
+ return (options.client ?? client).post({
219
+ ...formDataBodySerializer,
220
+ security: [
221
+ {
222
+ scheme: "bearer",
223
+ type: "http"
224
+ }
225
+ ],
226
+ url: "/api/v1/user",
227
+ ...options,
228
+ headers: {
229
+ "Content-Type": null,
230
+ ...options?.headers
231
+ }
232
+ });
233
+ };
234
+ var inspectionControllerListInspections = (options) => {
235
+ return (options?.client ?? client).get({
236
+ security: [
237
+ {
238
+ scheme: "bearer",
239
+ type: "http"
240
+ }
241
+ ],
242
+ url: "/api/v1/public/inspection/list",
243
+ ...options
244
+ });
245
+ };
246
+ var inspectionControllerSubmitInspectionPublic = (options) => {
247
+ return (options.client ?? client).post({
248
+ security: [
249
+ {
250
+ scheme: "bearer",
251
+ type: "http"
252
+ }
253
+ ],
254
+ url: "/api/v1/public/inspection/submit",
255
+ ...options,
256
+ headers: {
257
+ "Content-Type": "application/json",
258
+ ...options?.headers
259
+ }
260
+ });
261
+ };
262
+ var issueControllerListIssues = (options) => {
263
+ return (options?.client ?? client).get({
264
+ security: [
265
+ {
266
+ scheme: "bearer",
267
+ type: "http"
268
+ }
269
+ ],
270
+ url: "/api/v1/public/issue/list",
271
+ ...options
272
+ });
273
+ };
274
+ var issueControllerGetIssuePublic = (options) => {
275
+ return (options.client ?? client).get({
276
+ security: [
277
+ {
278
+ scheme: "bearer",
279
+ type: "http"
280
+ }
281
+ ],
282
+ url: "/api/v1/public/issue/{public_id}",
283
+ ...options
284
+ });
285
+ };
286
+ var issueControllerUpdateIssuePublic = (options) => {
287
+ return (options.client ?? client).patch({
288
+ security: [
289
+ {
290
+ scheme: "bearer",
291
+ type: "http"
292
+ }
293
+ ],
294
+ url: "/api/v1/public/issue/{public_id}",
295
+ ...options,
296
+ headers: {
297
+ "Content-Type": "application/json",
298
+ ...options?.headers
299
+ }
300
+ });
301
+ };
302
+ var issueControllerGetIssueHistoryPublic = (options) => {
303
+ return (options.client ?? client).get({
304
+ security: [
305
+ {
306
+ scheme: "bearer",
307
+ type: "http"
308
+ }
309
+ ],
310
+ url: "/api/v1/public/issue/{public_id}/history",
311
+ ...options
312
+ });
313
+ };
314
+ var userPropertyControllerDeleteUserProperty = (options) => {
315
+ return (options.client ?? client).delete({
316
+ security: [
317
+ {
318
+ scheme: "bearer",
319
+ type: "http"
320
+ }
321
+ ],
322
+ url: "/api/v1/user-property/{id}",
323
+ ...options
324
+ });
325
+ };
326
+ var userPropertyControllerUpdateUserProperty = (options) => {
327
+ return (options.client ?? client).patch({
328
+ security: [
329
+ {
330
+ scheme: "bearer",
331
+ type: "http"
332
+ }
333
+ ],
334
+ url: "/api/v1/user-property/{id}",
335
+ ...options,
336
+ headers: {
337
+ "Content-Type": "application/json",
338
+ ...options?.headers
339
+ }
340
+ });
341
+ };
342
+ var siteControllerListSites = (options) => {
343
+ return (options?.client ?? client).get({
344
+ security: [
345
+ {
346
+ scheme: "bearer",
347
+ type: "http"
348
+ }
349
+ ],
350
+ url: "/api/v1/site/list",
351
+ ...options
352
+ });
353
+ };
354
+ var siteControllerCreateSite = (options) => {
355
+ return (options.client ?? client).post({
356
+ security: [
357
+ {
358
+ scheme: "bearer",
359
+ type: "http"
360
+ }
361
+ ],
362
+ url: "/api/v1/site",
363
+ ...options,
364
+ headers: {
365
+ "Content-Type": "application/json",
366
+ ...options?.headers
367
+ }
368
+ });
369
+ };
370
+ var siteControllerDeleteSite = (options) => {
371
+ return (options.client ?? client).delete({
372
+ security: [
373
+ {
374
+ scheme: "bearer",
375
+ type: "http"
376
+ }
377
+ ],
378
+ url: "/api/v1/site/{id}",
379
+ ...options
380
+ });
381
+ };
382
+ var siteControllerUpdateSite = (options) => {
383
+ return (options.client ?? client).patch({
384
+ security: [
385
+ {
386
+ scheme: "bearer",
387
+ type: "http"
388
+ }
389
+ ],
390
+ url: "/api/v1/site/{id}",
391
+ ...options,
392
+ headers: {
393
+ "Content-Type": "application/json",
394
+ ...options?.headers
395
+ }
396
+ });
397
+ };
398
+
399
+ // src/client.ts
400
+ var DEFAULT_BASE_URL = "https://api.wakata.ai/api/v1";
401
+ var PACKAGE_VERSION = "0.1.0";
402
+ function unwrap(result) {
403
+ if (result.data === void 0) {
404
+ throw new WakataApiError({
405
+ code: "unknown_error",
406
+ statusCode: result.response.status,
407
+ requestId: result.response.headers.get("X-Request-Id") ?? "",
408
+ message: "Empty response body where data was expected."
409
+ });
410
+ }
411
+ return result.data;
412
+ }
413
+ var WakataClient = class {
414
+ constructor(options) {
415
+ if (!options.apiKey) {
416
+ throw new Error("WakataClient: `apiKey` is required.");
417
+ }
418
+ const baseUrl = options.baseUrl ?? DEFAULT_BASE_URL;
419
+ this.raw = createClient(
420
+ createConfig({
421
+ baseUrl,
422
+ // Inject the apiKey into the Authorization header via the `auth` hook
423
+ // so the generated `security: [{ scheme: 'bearer' }]` machinery picks
424
+ // it up on every operation.
425
+ auth: options.apiKey,
426
+ ...options.fetch ? { fetch: options.fetch } : {}
427
+ })
428
+ );
429
+ this.raw.interceptors.request.use((request) => {
430
+ try {
431
+ request.headers.set("User-Agent", `@wakata-dev/api-client/${PACKAGE_VERSION}`);
432
+ } catch {
433
+ }
434
+ const method = request.method.toUpperCase();
435
+ if (method === "POST" || method === "PATCH") {
436
+ if (!request.headers.has("Idempotency-Key")) {
437
+ request.headers.set("Idempotency-Key", generateIdempotencyKey());
438
+ }
439
+ }
440
+ return request;
441
+ });
442
+ this.raw.interceptors.response.use(async (response) => {
443
+ if (response.ok) return response;
444
+ let envelope;
445
+ try {
446
+ const cloned = response.clone();
447
+ const json = await cloned.json();
448
+ envelope = json?.error;
449
+ } catch {
450
+ }
451
+ const fallbackRequestId = response.headers.get("X-Request-Id") ?? "";
452
+ let retryAfterSeconds;
453
+ if (response.status === 429) {
454
+ const retryAfter = response.headers.get("Retry-After");
455
+ if (retryAfter) {
456
+ const n = Number(retryAfter);
457
+ if (Number.isFinite(n)) retryAfterSeconds = n;
458
+ }
459
+ if (retryAfterSeconds === void 0) {
460
+ const reset = response.headers.get("X-RateLimit-Reset");
461
+ if (reset) {
462
+ const resetEpoch = Number(reset);
463
+ if (Number.isFinite(resetEpoch)) {
464
+ retryAfterSeconds = Math.max(
465
+ 0,
466
+ Math.ceil(resetEpoch - Date.now() / 1e3)
467
+ );
468
+ }
469
+ }
470
+ }
471
+ }
472
+ throw mapApiError(
473
+ response.status,
474
+ envelope,
475
+ fallbackRequestId,
476
+ retryAfterSeconds
477
+ );
478
+ });
479
+ const client2 = this.raw;
480
+ this.assets = {
481
+ list: async (opts) => unwrap(await assetControllerListAssets({ ...opts ?? {}, client: client2 })),
482
+ create: async (opts) => unwrap(await assetControllerCreateAssetPublic({ ...opts, client: client2 })),
483
+ get: async (opts) => unwrap(await assetControllerGetAsset({ ...opts, client: client2 })),
484
+ update: async (opts) => unwrap(await assetControllerUpdateAsset({ ...opts, client: client2 }))
485
+ };
486
+ this.users = {
487
+ list: async (opts) => unwrap(await userControllerListUsers({ ...opts ?? {}, client: client2 })),
488
+ get: async (opts) => unwrap(await userControllerGetUser({ ...opts, client: client2 })),
489
+ create: async (opts) => unwrap(await userControllerCreateUser({ ...opts, client: client2 })),
490
+ update: async (opts) => unwrap(await userControllerUpdateUser({ ...opts, client: client2 }))
491
+ };
492
+ this.sites = {
493
+ list: async (opts) => unwrap(await siteControllerListSites({ ...opts ?? {}, client: client2 })),
494
+ create: async (opts) => unwrap(await siteControllerCreateSite({ ...opts, client: client2 })),
495
+ update: async (opts) => unwrap(await siteControllerUpdateSite({ ...opts, client: client2 })),
496
+ delete: async (opts) => unwrap(await siteControllerDeleteSite({ ...opts, client: client2 }))
497
+ };
498
+ this.inspections = {
499
+ list: async (opts) => unwrap(
500
+ await inspectionControllerListInspections({
501
+ ...opts ?? {},
502
+ client: client2
503
+ })
504
+ ),
505
+ submit: async (opts) => unwrap(
506
+ await inspectionControllerSubmitInspectionPublic({ ...opts, client: client2 })
507
+ )
508
+ };
509
+ this.issues = {
510
+ list: async (opts) => unwrap(await issueControllerListIssues({ ...opts ?? {}, client: client2 })),
511
+ get: async (opts) => unwrap(await issueControllerGetIssuePublic({ ...opts, client: client2 })),
512
+ update: async (opts) => unwrap(await issueControllerUpdateIssuePublic({ ...opts, client: client2 })),
513
+ getHistory: async (opts) => unwrap(
514
+ await issueControllerGetIssueHistoryPublic({ ...opts, client: client2 })
515
+ )
516
+ };
517
+ this.userProperties = {
518
+ update: async (opts) => unwrap(
519
+ await userPropertyControllerUpdateUserProperty({ ...opts, client: client2 })
520
+ ),
521
+ delete: async (opts) => unwrap(
522
+ await userPropertyControllerDeleteUserProperty({ ...opts, client: client2 })
523
+ )
524
+ };
525
+ }
526
+ };
527
+
528
+ // src/index.ts
529
+ var PACKAGE_NAME = "@wakata-dev/api-client";
530
+ var PACKAGE_VERSION2 = "0.1.0";
531
+ var DEFAULT_BASE_URL2 = "https://api.wakata.ai/api/v1";
532
+
533
+ export { DEFAULT_BASE_URL2 as DEFAULT_BASE_URL, PACKAGE_NAME, PACKAGE_VERSION2 as PACKAGE_VERSION, WakataApiError, WakataAuthError, WakataClient, WakataConflictError, WakataNotFoundError, WakataPermissionError, WakataRateLimitError, WakataServerError, WakataValidationError, generateIdempotencyKey, mapApiError };
534
+ //# sourceMappingURL=index.js.map
535
+ //# sourceMappingURL=index.js.map