-
Notifications
You must be signed in to change notification settings - Fork 5
Improved: flow for app version support in case of embedded app #145
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
ymaheshwari1
wants to merge
4
commits into
hotwax:main
Choose a base branch
from
ymaheshwari1:fix/embed-app-flow
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
4 commits
Select commit
Hold shift + click to select a range
b7a21a4
Improved: flow for app version support in case of embedded app
ymaheshwari1 52d6058
Improved: lock file
ymaheshwari1 195b19a
Improved: resolved lock file conflicts
ymaheshwari1 9c6c27d
Merge branch 'main' into fix/embed-app-flow
ymaheshwari1 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
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,114 @@ | ||
| // @vitest-environment jsdom | ||
|
|
||
| import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; | ||
| import { createPinia, setActivePinia } from "pinia"; | ||
|
|
||
| // Each scenario needs a fresh module instance: the in-flight flag and the "reconciled once" flag are | ||
| // module-scoped, standing in for a page load. resetModules() + dynamic import is how we simulate a reload. | ||
| const loadUseAuth = async () => { | ||
| vi.resetModules(); | ||
| const [{ useAuth }, { accxuiConfig }] = await Promise.all([ | ||
| import("./useAuth"), | ||
| import("../core/configRegistry") | ||
| ]); | ||
| return { useAuth, accxuiConfig }; | ||
| }; | ||
|
|
||
| const setBuildVersion = (buildVersion: string) => | ||
| vi.stubEnv("VITE_APP_VERSION_CONFIG", JSON.stringify({ appId: "BOPIS", environmentTypeId: "AppEnvDev", buildVersion })); | ||
|
|
||
| const setUrl = (url: string) => window.history.replaceState({}, "", url); | ||
|
|
||
| // Simulate one page load: bundle built as `buildVersion`, served at `pathname`, OMS pinning `pinned`. | ||
| // Returns whether a redirect was issued and where to, plus the composable for follow-up calls. | ||
| const load = async (buildVersion: string, pathname: string, pinned: string) => { | ||
| setBuildVersion(buildVersion); | ||
| setUrl(pathname); | ||
| const { useAuth, accxuiConfig } = await loadUseAuth(); | ||
| accxuiConfig.value.appVersion = pinned; | ||
|
|
||
| const replace = vi.fn(); | ||
| Object.defineProperty(window, "location", { | ||
| configurable: true, | ||
| value: { ...window.location, pathname, search: "", hash: "", origin: "https://app.test", replace } | ||
| }); | ||
|
|
||
| const auth = useAuth(); | ||
| const redirected = auth.checkAppVersionRedirect(); | ||
| return { redirected, to: replace.mock.calls[0]?.[0] as string | undefined, auth }; | ||
| }; | ||
|
|
||
| describe("checkAppVersionRedirect", () => { | ||
| beforeEach(() => { | ||
| setActivePinia(createPinia()); | ||
| sessionStorage.clear(); | ||
| }); | ||
|
|
||
| afterEach(() => vi.unstubAllEnvs()); | ||
|
|
||
| it("redirects the root build onto the pinned version", async () => { | ||
| const { redirected, to } = await load("", "/", "v5.1.0"); | ||
|
|
||
| expect(redirected).toBe(true); | ||
| expect(to).toContain("/v5.1.0/"); | ||
| }); | ||
|
|
||
| it("reports the in-flight redirect to later callers in the same page load", async () => { | ||
| const { auth } = await load("", "/", "v5.1.0"); | ||
|
|
||
| // Login.vue resolves the version from more than one path; the router guard fires per navigation. | ||
| expect(auth.checkAppVersionRedirect()).toBe(true); | ||
| expect(auth.checkAppVersionRedirect()).toBe(true); | ||
| }); | ||
|
|
||
| it("does nothing once the pinned version is the one being served", async () => { | ||
| sessionStorage.setItem("appVersionRedirectPending", "v5.1.0"); | ||
| const { redirected, to } = await load("v5.1.0", "/v5.1.0/tabs/orders", "v5.1.0"); | ||
|
|
||
| expect(redirected).toBe(false); | ||
| expect(to).toBeUndefined(); | ||
| // The landed attempt must not be recorded as a failure, or a later rollback here would be refused. | ||
| expect(sessionStorage.getItem("appVersionRedirectFailed")).toBeNull(); | ||
| }); | ||
|
|
||
| it("moves to a newly pinned version when the backend changes", async () => { | ||
| const { redirected, to } = await load("v5.1.0", "/v5.1.0/tabs/orders", "v5.2.0"); | ||
|
|
||
| expect(redirected).toBe(true); | ||
| expect(to).toContain("/v5.2.0/tabs/orders"); | ||
| }); | ||
|
|
||
| it("converges to root — without oscillating — when the pinned version isn't deployed", async () => { | ||
| // 1. Root build asks for v5.1.0. | ||
| const first = await load("", "/", "v5.1.0"); | ||
| expect(first.to).toContain("/v5.1.0/"); | ||
|
|
||
| // 2. The host's catch-all served the root bundle at the versioned path, so the attempt didn't land. | ||
| const second = await load("", "/v5.1.0/", "v5.1.0"); | ||
| expect(second.redirected).toBe(true); | ||
| expect(second.to).toBe("/"); | ||
| expect(sessionStorage.getItem("appVersionRedirectFailed")).toBe("v5.1.0"); | ||
|
|
||
| // 3. Back at root: v5.1.0 is known-unreachable, so we stay put instead of bouncing back to it. | ||
| const third = await load("", "/", "v5.1.0"); | ||
| expect(third.redirected).toBe(false); | ||
| expect(third.to).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("still honours a different version after one proved unreachable", async () => { | ||
| sessionStorage.setItem("appVersionRedirectFailed", "v5.1.0"); | ||
| const { redirected, to } = await load("", "/", "v5.2.0"); | ||
|
|
||
| expect(redirected).toBe(true); | ||
| expect(to).toContain("/v5.2.0/"); | ||
| }); | ||
|
|
||
| it("no-ops while the version is still unresolved", async () => { | ||
| setBuildVersion(""); | ||
| setUrl("/"); | ||
| const { useAuth, accxuiConfig } = await loadUseAuth(); | ||
| accxuiConfig.value.appVersion = undefined; | ||
|
|
||
| expect(useAuth().checkAppVersionRedirect()).toBe(false); | ||
| }); | ||
| }); |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a merchant opens the standalone app on the same origin after an embedded session, the persisted embedded store still contains its token and expiration because only
shopifyAppBridgeis omitted from persistence. These lines therefore prefer those credentials even thoughcommonUtil.isAppEmbedded()is false: an expired embedded token makes a valid cookie-backed standalone session appear unauthenticated, while a live one is paired with the store-first token/OMS helpers and can send requests using the previous embedded session. Select these values from the store only when the current page is actually embedded, or clear the embedded credentials when entering standalone mode.Useful? React with 👍 / 👎.