@kerne/react 1.2.0 → 1.3.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
@@ -3,10 +3,10 @@ import React, { ReactNode, Component, ErrorInfo } from 'react';
3
3
  import { KerneConfig, ConsumeParams, ReportUsageParams, ReportUsageBatchEvent, BatchUsageResult, JoinWaitlistParams, ValidateTokenResponse, ValidateCodeResponse } from '@kerne/server';
4
4
  export { JoinWaitlistParams, ValidateCodeResponse, ValidateTokenResponse, WaitlistEntry } from '@kerne/server';
5
5
  import * as _kerne_types from '@kerne/types';
6
- import { User, AuthResponse, ActivationContext, AuthConfig, EntitlementCheck, UsageRecord, SubscriptionWithPlan, Subscription, PublicPlan, Entitlements, PublicPlanPrice } from '@kerne/types';
6
+ import { User, AuthResponse, ActivationContext, AuthConfig, EntitlementCheck, UsageRecord, DriverSelection, SubscriptionWithPlan, Subscription, PublicPlan, Entitlements, PublicPlanPrice } from '@kerne/types';
7
7
  export { ActivationContext, AuthConfig, AuthResponse, BatchUsageResult, EntitlementCheck, Entitlements, PublicPlan, Subscription, SubscriptionWithPlan, UsageRecord, User, ValidationFieldError } from '@kerne/types';
8
- import { D as DeepPartial, K as KerneLocalization } from './i18n-CXEhPK58.js';
9
- export { d as defaultLocalization } from './i18n-CXEhPK58.js';
8
+ import { D as DeepPartial, K as KerneLocalization, a as KerneAppearance } from './fr-E5mmylSH.js';
9
+ export { d as defaultLocalization, f as fr, m as mergeLocalization } from './fr-E5mmylSH.js';
10
10
 
11
11
  interface KerneReactConfig extends Omit<KerneConfig, 'secretKey'> {
12
12
  storage?: Storage;
@@ -119,14 +119,14 @@ declare class KerneClient {
119
119
  /** Soft-deletes (deactivates) the caller's own account, then clears the local session. */
120
120
  requestAccountDeletion(): Promise<void>;
121
121
  /** Forgot-password flow (logged out) - sends the reset email. */
122
- requestPasswordReset(email: string, callbackUrl?: string): Promise<void>;
122
+ requestPasswordReset(email: string): Promise<void>;
123
123
  /** Confirms a password reset with the token from the email. */
124
124
  confirmPasswordReset(token: string, password: string): Promise<void>;
125
125
  /**
126
126
  * Sends a magic-link email (logged out). Anti-enumeration: always resolves,
127
127
  * regardless of whether the email is registered.
128
128
  */
129
- startPasswordless(email: string, callbackUrl?: string, invitation?: {
129
+ startPasswordless(email: string, invitation?: {
130
130
  invitationToken?: string;
131
131
  invitationCode?: string;
132
132
  }): Promise<void>;
@@ -173,16 +173,10 @@ declare class KerneClient {
173
173
  /** Several usage events in one request instead of one call each - kills the manual request staggering. */
174
174
  reportUsageBatch(events: Array<Omit<ReportUsageBatchEvent, 'subject'>>): Promise<BatchUsageResult[]>;
175
175
  private requireUserId;
176
- createCheckout(planPriceId: string, options?: {
177
- successUrl?: string;
178
- cancelUrl?: string;
179
- }): Promise<string>;
180
- openCheckout(planPriceId: string, options?: {
181
- successUrl?: string;
182
- cancelUrl?: string;
183
- }): Promise<void>;
184
- createPortal(returnUrl?: string): Promise<string>;
185
- openPortal(returnUrl?: string): Promise<void>;
176
+ createCheckout(planPriceId: string, drivers?: DriverSelection[]): Promise<string>;
177
+ openCheckout(planPriceId: string, drivers?: DriverSelection[]): Promise<void>;
178
+ createPortal(): Promise<string>;
179
+ openPortal(): Promise<void>;
186
180
  getSubscription(productSlug?: string): Promise<SubscriptionWithPlan | null>;
187
181
  /** `immediately: true` ends it now; otherwise cancels at period end (API default). */
188
182
  cancelSubscription(subscriptionId: string, immediately?: boolean): Promise<Subscription>;
@@ -203,7 +197,7 @@ declare class KerneClient {
203
197
  validateInvitationToken(token: string): Promise<ValidateTokenResponse>;
204
198
  /** Validate an invitation code before showing the registration form. */
205
199
  validateInvitationCode(code: string): Promise<ValidateCodeResponse>;
206
- sendVerificationEmail(verificationType?: 'code' | 'link', callbackUrl?: string): Promise<void>;
200
+ sendVerificationEmail(verificationType?: 'code' | 'link'): Promise<void>;
207
201
  verifyEmailWithCode(code: string): Promise<{
208
202
  success: boolean;
209
203
  needsTokenRefresh: boolean;
@@ -229,8 +223,14 @@ interface KerneProviderProps extends KerneReactConfig {
229
223
  * override keeps everything it does not mention.
230
224
  */
231
225
  localization?: DeepPartial<KerneLocalization>;
226
+ /**
227
+ * Appearance for every prebuilt component, set once. A host with its own dark
228
+ * mode would otherwise pass it to each one and keep them in sync by hand; a
229
+ * component's own `appearance` still wins, field by field.
230
+ */
231
+ appearance?: KerneAppearance;
232
232
  }
233
- declare function KerneProvider({ children, localization, ...config }: KerneProviderProps): react_jsx_runtime.JSX.Element;
233
+ declare function KerneProvider({ children, localization, appearance, ...config }: KerneProviderProps): react_jsx_runtime.JSX.Element;
234
234
 
235
235
  /**
236
236
  * Access the Kerne client instance
@@ -273,14 +273,14 @@ declare function useAuth(): {
273
273
  newPassword: string;
274
274
  }) => Promise<void>;
275
275
  requestAccountDeletion: () => Promise<void>;
276
- requestPasswordReset: (email: string, callbackUrl?: string) => Promise<void>;
276
+ requestPasswordReset: (email: string) => Promise<void>;
277
277
  confirmPasswordReset: (token: string, password: string) => Promise<void>;
278
- startPasswordless: (email: string, callbackUrl?: string, invitation?: {
278
+ startPasswordless: (email: string, invitation?: {
279
279
  invitationToken?: string;
280
280
  invitationCode?: string;
281
281
  }) => Promise<void>;
282
282
  loginWithMagicLink: (token: string) => Promise<_kerne_types.AuthResponse>;
283
- sendVerificationEmail: (verificationType?: "code" | "link", callbackUrl?: string) => Promise<void>;
283
+ sendVerificationEmail: (verificationType?: "code" | "link") => Promise<void>;
284
284
  verifyEmailWithCode: (code: string) => Promise<{
285
285
  success: boolean;
286
286
  needsTokenRefresh: boolean;
@@ -308,14 +308,8 @@ declare function useAuth(): {
308
308
  * ```
309
309
  */
310
310
  declare function useCheckout(): {
311
- createCheckout: (planPriceId: string, options?: {
312
- successUrl?: string;
313
- cancelUrl?: string;
314
- }) => Promise<string>;
315
- openCheckout: (planPriceId: string, options?: {
316
- successUrl?: string;
317
- cancelUrl?: string;
318
- }) => Promise<void>;
311
+ createCheckout: (planPriceId: string, drivers?: DriverSelection[]) => Promise<string>;
312
+ openCheckout: (planPriceId: string, drivers?: DriverSelection[]) => Promise<void>;
319
313
  };
320
314
  /**
321
315
  * Billing portal hook - lets a user manage their subscription/payment method.
@@ -327,8 +321,8 @@ declare function useCheckout(): {
327
321
  * ```
328
322
  */
329
323
  declare function usePortal(): {
330
- createPortal: (returnUrl?: string) => Promise<string>;
331
- openPortal: (returnUrl?: string) => Promise<void>;
324
+ createPortal: () => Promise<string>;
325
+ openPortal: () => Promise<void>;
332
326
  };
333
327
  /**
334
328
  * Cancels or changes the current scope's own subscription - JWT-scoped like every other hook
@@ -383,16 +377,13 @@ interface PlanSwitchTarget {
383
377
  * usePlanSwitch(subscription, refetch);
384
378
  * ```
385
379
  */
386
- declare function usePlanSwitch(subscription: SubscriptionWithPlan | null, refetchSubscription: () => void, options?: {
387
- successUrl?: string;
388
- cancelUrl?: string;
389
- }): {
380
+ declare function usePlanSwitch(subscription: SubscriptionWithPlan | null, refetchSubscription: () => void): {
390
381
  pending: PlanSwitchTarget | null;
391
382
  switching: boolean;
392
383
  switchError: unknown;
393
384
  checkoutPriceId: string | null;
394
385
  checkoutError: unknown;
395
- selectPlan: (plan: PublicPlan, price: PublicPlanPrice) => Promise<void>;
386
+ selectPlan: (plan: PublicPlan, price: PublicPlanPrice, drivers?: DriverSelection[]) => Promise<void>;
396
387
  confirmSwitch: () => Promise<void>;
397
388
  dismissSwitch: () => void;
398
389
  };
@@ -475,9 +466,13 @@ declare function useAuthConfig(): {
475
466
  };
476
467
  /**
477
468
  * Every entitlement for the current user in one call - for a "your plan"
478
- * screen. Use `useAccess` instead for a single feature - this response
479
- * never carries `allowed` (see docs: the list is cached, a stale verdict
480
- * would be unsafe).
469
+ * screen. `EntitlementSummary` carries no `allowed` field, on purpose: this
470
+ * list is a cached snapshot for display ("12/50 calls used"), not a live
471
+ * verdict. **Never gate access by reading `limit`/`remaining`/`enabled`
472
+ * yourself** - that silently reimplements override precedence, overage
473
+ * rules, and the race against concurrent usage that `useAccess()` already
474
+ * handles server-side. Use `useAccess()` (or `kerne.allows()`/`enforce()`)
475
+ * for every actual gate, and this hook only to render numbers.
481
476
  *
482
477
  * @example
483
478
  * ```tsx
package/dist/index.js CHANGED
@@ -4,6 +4,8 @@ import {
4
4
  KerneContext,
5
5
  KerneProvider,
6
6
  defaultLocalization,
7
+ fr,
8
+ mergeLocalization,
7
9
  useAccess,
8
10
  useAuth,
9
11
  useAuthConfig,
@@ -21,7 +23,7 @@ import {
21
23
  useUsage,
22
24
  useUser,
23
25
  useWaitlist
24
- } from "./chunk-IHNWY4ML.js";
26
+ } from "./chunk-ZVL47U4B.js";
25
27
 
26
28
  // src/components.tsx
27
29
  import React from "react";
@@ -81,6 +83,37 @@ function Protected({
81
83
  // src/error-boundary.tsx
82
84
  import React2, { Component } from "react";
83
85
  import { jsx as jsx2, jsxs } from "react/jsx-runtime";
86
+ var STYLE_ELEMENT_ID = "kerne-error-boundary-styles";
87
+ var CSS = `
88
+ .kerne-eb { padding: 24px; text-align: center; color: #16171a; }
89
+ .kerne-eb-title { font-size: 20px; font-weight: 600; letter-spacing: -.01em; margin: 0 0 8px; }
90
+ .kerne-eb-body { color: #6b7280; margin: 0 auto 20px; max-width: 40ch; font-size: 14px; line-height: 1.5; }
91
+ .kerne-eb-code { color: #6f7681; margin: -12px 0 20px; font-size: 12px; }
92
+ .kerne-eb-button {
93
+ font: inherit; font-size: 14px; font-weight: 500; height: 44px;
94
+ padding: 0 20px; border-radius: 8px; border: none; cursor: pointer;
95
+ background: #16171a; color: #fff;
96
+ transition: background-color .12s ease;
97
+ }
98
+ .kerne-eb-button:hover { background: #2c2e33; }
99
+ .kerne-eb-button:focus-visible { outline: 2px solid #16171a; outline-offset: 2px; }
100
+ @media (prefers-color-scheme: dark) {
101
+ .kerne-eb { color: #f0f1f3; }
102
+ .kerne-eb-body { color: #9ba2ad; }
103
+ .kerne-eb-code { color: #838b96; }
104
+ .kerne-eb-button { background: #f0f1f3; color: #16181d; }
105
+ .kerne-eb-button:hover { background: #d8dade; }
106
+ .kerne-eb-button:focus-visible { outline-color: #f0f1f3; }
107
+ }
108
+ `;
109
+ function ensureErrorBoundaryStylesInjected() {
110
+ if (typeof document === "undefined") return;
111
+ if (document.getElementById(STYLE_ELEMENT_ID)) return;
112
+ const style = document.createElement("style");
113
+ style.id = STYLE_ELEMENT_ID;
114
+ style.textContent = CSS;
115
+ document.head.appendChild(style);
116
+ }
84
117
  var KerneErrorBoundary = class extends Component {
85
118
  constructor(props) {
86
119
  super(props);
@@ -111,28 +144,15 @@ var KerneErrorBoundary = class extends Component {
111
144
  }
112
145
  return fallback;
113
146
  }
114
- return /* @__PURE__ */ jsxs("div", { style: { padding: "20px", textAlign: "center" }, children: [
115
- /* @__PURE__ */ jsx2("h2", { style: { color: "#dc2626", marginBottom: "10px" }, children: "Something went wrong" }),
116
- /* @__PURE__ */ jsx2("p", { style: { color: "#6b7280", marginBottom: "20px" }, children: error.message || "An unexpected error occurred" }),
117
- error.code && /* @__PURE__ */ jsxs("p", { style: { color: "#9ca3af", fontSize: "12px", marginBottom: "20px" }, children: [
147
+ ensureErrorBoundaryStylesInjected();
148
+ return /* @__PURE__ */ jsxs("div", { className: "kerne-eb", children: [
149
+ /* @__PURE__ */ jsx2("h2", { className: "kerne-eb-title", children: "Something went wrong" }),
150
+ /* @__PURE__ */ jsx2("p", { className: "kerne-eb-body", children: error.message || "An unexpected error occurred" }),
151
+ error.code && /* @__PURE__ */ jsxs("p", { className: "kerne-eb-code", children: [
118
152
  "Error code: ",
119
153
  error.code
120
154
  ] }),
121
- /* @__PURE__ */ jsx2(
122
- "button",
123
- {
124
- onClick: this.reset,
125
- style: {
126
- padding: "10px 20px",
127
- backgroundColor: "#3b82f6",
128
- color: "white",
129
- border: "none",
130
- borderRadius: "6px",
131
- cursor: "pointer"
132
- },
133
- children: "Try again"
134
- }
135
- )
155
+ /* @__PURE__ */ jsx2("button", { type: "button", className: "kerne-eb-button", onClick: this.reset, children: "Try again" })
136
156
  ] });
137
157
  }
138
158
  return this.props.children;
@@ -165,6 +185,8 @@ export {
165
185
  Protected,
166
186
  Unauthenticated,
167
187
  defaultLocalization,
188
+ fr,
189
+ mergeLocalization,
168
190
  useAccess,
169
191
  useAuth,
170
192
  useAuthConfig,