@servicetitan/marketing-ui 3.0.3 → 3.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/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/utils/marketing-parner-handlers.d.ts +15 -0
- package/dist/utils/marketing-parner-handlers.d.ts.map +1 -0
- package/dist/utils/marketing-parner-handlers.js +17 -0
- package/dist/utils/marketing-parner-handlers.js.map +1 -0
- package/package.json +4 -2
- package/src/index.ts +1 -0
- package/src/utils/marketing-parner-handlers.ts +40 -0
package/dist/index.d.ts
CHANGED
|
@@ -14,4 +14,5 @@ export * from './utils/use-client-rect';
|
|
|
14
14
|
export * from './utils/helpers';
|
|
15
15
|
export * from './utils/format-big-numbers';
|
|
16
16
|
export * from './utils/use-target-range-store';
|
|
17
|
+
export * as marketingRedirector from './utils/marketing-parner-handlers';
|
|
17
18
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sCAAsC,CAAC;AACrD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,mDAAmD,CAAC;AAClE,cAAc,iDAAiD,CAAC;AAChE,cAAc,2BAA2B,CAAC;AAC1C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,0CAA0C,CAAC;AAEzD,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,iBAAiB,CAAC;AAChC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gCAAgC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sCAAsC,CAAC;AACrD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,mDAAmD,CAAC;AAClE,cAAc,iDAAiD,CAAC;AAChE,cAAc,2BAA2B,CAAC;AAC1C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,0CAA0C,CAAC;AAEzD,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,iBAAiB,CAAC;AAChC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gCAAgC,CAAC;AAC/C,OAAO,KAAK,mBAAmB,MAAM,mCAAmC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -14,4 +14,5 @@ export * from './utils/use-client-rect';
|
|
|
14
14
|
export * from './utils/helpers';
|
|
15
15
|
export * from './utils/format-big-numbers';
|
|
16
16
|
export * from './utils/use-target-range-store';
|
|
17
|
+
export * as marketingRedirector from './utils/marketing-parner-handlers';
|
|
17
18
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sCAAsC,CAAC;AACrD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,mDAAmD,CAAC;AAClE,cAAc,iDAAiD,CAAC;AAChE,cAAc,2BAA2B,CAAC;AAC1C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,0CAA0C,CAAC;AAEzD,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,iBAAiB,CAAC;AAChC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gCAAgC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sCAAsC,CAAC;AACrD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,mDAAmD,CAAC;AAClE,cAAc,iDAAiD,CAAC;AAChE,cAAc,2BAA2B,CAAC;AAC1C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,0CAA0C,CAAC;AAEzD,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,iBAAiB,CAAC;AAChC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gCAAgC,CAAC;AAC/C,OAAO,KAAK,mBAAmB,MAAM,mCAAmC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AxiosInstance } from 'axios';
|
|
2
|
+
export interface AuthResponse {
|
|
3
|
+
redirect_uri: string;
|
|
4
|
+
redirect_query_param: string;
|
|
5
|
+
}
|
|
6
|
+
export declare type RedirectTarget = '_self' | '_blank' | '_parent' | '_top';
|
|
7
|
+
/**
|
|
8
|
+
* @see https://servicetitan.atlassian.net/wiki/spaces/EN/pages/2459272255/Frontend+redirect+issue
|
|
9
|
+
*/
|
|
10
|
+
export declare function execPartnerRedirect(res: {
|
|
11
|
+
status: number;
|
|
12
|
+
data?: AuthResponse;
|
|
13
|
+
} | undefined, target?: RedirectTarget): void;
|
|
14
|
+
export declare function initAuthHandlers(axiosInstane: AxiosInstance, target?: RedirectTarget): number;
|
|
15
|
+
//# sourceMappingURL=marketing-parner-handlers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"marketing-parner-handlers.d.ts","sourceRoot":"","sources":["../../src/utils/marketing-parner-handlers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAG3C,MAAM,WAAW,YAAY;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,oBAAoB,EAAE,MAAM,CAAC;CAChC;AAED,oBAAY,cAAc,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,CAAC;AAOrE;;GAEG;AACH,wBAAgB,mBAAmB,CAC/B,GAAG,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,YAAY,CAAA;CAAE,GAAG,SAAS,EACxD,MAAM,CAAC,EAAE,cAAc,QAY1B;AAED,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,aAAa,EAAE,MAAM,CAAC,EAAE,cAAc,UAKpF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const joinUrlParameter = (url, key, value) => {
|
|
2
|
+
const separator = url.includes('?') ? '&' : '?';
|
|
3
|
+
return `${url}${separator}${key}=${encodeURIComponent(value)}`;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* @see https://servicetitan.atlassian.net/wiki/spaces/EN/pages/2459272255/Frontend+redirect+issue
|
|
7
|
+
*/
|
|
8
|
+
export function execPartnerRedirect(res, target) {
|
|
9
|
+
var _a, _b;
|
|
10
|
+
if ((res === null || res === void 0 ? void 0 : res.status) === 401 && ((_a = res.data) === null || _a === void 0 ? void 0 : _a.redirect_uri) && ((_b = res.data) === null || _b === void 0 ? void 0 : _b.redirect_query_param)) {
|
|
11
|
+
window.open(joinUrlParameter(res.data.redirect_uri, res.data.redirect_query_param, window.location.href), target !== null && target !== void 0 ? target : '_self');
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export function initAuthHandlers(axiosInstane, target) {
|
|
15
|
+
return axiosInstane.interceptors.response.use(response => response, res => execPartnerRedirect(res.response, target));
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=marketing-parner-handlers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"marketing-parner-handlers.js","sourceRoot":"","sources":["../../src/utils/marketing-parner-handlers.ts"],"names":[],"mappings":"AAUA,MAAM,gBAAgB,GAAG,CAAC,GAAW,EAAE,GAAW,EAAE,KAAa,EAAE,EAAE;IACjE,MAAM,SAAS,GAAG,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;IAChD,OAAO,GAAG,GAAG,GAAG,SAAS,GAAG,GAAG,IAAI,kBAAkB,CAAC,KAAK,CAAC,EAAE,CAAC;AACnE,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAC/B,GAAwD,EACxD,MAAuB;;IAEvB,IAAI,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,MAAM,MAAK,GAAG,KAAI,MAAA,GAAG,CAAC,IAAI,0CAAE,YAAY,CAAA,KAAI,MAAA,GAAG,CAAC,IAAI,0CAAE,oBAAoB,CAAA,EAAE;QACjF,MAAM,CAAC,IAAI,CACP,gBAAgB,CACZ,GAAG,CAAC,IAAI,CAAC,YAAY,EACrB,GAAG,CAAC,IAAI,CAAC,oBAAoB,EAC7B,MAAM,CAAC,QAAQ,CAAC,IAAI,CACvB,EACD,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,OAAO,CACpB,CAAC;KACL;AACL,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,YAA2B,EAAE,MAAuB;IACjF,OAAO,YAAY,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CACzC,QAAQ,CAAC,EAAE,CAAC,QAAQ,EACpB,GAAG,CAAC,EAAE,CAAC,mBAAmB,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CACnD,CAAC;AACN,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@servicetitan/marketing-ui",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "Marketing UI component and utils",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"@servicetitan/react-ioc": "~14.1.1",
|
|
23
23
|
"@servicetitan/tokens": ">=12.1.11",
|
|
24
24
|
"accounting": "~0.4.1",
|
|
25
|
+
"axios": ">=0.20.0",
|
|
25
26
|
"mobx": "~6.3.2",
|
|
26
27
|
"mobx-react": "~7.2.0",
|
|
27
28
|
"moment": "~2.29.1",
|
|
@@ -38,6 +39,7 @@
|
|
|
38
39
|
"@types/react-image-crop": "8.1.2",
|
|
39
40
|
"@types/react-router-dom": "^5.1.8",
|
|
40
41
|
"accounting": "~0.4.1",
|
|
42
|
+
"axios": ">=0.20.0",
|
|
41
43
|
"mobx": "~6.3.2",
|
|
42
44
|
"mobx-react": "~7.2.0",
|
|
43
45
|
"moment": "~2.29.1",
|
|
@@ -50,5 +52,5 @@
|
|
|
50
52
|
"less": true,
|
|
51
53
|
"webpack": false
|
|
52
54
|
},
|
|
53
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "6369f122fb0edb53acde1be3c47e4972f65b39f1"
|
|
54
56
|
}
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { AxiosInstance } from 'axios';
|
|
2
|
+
|
|
3
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
4
|
+
export interface AuthResponse {
|
|
5
|
+
redirect_uri: string;
|
|
6
|
+
redirect_query_param: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type RedirectTarget = '_self' | '_blank' | '_parent' | '_top';
|
|
10
|
+
|
|
11
|
+
const joinUrlParameter = (url: string, key: string, value: string) => {
|
|
12
|
+
const separator = url.includes('?') ? '&' : '?';
|
|
13
|
+
return `${url}${separator}${key}=${encodeURIComponent(value)}`;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @see https://servicetitan.atlassian.net/wiki/spaces/EN/pages/2459272255/Frontend+redirect+issue
|
|
18
|
+
*/
|
|
19
|
+
export function execPartnerRedirect(
|
|
20
|
+
res: { status: number; data?: AuthResponse } | undefined,
|
|
21
|
+
target?: RedirectTarget
|
|
22
|
+
) {
|
|
23
|
+
if (res?.status === 401 && res.data?.redirect_uri && res.data?.redirect_query_param) {
|
|
24
|
+
window.open(
|
|
25
|
+
joinUrlParameter(
|
|
26
|
+
res.data.redirect_uri,
|
|
27
|
+
res.data.redirect_query_param,
|
|
28
|
+
window.location.href
|
|
29
|
+
),
|
|
30
|
+
target ?? '_self'
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function initAuthHandlers(axiosInstane: AxiosInstance, target?: RedirectTarget) {
|
|
36
|
+
return axiosInstane.interceptors.response.use(
|
|
37
|
+
response => response,
|
|
38
|
+
res => execPartnerRedirect(res.response, target)
|
|
39
|
+
);
|
|
40
|
+
}
|