first commit
This commit is contained in:
37
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/MatrixEntity.d.ts
generated
vendored
Normal file
37
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/MatrixEntity.d.ts
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Represents a Matrix entity
|
||||
* @category Utilities
|
||||
*/
|
||||
export declare class MatrixEntity {
|
||||
private fullId;
|
||||
private entityLocalpart;
|
||||
private entityDomain;
|
||||
/**
|
||||
* Creates a new Matrix entity
|
||||
* @param {string} fullId The full ID of the entity
|
||||
*/
|
||||
constructor(fullId: string);
|
||||
/**
|
||||
* The localpart for the entity
|
||||
*/
|
||||
get localpart(): string;
|
||||
/**
|
||||
* The domain for the entity
|
||||
*/
|
||||
get domain(): string;
|
||||
toString(): string;
|
||||
}
|
||||
/**
|
||||
* Represents a Matrix user ID
|
||||
* @category Utilities
|
||||
*/
|
||||
export declare class UserID extends MatrixEntity {
|
||||
constructor(userId: string);
|
||||
}
|
||||
/**
|
||||
* Represents a Matrix room alias
|
||||
* @category Utilities
|
||||
*/
|
||||
export declare class RoomAlias extends MatrixEntity {
|
||||
constructor(alias: string);
|
||||
}
|
70
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/MatrixEntity.js
generated
vendored
Normal file
70
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/MatrixEntity.js
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.RoomAlias = exports.UserID = exports.MatrixEntity = void 0;
|
||||
/**
|
||||
* Represents a Matrix entity
|
||||
* @category Utilities
|
||||
*/
|
||||
class MatrixEntity {
|
||||
fullId;
|
||||
entityLocalpart;
|
||||
entityDomain;
|
||||
/**
|
||||
* Creates a new Matrix entity
|
||||
* @param {string} fullId The full ID of the entity
|
||||
*/
|
||||
constructor(fullId) {
|
||||
this.fullId = fullId;
|
||||
if (!fullId)
|
||||
throw new Error("No entity ID provided");
|
||||
if (fullId.length < 2)
|
||||
throw new Error("ID too short");
|
||||
const parts = fullId.split(/:/g);
|
||||
this.entityLocalpart = parts[0].substring(1);
|
||||
this.entityDomain = parts.splice(1).join(':');
|
||||
}
|
||||
/**
|
||||
* The localpart for the entity
|
||||
*/
|
||||
get localpart() {
|
||||
return this.entityLocalpart;
|
||||
}
|
||||
/**
|
||||
* The domain for the entity
|
||||
*/
|
||||
get domain() {
|
||||
return this.entityDomain;
|
||||
}
|
||||
// override
|
||||
toString() {
|
||||
return this.fullId;
|
||||
}
|
||||
}
|
||||
exports.MatrixEntity = MatrixEntity;
|
||||
/**
|
||||
* Represents a Matrix user ID
|
||||
* @category Utilities
|
||||
*/
|
||||
class UserID extends MatrixEntity {
|
||||
constructor(userId) {
|
||||
super(userId);
|
||||
if (!userId.startsWith("@")) {
|
||||
throw new Error("Not a valid user ID");
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.UserID = UserID;
|
||||
/**
|
||||
* Represents a Matrix room alias
|
||||
* @category Utilities
|
||||
*/
|
||||
class RoomAlias extends MatrixEntity {
|
||||
constructor(alias) {
|
||||
super(alias);
|
||||
if (!alias.startsWith("#")) {
|
||||
throw new Error("Not a valid room alias");
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.RoomAlias = RoomAlias;
|
||||
//# sourceMappingURL=MatrixEntity.js.map
|
1
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/MatrixEntity.js.map
generated
vendored
Normal file
1
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/MatrixEntity.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"MatrixEntity.js","sourceRoot":"","sources":["../../src/helpers/MatrixEntity.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,MAAa,YAAY;IAQD;IAPZ,eAAe,CAAS;IACxB,YAAY,CAAS;IAE7B;;;OAGG;IACH,YAAoB,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;QAC9B,IAA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file
22
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/MatrixGlob.d.ts
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Represents a common Matrix glob. This is commonly used
|
||||
* for server ACLs and similar functions.
|
||||
* @category Utilities
|
||||
*/
|
||||
export declare class MatrixGlob {
|
||||
/**
|
||||
* The regular expression which represents this glob.
|
||||
*/
|
||||
readonly regex: RegExp;
|
||||
/**
|
||||
* Creates a new Matrix Glob
|
||||
* @param {string} glob The glob to convert. Eg: "*.example.org"
|
||||
*/
|
||||
constructor(glob: string);
|
||||
/**
|
||||
* Tests the glob against a value, returning true if it matches.
|
||||
* @param {string} val The value to test.
|
||||
* @returns {boolean} True if the value matches the glob, false otherwise.
|
||||
*/
|
||||
test(val: string): boolean;
|
||||
}
|
39
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/MatrixGlob.js
generated
vendored
Normal file
39
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/MatrixGlob.js
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.MatrixGlob = void 0;
|
||||
const globToRegexp = require("glob-to-regexp");
|
||||
/**
|
||||
* Represents a common Matrix glob. This is commonly used
|
||||
* for server ACLs and similar functions.
|
||||
* @category Utilities
|
||||
*/
|
||||
class MatrixGlob {
|
||||
/**
|
||||
* The regular expression which represents this glob.
|
||||
*/
|
||||
regex;
|
||||
/**
|
||||
* Creates a new Matrix Glob
|
||||
* @param {string} glob The glob to convert. Eg: "*.example.org"
|
||||
*/
|
||||
constructor(glob) {
|
||||
const globRegex = globToRegexp(glob, {
|
||||
extended: false,
|
||||
globstar: false,
|
||||
});
|
||||
// We need to convert `?` manually because globToRegexp's extended mode
|
||||
// does more than we want it to.
|
||||
const replaced = globRegex.toString().replace(/\\\?/g, ".");
|
||||
this.regex = new RegExp(replaced.substring(1, replaced.length - 1));
|
||||
}
|
||||
/**
|
||||
* Tests the glob against a value, returning true if it matches.
|
||||
* @param {string} val The value to test.
|
||||
* @returns {boolean} True if the value matches the glob, false otherwise.
|
||||
*/
|
||||
test(val) {
|
||||
return this.regex.test(val);
|
||||
}
|
||||
}
|
||||
exports.MatrixGlob = MatrixGlob;
|
||||
//# sourceMappingURL=MatrixGlob.js.map
|
1
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/MatrixGlob.js.map
generated
vendored
Normal file
1
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/MatrixGlob.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"MatrixGlob.js","sourceRoot":"","sources":["../../src/helpers/MatrixGlob.ts"],"names":[],"mappings":";;;AAAA,+CAA+C;AAE/C;;;;GAIG;AACH,MAAa,UAAU;IACnB;;OAEG;IACa,KAAK,CAAS;IAE9B;;;OAGG;IACH,YAAY,IAAY;QACpB,MAAM,SAAS,GAAG,YAAY,CAAC,IAAI,EAAE;YACjC,QAAQ,EAAE,KAAK;YACf,QAAQ,EAAE,KAAK;SAClB,CAAC,CAAC;QAEH,uEAAuE;QACvE,gCAAgC;QAChC,MAAM,QAAQ,GAAG,SAAS,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QAC5D,IAAI,CAAC,KAAK,GAAG,IAAI,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,EAAE,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;IACxE,CAAC;IAED;;;;OAIG;IACI,IAAI,CAAC,GAAW;QACnB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAChC,CAAC;CACJ;AA9BD,gCA8BC"}
|
40
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/MentionPill.d.ts
generated
vendored
Normal file
40
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/MentionPill.d.ts
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
import { MatrixClient } from "../MatrixClient";
|
||||
/**
|
||||
* Represents a system for generating a mention pill for an entity.
|
||||
* @category Utilities
|
||||
*/
|
||||
export declare class MentionPill {
|
||||
private entityPermalink;
|
||||
private displayName;
|
||||
private constructor();
|
||||
/**
|
||||
* The HTML component of the mention.
|
||||
*/
|
||||
get html(): string;
|
||||
/**
|
||||
* The plain text component of the mention.
|
||||
*/
|
||||
get text(): string;
|
||||
/**
|
||||
* Creates a new mention for a user in an optional room.
|
||||
* @param {string} userId The user ID the mention is for.
|
||||
* @param {String} inRoomId Optional room ID the user is being mentioned in, for the aesthetics of the mention.
|
||||
* @param {MatrixClient} client Optional client for creating a more pleasing mention.
|
||||
* @returns {Promise<MentionPill>} Resolves to the user's mention.
|
||||
*/
|
||||
static forUser(userId: string, inRoomId?: string, client?: MatrixClient): Promise<MentionPill>;
|
||||
/**
|
||||
* Creates a new mention for a room (not @room, but the room itself to be linked).
|
||||
* @param {string} roomIdOrAlias The room ID or alias to mention.
|
||||
* @param {MatrixClient} client Optional client for creating a more pleasing mention.
|
||||
* @returns {Promise<MentionPill>} Resolves to the room's mention.
|
||||
*/
|
||||
static forRoom(roomIdOrAlias: string, client?: MatrixClient): Promise<MentionPill>;
|
||||
/**
|
||||
* Creates a mention from static information.
|
||||
* @param {string} userId The user ID the mention is for.
|
||||
* @param {string} displayName The user's display name.
|
||||
* @returns {MentionPill} The mention for the user.
|
||||
*/
|
||||
static withDisplayName(userId: string, displayName: string): MentionPill;
|
||||
}
|
93
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/MentionPill.js
generated
vendored
Normal file
93
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/MentionPill.js
generated
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.MentionPill = void 0;
|
||||
const Permalinks_1 = require("./Permalinks");
|
||||
const __1 = require("..");
|
||||
/**
|
||||
* Represents a system for generating a mention pill for an entity.
|
||||
* @category Utilities
|
||||
*/
|
||||
class MentionPill {
|
||||
entityPermalink;
|
||||
displayName;
|
||||
constructor(entityPermalink, displayName) {
|
||||
this.entityPermalink = entityPermalink;
|
||||
this.displayName = displayName;
|
||||
}
|
||||
/**
|
||||
* The HTML component of the mention.
|
||||
*/
|
||||
get html() {
|
||||
return `<a href="${this.entityPermalink}">${this.displayName}</a>`;
|
||||
}
|
||||
/**
|
||||
* The plain text component of the mention.
|
||||
*/
|
||||
get text() {
|
||||
return this.displayName;
|
||||
}
|
||||
/**
|
||||
* Creates a new mention for a user in an optional room.
|
||||
* @param {string} userId The user ID the mention is for.
|
||||
* @param {String} inRoomId Optional room ID the user is being mentioned in, for the aesthetics of the mention.
|
||||
* @param {MatrixClient} client Optional client for creating a more pleasing mention.
|
||||
* @returns {Promise<MentionPill>} Resolves to the user's mention.
|
||||
*/
|
||||
static async forUser(userId, inRoomId = null, client = null) {
|
||||
const permalink = Permalinks_1.Permalinks.forUser(userId);
|
||||
let displayName = userId;
|
||||
try {
|
||||
if (client) {
|
||||
let profile = null;
|
||||
if (inRoomId) {
|
||||
profile = await client.getRoomStateEvent(inRoomId, "m.room.member", userId);
|
||||
}
|
||||
if (!profile) {
|
||||
profile = await client.getUserProfile(userId);
|
||||
}
|
||||
if (profile['displayname']) {
|
||||
displayName = profile['displayname'];
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
__1.LogService.warn("MentionPill", "Error getting profile", (0, __1.extractRequestError)(e));
|
||||
}
|
||||
return new MentionPill(permalink, displayName);
|
||||
}
|
||||
/**
|
||||
* Creates a new mention for a room (not @room, but the room itself to be linked).
|
||||
* @param {string} roomIdOrAlias The room ID or alias to mention.
|
||||
* @param {MatrixClient} client Optional client for creating a more pleasing mention.
|
||||
* @returns {Promise<MentionPill>} Resolves to the room's mention.
|
||||
*/
|
||||
static async forRoom(roomIdOrAlias, client = null) {
|
||||
let permalink = Permalinks_1.Permalinks.forRoom(roomIdOrAlias);
|
||||
let displayProp = roomIdOrAlias;
|
||||
try {
|
||||
if (client) {
|
||||
const roomId = await client.resolveRoom(roomIdOrAlias);
|
||||
const canonicalAlias = await client.getRoomStateEvent(roomId, "m.room.canonical_alias", "");
|
||||
if (canonicalAlias?.alias) {
|
||||
displayProp = canonicalAlias.alias;
|
||||
permalink = Permalinks_1.Permalinks.forRoom(displayProp);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
__1.LogService.warn("MentionPill", "Error getting room information", (0, __1.extractRequestError)(e));
|
||||
}
|
||||
return new MentionPill(permalink, displayProp);
|
||||
}
|
||||
/**
|
||||
* Creates a mention from static information.
|
||||
* @param {string} userId The user ID the mention is for.
|
||||
* @param {string} displayName The user's display name.
|
||||
* @returns {MentionPill} The mention for the user.
|
||||
*/
|
||||
static withDisplayName(userId, displayName) {
|
||||
return new MentionPill(Permalinks_1.Permalinks.forUser(userId), displayName || userId);
|
||||
}
|
||||
}
|
||||
exports.MentionPill = MentionPill;
|
||||
//# sourceMappingURL=MentionPill.js.map
|
1
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/MentionPill.js.map
generated
vendored
Normal file
1
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/MentionPill.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"MentionPill.js","sourceRoot":"","sources":["../../src/helpers/MentionPill.ts"],"names":[],"mappings":";;;AACA,6CAA0C;AAC1C,0BAAqD;AAErD;;;GAGG;AACH,MAAa,WAAW;IACQ;IAAiC;IAA7D,YAA4B,eAAuB,EAAU,WAAmB;QAApD,oBAAe,GAAf,eAAe,CAAQ;QAAU,gBAAW,GAAX,WAAW,CAAQ;IAChF,CAAC;IAED;;OAEG;IACH,IAAW,IAAI;QACX,OAAO,YAAY,IAAI,CAAC,eAAe,KAAK,IAAI,CAAC,WAAW,MAAM,CAAC;IACvE,CAAC;IAED;;OAEG;IACH,IAAW,IAAI;QACX,OAAO,IAAI,CAAC,WAAW,CAAC;I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C;gBAC5F,IAAI,cAAc,EAAE,KAAK,EAAE;oBACvB,WAAW,GAAG,cAAc,CAAC,KAAK,CAAC;oBACnC,SAAS,GAAG,uBAAU,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;iBAC/C;aACJ;SACJ;QAAC,OAAO,CAAC,EAAE;YACR,cAAU,CAAC,IAAI,CAAC,aAAa,EAAE,gCAAgC,EAAE,IAAA,uBAAmB,EAAC,CAAC,CAAC,CAAC,CAAC;SAC5F;QAED,OAAO,IAAI,WAAW,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;IACnD,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,eAAe,CAAC,MAAc,EAAE,WAAmB;QAC7D,OAAO,IAAI,WAAW,CAAC,uBAAU,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,WAAW,IAAI,MAAM,CAAC,CAAC;IAC9E,CAAC;CACJ;AAtFD,kCAsFC"}
|
58
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/Permalinks.d.ts
generated
vendored
Normal file
58
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/Permalinks.d.ts
generated
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* The parts of a permalink.
|
||||
* @see Permalinks
|
||||
* @category Utilities
|
||||
*/
|
||||
export interface PermalinkParts {
|
||||
/**
|
||||
* The room ID or alias the permalink references. May be undefined.
|
||||
*/
|
||||
roomIdOrAlias: string;
|
||||
/**
|
||||
* The user ID the permalink references. May be undefined.
|
||||
*/
|
||||
userId: string;
|
||||
/**
|
||||
* The event ID the permalink references. May be undefined.
|
||||
*/
|
||||
eventId: string;
|
||||
/**
|
||||
* The servers the permalink is routed through. May be undefined or empty.
|
||||
*/
|
||||
viaServers: string[];
|
||||
}
|
||||
/**
|
||||
* Functions for handling permalinks
|
||||
* @category Utilities
|
||||
*/
|
||||
export declare class Permalinks {
|
||||
private constructor();
|
||||
private static encodeViaArgs;
|
||||
/**
|
||||
* Creates a room permalink.
|
||||
* @param {string} roomIdOrAlias The room ID or alias to create a permalink for.
|
||||
* @param {string[]} viaServers The servers to route the permalink through.
|
||||
* @returns {string} A room permalink.
|
||||
*/
|
||||
static forRoom(roomIdOrAlias: string, viaServers?: string[]): string;
|
||||
/**
|
||||
* Creates a user permalink.
|
||||
* @param {string} userId The user ID to create a permalink for.
|
||||
* @returns {string} A user permalink.
|
||||
*/
|
||||
static forUser(userId: string): string;
|
||||
/**
|
||||
* Creates an event permalink.
|
||||
* @param {string} roomIdOrAlias The room ID or alias to create a permalink in.
|
||||
* @param {string} eventId The event ID to reference in the permalink.
|
||||
* @param {string[]} viaServers The servers to route the permalink through.
|
||||
* @returns {string} An event permalink.
|
||||
*/
|
||||
static forEvent(roomIdOrAlias: string, eventId: string, viaServers?: string[]): string;
|
||||
/**
|
||||
* Parses a permalink URL into usable parts.
|
||||
* @param {string} matrixTo The matrix.to URL to parse.
|
||||
* @returns {PermalinkParts} The parts of the permalink.
|
||||
*/
|
||||
static parseUrl(matrixTo: string): PermalinkParts;
|
||||
}
|
73
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/Permalinks.js
generated
vendored
Normal file
73
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/Permalinks.js
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Permalinks = void 0;
|
||||
/**
|
||||
* Functions for handling permalinks
|
||||
* @category Utilities
|
||||
*/
|
||||
class Permalinks {
|
||||
constructor() {
|
||||
}
|
||||
// TODO: Encode permalinks
|
||||
static encodeViaArgs(servers) {
|
||||
if (!servers || !servers.length)
|
||||
return "";
|
||||
return `?via=${servers.join("&via=")}`;
|
||||
}
|
||||
/**
|
||||
* Creates a room permalink.
|
||||
* @param {string} roomIdOrAlias The room ID or alias to create a permalink for.
|
||||
* @param {string[]} viaServers The servers to route the permalink through.
|
||||
* @returns {string} A room permalink.
|
||||
*/
|
||||
static forRoom(roomIdOrAlias, viaServers = []) {
|
||||
return `https://matrix.to/#/${roomIdOrAlias}${Permalinks.encodeViaArgs(viaServers)}`;
|
||||
}
|
||||
/**
|
||||
* Creates a user permalink.
|
||||
* @param {string} userId The user ID to create a permalink for.
|
||||
* @returns {string} A user permalink.
|
||||
*/
|
||||
static forUser(userId) {
|
||||
return `https://matrix.to/#/${userId}`;
|
||||
}
|
||||
/**
|
||||
* Creates an event permalink.
|
||||
* @param {string} roomIdOrAlias The room ID or alias to create a permalink in.
|
||||
* @param {string} eventId The event ID to reference in the permalink.
|
||||
* @param {string[]} viaServers The servers to route the permalink through.
|
||||
* @returns {string} An event permalink.
|
||||
*/
|
||||
static forEvent(roomIdOrAlias, eventId, viaServers = []) {
|
||||
return `https://matrix.to/#/${roomIdOrAlias}/${eventId}${Permalinks.encodeViaArgs(viaServers)}`;
|
||||
}
|
||||
/**
|
||||
* Parses a permalink URL into usable parts.
|
||||
* @param {string} matrixTo The matrix.to URL to parse.
|
||||
* @returns {PermalinkParts} The parts of the permalink.
|
||||
*/
|
||||
static parseUrl(matrixTo) {
|
||||
const matrixToRegexp = /^https:\/\/matrix\.to\/#\/(?<entity>[^/?]+)\/?(?<eventId>[^?]+)?(?<query>\?[^]*)?$/;
|
||||
const url = matrixToRegexp.exec(matrixTo)?.groups;
|
||||
if (!url) {
|
||||
throw new Error("Not a valid matrix.to URL");
|
||||
}
|
||||
const entity = decodeURIComponent(url.entity);
|
||||
if (entity[0] === '@') {
|
||||
return { userId: entity, roomIdOrAlias: undefined, eventId: undefined, viaServers: undefined };
|
||||
}
|
||||
else if (entity[0] === '#' || entity[0] === '!') {
|
||||
return {
|
||||
userId: undefined,
|
||||
roomIdOrAlias: entity,
|
||||
eventId: url.eventId && decodeURIComponent(url.eventId),
|
||||
viaServers: new URLSearchParams(url.query).getAll('via'),
|
||||
};
|
||||
}
|
||||
else {
|
||||
throw new Error("Unexpected entity");
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.Permalinks = Permalinks;
|
||||
//# sourceMappingURL=Permalinks.js.map
|
1
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/Permalinks.js.map
generated
vendored
Normal file
1
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/Permalinks.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"Permalinks.js","sourceRoot":"","sources":["../../src/helpers/Permalinks.ts"],"names":[],"mappings":";;;AA2BA;;;GAGG;AACH,MAAa,UAAU;IACnB;IACA,CAAC;IAED,0BAA0B;IAElB,MAAM,CAAC,aAAa,CAAC,OAAiB;QAC1C,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM;YAAE,OAAO,EAAE,CAAC;QAE3C,OAAO,QAAQ,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;IAC3C,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,OAAO,CAAC,aAAqB,EAAE,aAAuB,EAAE;QAClE,OAAO,uBAAuB,aAAa,GAAG,UAAU,CAAC,aAAa,CAAC,UAAU,CAAC,EAAE,CAAC;IACzF,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,OAAO,CAAC,MAAc;QAChC,OAAO,uBAAuB,MAAM,EAAE,CAAC;IAC3C,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,QAAQ,CAAC,aAAqB,EAAE,OAAe,EAAE,aAAuB,EAAE;QACpF,OAAO,uBAAuB,aAAa,IAAI,OAAO,GAAG,UAAU,CAAC,aAAa,CAAC,UAAU,CAAC,EAAE,CAAC;IACpG,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,QAAQ,CAAC,QAAgB;QACnC,MAAM,cAAc,GAAG,oFAAoF,CAAC;QAE5G,MAAM,GAAG,GAAG,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClD,IAAI,CAAC,GAAG,EAAE;YACN,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;SAChD;QAED,MAAM,MAAM,GAAG,kBAAkB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAC9C,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;YACnB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC;SAClG;aAAM,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;YAC/C,OAAO;gBACH,MAAM,EAAE,SAAS;gBACjB,aAAa,EAAE,MAAM;gBACrB,OAAO,EAAE,GAAG,CAAC,OAAO,IAAI,kBAAkB,CAAC,GAAG,CAAC,OAAO,CAAC;gBACvD,UAAU,EAAE,IAAI,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;aAC3D,CAAC;SACL;aAAM;YACH,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;SACxC;IACL,CAAC;CACJ;AArED,gCAqEC"}
|
48
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/ProfileCache.d.ts
generated
vendored
Normal file
48
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/ProfileCache.d.ts
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
import { MatrixClient, MatrixProfile } from "..";
|
||||
import { Appservice } from "../appservice/Appservice";
|
||||
/**
|
||||
* Functions for avoiding calls to profile endpoints. Useful for bots when
|
||||
* people are mentioned often or bridges which need profile information
|
||||
* often.
|
||||
* @category Utilities
|
||||
*/
|
||||
export declare class ProfileCache {
|
||||
private client;
|
||||
private cache;
|
||||
/**
|
||||
* Creates a new profile cache.
|
||||
* @param {number} maxEntries The maximum number of entries to cache.
|
||||
* @param {number} maxAgeMs The maximum age of an entry in milliseconds.
|
||||
* @param {MatrixClient} client The client to use to get profile updates.
|
||||
*/
|
||||
constructor(maxEntries: number, maxAgeMs: number, client: MatrixClient);
|
||||
private getCacheKey;
|
||||
/**
|
||||
* Watch for profile changes to cached entries with the provided client. The
|
||||
* same client will also be used to update the user's profile in the cache.
|
||||
* @param {MatrixClient} client The client to watch for profile changes with.
|
||||
*/
|
||||
watchWithClient(client: MatrixClient): void;
|
||||
/**
|
||||
* Watch for profile changes to cached entries with the provided application
|
||||
* service. The clientFn will be called to get the relevant client for any
|
||||
* updates. If the clientFn is null, the appservice's bot user will be used.
|
||||
* The clientFn takes two arguments: the user ID being updated and the room ID
|
||||
* they are being updated in (shouldn't be null). The return value should be the
|
||||
* MatrixClient to use, or null to use the appservice's bot client. The same
|
||||
* client will be used to update the user's general profile, if that profile
|
||||
* is cached.
|
||||
* @param {Appservice} appservice The application service to watch for profile changes with.
|
||||
* @param {Function} clientFn The function to use to acquire profile updates with. If null, the appservice's bot client will be used.
|
||||
*/
|
||||
watchWithAppservice(appservice: Appservice, clientFn?: (userId: string, roomId: string) => MatrixClient): void;
|
||||
/**
|
||||
* Gets a profile for a user in optional room.
|
||||
* @param {string} userId The user ID to get a profile for.
|
||||
* @param {string|null} roomId Optional room ID to get a per-room profile for the user.
|
||||
* @returns {Promise<MatrixProfile>} Resolves to the user's profile.
|
||||
*/
|
||||
getUserProfile(userId: string, roomId?: string): Promise<MatrixProfile>;
|
||||
private getUserProfileWith;
|
||||
private tryUpdateProfile;
|
||||
}
|
116
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/ProfileCache.js
generated
vendored
Normal file
116
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/ProfileCache.js
generated
vendored
Normal file
@@ -0,0 +1,116 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ProfileCache = void 0;
|
||||
const LRU = require("lru-cache");
|
||||
const __1 = require("..");
|
||||
const MembershipEvent_1 = require("../models/events/MembershipEvent");
|
||||
/**
|
||||
* Functions for avoiding calls to profile endpoints. Useful for bots when
|
||||
* people are mentioned often or bridges which need profile information
|
||||
* often.
|
||||
* @category Utilities
|
||||
*/
|
||||
class ProfileCache {
|
||||
client;
|
||||
cache;
|
||||
/**
|
||||
* Creates a new profile cache.
|
||||
* @param {number} maxEntries The maximum number of entries to cache.
|
||||
* @param {number} maxAgeMs The maximum age of an entry in milliseconds.
|
||||
* @param {MatrixClient} client The client to use to get profile updates.
|
||||
*/
|
||||
constructor(maxEntries, maxAgeMs, client) {
|
||||
this.client = client;
|
||||
this.cache = new LRU.LRUCache({
|
||||
max: maxEntries,
|
||||
ttl: maxAgeMs,
|
||||
});
|
||||
}
|
||||
getCacheKey(userId, roomId) {
|
||||
return `${userId}@${roomId || '<none>'}`;
|
||||
}
|
||||
/**
|
||||
* Watch for profile changes to cached entries with the provided client. The
|
||||
* same client will also be used to update the user's profile in the cache.
|
||||
* @param {MatrixClient} client The client to watch for profile changes with.
|
||||
*/
|
||||
watchWithClient(client) {
|
||||
client.on("room.event", async (roomId, event) => {
|
||||
if (!event['state_key'] || !event['content'] || event['type'] !== 'm.room.member')
|
||||
return;
|
||||
await this.tryUpdateProfile(roomId, new MembershipEvent_1.MembershipEvent(event), client);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Watch for profile changes to cached entries with the provided application
|
||||
* service. The clientFn will be called to get the relevant client for any
|
||||
* updates. If the clientFn is null, the appservice's bot user will be used.
|
||||
* The clientFn takes two arguments: the user ID being updated and the room ID
|
||||
* they are being updated in (shouldn't be null). The return value should be the
|
||||
* MatrixClient to use, or null to use the appservice's bot client. The same
|
||||
* client will be used to update the user's general profile, if that profile
|
||||
* is cached.
|
||||
* @param {Appservice} appservice The application service to watch for profile changes with.
|
||||
* @param {Function} clientFn The function to use to acquire profile updates with. If null, the appservice's bot client will be used.
|
||||
*/
|
||||
watchWithAppservice(appservice, clientFn = null) {
|
||||
if (!clientFn)
|
||||
clientFn = () => appservice.botClient;
|
||||
appservice.on("room.event", async (roomId, event) => {
|
||||
if (!event['state_key'] || !event['content'] || event['type'] !== 'm.room.member')
|
||||
return;
|
||||
const memberEvent = new MembershipEvent_1.MembershipEvent(event);
|
||||
let client = clientFn(memberEvent.membershipFor, roomId);
|
||||
if (!client)
|
||||
client = appservice.botClient;
|
||||
await this.tryUpdateProfile(roomId, memberEvent, client);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Gets a profile for a user in optional room.
|
||||
* @param {string} userId The user ID to get a profile for.
|
||||
* @param {string|null} roomId Optional room ID to get a per-room profile for the user.
|
||||
* @returns {Promise<MatrixProfile>} Resolves to the user's profile.
|
||||
*/
|
||||
async getUserProfile(userId, roomId = null) {
|
||||
const cacheKey = this.getCacheKey(userId, roomId);
|
||||
const cached = this.cache.get(cacheKey);
|
||||
if (cached)
|
||||
return Promise.resolve(cached);
|
||||
const profile = await this.getUserProfileWith(userId, roomId, this.client);
|
||||
this.cache.set(cacheKey, profile);
|
||||
return profile;
|
||||
}
|
||||
async getUserProfileWith(userId, roomId, client) {
|
||||
try {
|
||||
if (roomId) {
|
||||
const membership = await client.getRoomStateEvent(roomId, "m.room.member", userId);
|
||||
return new __1.MatrixProfile(userId, membership);
|
||||
}
|
||||
else {
|
||||
const profile = await client.getUserProfile(userId);
|
||||
return new __1.MatrixProfile(userId, profile);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
__1.LogService.warn("ProfileCache", "Non-fatal error getting user profile. They might not exist.");
|
||||
__1.LogService.warn("ProfileCache", (0, __1.extractRequestError)(e));
|
||||
return new __1.MatrixProfile(userId, {});
|
||||
}
|
||||
}
|
||||
async tryUpdateProfile(roomId, memberEvent, client) {
|
||||
const roomCacheKey = this.getCacheKey(memberEvent.membershipFor, roomId);
|
||||
const generalCacheKey = this.getCacheKey(memberEvent.membershipFor, null);
|
||||
if (this.cache.has(roomCacheKey)) {
|
||||
this.cache.set(roomCacheKey, new __1.MatrixProfile(memberEvent.membershipFor, memberEvent.content));
|
||||
}
|
||||
// TODO: Try and figure out semantics for this updating.
|
||||
// Large accounts could cause hammering on the profile endpoint, but hopefully it is cached by the server.
|
||||
if (this.cache.has(generalCacheKey)) {
|
||||
const profile = await this.getUserProfileWith(memberEvent.membershipFor, null, client);
|
||||
this.cache.set(generalCacheKey, profile);
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.ProfileCache = ProfileCache;
|
||||
//# sourceMappingURL=ProfileCache.js.map
|
1
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/ProfileCache.js.map
generated
vendored
Normal file
1
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/ProfileCache.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"ProfileCache.js","sourceRoot":"","sources":["../../src/helpers/ProfileCache.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AAEjC,0BAAkF;AAClF,sEAAmE;AAKnE;;;;;GAKG;AACH,MAAa,YAAY;IASqC;IARlD,KAAK,CAAwC;IAErD;;;;;OAKG;IACH,YAAY,UAAkB,EAAE,QAAgB,EAAU,MAAoB;QAApB,WAAM,GAAN,MAAM,CAAc;QAC1E,IAAI,CAAC,KAAK,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC;YAC1B,GAAG,EAAE,UAAU;YACf,GAAG,EAAE,QAAQ;SAChB,CAAC,CAAC;IACP,CAAC;IAEO,WAAW,CAAC,MAAc,EAAE,MAAqB;QACrD,OAAO,GAAG,MAAM,IAAI,MAAM,IAAI,QAAQ,EAAE,CAAC;IAC7C,CAAC;IAED;;;;OAIG;IACI,eAAe,CAAC,MAAoB;QACvC,MAAM,CAAC,EAAE,CAAC,YAAY,EAAE,KAAK,EAAE,MAAc,EAAE,KAAa,EAAE,EAAE;YAC5D,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,eAAe;gBAAE,OAAO;YAC1F,MAAM,IAAI,CAAC,gBAAgB,CAAC,MAAM,EAAE,IAAI,iCAAe,CAAC,KAAK,CAAC,EAAE,MAAM,CA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,GAAG,CAAC,eAAe,CAAC,EAAE;YACjC,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAAC,WAAW,CAAC,aAAa,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;YACvF,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;SAC5C;IACL,CAAC;CACJ;AAxGD,oCAwGC"}
|
17
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/RichReply.d.ts
generated
vendored
Normal file
17
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/RichReply.d.ts
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Helper for creating rich replies.
|
||||
* @category Utilities
|
||||
*/
|
||||
export declare class RichReply {
|
||||
private constructor();
|
||||
/**
|
||||
* Generates the event content required to reply to the provided event with the
|
||||
* provided text.
|
||||
* @param {string} roomId the room ID the event being replied to resides in
|
||||
* @param {any} event the event to reply to
|
||||
* @param {string} withText the plain text to reply with
|
||||
* @param {string} withHtml the HTML to reply with
|
||||
* @returns {any} the content of the event representing the reply
|
||||
*/
|
||||
static createFor(roomId: string, event: any, withText: string, withHtml: string): any;
|
||||
}
|
47
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/RichReply.js
generated
vendored
Normal file
47
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/RichReply.js
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.RichReply = void 0;
|
||||
const sanitizeHtml = require("sanitize-html");
|
||||
/**
|
||||
* Helper for creating rich replies.
|
||||
* @category Utilities
|
||||
*/
|
||||
class RichReply {
|
||||
constructor() {
|
||||
}
|
||||
/**
|
||||
* Generates the event content required to reply to the provided event with the
|
||||
* provided text.
|
||||
* @param {string} roomId the room ID the event being replied to resides in
|
||||
* @param {any} event the event to reply to
|
||||
* @param {string} withText the plain text to reply with
|
||||
* @param {string} withHtml the HTML to reply with
|
||||
* @returns {any} the content of the event representing the reply
|
||||
*/
|
||||
static createFor(roomId, event, withText, withHtml) {
|
||||
const originalBody = (event["content"] ? event["content"]["body"] : "") || "";
|
||||
let originalHtml = (event["content"] ? event["content"]["formatted_body"] : "") || null;
|
||||
if (originalHtml === null) {
|
||||
originalHtml = sanitizeHtml(originalBody);
|
||||
}
|
||||
const fallbackText = "> <" + event["sender"] + "> " + originalBody.split("\n").join("\n> ");
|
||||
const fallbackHtml = "<mx-reply><blockquote>"
|
||||
+ `<a href="https://matrix.to/#/${roomId}/${event["event_id"]}">In reply to</a> `
|
||||
+ `<a href="https://matrix.to/#/${event["sender"]}">${event["sender"]}</a>`
|
||||
+ "<br />" + originalHtml
|
||||
+ "</blockquote></mx-reply>";
|
||||
return {
|
||||
"m.relates_to": {
|
||||
"m.in_reply_to": {
|
||||
"event_id": event["event_id"],
|
||||
},
|
||||
},
|
||||
"msgtype": "m.text",
|
||||
"body": fallbackText + "\n\n" + withText,
|
||||
"format": "org.matrix.custom.html",
|
||||
"formatted_body": fallbackHtml + withHtml,
|
||||
};
|
||||
}
|
||||
}
|
||||
exports.RichReply = RichReply;
|
||||
//# sourceMappingURL=RichReply.js.map
|
1
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/RichReply.js.map
generated
vendored
Normal file
1
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/RichReply.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"RichReply.js","sourceRoot":"","sources":["../../src/helpers/RichReply.ts"],"names":[],"mappings":";;;AAAA,8CAA8C;AAE9C;;;GAGG;AACH,MAAa,SAAS;IAClB;IACA,CAAC;IAED;;;;;;;;OAQG;IACI,MAAM,CAAC,SAAS,CAAC,MAAc,EAAE,KAAU,EAAE,QAAgB,EAAE,QAAgB;QAClF,MAAM,YAAY,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC;QAC9E,IAAI,YAAY,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC;QACxF,IAAI,YAAY,KAAK,IAAI,EAAE;YACvB,YAAY,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC;SAC7C;QAED,MAAM,YAAY,GAAG,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,IAAI,GAAG,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC5F,MAAM,YAAY,GAAG,wBAAwB;cACvC,gCAAgC,MAAM,IAAI,KAAK,CAAC,UAAU,CAAC,oBAAoB;cAC/E,gCAAgC,KAAK,CAAC,QAAQ,CAAC,KAAK,KAAK,CAAC,QAAQ,CAAC,MAAM;cACzE,QAAQ,GAAG,YAAY;cACvB,0BAA0B,CAAC;QAEjC,OAAO;YACH,cAAc,EAAE;gBACZ,eAAe,EAAE;oBACb,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC;iBAChC;aACJ;YACD,SAAS,EAAE,QAAQ;YACnB,MAAM,EAAE,YAAY,GAAG,MAAM,GAAG,QAAQ;YACxC,QAAQ,EAAE,wBAAwB;YAClC,gBAAgB,EAAE,YAAY,GAAG,QAAQ;SAC5C,CAAC;IACN,CAAC;CACJ;AAvCD,8BAuCC"}
|
6
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/Types.d.ts
generated
vendored
Normal file
6
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/Types.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
export type Json = string | number | boolean | null | undefined | Json[] | {
|
||||
[key: string]: Json;
|
||||
};
|
||||
export interface IJsonType {
|
||||
[key: string]: Json;
|
||||
}
|
3
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/Types.js
generated
vendored
Normal file
3
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/Types.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=Types.js.map
|
1
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/Types.js.map
generated
vendored
Normal file
1
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/Types.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"Types.js","sourceRoot":"","sources":["../../src/helpers/Types.ts"],"names":[],"mappings":""}
|
32
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/UnpaddedBase64.d.ts
generated
vendored
Normal file
32
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/UnpaddedBase64.d.ts
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
/// <reference types="node" />
|
||||
/**
|
||||
* Unpadded Base64 utilities for Matrix.
|
||||
* @category Utilities
|
||||
*/
|
||||
export declare class UnpaddedBase64 {
|
||||
private constructor();
|
||||
/**
|
||||
* Encodes a buffer to Unpadded Base64
|
||||
* @param {Buffer} buf The buffer to encode.
|
||||
* @returns {string} The Unpadded Base64 string
|
||||
*/
|
||||
static encodeBuffer(buf: Buffer): string;
|
||||
/**
|
||||
* Encodes a string to Unpadded Base64
|
||||
* @param {string} str The string to encode.
|
||||
* @returns {string} The Unpadded Base64 string
|
||||
*/
|
||||
static encodeString(str: string): string;
|
||||
/**
|
||||
* Encodes a buffer to Unpadded Base64 (URL Safe Edition)
|
||||
* @param {Buffer} buf The buffer to encode.
|
||||
* @returns {string} The Unpadded Base64 string
|
||||
*/
|
||||
static encodeBufferUrlSafe(buf: Buffer): string;
|
||||
/**
|
||||
* Encodes a string to Unpadded Base64 (URL Safe Edition)
|
||||
* @param {string} str The string to encode.
|
||||
* @returns {string} The Unpadded Base64 string
|
||||
*/
|
||||
static encodeStringUrlSafe(str: string): string;
|
||||
}
|
45
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/UnpaddedBase64.js
generated
vendored
Normal file
45
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/UnpaddedBase64.js
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.UnpaddedBase64 = void 0;
|
||||
/**
|
||||
* Unpadded Base64 utilities for Matrix.
|
||||
* @category Utilities
|
||||
*/
|
||||
class UnpaddedBase64 {
|
||||
constructor() {
|
||||
}
|
||||
/**
|
||||
* Encodes a buffer to Unpadded Base64
|
||||
* @param {Buffer} buf The buffer to encode.
|
||||
* @returns {string} The Unpadded Base64 string
|
||||
*/
|
||||
static encodeBuffer(buf) {
|
||||
return buf.toString('base64').replace(/[=]*$/g, '');
|
||||
}
|
||||
/**
|
||||
* Encodes a string to Unpadded Base64
|
||||
* @param {string} str The string to encode.
|
||||
* @returns {string} The Unpadded Base64 string
|
||||
*/
|
||||
static encodeString(str) {
|
||||
return UnpaddedBase64.encodeBuffer(Buffer.from(str));
|
||||
}
|
||||
/**
|
||||
* Encodes a buffer to Unpadded Base64 (URL Safe Edition)
|
||||
* @param {Buffer} buf The buffer to encode.
|
||||
* @returns {string} The Unpadded Base64 string
|
||||
*/
|
||||
static encodeBufferUrlSafe(buf) {
|
||||
return UnpaddedBase64.encodeBuffer(buf).replace(/\+/g, '-').replace(/\//g, '_');
|
||||
}
|
||||
/**
|
||||
* Encodes a string to Unpadded Base64 (URL Safe Edition)
|
||||
* @param {string} str The string to encode.
|
||||
* @returns {string} The Unpadded Base64 string
|
||||
*/
|
||||
static encodeStringUrlSafe(str) {
|
||||
return UnpaddedBase64.encodeBufferUrlSafe(Buffer.from(str));
|
||||
}
|
||||
}
|
||||
exports.UnpaddedBase64 = UnpaddedBase64;
|
||||
//# sourceMappingURL=UnpaddedBase64.js.map
|
1
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/UnpaddedBase64.js.map
generated
vendored
Normal file
1
node_modules/@vector-im/matrix-bot-sdk/lib/helpers/UnpaddedBase64.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"UnpaddedBase64.js","sourceRoot":"","sources":["../../src/helpers/UnpaddedBase64.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,MAAa,cAAc;IACvB;IACA,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,YAAY,CAAC,GAAW;QAClC,OAAO,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IACxD,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,YAAY,CAAC,GAAW;QAClC,OAAO,cAAc,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IACzD,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,mBAAmB,CAAC,GAAW;QACzC,OAAO,cAAc,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACpF,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,mBAAmB,CAAC,GAAW;QACzC,OAAO,cAAc,CAAC,mBAAmB,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAChE,CAAC;CACJ;AAvCD,wCAuCC"}
|
Reference in New Issue
Block a user