wrangler 2.0.12 → 2.0.16

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