@layer-drone/protocol 0.6.0 → 0.7.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 CHANGED
@@ -1,43 +1,114 @@
1
- # Protocol SDK Test Setup
1
+ # LayerDrone Protocol SDK
2
2
 
3
- This directory contains comprehensive tests for the Layer Drone Protocol SDK that validate SDK functionality using mocks and simulated API responses.
3
+ Published as [`@layer-drone/protocol`](https://www.npmjs.com/package/@layer-drone/protocol).
4
4
 
5
- ## Test Configuration
5
+ ## Description
6
6
 
7
- The tests are designed to be completely self-contained and run seamlessly in CI/CD environments without any external dependencies. All API interactions are mocked to ensure reliable, fast test execution.
7
+ This SDK provides a typed client for using LayerDrone's REST API and parsing webhook events.
8
8
 
9
- ## Running Tests
9
+ ## Philosophy
10
10
 
11
- ### Standard Test Run
12
- ```bash
13
- # Run all tests with mocks
14
- pnpm test
11
+ The LayerDrone protocol exists as a hybrid of on and off-chain functionality. This helps strike
12
+ the right balance of transparency, speed, and familiarity.
13
+
14
+ - Objects related to missions & reward entitlement are recorded on-chain
15
+ - Off-chain indexing supports non-critical data outside of smart contracts, keeping gas usage low
16
+ - A REST API and webhook broadcaster offer a familiar facade over aggregated on & off-chain data
17
+
18
+ ## Installation
19
+
20
+ ```sh
21
+ $ npm install @layer-drone/protocol
15
22
  ```
16
23
 
17
- ### With Coverage
18
- ```bash
19
- # Run tests with coverage reporting
20
- pnpm test:coverage
24
+ ## Usage
25
+
26
+ ### Getting an API key
27
+
28
+ Organizations and API keys are provisioned manually for private use only at the moment.
29
+
30
+ ### Making API calls
31
+
32
+ ```ts
33
+ import * as LayerDrone from "@layer-drone/protocol";
34
+
35
+ const client = LayerDrone.createClient({
36
+ baseUrl: env.PROTOCOL_API_URL,
37
+ auth: env.PROTOCOL_API_KEY,
38
+ });
39
+
40
+ // Submit a flight for validation
41
+ const response = await LayerDrone.flightsControllerValidateFlight({
42
+ client,
43
+ body: {
44
+ storageKey: "s3://layerdrone-flights-staging/12345",
45
+ pilotAddress: "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb1",
46
+ missionId: 123n,
47
+ flightTimestamp: "2023-10-15T14:25:30.123Z",
48
+ flightRequestInfo: {
49
+ flightPlanId: 2,
50
+ filePaths: [
51
+ "images/IMG_0001.JPG",
52
+ "images/IMG_0002.JPG",
53
+ "images/IMG_0003.JPG",
54
+ ],
55
+ zoneHash: "https://explorer.spexi.com/zone/8928de8de43ffff",
56
+ provenancePath: "provenance.json",
57
+ },
58
+ },
59
+ });
21
60
  ```
22
61
 
23
- ## Test Coverage
62
+ ### Registering webhooks
63
+
64
+ The SDK supports registering webhooks via the API.
24
65
 
25
- The test suite includes:
66
+ ```ts
67
+ import * as LayerDrone from "@layer-drone/protocol";
26
68
 
27
- 1. **Client Creation and Configuration** - SDK initialization and configuration
28
- 2. **API Integration Tests** - Tests using mocked API responses:
29
- - Health check endpoint (`/`)
30
- - Sun altitude calculations (`/conditions/sun-altitude`)
31
- - Event schema retrieval (`/schema/event`)
32
- 3. **Error Handling** - Network errors, 404s, invalid parameters
33
- 4. **Response Styles** - Data-only vs full response formats
34
- 5. **Event Parsing** - Webhook event validation and parsing
35
- 6. **Integration Tests** - Complete workflows using mocks:
36
- - Flight workflow (storage key generation, presigned URLs, validation)
37
- - API token management (CRUD operations)
38
- - Mission creation workflow
39
- 7. **Type Safety** - TypeScript type validation and BigInt handling
69
+ const client = LayerDrone.createClient({
70
+ baseUrl: process.env.PROTOCOL_API_URL!,
71
+ auth: process.env.PROTOCOL_API_KEY!,
72
+ });
40
73
 
41
- ## SonarQube Integration
74
+ const webhook = await LayerDrone.webhooksControllerCreate({
75
+ client,
76
+ path: { org_id: 1 },
77
+ body: {
78
+ name: "MyOrg Webhook",
79
+ url: "https://api.example.com/webhooks/layer-drone",
80
+ event_types: ["protocol.flight.reviewed"],
81
+ active: true,
82
+ },
83
+ });
42
84
 
43
- Test coverage is automatically included in SonarQube scans via the LCOV report at `./coverage/lcov.info`.
85
+ // `webhook.id` is the config id. `webhook.secret` is the value LayerDrone
86
+ // will send on each request as the X-Webhook-Secret header.
87
+ ```
88
+
89
+ ### Receiving webhook events
90
+
91
+ Your API can parse webhook payloads at a registered endpoint.
92
+
93
+ ```ts
94
+ import type { Request, Response } from "express";
95
+
96
+ import { parseWebhookEvent } from "@layer-drone/protocol";
97
+
98
+ class MyController {
99
+ async handleLayerDroneWebhookEvent(req: Request, res: Response) {
100
+ const event = parseWebhookEvent(req, process.env.LAYERDRONE_WEBHOOK_SECRET);
101
+
102
+ let message = "Event received";
103
+ switch (event.event_type) {
104
+ case "protocol.flight.reviewed":
105
+ // handle narrowed event type
106
+ break;
107
+ default:
108
+ message = `Handler for ${event.event_type} not implemented`;
109
+ }
110
+
111
+ res.status(200).send({ message });
112
+ }
113
+ }
114
+ ```
package/dist/index.js CHANGED
@@ -882,9 +882,13 @@ var getMissionResponseDtoSchemaResponseTransformer = /* @__PURE__ */ __name((dat
882
882
  data.captureEndTime = new Date(data.captureEndTime);
883
883
  data.createdAt = new Date(data.createdAt);
884
884
  data.updatedAt = new Date(data.updatedAt);
885
- data.payout.createdAt = new Date(data.payout.createdAt);
886
- data.vault.createdAt = new Date(data.vault.createdAt);
887
- data.vault.updatedAt = new Date(data.vault.updatedAt);
885
+ if (data.payout) {
886
+ data.payout.createdAt = new Date(data.payout.createdAt);
887
+ }
888
+ if (data.vault) {
889
+ data.vault.createdAt = new Date(data.vault.createdAt);
890
+ data.vault.updatedAt = new Date(data.vault.updatedAt);
891
+ }
888
892
  return data;
889
893
  }, "getMissionResponseDtoSchemaResponseTransformer");
890
894
  var missionsControllerGetMissionResponseTransformer = /* @__PURE__ */ __name(async (data) => {
@@ -897,9 +901,13 @@ var getMissionsResponseDtoSchemaResponseTransformer = /* @__PURE__ */ __name((da
897
901
  item.captureEndTime = new Date(item.captureEndTime);
898
902
  item.createdAt = new Date(item.createdAt);
899
903
  item.updatedAt = new Date(item.updatedAt);
900
- item.payout.createdAt = new Date(item.payout.createdAt);
901
- item.vault.createdAt = new Date(item.vault.createdAt);
902
- item.vault.updatedAt = new Date(item.vault.updatedAt);
904
+ if (item.payout) {
905
+ item.payout.createdAt = new Date(item.payout.createdAt);
906
+ }
907
+ if (item.vault) {
908
+ item.vault.createdAt = new Date(item.vault.createdAt);
909
+ item.vault.updatedAt = new Date(item.vault.updatedAt);
910
+ }
903
911
  return item;
904
912
  });
905
913
  return data;
package/dist/index.mjs CHANGED
@@ -795,9 +795,13 @@ var getMissionResponseDtoSchemaResponseTransformer = /* @__PURE__ */ __name((dat
795
795
  data.captureEndTime = new Date(data.captureEndTime);
796
796
  data.createdAt = new Date(data.createdAt);
797
797
  data.updatedAt = new Date(data.updatedAt);
798
- data.payout.createdAt = new Date(data.payout.createdAt);
799
- data.vault.createdAt = new Date(data.vault.createdAt);
800
- data.vault.updatedAt = new Date(data.vault.updatedAt);
798
+ if (data.payout) {
799
+ data.payout.createdAt = new Date(data.payout.createdAt);
800
+ }
801
+ if (data.vault) {
802
+ data.vault.createdAt = new Date(data.vault.createdAt);
803
+ data.vault.updatedAt = new Date(data.vault.updatedAt);
804
+ }
801
805
  return data;
802
806
  }, "getMissionResponseDtoSchemaResponseTransformer");
803
807
  var missionsControllerGetMissionResponseTransformer = /* @__PURE__ */ __name(async (data) => {
@@ -810,9 +814,13 @@ var getMissionsResponseDtoSchemaResponseTransformer = /* @__PURE__ */ __name((da
810
814
  item.captureEndTime = new Date(item.captureEndTime);
811
815
  item.createdAt = new Date(item.createdAt);
812
816
  item.updatedAt = new Date(item.updatedAt);
813
- item.payout.createdAt = new Date(item.payout.createdAt);
814
- item.vault.createdAt = new Date(item.vault.createdAt);
815
- item.vault.updatedAt = new Date(item.vault.updatedAt);
817
+ if (item.payout) {
818
+ item.payout.createdAt = new Date(item.payout.createdAt);
819
+ }
820
+ if (item.vault) {
821
+ item.vault.createdAt = new Date(item.vault.createdAt);
822
+ item.vault.updatedAt = new Date(item.vault.updatedAt);
823
+ }
816
824
  return item;
817
825
  });
818
826
  return data;
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.6.0",
4
+ "version": "0.7.0",
5
5
  "license": "MIT",
6
6
  "files": [
7
7
  "dist",
@@ -178,9 +178,13 @@ const getMissionResponseDtoSchemaResponseTransformer = (data: any) => {
178
178
  data.captureEndTime = new Date(data.captureEndTime);
179
179
  data.createdAt = new Date(data.createdAt);
180
180
  data.updatedAt = new Date(data.updatedAt);
181
- data.payout.createdAt = new Date(data.payout.createdAt);
182
- data.vault.createdAt = new Date(data.vault.createdAt);
183
- data.vault.updatedAt = new Date(data.vault.updatedAt);
181
+ if (data.payout) {
182
+ data.payout.createdAt = new Date(data.payout.createdAt);
183
+ }
184
+ if (data.vault) {
185
+ data.vault.createdAt = new Date(data.vault.createdAt);
186
+ data.vault.updatedAt = new Date(data.vault.updatedAt);
187
+ }
184
188
  return data;
185
189
  };
186
190
 
@@ -197,9 +201,13 @@ const getMissionsResponseDtoSchemaResponseTransformer = (data: any) => {
197
201
  item.captureEndTime = new Date(item.captureEndTime);
198
202
  item.createdAt = new Date(item.createdAt);
199
203
  item.updatedAt = new Date(item.updatedAt);
200
- item.payout.createdAt = new Date(item.payout.createdAt);
201
- item.vault.createdAt = new Date(item.vault.createdAt);
202
- item.vault.updatedAt = new Date(item.vault.updatedAt);
204
+ if (item.payout) {
205
+ item.payout.createdAt = new Date(item.payout.createdAt);
206
+ }
207
+ if (item.vault) {
208
+ item.vault.createdAt = new Date(item.vault.createdAt);
209
+ item.vault.updatedAt = new Date(item.vault.updatedAt);
210
+ }
203
211
  return item;
204
212
  });
205
213
  return data;