@lukoweb/apitogo-plugin-dev-portal-billing 0.2.31 → 0.2.35

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.
@@ -0,0 +1,37 @@
1
+ import { _ as rateLimitCell, g as quotaCell } from "./useDevPortalApiBaseUrl-CgygF2z5.mjs";
2
+
3
+ //#region src/utils/billing-state.ts
4
+ /** Whether the pricing page has no plans to show yet because the answer is still on its way. */
5
+ function isPricingLoading(state) {
6
+ if (state.isPreview) return state.authPending && !state.hasPlans;
7
+ if (state.plansLoading) return true;
8
+ return state.authPending && !state.hasPlans && !state.plansFailed;
9
+ }
10
+ /**
11
+ * The line shown on the billing page while the subscription is being confirmed after checkout. A free plan has no
12
+ * payment, so it must not claim one; the paid return from the payment provider carries no marker and says so.
13
+ */
14
+ function checkoutConfirmingText(paid) {
15
+ return paid ? "Payment received. Confirming your subscription, this takes a few seconds…" : "Confirming your subscription, this takes a few seconds…";
16
+ }
17
+ /** Query parameter the checkout page adds when it returns from a plan that needs no payment. */
18
+ const FREE_CHECKOUT_MARKER = "paid=0";
19
+ /**
20
+ * The rows of the "Compare plans" table. Rows the tenant wrote in config win. Otherwise the rows come from the plans'
21
+ * own limits (request quota and rate limit), and a row nobody has a value for is left out. Sample rows are for the
22
+ * preview (no backend, no plans) only: a live project without data shows no table rather than made-up numbers.
23
+ */
24
+ function buildCompareRows(input) {
25
+ if (input.configuredRows && input.configuredRows.length > 0) return input.configuredRows;
26
+ if (input.plans.length === 0) return input.isPreview ? input.sampleRows : [];
27
+ return [{
28
+ label: "Request quota",
29
+ values: input.plans.map((plan) => quotaCell(plan.limitsJson) ?? "—")
30
+ }, {
31
+ label: "Rate limit",
32
+ values: input.plans.map((plan) => rateLimitCell(plan.limitsJson) ?? "—")
33
+ }].filter((row) => row.values.some((value) => value !== "—"));
34
+ }
35
+
36
+ //#endregion
37
+ export { isPricingLoading as i, buildCompareRows as n, checkoutConfirmingText as r, FREE_CHECKOUT_MARKER as t };
@@ -0,0 +1,65 @@
1
+ //#region src/utils/demo-session.ts
2
+ const DEMO_SUBSCRIPTION_KEY = "demo-subscription-key";
3
+ const DEMO_GATEWAY_KEY_HEADER = "Ocp-Apim-Subscription-Key";
4
+ const DEMO_MAX_KEYS = 5;
5
+ function resolveDemoPlans(plans) {
6
+ if (plans && plans.length > 0) return plans.map((plan) => ({
7
+ sku: plan.sku,
8
+ displayName: plan.displayName
9
+ }));
10
+ return [{
11
+ sku: "free",
12
+ displayName: "Free"
13
+ }];
14
+ }
15
+ function createDemoMeResponse(plans) {
16
+ const periodEnd = /* @__PURE__ */ new Date();
17
+ periodEnd.setMonth(periodEnd.getMonth() + 1);
18
+ return {
19
+ userId: "00000000-0000-0000-0000-000000000001",
20
+ displayName: "Demo User",
21
+ email: "demo@example.com",
22
+ emailVerified: true,
23
+ hasNativePassword: true,
24
+ subscriptions: resolveDemoPlans(plans).map((plan) => ({
25
+ planSku: plan.sku,
26
+ status: "Active",
27
+ entitlementState: "active",
28
+ currentPeriodEnd: periodEnd.toISOString()
29
+ }))
30
+ };
31
+ }
32
+ function createDemoCredentials(plans) {
33
+ return {
34
+ idToken: "demo-id-token",
35
+ accessToken: null,
36
+ gatewayBaseUrl: null,
37
+ planSkus: resolveDemoPlans(plans).map((plan) => plan.sku),
38
+ expiresAt: null
39
+ };
40
+ }
41
+ function createDemoApiKeys(plans) {
42
+ return {
43
+ plans: resolveDemoPlans(plans).map((plan, index) => ({
44
+ planSku: plan.sku,
45
+ displayName: plan.displayName,
46
+ keys: index === 0 ? [{
47
+ id: "00000000-0000-0000-0000-0000000000a1",
48
+ name: "default",
49
+ keyPrefix: DEMO_SUBSCRIPTION_KEY.slice(0, 8),
50
+ status: "active",
51
+ createdAtUtc: (/* @__PURE__ */ new Date()).toISOString(),
52
+ revokedAtUtc: null,
53
+ key: null
54
+ }] : [],
55
+ activeCount: index === 0 ? 1 : 0,
56
+ maxKeys: DEMO_MAX_KEYS,
57
+ canCreate: true
58
+ })),
59
+ header: DEMO_GATEWAY_KEY_HEADER,
60
+ gatewayBaseUrl: null
61
+ };
62
+ }
63
+
64
+ //#endregion
65
+ export { createDemoCredentials as n, createDemoMeResponse as r, createDemoApiKeys as t };
package/dist/index.d.mts CHANGED
@@ -41,7 +41,8 @@ type DevPortalBillingConfig = {
41
41
  subtitle?: string;
42
42
  compareRows?: DevPortalPricingCompareRow[];
43
43
  faqs?: DevPortalPricingFaq[];
44
- }; /** Live gateway URL (publish bake or explicit plugin option). */
44
+ }; /** Address of the plans backend; the portal's generated wrapper passes it. The plans request starts from it early. */
45
+ apiBaseUrl?: string; /** Live gateway URL (publish bake or explicit plugin option). */
45
46
  gatewayBaseUrl?: string | null; /** Local preview plan catalog (from `apitogo.config.json` `plans`). */
46
47
  previewPlans?: Array<{
47
48
  sku: string;