@umec/core 0.1.0-alpha.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/LICENSE +21 -0
- package/dist/access.d.ts +18 -0
- package/dist/access.js +7 -0
- package/dist/access.js.map +1 -0
- package/dist/checkout.d.ts +28 -0
- package/dist/checkout.js +8 -0
- package/dist/checkout.js.map +1 -0
- package/dist/chunk-2NYFCO5V.js +192 -0
- package/dist/chunk-2NYFCO5V.js.map +1 -0
- package/dist/chunk-2SNGXEIL.js +37 -0
- package/dist/chunk-2SNGXEIL.js.map +1 -0
- package/dist/chunk-7TJANK6S.js +10 -0
- package/dist/chunk-7TJANK6S.js.map +1 -0
- package/dist/chunk-7ZJOZAEO.js +82 -0
- package/dist/chunk-7ZJOZAEO.js.map +1 -0
- package/dist/chunk-QRFFBMFN.js +109 -0
- package/dist/chunk-QRFFBMFN.js.map +1 -0
- package/dist/chunk-REUSLO5I.js +199 -0
- package/dist/chunk-REUSLO5I.js.map +1 -0
- package/dist/chunk-WZFM6R5J.js +47 -0
- package/dist/chunk-WZFM6R5J.js.map +1 -0
- package/dist/chunk-X2SNVVFW.js +73 -0
- package/dist/chunk-X2SNVVFW.js.map +1 -0
- package/dist/config.d.ts +67 -0
- package/dist/config.js +11 -0
- package/dist/config.js.map +1 -0
- package/dist/env.d.ts +15 -0
- package/dist/env.js +7 -0
- package/dist/env.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +41 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware.d.ts +13 -0
- package/dist/middleware.js +7 -0
- package/dist/middleware.js.map +1 -0
- package/dist/notify.d.ts +23 -0
- package/dist/notify.js +7 -0
- package/dist/notify.js.map +1 -0
- package/dist/subscribe.d.ts +9 -0
- package/dist/subscribe.js +8 -0
- package/dist/subscribe.js.map +1 -0
- package/dist/webhook.d.ts +65 -0
- package/dist/webhook.js +10 -0
- package/dist/webhook.js.map +1 -0
- package/package.json +80 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Daisuke Murayama
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/access.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { JWTVerifyGetKey, JWTPayload } from 'jose';
|
|
2
|
+
|
|
3
|
+
interface AccessGuardOptions {
|
|
4
|
+
teamDomain: string;
|
|
5
|
+
aud: string;
|
|
6
|
+
getKey?: JWTVerifyGetKey;
|
|
7
|
+
}
|
|
8
|
+
type AccessGuardResult = {
|
|
9
|
+
ok: true;
|
|
10
|
+
payload: JWTPayload;
|
|
11
|
+
} | {
|
|
12
|
+
ok: false;
|
|
13
|
+
status: 403;
|
|
14
|
+
error: string;
|
|
15
|
+
};
|
|
16
|
+
declare function createAccessGuard(options: AccessGuardOptions): (request: Request) => Promise<AccessGuardResult>;
|
|
17
|
+
|
|
18
|
+
export { type AccessGuardOptions, type AccessGuardResult, createAccessGuard };
|
package/dist/access.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { UmecProduct, UmecConfig } from './config.js';
|
|
2
|
+
import 'zod';
|
|
3
|
+
|
|
4
|
+
type CheckoutProductsMap = Record<string, UmecProduct | undefined>;
|
|
5
|
+
type CheckoutOffer = {
|
|
6
|
+
priceOverrides: Record<string, number>;
|
|
7
|
+
freeShipping: boolean;
|
|
8
|
+
recipientInfo: boolean;
|
|
9
|
+
unitsRemaining?: Map<string, number>;
|
|
10
|
+
};
|
|
11
|
+
type CheckoutOfferUnavailable = {
|
|
12
|
+
error: "Offer not found" | "Offer expired";
|
|
13
|
+
status: 404 | 410;
|
|
14
|
+
};
|
|
15
|
+
type CheckStock = (skus: string[]) => Promise<Map<string, number>>;
|
|
16
|
+
type CheckOffer = (offerSlug: string) => Promise<CheckoutOffer | CheckoutOfferUnavailable | null>;
|
|
17
|
+
type CheckoutHandlerOptions = {
|
|
18
|
+
products: CheckoutProductsMap;
|
|
19
|
+
shipping?: UmecConfig["shipping"];
|
|
20
|
+
checkStock?: CheckStock;
|
|
21
|
+
checkOffer?: CheckOffer;
|
|
22
|
+
};
|
|
23
|
+
type CheckoutHandler = ({ request }: {
|
|
24
|
+
request: Request;
|
|
25
|
+
}) => Promise<Response>;
|
|
26
|
+
declare function createCheckoutHandler({ products, shipping, checkStock, checkOffer, }: CheckoutHandlerOptions): CheckoutHandler;
|
|
27
|
+
|
|
28
|
+
export { type CheckOffer, type CheckStock, type CheckoutHandler, type CheckoutHandlerOptions, type CheckoutOffer, type CheckoutOfferUnavailable, type CheckoutProductsMap, createCheckoutHandler };
|
package/dist/checkout.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getServerEnv
|
|
3
|
+
} from "./chunk-7TJANK6S.js";
|
|
4
|
+
|
|
5
|
+
// src/checkout.ts
|
|
6
|
+
import Stripe from "stripe";
|
|
7
|
+
var STRIPE_API_VERSION = "2026-05-27.dahlia";
|
|
8
|
+
var MAX_ITEMS = 10;
|
|
9
|
+
var MAX_QUANTITY = 20;
|
|
10
|
+
function jsonError(error, status) {
|
|
11
|
+
return new Response(JSON.stringify({ error }), {
|
|
12
|
+
status,
|
|
13
|
+
headers: { "Content-Type": "application/json" }
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
function isCheckoutPayload(value) {
|
|
17
|
+
return typeof value === "object" && value !== null;
|
|
18
|
+
}
|
|
19
|
+
function isValidQuantity(value) {
|
|
20
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 1;
|
|
21
|
+
}
|
|
22
|
+
function isOfferUnavailable(value) {
|
|
23
|
+
return "error" in value && "status" in value;
|
|
24
|
+
}
|
|
25
|
+
function calcShipping(items, products, shipping) {
|
|
26
|
+
const totalUnits = items.reduce((sum, { sku, quantity }) => {
|
|
27
|
+
return sum + (products[sku]?.shippingUnits ?? 1) * quantity;
|
|
28
|
+
}, 0);
|
|
29
|
+
const tier = shipping.tiers.find((shippingTier) => {
|
|
30
|
+
return shippingTier.maxUnits === void 0 || totalUnits <= shippingTier.maxUnits;
|
|
31
|
+
}) ?? shipping.tiers[shipping.tiers.length - 1];
|
|
32
|
+
return {
|
|
33
|
+
amount: tier.amount,
|
|
34
|
+
label: tier.label
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function createCheckoutHandler({
|
|
38
|
+
products,
|
|
39
|
+
shipping,
|
|
40
|
+
checkStock,
|
|
41
|
+
checkOffer
|
|
42
|
+
}) {
|
|
43
|
+
return async ({ request }) => {
|
|
44
|
+
const { STRIPE_SECRET_KEY: stripeKey } = getServerEnv();
|
|
45
|
+
if (!stripeKey) return jsonError("Stripe not configured", 503);
|
|
46
|
+
const stripe = new Stripe(stripeKey, {
|
|
47
|
+
apiVersion: STRIPE_API_VERSION
|
|
48
|
+
});
|
|
49
|
+
let payload;
|
|
50
|
+
try {
|
|
51
|
+
payload = await request.json();
|
|
52
|
+
} catch {
|
|
53
|
+
return jsonError("Invalid request body", 400);
|
|
54
|
+
}
|
|
55
|
+
if (!isCheckoutPayload(payload)) return jsonError("Invalid request body", 400);
|
|
56
|
+
const { items } = payload;
|
|
57
|
+
if (!Array.isArray(items) || items.length === 0) return jsonError("Invalid items", 400);
|
|
58
|
+
if (items.length > MAX_ITEMS) return jsonError("Invalid items", 400);
|
|
59
|
+
const rawItems = [];
|
|
60
|
+
for (const item of items) {
|
|
61
|
+
if (typeof item !== "object" || item === null) return jsonError("Invalid SKU", 400);
|
|
62
|
+
const { sku, quantity } = item;
|
|
63
|
+
if (typeof sku !== "string" || !products[sku]) return jsonError("Invalid SKU", 400);
|
|
64
|
+
if (!isValidQuantity(quantity)) return jsonError("Invalid quantity", 400);
|
|
65
|
+
rawItems.push({ sku, quantity });
|
|
66
|
+
}
|
|
67
|
+
const quantityMap = /* @__PURE__ */ new Map();
|
|
68
|
+
for (const { sku, quantity } of rawItems) {
|
|
69
|
+
quantityMap.set(sku, (quantityMap.get(sku) ?? 0) + quantity);
|
|
70
|
+
}
|
|
71
|
+
for (const [, total] of quantityMap) {
|
|
72
|
+
if (total > MAX_QUANTITY) return jsonError("Invalid quantity", 400);
|
|
73
|
+
}
|
|
74
|
+
const checkoutItems = Array.from(quantityMap.entries()).map(
|
|
75
|
+
([sku, quantity]) => ({ sku, quantity })
|
|
76
|
+
);
|
|
77
|
+
const { offerSlug } = payload;
|
|
78
|
+
let priceOverrides = {};
|
|
79
|
+
let freeShipping = false;
|
|
80
|
+
let recipientInfo = false;
|
|
81
|
+
if (typeof offerSlug === "string" && offerSlug.trim() !== "") {
|
|
82
|
+
if (!checkOffer) return jsonError("Offer not available", 503);
|
|
83
|
+
const offer = await checkOffer(offerSlug.trim());
|
|
84
|
+
if (!offer) return jsonError("Offer not found", 404);
|
|
85
|
+
if (isOfferUnavailable(offer)) return jsonError(offer.error, offer.status);
|
|
86
|
+
recipientInfo = offer.recipientInfo;
|
|
87
|
+
const offerUnits = offer.unitsRemaining;
|
|
88
|
+
if (offerUnits && offerUnits.size > 0) {
|
|
89
|
+
for (const { sku, quantity } of checkoutItems) {
|
|
90
|
+
const remaining = offerUnits.get(sku);
|
|
91
|
+
if (remaining !== void 0 && quantity > remaining) {
|
|
92
|
+
return jsonError(`Offer unit limit reached: ${sku}`, 409);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
priceOverrides = offer.priceOverrides;
|
|
97
|
+
freeShipping = offer.freeShipping;
|
|
98
|
+
}
|
|
99
|
+
const shippingRate = shipping ? freeShipping ? { amount: 0, label: shipping.freeLabel } : calcShipping(checkoutItems, products, shipping) : void 0;
|
|
100
|
+
const stock = checkStock ? await checkStock(checkoutItems.map((item) => item.sku)) : /* @__PURE__ */ new Map();
|
|
101
|
+
for (const { sku, quantity } of checkoutItems) {
|
|
102
|
+
const available = stock.get(sku);
|
|
103
|
+
if (available !== void 0 && quantity > available) {
|
|
104
|
+
return jsonError(`Out of stock: ${sku}`, 409);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const customFields = [];
|
|
108
|
+
if (recipientInfo) {
|
|
109
|
+
customFields.push(
|
|
110
|
+
{
|
|
111
|
+
key: "class_name",
|
|
112
|
+
label: { type: "custom", custom: "\u30AF\u30E9\u30B9\u540D" },
|
|
113
|
+
type: "text",
|
|
114
|
+
optional: false,
|
|
115
|
+
text: { maximum_length: 50 }
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
key: "child_name",
|
|
119
|
+
label: { type: "custom", custom: "\u304A\u5B50\u3055\u3093\u306E\u304A\u540D\u524D" },
|
|
120
|
+
type: "text",
|
|
121
|
+
optional: false,
|
|
122
|
+
text: { maximum_length: 50 }
|
|
123
|
+
}
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
customFields.push({
|
|
127
|
+
key: "message",
|
|
128
|
+
label: { type: "custom", custom: "\u30E1\u30C3\u30BB\u30FC\u30B8\u30FB\u3054\u8981\u671B\uFF08\u4EFB\u610F\uFF09" },
|
|
129
|
+
type: "text",
|
|
130
|
+
optional: true,
|
|
131
|
+
text: { maximum_length: 255 }
|
|
132
|
+
});
|
|
133
|
+
try {
|
|
134
|
+
const sessionParams = {
|
|
135
|
+
ui_mode: "embedded_page",
|
|
136
|
+
mode: "payment",
|
|
137
|
+
line_items: checkoutItems.map(({ sku, quantity }) => ({
|
|
138
|
+
price_data: {
|
|
139
|
+
currency: "jpy",
|
|
140
|
+
product_data: { name: products[sku].name },
|
|
141
|
+
unit_amount: priceOverrides[sku] ?? products[sku].price
|
|
142
|
+
},
|
|
143
|
+
quantity
|
|
144
|
+
})),
|
|
145
|
+
metadata: {
|
|
146
|
+
items: JSON.stringify(checkoutItems),
|
|
147
|
+
...typeof offerSlug === "string" && offerSlug.trim() ? { offer_slug: offerSlug.trim() } : {}
|
|
148
|
+
},
|
|
149
|
+
phone_number_collection: { enabled: true },
|
|
150
|
+
custom_fields: customFields,
|
|
151
|
+
shipping_address_collection: { allowed_countries: ["JP"] },
|
|
152
|
+
...shippingRate ? {
|
|
153
|
+
shipping_options: [
|
|
154
|
+
{
|
|
155
|
+
shipping_rate_data: {
|
|
156
|
+
type: "fixed_amount",
|
|
157
|
+
fixed_amount: { amount: shippingRate.amount, currency: "jpy" },
|
|
158
|
+
display_name: shippingRate.label,
|
|
159
|
+
delivery_estimate: {
|
|
160
|
+
minimum: { unit: "business_day", value: 2 },
|
|
161
|
+
maximum: { unit: "business_day", value: 5 }
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
]
|
|
166
|
+
} : {},
|
|
167
|
+
redirect_on_completion: "never"
|
|
168
|
+
};
|
|
169
|
+
const session = await stripe.checkout.sessions.create(sessionParams);
|
|
170
|
+
return new Response(JSON.stringify({ clientSecret: session.client_secret }), {
|
|
171
|
+
headers: { "Content-Type": "application/json" }
|
|
172
|
+
});
|
|
173
|
+
} catch (error) {
|
|
174
|
+
const stripeError = error;
|
|
175
|
+
console.error("[checkout] stripe session create failed:", {
|
|
176
|
+
type: stripeError.type,
|
|
177
|
+
code: stripeError.code,
|
|
178
|
+
statusCode: stripeError.statusCode,
|
|
179
|
+
requestId: stripeError.requestId
|
|
180
|
+
});
|
|
181
|
+
if (stripeError.type === "StripePermissionError") {
|
|
182
|
+
return jsonError("Stripe key does not have permission to create Checkout Sessions", 503);
|
|
183
|
+
}
|
|
184
|
+
return jsonError("Checkout session could not be created", 503);
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export {
|
|
190
|
+
createCheckoutHandler
|
|
191
|
+
};
|
|
192
|
+
//# sourceMappingURL=chunk-2NYFCO5V.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/checkout.ts"],"sourcesContent":["import Stripe from \"stripe\";\nimport type { UmecConfig, UmecProduct } from \"./config.js\";\nimport { getServerEnv } from \"./env.js\";\n\nconst STRIPE_API_VERSION = \"2026-05-27.dahlia\";\nconst MAX_ITEMS = 10;\nconst MAX_QUANTITY = 20;\n\ntype CheckoutItem = {\n sku: string;\n quantity: number;\n};\n\nexport type CheckoutProductsMap = Record<string, UmecProduct | undefined>;\n\nexport type CheckoutOffer = {\n priceOverrides: Record<string, number>;\n freeShipping: boolean;\n recipientInfo: boolean;\n unitsRemaining?: Map<string, number>;\n};\n\nexport type CheckoutOfferUnavailable = {\n error: \"Offer not found\" | \"Offer expired\";\n status: 404 | 410;\n};\n\nexport type CheckStock = (skus: string[]) => Promise<Map<string, number>>;\nexport type CheckOffer = (offerSlug: string) => Promise<CheckoutOffer | CheckoutOfferUnavailable | null>;\n\nexport type CheckoutHandlerOptions = {\n products: CheckoutProductsMap;\n shipping?: UmecConfig[\"shipping\"];\n checkStock?: CheckStock;\n checkOffer?: CheckOffer;\n};\n\nexport type CheckoutHandler = ({ request }: { request: Request }) => Promise<Response>;\n\nfunction jsonError(error: string, status: number) {\n return new Response(JSON.stringify({ error }), {\n status,\n headers: { \"Content-Type\": \"application/json\" },\n });\n}\n\nfunction isCheckoutPayload(value: unknown): value is { items?: unknown; offerSlug?: unknown } {\n return typeof value === \"object\" && value !== null;\n}\n\nfunction isValidQuantity(value: unknown): value is number {\n return typeof value === \"number\" && Number.isSafeInteger(value) && value >= 1;\n}\n\nfunction isOfferUnavailable(value: CheckoutOffer | CheckoutOfferUnavailable): value is CheckoutOfferUnavailable {\n return \"error\" in value && \"status\" in value;\n}\n\nfunction calcShipping(\n items: CheckoutItem[],\n products: CheckoutProductsMap,\n shipping: NonNullable<UmecConfig[\"shipping\"]>,\n) {\n const totalUnits = items.reduce((sum, { sku, quantity }) => {\n return sum + (products[sku]?.shippingUnits ?? 1) * quantity;\n }, 0);\n\n const tier = shipping.tiers.find((shippingTier) => {\n return shippingTier.maxUnits === undefined || totalUnits <= shippingTier.maxUnits;\n }) ?? shipping.tiers[shipping.tiers.length - 1]!;\n\n return {\n amount: tier.amount,\n label: tier.label,\n };\n}\n\nexport function createCheckoutHandler({\n products,\n shipping,\n checkStock,\n checkOffer,\n}: CheckoutHandlerOptions): CheckoutHandler {\n return async ({ request }) => {\n const { STRIPE_SECRET_KEY: stripeKey } = getServerEnv();\n if (!stripeKey) return jsonError(\"Stripe not configured\", 503);\n\n const stripe = new Stripe(stripeKey, {\n apiVersion: STRIPE_API_VERSION,\n });\n let payload: unknown;\n\n try {\n payload = await request.json();\n } catch {\n return jsonError(\"Invalid request body\", 400);\n }\n\n if (!isCheckoutPayload(payload)) return jsonError(\"Invalid request body\", 400);\n\n const { items } = payload;\n if (!Array.isArray(items) || items.length === 0) return jsonError(\"Invalid items\", 400);\n if (items.length > MAX_ITEMS) return jsonError(\"Invalid items\", 400);\n\n const rawItems: CheckoutItem[] = [];\n for (const item of items) {\n if (typeof item !== \"object\" || item === null) return jsonError(\"Invalid SKU\", 400);\n\n const { sku, quantity } = item as { sku?: unknown; quantity?: unknown };\n if (typeof sku !== \"string\" || !products[sku]) return jsonError(\"Invalid SKU\", 400);\n if (!isValidQuantity(quantity)) return jsonError(\"Invalid quantity\", 400);\n\n rawItems.push({ sku, quantity });\n }\n\n const quantityMap = new Map<string, number>();\n for (const { sku, quantity } of rawItems) {\n quantityMap.set(sku, (quantityMap.get(sku) ?? 0) + quantity);\n }\n\n for (const [, total] of quantityMap) {\n if (total > MAX_QUANTITY) return jsonError(\"Invalid quantity\", 400);\n }\n\n const checkoutItems: CheckoutItem[] = Array.from(quantityMap.entries()).map(\n ([sku, quantity]) => ({ sku, quantity }),\n );\n const { offerSlug } = payload as { items?: unknown; offerSlug?: unknown };\n let priceOverrides: Record<string, number> = {};\n let freeShipping = false;\n let recipientInfo = false;\n\n if (typeof offerSlug === \"string\" && offerSlug.trim() !== \"\") {\n if (!checkOffer) return jsonError(\"Offer not available\", 503);\n const offer = await checkOffer(offerSlug.trim());\n if (!offer) return jsonError(\"Offer not found\", 404);\n if (isOfferUnavailable(offer)) return jsonError(offer.error, offer.status);\n recipientInfo = offer.recipientInfo;\n const offerUnits = offer.unitsRemaining;\n if (offerUnits && offerUnits.size > 0) {\n for (const { sku, quantity } of checkoutItems) {\n const remaining = offerUnits.get(sku);\n // TOCTOU あり — 低頻度の emu では許容\n if (remaining !== undefined && quantity > remaining) {\n return jsonError(`Offer unit limit reached: ${sku}`, 409);\n }\n }\n }\n priceOverrides = offer.priceOverrides;\n freeShipping = offer.freeShipping;\n }\n\n const shippingRate = shipping\n ? freeShipping\n ? { amount: 0, label: shipping.freeLabel }\n : calcShipping(checkoutItems, products, shipping)\n : undefined;\n const stock = checkStock ? await checkStock(checkoutItems.map((item) => item.sku)) : new Map<string, number>();\n // TOCTOU race is acceptable for low-frequency emu sales. Move to Durable Objects if needed.\n for (const { sku, quantity } of checkoutItems) {\n const available = stock.get(sku);\n if (available !== undefined && quantity > available) {\n return jsonError(`Out of stock: ${sku}`, 409);\n }\n }\n\n const customFields: Stripe.Checkout.SessionCreateParams.CustomField[] = [];\n if (recipientInfo) {\n customFields.push(\n {\n key: \"class_name\",\n label: { type: \"custom\", custom: \"クラス名\" },\n type: \"text\",\n optional: false,\n text: { maximum_length: 50 },\n },\n {\n key: \"child_name\",\n label: { type: \"custom\", custom: \"お子さんのお名前\" },\n type: \"text\",\n optional: false,\n text: { maximum_length: 50 },\n },\n );\n }\n customFields.push({\n key: \"message\",\n label: { type: \"custom\", custom: \"メッセージ・ご要望(任意)\" },\n type: \"text\",\n optional: true,\n text: { maximum_length: 255 },\n });\n\n try {\n const sessionParams: Stripe.Checkout.SessionCreateParams = {\n ui_mode: \"embedded_page\",\n mode: \"payment\",\n line_items: checkoutItems.map(({ sku, quantity }) => ({\n price_data: {\n currency: \"jpy\",\n product_data: { name: products[sku]!.name },\n unit_amount: priceOverrides[sku] ?? products[sku]!.price,\n },\n quantity,\n })),\n metadata: {\n items: JSON.stringify(checkoutItems),\n ...(typeof offerSlug === \"string\" && offerSlug.trim() ? { offer_slug: offerSlug.trim() } : {}),\n },\n phone_number_collection: { enabled: true },\n custom_fields: customFields,\n shipping_address_collection: { allowed_countries: [\"JP\"] },\n ...(shippingRate\n ? {\n shipping_options: [\n {\n shipping_rate_data: {\n type: \"fixed_amount\",\n fixed_amount: { amount: shippingRate.amount, currency: \"jpy\" },\n display_name: shippingRate.label,\n delivery_estimate: {\n minimum: { unit: \"business_day\", value: 2 },\n maximum: { unit: \"business_day\", value: 5 },\n },\n },\n },\n ],\n }\n : {}),\n redirect_on_completion: \"never\",\n };\n\n const session = await stripe.checkout.sessions.create(sessionParams);\n\n return new Response(JSON.stringify({ clientSecret: session.client_secret }), {\n headers: { \"Content-Type\": \"application/json\" },\n });\n } catch (error) {\n const stripeError = error as {\n type?: string;\n code?: string;\n statusCode?: number;\n requestId?: string;\n };\n console.error(\"[checkout] stripe session create failed:\", {\n type: stripeError.type,\n code: stripeError.code,\n statusCode: stripeError.statusCode,\n requestId: stripeError.requestId,\n });\n\n if (stripeError.type === \"StripePermissionError\") {\n return jsonError(\"Stripe key does not have permission to create Checkout Sessions\", 503);\n }\n\n return jsonError(\"Checkout session could not be created\", 503);\n }\n };\n}\n"],"mappings":";;;;;AAAA,OAAO,YAAY;AAInB,IAAM,qBAAqB;AAC3B,IAAM,YAAY;AAClB,IAAM,eAAe;AAiCrB,SAAS,UAAU,OAAe,QAAgB;AAChD,SAAO,IAAI,SAAS,KAAK,UAAU,EAAE,MAAM,CAAC,GAAG;AAAA,IAC7C;AAAA,IACA,SAAS,EAAE,gBAAgB,mBAAmB;AAAA,EAChD,CAAC;AACH;AAEA,SAAS,kBAAkB,OAAmE;AAC5F,SAAO,OAAO,UAAU,YAAY,UAAU;AAChD;AAEA,SAAS,gBAAgB,OAAiC;AACxD,SAAO,OAAO,UAAU,YAAY,OAAO,cAAc,KAAK,KAAK,SAAS;AAC9E;AAEA,SAAS,mBAAmB,OAAoF;AAC9G,SAAO,WAAW,SAAS,YAAY;AACzC;AAEA,SAAS,aACP,OACA,UACA,UACA;AACA,QAAM,aAAa,MAAM,OAAO,CAAC,KAAK,EAAE,KAAK,SAAS,MAAM;AAC1D,WAAO,OAAO,SAAS,GAAG,GAAG,iBAAiB,KAAK;AAAA,EACrD,GAAG,CAAC;AAEJ,QAAM,OAAO,SAAS,MAAM,KAAK,CAAC,iBAAiB;AACjD,WAAO,aAAa,aAAa,UAAa,cAAc,aAAa;AAAA,EAC3E,CAAC,KAAK,SAAS,MAAM,SAAS,MAAM,SAAS,CAAC;AAE9C,SAAO;AAAA,IACL,QAAQ,KAAK;AAAA,IACb,OAAO,K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AAkB;AAAA,YAChB;AAAA,cACE,oBAAoB;AAAA,gBAClB,MAAM;AAAA,gBACN,cAAc,EAAE,QAAQ,aAAa,QAAQ,UAAU,MAAM;AAAA,gBAC7D,cAAc,aAAa;AAAA,gBAC3B,mBAAmB;AAAA,kBACjB,SAAS,EAAE,MAAM,gBAAgB,OAAO,EAAE;AAAA,kBAC1C,SAAS,EAAE,MAAM,gBAAgB,OAAO,EAAE;AAAA,gBAC5C;AAAA,cACF;AAAA,YACF;AAAA,UACF;AAAA,QACF,IACA,CAAC;AAAA,QACL,wBAAwB;AAAA,MAC1B;AAEA,YAAM,UAAU,MAAM,OAAO,SAAS,SAAS,OAAO,aAAa;AAEnE,aAAO,IAAI,SAAS,KAAK,UAAU,EAAE,cAAc,QAAQ,cAAc,CAAC,GAAG;AAAA,QAC3E,SAAS,EAAE,gBAAgB,mBAAmB;AAAA,MAChD,CAAC;AAAA,IACH,SAAS,OAAO;AACd,YAAM,cAAc;AAMpB,cAAQ,MAAM,4CAA4C;AAAA,QACxD,MAAM,YAAY;AAAA,QAClB,MAAM,YAAY;AAAA,QAClB,YAAY,YAAY;AAAA,QACxB,WAAW,YAAY;AAAA,MACzB,CAAC;AAED,UAAI,YAAY,SAAS,yBAAyB;AAChD,eAAO,UAAU,mEAAmE,GAAG;AAAA,MACzF;AAEA,aAAO,UAAU,yCAAyC,GAAG;AAAA,IAC/D;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// src/access.ts
|
|
2
|
+
import {
|
|
3
|
+
createRemoteJWKSet,
|
|
4
|
+
jwtVerify
|
|
5
|
+
} from "jose";
|
|
6
|
+
function createAccessGuard(options) {
|
|
7
|
+
const { teamDomain, aud } = options;
|
|
8
|
+
if (teamDomain === "") {
|
|
9
|
+
throw new Error("teamDomain is required");
|
|
10
|
+
}
|
|
11
|
+
if (aud === "") {
|
|
12
|
+
throw new Error("aud is required");
|
|
13
|
+
}
|
|
14
|
+
const issuer = `https://${teamDomain}`;
|
|
15
|
+
const getKey = options.getKey ?? createRemoteJWKSet(new URL(`${issuer}/cdn-cgi/access/certs`));
|
|
16
|
+
return async function guard(request) {
|
|
17
|
+
const token = request.headers.get("cf-access-jwt-assertion");
|
|
18
|
+
if (token === null) {
|
|
19
|
+
return { ok: false, status: 403, error: "Missing Access token" };
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
const { payload } = await jwtVerify(token, getKey, {
|
|
23
|
+
issuer,
|
|
24
|
+
audience: aud,
|
|
25
|
+
algorithms: ["RS256"]
|
|
26
|
+
});
|
|
27
|
+
return { ok: true, payload };
|
|
28
|
+
} catch {
|
|
29
|
+
return { ok: false, status: 403, error: "Invalid Access token" };
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export {
|
|
35
|
+
createAccessGuard
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=chunk-2SNGXEIL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/access.ts"],"sourcesContent":["import {\n createRemoteJWKSet,\n jwtVerify,\n type JWTPayload,\n type JWTVerifyGetKey,\n} from \"jose\";\n\nexport interface AccessGuardOptions {\n teamDomain: string;\n aud: string;\n getKey?: JWTVerifyGetKey;\n}\n\nexport type AccessGuardResult =\n | { ok: true; payload: JWTPayload }\n | { ok: false; status: 403; error: string };\n\nexport function createAccessGuard(options: AccessGuardOptions) {\n const { teamDomain, aud } = options;\n\n if (teamDomain === \"\") {\n throw new Error(\"teamDomain is required\");\n }\n\n if (aud === \"\") {\n throw new Error(\"aud is required\");\n }\n\n const issuer = `https://${teamDomain}`;\n const getKey =\n options.getKey ??\n createRemoteJWKSet(new URL(`${issuer}/cdn-cgi/access/certs`));\n\n return async function guard(request: Request): Promise<AccessGuardResult> {\n const token = request.headers.get(\"cf-access-jwt-assertion\");\n\n if (token === null) {\n return { ok: false, status: 403, error: \"Missing Access token\" };\n }\n\n try {\n const { payload } = await jwtVerify(token, getKey, {\n issuer,\n audience: aud,\n algorithms: [\"RS256\"],\n });\n\n return { ok: true, payload };\n } catch {\n return { ok: false, status: 403, error: \"Invalid Access token\" };\n }\n };\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAYA,SAAS,kBAAkB,SAA6B;AAC7D,QAAM,EAAE,YAAY,IAAI,IAAI;AAE5B,MAAI,eAAe,IAAI;AACrB,UAAM,IAAI,MAAM,wBAAwB;AAAA,EAC1C;AAEA,MAAI,QAAQ,IAAI;AACd,UAAM,IAAI,MAAM,iBAAiB;AAAA,EACnC;AAEA,QAAM,SAAS,WAAW,UAAU;AACpC,QAAM,SACJ,QAAQ,UACR,mBAAmB,IAAI,IAAI,GAAG,MAAM,uBAAuB,CAAC;AAE9D,SAAO,eAAe,MAAM,SAA8C;AACxE,UAAM,QAAQ,QAAQ,QAAQ,IAAI,yBAAyB;AAE3D,QAAI,UAAU,MAAM;AAClB,aAAO,EAAE,IAAI,OAAO,QAAQ,KAAK,OAAO,uBAAuB;AAAA,IACjE;AAEA,QAAI;AACF,YAAM,EAAE,QAAQ,IAAI,MAAM,UAAU,OAAO,QAAQ;AAAA,QACjD;AAAA,QACA,UAAU;AAAA,QACV,YAAY,CAAC,OAAO;AAAA,MACtB,CAAC;AAED,aAAO,EAAE,IAAI,MAAM,QAAQ;AAAA,IAC7B,QAAQ;AACN,aAAO,EAAE,IAAI,OAAO,QAAQ,KAAK,OAAO,uBAAuB;AAAA,IACjE;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/env.ts"],"sourcesContent":["import { env } from \"cloudflare:workers\";\n\nexport type ServerEnv = {\n PUBLIC_STRIPE_PUBLISHABLE_KEY?: string;\n STRIPE_SECRET_KEY: string;\n STRIPE_WEBHOOK_SECRET: string;\n RESEND_API_KEY: string;\n RESEND_AUDIENCE_ID: string;\n DISCORD_WEBHOOK_URL?: string;\n ALERT_DAYS_THRESHOLD?: string;\n ACCESS_TEAM_DOMAIN?: string;\n ACCESS_AUD?: string;\n DB?: D1Database;\n};\n\nexport function getServerEnv(): ServerEnv {\n return env as ServerEnv;\n}\n"],"mappings":";AAAA,SAAS,WAAW;AAeb,SAAS,eAA0B;AACxC,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// src/config.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
var skuKeySchema = z.string().min(1, "Product SKU must not be empty");
|
|
4
|
+
var productSchema = z.strictObject({
|
|
5
|
+
name: z.string().min(1, "Product name is required"),
|
|
6
|
+
price: z.int("Product price must be an integer (JPY)").positive("Product price must be a positive integer (JPY)"),
|
|
7
|
+
description: z.string().optional(),
|
|
8
|
+
active: z.boolean().default(true),
|
|
9
|
+
shippingUnits: z.int("Product shippingUnits must be a positive integer").positive("Product shippingUnits must be a positive integer").default(1),
|
|
10
|
+
images: z.array(z.string()).optional()
|
|
11
|
+
});
|
|
12
|
+
var brandSchema = z.strictObject({
|
|
13
|
+
name: z.string().min(1, "Brand name is required"),
|
|
14
|
+
url: z.url("Brand url must be a valid URL"),
|
|
15
|
+
description: z.string().optional()
|
|
16
|
+
});
|
|
17
|
+
var shippingTierSchema = z.strictObject({
|
|
18
|
+
maxUnits: z.int("Shipping tier maxUnits must be an integer").positive("Shipping tier maxUnits must be a positive integer").optional(),
|
|
19
|
+
amount: z.int("Shipping tier amount must be an integer (JPY)").nonnegative("Shipping tier amount must be a non-negative integer (JPY)"),
|
|
20
|
+
label: z.string().min(1, "Shipping tier label must not be empty")
|
|
21
|
+
});
|
|
22
|
+
var shippingSchema = z.strictObject({
|
|
23
|
+
tiers: z.array(shippingTierSchema).min(1, "Shipping tiers must include at least one tier"),
|
|
24
|
+
freeLabel: z.string().min(1, "Shipping freeLabel must not be empty")
|
|
25
|
+
}).superRefine((shipping, ctx) => {
|
|
26
|
+
let previousMaxUnits;
|
|
27
|
+
shipping.tiers.forEach((tier, index) => {
|
|
28
|
+
const isLast = index === shipping.tiers.length - 1;
|
|
29
|
+
if (isLast) {
|
|
30
|
+
if (tier.maxUnits !== void 0) {
|
|
31
|
+
ctx.addIssue({
|
|
32
|
+
code: "custom",
|
|
33
|
+
path: ["tiers", index, "maxUnits"],
|
|
34
|
+
message: "The final shipping tier must omit maxUnits so it can act as the catch-all tier"
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (tier.maxUnits === void 0) {
|
|
40
|
+
ctx.addIssue({
|
|
41
|
+
code: "custom",
|
|
42
|
+
path: ["tiers", index, "maxUnits"],
|
|
43
|
+
message: "Every shipping tier before the final catch-all tier must define maxUnits"
|
|
44
|
+
});
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (previousMaxUnits !== void 0 && tier.maxUnits <= previousMaxUnits) {
|
|
48
|
+
ctx.addIssue({
|
|
49
|
+
code: "custom",
|
|
50
|
+
path: ["tiers", index, "maxUnits"],
|
|
51
|
+
message: `Shipping tier maxUnits must be strictly increasing; tier ${index} has ${tier.maxUnits} after ${previousMaxUnits}`
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
previousMaxUnits = tier.maxUnits;
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
var emailSchema = z.strictObject({
|
|
58
|
+
from: z.email("Email from must be a valid email address"),
|
|
59
|
+
fromName: z.string().min(1, "Email fromName must not be empty").optional(),
|
|
60
|
+
bcc: z.email("Email bcc must be a valid email address").optional(),
|
|
61
|
+
replyTo: z.email("Email replyTo must be a valid email address").optional()
|
|
62
|
+
});
|
|
63
|
+
var umecConfigSchema = z.strictObject({
|
|
64
|
+
schemaVersion: z.literal(1),
|
|
65
|
+
brand: brandSchema,
|
|
66
|
+
products: z.record(skuKeySchema, productSchema),
|
|
67
|
+
shipping: shippingSchema.optional(),
|
|
68
|
+
email: emailSchema
|
|
69
|
+
});
|
|
70
|
+
function defineUmecConfig(config) {
|
|
71
|
+
return umecConfigSchema.parse(config);
|
|
72
|
+
}
|
|
73
|
+
function formatEmailFrom(email) {
|
|
74
|
+
return email.fromName ? `${email.fromName} <${email.from}>` : email.from;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export {
|
|
78
|
+
umecConfigSchema,
|
|
79
|
+
defineUmecConfig,
|
|
80
|
+
formatEmailFrom
|
|
81
|
+
};
|
|
82
|
+
//# sourceMappingURL=chunk-7ZJOZAEO.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/config.ts"],"sourcesContent":["import { z } from \"zod\";\n\nconst skuKeySchema = z\n .string()\n .min(1, \"Product SKU must not be empty\");\n\nconst productSchema = z.strictObject({\n name: z.string().min(1, \"Product name is required\"),\n price: z\n .int(\"Product price must be an integer (JPY)\")\n .positive(\"Product price must be a positive integer (JPY)\"),\n description: z.string().optional(),\n active: z.boolean().default(true),\n shippingUnits: z\n .int(\"Product shippingUnits must be a positive integer\")\n .positive(\"Product shippingUnits must be a positive integer\")\n .default(1),\n images: z.array(z.string()).optional(),\n});\n\nconst brandSchema = z.strictObject({\n name: z.string().min(1, \"Brand name is required\"),\n url: z.url(\"Brand url must be a valid URL\"),\n description: z.string().optional(),\n});\n\nconst shippingTierSchema = z.strictObject({\n maxUnits: z\n .int(\"Shipping tier maxUnits must be an integer\")\n .positive(\"Shipping tier maxUnits must be a positive integer\")\n .optional(),\n amount: z\n .int(\"Shipping tier amount must be an integer (JPY)\")\n .nonnegative(\"Shipping tier amount must be a non-negative integer (JPY)\"),\n label: z.string().min(1, \"Shipping tier label must not be empty\"),\n});\n\nconst shippingSchema = z\n .strictObject({\n tiers: z.array(shippingTierSchema).min(1, \"Shipping tiers must include at least one tier\"),\n freeLabel: z.string().min(1, \"Shipping freeLabel must not be empty\"),\n })\n .superRefine((shipping, ctx) => {\n let previousMaxUnits: number | undefined;\n\n shipping.tiers.forEach((tier, index) => {\n const isLast = index === shipping.tiers.length - 1;\n\n if (isLast) {\n if (tier.maxUnits !== undefined) {\n ctx.addIssue({\n code: \"custom\",\n path: [\"tiers\", index, \"maxUnits\"],\n message: \"The final shipping tier must omit maxUnits so it can act as the catch-all tier\",\n });\n }\n return;\n }\n\n if (tier.maxUnits === undefined) {\n ctx.addIssue({\n code: \"custom\",\n path: [\"tiers\", index, \"maxUnits\"],\n message: \"Every shipping tier before the final catch-all tier must define maxUnits\",\n });\n return;\n }\n\n if (previousMaxUnits !== undefined && tier.maxUnits <= previousMaxUnits) {\n ctx.addIssue({\n code: \"custom\",\n path: [\"tiers\", index, \"maxUnits\"],\n message: `Shipping tier maxUnits must be strictly increasing; tier ${index} has ${tier.maxUnits} after ${previousMaxUnits}`,\n });\n }\n\n previousMaxUnits = tier.maxUnits;\n });\n });\n\nconst emailSchema = z.strictObject({\n from: z.email(\"Email from must be a valid email address\"),\n fromName: z.string().min(1, \"Email fromName must not be empty\").optional(),\n bcc: z.email(\"Email bcc must be a valid email address\").optional(),\n replyTo: z.email(\"Email replyTo must be a valid email address\").optional(),\n});\n\nexport const umecConfigSchema = z.strictObject({\n schemaVersion: z.literal(1),\n brand: brandSchema,\n products: z.record(skuKeySchema, productSchema),\n shipping: shippingSchema.optional(),\n email: emailSchema,\n});\n\nexport type UmecConfig = z.infer<typeof umecConfigSchema>;\nexport type UmecConfigInput = z.input<typeof umecConfigSchema>;\nexport type UmecProduct = z.infer<typeof productSchema>;\nexport type UmecShipping = z.infer<typeof shippingSchema>;\n\n/**\n * Validates and returns a typed umec.config.ts object.\n * Applies defaults (e.g. product.active = true).\n */\nexport function defineUmecConfig(config: unknown): UmecConfig {\n return umecConfigSchema.parse(config);\n}\n\n/**\n * Formats an email config's from address with an optional display name,\n * e.g. { from: \"order@example.com\", fromName: \"emu\" } -> \"emu <order@example.com>\".\n */\nexport function formatEmailFrom(email: { from: string; fromName?: string }): string {\n return email.fromName ? `${email.fromName} <${email.from}>` : email.from;\n}\n"],"mappings":";AAAA,SAAS,SAAS;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{ Resend } from "resend";
|
|
3
|
+
var DAY_MS = 24 * 60 * 60 * 1e3;
|
|
4
|
+
function formatYen(value) {
|
|
5
|
+
if (value == null) return "-";
|
|
6
|
+
return new Intl.NumberFormat("ja-JP", {
|
|
7
|
+
style: "currency",
|
|
8
|
+
currency: "JPY",
|
|
9
|
+
maximumFractionDigits: 0
|
|
10
|
+
}).format(value);
|
|
11
|
+
}
|
|
12
|
+
function parseTimestamp(value) {
|
|
13
|
+
if (value == null || value === "") return null;
|
|
14
|
+
const timestamp = typeof value === "string" ? Number(value) : value;
|
|
15
|
+
return Number.isFinite(timestamp) ? timestamp : null;
|
|
16
|
+
}
|
|
17
|
+
function parseItems(itemsJson, products) {
|
|
18
|
+
if (!itemsJson) return "-";
|
|
19
|
+
try {
|
|
20
|
+
const parsed = JSON.parse(itemsJson);
|
|
21
|
+
if (!Array.isArray(parsed) || parsed.length === 0) return "-";
|
|
22
|
+
return parsed.map((item) => {
|
|
23
|
+
if (typeof item !== "object" || item === null) return null;
|
|
24
|
+
const { sku, quantity } = item;
|
|
25
|
+
const productSku = typeof sku === "string" ? sku : "";
|
|
26
|
+
const productName = productSku && products[productSku] ? products[productSku].name : productSku || "\u5546\u54C1";
|
|
27
|
+
const itemQuantity = typeof quantity === "number" && Number.isFinite(quantity) ? quantity : 0;
|
|
28
|
+
return `${productName} x ${itemQuantity}`;
|
|
29
|
+
}).filter((item) => Boolean(item)).join(", ");
|
|
30
|
+
} catch {
|
|
31
|
+
return "-";
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function escapeHtml(value) {
|
|
35
|
+
return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
36
|
+
}
|
|
37
|
+
function notificationErrorSuffix(error) {
|
|
38
|
+
if (typeof error !== "object" || error === null) return "";
|
|
39
|
+
const value = error;
|
|
40
|
+
const details = [
|
|
41
|
+
typeof value.name === "string" ? `name=${value.name}` : null,
|
|
42
|
+
typeof value.statusCode === "number" ? `statusCode=${value.statusCode}` : null
|
|
43
|
+
].filter((detail) => detail !== null);
|
|
44
|
+
return details.length > 0 ? ` (${details.join(", ")})` : "";
|
|
45
|
+
}
|
|
46
|
+
function formatOrderLine(order, products, now = Date.now()) {
|
|
47
|
+
const createdAt = parseTimestamp(order.created_at);
|
|
48
|
+
const elapsedDays = createdAt == null ? "-" : String(Math.floor((now - createdAt) / DAY_MS));
|
|
49
|
+
const name = order.name?.trim() || "\u304A\u5BA2\u69D8";
|
|
50
|
+
return `${name} | ${parseItems(order.items_json, products)} | ${formatYen(order.amount)} | ${elapsedDays}\u65E5`;
|
|
51
|
+
}
|
|
52
|
+
async function notifyUnshipped(orders, env, { alertFrom, alertTo, products = {} }) {
|
|
53
|
+
if (orders.length === 0) return;
|
|
54
|
+
if (!env.DISCORD_WEBHOOK_URL) throw new Error("DISCORD_WEBHOOK_URL is not configured");
|
|
55
|
+
if (!env.RESEND_API_KEY) throw new Error("RESEND_API_KEY is not configured");
|
|
56
|
+
const lines = orders.map((order) => formatOrderLine(order, products));
|
|
57
|
+
const content = ["\u672A\u767A\u9001\u30A2\u30E9\u30FC\u30C8: pending \u306E\u6CE8\u6587\u304C\u3042\u308A\u307E\u3059\u3002", "", ...lines].join("\n");
|
|
58
|
+
const discordResponse = await fetch(env.DISCORD_WEBHOOK_URL, {
|
|
59
|
+
method: "POST",
|
|
60
|
+
headers: { "Content-Type": "application/json" },
|
|
61
|
+
body: JSON.stringify({ content, allowed_mentions: { parse: [] } })
|
|
62
|
+
});
|
|
63
|
+
if (!discordResponse.ok) {
|
|
64
|
+
throw new Error(`Discord notification failed: ${discordResponse.status}`);
|
|
65
|
+
}
|
|
66
|
+
const rows = lines.map((line) => {
|
|
67
|
+
const [name, items, amount, elapsedDays] = line.split(" | ");
|
|
68
|
+
return `<tr>
|
|
69
|
+
<td style="padding:8px;border-bottom:1px solid #eee;">${escapeHtml(name ?? "")}</td>
|
|
70
|
+
<td style="padding:8px;border-bottom:1px solid #eee;">${escapeHtml(items ?? "")}</td>
|
|
71
|
+
<td style="padding:8px;border-bottom:1px solid #eee;text-align:right;">${escapeHtml(amount ?? "")}</td>
|
|
72
|
+
<td style="padding:8px;border-bottom:1px solid #eee;text-align:right;">${escapeHtml(elapsedDays ?? "")}</td>
|
|
73
|
+
</tr>`;
|
|
74
|
+
}).join("");
|
|
75
|
+
const resend = new Resend(env.RESEND_API_KEY);
|
|
76
|
+
const { error } = await resend.emails.send({
|
|
77
|
+
from: alertFrom,
|
|
78
|
+
to: alertTo,
|
|
79
|
+
subject: "\u3010emu\u3011\u672A\u767A\u9001\u30A2\u30E9\u30FC\u30C8",
|
|
80
|
+
html: `<!DOCTYPE html>
|
|
81
|
+
<html lang="ja">
|
|
82
|
+
<head><meta charset="UTF-8"></head>
|
|
83
|
+
<body style="font-family:sans-serif;color:#222;max-width:720px;margin:0 auto;padding:32px 16px;">
|
|
84
|
+
<h1 style="font-size:20px;margin:0 0 16px;">\u672A\u767A\u9001\u30A2\u30E9\u30FC\u30C8</h1>
|
|
85
|
+
<p style="font-size:14px;line-height:1.7;color:#555;">pending \u306E\u307E\u307E threshold \u3092\u8D85\u3048\u305F\u6CE8\u6587\u304C\u3042\u308A\u307E\u3059\u3002</p>
|
|
86
|
+
<table style="width:100%;border-collapse:collapse;font-size:14px;">
|
|
87
|
+
<thead>
|
|
88
|
+
<tr>
|
|
89
|
+
<th style="padding:8px;border-bottom:2px solid #222;text-align:left;">\u540D\u524D</th>
|
|
90
|
+
<th style="padding:8px;border-bottom:2px solid #222;text-align:left;">\u5546\u54C1</th>
|
|
91
|
+
<th style="padding:8px;border-bottom:2px solid #222;text-align:right;">\u91D1\u984D</th>
|
|
92
|
+
<th style="padding:8px;border-bottom:2px solid #222;text-align:right;">\u7D4C\u904E\u65E5\u6570</th>
|
|
93
|
+
</tr>
|
|
94
|
+
</thead>
|
|
95
|
+
<tbody>${rows}</tbody>
|
|
96
|
+
</table>
|
|
97
|
+
</body>
|
|
98
|
+
</html>`,
|
|
99
|
+
text: content
|
|
100
|
+
});
|
|
101
|
+
if (error) {
|
|
102
|
+
throw new Error(`Resend notification failed${notificationErrorSuffix(error)}`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export {
|
|
107
|
+
notifyUnshipped
|
|
108
|
+
};
|
|
109
|
+
//# sourceMappingURL=chunk-QRFFBMFN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/notify.ts"],"sourcesContent":["import { Resend } from \"resend\";\n\nconst DAY_MS = 24 * 60 * 60 * 1000;\n\nexport type UnshippedOrder = {\n id: string;\n name: string | null;\n items_json: string | null;\n amount: number | null;\n created_at: number | string | null;\n};\n\nexport type NotifyEnv = {\n DISCORD_WEBHOOK_URL?: string;\n RESEND_API_KEY?: string;\n};\n\ntype CheckoutItem = {\n sku?: unknown;\n quantity?: unknown;\n};\n\nexport type NotifyProduct = {\n name: string;\n};\n\nexport type NotifyProductsMap = Record<string, NotifyProduct | undefined>;\n\nexport type NotifyUnshippedOptions = {\n alertFrom: string;\n alertTo: string;\n products?: NotifyProductsMap;\n};\n\nfunction formatYen(value: number | null) {\n if (value == null) return \"-\";\n return new Intl.NumberFormat(\"ja-JP\", {\n style: \"currency\",\n currency: \"JPY\",\n maximumFractionDigits: 0,\n }).format(value);\n}\n\nfunction parseTimestamp(value: number | string | null) {\n if (value == null || value === \"\") return null;\n const timestamp = typeof value === \"string\" ? Number(value) : value;\n return Number.isFinite(timestamp) ? timestamp : null;\n}\n\nfunction parseItems(itemsJson: string | null, products: NotifyProductsMap) {\n if (!itemsJson) return \"-\";\n\n try {\n const parsed: unknown = JSON.parse(itemsJson);\n if (!Array.isArray(parsed) || parsed.length === 0) return \"-\";\n\n return parsed\n .map((item) => {\n if (typeof item !== \"object\" || item === null) return null;\n const { sku, quantity } = item as CheckoutItem;\n const productSku = typeof sku === \"string\" ? sku : \"\";\n const productName = productSku && products[productSku] ? products[productSku].name : productSku || \"商品\";\n const itemQuantity = typeof quantity === \"number\" && Number.isFinite(quantity) ? quantity : 0;\n return `${productName} x ${itemQuantity}`;\n })\n .filter((item): item is string => Boolean(item))\n .join(\", \");\n } catch {\n return \"-\";\n }\n}\n\nfunction escapeHtml(value: string) {\n return value\n .replaceAll(\"&\", \"&\")\n .replaceAll(\"<\", \"<\")\n .replaceAll(\">\", \">\")\n .replaceAll('\"', \""\")\n .replaceAll(\"'\", \"'\");\n}\n\nfunction notificationErrorSuffix(error: unknown) {\n if (typeof error !== \"object\" || error === null) return \"\";\n const value = error as { name?: unknown; statusCode?: unknown };\n const details = [\n typeof value.name === \"string\" ? `name=${value.name}` : null,\n typeof value.statusCode === \"number\" ? `statusCode=${value.statusCode}` : null,\n ].filter((detail): detail is string => detail !== null);\n\n return details.length > 0 ? ` (${details.join(\", \")})` : \"\";\n}\n\nfunction formatOrderLine(order: UnshippedOrder, products: NotifyProductsMap, now = Date.now()) {\n const createdAt = parseTimestamp(order.created_at);\n const elapsedDays = createdAt == null ? \"-\" : String(Math.floor((now - createdAt) / DAY_MS));\n const name = order.name?.trim() || \"お客様\";\n return `${name} | ${parseItems(order.items_json, products)} | ${formatYen(order.amount)} | ${elapsedDays}日`;\n}\n\nexport async function notifyUnshipped(\n orders: UnshippedOrder[],\n env: NotifyEnv,\n { alertFrom, alertTo, products = {} }: NotifyUnshippedOptions,\n) {\n if (orders.length === 0) return;\n if (!env.DISCORD_WEBHOOK_URL) throw new Error(\"DISCORD_WEBHOOK_URL is not configured\");\n if (!env.RESEND_API_KEY) throw new Error(\"RESEND_API_KEY is not configured\");\n\n const lines = orders.map((order) => formatOrderLine(order, products));\n const content = [\"未発送アラート: pending の注文があります。\", \"\", ...lines].join(\"\\n\");\n\n const discordResponse = await fetch(env.DISCORD_WEBHOOK_URL, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ content, allowed_mentions: { parse: [] } }),\n });\n if (!discordResponse.ok) {\n throw new Error(`Discord notification failed: ${discordResponse.status}`);\n }\n\n const rows = lines\n .map((line) => {\n const [name, items, amount, elapsedDays] = line.split(\" | \");\n return `<tr>\n <td style=\"padding:8px;border-bottom:1px solid #eee;\">${escapeHtml(name ?? \"\")}</td>\n <td style=\"padding:8px;border-bottom:1px solid #eee;\">${escapeHtml(items ?? \"\")}</td>\n <td style=\"padding:8px;border-bottom:1px solid #eee;text-align:right;\">${escapeHtml(amount ?? \"\")}</td>\n <td style=\"padding:8px;border-bottom:1px solid #eee;text-align:right;\">${escapeHtml(elapsedDays ?? \"\")}</td>\n </tr>`;\n })\n .join(\"\");\n\n const resend = new Resend(env.RESEND_API_KEY);\n const { error } = await resend.emails.send({\n from: alertFrom,\n to: alertTo,\n subject: \"【emu】未発送アラート\",\n html: `<!DOCTYPE html>\n<html lang=\"ja\">\n<head><meta charset=\"UTF-8\"></head>\n<body style=\"font-family:sans-serif;color:#222;max-width:720px;margin:0 auto;padding:32px 16px;\">\n <h1 style=\"font-size:20px;margin:0 0 16px;\">未発送アラート</h1>\n <p style=\"font-size:14px;line-height:1.7;color:#555;\">pending のまま threshold を超えた注文があります。</p>\n <table style=\"width:100%;border-collapse:collapse;font-size:14px;\">\n <thead>\n <tr>\n <th style=\"padding:8px;border-bottom:2px solid #222;text-align:left;\">名前</th>\n <th style=\"padding:8px;border-bottom:2px solid #222;text-align:left;\">商品</th>\n <th style=\"padding:8px;border-bottom:2px solid #222;text-align:right;\">金額</th>\n <th style=\"padding:8px;border-bottom:2px solid #222;text-align:right;\">経過日数</th>\n </tr>\n </thead>\n <tbody>${rows}</tbody>\n </table>\n</body>\n</html>`,\n text: content,\n });\n if (error) {\n throw new Error(`Resend notification failed${notificationErrorSuffix(error)}`);\n }\n}\n"],"mappings":";AAAA,SAAS,cAAc;AAEvB,IAAM,SAAS,KAAK,KAAK,KAAK;AAgC9B,SAAS,UAAU,OAAsB;AACvC,MAAI,SAAS,KAAM,QAAO;AAC1B,SAAO,IAAI,KAAK,aAAa,SAA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