@salla.sa/twilight 2.0.283 → 2.0.285

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 CHANGED
@@ -1,12 +1,216 @@
1
- # Salla Twilight
2
1
 
2
+ <div id="top"></div>
3
3
 
4
- ### Events `salla.event` base on [EventEmitter2](https://github.com/EventEmitter2/EventEmitter2)
4
+ <br />
5
+ <div align="center">
6
+ <a href="https://salla.dev">
7
+ <img src="https://salla.dev/wp-content/themes/salla-portal/dist/img/salla-logo.svg" alt="Logo" width="80" height="80">
8
+ </a>
9
+ <h1 align="center">Twilight JS APIs</h1>
10
+ <p align="center">
11
+ A JavaScript SDK for the Salla storefront APIs provides helper methods, or REST API endpoints, that allow communication between the frontend and backend.
12
+ <br />
13
+ <a href="https://salla.dev/"><strong>Explore our blogs »</strong></a>
14
+ <br />
15
+ <br />
16
+ <a href="https://github.com/SallaApp/Salla-CLI/issues/new">Report Bug</a> ·
17
+ <a href="https://github.com/SallaApp/Salla-CLI/discussions/new">Request Feature</a> .
18
+ <a href="https://t.me/salladev">&lt;/Salla Developers&gt;</a> .
19
+ <a href="https://salla.stoplight.io/docs/twilight-themes-documentation/3ac843cae76a2-overview">Official Documentation</a>
20
+ </p>
21
+ </div>
5
22
 
23
+ <!-- TABLE OF CONTENTS -->
24
+ <details open>
25
+ <summary>Table of Contents</summary>
26
+ <ol>
27
+ <li>
28
+ <a href="#overview">Overview</a>
29
+ </li>
30
+ <li>
31
+ <a href="#getting-started">Getting Started</a>
32
+ <ul>
33
+ <li><a href="#sdks-main-apis">SDK's main APIs</a></li>
34
+ <li><a href="#use-cases">Use cases</a></li>
35
+ </ul>
36
+ <li><a href="#installation">Installation</a></li>
37
+ <ul>
38
+ <li><a href="#initialization">Initialization</a></li>
39
+ </ul>
40
+ <li><a href="#usage">Usage</a></li>
41
+ <ul>
42
+ <li><a href="#basic-configuration">Basic configuration </a></li>
43
+ </ul>
44
+ <li><a href="#support">Support</a></li>
45
+ <li><a href="#contributing">Contributing</a></li>
46
+ <li><a href="#credits">Credits</a></li>
47
+ <li><a href="#license">License</a></li>
48
+ </li>
49
+ </ol>
50
+ </details>
51
+ <!-- Overview -->
6
52
 
53
+ ## Overview
7
54
 
8
- # Installing
55
+ **Twilight** comes with a **JavaScript SDK** for the Salla storefront APIs. This is to provide the developers with helper methods, or REST API endpoints, that allow communication between the frontend and backend. As a result, developers may use these methods to make merchants' stores dynamic after using the API features and data. In this documentation, we will be referring to it as **Twilight JS SDK** for short.
9
56
 
57
+ ## Getting Started
58
+ **SDK** stands for "software development kit," and it refers to a library for interacting with a specific REST API using JavaScript.
59
+
60
+ ### SDK's main APIs
61
+ The main parts of the **Twilight JS SDK** includes REST API endpoints that ease the actions related to the APIs request, such as:
62
+ - **Authorization APIs:** Several endpoints for customer logging in, logging out, and many more.
63
+ - **Cart APIs:** Customer's cart list of endpoints.
64
+ - **Comments APIs:** Group of endpoints related to the customer comments, or feedback, on product or page.
65
+ - **Currency APIs:** Group of endpoints related to the store's currencies list.
66
+ - **Order APIs:** Customer's orders related endpoints.
67
+ - **Product APIs**: Product related endpoints.
68
+ - **Profile APIs:** Customer's profile endpoints.
69
+ - **Rating APIs:** endpoints related to the store, product, order, shipping rating.
70
+ - **Wishlist APIs:** Customer's wishlist endpoints.
71
+
72
+ ### Use cases
73
+ Following are some of the possible uses of the Twilight JS SDK:
74
+ - Authenticating customers and allowing them to edit account details.
75
+ - Adding a product directly from the products list to the customer art.
76
+ - Returning the price of a product.
77
+ - Adding a product to the customer's wishlist.
78
+ - Rating the shipping company responsible for delivering orders.
79
+ - And many more!
80
+
81
+ <p align="right">(<a href="#top">back to top</a>)</p>
82
+
83
+ ## Installation
84
+ **Twilight JS SDK** can be installed from the `npm` using the following commands:
85
+
86
+ ```npm title="NPM Installation Command"
87
+ npm install @salla.sa/twilight-js --save
88
+ ```
89
+
90
+ ```yarn title="Yarn Installation Command"
91
+ yarn add @salla.sa/twilight-js
92
+ ```
93
+
94
+ ### Initialization
95
+
96
+ The following snippet of code will give the basic version of the SDK where the configurations are set to their minimum requirements, for example, store URL. The method `salla.init()` is used to setup and initialize the SDK.
97
+
98
+ ```js
99
+ <script>
100
+ let url = "https://my_store.test/";
101
+ salla.init({debug: true, store: {api: url + "api/v1/", url: url}});
102
+ </script>
103
+ ```
104
+ <p align="right">(<a href="#top">back to top</a>)</p>
105
+
106
+ ## Usage
107
+
108
+ As a result of the SDK initialization, the developer will be able to use any of the SDK's main APIs. For example, the method `addItem` adds an item into the cart, the developer may call the method `addItem` as follows:
109
+
110
+ ```js
111
+ salla.cart.addItem({
112
+ id: 1234,
113
+ quantity: 1,
114
+ notes: "please i need to get the red color"
115
+ }).then((response) => {
116
+ /* add your code here */
117
+ });
118
+ ```
119
+ In addition to the above example, the method `addItem` may adds an item with multiple options to the carts as follows:
120
+ ```js
121
+ salla.cart.addItem({
122
+ id: 1234,
123
+ quantity: 1,
124
+ options: {
125
+ 117414452: 11232214, // option value id (select choice)
126
+ 117416632: "http://option-value-as-url-of-image.com",
127
+ 117411132: "option value as string"
128
+ },
129
+ notes: "please i need to get the red color"
130
+ }).then((response) => {
131
+ /* add your code here */
132
+ });
133
+ ```
134
+
135
+ Furthermore, a large number of store events will be available for use. Thus, the developer's theme may be configured to respond automatically to a variety of activities, such as:
136
+
137
+ - The user requested an Access Code to perform a login, however, the code was not sent. For this scenario, using the method `salla.event.auth.onCodeNotSent()` can be used.
138
+
139
+ - A new item has been added to the cart via the `salla.cart.event.onItemAdded()` method.
140
+
141
+ - The user added a new item to the Wishlist using the method `salla.event.wishlist.onAdded()`.
142
+
143
+ Full example for that would be the event `onItemAdded` which is triggered when adding an item to the cart is done without having any errors coming back from the backend:
144
+ ```js
145
+ salla.cart.event.onItemAdded((response) => {
146
+ console.log(response)
147
+ });
148
+ ```
149
+ On the over hand, the event `onItemAddedFailed` is triggered when adding an item to the cart is not completed and an error has occurred. For example, the id of the product to be added to the cart was not found.
150
+ ```js
151
+ salla.cart.event.onItemAddedFailed((errorMessage) => {
152
+ console.log(errorMessage)
153
+ });
154
+ ```
155
+
156
+
157
+ ### Basic configuration
158
+
159
+ Aside from calling the APIs, the developer has the ability to configure the Twilight engine to meet the needs of his theme. This list of the available configurations can be found in this [article](https://salla.stoplight.io/docs/twilight-themes-documentation/ZG9jOjQ4OTE2NDQ5-configuration). For this purpose, the method `salla.config.get()` is used to retrieve a configuration value, while `salla.config.set()` is used to set a configuration value.
160
+
161
+ #### Set configuration value
162
+ The developer may set the debug mode to be activated. That is to state, the theme will be run in a debugger. This means that the debugger keeps track of everything that happens while the theme is running.
163
+
164
+ ```js
165
+ salla.config.set('debug', true)
166
+ ```
167
+
168
+ #### Get configuration value
169
+ Similarly, the developer can use the method'salla.config.get()' to get any value from the configuration file. To retrive simaple value such as the user Id, the following syntax can be followed:
170
+
171
+ ```js
172
+ salla.config.get('user.id’)
10
173
  ```
11
- npm install @salla.sa/twiglight
174
+
175
+ Furthermore, if the required value is nested inside an inner value, such as a currency code, the following syntax can be followed:
176
+
177
+ ```js
178
+ salla.config.get('curremcies.SAR.code’)
12
179
  ```
180
+
181
+ <p align="right">(<a href="#top">back to top</a>)</p>
182
+
183
+ ## Support
184
+
185
+ The team is always here to help you. Happen to face an issue? Want to report a bug? You can submit one here on Github using the [Issue Tracker](https://github.com/SallaApp/twilight-vscode-extension/issues/new). If you still have any questions, please contact us via the [Telegram Bot](https://t.me/SallaSupportBot) or join in the Global Developer Community on [Telegram](https://t.me/salladev).
186
+
187
+ <p align="right">(<a href="#top">back to top</a>)</p>
188
+
189
+ ## Contributing
190
+
191
+ Contributions are what make the open-source community such an amazing place to learn, inspire, and create.
192
+ Any contributions you make are **greatly appreciated**.
193
+
194
+ If you have a suggestion that would make this better, please fork the repo and create a pull request.
195
+ You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
196
+
197
+ 1. Fork the Project
198
+ 2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
199
+ 3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
200
+ 4. Push to the Branch (`git push origin feature/AmazingFeature`)
201
+ 5. Open a Pull Request
202
+
203
+ <p align="right">(<a href="#top">back to top</a>)</p>
204
+
205
+ ## Credits
206
+
207
+ - [Salla](https://github.com/sallaApp)
208
+ - [All Contributors](../../contributors)
209
+
210
+ <p align="right">(<a href="#top">back to top</a>)</p>
211
+
212
+ ## License
213
+
214
+ The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
215
+
216
+ <p align="right">(<a href="#top">back to top</a>)</p>