@timbrix/sdk 0.3.1 → 1.1.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 +178 -2
- package/dist/index.d.ts +178 -2
- package/dist/index.js +82 -0
- package/dist/index.mjs +81 -0
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -201,7 +201,7 @@ interface WebhookDelivery {
|
|
|
201
201
|
success: boolean;
|
|
202
202
|
createdAt: string;
|
|
203
203
|
}
|
|
204
|
-
type ApiKeyScope = "read:user" | "write:user" | "read:organization" | "write:organization" | "read:members" | "write:members" | "read:webhooks" | "write:webhooks" | "read:api-keys" | "write:api-keys";
|
|
204
|
+
type ApiKeyScope = "read:user" | "write:user" | "read:organization" | "write:organization" | "read:members" | "write:members" | "read:webhooks" | "write:webhooks" | "read:api-keys" | "write:api-keys" | "read:invoices" | "write:invoices";
|
|
205
205
|
interface ApiKey {
|
|
206
206
|
id: string;
|
|
207
207
|
organizationId: string;
|
|
@@ -408,6 +408,138 @@ interface ListUsosCfdiParams {
|
|
|
408
408
|
tipoPersona?: TipoPersona;
|
|
409
409
|
regimen?: string;
|
|
410
410
|
}
|
|
411
|
+
interface ClaveProdServ {
|
|
412
|
+
codigo: string;
|
|
413
|
+
descripcion: string;
|
|
414
|
+
incluyeIvaTrasladado: boolean;
|
|
415
|
+
incluyeIepsTrasladado: boolean;
|
|
416
|
+
}
|
|
417
|
+
interface ClaveUnidad {
|
|
418
|
+
codigo: string;
|
|
419
|
+
nombre: string;
|
|
420
|
+
descripcion: string;
|
|
421
|
+
simbolo?: string | null;
|
|
422
|
+
}
|
|
423
|
+
interface SearchClavesParams {
|
|
424
|
+
q?: string;
|
|
425
|
+
limit?: number;
|
|
426
|
+
}
|
|
427
|
+
interface SearchClavesProdServResult {
|
|
428
|
+
data: ClaveProdServ[];
|
|
429
|
+
total: number;
|
|
430
|
+
}
|
|
431
|
+
interface SearchClavesUnidadResult {
|
|
432
|
+
data: ClaveUnidad[];
|
|
433
|
+
total: number;
|
|
434
|
+
}
|
|
435
|
+
interface ImportProductsCsvRowError {
|
|
436
|
+
row: number;
|
|
437
|
+
message: string;
|
|
438
|
+
}
|
|
439
|
+
interface ImportProductsCsvResult {
|
|
440
|
+
totalRows: number;
|
|
441
|
+
successCount: number;
|
|
442
|
+
errorCount: number;
|
|
443
|
+
errors: ImportProductsCsvRowError[];
|
|
444
|
+
}
|
|
445
|
+
interface InvoiceCustomerInput {
|
|
446
|
+
legalName: string;
|
|
447
|
+
taxId: string;
|
|
448
|
+
/** SAT régimen fiscal code — required unless the customer is público en general */
|
|
449
|
+
taxSystem?: string;
|
|
450
|
+
zip?: string;
|
|
451
|
+
}
|
|
452
|
+
interface InvoiceTaxInput {
|
|
453
|
+
type: string;
|
|
454
|
+
factorType: string;
|
|
455
|
+
rate?: string;
|
|
456
|
+
base?: number;
|
|
457
|
+
amount?: number;
|
|
458
|
+
}
|
|
459
|
+
interface InvoiceItemInput {
|
|
460
|
+
quantity: number;
|
|
461
|
+
amount: number;
|
|
462
|
+
/** Existing product/service ID — mutually exclusive with `productKey`/`unitKey`/`description`/`unitPrice` (inline concept data) */
|
|
463
|
+
productId?: string;
|
|
464
|
+
/** Required unless `productId` is provided */
|
|
465
|
+
description?: string;
|
|
466
|
+
/** Required unless `productId` is provided */
|
|
467
|
+
unitPrice?: number;
|
|
468
|
+
/** Required unless `productId` is provided */
|
|
469
|
+
productKey?: string;
|
|
470
|
+
/** Required unless `productId` is provided */
|
|
471
|
+
unitKey?: string;
|
|
472
|
+
unit?: string;
|
|
473
|
+
taxObject?: string;
|
|
474
|
+
taxes?: InvoiceTaxInput[];
|
|
475
|
+
}
|
|
476
|
+
interface CreateInvoiceInput {
|
|
477
|
+
/** Ingreso, Egreso, or Traslado — default: I */
|
|
478
|
+
type?: "I" | "E" | "T";
|
|
479
|
+
series: string;
|
|
480
|
+
folioNumber: string;
|
|
481
|
+
date: string;
|
|
482
|
+
paymentForm: string;
|
|
483
|
+
/** Default: PUE */
|
|
484
|
+
paymentMethod?: "PUE" | "PPD";
|
|
485
|
+
/** Default: MXN */
|
|
486
|
+
currency?: string;
|
|
487
|
+
/** Default: 1 */
|
|
488
|
+
exchange?: number;
|
|
489
|
+
/** SAT clave de exportación — default: 01 */
|
|
490
|
+
export?: string;
|
|
491
|
+
/** SAT uso CFDI catalog code */
|
|
492
|
+
use: string;
|
|
493
|
+
/** Inline customer — mutually exclusive with customerId */
|
|
494
|
+
customer?: InvoiceCustomerInput;
|
|
495
|
+
/** Existing customer ID — mutually exclusive with customer */
|
|
496
|
+
customerId?: string;
|
|
497
|
+
items: InvoiceItemInput[];
|
|
498
|
+
/**
|
|
499
|
+
* Client-supplied key to safely retry this request without
|
|
500
|
+
* double-stamping. If an invoice was already created for this
|
|
501
|
+
* organization with the same key, that invoice is returned instead of
|
|
502
|
+
* stamping again.
|
|
503
|
+
*/
|
|
504
|
+
idempotencyKey?: string;
|
|
505
|
+
}
|
|
506
|
+
interface Invoice {
|
|
507
|
+
id: string;
|
|
508
|
+
uuid: string;
|
|
509
|
+
status: "valid";
|
|
510
|
+
series: string;
|
|
511
|
+
folioNumber: string;
|
|
512
|
+
total: number;
|
|
513
|
+
date: string;
|
|
514
|
+
xml: string;
|
|
515
|
+
createdAt: string;
|
|
516
|
+
}
|
|
517
|
+
interface ListInvoicesParams {
|
|
518
|
+
/** Page number (1-indexed). Default: 1 */
|
|
519
|
+
page?: number;
|
|
520
|
+
/** Results per page (1-100). Default: 20 */
|
|
521
|
+
limit?: number;
|
|
522
|
+
}
|
|
523
|
+
interface InvoiceListItem {
|
|
524
|
+
id: string;
|
|
525
|
+
uuid: string;
|
|
526
|
+
serie: string;
|
|
527
|
+
folio: string;
|
|
528
|
+
/** I = Ingreso, E = Egreso, T = Traslado */
|
|
529
|
+
tipoComprobante: string;
|
|
530
|
+
rfcReceptor: string;
|
|
531
|
+
moneda: string;
|
|
532
|
+
total: number;
|
|
533
|
+
status: "vigente" | "cancelado";
|
|
534
|
+
createdAt: string;
|
|
535
|
+
}
|
|
536
|
+
interface ListInvoicesResponse {
|
|
537
|
+
data: InvoiceListItem[];
|
|
538
|
+
total: number;
|
|
539
|
+
page: number;
|
|
540
|
+
limit: number;
|
|
541
|
+
totalPages: number;
|
|
542
|
+
}
|
|
411
543
|
interface TimbrixError {
|
|
412
544
|
statusCode: number;
|
|
413
545
|
message: string | string[];
|
|
@@ -485,6 +617,25 @@ declare class CustomersResource {
|
|
|
485
617
|
delete(organizationId: string, customerId: string): Promise<void>;
|
|
486
618
|
}
|
|
487
619
|
|
|
620
|
+
declare class InvoicesResource {
|
|
621
|
+
private http;
|
|
622
|
+
constructor(http: KyInstance);
|
|
623
|
+
/**
|
|
624
|
+
* Create and stamp (timbrar) a CFDI 4.0 invoice via the configured PAC.
|
|
625
|
+
* Works with either a Supabase bearer session (internal dashboard, the
|
|
626
|
+
* user must be a member of `organizationId`) or an API key (external
|
|
627
|
+
* integrations, requires the `write:invoices` scope — the key must
|
|
628
|
+
* belong to `organizationId`).
|
|
629
|
+
*/
|
|
630
|
+
create(organizationId: string, data: CreateInvoiceInput): Promise<Invoice>;
|
|
631
|
+
/**
|
|
632
|
+
* List invoices for an organization, newest first. Works with either a
|
|
633
|
+
* Supabase bearer session or an API key (requires the `read:invoices`
|
|
634
|
+
* scope), same rules as `create`.
|
|
635
|
+
*/
|
|
636
|
+
list(organizationId: string, params?: ListInvoicesParams): Promise<ListInvoicesResponse>;
|
|
637
|
+
}
|
|
638
|
+
|
|
488
639
|
declare class OAuthResource {
|
|
489
640
|
private http;
|
|
490
641
|
constructor(http: KyInstance);
|
|
@@ -602,6 +753,20 @@ declare class ProductsResource {
|
|
|
602
753
|
* Delete a product
|
|
603
754
|
*/
|
|
604
755
|
delete(organizationId: string, productId: string): Promise<void>;
|
|
756
|
+
/**
|
|
757
|
+
* Bulk import products/services from a CSV file (multipart/form-data,
|
|
758
|
+
* field name "file"). Works in both Node (18+) and browser environments,
|
|
759
|
+
* since both provide the global `Blob`/`File` and `FormData` APIs.
|
|
760
|
+
*
|
|
761
|
+
* Required CSV columns: description, productKey, price. Optional
|
|
762
|
+
* columns: unitKey (default H87), unitName, sku, taxIncluded,
|
|
763
|
+
* taxability, livemode. Processing is partial — valid rows are created
|
|
764
|
+
* even if other rows fail, and every failure is reported with its row
|
|
765
|
+
* number and reason.
|
|
766
|
+
*
|
|
767
|
+
* Calls POST /organizations/:organizationId/products/import
|
|
768
|
+
*/
|
|
769
|
+
importCsv(organizationId: string, file: Blob | File, filename?: string): Promise<ImportProductsCsvResult>;
|
|
605
770
|
}
|
|
606
771
|
|
|
607
772
|
declare class SatResource {
|
|
@@ -617,6 +782,16 @@ declare class SatResource {
|
|
|
617
782
|
* Calls GET /sat/usos-cfdi
|
|
618
783
|
*/
|
|
619
784
|
usosCfdi(params?: ListUsosCfdiParams): Promise<UsoCfdi[]>;
|
|
785
|
+
/**
|
|
786
|
+
* Search claves de producto o servicio in the SAT catalog (c_ClaveProdServ)
|
|
787
|
+
* Calls GET /sat/claves-prod-serv
|
|
788
|
+
*/
|
|
789
|
+
searchClavesProdServ(params?: SearchClavesParams): Promise<SearchClavesProdServResult>;
|
|
790
|
+
/**
|
|
791
|
+
* Search claves de unidad de medida in the SAT catalog (c_ClaveUnidad)
|
|
792
|
+
* Calls GET /sat/claves-unidad
|
|
793
|
+
*/
|
|
794
|
+
searchClavesUnidad(params?: SearchClavesParams): Promise<SearchClavesUnidadResult>;
|
|
620
795
|
}
|
|
621
796
|
|
|
622
797
|
declare class UsersResource {
|
|
@@ -687,6 +862,7 @@ declare class Timbrix {
|
|
|
687
862
|
readonly oauth: OAuthResource;
|
|
688
863
|
readonly products: ProductsResource;
|
|
689
864
|
readonly sat: SatResource;
|
|
865
|
+
readonly invoices: InvoicesResource;
|
|
690
866
|
constructor(config?: TimbrixConfig);
|
|
691
867
|
/**
|
|
692
868
|
* Update authentication strategy (useful for CLI when token changes)
|
|
@@ -715,4 +891,4 @@ declare class ApiKeyAuth implements AuthStrategy {
|
|
|
715
891
|
applyAuth(options: Options): Options;
|
|
716
892
|
}
|
|
717
893
|
|
|
718
|
-
export { type ApiKey, ApiKeyAuth, type ApiKeyScope, type ApiKeyStats, type ApiKeyValidateResponse, ApiKeysResource, type AuthMode, AuthResource, type AuthStrategy, BearerAuth, type CreateApiKeyInput, type CreateApiKeyResponse, type CreateCustomerInput, type CreateOAuthAppInput, type CreateOrganizationInput, type CreateProductInput, type CreateWebhookInput, type Customer, type CustomerAddress, CustomersResource, type ExchangeCodeInput, type GenerateTokenInput, type InviteMemberInput, type LegalAddress, type ListProductsFilters, type ListRegimenesParams, type ListUsosCfdiParams, type LoginInput, type LoginResponse, type OAuthApp, type OAuthAppWithSecret, OAuthResource, type OAuthScope, type OAuthToken, type Organization, type OrganizationDetails, type OrganizationInvite, type OrganizationMember, type OrganizationRole, OrganizationsResource, type Product, type ProductTax, ProductsResource, type RefreshTokenInput, type RegimenFiscal, SatResource, Timbrix, type TimbrixConfig, type TimbrixError, type TimbrixUser, type TipoPersona, type TokenResponse, type UpdateApiKeyInput, type UpdateCustomerInput, type UpdateLegalDataInput, type UpdateMemberRoleInput, type UpdateOAuthAppInput, type UpdateOrganizationInput, type UpdateProductInput, type UpdateWebhookInput, UsersResource, type UsoCfdi, type ValidateCertificateResponse, type Webhook, type WebhookDelivery, type WebhookEvent, WebhooksResource };
|
|
894
|
+
export { type ApiKey, ApiKeyAuth, type ApiKeyScope, type ApiKeyStats, type ApiKeyValidateResponse, ApiKeysResource, type AuthMode, AuthResource, type AuthStrategy, BearerAuth, type ClaveProdServ, type ClaveUnidad, type CreateApiKeyInput, type CreateApiKeyResponse, type CreateCustomerInput, type CreateInvoiceInput, type CreateOAuthAppInput, type CreateOrganizationInput, type CreateProductInput, type CreateWebhookInput, type Customer, type CustomerAddress, CustomersResource, type ExchangeCodeInput, type GenerateTokenInput, type ImportProductsCsvResult, type ImportProductsCsvRowError, type InviteMemberInput, type Invoice, type InvoiceCustomerInput, type InvoiceItemInput, type InvoiceListItem, type InvoiceTaxInput, InvoicesResource, type LegalAddress, type ListInvoicesParams, type ListInvoicesResponse, type ListProductsFilters, type ListRegimenesParams, type ListUsosCfdiParams, type LoginInput, type LoginResponse, type OAuthApp, type OAuthAppWithSecret, OAuthResource, type OAuthScope, type OAuthToken, type Organization, type OrganizationDetails, type OrganizationInvite, type OrganizationMember, type OrganizationRole, OrganizationsResource, type Product, type ProductTax, ProductsResource, type RefreshTokenInput, type RegimenFiscal, SatResource, type SearchClavesParams, type SearchClavesProdServResult, type SearchClavesUnidadResult, Timbrix, type TimbrixConfig, type TimbrixError, type TimbrixUser, type TipoPersona, type TokenResponse, type UpdateApiKeyInput, type UpdateCustomerInput, type UpdateLegalDataInput, type UpdateMemberRoleInput, type UpdateOAuthAppInput, type UpdateOrganizationInput, type UpdateProductInput, type UpdateWebhookInput, UsersResource, type UsoCfdi, type ValidateCertificateResponse, type Webhook, type WebhookDelivery, type WebhookEvent, WebhooksResource };
|
package/dist/index.d.ts
CHANGED
|
@@ -201,7 +201,7 @@ interface WebhookDelivery {
|
|
|
201
201
|
success: boolean;
|
|
202
202
|
createdAt: string;
|
|
203
203
|
}
|
|
204
|
-
type ApiKeyScope = "read:user" | "write:user" | "read:organization" | "write:organization" | "read:members" | "write:members" | "read:webhooks" | "write:webhooks" | "read:api-keys" | "write:api-keys";
|
|
204
|
+
type ApiKeyScope = "read:user" | "write:user" | "read:organization" | "write:organization" | "read:members" | "write:members" | "read:webhooks" | "write:webhooks" | "read:api-keys" | "write:api-keys" | "read:invoices" | "write:invoices";
|
|
205
205
|
interface ApiKey {
|
|
206
206
|
id: string;
|
|
207
207
|
organizationId: string;
|
|
@@ -408,6 +408,138 @@ interface ListUsosCfdiParams {
|
|
|
408
408
|
tipoPersona?: TipoPersona;
|
|
409
409
|
regimen?: string;
|
|
410
410
|
}
|
|
411
|
+
interface ClaveProdServ {
|
|
412
|
+
codigo: string;
|
|
413
|
+
descripcion: string;
|
|
414
|
+
incluyeIvaTrasladado: boolean;
|
|
415
|
+
incluyeIepsTrasladado: boolean;
|
|
416
|
+
}
|
|
417
|
+
interface ClaveUnidad {
|
|
418
|
+
codigo: string;
|
|
419
|
+
nombre: string;
|
|
420
|
+
descripcion: string;
|
|
421
|
+
simbolo?: string | null;
|
|
422
|
+
}
|
|
423
|
+
interface SearchClavesParams {
|
|
424
|
+
q?: string;
|
|
425
|
+
limit?: number;
|
|
426
|
+
}
|
|
427
|
+
interface SearchClavesProdServResult {
|
|
428
|
+
data: ClaveProdServ[];
|
|
429
|
+
total: number;
|
|
430
|
+
}
|
|
431
|
+
interface SearchClavesUnidadResult {
|
|
432
|
+
data: ClaveUnidad[];
|
|
433
|
+
total: number;
|
|
434
|
+
}
|
|
435
|
+
interface ImportProductsCsvRowError {
|
|
436
|
+
row: number;
|
|
437
|
+
message: string;
|
|
438
|
+
}
|
|
439
|
+
interface ImportProductsCsvResult {
|
|
440
|
+
totalRows: number;
|
|
441
|
+
successCount: number;
|
|
442
|
+
errorCount: number;
|
|
443
|
+
errors: ImportProductsCsvRowError[];
|
|
444
|
+
}
|
|
445
|
+
interface InvoiceCustomerInput {
|
|
446
|
+
legalName: string;
|
|
447
|
+
taxId: string;
|
|
448
|
+
/** SAT régimen fiscal code — required unless the customer is público en general */
|
|
449
|
+
taxSystem?: string;
|
|
450
|
+
zip?: string;
|
|
451
|
+
}
|
|
452
|
+
interface InvoiceTaxInput {
|
|
453
|
+
type: string;
|
|
454
|
+
factorType: string;
|
|
455
|
+
rate?: string;
|
|
456
|
+
base?: number;
|
|
457
|
+
amount?: number;
|
|
458
|
+
}
|
|
459
|
+
interface InvoiceItemInput {
|
|
460
|
+
quantity: number;
|
|
461
|
+
amount: number;
|
|
462
|
+
/** Existing product/service ID — mutually exclusive with `productKey`/`unitKey`/`description`/`unitPrice` (inline concept data) */
|
|
463
|
+
productId?: string;
|
|
464
|
+
/** Required unless `productId` is provided */
|
|
465
|
+
description?: string;
|
|
466
|
+
/** Required unless `productId` is provided */
|
|
467
|
+
unitPrice?: number;
|
|
468
|
+
/** Required unless `productId` is provided */
|
|
469
|
+
productKey?: string;
|
|
470
|
+
/** Required unless `productId` is provided */
|
|
471
|
+
unitKey?: string;
|
|
472
|
+
unit?: string;
|
|
473
|
+
taxObject?: string;
|
|
474
|
+
taxes?: InvoiceTaxInput[];
|
|
475
|
+
}
|
|
476
|
+
interface CreateInvoiceInput {
|
|
477
|
+
/** Ingreso, Egreso, or Traslado — default: I */
|
|
478
|
+
type?: "I" | "E" | "T";
|
|
479
|
+
series: string;
|
|
480
|
+
folioNumber: string;
|
|
481
|
+
date: string;
|
|
482
|
+
paymentForm: string;
|
|
483
|
+
/** Default: PUE */
|
|
484
|
+
paymentMethod?: "PUE" | "PPD";
|
|
485
|
+
/** Default: MXN */
|
|
486
|
+
currency?: string;
|
|
487
|
+
/** Default: 1 */
|
|
488
|
+
exchange?: number;
|
|
489
|
+
/** SAT clave de exportación — default: 01 */
|
|
490
|
+
export?: string;
|
|
491
|
+
/** SAT uso CFDI catalog code */
|
|
492
|
+
use: string;
|
|
493
|
+
/** Inline customer — mutually exclusive with customerId */
|
|
494
|
+
customer?: InvoiceCustomerInput;
|
|
495
|
+
/** Existing customer ID — mutually exclusive with customer */
|
|
496
|
+
customerId?: string;
|
|
497
|
+
items: InvoiceItemInput[];
|
|
498
|
+
/**
|
|
499
|
+
* Client-supplied key to safely retry this request without
|
|
500
|
+
* double-stamping. If an invoice was already created for this
|
|
501
|
+
* organization with the same key, that invoice is returned instead of
|
|
502
|
+
* stamping again.
|
|
503
|
+
*/
|
|
504
|
+
idempotencyKey?: string;
|
|
505
|
+
}
|
|
506
|
+
interface Invoice {
|
|
507
|
+
id: string;
|
|
508
|
+
uuid: string;
|
|
509
|
+
status: "valid";
|
|
510
|
+
series: string;
|
|
511
|
+
folioNumber: string;
|
|
512
|
+
total: number;
|
|
513
|
+
date: string;
|
|
514
|
+
xml: string;
|
|
515
|
+
createdAt: string;
|
|
516
|
+
}
|
|
517
|
+
interface ListInvoicesParams {
|
|
518
|
+
/** Page number (1-indexed). Default: 1 */
|
|
519
|
+
page?: number;
|
|
520
|
+
/** Results per page (1-100). Default: 20 */
|
|
521
|
+
limit?: number;
|
|
522
|
+
}
|
|
523
|
+
interface InvoiceListItem {
|
|
524
|
+
id: string;
|
|
525
|
+
uuid: string;
|
|
526
|
+
serie: string;
|
|
527
|
+
folio: string;
|
|
528
|
+
/** I = Ingreso, E = Egreso, T = Traslado */
|
|
529
|
+
tipoComprobante: string;
|
|
530
|
+
rfcReceptor: string;
|
|
531
|
+
moneda: string;
|
|
532
|
+
total: number;
|
|
533
|
+
status: "vigente" | "cancelado";
|
|
534
|
+
createdAt: string;
|
|
535
|
+
}
|
|
536
|
+
interface ListInvoicesResponse {
|
|
537
|
+
data: InvoiceListItem[];
|
|
538
|
+
total: number;
|
|
539
|
+
page: number;
|
|
540
|
+
limit: number;
|
|
541
|
+
totalPages: number;
|
|
542
|
+
}
|
|
411
543
|
interface TimbrixError {
|
|
412
544
|
statusCode: number;
|
|
413
545
|
message: string | string[];
|
|
@@ -485,6 +617,25 @@ declare class CustomersResource {
|
|
|
485
617
|
delete(organizationId: string, customerId: string): Promise<void>;
|
|
486
618
|
}
|
|
487
619
|
|
|
620
|
+
declare class InvoicesResource {
|
|
621
|
+
private http;
|
|
622
|
+
constructor(http: KyInstance);
|
|
623
|
+
/**
|
|
624
|
+
* Create and stamp (timbrar) a CFDI 4.0 invoice via the configured PAC.
|
|
625
|
+
* Works with either a Supabase bearer session (internal dashboard, the
|
|
626
|
+
* user must be a member of `organizationId`) or an API key (external
|
|
627
|
+
* integrations, requires the `write:invoices` scope — the key must
|
|
628
|
+
* belong to `organizationId`).
|
|
629
|
+
*/
|
|
630
|
+
create(organizationId: string, data: CreateInvoiceInput): Promise<Invoice>;
|
|
631
|
+
/**
|
|
632
|
+
* List invoices for an organization, newest first. Works with either a
|
|
633
|
+
* Supabase bearer session or an API key (requires the `read:invoices`
|
|
634
|
+
* scope), same rules as `create`.
|
|
635
|
+
*/
|
|
636
|
+
list(organizationId: string, params?: ListInvoicesParams): Promise<ListInvoicesResponse>;
|
|
637
|
+
}
|
|
638
|
+
|
|
488
639
|
declare class OAuthResource {
|
|
489
640
|
private http;
|
|
490
641
|
constructor(http: KyInstance);
|
|
@@ -602,6 +753,20 @@ declare class ProductsResource {
|
|
|
602
753
|
* Delete a product
|
|
603
754
|
*/
|
|
604
755
|
delete(organizationId: string, productId: string): Promise<void>;
|
|
756
|
+
/**
|
|
757
|
+
* Bulk import products/services from a CSV file (multipart/form-data,
|
|
758
|
+
* field name "file"). Works in both Node (18+) and browser environments,
|
|
759
|
+
* since both provide the global `Blob`/`File` and `FormData` APIs.
|
|
760
|
+
*
|
|
761
|
+
* Required CSV columns: description, productKey, price. Optional
|
|
762
|
+
* columns: unitKey (default H87), unitName, sku, taxIncluded,
|
|
763
|
+
* taxability, livemode. Processing is partial — valid rows are created
|
|
764
|
+
* even if other rows fail, and every failure is reported with its row
|
|
765
|
+
* number and reason.
|
|
766
|
+
*
|
|
767
|
+
* Calls POST /organizations/:organizationId/products/import
|
|
768
|
+
*/
|
|
769
|
+
importCsv(organizationId: string, file: Blob | File, filename?: string): Promise<ImportProductsCsvResult>;
|
|
605
770
|
}
|
|
606
771
|
|
|
607
772
|
declare class SatResource {
|
|
@@ -617,6 +782,16 @@ declare class SatResource {
|
|
|
617
782
|
* Calls GET /sat/usos-cfdi
|
|
618
783
|
*/
|
|
619
784
|
usosCfdi(params?: ListUsosCfdiParams): Promise<UsoCfdi[]>;
|
|
785
|
+
/**
|
|
786
|
+
* Search claves de producto o servicio in the SAT catalog (c_ClaveProdServ)
|
|
787
|
+
* Calls GET /sat/claves-prod-serv
|
|
788
|
+
*/
|
|
789
|
+
searchClavesProdServ(params?: SearchClavesParams): Promise<SearchClavesProdServResult>;
|
|
790
|
+
/**
|
|
791
|
+
* Search claves de unidad de medida in the SAT catalog (c_ClaveUnidad)
|
|
792
|
+
* Calls GET /sat/claves-unidad
|
|
793
|
+
*/
|
|
794
|
+
searchClavesUnidad(params?: SearchClavesParams): Promise<SearchClavesUnidadResult>;
|
|
620
795
|
}
|
|
621
796
|
|
|
622
797
|
declare class UsersResource {
|
|
@@ -687,6 +862,7 @@ declare class Timbrix {
|
|
|
687
862
|
readonly oauth: OAuthResource;
|
|
688
863
|
readonly products: ProductsResource;
|
|
689
864
|
readonly sat: SatResource;
|
|
865
|
+
readonly invoices: InvoicesResource;
|
|
690
866
|
constructor(config?: TimbrixConfig);
|
|
691
867
|
/**
|
|
692
868
|
* Update authentication strategy (useful for CLI when token changes)
|
|
@@ -715,4 +891,4 @@ declare class ApiKeyAuth implements AuthStrategy {
|
|
|
715
891
|
applyAuth(options: Options): Options;
|
|
716
892
|
}
|
|
717
893
|
|
|
718
|
-
export { type ApiKey, ApiKeyAuth, type ApiKeyScope, type ApiKeyStats, type ApiKeyValidateResponse, ApiKeysResource, type AuthMode, AuthResource, type AuthStrategy, BearerAuth, type CreateApiKeyInput, type CreateApiKeyResponse, type CreateCustomerInput, type CreateOAuthAppInput, type CreateOrganizationInput, type CreateProductInput, type CreateWebhookInput, type Customer, type CustomerAddress, CustomersResource, type ExchangeCodeInput, type GenerateTokenInput, type InviteMemberInput, type LegalAddress, type ListProductsFilters, type ListRegimenesParams, type ListUsosCfdiParams, type LoginInput, type LoginResponse, type OAuthApp, type OAuthAppWithSecret, OAuthResource, type OAuthScope, type OAuthToken, type Organization, type OrganizationDetails, type OrganizationInvite, type OrganizationMember, type OrganizationRole, OrganizationsResource, type Product, type ProductTax, ProductsResource, type RefreshTokenInput, type RegimenFiscal, SatResource, Timbrix, type TimbrixConfig, type TimbrixError, type TimbrixUser, type TipoPersona, type TokenResponse, type UpdateApiKeyInput, type UpdateCustomerInput, type UpdateLegalDataInput, type UpdateMemberRoleInput, type UpdateOAuthAppInput, type UpdateOrganizationInput, type UpdateProductInput, type UpdateWebhookInput, UsersResource, type UsoCfdi, type ValidateCertificateResponse, type Webhook, type WebhookDelivery, type WebhookEvent, WebhooksResource };
|
|
894
|
+
export { type ApiKey, ApiKeyAuth, type ApiKeyScope, type ApiKeyStats, type ApiKeyValidateResponse, ApiKeysResource, type AuthMode, AuthResource, type AuthStrategy, BearerAuth, type ClaveProdServ, type ClaveUnidad, type CreateApiKeyInput, type CreateApiKeyResponse, type CreateCustomerInput, type CreateInvoiceInput, type CreateOAuthAppInput, type CreateOrganizationInput, type CreateProductInput, type CreateWebhookInput, type Customer, type CustomerAddress, CustomersResource, type ExchangeCodeInput, type GenerateTokenInput, type ImportProductsCsvResult, type ImportProductsCsvRowError, type InviteMemberInput, type Invoice, type InvoiceCustomerInput, type InvoiceItemInput, type InvoiceListItem, type InvoiceTaxInput, InvoicesResource, type LegalAddress, type ListInvoicesParams, type ListInvoicesResponse, type ListProductsFilters, type ListRegimenesParams, type ListUsosCfdiParams, type LoginInput, type LoginResponse, type OAuthApp, type OAuthAppWithSecret, OAuthResource, type OAuthScope, type OAuthToken, type Organization, type OrganizationDetails, type OrganizationInvite, type OrganizationMember, type OrganizationRole, OrganizationsResource, type Product, type ProductTax, ProductsResource, type RefreshTokenInput, type RegimenFiscal, SatResource, type SearchClavesParams, type SearchClavesProdServResult, type SearchClavesUnidadResult, Timbrix, type TimbrixConfig, type TimbrixError, type TimbrixUser, type TipoPersona, type TokenResponse, type UpdateApiKeyInput, type UpdateCustomerInput, type UpdateLegalDataInput, type UpdateMemberRoleInput, type UpdateOAuthAppInput, type UpdateOrganizationInput, type UpdateProductInput, type UpdateWebhookInput, UsersResource, type UsoCfdi, type ValidateCertificateResponse, type Webhook, type WebhookDelivery, type WebhookEvent, WebhooksResource };
|
package/dist/index.js
CHANGED
|
@@ -35,6 +35,7 @@ __export(index_exports, {
|
|
|
35
35
|
AuthResource: () => AuthResource,
|
|
36
36
|
BearerAuth: () => BearerAuth,
|
|
37
37
|
CustomersResource: () => CustomersResource,
|
|
38
|
+
InvoicesResource: () => InvoicesResource,
|
|
38
39
|
OAuthResource: () => OAuthResource,
|
|
39
40
|
OrganizationsResource: () => OrganizationsResource,
|
|
40
41
|
ProductsResource: () => ProductsResource,
|
|
@@ -206,6 +207,37 @@ var CustomersResource = class {
|
|
|
206
207
|
}
|
|
207
208
|
};
|
|
208
209
|
|
|
210
|
+
// src/resources/invoices.ts
|
|
211
|
+
var InvoicesResource = class {
|
|
212
|
+
constructor(http) {
|
|
213
|
+
this.http = http;
|
|
214
|
+
}
|
|
215
|
+
http;
|
|
216
|
+
/**
|
|
217
|
+
* Create and stamp (timbrar) a CFDI 4.0 invoice via the configured PAC.
|
|
218
|
+
* Works with either a Supabase bearer session (internal dashboard, the
|
|
219
|
+
* user must be a member of `organizationId`) or an API key (external
|
|
220
|
+
* integrations, requires the `write:invoices` scope — the key must
|
|
221
|
+
* belong to `organizationId`).
|
|
222
|
+
*/
|
|
223
|
+
async create(organizationId, data) {
|
|
224
|
+
return this.http.post(`organizations/${organizationId}/invoices`, { json: data }).json();
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* List invoices for an organization, newest first. Works with either a
|
|
228
|
+
* Supabase bearer session or an API key (requires the `read:invoices`
|
|
229
|
+
* scope), same rules as `create`.
|
|
230
|
+
*/
|
|
231
|
+
async list(organizationId, params) {
|
|
232
|
+
const searchParams = {};
|
|
233
|
+
if (params?.page !== void 0) searchParams.page = String(params.page);
|
|
234
|
+
if (params?.limit !== void 0) searchParams.limit = String(params.limit);
|
|
235
|
+
return this.http.get(`organizations/${organizationId}/invoices`, {
|
|
236
|
+
searchParams: Object.keys(searchParams).length > 0 ? searchParams : void 0
|
|
237
|
+
}).json();
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
|
|
209
241
|
// src/resources/oauth.ts
|
|
210
242
|
var OAuthResource = class {
|
|
211
243
|
constructor(http) {
|
|
@@ -416,6 +448,29 @@ var ProductsResource = class {
|
|
|
416
448
|
`organizations/${organizationId}/products/${productId}`
|
|
417
449
|
);
|
|
418
450
|
}
|
|
451
|
+
/**
|
|
452
|
+
* Bulk import products/services from a CSV file (multipart/form-data,
|
|
453
|
+
* field name "file"). Works in both Node (18+) and browser environments,
|
|
454
|
+
* since both provide the global `Blob`/`File` and `FormData` APIs.
|
|
455
|
+
*
|
|
456
|
+
* Required CSV columns: description, productKey, price. Optional
|
|
457
|
+
* columns: unitKey (default H87), unitName, sku, taxIncluded,
|
|
458
|
+
* taxability, livemode. Processing is partial — valid rows are created
|
|
459
|
+
* even if other rows fail, and every failure is reported with its row
|
|
460
|
+
* number and reason.
|
|
461
|
+
*
|
|
462
|
+
* Calls POST /organizations/:organizationId/products/import
|
|
463
|
+
*/
|
|
464
|
+
async importCsv(organizationId, file, filename = "products.csv") {
|
|
465
|
+
const formData = new FormData();
|
|
466
|
+
formData.append("file", file, filename);
|
|
467
|
+
return this.http.post(`organizations/${organizationId}/products/import`, {
|
|
468
|
+
body: formData,
|
|
469
|
+
// Let fetch set the multipart Content-Type (with boundary) itself —
|
|
470
|
+
// unset the JSON default header inherited from the client instance.
|
|
471
|
+
headers: { "Content-Type": void 0 }
|
|
472
|
+
}).json();
|
|
473
|
+
}
|
|
419
474
|
};
|
|
420
475
|
|
|
421
476
|
// src/resources/sat.ts
|
|
@@ -447,6 +502,30 @@ var SatResource = class {
|
|
|
447
502
|
searchParams: Object.keys(searchParams).length > 0 ? searchParams : void 0
|
|
448
503
|
}).json();
|
|
449
504
|
}
|
|
505
|
+
/**
|
|
506
|
+
* Search claves de producto o servicio in the SAT catalog (c_ClaveProdServ)
|
|
507
|
+
* Calls GET /sat/claves-prod-serv
|
|
508
|
+
*/
|
|
509
|
+
async searchClavesProdServ(params) {
|
|
510
|
+
const searchParams = {};
|
|
511
|
+
if (params?.q) searchParams.q = params.q;
|
|
512
|
+
if (params?.limit !== void 0) searchParams.limit = String(params.limit);
|
|
513
|
+
return this.http.get("sat/claves-prod-serv", {
|
|
514
|
+
searchParams: Object.keys(searchParams).length > 0 ? searchParams : void 0
|
|
515
|
+
}).json();
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Search claves de unidad de medida in the SAT catalog (c_ClaveUnidad)
|
|
519
|
+
* Calls GET /sat/claves-unidad
|
|
520
|
+
*/
|
|
521
|
+
async searchClavesUnidad(params) {
|
|
522
|
+
const searchParams = {};
|
|
523
|
+
if (params?.q) searchParams.q = params.q;
|
|
524
|
+
if (params?.limit !== void 0) searchParams.limit = String(params.limit);
|
|
525
|
+
return this.http.get("sat/claves-unidad", {
|
|
526
|
+
searchParams: Object.keys(searchParams).length > 0 ? searchParams : void 0
|
|
527
|
+
}).json();
|
|
528
|
+
}
|
|
450
529
|
};
|
|
451
530
|
|
|
452
531
|
// src/resources/users.ts
|
|
@@ -548,6 +627,7 @@ var Timbrix = class {
|
|
|
548
627
|
oauth;
|
|
549
628
|
products;
|
|
550
629
|
sat;
|
|
630
|
+
invoices;
|
|
551
631
|
constructor(config = {}) {
|
|
552
632
|
const baseUrl = config.baseUrl || "http://localhost:3001";
|
|
553
633
|
if (config.bearerToken) {
|
|
@@ -582,6 +662,7 @@ var Timbrix = class {
|
|
|
582
662
|
this.oauth = new OAuthResource(this.http);
|
|
583
663
|
this.products = new ProductsResource(this.http);
|
|
584
664
|
this.sat = new SatResource(this.http);
|
|
665
|
+
this.invoices = new InvoicesResource(this.http);
|
|
585
666
|
}
|
|
586
667
|
/**
|
|
587
668
|
* Update authentication strategy (useful for CLI when token changes)
|
|
@@ -609,6 +690,7 @@ var Timbrix = class {
|
|
|
609
690
|
AuthResource,
|
|
610
691
|
BearerAuth,
|
|
611
692
|
CustomersResource,
|
|
693
|
+
InvoicesResource,
|
|
612
694
|
OAuthResource,
|
|
613
695
|
OrganizationsResource,
|
|
614
696
|
ProductsResource,
|
package/dist/index.mjs
CHANGED
|
@@ -159,6 +159,37 @@ var CustomersResource = class {
|
|
|
159
159
|
}
|
|
160
160
|
};
|
|
161
161
|
|
|
162
|
+
// src/resources/invoices.ts
|
|
163
|
+
var InvoicesResource = class {
|
|
164
|
+
constructor(http) {
|
|
165
|
+
this.http = http;
|
|
166
|
+
}
|
|
167
|
+
http;
|
|
168
|
+
/**
|
|
169
|
+
* Create and stamp (timbrar) a CFDI 4.0 invoice via the configured PAC.
|
|
170
|
+
* Works with either a Supabase bearer session (internal dashboard, the
|
|
171
|
+
* user must be a member of `organizationId`) or an API key (external
|
|
172
|
+
* integrations, requires the `write:invoices` scope — the key must
|
|
173
|
+
* belong to `organizationId`).
|
|
174
|
+
*/
|
|
175
|
+
async create(organizationId, data) {
|
|
176
|
+
return this.http.post(`organizations/${organizationId}/invoices`, { json: data }).json();
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* List invoices for an organization, newest first. Works with either a
|
|
180
|
+
* Supabase bearer session or an API key (requires the `read:invoices`
|
|
181
|
+
* scope), same rules as `create`.
|
|
182
|
+
*/
|
|
183
|
+
async list(organizationId, params) {
|
|
184
|
+
const searchParams = {};
|
|
185
|
+
if (params?.page !== void 0) searchParams.page = String(params.page);
|
|
186
|
+
if (params?.limit !== void 0) searchParams.limit = String(params.limit);
|
|
187
|
+
return this.http.get(`organizations/${organizationId}/invoices`, {
|
|
188
|
+
searchParams: Object.keys(searchParams).length > 0 ? searchParams : void 0
|
|
189
|
+
}).json();
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
|
|
162
193
|
// src/resources/oauth.ts
|
|
163
194
|
var OAuthResource = class {
|
|
164
195
|
constructor(http) {
|
|
@@ -369,6 +400,29 @@ var ProductsResource = class {
|
|
|
369
400
|
`organizations/${organizationId}/products/${productId}`
|
|
370
401
|
);
|
|
371
402
|
}
|
|
403
|
+
/**
|
|
404
|
+
* Bulk import products/services from a CSV file (multipart/form-data,
|
|
405
|
+
* field name "file"). Works in both Node (18+) and browser environments,
|
|
406
|
+
* since both provide the global `Blob`/`File` and `FormData` APIs.
|
|
407
|
+
*
|
|
408
|
+
* Required CSV columns: description, productKey, price. Optional
|
|
409
|
+
* columns: unitKey (default H87), unitName, sku, taxIncluded,
|
|
410
|
+
* taxability, livemode. Processing is partial — valid rows are created
|
|
411
|
+
* even if other rows fail, and every failure is reported with its row
|
|
412
|
+
* number and reason.
|
|
413
|
+
*
|
|
414
|
+
* Calls POST /organizations/:organizationId/products/import
|
|
415
|
+
*/
|
|
416
|
+
async importCsv(organizationId, file, filename = "products.csv") {
|
|
417
|
+
const formData = new FormData();
|
|
418
|
+
formData.append("file", file, filename);
|
|
419
|
+
return this.http.post(`organizations/${organizationId}/products/import`, {
|
|
420
|
+
body: formData,
|
|
421
|
+
// Let fetch set the multipart Content-Type (with boundary) itself —
|
|
422
|
+
// unset the JSON default header inherited from the client instance.
|
|
423
|
+
headers: { "Content-Type": void 0 }
|
|
424
|
+
}).json();
|
|
425
|
+
}
|
|
372
426
|
};
|
|
373
427
|
|
|
374
428
|
// src/resources/sat.ts
|
|
@@ -400,6 +454,30 @@ var SatResource = class {
|
|
|
400
454
|
searchParams: Object.keys(searchParams).length > 0 ? searchParams : void 0
|
|
401
455
|
}).json();
|
|
402
456
|
}
|
|
457
|
+
/**
|
|
458
|
+
* Search claves de producto o servicio in the SAT catalog (c_ClaveProdServ)
|
|
459
|
+
* Calls GET /sat/claves-prod-serv
|
|
460
|
+
*/
|
|
461
|
+
async searchClavesProdServ(params) {
|
|
462
|
+
const searchParams = {};
|
|
463
|
+
if (params?.q) searchParams.q = params.q;
|
|
464
|
+
if (params?.limit !== void 0) searchParams.limit = String(params.limit);
|
|
465
|
+
return this.http.get("sat/claves-prod-serv", {
|
|
466
|
+
searchParams: Object.keys(searchParams).length > 0 ? searchParams : void 0
|
|
467
|
+
}).json();
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* Search claves de unidad de medida in the SAT catalog (c_ClaveUnidad)
|
|
471
|
+
* Calls GET /sat/claves-unidad
|
|
472
|
+
*/
|
|
473
|
+
async searchClavesUnidad(params) {
|
|
474
|
+
const searchParams = {};
|
|
475
|
+
if (params?.q) searchParams.q = params.q;
|
|
476
|
+
if (params?.limit !== void 0) searchParams.limit = String(params.limit);
|
|
477
|
+
return this.http.get("sat/claves-unidad", {
|
|
478
|
+
searchParams: Object.keys(searchParams).length > 0 ? searchParams : void 0
|
|
479
|
+
}).json();
|
|
480
|
+
}
|
|
403
481
|
};
|
|
404
482
|
|
|
405
483
|
// src/resources/users.ts
|
|
@@ -501,6 +579,7 @@ var Timbrix = class {
|
|
|
501
579
|
oauth;
|
|
502
580
|
products;
|
|
503
581
|
sat;
|
|
582
|
+
invoices;
|
|
504
583
|
constructor(config = {}) {
|
|
505
584
|
const baseUrl = config.baseUrl || "http://localhost:3001";
|
|
506
585
|
if (config.bearerToken) {
|
|
@@ -535,6 +614,7 @@ var Timbrix = class {
|
|
|
535
614
|
this.oauth = new OAuthResource(this.http);
|
|
536
615
|
this.products = new ProductsResource(this.http);
|
|
537
616
|
this.sat = new SatResource(this.http);
|
|
617
|
+
this.invoices = new InvoicesResource(this.http);
|
|
538
618
|
}
|
|
539
619
|
/**
|
|
540
620
|
* Update authentication strategy (useful for CLI when token changes)
|
|
@@ -561,6 +641,7 @@ export {
|
|
|
561
641
|
AuthResource,
|
|
562
642
|
BearerAuth,
|
|
563
643
|
CustomersResource,
|
|
644
|
+
InvoicesResource,
|
|
564
645
|
OAuthResource,
|
|
565
646
|
OrganizationsResource,
|
|
566
647
|
ProductsResource,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@timbrix/sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "TypeScript SDK for Timbrix API",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"tsup": "^8.5.1",
|
|
34
34
|
"typescript": "^6.0.3",
|
|
35
|
-
"@repo/
|
|
36
|
-
"@repo/
|
|
35
|
+
"@repo/eslint-config": "0.1.1",
|
|
36
|
+
"@repo/typescript-config": "0.1.0"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
39
|
"build": "tsup src/index.ts --format cjs,esm --dts",
|