Files
speckle-server/packages/server/modules/auth/domain/operations.ts
T
Kristaps Fabians Geikins f5e4e09c9f chore(server): auth IoC 11 - createAppTokenFromAccessCodeFactory (#3032)
* chore(server): auth IoC 3 - getAllAppsCreatedByUserFactory

* minor fix

* chore(server): auth IoC 4 - getAllAppsAuthorizedByUserFactory

* chore(server): auth IoC 5 - createAppFactory

* chore(server): auth IoC 6 - updateAppFactory

* chore(server): auth IoC 7 - deleteAppFactory

* chore(server): auth IoC 8 - revokeExistingAppCredentialsForUserFactory

* chore(server): auth IoC 9 - revokeRefreshTokenFactory

* chore(server): auth IoC 10 - createAuthorizationCodeFactory

* chore(server): auth IoC 11 - createAppTokenFromAccessCodeFactory

---------

Co-authored-by: Gergő Jedlicska <gergo@jedlicska.com>
2024-09-19 09:58:37 +02:00

91 lines
2.5 KiB
TypeScript

import { DefaultAppWithUnwrappedScopes } from '@/modules/auth/defaultApps'
import {
FullServerApp,
ServerAppListItem,
UserServerApp
} from '@/modules/auth/domain/types'
import { ScopeRecord } from '@/modules/auth/helpers/types'
import {
AuthorizationCodeRecord,
RefreshTokenRecord
} from '@/modules/auth/repositories'
import { ServerAppRecord } from '@/modules/core/helpers/types'
import { MarkNullableOptional } from '@/modules/shared/helpers/typeHelper'
import { Optional, ServerScope } from '@speckle/shared'
import { SetOptional } from 'type-fest'
export type GetApp = (params: { id: string }) => Promise<FullServerApp | null>
export type GetAllPublicApps = () => Promise<ServerAppListItem[]>
export type GetAllAppsCreatedByUser = (params: {
userId: string
}) => Promise<UserServerApp[]>
export type GetAllAppsAuthorizedByUser = (params: {
userId: string
}) => Promise<ServerAppListItem[]>
export type GetAllScopes = () => Promise<ScopeRecord[]>
export type RegisterDefaultApp = (app: DefaultAppWithUnwrappedScopes) => Promise<void>
export type UpdateDefaultApp = (
app: DefaultAppWithUnwrappedScopes,
existingApp: FullServerApp
) => Promise<void>
export type CreateApp = (
app: Omit<
MarkNullableOptional<ServerAppRecord>,
'id' | 'secret' | 'createdAt' | 'trustByDefault'
> & {
scopes: ServerScope[]
}
) => Promise<{ id: string; secret: string }>
export type RevokeExistingAppCredentials = (params: {
appId: string
}) => Promise<number>
export type RevokeExistingAppCredentialsForUser = (params: {
appId: string
userId: string
}) => Promise<number>
export type RevokeRefreshToken = (params: { tokenId: string }) => Promise<boolean>
export type UpdateApp = (params: {
app: Partial<ServerAppRecord> & { id: string } & { scopes?: ServerScope[] }
}) => Promise<string>
export type DeleteApp = (params: { id: string }) => Promise<number>
export type GetAuthorizationCode = (params: {
id: string
}) => Promise<Optional<AuthorizationCodeRecord>>
export type DeleteAuthorizationCode = (params: { id: string }) => Promise<number>
export type CreateRefreshToken = (params: {
token: SetOptional<RefreshTokenRecord, 'createdAt' | 'lifespan'>
}) => Promise<RefreshTokenRecord>
export type CreateAuthorizationCode = (params: {
appId: string
userId: string
challenge: string
}) => Promise<string>
export type InitializeDefaultApps = () => Promise<void>
export type CreateAppTokenFromAccessCode = (params: {
appId: string
appSecret: string
accessCode: string
challenge: string
}) => Promise<{
token: string
refreshToken: string
}>