@garuhq/node 0.15.0 → 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.ts CHANGED
@@ -98,15 +98,13 @@ declare class HttpClient {
98
98
  * The resource layer maps friendly → wire at the edge.
99
99
  */
100
100
 
101
- type PaymentMethod = 'pix' | 'credit_card' | 'boleto';
102
101
  /**
103
- * Payment-method identifier as it appears on the wire. `pix_automatic`
104
- * (Pix Automático auto-debit) surfaces here on transactions/charges read
105
- * back from Pix Automático recurring cycles. It is never produced by
106
- * `toWirePaymentMethod`, since one-off charges can't use it.
102
+ * Stable, friendly charge status. Mirrors what /api/v1/charges returns — the
103
+ * raw processor statuses (payedPix, pendingBoleto, ) are normalized server-side
104
+ * and never surface here. Act on `paid`; `authorized` is card money held but not
105
+ * captured, `refund_pending` is a Pix devolução requested but not yet settled.
107
106
  */
108
- type WirePaymentMethodId = 'pix' | 'creditcard' | 'boleto' | 'pix_automatic';
109
- type ChargeStatus = 'pending' | 'authorized' | 'paid' | 'failed' | 'refunded' | 'cancelled' | 'expired';
107
+ type ChargeStatus = 'pending' | 'authorized' | 'paid' | 'failed' | 'expired' | 'canceled' | 'refund_pending' | 'refunded' | 'chargeback';
110
108
  interface Customer {
111
109
  /** Full legal name. 3–255 chars. */
112
110
  name: string;
@@ -125,78 +123,122 @@ interface Customer {
125
123
  /** 2-letter uppercase state code, e.g. `SP`. */
126
124
  state?: string;
127
125
  }
128
- interface CardInfo {
129
- /** 1319 digits, no spaces or hyphens. */
130
- cardNumber: string;
131
- /** 3 or 4 digits. */
132
- cvv: string;
133
- /** `YYYY-MM`. */
134
- expirationDate: string;
135
- /** As printed on the card. */
126
+ interface CardInput {
127
+ /** PAN, 13-19 digits, no spaces. Server-to-server only (PCI scope). */
128
+ number: string;
129
+ /** Holder name exactly as printed. */
136
130
  holderName: string;
137
- /** 1–12. */
131
+ /** Expiry as `YYYY-MM`. */
132
+ expirationDate: string;
133
+ /** 3 or 4 digits. Never stored by Garu. */
134
+ cvv: string;
135
+ /** 1-12. */
138
136
  installments: number;
139
137
  }
140
138
  interface CreateChargeParams {
141
- /** Customer buying the product. */
142
- customer: Customer;
143
139
  /** UUID of the product being charged. */
144
140
  productId: string;
145
141
  /** Payment method. */
146
- paymentMethod: PaymentMethod;
147
- /** Required when `paymentMethod` is `credit_card`. */
148
- cardInfo?: CardInfo;
149
- /** Free-form metadata attached to the charge. */
150
- additionalInfo?: string;
151
- /** Original checkout link, if any. */
152
- link?: string | null;
153
- /** Associated affiliate ID, if any. */
154
- affiliateId?: number | null;
155
- /** Subscription price ID (`price_*`), for subscription charges only. */
156
- priceId?: string | null;
157
- /** Optional pre-created checkout session token. */
158
- checkoutSessionToken?: string;
142
+ paymentMethod: ChargePaymentMethod;
143
+ /** Customer buying the product. */
144
+ customer: Customer;
159
145
  /**
160
- * Idempotency key. If omitted, the SDK generates a UUIDv4.
161
- * Keys are valid for 24h on the backend.
146
+ * Required when `paymentMethod` is `creditCard`. This is a raw PAN + CVV, so
147
+ * call the SDK only from your server, never a browser or app — it puts you in
148
+ * PCI DSS scope.
162
149
  */
150
+ card?: CardInput;
151
+ /** Optional pre-created checkout session token, for attribution. */
152
+ checkoutSessionToken?: string;
153
+ /** Free-form metadata attached to the charge. */
154
+ additionalInfo?: string;
155
+ /** Idempotency key. If omitted, the SDK generates a UUIDv4. Valid 24h. */
163
156
  idempotencyKey?: string;
164
157
  }
158
+ type ChargePaymentMethod = 'pix' | 'boleto' | 'creditCard';
165
159
  interface Charge {
166
- id: number;
160
+ /** Public identifier. Use this everywhere; there is no numeric id. */
161
+ uuid: string;
167
162
  status: ChargeStatus;
163
+ paymentMethod: ChargePaymentMethod;
164
+ /** Product base price, in decimal BRL / reais. */
168
165
  amount: number;
169
- paymentMethodId: WirePaymentMethodId;
170
- /** ISO-8601. */
171
- date: string;
166
+ /**
167
+ * What the customer is actually charged, in reais. Equals `amount` for PIX,
168
+ * boleto and 1x card; higher for installment card sales (fator markup). Use
169
+ * this to reconcile, not `amount`.
170
+ */
171
+ chargedTotal: number;
172
+ installments: number;
173
+ product: {
174
+ uuid: string;
175
+ name: string;
176
+ } | null;
177
+ /** `document` is partially masked. */
178
+ customer: {
179
+ name: string;
180
+ email: string;
181
+ document: string;
182
+ } | null;
183
+ /** Present for PIX: the copy-paste EMV code to render as a QR. */
184
+ pix: {
185
+ code: string;
186
+ } | null;
187
+ /** Present for boleto: the barcode line and a Garu-hosted PDF URL. */
188
+ boleto: {
189
+ barcodeLine: string;
190
+ pdfUrl: string;
191
+ } | null;
192
+ /** Present for card: only brand, last4 and the authorization code. */
193
+ card: {
194
+ brand: string | null;
195
+ last4: string | null;
196
+ authorizationCode: string | null;
197
+ } | null;
198
+ /** Set once refunded. `refundedAt` is null while a Pix devolução is unsettled. */
199
+ refund: {
200
+ amount: number;
201
+ reason: string | null;
202
+ refundedAt: string | null;
203
+ } | null;
172
204
  /** ISO-8601. */
173
- deadline?: string;
174
- /** Product this charge belongs to. */
175
- product?: {
176
- id: number;
177
- uuid?: string;
178
- name?: string;
179
- };
180
- [key: string]: unknown;
205
+ createdAt: string;
206
+ /** ISO-8601. Only set for boleto (due date); null for PIX and card. */
207
+ expiresAt: string | null;
181
208
  }
182
209
  interface RefundChargeParams {
183
- /** Partial refund in centavos. Omit for full refund. */
210
+ /**
211
+ * Partial refund in **decimal BRL / reais** (e.g. `10.00`) — NOT centavos.
212
+ * Omit for a full refund. Passing `1000` for "R$ 10,00" refunds a thousand
213
+ * reais.
214
+ *
215
+ * For a Pix Automático charge this starts an asynchronous devolução: the
216
+ * charge moves to `refund_pending` and only reaches `refunded` once the
217
+ * transfer settles.
218
+ */
184
219
  amount?: number;
185
220
  /** Free-form reason stored on the refund. */
186
221
  reason?: string;
187
- idempotencyKey?: string;
188
222
  }
189
223
  interface ListChargesParams {
190
224
  /** Page number (1-based). Default: 1. */
191
225
  page?: number;
192
- /** Items per page (1100). Default: 20. */
226
+ /** Items per page (1-100). Default: 20. */
193
227
  limit?: number;
194
- /** Filter by status (e.g. `paid`, `pending`). */
195
- status?: string;
228
+ /** Filter by friendly status (e.g. `paid`, `pending`). */
229
+ status?: ChargeStatus;
230
+ /** Filter by payment method. */
231
+ paymentMethod?: ChargePaymentMethod;
232
+ /** Filter by product UUID. */
233
+ productId?: string;
234
+ /** Charges created at or after this ISO-8601 instant. */
235
+ createdAfter?: string;
236
+ /** Charges created at or before this ISO-8601 instant. */
237
+ createdBefore?: string;
196
238
  /** Search by customer name, email, or document. */
197
239
  search?: string;
198
- /** Filter by payment method (`pix`, `creditcard`, `boleto`). */
199
- paymentMethod?: string;
240
+ /** Sort order. Default `-createdAt` (newest first). */
241
+ sort?: 'createdAt' | '-createdAt' | 'amount' | '-amount';
200
242
  }
201
243
  interface PaginatedList<T> {
202
244
  data: T[];
@@ -207,7 +249,18 @@ interface PaginatedList<T> {
207
249
  totalPages: number;
208
250
  };
209
251
  }
210
- type ChargeList = PaginatedList<Charge>;
252
+ interface ChargeList {
253
+ data: Charge[];
254
+ /** Items on this page. */
255
+ count: number;
256
+ /** Total matches across all pages. */
257
+ totalCount: number;
258
+ totalPages: number;
259
+ }
260
+ /** Result of cancelling a charge. */
261
+ interface CancelChargeResult {
262
+ canceled: boolean;
263
+ }
211
264
  interface CustomerRecord {
212
265
  id: number;
213
266
  name: string;
@@ -509,12 +562,17 @@ interface ChargeNowResult {
509
562
  message: string;
510
563
  }
511
564
  interface Product {
512
- id: number;
565
+ /**
566
+ * @deprecated The v1 API no longer returns a numeric id — use `uuid` to
567
+ * address a product. Present only on legacy `/api/products/*` responses;
568
+ * `undefined` on v1.
569
+ */
570
+ id?: number;
513
571
  uuid: string;
514
572
  name: string;
515
573
  description: string;
516
574
  image: string;
517
- /** Price in centavos (BRL × 100). */
575
+ /** Price in decimal BRL / reais (e.g. `297.50`) — NOT centavos. */
518
576
  value: number;
519
577
  sellerId: number;
520
578
  sellerName?: string;
@@ -528,7 +586,8 @@ interface Product {
528
586
  * checkout mode reads this flag. See {@link ScheduledPaymentMethod}.
529
587
  */
530
588
  pixAutomatic: boolean;
531
- installments: number[];
589
+ /** Per-parcela credit-card breakdown (the amount charged per installment). */
590
+ installments: Installment[];
532
591
  tags?: string[];
533
592
  isSubscription?: boolean;
534
593
  subscriptionType?: string;
@@ -541,18 +600,36 @@ interface Product {
541
600
  updatedAt: string;
542
601
  [key: string]: unknown;
543
602
  }
544
- type ProductList = PaginatedList<Product>;
603
+ /** One entry in a product's credit-card installment breakdown. */
604
+ interface Installment {
605
+ /** Number of parcelas. */
606
+ quantity: number;
607
+ /** Amount charged per installment, in reais (BRL), with the fator markup applied. */
608
+ value: number;
609
+ }
610
+ /**
611
+ * List envelope returned by `products.list()`. Flat (not `{ data, meta }`) —
612
+ * matches the `/api/v1/products` response.
613
+ */
614
+ interface ProductList {
615
+ data: Product[];
616
+ /** Items returned on this page. */
617
+ count: number;
618
+ /** Total products matching the filter across all pages. */
619
+ totalCount: number;
620
+ totalPages: number;
621
+ }
545
622
  interface ListProductsParams {
546
623
  page?: number;
547
624
  limit?: number;
548
625
  /** Search by product name. */
549
626
  search?: string;
550
- /** Backend tab filter (e.g. `active`, `archived`). Backend default is used when omitted. */
627
+ /** @deprecated Not supported by the v1 API (ignored). `list()` returns the seller's own products. */
551
628
  tab?: string;
552
629
  }
553
630
  interface CreateProductParams {
554
631
  name: string;
555
- /** Price in centavos (BRL × 100). */
632
+ /** Price in decimal BRL / reais (e.g. `297.50`) — NOT centavos. */
556
633
  value?: number;
557
634
  description?: string;
558
635
  /** HTTPS URL of the product cover image. */
@@ -585,6 +662,7 @@ interface CreateProductParams {
585
662
  }
586
663
  interface UpdateProductParams {
587
664
  name?: string;
665
+ /** Price in decimal BRL / reais (e.g. `297.50`) — NOT centavos. */
588
666
  value?: number;
589
667
  description?: string;
590
668
  image?: string;
@@ -789,27 +867,27 @@ interface SetProductPortalConfigParams {
789
867
  }
790
868
 
791
869
  /**
792
- * Charges — the core of the Garu API.
870
+ * Charges — create and manage payments against a product.
793
871
  *
794
- * A charge represents a single payment attempt against a product. The SDK
795
- * surfaces charges under `garu.charges` even though the backend route is
796
- * `/api/transactions` this matches Stripe convention and is the name every
797
- * other Garu surface (MCP, CLI, docs) uses.
872
+ * Backed by `/api/v1/charges`, the versioned public contract. A charge is keyed
873
+ * by `uuid`; there is no numeric id. Create returns everything needed to render
874
+ * a transparent checkout: the PIX EMV (`pix.code`), the boleto line and a
875
+ * Garu-hosted PDF (`boleto`), or the card authorization (`card`).
798
876
  */
799
877
  declare class Charges {
800
878
  private readonly http;
801
879
  constructor(http: HttpClient);
802
880
  /**
803
- * Create a charge (PIX, credit card, or boleto).
881
+ * Create a charge (PIX, boleto, or credit card).
804
882
  *
805
- * Automatically attaches an `X-Idempotency-Key` header — if you don't pass
806
- * `idempotencyKey`, the SDK generates a UUIDv4. Safe to retry: the backend
807
- * caches the first response for 24h.
883
+ * Attaches an `X-Idempotency-Key` header automatically — if you don't pass
884
+ * `idempotencyKey`, the SDK generates a UUIDv4. Safe to retry: the same key
885
+ * returns the original charge for 24h.
808
886
  *
809
887
  * @example
810
- * // PIX charge
888
+ * // PIX — render charge.pix.code as a QR in your own checkout
811
889
  * const charge = await garu.charges.create({
812
- * productId: 'b3f2c1e8-6e4a-4b9f-9d1c-2a1f6c3d4e5f',
890
+ * productId: 'a1b2c3d4-e5f6-7890-abcd-ef1234567890',
813
891
  * paymentMethod: 'pix',
814
892
  * customer: {
815
893
  * name: 'Maria Silva',
@@ -818,53 +896,62 @@ declare class Charges {
818
896
  * phone: '11987654321'
819
897
  * }
820
898
  * });
821
- * // charge.id, charge.status
899
+ * console.log(charge.uuid, charge.pix?.code);
822
900
  *
823
901
  * @example
824
- * // Credit card charge, 3 installments
902
+ * // Credit card, 2 installments. Server-to-server only (PCI scope).
825
903
  * const charge = await garu.charges.create({
826
- * productId: 'b3f2c1e8-6e4a-4b9f-9d1c-2a1f6c3d4e5f',
827
- * paymentMethod: 'credit_card',
904
+ * productId: 'a1b2c3d4-e5f6-7890-abcd-ef1234567890',
905
+ * paymentMethod: 'creditCard',
828
906
  * customer: { name: 'Maria Silva', email: 'maria@exemplo.com.br', document: '12345678909', phone: '11987654321' },
829
- * cardInfo: {
830
- * cardNumber: '4111111111111111',
831
- * cvv: '123',
832
- * expirationDate: '2030-12',
907
+ * card: {
908
+ * number: '4111111111111111',
833
909
  * holderName: 'MARIA SILVA',
834
- * installments: 3
910
+ * expirationDate: '2030-12',
911
+ * cvv: '123',
912
+ * installments: 2
835
913
  * }
836
914
  * });
915
+ * // charge.amount is the base price; charge.chargedTotal is what was charged.
837
916
  */
838
917
  create(params: CreateChargeParams): Promise<Charge>;
839
918
  /**
840
- * List charges for the authenticated seller, with pagination and filters.
919
+ * Retrieve a charge by uuid.
841
920
  *
842
921
  * @example
843
- * const { data, meta } = await garu.charges.list({ status: 'paid', limit: 10 });
844
- * // meta.total paid charges
922
+ * const charge = await garu.charges.retrieve('6f1c9b2e-4a7d-4f0b-9a3e-1d2c3b4a5e6f');
923
+ * if (charge.status === 'paid') fulfil(charge);
845
924
  */
846
- list(params?: ListChargesParams): Promise<ChargeList>;
925
+ retrieve(uuid: string): Promise<Charge>;
847
926
  /**
848
- * Fetch a single charge by numeric ID.
927
+ * List charges for the authenticated account, newest first by default.
849
928
  *
850
929
  * @example
851
- * const charge = await garu.charges.get(4472);
852
- * if (charge.status === 'paid') { ... }
930
+ * const { data, totalCount } = await garu.charges.list({ status: 'paid', limit: 50 });
931
+ * console.log(`${data.length} of ${totalCount} paid charges`);
853
932
  */
854
- get(id: number): Promise<Charge>;
933
+ list(params?: ListChargesParams): Promise<ChargeList>;
855
934
  /**
856
- * Refund a charge fully, or partially by passing `amount` in centavos.
935
+ * Refund a charge, fully or partially. `amount` is in reais.
936
+ *
937
+ * For a Pix Automático charge the refund is a devolução: it returns with the
938
+ * charge in `refund_pending`, reaching `refunded` only once the transfer
939
+ * settles.
857
940
  *
858
941
  * @example
859
- * // Full refund
860
- * await garu.charges.refund(4472);
942
+ * await garu.charges.refund('6f1c9b2e-...'); // full
943
+ * await garu.charges.refund('6f1c9b2e-...', { amount: 10.0 }); // R$10,00
944
+ */
945
+ refund(uuid: string, params?: RefundChargeParams): Promise<Charge>;
946
+ /**
947
+ * Cancel an unpaid charge.
861
948
  *
862
949
  * @example
863
- * // Partial refund of R$ 10,00
864
- * await garu.charges.refund(4472, { amount: 1000, reason: 'customer_request' });
950
+ * const { canceled } = await garu.charges.cancel('6f1c9b2e-...');
865
951
  */
866
- refund(id: number, params?: RefundChargeParams): Promise<Charge>;
867
- private buildCreateBody;
952
+ cancel(uuid: string): Promise<CancelChargeResult>;
953
+ private get;
954
+ private post;
868
955
  }
869
956
 
870
957
  /**
@@ -1023,7 +1110,7 @@ declare class Products {
1023
1110
  * List products for the authenticated seller, with pagination and search.
1024
1111
  *
1025
1112
  * @example
1026
- * const { data, meta } = await garu.products.list({ search: 'curso', limit: 10 });
1113
+ * const { data, totalCount } = await garu.products.list({ search: 'curso', limit: 10 });
1027
1114
  */
1028
1115
  list(params?: ListProductsParams): Promise<ProductList>;
1029
1116
  /**
@@ -1047,7 +1134,7 @@ declare class Products {
1047
1134
  * @example
1048
1135
  * const product = await garu.products.create({
1049
1136
  * name: 'Plano Mensal',
1050
- * value: 4990, // R$ 49,90 in centavos
1137
+ * value: 49.90, // R$ 49,90 in reais (decimal BRL), NOT centavos
1051
1138
  * description: 'Acesso completo à plataforma',
1052
1139
  * pix: true,
1053
1140
  * creditCard: true,
@@ -1061,13 +1148,13 @@ declare class Products {
1061
1148
  * Update a product (partial PATCH — only the fields you pass are changed).
1062
1149
  * Returns the updated product.
1063
1150
  *
1064
- * `id` accepts the numeric id or the product UUID the same identifiers
1065
- * accepted elsewhere on the `/api/products/:id` path (see
1151
+ * `id` accepts the product UUID (recommended) or the legacy numeric id
1152
+ * both resolve on the `/api/v1/products/:id` path (see
1066
1153
  * {@link ProductPortalConfigResource}).
1067
1154
  *
1068
1155
  * @example
1069
1156
  * const updated = await garu.products.update('b3f2c1e8-6e4a-4b9f-9d1c-2a1f6c3d4e5f', {
1070
- * value: 5990,
1157
+ * value: 59.90, // reais (decimal BRL), NOT centavos
1071
1158
  * pixAutomatic: true // turn on Pix Automático for this product
1072
1159
  * });
1073
1160
  */
@@ -1480,4 +1567,4 @@ declare class GaruServerError extends GaruAPIError {
1480
1567
  constructor(message: string, status: number, requestId: string | null, body: unknown);
1481
1568
  }
1482
1569
 
1483
- export { type CancelAtPeriodEndScheduledChargeParams, type CancelRecurrenceScheduledChargeParams, type CardInfo, type ChangePaymentMethodScheduledChargeParams, type Charge, type ChargeList, type ChargeNowOutcome, type ChargeNowReason, type ChargeNowResult, type ChargeStatus, type CreateChargeParams, type CreateCustomerParams, type CreateProductParams, type CreateScheduledChargeParams, type Customer, type CustomerList, type CustomerRecord, type FailurePayload, Garu, GaruAPIError, GaruAuthenticationError, GaruConnectionError, GaruError, type GaruErrorCode, type GaruFailureCode, GaruNotFoundError, type GaruOptions, GaruPermissionError, GaruRateLimitError, GaruServerError, GaruSignatureVerificationError, GaruValidationError, type ListChargesParams, type ListCustomersParams, type ListProductsParams, type ListScheduledChargeAttemptsParams, type ListScheduledChargesParams, type ListWebhookEventsParams, type MarkPaidScheduledChargeParams, type MetaFeatures, type MetaResponse, type PaginatedList, type PauseScheduledChargeParams, type PaymentMethod, type PaymentMethodExpiredPayload, type PaymentMethodExpiringPayload, type PostponeScheduledChargeParams, type Product, type ProductList, type ProductPortalConfig, type RecurrenceConfig, type RecurrenceInterval, type RefundChargeParams, type ResendWebhookEventParams, type ScheduledChargeActor, type ScheduledChargeAttempt, type ScheduledChargeAttemptList, type ScheduledChargeAttemptSource, type ScheduledChargeAttemptStatus, type ScheduledChargeDetail, type ScheduledChargeEvent, type ScheduledChargeEventType, type ScheduledChargeLinkedTransaction, type ScheduledChargeList, type ScheduledChargeRecord, type ScheduledChargeStatus, type ScheduledChargeType, type ScheduledPaymentMethod, type SetProductPortalConfigParams, type UpdateCustomerParams, type UpdateProductParams, type VerifiedWebhook, type VerifyWebhookParams, type WebhookEvent, type WebhookEventEndpoint, type WebhookEventList, type WebhookEventStatus, type WirePaymentMethodId, webhooks };
1570
+ export { type CancelAtPeriodEndScheduledChargeParams, type CancelChargeResult, type CancelRecurrenceScheduledChargeParams, type CardInput, type ChangePaymentMethodScheduledChargeParams, type Charge, type ChargeList, type ChargeNowOutcome, type ChargeNowReason, type ChargeNowResult, type ChargePaymentMethod, type ChargeStatus, type CreateChargeParams, type CreateCustomerParams, type CreateProductParams, type CreateScheduledChargeParams, type Customer, type CustomerList, type CustomerRecord, type FailurePayload, Garu, GaruAPIError, GaruAuthenticationError, GaruConnectionError, GaruError, type GaruErrorCode, type GaruFailureCode, GaruNotFoundError, type GaruOptions, GaruPermissionError, GaruRateLimitError, GaruServerError, GaruSignatureVerificationError, GaruValidationError, type ListChargesParams, type ListCustomersParams, type ListProductsParams, type ListScheduledChargeAttemptsParams, type ListScheduledChargesParams, type ListWebhookEventsParams, type MarkPaidScheduledChargeParams, type MetaFeatures, type MetaResponse, type PaginatedList, type PauseScheduledChargeParams, type PaymentMethodExpiredPayload, type PaymentMethodExpiringPayload, type PostponeScheduledChargeParams, type Product, type ProductList, type ProductPortalConfig, type RecurrenceConfig, type RecurrenceInterval, type RefundChargeParams, type ResendWebhookEventParams, type ScheduledChargeActor, type ScheduledChargeAttempt, type ScheduledChargeAttemptList, type ScheduledChargeAttemptSource, type ScheduledChargeAttemptStatus, type ScheduledChargeDetail, type ScheduledChargeEvent, type ScheduledChargeEventType, type ScheduledChargeLinkedTransaction, type ScheduledChargeList, type ScheduledChargeRecord, type ScheduledChargeStatus, type ScheduledChargeType, type ScheduledPaymentMethod, type SetProductPortalConfigParams, type UpdateCustomerParams, type UpdateProductParams, type VerifiedWebhook, type VerifyWebhookParams, type WebhookEvent, type WebhookEventEndpoint, type WebhookEventList, type WebhookEventStatus, webhooks };