Skip to content
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
14 changes: 7 additions & 7 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ Make sure you've read the contributing guidelines (CONTRIBUTING.md)

| Question | Answer |
| --------------- | ------ |
| Bug fix | ✔/✖ |
| New feature | ✔/✖ |
| Breaking change | ✔/✖ |
| Deprecations | ✔/✖ |
| Documentation | ✔/✖ |
| Tests added | ✔/✖ |
| Chore | ✔/✖ |
| Bug fix | ✔/✖ |
| New feature | ✔/✖ |
| Breaking change | ✔/✖ |
| Deprecations | ✔/✖ |
| Documentation | ✔/✖ |
| Tests added | ✔/✖ |
| Chore | ✔/✖ |

Related issues: #XXX , #XXX ...
Closes #XXX ...
Expand Down
7 changes: 4 additions & 3 deletions apps/auth-cron/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { config } from '@map-colonies/eslint-config/helpers';
import baseConfig from '../../eslint.config.mjs';
import { defineConfig, globalIgnores } from 'eslint/config';
import tsBaseConfig from '@map-colonies/eslint-config/ts-base';
import vitestConfig from '@map-colonies/eslint-config/vitest';

export default config(baseConfig, {});
export default defineConfig(tsBaseConfig, vitestConfig, globalIgnores(['vitest.config.mts', 'ui/**/*', 'drizzle.config.mts']));
2 changes: 0 additions & 2 deletions apps/auth-cron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
"url": "git+https://github.com/MapColonies/opa-la.git"
},
"scripts": {
"format": "prettier --check .",
"format:fix": "prettier --write .",
"lint": "eslint .",
"lint:fix": "eslint --fix .",
"migration:run": "npm run typeorm migration:run -- ",
Expand Down
9 changes: 5 additions & 4 deletions apps/auth-cron/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import { env } from 'node:process';
import { createServer } from 'node:http';
import express from 'express';
import { createTerminus } from '@godaddy/terminus';
import { CatchCallbackFn, Cron } from 'croner';
import { DataSource, Repository } from 'typeorm';
import { Bundle, Environments, initConnection } from '@map-colonies/auth-core';
import type { CatchCallbackFn } from 'croner';
import { Cron } from 'croner';
import type { DataSource, Repository } from 'typeorm';
import type { Environments } from '@map-colonies/auth-core';
import { Bundle, initConnection } from '@map-colonies/auth-core';
import type { commonDbFullV1Type } from '@map-colonies/schemas';
import { BundleDatabase } from '@map-colonies/auth-bundler';
import { collectMetricsExpressMiddleware } from '@map-colonies/telemetry/prom-metrics';
Expand Down Expand Up @@ -66,5 +68,4 @@ const main = async (): Promise<void> => {
});
};

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
main().catch((err) => logger?.error({ msg: 'program terminated with an error', err }));
7 changes: 4 additions & 3 deletions apps/auth-cron/src/job.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import path from 'node:path';
import { BundleDatabase, createBundle, getVersionCommand } from '@map-colonies/auth-bundler';
import { Bundle, Environments } from '@map-colonies/auth-core';
import { Repository } from 'typeorm';
import type { BundleDatabase } from '@map-colonies/auth-bundler';
import { createBundle, getVersionCommand } from '@map-colonies/auth-bundler';
import type { Bundle, Environments } from '@map-colonies/auth-core';
import type { Repository } from 'typeorm';
import { getS3Client } from './s3';
import { compareVersionsToBundle } from './util';
import { logger } from './telemetry/logger';
Expand Down
2 changes: 1 addition & 1 deletion apps/auth-cron/src/s3.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { readFileSync } from 'node:fs';
import { StatusCodes } from 'http-status-codes';
import { HeadBucketCommand, HeadObjectCommand, NotFound, PutObjectCommand, S3Client } from '@aws-sdk/client-s3';
import { Environments } from '@map-colonies/auth-core';
import type { Environments } from '@map-colonies/auth-core';
import type { infraOpalaCronV1Type } from '@map-colonies/schemas';
import { getConfig } from './config';
import { logger } from './telemetry/logger';
Expand Down
3 changes: 2 additions & 1 deletion apps/auth-cron/src/telemetry/logger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Logger, jsLogger } from '@map-colonies/js-logger';
import type { Logger } from '@map-colonies/js-logger';
import { jsLogger } from '@map-colonies/js-logger';
import { setLogger } from '@map-colonies/auth-bundler';
import { getConfig } from '../config';

Expand Down
4 changes: 2 additions & 2 deletions apps/auth-cron/src/util.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import assert from 'node:assert';
import { readdir, rm } from 'node:fs/promises';
import path from 'node:path';
import { Bundle } from '@map-colonies/auth-core';
import { BundleContentVersions } from '@map-colonies/auth-bundler/dist/types';
import type { Bundle } from '@map-colonies/auth-core';
import type { BundleContentVersions } from '@map-colonies/auth-bundler/dist/types';
import { logger } from './telemetry/logger';

export function compareVersionsToBundle(bundle: Bundle, versions: BundleContentVersions): boolean {
Expand Down
2 changes: 1 addition & 1 deletion apps/auth-cron/src/validators.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Environments } from '@map-colonies/auth-core';
import type { Environments } from '@map-colonies/auth-core';
import { getS3Client } from './s3';
import { logger } from './telemetry/logger';

Expand Down
15 changes: 10 additions & 5 deletions apps/auth-cron/tests/config.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { vi, describe, it, expect } from 'vitest';
import { ConfigErrors } from '@map-colonies/config';
import type * as configType from '@map-colonies/config';
import type { ConfigErrors } from '@map-colonies/config';
import type * as localConfigType from '@src/config';
import { getConfig } from '@src/config';

describe('config.ts', function () {
Expand All @@ -10,11 +12,11 @@ describe('config.ts', function () {

it('should throw if no cron is configured', async function () {
expect.assertions(2);

vi.resetModules();
// await vi.isolateModulesAsync(async () => {
/* eslint-disable @typescript-eslint/no-require-imports */
const { initConfig } = (await import('../src/config.js')) as typeof import('../src/config');
const configModule = require('@map-colonies/config') as typeof import('@map-colonies/config');
const { initConfig } = (await import('../src/config.js')) as typeof localConfigType;
const configModule = require('@map-colonies/config') as typeof configType;
/* eslint-enable @typescript-eslint/no-require-imports */

const configSpy = vi.spyOn(configModule, 'config');
Expand All @@ -24,13 +26,16 @@ describe('config.ts', function () {
});

const action = initConfig(true);

await expect(action).rejects.toThrow('Config validation error');

await action.catch((err) => {
const validationErr = err as ConfigErrors['configValidationError'];

const filtered = validationErr.payload.filter((error) => error.message === "property 'cron' must match a schema in anyOf");

// eslint-disable-next-line vitest/no-conditional-expect
expect(filtered).toHaveLength(1);
// });
});
});
});
Expand Down
13 changes: 8 additions & 5 deletions apps/auth-cron/tests/job.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { tmpdir } from 'node:os';
import { writeFile } from 'node:fs/promises';
import path from 'node:path';
import { BundleDatabase, createBundle } from '@map-colonies/auth-bundler';
import type { BundleDatabase } from '@map-colonies/auth-bundler';
import { createBundle } from '@map-colonies/auth-bundler';
import * as authBundler from '@map-colonies/auth-bundler';
import { Bundle, Environment } from '@map-colonies/auth-core';
import { Repository } from 'typeorm';
import { vi, describe, Mock, beforeEach, afterEach, afterAll, it, expect, beforeAll } from 'vitest';
import type { Bundle } from '@map-colonies/auth-core';
import { Environment } from '@map-colonies/auth-core';
import type { Repository } from 'typeorm';
import type { Mock } from 'vitest';
import { vi, describe, beforeEach, afterEach, afterAll, it, expect, beforeAll } from 'vitest';
import { jsLogger } from '@map-colonies/js-logger';
import { infraOpalaCronV1Type } from '@map-colonies/schemas';
import type { infraOpalaCronV1Type } from '@map-colonies/schemas';
import { PutObjectCommand, S3Client } from '@aws-sdk/client-s3';
import { getJob } from '@src/job';
import { getConfig, initConfig } from '@src/config';
Expand Down
12 changes: 7 additions & 5 deletions apps/auth-cron/tests/s3.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
// /// <reference types="jest-extended" />

import { createHash } from 'crypto';
import { createHash } from 'node:crypto';
import { tmpdir } from 'node:os';
import path from 'node:path';
import { writeFileSync } from 'node:fs';
import { vi, describe, beforeAll, it, expect } from 'vitest';
import { GetObjectCommand, PutObjectCommand, S3Client } from '@aws-sdk/client-s3';
import { Environment, Environments } from '@map-colonies/auth-core';
import { infraOpalaCronV1Type } from '@map-colonies/schemas';
import type { Environments } from '@map-colonies/auth-core';
import { Environment } from '@map-colonies/auth-core';
import type { infraOpalaCronV1Type } from '@map-colonies/schemas';
import { jsLogger } from '@map-colonies/js-logger';
import { initConfig, getConfig } from '@src/config';
import { getS3Client } from '@src/s3';
import * as appConfig from '@src/config';
import type * as appConfig from '@src/config';

vi.mock('../src/telemetry/logger', () => {
return {
Expand Down Expand Up @@ -66,6 +67,7 @@ describe('s3.ts', function () {
expect(() => getS3Client('avi' as Environments)).toThrow();
});
});

describe('#getObjectHash', function () {
it('should return the hash if the object exists', async function () {
// eslint-disable-next-line @typescript-eslint/naming-convention
Expand Down Expand Up @@ -121,7 +123,7 @@ describe('s3.ts', function () {
const res = await s3client.send(new GetObjectCommand({ Bucket: cronOptions.s3.bucket, Key: 'xd' }));

expect(res.ETag).toBe(hash);
expect(await res.Body?.transformToString()).toBe('abcdefg');
await expect(res.Body?.transformToString()).resolves.toBe('abcdefg');
});

it('should throw if something is wrong', async function () {
Expand Down
4 changes: 2 additions & 2 deletions apps/auth-cron/tests/util.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import path from 'node:path';
import { BundleContentVersions } from '@map-colonies/auth-bundler';
import type { BundleContentVersions } from '@map-colonies/auth-bundler';
import { describe, expect, it, vi } from 'vitest';
import { Bundle } from '@map-colonies/auth-core';
import type { Bundle } from '@map-colonies/auth-core';
import { jsLogger } from '@map-colonies/js-logger';
import { compareVersionsToBundle, emptyDir } from '@src/util';
import { getFakeBundle } from './utils/bundle';
Expand Down
3 changes: 2 additions & 1 deletion apps/auth-cron/tests/utils/asset.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { faker } from '@faker-js/faker';
import { AssetType, Environment, IAsset } from '@map-colonies/auth-core';
import type { IAsset } from '@map-colonies/auth-core';
import { AssetType, Environment } from '@map-colonies/auth-core';

const EIGHT = 8;

Expand Down
5 changes: 3 additions & 2 deletions apps/auth-cron/tests/utils/bundle.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { faker } from '@faker-js/faker';
import { BundleContent } from '@map-colonies/auth-bundler';
import { AssetType, Environment, IBundle } from '@map-colonies/auth-core';
import type { BundleContent } from '@map-colonies/auth-bundler';
import type { IBundle } from '@map-colonies/auth-core';
import { AssetType, Environment } from '@map-colonies/auth-core';

const EIGHT = 8;

Expand Down
3 changes: 2 additions & 1 deletion apps/auth-cron/tests/utils/connection.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { faker } from '@faker-js/faker';
import { Connection, Environment, IConnection } from '@map-colonies/auth-core';
import type { Connection, IConnection } from '@map-colonies/auth-core';
import { Environment } from '@map-colonies/auth-core';

const EIGHT = 8;

Expand Down
2 changes: 1 addition & 1 deletion apps/auth-cron/tests/utils/key.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { faker } from '@faker-js/faker';
import { JWKPrivateKey, JWKPublicKey } from '@map-colonies/auth-core';
import type { JWKPrivateKey, JWKPublicKey } from '@map-colonies/auth-core';

const LENGTH_OF_STRING = 3;

Expand Down
2 changes: 2 additions & 0 deletions apps/auth-cron/tests/validators.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ describe('validators.ts', function () {
beforeAll(async function () {
await initConfig(true);
});

describe('#validateS3', function () {
it('should not throw if the bucket exists', async function () {
const promise = validateS3([Environment.NP]);

await expect(promise).resolves.not.toThrow();
});

Expand Down
3 changes: 0 additions & 3 deletions apps/auth-cron/tsconfig.lint.json

This file was deleted.

12 changes: 4 additions & 8 deletions apps/auth-manager/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { config } from '@map-colonies/eslint-config/helpers';
import { defineConfig } from 'eslint/config';
import baseConfig from '../../eslint.config.mjs';
import { defineConfig, globalIgnores } from 'eslint/config';
import tsBaseConfig from '@map-colonies/eslint-config/ts-base';
import vitestConfig from '@map-colonies/eslint-config/vitest';

export default defineConfig(baseConfig, {});

// export default {
// rules: {}
// }
export default defineConfig(tsBaseConfig, vitestConfig, globalIgnores(['vitest.config.mts', 'ui/**/*', 'drizzle.config.mts']));
2 changes: 0 additions & 2 deletions apps/auth-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
"test": "vitest run",
"test:watch": "vitest watch",
"test:ui": "vitest --ui",
"format": "prettier --check .",
"format:fix": "prettier --write .",
"typeorm": "node ../../node_modules/typeorm/cli.js -d ./dataSource.mjs",
"migration:create": "npm run typeorm migration:generate --",
"migration:run": "npm run typeorm migration:run -- ",
Expand Down
7 changes: 4 additions & 3 deletions apps/auth-manager/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Application } from 'express';
import { DependencyContainer } from 'tsyringe';
import { registerExternalValues, RegisterOptions } from './containerConfig';
import type { Application } from 'express';
import type { DependencyContainer } from 'tsyringe';
import type { RegisterOptions } from './containerConfig';
import { registerExternalValues } from './containerConfig';
import { ServerBuilder } from './serverBuilder';

async function getApp(registerOptions?: RegisterOptions): Promise<[Application, DependencyContainer]> {
Expand Down
5 changes: 3 additions & 2 deletions apps/auth-manager/src/asset/DAL/assetRepository.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Asset } from '@map-colonies/auth-core';
import { FactoryFunction } from 'tsyringe';
import { DataSource, Repository } from 'typeorm';
import type { FactoryFunction } from 'tsyringe';
import type { Repository } from 'typeorm';
import { DataSource } from 'typeorm';

export type AssetRepository = Repository<Asset> & {
getMaxVersionWithLock: (name: string) => Promise<number | null>;
Expand Down
2 changes: 1 addition & 1 deletion apps/auth-manager/src/asset/routes/assetRouter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Router } from 'express';
import { FactoryFunction } from 'tsyringe';
import type { FactoryFunction } from 'tsyringe';
import { AssetController } from '../controllers/assetController';

export const assetRouterFactory: FactoryFunction<Router> = (dependencyContainer) => {
Expand Down
2 changes: 1 addition & 1 deletion apps/auth-manager/src/bundle/models/bundle.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IBundle } from '@map-colonies/auth-core';
import type { IBundle } from '@map-colonies/auth-core';

export interface BundleSearchParams {
environment?: IBundle['environment'][];
Expand Down
2 changes: 1 addition & 1 deletion apps/auth-manager/src/bundle/routes/bundleRouter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Router } from 'express';
import { FactoryFunction } from 'tsyringe';
import type { FactoryFunction } from 'tsyringe';
import { BundleController } from '../controllers/bundleController';

const bundleRouterFactory: FactoryFunction<Router> = (dependencyContainer) => {
Expand Down
5 changes: 3 additions & 2 deletions apps/auth-manager/src/client/DAL/clientRepository.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Client } from '@map-colonies/auth-core';
import { FactoryFunction } from 'tsyringe';
import { DataSource, Repository } from 'typeorm';
import type { FactoryFunction } from 'tsyringe';
import type { Repository } from 'typeorm';
import { DataSource } from 'typeorm';

export type ClientRepository = Repository<Client> & { updateAndReturn: (client: Client) => Promise<Client | null> };

Expand Down
2 changes: 1 addition & 1 deletion apps/auth-manager/src/client/routes/clientRouter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Router } from 'express';
import { FactoryFunction } from 'tsyringe';
import type { FactoryFunction } from 'tsyringe';
import { ConnectionController } from '@connection/controllers/connectionController';
import { ClientController } from '../controllers/clientController';

Expand Down
3 changes: 2 additions & 1 deletion apps/auth-manager/src/common/crypto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { importJWK, JWK, SignJWT } from 'jose';
import type { JWK } from 'jose';
import { importJWK, SignJWT } from 'jose';
import { TOKENS_ISSUER } from './constants';

/**
Expand Down
3 changes: 2 additions & 1 deletion apps/auth-manager/src/common/db/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Between, FindOperator, LessThan, MoreThan } from 'typeorm';
import type { FindOperator } from 'typeorm';
import { Between, LessThan, MoreThan } from 'typeorm';

export function createDatesComparison(earlyDate?: Date, laterDate?: Date): FindOperator<Date> | undefined {
if (earlyDate !== undefined && laterDate !== undefined) {
Expand Down
5 changes: 3 additions & 2 deletions apps/auth-manager/src/common/dependencyRegistration.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ClassProvider, container as defaultContainer, FactoryProvider, InjectionToken, ValueProvider } from 'tsyringe';
import { constructor, DependencyContainer } from 'tsyringe/dist/typings/types';
import type { ClassProvider, FactoryProvider, InjectionToken, ValueProvider } from 'tsyringe';
import { container as defaultContainer } from 'tsyringe';
import type { constructor, DependencyContainer } from 'tsyringe/dist/typings/types';

export type Providers<T> = ValueProvider<T> | FactoryProvider<T> | ClassProvider<T> | constructor<T>;

Expand Down
8 changes: 5 additions & 3 deletions apps/auth-manager/src/connection/DAL/connectionRepository.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Connection, Environments } from '@map-colonies/auth-core';
import { FactoryFunction } from 'tsyringe';
import { DataSource, Repository, SelectQueryBuilder } from 'typeorm';
import type { Environments } from '@map-colonies/auth-core';
import { Connection } from '@map-colonies/auth-core';
import type { FactoryFunction } from 'tsyringe';
import type { Repository, SelectQueryBuilder } from 'typeorm';
import { DataSource } from 'typeorm';

const maxVersionSubQuery = (qb: SelectQueryBuilder<Connection>): string => {
const subQuery = qb
Expand Down
6 changes: 3 additions & 3 deletions apps/auth-manager/src/connection/models/connectionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,10 @@ export class ConnectionManager {

try {
return await generateToken(key.privateKey as JWK, connection.name, key.privateKey.kid);
} catch (error) {
this.logger.error({ msg: 'could not generate token', error });
} catch (err) {
this.logger.error({ msg: 'could not generate token', err });
if (throwOnError === true) {
throw error;
throw err;
}
return '';
}
Expand Down
Loading
Loading