-
Notifications
You must be signed in to change notification settings - Fork 0
fix: show custom yields in the calculator offline #135
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
paccloud
wants to merge
6
commits into
main
Choose a base branch
from
claude/adoring-cerf-nzibk1
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
6 commits
Select commit
Hold shift + click to select a range
b40ba65
docs: record that the calculator works offline
claude 6cff891
fix: show custom yields in the calculator offline
claude 77b6e68
Merge remote-tracking branch 'origin/main' into claude/adoring-cerf-n…
claude ee8cbda
fix: track a newer yield revision when values are unchanged
claude e15b880
fix: scope, refresh and follow custom yields in the calculator
claude 07fd054
fix: keep edits made during a yield push and refresh fallback yields
claude 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| // Legacy password sessions (retired by ADR 0001) keep the account in a JWT. The client only | ||
| // reads it for display and for choosing where data is stored; the server verifies every token. | ||
|
|
||
| function decodeBase64UrlJson(value) { | ||
| try { | ||
| let base64 = value.replace(/-/g, '+').replace(/_/g, '/'); | ||
| const padding = base64.length % 4; | ||
| if (padding) { | ||
| base64 += '='.repeat(4 - padding); | ||
| } | ||
|
|
||
| const binary = globalThis.atob(base64); | ||
| const bytes = Uint8Array.from(binary, (c) => c.charCodeAt(0)); | ||
| const text = new TextDecoder().decode(bytes); | ||
| return JSON.parse(text); | ||
| } catch { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| export function decodeJwtPayload(token) { | ||
| const [, encodedPayload] = String(token ?? '').split('.'); | ||
| return encodedPayload ? decodeBase64UrlJson(encodedPayload) : null; | ||
| } | ||
|
|
||
| // The signed-in user a legacy JWT stands for. The id matters: DataContext keys the account's | ||
| // on-device data by it, so without one the account's synced yields would land in the guest scope. | ||
| export function legacyUserFromToken(token) { | ||
| const payload = decodeJwtPayload(token); | ||
| if (!payload?.username) return null; | ||
| return { | ||
| id: payload.id, | ||
| username: payload.username, | ||
| email: payload.email || null, | ||
| authProvider: 'password', | ||
| }; | ||
| } |
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,34 @@ | ||
| import { Buffer } from 'node:buffer'; | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { decodeJwtPayload, legacyUserFromToken } from './legacyJwt'; | ||
|
|
||
| const b64 = (value) => Buffer.from(JSON.stringify(value)).toString('base64url'); | ||
| const jwt = (payload) => `${b64({ alg: 'HS256', typ: 'JWT' })}.${b64(payload)}.signature`; | ||
|
|
||
| describe('decodeJwtPayload', () => { | ||
| it('reads the payload of a JWT', () => { | ||
| expect(decodeJwtPayload(jwt({ id: 7, username: 'skipper' }))).toEqual({ id: 7, username: 'skipper' }); | ||
| }); | ||
|
|
||
| it('returns null for anything that is not a JWT', () => { | ||
| expect(decodeJwtPayload('not-a-jwt')).toBeNull(); | ||
| expect(decodeJwtPayload('a.%%%.c')).toBeNull(); | ||
| expect(decodeJwtPayload(null)).toBeNull(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('legacyUserFromToken', () => { | ||
| it('includes the account id, so the account gets its own storage scope', () => { | ||
| expect(legacyUserFromToken(jwt({ id: 7, username: 'skipper', exp: 9999999999 }))).toEqual({ | ||
| id: 7, | ||
| username: 'skipper', | ||
| email: null, | ||
| authProvider: 'password', | ||
| }); | ||
| }); | ||
|
|
||
| it('returns null when the token names no user', () => { | ||
| expect(legacyUserFromToken(jwt({ id: 7 }))).toBeNull(); | ||
| expect(legacyUserFromToken('garbage')).toBeNull(); | ||
| }); | ||
| }); |
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.
Uh oh!
There was an error while loading. Please reload this page.