@space-df/sdk 0.0.1-dev.36 → 0.0.1-dev.38

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.
Files changed (43) hide show
  1. package/README.md +4 -7
  2. package/api.doc.md +167 -2
  3. package/dist/README.md +4 -7
  4. package/dist/core.d.ts +1 -4
  5. package/dist/core.d.ts.map +1 -1
  6. package/dist/core.js +1 -3
  7. package/dist/core.js.map +1 -1
  8. package/dist/core.mjs +1 -3
  9. package/dist/core.mjs.map +1 -1
  10. package/dist/index.d.mts +1 -6
  11. package/dist/index.d.ts +1 -6
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +2 -7
  14. package/dist/index.js.map +1 -1
  15. package/dist/index.mjs +2 -7
  16. package/dist/index.mjs.map +1 -1
  17. package/dist/package.json +1 -1
  18. package/dist/resources/telemetry/geofences.d.ts +61 -0
  19. package/dist/resources/telemetry/geofences.d.ts.map +1 -0
  20. package/dist/resources/telemetry/geofences.js +44 -0
  21. package/dist/resources/telemetry/geofences.js.map +1 -0
  22. package/dist/resources/telemetry/geofences.mjs +40 -0
  23. package/dist/resources/telemetry/geofences.mjs.map +1 -0
  24. package/dist/resources/telemetry/index.d.ts +2 -0
  25. package/dist/resources/telemetry/index.d.ts.map +1 -1
  26. package/dist/resources/telemetry/index.js +2 -0
  27. package/dist/resources/telemetry/index.js.map +1 -1
  28. package/dist/resources/telemetry/index.mjs +2 -0
  29. package/dist/resources/telemetry/index.mjs.map +1 -1
  30. package/dist/src/core.ts +0 -6
  31. package/dist/src/index.ts +1 -11
  32. package/dist/src/resources/telemetry/geofences.ts +91 -0
  33. package/dist/src/resources/telemetry/index.ts +2 -0
  34. package/dist/src/version.ts +1 -1
  35. package/dist/version.d.ts +1 -1
  36. package/dist/version.js +1 -1
  37. package/dist/version.mjs +1 -1
  38. package/package.json +1 -1
  39. package/src/core.ts +0 -6
  40. package/src/index.ts +1 -11
  41. package/src/resources/telemetry/geofences.ts +91 -0
  42. package/src/resources/telemetry/index.ts +2 -0
  43. package/src/version.ts +1 -1
package/dist/src/index.ts CHANGED
@@ -8,10 +8,6 @@ export interface ClientOptions {
8
8
  * Defaults to process.env['SPACEDF_ORG_ID'].
9
9
  */
10
10
  organization?: string | null | undefined;
11
- /**
12
- * Defaults to process.env['SPACEDF_API_KEY'].
13
- */
14
- APIKey?: string | undefined;
15
11
  /**
16
12
  * Override the default base URL for the API, e.g., "https://api.example.com/v2/"
17
13
  *
@@ -96,7 +92,6 @@ export class SpaceDFSDK extends Core.APIClient {
96
92
  * API Client for interfacing with the Spacedf SDK API.
97
93
  *
98
94
  * @param {string | null | undefined} [opts.organization=process.env['SPACEDF_ORG_ID'] ?? null]
99
- * @param {string | undefined} [opts.APIKey=process.env['SPACEDF_API_KEY']]
100
95
  * @param {string} [opts.baseURL=process.env['SPACEDF_SDK_BASE_URL'] ?? https://api.v0.spacedf.net/] - Override the default base URL for the API.
101
96
  * @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
102
97
  * @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
@@ -109,19 +104,16 @@ export class SpaceDFSDK extends Core.APIClient {
109
104
  constructor({
110
105
  baseURL = Core.readEnv('SPACEDF_SDK_BASE_URL'),
111
106
  organization = Core.readEnv('SPACEDF_ORG_ID') ?? null,
112
- APIKey = Core.readEnv('SPACEDF_API_KEY'),
113
107
  allowMultiOrgs = false,
114
108
  ...opts
115
109
  }: ClientOptions = {}) {
116
110
  const options: ClientOptions = {
117
111
  organization,
118
- APIKey,
119
112
  baseURL,
120
113
  ...opts,
121
114
  };
122
115
 
123
116
  super({
124
- APIKey: options.APIKey,
125
117
  baseURL: options.baseURL!,
126
118
  timeout: options.timeout ?? 60 * 1000 /* 1 minute */,
127
119
  httpAgent: options.httpAgent,
@@ -131,7 +123,6 @@ export class SpaceDFSDK extends Core.APIClient {
131
123
  });
132
124
 
133
125
  this._options = options;
134
- this.APIKey = APIKey;
135
126
  this.organization = organization;
136
127
  }
137
128
 
@@ -171,9 +162,8 @@ export class SpaceDFSDK extends Core.APIClient {
171
162
  protected override authHeaders(opts: Core.FinalRequestOptions): Core.Headers {
172
163
  const accessToken = (this.allowMultiOrgs && opts.accessToken) || this.accessToken || '';
173
164
  const Authorization = `Bearer ${accessToken}`;
174
- const APIKey = (this.allowMultiOrgs && opts.APIKey) || this.APIKey;
175
165
 
176
- return accessToken ? { Authorization, 'x-api-key': APIKey } : { 'x-api-key': APIKey };
166
+ return accessToken ? { Authorization } : {};
177
167
  }
178
168
 
179
169
  public setAccessToken(token: string | null): void {
@@ -0,0 +1,91 @@
1
+ import { APIResource } from '../../resource';
2
+ import * as Core from '../../core';
3
+ import { ListParamsResponse, ListResponse } from '../../types/api';
4
+
5
+ type Condition =
6
+ | { time_between: { start: string; end: string } }
7
+ | { weekday_in: number[] }
8
+ | { distance_from_geofence_km: { lte: number } }
9
+ | { and: Condition[] }
10
+ | { or: Condition[] }
11
+ | { not: Condition[] };
12
+
13
+ type Coordinate = [number, number];
14
+
15
+ type PolygonGeometry = {
16
+ type: 'Polygon';
17
+ coordinates: Coordinate[][][];
18
+ };
19
+
20
+ type FeatureProperties = {
21
+ mode: 'rectangle' | 'angled-rectangle' | string;
22
+ color: string;
23
+ };
24
+
25
+ interface Feature {
26
+ type: 'Feature';
27
+ geometry: PolygonGeometry;
28
+ properties: FeatureProperties;
29
+ id: string;
30
+ }
31
+
32
+ export interface Geofence {
33
+ id: string;
34
+ name: string;
35
+ color: string;
36
+ type_zone: 'safe' | 'danger';
37
+ definition: {
38
+ conditions: {
39
+ and: Condition[];
40
+ };
41
+ };
42
+ geometry: Feature[];
43
+ }
44
+
45
+ export type GeofencesListResponse = ListResponse<Geofence>;
46
+
47
+ export interface GeofencesListParams extends ListParamsResponse {
48
+ name?: string;
49
+ }
50
+
51
+ export class Geofences extends APIResource {
52
+ list(params: GeofencesListParams, options?: Core.RequestOptions): Core.APIPromise<GeofencesListResponse> {
53
+ const { ...query } = params;
54
+ return this._client.get(`/telemetry/v1/geofences`, {
55
+ query,
56
+ ...options,
57
+ headers: { ...options?.headers },
58
+ });
59
+ }
60
+ create(params: Omit<Geofence, 'id'>, options?: Core.RequestOptions): Core.APIPromise<Geofence> {
61
+ const { ...body } = params;
62
+ return this._client.post(`/telemetry/v1/geofences`, {
63
+ body,
64
+ ...options,
65
+ headers: { ...options?.headers },
66
+ });
67
+ }
68
+
69
+ retrieve(id: string, options?: Core.RequestOptions): Core.APIPromise<Geofence> {
70
+ return this._client.get(`/telemetry/v1/geofences/${id}`, {
71
+ ...options,
72
+ headers: { ...options?.headers },
73
+ });
74
+ }
75
+
76
+ update(id: string, params: Omit<Geofence, 'id'>, options?: Core.RequestOptions): Core.APIPromise<Geofence> {
77
+ const { ...body } = params;
78
+ return this._client.put(`/telemetry/v1/geofences/${id}`, {
79
+ body,
80
+ ...options,
81
+ headers: { ...options?.headers },
82
+ });
83
+ }
84
+
85
+ delete(id: string, options?: Core.RequestOptions): Core.APIPromise<void> {
86
+ return this._client.delete(`/telemetry/v1/geofences/${id}`, {
87
+ ...options,
88
+ headers: { ...options?.headers },
89
+ });
90
+ }
91
+ }
@@ -1,10 +1,12 @@
1
1
  import { APIResource } from "../../resource";
2
2
  import { Entities } from './entities';
3
3
  import { Alerts } from './alerts';
4
+ import { Geofences } from './geofences';
4
5
 
5
6
  export class Telemetry extends APIResource {
6
7
  entities: Entities = new Entities(this._client);
7
8
  alerts: Alerts = new Alerts(this._client);
9
+ geofences: Geofences = new Geofences(this._client);
8
10
  }
9
11
 
10
12
  export * from './entities';
@@ -1 +1 @@
1
- export const VERSION = '0.0.1-dev.36';
1
+ export const VERSION = '0.0.1-dev.38';
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.0.1-dev.36";
1
+ export declare const VERSION = "0.0.1-dev.38";
2
2
  //# sourceMappingURL=version.d.ts.map
package/dist/version.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = '0.0.1-dev.36';
4
+ exports.VERSION = '0.0.1-dev.38';
5
5
  //# sourceMappingURL=version.js.map
package/dist/version.mjs CHANGED
@@ -1,2 +1,2 @@
1
- export const VERSION = '0.0.1-dev.36';
1
+ export const VERSION = '0.0.1-dev.38';
2
2
  //# sourceMappingURL=version.mjs.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@space-df/sdk",
3
- "version": "0.0.1-dev.36",
3
+ "version": "0.0.1-dev.38",
4
4
  "description": "The official TypeScript library for the Spacedf SDK API",
5
5
  "author": "Spacedf SDK <support@digitalfortress.dev>",
6
6
  "types": "dist/index.d.ts",
package/src/core.ts CHANGED
@@ -128,7 +128,6 @@ export abstract class APIClient {
128
128
  timeout: number;
129
129
  httpAgent: Agent | undefined;
130
130
  allowMultiOrgs: boolean;
131
- APIKey: string | undefined;
132
131
 
133
132
  private fetch: Fetch;
134
133
  protected idempotencyHeader?: string;
@@ -139,7 +138,6 @@ export abstract class APIClient {
139
138
  timeout = 60 * 1000, // 1 minute
140
139
  httpAgent,
141
140
  fetch: overriddenFetch,
142
- APIKey,
143
141
  allowMultiOrgs = false,
144
142
  }: {
145
143
  baseURL: string;
@@ -147,14 +145,12 @@ export abstract class APIClient {
147
145
  timeout: number | undefined;
148
146
  httpAgent: Agent | undefined;
149
147
  fetch: Fetch | undefined;
150
- APIKey: string | undefined;
151
148
  allowMultiOrgs: boolean;
152
149
  }) {
153
150
  this.baseURL = baseURL;
154
151
  this.maxRetries = validatePositiveInteger('maxRetries', maxRetries);
155
152
  this.timeout = validatePositiveInteger('timeout', timeout);
156
153
  this.httpAgent = httpAgent;
157
- this.APIKey = APIKey;
158
154
  this.allowMultiOrgs = allowMultiOrgs;
159
155
 
160
156
  this.fetch = overriddenFetch ?? fetch;
@@ -684,7 +680,6 @@ export type RequestOptions<Req = unknown | Record<string, unknown> | Readable |
684
680
  idempotencyKey?: string;
685
681
  organization?: string;
686
682
  accessToken?: string;
687
- APIKey?: string;
688
683
 
689
684
  __binaryRequest?: boolean | undefined;
690
685
  __binaryResponse?: boolean | undefined;
@@ -708,7 +703,6 @@ const requestOptionsKeys: KeysEnum<RequestOptions> = {
708
703
  idempotencyKey: true,
709
704
  organization: true,
710
705
  accessToken: true,
711
- APIKey: true,
712
706
 
713
707
  __binaryRequest: true,
714
708
  __binaryResponse: true,
package/src/index.ts CHANGED
@@ -8,10 +8,6 @@ export interface ClientOptions {
8
8
  * Defaults to process.env['SPACEDF_ORG_ID'].
9
9
  */
10
10
  organization?: string | null | undefined;
11
- /**
12
- * Defaults to process.env['SPACEDF_API_KEY'].
13
- */
14
- APIKey?: string | undefined;
15
11
  /**
16
12
  * Override the default base URL for the API, e.g., "https://api.example.com/v2/"
17
13
  *
@@ -96,7 +92,6 @@ export class SpaceDFSDK extends Core.APIClient {
96
92
  * API Client for interfacing with the Spacedf SDK API.
97
93
  *
98
94
  * @param {string | null | undefined} [opts.organization=process.env['SPACEDF_ORG_ID'] ?? null]
99
- * @param {string | undefined} [opts.APIKey=process.env['SPACEDF_API_KEY']]
100
95
  * @param {string} [opts.baseURL=process.env['SPACEDF_SDK_BASE_URL'] ?? https://api.v0.spacedf.net/] - Override the default base URL for the API.
101
96
  * @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
102
97
  * @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
@@ -109,19 +104,16 @@ export class SpaceDFSDK extends Core.APIClient {
109
104
  constructor({
110
105
  baseURL = Core.readEnv('SPACEDF_SDK_BASE_URL'),
111
106
  organization = Core.readEnv('SPACEDF_ORG_ID') ?? null,
112
- APIKey = Core.readEnv('SPACEDF_API_KEY'),
113
107
  allowMultiOrgs = false,
114
108
  ...opts
115
109
  }: ClientOptions = {}) {
116
110
  const options: ClientOptions = {
117
111
  organization,
118
- APIKey,
119
112
  baseURL,
120
113
  ...opts,
121
114
  };
122
115
 
123
116
  super({
124
- APIKey: options.APIKey,
125
117
  baseURL: options.baseURL!,
126
118
  timeout: options.timeout ?? 60 * 1000 /* 1 minute */,
127
119
  httpAgent: options.httpAgent,
@@ -131,7 +123,6 @@ export class SpaceDFSDK extends Core.APIClient {
131
123
  });
132
124
 
133
125
  this._options = options;
134
- this.APIKey = APIKey;
135
126
  this.organization = organization;
136
127
  }
137
128
 
@@ -171,9 +162,8 @@ export class SpaceDFSDK extends Core.APIClient {
171
162
  protected override authHeaders(opts: Core.FinalRequestOptions): Core.Headers {
172
163
  const accessToken = (this.allowMultiOrgs && opts.accessToken) || this.accessToken || '';
173
164
  const Authorization = `Bearer ${accessToken}`;
174
- const APIKey = (this.allowMultiOrgs && opts.APIKey) || this.APIKey;
175
165
 
176
- return accessToken ? { Authorization, 'x-api-key': APIKey } : { 'x-api-key': APIKey };
166
+ return accessToken ? { Authorization } : {};
177
167
  }
178
168
 
179
169
  public setAccessToken(token: string | null): void {
@@ -0,0 +1,91 @@
1
+ import { APIResource } from '../../resource';
2
+ import * as Core from '../../core';
3
+ import { ListParamsResponse, ListResponse } from '../../types/api';
4
+
5
+ type Condition =
6
+ | { time_between: { start: string; end: string } }
7
+ | { weekday_in: number[] }
8
+ | { distance_from_geofence_km: { lte: number } }
9
+ | { and: Condition[] }
10
+ | { or: Condition[] }
11
+ | { not: Condition[] };
12
+
13
+ type Coordinate = [number, number];
14
+
15
+ type PolygonGeometry = {
16
+ type: 'Polygon';
17
+ coordinates: Coordinate[][][];
18
+ };
19
+
20
+ type FeatureProperties = {
21
+ mode: 'rectangle' | 'angled-rectangle' | string;
22
+ color: string;
23
+ };
24
+
25
+ interface Feature {
26
+ type: 'Feature';
27
+ geometry: PolygonGeometry;
28
+ properties: FeatureProperties;
29
+ id: string;
30
+ }
31
+
32
+ export interface Geofence {
33
+ id: string;
34
+ name: string;
35
+ color: string;
36
+ type_zone: 'safe' | 'danger';
37
+ definition: {
38
+ conditions: {
39
+ and: Condition[];
40
+ };
41
+ };
42
+ geometry: Feature[];
43
+ }
44
+
45
+ export type GeofencesListResponse = ListResponse<Geofence>;
46
+
47
+ export interface GeofencesListParams extends ListParamsResponse {
48
+ name?: string;
49
+ }
50
+
51
+ export class Geofences extends APIResource {
52
+ list(params: GeofencesListParams, options?: Core.RequestOptions): Core.APIPromise<GeofencesListResponse> {
53
+ const { ...query } = params;
54
+ return this._client.get(`/telemetry/v1/geofences`, {
55
+ query,
56
+ ...options,
57
+ headers: { ...options?.headers },
58
+ });
59
+ }
60
+ create(params: Omit<Geofence, 'id'>, options?: Core.RequestOptions): Core.APIPromise<Geofence> {
61
+ const { ...body } = params;
62
+ return this._client.post(`/telemetry/v1/geofences`, {
63
+ body,
64
+ ...options,
65
+ headers: { ...options?.headers },
66
+ });
67
+ }
68
+
69
+ retrieve(id: string, options?: Core.RequestOptions): Core.APIPromise<Geofence> {
70
+ return this._client.get(`/telemetry/v1/geofences/${id}`, {
71
+ ...options,
72
+ headers: { ...options?.headers },
73
+ });
74
+ }
75
+
76
+ update(id: string, params: Omit<Geofence, 'id'>, options?: Core.RequestOptions): Core.APIPromise<Geofence> {
77
+ const { ...body } = params;
78
+ return this._client.put(`/telemetry/v1/geofences/${id}`, {
79
+ body,
80
+ ...options,
81
+ headers: { ...options?.headers },
82
+ });
83
+ }
84
+
85
+ delete(id: string, options?: Core.RequestOptions): Core.APIPromise<void> {
86
+ return this._client.delete(`/telemetry/v1/geofences/${id}`, {
87
+ ...options,
88
+ headers: { ...options?.headers },
89
+ });
90
+ }
91
+ }
@@ -1,10 +1,12 @@
1
1
  import { APIResource } from '@space-df/sdk/resource';
2
2
  import { Entities } from './entities';
3
3
  import { Alerts } from './alerts';
4
+ import { Geofences } from './geofences';
4
5
 
5
6
  export class Telemetry extends APIResource {
6
7
  entities: Entities = new Entities(this._client);
7
8
  alerts: Alerts = new Alerts(this._client);
9
+ geofences: Geofences = new Geofences(this._client);
8
10
  }
9
11
 
10
12
  export * from './entities';
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const VERSION = '0.0.1-dev.36';
1
+ export const VERSION = '0.0.1-dev.38';