@xyo-network/api 2.38.9 → 2.38.11

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 (88) hide show
  1. package/dist/cjs/Archivist/XyoRemoteArchivist.d.ts.map +1 -1
  2. package/dist/cjs/Archivist/XyoRemoteArchivist.js +12 -9
  3. package/dist/cjs/Archivist/XyoRemoteArchivist.js.map +1 -1
  4. package/dist/cjs/Base.d.ts +14 -14
  5. package/dist/cjs/Base.d.ts.map +1 -1
  6. package/dist/cjs/Base.js +71 -71
  7. package/dist/cjs/Base.js.map +1 -1
  8. package/dist/cjs/Diviner/LocationDiviner/ApiConfig.d.ts +2 -2
  9. package/dist/cjs/Diviner/LocationDiviner/Queries/LocationHeatmapQuery/LocationHeatmapQuery.d.ts +1 -1
  10. package/dist/cjs/Diviner/LocationDiviner/Queries/LocationHeatmapQuery/LocationHeatmapQuery.d.ts.map +1 -1
  11. package/dist/cjs/Diviner/LocationDiviner/Queries/LocationQuadkeyHeatmapQuery/LocationQuadkeyHeatmapQuery.d.ts +1 -1
  12. package/dist/cjs/Diviner/LocationDiviner/Queries/LocationQuadkeyHeatmapQuery/LocationQuadkeyHeatmapQuery.d.ts.map +1 -1
  13. package/dist/cjs/Diviner/LocationDiviner/Queries/LocationQueryCreationRequest.d.ts +4 -4
  14. package/dist/cjs/Diviner/LocationDiviner/Queries/LocationQueryCreationRequest.d.ts.map +1 -1
  15. package/dist/cjs/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/LocationTimeRangePointProperties.d.ts +1 -1
  16. package/dist/cjs/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/LocationTimeRangePointProperties.d.ts.map +1 -1
  17. package/dist/cjs/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/LocationTimeRangeQuery.d.ts +1 -1
  18. package/dist/cjs/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/LocationTimeRangeQuery.d.ts.map +1 -1
  19. package/dist/cjs/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/LocationTimeRangeQuery.js.map +1 -1
  20. package/dist/cjs/Diviner/LocationDiviner/models.d.ts +1 -1
  21. package/dist/cjs/Diviner/LocationDiviner/models.d.ts.map +1 -1
  22. package/dist/cjs/Diviner/RemoteDivinerError.d.ts +1 -1
  23. package/dist/cjs/Diviner/RemoteDivinerError.d.ts.map +1 -1
  24. package/dist/cjs/Diviner/RemoteDivinerError.js.map +1 -1
  25. package/dist/cjs/Diviner/XyoRemoteDivinerConfig.d.ts +1 -1
  26. package/dist/cjs/Diviner/XyoRemoteDivinerConfig.d.ts.map +1 -1
  27. package/dist/cjs/Simple.d.ts +6 -6
  28. package/dist/cjs/Simple.d.ts.map +1 -1
  29. package/dist/cjs/Simple.js +12 -12
  30. package/dist/cjs/Simple.js.map +1 -1
  31. package/dist/cjs/User/Api.d.ts +5 -5
  32. package/dist/cjs/models/Api/Config.d.ts +12 -12
  33. package/dist/cjs/models/Api/Config.d.ts.map +1 -1
  34. package/dist/cjs/models/Archive.d.ts +2 -2
  35. package/dist/cjs/models/Archive.d.ts.map +1 -1
  36. package/dist/docs.json +4291 -4291
  37. package/dist/esm/Archivist/XyoRemoteArchivist.d.ts.map +1 -1
  38. package/dist/esm/Archivist/XyoRemoteArchivist.js +11 -8
  39. package/dist/esm/Archivist/XyoRemoteArchivist.js.map +1 -1
  40. package/dist/esm/Base.d.ts +14 -14
  41. package/dist/esm/Base.d.ts.map +1 -1
  42. package/dist/esm/Base.js +63 -63
  43. package/dist/esm/Base.js.map +1 -1
  44. package/dist/esm/Diviner/LocationDiviner/ApiConfig.d.ts +2 -2
  45. package/dist/esm/Diviner/LocationDiviner/Queries/LocationHeatmapQuery/LocationHeatmapQuery.d.ts +1 -1
  46. package/dist/esm/Diviner/LocationDiviner/Queries/LocationHeatmapQuery/LocationHeatmapQuery.d.ts.map +1 -1
  47. package/dist/esm/Diviner/LocationDiviner/Queries/LocationQuadkeyHeatmapQuery/LocationQuadkeyHeatmapQuery.d.ts +1 -1
  48. package/dist/esm/Diviner/LocationDiviner/Queries/LocationQuadkeyHeatmapQuery/LocationQuadkeyHeatmapQuery.d.ts.map +1 -1
  49. package/dist/esm/Diviner/LocationDiviner/Queries/LocationQueryCreationRequest.d.ts +4 -4
  50. package/dist/esm/Diviner/LocationDiviner/Queries/LocationQueryCreationRequest.d.ts.map +1 -1
  51. package/dist/esm/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/LocationTimeRangePointProperties.d.ts +1 -1
  52. package/dist/esm/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/LocationTimeRangePointProperties.d.ts.map +1 -1
  53. package/dist/esm/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/LocationTimeRangeQuery.d.ts +1 -1
  54. package/dist/esm/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/LocationTimeRangeQuery.d.ts.map +1 -1
  55. package/dist/esm/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/LocationTimeRangeQuery.js.map +1 -1
  56. package/dist/esm/Diviner/LocationDiviner/models.d.ts +1 -1
  57. package/dist/esm/Diviner/LocationDiviner/models.d.ts.map +1 -1
  58. package/dist/esm/Diviner/RemoteDivinerError.d.ts +1 -1
  59. package/dist/esm/Diviner/RemoteDivinerError.d.ts.map +1 -1
  60. package/dist/esm/Diviner/RemoteDivinerError.js +1 -1
  61. package/dist/esm/Diviner/RemoteDivinerError.js.map +1 -1
  62. package/dist/esm/Diviner/XyoRemoteDivinerConfig.d.ts +1 -1
  63. package/dist/esm/Diviner/XyoRemoteDivinerConfig.d.ts.map +1 -1
  64. package/dist/esm/Simple.d.ts +6 -6
  65. package/dist/esm/Simple.d.ts.map +1 -1
  66. package/dist/esm/Simple.js +11 -11
  67. package/dist/esm/Simple.js.map +1 -1
  68. package/dist/esm/User/Api.d.ts +5 -5
  69. package/dist/esm/models/Api/Config.d.ts +12 -12
  70. package/dist/esm/models/Api/Config.d.ts.map +1 -1
  71. package/dist/esm/models/Archive.d.ts +2 -2
  72. package/dist/esm/models/Archive.d.ts.map +1 -1
  73. package/package.json +9 -9
  74. package/src/Archivist/XyoRemoteArchivist.spec.ts +5 -0
  75. package/src/Archivist/XyoRemoteArchivist.ts +11 -8
  76. package/src/Base.ts +71 -71
  77. package/src/Diviner/LocationDiviner/ApiConfig.ts +2 -2
  78. package/src/Diviner/LocationDiviner/Queries/LocationHeatmapQuery/LocationHeatmapQuery.ts +1 -1
  79. package/src/Diviner/LocationDiviner/Queries/LocationQuadkeyHeatmapQuery/LocationQuadkeyHeatmapQuery.ts +1 -1
  80. package/src/Diviner/LocationDiviner/Queries/LocationQueryCreationRequest.ts +4 -4
  81. package/src/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/LocationTimeRangePointProperties.ts +1 -1
  82. package/src/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/LocationTimeRangeQuery.ts +2 -1
  83. package/src/Diviner/LocationDiviner/models.ts +1 -1
  84. package/src/Diviner/RemoteDivinerError.ts +1 -1
  85. package/src/Diviner/XyoRemoteDivinerConfig.ts +1 -1
  86. package/src/Simple.ts +18 -18
  87. package/src/models/Api/Config.ts +14 -14
  88. package/src/models/Archive.ts +2 -2
@@ -19,14 +19,14 @@ export declare class XyoUserApi extends XyoApiBase {
19
19
  }, import("@xyo-network/payload").XyoPayloadFindFilter, {
20
20
  root: string;
21
21
  apiDomain: string; /** @field Password of the user [in] */
22
- userid?: string | undefined;
23
- jwtToken?: string | undefined;
24
22
  apiKey?: string | undefined;
25
- query?: string | undefined;
26
23
  compressionThreshold?: number | undefined;
27
- throwFailure?: boolean | undefined;
28
- throwError?: boolean | undefined;
24
+ jwtToken?: string | undefined;
25
+ query?: string | undefined;
29
26
  reportableParent?: import("..").XyoApiReportable | undefined;
27
+ throwError?: boolean | undefined;
28
+ throwFailure?: boolean | undefined;
29
+ userid?: string | undefined;
30
30
  onError?: ((error: import("..").XyoApiError<any, any>, depth: number) => void) | undefined;
31
31
  /** @field Password of the user [in] */
32
32
  onFailure?: ((response: import("..").XyoApiResponse<unknown, unknown>, depth: number) => void) | undefined; /** @field Token to access the API as that user [out] */
@@ -2,24 +2,24 @@ import { XyoApiReportable } from './Reportable';
2
2
  interface XyoApiConfig extends XyoApiReportable {
3
3
  /** @description The domain where the api is located */
4
4
  apiDomain: string;
5
- /** @deprecated use the jwtToken instead*/
6
- userid?: string;
7
- /** @description The jwtToken of the currently logged in user */
8
- jwtToken?: string;
9
5
  /** @description The apiKey used for authentication */
10
6
  apiKey?: string;
11
- /** @description The location in the API tree where this API object is mounted */
12
- root?: string;
13
- /** @description The query string, if any, that is added to the end of every request */
14
- query?: string;
15
7
  /** @description Threshold for Content-Size to cause automatic gzip of request body [default = 1024] */
16
8
  compressionThreshold?: number;
17
- /** @description Throw on failures */
18
- throwFailure?: boolean;
19
- /** @description Throw on error */
20
- throwError?: boolean;
9
+ /** @description The jwtToken of the currently logged in user */
10
+ jwtToken?: string;
11
+ /** @description The query string, if any, that is added to the end of every request */
12
+ query?: string;
21
13
  /** @description Parent that should also report events from this api */
22
14
  reportableParent?: XyoApiReportable;
15
+ /** @description The location in the API tree where this API object is mounted */
16
+ root?: string;
17
+ /** @description Throw on error */
18
+ throwError?: boolean;
19
+ /** @description Throw on failures */
20
+ throwFailure?: boolean;
21
+ /** @deprecated use the jwtToken instead*/
22
+ userid?: string;
23
23
  }
24
24
  export type { XyoApiConfig };
25
25
  //# sourceMappingURL=Config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../../../src/models/Api/Config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAE/C,UAAU,YAAa,SAAQ,gBAAgB;IAC7C,uDAAuD;IACvD,SAAS,EAAE,MAAM,CAAA;IAEjB,0CAA0C;IAC1C,MAAM,CAAC,EAAE,MAAM,CAAA;IAEf,gEAAgE;IAChE,QAAQ,CAAC,EAAE,MAAM,CAAA;IAEjB,sDAAsD;IACtD,MAAM,CAAC,EAAE,MAAM,CAAA;IAEf,iFAAiF;IACjF,IAAI,CAAC,EAAE,MAAM,CAAA;IAEb,uFAAuF;IACvF,KAAK,CAAC,EAAE,MAAM,CAAA;IAEd,uGAAuG;IACvG,oBAAoB,CAAC,EAAE,MAAM,CAAA;IAE7B,qCAAqC;IACrC,YAAY,CAAC,EAAE,OAAO,CAAA;IAEtB,kCAAkC;IAClC,UAAU,CAAC,EAAE,OAAO,CAAA;IAEpB,uEAAuE;IACvE,gBAAgB,CAAC,EAAE,gBAAgB,CAAA;CACpC;AAED,YAAY,EAAE,YAAY,EAAE,CAAA"}
1
+ {"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../../../src/models/Api/Config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAE/C,UAAU,YAAa,SAAQ,gBAAgB;IAC7C,uDAAuD;IACvD,SAAS,EAAE,MAAM,CAAA;IAEjB,sDAAsD;IACtD,MAAM,CAAC,EAAE,MAAM,CAAA;IAEf,uGAAuG;IACvG,oBAAoB,CAAC,EAAE,MAAM,CAAA;IAE7B,gEAAgE;IAChE,QAAQ,CAAC,EAAE,MAAM,CAAA;IAEjB,uFAAuF;IACvF,KAAK,CAAC,EAAE,MAAM,CAAA;IAEd,uEAAuE;IACvE,gBAAgB,CAAC,EAAE,gBAAgB,CAAA;IAEnC,iFAAiF;IACjF,IAAI,CAAC,EAAE,MAAM,CAAA;IAEb,kCAAkC;IAClC,UAAU,CAAC,EAAE,OAAO,CAAA;IAEpB,qCAAqC;IACrC,YAAY,CAAC,EAAE,OAAO,CAAA;IAEtB,0CAA0C;IAC1C,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,YAAY,EAAE,YAAY,EAAE,CAAA"}
@@ -5,8 +5,8 @@ export declare type ExpirationWindow = 'create' | 'read';
5
5
  export interface XyoAccessControl {
6
6
  access?: Record<AccessType, AccessLevel>;
7
7
  expiration?: {
8
- window?: ExpirationWindow;
9
8
  delay?: number;
9
+ window?: ExpirationWindow;
10
10
  };
11
11
  }
12
12
  export interface XyoAccessControls {
@@ -19,7 +19,7 @@ export interface XyoAccessControls {
19
19
  schema?: Record<string, XyoAccessControl>;
20
20
  }
21
21
  export interface XyoArchive extends XyoArchivePath {
22
- user?: string;
23
22
  accessControl?: XyoAccessControl | boolean;
23
+ user?: string;
24
24
  }
25
25
  //# sourceMappingURL=Archive.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Archive.d.ts","sourceRoot":"","sources":["../../../src/models/Archive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAE9C,oBAAY,WAAW,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,CAAA;AACvD,oBAAY,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAA;AAC9D,oBAAY,gBAAgB,GAAG,QAAQ,GAAG,MAAM,CAAA;AAEhD,MAAM,WAAW,gBAAgB;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC,UAAU,EAAE,WAAW,CAAC,CAAA;IACxC,UAAU,CAAC,EAAE;QACX,MAAM,CAAC,EAAE,gBAAgB,CAAA;QACzB,KAAK,CAAC,EAAE,MAAM,CAAA;KACf,CAAA;CACF;AAED,MAAM,WAAW,iBAAiB;IAChC;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAA;CAC1C;AAED,MAAM,WAAW,UAAW,SAAQ,cAAc;IAChD,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,aAAa,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAA;CAC3C"}
1
+ {"version":3,"file":"Archive.d.ts","sourceRoot":"","sources":["../../../src/models/Archive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAE9C,oBAAY,WAAW,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,CAAA;AACvD,oBAAY,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAA;AAC9D,oBAAY,gBAAgB,GAAG,QAAQ,GAAG,MAAM,CAAA;AAEhD,MAAM,WAAW,gBAAgB;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC,UAAU,EAAE,WAAW,CAAC,CAAA;IACxC,UAAU,CAAC,EAAE;QACX,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,MAAM,CAAC,EAAE,gBAAgB,CAAA;KAC1B,CAAA;CACF;AAED,MAAM,WAAW,iBAAiB;IAChC;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAA;CAC1C;AAED,MAAM,WAAW,UAAW,SAAQ,cAAc;IAChD,aAAa,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAA;IAC1C,IAAI,CAAC,EAAE,MAAM,CAAA;CACd"}
package/package.json CHANGED
@@ -11,14 +11,14 @@
11
11
  "dependencies": {
12
12
  "@xylabs/assert": "^2.6.9",
13
13
  "@xylabs/delay": "^2.6.9",
14
- "@xyo-network/account": "^2.38.9",
15
- "@xyo-network/archivist": "^2.38.9",
16
- "@xyo-network/boundwitness": "^2.38.9",
17
- "@xyo-network/core": "^2.38.9",
18
- "@xyo-network/diviner": "^2.38.9",
19
- "@xyo-network/module": "^2.38.9",
20
- "@xyo-network/payload": "^2.38.9",
21
- "@xyo-network/schema-payload-plugin": "^2.38.9",
14
+ "@xyo-network/account": "^2.38.11",
15
+ "@xyo-network/archivist": "^2.38.11",
16
+ "@xyo-network/boundwitness": "^2.38.11",
17
+ "@xyo-network/core": "^2.38.11",
18
+ "@xyo-network/diviner": "^2.38.11",
19
+ "@xyo-network/module": "^2.38.11",
20
+ "@xyo-network/payload": "^2.38.11",
21
+ "@xyo-network/schema-payload-plugin": "^2.38.11",
22
22
  "tslib": "^2.4.0"
23
23
  },
24
24
  "peerDependencies": {
@@ -65,5 +65,5 @@
65
65
  },
66
66
  "sideEffects": false,
67
67
  "types": "dist/esm/index.d.ts",
68
- "version": "2.38.9"
68
+ "version": "2.38.11"
69
69
  }
@@ -1,3 +1,4 @@
1
+ import { XyoArchivistWrapper } from '@xyo-network/archivist'
1
2
  import { PayloadWrapper } from '@xyo-network/payload'
2
3
 
3
4
  import { XyoApiConfig } from '../models'
@@ -25,4 +26,8 @@ test('XyoRemoteArchivist', async () => {
25
26
  console.log(`getResult: ${JSON.stringify(getResult)}`)
26
27
  expect(getResult.length).toBe(1)
27
28
  expect(getResult[0]?.schema).toBe(payload.schema)
29
+
30
+ const wrapper = new XyoArchivistWrapper(archivist)
31
+ const findResult = await wrapper.find()
32
+ expect(findResult.length).toBe(20)
28
33
  })
@@ -83,16 +83,19 @@ export class XyoRemoteArchivist extends XyoArchivist<XyoRemoteArchivistConfig> {
83
83
 
84
84
  public override async find<R extends XyoPayload = XyoPayload>(filter: XyoPayloadFindFilter): Promise<R[]> {
85
85
  try {
86
- const [payloads = [], { error: payloadError }] = await this.api.archive(this.archive).payload.find(filter, 'tuple')
87
- if (payloadError?.length) {
88
- throw new RemoteArchivistError('find', payloadError, 'payloads')
86
+ const [payloads = [], payloadEnvelope, payloadResponse] = await this.api.archive(this.archive).payload.find(filter, 'tuple')
87
+ if (payloadEnvelope?.error?.length) {
88
+ throw new RemoteArchivistError('find', payloadEnvelope.error.shift(), 'payloads')
89
89
  }
90
- const [blocks = [], response, error] = await this.api.archive(this.archive).block.find(filter, 'tuple')
91
- if (error?.status >= 400) {
92
- throw new RemoteArchivistError('find', `${error.statusText} [${error.status}]`)
90
+ if (payloadResponse?.status >= 300) {
91
+ throw new RemoteArchivistError('find', `Invalid payload status [${payloadResponse.status}]`, 'payloads')
93
92
  }
94
- if (response?.error?.length) {
95
- throw new RemoteArchivistError('find', response?.error)
93
+ const [blocks = [], blockEnvelope, blockResponse] = await this.api.archive(this.archive).block.find(filter, 'tuple')
94
+ if (blockEnvelope?.error?.length) {
95
+ throw new RemoteArchivistError('find', blockEnvelope.error.shift(), 'payloads')
96
+ }
97
+ if (blockResponse?.status >= 300) {
98
+ throw new RemoteArchivistError('find', `Invalid block status [${blockResponse.status}]`, 'payloads')
96
99
  }
97
100
  return payloads.concat(blocks) as R[]
98
101
  } catch (ex) {
package/src/Base.ts CHANGED
@@ -22,34 +22,36 @@ export class XyoApiBase<C extends XyoApiConfig = XyoApiConfig> implements XyoApi
22
22
  this.axios = new Axios(this.axiosConfig())
23
23
  }
24
24
 
25
- private axiosHeaders(): RawAxiosRequestHeaders {
26
- const axiosHeaders: RawAxiosRequestHeaders = { ...this.headers }
27
- axiosHeaders['Accept'] = 'application/json, text/plain, *.*'
28
- axiosHeaders['Content-Type'] = 'application/json'
29
- return axiosHeaders
25
+ public get authenticated() {
26
+ return !!this.config.apiKey || !!this.config.jwtToken
30
27
  }
31
28
 
32
- private axiosConfig(): AxiosRequestConfig {
33
- return {
34
- headers: this.axiosHeaders(),
35
- transformRequest: (data, headers) => {
36
- const json = JSON.stringify(data)
37
- if (headers && data) {
38
- if (json.length > (this.config.compressionThreshold ?? 1024)) {
39
- headers['Content-Encoding'] = 'gzip'
40
- return gzip(JSON.stringify(data)).buffer
41
- }
42
- }
43
- return JSON.stringify(data)
44
- },
45
- transformResponse: (data) => {
46
- try {
47
- return JSON.parse(data)
48
- } catch (ex) {
49
- return null
50
- }
51
- },
29
+ protected get headers(): Record<string, string> {
30
+ const headers: Record<string, string> = {}
31
+ if (this.config.jwtToken) {
32
+ headers.Authorization = `Bearer ${this.config.jwtToken}`
52
33
  }
34
+ if (this.config.apiKey) {
35
+ headers['x-api-key'] = this.config.apiKey
36
+ }
37
+ return headers
38
+ }
39
+
40
+ protected get query() {
41
+ return this.config.query ?? ''
42
+ }
43
+
44
+ protected get root() {
45
+ return this.config.root ?? '/'
46
+ }
47
+
48
+ private static resolveResponse<T>(result?: XyoApiResponse<XyoApiEnvelope<T>>) {
49
+ return [result?.data?.data, result?.data, result] as XyoApiResponseTuple<T>
50
+ }
51
+
52
+ private static shapeResponse<T = unknown>(response: XyoApiResponse<XyoApiEnvelope<T>> | undefined, responseType?: XyoApiResponseType) {
53
+ const resolvedResponse = XyoApiBase.resolveResponse(response)
54
+ return responseType === 'tuple' ? resolvedResponse : resolvedResponse[0]
53
55
  }
54
56
 
55
57
  onError(error: XyoApiError, depth = 0) {
@@ -67,20 +69,24 @@ export class XyoApiBase<C extends XyoApiConfig = XyoApiConfig> implements XyoApi
67
69
  this.config.onSuccess?.(response, depth)
68
70
  }
69
71
 
70
- protected get root() {
71
- return this.config.root ?? '/'
72
- }
73
-
74
- protected get query() {
75
- return this.config.query ?? ''
76
- }
77
-
78
- private resolveRoot() {
79
- return `${this.config.apiDomain}${this.root}`
72
+ protected async deleteEndpoint<T = unknown>(endPoint?: string): Promise<XyoApiResponseBody<T>>
73
+ protected async deleteEndpoint<T = unknown>(endPoint?: string, responseType?: 'body'): Promise<XyoApiResponseBody<T>>
74
+ protected async deleteEndpoint<T = unknown>(endPoint?: string, responseType?: 'tuple'): Promise<XyoApiResponseTuple<T>>
75
+ protected async deleteEndpoint<T = unknown>(endPoint = '', responseType?: XyoApiResponseType): Promise<XyoApiResponseTupleOrBody<T>> {
76
+ const response = await this.monitorResponse<T>(async () => {
77
+ return await this.axios.delete<XyoApiEnvelope<T>, XyoApiResponse<XyoApiEnvelope<T>>>(`${this.resolveRoot()}${endPoint}${this.query}`)
78
+ })
79
+ return XyoApiBase.shapeResponse<T>(response, responseType)
80
80
  }
81
81
 
82
- private static resolveResponse<T>(result?: XyoApiResponse<XyoApiEnvelope<T>>) {
83
- return [result?.data?.data, result?.data, result] as XyoApiResponseTuple<T>
82
+ protected async getEndpoint<T = unknown>(endPoint?: string): Promise<XyoApiResponseBody<T>>
83
+ protected async getEndpoint<T = unknown>(endPoint?: string, responseType?: 'body'): Promise<XyoApiResponseBody<T>>
84
+ protected async getEndpoint<T = unknown>(endPoint?: string, responseType?: 'tuple'): Promise<XyoApiResponseTuple<T>>
85
+ protected async getEndpoint<T = unknown>(endPoint = '', responseType?: XyoApiResponseType): Promise<XyoApiResponseTupleOrBody<T>> {
86
+ const response = await this.monitorResponse<T>(async () => {
87
+ return await this.axios.get<XyoApiEnvelope<T>, XyoApiResponse<XyoApiEnvelope<T>>>(`${this.resolveRoot()}${endPoint}${this.query}`)
88
+ })
89
+ return XyoApiBase.shapeResponse<T>(response, responseType)
84
90
  }
85
91
 
86
92
  protected handleMonitorResponseError<T>(error: XyoApiError, trapAxiosException: boolean) {
@@ -112,16 +118,6 @@ export class XyoApiBase<C extends XyoApiConfig = XyoApiConfig> implements XyoApi
112
118
  }
113
119
  }
114
120
 
115
- protected async getEndpoint<T = unknown>(endPoint?: string): Promise<XyoApiResponseBody<T>>
116
- protected async getEndpoint<T = unknown>(endPoint?: string, responseType?: 'body'): Promise<XyoApiResponseBody<T>>
117
- protected async getEndpoint<T = unknown>(endPoint?: string, responseType?: 'tuple'): Promise<XyoApiResponseTuple<T>>
118
- protected async getEndpoint<T = unknown>(endPoint = '', responseType?: XyoApiResponseType): Promise<XyoApiResponseTupleOrBody<T>> {
119
- const response = await this.monitorResponse<T>(async () => {
120
- return await this.axios.get<XyoApiEnvelope<T>, XyoApiResponse<XyoApiEnvelope<T>>>(`${this.resolveRoot()}${endPoint}${this.query}`)
121
- })
122
- return XyoApiBase.shapeResponse<T>(response, responseType)
123
- }
124
-
125
121
  protected async postEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D): Promise<XyoApiResponseBody<T>>
126
122
  protected async postEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D, responseType?: 'body'): Promise<XyoApiResponseBody<T>>
127
123
  protected async postEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D, responseType?: 'tuple'): Promise<XyoApiResponseTuple<T>>
@@ -150,33 +146,37 @@ export class XyoApiBase<C extends XyoApiConfig = XyoApiConfig> implements XyoApi
150
146
  return XyoApiBase.shapeResponse<T>(response, responseType)
151
147
  }
152
148
 
153
- protected async deleteEndpoint<T = unknown>(endPoint?: string): Promise<XyoApiResponseBody<T>>
154
- protected async deleteEndpoint<T = unknown>(endPoint?: string, responseType?: 'body'): Promise<XyoApiResponseBody<T>>
155
- protected async deleteEndpoint<T = unknown>(endPoint?: string, responseType?: 'tuple'): Promise<XyoApiResponseTuple<T>>
156
- protected async deleteEndpoint<T = unknown>(endPoint = '', responseType?: XyoApiResponseType): Promise<XyoApiResponseTupleOrBody<T>> {
157
- const response = await this.monitorResponse<T>(async () => {
158
- return await this.axios.delete<XyoApiEnvelope<T>, XyoApiResponse<XyoApiEnvelope<T>>>(`${this.resolveRoot()}${endPoint}${this.query}`)
159
- })
160
- return XyoApiBase.shapeResponse<T>(response, responseType)
161
- }
162
-
163
- private static shapeResponse<T = unknown>(response: XyoApiResponse<XyoApiEnvelope<T>> | undefined, responseType?: XyoApiResponseType) {
164
- const resolvedResponse = XyoApiBase.resolveResponse(response)
165
- return responseType === 'tuple' ? resolvedResponse : resolvedResponse[0]
149
+ private axiosConfig(): AxiosRequestConfig {
150
+ return {
151
+ headers: this.axiosHeaders(),
152
+ transformRequest: (data, headers) => {
153
+ const json = JSON.stringify(data)
154
+ if (headers && data) {
155
+ if (json.length > (this.config.compressionThreshold ?? 1024)) {
156
+ headers['Content-Encoding'] = 'gzip'
157
+ return gzip(JSON.stringify(data)).buffer
158
+ }
159
+ }
160
+ return JSON.stringify(data)
161
+ },
162
+ transformResponse: (data) => {
163
+ try {
164
+ return JSON.parse(data)
165
+ } catch (ex) {
166
+ return null
167
+ }
168
+ },
169
+ }
166
170
  }
167
171
 
168
- protected get headers(): Record<string, string> {
169
- const headers: Record<string, string> = {}
170
- if (this.config.jwtToken) {
171
- headers.Authorization = `Bearer ${this.config.jwtToken}`
172
- }
173
- if (this.config.apiKey) {
174
- headers['x-api-key'] = this.config.apiKey
175
- }
176
- return headers
172
+ private axiosHeaders(): RawAxiosRequestHeaders {
173
+ const axiosHeaders: RawAxiosRequestHeaders = { ...this.headers }
174
+ axiosHeaders['Accept'] = 'application/json, text/plain, *.*'
175
+ axiosHeaders['Content-Type'] = 'application/json'
176
+ return axiosHeaders
177
177
  }
178
178
 
179
- public get authenticated() {
180
- return !!this.config.apiKey || !!this.config.jwtToken
179
+ private resolveRoot() {
180
+ return `${this.config.apiDomain}${this.root}`
181
181
  }
182
182
  }
@@ -1,6 +1,6 @@
1
1
  export interface ApiConfig {
2
2
  apiDomain: string
3
- userid?: string
4
- jwtToken?: string
5
3
  apiKey?: string
4
+ jwtToken?: string
5
+ userid?: string
6
6
  }
@@ -7,9 +7,9 @@ export type LocationHeatmapAnswerSchema = 'network.xyo.location.heatmap.answer'
7
7
  export const locationHeatmapAnswerSchema: LocationHeatmapAnswerSchema = 'network.xyo.location.heatmap.answer'
8
8
 
9
9
  export type LocationHeatmapQuery = {
10
+ schema: LocationWitnessSchema
10
11
  startTime?: string
11
12
  stopTime?: string
12
- schema: LocationWitnessSchema
13
13
  }
14
14
 
15
15
  export const isLocationHeatmapQuery = (query: Record<string, unknown>): query is LocationHeatmapQuery => {
@@ -5,9 +5,9 @@ export const locationQuadkeyHeatmapQuerySchema: LocationQuadkeyHeatmapQuerySchem
5
5
  export type LocationQuadkeyHeatmapAnswerSchema = 'network.xyo.location.heatmap.quadkey.answer'
6
6
  export const locationQuadkeyHeatmapAnswerSchema: LocationQuadkeyHeatmapAnswerSchema = 'network.xyo.location.heatmap.quadkey.answer'
7
7
  export type LocationQuadkeyHeatmapQuery = {
8
+ schema: LocationWitnessSchema
8
9
  startTime?: string
9
10
  stopTime?: string
10
- schema: LocationWitnessSchema
11
11
  }
12
12
 
13
13
  export const isLocationQuadkeyHeatmapQuery = (query: Record<string, unknown>): query is LocationQuadkeyHeatmapQuery => {
@@ -8,12 +8,12 @@ export interface LocationQueryCreationRequest<
8
8
  TSchema extends LocationQuerySchema = LocationQuerySchema,
9
9
  TQuery extends Record<string, unknown> = Record<string, unknown>,
10
10
  > {
11
- sourceArchivist: XyoApiConfig
12
- sourceArchive: string
13
- resultArchivist: XyoApiConfig
11
+ query: TQuery
14
12
  resultArchive: string
13
+ resultArchivist: XyoApiConfig
15
14
  schema: TSchema
16
- query: TQuery
15
+ sourceArchive: string
16
+ sourceArchivist: XyoApiConfig
17
17
  }
18
18
 
19
19
  export type LocationTimeRangeQueryCreationRequest = LocationQueryCreationRequest<LocationTimeRangeQuerySchema, LocationTimeRangeQuery>
@@ -1,8 +1,8 @@
1
1
  import { LocationWitnessSchema } from '../../Witnesses'
2
2
 
3
3
  export interface LocationTimeRangePointProperties {
4
- schema: LocationWitnessSchema
5
4
  _archive: string
6
5
  _client: string
7
6
  _timestamp: number
7
+ schema: LocationWitnessSchema
8
8
  }
@@ -7,9 +7,10 @@ export type LocationTimeRangeAnswerSchema = 'network.xyo.location.range.answer'
7
7
  export const LocationTimeRangeAnswerSchema: LocationTimeRangeAnswerSchema = 'network.xyo.location.range.answer'
8
8
 
9
9
  export type LocationTimeRangeQuery = {
10
+ schema: LocationWitnessSchema
10
11
  startTime?: string
11
12
  stopTime?: string
12
- schema: LocationWitnessSchema
13
+
13
14
  // TODO: Bounding rectangle, etc.
14
15
  }
15
16
 
@@ -1,4 +1,4 @@
1
1
  export interface GetLocationQueryResponse {
2
- queryHash: string
3
2
  answerHash?: string
3
+ queryHash: string
4
4
  }
@@ -1,8 +1,8 @@
1
1
  export class RemoteDivinerError extends Error {
2
+ isRemoteDivinerError = true
2
3
  constructor(action: string, error: Error['cause'], message?: string) {
3
4
  super(`Remote Diviner [${action}] failed${message ? ` (${message})` : ''}`, { cause: error })
4
5
  }
5
- isRemoteDivinerError = true
6
6
  static isRemoteDivinerError(error: unknown): RemoteDivinerError | undefined {
7
7
  return (error as RemoteDivinerError).isRemoteDivinerError ? (error as RemoteDivinerError) : undefined
8
8
  }
@@ -6,7 +6,7 @@ export type XyoRemoteDivinerConfigSchema = 'network.xyo.diviner.remote.config'
6
6
  export const XyoRemoteDivinerConfigSchema: XyoRemoteDivinerConfigSchema = 'network.xyo.diviner.remote.config'
7
7
 
8
8
  export type XyoRemoteDivinerConfig = XyoDivinerConfig & {
9
- schema: XyoRemoteDivinerConfigSchema
10
9
  api?: XyoArchivistApi
11
10
  archive?: string
11
+ schema: XyoRemoteDivinerConfigSchema
12
12
  }
package/src/Simple.ts CHANGED
@@ -12,15 +12,15 @@ export class XyoApiSimple<
12
12
  Q extends XyoApiSimpleQuery = XyoApiSimpleQuery,
13
13
  C extends XyoApiConfig = XyoApiConfig,
14
14
  > extends XyoApiBase<C> {
15
- public async get(): Promise<XyoApiResponseBody<T>>
16
- public async get(responseType?: 'body'): Promise<XyoApiResponseBody<T>>
17
- public async get(responseType?: 'tuple'): Promise<XyoApiResponseTuple<T>>
18
- public async get(responseType?: XyoApiResponseType): Promise<XyoApiResponseTupleOrBody<T>> {
15
+ public async delete(): Promise<XyoApiResponseBody<T>>
16
+ public async delete(responseType?: 'body'): Promise<XyoApiResponseBody<T>>
17
+ public async delete(responseType?: 'tuple'): Promise<XyoApiResponseTuple<T>>
18
+ public async delete(responseType?: XyoApiResponseType): Promise<XyoApiResponseTupleOrBody<T>> {
19
19
  switch (responseType) {
20
20
  case 'tuple':
21
- return await this.getEndpoint(undefined, 'tuple')
21
+ return await this.deleteEndpoint(undefined, 'tuple')
22
22
  default:
23
- return await this.getEndpoint(undefined)
23
+ return await this.deleteEndpoint(undefined)
24
24
  }
25
25
  }
26
26
 
@@ -36,6 +36,18 @@ export class XyoApiSimple<
36
36
  }
37
37
  }
38
38
 
39
+ public async get(): Promise<XyoApiResponseBody<T>>
40
+ public async get(responseType?: 'body'): Promise<XyoApiResponseBody<T>>
41
+ public async get(responseType?: 'tuple'): Promise<XyoApiResponseTuple<T>>
42
+ public async get(responseType?: XyoApiResponseType): Promise<XyoApiResponseTupleOrBody<T>> {
43
+ switch (responseType) {
44
+ case 'tuple':
45
+ return await this.getEndpoint(undefined, 'tuple')
46
+ default:
47
+ return await this.getEndpoint(undefined)
48
+ }
49
+ }
50
+
39
51
  public async post(data?: D): Promise<XyoApiResponseBody<T>>
40
52
  public async post(data?: D, responseType?: 'body'): Promise<XyoApiResponseBody<T>>
41
53
  public async post(data?: D, responseType?: 'tuple'): Promise<XyoApiResponseTuple<T>>
@@ -59,16 +71,4 @@ export class XyoApiSimple<
59
71
  return await this.putEndpoint(undefined, data)
60
72
  }
61
73
  }
62
-
63
- public async delete(): Promise<XyoApiResponseBody<T>>
64
- public async delete(responseType?: 'body'): Promise<XyoApiResponseBody<T>>
65
- public async delete(responseType?: 'tuple'): Promise<XyoApiResponseTuple<T>>
66
- public async delete(responseType?: XyoApiResponseType): Promise<XyoApiResponseTupleOrBody<T>> {
67
- switch (responseType) {
68
- case 'tuple':
69
- return await this.deleteEndpoint(undefined, 'tuple')
70
- default:
71
- return await this.deleteEndpoint(undefined)
72
- }
73
- }
74
74
  }
@@ -4,32 +4,32 @@ interface XyoApiConfig extends XyoApiReportable {
4
4
  /** @description The domain where the api is located */
5
5
  apiDomain: string
6
6
 
7
- /** @deprecated use the jwtToken instead*/
8
- userid?: string
9
-
10
- /** @description The jwtToken of the currently logged in user */
11
- jwtToken?: string
12
-
13
7
  /** @description The apiKey used for authentication */
14
8
  apiKey?: string
15
9
 
16
- /** @description The location in the API tree where this API object is mounted */
17
- root?: string
10
+ /** @description Threshold for Content-Size to cause automatic gzip of request body [default = 1024] */
11
+ compressionThreshold?: number
12
+
13
+ /** @description The jwtToken of the currently logged in user */
14
+ jwtToken?: string
18
15
 
19
16
  /** @description The query string, if any, that is added to the end of every request */
20
17
  query?: string
21
18
 
22
- /** @description Threshold for Content-Size to cause automatic gzip of request body [default = 1024] */
23
- compressionThreshold?: number
19
+ /** @description Parent that should also report events from this api */
20
+ reportableParent?: XyoApiReportable
24
21
 
25
- /** @description Throw on failures */
26
- throwFailure?: boolean
22
+ /** @description The location in the API tree where this API object is mounted */
23
+ root?: string
27
24
 
28
25
  /** @description Throw on error */
29
26
  throwError?: boolean
30
27
 
31
- /** @description Parent that should also report events from this api */
32
- reportableParent?: XyoApiReportable
28
+ /** @description Throw on failures */
29
+ throwFailure?: boolean
30
+
31
+ /** @deprecated use the jwtToken instead*/
32
+ userid?: string
33
33
  }
34
34
 
35
35
  export type { XyoApiConfig }
@@ -7,8 +7,8 @@ export type ExpirationWindow = 'create' | 'read'
7
7
  export interface XyoAccessControl {
8
8
  access?: Record<AccessType, AccessLevel>
9
9
  expiration?: {
10
- window?: ExpirationWindow
11
10
  delay?: number
11
+ window?: ExpirationWindow
12
12
  }
13
13
  }
14
14
 
@@ -23,6 +23,6 @@ export interface XyoAccessControls {
23
23
  }
24
24
 
25
25
  export interface XyoArchive extends XyoArchivePath {
26
- user?: string
27
26
  accessControl?: XyoAccessControl | boolean
27
+ user?: string
28
28
  }