@samebase/convex-hosting 0.3.2 → 0.4.1
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/CHANGELOG.md +17 -132
- package/README.md +188 -406
- package/dist/cli/convex.d.ts +63 -0
- package/dist/cli/convex.js +108 -0
- package/dist/cli/convex.js.map +1 -0
- package/dist/cli/files.d.ts +18 -0
- package/dist/cli/files.js +106 -0
- package/dist/cli/files.js.map +1 -0
- package/dist/cli/index.d.ts +1 -11
- package/dist/cli/index.js +3 -58
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/main.d.ts +5 -0
- package/dist/cli/main.js +377 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/client/index.d.ts +8 -115
- package/dist/client/index.js +65 -242
- package/dist/client/index.js.map +1 -1
- package/dist/client/types.d.ts +5 -0
- package/dist/client/version-module.d.ts +6 -0
- package/dist/component/_generated/api.d.ts +0 -5
- package/dist/component/_generated/api.js.map +1 -1
- package/dist/component/_generated/component.d.ts +20 -18
- package/dist/component/_generated/dataModel.d.ts +0 -1
- package/dist/component/_generated/server.d.ts +12 -1
- package/dist/component/_generated/server.js +2 -0
- package/dist/component/_generated/server.js.map +1 -1
- package/dist/component/convex.config.d.ts +0 -1
- package/dist/component/lib.d.ts +175 -156
- package/dist/component/lib.js +396 -710
- package/dist/component/lib.js.map +1 -1
- package/dist/component/schema.d.ts +76 -72
- package/dist/component/schema.js +35 -59
- package/dist/component/schema.js.map +1 -1
- package/dist/workers-shared/asset-worker/src/analytics.d.ts +39 -0
- package/dist/workers-shared/asset-worker/src/analytics.js +86 -0
- package/dist/workers-shared/asset-worker/src/analytics.js.map +1 -0
- package/dist/workers-shared/asset-worker/src/compatibility-flags.d.ts +19 -0
- package/dist/workers-shared/asset-worker/src/compatibility-flags.js +29 -0
- package/dist/workers-shared/asset-worker/src/compatibility-flags.js.map +1 -0
- package/dist/workers-shared/asset-worker/src/configuration.d.ts +3 -0
- package/dist/workers-shared/asset-worker/src/configuration.js +30 -0
- package/dist/workers-shared/asset-worker/src/configuration.js.map +1 -0
- package/dist/workers-shared/asset-worker/src/constants.d.ts +1 -0
- package/dist/workers-shared/asset-worker/src/constants.js +3 -0
- package/dist/workers-shared/asset-worker/src/constants.js.map +1 -0
- package/dist/workers-shared/asset-worker/src/handler.d.ts +28 -0
- package/dist/workers-shared/asset-worker/src/handler.js +717 -0
- package/dist/workers-shared/asset-worker/src/handler.js.map +1 -0
- package/dist/workers-shared/asset-worker/src/types.d.ts +13 -0
- package/dist/workers-shared/asset-worker/src/types.js +2 -0
- package/dist/workers-shared/asset-worker/src/types.js.map +1 -0
- package/dist/workers-shared/asset-worker/src/utils/base-path.d.ts +29 -0
- package/dist/workers-shared/asset-worker/src/utils/base-path.js +56 -0
- package/dist/workers-shared/asset-worker/src/utils/base-path.js.map +1 -0
- package/dist/workers-shared/asset-worker/src/utils/headers.d.ts +11 -0
- package/dist/workers-shared/asset-worker/src/utils/headers.js +77 -0
- package/dist/workers-shared/asset-worker/src/utils/headers.js.map +1 -0
- package/dist/workers-shared/asset-worker/src/utils/rules-engine.d.ts +23 -0
- package/dist/workers-shared/asset-worker/src/utils/rules-engine.js +133 -0
- package/dist/workers-shared/asset-worker/src/utils/rules-engine.js.map +1 -0
- package/dist/workers-shared/asset-worker/src/worker.d.ts +14 -0
- package/dist/workers-shared/asset-worker/src/worker.js +12 -0
- package/dist/workers-shared/asset-worker/src/worker.js.map +1 -0
- package/dist/workers-shared/utils/base-path.d.ts +32 -0
- package/dist/workers-shared/utils/base-path.js +94 -0
- package/dist/workers-shared/utils/base-path.js.map +1 -0
- package/dist/workers-shared/utils/configuration/constants.d.ts +15 -0
- package/dist/workers-shared/utils/configuration/constants.js +16 -0
- package/dist/workers-shared/utils/configuration/constants.js.map +1 -0
- package/dist/workers-shared/utils/configuration/constructConfiguration.d.ts +12 -0
- package/dist/workers-shared/utils/configuration/constructConfiguration.js +103 -0
- package/dist/workers-shared/utils/configuration/constructConfiguration.js.map +1 -0
- package/dist/workers-shared/utils/configuration/parseHeaders.d.ts +5 -0
- package/dist/workers-shared/utils/configuration/parseHeaders.js +181 -0
- package/dist/workers-shared/utils/configuration/parseHeaders.js.map +1 -0
- package/dist/workers-shared/utils/configuration/parseRedirects.d.ts +8 -0
- package/dist/workers-shared/utils/configuration/parseRedirects.js +129 -0
- package/dist/workers-shared/utils/configuration/parseRedirects.js.map +1 -0
- package/dist/workers-shared/utils/configuration/parseStaticRouting.d.ts +2 -0
- package/dist/workers-shared/utils/configuration/parseStaticRouting.js +94 -0
- package/dist/workers-shared/utils/configuration/parseStaticRouting.js.map +1 -0
- package/dist/workers-shared/utils/configuration/types.d.ts +38 -0
- package/dist/workers-shared/utils/configuration/types.js +2 -0
- package/dist/workers-shared/utils/configuration/types.js.map +1 -0
- package/dist/workers-shared/utils/configuration/validateURL.d.ts +3 -0
- package/dist/workers-shared/utils/configuration/validateURL.js +56 -0
- package/dist/workers-shared/utils/configuration/validateURL.js.map +1 -0
- package/dist/workers-shared/utils/constants.d.ts +28 -0
- package/dist/workers-shared/utils/constants.js +34 -0
- package/dist/workers-shared/utils/constants.js.map +1 -0
- package/dist/workers-shared/utils/helpers.d.ts +22 -0
- package/dist/workers-shared/utils/helpers.js +73 -0
- package/dist/workers-shared/utils/helpers.js.map +1 -0
- package/dist/workers-shared/utils/responses.d.ts +43 -0
- package/dist/workers-shared/utils/responses.js +125 -0
- package/dist/workers-shared/utils/responses.js.map +1 -0
- package/dist/workers-shared/utils/tracing.d.ts +3 -0
- package/dist/workers-shared/utils/tracing.js +29 -0
- package/dist/workers-shared/utils/tracing.js.map +1 -0
- package/dist/workers-shared/utils/types.d.ts +131 -0
- package/dist/workers-shared/utils/types.js +72 -0
- package/dist/workers-shared/utils/types.js.map +1 -0
- package/package.json +21 -37
- package/INTEGRATION.md +0 -399
- package/dist/cli/args.d.ts +0 -28
- package/dist/cli/args.d.ts.map +0 -1
- package/dist/cli/args.js +0 -148
- package/dist/cli/args.js.map +0 -1
- package/dist/cli/argumentChunks.d.ts +0 -3
- package/dist/cli/argumentChunks.d.ts.map +0 -1
- package/dist/cli/argumentChunks.js +0 -29
- package/dist/cli/argumentChunks.js.map +0 -1
- package/dist/cli/collectFiles.d.ts +0 -10
- package/dist/cli/collectFiles.d.ts.map +0 -1
- package/dist/cli/collectFiles.js +0 -53
- package/dist/cli/collectFiles.js.map +0 -1
- package/dist/cli/commands.d.ts +0 -8
- package/dist/cli/commands.d.ts.map +0 -1
- package/dist/cli/commands.js +0 -56
- package/dist/cli/commands.js.map +0 -1
- package/dist/cli/componentName.d.ts +0 -32
- package/dist/cli/componentName.d.ts.map +0 -1
- package/dist/cli/componentName.js +0 -43
- package/dist/cli/componentName.js.map +0 -1
- package/dist/cli/deploy.d.ts +0 -16
- package/dist/cli/deploy.d.ts.map +0 -1
- package/dist/cli/deploy.js +0 -283
- package/dist/cli/deploy.js.map +0 -1
- package/dist/cli/deployEnvironment.d.ts +0 -10
- package/dist/cli/deployEnvironment.d.ts.map +0 -1
- package/dist/cli/deployEnvironment.js +0 -12
- package/dist/cli/deployEnvironment.js.map +0 -1
- package/dist/cli/index.d.ts.map +0 -1
- package/dist/cli/upload.d.ts +0 -22
- package/dist/cli/upload.d.ts.map +0 -1
- package/dist/cli/upload.js +0 -630
- package/dist/cli/upload.js.map +0 -1
- package/dist/client/_generated/_ignore.d.ts +0 -1
- package/dist/client/_generated/_ignore.d.ts.map +0 -1
- package/dist/client/_generated/_ignore.js +0 -3
- package/dist/client/_generated/_ignore.js.map +0 -1
- package/dist/client/index.d.ts.map +0 -1
- package/dist/component/_generated/api.d.ts.map +0 -1
- package/dist/component/_generated/component.d.ts.map +0 -1
- package/dist/component/_generated/dataModel.d.ts.map +0 -1
- package/dist/component/_generated/server.d.ts.map +0 -1
- package/dist/component/convex.config.d.ts.map +0 -1
- package/dist/component/http.d.ts +0 -4
- package/dist/component/http.d.ts.map +0 -1
- package/dist/component/http.js +0 -113
- package/dist/component/http.js.map +0 -1
- package/dist/component/lib.d.ts.map +0 -1
- package/dist/component/schema.d.ts.map +0 -1
- package/dist/component/serving.d.ts +0 -23
- package/dist/component/serving.d.ts.map +0 -1
- package/dist/component/serving.js +0 -161
- package/dist/component/serving.js.map +0 -1
- package/dist/react/index.d.ts +0 -59
- package/dist/react/index.d.ts.map +0 -1
- package/dist/react/index.js +0 -137
- package/dist/react/index.js.map +0 -1
- package/src/cli/args.test.ts +0 -79
- package/src/cli/args.ts +0 -153
- package/src/cli/argumentChunks.test.ts +0 -27
- package/src/cli/argumentChunks.ts +0 -40
- package/src/cli/collectFiles.test.ts +0 -26
- package/src/cli/collectFiles.ts +0 -59
- package/src/cli/commands.ts +0 -68
- package/src/cli/componentName.test.ts +0 -41
- package/src/cli/componentName.ts +0 -46
- package/src/cli/deploy.ts +0 -336
- package/src/cli/deployEnvironment.test.ts +0 -27
- package/src/cli/deployEnvironment.ts +0 -17
- package/src/cli/index.ts +0 -65
- package/src/cli/upload.ts +0 -837
- package/src/client/_generated/_ignore.ts +0 -1
- package/src/client/index.test.ts +0 -549
- package/src/client/index.ts +0 -344
- package/src/client/setup.test.ts +0 -22
- package/src/component/_generated/api.ts +0 -54
- package/src/component/_generated/component.ts +0 -55
- package/src/component/_generated/dataModel.ts +0 -60
- package/src/component/_generated/server.ts +0 -156
- package/src/component/convex.config.ts +0 -3
- package/src/component/http.test.ts +0 -254
- package/src/component/http.ts +0 -133
- package/src/component/lib.test.ts +0 -1007
- package/src/component/lib.ts +0 -862
- package/src/component/schema.ts +0 -75
- package/src/component/serving.ts +0 -170
- package/src/component/setup.test.ts +0 -11
- package/src/react/index.tsx +0 -197
- package/src/test.ts +0 -23
package/dist/client/index.js
CHANGED
|
@@ -1,260 +1,83 @@
|
|
|
1
|
-
import { httpActionGeneric, queryGeneric, } from "convex/server";
|
|
2
|
-
import { v } from "convex/values";
|
|
3
|
-
import { cacheControlFor, decodeRequestPath, errorResponse, etagMatches, getMimeType, getSetupHtml, isHtmlContentType, } from "../component/serving.js";
|
|
4
|
-
const deploymentInfoValidator = v.object({
|
|
5
|
-
_id: v.string(),
|
|
6
|
-
_creationTime: v.number(),
|
|
7
|
-
currentDeploymentId: v.string(),
|
|
8
|
-
deployedAt: v.number(),
|
|
9
|
-
spaFallback: v.optional(v.boolean()),
|
|
10
|
-
});
|
|
11
1
|
/**
|
|
12
|
-
*
|
|
2
|
+
* Answers `request` with the asset of version `versionId` that Cloudflare's asset handler picks.
|
|
13
3
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```typescript
|
|
21
|
-
* // convex/convex.config.ts
|
|
22
|
-
* const app = defineApp();
|
|
23
|
-
* app.use(hosting); // no httpPrefix: the app owns HTTP routing
|
|
24
|
-
*
|
|
25
|
-
* // convex/http.ts
|
|
26
|
-
* const http = httpRouter();
|
|
27
|
-
* auth.addHttpRoutes(http);
|
|
28
|
-
* registerStaticRoutes(http, components.hosting);
|
|
29
|
-
* export default http;
|
|
30
|
-
* ```
|
|
4
|
+
* Returns `null` when no asset matches, so the app continues (a static site answers 404, a
|
|
5
|
+
* server-rendered site renders the page). A version that does not exist, is still uploading, or
|
|
6
|
+
* is being deleted answers 404, so a half-installed site does not render pages without their
|
|
7
|
+
* files. The first request for a `ready` version marks it live, which deletes the versions that
|
|
8
|
+
* were live before it.
|
|
31
9
|
*/
|
|
32
|
-
export function
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const decodedPath = decodeRequestPath(new URL(request.url).pathname);
|
|
39
|
-
if (decodedPath === null) {
|
|
40
|
-
return errorResponse(400, "Bad Request");
|
|
41
|
-
}
|
|
42
|
-
let path = decodedPath;
|
|
43
|
-
if (normalizedPrefix && path.startsWith(normalizedPrefix)) {
|
|
44
|
-
path = path.slice(normalizedPrefix.length) || "/";
|
|
45
|
-
}
|
|
46
|
-
if (path === "" || path === "/") {
|
|
47
|
-
path = "/index.html";
|
|
48
|
-
}
|
|
49
|
-
const response = await serveAsset(ctx, component, request, path, {
|
|
50
|
-
spaFallback,
|
|
51
|
-
cdnBaseUrl,
|
|
52
|
-
});
|
|
53
|
-
if (response)
|
|
54
|
-
return response;
|
|
55
|
-
if (path === "/index.html") {
|
|
56
|
-
return new Response(getSetupHtml(), {
|
|
57
|
-
status: 503,
|
|
58
|
-
headers: {
|
|
59
|
-
"Content-Type": "text/html; charset=utf-8",
|
|
60
|
-
"Cache-Control": "no-store",
|
|
61
|
-
"Retry-After": "5",
|
|
62
|
-
},
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
return errorResponse(404, "Not Found");
|
|
66
|
-
});
|
|
67
|
-
http.route({
|
|
68
|
-
pathPrefix: pathPrefix === "/" ? "/" : `${normalizedPrefix}/`,
|
|
69
|
-
method: "GET",
|
|
70
|
-
handler: serveStaticFile,
|
|
10
|
+
export async function serveAsset(ctx, component, request, versionId) {
|
|
11
|
+
const { state, newestLiveAt, asset } = await ctx.runQuery(component.lib.route, {
|
|
12
|
+
versionId,
|
|
13
|
+
method: request.method,
|
|
14
|
+
url: request.url,
|
|
15
|
+
headers: handlerHeaders(request.headers),
|
|
71
16
|
});
|
|
72
|
-
if (
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
17
|
+
if (state === null || state === "uploading" || state === "deleting") {
|
|
18
|
+
const problem = state === null
|
|
19
|
+
? "does not exist"
|
|
20
|
+
: state === "uploading"
|
|
21
|
+
? "is still uploading"
|
|
22
|
+
: "is being deleted";
|
|
23
|
+
return new Response(`Version ${versionId} of the site ${problem}.`, {
|
|
24
|
+
status: 404,
|
|
25
|
+
headers: NO_STORE,
|
|
77
26
|
});
|
|
78
27
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
*
|
|
85
|
-
* Found files get the same response as `registerStaticRoutes`: content type,
|
|
86
|
-
* cache headers, ETag revalidation, and legacy CDN redirects. A found file
|
|
87
|
-
* whose storage can't be read gets a 500 response. A request path with
|
|
88
|
-
* malformed percent-encoding matches no file, so it returns null.
|
|
89
|
-
*
|
|
90
|
-
* The lookup is exact by default. `/` is not mapped to `/index.html`, and there
|
|
91
|
-
* is no SPA fallback, so the SPA shell never answers for a route your action
|
|
92
|
-
* handles. To serve the shell, pass `{ path: "/index.html" }`. When your route
|
|
93
|
-
* has a prefix, pass `path` with the prefix removed.
|
|
94
|
-
*
|
|
95
|
-
* @example
|
|
96
|
-
* ```typescript
|
|
97
|
-
* // convex/http.ts
|
|
98
|
-
* const http = httpRouter();
|
|
99
|
-
* http.route({
|
|
100
|
-
* pathPrefix: "/",
|
|
101
|
-
* method: "GET",
|
|
102
|
-
* handler: httpAction(async (ctx, request) => {
|
|
103
|
-
* const file = await serveStaticAsset(ctx, components.hosting, request);
|
|
104
|
-
* if (file) return file;
|
|
105
|
-
* return await renderPage(request);
|
|
106
|
-
* }),
|
|
107
|
-
* });
|
|
108
|
-
* export default http;
|
|
109
|
-
* ```
|
|
110
|
-
*/
|
|
111
|
-
export async function serveStaticAsset(ctx, component, request, { path, spaFallback = false, cdnBaseUrl, } = {}) {
|
|
112
|
-
if (path !== undefined && !path.startsWith("/")) {
|
|
113
|
-
throw new Error("path must start with /");
|
|
114
|
-
}
|
|
115
|
-
const filePath = path ?? decodeRequestPath(new URL(request.url).pathname);
|
|
116
|
-
if (filePath === null)
|
|
117
|
-
return null;
|
|
118
|
-
return await serveAsset(ctx, component, request, filePath, {
|
|
119
|
-
spaFallback,
|
|
120
|
-
cdnBaseUrl,
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
export { decodeRequestPath };
|
|
124
|
-
/**
|
|
125
|
-
* Serve the uploaded file at `path` (decoded, relative to the mount prefix),
|
|
126
|
-
* or return null when no file matches. An undefined `spaFallback` uses the
|
|
127
|
-
* deployment's stored setting.
|
|
128
|
-
*/
|
|
129
|
-
async function serveAsset(ctx, component, request, path, { spaFallback, cdnBaseUrl, }) {
|
|
130
|
-
const asset = await ctx.runQuery(component.lib.resolveAssetForHttp, {
|
|
131
|
-
path,
|
|
132
|
-
...(spaFallback === undefined ? {} : { spaFallback }),
|
|
133
|
-
});
|
|
134
|
-
if (!asset)
|
|
135
|
-
return null;
|
|
136
|
-
const contentType = asset.contentType || getMimeType(path);
|
|
137
|
-
const cacheControl = cacheControlFor(path);
|
|
138
|
-
if (asset.blobId && !isHtmlContentType(contentType)) {
|
|
139
|
-
const configuredBase = typeof cdnBaseUrl === "function" ? cdnBaseUrl(request) : cdnBaseUrl;
|
|
140
|
-
const baseUrl = configuredBase ?? `${new URL(request.url).origin}/fs/blobs`;
|
|
141
|
-
return new Response(null, {
|
|
142
|
-
status: 302,
|
|
143
|
-
headers: {
|
|
144
|
-
Location: `${baseUrl.replace(/\/$/, "")}/${asset.blobId}`,
|
|
145
|
-
"Cache-Control": cacheControl,
|
|
146
|
-
},
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
// TODO(remove in a future major): v1→v2 transitional path. The file still
|
|
150
|
-
// lives in the app's own storage (a same-name migration inherited the v1
|
|
151
|
-
// row; see the component's resolveAssetForHttp). Serve it directly from app
|
|
152
|
-
// storage so the site stays up during migration with no re-upload. Once v1
|
|
153
|
-
// app-storage assets are no longer supported, delete this branch.
|
|
154
|
-
if (asset.appStorageId) {
|
|
155
|
-
if (asset.etag && etagMatches(request.headers.get("If-None-Match"), asset.etag)) {
|
|
156
|
-
return new Response(null, {
|
|
157
|
-
status: 304,
|
|
158
|
-
headers: { ETag: asset.etag, "Cache-Control": cacheControl },
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
const blob = await ctx.storage.get(asset.appStorageId);
|
|
162
|
-
if (!blob) {
|
|
163
|
-
// The component surfaces appStorageId whenever it can't resolve a
|
|
164
|
-
// storage URL, which also covers a genuinely deleted file (the two are
|
|
165
|
-
// indistinguishable from the component). If it isn't in app storage
|
|
166
|
-
// either, treat it as missing, like an empty deployment, rather than
|
|
167
|
-
// erroring.
|
|
168
|
-
return null;
|
|
169
|
-
}
|
|
170
|
-
return new Response(blob, {
|
|
171
|
-
status: 200,
|
|
172
|
-
headers: {
|
|
173
|
-
"Content-Type": contentType,
|
|
174
|
-
"Cache-Control": cacheControl,
|
|
175
|
-
...(asset.etag ? { ETag: asset.etag } : {}),
|
|
176
|
-
"X-Content-Type-Options": "nosniff",
|
|
177
|
-
},
|
|
28
|
+
// Only the pushed code knows which version the deployment runs, so its first request reports it.
|
|
29
|
+
if (state === "ready") {
|
|
30
|
+
await ctx.runMutation(component.lib.markLive, {
|
|
31
|
+
versionId,
|
|
32
|
+
expectedNewestLiveAt: newestLiveAt,
|
|
178
33
|
});
|
|
179
34
|
}
|
|
180
|
-
if (
|
|
181
|
-
return
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
35
|
+
if (asset === null)
|
|
36
|
+
return null;
|
|
37
|
+
const headers = new Headers();
|
|
38
|
+
for (const { name, value } of asset.headers)
|
|
39
|
+
headers.append(name, value);
|
|
40
|
+
if (asset.bodyUrl === null)
|
|
41
|
+
return new Response(null, { status: asset.status, headers });
|
|
42
|
+
// An app cannot read a component's storage, so the body comes from the storage URL.
|
|
43
|
+
let stored;
|
|
44
|
+
try {
|
|
45
|
+
stored = await fetch(asset.bodyUrl);
|
|
188
46
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
return errorResponse(500, "Storage error");
|
|
47
|
+
catch {
|
|
48
|
+
return badGateway();
|
|
192
49
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
headers:
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
"X-Content-Type-Options": "nosniff",
|
|
200
|
-
},
|
|
201
|
-
});
|
|
50
|
+
// A deploy deleted the file between the query and the fetch.
|
|
51
|
+
if (stored.status === 404)
|
|
52
|
+
return new Response(null, { status: 404, headers: NO_STORE });
|
|
53
|
+
if (!stored.ok)
|
|
54
|
+
return badGateway();
|
|
55
|
+
return new Response(stored.body, { status: asset.status, headers });
|
|
202
56
|
}
|
|
203
57
|
/**
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
* `@samebase/convex-hosting/react`. If you don't surface deployment updates
|
|
207
|
-
* in your app, you don't need to call this.
|
|
208
|
-
*
|
|
209
|
-
* @example
|
|
210
|
-
* ```typescript
|
|
211
|
-
* // convex/hosting.ts
|
|
212
|
-
* import { exposeDeploymentQuery } from "@samebase/convex-hosting";
|
|
213
|
-
* import { components } from "./_generated/api";
|
|
214
|
-
*
|
|
215
|
-
* export const { getCurrentDeployment } = exposeDeploymentQuery(
|
|
216
|
-
* components.hosting,
|
|
217
|
-
* );
|
|
218
|
-
* ```
|
|
58
|
+
* The request headers that Cloudflare's handler reads. It reads only the presence of
|
|
59
|
+
* `Authorization` and `Range`, so their values (a credential, for one) stay out of the query.
|
|
219
60
|
*/
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
const { pendingBlobCleanupCount: _pending, ...publicDeployment } = deploymentWithCleanup;
|
|
233
|
-
return publicDeployment;
|
|
234
|
-
},
|
|
235
|
-
}),
|
|
236
|
-
};
|
|
61
|
+
function handlerHeaders(headers) {
|
|
62
|
+
const picked = {};
|
|
63
|
+
for (const name of ["if-none-match", "sec-fetch-mode"]) {
|
|
64
|
+
const value = headers.get(name);
|
|
65
|
+
if (value !== null)
|
|
66
|
+
picked[name] = value;
|
|
67
|
+
}
|
|
68
|
+
for (const name of ["authorization", "range"]) {
|
|
69
|
+
if (headers.has(name))
|
|
70
|
+
picked[name] = "";
|
|
71
|
+
}
|
|
72
|
+
return picked;
|
|
237
73
|
}
|
|
238
74
|
/**
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
* @example
|
|
244
|
-
* ```typescript
|
|
245
|
-
* import { getConvexUrl } from "@samebase/convex-hosting";
|
|
246
|
-
*
|
|
247
|
-
* const convexUrl = import.meta.env.VITE_CONVEX_URL ?? getConvexUrl();
|
|
248
|
-
* const convex = new ConvexReactClient(convexUrl);
|
|
249
|
-
* ```
|
|
75
|
+
* For the answers that no uploaded file gives. The deployment's Cloudflare front caches 404 answers
|
|
76
|
+
* on static paths, so without it a script requested seconds before its upload ended would stay
|
|
77
|
+
* missing for hours (the 0.3.2 incident).
|
|
250
78
|
*/
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
}
|
|
255
|
-
if (window.location.hostname.endsWith(".convex.site")) {
|
|
256
|
-
return `https://${window.location.hostname.replace(".convex.site", ".convex.cloud")}`;
|
|
257
|
-
}
|
|
258
|
-
throw new Error("Unable to derive Convex URL. Please set VITE_CONVEX_URL environment variable.");
|
|
79
|
+
const NO_STORE = { "Cache-Control": "no-store" };
|
|
80
|
+
function badGateway() {
|
|
81
|
+
return new Response(null, { status: 502, headers: NO_STORE });
|
|
259
82
|
}
|
|
260
83
|
//# sourceMappingURL=index.js.map
|
package/dist/client/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,GAAyE,EACzE,SAAuB,EACvB,OAAgB,EAChB,SAAiB;IAEjB,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,GAAG,MAAM,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,EAAE;QAC7E,SAAS;QACT,MAAM,EAAE,OAAO,CAAC,M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, and the wildcard module in it needs an
|
|
2
|
+
// ambient context, so this is the one reference directive in the package.
|
|
3
|
+
// oxlint-disable-next-line typescript/triple-slash-reference
|
|
4
|
+
/// <reference path="./version-module.d.ts" />
|
|
5
|
+
export * from "./index.js";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Ambient declaration of the module that `convex-hosting deploy` writes, so an app typechecks on a
|
|
2
|
+
// fresh clone, before its first deploy. Script file on purpose: a wildcard module name is only allowed
|
|
3
|
+
// in an ambient context.
|
|
4
|
+
declare module "*/.convex-hosting/version.js" {
|
|
5
|
+
export const versionId: string;
|
|
6
|
+
}
|
|
@@ -6,14 +6,10 @@
|
|
|
6
6
|
* To regenerate, run `npx convex dev`.
|
|
7
7
|
* @module
|
|
8
8
|
*/
|
|
9
|
-
import type * as http from "../http.js";
|
|
10
9
|
import type * as lib from "../lib.js";
|
|
11
|
-
import type * as serving from "../serving.js";
|
|
12
10
|
import type { ApiFromModules, FilterApi, FunctionReference } from "convex/server";
|
|
13
11
|
declare const fullApi: ApiFromModules<{
|
|
14
|
-
http: typeof http;
|
|
15
12
|
lib: typeof lib;
|
|
16
|
-
serving: typeof serving;
|
|
17
13
|
}>;
|
|
18
14
|
/**
|
|
19
15
|
* A utility for referencing Convex functions in your app's public API.
|
|
@@ -35,4 +31,3 @@ export declare const api: FilterApi<typeof fullApi, FunctionReference<any, "publ
|
|
|
35
31
|
export declare const internal: FilterApi<typeof fullApi, FunctionReference<any, "internal">>;
|
|
36
32
|
export declare const components: {};
|
|
37
33
|
export {};
|
|
38
|
-
//# sourceMappingURL=api.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/component/_generated/api.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB;;;;;;;GAOG;
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/component/_generated/api.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB;;;;;;;GAOG;AASH,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAE1D,MAAM,OAAO,GAER,MAAa,CAAC;AAEnB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,GAAG,GAGZ,MAAa,CAAC;AAElB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,QAAQ,GAGjB,MAAa,CAAC;AAElB,MAAM,CAAC,MAAM,UAAU,GAAG,iBAAiB,EAAmB,CAAC"}
|
|
@@ -20,24 +20,26 @@ import type { FunctionReference } from "convex/server";
|
|
|
20
20
|
*/
|
|
21
21
|
export type ComponentApi<Name extends string | undefined = string | undefined> = {
|
|
22
22
|
lib: {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
path: string;
|
|
33
|
-
spaFallback?: boolean;
|
|
23
|
+
markLive: FunctionReference<"mutation", "internal", {
|
|
24
|
+
expectedNewestLiveAt: number | null;
|
|
25
|
+
versionId: string;
|
|
26
|
+
}, null, Name>;
|
|
27
|
+
route: FunctionReference<"query", "internal", {
|
|
28
|
+
headers: Record<string, string>;
|
|
29
|
+
method: string;
|
|
30
|
+
url: string;
|
|
31
|
+
versionId: string;
|
|
34
32
|
}, {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
asset: null | {
|
|
34
|
+
bodyUrl: string | null;
|
|
35
|
+
headers: Array<{
|
|
36
|
+
name: string;
|
|
37
|
+
value: string;
|
|
38
|
+
}>;
|
|
39
|
+
status: number;
|
|
40
|
+
};
|
|
41
|
+
newestLiveAt: number | null;
|
|
42
|
+
state: "uploading" | "ready" | "live" | "deleting" | null;
|
|
43
|
+
}, Name>;
|
|
41
44
|
};
|
|
42
45
|
};
|
|
43
|
-
//# sourceMappingURL=component.d.ts.map
|
|
@@ -8,6 +8,16 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import type { ActionBuilder, HttpActionBuilder, MutationBuilder, QueryBuilder, GenericActionCtx, GenericMutationCtx, GenericQueryCtx, GenericDatabaseReader, GenericDatabaseWriter } from "convex/server";
|
|
10
10
|
import type { DataModel } from "./dataModel.js";
|
|
11
|
+
/**
|
|
12
|
+
* Typesafe environment variables.
|
|
13
|
+
*
|
|
14
|
+
* This includes platform-provided env vars and any variables declared in
|
|
15
|
+
* `convex.config.ts`.
|
|
16
|
+
*/
|
|
17
|
+
type Env = {
|
|
18
|
+
readonly CONVEX_CLOUD_URL: string;
|
|
19
|
+
readonly CONVEX_SITE_URL: string;
|
|
20
|
+
};
|
|
11
21
|
/**
|
|
12
22
|
* Define a query in this Convex app's public API.
|
|
13
23
|
*
|
|
@@ -75,6 +85,7 @@ export declare const internalAction: ActionBuilder<DataModel, "internal">;
|
|
|
75
85
|
* @returns The wrapped function. Import this function from `convex/http.js` and route it to hook it up.
|
|
76
86
|
*/
|
|
77
87
|
export declare const httpAction: HttpActionBuilder;
|
|
88
|
+
export declare const env: Env;
|
|
78
89
|
/**
|
|
79
90
|
* A set of services for use within Convex query functions.
|
|
80
91
|
*
|
|
@@ -118,4 +129,4 @@ export type DatabaseReader = GenericDatabaseReader<DataModel>;
|
|
|
118
129
|
* for the guarantees Convex provides your functions.
|
|
119
130
|
*/
|
|
120
131
|
export type DatabaseWriter = GenericDatabaseWriter<DataModel>;
|
|
121
|
-
|
|
132
|
+
export {};
|
|
@@ -75,4 +75,6 @@ export const internalAction = internalActionGeneric;
|
|
|
75
75
|
* @returns The wrapped function. Import this function from `convex/http.js` and route it to hook it up.
|
|
76
76
|
*/
|
|
77
77
|
export const httpAction = httpActionGeneric;
|
|
78
|
+
export const env = globalThis
|
|
79
|
+
.process.env;
|
|
78
80
|
//# sourceMappingURL=server.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/component/_generated/server.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB;;;;;;;GAOG;AAaH,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,YAAY,EACZ,eAAe,EACf,qBAAqB,EACrB,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/component/_generated/server.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB;;;;;;;GAOG;AAaH,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,YAAY,EACZ,eAAe,EACf,qBAAqB,EACrB,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,eAAe,CAAC;AAcvB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,KAAK,GAAsC,YAAY,CAAC;AAErE;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,aAAa,GACxB,oBAAoB,CAAC;AAEvB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAyC,eAAe,CAAC;AAE9E;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAC3B,uBAAuB,CAAC;AAE1B;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,MAAM,GAAuC,aAAa,CAAC;AAExE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GACzB,qBAAqB,CAAC;AAExB;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,UAAU,GAAsB,iBAAiB,CAAC;AAC/D,MAAM,CAAC,MAAM,GAAG,GAAS,UAAmD;KACzE,OAAO,CAAC,GAAG,CAAC"}
|