@adobe/spacecat-shared-tier-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.
@@ -0,0 +1,6 @@
1
+ {
2
+ "reporterEnabled": "spec,xunit",
3
+ "xunitReporterOptions": {
4
+ "output": "junit/test-results.xml"
5
+ }
6
+ }
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,21 @@
1
+ # @adobe/spacecat-shared-tier-client-v1.0.0 (2025-09-16)
2
+
3
+
4
+ ### Features
5
+
6
+ * Tier client ([#961](https://github.com/adobe/spacecat-shared/issues/961)) ([2d95d07](https://github.com/adobe/spacecat-shared/commit/2d95d070a55e2ec702faf3bf94c046836b79528a))
7
+
8
+ # [@adobe/spacecat-shared-tier-client-v1.0.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-tier-client-v1.0.0...@adobe/spacecat-shared-tier-client-v1.0.0) (2025-01-27)
9
+
10
+ ### Features
11
+
12
+ * **tier-client:** initial implementation of TierClient for managing entitlements and site enrollments ([#1](https://github.com/adobe/spacecat-shared/issues/1)) ([initial-commit](https://github.com/adobe/spacecat-shared/commit/initial-commit))
13
+
14
+ ### Bug Fixes
15
+
16
+ * Initial release with basic functionality for entitlement and site enrollment management
17
+
18
+ ### Documentation
19
+
20
+ * Add comprehensive README with usage examples and API documentation
21
+ * Add TypeScript definitions for better IDE support
@@ -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 Spacecat Shared
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,263 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions
133
+ of this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing
141
+ the origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
203
+
204
+ APACHE JACKRABBIT SUBCOMPONENTS
205
+
206
+ Apache Jackrabbit includes parts with separate copyright notices and license
207
+ terms. Your use of these subcomponents is subject to the terms and conditions
208
+ of the following licenses:
209
+
210
+ XPath 2.0/XQuery 1.0 Parser:
211
+ http://www.w3.org/2002/11/xquery-xpath-applets/xgrammar.zip
212
+
213
+ Copyright (C) 2002 World Wide Web Consortium, (Massachusetts Institute of
214
+ Technology, European Research Consortium for Informatics and Mathematics,
215
+ Keio University). All Rights Reserved.
216
+
217
+ This work is distributed under the W3C(R) Software License in the hope
218
+ that it will be useful, but WITHOUT ANY WARRANTY; without even the
219
+ implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
220
+
221
+ W3C(R) SOFTWARE NOTICE AND LICENSE
222
+ http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231
223
+
224
+ This work (and included software, documentation such as READMEs, or
225
+ other related items) is being provided by the copyright holders under
226
+ the following license. By obtaining, using and/or copying this work,
227
+ you (the licensee) agree that you have read, understood, and will comply
228
+ with the following terms and conditions.
229
+
230
+ Permission to copy, modify, and distribute this software and its
231
+ documentation, with or without modification, for any purpose and
232
+ without fee or royalty is hereby granted, provided that you include
233
+ the following on ALL copies of the software and documentation or
234
+ portions thereof, including modifications:
235
+
236
+ 1. The full text of this NOTICE in a location viewable to users
237
+ of the redistributed or derivative work.
238
+
239
+ 2. Any pre-existing intellectual property disclaimers, notices,
240
+ or terms and conditions. If none exist, the W3C Software Short
241
+ Notice should be included (hypertext is preferred, text is
242
+ permitted) within the body of any redistributed or derivative code.
243
+
244
+ 3. Notice of any changes or modifications to the files, including
245
+ the date changes were made. (We recommend you provide URIs to the
246
+ location from which the code is derived.)
247
+
248
+ THIS SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS," AND COPYRIGHT
249
+ HOLDERS MAKE NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED,
250
+ INCLUDING BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY OR FITNESS
251
+ FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE OR
252
+ DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS,
253
+ TRADEMARKS OR OTHER RIGHTS.
254
+
255
+ COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL
256
+ OR CONSEQUENTIAL DAMAGES ARISING OUT OF ANY USE OF THE SOFTWARE OR
257
+ DOCUMENTATION.
258
+
259
+ The name and trademarks of copyright holders may NOT be used in
260
+ advertising or publicity pertaining to the software without specific,
261
+ written prior permission. Title to copyright in this software and
262
+ any associated documentation will at all times remain with
263
+ copyright holders.
package/README.md ADDED
@@ -0,0 +1,221 @@
1
+ # Spacecat Shared - Tier Client
2
+
3
+ ## Overview
4
+
5
+ The TierClient library provides methods to manage entitlements and site enrollments for the Spacecat Services. This client facilitates the creation and validation of product entitlements and site enrollments for organizations and sites.
6
+
7
+ ## Installation
8
+
9
+ Include the TierClient in your project by importing it from the package. Ensure that dependencies such as `@adobe/spacecat-shared-utils` and `@adobe/spacecat-shared-data-access` are also installed in your project.
10
+
11
+ ```javascript
12
+ import TierClient from '@adobe/spacecat-shared-tier-client';
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ### Creating a TierClient Instance
18
+
19
+ There are three ways to create a TierClient instance:
20
+
21
+ #### 1. Using Static Factory Methods (Recommended)
22
+
23
+ **For Organization-only operations:**
24
+ ```javascript
25
+ const context = {
26
+ dataAccess: {
27
+ Entitlement: /* Entitlement data access object */,
28
+ SiteEnrollment: /* SiteEnrollment data access object */,
29
+ Organization: /* Organization data access object */,
30
+ Site: /* Site data access object */,
31
+ OrganizationIdentityProvider: /* OrganizationIdentityProvider data access object */,
32
+ },
33
+ log: {
34
+ info: (message) => console.log(message),
35
+ error: (message) => console.error(message),
36
+ },
37
+ };
38
+
39
+ const organization = {
40
+ getId: () => 'your-org-id',
41
+ };
42
+
43
+ const productCode = 'LLMO';
44
+
45
+ // Create client for organization-only operations
46
+ const orgClient = TierClient.createForOrg(context, organization, productCode);
47
+ ```
48
+
49
+ **For Site-specific operations:**
50
+ ```javascript
51
+ const site = {
52
+ getId: () => 'your-site-id',
53
+ getOrganizationId: () => 'your-org-id', // or getOrganization() method
54
+ };
55
+
56
+ // Create client for site operations
57
+ const siteClient = TierClient.createForSite(context, site, productCode);
58
+ ```
59
+
60
+ #### 2. Direct Constructor Usage
61
+
62
+ ```javascript
63
+ const context = {
64
+ dataAccess: {
65
+ Entitlement: /* Entitlement data access object */,
66
+ SiteEnrollment: /* SiteEnrollment data access object */,
67
+ Organization: /* Organization data access object */,
68
+ Site: /* Site data access object */,
69
+ OrganizationIdentityProvider: /* OrganizationIdentityProvider data access object */,
70
+ },
71
+ log: {
72
+ info: (message) => console.log(message),
73
+ error: (message) => console.error(message),
74
+ },
75
+ };
76
+
77
+ const orgId = 'your-org-id';
78
+ const siteId = 'your-site-id'; // Optional for organization-only operations
79
+ const productCode = 'LLMO';
80
+
81
+ const tierClient = new TierClient(context, orgId, siteId, productCode);
82
+ ```
83
+
84
+ ### Checking Valid Entitlement
85
+
86
+ To check for valid entitlement and site enrollment, use the `checkValidEntitlement` method.
87
+
88
+ ```javascript
89
+ async function checkEntitlement() {
90
+ try {
91
+ const result = await tierClient.checkValidEntitlement();
92
+
93
+ if (result.entitlement) {
94
+ console.log('Valid entitlement found:', result.entitlement.getId());
95
+ }
96
+
97
+ if (result.siteEnrollment) {
98
+ console.log('Valid site enrollment found:', result.siteEnrollment.getId());
99
+ }
100
+
101
+ if (!result.entitlement) {
102
+ console.log('No valid entitlement found');
103
+ }
104
+ } catch (error) {
105
+ console.error('Error checking entitlement:', error);
106
+ }
107
+ }
108
+
109
+ checkEntitlement();
110
+ ```
111
+
112
+ ### Creating Entitlement
113
+
114
+ To create a new entitlement and site enrollment, use the `createEntitlement` method.
115
+
116
+ ```javascript
117
+ async function createEntitlement() {
118
+ try {
119
+ const tier = 'FREE_TRIAL'; // Valid tiers: FREE_TRIAL, PAID, etc.
120
+ const result = await tierClient.createEntitlement(tier);
121
+
122
+ console.log('Created entitlement:', result.entitlement.getId());
123
+ console.log('Created site enrollment:', result.siteEnrollment.getId());
124
+ } catch (error) {
125
+ console.error('Error creating entitlement:', error);
126
+ }
127
+ }
128
+
129
+ createEntitlement();
130
+ ```
131
+
132
+ ## API Reference
133
+
134
+ ### Static Factory Methods
135
+
136
+ #### TierClient.createForOrg(context, organization, productCode)
137
+
138
+ Creates a TierClient for organization-only operations.
139
+
140
+ **Parameters:**
141
+ - `context` (object): Context object containing dataAccess and log
142
+ - `organization` (object): Organization object with getId() method
143
+ - `productCode` (string): Product code (required)
144
+
145
+ **Returns:** TierClient instance for organization operations
146
+
147
+ #### TierClient.createForSite(context, site, productCode)
148
+
149
+ Creates a TierClient for site-specific operations.
150
+
151
+ **Parameters:**
152
+ - `context` (object): Context object containing dataAccess and log
153
+ - `site` (object): Site object with getId() method and either getOrganizationId() or getOrganization() method
154
+ - `productCode` (string): Product code (required)
155
+
156
+ **Returns:** TierClient instance for site operations
157
+
158
+ ### Constructor
159
+
160
+ #### TierClient(context, orgId, siteId, productCode)
161
+
162
+ Creates a new TierClient instance directly.
163
+
164
+ **Parameters:**
165
+ - `context` (object): Context object containing dataAccess and log
166
+ - `orgId` (string): Organization ID (required)
167
+ - `siteId` (string|null|undefined): Site ID (optional for organization-only operations)
168
+ - `productCode` (string): Product code (required)
169
+
170
+ **Returns:** TierClient instance
171
+
172
+ ### checkValidEntitlement()
173
+
174
+ Checks for valid entitlement on organization and valid site enrollment on site.
175
+
176
+ **Returns:** Promise<object> - Object with entitlement and/or siteEnrollment based on what exists
177
+
178
+ ### createEntitlement(tier)
179
+
180
+ Creates entitlement for organization and site enrollment for site.
181
+
182
+ **Parameters:**
183
+ - `tier` (string): Entitlement tier (must be a valid tier from EntitlementModel.TIERS)
184
+
185
+ **Returns:** Promise<object> - Object with created entitlement and siteEnrollment
186
+
187
+ ## Error Handling
188
+
189
+ All methods return promises. It's important to handle errors using `try/catch` blocks in async functions to manage database errors or validation failures gracefully.
190
+
191
+ ## Development
192
+
193
+ ### Testing
194
+
195
+ To run tests:
196
+
197
+ ```bash
198
+ npm test
199
+ ```
200
+
201
+ ### Linting
202
+
203
+ Lint your code:
204
+
205
+ ```bash
206
+ npm run lint
207
+ ```
208
+
209
+ ### Cleaning
210
+
211
+ To remove `node_modules` and `package-lock.json`:
212
+
213
+ ```bash
214
+ npm run clean
215
+ ```
216
+
217
+ ## Additional Information
218
+
219
+ - **Repository**: [GitHub](https://github.com/adobe/spacecat-shared.git)
220
+ - **Issue Tracking**: [GitHub Issues](https://github.com/adobe/spacecat-shared/issues)
221
+ - **License**: Apache-2.0