@automattic/vip 4.1.6 → 4.1.8
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/assets/dev-env.lando.template.yml.ejs +1 -1
- package/dist/bin/vip-app-deploy-token-generate.js +110 -78
- package/dist/bin/vip-app-deploy-token.js +24 -16
- package/dist/bin/vip-app-deploy-validate.js +45 -41
- package/dist/bin/vip-app-deploy.js +222 -215
- package/dist/bin/vip-app-list.js +59 -43
- package/dist/bin/vip-app.js +97 -66
- package/dist/bin/vip-backup-db.js +36 -29
- package/dist/bin/vip-backup.js +16 -9
- package/dist/bin/vip-cache-purge-url.js +93 -55
- package/dist/bin/vip-cache.js +23 -14
- package/dist/bin/vip-config-envvar-delete.js +74 -73
- package/dist/bin/vip-config-envvar-get-all.js +68 -68
- package/dist/bin/vip-config-envvar-get.js +46 -46
- package/dist/bin/vip-config-envvar-list.js +54 -57
- package/dist/bin/vip-config-envvar-set.js +102 -96
- package/dist/bin/vip-config-envvar.js +38 -24
- package/dist/bin/vip-config-software-get.js +88 -75
- package/dist/bin/vip-config-software-update.js +116 -120
- package/dist/bin/vip-config-software.js +31 -21
- package/dist/bin/vip-config.js +25 -17
- package/dist/bin/vip-db-phpmyadmin.js +40 -39
- package/dist/bin/vip-db.js +13 -12
- package/dist/bin/vip-defensive-mode-configure.js +197 -197
- package/dist/bin/vip-defensive-mode-disable.js +43 -35
- package/dist/bin/vip-defensive-mode-enable.js +47 -38
- package/dist/bin/vip-defensive-mode.js +28 -17
- package/dist/bin/vip-dev-env-create.js +147 -104
- package/dist/bin/vip-dev-env-destroy.js +48 -39
- package/dist/bin/vip-dev-env-envvar-delete.js +60 -49
- package/dist/bin/vip-dev-env-envvar-get-all.js +52 -45
- package/dist/bin/vip-dev-env-envvar-get.js +48 -37
- package/dist/bin/vip-dev-env-envvar-list.js +48 -41
- package/dist/bin/vip-dev-env-envvar-set.js +83 -70
- package/dist/bin/vip-dev-env-envvar.js +38 -23
- package/dist/bin/vip-dev-env-exec.js +81 -74
- package/dist/bin/vip-dev-env-import-media.js +34 -26
- package/dist/bin/vip-dev-env-import-sql.js +65 -51
- package/dist/bin/vip-dev-env-import.js +23 -14
- package/dist/bin/vip-dev-env-info.js +59 -50
- package/dist/bin/vip-dev-env-list.js +34 -31
- package/dist/bin/vip-dev-env-logs.js +59 -49
- package/dist/bin/vip-dev-env-purge.js +71 -63
- package/dist/bin/vip-dev-env-shell.js +82 -71
- package/dist/bin/vip-dev-env-start.js +77 -65
- package/dist/bin/vip-dev-env-stop.js +80 -74
- package/dist/bin/vip-dev-env-sync-sql.js +80 -72
- package/dist/bin/vip-dev-env-sync.js +18 -11
- package/dist/bin/vip-dev-env-update.js +93 -84
- package/dist/bin/vip-dev-env.js +25 -8
- package/dist/bin/vip-edge-workers-build.js +82 -54
- package/dist/bin/vip-edge-workers-delete.js +84 -52
- package/dist/bin/vip-edge-workers-deploy.js +186 -126
- package/dist/bin/vip-edge-workers-disable.js +75 -44
- package/dist/bin/vip-edge-workers-enable.js +86 -54
- package/dist/bin/vip-edge-workers-get.js +108 -88
- package/dist/bin/vip-edge-workers-init.js +83 -53
- package/dist/bin/vip-edge-workers-list.js +89 -54
- package/dist/bin/vip-edge-workers-new.js +98 -69
- package/dist/bin/vip-edge-workers-validate.js +123 -82
- package/dist/bin/vip-edge-workers.js +19 -6
- package/dist/bin/vip-export-sql.js +75 -69
- package/dist/bin/vip-export.js +12 -7
- package/dist/bin/vip-import-media-abort.js +99 -73
- package/dist/bin/vip-import-media-status.js +83 -51
- package/dist/bin/vip-import-media.js +165 -166
- package/dist/bin/vip-import-sql-status.js +75 -45
- package/dist/bin/vip-import-sql.js +536 -596
- package/dist/bin/vip-import-validate-files.js +122 -141
- package/dist/bin/vip-import-validate-sql.js +52 -16
- package/dist/bin/vip-import.js +16 -7
- package/dist/bin/vip-logout.js +17 -13
- package/dist/bin/vip-logs.js +209 -183
- package/dist/bin/vip-search-replace.js +85 -53
- package/dist/bin/vip-slowlogs.js +168 -147
- package/dist/bin/vip-sync.js +163 -133
- package/dist/bin/vip-whoami.js +71 -35
- package/dist/bin/vip-wp.js +506 -549
- package/dist/bin/vip.js +161 -116
- package/dist/commands/backup-db.js +183 -149
- package/dist/commands/dev-env-import-sql.js +162 -117
- package/dist/commands/dev-env-sync-sql.js +372 -330
- package/dist/commands/export-sql.js +441 -425
- package/dist/commands/phpmyadmin.js +232 -212
- package/dist/commands/wp-ssh.js +218 -187
- package/dist/lib/analytics/clients/tracks.js +84 -91
- package/dist/lib/analytics/index.js +27 -27
- package/dist/lib/api/app.js +37 -36
- package/dist/lib/api/cache-purge.js +17 -20
- package/dist/lib/api/constants.js +5 -6
- package/dist/lib/api/edge-workers.js +84 -135
- package/dist/lib/api/error-debug.js +10 -13
- package/dist/lib/api/feature-flags.js +16 -17
- package/dist/lib/api/http.js +47 -48
- package/dist/lib/api/user.js +17 -18
- package/dist/lib/api.js +107 -116
- package/dist/lib/app-logs/app-logs.js +24 -25
- package/dist/lib/app-slowlogs/app-slowlogs.js +23 -24
- package/dist/lib/app-slowlogs/types.js +2 -1
- package/dist/lib/app.js +6 -8
- package/dist/lib/backup-storage-availability/backup-storage-availability.js +119 -119
- package/dist/lib/backup-storage-availability/docker-machine-not-found-error.js +5 -6
- package/dist/lib/cli/apiConfig.js +71 -41
- package/dist/lib/cli/command.js +1120 -873
- package/dist/lib/cli/config.js +29 -29
- package/dist/lib/cli/envAlias.js +35 -50
- package/dist/lib/cli/exit.js +19 -19
- package/dist/lib/cli/format.js +172 -172
- package/dist/lib/cli/progress.js +193 -236
- package/dist/lib/cli/prompt.js +14 -15
- package/dist/lib/cli/runtime-mode.js +5 -6
- package/dist/lib/client-file-uploader.js +489 -641
- package/dist/lib/config/software.js +206 -212
- package/dist/lib/constants/dev-environment.js +40 -37
- package/dist/lib/constants/file-size.js +6 -7
- package/dist/lib/constants/vipgo.js +24 -12
- package/dist/lib/custom-deploy/custom-deploy.js +138 -120
- package/dist/lib/database.js +88 -85
- package/dist/lib/defensive-mode/api.js +41 -46
- package/dist/lib/defensive-mode/cli-helpers.js +40 -40
- package/dist/lib/dev-environment/dev-environment-cli.js +776 -735
- package/dist/lib/dev-environment/dev-environment-configuration-file.js +224 -191
- package/dist/lib/dev-environment/dev-environment-core.js +697 -732
- package/dist/lib/dev-environment/dev-environment-database.js +57 -41
- package/dist/lib/dev-environment/dev-environment-lando.js +734 -666
- package/dist/lib/dev-environment/docker-utils.js +96 -90
- package/dist/lib/dev-environment/env-vars.js +61 -59
- package/dist/lib/dev-environment/lando-loader.js +6 -7
- package/dist/lib/dev-environment/types.js +2 -1
- package/dist/lib/edge-workers/confirmation.js +42 -36
- package/dist/lib/edge-workers/deployment.js +150 -159
- package/dist/lib/edge-workers/index.js +68 -85
- package/dist/lib/edge-workers/location.js +26 -26
- package/dist/lib/edge-workers/output.js +14 -15
- package/dist/lib/edge-workers/project.js +123 -132
- package/dist/lib/edge-workers/toolchains/assemblyscript/constants.js +6 -8
- package/dist/lib/edge-workers/toolchains/assemblyscript/index.js +100 -101
- package/dist/lib/edge-workers/toolchains/assemblyscript/templates.js +31 -33
- package/dist/lib/edge-workers/toolchains/index.js +15 -15
- package/dist/lib/edge-workers/types.js +10 -38
- package/dist/lib/edge-workers/validation.js +161 -150
- package/dist/lib/env.js +16 -17
- package/dist/lib/envvar/api-delete.js +16 -18
- package/dist/lib/envvar/api-get-all.js +15 -19
- package/dist/lib/envvar/api-get.js +8 -9
- package/dist/lib/envvar/api-list.js +16 -21
- package/dist/lib/envvar/api-set.js +20 -19
- package/dist/lib/envvar/api.js +34 -29
- package/dist/lib/envvar/input.js +29 -34
- package/dist/lib/envvar/logging.js +9 -11
- package/dist/lib/envvar/read-file.js +6 -7
- package/dist/lib/http/download-file.js +76 -44
- package/dist/lib/http/proxy-agent.js +37 -40
- package/dist/lib/http/proxy-dispatcher.js +69 -71
- package/dist/lib/keychain/insecure.js +40 -36
- package/dist/lib/keychain/keychain.js +2 -1
- package/dist/lib/keychain/secure.js +16 -15
- package/dist/lib/keychain.js +22 -22
- package/dist/lib/live-backup-copy.js +117 -115
- package/dist/lib/logout.js +17 -19
- package/dist/lib/media-import/config.js +15 -14
- package/dist/lib/media-import/media-file-import.js +9 -13
- package/dist/lib/media-import/progress.js +53 -65
- package/dist/lib/media-import/status.js +241 -256
- package/dist/lib/media-import/utils.js +15 -15
- package/dist/lib/node-version-check.js +16 -16
- package/dist/lib/promise.js +16 -17
- package/dist/lib/read-file.js +48 -16
- package/dist/lib/rechallenge/client.js +37 -43
- package/dist/lib/rechallenge/errors.js +38 -37
- package/dist/lib/rechallenge/flow.js +148 -123
- package/dist/lib/rechallenge/index.js +23 -24
- package/dist/lib/rechallenge/link.js +153 -151
- package/dist/lib/rechallenge/open-browser.js +14 -17
- package/dist/lib/rechallenge/token-cache.js +83 -86
- package/dist/lib/rechallenge/types.js +5 -14
- package/dist/lib/retry.js +93 -129
- package/dist/lib/search-and-replace.js +164 -148
- package/dist/lib/site-import/db-file-import.js +12 -16
- package/dist/lib/site-import/status.js +291 -291
- package/dist/lib/token.js +86 -87
- package/dist/lib/tracker.js +51 -62
- package/dist/lib/types/graphql/rate-limit-exceeded-error.js +2 -1
- package/dist/lib/types.js +2 -1
- package/dist/lib/user-error.js +6 -8
- package/dist/lib/utils.js +81 -87
- package/dist/lib/validations/custom-deploy.js +218 -186
- package/dist/lib/validations/is-multi-site-sql-dump.js +6 -6
- package/dist/lib/validations/is-multi-site.js +83 -50
- package/dist/lib/validations/is-multisite-domain-mapped.js +92 -62
- package/dist/lib/validations/line-by-line.js +78 -46
- package/dist/lib/validations/site-type.js +59 -63
- package/dist/lib/validations/sql-insert-parser.js +415 -0
- package/dist/lib/validations/sql.js +551 -431
- package/dist/lib/validations/utils.js +27 -29
- package/dist/lib/vip-import-validate-files.js +481 -490
- package/dist/lib/wp/helpers.js +41 -45
- package/dist/lib/wp/readline.js +21 -57
- package/dist/lib/xdg-data.js +11 -12
- package/helpers/mark-cli-executable.js +9 -0
- package/node_modules/@apollo/client/CHANGELOG.md +10 -0
- package/node_modules/@apollo/client/__cjs/cache/inmemory/helpers.cjs +5 -0
- package/node_modules/@apollo/client/__cjs/cache/inmemory/helpers.cjs.map +1 -1
- package/node_modules/@apollo/client/__cjs/cache/inmemory/inMemoryCache.cjs +2 -1
- package/node_modules/@apollo/client/__cjs/cache/inmemory/inMemoryCache.cjs.map +1 -1
- package/node_modules/@apollo/client/__cjs/cache/inmemory/key-extractor.cjs +14 -2
- package/node_modules/@apollo/client/__cjs/cache/inmemory/key-extractor.cjs.map +1 -1
- package/node_modules/@apollo/client/__cjs/cache/inmemory/policies.cjs +16 -0
- package/node_modules/@apollo/client/__cjs/cache/inmemory/policies.cjs.map +1 -1
- package/node_modules/@apollo/client/__cjs/cache/inmemory/policies.d.cts +2 -0
- package/node_modules/@apollo/client/__cjs/cache/inmemory/writeToStore.cjs +3 -2
- package/node_modules/@apollo/client/__cjs/cache/inmemory/writeToStore.cjs.map +1 -1
- package/node_modules/@apollo/client/__cjs/core/QueryInfo.cjs +9 -1
- package/node_modules/@apollo/client/__cjs/core/QueryInfo.cjs.map +1 -1
- package/node_modules/@apollo/client/__cjs/core/QueryInfo.d.cts +1 -1
- package/node_modules/@apollo/client/__cjs/core/QueryManager.cjs +10 -3
- package/node_modules/@apollo/client/__cjs/core/QueryManager.cjs.map +1 -1
- package/node_modules/@apollo/client/__cjs/react/hooks/useFragment.cjs.map +1 -1
- package/node_modules/@apollo/client/__cjs/react/hooks/useFragment.d.cts +42 -43
- package/node_modules/@apollo/client/__cjs/version.cjs +1 -1
- package/node_modules/@apollo/client/cache/inmemory/helpers.js +5 -0
- package/node_modules/@apollo/client/cache/inmemory/helpers.js.map +1 -1
- package/node_modules/@apollo/client/cache/inmemory/inMemoryCache.js +2 -1
- package/node_modules/@apollo/client/cache/inmemory/inMemoryCache.js.map +1 -1
- package/node_modules/@apollo/client/cache/inmemory/key-extractor.js +14 -2
- package/node_modules/@apollo/client/cache/inmemory/key-extractor.js.map +1 -1
- package/node_modules/@apollo/client/cache/inmemory/policies.d.ts +2 -0
- package/node_modules/@apollo/client/cache/inmemory/policies.js +17 -1
- package/node_modules/@apollo/client/cache/inmemory/policies.js.map +1 -1
- package/node_modules/@apollo/client/cache/inmemory/writeToStore.js +3 -2
- package/node_modules/@apollo/client/cache/inmemory/writeToStore.js.map +1 -1
- package/node_modules/@apollo/client/core/QueryInfo.d.ts +1 -1
- package/node_modules/@apollo/client/core/QueryInfo.js +10 -2
- package/node_modules/@apollo/client/core/QueryInfo.js.map +1 -1
- package/node_modules/@apollo/client/core/QueryManager.js +10 -3
- package/node_modules/@apollo/client/core/QueryManager.js.map +1 -1
- package/node_modules/@apollo/client/package.json +1 -1
- package/node_modules/@apollo/client/react/hooks/useFragment.d.ts +42 -43
- package/node_modules/@apollo/client/react/hooks/useFragment.js.map +1 -1
- package/node_modules/@apollo/client/react/hooks-compiled/useFragment.d.ts +42 -43
- package/node_modules/@apollo/client/react/hooks-compiled/useFragment.js.map +1 -1
- package/node_modules/@apollo/client/version.js +1 -1
- package/node_modules/@automattic/vip-search-replace/README.md +6 -1
- package/node_modules/@automattic/vip-search-replace/lib/index.js +46 -14
- package/node_modules/@automattic/vip-search-replace/package.json +1 -1
- package/node_modules/@types/node/README.md +1 -1
- package/node_modules/@types/node/package.json +2 -2
- package/node_modules/@types/node/zlib.d.ts +752 -0
- package/node_modules/check-disk-space/README.md +92 -32
- package/node_modules/check-disk-space/dist/check-disk-space.d.mts +58 -0
- package/node_modules/check-disk-space/dist/check-disk-space.mjs +170 -190
- package/node_modules/check-disk-space/package.json +43 -71
- package/node_modules/cpu-features/build/Makefile +2 -2
- package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/filesystem.o.d +1 -1
- package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/impl_aarch64_linux_or_android.o.d +1 -1
- package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/impl_aarch64_macos_or_iphone.o.d +1 -1
- package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/impl_aarch64_windows.o.d +1 -1
- package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/impl_arm_linux_or_android.o.d +1 -1
- package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/impl_mips_linux_or_android.o.d +1 -1
- package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/impl_ppc_linux.o.d +1 -1
- package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/impl_x86_freebsd.o.d +1 -1
- package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/impl_x86_linux_or_android.o.d +1 -1
- package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/impl_x86_macos.o.d +1 -1
- package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/impl_x86_windows.o.d +1 -1
- package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/stack_line_reader.o.d +1 -1
- package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/string_view.o.d +1 -1
- package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpufeatures/src/binding.o.d +157 -145
- package/node_modules/cpu-features/build/Release/cpufeatures.node +0 -0
- package/node_modules/cpu-features/build/Release/obj.target/cpufeatures/src/binding.o +0 -0
- package/node_modules/cpu-features/build/Release/obj.target/cpufeatures.node +0 -0
- package/node_modules/cpu-features/build/config.gypi +100 -31
- package/node_modules/cpu-features/build/cpufeatures.target.mk +14 -14
- package/node_modules/cpu-features/build/deps/cpu_features/cpu_features.target.mk +14 -14
- package/node_modules/ssh2/lib/protocol/crypto/build/Makefile +2 -2
- package/node_modules/ssh2/lib/protocol/crypto/build/Release/.deps/Release/obj.target/sshcrypto/src/binding.o.d.raw +136 -0
- package/node_modules/ssh2/lib/protocol/crypto/build/sshcrypto.target.mk +14 -14
- package/node_modules/undici/docs/docs/api/Interceptors.md +15 -2
- package/node_modules/undici/lib/dispatcher/client-h2.js +78 -3
- package/node_modules/undici/lib/dispatcher/pool-base.js +20 -3
- package/node_modules/undici/package.json +3 -3
- package/node_modules/undici/types/api.d.ts +1 -1
- package/node_modules/undici/types/utility.d.ts +4 -4
- package/package.json +44 -13
- package/dist/lib/analytics/clients/client.js +0 -1
- package/dist/lib/analytics/clients/pendo.js +0 -78
- package/helpers/check-version.js +0 -16
- package/node_modules/check-disk-space/dist/check-disk-space.cjs +0 -210
- package/node_modules/check-disk-space/dist/check-disk-space.d.ts +0 -53
- package/node_modules/fetch-retry/.eslintignore +0 -1
- package/node_modules/fetch-retry/.eslintrc.yml +0 -20
- package/node_modules/fetch-retry/.github/workflows/node.js.yml +0 -32
- package/node_modules/fetch-retry/.husky/pre-commit +0 -6
- package/node_modules/fetch-retry/.nycrc.json +0 -24
- package/node_modules/fetch-retry/.travis.yml +0 -3
- package/node_modules/fetch-retry/LICENSE +0 -21
- package/node_modules/fetch-retry/README.md +0 -128
- package/node_modules/fetch-retry/dist/fetch-retry.umd.js +0 -151
- package/node_modules/fetch-retry/index.d.ts +0 -29
- package/node_modules/fetch-retry/index.js +0 -143
- package/node_modules/fetch-retry/package.json +0 -41
- package/node_modules/fetch-retry/rollup.config.js +0 -12
- package/node_modules/fetch-retry/test/.eslintrc.yml +0 -7
- package/node_modules/fetch-retry/test/integration/index.js +0 -212
- package/node_modules/fetch-retry/test/integration/mock-api/index.js +0 -42
- package/node_modules/fetch-retry/test/unit/index.js +0 -1169
- package/node_modules/ssh2/lib/protocol/crypto/build/Release/.deps/Release/obj.target/sshcrypto/src/binding.o.d +0 -265
- package/node_modules/ssh2/lib/protocol/crypto/build/Release/.deps/Release/obj.target/sshcrypto.node.d +0 -1
- package/node_modules/ssh2/lib/protocol/crypto/build/Release/.deps/Release/sshcrypto.node.d +0 -1
- package/node_modules/ssh2/lib/protocol/crypto/build/Release/obj.target/sshcrypto/src/binding.o +0 -0
- package/node_modules/ssh2/lib/protocol/crypto/build/Release/obj.target/sshcrypto.node +0 -0
- package/node_modules/ssh2/lib/protocol/crypto/build/Release/sshcrypto.node +0 -0
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var node_child_process = require('node:child_process');
|
|
6
|
-
var promises = require('node:fs/promises');
|
|
7
|
-
var node_os = require('node:os');
|
|
8
|
-
var node_path = require('node:path');
|
|
9
|
-
var node_process = require('node:process');
|
|
10
|
-
var node_util = require('node:util');
|
|
11
|
-
|
|
12
|
-
class InvalidPathError extends Error {
|
|
13
|
-
constructor(message) {
|
|
14
|
-
super(message);
|
|
15
|
-
this.name = 'InvalidPathError';
|
|
16
|
-
// Set the prototype explicitly.
|
|
17
|
-
Object.setPrototypeOf(this, InvalidPathError.prototype);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
class NoMatchError extends Error {
|
|
22
|
-
constructor(message) {
|
|
23
|
-
super(message);
|
|
24
|
-
this.name = 'NoMatchError';
|
|
25
|
-
// Set the prototype explicitly.
|
|
26
|
-
Object.setPrototypeOf(this, NoMatchError.prototype);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Tells if directory exists
|
|
32
|
-
*
|
|
33
|
-
* @param directoryPath - The file/folder path
|
|
34
|
-
* @param dependencies - Dependencies container
|
|
35
|
-
*/
|
|
36
|
-
async function isDirectoryExisting(directoryPath, dependencies) {
|
|
37
|
-
try {
|
|
38
|
-
await dependencies.fsAccess(directoryPath);
|
|
39
|
-
return Promise.resolve(true);
|
|
40
|
-
}
|
|
41
|
-
catch (error) {
|
|
42
|
-
return Promise.resolve(false);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Get the first existing parent path
|
|
48
|
-
*
|
|
49
|
-
* @param directoryPath - The file/folder path from where we want to know disk space
|
|
50
|
-
* @param dependencies - Dependencies container
|
|
51
|
-
*/
|
|
52
|
-
async function getFirstExistingParentPath(directoryPath, dependencies) {
|
|
53
|
-
let parentDirectoryPath = directoryPath;
|
|
54
|
-
let parentDirectoryFound = await isDirectoryExisting(parentDirectoryPath, dependencies);
|
|
55
|
-
while (!parentDirectoryFound) {
|
|
56
|
-
parentDirectoryPath = dependencies.pathNormalize(parentDirectoryPath + '/..');
|
|
57
|
-
parentDirectoryFound = await isDirectoryExisting(parentDirectoryPath, dependencies);
|
|
58
|
-
}
|
|
59
|
-
return parentDirectoryPath;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Tell if PowerShell 3 is available based on Windows version
|
|
64
|
-
*
|
|
65
|
-
* Note: 6.* is Windows 7
|
|
66
|
-
* Note: PowerShell 3 is natively available since Windows 8
|
|
67
|
-
*
|
|
68
|
-
* @param dependencies - Dependencies Injection Container
|
|
69
|
-
*/
|
|
70
|
-
async function hasPowerShell3(dependencies) {
|
|
71
|
-
const major = parseInt(dependencies.release.split('.')[0], 10);
|
|
72
|
-
if (major <= 6) {
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
try {
|
|
76
|
-
await dependencies.cpExecFile('where', ['powershell'], { windowsHide: true });
|
|
77
|
-
return true;
|
|
78
|
-
}
|
|
79
|
-
catch (error) {
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Check disk space
|
|
86
|
-
*
|
|
87
|
-
* @param directoryPath - The file/folder path from where we want to know disk space
|
|
88
|
-
* @param dependencies - Dependencies container
|
|
89
|
-
*/
|
|
90
|
-
function checkDiskSpace(directoryPath, dependencies = {
|
|
91
|
-
platform: node_process.platform,
|
|
92
|
-
release: node_os.release(),
|
|
93
|
-
fsAccess: promises.access,
|
|
94
|
-
pathNormalize: node_path.normalize,
|
|
95
|
-
pathSep: node_path.sep,
|
|
96
|
-
cpExecFile: node_util.promisify(node_child_process.execFile),
|
|
97
|
-
}) {
|
|
98
|
-
// Note: This function contains other functions in order
|
|
99
|
-
// to wrap them in a common context and make unit tests easier
|
|
100
|
-
/**
|
|
101
|
-
* Maps command output to a normalized object {diskPath, free, size}
|
|
102
|
-
*
|
|
103
|
-
* @param stdout - The command output
|
|
104
|
-
* @param filter - To filter drives (only used for win32)
|
|
105
|
-
* @param mapping - Map between column index and normalized column name
|
|
106
|
-
* @param coefficient - The size coefficient to get bytes instead of kB
|
|
107
|
-
*/
|
|
108
|
-
function mapOutput(stdout, filter, mapping, coefficient) {
|
|
109
|
-
const parsed = stdout
|
|
110
|
-
.split('\n') // Split lines
|
|
111
|
-
.map(line => line.trim()) // Trim all lines
|
|
112
|
-
.filter(line => line.length !== 0) // Remove empty lines
|
|
113
|
-
.slice(1) // Remove header
|
|
114
|
-
.map(line => line.split(/\s+(?=[\d/])/)); // Split on spaces to get columns
|
|
115
|
-
const filtered = parsed.filter(filter);
|
|
116
|
-
if (filtered.length === 0) {
|
|
117
|
-
throw new NoMatchError();
|
|
118
|
-
}
|
|
119
|
-
const diskData = filtered[0];
|
|
120
|
-
return {
|
|
121
|
-
diskPath: diskData[mapping.diskPath],
|
|
122
|
-
free: parseInt(diskData[mapping.free], 10) * coefficient,
|
|
123
|
-
size: parseInt(diskData[mapping.size], 10) * coefficient,
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Run the command and do common things between win32 and unix
|
|
128
|
-
*
|
|
129
|
-
* @param cmd - The command to execute
|
|
130
|
-
* @param filter - To filter drives (only used for win32)
|
|
131
|
-
* @param mapping - Map between column index and normalized column name
|
|
132
|
-
* @param coefficient - The size coefficient to get bytes instead of kB
|
|
133
|
-
*/
|
|
134
|
-
async function check(cmd, filter, mapping, coefficient = 1) {
|
|
135
|
-
const [file, ...args] = cmd;
|
|
136
|
-
/* istanbul ignore if */
|
|
137
|
-
if (file === undefined) {
|
|
138
|
-
return Promise.reject(new Error('cmd must contain at least one item'));
|
|
139
|
-
}
|
|
140
|
-
try {
|
|
141
|
-
const { stdout } = await dependencies.cpExecFile(file, args, { windowsHide: true });
|
|
142
|
-
return mapOutput(stdout, filter, mapping, coefficient);
|
|
143
|
-
}
|
|
144
|
-
catch (error) {
|
|
145
|
-
return Promise.reject(error);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Build the check call for win32
|
|
150
|
-
*
|
|
151
|
-
* @param directoryPath - The file/folder path from where we want to know disk space
|
|
152
|
-
*/
|
|
153
|
-
async function checkWin32(directoryPath) {
|
|
154
|
-
if (directoryPath.charAt(1) !== ':') {
|
|
155
|
-
return Promise.reject(new InvalidPathError(`The following path is invalid (should be X:\\...): ${directoryPath}`));
|
|
156
|
-
}
|
|
157
|
-
const powershellCmd = [
|
|
158
|
-
'powershell',
|
|
159
|
-
'Get-CimInstance -ClassName Win32_LogicalDisk | Select-Object Caption, FreeSpace, Size',
|
|
160
|
-
];
|
|
161
|
-
const wmicCmd = [
|
|
162
|
-
'wmic',
|
|
163
|
-
'logicaldisk',
|
|
164
|
-
'get',
|
|
165
|
-
'size,freespace,caption',
|
|
166
|
-
];
|
|
167
|
-
const cmd = await hasPowerShell3(dependencies) ? powershellCmd : wmicCmd;
|
|
168
|
-
return check(cmd, driveData => {
|
|
169
|
-
// Only get the drive which match the path
|
|
170
|
-
const driveLetter = driveData[0];
|
|
171
|
-
return directoryPath.toUpperCase().startsWith(driveLetter.toUpperCase());
|
|
172
|
-
}, {
|
|
173
|
-
diskPath: 0,
|
|
174
|
-
free: 1,
|
|
175
|
-
size: 2,
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Build the check call for unix
|
|
180
|
-
*
|
|
181
|
-
* @param directoryPath - The file/folder path from where we want to know disk space
|
|
182
|
-
*/
|
|
183
|
-
async function checkUnix(directoryPath) {
|
|
184
|
-
if (!dependencies.pathNormalize(directoryPath).startsWith(dependencies.pathSep)) {
|
|
185
|
-
return Promise.reject(new InvalidPathError(`The following path is invalid (should start by ${dependencies.pathSep}): ${directoryPath}`));
|
|
186
|
-
}
|
|
187
|
-
const pathToCheck = await getFirstExistingParentPath(directoryPath, dependencies);
|
|
188
|
-
return check([
|
|
189
|
-
'df',
|
|
190
|
-
'-Pk',
|
|
191
|
-
'--',
|
|
192
|
-
pathToCheck,
|
|
193
|
-
], () => true, // We should only get one line, so we did not need to filter
|
|
194
|
-
{
|
|
195
|
-
diskPath: 5,
|
|
196
|
-
free: 3,
|
|
197
|
-
size: 1,
|
|
198
|
-
}, 1024);
|
|
199
|
-
}
|
|
200
|
-
// Call the right check depending on the OS
|
|
201
|
-
if (dependencies.platform === 'win32') {
|
|
202
|
-
return checkWin32(directoryPath);
|
|
203
|
-
}
|
|
204
|
-
return checkUnix(directoryPath);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
exports.InvalidPathError = InvalidPathError;
|
|
208
|
-
exports.NoMatchError = NoMatchError;
|
|
209
|
-
exports.default = checkDiskSpace;
|
|
210
|
-
exports.getFirstExistingParentPath = getFirstExistingParentPath;
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { access } from 'node:fs/promises';
|
|
2
|
-
import { normalize, sep } from 'node:path';
|
|
3
|
-
|
|
4
|
-
declare class InvalidPathError extends Error {
|
|
5
|
-
name: string;
|
|
6
|
-
constructor(message?: string);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
declare class NoMatchError extends Error {
|
|
10
|
-
name: string;
|
|
11
|
-
constructor(message?: string);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
type Dependencies = {
|
|
15
|
-
platform: NodeJS.Platform;
|
|
16
|
-
release: string;
|
|
17
|
-
fsAccess: typeof access;
|
|
18
|
-
pathNormalize: typeof normalize;
|
|
19
|
-
pathSep: typeof sep;
|
|
20
|
-
cpExecFile: (file: string, args: ReadonlyArray<string> | undefined | null, options: {
|
|
21
|
-
windowsHide: true;
|
|
22
|
-
}) => Promise<{
|
|
23
|
-
stdout: string;
|
|
24
|
-
stderr: string;
|
|
25
|
-
}>;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Get the first existing parent path
|
|
30
|
-
*
|
|
31
|
-
* @param directoryPath - The file/folder path from where we want to know disk space
|
|
32
|
-
* @param dependencies - Dependencies container
|
|
33
|
-
*/
|
|
34
|
-
declare function getFirstExistingParentPath(directoryPath: string, dependencies: Dependencies): Promise<string>;
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* `free` and `size` are in bytes
|
|
38
|
-
*/
|
|
39
|
-
type DiskSpace = {
|
|
40
|
-
diskPath: string;
|
|
41
|
-
free: number;
|
|
42
|
-
size: number;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Check disk space
|
|
47
|
-
*
|
|
48
|
-
* @param directoryPath - The file/folder path from where we want to know disk space
|
|
49
|
-
* @param dependencies - Dependencies container
|
|
50
|
-
*/
|
|
51
|
-
declare function checkDiskSpace(directoryPath: string, dependencies?: Dependencies): Promise<DiskSpace>;
|
|
52
|
-
|
|
53
|
-
export { Dependencies, DiskSpace, InvalidPathError, NoMatchError, checkDiskSpace as default, getFirstExistingParentPath };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
*.d.ts
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
env:
|
|
2
|
-
browser: true
|
|
3
|
-
commonjs: true
|
|
4
|
-
es6: false
|
|
5
|
-
extends: 'eslint:recommended'
|
|
6
|
-
parserOptions:
|
|
7
|
-
ecmaVersion: 5
|
|
8
|
-
rules:
|
|
9
|
-
indent:
|
|
10
|
-
- warn
|
|
11
|
-
- 2
|
|
12
|
-
linebreak-style:
|
|
13
|
-
- warn
|
|
14
|
-
- unix
|
|
15
|
-
quotes:
|
|
16
|
-
- warn
|
|
17
|
-
- single
|
|
18
|
-
semi:
|
|
19
|
-
- warn
|
|
20
|
-
- always
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
|
|
2
|
-
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
|
|
3
|
-
|
|
4
|
-
name: Node.js CI
|
|
5
|
-
|
|
6
|
-
on:
|
|
7
|
-
push:
|
|
8
|
-
branches: [ "master" ]
|
|
9
|
-
pull_request:
|
|
10
|
-
branches: [ "master" ]
|
|
11
|
-
|
|
12
|
-
jobs:
|
|
13
|
-
build:
|
|
14
|
-
|
|
15
|
-
runs-on: ubuntu-latest
|
|
16
|
-
|
|
17
|
-
strategy:
|
|
18
|
-
matrix:
|
|
19
|
-
node-version: [14.x, 16.x, 18.x]
|
|
20
|
-
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
|
|
21
|
-
|
|
22
|
-
steps:
|
|
23
|
-
- uses: actions/checkout@v3
|
|
24
|
-
- name: Use Node.js ${{ matrix.node-version }}
|
|
25
|
-
uses: actions/setup-node@v3
|
|
26
|
-
with:
|
|
27
|
-
node-version: ${{ matrix.node-version }}
|
|
28
|
-
cache: 'npm'
|
|
29
|
-
- run: npm install # dev-dependencies are needed in order to run tests and for Rollup
|
|
30
|
-
- run: npm run build --if-present
|
|
31
|
-
- run: npm test
|
|
32
|
-
- run: npm ci
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"include": [
|
|
3
|
-
"**/*.js"
|
|
4
|
-
],
|
|
5
|
-
"exclude": [
|
|
6
|
-
"coverage/**",
|
|
7
|
-
"test/**",
|
|
8
|
-
"test{,-*}.js",
|
|
9
|
-
"**/*.test.js",
|
|
10
|
-
"**/__tests__/**",
|
|
11
|
-
"**/node_modules/**",
|
|
12
|
-
"**/*.spec.js"
|
|
13
|
-
],
|
|
14
|
-
"reporter": [
|
|
15
|
-
"lcov",
|
|
16
|
-
"text"
|
|
17
|
-
],
|
|
18
|
-
"check-coverage": true,
|
|
19
|
-
"per-file": false,
|
|
20
|
-
"statements": 100,
|
|
21
|
-
"branches": 100,
|
|
22
|
-
"functions": 100,
|
|
23
|
-
"lines": 100
|
|
24
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2016 Jon K. Bernhardsen
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
# fetch-retry
|
|
2
|
-
|
|
3
|
-
Adds retry functionality to the [Fetch](https://fetch.spec.whatwg.org/) API.
|
|
4
|
-
|
|
5
|
-
It wraps any `fetch` API package (eg: [isomorphic-fetch](https://github.com/matthew-andrews/isomorphic-fetch), [cross-fetch](https://github.com/lquixada/cross-fetch), [isomorphic-unfetch](https://github.com/developit/unfetch), or [Node.js native's fetch implementation](https://nodejs.org/dist/latest-v18.x/docs/api/globals.html#fetch)) and retries requests that fail due to network issues. It can also be configured to retry requests on specific HTTP status codes.
|
|
6
|
-
|
|
7
|
-
[](https://github.com/jonbern/fetch-retry/actions/workflows/node.js.yml)
|
|
8
|
-
|
|
9
|
-
## npm package
|
|
10
|
-
|
|
11
|
-
```javascript
|
|
12
|
-
npm install fetch-retry --save
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## Example
|
|
16
|
-
`fetch-retry` is used the same way as `fetch`, but also accepts `retries`, `retryDelay`, and `retryOn` on the `options` object.
|
|
17
|
-
|
|
18
|
-
These properties are optional, and unless different defaults have been specified when requiring `fetch-retry`, these will default to 3 retries, with a 1000ms retry delay, and to only retry on network errors.
|
|
19
|
-
|
|
20
|
-
```javascript
|
|
21
|
-
const originalFetch = require('isomorphic-fetch');
|
|
22
|
-
const fetch = require('fetch-retry')(originalFetch);
|
|
23
|
-
|
|
24
|
-
// fetch-retry can also wrap Node.js's native fetch API implementation:
|
|
25
|
-
const fetch = require('fetch-retry')(global.fetch);
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
```javascript
|
|
29
|
-
fetch(url, {
|
|
30
|
-
retries: 3,
|
|
31
|
-
retryDelay: 1000
|
|
32
|
-
})
|
|
33
|
-
.then(function(response) {
|
|
34
|
-
return response.json();
|
|
35
|
-
})
|
|
36
|
-
.then(function(json) {
|
|
37
|
-
// do something with the result
|
|
38
|
-
console.log(json);
|
|
39
|
-
});
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
or passing your own defaults:
|
|
43
|
-
|
|
44
|
-
```javascript
|
|
45
|
-
const originalFetch = require('isomorphic-fetch');
|
|
46
|
-
const fetch = require('fetch-retry')(originalFetch, {
|
|
47
|
-
retries: 5,
|
|
48
|
-
retryDelay: 800
|
|
49
|
-
});
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
> `fetch-retry` uses promises and requires you to polyfill the Promise API in order to support Internet Explorer.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
## Example: Exponential backoff
|
|
56
|
-
The default behavior of `fetch-retry` is to wait a fixed amount of time between attempts, but it is also possible to customize this by passing a function as the `retryDelay` option. The function is supplied three arguments: `attempt` (starting at 0), `error` (in case of a network error), and `response`. It must return a number indicating the delay.
|
|
57
|
-
|
|
58
|
-
```javascript
|
|
59
|
-
fetch(url, {
|
|
60
|
-
retryDelay: function(attempt, error, response) {
|
|
61
|
-
return Math.pow(2, attempt) * 1000; // 1000, 2000, 4000
|
|
62
|
-
}
|
|
63
|
-
}).then(function(response) {
|
|
64
|
-
return response.json();
|
|
65
|
-
}).then(function(json) {
|
|
66
|
-
// do something with the result
|
|
67
|
-
console.log(json);
|
|
68
|
-
});
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
## Example: Retry on 503 (Service Unavailable)
|
|
72
|
-
The default behavior of `fetch-retry` is to only retry requests on network related issues, but it is also possible to configure it to retry on specific HTTP status codes. This is done by using the `retryOn` property, which expects an array of HTTP status codes.
|
|
73
|
-
|
|
74
|
-
```javascript
|
|
75
|
-
fetch(url, {
|
|
76
|
-
retryOn: [503]
|
|
77
|
-
})
|
|
78
|
-
.then(function(response) {
|
|
79
|
-
return response.json();
|
|
80
|
-
})
|
|
81
|
-
.then(function(json) {
|
|
82
|
-
// do something with the result
|
|
83
|
-
console.log(json);
|
|
84
|
-
});
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
## Example: Retry custom behavior
|
|
88
|
-
The `retryOn` option may also be specified as a function, in which case it will be supplied three arguments: `attempt` (starting at 0), `error` (in case of a network error), and `response`. Return a truthy value from this function in order to trigger a retry, any falsy value will result in the call to fetch either resolving (in case the last attempt resulted in a response), or rejecting (in case the last attempt resulted in an error).
|
|
89
|
-
|
|
90
|
-
```javascript
|
|
91
|
-
fetch(url, {
|
|
92
|
-
retryOn: function(attempt, error, response) {
|
|
93
|
-
// retry on any network error, or 4xx or 5xx status codes
|
|
94
|
-
if (error !== null || response.status >= 400) {
|
|
95
|
-
console.log(`retrying, attempt number ${attempt + 1}`);
|
|
96
|
-
return true;
|
|
97
|
-
}
|
|
98
|
-
})
|
|
99
|
-
.then(function(response) {
|
|
100
|
-
return response.json();
|
|
101
|
-
}).then(function(json) {
|
|
102
|
-
// do something with the result
|
|
103
|
-
console.log(json);
|
|
104
|
-
});
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
## Example: Retry custom behavior with async
|
|
108
|
-
The `retryOn` option may also be used with async and await for calling asyncronous functions:
|
|
109
|
-
|
|
110
|
-
```javascript
|
|
111
|
-
fetch(url, {
|
|
112
|
-
retryOn: async function(attempt, error, response) {
|
|
113
|
-
if (attempt > 3) return false;
|
|
114
|
-
|
|
115
|
-
if (error !== null) {
|
|
116
|
-
var json = await response.json();
|
|
117
|
-
if (json.property !== undefined) {
|
|
118
|
-
return true;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
})
|
|
122
|
-
.then(function(response) {
|
|
123
|
-
return response.json();
|
|
124
|
-
}).then(function(json) {
|
|
125
|
-
// do something with the result
|
|
126
|
-
console.log(json);
|
|
127
|
-
});
|
|
128
|
-
```
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.fetchRetry = factory());
|
|
5
|
-
})(this, (function () { 'use strict';
|
|
6
|
-
|
|
7
|
-
var fetchRetry = function (fetch, defaults) {
|
|
8
|
-
defaults = defaults || {};
|
|
9
|
-
if (typeof fetch !== 'function') {
|
|
10
|
-
throw new ArgumentError('fetch must be a function');
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
if (typeof defaults !== 'object') {
|
|
14
|
-
throw new ArgumentError('defaults must be an object');
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
if (defaults.retries !== undefined && !isPositiveInteger(defaults.retries)) {
|
|
18
|
-
throw new ArgumentError('retries must be a positive integer');
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
if (defaults.retryDelay !== undefined && !isPositiveInteger(defaults.retryDelay) && typeof defaults.retryDelay !== 'function') {
|
|
22
|
-
throw new ArgumentError('retryDelay must be a positive integer or a function returning a positive integer');
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (defaults.retryOn !== undefined && !Array.isArray(defaults.retryOn) && typeof defaults.retryOn !== 'function') {
|
|
26
|
-
throw new ArgumentError('retryOn property expects an array or function');
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
var baseDefaults = {
|
|
30
|
-
retries: 3,
|
|
31
|
-
retryDelay: 1000,
|
|
32
|
-
retryOn: [],
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
defaults = Object.assign(baseDefaults, defaults);
|
|
36
|
-
|
|
37
|
-
return function fetchRetry(input, init) {
|
|
38
|
-
var retries = defaults.retries;
|
|
39
|
-
var retryDelay = defaults.retryDelay;
|
|
40
|
-
var retryOn = defaults.retryOn;
|
|
41
|
-
|
|
42
|
-
if (init && init.retries !== undefined) {
|
|
43
|
-
if (isPositiveInteger(init.retries)) {
|
|
44
|
-
retries = init.retries;
|
|
45
|
-
} else {
|
|
46
|
-
throw new ArgumentError('retries must be a positive integer');
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (init && init.retryDelay !== undefined) {
|
|
51
|
-
if (isPositiveInteger(init.retryDelay) || (typeof init.retryDelay === 'function')) {
|
|
52
|
-
retryDelay = init.retryDelay;
|
|
53
|
-
} else {
|
|
54
|
-
throw new ArgumentError('retryDelay must be a positive integer or a function returning a positive integer');
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (init && init.retryOn) {
|
|
59
|
-
if (Array.isArray(init.retryOn) || (typeof init.retryOn === 'function')) {
|
|
60
|
-
retryOn = init.retryOn;
|
|
61
|
-
} else {
|
|
62
|
-
throw new ArgumentError('retryOn property expects an array or function');
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// eslint-disable-next-line no-undef
|
|
67
|
-
return new Promise(function (resolve, reject) {
|
|
68
|
-
var wrappedFetch = function (attempt) {
|
|
69
|
-
// As of node 18, this is no longer needed since node comes with native support for fetch:
|
|
70
|
-
/* istanbul ignore next */
|
|
71
|
-
var _input =
|
|
72
|
-
typeof Request !== 'undefined' && input instanceof Request
|
|
73
|
-
? input.clone()
|
|
74
|
-
: input;
|
|
75
|
-
fetch(_input, init)
|
|
76
|
-
.then(function (response) {
|
|
77
|
-
if (Array.isArray(retryOn) && retryOn.indexOf(response.status) === -1) {
|
|
78
|
-
resolve(response);
|
|
79
|
-
} else if (typeof retryOn === 'function') {
|
|
80
|
-
try {
|
|
81
|
-
// eslint-disable-next-line no-undef
|
|
82
|
-
return Promise.resolve(retryOn(attempt, null, response))
|
|
83
|
-
.then(function (retryOnResponse) {
|
|
84
|
-
if(retryOnResponse) {
|
|
85
|
-
retry(attempt, null, response);
|
|
86
|
-
} else {
|
|
87
|
-
resolve(response);
|
|
88
|
-
}
|
|
89
|
-
}).catch(reject);
|
|
90
|
-
} catch (error) {
|
|
91
|
-
reject(error);
|
|
92
|
-
}
|
|
93
|
-
} else {
|
|
94
|
-
if (attempt < retries) {
|
|
95
|
-
retry(attempt, null, response);
|
|
96
|
-
} else {
|
|
97
|
-
resolve(response);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
})
|
|
101
|
-
.catch(function (error) {
|
|
102
|
-
if (typeof retryOn === 'function') {
|
|
103
|
-
try {
|
|
104
|
-
// eslint-disable-next-line no-undef
|
|
105
|
-
Promise.resolve(retryOn(attempt, error, null))
|
|
106
|
-
.then(function (retryOnResponse) {
|
|
107
|
-
if(retryOnResponse) {
|
|
108
|
-
retry(attempt, error, null);
|
|
109
|
-
} else {
|
|
110
|
-
reject(error);
|
|
111
|
-
}
|
|
112
|
-
})
|
|
113
|
-
.catch(function(error) {
|
|
114
|
-
reject(error);
|
|
115
|
-
});
|
|
116
|
-
} catch(error) {
|
|
117
|
-
reject(error);
|
|
118
|
-
}
|
|
119
|
-
} else if (attempt < retries) {
|
|
120
|
-
retry(attempt, error, null);
|
|
121
|
-
} else {
|
|
122
|
-
reject(error);
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
function retry(attempt, error, response) {
|
|
128
|
-
var delay = (typeof retryDelay === 'function') ?
|
|
129
|
-
retryDelay(attempt, error, response) : retryDelay;
|
|
130
|
-
setTimeout(function () {
|
|
131
|
-
wrappedFetch(++attempt);
|
|
132
|
-
}, delay);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
wrappedFetch(0);
|
|
136
|
-
});
|
|
137
|
-
};
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
function isPositiveInteger(value) {
|
|
141
|
-
return Number.isInteger(value) && value >= 0;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
function ArgumentError(message) {
|
|
145
|
-
this.name = 'ArgumentError';
|
|
146
|
-
this.message = message;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
return fetchRetry;
|
|
150
|
-
|
|
151
|
-
}));
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
declare module 'fetch-retry' {
|
|
2
|
-
export type FetchLibrary = (input: any, init?: any) => Promise<any>;
|
|
3
|
-
|
|
4
|
-
export type RequestDelayFunction<F extends FetchLibrary> = (
|
|
5
|
-
attempt: number,
|
|
6
|
-
error: Error | null,
|
|
7
|
-
response: Awaited<ReturnType<F>> | null,
|
|
8
|
-
) => number;
|
|
9
|
-
|
|
10
|
-
export type RequestRetryOnFunction<F extends FetchLibrary> = (
|
|
11
|
-
attempt: number,
|
|
12
|
-
error: Error | null,
|
|
13
|
-
response: Awaited<ReturnType<F>> | null,
|
|
14
|
-
) => boolean | Promise<boolean>;
|
|
15
|
-
|
|
16
|
-
export type RequestInitRetryParams<F extends FetchLibrary> = {
|
|
17
|
-
retries?: number;
|
|
18
|
-
retryDelay?: number | RequestDelayFunction<F>;
|
|
19
|
-
retryOn?: number[] | RequestRetryOnFunction<F>;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export type RequestInitWithRetry<F extends FetchLibrary> = Parameters<F>[1] &
|
|
23
|
-
RequestInitRetryParams<F>;
|
|
24
|
-
|
|
25
|
-
export default function fetchBuilder<F extends FetchLibrary>(
|
|
26
|
-
fetch: F,
|
|
27
|
-
defaults?: RequestInitRetryParams<F>,
|
|
28
|
-
): (input: Parameters<F>[0], init?: RequestInitWithRetry<F>) => ReturnType<F>;
|
|
29
|
-
}
|