@opengeni/api-router 3.2.2 → 3.3.1-canary.38922642121001

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.
Files changed (40) hide show
  1. package/dist/app.js +1 -1
  2. package/dist/billing-stripe-customer.d.ts +18 -0
  3. package/dist/billing-subscription-store.d.ts +34 -0
  4. package/dist/billing-subscriptions.d.ts +64 -0
  5. package/dist/{chunk-PQBHZ2YH.js → chunk-YH3WMZRL.js} +2663 -1647
  6. package/dist/{chunk-PQBHZ2YH.js.map → chunk-YH3WMZRL.js.map} +1 -1
  7. package/dist/index.js +2 -1
  8. package/dist/index.js.map +1 -1
  9. package/dist/integrations/marketplace-plugin.d.ts +43 -43
  10. package/dist/mcp/scheduled-task-view.d.ts +4 -4
  11. package/dist/mcp/server.d.ts +1 -1
  12. package/dist/sandbox/channel-a.d.ts +10 -1
  13. package/dist/site-publishing/agent-data-tools.d.ts +5 -5
  14. package/dist/site-publishing/agent-session.d.ts +3 -2
  15. package/dist/site-publishing/runtime.d.ts +7 -6
  16. package/dist/site-publishing/service.d.ts +8 -11
  17. package/dist/site-publishing/session-request-authority.d.ts +3 -0
  18. package/package.json +24 -24
  19. package/src/access-grant-rls.ts +1 -0
  20. package/src/billing-stripe-customer.ts +40 -0
  21. package/src/billing-subscription-store.ts +121 -0
  22. package/src/billing-subscriptions.ts +759 -0
  23. package/src/http/sse.ts +5 -1
  24. package/src/mcp/action-catalog.gen.ts +75 -0
  25. package/src/mcp/action-schema-imports.gen.ts +4 -1
  26. package/src/routes/billing.ts +161 -21
  27. package/src/routes/browser-sessions.ts +61 -17
  28. package/src/routes/computer-sessions.ts +102 -39
  29. package/src/routes/insights-usage.ts +22 -0
  30. package/src/routes/organization-memberships.ts +12 -0
  31. package/src/routes/sessions.ts +22 -4
  32. package/src/routes/site-runtime.ts +62 -20
  33. package/src/sandbox/channel-a.ts +18 -1
  34. package/src/sandbox/metrics-ingestion.ts +1 -0
  35. package/src/site-frame-guard.ts +11 -2
  36. package/src/site-publishing/agent-data-tools.ts +16 -8
  37. package/src/site-publishing/agent-session.ts +24 -6
  38. package/src/site-publishing/runtime.ts +29 -7
  39. package/src/site-publishing/service.ts +65 -77
  40. package/src/site-publishing/session-request-authority.ts +14 -0
package/dist/app.js CHANGED
@@ -28,7 +28,7 @@ import {
28
28
  withDefaultEnabledCapabilityMcpTools,
29
29
  workflowIdForSession,
30
30
  workspaceActorContextExempt
31
- } from "./chunk-PQBHZ2YH.js";
31
+ } from "./chunk-YH3WMZRL.js";
32
32
  import "./chunk-OGQDXVXY.js";
33
33
  export {
34
34
  API_MAX_REQUEST_BODY_BYTES,
@@ -0,0 +1,18 @@
1
+ import type Stripe from "stripe";
2
+ export interface StripeCustomerTransaction {
3
+ read(): Promise<string | null>;
4
+ account(): Promise<{
5
+ name: string;
6
+ } | null>;
7
+ save(customer: Stripe.Customer): Promise<void>;
8
+ }
9
+ /** The adapter must hold the account advisory lock for this whole callback,
10
+ * including provider I/O and persistence. The stable provider key also recovers
11
+ * creation when Stripe succeeds but the database transaction rolls back. */
12
+ export declare function serializedStripeCustomer(input: {
13
+ stripe: Stripe;
14
+ accountId: string;
15
+ provider: string;
16
+ email?: string;
17
+ locked: (run: (tx: StripeCustomerTransaction) => Promise<string>) => Promise<string>;
18
+ }): Promise<string>;
@@ -0,0 +1,34 @@
1
+ import type { BillingPlanBalance, SubscriptionPlan } from "@opengeni/contracts";
2
+ import { type Database, type OrganizationPlanStateInput, type PlanCreditPeriodInput, type BillingSubscriptionOperation, type BillingSubscriptionOperationKind } from "@opengeni/db";
3
+ export type StoredSubscriptionPlan = {
4
+ plan_key: string;
5
+ stripe_subscription_id: string | null;
6
+ };
7
+ export interface SubscriptionAccountStore {
8
+ operation(key: string): Promise<BillingSubscriptionOperation | null>;
9
+ beginOperation(input: {
10
+ operationKey: string;
11
+ kind: BillingSubscriptionOperationKind;
12
+ request: Record<string, unknown>;
13
+ intent: Record<string, unknown>;
14
+ }): Promise<BillingSubscriptionOperation>;
15
+ completeOperation(key: string, result: Record<string, unknown>): Promise<void>;
16
+ exists(): Promise<boolean>;
17
+ state(): Promise<StoredSubscriptionPlan | null>;
18
+ customer(provider: string): Promise<string | null>;
19
+ balance(): Promise<BillingPlanBalance | null>;
20
+ save(input: Omit<OrganizationPlanStateInput, "accountId">): Promise<void>;
21
+ replace(input: Omit<PlanCreditPeriodInput, "accountId">): Promise<void>;
22
+ expire(subscriptionId: string): Promise<void>;
23
+ }
24
+ export interface SubscriptionStore {
25
+ catalog(): Promise<{
26
+ revision: number;
27
+ plans: SubscriptionPlan[];
28
+ }>;
29
+ locked<T>(accountId: string, run: (store: SubscriptionAccountStore) => Promise<T>): Promise<T>;
30
+ }
31
+ /** Reuse the SQL seams in one outer transaction, membership/org fence before
32
+ * the credit-account lock. Stripe reads also run under this fence: concurrent
33
+ * deliveries cannot commit an older provider snapshot after a newer one. */
34
+ export declare function subscriptionStore(db: Database): SubscriptionStore;
@@ -0,0 +1,64 @@
1
+ import type { BillingSubscriptionCatalog, BillingSubscriptionChange, SubscriptionPlan } from "@opengeni/contracts";
2
+ import Stripe from "stripe";
3
+ import type { SubscriptionStore } from "./billing-subscription-store.js";
4
+ /** Enterprise is assigned only by operators, never inferred from an embedder. */
5
+ export declare function selfServicePlan(plan: SubscriptionPlan): boolean;
6
+ export declare function subscriptionItem(subscription: Stripe.Subscription): Stripe.SubscriptionItem;
7
+ export declare function subscriptionCheckoutParams(input: {
8
+ accountId: string;
9
+ customerId: string;
10
+ priceId: string;
11
+ successUrl: string;
12
+ cancelUrl: string;
13
+ }): Stripe.Checkout.SessionCreateParams;
14
+ export declare function subscriptionWebhookEvent(event: Stripe.Event): boolean;
15
+ export declare class StripeSubscriptions {
16
+ private readonly stripe;
17
+ private readonly store;
18
+ private readonly enabled;
19
+ private readonly provider;
20
+ constructor(stripe: Stripe, store: SubscriptionStore, enabled: boolean, provider: "stripe:live" | "stripe:test");
21
+ private requireEnabled;
22
+ catalog(accountId: string): Promise<BillingSubscriptionCatalog>;
23
+ private paidPlan;
24
+ private subscriptions;
25
+ checkout(input: {
26
+ accountId: string;
27
+ customerId: string;
28
+ planKey: string;
29
+ idempotencyKey: string;
30
+ successUrl: string;
31
+ cancelUrl: string;
32
+ }): Promise<{
33
+ checkoutSessionId: string;
34
+ url: string;
35
+ }>;
36
+ private current;
37
+ /** Two independent commits are essential: provider success cannot roll back
38
+ * the immutable target when local reconciliation fails. Replays resolve the
39
+ * receipt before looking at the organization's current subscription/catalog. */
40
+ private mutate;
41
+ private providerMutation;
42
+ private intent;
43
+ private target;
44
+ private unchanged;
45
+ /** Stripe fails the entire update for an incomplete immediate payment. Only
46
+ * its paid invoice may replace the old allowance, never the update itself. */
47
+ upgrade(input: {
48
+ accountId: string;
49
+ planKey: string;
50
+ idempotencyKey: string;
51
+ }): Promise<BillingSubscriptionChange>;
52
+ change(input: {
53
+ accountId: string;
54
+ planKey: string;
55
+ idempotencyKey: string;
56
+ }): Promise<BillingSubscriptionChange>;
57
+ cancel(input: {
58
+ accountId: string;
59
+ idempotencyKey: string;
60
+ }): Promise<BillingSubscriptionChange>;
61
+ handleEvent(event: Stripe.Event): Promise<boolean>;
62
+ private synchronize;
63
+ private rejectDuplicate;
64
+ }