celitech-sdk 1.1.84 → 1.1.86
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +4 -18
- package/dist/index.d.ts +1503 -12
- package/dist/index.js +2140 -76
- package/dist/index.mjs +2102 -0
- package/package.json +22 -5
- package/.devcontainer/devcontainer.json +0 -24
- package/.github/workflows/publish_npmjs.yml +0 -32
- package/.manifest.json +0 -256
- package/dist/http/client.d.ts +0 -14
- package/dist/http/client.d.ts.map +0 -1
- package/dist/http/client.js +0 -36
- package/dist/http/client.js.map +0 -1
- package/dist/http/environment.d.ts +0 -4
- package/dist/http/environment.d.ts.map +0 -1
- package/dist/http/environment.js +0 -8
- package/dist/http/environment.js.map +0 -1
- package/dist/http/error.d.ts +0 -7
- package/dist/http/error.d.ts.map +0 -1
- package/dist/http/error.js +0 -12
- package/dist/http/error.js.map +0 -1
- package/dist/http/handlers/handler-chain.d.ts +0 -8
- package/dist/http/handlers/handler-chain.d.ts.map +0 -1
- package/dist/http/handlers/handler-chain.js +0 -34
- package/dist/http/handlers/handler-chain.js.map +0 -1
- package/dist/http/handlers/hook-handler.d.ts +0 -12
- package/dist/http/handlers/hook-handler.d.ts.map +0 -1
- package/dist/http/handlers/hook-handler.js +0 -49
- package/dist/http/handlers/hook-handler.js.map +0 -1
- package/dist/http/handlers/request-validation-handler.d.ts +0 -9
- package/dist/http/handlers/request-validation-handler.d.ts.map +0 -1
- package/dist/http/handlers/request-validation-handler.js +0 -78
- package/dist/http/handlers/request-validation-handler.js.map +0 -1
- package/dist/http/handlers/response-validation-handler.d.ts +0 -11
- package/dist/http/handlers/response-validation-handler.d.ts.map +0 -1
- package/dist/http/handlers/response-validation-handler.js +0 -89
- package/dist/http/handlers/response-validation-handler.js.map +0 -1
- package/dist/http/handlers/retry-handler.d.ts +0 -9
- package/dist/http/handlers/retry-handler.d.ts.map +0 -1
- package/dist/http/handlers/retry-handler.js +0 -47
- package/dist/http/handlers/retry-handler.js.map +0 -1
- package/dist/http/handlers/terminating-handler.d.ts +0 -8
- package/dist/http/handlers/terminating-handler.d.ts.map +0 -1
- package/dist/http/handlers/terminating-handler.js +0 -45
- package/dist/http/handlers/terminating-handler.js.map +0 -1
- package/dist/http/hooks/custom-hook.d.ts +0 -9
- package/dist/http/hooks/custom-hook.d.ts.map +0 -1
- package/dist/http/hooks/custom-hook.js +0 -89
- package/dist/http/hooks/custom-hook.js.map +0 -1
- package/dist/http/hooks/hook.d.ts +0 -31
- package/dist/http/hooks/hook.d.ts.map +0 -1
- package/dist/http/hooks/hook.js +0 -3
- package/dist/http/hooks/hook.js.map +0 -1
- package/dist/http/serializer.d.ts +0 -13
- package/dist/http/serializer.d.ts.map +0 -1
- package/dist/http/serializer.js +0 -150
- package/dist/http/serializer.js.map +0 -1
- package/dist/http/transport/request-builder.d.ts +0 -24
- package/dist/http/transport/request-builder.d.ts.map +0 -1
- package/dist/http/transport/request-builder.js +0 -130
- package/dist/http/transport/request-builder.js.map +0 -1
- package/dist/http/transport/request.d.ts +0 -53
- package/dist/http/transport/request.d.ts.map +0 -1
- package/dist/http/transport/request.js +0 -116
- package/dist/http/transport/request.js.map +0 -1
- package/dist/http/types.d.ts +0 -60
- package/dist/http/types.d.ts.map +0 -1
- package/dist/http/types.js +0 -16
- package/dist/http/types.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/services/base-service.d.ts +0 -14
- package/dist/services/base-service.d.ts.map +0 -1
- package/dist/services/base-service.js +0 -27
- package/dist/services/base-service.js.map +0 -1
- package/dist/services/destinations/destinations.d.ts +0 -11
- package/dist/services/destinations/destinations.d.ts.map +0 -1
- package/dist/services/destinations/destinations.js +0 -43
- package/dist/services/destinations/destinations.js.map +0 -1
- package/dist/services/destinations/index.d.ts +0 -2
- package/dist/services/destinations/index.d.ts.map +0 -1
- package/dist/services/destinations/index.js +0 -6
- package/dist/services/destinations/index.js.map +0 -1
- package/dist/services/destinations/models/destinations.d.ts +0 -76
- package/dist/services/destinations/models/destinations.d.ts.map +0 -1
- package/dist/services/destinations/models/destinations.js +0 -49
- package/dist/services/destinations/models/destinations.js.map +0 -1
- package/dist/services/destinations/models/index.d.ts +0 -3
- package/dist/services/destinations/models/index.d.ts.map +0 -1
- package/dist/services/destinations/models/index.js +0 -3
- package/dist/services/destinations/models/index.js.map +0 -1
- package/dist/services/destinations/models/list-destinations-ok-response.d.ts +0 -140
- package/dist/services/destinations/models/list-destinations-ok-response.d.ts.map +0 -1
- package/dist/services/destinations/models/list-destinations-ok-response.js +0 -36
- package/dist/services/destinations/models/list-destinations-ok-response.js.map +0 -1
- package/dist/services/e-sim/e-sim.d.ts +0 -34
- package/dist/services/e-sim/e-sim.d.ts.map +0 -1
- package/dist/services/e-sim/e-sim.js +0 -120
- package/dist/services/e-sim/e-sim.js.map +0 -1
- package/dist/services/e-sim/index.d.ts +0 -2
- package/dist/services/e-sim/index.d.ts.map +0 -1
- package/dist/services/e-sim/index.js +0 -6
- package/dist/services/e-sim/index.js.map +0 -1
- package/dist/services/e-sim/models/device.d.ts +0 -90
- package/dist/services/e-sim/models/device.d.ts.map +0 -1
- package/dist/services/e-sim/models/device.js +0 -54
- package/dist/services/e-sim/models/device.js.map +0 -1
- package/dist/services/e-sim/models/get-esim-device-ok-response.d.ts +0 -163
- package/dist/services/e-sim/models/get-esim-device-ok-response.d.ts.map +0 -1
- package/dist/services/e-sim/models/get-esim-device-ok-response.js +0 -36
- package/dist/services/e-sim/models/get-esim-device-ok-response.js.map +0 -1
- package/dist/services/e-sim/models/get-esim-history-ok-response-esim.d.ts +0 -154
- package/dist/services/e-sim/models/get-esim-history-ok-response-esim.d.ts.map +0 -1
- package/dist/services/e-sim/models/get-esim-history-ok-response-esim.js +0 -40
- package/dist/services/e-sim/models/get-esim-history-ok-response-esim.js.map +0 -1
- package/dist/services/e-sim/models/get-esim-history-ok-response.d.ts +0 -249
- package/dist/services/e-sim/models/get-esim-history-ok-response.d.ts.map +0 -1
- package/dist/services/e-sim/models/get-esim-history-ok-response.js +0 -36
- package/dist/services/e-sim/models/get-esim-history-ok-response.js.map +0 -1
- package/dist/services/e-sim/models/get-esim-mac-ok-response-esim.d.ts +0 -76
- package/dist/services/e-sim/models/get-esim-mac-ok-response-esim.d.ts.map +0 -1
- package/dist/services/e-sim/models/get-esim-mac-ok-response-esim.js +0 -49
- package/dist/services/e-sim/models/get-esim-mac-ok-response-esim.js.map +0 -1
- package/dist/services/e-sim/models/get-esim-mac-ok-response.d.ts +0 -140
- package/dist/services/e-sim/models/get-esim-mac-ok-response.d.ts.map +0 -1
- package/dist/services/e-sim/models/get-esim-mac-ok-response.js +0 -36
- package/dist/services/e-sim/models/get-esim-mac-ok-response.js.map +0 -1
- package/dist/services/e-sim/models/get-esim-ok-response-esim.d.ts +0 -90
- package/dist/services/e-sim/models/get-esim-ok-response-esim.d.ts.map +0 -1
- package/dist/services/e-sim/models/get-esim-ok-response-esim.js +0 -54
- package/dist/services/e-sim/models/get-esim-ok-response-esim.js.map +0 -1
- package/dist/services/e-sim/models/get-esim-ok-response.d.ts +0 -163
- package/dist/services/e-sim/models/get-esim-ok-response.d.ts.map +0 -1
- package/dist/services/e-sim/models/get-esim-ok-response.js +0 -36
- package/dist/services/e-sim/models/get-esim-ok-response.js.map +0 -1
- package/dist/services/e-sim/models/history.d.ts +0 -76
- package/dist/services/e-sim/models/history.d.ts.map +0 -1
- package/dist/services/e-sim/models/history.js +0 -45
- package/dist/services/e-sim/models/history.js.map +0 -1
- package/dist/services/e-sim/models/index.d.ts +0 -10
- package/dist/services/e-sim/models/index.d.ts.map +0 -1
- package/dist/services/e-sim/models/index.js +0 -3
- package/dist/services/e-sim/models/index.js.map +0 -1
- package/dist/services/e-sim/request-params.d.ts +0 -4
- package/dist/services/e-sim/request-params.d.ts.map +0 -1
- package/dist/services/e-sim/request-params.js +0 -3
- package/dist/services/e-sim/request-params.js.map +0 -1
- package/dist/services/packages/index.d.ts +0 -2
- package/dist/services/packages/index.d.ts.map +0 -1
- package/dist/services/packages/index.js +0 -6
- package/dist/services/packages/index.js.map +0 -1
- package/dist/services/packages/models/index.d.ts +0 -3
- package/dist/services/packages/models/index.d.ts.map +0 -1
- package/dist/services/packages/models/index.js +0 -3
- package/dist/services/packages/models/index.js.map +0 -1
- package/dist/services/packages/models/list-packages-ok-response.d.ts +0 -223
- package/dist/services/packages/models/list-packages-ok-response.d.ts.map +0 -1
- package/dist/services/packages/models/list-packages-ok-response.js +0 -42
- package/dist/services/packages/models/list-packages-ok-response.js.map +0 -1
- package/dist/services/packages/models/packages.d.ts +0 -118
- package/dist/services/packages/models/packages.d.ts.map +0 -1
- package/dist/services/packages/models/packages.js +0 -64
- package/dist/services/packages/models/packages.js.map +0 -1
- package/dist/services/packages/packages.d.ts +0 -20
- package/dist/services/packages/packages.d.ts.map +0 -1
- package/dist/services/packages/packages.js +0 -59
- package/dist/services/packages/packages.js.map +0 -1
- package/dist/services/packages/request-params.d.ts +0 -11
- package/dist/services/packages/request-params.d.ts.map +0 -1
- package/dist/services/packages/request-params.js +0 -3
- package/dist/services/packages/request-params.js.map +0 -1
- package/dist/services/purchases/index.d.ts +0 -2
- package/dist/services/purchases/index.d.ts.map +0 -1
- package/dist/services/purchases/index.js +0 -6
- package/dist/services/purchases/index.js.map +0 -1
- package/dist/services/purchases/models/create-purchase-ok-response-profile.d.ts +0 -62
- package/dist/services/purchases/models/create-purchase-ok-response-profile.d.ts.map +0 -1
- package/dist/services/purchases/models/create-purchase-ok-response-profile.js +0 -39
- package/dist/services/purchases/models/create-purchase-ok-response-profile.js.map +0 -1
- package/dist/services/purchases/models/create-purchase-ok-response-purchase.d.ts +0 -132
- package/dist/services/purchases/models/create-purchase-ok-response-purchase.d.ts.map +0 -1
- package/dist/services/purchases/models/create-purchase-ok-response-purchase.js +0 -69
- package/dist/services/purchases/models/create-purchase-ok-response-purchase.js.map +0 -1
- package/dist/services/purchases/models/create-purchase-ok-response.d.ts +0 -315
- package/dist/services/purchases/models/create-purchase-ok-response.d.ts.map +0 -1
- package/dist/services/purchases/models/create-purchase-ok-response.js +0 -46
- package/dist/services/purchases/models/create-purchase-ok-response.js.map +0 -1
- package/dist/services/purchases/models/create-purchase-request.d.ts +0 -160
- package/dist/services/purchases/models/create-purchase-request.d.ts.map +0 -1
- package/dist/services/purchases/models/create-purchase-request.js +0 -79
- package/dist/services/purchases/models/create-purchase-request.js.map +0 -1
- package/dist/services/purchases/models/edit-purchase-ok-response.d.ts +0 -104
- package/dist/services/purchases/models/edit-purchase-ok-response.d.ts.map +0 -1
- package/dist/services/purchases/models/edit-purchase-ok-response.js +0 -59
- package/dist/services/purchases/models/edit-purchase-ok-response.js.map +0 -1
- package/dist/services/purchases/models/edit-purchase-request.d.ts +0 -104
- package/dist/services/purchases/models/edit-purchase-request.d.ts.map +0 -1
- package/dist/services/purchases/models/edit-purchase-request.js +0 -59
- package/dist/services/purchases/models/edit-purchase-request.js.map +0 -1
- package/dist/services/purchases/models/get-purchase-consumption-ok-response.d.ts +0 -62
- package/dist/services/purchases/models/get-purchase-consumption-ok-response.d.ts.map +0 -1
- package/dist/services/purchases/models/get-purchase-consumption-ok-response.js +0 -41
- package/dist/services/purchases/models/get-purchase-consumption-ok-response.js.map +0 -1
- package/dist/services/purchases/models/index.d.ts +0 -16
- package/dist/services/purchases/models/index.d.ts.map +0 -1
- package/dist/services/purchases/models/index.js +0 -3
- package/dist/services/purchases/models/index.js.map +0 -1
- package/dist/services/purchases/models/list-purchases-ok-response.d.ts +0 -622
- package/dist/services/purchases/models/list-purchases-ok-response.d.ts.map +0 -1
- package/dist/services/purchases/models/list-purchases-ok-response.js +0 -42
- package/dist/services/purchases/models/list-purchases-ok-response.js.map +0 -1
- package/dist/services/purchases/models/package_.d.ts +0 -104
- package/dist/services/purchases/models/package_.d.ts.map +0 -1
- package/dist/services/purchases/models/package_.js +0 -59
- package/dist/services/purchases/models/package_.js.map +0 -1
- package/dist/services/purchases/models/purchases-esim.d.ts +0 -48
- package/dist/services/purchases/models/purchases-esim.d.ts.map +0 -1
- package/dist/services/purchases/models/purchases-esim.js +0 -35
- package/dist/services/purchases/models/purchases-esim.js.map +0 -1
- package/dist/services/purchases/models/purchases.d.ts +0 -372
- package/dist/services/purchases/models/purchases.d.ts.map +0 -1
- package/dist/services/purchases/models/purchases.js +0 -91
- package/dist/services/purchases/models/purchases.js.map +0 -1
- package/dist/services/purchases/models/top-up-esim-ok-response-profile.d.ts +0 -48
- package/dist/services/purchases/models/top-up-esim-ok-response-profile.d.ts.map +0 -1
- package/dist/services/purchases/models/top-up-esim-ok-response-profile.js +0 -35
- package/dist/services/purchases/models/top-up-esim-ok-response-profile.js.map +0 -1
- package/dist/services/purchases/models/top-up-esim-ok-response-purchase.d.ts +0 -132
- package/dist/services/purchases/models/top-up-esim-ok-response-purchase.d.ts.map +0 -1
- package/dist/services/purchases/models/top-up-esim-ok-response-purchase.js +0 -69
- package/dist/services/purchases/models/top-up-esim-ok-response-purchase.js.map +0 -1
- package/dist/services/purchases/models/top-up-esim-ok-response.d.ts +0 -292
- package/dist/services/purchases/models/top-up-esim-ok-response.d.ts.map +0 -1
- package/dist/services/purchases/models/top-up-esim-ok-response.js +0 -46
- package/dist/services/purchases/models/top-up-esim-ok-response.js.map +0 -1
- package/dist/services/purchases/models/top-up-esim-request.d.ts +0 -146
- package/dist/services/purchases/models/top-up-esim-request.d.ts.map +0 -1
- package/dist/services/purchases/models/top-up-esim-request.js +0 -74
- package/dist/services/purchases/models/top-up-esim-request.js.map +0 -1
- package/dist/services/purchases/purchases.d.ts +0 -48
- package/dist/services/purchases/purchases.d.ts.map +0 -1
- package/dist/services/purchases/purchases.js +0 -162
- package/dist/services/purchases/purchases.js.map +0 -1
- package/dist/services/purchases/request-params.d.ts +0 -11
- package/dist/services/purchases/request-params.d.ts.map +0 -1
- package/dist/services/purchases/request-params.js +0 -3
- package/dist/services/purchases/request-params.js.map +0 -1
- package/documentation/models/CreatePurchaseOkResponse.md +0 -31
- package/documentation/models/CreatePurchaseRequest.md +0 -15
- package/documentation/models/EditPurchaseOkResponse.md +0 -11
- package/documentation/models/EditPurchaseRequest.md +0 -11
- package/documentation/models/GetEsimDeviceOkResponse.md +0 -18
- package/documentation/models/GetEsimHistoryOkResponse.md +0 -26
- package/documentation/models/GetEsimMacOkResponse.md +0 -17
- package/documentation/models/GetEsimOkResponse.md +0 -18
- package/documentation/models/GetPurchaseConsumptionOkResponse.md +0 -8
- package/documentation/models/ListDestinationsOkResponse.md +0 -17
- package/documentation/models/ListPackagesOkResponse.md +0 -21
- package/documentation/models/ListPurchasesOkResponse.md +0 -46
- package/documentation/models/TopUpEsimOkResponse.md +0 -30
- package/documentation/models/TopUpEsimRequest.md +0 -14
- package/documentation/services/DestinationsService.md +0 -35
- package/documentation/services/ESimService.md +0 -148
- package/documentation/services/PackagesService.md +0 -48
- package/documentation/services/PurchasesService.md +0 -219
- package/documentation/snippets/destinations-get.md +0 -14
- package/documentation/snippets/esim-get.md +0 -16
- package/documentation/snippets/esim-{iccid}-device-get.md +0 -14
- package/documentation/snippets/esim-{iccid}-history-get.md +0 -14
- package/documentation/snippets/esim-{iccid}-mac-get.md +0 -14
- package/documentation/snippets/packages-get.md +0 -14
- package/documentation/snippets/purchases-edit-post.md +0 -22
- package/documentation/snippets/purchases-get.md +0 -14
- package/documentation/snippets/purchases-post.md +0 -26
- package/documentation/snippets/purchases-topup-post.md +0 -25
- package/documentation/snippets/purchases-{purchaseId}-consumption-get.md +0 -14
- package/examples/README.md +0 -27
- package/examples/package.json +0 -18
- package/examples/src/index.ts +0 -12
- package/examples/tsconfig.json +0 -22
- package/src/http/client.ts +0 -46
- package/src/http/environment.ts +0 -3
- package/src/http/error.ts +0 -12
- package/src/http/handlers/handler-chain.ts +0 -22
- package/src/http/handlers/hook-handler.ts +0 -47
- package/src/http/handlers/request-validation-handler.ts +0 -72
- package/src/http/handlers/response-validation-handler.ts +0 -106
- package/src/http/handlers/retry-handler.ts +0 -40
- package/src/http/handlers/terminating-handler.ts +0 -38
- package/src/http/hooks/custom-hook.ts +0 -100
- package/src/http/hooks/hook.ts +0 -40
- package/src/http/serializer.ts +0 -183
- package/src/http/transport/request-builder.ts +0 -145
- package/src/http/transport/request.ts +0 -178
- package/src/http/types.ts +0 -70
- package/src/index.ts +0 -73
- package/src/services/base-service.ts +0 -29
- package/src/services/destinations/destinations.ts +0 -28
- package/src/services/destinations/index.ts +0 -1
- package/src/services/destinations/models/destinations.ts +0 -57
- package/src/services/destinations/models/index.ts +0 -2
- package/src/services/destinations/models/list-destinations-ok-response.ts +0 -42
- package/src/services/e-sim/e-sim.ts +0 -103
- package/src/services/e-sim/index.ts +0 -1
- package/src/services/e-sim/models/device.ts +0 -63
- package/src/services/e-sim/models/get-esim-device-ok-response.ts +0 -42
- package/src/services/e-sim/models/get-esim-history-ok-response-esim.ts +0 -47
- package/src/services/e-sim/models/get-esim-history-ok-response.ts +0 -46
- package/src/services/e-sim/models/get-esim-mac-ok-response-esim.ts +0 -57
- package/src/services/e-sim/models/get-esim-mac-ok-response.ts +0 -46
- package/src/services/e-sim/models/get-esim-ok-response-esim.ts +0 -63
- package/src/services/e-sim/models/get-esim-ok-response.ts +0 -46
- package/src/services/e-sim/models/history.ts +0 -53
- package/src/services/e-sim/models/index.ts +0 -9
- package/src/services/e-sim/request-params.ts +0 -3
- package/src/services/packages/index.ts +0 -1
- package/src/services/packages/models/index.ts +0 -2
- package/src/services/packages/models/list-packages-ok-response.ts +0 -49
- package/src/services/packages/models/packages.ts +0 -75
- package/src/services/packages/packages.ts +0 -48
- package/src/services/packages/request-params.ts +0 -10
- package/src/services/purchases/index.ts +0 -1
- package/src/services/purchases/models/create-purchase-ok-response-profile.ts +0 -46
- package/src/services/purchases/models/create-purchase-ok-response-purchase.ts +0 -81
- package/src/services/purchases/models/create-purchase-ok-response.ts +0 -61
- package/src/services/purchases/models/create-purchase-request.ts +0 -93
- package/src/services/purchases/models/edit-purchase-ok-response.ts +0 -69
- package/src/services/purchases/models/edit-purchase-request.ts +0 -69
- package/src/services/purchases/models/get-purchase-consumption-ok-response.ts +0 -48
- package/src/services/purchases/models/index.ts +0 -15
- package/src/services/purchases/models/list-purchases-ok-response.ts +0 -49
- package/src/services/purchases/models/package_.ts +0 -69
- package/src/services/purchases/models/purchases-esim.ts +0 -41
- package/src/services/purchases/models/purchases.ts +0 -107
- package/src/services/purchases/models/top-up-esim-ok-response-profile.ts +0 -41
- package/src/services/purchases/models/top-up-esim-ok-response-purchase.ts +0 -81
- package/src/services/purchases/models/top-up-esim-ok-response.ts +0 -61
- package/src/services/purchases/models/top-up-esim-request.ts +0 -87
- package/src/services/purchases/purchases.ts +0 -159
- package/src/services/purchases/request-params.ts +0 -10
- package/tsconfig.json +0 -22
package/examples/tsconfig.json
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"compilerOptions": {
|
3
|
-
"target": "es6",
|
4
|
-
"module": "commonjs",
|
5
|
-
"esModuleInterop": true,
|
6
|
-
"forceConsistentCasingInFileNames": true,
|
7
|
-
"strict": true,
|
8
|
-
"skipLibCheck": true,
|
9
|
-
"outDir": "./dist",
|
10
|
-
"rootDir": "./src",
|
11
|
-
"noImplicitAny": true,
|
12
|
-
"baseUrl": "./",
|
13
|
-
"declaration": true,
|
14
|
-
"moduleResolution": "node",
|
15
|
-
"isolatedModules": true,
|
16
|
-
"allowSyntheticDefaultImports": true,
|
17
|
-
"declarationMap": true,
|
18
|
-
"lib": ["es2017", "dom"],
|
19
|
-
"sourceMap": true
|
20
|
-
},
|
21
|
-
"include": ["src/"]
|
22
|
-
}
|
package/src/http/client.ts
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
import { SerializationStyle, serializePath, serializeQuery } from './serializer';
|
2
|
-
import { HttpMethod, HttpResponse, Options, RetryOptions, SdkConfig } from './types';
|
3
|
-
import { RequestHandlerChain } from './handlers/handler-chain';
|
4
|
-
import { HookHandler } from './handlers/hook-handler';
|
5
|
-
import { ResponseValidationHandler } from './handlers/response-validation-handler';
|
6
|
-
import { RequestValidationHandler } from './handlers/request-validation-handler';
|
7
|
-
import { CustomHook } from './hooks/custom-hook';
|
8
|
-
import { TerminatingHandler } from './handlers/terminating-handler';
|
9
|
-
import { RetryHandler } from './handlers/retry-handler';
|
10
|
-
import { Request } from './transport/request';
|
11
|
-
|
12
|
-
export class HttpClient {
|
13
|
-
private readonly requestHandlerChain = new RequestHandlerChain();
|
14
|
-
|
15
|
-
constructor(
|
16
|
-
private config: SdkConfig,
|
17
|
-
hook = new CustomHook(),
|
18
|
-
) {
|
19
|
-
this.requestHandlerChain.addHandler(new ResponseValidationHandler());
|
20
|
-
this.requestHandlerChain.addHandler(new RequestValidationHandler());
|
21
|
-
this.requestHandlerChain.addHandler(new RetryHandler());
|
22
|
-
this.requestHandlerChain.addHandler(new HookHandler(hook));
|
23
|
-
this.requestHandlerChain.addHandler(new TerminatingHandler());
|
24
|
-
}
|
25
|
-
|
26
|
-
call<T>(request: Request<T>): Promise<HttpResponse<T>> {
|
27
|
-
return this.requestHandlerChain.callChain(request);
|
28
|
-
}
|
29
|
-
|
30
|
-
buildPath(
|
31
|
-
pathPattern: string,
|
32
|
-
pathArguments: Record<string, unknown>,
|
33
|
-
style = SerializationStyle.SIMPLE,
|
34
|
-
explode = false,
|
35
|
-
): string {
|
36
|
-
return serializePath(pathPattern, pathArguments, style, explode);
|
37
|
-
}
|
38
|
-
|
39
|
-
setBaseUrl(url: string): void {
|
40
|
-
this.config.baseUrl = url;
|
41
|
-
}
|
42
|
-
|
43
|
-
setConfig(config: SdkConfig): void {
|
44
|
-
this.config = config;
|
45
|
-
}
|
46
|
-
}
|
package/src/http/environment.ts
DELETED
package/src/http/error.ts
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
import { HttpMetadata } from './types';
|
2
|
-
|
3
|
-
export class HttpError extends Error {
|
4
|
-
public readonly error: string;
|
5
|
-
public readonly metadata: HttpMetadata;
|
6
|
-
|
7
|
-
constructor(metadata: HttpMetadata, error?: string) {
|
8
|
-
super(error);
|
9
|
-
this.error = metadata.statusText;
|
10
|
-
this.metadata = metadata;
|
11
|
-
}
|
12
|
-
}
|
@@ -1,22 +0,0 @@
|
|
1
|
-
import { Request } from '../transport/request';
|
2
|
-
import { HttpResponse, RequestHandler } from '../types';
|
3
|
-
|
4
|
-
export class RequestHandlerChain {
|
5
|
-
private readonly handlers: RequestHandler[] = [];
|
6
|
-
|
7
|
-
addHandler(handler: RequestHandler): void {
|
8
|
-
if (this.handlers.length > 0) {
|
9
|
-
const previousHandler = this.handlers[this.handlers.length - 1];
|
10
|
-
previousHandler.next = handler;
|
11
|
-
}
|
12
|
-
this.handlers.push(handler);
|
13
|
-
}
|
14
|
-
|
15
|
-
async callChain<T>(request: Request<T>): Promise<HttpResponse<T>> {
|
16
|
-
if (!this.handlers.length) {
|
17
|
-
throw new Error('No handlers added to the chain');
|
18
|
-
}
|
19
|
-
|
20
|
-
return this.handlers[0].handle(request);
|
21
|
-
}
|
22
|
-
}
|
@@ -1,47 +0,0 @@
|
|
1
|
-
import { Request } from '../transport/request';
|
2
|
-
import { HttpResponse, RequestHandler } from '../types';
|
3
|
-
import { HttpError } from '../error';
|
4
|
-
import { Hook } from '../hooks/hook';
|
5
|
-
|
6
|
-
export class HookHandler implements RequestHandler {
|
7
|
-
next?: RequestHandler;
|
8
|
-
|
9
|
-
constructor(private readonly hook: Hook) {}
|
10
|
-
|
11
|
-
async handle<T>(request: Request<T>): Promise<HttpResponse<T>> {
|
12
|
-
if (!this.next) {
|
13
|
-
throw new Error('No next handler set in hook handler.');
|
14
|
-
}
|
15
|
-
|
16
|
-
const hookParams = this.getHookParams<T>(request);
|
17
|
-
|
18
|
-
const nextRequest = await this.beforeRequest(request, hookParams);
|
19
|
-
|
20
|
-
const response = await this.next.handle(nextRequest);
|
21
|
-
|
22
|
-
if (response.metadata.status < 400) {
|
23
|
-
return await this.hook.afterResponse(request.toHookRequest(), response, hookParams);
|
24
|
-
}
|
25
|
-
|
26
|
-
const error = await this.hook.onError(request.toHookRequest(), response, hookParams);
|
27
|
-
|
28
|
-
throw new HttpError(error.metadata, error.error);
|
29
|
-
}
|
30
|
-
|
31
|
-
private async beforeRequest<T>(request: Request<T>, hookParams: Map<string, string>): Promise<Request<T>> {
|
32
|
-
const hookRequest = request.toHookRequest();
|
33
|
-
|
34
|
-
const newRequest = await this.hook.beforeRequest(hookRequest, hookParams);
|
35
|
-
|
36
|
-
request.updateFromHookRequest(newRequest);
|
37
|
-
|
38
|
-
return request;
|
39
|
-
}
|
40
|
-
|
41
|
-
getHookParams<T>(request: Request<T>): Map<string, string> {
|
42
|
-
const hookParams: Map<string, string> = new Map();
|
43
|
-
hookParams.set('clientId', request.config.clientId || '');
|
44
|
-
hookParams.set('clientSecret', request.config.clientSecret || '');
|
45
|
-
return hookParams;
|
46
|
-
}
|
47
|
-
}
|
@@ -1,72 +0,0 @@
|
|
1
|
-
import { Request } from '../transport/request';
|
2
|
-
import { ContentType, HttpResponse, RequestHandler } from '../types';
|
3
|
-
import { HttpError } from '../error';
|
4
|
-
|
5
|
-
export class RequestValidationHandler implements RequestHandler {
|
6
|
-
next?: RequestHandler;
|
7
|
-
|
8
|
-
async handle<T>(request: Request<T>): Promise<HttpResponse<T>> {
|
9
|
-
if (!this.next) {
|
10
|
-
throw new Error('No next handler set in ContentTypeHandler.');
|
11
|
-
}
|
12
|
-
|
13
|
-
if (request.requestContentType === ContentType.Json) {
|
14
|
-
request.body = JSON.stringify(request.requestSchema?.parse(request.body));
|
15
|
-
} else if (
|
16
|
-
request.requestContentType === ContentType.Xml ||
|
17
|
-
request.requestContentType === ContentType.Binary ||
|
18
|
-
request.requestContentType === ContentType.Text
|
19
|
-
) {
|
20
|
-
request.body = request.body;
|
21
|
-
} else if (request.requestContentType === ContentType.FormUrlEncoded) {
|
22
|
-
request.body = this.toFormUrlEncoded(request.body);
|
23
|
-
} else if (request.requestContentType === ContentType.MultipartFormData) {
|
24
|
-
request.body = this.toFormData(request.body);
|
25
|
-
} else {
|
26
|
-
request.body = JSON.stringify(request.requestSchema?.parse(request.body));
|
27
|
-
}
|
28
|
-
|
29
|
-
return await this.next.handle(request);
|
30
|
-
}
|
31
|
-
|
32
|
-
toFormUrlEncoded(body: BodyInit | undefined): string {
|
33
|
-
if (body === undefined) {
|
34
|
-
return '';
|
35
|
-
}
|
36
|
-
|
37
|
-
if (typeof body === 'string') {
|
38
|
-
return body;
|
39
|
-
}
|
40
|
-
|
41
|
-
if (body instanceof URLSearchParams) {
|
42
|
-
return body.toString();
|
43
|
-
}
|
44
|
-
|
45
|
-
if (body instanceof FormData) {
|
46
|
-
const params = new URLSearchParams();
|
47
|
-
body.forEach((value, key) => {
|
48
|
-
params.append(key, value.toString());
|
49
|
-
});
|
50
|
-
return params.toString();
|
51
|
-
}
|
52
|
-
|
53
|
-
return '';
|
54
|
-
}
|
55
|
-
|
56
|
-
toFormData(body: Record<string, any>): FormData | undefined {
|
57
|
-
const formData = new FormData();
|
58
|
-
|
59
|
-
Object.keys(body).forEach((key: any) => {
|
60
|
-
const value: any = body[key];
|
61
|
-
if (Array.isArray(value)) {
|
62
|
-
value.forEach((v, i) => formData.append(`${key}[${i}]`, v));
|
63
|
-
} else if (value instanceof ArrayBuffer) {
|
64
|
-
formData.append(key, new Blob([value]));
|
65
|
-
} else {
|
66
|
-
formData.append(key, value);
|
67
|
-
}
|
68
|
-
});
|
69
|
-
|
70
|
-
return formData;
|
71
|
-
}
|
72
|
-
}
|
@@ -1,106 +0,0 @@
|
|
1
|
-
import { Request } from '../transport/request';
|
2
|
-
import { ZodUndefined } from 'zod';
|
3
|
-
import { ContentType, HttpResponse, RequestHandler } from '../types';
|
4
|
-
import { HttpError } from '../error';
|
5
|
-
|
6
|
-
export class ResponseValidationHandler implements RequestHandler {
|
7
|
-
next?: RequestHandler;
|
8
|
-
|
9
|
-
async handle<T>(request: Request<T>): Promise<HttpResponse<T>> {
|
10
|
-
const response = await this.next!.handle(request);
|
11
|
-
|
12
|
-
if (!this.hasContent(request, response)) {
|
13
|
-
return response;
|
14
|
-
}
|
15
|
-
|
16
|
-
if (request.responseContentType === ContentType.Json) {
|
17
|
-
const decodedBody = new TextDecoder().decode(response.raw);
|
18
|
-
const json = JSON.parse(decodedBody);
|
19
|
-
return {
|
20
|
-
...response,
|
21
|
-
data: this.validate<T>(request, json),
|
22
|
-
};
|
23
|
-
} else if (
|
24
|
-
request.responseContentType === ContentType.Binary ||
|
25
|
-
request.responseContentType === ContentType.Image
|
26
|
-
) {
|
27
|
-
return {
|
28
|
-
...response,
|
29
|
-
data: this.validate<T>(request, response.raw),
|
30
|
-
};
|
31
|
-
} else if (request.responseContentType === ContentType.Text || request.responseContentType === ContentType.Xml) {
|
32
|
-
const text = new TextDecoder().decode(response.raw);
|
33
|
-
return {
|
34
|
-
...response,
|
35
|
-
data: this.validate<T>(request, text),
|
36
|
-
};
|
37
|
-
} else if (request.responseContentType === ContentType.FormUrlEncoded) {
|
38
|
-
const urlEncoded = this.fromUrlEncoded(new TextDecoder().decode(response.raw));
|
39
|
-
return {
|
40
|
-
...response,
|
41
|
-
data: this.validate<T>(request, urlEncoded),
|
42
|
-
};
|
43
|
-
} else if (request.responseContentType === ContentType.MultipartFormData) {
|
44
|
-
const formData = this.fromFormData(response.raw);
|
45
|
-
return {
|
46
|
-
...response,
|
47
|
-
data: this.validate<T>(request, formData),
|
48
|
-
};
|
49
|
-
} else {
|
50
|
-
const decodedBody = new TextDecoder().decode(response.raw);
|
51
|
-
const json = JSON.parse(decodedBody);
|
52
|
-
return {
|
53
|
-
...response,
|
54
|
-
data: this.validate<T>(request, json),
|
55
|
-
};
|
56
|
-
}
|
57
|
-
}
|
58
|
-
|
59
|
-
private validate<T>(request: Request<T>, data: any): T {
|
60
|
-
if (request.validation?.responseValidation) {
|
61
|
-
return request.responseSchema.parse(data);
|
62
|
-
}
|
63
|
-
return data;
|
64
|
-
}
|
65
|
-
|
66
|
-
private hasContent<T>(request: Request<T>, response: HttpResponse<T>): boolean {
|
67
|
-
return (
|
68
|
-
!!request.responseSchema && !(request.responseSchema instanceof ZodUndefined) && response.metadata.status !== 204
|
69
|
-
);
|
70
|
-
}
|
71
|
-
|
72
|
-
private fromUrlEncoded(urlEncodedData: string): object {
|
73
|
-
const pairs = urlEncodedData.split('&');
|
74
|
-
const result: Record<string, string> = {};
|
75
|
-
|
76
|
-
pairs.forEach((pair) => {
|
77
|
-
const [key, value] = pair.split('=');
|
78
|
-
if (key && value !== undefined) {
|
79
|
-
result[decodeURIComponent(key)] = decodeURIComponent(value);
|
80
|
-
}
|
81
|
-
});
|
82
|
-
|
83
|
-
return result;
|
84
|
-
}
|
85
|
-
|
86
|
-
private fromFormData(arrayBuffer: ArrayBuffer): Record<string, string> {
|
87
|
-
const decoder = new TextDecoder();
|
88
|
-
const text = decoder.decode(arrayBuffer);
|
89
|
-
|
90
|
-
const boundary = text.split('\r\n')[0];
|
91
|
-
const parts = text.split(boundary).slice(1, -1);
|
92
|
-
|
93
|
-
const formDataObj: Record<string, string> = {};
|
94
|
-
|
95
|
-
parts.forEach((part) => {
|
96
|
-
const [header, value] = part.split('\r\n\r\n');
|
97
|
-
const nameMatch = header.match(/name="([^"]+)"/);
|
98
|
-
if (nameMatch) {
|
99
|
-
const name = nameMatch[1].trim();
|
100
|
-
formDataObj[name] = value?.trim() || '';
|
101
|
-
}
|
102
|
-
});
|
103
|
-
|
104
|
-
return formDataObj;
|
105
|
-
}
|
106
|
-
}
|
@@ -1,40 +0,0 @@
|
|
1
|
-
import { Request } from '../transport/request';
|
2
|
-
import { HttpResponse, RequestHandler } from '../types';
|
3
|
-
import { HttpError } from '../error';
|
4
|
-
|
5
|
-
export class RetryHandler implements RequestHandler {
|
6
|
-
next?: RequestHandler;
|
7
|
-
|
8
|
-
async handle<T>(request: Request<T>): Promise<HttpResponse<T>> {
|
9
|
-
if (!this.next) {
|
10
|
-
throw new Error('No next handler set in retry handler.');
|
11
|
-
}
|
12
|
-
|
13
|
-
for (let attempt = 1; attempt <= request.retry.attempts; attempt++) {
|
14
|
-
try {
|
15
|
-
return await this.next.handle(request);
|
16
|
-
} catch (error: any) {
|
17
|
-
if (!this.shouldRetry(error) || attempt === request.retry.attempts) {
|
18
|
-
throw error;
|
19
|
-
}
|
20
|
-
await this.delay(request.retry.delayMs);
|
21
|
-
}
|
22
|
-
}
|
23
|
-
|
24
|
-
throw new Error('Error retrying request.');
|
25
|
-
}
|
26
|
-
|
27
|
-
private shouldRetry(error: Error): boolean {
|
28
|
-
return error instanceof HttpError && (error.metadata.status >= 500 || error.metadata.status === 408);
|
29
|
-
}
|
30
|
-
|
31
|
-
private delay(delayMs: number | undefined): Promise<void> {
|
32
|
-
if (!delayMs) {
|
33
|
-
return Promise.resolve();
|
34
|
-
}
|
35
|
-
|
36
|
-
return new Promise((resolve, reject) => {
|
37
|
-
setTimeout(() => resolve(), delayMs);
|
38
|
-
});
|
39
|
-
}
|
40
|
-
}
|
@@ -1,38 +0,0 @@
|
|
1
|
-
import { HttpError } from '../error';
|
2
|
-
import { Request } from '../transport/request';
|
3
|
-
import { HttpResponse, RequestHandler } from '../types';
|
4
|
-
|
5
|
-
export class TerminatingHandler implements RequestHandler {
|
6
|
-
async handle<T>(request: Request<T>): Promise<HttpResponse<T>> {
|
7
|
-
const { url, requestInit } = request.getFetchArgs();
|
8
|
-
const response = await fetch(url, requestInit);
|
9
|
-
|
10
|
-
const metadata = {
|
11
|
-
status: response.status,
|
12
|
-
statusText: response.statusText,
|
13
|
-
headers: this.getHeaders(response),
|
14
|
-
};
|
15
|
-
|
16
|
-
if (metadata.status >= 400) {
|
17
|
-
throw new HttpError(metadata);
|
18
|
-
}
|
19
|
-
|
20
|
-
return {
|
21
|
-
metadata,
|
22
|
-
raw: await response.clone().arrayBuffer(),
|
23
|
-
};
|
24
|
-
}
|
25
|
-
|
26
|
-
private getHeaders(response: Response): Record<string, string> {
|
27
|
-
const headers: Record<string, string> = {};
|
28
|
-
response.headers.forEach((value: string, key: string) => {
|
29
|
-
headers[key] = value;
|
30
|
-
});
|
31
|
-
|
32
|
-
return headers;
|
33
|
-
}
|
34
|
-
|
35
|
-
private isErrorResponse(response: HttpResponse<unknown>): boolean {
|
36
|
-
return response.metadata.status >= 400;
|
37
|
-
}
|
38
|
-
}
|
@@ -1,100 +0,0 @@
|
|
1
|
-
import { HttpMetadata } from '../types';
|
2
|
-
import { Hook } from './hook';
|
3
|
-
import { HttpRequest, HttpResponse, HttpError } from './hook';
|
4
|
-
|
5
|
-
let CURRENT_TOKEN = '';
|
6
|
-
let CURRENT_EXPIRY = -1;
|
7
|
-
|
8
|
-
export class CustomHook implements Hook {
|
9
|
-
async getToken(clientId: string, clientSecret: string): Promise<any> {
|
10
|
-
const tokenUrl = 'https://auth.celitech.net/oauth2/token';
|
11
|
-
|
12
|
-
const headers = {
|
13
|
-
'Content-Type': 'application/x-www-form-urlencoded',
|
14
|
-
};
|
15
|
-
|
16
|
-
const body = {
|
17
|
-
client_id: clientId,
|
18
|
-
client_secret: clientSecret,
|
19
|
-
grant_type: 'client_credentials',
|
20
|
-
};
|
21
|
-
|
22
|
-
const response = await fetch(tokenUrl, {
|
23
|
-
method: 'POST',
|
24
|
-
headers: headers,
|
25
|
-
body: new URLSearchParams(body),
|
26
|
-
});
|
27
|
-
|
28
|
-
return response.json();
|
29
|
-
}
|
30
|
-
|
31
|
-
public async beforeRequest(request: HttpRequest, params: Map<string, string>): Promise<HttpRequest> {
|
32
|
-
console.log('request', request);
|
33
|
-
console.log('params', params);
|
34
|
-
|
35
|
-
const clientId = params.get('clientId') || '';
|
36
|
-
const clientSecret = params.get('clientSecret') || '';
|
37
|
-
|
38
|
-
console.log('clientId', clientId);
|
39
|
-
console.log('clientSecret', clientSecret);
|
40
|
-
|
41
|
-
if (!clientId || !clientSecret) {
|
42
|
-
throw new Error('Missing clientId and/or clientSecret constructor parameters');
|
43
|
-
}
|
44
|
-
|
45
|
-
if (!CURRENT_TOKEN || CURRENT_EXPIRY < Date.now()) {
|
46
|
-
// Fetch a fresh Oauth token
|
47
|
-
// Retrieve the new access token and expiry, and set them to the global variables
|
48
|
-
const tokenResponse = await this.getToken(clientId, clientSecret);
|
49
|
-
|
50
|
-
console.log('tokenResponse', tokenResponse);
|
51
|
-
|
52
|
-
if (tokenResponse.error) {
|
53
|
-
throw new Error(tokenResponse.error);
|
54
|
-
}
|
55
|
-
|
56
|
-
const { expires_in, access_token } = tokenResponse;
|
57
|
-
|
58
|
-
if (!expires_in || !access_token) {
|
59
|
-
throw new Error('There is an issue with getting the oauth token');
|
60
|
-
}
|
61
|
-
CURRENT_EXPIRY = Date.now() + expires_in * 1000;
|
62
|
-
CURRENT_TOKEN = access_token;
|
63
|
-
}
|
64
|
-
|
65
|
-
// Set the Bearer token in the request header
|
66
|
-
const authorization = `Bearer ${CURRENT_TOKEN}`;
|
67
|
-
|
68
|
-
console.log('authorization', authorization);
|
69
|
-
|
70
|
-
if (!request.headers) {
|
71
|
-
request.headers = new Map();
|
72
|
-
}
|
73
|
-
request.headers.set('Authorization', authorization);
|
74
|
-
|
75
|
-
return request;
|
76
|
-
}
|
77
|
-
|
78
|
-
public async afterResponse(
|
79
|
-
request: HttpRequest,
|
80
|
-
response: HttpResponse<any>,
|
81
|
-
params: Map<string, string>,
|
82
|
-
): Promise<HttpResponse<any>> {
|
83
|
-
return response;
|
84
|
-
}
|
85
|
-
|
86
|
-
public async onError(
|
87
|
-
request: HttpRequest,
|
88
|
-
response: HttpResponse<any>,
|
89
|
-
params: Map<string, string>,
|
90
|
-
): Promise<HttpError> {
|
91
|
-
return new CustomHttpError('a custom error message', response.metadata);
|
92
|
-
}
|
93
|
-
}
|
94
|
-
|
95
|
-
class CustomHttpError implements HttpError {
|
96
|
-
constructor(
|
97
|
-
public error: string,
|
98
|
-
public metadata: HttpMetadata,
|
99
|
-
) {}
|
100
|
-
}
|
package/src/http/hooks/hook.ts
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
2
|
-
|
3
|
-
export interface HttpRequest {
|
4
|
-
baseUrl: string;
|
5
|
-
method: HttpMethod;
|
6
|
-
path: string;
|
7
|
-
headers: Map<string, unknown>;
|
8
|
-
body?: BodyInit;
|
9
|
-
abortSignal?: AbortSignal;
|
10
|
-
queryParams: Map<string, unknown>;
|
11
|
-
}
|
12
|
-
|
13
|
-
interface HttpMetadata {
|
14
|
-
status: number;
|
15
|
-
statusText: string;
|
16
|
-
headers: Record<string, string>;
|
17
|
-
}
|
18
|
-
|
19
|
-
export interface HttpResponse<T> {
|
20
|
-
data?: T;
|
21
|
-
metadata: HttpMetadata;
|
22
|
-
raw: ArrayBuffer;
|
23
|
-
}
|
24
|
-
|
25
|
-
export interface HttpError {
|
26
|
-
error: string;
|
27
|
-
metadata: HttpMetadata;
|
28
|
-
}
|
29
|
-
|
30
|
-
export interface Hook {
|
31
|
-
beforeRequest(request: HttpRequest, params: Map<string, string>): Promise<HttpRequest>;
|
32
|
-
|
33
|
-
afterResponse(
|
34
|
-
request: HttpRequest,
|
35
|
-
response: HttpResponse<any>,
|
36
|
-
params: Map<string, string>,
|
37
|
-
): Promise<HttpResponse<any>>;
|
38
|
-
|
39
|
-
onError(request: HttpRequest, response: HttpResponse<any>, params: Map<string, string>): Promise<HttpError>;
|
40
|
-
}
|