File tree 10 files changed +204
-60
lines changed
10 files changed +204
-60
lines changed Load Diff Large diffs are not rendered by default.
Original file line number Diff line number Diff line change 1
- import { initialize } from '@iterable/web-sdk' ;
1
+ import { initializeWithConfig , WithJWTParams } from '@iterable/web-sdk' ;
2
2
import axios from 'axios' ;
3
3
import ReactDOM from 'react-dom' ;
4
4
import './styles/index.css' ;
@@ -38,9 +38,13 @@ const HomeLink = styled(Link)`
38
38
` ;
39
39
40
40
( ( ) : void => {
41
- const { setEmail, logout, refreshJwtToken } = initialize (
42
- process . env . API_KEY || '' ,
43
- ( { email } ) => {
41
+ const initializeParams : WithJWTParams = {
42
+ authToken : process . env . API_KEY || '' ,
43
+ configOptions : {
44
+ isEuIterableService : false ,
45
+ dangerouslyAllowJsPopups : true
46
+ } ,
47
+ generateJWT : ( { email } ) => {
44
48
return axios
45
49
. post (
46
50
process . env . JWT_GENERATOR || 'http://localhost:5000/generate' ,
@@ -59,7 +63,9 @@ const HomeLink = styled(Link)`
59
63
return response . data ?. token ;
60
64
} ) ;
61
65
}
62
- ) ;
66
+ } ;
67
+ const { setEmail, logout, refreshJwtToken } =
68
+ initializeWithConfig ( initializeParams ) ;
63
69
64
70
ReactDOM . render (
65
71
< BrowserRouter >
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ import {
16
16
validateTokenTime ,
17
17
isEmail
18
18
} from './utils' ;
19
- import { config } from '../utils/config' ;
19
+ import { Options , config } from '../utils/config' ;
20
20
21
21
const MAX_TIMEOUT = ONE_DAY ;
22
22
@@ -773,3 +773,34 @@ export function initialize(
773
773
}
774
774
} ;
775
775
}
776
+
777
+ export interface WithJWTParams {
778
+ authToken : string ;
779
+ configOptions : Partial < Options > ;
780
+ generateJWT : ( payload : GenerateJWTPayload ) => Promise < string > ;
781
+ }
782
+
783
+ export interface WithoutJWTParams {
784
+ authToken : string ;
785
+ configOptions : Partial < Options > ;
786
+ }
787
+
788
+ export interface InitializeParams {
789
+ authToken : string ;
790
+ configOptions : Partial < Options > ;
791
+ generateJWT ?: ( payload : GenerateJWTPayload ) => Promise < string > ;
792
+ }
793
+
794
+ export function initializeWithConfig ( initializeParams : WithJWTParams ) : WithJWT ;
795
+
796
+ export function initializeWithConfig (
797
+ initializeParams : WithoutJWTParams
798
+ ) : WithoutJWT ;
799
+
800
+ export function initializeWithConfig ( initializeParams : InitializeParams ) {
801
+ const { authToken, configOptions, generateJWT } = initializeParams ;
802
+ config . setConfig ( configOptions ?? { } ) ;
803
+ return generateJWT
804
+ ? initialize ( authToken , generateJWT )
805
+ : initialize ( authToken ) ;
806
+ }
Original file line number Diff line number Diff line change @@ -18,6 +18,8 @@ const ITERABLE_API_URL = `https://${
18
18
IS_EU_ITERABLE_SERVICE ? EU_ITERABLE_DOMAIN : US_ITERABLE_DOMAIN
19
19
} /api`;
20
20
21
+ export const EU_ITERABLE_API = `https://${ EU_ITERABLE_DOMAIN } /api` ;
22
+
21
23
// Do not set `process.env.BASE_URL` if intending on using the prod or EU APIs.
22
24
export const BASE_URL = process . env . BASE_URL || ITERABLE_API_URL ;
23
25
Original file line number Diff line number Diff line change 1
1
import { by } from '@pabra/sortby' ;
2
2
import {
3
3
ANIMATION_DURATION ,
4
- dangerouslyAllowJsPopupExecution ,
5
4
DEFAULT_CLOSE_BUTTON_OFFSET_PERCENTAGE
6
5
} from 'src/constants' ;
7
6
import { WebInAppDisplaySettings } from 'src/inapp' ;
8
7
import { srSpeak } from 'src/utils/srSpeak' ;
9
8
import { trackInAppDelivery } from '../events' ;
10
9
import { CloseButtonPosition , InAppMessage } from './types' ;
10
+ import { config } from 'src/utils/config' ;
11
11
12
12
interface Breakpoints {
13
13
smMatches : boolean ;
@@ -288,7 +288,9 @@ const generateSecuredIFrame = () => {
288
288
iframe . setAttribute (
289
289
'sandbox' ,
290
290
`allow-same-origin allow-popups allow-top-navigation ${
291
- dangerouslyAllowJsPopupExecution ? 'allow-popups-to-escape-sandbox' : ''
291
+ config . getConfig ( 'dangerouslyAllowJsPopups' )
292
+ ? 'allow-popups-to-escape-sandbox'
293
+ : ''
292
294
} `
293
295
) ;
294
296
/*
Original file line number Diff line number Diff line change 1
1
import Axios , { AxiosRequestConfig } from 'axios' ;
2
- import { BASE_URL , STATIC_HEADERS } from './constants' ;
2
+ import { BASE_URL , STATIC_HEADERS , EU_ITERABLE_API } from './constants' ;
3
3
import { IterablePromise , IterableResponse } from './types' ;
4
4
import { AnySchema , ValidationError } from 'yup' ;
5
5
import { config } from './utils/config' ;
@@ -35,9 +35,14 @@ export const baseIterableRequest = <T = any>(
35
35
abortEarly : false
36
36
} ) ;
37
37
}
38
+
39
+ const baseURL = config . getConfig ( 'isEuIterableService' )
40
+ ? EU_ITERABLE_API
41
+ : config . getConfig ( 'baseURL' ) ;
42
+
38
43
return baseAxiosRequest ( {
39
44
...payload ,
40
- baseURL : config . getConfig ( 'baseURL' ) || BASE_URL ,
45
+ baseURL,
41
46
headers : {
42
47
...payload . headers ,
43
48
...STATIC_HEADERS
Original file line number Diff line number Diff line change 1
1
import { BASE_URL } from '../constants' ;
2
2
3
- interface Options {
3
+ export type Options = {
4
4
logLevel : 'none' | 'verbose' ;
5
5
baseURL : string ;
6
- }
6
+ isEuIterableService : boolean ;
7
+ dangerouslyAllowJsPopups : boolean ;
8
+ } ;
7
9
8
10
const _config = ( ) => {
9
11
let options : Options = {
10
12
logLevel : 'none' ,
11
- baseURL : BASE_URL
13
+ baseURL : BASE_URL ,
14
+ isEuIterableService : false ,
15
+ dangerouslyAllowJsPopups : false
12
16
} ;
13
17
18
+ const getConfig = < K extends keyof Options > ( option : K ) => options [ option ] ;
19
+
14
20
return {
15
- getConfig : ( option : keyof Options ) => options [ option ] ,
21
+ getConfig,
16
22
setConfig : ( newOptions : Partial < Options > ) => {
17
23
options = {
18
24
...options ,
Original file line number Diff line number Diff line change @@ -8,13 +8,13 @@ function getParsedEnv() {
8
8
return {
9
9
...env . parsed ,
10
10
VERSION : version ,
11
- IS_EU_ITERABLE_SERVICE : process . env . IS_EU_ITERABLE_SERVICE || false ,
12
- DANGEROUSLY_ALLOW_JS_POPUP_EXECUTION :
13
- process . env . DANGEROUSLY_ALLOW_JS_POPUP_EXECUTION || false
11
+ IS_EU_ITERABLE_SERVICE : process . env . IS_EU_ITERABLE_SERVICE || false
14
12
} ;
15
13
}
16
14
17
- return { VERSION : version } ;
15
+ return {
16
+ VERSION : version
17
+ } ;
18
18
}
19
19
20
20
module . exports = {
Original file line number Diff line number Diff line change @@ -8,9 +8,7 @@ function getParsedEnv() {
8
8
return {
9
9
...env . parsed ,
10
10
VERSION : version ,
11
- IS_EU_ITERABLE_SERVICE : process . env . IS_EU_ITERABLE_SERVICE || false ,
12
- DANGEROUSLY_ALLOW_JS_POPUP_EXECUTION :
13
- process . env . DANGEROUSLY_ALLOW_JS_POPUP_EXECUTION || false
11
+ IS_EU_ITERABLE_SERVICE : process . env . IS_EU_ITERABLE_SERVICE || false
14
12
} ;
15
13
}
16
14
Original file line number Diff line number Diff line change @@ -8,9 +8,7 @@ function getParsedEnv() {
8
8
return {
9
9
...env . parsed ,
10
10
VERSION : version ,
11
- IS_EU_ITERABLE_SERVICE : process . env . IS_EU_ITERABLE_SERVICE || false ,
12
- DANGEROUSLY_ALLOW_JS_POPUP_EXECUTION :
13
- process . env . DANGEROUSLY_ALLOW_JS_POPUP_EXECUTION || false
11
+ IS_EU_ITERABLE_SERVICE : process . env . IS_EU_ITERABLE_SERVICE || false
14
12
} ;
15
13
}
16
14
You can’t perform that action at this time.
0 commit comments