@carecard/auth-util 3.10.0 → 3.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/skills/carecard-workspace-standards/SKILL.md +20 -3
- package/.agents/skills/github-pr-create-update/SKILL.md +17 -7
- package/.agents/skills/github-pr-merge-cleanup/SKILL.md +40 -10
- package/.agents/skills/pkg-auth-util-auth-crypto-library/SKILL.md +4 -0
- package/.agents/skills/pkg-publish/SKILL.md +4 -0
- package/.agents/skills/software-design-patterns-and-clean-code/SKILL.md +4 -0
- package/index.d.ts +2 -2
- package/lib/jwtUtilAuth.js +13 -15
- package/lib/pwdUtilAuth.js +13 -19
- package/package.json +5 -4
- package/readme.md +4 -0
|
@@ -3,12 +3,29 @@ name: carecard-workspace-standards
|
|
|
3
3
|
description: 'Follow the shared SO_CareCardCa/CareCard workspace coding, testing, repository, dependency, shared package, frontend, database, API response, and security standards. Use before modifying, testing, reviewing, or debugging any ms-*, pkg-*, app-*, website, dashboard, or other CareCard repository in this workspace, especially when choosing validation commands, package boundaries, TypeScript types, dependencies, API contracts, database logic, service patterns, or frontend architecture.'
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
+
Non-negotiable root-cause solution rule: Always identify and solve the verified root cause, use the stronger solution, and deliver a correct, durable, production-quality result. Never treat a temporary workaround, resource increase, retry, suppression, bypass, or symptom-only patch as completion. Validate the root-cause fix against the real failing workflow and prove the end state.
|
|
7
|
+
|
|
6
8
|
# CareCard Workspace Standards
|
|
7
9
|
|
|
8
10
|
Non-negotiable TDD rule: Always write the failing test first, run it to confirm it fails for the intended reason, then implement the code and rerun the test until it passes. Test Driven Development is required for all coding work and must not be skipped. For documentation- or skill-only edits, add or update the relevant validation check before changing the prose.
|
|
9
11
|
|
|
12
|
+
This requirement is non-negotiable and may be overridden only with the user's
|
|
13
|
+
explicit, direct approval.
|
|
14
|
+
|
|
15
|
+
A pre-existing test—defined as any test present before work on the current task
|
|
16
|
+
begins—must not be deleted, disabled, skipped, weakened, excluded from execution,
|
|
17
|
+
or otherwise removed. A pre-existing test must not be modified without the
|
|
18
|
+
user's explicit approval for the exact proposed change. If changing a
|
|
19
|
+
pre-existing test is believed necessary, stop before making the change and
|
|
20
|
+
request approval. The request must identify every affected test, describe the
|
|
21
|
+
precise proposed modification, provide detailed technical justification, and
|
|
22
|
+
explain all known or reasonably foreseeable regression risks. Until approval is
|
|
23
|
+
granted, leave every pre-existing test unchanged.
|
|
24
|
+
|
|
10
25
|
Non-negotiable repository isolation rule: Every repository must run its Husky hooks and tests using only files, code, fixtures, dependencies, and services contained within that repository. Tests and Husky scripts must not import, require, read, execute, or otherwise depend on sibling repositories or paths outside the repository root. app-e2e-tests is the only exception because cross-repository end-to-end testing is its explicit responsibility.
|
|
11
26
|
|
|
27
|
+
Non-negotiable error and warning rule: Never suppress, silence, hide, downgrade, filter, ignore, skip, or bypass errors or warnings from code, tests, tools, compilers, linters, or validation. Fix the root cause, then rerun the affected check and require a clean result. Expected error-path tests may assert errors, but must not conceal unexpected failures.
|
|
28
|
+
|
|
12
29
|
Non-negotiable code organization rule: Functions with the same or equivalent behavior must use the same or clearly corresponding descriptive names across CareCard repositories, and equivalent functionality must live in files with the same names within each repository's established architecture. No backward compatibility names, aliases, or duplicate locations are allowed.
|
|
13
30
|
|
|
14
31
|
## Purpose
|
|
@@ -85,7 +102,7 @@ config.
|
|
|
85
102
|
- Never suppress errors, TypeScript errors, linter warnings, authorization
|
|
86
103
|
failures, RLS failures, build failures, hydration issues, or failing tests.
|
|
87
104
|
Do not add `eslint-disable`, `@ts-ignore`, broad catches, empty catches, or
|
|
88
|
-
similar suppression
|
|
105
|
+
similar suppression. Fix the root cause.
|
|
89
106
|
- Do not add dependencies unless clearly necessary. If one might be needed, ask
|
|
90
107
|
first with the reason, tradeoff, and why existing code cannot solve it.
|
|
91
108
|
- Before finalizing repository work, run the affected repository's relevant
|
|
@@ -215,7 +232,7 @@ build artifacts, logs, or `.DS_Store`.
|
|
|
215
232
|
Most JavaScript `ms-*` services use CommonJS, Mocha, Supertest, Docker Compose
|
|
216
233
|
database tests, `@carecard/*` packages, and `sub-apps`
|
|
217
234
|
controller/router/model patterns. TypeScript services such as `ms-messages`
|
|
218
|
-
|
|
235
|
+
use Jest or TypeScript tooling and should keep their
|
|
219
236
|
existing TypeScript style.
|
|
220
237
|
|
|
221
238
|
- Keep environment-specific files explicit: `.env.development`, `.env.test`,
|
|
@@ -380,7 +397,7 @@ the authenticated dashboard.
|
|
|
380
397
|
|
|
381
398
|
## Auth Service RLS Contract
|
|
382
399
|
|
|
383
|
-
- `ms-auth` follows the shared PostgreSQL/RLS pattern
|
|
400
|
+
- `ms-auth` follows the shared PostgreSQL/RLS pattern: auth tables live in the `carecard` schema, RLS is enabled and forced on every auth table, and application runtime queries use the unprivileged database role.
|
|
384
401
|
- Auth table policies allow normal JWT users to access only self-owned rows. Do not add redundant `user_id = <jwt sub>` SQL predicates to duplicate self-row checks when RLS owns the authorization decision.
|
|
385
402
|
- A JWT payload containing `roles: ["ad"]` is the auth-service super-admin signal and can perform any action on auth tables. Dashboard code may map that role to `super_admin`, but backend auth RLS must not require a separate database role row for that bypass.
|
|
386
403
|
- Public auth flows such as registration, login, confirmation, recovery, visitor creation, and service user lookup must use narrow system contexts (`system_create`, `system_login`, `system_confirm`, `system_recovery`, `system_visitor`, `system_service`) instead of privileged runtime queries.
|
|
@@ -3,12 +3,16 @@ name: github-pr-create-update
|
|
|
3
3
|
description: 'Use only when the user explicitly asks for remote Git or GitHub PR work: pushing a branch, creating or updating a PR, or marking a PR ready from the current repository branch into development or main.'
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
+
Non-negotiable root-cause solution rule: Always identify and solve the verified root cause, use the stronger solution, and deliver a correct, durable, production-quality result. Never treat a temporary workaround, resource increase, retry, suppression, bypass, or symptom-only patch as completion. Validate the root-cause fix against the real failing workflow and prove the end state.
|
|
7
|
+
|
|
6
8
|
# Pull Request Create
|
|
7
9
|
|
|
8
10
|
Non-negotiable TDD rule: Always write the failing test first, run it to confirm it fails for the intended reason, then implement the code and rerun the test until it passes. Test Driven Development is required for all coding work and must not be skipped. For documentation- or skill-only edits, add or update the relevant validation check before changing the prose.
|
|
9
11
|
|
|
10
12
|
Non-negotiable repository isolation rule: Every repository must run its Husky hooks and tests using only files, code, fixtures, dependencies, and services contained within that repository. Tests and Husky scripts must not import, require, read, execute, or otherwise depend on sibling repositories or paths outside the repository root. app-e2e-tests is the only exception because cross-repository end-to-end testing is its explicit responsibility.
|
|
11
13
|
|
|
14
|
+
Non-negotiable error and warning rule: Never suppress, silence, hide, downgrade, filter, ignore, skip, or bypass errors or warnings from code, tests, tools, compilers, linters, or validation. Fix the root cause, then rerun the affected check and require a clean result. Expected error-path tests may assert errors, but must not conceal unexpected failures.
|
|
15
|
+
|
|
12
16
|
Non-negotiable code organization rule: Functions with the same or equivalent behavior must use the same or clearly corresponding descriptive names across CareCard repositories, and equivalent functionality must live in files with the same names within each repository's established architecture. No backward compatibility names, aliases, or duplicate locations are allowed.
|
|
13
17
|
|
|
14
18
|
## Purpose
|
|
@@ -77,14 +81,20 @@ Do not continue automatically when:
|
|
|
77
81
|
when `origin/development` is absent:
|
|
78
82
|
|
|
79
83
|
```sh
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
base
|
|
84
|
-
|
|
85
|
-
echo "No origin/development or origin/main branch exists."
|
|
86
|
-
exit 1
|
|
84
|
+
remote_base_refs="$(git ls-remote --heads origin development main)"
|
|
85
|
+
remote_query_status=$?
|
|
86
|
+
if [ "$remote_query_status" -ne 0 ]; then
|
|
87
|
+
printf 'Unable to inspect origin base branches (exit %s).\n' "$remote_query_status" >&2
|
|
88
|
+
exit "$remote_query_status"
|
|
87
89
|
fi
|
|
90
|
+
case "$remote_base_refs" in
|
|
91
|
+
*"refs/heads/development") base="development" ;;
|
|
92
|
+
*"refs/heads/main") base="main" ;;
|
|
93
|
+
*)
|
|
94
|
+
printf '%s\n' "No origin/development or origin/main branch exists." >&2
|
|
95
|
+
exit 1
|
|
96
|
+
;;
|
|
97
|
+
esac
|
|
88
98
|
git fetch origin "$base" --prune
|
|
89
99
|
```
|
|
90
100
|
|
|
@@ -3,12 +3,16 @@ name: github-pr-merge-cleanup
|
|
|
3
3
|
description: 'Use only when the user explicitly asks for remote Git or GitHub PR work: pushing a branch, creating a missing PR, reviewing mergeability, validating, merging, deleting, or cleaning up a pull request branch.'
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
+
Non-negotiable root-cause solution rule: Always identify and solve the verified root cause, use the stronger solution, and deliver a correct, durable, production-quality result. Never treat a temporary workaround, resource increase, retry, suppression, bypass, or symptom-only patch as completion. Validate the root-cause fix against the real failing workflow and prove the end state.
|
|
7
|
+
|
|
6
8
|
# Pull Request Merge Close
|
|
7
9
|
|
|
8
10
|
Non-negotiable TDD rule: Always write the failing test first, run it to confirm it fails for the intended reason, then implement the code and rerun the test until it passes. Test Driven Development is required for all coding work and must not be skipped. For documentation- or skill-only edits, add or update the relevant validation check before changing the prose.
|
|
9
11
|
|
|
10
12
|
Non-negotiable repository isolation rule: Every repository must run its Husky hooks and tests using only files, code, fixtures, dependencies, and services contained within that repository. Tests and Husky scripts must not import, require, read, execute, or otherwise depend on sibling repositories or paths outside the repository root. app-e2e-tests is the only exception because cross-repository end-to-end testing is its explicit responsibility.
|
|
11
13
|
|
|
14
|
+
Non-negotiable error and warning rule: Never suppress, silence, hide, downgrade, filter, ignore, skip, or bypass errors or warnings from code, tests, tools, compilers, linters, or validation. Fix the root cause, then rerun the affected check and require a clean result. Expected error-path tests may assert errors, but must not conceal unexpected failures.
|
|
15
|
+
|
|
12
16
|
Non-negotiable code organization rule: Functions with the same or equivalent behavior must use the same or clearly corresponding descriptive names across CareCard repositories, and equivalent functionality must live in files with the same names within each repository's established architecture. No backward compatibility names, aliases, or duplicate locations are allowed.
|
|
13
17
|
|
|
14
18
|
## Purpose
|
|
@@ -74,14 +78,20 @@ completion.
|
|
|
74
78
|
|
|
75
79
|
```sh
|
|
76
80
|
gh auth status
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
base
|
|
81
|
-
|
|
82
|
-
echo "No origin/development or origin/main branch exists."
|
|
83
|
-
exit 1
|
|
81
|
+
remote_base_refs="$(git ls-remote --heads origin development main)"
|
|
82
|
+
remote_query_status=$?
|
|
83
|
+
if [ "$remote_query_status" -ne 0 ]; then
|
|
84
|
+
printf 'Unable to inspect origin base branches (exit %s).\n' "$remote_query_status" >&2
|
|
85
|
+
exit "$remote_query_status"
|
|
84
86
|
fi
|
|
87
|
+
case "$remote_base_refs" in
|
|
88
|
+
*"refs/heads/development") base="development" ;;
|
|
89
|
+
*"refs/heads/main") base="main" ;;
|
|
90
|
+
*)
|
|
91
|
+
printf '%s\n' "No origin/development or origin/main branch exists." >&2
|
|
92
|
+
exit 1
|
|
93
|
+
;;
|
|
94
|
+
esac
|
|
85
95
|
target_branch="$(git branch --show-current)"
|
|
86
96
|
test -n "$target_branch"
|
|
87
97
|
test "$target_branch" != "$base"
|
|
@@ -171,7 +181,19 @@ completion.
|
|
|
171
181
|
not protected:
|
|
172
182
|
|
|
173
183
|
```sh
|
|
174
|
-
protected="$(gh api "repos/{owner}/{repo}/branches/$target_branch" --jq '.protected'
|
|
184
|
+
protected="$(gh api "repos/{owner}/{repo}/branches/$target_branch" --jq '.protected')"
|
|
185
|
+
protection_query_status=$?
|
|
186
|
+
if [ "$protection_query_status" -ne 0 ]; then
|
|
187
|
+
printf 'Unable to inspect branch protection (exit %s).\n' "$protection_query_status" >&2
|
|
188
|
+
exit "$protection_query_status"
|
|
189
|
+
fi
|
|
190
|
+
case "$protected" in
|
|
191
|
+
true|false) ;;
|
|
192
|
+
*)
|
|
193
|
+
printf 'Unexpected branch protection value: %s\n' "$protected" >&2
|
|
194
|
+
exit 1
|
|
195
|
+
;;
|
|
196
|
+
esac
|
|
175
197
|
if [ "$protected" = true ]; then
|
|
176
198
|
gh pr merge "$pr_number" --squash --admin
|
|
177
199
|
else
|
|
@@ -183,8 +205,16 @@ completion.
|
|
|
183
205
|
delete it explicitly:
|
|
184
206
|
|
|
185
207
|
```sh
|
|
186
|
-
if [ "$protected" != true ]
|
|
187
|
-
git
|
|
208
|
+
if [ "$protected" != true ]; then
|
|
209
|
+
remote_target_ref="$(git ls-remote --heads origin "$target_branch")"
|
|
210
|
+
remote_query_status=$?
|
|
211
|
+
if [ "$remote_query_status" -ne 0 ]; then
|
|
212
|
+
printf 'Unable to inspect the remote target branch (exit %s).\n' "$remote_query_status" >&2
|
|
213
|
+
exit "$remote_query_status"
|
|
214
|
+
fi
|
|
215
|
+
if [ -n "$remote_target_ref" ]; then
|
|
216
|
+
git push origin --delete "$target_branch"
|
|
217
|
+
fi
|
|
188
218
|
fi
|
|
189
219
|
```
|
|
190
220
|
|
|
@@ -3,12 +3,16 @@ name: pkg-auth-util-auth-crypto-library
|
|
|
3
3
|
description: 'Use when changing pkg-auth-util auth, password, JWT, crypto, key, exported API, types, or package validation behavior.'
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
+
Non-negotiable root-cause solution rule: Always identify and solve the verified root cause, use the stronger solution, and deliver a correct, durable, production-quality result. Never treat a temporary workaround, resource increase, retry, suppression, bypass, or symptom-only patch as completion. Validate the root-cause fix against the real failing workflow and prove the end state.
|
|
7
|
+
|
|
6
8
|
# Package Auth Util
|
|
7
9
|
|
|
8
10
|
Non-negotiable TDD rule: Always write the failing test first, run it to confirm it fails for the intended reason, then implement the code and rerun the test until it passes. Test Driven Development is required for all coding work and must not be skipped. For documentation- or skill-only edits, add or update the relevant validation check before changing the prose.
|
|
9
11
|
|
|
10
12
|
Non-negotiable repository isolation rule: Every repository must run its Husky hooks and tests using only files, code, fixtures, dependencies, and services contained within that repository. Tests and Husky scripts must not import, require, read, execute, or otherwise depend on sibling repositories or paths outside the repository root. app-e2e-tests is the only exception because cross-repository end-to-end testing is its explicit responsibility.
|
|
11
13
|
|
|
14
|
+
Non-negotiable error and warning rule: Never suppress, silence, hide, downgrade, filter, ignore, skip, or bypass errors or warnings from code, tests, tools, compilers, linters, or validation. Fix the root cause, then rerun the affected check and require a clean result. Expected error-path tests may assert errors, but must not conceal unexpected failures.
|
|
15
|
+
|
|
12
16
|
Non-negotiable code organization rule: Functions with the same or equivalent behavior must use the same or clearly corresponding descriptive names across CareCard repositories, and equivalent functionality must live in files with the same names within each repository's established architecture. No backward compatibility names, aliases, or duplicate locations are allowed.
|
|
13
17
|
|
|
14
18
|
## Purpose
|
|
@@ -3,12 +3,16 @@ name: pkg-publish
|
|
|
3
3
|
description: 'Use when any pkg-* repository has non-Markdown package changes, including source code, public types, tests, scripts, package metadata, lockfiles, dependency behavior, or validation config, and the CareCard packages must be versioned, published in order with just-in-time package pushes, and propagated to pkg-*, ms-*, and app-dashboard consumers. Do not use for Markdown-only changes.'
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
+
Non-negotiable root-cause solution rule: Always identify and solve the verified root cause, use the stronger solution, and deliver a correct, durable, production-quality result. Never treat a temporary workaround, resource increase, retry, suppression, bypass, or symptom-only patch as completion. Validate the root-cause fix against the real failing workflow and prove the end state.
|
|
7
|
+
|
|
6
8
|
# pkg Publish
|
|
7
9
|
|
|
8
10
|
Non-negotiable TDD rule: Always write the failing test first, run it to confirm it fails for the intended reason, then implement the code and rerun the test until it passes. Test Driven Development is required for all coding work and must not be skipped. For documentation- or skill-only edits, add or update the relevant validation check before changing the prose.
|
|
9
11
|
|
|
10
12
|
Non-negotiable repository isolation rule: Every repository must run its Husky hooks and tests using only files, code, fixtures, dependencies, and services contained within that repository. Tests and Husky scripts must not import, require, read, execute, or otherwise depend on sibling repositories or paths outside the repository root. app-e2e-tests is the only exception because cross-repository end-to-end testing is its explicit responsibility.
|
|
11
13
|
|
|
14
|
+
Non-negotiable error and warning rule: Never suppress, silence, hide, downgrade, filter, ignore, skip, or bypass errors or warnings from code, tests, tools, compilers, linters, or validation. Fix the root cause, then rerun the affected check and require a clean result. Expected error-path tests may assert errors, but must not conceal unexpected failures.
|
|
15
|
+
|
|
12
16
|
Non-negotiable code organization rule: Functions with the same or equivalent behavior must use the same or clearly corresponding descriptive names across CareCard repositories, and equivalent functionality must live in files with the same names within each repository's established architecture. No backward compatibility names, aliases, or duplicate locations are allowed.
|
|
13
17
|
|
|
14
18
|
## Trigger
|
|
@@ -3,12 +3,16 @@ name: software-design-patterns-and-clean-code
|
|
|
3
3
|
description: 'Use every time before coding, refactoring, debugging, or reviewing in this repository, alongside all other applicable skills, to apply pragmatic software design patterns, SOLID, Clean Code, and testable architecture.'
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
+
Non-negotiable root-cause solution rule: Always identify and solve the verified root cause, use the stronger solution, and deliver a correct, durable, production-quality result. Never treat a temporary workaround, resource increase, retry, suppression, bypass, or symptom-only patch as completion. Validate the root-cause fix against the real failing workflow and prove the end state.
|
|
7
|
+
|
|
6
8
|
# Software Design Patterns And Clean Code
|
|
7
9
|
|
|
8
10
|
Non-negotiable TDD rule: Always write the failing test first, run it to confirm it fails for the intended reason, then implement the code and rerun the test until it passes. Test Driven Development is required for all coding work and must not be skipped. For documentation- or skill-only edits, add or update the relevant validation check before changing the prose.
|
|
9
11
|
|
|
10
12
|
Non-negotiable repository isolation rule: Every repository must run its Husky hooks and tests using only files, code, fixtures, dependencies, and services contained within that repository. Tests and Husky scripts must not import, require, read, execute, or otherwise depend on sibling repositories or paths outside the repository root. app-e2e-tests is the only exception because cross-repository end-to-end testing is its explicit responsibility.
|
|
11
13
|
|
|
14
|
+
Non-negotiable error and warning rule: Never suppress, silence, hide, downgrade, filter, ignore, skip, or bypass errors or warnings from code, tests, tools, compilers, linters, or validation. Fix the root cause, then rerun the affected check and require a clean result. Expected error-path tests may assert errors, but must not conceal unexpected failures.
|
|
15
|
+
|
|
12
16
|
Non-negotiable code organization rule: Functions with the same or equivalent behavior must use the same or clearly corresponding descriptive names across CareCard repositories, and equivalent functionality must live in files with the same names within each repository's established architecture. No backward compatibility names, aliases, or duplicate locations are allowed.
|
|
13
17
|
|
|
14
18
|
## Purpose
|
package/index.d.ts
CHANGED
|
@@ -148,14 +148,14 @@ export const jwtUtilAuth: {
|
|
|
148
148
|
* @param headerObject - Header data for the JWT.
|
|
149
149
|
* @param payloadObject - Payload data for the JWT.
|
|
150
150
|
* @param privateKey - PEM formatted private key to sign the token.
|
|
151
|
-
* @returns Signed JWT string or null
|
|
151
|
+
* @returns Signed JWT string, or null when the private key is missing. Unexpected failures throw.
|
|
152
152
|
*/
|
|
153
153
|
createSignedJwtFromObject: (headerObject: JwtHeader, payloadObject: JwtPayload, privateKey: string) => string | null;
|
|
154
154
|
/**
|
|
155
155
|
* Verifies the signature of a JWT using a public key.
|
|
156
156
|
* @param jwt - The JWT string to verify.
|
|
157
157
|
* @param publicKey - PEM formatted public key.
|
|
158
|
-
* @returns True if the signature is valid, false
|
|
158
|
+
* @returns True if the signature is valid, false for malformed or invalid tokens. Unexpected failures throw.
|
|
159
159
|
*/
|
|
160
160
|
verifyJwtSignature: (jwt: string, publicKey: string) => boolean;
|
|
161
161
|
/**
|
package/lib/jwtUtilAuth.js
CHANGED
|
@@ -77,25 +77,21 @@ const normalizeSeconds = value => {
|
|
|
77
77
|
* @return {string|null}
|
|
78
78
|
*/
|
|
79
79
|
const createSignedJwtFromObject = (headerObject, payloadObject, privateKey) => {
|
|
80
|
-
|
|
81
|
-
if (!privateKey) return null;
|
|
80
|
+
if (!privateKey) return null;
|
|
82
81
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
const header = { ...headerObject };
|
|
83
|
+
header.alg = header.alg || 'EdDSA';
|
|
84
|
+
header.typ = 'JWT';
|
|
86
85
|
|
|
87
|
-
|
|
86
|
+
const payload = _normalizePayload(payloadObject);
|
|
88
87
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
88
|
+
const headerBase64UrlSafe = _encode(header);
|
|
89
|
+
const payloadBase64UrlSafe = _encode(payload);
|
|
90
|
+
const token = headerBase64UrlSafe + '.' + payloadBase64UrlSafe;
|
|
92
91
|
|
|
93
|
-
|
|
92
|
+
const signature = _sign(token, header.alg, privateKey);
|
|
94
93
|
|
|
95
|
-
|
|
96
|
-
} catch (error) {
|
|
97
|
-
return null;
|
|
98
|
-
}
|
|
94
|
+
return token + '.' + signature;
|
|
99
95
|
};
|
|
100
96
|
|
|
101
97
|
function createServiceJwt({
|
|
@@ -161,6 +157,7 @@ const verifyJwtSignature = (jwt, publicKey) => {
|
|
|
161
157
|
|
|
162
158
|
return _verify(token, signature, headerObject.alg, publicKey);
|
|
163
159
|
} catch (error) {
|
|
160
|
+
if (!(error instanceof SyntaxError)) throw error;
|
|
164
161
|
return false;
|
|
165
162
|
}
|
|
166
163
|
};
|
|
@@ -180,7 +177,8 @@ const getHeaderPayloadFromJwt = jwt => {
|
|
|
180
177
|
const payloadObject = _decode(splitJWT[1]);
|
|
181
178
|
|
|
182
179
|
return { header: headerObject, payload: payloadObject };
|
|
183
|
-
} catch (
|
|
180
|
+
} catch (error) {
|
|
181
|
+
if (!(error instanceof SyntaxError)) throw error;
|
|
184
182
|
return null;
|
|
185
183
|
}
|
|
186
184
|
};
|
package/lib/pwdUtilAuth.js
CHANGED
|
@@ -8,14 +8,10 @@ const crypto = require('crypto');
|
|
|
8
8
|
* @return {string}
|
|
9
9
|
*/
|
|
10
10
|
const createPasswordHashWithRandomSalt = (password, secret, algorithm) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return '$1$' + algorithmBase64 + '$' + hashBase64 + '$' + salt + '$';
|
|
16
|
-
} catch (e) {
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
11
|
+
const salt = crypto.randomBytes(32).toString('base64');
|
|
12
|
+
const algorithmBase64 = Buffer.from(algorithm).toString('base64');
|
|
13
|
+
const hashBase64 = crypto.createHmac(algorithm, secret).update(password).digest('base64');
|
|
14
|
+
return '$1$' + algorithmBase64 + '$' + hashBase64 + '$' + salt + '$';
|
|
19
15
|
};
|
|
20
16
|
|
|
21
17
|
/**
|
|
@@ -26,19 +22,17 @@ const createPasswordHashWithRandomSalt = (password, secret, algorithm) => {
|
|
|
26
22
|
* @return {string}
|
|
27
23
|
*/
|
|
28
24
|
const createPasswordHashBasedOnSavedAlgorithmSalt = (password, savedPasswordHash, secret) => {
|
|
29
|
-
|
|
30
|
-
const splitStringArray = savedPasswordHash.split('$');
|
|
31
|
-
if (splitStringArray.length !== 6) return null;
|
|
25
|
+
if (typeof savedPasswordHash !== 'string') return null;
|
|
32
26
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const algorithm = Buffer.from(algBase64, 'base64').toString('utf8');
|
|
27
|
+
const splitStringArray = savedPasswordHash.split('$');
|
|
28
|
+
if (splitStringArray.length !== 6) return null;
|
|
36
29
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
30
|
+
const algBase64 = splitStringArray[2];
|
|
31
|
+
const salt = splitStringArray[4];
|
|
32
|
+
const algorithm = Buffer.from(algBase64, 'base64').toString('utf8');
|
|
33
|
+
|
|
34
|
+
const hashBase64 = crypto.createHmac(algorithm, secret).update(password).digest('base64');
|
|
35
|
+
return '$1$' + algBase64 + '$' + hashBase64 + '$' + salt + '$';
|
|
42
36
|
};
|
|
43
37
|
|
|
44
38
|
module.exports = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carecard/auth-util",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.12.0",
|
|
4
4
|
"repository": "https://github.com/CareCard-ca/pkg-auth-util.git",
|
|
5
5
|
"description": "Auth utility functions",
|
|
6
6
|
"main": "index.js",
|
|
@@ -26,7 +26,6 @@
|
|
|
26
26
|
"license": "ISC",
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@istanbuljs/nyc-config-typescript": "1.0.2",
|
|
29
|
-
"@types/express": "5.0.6",
|
|
30
29
|
"@types/mocha": "10.0.10",
|
|
31
30
|
"@types/node": "25.9.3",
|
|
32
31
|
"eslint": "9.39.4",
|
|
@@ -42,11 +41,13 @@
|
|
|
42
41
|
"typescript": "6.0.3"
|
|
43
42
|
},
|
|
44
43
|
"dependencies": {
|
|
45
|
-
"@carecard/common-util": "3.
|
|
46
|
-
"@carecard/validate": "3.
|
|
44
|
+
"@carecard/common-util": "3.12.0",
|
|
45
|
+
"@carecard/validate": "3.12.0",
|
|
46
|
+
"@types/express": "5.0.6"
|
|
47
47
|
},
|
|
48
48
|
"overrides": {
|
|
49
49
|
"diff": "8.0.4",
|
|
50
|
+
"glob": "13.0.6",
|
|
50
51
|
"serialize-javascript": "7.0.5",
|
|
51
52
|
"js-yaml": "4.2.0"
|
|
52
53
|
}
|
package/readme.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# @carecard/auth-util
|
|
2
2
|
|
|
3
|
+
Non-negotiable root-cause solution rule: Always identify and solve the verified root cause, use the stronger solution, and deliver a correct, durable, production-quality result. Never treat a temporary workaround, resource increase, retry, suppression, bypass, or symptom-only patch as completion. Validate the root-cause fix against the real failing workflow and prove the end state.
|
|
4
|
+
|
|
3
5
|

|
|
4
6
|

|
|
5
7
|
|
|
@@ -11,6 +13,8 @@ Non-negotiable TDD rule: Always write the failing test first, run it to confirm
|
|
|
11
13
|
|
|
12
14
|
Non-negotiable repository isolation rule: Every repository must run its Husky hooks and tests using only files, code, fixtures, dependencies, and services contained within that repository. Tests and Husky scripts must not import, require, read, execute, or otherwise depend on sibling repositories or paths outside the repository root. app-e2e-tests is the only exception because cross-repository end-to-end testing is its explicit responsibility.
|
|
13
15
|
|
|
16
|
+
Non-negotiable error and warning rule: Never suppress, silence, hide, downgrade, filter, ignore, skip, or bypass errors or warnings from code, tests, tools, compilers, linters, or validation. Fix the root cause, then rerun the affected check and require a clean result. Expected error-path tests may assert errors, but must not conceal unexpected failures.
|
|
17
|
+
|
|
14
18
|
Non-negotiable code organization rule: Functions with the same or equivalent behavior must use the same or clearly corresponding descriptive names across CareCard repositories, and equivalent functionality must live in files with the same names within each repository's established architecture. No backward compatibility names, aliases, or duplicate locations are allowed.
|
|
15
19
|
|
|
16
20
|
## Features
|