@opengeni/api-router 3.2.2 → 3.4.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.
Files changed (45) hide show
  1. package/dist/access-grant-rls.d.ts +15 -0
  2. package/dist/app.js +1 -1
  3. package/dist/billing-stripe-customer.d.ts +18 -0
  4. package/dist/billing-subscription-store.d.ts +34 -0
  5. package/dist/billing-subscriptions.d.ts +64 -0
  6. package/dist/{chunk-PQBHZ2YH.js → chunk-6DZ4H5JQ.js} +3133 -1711
  7. package/dist/{chunk-PQBHZ2YH.js.map → chunk-6DZ4H5JQ.js.map} +1 -1
  8. package/dist/index.js +4 -2
  9. package/dist/index.js.map +1 -1
  10. package/dist/integrations/marketplace-plugin.d.ts +43 -43
  11. package/dist/mcp/server.d.ts +11 -1
  12. package/dist/routes/browser-sessions.d.ts +23 -2
  13. package/dist/routes/sessions.d.ts +1 -0
  14. package/dist/sandbox/channel-a.d.ts +10 -1
  15. package/dist/site-publishing/agent-data-tools.d.ts +5 -5
  16. package/dist/site-publishing/agent-session.d.ts +3 -2
  17. package/dist/site-publishing/runtime.d.ts +7 -6
  18. package/dist/site-publishing/service.d.ts +8 -11
  19. package/dist/site-publishing/session-request-authority.d.ts +3 -0
  20. package/package.json +24 -24
  21. package/src/access-grant-rls.ts +99 -10
  22. package/src/app.ts +105 -43
  23. package/src/billing-stripe-customer.ts +40 -0
  24. package/src/billing-subscription-store.ts +121 -0
  25. package/src/billing-subscriptions.ts +759 -0
  26. package/src/http/sse.ts +5 -1
  27. package/src/index.ts +3 -0
  28. package/src/mcp/action-catalog.gen.ts +113 -0
  29. package/src/mcp/action-schema-imports.gen.ts +5 -1
  30. package/src/mcp/server.ts +28 -0
  31. package/src/routes/billing.ts +161 -21
  32. package/src/routes/browser-sessions.ts +420 -26
  33. package/src/routes/computer-sessions.ts +102 -39
  34. package/src/routes/insights-usage.ts +22 -0
  35. package/src/routes/organization-memberships.ts +12 -0
  36. package/src/routes/sessions.ts +30 -5
  37. package/src/routes/site-runtime.ts +62 -20
  38. package/src/sandbox/channel-a.ts +18 -1
  39. package/src/sandbox/metrics-ingestion.ts +1 -0
  40. package/src/site-frame-guard.ts +11 -2
  41. package/src/site-publishing/agent-data-tools.ts +16 -8
  42. package/src/site-publishing/agent-session.ts +24 -6
  43. package/src/site-publishing/runtime.ts +29 -7
  44. package/src/site-publishing/service.ts +65 -77
  45. package/src/site-publishing/session-request-authority.ts +14 -0
@@ -7,4 +7,19 @@ import { type CreditDebitAttribution } from "@opengeni/db";
7
7
  * resolved through the validated middleware context installed below.
8
8
  */
9
9
  export declare function creditDebitAttributionForGrant(grant: AccessGrant): CreditDebitAttribution;
10
+ /**
11
+ * Start `work` alongside an authorization `gate` instead of after it, so a
12
+ * request pays one database wait for both. The gate still decides: when it
13
+ * refuses, its error is the answer and `work`'s result or failure is dropped
14
+ * unread. Only use this for reads whose result is disclosed after the gate.
15
+ */
16
+ export declare function alongsideAuthorization<G, W>(gate: Promise<G>, work: () => Promise<W>): Promise<[G, W]>;
10
17
  export declare function withAccessGrantSessionRlsContext<T>(deps: Pick<ApiRouteDeps, "db">, grant: AccessGrant, fn: () => Promise<T>): Promise<T>;
18
+ /**
19
+ * Prove that an agent-attempt grant is the exact live attempt of its bound
20
+ * session, with the same refusal as {@link withAccessGrantSessionRlsContext},
21
+ * without installing that request's RLS actor context. For requests that read
22
+ * and disclose nothing scoped (MCP protocol handshakes), so they need the
23
+ * liveness fence but none of the actor's data scope.
24
+ */
25
+ export declare function requireLiveAgentAttemptGrant(deps: Pick<ApiRouteDeps, "db">, grant: AccessGrant): Promise<void>;
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-6DZ4H5JQ.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
+ }