feat: auto-create product entitlement and site enrollment via x-product header#2432
Open
radhikagpt1208 wants to merge 2 commits into
Open
feat: auto-create product entitlement and site enrollment via x-product header#2432radhikagpt1208 wants to merge 2 commits into
radhikagpt1208 wants to merge 2 commits into
Conversation
Regenerate the lockfile after main was merged in: the previous lockfile
referenced older versions of @adobe/spacecat-shared-* and @aws-sdk/*
packages and was missing xml-naming@0.1.0, causing `npm ci` to fail in
CI with EUSAGE ("lock file's X@a does not satisfy X@b").
Co-authored-by: Cursor <cursoragent@cursor.com>
|
This PR will trigger a minor release when merged. |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an opt-in
x-productheader toPOST /sitesandPOST /organizationsthat triggers auto-creation of the org's product entitlement (FREE_TRIALtier) and — for sites — the correspondingSiteEnrollment, by delegating toTierClient(which is idempotent at the library level: existing entitlements/enrollments are reused).Without the header the endpoints behave exactly as before, preserving backward compatibility for callers that manage entitlements separately.
Jira: SITES-44944
Problem
GET /organizations/:orgId/sitesfilters results throughfilterSitesForProductCode(), which keeps only sites that have aSiteEnrollmentrow for the org'sEntitlement:Sites onboarded through the
aem-aso-trialflow are persisted in Spacecat but never get anEntitlement/SiteEnrollment, so they get filtered out of the product-scoped listing. The downstream effect: ASO Preflight breaks ("site is not supported for this widget") for trial customers, blocking the technical-validation flow used in customer workshops.This was previously masked by loose
(env id + program)matching that picked the first matching site — effectively a bug, surfaced once provisioning was tightened. The team had been working around it with manualset imsorgSlack admin commands per site.Once the trial flow (
aem-aso-trial) passesx-product: ASOonPOST /sites(andPOST /organizations), new trial sites are enrolled out-of-the-box and Preflight works without any manual provisioning step.Original incident thread: Preflight broken for AEM Sites Trial.
Changes
src/controllers/sites.jsensureSiteEntitlementAndEnrollmentthat callsTierClient.createForSite(...).createEntitlement(FREE_TRIAL).createSitereadsx-productfrom headers and invokes the helper after the site is persisted (for both newly created and existing site paths). Status code logic hoisted into alet statusvariable so the entitlement step runs uniformly while preserving the existing 201/200 idempotent-create semantics.500with a descriptive message (Failed to ensure <PRODUCT> entitlement/enrollment for site); retries are safe becauseTierClientis idempotent and the site lookup on retry returns the already-persisted site.src/controllers/organizations.jsensureOrgEntitlementthat callsTierClient.createForOrg(...).createEntitlement(FREE_TRIAL).createOrganizationreadsx-productfrom headers and invokes the helper, with the same idempotent-create semantics (200 for existing, 201 for newly created).internalServerErrorimport from@adobe/spacecat-shared-http-utils.OpenAPI specs
xProductparameter underdocs/openapi/parameters.yaml.sites-api.yamlandorganizations-api.yamlPOSTendpoints to reference the new parameter and document the auto-enrollment behavior + failure modes.200response onPOST /organizationsfor the idempotent-existing case.Tests
createSite auto-enrollment via x-product header(6 cases) andcreateOrganization auto-entitlement via x-product header(5 cases) covering: success on newly created, success on existing, header missing, empty-string header, TierClient failure on newly created, TierClient failure on existing.Backward compatibility
Without the
x-productheader, both endpoints behave exactly as before — no entitlement/enrollment is created and noTierClientcall is made. Existing integrations (PLG onboarding, Slackonboard sitecommand, etc.) that manage enrollment via their own paths are unaffected.Test plan
npm test(mocha + c8): all new and existing tests pass; 100% branch coverage on the changed code.eslinton changed files — clean.npm run docs:lint— clean (only pre-existing warnings inexamples.yaml).npm run docs:build— succeeds.POST /siteswithx-product: ASOon stage → site appears inGET /organizations/:orgId/sitesfor the same product code.POST /siteswithoutx-product→ behavior unchanged.Follow-up
A companion PR in
aem-aso-trialwill wire upx-product: ASOon itsPOST /sitesandPOST /organizationscalls so trial sites are enrolled out-of-the-box. Tracked under SITES-44944.References