Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: RestApiClient as Package #25469

Merged
merged 52 commits into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
f51ed91
wip
ggazzo May 6, 2022
1359aed
Merge remote-tracking branch 'origin/develop' into chore/api-client
ggazzo May 9, 2022
49d2a4c
WIP
ggazzo May 10, 2022
d4a5881
RestClient.get fallback
ggazzo May 11, 2022
ad17d15
..
ggazzo May 13, 2022
247d8aa
Merge remote-tracking branch 'origin/develop' into chore/api-client
ggazzo May 13, 2022
19a01e2
migrate useEndpoint
ggazzo May 13, 2022
25b1042
add v1 useendpoint
ggazzo May 16, 2022
c7216ba
omg
ggazzo May 16, 2022
0bc77c2
Merge remote-tracking branch 'origin/develop' into chore/api-client
ggazzo May 17, 2022
0e79037
..
ggazzo May 17, 2022
b3e2188
..
ggazzo May 17, 2022
64820f6
Merge remote-tracking branch 'origin/develop' into chore/api-client
ggazzo May 17, 2022
cf411eb
..
ggazzo May 17, 2022
5585356
..
ggazzo May 17, 2022
6f9909e
..
ggazzo May 17, 2022
9cccfd6
Merge remote-tracking branch 'origin/develop' into chore/api-client
ggazzo May 18, 2022
eb952fb
:eyes:
ggazzo May 18, 2022
54df87e
working
ggazzo May 18, 2022
427d3a5
lint
ggazzo May 18, 2022
cd91c9b
fix type
ggazzo May 18, 2022
9c367d0
Fix middleware issue
ggazzo May 18, 2022
e07a5a0
Merge remote-tracking branch 'origin/develop' into chore/api-client
ggazzo May 18, 2022
8f8f066
fix ci
ggazzo May 18, 2022
5e98801
Fix creation
ggazzo May 18, 2022
4cde122
f
ggazzo May 18, 2022
0797578
:)
ggazzo May 18, 2022
8812d1b
Merge remote-tracking branch 'origin/develop' into chore/api-client
ggazzo May 18, 2022
09a77b6
..
ggazzo May 18, 2022
01431af
..
ggazzo May 18, 2022
7f664a4
..
ggazzo May 18, 2022
015bfcc
fix File upload
ggazzo May 19, 2022
80c0198
ZZZzzz
ggazzo May 19, 2022
114ba92
Merge remote-tracking branch 'origin/develop' into chore/api-client
ggazzo May 19, 2022
fd99e06
LGTM
ggazzo May 19, 2022
548fab5
fix review
ggazzo May 20, 2022
aa29d86
Remove unused ESLint overrides
tassoevan May 20, 2022
60f09ed
Remove dangling console.log calls
tassoevan May 20, 2022
fbd514d
Fixing some unprefixed endpoint paths
tassoevan May 20, 2022
861f5bb
Move some Livechat query strings to GET parameters
tassoevan May 20, 2022
73a4fd2
Move some query strings to GET parameters
tassoevan May 20, 2022
bb7bd83
Remove dangling console.log calls
tassoevan May 20, 2022
ae34c61
Move some query strings to GET parameters
tassoevan May 20, 2022
e3cf242
Rollback uneeded `export`
tassoevan May 20, 2022
13560d2
Merge remote-tracking branch 'origin/develop' into chore/api-client
ggazzo May 24, 2022
8086a7f
warn message
ggazzo May 24, 2022
5865985
increase mem for tsc
ggazzo May 25, 2022
7124d6a
ops
ggazzo May 25, 2022
a2b97d4
test
ggazzo May 25, 2022
58fd89a
Merge remote-tracking branch 'origin/develop' into chore/api-client
ggazzo May 28, 2022
4e11d16
Merge remote-tracking branch 'origin/develop' into chore/api-client
ggazzo Jun 8, 2022
de97fc5
WIP
ggazzo Jun 8, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion apps/meteor/app/api/server/lib/getUploadFormData.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export const getUploadFormData = async ({ request }) =>
bb.on('file', (fieldname, file, { filename, encoding, mimeType: mimetype }) => {
const fileData = [];

console.log(file);
file.on('data', (data) => fileData.push(data));

file.on('end', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,29 @@ API.v1.addRoute(
'emoji-custom.list',
{ authRequired: true },
{
get() {
async get() {
const { query } = this.parseJsonQuery();
const { updatedSince } = this.queryParams;
let updatedSinceDate;
if (updatedSince) {
const updatedSinceDate = new Date(updatedSince);
if (isNaN(Date.parse(updatedSince))) {
throw new Meteor.Error('error-roomId-param-invalid', 'The "updatedSince" query parameter must be a valid date.');
} else {
updatedSinceDate = new Date(updatedSince);
}
const [update, remove] = await Promise.all([
EmojiCustom.find({ ...query, _updatedAt: { $gt: updatedSinceDate } }).toArray(),
EmojiCustom.trashFindDeletedAfter(updatedSinceDate).toArray(),
]);
return API.v1.success({
emojis: {
update: Promise.await(EmojiCustom.find({ ...query, _updatedAt: { $gt: updatedSinceDate } }).toArray()),
remove: Promise.await(EmojiCustom.trashFindDeletedAfter(updatedSinceDate).toArray()),
update,
remove,
},
});
}

return API.v1.success({
emojis: {
update: Promise.await(EmojiCustom.find(query).toArray()),
update: await EmojiCustom.find(query).toArray(),
remove: [],
},
});
Expand All @@ -42,21 +44,19 @@ API.v1.addRoute(
'emoji-custom.all',
{ authRequired: true },
{
get() {
async get() {
const { offset, count } = this.getPaginationItems();
const { sort, query } = this.parseJsonQuery();

return API.v1.success(
Promise.await(
findEmojisCustom({
query,
pagination: {
offset,
count,
sort,
},
}),
),
await findEmojisCustom({
query,
pagination: {
offset,
count,
sort,
},
}),
);
},
},
Expand All @@ -66,18 +66,16 @@ API.v1.addRoute(
'emoji-custom.create',
{ authRequired: true },
{
post() {
const { emoji, ...fields } = Promise.await(
getUploadFormData({
request: this.request,
}),
);
async post() {
const { emoji, ...fields } = await getUploadFormData({
request: this.request,
});

if (!emoji) {
throw new Meteor.Error('invalid-field');
}

const isUploadable = Promise.await(Media.isImage(emoji.fileBuffer));
const isUploadable = await Media.isImage(emoji.fileBuffer);
if (!isUploadable) {
throw new Meteor.Error('emoji-is-not-image', "Emoji file provided cannot be uploaded since it's not an image");
}
Expand All @@ -88,10 +86,10 @@ API.v1.addRoute(
fields.newFile = true;
fields.aliases = fields.aliases || '';

Meteor.runAsUser(this.userId, () => {
Meteor.call('insertOrUpdateEmoji', fields);
Meteor.call('uploadEmojiCustom', emoji.fileBuffer, emoji.mimetype, fields);
});
Meteor.call('insertOrUpdateEmoji', fields);
Meteor.call('uploadEmojiCustom', emoji.fileBuffer, emoji.mimetype, fields);

return API.v1.success();
},
},
);
Expand All @@ -100,12 +98,10 @@ API.v1.addRoute(
'emoji-custom.update',
{ authRequired: true },
{
post() {
const { emoji, ...fields } = Promise.await(
getUploadFormData({
request: this.request,
}),
);
async post() {
const { emoji, ...fields } = await getUploadFormData({
request: this.request,
});

if (!fields._id) {
throw new Meteor.Error('The required "_id" query param is missing.');
Expand Down Expand Up @@ -133,12 +129,11 @@ API.v1.addRoute(
fields.extension = emojiToUpdate.extension;
}

Meteor.runAsUser(this.userId, () => {
Meteor.call('insertOrUpdateEmoji', fields);
if (fields.newFile) {
Meteor.call('uploadEmojiCustom', emoji.fileBuffer, emoji.mimetype, fields);
}
});
Meteor.call('insertOrUpdateEmoji', fields);
if (fields.newFile) {
Meteor.call('uploadEmojiCustom', emoji.fileBuffer, emoji.mimetype, fields);
}
return API.v1.success();
},
},
);
Expand All @@ -153,7 +148,7 @@ API.v1.addRoute(
return API.v1.failure('The "emojiId" params is required!');
}

Meteor.runAsUser(this.userId, () => Meteor.call('deleteEmojiCustom', emojiId));
Meteor.call('deleteEmojiCustom', emojiId);

return API.v1.success();
},
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/api/server/v1/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ API.v1.addRoute(
},
post: {
twoFactorRequired: true,
async action(): Promise<ResultFor<'POST', 'settings/:_id'>> {
async action(): Promise<ResultFor<'POST', '/v1/settings/:_id'>> {
if (!hasPermission(this.userId, 'edit-privileged-setting')) {
return API.v1.unauthorized();
}
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/apps/client/RealAppsEngineUIHost.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class RealAppsEngineUIHost extends AppsEngineUIHost {

let cachedMembers = [];
try {
const { members } = await APIClient.get('v1/groups.members', { roomId: id });
const { members } = await APIClient.get('/v1/groups.members', { roomId: id });

cachedMembers = members.map(({ _id, username }) => ({
id: _id,
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/apps/client/communication/websockets.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class AppWebsocketReceiver extends Emitter {
}

onCommandAddedOrUpdated = (command) => {
APIClient.v1.get('commands.get', { command }).then((result) => {
APIClient.get('/v1/commands.get', { command }).then((result) => {
slashCommands.commands[command] = result.command;
});
};
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/apps/client/gameCenter/gameCenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { handleError } from '../../../../client/lib/utils/handleError';

const getExternalComponents = async (instance) => {
try {
const { externalComponents } = await APIClient.get('apps/externalComponents');
const { externalComponents } = await APIClient.get('/apps/externalComponents');
instance.games.set(externalComponents);
} catch (e) {
handleError(e);
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/app/apps/client/gameCenter/gameContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Template.GameContainer.events({
Template.GameContainer.onCreated(async () => {
const externalComponent = await getExternalComponent();

APIClient.post('apps/externalComponentEvent', {
APIClient.post('/apps/externalComponentEvent', {
event: 'IPostExternalComponentOpened',
externalComponent,
});
Expand All @@ -71,7 +71,7 @@ Template.GameContainer.onCreated(async () => {
Template.GameContainer.onDestroyed(async () => {
const externalComponent = await getExternalComponent();

APIClient.post('apps/externalComponentEvent', {
APIClient.post('/apps/externalComponentEvent', {
event: 'IPostExternalComponentClosed',
externalComponent,
});
Expand Down
40 changes: 20 additions & 20 deletions apps/meteor/app/apps/client/orchestrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { dispatchToastMessage } from '../../../client/lib/toast';
import { hasAtLeastOnePermission } from '../../authorization';
import { settings } from '../../settings/client';
import { CachedCollectionManager } from '../../ui-cached-collection';
import { APIClient } from '../../utils';
import { APIClient } from '../../utils/client';
import { AppWebsocketReceiver } from './communication';
import { handleI18nResources } from './i18n';
import { RealAppsEngineUIHost } from './RealAppsEngineUIHost';
Expand Down Expand Up @@ -63,12 +63,12 @@ class AppClientOrchestrator {
isEnabled = () => this.deferredIsEnabled;

getApps = async () => {
const { apps } = await APIClient.get('apps');
const { apps } = await APIClient.get('/apps');
return apps;
};

getAppsFromMarketplace = async () => {
const appsOverviews = await APIClient.get('apps', { marketplace: 'true' });
const appsOverviews = await APIClient.get('/apps', { marketplace: 'true' });
return appsOverviews.map(({ latest, price, pricingPlans, purchaseType, isEnterpriseOnly, modifiedAt }) => ({
...latest,
price,
Expand All @@ -80,30 +80,30 @@ class AppClientOrchestrator {
};

getAppsOnBundle = async (bundleId) => {
const { apps } = await APIClient.get(`apps/bundles/${bundleId}/apps`);
const { apps } = await APIClient.get(`/apps/bundles/${bundleId}/apps`);
return apps;
};

getAppsLanguages = async () => {
const { apps } = await APIClient.get('apps/languages');
const { apps } = await APIClient.get('/apps/languages');
return apps;
};

getApp = async (appId) => {
const { app } = await APIClient.get(`apps/${appId}`);
const { app } = await APIClient.get(`/apps/${appId}`);
return app;
};

getAppFromMarketplace = async (appId, version) => {
const { app } = await APIClient.get(`apps/${appId}`, {
const { app } = await APIClient.get(`/apps/${appId}`, {
marketplace: 'true',
version,
});
return app;
};

getLatestAppFromMarketplace = async (appId, version) => {
const { app } = await APIClient.get(`apps/${appId}`, {
const { app } = await APIClient.get(`/apps/${appId}`, {
marketplace: 'true',
update: 'true',
appVersion: version,
Expand All @@ -112,27 +112,27 @@ class AppClientOrchestrator {
};

getAppSettings = async (appId) => {
const { settings } = await APIClient.get(`apps/${appId}/settings`);
const { settings } = await APIClient.get(`/apps/${appId}/settings`);
return settings;
};

setAppSettings = async (appId, settings) => {
const { updated } = await APIClient.post(`apps/${appId}/settings`, undefined, { settings });
const { updated } = await APIClient.post(`/apps/${appId}/settings`, undefined, { settings });
return updated;
};

getAppApis = async (appId) => {
const { apis } = await APIClient.get(`apps/${appId}/apis`);
const { apis } = await APIClient.get(`/apps/${appId}/apis`);
return apis;
};

getAppLanguages = async (appId) => {
const { languages } = await APIClient.get(`apps/${appId}/languages`);
const { languages } = await APIClient.get(`/apps/${appId}/languages`);
return languages;
};

installApp = async (appId, version, permissionsGranted) => {
const { app } = await APIClient.post('apps/', {
const { app } = await APIClient.post('/apps/', {
appId,
marketplace: true,
version,
Expand All @@ -142,7 +142,7 @@ class AppClientOrchestrator {
};

updateApp = async (appId, version, permissionsGranted) => {
const { app } = await APIClient.post(`apps/${appId}`, {
const { app } = await APIClient.post(`/apps/${appId}`, {
appId,
marketplace: true,
version,
Expand All @@ -151,31 +151,31 @@ class AppClientOrchestrator {
return app;
};

uninstallApp = (appId) => APIClient.delete(`apps/${appId}`);
uninstallApp = (appId) => APIClient.delete(`/apps/${appId}`);

syncApp = (appId) => APIClient.post(`apps/${appId}/sync`);
syncApp = (appId) => APIClient.post(`/apps/${appId}/sync`);

setAppStatus = async (appId, status) => {
const { status: effectiveStatus } = await APIClient.post(`apps/${appId}/status`, { status });
const { status: effectiveStatus } = await APIClient.post(`/apps/${appId}/status`, { status });
return effectiveStatus;
};

screenshots = (appId) => APIClient.get(`apps/${appId}/screenshots`);
screenshots = (appId) => APIClient.get(`/apps/${appId}/screenshots`);

enableApp = (appId) => this.setAppStatus(appId, 'manually_enabled');

disableApp = (appId) => this.setAppStatus(appId, 'manually_disabled');

buildExternalUrl = (appId, purchaseType = 'buy', details = false) =>
APIClient.get('apps', {
APIClient.get('/apps', {
buildExternalUrl: 'true',
appId,
purchaseType,
details,
});

getCategories = async () => {
const categories = await APIClient.get('apps', { categories: 'true' });
const categories = await APIClient.get('/apps', { categories: 'true' });
return categories;
};

Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/authorization/client/startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { rolesStreamer } from './lib/streamer';

Meteor.startup(() => {
CachedCollectionManager.onLogin(async () => {
const { roles } = await APIClient.v1.get('roles.list');
const { roles } = await APIClient.get('/v1/roles.list');
// if a role is checked before this collection is populated, it will return undefined
Roles._collection._docs._map = new Map(roles.map((record) => [Roles._collection._docs._idStringify(record._id), record]));
Object.values(Roles._collection.queries).forEach((query) => Roles._collection._recomputeResults(query));
Expand Down
10 changes: 5 additions & 5 deletions apps/meteor/app/authorization/server/methods/saveRole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ Meteor.methods({
methodDeprecationLogger.warn('authorization:saveRole will be deprecated in future versions of Rocket.Chat');
const userId = Meteor.userId();

if (!userId || !hasPermission(userId, 'access-permissions')) {
throw new Meteor.Error('error-action-not-allowed', 'Accessing permissions is not allowed', {
if (!isRoleCreateProps(roleData)) {
throw new Meteor.Error('error-invalid-role-properties', 'The role properties are invalid.', {
method: 'authorization:saveRole',
action: 'Accessing_permissions',
});
}

if (!isRoleCreateProps(roleData)) {
throw new Meteor.Error('error-invalid-role-properties', 'The role properties are invalid.', {
if (!userId || !hasPermission(userId, 'access-permissions')) {
throw new Meteor.Error('error-action-not-allowed', 'Accessing permissions is not allowed', {
method: 'authorization:saveRole',
action: 'Accessing_permissions',
});
}

Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/emoji-custom/client/lib/emojiCustom.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ Meteor.startup(() =>
try {
const {
emojis: { update: emojis },
} = await APIClient.v1.get('emoji-custom.list');
} = await APIClient.get('/v1/emoji-custom.list');

emoji.packages.emojiCustom.emojisByCategory = { rocket: [] };
for (const currentEmoji of emojis) {
Expand Down
Loading