wrangler 0.0.0-e9ab55a → 0.0.0-e9e9872

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 (201) hide show
  1. package/Cloudflare_CA.pem +18 -0
  2. package/README.md +33 -14
  3. package/bin/wrangler.js +126 -25
  4. package/kv-asset-handler.js +1 -0
  5. package/miniflare-dist/index.mjs +4894 -0
  6. package/package.json +159 -125
  7. package/src/__tests__/config-cache-without-cache-dir.test.ts +38 -0
  8. package/src/__tests__/config-cache.test.ts +42 -0
  9. package/src/__tests__/configuration.test.ts +3946 -0
  10. package/src/__tests__/dev.test.tsx +1155 -63
  11. package/src/__tests__/guess-worker-format.test.ts +85 -0
  12. package/src/__tests__/{clipboardy-mock.js → helpers/clipboardy-mock.js} +0 -0
  13. package/src/__tests__/helpers/cmd-shim.d.ts +11 -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 +38 -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 +163 -0
  31. package/src/__tests__/index.test.ts +259 -284
  32. package/src/__tests__/init.test.ts +1992 -0
  33. package/src/__tests__/jest.setup.ts +108 -10
  34. package/src/__tests__/kv.test.ts +1433 -909
  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 +6586 -93
  40. package/src/__tests__/pubsub.test.ts +367 -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 +492 -0
  44. package/src/__tests__/tail.test.ts +698 -0
  45. package/src/__tests__/user.test.ts +143 -0
  46. package/src/__tests__/whoami.test.tsx +230 -0
  47. package/src/__tests__/worker-namespace.test.ts +327 -0
  48. package/src/abort.d.ts +3 -0
  49. package/src/api/dev.ts +52 -0
  50. package/src/api/index.ts +1 -0
  51. package/src/bundle-reporter.tsx +29 -0
  52. package/src/bundle.ts +212 -0
  53. package/src/cfetch/index.ts +88 -69
  54. package/src/cfetch/internal.ts +124 -44
  55. package/src/cli.ts +24 -6
  56. package/src/config/README.md +107 -0
  57. package/src/config/config.ts +243 -0
  58. package/src/config/diagnostics.ts +80 -0
  59. package/src/config/environment.ts +453 -0
  60. package/src/config/index.ts +238 -0
  61. package/src/config/validation-helpers.ts +584 -0
  62. package/src/config/validation.ts +1745 -0
  63. package/src/config-cache.ts +83 -0
  64. package/src/create-worker-preview.ts +255 -0
  65. package/src/create-worker-upload-form.ts +263 -0
  66. package/src/dev/dev-vars.ts +36 -0
  67. package/src/dev/dev.tsx +417 -0
  68. package/src/dev/local.tsx +354 -0
  69. package/src/dev/remote.tsx +382 -0
  70. package/src/dev/use-esbuild.ts +150 -0
  71. package/src/dev.tsx +527 -773
  72. package/src/dialogs.tsx +117 -59
  73. package/src/durable.ts +102 -0
  74. package/src/entry.ts +328 -0
  75. package/src/environment-variables.ts +35 -0
  76. package/src/errors.ts +11 -0
  77. package/src/faye-websocket.d.ts +6 -0
  78. package/src/generate.ts +33 -0
  79. package/src/git-client.ts +42 -0
  80. package/src/global-wrangler-config-path.ts +26 -0
  81. package/src/https-options.ts +127 -0
  82. package/src/index.tsx +1869 -1901
  83. package/src/init.ts +549 -0
  84. package/src/inspect.ts +615 -496
  85. package/src/intl-polyfill.d.ts +139 -0
  86. package/src/is-interactive.ts +12 -0
  87. package/src/kv.ts +430 -0
  88. package/src/logger.ts +73 -0
  89. package/src/miniflare-cli/README.md +30 -0
  90. package/src/miniflare-cli/enum-keys.ts +17 -0
  91. package/src/miniflare-cli/index.ts +53 -0
  92. package/src/miniflare-cli/request-context.ts +40 -0
  93. package/src/module-collection.ts +247 -53
  94. package/src/open-in-browser.ts +17 -0
  95. package/src/package-manager.ts +219 -0
  96. package/src/pages/build.tsx +202 -0
  97. package/src/pages/constants.ts +7 -0
  98. package/src/pages/deployments.tsx +101 -0
  99. package/src/pages/dev.tsx +964 -0
  100. package/src/pages/functions/buildPlugin.ts +105 -0
  101. package/src/pages/functions/buildWorker.ts +151 -0
  102. package/src/pages/functions/filepath-routing.test.ts +234 -0
  103. package/src/pages/functions/filepath-routing.ts +189 -0
  104. package/src/pages/functions/identifiers.ts +78 -0
  105. package/src/pages/functions/routes.ts +151 -0
  106. package/src/pages/index.tsx +84 -0
  107. package/src/pages/projects.tsx +157 -0
  108. package/src/pages/publish.tsx +335 -0
  109. package/src/pages/types.ts +40 -0
  110. package/src/pages/upload.tsx +396 -0
  111. package/src/pages/utils.ts +12 -0
  112. package/src/parse.ts +286 -0
  113. package/src/paths.ts +26 -0
  114. package/src/preview.ts +31 -0
  115. package/src/proxy.ts +428 -254
  116. package/src/publish.ts +764 -366
  117. package/src/pubsub/index.ts +286 -0
  118. package/src/pubsub/pubsub-commands.tsx +577 -0
  119. package/src/r2.ts +50 -0
  120. package/src/selfsigned.d.ts +29 -0
  121. package/src/sites.tsx +357 -103
  122. package/src/tail/filters.ts +279 -0
  123. package/src/tail/index.ts +299 -0
  124. package/src/tail/printing.ts +67 -0
  125. package/src/update-check.ts +19 -0
  126. package/src/user/choose-account.tsx +60 -0
  127. package/src/user/env-vars.ts +46 -0
  128. package/src/user/generate-auth-url.ts +33 -0
  129. package/src/user/generate-random-state.ts +16 -0
  130. package/src/user/index.ts +3 -0
  131. package/src/user/user.tsx +1170 -0
  132. package/src/whoami.tsx +90 -0
  133. package/src/worker-namespace.ts +190 -0
  134. package/src/worker.ts +191 -0
  135. package/src/zones.ts +76 -0
  136. package/templates/checked-fetch.js +17 -0
  137. package/templates/gitignore +171 -0
  138. package/templates/new-worker-scheduled.js +17 -0
  139. package/templates/new-worker-scheduled.ts +32 -0
  140. package/templates/new-worker.js +15 -0
  141. package/templates/new-worker.ts +30 -0
  142. package/templates/no-op-worker.js +10 -0
  143. package/templates/pages-template-plugin.ts +155 -0
  144. package/templates/pages-template-worker.ts +161 -0
  145. package/templates/static-asset-facade.js +49 -0
  146. package/templates/tsconfig.json +105 -0
  147. package/wrangler-dist/cli.d.ts +298 -0
  148. package/wrangler-dist/cli.js +107673 -103262
  149. package/pages/functions/buildWorker.ts +0 -62
  150. package/pages/functions/filepath-routing.test.ts +0 -39
  151. package/pages/functions/filepath-routing.ts +0 -228
  152. package/pages/functions/identifiers.ts +0 -78
  153. package/pages/functions/routes.ts +0 -158
  154. package/pages/functions/template-worker.ts +0 -136
  155. package/src/__tests__/mock-cfetch.ts +0 -171
  156. package/src/__tests__/mock-dialogs.ts +0 -65
  157. package/src/__tests__/run-in-tmp.ts +0 -19
  158. package/src/__tests__/run-wrangler.ts +0 -32
  159. package/src/api/form_data.ts +0 -131
  160. package/src/api/preview.ts +0 -128
  161. package/src/api/worker.ts +0 -155
  162. package/src/config.ts +0 -646
  163. package/src/kv.tsx +0 -276
  164. package/src/pages.tsx +0 -1040
  165. package/src/tail.tsx +0 -73
  166. package/src/user.tsx +0 -1027
  167. package/static-asset-facade.js +0 -47
  168. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
  169. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
  170. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
  171. package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
  172. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
  173. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
  174. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
  175. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
  176. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
  177. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
  178. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
  179. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
  180. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
  181. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
  182. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
  183. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
  184. package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
  185. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
  186. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
  187. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
  188. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
  189. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
  190. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
  191. package/vendor/wrangler-mime/CHANGELOG.md +0 -289
  192. package/vendor/wrangler-mime/LICENSE +0 -21
  193. package/vendor/wrangler-mime/Mime.js +0 -97
  194. package/vendor/wrangler-mime/README.md +0 -187
  195. package/vendor/wrangler-mime/cli.js +0 -46
  196. package/vendor/wrangler-mime/index.js +0 -4
  197. package/vendor/wrangler-mime/lite.js +0 -4
  198. package/vendor/wrangler-mime/package.json +0 -52
  199. package/vendor/wrangler-mime/types/other.js +0 -1
  200. package/vendor/wrangler-mime/types/standard.js +0 -1
  201. package/wrangler-dist/cli.js.map +0 -7
@@ -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 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
+ }