@kravc/serverless 0.10.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/build.js CHANGED
@@ -1,19 +1,19 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- 'use strict'
3
+ 'use strict';
4
4
 
5
- const fs = require('fs')
6
- const config = require('config')
7
- const { dump } = require('js-yaml')
8
- const { build } = require('../src')
5
+ const fs = require('fs');
6
+ const config = require('config');
7
+ const { dump } = require('js-yaml');
8
+ const { build } = require('../src');
9
9
 
10
10
  const main = () => {
11
- const input = JSON.parse(JSON.stringify(config))
11
+ const input = JSON.parse(JSON.stringify(config));
12
12
 
13
- const result = build(input)
14
- const yaml = dump(result)
13
+ const result = build(input);
14
+ const yaml = dump(result);
15
15
 
16
- fs.writeFileSync('serverless.yaml', yaml)
17
- }
16
+ fs.writeFileSync('serverless.yaml', yaml);
17
+ };
18
18
 
19
- main()
19
+ main();
package/eslint.config.mjs CHANGED
@@ -1,55 +1,19 @@
1
- import globals from "globals";
2
- import path from "node:path";
3
- import { fileURLToPath } from "node:url";
4
- import js from "@eslint/js";
5
- import { FlatCompat } from "@eslint/eslintrc";
1
+ import eslint from '@eslint/js';
2
+ import globals from 'globals';
3
+ import { globalIgnores, defineConfig } from 'eslint/config';
6
4
 
7
- const __filename = fileURLToPath(import.meta.url);
8
- const __dirname = path.dirname(__filename);
9
- const compat = new FlatCompat({
10
- baseDirectory: __dirname,
11
- recommendedConfig: js.configs.recommended,
12
- allConfig: js.configs.all
13
- });
14
-
15
- export default [...compat.extends("eslint:recommended"), {
5
+ export default defineConfig(
6
+ globalIgnores([ '**/dist/', '**/coverage/' ]),
7
+ {
16
8
  languageOptions: {
17
- globals: {
18
- ...globals.node,
19
- ...globals.mocha,
20
- },
21
-
22
- ecmaVersion: 2018,
23
- sourceType: "commonjs",
9
+ globals: {
10
+ ...globals.node,
11
+ },
24
12
  },
25
-
26
13
  rules: {
27
- "comma-style": "error",
28
- "consistent-this": ["error", "_this"],
29
-
30
- indent: ["error", 2, {
31
- SwitchCase: 1,
32
- VariableDeclarator: 2,
33
- }],
34
-
35
- "keyword-spacing": "error",
36
- "no-multi-spaces": "off",
37
- "no-spaced-func": "error",
38
- "no-trailing-spaces": "error",
39
- quotes: ["error", "single"],
40
- semi: ["error", "never"],
41
- curly: ["error"],
42
- "prefer-arrow-callback": "error",
43
- "space-before-blocks": "error",
44
-
45
- "space-before-function-paren": [1, {
46
- anonymous: "always",
47
- named: "never",
48
- }],
49
-
50
- "space-infix-ops": "error",
51
- "space-unary-ops": "error",
52
- "no-return-await": "error",
53
- eqeqeq: "error",
14
+ semi: ['error', 'always'],
15
+ quotes: ['error', 'single'],
54
16
  },
55
- }];
17
+ },
18
+ eslint.configs.recommended,
19
+ );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kravc/serverless",
3
- "version": "0.10.1",
3
+ "version": "1.0.0",
4
4
  "description": "Serverless configuration builder and deployment tool for @kravc/dos service.",
5
5
  "main": "src/index.js",
6
6
  "repository": {
@@ -8,7 +8,7 @@
8
8
  "url": "http://github.com/alexkravets/serverless.git"
9
9
  },
10
10
  "scripts": {
11
- "test": "eslint src/ test/ && NODE_PATH=./ nyc --reporter text mocha --exit"
11
+ "test": "eslint --fix src/ bin/"
12
12
  },
13
13
  "bin": {
14
14
  "build": "bin/build.js",
@@ -16,21 +16,17 @@
16
16
  "info": "bin/info.sh",
17
17
  "logs": "bin/logs.sh"
18
18
  },
19
- "author": "Alexander Kravets <a@kra.vc>",
19
+ "author": "Oleksandr Kravets <a@kra.vc>",
20
20
  "license": "ISC",
21
21
  "dependencies": {
22
- "config": "^4.1.0",
23
- "js-yaml": "^4.1.0",
24
- "lodash": "^4.17.21",
25
- "serverless": "^3.39.0"
22
+ "config": "^4.3.0",
23
+ "js-yaml": "^4.1.1",
24
+ "lodash": "^4.17.23",
25
+ "serverless": "^3.40.0-19128fad"
26
26
  },
27
27
  "devDependencies": {
28
- "@eslint/eslintrc": "^3.2.0",
29
- "@eslint/js": "^9.15.0",
30
- "chai": "^5.1.2",
31
- "eslint": "^9.15.0",
32
- "globals": "^15.12.0",
33
- "mocha": "^10.8.2",
34
- "nyc": "^17.1.0"
28
+ "@eslint/js": "^10.0.1",
29
+ "eslint": "^10.0.0",
30
+ "globals": "^17.3.0"
35
31
  }
36
32
  }
package/src/build.js CHANGED
@@ -1,25 +1,25 @@
1
- 'use strict'
1
+ 'use strict';
2
2
 
3
- const { get } = require('lodash')
3
+ const { get } = require('lodash');
4
4
 
5
- const NODE_ENV = process.env.NODE_ENV || 'serverless'
6
- const INSTANCE = process.env.NODE_APP_INSTANCE || 'localhost'
7
- const ROOT_PATH = process.cwd()
5
+ const NODE_ENV = process.env.NODE_ENV || 'serverless';
6
+ const INSTANCE = process.env.NODE_APP_INSTANCE || 'localhost';
7
+ const ROOT_PATH = process.cwd();
8
8
 
9
- const { name, version } = require(`${ROOT_PATH}/package.json`)
10
- const [ MAJOR_VERSION ] = version.split('.')
11
- const DEFAULT_SERVICE = name.replace('@', '').replace('/', '-') + `-v${MAJOR_VERSION}`
12
- const DEFAULT_TABLE = name.replace('@', '').replace('/', '-')
13
- const DEFAULT_RUNTIME = 'nodejs22.x'
9
+ const { name, version } = require(`${ROOT_PATH}/package.json`);
10
+ const [ MAJOR_VERSION ] = version.split('.');
11
+ const DEFAULT_SERVICE = name.replace('@', '').replace('/', '-') + `-v${MAJOR_VERSION}`;
12
+ const DEFAULT_TABLE = name.replace('@', '').replace('/', '-');
13
+ const DEFAULT_RUNTIME = 'nodejs24.x';
14
14
 
15
15
  const build = config => {
16
- const AWS = get(config, 'aws', {})
17
- const SERVERLESS = get(config, 'serverless', {})
16
+ const AWS = get(config, 'aws', {});
17
+ const SERVERLESS = get(config, 'serverless', {});
18
18
 
19
19
  const result = {
20
20
  service: SERVERLESS.service || DEFAULT_SERVICE,
21
21
  variablesResolutionMode: 20210326
22
- }
22
+ };
23
23
 
24
24
  result.provider = {
25
25
  name: 'aws',
@@ -44,14 +44,14 @@ const build = config => {
44
44
  shouldStartNameWithService: true
45
45
  },
46
46
  lambdaHashingVersion: '20201221'
47
- }
47
+ };
48
48
 
49
49
  if (AWS.region) {
50
- result.provider.region = AWS.region
50
+ result.provider.region = AWS.region;
51
51
  }
52
52
 
53
53
  if (AWS.profile) {
54
- result.provider.profile = AWS.profile
54
+ result.provider.profile = AWS.profile;
55
55
  }
56
56
 
57
57
  result.package = {
@@ -59,7 +59,7 @@ const build = config => {
59
59
  '!test/**',
60
60
  '!bin/**'
61
61
  ]
62
- }
62
+ };
63
63
 
64
64
  result.functions = {
65
65
  api: {
@@ -73,7 +73,7 @@ const build = config => {
73
73
  }
74
74
  ]
75
75
  }
76
- }
76
+ };
77
77
 
78
78
  const DEFAULT_HTTP_METHODS = [
79
79
  'get',
@@ -81,10 +81,10 @@ const build = config => {
81
81
  'patch',
82
82
  'delete',
83
83
  'options'
84
- ]
84
+ ];
85
85
 
86
86
  for (const method of DEFAULT_HTTP_METHODS) {
87
- const path = '/{operationId}'
87
+ const path = '/{operationId}';
88
88
  const http = {
89
89
  path,
90
90
  method,
@@ -95,25 +95,30 @@ const build = config => {
95
95
  }
96
96
  }
97
97
  }
98
- }
98
+ };
99
99
 
100
- result.functions.api.events.push({ http })
100
+ result.functions.api.events.push({ http });
101
101
  }
102
102
 
103
103
  if (SERVERLESS.iamRoleStatements) {
104
104
  result.provider.iamRoleStatements =
105
- result.provider.iamRoleStatements.concat(SERVERLESS.iamRoleStatements)
105
+ result.provider.iamRoleStatements.concat(SERVERLESS.iamRoleStatements);
106
106
  }
107
107
 
108
108
  if (SERVERLESS.timeout) {
109
- result.provider.timeout = SERVERLESS.timeout
109
+ result.provider.timeout = SERVERLESS.timeout;
110
110
  }
111
111
 
112
112
  if (SERVERLESS.custom) {
113
- result.custom = SERVERLESS.custom
113
+ result.custom = SERVERLESS.custom;
114
114
  }
115
115
 
116
- const TABLES = get(config, 'tables')
116
+ let TABLES = get(config, 'tables');
117
+ const TABLE = get(config, 'dynamodb');
118
+
119
+ if (TABLE) {
120
+ TABLES = { default: TABLE };
121
+ }
117
122
 
118
123
  if (TABLES) {
119
124
  const DEFAULT_TABLE_ACTIONS = [
@@ -123,13 +128,13 @@ const build = config => {
123
128
  'dynamodb:PutItem',
124
129
  'dynamodb:UpdateItem',
125
130
  'dynamodb:DeleteItem'
126
- ]
131
+ ];
127
132
 
128
133
  for (const tableKey in TABLES) {
129
- const tableConfig = TABLES[tableKey]
130
- const { name = DEFAULT_TABLE, actions = DEFAULT_TABLE_ACTIONS } = tableConfig
134
+ const tableConfig = TABLES[tableKey];
135
+ const { name = DEFAULT_TABLE, actions = DEFAULT_TABLE_ACTIONS } = tableConfig;
131
136
 
132
- const tableName = `${name}-${INSTANCE}`
137
+ const tableName = `${name}-${INSTANCE}`;
133
138
 
134
139
  const statement = {
135
140
  Effect: 'Allow',
@@ -138,18 +143,18 @@ const build = config => {
138
143
  `arn:aws:dynamodb:\${opt:region, self:provider.region}:*:table/${tableName}`,
139
144
  `arn:aws:dynamodb:\${opt:region, self:provider.region}:*:table/${tableName}/*`
140
145
  ]
141
- }
146
+ };
142
147
 
143
- result.provider.iamRoleStatements.push(statement)
148
+ result.provider.iamRoleStatements.push(statement);
144
149
  }
145
150
  }
146
151
 
147
152
  if (result.provider.iamRoleStatements) {
148
- result.provider.iam = { role: { statements: result.provider.iamRoleStatements } }
149
- delete result.provider.iamRoleStatements
153
+ result.provider.iam = { role: { statements: result.provider.iamRoleStatements } };
154
+ delete result.provider.iamRoleStatements;
150
155
  }
151
156
 
152
- return result
153
- }
157
+ return result;
158
+ };
154
159
 
155
- module.exports = build
160
+ module.exports = build;
package/src/index.js CHANGED
@@ -1,5 +1,5 @@
1
- 'use strict'
1
+ 'use strict';
2
2
 
3
3
  module.exports = {
4
4
  build: require('./build')
5
- }
5
+ };
package/test/index.js DELETED
@@ -1,3 +0,0 @@
1
- 'use strict'
2
-
3
- require('../src')