Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

fix(ramp): remove the sandbox environment switch (#1933)

Brad Barbinbae43c12f516
diff --git a/.claude/rules/ramp-integration.md b/.claude/rules/ramp-integration.md
index 126817c585..b5c89e0c10 100644
--- a/.claude/rules/ramp-integration.md
+++ b/.claude/rules/ramp-integration.md
@@ -150,8 +150,8 @@ providers, which own the data and mirror it out.
`"true"`). Renders `SetupInstructions` with the webhook URL
`${origin}/api/webhook/ramp/${companyId}` — **see "The webhook route" below.**
- **Client** — `lib/client.ts`: `RampClient` over the Ramp Developer API v1. Host is
- `https://api.ramp.com` (production) or `https://demo-api.ramp.com` (sandbox), chosen
- from `credentials.environment`. `client_credentials` grant mints/caches a bearer token
+ `https://api.ramp.com` (`RAMP_HOST`) — production only; there is no sandbox switch.
+ `client_credentials` grant mints/caches a bearer token
(`POST /developer/v1/token`, Basic auth, re-mint under 60s remaining). `oauth2` exchanges
authorization codes and refreshes within the same margin; `buildRampClient` supplies the
Carbon OAuth app plus an `onTokensRefreshed` callback that atomically persists the new
@@ -1039,9 +1039,10 @@ correctness guarantee**; the webhook is latency only.
- **One active connection per company.** The metadata carries a single `connectionId` /
`webhookId`; `ensureRampConnection` creates one connection (`remote_provider_name:
"Carbon"`) and reuses it — there is no multi-connection support.
-- **Sandbox** = `demo-api.ramp.com` (`RAMP_SANDBOX_HOST`) for a stored legacy
- `client_credentials` record. The current Connect UI creates production OAuth records and
- exposes no environment selector.
+- **Production only.** The sandbox (`demo-api.ramp.com`) switch and the stored
+ `credentials.environment` field were removed; every client talks to `api.ramp.com`. An
+ install connected while the switch was on holds demo tokens that production rejects —
+ reconnect it (the OAuth patch also drops the stale `credentials.environment` key).
- **API uncertainties remain source-marked**: the draft-bill payload/submit identity,
repayment funding beyond documented `ach`, all-connections/accounts endpoints, and the
webhook challenge/signing contract. Bill payment methods and reimbursement states use
diff --git a/apps/erp/app/routes/api+/integrations.ramp.oauth.test.ts b/apps/erp/app/routes/api+/integrations.ramp.oauth.test.ts
index 9faf7072cc..228a06d980 100644
--- a/apps/erp/app/routes/api+/integrations.ramp.oauth.test.ts
+++ b/apps/erp/app/routes/api+/integrations.ramp.oauth.test.ts
@@ -79,8 +79,7 @@ const credentials = {
type: "oauth2",
accessToken: "new-access",
refreshToken: "new-refresh",
- expiresAt: "2026-09-11T13:00:00.000Z",
- environment: "production"
+ expiresAt: "2026-09-11T13:00:00.000Z"
};
async function callbackRequest(
diff --git a/apps/erp/app/routes/x+/settings+/integrations.$id.tsx b/apps/erp/app/routes/x+/settings+/integrations.$id.tsx
index 976ebc8ca4..bb3b200a45 100644
--- a/apps/erp/app/routes/x+/settings+/integrations.$id.tsx
+++ b/apps/erp/app/routes/x+/settings+/integrations.$id.tsx
@@ -233,7 +233,7 @@ function unfoldRilletCredentials(
function foldRampCredentials(
metadata: Record<string, unknown>
): Record<string, unknown> {
- const { clientId, clientSecret, environment, ...rest } = metadata;
+ const { clientId, clientSecret, ...rest } = metadata;
if (typeof clientId !== "string" || clientId.length === 0) return metadata;
return {
@@ -241,17 +241,16 @@ function foldRampCredentials(
credentials: {
type: "client_credentials",
clientId,
- clientSecret: typeof clientSecret === "string" ? clientSecret : "",
- environment: environment === "sandbox" ? "sandbox" : "production"
+ clientSecret: typeof clientSecret === "string" ? clientSecret : ""
}
};
}
/**
* Inverse of `foldRampCredentials`: unfold the stored
- * `metadata.credentials` back into the flat clientId/clientSecret/environment
- * fields the settings form binds to, so the drawer prefills instead of showing
- * blanks (which a re-save would then persist over the real stored connection).
+ * `metadata.credentials` back into the flat clientId/clientSecret fields the
+ * settings form binds to, so the drawer prefills instead of showing blanks
+ * (which a re-save would then persist over the real stored connection).
* The clientSecret is vaulted and stripped from the plaintext metadata, so it
* reads back empty — the masked field left blank means "keep the vaulted value".
*/
@@ -271,9 +270,7 @@ function unfoldRampCredentials(
clientSecret:
typeof credentials.clientSecret === "string"
? credentials.clientSecret
- : "",
- environment:
- credentials.environment === "sandbox" ? "sandbox" : "production"
+ : ""
};
}
diff --git a/packages/ee/src/ramp/config.tsx b/packages/ee/src/ramp/config.tsx
index 21fdbc2218..0634823bb7 100644
--- a/packages/ee/src/ramp/config.tsx
+++ b/packages/ee/src/ramp/config.tsx
@@ -8,7 +8,6 @@ import { isBrowser } from "@carbon/utils";
import type { ComponentProps } from "react";
import { z } from "zod";
import { defineIntegration } from "../fns";
-import { RAMP_AUTHORIZE_URL, RAMP_TOKEN_URL } from "./environment";
// Client-bundle safe: `modes` value-imports only the pure `spend/types` leaf;
// everything else it touches is type-only and erased.
import {
@@ -19,19 +18,22 @@ import {
import { RAMP_OAUTH_SCOPES, RAMP_PUSH_ONLY_OAUTH_SCOPES } from "./scopes";
/**
- * OAuth "Connect to Ramp" authorization-code flow — the ONLY way to connect
- * Ramp. The authorize/token hosts come from `./environment` (a browser-safe
- * module, not `./lib/client`, which pulls `node:crypto` into the client
- * bundle), which carries the TEMPORARY sandbox/production switch used for
- * customer testing. `offline_access` requests a refresh token; the app must
- * have the Refresh Token grant enabled. IntegrationCard builds the authorize
- * redirect from this block.
+ * OAuth "Connect to Ramp" authorization-code flow (production) — the ONLY way to
+ * connect Ramp. Declared inline (not imported from `./lib/client`, which pulls
+ * `node:crypto` into the client bundle). `offline_access` requests a refresh
+ * token; the app must have the Refresh Token grant enabled. IntegrationCard
+ * builds the authorize redirect from this block.
*/
+// The user-consent authorize endpoint lives on the APP host (app.ramp.com), NOT
+// the API host — hitting api.ramp.com/v1/authorize returns "Not Authorized" from
+// the API gateway before any consent screen. The token exchange DOES stay on the
+// API host (api.ramp.com/developer/v1/token).
+const RAMP_AUTHORIZE_URL = "https://app.ramp.com/v1/authorize";
+const RAMP_TOKEN_URL = "https://api.ramp.com/developer/v1/token";
/**
* Ramp settings form schema. Connection is exclusively via the "Connect to Ramp"
- * OAuth flow — the callback stores `metadata.credentials` (oauth2), pinned to
- * production — so the form carries NO client credentials. It only holds the
+ * OAuth flow — the callback stores `metadata.credentials` (oauth2) — so the form carries NO client credentials. It only holds the
* optional entity scope, the account mapping, and the sync toggles, all flat at
* the metadata root.
*/
diff --git a/packages/ee/src/ramp/environment.ts b/packages/ee/src/ramp/environment.ts
deleted file mode 100644
index cb1f0ab9ae..0000000000
--- a/packages/ee/src/ramp/environment.ts
+++ /dev/null
@@ -1,40 +0,0 @@
-// SPDX-License-Identifier: LicenseRef-Carbon-Commercial
-// Carbon Enterprise file, licensed only under the Carbon Commercial License
-// (packages/ee/LICENSE). Not AGPL. Running, modifying, or copying it beyond those terms requires a commercial license.
-
-/**
- * TEMPORARY hard switch between the Ramp sandbox (demo) and production
- * environments, for testing the integration with a customer. There is NO env
- * var by design — flip this one constant and redeploy, then set it back to
- * "production" when testing is done.
- *
- * While set to "sandbox", point the RAMP_CLIENT_ID / RAMP_CLIENT_SECRET env
- * vars at your Ramp *demo* OAuth app's credentials — the sandbox is a separate
- * Ramp OAuth app, so the production app's id/secret will NOT authorize against
- * it. The stored `credentials.environment` (stamped by `exchangeRampOAuthCode`)
- * carries this choice through to every subsequent Ramp API call and token
- * refresh, so `RampClient` talks to demo-api.ramp.com automatically.
- *
- * This module is browser-safe (no node imports) so both the client-bundled
- * `config.tsx` and the server `connection.ts` share the one switch.
- */
-export type RampEnvironment = "production" | "sandbox";
-
-export const RAMP_ENVIRONMENT: RampEnvironment = "sandbox";
-
-const IS_SANDBOX = RAMP_ENVIRONMENT === "sandbox";
-
-/**
- * User-consent (authorize) endpoint. Lives on the APP host, NOT the API host —
- * hitting the api host's /v1/authorize returns "Not Authorized" before any
- * consent screen. Production: app.ramp.com. Sandbox/demo: demo.ramp.com. (If
- * the sandbox consent screen 404s, this demo host is the value to adjust.)
- */
-export const RAMP_AUTHORIZE_URL = IS_SANDBOX
- ? "https://demo.ramp.com/v1/authorize"
- : "https://app.ramp.com/v1/authorize";
-
-/** Token-exchange endpoint — on the API host. */
-export const RAMP_TOKEN_URL = IS_SANDBOX
- ? "https://demo-api.ramp.com/developer/v1/token"
- : "https://api.ramp.com/developer/v1/token";
diff --git a/packages/ee/src/ramp/hooks.server.test.ts b/packages/ee/src/ramp/hooks.server.test.ts
index f428ca51c3..5c103fe0c6 100644
--- a/packages/ee/src/ramp/hooks.server.test.ts
+++ b/packages/ee/src/ramp/hooks.server.test.ts
@@ -39,8 +39,7 @@ import { rampOnInstall, rampOnUpdate } from "./hooks.server";
const credentials = {
type: "oauth2" as const,
- accessToken: "access-token",
- environment: "production" as const
+ accessToken: "access-token"
};
function integration(metadata: Record<string, unknown>) {
diff --git a/packages/ee/src/ramp/lib/__tests__/client.test.ts b/packages/ee/src/ramp/lib/__tests__/client.test.ts
index fdab71f8c8..d43af802b8 100644
--- a/packages/ee/src/ramp/lib/__tests__/client.test.ts
+++ b/packages/ee/src/ramp/lib/__tests__/client.test.ts
@@ -13,8 +13,7 @@ import {
const credentials: RampCredentials = {
type: "client_credentials",
clientId: "ramp-client",
- clientSecret: "ramp-secret",
- environment: "sandbox"
+ clientSecret: "ramp-secret"
};
/** Minimal Response stand-in exercising only the fields RampClient reads. */
@@ -125,7 +124,7 @@ describe("RampClient OAuth (authorization code + refresh)", () => {
vi.stubGlobal("fetch", fetchMock);
const client = new RampClient(
- { type: "oauth2", accessToken: "", environment: "production" },
+ { type: "oauth2", accessToken: "" },
{ oauthApp }
);
const tokens = await client.exchangeAuthorizationCode(
@@ -166,8 +165,7 @@ describe("RampClient OAuth (authorization code + refresh)", () => {
type: "oauth2",
accessToken: "stale-access",
refreshToken: "the-refresh",
- expiresAt: new Date(Date.now() - 1000).toISOString(),
- environment: "production"
+ expiresAt: new Date(Date.now() - 1000).toISOString()
},
{
oauthApp,
@@ -205,8 +203,7 @@ describe("RampClient OAuth (authorization code + refresh)", () => {
type: "oauth2",
accessToken: "valid-access",
refreshToken: "the-refresh",
- expiresAt: new Date(Date.now() + 3_600_000).toISOString(),
- environment: "production"
+ expiresAt: new Date(Date.now() + 3_600_000).toISOString()
},
{ oauthApp }
);
@@ -223,8 +220,7 @@ describe("RampClient OAuth (authorization code + refresh)", () => {
const client = new RampClient({
type: "oauth2",
accessToken: "stale",
- expiresAt: new Date(Date.now() - 1000).toISOString(),
- environment: "production"
+ expiresAt: new Date(Date.now() - 1000).toISOString()
});
await expect(drain(client.listTransactions())).rejects.toThrow(
@@ -262,7 +258,7 @@ describe("RampClient rate limiting", () => {
describe("RampClient pagination", () => {
it("follows page.next twice then stops", async () => {
const nextUrl =
- "https://demo-api.ramp.com/developer/v1/transactions?start=cursor&page_size=100";
+ "https://api.ramp.com/developer/v1/transactions?start=cursor&page_size=100";
let dataCalls = 0;
const fetchMock = vi.fn(async (url: unknown) => {
if (isTokenRequest(url)) {
diff --git a/packages/ee/src/ramp/lib/__tests__/models.test.ts b/packages/ee/src/ramp/lib/__tests__/models.test.ts
index 0f169c635c..84068b46d3 100644
--- a/packages/ee/src/ramp/lib/__tests__/models.test.ts
+++ b/packages/ee/src/ramp/lib/__tests__/models.test.ts
@@ -8,8 +8,7 @@ import { RampIntegrationMetadataSchema } from "../models";
// Minimal oauth2 credentials — the shape a fresh "Connect to Ramp" install stores.
const credentials = {
type: "oauth2" as const,
- accessToken: "token",
- environment: "production" as const
+ accessToken: "token"
};
describe("RampIntegrationMetadataSchema — flat sync flags → runtime sync", () => {
diff --git a/packages/ee/src/ramp/lib/__tests__/state.test.ts b/packages/ee/src/ramp/lib/__tests__/state.test.ts
index fa9cc069ca..818bb0a6df 100644
--- a/packages/ee/src/ramp/lib/__tests__/state.test.ts
+++ b/packages/ee/src/ramp/lib/__tests__/state.test.ts
@@ -75,8 +75,7 @@ describe("Ramp integration state patches", () => {
type: "oauth2",
accessToken: "access-1",
refreshToken: "refresh-1",
- expiresAt: "2026-09-11T13:00:00.000Z",
- environment: "production"
+ expiresAt: "2026-09-11T13:00:00.000Z"
},
updatedBy: "user-1"
});
@@ -86,14 +85,13 @@ describe("Ramp integration state patches", () => {
expect.objectContaining({
p_metadata_patch: {
"credentials.type": "oauth2",
- "credentials.expiresAt": "2026-09-11T13:00:00.000Z",
- "credentials.environment": "production"
+ "credentials.expiresAt": "2026-09-11T13:00:00.000Z"
},
p_secret_patch: {
"credentials.accessToken": "access-1",
"credentials.refreshToken": "refresh-1"
},
- p_metadata_remove: ["credentials.clientId"],
+ p_metadata_remove: ["credentials.clientId", "credentials.environment"],
p_secret_remove: ["credentials.clientSecret"],
p_active: true,
p_updated_by: "user-1"
@@ -107,8 +105,7 @@ describe("Ramp integration state patches", () => {
await patchRampOAuthCredentials(client, "company-1", {
credentials: {
type: "oauth2",
- accessToken: "access-1",
- environment: "production"
+ accessToken: "access-1"
},
updatedBy: "user-1"
});
@@ -117,10 +114,13 @@ describe("Ramp integration state patches", () => {
"upsert_company_integration_patch",
expect.objectContaining({
p_metadata_patch: {
- "credentials.type": "oauth2",
- "credentials.environment": "production"
+ "credentials.type": "oauth2"
},
- p_metadata_remove: ["credentials.clientId", "credentials.expiresAt"],
+ p_metadata_remove: [
+ "credentials.clientId",
+ "credentials.environment",
+ "credentials.expiresAt"
+ ],
p_secret_remove: [
"credentials.clientSecret",
"credentials.refreshToken"
diff --git a/packages/ee/src/ramp/lib/client.ts b/packages/ee/src/ramp/lib/client.ts
index da97dacda5..8e1db93860 100644
--- a/packages/ee/src/ramp/lib/client.ts
+++ b/packages/ee/src/ramp/lib/client.ts
@@ -16,18 +16,13 @@ import {
RampVendorSchema
} from "./models";
-export const RAMP_PRODUCTION_HOST = "https://api.ramp.com";
-export const RAMP_SANDBOX_HOST = "https://demo-api.ramp.com";
+export const RAMP_HOST = "https://api.ramp.com";
// The canonical scope lists live in the browser-safe `../scopes` module so the
// client-bundled `config.tsx` can share them without importing this file (which
// pulls `node:crypto`). Re-exported here to preserve the public contract.
export { RAMP_OAUTH_SCOPES, RAMP_SCOPES } from "../scopes";
-/** Ramp OAuth authorize endpoints (production / sandbox). */
-export const RAMP_PRODUCTION_AUTHORIZE_URL = `${RAMP_PRODUCTION_HOST}/v1/authorize`;
-export const RAMP_SANDBOX_AUTHORIZE_URL = `${RAMP_SANDBOX_HOST}/v1/authorize`;
-
/** Re-mint a client-credentials token when fewer than this many ms remain. */
const TOKEN_REFRESH_MARGIN_MS = 60_000;
@@ -116,10 +111,7 @@ export class RampClient {
private readonly credentials: RampCredentials,
private readonly options: RampClientOptions = {}
) {
- this.host =
- credentials.environment === "sandbox"
- ? RAMP_SANDBOX_HOST
- : RAMP_PRODUCTION_HOST;
+ this.host = RAMP_HOST;
if (credentials.type === "oauth2") {
this.oauthAccessToken = credentials.accessToken;
this.oauthExpiresAt = credentials.expiresAt
diff --git a/packages/ee/src/ramp/lib/connection.ts b/packages/ee/src/ramp/lib/connection.ts
index f5319f876f..dd9ae17f07 100644
--- a/packages/ee/src/ramp/lib/connection.ts
+++ b/packages/ee/src/ramp/lib/connection.ts
@@ -6,7 +6,6 @@ import type { Database } from "@carbon/database";
import { getLogger } from "@carbon/logger";
import type { SupabaseClient } from "@supabase/supabase-js";
import { resolveIntegrationSecrets } from "../../integrations/secrets";
-import { RAMP_ENVIRONMENT } from "../environment";
import { buildRampIdempotencyKey, RampClient } from "./client";
import {
CARBON_PROVIDER_NAME,
@@ -191,12 +190,9 @@ export async function getRampIntegration(
/**
* Exchange an OAuth authorization code (the Connect-flow callback) for oauth2
- * credentials, using Carbon's registered Ramp OAuth app. The returned
- * credentials are stamped with `RAMP_ENVIRONMENT` (the TEMPORARY sandbox/
- * production switch in `../environment`) so every subsequent Ramp API call and
- * token refresh hits the matching host. The caller stores these via the atomic
- * Ramp OAuth patch (which vaults the access + refresh tokens) and then runs
- * `rampOnInstall`.
+ * credentials, using Carbon's registered Ramp OAuth app. The caller stores
+ * these via the atomic Ramp OAuth patch (which vaults the access + refresh
+ * tokens) and then runs `rampOnInstall`.
*/
export async function exchangeRampOAuthCode(
code: string,
@@ -221,11 +217,10 @@ export async function exchangeRampOAuthCode(
"Ramp OAuth is not configured (set RAMP_CLIENT_ID / RAMP_CLIENT_SECRET)"
);
}
- // A placeholder access token just to construct the client; the exchange uses
- // the OAuth app credentials + the environment's host (the token POST goes to
- // `${host}/developer/v1/token`, so the environment must be set here too).
+ // A placeholder access token just to construct the client; the exchange only
+ // uses the OAuth app credentials.
const client = new RampClient(
- { type: "oauth2", accessToken: "", environment: RAMP_ENVIRONMENT },
+ { type: "oauth2", accessToken: "" },
{ oauthApp: { clientId, clientSecret } }
);
const tokens = await client.exchangeAuthorizationCode(code, redirectUri);
@@ -234,8 +229,7 @@ export async function exchangeRampOAuthCode(
type: "oauth2",
accessToken: tokens.accessToken,
refreshToken: tokens.refreshToken,
- expiresAt: tokens.expiresAt,
- environment: RAMP_ENVIRONMENT
+ expiresAt: tokens.expiresAt
},
grantedScopes: tokens.scope?.split(" ").filter(Boolean)
};
diff --git a/packages/ee/src/ramp/lib/models.ts b/packages/ee/src/ramp/lib/models.ts
index 235f1f14a3..19d9390e08 100644
--- a/packages/ee/src/ramp/lib/models.ts
+++ b/packages/ee/src/ramp/lib/models.ts
@@ -383,16 +383,12 @@ export type RampSyncResult = z.infer<typeof RampSyncResultSchema>;
// * Credentials *
// \********************************************************/
-export const RampEnvironmentSchema = z.enum(["production", "sandbox"]);
-export type RampEnvironment = z.infer<typeof RampEnvironmentSchema>;
-
export const RampCredentialsSchema = z.discriminatedUnion("type", [
z
.object({
type: z.literal("client_credentials"),
clientId: z.string(),
- clientSecret: z.string(),
- environment: RampEnvironmentSchema
+ clientSecret: z.string()
})
.passthrough(),
z
@@ -400,8 +396,7 @@ export const RampCredentialsSchema = z.discriminatedUnion("type", [
type: z.literal("oauth2"),
accessToken: z.string(),
refreshToken: z.string().optional(),
- expiresAt: z.string().optional(),
- environment: RampEnvironmentSchema
+ expiresAt: z.string().optional()
})
.passthrough()
]);
diff --git a/packages/ee/src/ramp/lib/state.ts b/packages/ee/src/ramp/lib/state.ts
index eecfd91a41..1f6b788b08 100644
--- a/packages/ee/src/ramp/lib/state.ts
+++ b/packages/ee/src/ramp/lib/state.ts
@@ -99,8 +99,7 @@ export async function patchRampOAuthCredentials(
"credentials.accessToken": credentials.accessToken
};
const metadata: Record<string, Json | undefined> = {
- "credentials.type": credentials.type,
- "credentials.environment": credentials.environment
+ "credentials.type": credentials.type
};
if (args.syncMode) metadata.syncMode = args.syncMode;
if (args.grantedScopes) metadata.grantedScopes = args.grantedScopes;
@@ -108,7 +107,9 @@ export async function patchRampOAuthCredentials(
metadata.accountingConnectionProvider = args.accountingConnectionProvider;
}
- const removeMetadata = ["credentials.clientId"];
+ // `credentials.environment` is the retired sandbox/production stamp; a
+ // reconnect clears it from installs made while the sandbox switch was live.
+ const removeMetadata = ["credentials.clientId", "credentials.environment"];
const removeSecrets = ["credentials.clientSecret"];
if (credentials.expiresAt) {
metadata["credentials.expiresAt"] = credentials.expiresAt;
diff --git a/packages/jobs/src/inngest/functions/integrations/ramp-sync-card.integration.test.ts b/packages/jobs/src/inngest/functions/integrations/ramp-sync-card.integration.test.ts
index b28ad6ef67..24cc4613fa 100644
--- a/packages/jobs/src/inngest/functions/integrations/ramp-sync-card.integration.test.ts
+++ b/packages/jobs/src/inngest/functions/integrations/ramp-sync-card.integration.test.ts
@@ -323,8 +323,7 @@ describe.skipIf(!runDatabaseTests)("Ramp card staging (Postgres)", () => {
credentials: {
type: "client_credentials",
clientId: "integration-test",
- clientSecret: "integration-test",
- environment: "sandbox"
+ clientSecret: "integration-test"
},
sync: {
pullTransactions: true,
@@ -447,8 +446,7 @@ describe.skipIf(!runDatabaseTests)("Ramp card staging (Postgres)", () => {
credentials: {
type: "client_credentials",
clientId: "integration-test",
- clientSecret: "integration-test",
- environment: "sandbox"
+ clientSecret: "integration-test"
},
sync: {
pullTransactions: true,