@zeyolabs/shopping 2026.11.8 → 2026.11.9
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zeyolabs/shopping",
|
|
3
|
-
"version": "2026.11.
|
|
3
|
+
"version": "2026.11.9",
|
|
4
4
|
"description": "Shop and order fulfilment for SvelteKit 3 on Cloudflare: catalogue, basket, Stripe Checkout, orders, Royal Mail Click & Drop, order emails, packing, pages and admin.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { and, eq } from 'drizzle-orm';
|
|
2
|
+
|
|
3
|
+
import type { ShopDb } from '../db';
|
|
4
|
+
|
|
5
|
+
import { products, stockAlerts } from '../db/schema';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Data access for "tell me when it's back" signups. It takes the db it works on; it checks no
|
|
9
|
+
* permissions and sends nothing (the back-in-stock job in `stock-alerts.ts` does the sending).
|
|
10
|
+
*/
|
|
11
|
+
export class StockAlertService {
|
|
12
|
+
constructor(private readonly db: ShopDb) {}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Adds a signup for an active product and returns the product's name, or null when there is no
|
|
16
|
+
* such active product. Signing up twice is fine and is not reported, so a caller cannot tell
|
|
17
|
+
* whether an address was already on the list.
|
|
18
|
+
*/
|
|
19
|
+
async subscribe(email: string, productId: number): Promise<null | { productName: string }> {
|
|
20
|
+
const product = await this.db.query.products.findFirst({
|
|
21
|
+
where: and(eq(products.id, productId), eq(products.active, true)),
|
|
22
|
+
});
|
|
23
|
+
if (!product) return null;
|
|
24
|
+
await this.db
|
|
25
|
+
.insert(stockAlerts)
|
|
26
|
+
.values({ createdAt: Date.now(), email: email.toLowerCase(), productId })
|
|
27
|
+
.onConflictDoNothing();
|
|
28
|
+
return { productName: product.name };
|
|
29
|
+
}
|
|
30
|
+
}
|