Skip to content

Commit 91c3ec9

Browse files
authored
Merge pull request #27 from Fullscript/entrypoint
feat(feature option): new feature option to navigate to Labs or Catalog page
2 parents 58a6b96 + e429e5a commit 91c3ec9

File tree

4 files changed

+119
-28
lines changed

4 files changed

+119
-28
lines changed

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module.exports = {
2626
"@typescript-eslint/ban-ts-comment": "off",
2727
"@typescript-eslint/explicit-function-return-type": "off",
2828
"@typescript-eslint/explicit-module-boundary-types": "error",
29-
"@typescript-eslint/no-unused-vars": "error",
29+
"@typescript-eslint/no-unused-vars": ["error", { varsIgnorePattern: "^_" }],
3030
"@typescript-eslint/no-use-before-define": "error",
3131
"@typescript-eslint/no-var-requires": "error",
3232
"@typescript-eslint/prefer-for-of": "error",

src/feature/featureType.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ const FEATURE_TYPES = {
55
platform: "platform",
66
};
77

8+
type Entrypoint = "catalog" | "labs";
9+
10+
const ENTRYPOINTS: Entrypoint[] = ["catalog", "labs"];
11+
812
type FeatureType = keyof typeof FEATURE_TYPES;
913

1014
type PatientOptions = {
@@ -19,9 +23,12 @@ type PatientOptions = {
1923
discount?: number;
2024
};
2125
type TreatmentPlanOptions = { patient?: PatientOptions; secretToken: string };
26+
type PlatformOptions = TreatmentPlanOptions & { entrypoint?: Entrypoint };
2227

23-
type FeatureOptions<F extends FeatureType> = F extends "treatmentPlan" | "platform"
28+
type FeatureOptions<F extends FeatureType> = F extends "treatmentPlan"
2429
? TreatmentPlanOptions
30+
: F extends "platform"
31+
? PlatformOptions
2532
: Record<any, never>;
2633

2734
interface Feature {
@@ -34,8 +41,10 @@ interface Feature {
3441
export {
3542
FeatureType,
3643
FeatureOptions,
44+
PlatformOptions,
3745
TreatmentPlanOptions,
3846
PatientOptions,
3947
Feature,
4048
FEATURE_TYPES,
49+
ENTRYPOINTS,
4150
};

src/feature/featureUtil.spec.ts

Lines changed: 92 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,34 +32,102 @@ describe("getFeatureUrl", () => {
3232
});
3333

3434
describe("feature type", () => {
35-
it("returns the proper url when the feature type is 'treatmentPlan'", async () => {
36-
const url = await getFeatureURL(
37-
"treatmentPlan",
38-
mockFeatureOptions,
39-
mockFullscriptOptions,
40-
mockFrameId
41-
);
35+
describe("the feature type is 'treatmentPlan'", () => {
36+
it("returns the proper url", async () => {
37+
const url = await getFeatureURL(
38+
"treatmentPlan",
39+
mockFeatureOptions,
40+
mockFullscriptOptions,
41+
mockFrameId
42+
);
4243

43-
expect(url).toEqual(
44-
`https://us-snd.fullscript.io/api/embeddable/session/treatment_plans/new?data_token=${encodeURIComponent(
45-
mockDataToken
46-
)}&secret_token=secretToken&public_key=publicKey&frame_id=uuid&target_origin=http://localhost`
47-
);
44+
expect(url).toEqual(
45+
`https://us-snd.fullscript.io/api/embeddable/session/treatment_plans/new?data_token=${encodeURIComponent(
46+
mockDataToken
47+
)}&secret_token=secretToken&public_key=publicKey&frame_id=uuid&target_origin=http://localhost`
48+
);
49+
});
50+
51+
it("doesn't add entrypoint to the url when entrypoint is given", async () => {
52+
const url = await getFeatureURL(
53+
"treatmentPlan",
54+
// @ts-expect-error
55+
{ ...mockFeatureOptions, entrypoint: "labs" },
56+
mockFullscriptOptions,
57+
mockFrameId
58+
);
59+
60+
expect(url).toEqual(
61+
`https://us-snd.fullscript.io/api/embeddable/session/treatment_plans/new?data_token=${encodeURIComponent(
62+
mockDataToken
63+
)}&secret_token=secretToken&public_key=publicKey&frame_id=uuid&target_origin=http://localhost`
64+
);
65+
});
4866
});
4967

50-
it("returns the proper url when the feature type is 'platform'", async () => {
51-
const url = await getFeatureURL(
52-
"platform",
53-
mockFeatureOptions,
54-
mockFullscriptOptions,
55-
mockFrameId
56-
);
68+
describe("the feature type is 'platform'", () => {
69+
it("returns the proper url", async () => {
70+
const url = await getFeatureURL(
71+
"platform",
72+
mockFeatureOptions,
73+
mockFullscriptOptions,
74+
mockFrameId
75+
);
5776

58-
expect(url).toEqual(
59-
`https://us-snd.fullscript.io/api/embeddable/session/embed/entry?data_token=${encodeURIComponent(
60-
mockDataToken
61-
)}&secret_token=secretToken&public_key=publicKey&frame_id=uuid&target_origin=http://localhost`
62-
);
77+
expect(url).toEqual(
78+
`https://us-snd.fullscript.io/api/embeddable/session/embed/entry?data_token=${encodeURIComponent(
79+
mockDataToken
80+
)}&secret_token=secretToken&public_key=publicKey&frame_id=uuid&target_origin=http://localhost`
81+
);
82+
});
83+
84+
describe("entrypoint", () => {
85+
it("adds labs entrypoint to the url when it is given", async () => {
86+
const url = await getFeatureURL(
87+
"platform",
88+
{ ...mockFeatureOptions, entrypoint: "labs" },
89+
mockFullscriptOptions,
90+
mockFrameId
91+
);
92+
93+
expect(url).toEqual(
94+
`https://us-snd.fullscript.io/api/embeddable/session/embed/entry?data_token=${encodeURIComponent(
95+
mockDataToken
96+
)}&secret_token=secretToken&entrypoint=labs&public_key=publicKey&frame_id=uuid&target_origin=http://localhost`
97+
);
98+
});
99+
100+
it("adds catalog entrypoint to the url when it is given", async () => {
101+
const url = await getFeatureURL(
102+
"platform",
103+
{ ...mockFeatureOptions, entrypoint: "catalog" },
104+
mockFullscriptOptions,
105+
mockFrameId
106+
);
107+
108+
expect(url).toEqual(
109+
`https://us-snd.fullscript.io/api/embeddable/session/embed/entry?data_token=${encodeURIComponent(
110+
mockDataToken
111+
)}&secret_token=secretToken&entrypoint=catalog&public_key=publicKey&frame_id=uuid&target_origin=http://localhost`
112+
);
113+
});
114+
115+
it("doesn't add entrypoint to the url when an invalid entrypoint is given", async () => {
116+
const url = await getFeatureURL(
117+
"platform",
118+
// @ts-expect-error
119+
{ ...mockFeatureOptions, entrypoint: "invalid" },
120+
mockFullscriptOptions,
121+
mockFrameId
122+
);
123+
124+
expect(url).toEqual(
125+
`https://us-snd.fullscript.io/api/embeddable/session/embed/entry?data_token=${encodeURIComponent(
126+
mockDataToken
127+
)}&secret_token=secretToken&public_key=publicKey&frame_id=uuid&target_origin=http://localhost`
128+
);
129+
});
130+
});
63131
});
64132
});
65133

src/feature/featureUtil.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,31 @@ import { validateFeatureType } from "../fullscriptJsValidator";
33
import { buildQueryString } from "../utils";
44

55
import { FEATURE_PATHS } from "./featurePath";
6-
import { FeatureType, FeatureOptions } from "./featureType";
6+
import { ENTRYPOINTS, FeatureType, FeatureOptions } from "./featureType";
77

8+
const getValidFeatureOptions = (
9+
featureType: FeatureType,
10+
featureOptions: FeatureOptions<FeatureType>
11+
) => {
12+
if ("entrypoint" in featureOptions) {
13+
if (featureType === "treatmentPlan" || !ENTRYPOINTS.includes(featureOptions.entrypoint)) {
14+
const { entrypoint: _removed, ...validOptions } = featureOptions;
15+
return validOptions;
16+
}
17+
}
18+
19+
return featureOptions;
20+
};
821
const getFeatureURL = async <F extends FeatureType>(
922
featureType: F,
1023
featureOptions: FeatureOptions<F>,
1124
fullscriptOptions: FullscriptOptions,
1225
frameId: string
1326
): Promise<string> => {
1427
const { publicKey, env, domain } = fullscriptOptions;
28+
1529
const queryString = await buildQueryString({
16-
...featureOptions,
30+
...getValidFeatureOptions(featureType, featureOptions),
1731
fullscriptOptions,
1832
publicKey,
1933
frameId,

0 commit comments

Comments
 (0)