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.
Files changed (47) hide show
  1. package/README.md +383 -0
  2. package/dist/functions/api/config.cjs +81 -0
  3. package/dist/functions/api/config.mjs +71 -0
  4. package/dist/functions/api/index.cjs +35 -0
  5. package/dist/functions/api/index.mjs +33 -0
  6. package/dist/functions/api/services/carts.service.cjs +64 -0
  7. package/dist/functions/api/services/carts.service.mjs +62 -0
  8. package/dist/functions/api/services/catalog.service.cjs +60 -0
  9. package/dist/functions/api/services/catalog.service.mjs +58 -0
  10. package/dist/functions/api/services/configs.service.cjs +46 -0
  11. package/dist/functions/api/services/configs.service.mjs +44 -0
  12. package/dist/functions/api/services/coupons.service.cjs +54 -0
  13. package/dist/functions/api/services/coupons.service.mjs +52 -0
  14. package/dist/functions/api/services/customer.service.cjs +65 -0
  15. package/dist/functions/api/services/customer.service.mjs +63 -0
  16. package/dist/functions/api/services/images.service.cjs +17 -0
  17. package/dist/functions/api/services/images.service.mjs +15 -0
  18. package/dist/functions/api/services/orders.service.cjs +36 -0
  19. package/dist/functions/api/services/orders.service.mjs +34 -0
  20. package/dist/functions/api/services/payment.service.cjs +26 -0
  21. package/dist/functions/api/services/payment.service.mjs +24 -0
  22. package/dist/functions/api/services/plans.service.cjs +67 -0
  23. package/dist/functions/api/services/plans.service.mjs +65 -0
  24. package/dist/functions/api/services/products.service.cjs +104 -0
  25. package/dist/functions/api/services/products.service.mjs +102 -0
  26. package/dist/functions/api/services/sales.service.cjs +29 -0
  27. package/dist/functions/api/services/sales.service.mjs +27 -0
  28. package/dist/functions/api/services/token.service.cjs +17 -0
  29. package/dist/functions/api/services/token.service.mjs +15 -0
  30. package/dist/functions/api/services/users.service.cjs +13 -0
  31. package/dist/functions/api/services/users.service.mjs +11 -0
  32. package/dist/functions/api/services/wallet.service.cjs +33 -0
  33. package/dist/functions/api/services/wallet.service.mjs +31 -0
  34. package/dist/functions/utils/cart.cjs +53 -0
  35. package/dist/functions/utils/cart.mjs +47 -0
  36. package/dist/functions/utils/formarts.cjs +30 -0
  37. package/dist/functions/utils/formarts.mjs +25 -0
  38. package/dist/functions/utils/permission.cjs +31 -0
  39. package/dist/functions/utils/permission.mjs +29 -0
  40. package/dist/index.cjs +45 -0
  41. package/dist/index.d.cts +766 -0
  42. package/dist/index.d.mts +766 -0
  43. package/dist/index.d.ts +766 -0
  44. package/dist/index.mjs +32 -0
  45. package/dist/tools/pix.cjs +108 -0
  46. package/dist/tools/pix.mjs +101 -0
  47. package/package.json +47 -0
package/dist/index.mjs ADDED
@@ -0,0 +1,32 @@
1
+ import { configureApi } from './functions/api/config.mjs';
2
+ import { db } from './functions/api/index.mjs';
3
+ export { cartAntiFakeVerify, cartCalculeTotal, cartVerifyAproved, cartVerifyPermission, cartWillExpire } from './functions/utils/cart.mjs';
4
+ export { formatDecimalToNumber, formatNumberToDecimal, formatPrice, formatRelativeTime } from './functions/utils/formarts.mjs';
5
+ export { hasPermission } from './functions/utils/permission.mjs';
6
+ export { pixUtils } from './tools/pix.mjs';
7
+
8
+ class ShopEasySdk {
9
+ constructor(options) {
10
+ configureApi(
11
+ options.baseUrl ?? "https://api.shopeasy.site",
12
+ options.secretKey
13
+ );
14
+ }
15
+ //services crud
16
+ carts = db.carts;
17
+ catalogs = db.catalogs;
18
+ configs = db.configs;
19
+ coupons = db.coupon;
20
+ customers = db.customers;
21
+ images = db.images;
22
+ orders = db.orders;
23
+ paymentConfig = db.payment;
24
+ plans = db.plans;
25
+ products = db.products;
26
+ sales = db.sales;
27
+ tokens = db.tokens;
28
+ users = db.users;
29
+ wallet = db.wallet;
30
+ }
31
+
32
+ export { ShopEasySdk };
@@ -0,0 +1,108 @@
1
+ 'use strict';
2
+
3
+ const canvas = require('canvas');
4
+ const pixUtils$1 = require('pix-utils');
5
+ const QRCode = require('qrcode');
6
+ const sharp = require('sharp');
7
+
8
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
9
+
10
+ const QRCode__default = /*#__PURE__*/_interopDefaultCompat(QRCode);
11
+ const sharp__default = /*#__PURE__*/_interopDefaultCompat(sharp);
12
+
13
+ class Pix {
14
+ create(data) {
15
+ const payment = pixUtils$1.createStaticPix(data);
16
+ if (pixUtils$1.hasError(payment)) {
17
+ return null;
18
+ }
19
+ return payment;
20
+ }
21
+ async loadImageFromUrl(url) {
22
+ try {
23
+ const response = await fetch(url);
24
+ if (!response.ok) {
25
+ throw new Error(`Falha ao baixar imagem: ${response.statusText}`);
26
+ }
27
+ const arrayBuffer = await response.arrayBuffer();
28
+ const buffer = Buffer.from(arrayBuffer);
29
+ const pngBuffer = await sharp__default(buffer).resize(256, 256, {
30
+ fit: "contain",
31
+ background: { r: 0, g: 0, b: 0, alpha: 0 }
32
+ }).png().toBuffer();
33
+ return await canvas.loadImage(pngBuffer);
34
+ } catch (error) {
35
+ console.error("Erro ao carregar imagem:", error);
36
+ throw error;
37
+ }
38
+ }
39
+ async qrCodeImage(pixKeyOrPayload, options) {
40
+ let payload = pixKeyOrPayload;
41
+ if (!pixKeyOrPayload.startsWith("000201")) {
42
+ const pixData = this.create({
43
+ merchantName: options?.merchantName || "Comerciante",
44
+ merchantCity: options?.merchantCity || "Taquari",
45
+ pixKey: pixKeyOrPayload,
46
+ infoAdicional: options?.description,
47
+ transactionAmount: options?.amount ?? 10
48
+ });
49
+ if (!pixData) {
50
+ throw new Error("Erro ao gerar payload PIX");
51
+ }
52
+ payload = pixData.toBRCode();
53
+ }
54
+ const qrCodeDataUrl = await QRCode__default.toDataURL(payload, {
55
+ type: "image/png",
56
+ width: 400,
57
+ errorCorrectionLevel: "H",
58
+ margin: 2,
59
+ color: {
60
+ dark: options?.qrColor || "#000000",
61
+ light: options?.backgroundColor || "#ffffff"
62
+ }
63
+ });
64
+ const canvas$1 = canvas.createCanvas(400, 400);
65
+ const ctx = canvas$1.getContext("2d");
66
+ const qrImage = await canvas.loadImage(qrCodeDataUrl);
67
+ ctx.drawImage(qrImage, 0, 0, 400, 400);
68
+ if (options?.logoUrl) {
69
+ try {
70
+ const logo = await this.loadImageFromUrl(options.logoUrl);
71
+ const logoSize = options?.logoSize || 80;
72
+ const logoX = (400 - logoSize) / 2;
73
+ const logoY = (400 - logoSize) / 2;
74
+ const padding = 10;
75
+ const bgSize = logoSize + padding * 2;
76
+ const bgX = (400 - bgSize) / 2;
77
+ const bgY = (400 - bgSize) / 2;
78
+ ctx.fillStyle = options?.backgroundColor || "#ffffff";
79
+ if (options?.rounded !== false) {
80
+ this.roundRect(ctx, bgX, bgY, bgSize, bgSize, 15);
81
+ } else {
82
+ ctx.fillRect(bgX, bgY, bgSize, bgSize);
83
+ }
84
+ ctx.drawImage(logo, logoX, logoY, logoSize, logoSize);
85
+ } catch (error) {
86
+ }
87
+ }
88
+ return canvas$1.toBuffer("image/png");
89
+ }
90
+ // Método auxiliar para desenhar retângulo com cantos arredondados
91
+ roundRect(ctx, x, y, width, height, radius) {
92
+ ctx.beginPath();
93
+ ctx.moveTo(x + radius, y);
94
+ ctx.lineTo(x + width - radius, y);
95
+ ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
96
+ ctx.lineTo(x + width, y + height - radius);
97
+ ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
98
+ ctx.lineTo(x + radius, y + height);
99
+ ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
100
+ ctx.lineTo(x, y + radius);
101
+ ctx.quadraticCurveTo(x, y, x + radius, y);
102
+ ctx.closePath();
103
+ ctx.fill();
104
+ }
105
+ }
106
+ const pixUtils = new Pix();
107
+
108
+ exports.pixUtils = pixUtils;
@@ -0,0 +1,101 @@
1
+ import { loadImage, createCanvas } from 'canvas';
2
+ import { createStaticPix, hasError } from 'pix-utils';
3
+ import QRCode from 'qrcode';
4
+ import sharp from 'sharp';
5
+
6
+ class Pix {
7
+ create(data) {
8
+ const payment = createStaticPix(data);
9
+ if (hasError(payment)) {
10
+ return null;
11
+ }
12
+ return payment;
13
+ }
14
+ async loadImageFromUrl(url) {
15
+ try {
16
+ const response = await fetch(url);
17
+ if (!response.ok) {
18
+ throw new Error(`Falha ao baixar imagem: ${response.statusText}`);
19
+ }
20
+ const arrayBuffer = await response.arrayBuffer();
21
+ const buffer = Buffer.from(arrayBuffer);
22
+ const pngBuffer = await sharp(buffer).resize(256, 256, {
23
+ fit: "contain",
24
+ background: { r: 0, g: 0, b: 0, alpha: 0 }
25
+ }).png().toBuffer();
26
+ return await loadImage(pngBuffer);
27
+ } catch (error) {
28
+ console.error("Erro ao carregar imagem:", error);
29
+ throw error;
30
+ }
31
+ }
32
+ async qrCodeImage(pixKeyOrPayload, options) {
33
+ let payload = pixKeyOrPayload;
34
+ if (!pixKeyOrPayload.startsWith("000201")) {
35
+ const pixData = this.create({
36
+ merchantName: options?.merchantName || "Comerciante",
37
+ merchantCity: options?.merchantCity || "Taquari",
38
+ pixKey: pixKeyOrPayload,
39
+ infoAdicional: options?.description,
40
+ transactionAmount: options?.amount ?? 10
41
+ });
42
+ if (!pixData) {
43
+ throw new Error("Erro ao gerar payload PIX");
44
+ }
45
+ payload = pixData.toBRCode();
46
+ }
47
+ const qrCodeDataUrl = await QRCode.toDataURL(payload, {
48
+ type: "image/png",
49
+ width: 400,
50
+ errorCorrectionLevel: "H",
51
+ margin: 2,
52
+ color: {
53
+ dark: options?.qrColor || "#000000",
54
+ light: options?.backgroundColor || "#ffffff"
55
+ }
56
+ });
57
+ const canvas = createCanvas(400, 400);
58
+ const ctx = canvas.getContext("2d");
59
+ const qrImage = await loadImage(qrCodeDataUrl);
60
+ ctx.drawImage(qrImage, 0, 0, 400, 400);
61
+ if (options?.logoUrl) {
62
+ try {
63
+ const logo = await this.loadImageFromUrl(options.logoUrl);
64
+ const logoSize = options?.logoSize || 80;
65
+ const logoX = (400 - logoSize) / 2;
66
+ const logoY = (400 - logoSize) / 2;
67
+ const padding = 10;
68
+ const bgSize = logoSize + padding * 2;
69
+ const bgX = (400 - bgSize) / 2;
70
+ const bgY = (400 - bgSize) / 2;
71
+ ctx.fillStyle = options?.backgroundColor || "#ffffff";
72
+ if (options?.rounded !== false) {
73
+ this.roundRect(ctx, bgX, bgY, bgSize, bgSize, 15);
74
+ } else {
75
+ ctx.fillRect(bgX, bgY, bgSize, bgSize);
76
+ }
77
+ ctx.drawImage(logo, logoX, logoY, logoSize, logoSize);
78
+ } catch (error) {
79
+ }
80
+ }
81
+ return canvas.toBuffer("image/png");
82
+ }
83
+ // Método auxiliar para desenhar retângulo com cantos arredondados
84
+ roundRect(ctx, x, y, width, height, radius) {
85
+ ctx.beginPath();
86
+ ctx.moveTo(x + radius, y);
87
+ ctx.lineTo(x + width - radius, y);
88
+ ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
89
+ ctx.lineTo(x + width, y + height - radius);
90
+ ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
91
+ ctx.lineTo(x + radius, y + height);
92
+ ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
93
+ ctx.lineTo(x, y + radius);
94
+ ctx.quadraticCurveTo(x, y, x + radius, y);
95
+ ctx.closePath();
96
+ ctx.fill();
97
+ }
98
+ }
99
+ const pixUtils = new Pix();
100
+
101
+ export { pixUtils };
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "shopeasy-sdk",
3
+ "version": "1.0.0",
4
+ "description": "SDK oficial para integração com a API ShopEasy",
5
+ "license": "ISC",
6
+ "author": "jeanbrnd",
7
+ "type": "module",
8
+ "main": "./dist/index.cjs",
9
+ "module": "./dist/index.mjs",
10
+ "types": "./dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "import": "./dist/index.mjs",
14
+ "require": "./dist/index.cjs",
15
+ "types": "./dist/index.d.ts"
16
+ }
17
+ },
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "scripts": {
22
+ "dev": "tsx --env-file=.env playground/index.ts",
23
+ "build": "unbuild",
24
+ "lint": "tsc --noEmit",
25
+ "prepublishOnly": "npm run build"
26
+ },
27
+ "dependencies": {
28
+ "axios": "^1.13.6",
29
+ "canvas": "^3.2.1",
30
+ "decimal.js": "^10.6.0",
31
+ "discord.js": "^14.25.1",
32
+ "pix-utils": "^2.8.2",
33
+ "qrcode": "^1.5.4",
34
+ "sharp": "^0.34.5"
35
+ },
36
+ "engines": {
37
+ "node": ">=18"
38
+ },
39
+ "packageManager": "npm@10.2.4",
40
+ "devDependencies": {
41
+ "@types/node": "^22.19.15",
42
+ "@types/qrcode": "^1.5.6",
43
+ "tsx": "^4.21.0",
44
+ "typescript": "^5.0.0",
45
+ "unbuild": "^3.6.1"
46
+ }
47
+ }