@opens/gateways 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 ADDED
@@ -0,0 +1,48 @@
1
+ # @opens/sdk
2
+
3
+ SDK leve para acessar gateways de serviços (ex: Customer Service). Projeto organizado para facilitar adição de novos gateways.
4
+
5
+ ## Instalação
6
+
7
+ Instale via npm:
8
+
9
+ ```bash
10
+ npm install @opens/gateways
11
+ ```
12
+
13
+
14
+ ## Uso básico
15
+
16
+ O SDK expõe funções para configurar a instância e acessar gateways específicos.
17
+
18
+ - `configure(params)`: configura o SDK antes do uso.
19
+ - `gateway(service)`: retorna a instância do gateway solicitado.
20
+
21
+ Exemplo mínimo:
22
+
23
+ ```ts
24
+ import axios from 'axios';
25
+ import { configure, gateway } from '@opens/sdk';
26
+
27
+ // injete um cliente HTTP (axios) já configurado para facilitar testes
28
+ const axiosClient = axios.create({ headers: { Authorization: 'Bearer TOKEN' } });
29
+
30
+ configure({
31
+ axiosClient,
32
+ apiToken: 'TOKEN',
33
+ services: { customerService: { baseUrl: 'https://api.example.com' } },
34
+ });
35
+
36
+ const customerGateway = gateway('customer-service');
37
+ const resp = await customerGateway.getCompanyById('123');
38
+ console.log(resp);
39
+ ```
40
+
41
+
42
+ ## Padrão de acesso a gateways
43
+
44
+
45
+ ```ts
46
+ const serviceGateway = gateway('nome-do-servico');
47
+ // serviceGateway.metodoDoGateway(...)
48
+ ```
@@ -0,0 +1,47 @@
1
+ import { AxiosInstance } from 'axios';
2
+
3
+ interface CompanyResponse {
4
+ company: {
5
+ id: string;
6
+ name: string;
7
+ hostname: string;
8
+ crm_code: string;
9
+ token: string;
10
+ status: string;
11
+ timezone: string;
12
+ utc: string;
13
+ check_bad_password: boolean;
14
+ limit_bad_password: number;
15
+ watching: boolean;
16
+ trial: boolean;
17
+ support_widget_id: string;
18
+ createdAt: string;
19
+ updatedAt: string;
20
+ };
21
+ }
22
+
23
+ declare class CustomerServiceGateway {
24
+ private readonly httpClient;
25
+ private readonly baseUrl;
26
+ constructor(httpClient: AxiosInstance, baseUrl: string);
27
+ getCompanyById(companyId: string): Promise<CompanyResponse>;
28
+ }
29
+
30
+ interface GatewayClientParams {
31
+ axiosClient: AxiosInstance;
32
+ apiToken: string;
33
+ services: {
34
+ customerService: {
35
+ baseUrl: string;
36
+ };
37
+ };
38
+ }
39
+
40
+ declare enum SERVICE_GATEWAYS {
41
+ CUSTOMER_SERVICE = "customer-service"
42
+ }
43
+
44
+ declare const configure: (params: GatewayClientParams) => void;
45
+ declare const gateway: (service: SERVICE_GATEWAYS) => CustomerServiceGateway;
46
+
47
+ export { configure, gateway };
@@ -0,0 +1,47 @@
1
+ import { AxiosInstance } from 'axios';
2
+
3
+ interface CompanyResponse {
4
+ company: {
5
+ id: string;
6
+ name: string;
7
+ hostname: string;
8
+ crm_code: string;
9
+ token: string;
10
+ status: string;
11
+ timezone: string;
12
+ utc: string;
13
+ check_bad_password: boolean;
14
+ limit_bad_password: number;
15
+ watching: boolean;
16
+ trial: boolean;
17
+ support_widget_id: string;
18
+ createdAt: string;
19
+ updatedAt: string;
20
+ };
21
+ }
22
+
23
+ declare class CustomerServiceGateway {
24
+ private readonly httpClient;
25
+ private readonly baseUrl;
26
+ constructor(httpClient: AxiosInstance, baseUrl: string);
27
+ getCompanyById(companyId: string): Promise<CompanyResponse>;
28
+ }
29
+
30
+ interface GatewayClientParams {
31
+ axiosClient: AxiosInstance;
32
+ apiToken: string;
33
+ services: {
34
+ customerService: {
35
+ baseUrl: string;
36
+ };
37
+ };
38
+ }
39
+
40
+ declare enum SERVICE_GATEWAYS {
41
+ CUSTOMER_SERVICE = "customer-service"
42
+ }
43
+
44
+ declare const configure: (params: GatewayClientParams) => void;
45
+ declare const gateway: (service: SERVICE_GATEWAYS) => CustomerServiceGateway;
46
+
47
+ export { configure, gateway };
package/dist/index.js ADDED
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ configure: () => configure,
24
+ gateway: () => gateway
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+
28
+ // src/customer-service/index.ts
29
+ var CustomerServiceGateway = class {
30
+ constructor(httpClient, baseUrl) {
31
+ this.httpClient = httpClient;
32
+ this.baseUrl = baseUrl;
33
+ }
34
+ httpClient;
35
+ baseUrl;
36
+ async getCompanyById(companyId) {
37
+ const { data } = await this.httpClient.get(`${this.baseUrl}/companies/search/${companyId}`);
38
+ return data;
39
+ }
40
+ };
41
+
42
+ // src/@common/client.ts
43
+ var SDKGateways = class {
44
+ customerService;
45
+ constructor(customerService) {
46
+ this.customerService = customerService;
47
+ }
48
+ };
49
+ function createClient(params) {
50
+ const httpClient = params.axiosClient;
51
+ const customerService = new CustomerServiceGateway(httpClient, params.services.customerService.baseUrl);
52
+ return new SDKGateways(customerService);
53
+ }
54
+
55
+ // src/index.ts
56
+ var SDK = class {
57
+ client = null;
58
+ configure(params) {
59
+ this.client = createClient(params);
60
+ }
61
+ };
62
+ var sdk = new SDK();
63
+ var configure = (params) => {
64
+ sdk.configure(params);
65
+ };
66
+ var gateway = (service) => {
67
+ if (!sdk.client)
68
+ throw new Error(
69
+ "SDK not configured. Please call configure() with the appropriate parameters before using the SDK."
70
+ );
71
+ switch (service) {
72
+ case "customer-service" /* CUSTOMER_SERVICE */:
73
+ return sdk.client.customerService;
74
+ default:
75
+ throw new Error(`Unknown service gateway: ${service}`);
76
+ }
77
+ };
78
+ // Annotate the CommonJS export names for ESM import in node:
79
+ 0 && (module.exports = {
80
+ configure,
81
+ gateway
82
+ });
83
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/customer-service/index.ts","../src/@common/client.ts"],"sourcesContent":["import { createClient, SDKGatewaysInterface, GatewayClientParams } from './@common/client';\nimport { SERVICE_GATEWAYS } from './@common/enums';\nclass SDK {\n client: SDKGatewaysInterface | null = null;\n\n configure(params: GatewayClientParams) {\n this.client = createClient(params);\n }\n}\nconst sdk = new SDK();\n\nexport const configure = (params: GatewayClientParams) => {\n sdk.configure(params);\n};\n\nexport const gateway = (service: SERVICE_GATEWAYS) => {\n if (!sdk.client)\n throw new Error(\n 'SDK not configured. Please call configure() with the appropriate parameters before using the SDK.',\n );\n\n switch (service) {\n case SERVICE_GATEWAYS.CUSTOMER_SERVICE:\n return sdk.client.customerService;\n default:\n throw new Error(`Unknown service gateway: ${service}`);\n }\n};\n","import type { AxiosInstance } from 'axios';\nimport type { CompanyResponse } from './contracts/company';\n\nexport class CustomerServiceGateway {\n constructor(\n private readonly httpClient: AxiosInstance,\n private readonly baseUrl: string,\n ) {}\n\n async getCompanyById(companyId: string): Promise<CompanyResponse> {\n const { data } = await this.httpClient.get<CompanyResponse>(`${this.baseUrl}/companies/search/${companyId}`);\n return data;\n }\n}\n\nexport type { CompanyResponse } from './contracts/company';\n","import { CustomerServiceGateway } from '../customer-service';\nimport { AxiosInstance } from 'axios';\n\nexport interface SDKGatewaysInterface {\n customerService: CustomerServiceGateway;\n}\n\nclass SDKGateways {\n customerService: CustomerServiceGateway;\n constructor(customerService: CustomerServiceGateway) {\n this.customerService = customerService;\n }\n}\n\nexport interface GatewayClientParams {\n axiosClient: AxiosInstance;\n apiToken: string;\n services: {\n customerService: {\n baseUrl: string;\n };\n };\n}\n\nexport function createClient(params: GatewayClientParams) {\n const httpClient = params.axiosClient;\n const customerService = new CustomerServiceGateway(httpClient, params.services.customerService.baseUrl);\n return new SDKGateways(customerService);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGO,IAAM,yBAAN,MAA6B;AAAA,EAClC,YACmB,YACA,SACjB;AAFiB;AACA;AAAA,EAChB;AAAA,EAFgB;AAAA,EACA;AAAA,EAGnB,MAAM,eAAe,WAA6C;AAChE,UAAM,EAAE,KAAK,IAAI,MAAM,KAAK,WAAW,IAAqB,GAAG,KAAK,OAAO,qBAAqB,SAAS,EAAE;AAC3G,WAAO;AAAA,EACT;AACF;;;ACNA,IAAM,cAAN,MAAkB;AAAA,EAChB;AAAA,EACA,YAAY,iBAAyC;AACnD,SAAK,kBAAkB;AAAA,EACzB;AACF;AAYO,SAAS,aAAa,QAA6B;AACxD,QAAM,aAAa,OAAO;AAC1B,QAAM,kBAAkB,IAAI,uBAAuB,YAAY,OAAO,SAAS,gBAAgB,OAAO;AACtG,SAAO,IAAI,YAAY,eAAe;AACxC;;;AF1BA,IAAM,MAAN,MAAU;AAAA,EACR,SAAsC;AAAA,EAEtC,UAAU,QAA6B;AACrC,SAAK,SAAS,aAAa,MAAM;AAAA,EACnC;AACF;AACA,IAAM,MAAM,IAAI,IAAI;AAEb,IAAM,YAAY,CAAC,WAAgC;AACxD,MAAI,UAAU,MAAM;AACtB;AAEO,IAAM,UAAU,CAAC,YAA8B;AACpD,MAAI,CAAC,IAAI;AACP,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAEF,UAAQ,SAAS;AAAA,IACf;AACE,aAAO,IAAI,OAAO;AAAA,IACpB;AACE,YAAM,IAAI,MAAM,4BAA4B,OAAO,EAAE;AAAA,EACzD;AACF;","names":[]}
package/dist/index.mjs ADDED
@@ -0,0 +1,55 @@
1
+ // src/customer-service/index.ts
2
+ var CustomerServiceGateway = class {
3
+ constructor(httpClient, baseUrl) {
4
+ this.httpClient = httpClient;
5
+ this.baseUrl = baseUrl;
6
+ }
7
+ httpClient;
8
+ baseUrl;
9
+ async getCompanyById(companyId) {
10
+ const { data } = await this.httpClient.get(`${this.baseUrl}/companies/search/${companyId}`);
11
+ return data;
12
+ }
13
+ };
14
+
15
+ // src/@common/client.ts
16
+ var SDKGateways = class {
17
+ customerService;
18
+ constructor(customerService) {
19
+ this.customerService = customerService;
20
+ }
21
+ };
22
+ function createClient(params) {
23
+ const httpClient = params.axiosClient;
24
+ const customerService = new CustomerServiceGateway(httpClient, params.services.customerService.baseUrl);
25
+ return new SDKGateways(customerService);
26
+ }
27
+
28
+ // src/index.ts
29
+ var SDK = class {
30
+ client = null;
31
+ configure(params) {
32
+ this.client = createClient(params);
33
+ }
34
+ };
35
+ var sdk = new SDK();
36
+ var configure = (params) => {
37
+ sdk.configure(params);
38
+ };
39
+ var gateway = (service) => {
40
+ if (!sdk.client)
41
+ throw new Error(
42
+ "SDK not configured. Please call configure() with the appropriate parameters before using the SDK."
43
+ );
44
+ switch (service) {
45
+ case "customer-service" /* CUSTOMER_SERVICE */:
46
+ return sdk.client.customerService;
47
+ default:
48
+ throw new Error(`Unknown service gateway: ${service}`);
49
+ }
50
+ };
51
+ export {
52
+ configure,
53
+ gateway
54
+ };
55
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/customer-service/index.ts","../src/@common/client.ts","../src/index.ts"],"sourcesContent":["import type { AxiosInstance } from 'axios';\nimport type { CompanyResponse } from './contracts/company';\n\nexport class CustomerServiceGateway {\n constructor(\n private readonly httpClient: AxiosInstance,\n private readonly baseUrl: string,\n ) {}\n\n async getCompanyById(companyId: string): Promise<CompanyResponse> {\n const { data } = await this.httpClient.get<CompanyResponse>(`${this.baseUrl}/companies/search/${companyId}`);\n return data;\n }\n}\n\nexport type { CompanyResponse } from './contracts/company';\n","import { CustomerServiceGateway } from '../customer-service';\nimport { AxiosInstance } from 'axios';\n\nexport interface SDKGatewaysInterface {\n customerService: CustomerServiceGateway;\n}\n\nclass SDKGateways {\n customerService: CustomerServiceGateway;\n constructor(customerService: CustomerServiceGateway) {\n this.customerService = customerService;\n }\n}\n\nexport interface GatewayClientParams {\n axiosClient: AxiosInstance;\n apiToken: string;\n services: {\n customerService: {\n baseUrl: string;\n };\n };\n}\n\nexport function createClient(params: GatewayClientParams) {\n const httpClient = params.axiosClient;\n const customerService = new CustomerServiceGateway(httpClient, params.services.customerService.baseUrl);\n return new SDKGateways(customerService);\n}\n","import { createClient, SDKGatewaysInterface, GatewayClientParams } from './@common/client';\nimport { SERVICE_GATEWAYS } from './@common/enums';\nclass SDK {\n client: SDKGatewaysInterface | null = null;\n\n configure(params: GatewayClientParams) {\n this.client = createClient(params);\n }\n}\nconst sdk = new SDK();\n\nexport const configure = (params: GatewayClientParams) => {\n sdk.configure(params);\n};\n\nexport const gateway = (service: SERVICE_GATEWAYS) => {\n if (!sdk.client)\n throw new Error(\n 'SDK not configured. Please call configure() with the appropriate parameters before using the SDK.',\n );\n\n switch (service) {\n case SERVICE_GATEWAYS.CUSTOMER_SERVICE:\n return sdk.client.customerService;\n default:\n throw new Error(`Unknown service gateway: ${service}`);\n }\n};\n"],"mappings":";AAGO,IAAM,yBAAN,MAA6B;AAAA,EAClC,YACmB,YACA,SACjB;AAFiB;AACA;AAAA,EAChB;AAAA,EAFgB;AAAA,EACA;AAAA,EAGnB,MAAM,eAAe,WAA6C;AAChE,UAAM,EAAE,KAAK,IAAI,MAAM,KAAK,WAAW,IAAqB,GAAG,KAAK,OAAO,qBAAqB,SAAS,EAAE;AAC3G,WAAO;AAAA,EACT;AACF;;;ACNA,IAAM,cAAN,MAAkB;AAAA,EAChB;AAAA,EACA,YAAY,iBAAyC;AACnD,SAAK,kBAAkB;AAAA,EACzB;AACF;AAYO,SAAS,aAAa,QAA6B;AACxD,QAAM,aAAa,OAAO;AAC1B,QAAM,kBAAkB,IAAI,uBAAuB,YAAY,OAAO,SAAS,gBAAgB,OAAO;AACtG,SAAO,IAAI,YAAY,eAAe;AACxC;;;AC1BA,IAAM,MAAN,MAAU;AAAA,EACR,SAAsC;AAAA,EAEtC,UAAU,QAA6B;AACrC,SAAK,SAAS,aAAa,MAAM;AAAA,EACnC;AACF;AACA,IAAM,MAAM,IAAI,IAAI;AAEb,IAAM,YAAY,CAAC,WAAgC;AACxD,MAAI,UAAU,MAAM;AACtB;AAEO,IAAM,UAAU,CAAC,YAA8B;AACpD,MAAI,CAAC,IAAI;AACP,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAEF,UAAQ,SAAS;AAAA,IACf;AACE,aAAO,IAAI,OAAO;AAAA,IACpB;AACE,YAAM,IAAI,MAAM,4BAA4B,OAAO,EAAE;AAAA,EACzD;AACF;","names":[]}
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "version": "1.0.0",
3
+ "description": "A simple package to help with some common tasks",
4
+ "name": "@opens/gateways",
5
+ "private": false,
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "main": "./dist/index.js",
10
+ "module": "./dist/index.mjs",
11
+ "types": "./dist/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.mjs",
16
+ "require": "./dist/index.js"
17
+ }
18
+ },
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "scripts": {
23
+ "test": "vitest run",
24
+ "test:watch": "vitest",
25
+ "dev": "tsup --watch",
26
+ "build": "tsup --dts --format esm,cjs"
27
+ },
28
+ "tsup": {
29
+ "entry": [
30
+ "src/index.ts"
31
+ ],
32
+ "sourcemap": true,
33
+ "splitting": false
34
+ },
35
+ "engines": {
36
+ "node": ">=18"
37
+ },
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "git+https://bitbucket.org/snepdev/pkg_utils.git"
41
+ },
42
+ "author": "Opens Tecnologia",
43
+ "license": "MIT",
44
+ "bugs": {
45
+ "url": "https://bitbucket.org/snepdev/pkg_utils/issues"
46
+ },
47
+ "homepage": "https://bitbucket.org/snepdev/pkg_utils#readme",
48
+ "devDependencies": {
49
+ "tsup": "^8.4.0",
50
+ "typescript": "^5.8.2",
51
+ "vitest": "^3.0.7"
52
+ },
53
+ "dependencies": {
54
+ "axios": "^1.16.0"
55
+ }
56
+ }