@layer-drone/protocol 0.0.8 → 0.0.9-alpha

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.mjs CHANGED
@@ -1,8 +1,571 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
 
4
+ // src/client/core/bodySerializer.ts
5
+ var jsonBodySerializer = {
6
+ bodySerializer: /* @__PURE__ */ __name((body) => JSON.stringify(body, (key, value) => typeof value === "bigint" ? value.toString() : value), "bodySerializer")
7
+ };
8
+
9
+ // src/client/core/params.ts
10
+ var extraPrefixesMap = {
11
+ $body_: "body",
12
+ $headers_: "headers",
13
+ $path_: "path",
14
+ $query_: "query"
15
+ };
16
+ var extraPrefixes = Object.entries(extraPrefixesMap);
17
+
18
+ // src/client/core/auth.ts
19
+ var getAuthToken = /* @__PURE__ */ __name(async (auth, callback) => {
20
+ const token = typeof callback === "function" ? await callback(auth) : callback;
21
+ if (!token) {
22
+ return;
23
+ }
24
+ if (auth.scheme === "bearer") {
25
+ return `Bearer ${token}`;
26
+ }
27
+ if (auth.scheme === "basic") {
28
+ return `Basic ${btoa(token)}`;
29
+ }
30
+ return token;
31
+ }, "getAuthToken");
32
+
33
+ // src/client/core/pathSerializer.ts
34
+ var separatorArrayExplode = /* @__PURE__ */ __name((style) => {
35
+ switch (style) {
36
+ case "label":
37
+ return ".";
38
+ case "matrix":
39
+ return ";";
40
+ case "simple":
41
+ return ",";
42
+ default:
43
+ return "&";
44
+ }
45
+ }, "separatorArrayExplode");
46
+ var separatorArrayNoExplode = /* @__PURE__ */ __name((style) => {
47
+ switch (style) {
48
+ case "form":
49
+ return ",";
50
+ case "pipeDelimited":
51
+ return "|";
52
+ case "spaceDelimited":
53
+ return "%20";
54
+ default:
55
+ return ",";
56
+ }
57
+ }, "separatorArrayNoExplode");
58
+ var separatorObjectExplode = /* @__PURE__ */ __name((style) => {
59
+ switch (style) {
60
+ case "label":
61
+ return ".";
62
+ case "matrix":
63
+ return ";";
64
+ case "simple":
65
+ return ",";
66
+ default:
67
+ return "&";
68
+ }
69
+ }, "separatorObjectExplode");
70
+ var serializeArrayParam = /* @__PURE__ */ __name(({ allowReserved, explode, name, style, value }) => {
71
+ if (!explode) {
72
+ const joinedValues2 = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
73
+ switch (style) {
74
+ case "label":
75
+ return `.${joinedValues2}`;
76
+ case "matrix":
77
+ return `;${name}=${joinedValues2}`;
78
+ case "simple":
79
+ return joinedValues2;
80
+ default:
81
+ return `${name}=${joinedValues2}`;
82
+ }
83
+ }
84
+ const separator = separatorArrayExplode(style);
85
+ const joinedValues = value.map((v) => {
86
+ if (style === "label" || style === "simple") {
87
+ return allowReserved ? v : encodeURIComponent(v);
88
+ }
89
+ return serializePrimitiveParam({
90
+ allowReserved,
91
+ name,
92
+ value: v
93
+ });
94
+ }).join(separator);
95
+ return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
96
+ }, "serializeArrayParam");
97
+ var serializePrimitiveParam = /* @__PURE__ */ __name(({ allowReserved, name, value }) => {
98
+ if (value === void 0 || value === null) {
99
+ return "";
100
+ }
101
+ if (typeof value === "object") {
102
+ throw new Error("Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these.");
103
+ }
104
+ return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
105
+ }, "serializePrimitiveParam");
106
+ var serializeObjectParam = /* @__PURE__ */ __name(({ allowReserved, explode, name, style, value, valueOnly }) => {
107
+ if (value instanceof Date) {
108
+ return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
109
+ }
110
+ if (style !== "deepObject" && !explode) {
111
+ let values = [];
112
+ Object.entries(value).forEach(([key, v]) => {
113
+ values = [
114
+ ...values,
115
+ key,
116
+ allowReserved ? v : encodeURIComponent(v)
117
+ ];
118
+ });
119
+ const joinedValues2 = values.join(",");
120
+ switch (style) {
121
+ case "form":
122
+ return `${name}=${joinedValues2}`;
123
+ case "label":
124
+ return `.${joinedValues2}`;
125
+ case "matrix":
126
+ return `;${name}=${joinedValues2}`;
127
+ default:
128
+ return joinedValues2;
129
+ }
130
+ }
131
+ const separator = separatorObjectExplode(style);
132
+ const joinedValues = Object.entries(value).map(([key, v]) => serializePrimitiveParam({
133
+ allowReserved,
134
+ name: style === "deepObject" ? `${name}[${key}]` : key,
135
+ value: v
136
+ })).join(separator);
137
+ return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
138
+ }, "serializeObjectParam");
139
+
140
+ // src/client/client/utils.ts
141
+ var PATH_PARAM_RE = /\{[^{}]+\}/g;
142
+ var defaultPathSerializer = /* @__PURE__ */ __name(({ path, url: _url }) => {
143
+ let url = _url;
144
+ const matches = _url.match(PATH_PARAM_RE);
145
+ if (matches) {
146
+ for (const match of matches) {
147
+ let explode = false;
148
+ let name = match.substring(1, match.length - 1);
149
+ let style = "simple";
150
+ if (name.endsWith("*")) {
151
+ explode = true;
152
+ name = name.substring(0, name.length - 1);
153
+ }
154
+ if (name.startsWith(".")) {
155
+ name = name.substring(1);
156
+ style = "label";
157
+ } else if (name.startsWith(";")) {
158
+ name = name.substring(1);
159
+ style = "matrix";
160
+ }
161
+ const value = path[name];
162
+ if (value === void 0 || value === null) {
163
+ continue;
164
+ }
165
+ if (Array.isArray(value)) {
166
+ url = url.replace(match, serializeArrayParam({
167
+ explode,
168
+ name,
169
+ style,
170
+ value
171
+ }));
172
+ continue;
173
+ }
174
+ if (typeof value === "object") {
175
+ url = url.replace(match, serializeObjectParam({
176
+ explode,
177
+ name,
178
+ style,
179
+ value,
180
+ valueOnly: true
181
+ }));
182
+ continue;
183
+ }
184
+ if (style === "matrix") {
185
+ url = url.replace(match, `;${serializePrimitiveParam({
186
+ name,
187
+ value
188
+ })}`);
189
+ continue;
190
+ }
191
+ const replaceValue = encodeURIComponent(style === "label" ? `.${value}` : value);
192
+ url = url.replace(match, replaceValue);
193
+ }
194
+ }
195
+ return url;
196
+ }, "defaultPathSerializer");
197
+ var createQuerySerializer = /* @__PURE__ */ __name(({ allowReserved, array, object } = {}) => {
198
+ const querySerializer = /* @__PURE__ */ __name((queryParams) => {
199
+ const search = [];
200
+ if (queryParams && typeof queryParams === "object") {
201
+ for (const name in queryParams) {
202
+ const value = queryParams[name];
203
+ if (value === void 0 || value === null) {
204
+ continue;
205
+ }
206
+ if (Array.isArray(value)) {
207
+ const serializedArray = serializeArrayParam({
208
+ allowReserved,
209
+ explode: true,
210
+ name,
211
+ style: "form",
212
+ value,
213
+ ...array
214
+ });
215
+ if (serializedArray) search.push(serializedArray);
216
+ } else if (typeof value === "object") {
217
+ const serializedObject = serializeObjectParam({
218
+ allowReserved,
219
+ explode: true,
220
+ name,
221
+ style: "deepObject",
222
+ value,
223
+ ...object
224
+ });
225
+ if (serializedObject) search.push(serializedObject);
226
+ } else {
227
+ const serializedPrimitive = serializePrimitiveParam({
228
+ allowReserved,
229
+ name,
230
+ value
231
+ });
232
+ if (serializedPrimitive) search.push(serializedPrimitive);
233
+ }
234
+ }
235
+ }
236
+ return search.join("&");
237
+ }, "querySerializer");
238
+ return querySerializer;
239
+ }, "createQuerySerializer");
240
+ var getParseAs = /* @__PURE__ */ __name((contentType) => {
241
+ if (!contentType) {
242
+ return "stream";
243
+ }
244
+ const cleanContent = contentType.split(";")[0]?.trim();
245
+ if (!cleanContent) {
246
+ return;
247
+ }
248
+ if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) {
249
+ return "json";
250
+ }
251
+ if (cleanContent === "multipart/form-data") {
252
+ return "formData";
253
+ }
254
+ if ([
255
+ "application/",
256
+ "audio/",
257
+ "image/",
258
+ "video/"
259
+ ].some((type) => cleanContent.startsWith(type))) {
260
+ return "blob";
261
+ }
262
+ if (cleanContent.startsWith("text/")) {
263
+ return "text";
264
+ }
265
+ }, "getParseAs");
266
+ var setAuthParams = /* @__PURE__ */ __name(async ({ security, ...options }) => {
267
+ for (const auth of security) {
268
+ const token = await getAuthToken(auth, options.auth);
269
+ if (!token) {
270
+ continue;
271
+ }
272
+ const name = auth.name ?? "Authorization";
273
+ switch (auth.in) {
274
+ case "query":
275
+ if (!options.query) {
276
+ options.query = {};
277
+ }
278
+ options.query[name] = token;
279
+ break;
280
+ case "cookie":
281
+ options.headers.append("Cookie", `${name}=${token}`);
282
+ break;
283
+ case "header":
284
+ default:
285
+ options.headers.set(name, token);
286
+ break;
287
+ }
288
+ return;
289
+ }
290
+ }, "setAuthParams");
291
+ var buildUrl = /* @__PURE__ */ __name((options) => {
292
+ const url = getUrl({
293
+ baseUrl: options.baseUrl,
294
+ path: options.path,
295
+ query: options.query,
296
+ querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
297
+ url: options.url
298
+ });
299
+ return url;
300
+ }, "buildUrl");
301
+ var getUrl = /* @__PURE__ */ __name(({ baseUrl, path, query, querySerializer, url: _url }) => {
302
+ const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
303
+ let url = (baseUrl ?? "") + pathUrl;
304
+ if (path) {
305
+ url = defaultPathSerializer({
306
+ path,
307
+ url
308
+ });
309
+ }
310
+ let search = query ? querySerializer(query) : "";
311
+ if (search.startsWith("?")) {
312
+ search = search.substring(1);
313
+ }
314
+ if (search) {
315
+ url += `?${search}`;
316
+ }
317
+ return url;
318
+ }, "getUrl");
319
+ var mergeConfigs = /* @__PURE__ */ __name((a, b) => {
320
+ const config = {
321
+ ...a,
322
+ ...b
323
+ };
324
+ if (config.baseUrl?.endsWith("/")) {
325
+ config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
326
+ }
327
+ config.headers = mergeHeaders(a.headers, b.headers);
328
+ return config;
329
+ }, "mergeConfigs");
330
+ var mergeHeaders = /* @__PURE__ */ __name((...headers) => {
331
+ const mergedHeaders = new Headers();
332
+ for (const header of headers) {
333
+ if (!header || typeof header !== "object") {
334
+ continue;
335
+ }
336
+ const iterator = header instanceof Headers ? header.entries() : Object.entries(header);
337
+ for (const [key, value] of iterator) {
338
+ if (value === null) {
339
+ mergedHeaders.delete(key);
340
+ } else if (Array.isArray(value)) {
341
+ for (const v of value) {
342
+ mergedHeaders.append(key, v);
343
+ }
344
+ } else if (value !== void 0) {
345
+ mergedHeaders.set(key, typeof value === "object" ? JSON.stringify(value) : value);
346
+ }
347
+ }
348
+ }
349
+ return mergedHeaders;
350
+ }, "mergeHeaders");
351
+ var Interceptors = class Interceptors2 {
352
+ static {
353
+ __name(this, "Interceptors");
354
+ }
355
+ _fns;
356
+ constructor() {
357
+ this._fns = [];
358
+ }
359
+ clear() {
360
+ this._fns = [];
361
+ }
362
+ getInterceptorIndex(id) {
363
+ if (typeof id === "number") {
364
+ return this._fns[id] ? id : -1;
365
+ } else {
366
+ return this._fns.indexOf(id);
367
+ }
368
+ }
369
+ exists(id) {
370
+ const index = this.getInterceptorIndex(id);
371
+ return !!this._fns[index];
372
+ }
373
+ eject(id) {
374
+ const index = this.getInterceptorIndex(id);
375
+ if (this._fns[index]) {
376
+ this._fns[index] = null;
377
+ }
378
+ }
379
+ update(id, fn) {
380
+ const index = this.getInterceptorIndex(id);
381
+ if (this._fns[index]) {
382
+ this._fns[index] = fn;
383
+ return id;
384
+ } else {
385
+ return false;
386
+ }
387
+ }
388
+ use(fn) {
389
+ this._fns = [
390
+ ...this._fns,
391
+ fn
392
+ ];
393
+ return this._fns.length - 1;
394
+ }
395
+ };
396
+ var createInterceptors = /* @__PURE__ */ __name(() => ({
397
+ error: new Interceptors(),
398
+ request: new Interceptors(),
399
+ response: new Interceptors()
400
+ }), "createInterceptors");
401
+ var defaultQuerySerializer = createQuerySerializer({
402
+ allowReserved: false,
403
+ array: {
404
+ explode: true,
405
+ style: "form"
406
+ },
407
+ object: {
408
+ explode: true,
409
+ style: "deepObject"
410
+ }
411
+ });
412
+ var defaultHeaders = {
413
+ "Content-Type": "application/json"
414
+ };
415
+ var createConfig = /* @__PURE__ */ __name((override = {}) => ({
416
+ ...jsonBodySerializer,
417
+ headers: defaultHeaders,
418
+ parseAs: "auto",
419
+ querySerializer: defaultQuerySerializer,
420
+ ...override
421
+ }), "createConfig");
422
+
423
+ // src/client/client/client.ts
424
+ var createClient = /* @__PURE__ */ __name((config = {}) => {
425
+ let _config = mergeConfigs(createConfig(), config);
426
+ const getConfig = /* @__PURE__ */ __name(() => ({
427
+ ..._config
428
+ }), "getConfig");
429
+ const setConfig = /* @__PURE__ */ __name((config2) => {
430
+ _config = mergeConfigs(_config, config2);
431
+ return getConfig();
432
+ }, "setConfig");
433
+ const interceptors = createInterceptors();
434
+ const request = /* @__PURE__ */ __name(async (options) => {
435
+ const opts = {
436
+ ..._config,
437
+ ...options,
438
+ fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
439
+ headers: mergeHeaders(_config.headers, options.headers)
440
+ };
441
+ if (opts.security) {
442
+ await setAuthParams({
443
+ ...opts,
444
+ security: opts.security
445
+ });
446
+ }
447
+ if (opts.body && opts.bodySerializer) {
448
+ opts.body = opts.bodySerializer(opts.body);
449
+ }
450
+ if (opts.body === void 0 || opts.body === "") {
451
+ opts.headers.delete("Content-Type");
452
+ }
453
+ const url = buildUrl(opts);
454
+ const requestInit = {
455
+ redirect: "follow",
456
+ ...opts
457
+ };
458
+ let request2 = new Request(url, requestInit);
459
+ for (const fn of interceptors.request._fns) {
460
+ if (fn) {
461
+ request2 = await fn(request2, opts);
462
+ }
463
+ }
464
+ const _fetch = opts.fetch;
465
+ let response = await _fetch(request2);
466
+ for (const fn of interceptors.response._fns) {
467
+ if (fn) {
468
+ response = await fn(response, request2, opts);
469
+ }
470
+ }
471
+ const result = {
472
+ request: request2,
473
+ response
474
+ };
475
+ if (response.ok) {
476
+ if (response.status === 204 || response.headers.get("Content-Length") === "0") {
477
+ return opts.responseStyle === "data" ? {} : {
478
+ data: {},
479
+ ...result
480
+ };
481
+ }
482
+ const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
483
+ if (parseAs === "stream") {
484
+ return opts.responseStyle === "data" ? response.body : {
485
+ data: response.body,
486
+ ...result
487
+ };
488
+ }
489
+ let data = await response[parseAs]();
490
+ if (parseAs === "json") {
491
+ if (opts.responseValidator) {
492
+ await opts.responseValidator(data);
493
+ }
494
+ if (opts.responseTransformer) {
495
+ data = await opts.responseTransformer(data);
496
+ }
497
+ }
498
+ return opts.responseStyle === "data" ? data : {
499
+ data,
500
+ ...result
501
+ };
502
+ }
503
+ let error = await response.text();
504
+ try {
505
+ error = JSON.parse(error);
506
+ } catch {
507
+ }
508
+ let finalError = error;
509
+ for (const fn of interceptors.error._fns) {
510
+ if (fn) {
511
+ finalError = await fn(error, response, request2, opts);
512
+ }
513
+ }
514
+ finalError = finalError || {};
515
+ if (opts.throwOnError) {
516
+ throw finalError;
517
+ }
518
+ return opts.responseStyle === "data" ? void 0 : {
519
+ error: finalError,
520
+ ...result
521
+ };
522
+ }, "request");
523
+ return {
524
+ buildUrl,
525
+ connect: /* @__PURE__ */ __name((options) => request({
526
+ ...options,
527
+ method: "CONNECT"
528
+ }), "connect"),
529
+ delete: /* @__PURE__ */ __name((options) => request({
530
+ ...options,
531
+ method: "DELETE"
532
+ }), "delete"),
533
+ get: /* @__PURE__ */ __name((options) => request({
534
+ ...options,
535
+ method: "GET"
536
+ }), "get"),
537
+ getConfig,
538
+ head: /* @__PURE__ */ __name((options) => request({
539
+ ...options,
540
+ method: "HEAD"
541
+ }), "head"),
542
+ interceptors,
543
+ options: /* @__PURE__ */ __name((options) => request({
544
+ ...options,
545
+ method: "OPTIONS"
546
+ }), "options"),
547
+ patch: /* @__PURE__ */ __name((options) => request({
548
+ ...options,
549
+ method: "PATCH"
550
+ }), "patch"),
551
+ post: /* @__PURE__ */ __name((options) => request({
552
+ ...options,
553
+ method: "POST"
554
+ }), "post"),
555
+ put: /* @__PURE__ */ __name((options) => request({
556
+ ...options,
557
+ method: "PUT"
558
+ }), "put"),
559
+ request,
560
+ setConfig,
561
+ trace: /* @__PURE__ */ __name((options) => request({
562
+ ...options,
563
+ method: "TRACE"
564
+ }), "trace")
565
+ };
566
+ }, "createClient");
567
+
4
568
  // src/client/client.gen.ts
5
- import { createClient, createConfig } from "@hey-api/client-fetch";
6
569
  var client = createClient(createConfig());
7
570
 
8
571
  // src/client/sdk.gen.ts
@@ -30,7 +593,7 @@ var rewardsControllerDepositRewards = /* @__PURE__ */ __name((options) => {
30
593
  ...options,
31
594
  headers: {
32
595
  "Content-Type": "application/json",
33
- ...options?.headers
596
+ ...options.headers
34
597
  }
35
598
  });
36
599
  }, "rewardsControllerDepositRewards");
@@ -46,7 +609,7 @@ var rewardsControllerDistributeRewards = /* @__PURE__ */ __name((options) => {
46
609
  ...options,
47
610
  headers: {
48
611
  "Content-Type": "application/json",
49
- ...options?.headers
612
+ ...options.headers
50
613
  }
51
614
  });
52
615
  }, "rewardsControllerDistributeRewards");
@@ -62,7 +625,7 @@ var apiTokenControllerCreateToken = /* @__PURE__ */ __name((options) => {
62
625
  ...options,
63
626
  headers: {
64
627
  "Content-Type": "application/json",
65
- ...options?.headers
628
+ ...options.headers
66
629
  }
67
630
  });
68
631
  }, "apiTokenControllerCreateToken");
@@ -102,7 +665,7 @@ var apiTokenControllerUpdateToken = /* @__PURE__ */ __name((options) => {
102
665
  ...options,
103
666
  headers: {
104
667
  "Content-Type": "application/json",
105
- ...options?.headers
668
+ ...options.headers
106
669
  }
107
670
  });
108
671
  }, "apiTokenControllerUpdateToken");
@@ -118,7 +681,7 @@ var quotesControllerCreateQuote = /* @__PURE__ */ __name((options) => {
118
681
  ...options,
119
682
  headers: {
120
683
  "Content-Type": "application/json",
121
- ...options?.headers
684
+ ...options.headers
122
685
  }
123
686
  });
124
687
  }, "quotesControllerCreateQuote");
@@ -158,7 +721,7 @@ var flightsControllerCreatePresignedUrls = /* @__PURE__ */ __name((options) => {
158
721
  ...options,
159
722
  headers: {
160
723
  "Content-Type": "application/json",
161
- ...options?.headers
724
+ ...options.headers
162
725
  }
163
726
  });
164
727
  }, "flightsControllerCreatePresignedUrls");
@@ -174,7 +737,7 @@ var flightsControllerValidateFlight = /* @__PURE__ */ __name((options) => {
174
737
  ...options,
175
738
  headers: {
176
739
  "Content-Type": "application/json",
177
- ...options?.headers
740
+ ...options.headers
178
741
  }
179
742
  });
180
743
  }, "flightsControllerValidateFlight");
@@ -214,7 +777,7 @@ var webhooksControllerCreate = /* @__PURE__ */ __name((options) => {
214
777
  ...options,
215
778
  headers: {
216
779
  "Content-Type": "application/json",
217
- ...options?.headers
780
+ ...options.headers
218
781
  }
219
782
  });
220
783
  }, "webhooksControllerCreate");
@@ -254,7 +817,7 @@ var webhooksControllerUpdate = /* @__PURE__ */ __name((options) => {
254
817
  ...options,
255
818
  headers: {
256
819
  "Content-Type": "application/json",
257
- ...options?.headers
820
+ ...options.headers
258
821
  }
259
822
  });
260
823
  }, "webhooksControllerUpdate");
@@ -349,6 +912,7 @@ export {
349
912
  apiTokenControllerGetToken,
350
913
  apiTokenControllerUpdateToken,
351
914
  appControllerGetHello,
915
+ client,
352
916
  conditionsControllerGetSunAltitudeTimeLimits,
353
917
  flightsControllerCreatePresignedUrls,
354
918
  flightsControllerGenerateFlightId,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@layer-drone/protocol",
3
3
  "description": "Layer Drone protocol SDK with typed API client and event parsing",
4
- "version": "0.0.8",
4
+ "version": "0.0.9-alpha",
5
5
  "license": "MIT",
6
6
  "files": [
7
7
  "dist",
@@ -26,8 +26,8 @@
26
26
  "tsup": "^8.5.0",
27
27
  "typescript": "5.5.4",
28
28
  "zod": "^3.24.2",
29
- "@layer-drone/eslint-config": "0.0.0",
30
- "@layer-drone/typescript-config": "0.0.0"
29
+ "@layer-drone/typescript-config": "0.0.0",
30
+ "@layer-drone/eslint-config": "0.0.0"
31
31
  },
32
32
  "peerDependencies": {
33
33
  "zod": "^3.23.8"