Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/spicy-hosts-default.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@inflowpayai/inflow': patch
---

Default the production API base URL to `https://api.inflowpay.ai` for data endpoints, while OAuth/device auth keeps
using `https://app.inflowpay.ai`. A single `INFLOW_BASE_URL` (or `apiBaseUrl`) override still redirects both hosts, so
pointing the CLI at another environment stays a one-variable change.
21 changes: 17 additions & 4 deletions packages/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ export interface ResolvedInflowSdkConfig {
type AuthMode = ResolvedInflowSdkConfig['authMode'];

/** @internal */
export const ENVIRONMENT_BASE_URLS: Record<InflowEnvironment, string> = {
export const ENVIRONMENT_API_BASE_URLS: Record<InflowEnvironment, string> = {
production: 'https://api.inflowpay.ai',
sandbox: 'https://sandbox.inflowpay.ai',
};

/** @internal */
export const ENVIRONMENT_AUTH_BASE_URLS: Record<InflowEnvironment, string> = {
production: 'https://app.inflowpay.ai',
sandbox: 'https://sandbox.inflowpay.ai',
};
Expand All @@ -58,7 +64,9 @@ export const ENVIRONMENT_BASE_URLS: Record<InflowEnvironment, string> = {
*/
export function resolveApiBaseUrl(options: Pick<InflowOptions, 'apiBaseUrl' | 'environment'>): string {
return (
options.apiBaseUrl ?? process.env['INFLOW_BASE_URL'] ?? ENVIRONMENT_BASE_URLS[options.environment ?? 'production']
options.apiBaseUrl ??
process.env['INFLOW_BASE_URL'] ??
ENVIRONMENT_API_BASE_URLS[options.environment ?? 'production']
);
}

Expand Down Expand Up @@ -139,9 +147,14 @@ export function resolveInflowSdkConfig(options: InflowOptions = {}): ResolvedInf
const logger = options.logger ?? createDefaultLogger(verbose);
const environment: InflowEnvironment = options.environment ?? 'production';

const apiBaseUrl = options.apiBaseUrl ?? process.env['INFLOW_BASE_URL'] ?? ENVIRONMENT_BASE_URLS[environment];
const explicitApiBaseUrl = options.apiBaseUrl ?? process.env['INFLOW_BASE_URL'];
const apiBaseUrl = explicitApiBaseUrl ?? ENVIRONMENT_API_BASE_URLS[environment];

const authBaseUrl = options.authBaseUrl ?? process.env['INFLOW_AUTH_BASE_URL'] ?? apiBaseUrl;
const authBaseUrl =
options.authBaseUrl ??
process.env['INFLOW_AUTH_BASE_URL'] ??
explicitApiBaseUrl ??
ENVIRONMENT_AUTH_BASE_URLS[environment];

const cliClientId = options.cliClientId ?? process.env['INFLOW_CLI_CLIENT_ID'];

Expand Down
9 changes: 8 additions & 1 deletion packages/core/test/unit/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('resolveInflowSdkConfig', () => {
it('defaults environment to production and apiBaseUrl', () => {
const c = resolveInflowSdkConfig();
expect(c.environment).toBe('production');
expect(c.apiBaseUrl).toBe('https://app.inflowpay.ai');
expect(c.apiBaseUrl).toBe('https://api.inflowpay.ai');
expect(c.authBaseUrl).toBe('https://app.inflowpay.ai');
expect(c.clientName).toBe('InFlow');
});
Expand All @@ -46,6 +46,13 @@ describe('resolveInflowSdkConfig', () => {
expect(c.authBaseUrl).toBe('https://opt');
});

it('INFLOW_BASE_URL alone redirects both apiBaseUrl and authBaseUrl', () => {
process.env['INFLOW_BASE_URL'] = 'https://dev.inflowpay.ai';
const c = resolveInflowSdkConfig();
expect(c.apiBaseUrl).toBe('https://dev.inflowpay.ai');
expect(c.authBaseUrl).toBe('https://dev.inflowpay.ai');
});

it('authBaseUrl env overrides default', () => {
process.env['INFLOW_AUTH_BASE_URL'] = 'https://auth.test';
const c = resolveInflowSdkConfig();
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/unit/flows/inflow-flows.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ describe('Inflow augmented surface', () => {

it('resolvedApiBaseUrl defaults to the environment-derived URL when no explicit apiBaseUrl is set', () => {
const prodClient = new Inflow({ environment: 'production' });
expect(prodClient.resolvedApiBaseUrl).toBe('https://app.inflowpay.ai');
expect(prodClient.resolvedApiBaseUrl).toBe('https://api.inflowpay.ai');
const sandboxClient = new Inflow({ environment: 'sandbox' });
expect(sandboxClient.resolvedApiBaseUrl).toBe('https://sandbox.inflowpay.ai');
});
Expand Down
Loading