@layer-drone/protocol 0.0.3

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/.eslintrc.js ADDED
@@ -0,0 +1,19 @@
1
+ /** @type {import("eslint").Linter.Config} */
2
+ module.exports = {
3
+ extends: ["@layer-drone/eslint-config/nest.js"],
4
+ parserOptions: {
5
+ project: "tsconfig.json",
6
+ tsconfigRootDir: __dirname,
7
+ sourceType: "module",
8
+ },
9
+ ignorePatterns: [
10
+ "*.config.ts",
11
+ ".*.js",
12
+ "*.setup.js",
13
+ "*.config.js",
14
+ ".turbo/",
15
+ "dist/",
16
+ "coverage/",
17
+ "node_modules/",
18
+ ],
19
+ };
package/.prettierrc.js ADDED
@@ -0,0 +1,4 @@
1
+ /** @type {import("prettier").Config} */
2
+ module.exports = {
3
+ ...require('@layer-drone/eslint-config/prettier-base'),
4
+ };
@@ -0,0 +1,18 @@
1
+
2
+ > @layer-drone/protocol@0.0.3 build /home/runner/work/layer-drone/layer-drone/packages/protocol
3
+ > tsup src/index.ts --format cjs,esm --dts
4
+
5
+ CLI Building entry: src/index.ts
6
+ CLI Using tsconfig: tsconfig.json
7
+ CLI tsup v8.5.0
8
+ CLI Target: es2022
9
+ CJS Build start
10
+ ESM Build start
11
+ ESM dist/index.mjs 8.29 KB
12
+ ESM ⚡️ Build success in 464ms
13
+ CJS dist/index.js 10.83 KB
14
+ CJS ⚡️ Build success in 472ms
15
+ DTS Build start
16
+ DTS ⚡️ Build success in 14801ms
17
+ DTS dist/index.d.ts 21.83 KB
18
+ DTS dist/index.d.mts 21.83 KB
@@ -0,0 +1,4 @@
1
+
2
+ > @layer-drone/protocol@0.0.3 lint /home/runner/work/layer-drone/layer-drone/packages/protocol
3
+ > eslint "{src,apps,libs,test}/**/*.ts"
4
+
package/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # @layer-drone/protocol
2
+
3
+ ## 0.0.3
4
+
5
+ ### Patch Changes
6
+
7
+ - d0acf8f: Add SDK support for getting webhook statuses
8
+ - d0acf8f: Add support for cjs and esm bundle output
@@ -0,0 +1,7 @@
1
+ import { defineConfig } from "@hey-api/openapi-ts";
2
+
3
+ export default defineConfig({
4
+ input: "http://localhost:5000/api-yaml",
5
+ output: "src/client",
6
+ plugins: ["@hey-api/client-fetch"],
7
+ });
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@layer-drone/protocol",
3
+ "version": "0.0.3",
4
+ "license": "MIT",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "dependencies": {
11
+ "@hey-api/client-fetch": "^0.8.3"
12
+ },
13
+ "devDependencies": {
14
+ "@hey-api/openapi-ts": "^0.64.11",
15
+ "@types/node": "^20.3.1",
16
+ "json-schema-to-zod": "^2.6.1",
17
+ "ts-loader": "^9.4.3",
18
+ "ts-node": "^10.9.2",
19
+ "tsup": "^8.5.0",
20
+ "typescript": "5.5.4",
21
+ "zod": "^3.24.2",
22
+ "@layer-drone/eslint-config": "0.0.0",
23
+ "@layer-drone/typescript-config": "0.0.0"
24
+ },
25
+ "peerDependencies": {
26
+ "zod": "^3.23.8"
27
+ },
28
+ "scripts": {
29
+ "build": "tsup src/index.ts --format cjs,esm --dts",
30
+ "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
31
+ "lint": "eslint \"{src,apps,libs,test}/**/*.ts\"",
32
+ "generate-api": "openapi-ts",
33
+ "generate-event": "ts-node ./scripts/generate-event-type.ts",
34
+ "generate": "pnpm generate-api && pnpm generate-event && pnpm lint --fix && pnpm build"
35
+ }
36
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * This script generates the event type from the protocol API.
3
+ * It fetches the event schema from the protocol API and converts it to a Zod schema.
4
+ * It then formats the schema and writes it to a file.
5
+ */
6
+ import { jsonSchemaToZod } from "json-schema-to-zod";
7
+ import fs from "node:fs";
8
+ import path from "node:path";
9
+ import { format } from "prettier";
10
+
11
+ async function generateEventType() {
12
+ const response = await fetch("http://localhost:5000/schema/event");
13
+ const schema = await response.json();
14
+ const zodSchema = jsonSchemaToZod(schema, {
15
+ name: "Event",
16
+ module: "esm",
17
+ type: true,
18
+ });
19
+ const header = `// This file is auto-generated by @layer-drone/protocol\n`;
20
+ const formatted = await format(header + zodSchema, { parser: "typescript" });
21
+ const outputPath = getOutputPath("types.gen.ts");
22
+ fs.writeFileSync(outputPath, formatted);
23
+ }
24
+
25
+ function getOutputPath(fileName: string) {
26
+ const outputPath = path.join(process.cwd(), "src", "event", fileName);
27
+ // Ensure the directory exists
28
+ const dirPath = path.dirname(outputPath);
29
+ if (!fs.existsSync(dirPath)) {
30
+ fs.mkdirSync(dirPath, { recursive: true });
31
+ }
32
+ return outputPath;
33
+ }
34
+
35
+ generateEventType();
@@ -0,0 +1,24 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+ import {
3
+ type Config,
4
+ type ClientOptions as DefaultClientOptions,
5
+ createClient,
6
+ createConfig,
7
+ } from "@hey-api/client-fetch";
8
+
9
+ import type { ClientOptions } from "./types.gen";
10
+
11
+ /**
12
+ * The `createClientConfig()` function will be called on client initialization
13
+ * and the returned object will become the client's initial configuration.
14
+ *
15
+ * You may want to initialize your client this way instead of calling
16
+ * `setConfig()`. This is useful for example if you're using Next.js
17
+ * to ensure your client always has the correct values.
18
+ */
19
+ export type CreateClientConfig<T extends DefaultClientOptions = ClientOptions> =
20
+ (
21
+ override?: Config<DefaultClientOptions & T>,
22
+ ) => Config<Required<DefaultClientOptions> & T>;
23
+
24
+ export const client = createClient(createConfig<ClientOptions>());
@@ -0,0 +1,3 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+ export * from "./types.gen";
3
+ export * from "./sdk.gen";
@@ -0,0 +1,464 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+ import type {
3
+ Client,
4
+ Options as ClientOptions,
5
+ TDataShape,
6
+ } from "@hey-api/client-fetch";
7
+
8
+ import { client as _heyApiClient } from "./client.gen";
9
+ import type {
10
+ ApiTokenControllerCreateTokenData,
11
+ ApiTokenControllerCreateTokenResponse,
12
+ ApiTokenControllerDeleteTokenData,
13
+ ApiTokenControllerGetTokenData,
14
+ ApiTokenControllerUpdateTokenData,
15
+ ApiTokenControllerUpdateTokenResponse,
16
+ AppControllerGetHelloData,
17
+ FlightsControllerCreatePresignedUrlsData,
18
+ FlightsControllerGenerateFlightIdData,
19
+ FlightsControllerValidateFlightData,
20
+ KeysControllerGetProvenanceCryptoKeyData,
21
+ KeysControllerGetProvenanceCryptoKeyResponse,
22
+ RewardsControllerDepositRewardsData,
23
+ RewardsControllerDepositRewardsResponse,
24
+ RewardsControllerDistributeRewardsData,
25
+ RewardsControllerDistributeRewardsResponse,
26
+ SchemaControllerGetEventSchemaData,
27
+ WebhooksControllerCreateData,
28
+ WebhooksControllerCreateResponse,
29
+ WebhooksControllerDeleteData,
30
+ WebhooksControllerDeleteResponse,
31
+ WebhooksControllerGetData,
32
+ WebhooksControllerGetManyData,
33
+ WebhooksControllerGetManyResponse,
34
+ WebhooksControllerGetResponse,
35
+ WebhooksControllerGetStatusData,
36
+ WebhooksControllerGetStatusResponse,
37
+ WebhooksControllerRegenerateSecretData,
38
+ WebhooksControllerRegenerateSecretResponse,
39
+ WebhooksControllerTestData,
40
+ WebhooksControllerTestResponse,
41
+ WebhooksControllerUpdateData,
42
+ WebhooksControllerUpdateResponse,
43
+ } from "./types.gen";
44
+
45
+ export type Options<
46
+ TData extends TDataShape = TDataShape,
47
+ ThrowOnError extends boolean = boolean,
48
+ > = ClientOptions<TData, ThrowOnError> & {
49
+ /**
50
+ * You can provide a client instance returned by `createClient()` instead of
51
+ * individual options. This might be also useful if you want to implement a
52
+ * custom client.
53
+ */
54
+ client?: Client;
55
+ /**
56
+ * You can pass arbitrary values through the `meta` object. This can be
57
+ * used to access values that aren't defined as part of the SDK function.
58
+ */
59
+ meta?: Record<string, unknown>;
60
+ };
61
+
62
+ export const appControllerGetHello = <ThrowOnError extends boolean = false>(
63
+ options?: Options<AppControllerGetHelloData, ThrowOnError>,
64
+ ) => {
65
+ return (options?.client ?? _heyApiClient).get<unknown, unknown, ThrowOnError>(
66
+ {
67
+ url: "/",
68
+ ...options,
69
+ },
70
+ );
71
+ };
72
+
73
+ export const keysControllerGetProvenanceCryptoKey = <
74
+ ThrowOnError extends boolean = false,
75
+ >(
76
+ options?: Options<KeysControllerGetProvenanceCryptoKeyData, ThrowOnError>,
77
+ ) => {
78
+ return (options?.client ?? _heyApiClient).get<
79
+ KeysControllerGetProvenanceCryptoKeyResponse,
80
+ unknown,
81
+ ThrowOnError
82
+ >({
83
+ url: "/keys",
84
+ ...options,
85
+ });
86
+ };
87
+
88
+ export const rewardsControllerDepositRewards = <
89
+ ThrowOnError extends boolean = false,
90
+ >(
91
+ options: Options<RewardsControllerDepositRewardsData, ThrowOnError>,
92
+ ) => {
93
+ return (options.client ?? _heyApiClient).post<
94
+ RewardsControllerDepositRewardsResponse,
95
+ unknown,
96
+ ThrowOnError
97
+ >({
98
+ security: [
99
+ {
100
+ name: "x-api-token",
101
+ type: "apiKey",
102
+ },
103
+ ],
104
+ url: "/rewards/deposit",
105
+ ...options,
106
+ headers: {
107
+ "Content-Type": "application/json",
108
+ ...options?.headers,
109
+ },
110
+ });
111
+ };
112
+
113
+ export const rewardsControllerDistributeRewards = <
114
+ ThrowOnError extends boolean = false,
115
+ >(
116
+ options: Options<RewardsControllerDistributeRewardsData, ThrowOnError>,
117
+ ) => {
118
+ return (options.client ?? _heyApiClient).post<
119
+ RewardsControllerDistributeRewardsResponse,
120
+ unknown,
121
+ ThrowOnError
122
+ >({
123
+ security: [
124
+ {
125
+ name: "x-api-token",
126
+ type: "apiKey",
127
+ },
128
+ ],
129
+ url: "/rewards/distribute",
130
+ ...options,
131
+ headers: {
132
+ "Content-Type": "application/json",
133
+ ...options?.headers,
134
+ },
135
+ });
136
+ };
137
+
138
+ export const apiTokenControllerCreateToken = <
139
+ ThrowOnError extends boolean = false,
140
+ >(
141
+ options: Options<ApiTokenControllerCreateTokenData, ThrowOnError>,
142
+ ) => {
143
+ return (options.client ?? _heyApiClient).post<
144
+ ApiTokenControllerCreateTokenResponse,
145
+ unknown,
146
+ ThrowOnError
147
+ >({
148
+ security: [
149
+ {
150
+ name: "x-api-token",
151
+ type: "apiKey",
152
+ },
153
+ ],
154
+ url: "/tokens",
155
+ ...options,
156
+ headers: {
157
+ "Content-Type": "application/json",
158
+ ...options?.headers,
159
+ },
160
+ });
161
+ };
162
+
163
+ export const apiTokenControllerDeleteToken = <
164
+ ThrowOnError extends boolean = false,
165
+ >(
166
+ options: Options<ApiTokenControllerDeleteTokenData, ThrowOnError>,
167
+ ) => {
168
+ return (options.client ?? _heyApiClient).delete<
169
+ unknown,
170
+ unknown,
171
+ ThrowOnError
172
+ >({
173
+ security: [
174
+ {
175
+ name: "x-api-token",
176
+ type: "apiKey",
177
+ },
178
+ ],
179
+ url: "/tokens/{id}",
180
+ ...options,
181
+ });
182
+ };
183
+
184
+ export const apiTokenControllerGetToken = <
185
+ ThrowOnError extends boolean = false,
186
+ >(
187
+ options: Options<ApiTokenControllerGetTokenData, ThrowOnError>,
188
+ ) => {
189
+ return (options.client ?? _heyApiClient).get<unknown, unknown, ThrowOnError>({
190
+ security: [
191
+ {
192
+ name: "x-api-token",
193
+ type: "apiKey",
194
+ },
195
+ ],
196
+ url: "/tokens/{id}",
197
+ ...options,
198
+ });
199
+ };
200
+
201
+ export const apiTokenControllerUpdateToken = <
202
+ ThrowOnError extends boolean = false,
203
+ >(
204
+ options: Options<ApiTokenControllerUpdateTokenData, ThrowOnError>,
205
+ ) => {
206
+ return (options.client ?? _heyApiClient).patch<
207
+ ApiTokenControllerUpdateTokenResponse,
208
+ unknown,
209
+ ThrowOnError
210
+ >({
211
+ security: [
212
+ {
213
+ name: "x-api-token",
214
+ type: "apiKey",
215
+ },
216
+ ],
217
+ url: "/tokens/{id}",
218
+ ...options,
219
+ headers: {
220
+ "Content-Type": "application/json",
221
+ ...options?.headers,
222
+ },
223
+ });
224
+ };
225
+
226
+ export const flightsControllerGenerateFlightId = <
227
+ ThrowOnError extends boolean = false,
228
+ >(
229
+ options: Options<FlightsControllerGenerateFlightIdData, ThrowOnError>,
230
+ ) => {
231
+ return (options.client ?? _heyApiClient).get<unknown, unknown, ThrowOnError>({
232
+ security: [
233
+ {
234
+ name: "x-api-token",
235
+ type: "apiKey",
236
+ },
237
+ ],
238
+ url: "/flights/id",
239
+ ...options,
240
+ });
241
+ };
242
+
243
+ export const flightsControllerCreatePresignedUrls = <
244
+ ThrowOnError extends boolean = false,
245
+ >(
246
+ options: Options<FlightsControllerCreatePresignedUrlsData, ThrowOnError>,
247
+ ) => {
248
+ return (options.client ?? _heyApiClient).post<unknown, unknown, ThrowOnError>(
249
+ {
250
+ security: [
251
+ {
252
+ name: "x-api-token",
253
+ type: "apiKey",
254
+ },
255
+ ],
256
+ url: "/flights/files",
257
+ ...options,
258
+ headers: {
259
+ "Content-Type": "application/json",
260
+ ...options?.headers,
261
+ },
262
+ },
263
+ );
264
+ };
265
+
266
+ export const flightsControllerValidateFlight = <
267
+ ThrowOnError extends boolean = false,
268
+ >(
269
+ options: Options<FlightsControllerValidateFlightData, ThrowOnError>,
270
+ ) => {
271
+ return (options.client ?? _heyApiClient).post<unknown, unknown, ThrowOnError>(
272
+ {
273
+ security: [
274
+ {
275
+ name: "x-api-token",
276
+ type: "apiKey",
277
+ },
278
+ ],
279
+ url: "/flights",
280
+ ...options,
281
+ headers: {
282
+ "Content-Type": "application/json",
283
+ ...options?.headers,
284
+ },
285
+ },
286
+ );
287
+ };
288
+
289
+ export const schemaControllerGetEventSchema = <
290
+ ThrowOnError extends boolean = false,
291
+ >(
292
+ options?: Options<SchemaControllerGetEventSchemaData, ThrowOnError>,
293
+ ) => {
294
+ return (options?.client ?? _heyApiClient).get<unknown, unknown, ThrowOnError>(
295
+ {
296
+ url: "/schema/event",
297
+ ...options,
298
+ },
299
+ );
300
+ };
301
+
302
+ export const webhooksControllerGetMany = <ThrowOnError extends boolean = false>(
303
+ options: Options<WebhooksControllerGetManyData, ThrowOnError>,
304
+ ) => {
305
+ return (options.client ?? _heyApiClient).get<
306
+ WebhooksControllerGetManyResponse,
307
+ unknown,
308
+ ThrowOnError
309
+ >({
310
+ security: [
311
+ {
312
+ name: "x-api-token",
313
+ type: "apiKey",
314
+ },
315
+ ],
316
+ url: "/org/{org_id}/webhooks",
317
+ ...options,
318
+ });
319
+ };
320
+
321
+ export const webhooksControllerCreate = <ThrowOnError extends boolean = false>(
322
+ options: Options<WebhooksControllerCreateData, ThrowOnError>,
323
+ ) => {
324
+ return (options.client ?? _heyApiClient).post<
325
+ WebhooksControllerCreateResponse,
326
+ unknown,
327
+ ThrowOnError
328
+ >({
329
+ security: [
330
+ {
331
+ name: "x-api-token",
332
+ type: "apiKey",
333
+ },
334
+ ],
335
+ url: "/org/{org_id}/webhooks",
336
+ ...options,
337
+ headers: {
338
+ "Content-Type": "application/json",
339
+ ...options?.headers,
340
+ },
341
+ });
342
+ };
343
+
344
+ export const webhooksControllerDelete = <ThrowOnError extends boolean = false>(
345
+ options: Options<WebhooksControllerDeleteData, ThrowOnError>,
346
+ ) => {
347
+ return (options.client ?? _heyApiClient).delete<
348
+ WebhooksControllerDeleteResponse,
349
+ unknown,
350
+ ThrowOnError
351
+ >({
352
+ security: [
353
+ {
354
+ name: "x-api-token",
355
+ type: "apiKey",
356
+ },
357
+ ],
358
+ url: "/org/{org_id}/webhooks/{id}",
359
+ ...options,
360
+ });
361
+ };
362
+
363
+ export const webhooksControllerGet = <ThrowOnError extends boolean = false>(
364
+ options: Options<WebhooksControllerGetData, ThrowOnError>,
365
+ ) => {
366
+ return (options.client ?? _heyApiClient).get<
367
+ WebhooksControllerGetResponse,
368
+ unknown,
369
+ ThrowOnError
370
+ >({
371
+ security: [
372
+ {
373
+ name: "x-api-token",
374
+ type: "apiKey",
375
+ },
376
+ ],
377
+ url: "/org/{org_id}/webhooks/{id}",
378
+ ...options,
379
+ });
380
+ };
381
+
382
+ export const webhooksControllerUpdate = <ThrowOnError extends boolean = false>(
383
+ options: Options<WebhooksControllerUpdateData, ThrowOnError>,
384
+ ) => {
385
+ return (options.client ?? _heyApiClient).put<
386
+ WebhooksControllerUpdateResponse,
387
+ unknown,
388
+ ThrowOnError
389
+ >({
390
+ security: [
391
+ {
392
+ name: "x-api-token",
393
+ type: "apiKey",
394
+ },
395
+ ],
396
+ url: "/org/{org_id}/webhooks/{id}",
397
+ ...options,
398
+ headers: {
399
+ "Content-Type": "application/json",
400
+ ...options?.headers,
401
+ },
402
+ });
403
+ };
404
+
405
+ export const webhooksControllerRegenerateSecret = <
406
+ ThrowOnError extends boolean = false,
407
+ >(
408
+ options: Options<WebhooksControllerRegenerateSecretData, ThrowOnError>,
409
+ ) => {
410
+ return (options.client ?? _heyApiClient).post<
411
+ WebhooksControllerRegenerateSecretResponse,
412
+ unknown,
413
+ ThrowOnError
414
+ >({
415
+ security: [
416
+ {
417
+ name: "x-api-token",
418
+ type: "apiKey",
419
+ },
420
+ ],
421
+ url: "/org/{org_id}/webhooks/{id}/regenerate-secret",
422
+ ...options,
423
+ });
424
+ };
425
+
426
+ export const webhooksControllerTest = <ThrowOnError extends boolean = false>(
427
+ options: Options<WebhooksControllerTestData, ThrowOnError>,
428
+ ) => {
429
+ return (options.client ?? _heyApiClient).post<
430
+ WebhooksControllerTestResponse,
431
+ unknown,
432
+ ThrowOnError
433
+ >({
434
+ security: [
435
+ {
436
+ name: "x-api-token",
437
+ type: "apiKey",
438
+ },
439
+ ],
440
+ url: "/org/{org_id}/webhooks/{id}/test",
441
+ ...options,
442
+ });
443
+ };
444
+
445
+ export const webhooksControllerGetStatus = <
446
+ ThrowOnError extends boolean = false,
447
+ >(
448
+ options: Options<WebhooksControllerGetStatusData, ThrowOnError>,
449
+ ) => {
450
+ return (options.client ?? _heyApiClient).get<
451
+ WebhooksControllerGetStatusResponse,
452
+ unknown,
453
+ ThrowOnError
454
+ >({
455
+ security: [
456
+ {
457
+ name: "x-api-token",
458
+ type: "apiKey",
459
+ },
460
+ ],
461
+ url: "/org/{org_id}/webhooks/{id}/status",
462
+ ...options,
463
+ });
464
+ };
@@ -0,0 +1,551 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+
3
+ export type GetProvenanceCryptoKeyResponse = {
4
+ KeyId: string;
5
+ PublicKey: string;
6
+ KeySpec?:
7
+ | "ECC_NIST_P256"
8
+ | "ECC_NIST_P384"
9
+ | "ECC_NIST_P521"
10
+ | "ECC_SECG_P256K1"
11
+ | "HMAC_224"
12
+ | "HMAC_256"
13
+ | "HMAC_384"
14
+ | "HMAC_512"
15
+ | "RSA_2048"
16
+ | "RSA_3072"
17
+ | "RSA_4096"
18
+ | "SM2"
19
+ | "SYMMETRIC_DEFAULT";
20
+ KeyUsage?:
21
+ | "ENCRYPT_DECRYPT"
22
+ | "GENERATE_VERIFY_MAC"
23
+ | "KEY_AGREEMENT"
24
+ | "SIGN_VERIFY";
25
+ EncryptionAlgorithms?: Array<
26
+ "RSAES_OAEP_SHA_1" | "RSAES_OAEP_SHA_256" | "SM2PKE" | "SYMMETRIC_DEFAULT"
27
+ >;
28
+ };
29
+
30
+ export type DepositRewardsRequestDto = {
31
+ caller: string;
32
+ /**
33
+ * An integer where the last 18 places are decimal places
34
+ */
35
+ amount: number;
36
+ vaultId: number;
37
+ vaultManagerAddress?: string;
38
+ };
39
+
40
+ export type DepositRewardsResponseDto = {
41
+ MessageId: string;
42
+ };
43
+
44
+ export type DistributeRewardsRequestDto = {
45
+ amounts: {
46
+ [key: string]: number;
47
+ };
48
+ };
49
+
50
+ export type DistributeRewardsResponseDto = {
51
+ MessageId: string;
52
+ };
53
+
54
+ export type CreateApiTokenResponseDto = {
55
+ id: string;
56
+ name: string;
57
+ deleted_at: string | null;
58
+ last_used: string | null;
59
+ org: number;
60
+ scopes: Array<
61
+ "manageTokens" | "manageFlights" | "manageWebhooks" | "all"
62
+ > | null;
63
+ };
64
+
65
+ export type CreateApiTokenRequestDto = {
66
+ name: string;
67
+ scopes: Array<"manageTokens" | "manageFlights" | "manageWebhooks" | "all">;
68
+ orgId: number;
69
+ };
70
+
71
+ export type UpdateApiTokenRequestDto = {
72
+ name?: string;
73
+ scopes?: Array<"manageTokens" | "manageFlights" | "manageWebhooks" | "all">;
74
+ };
75
+
76
+ export type UpdateApiTokenResponseDto = {
77
+ id: string;
78
+ name: string;
79
+ deleted_at: string | null;
80
+ last_used: string | null;
81
+ org: number;
82
+ scopes: Array<
83
+ "manageTokens" | "manageFlights" | "manageWebhooks" | "all"
84
+ > | null;
85
+ };
86
+
87
+ export type CreateFileRequestDto = {
88
+ filenames: Array<string>;
89
+ flightId: number;
90
+ };
91
+
92
+ export type ValidateFlightDto = {
93
+ pilotAddress: string;
94
+ flightId: number;
95
+ flightManifestUri?: string;
96
+ };
97
+
98
+ export type CreateWebhookBody = {
99
+ name: string;
100
+ url: string;
101
+ event_types: Array<"test" | "protocol.flight.submitted" | "*">;
102
+ active: boolean;
103
+ };
104
+
105
+ export type CreateWebhookResponse = {
106
+ id: number;
107
+ secret: string;
108
+ };
109
+
110
+ export type GetWebhooksResponse = Array<{
111
+ id: number;
112
+ name: string;
113
+ url: string;
114
+ event_types: Array<"test" | "protocol.flight.submitted" | "*">;
115
+ active: boolean;
116
+ failure_count: number;
117
+ last_failure_reason: string | null;
118
+ created_at: string;
119
+ updated_at: string;
120
+ }>;
121
+
122
+ export type GetWebhookResponse = {
123
+ id: number;
124
+ name: string;
125
+ url: string;
126
+ event_types: Array<"test" | "protocol.flight.submitted" | "*">;
127
+ active: boolean;
128
+ failure_count: number;
129
+ last_failure_reason: string | null;
130
+ created_at: string;
131
+ updated_at: string;
132
+ };
133
+
134
+ export type UpdateWebhookBody = {
135
+ name?: string;
136
+ url?: string;
137
+ event_types?: Array<"test" | "protocol.flight.submitted" | "*">;
138
+ active?: boolean;
139
+ };
140
+
141
+ export type UpdateWebhookResponse = {
142
+ id: number;
143
+ name: string;
144
+ url: string;
145
+ event_types: Array<"test" | "protocol.flight.submitted" | "*">;
146
+ active: boolean;
147
+ failure_count: number;
148
+ last_failure_reason: string | null;
149
+ created_at: string;
150
+ updated_at: string;
151
+ };
152
+
153
+ export type DeleteWebhookResponse = {
154
+ message: string;
155
+ };
156
+
157
+ export type RegenerateWebhookSecretResponseDto = {
158
+ secret: string;
159
+ };
160
+
161
+ export type TestWebhookResponse = {
162
+ success: boolean;
163
+ };
164
+
165
+ export type GetWebhookStatusResponse = {
166
+ status: "inactive" | "error" | "connected" | "connecting";
167
+ error?: string | null;
168
+ };
169
+
170
+ export type AppControllerGetHelloData = {
171
+ body?: never;
172
+ path?: never;
173
+ query?: never;
174
+ url: "/";
175
+ };
176
+
177
+ export type AppControllerGetHelloResponses = {
178
+ 200: unknown;
179
+ };
180
+
181
+ export type KeysControllerGetProvenanceCryptoKeyData = {
182
+ body?: never;
183
+ path?: never;
184
+ query?: never;
185
+ url: "/keys";
186
+ };
187
+
188
+ export type KeysControllerGetProvenanceCryptoKeyResponses = {
189
+ 200: GetProvenanceCryptoKeyResponse;
190
+ };
191
+
192
+ export type KeysControllerGetProvenanceCryptoKeyResponse =
193
+ KeysControllerGetProvenanceCryptoKeyResponses[keyof KeysControllerGetProvenanceCryptoKeyResponses];
194
+
195
+ export type RewardsControllerDepositRewardsData = {
196
+ body: DepositRewardsRequestDto;
197
+ path?: never;
198
+ query?: never;
199
+ url: "/rewards/deposit";
200
+ };
201
+
202
+ export type RewardsControllerDepositRewardsErrors = {
203
+ 401: unknown;
204
+ 403: unknown;
205
+ };
206
+
207
+ export type RewardsControllerDepositRewardsResponses = {
208
+ 200: DepositRewardsResponseDto;
209
+ };
210
+
211
+ export type RewardsControllerDepositRewardsResponse =
212
+ RewardsControllerDepositRewardsResponses[keyof RewardsControllerDepositRewardsResponses];
213
+
214
+ export type RewardsControllerDistributeRewardsData = {
215
+ body: DistributeRewardsRequestDto;
216
+ path?: never;
217
+ query?: never;
218
+ url: "/rewards/distribute";
219
+ };
220
+
221
+ export type RewardsControllerDistributeRewardsErrors = {
222
+ 401: unknown;
223
+ 403: unknown;
224
+ };
225
+
226
+ export type RewardsControllerDistributeRewardsResponses = {
227
+ 200: DistributeRewardsResponseDto;
228
+ };
229
+
230
+ export type RewardsControllerDistributeRewardsResponse =
231
+ RewardsControllerDistributeRewardsResponses[keyof RewardsControllerDistributeRewardsResponses];
232
+
233
+ export type ApiTokenControllerCreateTokenData = {
234
+ body: CreateApiTokenRequestDto;
235
+ path?: never;
236
+ query?: never;
237
+ url: "/tokens";
238
+ };
239
+
240
+ export type ApiTokenControllerCreateTokenErrors = {
241
+ 401: unknown;
242
+ 403: unknown;
243
+ };
244
+
245
+ export type ApiTokenControllerCreateTokenResponses = {
246
+ 200: CreateApiTokenResponseDto;
247
+ 201: unknown;
248
+ };
249
+
250
+ export type ApiTokenControllerCreateTokenResponse =
251
+ ApiTokenControllerCreateTokenResponses[keyof ApiTokenControllerCreateTokenResponses];
252
+
253
+ export type ApiTokenControllerDeleteTokenData = {
254
+ body?: never;
255
+ path: {
256
+ id: string;
257
+ };
258
+ query?: never;
259
+ url: "/tokens/{id}";
260
+ };
261
+
262
+ export type ApiTokenControllerDeleteTokenErrors = {
263
+ 401: unknown;
264
+ 403: unknown;
265
+ };
266
+
267
+ export type ApiTokenControllerDeleteTokenResponses = {
268
+ 200: unknown;
269
+ };
270
+
271
+ export type ApiTokenControllerGetTokenData = {
272
+ body?: never;
273
+ path: {
274
+ id: string;
275
+ };
276
+ query?: never;
277
+ url: "/tokens/{id}";
278
+ };
279
+
280
+ export type ApiTokenControllerGetTokenErrors = {
281
+ 401: unknown;
282
+ 403: unknown;
283
+ };
284
+
285
+ export type ApiTokenControllerGetTokenResponses = {
286
+ 200: unknown;
287
+ };
288
+
289
+ export type ApiTokenControllerUpdateTokenData = {
290
+ body: UpdateApiTokenRequestDto;
291
+ path: {
292
+ id: string;
293
+ };
294
+ query?: never;
295
+ url: "/tokens/{id}";
296
+ };
297
+
298
+ export type ApiTokenControllerUpdateTokenErrors = {
299
+ 401: unknown;
300
+ 403: unknown;
301
+ };
302
+
303
+ export type ApiTokenControllerUpdateTokenResponses = {
304
+ 200: UpdateApiTokenResponseDto;
305
+ };
306
+
307
+ export type ApiTokenControllerUpdateTokenResponse =
308
+ ApiTokenControllerUpdateTokenResponses[keyof ApiTokenControllerUpdateTokenResponses];
309
+
310
+ export type FlightsControllerGenerateFlightIdData = {
311
+ body?: never;
312
+ path?: never;
313
+ query: {
314
+ missionId: number;
315
+ pilotAddress: string;
316
+ };
317
+ url: "/flights/id";
318
+ };
319
+
320
+ export type FlightsControllerGenerateFlightIdErrors = {
321
+ 401: unknown;
322
+ 403: unknown;
323
+ };
324
+
325
+ export type FlightsControllerGenerateFlightIdResponses = {
326
+ 200: unknown;
327
+ };
328
+
329
+ export type FlightsControllerCreatePresignedUrlsData = {
330
+ body: CreateFileRequestDto;
331
+ path?: never;
332
+ query?: never;
333
+ url: "/flights/files";
334
+ };
335
+
336
+ export type FlightsControllerCreatePresignedUrlsErrors = {
337
+ 401: unknown;
338
+ 403: unknown;
339
+ };
340
+
341
+ export type FlightsControllerCreatePresignedUrlsResponses = {
342
+ 201: unknown;
343
+ };
344
+
345
+ export type FlightsControllerValidateFlightData = {
346
+ body: ValidateFlightDto;
347
+ path?: never;
348
+ query?: never;
349
+ url: "/flights";
350
+ };
351
+
352
+ export type FlightsControllerValidateFlightErrors = {
353
+ 401: unknown;
354
+ 403: unknown;
355
+ };
356
+
357
+ export type FlightsControllerValidateFlightResponses = {
358
+ 201: unknown;
359
+ };
360
+
361
+ export type SchemaControllerGetEventSchemaData = {
362
+ body?: never;
363
+ path?: never;
364
+ query?: never;
365
+ url: "/schema/event";
366
+ };
367
+
368
+ export type SchemaControllerGetEventSchemaResponses = {
369
+ /**
370
+ * Get event schema
371
+ */
372
+ 200: unknown;
373
+ };
374
+
375
+ export type WebhooksControllerGetManyData = {
376
+ body?: never;
377
+ path: {
378
+ org_id: number;
379
+ };
380
+ query?: never;
381
+ url: "/org/{org_id}/webhooks";
382
+ };
383
+
384
+ export type WebhooksControllerGetManyErrors = {
385
+ 401: unknown;
386
+ 403: unknown;
387
+ };
388
+
389
+ export type WebhooksControllerGetManyResponses = {
390
+ 200: GetWebhooksResponse;
391
+ };
392
+
393
+ export type WebhooksControllerGetManyResponse =
394
+ WebhooksControllerGetManyResponses[keyof WebhooksControllerGetManyResponses];
395
+
396
+ export type WebhooksControllerCreateData = {
397
+ body: CreateWebhookBody;
398
+ path: {
399
+ org_id: number;
400
+ };
401
+ query?: never;
402
+ url: "/org/{org_id}/webhooks";
403
+ };
404
+
405
+ export type WebhooksControllerCreateErrors = {
406
+ 401: unknown;
407
+ 403: unknown;
408
+ };
409
+
410
+ export type WebhooksControllerCreateResponses = {
411
+ 201: CreateWebhookResponse;
412
+ };
413
+
414
+ export type WebhooksControllerCreateResponse =
415
+ WebhooksControllerCreateResponses[keyof WebhooksControllerCreateResponses];
416
+
417
+ export type WebhooksControllerDeleteData = {
418
+ body?: never;
419
+ path: {
420
+ org_id: number;
421
+ id: number;
422
+ };
423
+ query?: never;
424
+ url: "/org/{org_id}/webhooks/{id}";
425
+ };
426
+
427
+ export type WebhooksControllerDeleteErrors = {
428
+ 401: unknown;
429
+ 403: unknown;
430
+ };
431
+
432
+ export type WebhooksControllerDeleteResponses = {
433
+ 200: DeleteWebhookResponse;
434
+ };
435
+
436
+ export type WebhooksControllerDeleteResponse =
437
+ WebhooksControllerDeleteResponses[keyof WebhooksControllerDeleteResponses];
438
+
439
+ export type WebhooksControllerGetData = {
440
+ body?: never;
441
+ path: {
442
+ org_id: number;
443
+ id: number;
444
+ };
445
+ query?: never;
446
+ url: "/org/{org_id}/webhooks/{id}";
447
+ };
448
+
449
+ export type WebhooksControllerGetErrors = {
450
+ 401: unknown;
451
+ 403: unknown;
452
+ };
453
+
454
+ export type WebhooksControllerGetResponses = {
455
+ 200: GetWebhookResponse;
456
+ };
457
+
458
+ export type WebhooksControllerGetResponse =
459
+ WebhooksControllerGetResponses[keyof WebhooksControllerGetResponses];
460
+
461
+ export type WebhooksControllerUpdateData = {
462
+ body: UpdateWebhookBody;
463
+ path: {
464
+ org_id: number;
465
+ id: number;
466
+ };
467
+ query?: never;
468
+ url: "/org/{org_id}/webhooks/{id}";
469
+ };
470
+
471
+ export type WebhooksControllerUpdateErrors = {
472
+ 401: unknown;
473
+ 403: unknown;
474
+ };
475
+
476
+ export type WebhooksControllerUpdateResponses = {
477
+ 200: UpdateWebhookResponse;
478
+ };
479
+
480
+ export type WebhooksControllerUpdateResponse =
481
+ WebhooksControllerUpdateResponses[keyof WebhooksControllerUpdateResponses];
482
+
483
+ export type WebhooksControllerRegenerateSecretData = {
484
+ body?: never;
485
+ path: {
486
+ org_id: number;
487
+ id: number;
488
+ };
489
+ query?: never;
490
+ url: "/org/{org_id}/webhooks/{id}/regenerate-secret";
491
+ };
492
+
493
+ export type WebhooksControllerRegenerateSecretErrors = {
494
+ 401: unknown;
495
+ 403: unknown;
496
+ };
497
+
498
+ export type WebhooksControllerRegenerateSecretResponses = {
499
+ 200: RegenerateWebhookSecretResponseDto;
500
+ };
501
+
502
+ export type WebhooksControllerRegenerateSecretResponse =
503
+ WebhooksControllerRegenerateSecretResponses[keyof WebhooksControllerRegenerateSecretResponses];
504
+
505
+ export type WebhooksControllerTestData = {
506
+ body?: never;
507
+ path: {
508
+ org_id: number;
509
+ id: number;
510
+ };
511
+ query?: never;
512
+ url: "/org/{org_id}/webhooks/{id}/test";
513
+ };
514
+
515
+ export type WebhooksControllerTestErrors = {
516
+ 401: unknown;
517
+ 403: unknown;
518
+ };
519
+
520
+ export type WebhooksControllerTestResponses = {
521
+ 200: TestWebhookResponse;
522
+ };
523
+
524
+ export type WebhooksControllerTestResponse =
525
+ WebhooksControllerTestResponses[keyof WebhooksControllerTestResponses];
526
+
527
+ export type WebhooksControllerGetStatusData = {
528
+ body?: never;
529
+ path: {
530
+ org_id: number;
531
+ id: number;
532
+ };
533
+ query?: never;
534
+ url: "/org/{org_id}/webhooks/{id}/status";
535
+ };
536
+
537
+ export type WebhooksControllerGetStatusErrors = {
538
+ 401: unknown;
539
+ 403: unknown;
540
+ };
541
+
542
+ export type WebhooksControllerGetStatusResponses = {
543
+ 200: GetWebhookStatusResponse;
544
+ };
545
+
546
+ export type WebhooksControllerGetStatusResponse =
547
+ WebhooksControllerGetStatusResponses[keyof WebhooksControllerGetStatusResponses];
548
+
549
+ export type ClientOptions = {
550
+ baseUrl: string;
551
+ };
@@ -0,0 +1,2 @@
1
+ export * from "./types.gen";
2
+ export * from "./parser";
@@ -0,0 +1,19 @@
1
+ import { Event } from "./types.gen";
2
+
3
+ const WEBHOOK_SECRET_HEADER = "X-Webhook-Secret";
4
+
5
+ export function parseWebhookEvent(req: Request, webhookSecret: string) {
6
+ const secret: string | undefined =
7
+ req.headers[WEBHOOK_SECRET_HEADER] ||
8
+ req.headers[WEBHOOK_SECRET_HEADER.toLowerCase()];
9
+ if (typeof secret !== "string") {
10
+ throw new Error("Webhook request signature is not a string");
11
+ }
12
+ if (!Buffer.isBuffer(req.body)) {
13
+ throw new Error("Webhook request body is not a Buffer");
14
+ }
15
+ if (secret !== webhookSecret) {
16
+ throw new Error("Invalid webhook secret");
17
+ }
18
+ return Event.parse(JSON.parse(req.body.toString("utf-8")));
19
+ }
@@ -0,0 +1,28 @@
1
+ // This file is auto-generated by @layer-drone/protocol
2
+ import { z } from "zod";
3
+
4
+ export const Event = z.union([
5
+ z
6
+ .object({
7
+ id: z.string(),
8
+ event_type: z.literal("test"),
9
+ timestamp: z.string(),
10
+ data: z.object({ message: z.string() }).strict(),
11
+ })
12
+ .strict(),
13
+ z
14
+ .object({
15
+ id: z.any(),
16
+ event_type: z.literal("protocol.flight.submitted"),
17
+ timestamp: z.any(),
18
+ data: z
19
+ .object({
20
+ flightId: z.number(),
21
+ pilotAddress: z.string(),
22
+ flightManifestUri: z.string(),
23
+ })
24
+ .strict(),
25
+ })
26
+ .strict(),
27
+ ]);
28
+ export type Event = z.infer<typeof Event>;
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./client";
2
+ export * from "./event";
package/tsconfig.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "extends": "@layer-drone/typescript-config/nestjs.json",
3
+ "compilerOptions": {
4
+ "allowJs": true,
5
+ "baseUrl": "./src",
6
+ "outDir": "./dist",
7
+ "esModuleInterop": true,
8
+ "incremental": false
9
+ },
10
+ "include": ["src"],
11
+ "exclude": ["node_modules", "test", "dist", "scripts", "**/*spec.ts"]
12
+ }