@pimia/sdk 0.11.0 → 0.12.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/api.d.ts +851 -13
- package/dist/client.d.ts +230 -0
- package/dist/client.js +52 -0
- package/dist/index.d.ts +9 -1
- package/dist/index.js +8 -0
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -23,12 +23,19 @@ export type CustomerResource = Schemas['CustomerResource'];
|
|
|
23
23
|
export type InvoiceResource = Schemas['InvoiceResource'];
|
|
24
24
|
/** Presupuesto tal y como lo devuelve la API. */
|
|
25
25
|
export type EstimateResource = Schemas['EstimateResource'];
|
|
26
|
+
/** Contrato de servicio tal y como lo devuelve la API. */
|
|
27
|
+
export type ContractResource = Schemas['ContractResource'];
|
|
26
28
|
/** Cuerpo de alta/edición de cliente. Incluye `customFields`. */
|
|
27
29
|
export type CustomerRequest = Schemas['CustomerRequest'];
|
|
28
30
|
/** Cuerpo de alta/edición de factura. Incluye `customFields`. */
|
|
29
31
|
export type InvoicesRequest = Schemas['InvoicesRequest'];
|
|
30
32
|
/** Cuerpo de alta/edición de presupuesto. Incluye `customFields`. */
|
|
31
33
|
export type EstimatesRequest = Schemas['EstimatesRequest'];
|
|
34
|
+
/**
|
|
35
|
+
* Cuerpo de alta/edición de contrato. Sin `status` a propósito: el ciclo de
|
|
36
|
+
* vida va por sus acciones (`activate`/`cancel`/`renew`), nunca por el PUT.
|
|
37
|
+
*/
|
|
38
|
+
export type ContractRequest = Schemas['ContractRequest'];
|
|
32
39
|
/**
|
|
33
40
|
* El sobre `{ data: … }` de Laravel para las escrituras que el spec **no
|
|
34
41
|
* tipa**.
|
|
@@ -561,6 +568,229 @@ export declare class PimiaClient {
|
|
|
561
568
|
currency?: components["schemas"]["CurrencyResource"] | null;
|
|
562
569
|
}>>;
|
|
563
570
|
};
|
|
571
|
+
/**
|
|
572
|
+
* Contratos de servicio. Exige `contracts:read` / `contracts:write`.
|
|
573
|
+
*
|
|
574
|
+
* Un contrato GOBIERNA facturas recurrentes: su periodo se vuelve los
|
|
575
|
+
* límites de la recurrente. El ciclo de vida va por sus acciones — el
|
|
576
|
+
* `PUT` no acepta `status`, y fuera de borrador solo toca lo descriptivo
|
|
577
|
+
* (el periodo se cambia con `renew`, que sí propaga).
|
|
578
|
+
*/
|
|
579
|
+
get contracts(): {
|
|
580
|
+
list: (query?: RequestOptions["query"], options?: ReadOptions) => Promise<{
|
|
581
|
+
data: components["schemas"]["ContractResource"][];
|
|
582
|
+
meta: {
|
|
583
|
+
contract_total_count: number;
|
|
584
|
+
};
|
|
585
|
+
}>;
|
|
586
|
+
get: (id: number | string, options?: ReadOptions) => Promise<{
|
|
587
|
+
data: components["schemas"]["ContractResource"];
|
|
588
|
+
}>;
|
|
589
|
+
create: (body: ContractRequest, options?: WriteOptions) => Promise<ResourceEnvelope<{
|
|
590
|
+
id: number;
|
|
591
|
+
title: string;
|
|
592
|
+
description: string | null;
|
|
593
|
+
contract_number: string | null;
|
|
594
|
+
customer_id: number | null;
|
|
595
|
+
company_id: number | null;
|
|
596
|
+
creator_id: number | null;
|
|
597
|
+
currency_id: number | null;
|
|
598
|
+
status: string;
|
|
599
|
+
ha_vencido: boolean;
|
|
600
|
+
starts_at: string | null;
|
|
601
|
+
ends_at: string | null;
|
|
602
|
+
amount: number | null;
|
|
603
|
+
billing_every: string;
|
|
604
|
+
billing_anchor_day: number | null;
|
|
605
|
+
renewal_mode: string;
|
|
606
|
+
notice_days: number | null;
|
|
607
|
+
notice_days_effective: number;
|
|
608
|
+
has_document: boolean;
|
|
609
|
+
estimate_id: number | null;
|
|
610
|
+
cancelled_at: string | null;
|
|
611
|
+
fields?: components["schemas"]["CustomFieldValueResource"][];
|
|
612
|
+
customer?: components["schemas"]["CustomerResource"] | null;
|
|
613
|
+
estimate?: components["schemas"]["EstimateResource"] | null;
|
|
614
|
+
recurring_invoices?: components["schemas"]["RecurringInvoiceResource"][];
|
|
615
|
+
invoices?: components["schemas"]["InvoiceResource"][];
|
|
616
|
+
}>>;
|
|
617
|
+
update: (id: number | string, body: ContractRequest, options?: WriteOptions) => Promise<ResourceEnvelope<{
|
|
618
|
+
id: number;
|
|
619
|
+
title: string;
|
|
620
|
+
description: string | null;
|
|
621
|
+
contract_number: string | null;
|
|
622
|
+
customer_id: number | null;
|
|
623
|
+
company_id: number | null;
|
|
624
|
+
creator_id: number | null;
|
|
625
|
+
currency_id: number | null;
|
|
626
|
+
status: string;
|
|
627
|
+
ha_vencido: boolean;
|
|
628
|
+
starts_at: string | null;
|
|
629
|
+
ends_at: string | null;
|
|
630
|
+
amount: number | null;
|
|
631
|
+
billing_every: string;
|
|
632
|
+
billing_anchor_day: number | null;
|
|
633
|
+
renewal_mode: string;
|
|
634
|
+
notice_days: number | null;
|
|
635
|
+
notice_days_effective: number;
|
|
636
|
+
has_document: boolean;
|
|
637
|
+
estimate_id: number | null;
|
|
638
|
+
cancelled_at: string | null;
|
|
639
|
+
fields?: components["schemas"]["CustomFieldValueResource"][];
|
|
640
|
+
customer?: components["schemas"]["CustomerResource"] | null;
|
|
641
|
+
estimate?: components["schemas"]["EstimateResource"] | null;
|
|
642
|
+
recurring_invoices?: components["schemas"]["RecurringInvoiceResource"][];
|
|
643
|
+
invoices?: components["schemas"]["InvoiceResource"][];
|
|
644
|
+
}>>;
|
|
645
|
+
/**
|
|
646
|
+
* Activa el contrato: DRAFT → ACTIVE, lo numera, y crea la recurrente
|
|
647
|
+
* gobernada — o adopta la de `recurringInvoiceId` (misma empresa y
|
|
648
|
+
* mismo cliente; sus líneas e impuestos no se tocan).
|
|
649
|
+
*
|
|
650
|
+
* Exige `contracts:write` **e** `invoices:write`: la recurrente que
|
|
651
|
+
* nace emitirá facturas por su cuenta. Manda `idempotencyKey` —una
|
|
652
|
+
* clave estable del estilo `contract:{id}:activate`— y el reintento
|
|
653
|
+
* tras un timeout no te creará una segunda recurrente.
|
|
654
|
+
*/
|
|
655
|
+
activate: (id: number | string, options?: WriteOptions & {
|
|
656
|
+
recurringInvoiceId?: number | string;
|
|
657
|
+
}) => Promise<ResourceEnvelope<{
|
|
658
|
+
id: number;
|
|
659
|
+
title: string;
|
|
660
|
+
description: string | null;
|
|
661
|
+
contract_number: string | null;
|
|
662
|
+
customer_id: number | null;
|
|
663
|
+
company_id: number | null;
|
|
664
|
+
creator_id: number | null;
|
|
665
|
+
currency_id: number | null;
|
|
666
|
+
status: string;
|
|
667
|
+
ha_vencido: boolean;
|
|
668
|
+
starts_at: string | null;
|
|
669
|
+
ends_at: string | null;
|
|
670
|
+
amount: number | null;
|
|
671
|
+
billing_every: string;
|
|
672
|
+
billing_anchor_day: number | null;
|
|
673
|
+
renewal_mode: string;
|
|
674
|
+
notice_days: number | null;
|
|
675
|
+
notice_days_effective: number;
|
|
676
|
+
has_document: boolean;
|
|
677
|
+
estimate_id: number | null;
|
|
678
|
+
cancelled_at: string | null;
|
|
679
|
+
fields?: components["schemas"]["CustomFieldValueResource"][];
|
|
680
|
+
customer?: components["schemas"]["CustomerResource"] | null;
|
|
681
|
+
estimate?: components["schemas"]["EstimateResource"] | null;
|
|
682
|
+
recurring_invoices?: components["schemas"]["RecurringInvoiceResource"][];
|
|
683
|
+
invoices?: components["schemas"]["InvoiceResource"][];
|
|
684
|
+
}>>;
|
|
685
|
+
/**
|
|
686
|
+
* Cancela: sus recurrentes quedan en pausa (`ON_HOLD`) y las facturas
|
|
687
|
+
* emitidas conservan el rastro entero.
|
|
688
|
+
*/
|
|
689
|
+
cancel: (id: number | string, options?: WriteOptions) => Promise<ResourceEnvelope<{
|
|
690
|
+
id: number;
|
|
691
|
+
title: string;
|
|
692
|
+
description: string | null;
|
|
693
|
+
contract_number: string | null;
|
|
694
|
+
customer_id: number | null;
|
|
695
|
+
company_id: number | null;
|
|
696
|
+
creator_id: number | null;
|
|
697
|
+
currency_id: number | null;
|
|
698
|
+
status: string;
|
|
699
|
+
ha_vencido: boolean;
|
|
700
|
+
starts_at: string | null;
|
|
701
|
+
ends_at: string | null;
|
|
702
|
+
amount: number | null;
|
|
703
|
+
billing_every: string;
|
|
704
|
+
billing_anchor_day: number | null;
|
|
705
|
+
renewal_mode: string;
|
|
706
|
+
notice_days: number | null;
|
|
707
|
+
notice_days_effective: number;
|
|
708
|
+
has_document: boolean;
|
|
709
|
+
estimate_id: number | null;
|
|
710
|
+
cancelled_at: string | null;
|
|
711
|
+
fields?: components["schemas"]["CustomFieldValueResource"][];
|
|
712
|
+
customer?: components["schemas"]["CustomerResource"] | null;
|
|
713
|
+
estimate?: components["schemas"]["EstimateResource"] | null;
|
|
714
|
+
recurring_invoices?: components["schemas"]["RecurringInvoiceResource"][];
|
|
715
|
+
invoices?: components["schemas"]["InvoiceResource"][];
|
|
716
|
+
}>>;
|
|
717
|
+
/**
|
|
718
|
+
* Renovación manual: extiende `ends_at` (posterior al fin actual) y lo
|
|
719
|
+
* propaga a las recurrentes gobernadas, reviviendo las completadas por
|
|
720
|
+
* el límite viejo.
|
|
721
|
+
*/
|
|
722
|
+
renew: (id: number | string, endsAt: string, options?: WriteOptions) => Promise<ResourceEnvelope<{
|
|
723
|
+
id: number;
|
|
724
|
+
title: string;
|
|
725
|
+
description: string | null;
|
|
726
|
+
contract_number: string | null;
|
|
727
|
+
customer_id: number | null;
|
|
728
|
+
company_id: number | null;
|
|
729
|
+
creator_id: number | null;
|
|
730
|
+
currency_id: number | null;
|
|
731
|
+
status: string;
|
|
732
|
+
ha_vencido: boolean;
|
|
733
|
+
starts_at: string | null;
|
|
734
|
+
ends_at: string | null;
|
|
735
|
+
amount: number | null;
|
|
736
|
+
billing_every: string;
|
|
737
|
+
billing_anchor_day: number | null;
|
|
738
|
+
renewal_mode: string;
|
|
739
|
+
notice_days: number | null;
|
|
740
|
+
notice_days_effective: number;
|
|
741
|
+
has_document: boolean;
|
|
742
|
+
estimate_id: number | null;
|
|
743
|
+
cancelled_at: string | null;
|
|
744
|
+
fields?: components["schemas"]["CustomFieldValueResource"][];
|
|
745
|
+
customer?: components["schemas"]["CustomerResource"] | null;
|
|
746
|
+
estimate?: components["schemas"]["EstimateResource"] | null;
|
|
747
|
+
recurring_invoices?: components["schemas"]["RecurringInvoiceResource"][];
|
|
748
|
+
invoices?: components["schemas"]["InvoiceResource"][];
|
|
749
|
+
}>>;
|
|
750
|
+
/**
|
|
751
|
+
* El enlace del PDF para el cliente final: URL FIRMADA con caducidad.
|
|
752
|
+
* Un contrato en borrador —sin número— es un 422.
|
|
753
|
+
*/
|
|
754
|
+
sharedLink: (id: number | string, options?: ReadOptions) => Promise<{
|
|
755
|
+
data: {
|
|
756
|
+
url: string;
|
|
757
|
+
expires_at: string;
|
|
758
|
+
};
|
|
759
|
+
}>;
|
|
760
|
+
/**
|
|
761
|
+
* Sube (o reemplaza: un fichero por colección) el contrato FIRMADO —
|
|
762
|
+
* el papel escaneado. Multiparte por `POST` dedicado; el `FormData` lo
|
|
763
|
+
* arma el atajo, no le pongas `content-type`.
|
|
764
|
+
*/
|
|
765
|
+
uploadDocument: (id: number | string, document: Blob, options?: WriteOptions) => Promise<ResourceEnvelope<{
|
|
766
|
+
id: number;
|
|
767
|
+
title: string;
|
|
768
|
+
description: string | null;
|
|
769
|
+
contract_number: string | null;
|
|
770
|
+
customer_id: number | null;
|
|
771
|
+
company_id: number | null;
|
|
772
|
+
creator_id: number | null;
|
|
773
|
+
currency_id: number | null;
|
|
774
|
+
status: string;
|
|
775
|
+
ha_vencido: boolean;
|
|
776
|
+
starts_at: string | null;
|
|
777
|
+
ends_at: string | null;
|
|
778
|
+
amount: number | null;
|
|
779
|
+
billing_every: string;
|
|
780
|
+
billing_anchor_day: number | null;
|
|
781
|
+
renewal_mode: string;
|
|
782
|
+
notice_days: number | null;
|
|
783
|
+
notice_days_effective: number;
|
|
784
|
+
has_document: boolean;
|
|
785
|
+
estimate_id: number | null;
|
|
786
|
+
cancelled_at: string | null;
|
|
787
|
+
fields?: components["schemas"]["CustomFieldValueResource"][];
|
|
788
|
+
customer?: components["schemas"]["CustomerResource"] | null;
|
|
789
|
+
estimate?: components["schemas"]["EstimateResource"] | null;
|
|
790
|
+
recurring_invoices?: components["schemas"]["RecurringInvoiceResource"][];
|
|
791
|
+
invoices?: components["schemas"]["InvoiceResource"][];
|
|
792
|
+
}>>;
|
|
793
|
+
};
|
|
564
794
|
get<T = unknown>(path: string, query?: RequestOptions['query'], options?: ReadOptions): Promise<T>;
|
|
565
795
|
post<T = unknown>(path: string, body?: unknown, options?: WriteOptions): Promise<T>;
|
|
566
796
|
put<T = unknown>(path: string, body?: unknown, options?: WriteOptions): Promise<T>;
|
package/dist/client.js
CHANGED
|
@@ -112,6 +112,58 @@ export class PimiaClient {
|
|
|
112
112
|
},
|
|
113
113
|
};
|
|
114
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Contratos de servicio. Exige `contracts:read` / `contracts:write`.
|
|
117
|
+
*
|
|
118
|
+
* Un contrato GOBIERNA facturas recurrentes: su periodo se vuelve los
|
|
119
|
+
* límites de la recurrente. El ciclo de vida va por sus acciones — el
|
|
120
|
+
* `PUT` no acepta `status`, y fuera de borrador solo toca lo descriptivo
|
|
121
|
+
* (el periodo se cambia con `renew`, que sí propaga).
|
|
122
|
+
*/
|
|
123
|
+
get contracts() {
|
|
124
|
+
return {
|
|
125
|
+
list: (query, options) => this.get('/contracts', query, options),
|
|
126
|
+
get: (id, options) => this.get(`/contracts/${id}`, undefined, options),
|
|
127
|
+
create: (body, options) => this.post('/contracts', body, options),
|
|
128
|
+
update: (id, body, options) => this.put(`/contracts/${id}`, body, options),
|
|
129
|
+
/**
|
|
130
|
+
* Activa el contrato: DRAFT → ACTIVE, lo numera, y crea la recurrente
|
|
131
|
+
* gobernada — o adopta la de `recurringInvoiceId` (misma empresa y
|
|
132
|
+
* mismo cliente; sus líneas e impuestos no se tocan).
|
|
133
|
+
*
|
|
134
|
+
* Exige `contracts:write` **e** `invoices:write`: la recurrente que
|
|
135
|
+
* nace emitirá facturas por su cuenta. Manda `idempotencyKey` —una
|
|
136
|
+
* clave estable del estilo `contract:{id}:activate`— y el reintento
|
|
137
|
+
* tras un timeout no te creará una segunda recurrente.
|
|
138
|
+
*/
|
|
139
|
+
activate: (id, options) => {
|
|
140
|
+
const { recurringInvoiceId, ...resto } = options ?? {};
|
|
141
|
+
return this.post(`/contracts/${id}/activate`, recurringInvoiceId === undefined ? {} : { recurring_invoice_id: recurringInvoiceId }, resto);
|
|
142
|
+
},
|
|
143
|
+
/**
|
|
144
|
+
* Cancela: sus recurrentes quedan en pausa (`ON_HOLD`) y las facturas
|
|
145
|
+
* emitidas conservan el rastro entero.
|
|
146
|
+
*/
|
|
147
|
+
cancel: (id, options) => this.post(`/contracts/${id}/cancel`, {}, options),
|
|
148
|
+
/**
|
|
149
|
+
* Renovación manual: extiende `ends_at` (posterior al fin actual) y lo
|
|
150
|
+
* propaga a las recurrentes gobernadas, reviviendo las completadas por
|
|
151
|
+
* el límite viejo.
|
|
152
|
+
*/
|
|
153
|
+
renew: (id, endsAt, options) => this.post(`/contracts/${id}/renew`, { ends_at: endsAt }, options),
|
|
154
|
+
/**
|
|
155
|
+
* El enlace del PDF para el cliente final: URL FIRMADA con caducidad.
|
|
156
|
+
* Un contrato en borrador —sin número— es un 422.
|
|
157
|
+
*/
|
|
158
|
+
sharedLink: (id, options) => this.get(`/contracts/${id}/shared-link`, undefined, options),
|
|
159
|
+
/**
|
|
160
|
+
* Sube (o reemplaza: un fichero por colección) el contrato FIRMADO —
|
|
161
|
+
* el papel escaneado. Multiparte por `POST` dedicado; el `FormData` lo
|
|
162
|
+
* arma el atajo, no le pongas `content-type`.
|
|
163
|
+
*/
|
|
164
|
+
uploadDocument: (id, document, options) => this.post(`/contracts/${id}/document`, toFormData({ document }), options),
|
|
165
|
+
};
|
|
166
|
+
}
|
|
115
167
|
get(path, query, options) {
|
|
116
168
|
return this.request(path, { ...options, method: 'GET', query });
|
|
117
169
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* salen los tipos de `./api`.
|
|
7
7
|
*/
|
|
8
8
|
export { PimiaClient, toFormData } from './client.js';
|
|
9
|
-
export type { CustomerRequest, CustomerResource, EstimateResource, EstimatesRequest, InvoiceResource, InvoicesRequest, PimiaClientOptions, RateLimit, ReadOptions, RequestOptions, ResourceEnvelope, ResponseMeta, ResponseWithMeta, WriteOptions, } from './client.js';
|
|
9
|
+
export type { ContractRequest, ContractResource, CustomerRequest, CustomerResource, EstimateResource, EstimatesRequest, InvoiceResource, InvoicesRequest, PimiaClientOptions, RateLimit, ReadOptions, RequestOptions, ResourceEnvelope, ResponseMeta, ResponseWithMeta, WriteOptions, } from './client.js';
|
|
10
10
|
export { OAuth, createPkceChallenge, createState } from './oauth.js';
|
|
11
11
|
export type { AuthorizationServerMetadata, AuthorizeUrlOptions, OAuthConfig, PkceChallenge, } from './oauth.js';
|
|
12
12
|
export { MemoryTokenStore, isExpired, tokenSetFromResponse } from './tokens.js';
|
|
@@ -20,6 +20,14 @@ export declare const SCOPES: {
|
|
|
20
20
|
readonly invoicesWrite: "invoices:write";
|
|
21
21
|
readonly estimatesRead: "estimates:read";
|
|
22
22
|
readonly estimatesWrite: "estimates:write";
|
|
23
|
+
/** Leer contratos de servicio: periodo, estado, sus recurrentes. */
|
|
24
|
+
readonly contractsRead: "contracts:read";
|
|
25
|
+
/**
|
|
26
|
+
* Gestionar contratos: crear, activar, renovar y cancelar — pueden
|
|
27
|
+
* comprometer periodos de facturación futuros. Activar exige además
|
|
28
|
+
* `invoices:write` (la recurrente que nace emitirá facturas por su cuenta).
|
|
29
|
+
*/
|
|
30
|
+
readonly contractsWrite: "contracts:write";
|
|
23
31
|
readonly customersRead: "customers:read";
|
|
24
32
|
readonly customersWrite: "customers:write";
|
|
25
33
|
readonly expensesRead: "expenses:read";
|
package/dist/index.js
CHANGED
|
@@ -16,6 +16,14 @@ export const SCOPES = {
|
|
|
16
16
|
invoicesWrite: 'invoices:write',
|
|
17
17
|
estimatesRead: 'estimates:read',
|
|
18
18
|
estimatesWrite: 'estimates:write',
|
|
19
|
+
/** Leer contratos de servicio: periodo, estado, sus recurrentes. */
|
|
20
|
+
contractsRead: 'contracts:read',
|
|
21
|
+
/**
|
|
22
|
+
* Gestionar contratos: crear, activar, renovar y cancelar — pueden
|
|
23
|
+
* comprometer periodos de facturación futuros. Activar exige además
|
|
24
|
+
* `invoices:write` (la recurrente que nace emitirá facturas por su cuenta).
|
|
25
|
+
*/
|
|
26
|
+
contractsWrite: 'contracts:write',
|
|
19
27
|
customersRead: 'customers:read',
|
|
20
28
|
customersWrite: 'customers:write',
|
|
21
29
|
expensesRead: 'expenses:read',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pimia/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "Cliente TypeScript de la API de Pimia para apps de partner: OAuth con PKCE, rotación de refresh persistida, reintentos de rate limit y tipos generados del OpenAPI.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Pimia (https://pimia.es)",
|