├── .eslintrc.js ├── .github └── workflows │ ├── check-version.yaml │ ├── publish.yaml │ ├── release-rc.yaml │ ├── release.yaml │ └── test.yaml ├── .gitignore ├── .licensee.json ├── .npmignore ├── .prettierignore ├── .prettierrc.js ├── CHANGELOG.md ├── LICENSE ├── README.md ├── assets ├── license_header.txt └── nitric-logo.svg ├── jest.config.ts ├── licenseconfig.json ├── package.json ├── scripts └── check-nitric-version.ts ├── src ├── api │ ├── batch │ │ └── v1 │ │ │ ├── batch.ts │ │ │ ├── index.ts │ │ │ ├── job.test.ts │ │ │ └── job.ts │ ├── errors │ │ ├── index.test.ts │ │ ├── index.ts │ │ └── provider-error.ts │ ├── index.ts │ ├── keyvalue │ │ ├── index.ts │ │ └── v1 │ │ │ ├── index.ts │ │ │ ├── keyvalue.test.ts │ │ │ ├── keyvalue.ts │ │ │ └── store.ts │ ├── queues │ │ ├── index.ts │ │ └── v1 │ │ │ ├── index.ts │ │ │ ├── queues.test.ts │ │ │ └── queues.ts │ ├── secrets │ │ ├── index.ts │ │ └── v1 │ │ │ ├── index.ts │ │ │ ├── secret.test.ts │ │ │ └── secrets.ts │ ├── storage │ │ ├── index.ts │ │ └── v1 │ │ │ ├── index.ts │ │ │ ├── storage.test.ts │ │ │ └── storage.ts │ ├── topics │ │ ├── index.ts │ │ └── v1 │ │ │ ├── index.ts │ │ │ ├── topics.test.ts │ │ │ └── topics.ts │ └── websocket │ │ ├── index.ts │ │ └── v1 │ │ ├── index.ts │ │ └── websocket.ts ├── constants.ts ├── context │ ├── base.ts │ ├── bucket.ts │ ├── http.ts │ ├── index.ts │ ├── interval.ts │ ├── job.ts │ ├── message.ts │ └── websocket.ts ├── gen │ └── nitric │ │ └── proto │ │ ├── apis │ │ └── v1 │ │ │ ├── apis_grpc_pb.d.ts │ │ │ ├── apis_grpc_pb.js │ │ │ ├── apis_pb.d.ts │ │ │ └── apis_pb.js │ │ ├── batch │ │ └── v1 │ │ │ ├── batch_grpc_pb.d.ts │ │ │ ├── batch_grpc_pb.js │ │ │ ├── batch_pb.d.ts │ │ │ └── batch_pb.js │ │ ├── deployments │ │ └── v1 │ │ │ ├── deployments_grpc_pb.d.ts │ │ │ ├── deployments_grpc_pb.js │ │ │ ├── deployments_pb.d.ts │ │ │ └── deployments_pb.js │ │ ├── http │ │ └── v1 │ │ │ ├── http_grpc_pb.d.ts │ │ │ ├── http_grpc_pb.js │ │ │ ├── http_pb.d.ts │ │ │ └── http_pb.js │ │ ├── keyvalue │ │ └── v1 │ │ │ ├── keyvalue_grpc_pb.d.ts │ │ │ ├── keyvalue_grpc_pb.js │ │ │ ├── keyvalue_pb.d.ts │ │ │ └── keyvalue_pb.js │ │ ├── kvstore │ │ └── v1 │ │ │ ├── kvstore_grpc_pb.d.ts │ │ │ ├── kvstore_grpc_pb.js │ │ │ ├── kvstore_pb.d.ts │ │ │ └── kvstore_pb.js │ │ ├── queues │ │ └── v1 │ │ │ ├── queues_grpc_pb.d.ts │ │ │ ├── queues_grpc_pb.js │ │ │ ├── queues_pb.d.ts │ │ │ └── queues_pb.js │ │ ├── resources │ │ └── v1 │ │ │ ├── resources_grpc_pb.d.ts │ │ │ ├── resources_grpc_pb.js │ │ │ ├── resources_pb.d.ts │ │ │ └── resources_pb.js │ │ ├── schedules │ │ └── v1 │ │ │ ├── schedules_grpc_pb.d.ts │ │ │ ├── schedules_grpc_pb.js │ │ │ ├── schedules_pb.d.ts │ │ │ └── schedules_pb.js │ │ ├── secrets │ │ └── v1 │ │ │ ├── secrets_grpc_pb.d.ts │ │ │ ├── secrets_grpc_pb.js │ │ │ ├── secrets_pb.d.ts │ │ │ └── secrets_pb.js │ │ ├── sql │ │ └── v1 │ │ │ ├── sql_grpc_pb.d.ts │ │ │ ├── sql_grpc_pb.js │ │ │ ├── sql_pb.d.ts │ │ │ └── sql_pb.js │ │ ├── storage │ │ └── v1 │ │ │ ├── storage_grpc_pb.d.ts │ │ │ ├── storage_grpc_pb.js │ │ │ ├── storage_pb.d.ts │ │ │ └── storage_pb.js │ │ ├── topics │ │ └── v1 │ │ │ ├── topics_grpc_pb.d.ts │ │ │ ├── topics_grpc_pb.js │ │ │ ├── topics_pb.d.ts │ │ │ └── topics_pb.js │ │ └── websockets │ │ └── v1 │ │ ├── websockets_grpc_pb.d.ts │ │ ├── websockets_grpc_pb.js │ │ ├── websockets_pb.d.ts │ │ └── websockets_pb.js ├── handlers │ ├── handler.test.ts │ ├── handler.ts │ ├── index.ts │ └── json.ts ├── index.ts ├── lifecycle │ ├── index.ts │ └── lifecycle.ts ├── resources │ ├── api.test.ts │ ├── api.ts │ ├── batch.test.ts │ ├── batch.ts │ ├── bucket.test.ts │ ├── bucket.ts │ ├── client.ts │ ├── common.test.ts │ ├── common.ts │ ├── http.test.ts │ ├── http.ts │ ├── index.ts │ ├── keyvalue.test.ts │ ├── keyvalue.ts │ ├── oidc.ts │ ├── queue.test.ts │ ├── queue.ts │ ├── schedule.test.ts │ ├── schedule.ts │ ├── secret.test.ts │ ├── secret.ts │ ├── sql.ts │ ├── topic.test.ts │ ├── topic.ts │ ├── websocket.test.ts │ └── websocket.ts └── types.ts ├── tsconfig.json └── yarn.lock /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: '@typescript-eslint/parser', 3 | ignorePatterns: ['src/gen/**/*.ts', 'src/**/*.test.ts'], 4 | env: { 5 | node: true, 6 | }, 7 | plugins: ['jsdoc'], 8 | extends: [ 9 | 'plugin:@typescript-eslint/eslint-recommended', 10 | 'plugin:@typescript-eslint/recommended', 11 | 'plugin:jsdoc/recommended-typescript-error', 12 | ], 13 | rules: { 14 | '@typescript-eslint/explicit-function-return-type': 'off', 15 | '@typescript-eslint/ban-ts-ignore': 'off', 16 | '@typescript-eslint/no-explicit-any': 'off', 17 | 'jsdoc/tag-lines': 'off', // not documented on jsdoc plugin site, unsure how to correct. 18 | '@typescript-eslint/no-unused-vars': [ 19 | 'error', 20 | { args: 'all', argsIgnorePattern: '^_' }, 21 | ], 22 | 'no-warning-comments': [ 23 | 'error', 24 | { 25 | terms: ['todo', 'fixme'], 26 | location: 'anywhere', 27 | }, 28 | ], 29 | }, 30 | }; 31 | -------------------------------------------------------------------------------- /.github/workflows/check-version.yaml: -------------------------------------------------------------------------------- 1 | name: Check Nitric Version 2 | 3 | on: 4 | pull_request: 5 | branches: 6 | - main 7 | 8 | jobs: 9 | build: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Checkout 13 | uses: actions/checkout@v2 14 | - name: Cache Yarn Cache 15 | uses: actions/cache@v4 16 | with: 17 | path: 'node_modules' 18 | key: ${{ runner.os }}-modules-${{ hashFiles('yarn.lock') }} 19 | - name: Install modules 20 | run: yarn --frozen-lockfile 21 | - name: Check nitric version 22 | run: yarn check-nitric 23 | -------------------------------------------------------------------------------- /.github/workflows/publish.yaml: -------------------------------------------------------------------------------- 1 | name: Publish to NPM on Github Release 2 | 3 | on: 4 | release: 5 | types: [published] 6 | 7 | jobs: 8 | publish: 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - name: Checkout 13 | uses: actions/checkout@v2 14 | with: 15 | token: ${{ secrets.NITRIC_BOT_TOKEN }} 16 | 17 | - name: Cache Dependencies 18 | uses: actions/cache@v4 19 | with: 20 | path: 'node_modules' 21 | key: ${{ runner.os }}-modules-${{ hashFiles('yarn.lock') }} 22 | 23 | - name: Use Node 20 24 | uses: actions/setup-node@v1 25 | with: 26 | node-version: 20 27 | registry-url: 'https://registry.npmjs.org' 28 | always-auth: true 29 | 30 | - name: Git Identity 31 | run: | 32 | git config --global user.name 'nitric-bot[bot]' 33 | git config --global user.email 'maintainers@nitric.io' 34 | 35 | - name: Set Version 36 | # Tag will already be created by release flow 37 | run: npm version --no-git-tag-version ${{ github.event.release.tag_name }} 38 | 39 | - name: Install Dependencies 40 | run: yarn install --frozen-lockfile 41 | 42 | - name: Build 43 | run: yarn build 44 | 45 | - name: Publish latest to NPM 46 | if: '!github.event.release.prerelease' 47 | run: npm publish --access public 48 | env: 49 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 50 | 51 | - name: Publish latest RC to NPM 52 | if: 'github.event.release.prerelease' 53 | run: npm publish --access public --tag rc-latest 54 | env: 55 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 56 | -------------------------------------------------------------------------------- /.github/workflows/release-rc.yaml: -------------------------------------------------------------------------------- 1 | name: Release Candidate 2 | on: 3 | push: 4 | branches: 5 | - develop 6 | 7 | jobs: 8 | # Bump the membrane version 9 | version_bump: 10 | name: Bump Version and Create Release 11 | runs-on: ubuntu-latest 12 | outputs: 13 | version_id: ${{ steps.tag_version.outputs.new_tag }} 14 | upload_url: ${{ steps.create_release.outputs.upload_url }} 15 | steps: 16 | - uses: actions/checkout@v2 17 | with: 18 | fetch-depth: 0 19 | - name: Bump version and push tag 20 | id: tag_version 21 | uses: mathieudutour/github-tag-action@v5.5 22 | with: 23 | # Don't commit tag 24 | # this will be done as part of the release 25 | dry_run: true 26 | github_token: ${{ secrets.GITHUB_TOKEN }} 27 | release_branches: main,develop 28 | 29 | - name: Calculate RC number 30 | id: vars 31 | run: echo "::set-output name=rc_num::$(git rev-list --merges --count origin/develop...origin/main)" 32 | 33 | - name: Create a GitHub release 34 | id: create_release 35 | uses: actions/create-release@v1 36 | env: 37 | # Use NITRIC_BOT_TOKEN here to 38 | # trigger release 'published' workflows 39 | GITHUB_TOKEN: ${{ secrets.NITRIC_BOT_TOKEN }} 40 | with: 41 | prerelease: true 42 | tag_name: ${{ steps.tag_version.outputs.new_tag }}-rc.${{ steps.vars.outputs.rc_num }} 43 | release_name: Release ${{ steps.tag_version.outputs.new_tag }}-rc.${{ steps.vars.outputs.rc_num }} 44 | body: ${{ steps.tag_version.outputs.changelog }}-rc.${{ steps.vars.outputs.rc_num }} -------------------------------------------------------------------------------- /.github/workflows/release.yaml: -------------------------------------------------------------------------------- 1 | name: Production Release 2 | on: 3 | push: 4 | branches: 5 | - main 6 | jobs: 7 | # Bump the membrane version 8 | version_bump: 9 | name: Bump Version and Create Release 10 | runs-on: ubuntu-latest 11 | outputs: 12 | version_id: ${{ steps.tag_version.outputs.new_tag }} 13 | upload_url: ${{ steps.create_release.outputs.upload_url }} 14 | steps: 15 | - uses: actions/checkout@v2 16 | - name: Bump version and push tag 17 | id: tag_version 18 | uses: mathieudutour/github-tag-action@v5.5 19 | with: 20 | # Use GITHUB_TOKEN here to prevent further workflows 21 | # generated on 'tag' action 22 | github_token: ${{ secrets.GITHUB_TOKEN }} 23 | - name: Create a GitHub release 24 | id: create_release 25 | uses: actions/create-release@v1 26 | env: 27 | # Use NITRIC_BOT_TOKEN here to 28 | # trigger release 'published' workflows 29 | GITHUB_TOKEN: ${{ secrets.NITRIC_BOT_TOKEN }} 30 | with: 31 | tag_name: ${{ steps.tag_version.outputs.new_tag }} 32 | release_name: Release ${{ steps.tag_version.outputs.new_tag }} 33 | body: ${{ steps.tag_version.outputs.changelog }} -------------------------------------------------------------------------------- /.github/workflows/test.yaml: -------------------------------------------------------------------------------- 1 | name: Tests 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | pull_request: 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - name: Checkout 14 | uses: actions/checkout@v2 15 | - name: Cache Yarn Cache 16 | uses: actions/cache@v4 17 | with: 18 | path: 'node_modules' 19 | key: ${{ runner.os }}-modules-${{ hashFiles('yarn.lock') }} 20 | - name: Install modules 21 | run: yarn --frozen-lockfile 22 | - name: License Header Check 23 | run: yarn license:header:check 24 | - name: OSS License Whitelist Check 25 | run: yarn license:check 26 | - name: Check sources 27 | run: | 28 | yarn gen:proto 29 | git add . 30 | git diff --cached --quiet 31 | - name: Check Formatting 32 | run: yarn prettier:check 33 | - name: Linting 34 | run: yarn lint 35 | - name: Build 36 | run: yarn build 37 | - name: Run tests 38 | run: yarn test:coverage 39 | - name: Upload coverage 40 | uses: codecov/codecov-action@v5 41 | with: 42 | token: ${{ secrets.CODECOV_TOKEN }} 43 | gcov_ignore: './src/gen' 44 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore tmp directory 2 | tmp/ 3 | 4 | # Logs 5 | logs 6 | *.log 7 | npm-debug.log* 8 | yarn-debug.log* 9 | yarn-error.log* 10 | lerna-debug.log* 11 | 12 | # Diagnostic reports (https://nodejs.org/api/report.html) 13 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 14 | 15 | # Runtime data 16 | pids 17 | *.pid 18 | *.seed 19 | *.pid.lock 20 | 21 | # Directory for instrumented libs generated by jscoverage/JSCover 22 | lib-cov 23 | 24 | # Coverage directory used by tools like istanbul 25 | coverage 26 | *.lcov 27 | 28 | # nyc test coverage 29 | .nyc_output 30 | 31 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 32 | .grunt 33 | 34 | # Bower dependency directory (https://bower.io/) 35 | bower_components 36 | 37 | # node-waf configuration 38 | .lock-wscript 39 | 40 | # Compiled binary addons (https://nodejs.org/api/addons.html) 41 | build/Release 42 | 43 | # Dependency directories 44 | node_modules/ 45 | jspm_packages/ 46 | 47 | # TypeScript v1 declaration files 48 | typings/ 49 | 50 | # TypeScript cache 51 | *.tsbuildinfo 52 | 53 | # Optional npm cache directory 54 | .npm 55 | 56 | # Optional eslint cache 57 | .eslintcache 58 | 59 | # Optional REPL history 60 | .node_repl_history 61 | 62 | # Output of 'npm pack' 63 | *.tgz 64 | 65 | # Yarn Integrity file 66 | .yarn-integrity 67 | 68 | # dotenv environment variables file 69 | .env 70 | .env.test 71 | 72 | # parcel-bundler cache (https://parceljs.org/) 73 | .cache 74 | 75 | # next.js build output 76 | .next 77 | 78 | # nuxt.js build output 79 | .nuxt 80 | 81 | # vuepress build output 82 | .vuepress/dist 83 | 84 | # Serverless directories 85 | .serverless/ 86 | 87 | # FuseBox cache 88 | .fusebox/ 89 | 90 | # DynamoDB Local files 91 | .dynamodb/ 92 | 93 | lib/ 94 | 95 | contracts/ 96 | 97 | nitric/** -------------------------------------------------------------------------------- /.licensee.json: -------------------------------------------------------------------------------- 1 | { 2 | "licenses": { 3 | "spdx": [ 4 | "MIT", 5 | "BSD-3-Clause", 6 | "Apache-2.0", 7 | "ISC", 8 | "0BSD" 9 | ] 10 | } 11 | } -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | src/ 2 | contracts/ 3 | .git/ 4 | .github/ 5 | .gitmodules 6 | tests/ 7 | coverage/ 8 | node_modules/ 9 | docs/ 10 | jest.config.json 11 | tsconfig.json 12 | yarn.lock 13 | README.md -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | **/src/gen 2 | -------------------------------------------------------------------------------- /.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | semi: true, 3 | trailingComma: 'es5', 4 | singleQuote: true, 5 | printWidth: 80, 6 | tabWidth: 2, 7 | useTabs: false, 8 | }; 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |
5 |
8 | Build Nitric applications with Node.js 9 |
10 | 11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
extends Resource {
59 | protected abstract permsToActions(...perms: P[]): ActionsList;
60 |
61 | protected registerPolicy(...perms: P[]): void {
62 | const req = new ResourceDeclareRequest();
63 | const policyResource = new ProtoResource();
64 | policyResource.setType(ResourceType.POLICY);
65 |
66 | // Send an unnamed function as the principle. This is interpreted to mean the currently running function, making the request.
67 | const policy = new PolicyResource();
68 | const defaultPrincipal = new ProtoResource();
69 | defaultPrincipal.setType(ResourceType.SERVICE);
70 | policy.setPrincipalsList([defaultPrincipal]);
71 |
72 | // Convert the permissions to an action set.
73 | const actions = this.permsToActions(...perms);
74 | policy.setActionsList(actions);
75 |
76 | req.setId(policyResource);
77 | req.setPolicy(policy);
78 |
79 | this.registerPromise.then((resource) => {
80 | policy.setResourcesList([resource]);
81 |
82 | resourceClient.declare(req, (error) => {
83 | if (error) {
84 | throw fromGrpcError(error);
85 | }
86 | });
87 | });
88 | }
89 | }
90 |
91 | // This singleton helps avoid duplicate references to bucket('name')
92 | // will return the same bucket resource
93 | const cache: Record