Skip to content

Commit c9efd5c

Browse files
committed
Merge branch 'main' into feat/interface-definitions
# Conflicts: # lib/flagsmith/package.json # lib/react-native-flagsmith/package.json
2 parents 22317a5 + 23f90b5 commit c9efd5c

File tree

7 files changed

+31
-41
lines changed

7 files changed

+31
-41
lines changed

flagsmith-core.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import angularFetch from './utils/angular-fetch';
2323
import setDynatraceValue from './utils/set-dynatrace-value';
2424
import { EvaluationContext } from './evaluation-context';
2525
import { isTraitEvaluationContext, toEvaluationContext, toTraitEvaluationContextObject } from './utils/types';
26+
import { ensureTrailingSlash } from './utils/ensureTrailingSlash';
2627

2728
enum FlagSource {
2829
"NONE" = "NONE",
@@ -260,7 +261,7 @@ const Flagsmith = class {
260261
analyticsInterval: NodeJS.Timer | null= null
261262
api: string|null= null
262263
cacheFlags= false
263-
ts: number|null= null
264+
ts?: number
264265
enableAnalytics= false
265266
enableLogs= false
266267
evaluationContext: EvaluationContext= {}
@@ -318,7 +319,7 @@ const Flagsmith = class {
318319
) : {},
319320
} : evaluationContext.identity;
320321
this.evaluationContext = evaluationContext;
321-
this.api = api;
322+
this.api = ensureTrailingSlash(api);
322323
this.headers = headers;
323324
this.getFlagInterval = null;
324325
this.analyticsInterval = null;

index-es.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

isomorphic-es.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

test/init.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,21 @@ describe('Flagsmith.init', () => {
9595
});
9696
await expect(flagsmith.init(initConfig)).rejects.toThrow(Error);
9797
});
98+
test('should sanitise api url', async () => {
99+
const onChange = jest.fn();
100+
const { flagsmith,initConfig } = getFlagsmith({
101+
api:'https://edge.api.flagsmith.com/api/v1/',
102+
onChange,
103+
});
104+
await flagsmith.init(initConfig)
105+
expect(flagsmith.getState().api).toBe('https://edge.api.flagsmith.com/api/v1/');
106+
const { flagsmith:flagsmith2 } = getFlagsmith({
107+
api:'https://edge.api.flagsmith.com/api/v1',
108+
onChange,
109+
});
110+
await flagsmith2.init(initConfig)
111+
expect(flagsmith2.getState().api).toBe('https://edge.api.flagsmith.com/api/v1/');
112+
});
98113
test('should reject initialize with identity bad key', async () => {
99114
const onChange = jest.fn();
100115
const { flagsmith, initConfig, mockFetch } = getFlagsmith({ onChange, environmentID: 'bad' });

test/isomorphic.test.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import flagsmithIsomorphic from '../lib/flagsmith/isomorphic';
2+
import { getFlagsmith } from './test-constants';
3+
4+
describe('Flagsmith Isomorphic Import', () => {
5+
test('flagsmith is imported correctly', () => {
6+
const { initConfig } = getFlagsmith({});
7+
flagsmithIsomorphic.init(initConfig)
8+
})
9+
})

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"skipLibCheck": true,
66
"jsx": "react",
77
"module": "ESNext",
8-
"declaration": false,
8+
"declaration": true,
99
"strict": true,
1010
"noEmit": true,
1111
"sourceMap": true,

utils/ensureTrailingSlash.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function ensureTrailingSlash(str: string): string {
2+
return str.endsWith('/') ? str : str + '/';
3+
}

0 commit comments

Comments
 (0)