@afiliado/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/dist/index.d.ts +14 -0
- package/dist/index.js +41 -0
- package/package.json +18 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare class AfiliadoSDK {
|
|
2
|
+
private apiKey;
|
|
3
|
+
private baseUrl;
|
|
4
|
+
constructor(apiKey: string);
|
|
5
|
+
/**
|
|
6
|
+
* Transforma uma URL bruta em um objeto de produto com link de afiliado.
|
|
7
|
+
*/
|
|
8
|
+
parse({ url, tags }: {
|
|
9
|
+
url: string;
|
|
10
|
+
tags?: Record<string, string>;
|
|
11
|
+
}): Promise<any>;
|
|
12
|
+
}
|
|
13
|
+
export declare const afiliado: AfiliadoSDK;
|
|
14
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.afiliado = void 0;
|
|
13
|
+
class AfiliadoSDK {
|
|
14
|
+
constructor(apiKey) {
|
|
15
|
+
// Em produção, use a URL real: https://api.afiliado.me/v1
|
|
16
|
+
this.baseUrl = '/api/v1';
|
|
17
|
+
this.apiKey = apiKey;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Transforma uma URL bruta em um objeto de produto com link de afiliado.
|
|
21
|
+
*/
|
|
22
|
+
parse(_a) {
|
|
23
|
+
return __awaiter(this, arguments, void 0, function* ({ url, tags }) {
|
|
24
|
+
const res = yield fetch(`${this.baseUrl}/parse`, {
|
|
25
|
+
method: 'POST',
|
|
26
|
+
headers: {
|
|
27
|
+
'Authorization': `Bearer ${this.apiKey}`,
|
|
28
|
+
'Content-Type': 'application/json',
|
|
29
|
+
},
|
|
30
|
+
body: JSON.stringify({ url, tags }),
|
|
31
|
+
});
|
|
32
|
+
if (!res.ok) {
|
|
33
|
+
const error = yield res.json();
|
|
34
|
+
throw new Error(error.error || 'Falha ao processar API');
|
|
35
|
+
}
|
|
36
|
+
return res.json();
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// Exporta uma instância pronta para uso se houver uma KEY no ambiente
|
|
41
|
+
exports.afiliado = new AfiliadoSDK(process.env.AFILIADO_API_KEY || '');
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@afiliado/sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "SDK oficial para integração com o motor de links do afiliado.me",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": ["dist"],
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"prepublishOnly": "npm run build"
|
|
11
|
+
},
|
|
12
|
+
"keywords": ["affiliate", "marketing", "sdk", "nextjs"],
|
|
13
|
+
"author": "Afiliado.me",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"typescript": "^5.0.0"
|
|
17
|
+
}
|
|
18
|
+
}
|