Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions packages/consts/src/consts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DNS_SAFE_NAME_REGEX } from './regexs';
import { DNS_SAFE_NAME_REGEX, EMAIL_REGEX } from './regexs';

export const FREE_SUBSCRIPTION_PLAN_CODE = 'DEV';

Expand Down Expand Up @@ -97,6 +97,11 @@ export const ACTOR_TYPES = {
CRAWLER: 'crawlers',
} as const;

/**
* Used as username for returning user own info from API v2/users/username
*/
export const ME_USER_NAME_PLACEHOLDER = 'me';

/**
* Username used when user is anonymous.
*/
Expand All @@ -114,6 +119,19 @@ export const USERNAME = {
REGEX: /^[a-zA-Z0-9_.-]{3,30}$/,
};

export const EMAIL = {
MAX_LENGTH: 254, // see https://www.rfc-editor.org/errata_search.php?rfc=3696&eid=1690
REGEX: EMAIL_REGEX,
};

/**
* Profile name (such as organization or first / last name) constraints.
*/
export const PROFILE_NAME = {
MAX_LENGTH: 50,
REGEX: /^(?!.*:\/\/)[^@><]*$/, // Prohibits usage of @, <, > and ://
};

/**
* Max length for DNS safe string
*/
Expand Down Expand Up @@ -239,11 +257,6 @@ export const DEFAULT_PLATFORM_LIMITS = {
MAX_TASKS_PER_SCHEDULER: 10,
};

/**
* Use as username for returning user own info from API v2/users/username
*/
export const ME_USER_NAME_PLACEHOLDER = 'me';

/**
* Max length of the queue head that server will return in Request Queue API.
*/
Expand Down
36 changes: 35 additions & 1 deletion test/consts.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
import { USERNAME, APIFY_ID_REGEX, ACTOR_ENV_VARS, ENV_VARS, APIFY_ENV_VARS, LOCAL_ACTOR_ENV_VARS, LOCAL_APIFY_ENV_VARS, LOCAL_ENV_VARS } from '@apify/consts';
import {
USERNAME,
APIFY_ID_REGEX,
ACTOR_ENV_VARS,
ENV_VARS,
APIFY_ENV_VARS,
LOCAL_ACTOR_ENV_VARS,
LOCAL_APIFY_ENV_VARS,
LOCAL_ENV_VARS,
PROFILE_NAME,
} from '@apify/consts';
import { cryptoRandomObjectId } from '@apify/utilities';

describe('consts', () => {
Expand All @@ -17,6 +27,30 @@ describe('consts', () => {
});
});

describe('PROFILE_NAME', () => {
it('REGEX works as expected', () => {
// Valid cases
expect(PROFILE_NAME.REGEX.test('John Doe')).toBe(true);
expect(PROFILE_NAME.REGEX.test('Anonymous')).toBe(true);
expect(PROFILE_NAME.REGEX.test('John123')).toBe(true);
expect(PROFILE_NAME.REGEX.test('John-Doe')).toBe(true);
expect(PROFILE_NAME.REGEX.test('Org_Example')).toBe(true);
expect(PROFILE_NAME.REGEX.test(':/JohnDoe')).toBe(true);
expect(PROFILE_NAME.REGEX.test(':/a/Simple.Name')).toBe(true);
expect(PROFILE_NAME.REGEX.test('John:/Doe/')).toBe(true);
expect(PROFILE_NAME.REGEX.test('Simple:.//Name')).toBe(true);
expect(PROFILE_NAME.REGEX.test('Joh////:/n-Doe')).toBe(true);
expect(PROFILE_NAME.REGEX.test('user:name')).toBe(true);

// Invalid cases
expect(PROFILE_NAME.REGEX.test('user@name')).toBe(false);
expect(PROFILE_NAME.REGEX.test('user>name')).toBe(false);
expect(PROFILE_NAME.REGEX.test('user<name')).toBe(false);
expect(PROFILE_NAME.REGEX.test('example://test')).toBe(false);
expect(PROFILE_NAME.REGEX.test('example://////test')).toBe(false);
});
});

describe('APIFY_ID_REGEX', () => {
it('matches testing apify IDs', () => {
const testingStrings = {
Expand Down