Skip to content

Commit 4f6eec0

Browse files
committed
feat(common): APPEX-204 add api support for testing
1 parent 9690ad2 commit 4f6eec0

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lib/auth.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
import * as jwt from 'jsonwebtoken';
22
import { NextApiRequest } from 'next';
33
import * as BigCommerce from 'node-bigcommerce';
4-
import { QueryParams, SessionContextProps, SessionProps } from '../types';
4+
import { ApiConfig, QueryParams, SessionContextProps, SessionProps } from '../types';
55
import db from './db';
66

7-
const { AUTH_CALLBACK, CLIENT_ID, CLIENT_SECRET, JWT_KEY } = process.env;
7+
const { API_URL, AUTH_CALLBACK, CLIENT_ID, CLIENT_SECRET, JWT_KEY, LOGIN_URL } = process.env;
8+
9+
// Used for internal configuration; 3rd party apps may remove
10+
const apiConfig: ApiConfig = {};
11+
if (API_URL && LOGIN_URL) {
12+
apiConfig.apiUrl = API_URL;
13+
apiConfig.loginUrl = LOGIN_URL;
14+
}
815

916
// Create BigCommerce instance
1017
// https://github.com/bigcommerce/node-bigcommerce/
@@ -16,6 +23,7 @@ const bigcommerce = new BigCommerce({
1623
responseType: 'json',
1724
headers: { 'Accept-Encoding': '*' },
1825
apiVersion: 'v3',
26+
...apiConfig,
1927
});
2028

2129
const bigcommerceSigned = new BigCommerce({
@@ -30,6 +38,7 @@ export function bigcommerceClient(accessToken: string, storeHash: string, apiVer
3038
storeHash,
3139
responseType: 'json',
3240
apiVersion,
41+
...apiConfig,
3342
});
3443
}
3544

types/auth.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,8 @@ export interface SessionContextProps {
2424
export interface QueryParams {
2525
[key: string]: string | string[];
2626
}
27+
28+
export interface ApiConfig {
29+
apiUrl?: string;
30+
loginUrl?: string;
31+
}

0 commit comments

Comments
 (0)