@kontrolia/shared 1.1.0 → 1.2.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/types.d.ts CHANGED
@@ -24,7 +24,7 @@ export interface KontroliaMembershipWithOrganization extends KontroliaMembership
24
24
  organization: KontroliaOrganization;
25
25
  }
26
26
  /**
27
- * Shape of the custom claims injected by kontrolia.custom_access_token_hook
27
+ * Shape of the custom claims injected by kontrolia_auth.custom_access_token_hook
28
28
  * (see packages/db/migrations/0007_custom_access_token_hook.sql), plus the
29
29
  * standard GoTrue claims every Supabase-issued access token already carries
30
30
  * (`email`, `user_metadata`) — present under the top-level JWT claims,
@@ -41,12 +41,20 @@ export interface KontroliaTokenClaims {
41
41
  permissions: string[];
42
42
  /**
43
43
  * True for a user granted platform-admin status (see
44
- * kontrolia.platform_admins) — a reserved claim outside the app
44
+ * kontrolia_auth.platform_admins) — a reserved claim outside the app
45
45
  * permission-key namespace, for support/ops tooling that needs to see
46
46
  * across every organization instead of just the active one. Not
47
47
  * something an app's own role/permission catalog can grant.
48
48
  */
49
49
  is_platform_admin?: boolean;
50
+ /**
51
+ * `{ "<application slug>": "<plan slug>" }` for every live subscription
52
+ * of the active organization. Informational (show "Plan Pro" without a
53
+ * round trip) — the actual gate is that `permissions` above is already
54
+ * intersected with the plan for applications that require one. Limits
55
+ * and usage are never in the token; see KontroliaEntitlements.
56
+ */
57
+ plans?: Record<string, string>;
50
58
  exp: number;
51
59
  email?: string | null;
52
60
  user_metadata?: {
@@ -67,4 +75,71 @@ export interface KontroliaInvitation {
67
75
  }
68
76
  /** A single "resource.action" permission key, e.g. "facturacion.facturas.crear". */
69
77
  export type PermissionKey = string;
78
+ export type KontroliaBillingInterval = "month" | "year" | "one_time";
79
+ export type KontroliaLimitPeriod = "day" | "month" | "year" | "lifetime";
80
+ export type KontroliaSubscriptionStatus = "trialing" | "active" | "past_due" | "canceled" | "expired";
81
+ export interface KontroliaPlanLimit {
82
+ key: string;
83
+ /** null = unlimited. */
84
+ limit: number | null;
85
+ period: KontroliaLimitPeriod;
86
+ description: string | null;
87
+ }
88
+ /** A commercial tier of an application, as an app shows it on its pricing screen. */
89
+ export interface KontroliaPlan {
90
+ id: string;
91
+ applicationId: string;
92
+ slug: string;
93
+ name: string;
94
+ description: string | null;
95
+ /** Minor units (centavos/cents). */
96
+ priceAmount: number;
97
+ currency: string;
98
+ billingInterval: KontroliaBillingInterval;
99
+ trialDays: number;
100
+ features: string[];
101
+ isDefault: boolean;
102
+ isActive: boolean;
103
+ sortOrder: number;
104
+ /** Permission keys this plan unlocks. */
105
+ permissions: string[];
106
+ limits: KontroliaPlanLimit[];
107
+ }
108
+ export interface KontroliaSubscription {
109
+ id: string;
110
+ organizationId: string;
111
+ applicationId: string;
112
+ planId: string;
113
+ planSlug: string;
114
+ planName: string;
115
+ status: KontroliaSubscriptionStatus;
116
+ /** Whether it currently grants access (active/trialing, or past_due inside the grace window). */
117
+ isLive: boolean;
118
+ currentPeriodStart: string | null;
119
+ currentPeriodEnd: string | null;
120
+ cancelAtPeriodEnd: boolean;
121
+ provider: "manual" | "stripe";
122
+ }
123
+ export interface KontroliaUsage extends KontroliaPlanLimit {
124
+ used: number;
125
+ /** null when the limit is unlimited. */
126
+ remaining: number | null;
127
+ periodStart: string;
128
+ }
129
+ /**
130
+ * What the caller's active organization is entitled to in one application:
131
+ * its live plan (if any), why access might be blocked, the permissions that
132
+ * survive the role ∩ plan intersection, and every limit with its current
133
+ * usage.
134
+ */
135
+ export interface KontroliaEntitlements {
136
+ applicationId: string;
137
+ applicationSlug: string;
138
+ plansRequired: boolean;
139
+ subscription: KontroliaSubscription | null;
140
+ /** "ok" when access is granted; otherwise why not. */
141
+ access: "ok" | "no_subscription" | "past_due" | "canceled" | "expired";
142
+ permissions: string[];
143
+ usage: KontroliaUsage[];
144
+ }
70
145
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":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OAAO,CAAC;IAChB,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,iBAAiB,EAAE,OAAO,CAAC;IAC3B,QAAQ,EAAE,QAAQ,GAAG,QAAQ,CAAC;CAC/B;AAED,MAAM,WAAW,cAAe,SAAQ,kBAAkB;IACxD,IAAI,EAAE,MAAM,CAAC;IACb,wCAAwC;IACxC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;;;GAKG;AACH,MAAM,WAAW,qBAAqB;IACpC,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,aAAa,EAAE,OAAO,CAAC;IACvB,YAAY,EAAE,qBAAqB,GAAG,IAAI,CAAC;IAC3C,sDAAsD;IACtD,MAAM,EAAE,IAAI,GAAG,iBAAiB,GAAG,UAAU,GAAG,UAAU,GAAG,SAAS,CAAC;IACvE,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,KAAK,EAAE,cAAc,EAAE,CAAC;CACzB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kontrolia/shared",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "license": "MIT",
5
5
  "description": "Shared TypeScript types and utilities used across every KontrolIA Auth package and app.",
6
6
  "keywords": [