wrangler 0.0.0-e5182f6 → 0.0.0-e5d3690

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.
Files changed (44) hide show
  1. package/README.md +51 -0
  2. package/bin/wrangler.js +36 -2
  3. package/import_meta_url.js +3 -0
  4. package/package.json +64 -18
  5. package/pages/functions/buildWorker.ts +62 -0
  6. package/pages/functions/filepath-routing.test.ts +39 -0
  7. package/pages/functions/filepath-routing.ts +228 -0
  8. package/pages/functions/identifiers.ts +78 -0
  9. package/pages/functions/routes.ts +158 -0
  10. package/pages/functions/template-worker.ts +136 -0
  11. package/src/__tests__/clipboardy-mock.js +4 -0
  12. package/src/__tests__/dev.test.tsx +67 -0
  13. package/src/__tests__/index.test.ts +289 -0
  14. package/src/__tests__/jest.setup.ts +22 -0
  15. package/src/__tests__/kv.test.ts +1199 -0
  16. package/src/__tests__/mock-cfetch.ts +173 -0
  17. package/src/__tests__/mock-dialogs.ts +65 -0
  18. package/src/__tests__/publish.test.ts +672 -0
  19. package/src/__tests__/run-in-tmp.ts +19 -0
  20. package/src/__tests__/run-wrangler.ts +32 -0
  21. package/src/__tests__/whoami.test.tsx +130 -0
  22. package/src/api/form_data.ts +131 -0
  23. package/src/api/preview.ts +128 -0
  24. package/src/api/worker.ts +155 -0
  25. package/src/cfetch/index.ts +110 -0
  26. package/src/cfetch/internal.ts +71 -0
  27. package/src/cli.ts +9 -0
  28. package/src/config.ts +646 -0
  29. package/src/dev.tsx +779 -0
  30. package/src/dialogs.tsx +77 -0
  31. package/src/index.tsx +1975 -0
  32. package/src/inspect.ts +543 -0
  33. package/src/kv.tsx +276 -0
  34. package/src/module-collection.ts +64 -0
  35. package/src/pages.tsx +1040 -0
  36. package/src/proxy.ts +302 -0
  37. package/src/publish.ts +382 -0
  38. package/src/sites.tsx +243 -0
  39. package/src/tail.tsx +73 -0
  40. package/src/user.tsx +1019 -0
  41. package/src/whoami.tsx +69 -0
  42. package/wrangler-dist/{index_node.js → cli.js} +61497 -38835
  43. package/wrangler-dist/cli.js.map +7 -0
  44. package/wrangler-dist/index_node.js.map +0 -7
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 &apos;{props.email}&apos;!
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
+ }