fix(jac-client): jacLogin/jacSignup use identity/credential shape#5602
Open
kashmithnisakya wants to merge 16 commits intojaseci-labs:mainfrom
Open
fix(jac-client): jacLogin/jacSignup use identity/credential shape#5602kashmithnisakya wants to merge 16 commits intojaseci-labs:mainfrom
kashmithnisakya wants to merge 16 commits intojaseci-labs:mainfrom
Conversation
…l types for improved authentication structure
…dated identity/credential shape
…/jacSignup The ECMAScript codegen pass (emit_isinstance in primitives_es.impl.jac) cannot resolve user-defined obj classes as the second arg of isinstance(), causing IndexError during PWA bundle transpilation. Restructure the branching to use isinstance(x, str) and isinstance(x, list) only — both are builtins the JS pass handles. Behavior is unchanged: strings are auto-wrapped, lists are mapped, everything else is assumed to be an Identity/Credential instance and passed through unchanged.
…h helpers
The ECMAScript codegen's emit_isinstance is naive (args[0] + ' instanceof ' +
args[1]) and fails whenever args[1] isn't a resolvable JS class name. This
breaks for both user-defined obj classes (Identity, Credential) and builtin
primitives (str, list) — IndexError: list index out of range during PWA
bundle transpilation.
Restructure jacLogin / jacSignup to use the pattern already established in
jac/jaclang/runtimelib/impl/client_runtime.impl.jac:
- Array.isArray(x) replaces isinstance(x, list)
- __isString(x) replaces isinstance(x, str) (new helper,
mirrors the existing __isObject / __isFunction
built on Object.prototype.toString.call)
- identity.to_dict truthy replaces isinstance(x, Identity)
(positive duck-type check: presence of the
method we're about to call)
Each dispatch branch is now positively identified. Unknown inputs raise
ValueError with an explicit message instead of crashing later at
undefined.to_dict() or silently sending the wrong wire shape.
…block scope
Browser e2e tests fail with 'ReferenceError: identities is not defined' and
'ReferenceError: ident is not defined' because the Jac -> JS transpiler emits
each branch of an if/elif/else as a block-scoped 'let' declaration. Variables
assigned only inside the branches are invisible when used afterwards.
Move the per-input dispatch into two new static methods that use early
return (which compiles cleanly to function-scoped JS):
Identity.from_any(value) str -> Identity.auto(), Identity passthrough,
else raise ValueError
Credential.from_any(value) str -> Credential.password(), Credential
passthrough, else raise ValueError
jacLogin then becomes a straight two-liner:
ident = Identity.from_any(identity);
cred = Credential.from_any(credential);
jacSignup does list-normalization via a single ternary, then maps to_dict:
identity_list = identity if Array.isArray(identity) else
[Identity.from_any(identity)];
identities = [i.to_dict() for i in identity_list];
cred = Credential.from_any(credential);
All dispatch results live in function scope from their first assignment, so
the block-scoping issue goes away.
…on for cleaner user registration and login
…and credential definitions
…acy and identity/credential shapes
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.
Description
jacLoginandjacSignupwere still POSTing{username, password}, which jac-scale no longer accepts. They now send{identity: {type, value}, credential: {type, password}}(pluralidentitiesfor signup).IdentityandCredentialtypes, exported from@jac/runtime, for explicit typed calls likejacLogin(Identity.email("a@b.com"), Credential.password("pw")).jacLogin("alice", "pw")) keep working — strings are auto-wrapped, so no example/template/product code needs to change.