@40rty/ams-cli 0.5.14 → 0.5.15
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/connect.mjs +27 -13
- package/bin/commands/doctor.mjs +12 -9
- package/bin/commands/publish.mjs +3 -2
- package/bin/forty.mjs +3 -1
- package/bin/lib/build.mjs +13 -3
- package/package.json +1 -1
package/bin/commands/connect.mjs
CHANGED
|
@@ -69,7 +69,10 @@ async function derivedName(config) {
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
/** Why a search that ran found nothing — the one cause we see over and over. */
|
|
72
|
-
export const ZERO_RESULTS_HINT = 'unpublished/dev stores are not in Shopify\'s global catalog
|
|
72
|
+
export const ZERO_RESULTS_HINT = 'unpublished/dev stores are not in Shopify\'s global catalog — publish the store (remove its password) and put its products on the Shop channel, or search the store\'s own catalog instead: `forty connect --search storefront`';
|
|
73
|
+
|
|
74
|
+
/** Where the agent's catalog search runs: Shopify's Global catalog (by shop id), or the store's own Storefront search. */
|
|
75
|
+
const SEARCH_MODES = ['global', 'storefront'];
|
|
73
76
|
|
|
74
77
|
/** `forty connect` — attach this app's store to the space. What the space renders is not decided here. */
|
|
75
78
|
export async function connect() {
|
|
@@ -90,21 +93,31 @@ export async function connect() {
|
|
|
90
93
|
const token = present(binding.token);
|
|
91
94
|
if (domain === undefined || token === undefined) fail('no store: pass --from <the store\'s live URL> (reads its public Storefront token), or set PUBLIC_STORE_DOMAIN and PUBLIC_STOREFRONT_API_TOKEN (or SHOPIFY_STORE_DOMAIN and SHOPIFY_STOREFRONT_ACCESS_TOKEN) in .env, or pass --domain and --token');
|
|
92
95
|
const host = domain.replace(/^https?:\/\//, '').replace(/\/+$/, '');
|
|
93
|
-
//
|
|
94
|
-
// store's
|
|
95
|
-
//
|
|
96
|
-
|
|
96
|
+
// `--search global` (default): Shopify's Global catalog, scoped by the
|
|
97
|
+
// store's shop id, with the store's own search beside it. `--search
|
|
98
|
+
// storefront`: the store's own Storefront search only — for a store Global
|
|
99
|
+
// does not index (a dev store, mock.shop, a Storefront-shaped mock API).
|
|
100
|
+
const search = option('search') === undefined ? 'global' : option('search');
|
|
101
|
+
if (!SEARCH_MODES.includes(search)) fail(`--search must be one of ${SEARCH_MODES.join(', ')} (got "${search}")`);
|
|
102
|
+
if (host === 'mock.shop' && search === 'global') fail('mock.shop is not in Shopify\'s Global catalog — connect it with `--search storefront`');
|
|
97
103
|
|
|
98
104
|
const store = await askStore(host, token);
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
105
|
+
const settings = { hosting: { embedded: true, headless: true }, storefrontAccessToken: token };
|
|
106
|
+
let shopId;
|
|
107
|
+
if (search === 'global') {
|
|
108
|
+
shopId = present(binding.shopId) !== undefined ? present(binding.shopId) : store.shopId;
|
|
109
|
+
if (shopId === undefined) {
|
|
110
|
+
fail(`could not work out ${host}'s shop id, which Global catalog search is scoped by — set SHOP_ID in .env to the number in gid://shopify/Shop/<n>, or search the store's own catalog: \`--search storefront\``);
|
|
111
|
+
}
|
|
112
|
+
settings.globalShopId = shopId;
|
|
113
|
+
// The store's market: Global search ranks by ship-to country and defaults to the US.
|
|
114
|
+
if (store.marketCountry !== undefined) settings.marketCountry = store.marketCountry;
|
|
115
|
+
} else {
|
|
116
|
+
// An empty value removes a shop id an earlier `forty connect` stored, so
|
|
117
|
+
// catalog search routes to the store's own search.
|
|
118
|
+
settings.globalShopId = '';
|
|
102
119
|
}
|
|
103
120
|
|
|
104
|
-
const settings = { hosting: { embedded: true, headless: true }, storefrontAccessToken: token, globalShopId: shopId };
|
|
105
|
-
// The store's market: Global search ranks by ship-to country and defaults to the US.
|
|
106
|
-
if (store.marketCountry !== undefined) settings.marketCountry = store.marketCountry;
|
|
107
|
-
|
|
108
121
|
const body = { platform: 'shopify', platformConfig: { platform: 'shopify', domain: host, config: settings }, vertical: 'ecommerce' };
|
|
109
122
|
// The agent greets visitors by the space's name: a name `forty init` derived
|
|
110
123
|
// (from the slug or package.json) gives way to the store's own.
|
|
@@ -112,7 +125,8 @@ export async function connect() {
|
|
|
112
125
|
if (rename !== undefined && rename !== store.shopName) body.name = store.shopName;
|
|
113
126
|
const result = await call(config.apiUrl, 'PUT', `/org/spaces/${config.spaceSlug}/storefront`, body);
|
|
114
127
|
if (body.name !== undefined) console.log(`space "${result.slug}" is now named "${body.name}" (was "${rename}", derived by \`forty init\`)`);
|
|
115
|
-
|
|
128
|
+
const how = search === 'global' ? `shop ${shopId}, Global catalog search${store.marketCountry === undefined ? '' : `, market ${store.marketCountry}`}` : 'the store\'s own catalog search';
|
|
129
|
+
console.log(`space "${result.slug}" is connected to ${host} (${how}) — \`forty dev\` to work on it`);
|
|
116
130
|
|
|
117
131
|
// Connected is not searchable: run the agent's own search once, for a product the store just named.
|
|
118
132
|
const probe = await probeSearch(config, store.sampleTitle);
|
package/bin/commands/doctor.mjs
CHANGED
|
@@ -16,8 +16,8 @@ import { findCredential, request } from '../lib/credentials.mjs';
|
|
|
16
16
|
import { agenticFramework, agenticWiringProblems } from '../lib/agentic.mjs';
|
|
17
17
|
import { askStore, probeSearch, ZERO_RESULTS_HINT } from './connect.mjs';
|
|
18
18
|
|
|
19
|
-
/** What
|
|
20
|
-
const
|
|
19
|
+
/** What a space bound to a store requires a source to draw, and what the agent speaks through. */
|
|
20
|
+
const STORE_TYPES = ['productGrid', 'collectionList'];
|
|
21
21
|
const REQUIRED_RENDERERS = ['agentText', 'turn'];
|
|
22
22
|
|
|
23
23
|
async function exists(file) {
|
|
@@ -117,10 +117,10 @@ export async function doctor() {
|
|
|
117
117
|
// ── The repo ──
|
|
118
118
|
const hasCatalog = await exists(config.catalog);
|
|
119
119
|
check(hasCatalog, `catalog file ${config.catalog} exists`);
|
|
120
|
+
let types = [];
|
|
120
121
|
if (hasCatalog) {
|
|
121
122
|
check(!/from ['"]react['"]/.test(await readFile(path.join(cwd, config.catalog), 'utf8')), 'the catalog file does not import React');
|
|
122
|
-
|
|
123
|
-
for (const type of REQUIRED_TYPES) check(types.includes(type), `the catalog declares "${type}"`);
|
|
123
|
+
types = Object.keys(await loadCatalog(config.catalog));
|
|
124
124
|
}
|
|
125
125
|
if (selfHosted) {
|
|
126
126
|
const componentsFile = path.join(path.dirname(config.catalog), 'components.tsx');
|
|
@@ -143,11 +143,14 @@ export async function doctor() {
|
|
|
143
143
|
// platform's own components, and the brand's only in a preview.
|
|
144
144
|
const released = space.componentSources.length === 1 && space.componentSources[0] === config.sourceId;
|
|
145
145
|
console.log(released ? `- visitors see ${config.sourceId}` : `- not released yet: visitors see ${space.componentSources.join(', ')} — \`forty publish\` when ready`);
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
146
|
+
// Only a space with a store has products and collections to draw.
|
|
147
|
+
if (hasCatalog && space.domain !== undefined) {
|
|
148
|
+
for (const type of STORE_TYPES) check(types.includes(type), `the catalog declares "${type}"`);
|
|
149
|
+
}
|
|
150
|
+
if (selfHosted && space.domain !== undefined) {
|
|
151
|
+
// The agent's tools read the store with its token. Whether catalog search
|
|
152
|
+
// works (Global by shop id, or the store's own) is the search check below.
|
|
153
|
+
check(space.hasStorefrontToken === true, `the space's store (${space.domain}) has a storefront token`, 'run `forty connect`');
|
|
151
154
|
}
|
|
152
155
|
if (space.domain !== undefined) await searchCheck(config, check);
|
|
153
156
|
}
|
package/bin/commands/publish.mjs
CHANGED
|
@@ -17,12 +17,13 @@ export async function buildRelease(config) {
|
|
|
17
17
|
version = '0.0.0';
|
|
18
18
|
console.log('package.json has no "version" — releasing as 0.0.0');
|
|
19
19
|
}
|
|
20
|
+
const catalog = await loadCatalog(config.catalog);
|
|
20
21
|
const release = {
|
|
21
22
|
sourceId: config.sourceId,
|
|
22
23
|
label: config.label,
|
|
23
24
|
version,
|
|
24
|
-
catalog: catalogToWire(
|
|
25
|
-
manifests: await loadManifests(config.manifests),
|
|
25
|
+
catalog: catalogToWire(catalog),
|
|
26
|
+
manifests: await loadManifests(config.manifests, Object.keys(catalog)),
|
|
26
27
|
};
|
|
27
28
|
if (config.bundle !== undefined) {
|
|
28
29
|
release.bundle = await buildBundle(config.bundle);
|
package/bin/forty.mjs
CHANGED
|
@@ -17,7 +17,9 @@
|
|
|
17
17
|
// forty releases the package's release history, and which one is live
|
|
18
18
|
// forty rollback make an earlier release live again (`forty rollback 3`)
|
|
19
19
|
// forty connect attach this app's store to the space (`--from <store url>`
|
|
20
|
-
// reads its public Storefront token off the live page
|
|
20
|
+
// reads its public Storefront token off the live page;
|
|
21
|
+
// `--search storefront` searches the store's own catalog
|
|
22
|
+
// instead of Shopify's Global one)
|
|
21
23
|
// forty origin add let a deployed site's origin call the api (CORS)
|
|
22
24
|
// forty domain add serve the space on your own domain; prints the DNS records
|
|
23
25
|
// forty feedback report a problem to the 40rty team
|
package/bin/lib/build.mjs
CHANGED
|
@@ -189,16 +189,26 @@ function bundleAssets(outputs) {
|
|
|
189
189
|
* types from (`node_modules/@40rty/ams-ui/dist/conversation/manifests`). The
|
|
190
190
|
* first folder that has a file wins it — the same layering a brand in the
|
|
191
191
|
* platform's repository gets from `layerCatalogsFileAccess`.
|
|
192
|
+
*
|
|
193
|
+
* `declared` (the catalog's types) filters the KIT folders only: a brand that
|
|
194
|
+
* drops a kit block must not ship its manifest, which the platform refuses.
|
|
195
|
+
* The brand's own folder is never filtered, so an orphan it wrote still fails.
|
|
192
196
|
*/
|
|
193
|
-
export async function loadManifests(dirs) {
|
|
197
|
+
export async function loadManifests(dirs, declared) {
|
|
194
198
|
const out = {};
|
|
195
|
-
|
|
199
|
+
const folders = Array.isArray(dirs) ? dirs : [dirs];
|
|
200
|
+
for (const [index, dir] of folders.entries()) {
|
|
196
201
|
const root = path.resolve(cwd, dir);
|
|
197
202
|
for (const entry of await readdir(root, { recursive: true, withFileTypes: true })) {
|
|
198
203
|
if (!entry.isFile() || !entry.name.endsWith('.md')) continue;
|
|
199
204
|
const abs = path.join(entry.parentPath, entry.name);
|
|
200
205
|
const key = `catalogs/${path.relative(root, abs).split(path.sep).join('/')}`;
|
|
201
|
-
if (
|
|
206
|
+
if (key in out) continue;
|
|
207
|
+
const text = await readFile(abs, 'utf8');
|
|
208
|
+
// A manifest names its type in its `# <type>` heading, as the platform reads it.
|
|
209
|
+
const type = /^#\s+(\S+)/m.exec(text)?.[1];
|
|
210
|
+
if (index > 0 && declared !== undefined && !declared.includes(type)) continue;
|
|
211
|
+
out[key] = text;
|
|
202
212
|
}
|
|
203
213
|
}
|
|
204
214
|
return out;
|