wrangler 0.0.0-ea7ee45 → 0.0.0-eab9542

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.
@@ -15,7 +15,7 @@ export type ChooseAccountItem = {
15
15
  */
16
16
  export function ChooseAccount(props: {
17
17
  accounts: ChooseAccountItem[];
18
- onSelect: (accountId: string) => void;
18
+ onSelect: (account: { name: string; id: string }) => void;
19
19
  onError: (error: Error) => void;
20
20
  }) {
21
21
  return (
@@ -29,7 +29,7 @@ export function ChooseAccount(props: {
29
29
  }))}
30
30
  onSelect={(item) => {
31
31
  logger.log(`Using account: "${item.value.name} - ${item.value.id}"`);
32
- props.onSelect(item.value.id);
32
+ props.onSelect({ id: item.value.id, name: item.value.name });
33
33
  }}
34
34
  />
35
35
  </>
package/src/user/user.tsx CHANGED
@@ -219,7 +219,12 @@ import { render } from "ink";
219
219
  import Table from "ink-table";
220
220
  import React from "react";
221
221
  import { fetch } from "undici";
222
- import { purgeConfigCaches } from "../config-cache";
222
+ import {
223
+ getConfigCache,
224
+ purgeConfigCaches,
225
+ saveToConfigCache,
226
+ } from "../config-cache";
227
+ import isInteractive from "../is-interactive";
223
228
  import { logger } from "../logger";
224
229
  import openInBrowser from "../open-in-browser";
225
230
  import { parseTOML, readFileSync } from "../parse";
@@ -1058,27 +1063,37 @@ export async function getAccountId(): Promise<string | undefined> {
1058
1063
  const apiToken = getAPIToken();
1059
1064
  if (!apiToken) return;
1060
1065
 
1066
+ // check if we have a cached value
1067
+ const cachedAccount = getAccountFromCache();
1068
+ if (cachedAccount) {
1069
+ return cachedAccount.id;
1070
+ }
1061
1071
  const accounts = await getAccountChoices();
1062
1072
  if (accounts.length === 1) {
1073
+ saveAccountToCache({ id: accounts[0].id, name: accounts[0].name });
1063
1074
  return accounts[0].id;
1064
1075
  }
1065
1076
 
1066
1077
  if (isInteractive()) {
1067
- return await new Promise((resolve, reject) => {
1068
- const { unmount } = render(
1069
- <ChooseAccount
1070
- accounts={accounts}
1071
- onSelect={async (selected) => {
1072
- resolve(selected);
1073
- unmount();
1074
- }}
1075
- onError={(err) => {
1076
- reject(err);
1077
- unmount();
1078
- }}
1079
- />
1080
- );
1081
- });
1078
+ const account = await new Promise<{ id: string; name: string }>(
1079
+ (resolve, reject) => {
1080
+ const { unmount } = render(
1081
+ <ChooseAccount
1082
+ accounts={accounts}
1083
+ onSelect={async (selected) => {
1084
+ saveAccountToCache(selected);
1085
+ resolve(selected);
1086
+ unmount();
1087
+ }}
1088
+ onError={(err) => {
1089
+ reject(err);
1090
+ unmount();
1091
+ }}
1092
+ />
1093
+ );
1094
+ }
1095
+ );
1096
+ return account.id;
1082
1097
  }
1083
1098
 
1084
1099
  throw new Error(
@@ -1121,10 +1136,26 @@ export function requireApiToken(): ApiCredentials {
1121
1136
  return credentials;
1122
1137
  }
1123
1138
 
1124
- function isInteractive(): boolean {
1125
- try {
1126
- return Boolean(process.stdin.isTTY && process.stdout.isTTY);
1127
- } catch {
1128
- return false;
1129
- }
1139
+ /**
1140
+ * Save the given account details to a cache
1141
+ */
1142
+ export function saveAccountToCache(account: {
1143
+ id: string;
1144
+ name: string;
1145
+ }): void {
1146
+ saveToConfigCache<{ account: { id: string; name: string } }>(
1147
+ "wrangler-account.json",
1148
+ { account }
1149
+ );
1150
+ }
1151
+
1152
+ /**
1153
+ * Fetch the given account details from a cache if available
1154
+ */
1155
+ export function getAccountFromCache():
1156
+ | undefined
1157
+ | { id: string; name: string } {
1158
+ return getConfigCache<{ account: { id: string; name: string } }>(
1159
+ "wrangler-account.json"
1160
+ ).account;
1130
1161
  }
package/src/worker.ts CHANGED
@@ -122,6 +122,11 @@ interface CfService {
122
122
  environment?: string;
123
123
  }
124
124
 
125
+ interface CfWorkerNamespace {
126
+ binding: string;
127
+ namespace: string;
128
+ }
129
+
125
130
  interface CfUnsafeBinding {
126
131
  name: string;
127
132
  type: string;
@@ -168,6 +173,7 @@ export interface CfWorkerInit {
168
173
  durable_objects: { bindings: CfDurableObject[] } | undefined;
169
174
  r2_buckets: CfR2Bucket[] | undefined;
170
175
  services: CfService[] | undefined;
176
+ worker_namespaces: CfWorkerNamespace[] | undefined;
171
177
  unsafe: CfUnsafeBinding[] | undefined;
172
178
  };
173
179
  migrations: CfDurableObjectMigrations | undefined;