@hellena-sdk/hellena 1.0.6 → 1.0.8
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 +279 -50
- package/dist/core/HellenaConnect.d.ts +27 -2
- package/dist/main.d.ts +15 -3
- package/dist/main.js +384 -38
- package/dist/resources/category/category.feature.d.ts +10 -0
- package/dist/resources/category/category.model.d.ts +3 -0
- package/dist/resources/category/dto/category.dto.d.ts +26 -0
- package/dist/resources/category/service/category.ser.d.ts +8 -0
- package/dist/resources/comment/comment.feature.d.ts +22 -0
- package/dist/resources/comment/comment.model.d.ts +3 -0
- package/dist/resources/comment/dto/comment.dto.d.ts +31 -0
- package/dist/resources/comment/service/comment.ser.d.ts +17 -0
- package/dist/resources/order/dto/order.dto.d.ts +57 -52
- package/dist/resources/order/order.feature.d.ts +12 -3
- package/dist/resources/order/order.model.d.ts +1 -2
- package/dist/resources/order/service/order.ser.d.ts +8 -3
- package/dist/resources/organization/dto/organization.dto.d.ts +0 -1
- package/dist/resources/organization/organization.feature.d.ts +4 -3
- package/dist/resources/organization/organization.model.d.ts +0 -1
- package/dist/resources/organization/service/organization.ser.d.ts +0 -1
- package/dist/resources/payment/dto/payment.dto.d.ts +14 -0
- package/dist/resources/payment/payment.feature.d.ts +10 -0
- package/dist/resources/payment/payment.model.d.ts +3 -0
- package/dist/resources/payment/service/payment.ser.d.ts +8 -0
- package/dist/resources/product/dto/product.dto.d.ts +59 -4
- package/dist/resources/product/product.feature.d.ts +27 -6
- package/dist/resources/product/product.model.d.ts +1 -2
- package/dist/resources/product/service/product.ser.d.ts +5 -4
- package/dist/resources/rating/dto/rating.dto.d.ts +52 -0
- package/dist/resources/rating/rating.feature.d.ts +29 -0
- package/dist/resources/rating/rating.model.d.ts +3 -0
- package/dist/resources/rating/service/rating.ser.d.ts +24 -0
- package/package.json +5 -3
- package/dist/core/HellenaConnect.d.ts.map +0 -1
- package/dist/main.d.ts.map +0 -1
- package/dist/resources/order/dto/order.dto.d.ts.map +0 -1
- package/dist/resources/order/order.feature.d.ts.map +0 -1
- package/dist/resources/order/order.model.d.ts.map +0 -1
- package/dist/resources/order/service/order.ser.d.ts.map +0 -1
- package/dist/resources/organization/dto/organization.dto.d.ts.map +0 -1
- package/dist/resources/organization/organization.feature.d.ts.map +0 -1
- package/dist/resources/organization/organization.model.d.ts.map +0 -1
- package/dist/resources/organization/service/organization.ser.d.ts.map +0 -1
- package/dist/resources/product/dto/product.dto.d.ts.map +0 -1
- package/dist/resources/product/product.feature.d.ts.map +0 -1
- package/dist/resources/product/product.model.d.ts.map +0 -1
- package/dist/resources/product/service/product.ser.d.ts.map +0 -1
package/dist/main.js
CHANGED
|
@@ -1,22 +1,100 @@
|
|
|
1
1
|
// src/core/HellenaConnect.ts
|
|
2
|
+
class HellenaAPIError extends Error {
|
|
3
|
+
status;
|
|
4
|
+
response;
|
|
5
|
+
path;
|
|
6
|
+
constructor(message, status, path, response) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = "HellenaAPIError";
|
|
9
|
+
this.status = status;
|
|
10
|
+
this.path = path;
|
|
11
|
+
this.response = response;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
2
15
|
class HellenaConnect {
|
|
3
16
|
apiKey;
|
|
4
17
|
apiUrl;
|
|
5
18
|
apiVersion;
|
|
6
|
-
|
|
19
|
+
timeout;
|
|
20
|
+
constructor(apiKey, options = {}) {
|
|
7
21
|
this.apiKey = apiKey;
|
|
8
|
-
|
|
9
|
-
|
|
22
|
+
if (!apiKey?.trim()) {
|
|
23
|
+
throw new Error("A API Key da Hellena é obrigatória.");
|
|
24
|
+
}
|
|
25
|
+
this.apiUrl = (options.apiUrl ?? "https://api.hellena.app").replace(/\/+$/, "");
|
|
26
|
+
this.apiVersion = (options.apiVersion ?? "v1").replace(/^\/+|\/+$/g, "");
|
|
27
|
+
this.timeout = options.timeout ?? 30000;
|
|
10
28
|
}
|
|
11
29
|
get apiEndpoint() {
|
|
12
30
|
return `${this.apiUrl}/${this.apiVersion}`;
|
|
13
31
|
}
|
|
14
32
|
getHeaders() {
|
|
15
33
|
return {
|
|
34
|
+
Accept: "application/json",
|
|
16
35
|
"Content-Type": "application/json",
|
|
17
36
|
"x-hellena-api-key": this.apiKey
|
|
18
37
|
};
|
|
19
38
|
}
|
|
39
|
+
async sendRestRequest(path, options = {}) {
|
|
40
|
+
const normalizedPath = path.replace(/^\/+/, "");
|
|
41
|
+
const url = new URL(`${this.apiEndpoint}/${normalizedPath}`);
|
|
42
|
+
for (const [key, value] of Object.entries(options.query ?? {})) {
|
|
43
|
+
if (value !== undefined && value !== null)
|
|
44
|
+
url.searchParams.set(key, String(value));
|
|
45
|
+
}
|
|
46
|
+
const controller = new AbortController;
|
|
47
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
48
|
+
const externalSignal = options.signal;
|
|
49
|
+
const abortFromExternal = () => controller.abort();
|
|
50
|
+
externalSignal?.addEventListener("abort", abortFromExternal, { once: true });
|
|
51
|
+
try {
|
|
52
|
+
const response = await fetch(url, {
|
|
53
|
+
method: options.method ?? "GET",
|
|
54
|
+
headers: { ...this.getHeaders(), ...options.headers },
|
|
55
|
+
...options.body !== undefined ? { body: JSON.stringify(options.body) } : {},
|
|
56
|
+
signal: externalSignal?.aborted ? externalSignal : controller.signal
|
|
57
|
+
});
|
|
58
|
+
const raw = await response.text();
|
|
59
|
+
let data = undefined;
|
|
60
|
+
if (raw) {
|
|
61
|
+
try {
|
|
62
|
+
data = JSON.parse(raw);
|
|
63
|
+
} catch {
|
|
64
|
+
data = raw;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (!response.ok) {
|
|
68
|
+
const payload = data;
|
|
69
|
+
const message = Array.isArray(payload?.message) ? payload.message.join(", ") : typeof payload?.message === "string" ? payload.message : typeof payload?.error === "string" ? payload.error : `Pedido à Hellena falhou (${response.status} ${response.statusText})`;
|
|
70
|
+
throw new HellenaAPIError(message, response.status, url.toString(), data);
|
|
71
|
+
}
|
|
72
|
+
return data;
|
|
73
|
+
} catch (error) {
|
|
74
|
+
if (error instanceof HellenaAPIError)
|
|
75
|
+
throw error;
|
|
76
|
+
if (controller.signal.aborted) {
|
|
77
|
+
throw new Error(`O pedido à Hellena excedeu o limite de ${this.timeout} ms ou foi cancelado.`, { cause: error });
|
|
78
|
+
}
|
|
79
|
+
throw new Error(`Não foi possível comunicar com a API Hellena: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
80
|
+
} finally {
|
|
81
|
+
clearTimeout(timeoutId);
|
|
82
|
+
externalSignal?.removeEventListener("abort", abortFromExternal);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
async graphql(query, variables) {
|
|
86
|
+
const response = await fetch(`${this.apiUrl}/graphql`, {
|
|
87
|
+
method: "POST",
|
|
88
|
+
headers: this.getHeaders(),
|
|
89
|
+
body: JSON.stringify({ query, variables })
|
|
90
|
+
});
|
|
91
|
+
const payload = await response.json();
|
|
92
|
+
if (!response.ok || payload.errors?.length) {
|
|
93
|
+
const message = payload.errors?.map((item) => item.message ?? "Erro GraphQL").join("; ") ?? `Pedido GraphQL falhou (${response.status})`;
|
|
94
|
+
throw new HellenaAPIError(message, response.status, `${this.apiUrl}/graphql`, payload);
|
|
95
|
+
}
|
|
96
|
+
return payload.data;
|
|
97
|
+
}
|
|
20
98
|
}
|
|
21
99
|
|
|
22
100
|
// src/resources/order/service/order.ser.ts
|
|
@@ -25,20 +103,20 @@ class OrderService {
|
|
|
25
103
|
constructor(connect) {
|
|
26
104
|
this.connect = connect;
|
|
27
105
|
}
|
|
28
|
-
|
|
29
|
-
|
|
106
|
+
make({ data }) {
|
|
107
|
+
return this.connect.sendRestRequest("orders/new", {
|
|
30
108
|
method: "POST",
|
|
31
|
-
|
|
32
|
-
body: JSON.stringify(data)
|
|
109
|
+
body: data
|
|
33
110
|
});
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
111
|
+
}
|
|
112
|
+
renewTransactionId(id) {
|
|
113
|
+
return this.connect.sendRestRequest(`orders/${encodeURIComponent(id)}/renew-transaction`, { method: "POST" });
|
|
114
|
+
}
|
|
115
|
+
getFrete(payload) {
|
|
116
|
+
return this.connect.sendRestRequest("orders/checkout/frete", { method: "POST", body: payload });
|
|
117
|
+
}
|
|
118
|
+
calculateCouponDiscount(payload) {
|
|
119
|
+
return this.connect.sendRestRequest("orders/checkout/coupon-discount", { method: "POST", body: payload });
|
|
42
120
|
}
|
|
43
121
|
}
|
|
44
122
|
|
|
@@ -48,9 +126,17 @@ class OrderFeature {
|
|
|
48
126
|
constructor(service) {
|
|
49
127
|
this.service = service;
|
|
50
128
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
129
|
+
createOrder(data) {
|
|
130
|
+
return this.service.make({ data });
|
|
131
|
+
}
|
|
132
|
+
renewOrderTransactionId(id) {
|
|
133
|
+
return this.service.renewTransactionId(id);
|
|
134
|
+
}
|
|
135
|
+
calculateShippingCost(data) {
|
|
136
|
+
return this.service.getFrete(data);
|
|
137
|
+
}
|
|
138
|
+
calculateCouponDiscount(data) {
|
|
139
|
+
return this.service.calculateCouponDiscount(data);
|
|
54
140
|
}
|
|
55
141
|
}
|
|
56
142
|
|
|
@@ -66,58 +152,318 @@ class ProductService {
|
|
|
66
152
|
constructor(connect) {
|
|
67
153
|
this.connect = connect;
|
|
68
154
|
}
|
|
69
|
-
|
|
70
|
-
|
|
155
|
+
getAllProducts(params = {}) {
|
|
156
|
+
return this.connect.sendRestRequest("products/all", { query: this.toQuery(params) });
|
|
157
|
+
}
|
|
158
|
+
searchProducts(params) {
|
|
159
|
+
const { ref, ...filters } = params;
|
|
160
|
+
return this.connect.sendRestRequest("products/search", {
|
|
161
|
+
query: { ...this.toQuery(filters), ...ref ? { ref } : {} }
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
getProductById(id) {
|
|
165
|
+
return this.connect.sendRestRequest(`products/${encodeURIComponent(id)}`);
|
|
166
|
+
}
|
|
167
|
+
toQuery(params) {
|
|
168
|
+
const list = (value) => Array.isArray(value) ? value.join(",") : value;
|
|
169
|
+
return {
|
|
170
|
+
page: params.page,
|
|
171
|
+
limit: params.limit,
|
|
172
|
+
q: params.q,
|
|
173
|
+
category: params.category,
|
|
174
|
+
color: list(params.color),
|
|
175
|
+
brand: params.brand,
|
|
176
|
+
model: list(params.model),
|
|
177
|
+
material: list(params.material),
|
|
178
|
+
size: list(params.size),
|
|
179
|
+
tags: list(params.tags),
|
|
180
|
+
gender: list(params.gender),
|
|
181
|
+
minPrice: params.minPrice,
|
|
182
|
+
maxPrice: params.maxPrice,
|
|
183
|
+
inStock: params.inStock,
|
|
184
|
+
sortBy: params.sortBy,
|
|
185
|
+
sortOrder: params.sortOrder
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// src/resources/product/product.feature.ts
|
|
191
|
+
class ProductFeature {
|
|
192
|
+
service;
|
|
193
|
+
constructor(service) {
|
|
194
|
+
this.service = service;
|
|
195
|
+
}
|
|
196
|
+
listProducts(params = {}) {
|
|
197
|
+
this.validatePriceRange(params);
|
|
198
|
+
return this.service.getAllProducts(params);
|
|
199
|
+
}
|
|
200
|
+
filterProducts(filters = {}) {
|
|
201
|
+
return this.listProducts(filters);
|
|
202
|
+
}
|
|
203
|
+
searchProducts(params = {}) {
|
|
204
|
+
this.validatePriceRange(params);
|
|
205
|
+
return this.service.searchProducts(params);
|
|
206
|
+
}
|
|
207
|
+
getProductByIdOrSlug(id) {
|
|
208
|
+
if (!id?.trim()) {
|
|
209
|
+
throw new Error("O ID ou slug do produto é obrigatório.");
|
|
210
|
+
}
|
|
211
|
+
return this.service.getProductById(id.trim());
|
|
212
|
+
}
|
|
213
|
+
validatePriceRange(params) {
|
|
214
|
+
const { minPrice, maxPrice } = params;
|
|
215
|
+
if (minPrice !== undefined && (!Number.isFinite(minPrice) || minPrice < 0)) {
|
|
216
|
+
throw new Error("minPrice deve ser um número maior ou igual a zero.");
|
|
217
|
+
}
|
|
218
|
+
if (maxPrice !== undefined && (!Number.isFinite(maxPrice) || maxPrice < 0)) {
|
|
219
|
+
throw new Error("maxPrice deve ser um número maior ou igual a zero.");
|
|
220
|
+
}
|
|
221
|
+
if (minPrice !== undefined && maxPrice !== undefined && minPrice > maxPrice) {
|
|
222
|
+
throw new Error("minPrice não pode ser superior a maxPrice.");
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// src/resources/product/product.model.ts
|
|
228
|
+
function ProductModel(connect) {
|
|
229
|
+
const service = new ProductService(connect);
|
|
230
|
+
return new ProductFeature(service);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// src/resources/organization/service/organization.ser.ts
|
|
234
|
+
class OrganizationService {
|
|
235
|
+
connect;
|
|
236
|
+
constructor(connect) {
|
|
237
|
+
this.connect = connect;
|
|
238
|
+
}
|
|
239
|
+
async getInfo() {
|
|
240
|
+
const response = await fetch(`${this.connect["apiEndpoint"]}/organization/info`, {
|
|
71
241
|
method: "GET",
|
|
72
242
|
headers: this.connect["getHeaders"]()
|
|
73
243
|
});
|
|
74
244
|
if (!response.ok) {
|
|
75
|
-
throw new Error(`Erro ao buscar
|
|
245
|
+
throw new Error(`Erro ao buscar informações da organização (${response.status})`);
|
|
76
246
|
}
|
|
77
247
|
return response.json();
|
|
78
248
|
}
|
|
79
|
-
async
|
|
80
|
-
const response = await fetch(`${this.connect["apiEndpoint"]}/
|
|
249
|
+
async getLinks() {
|
|
250
|
+
const response = await fetch(`${this.connect["apiEndpoint"]}/organization/links`, {
|
|
81
251
|
method: "GET",
|
|
82
252
|
headers: this.connect["getHeaders"]()
|
|
83
253
|
});
|
|
84
254
|
if (!response.ok) {
|
|
85
|
-
throw new Error(`Erro ao buscar
|
|
255
|
+
throw new Error(`Erro ao buscar links da organização (${response.status})`);
|
|
86
256
|
}
|
|
87
257
|
return response.json();
|
|
88
258
|
}
|
|
89
259
|
}
|
|
90
260
|
|
|
91
|
-
// src/resources/
|
|
92
|
-
class
|
|
261
|
+
// src/resources/organization/organization.feature.ts
|
|
262
|
+
class OrganizationFeature {
|
|
93
263
|
service;
|
|
94
264
|
constructor(service) {
|
|
95
265
|
this.service = service;
|
|
96
266
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
return products;
|
|
267
|
+
getOrganizationInfo() {
|
|
268
|
+
return this.service.getInfo();
|
|
100
269
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
return product;
|
|
270
|
+
getOrganizationSocialLinks() {
|
|
271
|
+
return this.service.getLinks();
|
|
104
272
|
}
|
|
105
273
|
}
|
|
106
274
|
|
|
107
|
-
// src/resources/
|
|
108
|
-
function
|
|
109
|
-
const service = new
|
|
110
|
-
return new
|
|
275
|
+
// src/resources/organization/organization.model.ts
|
|
276
|
+
function OrganizationModel(connect) {
|
|
277
|
+
const service = new OrganizationService(connect);
|
|
278
|
+
return new OrganizationFeature(service);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// src/resources/comment/comment.feature.ts
|
|
282
|
+
class CommentFeature {
|
|
283
|
+
service;
|
|
284
|
+
constructor(service) {
|
|
285
|
+
this.service = service;
|
|
286
|
+
}
|
|
287
|
+
listProductComments(params) {
|
|
288
|
+
return this.service.findMany(params);
|
|
289
|
+
}
|
|
290
|
+
getCommentById(id) {
|
|
291
|
+
return this.service.findOne(id);
|
|
292
|
+
}
|
|
293
|
+
createComment(data) {
|
|
294
|
+
return this.service.create(data);
|
|
295
|
+
}
|
|
296
|
+
updateComment(id, data) {
|
|
297
|
+
return this.service.update(id, data);
|
|
298
|
+
}
|
|
299
|
+
deleteComment(id) {
|
|
300
|
+
return this.service.delete(id);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// src/resources/comment/service/comment.ser.ts
|
|
305
|
+
class CommentService {
|
|
306
|
+
connect;
|
|
307
|
+
constructor(connect) {
|
|
308
|
+
this.connect = connect;
|
|
309
|
+
}
|
|
310
|
+
findMany(params) {
|
|
311
|
+
return this.connect.sendRestRequest("comments", { query: params });
|
|
312
|
+
}
|
|
313
|
+
findOne(id) {
|
|
314
|
+
return this.connect.sendRestRequest(`comments/${encodeURIComponent(id)}`);
|
|
315
|
+
}
|
|
316
|
+
create(data) {
|
|
317
|
+
return this.connect.sendRestRequest("comments", { method: "POST", body: data });
|
|
318
|
+
}
|
|
319
|
+
update(id, data) {
|
|
320
|
+
return this.connect.sendRestRequest(`comments/${encodeURIComponent(id)}`, { method: "PATCH", body: data });
|
|
321
|
+
}
|
|
322
|
+
delete(id) {
|
|
323
|
+
return this.connect.sendRestRequest(`comments/${encodeURIComponent(id)}`, { method: "DELETE" });
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// src/resources/comment/comment.model.ts
|
|
328
|
+
function CommentModel(connect) {
|
|
329
|
+
return new CommentFeature(new CommentService(connect));
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// src/resources/rating/rating.feature.ts
|
|
333
|
+
class RatingFeature {
|
|
334
|
+
service;
|
|
335
|
+
constructor(service) {
|
|
336
|
+
this.service = service;
|
|
337
|
+
}
|
|
338
|
+
getProductRatingSummary(stockId, params = {}) {
|
|
339
|
+
return this.service.summary(stockId, params);
|
|
340
|
+
}
|
|
341
|
+
listProductRatings(params) {
|
|
342
|
+
return this.service.findMany(params);
|
|
343
|
+
}
|
|
344
|
+
getCustomerProductRating(params) {
|
|
345
|
+
return this.service.findOne(params);
|
|
346
|
+
}
|
|
347
|
+
createProductRating(data) {
|
|
348
|
+
return this.service.create(data);
|
|
349
|
+
}
|
|
350
|
+
deleteProductRating(id) {
|
|
351
|
+
return this.service.delete(id);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// src/resources/rating/service/rating.ser.ts
|
|
356
|
+
class RatingService {
|
|
357
|
+
connect;
|
|
358
|
+
constructor(connect) {
|
|
359
|
+
this.connect = connect;
|
|
360
|
+
}
|
|
361
|
+
summary(stockId, params = {}) {
|
|
362
|
+
return this.connect.sendRestRequest(`rating/products/${encodeURIComponent(stockId)}/summary`, { query: params });
|
|
363
|
+
}
|
|
364
|
+
findMany(params) {
|
|
365
|
+
const { stockId, ...pagination } = params;
|
|
366
|
+
return this.connect.sendRestRequest(`rating/products/${encodeURIComponent(stockId)}/ratings`, { query: pagination });
|
|
367
|
+
}
|
|
368
|
+
findOne(params) {
|
|
369
|
+
return this.connect.sendRestRequest(`rating/products/${encodeURIComponent(params.stockId)}`, { query: { customerId: params.customerId } });
|
|
370
|
+
}
|
|
371
|
+
create(data) {
|
|
372
|
+
return this.connect.sendRestRequest("rating", { method: "POST", body: data });
|
|
373
|
+
}
|
|
374
|
+
delete(id) {
|
|
375
|
+
return this.connect.sendRestRequest(`rating/${encodeURIComponent(id)}`, { method: "DELETE" });
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// src/resources/rating/rating.model.ts
|
|
380
|
+
function RatingModel(connect) {
|
|
381
|
+
return new RatingFeature(new RatingService(connect));
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
// src/resources/payment/payment.feature.ts
|
|
385
|
+
class PaymentFeature {
|
|
386
|
+
service;
|
|
387
|
+
constructor(service) {
|
|
388
|
+
this.service = service;
|
|
389
|
+
}
|
|
390
|
+
listAvailablePaymentMethods() {
|
|
391
|
+
return this.service.methods();
|
|
392
|
+
}
|
|
393
|
+
createWiPayPayment(data) {
|
|
394
|
+
return this.service.createWiPayPayment(data);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
// src/resources/payment/service/payment.ser.ts
|
|
399
|
+
class PaymentService {
|
|
400
|
+
connect;
|
|
401
|
+
constructor(connect) {
|
|
402
|
+
this.connect = connect;
|
|
403
|
+
}
|
|
404
|
+
methods() {
|
|
405
|
+
return this.connect.sendRestRequest("payment/methods");
|
|
406
|
+
}
|
|
407
|
+
createWiPayPayment(data) {
|
|
408
|
+
return this.connect.sendRestRequest("payment/wipay/create", { method: "POST", body: data });
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
// src/resources/payment/payment.model.ts
|
|
413
|
+
function PaymentModel(connect) {
|
|
414
|
+
return new PaymentFeature(new PaymentService(connect));
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
// src/resources/category/category.feature.ts
|
|
418
|
+
class CategoryFeature {
|
|
419
|
+
service;
|
|
420
|
+
constructor(service) {
|
|
421
|
+
this.service = service;
|
|
422
|
+
}
|
|
423
|
+
listCategories(params = {}) {
|
|
424
|
+
return this.service.findMany(params);
|
|
425
|
+
}
|
|
426
|
+
getCategoryByRef(params) {
|
|
427
|
+
return this.service.findOne(params);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
// src/resources/category/service/category.ser.ts
|
|
432
|
+
class CategoryService {
|
|
433
|
+
connect;
|
|
434
|
+
constructor(connect) {
|
|
435
|
+
this.connect = connect;
|
|
436
|
+
}
|
|
437
|
+
findMany(params = {}) {
|
|
438
|
+
return this.connect.sendRestRequest("category", {
|
|
439
|
+
query: { page: params.page, limit: params.limit, search: params.search }
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
findOne(params) {
|
|
443
|
+
const { ref, ...pagination } = params;
|
|
444
|
+
return this.connect.sendRestRequest(`category/${encodeURIComponent(ref)}`, { query: pagination });
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
// src/resources/category/category.model.ts
|
|
449
|
+
function CategoryModel(connect) {
|
|
450
|
+
return new CategoryFeature(new CategoryService(connect));
|
|
111
451
|
}
|
|
112
452
|
|
|
113
453
|
// src/main.ts
|
|
114
454
|
class HellenaClient extends HellenaConnect {
|
|
115
455
|
product = ProductModel(this);
|
|
116
456
|
order = OrderModel(this);
|
|
117
|
-
|
|
118
|
-
|
|
457
|
+
organization = OrganizationModel(this);
|
|
458
|
+
comment = CommentModel(this);
|
|
459
|
+
rating = RatingModel(this);
|
|
460
|
+
payment = PaymentModel(this);
|
|
461
|
+
category = CategoryModel(this);
|
|
462
|
+
constructor(apiKey, options = {}) {
|
|
463
|
+
super(apiKey, options);
|
|
119
464
|
}
|
|
120
465
|
}
|
|
121
466
|
export {
|
|
467
|
+
HellenaAPIError,
|
|
122
468
|
HellenaClient
|
|
123
469
|
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { CategoryListParams, CategoryProductsParams, CategoryWithProductsDTO, PaginatedCategoriesDTO } from "./dto/category.dto";
|
|
2
|
+
import type { CategoryService } from "./service/category.ser";
|
|
3
|
+
export declare class CategoryFeature {
|
|
4
|
+
private readonly service;
|
|
5
|
+
constructor(service: CategoryService);
|
|
6
|
+
/** Lista as categorias da organização com paginação e pesquisa opcional. */
|
|
7
|
+
listCategories(params?: CategoryListParams): Promise<PaginatedCategoriesDTO>;
|
|
8
|
+
/** Obtém uma categoria pelo ID ou identificador e os respetivos produtos paginados. */
|
|
9
|
+
getCategoryByRef(params: CategoryProductsParams): Promise<CategoryWithProductsDTO>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { PaginatedResponse, ProductDTO, PaginationMeta } from "../../product/dto/product.dto";
|
|
2
|
+
export interface CategoryDTO {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
category: string;
|
|
6
|
+
icon?: string | null;
|
|
7
|
+
image?: string | null;
|
|
8
|
+
organizationId?: string;
|
|
9
|
+
createdAt?: string;
|
|
10
|
+
updatedAt?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface CategoryListParams {
|
|
13
|
+
page?: number;
|
|
14
|
+
limit?: number;
|
|
15
|
+
search?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface CategoryProductsParams {
|
|
18
|
+
ref: string;
|
|
19
|
+
page?: number;
|
|
20
|
+
limit?: number;
|
|
21
|
+
}
|
|
22
|
+
export interface CategoryWithProductsDTO extends CategoryDTO {
|
|
23
|
+
products: ProductDTO[];
|
|
24
|
+
meta: PaginationMeta;
|
|
25
|
+
}
|
|
26
|
+
export type PaginatedCategoriesDTO = PaginatedResponse<CategoryDTO>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { HellenaConnect } from "../../../core/HellenaConnect";
|
|
2
|
+
import type { CategoryListParams, CategoryProductsParams, CategoryWithProductsDTO, PaginatedCategoriesDTO } from "../dto/category.dto";
|
|
3
|
+
export declare class CategoryService {
|
|
4
|
+
private readonly connect;
|
|
5
|
+
constructor(connect: HellenaConnect);
|
|
6
|
+
findMany(params?: CategoryListParams): Promise<PaginatedCategoriesDTO>;
|
|
7
|
+
findOne(params: CategoryProductsParams): Promise<CategoryWithProductsDTO>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { AddCommentDTO, CommentDTO, PaginatedCommentsDTO, UpdateCommentDTO } from "./dto/comment.dto";
|
|
2
|
+
import type { CommentService } from "./service/comment.ser";
|
|
3
|
+
export declare class CommentFeature {
|
|
4
|
+
private readonly service;
|
|
5
|
+
constructor(service: CommentService);
|
|
6
|
+
/** Lista os comentários de um produto. */
|
|
7
|
+
listProductComments(params: {
|
|
8
|
+
stockId: string;
|
|
9
|
+
page?: number;
|
|
10
|
+
limit?: number;
|
|
11
|
+
}): Promise<PaginatedCommentsDTO>;
|
|
12
|
+
/** Obtém um comentário pelo seu identificador. */
|
|
13
|
+
getCommentById(id: string): Promise<CommentDTO>;
|
|
14
|
+
/** Publica um comentário num produto. */
|
|
15
|
+
createComment(data: AddCommentDTO): Promise<CommentDTO>;
|
|
16
|
+
/** Atualiza o conteúdo ou as reações de um comentário. */
|
|
17
|
+
updateComment(id: string, data: UpdateCommentDTO): Promise<CommentDTO>;
|
|
18
|
+
/** Elimina um comentário pelo seu identificador. */
|
|
19
|
+
deleteComment(id: string): Promise<{
|
|
20
|
+
success: boolean;
|
|
21
|
+
}>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { PaginatedResponse } from "../../product/dto/product.dto";
|
|
2
|
+
export interface CommentDTO {
|
|
3
|
+
id: string;
|
|
4
|
+
stockId: string;
|
|
5
|
+
content: string;
|
|
6
|
+
customerId?: string | null;
|
|
7
|
+
customerProfile?: string | null;
|
|
8
|
+
customerName?: string | null;
|
|
9
|
+
customerEmail?: string | null;
|
|
10
|
+
parentId?: string | null;
|
|
11
|
+
reactions?: string | null;
|
|
12
|
+
replies?: CommentDTO[];
|
|
13
|
+
parent?: CommentDTO | null;
|
|
14
|
+
createdAt?: string;
|
|
15
|
+
updatedAt?: string | null;
|
|
16
|
+
}
|
|
17
|
+
export interface AddCommentDTO {
|
|
18
|
+
stockId: string;
|
|
19
|
+
content: string;
|
|
20
|
+
customerId?: string;
|
|
21
|
+
customerProfile?: string;
|
|
22
|
+
customerName?: string;
|
|
23
|
+
customerEmail?: string;
|
|
24
|
+
parentId?: string;
|
|
25
|
+
reactions?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface UpdateCommentDTO {
|
|
28
|
+
content?: string;
|
|
29
|
+
reactions?: string;
|
|
30
|
+
}
|
|
31
|
+
export type PaginatedCommentsDTO = PaginatedResponse<CommentDTO>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { HellenaConnect } from "../../../core/HellenaConnect";
|
|
2
|
+
import type { AddCommentDTO, CommentDTO, PaginatedCommentsDTO, UpdateCommentDTO } from "../dto/comment.dto";
|
|
3
|
+
export declare class CommentService {
|
|
4
|
+
private readonly connect;
|
|
5
|
+
constructor(connect: HellenaConnect);
|
|
6
|
+
findMany(params: {
|
|
7
|
+
stockId: string;
|
|
8
|
+
page?: number;
|
|
9
|
+
limit?: number;
|
|
10
|
+
}): Promise<PaginatedCommentsDTO>;
|
|
11
|
+
findOne(id: string): Promise<CommentDTO>;
|
|
12
|
+
create(data: AddCommentDTO): Promise<CommentDTO>;
|
|
13
|
+
update(id: string, data: UpdateCommentDTO): Promise<CommentDTO>;
|
|
14
|
+
delete(id: string): Promise<{
|
|
15
|
+
success: boolean;
|
|
16
|
+
}>;
|
|
17
|
+
}
|