@hintergrund/worker 0.1.2 → 0.1.5
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/api/cms/handlers/assets.handler.d.ts +24 -1
- package/dist/api/cms/handlers/assets.handler.d.ts.map +1 -1
- package/dist/api/cms/handlers/assets.handler.js +111 -210
- package/dist/api/cms/handlers/auth.handler.d.ts +4 -3
- package/dist/api/cms/handlers/auth.handler.d.ts.map +1 -1
- package/dist/api/cms/handlers/auth.handler.js +24 -14
- package/dist/api/cms/handlers/config.handler.d.ts +4 -0
- package/dist/api/cms/handlers/config.handler.d.ts.map +1 -1
- package/dist/api/cms/handlers/config.handler.js +20 -71
- package/dist/api/cms/handlers/content.handler.d.ts +12 -1
- package/dist/api/cms/handlers/content.handler.d.ts.map +1 -1
- package/dist/api/cms/handlers/content.handler.js +57 -233
- package/dist/api/cms/handlers/dashboard.handler.js +1 -1
- package/dist/api/cms/routes/auth.routes.d.ts +2 -1
- package/dist/api/cms/routes/auth.routes.d.ts.map +1 -1
- package/dist/api/cms/routes/auth.routes.js +7 -0
- package/dist/api/cms/routes/index.d.ts +2 -1
- package/dist/api/cms/routes/index.d.ts.map +1 -1
- package/dist/api/emails/handlers/branding.handler.d.ts +17 -0
- package/dist/api/emails/handlers/branding.handler.d.ts.map +1 -0
- package/dist/api/emails/handlers/branding.handler.js +120 -0
- package/dist/api/emails/handlers/campaigns.handler.d.ts +32 -0
- package/dist/api/emails/handlers/campaigns.handler.d.ts.map +1 -0
- package/dist/api/emails/handlers/campaigns.handler.js +139 -0
- package/dist/api/emails/handlers/contacts.handler.d.ts +37 -0
- package/dist/api/emails/handlers/contacts.handler.d.ts.map +1 -0
- package/dist/api/emails/handlers/contacts.handler.js +161 -0
- package/dist/api/emails/handlers/invoice.handler.d.ts +30 -0
- package/dist/api/emails/handlers/invoice.handler.d.ts.map +1 -0
- package/dist/api/emails/handlers/invoice.handler.js +463 -0
- package/dist/api/emails/handlers/public.handler.d.ts +36 -0
- package/dist/api/emails/handlers/public.handler.d.ts.map +1 -0
- package/dist/api/emails/handlers/public.handler.js +350 -0
- package/dist/api/emails/handlers/send.handler.d.ts +23 -0
- package/dist/api/emails/handlers/send.handler.d.ts.map +1 -0
- package/dist/api/emails/handlers/send.handler.js +117 -0
- package/dist/api/emails/handlers/settings.handler.d.ts +36 -0
- package/dist/api/emails/handlers/settings.handler.d.ts.map +1 -0
- package/dist/api/emails/handlers/settings.handler.js +312 -0
- package/dist/api/emails/handlers/templates.handler.d.ts +32 -0
- package/dist/api/emails/handlers/templates.handler.d.ts.map +1 -0
- package/dist/api/emails/handlers/templates.handler.js +132 -0
- package/dist/api/emails/handlers/webhook.handler.d.ts +10 -0
- package/dist/api/emails/handlers/webhook.handler.d.ts.map +1 -0
- package/dist/api/emails/handlers/webhook.handler.js +261 -0
- package/dist/api/emails/routes/admin.routes.d.ts +9 -0
- package/dist/api/emails/routes/admin.routes.d.ts.map +1 -0
- package/dist/api/emails/routes/admin.routes.js +77 -0
- package/dist/api/emails/routes/index.d.ts +9 -0
- package/dist/api/emails/routes/index.d.ts.map +1 -0
- package/dist/api/emails/routes/index.js +14 -0
- package/dist/api/emails/routes/public.routes.d.ts +9 -0
- package/dist/api/emails/routes/public.routes.d.ts.map +1 -0
- package/dist/api/emails/routes/public.routes.js +18 -0
- package/dist/api/shop/handlers/webhook.handler.d.ts.map +1 -1
- package/dist/api/shop/handlers/webhook.handler.js +66 -60
- package/dist/api/shop/routes.d.ts.map +1 -1
- package/dist/api/shop/routes.js +0 -3
- package/dist/hintergrund-assets.d.ts +2 -2
- package/dist/hintergrund-assets.d.ts.map +1 -1
- package/dist/hintergrund-assets.js +2 -2
- package/dist/index.d.ts +20 -19
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -7
- package/dist/lib/config.d.ts +13 -7
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +44 -46
- package/dist/lib/email.d.ts +2 -2
- package/dist/lib/email.d.ts.map +1 -1
- package/dist/lib/email.js +7 -9
- package/dist/lib/github.d.ts +124 -0
- package/dist/lib/github.d.ts.map +1 -0
- package/dist/lib/github.js +286 -0
- package/dist/lib/plunk.d.ts +204 -0
- package/dist/lib/plunk.d.ts.map +1 -0
- package/dist/lib/plunk.js +259 -0
- package/dist/middleware/auth.d.ts.map +1 -1
- package/dist/middleware/auth.js +2 -5
- package/package.json +32 -32
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plunk API Client
|
|
3
|
+
*
|
|
4
|
+
* Provides methods for interacting with Plunk's email marketing API:
|
|
5
|
+
* - Contacts management
|
|
6
|
+
* - Templates management
|
|
7
|
+
* - Campaigns management
|
|
8
|
+
* - Transactional email sending
|
|
9
|
+
* - Event tracking
|
|
10
|
+
*/
|
|
11
|
+
export class PlunkClient {
|
|
12
|
+
constructor(config) {
|
|
13
|
+
this.baseUrl = 'https://next-api.useplunk.com';
|
|
14
|
+
this.secretKey = config.secretKey;
|
|
15
|
+
this.publicKey = config.publicKey;
|
|
16
|
+
}
|
|
17
|
+
async request(endpoint, options = {}, usePublicKey = false) {
|
|
18
|
+
const apiKey = usePublicKey && this.publicKey ? this.publicKey : this.secretKey;
|
|
19
|
+
const response = await fetch(`${this.baseUrl}${endpoint}`, {
|
|
20
|
+
...options,
|
|
21
|
+
headers: {
|
|
22
|
+
'Content-Type': 'application/json',
|
|
23
|
+
'Authorization': `Bearer ${apiKey}`,
|
|
24
|
+
...options.headers,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
const data = await response.json();
|
|
28
|
+
if (!response.ok) {
|
|
29
|
+
const error = data;
|
|
30
|
+
// Enhanced error logging
|
|
31
|
+
console.error(`Plunk API Error: ${error.error || error.message}`);
|
|
32
|
+
throw new Error(error.message || error.error || `Plunk API error: ${response.status}`);
|
|
33
|
+
}
|
|
34
|
+
return data;
|
|
35
|
+
}
|
|
36
|
+
// ==========================================================================
|
|
37
|
+
// Contacts
|
|
38
|
+
// ==========================================================================
|
|
39
|
+
/**
|
|
40
|
+
* Get all contacts
|
|
41
|
+
*/
|
|
42
|
+
async getContacts() {
|
|
43
|
+
const response = await this.request('/contacts');
|
|
44
|
+
return {
|
|
45
|
+
contacts: response.data || [],
|
|
46
|
+
count: response.count || 0,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Get a single contact by ID
|
|
51
|
+
*/
|
|
52
|
+
async getContact(id) {
|
|
53
|
+
return this.request(`/contacts/${id}`);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Create a new contact
|
|
57
|
+
*/
|
|
58
|
+
async createContact(data) {
|
|
59
|
+
return this.request('/contacts', {
|
|
60
|
+
method: 'POST',
|
|
61
|
+
body: JSON.stringify(data),
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Update an existing contact
|
|
66
|
+
*/
|
|
67
|
+
async updateContact(id, data) {
|
|
68
|
+
return this.request(`/contacts/${id}`, {
|
|
69
|
+
method: 'PUT',
|
|
70
|
+
body: JSON.stringify(data),
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Delete a contact
|
|
75
|
+
*/
|
|
76
|
+
async deleteContact(id) {
|
|
77
|
+
return this.request(`/contacts/${id}`, {
|
|
78
|
+
method: 'DELETE',
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Subscribe a contact (set subscribed to true)
|
|
83
|
+
*/
|
|
84
|
+
async subscribeContact(id) {
|
|
85
|
+
return this.updateContact(id, { subscribed: true });
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Unsubscribe a contact (set subscribed to false)
|
|
89
|
+
*/
|
|
90
|
+
async unsubscribeContact(id) {
|
|
91
|
+
return this.updateContact(id, { subscribed: false });
|
|
92
|
+
}
|
|
93
|
+
// ==========================================================================
|
|
94
|
+
// Templates
|
|
95
|
+
// ==========================================================================
|
|
96
|
+
/**
|
|
97
|
+
* Get all templates
|
|
98
|
+
*/
|
|
99
|
+
async getTemplates() {
|
|
100
|
+
const response = await this.request('/templates');
|
|
101
|
+
return {
|
|
102
|
+
templates: response.data || [],
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Get a single template by ID
|
|
107
|
+
*/
|
|
108
|
+
async getTemplate(id) {
|
|
109
|
+
return this.request(`/templates/${id}`);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Create a new template
|
|
113
|
+
*/
|
|
114
|
+
async createTemplate(data) {
|
|
115
|
+
return this.request('/templates', {
|
|
116
|
+
method: 'POST',
|
|
117
|
+
body: JSON.stringify({
|
|
118
|
+
...data,
|
|
119
|
+
type: data.type || 'TRANSACTIONAL',
|
|
120
|
+
}),
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Update an existing template
|
|
125
|
+
*/
|
|
126
|
+
async updateTemplate(id, data) {
|
|
127
|
+
return this.request(`/templates/${id}`, {
|
|
128
|
+
method: 'PUT',
|
|
129
|
+
body: JSON.stringify(data),
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Delete a template
|
|
134
|
+
*/
|
|
135
|
+
async deleteTemplate(id) {
|
|
136
|
+
return this.request(`/templates/${id}`, {
|
|
137
|
+
method: 'DELETE',
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
// ==========================================================================
|
|
141
|
+
// Campaigns
|
|
142
|
+
// ==========================================================================
|
|
143
|
+
/**
|
|
144
|
+
* Get all campaigns
|
|
145
|
+
*/
|
|
146
|
+
async getCampaigns() {
|
|
147
|
+
const response = await this.request('/campaigns');
|
|
148
|
+
return {
|
|
149
|
+
campaigns: response.data || [],
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Get a single campaign by ID
|
|
154
|
+
*/
|
|
155
|
+
async getCampaign(id) {
|
|
156
|
+
return this.request(`/campaigns/${id}`);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Create a new campaign (draft)
|
|
160
|
+
*/
|
|
161
|
+
async createCampaign(data) {
|
|
162
|
+
return this.request('/campaigns', {
|
|
163
|
+
method: 'POST',
|
|
164
|
+
body: JSON.stringify({
|
|
165
|
+
...data,
|
|
166
|
+
recipients: 'all', // Send to all subscribed contacts
|
|
167
|
+
}),
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Send a campaign to all subscribed contacts
|
|
172
|
+
*/
|
|
173
|
+
async sendCampaign(id) {
|
|
174
|
+
return this.request(`/campaigns/${id}/send`, {
|
|
175
|
+
method: 'POST',
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Send a test email for a campaign to a specific email
|
|
180
|
+
*/
|
|
181
|
+
async testCampaign(id, email) {
|
|
182
|
+
// Get the campaign to use its content
|
|
183
|
+
const campaign = await this.getCampaign(id);
|
|
184
|
+
// Send as transactional to the test email
|
|
185
|
+
return this.send({
|
|
186
|
+
to: email,
|
|
187
|
+
subject: `[TEST] ${campaign.subject}`,
|
|
188
|
+
body: campaign.body || '',
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
// ==========================================================================
|
|
192
|
+
// Transactional Emails
|
|
193
|
+
// ==========================================================================
|
|
194
|
+
/**
|
|
195
|
+
* Send a transactional email
|
|
196
|
+
*/
|
|
197
|
+
async send(data) {
|
|
198
|
+
return this.request('/v1/send', {
|
|
199
|
+
method: 'POST',
|
|
200
|
+
body: JSON.stringify(data),
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
// ==========================================================================
|
|
204
|
+
// Event Tracking
|
|
205
|
+
// ==========================================================================
|
|
206
|
+
/**
|
|
207
|
+
* Track an event for a contact
|
|
208
|
+
* Uses the public key if available for client-side tracking
|
|
209
|
+
*/
|
|
210
|
+
async track(data) {
|
|
211
|
+
return this.request('/v1/track', {
|
|
212
|
+
method: 'POST',
|
|
213
|
+
body: JSON.stringify(data),
|
|
214
|
+
}, true // Use public key for tracking
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
// ==========================================================================
|
|
218
|
+
// Utility Methods
|
|
219
|
+
// ==========================================================================
|
|
220
|
+
/**
|
|
221
|
+
* Find a contact by email
|
|
222
|
+
*/
|
|
223
|
+
async findContactByEmail(email) {
|
|
224
|
+
const { contacts } = await this.getContacts();
|
|
225
|
+
return contacts.find(c => c.email.toLowerCase() === email.toLowerCase()) || null;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Create or update a contact by email
|
|
229
|
+
*/
|
|
230
|
+
async upsertContact(data) {
|
|
231
|
+
const existing = await this.findContactByEmail(data.email);
|
|
232
|
+
if (existing) {
|
|
233
|
+
return this.updateContact(existing.id, {
|
|
234
|
+
subscribed: data.subscribed,
|
|
235
|
+
data: data.data,
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
return this.createContact(data);
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Get count of subscribed contacts
|
|
242
|
+
*/
|
|
243
|
+
async getSubscribedCount() {
|
|
244
|
+
const { contacts } = await this.getContacts();
|
|
245
|
+
return contacts.filter(c => c.subscribed).length;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Create a Plunk client from environment configuration
|
|
250
|
+
*/
|
|
251
|
+
export function createPlunkClient(env) {
|
|
252
|
+
if (!env.HG_EMAILS_PLUNK_SECRET_KEY) {
|
|
253
|
+
throw new Error('HG_EMAILS_PLUNK_SECRET_KEY is required');
|
|
254
|
+
}
|
|
255
|
+
return new PlunkClient({
|
|
256
|
+
secretKey: env.HG_EMAILS_PLUNK_SECRET_KEY,
|
|
257
|
+
publicKey: env.HG_EMAILS_PLUNK_PUBLIC_KEY,
|
|
258
|
+
});
|
|
259
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/middleware/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/middleware/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAsCrC,wBAAsB,cAAc,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI;;;;;;0FAuE1D"}
|
package/dist/middleware/auth.js
CHANGED
|
@@ -8,15 +8,12 @@ function getModuleFromPath(pathname) {
|
|
|
8
8
|
if (pathname.includes('/api/admin/cms') || pathname.includes('/api/admin/collections') || pathname.includes('/api/admin/assets')) {
|
|
9
9
|
return 'cms';
|
|
10
10
|
}
|
|
11
|
-
if (pathname.includes('/api/admin
|
|
12
|
-
return '
|
|
11
|
+
if (pathname.includes('/api/email/admin')) {
|
|
12
|
+
return 'emails';
|
|
13
13
|
}
|
|
14
14
|
if (pathname.includes('/api/admin/shop')) {
|
|
15
15
|
return 'shop';
|
|
16
16
|
}
|
|
17
|
-
/* if (pathname.includes('/api/admin/builder')) {
|
|
18
|
-
return 'builder';
|
|
19
|
-
} */
|
|
20
17
|
return null;
|
|
21
18
|
}
|
|
22
19
|
/**
|
package/package.json
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
2
|
+
"name": "@hintergrund/worker",
|
|
3
|
+
"version": "0.1.5",
|
|
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
|
+
"scripts": {
|
|
14
|
+
"build": "tsc",
|
|
15
|
+
"dev": "tsc --watch"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@cloudflare/workers-types": "^4.20250111.0",
|
|
22
|
+
"concurrently": "^9.2.1",
|
|
23
|
+
"typescript": "^5.5.2"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@hintergrund/shared": "workspace:*",
|
|
27
|
+
"@octokit/rest": "^22.0.0",
|
|
28
|
+
"cookie": "^1.0.2",
|
|
29
|
+
"hono": "^4.10.2",
|
|
30
|
+
"pdf-lib": "^1.17.1",
|
|
31
|
+
"stripe": "^17.5.0"
|
|
32
|
+
}
|
|
33
|
+
}
|