@hintergrund/worker 0.1.1 → 0.1.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.
Files changed (94) hide show
  1. package/dist/api/cms/handlers/assets.handler.d.ts +24 -1
  2. package/dist/api/cms/handlers/assets.handler.d.ts.map +1 -1
  3. package/dist/api/cms/handlers/assets.handler.js +111 -210
  4. package/dist/api/cms/handlers/config.handler.d.ts +4 -0
  5. package/dist/api/cms/handlers/config.handler.d.ts.map +1 -1
  6. package/dist/api/cms/handlers/config.handler.js +20 -71
  7. package/dist/api/cms/handlers/content.handler.d.ts +12 -1
  8. package/dist/api/cms/handlers/content.handler.d.ts.map +1 -1
  9. package/dist/api/cms/handlers/content.handler.js +57 -233
  10. package/dist/api/cms/handlers/dashboard.handler.js +1 -1
  11. package/dist/api/emails/handlers/branding.handler.d.ts +17 -0
  12. package/dist/api/emails/handlers/branding.handler.d.ts.map +1 -0
  13. package/dist/api/emails/handlers/branding.handler.js +120 -0
  14. package/dist/api/emails/handlers/campaigns.handler.d.ts +32 -0
  15. package/dist/api/emails/handlers/campaigns.handler.d.ts.map +1 -0
  16. package/dist/api/emails/handlers/campaigns.handler.js +139 -0
  17. package/dist/api/emails/handlers/contacts.handler.d.ts +37 -0
  18. package/dist/api/emails/handlers/contacts.handler.d.ts.map +1 -0
  19. package/dist/api/emails/handlers/contacts.handler.js +161 -0
  20. package/dist/api/emails/handlers/invoice.handler.d.ts +30 -0
  21. package/dist/api/emails/handlers/invoice.handler.d.ts.map +1 -0
  22. package/dist/api/emails/handlers/invoice.handler.js +463 -0
  23. package/dist/api/emails/handlers/public.handler.d.ts +36 -0
  24. package/dist/api/emails/handlers/public.handler.d.ts.map +1 -0
  25. package/dist/api/emails/handlers/public.handler.js +350 -0
  26. package/dist/api/emails/handlers/send.handler.d.ts +23 -0
  27. package/dist/api/emails/handlers/send.handler.d.ts.map +1 -0
  28. package/dist/api/emails/handlers/send.handler.js +117 -0
  29. package/dist/api/emails/handlers/settings.handler.d.ts +36 -0
  30. package/dist/api/emails/handlers/settings.handler.d.ts.map +1 -0
  31. package/dist/api/emails/handlers/settings.handler.js +312 -0
  32. package/dist/api/emails/handlers/templates.handler.d.ts +32 -0
  33. package/dist/api/emails/handlers/templates.handler.d.ts.map +1 -0
  34. package/dist/api/emails/handlers/templates.handler.js +132 -0
  35. package/dist/api/emails/routes/admin.routes.d.ts +9 -0
  36. package/dist/api/emails/routes/admin.routes.d.ts.map +1 -0
  37. package/dist/api/emails/routes/admin.routes.js +77 -0
  38. package/dist/api/emails/routes/index.d.ts +9 -0
  39. package/dist/api/emails/routes/index.d.ts.map +1 -0
  40. package/dist/api/emails/routes/index.js +14 -0
  41. package/dist/api/emails/routes/public.routes.d.ts +9 -0
  42. package/dist/api/emails/routes/public.routes.d.ts.map +1 -0
  43. package/dist/api/emails/routes/public.routes.js +15 -0
  44. package/dist/api/newsletter/handlers/emails.handler.d.ts +13 -3
  45. package/dist/api/newsletter/handlers/emails.handler.d.ts.map +1 -1
  46. package/dist/api/newsletter/handlers/emails.handler.js +140 -12
  47. package/dist/api/newsletter/handlers/invoice.handler.d.ts +22 -0
  48. package/dist/api/newsletter/handlers/invoice.handler.d.ts.map +1 -0
  49. package/dist/api/newsletter/handlers/invoice.handler.js +455 -0
  50. package/dist/api/newsletter/handlers/public.handler.d.ts +4 -4
  51. package/dist/api/newsletter/handlers/public.handler.d.ts.map +1 -1
  52. package/dist/api/newsletter/handlers/public.handler.js +78 -20
  53. package/dist/api/newsletter/handlers/send.handler.d.ts +2 -2
  54. package/dist/api/newsletter/handlers/send.handler.js +3 -3
  55. package/dist/api/newsletter/handlers/subscribers.handler.d.ts +4 -4
  56. package/dist/api/newsletter/handlers/subscribers.handler.d.ts.map +1 -1
  57. package/dist/api/newsletter/handlers/subscribers.handler.js +8 -4
  58. package/dist/api/newsletter/routes/admin.routes.d.ts.map +1 -1
  59. package/dist/api/newsletter/routes/admin.routes.js +8 -1
  60. package/dist/api/shop/handlers/assets.handler.d.ts +3 -0
  61. package/dist/api/shop/handlers/assets.handler.d.ts.map +1 -0
  62. package/dist/api/shop/handlers/assets.handler.js +62 -0
  63. package/dist/api/shop/handlers/checkout.handler.d.ts +10 -0
  64. package/dist/api/shop/handlers/checkout.handler.d.ts.map +1 -0
  65. package/dist/api/shop/handlers/checkout.handler.js +50 -0
  66. package/dist/api/shop/handlers/products.handler.d.ts +0 -7
  67. package/dist/api/shop/handlers/products.handler.d.ts.map +1 -1
  68. package/dist/api/shop/handlers/products.handler.js +0 -23
  69. package/dist/api/shop/handlers/public.handler.d.ts +17 -0
  70. package/dist/api/shop/handlers/public.handler.d.ts.map +1 -0
  71. package/dist/api/shop/handlers/public.handler.js +108 -0
  72. package/dist/api/shop/handlers/webhook.handler.d.ts +10 -0
  73. package/dist/api/shop/handlers/webhook.handler.d.ts.map +1 -0
  74. package/dist/api/shop/handlers/webhook.handler.js +233 -0
  75. package/dist/api/shop/routes.d.ts.map +1 -1
  76. package/dist/api/shop/routes.js +9 -12
  77. package/dist/hintergrund-assets.d.ts +2 -2
  78. package/dist/hintergrund-assets.d.ts.map +1 -1
  79. package/dist/hintergrund-assets.js +2 -2
  80. package/dist/index.d.ts +9 -17
  81. package/dist/index.d.ts.map +1 -1
  82. package/dist/index.js +4 -7
  83. package/dist/lib/config.d.ts +13 -7
  84. package/dist/lib/config.d.ts.map +1 -1
  85. package/dist/lib/config.js +39 -44
  86. package/dist/lib/github.d.ts +124 -0
  87. package/dist/lib/github.d.ts.map +1 -0
  88. package/dist/lib/github.js +286 -0
  89. package/dist/lib/plunk.d.ts +207 -0
  90. package/dist/lib/plunk.d.ts.map +1 -0
  91. package/dist/lib/plunk.js +262 -0
  92. package/dist/middleware/auth.d.ts.map +1 -1
  93. package/dist/middleware/auth.js +2 -5
  94. package/package.json +32 -31
@@ -0,0 +1,207 @@
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
+ import type { Contact, PlunkTemplate, PlunkCampaign } from '@hintergrund/shared';
12
+ interface PlunkConfig {
13
+ secretKey: string;
14
+ publicKey?: string;
15
+ projectName?: string;
16
+ }
17
+ interface PlunkContactResponse {
18
+ success: boolean;
19
+ id: string;
20
+ email: string;
21
+ subscribed: boolean;
22
+ }
23
+ interface PlunkTemplateResponse {
24
+ success: boolean;
25
+ id: string;
26
+ }
27
+ interface PlunkCampaignResponse {
28
+ success: boolean;
29
+ id: string;
30
+ timestamp: string;
31
+ emails?: PlunkCampaignEmail[];
32
+ }
33
+ interface PlunkCampaignEmail {
34
+ contact: string;
35
+ email: string;
36
+ }
37
+ interface PlunkSendResponse {
38
+ success: boolean;
39
+ emails?: Array<{
40
+ contact: {
41
+ id: string;
42
+ };
43
+ email: string;
44
+ }>;
45
+ }
46
+ interface PlunkTrackResponse {
47
+ success: boolean;
48
+ contact: string;
49
+ event: string;
50
+ timestamp: string;
51
+ }
52
+ export declare class PlunkClient {
53
+ private baseUrl;
54
+ private secretKey;
55
+ private publicKey?;
56
+ private projectName?;
57
+ constructor(config: PlunkConfig);
58
+ private request;
59
+ /**
60
+ * Get all contacts
61
+ */
62
+ getContacts(): Promise<{
63
+ contacts: Contact[];
64
+ count: number;
65
+ }>;
66
+ /**
67
+ * Get a single contact by ID
68
+ */
69
+ getContact(id: string): Promise<Contact>;
70
+ /**
71
+ * Create a new contact
72
+ */
73
+ createContact(data: {
74
+ email: string;
75
+ subscribed?: boolean;
76
+ data?: Record<string, unknown>;
77
+ }): Promise<PlunkContactResponse>;
78
+ /**
79
+ * Update an existing contact
80
+ */
81
+ updateContact(id: string, data: {
82
+ subscribed?: boolean;
83
+ data?: Record<string, unknown>;
84
+ }): Promise<PlunkContactResponse>;
85
+ /**
86
+ * Delete a contact
87
+ */
88
+ deleteContact(id: string): Promise<{
89
+ success: boolean;
90
+ }>;
91
+ /**
92
+ * Subscribe a contact (set subscribed to true)
93
+ */
94
+ subscribeContact(id: string): Promise<PlunkContactResponse>;
95
+ /**
96
+ * Unsubscribe a contact (set subscribed to false)
97
+ */
98
+ unsubscribeContact(id: string): Promise<PlunkContactResponse>;
99
+ /**
100
+ * Get all templates
101
+ */
102
+ getTemplates(): Promise<{
103
+ templates: PlunkTemplate[];
104
+ }>;
105
+ /**
106
+ * Get a single template by ID
107
+ */
108
+ getTemplate(id: string): Promise<PlunkTemplate>;
109
+ /**
110
+ * Create a new template
111
+ */
112
+ createTemplate(data: {
113
+ name: string;
114
+ subject: string;
115
+ body: string;
116
+ type?: 'TRANSACTIONAL' | 'MARKETING';
117
+ }): Promise<PlunkTemplateResponse>;
118
+ /**
119
+ * Update an existing template
120
+ */
121
+ updateTemplate(id: string, data: {
122
+ name?: string;
123
+ subject?: string;
124
+ body?: string;
125
+ }): Promise<PlunkTemplateResponse>;
126
+ /**
127
+ * Delete a template
128
+ */
129
+ deleteTemplate(id: string): Promise<{
130
+ success: boolean;
131
+ }>;
132
+ /**
133
+ * Get all campaigns
134
+ */
135
+ getCampaigns(): Promise<{
136
+ campaigns: PlunkCampaign[];
137
+ }>;
138
+ /**
139
+ * Get a single campaign by ID
140
+ */
141
+ getCampaign(id: string): Promise<PlunkCampaign>;
142
+ /**
143
+ * Create a new campaign (draft)
144
+ */
145
+ createCampaign(data: {
146
+ name: string;
147
+ subject: string;
148
+ body: string;
149
+ from?: string;
150
+ style?: Record<string, string>;
151
+ }): Promise<PlunkCampaignResponse>;
152
+ /**
153
+ * Send a campaign to all subscribed contacts
154
+ */
155
+ sendCampaign(id: string): Promise<PlunkCampaignResponse>;
156
+ /**
157
+ * Send a test email for a campaign to a specific email
158
+ */
159
+ testCampaign(id: string, email: string): Promise<PlunkSendResponse>;
160
+ /**
161
+ * Send a transactional email
162
+ */
163
+ send(data: {
164
+ to: string;
165
+ subject: string;
166
+ body: string;
167
+ name?: string;
168
+ from?: string;
169
+ replyTo?: string;
170
+ headers?: Record<string, string>;
171
+ }): Promise<PlunkSendResponse>;
172
+ /**
173
+ * Track an event for a contact
174
+ * Uses the public key if available for client-side tracking
175
+ */
176
+ track(data: {
177
+ email: string;
178
+ event: string;
179
+ data?: Record<string, unknown>;
180
+ }): Promise<PlunkTrackResponse>;
181
+ /**
182
+ * Find a contact by email
183
+ */
184
+ findContactByEmail(email: string): Promise<Contact | null>;
185
+ /**
186
+ * Create or update a contact by email
187
+ */
188
+ upsertContact(data: {
189
+ email: string;
190
+ subscribed?: boolean;
191
+ data?: Record<string, unknown>;
192
+ }): Promise<PlunkContactResponse>;
193
+ /**
194
+ * Get count of subscribed contacts
195
+ */
196
+ getSubscribedCount(): Promise<number>;
197
+ }
198
+ /**
199
+ * Create a Plunk client from environment configuration
200
+ */
201
+ export declare function createPlunkClient(env: {
202
+ HG_EMAILS_PLUNK_SECRET_KEY?: string;
203
+ HG_EMAILS_PLUNK_PUBLIC_KEY?: string;
204
+ HG_EMAILS_PLUNK_PROJECT?: string;
205
+ }): PlunkClient;
206
+ export {};
207
+ //# sourceMappingURL=plunk.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plunk.d.ts","sourceRoot":"","sources":["../../src/lib/plunk.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EACX,OAAO,EACP,aAAa,EACb,aAAa,EACb,MAAM,qBAAqB,CAAC;AAE7B,UAAU,WAAW;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAOD,UAAU,oBAAoB;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,OAAO,CAAC;CACpB;AAMD,UAAU,qBAAqB;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,EAAE,EAAE,MAAM,CAAC;CACX;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CAAC,IAAI,EAAE;QACzB,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,CAAC,EAAE,OAAO,CAAC;QACrB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAC/B,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAajC;;OAEG;IACG,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;CAI3C;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE;IACtC,0BAA0B,CAAC,EAAE,MAAM,CAAC;IACpC,0BAA0B,CAAC,EAAE,MAAM,CAAC;IACpC,uBAAuB,CAAC,EAAE,MAAM,CAAC;CACjC,GAAG,WAAW,CAUd"}
@@ -0,0 +1,262 @@
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
+ this.projectName = config.projectName;
17
+ }
18
+ async request(endpoint, options = {}, usePublicKey = false) {
19
+ const apiKey = usePublicKey && this.publicKey ? this.publicKey : this.secretKey;
20
+ const response = await fetch(`${this.baseUrl}${endpoint}`, {
21
+ ...options,
22
+ headers: {
23
+ 'Content-Type': 'application/json',
24
+ 'Authorization': `Bearer ${apiKey}`,
25
+ ...options.headers,
26
+ },
27
+ });
28
+ const data = await response.json();
29
+ if (!response.ok) {
30
+ const error = data;
31
+ // Enhanced error logging
32
+ const projectInfo = this.projectName ? ` (Project: ${this.projectName})` : '';
33
+ console.error(`Plunk API Error${projectInfo}: ${error.error || error.message}`);
34
+ throw new Error(error.message || error.error || `Plunk API error: ${response.status}`);
35
+ }
36
+ return data;
37
+ }
38
+ // ==========================================================================
39
+ // Contacts
40
+ // ==========================================================================
41
+ /**
42
+ * Get all contacts
43
+ */
44
+ async getContacts() {
45
+ const response = await this.request('/contacts');
46
+ return {
47
+ contacts: response.data || [],
48
+ count: response.count || 0,
49
+ };
50
+ }
51
+ /**
52
+ * Get a single contact by ID
53
+ */
54
+ async getContact(id) {
55
+ return this.request(`/contacts/${id}`);
56
+ }
57
+ /**
58
+ * Create a new contact
59
+ */
60
+ async createContact(data) {
61
+ return this.request('/contacts', {
62
+ method: 'POST',
63
+ body: JSON.stringify(data),
64
+ });
65
+ }
66
+ /**
67
+ * Update an existing contact
68
+ */
69
+ async updateContact(id, data) {
70
+ return this.request(`/contacts/${id}`, {
71
+ method: 'PUT',
72
+ body: JSON.stringify(data),
73
+ });
74
+ }
75
+ /**
76
+ * Delete a contact
77
+ */
78
+ async deleteContact(id) {
79
+ return this.request(`/contacts/${id}`, {
80
+ method: 'DELETE',
81
+ });
82
+ }
83
+ /**
84
+ * Subscribe a contact (set subscribed to true)
85
+ */
86
+ async subscribeContact(id) {
87
+ return this.updateContact(id, { subscribed: true });
88
+ }
89
+ /**
90
+ * Unsubscribe a contact (set subscribed to false)
91
+ */
92
+ async unsubscribeContact(id) {
93
+ return this.updateContact(id, { subscribed: false });
94
+ }
95
+ // ==========================================================================
96
+ // Templates
97
+ // ==========================================================================
98
+ /**
99
+ * Get all templates
100
+ */
101
+ async getTemplates() {
102
+ const response = await this.request('/templates');
103
+ return {
104
+ templates: response.data || [],
105
+ };
106
+ }
107
+ /**
108
+ * Get a single template by ID
109
+ */
110
+ async getTemplate(id) {
111
+ return this.request(`/templates/${id}`);
112
+ }
113
+ /**
114
+ * Create a new template
115
+ */
116
+ async createTemplate(data) {
117
+ return this.request('/templates', {
118
+ method: 'POST',
119
+ body: JSON.stringify({
120
+ ...data,
121
+ type: data.type || 'TRANSACTIONAL',
122
+ }),
123
+ });
124
+ }
125
+ /**
126
+ * Update an existing template
127
+ */
128
+ async updateTemplate(id, data) {
129
+ return this.request(`/templates/${id}`, {
130
+ method: 'PUT',
131
+ body: JSON.stringify(data),
132
+ });
133
+ }
134
+ /**
135
+ * Delete a template
136
+ */
137
+ async deleteTemplate(id) {
138
+ return this.request(`/templates/${id}`, {
139
+ method: 'DELETE',
140
+ });
141
+ }
142
+ // ==========================================================================
143
+ // Campaigns
144
+ // ==========================================================================
145
+ /**
146
+ * Get all campaigns
147
+ */
148
+ async getCampaigns() {
149
+ const response = await this.request('/campaigns');
150
+ return {
151
+ campaigns: response.data || [],
152
+ };
153
+ }
154
+ /**
155
+ * Get a single campaign by ID
156
+ */
157
+ async getCampaign(id) {
158
+ return this.request(`/campaigns/${id}`);
159
+ }
160
+ /**
161
+ * Create a new campaign (draft)
162
+ */
163
+ async createCampaign(data) {
164
+ return this.request('/campaigns', {
165
+ method: 'POST',
166
+ body: JSON.stringify({
167
+ ...data,
168
+ recipients: 'all', // Send to all subscribed contacts
169
+ }),
170
+ });
171
+ }
172
+ /**
173
+ * Send a campaign to all subscribed contacts
174
+ */
175
+ async sendCampaign(id) {
176
+ return this.request(`/campaigns/${id}/send`, {
177
+ method: 'POST',
178
+ });
179
+ }
180
+ /**
181
+ * Send a test email for a campaign to a specific email
182
+ */
183
+ async testCampaign(id, email) {
184
+ // Get the campaign to use its content
185
+ const campaign = await this.getCampaign(id);
186
+ // Send as transactional to the test email
187
+ return this.send({
188
+ to: email,
189
+ subject: `[TEST] ${campaign.subject}`,
190
+ body: campaign.body || '',
191
+ });
192
+ }
193
+ // ==========================================================================
194
+ // Transactional Emails
195
+ // ==========================================================================
196
+ /**
197
+ * Send a transactional email
198
+ */
199
+ async send(data) {
200
+ return this.request('/v1/send', {
201
+ method: 'POST',
202
+ body: JSON.stringify(data),
203
+ });
204
+ }
205
+ // ==========================================================================
206
+ // Event Tracking
207
+ // ==========================================================================
208
+ /**
209
+ * Track an event for a contact
210
+ * Uses the public key if available for client-side tracking
211
+ */
212
+ async track(data) {
213
+ return this.request('/v1/track', {
214
+ method: 'POST',
215
+ body: JSON.stringify(data),
216
+ }, true // Use public key for tracking
217
+ );
218
+ }
219
+ // ==========================================================================
220
+ // Utility Methods
221
+ // ==========================================================================
222
+ /**
223
+ * Find a contact by email
224
+ */
225
+ async findContactByEmail(email) {
226
+ const { contacts } = await this.getContacts();
227
+ return contacts.find(c => c.email.toLowerCase() === email.toLowerCase()) || null;
228
+ }
229
+ /**
230
+ * Create or update a contact by email
231
+ */
232
+ async upsertContact(data) {
233
+ const existing = await this.findContactByEmail(data.email);
234
+ if (existing) {
235
+ return this.updateContact(existing.id, {
236
+ subscribed: data.subscribed,
237
+ data: data.data,
238
+ });
239
+ }
240
+ return this.createContact(data);
241
+ }
242
+ /**
243
+ * Get count of subscribed contacts
244
+ */
245
+ async getSubscribedCount() {
246
+ const { contacts } = await this.getContacts();
247
+ return contacts.filter(c => c.subscribed).length;
248
+ }
249
+ }
250
+ /**
251
+ * Create a Plunk client from environment configuration
252
+ */
253
+ export function createPlunkClient(env) {
254
+ if (!env.HG_EMAILS_PLUNK_SECRET_KEY) {
255
+ throw new Error('HG_EMAILS_PLUNK_SECRET_KEY is required');
256
+ }
257
+ return new PlunkClient({
258
+ secretKey: env.HG_EMAILS_PLUNK_SECRET_KEY,
259
+ publicKey: env.HG_EMAILS_PLUNK_PUBLIC_KEY,
260
+ projectName: env.HG_EMAILS_PLUNK_PROJECT,
261
+ });
262
+ }
@@ -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;AAyCrC,wBAAsB,cAAc,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI;;;;;;0FAuE1D"}
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"}
@@ -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/newsletter')) {
12
- return 'newsletter';
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,32 +1,33 @@
1
1
  {
2
- "name": "@hintergrund/worker",
3
- "version": "0.1.1",
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
- "stripe": "^17.5.0"
31
- }
32
- }
2
+ "name": "@hintergrund/worker",
3
+ "version": "0.1.3",
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
+ "pdf-lib": "^1.17.1",
26
+ "stripe": "^17.5.0",
27
+ "@hintergrund/shared": "0.1.3"
28
+ },
29
+ "scripts": {
30
+ "build": "tsc",
31
+ "dev": "tsc --watch"
32
+ }
33
+ }