@garuhq/node 2.0.0 → 4.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.js CHANGED
@@ -936,9 +936,13 @@ var ScheduledCharges = class {
936
936
  }
937
937
  http;
938
938
  /**
939
- * Create a new scheduled charge. Auto-attaches `X-Idempotency-Key`
940
- * (UUIDv4 if you don't pass `idempotencyKey`) so retries on transient
941
- * network failures don't silently double-create.
939
+ * Create a new scheduled charge. The SDK attaches an `X-Idempotency-Key`
940
+ * header (UUIDv4 unless you pass `idempotencyKey`), but the gateway does
941
+ * not currently deduplicate `/scheduled-charges` creates against it — a
942
+ * retry after a network failure can create more than one series. Pair
943
+ * this with your own retry-suppression (e.g. check `list` for an existing
944
+ * series with the same `externalReference`) if that matters for your
945
+ * integration.
942
946
  *
943
947
  * @example
944
948
  * const charge = await garu.scheduledCharges.create({
@@ -968,7 +972,7 @@ var ScheduledCharges = class {
968
972
  const idempotencyKey = params.idempotencyKey ?? generateIdempotencyKey();
969
973
  const { idempotencyKey: _omit, ...body } = params;
970
974
  return this.http.call(
971
- (signal) => this.http.client.POST("/api/scheduled-charges", {
975
+ (signal) => this.http.client.POST("/api/v1/scheduled-charges", {
972
976
  body,
973
977
  headers: { "X-Idempotency-Key": idempotencyKey },
974
978
  signal
@@ -1003,7 +1007,7 @@ var ScheduledCharges = class {
1003
1007
  for (const s of statuses) qs.append("status", s);
1004
1008
  }
1005
1009
  const query = qs.toString();
1006
- const url = `/api/scheduled-charges${query ? `?${query}` : ""}`;
1010
+ const url = `/api/v1/scheduled-charges${query ? `?${query}` : ""}`;
1007
1011
  return this.http.call(
1008
1012
  (signal) => this.http.client.GET(url, { signal }).then(
1009
1013
  (r) => r
@@ -1020,7 +1024,7 @@ var ScheduledCharges = class {
1020
1024
  */
1021
1025
  async get(id) {
1022
1026
  return this.http.call(
1023
- (signal) => this.http.client.GET(`/api/scheduled-charges/${encodeURIComponent(id)}`, {
1027
+ (signal) => this.http.client.GET(`/api/v1/scheduled-charges/${encodeURIComponent(id)}`, {
1024
1028
  signal
1025
1029
  }).then((r) => r)
1026
1030
  );
@@ -1039,7 +1043,7 @@ var ScheduledCharges = class {
1039
1043
  async postpone(id, params) {
1040
1044
  return this.http.call(
1041
1045
  (signal) => this.http.client.POST(
1042
- `/api/scheduled-charges/${encodeURIComponent(id)}/postpone`,
1046
+ `/api/v1/scheduled-charges/${encodeURIComponent(id)}/postpone`,
1043
1047
  {
1044
1048
  body: params,
1045
1049
  signal
@@ -1058,7 +1062,7 @@ var ScheduledCharges = class {
1058
1062
  async pause(id, params = {}) {
1059
1063
  return this.http.call(
1060
1064
  (signal) => this.http.client.POST(
1061
- `/api/scheduled-charges/${encodeURIComponent(id)}/pause`,
1065
+ `/api/v1/scheduled-charges/${encodeURIComponent(id)}/pause`,
1062
1066
  {
1063
1067
  body: params,
1064
1068
  signal
@@ -1075,7 +1079,7 @@ var ScheduledCharges = class {
1075
1079
  async resume(id) {
1076
1080
  return this.http.call(
1077
1081
  (signal) => this.http.client.POST(
1078
- `/api/scheduled-charges/${encodeURIComponent(id)}/resume`,
1082
+ `/api/v1/scheduled-charges/${encodeURIComponent(id)}/resume`,
1079
1083
  {
1080
1084
  body: {},
1081
1085
  signal
@@ -1109,7 +1113,7 @@ var ScheduledCharges = class {
1109
1113
  async markPaid(id, params) {
1110
1114
  return this.http.call(
1111
1115
  (signal) => this.http.client.POST(
1112
- `/api/scheduled-charges/${encodeURIComponent(id)}/mark-paid`,
1116
+ `/api/v1/scheduled-charges/${encodeURIComponent(id)}/mark-paid`,
1113
1117
  {
1114
1118
  body: params,
1115
1119
  signal
@@ -1131,24 +1135,22 @@ var ScheduledCharges = class {
1131
1135
  * const result = await garu.scheduledCharges.chargeNow('sch_abc123');
1132
1136
  * switch (result.outcome) {
1133
1137
  * case 'dispatched':
1134
- * console.log(`Cobrança enviada (ciclo ${result.cycleNumber}).`);
1138
+ * result.cycleNumber; // billed this cycle
1135
1139
  * break;
1136
1140
  * case 'already_sent':
1137
- * console.log('Já havia sido enviada — nada a fazer.');
1138
- * break;
1141
+ * break; // nothing to do
1139
1142
  * case 'failed':
1140
- * // result.reason is e.g. 'card_expired' or a gateway decline code
1141
- * console.error(`Falha na cobrança: ${result.reason}. ${result.message}`);
1143
+ * result.reason; // e.g. 'card_expired' or a gateway decline code
1142
1144
  * break;
1143
1145
  * case 'not_sent':
1144
- * console.warn(`Não enviada (${result.reason}): ${result.message}`);
1146
+ * result.reason;
1145
1147
  * break;
1146
1148
  * }
1147
1149
  */
1148
1150
  async chargeNow(id) {
1149
1151
  return this.http.call(
1150
1152
  (signal) => this.http.client.POST(
1151
- `/api/scheduled-charges/${encodeURIComponent(id)}/charge-now`,
1153
+ `/api/v1/scheduled-charges/${encodeURIComponent(id)}/charge-now`,
1152
1154
  {
1153
1155
  body: {},
1154
1156
  signal
@@ -1170,7 +1172,7 @@ var ScheduledCharges = class {
1170
1172
  async cancelRecurrence(id, params = {}) {
1171
1173
  return this.http.call(
1172
1174
  (signal) => this.http.client.POST(
1173
- `/api/scheduled-charges/${encodeURIComponent(id)}/cancel-recurrence`,
1175
+ `/api/v1/scheduled-charges/${encodeURIComponent(id)}/cancel-recurrence`,
1174
1176
  {
1175
1177
  body: params,
1176
1178
  signal
@@ -1190,7 +1192,7 @@ var ScheduledCharges = class {
1190
1192
  async setCancelAtPeriodEnd(id, params) {
1191
1193
  return this.http.call(
1192
1194
  (signal) => this.http.client.POST(
1193
- `/api/scheduled-charges/${encodeURIComponent(id)}/cancel-at-period-end`,
1195
+ `/api/v1/scheduled-charges/${encodeURIComponent(id)}/cancel-at-period-end`,
1194
1196
  {
1195
1197
  body: params,
1196
1198
  signal
@@ -1209,7 +1211,7 @@ var ScheduledCharges = class {
1209
1211
  async changePaymentMethod(id, params) {
1210
1212
  return this.http.call(
1211
1213
  (signal) => this.http.client.POST(
1212
- `/api/scheduled-charges/${encodeURIComponent(id)}/payment-method`,
1214
+ `/api/v1/scheduled-charges/${encodeURIComponent(id)}/payment-method`,
1213
1215
  {
1214
1216
  body: params,
1215
1217
  signal
@@ -1228,7 +1230,7 @@ var ScheduledCharges = class {
1228
1230
  async clearPaymentMethod(id) {
1229
1231
  return this.http.call(
1230
1232
  (signal) => this.http.client.DELETE(
1231
- `/api/scheduled-charges/${encodeURIComponent(id)}/payment-method`,
1233
+ `/api/v1/scheduled-charges/${encodeURIComponent(id)}/payment-method`,
1232
1234
  {
1233
1235
  body: {},
1234
1236
  signal
@@ -1255,7 +1257,7 @@ var ScheduledCharges = class {
1255
1257
  if (params.limit !== void 0) qs.set("limit", String(params.limit));
1256
1258
  if (params.cycleNumber !== void 0) qs.set("cycleNumber", String(params.cycleNumber));
1257
1259
  const query = qs.toString();
1258
- const url = `/api/scheduled-charges/${encodeURIComponent(id)}/attempts${query ? `?${query}` : ""}`;
1260
+ const url = `/api/v1/scheduled-charges/${encodeURIComponent(id)}/attempts${query ? `?${query}` : ""}`;
1259
1261
  return this.http.call(
1260
1262
  (signal) => this.http.client.GET(url, { signal }).then(
1261
1263
  (r) => r
@@ -1287,42 +1289,31 @@ var WebhookEvents = class {
1287
1289
  * });
1288
1290
  */
1289
1291
  async list(params = {}) {
1290
- const qs = new URLSearchParams();
1291
- if (params.page !== void 0) qs.set("page", String(params.page));
1292
- if (params.limit !== void 0) qs.set("limit", String(params.limit));
1293
- if (params.status) qs.set("status", params.status);
1294
- if (params.eventType) qs.set("event_type", params.eventType);
1295
- if (params.endpointId !== void 0) qs.set("endpoint_id", String(params.endpointId));
1296
- const query = qs.toString();
1297
- const url = `/api/webhook-events${query ? `?${query}` : ""}`;
1298
- const raw = await this.http.call(
1292
+ const query = {};
1293
+ if (params.page !== void 0) query.page = String(params.page);
1294
+ if (params.limit !== void 0) query.limit = String(params.limit);
1295
+ if (params.status) query.status = params.status;
1296
+ if (params.eventType) query.eventType = params.eventType;
1297
+ if (params.endpointId !== void 0) query.endpointId = String(params.endpointId);
1298
+ const qs = new URLSearchParams(query).toString();
1299
+ const url = `/api/v1/webhook-events${qs ? `?${qs}` : ""}`;
1300
+ return this.http.call(
1299
1301
  (signal) => this.http.client.GET(url, { signal }).then(
1300
1302
  (r) => r
1301
1303
  )
1302
1304
  );
1303
- return {
1304
- data: raw.events,
1305
- meta: {
1306
- page: raw.page,
1307
- limit: raw.limit,
1308
- total: raw.total,
1309
- totalPages: raw.pages
1310
- }
1311
- };
1312
1305
  }
1313
1306
  /**
1314
- * Fetch one webhook event by numeric ID — includes the full payload, the
1307
+ * Fetch one webhook event by uuid — includes the full payload, the
1315
1308
  * embedded endpoint snapshot, and the most recent response status/body.
1316
1309
  *
1317
1310
  * @example
1318
- * const event = await garu.webhookEvents.get(42);
1319
- * if (event.status === 'failed') {
1320
- * console.log(event.responseStatus, event.responseBody);
1321
- * }
1311
+ * const event = await garu.webhookEvents.get('a1b2c3d4-e5f6-7890-abcd-ef1234567890');
1312
+ * event.status === 'failed' && event.responseStatus;
1322
1313
  */
1323
- async get(id) {
1314
+ async get(uuid) {
1324
1315
  return this.http.call(
1325
- (signal) => this.http.client.GET(`/api/webhook-events/${id}`, { signal }).then(
1316
+ (signal) => this.http.client.GET(`/api/v1/webhook-events/${uuid}`, { signal }).then(
1326
1317
  (r) => r
1327
1318
  )
1328
1319
  );
@@ -1335,28 +1326,28 @@ var WebhookEvents = class {
1335
1326
  * explicitly want the legacy in-place semantics (and for backwards
1336
1327
  * compatibility with older CLI / MCP releases).
1337
1328
  *
1338
- * Re-deliver a webhook event by ID. Resets it to `pending`, clears the
1329
+ * Re-deliver a webhook event by uuid. Resets it to `pending`, clears the
1339
1330
  * retry schedule, and triggers an immediate delivery attempt. Works on
1340
1331
  * any status (`success`, `failed`, `pending`).
1341
1332
  *
1342
1333
  * @example
1343
1334
  * const failed = await garu.webhookEvents.list({ status: 'failed', limit: 5 });
1344
1335
  * for (const event of failed.data) {
1345
- * await garu.webhookEvents.retry(event.id);
1336
+ * await garu.webhookEvents.retry(event.uuid);
1346
1337
  * }
1347
1338
  */
1348
- async retry(id) {
1339
+ async retry(uuid) {
1349
1340
  return this.http.call(
1350
- (signal) => this.http.client.POST(`/api/webhook-events/${id}/retry`, {
1341
+ (signal) => this.http.client.POST(`/api/v1/webhook-events/${uuid}/retry`, {
1351
1342
  body: {},
1352
1343
  signal
1353
1344
  }).then((r) => r)
1354
1345
  );
1355
1346
  }
1356
1347
  /**
1357
- * Re-deliver a webhook event by ID, audit-trail preserving. Unlike
1348
+ * Re-deliver a webhook event by uuid, audit-trail preserving. Unlike
1358
1349
  * {@link retry}, this does *not* mutate the original row — it inserts a
1359
- * fresh event (new numeric id) that points back at the source via
1350
+ * fresh event (new uuid) that points back at the source via
1360
1351
  * `manualResendOf`, then dispatches that clone. The original row is
1361
1352
  * untouched, so the historical record of the prior failure (and its
1362
1353
  * response status / body) is preserved.
@@ -1367,30 +1358,30 @@ var WebhookEvents = class {
1367
1358
  * delivery's outcome to remain on the record.
1368
1359
  *
1369
1360
  * **Outbound delivery semantics**: the gateway POSTs the clone with
1370
- * `Idempotency-Key: resend_<originalId>` (where `<originalId>` is the id
1371
- * of the source event, not the clone). Recipient handlers that key off
1361
+ * `Idempotency-Key: resend_<cloneUuid>`. Recipient handlers that key off
1372
1362
  * `Idempotency-Key` will see this as a distinct delivery from the
1373
1363
  * original — distinguishable both by the `resend_` prefix and by reading
1374
1364
  * the response payload's `manualResendOf` field.
1375
1365
  *
1376
- * **SDK→gateway dedup**: the SDK auto-attaches `X-Idempotency-Key`
1377
- * (UUIDv4 unless you pass `idempotencyKey`) so transient transport
1378
- * retries (5xx SDK backoff) cannot create duplicate clones the
1379
- * backend returns the original clone on the second call within 24h.
1366
+ * The SDK also attaches an `X-Idempotency-Key` header (UUIDv4 unless you
1367
+ * pass `idempotencyKey`); the gateway does not currently deduplicate
1368
+ * `/resend` calls against it, so retrying this call from your own code
1369
+ * after a network failure can create more than one clone — pair it with
1370
+ * your own retry-suppression if that matters for your integration.
1380
1371
  *
1381
- * Returns the *clone* event (new id), not the original. The original is
1372
+ * Returns the *clone* event (new uuid), not the original. The original is
1382
1373
  * unchanged on the server.
1383
1374
  *
1384
1375
  * @example
1385
- * const event = await garu.webhookEvents.get(42);
1386
- * const clone = await garu.webhookEvents.resend(42);
1387
- * clone.id !== event.id; // true — clone has its own id
1388
- * clone.manualResendOf === event.id; // true — points back at the source
1376
+ * const event = await garu.webhookEvents.get('a1b2c3d4-e5f6-7890-abcd-ef1234567890');
1377
+ * const clone = await garu.webhookEvents.resend(event.uuid);
1378
+ * clone.uuid !== event.uuid; // true — clone has its own uuid
1379
+ * clone.manualResendOf === event.uuid; // true — points back at the source
1389
1380
  */
1390
- async resend(id, params = {}) {
1381
+ async resend(uuid, params = {}) {
1391
1382
  const idempotencyKey = params.idempotencyKey ?? generateIdempotencyKey();
1392
1383
  return this.http.call(
1393
- (signal) => this.http.client.POST(`/api/webhook-events/${id}/resend`, {
1384
+ (signal) => this.http.client.POST(`/api/v1/webhook-events/${uuid}/resend`, {
1394
1385
  body: {},
1395
1386
  headers: { "X-Idempotency-Key": idempotencyKey },
1396
1387
  signal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@garuhq/node",
3
- "version": "2.0.0",
3
+ "version": "4.0.0",
4
4
  "description": "Official Node.js / TypeScript SDK for the Garu payment gateway.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://garu.com.br",