@zentto/platform-client 0.1.0 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @zentto/platform-client
2
2
 
3
- Cliente oficial tipado para los servicios de plataforma Zentto: **notify**, **cache** (pronto), **auth** (pronto), **landing** (pronto).
3
+ Cliente oficial tipado para los servicios de plataforma Zentto: **notify**, **auth**, **cache**, **landing**.
4
4
 
5
5
  Úsalo desde el ERP, cualquier vertical (hotel, medical, tickets, rental, education, inmobiliario…) o un sitio externo de un tenant cliente.
6
6
 
@@ -40,7 +40,46 @@ Variables de entorno:
40
40
  | `NOTIFY_API_KEY` | — | Master key del servicio (server-to-server) |
41
41
  | `API_MASTER_KEY` | — | Fallback legacy |
42
42
 
43
- ### Construcción manual (multi-tenant, tests)
43
+ ### Auth (zentto-auth)
44
+
45
+ ```ts
46
+ import { authFromEnv, AuthClient } from "@zentto/platform-client/auth";
47
+
48
+ // Service-to-service (backend) — provisioning de owners desde el ERP
49
+ const svc = authFromEnv(); // lee AUTH_SERVICE_URL + AUTH_SERVICE_KEY
50
+ await svc.admin.provisionOwner({
51
+ email, fullName, companyId, companyCode, sendMagicLink: true,
52
+ });
53
+
54
+ // User-facing (con JWT del usuario)
55
+ const user = new AuthClient({ accessToken: jwt });
56
+ const me = await user.me();
57
+ ```
58
+
59
+ ### Cache (zentto-cache)
60
+
61
+ ```ts
62
+ import { cacheFromEnv } from "@zentto/platform-client/cache";
63
+ const c = cacheFromEnv(); // lee CACHE_URL + CACHE_APP_KEY
64
+
65
+ await c.gridLayouts.put("invoices-list", layoutJson, { companyId, userId });
66
+ const res = await c.gridLayouts.get("invoices-list", { companyId, userId });
67
+ // res.data.layout → layout guardado
68
+ ```
69
+
70
+ ### Landing (leads de tenants clientes)
71
+
72
+ ```ts
73
+ import { LandingClient } from "@zentto/platform-client/landing";
74
+ const landing = new LandingClient({ tenantKey: "zk_<prefix>_<secret>" });
75
+
76
+ await landing.registerLead({
77
+ email, name, phone, topic: "sales", message, source: "acme.com",
78
+ });
79
+ // Cae en el crm.Lead del tenant dueño de la key.
80
+ ```
81
+
82
+ ### Construcción manual
44
83
 
45
84
  ```ts
46
85
  import { notify } from "@zentto/platform-client";
@@ -0,0 +1,126 @@
1
+ /**
2
+ * AuthClient — cliente tipado para zentto-auth (sso.zentto.net / auth.zentto.net).
3
+ *
4
+ * Expone dos modos:
5
+ * - Cliente user-facing (frontend): cookies httpOnly + Bearer JWT.
6
+ * Métodos: login, refresh, logout, me.
7
+ * - Cliente service-to-service (backend): header `x-service-key`.
8
+ * Métodos: admin.provisionOwner, admin.createMagicLink.
9
+ *
10
+ * setPassword es público (magic-link consumo), no requiere auth.
11
+ */
12
+ import { type HttpConfig, type HttpResult } from "../internal/http.js";
13
+ export interface AuthConfig {
14
+ baseUrl?: string;
15
+ /** Bearer JWT para llamadas user-facing. Opcional — algunos métodos no requieren. */
16
+ accessToken?: string;
17
+ /** Service key (`x-service-key`) para llamadas admin/provisioning. */
18
+ serviceKey?: string;
19
+ timeoutMs?: number;
20
+ retries?: number;
21
+ onError?: HttpConfig["onError"];
22
+ }
23
+ export interface AuthUser {
24
+ userId?: number;
25
+ username?: string;
26
+ email?: string;
27
+ displayName?: string;
28
+ isAdmin?: boolean;
29
+ mfaEnabled?: boolean;
30
+ [k: string]: unknown;
31
+ }
32
+ export interface LoginResponse {
33
+ user: AuthUser;
34
+ accessToken: string;
35
+ refreshToken?: string;
36
+ mfaChallengeToken?: string;
37
+ }
38
+ export interface MeResponse {
39
+ user: AuthUser;
40
+ modulos?: unknown[];
41
+ permisos?: unknown[];
42
+ companyAccesses?: unknown[];
43
+ defaultCompany?: unknown;
44
+ }
45
+ export interface ProvisionOwnerParams {
46
+ email: string;
47
+ fullName: string;
48
+ companyId: number;
49
+ companyCode: string;
50
+ tenantSubdomain?: string;
51
+ role?: string;
52
+ sendMagicLink?: boolean;
53
+ locale?: string;
54
+ }
55
+ export interface ProvisionOwnerResponse {
56
+ userId: number;
57
+ email: string;
58
+ magicLinkUrl?: string;
59
+ alreadyExisted?: boolean;
60
+ }
61
+ export interface MagicLinkParams {
62
+ email: string;
63
+ companyId: number;
64
+ purpose: "set_password" | "reset_password";
65
+ tenantSubdomain?: string;
66
+ ttlMinutes?: number;
67
+ }
68
+ export interface MagicLinkResponse {
69
+ url: string;
70
+ expiresAt: string;
71
+ }
72
+ export declare class AuthClient {
73
+ private readonly cfg;
74
+ private readonly serviceKey?;
75
+ private accessToken?;
76
+ constructor(opts: AuthConfig);
77
+ setAccessToken(token: string | undefined): void;
78
+ private bearer;
79
+ private service;
80
+ login(params: {
81
+ username: string;
82
+ password: string;
83
+ appId?: string;
84
+ }): Promise<HttpResult<LoginResponse>>;
85
+ loginMfa(params: {
86
+ mfaChallengeToken: string;
87
+ mfaToken: string;
88
+ }): Promise<HttpResult<LoginResponse>>;
89
+ refresh(): Promise<HttpResult<{
90
+ ok: boolean;
91
+ accessToken: string;
92
+ }>>;
93
+ logout(): Promise<HttpResult<{
94
+ ok: boolean;
95
+ }>>;
96
+ me(appId?: string): Promise<HttpResult<MeResponse>>;
97
+ registerForApp(params: {
98
+ email: string;
99
+ password: string;
100
+ displayName?: string;
101
+ appId: string;
102
+ role: string;
103
+ metadata?: Record<string, unknown>;
104
+ }): Promise<HttpResult<LoginResponse>>;
105
+ /** Consumo de magic-link (público). */
106
+ setPassword(params: {
107
+ token: string;
108
+ newPassword: string;
109
+ }): Promise<HttpResult<{
110
+ ok: boolean;
111
+ email: string;
112
+ }>>;
113
+ readonly admin: {
114
+ provisionOwner: (params: ProvisionOwnerParams) => Promise<HttpResult<ProvisionOwnerResponse>>;
115
+ createMagicLink: (params: MagicLinkParams) => Promise<HttpResult<MagicLinkResponse>>;
116
+ };
117
+ }
118
+ /**
119
+ * Factory desde env vars estándar:
120
+ * AUTH_SERVICE_URL / AUTH_URL — default https://auth.zentto.net
121
+ * AUTH_SERVICE_KEY — para llamadas admin (backend)
122
+ *
123
+ * Para user-facing, construí manualmente con `new AuthClient({ accessToken })`.
124
+ */
125
+ export declare function authFromEnv(overrides?: Partial<AuthConfig>): AuthClient;
126
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/auth/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAkC,KAAK,UAAU,EAAE,KAAK,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEvG,MAAM,WAAW,UAAU;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,qFAAqF;IACrF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sEAAsE;IACtE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,UAAU,CAAC,SAAS,CAAC,CAAC;CACjC;AAGD,MAAM,WAAW,QAAQ;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,QAAQ,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,QAAQ,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC;IACr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GAMG;AACH,wBAAgB,WAAW,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG,UAAU,CAMvE"}
@@ -0,0 +1,125 @@
1
+ /**
2
+ * AuthClient — cliente tipado para zentto-auth (sso.zentto.net / auth.zentto.net).
3
+ *
4
+ * Expone dos modos:
5
+ * - Cliente user-facing (frontend): cookies httpOnly + Bearer JWT.
6
+ * Métodos: login, refresh, logout, me.
7
+ * - Cliente service-to-service (backend): header `x-service-key`.
8
+ * Métodos: admin.provisionOwner, admin.createMagicLink.
9
+ *
10
+ * setPassword es público (magic-link consumo), no requiere auth.
11
+ */
12
+ import { defaultHttpConfig, httpRequest } from "../internal/http.js";
13
+ // ── Client ──────────────────────────────────────────────────────────────────
14
+ export class AuthClient {
15
+ cfg;
16
+ serviceKey;
17
+ accessToken;
18
+ constructor(opts) {
19
+ this.cfg = defaultHttpConfig({
20
+ baseUrl: opts.baseUrl ?? "https://auth.zentto.net",
21
+ timeoutMs: opts.timeoutMs,
22
+ retries: opts.retries,
23
+ onError: opts.onError,
24
+ });
25
+ this.accessToken = opts.accessToken;
26
+ this.serviceKey = opts.serviceKey;
27
+ }
28
+ setAccessToken(token) {
29
+ this.accessToken = token;
30
+ }
31
+ bearer() {
32
+ return this.accessToken ? { Authorization: `Bearer ${this.accessToken}` } : {};
33
+ }
34
+ service() {
35
+ if (!this.serviceKey)
36
+ throw new Error("AuthClient: serviceKey no configurada para este método");
37
+ return { "x-service-key": this.serviceKey };
38
+ }
39
+ // ── User-facing ──────────────────────────────────────────────────────────
40
+ async login(params) {
41
+ return httpRequest(this.cfg, {
42
+ method: "POST",
43
+ path: "/auth/login",
44
+ body: params,
45
+ credentials: "include",
46
+ });
47
+ }
48
+ async loginMfa(params) {
49
+ return httpRequest(this.cfg, {
50
+ method: "POST",
51
+ path: "/auth/login/mfa",
52
+ body: params,
53
+ credentials: "include",
54
+ });
55
+ }
56
+ async refresh() {
57
+ return httpRequest(this.cfg, {
58
+ method: "POST",
59
+ path: "/auth/refresh",
60
+ credentials: "include",
61
+ });
62
+ }
63
+ async logout() {
64
+ return httpRequest(this.cfg, {
65
+ method: "POST",
66
+ path: "/auth/logout",
67
+ credentials: "include",
68
+ headers: this.bearer(),
69
+ });
70
+ }
71
+ async me(appId) {
72
+ return httpRequest(this.cfg, {
73
+ method: "GET",
74
+ path: "/auth/me",
75
+ query: { appId },
76
+ headers: this.bearer(),
77
+ credentials: "include",
78
+ });
79
+ }
80
+ async registerForApp(params) {
81
+ return httpRequest(this.cfg, {
82
+ method: "POST",
83
+ path: "/auth/register-for-app",
84
+ body: params,
85
+ });
86
+ }
87
+ /** Consumo de magic-link (público). */
88
+ async setPassword(params) {
89
+ return httpRequest(this.cfg, {
90
+ method: "POST",
91
+ path: "/auth/set-password",
92
+ body: params,
93
+ });
94
+ }
95
+ // ── Service-to-service ───────────────────────────────────────────────────
96
+ admin = {
97
+ provisionOwner: (params) => httpRequest(this.cfg, {
98
+ method: "POST",
99
+ path: "/admin/users/provision-owner",
100
+ body: params,
101
+ headers: this.service(),
102
+ }),
103
+ createMagicLink: (params) => httpRequest(this.cfg, {
104
+ method: "POST",
105
+ path: "/admin/users/magic-link",
106
+ body: params,
107
+ headers: this.service(),
108
+ }),
109
+ };
110
+ }
111
+ /**
112
+ * Factory desde env vars estándar:
113
+ * AUTH_SERVICE_URL / AUTH_URL — default https://auth.zentto.net
114
+ * AUTH_SERVICE_KEY — para llamadas admin (backend)
115
+ *
116
+ * Para user-facing, construí manualmente con `new AuthClient({ accessToken })`.
117
+ */
118
+ export function authFromEnv(overrides) {
119
+ return new AuthClient({
120
+ baseUrl: process.env.AUTH_SERVICE_URL ?? process.env.AUTH_URL,
121
+ serviceKey: process.env.AUTH_SERVICE_KEY,
122
+ ...overrides,
123
+ });
124
+ }
125
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/auth/client.ts"],"names":[],"mappings":"AAAA;;;;;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AAE,CAAC,MAA4B,EAA+C,EAAE,CAC5F,WAAW,CAAyB,IAAI,CAAC,GAAG,EAAE;YAC5C,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,8BAA8B;YACpC,IAAI,EAAE,MAAM;YACZ,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE;SACxB,CAAC;QAEJ,eAAe,EAAE,CAAC,MAAuB,EAA0C,EAAE,CACnF,WAAW,CAAoB,IAAI,CAAC,GAAG,EAAE;YACvC,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,yBAAyB;YAC/B,IAAI,EAAE,MAAM;YACZ,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE;SACxB,CAAC;KACL,CAAC;CACH;AAED;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,SAA+B;IACzD,OAAO,IAAI,UAAU,CAAC;QACpB,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,gBAAgB,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ;QAC7D,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,gBAAgB;QACxC,GAAG,SAAS;KACb,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./client.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./client.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
@@ -0,0 +1,113 @@
1
+ /**
2
+ * CacheClient — cliente tipado para zentto-cache (cache.zentto.net).
3
+ *
4
+ * Estandariza el header `x-client-key`. Cada recurso (grid-layouts,
5
+ * report-templates, studio-schemas, blog-posts) expone list/get/put/delete
6
+ * con la misma forma.
7
+ *
8
+ * Identidad del dueño del dato: `companyId` + (`userId` | `email`).
9
+ */
10
+ import { type HttpConfig, type HttpResult } from "../internal/http.js";
11
+ export interface CacheConfig {
12
+ baseUrl?: string;
13
+ /** Header `x-client-key` — identifica la app consumidora. */
14
+ clientKey: string;
15
+ timeoutMs?: number;
16
+ retries?: number;
17
+ onError?: HttpConfig["onError"];
18
+ }
19
+ export interface CacheIdentity {
20
+ companyId: number;
21
+ userId?: number | string;
22
+ email?: string;
23
+ }
24
+ export declare class CacheClient {
25
+ private readonly cfg;
26
+ private readonly clientKey;
27
+ constructor(opts: CacheConfig);
28
+ private headers;
29
+ private resource;
30
+ readonly gridLayouts: {
31
+ list: (id: CacheIdentity) => Promise<HttpResult<{
32
+ ok: boolean;
33
+ } & Record<string, string[]>>>;
34
+ get: (itemId: string, id: CacheIdentity) => Promise<HttpResult<{
35
+ ok: boolean;
36
+ layout?: unknown;
37
+ template?: unknown;
38
+ schema?: unknown;
39
+ post?: unknown;
40
+ updatedAt?: string;
41
+ }>>;
42
+ put: (itemId: string, value: unknown, id: CacheIdentity) => Promise<HttpResult<{
43
+ ok: boolean;
44
+ }>>;
45
+ delete: (itemId: string, id: CacheIdentity) => Promise<HttpResult<{
46
+ ok: boolean;
47
+ }>>;
48
+ };
49
+ readonly reportTemplates: {
50
+ list: (id: CacheIdentity) => Promise<HttpResult<{
51
+ ok: boolean;
52
+ } & Record<string, string[]>>>;
53
+ get: (itemId: string, id: CacheIdentity) => Promise<HttpResult<{
54
+ ok: boolean;
55
+ layout?: unknown;
56
+ template?: unknown;
57
+ schema?: unknown;
58
+ post?: unknown;
59
+ updatedAt?: string;
60
+ }>>;
61
+ put: (itemId: string, value: unknown, id: CacheIdentity) => Promise<HttpResult<{
62
+ ok: boolean;
63
+ }>>;
64
+ delete: (itemId: string, id: CacheIdentity) => Promise<HttpResult<{
65
+ ok: boolean;
66
+ }>>;
67
+ };
68
+ readonly studioSchemas: {
69
+ list: (id: CacheIdentity) => Promise<HttpResult<{
70
+ ok: boolean;
71
+ } & Record<string, string[]>>>;
72
+ get: (itemId: string, id: CacheIdentity) => Promise<HttpResult<{
73
+ ok: boolean;
74
+ layout?: unknown;
75
+ template?: unknown;
76
+ schema?: unknown;
77
+ post?: unknown;
78
+ updatedAt?: string;
79
+ }>>;
80
+ put: (itemId: string, value: unknown, id: CacheIdentity) => Promise<HttpResult<{
81
+ ok: boolean;
82
+ }>>;
83
+ delete: (itemId: string, id: CacheIdentity) => Promise<HttpResult<{
84
+ ok: boolean;
85
+ }>>;
86
+ };
87
+ readonly blogPosts: {
88
+ list: (id: CacheIdentity) => Promise<HttpResult<{
89
+ ok: boolean;
90
+ } & Record<string, string[]>>>;
91
+ get: (itemId: string, id: CacheIdentity) => Promise<HttpResult<{
92
+ ok: boolean;
93
+ layout?: unknown;
94
+ template?: unknown;
95
+ schema?: unknown;
96
+ post?: unknown;
97
+ updatedAt?: string;
98
+ }>>;
99
+ put: (itemId: string, value: unknown, id: CacheIdentity) => Promise<HttpResult<{
100
+ ok: boolean;
101
+ }>>;
102
+ delete: (itemId: string, id: CacheIdentity) => Promise<HttpResult<{
103
+ ok: boolean;
104
+ }>>;
105
+ };
106
+ }
107
+ /**
108
+ * Factory desde env vars:
109
+ * CACHE_URL — default https://cache.zentto.net
110
+ * CACHE_APP_KEY — header x-client-key (obligatoria)
111
+ */
112
+ export declare function cacheFromEnv(overrides?: Partial<CacheConfig>): CacheClient;
113
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/cache/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAkC,KAAK,UAAU,EAAE,KAAK,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEvG,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,6DAA6D;IAC7D,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAA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4B,OAAO;;yBAiBxE,MAAM,MAAM,aAAa;gBAA4B,OAAO;;MAajB;CACjE;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,WAAW,CAM1E"}
@@ -0,0 +1,87 @@
1
+ /**
2
+ * CacheClient — cliente tipado para zentto-cache (cache.zentto.net).
3
+ *
4
+ * Estandariza el header `x-client-key`. Cada recurso (grid-layouts,
5
+ * report-templates, studio-schemas, blog-posts) expone list/get/put/delete
6
+ * con la misma forma.
7
+ *
8
+ * Identidad del dueño del dato: `companyId` + (`userId` | `email`).
9
+ */
10
+ import { defaultHttpConfig, httpRequest } from "../internal/http.js";
11
+ function identityQuery(id) {
12
+ return {
13
+ companyId: id.companyId,
14
+ userId: id.userId !== undefined ? String(id.userId) : undefined,
15
+ email: id.email,
16
+ };
17
+ }
18
+ export class CacheClient {
19
+ cfg;
20
+ clientKey;
21
+ constructor(opts) {
22
+ this.cfg = defaultHttpConfig({
23
+ baseUrl: opts.baseUrl ?? "https://cache.zentto.net",
24
+ timeoutMs: opts.timeoutMs,
25
+ retries: opts.retries,
26
+ onError: opts.onError,
27
+ });
28
+ this.clientKey = opts.clientKey;
29
+ }
30
+ headers() {
31
+ return { "x-client-key": this.clientKey };
32
+ }
33
+ resource(name) {
34
+ return {
35
+ list: (id) => httpRequest(this.cfg, {
36
+ method: "GET",
37
+ path: `/v1/${name}`,
38
+ query: identityQuery(id),
39
+ headers: this.headers(),
40
+ }),
41
+ get: (itemId, id) => httpRequest(this.cfg, {
42
+ method: "GET",
43
+ path: `/v1/${name}/${encodeURIComponent(itemId)}`,
44
+ query: identityQuery(id),
45
+ headers: this.headers(),
46
+ }),
47
+ put: (itemId, value, id) => httpRequest(this.cfg, {
48
+ method: "PUT",
49
+ path: `/v1/${name}/${encodeURIComponent(itemId)}`,
50
+ body: {
51
+ companyId: id.companyId,
52
+ userId: id.userId,
53
+ email: id.email,
54
+ // El campo varía según el recurso; mandamos todos los shapes vistos en el server.
55
+ layout: value,
56
+ template: value,
57
+ schema: value,
58
+ post: value,
59
+ },
60
+ headers: this.headers(),
61
+ }),
62
+ delete: (itemId, id) => httpRequest(this.cfg, {
63
+ method: "DELETE",
64
+ path: `/v1/${name}/${encodeURIComponent(itemId)}`,
65
+ query: identityQuery(id),
66
+ headers: this.headers(),
67
+ }),
68
+ };
69
+ }
70
+ gridLayouts = this.resource("grid-layouts");
71
+ reportTemplates = this.resource("report-templates");
72
+ studioSchemas = this.resource("studio-schemas");
73
+ blogPosts = this.resource("blog-posts");
74
+ }
75
+ /**
76
+ * Factory desde env vars:
77
+ * CACHE_URL — default https://cache.zentto.net
78
+ * CACHE_APP_KEY — header x-client-key (obligatoria)
79
+ */
80
+ export function cacheFromEnv(overrides) {
81
+ return new CacheClient({
82
+ baseUrl: process.env.CACHE_URL,
83
+ clientKey: process.env.CACHE_APP_KEY ?? "",
84
+ ...overrides,
85
+ });
86
+ }
87
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/cache/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAoC,MAAM,qBAAqB,CAAC;AAiBvG,SAAS,aAAa,CAAC,EAAiB;IACtC,OAAO;QACL,SAAS,EAAE,EAAE,CAAC,SAAS;QACvB,MAAM,EAAE,EAAE,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS;QAC/D,KAAK,EAAE,EAAE,CAAC,KAAK;KAChB,CAAC;AACJ,CAAC;AAID,MAAM,OAAO,WAAW;IACL,GAAG,CAAa;IAChB,SAAS,CAAS;IAEnC,YAAY,IAAiB;QAC3B,IAAI,CAAC,GAAG,GAAG,iBAAiB,CAAC;YAC3B,OAAO,EAAE,IAAI,CAAC,OAAO,IAAI,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E,KAAK;oBACb,QAAQ,EAAE,KAAK;oBACf,MAAM,EAAE,KAAK;oBACb,IAAI,EAAE,KAAK;iBACZ;gBACD,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE;aACxB,CAAC;YAEJ,MAAM,EAAE,CAAC,MAAc,EAAE,EAAiB,EAAwC,EAAE,CAClF,WAAW,CAAC,IAAI,CAAC,GAAG,EAAE;gBACpB,MAAM,EAAE,QAAQ;gBAChB,IAAI,EAAE,OAAO,IAAI,IAAI,kBAAkB,CAAC,MAAM,CAAC,EAAE;gBACjD,KAAK,EAAE,aAAa,CAAC,EAAE,CAAC;gBACxB,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE;aACxB,CAAC;SACL,CAAC;IACJ,CAAC;IAEQ,WAAW,GAAO,IAAI,CAAC,QAAQ,CAAU,cAAc,CAAC,CAAC;IACzD,eAAe,GAAG,IAAI,CAAC,QAAQ,CAAU,kBAAkB,CAAC,CAAC;IAC7D,aAAa,GAAK,IAAI,CAAC,QAAQ,CAAU,gBAAgB,CAAC,CAAC;IAC3D,SAAS,GAAS,IAAI,CAAC,QAAQ,CAAU,YAAY,CAAC,CAAC;CACjE;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,SAAgC;IAC3D,OAAO,IAAI,WAAW,CAAC;QACrB,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS;QAC9B,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI,EAAE;QAC1C,GAAG,SAAS;KACb,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./client.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cache/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./client.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cache/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,2 +1,5 @@
1
1
  export * as notify from "./notify/index.js";
2
+ export * as auth from "./auth/index.js";
3
+ export * as cache from "./cache/index.js";
4
+ export * as landing from "./landing/index.js";
2
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAC;AAC5C,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,kBAAkB,CAAC;AAC1C,OAAO,KAAK,OAAO,MAAM,oBAAoB,CAAC"}
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
- // Barrel del platform-client. Cada submódulo expone su propia API; acá
2
- // re-exportamos en namespaces para llamadas tipo `platform.notify.email.send(...)`.
1
+ // Barrel de @zentto/platform-client. Un submódulo por servicio de plataforma.
2
+ // Uso: `import { notify } from "@zentto/platform-client"` o import directo
3
+ // del subpath `@zentto/platform-client/notify`.
3
4
  export * as notify from "./notify/index.js";
4
- // Placeholders se llenan cuando se migren cache/auth/landing al mismo patrón.
5
- // export * as cache from "./cache/index.js";
6
- // export * as auth from "./auth/index.js";
7
- // export * as landing from "./landing/index.js";
5
+ export * as auth from "./auth/index.js";
6
+ export * as cache from "./cache/index.js";
7
+ export * as landing from "./landing/index.js";
8
8
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,oFAAoF;AAEpF,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAC;AAE5C,gFAAgF;AAChF,6CAA6C;AAC7C,2CAA2C;AAC3C,iDAAiD"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,2EAA2E;AAC3E,gDAAgD;AAEhD,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAC;AAC5C,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,kBAAkB,CAAC;AAC1C,OAAO,KAAK,OAAO,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * HTTP helper compartido entre submódulos.
3
+ *
4
+ * - Retries con backoff exponencial ante errores de red o 5xx.
5
+ * - Sin retry en 4xx (es error del caller).
6
+ * - Timeout por request.
7
+ * - onError hook para observability.
8
+ * - No lanza: siempre retorna Result<T> (ok/error). Los callers deciden si
9
+ * propagar o no.
10
+ */
11
+ export interface HttpConfig {
12
+ baseUrl: string;
13
+ timeoutMs: number;
14
+ retries: number;
15
+ onError: (err: Error, ctx: {
16
+ path: string;
17
+ attempt: number;
18
+ }) => void;
19
+ }
20
+ export interface HttpResult<T = unknown> {
21
+ ok: boolean;
22
+ status?: number;
23
+ data?: T;
24
+ error?: string;
25
+ }
26
+ export interface RequestOptions {
27
+ method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
28
+ path: string;
29
+ body?: object;
30
+ headers?: Record<string, string>;
31
+ query?: Record<string, string | number | undefined | null>;
32
+ /** Enviar cookies (para endpoints que usan cookie httpOnly). */
33
+ credentials?: "include" | "omit";
34
+ }
35
+ export declare function httpRequest<T = unknown>(cfg: HttpConfig, opts: RequestOptions): Promise<HttpResult<T>>;
36
+ export declare function defaultHttpConfig(overrides: Partial<HttpConfig> & {
37
+ baseUrl: string;
38
+ }): HttpConfig;
39
+ //# sourceMappingURL=http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"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+ /**
2
+ * HTTP helper compartido entre submódulos.
3
+ *
4
+ * - Retries con backoff exponencial ante errores de red o 5xx.
5
+ * - Sin retry en 4xx (es error del caller).
6
+ * - Timeout por request.
7
+ * - onError hook para observability.
8
+ * - No lanza: siempre retorna Result<T> (ok/error). Los callers deciden si
9
+ * propagar o no.
10
+ */
11
+ function buildUrl(baseUrl, path, query) {
12
+ const url = `${baseUrl.replace(/\/$/, "")}${path.startsWith("/") ? path : `/${path}`}`;
13
+ if (!query)
14
+ return url;
15
+ const params = new URLSearchParams();
16
+ for (const [k, v] of Object.entries(query)) {
17
+ if (v === undefined || v === null)
18
+ continue;
19
+ params.set(k, String(v));
20
+ }
21
+ const qs = params.toString();
22
+ return qs ? `${url}?${qs}` : url;
23
+ }
24
+ export async function httpRequest(cfg, opts) {
25
+ const url = buildUrl(cfg.baseUrl, opts.path, opts.query);
26
+ const headers = {
27
+ "Content-Type": "application/json",
28
+ ...opts.headers,
29
+ };
30
+ let lastErr;
31
+ for (let attempt = 0; attempt <= cfg.retries; attempt++) {
32
+ try {
33
+ const res = await fetch(url, {
34
+ method: opts.method,
35
+ headers,
36
+ body: opts.body ? JSON.stringify(opts.body) : undefined,
37
+ credentials: opts.credentials,
38
+ signal: AbortSignal.timeout(cfg.timeoutMs),
39
+ });
40
+ const json = (await res.json().catch(() => ({})));
41
+ if (res.ok) {
42
+ return { ok: true, status: res.status, data: json };
43
+ }
44
+ // 4xx: sin retry — es error del caller / auth / validación.
45
+ if (res.status >= 400 && res.status < 500) {
46
+ return {
47
+ ok: false,
48
+ status: res.status,
49
+ error: json.error ?? json.message ?? `HTTP ${res.status}`,
50
+ };
51
+ }
52
+ lastErr = new Error(`HTTP ${res.status}`);
53
+ }
54
+ catch (err) {
55
+ lastErr = err;
56
+ }
57
+ if (attempt < cfg.retries) {
58
+ cfg.onError(lastErr, { path: opts.path, attempt });
59
+ await new Promise((r) => setTimeout(r, 250 * Math.pow(2, attempt)));
60
+ }
61
+ }
62
+ const err = lastErr ?? new Error("unknown error");
63
+ cfg.onError(err, { path: opts.path, attempt: cfg.retries });
64
+ return { ok: false, error: err.message };
65
+ }
66
+ export function defaultHttpConfig(overrides) {
67
+ return {
68
+ baseUrl: overrides.baseUrl,
69
+ timeoutMs: overrides.timeoutMs ?? 10_000,
70
+ retries: Math.max(0, overrides.retries ?? 1),
71
+ onError: overrides.onError ?? (() => { }),
72
+ };
73
+ }
74
+ //# sourceMappingURL=http.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/internal/http.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AA0BH,SAAS,QAAQ,CAAC,OAAe,EAAE,IAAY,EAAE,KAA+B;IAC9E,MAAM,GAAG,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,EAAE,CAAC;IACvF,IAAI,CAAC,KAAK;QAAE,OAAO,GAAG,CAAC;IACvB,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;IACrC,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3C,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,IAAI;YAAE,SAAS;QAC5C,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3B,CAAC;IACD,MAAM,EAAE,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;IAC7B,OAAO,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;AACnC,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,GAAe,EACf,IAAoB;IAEpB,MAAM,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1
+ /**
2
+ * LandingClient — cliente tipado para el endpoint público de leads del
3
+ * ERP Zentto (POST https://api.zentto.net/api/landing/register).
4
+ *
5
+ * Útil para sitios externos de tenants clientes (acme.com) que quieren
6
+ * integrar su formulario de contacto sin reescribir fetch a mano. Resuelve
7
+ * el tenant destino vía `X-Tenant-Key` emitido desde el CRM del cliente.
8
+ *
9
+ * Para el landing propio de Zentto (zentto.net), la Pages Function ya
10
+ * llama al ERP directamente — no necesita este cliente.
11
+ */
12
+ import { type HttpConfig, type HttpResult } from "../internal/http.js";
13
+ export interface LandingConfig {
14
+ baseUrl?: string;
15
+ /** Header `X-Tenant-Key` — PublicApiKey emitida desde el CRM del tenant. */
16
+ tenantKey?: string;
17
+ timeoutMs?: number;
18
+ retries?: number;
19
+ onError?: HttpConfig["onError"];
20
+ }
21
+ export interface RegisterLeadParams {
22
+ email: string;
23
+ name: string;
24
+ company?: string;
25
+ country?: string;
26
+ phone?: string;
27
+ source?: string;
28
+ topic?: string;
29
+ message?: string;
30
+ }
31
+ export interface RegisterLeadResponse {
32
+ ok: boolean;
33
+ mensaje?: string;
34
+ targetCompanyId?: number | null;
35
+ zentto_registered?: boolean;
36
+ paddle_customer_id?: string | null;
37
+ }
38
+ export declare class LandingClient {
39
+ private readonly cfg;
40
+ private readonly tenantKey?;
41
+ constructor(opts: LandingConfig);
42
+ registerLead(params: RegisterLeadParams): Promise<HttpResult<RegisterLeadResponse>>;
43
+ }
44
+ /**
45
+ * Factory desde env vars:
46
+ * ZENTTO_API_URL — default https://api.zentto.net
47
+ * ZENTTO_TENANT_KEY — PublicApiKey del tenant (si el caller es externo)
48
+ */
49
+ export declare function landingFromEnv(overrides?: Partial<LandingConfig>): LandingClient;
50
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/landing/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAkC,KAAK,UAAU,EAA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* ERP Zentto (POST https://api.zentto.net/api/landing/register).
4
+ *
5
+ * Útil para sitios externos de tenants clientes (acme.com) que quieren
6
+ * integrar su formulario de contacto sin reescribir fetch a mano. Resuelve
7
+ * el tenant destino vía `X-Tenant-Key` emitido desde el CRM del cliente.
8
+ *
9
+ * Para el landing propio de Zentto (zentto.net), la Pages Function ya
10
+ * llama al ERP directamente — no necesita este cliente.
11
+ */
12
+ import { defaultHttpConfig, httpRequest } from "../internal/http.js";
13
+ export class LandingClient {
14
+ cfg;
15
+ tenantKey;
16
+ constructor(opts) {
17
+ this.cfg = defaultHttpConfig({
18
+ baseUrl: opts.baseUrl ?? "https://api.zentto.net",
19
+ timeoutMs: opts.timeoutMs,
20
+ retries: opts.retries,
21
+ onError: opts.onError,
22
+ });
23
+ this.tenantKey = opts.tenantKey;
24
+ }
25
+ async registerLead(params) {
26
+ return httpRequest(this.cfg, {
27
+ method: "POST",
28
+ path: "/api/landing/register",
29
+ body: params,
30
+ headers: this.tenantKey ? { "X-Tenant-Key": this.tenantKey } : undefined,
31
+ });
32
+ }
33
+ }
34
+ /**
35
+ * Factory desde env vars:
36
+ * ZENTTO_API_URL — default https://api.zentto.net
37
+ * ZENTTO_TENANT_KEY — PublicApiKey del tenant (si el caller es externo)
38
+ */
39
+ export function landingFromEnv(overrides) {
40
+ return new LandingClient({
41
+ baseUrl: process.env.ZENTTO_API_URL,
42
+ tenantKey: process.env.ZENTTO_TENANT_KEY,
43
+ ...overrides,
44
+ });
45
+ }
46
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/landing/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAoC,MAAM,qBAAqB,CAAC;AA8BvG,MAAM,OAAO,aAAa;IACP,GAAG,CAAa;IAChB,SAAS,CAAU;IAEpC,YAAY,IAAmB;QAC7B,IAAI,CAAC,GAAG,GAAG,iBAAiB,CAAC;YAC3B,OAAO,EAAE,IAAI,CAAC,OAAO,IAAI,wBAAwB;YACjD,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC,CAAC;QACH,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;IAClC,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,MAA0B;QAC3C,OAAO,WAAW,CAAuB,IAAI,CAAC,GAAG,EAAE;YACjD,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,uBAAuB;YAC7B,IAAI,EAAE,MAAM;YACZ,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,SAAS;SACzE,CAAC,CAAC;IACL,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,SAAkC;IAC/D,OAAO,IAAI,aAAa,CAAC;QACvB,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,cAAc;QACnC,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,iBAAiB;QACxC,GAAG,SAAS;KACb,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./client.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/landing/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./client.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/landing/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zentto/platform-client",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Cliente tipado para los servicios de plataforma Zentto (notify, cache, auth, landing). Uso oficial en ERP, verticals y sitios de tenants clientes.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -13,6 +13,18 @@
13
13
  "./notify": {
14
14
  "types": "./dist/notify/index.d.ts",
15
15
  "import": "./dist/notify/index.js"
16
+ },
17
+ "./auth": {
18
+ "types": "./dist/auth/index.d.ts",
19
+ "import": "./dist/auth/index.js"
20
+ },
21
+ "./cache": {
22
+ "types": "./dist/cache/index.d.ts",
23
+ "import": "./dist/cache/index.js"
24
+ },
25
+ "./landing": {
26
+ "types": "./dist/landing/index.d.ts",
27
+ "import": "./dist/landing/index.js"
16
28
  }
17
29
  },
18
30
  "files": [