@neetru/sdk 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,83 @@
1
+ /** Tipo do tenant alvo da subscription (PF=uid, PJ=orgId). */
2
+ type CheckoutTenantType = 'pf' | 'pj';
3
+ /** Status do `checkout_intents/{intentId}` no Core. */
4
+ type CheckoutIntentStatus = 'pending' | 'kyc_in_progress' | 'stripe_redirected' | 'completed' | 'expired' | 'cancelled';
5
+ interface CheckoutStartInput {
6
+ /** Slug do produto no catálogo (ex: `neetru-pulse`). */
7
+ productId: string;
8
+ /** Slug do plano no catálogo do produto (ex: `pro_monthly`). */
9
+ planId: string;
10
+ /** Pra onde o produto SaaS quer voltar pós-checkout. https obrigatório (ou http://localhost em dev). */
11
+ callbackUrl: string;
12
+ /** Override pra checkout em nome de uma org. Default: PF do uid logado. */
13
+ tenantType?: CheckoutTenantType;
14
+ /** Quando `tenantType='pj'`, id da org. Ignorado quando PF. */
15
+ tenantId?: string;
16
+ /**
17
+ * Em browsers, default `true` — SDK faz `window.location.href = redirectUrl`.
18
+ * Passe `false` se quiser controlar o redirect manualmente.
19
+ */
20
+ autoRedirect?: boolean;
21
+ }
22
+ interface CheckoutStartResult {
23
+ intentId: string;
24
+ redirectUrl: string;
25
+ status: CheckoutIntentStatus;
26
+ expiresAt: string;
27
+ /** True se KYC ainda precisa ser coletado no portal. UI pode mostrar hint. */
28
+ requiresKyc: boolean;
29
+ }
30
+ interface CheckoutIntentInfo {
31
+ intentId: string;
32
+ uid: string;
33
+ targetTenantId: string;
34
+ targetTenantType: CheckoutTenantType;
35
+ productId: string;
36
+ planId: string;
37
+ callbackUrl: string;
38
+ status: CheckoutIntentStatus;
39
+ /** Stripe Checkout Session id quando avançou pra `stripe_redirected`. */
40
+ stripeSessionId?: string | null;
41
+ expiresAt: string;
42
+ /** True se já passou `expiresAt` mas Core ainda não marcou expired. */
43
+ isStale?: boolean;
44
+ }
45
+ interface CheckoutNamespace {
46
+ /**
47
+ * Inicia checkout. Em browser, redireciona automaticamente pro portal.
48
+ * Em Node/SSR, retorna o resultado sem efeitos colaterais — caller decide
49
+ * o que fazer com `redirectUrl`.
50
+ *
51
+ * Dev mode (`NEETRU_ENV=dev`): retorna URL fake `https://localhost:9003/portal/checkout/mock-XXXX`.
52
+ */
53
+ start(input: CheckoutStartInput): Promise<CheckoutStartResult>;
54
+ /** Lê estado atual do intent (Core). */
55
+ get(intentId: string): Promise<CheckoutIntentInfo>;
56
+ /** Cancela um intent que ainda não virou `stripe_redirected`. */
57
+ cancel(intentId: string): Promise<{
58
+ ok: true;
59
+ alreadyCancelled: boolean;
60
+ }>;
61
+ }
62
+ /**
63
+ * Mock dev — retorna URL fake `https://localhost:9003/portal/checkout/mock-XXXX`
64
+ * sem tocar no Core. Útil pra dev externo SaaS testar UI/redirect sem precisar
65
+ * de Bearer token Neetru.
66
+ *
67
+ * Dev mode persiste intents em mapa in-memory pro `get`/`cancel` retornarem
68
+ * resultado consistente.
69
+ */
70
+ declare class MockCheckout implements CheckoutNamespace {
71
+ private readonly intents;
72
+ start(input: CheckoutStartInput): Promise<CheckoutStartResult>;
73
+ get(intentId: string): Promise<CheckoutIntentInfo>;
74
+ cancel(intentId: string): Promise<{
75
+ ok: true;
76
+ alreadyCancelled: boolean;
77
+ }>;
78
+ }
79
+ declare function createCheckoutNamespace(config: ResolvedConfig): CheckoutNamespace;
80
+
1
81
  /**
2
82
  * Tipos públicos do SDK Neetru.
3
83
  *
@@ -199,6 +279,8 @@ interface NeetruClient {
199
279
  readonly support: SupportNamespace;
200
280
  /** Namespace db (v0.3 — coleções tenant-scoped). */
201
281
  readonly db: DbNamespace;
282
+ /** Namespace checkout (v1.1 — start/get/cancel intent + auto-redirect). */
283
+ readonly checkout: CheckoutNamespace;
202
284
  }
203
285
  /**
204
286
  * User retornado pelo OIDC ID token. Schema neutro — não vaza Firebase
@@ -405,4 +487,4 @@ interface CatalogListOptions {
405
487
  includeDrafts?: boolean;
406
488
  }
407
489
 
408
- export { type AuthNamespace as A, type CatalogListOptions as C, DEFAULT_BASE_URL as D, type EntitlementCheck as E, type NeetruClientConfig as N, type Product as P, type ResolvedConfig as R, type SignInOptions as S, type TelemetryEventAck as T, type UsageEventInput as U, type NeetruClient as a, type AuthStateListener as b, type CatalogListResponse as c, type CreateTicketInput as d, type DbCollectionRef as e, type DbListOptions as f, type DbNamespace as g, type DbWhereFilter as h, type NeetruEnv as i, type NeetruUser as j, type ProductPlan as k, type ProductStatus as l, type SupportNamespace as m, type SupportSeverity as n, type SupportStatus as o, type SupportTicket as p, type TelemetryEventInput as q, type UsageNamespace as r, type UsageQuota as s, type TelemetryLogInput as t, type TelemetryLogAck as u };
490
+ export { type AuthNamespace as A, type TelemetryLogInput as B, type CatalogListOptions as C, DEFAULT_BASE_URL as D, type EntitlementCheck as E, type TelemetryLogAck as F, MockCheckout as M, type NeetruClientConfig as N, type Product as P, type ResolvedConfig as R, type SignInOptions as S, type TelemetryEventAck as T, type UsageEventInput as U, type NeetruClient as a, type AuthStateListener as b, type CatalogListResponse as c, type CheckoutIntentInfo as d, type CheckoutIntentStatus as e, type CheckoutNamespace as f, type CheckoutStartInput as g, type CheckoutStartResult as h, type CheckoutTenantType as i, type CreateTicketInput as j, type DbCollectionRef as k, type DbListOptions as l, type DbNamespace as m, type DbWhereFilter as n, type NeetruEnv as o, type NeetruUser as p, type ProductPlan as q, type ProductStatus as r, type SupportNamespace as s, type SupportSeverity as t, type SupportStatus as u, type SupportTicket as v, type TelemetryEventInput as w, type UsageNamespace as x, type UsageQuota as y, createCheckoutNamespace as z };
@@ -1,3 +1,83 @@
1
+ /** Tipo do tenant alvo da subscription (PF=uid, PJ=orgId). */
2
+ type CheckoutTenantType = 'pf' | 'pj';
3
+ /** Status do `checkout_intents/{intentId}` no Core. */
4
+ type CheckoutIntentStatus = 'pending' | 'kyc_in_progress' | 'stripe_redirected' | 'completed' | 'expired' | 'cancelled';
5
+ interface CheckoutStartInput {
6
+ /** Slug do produto no catálogo (ex: `neetru-pulse`). */
7
+ productId: string;
8
+ /** Slug do plano no catálogo do produto (ex: `pro_monthly`). */
9
+ planId: string;
10
+ /** Pra onde o produto SaaS quer voltar pós-checkout. https obrigatório (ou http://localhost em dev). */
11
+ callbackUrl: string;
12
+ /** Override pra checkout em nome de uma org. Default: PF do uid logado. */
13
+ tenantType?: CheckoutTenantType;
14
+ /** Quando `tenantType='pj'`, id da org. Ignorado quando PF. */
15
+ tenantId?: string;
16
+ /**
17
+ * Em browsers, default `true` — SDK faz `window.location.href = redirectUrl`.
18
+ * Passe `false` se quiser controlar o redirect manualmente.
19
+ */
20
+ autoRedirect?: boolean;
21
+ }
22
+ interface CheckoutStartResult {
23
+ intentId: string;
24
+ redirectUrl: string;
25
+ status: CheckoutIntentStatus;
26
+ expiresAt: string;
27
+ /** True se KYC ainda precisa ser coletado no portal. UI pode mostrar hint. */
28
+ requiresKyc: boolean;
29
+ }
30
+ interface CheckoutIntentInfo {
31
+ intentId: string;
32
+ uid: string;
33
+ targetTenantId: string;
34
+ targetTenantType: CheckoutTenantType;
35
+ productId: string;
36
+ planId: string;
37
+ callbackUrl: string;
38
+ status: CheckoutIntentStatus;
39
+ /** Stripe Checkout Session id quando avançou pra `stripe_redirected`. */
40
+ stripeSessionId?: string | null;
41
+ expiresAt: string;
42
+ /** True se já passou `expiresAt` mas Core ainda não marcou expired. */
43
+ isStale?: boolean;
44
+ }
45
+ interface CheckoutNamespace {
46
+ /**
47
+ * Inicia checkout. Em browser, redireciona automaticamente pro portal.
48
+ * Em Node/SSR, retorna o resultado sem efeitos colaterais — caller decide
49
+ * o que fazer com `redirectUrl`.
50
+ *
51
+ * Dev mode (`NEETRU_ENV=dev`): retorna URL fake `https://localhost:9003/portal/checkout/mock-XXXX`.
52
+ */
53
+ start(input: CheckoutStartInput): Promise<CheckoutStartResult>;
54
+ /** Lê estado atual do intent (Core). */
55
+ get(intentId: string): Promise<CheckoutIntentInfo>;
56
+ /** Cancela um intent que ainda não virou `stripe_redirected`. */
57
+ cancel(intentId: string): Promise<{
58
+ ok: true;
59
+ alreadyCancelled: boolean;
60
+ }>;
61
+ }
62
+ /**
63
+ * Mock dev — retorna URL fake `https://localhost:9003/portal/checkout/mock-XXXX`
64
+ * sem tocar no Core. Útil pra dev externo SaaS testar UI/redirect sem precisar
65
+ * de Bearer token Neetru.
66
+ *
67
+ * Dev mode persiste intents em mapa in-memory pro `get`/`cancel` retornarem
68
+ * resultado consistente.
69
+ */
70
+ declare class MockCheckout implements CheckoutNamespace {
71
+ private readonly intents;
72
+ start(input: CheckoutStartInput): Promise<CheckoutStartResult>;
73
+ get(intentId: string): Promise<CheckoutIntentInfo>;
74
+ cancel(intentId: string): Promise<{
75
+ ok: true;
76
+ alreadyCancelled: boolean;
77
+ }>;
78
+ }
79
+ declare function createCheckoutNamespace(config: ResolvedConfig): CheckoutNamespace;
80
+
1
81
  /**
2
82
  * Tipos públicos do SDK Neetru.
3
83
  *
@@ -199,6 +279,8 @@ interface NeetruClient {
199
279
  readonly support: SupportNamespace;
200
280
  /** Namespace db (v0.3 — coleções tenant-scoped). */
201
281
  readonly db: DbNamespace;
282
+ /** Namespace checkout (v1.1 — start/get/cancel intent + auto-redirect). */
283
+ readonly checkout: CheckoutNamespace;
202
284
  }
203
285
  /**
204
286
  * User retornado pelo OIDC ID token. Schema neutro — não vaza Firebase
@@ -405,4 +487,4 @@ interface CatalogListOptions {
405
487
  includeDrafts?: boolean;
406
488
  }
407
489
 
408
- export { type AuthNamespace as A, type CatalogListOptions as C, DEFAULT_BASE_URL as D, type EntitlementCheck as E, type NeetruClientConfig as N, type Product as P, type ResolvedConfig as R, type SignInOptions as S, type TelemetryEventAck as T, type UsageEventInput as U, type NeetruClient as a, type AuthStateListener as b, type CatalogListResponse as c, type CreateTicketInput as d, type DbCollectionRef as e, type DbListOptions as f, type DbNamespace as g, type DbWhereFilter as h, type NeetruEnv as i, type NeetruUser as j, type ProductPlan as k, type ProductStatus as l, type SupportNamespace as m, type SupportSeverity as n, type SupportStatus as o, type SupportTicket as p, type TelemetryEventInput as q, type UsageNamespace as r, type UsageQuota as s, type TelemetryLogInput as t, type TelemetryLogAck as u };
490
+ export { type AuthNamespace as A, type TelemetryLogInput as B, type CatalogListOptions as C, DEFAULT_BASE_URL as D, type EntitlementCheck as E, type TelemetryLogAck as F, MockCheckout as M, type NeetruClientConfig as N, type Product as P, type ResolvedConfig as R, type SignInOptions as S, type TelemetryEventAck as T, type UsageEventInput as U, type NeetruClient as a, type AuthStateListener as b, type CatalogListResponse as c, type CheckoutIntentInfo as d, type CheckoutIntentStatus as e, type CheckoutNamespace as f, type CheckoutStartInput as g, type CheckoutStartResult as h, type CheckoutTenantType as i, type CreateTicketInput as j, type DbCollectionRef as k, type DbListOptions as l, type DbNamespace as m, type DbWhereFilter as n, type NeetruEnv as o, type NeetruUser as p, type ProductPlan as q, type ProductStatus as r, type SupportNamespace as s, type SupportSeverity as t, type SupportStatus as u, type SupportTicket as v, type TelemetryEventInput as w, type UsageNamespace as x, type UsageQuota as y, createCheckoutNamespace as z };
package/dist/usage.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { R as ResolvedConfig, r as UsageNamespace } from './types-PKUaFtBY.cjs';
1
+ import { R as ResolvedConfig, x as UsageNamespace } from './types-BA53dd8S.cjs';
2
2
 
3
3
  declare function createUsageNamespace(config: ResolvedConfig): UsageNamespace;
4
4
 
package/dist/usage.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { R as ResolvedConfig, r as UsageNamespace } from './types-PKUaFtBY.js';
1
+ import { R as ResolvedConfig, x as UsageNamespace } from './types-BA53dd8S.js';
2
2
 
3
3
  declare function createUsageNamespace(config: ResolvedConfig): UsageNamespace;
4
4
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@neetru/sdk",
3
- "version": "1.0.0",
4
- "description": "Neetru SDK 1.0 GA — biblioteca runtime estável para consumir o ecossistema Neetru (auth OIDC, catalog, entitlements, telemetry, usage metering, support tickets, datastore).",
3
+ "version": "1.1.0",
4
+ "description": "Neetru SDK 1.1 — biblioteca runtime estável para consumir o ecossistema Neetru (auth OIDC, catalog, entitlements, telemetry, usage metering, support tickets, datastore, checkout).",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.mjs",
@@ -56,8 +56,24 @@
56
56
  "types": "./dist/errors.d.ts",
57
57
  "import": "./dist/errors.mjs",
58
58
  "require": "./dist/errors.cjs"
59
+ },
60
+ "./checkout": {
61
+ "types": "./dist/checkout.d.ts",
62
+ "import": "./dist/checkout.mjs",
63
+ "require": "./dist/checkout.cjs"
64
+ },
65
+ "./react": {
66
+ "types": "./dist/react.d.ts",
67
+ "import": "./dist/react.mjs",
68
+ "require": "./dist/react.cjs"
59
69
  }
60
70
  },
71
+ "peerDependencies": {
72
+ "react": "^18.0.0 || ^19.0.0"
73
+ },
74
+ "peerDependenciesMeta": {
75
+ "react": { "optional": true }
76
+ },
61
77
  "sideEffects": false,
62
78
  "scripts": {
63
79
  "build": "tsup",