wrangler 2.1.0 → 2.1.1
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/package.json +2 -1
- package/src/__tests__/helpers/mock-cfetch.ts +35 -15
- package/src/__tests__/helpers/msw/handlers/index.ts +13 -0
- package/src/__tests__/helpers/msw/handlers/namespaces.ts +104 -0
- package/src/__tests__/helpers/msw/handlers/oauth.ts +36 -0
- package/src/__tests__/helpers/msw/handlers/r2.ts +80 -0
- package/src/__tests__/helpers/msw/handlers/user.ts +63 -0
- package/src/__tests__/helpers/msw/index.ts +4 -0
- package/src/__tests__/index.test.ts +2 -0
- package/src/__tests__/jest.setup.ts +16 -0
- package/src/__tests__/publish.test.ts +52 -0
- package/src/__tests__/r2.test.ts +128 -93
- package/src/__tests__/secret.test.ts +78 -0
- package/src/__tests__/whoami.test.tsx +49 -64
- package/src/index.tsx +90 -0
- package/src/publish.ts +21 -13
- package/wrangler-dist/cli.js +132 -28
package/src/publish.ts
CHANGED
|
@@ -220,21 +220,29 @@ export default async function publish(props: Props): Promise<void> {
|
|
|
220
220
|
// TODO: warn if git/hg has uncommitted changes
|
|
221
221
|
const { config, accountId, name } = props;
|
|
222
222
|
if (accountId && name) {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
default_environment
|
|
228
|
-
|
|
223
|
+
try {
|
|
224
|
+
const serviceMetaData = await fetchResult(
|
|
225
|
+
`/accounts/${accountId}/workers/services/${name}`
|
|
226
|
+
);
|
|
227
|
+
const { default_environment } = serviceMetaData as {
|
|
228
|
+
default_environment: {
|
|
229
|
+
script: { last_deployed_from: "dash" | "wrangler" | "api" };
|
|
230
|
+
};
|
|
229
231
|
};
|
|
230
|
-
};
|
|
231
232
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
233
|
+
if (
|
|
234
|
+
(await fromDashMessagePrompt(
|
|
235
|
+
default_environment.script.last_deployed_from
|
|
236
|
+
)) === false
|
|
237
|
+
)
|
|
238
|
+
return;
|
|
239
|
+
} catch (e) {
|
|
240
|
+
// code: 10090, message: workers.api.error.service_not_found
|
|
241
|
+
// is thrown from the above fetchResult on the first publish of a Worker
|
|
242
|
+
if ((e as { code?: number }).code !== 10090) {
|
|
243
|
+
logger.error(e);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
238
246
|
}
|
|
239
247
|
|
|
240
248
|
if (!(props.compatibilityDate || config.compatibility_date)) {
|
package/wrangler-dist/cli.js
CHANGED
|
@@ -94180,6 +94180,7 @@ var require_get_intrinsic = __commonJS({
|
|
|
94180
94180
|
var $spliceApply = bind.call(Function.apply, Array.prototype.splice);
|
|
94181
94181
|
var $replace = bind.call(Function.call, String.prototype.replace);
|
|
94182
94182
|
var $strSlice = bind.call(Function.call, String.prototype.slice);
|
|
94183
|
+
var $exec = bind.call(Function.call, RegExp.prototype.exec);
|
|
94183
94184
|
var rePropName = /[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g;
|
|
94184
94185
|
var reEscapeChar = /\\(\\)?/g;
|
|
94185
94186
|
var stringToPath = function stringToPath2(string) {
|
|
@@ -94226,6 +94227,9 @@ var require_get_intrinsic = __commonJS({
|
|
|
94226
94227
|
if (arguments.length > 1 && typeof allowMissing !== "boolean") {
|
|
94227
94228
|
throw new $TypeError('"allowMissing" argument must be a boolean');
|
|
94228
94229
|
}
|
|
94230
|
+
if ($exec(/^%?[^%]*%?$/g, name) === null) {
|
|
94231
|
+
throw new $SyntaxError("`%` may not be present anywhere but at the beginning and end of the intrinsic name");
|
|
94232
|
+
}
|
|
94229
94233
|
var parts = stringToPath(name);
|
|
94230
94234
|
var intrinsicBaseName = parts.length > 0 ? parts[0] : "";
|
|
94231
94235
|
var intrinsic = getBaseIntrinsic("%" + intrinsicBaseName + "%", allowMissing);
|
|
@@ -94406,8 +94410,9 @@ var require_object_inspect = __commonJS({
|
|
|
94406
94410
|
}
|
|
94407
94411
|
return $replace.call(str, sepRegex, "$&_");
|
|
94408
94412
|
}
|
|
94409
|
-
var
|
|
94410
|
-
var
|
|
94413
|
+
var utilInspect2 = require_util_inspect();
|
|
94414
|
+
var inspectCustom = utilInspect2.custom;
|
|
94415
|
+
var inspectSymbol = isSymbol(inspectCustom) ? inspectCustom : null;
|
|
94411
94416
|
module2.exports = function inspect_(obj, options, depth, seen) {
|
|
94412
94417
|
var opts = options || {};
|
|
94413
94418
|
if (has(opts, "quoteStyle") && (opts.quoteStyle !== "single" && opts.quoteStyle !== "double")) {
|
|
@@ -94479,7 +94484,7 @@ var require_object_inspect = __commonJS({
|
|
|
94479
94484
|
}
|
|
94480
94485
|
return inspect_(value, opts, depth + 1, seen);
|
|
94481
94486
|
}
|
|
94482
|
-
if (typeof obj === "function") {
|
|
94487
|
+
if (typeof obj === "function" && !isRegExp(obj)) {
|
|
94483
94488
|
var name = nameOf(obj);
|
|
94484
94489
|
var keys = arrObjKeys(obj, inspect2);
|
|
94485
94490
|
return "[Function" + (name ? ": " + name : " (anonymous)") + "]" + (keys.length > 0 ? " { " + $join.call(keys, ", ") + " }" : "");
|
|
@@ -94513,7 +94518,7 @@ var require_object_inspect = __commonJS({
|
|
|
94513
94518
|
}
|
|
94514
94519
|
if (isError(obj)) {
|
|
94515
94520
|
var parts = arrObjKeys(obj, inspect2);
|
|
94516
|
-
if ("cause" in obj && !isEnumerable.call(obj, "cause")) {
|
|
94521
|
+
if (!("cause" in Error.prototype) && "cause" in obj && !isEnumerable.call(obj, "cause")) {
|
|
94517
94522
|
return "{ [" + String(obj) + "] " + $join.call($concat.call("[cause]: " + inspect2(obj.cause), parts), ", ") + " }";
|
|
94518
94523
|
}
|
|
94519
94524
|
if (parts.length === 0) {
|
|
@@ -94522,8 +94527,8 @@ var require_object_inspect = __commonJS({
|
|
|
94522
94527
|
return "{ [" + String(obj) + "] " + $join.call(parts, ", ") + " }";
|
|
94523
94528
|
}
|
|
94524
94529
|
if (typeof obj === "object" && customInspect) {
|
|
94525
|
-
if (inspectSymbol && typeof obj[inspectSymbol] === "function") {
|
|
94526
|
-
return obj
|
|
94530
|
+
if (inspectSymbol && typeof obj[inspectSymbol] === "function" && utilInspect2) {
|
|
94531
|
+
return utilInspect2(obj, { depth: maxDepth - depth });
|
|
94527
94532
|
} else if (customInspect !== "symbol" && typeof obj.inspect === "function") {
|
|
94528
94533
|
return obj.inspect();
|
|
94529
94534
|
}
|
|
@@ -113039,6 +113044,38 @@ var require_object_keys = __commonJS({
|
|
|
113039
113044
|
}
|
|
113040
113045
|
});
|
|
113041
113046
|
|
|
113047
|
+
// ../../node_modules/has-property-descriptors/index.js
|
|
113048
|
+
var require_has_property_descriptors = __commonJS({
|
|
113049
|
+
"../../node_modules/has-property-descriptors/index.js"(exports2, module2) {
|
|
113050
|
+
"use strict";
|
|
113051
|
+
init_import_meta_url();
|
|
113052
|
+
var GetIntrinsic = require_get_intrinsic();
|
|
113053
|
+
var $defineProperty = GetIntrinsic("%Object.defineProperty%", true);
|
|
113054
|
+
var hasPropertyDescriptors = function hasPropertyDescriptors2() {
|
|
113055
|
+
if ($defineProperty) {
|
|
113056
|
+
try {
|
|
113057
|
+
$defineProperty({}, "a", { value: 1 });
|
|
113058
|
+
return true;
|
|
113059
|
+
} catch (e2) {
|
|
113060
|
+
return false;
|
|
113061
|
+
}
|
|
113062
|
+
}
|
|
113063
|
+
return false;
|
|
113064
|
+
};
|
|
113065
|
+
hasPropertyDescriptors.hasArrayLengthDefineBug = function hasArrayLengthDefineBug() {
|
|
113066
|
+
if (!hasPropertyDescriptors()) {
|
|
113067
|
+
return null;
|
|
113068
|
+
}
|
|
113069
|
+
try {
|
|
113070
|
+
return $defineProperty([], "length", { value: 1 }).length !== 1;
|
|
113071
|
+
} catch (e2) {
|
|
113072
|
+
return true;
|
|
113073
|
+
}
|
|
113074
|
+
};
|
|
113075
|
+
module2.exports = hasPropertyDescriptors;
|
|
113076
|
+
}
|
|
113077
|
+
});
|
|
113078
|
+
|
|
113042
113079
|
// ../../node_modules/define-properties/index.js
|
|
113043
113080
|
var require_define_properties = __commonJS({
|
|
113044
113081
|
"../../node_modules/define-properties/index.js"(exports2, module2) {
|
|
@@ -113052,19 +113089,8 @@ var require_define_properties = __commonJS({
|
|
|
113052
113089
|
var isFunction2 = function(fn) {
|
|
113053
113090
|
return typeof fn === "function" && toStr.call(fn) === "[object Function]";
|
|
113054
113091
|
};
|
|
113055
|
-
var
|
|
113056
|
-
|
|
113057
|
-
try {
|
|
113058
|
-
origDefineProperty(obj, "x", { enumerable: false, value: obj });
|
|
113059
|
-
for (var _2 in obj) {
|
|
113060
|
-
return false;
|
|
113061
|
-
}
|
|
113062
|
-
return obj.x === obj;
|
|
113063
|
-
} catch (e2) {
|
|
113064
|
-
return false;
|
|
113065
|
-
}
|
|
113066
|
-
};
|
|
113067
|
-
var supportsDescriptors = origDefineProperty && arePropertyDescriptorsSupported();
|
|
113092
|
+
var hasPropertyDescriptors = require_has_property_descriptors()();
|
|
113093
|
+
var supportsDescriptors = origDefineProperty && hasPropertyDescriptors;
|
|
113068
113094
|
var defineProperty2 = function(object, name, value, predicate) {
|
|
113069
113095
|
if (name in object && (!isFunction2(predicate) || !predicate())) {
|
|
113070
113096
|
return;
|
|
@@ -138648,7 +138674,7 @@ var import_websocket_server = __toESM(require_websocket_server2(), 1);
|
|
|
138648
138674
|
var wrapper_default = import_websocket.default;
|
|
138649
138675
|
|
|
138650
138676
|
// package.json
|
|
138651
|
-
var version = "2.1.
|
|
138677
|
+
var version = "2.1.1";
|
|
138652
138678
|
var package_default = {
|
|
138653
138679
|
name: "wrangler",
|
|
138654
138680
|
version,
|
|
@@ -138799,6 +138825,7 @@ var package_default = {
|
|
|
138799
138825
|
"jest-fetch-mock": "^3.0.3",
|
|
138800
138826
|
"jest-websocket-mock": "^2.3.0",
|
|
138801
138827
|
mime: "^3.0.0",
|
|
138828
|
+
msw: "^0.47.1",
|
|
138802
138829
|
open: "^8.4.0",
|
|
138803
138830
|
"p-queue": "^7.2.0",
|
|
138804
138831
|
"pretty-bytes": "^6.0.0",
|
|
@@ -151529,14 +151556,20 @@ Update them to point to this script instead?`;
|
|
|
151529
151556
|
async function publish(props) {
|
|
151530
151557
|
const { config, accountId, name } = props;
|
|
151531
151558
|
if (accountId && name) {
|
|
151532
|
-
|
|
151533
|
-
|
|
151534
|
-
|
|
151535
|
-
|
|
151536
|
-
|
|
151537
|
-
|
|
151538
|
-
|
|
151539
|
-
|
|
151559
|
+
try {
|
|
151560
|
+
const serviceMetaData = await fetchResult(
|
|
151561
|
+
`/accounts/${accountId}/workers/services/${name}`
|
|
151562
|
+
);
|
|
151563
|
+
const { default_environment } = serviceMetaData;
|
|
151564
|
+
if (await fromDashMessagePrompt(
|
|
151565
|
+
default_environment.script.last_deployed_from
|
|
151566
|
+
) === false)
|
|
151567
|
+
return;
|
|
151568
|
+
} catch (e2) {
|
|
151569
|
+
if (e2.code !== 10090) {
|
|
151570
|
+
logger.error(e2);
|
|
151571
|
+
}
|
|
151572
|
+
}
|
|
151540
151573
|
}
|
|
151541
151574
|
if (!(props.compatibilityDate || config.compatibility_date)) {
|
|
151542
151575
|
const compatibilityDateStr = `${new Date().getFullYear()}-${(new Date().getMonth() + 1 + "").padStart(2, "0")}-${(new Date().getDate() + "").padStart(2, "0")}`;
|
|
@@ -153741,6 +153774,77 @@ ${shouldDo}`);
|
|
|
153741
153774
|
);
|
|
153742
153775
|
}
|
|
153743
153776
|
);
|
|
153777
|
+
wrangler.command(
|
|
153778
|
+
"secret:bulk <json>",
|
|
153779
|
+
"\u{1F5C4}\uFE0F Bulk upload secrets for a Worker",
|
|
153780
|
+
(yargs) => {
|
|
153781
|
+
return yargs.positional("json", {
|
|
153782
|
+
describe: `The JSON file of key-value pairs to upload, in form {"key": value, ...}`,
|
|
153783
|
+
type: "string",
|
|
153784
|
+
demandOption: "true"
|
|
153785
|
+
}).option("name", {
|
|
153786
|
+
describe: "Name of the Worker",
|
|
153787
|
+
type: "string",
|
|
153788
|
+
requiresArg: true
|
|
153789
|
+
}).option("env", {
|
|
153790
|
+
type: "string",
|
|
153791
|
+
requiresArg: true,
|
|
153792
|
+
describe: "Binds the secret to the Worker of the specific environment.",
|
|
153793
|
+
alias: "e"
|
|
153794
|
+
});
|
|
153795
|
+
},
|
|
153796
|
+
async (secretBulkArgs) => {
|
|
153797
|
+
await printWranglerBanner();
|
|
153798
|
+
const config = readConfig(
|
|
153799
|
+
secretBulkArgs.config,
|
|
153800
|
+
secretBulkArgs
|
|
153801
|
+
);
|
|
153802
|
+
const scriptName = getLegacyScriptName(secretBulkArgs, config);
|
|
153803
|
+
if (!scriptName) {
|
|
153804
|
+
throw new Error(
|
|
153805
|
+
"Required Worker name missing. Please specify the Worker name in wrangler.toml, or pass it as an argument with `--name <worker-name>`"
|
|
153806
|
+
);
|
|
153807
|
+
}
|
|
153808
|
+
const accountId = await requireAuth(config);
|
|
153809
|
+
logger.log(
|
|
153810
|
+
`\u{1F300} Creating the secrets for the Worker "${scriptName}" ${secretBulkArgs.env && !isLegacyEnv(config) ? `(${secretBulkArgs.env})` : ""}`
|
|
153811
|
+
);
|
|
153812
|
+
const jsonFilePath = import_node_path32.default.resolve(secretBulkArgs.json);
|
|
153813
|
+
const content = parseJSON(
|
|
153814
|
+
readFileSync5(jsonFilePath),
|
|
153815
|
+
jsonFilePath
|
|
153816
|
+
);
|
|
153817
|
+
for (const key2 in content) {
|
|
153818
|
+
if (typeof content[key2] !== "string") {
|
|
153819
|
+
throw new Error(
|
|
153820
|
+
`The value for ${key2} in ${jsonFilePath} is not a string.`
|
|
153821
|
+
);
|
|
153822
|
+
}
|
|
153823
|
+
}
|
|
153824
|
+
const url3 = !secretBulkArgs.env || isLegacyEnv(config) ? `/accounts/${accountId}/workers/scripts/${scriptName}/secrets` : `/accounts/${accountId}/workers/services/${scriptName}/environments/${secretBulkArgs.env}/secrets`;
|
|
153825
|
+
await Promise.allSettled(
|
|
153826
|
+
Object.entries(content).map(async ([key2, value]) => {
|
|
153827
|
+
return fetchResult(url3, {
|
|
153828
|
+
method: "PUT",
|
|
153829
|
+
headers: { "Content-Type": "application/json" },
|
|
153830
|
+
body: JSON.stringify({
|
|
153831
|
+
name: key2,
|
|
153832
|
+
text: value,
|
|
153833
|
+
type: "secret_text"
|
|
153834
|
+
})
|
|
153835
|
+
}).then(() => {
|
|
153836
|
+
logger.log(`\u2728 Successfully created secret for key: ${key2}`);
|
|
153837
|
+
}).catch((e2) => {
|
|
153838
|
+
logger.error(
|
|
153839
|
+
`\u{1F6A8} Error uploading secret for key: ${key2}:
|
|
153840
|
+
${e2.message}`
|
|
153841
|
+
);
|
|
153842
|
+
});
|
|
153843
|
+
})
|
|
153844
|
+
);
|
|
153845
|
+
return logger.log("\u2728 Finished processing secrets JSON file");
|
|
153846
|
+
}
|
|
153847
|
+
);
|
|
153744
153848
|
wrangler.command(
|
|
153745
153849
|
"kv:namespace",
|
|
153746
153850
|
"\u{1F5C2}\uFE0F Interact with your Workers KV Namespaces",
|