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