@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.
- package/dist/cjs/Archivist/XyoRemoteArchivist.d.ts.map +1 -1
- package/dist/cjs/Archivist/XyoRemoteArchivist.js +12 -9
- package/dist/cjs/Archivist/XyoRemoteArchivist.js.map +1 -1
- package/dist/cjs/Base.d.ts +14 -14
- package/dist/cjs/Base.d.ts.map +1 -1
- package/dist/cjs/Base.js +71 -71
- package/dist/cjs/Base.js.map +1 -1
- package/dist/cjs/Diviner/LocationDiviner/ApiConfig.d.ts +2 -2
- package/dist/cjs/Diviner/LocationDiviner/Queries/LocationHeatmapQuery/LocationHeatmapQuery.d.ts +1 -1
- package/dist/cjs/Diviner/LocationDiviner/Queries/LocationHeatmapQuery/LocationHeatmapQuery.d.ts.map +1 -1
- package/dist/cjs/Diviner/LocationDiviner/Queries/LocationQuadkeyHeatmapQuery/LocationQuadkeyHeatmapQuery.d.ts +1 -1
- package/dist/cjs/Diviner/LocationDiviner/Queries/LocationQuadkeyHeatmapQuery/LocationQuadkeyHeatmapQuery.d.ts.map +1 -1
- package/dist/cjs/Diviner/LocationDiviner/Queries/LocationQueryCreationRequest.d.ts +4 -4
- package/dist/cjs/Diviner/LocationDiviner/Queries/LocationQueryCreationRequest.d.ts.map +1 -1
- package/dist/cjs/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/LocationTimeRangePointProperties.d.ts +1 -1
- package/dist/cjs/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/LocationTimeRangePointProperties.d.ts.map +1 -1
- package/dist/cjs/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/LocationTimeRangeQuery.d.ts +1 -1
- package/dist/cjs/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/LocationTimeRangeQuery.d.ts.map +1 -1
- package/dist/cjs/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/LocationTimeRangeQuery.js.map +1 -1
- package/dist/cjs/Diviner/LocationDiviner/models.d.ts +1 -1
- package/dist/cjs/Diviner/LocationDiviner/models.d.ts.map +1 -1
- package/dist/cjs/Diviner/RemoteDivinerError.d.ts +1 -1
- package/dist/cjs/Diviner/RemoteDivinerError.d.ts.map +1 -1
- package/dist/cjs/Diviner/RemoteDivinerError.js.map +1 -1
- package/dist/cjs/Diviner/XyoRemoteDivinerConfig.d.ts +1 -1
- package/dist/cjs/Diviner/XyoRemoteDivinerConfig.d.ts.map +1 -1
- package/dist/cjs/Simple.d.ts +6 -6
- package/dist/cjs/Simple.d.ts.map +1 -1
- package/dist/cjs/Simple.js +12 -12
- package/dist/cjs/Simple.js.map +1 -1
- package/dist/cjs/User/Api.d.ts +5 -5
- package/dist/cjs/models/Api/Config.d.ts +12 -12
- package/dist/cjs/models/Api/Config.d.ts.map +1 -1
- package/dist/cjs/models/Archive.d.ts +2 -2
- package/dist/cjs/models/Archive.d.ts.map +1 -1
- package/dist/docs.json +4291 -4291
- package/dist/esm/Archivist/XyoRemoteArchivist.d.ts.map +1 -1
- package/dist/esm/Archivist/XyoRemoteArchivist.js +11 -8
- package/dist/esm/Archivist/XyoRemoteArchivist.js.map +1 -1
- package/dist/esm/Base.d.ts +14 -14
- package/dist/esm/Base.d.ts.map +1 -1
- package/dist/esm/Base.js +63 -63
- package/dist/esm/Base.js.map +1 -1
- package/dist/esm/Diviner/LocationDiviner/ApiConfig.d.ts +2 -2
- package/dist/esm/Diviner/LocationDiviner/Queries/LocationHeatmapQuery/LocationHeatmapQuery.d.ts +1 -1
- package/dist/esm/Diviner/LocationDiviner/Queries/LocationHeatmapQuery/LocationHeatmapQuery.d.ts.map +1 -1
- package/dist/esm/Diviner/LocationDiviner/Queries/LocationQuadkeyHeatmapQuery/LocationQuadkeyHeatmapQuery.d.ts +1 -1
- package/dist/esm/Diviner/LocationDiviner/Queries/LocationQuadkeyHeatmapQuery/LocationQuadkeyHeatmapQuery.d.ts.map +1 -1
- package/dist/esm/Diviner/LocationDiviner/Queries/LocationQueryCreationRequest.d.ts +4 -4
- package/dist/esm/Diviner/LocationDiviner/Queries/LocationQueryCreationRequest.d.ts.map +1 -1
- package/dist/esm/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/LocationTimeRangePointProperties.d.ts +1 -1
- package/dist/esm/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/LocationTimeRangePointProperties.d.ts.map +1 -1
- package/dist/esm/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/LocationTimeRangeQuery.d.ts +1 -1
- package/dist/esm/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/LocationTimeRangeQuery.d.ts.map +1 -1
- package/dist/esm/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/LocationTimeRangeQuery.js.map +1 -1
- package/dist/esm/Diviner/LocationDiviner/models.d.ts +1 -1
- package/dist/esm/Diviner/LocationDiviner/models.d.ts.map +1 -1
- package/dist/esm/Diviner/RemoteDivinerError.d.ts +1 -1
- package/dist/esm/Diviner/RemoteDivinerError.d.ts.map +1 -1
- package/dist/esm/Diviner/RemoteDivinerError.js +1 -1
- package/dist/esm/Diviner/RemoteDivinerError.js.map +1 -1
- package/dist/esm/Diviner/XyoRemoteDivinerConfig.d.ts +1 -1
- package/dist/esm/Diviner/XyoRemoteDivinerConfig.d.ts.map +1 -1
- package/dist/esm/Simple.d.ts +6 -6
- package/dist/esm/Simple.d.ts.map +1 -1
- package/dist/esm/Simple.js +11 -11
- package/dist/esm/Simple.js.map +1 -1
- package/dist/esm/User/Api.d.ts +5 -5
- package/dist/esm/models/Api/Config.d.ts +12 -12
- package/dist/esm/models/Api/Config.d.ts.map +1 -1
- package/dist/esm/models/Archive.d.ts +2 -2
- package/dist/esm/models/Archive.d.ts.map +1 -1
- package/package.json +9 -9
- package/src/Archivist/XyoRemoteArchivist.spec.ts +5 -0
- package/src/Archivist/XyoRemoteArchivist.ts +11 -8
- package/src/Base.ts +71 -71
- package/src/Diviner/LocationDiviner/ApiConfig.ts +2 -2
- package/src/Diviner/LocationDiviner/Queries/LocationHeatmapQuery/LocationHeatmapQuery.ts +1 -1
- package/src/Diviner/LocationDiviner/Queries/LocationQuadkeyHeatmapQuery/LocationQuadkeyHeatmapQuery.ts +1 -1
- package/src/Diviner/LocationDiviner/Queries/LocationQueryCreationRequest.ts +4 -4
- package/src/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/LocationTimeRangePointProperties.ts +1 -1
- package/src/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/LocationTimeRangeQuery.ts +2 -1
- package/src/Diviner/LocationDiviner/models.ts +1 -1
- package/src/Diviner/RemoteDivinerError.ts +1 -1
- package/src/Diviner/XyoRemoteDivinerConfig.ts +1 -1
- package/src/Simple.ts +18 -18
- package/src/models/Api/Config.ts +14 -14
- package/src/models/Archive.ts +2 -2
package/dist/esm/User/Api.d.ts
CHANGED
|
@@ -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
|
-
|
|
28
|
-
|
|
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
|
|
18
|
-
|
|
19
|
-
/** @description
|
|
20
|
-
|
|
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,
|
|
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,
|
|
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.
|
|
15
|
-
"@xyo-network/archivist": "^2.38.
|
|
16
|
-
"@xyo-network/boundwitness": "^2.38.
|
|
17
|
-
"@xyo-network/core": "^2.38.
|
|
18
|
-
"@xyo-network/diviner": "^2.38.
|
|
19
|
-
"@xyo-network/module": "^2.38.
|
|
20
|
-
"@xyo-network/payload": "^2.38.
|
|
21
|
-
"@xyo-network/schema-payload-plugin": "^2.38.
|
|
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.
|
|
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 = [],
|
|
87
|
-
if (
|
|
88
|
-
throw new RemoteArchivistError('find',
|
|
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
|
-
|
|
91
|
-
|
|
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
|
-
|
|
95
|
-
|
|
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
|
-
|
|
26
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
-
|
|
83
|
-
|
|
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
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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
|
-
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
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
|
-
|
|
180
|
-
return
|
|
179
|
+
private resolveRoot() {
|
|
180
|
+
return `${this.config.apiDomain}${this.root}`
|
|
181
181
|
}
|
|
182
182
|
}
|
|
@@ -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
|
-
|
|
12
|
-
sourceArchive: string
|
|
13
|
-
resultArchivist: XyoApiConfig
|
|
11
|
+
query: TQuery
|
|
14
12
|
resultArchive: string
|
|
13
|
+
resultArchivist: XyoApiConfig
|
|
15
14
|
schema: TSchema
|
|
16
|
-
|
|
15
|
+
sourceArchive: string
|
|
16
|
+
sourceArchivist: XyoApiConfig
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export type LocationTimeRangeQueryCreationRequest = LocationQueryCreationRequest<LocationTimeRangeQuerySchema, LocationTimeRangeQuery>
|
package/src/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/LocationTimeRangeQuery.ts
CHANGED
|
@@ -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
|
-
|
|
13
|
+
|
|
13
14
|
// TODO: Bounding rectangle, etc.
|
|
14
15
|
}
|
|
15
16
|
|
|
@@ -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
|
|
16
|
-
public async
|
|
17
|
-
public async
|
|
18
|
-
public async
|
|
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.
|
|
21
|
+
return await this.deleteEndpoint(undefined, 'tuple')
|
|
22
22
|
default:
|
|
23
|
-
return await this.
|
|
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
|
}
|
package/src/models/Api/Config.ts
CHANGED
|
@@ -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
|
|
17
|
-
|
|
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
|
|
23
|
-
|
|
19
|
+
/** @description Parent that should also report events from this api */
|
|
20
|
+
reportableParent?: XyoApiReportable
|
|
24
21
|
|
|
25
|
-
/** @description
|
|
26
|
-
|
|
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
|
|
32
|
-
|
|
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 }
|
package/src/models/Archive.ts
CHANGED
|
@@ -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
|
}
|