@40rty/ams-cli 0.5.15 → 0.5.17
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/bin/commands/theme.mjs +1 -1
- package/bin/lib/__tests__/theme-feeds.test.mjs +22 -1
- package/bin/lib/theme/feeds.mjs +22 -11
- package/dist/wire.js +2 -1
- package/package.json +1 -1
package/bin/commands/theme.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// the store's own live theme: every product template's sections in the
|
|
3
3
|
// merchant's order, which template each product renders, and what the store's
|
|
4
4
|
// apps add to a product page (video reels, photo walls, sibling tiles, photo
|
|
5
|
-
// badges). Run it again whenever the merchant edits a template.
|
|
5
|
+
// badges, per page). Run it again whenever the merchant edits a template.
|
|
6
6
|
//
|
|
7
7
|
// The theme comes through the api (`/org/spaces/:slug/theme-*`), under the
|
|
8
8
|
// store's theme grant — the store's token never reaches this machine. The rest
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { balancedObject, renderedVideos, starappsGroup, yotpoAppKey } from '../theme/feeds.mjs';
|
|
2
|
+
import { badgesByPage, balancedObject, renderedVideos, starappsGroup, yotpoAppKey } from '../theme/feeds.mjs';
|
|
3
3
|
|
|
4
4
|
const catalog = new Map([
|
|
5
5
|
[1, { id: 1, title: 'Monitor, one camera', images: [{ src: 'https://cdn/1.png' }] }],
|
|
@@ -39,4 +39,25 @@ describe('store feeds', () => {
|
|
|
39
39
|
expect(yotpoAppKey('<script src="https://cdn-widgetsrepository.yotpo.com/v1/loader/GYcxUHBDXlibqKgqLLAjwv4yfXdemJJXH5POH6UZ"></script>')).toBe('GYcxUHBDXlibqKgqLLAjwv4yfXdemJJXH5POH6UZ');
|
|
40
40
|
expect(yotpoAppKey('<html></html>')).toBeUndefined();
|
|
41
41
|
});
|
|
42
|
+
|
|
43
|
+
it('files each Labeler sticker under every page it is selected for, active product-scoped ones only', () => {
|
|
44
|
+
const badge = (imageUrl, selectedPages, ids, extra = {}) => ({
|
|
45
|
+
isActivated: true, imageUrl, selectedPages, rules: { selected: ['specificProducts'], specificProducts: ids },
|
|
46
|
+
style: { width: 27, margin: { top: 0, left: 0, right: 'inherit', bottom: 'inherit' } }, ...extra,
|
|
47
|
+
});
|
|
48
|
+
const feed = { badges: [
|
|
49
|
+
badge('a/text.png', ['products'], ['p1']),
|
|
50
|
+
badge('a/round.png', ['home', 'collections'], ['p1', 'p2']),
|
|
51
|
+
badge('a/new.png', ['home'], ['p2']),
|
|
52
|
+
badge('a/off.png', ['products', 'home'], ['p1'], { isActivated: false }),
|
|
53
|
+
{ ...badge('a/all.png', ['home'], []), rules: { selected: ['allProducts'] } },
|
|
54
|
+
] };
|
|
55
|
+
const at = (image) => ({ image: `https://cdn.labeler.apps.acowebs.com/a/${image}`, width: 27, top: 0, left: 0, right: undefined, bottom: undefined });
|
|
56
|
+
expect(badgesByPage(feed)).toEqual({
|
|
57
|
+
products: { p1: [at('text.png')] },
|
|
58
|
+
home: { p1: [at('round.png')], p2: [at('round.png'), at('new.png')] },
|
|
59
|
+
collections: { p1: [at('round.png')], p2: [at('round.png')] },
|
|
60
|
+
});
|
|
61
|
+
expect(badgesByPage({ badges: [] })).toEqual({ products: {}, home: {}, collections: {} });
|
|
62
|
+
});
|
|
42
63
|
});
|
package/bin/lib/theme/feeds.mjs
CHANGED
|
@@ -160,19 +160,30 @@ export async function yotpoGallery(appKey, galleryId, pageSize = 9) {
|
|
|
160
160
|
return [...new Set([...body[0].result.matchAll(/<img class="yotpo-image[^"]*"[^>]*?data-src="([^"]+)"/g)].map((m) => `https:${m[1]}`))];
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
-
/** The Labeler
|
|
164
|
-
export
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
163
|
+
/** The Labeler pages a sticker can be scoped to (its `selectedPages`): the product page, the home page, a collection grid. */
|
|
164
|
+
export const LABELER_PAGES = ['products', 'home', 'collections'];
|
|
165
|
+
|
|
166
|
+
/** Labeler's feed as photo badges per page, per product (percent positions): each active, product-scoped
|
|
167
|
+
* badge under every page it is selected for — the store runs a different set on each. */
|
|
168
|
+
export function badgesByPage(feed) {
|
|
169
|
+
const byPage = Object.fromEntries(LABELER_PAGES.map((page) => [page, {}]));
|
|
169
170
|
const offset = (v) => (typeof v === 'number' ? v : undefined);
|
|
170
|
-
for (const badge of
|
|
171
|
-
if (badge.isActivated !== true || !badge.
|
|
172
|
-
if (!badge.rules.selected.includes('specificProducts')) continue;
|
|
171
|
+
for (const badge of feed.badges) {
|
|
172
|
+
if (badge.isActivated !== true || !badge.rules.selected.includes('specificProducts')) continue;
|
|
173
173
|
const m = badge.style.margin;
|
|
174
174
|
const sticker = { image: `https://cdn.labeler.apps.acowebs.com/${badge.imageUrl}`, width: badge.style.width, top: offset(m.top), left: offset(m.left), right: offset(m.right), bottom: offset(m.bottom) };
|
|
175
|
-
for (const
|
|
175
|
+
for (const page of LABELER_PAGES) {
|
|
176
|
+
if (!badge.selectedPages.includes(page)) continue;
|
|
177
|
+
for (const id of badge.rules.specificProducts) (byPage[page][id] = byPage[page][id] || []).push(sticker);
|
|
178
|
+
}
|
|
176
179
|
}
|
|
177
|
-
return
|
|
180
|
+
return byPage;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** The Labeler app's photo badges, per page then product; every page empty when the store has no Labeler feed. */
|
|
184
|
+
export async function labelerBadges(domain) {
|
|
185
|
+
const res = await fetch(`https://cdn.labeler.apps.acowebs.com/V3/${domain}/${domain}.json`);
|
|
186
|
+
if (res.status === 403 || res.status === 404) return badgesByPage({ badges: [] });
|
|
187
|
+
if (!res.ok) throw new Error(`labeler feed: ${res.status}`);
|
|
188
|
+
return badgesByPage(await res.json());
|
|
178
189
|
}
|
package/dist/wire.js
CHANGED
|
@@ -435,7 +435,7 @@ function partsText(parts) {
|
|
|
435
435
|
var ModelTurnAskSchema = z11.object({
|
|
436
436
|
kind: z11.enum(["choice", "open"]),
|
|
437
437
|
parts: z11.array(PartSchema).min(1)
|
|
438
|
-
}).refine((ask) => partsText(ask.parts).trim().length > 0, { message: "the question reads as nothing" }).transform((ask) => {
|
|
438
|
+
}).refine((ask) => partsText(ask.parts).trim().length > 0, { message: "the question reads as nothing" }).refine((ask) => /\?["'”’*)\s]*$/.test(partsText(ask.parts)), { message: "an ask is a question" }).transform((ask) => {
|
|
439
439
|
const answers = ask.parts.filter((p) => typeof p !== "string").length;
|
|
440
440
|
if (ask.kind === "choice" && answers >= MIN_CHOICE_ANSWERS && answers <= MAX_CHOICE_ANSWERS) return ask;
|
|
441
441
|
if (ask.kind === "open" && answers === 0) return ask;
|
|
@@ -816,6 +816,7 @@ var WireCatalogEntrySchema = z21.object({
|
|
|
816
816
|
examples: z21.array(z21.record(z21.unknown())).optional(),
|
|
817
817
|
renderedBy: z21.string().optional(),
|
|
818
818
|
alwaysInclude: z21.boolean().optional(),
|
|
819
|
+
asks: z21.boolean().optional(),
|
|
819
820
|
whenToUse: z21.string().optional(),
|
|
820
821
|
dontUseWhen: z21.string().optional(),
|
|
821
822
|
variants: z21.string().optional(),
|