@garchicms/garchi-node-sdk 0.0.1

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/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Garchi CMS
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,269 @@
1
+ ## 📖 Table of Contents
2
+
3
+ - [📖 Table of Contents](#-table-of-contents)
4
+ - [GarchiCMS SDK](#garchicms-sdk)
5
+ - [Features](#features)
6
+ - [Installation](#installation)
7
+ - [Usage](#usage)
8
+ - [Importing the SDK](#importing-the-sdk)
9
+ - [Initializing the Client](#initializing-the-client)
10
+ - [Module mapping](#module-mapping)
11
+ - [Example usages](#example-usages)
12
+ - [Data item API](#data-item-api)
13
+ - [Create a Data Item](#create-a-data-item)
14
+ - [Get All Items](#get-all-items)
15
+ - [Category API](#category-api)
16
+ - [Create a Category](#create-a-category)
17
+ - [Get All Categories](#get-all-categories)
18
+ - [Review API](#review-api)
19
+ - [Create a Review](#create-a-review)
20
+ - [Reaction API](#reaction-api)
21
+ - [Add or Update Reaction](#add-or-update-reaction)
22
+ - [Space API](#space-api)
23
+ - [Create a Space](#create-a-space)
24
+ - [Compound Query API](#compound-query-api)
25
+ - [Perform a Compound Query](#perform-a-compound-query)
26
+ - [Headless CMS API](#headless-cms-api)
27
+ - [Get a Page](#get-a-page)
28
+ - [Error Handling](#error-handling)
29
+ - [Types and Interfaces](#types-and-interfaces)
30
+ - [Contributing](#contributing)
31
+ - [License](#license)
32
+
33
+ ## GarchiCMS SDK
34
+
35
+ GarchiCMS SDK is a TypeScript library for interacting with the Garchi CMS API. It provides a simple, modular, and intuitive interface for managing categories, data items, reviews, reactions, spaces, and headless web APIs.
36
+
37
+ You can find the API documentation [here](https://garchi.co.uk/docs/v2)
38
+
39
+
40
+ ## Features
41
+
42
+ - Manage **Data Items**: Create, update, delete, and fetch data items.
43
+ - Handle **Categories**: Create, update, delete, and list categories.
44
+ - Manage **Spaces**: Create, update, and fetch spaces.
45
+ - Handle **Reviews**: Create, update, delete, and fetch reviews.
46
+ - Manage **Reactions**: Add or remove reactions for items or reviews.
47
+ - Perform **Compound Queries**: Execute complex queries across items, categories, and reviews.
48
+ - Work with **Headless CMS**: Manage assets, pages, and section templates.
49
+
50
+ ## Installation
51
+
52
+ ```bash
53
+ npm install @garchicms/garchi-node-sdk
54
+ ```
55
+
56
+ ## Usage
57
+
58
+ This SDK is a wrapper around the [Garchi CMS API](https://garchi.co.uk/docs/v2). providing easy-to-use modular functions that map directly to API endpoints.
59
+
60
+
61
+
62
+
63
+
64
+ ### Importing the SDK
65
+
66
+ ```typescript
67
+ import GarchiCMS from '@garchicms/garchi-node-sdk';
68
+ ```
69
+
70
+ ### Initializing the Client
71
+
72
+ ```typescript
73
+ const garchi = new GarchiCMS({ api_key: 'YOUR_API_KEY' });
74
+ ```
75
+
76
+ ### Module mapping
77
+
78
+ Each module corresponds to a specific API group:
79
+
80
+ - garchi.dataItem → Data Item/Items API
81
+ - garchi.dataItem.create() corresponds to [Create data item API](https://garchi.co.uk/docs/v2#item-POSTapi-v2-item)
82
+ - garchi.dataItem.update() corresponds to [Update data item API](https://garchi.co.uk/docs/v2#item-POSTapi-v2-update-item)
83
+ - garchi.dataItem.delete() corresponds to [Delete data item API](https://garchi.co.uk/docs/v2#item-POSTapi-v2-delete-item)
84
+ - garchi.dataItem.createMetaInfo() corresponds to [Create meta info for item API](https://garchi.co.uk/docs/v2#item-POSTapi-v2-item_meta)
85
+ - garchi.dataItem.deleteMetaInfo() corresponds to [Delete meta info for item API](https://garchi.co.uk/docs/v2#item-POSTapi-v2-delete-item_meta)
86
+ - garchi.dataItem.updateMetaInfo() corresponds to [Update meta info for item API](https://garchi.co.uk/docs/v2#item-POSTapi-v2-update-item_meta)
87
+ - garchi.dataItem.getBySpace() corresponds to [Get items by space API](https://garchi.co.uk/docs/v2#item-GETapi-v2-space--uid--items)
88
+ - garchi.dataItem.semanticSearch() corresponds to [Semantic item search API](https://garchi.co.uk/docs/v2#item-GETapi-v2-items-semantic-search)
89
+ - garchi.dataItem.featured() corresponds to [Get featured items API](https://garchi.co.uk/docs/v2#item-GETapi-v2-items-featured)
90
+ - garchi.dataItem.get() corresponds to [Get data item API](https://garchi.co.uk/docs/v2#item-GETapi-v2-item--item-)
91
+ - garchi.dataItem.getAll() corresponds to [Get all data items API](https://garchi.co.uk/docs/v2#item-GETapi-v2-items)
92
+ - garchi.dataItem.filter() corresponds to [Filter data items API](https://garchi.co.uk/docs/v2#item-POSTapi-v2-items-filter)
93
+ - garchi.dataItem.filterByMeta() corresponds to [Filter data items by meta information API](https://garchi.co.uk/docs/v2#item-POSTapi-v2-items-filter-bymeta)
94
+ - garchi.dataItem.getByIds() corresponds to [Get data items by IDs API](https://garchi.co.uk/docs/v2#item-POSTapi-v2-items-byids)
95
+
96
+
97
+ - garchi.category → Category API
98
+ - garchi.category.create() corresponds to [Create cateogry API](https://garchi.co.uk/docs/v2#category-POSTapi-v2-category)
99
+ - garchi.category.update() corresponds to [Update category API](https://garchi.co.uk/docs/v2#category-POSTapi-v2-update-category--category_id-)
100
+ - garchi.category.delete() corresponds to [Delete category API](https://garchi.co.uk/docs/v2#category-POSTapi-v2-delete-category--space_uid---category_id-)
101
+ - garchi.category.getAll() corresponds to [Get all categories API](https://garchi.co.uk/docs/v2#category-GETapi-v2-categories)
102
+
103
+
104
+ - garchi.space → Space API
105
+ - garchi.space.create() corresponds to [Create a space API](https://garchi.co.uk/docs/v2#spaces-POSTapi-v2-space)
106
+ - garchi.space.update() corresponds to [Update a space API](https://garchi.co.uk/docs/v2#spaces-POSTapi-v2-update-space--uid-)
107
+ - garchi.space.delete() corresponds to [Delete a space API](https://garchi.co.uk/docs/v2#spaces-POSTapi-v2-delete-space--uid-)
108
+ - garchi.space.getAll() corresponds to [Get all spaces API](https://garchi.co.uk/docs/v2#spaces-GETapi-v2-spaces)
109
+ - garchi.space.get() corresponds to [Get space details API](https://garchi.co.uk/docs/v2#spaces-GETapi-v2-space--uid-)
110
+ - garchi.space.categories() corresponds to [Get categories for space API](https://garchi.co.uk/docs/v2#category-GETapi-v2-space--uid--categories)
111
+
112
+
113
+ - garchi.review → Review API
114
+ - garchi.review.create() corresponds to [Create a review API](https://garchi.co.uk/docs/v2#reviews-POSTapi-v2-reviews-item)
115
+ - garchi.review.update() corresponds to [Update review API](https://garchi.co.uk/docs/v2#reviews-POSTapi-v2-reviews-edit)
116
+ - garchi.review.delete() corresponds to [Delete review API](https://garchi.co.uk/docs/v2#reviews-POSTapi-v2-reviews-delete)
117
+ - garchi.review.getByItem() corresponds to [Get reviews for an item API](https://garchi.co.uk/docs/v2#reviews-GETapi-v2-reviews-item--item-)
118
+
119
+
120
+ - garchi.headless → Headless API
121
+ - garchi.headless.getAsset() corresponds to [Get asset file for space API](https://garchi.co.uk/docs/v2#headless-web-GETapi-v2-space-assets--name-)
122
+ - garchi.headless.getPage() corresponds to [Get page content API](https://garchi.co.uk/docs/v2#headless-web-POSTapi-v2-page)
123
+ - garchi.headless.createOrUpdateSectionTemplates() corresponds to [Create or update section templates API](https://garchi.co.uk/docs/v2#headless-web-POSTapi-v2-section_template)
124
+
125
+
126
+ - garchi.reaction → Reaction API
127
+ - garchi.reaction.manage() corresponds to [Reaction API](https://garchi.co.uk/docs/v2#reaction-POSTapi-v2-manage-reaction)
128
+
129
+
130
+ - garchi.compoundQuery → Compound Query API
131
+ - garchi.compoundQuery.query() corresponds to [Compound query API](https://garchi.co.uk/docs/v2#compound-query-POSTapi-v2-compound_query)
132
+
133
+
134
+ Each module return values corresponds to the return value of the respective API Endpoint. The only difference being the excluding the paginated API endpoints, each module return value can be accessed without the `.data` attribute.
135
+
136
+ ## Example usages
137
+
138
+ Here are some example usages
139
+
140
+ ### Data item API
141
+
142
+ #### Create a Data Item
143
+
144
+ ```typescript
145
+ const newItem = await garchi.dataItem.create({
146
+ space_uid: 'your_space_uid',
147
+ name: 'New Item',
148
+ categories: [1, 2, 3],
149
+ });
150
+ ```
151
+
152
+ #### Get All Items
153
+
154
+ ```typescript
155
+ const items = await client.dataItem.getAll({ size: 10 });
156
+ ```
157
+
158
+ ### Category API
159
+
160
+ #### Create a Category
161
+
162
+ ```typescript
163
+ const newCategory = await client.category.create({
164
+ category: 'New Category',
165
+ space_uid: 'your_space_uid'
166
+ });
167
+ ```
168
+
169
+ #### Get All Categories
170
+
171
+ ```typescript
172
+ const categories = await client.category.getAll();
173
+ ```
174
+
175
+ ### Review API
176
+
177
+ #### Create a Review
178
+
179
+ ```typescript
180
+ const review = await client.review.create({
181
+ item_id: 1,
182
+ rating: 5,
183
+ review_body: 'Excellent product!',
184
+ user_email: 'user@example.com',
185
+ user_name: 'John Doe'
186
+ });
187
+ ```
188
+
189
+ ### Reaction API
190
+
191
+ #### Add or Update Reaction
192
+
193
+ ```typescript
194
+ const reaction = await client.reaction.manage({
195
+ reaction: 'like',
196
+ user_identifier: 'user@example.com',
197
+ review_id: 1,
198
+ item_id: 1,
199
+ reaction_for: 'review'
200
+ });
201
+ ```
202
+
203
+ ### Space API
204
+
205
+ #### Create a Space
206
+
207
+ ```typescript
208
+ const newSpace = await client.space.create({
209
+ name: 'New Space',
210
+ logo: yourLogoFile
211
+ });
212
+ ```
213
+
214
+ ### Compound Query API
215
+
216
+ #### Perform a Compound Query
217
+
218
+ ```typescript
219
+ const queryResult = await client.compoundQuery.query({
220
+ dataset: 'items',
221
+ fields: ['name', 'price'],
222
+ conditions: ['like', 'gte'],
223
+ values: ['%item%', '10'],
224
+ logic: ['and']
225
+ }, { order_key: 'name', order_by: 'asc' });
226
+ ```
227
+
228
+ ### Headless CMS API
229
+
230
+ #### Get a Page
231
+
232
+ ```typescript
233
+ const page = await client.headless.getPage({
234
+ space_uid: 'your_space_uid',
235
+ slug: '/',
236
+ lang: 'en-US',
237
+ mode: 'live'
238
+ });
239
+ ```
240
+
241
+ ## Error Handling
242
+
243
+ All API calls return promises and throw errors if the API call fails.
244
+
245
+ ```typescript
246
+ try {
247
+ const item = await client.dataItem.getItem({ item: 1 });
248
+ console.log(item);
249
+ } catch (error) {
250
+ console.error('Error:', error);
251
+ }
252
+ ```
253
+
254
+ ## Types and Interfaces
255
+
256
+ The SDK exports types and interfaces for better TypeScript support.
257
+
258
+ ```typescript
259
+ import { GarchiItem, GarchiCategory, GarchiReview } from '@garchicms/garchi-sdk-node';
260
+ ```
261
+
262
+ ## Contributing
263
+
264
+ Feel free to submit issues and pull requests to improve the SDK.
265
+
266
+ ## License
267
+
268
+ This project is licensed under the MIT License.
269
+