wrangler 0.0.0-ece06ea → 0.0.0-ecfbb0c

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 (190) hide show
  1. package/Cloudflare_CA.pem +18 -0
  2. package/README.md +33 -14
  3. package/bin/wrangler.js +123 -25
  4. package/kv-asset-handler.js +1 -0
  5. package/miniflare-dist/index.mjs +4893 -0
  6. package/package.json +157 -116
  7. package/src/__tests__/config-cache.test.ts +36 -0
  8. package/src/__tests__/configuration.test.ts +3829 -0
  9. package/src/__tests__/dev.test.tsx +1159 -0
  10. package/src/__tests__/guess-worker-format.test.ts +85 -0
  11. package/src/__tests__/{clipboardy-mock.js → helpers/clipboardy-mock.js} +0 -0
  12. package/src/__tests__/helpers/cmd-shim.d.ts +11 -0
  13. package/src/__tests__/helpers/faye-websocket.d.ts +6 -0
  14. package/src/__tests__/helpers/mock-account-id.ts +48 -0
  15. package/src/__tests__/helpers/mock-bin.ts +36 -0
  16. package/src/__tests__/helpers/mock-cfetch.ts +211 -0
  17. package/src/__tests__/helpers/mock-console.ts +97 -0
  18. package/src/__tests__/helpers/mock-dialogs.ts +153 -0
  19. package/src/__tests__/helpers/mock-http-server.ts +46 -0
  20. package/src/__tests__/helpers/mock-istty.ts +74 -0
  21. package/src/__tests__/helpers/mock-kv.ts +33 -0
  22. package/src/__tests__/helpers/mock-oauth-flow.ts +250 -0
  23. package/src/__tests__/helpers/mock-process.ts +39 -0
  24. package/src/__tests__/helpers/mock-stdin.ts +108 -0
  25. package/src/__tests__/helpers/mock-web-socket.ts +29 -0
  26. package/src/__tests__/helpers/run-in-tmp.ts +39 -0
  27. package/src/__tests__/helpers/run-wrangler.ts +16 -0
  28. package/src/__tests__/helpers/write-worker-source.ts +31 -0
  29. package/src/__tests__/helpers/write-wrangler-toml.ts +17 -0
  30. package/src/__tests__/https-options.test.ts +130 -0
  31. package/src/__tests__/index.test.ts +255 -148
  32. package/src/__tests__/init.test.ts +1992 -0
  33. package/src/__tests__/jest.setup.ts +107 -0
  34. package/src/__tests__/kv.test.ts +1619 -0
  35. package/src/__tests__/logger.test.ts +141 -0
  36. package/src/__tests__/package-manager.test.ts +353 -0
  37. package/src/__tests__/pages.test.ts +1254 -0
  38. package/src/__tests__/parse.test.ts +330 -0
  39. package/src/__tests__/publish.test.ts +6513 -0
  40. package/src/__tests__/pubsub.test.ts +276 -0
  41. package/src/__tests__/r2.test.ts +233 -0
  42. package/src/__tests__/route.test.ts +45 -0
  43. package/src/__tests__/secret.test.ts +486 -0
  44. package/src/__tests__/tail.test.ts +690 -0
  45. package/src/__tests__/user.test.ts +143 -0
  46. package/src/__tests__/whoami.test.tsx +220 -0
  47. package/src/abort.d.ts +3 -0
  48. package/src/api/dev.ts +39 -0
  49. package/src/api/index.ts +1 -0
  50. package/src/bundle-reporter.tsx +29 -0
  51. package/src/bundle.ts +212 -0
  52. package/src/cfetch/index.ts +121 -0
  53. package/src/cfetch/internal.ts +149 -0
  54. package/src/cli.ts +25 -8
  55. package/src/config/README.md +107 -0
  56. package/src/config/config.ts +243 -0
  57. package/src/config/diagnostics.ts +80 -0
  58. package/src/config/environment.ts +430 -0
  59. package/src/config/index.ts +225 -0
  60. package/src/config/validation-helpers.ts +584 -0
  61. package/src/config/validation.ts +1693 -0
  62. package/src/config-cache.ts +44 -0
  63. package/src/create-worker-preview.ts +199 -0
  64. package/src/create-worker-upload-form.ts +254 -0
  65. package/src/dev/dev-vars.ts +36 -0
  66. package/src/dev/dev.tsx +417 -0
  67. package/src/dev/local.tsx +350 -0
  68. package/src/dev/remote.tsx +294 -0
  69. package/src/dev/use-esbuild.ts +150 -0
  70. package/src/dev.tsx +517 -727
  71. package/src/dialogs.tsx +116 -66
  72. package/src/durable.ts +102 -0
  73. package/src/entry.ts +328 -0
  74. package/src/environment-variables.ts +35 -0
  75. package/src/errors.ts +11 -0
  76. package/src/generate.ts +33 -0
  77. package/src/git-client.ts +42 -0
  78. package/src/https-options.ts +123 -0
  79. package/src/index.tsx +1845 -1828
  80. package/src/init.ts +549 -0
  81. package/src/inspect.ts +662 -0
  82. package/src/intl-polyfill.d.ts +139 -0
  83. package/src/kv.ts +408 -0
  84. package/src/logger.ts +73 -0
  85. package/src/miniflare-cli/README.md +30 -0
  86. package/src/miniflare-cli/enum-keys.ts +17 -0
  87. package/src/miniflare-cli/index.ts +52 -0
  88. package/src/miniflare-cli/request-context.ts +40 -0
  89. package/src/module-collection.ts +258 -0
  90. package/src/open-in-browser.ts +17 -0
  91. package/src/package-manager.ts +174 -0
  92. package/src/pages/build.tsx +202 -0
  93. package/src/pages/constants.ts +7 -0
  94. package/src/pages/deployments.tsx +101 -0
  95. package/src/pages/dev.tsx +964 -0
  96. package/src/pages/functions/buildPlugin.ts +105 -0
  97. package/src/pages/functions/buildWorker.ts +151 -0
  98. package/src/pages/functions/filepath-routing.test.ts +234 -0
  99. package/src/pages/functions/filepath-routing.ts +189 -0
  100. package/src/pages/functions/identifiers.ts +78 -0
  101. package/src/pages/functions/routes.ts +151 -0
  102. package/src/pages/index.tsx +84 -0
  103. package/src/pages/projects.tsx +157 -0
  104. package/src/pages/publish.tsx +335 -0
  105. package/src/pages/types.ts +40 -0
  106. package/src/pages/upload.tsx +384 -0
  107. package/src/pages/utils.ts +12 -0
  108. package/src/parse.ts +286 -0
  109. package/src/paths.ts +26 -0
  110. package/src/preview.ts +31 -0
  111. package/src/proxy.ts +476 -0
  112. package/src/publish.ts +755 -343
  113. package/src/pubsub/index.ts +286 -0
  114. package/src/pubsub/pubsub-commands.tsx +594 -0
  115. package/src/r2.ts +50 -0
  116. package/src/selfsigned.d.ts +29 -0
  117. package/src/sites.tsx +357 -100
  118. package/src/tail/filters.ts +279 -0
  119. package/src/tail/index.ts +299 -0
  120. package/src/tail/printing.ts +67 -0
  121. package/src/update-check.ts +19 -0
  122. package/src/user/choose-account.tsx +60 -0
  123. package/src/user/env-vars.ts +46 -0
  124. package/src/user/generate-auth-url.ts +33 -0
  125. package/src/user/generate-random-state.ts +16 -0
  126. package/src/user/index.ts +3 -0
  127. package/src/user/user.tsx +1130 -0
  128. package/src/whoami.tsx +90 -0
  129. package/src/worker.ts +185 -0
  130. package/src/zones.ts +76 -0
  131. package/templates/checked-fetch.js +17 -0
  132. package/templates/gitignore +171 -0
  133. package/templates/new-worker-scheduled.js +17 -0
  134. package/templates/new-worker-scheduled.ts +32 -0
  135. package/templates/new-worker.js +15 -0
  136. package/templates/new-worker.ts +30 -0
  137. package/templates/no-op-worker.js +10 -0
  138. package/templates/pages-template-plugin.ts +155 -0
  139. package/templates/pages-template-worker.ts +161 -0
  140. package/templates/static-asset-facade.js +43 -0
  141. package/templates/tsconfig.json +105 -0
  142. package/wrangler-dist/cli.js +104118 -113381
  143. package/src/__tests__/fixtures/init/.gitkeep +0 -0
  144. package/src/__tests__/mock-cfetch.js +0 -46
  145. package/src/api/form_data.ts +0 -158
  146. package/src/api/inspect.ts +0 -441
  147. package/src/api/preview.ts +0 -123
  148. package/src/api/worker.ts +0 -161
  149. package/src/cfetch.ts +0 -72
  150. package/src/config.ts +0 -124
  151. package/src/kv.tsx +0 -211
  152. package/src/pages.tsx +0 -344
  153. package/src/tail.tsx +0 -71
  154. package/src/user.tsx +0 -1029
  155. package/src/util/fetch.ts +0 -74
  156. package/static-asset-facade.js +0 -47
  157. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
  158. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
  159. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
  160. package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
  161. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
  162. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
  163. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
  164. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
  165. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
  166. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
  167. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
  168. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
  169. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
  170. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
  171. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
  172. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
  173. package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
  174. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
  175. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
  176. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
  177. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
  178. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
  179. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
  180. package/vendor/wrangler-mime/CHANGELOG.md +0 -289
  181. package/vendor/wrangler-mime/LICENSE +0 -21
  182. package/vendor/wrangler-mime/Mime.js +0 -97
  183. package/vendor/wrangler-mime/README.md +0 -187
  184. package/vendor/wrangler-mime/cli.js +0 -46
  185. package/vendor/wrangler-mime/index.js +0 -4
  186. package/vendor/wrangler-mime/lite.js +0 -4
  187. package/vendor/wrangler-mime/package.json +0 -52
  188. package/vendor/wrangler-mime/types/other.js +0 -1
  189. package/vendor/wrangler-mime/types/standard.js +0 -1
  190. package/wrangler-dist/cli.js.map +0 -7
@@ -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 ADDED
@@ -0,0 +1,50 @@
1
+ import { fetchResult } from "./cfetch";
2
+
3
+ /**
4
+ * Information about a bucket, returned from `listR2Buckets()`.
5
+ */
6
+ export interface R2BucketInfo {
7
+ name: string;
8
+ creation_date: string;
9
+ }
10
+
11
+ /**
12
+ * Fetch a list of all the buckets under the given `accountId`.
13
+ */
14
+ export async function listR2Buckets(
15
+ accountId: string
16
+ ): Promise<R2BucketInfo[]> {
17
+ const results = await fetchResult<{
18
+ buckets: R2BucketInfo[];
19
+ }>(`/accounts/${accountId}/r2/buckets`);
20
+ return results.buckets;
21
+ }
22
+
23
+ /**
24
+ * Create a bucket with the given `bucketName` within the account given by `accountId`.
25
+ *
26
+ * A 400 is returned if the account already owns a bucket with this name.
27
+ * A bucket must be explicitly deleted to be replaced.
28
+ */
29
+ export async function createR2Bucket(
30
+ accountId: string,
31
+ bucketName: string
32
+ ): Promise<void> {
33
+ return await fetchResult<void>(
34
+ `/accounts/${accountId}/r2/buckets/${bucketName}`,
35
+ { method: "PUT" }
36
+ );
37
+ }
38
+
39
+ /**
40
+ * Delete a bucket with the given name
41
+ */
42
+ export async function deleteR2Bucket(
43
+ accountId: string,
44
+ bucketName: string
45
+ ): Promise<void> {
46
+ return await fetchResult<void>(
47
+ `/accounts/${accountId}/r2/buckets/${bucketName}`,
48
+ { method: "DELETE" }
49
+ );
50
+ }
@@ -0,0 +1,29 @@
1
+ declare module "selfsigned" {
2
+ import type { pki } from "node-forge";
3
+
4
+ export type Attributes = pki.CertificateField[];
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
+ }
15
+
16
+ export interface Certificate {
17
+ private: string;
18
+ public: string;
19
+ cert: string;
20
+ fingerprint: string;
21
+ }
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;
29
+ }