Skip to content

Commit

Permalink
chore: update meteor types (RocketChat#28884)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcosSpessatto committed Apr 13, 2023
1 parent 1576ace commit 0b4df50
Show file tree
Hide file tree
Showing 20 changed files with 54 additions and 52 deletions.
2 changes: 1 addition & 1 deletion apps/meteor/app/2fa/server/loginHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const isCredentialWithError = (credential: any): credential is { error: Error }
};

Accounts.registerLoginHandler('totp', function (options) {
if (!options.totp || !options.totp.code) {
if (!options.totp?.code) {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/app/crowd/server/crowd.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export class CROWD {
};

if (crowdUser.password) {
Accounts.setPassword(id, crowdUser.password, {
await Accounts.setPasswordAsync(id, crowdUser.password, {
logout: false,
});

Expand Down Expand Up @@ -262,7 +262,7 @@ export class CROWD {

// Attempt to create the new user
try {
crowdUser._id = Accounts.createUser(crowdUser);
crowdUser._id = await Accounts.createUserAsync(crowdUser);

// sync the user data
await this.syncDataToUser(crowdUser, crowdUser._id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,15 +282,15 @@ export class ImportDataConverter {
async insertUser(userData: IImportUser): Promise<IUser> {
const password = `${Date.now()}${userData.name || ''}${userData.emails.length ? userData.emails[0].toUpperCase() : ''}`;
const userId = userData.emails.length
? Accounts.createUser({
? await Accounts.createUserAsync({
email: userData.emails[0],
password,
})
: Accounts.createUser({
: await Accounts.createUserAsync({
username: userData.username,
password,
joinDefaultChannelsSilenced: true,
});
} as any);

const user = await Users.findOneById(userId, {});
if (!user) {
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/app/lib/server/functions/saveUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ const saveNewUser = async function (userData, sendPassword) {
createUser.email = userData.email;
}

const _id = Accounts.createUser(createUser);
const _id = await Accounts.createUserAsync(createUser);

const updateUser = {
$set: {
Expand Down Expand Up @@ -386,7 +386,7 @@ export const saveUser = async function (userId, userData) {
(await hasPermissionAsync(userId, 'edit-other-user-password')) &&
passwordPolicy.validate(userData.password)
) {
Accounts.setPassword(userData._id, userData.password.trim());
await Accounts.setPasswordAsync(userData._id, userData.password.trim());
} else {
sendPassword = false;
}
Expand Down
5 changes: 2 additions & 3 deletions apps/meteor/app/mailer/server/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,13 @@ export const sendNoWrap = async ({
html = undefined;
}

// TODO change to await once Email.send is converted to Email.sendAsync
void Settings.incrementValueById('Triggered_Emails_Count');
await Settings.incrementValueById('Triggered_Emails_Count');

const email = { to, from, replyTo, subject, html, text, headers };

const eventResult = await Apps.triggerEvent('IPreEmailSent', { email });

Meteor.defer(() => Email.send(eventResult || email));
Meteor.defer(() => Email.sendAsync(eventResult || email));
};

export const send = async ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type { ILogoutRequestValidateCallback, ILogoutResponseValidateCallback, I
export class SAMLServiceProvider {
serviceProviderOptions: IServiceProviderOptions;

syncRequestToUrl: (request: string, operation: string) => void;
syncRequestToUrl: Function;

constructor(serviceProviderOptions: IServiceProviderOptions) {
if (!serviceProviderOptions) {
Expand All @@ -29,7 +29,9 @@ export class SAMLServiceProvider {

this.serviceProviderOptions = serviceProviderOptions;

this.syncRequestToUrl = Meteor.wrapAsync(this.requestToUrl, this);
this.syncRequestToUrl = Meteor.wrapAsync<
(request: string, operation: string, callback: (err: string | object | null, url?: string | undefined) => void) => void
>(this.requestToUrl, this);
}

private signRequest(xml: string): string {
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/slackbridge/server/RocketAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ export default class RocketAdapter {
newUser.joinDefaultChannels = false;
}

rocketUserData.rocketId = Accounts.createUser(newUser);
rocketUserData.rocketId = await Accounts.createUserAsync(newUser);
const userUpdate = {
utcOffset: rocketUserData.tz_offset / 3600, // Slack's is -18000 which translates to Rocket.Chat's after dividing by 3600,
roles: isBot ? ['bot'] : ['user'],
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/client/providers/UserProvider/UserProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const UserProvider = ({ children }: UserProviderProps): ReactElement => {
resolve(undefined);
}),
),
loginWithPassword: (user: string | object, password: string): Promise<void> =>
loginWithPassword: (user: string | { username: string } | { email: string } | { id: string }, password: string): Promise<void> =>
new Promise((resolve, reject) => {
Meteor[loginMethod](user, password, (error: Error | Meteor.Error | Meteor.TypedError | undefined) => {
if (error) {
Expand Down
4 changes: 3 additions & 1 deletion apps/meteor/definition/externals/meteor/accounts-base.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ declare module 'meteor/accounts-base' {

function _insertLoginToken(userId: string, token: { token: string; when: Date }): void;

function _runLoginHandlers<T>(methodInvocation: T, loginRequest: Record<string, any>): Record<string, any> | undefined;
function _runLoginHandlers<T>(methodInvocation: T, loginRequest: Record<string, any>): LoginMethodResult | undefined;

function registerLoginHandler(name: string, handler: (options: any) => undefined | Object): void;

function _storedLoginToken(): unknown;

Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
"@types/lodash.get": "^4.4.7",
"@types/mailparser": "^3.4.0",
"@types/marked": "^4.0.8",
"@types/meteor": "2.8.1",
"@types/meteor": "^2.9.2",
"@types/meteor-collection-hooks": "^0.8.6",
"@types/mkdirp": "^1.0.2",
"@types/mocha": "^8.2.3",
Expand Down
10 changes: 5 additions & 5 deletions apps/meteor/packages/rocketchat-mongo-config/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,18 @@ process.env.HTTP_FORWARDED_COUNT = process.env.HTTP_FORWARDED_COUNT || '1';

// Send emails to a "fake" stream instead of print them in console in case MAIL_URL or SMTP is not configured
if (process.env.NODE_ENV !== 'development') {
const { send } = Email;
const { sendAsync } = Email;
const stream = new PassThrough();
stream.on('data', () => {});
stream.on('end', () => {});
Email.send = function _send(options) {
return send.call(this, { stream, ...options });
Email.sendAsync = function _sendAsync(options) {
return sendAsync.call(this, { stream, ...options });
};
}

// Just print to logs if in TEST_MODE due to a bug in Meteor 2.5: TypeError: Cannot read property '_syncSendMail' of null
if (process.env.TEST_MODE === 'true') {
Email.send = function _send(options) {
console.log('Email.send', options);
Email.sendAsync = function _sendAsync(options) {
console.log('Email.sendAsync', options);
};
}
2 changes: 1 addition & 1 deletion apps/meteor/server/lib/ldap/Manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export class LDAPManager {
): Promise<void> {
logger.debug('running onLDAPLogin');
if (settings.get<boolean>('LDAP_Login_Fallback') && typeof password === 'string' && password.trim() !== '') {
Accounts.setPassword(user._id, password, { logout: false });
await Accounts.setPasswordAsync(user._id, password, { logout: false });
}

await this.syncUserAvatar(user, ldapUser);
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/server/methods/registerUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ Meteor.methods<ServerMethods>({
const importedUser = await Users.findOneByEmailAddress(formData.email);

if (importedUser?.importIds?.length && !importedUser.lastLogin) {
Accounts.setPassword(importedUser._id, userData.password);
await Accounts.setPasswordAsync(importedUser._id, userData.password);
userId = importedUser._id;
} else {
userId = Accounts.createUser(userData);
userId = await Accounts.createUserAsync(userData);
}
} catch (e) {
if (e instanceof Meteor.Error) {
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/server/methods/saveUserProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ async function saveUserProfile(

passwordPolicy.validate(settings.newPassword);

Accounts.setPassword(this.userId, settings.newPassword, {
await Accounts.setPasswordAsync(this.userId, settings.newPassword, {
logout: false,
});

Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/server/methods/setUserPassword.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Meteor.methods<ServerMethods>({

passwordPolicy.validate(password);

Accounts.setPassword(userId, password, {
await Accounts.setPasswordAsync(userId, password, {
logout: false,
});

Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/server/startup/initialData.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Meteor.startup(async function () {

const id = await Users.create(adminUser);

Accounts.setPassword(id, process.env.ADMIN_PASS);
await Accounts.setPasswordAsync(id, process.env.ADMIN_PASS);

await addUserRolesAsync(id, ['admin']);
} else {
Expand Down Expand Up @@ -198,7 +198,7 @@ Meteor.startup(async function () {

await Users.create(adminUser);

Accounts.setPassword(adminUser._id, adminUser._id);
await Accounts.setPasswordAsync(adminUser._id, adminUser._id);

await addUserRolesAsync(adminUser._id, ['admin']);

Expand Down
2 changes: 1 addition & 1 deletion ee/apps/ddp-streamer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@rocket.chat/eslint-config": "workspace:^",
"@types/ejson": "^2.2.0",
"@types/eslint": "^8.4.10",
"@types/meteor": "2.7.1",
"@types/meteor": "^2.9.2",
"@types/node": "^14.18.21",
"@types/polka": "^0.5.4",
"@types/sharp": "^0.30.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/ui-contexts/src/UserContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export type UserContextValue = {
options?: FindOptions,
) => [subscribe: (onStoreChange: () => void) => () => void, getSnapshot: () => SubscriptionWithRoom[]];

loginWithPassword: (user: string | object, password: string) => Promise<void>;
loginWithPassword: (user: string | { username: string } | { email: string } | { id: string }, password: string) => Promise<void>;
loginWithToken: (user: string) => Promise<void>;
logout: () => Promise<void>;

Expand Down
6 changes: 4 additions & 2 deletions packages/ui-contexts/src/hooks/useLoginWithPassword.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ import { useContext } from 'react';

import { UserContext } from '../UserContext';

export const useLoginWithPassword = (): ((user: string | object, password: string) => Promise<void>) =>
useContext(UserContext).loginWithPassword;
export const useLoginWithPassword = (): ((
user: string | { username: string } | { email: string } | { id: string },
password: string,
) => Promise<void>) => useContext(UserContext).loginWithPassword;
35 changes: 16 additions & 19 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6677,7 +6677,7 @@ __metadata:
"@rocket.chat/string-helpers": next
"@types/ejson": ^2.2.0
"@types/eslint": ^8.4.10
"@types/meteor": 2.7.1
"@types/meteor": ^2.9.2
"@types/node": ^14.18.21
"@types/polka": ^0.5.4
"@types/sharp": ^0.30.4
Expand Down Expand Up @@ -7291,7 +7291,7 @@ __metadata:
"@types/lodash.get": ^4.4.7
"@types/mailparser": ^3.4.0
"@types/marked": ^4.0.8
"@types/meteor": 2.8.1
"@types/meteor": ^2.9.2
"@types/meteor-collection-hooks": ^0.8.6
"@types/mkdirp": ^1.0.2
"@types/mocha": ^8.2.3
Expand Down Expand Up @@ -11979,29 +11979,17 @@ __metadata:
languageName: node
linkType: hard

"@types/meteor@npm:2.7.1":
version: 2.7.1
resolution: "@types/meteor@npm:2.7.1"
dependencies:
"@types/connect": "*"
"@types/jquery": "*"
"@types/react": "*"
"@types/underscore": "*"
mongodb: ^4.3.1
checksum: a363cbcdec41e233997f3e05fd616e9ba1840bf7648b265144102769c0afdbeb614bf6d17e969343ed70883396a341ea876149d3f23fd2ea60a07c99f067f91e
languageName: node
linkType: hard

"@types/meteor@npm:2.8.1":
version: 2.8.1
resolution: "@types/meteor@npm:2.8.1"
"@types/meteor@npm:^2.9.2":
version: 2.9.2
resolution: "@types/meteor@npm:2.9.2"
dependencies:
"@types/connect": "*"
"@types/jquery": "*"
"@types/nodemailer": "*"
"@types/react": "*"
"@types/underscore": "*"
mongodb: ^4.3.1
checksum: 00d29816a05db7dac92f27e22ced92f4db36b56a5778479f3c3aa4b00165944536ce1c37600f9b61c497dc85a77a91e1244f1ed346daea383af1c54f86013d72
checksum: 6395578e5d5f139aad8dfd0f70cb489dd70984b78ed2ab791bfabc59c70f94196cdb3cfc40659da0498ae1962f135782067579e5c320341c9a1a331553329f56
languageName: node
linkType: hard

Expand Down Expand Up @@ -12108,6 +12096,15 @@ __metadata:
languageName: node
linkType: hard

"@types/nodemailer@npm:*":
version: 6.4.7
resolution: "@types/nodemailer@npm:6.4.7"
dependencies:
"@types/node": "*"
checksum: dc2a33a89135e04a5bea4921e8645e8453b90e3c3b05f0646f05071c5951ab697ea49ea1e503a690f04cb0a6abfc54967325c5a4036356793cfbb64ba64fb141
languageName: node
linkType: hard

"@types/nodemailer@npm:^6.4.4":
version: 6.4.4
resolution: "@types/nodemailer@npm:6.4.4"
Expand Down

0 comments on commit 0b4df50

Please sign in to comment.