@timbrix/sdk 0.3.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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,72 @@ interface ListUsosCfdiParams {
408
408
  tipoPersona?: TipoPersona;
409
409
  regimen?: string;
410
410
  }
411
+ interface InvoiceCustomerInput {
412
+ legalName: string;
413
+ taxId: string;
414
+ /** SAT régimen fiscal code — required unless the customer is público en general */
415
+ taxSystem?: string;
416
+ zip?: string;
417
+ }
418
+ interface InvoiceTaxInput {
419
+ type: string;
420
+ factorType: string;
421
+ rate?: string;
422
+ base?: number;
423
+ amount?: number;
424
+ }
425
+ interface InvoiceItemInput {
426
+ quantity: number;
427
+ description: string;
428
+ unitPrice: number;
429
+ amount: number;
430
+ productKey: string;
431
+ unitKey: string;
432
+ unit?: string;
433
+ taxObject?: string;
434
+ taxes?: InvoiceTaxInput[];
435
+ }
436
+ interface CreateInvoiceInput {
437
+ /** Ingreso, Egreso, or Traslado — default: I */
438
+ type?: "I" | "E" | "T";
439
+ series: string;
440
+ folioNumber: string;
441
+ date: string;
442
+ paymentForm: string;
443
+ /** Default: PUE */
444
+ paymentMethod?: "PUE" | "PPD";
445
+ /** Default: MXN */
446
+ currency?: string;
447
+ /** Default: 1 */
448
+ exchange?: number;
449
+ /** SAT clave de exportación — default: 01 */
450
+ export?: string;
451
+ /** SAT uso CFDI catalog code */
452
+ use: string;
453
+ /** Inline customer — mutually exclusive with customerId */
454
+ customer?: InvoiceCustomerInput;
455
+ /** Existing customer ID — mutually exclusive with customer */
456
+ customerId?: string;
457
+ items: InvoiceItemInput[];
458
+ /**
459
+ * Client-supplied key to safely retry this request without
460
+ * double-stamping. If an invoice was already created for this
461
+ * organization with the same key, that invoice is returned instead of
462
+ * stamping again.
463
+ */
464
+ idempotencyKey?: string;
465
+ }
466
+ interface Invoice {
467
+ id: string;
468
+ uuid: string;
469
+ status: "valid";
470
+ series: string;
471
+ folioNumber: string;
472
+ total: number;
473
+ date: string;
474
+ xml: string;
475
+ createdAt: string;
476
+ }
411
477
  interface TimbrixError {
412
478
  statusCode: number;
413
479
  message: string | string[];
@@ -485,6 +551,17 @@ declare class CustomersResource {
485
551
  delete(organizationId: string, customerId: string): Promise<void>;
486
552
  }
487
553
 
554
+ declare class InvoicesResource {
555
+ private http;
556
+ constructor(http: KyInstance);
557
+ /**
558
+ * Create and stamp (timbrar) a CFDI 4.0 invoice via the configured PAC.
559
+ * Requires an API-key-authenticated client — the issuing organization is
560
+ * resolved from the key, there is no organizationId parameter.
561
+ */
562
+ create(data: CreateInvoiceInput): Promise<Invoice>;
563
+ }
564
+
488
565
  declare class OAuthResource {
489
566
  private http;
490
567
  constructor(http: KyInstance);
@@ -687,6 +764,7 @@ declare class Timbrix {
687
764
  readonly oauth: OAuthResource;
688
765
  readonly products: ProductsResource;
689
766
  readonly sat: SatResource;
767
+ readonly invoices: InvoicesResource;
690
768
  constructor(config?: TimbrixConfig);
691
769
  /**
692
770
  * Update authentication strategy (useful for CLI when token changes)
@@ -715,4 +793,4 @@ declare class ApiKeyAuth implements AuthStrategy {
715
793
  applyAuth(options: Options): Options;
716
794
  }
717
795
 
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 };
796
+ export { type ApiKey, ApiKeyAuth, type ApiKeyScope, type ApiKeyStats, type ApiKeyValidateResponse, ApiKeysResource, type AuthMode, AuthResource, type AuthStrategy, BearerAuth, 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 InviteMemberInput, type Invoice, type InvoiceCustomerInput, type InvoiceItemInput, type InvoiceTaxInput, InvoicesResource, 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 };
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,72 @@ interface ListUsosCfdiParams {
408
408
  tipoPersona?: TipoPersona;
409
409
  regimen?: string;
410
410
  }
411
+ interface InvoiceCustomerInput {
412
+ legalName: string;
413
+ taxId: string;
414
+ /** SAT régimen fiscal code — required unless the customer is público en general */
415
+ taxSystem?: string;
416
+ zip?: string;
417
+ }
418
+ interface InvoiceTaxInput {
419
+ type: string;
420
+ factorType: string;
421
+ rate?: string;
422
+ base?: number;
423
+ amount?: number;
424
+ }
425
+ interface InvoiceItemInput {
426
+ quantity: number;
427
+ description: string;
428
+ unitPrice: number;
429
+ amount: number;
430
+ productKey: string;
431
+ unitKey: string;
432
+ unit?: string;
433
+ taxObject?: string;
434
+ taxes?: InvoiceTaxInput[];
435
+ }
436
+ interface CreateInvoiceInput {
437
+ /** Ingreso, Egreso, or Traslado — default: I */
438
+ type?: "I" | "E" | "T";
439
+ series: string;
440
+ folioNumber: string;
441
+ date: string;
442
+ paymentForm: string;
443
+ /** Default: PUE */
444
+ paymentMethod?: "PUE" | "PPD";
445
+ /** Default: MXN */
446
+ currency?: string;
447
+ /** Default: 1 */
448
+ exchange?: number;
449
+ /** SAT clave de exportación — default: 01 */
450
+ export?: string;
451
+ /** SAT uso CFDI catalog code */
452
+ use: string;
453
+ /** Inline customer — mutually exclusive with customerId */
454
+ customer?: InvoiceCustomerInput;
455
+ /** Existing customer ID — mutually exclusive with customer */
456
+ customerId?: string;
457
+ items: InvoiceItemInput[];
458
+ /**
459
+ * Client-supplied key to safely retry this request without
460
+ * double-stamping. If an invoice was already created for this
461
+ * organization with the same key, that invoice is returned instead of
462
+ * stamping again.
463
+ */
464
+ idempotencyKey?: string;
465
+ }
466
+ interface Invoice {
467
+ id: string;
468
+ uuid: string;
469
+ status: "valid";
470
+ series: string;
471
+ folioNumber: string;
472
+ total: number;
473
+ date: string;
474
+ xml: string;
475
+ createdAt: string;
476
+ }
411
477
  interface TimbrixError {
412
478
  statusCode: number;
413
479
  message: string | string[];
@@ -485,6 +551,17 @@ declare class CustomersResource {
485
551
  delete(organizationId: string, customerId: string): Promise<void>;
486
552
  }
487
553
 
554
+ declare class InvoicesResource {
555
+ private http;
556
+ constructor(http: KyInstance);
557
+ /**
558
+ * Create and stamp (timbrar) a CFDI 4.0 invoice via the configured PAC.
559
+ * Requires an API-key-authenticated client — the issuing organization is
560
+ * resolved from the key, there is no organizationId parameter.
561
+ */
562
+ create(data: CreateInvoiceInput): Promise<Invoice>;
563
+ }
564
+
488
565
  declare class OAuthResource {
489
566
  private http;
490
567
  constructor(http: KyInstance);
@@ -687,6 +764,7 @@ declare class Timbrix {
687
764
  readonly oauth: OAuthResource;
688
765
  readonly products: ProductsResource;
689
766
  readonly sat: SatResource;
767
+ readonly invoices: InvoicesResource;
690
768
  constructor(config?: TimbrixConfig);
691
769
  /**
692
770
  * Update authentication strategy (useful for CLI when token changes)
@@ -715,4 +793,4 @@ declare class ApiKeyAuth implements AuthStrategy {
715
793
  applyAuth(options: Options): Options;
716
794
  }
717
795
 
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 };
796
+ export { type ApiKey, ApiKeyAuth, type ApiKeyScope, type ApiKeyStats, type ApiKeyValidateResponse, ApiKeysResource, type AuthMode, AuthResource, type AuthStrategy, BearerAuth, 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 InviteMemberInput, type Invoice, type InvoiceCustomerInput, type InvoiceItemInput, type InvoiceTaxInput, InvoicesResource, 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 };
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,22 @@ 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
+ * Requires an API-key-authenticated client — the issuing organization is
219
+ * resolved from the key, there is no organizationId parameter.
220
+ */
221
+ async create(data) {
222
+ return this.http.post("invoices", { json: data }).json();
223
+ }
224
+ };
225
+
209
226
  // src/resources/oauth.ts
210
227
  var OAuthResource = class {
211
228
  constructor(http) {
@@ -548,6 +565,7 @@ var Timbrix = class {
548
565
  oauth;
549
566
  products;
550
567
  sat;
568
+ invoices;
551
569
  constructor(config = {}) {
552
570
  const baseUrl = config.baseUrl || "http://localhost:3001";
553
571
  if (config.bearerToken) {
@@ -582,6 +600,7 @@ var Timbrix = class {
582
600
  this.oauth = new OAuthResource(this.http);
583
601
  this.products = new ProductsResource(this.http);
584
602
  this.sat = new SatResource(this.http);
603
+ this.invoices = new InvoicesResource(this.http);
585
604
  }
586
605
  /**
587
606
  * Update authentication strategy (useful for CLI when token changes)
@@ -609,6 +628,7 @@ var Timbrix = class {
609
628
  AuthResource,
610
629
  BearerAuth,
611
630
  CustomersResource,
631
+ InvoicesResource,
612
632
  OAuthResource,
613
633
  OrganizationsResource,
614
634
  ProductsResource,
package/dist/index.mjs CHANGED
@@ -159,6 +159,22 @@ 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
+ * Requires an API-key-authenticated client — the issuing organization is
171
+ * resolved from the key, there is no organizationId parameter.
172
+ */
173
+ async create(data) {
174
+ return this.http.post("invoices", { json: data }).json();
175
+ }
176
+ };
177
+
162
178
  // src/resources/oauth.ts
163
179
  var OAuthResource = class {
164
180
  constructor(http) {
@@ -501,6 +517,7 @@ var Timbrix = class {
501
517
  oauth;
502
518
  products;
503
519
  sat;
520
+ invoices;
504
521
  constructor(config = {}) {
505
522
  const baseUrl = config.baseUrl || "http://localhost:3001";
506
523
  if (config.bearerToken) {
@@ -535,6 +552,7 @@ var Timbrix = class {
535
552
  this.oauth = new OAuthResource(this.http);
536
553
  this.products = new ProductsResource(this.http);
537
554
  this.sat = new SatResource(this.http);
555
+ this.invoices = new InvoicesResource(this.http);
538
556
  }
539
557
  /**
540
558
  * Update authentication strategy (useful for CLI when token changes)
@@ -561,6 +579,7 @@ export {
561
579
  AuthResource,
562
580
  BearerAuth,
563
581
  CustomersResource,
582
+ InvoicesResource,
564
583
  OAuthResource,
565
584
  OrganizationsResource,
566
585
  ProductsResource,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@timbrix/sdk",
3
- "version": "0.3.1",
3
+ "version": "1.0.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/typescript-config": "0.1.0",
36
- "@repo/eslint-config": "0.1.1"
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",