Skip to content

Commit

Permalink
Merge pull request #4315 from beyondessential/release-2023-04
Browse files Browse the repository at this point in the history
Release 2023 04
  • Loading branch information
chris-pollard authored Jan 23, 2023
2 parents 1cba4f8 + 3f5cbdc commit 222b92a
Show file tree
Hide file tree
Showing 62 changed files with 4,332 additions and 375 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const convertSearchTermToFilter = (unprocessedFilterObject = {}) => {

filterObject[key] = {
comparator: `ilike`,
comparisonValue: `%${value}%`,
comparisonValue: `${value}%`,
castAs: 'text',
};
});
Expand Down
2 changes: 2 additions & 0 deletions packages/api-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
"directory": "packages/api-client"
},
"dependencies": {
"@tupaia/tsutils": "1.0.0",
"lodash.pick": "^4.4.0",
"node-fetch": "^1.7.3",
"qs": "^6.10.1"
}
Expand Down
32 changes: 32 additions & 0 deletions packages/api-client/src/MockTupaiaApiClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Tupaia
* Copyright (c) 2017 - 2022 Beyond Essential Systems Pty Ltd
*/

import {
AuthApiInterface,
CentralApiInterface,
EntityApiInterface,
ReportApiInterface,
} from './connections';

import { MockAuthApi, MockCentralApi, MockEntityApi, MockReportApi } from './connections/mocks';

export class MockTupaiaApiClient {
public readonly entity: EntityApiInterface;
public readonly central: CentralApiInterface;
public readonly auth: AuthApiInterface;
public readonly report: ReportApiInterface;

public constructor({
auth = new MockAuthApi(),
central = new MockCentralApi(),
entity = new MockEntityApi(),
report = new MockReportApi(),
}) {
this.auth = auth;
this.central = central;
this.entity = entity;
this.report = report;
}
}
20 changes: 15 additions & 5 deletions packages/api-client/src/TupaiaApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,24 @@
*/

import { AuthHandler } from './types';
import { ApiConnection, AuthApi, EntityApi, CentralApi, ReportApi } from './connections';
import {
ApiConnection,
AuthApi,
EntityApi,
CentralApi,
ReportApi,
EntityApiInterface,
CentralApiInterface,
AuthApiInterface,
ReportApiInterface,
} from './connections';
import { PRODUCTION_BASE_URLS, ServiceBaseUrlSet } from './constants';

export class TupaiaApiClient {
public readonly entity: EntityApi;
public readonly central: CentralApi;
public readonly auth: AuthApi;
public readonly report: ReportApi;
public readonly entity: EntityApiInterface;
public readonly central: CentralApiInterface;
public readonly auth: AuthApiInterface;
public readonly report: ReportApiInterface;

public constructor(authHandler: AuthHandler, baseUrls: ServiceBaseUrlSet = PRODUCTION_BASE_URLS) {
this.auth = new AuthApi(new ApiConnection(authHandler, baseUrls.auth));
Expand Down
3 changes: 3 additions & 0 deletions packages/api-client/src/connections/AuthApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import { AccessPolicyObject } from '../types';
import { BaseApi } from './BaseApi';
import { PublicInterface } from './types';

type ServerAuthResponse = {
accessToken?: string;
Expand Down Expand Up @@ -52,3 +53,5 @@ export class AuthApi extends BaseApi {
return { accessToken, refreshToken, accessPolicy, email, user };
}
}

export interface AuthApiInterface extends PublicInterface<AuthApi> {}
3 changes: 3 additions & 0 deletions packages/api-client/src/connections/CentralApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { QueryParameters } from '../types';
import { RequestBody } from './ApiConnection';
import { BaseApi } from './BaseApi';
import { PublicInterface } from './types';

export type SurveyResponse = {
surveyId: string;
Expand Down Expand Up @@ -97,3 +98,5 @@ export class CentralApi extends BaseApi {
return resource;
}
}

export interface CentralApiInterface extends PublicInterface<CentralApi> {}
3 changes: 3 additions & 0 deletions packages/api-client/src/connections/EntityApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import { BaseApi } from './BaseApi';
import { PublicInterface } from './types';

const CLAUSE_DELIMITER = ';';
const NESTED_FIELD_DELIMITER = '_';
Expand Down Expand Up @@ -254,3 +255,5 @@ export class EntityApi extends BaseApi {
);
}
}

export interface EntityApiInterface extends PublicInterface<EntityApi> {}
3 changes: 3 additions & 0 deletions packages/api-client/src/connections/ReportApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { QueryParameters } from '../types';
import { RequestBody } from './ApiConnection';
import { BaseApi } from './BaseApi';
import { PublicInterface } from './types';

export class ReportApi extends BaseApi {
public async testReport(query: QueryParameters, body: RequestBody) {
Expand All @@ -20,3 +21,5 @@ export class ReportApi extends BaseApi {
return this.connection.get('fetchTransformSchemas');
}
}

export interface ReportApiInterface extends PublicInterface<ReportApi> {}
8 changes: 4 additions & 4 deletions packages/api-client/src/connections/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

export { ApiConnection } from './ApiConnection';
export { AuthApi } from './AuthApi';
export { EntityApi } from './EntityApi';
export { CentralApi } from './CentralApi';
export { ReportApi } from './ReportApi';
export { AuthApi, AuthApiInterface } from './AuthApi';
export { EntityApi, EntityApiInterface } from './EntityApi';
export { CentralApi, CentralApiInterface } from './CentralApi';
export { ReportApi, ReportApiInterface } from './ReportApi';
37 changes: 37 additions & 0 deletions packages/api-client/src/connections/mocks/MockAuthApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
/**
* Tupaia
* Copyright (c) 2017 - 2022 Beyond Essential Systems Pty Ltd
*/

import { AuthApiInterface } from '..';
import { AccessPolicyObject } from '../../types';

export class MockAuthApi implements AuthApiInterface {
public login(authDetails: {
emailAddress: string;
password: string;
deviceName: string;
devicePlatform?: string | undefined;
installId?: string | undefined;
}): Promise<{
accessToken: string;
refreshToken: string;
accessPolicy: AccessPolicyObject;
email: string;
user: { email: string; accessPolicy: AccessPolicyObject };
}> {
throw new Error('Method not implemented.');
}
public refreshAccessToken(
refreshToken: string,
): Promise<{
accessToken: string;
refreshToken: string;
accessPolicy: AccessPolicyObject;
email: string;
user: { email: string; accessPolicy: AccessPolicyObject };
}> {
throw new Error('Method not implemented.');
}
}
58 changes: 58 additions & 0 deletions packages/api-client/src/connections/mocks/MockCentralApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
/**
* Tupaia
* Copyright (c) 2017 - 2022 Beyond Essential Systems Pty Ltd
*/

import { CentralApiInterface } from '..';
import { RequestBody } from '../ApiConnection';
import { SurveyResponse } from '../CentralApi';

export class MockCentralApi implements CentralApiInterface {
public getUser(): Promise<any> {
throw new Error('Method not implemented.');
}
public registerUserAccount(
userFields: Record<string, unknown>,
): Promise<{ userId: string; message: string }> {
throw new Error('Method not implemented.');
}
public changeUserPassword(
passwordChangeFields: Record<string, unknown>,
): Promise<{ message: string }> {
throw new Error('Method not implemented.');
}
public createSurveyResponses(responses: SurveyResponse[]): Promise<void> {
throw new Error('Method not implemented.');
}
public fetchResources(
endpoint: string,
params?: Record<string, unknown> | undefined,
): Promise<any> {
throw new Error('Method not implemented.');
}
public createResource(
endpoint: string,
params: Record<string, unknown>,
body: RequestBody,
): Promise<any> {
throw new Error('Method not implemented.');
}
public updateResource(
endpoint: string,
params: Record<string, unknown>,
body: RequestBody,
): Promise<any> {
throw new Error('Method not implemented.');
}
public deleteResource(endpoint: string): Promise<any> {
throw new Error('Method not implemented.');
}
public upsertResource(
endpoint: string,
params: Record<string, unknown>,
body: RequestBody,
): Promise<any> {
throw new Error('Method not implemented.');
}
}
Loading

0 comments on commit 222b92a

Please sign in to comment.