@aglyn/plugins-commerce 1.31.0 → 1.33.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 +4 -0
- package/package.json +13 -13
- package/src/lib/components/cart.js +35 -15
- package/src/lib/components/cart.js.map +1 -1
- package/src/lib/components/commerce-console-page.js +6 -0
- package/src/lib/components/commerce-console-page.js.map +1 -1
- package/src/lib/components/console/currencies-card.component.d.ts +21 -0
- package/src/lib/components/console/currencies-card.component.js +408 -0
- package/src/lib/components/console/currencies-card.component.js.map +1 -0
- package/src/lib/components/console/product-add-ons-fields.component.d.ts +13 -0
- package/src/lib/components/console/product-add-ons-fields.component.js +74 -2
- package/src/lib/components/console/product-add-ons-fields.component.js.map +1 -1
- package/src/lib/components/console/product-editor-dialog.component.js +42 -1
- package/src/lib/components/console/product-editor-dialog.component.js.map +1 -1
- package/src/lib/components/console/product-fixed-prices-fields.component.d.ts +25 -0
- package/src/lib/components/console/product-fixed-prices-fields.component.js +112 -0
- package/src/lib/components/console/product-fixed-prices-fields.component.js.map +1 -0
- package/src/lib/components/console/reservations-card.component.js +32 -15
- package/src/lib/components/console/reservations-card.component.js.map +1 -1
- package/src/lib/components/console/shipping-settings-card.component.js +337 -10
- package/src/lib/components/console/shipping-settings-card.component.js.map +1 -1
- package/src/lib/components/console/store-settings-card.component.js +1 -1
- package/src/lib/components/console/store-settings-card.component.js.map +1 -1
- package/src/lib/components/console/use-currency-setup.d.ts +20 -0
- package/src/lib/components/console/use-currency-setup.js +61 -0
- package/src/lib/components/console/use-currency-setup.js.map +1 -0
- package/src/lib/components/currency-selector.d.ts +36 -0
- package/src/lib/components/currency-selector.js +157 -0
- package/src/lib/components/currency-selector.js.map +1 -0
- package/src/lib/components/product-add-ons.d.ts +9 -1
- package/src/lib/components/product-add-ons.js +8 -4
- package/src/lib/components/product-add-ons.js.map +1 -1
- package/src/lib/components/product-choice-cards.d.ts +13 -1
- package/src/lib/components/product-choice-cards.js +5 -4
- package/src/lib/components/product-choice-cards.js.map +1 -1
- package/src/lib/components/product-detail.d.ts +8 -0
- package/src/lib/components/product-detail.js +38 -11
- package/src/lib/components/product-detail.js.map +1 -1
- package/src/lib/components/product-grid.d.ts +2 -0
- package/src/lib/components/product-grid.js +22 -9
- package/src/lib/components/product-grid.js.map +1 -1
- package/src/lib/components/related-products.js +6 -2
- package/src/lib/components/related-products.js.map +1 -1
- package/src/lib/components/shopper-currency.d.ts +108 -0
- package/src/lib/components/shopper-currency.js +262 -0
- package/src/lib/components/shopper-currency.js.map +1 -0
- package/src/lib/components/wishlist.js +7 -1
- package/src/lib/components/wishlist.js.map +1 -1
- package/src/lib/declarations.server.js +39 -0
- package/src/lib/declarations.server.js.map +1 -1
- package/src/lib/model/commerce-currency-setup.d.ts +79 -0
- package/src/lib/model/commerce-currency-setup.js +124 -0
- package/src/lib/model/commerce-currency-setup.js.map +1 -0
- package/src/lib/model/commerce-currency.d.ts +215 -0
- package/src/lib/model/commerce-currency.js +511 -0
- package/src/lib/model/commerce-currency.js.map +1 -0
- package/src/lib/model/commerce-orders.d.ts +17 -0
- package/src/lib/model/commerce-orders.js +10 -5
- package/src/lib/model/commerce-orders.js.map +1 -1
- package/src/lib/model/commerce-record-routes.js +26 -1
- package/src/lib/model/commerce-record-routes.js.map +1 -1
- package/src/lib/model/commerce-reservations.d.ts +6 -0
- package/src/lib/model/commerce-reservations.js.map +1 -1
- package/src/lib/model/commerce-shipping.d.ts +66 -11
- package/src/lib/model/commerce-shipping.js +91 -7
- package/src/lib/model/commerce-shipping.js.map +1 -1
- package/src/lib/model/commerce.d.ts +6 -0
- package/src/lib/model/commerce.js.map +1 -1
- package/src/lib/model/index.d.ts +2 -0
- package/src/lib/model/index.js +2 -0
- package/src/lib/model/index.js.map +1 -1
- package/src/lib/model/order-figures.js +9 -2
- package/src/lib/model/order-figures.js.map +1 -1
- package/src/lib/model/product-modifiers.d.ts +5 -0
- package/src/lib/model/product-modifiers.js.map +1 -1
- package/src/lib/model/store-setup-content.js +23 -2
- package/src/lib/model/store-setup-content.js.map +1 -1
- package/src/lib/server/billing-webhook.js +37 -24
- package/src/lib/server/billing-webhook.js.map +1 -1
- package/src/lib/server/carrier-shipping.d.ts +2 -0
- package/src/lib/server/carrier-shipping.js +8 -4
- package/src/lib/server/carrier-shipping.js.map +1 -1
- package/src/lib/server/cart-checkout.js +74 -13
- package/src/lib/server/cart-checkout.js.map +1 -1
- package/src/lib/server/cart.d.ts +12 -0
- package/src/lib/server/cart.js +50 -4
- package/src/lib/server/cart.js.map +1 -1
- package/src/lib/server/catalog.d.ts +5 -0
- package/src/lib/server/catalog.js +7 -0
- package/src/lib/server/catalog.js.map +1 -1
- package/src/lib/server/checkout.js +53 -12
- package/src/lib/server/checkout.js.map +1 -1
- package/src/lib/server/currency.d.ts +93 -0
- package/src/lib/server/currency.js +182 -0
- package/src/lib/server/currency.js.map +1 -0
- package/src/lib/server/order-notifications.js +4 -2
- package/src/lib/server/order-notifications.js.map +1 -1
- package/src/lib/server/product.d.ts +9 -0
- package/src/lib/server/product.js +12 -0
- package/src/lib/server/product.js.map +1 -1
- package/src/lib/server/refund.js +3 -3
- package/src/lib/server/refund.js.map +1 -1
- package/src/lib/server/site-chat-tools.d.ts +22 -0
- package/src/lib/server/site-chat-tools.js +369 -0
- package/src/lib/server/site-chat-tools.js.map +1 -0
- package/src/lib/server/site-chat-visitor.d.ts +24 -0
- package/src/lib/server/site-chat-visitor.js +39 -0
- package/src/lib/server/site-chat-visitor.js.map +1 -0
- package/src/lib/server/site-offers.d.ts +31 -0
- package/src/lib/server/site-offers.js +91 -0
- package/src/lib/server/site-offers.js.map +1 -0
- package/src/lib/server/stays-site-search.d.ts +20 -0
- package/src/lib/server/stays-site-search.js +78 -0
- package/src/lib/server/stays-site-search.js.map +1 -0
- package/src/lib/server.js +20 -0
- package/src/lib/server.js.map +1 -1
- package/src/lib/site-chat-tool-definitions.d.ts +26 -0
- package/src/lib/site-chat-tool-definitions.js +141 -0
- package/src/lib/site-chat-tool-definitions.js.map +1 -0
- package/src/lib/site.js +8 -0
- package/src/lib/site.js.map +1 -1
- package/src/lib/subprocessors.js +7 -0
- package/src/lib/subprocessors.js.map +1 -1
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/ import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
17
|
+
import { resolveMediaSrc } from "@aglyn/aglyn/app-utils/media-ref";
|
|
18
|
+
import { buildSectionIndex, rankSections } from "@aglyn/aglyn/app-utils/section-retrieval";
|
|
19
|
+
import { firebaseAdmin } from "@aglyn/tenant-data-admin/server/firebase-admin";
|
|
20
|
+
import { CART_UPDATED_EVENT } from "../constants/cart-events.js";
|
|
21
|
+
import * as CommerceModel from "../model/index.js";
|
|
22
|
+
import { reservationAvailabilityHandler } from "./reservation-availability.js";
|
|
23
|
+
/**
|
|
24
|
+
* The store's site chat tools (AGL-4250). Each reads the one site it is
|
|
25
|
+
* handed and nothing else; a proposal checks what it proposes against the
|
|
26
|
+
* same rules the door it names will apply, so a card the visitor presses
|
|
27
|
+
* goes through. The prices and dates it states are the store's own.
|
|
28
|
+
*/ const PRODUCT_SCAN = 300;
|
|
29
|
+
const RESOURCE_SCAN = 100;
|
|
30
|
+
const str = (value)=>typeof value === 'string' ? value.trim() : '';
|
|
31
|
+
const money = (usd)=>`$${Number.isInteger(usd) ? usd : usd.toFixed(2)}`;
|
|
32
|
+
const DAY = /^\d{4}-\d{2}-\d{2}$/;
|
|
33
|
+
const dayMs = (day)=>DAY.test(day) ? Date.parse(`${day}T00:00:00Z`) : 0;
|
|
34
|
+
const dayLabel = (ms)=>new Date(ms).toLocaleDateString('en-US', {
|
|
35
|
+
weekday: 'short',
|
|
36
|
+
month: 'short',
|
|
37
|
+
day: 'numeric',
|
|
38
|
+
timeZone: 'UTC'
|
|
39
|
+
});
|
|
40
|
+
const hostRef = (hostId)=>firebaseAdmin.app().firestore().collection('hosts').doc(hostId);
|
|
41
|
+
/** The site's online product best named by `name`, or `null`. */ async function findProduct(hostId, name) {
|
|
42
|
+
var _rankSections_;
|
|
43
|
+
if (!name) return null;
|
|
44
|
+
const snapshot = await hostRef(hostId).collection('products').where('deletedAt', '==', null).where('status', '==', 'active').limit(PRODUCT_SCAN).get();
|
|
45
|
+
const listed = snapshot.docs.map((doc)=>({
|
|
46
|
+
id: doc.id,
|
|
47
|
+
data: doc.data()
|
|
48
|
+
})).filter(({ data })=>CommerceModel.productListedOnline(data) && CommerceModel.productSellsOnline(data) && !CommerceModel.productIsSample(data));
|
|
49
|
+
const exact = listed.find(({ data })=>str(data['name']).toLowerCase() === name.toLowerCase());
|
|
50
|
+
const best = exact != null ? exact : (_rankSections_ = rankSections(buildSectionIndex(listed.map((entry)=>{
|
|
51
|
+
var _entry_data_tags;
|
|
52
|
+
return {
|
|
53
|
+
title: str(entry.data['name']),
|
|
54
|
+
heading: '',
|
|
55
|
+
text: [
|
|
56
|
+
str(entry.data['slug']).replace(/-/g, ' '),
|
|
57
|
+
...(_entry_data_tags = entry.data['tags']) != null ? _entry_data_tags : []
|
|
58
|
+
].join(' '),
|
|
59
|
+
entry
|
|
60
|
+
};
|
|
61
|
+
})), name, {
|
|
62
|
+
limit: 1
|
|
63
|
+
})[0]) == null ? void 0 : _rankSections_.section.entry;
|
|
64
|
+
if (!best) return null;
|
|
65
|
+
return _extends({}, best, {
|
|
66
|
+
product: CommerceModel.liftLegacyProduct(best.data)
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
const optionName = (variant)=>{
|
|
70
|
+
var _variant_options;
|
|
71
|
+
return Object.values((_variant_options = variant.options) != null ? _variant_options : {}).filter(Boolean).join(' / ') || 'Standard';
|
|
72
|
+
};
|
|
73
|
+
function productCardOf(hostId, found, variant) {
|
|
74
|
+
var _ref, _ref1;
|
|
75
|
+
var _found_data_mediaUrls;
|
|
76
|
+
const [min, max] = CommerceModel.productPriceRange(found.product);
|
|
77
|
+
const image = resolveMediaSrc((_ref = (_ref1 = variant == null ? void 0 : variant.imageUrl) != null ? _ref1 : found.data['imageUrl']) != null ? _ref : (_found_data_mediaUrls = found.data['mediaUrls']) == null ? void 0 : _found_data_mediaUrls[0], {
|
|
78
|
+
hostId
|
|
79
|
+
});
|
|
80
|
+
const slug = str(found.data['slug']);
|
|
81
|
+
return _extends({
|
|
82
|
+
kind: 'product',
|
|
83
|
+
title: str(found.data['name']) || found.id
|
|
84
|
+
}, slug ? {
|
|
85
|
+
url: `/products/${slug}`
|
|
86
|
+
} : {}, image ? {
|
|
87
|
+
imageUrl: image
|
|
88
|
+
} : {}, {
|
|
89
|
+
price: variant ? money(variant.priceUsd) : CommerceModel.productPriceText(found.product, min, max)
|
|
90
|
+
}, (variant == null ? void 0 : variant.compareAtPriceUsd) && variant.compareAtPriceUsd > variant.priceUsd ? {
|
|
91
|
+
compareAtPrice: money(variant.compareAtPriceUsd)
|
|
92
|
+
} : {});
|
|
93
|
+
}
|
|
94
|
+
function needsAddOns(product, variantId) {
|
|
95
|
+
const resolved = CommerceModel.resolveWebsiteLineModifiers(product, [], variantId);
|
|
96
|
+
return !resolved.ok;
|
|
97
|
+
}
|
|
98
|
+
export async function commerceProductDetails(request) {
|
|
99
|
+
var _found_product_variants;
|
|
100
|
+
var _variants_;
|
|
101
|
+
const found = await findProduct(request.hostId, str(request.input['product']));
|
|
102
|
+
if (!found) return {
|
|
103
|
+
text: 'No product on this site matches that name.'
|
|
104
|
+
};
|
|
105
|
+
const variants = (_found_product_variants = found.product.variants) != null ? _found_product_variants : [];
|
|
106
|
+
const lines = variants.slice(0, 12).map((variant)=>{
|
|
107
|
+
const sale = variant.compareAtPriceUsd && variant.compareAtPriceUsd > variant.priceUsd ? ` (was ${money(variant.compareAtPriceUsd)})` : '';
|
|
108
|
+
const day = CommerceModel.productAsksUseDate(found.product, variant.id) ? '; asks for the day it will be used' : '';
|
|
109
|
+
return `- ${optionName(variant)}: ${CommerceModel.variantHasPrice(variant) ? money(variant.priceUsd) : 'price coming soon'}${sale}${day}`;
|
|
110
|
+
});
|
|
111
|
+
const addOns = needsAddOns(found.product, (_variants_ = variants[0]) == null ? void 0 : _variants_.id) ? 'It has add-ons the visitor must choose on its page, so it cannot be added from the chat.' : '';
|
|
112
|
+
return {
|
|
113
|
+
text: [
|
|
114
|
+
`${str(found.data['name'])}${found.data['slug'] ? ` (page /products/${found.data['slug']})` : ''}`,
|
|
115
|
+
variants.length > 1 ? 'Options:' : 'Price:',
|
|
116
|
+
...lines,
|
|
117
|
+
addOns
|
|
118
|
+
].filter(Boolean).join('\n'),
|
|
119
|
+
cards: [
|
|
120
|
+
productCardOf(request.hostId, found)
|
|
121
|
+
]
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
export async function commerceProposeAddToCart(request) {
|
|
125
|
+
var _found_product_variants, _variants_find;
|
|
126
|
+
const found = await findProduct(request.hostId, str(request.input['product']));
|
|
127
|
+
if (!found) return {
|
|
128
|
+
text: 'No product on this site matches that name.'
|
|
129
|
+
};
|
|
130
|
+
const variants = (_found_product_variants = found.product.variants) != null ? _found_product_variants : [];
|
|
131
|
+
const asked = str(request.input['option']).toLowerCase();
|
|
132
|
+
const variant = variants.length <= 1 ? variants[0] : (_variants_find = variants.find((entry)=>optionName(entry).toLowerCase() === asked)) != null ? _variants_find : variants.find((entry)=>asked && optionName(entry).toLowerCase().includes(asked));
|
|
133
|
+
if (!variant) {
|
|
134
|
+
return {
|
|
135
|
+
text: `Ask which option the visitor wants: ${variants.map(optionName).join(', ')}.`
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
if (!CommerceModel.variantHasPrice(variant)) return {
|
|
139
|
+
text: 'That option has no price yet, so it cannot be added.'
|
|
140
|
+
};
|
|
141
|
+
if (needsAddOns(found.product, variant.id)) {
|
|
142
|
+
const slug = str(found.data['slug']);
|
|
143
|
+
return {
|
|
144
|
+
text: `This product has add-ons to choose on its page${slug ? ` (/products/${slug})` : ''}; send the visitor there.`
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
const day = str(request.input['day']);
|
|
148
|
+
const asksDay = CommerceModel.productAsksUseDate(found.product, variant.id);
|
|
149
|
+
if (asksDay && !DAY.test(day)) return {
|
|
150
|
+
text: 'Ask the visitor which day they will use it.'
|
|
151
|
+
};
|
|
152
|
+
const quantity = Math.min(CommerceModel.CART_MAX_QUANTITY, Math.max(1, Math.round(Number(request.input['quantity']) || 1)));
|
|
153
|
+
const name = str(found.data['name']);
|
|
154
|
+
const option = variants.length > 1 ? ` (${optionName(variant)})` : '';
|
|
155
|
+
return {
|
|
156
|
+
text: `Offered the visitor a card to add ${quantity} × ${name}${option} to their cart.`,
|
|
157
|
+
proposal: {
|
|
158
|
+
kind: 'add-to-cart',
|
|
159
|
+
title: `Add ${name}${option} to your cart?`,
|
|
160
|
+
summary: `${quantity} × ${money(variant.priceUsd)}${asksDay ? `, for ${dayLabel(dayMs(day))}` : ''}. You can review it in your cart before checkout.`,
|
|
161
|
+
confirmLabel: 'Add to cart',
|
|
162
|
+
afterEvent: CART_UPDATED_EVENT,
|
|
163
|
+
card: productCardOf(request.hostId, found, variant),
|
|
164
|
+
request: {
|
|
165
|
+
path: 'commerce/cart',
|
|
166
|
+
body: _extends({
|
|
167
|
+
hostId: request.hostId,
|
|
168
|
+
action: 'add',
|
|
169
|
+
productId: found.id
|
|
170
|
+
}, variant.id && variant.id !== 'default' ? {
|
|
171
|
+
variantId: variant.id
|
|
172
|
+
} : {}, {
|
|
173
|
+
quantity
|
|
174
|
+
}, asksDay ? {
|
|
175
|
+
useDayKey: day
|
|
176
|
+
} : {})
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
async function findResource(hostId, name) {
|
|
182
|
+
var _ref;
|
|
183
|
+
var _rankSections_;
|
|
184
|
+
if (!name) return null;
|
|
185
|
+
const snapshot = await hostRef(hostId).collection('resources').limit(RESOURCE_SCAN).get();
|
|
186
|
+
const all = snapshot.docs.map((doc)=>({
|
|
187
|
+
id: doc.id,
|
|
188
|
+
resource: doc.data()
|
|
189
|
+
}));
|
|
190
|
+
const exact = all.find(({ resource })=>str(resource.name).toLowerCase() === name.toLowerCase());
|
|
191
|
+
if (exact) return exact;
|
|
192
|
+
return (_ref = (_rankSections_ = rankSections(buildSectionIndex(all.map((entry)=>({
|
|
193
|
+
title: str(entry.resource.name),
|
|
194
|
+
heading: '',
|
|
195
|
+
text: '',
|
|
196
|
+
entry
|
|
197
|
+
}))), name, {
|
|
198
|
+
limit: 1
|
|
199
|
+
})[0]) == null ? void 0 : _rankSections_.section.entry) != null ? _ref : null;
|
|
200
|
+
}
|
|
201
|
+
/** A registered handler answered in-process, for its JSON. */ async function answerOf(handler, query) {
|
|
202
|
+
let status = 200;
|
|
203
|
+
let body = null;
|
|
204
|
+
const res = {
|
|
205
|
+
status (code) {
|
|
206
|
+
status = code;
|
|
207
|
+
return res;
|
|
208
|
+
},
|
|
209
|
+
json (value) {
|
|
210
|
+
body = value;
|
|
211
|
+
},
|
|
212
|
+
send (value) {
|
|
213
|
+
body = value;
|
|
214
|
+
},
|
|
215
|
+
setHeader () {
|
|
216
|
+
return undefined;
|
|
217
|
+
},
|
|
218
|
+
redirect () {
|
|
219
|
+
return undefined;
|
|
220
|
+
},
|
|
221
|
+
end () {
|
|
222
|
+
return undefined;
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
const req = {
|
|
226
|
+
method: 'GET',
|
|
227
|
+
query,
|
|
228
|
+
body: undefined,
|
|
229
|
+
headers: {},
|
|
230
|
+
cookies: {}
|
|
231
|
+
};
|
|
232
|
+
await handler(req, res);
|
|
233
|
+
return {
|
|
234
|
+
status,
|
|
235
|
+
body
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
async function checkStay(request) {
|
|
239
|
+
var _body_unavailable;
|
|
240
|
+
const found = await findResource(request.hostId, str(request.input['stay']));
|
|
241
|
+
if (!found) return 'No stay on this site matches that name.';
|
|
242
|
+
const checkInDayMs = dayMs(str(request.input['checkIn']));
|
|
243
|
+
const checkOutDayMs = dayMs(str(request.input['checkOut']));
|
|
244
|
+
if (!checkInDayMs || !checkOutDayMs) return 'Ask the visitor for the check-in and check-out days.';
|
|
245
|
+
if (checkOutDayMs <= checkInDayMs) return 'The check-out day must be after the check-in day.';
|
|
246
|
+
const todayMs = Date.parse(`${new Date().toISOString().slice(0, 10)}T00:00:00Z`);
|
|
247
|
+
if (checkInDayMs < todayMs) return 'That check-in day has passed.';
|
|
248
|
+
const { status, body } = await answerOf(reservationAvailabilityHandler, {
|
|
249
|
+
hostId: request.hostId,
|
|
250
|
+
resourceId: found.id
|
|
251
|
+
});
|
|
252
|
+
if (status !== 200 || !(body == null ? void 0 : body.resource)) return 'Availability for that stay is not available right now.';
|
|
253
|
+
const quote = CommerceModel.computeReservationQuote(found.resource, checkInDayMs, checkOutDayMs);
|
|
254
|
+
const free = CommerceModel.isRangeAvailable(found.resource, ((_body_unavailable = body.unavailable) != null ? _body_unavailable : []).map((range)=>({
|
|
255
|
+
checkInDayMs: range.fromDayMs,
|
|
256
|
+
checkOutDayMs: range.toDayMs,
|
|
257
|
+
status: 'confirmed'
|
|
258
|
+
})), checkInDayMs, checkOutDayMs);
|
|
259
|
+
return {
|
|
260
|
+
found,
|
|
261
|
+
checkInDayMs,
|
|
262
|
+
checkOutDayMs,
|
|
263
|
+
free,
|
|
264
|
+
quote
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
function stayCard(hostId, found, quote) {
|
|
268
|
+
var _found_resource_photoUrls;
|
|
269
|
+
const image = resolveMediaSrc((_found_resource_photoUrls = found.resource.photoUrls) == null ? void 0 : _found_resource_photoUrls[0], {
|
|
270
|
+
hostId
|
|
271
|
+
});
|
|
272
|
+
return _extends({
|
|
273
|
+
kind: 'stay',
|
|
274
|
+
title: found.resource.name
|
|
275
|
+
}, image ? {
|
|
276
|
+
imageUrl: image
|
|
277
|
+
} : {}, {
|
|
278
|
+
price: quote && quote.totalCents ? money(quote.totalCents / 100) : `${money(found.resource.nightlyRateUsd)} a night`
|
|
279
|
+
}, quote && quote.nights ? {
|
|
280
|
+
caption: `${quote.nights} ${quote.nights === 1 ? 'night' : 'nights'}`
|
|
281
|
+
} : {});
|
|
282
|
+
}
|
|
283
|
+
export async function commerceStayAvailability(request) {
|
|
284
|
+
const check = await checkStay(request);
|
|
285
|
+
if (typeof check === 'string') return {
|
|
286
|
+
text: check
|
|
287
|
+
};
|
|
288
|
+
const { found, checkInDayMs, checkOutDayMs, free, quote } = check;
|
|
289
|
+
const range = `${dayLabel(checkInDayMs)} to ${dayLabel(checkOutDayMs)}`;
|
|
290
|
+
if (quote.problem) return {
|
|
291
|
+
text: `${found.resource.name}: ${quote.problem}.`
|
|
292
|
+
};
|
|
293
|
+
return {
|
|
294
|
+
text: free ? `${found.resource.name} is free from ${range}: ${quote.nights} nights, ${money(quote.totalCents / 100)} in all${quote.depositCents && quote.depositCents < quote.totalCents ? `, ${money(quote.depositCents / 100)} due now as a deposit` : ''}.` : `${found.resource.name} is not free for every night from ${range}.`,
|
|
295
|
+
cards: [
|
|
296
|
+
stayCard(request.hostId, found, free ? quote : undefined)
|
|
297
|
+
]
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
export async function commerceProposeReservation(request) {
|
|
301
|
+
const check = await checkStay(request);
|
|
302
|
+
if (typeof check === 'string') return {
|
|
303
|
+
text: check
|
|
304
|
+
};
|
|
305
|
+
const { found, checkInDayMs, checkOutDayMs, free, quote } = check;
|
|
306
|
+
if (quote.problem) return {
|
|
307
|
+
text: `${found.resource.name}: ${quote.problem}.`
|
|
308
|
+
};
|
|
309
|
+
if (!free) return {
|
|
310
|
+
text: `${found.resource.name} is not free for those nights; offer other dates.`
|
|
311
|
+
};
|
|
312
|
+
const guests = Math.max(0, Math.round(Number(request.input['guests']) || 0));
|
|
313
|
+
const ceiling = CommerceModel.resourceGuestCeiling(found.resource);
|
|
314
|
+
if (guests && ceiling && guests > ceiling) return {
|
|
315
|
+
text: `${found.resource.name} sleeps ${ceiling} at most.`
|
|
316
|
+
};
|
|
317
|
+
const due = quote.depositCents && quote.depositCents < quote.totalCents ? quote.depositCents : quote.totalCents;
|
|
318
|
+
return {
|
|
319
|
+
text: `Offered the visitor a card to reserve ${found.resource.name}.`,
|
|
320
|
+
proposal: {
|
|
321
|
+
kind: 'reserve',
|
|
322
|
+
title: `Reserve ${found.resource.name}?`,
|
|
323
|
+
summary: `${dayLabel(checkInDayMs)} to ${dayLabel(checkOutDayMs)}, ${quote.nights} nights, ${money(quote.totalCents / 100)}. You pay ${money(due / 100)} at checkout.`,
|
|
324
|
+
confirmLabel: 'Reserve and pay',
|
|
325
|
+
idempotent: true,
|
|
326
|
+
fields: [
|
|
327
|
+
{
|
|
328
|
+
name: 'guestName',
|
|
329
|
+
label: 'Your name',
|
|
330
|
+
type: 'text',
|
|
331
|
+
required: true
|
|
332
|
+
},
|
|
333
|
+
{
|
|
334
|
+
name: 'guestEmail',
|
|
335
|
+
label: 'Your email',
|
|
336
|
+
type: 'email',
|
|
337
|
+
required: true
|
|
338
|
+
}
|
|
339
|
+
],
|
|
340
|
+
card: stayCard(request.hostId, found, quote),
|
|
341
|
+
request: {
|
|
342
|
+
path: 'commerce/reserve',
|
|
343
|
+
body: _extends({
|
|
344
|
+
hostId: request.hostId,
|
|
345
|
+
resourceId: found.id,
|
|
346
|
+
checkInDayMs,
|
|
347
|
+
checkOutDayMs
|
|
348
|
+
}, guests ? {
|
|
349
|
+
guests
|
|
350
|
+
} : {})
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
const RUNNERS = {
|
|
356
|
+
commerce_product_details: commerceProductDetails,
|
|
357
|
+
commerce_propose_add_to_cart: commerceProposeAddToCart,
|
|
358
|
+
commerce_stay_availability: commerceStayAvailability,
|
|
359
|
+
commerce_propose_reservation: commerceProposeReservation
|
|
360
|
+
};
|
|
361
|
+
export function runCommerceSiteChatTool(name, request) {
|
|
362
|
+
const run = RUNNERS[name];
|
|
363
|
+
if (!run) return Promise.resolve({
|
|
364
|
+
text: 'That tool is not available.'
|
|
365
|
+
});
|
|
366
|
+
return run(request);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
//# sourceMappingURL=site-chat-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/server/site-chat-tools.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { PluginApiHandler, PluginApiRequest } from '@aglyn/aglyn/app-utils/api-plugins'\nimport { resolveMediaSrc } from '@aglyn/aglyn/app-utils/media-ref'\nimport { buildSectionIndex, rankSections } from '@aglyn/aglyn/app-utils/section-retrieval'\nimport type {\n SiteChatCard,\n SiteChatToolAnswer,\n SiteChatToolRequest,\n} from '@aglyn/aglyn/plugin-manager/plugin-site-chat-tools'\nimport { firebaseAdmin } from '@aglyn/tenant-data-admin/server/firebase-admin'\nimport { CART_UPDATED_EVENT } from '../constants/cart-events'\nimport * as CommerceModel from '../model'\nimport { reservationAvailabilityHandler } from './reservation-availability'\n\n/**\n * The store's site chat tools (AGL-4250). Each reads the one site it is\n * handed and nothing else; a proposal checks what it proposes against the\n * same rules the door it names will apply, so a card the visitor presses\n * goes through. The prices and dates it states are the store's own.\n */\n\nconst PRODUCT_SCAN = 300\nconst RESOURCE_SCAN = 100\n\nconst str = (value: unknown): string => (typeof value === 'string' ? value.trim() : '')\nconst money = (usd: number): string =>\n `$${Number.isInteger(usd) ? usd : usd.toFixed(2)}`\nconst DAY = /^\\d{4}-\\d{2}-\\d{2}$/\nconst dayMs = (day: string): number => (DAY.test(day) ? Date.parse(`${day}T00:00:00Z`) : 0)\nconst dayLabel = (ms: number): string =>\n new Date(ms).toLocaleDateString('en-US', { weekday: 'short', month: 'short', day: 'numeric', timeZone: 'UTC' })\n\nconst hostRef = (hostId: string) => firebaseAdmin.app().firestore().collection('hosts').doc(hostId)\n\ninterface FoundProduct {\n id: string\n data: Record<string, any>\n product: CommerceModel.HostProduct\n}\n\n/** The site's online product best named by `name`, or `null`. */\nasync function findProduct(hostId: string, name: string): Promise<FoundProduct | null> {\n if (!name) return null\n const snapshot = await hostRef(hostId)\n .collection('products')\n .where('deletedAt', '==', null)\n .where('status', '==', 'active')\n .limit(PRODUCT_SCAN)\n .get()\n const listed = snapshot.docs\n .map((doc) => ({ id: doc.id, data: doc.data() as Record<string, any> }))\n .filter(\n ({ data }) =>\n CommerceModel.productListedOnline(data) &&\n CommerceModel.productSellsOnline(data) &&\n !CommerceModel.productIsSample(data),\n )\n const exact = listed.find(({ data }) => str(data['name']).toLowerCase() === name.toLowerCase())\n const best =\n exact ??\n rankSections(\n buildSectionIndex(\n listed.map((entry) => ({\n title: str(entry.data['name']),\n heading: '',\n text: [str(entry.data['slug']).replace(/-/g, ' '), ...(entry.data['tags'] ?? [])].join(' '),\n entry,\n })),\n ),\n name,\n { limit: 1 },\n )[0]?.section.entry\n if (!best) return null\n return { ...best, product: CommerceModel.liftLegacyProduct(best.data as never) }\n}\n\nconst optionName = (variant: CommerceModel.ProductVariant): string =>\n Object.values(variant.options ?? {}).filter(Boolean).join(' / ') || 'Standard'\n\nfunction productCardOf(hostId: string, found: FoundProduct, variant?: CommerceModel.ProductVariant): SiteChatCard {\n const [min, max] = CommerceModel.productPriceRange(found.product)\n const image = resolveMediaSrc(variant?.imageUrl ?? found.data['imageUrl'] ?? found.data['mediaUrls']?.[0], { hostId })\n const slug = str(found.data['slug'])\n return {\n kind: 'product',\n title: str(found.data['name']) || found.id,\n ...(slug ? { url: `/products/${slug}` } : {}),\n ...(image ? { imageUrl: image } : {}),\n price: variant ? money(variant.priceUsd) : CommerceModel.productPriceText(found.product, min, max),\n ...(variant?.compareAtPriceUsd && variant.compareAtPriceUsd > variant.priceUsd\n ? { compareAtPrice: money(variant.compareAtPriceUsd) }\n : {}),\n }\n}\n\nfunction needsAddOns(product: CommerceModel.HostProduct, variantId: string | undefined): boolean {\n const resolved = CommerceModel.resolveWebsiteLineModifiers(product as never, [], variantId)\n return !resolved.ok\n}\n\nexport async function commerceProductDetails(request: SiteChatToolRequest): Promise<SiteChatToolAnswer> {\n const found = await findProduct(request.hostId, str(request.input['product']))\n if (!found) return { text: 'No product on this site matches that name.' }\n const variants = found.product.variants ?? []\n const lines = variants.slice(0, 12).map((variant) => {\n const sale =\n variant.compareAtPriceUsd && variant.compareAtPriceUsd > variant.priceUsd\n ? ` (was ${money(variant.compareAtPriceUsd)})`\n : ''\n const day = CommerceModel.productAsksUseDate(found.product, variant.id) ? '; asks for the day it will be used' : ''\n return `- ${optionName(variant)}: ${CommerceModel.variantHasPrice(variant) ? money(variant.priceUsd) : 'price coming soon'}${sale}${day}`\n })\n const addOns = needsAddOns(found.product, variants[0]?.id)\n ? 'It has add-ons the visitor must choose on its page, so it cannot be added from the chat.'\n : ''\n return {\n text: [\n `${str(found.data['name'])}${found.data['slug'] ? ` (page /products/${found.data['slug']})` : ''}`,\n variants.length > 1 ? 'Options:' : 'Price:',\n ...lines,\n addOns,\n ]\n .filter(Boolean)\n .join('\\n'),\n cards: [productCardOf(request.hostId, found)],\n }\n}\n\nexport async function commerceProposeAddToCart(request: SiteChatToolRequest): Promise<SiteChatToolAnswer> {\n const found = await findProduct(request.hostId, str(request.input['product']))\n if (!found) return { text: 'No product on this site matches that name.' }\n const variants = found.product.variants ?? []\n const asked = str(request.input['option']).toLowerCase()\n const variant =\n variants.length <= 1\n ? variants[0]\n : variants.find((entry) => optionName(entry).toLowerCase() === asked) ??\n variants.find((entry) => asked && optionName(entry).toLowerCase().includes(asked))\n if (!variant) {\n return { text: `Ask which option the visitor wants: ${variants.map(optionName).join(', ')}.` }\n }\n if (!CommerceModel.variantHasPrice(variant)) return { text: 'That option has no price yet, so it cannot be added.' }\n if (needsAddOns(found.product, variant.id)) {\n const slug = str(found.data['slug'])\n return {\n text: `This product has add-ons to choose on its page${slug ? ` (/products/${slug})` : ''}; send the visitor there.`,\n }\n }\n const day = str(request.input['day'])\n const asksDay = CommerceModel.productAsksUseDate(found.product, variant.id)\n if (asksDay && !DAY.test(day)) return { text: 'Ask the visitor which day they will use it.' }\n const quantity = Math.min(CommerceModel.CART_MAX_QUANTITY, Math.max(1, Math.round(Number(request.input['quantity']) || 1)))\n const name = str(found.data['name'])\n const option = variants.length > 1 ? ` (${optionName(variant)})` : ''\n return {\n text: `Offered the visitor a card to add ${quantity} × ${name}${option} to their cart.`,\n proposal: {\n kind: 'add-to-cart',\n title: `Add ${name}${option} to your cart?`,\n summary: `${quantity} × ${money(variant.priceUsd)}${asksDay ? `, for ${dayLabel(dayMs(day))}` : ''}. You can review it in your cart before checkout.`,\n confirmLabel: 'Add to cart',\n afterEvent: CART_UPDATED_EVENT,\n card: productCardOf(request.hostId, found, variant),\n request: {\n path: 'commerce/cart',\n body: {\n hostId: request.hostId,\n action: 'add',\n productId: found.id,\n ...(variant.id && variant.id !== 'default' ? { variantId: variant.id } : {}),\n quantity,\n ...(asksDay ? { useDayKey: day } : {}),\n },\n },\n },\n }\n}\n\ninterface FoundResource {\n id: string\n resource: CommerceModel.HostResource\n}\n\nasync function findResource(hostId: string, name: string): Promise<FoundResource | null> {\n if (!name) return null\n const snapshot = await hostRef(hostId).collection('resources').limit(RESOURCE_SCAN).get()\n const all = snapshot.docs.map((doc) => ({ id: doc.id, resource: doc.data() as CommerceModel.HostResource }))\n const exact = all.find(({ resource }) => str(resource.name).toLowerCase() === name.toLowerCase())\n if (exact) return exact\n return (\n rankSections(\n buildSectionIndex(all.map((entry) => ({ title: str(entry.resource.name), heading: '', text: '', entry }))),\n name,\n { limit: 1 },\n )[0]?.section.entry ?? null\n )\n}\n\n/** A registered handler answered in-process, for its JSON. */\nasync function answerOf(\n handler: PluginApiHandler,\n query: Record<string, string>,\n): Promise<{ status: number; body: any }> {\n let status = 200\n let body: unknown = null\n const res = {\n status(code: number) {\n status = code\n return res\n },\n json(value: unknown) {\n body = value\n },\n send(value: unknown) {\n body = value\n },\n setHeader() {\n return undefined\n },\n redirect() {\n return undefined\n },\n end() {\n return undefined\n },\n }\n const req: PluginApiRequest = { method: 'GET', query, body: undefined, headers: {}, cookies: {} } as never\n await handler(req, res as never)\n return { status, body }\n}\n\ninterface StayCheck {\n found: FoundResource\n checkInDayMs: number\n checkOutDayMs: number\n free: boolean\n quote: CommerceModel.ReservationQuote\n}\n\nasync function checkStay(request: SiteChatToolRequest): Promise<StayCheck | string> {\n const found = await findResource(request.hostId, str(request.input['stay']))\n if (!found) return 'No stay on this site matches that name.'\n const checkInDayMs = dayMs(str(request.input['checkIn']))\n const checkOutDayMs = dayMs(str(request.input['checkOut']))\n if (!checkInDayMs || !checkOutDayMs) return 'Ask the visitor for the check-in and check-out days.'\n if (checkOutDayMs <= checkInDayMs) return 'The check-out day must be after the check-in day.'\n const todayMs = Date.parse(`${new Date().toISOString().slice(0, 10)}T00:00:00Z`)\n if (checkInDayMs < todayMs) return 'That check-in day has passed.'\n const { status, body } = await answerOf(reservationAvailabilityHandler, {\n hostId: request.hostId,\n resourceId: found.id,\n })\n if (status !== 200 || !body?.resource) return 'Availability for that stay is not available right now.'\n const quote = CommerceModel.computeReservationQuote(found.resource, checkInDayMs, checkOutDayMs)\n const free = CommerceModel.isRangeAvailable(\n found.resource,\n (body.unavailable ?? []).map((range: { fromDayMs: number; toDayMs: number }) => ({\n checkInDayMs: range.fromDayMs,\n checkOutDayMs: range.toDayMs,\n status: 'confirmed' as const,\n })),\n checkInDayMs,\n checkOutDayMs,\n )\n return { found, checkInDayMs, checkOutDayMs, free, quote }\n}\n\nfunction stayCard(hostId: string, found: FoundResource, quote?: CommerceModel.ReservationQuote): SiteChatCard {\n const image = resolveMediaSrc(found.resource.photoUrls?.[0], { hostId })\n return {\n kind: 'stay',\n title: found.resource.name,\n ...(image ? { imageUrl: image } : {}),\n price: quote && quote.totalCents ? money(quote.totalCents / 100) : `${money(found.resource.nightlyRateUsd)} a night`,\n ...(quote && quote.nights ? { caption: `${quote.nights} ${quote.nights === 1 ? 'night' : 'nights'}` } : {}),\n }\n}\n\nexport async function commerceStayAvailability(request: SiteChatToolRequest): Promise<SiteChatToolAnswer> {\n const check = await checkStay(request)\n if (typeof check === 'string') return { text: check }\n const { found, checkInDayMs, checkOutDayMs, free, quote } = check\n const range = `${dayLabel(checkInDayMs)} to ${dayLabel(checkOutDayMs)}`\n if (quote.problem) return { text: `${found.resource.name}: ${quote.problem}.` }\n return {\n text: free\n ? `${found.resource.name} is free from ${range}: ${quote.nights} nights, ${money(quote.totalCents / 100)} in all${\n quote.depositCents && quote.depositCents < quote.totalCents ? `, ${money(quote.depositCents / 100)} due now as a deposit` : ''\n }.`\n : `${found.resource.name} is not free for every night from ${range}.`,\n cards: [stayCard(request.hostId, found, free ? quote : undefined)],\n }\n}\n\nexport async function commerceProposeReservation(request: SiteChatToolRequest): Promise<SiteChatToolAnswer> {\n const check = await checkStay(request)\n if (typeof check === 'string') return { text: check }\n const { found, checkInDayMs, checkOutDayMs, free, quote } = check\n if (quote.problem) return { text: `${found.resource.name}: ${quote.problem}.` }\n if (!free) return { text: `${found.resource.name} is not free for those nights; offer other dates.` }\n const guests = Math.max(0, Math.round(Number(request.input['guests']) || 0))\n const ceiling = CommerceModel.resourceGuestCeiling(found.resource)\n if (guests && ceiling && guests > ceiling) return { text: `${found.resource.name} sleeps ${ceiling} at most.` }\n const due = quote.depositCents && quote.depositCents < quote.totalCents ? quote.depositCents : quote.totalCents\n return {\n text: `Offered the visitor a card to reserve ${found.resource.name}.`,\n proposal: {\n kind: 'reserve',\n title: `Reserve ${found.resource.name}?`,\n summary: `${dayLabel(checkInDayMs)} to ${dayLabel(checkOutDayMs)}, ${quote.nights} nights, ${money(\n quote.totalCents / 100,\n )}. You pay ${money(due / 100)} at checkout.`,\n confirmLabel: 'Reserve and pay',\n idempotent: true,\n fields: [\n { name: 'guestName', label: 'Your name', type: 'text', required: true },\n { name: 'guestEmail', label: 'Your email', type: 'email', required: true },\n ],\n card: stayCard(request.hostId, found, quote),\n request: {\n path: 'commerce/reserve',\n body: {\n hostId: request.hostId,\n resourceId: found.id,\n checkInDayMs,\n checkOutDayMs,\n ...(guests ? { guests } : {}),\n },\n },\n },\n }\n}\n\nconst RUNNERS: Record<string, (request: SiteChatToolRequest) => Promise<SiteChatToolAnswer>> = {\n commerce_product_details: commerceProductDetails,\n commerce_propose_add_to_cart: commerceProposeAddToCart,\n commerce_stay_availability: commerceStayAvailability,\n commerce_propose_reservation: commerceProposeReservation,\n}\n\nexport function runCommerceSiteChatTool(name: string, request: SiteChatToolRequest): Promise<SiteChatToolAnswer> {\n const run = RUNNERS[name]\n if (!run) return Promise.resolve({ text: 'That tool is not available.' })\n return run(request)\n}\n"],"names":["resolveMediaSrc","buildSectionIndex","rankSections","firebaseAdmin","CART_UPDATED_EVENT","CommerceModel","reservationAvailabilityHandler","PRODUCT_SCAN","RESOURCE_SCAN","str","value","trim","money","usd","Number","isInteger","toFixed","DAY","dayMs","day","test","Date","parse","dayLabel","ms","toLocaleDateString","weekday","month","timeZone","hostRef","hostId","app","firestore","collection","doc","findProduct","name","snapshot","where","limit","get","listed","docs","map","id","data","filter","productListedOnline","productSellsOnline","productIsSample","exact","find","toLowerCase","best","entry","title","heading","text","replace","join","section","product","liftLegacyProduct","optionName","variant","Object","values","options","Boolean","productCardOf","found","min","max","productPriceRange","image","imageUrl","slug","kind","url","price","priceUsd","productPriceText","compareAtPriceUsd","compareAtPrice","needsAddOns","variantId","resolved","resolveWebsiteLineModifiers","ok","commerceProductDetails","request","variants","input","lines","slice","sale","productAsksUseDate","variantHasPrice","addOns","length","cards","commerceProposeAddToCart","asked","includes","asksDay","quantity","Math","CART_MAX_QUANTITY","round","option","proposal","summary","confirmLabel","afterEvent","card","path","body","action","productId","useDayKey","findResource","all","resource","answerOf","handler","query","status","res","code","json","send","setHeader","undefined","redirect","end","req","method","headers","cookies","checkStay","checkInDayMs","checkOutDayMs","todayMs","toISOString","resourceId","quote","computeReservationQuote","free","isRangeAvailable","unavailable","range","fromDayMs","toDayMs","stayCard","photoUrls","totalCents","nightlyRateUsd","nights","caption","commerceStayAvailability","check","problem","depositCents","commerceProposeReservation","guests","ceiling","resourceGuestCeiling","due","idempotent","fields","label","type","required","RUNNERS","commerce_product_details","commerce_propose_add_to_cart","commerce_stay_availability","commerce_propose_reservation","runCommerceSiteChatTool","run","Promise","resolve"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC;AAGD,SAASA,eAAe,QAAQ,mCAAkC;AAClE,SAASC,iBAAiB,EAAEC,YAAY,QAAQ,2CAA0C;AAM1F,SAASC,aAAa,QAAQ,iDAAgD;AAC9E,SAASC,kBAAkB,QAAQ,8BAA0B;AAC7D,YAAYC,mBAAmB,oBAAU;AACzC,SAASC,8BAA8B,QAAQ,gCAA4B;AAE3E;;;;;CAKC,GAED,MAAMC,eAAe;AACrB,MAAMC,gBAAgB;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A4BjB;IAC5BkB,8BAA8Bd;AAChC;AAEA,OAAO,SAASe,wBAAwB9I,IAAY,EAAEsD,OAA4B;IAChF,MAAMyF,MAAMN,OAAO,CAACzI,KAAK;IACzB,IAAI,CAAC+I,KAAK,OAAOC,QAAQC,OAAO,CAAC;QAAE5H,MAAM;IAA8B;IACvE,OAAO0H,IAAIzF;AACb"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import type { SiteChatVisitorReader } from '@aglyn/aglyn/plugin-manager/plugin-site-chat-tools';
|
|
18
|
+
/**
|
|
19
|
+
* Who a site chat visitor is, for its greeting (AGL-4250): a signed-in site
|
|
20
|
+
* member's first name, read from the member's own session the way every
|
|
21
|
+
* member endpoint reads it (a suspended or signed-out member is nobody).
|
|
22
|
+
* The name only: the chat learns nothing else about the account.
|
|
23
|
+
*/
|
|
24
|
+
export declare const commerceSiteChatVisitor: SiteChatVisitorReader;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/ import { readActiveMemberSession } from "./membership.js";
|
|
17
|
+
/**
|
|
18
|
+
* Who a site chat visitor is, for its greeting (AGL-4250): a signed-in site
|
|
19
|
+
* member's first name, read from the member's own session the way every
|
|
20
|
+
* member endpoint reads it (a suspended or signed-out member is nobody).
|
|
21
|
+
* The name only: the chat learns nothing else about the account.
|
|
22
|
+
*/ export const commerceSiteChatVisitor = {
|
|
23
|
+
async readVisitor ({ hostId, cookies }) {
|
|
24
|
+
var _session_member_data, _ref, _ref1, _data_firstName, _ref2;
|
|
25
|
+
var _full_split_;
|
|
26
|
+
const session = await readActiveMemberSession({
|
|
27
|
+
cookies
|
|
28
|
+
}, hostId);
|
|
29
|
+
if (session.status !== 'active') return null;
|
|
30
|
+
const data = (_session_member_data = session.member.data()) != null ? _session_member_data : {};
|
|
31
|
+
const full = String((_ref = (_ref1 = (_data_firstName = data['firstName']) != null ? _data_firstName : data['name']) != null ? _ref1 : data['displayName']) != null ? _ref : '').trim();
|
|
32
|
+
const first = (_ref2 = (_full_split_ = full.split(/\s+/)[0]) == null ? void 0 : _full_split_.slice(0, 40)) != null ? _ref2 : '';
|
|
33
|
+
return first ? {
|
|
34
|
+
name: first
|
|
35
|
+
} : null;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
//# sourceMappingURL=site-chat-visitor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/server/site-chat-visitor.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { SiteChatVisitorReader } from '@aglyn/aglyn/plugin-manager/plugin-site-chat-tools'\nimport { readActiveMemberSession } from './membership'\n\n/**\n * Who a site chat visitor is, for its greeting (AGL-4250): a signed-in site\n * member's first name, read from the member's own session the way every\n * member endpoint reads it (a suspended or signed-out member is nobody).\n * The name only: the chat learns nothing else about the account.\n */\nexport const commerceSiteChatVisitor: SiteChatVisitorReader = {\n async readVisitor({ hostId, cookies }) {\n const session = await readActiveMemberSession({ cookies } as never, hostId)\n if (session.status !== 'active') return null\n const data = (session.member.data() ?? {}) as Record<string, unknown>\n const full = String(data['firstName'] ?? data['name'] ?? data['displayName'] ?? '').trim()\n const first = full.split(/\\s+/)[0]?.slice(0, 40) ?? ''\n return first ? { name: first } : null\n },\n}\n"],"names":["readActiveMemberSession","commerceSiteChatVisitor","readVisitor","hostId","cookies","session","data","full","status","member","String","trim","first","split","slice","name"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAGD,SAASA,uBAAuB,QAAQ,kBAAc;AAEtD;;;;;CAKC,GACD,OAAO,MAAMC,0BAAiD;IAC5D,MAAMC,aAAY,EAAEC,MAAM,EAAEC,OAAO,EAAE;YAGrBC,sBACMC,MAAAA,OAAAA;YACNC;QAJd,MAAMF,UAAU,MAAML,wBAAwB;YAAEI;QAAQ,GAAYD;QACpE,IAAIE,QAAQG,MAAM,KAAK,UAAU,OAAO;QACxC,MAAMF,QAAQD,uBAAAA,QAAQI,MAAM,CAACH,IAAI,cAAnBD,uBAAyB,CAAC;QACxC,MAAME,OAAOG,QAAOJ,QAAAA,SAAAA,kBAAAA,IAAI,CAAC,YAAY,YAAjBA,kBAAqBA,IAAI,CAAC,OAAO,YAAjCA,QAAqCA,IAAI,CAAC,cAAc,YAAxDA,OAA4D,IAAIK,IAAI;QACxF,MAAMC,kBAAQL,eAAAA,KAAKM,KAAK,CAAC,MAAM,CAAC,EAAE,qBAApBN,aAAsBO,KAAK,CAAC,GAAG,uBAAO;QACpD,OAAOF,QAAQ;YAAEG,MAAMH;QAAM,IAAI;IACnC;AACF,EAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import type { PluginSiteOffer, PluginSiteOfferSource } from '@aglyn/aglyn/plugin-manager/plugin-site-offers';
|
|
18
|
+
/**
|
|
19
|
+
* A STORE PRODUCT AS ANOTHER PLUGIN'S BUTTON SELLS IT (AGL-4252): core's
|
|
20
|
+
* `core.site-offers` for the `product` kind — an events calendar's "Get
|
|
21
|
+
* tickets", today.
|
|
22
|
+
*
|
|
23
|
+
* A product with one variant and no add-on the shopper must pick goes
|
|
24
|
+
* straight into the cart through the cart's own door, with the event's day
|
|
25
|
+
* as its use day when the product asks for one (a dated pass), so the cart's
|
|
26
|
+
* own rules (sold online, a day that has not passed) decide. Anything that
|
|
27
|
+
* needs a choice opens the product's page instead. A product the storefront
|
|
28
|
+
* does not list offers nothing.
|
|
29
|
+
*/
|
|
30
|
+
export declare function productSiteOffer(hostId: string, productId: string, data: Record<string, any>, dayKey?: string): PluginSiteOffer | null;
|
|
31
|
+
export declare const commerceProductSiteOffer: PluginSiteOfferSource;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/ import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
17
|
+
import { firebaseAdmin } from "@aglyn/tenant-data-admin/server/firebase-admin";
|
|
18
|
+
import { CART_UPDATED_EVENT } from "../constants/cart-events.js";
|
|
19
|
+
import * as CommerceModel from "../model/index.js";
|
|
20
|
+
import { productCard } from "./product-card.js";
|
|
21
|
+
/**
|
|
22
|
+
* A STORE PRODUCT AS ANOTHER PLUGIN'S BUTTON SELLS IT (AGL-4252): core's
|
|
23
|
+
* `core.site-offers` for the `product` kind — an events calendar's "Get
|
|
24
|
+
* tickets", today.
|
|
25
|
+
*
|
|
26
|
+
* A product with one variant and no add-on the shopper must pick goes
|
|
27
|
+
* straight into the cart through the cart's own door, with the event's day
|
|
28
|
+
* as its use day when the product asks for one (a dated pass), so the cart's
|
|
29
|
+
* own rules (sold online, a day that has not passed) decide. Anything that
|
|
30
|
+
* needs a choice opens the product's page instead. A product the storefront
|
|
31
|
+
* does not list offers nothing.
|
|
32
|
+
*/ export function productSiteOffer(hostId, productId, data, dayKey) {
|
|
33
|
+
var _product_variants, _product_modifierGroups;
|
|
34
|
+
var _variants_;
|
|
35
|
+
if (!CommerceModel.productListedOnline(data)) return null;
|
|
36
|
+
if (CommerceModel.productIsSample(data)) return null;
|
|
37
|
+
const card = productCard(productId, data);
|
|
38
|
+
const product = CommerceModel.liftLegacyProduct(data);
|
|
39
|
+
const [minPrice, maxPrice] = CommerceModel.productPriceRange(product);
|
|
40
|
+
const caption = CommerceModel.productPriceText(product, minPrice, maxPrice);
|
|
41
|
+
const variants = (_product_variants = product.variants) != null ? _product_variants : [];
|
|
42
|
+
const variantId = (_variants_ = variants[0]) == null ? void 0 : _variants_.id;
|
|
43
|
+
const needsChoice = variants.length > 1 || ((_product_modifierGroups = product.modifierGroups) != null ? _product_modifierGroups : []).some((group)=>{
|
|
44
|
+
var _ref;
|
|
45
|
+
return ((_ref = group == null ? void 0 : group.min) != null ? _ref : 0) > 0;
|
|
46
|
+
});
|
|
47
|
+
const base = _extends({
|
|
48
|
+
title: card.title
|
|
49
|
+
}, caption ? {
|
|
50
|
+
caption
|
|
51
|
+
} : {}, card.imageUrl ? {
|
|
52
|
+
imageUrl: String(card.imageUrl)
|
|
53
|
+
} : {});
|
|
54
|
+
if (needsChoice) {
|
|
55
|
+
return card.path ? _extends({}, base, {
|
|
56
|
+
action: {
|
|
57
|
+
kind: 'link',
|
|
58
|
+
href: card.path
|
|
59
|
+
}
|
|
60
|
+
}) : null;
|
|
61
|
+
}
|
|
62
|
+
const asksDay = CommerceModel.productAsksUseDate(product, variantId);
|
|
63
|
+
return _extends({}, base, {
|
|
64
|
+
action: {
|
|
65
|
+
kind: 'post',
|
|
66
|
+
endpoint: '/api/commerce/cart',
|
|
67
|
+
body: _extends({
|
|
68
|
+
hostId,
|
|
69
|
+
action: 'add',
|
|
70
|
+
productId
|
|
71
|
+
}, variantId ? {
|
|
72
|
+
variantId
|
|
73
|
+
} : {}, {
|
|
74
|
+
quantity: 1
|
|
75
|
+
}, asksDay && dayKey ? {
|
|
76
|
+
useDayKey: dayKey
|
|
77
|
+
} : {}),
|
|
78
|
+
notify: CART_UPDATED_EVENT,
|
|
79
|
+
done: 'Added to your cart'
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
export const commerceProductSiteOffer = {
|
|
84
|
+
async resolve ({ hostId, id, dayKey }) {
|
|
85
|
+
if (!hostId || !id || id.includes('/') || hostId.includes('/')) return null;
|
|
86
|
+
const snapshot = await firebaseAdmin.app().firestore().collection('hosts').doc(hostId).collection('products').doc(id).get();
|
|
87
|
+
return snapshot.exists ? productSiteOffer(hostId, id, snapshot.data(), dayKey) : null;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
//# sourceMappingURL=site-offers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/server/site-offers.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n PluginSiteOffer,\n PluginSiteOfferSource,\n} from '@aglyn/aglyn/plugin-manager/plugin-site-offers'\nimport { firebaseAdmin } from '@aglyn/tenant-data-admin/server/firebase-admin'\nimport { CART_UPDATED_EVENT } from '../constants/cart-events'\nimport * as CommerceModel from '../model'\nimport { productCard } from './product-card'\n\n/**\n * A STORE PRODUCT AS ANOTHER PLUGIN'S BUTTON SELLS IT (AGL-4252): core's\n * `core.site-offers` for the `product` kind — an events calendar's \"Get\n * tickets\", today.\n *\n * A product with one variant and no add-on the shopper must pick goes\n * straight into the cart through the cart's own door, with the event's day\n * as its use day when the product asks for one (a dated pass), so the cart's\n * own rules (sold online, a day that has not passed) decide. Anything that\n * needs a choice opens the product's page instead. A product the storefront\n * does not list offers nothing.\n */\nexport function productSiteOffer(\n hostId: string,\n productId: string,\n data: Record<string, any>,\n dayKey?: string,\n): PluginSiteOffer | null {\n if (!CommerceModel.productListedOnline(data)) return null\n if (CommerceModel.productIsSample(data)) return null\n const card = productCard(productId, data)\n const product = CommerceModel.liftLegacyProduct(\n data as CommerceModel.HostProduct,\n )\n const [minPrice, maxPrice] = CommerceModel.productPriceRange(product)\n const caption = CommerceModel.productPriceText(product, minPrice, maxPrice)\n const variants = product.variants ?? []\n const variantId = variants[0]?.id\n const needsChoice =\n variants.length > 1 ||\n (product.modifierGroups ?? []).some((group) => (group?.min ?? 0) > 0)\n const base = {\n title: card.title,\n ...(caption ? { caption } : {}),\n ...(card.imageUrl ? { imageUrl: String(card.imageUrl) } : {}),\n }\n if (needsChoice) {\n return card.path\n ? { ...base, action: { kind: 'link', href: card.path } }\n : null\n }\n const asksDay = CommerceModel.productAsksUseDate(product, variantId)\n return {\n ...base,\n action: {\n kind: 'post',\n endpoint: '/api/commerce/cart',\n body: {\n hostId,\n action: 'add',\n productId,\n ...(variantId ? { variantId } : {}),\n quantity: 1,\n ...(asksDay && dayKey ? { useDayKey: dayKey } : {}),\n },\n notify: CART_UPDATED_EVENT,\n done: 'Added to your cart',\n },\n }\n}\n\nexport const commerceProductSiteOffer: PluginSiteOfferSource = {\n async resolve({ hostId, id, dayKey }) {\n if (!hostId || !id || id.includes('/') || hostId.includes('/')) return null\n const snapshot = await firebaseAdmin\n .app()\n .firestore()\n .collection('hosts')\n .doc(hostId)\n .collection('products')\n .doc(id)\n .get()\n return snapshot.exists\n ? productSiteOffer(\n hostId,\n id,\n snapshot.data() as Record<string, any>,\n dayKey,\n )\n : null\n },\n}\n"],"names":["firebaseAdmin","CART_UPDATED_EVENT","CommerceModel","productCard","productSiteOffer","hostId","productId","data","dayKey","product","variants","productListedOnline","productIsSample","card","liftLegacyProduct","minPrice","maxPrice","productPriceRange","caption","productPriceText","variantId","id","needsChoice","length","modifierGroups","some","group","min","base","title","imageUrl","String","path","action","kind","href","asksDay","productAsksUseDate","endpoint","body","quantity","useDayKey","notify","done","commerceProductSiteOffer","resolve","includes","snapshot","app","firestore","collection","doc","get","exists"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC;AAMD,SAASA,aAAa,QAAQ,iDAAgD;AAC9E,SAASC,kBAAkB,QAAQ,8BAA0B;AAC7D,YAAYC,mBAAmB,oBAAU;AACzC,SAASC,WAAW,QAAQ,oBAAgB;AAE5C;;;;;;;;;;;CAWC,GACD,OAAO,SAASC,iBACdC,MAAc,EACdC,SAAiB,EACjBC,IAAyB,EACzBC,MAAe;QAUEC,mBAIdA;QAHeC;IATlB,IAAI,CAACR,cAAcS,mBAAmB,CAACJ,OAAO,OAAO;IACrD,IAAIL,cAAcU,eAAe,CAACL,OAAO,OAAO;IAChD,MAAMM,OAAOV,YAAYG,WAAWC;IACpC,MAAME,UAAUP,cAAcY,iBAAiB,CAC7CP;IAEF,MAAM,CAACQ,UAAUC,SAAS,GAAGd,cAAce,iBAAiB,CAACR;IAC7D,MAAMS,UAAUhB,cAAciB,gBAAgB,CAACV,SAASM,UAAUC;IAClE,MAAMN,YAAWD,oBAAAA,QAAQC,QAAQ,YAAhBD,oBAAoB,EAAE;IACvC,MAAMW,aAAYV,aAAAA,QAAQ,CAAC,EAAE,qBAAXA,WAAaW,EAAE;IACjC,MAAMC,cACJZ,SAASa,MAAM,GAAG,KAClB,EAACd,0BAAAA,QAAQe,cAAc,YAAtBf,0BAA0B,EAAE,EAAEgB,IAAI,CAAC,CAACC;;eAAU,SAACA,yBAAAA,MAAOC,GAAG,mBAAI,KAAK;;IACrE,MAAMC,OAAO;QACXC,OAAOhB,KAA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