wrangler 0.0.0-e6733a3 → 0.0.0-edc4b53
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 +1 -1
- package/src/__tests__/kv.test.ts +10 -2
- package/src/api/form_data.ts +1 -1
- package/src/cfetch/internal.ts +4 -8
- package/src/kv.tsx +18 -9
- package/src/sites.tsx +5 -1
- package/src/user.tsx +10 -8
- package/wrangler-dist/cli.js +17 -14
- package/wrangler-dist/cli.js.map +2 -2
package/package.json
CHANGED
package/src/__tests__/kv.test.ts
CHANGED
|
@@ -335,8 +335,16 @@ describe("wrangler", () => {
|
|
|
335
335
|
expect(namespaceId).toEqual(expectedNamespaceId);
|
|
336
336
|
expect(key).toEqual(expectedKey);
|
|
337
337
|
expect(body).toEqual(expectedValue);
|
|
338
|
-
|
|
339
|
-
|
|
338
|
+
if (expiration !== undefined) {
|
|
339
|
+
expect(query.get("expiration")).toEqual(`${expiration}`);
|
|
340
|
+
} else {
|
|
341
|
+
expect(query.has("expiration")).toBe(false);
|
|
342
|
+
}
|
|
343
|
+
if (expirationTtl) {
|
|
344
|
+
expect(query.get("expiration_ttl")).toEqual(`${expirationTtl}`);
|
|
345
|
+
} else {
|
|
346
|
+
expect(query.has("expiration_ttl")).toBe(false);
|
|
347
|
+
}
|
|
340
348
|
return null;
|
|
341
349
|
}
|
|
342
350
|
);
|
package/src/api/form_data.ts
CHANGED
|
@@ -23,7 +23,7 @@ export function toMimeType(type: CfModuleType): string {
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
function toModule(module: CfModule, entryType
|
|
26
|
+
function toModule(module: CfModule, entryType: CfModuleType): Blob {
|
|
27
27
|
const { type: moduleType, content } = module;
|
|
28
28
|
const type = toMimeType(moduleType ?? entryType);
|
|
29
29
|
|
package/src/cfetch/internal.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import fetch from "node-fetch";
|
|
2
|
-
import type { RequestInit
|
|
1
|
+
import fetch, { Headers } from "node-fetch";
|
|
2
|
+
import type { RequestInit } from "node-fetch";
|
|
3
3
|
import { getAPIToken, loginOrRefreshIfRequired } from "../user";
|
|
4
4
|
|
|
5
5
|
export const CF_API_BASE_URL =
|
|
@@ -21,7 +21,7 @@ export async function fetchInternal<ResponseType>(
|
|
|
21
21
|
): Promise<ResponseType> {
|
|
22
22
|
await requireLoggedIn();
|
|
23
23
|
const apiToken = requireApiToken();
|
|
24
|
-
const headers =
|
|
24
|
+
const headers = new Headers(init.headers);
|
|
25
25
|
addAuthorizationHeader(headers, apiToken);
|
|
26
26
|
|
|
27
27
|
const queryString = queryParams ? `?${queryParams.toString()}` : "";
|
|
@@ -55,11 +55,7 @@ function requireApiToken(): string {
|
|
|
55
55
|
return apiToken;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
function
|
|
59
|
-
return { ...headers };
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function addAuthorizationHeader(headers: HeadersInit, apiToken: string): void {
|
|
58
|
+
function addAuthorizationHeader(headers: Headers, apiToken: string): void {
|
|
63
59
|
if (headers["Authorization"]) {
|
|
64
60
|
throw new Error(
|
|
65
61
|
"The request already specifies an authorisation header - cannot add a new one."
|
package/src/kv.tsx
CHANGED
|
@@ -82,7 +82,7 @@ export interface NamespaceKeyInfo {
|
|
|
82
82
|
export async function listNamespaceKeys(
|
|
83
83
|
accountId: string,
|
|
84
84
|
namespaceId: string,
|
|
85
|
-
prefix
|
|
85
|
+
prefix = ""
|
|
86
86
|
) {
|
|
87
87
|
return await fetchListResult<NamespaceKeyInfo>(
|
|
88
88
|
`/accounts/${accountId}/storage/kv/namespaces/${namespaceId}/keys`,
|
|
@@ -98,15 +98,20 @@ export async function putKeyValue(
|
|
|
98
98
|
value: string,
|
|
99
99
|
args?: { expiration?: number; expiration_ttl?: number }
|
|
100
100
|
) {
|
|
101
|
+
let searchParams: URLSearchParams | undefined;
|
|
102
|
+
if (args) {
|
|
103
|
+
searchParams = new URLSearchParams();
|
|
104
|
+
if (args.expiration) {
|
|
105
|
+
searchParams.set("expiration", `${args.expiration}`);
|
|
106
|
+
}
|
|
107
|
+
if (args.expiration_ttl) {
|
|
108
|
+
searchParams.set("expiration_ttl", `${args.expiration_ttl}`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
101
111
|
return await fetchResult(
|
|
102
112
|
`/accounts/${accountId}/storage/kv/namespaces/${namespaceId}/values/${key}`,
|
|
103
113
|
{ method: "PUT", body: value },
|
|
104
|
-
|
|
105
|
-
? new URLSearchParams({
|
|
106
|
-
expiration: args.expiration?.toString(),
|
|
107
|
-
expiration_ttl: args.expiration_ttl?.toString(),
|
|
108
|
-
})
|
|
109
|
-
: undefined
|
|
114
|
+
searchParams
|
|
110
115
|
);
|
|
111
116
|
}
|
|
112
117
|
|
|
@@ -262,6 +267,10 @@ export function getNamespaceId({
|
|
|
262
267
|
/**
|
|
263
268
|
* KV namespace binding names must be valid JS identifiers.
|
|
264
269
|
*/
|
|
265
|
-
export function isValidNamespaceBinding(
|
|
266
|
-
|
|
270
|
+
export function isValidNamespaceBinding(
|
|
271
|
+
binding: string | undefined
|
|
272
|
+
): binding is string {
|
|
273
|
+
return (
|
|
274
|
+
typeof binding === "string" && /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(binding)
|
|
275
|
+
);
|
|
267
276
|
}
|
package/src/sites.tsx
CHANGED
|
@@ -89,7 +89,11 @@ export async function syncAssets(
|
|
|
89
89
|
);
|
|
90
90
|
|
|
91
91
|
const manifest = {};
|
|
92
|
-
const upload
|
|
92
|
+
const upload: {
|
|
93
|
+
key: string;
|
|
94
|
+
value: string;
|
|
95
|
+
base64: boolean;
|
|
96
|
+
}[] = [];
|
|
93
97
|
// TODO: this can be more efficient by parallelising
|
|
94
98
|
for await (const file of getFilesInFolder(dirPath)) {
|
|
95
99
|
// TODO: "exclude:" config
|
package/src/user.tsx
CHANGED
|
@@ -298,9 +298,9 @@ let initialised = false;
|
|
|
298
298
|
|
|
299
299
|
// we do this because we have some async stuff
|
|
300
300
|
// TODO: this should just happen in the top level
|
|
301
|
-
//
|
|
301
|
+
// and we should figure out how to do top level await
|
|
302
302
|
export async function initialise(): Promise<void> {
|
|
303
|
-
// get
|
|
303
|
+
// get refreshToken/accessToken from fs if exists
|
|
304
304
|
try {
|
|
305
305
|
// if CF_API_TOKEN available, use that
|
|
306
306
|
if (process.env.CF_API_TOKEN) {
|
|
@@ -350,7 +350,9 @@ export function getAPIToken(): string {
|
|
|
350
350
|
}
|
|
351
351
|
|
|
352
352
|
throwIfNotInitialised();
|
|
353
|
-
|
|
353
|
+
// `throwIfNotInitialised()` ensures that the accessToken is guaranteed to be defined.
|
|
354
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
355
|
+
return LocalState.accessToken!.value;
|
|
354
356
|
}
|
|
355
357
|
|
|
356
358
|
interface AccessContext {
|
|
@@ -971,14 +973,14 @@ export async function getAccountId() {
|
|
|
971
973
|
});
|
|
972
974
|
} catch (err) {
|
|
973
975
|
// probably offline
|
|
976
|
+
return;
|
|
974
977
|
}
|
|
975
|
-
|
|
976
|
-
let accountId: string;
|
|
977
|
-
|
|
978
|
-
const responseJSON: {
|
|
978
|
+
|
|
979
|
+
let accountId: string | undefined;
|
|
980
|
+
const responseJSON = (await response.json()) as {
|
|
979
981
|
success: boolean;
|
|
980
982
|
result: { id: string; account: { id: string; name: string } }[];
|
|
981
|
-
}
|
|
983
|
+
};
|
|
982
984
|
|
|
983
985
|
if (responseJSON.success === true) {
|
|
984
986
|
if (responseJSON.result.length === 1) {
|
package/wrangler-dist/cli.js
CHANGED
|
@@ -106633,7 +106633,7 @@ var import_http = __toModule(require("http"));
|
|
|
106633
106633
|
var import_react = __toModule(require_react());
|
|
106634
106634
|
|
|
106635
106635
|
// package.json
|
|
106636
|
-
var version = "0.0.0-
|
|
106636
|
+
var version = "0.0.0-edc4b53";
|
|
106637
106637
|
|
|
106638
106638
|
// src/inspect.ts
|
|
106639
106639
|
function useInspector(props) {
|
|
@@ -108103,7 +108103,7 @@ function getAPIToken() {
|
|
|
108103
108103
|
return import_node_process.default.env.CF_API_TOKEN;
|
|
108104
108104
|
}
|
|
108105
108105
|
throwIfNotInitialised();
|
|
108106
|
-
return LocalState.accessToken
|
|
108106
|
+
return LocalState.accessToken.value;
|
|
108107
108107
|
}
|
|
108108
108108
|
var ErrorOAuth2 = class extends Error {
|
|
108109
108109
|
toString() {
|
|
@@ -108522,9 +108522,8 @@ async function getAccountId() {
|
|
|
108522
108522
|
}
|
|
108523
108523
|
});
|
|
108524
108524
|
} catch (err2) {
|
|
108525
|
-
}
|
|
108526
|
-
if (!response)
|
|
108527
108525
|
return;
|
|
108526
|
+
}
|
|
108528
108527
|
let accountId;
|
|
108529
108528
|
const responseJSON = await response.json();
|
|
108530
108529
|
if (responseJSON.success === true) {
|
|
@@ -108563,7 +108562,7 @@ var CF_API_BASE_URL = process.env.CF_API_BASE_URL || "https://api.cloudflare.com
|
|
|
108563
108562
|
async function fetchInternal(resource, init = {}, queryParams) {
|
|
108564
108563
|
await requireLoggedIn();
|
|
108565
108564
|
const apiToken = requireApiToken();
|
|
108566
|
-
const headers =
|
|
108565
|
+
const headers = new Headers(init.headers);
|
|
108567
108566
|
addAuthorizationHeader(headers, apiToken);
|
|
108568
108567
|
const queryString = queryParams ? `?${queryParams.toString()}` : "";
|
|
108569
108568
|
const response = await fetch(`${CF_API_BASE_URL}${resource}${queryString}`, {
|
|
@@ -108590,9 +108589,6 @@ function requireApiToken() {
|
|
|
108590
108589
|
}
|
|
108591
108590
|
return apiToken;
|
|
108592
108591
|
}
|
|
108593
|
-
function cloneHeaders(headers) {
|
|
108594
|
-
return { ...headers };
|
|
108595
|
-
}
|
|
108596
108592
|
function addAuthorizationHeader(headers, apiToken) {
|
|
108597
108593
|
if (headers["Authorization"]) {
|
|
108598
108594
|
throw new Error("The request already specifies an authorisation header - cannot add a new one.");
|
|
@@ -111093,14 +111089,21 @@ async function listNamespaces(accountId) {
|
|
|
111093
111089
|
}
|
|
111094
111090
|
return results;
|
|
111095
111091
|
}
|
|
111096
|
-
async function listNamespaceKeys(accountId, namespaceId, prefix2) {
|
|
111092
|
+
async function listNamespaceKeys(accountId, namespaceId, prefix2 = "") {
|
|
111097
111093
|
return await fetchListResult(`/accounts/${accountId}/storage/kv/namespaces/${namespaceId}/keys`, {}, new import_node_url3.URLSearchParams({ prefix: prefix2 }));
|
|
111098
111094
|
}
|
|
111099
111095
|
async function putKeyValue(accountId, namespaceId, key2, value, args2) {
|
|
111100
|
-
|
|
111101
|
-
|
|
111102
|
-
|
|
111103
|
-
|
|
111096
|
+
let searchParams;
|
|
111097
|
+
if (args2) {
|
|
111098
|
+
searchParams = new import_node_url3.URLSearchParams();
|
|
111099
|
+
if (args2.expiration) {
|
|
111100
|
+
searchParams.set("expiration", `${args2.expiration}`);
|
|
111101
|
+
}
|
|
111102
|
+
if (args2.expiration_ttl) {
|
|
111103
|
+
searchParams.set("expiration_ttl", `${args2.expiration_ttl}`);
|
|
111104
|
+
}
|
|
111105
|
+
}
|
|
111106
|
+
return await fetchResult(`/accounts/${accountId}/storage/kv/namespaces/${namespaceId}/values/${key2}`, { method: "PUT", body: value }, searchParams);
|
|
111104
111107
|
}
|
|
111105
111108
|
async function putBulkKeyValue(accountId, namespaceId, keyvalueStr) {
|
|
111106
111109
|
return await fetchResult(`/accounts/${accountId}/storage/kv/namespaces/${namespaceId}/bulk`, {
|
|
@@ -111182,7 +111185,7 @@ function getNamespaceId({
|
|
|
111182
111185
|
return namespaceId;
|
|
111183
111186
|
}
|
|
111184
111187
|
function isValidNamespaceBinding(binding) {
|
|
111185
|
-
return /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(binding);
|
|
111188
|
+
return typeof binding === "string" && /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(binding);
|
|
111186
111189
|
}
|
|
111187
111190
|
|
|
111188
111191
|
// src/sites.tsx
|