Skip to content

Commit

Permalink
refactor(constants): expose regex (#3351)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmenko authored Dec 18, 2023
1 parent bc0ece9 commit 72ae1d3
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changeset/purple-otters-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@commercetools-frontend/application-config': patch
---

Re-export regex for backwards compatibility
5 changes: 5 additions & 0 deletions .changeset/seven-falcons-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@commercetools-frontend/constants': patch
---

Expose some regex `PROJECT_KEY_REGEX`, `ENTRY_POINT_URI_PATH_REGEX`, `PERMISSION_GROUP_NAME_REGEX`.
13 changes: 0 additions & 13 deletions packages/application-config/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
/**
* The entryPointUriPath may be between 2 and 64 characters and only contain alphabetic lowercase characters,
* non-consecutive underscores and hyphens. Leading and trailing underscore and hyphens are also not allowed.
*/
export const ENTRY_POINT_URI_PATH_REGEX =
/^[^-_#]([0-9a-z]|[-_](?![-_])){0,62}[^-_#]$/g;

/**
* The permission group name may be between 2 and 64 characters and only contain alphanumeric lowercase characters and non-consecutive hyphens. Leading and trailing hyphens are also not allowed.
*/
export const PERMISSION_GROUP_NAME_REGEX =
/^[^-#]([a-z]|[-](?![-])){0,62}[^-#]$/g;

export const CLOUD_IDENTIFIERS = {
GCP_AU: 'gcp-au',
GCP_EU: 'gcp-eu',
Expand Down
6 changes: 6 additions & 0 deletions packages/application-config/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@ export { default as sanitizeSvg } from './sanitize-svg';
export * from './constants';
export * from './errors';
export * from './types';

// Backwards compatiblity
export {
ENTRY_POINT_URI_PATH_REGEX,
PERMISSION_GROUP_NAME_REGEX,
} from '@commercetools-frontend/constants';
8 changes: 4 additions & 4 deletions packages/application-config/src/validations.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Ajv, { ValidateFunction, type ErrorObject } from 'ajv';
import customApplicationSchemaJson from '../custom-application.schema.json';
import customViewSchemaJson from '../custom-view.schema.json';
import {
ENTRY_POINT_URI_PATH_REGEX,
LOADED_CONFIG_TYPES,
PERMISSION_GROUP_NAME_REGEX,
} from './constants';
} from '@commercetools-frontend/constants';
import customApplicationSchemaJson from '../custom-application.schema.json';
import customViewSchemaJson from '../custom-view.schema.json';
import { LOADED_CONFIG_TYPES } from './constants';
import type { JSONSchemaForCustomApplicationConfigurationFiles } from './schemas/generated/custom-application.schema';
import type { JSONSchemaForCustomViewConfigurationFiles } from './schemas/generated/custom-view.schema';
import type { LoadedConfigType } from './types';
Expand Down
19 changes: 19 additions & 0 deletions packages/constants/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
import type { TCustomView } from './types/generated/settings';

/**
* The entryPointUriPath may be between 2 and 36 characters and only contain alphabetic lowercase characters,
* non-consecutive underscores and hyphens. Leading and trailing underscore and hyphens are also not allowed.
*/
export const PROJECT_KEY_REGEX = /^[^-_#]([0-9a-z]|[-_](?![-_])){0,34}[^-_#]$/g;

/**
* The entryPointUriPath may be between 2 and 64 characters and only contain alphabetic lowercase characters,
* non-consecutive underscores and hyphens. Leading and trailing underscore and hyphens are also not allowed.
*/
export const ENTRY_POINT_URI_PATH_REGEX =
/^[^-_#]([0-9a-z]|[-_](?![-_])){0,62}[^-_#]$/g;

/**
* The permission group name may be between 2 and 64 characters and only contain alphanumeric lowercase characters and non-consecutive hyphens. Leading and trailing hyphens are also not allowed.
*/
export const PERMISSION_GROUP_NAME_REGEX =
/^[^-#]([a-z]|[-](?![-])){0,62}[^-#]$/g;

// DOM elements
export const PORTALS_CONTAINER_ID = 'portals-container';
export const PORTALS_CONTAINER_INDENTATION_SIZE = '48px';
Expand Down

2 comments on commit 72ae1d3

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for merchant-center-application-kit ready!

✅ Preview
https://merchant-center-application-mmlvs9yo1-commercetools.vercel.app

Built with commit 72ae1d3.
This pull request is being automatically deployed with vercel-action

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for application-kit-custom-views ready!

✅ Preview
https://application-kit-custom-views-bl2vu5o8f-commercetools.vercel.app

Built with commit 72ae1d3.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.