Skip to content

Commit

Permalink
refactor: convert project to ESM (#927)
Browse files Browse the repository at this point in the history
* feat(hermes): add scalar to eventually replace swagger ui

note: it throws a build error that we can hack around, but we should find a proper fix.
also, the issue of only client id appearing is also present here

* refactor(grpc-sdk): to esm

* chore: update ts-proto to latest

* refactor(module-tools): to esm

* chore(testing-tools): update ts-proto

* refactor(hermes): to esm

* refactor(authentication): to esm
refactor: change lodash in libraries and auth to lodash-es

cannot progress further due to long.js import issues

* refactor(authorization): convert to esm

* refactor(chat): convert to esm

* refactor(database): convert to esm

* refactor(email): convert to esm

* refactor(forms): convert to esm

* refactor(functions): convert to esm

* refactor(push-notifications): convert to esm

* refactor(router): convert to esm

* refactor(sms): convert to esm

* refactor(storage): convert to esm

* refactor(admin,commons,core): convert to esm

* fix: missing __dirname in ESM
refactor(grpc-sdk): replace redlock with current package
fix(hermes): plugin and type issues after esm update

* fix(chat): missing lodash-es

* fix(authorization): missing __dirname in jobs

* fix(authentication): circular dependency

* [CodeFactor] Apply fixes

* fix(authorization): remove any from job events

* fix(authentication): remove any from oauth2 handler construction

* fix(grpc-sdk): remove any cast of redis client

* fix(email): type issues

* fix(database): redundant import

* refactor(email): apply codefactor recommendations

* chore(forms): redundant code cleanup

* fix(forms): form schema types

* fix(forms): reply schema types

* build: bump typescript from 5.2.2 to 5.3.3

* fix(authentication,admin): jsonwebtoken imports

* chore(authentication,admin): drop crypto standalone pkg

* chore(hermes,router,database): replace deepdash with deepdash-es

* fix(authentication,router,sms): bcrypt esm imports

* fix(authorization,email,functions): lodash->lodash-es leftovers, bump types, rm unusude devDeps

---------

Co-authored-by: codefactor-io <[email protected]>
Co-authored-by: Konstantinos Feretos <[email protected]>
  • Loading branch information
3 people authored Jan 31, 2024
1 parent 88294fe commit f81c811
Show file tree
Hide file tree
Showing 462 changed files with 2,178 additions and 1,745 deletions.
3 changes: 2 additions & 1 deletion libraries/grpc-sdk/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ protoc \
--ts_proto_opt=esModuleInterop=true \
--ts_proto_opt=outputServices=generic-definitions,exportCommonSymbols=false,useExactTypes=false \
--ts_proto_out=./ \
--ts_proto_opt=importSuffix=.js \
--ts_proto_opt=snakeToCamel=false \
./*.proto

Expand All @@ -25,7 +26,7 @@ for FILE in ./*.ts; do
if [ "$FILENAME" != "index.ts" ]; then
# Remove the file extension and create an export statement
BASENAME="${FILENAME%.ts}"
EXPORT_STATEMENT="export * from './$BASENAME';"
EXPORT_STATEMENT="export * from './$BASENAME.js';"

# Append the export statement to the index.ts content
INDEX_CONTENT="$INDEX_CONTENT$EXPORT_STATEMENT\n"
Expand Down
13 changes: 6 additions & 7 deletions libraries/grpc-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"engines": {
"node": ">=14"
},
"type": "module",
"scripts": {
"prepublish": "npm run build",
"prebuild": "npm run protoc",
Expand All @@ -17,20 +18,18 @@
"dependencies": {
"@grpc/grpc-js": "^1.9.7",
"@grpc/proto-loader": "^0.7.6",
"@types/google-protobuf": "^3.15.6",
"@types/lodash": "^4.14.200",
"@sesamecare-oss/redlock": "^1.2.0",
"abort-controller-x": "^0.4.1",
"convict": "^6.2.4",
"express": "^4.18.2",
"fast-jwt": "^3.3.2",
"fs-extra": "^11.2.0",
"ioredis": "^5.3.2",
"lodash": "^4.17.21",
"lodash-es": "^4.17.21",
"nice-grpc": "^2.1.7",
"nice-grpc-client-middleware-retry": "^3",
"prom-client": "^15.0.0",
"protobufjs": "^7.2.4",
"redlock": "^5.0.0-beta.2",
"winston": "^3.8.2",
"winston-loki": "^6.0.8"
},
Expand All @@ -51,12 +50,12 @@
"@types/express": "^4.17.21",
"@types/fs-extra": "^11.0.4",
"@types/google-protobuf": "^3.15.6",
"@types/lodash": "^4.14.200",
"@types/lodash-es": "^4.17.12",
"@types/node": "20.10.3",
"copyfiles": "^2.4.1",
"rimraf": "^5.0.5",
"ts-proto": "^1.160.0",
"typescript": "~5.2.2"
"ts-proto": "^1.167.1",
"typescript": "~5.3.3"
},
"peerDependencies": {
"@grpc/grpc-js": "^1.9.7"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Resource_Permission, Resource_Relation } from '../protoUtils/authorization';
import { Resource_Permission, Resource_Relation } from '../protoUtils/index.js';

export class ConduitAuthorizedResource {
readonly name: string;
Expand Down
9 changes: 6 additions & 3 deletions libraries/grpc-sdk/src/classes/ConduitModule.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { getGrpcSignedTokenInterceptor, getModuleNameInterceptor } from '../interceptors';
import {
getGrpcSignedTokenInterceptor,
getModuleNameInterceptor,
} from '../interceptors/index.js';
import { CompatServiceDefinition } from 'nice-grpc/lib/service-definitions';
import { Channel, Client, createChannel, createClientFactory } from 'nice-grpc';
import { retryMiddleware } from 'nice-grpc-client-middleware-retry';
import {
ConduitModuleDefinition,
HealthCheckResponse,
HealthDefinition,
} from '../protoUtils';
} from '../protoUtils/index.js';
import { EventEmitter } from 'events';
import ConduitGrpcSdk from '../index';
import ConduitGrpcSdk from '../index.js';

export class ConduitModule<T extends CompatServiceDefinition> {
protected channel?: Channel;
Expand Down
2 changes: 1 addition & 1 deletion libraries/grpc-sdk/src/classes/ConduitSchema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ConduitModel, ConduitSchemaOptions } from '../interfaces';
import { ConduitModel, ConduitSchemaOptions } from '../interfaces/index.js';

export class ConduitSchema {
readonly name: string;
Expand Down
9 changes: 6 additions & 3 deletions libraries/grpc-sdk/src/classes/HealthCheck.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { getGrpcSignedTokenInterceptor, getModuleNameInterceptor } from '../interceptors';
import {
getGrpcSignedTokenInterceptor,
getModuleNameInterceptor,
} from '../interceptors/index.js';
import { createChannel, createClientFactory } from 'nice-grpc';
import { HealthCheckResponse, HealthDefinition } from '../protoUtils';
import ConduitGrpcSdk from '../index';
import { HealthCheckResponse, HealthDefinition } from '../protoUtils/index.js';
import ConduitGrpcSdk from '../index.js';

export async function checkModuleHealth(
clientName: string,
Expand Down
10 changes: 5 additions & 5 deletions libraries/grpc-sdk/src/classes/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from './Error';
export * from './ConduitModule';
export * from './HealthCheck';
export * from './ConduitSchema';
export * from './ConduitAuthorizedResource';
export * from './Error.js';
export * from './ConduitModule.js';
export * from './HealthCheck.js';
export * from './ConduitSchema.js';
export * from './ConduitAuthorizedResource.js';
2 changes: 1 addition & 1 deletion libraries/grpc-sdk/src/constants/enums/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './PlatformTypesEnum';
export * from './PlatformTypesEnum.js';
2 changes: 1 addition & 1 deletion libraries/grpc-sdk/src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './enums';
export * from './enums/index.js';
42 changes: 24 additions & 18 deletions libraries/grpc-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,29 @@ import {
Router,
SMS,
Storage,
} from './modules';
import Crypto from 'crypto';
import { EventBus, getJsonEnv, RedisManager, sleep, StateManager } from './utilities';
} from './modules/index.js';
import crypto from 'crypto';
import {
EventBus,
getJsonEnv,
RedisManager,
sleep,
StateManager,
} from './utilities/index.js';
import { CompatServiceDefinition } from 'nice-grpc/lib/service-definitions';
import { checkModuleHealth, ConduitModule } from './classes';
import { checkModuleHealth, ConduitModule } from './classes/index.js';
import { Client } from 'nice-grpc';
import { status } from '@grpc/grpc-js';
import { GrpcError, HealthCheckStatus } from './types/index.js';
import { createSigner } from 'fast-jwt';
import { ClusterOptions, RedisOptions } from 'ioredis';
import { IConduitLogger, IConduitMetrics } from './interfaces/index.js';
import {
ConduitModuleDefinition,
HealthCheckResponse_ServingStatus,
HealthDefinition,
ModuleListResponse_ModuleResponse,
} from './protoUtils';
import { GrpcError, HealthCheckStatus } from './types';
import { createSigner } from 'fast-jwt';
import { ClusterOptions, RedisOptions } from 'ioredis';
import { IConduitLogger, IConduitMetrics } from './interfaces';
} from './protoUtils/index.js';

type UrlRemap = { [url: string]: string };

Expand Down Expand Up @@ -75,13 +81,13 @@ export default class ConduitGrpcSdk {
}

if (!name) {
this.name = 'module_' + Crypto.randomBytes(16).toString('hex');
this.name = 'module_' + crypto.randomBytes(16).toString('hex');
} else {
this.name = name;
}
this.instance = this.name.startsWith('module_')
? this.name.substring(8)
: Crypto.randomBytes(16).toString('hex');
: crypto.randomBytes(16).toString('hex');

this.urlRemap = getJsonEnv<UrlRemap>(
'URL_REMAP',
Expand Down Expand Up @@ -565,11 +571,11 @@ export default class ConduitGrpcSdk {
}
}

export * from './interfaces';
export * from './classes';
export * from './modules';
export * from './constants';
export * from './types';
export * from './utilities';
export * from './protoUtils';
export * from './interfaces/index.js';
export * from './classes/index.js';
export * from './modules/index.js';
export * from './constants/index.js';
export * from './types/index.js';
export * from './utilities/index.js';
export * from './protoUtils/index.js';
export * from '@grpc/grpc-js';
4 changes: 2 additions & 2 deletions libraries/grpc-sdk/src/interceptors/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './moduleName';
export * from './grpcSignedToken';
export * from './moduleName.js';
export * from './grpcSignedToken.js';
2 changes: 1 addition & 1 deletion libraries/grpc-sdk/src/interfaces/ConduitMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ConduitRouteActions } from './Route';
import { ConduitRouteActions } from './Route.js';

export interface ConduitMiddlewareOptions {
action?: ConduitRouteActions;
Expand Down
4 changes: 2 additions & 2 deletions libraries/grpc-sdk/src/interfaces/ConduitRoute.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ConduitRouteReturnDefinition } from './ConduitRouteReturn';
import { ConduitRouteOptions } from './Route';
import { ConduitRouteReturnDefinition } from './ConduitRouteReturn.js';
import { ConduitRouteOptions } from './Route.js';

export interface ConduitRoute {
returnType: ConduitRouteReturnDefinition;
Expand Down
2 changes: 1 addition & 1 deletion libraries/grpc-sdk/src/interfaces/ConduitRouteReturn.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ConduitReturn } from './Route';
import { ConduitReturn } from './Route.js';

/**
* Supports:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ConduitModel } from './Model';
import { ConduitModel } from './Model.js';

export interface ConduitSchemaExtension {
readonly schemaName: string;
Expand Down
2 changes: 1 addition & 1 deletion libraries/grpc-sdk/src/interfaces/IConduitLogger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import winston, { LogCallback, Logger } from 'winston';
import { Indexable } from './Indexable';
import { Indexable } from './Indexable.js';

export interface IConduitLogger {
get winston(): winston.Logger;
Expand Down
2 changes: 1 addition & 1 deletion libraries/grpc-sdk/src/interfaces/IConduitMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
Summary,
SummaryConfiguration,
} from 'prom-client';
import { MetricType } from '../types';
import { MetricType } from '../types/index.js';

export interface IConduitMetrics {
initializeDefaultMetrics(): void;
Expand Down
2 changes: 1 addition & 1 deletion libraries/grpc-sdk/src/interfaces/Params.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Indexable } from './Indexable';
import { Indexable } from './Indexable.js';

export type UrlParams = {
[key: string]: string;
Expand Down
4 changes: 2 additions & 2 deletions libraries/grpc-sdk/src/interfaces/Route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { allowedTypes, ConduitModel, TYPE } from './Model';
import { Indexable } from './Indexable';
import { allowedTypes, ConduitModel, TYPE } from './Model.js';
import { Indexable } from './Indexable.js';

export interface ConduitRouteParameters {
params?: Indexable;
Expand Down
4 changes: 2 additions & 2 deletions libraries/grpc-sdk/src/interfaces/Socket.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ConduitRouteReturnDefinition } from './ConduitRouteReturn';
import { TYPE } from './Model';
import { ConduitRouteReturnDefinition } from './ConduitRouteReturn.js';
import { TYPE } from './Model.js';

export type ConduitSocketParamTypes = (TYPE | ConduitSocketParamTypes)[];

Expand Down
32 changes: 16 additions & 16 deletions libraries/grpc-sdk/src/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
export * from './ConduitMiddleware';
export * from './ConduitRoute';
export * from './ProxyRoute';
export * from './Route';
export * from './Socket';
export * from './types';
export * from './Model';
export * from './GrpcCallback';
export * from './Indexable';
export * from './RawQuery';
export * from './UntypedArray';
export * from './Params';
export * from './ConduitRouteReturn';
export * from './ConduitSchemaExtension';
export * from './IConduitLogger';
export * from './IConduitMetrics';
export * from './ConduitMiddleware.js';
export * from './ConduitRoute.js';
export * from './ProxyRoute.js';
export * from './Route.js';
export * from './Socket.js';
export * from './types.js';
export * from './Model.js';
export * from './GrpcCallback.js';
export * from './Indexable.js';
export * from './RawQuery.js';
export * from './UntypedArray.js';
export * from './Params.js';
export * from './ConduitRouteReturn.js';
export * from './ConduitSchemaExtension.js';
export * from './IConduitLogger.js';
export * from './IConduitMetrics.js';
4 changes: 2 additions & 2 deletions libraries/grpc-sdk/src/interfaces/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Context, Cookies, Indexable, Params } from './Indexable';
import { GrpcRequest } from '../types';
import { Context, Cookies, Indexable, Params } from './Indexable.js';
import { GrpcRequest } from '../types/index.js';

export type ParsedRouterRequest = GrpcRequest<{
params: Params;
Expand Down
12 changes: 8 additions & 4 deletions libraries/grpc-sdk/src/modules/admin/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { ConduitModule } from '../../classes';
import { ConduitModule } from '../../classes/index.js';
import {
AdminDefinition,
RegisterAdminRouteRequest,
RegisterAdminRouteRequest_PathDefinition,
} from '../../protoUtils';
import { ConduitRouteActions } from '../../interfaces';
} from '../../protoUtils/index.js';
import { ConduitRouteActions } from '../../interfaces/index.js';

export class Admin extends ConduitModule<typeof AdminDefinition> {
constructor(readonly moduleName: string, url: string, grpcToken?: string) {
constructor(
readonly moduleName: string,
url: string,
grpcToken?: string,
) {
super(moduleName, 'admin', url, grpcToken);
this.initializeClient(AdminDefinition);
}
Expand Down
4 changes: 2 additions & 2 deletions libraries/grpc-sdk/src/modules/authentication/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ConduitModule } from '../../classes';
import { ConduitModule } from '../../classes/index.js';
import {
AuthenticationDefinition,
TeamDeleteResponse,
Expand All @@ -7,7 +7,7 @@ import {
UserLoginResponse,
Team,
ValidateAccessTokenResponse,
} from '../../protoUtils';
} from '../../protoUtils/index.js';

export class Authentication extends ConduitModule<typeof AuthenticationDefinition> {
constructor(
Expand Down
Loading

0 comments on commit f81c811

Please sign in to comment.