greatstore 0.0.0-stage → 0.2.3
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/CHANGELOG.md +564 -0
- package/README.md +122 -2
- package/dist/cli.js +795 -0
- package/dist/gs-skill/SKILL.md +82 -0
- package/dist/gs-skill/recipes/ask-about-this.md +31 -0
- package/dist/gs-skill/recipes/campaign-hero.md +48 -0
- package/dist/gs-skill/recipes/comparison-table.md +80 -0
- package/dist/gs-skill/recipes/complete-the-look.md +59 -0
- package/dist/gs-skill/recipes/gift-finder-funnel.md +88 -0
- package/dist/gs-skill/recipes/launchers.md +109 -0
- package/dist/gs-skill/recipes/page-action-suite.md +87 -0
- package/dist/gs-skill/recipes/product-faq.md +58 -0
- package/dist/gs-skill/references/agents-and-mcp.md +35 -0
- package/dist/gs-skill/references/apps.md +339 -0
- package/dist/gs-skill/references/embed-api.md +369 -0
- package/dist/gs-skill/references/push-notifications.md +66 -0
- package/dist/gs-skill/references/store-admin.md +129 -0
- package/dist/gs-skill/references/structured-content.md +296 -0
- package/package.json +29 -4
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
# `window.GreatStore` API reference
|
|
2
|
+
|
|
3
|
+
## Setup
|
|
4
|
+
|
|
5
|
+
```html
|
|
6
|
+
<script src="https://my-store.greatstore.ai/embed.js"></script>
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
One script tag, anywhere on the page (end of `<body>` preferred), with the
|
|
10
|
+
store's slug in the host. The `window.GreatStore` object exists synchronously
|
|
11
|
+
once the script executes; every method below is safe to call before the chat
|
|
12
|
+
UI has finished loading — pre-mount calls are queued and replayed in order
|
|
13
|
+
once it mounts. The SDK pre-warms its chat bundle in the background
|
|
14
|
+
automatically; the drawer stays closed until `open()` / `toggle()` /
|
|
15
|
+
`sendMessage()` is called or the shopper opens it from the chat bar
|
|
16
|
+
GreatStore puts at the bottom of the page. That bar is always present, so
|
|
17
|
+
the page needs no launcher of its own.
|
|
18
|
+
|
|
19
|
+
Requirements:
|
|
20
|
+
|
|
21
|
+
- The page's domain must be in the store's **allowed domains** (GreatStore
|
|
22
|
+
store settings) — see Troubleshooting below for the failure signature.
|
|
23
|
+
- If the store also wants push notifications, host `gs.js` at the site root
|
|
24
|
+
and load that instead of `embed.js` — it injects the embed for you. See
|
|
25
|
+
[push-notifications.md](push-notifications.md).
|
|
26
|
+
|
|
27
|
+
Code samples throughout are framework-free reference implementations —
|
|
28
|
+
re-express them in the host repo's framework (React, Vue, Shopify Liquid,
|
|
29
|
+
…) rather than retrofitting them as-is. **Using React?** `@greatstore/react`
|
|
30
|
+
wraps all of this in a `<GreatStore>` component with typed props (no
|
|
31
|
+
`data-*` attribute quoting) and clean mount/unmount for SPA routing —
|
|
32
|
+
`npm install @greatstore/react`.
|
|
33
|
+
|
|
34
|
+
## Appearance overrides
|
|
35
|
+
|
|
36
|
+
The store's configured appearance (theme colors, fonts, roundedness, mobile
|
|
37
|
+
bar, AI disclaimer) is the default everywhere. To make the
|
|
38
|
+
embed look or behave differently on a specific page — e.g. matching a
|
|
39
|
+
campaign landing page's palette — set `data-*` attributes on the embed
|
|
40
|
+
script tag. Every attribute is optional; anything you don't set falls back
|
|
41
|
+
to the store's configured value.
|
|
42
|
+
|
|
43
|
+
```html
|
|
44
|
+
<script
|
|
45
|
+
src="https://my-store.greatstore.ai/embed.js"
|
|
46
|
+
data-theme-mode="dark"
|
|
47
|
+
data-theme-radius="rounded"
|
|
48
|
+
data-z-index="9999"
|
|
49
|
+
data-theme-brand-color="#1a1a2e"
|
|
50
|
+
data-theme-surface-color="#ffffff"
|
|
51
|
+
data-theme-text-color="#111111"
|
|
52
|
+
data-theme-font="Inter, sans-serif"
|
|
53
|
+
data-ai-disclaimer="false"
|
|
54
|
+
></script>
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
| Attribute | Values | Overrides |
|
|
58
|
+
|---|---|---|
|
|
59
|
+
| `data-theme-mode` | `auto` \| `light` \| `dark` \| `custom` | Color scheme. |
|
|
60
|
+
| `data-theme-radius` | `sharp` \| `default` \| `rounded` | Corner roundedness. |
|
|
61
|
+
| `data-theme-mobile-bar-offset` | integer, `0`–`200` | Pixels the mobile chat bar sits above the bottom of the screen while the chat is closed. Raise it to clear a bottom nav of your own. |
|
|
62
|
+
| `data-z-index` | integer, `0`–`2147483647` | Stacking order of the chat overlay on your page. Lower it if something on the page must stay above the chat. |
|
|
63
|
+
| `data-theme-font` | CSS font-family string | Primary font. |
|
|
64
|
+
| `data-theme-font-secondary` | CSS font-family string | Secondary font. |
|
|
65
|
+
| `data-theme-brand-color` | any CSS color | Brand/primary color (only used in `custom` mode). |
|
|
66
|
+
| `data-theme-surface-color` | any CSS color | Surface/background color (only used in `custom` mode). |
|
|
67
|
+
| `data-theme-text-color` | any CSS color | Text color (only used in `custom` mode). |
|
|
68
|
+
| `data-ai-disclaimer` | `true` \| `false` | Shows or hides the AI disclaimer line. |
|
|
69
|
+
| `data-ai-disclaimer-text` | string, up to 200 chars | Custom disclaimer message (implies shown, unless `data-ai-disclaimer="false"` is also set). |
|
|
70
|
+
|
|
71
|
+
Not overridable this way: display name, assistant name, logo, and icons —
|
|
72
|
+
those stay whatever's configured in the store's admin.
|
|
73
|
+
|
|
74
|
+
Invalid values (unrecognized enum, malformed color, disallowed font
|
|
75
|
+
characters) are silently ignored and fall back to the configured default.
|
|
76
|
+
|
|
77
|
+
## Properties
|
|
78
|
+
|
|
79
|
+
| Property | Type | Description |
|
|
80
|
+
|---|---|---|
|
|
81
|
+
| `slug` | `string` | The store identifier the script was loaded for. |
|
|
82
|
+
| `host` | `string` | `"greatstore.ai"`. |
|
|
83
|
+
| `embedHost` | `string` | Origin the embed assets load from, e.g. `https://<slug>.greatstore.ai`. |
|
|
84
|
+
|
|
85
|
+
## Readiness: the `greatstore:ready` event
|
|
86
|
+
|
|
87
|
+
A `greatstore:ready` `CustomEvent` (with the SDK object as `detail`) is
|
|
88
|
+
dispatched on `window` once the chat UI has mounted and `open()` would render
|
|
89
|
+
instantly. It is the signal to gate on, and it works no matter when the
|
|
90
|
+
listener is attached: a listener added after GreatStore is ready receives the
|
|
91
|
+
event once, straight away.
|
|
92
|
+
|
|
93
|
+
```js
|
|
94
|
+
window.addEventListener(
|
|
95
|
+
"greatstore:ready",
|
|
96
|
+
() => {
|
|
97
|
+
button.hidden = false;
|
|
98
|
+
},
|
|
99
|
+
{ once: true },
|
|
100
|
+
);
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Methods
|
|
104
|
+
|
|
105
|
+
### `load(): void`
|
|
106
|
+
|
|
107
|
+
Pre-warms the chat bundle and identity in the background without opening the
|
|
108
|
+
panel. Called automatically when `embed.js` runs, so you rarely need it.
|
|
109
|
+
Idempotent.
|
|
110
|
+
|
|
111
|
+
### `open(): void` / `close(): void` / `toggle(): void`
|
|
112
|
+
|
|
113
|
+
Open, close, or toggle the chat. It is a drawer rising from the bottom of
|
|
114
|
+
the screen — a bounded, floating card on desktop, full-height under 768px
|
|
115
|
+
viewport width. All three queue if called before mount.
|
|
116
|
+
|
|
117
|
+
### `sendMessage(text: string): void`
|
|
118
|
+
|
|
119
|
+
Sends `text` as the shopper's own visible chat message and **opens the panel
|
|
120
|
+
if it's closed**. The text is trimmed; empty or whitespace-only strings are
|
|
121
|
+
silently dropped. Queues if called before mount.
|
|
122
|
+
|
|
123
|
+
This is the highest-leverage one-liner in the SDK: any element on the page
|
|
124
|
+
can become a conversation entry point with context baked into the question.
|
|
125
|
+
|
|
126
|
+
```js
|
|
127
|
+
document.querySelector("#ask-fit").addEventListener("click", () => {
|
|
128
|
+
window.GreatStore.sendMessage(
|
|
129
|
+
`I'm looking at "${productName}" — how does the sizing run?`
|
|
130
|
+
);
|
|
131
|
+
});
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Because the message renders as if the shopper typed it, write it in the
|
|
135
|
+
shopper's voice. It is not a hidden-context channel — don't stuff it with
|
|
136
|
+
invisible instructions or data dumps. For that, use `updateModelContext`.
|
|
137
|
+
|
|
138
|
+
### `updateModelContext(context: string): void`
|
|
139
|
+
|
|
140
|
+
Injects free-text **background context** about what the shopper is doing on
|
|
141
|
+
the page — the product they're viewing, what's in their cart, their account
|
|
142
|
+
tier — so the assistant can factor it in. Unlike `sendMessage`, this is
|
|
143
|
+
**invisible**: it never renders as a chat message and doesn't open the panel.
|
|
144
|
+
|
|
145
|
+
Each call **replaces** the value from the previous call — it never appends.
|
|
146
|
+
Keep one current snapshot; re-call it whenever the page state changes. Pass
|
|
147
|
+
an empty string to clear it. The text is read on the next chat turn, so set
|
|
148
|
+
it before (or while) the shopper is chatting. Queues if called before mount.
|
|
149
|
+
|
|
150
|
+
```js
|
|
151
|
+
// Keep the assistant aware of the current product as the shopper browses.
|
|
152
|
+
function syncContext() {
|
|
153
|
+
window.GreatStore.updateModelContext(
|
|
154
|
+
`Viewing "${product.title}" (${product.price}). In stock: ${product.inStock}. ` +
|
|
155
|
+
`Cart: ${cart.count} item(s), subtotal ${cart.subtotal}.`
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
syncContext();
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Write it as concise notes for the model, not prose for the shopper. The
|
|
162
|
+
context is page-controlled, so the assistant treats it as background
|
|
163
|
+
information, not as instructions — don't rely on it to change the assistant's
|
|
164
|
+
rules or persona.
|
|
165
|
+
|
|
166
|
+
### `on(event: string, handler: (...args) => void): () => void`
|
|
167
|
+
|
|
168
|
+
Subscribe to SDK events. Returns an unsubscribe function. Listeners attached
|
|
169
|
+
before mount are queued and wired up at mount. Handler exceptions are caught
|
|
170
|
+
and reported — they won't break the chat.
|
|
171
|
+
|
|
172
|
+
Events emitted:
|
|
173
|
+
|
|
174
|
+
| Event | Fired when |
|
|
175
|
+
|---|---|
|
|
176
|
+
| `"open"` | Panel transitions closed → open (including via `sendMessage` or the shopper's own click). |
|
|
177
|
+
| `"close"` | Panel transitions open → closed. |
|
|
178
|
+
|
|
179
|
+
### `generateStructuredContent(schema: object, prompt: string): Promise<unknown>`
|
|
180
|
+
|
|
181
|
+
Generates JSON matching `schema` from `prompt`, grounded in the store's live
|
|
182
|
+
catalog. Resolves to the generated data object itself. Rejects with `Error`
|
|
183
|
+
on any failure (invalid input, decline, validation failure, rate limit,
|
|
184
|
+
network); a decline sets `error.reason`. See
|
|
185
|
+
[structured-content.md](structured-content.md) for the full
|
|
186
|
+
contract, schema support, caching, and error semantics.
|
|
187
|
+
|
|
188
|
+
Accepts either a plain JSON Schema object or any object exposing a
|
|
189
|
+
`.toJSONSchema()` method (e.g. Zod schemas) — the conversion is called for
|
|
190
|
+
you.
|
|
191
|
+
|
|
192
|
+
Throws synchronously (rejects) if `prompt` is not a non-empty string or
|
|
193
|
+
`schema` is not an object.
|
|
194
|
+
|
|
195
|
+
### `enableNotifications(): Promise<{ ok: boolean }>`
|
|
196
|
+
|
|
197
|
+
Opts this browser into Web Push notifications from the store. Requirements:
|
|
198
|
+
|
|
199
|
+
- Must be called from a user gesture (e.g. a click handler).
|
|
200
|
+
- The site must host GreatStore's `gs.js` service-worker file. By default the
|
|
201
|
+
SDK looks for it at `/gs.js`; if it's hosted elsewhere, point to it via an
|
|
202
|
+
attribute on the embed script tag:
|
|
203
|
+
`<script src="…/embed.js" data-push-sw-path="/path/to/gs.js"></script>`.
|
|
204
|
+
|
|
205
|
+
Resolves `{ ok: true }` on success and `{ ok: false }` on any failure
|
|
206
|
+
(unsupported browser, no service worker hosted, permission denied). It never
|
|
207
|
+
rejects.
|
|
208
|
+
|
|
209
|
+
### `destroy(): void`
|
|
210
|
+
|
|
211
|
+
Fully tears down a mounted panel: unmounts the chat UI, closes any open voice
|
|
212
|
+
connection, and removes the embed's DOM/listeners from the page. Use this
|
|
213
|
+
when your page is done with the embed for good — e.g. a single-page app
|
|
214
|
+
navigating away from the only route that should show it.
|
|
215
|
+
|
|
216
|
+
No-ops (with a console warning) if nothing is mounted. The cached identity
|
|
217
|
+
and downloaded chat bundle are kept, so a later `load()` (or any call that
|
|
218
|
+
triggers a mount, like `open()`) mounts a fresh panel without a network
|
|
219
|
+
round-trip for either. `greatstore:ready` fires again once the next mount
|
|
220
|
+
completes:
|
|
221
|
+
|
|
222
|
+
```js
|
|
223
|
+
window.GreatStore.destroy();
|
|
224
|
+
// ...later, on the page/route where the embed should come back:
|
|
225
|
+
window.addEventListener("greatstore:ready", onRemounted, { once: true });
|
|
226
|
+
window.GreatStore.load();
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## Page tools — WebMCP (`document.modelContext`)
|
|
230
|
+
|
|
231
|
+
The recommended way to expose page capabilities to the assistant is the
|
|
232
|
+
WebMCP standard. The GreatStore assistant uses every tool registered on
|
|
233
|
+
`document.modelContext` **once GreatStore is ready** (see [Availability](#availability)
|
|
234
|
+
below), re-reading the list on each conversational turn — so tools
|
|
235
|
+
registered mid-session appear on the next message without a reload. Tools
|
|
236
|
+
registered before GreatStore is ready are ignored.
|
|
237
|
+
|
|
238
|
+
### Availability
|
|
239
|
+
|
|
240
|
+
If the browser implements WebMCP natively, `document.modelContext` is just
|
|
241
|
+
there. Otherwise the SDK installs a minimal fallback the instant `embed.js`
|
|
242
|
+
starts running — synchronously, no async gap — so `document.modelContext`
|
|
243
|
+
is normally available immediately. The embed script tag deliberately has no
|
|
244
|
+
`async`/`defer` — a script with neither blocks parsing and runs at its own
|
|
245
|
+
position, which matters if the page also has another script (a nav widget,
|
|
246
|
+
an analytics tag) registering its own WebMCP tools: whichever executes
|
|
247
|
+
first wins that registration, and only a synchronous, unconditionally-first
|
|
248
|
+
script gives GreatStore's fallback shim a real chance of installing before
|
|
249
|
+
one of those calls happens. Your own code
|
|
250
|
+
can still run on either side of `embed.js` — before it has executed at all
|
|
251
|
+
(`window.GreatStore` doesn't exist yet), or long after it has mounted (a lazily rendered component, a
|
|
252
|
+
tag manager). Listening for `greatstore:ready` covers both: a listener
|
|
253
|
+
attached after GreatStore is already ready still receives the event, once.
|
|
254
|
+
|
|
255
|
+
```js
|
|
256
|
+
window.addEventListener(
|
|
257
|
+
"greatstore:ready",
|
|
258
|
+
() => {
|
|
259
|
+
document.modelContext.registerTool(/* … */);
|
|
260
|
+
},
|
|
261
|
+
{ once: true },
|
|
262
|
+
);
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
(`navigator.modelContext` is a deprecated alias for the same object; use
|
|
266
|
+
`document.modelContext` in new code.)
|
|
267
|
+
|
|
268
|
+
### `registerTool(tool, options?)`
|
|
269
|
+
|
|
270
|
+
```ts
|
|
271
|
+
document.modelContext.registerTool(
|
|
272
|
+
{
|
|
273
|
+
name: string, // required, non-empty, unique on the page
|
|
274
|
+
description: string, // required — how the AI decides when to call it
|
|
275
|
+
inputSchema?: object, // JSON Schema for execute's args;
|
|
276
|
+
// defaults to { type: "object", properties: {} }
|
|
277
|
+
execute(args): Result | Promise<Result>,
|
|
278
|
+
},
|
|
279
|
+
options?: { signal?: AbortSignal }, // abort to unregister
|
|
280
|
+
);
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
- **Result shape**: `execute` returns MCP content blocks —
|
|
284
|
+
`{ content: [{ type: "text", text: "…" }] }`. For structured data,
|
|
285
|
+
`JSON.stringify` it into `text`. Add `isError: true` to mark a handled
|
|
286
|
+
failure.
|
|
287
|
+
- **Errors**: a thrown error or rejected promise is delivered to the
|
|
288
|
+
assistant as a *failed* tool call carrying the error message — the
|
|
289
|
+
assistant can explain or adapt. Errors never escape into your page.
|
|
290
|
+
- **Duplicate names throw.** To replace a tool, abort its registration first.
|
|
291
|
+
- **Unregistration is `AbortSignal`-driven**: pass `{ signal }` and call
|
|
292
|
+
`abort()` when the tool's context goes away (SPA navigation, modal close).
|
|
293
|
+
A pre-aborted signal skips registration. (A legacy
|
|
294
|
+
`unregisterTool(name)` exists but is deprecated in the spec.)
|
|
295
|
+
- **Treat `args` as untrusted input**: values are AI-generated. Validate
|
|
296
|
+
before passing to your own APIs, and never `eval` anything from them.
|
|
297
|
+
|
|
298
|
+
A complete tool, registered once GreatStore is ready:
|
|
299
|
+
|
|
300
|
+
```js
|
|
301
|
+
window.addEventListener("greatstore:ready", () => {
|
|
302
|
+
document.modelContext.registerTool({
|
|
303
|
+
name: "add_to_cart",
|
|
304
|
+
description:
|
|
305
|
+
"Add a product variant to the shopper's cart on this site. " +
|
|
306
|
+
"Use when the shopper asks to add, buy, or get a product.",
|
|
307
|
+
inputSchema: {
|
|
308
|
+
type: "object",
|
|
309
|
+
properties: {
|
|
310
|
+
variantId: { type: "string" },
|
|
311
|
+
quantity: { type: "integer", minimum: 1 },
|
|
312
|
+
},
|
|
313
|
+
required: ["variantId"],
|
|
314
|
+
},
|
|
315
|
+
async execute({ variantId, quantity }) {
|
|
316
|
+
const res = await fetch("/cart/add.js", {
|
|
317
|
+
method: "POST",
|
|
318
|
+
headers: { "Content-Type": "application/json" },
|
|
319
|
+
body: JSON.stringify({ id: variantId, quantity: quantity ?? 1 }),
|
|
320
|
+
});
|
|
321
|
+
if (!res.ok) throw new Error(`Cart add failed (${res.status})`);
|
|
322
|
+
const cart = await res.json();
|
|
323
|
+
return { content: [{ type: "text", text: JSON.stringify(cart) }] };
|
|
324
|
+
},
|
|
325
|
+
});
|
|
326
|
+
}, { once: true });
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
Returning the fresh cart state after the mutation lets the assistant confirm
|
|
330
|
+
accurately. Good tool families: cart (`get_cart`, `add_to_cart`), navigation
|
|
331
|
+
(`go_to_page`), page state (`get_current_product`, `apply_filters`), UI
|
|
332
|
+
(`highlight_section`, `scroll_to_reviews`).
|
|
333
|
+
|
|
334
|
+
And a context-scoped tool, unregistered via `AbortSignal`:
|
|
335
|
+
|
|
336
|
+
```js
|
|
337
|
+
const ac = new AbortController();
|
|
338
|
+
document.modelContext.registerTool(
|
|
339
|
+
{
|
|
340
|
+
name: "get_product_reviews",
|
|
341
|
+
description: "Read the reviews shown on the current product page.",
|
|
342
|
+
inputSchema: { type: "object", properties: {} },
|
|
343
|
+
execute: () => ({
|
|
344
|
+
content: [{ type: "text", text: JSON.stringify(collectReviews()) }],
|
|
345
|
+
}),
|
|
346
|
+
},
|
|
347
|
+
{ signal: ac.signal },
|
|
348
|
+
);
|
|
349
|
+
|
|
350
|
+
// On SPA route change away from the product page:
|
|
351
|
+
ac.abort();
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
## URL parameter: `?gs_chat=open`
|
|
355
|
+
|
|
356
|
+
When the page URL carries `gs_chat=open`, the panel opens automatically once
|
|
357
|
+
the embed mounts. The param is consumed and stripped from the URL via
|
|
358
|
+
`history.replaceState`, so a manual reload doesn't re-open the panel. Use it
|
|
359
|
+
in campaign links, emails, and post-login redirects.
|
|
360
|
+
|
|
361
|
+
## Troubleshooting
|
|
362
|
+
|
|
363
|
+
| Symptom | Likely cause |
|
|
364
|
+
|---|---|
|
|
365
|
+
| Console: `[GreatStore] Chat is unavailable on <origin>… this domain isn't in the store's allowed domains` | The page's origin isn't in the store's allowed domains. Add it in store settings. Until then every SDK network call fails. |
|
|
366
|
+
| Console: `[GreatStore] Embed script must be loaded from <slug>.greatstore.ai/embed.js` | The script was copied/self-hosted instead of loaded from the store's embed URL. Always load it from `https://<slug>.greatstore.ai/embed.js`. |
|
|
367
|
+
| `generateStructuredContent` rejects with a rate-limit message | More than ~20 requests/minute from one visitor. Consolidate calls into fewer, richer schemas. |
|
|
368
|
+
| Chat won't auto-open after returning to the page | Intentional: the drawer never auto-opens on resume — it would cover the content the shopper is reading. The transcript is preserved; they'll see it when they tap the launcher. |
|
|
369
|
+
| Tools registered but the assistant doesn't use them | Check the `description` — it's the only signal for *when* to call. Also confirm the registration ran (it runs inside a `greatstore:ready` listener) on the same page the conversation is on. |
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Web push re-engagement
|
|
2
|
+
|
|
3
|
+
Shoppers who opt in receive browser notifications from the store — under the
|
|
4
|
+
merchant's own domain and branding, with the permission prompt shown inline
|
|
5
|
+
on the merchant's page. Setup is two pieces: a single file hosted at the site
|
|
6
|
+
root, and an opt-in button.
|
|
7
|
+
|
|
8
|
+
## 1. Host `gs.js` at the site root
|
|
9
|
+
|
|
10
|
+
Download the store's loader and serve it at `/gs.js` on the merchant's
|
|
11
|
+
domain:
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
https://<slug>.greatstore.ai/gs.js → https://www.merchant-site.com/gs.js
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Always download it from the **store's own subdomain** — the file is built for
|
|
18
|
+
that store; don't copy one from elsewhere.
|
|
19
|
+
|
|
20
|
+
Then load it with one tag (replacing the `embed.js` tag — `gs.js` injects the
|
|
21
|
+
embed for you and registers itself as the service worker):
|
|
22
|
+
|
|
23
|
+
```html
|
|
24
|
+
<script src="/gs.js"></script>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Hosting this file is what enables push. Without it, push is simply off —
|
|
28
|
+
`enableNotifications()` returns `{ ok: false }` and nothing else changes.
|
|
29
|
+
|
|
30
|
+
### Non-root hosting
|
|
31
|
+
|
|
32
|
+
If the platform can't serve files at the site root (e.g. Shopify themes
|
|
33
|
+
serve assets under a path), keep the regular `embed.js` tag and point it at
|
|
34
|
+
where the file lives — the path must be on the merchant's own origin:
|
|
35
|
+
|
|
36
|
+
```html
|
|
37
|
+
<script
|
|
38
|
+
src="https://my-store.greatstore.ai/embed.js"
|
|
39
|
+
data-push-sw-path="/cdn/shop/files/gs.js"
|
|
40
|
+
></script>
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## 2. Offer the opt-in from a user gesture
|
|
44
|
+
|
|
45
|
+
```js
|
|
46
|
+
optInButton.addEventListener("click", async () => {
|
|
47
|
+
const { ok } = await window.GreatStore.enableNotifications();
|
|
48
|
+
optInButton.hidden = ok; // done — or quietly keep the button
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Rules that make this work well:
|
|
53
|
+
|
|
54
|
+
- **Always call it from a click** — browsers ignore or penalize permission
|
|
55
|
+
prompts that aren't user-initiated, and the call is designed for gesture
|
|
56
|
+
context.
|
|
57
|
+
- **Never prompt on page load.** Tie the button to a moment where
|
|
58
|
+
notifications have obvious value ("Notify me when this is back in stock",
|
|
59
|
+
post-purchase, after a chat conversation).
|
|
60
|
+
- `{ ok: false }` covers every failure the same way — unsupported browser, no
|
|
61
|
+
`gs.js` hosted, permission denied. It never rejects, and there's no popup
|
|
62
|
+
fallback. Design the button so a decline just leaves the page as it was;
|
|
63
|
+
don't show an error.
|
|
64
|
+
- The promise resolving `{ ok: true }` means this browser is subscribed.
|
|
65
|
+
There's nothing else to wire — notification delivery is handled by
|
|
66
|
+
GreatStore.
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# Store administration from the CLI
|
|
2
|
+
|
|
3
|
+
The `gs` CLI is a full admin surface for a GreatStore store, mirroring the
|
|
4
|
+
merchant's admin dashboard one-to-one: `npx greatstore configure` ↔ the Configure panel,
|
|
5
|
+
`npx greatstore connectors` ↔ the Connectors panel, `npx greatstore apps` ↔ the Apps panel. Same
|
|
6
|
+
fields, same behaviour — anything you change is what the merchant sees in
|
|
7
|
+
their dashboard.
|
|
8
|
+
|
|
9
|
+
That makes the CLI the way a coding agent grounds and unblocks its own work:
|
|
10
|
+
read the store's configuration to make better decisions, and make the narrow
|
|
11
|
+
class of additive, integration-enabling changes yourself instead of telling
|
|
12
|
+
the user to go click through a dashboard.
|
|
13
|
+
|
|
14
|
+
## Setup
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
npx greatstore login # one-time browser sign-in (needs a human)
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Credentials persist across runs. Admin commands take `--store <slug>`
|
|
21
|
+
directly, or read the nearest `.gsrc` (`{"store":"my-store"}`) — so they work
|
|
22
|
+
from any repo, not just a scaffolded app project. Every read supports
|
|
23
|
+
`--json` for machine-readable output.
|
|
24
|
+
|
|
25
|
+
## Read freely — always safe
|
|
26
|
+
|
|
27
|
+
Reading store state is never destructive. Do it whenever it would improve a
|
|
28
|
+
decision:
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
npx greatstore configure --store my-store --json # brand config
|
|
32
|
+
npx greatstore connectors --store my-store --json # MCP connectors feeding the assistant
|
|
33
|
+
npx greatstore connectors health --store my-store # live-probe them (reports tool counts)
|
|
34
|
+
npx greatstore apps list --store my-store --json # deployed custom in-chat apps
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
What each read is good for:
|
|
38
|
+
|
|
39
|
+
- **`npx greatstore configure`** — the store's `extraOrigins` (is the site you're
|
|
40
|
+
integrating actually allowlisted? — see the embed troubleshooting note in
|
|
41
|
+
[embed-api.md](embed-api.md)), `theme` (match generated on-page UI to the
|
|
42
|
+
brand's colors/radius), `storeLink`, and CSP host lists.
|
|
43
|
+
- **`npx greatstore connectors`** — which MCP connectors the assistant has, and whether
|
|
44
|
+
the Maker MCP is on. This tells you what the assistant can actually *do*:
|
|
45
|
+
check it before building features that lean on catalog data (e.g.
|
|
46
|
+
[structured content](structured-content.md) grounding), and before
|
|
47
|
+
registering WebMCP page tools that would duplicate a capability a
|
|
48
|
+
server-side connector already provides.
|
|
49
|
+
- **`npx greatstore connectors health`** — a connector being listed doesn't mean it's
|
|
50
|
+
reachable; this probes each one live. Run it when assistant behaviour
|
|
51
|
+
suggests a tool isn't responding.
|
|
52
|
+
|
|
53
|
+
## Safe to change without asking
|
|
54
|
+
|
|
55
|
+
When the task the user gave you requires it, these changes are yours to
|
|
56
|
+
make: they're additive, easy to undo, and invisible to shoppers.
|
|
57
|
+
|
|
58
|
+
- **`extraOrigins`** — the origin allowlist for the embed. Installing the
|
|
59
|
+
widget on a new site/staging domain? Add that origin yourself instead of
|
|
60
|
+
reporting "ask the merchant to allowlist it".
|
|
61
|
+
- **`cspScriptHosts` / `cspConnectHosts`** — hosts the storefront accepts
|
|
62
|
+
for scripts/connections. Add a host when an app
|
|
63
|
+
legitimately needs a third-party SDK or API.
|
|
64
|
+
|
|
65
|
+
**List flags replace the stored list — always read-merge-write.** Fetch the
|
|
66
|
+
current value, append yours, write the union:
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
npx greatstore configure --store my-store --json
|
|
70
|
+
# extraOrigins is ["https://shop.example.com"] → write both, comma-separated:
|
|
71
|
+
npx greatstore configure set --store my-store \
|
|
72
|
+
--extraOrigins "https://shop.example.com,https://staging.example.com"
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Never drop an entry you didn't add, and say what you changed (and why) when
|
|
76
|
+
you report back to the user.
|
|
77
|
+
|
|
78
|
+
## Ask the merchant first
|
|
79
|
+
|
|
80
|
+
Everything below is shopper-visible or changes what the live assistant can
|
|
81
|
+
do for every shopper. Propose it, don't do it unprompted:
|
|
82
|
+
|
|
83
|
+
- **Brand-visible config** — `displayName`, `assistantName`, `storeLink`,
|
|
84
|
+
`theme`, and asset uploads
|
|
85
|
+
(`npx greatstore configure upload|clear icon|logoLight|logoDark`).
|
|
86
|
+
- **Connector mutations** — `npx greatstore connectors add|remove|enable|disable` and
|
|
87
|
+
`npx greatstore connectors maker on|off`. (`add` probes the connector for tool
|
|
88
|
+
discovery before saving and refuses if it doesn't answer; `--force`
|
|
89
|
+
overrides. Still: adding capabilities to the merchant's assistant is the
|
|
90
|
+
merchant's call.)
|
|
91
|
+
- **Anything that clears** — passing `""` to empty a field, removing list
|
|
92
|
+
entries, `clear`ing assets.
|
|
93
|
+
|
|
94
|
+
When the user has *explicitly asked* for one of these ("set the assistant's
|
|
95
|
+
name to Voyager", "connect this MCP server"), that's the go-ahead — do it
|
|
96
|
+
and confirm the result with a read.
|
|
97
|
+
|
|
98
|
+
## Command reference
|
|
99
|
+
|
|
100
|
+
```
|
|
101
|
+
npx greatstore configure [--json] show configuration
|
|
102
|
+
npx greatstore configure set --<field> <value> displayName, assistantName,
|
|
103
|
+
storeLink, extraOrigins a,b,
|
|
104
|
+
cspScriptHosts a,b, cspConnectHosts a,b
|
|
105
|
+
("" clears a field)
|
|
106
|
+
npx greatstore configure set --theme.<field> <value> one theme field, merged into the rest:
|
|
107
|
+
mode auto|light|dark|custom,
|
|
108
|
+
radius sharp|default|rounded,
|
|
109
|
+
fontFamily, secondaryFontFamily,
|
|
110
|
+
mobileBottomBarOffset (px, 0-200), zIndex,
|
|
111
|
+
brandColor/surfaceColor/textColor and
|
|
112
|
+
the fine-grained color tokens
|
|
113
|
+
npx greatstore configure set --theme '<json>' merge a whole object (--themeFile <path>);
|
|
114
|
+
--replace overwrites instead of merging
|
|
115
|
+
npx greatstore configure set --help every field, its type and legal values
|
|
116
|
+
npx greatstore configure upload <kind> <file> icon | logoLight | logoDark (.png/.jpg/.webp)
|
|
117
|
+
npx greatstore configure clear <kind> remove an uploaded asset
|
|
118
|
+
|
|
119
|
+
npx greatstore connectors [--json] list Maker toggle + custom connectors
|
|
120
|
+
npx greatstore connectors add <name> --url <url> [--token <t>] [--profileUrl <u>]
|
|
121
|
+
[--disabled] [--force]
|
|
122
|
+
npx greatstore connectors remove <name|id>
|
|
123
|
+
npx greatstore connectors enable|disable <name|id>
|
|
124
|
+
npx greatstore connectors maker on|off
|
|
125
|
+
npx greatstore connectors health [<name|id>] [--json]
|
|
126
|
+
|
|
127
|
+
npx greatstore apps <init|build|list|pull|push|publish|unpublish|delete>
|
|
128
|
+
see apps.md for the workflow
|
|
129
|
+
```
|