Auto-commit 2026-04-29 16:31

This commit is contained in:
2026-04-29 16:31:27 -04:00
parent e8687bb6b2
commit 0495ee5bd2
19691 changed files with 3272886 additions and 138 deletions

View File

@@ -0,0 +1,7 @@
export default abstract class AuthStrategy {
private authType;
protected constructor(authType: string);
getAuthType(): string;
abstract getAuthString(): Promise<string>;
abstract requiresAuthentication(): boolean;
}

11
node_modules/twilio/lib/auth_strategy/AuthStrategy.js generated vendored Normal file
View File

@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class AuthStrategy {
constructor(authType) {
this.authType = authType;
}
getAuthType() {
return this.authType;
}
}
exports.default = AuthStrategy;

View File

@@ -0,0 +1,8 @@
import AuthStrategy from "./AuthStrategy";
export default class BasicAuthStrategy extends AuthStrategy {
private username;
private password;
constructor(username: string, password: string);
getAuthString(): Promise<string>;
requiresAuthentication(): boolean;
}

View File

@@ -0,0 +1,21 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const AuthStrategy_1 = __importDefault(require("./AuthStrategy"));
class BasicAuthStrategy extends AuthStrategy_1.default {
constructor(username, password) {
super("basic");
this.username = username;
this.password = password;
}
getAuthString() {
const auth = Buffer.from(this.username + ":" + this.password).toString("base64");
return Promise.resolve(`Basic ${auth}`);
}
requiresAuthentication() {
return true;
}
}
exports.default = BasicAuthStrategy;

View File

@@ -0,0 +1,6 @@
import AuthStrategy from "./AuthStrategy";
export default class NoAuthStrategy extends AuthStrategy {
constructor();
getAuthString(): Promise<string>;
requiresAuthentication(): boolean;
}

View File

@@ -0,0 +1,18 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const AuthStrategy_1 = __importDefault(require("./AuthStrategy"));
class NoAuthStrategy extends AuthStrategy_1.default {
constructor() {
super("noauth");
}
getAuthString() {
return Promise.resolve("");
}
requiresAuthentication() {
return false;
}
}
exports.default = NoAuthStrategy;

View File

@@ -0,0 +1,16 @@
import AuthStrategy from "./AuthStrategy";
import TokenManager from "../http/bearer_token/TokenManager";
export default class TokenAuthStrategy extends AuthStrategy {
private token;
private tokenManager;
constructor(tokenManager: TokenManager);
getAuthString(): Promise<string>;
requiresAuthentication(): boolean;
fetchToken(): Promise<string>;
/**
* Function to check if the token is expired with a buffer of 30 seconds.
* @param token - The JWT token as a string.
* @returns Boolean indicating if the token is expired.
*/
isTokenExpired(token: string): boolean;
}

View File

@@ -0,0 +1,60 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const AuthStrategy_1 = __importDefault(require("./AuthStrategy"));
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
class TokenAuthStrategy extends AuthStrategy_1.default {
constructor(tokenManager) {
super("token");
this.token = "";
this.tokenManager = tokenManager;
}
async getAuthString() {
return this.fetchToken()
.then((token) => {
this.token = token;
return `Bearer ${this.token}`;
})
.catch((error) => {
throw new Error(`Failed to fetch access token: ${error.message}`);
});
}
requiresAuthentication() {
return true;
}
async fetchToken() {
if (this.token == null ||
this.token.length === 0 ||
this.isTokenExpired(this.token)) {
return this.tokenManager.fetchToken();
}
return Promise.resolve(this.token);
}
/**
* Function to check if the token is expired with a buffer of 30 seconds.
* @param token - The JWT token as a string.
* @returns Boolean indicating if the token is expired.
*/
isTokenExpired(token) {
try {
// Decode the token without verifying the signature, as we only want to read the expiration for this check
const decoded = jsonwebtoken_1.default.decode(token);
if (!decoded || !decoded.exp) {
// If the token doesn't have an expiration, consider it expired
return true;
}
const expiresAt = decoded.exp * 1000;
const bufferMilliseconds = 30 * 1000;
const bufferExpiresAt = expiresAt - bufferMilliseconds;
// Return true if the current time is after the expiration time with buffer
return Date.now() > bufferExpiresAt;
}
catch (error) {
// If there's an error decoding the token, consider it expired
return true;
}
}
}
exports.default = TokenAuthStrategy;