wrangler 0.0.0-e978986 → 0.0.0-ea7ee45

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 (181) hide show
  1. package/README.md +7 -1
  2. package/bin/wrangler.js +111 -57
  3. package/kv-asset-handler.js +1 -0
  4. package/miniflare-dist/index.mjs +9 -2
  5. package/package.json +156 -152
  6. package/src/__tests__/config-cache.test.ts +24 -24
  7. package/src/__tests__/configuration.test.ts +3818 -3363
  8. package/src/__tests__/dev.test.tsx +1128 -949
  9. package/src/__tests__/guess-worker-format.test.ts +68 -68
  10. package/src/__tests__/helpers/cmd-shim.d.ts +6 -6
  11. package/src/__tests__/helpers/faye-websocket.d.ts +4 -4
  12. package/src/__tests__/helpers/mock-account-id.ts +24 -24
  13. package/src/__tests__/helpers/mock-bin.ts +20 -20
  14. package/src/__tests__/helpers/mock-cfetch.ts +92 -92
  15. package/src/__tests__/helpers/mock-console.ts +49 -39
  16. package/src/__tests__/helpers/mock-dialogs.ts +94 -71
  17. package/src/__tests__/helpers/mock-http-server.ts +30 -30
  18. package/src/__tests__/helpers/mock-istty.ts +65 -18
  19. package/src/__tests__/helpers/mock-kv.ts +26 -26
  20. package/src/__tests__/helpers/mock-oauth-flow.ts +223 -228
  21. package/src/__tests__/helpers/mock-process.ts +39 -0
  22. package/src/__tests__/helpers/mock-stdin.ts +82 -77
  23. package/src/__tests__/helpers/mock-web-socket.ts +21 -21
  24. package/src/__tests__/helpers/run-in-tmp.ts +27 -27
  25. package/src/__tests__/helpers/run-wrangler.ts +8 -8
  26. package/src/__tests__/helpers/write-worker-source.ts +16 -16
  27. package/src/__tests__/helpers/write-wrangler-toml.ts +9 -9
  28. package/src/__tests__/https-options.test.ts +104 -104
  29. package/src/__tests__/index.test.ts +239 -233
  30. package/src/__tests__/init.test.ts +1605 -1180
  31. package/src/__tests__/jest.setup.ts +63 -33
  32. package/src/__tests__/kv.test.ts +1128 -990
  33. package/src/__tests__/logger.test.ts +100 -74
  34. package/src/__tests__/package-manager.test.ts +303 -303
  35. package/src/__tests__/pages.test.ts +1160 -563
  36. package/src/__tests__/parse.test.ts +252 -252
  37. package/src/__tests__/publish.test.ts +6344 -5299
  38. package/src/__tests__/pubsub.test.ts +276 -0
  39. package/src/__tests__/r2.test.ts +133 -133
  40. package/src/__tests__/route.test.ts +18 -18
  41. package/src/__tests__/secret.test.ts +382 -377
  42. package/src/__tests__/tail.test.ts +530 -530
  43. package/src/__tests__/user.test.ts +123 -111
  44. package/src/__tests__/whoami.test.tsx +198 -83
  45. package/src/__tests__/worker-namespace.test.ts +327 -0
  46. package/src/abort.d.ts +1 -1
  47. package/src/api/dev.ts +39 -0
  48. package/src/api/index.ts +1 -0
  49. package/src/bundle-reporter.tsx +29 -0
  50. package/src/bundle.ts +158 -146
  51. package/src/cfetch/index.ts +80 -80
  52. package/src/cfetch/internal.ts +92 -88
  53. package/src/cli.ts +21 -7
  54. package/src/config/config.ts +204 -195
  55. package/src/config/diagnostics.ts +61 -61
  56. package/src/config/environment.ts +367 -357
  57. package/src/config/index.ts +193 -193
  58. package/src/config/validation-helpers.ts +366 -357
  59. package/src/config/validation.ts +1521 -1367
  60. package/src/config-cache.ts +24 -25
  61. package/src/create-worker-preview.ts +206 -136
  62. package/src/create-worker-upload-form.ts +238 -238
  63. package/src/dev/dev-vars.ts +13 -13
  64. package/src/dev/dev.tsx +334 -336
  65. package/src/dev/local.tsx +304 -272
  66. package/src/dev/remote.tsx +351 -211
  67. package/src/dev/use-esbuild.ts +126 -94
  68. package/src/dev.tsx +526 -0
  69. package/src/dialogs.tsx +97 -97
  70. package/src/durable.ts +87 -87
  71. package/src/entry.ts +234 -228
  72. package/src/environment-variables.ts +23 -23
  73. package/src/errors.ts +6 -6
  74. package/src/generate.ts +33 -0
  75. package/src/git-client.ts +42 -0
  76. package/src/https-options.ts +79 -79
  77. package/src/index.tsx +1775 -2752
  78. package/src/init.ts +549 -0
  79. package/src/inspect.ts +593 -593
  80. package/src/intl-polyfill.d.ts +123 -123
  81. package/src/kv.ts +277 -277
  82. package/src/logger.ts +46 -39
  83. package/src/miniflare-cli/enum-keys.ts +8 -8
  84. package/src/miniflare-cli/index.ts +42 -31
  85. package/src/miniflare-cli/request-context.ts +18 -18
  86. package/src/module-collection.ts +212 -212
  87. package/src/open-in-browser.ts +4 -6
  88. package/src/package-manager.ts +123 -123
  89. package/src/pages/build.tsx +202 -0
  90. package/src/pages/constants.ts +7 -0
  91. package/src/pages/deployments.tsx +101 -0
  92. package/src/pages/dev.tsx +964 -0
  93. package/src/pages/functions/buildPlugin.ts +105 -0
  94. package/src/pages/functions/buildWorker.ts +151 -0
  95. package/{pages → src/pages}/functions/filepath-routing.test.ts +113 -113
  96. package/src/pages/functions/filepath-routing.ts +189 -0
  97. package/src/pages/functions/identifiers.ts +78 -0
  98. package/src/pages/functions/routes.ts +151 -0
  99. package/src/pages/index.tsx +84 -0
  100. package/src/pages/projects.tsx +157 -0
  101. package/src/pages/publish.tsx +335 -0
  102. package/src/pages/types.ts +40 -0
  103. package/src/pages/upload.tsx +384 -0
  104. package/src/pages/utils.ts +12 -0
  105. package/src/parse.ts +209 -125
  106. package/src/paths.ts +6 -6
  107. package/src/preview.ts +31 -0
  108. package/src/proxy.ts +400 -389
  109. package/src/publish.ts +688 -505
  110. package/src/pubsub/index.ts +286 -0
  111. package/src/pubsub/pubsub-commands.tsx +594 -0
  112. package/src/r2.ts +19 -19
  113. package/src/selfsigned.d.ts +23 -23
  114. package/src/sites.tsx +278 -201
  115. package/src/tail/filters.ts +108 -108
  116. package/src/tail/index.ts +217 -217
  117. package/src/tail/printing.ts +45 -45
  118. package/src/update-check.ts +11 -11
  119. package/src/user/choose-account.tsx +60 -0
  120. package/src/user/env-vars.ts +46 -0
  121. package/src/user/generate-auth-url.ts +33 -0
  122. package/src/user/generate-random-state.ts +16 -0
  123. package/src/user/index.ts +3 -0
  124. package/src/user/user.tsx +1130 -0
  125. package/src/whoami.tsx +61 -41
  126. package/src/worker-namespace.ts +190 -0
  127. package/src/worker.ts +104 -99
  128. package/src/zones.ts +76 -0
  129. package/templates/checked-fetch.js +17 -0
  130. package/templates/new-worker-scheduled.js +4 -4
  131. package/templates/new-worker-scheduled.ts +16 -16
  132. package/templates/new-worker.js +3 -3
  133. package/templates/new-worker.ts +15 -15
  134. package/templates/no-op-worker.js +10 -0
  135. package/templates/pages-template-plugin.ts +155 -0
  136. package/templates/pages-template-worker.ts +161 -0
  137. package/templates/static-asset-facade.js +32 -36
  138. package/templates/tsconfig.json +95 -95
  139. package/wrangler-dist/cli.js +40620 -39223
  140. package/pages/functions/buildPlugin.ts +0 -105
  141. package/pages/functions/buildWorker.ts +0 -151
  142. package/pages/functions/filepath-routing.ts +0 -189
  143. package/pages/functions/identifiers.ts +0 -78
  144. package/pages/functions/routes.ts +0 -156
  145. package/pages/functions/template-plugin.ts +0 -147
  146. package/pages/functions/template-worker.ts +0 -143
  147. package/src/pages.tsx +0 -2027
  148. package/src/user.tsx +0 -1203
  149. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
  150. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
  151. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
  152. package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
  153. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
  154. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
  155. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
  156. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
  157. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
  158. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
  159. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
  160. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
  161. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
  162. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
  163. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
  164. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
  165. package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
  166. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
  167. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
  168. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
  169. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
  170. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
  171. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
  172. package/vendor/wrangler-mime/CHANGELOG.md +0 -289
  173. package/vendor/wrangler-mime/LICENSE +0 -21
  174. package/vendor/wrangler-mime/Mime.js +0 -97
  175. package/vendor/wrangler-mime/README.md +0 -187
  176. package/vendor/wrangler-mime/cli.js +0 -46
  177. package/vendor/wrangler-mime/index.js +0 -4
  178. package/vendor/wrangler-mime/lite.js +0 -4
  179. package/vendor/wrangler-mime/package.json +0 -52
  180. package/vendor/wrangler-mime/types/other.js +0 -1
  181. package/vendor/wrangler-mime/types/standard.js +0 -1
@@ -0,0 +1,594 @@
1
+ import { type ConfigPath } from "..";
2
+ import { readConfig } from "../config";
3
+ import { confirm } from "../dialogs";
4
+ import { CommandLineArgsError } from "../index";
5
+ import { logger } from "../logger";
6
+ import { parseHumanDuration } from "../parse";
7
+ import { requireAuth } from "../user";
8
+ import * as pubsub from ".";
9
+ import type { Argv, CommandModule } from "yargs";
10
+
11
+ export function pubSubCommands(
12
+ pubsubYargs: Argv,
13
+ subHelp: CommandModule
14
+ ): Argv {
15
+ return pubsubYargs
16
+ .command(subHelp)
17
+ .command(
18
+ "namespace",
19
+ "Manage your Pub/Sub Namespaces",
20
+ (pubsubNamespaceYargs) => {
21
+ pubsubNamespaceYargs
22
+ .command(
23
+ "create <name>",
24
+ "Create a new Pub/Sub Namespace",
25
+ (yargs) => {
26
+ return yargs
27
+ .positional("name", {
28
+ describe:
29
+ "The name of the new Namespace. This name will form part of the public endpoint, in the form <broker>.<namespace>.cloudflarepubsub.com",
30
+ type: "string",
31
+ demandOption: true,
32
+ })
33
+ .option("description", {
34
+ describe: "Textual description of Namespace",
35
+ type: "string",
36
+ });
37
+ },
38
+ async (args) => {
39
+ const config = readConfig(args.config as ConfigPath, args);
40
+ const accountId = await requireAuth(config);
41
+
42
+ const namespace: pubsub.PubSubNamespace = {
43
+ name: args.name,
44
+ };
45
+ if (args.description) {
46
+ namespace.description = args.description;
47
+ }
48
+
49
+ logger.log(`Creating Pub/SubNamespace ${args.name}...`);
50
+ await pubsub.createPubSubNamespace(accountId, namespace);
51
+ logger.log(`Success! Created Pub/Sub Namespace ${args.name}`);
52
+ }
53
+ )
54
+ .epilogue(pubsub.pubSubBetaWarning);
55
+
56
+ pubsubNamespaceYargs
57
+ .command(
58
+ "list",
59
+ "List your existing Pub/Sub Namespaces",
60
+ {},
61
+ async (args) => {
62
+ const config = readConfig(args.config as ConfigPath, args);
63
+ const accountId = await requireAuth(config);
64
+
65
+ logger.log(await pubsub.listPubSubNamespaces(accountId));
66
+ }
67
+ )
68
+ .epilogue(pubsub.pubSubBetaWarning);
69
+
70
+ pubsubNamespaceYargs
71
+ .command(
72
+ "delete <name>",
73
+ "Delete a Pub/Sub Namespace",
74
+ (yargs) => {
75
+ return yargs.positional("name", {
76
+ describe: "The name of the namespace to delete",
77
+ type: "string",
78
+ demandOption: true,
79
+ });
80
+ },
81
+ async (args) => {
82
+ const config = readConfig(args.config as ConfigPath, args);
83
+ const accountId = await requireAuth(config);
84
+
85
+ if (
86
+ await confirm(
87
+ `️❗️ Are you sure you want to delete the Pub/Sub Namespace ${args.name}? This cannot be undone.\nThis name will be available for others to register.`
88
+ )
89
+ ) {
90
+ logger.log(`Deleting namespace ${args.name}...`);
91
+ await pubsub.deletePubSubNamespace(accountId, args.name);
92
+ logger.log(`Deleted namespace ${args.name}.`);
93
+ }
94
+ }
95
+ )
96
+ .epilogue(pubsub.pubSubBetaWarning);
97
+
98
+ pubsubNamespaceYargs
99
+ .command(
100
+ "describe <name>",
101
+ "Describe a Pub/Sub Namespace",
102
+ (yargs) => {
103
+ return yargs.positional("name", {
104
+ describe: "The name of the namespace to describe.",
105
+ type: "string",
106
+ demandOption: true,
107
+ });
108
+ },
109
+ async (args) => {
110
+ const config = readConfig(args.config as ConfigPath, args);
111
+ const accountId = await requireAuth(config);
112
+
113
+ logger.log(
114
+ await pubsub.describePubSubNamespace(accountId, args.name)
115
+ );
116
+ }
117
+ )
118
+ .epilogue(pubsub.pubSubBetaWarning);
119
+
120
+ return pubsubNamespaceYargs;
121
+ }
122
+ )
123
+ .command("broker", "Interact with your Pub/Sub Brokers", (brokersYargs) => {
124
+ brokersYargs
125
+ .command(
126
+ "create <name>",
127
+ "Create a new Pub/Sub Broker",
128
+ (yargs) =>
129
+ yargs
130
+ .positional("name", {
131
+ describe:
132
+ "The name of the Pub/Sub Broker. This name will form part of the public endpoint, in the form <broker>.<namespace>.cloudflarepubsub.com",
133
+ type: "string",
134
+ demandOption: true,
135
+ })
136
+ .option("namespace", {
137
+ describe:
138
+ "An existing Namespace to associate the Broker with. This name will form part of the public endpoint, in the form <broker>.<namespace>.cloudflarepubsub.com",
139
+ type: "string",
140
+ alias: "ns",
141
+ demandOption: true,
142
+ })
143
+ .option("description", {
144
+ describe: "Longer description for the broker",
145
+ type: "string",
146
+ })
147
+ .option("expiration", {
148
+ describe:
149
+ "Time to allow token validity (can use seconds, hours, months, weeks, years)",
150
+ type: "string",
151
+ })
152
+ .option("on-publish-url", {
153
+ describe:
154
+ "A (HTTPS) Cloudflare Worker (or webhook) URL that messages will be sent to on-publish.",
155
+ type: "string",
156
+ }),
157
+ async (args) => {
158
+ const config = readConfig(args.config as ConfigPath, args);
159
+ const accountId = await requireAuth(config);
160
+
161
+ const broker: pubsub.PubSubBroker = {
162
+ name: args.name,
163
+ };
164
+ if (args.description) {
165
+ broker.description = args.description;
166
+ }
167
+ if (args.expiration) {
168
+ const expiration = parseHumanDuration(args.expiration);
169
+ if (isNaN(expiration)) {
170
+ throw new CommandLineArgsError(
171
+ `${args.expiration} is not a time duration. (Example of valid values are: 1y, 6 days)`
172
+ );
173
+ }
174
+ broker.expiration = expiration;
175
+ }
176
+ if (args["on-publish-url"]) {
177
+ broker.on_publish = {
178
+ url: args["on-publish-url"],
179
+ };
180
+ }
181
+
182
+ logger.log(
183
+ await pubsub.createPubSubBroker(accountId, args.namespace, broker)
184
+ );
185
+ }
186
+ )
187
+ .epilogue(pubsub.pubSubBetaWarning);
188
+
189
+ brokersYargs
190
+ .command(
191
+ "update <name>",
192
+ "Update an existing Pub/Sub Broker's configuration.",
193
+ (yargs) =>
194
+ yargs
195
+ .positional("name", {
196
+ describe: "The name of an existing Pub/Sub Broker",
197
+ type: "string",
198
+ demandOption: true,
199
+ })
200
+ .option("namespace", {
201
+ describe: "The Namespace the Broker is associated with",
202
+ type: "string",
203
+ alias: "ns",
204
+ demandOption: true,
205
+ })
206
+ .option("description", {
207
+ describe: "A optional description of the Broker.",
208
+ type: "string",
209
+ })
210
+ .option("expiration", {
211
+ describe:
212
+ "The expiration date for all client credentials issued by the Broker (can use seconds, hours, months, weeks, years)",
213
+ type: "string",
214
+ })
215
+ .option("on-publish-url", {
216
+ describe:
217
+ "A (HTTPS) Cloudflare Worker (or webhook) URL that messages will be sent to on-publish.",
218
+ type: "string",
219
+ }),
220
+ async (args) => {
221
+ const config = readConfig(args.config as ConfigPath, args);
222
+ const accountId = await requireAuth(config);
223
+
224
+ const broker: pubsub.PubSubBrokerUpdate = {};
225
+
226
+ if (args.description) {
227
+ broker.description = args.description;
228
+ }
229
+
230
+ if (args.expiration) {
231
+ const expiration = parseHumanDuration(args.expiration);
232
+ if (isNaN(expiration)) {
233
+ throw new CommandLineArgsError(
234
+ `${args.expiration} is not a time duration. Examples of valid values include: '1y', '24h', or '6 days'.`
235
+ );
236
+ }
237
+ broker.expiration = expiration;
238
+ }
239
+
240
+ if (args["on-publish-url"]) {
241
+ broker.on_publish = {
242
+ url: args["on-publish-url"],
243
+ };
244
+ }
245
+
246
+ logger.log(
247
+ await pubsub.updatePubSubBroker(
248
+ accountId,
249
+ args.namespace,
250
+ args.name,
251
+ broker
252
+ )
253
+ );
254
+ logger.log(`Successfully updated Pub/Sub Broker ${args.name}`);
255
+ }
256
+ )
257
+ .epilogue(pubsub.pubSubBetaWarning);
258
+
259
+ brokersYargs
260
+ .command(
261
+ "list",
262
+ "List the Pub/Sub Brokers within a Namespace",
263
+ (yargs) => {
264
+ return yargs.option("namespace", {
265
+ describe: "The Namespace the Brokers are associated with.",
266
+ type: "string",
267
+ alias: "ns",
268
+ demandOption: true,
269
+ });
270
+ },
271
+ async (args) => {
272
+ const config = readConfig(args.config as ConfigPath, args);
273
+ const accountId = await requireAuth(config);
274
+
275
+ logger.log(
276
+ await pubsub.listPubSubBrokers(accountId, args.namespace)
277
+ );
278
+ }
279
+ )
280
+ .epilogue(pubsub.pubSubBetaWarning);
281
+
282
+ brokersYargs
283
+ .command(
284
+ "delete <name>",
285
+ "Delete an existing Pub/Sub Broker",
286
+ (yargs) => {
287
+ return yargs
288
+ .positional("name", {
289
+ describe: "The name of the Broker to delete",
290
+ type: "string",
291
+ demandOption: true,
292
+ })
293
+ .option("namespace", {
294
+ describe: "The Namespace the Broker is associated with.",
295
+ type: "string",
296
+ alias: "ns",
297
+ demandOption: true,
298
+ });
299
+ },
300
+ async (args) => {
301
+ const config = readConfig(args.config as ConfigPath, args);
302
+ const accountId = await requireAuth(config);
303
+
304
+ if (
305
+ await confirm(
306
+ `️❗️ Are you sure you want to delete the Pub/Sub Broker ${args.name}? This cannot be undone.\nAll existing clients will be disconnected.`
307
+ )
308
+ ) {
309
+ logger.log(`Deleting Pub/Sub Broker ${args.name}.`);
310
+ await pubsub.deletePubSubBroker(
311
+ accountId,
312
+ args.namespace,
313
+ args.name
314
+ );
315
+ logger.log(`Deleted Pub/Sub Broker ${args.name}.`);
316
+ }
317
+ }
318
+ )
319
+ .epilogue(pubsub.pubSubBetaWarning);
320
+
321
+ brokersYargs
322
+ .command(
323
+ "describe <name>",
324
+ "Describe an existing Pub/Sub Broker.",
325
+ (yargs) => {
326
+ return yargs
327
+ .positional("name", {
328
+ describe: "The name of the Broker to describe.",
329
+ type: "string",
330
+ demandOption: true,
331
+ })
332
+ .option("namespace", {
333
+ describe: "The Namespace the Broker is associated with.",
334
+ type: "string",
335
+ alias: "ns",
336
+ demandOption: true,
337
+ });
338
+ },
339
+ async (args) => {
340
+ const config = readConfig(args.config as ConfigPath, args);
341
+ const accountId = await requireAuth(config);
342
+
343
+ logger.log(
344
+ await pubsub.describePubSubBroker(
345
+ accountId,
346
+ args.namespace,
347
+ args.name
348
+ )
349
+ );
350
+ }
351
+ )
352
+ .epilogue(pubsub.pubSubBetaWarning);
353
+
354
+ brokersYargs
355
+ .command(
356
+ "issue <name>",
357
+ "Issue new client credentials for a specific Pub/Sub Broker.",
358
+ (yargs) => {
359
+ return yargs
360
+ .positional("name", {
361
+ describe: "The name of the Broker to issue credentials for.",
362
+ type: "string",
363
+ demandOption: true,
364
+ })
365
+ .option("namespace", {
366
+ describe: "The Namespace the Broker is associated with.",
367
+ type: "string",
368
+ alias: "ns",
369
+ demandOption: true,
370
+ })
371
+ .option("number", {
372
+ describe: "The number of credentials to generate.",
373
+ type: "number",
374
+ alias: "n",
375
+ default: 1,
376
+ })
377
+ .option("type", {
378
+ describe: "The type of credential to generate.",
379
+ type: "string",
380
+ default: "TOKEN",
381
+ })
382
+ .option("expiration", {
383
+ describe:
384
+ "The expiration to set on the issued credentials. This overrides any Broker-level expiration that is set.",
385
+ type: "string",
386
+ alias: "exp",
387
+ })
388
+ .option("client-id", {
389
+ describe:
390
+ "A list of existing clientIds to generate tokens for. By default, clientIds are randomly generated.",
391
+ type: "string",
392
+ alias: "jti",
393
+ array: true,
394
+ });
395
+ },
396
+ async (args) => {
397
+ const config = readConfig(args.config as ConfigPath, args);
398
+ const accountId = await requireAuth(config);
399
+
400
+ let parsedExpiration: number | undefined;
401
+ if (args.expiration) {
402
+ const expiration = parseHumanDuration(args.expiration);
403
+ if (isNaN(expiration)) {
404
+ throw new CommandLineArgsError(
405
+ `${args.expiration} is not a time duration. Example of valid values are: 1y, 6 days.`
406
+ );
407
+ }
408
+ parsedExpiration = expiration;
409
+ }
410
+
411
+ logger.log(
412
+ `🔑 Issuing credential(s) for ${args.name}.${args.namespace}...`
413
+ );
414
+
415
+ logger.log(
416
+ await pubsub.issuePubSubBrokerTokens(
417
+ accountId,
418
+ args.namespace,
419
+ args.name,
420
+ args.number,
421
+ args.type,
422
+ args["client-id"],
423
+ parsedExpiration
424
+ )
425
+ );
426
+ }
427
+ )
428
+ .epilogue(pubsub.pubSubBetaWarning);
429
+
430
+ brokersYargs
431
+ .command(
432
+ "revoke <name>",
433
+ "Revoke a set of active client credentials associated with the given Broker",
434
+ (yargs) => {
435
+ return yargs
436
+ .positional("name", {
437
+ describe:
438
+ "The name of the Broker to revoke credentials against.",
439
+ type: "string",
440
+ demandOption: true,
441
+ })
442
+ .option("namespace", {
443
+ describe: "The Namespace the Broker is associated with.",
444
+ type: "string",
445
+ alias: "ns",
446
+ demandOption: true,
447
+ })
448
+ .option("jti", {
449
+ describe: "Tokens to revoke",
450
+ type: "string",
451
+ demandOption: true,
452
+ array: true,
453
+ });
454
+ },
455
+ async (args) => {
456
+ const config = readConfig(args.config as ConfigPath, args);
457
+ const accountId = await requireAuth(config);
458
+
459
+ const numTokens = args.jti.length;
460
+
461
+ logger.log(
462
+ `🔴 Revoking access to ${args.name} for ${numTokens} credential(s)...`
463
+ );
464
+
465
+ await pubsub.revokePubSubBrokerTokens(
466
+ accountId,
467
+ args.namespace,
468
+ args.name,
469
+ args.jti
470
+ );
471
+
472
+ logger.log(`Revoked ${args.jti.length} credential(s).`);
473
+ }
474
+ )
475
+ .epilogue(pubsub.pubSubBetaWarning);
476
+
477
+ brokersYargs
478
+ .command(
479
+ "unrevoke <name>",
480
+ "Restore access to a set of previously revoked client credentials.",
481
+ (yargs) => {
482
+ return yargs
483
+ .positional("name", {
484
+ describe:
485
+ "The name of the Broker to revoke credentials against.",
486
+ type: "string",
487
+ demandOption: true,
488
+ })
489
+ .option("namespace", {
490
+ describe: "The Namespace the Broker is associated with.",
491
+ type: "string",
492
+ alias: "ns",
493
+ demandOption: true,
494
+ })
495
+ .option("jti", {
496
+ describe: "Tokens to revoke",
497
+ type: "string",
498
+ demandOption: true,
499
+ array: true,
500
+ });
501
+ },
502
+ async (args) => {
503
+ const config = readConfig(args.config as ConfigPath, args);
504
+ const accountId = await requireAuth(config);
505
+
506
+ const numTokens = args.jti.length;
507
+ logger.log(
508
+ `🟢 Restoring access to ${args.broker} for ${numTokens} credential(s)...`
509
+ );
510
+
511
+ await pubsub.unrevokePubSubBrokerTokens(
512
+ accountId,
513
+ args.namespace,
514
+ args.name,
515
+ args.jti
516
+ );
517
+
518
+ logger.log(`Unrevoked ${numTokens} credential(s)`);
519
+ }
520
+ )
521
+ .epilogue(pubsub.pubSubBetaWarning);
522
+
523
+ brokersYargs
524
+ .command(
525
+ "show-revocations <name>",
526
+ "Show all previously revoked client credentials.",
527
+ (yargs) => {
528
+ return yargs
529
+ .positional("name", {
530
+ describe:
531
+ "The name of the Broker to revoke credentials against.",
532
+ type: "string",
533
+ demandOption: true,
534
+ })
535
+ .option("namespace", {
536
+ describe: "The Namespace the Broker is associated with.",
537
+ type: "string",
538
+ alias: "ns",
539
+ demandOption: true,
540
+ });
541
+ },
542
+ async (args) => {
543
+ const config = readConfig(args.config as ConfigPath, args);
544
+ const accountId = await requireAuth(config);
545
+
546
+ logger.log(`Listing previously revoked tokens for ${args.name}...`);
547
+ logger.log(
548
+ await pubsub.listRevokedPubSubBrokerTokens(
549
+ accountId,
550
+ args.namespace,
551
+ args.name
552
+ )
553
+ );
554
+ }
555
+ )
556
+ .epilogue(pubsub.pubSubBetaWarning);
557
+
558
+ brokersYargs
559
+ .command(
560
+ "public-keys <name>",
561
+ "Show the public keys used for verifying on-publish hooks and credentials for a Broker.",
562
+ (yargs) => {
563
+ return yargs
564
+ .positional("name", {
565
+ describe:
566
+ "The name of the Broker to revoke credentials against.",
567
+ type: "string",
568
+ demandOption: true,
569
+ })
570
+ .option("namespace", {
571
+ describe: "The Namespace the Broker is associated with.",
572
+ type: "string",
573
+ alias: "ns",
574
+ demandOption: true,
575
+ });
576
+ },
577
+ async (args) => {
578
+ const config = readConfig(args.config as ConfigPath, args);
579
+ const accountId = await requireAuth(config);
580
+
581
+ logger.log(
582
+ await pubsub.getPubSubBrokerPublicKeys(
583
+ accountId,
584
+ args.namespace,
585
+ args.name
586
+ )
587
+ );
588
+ }
589
+ )
590
+ .epilogue(pubsub.pubSubBetaWarning);
591
+
592
+ return brokersYargs;
593
+ });
594
+ }
package/src/r2.ts CHANGED
@@ -4,20 +4,20 @@ import { fetchResult } from "./cfetch";
4
4
  * Information about a bucket, returned from `listR2Buckets()`.
5
5
  */
6
6
  export interface R2BucketInfo {
7
- name: string;
8
- creation_date: string;
7
+ name: string;
8
+ creation_date: string;
9
9
  }
10
10
 
11
11
  /**
12
12
  * Fetch a list of all the buckets under the given `accountId`.
13
13
  */
14
14
  export async function listR2Buckets(
15
- accountId: string
15
+ accountId: string
16
16
  ): Promise<R2BucketInfo[]> {
17
- const results = await fetchResult<{
18
- buckets: R2BucketInfo[];
19
- }>(`/accounts/${accountId}/r2/buckets`);
20
- return results.buckets;
17
+ const results = await fetchResult<{
18
+ buckets: R2BucketInfo[];
19
+ }>(`/accounts/${accountId}/r2/buckets`);
20
+ return results.buckets;
21
21
  }
22
22
 
23
23
  /**
@@ -27,24 +27,24 @@ export async function listR2Buckets(
27
27
  * A bucket must be explicitly deleted to be replaced.
28
28
  */
29
29
  export async function createR2Bucket(
30
- accountId: string,
31
- bucketName: string
30
+ accountId: string,
31
+ bucketName: string
32
32
  ): Promise<void> {
33
- return await fetchResult<void>(
34
- `/accounts/${accountId}/r2/buckets/${bucketName}`,
35
- { method: "PUT" }
36
- );
33
+ return await fetchResult<void>(
34
+ `/accounts/${accountId}/r2/buckets/${bucketName}`,
35
+ { method: "PUT" }
36
+ );
37
37
  }
38
38
 
39
39
  /**
40
40
  * Delete a bucket with the given name
41
41
  */
42
42
  export async function deleteR2Bucket(
43
- accountId: string,
44
- bucketName: string
43
+ accountId: string,
44
+ bucketName: string
45
45
  ): Promise<void> {
46
- return await fetchResult<void>(
47
- `/accounts/${accountId}/r2/buckets/${bucketName}`,
48
- { method: "DELETE" }
49
- );
46
+ return await fetchResult<void>(
47
+ `/accounts/${accountId}/r2/buckets/${bucketName}`,
48
+ { method: "DELETE" }
49
+ );
50
50
  }
@@ -1,29 +1,29 @@
1
1
  declare module "selfsigned" {
2
- import type { pki } from "node-forge";
2
+ import type { pki } from "node-forge";
3
3
 
4
- export type Attributes = pki.CertificateField[];
4
+ export type Attributes = pki.CertificateField[];
5
5
 
6
- export interface Options {
7
- days?: number;
8
- keySize?: number;
9
- extensions?: unknown[];
10
- algorithm?: string;
11
- pkcs7?: boolean;
12
- clientCertificate?: boolean;
13
- clientCertificateCN?: string;
14
- }
6
+ export interface Options {
7
+ days?: number;
8
+ keySize?: number;
9
+ extensions?: unknown[];
10
+ algorithm?: string;
11
+ pkcs7?: boolean;
12
+ clientCertificate?: boolean;
13
+ clientCertificateCN?: string;
14
+ }
15
15
 
16
- export interface Certificate {
17
- private: string;
18
- public: string;
19
- cert: string;
20
- fingerprint: string;
21
- }
16
+ export interface Certificate {
17
+ private: string;
18
+ public: string;
19
+ cert: string;
20
+ fingerprint: string;
21
+ }
22
22
 
23
- export function generate(attrs?: Attributes, options?: Options): Certificate;
24
- export function generate(
25
- attrs: Attributes,
26
- options: Options,
27
- callback: (err: Error, certificate: Certificate) => void
28
- ): void;
23
+ export function generate(attrs?: Attributes, options?: Options): Certificate;
24
+ export function generate(
25
+ attrs: Attributes,
26
+ options: Options,
27
+ callback: (err: Error, certificate: Certificate) => void
28
+ ): void;
29
29
  }