@adobe/spacecat-shared-launchdarkly-client 1.0.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/.jsdoc.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "tags": {
3
+ "allowUnknownTags": true
4
+ },
5
+ "plugins": [
6
+ "plugins/markdown"
7
+ ]
8
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "reporterEnabled": "spec,xunit",
3
+ "xunitReporterOptions": {
4
+ "output": "junit/test-results.xml"
5
+ }
6
+ }
package/.nycrc.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "reporter": [
3
+ "lcov",
4
+ "text"
5
+ ],
6
+ "check-coverage": true,
7
+ "lines": 100,
8
+ "statements": 98,
9
+ "functions": 100,
10
+ "branches": 94,
11
+ "all": true,
12
+ "include": [
13
+ "src/**/*.js"
14
+ ]
15
+ }
package/.releaserc.cjs ADDED
@@ -0,0 +1,17 @@
1
+ module.exports = {
2
+ extends: "semantic-release-monorepo",
3
+ plugins: [
4
+ "@semantic-release/commit-analyzer",
5
+ "@semantic-release/release-notes-generator",
6
+ ["@semantic-release/changelog", {
7
+ "changelogFile": "CHANGELOG.md",
8
+ }],
9
+ "@semantic-release/npm",
10
+ ["@semantic-release/git", {
11
+ "assets": ["package.json", "CHANGELOG.md"],
12
+ "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
13
+ }],
14
+ ["@semantic-release/github", {}],
15
+ ],
16
+ branches: ['main'],
17
+ };
package/CHANGELOG.md ADDED
@@ -0,0 +1,26 @@
1
+ # @adobe/spacecat-shared-launchdarkly-client-v1.0.0 (2026-02-04)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * introduce Ld support libs ([#1316](https://github.com/adobe/spacecat-shared/issues/1316)) ([76efb22](https://github.com/adobe/spacecat-shared/commit/76efb22e5dc088deef1054cf2a4b2ea4842b4517))
7
+
8
+ # Changelog
9
+
10
+ All notable changes to this project will be documented in this file.
11
+
12
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
13
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
14
+
15
+ ## [1.0.0] - TBD
16
+
17
+ ### Added
18
+ - Initial release of LaunchDarkly client wrapper
19
+ - Support for feature flag evaluation
20
+ - Support for detailed flag evaluation
21
+ - Support for retrieving all flags state
22
+ - Support for custom event tracking
23
+ - Support for context identification
24
+ - Support for Helix Universal Context integration
25
+ - Comprehensive test coverage
26
+ - Example usage script
@@ -0,0 +1,74 @@
1
+ # Adobe Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at Grp-opensourceoffice@adobe.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
@@ -0,0 +1,74 @@
1
+ # Contributing to Project Franklin
2
+
3
+ This project (like almost all of Project Franklin) is an Open Development project and welcomes contributions from everyone who finds it useful or lacking.
4
+
5
+ ## Code Of Conduct
6
+
7
+ This project adheres to the Adobe [code of conduct](CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code. Please report unacceptable behavior to cstaub at adobe dot com.
8
+
9
+ ## Contributor License Agreement
10
+
11
+ All third-party contributions to this project must be accompanied by a signed contributor license. This gives Adobe permission to redistribute your contributions as part of the project. [Sign our CLA](http://opensource.adobe.com/cla.html)! You only need to submit an Adobe CLA one time, so if you have submitted one previously, you are good to go!
12
+
13
+ ## Things to Keep in Mind
14
+
15
+ This project uses a **commit then review** process, which means that for approved maintainers, changes can be merged immediately, but will be reviewed by others.
16
+
17
+ For other contributors, a maintainer of the project has to approve the pull request.
18
+
19
+ # Before You Contribute
20
+
21
+ * Check that there is an existing issue in GitHub issues
22
+ * Check if there are other pull requests that might overlap or conflict with your intended contribution
23
+
24
+ # How to Contribute
25
+
26
+ 1. Fork the repository
27
+ 2. Make some changes on a branch on your fork
28
+ 3. Create a pull request from your branch
29
+
30
+ In your pull request, outline:
31
+
32
+ * What the changes intend
33
+ * How they change the existing code
34
+ * If (and what) they breaks
35
+ * Start the pull request with the GitHub issue ID, e.g. #123
36
+
37
+ Lastly, please follow the [pull request template](.github/pull_request_template.md) when submitting a pull request!
38
+
39
+ Each commit message that is not part of a pull request:
40
+
41
+ * Should contain the issue ID like `#123`
42
+ * Can contain the tag `[trivial]` for trivial changes that don't relate to an issue
43
+
44
+
45
+
46
+ ## Coding Styleguides
47
+
48
+ We enforce a coding styleguide using `eslint`. As part of your build, run `npm run lint` to check if your code is conforming to the style guide. We do the same for every PR in our CI, so PRs will get rejected if they don't follow the style guide.
49
+
50
+ You can fix some of the issues automatically by running `npx eslint . --fix`.
51
+
52
+ ## Commit Message Format
53
+
54
+ This project uses a structured commit changelog format that should be used for every commit. Use `npm run commit` instead of your usual `git commit` to generate commit messages using a wizard.
55
+
56
+ ```bash
57
+ # either add all changed files
58
+ $ git add -A
59
+ # or selectively add files
60
+ $ git add package.json
61
+ # then commit using the wizard
62
+ $ npm run commit
63
+ ```
64
+
65
+ # How Contributions get Reviewed
66
+
67
+ One of the maintainers will look at the pull request within one week. Feedback on the pull request will be given in writing, in GitHub.
68
+
69
+ # Release Management
70
+
71
+ The project's committers will release to the [Adobe organization on npmjs.org](https://www.npmjs.com/org/adobe).
72
+ Please contact the [Adobe Open Source Advisory Board](https://git.corp.adobe.com/OpenSourceAdvisoryBoard/discuss/issues) to get access to the npmjs organization.
73
+
74
+ The release process is fully automated using `semantic-release`, increasing the version numbers, etc. based on the contents of the commit messages found.
package/LICENSE.txt ADDED
@@ -0,0 +1,264 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
203
+
204
+
205
+ APACHE JACKRABBIT SUBCOMPONENTS
206
+
207
+ Apache Jackrabbit includes parts with separate copyright notices and license
208
+ terms. Your use of these subcomponents is subject to the terms and conditions
209
+ of the following licenses:
210
+
211
+ XPath 2.0/XQuery 1.0 Parser:
212
+ http://www.w3.org/2002/11/xquery-xpath-applets/xgrammar.zip
213
+
214
+ Copyright (C) 2002 World Wide Web Consortium, (Massachusetts Institute of
215
+ Technology, European Research Consortium for Informatics and Mathematics,
216
+ Keio University). All Rights Reserved.
217
+
218
+ This work is distributed under the W3C(R) Software License in the hope
219
+ that it will be useful, but WITHOUT ANY WARRANTY; without even the
220
+ implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
221
+
222
+ W3C(R) SOFTWARE NOTICE AND LICENSE
223
+ http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231
224
+
225
+ This work (and included software, documentation such as READMEs, or
226
+ other related items) is being provided by the copyright holders under
227
+ the following license. By obtaining, using and/or copying this work,
228
+ you (the licensee) agree that you have read, understood, and will comply
229
+ with the following terms and conditions.
230
+
231
+ Permission to copy, modify, and distribute this software and its
232
+ documentation, with or without modification, for any purpose and
233
+ without fee or royalty is hereby granted, provided that you include
234
+ the following on ALL copies of the software and documentation or
235
+ portions thereof, including modifications:
236
+
237
+ 1. The full text of this NOTICE in a location viewable to users
238
+ of the redistributed or derivative work.
239
+
240
+ 2. Any pre-existing intellectual property disclaimers, notices,
241
+ or terms and conditions. If none exist, the W3C Software Short
242
+ Notice should be included (hypertext is preferred, text is
243
+ permitted) within the body of any redistributed or derivative code.
244
+
245
+ 3. Notice of any changes or modifications to the files, including
246
+ the date changes were made. (We recommend you provide URIs to the
247
+ location from which the code is derived.)
248
+
249
+ THIS SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS," AND COPYRIGHT
250
+ HOLDERS MAKE NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED,
251
+ INCLUDING BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY OR FITNESS
252
+ FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE OR
253
+ DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS,
254
+ TRADEMARKS OR OTHER RIGHTS.
255
+
256
+ COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL
257
+ OR CONSEQUENTIAL DAMAGES ARISING OUT OF ANY USE OF THE SOFTWARE OR
258
+ DOCUMENTATION.
259
+
260
+ The name and trademarks of copyright holders may NOT be used in
261
+ advertising or publicity pertaining to the software without specific,
262
+ written prior permission. Title to copyright in this software and
263
+ any associated documentation will at all times remain with
264
+ copyright holders.
package/README.md ADDED
@@ -0,0 +1,119 @@
1
+ # Spacecat Shared - LaunchDarkly Client
2
+
3
+ A lightweight LaunchDarkly client wrapper for checking feature flags in SpaceCat services.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @adobe/spacecat-shared-launchdarkly-client
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Basic Example
14
+
15
+ ```javascript
16
+ import { LaunchDarklyClient } from '@adobe/spacecat-shared-launchdarkly-client';
17
+
18
+ // Create client from Universal context
19
+ const ldClient = LaunchDarklyClient.createFrom(context);
20
+
21
+ // Check if flag is enabled for an IMS organization
22
+ const imsOrgId = '855422996904EB9F0A495F9A@AdobeOrg';
23
+ const isEnabled = await ldClient.isFlagEnabledForIMSOrg('FT_LLMO-2817', imsOrgId);
24
+
25
+ if (isEnabled) {
26
+ // Feature is enabled for this organization
27
+ console.log('Feature enabled');
28
+ } else {
29
+ // Feature is disabled
30
+ console.log('Feature disabled');
31
+ }
32
+ ```
33
+
34
+ ### In a Request Handler
35
+
36
+ ```javascript
37
+ import { LaunchDarklyClient } from '@adobe/spacecat-shared-launchdarkly-client';
38
+
39
+ export default async function handler(request, context) {
40
+ // Initialize client once (reuse across requests)
41
+ const ldClient = LaunchDarklyClient.createFrom(context);
42
+
43
+ // Get IMS org from request
44
+ const imsOrgId = request.headers.get('x-ims-org-id');
45
+
46
+ // Check feature flag
47
+ const isEnabled = await ldClient.isFlagEnabledForIMSOrg(
48
+ 'FT_LLMO-2817',
49
+ imsOrgId
50
+ );
51
+
52
+ if (isEnabled) {
53
+ // New feature logic
54
+ return executeNewFeature(request);
55
+ }
56
+
57
+ // Default/legacy logic
58
+ return executeLegacyFeature(request);
59
+ }
60
+ ```
61
+
62
+ ### With Custom User Key (Optional)
63
+
64
+ ```javascript
65
+ const ldClient = LaunchDarklyClient.createFrom(context);
66
+
67
+ // Provide a user key for tracking (defaults to 'anonymous')
68
+ const isEnabled = await ldClient.isFlagEnabledForIMSOrg(
69
+ 'FT_LLMO-2817',
70
+ imsOrgId,
71
+ 'user-123' // optional user key for analytics
72
+ );
73
+ ```
74
+
75
+ ## API
76
+
77
+ ### `isFlagEnabledForIMSOrg(flagKey, imsOrgId, userKey?)`
78
+
79
+ Checks if a feature flag is enabled for a specific IMS organization.
80
+
81
+ **Parameters:**
82
+ - `flagKey` (string, required) - The LaunchDarkly feature flag key
83
+ - `imsOrgId` (string, required) - The IMS organization ID (e.g., `"855422996904EB9F0A495F9A@AdobeOrg"`)
84
+ - `userKey` (string, optional) - User identifier for tracking (defaults to `"anonymous"`)
85
+
86
+ **Returns:** `Promise<boolean>` - `true` if flag is enabled, `false` otherwise
87
+
88
+ ## Environment Variables
89
+
90
+ Set the following environment variable:
91
+
92
+ ```bash
93
+ export LAUNCHDARKLY_SDK_KEY="sdk-your-server-side-key-here"
94
+ ```
95
+
96
+ **Note:** Use a **server-side SDK key** (starts with `sdk-`), not a client-side ID.
97
+
98
+ ## LaunchDarkly Configuration
99
+
100
+ In your LaunchDarkly dashboard, configure targeting rules using:
101
+ - **Attribute:** `organization identityProviderId`
102
+ - **Operator:** `is one of`
103
+ - **Values:** List of IMS org IDs
104
+
105
+ ## Testing
106
+
107
+ ```bash
108
+ npm test
109
+ ```
110
+
111
+ ## License
112
+
113
+ Apache-2.0
114
+
115
+ ## Additional Information
116
+
117
+ - **Repository**: [GitHub](https://github.com/adobe/spacecat-shared)
118
+ - **Issues**: [GitHub Issues](https://github.com/adobe/spacecat-shared/issues)
119
+ - **LaunchDarkly Docs**: [Node.js SDK](https://docs.launchdarkly.com/sdk/server-side/node-js)
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@adobe/spacecat-shared-launchdarkly-client",
3
+ "version": "1.0.0",
4
+ "description": "Shared modules of the Spacecat Services - LaunchDarkly Client",
5
+ "type": "module",
6
+ "engines": {
7
+ "node": ">=22.0.0 <25.0.0",
8
+ "npm": ">=10.9.0 <12.0.0"
9
+ },
10
+ "main": "src/index.js",
11
+ "types": "src/index.d.ts",
12
+ "scripts": {
13
+ "test": "c8 mocha --timeout 30000",
14
+ "lint": "eslint .",
15
+ "clean": "rm -rf package-lock.json node_modules"
16
+ },
17
+ "mocha": {
18
+ "reporter": "mocha-multi-reporters",
19
+ "reporter-options": "configFile=.mocha-multi.json",
20
+ "spec": "test/**/*.test.js"
21
+ },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "https://github.com/adobe/spacecat-shared.git"
25
+ },
26
+ "author": "",
27
+ "license": "Apache-2.0",
28
+ "bugs": {
29
+ "url": "https://github.com/adobe/spacecat-shared/issues"
30
+ },
31
+ "homepage": "https://github.com/adobe/spacecat-shared#readme",
32
+ "publishConfig": {
33
+ "access": "public"
34
+ },
35
+ "dependencies": {
36
+ "@adobe/helix-universal": "5.4.0",
37
+ "@adobe/spacecat-shared-utils": "1.81.1",
38
+ "@launchdarkly/node-server-sdk": "^9.9.7"
39
+ },
40
+ "devDependencies": {
41
+ "chai": "6.2.1",
42
+ "chai-as-promised": "8.0.2",
43
+ "esmock": "2.7.3",
44
+ "nock": "14.0.10",
45
+ "sinon": "21.0.0",
46
+ "sinon-chai": "4.0.1",
47
+ "typescript": "5.9.3"
48
+ }
49
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,56 @@
1
+ /*
2
+ * Copyright 2025 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ import type { LDOptions, LDContext, LDFlagValue } from '@launchdarkly/node-server-sdk';
14
+
15
+ export interface LaunchDarklyConfig {
16
+ sdkKey: string;
17
+ options?: LDOptions;
18
+ }
19
+
20
+ export interface UniversalContext {
21
+ env: {
22
+ LAUNCHDARKLY_SDK_KEY: string;
23
+ [key: string]: any;
24
+ };
25
+ log: {
26
+ info: (message: string, ...args: any[]) => void;
27
+ error: (message: string, ...args: any[]) => void;
28
+ debug: (message: string, ...args: any[]) => void;
29
+ warn: (message: string, ...args: any[]) => void;
30
+ };
31
+ }
32
+
33
+ export interface Logger {
34
+ info: (message: string, ...args: any[]) => void;
35
+ error: (message: string, ...args: any[]) => void;
36
+ debug: (message: string, ...args: any[]) => void;
37
+ warn: (message: string, ...args: any[]) => void;
38
+ }
39
+
40
+ export declare class LaunchDarklyClient {
41
+ constructor(config: LaunchDarklyConfig, log?: Logger);
42
+
43
+ static createFrom(context: UniversalContext): LaunchDarklyClient;
44
+
45
+ init(): Promise<void>;
46
+
47
+ variation(flagKey: string, context: LDContext, defaultValue: LDFlagValue): Promise<LDFlagValue>;
48
+
49
+ isFlagEnabledForIMSOrg(
50
+ flagKey: string,
51
+ imsOrgId: string,
52
+ userKey?: string
53
+ ): Promise<boolean>;
54
+ }
55
+
56
+ export { LaunchDarklyClient as default };
package/src/index.js ADDED
@@ -0,0 +1,16 @@
1
+ /*
2
+ * Copyright 2025 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ import LaunchDarklyClient from './launchdarkly-client.js';
14
+
15
+ export { LaunchDarklyClient };
16
+ export default LaunchDarklyClient;
@@ -0,0 +1,130 @@
1
+ /*
2
+ * Copyright 2025 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ import * as ld from '@launchdarkly/node-server-sdk';
14
+
15
+ /**
16
+ * LaunchDarkly Client wrapper for SpaceCat services
17
+ */
18
+ class LaunchDarklyClient {
19
+ /**
20
+ * Creates a LaunchDarklyClient instance from a Universal context
21
+ * @param {Object} context - The Universal context object
22
+ * @param {Object} context.env - Environment variables
23
+ * @param {string} context.env.LD_SDK_KEY - LaunchDarkly SDK key
24
+ * @param {Object} context.log - Logger instance
25
+ * @returns {LaunchDarklyClient} A new LaunchDarklyClient instance
26
+ */
27
+ static createFrom(context) {
28
+ const {
29
+ LD_SDK_KEY: sdkKey,
30
+ } = context.env;
31
+ return new LaunchDarklyClient({ sdkKey }, context.log);
32
+ }
33
+
34
+ /**
35
+ * Creates a new LaunchDarklyClient instance
36
+ * @param {Object} config - Configuration object
37
+ * @param {string} config.sdkKey - LaunchDarkly SDK key
38
+ * @param {Object} [config.options] - Additional LaunchDarkly SDK options
39
+ * @param {Object} [log=console] - Logger instance
40
+ */
41
+ constructor(config, log = console) {
42
+ const { sdkKey, options = {} } = config;
43
+
44
+ if (!sdkKey) {
45
+ throw new Error('LaunchDarkly SDK key is required');
46
+ }
47
+
48
+ this.sdkKey = sdkKey;
49
+ this.options = options;
50
+ this.log = log;
51
+ this.client = null;
52
+ this.initPromise = null;
53
+ }
54
+
55
+ /**
56
+ * Initializes the LaunchDarkly client
57
+ * @returns {Promise<void>}
58
+ */
59
+ async init() {
60
+ // If already initialized, return immediately
61
+ if (this.client) {
62
+ return undefined;
63
+ }
64
+
65
+ // If initialization is in progress, wait for it
66
+ if (this.initPromise) {
67
+ await this.initPromise;
68
+ return undefined;
69
+ }
70
+
71
+ // Start initialization
72
+ this.initPromise = (async () => {
73
+ try {
74
+ this.client = ld.init(this.sdkKey, this.options);
75
+ await this.client.waitForInitialization();
76
+ this.log.info('LaunchDarkly client initialized successfully');
77
+ } catch (error) {
78
+ this.log.error('Failed to initialize LaunchDarkly client:', error);
79
+ throw error;
80
+ }
81
+ })();
82
+
83
+ await this.initPromise;
84
+ return undefined;
85
+ }
86
+
87
+ /**
88
+ * Evaluates a feature flag for a given context
89
+ * @param {string} flagKey - The feature flag key
90
+ * @param {Object} context - The LaunchDarkly context (user/application context)
91
+ * @param {*} defaultValue - Default value if flag evaluation fails
92
+ * @returns {Promise<*>} The evaluated flag value
93
+ */
94
+ async variation(flagKey, context, defaultValue) {
95
+ await this.init();
96
+
97
+ try {
98
+ const value = await this.client.variation(flagKey, context, defaultValue);
99
+ this.log.debug(`Flag "${flagKey}" evaluated to:`, value);
100
+ return value;
101
+ } catch (error) {
102
+ this.log.error(`Error evaluating flag "${flagKey}":`, error);
103
+ return defaultValue;
104
+ }
105
+ }
106
+
107
+ /**
108
+ * Check if a feature flag is enabled for a specific IMS organization
109
+ * @param {string} flagKey - The feature flag key
110
+ * @param {string} imsOrgId - The IMS organization ID
111
+ * @param {string} [userKey='anonymous'] - Optional user key for tracking
112
+ * @returns {Promise<boolean>} True if flag is enabled for the IMS org, false otherwise
113
+ */
114
+ async isFlagEnabledForIMSOrg(flagKey, imsOrgId, userKey = 'anonymous') {
115
+ const context = {
116
+ kind: 'multi',
117
+ user: {
118
+ key: userKey,
119
+ },
120
+ organization: {
121
+ key: imsOrgId,
122
+ identityProviderId: imsOrgId,
123
+ },
124
+ };
125
+
126
+ return this.variation(flagKey, context, false);
127
+ }
128
+ }
129
+
130
+ export default LaunchDarklyClient;
@@ -0,0 +1,32 @@
1
+ /*
2
+ * Copyright 2025 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ /* eslint-env mocha */
14
+
15
+ import { expect } from 'chai';
16
+ import DefaultExport, { LaunchDarklyClient } from '../src/index.js';
17
+
18
+ describe('Module Exports', () => {
19
+ it('should export LaunchDarklyClient as named export', () => {
20
+ expect(LaunchDarklyClient).to.be.a('function');
21
+ expect(LaunchDarklyClient.name).to.equal('LaunchDarklyClient');
22
+ });
23
+
24
+ it('should export LaunchDarklyClient as default export', () => {
25
+ expect(DefaultExport).to.be.a('function');
26
+ expect(DefaultExport.name).to.equal('LaunchDarklyClient');
27
+ });
28
+
29
+ it('should have both exports reference the same constructor', () => {
30
+ expect(DefaultExport).to.equal(LaunchDarklyClient);
31
+ });
32
+ });
@@ -0,0 +1,349 @@
1
+ /*
2
+ * Copyright 2025 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ /* eslint-env mocha */
14
+
15
+ import { expect, use } from 'chai';
16
+ import chaiAsPromised from 'chai-as-promised';
17
+ import sinon from 'sinon';
18
+ import sinonChai from 'sinon-chai';
19
+ import esmock from 'esmock';
20
+
21
+ use(chaiAsPromised);
22
+ use(sinonChai);
23
+
24
+ describe('LaunchDarklyClient', () => {
25
+ let LaunchDarklyClient;
26
+ let mockClient;
27
+ let mockInit;
28
+ const testSdkKey = 'sdk-test-key-12345';
29
+
30
+ before(async () => {
31
+ // Create a mock LaunchDarkly client
32
+ mockClient = {
33
+ waitForInitialization: sinon.stub().resolves(),
34
+ variation: sinon.stub().resolves(true),
35
+ close: sinon.stub().resolves(),
36
+ };
37
+
38
+ // Mock ld.init
39
+ mockInit = sinon.stub().returns(mockClient);
40
+
41
+ // Use esmock to mock the LaunchDarkly SDK dependency
42
+ const module = await esmock('../src/launchdarkly-client.js', {
43
+ '@launchdarkly/node-server-sdk': {
44
+ init: mockInit,
45
+ },
46
+ });
47
+
48
+ LaunchDarklyClient = module.default;
49
+ });
50
+
51
+ afterEach(() => {
52
+ sinon.resetHistory();
53
+ });
54
+
55
+ describe('constructor', () => {
56
+ it('should create instance with valid config', () => {
57
+ const client = new LaunchDarklyClient({ sdkKey: testSdkKey });
58
+
59
+ expect(client).to.be.instanceOf(LaunchDarklyClient);
60
+ expect(client.sdkKey).to.equal(testSdkKey);
61
+ });
62
+
63
+ it('should throw error when SDK key is missing', () => {
64
+ expect(() => new LaunchDarklyClient({})).to.throw('LaunchDarkly SDK key is required');
65
+ });
66
+
67
+ it('should throw error when SDK key is undefined', () => {
68
+ expect(() => new LaunchDarklyClient({ sdkKey: undefined }))
69
+ .to.throw('LaunchDarkly SDK key is required');
70
+ });
71
+
72
+ it('should accept custom logger', () => {
73
+ const customLog = {
74
+ info: sinon.stub(),
75
+ error: sinon.stub(),
76
+ debug: sinon.stub(),
77
+ warn: sinon.stub(),
78
+ };
79
+ const client = new LaunchDarklyClient({ sdkKey: testSdkKey }, customLog);
80
+
81
+ expect(client.log).to.equal(customLog);
82
+ });
83
+
84
+ it('should use console as default logger', () => {
85
+ const client = new LaunchDarklyClient({ sdkKey: testSdkKey });
86
+
87
+ expect(client.log).to.equal(console);
88
+ });
89
+ });
90
+
91
+ describe('createFrom', () => {
92
+ it('should create instance from context', () => {
93
+ const context = {
94
+ env: {
95
+ LD_SDK_KEY: testSdkKey,
96
+ },
97
+ log: {
98
+ info: sinon.stub(),
99
+ error: sinon.stub(),
100
+ debug: sinon.stub(),
101
+ warn: sinon.stub(),
102
+ },
103
+ };
104
+
105
+ const client = LaunchDarklyClient.createFrom(context);
106
+
107
+ expect(client).to.be.instanceOf(LaunchDarklyClient);
108
+ expect(client.sdkKey).to.equal(testSdkKey);
109
+ expect(client.log).to.equal(context.log);
110
+ });
111
+
112
+ it('should throw error when SDK key is missing from context', () => {
113
+ const context = {
114
+ env: {},
115
+ log: {
116
+ info: sinon.stub(),
117
+ error: sinon.stub(),
118
+ debug: sinon.stub(),
119
+ warn: sinon.stub(),
120
+ },
121
+ };
122
+
123
+ expect(() => LaunchDarklyClient.createFrom(context))
124
+ .to.throw('LaunchDarkly SDK key is required');
125
+ });
126
+ });
127
+
128
+ describe('init', () => {
129
+ it('should initialize LaunchDarkly client', async () => {
130
+ const customLog = {
131
+ info: sinon.stub(),
132
+ error: sinon.stub(),
133
+ debug: sinon.stub(),
134
+ warn: sinon.stub(),
135
+ };
136
+ const client = new LaunchDarklyClient({ sdkKey: testSdkKey }, customLog);
137
+
138
+ await client.init();
139
+
140
+ expect(mockInit).to.have.been.calledOnceWith(testSdkKey, {});
141
+ expect(mockClient.waitForInitialization).to.have.been.calledOnce;
142
+ expect(customLog.info).to.have.been.calledWith('LaunchDarkly client initialized successfully');
143
+ });
144
+
145
+ it('should return undefined if already initialized', async () => {
146
+ const client = new LaunchDarklyClient({ sdkKey: testSdkKey });
147
+ await client.init();
148
+
149
+ const result = await client.init();
150
+
151
+ expect(result).to.be.undefined;
152
+ expect(mockInit).to.have.been.calledOnce;
153
+ });
154
+
155
+ it('should handle concurrent initialization calls', async () => {
156
+ const client = new LaunchDarklyClient({ sdkKey: testSdkKey });
157
+
158
+ // Start first init but don't await it yet
159
+ const firstInit = client.init();
160
+
161
+ // Immediately call init again while first one is in progress
162
+ const secondInit = client.init();
163
+ const thirdInit = client.init();
164
+
165
+ const [result1, result2, result3] = await Promise.all([
166
+ firstInit,
167
+ secondInit,
168
+ thirdInit,
169
+ ]);
170
+
171
+ expect(result1).to.be.undefined;
172
+ expect(result2).to.be.undefined;
173
+ expect(result3).to.be.undefined;
174
+ expect(mockInit).to.have.been.calledOnce;
175
+ });
176
+
177
+ it('should handle sequential initialization calls', async () => {
178
+ const client = new LaunchDarklyClient({ sdkKey: testSdkKey });
179
+
180
+ // First initialization
181
+ await client.init();
182
+
183
+ // Try to initialize again after completion
184
+ const result = await client.init();
185
+
186
+ expect(result).to.be.undefined;
187
+ expect(mockInit).to.have.been.calledOnce;
188
+ });
189
+
190
+ it('should wait for initPromise when concurrent calls happen', async () => {
191
+ const client = new LaunchDarklyClient({ sdkKey: testSdkKey });
192
+
193
+ // Manually create a scenario where initPromise exists
194
+ // This simulates the exact moment between two concurrent init() calls
195
+ let resolvePromise;
196
+ const testPromise = new Promise((resolve) => {
197
+ resolvePromise = resolve;
198
+ });
199
+
200
+ // Set initPromise directly to simulate initialization in progress
201
+ client.initPromise = testPromise;
202
+
203
+ // Temporarily set client to null to force the code path
204
+ const originalClient = client.client;
205
+ client.client = null;
206
+
207
+ // Now call init() - this should hit lines 66-68
208
+ const initCall = client.init();
209
+
210
+ // Verify we're waiting
211
+ expect(client.initPromise).to.equal(testPromise);
212
+
213
+ // Restore client and resolve
214
+ client.client = originalClient;
215
+ resolvePromise();
216
+
217
+ // Wait for init to complete
218
+ const result = await initCall;
219
+ expect(result).to.be.undefined;
220
+ });
221
+
222
+ it('should throw error if initialization fails', async () => {
223
+ const customLog = {
224
+ info: sinon.stub(),
225
+ error: sinon.stub(),
226
+ debug: sinon.stub(),
227
+ warn: sinon.stub(),
228
+ };
229
+ const initError = new Error('Initialization failed');
230
+ mockClient.waitForInitialization.rejects(initError);
231
+
232
+ const client = new LaunchDarklyClient({ sdkKey: testSdkKey }, customLog);
233
+
234
+ await expect(client.init()).to.be.rejectedWith('Initialization failed');
235
+ expect(customLog.error).to.have.been.calledWith('Failed to initialize LaunchDarkly client:', initError);
236
+
237
+ // Reset for other tests
238
+ mockClient.waitForInitialization.resolves();
239
+ });
240
+ });
241
+
242
+ describe('variation', () => {
243
+ it('should evaluate a feature flag', async () => {
244
+ const customLog = {
245
+ info: sinon.stub(),
246
+ error: sinon.stub(),
247
+ debug: sinon.stub(),
248
+ warn: sinon.stub(),
249
+ };
250
+ const client = new LaunchDarklyClient({ sdkKey: testSdkKey }, customLog);
251
+ const context = { kind: 'user', key: 'test-user' };
252
+
253
+ mockClient.variation.resolves(true);
254
+
255
+ const result = await client.variation('test-flag', context, false);
256
+
257
+ expect(result).to.be.true;
258
+ expect(mockClient.variation).to.have.been.calledWith('test-flag', context, false);
259
+ expect(customLog.debug).to.have.been.calledWith('Flag "test-flag" evaluated to:', true);
260
+ });
261
+
262
+ it('should return default value on error', async () => {
263
+ const customLog = {
264
+ info: sinon.stub(),
265
+ error: sinon.stub(),
266
+ debug: sinon.stub(),
267
+ warn: sinon.stub(),
268
+ };
269
+ const client = new LaunchDarklyClient({ sdkKey: testSdkKey }, customLog);
270
+ const context = { kind: 'user', key: 'test-user' };
271
+ const flagError = new Error('Flag evaluation failed');
272
+
273
+ mockClient.variation.rejects(flagError);
274
+
275
+ const result = await client.variation('test-flag', context, false);
276
+
277
+ expect(result).to.be.false;
278
+ expect(customLog.error).to.have.been.calledWith('Error evaluating flag "test-flag":', flagError);
279
+
280
+ // Reset for other tests
281
+ mockClient.variation.resolves(true);
282
+ });
283
+ });
284
+
285
+ describe('isFlagEnabledForIMSOrg', () => {
286
+ it('should check if flag is enabled for IMS org', async () => {
287
+ const client = new LaunchDarklyClient({ sdkKey: testSdkKey });
288
+ mockClient.variation.resolves(true);
289
+
290
+ const result = await client.isFlagEnabledForIMSOrg(
291
+ 'FT_LLMO-2817',
292
+ '855422996904EB9F0A495F9A@AdobeOrg',
293
+ );
294
+
295
+ expect(result).to.be.true;
296
+ expect(mockClient.variation).to.have.been.calledWith(
297
+ 'FT_LLMO-2817',
298
+ {
299
+ kind: 'multi',
300
+ user: { key: 'anonymous' },
301
+ organization: {
302
+ key: '855422996904EB9F0A495F9A@AdobeOrg',
303
+ identityProviderId: '855422996904EB9F0A495F9A@AdobeOrg',
304
+ },
305
+ },
306
+ false,
307
+ );
308
+ });
309
+
310
+ it('should use custom user key when provided', async () => {
311
+ const client = new LaunchDarklyClient({ sdkKey: testSdkKey });
312
+ mockClient.variation.resolves(false);
313
+
314
+ const result = await client.isFlagEnabledForIMSOrg(
315
+ 'test-flag',
316
+ 'test-org-id',
317
+ 'custom-user',
318
+ );
319
+
320
+ expect(result).to.be.false;
321
+ expect(mockClient.variation).to.have.been.calledWith(
322
+ 'test-flag',
323
+ {
324
+ kind: 'multi',
325
+ user: { key: 'custom-user' },
326
+ organization: {
327
+ key: 'test-org-id',
328
+ identityProviderId: 'test-org-id',
329
+ },
330
+ },
331
+ false,
332
+ );
333
+ });
334
+ });
335
+
336
+ describe('API surface', () => {
337
+ it('should expose expected public methods', () => {
338
+ const client = new LaunchDarklyClient({ sdkKey: testSdkKey });
339
+
340
+ // Should have these instance methods
341
+ expect(client).to.respondTo('init');
342
+ expect(client).to.respondTo('variation');
343
+ expect(client).to.respondTo('isFlagEnabledForIMSOrg');
344
+
345
+ // Should have static method
346
+ expect(LaunchDarklyClient.createFrom).to.be.a('function');
347
+ });
348
+ });
349
+ });