@workleap/mixpanel 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/createTrackingFunction.d.ts +11 -3
- package/dist/createTrackingFunction.js +8 -13
- package/dist/createTrackingFunction.js.map +1 -1
- package/dist/env.d.ts +4 -0
- package/dist/env.js +33 -0
- package/dist/env.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
- package/src/createTrackingFunction.ts +16 -10
- package/src/env.ts +27 -0
- package/src/index.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @workleap/mixpanel
|
|
2
2
|
|
|
3
|
+
## 1.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#8](https://github.com/workleap/wl-tracking/pull/8) [`5199dc1`](https://github.com/workleap/wl-tracking/commit/5199dc1cce5d9ab05c0cda84be2ac81cdf6a9456) Thanks [@alexasselin008](https://github.com/alexasselin008)! - Add the possibility to specify only the environment to use, and the tracking function will provide the correct URL
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- [#6](https://github.com/workleap/wl-tracking/pull/6) [`e26a764`](https://github.com/workleap/wl-tracking/commit/e26a764282f881b4ab50009db1f88879e8a02776) Thanks [@alexasselin008](https://github.com/alexasselin008)! - Export types from the packages
|
|
12
|
+
|
|
13
|
+
## 1.0.2
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- [#4](https://github.com/workleap/wl-tracking/pull/4) [`3430c6d`](https://github.com/workleap/wl-tracking/commit/3430c6dc2ccf381a96f8d1d03e7f695670d9e9d2) Thanks [@alexasselin008](https://github.com/alexasselin008)! - Added cjs entry point to our package
|
|
18
|
+
|
|
3
19
|
## 1.0.1
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type Environment } from "./env.ts";
|
|
1
2
|
import { type TrackEventProperties } from "./properties.ts";
|
|
2
3
|
export interface TrackingOptions {
|
|
3
4
|
/**
|
|
@@ -19,7 +20,7 @@ export interface TrackingOptions {
|
|
|
19
20
|
* @param options Options for tracking the event.
|
|
20
21
|
*/
|
|
21
22
|
export type TrackingFunction = (eventName: string, properties: TrackEventProperties, options?: TrackingOptions) => Promise<void>;
|
|
22
|
-
interface CreateTrackingFunctionOptions {
|
|
23
|
+
export interface CreateTrackingFunctionOptions {
|
|
23
24
|
/**
|
|
24
25
|
* The product identifier of the target product.
|
|
25
26
|
* @default null
|
|
@@ -29,9 +30,16 @@ interface CreateTrackingFunctionOptions {
|
|
|
29
30
|
/**
|
|
30
31
|
* Creates a function that sends tracking events to the tracking API.
|
|
31
32
|
* @param productId Your product identifier. e.g. "wlp", "ov"
|
|
32
|
-
* @param
|
|
33
|
+
* @param env The environment to get the navigation url from . e.g. "local", "prod"
|
|
34
|
+
* @param createOptions Options for creating the tracking function.
|
|
35
|
+
* @returns A function that sends tracking events to the tracking API.
|
|
36
|
+
*/
|
|
37
|
+
export declare function createTrackingFunction(productId: string, env: Environment, createOptions?: CreateTrackingFunctionOptions): TrackingFunction;
|
|
38
|
+
/**
|
|
39
|
+
* Creates a function that sends tracking events to the tracking API.
|
|
40
|
+
* @param productId Your product identifier. e.g. "wlp", "ov"
|
|
41
|
+
* @param trackingApiBaseUrl The base Url to get the tracking api from . e.g. "https://api.platform.workleap-dev.com/shell/navigation/"
|
|
33
42
|
* @param createOptions Options for creating the tracking function.
|
|
34
43
|
* @returns A function that sends tracking events to the tracking API.
|
|
35
44
|
*/
|
|
36
45
|
export declare function createTrackingFunction(productId: string, trackingApiBaseUrl: string, createOptions?: CreateTrackingFunctionOptions): TrackingFunction;
|
|
37
|
-
export {};
|
|
@@ -1,28 +1,23 @@
|
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE__env_js_a43599a2__ from "./env.js";
|
|
1
2
|
import * as __WEBPACK_EXTERNAL_MODULE__properties_js_2cf909bd__ from "./properties.js";
|
|
2
3
|
|
|
4
|
+
;// CONCATENATED MODULE: external "./env.js"
|
|
5
|
+
|
|
3
6
|
;// CONCATENATED MODULE: external "./properties.js"
|
|
4
7
|
|
|
5
8
|
;// CONCATENATED MODULE: ./src/createTrackingFunction.ts?__rslib_entry__
|
|
6
9
|
|
|
7
|
-
|
|
8
|
-
function
|
|
9
|
-
return `${baseUrl}${baseUrl.endsWith("/") ? "" : "/"}${path.startsWith("/") ? path.substring(1) : path}`;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Creates a function that sends tracking events to the tracking API.
|
|
13
|
-
* @param productId Your product identifier. e.g. "wlp", "ov"
|
|
14
|
-
* @param trackingApiUrl The base URL of the tracking controlled. e.g. "/api/navigation"
|
|
15
|
-
* @param createOptions Options for creating the tracking function.
|
|
16
|
-
* @returns A function that sends tracking events to the tracking API.
|
|
17
|
-
*/ function createTrackingFunction(productId, trackingApiBaseUrl, createOptions = {}) {
|
|
10
|
+
|
|
11
|
+
function createTrackingFunction(productId, envOrTrackingApiBaseUrl, createOptions = {}) {
|
|
18
12
|
const targetProductId = createOptions?.targetProductId ?? null;
|
|
13
|
+
const fullUrl = (0,__WEBPACK_EXTERNAL_MODULE__env_js_a43599a2__.getTrackingEndpoint)(envOrTrackingApiBaseUrl);
|
|
19
14
|
return async (eventName, properties, options)=>{
|
|
20
15
|
const baseProperties = (0,__WEBPACK_EXTERNAL_MODULE__properties_js_2cf909bd__.getBaseProperties)();
|
|
21
16
|
const allProperties = {
|
|
22
17
|
...baseProperties,
|
|
23
18
|
...properties
|
|
24
19
|
};
|
|
25
|
-
await fetch(
|
|
20
|
+
await fetch(fullUrl, {
|
|
26
21
|
method: "POST",
|
|
27
22
|
credentials: "include",
|
|
28
23
|
keepalive: options?.keepAlive,
|
|
@@ -32,7 +27,7 @@ function resolveApiUrl(path, baseUrl) {
|
|
|
32
27
|
body: JSON.stringify({
|
|
33
28
|
eventName,
|
|
34
29
|
productId,
|
|
35
|
-
targetProductId
|
|
30
|
+
targetProductId,
|
|
36
31
|
properties: allProperties
|
|
37
32
|
})
|
|
38
33
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createTrackingFunction.js","sources":["webpack://@workleap/mixpanel/./src/createTrackingFunction.ts"],"sourcesContent":["import { getBaseProperties, type TrackEventProperties } from \"./properties.ts\";\n\nexport interface TrackingOptions {\n /**\n * Whether to keep the connection alive for the tracking request.\n * It is mostly used for tracking links where the user might navigate away before the request is completed.\n *\n * Caution! The body size for keepalive requests is limited to 64 kibibytes.\n *\n * https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#keepalive\n *\n * @default false\n */\n keepAlive?: boolean;\n}\n\n/**\n * A function that sends tracking events to the tracking API.\n * @param eventName The name of the event to track.\n * @param properties The properties to send with the event.\n * @param options Options for tracking the event.\n */\nexport type TrackingFunction = (eventName: string, properties: TrackEventProperties, options?: TrackingOptions) => Promise<void>;\n\
|
|
1
|
+
{"version":3,"file":"createTrackingFunction.js","sources":["webpack://@workleap/mixpanel/./src/createTrackingFunction.ts"],"sourcesContent":["import { getTrackingEndpoint, type Environment } from \"./env.ts\";\nimport { getBaseProperties, type TrackEventProperties } from \"./properties.ts\";\n\nexport interface TrackingOptions {\n /**\n * Whether to keep the connection alive for the tracking request.\n * It is mostly used for tracking links where the user might navigate away before the request is completed.\n *\n * Caution! The body size for keepalive requests is limited to 64 kibibytes.\n *\n * https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#keepalive\n *\n * @default false\n */\n keepAlive?: boolean;\n}\n\n/**\n * A function that sends tracking events to the tracking API.\n * @param eventName The name of the event to track.\n * @param properties The properties to send with the event.\n * @param options Options for tracking the event.\n */\nexport type TrackingFunction = (eventName: string, properties: TrackEventProperties, options?: TrackingOptions) => Promise<void>;\n\nexport interface CreateTrackingFunctionOptions {\n /**\n * The product identifier of the target product.\n * @default null\n */\n targetProductId?: string | null;\n}\n\n/**\n * Creates a function that sends tracking events to the tracking API.\n * @param productId Your product identifier. e.g. \"wlp\", \"ov\"\n * @param env The environment to get the navigation url from . e.g. \"local\", \"prod\"\n * @param createOptions Options for creating the tracking function.\n * @returns A function that sends tracking events to the tracking API.\n */\nexport function createTrackingFunction(productId: string, env: Environment, createOptions?: CreateTrackingFunctionOptions) : TrackingFunction;\n/**\n * Creates a function that sends tracking events to the tracking API.\n * @param productId Your product identifier. e.g. \"wlp\", \"ov\"\n * @param trackingApiBaseUrl The base Url to get the tracking api from . e.g. \"https://api.platform.workleap-dev.com/shell/navigation/\"\n * @param createOptions Options for creating the tracking function.\n * @returns A function that sends tracking events to the tracking API.\n */\nexport function createTrackingFunction(productId: string, trackingApiBaseUrl: string, createOptions?: CreateTrackingFunctionOptions) : TrackingFunction;\nexport function createTrackingFunction(productId: string, envOrTrackingApiBaseUrl: Environment | (string & {}), createOptions: CreateTrackingFunctionOptions = {}) : TrackingFunction {\n const targetProductId = createOptions?.targetProductId ?? null;\n const fullUrl = getTrackingEndpoint(envOrTrackingApiBaseUrl);\n\n return async (eventName, properties, options) => {\n const baseProperties = getBaseProperties();\n const allProperties = { ...baseProperties, ...properties };\n\n await fetch(fullUrl, {\n method: \"POST\",\n credentials: \"include\",\n keepalive: options?.keepAlive,\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n eventName,\n productId,\n targetProductId,\n properties: allProperties\n })\n });\n };\n}\n"],"names":["getTrackingEndpoint","getBaseProperties","createTrackingFunction","productId","envOrTrackingApiBaseUrl","createOptions","targetProductId","fullUrl","eventName","properties","options","baseProperties","allProperties","fetch","JSON"],"mappings":";;;;;;;;AAAiE;AACc;AAgDxE,SAASE,uBAAuBC,SAAiB,EAAEC,uBAAoD,EAAEC,gBAA+C,CAAC,CAAC;IAC7J,MAAMC,kBAAkBD,eAAe,mBAAmB;IAC1D,MAAME,UAAUP,oEAAmBA,CAACI;IAEpC,OAAO,OAAOI,WAAWC,YAAYC;QACjC,MAAMC,iBAAiBV,yEAAiBA;QACxC,MAAMW,gBAAgB;YAAE,GAAGD,cAAc;YAAE,GAAGF,UAAU;QAAC;QAEzD,MAAMI,MAAMN,SAAS;YACjB,QAAQ;YACR,aAAa;YACb,WAAWG,SAAS;YACpB,SAAS;gBAAE,gBAAgB;YAAmB;YAC9C,MAAMI,KAAK,SAAS,CAAC;gBACjBN;gBACAL;gBACAG;gBACA,YAAYM;YAChB;QACJ;IACJ;AACJ"}
|
package/dist/env.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
declare const EnvironmentList: readonly ["development", "staging", "production", "local", "msw"];
|
|
2
|
+
export type Environment = typeof EnvironmentList[number];
|
|
3
|
+
export declare function getTrackingEndpoint(envOrTrackingApiBaseUrl: Environment | (string & {})): string;
|
|
4
|
+
export {};
|
package/dist/env.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
|
|
2
|
+
;// CONCATENATED MODULE: ./src/env.ts?__rslib_entry__
|
|
3
|
+
const EnvironmentList = [
|
|
4
|
+
"development",
|
|
5
|
+
"staging",
|
|
6
|
+
"production",
|
|
7
|
+
"local",
|
|
8
|
+
"msw"
|
|
9
|
+
];
|
|
10
|
+
const NavigationApiBaseUrl = {
|
|
11
|
+
"production": "https://api.platform.workleap.com/shell/navigation/",
|
|
12
|
+
"staging": "https://api.platform.workleap-stg.com/shell/navigation/",
|
|
13
|
+
"development": "https://api.platform.workleap-dev.com/shell/navigation/",
|
|
14
|
+
"local": "https://api.platform.workleap-dev.com/shell/navigation/",
|
|
15
|
+
"msw": "/api/shell/navigation/"
|
|
16
|
+
};
|
|
17
|
+
// Cannot use URL() because it doesn't support relative base url: https://github.com/whatwg/url/issues/531.
|
|
18
|
+
function resolveApiUrl(path, baseUrl) {
|
|
19
|
+
return `${baseUrl}${baseUrl.endsWith("/") ? "" : "/"}${path.startsWith("/") ? path.substring(1) : path}`;
|
|
20
|
+
}
|
|
21
|
+
function getTrackingEndpoint(envOrTrackingApiBaseUrl) {
|
|
22
|
+
let baseUrl;
|
|
23
|
+
if (EnvironmentList.includes(envOrTrackingApiBaseUrl)) {
|
|
24
|
+
baseUrl = NavigationApiBaseUrl[envOrTrackingApiBaseUrl];
|
|
25
|
+
} else {
|
|
26
|
+
baseUrl = envOrTrackingApiBaseUrl;
|
|
27
|
+
}
|
|
28
|
+
return resolveApiUrl("tracking/track", baseUrl);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { getTrackingEndpoint };
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=env.js.map
|
package/dist/env.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.js","sources":["webpack://@workleap/mixpanel/./src/env.ts"],"sourcesContent":["\nconst EnvironmentList = [\"development\", \"staging\", \"production\", \"local\", \"msw\"] as const;\nexport type Environment = typeof EnvironmentList[number];\n\nconst NavigationApiBaseUrl: Record<Environment, string> = {\n \"production\": \"https://api.platform.workleap.com/shell/navigation/\",\n \"staging\": \"https://api.platform.workleap-stg.com/shell/navigation/\",\n \"development\": \"https://api.platform.workleap-dev.com/shell/navigation/\",\n \"local\": \"https://api.platform.workleap-dev.com/shell/navigation/\",\n \"msw\": \"/api/shell/navigation/\"\n};\n\n// Cannot use URL() because it doesn't support relative base url: https://github.com/whatwg/url/issues/531.\nfunction resolveApiUrl(path: string, baseUrl: string | undefined) : string {\n return `${baseUrl}${baseUrl!.endsWith(\"/\") ? \"\" : \"/\"}${path.startsWith(\"/\") ? path.substring(1) : path}`;\n}\n\nexport function getTrackingEndpoint(envOrTrackingApiBaseUrl: Environment | (string & {})) {\n let baseUrl: string;\n if (EnvironmentList.includes(envOrTrackingApiBaseUrl as Environment)) {\n baseUrl = NavigationApiBaseUrl[envOrTrackingApiBaseUrl as Environment];\n } else {\n baseUrl = envOrTrackingApiBaseUrl;\n }\n\n return resolveApiUrl(\"tracking/track\", baseUrl);\n}\n"],"names":["EnvironmentList","NavigationApiBaseUrl","resolveApiUrl","path","baseUrl","getTrackingEndpoint","envOrTrackingApiBaseUrl"],"mappings":";;AACA,MAAMA,kBAAkB;IAAC;IAAe;IAAW;IAAc;IAAS;CAAM;AAGhF,MAAMC,uBAAoD;IACtD,cAAc;IACd,WAAW;IACX,eAAe;IACf,SAAS;IACT,OAAO;AACX;AAEA,2GAA2G;AAC3G,SAASC,cAAcC,IAAY,EAAEC,OAA2B;IAC5D,OAAO,GAAGA,UAAUA,QAAS,QAAQ,CAAC,OAAO,KAAK,MAAMD,KAAK,UAAU,CAAC,OAAOA,KAAK,SAAS,CAAC,KAAKA,MAAM;AAC7G;AAEO,SAASE,oBAAoBC,uBAAoD;IACpF,IAAIF;IACJ,IAAIJ,gBAAgB,QAAQ,CAACM,0BAAyC;QAClEF,UAAUH,oBAAoB,CAACK,wBAAuC;IAC1E,OAAO;QACHF,UAAUE;IACd;IAEA,OAAOJ,cAAc,kBAAkBE;AAC3C"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["webpack://@workleap/mixpanel/./src/index.ts"],"sourcesContent":["export * from \"./createTrackingFunction.ts\";\n\n"],"names":[],"mappings":";;;AAA4C"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["webpack://@workleap/mixpanel/./src/index.ts"],"sourcesContent":["export * from \"./createTrackingFunction.ts\";\nexport type { Environment } from \"./env.ts\";\nexport type { TrackEventProperties } from \"./properties.ts\";\n\n"],"names":[],"mappings":";;;AAA4C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@workleap/mixpanel",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"provenance": true
|
|
13
13
|
},
|
|
14
14
|
"type": "module",
|
|
15
|
+
"main": "./dist/index.js",
|
|
15
16
|
"exports": {
|
|
16
17
|
".": {
|
|
17
18
|
"import": "./dist/index.js",
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getTrackingEndpoint, type Environment } from "./env.ts";
|
|
1
2
|
import { getBaseProperties, type TrackEventProperties } from "./properties.ts";
|
|
2
3
|
|
|
3
4
|
export interface TrackingOptions {
|
|
@@ -22,12 +23,7 @@ export interface TrackingOptions {
|
|
|
22
23
|
*/
|
|
23
24
|
export type TrackingFunction = (eventName: string, properties: TrackEventProperties, options?: TrackingOptions) => Promise<void>;
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
function resolveApiUrl(path: string, baseUrl: string | undefined) : string {
|
|
27
|
-
return `${baseUrl}${baseUrl!.endsWith("/") ? "" : "/"}${path.startsWith("/") ? path.substring(1) : path}`;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
interface CreateTrackingFunctionOptions {
|
|
26
|
+
export interface CreateTrackingFunctionOptions {
|
|
31
27
|
/**
|
|
32
28
|
* The product identifier of the target product.
|
|
33
29
|
* @default null
|
|
@@ -38,18 +34,28 @@ interface CreateTrackingFunctionOptions {
|
|
|
38
34
|
/**
|
|
39
35
|
* Creates a function that sends tracking events to the tracking API.
|
|
40
36
|
* @param productId Your product identifier. e.g. "wlp", "ov"
|
|
41
|
-
* @param
|
|
37
|
+
* @param env The environment to get the navigation url from . e.g. "local", "prod"
|
|
38
|
+
* @param createOptions Options for creating the tracking function.
|
|
39
|
+
* @returns A function that sends tracking events to the tracking API.
|
|
40
|
+
*/
|
|
41
|
+
export function createTrackingFunction(productId: string, env: Environment, createOptions?: CreateTrackingFunctionOptions) : TrackingFunction;
|
|
42
|
+
/**
|
|
43
|
+
* Creates a function that sends tracking events to the tracking API.
|
|
44
|
+
* @param productId Your product identifier. e.g. "wlp", "ov"
|
|
45
|
+
* @param trackingApiBaseUrl The base Url to get the tracking api from . e.g. "https://api.platform.workleap-dev.com/shell/navigation/"
|
|
42
46
|
* @param createOptions Options for creating the tracking function.
|
|
43
47
|
* @returns A function that sends tracking events to the tracking API.
|
|
44
48
|
*/
|
|
45
|
-
export function createTrackingFunction(productId: string, trackingApiBaseUrl: string, createOptions
|
|
49
|
+
export function createTrackingFunction(productId: string, trackingApiBaseUrl: string, createOptions?: CreateTrackingFunctionOptions) : TrackingFunction;
|
|
50
|
+
export function createTrackingFunction(productId: string, envOrTrackingApiBaseUrl: Environment | (string & {}), createOptions: CreateTrackingFunctionOptions = {}) : TrackingFunction {
|
|
46
51
|
const targetProductId = createOptions?.targetProductId ?? null;
|
|
52
|
+
const fullUrl = getTrackingEndpoint(envOrTrackingApiBaseUrl);
|
|
47
53
|
|
|
48
54
|
return async (eventName, properties, options) => {
|
|
49
55
|
const baseProperties = getBaseProperties();
|
|
50
56
|
const allProperties = { ...baseProperties, ...properties };
|
|
51
57
|
|
|
52
|
-
await fetch(
|
|
58
|
+
await fetch(fullUrl, {
|
|
53
59
|
method: "POST",
|
|
54
60
|
credentials: "include",
|
|
55
61
|
keepalive: options?.keepAlive,
|
|
@@ -57,7 +63,7 @@ export function createTrackingFunction(productId: string, trackingApiBaseUrl: st
|
|
|
57
63
|
body: JSON.stringify({
|
|
58
64
|
eventName,
|
|
59
65
|
productId,
|
|
60
|
-
targetProductId
|
|
66
|
+
targetProductId,
|
|
61
67
|
properties: allProperties
|
|
62
68
|
})
|
|
63
69
|
});
|
package/src/env.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
|
|
2
|
+
const EnvironmentList = ["development", "staging", "production", "local", "msw"] as const;
|
|
3
|
+
export type Environment = typeof EnvironmentList[number];
|
|
4
|
+
|
|
5
|
+
const NavigationApiBaseUrl: Record<Environment, string> = {
|
|
6
|
+
"production": "https://api.platform.workleap.com/shell/navigation/",
|
|
7
|
+
"staging": "https://api.platform.workleap-stg.com/shell/navigation/",
|
|
8
|
+
"development": "https://api.platform.workleap-dev.com/shell/navigation/",
|
|
9
|
+
"local": "https://api.platform.workleap-dev.com/shell/navigation/",
|
|
10
|
+
"msw": "/api/shell/navigation/"
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// Cannot use URL() because it doesn't support relative base url: https://github.com/whatwg/url/issues/531.
|
|
14
|
+
function resolveApiUrl(path: string, baseUrl: string | undefined) : string {
|
|
15
|
+
return `${baseUrl}${baseUrl!.endsWith("/") ? "" : "/"}${path.startsWith("/") ? path.substring(1) : path}`;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function getTrackingEndpoint(envOrTrackingApiBaseUrl: Environment | (string & {})) {
|
|
19
|
+
let baseUrl: string;
|
|
20
|
+
if (EnvironmentList.includes(envOrTrackingApiBaseUrl as Environment)) {
|
|
21
|
+
baseUrl = NavigationApiBaseUrl[envOrTrackingApiBaseUrl as Environment];
|
|
22
|
+
} else {
|
|
23
|
+
baseUrl = envOrTrackingApiBaseUrl;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return resolveApiUrl("tracking/track", baseUrl);
|
|
27
|
+
}
|
package/src/index.ts
CHANGED