wrangler 0.0.0-e14e589 → 0.0.0-e2a26a0
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/README.md +51 -0
- package/bin/wrangler.js +2 -2
- package/package.json +49 -30
- package/pages/functions/buildWorker.ts +62 -0
- package/pages/functions/filepath-routing.test.ts +47 -0
- package/pages/functions/filepath-routing.ts +231 -0
- package/pages/functions/identifiers.ts +78 -0
- package/pages/functions/routes.ts +160 -0
- package/pages/functions/template-worker.ts +136 -0
- package/src/__tests__/dev.test.tsx +71 -0
- package/src/__tests__/{clipboardy-mock.js → helpers/clipboardy-mock.js} +0 -0
- package/src/__tests__/helpers/cmd-shim.d.ts +11 -0
- package/src/__tests__/helpers/mock-account-id.ts +30 -0
- package/src/__tests__/helpers/mock-bin.ts +33 -0
- package/src/__tests__/helpers/mock-cfetch.ts +207 -0
- package/src/__tests__/helpers/mock-console.ts +56 -0
- package/src/__tests__/helpers/mock-dialogs.ts +65 -0
- package/src/__tests__/helpers/mock-kv.ts +40 -0
- package/src/__tests__/helpers/mock-user.ts +27 -0
- package/src/__tests__/helpers/run-in-tmp.ts +29 -0
- package/src/__tests__/helpers/run-wrangler.ts +14 -0
- package/src/__tests__/index.test.ts +509 -119
- package/src/__tests__/jest.setup.ts +37 -0
- package/src/__tests__/kv.test.ts +1139 -0
- package/src/__tests__/logout.test.ts +50 -0
- package/src/__tests__/package-manager.test.ts +206 -0
- package/src/__tests__/publish.test.ts +1222 -0
- package/src/__tests__/secret.test.ts +210 -0
- package/src/__tests__/whoami.test.tsx +86 -0
- package/src/api/form_data.ts +85 -76
- package/src/api/preview.ts +29 -24
- package/src/api/worker.ts +50 -35
- package/src/cfetch/index.ts +102 -0
- package/src/cfetch/internal.ts +101 -0
- package/src/cli.ts +6 -7
- package/src/config.ts +630 -85
- package/src/dev.tsx +446 -282
- package/src/dialogs.tsx +6 -14
- package/src/index.tsx +773 -426
- package/src/inspect.ts +596 -0
- package/src/kv.tsx +118 -45
- package/src/module-collection.ts +63 -0
- package/src/package-manager.ts +120 -0
- package/src/pages.tsx +917 -211
- package/src/paths.ts +26 -0
- package/src/proxy.ts +370 -0
- package/src/publish.ts +220 -88
- package/src/sites.tsx +180 -55
- package/src/tail.tsx +6 -4
- package/src/user.tsx +77 -87
- package/src/whoami.tsx +69 -0
- package/templates/new-worker.js +15 -0
- package/templates/new-worker.ts +15 -0
- package/{static-asset-facade.js → templates/static-asset-facade.js} +0 -0
- package/wrangler-dist/cli.js +125330 -557
- package/wrangler-dist/cli.js.map +3 -3
- package/src/__tests__/fixtures/init/.gitkeep +0 -0
- package/src/__tests__/mock-cfetch.js +0 -46
- package/src/api/inspect.ts +0 -441
- package/src/cfetch.ts +0 -72
- package/src/util/fetch.ts +0 -74
package/src/whoami.tsx
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Text, render } from "ink";
|
|
2
|
+
import Table from "ink-table";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { fetchListResult, fetchResult } from "./cfetch";
|
|
5
|
+
import { getAPIToken } from "./user";
|
|
6
|
+
|
|
7
|
+
export async function whoami() {
|
|
8
|
+
console.log("Getting User settings...");
|
|
9
|
+
const user = await getUserInfo();
|
|
10
|
+
render(<WhoAmI user={user}></WhoAmI>);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function WhoAmI({ user }: { user: UserInfo | undefined }) {
|
|
14
|
+
return user ? (
|
|
15
|
+
<>
|
|
16
|
+
<Email tokenType={user.authType} email={user.email}></Email>
|
|
17
|
+
<Accounts accounts={user.accounts}></Accounts>
|
|
18
|
+
</>
|
|
19
|
+
) : (
|
|
20
|
+
<Text>You are not authenticated. Please run `wrangler login`.</Text>
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function Email(props: { tokenType: string; email: string }) {
|
|
25
|
+
return (
|
|
26
|
+
<Text>
|
|
27
|
+
👋 You are logged in with an {props.tokenType} Token, associated with the
|
|
28
|
+
email '{props.email}'!
|
|
29
|
+
</Text>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function Accounts(props: { accounts: AccountInfo[] }) {
|
|
34
|
+
const accounts = props.accounts.map((account) => ({
|
|
35
|
+
"Account Name": account.name,
|
|
36
|
+
"Account ID": account.id,
|
|
37
|
+
}));
|
|
38
|
+
return <Table data={accounts}></Table>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface UserInfo {
|
|
42
|
+
apiToken: string;
|
|
43
|
+
authType: string;
|
|
44
|
+
email: string;
|
|
45
|
+
accounts: AccountInfo[];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export async function getUserInfo(): Promise<UserInfo | undefined> {
|
|
49
|
+
const apiToken = getAPIToken();
|
|
50
|
+
return apiToken
|
|
51
|
+
? {
|
|
52
|
+
apiToken,
|
|
53
|
+
authType: "OAuth",
|
|
54
|
+
email: await getEmail(),
|
|
55
|
+
accounts: await getAccounts(),
|
|
56
|
+
}
|
|
57
|
+
: undefined;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async function getEmail(): Promise<string> {
|
|
61
|
+
const { email } = await fetchResult<{ email: string }>("/user");
|
|
62
|
+
return email;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
type AccountInfo = { name: string; id: string };
|
|
66
|
+
|
|
67
|
+
async function getAccounts(): Promise<AccountInfo[]> {
|
|
68
|
+
return await fetchListResult<AccountInfo>("/accounts");
|
|
69
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Welcome to Cloudflare Workers! This is your first worker.
|
|
3
|
+
*
|
|
4
|
+
* - Run `npx wrangler dev src/index.js` in your terminal to start a development server
|
|
5
|
+
* - Open a browser tab at http://localhost:8787/ to see your worker in action
|
|
6
|
+
* - Run `npx wrangler publish src/index.js --name my-worker` to deploy your worker
|
|
7
|
+
*
|
|
8
|
+
* Learn more at https://developers.cloudflare.com/workers/
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
async fetch(request) {
|
|
13
|
+
return new Response("Hello World!");
|
|
14
|
+
},
|
|
15
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Welcome to Cloudflare Workers! This is your first worker.
|
|
3
|
+
*
|
|
4
|
+
* - Run `wrangler dev src/index.ts` in your terminal to start a development server
|
|
5
|
+
* - Open a browser tab at http://localhost:8787/ to see your worker in action
|
|
6
|
+
* - Run `wrangler publish src/index.ts --name my-worker` to deploy your worker
|
|
7
|
+
*
|
|
8
|
+
* Learn more at https://developers.cloudflare.com/workers/
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
async fetch(request: Request): Promise<Response> {
|
|
13
|
+
return new Response("Hello World!");
|
|
14
|
+
},
|
|
15
|
+
};
|
|
File without changes
|