@stacksjs/auth 0.75.37 → 0.75.40
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/dist/gate.d.ts +1 -1
- package/dist/oauth-authorization.d.ts +2 -2
- package/dist/passkey.d.ts +1 -1
- package/dist/referrals.js +1 -1
- package/dist/tokens.d.ts +4 -16
- package/package.json +13 -13
package/dist/gate.d.ts
CHANGED
|
@@ -320,7 +320,7 @@ export declare class AuthorizationResponse {
|
|
|
320
320
|
*/
|
|
321
321
|
export declare class AuthorizationException extends Error {
|
|
322
322
|
public readonly code?: string;
|
|
323
|
-
public readonly status
|
|
323
|
+
public readonly status: number;
|
|
324
324
|
constructor(message?: string, code?: string, status?: number);
|
|
325
325
|
}
|
|
326
326
|
export default Gate;
|
|
@@ -55,7 +55,7 @@ export type OAuthAuthorizationRequestErrorCode = | 'invalid_request'
|
|
|
55
55
|
/** A protocol failure plus the only callback target that is safe to use. */
|
|
56
56
|
export declare class OAuthAuthorizationRequestError extends Error {
|
|
57
57
|
public readonly code: OAuthAuthorizationRequestErrorCode;
|
|
58
|
-
public readonly redirectUri
|
|
59
|
-
public readonly state
|
|
58
|
+
public readonly redirectUri: string | null;
|
|
59
|
+
public readonly state: string | null;
|
|
60
60
|
constructor(code: OAuthAuthorizationRequestErrorCode, message: string, redirectUri?: string | null, state?: string | null);
|
|
61
61
|
}
|
package/dist/passkey.d.ts
CHANGED
|
@@ -40,7 +40,7 @@ export declare function getUserPasskey(userId: number, passkeyId: string): Promi
|
|
|
40
40
|
* stacksjs/stacks#1861 A-4.
|
|
41
41
|
*/
|
|
42
42
|
export declare function updatePasskeyCounter(userId: number, passkeyId: string, newCounter: number): Promise<boolean>;
|
|
43
|
-
export declare function setCurrentRegistrationOptions(verified: VerifiedRegistrationResponse): Promise<void>;
|
|
43
|
+
export declare function setCurrentRegistrationOptions(user: { id: number, email?: string }, verified: VerifiedRegistrationResponse): Promise<void>;
|
|
44
44
|
/**
|
|
45
45
|
* Persist a server-issued WebAuthn challenge for the given user +
|
|
46
46
|
* purpose. Deletes any prior challenge for the same (user, purpose)
|
package/dist/referrals.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{randomBytes}from"node:crypto";export function normalizeReferralCode(value){if(typeof value!=="string")return null;const code=value.trim().toLowerCase();return/^[a-f0-9]{24}$/.test(code)?code:null}function userId(value){if(!Number.isSafeInteger(value)||value<1)throw TypeError("A positive integer user ID is required.")}async function connection(database){return database??(await import("@stacksjs/database/runtime")).db}async function rows(database,sql,bindings){const result=await database.unsafe(sql,bindings).execute();if(Array.isArray(result))return result;if(result&&typeof result==="object"&&"rows"in result&&Array.isArray(result.rows))return result.rows;throw Error("The referral query returned an unsupported result.")}async function duplicate(error){const{isUniqueViolation}=await import("@stacksjs/orm");return isUniqueViolation(error)}export async function createReferralCode(ownerId,database){userId(ownerId);const db=await connection(database);for(let attempt=0;attempt<5;attempt++){const existing=await rows(db
|
|
1
|
+
import{randomBytes}from"node:crypto";export function normalizeReferralCode(value){if(typeof value!=="string")return null;const code=value.trim().toLowerCase();return/^[a-f0-9]{24}$/.test(code)?code:null}function userId(value){if(!Number.isSafeInteger(value)||value<1)throw TypeError("A positive integer user ID is required.")}async function connection(database){return database??(await import("@stacksjs/database/runtime")).db}async function rows(database,sql,bindings){const result=await database.unsafe(sql,bindings).execute();if(Array.isArray(result))return result;if(result&&typeof result==="object"&&"rows"in result&&Array.isArray(result.rows))return result.rows;throw Error("The referral query returned an unsupported result.")}async function duplicate(error){const{isUniqueViolation}=await import("@stacksjs/orm");return isUniqueViolation(error)}async function placeholder(){const{getDatabaseDialect,sqlHelpers}=await import("@stacksjs/database/runtime");return sqlHelpers(getDatabaseDialect()).param}export async function createReferralCode(ownerId,database){userId(ownerId);const db=await connection(database),param=await placeholder();for(let attempt=0;attempt<5;attempt++){const existing=await rows(db,`SELECT code, user_id FROM referral_codes WHERE user_id = ${param(1)}`,[ownerId]);if(existing[0])return existing[0].code;const code=randomBytes(12).toString("hex");try{await db.unsafe(`INSERT INTO referral_codes (user_id, code) VALUES (${param(1)}, ${param(2)})`,[ownerId,code]).execute();return code}catch(error){if(!await duplicate(error))throw error}}throw Error("Could not allocate a referral code. Please retry.")}export async function attributeReferral(newUserId,input,database){userId(newUserId);const code=normalizeReferralCode(input);if(!code)return!1;const db=await connection(database),param=await placeholder(),owner=(await rows(db,`SELECT code, user_id FROM referral_codes WHERE code = ${param(1)}`,[code]))[0];if(!owner||Number(owner.user_id)===newUserId)return!1;try{await db.unsafe(`INSERT INTO referrals (referrer_id, referred_user_id, code, status) VALUES (${param(1)}, ${param(2)}, ${param(3)}, ${param(4)})`,[Number(owner.user_id),newUserId,code,"registered"]).execute();return!0}catch(error){if(await duplicate(error))return!1;throw error}}export async function qualifyReferral(referredUserId,database){userId(referredUserId);const db=await connection(database),param=await placeholder(),now=new Date().toISOString().slice(0,19).replace("T"," ");await db.unsafe(`UPDATE referrals SET status = ${param(1)}, qualified_at = ${param(2)}, updated_at = ${param(3)} WHERE referred_user_id = ${param(4)} AND status = ${param(5)}`,["qualified",now,now,referredUserId,"registered"]).execute()}export async function referralSummary(ownerId,database){userId(ownerId);const db=await connection(database),param=await placeholder(),codes=await rows(db,`SELECT code, user_id FROM referral_codes WHERE user_id = ${param(1)}`,[ownerId]),counts=await rows(db,`SELECT COUNT(*) AS total, SUM(CASE WHEN status = ${param(1)} THEN 1 ELSE 0 END) AS qualified FROM referrals WHERE referrer_id = ${param(2)}`,["qualified",ownerId]);return{code:codes[0]?.code??null,referred:Number(counts[0]?.total??0),qualified:Number(counts[0]?.qualified??0)}}
|
package/dist/tokens.d.ts
CHANGED
|
@@ -108,29 +108,17 @@ export declare function tokenAbilities(): Promise<string[]>;
|
|
|
108
108
|
* console.log(result.refreshToken) // Use this to get new access tokens
|
|
109
109
|
*/
|
|
110
110
|
export declare function createToken(userId: number, name?: string, scopes?: string[], options?: {
|
|
111
|
-
|
|
111
|
+
|
|
112
112
|
clientId?: number
|
|
113
113
|
expiresInMinutes?: number
|
|
114
114
|
expiresAt?: Date
|
|
115
115
|
withRefreshToken?: boolean
|
|
116
116
|
refreshExpiresInDays?: number
|
|
117
|
-
|
|
118
|
-
* What the browser called itself, when there is one.
|
|
119
|
-
*
|
|
120
|
-
* Stored so a person can recognise their own sessions on a list well enough
|
|
121
|
-
* to revoke one. Untrusted - it is a string a client chose - which is why
|
|
122
|
-
* it sits beside the address rather than instead of it, and why nothing
|
|
123
|
-
* authorises on it.
|
|
124
|
-
*/
|
|
117
|
+
|
|
125
118
|
userAgent?: string | null
|
|
126
|
-
|
|
119
|
+
|
|
127
120
|
ipAddress?: string | null
|
|
128
|
-
|
|
129
|
-
* The owner's table, for a token that does not belong to a user.
|
|
130
|
-
*
|
|
131
|
-
* `oauth_access_tokens` is polymorphic; a caller that passes only an id
|
|
132
|
-
* gets `users`, which is what every caller predating the pair meant.
|
|
133
|
-
*/
|
|
121
|
+
|
|
134
122
|
tokenableType?: string
|
|
135
123
|
}): Promise<PersonalAccessTokenResult>;
|
|
136
124
|
/**
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@stacksjs/auth",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"sideEffects": false,
|
|
5
|
-
"version": "0.75.
|
|
5
|
+
"version": "0.75.40",
|
|
6
6
|
"description": "A more simplistic way to authenticate.",
|
|
7
7
|
"author": "Chris Breuer",
|
|
8
8
|
"contributors": [
|
|
@@ -58,18 +58,18 @@
|
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"@stacksjs/bun-router": "^0.1.18",
|
|
61
|
-
"@stacksjs/cache": "0.75.
|
|
62
|
-
"@stacksjs/config": "0.75.
|
|
63
|
-
"@stacksjs/database": "0.75.
|
|
64
|
-
"@stacksjs/email": "0.75.
|
|
65
|
-
"@stacksjs/env": "0.75.
|
|
66
|
-
"@stacksjs/error-handling": "0.75.
|
|
67
|
-
"@stacksjs/logging": "0.75.
|
|
68
|
-
"@stacksjs/orm": "0.75.
|
|
69
|
-
"@stacksjs/path": "0.75.
|
|
70
|
-
"@stacksjs/router": "0.75.
|
|
71
|
-
"@stacksjs/security": "0.75.
|
|
72
|
-
"@stacksjs/storage": "0.75.
|
|
61
|
+
"@stacksjs/cache": "0.75.40",
|
|
62
|
+
"@stacksjs/config": "0.75.40",
|
|
63
|
+
"@stacksjs/database": "0.75.40",
|
|
64
|
+
"@stacksjs/email": "0.75.40",
|
|
65
|
+
"@stacksjs/env": "0.75.40",
|
|
66
|
+
"@stacksjs/error-handling": "0.75.40",
|
|
67
|
+
"@stacksjs/logging": "0.75.40",
|
|
68
|
+
"@stacksjs/orm": "0.75.40",
|
|
69
|
+
"@stacksjs/path": "0.75.40",
|
|
70
|
+
"@stacksjs/router": "0.75.40",
|
|
71
|
+
"@stacksjs/security": "0.75.40",
|
|
72
|
+
"@stacksjs/storage": "0.75.40",
|
|
73
73
|
"@stacksjs/ts-auth": "^0.4.4",
|
|
74
74
|
"ts-qr-codes": "^0.1.8"
|
|
75
75
|
},
|