@devultur/convex 1.0.1 → 1.0.2

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.
package/README.md CHANGED
@@ -49,6 +49,52 @@ function CoverUpload({ onSaved }) {
49
49
  }
50
50
  ```
51
51
 
52
+ ## Using a self-hosted Worker
53
+
54
+ The component talks to any Worker built with `createWorker()` from
55
+ [`@devultur/self-host`](https://github.com/devultur/devultur/tree/main/packages/self-host) (see the
56
+ [self-host guide](https://github.com/devultur/devultur/blob/main/docs/guides/self-host.md)). It needs two values:
57
+
58
+ | Convex env var | Value |
59
+ | --- | --- |
60
+ | `DEVULTUR_API_URL` | The Worker's origin, without a trailing slash, for example `https://media.example.com` |
61
+ | `DEVULTUR_SECRET` | The Worker's `WORKER_AUTH_SECRET`, the same string you set with `wrangler secret put` |
62
+
63
+ Declare both in your app and bind them to the component. Convex rejects `app.env.<NAME>` for a name that
64
+ `defineApp()` doesn't declare:
65
+
66
+ ```typescript
67
+ // convex/convex.config.ts
68
+ import devultur from "@devultur/convex/convex.config";
69
+ import { defineApp } from "convex/server";
70
+ import { v } from "convex/values";
71
+
72
+ const app = defineApp({ env: { DEVULTUR_SECRET: v.string(), DEVULTUR_API_URL: v.string() } });
73
+ app.use(devultur, {
74
+ httpPrefix: "/devultur/",
75
+ env: { DEVULTUR_SECRET: app.env.DEVULTUR_SECRET, DEVULTUR_API_URL: app.env.DEVULTUR_API_URL },
76
+ });
77
+
78
+ export default app;
79
+ ```
80
+
81
+ ```bash
82
+ npx convex env set DEVULTUR_API_URL https://media.example.com
83
+ npx convex env set DEVULTUR_SECRET <the Worker's WORKER_AUTH_SECRET>
84
+ ```
85
+
86
+ **Webhooks.** You don't configure anything else. `processVideo` sends the Worker a `callbackUrl` that points at
87
+ the component's route, `<CONVEX_SITE_URL>/devultur/webhook`. The transcode runner reports to the Worker with
88
+ `TRANSCODE_WEBHOOK_SECRET`. The Worker then forwards each event to the `callbackUrl` with
89
+ `Authorization: Bearer <WORKER_AUTH_SECRET>`. The component accepts an event only when that bearer equals
90
+ `DEVULTUR_SECRET`. If `DEVULTUR_SECRET` is wrong or missing, the component answers `401` to every event. Keep
91
+ `TRANSCODE_WEBHOOK_SECRET` on the Worker only: the component never needs it.
92
+
93
+ If you replace the Worker's `workerSecretAuth()` plugin with an auth plugin of your own, the Worker forwards
94
+ webhooks with the `webhookCredential` your plugin sets in the request state (or `runnerCredential` when it sets
95
+ none; see [Plugins](https://github.com/devultur/devultur/blob/main/docs/guides/plugins.md)). Set `DEVULTUR_SECRET`
96
+ to that value, and make sure your plugin also accepts it as the bearer of the component's calls.
97
+
52
98
  ## Documentation
53
99
 
54
100
  Guides and API reference: [github.com/devultur/devultur/tree/main/docs](https://github.com/devultur/devultur/tree/main/docs).
package/dist/bin/init.js CHANGED
@@ -22,9 +22,10 @@ function patchConvexConfig() {
22
22
  const useLine = 'app.use(devultur, { httpPrefix: "/devultur/", env: { DEVULTUR_SECRET: app.env.DEVULTUR_SECRET, DEVULTUR_API_URL: app.env.DEVULTUR_API_URL } });';
23
23
  if (!existsSync(configPath)) {
24
24
  const content2 = `import { defineApp } from "convex/server";
25
+ import { v } from "convex/values";
25
26
  ${importLine}
26
27
 
27
- const app = defineApp();
28
+ const app = defineApp({ env: { DEVULTUR_SECRET: v.string(), DEVULTUR_API_URL: v.string() } });
28
29
  ${useLine}
29
30
 
30
31
  export default app;
@@ -54,6 +55,10 @@ ${content.slice(exportIndex)}`;
54
55
  }
55
56
  writeFileSync(configPath, content);
56
57
  log("\u2705 Patched convex/convex.config.ts with devultur component");
58
+ if (!/DEVULTUR_SECRET:\s*v\./.test(content)) {
59
+ log("\u26A0\uFE0F Declare the env vars it binds in defineApp(), or Convex rejects the config:");
60
+ log(" defineApp({ env: { DEVULTUR_SECRET: v.string(), DEVULTUR_API_URL: v.string() } })");
61
+ }
57
62
  }
58
63
  function createDevulturModule() {
59
64
  const modulePath = join(CONVEX_DIR, "devultur.ts");
@@ -19,13 +19,13 @@ declare const dv: {
19
19
  kind: DevulturKind;
20
20
  visibility: "public" | "private";
21
21
  }, {
22
- kind: convex_values.VLiteral<DevulturKind, "required"> | convex_values.VUnion<"image" | "video" | "file", [convex_values.VLiteral<"image", "required">, convex_values.VLiteral<"video", "required">, convex_values.VLiteral<"file", "required">], "required", never>;
22
+ kind: convex_values.VLiteral<DevulturKind, "required"> | convex_values.VUnion<"video" | "image" | "file", [convex_values.VLiteral<"image", "required">, convex_values.VLiteral<"video", "required">, convex_values.VLiteral<"file", "required">], "required", never>;
23
23
  id: convex_values.VString<string, "required">;
24
24
  visibility: convex_values.VUnion<"public" | "private", [convex_values.VLiteral<"public", "required">, convex_values.VLiteral<"private", "required">], "required", never>;
25
25
  filename: convex_values.VString<string | undefined, "optional">;
26
26
  width: convex_values.VFloat64<number | undefined, "optional">;
27
27
  height: convex_values.VFloat64<number | undefined, "optional">;
28
- }, "required", "id" | "kind" | "visibility" | "filename" | "width" | "height">;
28
+ }, "required", "filename" | "id" | "kind" | "visibility" | "width" | "height">;
29
29
  };
30
30
 
31
31
  export { dv };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devultur/convex",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Convex component for Devultur media: media records, uploads, transcodes, watch progress and React bindings",
5
5
  "keywords": [
6
6
  "convex",
@@ -51,8 +51,8 @@
51
51
  "dist"
52
52
  ],
53
53
  "dependencies": {
54
- "@devultur/react": "1.0.1",
55
- "@devultur/core": "1.0.1"
54
+ "@devultur/core": "1.0.2",
55
+ "@devultur/react": "1.0.2"
56
56
  },
57
57
  "peerDependencies": {
58
58
  "convex": ">=1.25.0",