@strapi/utils 4.10.1 → 4.10.2-alpha.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.
Files changed (164) hide show
  1. package/dist/async.d.ts +15 -0
  2. package/dist/async.js +33 -0
  3. package/dist/async.js.map +1 -0
  4. package/dist/code-generator.d.ts +2 -0
  5. package/dist/code-generator.js +11 -0
  6. package/dist/code-generator.js.map +1 -0
  7. package/dist/config.d.ts +8 -0
  8. package/dist/config.js +79 -0
  9. package/dist/config.js.map +1 -0
  10. package/dist/content-types.d.ts +60 -0
  11. package/dist/content-types.js +143 -0
  12. package/dist/content-types.js.map +1 -0
  13. package/dist/env-helper.d.ts +2 -0
  14. package/dist/env-helper.js +83 -0
  15. package/dist/env-helper.js.map +1 -0
  16. package/dist/errors.d.ts +37 -0
  17. package/dist/errors.js +100 -0
  18. package/dist/errors.js.map +1 -0
  19. package/dist/file.d.ts +16 -0
  20. package/dist/file.js +54 -0
  21. package/dist/file.js.map +1 -0
  22. package/dist/format-yup-error.d.ts +10 -0
  23. package/dist/format-yup-error.js +17 -0
  24. package/dist/format-yup-error.js.map +1 -0
  25. package/dist/hooks.d.ts +92 -0
  26. package/dist/hooks.js +89 -0
  27. package/dist/hooks.js.map +1 -0
  28. package/dist/import-default.d.ts +2 -0
  29. package/dist/import-default.js +7 -0
  30. package/dist/import-default.js.map +1 -0
  31. package/dist/index.d.ts +30 -0
  32. package/dist/index.js +82 -0
  33. package/dist/index.js.map +1 -0
  34. package/dist/object-formatting.d.ts +3 -0
  35. package/dist/object-formatting.js +14 -0
  36. package/dist/object-formatting.js.map +1 -0
  37. package/dist/pagination.d.ts +14 -0
  38. package/dist/pagination.js +80 -0
  39. package/dist/pagination.js.map +1 -0
  40. package/dist/parse-multipart.d.ts +8 -0
  41. package/dist/parse-multipart.js +36 -0
  42. package/dist/parse-multipart.js.map +1 -0
  43. package/dist/parse-type.d.ts +1 -0
  44. package/dist/parse-type.js +95 -0
  45. package/dist/parse-type.js.map +1 -0
  46. package/dist/policy.d.ts +41 -0
  47. package/dist/policy.js +109 -0
  48. package/dist/policy.js.map +1 -0
  49. package/dist/print-value.d.ts +2 -0
  50. package/dist/print-value.js +50 -0
  51. package/dist/print-value.js.map +1 -0
  52. package/dist/provider-factory.d.ts +84 -0
  53. package/dist/provider-factory.js +87 -0
  54. package/dist/provider-factory.js.map +1 -0
  55. package/dist/relations.d.ts +10 -0
  56. package/dist/relations.js +23 -0
  57. package/dist/relations.js.map +1 -0
  58. package/dist/sanitize/index.d.ts +28 -0
  59. package/dist/sanitize/index.js +135 -0
  60. package/dist/sanitize/index.js.map +1 -0
  61. package/dist/sanitize/sanitizers.d.ts +10 -0
  62. package/dist/sanitize/sanitizers.js +106 -0
  63. package/dist/sanitize/sanitizers.js.map +1 -0
  64. package/dist/sanitize/visitors/allowed-fields.d.ts +3 -0
  65. package/dist/sanitize/visitors/allowed-fields.js +83 -0
  66. package/dist/sanitize/visitors/allowed-fields.js.map +1 -0
  67. package/dist/sanitize/visitors/index.d.ts +7 -0
  68. package/dist/sanitize/visitors/index.js +21 -0
  69. package/dist/sanitize/visitors/index.js.map +1 -0
  70. package/dist/sanitize/visitors/remove-dynamic-zones.d.ts +3 -0
  71. package/dist/sanitize/visitors/remove-dynamic-zones.js +10 -0
  72. package/dist/sanitize/visitors/remove-dynamic-zones.js.map +1 -0
  73. package/dist/sanitize/visitors/remove-morph-to-relations.d.ts +3 -0
  74. package/dist/sanitize/visitors/remove-morph-to-relations.js +10 -0
  75. package/dist/sanitize/visitors/remove-morph-to-relations.js.map +1 -0
  76. package/dist/sanitize/visitors/remove-password.d.ts +3 -0
  77. package/dist/sanitize/visitors/remove-password.js +9 -0
  78. package/dist/sanitize/visitors/remove-password.js.map +1 -0
  79. package/dist/sanitize/visitors/remove-private.d.ts +3 -0
  80. package/dist/sanitize/visitors/remove-private.js +14 -0
  81. package/dist/sanitize/visitors/remove-private.js.map +1 -0
  82. package/dist/sanitize/visitors/remove-restricted-relations.d.ts +3 -0
  83. package/dist/sanitize/visitors/remove-restricted-relations.js +88 -0
  84. package/dist/sanitize/visitors/remove-restricted-relations.js.map +1 -0
  85. package/dist/sanitize/visitors/restricted-fields.d.ts +3 -0
  86. package/dist/sanitize/visitors/restricted-fields.js +25 -0
  87. package/dist/sanitize/visitors/restricted-fields.js.map +1 -0
  88. package/dist/set-creator-fields.d.ts +9 -0
  89. package/dist/set-creator-fields.js +37 -0
  90. package/dist/set-creator-fields.js.map +1 -0
  91. package/dist/string-formatting.d.ts +16 -0
  92. package/dist/string-formatting.js +85 -0
  93. package/dist/string-formatting.js.map +1 -0
  94. package/dist/template-configuration.d.ts +5 -0
  95. package/dist/template-configuration.js +28 -0
  96. package/dist/template-configuration.js.map +1 -0
  97. package/dist/template.d.ts +9 -0
  98. package/dist/template.js +20 -0
  99. package/dist/template.js.map +1 -0
  100. package/dist/traverse/factory.d.ts +13 -0
  101. package/dist/traverse/factory.js +126 -0
  102. package/dist/traverse/factory.js.map +1 -0
  103. package/dist/traverse/index.d.ts +5 -0
  104. package/dist/traverse/index.js +17 -0
  105. package/dist/traverse/index.js.map +1 -0
  106. package/dist/traverse/query-fields.d.ts +3 -0
  107. package/dist/traverse/query-fields.js +35 -0
  108. package/dist/traverse/query-fields.js.map +1 -0
  109. package/dist/traverse/query-filters.d.ts +3 -0
  110. package/dist/traverse/query-filters.js +73 -0
  111. package/dist/traverse/query-filters.js.map +1 -0
  112. package/dist/traverse/query-populate.d.ts +3 -0
  113. package/dist/traverse/query-populate.js +140 -0
  114. package/dist/traverse/query-populate.js.map +1 -0
  115. package/dist/traverse/query-sort.d.ts +3 -0
  116. package/dist/traverse/query-sort.js +114 -0
  117. package/dist/traverse/query-sort.js.map +1 -0
  118. package/dist/traverse-entity.d.ts +33 -0
  119. package/dist/traverse-entity.js +134 -0
  120. package/dist/traverse-entity.js.map +1 -0
  121. package/dist/types.d.ts +57 -0
  122. package/dist/types.js +4 -0
  123. package/dist/types.js.map +1 -0
  124. package/dist/validators.d.ts +5 -0
  125. package/dist/validators.js +110 -0
  126. package/dist/validators.js.map +1 -0
  127. package/dist/webhook.d.ts +10 -0
  128. package/dist/webhook.js +14 -0
  129. package/dist/webhook.js.map +1 -0
  130. package/index.d.ts +5 -3
  131. package/package.json +2 -2
  132. package/coverage/clover.xml +0 -638
  133. package/coverage/coverage-final.json +0 -24
  134. package/coverage/lcov-report/base.css +0 -224
  135. package/coverage/lcov-report/block-navigation.js +0 -87
  136. package/coverage/lcov-report/favicon.png +0 -0
  137. package/coverage/lcov-report/index.html +0 -146
  138. package/coverage/lcov-report/lib/async.js.html +0 -223
  139. package/coverage/lcov-report/lib/content-types.js.html +0 -643
  140. package/coverage/lcov-report/lib/env-helper.js.html +0 -319
  141. package/coverage/lcov-report/lib/errors.js.html +0 -397
  142. package/coverage/lcov-report/lib/format-yup-error.js.html +0 -145
  143. package/coverage/lcov-report/lib/hooks.js.html +0 -415
  144. package/coverage/lcov-report/lib/import-default.js.html +0 -115
  145. package/coverage/lcov-report/lib/index.html +0 -326
  146. package/coverage/lcov-report/lib/pagination.js.html +0 -382
  147. package/coverage/lcov-report/lib/parse-type.js.html +0 -385
  148. package/coverage/lcov-report/lib/policy.js.html +0 -472
  149. package/coverage/lcov-report/lib/print-value.js.html +0 -241
  150. package/coverage/lcov-report/lib/provider-factory.js.html +0 -433
  151. package/coverage/lcov-report/lib/relations.js.html +0 -178
  152. package/coverage/lcov-report/lib/sanitize/visitors/allowed-fields.js.html +0 -367
  153. package/coverage/lcov-report/lib/sanitize/visitors/index.html +0 -191
  154. package/coverage/lcov-report/lib/sanitize/visitors/index.js.html +0 -112
  155. package/coverage/lcov-report/lib/sanitize/visitors/remove-password.js.html +0 -106
  156. package/coverage/lcov-report/lib/sanitize/visitors/remove-private.js.html +0 -118
  157. package/coverage/lcov-report/lib/sanitize/visitors/remove-restricted-relations.js.html +0 -316
  158. package/coverage/lcov-report/lib/sanitize/visitors/restricted-fields.js.html +0 -181
  159. package/coverage/lcov-report/lib/string-formatting.js.html +0 -322
  160. package/coverage/lcov-report/lib/validators.js.html +0 -445
  161. package/coverage/lcov-report/prettify.css +0 -1
  162. package/coverage/lcov-report/prettify.js +0 -2
  163. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  164. package/coverage/lcov-report/sorter.js +0 -196
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const fp_1 = require("lodash/fp");
30
+ const content_types_1 = require("../content-types");
31
+ const async_1 = require("../async");
32
+ const visitors = __importStar(require("./visitors"));
33
+ const sanitizers = __importStar(require("./sanitizers"));
34
+ const traverse_entity_1 = __importDefault(require("../traverse-entity"));
35
+ const traverse_1 = require("../traverse");
36
+ const createContentAPISanitizers = () => {
37
+ const sanitizeInput = (data, schema, { auth } = {}) => {
38
+ if ((0, fp_1.isArray)(data)) {
39
+ return Promise.all(data.map((entry) => sanitizeInput(entry, schema, { auth })));
40
+ }
41
+ const nonWritableAttributes = (0, content_types_1.getNonWritableAttributes)(schema);
42
+ const transforms = [
43
+ // Remove non writable attributes
44
+ (0, traverse_entity_1.default)(visitors.restrictedFields(nonWritableAttributes), { schema }),
45
+ ];
46
+ if (auth) {
47
+ // Remove restricted relations
48
+ transforms.push((0, traverse_entity_1.default)(visitors.removeRestrictedRelations(auth), { schema }));
49
+ }
50
+ // Apply sanitizers from registry if exists
51
+ strapi.sanitizers
52
+ .get('content-api.input')
53
+ .forEach((sanitizer) => transforms.push(sanitizer(schema)));
54
+ return (0, async_1.pipeAsync)(...transforms)(data);
55
+ };
56
+ const sanitizeOutput = async (data, schema, { auth } = {}) => {
57
+ if ((0, fp_1.isArray)(data)) {
58
+ const res = new Array(data.length);
59
+ for (let i = 0; i < data.length; i += 1) {
60
+ res[i] = await sanitizeOutput(data[i], schema, { auth });
61
+ }
62
+ return res;
63
+ }
64
+ const transforms = [(data) => sanitizers.defaultSanitizeOutput(schema, data)];
65
+ if (auth) {
66
+ transforms.push((0, traverse_entity_1.default)(visitors.removeRestrictedRelations(auth), { schema }));
67
+ }
68
+ // Apply sanitizers from registry if exists
69
+ strapi.sanitizers
70
+ .get('content-api.output')
71
+ .forEach((sanitizer) => transforms.push(sanitizer(schema)));
72
+ return (0, async_1.pipeAsync)(...transforms)(data);
73
+ };
74
+ const sanitizeQuery = async (query, schema, { auth } = {}) => {
75
+ const { filters, sort, fields, populate } = query;
76
+ const sanitizedQuery = (0, fp_1.cloneDeep)(query);
77
+ if (filters) {
78
+ Object.assign(sanitizedQuery, { filters: await sanitizeFilters(filters, schema, { auth }) });
79
+ }
80
+ if (sort) {
81
+ Object.assign(sanitizedQuery, { sort: await sanitizeSort(sort, schema, { auth }) });
82
+ }
83
+ if (fields) {
84
+ Object.assign(sanitizedQuery, { fields: await sanitizeFields(fields, schema) });
85
+ }
86
+ if (populate) {
87
+ Object.assign(sanitizedQuery, { populate: await sanitizePopulate(populate, schema) });
88
+ }
89
+ return sanitizedQuery;
90
+ };
91
+ const sanitizeFilters = (filters, schema, { auth } = {}) => {
92
+ if ((0, fp_1.isArray)(filters)) {
93
+ return Promise.all(filters.map((filter) => sanitizeFilters(filter, schema, { auth })));
94
+ }
95
+ const transforms = [sanitizers.defaultSanitizeFilters(schema)];
96
+ if (auth) {
97
+ transforms.push((0, traverse_1.traverseQueryFilters)(visitors.removeRestrictedRelations(auth), { schema }));
98
+ }
99
+ return (0, async_1.pipeAsync)(...transforms)(filters);
100
+ };
101
+ const sanitizeSort = (sort, schema, { auth } = {}) => {
102
+ const transforms = [sanitizers.defaultSanitizeSort(schema)];
103
+ if (auth) {
104
+ transforms.push((0, traverse_1.traverseQuerySort)(visitors.removeRestrictedRelations(auth), { schema }));
105
+ }
106
+ return (0, async_1.pipeAsync)(...transforms)(sort);
107
+ };
108
+ const sanitizeFields = (fields, schema) => {
109
+ const transforms = [sanitizers.defaultSanitizeFields(schema)];
110
+ return (0, async_1.pipeAsync)(...transforms)(fields);
111
+ };
112
+ const sanitizePopulate = (populate, schema, { auth } = {}) => {
113
+ const transforms = [sanitizers.defaultSanitizePopulate(schema)];
114
+ if (auth) {
115
+ transforms.push((0, traverse_1.traverseQueryPopulate)(visitors.removeRestrictedRelations(auth), { schema }));
116
+ }
117
+ return (0, async_1.pipeAsync)(...transforms)(populate);
118
+ };
119
+ return {
120
+ input: sanitizeInput,
121
+ output: sanitizeOutput,
122
+ query: sanitizeQuery,
123
+ filters: sanitizeFilters,
124
+ sort: sanitizeSort,
125
+ fields: sanitizeFields,
126
+ populate: sanitizePopulate,
127
+ };
128
+ };
129
+ const contentAPI = createContentAPISanitizers();
130
+ exports.default = {
131
+ contentAPI,
132
+ sanitizers,
133
+ visitors,
134
+ };
135
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../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AC,CAAC;IAEF,OAAO;QACL,KAAK,EAAE,aAAa;QACpB,MAAM,EAAE,cAAc;QACtB,KAAK,EAAE,aAAa;QACpB,OAAO,EAAE,eAAe;QACxB,IAAI,EAAE,YAAY;QAClB,MAAM,EAAE,cAAc;QACtB,QAAQ,EAAE,gBAAgB;KAC3B,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,0BAA0B,EAAE,CAAC;AAEhD,kBAAe;IACb,UAAU;IACV,UAAU;IACV,QAAQ;CACT,CAAC"}
@@ -0,0 +1,10 @@
1
+ /// <reference types="lodash" />
2
+ import { Data } from '../traverse-entity';
3
+ import type { Model } from '../types';
4
+ declare const sanitizePasswords: (schema: Model) => (entity: Data) => Promise<Data>;
5
+ declare const defaultSanitizeOutput: (schema: Model, entity: Data) => Promise<Data>;
6
+ declare const defaultSanitizeFilters: import("lodash").CurriedFunction2<Model, any, Promise<unknown>>;
7
+ declare const defaultSanitizeSort: import("lodash").CurriedFunction2<Model, any, Promise<unknown>>;
8
+ declare const defaultSanitizeFields: import("lodash").CurriedFunction2<Model, any, Promise<unknown>>;
9
+ declare const defaultSanitizePopulate: import("lodash").CurriedFunction2<Model, any, Promise<unknown>>;
10
+ export { sanitizePasswords, defaultSanitizeOutput, defaultSanitizeFilters, defaultSanitizeSort, defaultSanitizeFields, defaultSanitizePopulate, };
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.defaultSanitizePopulate = exports.defaultSanitizeFields = exports.defaultSanitizeSort = exports.defaultSanitizeFilters = exports.defaultSanitizeOutput = exports.sanitizePasswords = void 0;
7
+ const fp_1 = require("lodash/fp");
8
+ const async_1 = require("../async");
9
+ const traverse_entity_1 = __importDefault(require("../traverse-entity"));
10
+ const content_types_1 = require("../content-types");
11
+ const traverse_1 = require("../traverse");
12
+ const visitors_1 = require("./visitors");
13
+ const sanitizePasswords = (schema) => async (entity) => {
14
+ return (0, traverse_entity_1.default)(visitors_1.removePassword, { schema }, entity);
15
+ };
16
+ exports.sanitizePasswords = sanitizePasswords;
17
+ const defaultSanitizeOutput = async (schema, entity) => {
18
+ return (0, traverse_entity_1.default)((...args) => {
19
+ (0, visitors_1.removePassword)(...args);
20
+ (0, visitors_1.removePrivate)(...args);
21
+ }, { schema }, entity);
22
+ };
23
+ exports.defaultSanitizeOutput = defaultSanitizeOutput;
24
+ const defaultSanitizeFilters = (0, fp_1.curry)((schema, filters) => {
25
+ return (0, async_1.pipeAsync)(
26
+ // Remove dynamic zones from filters
27
+ (0, traverse_1.traverseQueryFilters)(visitors_1.removeDynamicZones, { schema }),
28
+ // Remove morpTo relations from filters
29
+ (0, traverse_1.traverseQueryFilters)(visitors_1.removeMorphToRelations, { schema }),
30
+ // Remove passwords from filters
31
+ (0, traverse_1.traverseQueryFilters)(visitors_1.removePassword, { schema }),
32
+ // Remove private from filters
33
+ (0, traverse_1.traverseQueryFilters)(visitors_1.removePrivate, { schema }),
34
+ // Remove empty objects
35
+ (0, traverse_1.traverseQueryFilters)(({ key, value }, { remove }) => {
36
+ if ((0, fp_1.isObject)(value) && (0, fp_1.isEmpty)(value)) {
37
+ remove(key);
38
+ }
39
+ }, { schema }))(filters);
40
+ });
41
+ exports.defaultSanitizeFilters = defaultSanitizeFilters;
42
+ const defaultSanitizeSort = (0, fp_1.curry)((schema, sort) => {
43
+ return (0, async_1.pipeAsync)(
44
+ // Remove non attribute keys
45
+ (0, traverse_1.traverseQuerySort)(({ key, attribute }, { remove }) => {
46
+ // ID is not an attribute per se, so we need to make
47
+ // an extra check to ensure we're not removing it
48
+ if (key === 'id') {
49
+ return;
50
+ }
51
+ if (!attribute) {
52
+ remove(key);
53
+ }
54
+ }, { schema }),
55
+ // Remove dynamic zones from sort
56
+ (0, traverse_1.traverseQuerySort)(visitors_1.removeDynamicZones, { schema }),
57
+ // Remove morpTo relations from sort
58
+ (0, traverse_1.traverseQuerySort)(visitors_1.removeMorphToRelations, { schema }),
59
+ // Remove private from sort
60
+ (0, traverse_1.traverseQuerySort)(visitors_1.removePrivate, { schema }),
61
+ // Remove passwords from filters
62
+ (0, traverse_1.traverseQuerySort)(visitors_1.removePassword, { schema }),
63
+ // Remove keys for empty non-scalar values
64
+ (0, traverse_1.traverseQuerySort)(({ key, attribute, value }, { remove }) => {
65
+ if (!(0, content_types_1.isScalarAttribute)(attribute) && (0, fp_1.isEmpty)(value)) {
66
+ remove(key);
67
+ }
68
+ }, { schema }))(sort);
69
+ });
70
+ exports.defaultSanitizeSort = defaultSanitizeSort;
71
+ const defaultSanitizeFields = (0, fp_1.curry)((schema, fields) => {
72
+ return (0, async_1.pipeAsync)(
73
+ // Only keep scalar attributes
74
+ (0, traverse_1.traverseQueryFields)(({ key, attribute }, { remove }) => {
75
+ if ((0, fp_1.isNil)(attribute) || !(0, content_types_1.isScalarAttribute)(attribute)) {
76
+ remove(key);
77
+ }
78
+ }, { schema }),
79
+ // Remove private fields
80
+ (0, traverse_1.traverseQueryFields)(visitors_1.removePrivate, { schema }),
81
+ // Remove password fields
82
+ (0, traverse_1.traverseQueryFields)(visitors_1.removePassword, { schema }),
83
+ // Remove nil values from fields array
84
+ (value) => ((0, fp_1.isArray)(value) ? value.filter((field) => !(0, fp_1.isNil)(field)) : value))(fields);
85
+ });
86
+ exports.defaultSanitizeFields = defaultSanitizeFields;
87
+ const defaultSanitizePopulate = (0, fp_1.curry)((schema, populate) => {
88
+ return (0, async_1.pipeAsync)((0, traverse_1.traverseQueryPopulate)(async ({ key, value, schema, attribute }, { set }) => {
89
+ if (attribute) {
90
+ return;
91
+ }
92
+ if (key === 'sort') {
93
+ set(key, await defaultSanitizeSort(schema, value));
94
+ }
95
+ if (key === 'filters') {
96
+ set(key, await defaultSanitizeFilters(schema, value));
97
+ }
98
+ if (key === 'fields') {
99
+ set(key, await defaultSanitizeFields(schema, value));
100
+ }
101
+ }, { schema }),
102
+ // Remove private fields
103
+ (0, traverse_1.traverseQueryPopulate)(visitors_1.removePrivate, { schema }))(populate);
104
+ });
105
+ exports.defaultSanitizePopulate = defaultSanitizePopulate;
106
+ //# sourceMappingURL=sanitizers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sanitizers.js","sourceRoot":"","sources":["../../src/sanitize/sanitizers.ts"],"names":[],"mappings":";;;;;;AAAA,kCAAqE;AAErE,oCAAqC;AACrC,yEAA0D;AAC1D,oDAAqD;AAErD,0CAKqB;AAErB,yCAKoB;AAIpB,MAAM,iBAAiB,GAAG,CAAC,MAAa,EAAE,EAAE,CAAC,KAAK,EAAE,MAAY,EAAE,EAAE;IAClE,OAAO,IAAA,yBAAc,EAAC,yBAAc,EAAE,EAAE,MAAM,EAAE,EAAE,MAAM,CAAC,CAAC;AAC5D,CAAC,CAAC;AAwHA,8CAAiB;AAtHnB,MAAM,qBAAqB,GAAG,KAAK,EAAE,MAAa,EAAE,MAAY,EAAE,EAAE;IAClE,OAAO,IAAA,yBAAc,EACnB,CAAC,GAAG,IAAI,EAAE,EAAE;QACV,IAAA,yBAAc,EAAC,GAAG,IAAI,CAAC,CAAC;QACxB,IAAA,wBAAa,EAAC,GAAG,IAAI,CAAC,CAAC;IACzB,CAAC,EACD,EAAE,MAAM,EAAE,EACV,MAAM,CACP,CAAC;AACJ,CAAC,CAAC;AA8GA,sDAAqB;AA5GvB,MAAM,sBAAsB,GAAG,IAAA,UAAK,EAAC,CAAC,MAAa,EAAE,OAAO,EAAE,EAAE;IAC9D,OAAO,IAAA,iBAAS;IACd,oCAAoC;IACpC,IAAA,+BAAoB,EAAC,6BAAkB,EAAE,EAAE,MAAM,EAAE,CAAC;IACpD,uCAAuC;IACvC,IAAA,+BAAoB,EAAC,iCAAsB,EAAE,EAAE,MAAM,EAAE,CAAC;IACxD,gCAAgC;IAChC,IAAA,+BAAoB,EAAC,yBAAc,EAAE,EAAE,MAAM,EAAE,CAAC;IAChD,8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AA,iBAAS,EACd,IAAA,gCAAqB,EACnB,KAAK,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE;QACnD,IAAI,SAAS,EAAE;YACb,OAAO;SACR;QAED,IAAI,GAAG,KAAK,MAAM,EAAE;YAClB,GAAG,CAAC,GAAG,EAAE,MAAM,mBAAmB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;SACpD;QAED,IAAI,GAAG,KAAK,SAAS,EAAE;YACrB,GAAG,CAAC,GAAG,EAAE,MAAM,sBAAsB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;SACvD;QAED,IAAI,GAAG,KAAK,QAAQ,EAAE;YACpB,GAAG,CAAC,GAAG,EAAE,MAAM,qBAAqB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;SACtD;IACH,CAAC,EACD,EAAE,MAAM,EAAE,CACX;IACD,wBAAwB;IACxB,IAAA,gCAAqB,EAAC,wBAAa,EAAE,EAAE,MAAM,EAAE,CAAC,CACjD,CAAC,QAAQ,CAAC,CAAC;AACd,CAAC,CAAC,CAAC;AAQD,0DAAuB"}
@@ -0,0 +1,3 @@
1
+ import { Visitor } from '../../traverse-entity';
2
+ declare const _default: (allowedFields?: string[] | null) => Visitor;
3
+ export default _default;
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const fp_1 = require("lodash/fp");
4
+ exports.default = (allowedFields = null) => ({ key, path: { attribute: path } }, { remove }) => {
5
+ // All fields are allowed
6
+ if (allowedFields === null) {
7
+ return;
8
+ }
9
+ // Ignore invalid formats
10
+ if (!(0, fp_1.isArray)(allowedFields)) {
11
+ return;
12
+ }
13
+ if ((0, fp_1.isNil)(path)) {
14
+ return;
15
+ }
16
+ const containedPaths = getContainedPaths(path);
17
+ /**
18
+ * Tells if the current path should be kept or not based
19
+ * on the success of the check functions for any of the allowed paths.
20
+ *
21
+ * The check functions are defined as follow:
22
+ *
23
+ * `containedPaths.includes(p)`
24
+ * @example
25
+ * ```js
26
+ * const path = 'foo.bar.field';
27
+ * const p = 'foo.bar';
28
+ * // it should match
29
+ *
30
+ * const path = 'foo.bar.field';
31
+ * const p = 'bar.foo';
32
+ * // it shouldn't match
33
+ *
34
+ * const path = 'foo.bar';
35
+ * const p = 'foo.bar.field';
36
+ * // it should match but isn't handled by this check
37
+ * ```
38
+ *
39
+ * `p.startsWith(`${path}.`)`
40
+ * @example
41
+ * ```js
42
+ * const path = 'foo.bar';
43
+ * const p = 'foo.bar.field';
44
+ * // it should match
45
+ *
46
+ * const path = 'foo.bar.field';
47
+ * const p = 'bar.foo';
48
+ * // it shouldn't match
49
+ *
50
+ * const path = 'foo.bar.field';
51
+ * const p = 'foo.bar';
52
+ * // it should match but isn't handled by this check
53
+ * ```
54
+ */
55
+ const isPathAllowed = allowedFields.some((p) => containedPaths.includes(p) || p.startsWith(`${path}.`));
56
+ if (isPathAllowed) {
57
+ return;
58
+ }
59
+ // Remove otherwise
60
+ remove(key);
61
+ };
62
+ /**
63
+ * Retrieve the list of allowed paths based on the given path
64
+ *
65
+ * @example
66
+ * ```js
67
+ * const containedPaths = getContainedPaths('foo');
68
+ * // ['foo']
69
+ *
70
+ * * const containedPaths = getContainedPaths('foo.bar');
71
+ * // ['foo', 'foo.bar']
72
+ *
73
+ * * const containedPaths = getContainedPaths('foo.bar.field');
74
+ * // ['foo', 'foo.bar', 'foo.bar.field']
75
+ * ```
76
+ */
77
+ const getContainedPaths = (path) => {
78
+ const parts = (0, fp_1.toPath)(path);
79
+ return parts.reduce((acc, value, index, list) => {
80
+ return [...acc, list.slice(0, index + 1).join('.')];
81
+ }, []);
82
+ };
83
+ //# sourceMappingURL=allowed-fields.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"allowed-fields.js","sourceRoot":"","sources":["../../../src/sanitize/visitors/allowed-fields.ts"],"names":[],"mappings":";;AAAA,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,7 @@
1
+ export { default as removePassword } from './remove-password';
2
+ export { default as removePrivate } from './remove-private';
3
+ export { default as removeRestrictedRelations } from './remove-restricted-relations';
4
+ export { default as removeMorphToRelations } from './remove-morph-to-relations';
5
+ export { default as removeDynamicZones } from './remove-dynamic-zones';
6
+ export { default as allowedFields } from './allowed-fields';
7
+ export { default as restrictedFields } from './restricted-fields';
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.restrictedFields = exports.allowedFields = exports.removeDynamicZones = exports.removeMorphToRelations = exports.removeRestrictedRelations = exports.removePrivate = exports.removePassword = void 0;
7
+ var remove_password_1 = require("./remove-password");
8
+ Object.defineProperty(exports, "removePassword", { enumerable: true, get: function () { return __importDefault(remove_password_1).default; } });
9
+ var remove_private_1 = require("./remove-private");
10
+ Object.defineProperty(exports, "removePrivate", { enumerable: true, get: function () { return __importDefault(remove_private_1).default; } });
11
+ var remove_restricted_relations_1 = require("./remove-restricted-relations");
12
+ Object.defineProperty(exports, "removeRestrictedRelations", { enumerable: true, get: function () { return __importDefault(remove_restricted_relations_1).default; } });
13
+ var remove_morph_to_relations_1 = require("./remove-morph-to-relations");
14
+ Object.defineProperty(exports, "removeMorphToRelations", { enumerable: true, get: function () { return __importDefault(remove_morph_to_relations_1).default; } });
15
+ var remove_dynamic_zones_1 = require("./remove-dynamic-zones");
16
+ Object.defineProperty(exports, "removeDynamicZones", { enumerable: true, get: function () { return __importDefault(remove_dynamic_zones_1).default; } });
17
+ var allowed_fields_1 = require("./allowed-fields");
18
+ Object.defineProperty(exports, "allowedFields", { enumerable: true, get: function () { return __importDefault(allowed_fields_1).default; } });
19
+ var restricted_fields_1 = require("./restricted-fields");
20
+ Object.defineProperty(exports, "restrictedFields", { enumerable: true, get: function () { return __importDefault(restricted_fields_1).default; } });
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/sanitize/visitors/index.ts"],"names":[],"mappings":";;;;;;AAAA,qDAA8D;AAArD,kIAAA,OAAO,OAAkB;AAClC,mDAA4D;AAAnD,gIAAA,OAAO,OAAiB;AACjC,6EAAqF;AAA5E,yJAAA,OAAO,OAA6B;AAC7C,yEAAgF;AAAvE,oJAAA,OAAO,OAA0B;AAC1C,+DAAuE;AAA9D,2IAAA,OAAO,OAAsB;AACtC,mDAA4D;AAAnD,gIAAA,OAAO,OAAiB;AACjC,yDAAkE;AAAzD,sIAAA,OAAO,OAAoB"}
@@ -0,0 +1,3 @@
1
+ import type { Visitor } from '../../traverse-entity';
2
+ declare const visitor: Visitor;
3
+ export default visitor;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const content_types_1 = require("../../content-types");
4
+ const visitor = ({ key, attribute }, { remove }) => {
5
+ if ((0, content_types_1.isDynamicZoneAttribute)(attribute)) {
6
+ remove(key);
7
+ }
8
+ };
9
+ exports.default = visitor;
10
+ //# sourceMappingURL=remove-dynamic-zones.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remove-dynamic-zones.js","sourceRoot":"","sources":["../../../src/sanitize/visitors/remove-dynamic-zones.ts"],"names":[],"mappings":";;AAAA,uDAA6D;AAG7D,MAAM,OAAO,GAAY,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;IAC1D,IAAI,IAAA,sCAAsB,EAAC,SAAS,CAAC,EAAE;QACrC,MAAM,CAAC,GAAG,CAAC,CAAC;KACb;AACH,CAAC,CAAC;AAEF,kBAAe,OAAO,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Visitor } from '../../traverse-entity';
2
+ declare const visitor: Visitor;
3
+ export default visitor;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const content_types_1 = require("../../content-types");
4
+ const visitor = ({ key, attribute }, { remove }) => {
5
+ if ((0, content_types_1.isMorphToRelationalAttribute)(attribute)) {
6
+ remove(key);
7
+ }
8
+ };
9
+ exports.default = visitor;
10
+ //# sourceMappingURL=remove-morph-to-relations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remove-morph-to-relations.js","sourceRoot":"","sources":["../../../src/sanitize/visitors/remove-morph-to-relations.ts"],"names":[],"mappings":";;AAAA,uDAAmE;AAGnE,MAAM,OAAO,GAAY,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;IAC1D,IAAI,IAAA,4CAA4B,EAAC,SAAS,CAAC,EAAE;QAC3C,MAAM,CAAC,GAAG,CAAC,CAAC;KACb;AACH,CAAC,CAAC;AAEF,kBAAe,OAAO,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Visitor } from '../../traverse-entity';
2
+ declare const visitor: Visitor;
3
+ export default visitor;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const visitor = ({ key, attribute }, { remove }) => {
4
+ if (attribute?.type === 'password') {
5
+ remove(key);
6
+ }
7
+ };
8
+ exports.default = visitor;
9
+ //# sourceMappingURL=remove-password.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remove-password.js","sourceRoot":"","sources":["../../../src/sanitize/visitors/remove-password.ts"],"names":[],"mappings":";;AAEA,MAAM,OAAO,GAAY,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;IAC1D,IAAI,SAAS,EAAE,IAAI,KAAK,UAAU,EAAE;QAClC,MAAM,CAAC,GAAG,CAAC,CAAC;KACb;AACH,CAAC,CAAC;AAEF,kBAAe,OAAO,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Visitor } from '../../traverse-entity';
2
+ declare const visitor: Visitor;
3
+ export default visitor;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const content_types_1 = require("../../content-types");
4
+ const visitor = ({ schema, key, attribute }, { remove }) => {
5
+ if (!attribute) {
6
+ return;
7
+ }
8
+ const isPrivate = (0, content_types_1.isPrivateAttribute)(schema, key) || attribute.private === true;
9
+ if (isPrivate) {
10
+ remove(key);
11
+ }
12
+ };
13
+ exports.default = visitor;
14
+ //# sourceMappingURL=remove-private.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remove-private.js","sourceRoot":"","sources":["../../../src/sanitize/visitors/remove-private.ts"],"names":[],"mappings":";;AAAA,uDAAyD;AAGzD,MAAM,OAAO,GAAY,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;IAClE,IAAI,CAAC,SAAS,EAAE;QACd,OAAO;KACR;IAED,MAAM,SAAS,GAAG,IAAA,kCAAkB,EAAC,MAAM,EAAE,GAAG,CAAC,IAAI,SAAS,CAAC,OAAO,KAAK,IAAI,CAAC;IAEhF,IAAI,SAAS,EAAE;QACb,MAAM,CAAC,GAAG,CAAC,CAAC;KACb;AACH,CAAC,CAAC;AAEF,kBAAe,OAAO,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Visitor } from '../../traverse-entity';
2
+ declare const _default: (auth: unknown) => Visitor;
3
+ export default _default;
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const contentTypeUtils = __importStar(require("../../content-types"));
27
+ const ACTIONS_TO_VERIFY = ['find'];
28
+ const { CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE } = contentTypeUtils.constants;
29
+ exports.default = (auth) => async ({ data, key, attribute, schema }, { remove, set }) => {
30
+ if (!attribute) {
31
+ return;
32
+ }
33
+ const isRelation = attribute.type === 'relation';
34
+ if (!isRelation) {
35
+ return;
36
+ }
37
+ const handleMorphRelation = async () => {
38
+ const newMorphValue = [];
39
+ for (const element of data[key]) {
40
+ const scopes = ACTIONS_TO_VERIFY.map((action) => `${element.__type}.${action}`);
41
+ const isAllowed = await hasAccessToSomeScopes(scopes, auth);
42
+ if (isAllowed) {
43
+ newMorphValue.push(element);
44
+ }
45
+ }
46
+ // If the new value is empty, remove the relation completely
47
+ if (newMorphValue.length === 0) {
48
+ remove(key);
49
+ }
50
+ else {
51
+ set(key, newMorphValue);
52
+ }
53
+ };
54
+ const handleRegularRelation = async () => {
55
+ const scopes = ACTIONS_TO_VERIFY.map((action) => `${attribute.target}.${action}`);
56
+ const isAllowed = await hasAccessToSomeScopes(scopes, auth);
57
+ // If the authenticated user don't have access to any of the scopes, then remove the field
58
+ if (!isAllowed) {
59
+ remove(key);
60
+ }
61
+ };
62
+ const isCreatorRelation = [CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE].includes(key);
63
+ // Polymorphic relations
64
+ if (contentTypeUtils.isMorphToRelationalAttribute(attribute)) {
65
+ await handleMorphRelation();
66
+ return;
67
+ }
68
+ // Creator relations
69
+ if (isCreatorRelation && schema.options.populateCreatorFields) {
70
+ // do nothing
71
+ return;
72
+ }
73
+ // Regular relations
74
+ await handleRegularRelation();
75
+ };
76
+ const hasAccessToSomeScopes = async (scopes, auth) => {
77
+ for (const scope of scopes) {
78
+ try {
79
+ await strapi.auth.verify(auth, { scope });
80
+ return true;
81
+ }
82
+ catch {
83
+ continue;
84
+ }
85
+ }
86
+ return false;
87
+ };
88
+ //# sourceMappingURL=remove-restricted-relations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remove-restricted-relations.js","sourceRoot":"","sources":["../../../src/sanitize/visitors/remove-restricted-relations.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sEAAwD;AAGxD,MAAM,iBAAiB,GAAG,CAAC,MAAM,CAAC,CAAC;AACnC,MAAM,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,GAAG,gBAAgB,CAAC,SAAS,CAAC;AAElF,kBAAe,CAAC,IAAa,EAAW,EAAE,CACxC,KAAK,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,EAAE;IAC1D,IAAI,CAAC,SAAS,EAAE;QACd,OAAO;KACR;IAED,MAAM,UAAU,GAAG,SAAS,CAAC,IAAI,KAAK,UAAU,CAAC;IAEjD,IAAI,CAAC,UAAU,EAAE;QACf,OAAO;KACR;IAED,MAAM,mBAAmB,GAAG,KAAK,IAAI,EAAE;QACrC,MAAM,aAAa,GAA8B,EAAE,CAAC;QAEpD,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE;YAC/B,MAAM,MAAM,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,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AE;QAC1B,IAAI;YACF,MAAM,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;YAC1C,OAAO,IAAI,CAAC;SACb;QAAC,MAAM;YACN,SAAS;SACV;KACF;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Visitor } from '../../traverse-entity';
2
+ declare const _default: (restrictedFields?: string[] | null) => Visitor;
3
+ export default _default;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const fp_1 = require("lodash/fp");
4
+ exports.default = (restrictedFields = null) => ({ key, path: { attribute: path } }, { remove }) => {
5
+ // Remove all fields
6
+ if (restrictedFields === null) {
7
+ remove(key);
8
+ return;
9
+ }
10
+ // Ignore invalid formats
11
+ if (!(0, fp_1.isArray)(restrictedFields)) {
12
+ return;
13
+ }
14
+ // Remove if an exact match was found
15
+ if (restrictedFields.includes(path)) {
16
+ remove(key);
17
+ return;
18
+ }
19
+ // Remove nested matches
20
+ const isRestrictedNested = restrictedFields.some((allowedPath) => path?.toString().startsWith(`${allowedPath}.`));
21
+ if (isRestrictedNested) {
22
+ remove(key);
23
+ }
24
+ };
25
+ //# sourceMappingURL=restricted-fields.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"restricted-fields.js","sourceRoot":"","sources":["../../../src/sanitize/visitors/restricted-fields.ts"],"names":[],"mappings":";;AAAA,kCAAoC;AAGpC,kBAAe,CAAC,mBAAoC,IAAI,EAAW,EAAE,CACnE,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;IACjD,oBAAoB;IACpB,IAAI,gBAAgB,KAAK,IAAI,EAAE;QAC7B,MAAM,CAAC,GAAG,CAAC,CAAC;QACZ,OAAO;KACR;IAED,yBAAyB;IACzB,IAAI,CAAC,IAAA,YAAO,EAAC,gBAAgB,CAAC,EAAE;QAC9B,OAAO;KACR;IAED,qCAAqC;IACrC,IAAI,gBAAgB,CAAC,QAAQ,CAAC,IAAc,CAAC,EAAE;QAC7C,MAAM,CAAC,GAAG,CAAC,CAAC;QACZ,OAAO;KACR;IAED,wBAAwB;IACxB,MAAM,kBAAkB,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE,CAC/D,IAAI,EAAE,QAAQ,EAAE,CAAC,UAAU,CAAC,GAAG,WAAW,GAAG,CAAC,CAC/C,CAAC;IACF,IAAI,kBAAkB,EAAE;QACtB,MAAM,CAAC,GAAG,CAAC,CAAC;KACb;AACH,CAAC,CAAC"}
@@ -0,0 +1,9 @@
1
+ interface Options {
2
+ user: User;
3
+ isEdition?: boolean;
4
+ }
5
+ interface User {
6
+ id: string | number;
7
+ }
8
+ declare const _default: ({ user, isEdition }: Options) => (data: object) => object;
9
+ export = _default;