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

no-issue: Add @tupaia/server-utils package #5121

Merged
merged 6 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ jobs:
- psss-server
- report-server
- server-boilerplate
- server-utils
- superset-api
- tsutils
- tupaia-web
Expand Down Expand Up @@ -207,4 +208,4 @@ jobs:
- name: Green if all jobs are green
uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJSON(needs) }}
jobs: ${{ toJSON(needs) }}
1 change: 1 addition & 0 deletions packages/central-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@tupaia/dhis-api": "1.0.0",
"@tupaia/expression-parser": "1.0.0",
"@tupaia/server-boilerplate": "1.0.0",
"@tupaia/server-utils": "1.0.0",
"@tupaia/tsutils": "1.0.0",
"@tupaia/types": "1.0.0",
"@tupaia/utils": "1.0.0",
Expand Down
3 changes: 1 addition & 2 deletions packages/central-server/src/apiV2/DownloadFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
*/

import {
S3,
S3Client,
ValidationError,
respondWithDownload,
writeStreamToFile,
getUniqueFileNameParts,
getDeDuplicatedFileName,
} from '@tupaia/utils';
import { S3, S3Client } from '@tupaia/server-utils';
import { RouteHandler } from './RouteHandler';
import { getTempDirectory } from '../utilities';
import { zipMultipleFiles } from './utilities';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import winston from 'winston';
import { S3Client, S3 } from '@tupaia/utils';
import { S3Client, S3 } from '@tupaia/server-utils';

/**
* action object e.g.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import winston from 'winston';
import { S3Client, S3 } from '@tupaia/utils';
import { S3Client, S3 } from '@tupaia/server-utils';

// Upload a surveyImage to s3
export const addSurveyImage = async (models, { id, data }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Copyright (c) 2017 - 2020 Beyond Essential Systems Pty Ltd
*/

import { S3, S3Client } from '@tupaia/utils';
import { S3, S3Client } from '@tupaia/server-utils';
import { AnalyticsRefresher } from '@tupaia/database';
import fs from 'fs';
import { EditHandler } from '../EditHandler';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import { hashAndSaltPassword } from '@tupaia/auth';
import { S3Client, S3 } from '@tupaia/utils';
import { S3Client, S3 } from '@tupaia/server-utils';
import { EditHandler } from '../EditHandler';
import {
assertAnyPermissions,
Expand Down Expand Up @@ -52,7 +52,6 @@ export class EditUserAccounts extends EditHandler {
};
}


if (preferenceField) {
throw new Error('Preferences should be updated via the specific preferences fields');
}
Expand Down
2 changes: 1 addition & 1 deletion packages/central-server/src/apiV2/utilities/uploadImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/

import { S3Client, S3 } from '@tupaia/utils';
import { S3Client, S3 } from '@tupaia/server-utils';
import { getStandardisedImageName } from '../../utilities';

/**
Expand Down
10 changes: 2 additions & 8 deletions packages/central-server/src/dataAccessors/upsertAnswers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,8 @@
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/

import {
DatabaseError,
getS3ImageFilePath,
S3Client,
S3,
S3_BUCKET_PATH,
UploadError,
} from '@tupaia/utils';
import { DatabaseError, UploadError } from '@tupaia/utils';
import { getS3ImageFilePath, S3Client, S3, S3_BUCKET_PATH } from '@tupaia/server-utils';

export async function upsertAnswers(models, answers, surveyResponseId) {
const answerRecords = [];
Expand Down
1 change: 1 addition & 0 deletions packages/lesmis-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@tupaia/access-policy": "3.0.0",
"@tupaia/database": "1.0.0",
"@tupaia/server-boilerplate": "1.0.0",
"@tupaia/server-utils": "1.0.0",
"@tupaia/tsutils": "1.0.0",
"@tupaia/utils": "1.0.0",
"camelcase-keys": "^6.2.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/lesmis-server/src/routes/PDFExportRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
import { Request, Response, NextFunction } from 'express';
import { Route } from '@tupaia/server-boilerplate';
import { downloadPageAsPDF } from '@tupaia/tsutils';
import { downloadPageAsPDF } from '@tupaia/server-utils';

type Body = {
pdfPageUrl: string;
Expand Down
1 change: 1 addition & 0 deletions packages/meditrak-app-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@tupaia/auth": "1.0.0",
"@tupaia/database": "1.0.0",
"@tupaia/server-boilerplate": "1.0.0",
"@tupaia/server-utils": "1.0.0",
"@tupaia/tsutils": "1.0.0",
"@tupaia/types": "1.0.0",
"@tupaia/utils": "1.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ const S3ClientMock = {
},
};

jest.mock('@tupaia/utils', () => {
const original = jest.requireActual('@tupaia/utils');
jest.mock('@tupaia/server-utils', () => {
const original = jest.requireActual('@tupaia/server-utils');
return {
...original,
S3Client: jest.fn().mockImplementation(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import winston from 'winston';
import { S3Client, S3 } from '@tupaia/utils';
import { S3Client, S3 } from '@tupaia/server-utils';
import { MeditrakAppServerModelRegistry } from '../../../types';

/**
Expand All @@ -29,6 +29,6 @@ export const addSurveyFile = async (
const s3Client = new S3Client(new S3());
await s3Client.uploadFile(uniqueFileName, decodedFileBuffer);
} catch (error) {
winston.error(error.message);
winston.error((error as Error).message);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import winston from 'winston';
import { S3Client, S3 } from '@tupaia/utils';
import { S3Client, S3 } from '@tupaia/server-utils';

// Upload a surveyImage to s3
export const addSurveyImage = async (id: string, data: string) => {
Expand Down
10 changes: 10 additions & 0 deletions packages/server-utils/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* eslint-env node */
module.exports = {
extends: "../../.eslintrc-ts.json",
// Standard config needed for correct scoping of eslint
parserOptions: {
tsconfigRootDir: __dirname,
project: ['./tsconfig.json'],
},
root: true,
};
1 change: 1 addition & 0 deletions packages/server-utils/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scripts-prepend-node-path=true
3 changes: 3 additions & 0 deletions packages/server-utils/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @tupaia/server-utils

Utility functions that are just for server packages
6 changes: 6 additions & 0 deletions packages/server-utils/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const baseConfig = require('../../jest.config-ts.json');

module.exports = async () => ({
...baseConfig,
rootDir: '.',
});
30 changes: 30 additions & 0 deletions packages/server-utils/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "@tupaia/server-utils",
"version": "1.0.0",
"private": true,
"description": "Utility functions that are just for server packages",
"repository": {
"type": "git",
"url": "git+https://github.com/beyondessential/tupaia.git",
"directory": "packages/server-utils"
},
"author": "Beyond Essential Systems <admin@tupaia.org> (https://beyondessential.com.au)",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "rm -rf dist && npm run --prefix ../../ package:build:ts",
"build-dev": "npm run build",
"lint": "yarn package:lint",
"lint:fix": "yarn lint --fix",
"test": "yarn package:test --passWithNoTests",
"test:coverage": "yarn test --coverage"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.341.0",
"@aws-sdk/credential-providers": "^3.341.0",
"@aws-sdk/lib-storage": "^3.348.0",
"@tupaia/utils": "1.0.0",
"cookie": "^0.5.0",
"puppeteer": "^15.4.0"
}
}
10 changes: 10 additions & 0 deletions packages/server-utils/src/__tests__/example.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Tupaia
* Copyright (c) 2017 - 2021 Beyond Essential Systems Pty Ltd
*/

describe('Example test', () => {
it('passes a stub test', () => {
expect(1).toBe(1);
});
});
2 changes: 2 additions & 0 deletions packages/server-utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './downloadPageAsPDF';
export * from './s3';
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

import { fromEnv } from '@aws-sdk/credential-providers';
import { S3 as BaseS3 } from '@aws-sdk/client-s3';
import { requireEnv } from '../requireEnv';
import { requireEnv } from '@tupaia/utils';

export class S3 extends BaseS3 {
constructor() {
public constructor() {
super({ credentials: fromEnv(), region: requireEnv('AWS_REGION') });
}
}
Loading