UNPKG

4.63 kBJavaScriptView Raw
1"use strict";
2
3const {
4 HttpStatusError
5} = require('common-errors');
6
7module.exports = exports = {
8 // indices
9 USERS_INDEX: 'user-iterator-set',
10 USERS_PUBLIC_INDEX: 'users-public',
11 USERS_REFERRAL_INDEX: 'users-referral',
12 ORGANIZATIONS_INDEX: 'organization-iterator-set',
13 // id mapping
14 USERS_ALIAS_TO_ID: 'users-alias',
15 USERS_SSO_TO_ID: 'users-sso-hash',
16 USERS_USERNAME_TO_ID: 'users-username',
17 ORGANIZATIONS_NAME_TO_ID: 'organization-name',
18 // referral tracking
19 USERS_REF: 'users-ref',
20 // hashes
21 USERS_DATA: 'data',
22 USERS_METADATA: 'metadata',
23 USERS_TOKENS: 'tokens',
24 USERS_API_TOKENS: 'api-tokens',
25 USERS_API_TOKENS_ZSET: 'api-tokens-set',
26 USERS_MFA_FLAG: 'mfa',
27 USERS_MFA_RECOVERY: 'mfa-recovery',
28 USERS_ORGANIZATIONS: 'user-organizations',
29 ORGANIZATIONS_DATA: 'data',
30 ORGANIZATIONS_METADATA: 'metadata',
31 ORGANIZATIONS_MEMBERS: 'members',
32 // standard JWT with TTL
33 USERS_ID_FIELD: 'id',
34 USERS_ALIAS_FIELD: 'alias',
35 USERS_BANNED_FLAG: 'ban',
36 USERS_ACTIVE_FLAG: 'active',
37 USERS_ADMIN_ROLE: 'admin',
38 USERS_SUPER_ADMIN_ROLE: 'root',
39 USERS_TESTER_ROLE: 'tester',
40 USERS_BANNED_DATA: 'bannedData',
41 USERS_CREATED_FIELD: 'created',
42 USERS_ACTIVATED_FIELD: 'aa',
43 USERS_USERNAME_FIELD: 'username',
44 USERS_IS_ORG_FIELD: 'org',
45 USERS_PASSWORD_FIELD: 'password',
46 USERS_NEXT_CYCLE_FIELD: 'nextCycle',
47 USERS_REFERRAL_FIELD: 'referral',
48 USERS_SSO_FACEBOOK_FIELD: 'facebook',
49 ORGANIZATIONS_ID_FIELD: 'id',
50 ORGANIZATIONS_CREATED_FIELD: 'created',
51 ORGANIZATIONS_NAME_FIELD: 'name',
52 ORGANIZATIONS_ACTIVE_FLAG: 'active',
53 // bearer tokens
54 BEARER_USERNAME_FIELD: 'userId',
55 BEARER_LEGACY_USERNAME_FIELD: 'username',
56 // pre-generated errors
57 ERROR_AUTH_REQUIRED: new HttpStatusError(401, 'authentication required'),
58 USERS_CREDENTIALS_REQUIRED_ERROR: new HttpStatusError(401, 'Credentials Required'),
59 USERS_DISPOSABLE_PASSWORD_MIA: new HttpStatusError(403, 'Invalid or Expired Password'),
60 USERS_INCORRECT_PASSWORD: new HttpStatusError(403, 'incorrect password'),
61 USERS_AUDIENCE_MISMATCH: new HttpStatusError(403, 'audience mismatch'),
62 USERS_INVALID_TOKEN: new HttpStatusError(403, 'invalid token'),
63 USERS_MALFORMED_TOKEN: new HttpStatusError(403, 'malformed token'),
64 USER_ALREADY_ACTIVE: new HttpStatusError(417, 'this user is already active'),
65 ErrorAccountLocked: new HttpStatusError(423, 'Account has been locked'),
66 ErrorConflictUserExists: new HttpStatusError(409, 'user already exists'),
67 ErrorConflictOrganizationExists: new HttpStatusError(409, 'organization already exists'),
68 ErrorOrganizationNotFound: new HttpStatusError(404, 'organization not found'),
69 ErrorTotpRequired: Object.defineProperty(new HttpStatusError(403, 'TOTP required'), 'credentials', {
70 enumerable: false,
71 writable: true
72 }),
73 ErrorTotpInvalid: new HttpStatusError(403, 'TOTP invalid'),
74 ErrorSecretRequired: new HttpStatusError(403, 'Secret required'),
75 ErrorUserNotFound: new HttpStatusError(404, 'username not found'),
76 ErrorUserNotMember: new HttpStatusError(404, 'username not member of organization'),
77 ErrorInvitationExpiredOrUsed: new HttpStatusError(400, 'Invitation has expired or already been used'),
78 // actions
79 USERS_ACTION_ACTIVATE: 'activate',
80 USERS_ACTION_DISPOSABLE_PASSWORD: 'disposable-password',
81 USERS_ACTION_PASSWORD: 'password',
82 USERS_ACTION_RESET: 'reset',
83 USERS_ACTION_REGISTER: 'register',
84 USERS_ACTION_INVITE: 'invite',
85 USERS_ACTION_ORGANIZATION_INVITE: 'organization-user-invite',
86 USERS_ACTION_ORGANIZATION_REGISTER: 'organization-user-register',
87 // invitations constants
88 INVITATIONS_INDEX: 'user-invitations',
89 ORGANIZATIONS_INVITATIONS_INDEX: 'organization-invitations',
90 // token
91 TOKEN_METADATA_FIELD_METADATA: '1',
92 TOKEN_METADATA_FIELD_SENDED_AT: '2',
93 TOKEN_METADATA_FIELD_CONTEXT: '3',
94 // challenge types
95 CHALLENGE_TYPE_EMAIL: 'email',
96 CHALLENGE_TYPE_PHONE: 'phone',
97 // MFA action types
98 MFA_TYPE_REQUIRED: Symbol('required'),
99 MFA_TYPE_OPTIONAL: Symbol('optional'),
100 MFA_TYPE_DISABLED: Symbol('disabled'),
101 // lock names
102 lockAlias: alias => `users:alias:${alias}`,
103 lockRegister: username => `users:register:${username}`,
104 lockOrganization: organizationName => `organizations:create:${organizationName}`
105}; // embed error codes
106
107exports.ErrorConflictUserExists.code = 'E_USERNAME_CONFLICT';
108exports.ErrorTotpRequired.code = 'E_TOTP_REQUIRED';
109exports.ErrorTotpInvalid.code = 'E_TOTP_INVALID';
110exports.ErrorSecretRequired.code = 'E_TOTP_NOSECRET';
111exports.SSO_PROVIDERS = [exports.USERS_SSO_FACEBOOK_FIELD];
112exports.FIELDS_TO_STRINGIFY = [exports.USERS_SSO_FACEBOOK_FIELD];
\No newline at end of file