@servicetitan/launchdarkly-service 39.0.0 → 39.0.1
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/get-ld-client.d.ts.map +1 -1
- package/dist/get-ld-client.js +7 -1
- package/dist/get-ld-client.js.map +1 -1
- package/dist/tests/get-ld-client.test.js +21 -4
- package/dist/tests/get-ld-client.test.js.map +1 -1
- package/package.json +7 -7
- package/src/get-ld-client.ts +4 -2
- package/src/tests/get-ld-client.test.ts +20 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-ld-client.d.ts","sourceRoot":"","sources":["../src/get-ld-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"get-ld-client.d.ts","sourceRoot":"","sources":["../src/get-ld-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAyB,MAAM,4BAA4B,CAAC;AAC7E,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAMvC,wBAAgB,WAAW,CAAC,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,YAAY,GAAG,QAAQ,CAOtF"}
|
package/dist/get-ld-client.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { initialize } from 'launchdarkly-js-client-sdk';
|
|
2
2
|
const ldClients = new Map();
|
|
3
|
+
const defaultOptions = {
|
|
4
|
+
sendEventsOnlyForVariation: true
|
|
5
|
+
};
|
|
3
6
|
export function getLDClient({ clientSideID, context, options }) {
|
|
4
7
|
let client = ldClients.get(clientSideID);
|
|
5
8
|
if (!client) {
|
|
6
|
-
client = initialize(clientSideID, context,
|
|
9
|
+
client = initialize(clientSideID, context, {
|
|
10
|
+
...defaultOptions,
|
|
11
|
+
...options
|
|
12
|
+
});
|
|
7
13
|
ldClients.set(clientSideID, client);
|
|
8
14
|
}
|
|
9
15
|
return client;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/get-ld-client.ts"],"sourcesContent":["import { LDClient, initialize } from 'launchdarkly-js-client-sdk';\nimport { ClientConfig } from './types';\n\nconst ldClients: Map<string, LDClient> = new Map();\n\nexport function getLDClient({ clientSideID, context, options }: ClientConfig): LDClient {\n let client = ldClients.get(clientSideID);\n if (!client) {\n client = initialize(clientSideID, context, options);\n ldClients.set(clientSideID, client);\n }\n return client;\n}\n"],"names":["initialize","ldClients","Map","getLDClient","clientSideID","context","options","client","get","set"],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"sources":["../src/get-ld-client.ts"],"sourcesContent":["import { LDClient, LDOptions, initialize } from 'launchdarkly-js-client-sdk';\nimport { ClientConfig } from './types';\n\nconst ldClients: Map<string, LDClient> = new Map();\n\nconst defaultOptions: LDOptions = { sendEventsOnlyForVariation: true };\n\nexport function getLDClient({ clientSideID, context, options }: ClientConfig): LDClient {\n let client = ldClients.get(clientSideID);\n if (!client) {\n client = initialize(clientSideID, context, { ...defaultOptions, ...options });\n ldClients.set(clientSideID, client);\n }\n return client;\n}\n"],"names":["initialize","ldClients","Map","defaultOptions","sendEventsOnlyForVariation","getLDClient","clientSideID","context","options","client","get","set"],"mappings":"AAAA,SAA8BA,UAAU,QAAQ,6BAA6B;AAG7E,MAAMC,YAAmC,IAAIC;AAE7C,MAAMC,iBAA4B;IAAEC,4BAA4B;AAAK;AAErE,OAAO,SAASC,YAAY,EAAEC,YAAY,EAAEC,OAAO,EAAEC,OAAO,EAAgB;IACxE,IAAIC,SAASR,UAAUS,GAAG,CAACJ;IAC3B,IAAI,CAACG,QAAQ;QACTA,SAAST,WAAWM,cAAcC,SAAS;YAAE,GAAGJ,cAAc;YAAE,GAAGK,OAAO;QAAC;QAC3EP,UAAUU,GAAG,CAACL,cAAcG;IAChC;IACA,OAAOA;AACX"}
|
|
@@ -5,6 +5,9 @@ jest.mock('launchdarkly-js-client-sdk', ()=>({
|
|
|
5
5
|
}));
|
|
6
6
|
describe(`[launchdarkly-service] ${getLDClient.name}`, ()=>{
|
|
7
7
|
const mockClient = Symbol('mockClient');
|
|
8
|
+
const defaultOptions = {
|
|
9
|
+
sendEventsOnlyForVariation: true
|
|
10
|
+
};
|
|
8
11
|
let config;
|
|
9
12
|
const subject = ()=>getLDClient(config);
|
|
10
13
|
beforeEach(()=>{
|
|
@@ -17,17 +20,31 @@ describe(`[launchdarkly-service] ${getLDClient.name}`, ()=>{
|
|
|
17
20
|
}
|
|
18
21
|
};
|
|
19
22
|
});
|
|
20
|
-
test('initializes client with the given context', ()=>{
|
|
23
|
+
test('initializes client with the given context and default options', ()=>{
|
|
21
24
|
expect(subject()).toBe(mockClient);
|
|
22
|
-
expect(initialize).toHaveBeenCalledWith(config.clientSideID, config.context,
|
|
25
|
+
expect(initialize).toHaveBeenCalledWith(config.clientSideID, config.context, defaultOptions);
|
|
23
26
|
});
|
|
24
27
|
describe('when given options', ()=>{
|
|
25
28
|
beforeEach(()=>config.options = {
|
|
26
29
|
hash: 'foo'
|
|
27
30
|
});
|
|
28
|
-
test('passes options through
|
|
31
|
+
test('passes options through alongside the defaults', ()=>{
|
|
29
32
|
subject();
|
|
30
|
-
expect(initialize).toHaveBeenCalledWith(config.clientSideID, config.context,
|
|
33
|
+
expect(initialize).toHaveBeenCalledWith(config.clientSideID, config.context, {
|
|
34
|
+
...defaultOptions,
|
|
35
|
+
...config.options
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
describe('when given sendEventsOnlyForVariation', ()=>{
|
|
40
|
+
beforeEach(()=>config.options = {
|
|
41
|
+
sendEventsOnlyForVariation: false
|
|
42
|
+
});
|
|
43
|
+
test('lets the caller override the default', ()=>{
|
|
44
|
+
subject();
|
|
45
|
+
expect(initialize).toHaveBeenCalledWith(config.clientSideID, config.context, {
|
|
46
|
+
sendEventsOnlyForVariation: false
|
|
47
|
+
});
|
|
31
48
|
});
|
|
32
49
|
});
|
|
33
50
|
describe('when client already exists', ()=>{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/tests/get-ld-client.test.ts"],"sourcesContent":["import { initialize } from 'launchdarkly-js-client-sdk';\nimport { getLDClient } from '../get-ld-client';\n\njest.mock('launchdarkly-js-client-sdk', () => ({\n initialize: jest.fn(),\n}));\n\ndescribe(`[launchdarkly-service] ${getLDClient.name}`, () => {\n const mockClient: any = Symbol('mockClient');\n let config: Parameters<typeof getLDClient>[0];\n\n const subject = () => getLDClient(config);\n\n beforeEach(() => {\n jest.clearAllMocks();\n jest.mocked(initialize).mockImplementation(() => mockClient);\n config = { clientSideID: makeId(), context: { kind: 'multi' } };\n });\n\n test('initializes client with the given context', () => {\n expect(subject()).toBe(mockClient);\n expect(initialize).toHaveBeenCalledWith(\n config.clientSideID,\n config.context,\n
|
|
1
|
+
{"version":3,"sources":["../../src/tests/get-ld-client.test.ts"],"sourcesContent":["import { initialize } from 'launchdarkly-js-client-sdk';\nimport { getLDClient } from '../get-ld-client';\n\njest.mock('launchdarkly-js-client-sdk', () => ({\n initialize: jest.fn(),\n}));\n\ndescribe(`[launchdarkly-service] ${getLDClient.name}`, () => {\n const mockClient: any = Symbol('mockClient');\n const defaultOptions = { sendEventsOnlyForVariation: true };\n let config: Parameters<typeof getLDClient>[0];\n\n const subject = () => getLDClient(config);\n\n beforeEach(() => {\n jest.clearAllMocks();\n jest.mocked(initialize).mockImplementation(() => mockClient);\n config = { clientSideID: makeId(), context: { kind: 'multi' } };\n });\n\n test('initializes client with the given context and default options', () => {\n expect(subject()).toBe(mockClient);\n expect(initialize).toHaveBeenCalledWith(\n config.clientSideID,\n config.context,\n defaultOptions\n );\n });\n\n describe('when given options', () => {\n beforeEach(() => (config.options = { hash: 'foo' }));\n\n test('passes options through alongside the defaults', () => {\n subject();\n\n expect(initialize).toHaveBeenCalledWith(config.clientSideID, config.context, {\n ...defaultOptions,\n ...config.options,\n });\n });\n });\n\n describe('when given sendEventsOnlyForVariation', () => {\n beforeEach(() => (config.options = { sendEventsOnlyForVariation: false }));\n\n test('lets the caller override the default', () => {\n subject();\n\n expect(initialize).toHaveBeenCalledWith(config.clientSideID, config.context, {\n sendEventsOnlyForVariation: false,\n });\n });\n });\n\n describe('when client already exists', () => {\n const existingClient: any = Symbol('existingClient');\n\n beforeEach(() => {\n jest.mocked(initialize).mockImplementationOnce(() => existingClient);\n subject();\n });\n\n test('returns existing client', () => {\n expect(subject()).toBe(existingClient);\n expect(initialize).toHaveBeenCalledTimes(1);\n });\n });\n});\n\nfunction makeId() {\n return Math.round(1e6 * Math.random()).toString(36);\n}\n"],"names":["initialize","getLDClient","jest","mock","fn","describe","name","mockClient","Symbol","defaultOptions","sendEventsOnlyForVariation","config","subject","beforeEach","clearAllMocks","mocked","mockImplementation","clientSideID","makeId","context","kind","test","expect","toBe","toHaveBeenCalledWith","options","hash","existingClient","mockImplementationOnce","toHaveBeenCalledTimes","Math","round","random","toString"],"mappings":"AAAA,SAASA,UAAU,QAAQ,6BAA6B;AACxD,SAASC,WAAW,QAAQ,mBAAmB;AAE/CC,KAAKC,IAAI,CAAC,8BAA8B,IAAO,CAAA;QAC3CH,YAAYE,KAAKE,EAAE;IACvB,CAAA;AAEAC,SAAS,CAAC,uBAAuB,EAAEJ,YAAYK,IAAI,EAAE,EAAE;IACnD,MAAMC,aAAkBC,OAAO;IAC/B,MAAMC,iBAAiB;QAAEC,4BAA4B;IAAK;IAC1D,IAAIC;IAEJ,MAAMC,UAAU,IAAMX,YAAYU;IAElCE,WAAW;QACPX,KAAKY,aAAa;QAClBZ,KAAKa,MAAM,CAACf,YAAYgB,kBAAkB,CAAC,IAAMT;QACjDI,SAAS;YAAEM,cAAcC;YAAUC,SAAS;gBAAEC,MAAM;YAAQ;QAAE;IAClE;IAEAC,KAAK,iEAAiE;QAClEC,OAAOV,WAAWW,IAAI,CAAChB;QACvBe,OAAOtB,YAAYwB,oBAAoB,CACnCb,OAAOM,YAAY,EACnBN,OAAOQ,OAAO,EACdV;IAER;IAEAJ,SAAS,sBAAsB;QAC3BQ,WAAW,IAAOF,OAAOc,OAAO,GAAG;gBAAEC,MAAM;YAAM;QAEjDL,KAAK,iDAAiD;YAClDT;YAEAU,OAAOtB,YAAYwB,oBAAoB,CAACb,OAAOM,YAAY,EAAEN,OAAOQ,OAAO,EAAE;gBACzE,GAAGV,cAAc;gBACjB,GAAGE,OAAOc,OAAO;YACrB;QACJ;IACJ;IAEApB,SAAS,yCAAyC;QAC9CQ,WAAW,IAAOF,OAAOc,OAAO,GAAG;gBAAEf,4BAA4B;YAAM;QAEvEW,KAAK,wCAAwC;YACzCT;YAEAU,OAAOtB,YAAYwB,oBAAoB,CAACb,OAAOM,YAAY,EAAEN,OAAOQ,OAAO,EAAE;gBACzET,4BAA4B;YAChC;QACJ;IACJ;IAEAL,SAAS,8BAA8B;QACnC,MAAMsB,iBAAsBnB,OAAO;QAEnCK,WAAW;YACPX,KAAKa,MAAM,CAACf,YAAY4B,sBAAsB,CAAC,IAAMD;YACrDf;QACJ;QAEAS,KAAK,2BAA2B;YAC5BC,OAAOV,WAAWW,IAAI,CAACI;YACvBL,OAAOtB,YAAY6B,qBAAqB,CAAC;QAC7C;IACJ;AACJ;AAEA,SAASX;IACL,OAAOY,KAAKC,KAAK,CAAC,MAAMD,KAAKE,MAAM,IAAIC,QAAQ,CAAC;AACpD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@servicetitan/launchdarkly-service",
|
|
3
|
-
"version": "39.0.
|
|
3
|
+
"version": "39.0.1",
|
|
4
4
|
"description": "Service for creating and reusing client connections for LaunchDarkly",
|
|
5
5
|
"homepage": "https://docs.st.dev/docs/frontend/uikit/launchdarkly-service",
|
|
6
6
|
"repository": {
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
],
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@datadog/browser-rum": "^7.5.0",
|
|
30
|
-
"@servicetitan/log-service": "39.0.
|
|
31
|
-
"@servicetitan/react-ioc": "39.0.
|
|
30
|
+
"@servicetitan/log-service": "39.0.1",
|
|
31
|
+
"@servicetitan/react-ioc": "39.0.1",
|
|
32
32
|
"@testing-library/dom": "^10.4.1",
|
|
33
|
-
"@testing-library/jest-dom": "^7.0.
|
|
33
|
+
"@testing-library/jest-dom": "^7.0.1",
|
|
34
34
|
"@testing-library/react": "^16.3.2",
|
|
35
35
|
"launchdarkly-js-client-sdk": "3.5.0",
|
|
36
36
|
"launchdarkly-react-client-sdk": "3.6.1",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"@datadog/browser-rum": ">=6.19.0",
|
|
43
|
-
"@servicetitan/log-service": "39.0.
|
|
44
|
-
"@servicetitan/react-ioc": "39.0.
|
|
43
|
+
"@servicetitan/log-service": "39.0.1",
|
|
44
|
+
"@servicetitan/react-ioc": "39.0.1",
|
|
45
45
|
"launchdarkly-js-client-sdk": "3.5.0",
|
|
46
46
|
"launchdarkly-react-client-sdk": "3.6.1",
|
|
47
47
|
"mobx": ">= 6.13.5",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"cli": {
|
|
60
60
|
"webpack": false
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "6e852d0d87277df097ee9fb38b096dae3fb6d68e"
|
|
63
63
|
}
|
package/src/get-ld-client.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import { LDClient, initialize } from 'launchdarkly-js-client-sdk';
|
|
1
|
+
import { LDClient, LDOptions, initialize } from 'launchdarkly-js-client-sdk';
|
|
2
2
|
import { ClientConfig } from './types';
|
|
3
3
|
|
|
4
4
|
const ldClients: Map<string, LDClient> = new Map();
|
|
5
5
|
|
|
6
|
+
const defaultOptions: LDOptions = { sendEventsOnlyForVariation: true };
|
|
7
|
+
|
|
6
8
|
export function getLDClient({ clientSideID, context, options }: ClientConfig): LDClient {
|
|
7
9
|
let client = ldClients.get(clientSideID);
|
|
8
10
|
if (!client) {
|
|
9
|
-
client = initialize(clientSideID, context, options);
|
|
11
|
+
client = initialize(clientSideID, context, { ...defaultOptions, ...options });
|
|
10
12
|
ldClients.set(clientSideID, client);
|
|
11
13
|
}
|
|
12
14
|
return client;
|
|
@@ -7,6 +7,7 @@ jest.mock('launchdarkly-js-client-sdk', () => ({
|
|
|
7
7
|
|
|
8
8
|
describe(`[launchdarkly-service] ${getLDClient.name}`, () => {
|
|
9
9
|
const mockClient: any = Symbol('mockClient');
|
|
10
|
+
const defaultOptions = { sendEventsOnlyForVariation: true };
|
|
10
11
|
let config: Parameters<typeof getLDClient>[0];
|
|
11
12
|
|
|
12
13
|
const subject = () => getLDClient(config);
|
|
@@ -17,26 +18,37 @@ describe(`[launchdarkly-service] ${getLDClient.name}`, () => {
|
|
|
17
18
|
config = { clientSideID: makeId(), context: { kind: 'multi' } };
|
|
18
19
|
});
|
|
19
20
|
|
|
20
|
-
test('initializes client with the given context', () => {
|
|
21
|
+
test('initializes client with the given context and default options', () => {
|
|
21
22
|
expect(subject()).toBe(mockClient);
|
|
22
23
|
expect(initialize).toHaveBeenCalledWith(
|
|
23
24
|
config.clientSideID,
|
|
24
25
|
config.context,
|
|
25
|
-
|
|
26
|
+
defaultOptions
|
|
26
27
|
);
|
|
27
28
|
});
|
|
28
29
|
|
|
29
30
|
describe('when given options', () => {
|
|
30
31
|
beforeEach(() => (config.options = { hash: 'foo' }));
|
|
31
32
|
|
|
32
|
-
test('passes options through
|
|
33
|
+
test('passes options through alongside the defaults', () => {
|
|
33
34
|
subject();
|
|
34
35
|
|
|
35
|
-
expect(initialize).toHaveBeenCalledWith(
|
|
36
|
-
|
|
37
|
-
config.
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
expect(initialize).toHaveBeenCalledWith(config.clientSideID, config.context, {
|
|
37
|
+
...defaultOptions,
|
|
38
|
+
...config.options,
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe('when given sendEventsOnlyForVariation', () => {
|
|
44
|
+
beforeEach(() => (config.options = { sendEventsOnlyForVariation: false }));
|
|
45
|
+
|
|
46
|
+
test('lets the caller override the default', () => {
|
|
47
|
+
subject();
|
|
48
|
+
|
|
49
|
+
expect(initialize).toHaveBeenCalledWith(config.clientSideID, config.context, {
|
|
50
|
+
sendEventsOnlyForVariation: false,
|
|
51
|
+
});
|
|
40
52
|
});
|
|
41
53
|
});
|
|
42
54
|
|