Skip to content

Commit 79326c9

Browse files
committed
chore: upgrade @hapi/joi to joi
1 parent 47fcb4e commit 79326c9

File tree

8 files changed

+146
-116
lines changed

8 files changed

+146
-116
lines changed

lib/deploy/stepFunctions/compileAlarms.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const _ = require('lodash');
44
const BbPromise = require('bluebird');
5-
const Joi = require('@hapi/joi');
5+
const Joi = require('joi');
66
const schema = require('./compileAlarms.schema');
77
const logger = require('../../utils/logger');
88

@@ -142,17 +142,17 @@ function validateConfig(serverless, stateMachineName, alarmsObj) {
142142
return false;
143143
}
144144

145-
const { error } = Joi.validate(alarmsObj, schema, { allowUnknown: false });
146-
147-
if (error) {
148-
logger.log(
149-
`State machine [${stateMachineName}] : alarms config is malformed. `
150-
+ 'Please see https://github.com/horike37/serverless-step-functions for examples. '
151-
+ `${error}`,
152-
);
153-
return false;
154-
}
155-
145+
Joi.validate(alarmsObj, schema, { allowUnknown: false }, (err) => {
146+
if (err) {
147+
logger.log(
148+
`State machine [${stateMachineName}] : alarms config is malformed. `
149+
+ 'Please see https://github.com/horike37/serverless-step-functions for examples. '
150+
+ `${err}`,
151+
);
152+
return false;
153+
}
154+
return true;
155+
});
156156
return true;
157157
}
158158

lib/deploy/stepFunctions/compileAlarms.schema.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const Joi = require('@hapi/joi');
1+
const Joi = require('joi');
22

33
const arn = Joi.alternatives().try(
44
Joi.string(),

lib/deploy/stepFunctions/compileNotifications.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
const _ = require('lodash');
4-
const Joi = require('@hapi/joi');
4+
const Joi = require('joi');
55
const crypto = require('crypto');
66
const BbPromise = require('bluebird');
77
const schema = require('./compileNotifications.schema');
@@ -326,18 +326,18 @@ function validateConfig(serverless, stateMachineName, stateMachineObj, notificat
326326
return false;
327327
}
328328

329-
const { error } = Joi.validate(
330-
notificationsObj, schema, { allowUnknown: false },
331-
);
329+
Joi.validate(notificationsObj, schema, { allowUnknown: false }, (err) => {
330+
if (err) {
331+
logger.log(
332+
`State machine [${stateMachineName}] : notifications config is malformed. `
333+
+ 'Please see https://github.com/horike37/serverless-step-functions for examples. '
334+
+ `${err}`,
335+
);
336+
return false;
337+
}
332338

333-
if (error) {
334-
logger.log(
335-
`State machine [${stateMachineName}] : notifications config is malformed. `
336-
+ 'Please see https://github.com/horike37/serverless-step-functions for examples. '
337-
+ `${error}`,
338-
);
339-
return false;
340-
}
339+
return true;
340+
});
341341

342342
return true;
343343
}

lib/deploy/stepFunctions/compileNotifications.schema.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const Joi = require('@hapi/joi');
1+
const Joi = require('joi');
22

33
const arn = Joi.alternatives().try(
44
Joi.string(),

lib/deploy/stepFunctions/compileStateMachines.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
const _ = require('lodash');
4-
const Joi = require('@hapi/joi');
4+
const Joi = require('joi');
55
const aslValidator = require('asl-validator');
66
const BbPromise = require('bluebird');
77
const crypto = require('crypto');
@@ -107,14 +107,17 @@ module.exports = {
107107
} else {
108108
Tags = toTags(this.serverless.service.provider.tags);
109109
}
110-
111-
const { error, value } = Joi.validate(stateMachineObj, schema, { allowUnknown: false });
112-
if (error) {
113-
const errorMessage = `State machine [${stateMachineName}] is malformed. `
110+
let validationValue;
111+
Joi.validate(stateMachineObj, schema, { allowUnknown: false }, (err, value) => {
112+
if (err) {
113+
const errorMessage = `State machine [${stateMachineName}] is malformed. `
114114
+ 'Please check the README for more info. '
115-
+ `${error}`;
116-
throw new this.serverless.classes.Error(errorMessage);
117-
}
115+
+ `${err}`;
116+
throw new this.serverless.classes.Error(errorMessage);
117+
} else {
118+
validationValue = value;
119+
}
120+
});
118121

119122
if (stateMachineObj.definition) {
120123
if (this.serverless.service.stepFunctions.validate) {
@@ -201,23 +204,23 @@ module.exports = {
201204
_.forEach(stateMachineTags, tag => Tags.push(tag));
202205
}
203206

204-
if (value.loggingConfig) {
205-
const Destinations = (value.loggingConfig.destinations || [])
207+
if (validationValue.loggingConfig) {
208+
const Destinations = (validationValue.loggingConfig.destinations || [])
206209
.map(arn => ({
207210
CloudWatchLogsLogGroup: {
208211
LogGroupArn: arn,
209212
},
210213
}));
211214
LoggingConfiguration = {
212-
Level: value.loggingConfig.level,
213-
IncludeExecutionData: value.loggingConfig.includeExecutionData,
215+
Level: validationValue.loggingConfig.level,
216+
IncludeExecutionData: validationValue.loggingConfig.includeExecutionData,
214217
Destinations,
215218
};
216219
}
217220

218-
if (value.tracingConfig) {
221+
if (validationValue.tracingConfig) {
219222
TracingConfiguration = {
220-
Enabled: value.tracingConfig.enabled,
223+
Enabled: validationValue.tracingConfig.enabled,
221224
};
222225
}
223226

lib/deploy/stepFunctions/compileStateMachines.schema.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const Joi = require('@hapi/joi');
1+
const Joi = require('joi');
22

33
const arn = Joi.alternatives().try(
44
Joi.string().regex(/^arn:aws/, 'ARN'),

package-lock.json

Lines changed: 101 additions & 74 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"sinon": "^12.0.1"
4545
},
4646
"dependencies": {
47-
"@hapi/joi": "^15.0.2",
47+
"joi": "^17.7.0",
4848
"@serverless/utils": "^6.7.0",
4949
"asl-validator": "^3.1.0",
5050
"bluebird": "^3.4.0",

0 commit comments

Comments
 (0)