@afilimax/core 0.1.2 → 0.2.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 +38 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/interfaces/product.interface.d.ts +1 -1
- package/dist/interfaces/shipping.interface.d.ts +1 -1
- package/dist/schemas/coupon.schema.d.ts +5 -0
- package/dist/schemas/coupon.schema.js +8 -0
- package/dist/schemas/index.d.ts +4 -0
- package/dist/schemas/index.js +20 -0
- package/dist/schemas/price.schema.d.ts +11 -0
- package/dist/schemas/price.schema.js +16 -0
- package/dist/schemas/product.schema.d.ts +45 -0
- package/dist/schemas/product.schema.js +32 -0
- package/dist/schemas/shipping.schema.d.ts +9 -0
- package/dist/schemas/shipping.schema.js +12 -0
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -48,6 +48,44 @@ const product: ScrapedProduct = {
|
|
|
48
48
|
}
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
+
### Validação de dados
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { scrapedProductSchema, couponSchema, priceSchema, shippingSchema } from "@afilimax/core"
|
|
55
|
+
|
|
56
|
+
const product = scrapedProductSchema.parse({
|
|
57
|
+
marketplace: "Amazon",
|
|
58
|
+
title: "Produto",
|
|
59
|
+
price: {
|
|
60
|
+
value: 10,
|
|
61
|
+
currency: "BRL"
|
|
62
|
+
},
|
|
63
|
+
shipping: {
|
|
64
|
+
price: 2,
|
|
65
|
+
currency: "BRL",
|
|
66
|
+
freeShipping: true
|
|
67
|
+
},
|
|
68
|
+
rating: {
|
|
69
|
+
average: 4,
|
|
70
|
+
totalReviews: 10
|
|
71
|
+
},
|
|
72
|
+
availability: {
|
|
73
|
+
inStock: true,
|
|
74
|
+
quantity: 10
|
|
75
|
+
},
|
|
76
|
+
images: ["https://example.com/image.jpg"],
|
|
77
|
+
thumbnails: ["https://example.com/thumbnail.jpg"],
|
|
78
|
+
categories: ["Categoria"],
|
|
79
|
+
features: {
|
|
80
|
+
"Característica": "Valor"
|
|
81
|
+
},
|
|
82
|
+
specifications: {
|
|
83
|
+
"Especificação": "Valor"
|
|
84
|
+
},
|
|
85
|
+
scrapedAt: new Date().toISOString()
|
|
86
|
+
})
|
|
87
|
+
```
|
|
88
|
+
|
|
51
89
|
## Licença
|
|
52
90
|
|
|
53
91
|
Este projeto está sob a licença MIT.
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./interfaces"), exports);
|
|
18
|
+
__exportStar(require("./schemas"), exports);
|
|
18
19
|
__exportStar(require("./enums"), exports);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./product.schema"), exports);
|
|
18
|
+
__exportStar(require("./coupon.schema"), exports);
|
|
19
|
+
__exportStar(require("./price.schema"), exports);
|
|
20
|
+
__exportStar(require("./shipping.schema"), exports);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const priceSchema: z.ZodObject<{
|
|
3
|
+
value: z.ZodNumber;
|
|
4
|
+
originalValue: z.ZodNullable<z.ZodNumber>;
|
|
5
|
+
currency: z.ZodLiteral<"BRL">;
|
|
6
|
+
pixPrice: z.ZodNullable<z.ZodNumber>;
|
|
7
|
+
installment: z.ZodNullable<z.ZodObject<{
|
|
8
|
+
count: z.ZodNumber;
|
|
9
|
+
value: z.ZodNumber;
|
|
10
|
+
}, z.core.$strip>>;
|
|
11
|
+
}, z.core.$strip>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.priceSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
exports.priceSchema = zod_1.z.object({
|
|
6
|
+
value: zod_1.z.number(),
|
|
7
|
+
originalValue: zod_1.z.number().nullable(),
|
|
8
|
+
currency: zod_1.z.literal("BRL"),
|
|
9
|
+
pixPrice: zod_1.z.number().nullable(),
|
|
10
|
+
installment: zod_1.z
|
|
11
|
+
.object({
|
|
12
|
+
count: zod_1.z.number(),
|
|
13
|
+
value: zod_1.z.number(),
|
|
14
|
+
})
|
|
15
|
+
.nullable(),
|
|
16
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { Marketplace } from "../enums";
|
|
3
|
+
export declare const scrapedProductSchema: z.ZodObject<{
|
|
4
|
+
marketplace: z.ZodEnum<typeof Marketplace>;
|
|
5
|
+
externalId: z.ZodNullable<z.ZodString>;
|
|
6
|
+
title: z.ZodString;
|
|
7
|
+
description: z.ZodNullable<z.ZodString>;
|
|
8
|
+
brand: z.ZodNullable<z.ZodString>;
|
|
9
|
+
price: z.ZodObject<{
|
|
10
|
+
value: z.ZodNumber;
|
|
11
|
+
originalValue: z.ZodNullable<z.ZodNumber>;
|
|
12
|
+
currency: z.ZodLiteral<"BRL">;
|
|
13
|
+
pixPrice: z.ZodNullable<z.ZodNumber>;
|
|
14
|
+
installment: z.ZodNullable<z.ZodObject<{
|
|
15
|
+
count: z.ZodNumber;
|
|
16
|
+
value: z.ZodNumber;
|
|
17
|
+
}, z.core.$strip>>;
|
|
18
|
+
}, z.core.$strip>;
|
|
19
|
+
shipping: z.ZodNullable<z.ZodObject<{
|
|
20
|
+
price: z.ZodNullable<z.ZodNumber>;
|
|
21
|
+
currency: z.ZodLiteral<"BRL">;
|
|
22
|
+
freeShipping: z.ZodNullable<z.ZodBoolean>;
|
|
23
|
+
full: z.ZodNullable<z.ZodBoolean>;
|
|
24
|
+
prime: z.ZodNullable<z.ZodBoolean>;
|
|
25
|
+
estimatedDays: z.ZodNullable<z.ZodNumber>;
|
|
26
|
+
}, z.core.$strip>>;
|
|
27
|
+
rating: z.ZodObject<{
|
|
28
|
+
average: z.ZodNumber;
|
|
29
|
+
totalReviews: z.ZodNullable<z.ZodNumber>;
|
|
30
|
+
}, z.core.$strip>;
|
|
31
|
+
availability: z.ZodObject<{
|
|
32
|
+
inStock: z.ZodBoolean;
|
|
33
|
+
quantity: z.ZodNullable<z.ZodNumber>;
|
|
34
|
+
}, z.core.$strip>;
|
|
35
|
+
images: z.ZodArray<z.ZodString>;
|
|
36
|
+
thumbnails: z.ZodNullable<z.ZodArray<z.ZodString>>;
|
|
37
|
+
categories: z.ZodNullable<z.ZodArray<z.ZodString>>;
|
|
38
|
+
features: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
39
|
+
specifications: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
40
|
+
coupons: z.ZodArray<z.ZodObject<{
|
|
41
|
+
value: z.ZodString;
|
|
42
|
+
feature: z.ZodNullable<z.ZodString>;
|
|
43
|
+
}, z.core.$strip>>;
|
|
44
|
+
scrapedAt: z.ZodString;
|
|
45
|
+
}, z.core.$strip>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.scrapedProductSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const shipping_schema_1 = require("./shipping.schema");
|
|
6
|
+
const coupon_schema_1 = require("./coupon.schema");
|
|
7
|
+
const price_schema_1 = require("./price.schema");
|
|
8
|
+
const enums_1 = require("../enums");
|
|
9
|
+
exports.scrapedProductSchema = zod_1.z.object({
|
|
10
|
+
marketplace: zod_1.z.enum(enums_1.Marketplace),
|
|
11
|
+
externalId: zod_1.z.string().nullable(),
|
|
12
|
+
title: zod_1.z.string(),
|
|
13
|
+
description: zod_1.z.string().nullable(),
|
|
14
|
+
brand: zod_1.z.string().nullable(),
|
|
15
|
+
price: price_schema_1.priceSchema,
|
|
16
|
+
shipping: shipping_schema_1.shippingSchema.nullable(),
|
|
17
|
+
rating: zod_1.z.object({
|
|
18
|
+
average: zod_1.z.number(),
|
|
19
|
+
totalReviews: zod_1.z.number().nullable(),
|
|
20
|
+
}),
|
|
21
|
+
availability: zod_1.z.object({
|
|
22
|
+
inStock: zod_1.z.boolean(),
|
|
23
|
+
quantity: zod_1.z.number().nullable(),
|
|
24
|
+
}),
|
|
25
|
+
images: zod_1.z.array(zod_1.z.string()),
|
|
26
|
+
thumbnails: zod_1.z.array(zod_1.z.string()).nullable(),
|
|
27
|
+
categories: zod_1.z.array(zod_1.z.string()).nullable(),
|
|
28
|
+
features: zod_1.z.record(zod_1.z.string(), zod_1.z.string()).nullable(),
|
|
29
|
+
specifications: zod_1.z.record(zod_1.z.string(), zod_1.z.string()).nullable(),
|
|
30
|
+
coupons: zod_1.z.array(coupon_schema_1.couponSchema),
|
|
31
|
+
scrapedAt: zod_1.z.string(),
|
|
32
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const shippingSchema: z.ZodObject<{
|
|
3
|
+
price: z.ZodNullable<z.ZodNumber>;
|
|
4
|
+
currency: z.ZodLiteral<"BRL">;
|
|
5
|
+
freeShipping: z.ZodNullable<z.ZodBoolean>;
|
|
6
|
+
full: z.ZodNullable<z.ZodBoolean>;
|
|
7
|
+
prime: z.ZodNullable<z.ZodBoolean>;
|
|
8
|
+
estimatedDays: z.ZodNullable<z.ZodNumber>;
|
|
9
|
+
}, z.core.$strip>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.shippingSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
exports.shippingSchema = zod_1.z.object({
|
|
6
|
+
price: zod_1.z.number().nullable(),
|
|
7
|
+
currency: zod_1.z.literal("BRL"),
|
|
8
|
+
freeShipping: zod_1.z.boolean().nullable(),
|
|
9
|
+
full: zod_1.z.boolean().nullable(),
|
|
10
|
+
prime: zod_1.z.boolean().nullable(),
|
|
11
|
+
estimatedDays: zod_1.z.number().nullable(),
|
|
12
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@afilimax/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -33,5 +33,8 @@
|
|
|
33
33
|
"prettier-plugin-sort-imports": "^1.8.10",
|
|
34
34
|
"ts-node": "^10.9.2",
|
|
35
35
|
"typescript": "^5.9.3"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"zod": "^4.3.6"
|
|
36
39
|
}
|
|
37
40
|
}
|