@strapi/utils 4.2.0-beta.2 → 4.2.0-beta.3

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/lib/hooks.js CHANGED
@@ -20,17 +20,19 @@ const createHook = () => {
20
20
  };
21
21
 
22
22
  return {
23
- get handlers() {
23
+ getHandlers() {
24
24
  return state.handlers;
25
25
  },
26
26
 
27
27
  register(handler) {
28
28
  state.handlers.push(handler);
29
+
29
30
  return this;
30
31
  },
31
32
 
32
33
  delete(handler) {
33
34
  state.handlers = remove(eq(handler), state.handlers);
35
+
34
36
  return this;
35
37
  },
36
38
 
@@ -49,7 +51,7 @@ const createAsyncSeriesHook = () => ({
49
51
  ...createHook(),
50
52
 
51
53
  async call(context) {
52
- for (const handler of this.handlers) {
54
+ for (const handler of this.getHandlers()) {
53
55
  await handler(context);
54
56
  }
55
57
  },
@@ -66,7 +68,7 @@ const createAsyncSeriesWaterfallHook = () => ({
66
68
  async call(param) {
67
69
  let res = param;
68
70
 
69
- for (const handler of this.handlers) {
71
+ for (const handler of this.getHandlers()) {
70
72
  res = await handler(res);
71
73
  }
72
74
 
@@ -83,7 +85,7 @@ const createAsyncParallelHook = () => ({
83
85
  ...createHook(),
84
86
 
85
87
  async call(context) {
86
- const promises = this.handlers.map(handler => handler(cloneDeep(context)));
88
+ const promises = this.getHandlers().map(handler => handler(cloneDeep(context)));
87
89
 
88
90
  return Promise.all(promises);
89
91
  },
package/lib/index.js CHANGED
@@ -22,6 +22,7 @@ const {
22
22
  toRegressedEnumValue,
23
23
  startsWithANumber,
24
24
  joinBy,
25
+ toKebabCase,
25
26
  } = require('./string-formatting');
26
27
  const { removeUndefined } = require('./object-formatting');
27
28
  const { getConfigUrls, getAbsoluteAdminUrl, getAbsoluteServerUrl } = require('./config');
@@ -65,6 +66,7 @@ module.exports = {
65
66
  stringEquals,
66
67
  isKebabCase,
67
68
  isCamelCase,
69
+ toKebabCase,
68
70
  contentTypes,
69
71
  webhook,
70
72
  env,
@@ -28,6 +28,11 @@ module.exports = {
28
28
  transforms.push(traverseEntity(visitors.removeRestrictedRelations(auth), { schema }));
29
29
  }
30
30
 
31
+ // Apply sanitizers from registry if exists
32
+ strapi.sanitizers
33
+ .get('content-api.input')
34
+ .forEach(sanitizer => transforms.push(sanitizer(schema)));
35
+
31
36
  return pipeAsync(...transforms)(data);
32
37
  },
33
38
 
@@ -42,6 +47,11 @@ module.exports = {
42
47
  transforms.push(traverseEntity(visitors.removeRestrictedRelations(auth), { schema }));
43
48
  }
44
49
 
50
+ // Apply sanitizers from registry if exists
51
+ strapi.sanitizers
52
+ .get('content-api.output')
53
+ .forEach(sanitizer => transforms.push(sanitizer(schema)));
54
+
45
55
  return pipeAsync(...transforms)(data);
46
56
  },
47
57
  },
@@ -2,6 +2,7 @@
2
2
  const _ = require('lodash');
3
3
  const { trimChars, trimCharsEnd, trimCharsStart } = require('lodash/fp');
4
4
  const slugify = require('@sindresorhus/slugify');
5
+ const { kebabCase } = require('lodash');
5
6
 
6
7
  const nameToSlug = (name, options = { separator: '-' }) => slugify(name, options);
7
8
 
@@ -58,6 +59,8 @@ const joinBy = (joint, ...args) => {
58
59
  }, '');
59
60
  };
60
61
 
62
+ const toKebabCase = value => kebabCase(value);
63
+
61
64
  module.exports = {
62
65
  nameToSlug,
63
66
  nameToCollectionName,
@@ -68,6 +71,7 @@ module.exports = {
68
71
  stringEquals,
69
72
  isCamelCase,
70
73
  isKebabCase,
74
+ toKebabCase,
71
75
  toRegressedEnumValue,
72
76
  startsWithANumber,
73
77
  joinBy,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/utils",
3
- "version": "4.2.0-beta.2",
3
+ "version": "4.2.0-beta.3",
4
4
  "description": "Shared utilities for the Strapi packages",
5
5
  "keywords": [
6
6
  "strapi",
@@ -45,5 +45,5 @@
45
45
  "node": ">=12.22.0 <=16.x.x",
46
46
  "npm": ">=6.0.0"
47
47
  },
48
- "gitHead": "bff73257e7695d6f361c91dda8cc810a2bb70b6e"
48
+ "gitHead": "c4addbad6ecbc8ef7633bbba3806f3b0a2ae5f49"
49
49
  }