@salla.sa/twilight 3.0.0-alpha.0 → 3.0.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 +66 -3
- package/dist/@salla.sa/twilight.min.js +1 -19
- package/dist/@salla.sa/twilight.min.js.map +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/package.json +29 -24
- package/types/api/cart/index.d.ts +1 -1
- package/types/api/index.d.ts +7 -1
- package/types/api/loyalty.d.ts +10 -1
- package/types/api/metadata.d.ts +33 -0
- package/types/api/order.d.ts +18 -2
- package/types/api/product/request.d.ts +2 -1
- package/types/api/profile.d.ts +5 -0
- package/types/common.d.ts +20 -1
- package/types/event/auth.d.ts +5 -1
- package/types/event/index.d.ts +3 -0
- package/types/event/loyalty.d.ts +5 -1
- package/types/event/metadata.d.ts +7 -0
- package/types/event/product.d.ts +1 -1
- package/types/index.d.ts +2 -0
- package/types/lib/error-monitor.d.ts +7 -0
- package/types/lib/lang.d.ts +2 -1
- package/types/tiwlight-config.d.ts +229 -18
- package/watcher.js +2 -2
package/README.md
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
<div id="top"></div>
|
|
3
2
|
|
|
4
3
|
<br />
|
|
@@ -49,7 +48,29 @@
|
|
|
49
48
|
|
|
50
49
|
## Overview
|
|
51
50
|
|
|
52
|
-
|
|
51
|
+
The Twilight JS SDK (`@salla.sa/twilight`) is the core package of the Twilight Framework, providing a comprehensive JavaScript interface for Salla's storefront APIs. It enables theme developers to easily communicate with Salla's backend services, handle events, manage state, and build interactive e-commerce experiences.
|
|
52
|
+
|
|
53
|
+
### Architecture
|
|
54
|
+
|
|
55
|
+
The Twilight Framework consists of several packages working together:
|
|
56
|
+
|
|
57
|
+
1. **@salla.sa/base**: Foundation layer with core utilities and services
|
|
58
|
+
2. **@salla.sa/twilight** (this package): Main SDK for Salla themes
|
|
59
|
+
3. **@salla.sa/twilight-components**: Web components for Salla themes
|
|
60
|
+
4. **@salla.sa/twilight-tailwind-theme**: Tailwind CSS theme for Salla themes
|
|
61
|
+
5. **@salla.sa/applepay**: Apple Pay integration for Salla
|
|
62
|
+
|
|
63
|
+
This modular architecture allows for better separation of concerns, more maintainable code, and the ability to use only the parts of the framework that are needed for a specific application.
|
|
64
|
+
|
|
65
|
+
### Key Features
|
|
66
|
+
|
|
67
|
+
- **API Integration**: Pre-built methods for all Salla API endpoints
|
|
68
|
+
- **Event System**: Powerful event handling for real-time updates
|
|
69
|
+
- **Authentication**: Seamless user authentication and session management
|
|
70
|
+
- **Cart Management**: Complete shopping cart functionality
|
|
71
|
+
- **Multilingual Support**: Built-in localization capabilities
|
|
72
|
+
- **Version Management**: Easy access to package versions via `Salla.versions`
|
|
73
|
+
- **Optimized Bundle**: Tree-shakable modules for minimal production builds
|
|
53
74
|
|
|
54
75
|
## Getting Started
|
|
55
76
|
**SDK** stands for "software development kit," and it refers to a library for interacting with a specific REST API using JavaScript.
|
|
@@ -215,6 +236,49 @@ Furthermore, if the required value is nested inside an inner value, such as a cu
|
|
|
215
236
|
salla.config.get('currencies.SAR.code’)
|
|
216
237
|
```
|
|
217
238
|
|
|
239
|
+
#### Accessing Version Information
|
|
240
|
+
|
|
241
|
+
The Twilight Framework provides easy access to version information for all packages through the `Salla.versions` object:
|
|
242
|
+
|
|
243
|
+
```js
|
|
244
|
+
// Get the version of the core package
|
|
245
|
+
console.log(Salla.versions.twilight); // e.g., "v2.14.145"
|
|
246
|
+
|
|
247
|
+
// Get the version of the base package
|
|
248
|
+
console.log(Salla.versions.base); // e.g., "v2.14.143"
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
This is particularly useful for debugging, support, and ensuring compatibility between different parts of the framework.
|
|
252
|
+
|
|
253
|
+
<p align="right">(<a href="#top">back to top</a>)</p>
|
|
254
|
+
|
|
255
|
+
### WebMCP (tools for in-browser AI agents)
|
|
256
|
+
|
|
257
|
+
Twilight can register [WebMCP](https://webmachinelearning.github.io/webmcp/) tools so an AI agent running in the shopper's browser can search, fill the cart and head to checkout. The tools call the regular SDK (`salla.cart.*`, `salla.product.*`) in the shopper's own tab, so they fire the normal cart events and the cart badge and mini-cart update as they would for a click. They never call the `/mcp` worker, whose carts are not the tab's cart.
|
|
258
|
+
|
|
259
|
+
| Tool | Read-only | What it does |
|
|
260
|
+
|------|-----------|--------------|
|
|
261
|
+
| `search_products` | yes | Search the store's products by keyword (`query`, optional `limit`). |
|
|
262
|
+
| `get_product` | yes | Product details by `product_id`. |
|
|
263
|
+
| `get_cart` | yes | The shopper's current cart: items, totals, coupon. |
|
|
264
|
+
| `add_to_cart` | no | Add `product_id` (`quantity`, and `options` keyed by option id for products that need them). |
|
|
265
|
+
| `update_cart_item` | no | Change the quantity of a cart item. |
|
|
266
|
+
| `remove_cart_item` | no | Remove a cart item. |
|
|
267
|
+
| `apply_coupon` | no | Apply a coupon code. |
|
|
268
|
+
| `go_to_checkout` | no | Navigate to checkout (guests go to login first). It only navigates; **it never places an order**, the shopper pays on the checkout page. |
|
|
269
|
+
|
|
270
|
+
Failures come back as `{ isError: true, content: [...] }` with the API's own message.
|
|
271
|
+
|
|
272
|
+
**Off by default.** Stores opt in through the config passed to `Salla.init`:
|
|
273
|
+
|
|
274
|
+
```js
|
|
275
|
+
Salla.init({ store: { id: 1234 }, webmcp: { enabled: true } });
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
Only the boolean `true` (or `'true'` / `1`) turns it on. Salla Store renders this value for you from `TWILIGHT_WEBMCP_ENABLED` (all stores) or the `themes::webmcp.enabled` store setting; set it back to `false` to switch the tools off. No Twilight release is involved.
|
|
279
|
+
|
|
280
|
+
**Browser support.** Needs a browser that implements WebMCP and an HTTPS page. It looks for `document.modelContext` first, then `navigator.modelContext`, and does nothing when neither exists (all other browsers, including current Firefox and Safari) or on HTTP. In Chrome 146+ the API is behind the `chrome://flags/#enable-webmcp-testing` flag ("WebMCP for testing"). Registering the same tool twice (for example when init runs twice) is tolerated.
|
|
281
|
+
|
|
218
282
|
<p align="right">(<a href="#top">back to top</a>)</p>
|
|
219
283
|
|
|
220
284
|
## Support
|
|
@@ -251,4 +315,3 @@ You can also simply open an issue with the tag "enhancement". Don't forget to gi
|
|
|
251
315
|
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
|
|
252
316
|
|
|
253
317
|
<p align="right">(<a href="#top">back to top</a>)</p>
|
|
254
|
-
|