This commit is contained in:
tamaina
2023-06-04 16:41:45 +00:00
parent f651ca4b48
commit 35b1f73b51
9 changed files with 149 additions and 151 deletions

View File

@@ -2341,7 +2341,113 @@ export const endpoints = {
$ref: 'https://misskey-hub.net/api/schemas/App',
},
}],
}
},
//#endregion
//#region auth
'auth/session/genrate': {
tags: ['auth'],
requireCredential: false,
errors: {
noSuchApp: {
message: 'No such app.',
code: 'NO_SUCH_APP',
id: '92f93e63-428e-4f2f-a5a4-39e1407fe998',
},
},
defines: [{
req: {
type: 'object',
properties: {
appSecret: { type: 'string' },
},
required: ['appSecret'],
},
res: {
type: 'object',
properties: {
token: { type: 'string' },
url: { type: 'string', format: 'url' },
},
required: ['token', 'url'],
},
}],
},
'auth/session/show': {
tags: ['auth'],
requireCredential: false,
errors: {
noSuchSession: {
message: 'No such session.',
code: 'NO_SUCH_SESSION',
id: 'bd72c97d-eba7-4adb-a467-f171b8847250',
},
},
defines: [{
req: {
type: 'object',
properties: {
token: { type: 'string' },
},
required: ['token'],
},
res: {
$ref: 'https://misskey-hub.net/api/schemas/AuthSession',
},
}],
},
'auth/session/userkey': {
tags: ['auth'],
requireCredential: false,
errors: {
noSuchApp: {
message: 'No such app.',
code: 'NO_SUCH_APP',
id: 'fcab192a-2c5a-43b7-8ad8-9b7054d8d40d',
},
noSuchSession: {
message: 'No such session.',
code: 'NO_SUCH_SESSION',
id: '5b5a1503-8bc8-4bd0-8054-dc189e8cdcb3',
},
pendingSession: {
message: 'This session is not completed yet.',
code: 'PENDING_SESSION',
id: '8c8a4145-02cc-4cca-8e66-29ba60445a8e',
},
},
defines: [{
req: {
type: 'object',
properties: {
appSecret: { type: 'string' },
token: { type: 'string' },
},
required: ['appSecret', 'token'],
},
res: {
type: 'object',
properties: {
accessToken: { type: 'string' },
user: {
$ref: 'https://misskey-hub.net/api/schemas/UserDetailedNotMe',
}
},
required: ['accessToken', 'user'],
}
}],
},
//#endregion
} as const satisfies { [x: string]: IEndpointMeta; };

View File

@@ -119,11 +119,7 @@ export type Stats = {
driveUsageRemote: number;
};
export type AuthSession = {
id: ID;
app: App;
token: string;
};
export type AuthSession = Serialized<Packed<'AuthSession'>>;
export type FollowRequest = {
id: ID;

View File

@@ -56,6 +56,7 @@ import {
SignInSchema,
} from './schemas/sign-in.js';
import { packedModerationLogSchema } from './schemas/moderation-log.js';
import { packedAuthSessionSchema } from './schemas/auth-session.js';
import { Error, ApiError } from './schemas/error.js';
import type { JSONSchema7, JSONSchema7Definition, GetDef, GetRefs, GetKeys, UnionToArray } from 'schema-type';
@@ -109,6 +110,7 @@ export const refs = {
ServerInfoAdmin: ServerInfoAdminSchema,
ModerationLog: packedModerationLogSchema,
SignIn: SignInSchema,
AuthSession: packedAuthSessionSchema,
Error: Error,
ApiError: ApiError,

View File

@@ -0,0 +1,19 @@
import type { JSONSchema7Definition } from 'schema-type';
export const packedAuthSessionSchema = {
$id: 'https://misskey-hub.net/api/schemas/AuthSession',
type: 'object',
properties: {
id: { $ref: 'https://misskey-hub.net/api/schemas/Id' },
app: { $ref: 'https://misskey-hub.net/api/schemas/App' },
token: {
type: 'string',
},
},
required: [
'id',
'app',
'token',
],
} as const satisfies JSONSchema7Definition;

View File

@@ -1,3 +1,4 @@
import { test } from 'node:test';
import { Packed, Def } from '../src/schemas';
import { expectType } from 'tsd';
@@ -122,6 +123,9 @@ describe('schemas', () => {
test('moderation log', () => {
type ModerationLog = Packed<'ModerationLog'>;
});
test('auth session', () => {
type AuthSession = Packed<'AuthSession'>;
});
test('error', () => {
type Error = Packed<'Error'>;
type ApiError = Packed<'ApiError'>;