Skip to content

Commit 1f99952

Browse files
authored
Merge pull request #7633 from schrodingersket/openapi/accounts
NextJS API: Completed `/api/v2/accounts` endpoints…
2 parents e6c5879 + a082137 commit 1f99952

35 files changed

+705
-111
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { z } from "../../framework";
2+
3+
import {
4+
FailedAPIOperationSchema,
5+
SuccessfulAPIOperationSchema,
6+
} from "../common";
7+
8+
import { AccountIdSchema } from "./common";
9+
10+
// OpenAPI spec
11+
//
12+
export const BanAccountInputSchema = z
13+
.object({
14+
account_id: AccountIdSchema.describe("Account id to ban."),
15+
})
16+
.describe(
17+
"**Administrators only**. Used to ban a user's account from the system.",
18+
);
19+
20+
export const BanAccountOutputSchema = z.union([
21+
FailedAPIOperationSchema,
22+
SuccessfulAPIOperationSchema,
23+
]);
24+
25+
export type BanAccountInput = z.infer<typeof BanAccountInputSchema>;
26+
export type BanAccountOutput = z.infer<typeof BanAccountOutputSchema>;
Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,50 @@
11
import { z } from "../../framework";
22

3-
export const AccountIdSchema = z
4-
.string()
5-
.uuid()
6-
.describe("Account id.");
3+
export const AccountIdSchema = z.string().uuid().describe("Account id.");
74

85
export type AccountId = z.infer<typeof AccountIdSchema>;
6+
7+
export const AccountEmailSchema = z
8+
.string()
9+
.describe("The account e-mail address.");
10+
11+
export type AccountEmail = z.infer<typeof AccountEmailSchema>;
12+
13+
export const AccountUserSchema = z
14+
.object({
15+
account_id: AccountIdSchema,
16+
first_name: z.string().describe("User's first name.").nullish(),
17+
last_name: z.string().describe("User's last name.").nullish(),
18+
name: z.string().describe("Customizable username").nullish(),
19+
last_active: z
20+
.number()
21+
.min(0)
22+
.nullable()
23+
.describe(
24+
"UNIX timestamp indicating time at which the account was last active.",
25+
),
26+
created: z
27+
.number()
28+
.min(0)
29+
.describe(
30+
"UNIX timestamp indicating time at which the account was created.",
31+
),
32+
banned: z
33+
.boolean()
34+
.optional()
35+
.describe("**Administrators only**. True if this user has been banned."),
36+
email_address_verified: z
37+
.boolean()
38+
.nullish()
39+
.describe("Set to `true` once the user's e-mail has been verified."),
40+
email_address: AccountEmailSchema.optional().describe(
41+
`The account e-mail address.
42+
43+
*Note*: For security reasons, the email_address *only* occurs in search queries
44+
that are by \`email_address\` (or for admins); email addresses of users queried
45+
by substring searches are not revealed.`,
46+
),
47+
})
48+
.describe("User account.");
49+
50+
export type AccountUser = z.infer<typeof AccountUserSchema>;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { z } from "../../framework";
2+
3+
import {
4+
FailedAPIOperationSchema,
5+
SuccessfulAPIOperationSchema,
6+
} from "../common";
7+
8+
// OpenAPI spec
9+
//
10+
export const DeleteAccountOutputSchema = z.union([
11+
FailedAPIOperationSchema,
12+
SuccessfulAPIOperationSchema,
13+
]);
14+
15+
export type DeleteAccountOutput = z.infer<typeof DeleteAccountOutputSchema>;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { z } from "../../framework";
2+
3+
import { FailedAPIOperationSchema } from "../common";
4+
5+
import { AccountEmailSchema, AccountIdSchema } from "./common";
6+
7+
// OpenAPI spec
8+
//
9+
export const GetAccountEmailAddressInputSchema = z
10+
.object({
11+
account_id: AccountIdSchema,
12+
})
13+
.describe(
14+
`**Administrators only**. Used to fetch the e-mail address associated with an
15+
account id.`,
16+
);
17+
18+
export const GetAccountEmailAddressOutputSchema = z.union([
19+
FailedAPIOperationSchema,
20+
z.object({
21+
email_address: AccountEmailSchema,
22+
}),
23+
]);
24+
25+
export type GetAccountEmailAddressInput = z.infer<
26+
typeof GetAccountEmailAddressInputSchema
27+
>;
28+
export type GetAccountEmailAddressOutput = z.infer<
29+
typeof GetAccountEmailAddressOutputSchema
30+
>;
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { z } from "../../framework";
2+
3+
import { FailedAPIOperationSchema } from "../common";
4+
5+
import { AccountIdSchema } from "./common";
6+
import { RequestNoCacheSchema } from "../common";
7+
8+
// OpenAPI spec
9+
//
10+
export const AccountProfileInputSchema = z
11+
.object({
12+
account_id: AccountIdSchema,
13+
noCache: RequestNoCacheSchema,
14+
})
15+
.describe(
16+
`Get the *public* profile for a given account or the private profile of the user
17+
making the request. This is public information if user the user knows the account_id.
18+
It is the color, the name, and the image.`,
19+
);
20+
21+
export const AccountProfileOutputSchema = z.union([
22+
FailedAPIOperationSchema,
23+
z.object({
24+
profile: z
25+
.object({
26+
account_id: AccountIdSchema,
27+
first_name: z.string().describe("First name of account holder."),
28+
last_name: z.string().describe("Last name of account holder."),
29+
image: z
30+
.string()
31+
.describe(
32+
`Account avatar image. This value may be used directly in the \`src\`
33+
attribute of an HTML \`image\` tag`,
34+
)
35+
.optional(),
36+
color: z
37+
.string()
38+
.describe(
39+
`Background color for account avatar if an image is not provided.`,
40+
)
41+
.optional(),
42+
name: z
43+
.union([z.string().describe("Account username"), z.null()])
44+
.describe(
45+
`Account username. This is used to provide a nice URL for public content
46+
associated with this account.`,
47+
),
48+
is_admin: z
49+
.boolean()
50+
.describe("_Included when the full profile is returned.")
51+
.optional(),
52+
is_partner: z
53+
.boolean()
54+
.describe("_Included when the full profile is returned.")
55+
.optional(),
56+
is_anonymous: z
57+
.boolean()
58+
.describe("_Included when the full profile is returned.")
59+
.optional(),
60+
email_address: z.string().describe("The account e-mail address."),
61+
})
62+
.describe("An object containing account profile information."),
63+
}),
64+
]);
65+
66+
export type AccountProfileInput = z.infer<typeof AccountProfileInputSchema>;
67+
export type AccountProfileOutput = z.infer<typeof AccountProfileOutputSchema>;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { z } from "../../framework";
2+
3+
import {
4+
FailedAPIOperationSchema,
5+
SuccessfulAPIOperationSchema,
6+
} from "../common";
7+
8+
import { AccountIdSchema } from "./common";
9+
10+
// OpenAPI spec
11+
//
12+
export const RemoveAccountBanInputSchema = z
13+
.object({
14+
account_id: AccountIdSchema.describe("Account id to remove ban for."),
15+
})
16+
.describe(
17+
"**Administrators only**. Used to remove an existing ban on a user's account",
18+
);
19+
20+
export const RemoveAccountBanOutputSchema = z.union([
21+
FailedAPIOperationSchema,
22+
SuccessfulAPIOperationSchema,
23+
]);
24+
25+
export type RemoveAccountBanInput = z.infer<typeof RemoveAccountBanInputSchema>;
26+
export type RemoveAccountBanOutput = z.infer<
27+
typeof RemoveAccountBanOutputSchema
28+
>;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { z } from "../../framework";
2+
3+
import { FailedAPIOperationSchema } from "../common";
4+
import { AccountUserSchema } from "./common";
5+
6+
// OpenAPI spec
7+
//
8+
export const AccountSearchInputSchema = z
9+
.object({
10+
query: z.string()
11+
.describe(`Comma- or space-delimited) list of account e-mail addresses, account ids,
12+
and/or first/last names to query for an account by.`),
13+
})
14+
.describe(
15+
`Search for accounts matching a given query. If user is signed in, then their
16+
account id is used to prioritize the search.`,
17+
);
18+
19+
export const AccountSearchOutputSchema = z.union([
20+
FailedAPIOperationSchema,
21+
z
22+
.array(AccountUserSchema)
23+
.describe(
24+
"List of matching accounts, sorted by last active and/or account creation date.",
25+
),
26+
]);
27+
28+
export type AccountSearchInput = z.infer<typeof AccountSearchInputSchema>;
29+
export type AccountSearchOutput = z.infer<typeof AccountSearchOutputSchema>;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { z } from "../../framework";
2+
3+
import {
4+
FailedAPIOperationSchema,
5+
SuccessfulAPIOperationSchema,
6+
} from "../common";
7+
8+
import { AccountEmailSchema } from "./common";
9+
10+
// OpenAPI spec
11+
//
12+
export const SendAccountVerificationEmailInputSchema = z
13+
.object({
14+
email_address: AccountEmailSchema,
15+
})
16+
.describe("Send account verification email.");
17+
18+
export const SendAccountVerificationEmailOutputSchema = z.union([
19+
FailedAPIOperationSchema,
20+
SuccessfulAPIOperationSchema,
21+
]);
22+
23+
export type SendAccountVerificationEmailInput = z.infer<
24+
typeof SendAccountVerificationEmailInputSchema
25+
>;
26+
export type SendAccountVerificationEmailOutput = z.infer<
27+
typeof SendAccountVerificationEmailOutputSchema
28+
>;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { z } from "../../framework";
2+
3+
import {
4+
FailedAPIOperationSchema,
5+
SuccessfulAPIOperationSchema,
6+
} from "../common";
7+
8+
import { AccountEmailSchema } from "./common";
9+
10+
// OpenAPI spec
11+
//
12+
export const SetAccountEmailAddressInputSchema = z
13+
.object({
14+
email_address: AccountEmailSchema,
15+
password: z.string().describe("The password for the account."),
16+
})
17+
.describe(
18+
`Set email address of an account. The password must also be provided. If the
19+
email address is already set in the database, then \`password\` must be the current
20+
correct password. If the email address is NOT set, then a new email address and
21+
password are set.`,
22+
);
23+
24+
export const SetAccountEmailAddressOutputSchema = z.union([
25+
FailedAPIOperationSchema,
26+
SuccessfulAPIOperationSchema,
27+
]);
28+
29+
export type SetAccountEmailAddressInput = z.infer<
30+
typeof SetAccountEmailAddressInputSchema
31+
>;
32+
export type SetAccountEmailAddressOutput = z.infer<
33+
typeof SetAccountEmailAddressOutputSchema
34+
>;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { z } from "../../framework";
2+
3+
import {
4+
FailedAPIOperationSchema,
5+
SuccessfulAPIOperationSchema,
6+
} from "../common";
7+
8+
// OpenAPI spec
9+
//
10+
export const SetAccountPasswordInputSchema = z
11+
.object({
12+
currentPassword: z
13+
.string()
14+
.describe("The current password for the account."),
15+
newPassword: z.string().describe("The new password for the account."),
16+
})
17+
.describe("Set password for an existing account.");
18+
19+
export const SetAccountPasswordOutputSchema = z.union([
20+
FailedAPIOperationSchema,
21+
SuccessfulAPIOperationSchema,
22+
]);
23+
24+
export type SetAccountPasswordInput = z.infer<
25+
typeof SetAccountPasswordInputSchema
26+
>;
27+
export type SetAccountPasswordOutput = z.infer<
28+
typeof SetAccountPasswordOutputSchema
29+
>;

0 commit comments

Comments
 (0)