-
Notifications
You must be signed in to change notification settings - Fork 8
CEXT-6160: store commerce instance on association and expose retrieval helpers #511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vinayrao2000
wants to merge
50
commits into
main
Choose a base branch
from
CEXT-6160-commerce-system-config-on-association
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
9a7f23e
CEXT-6160: store and expose Commerce system config during app associa…
vinayrao2000 92644b9
CEXT-6160: add association-data spec
vinayrao2000 9f2d51e
address review feedback
vinayrao2000 204f842
address review feedback
vinayrao2000 07a1aae
CEXT-6160: rename to getCommerceInstance/getCommerceClient
vinayrao2000 9e3fef5
Merge branch 'main' of https://github.com/adobe/aio-commerce-sdk into…
vinayrao2000 bd84bf8
CEXT-6160: throw AppNotAssociatedError instead of returning null
vinayrao2000 ccd61de
CEXT-6160: use system.association as storage key
vinayrao2000 0457e1e
CEXT-6160: split storage into generic + typed layers
vinayrao2000 42dfccc
CEXT-6160: update spec to reference correct modules
vinayrao2000 4eed582
CEXT-6160: clarify generic lib-config module and helper layering in spec
vinayrao2000 434ebe2
CEXT-6160: document that system config bypasses scope tree
vinayrao2000 2ffbd15
CEXT-6160: drop TTL refresh, document two-layer storage
vinayrao2000 2b1c005
CEXT-6160: nest system module under configuration/
vinayrao2000 bb79d73
CEXT-6160: add generic system config submodule to lib-config
vinayrao2000 dbbb395
CEXT-6160: add association module and public helpers to lib-app
vinayrao2000 1b1a82e
CEXT-6160: add association runtime action and scaffolding
vinayrao2000 3a1f2b4
CEXT-6160: add tests, changeset, and docs for association helpers
vinayrao2000 f80b47e
Merge branch 'main' into CEXT-6160-commerce-system-config-on-association
vinayrao2000 034f895
resloved conflicts in usage.md
vinayrao2000 46ed932
CEXT-6160: clarify association adoption docs for new vs existing apps
vinayrao2000 f54668c
CEXT-6160: resolve merge conflict in lib-app usage.md
vinayrao2000 6ab289f
CEXT-6160: validate commerceBaseUrl as a URL in association schema
vinayrao2000 305860a
CEXT-6160: document system-repository helpers and read files directly
vinayrao2000 fb2dfc4
CEXT-6160: move commerce helpers out of index barrel
vinayrao2000 80a7526
CEXT-6160: test 500 path when association storage fails
vinayrao2000 8b61c1e
CEXT-6160: reuse CommerceSdkErrorBaseOptions in AppNotAssociatedError
vinayrao2000 4847086
CEXT-6160: document 401/403 on association routes
vinayrao2000 90f2491
CEXT-6160: use response presets and unwrap prose in usage.md
vinayrao2000 0a4de5c
CEXT-6160: invalidate system-config cache on write failure
vinayrao2000 b2409d9
CEXT-6160: move runtime helpers to access module
vinayrao2000 bf31144
CEXT-6160: make getCommerceClient composable, drop unused param
vinayrao2000 04b6559
CEXT-6160: keep AppNotAssociatedError options as a named seam
vinayrao2000 de6e29f
CEXT-6160: reuse configuration-repository for system config storage
vinayrao2000 b290319
CEXT-6160: restore caching-failure comment in configuration-repository
vinayrao2000 5e948fe
CEXT-6160: read config file directly instead of list-then-read
vinayrao2000 3f09333
CEXT-6160: bubble up persisted config delete errors
vinayrao2000 f1130a7
CEXT-6160: reuse shared storage mocks in system-config tests
vinayrao2000 9b42d0e
CEXT-6160: move SYSTEM_NAMESPACE into system-config and default getSy…
vinayrao2000 b83a64f
CEXT-6160: add changeset for CommerceSdkErrorBaseOptions export
vinayrao2000 36fa0c9
CEXT-6160: removed implementation detail from changeset
vinayrao2000 6d4c3c3
CEXT-6160: split internal rationale out of AppNotAssociatedErrorOptio…
vinayrao2000 871f7fb
CEXT-6160: move association under management, restrict getCommerceCli…
vinayrao2000 cb74abd
CEXT-6160: harden getCommerceClient (IMS-only, fetch options) and ret…
vinayrao2000 8898984
CEXT-6160: address PR review feedback
vinayrao2000 8ff826d
Merge branch 'main' into CEXT-6160-commerce-system-config-on-association
vinayrao2000 120de50
CEXT-6160: use CommerceEnv from lib-core for association env
vinayrao2000 835cb89
CEXT-6160: test association repository via round-trip storage
vinayrao2000 0cc7dde
CEXT-6160: rename stale index test to access/commerce-instance
vinayrao2000 dd4c61c
CEXT-6160: align spec with final association design
vinayrao2000 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@adobe/aio-commerce-lib-app": minor | ||
| --- | ||
|
|
||
| Add helpers to retrieve the Commerce instance an app is associated with from any runtime action: `getCommerceInstance()` returns the stored instance data, and `getCommerceClient(auth)` returns a ready-to-use Commerce HTTP client built from that instance. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@adobe/aio-commerce-lib-core": minor | ||
| --- | ||
|
|
||
| Export the `CommerceSdkErrorBaseOptions` type so consumers can type the options passed when constructing or extending `CommerceSdkErrorBase`. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@adobe/aio-commerce-lib-config": minor | ||
| --- | ||
|
|
||
| Add `getSystemConfigByKey` and `setSystemConfigByKey` to store and retrieve generic SDK system configuration under a dedicated `system.*` namespace. |
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
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
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
95 changes: 95 additions & 0 deletions
95
packages/aio-commerce-lib-app/source/access/commerce-instance.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| /* | ||
| * Copyright 2026 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| import { AdobeCommerceHttpClient } from "@adobe/aio-commerce-lib-api"; | ||
|
|
||
| import { AppNotAssociatedError } from "../errors/app-not-associated-error"; | ||
| import { getAssociationData } from "../management/association/association-repository"; | ||
|
|
||
| import type { CommerceHttpClientParams } from "@adobe/aio-commerce-lib-api"; | ||
| import type { | ||
| ImsAuthParams, | ||
| ImsAuthProvider, | ||
| } from "@adobe/aio-commerce-lib-auth"; | ||
| import type { AssociatedCommerceInstance } from "../management/association/types"; | ||
|
|
||
| /** | ||
| * Returns the Commerce instance this app is currently associated with. | ||
| * | ||
| * @throws {AppNotAssociatedError} If the app is not associated, was | ||
| * unassociated, or was associated by an older SDK that did not store this | ||
| * data. Re-associating the app resolves the error. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { getCommerceInstance } from "@adobe/aio-commerce-lib-app"; | ||
| * | ||
| * export async function main() { | ||
| * const instance = await getCommerceInstance(); | ||
| * | ||
| * // instance.baseUrl — e.g. "https://my-store.example.com" | ||
| * // instance.env — "saas" | "paas" | ||
| * } | ||
| * ``` | ||
| */ | ||
| export async function getCommerceInstance(): Promise<AssociatedCommerceInstance> { | ||
| const instance = await getAssociationData(); | ||
| if (instance === null) { | ||
| throw new AppNotAssociatedError(); | ||
| } | ||
| return instance; | ||
| } | ||
|
|
||
| /** | ||
| * Returns an initialised `AdobeCommerceHttpClient` for the Commerce instance | ||
| * this app is currently associated with. | ||
| * | ||
| * The base URL and flavor come from the stored association data | ||
| * ({@link getCommerceInstance}); only the auth credentials are supplied by the | ||
| * caller, already resolved. App Management requires IMS, so this accepts only | ||
| * IMS auth: resolve params with `resolveImsAuthParams`, or pass an | ||
| * `ImsAuthProvider` built with `getImsAuthProvider` / `forwardImsAuthProvider` | ||
| * from `@adobe/aio-commerce-lib-auth`. | ||
| * | ||
| * @param auth - Resolved IMS auth params or an IMS auth provider. | ||
| * @param fetchOptions - Optional global fetch options forwarded to the | ||
| * underlying `AdobeCommerceHttpClient` (e.g. `headers`, `timeout`, `retry`). | ||
| * @throws {AppNotAssociatedError} If the app is not associated, was | ||
| * unassociated, or was associated by an older SDK that did not store this | ||
| * data. Re-associating the app resolves the error. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { getCommerceClient } from "@adobe/aio-commerce-lib-app"; | ||
| * import { resolveImsAuthParams } from "@adobe/aio-commerce-lib-auth"; | ||
| * | ||
| * export async function main(params) { | ||
| * const client = await getCommerceClient(resolveImsAuthParams(params)); | ||
| * const products = await client.get("products").json(); | ||
| * } | ||
| * ``` | ||
| */ | ||
| export async function getCommerceClient( | ||
| auth: ImsAuthParams | ImsAuthProvider, | ||
| fetchOptions?: CommerceHttpClientParams["fetchOptions"], | ||
| ): Promise<AdobeCommerceHttpClient> { | ||
| const instance = await getCommerceInstance(); | ||
|
|
||
| // `CommerceHttpClientParams` is a flavor-discriminated union; the stored env | ||
| // is a runtime value TypeScript cannot narrow against the auth union, so the | ||
| // assembled params are asserted to the resolved shape. | ||
| return new AdobeCommerceHttpClient({ | ||
| auth, | ||
| config: { baseUrl: instance.baseUrl, flavor: instance.env }, | ||
| fetchOptions, | ||
| } as CommerceHttpClientParams); | ||
| } |
29 changes: 29 additions & 0 deletions
29
packages/aio-commerce-lib-app/source/actions/association/index.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /* | ||
| * Copyright 2026 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| import { router } from "./router"; | ||
|
|
||
| import type { RuntimeActionParams } from "@adobe/aio-commerce-lib-core/params"; | ||
|
|
||
| /** | ||
| * Factory to create the route handler for the `association` action. | ||
| * | ||
| * The `association` action manages the lifecycle of the Commerce instance the | ||
| * app is associated with — `POST /` stores the data when the app is associated, | ||
| * and `DELETE /` clears it on unassociation. Runtime actions consume the data | ||
| * via `getCommerceInstance` / `getCommerceClient` from the root entrypoint. | ||
| */ | ||
| export const associationRuntimeAction = | ||
| () => async (params: RuntimeActionParams) => { | ||
| const handler = router.handler(); | ||
| return await handler({ ...params }); | ||
| }; |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.