diff options
author | Chocobozzz <me@florianbigard.com> | 2023-07-31 14:34:36 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-08-11 15:02:33 +0200 |
commit | 3a4992633ee62d5edfbb484d9c6bcb3cf158489d (patch) | |
tree | e4510b39bdac9c318fdb4b47018d08f15368b8f0 /shared/server-commands/users/registrations-command.ts | |
parent | 04d1da5621d25d59bd5fa1543b725c497bf5d9a8 (diff) | |
download | PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.gz PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.zst PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.zip |
Migrate server to ESM
Sorry for the very big commit that may lead to git log issues and merge
conflicts, but it's a major step forward:
* Server can be faster at startup because imports() are async and we can
easily lazy import big modules
* Angular doesn't seem to support ES import (with .js extension), so we
had to correctly organize peertube into a monorepo:
* Use yarn workspace feature
* Use typescript reference projects for dependencies
* Shared projects have been moved into "packages", each one is now a
node module (with a dedicated package.json/tsconfig.json)
* server/tools have been moved into apps/ and is now a dedicated app
bundled and published on NPM so users don't have to build peertube
cli tools manually
* server/tests have been moved into packages/ so we don't compile
them every time we want to run the server
* Use isolatedModule option:
* Had to move from const enum to const
(https://www.typescriptlang.org/docs/handbook/enums.html#objects-vs-enums)
* Had to explictely specify "type" imports when used in decorators
* Prefer tsx (that uses esbuild under the hood) instead of ts-node to
load typescript files (tests with mocha or scripts):
* To reduce test complexity as esbuild doesn't support decorator
metadata, we only test server files that do not import server
models
* We still build tests files into js files for a faster CI
* Remove unmaintained peertube CLI import script
* Removed some barrels to speed up execution (less imports)
Diffstat (limited to 'shared/server-commands/users/registrations-command.ts')
-rw-r--r-- | shared/server-commands/users/registrations-command.ts | 151 |
1 files changed, 0 insertions, 151 deletions
diff --git a/shared/server-commands/users/registrations-command.ts b/shared/server-commands/users/registrations-command.ts deleted file mode 100644 index f57f54b34..000000000 --- a/shared/server-commands/users/registrations-command.ts +++ /dev/null | |||
@@ -1,151 +0,0 @@ | |||
1 | import { pick } from '@shared/core-utils' | ||
2 | import { HttpStatusCode, ResultList, UserRegistration, UserRegistrationRequest, UserRegistrationUpdateState } from '@shared/models' | ||
3 | import { unwrapBody } from '../requests' | ||
4 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
5 | |||
6 | export class RegistrationsCommand extends AbstractCommand { | ||
7 | |||
8 | register (options: OverrideCommandOptions & Partial<UserRegistrationRequest> & Pick<UserRegistrationRequest, 'username'>) { | ||
9 | const { password = 'password', email = options.username + '@example.com' } = options | ||
10 | const path = '/api/v1/users/register' | ||
11 | |||
12 | return this.postBodyRequest({ | ||
13 | ...options, | ||
14 | |||
15 | path, | ||
16 | fields: { | ||
17 | ...pick(options, [ 'username', 'displayName', 'channel' ]), | ||
18 | |||
19 | password, | ||
20 | |||
21 | }, | ||
22 | implicitToken: false, | ||
23 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
24 | }) | ||
25 | } | ||
26 | |||
27 | requestRegistration ( | ||
28 | options: OverrideCommandOptions & Partial<UserRegistrationRequest> & Pick<UserRegistrationRequest, 'username' | 'registrationReason'> | ||
29 | ) { | ||
30 | const { password = 'password', email = options.username + '@example.com' } = options | ||
31 | const path = '/api/v1/users/registrations/request' | ||
32 | |||
33 | return unwrapBody<UserRegistration>(this.postBodyRequest({ | ||
34 | ...options, | ||
35 | |||
36 | path, | ||
37 | fields: { | ||
38 | ...pick(options, [ 'username', 'displayName', 'channel', 'registrationReason' ]), | ||
39 | |||
40 | password, | ||
41 | |||
42 | }, | ||
43 | implicitToken: false, | ||
44 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
45 | })) | ||
46 | } | ||
47 | |||
48 | // --------------------------------------------------------------------------- | ||
49 | |||
50 | accept (options: OverrideCommandOptions & { id: number } & UserRegistrationUpdateState) { | ||
51 | const { id } = options | ||
52 | const path = '/api/v1/users/registrations/' + id + '/accept' | ||
53 | |||
54 | return this.postBodyRequest({ | ||
55 | ...options, | ||
56 | |||
57 | path, | ||
58 | fields: pick(options, [ 'moderationResponse', 'preventEmailDelivery' ]), | ||
59 | implicitToken: true, | ||
60 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
61 | }) | ||
62 | } | ||
63 | |||
64 | reject (options: OverrideCommandOptions & { id: number } & UserRegistrationUpdateState) { | ||
65 | const { id } = options | ||
66 | const path = '/api/v1/users/registrations/' + id + '/reject' | ||
67 | |||
68 | return this.postBodyRequest({ | ||
69 | ...options, | ||
70 | |||
71 | path, | ||
72 | fields: pick(options, [ 'moderationResponse', 'preventEmailDelivery' ]), | ||
73 | implicitToken: true, | ||
74 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
75 | }) | ||
76 | } | ||
77 | |||
78 | // --------------------------------------------------------------------------- | ||
79 | |||
80 | delete (options: OverrideCommandOptions & { | ||
81 | id: number | ||
82 | }) { | ||
83 | const { id } = options | ||
84 | const path = '/api/v1/users/registrations/' + id | ||
85 | |||
86 | return this.deleteRequest({ | ||
87 | ...options, | ||
88 | |||
89 | path, | ||
90 | implicitToken: true, | ||
91 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
92 | }) | ||
93 | } | ||
94 | |||
95 | // --------------------------------------------------------------------------- | ||
96 | |||
97 | list (options: OverrideCommandOptions & { | ||
98 | start?: number | ||
99 | count?: number | ||
100 | sort?: string | ||
101 | search?: string | ||
102 | } = {}) { | ||
103 | const path = '/api/v1/users/registrations' | ||
104 | |||
105 | return this.getRequestBody<ResultList<UserRegistration>>({ | ||
106 | ...options, | ||
107 | |||
108 | path, | ||
109 | query: pick(options, [ 'start', 'count', 'sort', 'search' ]), | ||
110 | implicitToken: true, | ||
111 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
112 | }) | ||
113 | } | ||
114 | |||
115 | // --------------------------------------------------------------------------- | ||
116 | |||
117 | askSendVerifyEmail (options: OverrideCommandOptions & { | ||
118 | email: string | ||
119 | }) { | ||
120 | const { email } = options | ||
121 | const path = '/api/v1/users/registrations/ask-send-verify-email' | ||
122 | |||
123 | return this.postBodyRequest({ | ||
124 | ...options, | ||
125 | |||
126 | path, | ||
127 | fields: { email }, | ||
128 | implicitToken: false, | ||
129 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
130 | }) | ||
131 | } | ||
132 | |||
133 | verifyEmail (options: OverrideCommandOptions & { | ||
134 | registrationId: number | ||
135 | verificationString: string | ||
136 | }) { | ||
137 | const { registrationId, verificationString } = options | ||
138 | const path = '/api/v1/users/registrations/' + registrationId + '/verify-email' | ||
139 | |||
140 | return this.postBodyRequest({ | ||
141 | ...options, | ||
142 | |||
143 | path, | ||
144 | fields: { | ||
145 | verificationString | ||
146 | }, | ||
147 | implicitToken: false, | ||
148 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
149 | }) | ||
150 | } | ||
151 | } | ||