@xyo-network/api 2.75.0 → 2.75.2
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/browser/Api/Api.d.cts +12 -0
- package/dist/browser/Api/Api.d.cts.map +1 -0
- package/dist/browser/Api/Api.js +3 -155
- package/dist/browser/Api/Api.js.map +1 -1
- package/dist/browser/Api/index.d.cts +2 -0
- package/dist/browser/Api/index.d.cts.map +1 -0
- package/dist/browser/Api/index.js +1 -166
- package/dist/browser/Api/index.js.map +1 -1
- package/dist/browser/Base.d.cts +32 -0
- package/dist/browser/Base.d.cts.map +1 -0
- package/dist/browser/Base.js +7 -8
- package/dist/browser/Base.js.map +1 -1
- package/dist/browser/Diviner/LocationDiviner/LocationDivinerApi.d.cts +12 -0
- package/dist/browser/Diviner/LocationDiviner/LocationDivinerApi.d.cts.map +1 -0
- package/dist/browser/Diviner/LocationDiviner/LocationDivinerApi.js +5 -16
- package/dist/browser/Diviner/LocationDiviner/LocationDivinerApi.js.map +1 -1
- package/dist/browser/Diviner/LocationDiviner/LocationDivinerApiResponseTransformer.d.cts +10 -0
- package/dist/browser/Diviner/LocationDiviner/LocationDivinerApiResponseTransformer.d.cts.map +1 -0
- package/dist/browser/Diviner/LocationDiviner/LocationDivinerApiResponseTransformer.js +2 -3
- package/dist/browser/Diviner/LocationDiviner/LocationDivinerApiResponseTransformer.js.map +1 -1
- package/dist/browser/Diviner/LocationDiviner/Queries/LocationHeatmapQuery/LocationHeatmapPointProperties.d.cts +5 -0
- package/dist/browser/Diviner/LocationDiviner/Queries/LocationHeatmapQuery/LocationHeatmapPointProperties.d.cts.map +1 -0
- package/dist/browser/Diviner/LocationDiviner/Queries/LocationHeatmapQuery/LocationHeatmapQuery.d.cts +12 -0
- package/dist/browser/Diviner/LocationDiviner/Queries/LocationHeatmapQuery/LocationHeatmapQuery.d.cts.map +1 -0
- package/dist/browser/Diviner/LocationDiviner/Queries/LocationHeatmapQuery/LocationHeatmapQuery.js +3 -4
- package/dist/browser/Diviner/LocationDiviner/Queries/LocationHeatmapQuery/LocationHeatmapQuery.js.map +1 -1
- package/dist/browser/Diviner/LocationDiviner/Queries/LocationHeatmapQuery/index.d.cts +3 -0
- package/dist/browser/Diviner/LocationDiviner/Queries/LocationHeatmapQuery/index.d.cts.map +1 -0
- package/dist/browser/Diviner/LocationDiviner/Queries/LocationHeatmapQuery/index.js +2 -11
- package/dist/browser/Diviner/LocationDiviner/Queries/LocationHeatmapQuery/index.js.map +1 -1
- package/dist/browser/Diviner/LocationDiviner/Queries/LocationQuadkeyHeatmapQuery/LocationQuadkeyHeatmapQuery.d.cts +12 -0
- package/dist/browser/Diviner/LocationDiviner/Queries/LocationQuadkeyHeatmapQuery/LocationQuadkeyHeatmapQuery.d.cts.map +1 -0
- package/dist/browser/Diviner/LocationDiviner/Queries/LocationQuadkeyHeatmapQuery/LocationQuadkeyHeatmapQuery.js +3 -4
- package/dist/browser/Diviner/LocationDiviner/Queries/LocationQuadkeyHeatmapQuery/LocationQuadkeyHeatmapQuery.js.map +1 -1
- package/dist/browser/Diviner/LocationDiviner/Queries/LocationQuadkeyHeatmapQuery/index.d.cts +2 -0
- package/dist/browser/Diviner/LocationDiviner/Queries/LocationQuadkeyHeatmapQuery/index.d.cts.map +1 -0
- package/dist/browser/Diviner/LocationDiviner/Queries/LocationQuadkeyHeatmapQuery/index.js +1 -11
- package/dist/browser/Diviner/LocationDiviner/Queries/LocationQuadkeyHeatmapQuery/index.js.map +1 -1
- package/dist/browser/Diviner/LocationDiviner/Queries/LocationQueryCreationRequest.d.cts +18 -0
- package/dist/browser/Diviner/LocationDiviner/Queries/LocationQueryCreationRequest.d.cts.map +1 -0
- package/dist/browser/Diviner/LocationDiviner/Queries/LocationQueryCreationResponse.d.cts +5 -0
- package/dist/browser/Diviner/LocationDiviner/Queries/LocationQueryCreationResponse.d.cts.map +1 -0
- package/dist/browser/Diviner/LocationDiviner/Queries/LocationQuerySchema.d.cts +6 -0
- package/dist/browser/Diviner/LocationDiviner/Queries/LocationQuerySchema.d.cts.map +1 -0
- package/dist/browser/Diviner/LocationDiviner/Queries/LocationQuerySchema.js +2 -3
- package/dist/browser/Diviner/LocationDiviner/Queries/LocationQuerySchema.js.map +1 -1
- package/dist/browser/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/LocationTimeRangePointProperties.d.cts +8 -0
- package/dist/browser/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/LocationTimeRangePointProperties.d.cts.map +1 -0
- package/dist/browser/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/LocationTimeRangeQuery.d.cts +12 -0
- package/dist/browser/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/LocationTimeRangeQuery.d.cts.map +1 -0
- package/dist/browser/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/LocationTimeRangeQuery.js +3 -4
- package/dist/browser/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/LocationTimeRangeQuery.js.map +1 -1
- package/dist/browser/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/index.d.cts +3 -0
- package/dist/browser/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/index.d.cts.map +1 -0
- package/dist/browser/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/index.js +2 -11
- package/dist/browser/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/index.js.map +1 -1
- package/dist/browser/Diviner/LocationDiviner/Queries/index.d.cts +7 -0
- package/dist/browser/Diviner/LocationDiviner/Queries/index.d.cts.map +1 -0
- package/dist/browser/Diviner/LocationDiviner/Queries/index.js +6 -42
- package/dist/browser/Diviner/LocationDiviner/Queries/index.js.map +1 -1
- package/dist/browser/Diviner/LocationDiviner/Witnesses/CurrentLocationWitness.d.cts +13 -0
- package/dist/browser/Diviner/LocationDiviner/Witnesses/CurrentLocationWitness.d.cts.map +1 -0
- package/dist/browser/Diviner/LocationDiviner/Witnesses/CurrentLocationWitness.js +1 -2
- package/dist/browser/Diviner/LocationDiviner/Witnesses/CurrentLocationWitness.js.map +1 -1
- package/dist/browser/Diviner/LocationDiviner/Witnesses/LocationWitness.d.cts +21 -0
- package/dist/browser/Diviner/LocationDiviner/Witnesses/LocationWitness.d.cts.map +1 -0
- package/dist/browser/Diviner/LocationDiviner/Witnesses/LocationWitness.js +1 -2
- package/dist/browser/Diviner/LocationDiviner/Witnesses/LocationWitness.js.map +1 -1
- package/dist/browser/Diviner/LocationDiviner/Witnesses/index.d.cts +3 -0
- package/dist/browser/Diviner/LocationDiviner/Witnesses/index.d.cts.map +1 -0
- package/dist/browser/Diviner/LocationDiviner/Witnesses/index.js +2 -9
- package/dist/browser/Diviner/LocationDiviner/Witnesses/index.js.map +1 -1
- package/dist/browser/Diviner/LocationDiviner/index.d.cts +5 -0
- package/dist/browser/Diviner/LocationDiviner/index.d.cts.map +1 -0
- package/dist/browser/Diviner/LocationDiviner/index.js +4 -82
- package/dist/browser/Diviner/LocationDiviner/index.js.map +1 -1
- package/dist/browser/Diviner/LocationDiviner/models.d.cts +5 -0
- package/dist/browser/Diviner/LocationDiviner/models.d.cts.map +1 -0
- package/dist/browser/Diviner/RemoteDivinerConfig.d.cts +11 -0
- package/dist/browser/Diviner/RemoteDivinerConfig.d.cts.map +1 -0
- package/dist/browser/Diviner/RemoteDivinerConfig.js +1 -2
- package/dist/browser/Diviner/RemoteDivinerConfig.js.map +1 -1
- package/dist/browser/Diviner/RemoteDivinerError.d.cts +6 -0
- package/dist/browser/Diviner/RemoteDivinerError.d.cts.map +1 -0
- package/dist/browser/Diviner/RemoteDivinerError.js +2 -3
- package/dist/browser/Diviner/RemoteDivinerError.js.map +1 -1
- package/dist/browser/Diviner/index.d.cts +3 -0
- package/dist/browser/Diviner/index.d.cts.map +1 -0
- package/dist/browser/Diviner/index.js +2 -86
- package/dist/browser/Diviner/index.js.map +1 -1
- package/dist/browser/Simple.d.cts +22 -0
- package/dist/browser/Simple.d.cts.map +1 -0
- package/dist/browser/Simple.js +4 -109
- package/dist/browser/Simple.js.map +1 -1
- package/dist/browser/Test/index.d.cts +3 -0
- package/dist/browser/Test/index.d.cts.map +1 -0
- package/dist/browser/Test/index.js +2 -32
- package/dist/browser/Test/index.js.map +1 -1
- package/dist/browser/Test/testBoundWitness.d.cts +4 -0
- package/dist/browser/Test/testBoundWitness.d.cts.map +1 -0
- package/dist/browser/Test/testBoundWitness.js +1 -2
- package/dist/browser/Test/testBoundWitness.js.map +1 -1
- package/dist/browser/Test/testPayload.d.cts +6 -0
- package/dist/browser/Test/testPayload.d.cts.map +1 -0
- package/dist/browser/Test/testPayload.js +2 -3
- package/dist/browser/Test/testPayload.js.map +1 -1
- package/dist/browser/WithArchive.d.cts +4 -0
- package/dist/browser/WithArchive.d.cts.map +1 -0
- package/dist/browser/index.d.cts +7 -0
- package/dist/browser/index.d.cts.map +1 -0
- package/dist/browser/index.js +6 -253
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/models/ArchivePath.d.cts +4 -0
- package/dist/browser/models/ArchivePath.d.cts.map +1 -0
- package/dist/browser/models/index.d.cts +2 -0
- package/dist/browser/models/index.d.cts.map +1 -0
- package/dist/browser/models/index.js +1 -0
- package/dist/browser/models/index.js.map +1 -1
- package/dist/browser/objToQuery.d.cts +2 -0
- package/dist/browser/objToQuery.d.cts.map +1 -0
- package/dist/browser/objToQuery.js +1 -2
- package/dist/browser/objToQuery.js.map +1 -1
- package/dist/docs.json +16171 -0
- package/dist/node/Api/Api.d.cts +12 -0
- package/dist/node/Api/Api.d.cts.map +1 -0
- package/dist/node/Api/Api.js +161 -4
- package/dist/node/Api/Api.js.map +1 -1
- package/dist/node/Api/Api.mjs +159 -3
- package/dist/node/Api/Api.mjs.map +1 -1
- package/dist/node/Api/index.d.cts +2 -0
- package/dist/node/Api/index.d.cts.map +1 -0
- package/dist/node/Api/index.js +178 -3
- package/dist/node/Api/index.js.map +1 -1
- package/dist/node/Api/index.mjs +170 -1
- package/dist/node/Api/index.mjs.map +1 -1
- package/dist/node/Base.d.cts +32 -0
- package/dist/node/Base.d.cts.map +1 -0
- package/dist/node/Base.js +20 -14
- package/dist/node/Base.js.map +1 -1
- package/dist/node/Base.mjs +19 -14
- package/dist/node/Base.mjs.map +1 -1
- package/dist/node/Diviner/LocationDiviner/LocationDivinerApi.d.cts +12 -0
- package/dist/node/Diviner/LocationDiviner/LocationDivinerApi.d.cts.map +1 -0
- package/dist/node/Diviner/LocationDiviner/LocationDivinerApi.js +18 -6
- package/dist/node/Diviner/LocationDiviner/LocationDivinerApi.js.map +1 -1
- package/dist/node/Diviner/LocationDiviner/LocationDivinerApi.mjs +16 -5
- package/dist/node/Diviner/LocationDiviner/LocationDivinerApi.mjs.map +1 -1
- package/dist/node/Diviner/LocationDiviner/LocationDivinerApiResponseTransformer.d.cts +10 -0
- package/dist/node/Diviner/LocationDiviner/LocationDivinerApiResponseTransformer.d.cts.map +1 -0
- package/dist/node/Diviner/LocationDiviner/LocationDivinerApiResponseTransformer.js +4 -2
- package/dist/node/Diviner/LocationDiviner/LocationDivinerApiResponseTransformer.js.map +1 -1
- package/dist/node/Diviner/LocationDiviner/LocationDivinerApiResponseTransformer.mjs +3 -2
- package/dist/node/Diviner/LocationDiviner/LocationDivinerApiResponseTransformer.mjs.map +1 -1
- package/dist/node/Diviner/LocationDiviner/Queries/LocationHeatmapQuery/LocationHeatmapPointProperties.d.cts +5 -0
- package/dist/node/Diviner/LocationDiviner/Queries/LocationHeatmapQuery/LocationHeatmapPointProperties.d.cts.map +1 -0
- package/dist/node/Diviner/LocationDiviner/Queries/LocationHeatmapQuery/LocationHeatmapPointProperties.js +2 -0
- package/dist/node/Diviner/LocationDiviner/Queries/LocationHeatmapQuery/LocationHeatmapPointProperties.js.map +1 -1
- package/dist/node/Diviner/LocationDiviner/Queries/LocationHeatmapQuery/LocationHeatmapQuery.d.cts +12 -0
- package/dist/node/Diviner/LocationDiviner/Queries/LocationHeatmapQuery/LocationHeatmapQuery.d.cts.map +1 -0
- package/dist/node/Diviner/LocationDiviner/Queries/LocationHeatmapQuery/LocationHeatmapQuery.js +6 -4
- package/dist/node/Diviner/LocationDiviner/Queries/LocationHeatmapQuery/LocationHeatmapQuery.js.map +1 -1
- package/dist/node/Diviner/LocationDiviner/Queries/LocationHeatmapQuery/LocationHeatmapQuery.mjs +5 -4
- package/dist/node/Diviner/LocationDiviner/Queries/LocationHeatmapQuery/LocationHeatmapQuery.mjs.map +1 -1
- package/dist/node/Diviner/LocationDiviner/Queries/LocationHeatmapQuery/index.d.cts +3 -0
- package/dist/node/Diviner/LocationDiviner/Queries/LocationHeatmapQuery/index.d.cts.map +1 -0
- package/dist/node/Diviner/LocationDiviner/Queries/LocationHeatmapQuery/index.js +21 -5
- package/dist/node/Diviner/LocationDiviner/Queries/LocationHeatmapQuery/index.js.map +1 -1
- package/dist/node/Diviner/LocationDiviner/Queries/LocationHeatmapQuery/index.mjs +11 -2
- package/dist/node/Diviner/LocationDiviner/Queries/LocationHeatmapQuery/index.mjs.map +1 -1
- package/dist/node/Diviner/LocationDiviner/Queries/LocationQuadkeyHeatmapQuery/LocationQuadkeyHeatmapQuery.d.cts +12 -0
- package/dist/node/Diviner/LocationDiviner/Queries/LocationQuadkeyHeatmapQuery/LocationQuadkeyHeatmapQuery.d.cts.map +1 -0
- package/dist/node/Diviner/LocationDiviner/Queries/LocationQuadkeyHeatmapQuery/LocationQuadkeyHeatmapQuery.js +6 -4
- package/dist/node/Diviner/LocationDiviner/Queries/LocationQuadkeyHeatmapQuery/LocationQuadkeyHeatmapQuery.js.map +1 -1
- package/dist/node/Diviner/LocationDiviner/Queries/LocationQuadkeyHeatmapQuery/LocationQuadkeyHeatmapQuery.mjs +5 -4
- package/dist/node/Diviner/LocationDiviner/Queries/LocationQuadkeyHeatmapQuery/LocationQuadkeyHeatmapQuery.mjs.map +1 -1
- package/dist/node/Diviner/LocationDiviner/Queries/LocationQuadkeyHeatmapQuery/index.d.cts +2 -0
- package/dist/node/Diviner/LocationDiviner/Queries/LocationQuadkeyHeatmapQuery/index.d.cts.map +1 -0
- package/dist/node/Diviner/LocationDiviner/Queries/LocationQuadkeyHeatmapQuery/index.js +21 -3
- package/dist/node/Diviner/LocationDiviner/Queries/LocationQuadkeyHeatmapQuery/index.js.map +1 -1
- package/dist/node/Diviner/LocationDiviner/Queries/LocationQuadkeyHeatmapQuery/index.mjs +11 -1
- package/dist/node/Diviner/LocationDiviner/Queries/LocationQuadkeyHeatmapQuery/index.mjs.map +1 -1
- package/dist/node/Diviner/LocationDiviner/Queries/LocationQueryCreationRequest.d.cts +18 -0
- package/dist/node/Diviner/LocationDiviner/Queries/LocationQueryCreationRequest.d.cts.map +1 -0
- package/dist/node/Diviner/LocationDiviner/Queries/LocationQueryCreationRequest.js +2 -0
- package/dist/node/Diviner/LocationDiviner/Queries/LocationQueryCreationRequest.js.map +1 -1
- package/dist/node/Diviner/LocationDiviner/Queries/LocationQueryCreationResponse.d.cts +5 -0
- package/dist/node/Diviner/LocationDiviner/Queries/LocationQueryCreationResponse.d.cts.map +1 -0
- package/dist/node/Diviner/LocationDiviner/Queries/LocationQueryCreationResponse.js +2 -0
- package/dist/node/Diviner/LocationDiviner/Queries/LocationQueryCreationResponse.js.map +1 -1
- package/dist/node/Diviner/LocationDiviner/Queries/LocationQuerySchema.d.cts +6 -0
- package/dist/node/Diviner/LocationDiviner/Queries/LocationQuerySchema.d.cts.map +1 -0
- package/dist/node/Diviner/LocationDiviner/Queries/LocationQuerySchema.js +4 -2
- package/dist/node/Diviner/LocationDiviner/Queries/LocationQuerySchema.js.map +1 -1
- package/dist/node/Diviner/LocationDiviner/Queries/LocationQuerySchema.mjs +3 -2
- package/dist/node/Diviner/LocationDiviner/Queries/LocationQuerySchema.mjs.map +1 -1
- package/dist/node/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/LocationTimeRangePointProperties.d.cts +8 -0
- package/dist/node/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/LocationTimeRangePointProperties.d.cts.map +1 -0
- package/dist/node/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/LocationTimeRangePointProperties.js +2 -0
- package/dist/node/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/LocationTimeRangePointProperties.js.map +1 -1
- package/dist/node/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/LocationTimeRangeQuery.d.cts +12 -0
- package/dist/node/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/LocationTimeRangeQuery.d.cts.map +1 -0
- package/dist/node/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/LocationTimeRangeQuery.js +6 -4
- package/dist/node/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/LocationTimeRangeQuery.js.map +1 -1
- package/dist/node/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/LocationTimeRangeQuery.mjs +5 -4
- package/dist/node/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/LocationTimeRangeQuery.mjs.map +1 -1
- package/dist/node/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/index.d.cts +3 -0
- package/dist/node/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/index.d.cts.map +1 -0
- package/dist/node/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/index.js +21 -5
- package/dist/node/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/index.js.map +1 -1
- package/dist/node/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/index.mjs +11 -2
- package/dist/node/Diviner/LocationDiviner/Queries/LocationTimeRangeQuery/index.mjs.map +1 -1
- package/dist/node/Diviner/LocationDiviner/Queries/index.d.cts +7 -0
- package/dist/node/Diviner/LocationDiviner/Queries/index.d.cts.map +1 -0
- package/dist/node/Diviner/LocationDiviner/Queries/index.js +59 -13
- package/dist/node/Diviner/LocationDiviner/Queries/index.js.map +1 -1
- package/dist/node/Diviner/LocationDiviner/Queries/index.mjs +42 -6
- package/dist/node/Diviner/LocationDiviner/Queries/index.mjs.map +1 -1
- package/dist/node/Diviner/LocationDiviner/Witnesses/CurrentLocationWitness.d.cts +13 -0
- package/dist/node/Diviner/LocationDiviner/Witnesses/CurrentLocationWitness.d.cts.map +1 -0
- package/dist/node/Diviner/LocationDiviner/Witnesses/CurrentLocationWitness.js +3 -1
- package/dist/node/Diviner/LocationDiviner/Witnesses/CurrentLocationWitness.js.map +1 -1
- package/dist/node/Diviner/LocationDiviner/Witnesses/CurrentLocationWitness.mjs +2 -1
- package/dist/node/Diviner/LocationDiviner/Witnesses/CurrentLocationWitness.mjs.map +1 -1
- package/dist/node/Diviner/LocationDiviner/Witnesses/LocationWitness.d.cts +21 -0
- package/dist/node/Diviner/LocationDiviner/Witnesses/LocationWitness.d.cts.map +1 -0
- package/dist/node/Diviner/LocationDiviner/Witnesses/LocationWitness.js +3 -1
- package/dist/node/Diviner/LocationDiviner/Witnesses/LocationWitness.js.map +1 -1
- package/dist/node/Diviner/LocationDiviner/Witnesses/LocationWitness.mjs +2 -1
- package/dist/node/Diviner/LocationDiviner/Witnesses/LocationWitness.mjs.map +1 -1
- package/dist/node/Diviner/LocationDiviner/Witnesses/index.d.cts +3 -0
- package/dist/node/Diviner/LocationDiviner/Witnesses/index.d.cts.map +1 -0
- package/dist/node/Diviner/LocationDiviner/Witnesses/index.js +18 -5
- package/dist/node/Diviner/LocationDiviner/Witnesses/index.js.map +1 -1
- package/dist/node/Diviner/LocationDiviner/Witnesses/index.mjs +9 -2
- package/dist/node/Diviner/LocationDiviner/Witnesses/index.mjs.map +1 -1
- package/dist/node/Diviner/LocationDiviner/index.d.cts +5 -0
- package/dist/node/Diviner/LocationDiviner/index.d.cts.map +1 -0
- package/dist/node/Diviner/LocationDiviner/index.js +102 -9
- package/dist/node/Diviner/LocationDiviner/index.js.map +1 -1
- package/dist/node/Diviner/LocationDiviner/index.mjs +82 -4
- package/dist/node/Diviner/LocationDiviner/index.mjs.map +1 -1
- package/dist/node/Diviner/LocationDiviner/models.d.cts +5 -0
- package/dist/node/Diviner/LocationDiviner/models.d.cts.map +1 -0
- package/dist/node/Diviner/LocationDiviner/models.js +2 -0
- package/dist/node/Diviner/LocationDiviner/models.js.map +1 -1
- package/dist/node/Diviner/RemoteDivinerConfig.d.cts +11 -0
- package/dist/node/Diviner/RemoteDivinerConfig.d.cts.map +1 -0
- package/dist/node/Diviner/RemoteDivinerConfig.js +3 -1
- package/dist/node/Diviner/RemoteDivinerConfig.js.map +1 -1
- package/dist/node/Diviner/RemoteDivinerConfig.mjs +2 -1
- package/dist/node/Diviner/RemoteDivinerConfig.mjs.map +1 -1
- package/dist/node/Diviner/RemoteDivinerError.d.cts +6 -0
- package/dist/node/Diviner/RemoteDivinerError.d.cts.map +1 -0
- package/dist/node/Diviner/RemoteDivinerError.js +4 -2
- package/dist/node/Diviner/RemoteDivinerError.js.map +1 -1
- package/dist/node/Diviner/RemoteDivinerError.mjs +3 -2
- package/dist/node/Diviner/RemoteDivinerError.mjs.map +1 -1
- package/dist/node/Diviner/index.d.cts +3 -0
- package/dist/node/Diviner/index.d.cts.map +1 -0
- package/dist/node/Diviner/index.js +107 -5
- package/dist/node/Diviner/index.js.map +1 -1
- package/dist/node/Diviner/index.mjs +86 -2
- package/dist/node/Diviner/index.mjs.map +1 -1
- package/dist/node/Simple.d.cts +22 -0
- package/dist/node/Simple.d.cts.map +1 -0
- package/dist/node/Simple.js +118 -6
- package/dist/node/Simple.js.map +1 -1
- package/dist/node/Simple.mjs +113 -4
- package/dist/node/Simple.mjs.map +1 -1
- package/dist/node/Test/index.d.cts +3 -0
- package/dist/node/Test/index.d.cts.map +1 -0
- package/dist/node/Test/index.js +42 -5
- package/dist/node/Test/index.js.map +1 -1
- package/dist/node/Test/index.mjs +32 -2
- package/dist/node/Test/index.mjs.map +1 -1
- package/dist/node/Test/testBoundWitness.d.cts +4 -0
- package/dist/node/Test/testBoundWitness.d.cts.map +1 -0
- package/dist/node/Test/testBoundWitness.js +3 -1
- package/dist/node/Test/testBoundWitness.js.map +1 -1
- package/dist/node/Test/testBoundWitness.mjs +2 -1
- package/dist/node/Test/testBoundWitness.mjs.map +1 -1
- package/dist/node/Test/testPayload.d.cts +6 -0
- package/dist/node/Test/testPayload.d.cts.map +1 -0
- package/dist/node/Test/testPayload.js +4 -2
- package/dist/node/Test/testPayload.js.map +1 -1
- package/dist/node/Test/testPayload.mjs +3 -2
- package/dist/node/Test/testPayload.mjs.map +1 -1
- package/dist/node/WithArchive.d.cts +4 -0
- package/dist/node/WithArchive.d.cts.map +1 -0
- package/dist/node/WithArchive.js +2 -0
- package/dist/node/WithArchive.js.map +1 -1
- package/dist/node/index.d.cts +7 -0
- package/dist/node/index.d.cts.map +1 -0
- package/dist/node/index.js +281 -13
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +257 -6
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/models/ArchivePath.d.cts +4 -0
- package/dist/node/models/ArchivePath.d.cts.map +1 -0
- package/dist/node/models/ArchivePath.js +2 -0
- package/dist/node/models/ArchivePath.js.map +1 -1
- package/dist/node/models/index.d.cts +2 -0
- package/dist/node/models/index.d.cts.map +1 -0
- package/dist/node/models/index.js +2 -6
- package/dist/node/models/index.js.map +1 -1
- package/dist/node/models/index.mjs +0 -1
- package/dist/node/models/index.mjs.map +1 -1
- package/dist/node/objToQuery.d.cts +2 -0
- package/dist/node/objToQuery.d.cts.map +1 -0
- package/dist/node/objToQuery.js +3 -1
- package/dist/node/objToQuery.js.map +1 -1
- package/dist/node/objToQuery.mjs +2 -1
- package/dist/node/objToQuery.mjs.map +1 -1
- package/package.json +12 -12
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/Api/index.ts"],"sourcesContent":["export * from './Api'\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,kBAAd;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/Api/index.ts","../../../src/Api/Api.ts","../../../src/Base.ts","../../../src/objToQuery.ts","../../../src/Simple.ts"],"sourcesContent":["export * from './Api'\n","import { ApiConfig } from '@xyo-network/api-models'\nimport { Huri } from '@xyo-network/huri'\nimport { Payload } from '@xyo-network/payload-model'\n\nimport { ApiSimple } from '../Simple'\n\nexport class ArchivistApi<C extends ApiConfig = ApiConfig> extends ApiSimple<Payload[], C> {\n huri(huri: Huri | string) {\n const huriObj = typeof huri === 'string' ? new Huri(huri) : huri\n return new ApiSimple<Payload>({\n ...this.config,\n root: `${this.root}${huriObj.href}/`,\n })\n }\n}\n","import {\n ApiConfig,\n ApiEnvelope,\n ApiError,\n ApiReportable,\n ApiResponse,\n ApiResponseBody,\n ApiResponseTuple,\n ApiResponseTupleOrBody,\n ApiResponseType,\n} from '@xyo-network/api-models'\nimport { AxiosJson } from '@xyo-network/axios'\n\nexport class ApiBase<C extends ApiConfig = ApiConfig> implements ApiReportable {\n readonly config: C\n protected axios: AxiosJson\n\n constructor(config: C) {\n this.config = config\n this.axios = new AxiosJson({ ...this.config, headers: this.headers })\n }\n\n get authenticated() {\n return !!this.config.apiKey || !!this.config.jwtToken\n }\n\n protected get headers(): Record<string, string> {\n const headers: Record<string, string> = {}\n if (this.config.jwtToken) {\n headers.Authorization = `Bearer ${this.config.jwtToken}`\n }\n if (this.config.apiKey) {\n headers['x-api-key'] = this.config.apiKey\n }\n return headers\n }\n\n protected get query() {\n return this.config.query ?? ''\n }\n\n protected get root() {\n return this.config.root ?? '/'\n }\n\n private static resolveResponse<T>(result?: ApiResponse<ApiEnvelope<T>>) {\n return [result?.data?.data, result?.data, result] as ApiResponseTuple<T>\n }\n\n private static shapeResponse<T = unknown>(response: ApiResponse<ApiEnvelope<T>> | undefined, responseType?: ApiResponseType) {\n const resolvedResponse = ApiBase.resolveResponse(response)\n return responseType === 'tuple' ? resolvedResponse : resolvedResponse[0]\n }\n\n onError(error: ApiError, depth = 0) {\n this.config.reportableParent?.onError?.(error, depth + 1)\n this.config.onError?.(error, depth)\n }\n\n onFailure(response: ApiResponse, depth = 0) {\n this.config.reportableParent?.onFailure?.(response, depth + 1)\n this.config.onFailure?.(response, depth)\n }\n\n onSuccess(response: ApiResponse, depth = 0) {\n this.config.reportableParent?.onSuccess?.(response, depth + 1)\n this.config.onSuccess?.(response, depth)\n }\n\n protected async deleteEndpoint<T = unknown>(endPoint?: string): Promise<ApiResponseBody<T>>\n protected async deleteEndpoint<T = unknown>(endPoint?: string, responseType?: 'body'): Promise<ApiResponseBody<T>>\n protected async deleteEndpoint<T = unknown>(endPoint?: string, responseType?: 'tuple'): Promise<ApiResponseTuple<T>>\n protected async deleteEndpoint<T = unknown>(endPoint = '', responseType?: ApiResponseType): Promise<ApiResponseTupleOrBody<T>> {\n const response = await this.monitorResponse<T>(async () => {\n return await this.axios.delete<ApiEnvelope<T>, ApiResponse<ApiEnvelope<T>>>(`${this.resolveRoot()}${endPoint}${this.query}`)\n })\n return ApiBase.shapeResponse<T>(response, responseType)\n }\n\n protected async getEndpoint<T = unknown>(endPoint?: string): Promise<ApiResponseBody<T>>\n protected async getEndpoint<T = unknown>(endPoint?: string, responseType?: 'body'): Promise<ApiResponseBody<T>>\n protected async getEndpoint<T = unknown>(endPoint?: string, responseType?: 'tuple'): Promise<ApiResponseTuple<T>>\n protected async getEndpoint<T = unknown>(endPoint = '', responseType?: ApiResponseType): Promise<ApiResponseTupleOrBody<T>> {\n const response = await this.monitorResponse<T>(async () => {\n return await this.axios.get<ApiEnvelope<T>, ApiResponse<ApiEnvelope<T>>>(`${this.resolveRoot()}${endPoint}${this.query}`)\n })\n return ApiBase.shapeResponse<T>(response, responseType)\n }\n\n protected handleMonitorResponseError<T>(error: ApiError, trapAxiosException: boolean) {\n if (!error.isError) {\n throw error\n }\n\n if (trapAxiosException) {\n error.response ? this.onFailure(error.response) : this.onError(error)\n if (this.config.throwFailure) {\n throw error\n }\n return error.response as ApiResponse<ApiEnvelope<T>>\n }\n }\n\n protected async monitorResponse<T>(closure: () => Promise<ApiResponse<ApiEnvelope<T>>>) {\n //we use this to prevent accidental catching on exceptions in callbacks\n let trapAxiosException = true\n try {\n const response = await closure()\n trapAxiosException = false\n\n response.status < 300 ? this.onSuccess(response) : this.onFailure(response)\n\n return response\n } catch (ex) {\n this.handleMonitorResponseError(ex as ApiError, trapAxiosException)\n }\n }\n\n protected async postEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D): Promise<ApiResponseBody<T>>\n protected async postEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D, responseType?: 'body'): Promise<ApiResponseBody<T>>\n protected async postEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D, responseType?: 'tuple'): Promise<ApiResponseTuple<T>>\n protected async postEndpoint<T = unknown, D = unknown>(\n endPoint = '',\n data?: D,\n responseType?: ApiResponseType,\n ): Promise<ApiResponseTupleOrBody<T>> {\n const response = await this.monitorResponse<T>(async () => {\n return await this.axios.post<ApiEnvelope<T>, ApiResponse<ApiEnvelope<T>, D>, D>(`${this.resolveRoot()}${endPoint}${this.query}`, data)\n })\n return ApiBase.shapeResponse<T>(response, responseType)\n }\n\n protected async putEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D): Promise<ApiResponseBody<T>>\n protected async putEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D, responseType?: 'body'): Promise<ApiResponseBody<T>>\n protected async putEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D, responseType?: 'tuple'): Promise<ApiResponseTuple<T>>\n protected async putEndpoint<T = unknown, D = unknown>(endPoint = '', data?: D, responseType?: ApiResponseType): Promise<ApiResponseTupleOrBody<T>> {\n const response = await this.monitorResponse<T>(async () => {\n return await this.axios.put<ApiEnvelope<T>, ApiResponse<ApiEnvelope<T>, D>, D>(`${this.resolveRoot()}${endPoint}${this.query}`, data)\n })\n return ApiBase.shapeResponse<T>(response, responseType)\n }\n\n private resolveRoot() {\n return `${this.config.apiDomain}${this.root}`\n }\n}\n","export const objToQuery = (obj: Record<string, string | number | undefined>) => {\n return `?${Object.entries(obj)\n .map(([key, value]) => {\n return `${key}=${value}`\n })\n .filter((value) => value !== undefined)\n .join('&')}`\n}\n","import { ApiConfig, ApiResponseBody, ApiResponseTuple, ApiResponseTupleOrBody, ApiResponseType } from '@xyo-network/api-models'\nimport { Payload, PayloadFindFilter } from '@xyo-network/payload-model'\n\nimport { ApiBase } from './Base'\nimport { objToQuery } from './objToQuery'\n\nexport type ApiSimpleQuery = PayloadFindFilter\n\nexport class ApiSimple<T = Payload, D = T, Q extends ApiSimpleQuery = ApiSimpleQuery, C extends ApiConfig = ApiConfig> extends ApiBase<C> {\n async delete(): Promise<ApiResponseBody<T>>\n async delete(responseType?: 'body'): Promise<ApiResponseBody<T>>\n async delete(responseType?: 'tuple'): Promise<ApiResponseTuple<T>>\n async delete(responseType?: ApiResponseType): Promise<ApiResponseTupleOrBody<T>> {\n switch (responseType) {\n case 'tuple':\n return await this.deleteEndpoint(undefined, 'tuple')\n default:\n return await this.deleteEndpoint(undefined)\n }\n }\n\n async find(query?: Q): Promise<ApiResponseBody<T>>\n async find(query?: Q, responseType?: 'body'): Promise<ApiResponseBody<T>>\n async find(query?: Q, responseType?: 'tuple'): Promise<ApiResponseTuple<T>>\n async find(query = {}, responseType?: ApiResponseType): Promise<ApiResponseTupleOrBody<T>> {\n switch (responseType) {\n case 'tuple':\n return await this.getEndpoint(objToQuery(query), 'tuple')\n default:\n return await this.getEndpoint(objToQuery(query))\n }\n }\n\n async get(): Promise<ApiResponseBody<T>>\n async get(responseType?: 'body'): Promise<ApiResponseBody<T>>\n async get(responseType?: 'tuple'): Promise<ApiResponseTuple<T>>\n async get(responseType?: ApiResponseType): Promise<ApiResponseTupleOrBody<T>> {\n switch (responseType) {\n case 'tuple':\n return await this.getEndpoint(undefined, 'tuple')\n default:\n return await this.getEndpoint(undefined)\n }\n }\n\n async post(data?: D): Promise<ApiResponseBody<T>>\n async post(data?: D, responseType?: 'body'): Promise<ApiResponseBody<T>>\n async post(data?: D, responseType?: 'tuple'): Promise<ApiResponseTuple<T>>\n async post(data?: D, responseType?: ApiResponseType): Promise<ApiResponseTupleOrBody<T>> {\n switch (responseType) {\n case 'tuple':\n return await this.postEndpoint(undefined, data, 'tuple')\n default:\n return await this.postEndpoint(undefined, data)\n }\n }\n\n async put(data?: D): Promise<ApiResponseBody<T>>\n async put(data?: D, responseType?: 'body'): Promise<ApiResponseBody<T>>\n async put(data?: D, responseType?: 'tuple'): Promise<ApiResponseTuple<T>>\n async put(data?: D, responseType?: ApiResponseType): Promise<ApiResponseTupleOrBody<T>> {\n switch (responseType) {\n case 'tuple':\n return await this.putEndpoint(undefined, data, 'tuple')\n default:\n return await this.putEndpoint(undefined, data)\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,kBAAqB;;;ACUrB,mBAA0B;AAEnB,IAAM,UAAN,MAAM,SAAkE;AAAA,EACpE;AAAA,EACC;AAAA,EAEV,YAAY,QAAW;AACrB,SAAK,SAAS;AACd,SAAK,QAAQ,IAAI,uBAAU,EAAE,GAAG,KAAK,QAAQ,SAAS,KAAK,QAAQ,CAAC;AAAA,EACtE;AAAA,EAEA,IAAI,gBAAgB;AAClB,WAAO,CAAC,CAAC,KAAK,OAAO,UAAU,CAAC,CAAC,KAAK,OAAO;AAAA,EAC/C;AAAA,EAEA,IAAc,UAAkC;AAC9C,UAAM,UAAkC,CAAC;AACzC,QAAI,KAAK,OAAO,UAAU;AACxB,cAAQ,gBAAgB,UAAU,KAAK,OAAO,QAAQ;AAAA,IACxD;AACA,QAAI,KAAK,OAAO,QAAQ;AACtB,cAAQ,WAAW,IAAI,KAAK,OAAO;AAAA,IACrC;AACA,WAAO;AAAA,EACT;AAAA,EAEA,IAAc,QAAQ;AACpB,WAAO,KAAK,OAAO,SAAS;AAAA,EAC9B;AAAA,EAEA,IAAc,OAAO;AACnB,WAAO,KAAK,OAAO,QAAQ;AAAA,EAC7B;AAAA,EAEA,OAAe,gBAAmB,QAAsC;AA7C1E;AA8CI,WAAO,EAAC,sCAAQ,SAAR,mBAAc,MAAM,iCAAQ,MAAM,MAAM;AAAA,EAClD;AAAA,EAEA,OAA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AI;AAC5D,WAAO,IAAI,UAAmB;AAAA,MAC5B,GAAG,KAAK;AAAA,MACR,MAAM,GAAG,KAAK,IAAI,GAAG,QAAQ,IAAI;AAAA,IACnC,CAAC;AAAA,EACH;AACF;","names":[]}
|
package/dist/node/Api/index.mjs
CHANGED
|
@@ -1,2 +1,171 @@
|
|
|
1
|
-
|
|
1
|
+
// src/Api/Api.ts
|
|
2
|
+
import { Huri } from "@xyo-network/huri";
|
|
3
|
+
|
|
4
|
+
// src/Base.ts
|
|
5
|
+
import { AxiosJson } from "@xyo-network/axios";
|
|
6
|
+
var ApiBase = class _ApiBase {
|
|
7
|
+
config;
|
|
8
|
+
axios;
|
|
9
|
+
constructor(config) {
|
|
10
|
+
this.config = config;
|
|
11
|
+
this.axios = new AxiosJson({ ...this.config, headers: this.headers });
|
|
12
|
+
}
|
|
13
|
+
get authenticated() {
|
|
14
|
+
return !!this.config.apiKey || !!this.config.jwtToken;
|
|
15
|
+
}
|
|
16
|
+
get headers() {
|
|
17
|
+
const headers = {};
|
|
18
|
+
if (this.config.jwtToken) {
|
|
19
|
+
headers.Authorization = `Bearer ${this.config.jwtToken}`;
|
|
20
|
+
}
|
|
21
|
+
if (this.config.apiKey) {
|
|
22
|
+
headers["x-api-key"] = this.config.apiKey;
|
|
23
|
+
}
|
|
24
|
+
return headers;
|
|
25
|
+
}
|
|
26
|
+
get query() {
|
|
27
|
+
return this.config.query ?? "";
|
|
28
|
+
}
|
|
29
|
+
get root() {
|
|
30
|
+
return this.config.root ?? "/";
|
|
31
|
+
}
|
|
32
|
+
static resolveResponse(result) {
|
|
33
|
+
var _a;
|
|
34
|
+
return [(_a = result == null ? void 0 : result.data) == null ? void 0 : _a.data, result == null ? void 0 : result.data, result];
|
|
35
|
+
}
|
|
36
|
+
static shapeResponse(response, responseType) {
|
|
37
|
+
const resolvedResponse = _ApiBase.resolveResponse(response);
|
|
38
|
+
return responseType === "tuple" ? resolvedResponse : resolvedResponse[0];
|
|
39
|
+
}
|
|
40
|
+
onError(error, depth = 0) {
|
|
41
|
+
var _a, _b, _c, _d;
|
|
42
|
+
(_b = (_a = this.config.reportableParent) == null ? void 0 : _a.onError) == null ? void 0 : _b.call(_a, error, depth + 1);
|
|
43
|
+
(_d = (_c = this.config).onError) == null ? void 0 : _d.call(_c, error, depth);
|
|
44
|
+
}
|
|
45
|
+
onFailure(response, depth = 0) {
|
|
46
|
+
var _a, _b, _c, _d;
|
|
47
|
+
(_b = (_a = this.config.reportableParent) == null ? void 0 : _a.onFailure) == null ? void 0 : _b.call(_a, response, depth + 1);
|
|
48
|
+
(_d = (_c = this.config).onFailure) == null ? void 0 : _d.call(_c, response, depth);
|
|
49
|
+
}
|
|
50
|
+
onSuccess(response, depth = 0) {
|
|
51
|
+
var _a, _b, _c, _d;
|
|
52
|
+
(_b = (_a = this.config.reportableParent) == null ? void 0 : _a.onSuccess) == null ? void 0 : _b.call(_a, response, depth + 1);
|
|
53
|
+
(_d = (_c = this.config).onSuccess) == null ? void 0 : _d.call(_c, response, depth);
|
|
54
|
+
}
|
|
55
|
+
async deleteEndpoint(endPoint = "", responseType) {
|
|
56
|
+
const response = await this.monitorResponse(async () => {
|
|
57
|
+
return await this.axios.delete(`${this.resolveRoot()}${endPoint}${this.query}`);
|
|
58
|
+
});
|
|
59
|
+
return _ApiBase.shapeResponse(response, responseType);
|
|
60
|
+
}
|
|
61
|
+
async getEndpoint(endPoint = "", responseType) {
|
|
62
|
+
const response = await this.monitorResponse(async () => {
|
|
63
|
+
return await this.axios.get(`${this.resolveRoot()}${endPoint}${this.query}`);
|
|
64
|
+
});
|
|
65
|
+
return _ApiBase.shapeResponse(response, responseType);
|
|
66
|
+
}
|
|
67
|
+
handleMonitorResponseError(error, trapAxiosException) {
|
|
68
|
+
if (!error.isError) {
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
if (trapAxiosException) {
|
|
72
|
+
error.response ? this.onFailure(error.response) : this.onError(error);
|
|
73
|
+
if (this.config.throwFailure) {
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
return error.response;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
async monitorResponse(closure) {
|
|
80
|
+
let trapAxiosException = true;
|
|
81
|
+
try {
|
|
82
|
+
const response = await closure();
|
|
83
|
+
trapAxiosException = false;
|
|
84
|
+
response.status < 300 ? this.onSuccess(response) : this.onFailure(response);
|
|
85
|
+
return response;
|
|
86
|
+
} catch (ex) {
|
|
87
|
+
this.handleMonitorResponseError(ex, trapAxiosException);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
async postEndpoint(endPoint = "", data, responseType) {
|
|
91
|
+
const response = await this.monitorResponse(async () => {
|
|
92
|
+
return await this.axios.post(`${this.resolveRoot()}${endPoint}${this.query}`, data);
|
|
93
|
+
});
|
|
94
|
+
return _ApiBase.shapeResponse(response, responseType);
|
|
95
|
+
}
|
|
96
|
+
async putEndpoint(endPoint = "", data, responseType) {
|
|
97
|
+
const response = await this.monitorResponse(async () => {
|
|
98
|
+
return await this.axios.put(`${this.resolveRoot()}${endPoint}${this.query}`, data);
|
|
99
|
+
});
|
|
100
|
+
return _ApiBase.shapeResponse(response, responseType);
|
|
101
|
+
}
|
|
102
|
+
resolveRoot() {
|
|
103
|
+
return `${this.config.apiDomain}${this.root}`;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
// src/objToQuery.ts
|
|
108
|
+
var objToQuery = (obj) => {
|
|
109
|
+
return `?${Object.entries(obj).map(([key, value]) => {
|
|
110
|
+
return `${key}=${value}`;
|
|
111
|
+
}).filter((value) => value !== void 0).join("&")}`;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// src/Simple.ts
|
|
115
|
+
var ApiSimple = class extends ApiBase {
|
|
116
|
+
async delete(responseType) {
|
|
117
|
+
switch (responseType) {
|
|
118
|
+
case "tuple":
|
|
119
|
+
return await this.deleteEndpoint(void 0, "tuple");
|
|
120
|
+
default:
|
|
121
|
+
return await this.deleteEndpoint(void 0);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
async find(query = {}, responseType) {
|
|
125
|
+
switch (responseType) {
|
|
126
|
+
case "tuple":
|
|
127
|
+
return await this.getEndpoint(objToQuery(query), "tuple");
|
|
128
|
+
default:
|
|
129
|
+
return await this.getEndpoint(objToQuery(query));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
async get(responseType) {
|
|
133
|
+
switch (responseType) {
|
|
134
|
+
case "tuple":
|
|
135
|
+
return await this.getEndpoint(void 0, "tuple");
|
|
136
|
+
default:
|
|
137
|
+
return await this.getEndpoint(void 0);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
async post(data, responseType) {
|
|
141
|
+
switch (responseType) {
|
|
142
|
+
case "tuple":
|
|
143
|
+
return await this.postEndpoint(void 0, data, "tuple");
|
|
144
|
+
default:
|
|
145
|
+
return await this.postEndpoint(void 0, data);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
async put(data, responseType) {
|
|
149
|
+
switch (responseType) {
|
|
150
|
+
case "tuple":
|
|
151
|
+
return await this.putEndpoint(void 0, data, "tuple");
|
|
152
|
+
default:
|
|
153
|
+
return await this.putEndpoint(void 0, data);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
// src/Api/Api.ts
|
|
159
|
+
var ArchivistApi = class extends ApiSimple {
|
|
160
|
+
huri(huri) {
|
|
161
|
+
const huriObj = typeof huri === "string" ? new Huri(huri) : huri;
|
|
162
|
+
return new ApiSimple({
|
|
163
|
+
...this.config,
|
|
164
|
+
root: `${this.root}${huriObj.href}/`
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
export {
|
|
169
|
+
ArchivistApi
|
|
170
|
+
};
|
|
2
171
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/Api/index.ts"],"sourcesContent":["export * from './Api'\n"],"mappings":"AAAA,cAAc;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/Api/Api.ts","../../../src/Base.ts","../../../src/objToQuery.ts","../../../src/Simple.ts"],"sourcesContent":["import { ApiConfig } from '@xyo-network/api-models'\nimport { Huri } from '@xyo-network/huri'\nimport { Payload } from '@xyo-network/payload-model'\n\nimport { ApiSimple } from '../Simple'\n\nexport class ArchivistApi<C extends ApiConfig = ApiConfig> extends ApiSimple<Payload[], C> {\n huri(huri: Huri | string) {\n const huriObj = typeof huri === 'string' ? new Huri(huri) : huri\n return new ApiSimple<Payload>({\n ...this.config,\n root: `${this.root}${huriObj.href}/`,\n })\n }\n}\n","import {\n ApiConfig,\n ApiEnvelope,\n ApiError,\n ApiReportable,\n ApiResponse,\n ApiResponseBody,\n ApiResponseTuple,\n ApiResponseTupleOrBody,\n ApiResponseType,\n} from '@xyo-network/api-models'\nimport { AxiosJson } from '@xyo-network/axios'\n\nexport class ApiBase<C extends ApiConfig = ApiConfig> implements ApiReportable {\n readonly config: C\n protected axios: AxiosJson\n\n constructor(config: C) {\n this.config = config\n this.axios = new AxiosJson({ ...this.config, headers: this.headers })\n }\n\n get authenticated() {\n return !!this.config.apiKey || !!this.config.jwtToken\n }\n\n protected get headers(): Record<string, string> {\n const headers: Record<string, string> = {}\n if (this.config.jwtToken) {\n headers.Authorization = `Bearer ${this.config.jwtToken}`\n }\n if (this.config.apiKey) {\n headers['x-api-key'] = this.config.apiKey\n }\n return headers\n }\n\n protected get query() {\n return this.config.query ?? ''\n }\n\n protected get root() {\n return this.config.root ?? '/'\n }\n\n private static resolveResponse<T>(result?: ApiResponse<ApiEnvelope<T>>) {\n return [result?.data?.data, result?.data, result] as ApiResponseTuple<T>\n }\n\n private static shapeResponse<T = unknown>(response: ApiResponse<ApiEnvelope<T>> | undefined, responseType?: ApiResponseType) {\n const resolvedResponse = ApiBase.resolveResponse(response)\n return responseType === 'tuple' ? resolvedResponse : resolvedResponse[0]\n }\n\n onError(error: ApiError, depth = 0) {\n this.config.reportableParent?.onError?.(error, depth + 1)\n this.config.onError?.(error, depth)\n }\n\n onFailure(response: ApiResponse, depth = 0) {\n this.config.reportableParent?.onFailure?.(response, depth + 1)\n this.config.onFailure?.(response, depth)\n }\n\n onSuccess(response: ApiResponse, depth = 0) {\n this.config.reportableParent?.onSuccess?.(response, depth + 1)\n this.config.onSuccess?.(response, depth)\n }\n\n protected async deleteEndpoint<T = unknown>(endPoint?: string): Promise<ApiResponseBody<T>>\n protected async deleteEndpoint<T = unknown>(endPoint?: string, responseType?: 'body'): Promise<ApiResponseBody<T>>\n protected async deleteEndpoint<T = unknown>(endPoint?: string, responseType?: 'tuple'): Promise<ApiResponseTuple<T>>\n protected async deleteEndpoint<T = unknown>(endPoint = '', responseType?: ApiResponseType): Promise<ApiResponseTupleOrBody<T>> {\n const response = await this.monitorResponse<T>(async () => {\n return await this.axios.delete<ApiEnvelope<T>, ApiResponse<ApiEnvelope<T>>>(`${this.resolveRoot()}${endPoint}${this.query}`)\n })\n return ApiBase.shapeResponse<T>(response, responseType)\n }\n\n protected async getEndpoint<T = unknown>(endPoint?: string): Promise<ApiResponseBody<T>>\n protected async getEndpoint<T = unknown>(endPoint?: string, responseType?: 'body'): Promise<ApiResponseBody<T>>\n protected async getEndpoint<T = unknown>(endPoint?: string, responseType?: 'tuple'): Promise<ApiResponseTuple<T>>\n protected async getEndpoint<T = unknown>(endPoint = '', responseType?: ApiResponseType): Promise<ApiResponseTupleOrBody<T>> {\n const response = await this.monitorResponse<T>(async () => {\n return await this.axios.get<ApiEnvelope<T>, ApiResponse<ApiEnvelope<T>>>(`${this.resolveRoot()}${endPoint}${this.query}`)\n })\n return ApiBase.shapeResponse<T>(response, responseType)\n }\n\n protected handleMonitorResponseError<T>(error: ApiError, trapAxiosException: boolean) {\n if (!error.isError) {\n throw error\n }\n\n if (trapAxiosException) {\n error.response ? this.onFailure(error.response) : this.onError(error)\n if (this.config.throwFailure) {\n throw error\n }\n return error.response as ApiResponse<ApiEnvelope<T>>\n }\n }\n\n protected async monitorResponse<T>(closure: () => Promise<ApiResponse<ApiEnvelope<T>>>) {\n //we use this to prevent accidental catching on exceptions in callbacks\n let trapAxiosException = true\n try {\n const response = await closure()\n trapAxiosException = false\n\n response.status < 300 ? this.onSuccess(response) : this.onFailure(response)\n\n return response\n } catch (ex) {\n this.handleMonitorResponseError(ex as ApiError, trapAxiosException)\n }\n }\n\n protected async postEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D): Promise<ApiResponseBody<T>>\n protected async postEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D, responseType?: 'body'): Promise<ApiResponseBody<T>>\n protected async postEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D, responseType?: 'tuple'): Promise<ApiResponseTuple<T>>\n protected async postEndpoint<T = unknown, D = unknown>(\n endPoint = '',\n data?: D,\n responseType?: ApiResponseType,\n ): Promise<ApiResponseTupleOrBody<T>> {\n const response = await this.monitorResponse<T>(async () => {\n return await this.axios.post<ApiEnvelope<T>, ApiResponse<ApiEnvelope<T>, D>, D>(`${this.resolveRoot()}${endPoint}${this.query}`, data)\n })\n return ApiBase.shapeResponse<T>(response, responseType)\n }\n\n protected async putEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D): Promise<ApiResponseBody<T>>\n protected async putEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D, responseType?: 'body'): Promise<ApiResponseBody<T>>\n protected async putEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D, responseType?: 'tuple'): Promise<ApiResponseTuple<T>>\n protected async putEndpoint<T = unknown, D = unknown>(endPoint = '', data?: D, responseType?: ApiResponseType): Promise<ApiResponseTupleOrBody<T>> {\n const response = await this.monitorResponse<T>(async () => {\n return await this.axios.put<ApiEnvelope<T>, ApiResponse<ApiEnvelope<T>, D>, D>(`${this.resolveRoot()}${endPoint}${this.query}`, data)\n })\n return ApiBase.shapeResponse<T>(response, responseType)\n }\n\n private resolveRoot() {\n return `${this.config.apiDomain}${this.root}`\n }\n}\n","export const objToQuery = (obj: Record<string, string | number | undefined>) => {\n return `?${Object.entries(obj)\n .map(([key, value]) => {\n return `${key}=${value}`\n })\n .filter((value) => value !== undefined)\n .join('&')}`\n}\n","import { ApiConfig, ApiResponseBody, ApiResponseTuple, ApiResponseTupleOrBody, ApiResponseType } from '@xyo-network/api-models'\nimport { Payload, PayloadFindFilter } from '@xyo-network/payload-model'\n\nimport { ApiBase } from './Base'\nimport { objToQuery } from './objToQuery'\n\nexport type ApiSimpleQuery = PayloadFindFilter\n\nexport class ApiSimple<T = Payload, D = T, Q extends ApiSimpleQuery = ApiSimpleQuery, C extends ApiConfig = ApiConfig> extends ApiBase<C> {\n async delete(): Promise<ApiResponseBody<T>>\n async delete(responseType?: 'body'): Promise<ApiResponseBody<T>>\n async delete(responseType?: 'tuple'): Promise<ApiResponseTuple<T>>\n async delete(responseType?: ApiResponseType): Promise<ApiResponseTupleOrBody<T>> {\n switch (responseType) {\n case 'tuple':\n return await this.deleteEndpoint(undefined, 'tuple')\n default:\n return await this.deleteEndpoint(undefined)\n }\n }\n\n async find(query?: Q): Promise<ApiResponseBody<T>>\n async find(query?: Q, responseType?: 'body'): Promise<ApiResponseBody<T>>\n async find(query?: Q, responseType?: 'tuple'): Promise<ApiResponseTuple<T>>\n async find(query = {}, responseType?: ApiResponseType): Promise<ApiResponseTupleOrBody<T>> {\n switch (responseType) {\n case 'tuple':\n return await this.getEndpoint(objToQuery(query), 'tuple')\n default:\n return await this.getEndpoint(objToQuery(query))\n }\n }\n\n async get(): Promise<ApiResponseBody<T>>\n async get(responseType?: 'body'): Promise<ApiResponseBody<T>>\n async get(responseType?: 'tuple'): Promise<ApiResponseTuple<T>>\n async get(responseType?: ApiResponseType): Promise<ApiResponseTupleOrBody<T>> {\n switch (responseType) {\n case 'tuple':\n return await this.getEndpoint(undefined, 'tuple')\n default:\n return await this.getEndpoint(undefined)\n }\n }\n\n async post(data?: D): Promise<ApiResponseBody<T>>\n async post(data?: D, responseType?: 'body'): Promise<ApiResponseBody<T>>\n async post(data?: D, responseType?: 'tuple'): Promise<ApiResponseTuple<T>>\n async post(data?: D, responseType?: ApiResponseType): Promise<ApiResponseTupleOrBody<T>> {\n switch (responseType) {\n case 'tuple':\n return await this.postEndpoint(undefined, data, 'tuple')\n default:\n return await this.postEndpoint(undefined, data)\n }\n }\n\n async put(data?: D): Promise<ApiResponseBody<T>>\n async put(data?: D, responseType?: 'body'): Promise<ApiResponseBody<T>>\n async put(data?: D, responseType?: 'tuple'): Promise<ApiResponseTuple<T>>\n async put(data?: D, responseType?: ApiResponseType): Promise<ApiResponseTupleOrBody<T>> {\n switch (responseType) {\n case 'tuple':\n return await this.putEndpoint(undefined, data, 'tuple')\n default:\n return await this.putEndpoint(undefined, data)\n }\n }\n}\n"],"mappings":";AACA,SAAS,YAAY;;;ACUrB,SAAS,iBAAiB;AAEnB,IAAM,UAAN,MAAM,SAAkE;AAAA,EACpE;AAAA,EACC;AAAA,EAEV,YAAY,QAAW;AACrB,SAAK,SAAS;AACd,SAAK,QAAQ,IAAI,UAAU,EAAE,GAAG,KAAK,QAAQ,SAAS,KAAK,QAAQ,CAAC;AAAA,EACtE;AAAA,EAEA,IAAI,gBAAgB;AAClB,WAAO,CAAC,CAAC,KAAK,OAAO,UAAU,CAAC,CAAC,KAAK,OAAO;AAAA,EAC/C;AAAA,EAEA,IAAc,UAAkC;AAC9C,UAAM,UAAkC,CAAC;AACzC,QAAI,KAAK,OAAO,UAAU;AACxB,cAAQ,gBAAgB,UAAU,KAAK,OAAO,QAAQ;AAAA,IACxD;AACA,QAAI,KAAK,OAAO,QAAQ;AACtB,cAAQ,WAAW,IAAI,KAAK,OAAO;AAAA,IACrC;AACA,WAAO;AAAA,EACT;AAAA,EAEA,IAAc,QAAQ;AACpB,WAAO,KAAK,OAAO,SAAS;AAAA,EAC9B;AAAA,EAEA,IAAc,OAAO;AACnB,WAAO,KAAK,OAAO,QAAQ;AAAA,EAC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IACjD;AAAA,EACF;AACF;;;AH9DO,IAAM,eAAN,cAA4D,UAAwB;AAAA,EACzF,KAAK,MAAqB;AACxB,UAAM,UAAU,OAAO,SAAS,WAAW,IAAI,KAAK,IAAI,IAAI;AAC5D,WAAO,IAAI,UAAmB;AAAA,MAC5B,GAAG,KAAK;AAAA,MACR,MAAM,GAAG,KAAK,IAAI,GAAG,QAAQ,IAAI;AAAA,IACnC,CAAC;AAAA,EACH;AACF;","names":[]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ApiConfig, ApiEnvelope, ApiError, ApiReportable, ApiResponse, ApiResponseBody, ApiResponseTuple } from '@xyo-network/api-models';
|
|
2
|
+
import { AxiosJson } from '@xyo-network/axios';
|
|
3
|
+
export declare class ApiBase<C extends ApiConfig = ApiConfig> implements ApiReportable {
|
|
4
|
+
readonly config: C;
|
|
5
|
+
protected axios: AxiosJson;
|
|
6
|
+
constructor(config: C);
|
|
7
|
+
get authenticated(): boolean;
|
|
8
|
+
protected get headers(): Record<string, string>;
|
|
9
|
+
protected get query(): string;
|
|
10
|
+
protected get root(): string;
|
|
11
|
+
private static resolveResponse;
|
|
12
|
+
private static shapeResponse;
|
|
13
|
+
onError(error: ApiError, depth?: number): void;
|
|
14
|
+
onFailure(response: ApiResponse, depth?: number): void;
|
|
15
|
+
onSuccess(response: ApiResponse, depth?: number): void;
|
|
16
|
+
protected deleteEndpoint<T = unknown>(endPoint?: string): Promise<ApiResponseBody<T>>;
|
|
17
|
+
protected deleteEndpoint<T = unknown>(endPoint?: string, responseType?: 'body'): Promise<ApiResponseBody<T>>;
|
|
18
|
+
protected deleteEndpoint<T = unknown>(endPoint?: string, responseType?: 'tuple'): Promise<ApiResponseTuple<T>>;
|
|
19
|
+
protected getEndpoint<T = unknown>(endPoint?: string): Promise<ApiResponseBody<T>>;
|
|
20
|
+
protected getEndpoint<T = unknown>(endPoint?: string, responseType?: 'body'): Promise<ApiResponseBody<T>>;
|
|
21
|
+
protected getEndpoint<T = unknown>(endPoint?: string, responseType?: 'tuple'): Promise<ApiResponseTuple<T>>;
|
|
22
|
+
protected handleMonitorResponseError<T>(error: ApiError, trapAxiosException: boolean): ApiResponse<ApiEnvelope<T>> | undefined;
|
|
23
|
+
protected monitorResponse<T>(closure: () => Promise<ApiResponse<ApiEnvelope<T>>>): Promise<ApiResponse<ApiEnvelope<T>> | undefined>;
|
|
24
|
+
protected postEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D): Promise<ApiResponseBody<T>>;
|
|
25
|
+
protected postEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D, responseType?: 'body'): Promise<ApiResponseBody<T>>;
|
|
26
|
+
protected postEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D, responseType?: 'tuple'): Promise<ApiResponseTuple<T>>;
|
|
27
|
+
protected putEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D): Promise<ApiResponseBody<T>>;
|
|
28
|
+
protected putEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D, responseType?: 'body'): Promise<ApiResponseBody<T>>;
|
|
29
|
+
protected putEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D, responseType?: 'tuple'): Promise<ApiResponseTuple<T>>;
|
|
30
|
+
private resolveRoot;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=Base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Base.d.ts","sourceRoot":"","sources":["../../src/Base.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,WAAW,EACX,QAAQ,EACR,aAAa,EACb,WAAW,EACX,eAAe,EACf,gBAAgB,EAGjB,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAE9C,qBAAa,OAAO,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS,CAAE,YAAW,aAAa;IAC5E,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAA;IAClB,SAAS,CAAC,KAA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G,OAAO,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,EAAE,YAAY,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC;IAQxI,OAAO,CAAC,WAAW;CAGpB"}
|
package/dist/node/Base.js
CHANGED
|
@@ -16,13 +16,15 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/Base.ts
|
|
19
21
|
var Base_exports = {};
|
|
20
22
|
__export(Base_exports, {
|
|
21
23
|
ApiBase: () => ApiBase
|
|
22
24
|
});
|
|
23
25
|
module.exports = __toCommonJS(Base_exports);
|
|
24
26
|
var import_axios = require("@xyo-network/axios");
|
|
25
|
-
|
|
27
|
+
var ApiBase = class _ApiBase {
|
|
26
28
|
config;
|
|
27
29
|
axios;
|
|
28
30
|
constructor(config) {
|
|
@@ -49,35 +51,39 @@ class ApiBase {
|
|
|
49
51
|
return this.config.root ?? "/";
|
|
50
52
|
}
|
|
51
53
|
static resolveResponse(result) {
|
|
52
|
-
|
|
54
|
+
var _a;
|
|
55
|
+
return [(_a = result == null ? void 0 : result.data) == null ? void 0 : _a.data, result == null ? void 0 : result.data, result];
|
|
53
56
|
}
|
|
54
57
|
static shapeResponse(response, responseType) {
|
|
55
|
-
const resolvedResponse =
|
|
58
|
+
const resolvedResponse = _ApiBase.resolveResponse(response);
|
|
56
59
|
return responseType === "tuple" ? resolvedResponse : resolvedResponse[0];
|
|
57
60
|
}
|
|
58
61
|
onError(error, depth = 0) {
|
|
59
|
-
|
|
60
|
-
this.config.onError
|
|
62
|
+
var _a, _b, _c, _d;
|
|
63
|
+
(_b = (_a = this.config.reportableParent) == null ? void 0 : _a.onError) == null ? void 0 : _b.call(_a, error, depth + 1);
|
|
64
|
+
(_d = (_c = this.config).onError) == null ? void 0 : _d.call(_c, error, depth);
|
|
61
65
|
}
|
|
62
66
|
onFailure(response, depth = 0) {
|
|
63
|
-
|
|
64
|
-
this.config.onFailure
|
|
67
|
+
var _a, _b, _c, _d;
|
|
68
|
+
(_b = (_a = this.config.reportableParent) == null ? void 0 : _a.onFailure) == null ? void 0 : _b.call(_a, response, depth + 1);
|
|
69
|
+
(_d = (_c = this.config).onFailure) == null ? void 0 : _d.call(_c, response, depth);
|
|
65
70
|
}
|
|
66
71
|
onSuccess(response, depth = 0) {
|
|
67
|
-
|
|
68
|
-
this.config.onSuccess
|
|
72
|
+
var _a, _b, _c, _d;
|
|
73
|
+
(_b = (_a = this.config.reportableParent) == null ? void 0 : _a.onSuccess) == null ? void 0 : _b.call(_a, response, depth + 1);
|
|
74
|
+
(_d = (_c = this.config).onSuccess) == null ? void 0 : _d.call(_c, response, depth);
|
|
69
75
|
}
|
|
70
76
|
async deleteEndpoint(endPoint = "", responseType) {
|
|
71
77
|
const response = await this.monitorResponse(async () => {
|
|
72
78
|
return await this.axios.delete(`${this.resolveRoot()}${endPoint}${this.query}`);
|
|
73
79
|
});
|
|
74
|
-
return
|
|
80
|
+
return _ApiBase.shapeResponse(response, responseType);
|
|
75
81
|
}
|
|
76
82
|
async getEndpoint(endPoint = "", responseType) {
|
|
77
83
|
const response = await this.monitorResponse(async () => {
|
|
78
84
|
return await this.axios.get(`${this.resolveRoot()}${endPoint}${this.query}`);
|
|
79
85
|
});
|
|
80
|
-
return
|
|
86
|
+
return _ApiBase.shapeResponse(response, responseType);
|
|
81
87
|
}
|
|
82
88
|
handleMonitorResponseError(error, trapAxiosException) {
|
|
83
89
|
if (!error.isError) {
|
|
@@ -106,18 +112,18 @@ class ApiBase {
|
|
|
106
112
|
const response = await this.monitorResponse(async () => {
|
|
107
113
|
return await this.axios.post(`${this.resolveRoot()}${endPoint}${this.query}`, data);
|
|
108
114
|
});
|
|
109
|
-
return
|
|
115
|
+
return _ApiBase.shapeResponse(response, responseType);
|
|
110
116
|
}
|
|
111
117
|
async putEndpoint(endPoint = "", data, responseType) {
|
|
112
118
|
const response = await this.monitorResponse(async () => {
|
|
113
119
|
return await this.axios.put(`${this.resolveRoot()}${endPoint}${this.query}`, data);
|
|
114
120
|
});
|
|
115
|
-
return
|
|
121
|
+
return _ApiBase.shapeResponse(response, responseType);
|
|
116
122
|
}
|
|
117
123
|
resolveRoot() {
|
|
118
124
|
return `${this.config.apiDomain}${this.root}`;
|
|
119
125
|
}
|
|
120
|
-
}
|
|
126
|
+
};
|
|
121
127
|
// Annotate the CommonJS export names for ESM import in node:
|
|
122
128
|
0 && (module.exports = {
|
|
123
129
|
ApiBase
|
package/dist/node/Base.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Base.ts"],"sourcesContent":["import {\n ApiConfig,\n ApiEnvelope,\n ApiError,\n ApiReportable,\n ApiResponse,\n ApiResponseBody,\n ApiResponseTuple,\n ApiResponseTupleOrBody,\n ApiResponseType,\n} from '@xyo-network/api-models'\nimport { AxiosJson } from '@xyo-network/axios'\n\nexport class ApiBase<C extends ApiConfig = ApiConfig> implements ApiReportable {\n readonly config: C\n protected axios: AxiosJson\n\n constructor(config: C) {\n this.config = config\n this.axios = new AxiosJson({ ...this.config, headers: this.headers })\n }\n\n get authenticated() {\n return !!this.config.apiKey || !!this.config.jwtToken\n }\n\n protected get headers(): Record<string, string> {\n const headers: Record<string, string> = {}\n if (this.config.jwtToken) {\n headers.Authorization = `Bearer ${this.config.jwtToken}`\n }\n if (this.config.apiKey) {\n headers['x-api-key'] = this.config.apiKey\n }\n return headers\n }\n\n protected get query() {\n return this.config.query ?? ''\n }\n\n protected get root() {\n return this.config.root ?? '/'\n }\n\n private static resolveResponse<T>(result?: ApiResponse<ApiEnvelope<T>>) {\n return [result?.data?.data, result?.data, result] as ApiResponseTuple<T>\n }\n\n private static shapeResponse<T = unknown>(response: ApiResponse<ApiEnvelope<T>> | undefined, responseType?: ApiResponseType) {\n const resolvedResponse = ApiBase.resolveResponse(response)\n return responseType === 'tuple' ? resolvedResponse : resolvedResponse[0]\n }\n\n onError(error: ApiError, depth = 0) {\n this.config.reportableParent?.onError?.(error, depth + 1)\n this.config.onError?.(error, depth)\n }\n\n onFailure(response: ApiResponse, depth = 0) {\n this.config.reportableParent?.onFailure?.(response, depth + 1)\n this.config.onFailure?.(response, depth)\n }\n\n onSuccess(response: ApiResponse, depth = 0) {\n this.config.reportableParent?.onSuccess?.(response, depth + 1)\n this.config.onSuccess?.(response, depth)\n }\n\n protected async deleteEndpoint<T = unknown>(endPoint?: string): Promise<ApiResponseBody<T>>\n protected async deleteEndpoint<T = unknown>(endPoint?: string, responseType?: 'body'): Promise<ApiResponseBody<T>>\n protected async deleteEndpoint<T = unknown>(endPoint?: string, responseType?: 'tuple'): Promise<ApiResponseTuple<T>>\n protected async deleteEndpoint<T = unknown>(endPoint = '', responseType?: ApiResponseType): Promise<ApiResponseTupleOrBody<T>> {\n const response = await this.monitorResponse<T>(async () => {\n return await this.axios.delete<ApiEnvelope<T>, ApiResponse<ApiEnvelope<T>>>(`${this.resolveRoot()}${endPoint}${this.query}`)\n })\n return ApiBase.shapeResponse<T>(response, responseType)\n }\n\n protected async getEndpoint<T = unknown>(endPoint?: string): Promise<ApiResponseBody<T>>\n protected async getEndpoint<T = unknown>(endPoint?: string, responseType?: 'body'): Promise<ApiResponseBody<T>>\n protected async getEndpoint<T = unknown>(endPoint?: string, responseType?: 'tuple'): Promise<ApiResponseTuple<T>>\n protected async getEndpoint<T = unknown>(endPoint = '', responseType?: ApiResponseType): Promise<ApiResponseTupleOrBody<T>> {\n const response = await this.monitorResponse<T>(async () => {\n return await this.axios.get<ApiEnvelope<T>, ApiResponse<ApiEnvelope<T>>>(`${this.resolveRoot()}${endPoint}${this.query}`)\n })\n return ApiBase.shapeResponse<T>(response, responseType)\n }\n\n protected handleMonitorResponseError<T>(error: ApiError, trapAxiosException: boolean) {\n if (!error.isError) {\n throw error\n }\n\n if (trapAxiosException) {\n error.response ? this.onFailure(error.response) : this.onError(error)\n if (this.config.throwFailure) {\n throw error\n }\n return error.response as ApiResponse<ApiEnvelope<T>>\n }\n }\n\n protected async monitorResponse<T>(closure: () => Promise<ApiResponse<ApiEnvelope<T>>>) {\n //we use this to prevent accidental catching on exceptions in callbacks\n let trapAxiosException = true\n try {\n const response = await closure()\n trapAxiosException = false\n\n response.status < 300 ? this.onSuccess(response) : this.onFailure(response)\n\n return response\n } catch (ex) {\n this.handleMonitorResponseError(ex as ApiError, trapAxiosException)\n }\n }\n\n protected async postEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D): Promise<ApiResponseBody<T>>\n protected async postEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D, responseType?: 'body'): Promise<ApiResponseBody<T>>\n protected async postEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D, responseType?: 'tuple'): Promise<ApiResponseTuple<T>>\n protected async postEndpoint<T = unknown, D = unknown>(\n endPoint = '',\n data?: D,\n responseType?: ApiResponseType,\n ): Promise<ApiResponseTupleOrBody<T>> {\n const response = await this.monitorResponse<T>(async () => {\n return await this.axios.post<ApiEnvelope<T>, ApiResponse<ApiEnvelope<T>, D>, D>(`${this.resolveRoot()}${endPoint}${this.query}`, data)\n })\n return ApiBase.shapeResponse<T>(response, responseType)\n }\n\n protected async putEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D): Promise<ApiResponseBody<T>>\n protected async putEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D, responseType?: 'body'): Promise<ApiResponseBody<T>>\n protected async putEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D, responseType?: 'tuple'): Promise<ApiResponseTuple<T>>\n protected async putEndpoint<T = unknown, D = unknown>(endPoint = '', data?: D, responseType?: ApiResponseType): Promise<ApiResponseTupleOrBody<T>> {\n const response = await this.monitorResponse<T>(async () => {\n return await this.axios.put<ApiEnvelope<T>, ApiResponse<ApiEnvelope<T>, D>, D>(`${this.resolveRoot()}${endPoint}${this.query}`, data)\n })\n return ApiBase.shapeResponse<T>(response, responseType)\n }\n\n private resolveRoot() {\n return `${this.config.apiDomain}${this.root}`\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/Base.ts"],"sourcesContent":["import {\n ApiConfig,\n ApiEnvelope,\n ApiError,\n ApiReportable,\n ApiResponse,\n ApiResponseBody,\n ApiResponseTuple,\n ApiResponseTupleOrBody,\n ApiResponseType,\n} from '@xyo-network/api-models'\nimport { AxiosJson } from '@xyo-network/axios'\n\nexport class ApiBase<C extends ApiConfig = ApiConfig> implements ApiReportable {\n readonly config: C\n protected axios: AxiosJson\n\n constructor(config: C) {\n this.config = config\n this.axios = new AxiosJson({ ...this.config, headers: this.headers })\n }\n\n get authenticated() {\n return !!this.config.apiKey || !!this.config.jwtToken\n }\n\n protected get headers(): Record<string, string> {\n const headers: Record<string, string> = {}\n if (this.config.jwtToken) {\n headers.Authorization = `Bearer ${this.config.jwtToken}`\n }\n if (this.config.apiKey) {\n headers['x-api-key'] = this.config.apiKey\n }\n return headers\n }\n\n protected get query() {\n return this.config.query ?? ''\n }\n\n protected get root() {\n return this.config.root ?? '/'\n }\n\n private static resolveResponse<T>(result?: ApiResponse<ApiEnvelope<T>>) {\n return [result?.data?.data, result?.data, result] as ApiResponseTuple<T>\n }\n\n private static shapeResponse<T = unknown>(response: ApiResponse<ApiEnvelope<T>> | undefined, responseType?: ApiResponseType) {\n const resolvedResponse = ApiBase.resolveResponse(response)\n return responseType === 'tuple' ? resolvedResponse : resolvedResponse[0]\n }\n\n onError(error: ApiError, depth = 0) {\n this.config.reportableParent?.onError?.(error, depth + 1)\n this.config.onError?.(error, depth)\n }\n\n onFailure(response: ApiResponse, depth = 0) {\n this.config.reportableParent?.onFailure?.(response, depth + 1)\n this.config.onFailure?.(response, depth)\n }\n\n onSuccess(response: ApiResponse, depth = 0) {\n this.config.reportableParent?.onSuccess?.(response, depth + 1)\n this.config.onSuccess?.(response, depth)\n }\n\n protected async deleteEndpoint<T = unknown>(endPoint?: string): Promise<ApiResponseBody<T>>\n protected async deleteEndpoint<T = unknown>(endPoint?: string, responseType?: 'body'): Promise<ApiResponseBody<T>>\n protected async deleteEndpoint<T = unknown>(endPoint?: string, responseType?: 'tuple'): Promise<ApiResponseTuple<T>>\n protected async deleteEndpoint<T = unknown>(endPoint = '', responseType?: ApiResponseType): Promise<ApiResponseTupleOrBody<T>> {\n const response = await this.monitorResponse<T>(async () => {\n return await this.axios.delete<ApiEnvelope<T>, ApiResponse<ApiEnvelope<T>>>(`${this.resolveRoot()}${endPoint}${this.query}`)\n })\n return ApiBase.shapeResponse<T>(response, responseType)\n }\n\n protected async getEndpoint<T = unknown>(endPoint?: string): Promise<ApiResponseBody<T>>\n protected async getEndpoint<T = unknown>(endPoint?: string, responseType?: 'body'): Promise<ApiResponseBody<T>>\n protected async getEndpoint<T = unknown>(endPoint?: string, responseType?: 'tuple'): Promise<ApiResponseTuple<T>>\n protected async getEndpoint<T = unknown>(endPoint = '', responseType?: ApiResponseType): Promise<ApiResponseTupleOrBody<T>> {\n const response = await this.monitorResponse<T>(async () => {\n return await this.axios.get<ApiEnvelope<T>, ApiResponse<ApiEnvelope<T>>>(`${this.resolveRoot()}${endPoint}${this.query}`)\n })\n return ApiBase.shapeResponse<T>(response, responseType)\n }\n\n protected handleMonitorResponseError<T>(error: ApiError, trapAxiosException: boolean) {\n if (!error.isError) {\n throw error\n }\n\n if (trapAxiosException) {\n error.response ? this.onFailure(error.response) : this.onError(error)\n if (this.config.throwFailure) {\n throw error\n }\n return error.response as ApiResponse<ApiEnvelope<T>>\n }\n }\n\n protected async monitorResponse<T>(closure: () => Promise<ApiResponse<ApiEnvelope<T>>>) {\n //we use this to prevent accidental catching on exceptions in callbacks\n let trapAxiosException = true\n try {\n const response = await closure()\n trapAxiosException = false\n\n response.status < 300 ? this.onSuccess(response) : this.onFailure(response)\n\n return response\n } catch (ex) {\n this.handleMonitorResponseError(ex as ApiError, trapAxiosException)\n }\n }\n\n protected async postEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D): Promise<ApiResponseBody<T>>\n protected async postEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D, responseType?: 'body'): Promise<ApiResponseBody<T>>\n protected async postEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D, responseType?: 'tuple'): Promise<ApiResponseTuple<T>>\n protected async postEndpoint<T = unknown, D = unknown>(\n endPoint = '',\n data?: D,\n responseType?: ApiResponseType,\n ): Promise<ApiResponseTupleOrBody<T>> {\n const response = await this.monitorResponse<T>(async () => {\n return await this.axios.post<ApiEnvelope<T>, ApiResponse<ApiEnvelope<T>, D>, D>(`${this.resolveRoot()}${endPoint}${this.query}`, data)\n })\n return ApiBase.shapeResponse<T>(response, responseType)\n }\n\n protected async putEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D): Promise<ApiResponseBody<T>>\n protected async putEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D, responseType?: 'body'): Promise<ApiResponseBody<T>>\n protected async putEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D, responseType?: 'tuple'): Promise<ApiResponseTuple<T>>\n protected async putEndpoint<T = unknown, D = unknown>(endPoint = '', data?: D, responseType?: ApiResponseType): Promise<ApiResponseTupleOrBody<T>> {\n const response = await this.monitorResponse<T>(async () => {\n return await this.axios.put<ApiEnvelope<T>, ApiResponse<ApiEnvelope<T>, D>, D>(`${this.resolveRoot()}${endPoint}${this.query}`, data)\n })\n return ApiBase.shapeResponse<T>(response, responseType)\n }\n\n private resolveRoot() {\n return `${this.config.apiDomain}${this.root}`\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,mBAA0B;AAEnB,IAAM,UAAN,MAAM,SAAkE;AAAA,EACpE;AAAA,EACC;AAAA,EAEV,YAAY,QAAW;AACrB,SAAK,SAAS;AACd,SAAK,QAAQ,IAAI,uBAAU,EAAE,GAAG,KAAK,QAA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AAM,KAAK,MAAM,KAAwD,GAAG,KAAK,YAAY,CAAC,GAAG,QAAQ,GAAG,KAAK,KAAK,IAAI,IAAI;AAAA,IACvI,CAAC;AACD,WAAO,SAAQ,cAAiB,UAAU,YAAY;AAAA,EACxD;AAAA,EAKA,MAAgB,YAAsC,WAAW,IAAI,MAAU,cAAoE;AACjJ,UAAM,WAAW,MAAM,KAAK,gBAAmB,YAAY;AACzD,aAAO,MAAM,KAAK,MAAM,IAAuD,GAAG,KAAK,YAAY,CAAC,GAAG,QAAQ,GAAG,KAAK,KAAK,IAAI,IAAI;AAAA,IACtI,CAAC;AACD,WAAO,SAAQ,cAAiB,UAAU,YAAY;AAAA,EACxD;AAAA,EAEQ,cAAc;AACpB,WAAO,GAAG,KAAK,OAAO,SAAS,GAAG,KAAK,IAAI;AAAA,EAC7C;AACF;","names":[]}
|
package/dist/node/Base.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
// src/Base.ts
|
|
1
2
|
import { AxiosJson } from "@xyo-network/axios";
|
|
2
|
-
|
|
3
|
+
var ApiBase = class _ApiBase {
|
|
3
4
|
config;
|
|
4
5
|
axios;
|
|
5
6
|
constructor(config) {
|
|
@@ -26,35 +27,39 @@ class ApiBase {
|
|
|
26
27
|
return this.config.root ?? "/";
|
|
27
28
|
}
|
|
28
29
|
static resolveResponse(result) {
|
|
29
|
-
|
|
30
|
+
var _a;
|
|
31
|
+
return [(_a = result == null ? void 0 : result.data) == null ? void 0 : _a.data, result == null ? void 0 : result.data, result];
|
|
30
32
|
}
|
|
31
33
|
static shapeResponse(response, responseType) {
|
|
32
|
-
const resolvedResponse =
|
|
34
|
+
const resolvedResponse = _ApiBase.resolveResponse(response);
|
|
33
35
|
return responseType === "tuple" ? resolvedResponse : resolvedResponse[0];
|
|
34
36
|
}
|
|
35
37
|
onError(error, depth = 0) {
|
|
36
|
-
|
|
37
|
-
this.config.onError
|
|
38
|
+
var _a, _b, _c, _d;
|
|
39
|
+
(_b = (_a = this.config.reportableParent) == null ? void 0 : _a.onError) == null ? void 0 : _b.call(_a, error, depth + 1);
|
|
40
|
+
(_d = (_c = this.config).onError) == null ? void 0 : _d.call(_c, error, depth);
|
|
38
41
|
}
|
|
39
42
|
onFailure(response, depth = 0) {
|
|
40
|
-
|
|
41
|
-
this.config.onFailure
|
|
43
|
+
var _a, _b, _c, _d;
|
|
44
|
+
(_b = (_a = this.config.reportableParent) == null ? void 0 : _a.onFailure) == null ? void 0 : _b.call(_a, response, depth + 1);
|
|
45
|
+
(_d = (_c = this.config).onFailure) == null ? void 0 : _d.call(_c, response, depth);
|
|
42
46
|
}
|
|
43
47
|
onSuccess(response, depth = 0) {
|
|
44
|
-
|
|
45
|
-
this.config.onSuccess
|
|
48
|
+
var _a, _b, _c, _d;
|
|
49
|
+
(_b = (_a = this.config.reportableParent) == null ? void 0 : _a.onSuccess) == null ? void 0 : _b.call(_a, response, depth + 1);
|
|
50
|
+
(_d = (_c = this.config).onSuccess) == null ? void 0 : _d.call(_c, response, depth);
|
|
46
51
|
}
|
|
47
52
|
async deleteEndpoint(endPoint = "", responseType) {
|
|
48
53
|
const response = await this.monitorResponse(async () => {
|
|
49
54
|
return await this.axios.delete(`${this.resolveRoot()}${endPoint}${this.query}`);
|
|
50
55
|
});
|
|
51
|
-
return
|
|
56
|
+
return _ApiBase.shapeResponse(response, responseType);
|
|
52
57
|
}
|
|
53
58
|
async getEndpoint(endPoint = "", responseType) {
|
|
54
59
|
const response = await this.monitorResponse(async () => {
|
|
55
60
|
return await this.axios.get(`${this.resolveRoot()}${endPoint}${this.query}`);
|
|
56
61
|
});
|
|
57
|
-
return
|
|
62
|
+
return _ApiBase.shapeResponse(response, responseType);
|
|
58
63
|
}
|
|
59
64
|
handleMonitorResponseError(error, trapAxiosException) {
|
|
60
65
|
if (!error.isError) {
|
|
@@ -83,18 +88,18 @@ class ApiBase {
|
|
|
83
88
|
const response = await this.monitorResponse(async () => {
|
|
84
89
|
return await this.axios.post(`${this.resolveRoot()}${endPoint}${this.query}`, data);
|
|
85
90
|
});
|
|
86
|
-
return
|
|
91
|
+
return _ApiBase.shapeResponse(response, responseType);
|
|
87
92
|
}
|
|
88
93
|
async putEndpoint(endPoint = "", data, responseType) {
|
|
89
94
|
const response = await this.monitorResponse(async () => {
|
|
90
95
|
return await this.axios.put(`${this.resolveRoot()}${endPoint}${this.query}`, data);
|
|
91
96
|
});
|
|
92
|
-
return
|
|
97
|
+
return _ApiBase.shapeResponse(response, responseType);
|
|
93
98
|
}
|
|
94
99
|
resolveRoot() {
|
|
95
100
|
return `${this.config.apiDomain}${this.root}`;
|
|
96
101
|
}
|
|
97
|
-
}
|
|
102
|
+
};
|
|
98
103
|
export {
|
|
99
104
|
ApiBase
|
|
100
105
|
};
|
package/dist/node/Base.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Base.ts"],"sourcesContent":["import {\n ApiConfig,\n ApiEnvelope,\n ApiError,\n ApiReportable,\n ApiResponse,\n ApiResponseBody,\n ApiResponseTuple,\n ApiResponseTupleOrBody,\n ApiResponseType,\n} from '@xyo-network/api-models'\nimport { AxiosJson } from '@xyo-network/axios'\n\nexport class ApiBase<C extends ApiConfig = ApiConfig> implements ApiReportable {\n readonly config: C\n protected axios: AxiosJson\n\n constructor(config: C) {\n this.config = config\n this.axios = new AxiosJson({ ...this.config, headers: this.headers })\n }\n\n get authenticated() {\n return !!this.config.apiKey || !!this.config.jwtToken\n }\n\n protected get headers(): Record<string, string> {\n const headers: Record<string, string> = {}\n if (this.config.jwtToken) {\n headers.Authorization = `Bearer ${this.config.jwtToken}`\n }\n if (this.config.apiKey) {\n headers['x-api-key'] = this.config.apiKey\n }\n return headers\n }\n\n protected get query() {\n return this.config.query ?? ''\n }\n\n protected get root() {\n return this.config.root ?? '/'\n }\n\n private static resolveResponse<T>(result?: ApiResponse<ApiEnvelope<T>>) {\n return [result?.data?.data, result?.data, result] as ApiResponseTuple<T>\n }\n\n private static shapeResponse<T = unknown>(response: ApiResponse<ApiEnvelope<T>> | undefined, responseType?: ApiResponseType) {\n const resolvedResponse = ApiBase.resolveResponse(response)\n return responseType === 'tuple' ? resolvedResponse : resolvedResponse[0]\n }\n\n onError(error: ApiError, depth = 0) {\n this.config.reportableParent?.onError?.(error, depth + 1)\n this.config.onError?.(error, depth)\n }\n\n onFailure(response: ApiResponse, depth = 0) {\n this.config.reportableParent?.onFailure?.(response, depth + 1)\n this.config.onFailure?.(response, depth)\n }\n\n onSuccess(response: ApiResponse, depth = 0) {\n this.config.reportableParent?.onSuccess?.(response, depth + 1)\n this.config.onSuccess?.(response, depth)\n }\n\n protected async deleteEndpoint<T = unknown>(endPoint?: string): Promise<ApiResponseBody<T>>\n protected async deleteEndpoint<T = unknown>(endPoint?: string, responseType?: 'body'): Promise<ApiResponseBody<T>>\n protected async deleteEndpoint<T = unknown>(endPoint?: string, responseType?: 'tuple'): Promise<ApiResponseTuple<T>>\n protected async deleteEndpoint<T = unknown>(endPoint = '', responseType?: ApiResponseType): Promise<ApiResponseTupleOrBody<T>> {\n const response = await this.monitorResponse<T>(async () => {\n return await this.axios.delete<ApiEnvelope<T>, ApiResponse<ApiEnvelope<T>>>(`${this.resolveRoot()}${endPoint}${this.query}`)\n })\n return ApiBase.shapeResponse<T>(response, responseType)\n }\n\n protected async getEndpoint<T = unknown>(endPoint?: string): Promise<ApiResponseBody<T>>\n protected async getEndpoint<T = unknown>(endPoint?: string, responseType?: 'body'): Promise<ApiResponseBody<T>>\n protected async getEndpoint<T = unknown>(endPoint?: string, responseType?: 'tuple'): Promise<ApiResponseTuple<T>>\n protected async getEndpoint<T = unknown>(endPoint = '', responseType?: ApiResponseType): Promise<ApiResponseTupleOrBody<T>> {\n const response = await this.monitorResponse<T>(async () => {\n return await this.axios.get<ApiEnvelope<T>, ApiResponse<ApiEnvelope<T>>>(`${this.resolveRoot()}${endPoint}${this.query}`)\n })\n return ApiBase.shapeResponse<T>(response, responseType)\n }\n\n protected handleMonitorResponseError<T>(error: ApiError, trapAxiosException: boolean) {\n if (!error.isError) {\n throw error\n }\n\n if (trapAxiosException) {\n error.response ? this.onFailure(error.response) : this.onError(error)\n if (this.config.throwFailure) {\n throw error\n }\n return error.response as ApiResponse<ApiEnvelope<T>>\n }\n }\n\n protected async monitorResponse<T>(closure: () => Promise<ApiResponse<ApiEnvelope<T>>>) {\n //we use this to prevent accidental catching on exceptions in callbacks\n let trapAxiosException = true\n try {\n const response = await closure()\n trapAxiosException = false\n\n response.status < 300 ? this.onSuccess(response) : this.onFailure(response)\n\n return response\n } catch (ex) {\n this.handleMonitorResponseError(ex as ApiError, trapAxiosException)\n }\n }\n\n protected async postEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D): Promise<ApiResponseBody<T>>\n protected async postEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D, responseType?: 'body'): Promise<ApiResponseBody<T>>\n protected async postEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D, responseType?: 'tuple'): Promise<ApiResponseTuple<T>>\n protected async postEndpoint<T = unknown, D = unknown>(\n endPoint = '',\n data?: D,\n responseType?: ApiResponseType,\n ): Promise<ApiResponseTupleOrBody<T>> {\n const response = await this.monitorResponse<T>(async () => {\n return await this.axios.post<ApiEnvelope<T>, ApiResponse<ApiEnvelope<T>, D>, D>(`${this.resolveRoot()}${endPoint}${this.query}`, data)\n })\n return ApiBase.shapeResponse<T>(response, responseType)\n }\n\n protected async putEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D): Promise<ApiResponseBody<T>>\n protected async putEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D, responseType?: 'body'): Promise<ApiResponseBody<T>>\n protected async putEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D, responseType?: 'tuple'): Promise<ApiResponseTuple<T>>\n protected async putEndpoint<T = unknown, D = unknown>(endPoint = '', data?: D, responseType?: ApiResponseType): Promise<ApiResponseTupleOrBody<T>> {\n const response = await this.monitorResponse<T>(async () => {\n return await this.axios.put<ApiEnvelope<T>, ApiResponse<ApiEnvelope<T>, D>, D>(`${this.resolveRoot()}${endPoint}${this.query}`, data)\n })\n return ApiBase.shapeResponse<T>(response, responseType)\n }\n\n private resolveRoot() {\n return `${this.config.apiDomain}${this.root}`\n }\n}\n"],"mappings":"AAWA,SAAS,iBAAiB;AAEnB,MAAM,
|
|
1
|
+
{"version":3,"sources":["../../src/Base.ts"],"sourcesContent":["import {\n ApiConfig,\n ApiEnvelope,\n ApiError,\n ApiReportable,\n ApiResponse,\n ApiResponseBody,\n ApiResponseTuple,\n ApiResponseTupleOrBody,\n ApiResponseType,\n} from '@xyo-network/api-models'\nimport { AxiosJson } from '@xyo-network/axios'\n\nexport class ApiBase<C extends ApiConfig = ApiConfig> implements ApiReportable {\n readonly config: C\n protected axios: AxiosJson\n\n constructor(config: C) {\n this.config = config\n this.axios = new AxiosJson({ ...this.config, headers: this.headers })\n }\n\n get authenticated() {\n return !!this.config.apiKey || !!this.config.jwtToken\n }\n\n protected get headers(): Record<string, string> {\n const headers: Record<string, string> = {}\n if (this.config.jwtToken) {\n headers.Authorization = `Bearer ${this.config.jwtToken}`\n }\n if (this.config.apiKey) {\n headers['x-api-key'] = this.config.apiKey\n }\n return headers\n }\n\n protected get query() {\n return this.config.query ?? ''\n }\n\n protected get root() {\n return this.config.root ?? '/'\n }\n\n private static resolveResponse<T>(result?: ApiResponse<ApiEnvelope<T>>) {\n return [result?.data?.data, result?.data, result] as ApiResponseTuple<T>\n }\n\n private static shapeResponse<T = unknown>(response: ApiResponse<ApiEnvelope<T>> | undefined, responseType?: ApiResponseType) {\n const resolvedResponse = ApiBase.resolveResponse(response)\n return responseType === 'tuple' ? resolvedResponse : resolvedResponse[0]\n }\n\n onError(error: ApiError, depth = 0) {\n this.config.reportableParent?.onError?.(error, depth + 1)\n this.config.onError?.(error, depth)\n }\n\n onFailure(response: ApiResponse, depth = 0) {\n this.config.reportableParent?.onFailure?.(response, depth + 1)\n this.config.onFailure?.(response, depth)\n }\n\n onSuccess(response: ApiResponse, depth = 0) {\n this.config.reportableParent?.onSuccess?.(response, depth + 1)\n this.config.onSuccess?.(response, depth)\n }\n\n protected async deleteEndpoint<T = unknown>(endPoint?: string): Promise<ApiResponseBody<T>>\n protected async deleteEndpoint<T = unknown>(endPoint?: string, responseType?: 'body'): Promise<ApiResponseBody<T>>\n protected async deleteEndpoint<T = unknown>(endPoint?: string, responseType?: 'tuple'): Promise<ApiResponseTuple<T>>\n protected async deleteEndpoint<T = unknown>(endPoint = '', responseType?: ApiResponseType): Promise<ApiResponseTupleOrBody<T>> {\n const response = await this.monitorResponse<T>(async () => {\n return await this.axios.delete<ApiEnvelope<T>, ApiResponse<ApiEnvelope<T>>>(`${this.resolveRoot()}${endPoint}${this.query}`)\n })\n return ApiBase.shapeResponse<T>(response, responseType)\n }\n\n protected async getEndpoint<T = unknown>(endPoint?: string): Promise<ApiResponseBody<T>>\n protected async getEndpoint<T = unknown>(endPoint?: string, responseType?: 'body'): Promise<ApiResponseBody<T>>\n protected async getEndpoint<T = unknown>(endPoint?: string, responseType?: 'tuple'): Promise<ApiResponseTuple<T>>\n protected async getEndpoint<T = unknown>(endPoint = '', responseType?: ApiResponseType): Promise<ApiResponseTupleOrBody<T>> {\n const response = await this.monitorResponse<T>(async () => {\n return await this.axios.get<ApiEnvelope<T>, ApiResponse<ApiEnvelope<T>>>(`${this.resolveRoot()}${endPoint}${this.query}`)\n })\n return ApiBase.shapeResponse<T>(response, responseType)\n }\n\n protected handleMonitorResponseError<T>(error: ApiError, trapAxiosException: boolean) {\n if (!error.isError) {\n throw error\n }\n\n if (trapAxiosException) {\n error.response ? this.onFailure(error.response) : this.onError(error)\n if (this.config.throwFailure) {\n throw error\n }\n return error.response as ApiResponse<ApiEnvelope<T>>\n }\n }\n\n protected async monitorResponse<T>(closure: () => Promise<ApiResponse<ApiEnvelope<T>>>) {\n //we use this to prevent accidental catching on exceptions in callbacks\n let trapAxiosException = true\n try {\n const response = await closure()\n trapAxiosException = false\n\n response.status < 300 ? this.onSuccess(response) : this.onFailure(response)\n\n return response\n } catch (ex) {\n this.handleMonitorResponseError(ex as ApiError, trapAxiosException)\n }\n }\n\n protected async postEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D): Promise<ApiResponseBody<T>>\n protected async postEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D, responseType?: 'body'): Promise<ApiResponseBody<T>>\n protected async postEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D, responseType?: 'tuple'): Promise<ApiResponseTuple<T>>\n protected async postEndpoint<T = unknown, D = unknown>(\n endPoint = '',\n data?: D,\n responseType?: ApiResponseType,\n ): Promise<ApiResponseTupleOrBody<T>> {\n const response = await this.monitorResponse<T>(async () => {\n return await this.axios.post<ApiEnvelope<T>, ApiResponse<ApiEnvelope<T>, D>, D>(`${this.resolveRoot()}${endPoint}${this.query}`, data)\n })\n return ApiBase.shapeResponse<T>(response, responseType)\n }\n\n protected async putEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D): Promise<ApiResponseBody<T>>\n protected async putEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D, responseType?: 'body'): Promise<ApiResponseBody<T>>\n protected async putEndpoint<T = unknown, D = unknown>(endPoint?: string, data?: D, responseType?: 'tuple'): Promise<ApiResponseTuple<T>>\n protected async putEndpoint<T = unknown, D = unknown>(endPoint = '', data?: D, responseType?: ApiResponseType): Promise<ApiResponseTupleOrBody<T>> {\n const response = await this.monitorResponse<T>(async () => {\n return await this.axios.put<ApiEnvelope<T>, ApiResponse<ApiEnvelope<T>, D>, D>(`${this.resolveRoot()}${endPoint}${this.query}`, data)\n })\n return ApiBase.shapeResponse<T>(response, responseType)\n }\n\n private resolveRoot() {\n return `${this.config.apiDomain}${this.root}`\n }\n}\n"],"mappings":";AAWA,SAAS,iBAAiB;AAEnB,IAAM,UAAN,MAAM,SAAkE;AAAA,EACpE;AAAA,EACC;AAAA,EAEV,YAAY,QAAW;AACrB,SAAK,SAAS;AACd,SAA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AW,MAAM,KAAK,gBAAmB,YAAY;AACzD,aAAO,MAAM,KAAK,MAAM,KAAwD,GAAG,KAAK,YAAY,CAAC,GAAG,QAAQ,GAAG,KAAK,KAAK,IAAI,IAAI;AAAA,IACvI,CAAC;AACD,WAAO,SAAQ,cAAiB,UAAU,YAAY;AAAA,EACxD;AAAA,EAKA,MAAgB,YAAsC,WAAW,IAAI,MAAU,cAAoE;AACjJ,UAAM,WAAW,MAAM,KAAK,gBAAmB,YAAY;AACzD,aAAO,MAAM,KAAK,MAAM,IAAuD,GAAG,KAAK,YAAY,CAAC,GAAG,QAAQ,GAAG,KAAK,KAAK,IAAI,IAAI;AAAA,IACtI,CAAC;AACD,WAAO,SAAQ,cAAiB,UAAU,YAAY;AAAA,EACxD;AAAA,EAEQ,cAAc;AACpB,WAAO,GAAG,KAAK,OAAO,SAAS,GAAG,KAAK,IAAI;AAAA,EAC7C;AACF;","names":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ApiConfig } from '@xyo-network/api-models';
|
|
2
|
+
import { GetLocationQueryResponse } from './models';
|
|
3
|
+
import { LocationQueryCreationResponse, SupportedLocationQueryCreationRequest } from './Queries';
|
|
4
|
+
declare class LocationDivinerApi {
|
|
5
|
+
config: ApiConfig;
|
|
6
|
+
constructor(config: ApiConfig);
|
|
7
|
+
private get axiosRequestConfig();
|
|
8
|
+
getLocationQuery(hash: string): Promise<GetLocationQueryResponse>;
|
|
9
|
+
postLocationQuery(request: SupportedLocationQueryCreationRequest): Promise<LocationQueryCreationResponse>;
|
|
10
|
+
}
|
|
11
|
+
export { LocationDivinerApi };
|
|
12
|
+
//# sourceMappingURL=LocationDivinerApi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LocationDivinerApi.d.ts","sourceRoot":"","sources":["../../../../src/Diviner/LocationDiviner/LocationDivinerApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAInD,OAAO,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAA;AACnD,OAAO,EAAE,6BAA6B,EAAE,qCAAqC,EAAE,MAAM,WAAW,CAAA;AAEhG,cAAM,kBAAkB;IACtB,MAAM,EAAE,SAAS,CAAA;gBACL,MAAM,EAAE,SAAS;IAI7B,OAAO,KAAK,kBAAkB,GAI7B;IAEK,gBAAgB,CAAC,IAAI,EAAE,MAAM;IAI7B,iBAAiB,CAAC,OAAO,EAAE,qCAAqC;CAGvE;AAED,OAAO,EAAE,kBAAkB,EAAE,CAAA"}
|
|
@@ -16,30 +16,42 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/Diviner/LocationDiviner/LocationDivinerApi.ts
|
|
19
21
|
var LocationDivinerApi_exports = {};
|
|
20
22
|
__export(LocationDivinerApi_exports, {
|
|
21
23
|
LocationDivinerApi: () => LocationDivinerApi
|
|
22
24
|
});
|
|
23
25
|
module.exports = __toCommonJS(LocationDivinerApi_exports);
|
|
26
|
+
var import_axios2 = require("@xyo-network/axios");
|
|
27
|
+
|
|
28
|
+
// src/Diviner/LocationDiviner/LocationDivinerApiResponseTransformer.ts
|
|
24
29
|
var import_axios = require("@xyo-network/axios");
|
|
25
|
-
var
|
|
26
|
-
|
|
30
|
+
var locationDivinerApiResponseTransformer = (data, _headers) => {
|
|
31
|
+
return data.data;
|
|
32
|
+
};
|
|
33
|
+
var getLocationDivinerApiResponseTransformer = (axiosInstance = import_axios.axios) => {
|
|
34
|
+
return axiosInstance.defaults.transformResponse ? [].concat(axiosInstance.defaults.transformResponse, locationDivinerApiResponseTransformer) : [locationDivinerApiResponseTransformer];
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// src/Diviner/LocationDiviner/LocationDivinerApi.ts
|
|
38
|
+
var LocationDivinerApi = class {
|
|
27
39
|
config;
|
|
28
40
|
constructor(config) {
|
|
29
41
|
this.config = config;
|
|
30
42
|
}
|
|
31
43
|
get axiosRequestConfig() {
|
|
32
44
|
return {
|
|
33
|
-
transformResponse:
|
|
45
|
+
transformResponse: getLocationDivinerApiResponseTransformer()
|
|
34
46
|
};
|
|
35
47
|
}
|
|
36
48
|
async getLocationQuery(hash) {
|
|
37
|
-
return (await
|
|
49
|
+
return (await import_axios2.axios.get(`${this.config.apiDomain}/location/query/${hash}`, this.axiosRequestConfig)).data;
|
|
38
50
|
}
|
|
39
51
|
async postLocationQuery(request) {
|
|
40
|
-
return (await
|
|
52
|
+
return (await import_axios2.axios.post(`${this.config.apiDomain}/location/query`, { ...request }, this.axiosRequestConfig)).data;
|
|
41
53
|
}
|
|
42
|
-
}
|
|
54
|
+
};
|
|
43
55
|
// Annotate the CommonJS export names for ESM import in node:
|
|
44
56
|
0 && (module.exports = {
|
|
45
57
|
LocationDivinerApi
|