@geekapps/billing-fastify 0.13.0 → 0.15.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
@@ -131,9 +131,23 @@ interface CustomerInput {
131
131
  address_state?: string;
132
132
  address_postal_code?: string;
133
133
  address_country?: string;
134
- /** Para CNPJ, completa com os dados da Receita Federal os campos não informados. Default: true. */
134
+ /**
135
+ * Para CNPJ, razão social e endereço vêm sempre da Receita Federal (o que for enviado é
136
+ * ignorado). Default: true.
137
+ */
135
138
  autofill?: boolean;
139
+ /**
140
+ * Obrigatório (`true`) quando a Receita não pôde ser consultada e os dados da empresa
141
+ * foram informados à mão: aceite da declaração de que as informações são verdadeiras e de
142
+ * que quem as forneceu responde por elas. Sem isso a API responde 422
143
+ * `{ code: "manual_declaration_required", declaration }`.
144
+ */
145
+ manual_declaration?: boolean;
136
146
  }
147
+ /**
148
+ * Em empresa verificada (`registry_synced_at` preenchido), razão social e endereço não podem
149
+ * ser alterados (409) — use `customers.refreshRegistry(id)`.
150
+ */
137
151
  type CustomerUpdateInput = Partial<Omit<CustomerInput, "autofill" | "external_ref">> & {
138
152
  /** `null` remove a referência. */
139
153
  external_ref?: string | null;
@@ -164,6 +178,11 @@ interface Customer {
164
178
  /** Pessoa física: "***" quando presente. Empresa: completo. */
165
179
  address_line2: string | null;
166
180
  address_district: string | null;
181
+ /** Empresa: data da última sincronização de razão social/endereço com a Receita Federal
182
+ * (null = não verificada, dados declarados manualmente). */
183
+ registry_synced_at?: string | null;
184
+ /** Empresa não verificada: quando a declaração de veracidade foi aceita. */
185
+ registry_declared_at?: string | null;
167
186
  address_city: string | null;
168
187
  address_state: string | null;
169
188
  /** Mascarado, mantém só o prefixo (ex: "01310***"). */
@@ -314,6 +333,8 @@ interface CompanyTaxIdData {
314
333
  legal_nature: string | null;
315
334
  email: string | null;
316
335
  phone: string | null;
336
+ /** Inscrição estadual (quando a fonte informa). */
337
+ state_registration: string | null;
317
338
  address_line1: string | null;
318
339
  address_number: string | null;
319
340
  address_line2: string | null;
@@ -322,6 +343,8 @@ interface CompanyTaxIdData {
322
343
  address_state: string | null;
323
344
  address_postal_code: string | null;
324
345
  address_country: string;
346
+ /** Base que respondeu: "minhareceita" | "brasilapi" | "cnpja" | "cnpjws" | "receitaws". */
347
+ source: string;
325
348
  }
326
349
  interface TaxIdLookupResult {
327
350
  tax_id: string;
@@ -603,6 +626,16 @@ interface CreateOrderResult {
603
626
  payment_ref: string;
604
627
  stripe_publishable_key: string | null;
605
628
  }
629
+ interface CepLookupResult {
630
+ postal_code: string;
631
+ address_line1: string | null;
632
+ address_district: string | null;
633
+ address_city: string;
634
+ address_state: string;
635
+ address_country: "BR";
636
+ /** Base que respondeu: "viacep" | "brasilapi" | "opencep" | "awesomeapi" | "apicep". */
637
+ source: string;
638
+ }
606
639
 
607
640
  declare class ChargesResource {
608
641
  private readonly http;
@@ -710,6 +743,8 @@ declare class CustomersResource {
710
743
  /**
711
744
  * Valida um CPF/CNPJ e, para CNPJ, retorna razão social, nome fantasia e endereço da
712
745
  * Receita Federal — use para pré-preencher o cadastro assim que o usuário digitar.
746
+ * Consulta em cascata (Minha Receita → BrasilAPI → CNPJá → CNPJ.ws → ReceitaWS); 404
747
+ * quando nenhuma base encontra o CNPJ, 502 quando todas falham.
713
748
  */
714
749
  lookupTaxId(taxId: string): Promise<TaxIdLookupResult>;
715
750
  /**
@@ -721,6 +756,18 @@ declare class CustomersResource {
721
756
  * await client.customers.create({ tax_id: "11.222.333/0001-81", email: "fin@acme.com", external_ref: "company:456" });
722
757
  * ```
723
758
  */
759
+ /**
760
+ * Busca o endereço de um CEP (ViaCEP → BrasilAPI → OpenCEP → AwesomeAPI → ApiCEP, em
761
+ * cascata). 404 quando nenhuma base conhece o CEP, 502 quando todas falham.
762
+ */
763
+ lookupCep(cep: string): Promise<CepLookupResult>;
764
+ /**
765
+ * Ressincroniza razão social, nome fantasia e endereço de um cliente empresa com o
766
+ * registro atual da Receita Federal — único jeito de alterar esses campos.
767
+ */
768
+ refreshRegistry(id: string): Promise<Customer & {
769
+ registry_source: string;
770
+ }>;
724
771
  create(input: CustomerInput): Promise<Customer>;
725
772
  get(id: string): Promise<Customer>;
726
773
  /** Atualiza dados de cobrança do cliente (nome, e-mail, endereço, CPF/CNPJ, razão social...). */
@@ -1189,4 +1236,4 @@ type ExpirationUnit = "seconds" | "minutes" | "hours" | "days";
1189
1236
  */
1190
1237
  declare function expiresIn(value: number, unit: ExpirationUnit): number;
1191
1238
 
1192
- export { type AppliedDiscount, BillingApiError, BillingClient, type BillingClientOptions, type BillingItem, type BillingPeriod, type BillingPlanSummary, type BillingPluginOptions, type BillingRecurringInterval, type BillingRecurringStatus, type BillingSubscriptionCancelReason, type CancelSubscriptionInput, type CancellationPolicy, type Charge, type ChargeEventData, type ChargeStatus, ChargesResource, type CheckoutForCustomerInput, type CheckoutForCustomerResult, CheckoutResource, type CheckoutSessionStatus, type CheckoutStatusResult, type CompanyTaxIdData, type Coupon, type CouponDuration, type CouponType, CouponsResource, type CreateBillingPlanInput, type CreateChargeInput, type CreateChargeResult, type CreateCouponInput, type CreateOrderInput, type CreateOrderResult, type CreateSubscriptionInput, type CreateSubscriptionResult, type Customer, type CustomerInput, type CustomerListFilters, type CustomerType, type CustomerUpdateInput, CustomersResource, type ExpirationUnit, type GetPublicPlanPageResult, HttpClient, type HttpClientOptions, type ItemInput, ItemsResource, type ListPublicPlansResult, OrdersResource, type OutboundWebhookEventType, type PaymentMethod, type PaymentMethodSetupIntent, type PaymentMethodSummary, type PlanCheckoutCustomerInput, type PlanCheckoutInput, type PlanCheckoutResult, type PlanSubscriptionStatusResult, PlansResource, type ProrationPolicy, type PublicBillingPlan, type PublicOrganization, type PublicPlanBranding, type QuickChargeInput, type QuickChargeResult, type ServiceAccountOptions, ServiceAccountTokenProvider, type Subscription, type SubscriptionItemSummary, type SubscriptionPlanSummary, type SubscriptionStatusResult, SubscriptionsResource, type SwapMode, type SwapPlanInput, type SwapPlanPreviewResult, type SwapPlanResult, type SwapPolicy, type TaxIdLookupResult, type TokenResolver, type WaitUntilPaidOptions, type WebhookEndpointInput, type WebhookEndpointSummary, type WebhookEvent, WebhooksResource, _default as billingPlugin, createServiceAccountToken, expiresIn };
1239
+ export { type AppliedDiscount, BillingApiError, BillingClient, type BillingClientOptions, type BillingItem, type BillingPeriod, type BillingPlanSummary, type BillingPluginOptions, type BillingRecurringInterval, type BillingRecurringStatus, type BillingSubscriptionCancelReason, type CancelSubscriptionInput, type CancellationPolicy, type CepLookupResult, type Charge, type ChargeEventData, type ChargeStatus, ChargesResource, type CheckoutForCustomerInput, type CheckoutForCustomerResult, CheckoutResource, type CheckoutSessionStatus, type CheckoutStatusResult, type CompanyTaxIdData, type Coupon, type CouponDuration, type CouponType, CouponsResource, type CreateBillingPlanInput, type CreateChargeInput, type CreateChargeResult, type CreateCouponInput, type CreateOrderInput, type CreateOrderResult, type CreateSubscriptionInput, type CreateSubscriptionResult, type Customer, type CustomerInput, type CustomerListFilters, type CustomerType, type CustomerUpdateInput, CustomersResource, type ExpirationUnit, type GetPublicPlanPageResult, HttpClient, type HttpClientOptions, type ItemInput, ItemsResource, type ListPublicPlansResult, OrdersResource, type OutboundWebhookEventType, type PaymentMethod, type PaymentMethodSetupIntent, type PaymentMethodSummary, type PlanCheckoutCustomerInput, type PlanCheckoutInput, type PlanCheckoutResult, type PlanSubscriptionStatusResult, PlansResource, type ProrationPolicy, type PublicBillingPlan, type PublicOrganization, type PublicPlanBranding, type QuickChargeInput, type QuickChargeResult, type ServiceAccountOptions, ServiceAccountTokenProvider, type Subscription, type SubscriptionItemSummary, type SubscriptionPlanSummary, type SubscriptionStatusResult, SubscriptionsResource, type SwapMode, type SwapPlanInput, type SwapPlanPreviewResult, type SwapPlanResult, type SwapPolicy, type TaxIdLookupResult, type TokenResolver, type WaitUntilPaidOptions, type WebhookEndpointInput, type WebhookEndpointSummary, type WebhookEvent, WebhooksResource, _default as billingPlugin, createServiceAccountToken, expiresIn };
package/dist/index.js CHANGED
@@ -355,6 +355,8 @@ var CustomersResource = class {
355
355
  /**
356
356
  * Valida um CPF/CNPJ e, para CNPJ, retorna razão social, nome fantasia e endereço da
357
357
  * Receita Federal — use para pré-preencher o cadastro assim que o usuário digitar.
358
+ * Consulta em cascata (Minha Receita → BrasilAPI → CNPJá → CNPJ.ws → ReceitaWS); 404
359
+ * quando nenhuma base encontra o CNPJ, 502 quando todas falham.
358
360
  */
359
361
  lookupTaxId(taxId) {
360
362
  return this.http.get(`/customers/tax-id-lookup/${encodeURIComponent(taxId.replace(/\D/g, ""))}`);
@@ -368,6 +370,20 @@ var CustomersResource = class {
368
370
  * await client.customers.create({ tax_id: "11.222.333/0001-81", email: "fin@acme.com", external_ref: "company:456" });
369
371
  * ```
370
372
  */
373
+ /**
374
+ * Busca o endereço de um CEP (ViaCEP → BrasilAPI → OpenCEP → AwesomeAPI → ApiCEP, em
375
+ * cascata). 404 quando nenhuma base conhece o CEP, 502 quando todas falham.
376
+ */
377
+ lookupCep(cep) {
378
+ return this.http.get(`/customers/cep-lookup/${encodeURIComponent(cep.replace(/\D/g, ""))}`);
379
+ }
380
+ /**
381
+ * Ressincroniza razão social, nome fantasia e endereço de um cliente empresa com o
382
+ * registro atual da Receita Federal — único jeito de alterar esses campos.
383
+ */
384
+ refreshRegistry(id) {
385
+ return this.http.post(`/customers/${id}/refresh-registry`);
386
+ }
371
387
  create(input) {
372
388
  return this.http.post("/customers", input);
373
389
  }
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../node_modules/.bun/fastify-plugin@6.0.0/node_modules/fastify-plugin/lib/getPluginName.js","../../../node_modules/.bun/fastify-plugin@6.0.0/node_modules/fastify-plugin/lib/toCamelCase.js","../../../node_modules/.bun/fastify-plugin@6.0.0/node_modules/fastify-plugin/index.js","../src/errors.ts","../src/http.ts","../src/resources/charges.ts","../src/resources/checkout.ts","../src/resources/coupons.ts","../src/resources/customers.ts","../src/resources/items.ts","../src/resources/orders.ts","../src/resources/plans.ts","../src/resources/subscriptions.ts","../src/resources/webhooks.ts","../src/client.ts","../src/plugin.ts","../src/service-account.ts","../src/expiration.ts"],"sourcesContent":["'use strict'\n\nconst fpStackTracePattern = /at\\s(?:.*\\.)?plugin\\s.*\\n\\s*(.*)/\nconst fileNamePattern = /(\\w*(\\.\\w*)*)\\..*/\n\nmodule.exports = function getPluginName (fn) {\n if (fn.name.length > 0) return fn.name\n\n const stackTraceLimit = Error.stackTraceLimit\n Error.stackTraceLimit = 10\n try {\n throw new Error('anonymous function')\n } catch (e) {\n Error.stackTraceLimit = stackTraceLimit\n return extractPluginName(e.stack)\n }\n}\n\nfunction extractPluginName (stack) {\n const m = stack.match(fpStackTracePattern)\n\n // get last section of path and match for filename\n return m ? m[1].split(/[/\\\\]/).slice(-1)[0].match(fileNamePattern)[1] : 'anonymous'\n}\nmodule.exports.extractPluginName = extractPluginName\n","'use strict'\n\nmodule.exports = function toCamelCase (name) {\n if (name[0] === '@') {\n name = name.slice(1).replace('/', '-')\n }\n return name.replace(/-(.)/g, function (match, g1) {\n return g1.toUpperCase()\n })\n}\n","'use strict'\n\nconst getPluginName = require('./lib/getPluginName')\nconst toCamelCase = require('./lib/toCamelCase')\n\nlet count = 0\n\nfunction plugin (fn, options = {}) {\n let autoName = false\n\n if (fn.default !== undefined) {\n // Support for 'export default' behaviour in transpiled ECMAScript module\n fn = fn.default\n }\n\n if (typeof fn !== 'function') {\n throw new TypeError(\n `fastify-plugin expects a function, instead got a '${typeof fn}'`\n )\n }\n\n if (typeof options === 'string') {\n options = {\n fastify: options\n }\n }\n\n if (\n typeof options !== 'object' ||\n Array.isArray(options) ||\n options === null\n ) {\n throw new TypeError('The options object should be an object')\n }\n\n if (options.fastify !== undefined && typeof options.fastify !== 'string') {\n throw new TypeError(`fastify-plugin expects a version string, instead got '${typeof options.fastify}'`)\n }\n\n if (!options.name) {\n autoName = true\n options.name = getPluginName(fn) + '-auto-' + count++\n }\n\n fn[Symbol.for('skip-override')] = options.encapsulate !== true\n fn[Symbol.for('fastify.display-name')] = options.name\n fn[Symbol.for('plugin-meta')] = options\n\n // Faux modules support\n if (!fn.default) {\n fn.default = fn\n }\n\n // TypeScript support for named imports\n // See https://github.com/fastify/fastify/issues/2404 for more details\n // The type definitions would have to be update to match this.\n const camelCase = toCamelCase(options.name)\n if (!autoName && !fn[camelCase]) {\n fn[camelCase] = fn\n }\n\n return fn\n}\n\nmodule.exports = plugin\nmodule.exports.default = plugin\nmodule.exports.fastifyPlugin = plugin\n","export class BillingApiError extends Error {\n constructor(\n public readonly status: number,\n message: string,\n public readonly detail?: string,\n ) {\n super(detail ? `${message}: ${detail}` : message);\n this.name = \"BillingApiError\";\n }\n\n get isNotFound() {\n return this.status === 404;\n }\n\n get isUnauthorized() {\n return this.status === 401;\n }\n\n get isForbidden() {\n return this.status === 403;\n }\n\n get isRateLimited() {\n return this.status === 429;\n }\n\n get isValidationError() {\n return this.status === 400 || this.status === 422;\n }\n}\n","import { BillingApiError } from \"./errors.js\";\n\nexport type TokenResolver = string | (() => string | Promise<string>);\n\nexport interface HttpClientOptions {\n baseUrl: string;\n token: TokenResolver;\n organizationId?: string | (() => string | Promise<string>);\n /**\n * Ambiente de billing (dev/prod) — enviado via header x-billing-mode em toda chamada\n * feita por esta instância. Defina uma vez aqui; os métodos individuais (charges.create,\n * customers.list, etc) nunca precisam recebê-lo de novo. Default: \"prod\".\n */\n mode?: string | (() => string | Promise<string>);\n}\n\nconst DEFAULT_MODE = \"prod\";\n\nexport class HttpClient {\n private readonly baseUrl: string;\n private readonly token: TokenResolver;\n private readonly organizationId?: string | (() => string | Promise<string>);\n private readonly mode: string | (() => string | Promise<string>);\n\n constructor(options: HttpClientOptions) {\n this.baseUrl = options.baseUrl.replace(/\\/$/, \"\");\n this.token = options.token;\n this.organizationId = options.organizationId;\n this.mode = options.mode ?? DEFAULT_MODE;\n }\n\n private async resolveToken(): Promise<string> {\n return typeof this.token === \"function\" ? await this.token() : this.token;\n }\n\n private async resolveOrgId(): Promise<string | undefined> {\n if (!this.organizationId) return undefined;\n return typeof this.organizationId === \"function\"\n ? await this.organizationId()\n : this.organizationId;\n }\n\n private async resolveMode(): Promise<string> {\n return typeof this.mode === \"function\" ? await this.mode() : this.mode;\n }\n\n async request<T = unknown>(\n method: string,\n path: string,\n body?: unknown,\n ): Promise<T> {\n const token = await this.resolveToken();\n const orgId = await this.resolveOrgId();\n const mode = await this.resolveMode();\n\n const res = await fetch(`${this.baseUrl}${path}`, {\n method,\n headers: {\n Authorization: `Bearer ${token}`,\n ...(body !== undefined ? { \"Content-Type\": \"application/json\" } : {}),\n ...(orgId ? { \"x-org-id\": orgId } : {}),\n \"x-billing-mode\": mode,\n },\n ...(body !== undefined ? { body: JSON.stringify(body) } : {}),\n });\n\n if (!res.ok) {\n const err = await res.json().catch(() => ({})) as {\n error?: string;\n message?: string;\n };\n throw new BillingApiError(\n res.status,\n err.error ?? err.message ?? `HTTP ${res.status}`,\n );\n }\n\n if (res.status === 202 || res.status === 204) {\n if (res.status === 204) return undefined as T;\n return res.json().catch(() => undefined) as Promise<T>;\n }\n return res.json() as Promise<T>;\n }\n\n get<T>(path: string) {\n return this.request<T>(\"GET\", path);\n }\n\n post<T>(path: string, body?: unknown) {\n return this.request<T>(\"POST\", path, body);\n }\n\n put<T>(path: string, body?: unknown) {\n return this.request<T>(\"PUT\", path, body);\n }\n\n patch<T>(path: string, body?: unknown) {\n return this.request<T>(\"PATCH\", path, body);\n }\n\n delete<T = void>(path: string) {\n return this.request<T>(\"DELETE\", path);\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type { Charge, CreateChargeInput, CreateChargeResult, QuickChargeInput, QuickChargeResult } from \"../types.js\";\n\nexport class ChargesResource {\n constructor(private readonly http: HttpClient) {}\n\n list(params?: { installment_group_id?: string }): Promise<Charge[]> {\n const qs = params?.installment_group_id\n ? `?installment_group_id=${encodeURIComponent(params.installment_group_id)}`\n : \"\";\n return this.http.get<Charge[]>(`/charges${qs}`);\n }\n\n /**\n * Cria uma cobrança (PIX, boleto ou cartão). A geração de fato acontece de forma\n * assíncrona no backend — a resposta volta com a charge em PENDING, sem os campos\n * do método (QR code, boleto, etc) ainda preenchidos. Use `get`/`getStatus` para\n * acompanhar até que estejam prontos.\n */\n create(input: CreateChargeInput): Promise<CreateChargeResult> {\n return this.http.post<CreateChargeResult>(\"/charges\", input);\n }\n\n /**\n * Cobrança avulsa simples, sempre em cartão — cobra direto no cartão padrão já\n * salvo do cliente (sem fricção nenhuma). Se ele ainda não tiver um cartão salvo,\n * retorna `checkout_url` para você abrir (ex: nova aba) e o cliente cadastrar o\n * cartão e pagar.\n *\n * ```ts\n * const result = await client.charges.charge(customerId, 5000); // R$ 50,00\n * if (!result.charged_off_session) {\n * window.open(result.checkout_url!, \"_blank\");\n * }\n * ```\n */\n charge(customerId: string, amountCents: number, options?: Omit<QuickChargeInput, \"customer_id\" | \"amount\">): Promise<QuickChargeResult> {\n return this.http.post<QuickChargeResult>(\"/charges/quick\", {\n customer_id: customerId,\n amount: amountCents,\n ...options,\n });\n }\n\n get(id: string): Promise<Charge> {\n return this.http.get<Charge>(`/charges/${id}`);\n }\n\n getStatus(id: string): Promise<{ status: Charge[\"status\"] }> {\n return this.http.get(`/charges/${id}/status`);\n }\n\n cancel(id: string): Promise<Charge> {\n return this.http.patch<Charge>(`/charges/${id}/cancel`);\n }\n\n refund(id: string): Promise<Charge> {\n return this.http.post<Charge>(`/charges/${id}/refund`);\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type { CheckoutStatusResult } from \"../types.js\";\n\nexport interface WaitUntilPaidOptions {\n /** Intervalo entre tentativas, em ms. Default: 2000. */\n intervalMs?: number;\n /** Tempo máximo de espera antes de desistir, em ms. Default: 5 minutos. */\n timeoutMs?: number;\n}\n\nexport class CheckoutResource {\n constructor(private readonly http: HttpClient) {}\n\n /** Consulta o status atual de uma cobrança/checkout pelo `checkout_token` retornado\n * por `plans.checkout()` (ou qualquer outro fluxo de cobrança do SDK). Sincroniza com\n * o provedor de pagamento sob o capô quando ainda está PENDING. */\n getStatus(checkoutToken: string): Promise<CheckoutStatusResult> {\n return this.http.get<CheckoutStatusResult>(`/checkout/${checkoutToken}/status`);\n }\n\n /**\n * Faz polling de `getStatus` até o pagamento ser confirmado (ou falhar/expirar) — é\n * a forma recomendada de confirmar, depois de redirecionar o cliente para a\n * `checkout_url`, que a assinatura realmente foi paga antes de liberar acesso.\n *\n * Resolve quando o status deixa de ser PENDING/PROCESSING. Lança um erro se o tempo\n * limite (`timeoutMs`) for atingido antes disso.\n */\n async waitUntilPaid(checkoutToken: string, options: WaitUntilPaidOptions = {}): Promise<CheckoutStatusResult> {\n const intervalMs = options.intervalMs ?? 2000;\n const timeoutMs = options.timeoutMs ?? 5 * 60 * 1000;\n const deadline = Date.now() + timeoutMs;\n\n for (;;) {\n const result = await this.getStatus(checkoutToken);\n if (result.status !== \"PENDING\" && result.status !== \"PROCESSING\") {\n return result;\n }\n if (Date.now() >= deadline) {\n throw new Error(`Tempo limite excedido aguardando confirmação de pagamento (checkout_token=${checkoutToken}).`);\n }\n await new Promise((resolve) => setTimeout(resolve, intervalMs));\n }\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type { Coupon, CreateCouponInput } from \"../types.js\";\n\nexport class CouponsResource {\n constructor(private readonly http: HttpClient) {}\n\n list(): Promise<Coupon[]> {\n return this.http.get<Coupon[]>(\"/coupons\");\n }\n\n /** `idOrCode` aceita tanto o id interno (`coupon.id`) quanto o `code` legível que você\n * escolheu na criação (ex: `\"BEMVINDO20\"`) — normalmente é mais prático guardar/usar o\n * `code`, já que é você quem o define e é o que aparece para o cliente final. */\n get(idOrCode: string): Promise<Coupon> {\n return this.http.get<Coupon>(`/coupons/${idOrCode}`);\n }\n\n /**\n * Cria um cupom de desconto — o `code` é o que o cliente final informa no checkout\n * (`plans.checkout(planId, { coupon_code })`).\n *\n * ```ts\n * // 20% de desconto, aplicado só na primeira cobrança\n * await client.coupons.create({ code: \"BEMVINDO20\", type: \"PERCENTAGE\", value: 20, duration: \"ONCE\" });\n *\n * // R$10 de desconto, repetido pelas 3 primeiras renovações\n * await client.coupons.create({\n * code: \"R10X3\", type: \"FIXED\", value: 1000, duration: \"REPEATING\", duration_months: 3,\n * });\n * ```\n */\n create(input: CreateCouponInput): Promise<Coupon> {\n return this.http.post<Coupon>(\"/coupons\", input);\n }\n\n /** Só permite editar limites/validade/ativação — o desconto em si (type/value/duration)\n * de um cupom já criado é imutável; crie um novo código para mudar o valor do desconto.\n * `idOrCode` aceita id interno ou `code` (ver `get`). */\n update(idOrCode: string, input: Partial<Pick<CreateCouponInput, \"max_redemptions\" | \"expires_at\">> & { active?: boolean }): Promise<Coupon> {\n return this.http.patch<Coupon>(`/coupons/${idOrCode}`, input);\n }\n\n /** Desativa o cupom (soft-delete) — códigos já resgatados continuam no histórico.\n * `idOrCode` aceita id interno ou `code` (ver `get`). */\n remove(idOrCode: string): Promise<void> {\n return this.http.delete<void>(`/coupons/${idOrCode}`);\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type {\n Customer,\n CustomerInput,\n CustomerListFilters,\n CustomerUpdateInput,\n PaymentMethodSetupIntent,\n PaymentMethodSummary,\n TaxIdLookupResult,\n} from \"../types.js\";\n\nexport class CustomersResource {\n constructor(private readonly http: HttpClient) {}\n\n /** Lista clientes — opcionalmente filtrando por `external_ref`, `tax_id` ou `customer_type`. */\n list(filters: CustomerListFilters = {}): Promise<Customer[]> {\n const qs = new URLSearchParams(Object.entries(filters).filter(([, v]) => v) as [string, string][]).toString();\n return this.http.get<Customer[]>(qs ? `/customers?${qs}` : \"/customers\");\n }\n\n /**\n * Busca o cliente de cobrança pela referência do seu app (ex: `\"company:456\"`). Use ao\n * trocar de conta (pessoal ↔ empresa) para operar nos cartões da conta ativa.\n */\n async findByExternalRef(externalRef: string): Promise<Customer | null> {\n const [c] = await this.list({ external_ref: externalRef });\n return c ?? null;\n }\n\n /**\n * Valida um CPF/CNPJ e, para CNPJ, retorna razão social, nome fantasia e endereço da\n * Receita Federal — use para pré-preencher o cadastro assim que o usuário digitar.\n */\n lookupTaxId(taxId: string): Promise<TaxIdLookupResult> {\n return this.http.get<TaxIdLookupResult>(`/customers/tax-id-lookup/${encodeURIComponent(taxId.replace(/\\D/g, \"\"))}`);\n }\n\n /**\n * Cria um cliente pessoa física (CPF) ou empresa (CNPJ). Para CNPJ, os campos não\n * informados (razão social, endereço...) são completados com os dados da Receita.\n * Cada cliente tem seus próprios cartões — cadastre a empresa como cliente separado.\n *\n * ```ts\n * await client.customers.create({ tax_id: \"11.222.333/0001-81\", email: \"fin@acme.com\", external_ref: \"company:456\" });\n * ```\n */\n create(input: CustomerInput): Promise<Customer> {\n return this.http.post<Customer>(\"/customers\", input);\n }\n\n get(id: string): Promise<Customer> {\n return this.http.get<Customer>(`/customers/${id}`);\n }\n\n /** Atualiza dados de cobrança do cliente (nome, e-mail, endereço, CPF/CNPJ, razão social...). */\n update(id: string, input: CustomerUpdateInput): Promise<Customer> {\n return this.http.patch<Customer>(`/customers/${id}`, input);\n }\n\n /**\n * Lista os métodos de pagamento salvos do cliente — nunca expõe o número completo do\n * cartão, só os 4 últimos dígitos, bandeira e validade.\n */\n listPaymentMethods(id: string): Promise<PaymentMethodSummary[]> {\n return this.http.get<PaymentMethodSummary[]>(`/customers/${id}/payment-methods`);\n }\n\n /**\n * Cria um SetupIntent para o cliente cadastrar um novo cartão — use o `clientSecret`\n * retornado com Stripe.js/Elements no frontend do seu app para coletar e confirmar o\n * cartão; seu backend nunca vê o número do cartão.\n *\n * ```ts\n * const { clientSecret } = await client.customers.createPaymentMethodSetupIntent(customerId);\n * // no frontend: stripe.confirmCardSetup(clientSecret, { payment_method: {...} })\n * ```\n */\n createPaymentMethodSetupIntent(id: string): Promise<PaymentMethodSetupIntent> {\n return this.http.post<PaymentMethodSetupIntent>(`/customers/${id}/payment-methods/setup-intent`);\n }\n\n /** Define um método de pagamento salvo como o padrão do cliente (usado em cobranças off-session). */\n setDefaultPaymentMethod(id: string, paymentMethodId: string): Promise<void> {\n return this.http.patch<void>(`/customers/${id}/payment-methods/${paymentMethodId}/default`);\n }\n\n /** Remove um método de pagamento salvo do cliente. */\n deletePaymentMethod(id: string, paymentMethodId: string): Promise<void> {\n return this.http.delete<void>(`/customers/${id}/payment-methods/${paymentMethodId}`);\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type { BillingItem } from \"../types.js\";\n\nexport interface ItemInput {\n name: string;\n description?: string;\n amount: number;\n currency?: string;\n}\n\nexport class ItemsResource {\n constructor(private readonly http: HttpClient) {}\n\n list(): Promise<BillingItem[]> {\n return this.http.get<BillingItem[]>(\"/items\");\n }\n\n create(input: ItemInput): Promise<BillingItem> {\n return this.http.post<BillingItem>(\"/items\", input);\n }\n\n get(id: string): Promise<BillingItem> {\n return this.http.get<BillingItem>(`/items/${id}`);\n }\n\n update(id: string, input: Partial<ItemInput>): Promise<BillingItem> {\n return this.http.patch<BillingItem>(`/items/${id}`, input);\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type { CreateOrderInput, CreateOrderResult } from \"../types.js\";\n\nexport class OrdersResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Cria um pedido parcelado (parcelamento real via cobranças avulsas agendadas,\n * não assinatura). Retorna o `client_secret` da 1ª parcela para o front-end\n * confirmar via Stripe Elements — as parcelas seguintes são cobradas\n * automaticamente pelo backend no cartão salvo.\n */\n create(input: CreateOrderInput): Promise<CreateOrderResult> {\n return this.http.post<CreateOrderResult>(\"/orders\", input);\n }\n\n list(): Promise<unknown[]> {\n return this.http.get(\"/orders\");\n }\n\n get(id: string): Promise<unknown> {\n return this.http.get(`/orders/${id}`);\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type {\n BillingPlanSummary,\n CheckoutForCustomerInput,\n CheckoutForCustomerResult,\n CreateBillingPlanInput,\n GetPublicPlanPageResult,\n ListPublicPlansResult,\n PlanCheckoutInput,\n PlanCheckoutResult,\n PlanSubscriptionStatusResult,\n} from \"../types.js\";\n\nexport class PlansResource {\n constructor(private readonly http: HttpClient) {}\n\n list(): Promise<BillingPlanSummary[]> {\n return this.http.get<BillingPlanSummary[]>(\"/billing-plans\");\n }\n\n get(id: string): Promise<BillingPlanSummary> {\n return this.http.get<BillingPlanSummary>(`/billing-plans/${id}`);\n }\n\n create(input: CreateBillingPlanInput): Promise<BillingPlanSummary> {\n return this.http.post<BillingPlanSummary>(\"/billing-plans\", input);\n }\n\n update(id: string, input: Partial<CreateBillingPlanInput> & { active?: boolean }): Promise<BillingPlanSummary> {\n return this.http.patch<BillingPlanSummary>(`/billing-plans/${id}`, input);\n }\n\n /** Não há hard-delete de planos (assinaturas existentes ainda referenciam) — para\n * remover um plano do catálogo público, arquive-o. */\n archive(id: string): Promise<BillingPlanSummary> {\n return this.http.patch<BillingPlanSummary>(`/billing-plans/${id}`, { active: false });\n }\n\n /** Vincula um plano avulso a uma página de planos existente (mesma org). */\n attachToPage(planId: string, pageId: string): Promise<BillingPlanSummary> {\n return this.http.patch<BillingPlanSummary>(`/billing-plans/${planId}`, { plan_page_id: pageId });\n }\n\n /** Desvincula um plano da sua página, tornando-o avulso (sem página pública). */\n detachFromPage(planId: string): Promise<BillingPlanSummary> {\n return this.http.patch<BillingPlanSummary>(`/billing-plans/${planId}`, { plan_page_id: null });\n }\n\n /**\n * Fluxo simplificado de assinatura para um `Customer` já cadastrado na sua org\n * (autenticado, sem formulário de nome/e-mail): cria a assinatura + cobrança inicial e\n * retorna a URL de checkout hospedada.\n *\n * ```ts\n * const { checkout_url } = await client.plans.checkoutPlan(planId, customerId, {\n * return_url: \"https://meuapp.com/conta?upgraded=1\",\n * });\n * // redirecione o cliente para checkout_url; ele paga e volta para sua URL de retorno\n *\n * // depois que o cliente volta:\n * const { active, item } = await client.plans.confirmPlanSubscription(planId, customerId);\n * if (active) {\n * // ativa o plano real no seu sistema\n * }\n * ```\n */\n checkoutPlan(planId: string, customerId: string, input?: CheckoutForCustomerInput): Promise<CheckoutForCustomerResult> {\n return this.http.post<CheckoutForCustomerResult>(`/billing-plans/${planId}/checkout-for-customer`, {\n customer_id: customerId,\n ...(input?.return_url ? { return_url: input.return_url } : {}),\n ...(input?.expires_in ? { expires_in: input.expires_in } : {}),\n ...(input?.coupon_code ? { coupon_code: input.coupon_code } : {}),\n });\n }\n\n /** Verifica se um `Customer` tem uma assinatura ativa deste plano (a mais recente),\n * contraparte de `checkoutPlan` no fluxo simplificado autenticado. */\n confirmPlanSubscription(planId: string, customerId: string): Promise<PlanSubscriptionStatusResult> {\n return this.http.get<PlanSubscriptionStatusResult>(`/billing-plans/${planId}/subscription-status?customer_id=${encodeURIComponent(customerId)}`);\n }\n\n // ─── Rotas públicas (sem auth — usadas para montar sua própria página de preços) ──\n\n /** Lista os planos ativos de uma org pelo slug público — página fixa legada, sem\n * suporte a múltiplas páginas. Prefira `getPublicPage` para orgs com várias páginas. */\n listPublic(orgSlug: string): Promise<ListPublicPlansResult> {\n return this.http.get<ListPublicPlansResult>(`/public/orgs/${orgSlug}/billing-plans`);\n }\n\n /** Busca uma página de planos pública específica pelo slug da org + slug da página. */\n getPublicPage(orgSlug: string, pageSlug: string): Promise<GetPublicPlanPageResult> {\n return this.http.get<GetPublicPlanPageResult>(`/public/orgs/${orgSlug}/plan-pages/${pageSlug}`);\n }\n\n /**\n * Inicia a assinatura de um plano para um cliente final: cria (ou reaproveita) o\n * `Customer` pelo e-mail, cria a `Subscription` e retorna uma URL de checkout hospedada\n * pela Geekapps para o cliente confirmar o pagamento.\n *\n * Fluxo típico:\n * ```ts\n * const { checkout_url, checkout_token } = await client.plans.checkout(planId, {\n * customer: { name, email },\n * coupon_code: \"PROMO20\", // opcional — página já abre com o desconto aplicado\n * });\n * // redirecione o cliente (ou abra checkout_url em uma WebView/nova aba)\n * window.location.href = checkout_url;\n *\n * // depois do retorno, confirme se realmente foi pago:\n * const { status } = await client.checkout.waitUntilPaid(checkout_token);\n * if (status === \"PAID\") { /* liberar acesso *\\/ }\n * ```\n *\n * Não requer autenticação — pode ser chamado a partir do backend do dev sem token de\n * service account, ou do próprio SDK server-side usando qualquer token válido.\n */\n checkout(planId: string, input: PlanCheckoutInput): Promise<PlanCheckoutResult> {\n return this.http.post<PlanCheckoutResult>(`/public/billing-plans/${planId}/checkout`, input);\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type {\n CancelSubscriptionInput,\n CreateSubscriptionInput,\n CreateSubscriptionResult,\n Subscription,\n SubscriptionStatusResult,\n SwapPlanInput,\n SwapPlanPreviewResult,\n SwapPlanResult,\n} from \"../types.js\";\n\nexport class SubscriptionsResource {\n constructor(private readonly http: HttpClient) {}\n\n /** Requer autenticação (service account) — lista todas as assinaturas da sua org. */\n list(): Promise<Subscription[]> {\n return this.http.get<Subscription[]>(\"/billing-subscriptions\");\n }\n\n /**\n * Fluxo legado de assinatura por `BillingItem` avulso (sem `BillingPlan`) — requer\n * autenticação (service account) e que `customer_id`/`item_id` já existam na sua org.\n * Prefira `plans.checkout`/`plans.checkoutPlan` para novos catálogos baseados em plano.\n *\n * ```ts\n * await client.subscriptions.create({\n * customer_id, item_id, interval: \"MONTHLY\", coupon_code: \"PROMO20\",\n * });\n * ```\n */\n create(input: CreateSubscriptionInput): Promise<CreateSubscriptionResult> {\n return this.http.post<CreateSubscriptionResult>(\"/billing-subscriptions\", input);\n }\n\n /** Requer autenticação (service account). */\n get(id: string): Promise<Subscription> {\n return this.http.get<Subscription>(`/billing-subscriptions/${id}`);\n }\n\n /**\n * Cancela uma assinatura — requer autenticação (service account). Cancela no provedor\n * (Stripe) quando aplicável, marca cobranças pendentes como CANCELLED, e notifica o\n * cliente. `policy` decide o que acontece com o valor já pago do período vigente:\n * `IMMEDIATE_NO_REFUND` (cancela agora, sem reembolso), `IMMEDIATE_PRORATED_REFUND`\n * (cancela agora, reembolsa a parte não usada), `IMMEDIATE_FIXED_REFUND` (cancela agora,\n * reembolsa um valor definido manualmente — exige `fixedRefundAmount`), ou\n * `END_OF_PERIOD` (continua ativa até o fim do período atual, sem reembolso).\n *\n * ```ts\n * await client.subscriptions.cancel(subId, { policy: \"END_OF_PERIOD\" });\n * ```\n */\n cancel(id: string, input: CancelSubscriptionInput): Promise<Subscription> {\n return this.http.patch<Subscription>(`/billing-subscriptions/${id}/cancel`, {\n policy: input.policy,\n ...(input.fixedRefundAmount !== undefined ? { fixed_refund_amount: input.fixedRefundAmount } : {}),\n });\n }\n\n /**\n * Reverte um cancelamento agendado (cancel_at_period_end) — requer autenticação\n * (service account). Só se aplica enquanto a assinatura ainda está ACTIVE com o\n * cancelamento agendado pro fim do período vigente (ver SUBSCRIPTION_CANCEL_SCHEDULE);\n * uma vez CANCELLED de fato, a Subscription já foi encerrada no Stripe e não há o que\n * reverter — chame `cancel`/checkout novamente para recomeçar.\n */\n resume(id: string): Promise<Subscription> {\n return this.http.patch<Subscription>(`/billing-subscriptions/${id}/resume`);\n }\n\n /**\n * Calcula o preview de uma troca de plano (não muta nada) — requer autenticação\n * (service account). Use para mostrar ao dono da org o valor devido/estimado antes de\n * confirmar com `swapPlan`.\n *\n * ```ts\n * const preview = await client.subscriptions.previewPlanSwap(subId, {\n * newPlanId, policy: \"AT_RENEWAL\",\n * });\n * ```\n */\n previewPlanSwap(id: string, input: SwapPlanInput): Promise<SwapPlanPreviewResult> {\n const params = new URLSearchParams({ new_plan_id: input.newPlanId, policy: input.policy });\n if (input.manualAmount !== undefined) params.set(\"manual_amount\", String(input.manualAmount));\n if (input.couponCode) params.set(\"coupon_code\", input.couponCode);\n return this.http.get<SwapPlanPreviewResult>(`/billing-subscriptions/${id}/swap-preview?${params.toString()}`);\n }\n\n /**\n * Executa a troca de plano/item de uma assinatura já existente (upgrade/downgrade de\n * tier) — requer autenticação (service account). Executa a troca diretamente, sem\n * confirmação posterior do cliente final; o dono do org escolhe `policy` (cobrar/estornar\n * agora, aplicar só na próxima renovação, ou valor definido manualmente) antes de chamar.\n *\n * `manualAmount`: obrigatório quando `policy` é `\"FIXED_AMOUNT\"` — valor de ajuste assinado\n * (cents), positivo cobra o cliente, negativo estorna.\n *\n * `couponCode`: aplica um cupom na troca — se a assinatura for Stripe, o desconto passa a\n * valer também nas renovações futuras (recorrente, direto na Subscription); se for\n * PIX/boleto, o desconto vale só para a cobrança de proration desta troca.\n *\n * `autoCharge`: quando há diferença a cobrar na hora (`policy` `\"IMMEDIATE\"` ou\n * `\"FIXED_AMOUNT\"` positivo), decide se tenta cobrar o cartão salvo do cliente direto\n * (`true` — se falhar, a troca inteira é revertida e a chamada rejeita) ou se gera a\n * cobrança e devolve `checkout_url` para o cliente pagar manualmente (`false`/omitido,\n * padrão — o plano só é aplicado quando o pagamento for confirmado).\n *\n * ```ts\n * // Cobra o cartão salvo na hora — se falhar, a troca não acontece.\n * const result = await client.subscriptions.swapPlan(subId, {\n * newPlanId, policy: \"IMMEDIATE\", couponCode: \"PROMO20\", autoCharge: true,\n * });\n *\n * // Ou: gera o link de pagamento, sem tentar cartão salvo.\n * const result2 = await client.subscriptions.swapPlan(subId, { newPlanId, policy: \"IMMEDIATE\" });\n * if (result2.checkout_url) {\n * // redirecione o cliente final para result2.checkout_url para pagar a cobrança de ajuste\n * }\n * ```\n */\n swapPlan(id: string, input: SwapPlanInput): Promise<SwapPlanResult> {\n return this.http.patch<SwapPlanResult>(`/billing-subscriptions/${id}/swap`, {\n new_plan_id: input.newPlanId,\n policy: input.policy,\n ...(input.manualAmount !== undefined ? { manual_amount: input.manualAmount } : {}),\n ...(input.expiresInSeconds ? { expires_in: input.expiresInSeconds } : {}),\n ...(input.couponCode ? { coupon_code: input.couponCode } : {}),\n ...(input.autoCharge !== undefined ? { auto_charge: input.autoCharge } : {}),\n });\n }\n\n /**\n * Cancela uma troca de plano ainda pendente (aguardando confirmação de pagamento ou\n * renovação — `policy: \"AT_RENEWAL\"` ou upgrade IMMEDIATE com proration nativa) — requer\n * autenticação (service account). Mantém a assinatura no plano atual, revertendo o price já\n * trocado no Stripe. Não se aplica a trocas com `policy: \"FIXED_AMOUNT\"` ou downgrade/estorno\n * imediato, que já aplicam o novo plano na hora — nesse caso não há o que cancelar, é preciso\n * chamar `swapPlan` de novo para trocar para outro plano.\n *\n * ```ts\n * await client.subscriptions.cancelPendingPlanSwap(subId);\n * ```\n */\n cancelPendingPlanSwap(id: string): Promise<Subscription> {\n return this.http.delete<Subscription>(`/billing-subscriptions/${id}/swap`);\n }\n\n /**\n * Verifica se uma assinatura está ativa e qual item ela cobre, usando o\n * `management_token` retornado por `plans.checkout()` — rota pública, sem\n * autenticação, segura para chamar tanto do seu backend quanto (via fetch direto,\n * sem o SDK) do client-side do seu app.\n *\n * ```ts\n * const status = await client.subscriptions.checkByToken(managementToken);\n * if (status.subscription.active) {\n * console.log(\"cobrando\", status.item.name);\n * }\n * ```\n */\n checkByToken(managementToken: string): Promise<SubscriptionStatusResult> {\n return this.http.get<SubscriptionStatusResult>(`/public/plan-management/${managementToken}`);\n }\n}\n","import type { HttpClient } from \"../http.js\";\n\nexport type OutboundWebhookEventType =\n | \"SUBSCRIPTION_CREATED\"\n | \"SUBSCRIPTION_ACTIVATED\"\n | \"SUBSCRIPTION_RENEWED\"\n | \"SUBSCRIPTION_PLAN_SWAPPED\"\n | \"SUBSCRIPTION_PAST_DUE\"\n | \"SUBSCRIPTION_CANCELLED\"\n | \"SUBSCRIPTION_CANCEL_SCHEDULE\"\n | \"SUBSCRIPTION_RESUMED\"\n | \"CHARGE_PAID\"\n | \"CHARGE_FAILED\"\n | \"CHARGE_EXPIRED\"\n | \"CHARGE_REFUNDED\";\n\n/** Payload de uma cobrança (`data`) nos eventos CHARGE_*. `description` é `null` quando\n * a cobrança não tem descrição definida. */\nexport interface ChargeEventData {\n chargeId: string;\n amountCents: number;\n description: string | null;\n}\n\n/** Union discriminada por `event_type` — use para tipar o corpo recebido na sua rota de\n * webhook (ver `X-Geekapps-Signature` para validar a assinatura antes de confiar no payload).\n *\n * ```ts\n * const event = JSON.parse(rawBody) as WebhookEvent;\n * switch (event.event_type) {\n * case \"CHARGE_PAID\":\n * // event.data: { chargeId, amountCents, description }\n * break;\n * case \"SUBSCRIPTION_CANCELLED\":\n * // event.data: { subscriptionId }\n * break;\n * }\n * ```\n */\nexport type WebhookEvent =\n | {\n event_type: \"SUBSCRIPTION_CREATED\";\n org_id: string;\n data: { subscriptionId: string; customerId: string; itemId: string; interval: string };\n }\n | {\n event_type: \"SUBSCRIPTION_ACTIVATED\";\n org_id: string;\n data: { subscriptionId: string };\n }\n | {\n /** Disparado a cada renovação paga com sucesso — em toda cobrança recorrente\n * confirmada, independente do status anterior da assinatura (distinto de\n * SUBSCRIPTION_ACTIVATED, que só marca a transição de volta pra ACTIVE). */\n event_type: \"SUBSCRIPTION_RENEWED\";\n org_id: string;\n data: { subscriptionId: string; chargeId: string | null };\n }\n | {\n event_type: \"SUBSCRIPTION_PLAN_SWAPPED\";\n org_id: string;\n data: { subscriptionId: string; oldPlanId: string; newPlanId: string; mode: string };\n }\n | {\n event_type: \"SUBSCRIPTION_PAST_DUE\";\n org_id: string;\n data: { subscriptionId: string };\n }\n | {\n event_type: \"SUBSCRIPTION_CANCELLED\";\n org_id: string;\n data: { subscriptionId: string };\n }\n | {\n /** Disparado quando um cancelamento é agendado para o fim do período vigente\n * (política END_OF_PERIOD ou cancelamento/reversão feito no Stripe Billing Portal) —\n * a assinatura continua ACTIVE até `data.effective_at`; distinto de\n * SUBSCRIPTION_CANCELLED, que marca o cancelamento definitivo. */\n event_type: \"SUBSCRIPTION_CANCEL_SCHEDULE\";\n org_id: string;\n data: { subscriptionId: string; effective_at: string | null };\n }\n | {\n /** Disparado quando um cancelamento agendado (SUBSCRIPTION_CANCEL_SCHEDULE) é\n * revertido antes do fim do período — a assinatura volta a renovar normalmente. */\n event_type: \"SUBSCRIPTION_RESUMED\";\n org_id: string;\n data: { subscriptionId: string };\n }\n | {\n event_type: \"CHARGE_PAID\";\n org_id: string;\n data: ChargeEventData;\n }\n | {\n event_type: \"CHARGE_FAILED\";\n org_id: string;\n data: ChargeEventData;\n }\n | {\n event_type: \"CHARGE_EXPIRED\";\n org_id: string;\n data: ChargeEventData;\n }\n | {\n event_type: \"CHARGE_REFUNDED\";\n org_id: string;\n data: ChargeEventData;\n };\n\nexport interface WebhookEndpointInput {\n url: string;\n eventTypes: OutboundWebhookEventType[];\n /** Opcional — quando omitido, o servidor gera um secret automaticamente. */\n secret?: string;\n}\n\nexport interface WebhookEndpointSummary {\n id: string;\n url: string;\n event_types: OutboundWebhookEventType[];\n active: boolean;\n /** Segredo completo apenas na primeira criação — em toda resposta subsequente vem mascarado. */\n secret: string;\n created_at: string;\n updated_at: string;\n}\n\nexport class WebhooksResource {\n constructor(private readonly http: HttpClient) {}\n\n /** Lista os webhooks outbound cadastrados na sua org (secret sempre mascarado). */\n list(): Promise<WebhookEndpointSummary[]> {\n return this.http.get<WebhookEndpointSummary[]>(\"/webhook-endpoints\");\n }\n\n /**\n * Registra um webhook outbound — idempotente por (org, url): chamar de novo com a\n * mesma URL apenas atualiza os `eventTypes`, sem criar duplicata. Guarde o `secret`\n * retornado (só vem completo na primeira criação) para validar a assinatura\n * `X-Geekapps-Signature` nas entregas recebidas. Passe `secret` para definir o seu\n * próprio signing secret; se omitido, um valor aleatório é gerado automaticamente.\n */\n register(input: WebhookEndpointInput): Promise<WebhookEndpointSummary> {\n return this.http.post<WebhookEndpointSummary>(\"/webhook-endpoints\", {\n url: input.url,\n event_types: input.eventTypes,\n ...(input.secret ? { secret: input.secret } : {}),\n });\n }\n\n /** Edita um webhook existente — URL, eventos assinados e/ou status ativo/inativo. */\n update(id: string, input: Partial<WebhookEndpointInput> & { active?: boolean }): Promise<WebhookEndpointSummary> {\n return this.http.patch<WebhookEndpointSummary>(`/webhook-endpoints/${id}`, {\n ...(input.url ? { url: input.url } : {}),\n ...(input.eventTypes ? { event_types: input.eventTypes } : {}),\n ...(input.active !== undefined ? { active: input.active } : {}),\n });\n }\n\n /** Gera um novo secret e substitui o atual — a versão antiga deixa de validar imediatamente. */\n rotateSecret(id: string): Promise<WebhookEndpointSummary> {\n return this.http.post<WebhookEndpointSummary>(`/webhook-endpoints/${id}/rotate-secret`);\n }\n\n remove(id: string): Promise<void> {\n return this.http.delete<void>(`/webhook-endpoints/${id}`);\n }\n}\n","import { HttpClient, type HttpClientOptions } from \"./http.js\";\nimport { ChargesResource } from \"./resources/charges.js\";\nimport { CheckoutResource } from \"./resources/checkout.js\";\nimport { CouponsResource } from \"./resources/coupons.js\";\nimport { CustomersResource } from \"./resources/customers.js\";\nimport { ItemsResource } from \"./resources/items.js\";\nimport { OrdersResource } from \"./resources/orders.js\";\nimport { PlansResource } from \"./resources/plans.js\";\nimport { SubscriptionsResource } from \"./resources/subscriptions.js\";\nimport { WebhooksResource } from \"./resources/webhooks.js\";\n\nexport interface BillingClientOptions\n extends Omit<HttpClientOptions, \"baseUrl\"> {\n baseUrl?: string;\n}\n\nexport class BillingClient {\n private readonly http: HttpClient;\n\n readonly charges: ChargesResource;\n readonly checkout: CheckoutResource;\n readonly coupons: CouponsResource;\n readonly customers: CustomersResource;\n readonly items: ItemsResource;\n readonly orders: OrdersResource;\n readonly plans: PlansResource;\n readonly subscriptions: SubscriptionsResource;\n readonly webhooks: WebhooksResource;\n\n constructor(options: HttpClientOptions) {\n this.http = new HttpClient(options);\n\n this.charges = new ChargesResource(this.http);\n this.checkout = new CheckoutResource(this.http);\n this.coupons = new CouponsResource(this.http);\n this.customers = new CustomersResource(this.http);\n this.items = new ItemsResource(this.http);\n this.orders = new OrdersResource(this.http);\n this.plans = new PlansResource(this.http);\n this.subscriptions = new SubscriptionsResource(this.http);\n this.webhooks = new WebhooksResource(this.http);\n }\n}\n","import type { FastifyInstance, FastifyPluginAsync } from \"fastify\";\nimport fp from \"fastify-plugin\";\nimport { BillingClient } from \"./client.js\";\nimport { ServiceAccountTokenProvider, type ServiceAccountOptions } from \"./service-account.js\";\n\nexport interface BillingPluginOptions {\n /** Geekapps Billing API base URL */\n baseUrl: string;\n /** Service account credentials — required */\n serviceAccount: ServiceAccountOptions;\n /** Ambiente de billing (dev/prod). Default: \"prod\". */\n mode?: string;\n}\n\ndeclare module \"fastify\" {\n interface FastifyInstance {\n billingClient: BillingClient;\n }\n}\n\nconst billingPlugin: FastifyPluginAsync<BillingPluginOptions> = async (\n fastify: FastifyInstance,\n options: BillingPluginOptions,\n) => {\n const tokenProvider = new ServiceAccountTokenProvider(options.serviceAccount);\n\n const client = new BillingClient({\n baseUrl: options.baseUrl,\n token: () => tokenProvider.getToken(),\n organizationId: () => tokenProvider.getOrganizationId() as Promise<string>,\n mode: options.mode,\n });\n\n fastify.decorate(\"billingClient\", client);\n};\n\nexport default fp(billingPlugin, {\n fastify: \">=4.0.0\",\n name: \"@geekapps/billing-fastify\",\n});\n","import type { TokenResolver } from \"./http.js\";\n\nexport interface ServiceAccountOptions {\n /** Geekapps Auth issuer base URL (e.g. https://accounts-api.geekapps.com.br) */\n issuerUrl: string;\n clientId: string;\n clientSecret: string;\n /** Seconds before expiry to proactively refresh. Defaults to 30. */\n refreshBeforeExpirySeconds?: number;\n}\n\ninterface CachedToken {\n value: string;\n expiresAt: number; // ms epoch\n organizationId: string | undefined;\n}\n\nfunction decodeJwtPayload(token: string): Record<string, unknown> {\n try {\n const [, payload] = token.split(\".\");\n if (!payload) return {};\n const json = Buffer.from(payload, \"base64url\").toString(\"utf-8\");\n return JSON.parse(json) as Record<string, unknown>;\n } catch {\n return {};\n }\n}\n\n/**\n * Fetches a short-lived token from the Geekapps Auth service using\n * client_credentials grant and caches it until near expiry.\n *\n * The organizationId claim is extracted automatically from the JWT payload.\n */\nexport class ServiceAccountTokenProvider {\n private readonly issuerUrl: string;\n private readonly clientId: string;\n private readonly clientSecret: string;\n private readonly refreshBeforeMs: number;\n private cached: CachedToken | null = null;\n private inflight: Promise<CachedToken> | null = null;\n\n constructor(options: ServiceAccountOptions) {\n this.issuerUrl = options.issuerUrl.replace(/\\/$/, \"\");\n this.clientId = options.clientId;\n this.clientSecret = options.clientSecret;\n this.refreshBeforeMs = (options.refreshBeforeExpirySeconds ?? 30) * 1000;\n }\n\n private async ensureFresh(): Promise<CachedToken> {\n const now = Date.now();\n\n if (this.cached && this.cached.expiresAt - now > this.refreshBeforeMs) {\n return this.cached;\n }\n\n if (this.inflight) return this.inflight;\n\n this.inflight = this.fetchToken().finally(() => {\n this.inflight = null;\n });\n\n return this.inflight;\n }\n\n /** Returns a valid access token. */\n getToken(): Promise<string> {\n return this.ensureFresh().then((c) => c.value);\n }\n\n /** Returns the organizationId embedded in the service account JWT. */\n getOrganizationId(): Promise<string | undefined> {\n return this.ensureFresh().then((c) => c.organizationId);\n }\n\n private async fetchToken(): Promise<CachedToken> {\n const credentials = Buffer.from(`${this.clientId}:${this.clientSecret}`).toString(\"base64\");\n\n const res = await fetch(`${this.issuerUrl}/auth/token`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Basic ${credentials}`,\n },\n body: JSON.stringify({ grant_type: \"service_account\" }),\n });\n\n if (!res.ok) {\n const err = await res.json().catch(() => ({})) as { error?: string };\n throw new Error(\n `ServiceAccount token fetch failed (${res.status}): ${err.error ?? \"unknown error\"}`,\n );\n }\n\n const data = await res.json() as { access_token: string; expires_in?: number };\n\n const claims = decodeJwtPayload(data.access_token);\n const organizationId =\n typeof claims.organizationId === \"string\" ? claims.organizationId :\n typeof claims.organization_id === \"string\" ? claims.organization_id :\n typeof claims.org_id === \"string\" ? claims.org_id :\n undefined;\n\n const expiresInMs = (data.expires_in ?? 420) * 1000;\n this.cached = {\n value: data.access_token,\n expiresAt: Date.now() + expiresInMs,\n organizationId,\n };\n\n return this.cached;\n }\n\n /** Returns this provider as a TokenResolver to pass directly to BillingClient. */\n asTokenResolver(): TokenResolver {\n return () => this.getToken();\n }\n}\n\n/** Convenience factory. Returns a TokenResolver ready for use in BillingClient. */\nexport function createServiceAccountToken(\n options: ServiceAccountOptions,\n): TokenResolver {\n return new ServiceAccountTokenProvider(options).asTokenResolver();\n}\n","export type ExpirationUnit = \"seconds\" | \"minutes\" | \"hours\" | \"days\";\n\nconst MULTIPLIERS: Record<ExpirationUnit, number> = {\n seconds: 1,\n minutes: 60,\n hours: 3600,\n days: 86400,\n};\n\n/**\n * Converte um valor + unidade para segundos, prontos para usar em `expires_in`.\n *\n * ```ts\n * await client.charges.create({ ..., expires_in: expiresIn(30, \"minutes\") });\n * ```\n */\nexport function expiresIn(value: number, unit: ExpirationUnit): number {\n return value * MULTIPLIERS[unit];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAEA,QAAM,sBAAsB;AAC5B,QAAM,kBAAkB;AAExB,WAAO,UAAU,SAAS,cAAe,IAAI;AAC3C,UAAI,GAAG,KAAK,SAAS,EAAG,QAAO,GAAG;AAElC,YAAM,kBAAkB,MAAM;AAC9B,YAAM,kBAAkB;AACxB,UAAI;AACF,cAAM,IAAI,MAAM,oBAAoB;AAAA,MACtC,SAAS,GAAG;AACV,cAAM,kBAAkB;AACxB,eAAO,kBAAkB,EAAE,KAAK;AAAA,MAClC;AAAA,IACF;AAEA,aAAS,kBAAmB,OAAO;AACjC,YAAM,IAAI,MAAM,MAAM,mBAAmB;AAGzC,aAAO,IAAI,EAAE,CAAC,EAAE,MAAM,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,eAAe,EAAE,CAAC,IAAI;AAAA,IAC1E;AACA,WAAO,QAAQ,oBAAoB;AAAA;AAAA;;;ACxBnC;AAAA;AAAA;AAEA,WAAO,UAAU,SAAS,YAAa,MAAM;AAC3C,UAAI,KAAK,CAAC,MAAM,KAAK;AACnB,eAAO,KAAK,MAAM,CAAC,EAAE,QAAQ,KAAK,GAAG;AAAA,MACvC;AACA,aAAO,KAAK,QAAQ,SAAS,SAAU,OAAO,IAAI;AAChD,eAAO,GAAG,YAAY;AAAA,MACxB,CAAC;AAAA,IACH;AAAA;AAAA;;;ACTA;AAAA;AAAA;AAEA,QAAM,gBAA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,sBAAAA,SAAG,eAAe;AAAA,EAC/B,SAAS;AAAA,EACT,MAAM;AACR,CAAC;;;AErCD,IAAM,cAA8C;AAAA,EAClD,SAAS;AAAA,EACT,SAAS;AAAA,EACT,OAAO;AAAA,EACP,MAAM;AACR;AASO,SAAS,UAAU,OAAe,MAA8B;AACrE,SAAO,QAAQ,YAAY,IAAI;AACjC;","names":["fp"]}
1
+ {"version":3,"sources":["../../../node_modules/.bun/fastify-plugin@6.0.0/node_modules/fastify-plugin/lib/getPluginName.js","../../../node_modules/.bun/fastify-plugin@6.0.0/node_modules/fastify-plugin/lib/toCamelCase.js","../../../node_modules/.bun/fastify-plugin@6.0.0/node_modules/fastify-plugin/index.js","../src/errors.ts","../src/http.ts","../src/resources/charges.ts","../src/resources/checkout.ts","../src/resources/coupons.ts","../src/resources/customers.ts","../src/resources/items.ts","../src/resources/orders.ts","../src/resources/plans.ts","../src/resources/subscriptions.ts","../src/resources/webhooks.ts","../src/client.ts","../src/plugin.ts","../src/service-account.ts","../src/expiration.ts"],"sourcesContent":["'use strict'\n\nconst fpStackTracePattern = /at\\s(?:.*\\.)?plugin\\s.*\\n\\s*(.*)/\nconst fileNamePattern = /(\\w*(\\.\\w*)*)\\..*/\n\nmodule.exports = function getPluginName (fn) {\n if (fn.name.length > 0) return fn.name\n\n const stackTraceLimit = Error.stackTraceLimit\n Error.stackTraceLimit = 10\n try {\n throw new Error('anonymous function')\n } catch (e) {\n Error.stackTraceLimit = stackTraceLimit\n return extractPluginName(e.stack)\n }\n}\n\nfunction extractPluginName (stack) {\n const m = stack.match(fpStackTracePattern)\n\n // get last section of path and match for filename\n return m ? m[1].split(/[/\\\\]/).slice(-1)[0].match(fileNamePattern)[1] : 'anonymous'\n}\nmodule.exports.extractPluginName = extractPluginName\n","'use strict'\n\nmodule.exports = function toCamelCase (name) {\n if (name[0] === '@') {\n name = name.slice(1).replace('/', '-')\n }\n return name.replace(/-(.)/g, function (match, g1) {\n return g1.toUpperCase()\n })\n}\n","'use strict'\n\nconst getPluginName = require('./lib/getPluginName')\nconst toCamelCase = require('./lib/toCamelCase')\n\nlet count = 0\n\nfunction plugin (fn, options = {}) {\n let autoName = false\n\n if (fn.default !== undefined) {\n // Support for 'export default' behaviour in transpiled ECMAScript module\n fn = fn.default\n }\n\n if (typeof fn !== 'function') {\n throw new TypeError(\n `fastify-plugin expects a function, instead got a '${typeof fn}'`\n )\n }\n\n if (typeof options === 'string') {\n options = {\n fastify: options\n }\n }\n\n if (\n typeof options !== 'object' ||\n Array.isArray(options) ||\n options === null\n ) {\n throw new TypeError('The options object should be an object')\n }\n\n if (options.fastify !== undefined && typeof options.fastify !== 'string') {\n throw new TypeError(`fastify-plugin expects a version string, instead got '${typeof options.fastify}'`)\n }\n\n if (!options.name) {\n autoName = true\n options.name = getPluginName(fn) + '-auto-' + count++\n }\n\n fn[Symbol.for('skip-override')] = options.encapsulate !== true\n fn[Symbol.for('fastify.display-name')] = options.name\n fn[Symbol.for('plugin-meta')] = options\n\n // Faux modules support\n if (!fn.default) {\n fn.default = fn\n }\n\n // TypeScript support for named imports\n // See https://github.com/fastify/fastify/issues/2404 for more details\n // The type definitions would have to be update to match this.\n const camelCase = toCamelCase(options.name)\n if (!autoName && !fn[camelCase]) {\n fn[camelCase] = fn\n }\n\n return fn\n}\n\nmodule.exports = plugin\nmodule.exports.default = plugin\nmodule.exports.fastifyPlugin = plugin\n","export class BillingApiError extends Error {\n constructor(\n public readonly status: number,\n message: string,\n public readonly detail?: string,\n ) {\n super(detail ? `${message}: ${detail}` : message);\n this.name = \"BillingApiError\";\n }\n\n get isNotFound() {\n return this.status === 404;\n }\n\n get isUnauthorized() {\n return this.status === 401;\n }\n\n get isForbidden() {\n return this.status === 403;\n }\n\n get isRateLimited() {\n return this.status === 429;\n }\n\n get isValidationError() {\n return this.status === 400 || this.status === 422;\n }\n}\n","import { BillingApiError } from \"./errors.js\";\n\nexport type TokenResolver = string | (() => string | Promise<string>);\n\nexport interface HttpClientOptions {\n baseUrl: string;\n token: TokenResolver;\n organizationId?: string | (() => string | Promise<string>);\n /**\n * Ambiente de billing (dev/prod) — enviado via header x-billing-mode em toda chamada\n * feita por esta instância. Defina uma vez aqui; os métodos individuais (charges.create,\n * customers.list, etc) nunca precisam recebê-lo de novo. Default: \"prod\".\n */\n mode?: string | (() => string | Promise<string>);\n}\n\nconst DEFAULT_MODE = \"prod\";\n\nexport class HttpClient {\n private readonly baseUrl: string;\n private readonly token: TokenResolver;\n private readonly organizationId?: string | (() => string | Promise<string>);\n private readonly mode: string | (() => string | Promise<string>);\n\n constructor(options: HttpClientOptions) {\n this.baseUrl = options.baseUrl.replace(/\\/$/, \"\");\n this.token = options.token;\n this.organizationId = options.organizationId;\n this.mode = options.mode ?? DEFAULT_MODE;\n }\n\n private async resolveToken(): Promise<string> {\n return typeof this.token === \"function\" ? await this.token() : this.token;\n }\n\n private async resolveOrgId(): Promise<string | undefined> {\n if (!this.organizationId) return undefined;\n return typeof this.organizationId === \"function\"\n ? await this.organizationId()\n : this.organizationId;\n }\n\n private async resolveMode(): Promise<string> {\n return typeof this.mode === \"function\" ? await this.mode() : this.mode;\n }\n\n async request<T = unknown>(\n method: string,\n path: string,\n body?: unknown,\n ): Promise<T> {\n const token = await this.resolveToken();\n const orgId = await this.resolveOrgId();\n const mode = await this.resolveMode();\n\n const res = await fetch(`${this.baseUrl}${path}`, {\n method,\n headers: {\n Authorization: `Bearer ${token}`,\n ...(body !== undefined ? { \"Content-Type\": \"application/json\" } : {}),\n ...(orgId ? { \"x-org-id\": orgId } : {}),\n \"x-billing-mode\": mode,\n },\n ...(body !== undefined ? { body: JSON.stringify(body) } : {}),\n });\n\n if (!res.ok) {\n const err = await res.json().catch(() => ({})) as {\n error?: string;\n message?: string;\n };\n throw new BillingApiError(\n res.status,\n err.error ?? err.message ?? `HTTP ${res.status}`,\n );\n }\n\n if (res.status === 202 || res.status === 204) {\n if (res.status === 204) return undefined as T;\n return res.json().catch(() => undefined) as Promise<T>;\n }\n return res.json() as Promise<T>;\n }\n\n get<T>(path: string) {\n return this.request<T>(\"GET\", path);\n }\n\n post<T>(path: string, body?: unknown) {\n return this.request<T>(\"POST\", path, body);\n }\n\n put<T>(path: string, body?: unknown) {\n return this.request<T>(\"PUT\", path, body);\n }\n\n patch<T>(path: string, body?: unknown) {\n return this.request<T>(\"PATCH\", path, body);\n }\n\n delete<T = void>(path: string) {\n return this.request<T>(\"DELETE\", path);\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type { Charge, CreateChargeInput, CreateChargeResult, QuickChargeInput, QuickChargeResult } from \"../types.js\";\n\nexport class ChargesResource {\n constructor(private readonly http: HttpClient) {}\n\n list(params?: { installment_group_id?: string }): Promise<Charge[]> {\n const qs = params?.installment_group_id\n ? `?installment_group_id=${encodeURIComponent(params.installment_group_id)}`\n : \"\";\n return this.http.get<Charge[]>(`/charges${qs}`);\n }\n\n /**\n * Cria uma cobrança (PIX, boleto ou cartão). A geração de fato acontece de forma\n * assíncrona no backend — a resposta volta com a charge em PENDING, sem os campos\n * do método (QR code, boleto, etc) ainda preenchidos. Use `get`/`getStatus` para\n * acompanhar até que estejam prontos.\n */\n create(input: CreateChargeInput): Promise<CreateChargeResult> {\n return this.http.post<CreateChargeResult>(\"/charges\", input);\n }\n\n /**\n * Cobrança avulsa simples, sempre em cartão — cobra direto no cartão padrão já\n * salvo do cliente (sem fricção nenhuma). Se ele ainda não tiver um cartão salvo,\n * retorna `checkout_url` para você abrir (ex: nova aba) e o cliente cadastrar o\n * cartão e pagar.\n *\n * ```ts\n * const result = await client.charges.charge(customerId, 5000); // R$ 50,00\n * if (!result.charged_off_session) {\n * window.open(result.checkout_url!, \"_blank\");\n * }\n * ```\n */\n charge(customerId: string, amountCents: number, options?: Omit<QuickChargeInput, \"customer_id\" | \"amount\">): Promise<QuickChargeResult> {\n return this.http.post<QuickChargeResult>(\"/charges/quick\", {\n customer_id: customerId,\n amount: amountCents,\n ...options,\n });\n }\n\n get(id: string): Promise<Charge> {\n return this.http.get<Charge>(`/charges/${id}`);\n }\n\n getStatus(id: string): Promise<{ status: Charge[\"status\"] }> {\n return this.http.get(`/charges/${id}/status`);\n }\n\n cancel(id: string): Promise<Charge> {\n return this.http.patch<Charge>(`/charges/${id}/cancel`);\n }\n\n refund(id: string): Promise<Charge> {\n return this.http.post<Charge>(`/charges/${id}/refund`);\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type { CheckoutStatusResult } from \"../types.js\";\n\nexport interface WaitUntilPaidOptions {\n /** Intervalo entre tentativas, em ms. Default: 2000. */\n intervalMs?: number;\n /** Tempo máximo de espera antes de desistir, em ms. Default: 5 minutos. */\n timeoutMs?: number;\n}\n\nexport class CheckoutResource {\n constructor(private readonly http: HttpClient) {}\n\n /** Consulta o status atual de uma cobrança/checkout pelo `checkout_token` retornado\n * por `plans.checkout()` (ou qualquer outro fluxo de cobrança do SDK). Sincroniza com\n * o provedor de pagamento sob o capô quando ainda está PENDING. */\n getStatus(checkoutToken: string): Promise<CheckoutStatusResult> {\n return this.http.get<CheckoutStatusResult>(`/checkout/${checkoutToken}/status`);\n }\n\n /**\n * Faz polling de `getStatus` até o pagamento ser confirmado (ou falhar/expirar) — é\n * a forma recomendada de confirmar, depois de redirecionar o cliente para a\n * `checkout_url`, que a assinatura realmente foi paga antes de liberar acesso.\n *\n * Resolve quando o status deixa de ser PENDING/PROCESSING. Lança um erro se o tempo\n * limite (`timeoutMs`) for atingido antes disso.\n */\n async waitUntilPaid(checkoutToken: string, options: WaitUntilPaidOptions = {}): Promise<CheckoutStatusResult> {\n const intervalMs = options.intervalMs ?? 2000;\n const timeoutMs = options.timeoutMs ?? 5 * 60 * 1000;\n const deadline = Date.now() + timeoutMs;\n\n for (;;) {\n const result = await this.getStatus(checkoutToken);\n if (result.status !== \"PENDING\" && result.status !== \"PROCESSING\") {\n return result;\n }\n if (Date.now() >= deadline) {\n throw new Error(`Tempo limite excedido aguardando confirmação de pagamento (checkout_token=${checkoutToken}).`);\n }\n await new Promise((resolve) => setTimeout(resolve, intervalMs));\n }\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type { Coupon, CreateCouponInput } from \"../types.js\";\n\nexport class CouponsResource {\n constructor(private readonly http: HttpClient) {}\n\n list(): Promise<Coupon[]> {\n return this.http.get<Coupon[]>(\"/coupons\");\n }\n\n /** `idOrCode` aceita tanto o id interno (`coupon.id`) quanto o `code` legível que você\n * escolheu na criação (ex: `\"BEMVINDO20\"`) — normalmente é mais prático guardar/usar o\n * `code`, já que é você quem o define e é o que aparece para o cliente final. */\n get(idOrCode: string): Promise<Coupon> {\n return this.http.get<Coupon>(`/coupons/${idOrCode}`);\n }\n\n /**\n * Cria um cupom de desconto — o `code` é o que o cliente final informa no checkout\n * (`plans.checkout(planId, { coupon_code })`).\n *\n * ```ts\n * // 20% de desconto, aplicado só na primeira cobrança\n * await client.coupons.create({ code: \"BEMVINDO20\", type: \"PERCENTAGE\", value: 20, duration: \"ONCE\" });\n *\n * // R$10 de desconto, repetido pelas 3 primeiras renovações\n * await client.coupons.create({\n * code: \"R10X3\", type: \"FIXED\", value: 1000, duration: \"REPEATING\", duration_months: 3,\n * });\n * ```\n */\n create(input: CreateCouponInput): Promise<Coupon> {\n return this.http.post<Coupon>(\"/coupons\", input);\n }\n\n /** Só permite editar limites/validade/ativação — o desconto em si (type/value/duration)\n * de um cupom já criado é imutável; crie um novo código para mudar o valor do desconto.\n * `idOrCode` aceita id interno ou `code` (ver `get`). */\n update(idOrCode: string, input: Partial<Pick<CreateCouponInput, \"max_redemptions\" | \"expires_at\">> & { active?: boolean }): Promise<Coupon> {\n return this.http.patch<Coupon>(`/coupons/${idOrCode}`, input);\n }\n\n /** Desativa o cupom (soft-delete) — códigos já resgatados continuam no histórico.\n * `idOrCode` aceita id interno ou `code` (ver `get`). */\n remove(idOrCode: string): Promise<void> {\n return this.http.delete<void>(`/coupons/${idOrCode}`);\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type {\n Customer,\n CustomerInput,\n CustomerListFilters,\n CustomerUpdateInput,\n PaymentMethodSetupIntent,\n PaymentMethodSummary,\n TaxIdLookupResult,\n CepLookupResult,\n} from \"../types.js\";\n\nexport class CustomersResource {\n constructor(private readonly http: HttpClient) {}\n\n /** Lista clientes — opcionalmente filtrando por `external_ref`, `tax_id` ou `customer_type`. */\n list(filters: CustomerListFilters = {}): Promise<Customer[]> {\n const qs = new URLSearchParams(Object.entries(filters).filter(([, v]) => v) as [string, string][]).toString();\n return this.http.get<Customer[]>(qs ? `/customers?${qs}` : \"/customers\");\n }\n\n /**\n * Busca o cliente de cobrança pela referência do seu app (ex: `\"company:456\"`). Use ao\n * trocar de conta (pessoal ↔ empresa) para operar nos cartões da conta ativa.\n */\n async findByExternalRef(externalRef: string): Promise<Customer | null> {\n const [c] = await this.list({ external_ref: externalRef });\n return c ?? null;\n }\n\n /**\n * Valida um CPF/CNPJ e, para CNPJ, retorna razão social, nome fantasia e endereço da\n * Receita Federal — use para pré-preencher o cadastro assim que o usuário digitar.\n * Consulta em cascata (Minha Receita → BrasilAPI → CNPJá → CNPJ.ws → ReceitaWS); 404\n * quando nenhuma base encontra o CNPJ, 502 quando todas falham.\n */\n lookupTaxId(taxId: string): Promise<TaxIdLookupResult> {\n return this.http.get<TaxIdLookupResult>(`/customers/tax-id-lookup/${encodeURIComponent(taxId.replace(/\\D/g, \"\"))}`);\n }\n\n /**\n * Cria um cliente pessoa física (CPF) ou empresa (CNPJ). Para CNPJ, os campos não\n * informados (razão social, endereço...) são completados com os dados da Receita.\n * Cada cliente tem seus próprios cartões — cadastre a empresa como cliente separado.\n *\n * ```ts\n * await client.customers.create({ tax_id: \"11.222.333/0001-81\", email: \"fin@acme.com\", external_ref: \"company:456\" });\n * ```\n */\n /**\n * Busca o endereço de um CEP (ViaCEP → BrasilAPI → OpenCEP → AwesomeAPI → ApiCEP, em\n * cascata). 404 quando nenhuma base conhece o CEP, 502 quando todas falham.\n */\n lookupCep(cep: string): Promise<CepLookupResult> {\n return this.http.get<CepLookupResult>(`/customers/cep-lookup/${encodeURIComponent(cep.replace(/\\D/g, \"\"))}`);\n }\n\n /**\n * Ressincroniza razão social, nome fantasia e endereço de um cliente empresa com o\n * registro atual da Receita Federal — único jeito de alterar esses campos.\n */\n refreshRegistry(id: string): Promise<Customer & { registry_source: string }> {\n return this.http.post<Customer & { registry_source: string }>(`/customers/${id}/refresh-registry`);\n }\n\n create(input: CustomerInput): Promise<Customer> {\n return this.http.post<Customer>(\"/customers\", input);\n }\n\n get(id: string): Promise<Customer> {\n return this.http.get<Customer>(`/customers/${id}`);\n }\n\n /** Atualiza dados de cobrança do cliente (nome, e-mail, endereço, CPF/CNPJ, razão social...). */\n update(id: string, input: CustomerUpdateInput): Promise<Customer> {\n return this.http.patch<Customer>(`/customers/${id}`, input);\n }\n\n /**\n * Lista os métodos de pagamento salvos do cliente — nunca expõe o número completo do\n * cartão, só os 4 últimos dígitos, bandeira e validade.\n */\n listPaymentMethods(id: string): Promise<PaymentMethodSummary[]> {\n return this.http.get<PaymentMethodSummary[]>(`/customers/${id}/payment-methods`);\n }\n\n /**\n * Cria um SetupIntent para o cliente cadastrar um novo cartão — use o `clientSecret`\n * retornado com Stripe.js/Elements no frontend do seu app para coletar e confirmar o\n * cartão; seu backend nunca vê o número do cartão.\n *\n * ```ts\n * const { clientSecret } = await client.customers.createPaymentMethodSetupIntent(customerId);\n * // no frontend: stripe.confirmCardSetup(clientSecret, { payment_method: {...} })\n * ```\n */\n createPaymentMethodSetupIntent(id: string): Promise<PaymentMethodSetupIntent> {\n return this.http.post<PaymentMethodSetupIntent>(`/customers/${id}/payment-methods/setup-intent`);\n }\n\n /** Define um método de pagamento salvo como o padrão do cliente (usado em cobranças off-session). */\n setDefaultPaymentMethod(id: string, paymentMethodId: string): Promise<void> {\n return this.http.patch<void>(`/customers/${id}/payment-methods/${paymentMethodId}/default`);\n }\n\n /** Remove um método de pagamento salvo do cliente. */\n deletePaymentMethod(id: string, paymentMethodId: string): Promise<void> {\n return this.http.delete<void>(`/customers/${id}/payment-methods/${paymentMethodId}`);\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type { BillingItem } from \"../types.js\";\n\nexport interface ItemInput {\n name: string;\n description?: string;\n amount: number;\n currency?: string;\n}\n\nexport class ItemsResource {\n constructor(private readonly http: HttpClient) {}\n\n list(): Promise<BillingItem[]> {\n return this.http.get<BillingItem[]>(\"/items\");\n }\n\n create(input: ItemInput): Promise<BillingItem> {\n return this.http.post<BillingItem>(\"/items\", input);\n }\n\n get(id: string): Promise<BillingItem> {\n return this.http.get<BillingItem>(`/items/${id}`);\n }\n\n update(id: string, input: Partial<ItemInput>): Promise<BillingItem> {\n return this.http.patch<BillingItem>(`/items/${id}`, input);\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type { CreateOrderInput, CreateOrderResult } from \"../types.js\";\n\nexport class OrdersResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Cria um pedido parcelado (parcelamento real via cobranças avulsas agendadas,\n * não assinatura). Retorna o `client_secret` da 1ª parcela para o front-end\n * confirmar via Stripe Elements — as parcelas seguintes são cobradas\n * automaticamente pelo backend no cartão salvo.\n */\n create(input: CreateOrderInput): Promise<CreateOrderResult> {\n return this.http.post<CreateOrderResult>(\"/orders\", input);\n }\n\n list(): Promise<unknown[]> {\n return this.http.get(\"/orders\");\n }\n\n get(id: string): Promise<unknown> {\n return this.http.get(`/orders/${id}`);\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type {\n BillingPlanSummary,\n CheckoutForCustomerInput,\n CheckoutForCustomerResult,\n CreateBillingPlanInput,\n GetPublicPlanPageResult,\n ListPublicPlansResult,\n PlanCheckoutInput,\n PlanCheckoutResult,\n PlanSubscriptionStatusResult,\n} from \"../types.js\";\n\nexport class PlansResource {\n constructor(private readonly http: HttpClient) {}\n\n list(): Promise<BillingPlanSummary[]> {\n return this.http.get<BillingPlanSummary[]>(\"/billing-plans\");\n }\n\n get(id: string): Promise<BillingPlanSummary> {\n return this.http.get<BillingPlanSummary>(`/billing-plans/${id}`);\n }\n\n create(input: CreateBillingPlanInput): Promise<BillingPlanSummary> {\n return this.http.post<BillingPlanSummary>(\"/billing-plans\", input);\n }\n\n update(id: string, input: Partial<CreateBillingPlanInput> & { active?: boolean }): Promise<BillingPlanSummary> {\n return this.http.patch<BillingPlanSummary>(`/billing-plans/${id}`, input);\n }\n\n /** Não há hard-delete de planos (assinaturas existentes ainda referenciam) — para\n * remover um plano do catálogo público, arquive-o. */\n archive(id: string): Promise<BillingPlanSummary> {\n return this.http.patch<BillingPlanSummary>(`/billing-plans/${id}`, { active: false });\n }\n\n /** Vincula um plano avulso a uma página de planos existente (mesma org). */\n attachToPage(planId: string, pageId: string): Promise<BillingPlanSummary> {\n return this.http.patch<BillingPlanSummary>(`/billing-plans/${planId}`, { plan_page_id: pageId });\n }\n\n /** Desvincula um plano da sua página, tornando-o avulso (sem página pública). */\n detachFromPage(planId: string): Promise<BillingPlanSummary> {\n return this.http.patch<BillingPlanSummary>(`/billing-plans/${planId}`, { plan_page_id: null });\n }\n\n /**\n * Fluxo simplificado de assinatura para um `Customer` já cadastrado na sua org\n * (autenticado, sem formulário de nome/e-mail): cria a assinatura + cobrança inicial e\n * retorna a URL de checkout hospedada.\n *\n * ```ts\n * const { checkout_url } = await client.plans.checkoutPlan(planId, customerId, {\n * return_url: \"https://meuapp.com/conta?upgraded=1\",\n * });\n * // redirecione o cliente para checkout_url; ele paga e volta para sua URL de retorno\n *\n * // depois que o cliente volta:\n * const { active, item } = await client.plans.confirmPlanSubscription(planId, customerId);\n * if (active) {\n * // ativa o plano real no seu sistema\n * }\n * ```\n */\n checkoutPlan(planId: string, customerId: string, input?: CheckoutForCustomerInput): Promise<CheckoutForCustomerResult> {\n return this.http.post<CheckoutForCustomerResult>(`/billing-plans/${planId}/checkout-for-customer`, {\n customer_id: customerId,\n ...(input?.return_url ? { return_url: input.return_url } : {}),\n ...(input?.expires_in ? { expires_in: input.expires_in } : {}),\n ...(input?.coupon_code ? { coupon_code: input.coupon_code } : {}),\n });\n }\n\n /** Verifica se um `Customer` tem uma assinatura ativa deste plano (a mais recente),\n * contraparte de `checkoutPlan` no fluxo simplificado autenticado. */\n confirmPlanSubscription(planId: string, customerId: string): Promise<PlanSubscriptionStatusResult> {\n return this.http.get<PlanSubscriptionStatusResult>(`/billing-plans/${planId}/subscription-status?customer_id=${encodeURIComponent(customerId)}`);\n }\n\n // ─── Rotas públicas (sem auth — usadas para montar sua própria página de preços) ──\n\n /** Lista os planos ativos de uma org pelo slug público — página fixa legada, sem\n * suporte a múltiplas páginas. Prefira `getPublicPage` para orgs com várias páginas. */\n listPublic(orgSlug: string): Promise<ListPublicPlansResult> {\n return this.http.get<ListPublicPlansResult>(`/public/orgs/${orgSlug}/billing-plans`);\n }\n\n /** Busca uma página de planos pública específica pelo slug da org + slug da página. */\n getPublicPage(orgSlug: string, pageSlug: string): Promise<GetPublicPlanPageResult> {\n return this.http.get<GetPublicPlanPageResult>(`/public/orgs/${orgSlug}/plan-pages/${pageSlug}`);\n }\n\n /**\n * Inicia a assinatura de um plano para um cliente final: cria (ou reaproveita) o\n * `Customer` pelo e-mail, cria a `Subscription` e retorna uma URL de checkout hospedada\n * pela Geekapps para o cliente confirmar o pagamento.\n *\n * Fluxo típico:\n * ```ts\n * const { checkout_url, checkout_token } = await client.plans.checkout(planId, {\n * customer: { name, email },\n * coupon_code: \"PROMO20\", // opcional — página já abre com o desconto aplicado\n * });\n * // redirecione o cliente (ou abra checkout_url em uma WebView/nova aba)\n * window.location.href = checkout_url;\n *\n * // depois do retorno, confirme se realmente foi pago:\n * const { status } = await client.checkout.waitUntilPaid(checkout_token);\n * if (status === \"PAID\") { /* liberar acesso *\\/ }\n * ```\n *\n * Não requer autenticação — pode ser chamado a partir do backend do dev sem token de\n * service account, ou do próprio SDK server-side usando qualquer token válido.\n */\n checkout(planId: string, input: PlanCheckoutInput): Promise<PlanCheckoutResult> {\n return this.http.post<PlanCheckoutResult>(`/public/billing-plans/${planId}/checkout`, input);\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type {\n CancelSubscriptionInput,\n CreateSubscriptionInput,\n CreateSubscriptionResult,\n Subscription,\n SubscriptionStatusResult,\n SwapPlanInput,\n SwapPlanPreviewResult,\n SwapPlanResult,\n} from \"../types.js\";\n\nexport class SubscriptionsResource {\n constructor(private readonly http: HttpClient) {}\n\n /** Requer autenticação (service account) — lista todas as assinaturas da sua org. */\n list(): Promise<Subscription[]> {\n return this.http.get<Subscription[]>(\"/billing-subscriptions\");\n }\n\n /**\n * Fluxo legado de assinatura por `BillingItem` avulso (sem `BillingPlan`) — requer\n * autenticação (service account) e que `customer_id`/`item_id` já existam na sua org.\n * Prefira `plans.checkout`/`plans.checkoutPlan` para novos catálogos baseados em plano.\n *\n * ```ts\n * await client.subscriptions.create({\n * customer_id, item_id, interval: \"MONTHLY\", coupon_code: \"PROMO20\",\n * });\n * ```\n */\n create(input: CreateSubscriptionInput): Promise<CreateSubscriptionResult> {\n return this.http.post<CreateSubscriptionResult>(\"/billing-subscriptions\", input);\n }\n\n /** Requer autenticação (service account). */\n get(id: string): Promise<Subscription> {\n return this.http.get<Subscription>(`/billing-subscriptions/${id}`);\n }\n\n /**\n * Cancela uma assinatura — requer autenticação (service account). Cancela no provedor\n * (Stripe) quando aplicável, marca cobranças pendentes como CANCELLED, e notifica o\n * cliente. `policy` decide o que acontece com o valor já pago do período vigente:\n * `IMMEDIATE_NO_REFUND` (cancela agora, sem reembolso), `IMMEDIATE_PRORATED_REFUND`\n * (cancela agora, reembolsa a parte não usada), `IMMEDIATE_FIXED_REFUND` (cancela agora,\n * reembolsa um valor definido manualmente — exige `fixedRefundAmount`), ou\n * `END_OF_PERIOD` (continua ativa até o fim do período atual, sem reembolso).\n *\n * ```ts\n * await client.subscriptions.cancel(subId, { policy: \"END_OF_PERIOD\" });\n * ```\n */\n cancel(id: string, input: CancelSubscriptionInput): Promise<Subscription> {\n return this.http.patch<Subscription>(`/billing-subscriptions/${id}/cancel`, {\n policy: input.policy,\n ...(input.fixedRefundAmount !== undefined ? { fixed_refund_amount: input.fixedRefundAmount } : {}),\n });\n }\n\n /**\n * Reverte um cancelamento agendado (cancel_at_period_end) — requer autenticação\n * (service account). Só se aplica enquanto a assinatura ainda está ACTIVE com o\n * cancelamento agendado pro fim do período vigente (ver SUBSCRIPTION_CANCEL_SCHEDULE);\n * uma vez CANCELLED de fato, a Subscription já foi encerrada no Stripe e não há o que\n * reverter — chame `cancel`/checkout novamente para recomeçar.\n */\n resume(id: string): Promise<Subscription> {\n return this.http.patch<Subscription>(`/billing-subscriptions/${id}/resume`);\n }\n\n /**\n * Calcula o preview de uma troca de plano (não muta nada) — requer autenticação\n * (service account). Use para mostrar ao dono da org o valor devido/estimado antes de\n * confirmar com `swapPlan`.\n *\n * ```ts\n * const preview = await client.subscriptions.previewPlanSwap(subId, {\n * newPlanId, policy: \"AT_RENEWAL\",\n * });\n * ```\n */\n previewPlanSwap(id: string, input: SwapPlanInput): Promise<SwapPlanPreviewResult> {\n const params = new URLSearchParams({ new_plan_id: input.newPlanId, policy: input.policy });\n if (input.manualAmount !== undefined) params.set(\"manual_amount\", String(input.manualAmount));\n if (input.couponCode) params.set(\"coupon_code\", input.couponCode);\n return this.http.get<SwapPlanPreviewResult>(`/billing-subscriptions/${id}/swap-preview?${params.toString()}`);\n }\n\n /**\n * Executa a troca de plano/item de uma assinatura já existente (upgrade/downgrade de\n * tier) — requer autenticação (service account). Executa a troca diretamente, sem\n * confirmação posterior do cliente final; o dono do org escolhe `policy` (cobrar/estornar\n * agora, aplicar só na próxima renovação, ou valor definido manualmente) antes de chamar.\n *\n * `manualAmount`: obrigatório quando `policy` é `\"FIXED_AMOUNT\"` — valor de ajuste assinado\n * (cents), positivo cobra o cliente, negativo estorna.\n *\n * `couponCode`: aplica um cupom na troca — se a assinatura for Stripe, o desconto passa a\n * valer também nas renovações futuras (recorrente, direto na Subscription); se for\n * PIX/boleto, o desconto vale só para a cobrança de proration desta troca.\n *\n * `autoCharge`: quando há diferença a cobrar na hora (`policy` `\"IMMEDIATE\"` ou\n * `\"FIXED_AMOUNT\"` positivo), decide se tenta cobrar o cartão salvo do cliente direto\n * (`true` — se falhar, a troca inteira é revertida e a chamada rejeita) ou se gera a\n * cobrança e devolve `checkout_url` para o cliente pagar manualmente (`false`/omitido,\n * padrão — o plano só é aplicado quando o pagamento for confirmado).\n *\n * ```ts\n * // Cobra o cartão salvo na hora — se falhar, a troca não acontece.\n * const result = await client.subscriptions.swapPlan(subId, {\n * newPlanId, policy: \"IMMEDIATE\", couponCode: \"PROMO20\", autoCharge: true,\n * });\n *\n * // Ou: gera o link de pagamento, sem tentar cartão salvo.\n * const result2 = await client.subscriptions.swapPlan(subId, { newPlanId, policy: \"IMMEDIATE\" });\n * if (result2.checkout_url) {\n * // redirecione o cliente final para result2.checkout_url para pagar a cobrança de ajuste\n * }\n * ```\n */\n swapPlan(id: string, input: SwapPlanInput): Promise<SwapPlanResult> {\n return this.http.patch<SwapPlanResult>(`/billing-subscriptions/${id}/swap`, {\n new_plan_id: input.newPlanId,\n policy: input.policy,\n ...(input.manualAmount !== undefined ? { manual_amount: input.manualAmount } : {}),\n ...(input.expiresInSeconds ? { expires_in: input.expiresInSeconds } : {}),\n ...(input.couponCode ? { coupon_code: input.couponCode } : {}),\n ...(input.autoCharge !== undefined ? { auto_charge: input.autoCharge } : {}),\n });\n }\n\n /**\n * Cancela uma troca de plano ainda pendente (aguardando confirmação de pagamento ou\n * renovação — `policy: \"AT_RENEWAL\"` ou upgrade IMMEDIATE com proration nativa) — requer\n * autenticação (service account). Mantém a assinatura no plano atual, revertendo o price já\n * trocado no Stripe. Não se aplica a trocas com `policy: \"FIXED_AMOUNT\"` ou downgrade/estorno\n * imediato, que já aplicam o novo plano na hora — nesse caso não há o que cancelar, é preciso\n * chamar `swapPlan` de novo para trocar para outro plano.\n *\n * ```ts\n * await client.subscriptions.cancelPendingPlanSwap(subId);\n * ```\n */\n cancelPendingPlanSwap(id: string): Promise<Subscription> {\n return this.http.delete<Subscription>(`/billing-subscriptions/${id}/swap`);\n }\n\n /**\n * Verifica se uma assinatura está ativa e qual item ela cobre, usando o\n * `management_token` retornado por `plans.checkout()` — rota pública, sem\n * autenticação, segura para chamar tanto do seu backend quanto (via fetch direto,\n * sem o SDK) do client-side do seu app.\n *\n * ```ts\n * const status = await client.subscriptions.checkByToken(managementToken);\n * if (status.subscription.active) {\n * console.log(\"cobrando\", status.item.name);\n * }\n * ```\n */\n checkByToken(managementToken: string): Promise<SubscriptionStatusResult> {\n return this.http.get<SubscriptionStatusResult>(`/public/plan-management/${managementToken}`);\n }\n}\n","import type { HttpClient } from \"../http.js\";\n\nexport type OutboundWebhookEventType =\n | \"SUBSCRIPTION_CREATED\"\n | \"SUBSCRIPTION_ACTIVATED\"\n | \"SUBSCRIPTION_RENEWED\"\n | \"SUBSCRIPTION_PLAN_SWAPPED\"\n | \"SUBSCRIPTION_PAST_DUE\"\n | \"SUBSCRIPTION_CANCELLED\"\n | \"SUBSCRIPTION_CANCEL_SCHEDULE\"\n | \"SUBSCRIPTION_RESUMED\"\n | \"CHARGE_PAID\"\n | \"CHARGE_FAILED\"\n | \"CHARGE_EXPIRED\"\n | \"CHARGE_REFUNDED\";\n\n/** Payload de uma cobrança (`data`) nos eventos CHARGE_*. `description` é `null` quando\n * a cobrança não tem descrição definida. */\nexport interface ChargeEventData {\n chargeId: string;\n amountCents: number;\n description: string | null;\n}\n\n/** Union discriminada por `event_type` — use para tipar o corpo recebido na sua rota de\n * webhook (ver `X-Geekapps-Signature` para validar a assinatura antes de confiar no payload).\n *\n * ```ts\n * const event = JSON.parse(rawBody) as WebhookEvent;\n * switch (event.event_type) {\n * case \"CHARGE_PAID\":\n * // event.data: { chargeId, amountCents, description }\n * break;\n * case \"SUBSCRIPTION_CANCELLED\":\n * // event.data: { subscriptionId }\n * break;\n * }\n * ```\n */\nexport type WebhookEvent =\n | {\n event_type: \"SUBSCRIPTION_CREATED\";\n org_id: string;\n data: { subscriptionId: string; customerId: string; itemId: string; interval: string };\n }\n | {\n event_type: \"SUBSCRIPTION_ACTIVATED\";\n org_id: string;\n data: { subscriptionId: string };\n }\n | {\n /** Disparado a cada renovação paga com sucesso — em toda cobrança recorrente\n * confirmada, independente do status anterior da assinatura (distinto de\n * SUBSCRIPTION_ACTIVATED, que só marca a transição de volta pra ACTIVE). */\n event_type: \"SUBSCRIPTION_RENEWED\";\n org_id: string;\n data: { subscriptionId: string; chargeId: string | null };\n }\n | {\n event_type: \"SUBSCRIPTION_PLAN_SWAPPED\";\n org_id: string;\n data: { subscriptionId: string; oldPlanId: string; newPlanId: string; mode: string };\n }\n | {\n event_type: \"SUBSCRIPTION_PAST_DUE\";\n org_id: string;\n data: { subscriptionId: string };\n }\n | {\n event_type: \"SUBSCRIPTION_CANCELLED\";\n org_id: string;\n data: { subscriptionId: string };\n }\n | {\n /** Disparado quando um cancelamento é agendado para o fim do período vigente\n * (política END_OF_PERIOD ou cancelamento/reversão feito no Stripe Billing Portal) —\n * a assinatura continua ACTIVE até `data.effective_at`; distinto de\n * SUBSCRIPTION_CANCELLED, que marca o cancelamento definitivo. */\n event_type: \"SUBSCRIPTION_CANCEL_SCHEDULE\";\n org_id: string;\n data: { subscriptionId: string; effective_at: string | null };\n }\n | {\n /** Disparado quando um cancelamento agendado (SUBSCRIPTION_CANCEL_SCHEDULE) é\n * revertido antes do fim do período — a assinatura volta a renovar normalmente. */\n event_type: \"SUBSCRIPTION_RESUMED\";\n org_id: string;\n data: { subscriptionId: string };\n }\n | {\n event_type: \"CHARGE_PAID\";\n org_id: string;\n data: ChargeEventData;\n }\n | {\n event_type: \"CHARGE_FAILED\";\n org_id: string;\n data: ChargeEventData;\n }\n | {\n event_type: \"CHARGE_EXPIRED\";\n org_id: string;\n data: ChargeEventData;\n }\n | {\n event_type: \"CHARGE_REFUNDED\";\n org_id: string;\n data: ChargeEventData;\n };\n\nexport interface WebhookEndpointInput {\n url: string;\n eventTypes: OutboundWebhookEventType[];\n /** Opcional — quando omitido, o servidor gera um secret automaticamente. */\n secret?: string;\n}\n\nexport interface WebhookEndpointSummary {\n id: string;\n url: string;\n event_types: OutboundWebhookEventType[];\n active: boolean;\n /** Segredo completo apenas na primeira criação — em toda resposta subsequente vem mascarado. */\n secret: string;\n created_at: string;\n updated_at: string;\n}\n\nexport class WebhooksResource {\n constructor(private readonly http: HttpClient) {}\n\n /** Lista os webhooks outbound cadastrados na sua org (secret sempre mascarado). */\n list(): Promise<WebhookEndpointSummary[]> {\n return this.http.get<WebhookEndpointSummary[]>(\"/webhook-endpoints\");\n }\n\n /**\n * Registra um webhook outbound — idempotente por (org, url): chamar de novo com a\n * mesma URL apenas atualiza os `eventTypes`, sem criar duplicata. Guarde o `secret`\n * retornado (só vem completo na primeira criação) para validar a assinatura\n * `X-Geekapps-Signature` nas entregas recebidas. Passe `secret` para definir o seu\n * próprio signing secret; se omitido, um valor aleatório é gerado automaticamente.\n */\n register(input: WebhookEndpointInput): Promise<WebhookEndpointSummary> {\n return this.http.post<WebhookEndpointSummary>(\"/webhook-endpoints\", {\n url: input.url,\n event_types: input.eventTypes,\n ...(input.secret ? { secret: input.secret } : {}),\n });\n }\n\n /** Edita um webhook existente — URL, eventos assinados e/ou status ativo/inativo. */\n update(id: string, input: Partial<WebhookEndpointInput> & { active?: boolean }): Promise<WebhookEndpointSummary> {\n return this.http.patch<WebhookEndpointSummary>(`/webhook-endpoints/${id}`, {\n ...(input.url ? { url: input.url } : {}),\n ...(input.eventTypes ? { event_types: input.eventTypes } : {}),\n ...(input.active !== undefined ? { active: input.active } : {}),\n });\n }\n\n /** Gera um novo secret e substitui o atual — a versão antiga deixa de validar imediatamente. */\n rotateSecret(id: string): Promise<WebhookEndpointSummary> {\n return this.http.post<WebhookEndpointSummary>(`/webhook-endpoints/${id}/rotate-secret`);\n }\n\n remove(id: string): Promise<void> {\n return this.http.delete<void>(`/webhook-endpoints/${id}`);\n }\n}\n","import { HttpClient, type HttpClientOptions } from \"./http.js\";\nimport { ChargesResource } from \"./resources/charges.js\";\nimport { CheckoutResource } from \"./resources/checkout.js\";\nimport { CouponsResource } from \"./resources/coupons.js\";\nimport { CustomersResource } from \"./resources/customers.js\";\nimport { ItemsResource } from \"./resources/items.js\";\nimport { OrdersResource } from \"./resources/orders.js\";\nimport { PlansResource } from \"./resources/plans.js\";\nimport { SubscriptionsResource } from \"./resources/subscriptions.js\";\nimport { WebhooksResource } from \"./resources/webhooks.js\";\n\nexport interface BillingClientOptions\n extends Omit<HttpClientOptions, \"baseUrl\"> {\n baseUrl?: string;\n}\n\nexport class BillingClient {\n private readonly http: HttpClient;\n\n readonly charges: ChargesResource;\n readonly checkout: CheckoutResource;\n readonly coupons: CouponsResource;\n readonly customers: CustomersResource;\n readonly items: ItemsResource;\n readonly orders: OrdersResource;\n readonly plans: PlansResource;\n readonly subscriptions: SubscriptionsResource;\n readonly webhooks: WebhooksResource;\n\n constructor(options: HttpClientOptions) {\n this.http = new HttpClient(options);\n\n this.charges = new ChargesResource(this.http);\n this.checkout = new CheckoutResource(this.http);\n this.coupons = new CouponsResource(this.http);\n this.customers = new CustomersResource(this.http);\n this.items = new ItemsResource(this.http);\n this.orders = new OrdersResource(this.http);\n this.plans = new PlansResource(this.http);\n this.subscriptions = new SubscriptionsResource(this.http);\n this.webhooks = new WebhooksResource(this.http);\n }\n}\n","import type { FastifyInstance, FastifyPluginAsync } from \"fastify\";\nimport fp from \"fastify-plugin\";\nimport { BillingClient } from \"./client.js\";\nimport { ServiceAccountTokenProvider, type ServiceAccountOptions } from \"./service-account.js\";\n\nexport interface BillingPluginOptions {\n /** Geekapps Billing API base URL */\n baseUrl: string;\n /** Service account credentials — required */\n serviceAccount: ServiceAccountOptions;\n /** Ambiente de billing (dev/prod). Default: \"prod\". */\n mode?: string;\n}\n\ndeclare module \"fastify\" {\n interface FastifyInstance {\n billingClient: BillingClient;\n }\n}\n\nconst billingPlugin: FastifyPluginAsync<BillingPluginOptions> = async (\n fastify: FastifyInstance,\n options: BillingPluginOptions,\n) => {\n const tokenProvider = new ServiceAccountTokenProvider(options.serviceAccount);\n\n const client = new BillingClient({\n baseUrl: options.baseUrl,\n token: () => tokenProvider.getToken(),\n organizationId: () => tokenProvider.getOrganizationId() as Promise<string>,\n mode: options.mode,\n });\n\n fastify.decorate(\"billingClient\", client);\n};\n\nexport default fp(billingPlugin, {\n fastify: \">=4.0.0\",\n name: \"@geekapps/billing-fastify\",\n});\n","import type { TokenResolver } from \"./http.js\";\n\nexport interface ServiceAccountOptions {\n /** Geekapps Auth issuer base URL (e.g. https://accounts-api.geekapps.com.br) */\n issuerUrl: string;\n clientId: string;\n clientSecret: string;\n /** Seconds before expiry to proactively refresh. Defaults to 30. */\n refreshBeforeExpirySeconds?: number;\n}\n\ninterface CachedToken {\n value: string;\n expiresAt: number; // ms epoch\n organizationId: string | undefined;\n}\n\nfunction decodeJwtPayload(token: string): Record<string, unknown> {\n try {\n const [, payload] = token.split(\".\");\n if (!payload) return {};\n const json = Buffer.from(payload, \"base64url\").toString(\"utf-8\");\n return JSON.parse(json) as Record<string, unknown>;\n } catch {\n return {};\n }\n}\n\n/**\n * Fetches a short-lived token from the Geekapps Auth service using\n * client_credentials grant and caches it until near expiry.\n *\n * The organizationId claim is extracted automatically from the JWT payload.\n */\nexport class ServiceAccountTokenProvider {\n private readonly issuerUrl: string;\n private readonly clientId: string;\n private readonly clientSecret: string;\n private readonly refreshBeforeMs: number;\n private cached: CachedToken | null = null;\n private inflight: Promise<CachedToken> | null = null;\n\n constructor(options: ServiceAccountOptions) {\n this.issuerUrl = options.issuerUrl.replace(/\\/$/, \"\");\n this.clientId = options.clientId;\n this.clientSecret = options.clientSecret;\n this.refreshBeforeMs = (options.refreshBeforeExpirySeconds ?? 30) * 1000;\n }\n\n private async ensureFresh(): Promise<CachedToken> {\n const now = Date.now();\n\n if (this.cached && this.cached.expiresAt - now > this.refreshBeforeMs) {\n return this.cached;\n }\n\n if (this.inflight) return this.inflight;\n\n this.inflight = this.fetchToken().finally(() => {\n this.inflight = null;\n });\n\n return this.inflight;\n }\n\n /** Returns a valid access token. */\n getToken(): Promise<string> {\n return this.ensureFresh().then((c) => c.value);\n }\n\n /** Returns the organizationId embedded in the service account JWT. */\n getOrganizationId(): Promise<string | undefined> {\n return this.ensureFresh().then((c) => c.organizationId);\n }\n\n private async fetchToken(): Promise<CachedToken> {\n const credentials = Buffer.from(`${this.clientId}:${this.clientSecret}`).toString(\"base64\");\n\n const res = await fetch(`${this.issuerUrl}/auth/token`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Basic ${credentials}`,\n },\n body: JSON.stringify({ grant_type: \"service_account\" }),\n });\n\n if (!res.ok) {\n const err = await res.json().catch(() => ({})) as { error?: string };\n throw new Error(\n `ServiceAccount token fetch failed (${res.status}): ${err.error ?? \"unknown error\"}`,\n );\n }\n\n const data = await res.json() as { access_token: string; expires_in?: number };\n\n const claims = decodeJwtPayload(data.access_token);\n const organizationId =\n typeof claims.organizationId === \"string\" ? claims.organizationId :\n typeof claims.organization_id === \"string\" ? claims.organization_id :\n typeof claims.org_id === \"string\" ? claims.org_id :\n undefined;\n\n const expiresInMs = (data.expires_in ?? 420) * 1000;\n this.cached = {\n value: data.access_token,\n expiresAt: Date.now() + expiresInMs,\n organizationId,\n };\n\n return this.cached;\n }\n\n /** Returns this provider as a TokenResolver to pass directly to BillingClient. */\n asTokenResolver(): TokenResolver {\n return () => this.getToken();\n }\n}\n\n/** Convenience factory. Returns a TokenResolver ready for use in BillingClient. */\nexport function createServiceAccountToken(\n options: ServiceAccountOptions,\n): TokenResolver {\n return new ServiceAccountTokenProvider(options).asTokenResolver();\n}\n","export type ExpirationUnit = \"seconds\" | \"minutes\" | \"hours\" | \"days\";\n\nconst MULTIPLIERS: Record<ExpirationUnit, number> = {\n seconds: 1,\n minutes: 60,\n hours: 3600,\n days: 86400,\n};\n\n/**\n * Converte um valor + unidade para segundos, prontos para usar em `expires_in`.\n *\n * ```ts\n * await client.charges.create({ ..., expires_in: expiresIn(30, \"minutes\") });\n * ```\n */\nexport function expiresIn(value: number, unit: ExpirationUnit): number {\n return value * MULTIPLIERS[unit];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAEA,QAAM,sBAAsB;AAC5B,QAAM,kBAAkB;AAExB,WAAO,UAAU,SAAS,cAAe,IAAI;AAC3C,UAAI,GAAG,KAAK,SAAS,EAAG,QAAO,GAAG;AAElC,YAAM,kBAAkB,MAAM;AAC9B,YAAM,kBAAkB;AACxB,UAAI;AACF,cAAM,IAAI,MAAM,oBAAoB;AAAA,MACtC,SAAS,GAAG;AACV,cAAM,kBAAkB;AACxB,eAAO,kBAAkB,EAAE,KAAK;AAAA,MAClC;AAAA,IACF;AAEA,aAAS,kBAAmB,OAAO;AACjC,YAAM,IAAI,MAAM,MAAM,mBAAmB;AAGzC,aAAO,IAAI,EAAE,CAAC,EAAE,MAAM,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,eAAe,EAAE,CAAC,IAAI;AAAA,IAC1E;AACA,WAAO,QAAQ,oBAAoB;AAAA;AAAA;;;ACxBnC;AAAA;AAAA;AAEA,WAAO,UAAU,SAAS,YAAa,MAAM;AAC3C,UAAI,KAAK,CAAC,MAAM,KAAK;AACnB,eAAO,KAAK,MAAM,CAAC,EAAE,QAAQ,KAAK,GAAG;AAAA,MACvC;AACA,aAAO,KAAK,QAAQ,SAAS,SAAU,OAAO,IAAI;AAChD,eAAO,GAAG,YAAY;AAAA,MACxB,CAAC;AAAA,IACH;AAAA;AAAA;;;ACTA;AAAA;AAAA;AAEA,QAAM,gBAAgB;AACtB,QAAM,cAAc;AAEpB,QAAI,QAAQ;AAEZ,aAAS,OAAQ,IAAI,UAAU,CAAC,GAAG;AACjC,UAAI,WAAW;AAEf,UAAI,GAAG,YAAY,QAAW;AAE5B,aAAK,GAAG;AAAA,MACV;AAEA,UAAI,OAAO,OAAO,YAAY;AAC5B,cAA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;AAAA,EAChB,CAAC;AAED,UAAQ,SAAS,iBAAiB,MAAM;AAC1C;AAEA,IAAO,qBAAQ,sBAAAA,SAAG,eAAe;AAAA,EAC/B,SAAS;AAAA,EACT,MAAM;AACR,CAAC;;;AErCD,IAAM,cAA8C;AAAA,EAClD,SAAS;AAAA,EACT,SAAS;AAAA,EACT,OAAO;AAAA,EACP,MAAM;AACR;AASO,SAAS,UAAU,OAAe,MAA8B;AACrE,SAAO,QAAQ,YAAY,IAAI;AACjC;","names":["fp"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geekapps/billing-fastify",
3
- "version": "0.13.0",
3
+ "version": "0.15.0",
4
4
  "description": "Geekapps Billing SDK for Fastify",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",