From decc59c47399a819940c4b0d879734cb2ad01e97 Mon Sep 17 00:00:00 2001 From: akumar Date: Mon, 12 Feb 2024 10:43:59 +0100 Subject: [PATCH] feat: switch to esm --- .eslintrc.cjs | 11 ++++ .eslintrc.js | 81 --------------------------- .github/workflows/build.yaml | 40 +++++-------- .github/workflows/pr-lint.yaml | 20 +++++++ .github/workflows/release.yaml | 62 ++++++++++---------- .mocharc.json | 6 +- .nvmrc | 1 + package.json | 19 ++++--- src/accessControlService.ts | 12 ++-- src/core/accessController.ts | 32 ++++++----- src/core/hierarchicalScope.ts | 12 ++-- src/core/index.ts | 6 +- src/core/interfaces.ts | 10 ++-- src/core/resource_adapters/adapter.ts | 2 +- src/core/resource_adapters/gql.ts | 10 ++-- src/core/resource_adapters/index.ts | 4 +- src/core/utils.ts | 20 +++---- src/core/verifyACL.ts | 12 ++-- src/resourceManager.ts | 20 +++---- src/start.ts | 20 ++++--- src/worker.ts | 34 +++++------ tsconfig.json | 28 +-------- 22 files changed, 197 insertions(+), 265 deletions(-) create mode 100644 .eslintrc.cjs delete mode 100644 .eslintrc.js create mode 100644 .github/workflows/pr-lint.yaml create mode 100644 .nvmrc diff --git a/.eslintrc.cjs b/.eslintrc.cjs new file mode 100644 index 0000000..dcdfe2e --- /dev/null +++ b/.eslintrc.cjs @@ -0,0 +1,11 @@ +module.exports = { + extends: './node_modules/@restorecommerce/dev/.eslintrc.cjs', + parserOptions: { + project: [ + 'tsconfig.json', + ], + }, + rules: { + '@typescript-eslint/consistent-type-imports': 0 + } +}; diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 2376c0d..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1,81 +0,0 @@ -module.exports = { - "env": { - "browser": false, - "es6": true, - "node": true - }, - "parser": "@typescript-eslint/parser", - "parserOptions": { - "project": [ - "tsconfig.json", - "tsconfig.test.json" - ], - "sourceType": "module" - }, - "plugins": [ - "@typescript-eslint", - "@typescript-eslint/eslint-plugin", - "prefer-arrow-functions" - ], - "rules": { - "@typescript-eslint/adjacent-overload-signatures": "error", - "@typescript-eslint/no-floating-promises": "error", - "@typescript-eslint/naming-convention": [ - "error", - { - "selector": "class", - "format": ["PascalCase"] - }, - { - "selector": "interface", - "format": ["PascalCase"] - } - ], - "@typescript-eslint/indent": ["error", 2], - "@typescript-eslint/member-delimiter-style": [ - "error", - { - "multiline": { - "delimiter": "semi", - "requireLast": true - }, - "singleline": { - "delimiter": "semi", - "requireLast": false - } - } - ], - "@typescript-eslint/no-inferrable-types": "error", - "@typescript-eslint/no-use-before-define": [2, {"functions": true, "classes": true}], - "@typescript-eslint/prefer-namespace-keyword": "error", - "@typescript-eslint/semi": [ - "error", - "always" - ], - "@typescript-eslint/type-annotation-spacing": "error", - "arrow-parens": [ - "off", - "as-needed" - ], - "capitalized-comments": 0, - "quotes": ["error", "single", { "allowTemplateLiterals": true }], - "no-trailing-spaces": "error", - "no-var": "error", - "object-shorthand": "error", - "prefer-arrow-functions/prefer-arrow-functions": [ - "warn", - { - "classPropertiesAllowed": false, - "disallowPrototype": false, - "returnStyle": "unchanged", - "singleReturnOnly": false - } - ], - "prefer-arrow-callback": "error", - "quote-props": [ - "error", - "as-needed" - ], - "spaced-comment": "error" - } - }; diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 6870e80..ad47c09 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -4,15 +4,13 @@ on: push jobs: build: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - - name: Checkout - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - - name: Setup NodeJS - uses: actions/setup-node@v1 + - uses: actions/setup-node@v4 with: - node-version: '20.8.0' + node-version-file: '.nvmrc' - name: Install Dependencies run: npm ci @@ -21,19 +19,16 @@ jobs: run: npm run build test: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 needs: build steps: - - name: Checkout - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - - name: Setup NodeJS - uses: actions/setup-node@v1 + - uses: actions/setup-node@v4 with: - node-version: '20.8.0' + node-version-file: '.nvmrc' - - name: Setup System - uses: restorecommerce/setup-system-action@v1 + - uses: restorecommerce/setup-system-action@v1 - name: Install Dependencies run: npm ci @@ -41,20 +36,17 @@ jobs: - name: Test run: npm run test && npm run lcov-report - - name: Coveralls - uses: coverallsapp/github-action@master + - uses: coverallsapp/github-action@master with: github-token: ${{ secrets.GITHUB_TOKEN }} image: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 needs: build steps: - - name: Checkout - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - - name: Setup buildx - uses: docker/setup-buildx-action@v1 + - uses: docker/setup-buildx-action@v3 - name: Set variables id: vars @@ -62,13 +54,9 @@ jobs: echo ::set-output name=version_tag::$(echo ${GITHUB_REF#refs/*/}) echo ::set-output name=repo_name::$(echo ${GITHUB_REPOSITORY#*/*}) - - name: Build - uses: docker/build-push-action@v2 + - uses: docker/build-push-action@v5 with: - context: . - file: ./Dockerfile platforms: linux/amd64 - push: false build-args: | APP_HOME=/home/node/${{ steps.vars.outputs.repo_name }} cache-from: | diff --git a/.github/workflows/pr-lint.yaml b/.github/workflows/pr-lint.yaml new file mode 100644 index 0000000..1e6aa17 --- /dev/null +++ b/.github/workflows/pr-lint.yaml @@ -0,0 +1,20 @@ +name: "Lint PR" + +on: + pull_request_target: + types: + - opened + - edited + - synchronize + +permissions: + pull-requests: read + +jobs: + main: + name: pr-lint + runs-on: ubuntu-latest + steps: + - uses: amannn/action-semantic-pull-request@v5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index a0ec5a0..ab841f2 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,31 +1,35 @@ -name: release +name: Release on: push: - tags: - - v* + branches: + - master + +permissions: + contents: read jobs: release: - runs-on: ubuntu-20.04 + permissions: + contents: write + issues: write + pull-requests: write + runs-on: ubuntu-22.04 steps: - - name: Checkout - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - - name: Login to DockerHub - uses: docker/login-action@v1 + - uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Login to GitHub Container Registry - uses: docker/login-action@v1 + - uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.CR_PAT }} - - uses: docker/setup-buildx-action@v1 + - uses: docker/setup-buildx-action@v3 with: install: true @@ -34,28 +38,26 @@ jobs: run: | echo ::set-output name=repo_name::$(echo ${GITHUB_REPOSITORY#*/*}) - - name: Docker meta + - uses: docker/metadata-action@v5 id: docker_meta - uses: crazy-max/ghaction-docker-meta@v1 with: - images: | - ${{ github.repository }} - ghcr.io/${{ github.repository }} - tag-sha: true - tag-semver: | - {{version}} - {{major}}.{{minor}} - - - name: Build and push - uses: docker/build-push-action@v2 + images: ${{ github.repository }} + + - uses: docker/build-push-action@v5 with: - context: . - file: ./Dockerfile - platforms: linux/amd64 - push: true + load: true build-args: | APP_HOME=/home/node/${{ steps.vars.outputs.repo_name }} - cache-from: | - ${{ github.repository }}:latest - tags: ${{ steps.docker_meta.outputs.tags }} + tags: ${{ github.repository }} labels: ${{ steps.docker_meta.outputs.labels }} + + - uses: actions/setup-node@v4 + with: + node-version-file: '.nvmrc' + + - name: Install Dependencies + run: npm clean-install + + - run: npx semantic-release@22.0.12 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.mocharc.json b/.mocharc.json index 8e40263..0112f4f 100644 --- a/.mocharc.json +++ b/.mocharc.json @@ -1,5 +1,9 @@ { "extension": ["ts"], "spec": "test/**/*.spec.ts", - "require": "ts-node/register" + "require": "ts-node/register", + "node-option": [ + "experimental-specifier-resolution=node", + "loader=ts-node/esm" + ] } diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..ba17e93 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +20.8 \ No newline at end of file diff --git a/package.json b/package.json index 1985b14..d4c4c33 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "cross-fetch": "^4.0.0", "graphql-tag": "^2.12.6", "js-yaml": "^4.1.0", - "lodash": "^4.17.21", + "lodash-es": "^4.17.21", "node-eval": "^2.0.0", "traverse": "^0.6.8" }, @@ -40,7 +40,7 @@ "@alenon/grpc-mock-server": "^3.1.9", "@grpc/proto-loader": "^0.7.10", "@restorecommerce/protos": "^6.7.0", - "@types/lodash": "^4.14.202", + "@types/lodash-es": "^4.17.12", "@types/mocha": "^10.0.6", "@types/nock": "^11.1.0", "@types/node": "^20.11.17", @@ -60,11 +60,12 @@ "should": "^13.2.3", "ts-node": "^10.9.2", "tslint": "^6.1.3", - "typescript": "^5.3.3" + "typescript": "^5.3.3", + "esbuild": "^0.20.0" }, "scripts": { "start": "node lib/start.js", - "dev": "cross-env NODE_ENV=development nodemon --watch './src/**/*.ts' --exec 'ts-node' src/start.ts", + "dev": "cross-env NODE_ENV=development nodemon --watch './src/**/*.ts' --exec node --loader ts-node/esm ./src/start.ts", "test": "npm run build && npm run lint && nyc npm run mocha", "lint": "eslint src --ext .ts", "mocha": "cross-env NODE_ENV=test mocha --full-trace --exit --timeout 120000", @@ -73,11 +74,13 @@ "lcov-report": "nyc report --reporter=lcov", "coveralls": "nyc report --reporter=text-lcov | coveralls", "tsctests": "tsc -d -p tsconfig.test.json", - "build:tsc": "tsc -d", + "build:tsc": "esbuild ./src/start.ts --bundle --platform=node --outfile=lib/start.js --minify --tree-shaking=true --sourcemap=inline", + "build:jobs": "find ./src/jobs -maxdepth 1 -type f -exec bash -c 'esbuild {} --bundle --platform=node --outfile=lib/jobs/$(basename {} .ts).js --minify --tree-shaking=true --sourcemap=inline' \\;", "build:clean": "rimraf lib", - "build": "npm-run-all lint build:clean build:tsc" + "build": "npm-run-all lint build:clean build:tsc build:jobs" }, "engines": { - "node": ">= 18.0.0" - } + "node": ">= 20.8.0" + }, + "type": "module" } diff --git a/src/accessControlService.ts b/src/accessControlService.ts index e266ba7..65a847b 100644 --- a/src/accessControlService.ts +++ b/src/accessControlService.ts @@ -1,21 +1,21 @@ -import * as _ from 'lodash'; +import * as _ from 'lodash-es'; import { Server } from '@restorecommerce/chassis-srv'; import { Events } from '@restorecommerce/kafka-client'; import { CommandInterface } from '@restorecommerce/chassis-srv'; -import { ResourceManager } from './resourceManager'; +import { ResourceManager } from './resourceManager.js'; import { RedisClientType } from 'redis'; -import * as core from './core'; +import * as core from './core.js'; import { Logger } from 'winston'; import { AccessControlServiceImplementation, ReverseQuery, Request, Response, DeepPartial, Response_Decision -} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/access_control'; +} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/access_control.js'; import { CommandInterfaceServiceImplementation -} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/commandinterface'; -import { PolicySetWithCombinables } from './core/interfaces'; +} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/commandinterface.js'; +import { PolicySetWithCombinables } from './core/interfaces.js'; export class AccessControlService implements AccessControlServiceImplementation { cfg: any; diff --git a/src/core/accessController.ts b/src/core/accessController.ts index ea08eac..c8f13f9 100644 --- a/src/core/accessController.ts +++ b/src/core/accessController.ts @@ -1,24 +1,26 @@ -import * as _ from 'lodash'; -import { PolicySetWithCombinables, PolicyWithCombinables, AccessControlOperation } from './interfaces'; -import { CombiningAlgorithm, AccessControlConfiguration, EffectEvaluation, ContextWithSubResolved } from './interfaces'; -import { Request, Response, Response_Decision, ReverseQuery } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/access_control'; -import { Rule, RuleRQ, ContextQuery, Effect, Target } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/rule'; -import { Policy, PolicyRQ } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/policy'; -import { PolicySetRQ } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/policy_set'; -import { Attribute } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/attribute'; -import { HierarchicalScope } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/auth'; +import * as _ from 'lodash-es'; +import { + PolicySetWithCombinables, PolicyWithCombinables, AccessControlOperation, + CombiningAlgorithm, AccessControlConfiguration, EffectEvaluation, ContextWithSubResolved +} from './interfaces.js'; +import { Request, Response, Response_Decision, ReverseQuery } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/access_control.js'; +import { Rule, RuleRQ, ContextQuery, Effect, Target } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/rule.js'; +import { Policy, PolicyRQ } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/policy.js'; +import { PolicySetRQ } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/policy_set.js'; +import { Attribute } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/attribute.js'; +import { HierarchicalScope } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/auth.js'; import { UserServiceClient -} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/user'; +} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/user.js'; -import { ResourceAdapter, GraphQLAdapter } from './resource_adapters'; -import * as errors from './errors'; -import { checkHierarchicalScope } from './hierarchicalScope'; +import { ResourceAdapter, GraphQLAdapter } from './resource_adapters.js'; +import * as errors from './errors.js'; +import { checkHierarchicalScope } from './hierarchicalScope.js'; import { Logger } from 'winston'; import { createClient, RedisClientType } from 'redis'; import { Topic } from '@restorecommerce/kafka-client'; -import { verifyACLList } from './verifyACL'; -import { conditionMatches } from './utils'; +import { verifyACLList } from './verifyACL.js'; +import { conditionMatches } from './utils.js'; export class AccessController { policySets: Map; diff --git a/src/core/hierarchicalScope.ts b/src/core/hierarchicalScope.ts index 5428282..39e828a 100644 --- a/src/core/hierarchicalScope.ts +++ b/src/core/hierarchicalScope.ts @@ -1,12 +1,12 @@ -import * as _ from 'lodash'; +import * as _ from 'lodash-es'; import traverse from 'traverse'; import { Logger } from 'winston'; import { AccessController } from '.'; -import { Request } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/access_control'; -import { Target } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/rule'; -import { Attribute } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/attribute'; -import { Resource, ContextWithSubResolved } from './interfaces'; -import { getAllValues, updateScopedRoles } from './utils'; +import { Request } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/access_control.js'; +import { Target } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/rule.js'; +import { Attribute } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/attribute.js'; +import { Resource, ContextWithSubResolved } from './interfaces.js'; +import { getAllValues, updateScopedRoles } from './utils.js'; export const checkHierarchicalScope = async (ruleTarget: Target, request: Request, urns: Map, accessController: AccessController, logger?: Logger): Promise => { diff --git a/src/core/index.ts b/src/core/index.ts index bd0f82c..a747258 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -1,8 +1,8 @@ -import { AccessController } from './accessController'; +import { AccessController } from './accessController.js'; export { AccessController }; -import { InvalidRequest } from './errors'; +import { InvalidRequest } from './errors.js'; export { InvalidRequest }; -import * as utils from './utils'; +import * as utils from './utils.js'; export { utils }; diff --git a/src/core/interfaces.ts b/src/core/interfaces.ts index 31ab3b1..40d0403 100644 --- a/src/core/interfaces.ts +++ b/src/core/interfaces.ts @@ -1,8 +1,8 @@ -import { Effect, Rule } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/rule'; -import { Policy } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/policy'; -import { PolicySet } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/policy_set'; -import { Attribute } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/attribute'; -import { RoleAssociation as RoleAssociations, HierarchicalScope, Tokens } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/auth'; +import { Effect, Rule } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/rule.js'; +import { Policy } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/policy.js'; +import { PolicySet } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/policy_set.js'; +import { Attribute } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/attribute.js'; +import { RoleAssociation as RoleAssociations, HierarchicalScope, Tokens } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/auth.js'; export interface PolicyWithCombinables extends Policy { combinables: Map; diff --git a/src/core/resource_adapters/adapter.ts b/src/core/resource_adapters/adapter.ts index 61c5788..0527186 100644 --- a/src/core/resource_adapters/adapter.ts +++ b/src/core/resource_adapters/adapter.ts @@ -1,4 +1,4 @@ -import { ContextQuery } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/rule'; +import { ContextQuery } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/rule.js'; export interface ResourceAdapter { query(contextQuery: ContextQuery, context: any): Promise; diff --git a/src/core/resource_adapters/gql.ts b/src/core/resource_adapters/gql.ts index a9426ef..df4b36d 100644 --- a/src/core/resource_adapters/gql.ts +++ b/src/core/resource_adapters/gql.ts @@ -1,12 +1,12 @@ -import { ResourceAdapter, QueryResult } from './adapter'; +import { ResourceAdapter, QueryResult } from './adapter.js'; import { ApolloClient } from 'apollo-client'; import gql from 'graphql-tag'; import { InMemoryCache } from 'apollo-cache-inmemory'; import { HttpLink } from 'apollo-link-http'; -import * as _ from 'lodash'; -import { ContextQuery } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/rule'; -import { Request } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/access_control'; -import * as errors from '../errors'; +import * as _ from 'lodash-es'; +import { ContextQuery } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/rule.js'; +import { Request } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/access_control.js'; +import * as errors from '../errors.js'; import fetch from 'cross-fetch'; export class GraphQLAdapter implements ResourceAdapter { diff --git a/src/core/resource_adapters/index.ts b/src/core/resource_adapters/index.ts index 0b673a0..fb0cf59 100644 --- a/src/core/resource_adapters/index.ts +++ b/src/core/resource_adapters/index.ts @@ -1,4 +1,4 @@ -import { ResourceAdapter } from './adapter'; -import { GraphQLAdapter } from './gql'; +import { ResourceAdapter } from './adapter.js'; +import { GraphQLAdapter } from './gql.js'; export { ResourceAdapter, GraphQLAdapter }; diff --git a/src/core/utils.ts b/src/core/utils.ts index 7372590..4f02dfe 100644 --- a/src/core/utils.ts +++ b/src/core/utils.ts @@ -1,24 +1,24 @@ import * as _ from 'lodash'; -import * as fs from 'fs'; +import * as fs from 'node:fs'; import * as yaml from 'js-yaml'; -import { AccessController } from './accessController'; +import { AccessController } from './accessController.js'; import { AuthZAction, accessRequest, PolicySetRQ, DecisionResponse, Operation, PolicySetRQResponse, Obligation, ACSClientContext, Resource } from '@restorecommerce/acs-client'; -import { Subject } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/auth'; -import { Response_Decision } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/access_control'; +import { Subject } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/auth.js'; +import { Response_Decision } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/access_control.js'; import { createServiceConfig } from '@restorecommerce/service-config'; import { createLogger } from '@restorecommerce/logger'; import { createClient, createChannel } from '@restorecommerce/grpc-client'; -import { FilterOp } from '@restorecommerce/resource-base-interface/lib/core/interfaces'; +import { FilterOp } from '@restorecommerce/resource-base-interface/lib/core/interfaces.js'; import * as uuid from 'uuid'; import nodeEval from 'node-eval'; -import { Request } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/access_control'; -import { Rule, Target, Effect } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/rule'; +import { Request } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/access_control.js'; +import { Rule, Target, Effect } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/rule.js'; import { UserServiceDefinition, UserServiceClient -} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/user'; -import { PolicySetWithCombinables, PolicyWithCombinables } from './interfaces'; -import { RoleAssociation } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/auth'; +} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/user.js'; +import { PolicySetWithCombinables, PolicyWithCombinables } from './interfaces.js'; +import { RoleAssociation } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/auth.js'; import { Topic } from '@restorecommerce/kafka-client'; diff --git a/src/core/verifyACL.ts b/src/core/verifyACL.ts index 66e559a..047a972 100644 --- a/src/core/verifyACL.ts +++ b/src/core/verifyACL.ts @@ -1,12 +1,12 @@ -import * as _ from 'lodash'; +import * as _ from 'lodash-es'; import { Logger } from 'winston'; -import { Request } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/access_control'; -import { Target } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/rule'; -import { Attribute } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/attribute'; +import { Request } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/access_control.js'; +import { Target } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/rule.js'; +import { Attribute } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/attribute.js'; import { AccessController } from '.'; -import { Resource, ContextWithSubResolved } from './interfaces'; +import { Resource, ContextWithSubResolved } from './interfaces.js'; import traverse from 'traverse'; -import { getAllValues } from './utils'; +import { getAllValues } from './utils.js'; export const verifyACLList = async (ruleTarget: Target, request: Request, urns: Map, accessController: AccessController, logger?: Logger): Promise => { diff --git a/src/resourceManager.ts b/src/resourceManager.ts index 4f4a667..88740a4 100644 --- a/src/resourceManager.ts +++ b/src/resourceManager.ts @@ -1,28 +1,28 @@ -import * as _ from 'lodash'; +import * as _ from 'lodash-es'; import { ResourcesAPIBase, ServiceBase, FilterOperation } from '@restorecommerce/resource-base-interface'; import { Topic, Events } from '@restorecommerce/kafka-client'; -import * as core from './core'; -import { createMetadata, checkAccessRequest } from './core/utils'; +import * as core from './core.js'; +import { createMetadata, checkAccessRequest } from './core/utils.js'; import { AuthZAction, Operation, ACSAuthZ, DecisionResponse, PolicySetRQResponse } from '@restorecommerce/acs-client'; import { RedisClientType } from 'redis'; import { Logger } from 'winston'; import { Response_Decision -} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/access_control'; +} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/access_control.js'; import { PolicySetServiceImplementation, - PolicySetList, PolicySetListResponse, PolicySet, PolicySetResponse -} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/policy_set'; + PolicySetList, PolicySetListResponse, PolicySet +} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/policy_set.js'; import { PolicyServiceImplementation, PolicyList, PolicyListResponse, Policy -} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/policy'; +} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/policy.js'; import { RuleServiceImplementation, RuleList, RuleListResponse, Rule -} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/rule'; -import { ReadRequest, Filter_Operation, DeepPartial, DeleteRequest, DeleteResponse } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/resource_base'; -import { PolicyWithCombinables, PolicySetWithCombinables } from './core/interfaces'; +} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/rule.js'; +import { ReadRequest, Filter_Operation, DeepPartial, DeleteRequest, DeleteResponse } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/resource_base.js'; +import { PolicyWithCombinables, PolicySetWithCombinables } from './core/interfaces.js'; export interface IAccessControlResourceService { diff --git a/src/start.ts b/src/start.ts index 5ac9b3d..7ba4299 100644 --- a/src/start.ts +++ b/src/start.ts @@ -1,9 +1,15 @@ -import Cluster from '@restorecommerce/cluster-service'; -import { createServiceConfig } from '@restorecommerce/service-config'; +import { Worker } from './worker.js'; -const cfg = createServiceConfig(process.cwd()); -const server = new Cluster(cfg); -server.run('./lib/worker'); -process.on('SIGINT', () => { - server.stop(); +const worker = new Worker(); +const logger = worker.logger; +worker.start().then().catch((err) => { + logger.error('startup error', err); + process.exit(1); }); + +process.on('SIGINT', () => { + worker.stop().then().catch((err) => { + logger.error('shutdown error', err); + process.exit(1); + }); +}); \ No newline at end of file diff --git a/src/worker.ts b/src/worker.ts index c2fa31e..0389bab 100644 --- a/src/worker.ts +++ b/src/worker.ts @@ -1,52 +1,52 @@ -import * as _ from 'lodash'; +import * as _ from 'lodash-es'; import * as chassis from '@restorecommerce/chassis-srv'; import { createLogger } from '@restorecommerce/logger'; import { Logger } from 'winston'; import { Events, registerProtoMeta } from '@restorecommerce/kafka-client'; -import { AccessControlCommandInterface, AccessControlService } from './accessControlService'; -import { ResourceManager } from './resourceManager'; +import { AccessControlCommandInterface, AccessControlService } from './accessControlService.js'; +import { ResourceManager } from './resourceManager.js'; import { createClient, RedisClientType } from 'redis'; -import { Arango } from '@restorecommerce/chassis-srv/lib/database/provider/arango/base'; +import { Arango } from '@restorecommerce/chassis-srv/lib/database/provider/arango/base.js'; import * as core from './core'; import { ACSAuthZ, initAuthZ, initializeCache } from '@restorecommerce/acs-client'; import { createChannel, createClient as grpcCreateClient } from '@restorecommerce/grpc-client'; import { FindByTokenRequest, UserServiceClient, UserServiceDefinition -} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/user'; +} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/user.js'; import { RoleAssociation -} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/auth'; +} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/auth.js'; import { RuleServiceDefinition, protoMetadata as ruleMeta -} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/rule'; +} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/rule.js'; import { PolicyServiceDefinition, protoMetadata as policyMeta -} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/policy'; +} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/policy.js'; import { PolicySetServiceDefinition, protoMetadata as policySetMeta -} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/policy_set'; +} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/policy_set.js'; import { AccessControlServiceDefinition, protoMetadata as accessControlMeta -} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/access_control'; +} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/access_control.js'; import { CommandInterfaceServiceDefinition, protoMetadata as commandInterfaceMeta -} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/commandinterface'; -import { protoMetadata as reflectionMeta } from '@restorecommerce/rc-grpc-clients/dist/generated-server/grpc/reflection/v1alpha/reflection'; -import { protoMetadata as authMeta } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/auth'; +} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/commandinterface.js'; +import { protoMetadata as reflectionMeta } from '@restorecommerce/rc-grpc-clients/dist/generated-server/grpc/reflection/v1alpha/reflection.js'; +import { protoMetadata as authMeta } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/auth.js'; import { protoMetadata as userMeta -} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/user'; +} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/user.js'; import { HealthDefinition -} from '@restorecommerce/rc-grpc-clients/dist/generated-server/grpc/health/v1/health'; -import { BindConfig } from '@restorecommerce/chassis-srv/lib/microservice/transport/provider/grpc'; -import { compareRoleAssociations, flushACSCache } from './core/utils'; +} from '@restorecommerce/rc-grpc-clients/dist/generated-server/grpc/health/v1/health.js'; +import { BindConfig } from '@restorecommerce/chassis-srv/lib/microservice/transport/provider/grpc.js'; +import { compareRoleAssociations, flushACSCache } from './core/utils.js'; const capitalized = (collectionName: string): string => { const labels = collectionName.split('_').map((element) => { diff --git a/tsconfig.json b/tsconfig.json index 5c4d66e..ce4c8d9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,29 +1,5 @@ { - "compilerOptions": { - "target": "ES2021", - "module": "commonjs", - "incremental": true, - "diagnostics": false, - "moduleResolution": "node", - "declaration": true, - // "strict": true, - "downlevelIteration": true, - "emitDecoratorMetadata": true, - "experimentalDecorators": true, - "allowSyntheticDefaultImports": true, - "noUnusedLocals": false, - "skipLibCheck": true, - "esModuleInterop": true, - "sourceMap": true, - "outDir": "lib", - "typeRoots": [ - "node_modules/@types" - ], - "lib": [ - "es2020.promise", - "dom" - ] - }, + "extends": "./node_modules/@restorecommerce/dev/tsconfig.json", "include": [ "./src/**/*.ts" ], @@ -32,4 +8,4 @@ "lib", "doc" ] -} +} \ No newline at end of file