@hintergrund/worker 0.1.0
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 +45 -0
- package/dist/api/builder/handlers/generate.handler.d.ts +12 -0
- package/dist/api/builder/handlers/generate.handler.d.ts.map +1 -0
- package/dist/api/builder/handlers/generate.handler.js +203 -0
- package/dist/api/builder/handlers/template.handler.d.ts +12 -0
- package/dist/api/builder/handlers/template.handler.d.ts.map +1 -0
- package/dist/api/builder/handlers/template.handler.js +208 -0
- package/dist/api/builder/routes.d.ts +7 -0
- package/dist/api/builder/routes.d.ts.map +1 -0
- package/dist/api/builder/routes.js +15 -0
- package/dist/api/cms/handlers/assets.handler.d.ts +8 -0
- package/dist/api/cms/handlers/assets.handler.d.ts.map +1 -0
- package/dist/api/cms/handlers/assets.handler.js +299 -0
- package/dist/api/cms/handlers/auth.handler.d.ts +11 -0
- package/dist/api/cms/handlers/auth.handler.d.ts.map +1 -0
- package/dist/api/cms/handlers/auth.handler.js +214 -0
- package/dist/api/cms/handlers/config.handler.d.ts +3 -0
- package/dist/api/cms/handlers/config.handler.d.ts.map +1 -0
- package/dist/api/cms/handlers/config.handler.js +88 -0
- package/dist/api/cms/handlers/content.handler.d.ts +10 -0
- package/dist/api/cms/handlers/content.handler.d.ts.map +1 -0
- package/dist/api/cms/handlers/content.handler.js +293 -0
- package/dist/api/cms/handlers/dashboard.handler.d.ts +6 -0
- package/dist/api/cms/handlers/dashboard.handler.d.ts.map +1 -0
- package/dist/api/cms/handlers/dashboard.handler.js +15 -0
- package/dist/api/cms/routes/assets.routes.d.ts +4 -0
- package/dist/api/cms/routes/assets.routes.d.ts.map +1 -0
- package/dist/api/cms/routes/assets.routes.js +13 -0
- package/dist/api/cms/routes/auth.routes.d.ts +4 -0
- package/dist/api/cms/routes/auth.routes.d.ts.map +1 -0
- package/dist/api/cms/routes/auth.routes.js +7 -0
- package/dist/api/cms/routes/content.routes.d.ts +4 -0
- package/dist/api/cms/routes/content.routes.d.ts.map +1 -0
- package/dist/api/cms/routes/content.routes.js +11 -0
- package/dist/api/cms/routes/index.d.ts +4 -0
- package/dist/api/cms/routes/index.d.ts.map +1 -0
- package/dist/api/cms/routes/index.js +16 -0
- package/dist/api/newsletter/handlers/email.handler.d.ts +7 -0
- package/dist/api/newsletter/handlers/email.handler.d.ts.map +1 -0
- package/dist/api/newsletter/handlers/email.handler.js +102 -0
- package/dist/api/newsletter/handlers/emails.handler.d.ts +21 -0
- package/dist/api/newsletter/handlers/emails.handler.d.ts.map +1 -0
- package/dist/api/newsletter/handlers/emails.handler.js +134 -0
- package/dist/api/newsletter/handlers/public.handler.d.ts +22 -0
- package/dist/api/newsletter/handlers/public.handler.d.ts.map +1 -0
- package/dist/api/newsletter/handlers/public.handler.js +242 -0
- package/dist/api/newsletter/handlers/send.handler.d.ts +12 -0
- package/dist/api/newsletter/handlers/send.handler.d.ts.map +1 -0
- package/dist/api/newsletter/handlers/send.handler.js +153 -0
- package/dist/api/newsletter/handlers/subscribers.handler.d.ts +22 -0
- package/dist/api/newsletter/handlers/subscribers.handler.d.ts.map +1 -0
- package/dist/api/newsletter/handlers/subscribers.handler.js +191 -0
- package/dist/api/newsletter/routes/admin.routes.d.ts +4 -0
- package/dist/api/newsletter/routes/admin.routes.d.ts.map +1 -0
- package/dist/api/newsletter/routes/admin.routes.js +21 -0
- package/dist/api/newsletter/routes/index.d.ts +4 -0
- package/dist/api/newsletter/routes/index.d.ts.map +1 -0
- package/dist/api/newsletter/routes/index.js +9 -0
- package/dist/api/newsletter/routes/public.routes.d.ts +4 -0
- package/dist/api/newsletter/routes/public.routes.d.ts.map +1 -0
- package/dist/api/newsletter/routes/public.routes.js +9 -0
- package/dist/api/shop/handlers/customers.handler.d.ts +17 -0
- package/dist/api/shop/handlers/customers.handler.d.ts.map +1 -0
- package/dist/api/shop/handlers/customers.handler.js +89 -0
- package/dist/api/shop/handlers/orders.handler.d.ts +17 -0
- package/dist/api/shop/handlers/orders.handler.d.ts.map +1 -0
- package/dist/api/shop/handlers/orders.handler.js +84 -0
- package/dist/api/shop/handlers/prices.handler.d.ts +17 -0
- package/dist/api/shop/handlers/prices.handler.d.ts.map +1 -0
- package/dist/api/shop/handlers/prices.handler.js +87 -0
- package/dist/api/shop/handlers/products.handler.d.ts +45 -0
- package/dist/api/shop/handlers/products.handler.d.ts.map +1 -0
- package/dist/api/shop/handlers/products.handler.js +243 -0
- package/dist/api/shop/handlers/stats.handler.d.ts +10 -0
- package/dist/api/shop/handlers/stats.handler.d.ts.map +1 -0
- package/dist/api/shop/handlers/stats.handler.js +71 -0
- package/dist/api/shop/routes.d.ts +7 -0
- package/dist/api/shop/routes.d.ts.map +1 -0
- package/dist/api/shop/routes.js +31 -0
- package/dist/cms-assets.d.ts +4 -0
- package/dist/cms-assets.d.ts.map +1 -0
- package/dist/cms-assets.js +5 -0
- package/dist/cms-bundle.d.ts +3 -0
- package/dist/cms-bundle.d.ts.map +1 -0
- package/dist/cms-bundle.js +4 -0
- package/dist/config-loader.d.ts +26 -0
- package/dist/config-loader.d.ts.map +1 -0
- package/dist/config-loader.js +98 -0
- package/dist/hintergrund-assets.d.ts +4 -0
- package/dist/hintergrund-assets.d.ts.map +1 -0
- package/dist/hintergrund-assets.js +9 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +66 -0
- package/dist/jwt.d.ts +26 -0
- package/dist/jwt.d.ts.map +1 -0
- package/dist/jwt.js +102 -0
- package/dist/lib/auth/crypto.d.ts +23 -0
- package/dist/lib/auth/crypto.d.ts.map +1 -0
- package/dist/lib/auth/crypto.js +110 -0
- package/dist/lib/auth/jwt.d.ts +38 -0
- package/dist/lib/auth/jwt.d.ts.map +1 -0
- package/dist/lib/auth/jwt.js +120 -0
- package/dist/lib/config.d.ts +31 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/dist/lib/config.js +174 -0
- package/dist/lib/email.d.ts +16 -0
- package/dist/lib/email.d.ts.map +1 -0
- package/dist/lib/email.js +83 -0
- package/dist/lib/template.d.ts +2 -0
- package/dist/lib/template.d.ts.map +1 -0
- package/dist/lib/template.js +226 -0
- package/dist/middleware/auth.d.ts +9 -0
- package/dist/middleware/auth.d.ts.map +1 -0
- package/dist/middleware/auth.js +93 -0
- package/dist/template.d.ts +2 -0
- package/dist/template.d.ts.map +1 -0
- package/dist/template.js +61 -0
- package/dist/utils.d.ts +23 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +110 -0
- package/package.json +32 -0
package/dist/template.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export function getTemplate(element, uiBaseUrl, params = '') {
|
|
2
|
+
if (element === 'login') {
|
|
3
|
+
return `
|
|
4
|
+
<!doctype html>
|
|
5
|
+
<html>
|
|
6
|
+
<head>
|
|
7
|
+
<meta charset="utf-8">
|
|
8
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
9
|
+
<title>Login</title>
|
|
10
|
+
<style>
|
|
11
|
+
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
12
|
+
body { margin: 0; height: 100vh; }
|
|
13
|
+
</style>
|
|
14
|
+
<link rel="stylesheet" href="${uiBaseUrl}/ui.css">
|
|
15
|
+
</head>
|
|
16
|
+
<body>
|
|
17
|
+
<hintergrund-login></hintergrund-login>
|
|
18
|
+
<script type="module" src="${uiBaseUrl}/login.js"></script>
|
|
19
|
+
</body>
|
|
20
|
+
</html>
|
|
21
|
+
`;
|
|
22
|
+
}
|
|
23
|
+
if (element === 'admin') {
|
|
24
|
+
return `
|
|
25
|
+
<!doctype html>
|
|
26
|
+
<html>
|
|
27
|
+
<head>
|
|
28
|
+
<meta charset="utf-8">
|
|
29
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
30
|
+
<title>Hintergrund Admin</title>
|
|
31
|
+
<meta name="description" content="Admin Panel for Hintergrund">
|
|
32
|
+
<style>
|
|
33
|
+
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
34
|
+
body { margin: 0; height: 100vh; }
|
|
35
|
+
</style>
|
|
36
|
+
<link rel="stylesheet" href="${uiBaseUrl}/ui.css">
|
|
37
|
+
</head>
|
|
38
|
+
<body>
|
|
39
|
+
<hintergrund-admin ${params}></hintergrund-admin>
|
|
40
|
+
<script type="module" src="${uiBaseUrl}/admin.js"></script>
|
|
41
|
+
</body>
|
|
42
|
+
</html>
|
|
43
|
+
`;
|
|
44
|
+
}
|
|
45
|
+
return `
|
|
46
|
+
<!doctype html>
|
|
47
|
+
<html>
|
|
48
|
+
<head>
|
|
49
|
+
<meta charset="utf-8">
|
|
50
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
51
|
+
<title>Hintergrund CMS</title>
|
|
52
|
+
<meta name="description" content="Admin Panel for Hintergrund CMS">
|
|
53
|
+
<style>body{margin:0}</style>
|
|
54
|
+
</head>
|
|
55
|
+
<body>
|
|
56
|
+
<${element} ${params}></${element}>
|
|
57
|
+
<script type="module" src="/index.js"></script>
|
|
58
|
+
</body>
|
|
59
|
+
</html>
|
|
60
|
+
`;
|
|
61
|
+
}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a random token used as a Secret Key
|
|
3
|
+
*/
|
|
4
|
+
export declare function generateRandomToken(): string;
|
|
5
|
+
/**
|
|
6
|
+
* Hash a password with salt and pepper
|
|
7
|
+
*/
|
|
8
|
+
export declare function hashPw(password: string, pepper: string): Promise<string>;
|
|
9
|
+
/**
|
|
10
|
+
* Verify a password against an encrypted password
|
|
11
|
+
* Uses AES-GCM decryption to match hintergrund.cloud's encryption method
|
|
12
|
+
*/
|
|
13
|
+
export declare function verifyPw(encryptedPassword: string, password: string, secret: string): Promise<boolean>;
|
|
14
|
+
/**
|
|
15
|
+
* Decrypts an encrypted string using AES-GCM
|
|
16
|
+
* Matches hintergrund.cloud's decrypt function
|
|
17
|
+
*/
|
|
18
|
+
export declare function decrypt(ciphertext: string, secret: string): Promise<string>;
|
|
19
|
+
/**
|
|
20
|
+
* Read and parse request body
|
|
21
|
+
*/
|
|
22
|
+
export declare function readRequestBody(request: Request): Promise<any>;
|
|
23
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,CAG5C;AAED;;GAEG;AACH,wBAAsB,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA2B9E;AAED;;;GAGG;AACH,wBAAsB,QAAQ,CAAC,iBAAiB,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAO5G;AAiBD;;;GAGG;AACH,wBAAsB,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA0BjF;AAiBD;;GAEG;AACH,wBAAsB,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAepE"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a random token used as a Secret Key
|
|
3
|
+
*/
|
|
4
|
+
export function generateRandomToken() {
|
|
5
|
+
const tokenBytes = crypto.getRandomValues(new Uint8Array(32));
|
|
6
|
+
return btoa(String.fromCharCode(...tokenBytes));
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Hash a password with salt and pepper
|
|
10
|
+
*/
|
|
11
|
+
export async function hashPw(password, pepper) {
|
|
12
|
+
// Create salt
|
|
13
|
+
const salt = crypto.getRandomValues(new Uint8Array(16));
|
|
14
|
+
// Convert password and pepper to Uint8Array
|
|
15
|
+
const pass = new TextEncoder().encode(password);
|
|
16
|
+
const pepp = new TextEncoder().encode(pepper);
|
|
17
|
+
// Combine salt, pepper, and password hash
|
|
18
|
+
const combined = new Uint8Array(salt.length + pepper.length + password.length);
|
|
19
|
+
combined.set(salt);
|
|
20
|
+
combined.set(pepp, salt.length);
|
|
21
|
+
combined.set(pass, salt.length + pepper.length);
|
|
22
|
+
// Hash combined
|
|
23
|
+
const hashBuffer = await crypto.subtle.digest('SHA-256', combined);
|
|
24
|
+
// Convert hashBuffer to Uint8Array
|
|
25
|
+
const hash = new Uint8Array(hashBuffer);
|
|
26
|
+
// Combine salt and hash
|
|
27
|
+
const combinedHash = new Uint8Array(salt.length + hash.length);
|
|
28
|
+
combinedHash.set(salt);
|
|
29
|
+
combinedHash.set(hash, salt.length);
|
|
30
|
+
// Return combined hash as base64 string
|
|
31
|
+
return btoa(new Uint8Array(combinedHash).reduce((s, b) => s + String.fromCharCode(b), ''));
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Verify a password against an encrypted password
|
|
35
|
+
* Uses AES-GCM decryption to match hintergrund.cloud's encryption method
|
|
36
|
+
*/
|
|
37
|
+
export async function verifyPw(encryptedPassword, password, secret) {
|
|
38
|
+
try {
|
|
39
|
+
const decryptedPassword = await decrypt(encryptedPassword, secret);
|
|
40
|
+
return decryptedPassword === password;
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Derives a cryptographic key from the secret string
|
|
48
|
+
*/
|
|
49
|
+
async function deriveKey(secret) {
|
|
50
|
+
const secretBytes = new TextEncoder().encode(secret);
|
|
51
|
+
const keyMaterial = await crypto.subtle.digest('SHA-256', secretBytes);
|
|
52
|
+
return await crypto.subtle.importKey('raw', keyMaterial, { name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt']);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Decrypts an encrypted string using AES-GCM
|
|
56
|
+
* Matches hintergrund.cloud's decrypt function
|
|
57
|
+
*/
|
|
58
|
+
export async function decrypt(ciphertext, secret) {
|
|
59
|
+
try {
|
|
60
|
+
// Decode from base64
|
|
61
|
+
const combined = Uint8Array.from(atob(ciphertext), (c) => c.charCodeAt(0));
|
|
62
|
+
// Extract IV (first 12 bytes)
|
|
63
|
+
const iv = combined.slice(0, 12);
|
|
64
|
+
// Extract encrypted data (remaining bytes)
|
|
65
|
+
const encryptedData = combined.slice(12);
|
|
66
|
+
// Derive decryption key
|
|
67
|
+
const key = await deriveKey(secret);
|
|
68
|
+
// Decrypt
|
|
69
|
+
const decryptedBuffer = await crypto.subtle.decrypt({ name: 'AES-GCM', iv }, key, encryptedData);
|
|
70
|
+
// Convert bytes back to string
|
|
71
|
+
return new TextDecoder().decode(decryptedBuffer);
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
throw new Error('Decryption failed');
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Compare two Uint8Arrays for equality
|
|
79
|
+
*/
|
|
80
|
+
function areUint8ArraysEqual(a, b) {
|
|
81
|
+
if (a.length !== b.length) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
for (let i = 0; i < a.length; i++) {
|
|
85
|
+
if (a[i] !== b[i]) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Read and parse request body
|
|
93
|
+
*/
|
|
94
|
+
export async function readRequestBody(request) {
|
|
95
|
+
const contentType = request.headers.get('content-type');
|
|
96
|
+
if (!contentType)
|
|
97
|
+
throw new Error('Content-Type not set');
|
|
98
|
+
if (contentType.includes('application/json')) {
|
|
99
|
+
return await request.json();
|
|
100
|
+
}
|
|
101
|
+
else if (contentType.includes('form')) {
|
|
102
|
+
const formData = await request.formData();
|
|
103
|
+
const body = {};
|
|
104
|
+
for (const entry of formData.entries()) {
|
|
105
|
+
body[entry[0]] = entry[1];
|
|
106
|
+
}
|
|
107
|
+
return body;
|
|
108
|
+
}
|
|
109
|
+
throw new Error('Content-Type not supported');
|
|
110
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hintergrund/worker",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@cloudflare/workers-types": "^4.20250111.0",
|
|
18
|
+
"concurrently": "^9.2.1",
|
|
19
|
+
"typescript": "^5.5.2"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@octokit/rest": "^22.0.0",
|
|
23
|
+
"cookie": "^1.0.2",
|
|
24
|
+
"hono": "^4.10.2",
|
|
25
|
+
"stripe": "^17.5.0",
|
|
26
|
+
"@hintergrund/shared": "0.0.1"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsc",
|
|
30
|
+
"dev": "tsc --watch"
|
|
31
|
+
}
|
|
32
|
+
}
|