factuplan 0.6.0 → 0.8.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.mts CHANGED
@@ -103,6 +103,13 @@ interface InvoiceItem {
103
103
  /** Tax rate override for IVA_RATE. Valid: 0, 5, 8, 12, 14, 15. Default: 15 */
104
104
  tax?: number;
105
105
  }
106
+ type PaymentTimeUnit = 'dias' | 'meses' | 'anios';
107
+ interface InvoicePayment {
108
+ method: string;
109
+ amount: number;
110
+ term?: number;
111
+ timeUnit?: PaymentTimeUnit;
112
+ }
106
113
  interface CreateInvoiceInput {
107
114
  /** UUID of the emission point. Optional if using establishment + emissionPoint codes, or if the taxpayer has a single active emission point. */
108
115
  emissionPointId?: string;
@@ -112,8 +119,14 @@ interface CreateInvoiceInput {
112
119
  emissionPoint?: string;
113
120
  customer: InvoiceCustomer;
114
121
  items: InvoiceItem[];
115
- paymentMethod?: string;
122
+ /** List of payment methods for multi-payment support. */
123
+ payments?: InvoicePayment[];
116
124
  additionalInfo?: Record<string, string>;
125
+ /**
126
+ * Whether to send the authorized invoice by email to the customer.
127
+ * @default true
128
+ */
129
+ sendEmail?: boolean;
117
130
  }
118
131
  interface ImportByAccessKeyInput {
119
132
  /** 49-digit SRI access key (claveAcceso) of an already-authorized invoice */
@@ -214,6 +227,36 @@ interface FactuplanOptions {
214
227
  baseUrl?: string;
215
228
  /** Request timeout in milliseconds (default: 30000) */
216
229
  timeout?: number;
230
+ /**
231
+ * Default taxpayer RUC sent as `x-taxpayer-ruc` header in every request.
232
+ * Required for most operations (emit, sign, customers, products, etc.).
233
+ * Not required for `queryExternalByAccessKey`.
234
+ */
235
+ ruc?: string;
236
+ }
237
+ interface QueryExternalByAccessKeyInput {
238
+ /** Clave de acceso de 49 dígitos del comprobante en el SRI */
239
+ accessKey: string;
240
+ /**
241
+ * Si es true (por defecto), guarda el contribuyente, documento, XML y PDF.
242
+ * Si es false, solo verifica el comprobante y descuenta el contador sin guardar registros.
243
+ * @default true
244
+ */
245
+ save?: boolean;
246
+ }
247
+ interface QueryExternalByAccessKeyResponse {
248
+ /** ID del comprobante guardado en Factuplan; null cuando save=false */
249
+ id: string | null;
250
+ /** Clave de acceso de 49 dígitos */
251
+ accessKey: string;
252
+ /** Número secuencial del comprobante (ej: '000000001') */
253
+ sequential: string;
254
+ /** Estado del comprobante ('AUTHORIZED') */
255
+ status: string;
256
+ /** Total del comprobante */
257
+ total: number;
258
+ /** XML completo autorizado del SRI (envelope <autorizacion>) en base64 */
259
+ xmlBase64: string;
217
260
  }
218
261
 
219
262
  type Requester$3 = (method: string, path: string, body?: unknown, params?: Record<string, string | number | undefined>) => Promise<unknown>;
@@ -241,6 +284,7 @@ declare class InvoicesResource {
241
284
  downloadXml(id: string): Promise<DownloadUrlResponse>;
242
285
  downloadPdf(id: string): Promise<DownloadUrlResponse>;
243
286
  importByAccessKey(input: ImportByAccessKeyInput): Promise<Invoice>;
287
+ queryExternalByAccessKey(input: QueryExternalByAccessKeyInput): Promise<QueryExternalByAccessKeyResponse>;
244
288
  }
245
289
 
246
290
  type Requester$1 = (method: string, path: string, body?: unknown, params?: Record<string, string | number | undefined>) => Promise<unknown>;
@@ -272,6 +316,7 @@ declare class Factuplan {
272
316
  private readonly apiKey;
273
317
  private readonly baseUrl;
274
318
  private readonly timeout;
319
+ private readonly options;
275
320
  readonly customers: CustomersResource;
276
321
  readonly products: ProductsResource;
277
322
  readonly invoices: InvoicesResource;
package/dist/index.d.ts CHANGED
@@ -103,6 +103,13 @@ interface InvoiceItem {
103
103
  /** Tax rate override for IVA_RATE. Valid: 0, 5, 8, 12, 14, 15. Default: 15 */
104
104
  tax?: number;
105
105
  }
106
+ type PaymentTimeUnit = 'dias' | 'meses' | 'anios';
107
+ interface InvoicePayment {
108
+ method: string;
109
+ amount: number;
110
+ term?: number;
111
+ timeUnit?: PaymentTimeUnit;
112
+ }
106
113
  interface CreateInvoiceInput {
107
114
  /** UUID of the emission point. Optional if using establishment + emissionPoint codes, or if the taxpayer has a single active emission point. */
108
115
  emissionPointId?: string;
@@ -112,8 +119,14 @@ interface CreateInvoiceInput {
112
119
  emissionPoint?: string;
113
120
  customer: InvoiceCustomer;
114
121
  items: InvoiceItem[];
115
- paymentMethod?: string;
122
+ /** List of payment methods for multi-payment support. */
123
+ payments?: InvoicePayment[];
116
124
  additionalInfo?: Record<string, string>;
125
+ /**
126
+ * Whether to send the authorized invoice by email to the customer.
127
+ * @default true
128
+ */
129
+ sendEmail?: boolean;
117
130
  }
118
131
  interface ImportByAccessKeyInput {
119
132
  /** 49-digit SRI access key (claveAcceso) of an already-authorized invoice */
@@ -214,6 +227,36 @@ interface FactuplanOptions {
214
227
  baseUrl?: string;
215
228
  /** Request timeout in milliseconds (default: 30000) */
216
229
  timeout?: number;
230
+ /**
231
+ * Default taxpayer RUC sent as `x-taxpayer-ruc` header in every request.
232
+ * Required for most operations (emit, sign, customers, products, etc.).
233
+ * Not required for `queryExternalByAccessKey`.
234
+ */
235
+ ruc?: string;
236
+ }
237
+ interface QueryExternalByAccessKeyInput {
238
+ /** Clave de acceso de 49 dígitos del comprobante en el SRI */
239
+ accessKey: string;
240
+ /**
241
+ * Si es true (por defecto), guarda el contribuyente, documento, XML y PDF.
242
+ * Si es false, solo verifica el comprobante y descuenta el contador sin guardar registros.
243
+ * @default true
244
+ */
245
+ save?: boolean;
246
+ }
247
+ interface QueryExternalByAccessKeyResponse {
248
+ /** ID del comprobante guardado en Factuplan; null cuando save=false */
249
+ id: string | null;
250
+ /** Clave de acceso de 49 dígitos */
251
+ accessKey: string;
252
+ /** Número secuencial del comprobante (ej: '000000001') */
253
+ sequential: string;
254
+ /** Estado del comprobante ('AUTHORIZED') */
255
+ status: string;
256
+ /** Total del comprobante */
257
+ total: number;
258
+ /** XML completo autorizado del SRI (envelope <autorizacion>) en base64 */
259
+ xmlBase64: string;
217
260
  }
218
261
 
219
262
  type Requester$3 = (method: string, path: string, body?: unknown, params?: Record<string, string | number | undefined>) => Promise<unknown>;
@@ -241,6 +284,7 @@ declare class InvoicesResource {
241
284
  downloadXml(id: string): Promise<DownloadUrlResponse>;
242
285
  downloadPdf(id: string): Promise<DownloadUrlResponse>;
243
286
  importByAccessKey(input: ImportByAccessKeyInput): Promise<Invoice>;
287
+ queryExternalByAccessKey(input: QueryExternalByAccessKeyInput): Promise<QueryExternalByAccessKeyResponse>;
244
288
  }
245
289
 
246
290
  type Requester$1 = (method: string, path: string, body?: unknown, params?: Record<string, string | number | undefined>) => Promise<unknown>;
@@ -272,6 +316,7 @@ declare class Factuplan {
272
316
  private readonly apiKey;
273
317
  private readonly baseUrl;
274
318
  private readonly timeout;
319
+ private readonly options;
275
320
  readonly customers: CustomersResource;
276
321
  readonly products: ProductsResource;
277
322
  readonly invoices: InvoicesResource;
package/dist/index.js CHANGED
@@ -107,6 +107,13 @@ var InvoicesResource = class {
107
107
  async importByAccessKey(input) {
108
108
  return this.request("POST", "/developer/invoices/import", input);
109
109
  }
110
+ async queryExternalByAccessKey(input) {
111
+ return this.request(
112
+ "POST",
113
+ "/developer/receipts/query",
114
+ input
115
+ );
116
+ }
110
117
  };
111
118
 
112
119
  // src/resources/products.ts
@@ -160,6 +167,7 @@ var Factuplan = class {
160
167
  constructor(apiKey, options) {
161
168
  if (!apiKey) throw new Error("API key is required");
162
169
  this.apiKey = apiKey;
170
+ this.options = options;
163
171
  this.baseUrl = (options?.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
164
172
  this.timeout = options?.timeout ?? DEFAULT_TIMEOUT;
165
173
  const requester = this.request.bind(this);
@@ -190,6 +198,9 @@ var Factuplan = class {
190
198
  "x-api-key": this.apiKey,
191
199
  Accept: "application/json"
192
200
  };
201
+ if (this.options?.ruc) {
202
+ headers["x-taxpayer-ruc"] = this.options.ruc;
203
+ }
193
204
  if (body !== void 0) {
194
205
  headers["Content-Type"] = "application/json";
195
206
  }
package/dist/index.mjs CHANGED
@@ -78,6 +78,13 @@ var InvoicesResource = class {
78
78
  async importByAccessKey(input) {
79
79
  return this.request("POST", "/developer/invoices/import", input);
80
80
  }
81
+ async queryExternalByAccessKey(input) {
82
+ return this.request(
83
+ "POST",
84
+ "/developer/receipts/query",
85
+ input
86
+ );
87
+ }
81
88
  };
82
89
 
83
90
  // src/resources/products.ts
@@ -131,6 +138,7 @@ var Factuplan = class {
131
138
  constructor(apiKey, options) {
132
139
  if (!apiKey) throw new Error("API key is required");
133
140
  this.apiKey = apiKey;
141
+ this.options = options;
134
142
  this.baseUrl = (options?.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
135
143
  this.timeout = options?.timeout ?? DEFAULT_TIMEOUT;
136
144
  const requester = this.request.bind(this);
@@ -161,6 +169,9 @@ var Factuplan = class {
161
169
  "x-api-key": this.apiKey,
162
170
  Accept: "application/json"
163
171
  };
172
+ if (this.options?.ruc) {
173
+ headers["x-taxpayer-ruc"] = this.options.ruc;
174
+ }
164
175
  if (body !== void 0) {
165
176
  headers["Content-Type"] = "application/json";
166
177
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "factuplan",
3
- "version": "0.6.0",
3
+ "version": "0.8.0",
4
4
  "description": "Official Factuplan SDK for JavaScript & TypeScript — Create electronic invoices for Ecuador (SRI)",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",