shopeasy-sdk 1.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 +383 -0
- package/dist/functions/api/config.cjs +81 -0
- package/dist/functions/api/config.mjs +71 -0
- package/dist/functions/api/index.cjs +35 -0
- package/dist/functions/api/index.mjs +33 -0
- package/dist/functions/api/services/carts.service.cjs +64 -0
- package/dist/functions/api/services/carts.service.mjs +62 -0
- package/dist/functions/api/services/catalog.service.cjs +60 -0
- package/dist/functions/api/services/catalog.service.mjs +58 -0
- package/dist/functions/api/services/configs.service.cjs +46 -0
- package/dist/functions/api/services/configs.service.mjs +44 -0
- package/dist/functions/api/services/coupons.service.cjs +54 -0
- package/dist/functions/api/services/coupons.service.mjs +52 -0
- package/dist/functions/api/services/customer.service.cjs +65 -0
- package/dist/functions/api/services/customer.service.mjs +63 -0
- package/dist/functions/api/services/images.service.cjs +17 -0
- package/dist/functions/api/services/images.service.mjs +15 -0
- package/dist/functions/api/services/orders.service.cjs +36 -0
- package/dist/functions/api/services/orders.service.mjs +34 -0
- package/dist/functions/api/services/payment.service.cjs +26 -0
- package/dist/functions/api/services/payment.service.mjs +24 -0
- package/dist/functions/api/services/plans.service.cjs +67 -0
- package/dist/functions/api/services/plans.service.mjs +65 -0
- package/dist/functions/api/services/products.service.cjs +104 -0
- package/dist/functions/api/services/products.service.mjs +102 -0
- package/dist/functions/api/services/sales.service.cjs +29 -0
- package/dist/functions/api/services/sales.service.mjs +27 -0
- package/dist/functions/api/services/token.service.cjs +17 -0
- package/dist/functions/api/services/token.service.mjs +15 -0
- package/dist/functions/api/services/users.service.cjs +13 -0
- package/dist/functions/api/services/users.service.mjs +11 -0
- package/dist/functions/api/services/wallet.service.cjs +33 -0
- package/dist/functions/api/services/wallet.service.mjs +31 -0
- package/dist/functions/utils/cart.cjs +53 -0
- package/dist/functions/utils/cart.mjs +47 -0
- package/dist/functions/utils/formarts.cjs +30 -0
- package/dist/functions/utils/formarts.mjs +25 -0
- package/dist/functions/utils/permission.cjs +31 -0
- package/dist/functions/utils/permission.mjs +29 -0
- package/dist/index.cjs +45 -0
- package/dist/index.d.cts +766 -0
- package/dist/index.d.mts +766 -0
- package/dist/index.d.ts +766 -0
- package/dist/index.mjs +32 -0
- package/dist/tools/pix.cjs +108 -0
- package/dist/tools/pix.mjs +101 -0
- package/package.json +47 -0
package/README.md
ADDED
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
# ShopEasy SDK
|
|
2
|
+
|
|
3
|
+
SDK oficial para integração com a API ShopEasy.
|
|
4
|
+
|
|
5
|
+
## Instalação
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install shopeasy-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Configuração
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { ShopEasySdk } from "shopeasy-sdk";
|
|
15
|
+
|
|
16
|
+
const sdk = new ShopEasySdk({
|
|
17
|
+
secretKey: "sua-chave-secreta",
|
|
18
|
+
baseUrl: "https://api.shopeasy.site", // opcional
|
|
19
|
+
});
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## `sdk.carts`
|
|
25
|
+
|
|
26
|
+
| Método | Parâmetros | Retorno |
|
|
27
|
+
|--------|-----------|--------|
|
|
28
|
+
| `draft.get` | `cardId: string` | `CartDraft | null` |
|
|
29
|
+
| `draft.set` | `cartId: string, update: CartDraft` | `Cart` |
|
|
30
|
+
| `draft.delete` | `cartId: string` | `void` |
|
|
31
|
+
| `create` | `args: CreateCartArgs` | `Cart` |
|
|
32
|
+
| `get` | `args: CartGetArgs` | `Cart | null` |
|
|
33
|
+
| `getById` | `cartId: string` | `Cart | null` |
|
|
34
|
+
| `getAllByGuild` | `guildId: string` | `Cart[]` |
|
|
35
|
+
| `update` | `args: CartUpdateArgs` | `Cart` |
|
|
36
|
+
| `expires` | `botClient: string` | `Cart[]` |
|
|
37
|
+
| `count` | `guildId: string` | `number` |
|
|
38
|
+
| `delete` | `cartId: string` | `void` |
|
|
39
|
+
|
|
40
|
+
**Exemplo de uso:**
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
import { ShopEasySdk } from "shopeasy-sdk";
|
|
44
|
+
|
|
45
|
+
const sdk = new ShopEasySdk({ secretKey: "sua-chave" });
|
|
46
|
+
|
|
47
|
+
const result = await sdk.carts.draft.get(/* args */);
|
|
48
|
+
const result = await sdk.carts.draft.set(/* args */);
|
|
49
|
+
const result = await sdk.carts.draft.delete(/* args */);
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## `sdk.catalogs`
|
|
55
|
+
|
|
56
|
+
| Método | Parâmetros | Retorno |
|
|
57
|
+
|--------|-----------|--------|
|
|
58
|
+
| `setDraft` | `args: CatalogDraftSetArgs` | `Catalog | null` |
|
|
59
|
+
| `getDraft` | `args: CatalogDraftGetArgs` | `Catalog | null` |
|
|
60
|
+
| `getByReference` | `reference: string, guildId: string` | `Catalog | null` |
|
|
61
|
+
| `getById` | `id: string` | `Catalog | null` |
|
|
62
|
+
| `create` | `args: CatalogCreateArgs` | `Catalog` |
|
|
63
|
+
| `getByCaching` | `id: string` | `Catalog | null` |
|
|
64
|
+
| `getAllByGuild` | `guildId: string` | `Array<Catalog>` |
|
|
65
|
+
| `update` | `args: CatalogUpdateArgs` | `Catalog` |
|
|
66
|
+
| `count` | `guildId: string` | `number` |
|
|
67
|
+
| `delete` | `id: string` | `Catalog` |
|
|
68
|
+
|
|
69
|
+
**Exemplo de uso:**
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
import { ShopEasySdk } from "shopeasy-sdk";
|
|
73
|
+
|
|
74
|
+
const sdk = new ShopEasySdk({ secretKey: "sua-chave" });
|
|
75
|
+
|
|
76
|
+
const result = await sdk.catalogs.setDraft(/* args */);
|
|
77
|
+
const result = await sdk.catalogs.getDraft(/* args */);
|
|
78
|
+
const result = await sdk.catalogs.getByReference(/* args */);
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## `sdk.configss`
|
|
84
|
+
|
|
85
|
+
| Método | Parâmetros | Retorno |
|
|
86
|
+
|--------|-----------|--------|
|
|
87
|
+
| `getByGuild` | `guildId: string` | `Config` |
|
|
88
|
+
| `setDraft` | `args: ConfigDraftSetArgs` | `Config | null` |
|
|
89
|
+
| `delDraft` | `args: ConfigDraftGetArgs` | `Config | null` |
|
|
90
|
+
| `getDraft` | `args: ConfigDraftGetArgs` | `Config | null` |
|
|
91
|
+
| `update` | `args: ConfigUpdateArgs` | `Config` |
|
|
92
|
+
| `getByCaching` | `_guildId: string` | `Config | null` |
|
|
93
|
+
|
|
94
|
+
**Exemplo de uso:**
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
import { ShopEasySdk } from "shopeasy-sdk";
|
|
98
|
+
|
|
99
|
+
const sdk = new ShopEasySdk({ secretKey: "sua-chave" });
|
|
100
|
+
|
|
101
|
+
const result = await sdk.configss.getByGuild(/* args */);
|
|
102
|
+
const result = await sdk.configss.setDraft(/* args */);
|
|
103
|
+
const result = await sdk.configss.delDraft(/* args */);
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## `sdk.coupons`
|
|
109
|
+
|
|
110
|
+
| Método | Parâmetros | Retorno |
|
|
111
|
+
|--------|-----------|--------|
|
|
112
|
+
| `setDraft` | `args: CouponDraftSetArgs` | `Coupon | null` |
|
|
113
|
+
| `getDraft` | `args: CouponDraftGetArgs` | `Coupon | null` |
|
|
114
|
+
| `existsByCode` | `code: string` | `boolean` |
|
|
115
|
+
| `getById` | `id: string` | `Coupon | null` |
|
|
116
|
+
| `create` | `args: CouponCreateArgs` | `Coupon` |
|
|
117
|
+
| `getByCaching` | `id: string` | `Coupon | null` |
|
|
118
|
+
| `getAllByGuild` | `guildId: string` | `Coupon[]` |
|
|
119
|
+
| `update` | `args: CouponUpdateArgs` | `Coupon` |
|
|
120
|
+
| `count` | `guildId: string` | `number` |
|
|
121
|
+
| `delete` | `id: string` | `Coupon` |
|
|
122
|
+
|
|
123
|
+
**Exemplo de uso:**
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
import { ShopEasySdk } from "shopeasy-sdk";
|
|
127
|
+
|
|
128
|
+
const sdk = new ShopEasySdk({ secretKey: "sua-chave" });
|
|
129
|
+
|
|
130
|
+
const result = await sdk.coupons.setDraft(/* args */);
|
|
131
|
+
const result = await sdk.coupons.getDraft(/* args */);
|
|
132
|
+
const result = await sdk.coupons.existsByCode(/* args */);
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## `sdk.customers`
|
|
138
|
+
|
|
139
|
+
| Método | Parâmetros | Retorno |
|
|
140
|
+
|--------|-----------|--------|
|
|
141
|
+
| `setDraft` | `args: CustomerDraftSetArgs` | `Customer | null` |
|
|
142
|
+
| `getDraft` | `args: CustomerDraftGetArgs` | `Customer | null` |
|
|
143
|
+
| `existsByReference` | `_reference: string` | `boolean` |
|
|
144
|
+
| `getById` | `id: string` | `Customer | null` |
|
|
145
|
+
| `getByReference` | `_reference: string` | `Customer | null` |
|
|
146
|
+
| `create` | `args: CustomerCreateArgs` | `Customer` |
|
|
147
|
+
| `getByCaching` | `id: string` | `Customer | null` |
|
|
148
|
+
| `getAllByGuild` | `guildId: string` | `Customer[]` |
|
|
149
|
+
| `update` | `args: CustomerUpdateArgs` | `Customer` |
|
|
150
|
+
| `count` | `guildId: string` | `number` |
|
|
151
|
+
| `delete` | `id: string` | `Customer` |
|
|
152
|
+
|
|
153
|
+
**Exemplo de uso:**
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
import { ShopEasySdk } from "shopeasy-sdk";
|
|
157
|
+
|
|
158
|
+
const sdk = new ShopEasySdk({ secretKey: "sua-chave" });
|
|
159
|
+
|
|
160
|
+
const result = await sdk.customers.setDraft(/* args */);
|
|
161
|
+
const result = await sdk.customers.getDraft(/* args */);
|
|
162
|
+
const result = await sdk.customers.existsByReference(/* args */);
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
## `sdk.images`
|
|
168
|
+
|
|
169
|
+
| Método | Parâmetros | Retorno |
|
|
170
|
+
|--------|-----------|--------|
|
|
171
|
+
| `getAll` | `guildId: string` | `Image[]` |
|
|
172
|
+
| `create` | `args: imageCreate` | `Image` |
|
|
173
|
+
|
|
174
|
+
**Exemplo de uso:**
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
import { ShopEasySdk } from "shopeasy-sdk";
|
|
178
|
+
|
|
179
|
+
const sdk = new ShopEasySdk({ secretKey: "sua-chave" });
|
|
180
|
+
|
|
181
|
+
const result = await sdk.images.getAll(/* args */);
|
|
182
|
+
const result = await sdk.images.create(/* args */);
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
## `sdk.orders`
|
|
188
|
+
|
|
189
|
+
| Método | Parâmetros | Retorno |
|
|
190
|
+
|--------|-----------|--------|
|
|
191
|
+
| `create` | `args: OrderCreate` | `Order` |
|
|
192
|
+
| `get` | `orderId: string` | `Order | null` |
|
|
193
|
+
| `getPayment` | `orderId: string` | `OrderPayment | null` |
|
|
194
|
+
| `getApprovedUnprocessed` | `botClient: string, guildId?: string` | `Order[]` |
|
|
195
|
+
| `markAsReleased` | `id: string` | `Order` |
|
|
196
|
+
| `aprove` | `id: string` | `Order` |
|
|
197
|
+
|
|
198
|
+
**Exemplo de uso:**
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
import { ShopEasySdk } from "shopeasy-sdk";
|
|
202
|
+
|
|
203
|
+
const sdk = new ShopEasySdk({ secretKey: "sua-chave" });
|
|
204
|
+
|
|
205
|
+
const result = await sdk.orders.create(/* args */);
|
|
206
|
+
const result = await sdk.orders.get(/* args */);
|
|
207
|
+
const result = await sdk.orders.getPayment(/* args */);
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
## `sdk.paymentConfig`
|
|
213
|
+
|
|
214
|
+
| Método | Parâmetros | Retorno |
|
|
215
|
+
|--------|-----------|--------|
|
|
216
|
+
| `getOrCreate` | `guildId: string` | `PaymentConfig` |
|
|
217
|
+
| `update` | `args: UpdatePaymentConfigArgs` | `PaymentConfig` |
|
|
218
|
+
| `getByCaching` | `guildId: string` | `PaymentConfig | null` |
|
|
219
|
+
|
|
220
|
+
**Exemplo de uso:**
|
|
221
|
+
|
|
222
|
+
```typescript
|
|
223
|
+
import { ShopEasySdk } from "shopeasy-sdk";
|
|
224
|
+
|
|
225
|
+
const sdk = new ShopEasySdk({ secretKey: "sua-chave" });
|
|
226
|
+
|
|
227
|
+
const result = await sdk.paymentConfig.getOrCreate(/* args */);
|
|
228
|
+
const result = await sdk.paymentConfig.update(/* args */);
|
|
229
|
+
const result = await sdk.paymentConfig.getByCaching(/* args */);
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
---
|
|
233
|
+
|
|
234
|
+
## `sdk.planss`
|
|
235
|
+
|
|
236
|
+
| Método | Parâmetros | Retorno |
|
|
237
|
+
|--------|-----------|--------|
|
|
238
|
+
| `getByGuild` | `guildId: string` | `Plan | null` |
|
|
239
|
+
| `havePlan` | `guildId: string` | `PlanType | null` |
|
|
240
|
+
| `create` | `args: Plan` | `Plan` |
|
|
241
|
+
| `getExpiring` | `days?: number` | `ExpiringPlan[]` |
|
|
242
|
+
| `getExpired` | `—` | `ExpiredPlansResponse` |
|
|
243
|
+
| `getPlansNeedingAlert` | `days?: number` | `PlansNeedingAlertResponse` |
|
|
244
|
+
| `markAlertSent` | `guildId: string, daysUntilExpire: number` | `MarkAlertResponse` |
|
|
245
|
+
| `checkExpirations` | `—` | `CheckExpirationsResponse` |
|
|
246
|
+
| `getExpirationStatus` | `guildId: string` | `PlanStatus` |
|
|
247
|
+
| `update` | `guildId: string, updates: Partial<Plan>` | `Plan` |
|
|
248
|
+
| `delete` | `guildId: string` | `void` |
|
|
249
|
+
| `createSubscription` | `args: PlanSubscriptionCreateArgs` | `EfiPixCreateResponse` |
|
|
250
|
+
|
|
251
|
+
**Exemplo de uso:**
|
|
252
|
+
|
|
253
|
+
```typescript
|
|
254
|
+
import { ShopEasySdk } from "shopeasy-sdk";
|
|
255
|
+
|
|
256
|
+
const sdk = new ShopEasySdk({ secretKey: "sua-chave" });
|
|
257
|
+
|
|
258
|
+
const result = await sdk.planss.getByGuild(/* args */);
|
|
259
|
+
const result = await sdk.planss.havePlan(/* args */);
|
|
260
|
+
const result = await sdk.planss.create(/* args */);
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
---
|
|
264
|
+
|
|
265
|
+
## `sdk.products`
|
|
266
|
+
|
|
267
|
+
| Método | Parâmetros | Retorno |
|
|
268
|
+
|--------|-----------|--------|
|
|
269
|
+
| `setDraft` | `args: ProduductDraftSetArgs` | `Product | null` |
|
|
270
|
+
| `pushStock` | `{
|
|
271
|
+
product, amount, }: ProductStockPushArgs` | `string[]` |
|
|
272
|
+
| `getDraft` | `args: ProduductDraftGetArgs` | `Product | null` |
|
|
273
|
+
| `existsByReference` | `args: ProductGetByReference` | `Product | null` |
|
|
274
|
+
| `getById` | `id: string` | `Product | null` |
|
|
275
|
+
| `getByReference` | `reference: string, guildId: string` | `Product | null` |
|
|
276
|
+
| `create` | `args: ProductCreateArgs` | `Product` |
|
|
277
|
+
| `getByCaching` | `id: string` | `Product | null` |
|
|
278
|
+
| `getAllByGuild` | `guildId: string` | `Array<Product>` |
|
|
279
|
+
| `update` | `args: ProductUpdateArgs` | `Product` |
|
|
280
|
+
| `count` | `guildId: string` | `number` |
|
|
281
|
+
| `delete` | `id: string` | `void` |
|
|
282
|
+
|
|
283
|
+
**Exemplo de uso:**
|
|
284
|
+
|
|
285
|
+
```typescript
|
|
286
|
+
import { ShopEasySdk } from "shopeasy-sdk";
|
|
287
|
+
|
|
288
|
+
const sdk = new ShopEasySdk({ secretKey: "sua-chave" });
|
|
289
|
+
|
|
290
|
+
const result = await sdk.products.setDraft(/* args */);
|
|
291
|
+
const result = await sdk.products.pushStock(/* args */);
|
|
292
|
+
const result = await sdk.products.getDraft(/* args */);
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
---
|
|
296
|
+
|
|
297
|
+
## `sdk.sales`
|
|
298
|
+
|
|
299
|
+
| Método | Parâmetros | Retorno |
|
|
300
|
+
|--------|-----------|--------|
|
|
301
|
+
| `create` | `args: SaleCreateArgs` | `Sale` |
|
|
302
|
+
| `getById` | `id: string` | `Sale | null` |
|
|
303
|
+
| `getAllByGuild` | `guildId: string` | `Sale[]` |
|
|
304
|
+
| `saleProductGet` | `id: string` | `SaleProduct | null` |
|
|
305
|
+
| `delete` | `id: string` | `void` |
|
|
306
|
+
|
|
307
|
+
**Exemplo de uso:**
|
|
308
|
+
|
|
309
|
+
```typescript
|
|
310
|
+
import { ShopEasySdk } from "shopeasy-sdk";
|
|
311
|
+
|
|
312
|
+
const sdk = new ShopEasySdk({ secretKey: "sua-chave" });
|
|
313
|
+
|
|
314
|
+
const result = await sdk.sales.create(/* args */);
|
|
315
|
+
const result = await sdk.sales.getById(/* args */);
|
|
316
|
+
const result = await sdk.sales.getAllByGuild(/* args */);
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
---
|
|
320
|
+
|
|
321
|
+
## `sdk.tokens`
|
|
322
|
+
|
|
323
|
+
| Método | Parâmetros | Retorno |
|
|
324
|
+
|--------|-----------|--------|
|
|
325
|
+
| `listUnused` | `—` | `Token[] | null` |
|
|
326
|
+
| `update` | `args: TokenUpdateArgs` | `Token` |
|
|
327
|
+
|
|
328
|
+
**Exemplo de uso:**
|
|
329
|
+
|
|
330
|
+
```typescript
|
|
331
|
+
import { ShopEasySdk } from "shopeasy-sdk";
|
|
332
|
+
|
|
333
|
+
const sdk = new ShopEasySdk({ secretKey: "sua-chave" });
|
|
334
|
+
|
|
335
|
+
const result = await sdk.tokens.listUnused();
|
|
336
|
+
const result = await sdk.tokens.update(/* args */);
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
---
|
|
340
|
+
|
|
341
|
+
## `sdk.users`
|
|
342
|
+
|
|
343
|
+
| Método | Parâmetros | Retorno |
|
|
344
|
+
|--------|-----------|--------|
|
|
345
|
+
| `get` | `userId: string` | `User | null` |
|
|
346
|
+
|
|
347
|
+
**Exemplo de uso:**
|
|
348
|
+
|
|
349
|
+
```typescript
|
|
350
|
+
import { ShopEasySdk } from "shopeasy-sdk";
|
|
351
|
+
|
|
352
|
+
const sdk = new ShopEasySdk({ secretKey: "sua-chave" });
|
|
353
|
+
|
|
354
|
+
const result = await sdk.users.get(/* args */);
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
---
|
|
358
|
+
|
|
359
|
+
## `sdk.wallet`
|
|
360
|
+
|
|
361
|
+
| Método | Parâmetros | Retorno |
|
|
362
|
+
|--------|-----------|--------|
|
|
363
|
+
| `getOrCreate` | `userId: string` | `Wallet` |
|
|
364
|
+
| `getByUserId` | `userId: string` | `Wallet` |
|
|
365
|
+
| `getByApiKey` | `apiKey: string` | `Wallet` |
|
|
366
|
+
| `update` | `args: UpdateWalletArgs` | `Wallet` |
|
|
367
|
+
| `getByCaching` | `userId: string` | `Wallet | null` |
|
|
368
|
+
|
|
369
|
+
**Exemplo de uso:**
|
|
370
|
+
|
|
371
|
+
```typescript
|
|
372
|
+
import { ShopEasySdk } from "shopeasy-sdk";
|
|
373
|
+
|
|
374
|
+
const sdk = new ShopEasySdk({ secretKey: "sua-chave" });
|
|
375
|
+
|
|
376
|
+
const result = await sdk.wallet.getOrCreate(/* args */);
|
|
377
|
+
const result = await sdk.wallet.getByUserId(/* args */);
|
|
378
|
+
const result = await sdk.wallet.getByApiKey(/* args */);
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
---
|
|
382
|
+
|
|
383
|
+
> Documentação gerada automaticamente em 11/03/2026.
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const axios = require('axios');
|
|
4
|
+
const http = require('node:http');
|
|
5
|
+
const https = require('node:https');
|
|
6
|
+
|
|
7
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
8
|
+
|
|
9
|
+
const axios__default = /*#__PURE__*/_interopDefaultCompat(axios);
|
|
10
|
+
const http__default = /*#__PURE__*/_interopDefaultCompat(http);
|
|
11
|
+
const https__default = /*#__PURE__*/_interopDefaultCompat(https);
|
|
12
|
+
|
|
13
|
+
class ApiError extends Error {
|
|
14
|
+
statusCode;
|
|
15
|
+
details;
|
|
16
|
+
constructor(statusCode, message, details) {
|
|
17
|
+
super(message);
|
|
18
|
+
this.name = "ApiError";
|
|
19
|
+
this.statusCode = statusCode;
|
|
20
|
+
this.details = details;
|
|
21
|
+
Error.captureStackTrace(this, this.constructor);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const httpAgent = new http__default.Agent({
|
|
25
|
+
keepAlive: true,
|
|
26
|
+
maxSockets: 100,
|
|
27
|
+
maxFreeSockets: 20,
|
|
28
|
+
timeout: 3e4
|
|
29
|
+
});
|
|
30
|
+
const httpsAgent = new https__default.Agent({
|
|
31
|
+
keepAlive: true,
|
|
32
|
+
maxSockets: 100,
|
|
33
|
+
maxFreeSockets: 20,
|
|
34
|
+
timeout: 3e4
|
|
35
|
+
});
|
|
36
|
+
const api = axios__default.create({
|
|
37
|
+
timeout: 1e4,
|
|
38
|
+
httpAgent,
|
|
39
|
+
httpsAgent,
|
|
40
|
+
headers: {
|
|
41
|
+
"Content-Type": "application/json"
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
api.interceptors.response.use(
|
|
45
|
+
(res) => res,
|
|
46
|
+
(err) => {
|
|
47
|
+
if (err.response) {
|
|
48
|
+
const data = err.response.data;
|
|
49
|
+
return Promise.reject(
|
|
50
|
+
new ApiError(
|
|
51
|
+
err.response.status,
|
|
52
|
+
data?.message ?? "Erro na API",
|
|
53
|
+
data?.errors ?? data
|
|
54
|
+
)
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
if (err.request) {
|
|
58
|
+
return Promise.reject(
|
|
59
|
+
new ApiError(503, "API indispon\xEDvel", {
|
|
60
|
+
url: err.config?.url,
|
|
61
|
+
method: err.config?.method,
|
|
62
|
+
timeout: err.config?.timeout
|
|
63
|
+
})
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
return Promise.reject(new ApiError(500, err.message));
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
function configureApi(baseUrl, secretKey) {
|
|
70
|
+
api.defaults.baseURL = baseUrl;
|
|
71
|
+
api.defaults.headers.common["Content-Type"] = "application/json";
|
|
72
|
+
if (secretKey) {
|
|
73
|
+
api.defaults.headers.common["Authorization"] = `Bearer ${secretKey}`;
|
|
74
|
+
} else {
|
|
75
|
+
delete api.defaults.headers.common["Authorization"];
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
exports.ApiError = ApiError;
|
|
80
|
+
exports.api = api;
|
|
81
|
+
exports.configureApi = configureApi;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import http from 'node:http';
|
|
3
|
+
import https from 'node:https';
|
|
4
|
+
|
|
5
|
+
class ApiError extends Error {
|
|
6
|
+
statusCode;
|
|
7
|
+
details;
|
|
8
|
+
constructor(statusCode, message, details) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = "ApiError";
|
|
11
|
+
this.statusCode = statusCode;
|
|
12
|
+
this.details = details;
|
|
13
|
+
Error.captureStackTrace(this, this.constructor);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const httpAgent = new http.Agent({
|
|
17
|
+
keepAlive: true,
|
|
18
|
+
maxSockets: 100,
|
|
19
|
+
maxFreeSockets: 20,
|
|
20
|
+
timeout: 3e4
|
|
21
|
+
});
|
|
22
|
+
const httpsAgent = new https.Agent({
|
|
23
|
+
keepAlive: true,
|
|
24
|
+
maxSockets: 100,
|
|
25
|
+
maxFreeSockets: 20,
|
|
26
|
+
timeout: 3e4
|
|
27
|
+
});
|
|
28
|
+
const api = axios.create({
|
|
29
|
+
timeout: 1e4,
|
|
30
|
+
httpAgent,
|
|
31
|
+
httpsAgent,
|
|
32
|
+
headers: {
|
|
33
|
+
"Content-Type": "application/json"
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
api.interceptors.response.use(
|
|
37
|
+
(res) => res,
|
|
38
|
+
(err) => {
|
|
39
|
+
if (err.response) {
|
|
40
|
+
const data = err.response.data;
|
|
41
|
+
return Promise.reject(
|
|
42
|
+
new ApiError(
|
|
43
|
+
err.response.status,
|
|
44
|
+
data?.message ?? "Erro na API",
|
|
45
|
+
data?.errors ?? data
|
|
46
|
+
)
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
if (err.request) {
|
|
50
|
+
return Promise.reject(
|
|
51
|
+
new ApiError(503, "API indispon\xEDvel", {
|
|
52
|
+
url: err.config?.url,
|
|
53
|
+
method: err.config?.method,
|
|
54
|
+
timeout: err.config?.timeout
|
|
55
|
+
})
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
return Promise.reject(new ApiError(500, err.message));
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
function configureApi(baseUrl, secretKey) {
|
|
62
|
+
api.defaults.baseURL = baseUrl;
|
|
63
|
+
api.defaults.headers.common["Content-Type"] = "application/json";
|
|
64
|
+
if (secretKey) {
|
|
65
|
+
api.defaults.headers.common["Authorization"] = `Bearer ${secretKey}`;
|
|
66
|
+
} else {
|
|
67
|
+
delete api.defaults.headers.common["Authorization"];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export { ApiError, api, configureApi };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const carts_service = require('./services/carts.service.cjs');
|
|
4
|
+
const catalog_service = require('./services/catalog.service.cjs');
|
|
5
|
+
const configs_service = require('./services/configs.service.cjs');
|
|
6
|
+
const coupons_service = require('./services/coupons.service.cjs');
|
|
7
|
+
const customer_service = require('./services/customer.service.cjs');
|
|
8
|
+
const images_service = require('./services/images.service.cjs');
|
|
9
|
+
const orders_service = require('./services/orders.service.cjs');
|
|
10
|
+
const payment_service = require('./services/payment.service.cjs');
|
|
11
|
+
const plans_service = require('./services/plans.service.cjs');
|
|
12
|
+
const products_service = require('./services/products.service.cjs');
|
|
13
|
+
const sales_service = require('./services/sales.service.cjs');
|
|
14
|
+
const token_service = require('./services/token.service.cjs');
|
|
15
|
+
const users_service = require('./services/users.service.cjs');
|
|
16
|
+
const wallet_service = require('./services/wallet.service.cjs');
|
|
17
|
+
|
|
18
|
+
const db = {
|
|
19
|
+
products: products_service,
|
|
20
|
+
images: images_service,
|
|
21
|
+
configs: configs_service,
|
|
22
|
+
plans: plans_service,
|
|
23
|
+
coupon: coupons_service,
|
|
24
|
+
carts: carts_service,
|
|
25
|
+
customers: customer_service,
|
|
26
|
+
catalogs: catalog_service,
|
|
27
|
+
payment: payment_service,
|
|
28
|
+
sales: sales_service,
|
|
29
|
+
wallet: wallet_service,
|
|
30
|
+
orders: orders_service,
|
|
31
|
+
tokens: token_service,
|
|
32
|
+
users: users_service
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
exports.db = db;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import cartService from './services/carts.service.mjs';
|
|
2
|
+
import CatalogService from './services/catalog.service.mjs';
|
|
3
|
+
import ConfigsService from './services/configs.service.mjs';
|
|
4
|
+
import CouponService from './services/coupons.service.mjs';
|
|
5
|
+
import CustomerService from './services/customer.service.mjs';
|
|
6
|
+
import ImageService from './services/images.service.mjs';
|
|
7
|
+
import ordersService from './services/orders.service.mjs';
|
|
8
|
+
import PaymentService from './services/payment.service.mjs';
|
|
9
|
+
import PlanService from './services/plans.service.mjs';
|
|
10
|
+
import ProductService from './services/products.service.mjs';
|
|
11
|
+
import SaleService from './services/sales.service.mjs';
|
|
12
|
+
import tokenService from './services/token.service.mjs';
|
|
13
|
+
import usersService from './services/users.service.mjs';
|
|
14
|
+
import walletService from './services/wallet.service.mjs';
|
|
15
|
+
|
|
16
|
+
const db = {
|
|
17
|
+
products: ProductService,
|
|
18
|
+
images: ImageService,
|
|
19
|
+
configs: ConfigsService,
|
|
20
|
+
plans: PlanService,
|
|
21
|
+
coupon: CouponService,
|
|
22
|
+
carts: cartService,
|
|
23
|
+
customers: CustomerService,
|
|
24
|
+
catalogs: CatalogService,
|
|
25
|
+
payment: PaymentService,
|
|
26
|
+
sales: SaleService,
|
|
27
|
+
wallet: walletService,
|
|
28
|
+
orders: ordersService,
|
|
29
|
+
tokens: tokenService,
|
|
30
|
+
users: usersService
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export { db };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const config = require('../config.cjs');
|
|
4
|
+
|
|
5
|
+
class cartService {
|
|
6
|
+
draft = {
|
|
7
|
+
get: async (cardId) => {
|
|
8
|
+
const { data } = await config.api.get(`/carts/draft/${cardId}`);
|
|
9
|
+
return data;
|
|
10
|
+
},
|
|
11
|
+
set: async ({
|
|
12
|
+
cartId,
|
|
13
|
+
update
|
|
14
|
+
}) => {
|
|
15
|
+
const { data } = await config.api.patch(`/carts/draft/${cartId}`, update);
|
|
16
|
+
return data;
|
|
17
|
+
},
|
|
18
|
+
delete: async (cartId) => {
|
|
19
|
+
await config.api.request({
|
|
20
|
+
method: "DELETE",
|
|
21
|
+
url: `/carts/draft/${cartId}`,
|
|
22
|
+
data: {}
|
|
23
|
+
});
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
async create(args) {
|
|
28
|
+
const { data } = await config.api.post("/carts", args);
|
|
29
|
+
return data;
|
|
30
|
+
}
|
|
31
|
+
async get(args) {
|
|
32
|
+
const { data } = await config.api.get(
|
|
33
|
+
`/carts/by-userid/${args.guildId}/${args.userId}`
|
|
34
|
+
);
|
|
35
|
+
return data;
|
|
36
|
+
}
|
|
37
|
+
async getById(cartId) {
|
|
38
|
+
const { data } = await config.api.get(`/carts/${cartId}`);
|
|
39
|
+
return data;
|
|
40
|
+
}
|
|
41
|
+
async getAllByGuild(guildId) {
|
|
42
|
+
const { data } = await config.api.get(`/carts/by-guild/${guildId}`);
|
|
43
|
+
return data.data ?? data;
|
|
44
|
+
}
|
|
45
|
+
async update(args) {
|
|
46
|
+
const { data } = await config.api.patch(`/carts/${args.id}`, args.data);
|
|
47
|
+
return data;
|
|
48
|
+
}
|
|
49
|
+
async expires(botClient) {
|
|
50
|
+
const { data } = await config.api.get(`/carts/expires/${botClient}`);
|
|
51
|
+
return data;
|
|
52
|
+
}
|
|
53
|
+
async count(guildId) {
|
|
54
|
+
const { data } = await config.api.get(`/carts/count/${guildId}`);
|
|
55
|
+
return data ?? 0;
|
|
56
|
+
}
|
|
57
|
+
async delete(cartId) {
|
|
58
|
+
await config.api.request({ method: "DELETE", url: `/carts/${cartId}`, data: {} });
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const cartService$1 = new cartService();
|
|
63
|
+
|
|
64
|
+
module.exports = cartService$1;
|