1 | "use strict";
|
2 |
|
3 | const {
|
4 | HttpStatusError
|
5 | } = require('common-errors');
|
6 |
|
7 | module.exports = exports = {
|
8 |
|
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 |
|
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 |
|
19 | USERS_REF: 'users-ref',
|
20 |
|
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 |
|
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 |
|
54 | BEARER_USERNAME_FIELD: 'userId',
|
55 | BEARER_LEGACY_USERNAME_FIELD: 'username',
|
56 |
|
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 |
|
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 |
|
88 | INVITATIONS_INDEX: 'user-invitations',
|
89 | organizationInvite: organizationId => `organization-invitations:${organizationId}`,
|
90 | inviteId: (organizationId, username) => `${organizationId}:${username}`,
|
91 |
|
92 | TOKEN_METADATA_FIELD_METADATA: '1',
|
93 | TOKEN_METADATA_FIELD_SENDED_AT: '2',
|
94 | TOKEN_METADATA_FIELD_CONTEXT: '3',
|
95 |
|
96 | CHALLENGE_TYPE_EMAIL: 'email',
|
97 | CHALLENGE_TYPE_PHONE: 'phone',
|
98 |
|
99 | MFA_TYPE_REQUIRED: Symbol('required'),
|
100 | MFA_TYPE_OPTIONAL: Symbol('optional'),
|
101 | MFA_TYPE_DISABLED: Symbol('disabled'),
|
102 |
|
103 | lockAlias: alias => `users:alias:${alias}`,
|
104 | lockRegister: username => `users:register:${username}`,
|
105 | lockOrganization: organizationName => `organizations:create:${organizationName}`,
|
106 | lockTbits: profile => `tbits:${profile.accountId}:${profile.fanId}`
|
107 | };
|
108 |
|
109 | exports.ErrorConflictUserExists.code = 'E_USERNAME_CONFLICT';
|
110 | exports.ErrorTotpRequired.code = 'E_TOTP_REQUIRED';
|
111 | exports.ErrorTotpInvalid.code = 'E_TOTP_INVALID';
|
112 | exports.ErrorSecretRequired.code = 'E_TOTP_NOSECRET';
|
113 | exports.SSO_PROVIDERS = [exports.USERS_SSO_FACEBOOK_FIELD];
|
114 | exports.FIELDS_TO_STRINGIFY = [exports.USERS_SSO_FACEBOOK_FIELD]; |
\ | No newline at end of file |