* fix: handle NSMutableData * feat: integrate react-native-network-client * fix: typos * fix: semicolon * fix: rename to urlVersion * fix: add returnDataOnly arg * fix: configure network client * fix: headers * fix: handling of serverVersion * fix: rename requests to actions * fix: action imports * fix: no need to stringify body * fix: sso flow * fix: address PR feedback * fix: invalidate client on logout * fix: address PR feedback take 2 * fix: address PR feedback take 3 * fix: tsc issues * fix: get csrf token during client creation * fix: linter * fix: invalidate client onLogout * fix: event emitter * fix: unit tests * fix: apply linter fixes * fix lint * Modify actions to add / update database values * Rename clien4.d.ts to client.d.ts * fix empty & missing translations * cleanup api client * Cleanup init & squash some TODO's * Emit certificate errors in NetworkManager * cleanup user actions * Fix NetworkManager invalidate client * Invalidate client when server screen appears * Update kotlin to 1.4.30 required by network-client * patch react-native-keychain to remove cached credential * update react-native-network-client * Use app.db instead of default.db in native code * fix use of rnnc on Android * Init PushNotifications * No need to reset serverVersion on logout * fix logout action * fix deleteServerDatabase * fix schedule expired session notification * use safeParseJSON for db json fields * unsubscribe when database component unmounts * cleanup init * session type * pass launchprops to entire login flow * Properly remove third party cookies after SSO login * recreate network client if sso with redirect fails * add missing launch props from server screen * use query prefix for database queries * Add temporary logout function to channel screen Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
96 lines
2.7 KiB
TypeScript
96 lines
2.7 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {buildQueryString} from '@utils/helpers';
|
|
|
|
import ClientError from './error';
|
|
|
|
export interface ClientGeneralMix {
|
|
getOpenGraphMetadata: (url: string) => Promise<any>;
|
|
ping: () => Promise<any>;
|
|
logClientError: (message: string, level?: string) => Promise<any>;
|
|
getClientConfigOld: () => Promise<ClientConfig>;
|
|
getClientLicenseOld: () => Promise<ClientLicense>;
|
|
getTimezones: () => Promise<string[]>;
|
|
getDataRetentionPolicy: () => Promise<any>;
|
|
getRolesByNames: (rolesNames: string[]) => Promise<Role[]>;
|
|
getRedirectLocation: (urlParam: string) => Promise<Record<string, string>>;
|
|
}
|
|
|
|
const ClientGeneral = (superclass: any) => class extends superclass {
|
|
getOpenGraphMetadata = async (url: string) => {
|
|
return this.doFetch(
|
|
`${this.urlVersion}/opengraph`,
|
|
{method: 'post', body: {url}},
|
|
);
|
|
};
|
|
|
|
ping = async () => {
|
|
return this.doFetch(
|
|
`${this.urlVersion}/system/ping?time=${Date.now()}`,
|
|
{method: 'get'},
|
|
false,
|
|
);
|
|
};
|
|
|
|
logClientError = async (message: string, level = 'ERROR') => {
|
|
const url = `${this.urlVersion}/logs`;
|
|
|
|
if (!this.enableLogging) {
|
|
throw new ClientError(this.client.baseUrl, {
|
|
message: 'Logging disabled.',
|
|
url,
|
|
});
|
|
}
|
|
|
|
return this.doFetch(
|
|
url,
|
|
{method: 'post', body: {message, level}},
|
|
);
|
|
};
|
|
|
|
getClientConfigOld = async () => {
|
|
return this.doFetch(
|
|
`${this.urlVersion}/config/client?format=old`,
|
|
{method: 'get'},
|
|
);
|
|
};
|
|
|
|
getClientLicenseOld = async () => {
|
|
return this.doFetch(
|
|
`${this.urlVersion}/license/client?format=old`,
|
|
{method: 'get'},
|
|
);
|
|
};
|
|
|
|
getTimezones = async () => {
|
|
return this.doFetch(
|
|
`${this.getTimezonesRoute()}`,
|
|
{method: 'get'},
|
|
);
|
|
};
|
|
|
|
getDataRetentionPolicy = () => {
|
|
return this.doFetch(
|
|
`${this.getDataRetentionRoute()}/policy`,
|
|
{method: 'get'},
|
|
);
|
|
};
|
|
|
|
getRolesByNames = async (rolesNames: string[]) => {
|
|
return this.doFetch(
|
|
`${this.getRolesRoute()}/names`,
|
|
{method: 'post', body: rolesNames},
|
|
);
|
|
};
|
|
|
|
getRedirectLocation = async (urlParam: string) => {
|
|
if (!urlParam.length) {
|
|
return Promise.resolve();
|
|
}
|
|
const url = `${this.getRedirectLocationRoute()}${buildQueryString({url: urlParam})}`;
|
|
return this.doFetch(url, {method: 'get'});
|
|
};
|
|
};
|
|
|
|
export default ClientGeneral;
|