@emdash-cms/cloudflare 0.0.1 → 0.0.3
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/dist/auth/index.mjs
CHANGED
|
@@ -1,17 +1,6 @@
|
|
|
1
1
|
import { createRemoteJWKSet, jwtVerify } from "jose";
|
|
2
2
|
|
|
3
3
|
//#region src/auth/cloudflare-access.ts
|
|
4
|
-
/**
|
|
5
|
-
* Cloudflare Access Authentication - RUNTIME MODULE
|
|
6
|
-
*
|
|
7
|
-
* When EmDash is deployed behind Cloudflare Access, this module handles
|
|
8
|
-
* JWT validation and user provisioning from Access identity.
|
|
9
|
-
*
|
|
10
|
-
* Uses jose for JWT verification - works in all runtimes.
|
|
11
|
-
*
|
|
12
|
-
* This is loaded at runtime via the auth provider system.
|
|
13
|
-
* Do not import at config time.
|
|
14
|
-
*/
|
|
15
4
|
const jwksCache = /* @__PURE__ */ new Map();
|
|
16
5
|
/** Regex to extract CF_Authorization cookie value */
|
|
17
6
|
const CF_AUTHORIZATION_COOKIE_REGEX = /CF_Authorization=([^;]+)/;
|
|
@@ -40,7 +40,7 @@ function renderPlaygroundToolbar(config) {
|
|
|
40
40
|
<svg class="ec-pg-icon" id="ec-pg-reset-icon" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="23 4 23 10 17 10"/><path d="M20.49 15a9 9 0 1 1-2.12-9.36L23 10"/></svg>
|
|
41
41
|
</button>
|
|
42
42
|
|
|
43
|
-
<a class="ec-pg-btn ec-pg-btn--deploy" href="https://
|
|
43
|
+
<a class="ec-pg-btn ec-pg-btn--deploy" href="https://github.com/emdash-cms/emdash" target="_blank" rel="noopener">
|
|
44
44
|
Deploy your own
|
|
45
45
|
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/><polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/></svg>
|
|
46
46
|
</a>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@emdash-cms/cloudflare",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Cloudflare adapters for EmDash - D1, R2, Access, and Worker Loader sandbox",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.mjs",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"jose": "^6.1.3",
|
|
67
67
|
"kysely-d1": "^0.4.0",
|
|
68
68
|
"ulidx": "^2.4.1",
|
|
69
|
-
"emdash": "0.0.
|
|
69
|
+
"emdash": "0.0.3"
|
|
70
70
|
},
|
|
71
71
|
"peerDependencies": {
|
|
72
72
|
"@cloudflare/workers-types": ">=4.0.0",
|
|
@@ -83,10 +83,10 @@
|
|
|
83
83
|
},
|
|
84
84
|
"repository": {
|
|
85
85
|
"type": "git",
|
|
86
|
-
"url": "git+https://github.com/
|
|
86
|
+
"url": "git+https://github.com/emdash-cms/emdash.git",
|
|
87
87
|
"directory": "packages/cloudflare"
|
|
88
88
|
},
|
|
89
|
-
"homepage": "https://github.com/
|
|
89
|
+
"homepage": "https://github.com/emdash-cms/emdash",
|
|
90
90
|
"keywords": [
|
|
91
91
|
"emdash",
|
|
92
92
|
"cloudflare",
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
* Do not import at config time.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import { createRemoteJWKSet, jwtVerify, type JWTPayload } from "jose";
|
|
14
13
|
import type { AuthResult } from "emdash";
|
|
14
|
+
import { createRemoteJWKSet, jwtVerify, type JWTPayload } from "jose";
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Configuration for Cloudflare Access authentication
|
package/src/db/do-preview.ts
CHANGED
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
|
|
23
23
|
import type { MiddlewareHandler } from "astro";
|
|
24
24
|
import { env } from "cloudflare:workers";
|
|
25
|
-
import { Kysely } from "kysely";
|
|
26
25
|
import { runWithContext } from "emdash/request-context";
|
|
26
|
+
import { Kysely } from "kysely";
|
|
27
27
|
import { ulid } from "ulidx";
|
|
28
28
|
|
|
29
29
|
import type { EmDashPreviewDB } from "./do-class.js";
|
|
@@ -11,12 +11,12 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
export interface PlaygroundToolbarConfig {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
/** When the playground was created (ISO string) */
|
|
15
|
+
createdAt: string;
|
|
16
|
+
/** TTL in seconds */
|
|
17
|
+
ttl: number;
|
|
18
|
+
/** Whether edit mode is currently active */
|
|
19
|
+
editMode: boolean;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
const RE_AMP = /&/g;
|
|
@@ -25,9 +25,9 @@ const RE_LT = /</g;
|
|
|
25
25
|
const RE_GT = />/g;
|
|
26
26
|
|
|
27
27
|
export function renderPlaygroundToolbar(config: PlaygroundToolbarConfig): string {
|
|
28
|
-
|
|
28
|
+
const { createdAt, ttl, editMode } = config;
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
return `
|
|
31
31
|
<!-- EmDash Playground Toolbar -->
|
|
32
32
|
<div id="emdash-playground-toolbar" data-created-at="${escapeAttr(createdAt)}" data-ttl="${ttl}" data-edit-mode="${editMode}">
|
|
33
33
|
<div class="ec-pg-inner">
|
|
@@ -53,7 +53,7 @@ export function renderPlaygroundToolbar(config: PlaygroundToolbarConfig): string
|
|
|
53
53
|
<svg class="ec-pg-icon" id="ec-pg-reset-icon" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="23 4 23 10 17 10"/><path d="M20.49 15a9 9 0 1 1-2.12-9.36L23 10"/></svg>
|
|
54
54
|
</button>
|
|
55
55
|
|
|
56
|
-
<a class="ec-pg-btn ec-pg-btn--deploy" href="https://
|
|
56
|
+
<a class="ec-pg-btn ec-pg-btn--deploy" href="https://github.com/emdash-cms/emdash" target="_blank" rel="noopener">
|
|
57
57
|
Deploy your own
|
|
58
58
|
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/><polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/></svg>
|
|
59
59
|
</a>
|
|
@@ -333,9 +333,9 @@ export function renderPlaygroundToolbar(config: PlaygroundToolbarConfig): string
|
|
|
333
333
|
}
|
|
334
334
|
|
|
335
335
|
function escapeAttr(str: string): string {
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
336
|
+
return str
|
|
337
|
+
.replace(RE_AMP, "&")
|
|
338
|
+
.replace(RE_QUOT, """)
|
|
339
|
+
.replace(RE_LT, "<")
|
|
340
|
+
.replace(RE_GT, ">");
|
|
341
341
|
}
|
package/src/storage/r2.ts
CHANGED
|
@@ -61,11 +61,7 @@ export class R2Storage implements Storage {
|
|
|
61
61
|
};
|
|
62
62
|
} catch (error) {
|
|
63
63
|
if (error instanceof EmDashStorageError) throw error;
|
|
64
|
-
throw new EmDashStorageError(
|
|
65
|
-
`Failed to upload file: ${options.key}`,
|
|
66
|
-
"UPLOAD_FAILED",
|
|
67
|
-
error,
|
|
68
|
-
);
|
|
64
|
+
throw new EmDashStorageError(`Failed to upload file: ${options.key}`, "UPLOAD_FAILED", error);
|
|
69
65
|
}
|
|
70
66
|
}
|
|
71
67
|
|
|
@@ -107,11 +103,7 @@ export class R2Storage implements Storage {
|
|
|
107
103
|
const object = await this.bucket.head(key);
|
|
108
104
|
return object !== null;
|
|
109
105
|
} catch (error) {
|
|
110
|
-
throw new EmDashStorageError(
|
|
111
|
-
`Failed to check file existence: ${key}`,
|
|
112
|
-
"HEAD_FAILED",
|
|
113
|
-
error,
|
|
114
|
-
);
|
|
106
|
+
throw new EmDashStorageError(`Failed to check file existence: ${key}`, "HEAD_FAILED", error);
|
|
115
107
|
}
|
|
116
108
|
}
|
|
117
109
|
|