Skip to content

Commit

Permalink
TPA-4677: Add in base url and override url for testing purposes.
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonMRojas authored and JasonMRojas committed Jul 28, 2024
1 parent a684de1 commit e44ad44
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 77 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,6 @@ In the spirit of creating a seemless process we will also be forgoing the verifi

Make sure to bump the version of the `package.json` with each release.

Develop APIToken `49d492e0-9772-4975-8d1e-17f0ad8f2de0` not for actual customer use.
Develop APIToken `49d492e0-9772-4975-8d1e-17f0ad8f2de0` not for actual customer use.

On init you can pass in _overrideBaseUrl for development sandbox as well.
18 changes: 13 additions & 5 deletions assets/sdk/entries/sdk.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { render } from 'react-dom';
import SDK from '../components/sdk';
import $ from 'jquery';

let version = '0.7.0';
let version = '0.7.1';

function uuidv4() {
return '10000000-1000-4000-8000-100000000000'.replace(/[018]/g, c =>
Expand Down Expand Up @@ -48,7 +48,8 @@ const affirmInstance = ({
doneRealTime,
doneEasyEnroll,
handleFormErrors,
handleInitErrors
handleInitErrors,
_overrideBaseUrl
}) => {
const sdkPropParsed = {
el: typeof el == 'string',
Expand Down Expand Up @@ -101,7 +102,11 @@ const affirmInstance = ({
doneRealTime: typeof doneRealTime == 'function',
doneEasyEnroll: typeof doneEasyEnroll == 'function',
handleFormErrors: typeof handleFormErrors == 'function',
handleInitErrors: typeof handleInitErrors == 'function'
handleInitErrors: typeof handleInitErrors == 'function',
_overrideBaseUrl: _overrideBaseUrl
? typeof _overrideBaseUrl == 'string' &&
_overrideBaseUrl.includes('/sdk-api')
: true
};

for (const key in sdkPropParsed) {
Expand Down Expand Up @@ -155,7 +160,8 @@ const StreamConnect = ({
doneRealTime = () => {},
doneEasyEnroll = () => {},
handleFormErrors = () => {},
handleInitErrors = () => {}
handleInitErrors = () => {},
_overrideBaseUrl = ''
}) => {
const configuredCorrectly = affirmInstance({
el,
Expand Down Expand Up @@ -190,7 +196,8 @@ const StreamConnect = ({
doneRealTime,
doneEasyEnroll,
handleFormErrors,
handleInitErrors
handleInitErrors,
_overrideBaseUrl
});

if (!configuredCorrectly) {
Expand Down Expand Up @@ -252,6 +259,7 @@ const StreamConnect = ({
version={version}
sdkStateId={sdkStateId}
maxRetries={Math.round(realtimeTimeout / 5)}
_overrideBaseUrl={_overrideBaseUrl}
/>,
document.querySelector(el)
);
Expand Down
9 changes: 3 additions & 6 deletions assets/shared/requests/enter-credentials.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@ export const postCredentials = async ({
try {
response = policyHolderId
? await sdkAxios.put(
`https://app.tpastream.com/sdk-api/policy_holder_sdk/policy_holder/${policyHolderId}`,
`policy_holder_sdk/policy_holder/${policyHolderId}`,
params
)
: await sdkAxios.post(
'https://app.tpastream.com/sdk-api/policy_holder_sdk/policy_holder',
params
);
: await sdkAxios.post('policy_holder_sdk/policy_holder', params);
} catch (error) {
handleFormErrors(error, {
response: error.response,
Expand All @@ -41,7 +38,7 @@ export const getPolicyHolder = async ({
email
}) => {
const policyHolderResponse = await sdkAxios.get(
`https://app.tpastream.com/sdk-api/policy_holder_sdk/policy_holder/${policyHolderId}`,
`policy_holder_sdk/policy_holder/${policyHolderId}`,
{
params: {
employer_id: employerId,
Expand Down
11 changes: 4 additions & 7 deletions assets/shared/requests/fix-credentials.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { sdkAxios } from '../services/axios';

export const getFixCredentials = async ({ email }) => {
const fixCredentialsResponse = await sdkAxios.get(
`https://app.tpastream.com/sdk-api/fix-credentials`,
{
params: {
email: email
}
const fixCredentialsResponse = await sdkAxios.get(`fix-credentials`, {
params: {
email: email
}
);
});
return fixCredentialsResponse.data.data;
};
20 changes: 7 additions & 13 deletions assets/shared/requests/interop.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
import { sdkAxios } from '../services/axios';

export const beginInterop = async ({ email }) => {
const interopStateResponse = await sdkAxios.post(
'https://app.tpastream.com/sdk-api/interop',
{
user_email: email
}
);
const interopStateResponse = await sdkAxios.post('interop', {
user_email: email
});
return interopStateResponse.data.data;
};

export const getInteropState = async ({ email }) => {
const interopStateResponse = await sdkAxios.get(
'https://app.tpastream.com/sdk-api/interop',
{
params: {
email: email
}
const interopStateResponse = await sdkAxios.get('interop', {
params: {
email: email
}
);
});
return interopStateResponse.data.data;
};
13 changes: 5 additions & 8 deletions assets/shared/requests/payer.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { sdkAxios } from '../services/axios';

export const getPayer = async ({ email, employerId, payerId, referer }) => {
const payerResponse = await sdkAxios.get(
`https://app.tpastream.com/sdk-api/payer/${employerId}/${payerId}`,
{
params: {
email: email,
referer: referer
}
const payerResponse = await sdkAxios.get(`payer/${employerId}/${payerId}`, {
params: {
email: email,
referer: referer
}
);
});
return payerResponse.data.data;
};
29 changes: 12 additions & 17 deletions assets/shared/requests/sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,19 @@ export const getSDK = async ({ employer, user, isDemo, doneGetSDK }) => {
let sdkResponse = {};
try {
if (isDemo) {
sdkResponse = await sdkAxios.get(
'https://app.tpastream.com/sdk-api/tpastream_sdk'
);
sdkResponse = await sdkAxios.get('tpastream_sdk');
} else {
sdkResponse = await sdkAxios.post(
'https://app.tpastream.com/sdk-api/tpastream_sdk',
{
system_key: employer.systemKey,
vendor: employer.vendor,
employer_name: employer.name,
user_first_name: user.firstName,
user_last_name: user.lastName,
user_email: user.email,
phone_number: user.phoneNumber,
member_system_key: user.memberSystemKey,
date_of_birth: user.dateOfBirth
}
);
sdkResponse = await sdkAxios.post('tpastream_sdk', {
system_key: employer.systemKey,
vendor: employer.vendor,
employer_name: employer.name,
user_first_name: user.firstName,
user_last_name: user.lastName,
user_email: user.email,
phone_number: user.phoneNumber,
member_system_key: user.memberSystemKey,
date_of_birth: user.dateOfBirth
});
}
const data = {
user: sdkResponse.data.data.user,
Expand Down
22 changes: 8 additions & 14 deletions assets/shared/requests/terms.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
import { sdkAxios } from '../services/axios';

export const getTerms = async ({ email }) => {
const termsResponse = await sdkAxios.get(
`https://app.tpastream.com/sdk-api/terms_of_service`,
{
params: {
email: email
}
const termsResponse = await sdkAxios.get(`terms_of_service`, {
params: {
email: email
}
);
});
return termsResponse.data.data.html_string;
};

export const getTermsText = async ({ email }) => {
const termsResponse = await sdkAxios.get(
`https://app.tpastream.com/sdk-api/terms_of_service`,
{
params: {
email: email
}
const termsResponse = await sdkAxios.get(`terms_of_service`, {
params: {
email: email
}
);
});
return termsResponse.data.data.text;
};
4 changes: 2 additions & 2 deletions assets/shared/requests/validate-credentials.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const validateCredentials = async ({
email
}) => {
const validateCredsResponse = await sdkAxios.get(
`https://app.tpastream.com/sdk-api/validate-credentials/${policyHolderId}/${taskId}`,
`validate-credentials/${policyHolderId}/${taskId}`,
{
params: {
email: email
Expand All @@ -18,7 +18,7 @@ export const validateCredentials = async ({

export const putTask = async ({ taskId, policyHolderId, params }) => {
const validateCredsResponse = await sdkAxios.put(
`https://app.tpastream.com/sdk-api/validate-credentials/${policyHolderId}/${taskId}`,
`validate-credentials/${policyHolderId}/${taskId}`,
params
);
return validateCredsResponse.data.data;
Expand Down
4 changes: 3 additions & 1 deletion assets/shared/services/axios.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ const sdkAxiosMaker = ({
version,
isDemo,
sdkStateId,
tenant
tenant,
_overrideBaseUrl
}) => {
sdkAxios = axios.create({
baseURL: _overrideBaseUrl || 'https://app.tpastream.com/sdk-api',
crossdomain: true,
headers: {
'X-TPAStream-Token': apiToken,
Expand Down
27 changes: 27 additions & 0 deletions assets/tests/axios.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,31 @@ it("Test sdkAxiosMaker no tenant", () => {
expect(sdkAxios.defaults.headers['X-TPAStream-Token']).toBe('test-token')
expect(sdkAxios.defaults.headers['X-Tenant-Label']).toBe(undefined)
expect(sdkAxios.defaults.headers['X-Tenant-Key']).toBe(undefined)
// Check baseURL after sdkAxiosMaker call
expect(sdkAxios.defaults.baseURL).toBe('https://app.tpastream.com/sdk-api');
});


it("Test sdkAxiosMaker no tenant override url", () => {
expect(sdkAxios.defaults.headers['X-Is-Demo']).toBe('0')
expect(sdkAxios.defaults.headers['X-SDK-Version']).toBe('testVersion')
expect(sdkAxios.defaults.headers['X-TPAStream-Token']).toBe('test-token')
expect(sdkAxios.defaults.headers['X-Tenant-Label']).toBe(undefined)
expect(sdkAxios.defaults.headers['X-Tenant-Key']).toBe(undefined)

sdkAxiosMaker({
apiToken: 'test-token',
version: 'testVersion',
isDemo: false,
tenant: undefined,
_overrideBaseUrl: 'https://override-url.com/sdk-api'
});

expect(sdkAxios.defaults.headers['X-Is-Demo']).toBe('0')
expect(sdkAxios.defaults.headers['X-SDK-Version']).toBe('testVersion')
expect(sdkAxios.defaults.headers['X-TPAStream-Token']).toBe('test-token')
expect(sdkAxios.defaults.headers['X-Tenant-Label']).toBe(undefined)
expect(sdkAxios.defaults.headers['X-Tenant-Key']).toBe(undefined)
// Check baseURL after sdkAxiosMaker call
expect(sdkAxios.defaults.baseURL).toBe('https://override-url.com/sdk-api');
});
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stream-connect-sdk",
"version": "0.7.0",
"version": "0.7.1",
"description": "A JavaScript SDK implementing TPAStream's Connect Platform",
"scripts": {
"build": "webpack --config webpack.prod-sdk.js --mode=production",
Expand Down

0 comments on commit e44ad44

Please sign in to comment.