@afilimax/core 0.3.0 → 0.4.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/README.md CHANGED
@@ -86,6 +86,62 @@ const product = scrapedProductSchema.parse({
86
86
  })
87
87
  ```
88
88
 
89
+ ### Provedores de Afiliados
90
+
91
+ O `AffiliateProvider` é uma classe abstrata fundamental para estender as capacidades de afiliação do ecossistema Afilimax.
92
+
93
+ ```typescript
94
+ import { AffiliateProvider } from "@afilimax/core"
95
+
96
+ interface CustomOptions {
97
+ trackingId: string
98
+ }
99
+
100
+ class MyProvider extends AffiliateProvider<CustomOptions> {
101
+ name = "Meu Provedor"
102
+ domains = ["loja-exemplo.com.br"]
103
+
104
+ // Implementação obrigatória para gerar o link
105
+ async createAffiliateUrl(url: string) {
106
+ return `https://link-afiliado.com?id=${this.options.trackingId}&url=${url}`
107
+ }
108
+ }
109
+
110
+ const provider = new MyProvider({ trackingId: "user-123" })
111
+
112
+ // Verifica se uma URL pertence ao provedor
113
+ if (provider.supportsUrl("https://loja-exemplo.com.br/item")) {
114
+ const affiliateUrl = await provider.createAffiliateUrl("https://loja-exemplo.com.br/item")
115
+ console.log(affiliateUrl)
116
+ }
117
+ ```
118
+
119
+ ### Gerenciamento de Provedores (Encadeamento)
120
+
121
+ O `AffiliateManager` permite agrupar múltiplos provedores e encontrar automaticamente o correto para uma determinada URL.
122
+
123
+ ```typescript
124
+ import { AffiliateManager } from "@afilimax/core"
125
+
126
+ const manager = new AffiliateManager([
127
+ new AmazonProvider(options),
128
+ new ShopeeProvider(options),
129
+ new MagaluProvider(options)
130
+ ])
131
+
132
+ // O manager encontrará o provedor correto baseado nos domínios suportados.
133
+ // Caso nenhum provedor suporte a URL, retornará null.
134
+ const url = "https://www.amazon.com.br/dp/B088GHHR6K"
135
+ const affiliateUrl = await manager.createAffiliateUrl(url)
136
+
137
+ if (affiliateUrl) {
138
+ console.log("URL de afiliado:", affiliateUrl)
139
+ }
140
+
141
+ // Você também pode adicionar novos provedores dinamicamente
142
+ manager.use(new CustomProvider())
143
+ ```
144
+
89
145
  ## Licença
90
146
 
91
147
  Este projeto está sob a licença MIT.
@@ -0,0 +1,18 @@
1
+ import { AffiliateProvider } from "./interfaces/affiliate-provider.interface";
2
+ export declare class AffiliateManager {
3
+ private readonly providers;
4
+ constructor(providers: AffiliateProvider<any>[]);
5
+ /**
6
+ * Encontra o primeiro provedor que suporta a URL fornecida.
7
+ */
8
+ findProvider(url: string): AffiliateProvider<any> | undefined;
9
+ /**
10
+ * Cria uma URL de afiliado usando o primeiro provedor compatível encontrado.
11
+ * Caso nenhum provedor seja encontrado, retorna null.
12
+ */
13
+ createAffiliateUrl(url: string): Promise<string | null>;
14
+ /**
15
+ * Adiciona um provedor ao início da cadeia.
16
+ */
17
+ use(provider: AffiliateProvider<any>): this;
18
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AffiliateManager = void 0;
4
+ class AffiliateManager {
5
+ constructor(providers) {
6
+ this.providers = providers;
7
+ }
8
+ /**
9
+ * Encontra o primeiro provedor que suporta a URL fornecida.
10
+ */
11
+ findProvider(url) {
12
+ return this.providers.find(provider => provider.supportsUrl(url));
13
+ }
14
+ /**
15
+ * Cria uma URL de afiliado usando o primeiro provedor compatível encontrado.
16
+ * Caso nenhum provedor seja encontrado, retorna null.
17
+ */
18
+ async createAffiliateUrl(url) {
19
+ const provider = this.findProvider(url);
20
+ if (!provider) {
21
+ return null;
22
+ }
23
+ return provider.createAffiliateUrl(url);
24
+ }
25
+ /**
26
+ * Adiciona um provedor ao início da cadeia.
27
+ */
28
+ use(provider) {
29
+ this.providers.unshift(provider);
30
+ return this;
31
+ }
32
+ }
33
+ exports.AffiliateManager = AffiliateManager;
package/dist/index.d.ts CHANGED
@@ -2,3 +2,4 @@ export * from "./interfaces";
2
2
  export * from "./schemas";
3
3
  export * from "./enums";
4
4
  export * from "./utils";
5
+ export * from "./affiliate-manager";
package/dist/index.js CHANGED
@@ -18,3 +18,4 @@ __exportStar(require("./interfaces"), exports);
18
18
  __exportStar(require("./schemas"), exports);
19
19
  __exportStar(require("./enums"), exports);
20
20
  __exportStar(require("./utils"), exports);
21
+ __exportStar(require("./affiliate-manager"), exports);
@@ -0,0 +1,8 @@
1
+ export declare abstract class AffiliateProvider<TOptions> {
2
+ protected readonly options: TOptions;
3
+ abstract domains: string[];
4
+ constructor(options: TOptions);
5
+ abstract name: string;
6
+ supportsUrl(url: string): boolean;
7
+ abstract createAffiliateUrl(url: string): Promise<string>;
8
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AffiliateProvider = void 0;
4
+ class AffiliateProvider {
5
+ constructor(options) {
6
+ this.options = options;
7
+ }
8
+ supportsUrl(url) {
9
+ const hostname = new URL(url).hostname;
10
+ return this.domains.some(domain => hostname === domain || hostname.endsWith(`.${domain}`));
11
+ }
12
+ }
13
+ exports.AffiliateProvider = AffiliateProvider;
@@ -2,3 +2,4 @@ export * from "./price.interface";
2
2
  export * from "./product.interface";
3
3
  export * from "./shipping.interface";
4
4
  export * from "./coupon.interface";
5
+ export * from "./affiliate-provider.interface";
@@ -18,3 +18,4 @@ __exportStar(require("./price.interface"), exports);
18
18
  __exportStar(require("./product.interface"), exports);
19
19
  __exportStar(require("./shipping.interface"), exports);
20
20
  __exportStar(require("./coupon.interface"), exports);
21
+ __exportStar(require("./affiliate-provider.interface"), exports);
package/package.json CHANGED
@@ -1,40 +1,40 @@
1
- {
2
- "name": "@afilimax/core",
3
- "version": "0.3.0",
4
- "type": "commonjs",
5
- "main": "./dist/index.js",
6
- "module": "./dist/index.js",
7
- "types": "./dist/index.d.ts",
8
- "files": [
9
- "dist/*",
10
- "!/**/__tests__"
11
- ],
12
- "scripts": {
13
- "build": "tsc",
14
- "dev": "ts-node ./src/index.ts",
15
- "format": "prettier --write \"src/**/*.ts\""
16
- },
17
- "publishConfig": {
18
- "access": "public"
19
- },
20
- "keywords": [
21
- "afilimax",
22
- "brazilian marketplaces scraper",
23
- "brazilian afiliate marketing"
24
- ],
25
- "author": "Marcuth",
26
- "license": "MIT",
27
- "devDependencies": {
28
- "@types/node": "^25.2.3",
29
- "eslint": "^10.0.0",
30
- "eslint-config-prettier": "^10.1.8",
31
- "eslint-plugin-prettier": "^5.5.5",
32
- "prettier": "^3.8.1",
33
- "prettier-plugin-sort-imports": "^1.8.10",
34
- "ts-node": "^10.9.2",
35
- "typescript": "^5.9.3"
36
- },
37
- "dependencies": {
38
- "zod": "^4.3.6"
39
- }
40
- }
1
+ {
2
+ "name": "@afilimax/core",
3
+ "version": "0.4.1",
4
+ "type": "commonjs",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "files": [
9
+ "dist/*",
10
+ "!/**/__tests__"
11
+ ],
12
+ "scripts": {
13
+ "build": "tsc",
14
+ "dev": "ts-node ./src/index.ts",
15
+ "format": "prettier --write \"src/**/*.ts\""
16
+ },
17
+ "publishConfig": {
18
+ "access": "public"
19
+ },
20
+ "keywords": [
21
+ "afilimax",
22
+ "brazilian marketplaces scraper",
23
+ "brazilian afiliate marketing"
24
+ ],
25
+ "author": "Marcuth",
26
+ "license": "MIT",
27
+ "devDependencies": {
28
+ "@types/node": "^25.3.2",
29
+ "eslint": "^10.0.2",
30
+ "eslint-config-prettier": "^10.1.8",
31
+ "eslint-plugin-prettier": "^5.5.5",
32
+ "prettier": "^3.8.1",
33
+ "prettier-plugin-sort-imports": "^1.8.11",
34
+ "ts-node": "^10.9.2",
35
+ "typescript": "^5.9.3"
36
+ },
37
+ "dependencies": {
38
+ "zod": "^4.3.6"
39
+ }
40
+ }