@commercetools-frontend/application-shell-connectors 22.2.1 → 22.3.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.
@@ -46,44 +46,37 @@ var _valuesInstanceProperty__default = /*#__PURE__*/_interopDefault(_valuesInsta
46
46
  var warning__default = /*#__PURE__*/_interopDefault(warning);
47
47
 
48
48
  // NOTE: This string will be replaced on build time with the package version.
49
- var version = "22.2.1";
49
+ var version = "22.3.0";
50
50
 
51
51
  const mcHostnameRegex = /^mc(-(\d){4,})?\.(.*)$/;
52
52
  const mcPreviewHostnameRegex = /^.*\.mc-preview\.(.*)$/;
53
-
54
53
  const getMcOriginTld = host => {
55
54
  if (host.match(mcPreviewHostnameRegex)) {
56
55
  return host.replace(mcPreviewHostnameRegex, '$1');
57
56
  }
58
-
59
57
  return host.replace(mcHostnameRegex, '$3');
60
58
  };
61
-
62
59
  const getMcApiUrlFromOrigin = origin => {
63
60
  var _context;
64
-
65
61
  const url = new _URL__default["default"](origin);
66
62
  const originTld = getMcOriginTld(url.host);
67
63
  return _concatInstanceProperty__default["default"](_context = "".concat(url.protocol, "//mc-api.")).call(_context, originTld);
68
64
  };
69
-
70
65
  const parseAsBoolean = value => value === true || value === 'true';
71
-
72
66
  function getMcApiUrl() {
73
67
  let environment = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window.app;
74
68
  let origin = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : window.origin;
75
69
  const isServedByProxy = parseAsBoolean(environment.servedByProxy);
70
+
76
71
  /**
77
72
  * Prefer using the origin URL for the MC API based on the origin value
78
73
  * of the browser's `window.location`.
79
74
  * This ensures that the application always uses the correct URL associated
80
75
  * with that environment, instead of relying on the config value.
81
76
  */
82
-
83
77
  if (isServedByProxy) {
84
78
  return getMcApiUrlFromOrigin(origin);
85
79
  }
86
-
87
80
  return environment.mcApiUrl;
88
81
  }
89
82
 
@@ -92,20 +85,20 @@ const getDisplayName = Component => {
92
85
  if (typeof Component === 'string') {
93
86
  return Component;
94
87
  }
95
-
96
88
  if (!Component) {
97
89
  return undefined;
98
90
  }
99
-
100
91
  return Component.displayName || Component.name || 'Component';
101
92
  };
102
93
 
103
94
  function ownKeys$2(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
104
-
105
95
  function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var _context2, _context3; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context2 = ownKeys$2(Object(source), !0)).call(_context2, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context3 = ownKeys$2(Object(source))).call(_context3, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
106
96
  // Menu visibilities
97
+
107
98
  // Permissions
99
+
108
100
  // Action rights
101
+
109
102
  // Data fences
110
103
 
111
104
  /**
@@ -130,7 +123,6 @@ const normalizeAllAppliedPermissions = allAppliedPermissions => {
130
123
  if (!allAppliedPermissions || allAppliedPermissions.length === 0) {
131
124
  return null;
132
125
  }
133
-
134
126
  return _reduceInstanceProperty__default["default"](allAppliedPermissions).call(allAppliedPermissions, (transformedAllApplied, allApplied) => {
135
127
  if (!allApplied) return transformedAllApplied;
136
128
  return _objectSpread$2(_objectSpread$2({}, transformedAllApplied), {}, {
@@ -142,7 +134,6 @@ const normalizeAllAppliedMenuVisibilities = allAppliedMenuVisibilities => {
142
134
  if (!allAppliedMenuVisibilities || allAppliedMenuVisibilities.length === 0) {
143
135
  return null;
144
136
  }
145
-
146
137
  return _reduceInstanceProperty__default["default"](allAppliedMenuVisibilities).call(allAppliedMenuVisibilities, (transformedAllApplied, allApplied) => {
147
138
  if (!allApplied) return transformedAllApplied;
148
139
  return _objectSpread$2(_objectSpread$2({}, transformedAllApplied), {}, {
@@ -154,7 +145,6 @@ const normalizeAllAppliedActionRights = allAppliedActionRights => {
154
145
  if (!allAppliedActionRights || allAppliedActionRights.length === 0) {
155
146
  return null;
156
147
  }
157
-
158
148
  return _reduceInstanceProperty__default["default"](allAppliedActionRights).call(allAppliedActionRights, (transformedAllApplied, allApplied) => {
159
149
  if (!allApplied) return transformedAllApplied;
160
150
  const previousAllAppliedGroup = transformedAllApplied[allApplied.group];
@@ -165,10 +155,8 @@ const normalizeAllAppliedActionRights = allAppliedActionRights => {
165
155
  });
166
156
  }, {});
167
157
  };
168
-
169
158
  const normalizeAppliedDataFencesForStoresByResourceType = dataFences => {
170
159
  var _context;
171
-
172
160
  const groupedByResourceType = _reduceInstanceProperty__default["default"](dataFences).call(dataFences, (previousGroupsOfSameType, appliedDataFence) => {
173
161
  if (!appliedDataFence) return previousGroupsOfSameType;
174
162
  const previousGroup = previousGroupsOfSameType[appliedDataFence.group];
@@ -176,12 +164,10 @@ const normalizeAppliedDataFencesForStoresByResourceType = dataFences => {
176
164
  [appliedDataFence.group]: [...(previousGroup || []), appliedDataFence]
177
165
  });
178
166
  }, {});
179
-
180
167
  return _reduceInstanceProperty__default["default"](_context = _Object$entries__default["default"](groupedByResourceType)).call(_context, (previousGroupedByResourceType, _ref) => {
181
168
  let _ref2 = _slicedToArray(_ref, 2),
182
- resourceType = _ref2[0],
183
- dataFences = _ref2[1];
184
-
169
+ resourceType = _ref2[0],
170
+ dataFences = _ref2[1];
185
171
  const groupByDataFenceName = _reduceInstanceProperty__default["default"](dataFences).call(dataFences, (nextDataFenceValues, dataFence) => {
186
172
  const dataFenceByName = nextDataFenceValues[dataFence.name] || {
187
173
  values: []
@@ -192,12 +178,13 @@ const normalizeAppliedDataFencesForStoresByResourceType = dataFences => {
192
178
  })
193
179
  });
194
180
  }, {});
195
-
196
181
  return _objectSpread$2(_objectSpread$2({}, previousGroupedByResourceType), {}, {
197
182
  [resourceType]: groupByDataFenceName
198
183
  });
199
184
  }, {});
200
- }; // input:
185
+ };
186
+
187
+ // input:
201
188
  // [
202
189
  // {
203
190
  // type: 'store',
@@ -228,12 +215,10 @@ const normalizeAppliedDataFencesForStoresByResourceType = dataFences => {
228
215
  // }
229
216
  // }
230
217
 
231
-
232
218
  const normalizeAllAppliedDataFences = allAppliedDataFences => {
233
219
  if (!allAppliedDataFences || allAppliedDataFences.length === 0) {
234
220
  return null;
235
221
  }
236
-
237
222
  const groupedByType = _reduceInstanceProperty__default["default"](allAppliedDataFences).call(allAppliedDataFences, (previousGroupsOfSameType, appliedDataFence) => {
238
223
  if (!appliedDataFence) return previousGroupsOfSameType;
239
224
  const previousGroup = previousGroupsOfSameType[appliedDataFence.type];
@@ -241,22 +226,20 @@ const normalizeAllAppliedDataFences = allAppliedDataFences => {
241
226
  [appliedDataFence.type]: [...(previousGroup || []), appliedDataFence]
242
227
  });
243
228
  }, {});
244
-
245
229
  const normalizedDataFences = _objectSpread$2({}, 'store' in groupedByType ? {
246
230
  store: normalizeAppliedDataFencesForStoresByResourceType(groupedByType.store)
247
231
  } : {});
248
-
249
232
  if (_Object$keys__default["default"](normalizedDataFences).length > 0) return normalizedDataFences;
250
233
  return null;
251
234
  };
252
235
 
253
236
  function ownKeys$1(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
254
-
255
237
  function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys$1(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys$1(Object(source))).call(_context2, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
256
238
  const Context$1 = /*#__PURE__*/react.createContext({});
257
- const defaultTimeZone = moment__default["default"].tz.guess() || 'Etc/UTC'; // Expose only certain fields as some of them are only meant to
258
- // be used internally in the AppShell
239
+ const defaultTimeZone = moment__default["default"].tz.guess() || 'Etc/UTC';
259
240
 
241
+ // Expose only certain fields as some of them are only meant to
242
+ // be used internally in the AppShell
260
243
  const mapUserToApplicationContextUser = user => {
261
244
  if (!user) return null;
262
245
  let applicationContextUser = {
@@ -271,11 +254,11 @@ const mapUserToApplicationContextUser = user => {
271
254
  locale: user.language,
272
255
  timeZone: user.timeZone || defaultTimeZone,
273
256
  projects: user.projects
274
- }; // This property will only be populated when user has logged in using SSO
257
+ };
275
258
 
259
+ // This property will only be populated when user has logged in using SSO
276
260
  if (user.idTokenUserInfo) {
277
261
  let additionalClaims = {};
278
-
279
262
  try {
280
263
  additionalClaims = JSON.parse(user.idTokenUserInfo.additionalClaims || '{}');
281
264
  } catch (error) {
@@ -285,21 +268,21 @@ const mapUserToApplicationContextUser = user => {
285
268
  }
286
269
  });
287
270
  }
288
-
289
271
  applicationContextUser.idTokenUserInfo = _objectSpread$1(_objectSpread$1({}, user.idTokenUserInfo), {}, {
290
272
  additionalClaims
291
273
  });
292
274
  }
293
-
294
275
  return applicationContextUser;
295
- }; // Adjust certain fields which depend e.g. on the origin
276
+ };
296
277
 
278
+ // Adjust certain fields which depend e.g. on the origin
297
279
  const mapEnvironmentToApplicationContextEnvironment = (environment, origin) => _objectSpread$1(_objectSpread$1({}, environment), {}, {
298
280
  // NOTE: The `mcApiUrl` depends on `servedByProxy`
299
281
  mcApiUrl: getMcApiUrl(environment, origin)
300
- }); // Expose only certain fields as some of them are only meant to
301
- // be used internally in the AppShell
282
+ });
302
283
 
284
+ // Expose only certain fields as some of them are only meant to
285
+ // be used internally in the AppShell
303
286
  const mapProjectToApplicationContextProject = project => {
304
287
  if (!project) return null;
305
288
  return {
@@ -313,7 +296,6 @@ const mapProjectToApplicationContextProject = project => {
313
296
  ownerName: project.owner.name
314
297
  };
315
298
  };
316
-
317
299
  const createApplicationContext = (environment, user, project, projectDataLocale) => ({
318
300
  environment: mapEnvironmentToApplicationContextEnvironment(environment),
319
301
  user: mapUserToApplicationContextUser(user),
@@ -323,18 +305,15 @@ const createApplicationContext = (environment, user, project, projectDataLocale)
323
305
  dataFences: normalizeAllAppliedDataFences(project === null || project === void 0 ? void 0 : project.allAppliedDataFences),
324
306
  dataLocale: projectDataLocale || null
325
307
  });
326
-
327
308
  const ApplicationContextProvider = props => jsxRuntime.jsx(Context$1.Provider, {
328
309
  value: createApplicationContext(props.environment, props.user, props.project, props.projectDataLocale),
329
310
  children: props.children
330
311
  });
331
-
332
312
  ApplicationContextProvider.propTypes = process.env.NODE_ENV !== "production" ? {
333
313
  projectDataLocale: _pt__default["default"].string,
334
314
  children: _pt__default["default"].node.isRequired
335
315
  } : {};
336
316
  ApplicationContextProvider.displayName = 'ApplicationContextProvider';
337
-
338
317
  const ApplicationContext = props => jsxRuntime.jsx(Context$1.Consumer, {
339
318
  children: context => {
340
319
  // Because of the way the ApplicationShell configures the Context.Provider,
@@ -345,12 +324,10 @@ const ApplicationContext = props => jsxRuntime.jsx(Context$1.Consumer, {
345
324
  return props.render(applicationContext);
346
325
  }
347
326
  });
348
-
349
327
  ApplicationContext.propTypes = process.env.NODE_ENV !== "production" ? {
350
328
  render: _pt__default["default"].func.isRequired
351
329
  } : {};
352
330
  ApplicationContext.displayName = 'ApplicationContext';
353
-
354
331
  function withApplicationContext(mapApplicationContextToProps) {
355
332
  return Component => {
356
333
  const WrappedComponent = props => jsxRuntime.jsx(ApplicationContext, {
@@ -361,68 +338,61 @@ function withApplicationContext(mapApplicationContextToProps) {
361
338
  return jsxRuntime.jsx(Component, _objectSpread$1(_objectSpread$1({}, props), mappedProps));
362
339
  }
363
340
  });
364
-
365
341
  WrappedComponent.displayName = "withApplicationContext(".concat(getDisplayName(Component), ")");
366
342
  return WrappedComponent;
367
343
  };
368
- } // Use function overloading to declare two possible signatures with two
369
- // distict return types, based on the selector function argument.
370
-
344
+ }
371
345
 
346
+ // Use function overloading to declare two possible signatures with two
347
+ // distict return types, based on the selector function argument.
372
348
  // Then implement the function. Typescript will pick the appropriate signature
373
349
  // based on the function arguments.
374
350
  function useApplicationContextHook(selector) {
375
- const context = react.useContext(Context$1); // Because of the way the ApplicationShell configures the Context.Provider,
351
+ const context = react.useContext(Context$1);
352
+ // Because of the way the ApplicationShell configures the Context.Provider,
376
353
  // we ensure that, when we read from the context, we always get actual
377
354
  // context object and not the initial value.
378
355
  // Therefore, we can safely cast the value to be out `TApplicationContext` type.
379
-
380
356
  const applicationContext = context;
381
357
  return selector ? selector(applicationContext) : applicationContext;
382
- } // This is a workaround to trick babel/rollup to correctly export the function.
358
+ }
359
+
360
+ // This is a workaround to trick babel/rollup to correctly export the function.
383
361
  // Most likely the problem arises with the use of overloading.
384
362
  // See related issue: https://github.com/babel/babel/issues/8361
385
-
386
-
387
- const useApplicationContext = useApplicationContextHook; // Exports
363
+ const useApplicationContext = useApplicationContextHook;
388
364
 
389
365
  function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
390
-
391
366
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
392
367
  var FetchProjectExtensionImageRegex = { kind: "Document", definitions: [{ kind: "OperationDefinition", operation: "query", name: { kind: "Name", value: "FetchProjectExtensionImageRegex" }, variableDefinitions: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "projectExtension" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "id" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "imageRegex" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "thumb" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "FragmentSpread", name: { kind: "Name", value: "ImageRegex" }, directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "small" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "FragmentSpread", name: { kind: "Name", value: "ImageRegex" }, directives: [] }] } }] } }] } }] } }, { kind: "FragmentDefinition", name: { kind: "Name", value: "ImageRegex" }, typeCondition: { kind: "NamedType", name: { kind: "Name", value: "ImageRegexOptions" } }, directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "flag" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "search" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "replace" }, arguments: [], directives: [] }] } }], loc: { start: 0, end: 256, source: { body: "query FetchProjectExtensionImageRegex {\n projectExtension {\n id\n imageRegex {\n thumb {\n ...ImageRegex\n }\n small {\n ...ImageRegex\n }\n }\n }\n}\nfragment ImageRegex on ImageRegexOptions {\n flag\n search\n replace\n}\n", name: "GraphQL request", locationOffset: { line: 1, column: 1 } } } };
393
-
394
368
  const useWarning = (condition, message) => {
395
369
  react.useEffect(() => {
396
- process.env.NODE_ENV !== "production" ? warning__default["default"](condition, message) : void 0; // eslint-disable-next-line react-hooks/exhaustive-deps
370
+ process.env.NODE_ENV !== "production" ? warning__default["default"](condition, message) : void 0;
371
+ // eslint-disable-next-line react-hooks/exhaustive-deps
397
372
  }, []);
398
373
  };
399
-
400
374
  const Context = /*#__PURE__*/react.createContext({
401
375
  isLoading: false
402
376
  });
403
-
404
377
  const useProjectExtensionImageRegex = () => {
405
378
  const _useContext = react.useContext(Context),
406
- isLoading = _useContext.isLoading,
407
- imageRegex = _useContext.imageRegex;
408
-
379
+ isLoading = _useContext.isLoading,
380
+ imageRegex = _useContext.imageRegex;
409
381
  return {
410
382
  isLoading,
411
383
  imageRegex
412
384
  };
413
385
  };
414
-
415
386
  const ProjectExtensionProviderForImageRegex = props => {
416
387
  const _useQuery = react$1.useQuery(FetchProjectExtensionImageRegex, {
417
- skip: props.skip,
418
- onError: sentry.reportErrorToSentry,
419
- context: {
420
- target: constants.GRAPHQL_TARGETS.SETTINGS_SERVICE
421
- }
422
- }),
423
- loading = _useQuery.loading,
424
- data = _useQuery.data;
425
-
388
+ skip: props.skip,
389
+ onError: sentry.reportErrorToSentry,
390
+ context: {
391
+ target: constants.GRAPHQL_TARGETS.SETTINGS_SERVICE
392
+ }
393
+ }),
394
+ loading = _useQuery.loading,
395
+ data = _useQuery.data;
426
396
  return jsxRuntime.jsx(Context.Provider, {
427
397
  value: {
428
398
  isLoading: loading,
@@ -431,25 +401,21 @@ const ProjectExtensionProviderForImageRegex = props => {
431
401
  children: props.children
432
402
  });
433
403
  };
434
-
435
404
  ProjectExtensionProviderForImageRegex.propTypes = process.env.NODE_ENV !== "production" ? {
436
405
  skip: _pt__default["default"].bool,
437
406
  children: _pt__default["default"].node.isRequired
438
407
  } : {};
439
408
  ProjectExtensionProviderForImageRegex.displayName = 'ProjectExtensionProviderForImageRegex';
440
-
441
409
  const GetProjectExtensionImageRegex = props => {
442
410
  useWarning(false, "@commercetools-frontend/application-shell-connectors: It is not recommended to use the 'GetProjectExtensionImageRegex' anymore. Please use the 'useProjectExtensionImageRegex' hook instead.");
443
411
  return jsxRuntime.jsx(Context.Consumer, {
444
412
  children: imageRegexContext => props.render(imageRegexContext)
445
413
  });
446
414
  };
447
-
448
415
  GetProjectExtensionImageRegex.propTypes = process.env.NODE_ENV !== "production" ? {
449
416
  render: _pt__default["default"].func.isRequired
450
417
  } : {};
451
418
  GetProjectExtensionImageRegex.displayName = 'GetProjectExtensionImageRegex';
452
-
453
419
  function withProjectExtensionImageRegex() {
454
420
  let propKey = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'imageRegexData';
455
421
  return Component => {
@@ -462,11 +428,10 @@ function withProjectExtensionImageRegex() {
462
428
  }))
463
429
  });
464
430
  };
465
-
466
431
  WrappedComponent.displayName = "withProjectExtensionImageRegex(".concat(getDisplayName(Component), ")");
467
432
  return WrappedComponent;
468
433
  };
469
- } // Exports
434
+ }
470
435
 
471
436
  exports.ApplicationContext = ApplicationContext;
472
437
  exports.ApplicationContextProvider = ApplicationContextProvider;