@40rty/ams-cli 0.5.16 → 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.
@@ -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
  });
@@ -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 app's photo badges per product (percent positions); empty when the store has no Labeler feed. */
164
- export async function labelerBadges(domain) {
165
- const res = await fetch(`https://cdn.labeler.apps.acowebs.com/V3/${domain}/${domain}.json`);
166
- if (res.status === 403 || res.status === 404) return {};
167
- if (!res.ok) throw new Error(`labeler feed: ${res.status}`);
168
- const byProduct = {};
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 (await res.json()).badges) {
171
- if (badge.isActivated !== true || !badge.selectedPages.includes('products')) continue;
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 id of badge.rules.specificProducts) (byProduct[id] = byProduct[id] || []).push(sticker);
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 byProduct;
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/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  "peerDependencies": {
17
17
  "zod": "^3.25.0"
18
18
  },
19
- "version": "0.5.16",
19
+ "version": "0.5.17",
20
20
  "homepage": "https://docs.40rty.ai",
21
21
  "license": "UNLICENSED",
22
22
  "engines": {