mirror of
https://github.com/wassname/talk.git
synced 2026-09-10 12:43:11 +08:00
[CORL-1074] Upgrade dependencies (#2999)
* chore: upgrade eslint, typescript * chore: upgrade deps * chore: revert upgrade ts-node-dev * chore: revert unneeded comments Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
@@ -23,9 +23,9 @@ import { Request, RequestHandler } from "coral-server/types/express";
|
||||
|
||||
function getMetricsOptions(req: Request) {
|
||||
// Get the current Tenant on the request.
|
||||
const { id: tenantID } = req.coral?.tenant!;
|
||||
const { id: tenantID } = req.coral!.tenant!;
|
||||
|
||||
const now = req.coral?.now!;
|
||||
const now = req.coral!.now;
|
||||
|
||||
// To set a fixed date for the date, uncomment the line below.
|
||||
// const now = DateTime.utc(2020, 5, 5, 12, 30).toJSDate();
|
||||
|
||||
@@ -27,6 +27,7 @@ export type JWTStrategyOptions = Pick<
|
||||
/**
|
||||
* Token is the various forms of the Token that can be verified.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
export type Token = OIDCIDToken | SSOToken | JWTToken | object | string | null;
|
||||
|
||||
/**
|
||||
@@ -49,6 +50,7 @@ export interface Verifier<T = Token> {
|
||||
* supports will perform type checking and ensure that the given Tenant
|
||||
* supports the requested verification type.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
supports: (token: T | object, tenant: Tenant, kid?: string) => token is T;
|
||||
}
|
||||
|
||||
|
||||
@@ -84,6 +84,7 @@ export interface StrategyItem {
|
||||
jwksClient?: JwksClient;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
export function isOIDCToken(token: OIDCIDToken | object): token is OIDCIDToken {
|
||||
const { error } = OIDCIDTokenSchema.validate(token, {
|
||||
// OIDC ID tokens may contain many other fields we haven't seen.. We Just
|
||||
|
||||
@@ -27,6 +27,7 @@ it("validates a jwt token", async () => {
|
||||
const tokenString = await signTokenString(config, user, tenant, {}, now);
|
||||
|
||||
// Verify that the token conforms to the JWT token schema.
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
const token = jwt.decode(tokenString) as object;
|
||||
|
||||
expect(isJWTToken(token)).toBeTruthy();
|
||||
|
||||
@@ -35,6 +35,7 @@ export const JWTTokenSchema = Joi.object().keys({
|
||||
pat: Joi.boolean(),
|
||||
});
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
export function isJWTToken(token: JWTToken | object): token is JWTToken {
|
||||
const { error } = JWTTokenSchema.validate(token, {
|
||||
allowUnknown: true,
|
||||
@@ -59,6 +60,7 @@ export class JWTVerifier implements Verifier<JWTToken> {
|
||||
this.redis = redis;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
public supports(token: JWTToken | object, tenant: Tenant): token is JWTToken {
|
||||
return isJWTToken(token) && token.iss === tenant.id;
|
||||
}
|
||||
|
||||
@@ -60,6 +60,7 @@ export interface SSOToken {
|
||||
user: SSOUserProfile;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
export function isSSOToken(token: SSOToken | object): token is SSOToken {
|
||||
const { error } = SSOTokenSchema.validate(token, { allowUnknown: true });
|
||||
return isNil(error);
|
||||
@@ -237,6 +238,7 @@ export class SSOVerifier implements Verifier<SSOToken> {
|
||||
}
|
||||
|
||||
public supports(
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
token: SSOToken | object,
|
||||
tenant: Tenant,
|
||||
kid?: string
|
||||
@@ -304,7 +306,7 @@ export class SSOVerifier implements Verifier<SSOToken> {
|
||||
// succeeded! Mark the key as used last now and break out. We should do
|
||||
// this in the nextTick because it's not important to have it recorded at
|
||||
// the same time.
|
||||
updateLastUsedAtKID(this.redis, tenant.id, key.kid, now);
|
||||
void updateLastUsedAtKID(this.redis, tenant.id, key.kid, now);
|
||||
|
||||
// TODO: [CORL-754] (wyattjoh) reintroduce when we amend the front-end to display the kid
|
||||
// if (!kid) {
|
||||
|
||||
@@ -65,7 +65,7 @@ export class Limiter {
|
||||
// if this is new or has no expiry
|
||||
if (tries === 1 || expiry === -1) {
|
||||
// then expire it after the timeout
|
||||
this.redis.expire(key, this.ttl);
|
||||
void this.redis.expire(key, this.ttl);
|
||||
}
|
||||
|
||||
if (tries > this.max) {
|
||||
|
||||
@@ -108,7 +108,7 @@ const processNotificationDigesting = (
|
||||
// TODO: sort the digest template elements by the digest order.
|
||||
|
||||
// Add the email containing the digest information.
|
||||
mailerQueue.add({
|
||||
void mailerQueue.add({
|
||||
tenantID: tenant.id,
|
||||
message: {
|
||||
to: user.email!,
|
||||
|
||||
@@ -184,7 +184,7 @@ export const Comments = (ctx: GraphContext) => ({
|
||||
)
|
||||
.then((comment) => {
|
||||
// Publish that the comment was featured.
|
||||
publishCommentFeatured(ctx.broker, comment);
|
||||
void publishCommentFeatured(ctx.broker, comment);
|
||||
|
||||
// Return it to the next step.
|
||||
return comment;
|
||||
|
||||
@@ -82,7 +82,7 @@ export const Comment: GQLCommentTypeResolver<comment.Comment> = {
|
||||
|
||||
const children = await ctx.loaders.Comments.visible.loadMany(childIDs);
|
||||
return children.reduce(
|
||||
(sum: any, c: any) => (c && hasPublishedStatus(c) ? sum + 1 : sum),
|
||||
(sum: number, c: any) => (c && hasPublishedStatus(c) ? sum + 1 : sum),
|
||||
0
|
||||
);
|
||||
},
|
||||
|
||||
@@ -19,7 +19,7 @@ export const ModerationQueue: GQLModerationQueueTypeResolver<ModerationQueueInpu
|
||||
id: ({ selector, connection: { filter } }) => {
|
||||
// NOTE: (wyattjoh) when the queues change shape in the future, investigate adding more dynamicness to this id generation
|
||||
if (filter && filter.storyID) {
|
||||
return selector + "::storyID:" + filter.storyID;
|
||||
return selector + "::storyID:" + (filter.storyID as string);
|
||||
}
|
||||
|
||||
return selector;
|
||||
|
||||
@@ -16,6 +16,6 @@ export function getRequestedFields<T>(info: GraphQLResolveInfo) {
|
||||
}
|
||||
|
||||
export function reconstructTenantURLResolver<T = any>(path: string) {
|
||||
return (parent: T, args: {}, ctx: GraphContext) =>
|
||||
return (parent: T, args: unknown, ctx: GraphContext) =>
|
||||
reconstructTenantURL(ctx.config, ctx.tenant, ctx.req, path);
|
||||
}
|
||||
|
||||
@@ -210,7 +210,10 @@ export async function updateSharedCommentCounts(
|
||||
const args = flattenDeep(Object.entries(moderationQueueQueues));
|
||||
|
||||
// Add the command to the pipeline.
|
||||
pipeline.mhincrby(commentCountsModerationQueueQueuesKey(tenantID), ...args);
|
||||
void pipeline.mhincrby(
|
||||
commentCountsModerationQueueQueuesKey(tenantID),
|
||||
...args
|
||||
);
|
||||
}
|
||||
|
||||
// Execute the pipeline.
|
||||
|
||||
@@ -80,7 +80,7 @@ export default class Task<T extends TenantResource, U = any> {
|
||||
* job requests.
|
||||
*/
|
||||
public process() {
|
||||
this.queue.process(async (job: Job<T>) => {
|
||||
void this.queue.process(async (job: Job<T>) => {
|
||||
const log = this.log.child(
|
||||
{ jobID: job.id, attemptsMade: job.attemptsMade },
|
||||
true
|
||||
|
||||
@@ -133,7 +133,8 @@ function createMessageTranslator(i18n: I18n) {
|
||||
}
|
||||
|
||||
// Translate the bundle.
|
||||
await loc.translateFragment(dom.window.document);
|
||||
// TODO: don't cast to any.
|
||||
await loc.translateFragment(dom.window.document as any);
|
||||
|
||||
// Grab the rendered HTML from the dom, and juice them.
|
||||
if (!dom.window.document.documentElement) {
|
||||
|
||||
@@ -246,7 +246,7 @@ export async function createReaction(
|
||||
);
|
||||
if (action) {
|
||||
// A comment reaction was created! Publish it.
|
||||
publishCommentReactionCreated(
|
||||
void publishCommentReactionCreated(
|
||||
broker,
|
||||
comment,
|
||||
input.commentRevisionID,
|
||||
@@ -356,7 +356,12 @@ export async function createFlag(
|
||||
);
|
||||
if (action) {
|
||||
// A action was created! Publish the event.
|
||||
publishCommentFlagCreated(broker, comment, input.commentRevisionID, action);
|
||||
void publishCommentFlagCreated(
|
||||
broker,
|
||||
comment,
|
||||
input.commentRevisionID,
|
||||
action
|
||||
);
|
||||
}
|
||||
|
||||
return comment;
|
||||
|
||||
@@ -95,7 +95,7 @@ export async function findOrCreate(
|
||||
}
|
||||
|
||||
if (wasUpserted) {
|
||||
StoryCreatedCoralEvent.publish(broker, {
|
||||
void StoryCreatedCoralEvent.publish(broker, {
|
||||
storyID: story.id,
|
||||
storyURL: story.url,
|
||||
siteID: story.siteID,
|
||||
@@ -224,7 +224,7 @@ export async function create(
|
||||
story = await scrape(mongo, config, tenant.id, story.id, storyURL);
|
||||
}
|
||||
|
||||
StoryCreatedCoralEvent.publish(broker, {
|
||||
void StoryCreatedCoralEvent.publish(broker, {
|
||||
storyID: story.id,
|
||||
storyURL: story.url,
|
||||
siteID: site.id,
|
||||
|
||||
+1
-1
@@ -144,7 +144,7 @@ export default class TenantCache {
|
||||
subscriber.on("message", this.onMessage);
|
||||
|
||||
// Subscribe to tenant notifications.
|
||||
subscriber.subscribe(TENANT_CACHE_CHANNEL);
|
||||
void subscriber.subscribe(TENANT_CACHE_CHANNEL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,36 +25,43 @@ export default async function publishChanges(
|
||||
broker: CoralEventPublisherBroker,
|
||||
input: PublishChangesInput
|
||||
) {
|
||||
const promises: Promise<any>[] = [];
|
||||
|
||||
// Publish changes.
|
||||
publishModerationQueueChanges(broker, input.moderationQueue, input.after);
|
||||
promises.push(
|
||||
publishModerationQueueChanges(broker, input.moderationQueue, input.after)
|
||||
);
|
||||
|
||||
// If this was a change, and it has a "before" state for the comment, process
|
||||
// those updates too.
|
||||
if (input.before) {
|
||||
publishCommentStatusChanges(
|
||||
broker,
|
||||
input.before.status,
|
||||
input.after.status,
|
||||
input.after.id,
|
||||
input.commentRevisionID,
|
||||
input.after.storyID,
|
||||
input.moderatorID || null
|
||||
promises.push(
|
||||
publishCommentStatusChanges(
|
||||
broker,
|
||||
input.before.status,
|
||||
input.after.status,
|
||||
input.after.id,
|
||||
input.commentRevisionID,
|
||||
input.after.storyID,
|
||||
input.moderatorID || null
|
||||
)
|
||||
);
|
||||
|
||||
if (hasModeratorStatus(input.before) && hasPublishedStatus(input.after)) {
|
||||
publishCommentReleased(broker, input.after);
|
||||
promises.push(publishCommentReleased(broker, input.after));
|
||||
}
|
||||
} else {
|
||||
// This block is only hit if there is no before (if this is a new comment).
|
||||
|
||||
// If this is a reply, publish it.
|
||||
if (input.after.parentID) {
|
||||
publishCommentReplyCreated(broker, input.after);
|
||||
promises.push(publishCommentReplyCreated(broker, input.after));
|
||||
}
|
||||
|
||||
// If this comment is visible (and not a reply), publish it.
|
||||
if (!input.after.parentID && hasPublishedStatus(input.after)) {
|
||||
publishCommentCreated(broker, input.after);
|
||||
promises.push(publishCommentCreated(broker, input.after));
|
||||
}
|
||||
}
|
||||
await Promise.all(promises);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user