diff --git a/src/lib/api/index.ts b/src/lib/api/index.ts index 30b015fb..99ed65db 100644 --- a/src/lib/api/index.ts +++ b/src/lib/api/index.ts @@ -77,10 +77,6 @@ export { shockerShockerShareCodeUpdate, shockerShockerShareRemove, tokenDeleteDeleteToken, - tokensCreateToken, - tokensEditToken, - tokensListTokens, - tokensReportTokens, usersGetByName, usersGetSelf, versionGetBackendInfo, @@ -121,8 +117,6 @@ export type { SharedShocker, ShockerResponse, ShockerWithDevice, - TokenCreatedResponse, - TokenResponse, UserNameBlacklistDto, WebhookDto, } from './internal/v1'; @@ -132,6 +126,13 @@ export { accountLoginV2, accountSignUpV2, devicesCreateDeviceV2, + tokensCreateTokenV2, + tokensEditTokenV2, + tokensGetTokenByIdV2, + tokensListTokensV2, + tokensReportTokens, + tokensSelfGetSelfTokenV2, + tokensSetTokenPaused, userSharesCreateShareInvite, userSharesDeleteOutgoingInvite, userSharesDenyIncomingInvite, @@ -141,13 +142,22 @@ export { userSharesRedeemInvite, } from './internal/v2'; -export { UsernameAvailability, UsernameErrorType } from './internal/v2'; +export { ControlLimitMode, UsernameAvailability, UsernameErrorType } from './internal/v2'; export type { + CreateTokenRequestV2, + DurationLimitSettings, + EditTokenRequestV2, + IntensityLimitSettings, + SetTokenPausedRequest, ShareInviteBaseDetails, + ShockerControlSettings, ShockerLimits, ShockerPermLimitPairWithIdAndName, ShockerPermissions, + TokenCreatedResponseV2, + TokenPausedResponse, + TokenResponseV2, UserShareInfo, UsernameCheckResponse, V2UserShares, diff --git a/src/lib/api/internal/v2/index.ts b/src/lib/api/internal/v2/index.ts index ce93712c..3bdb52c8 100644 --- a/src/lib/api/internal/v2/index.ts +++ b/src/lib/api/internal/v2/index.ts @@ -1,4 +1,4 @@ // This file is auto-generated by @hey-api/openapi-ts -export { accountCheckUsername, accountLoginV2, accountPasswordResetInitiateV2, accountPasswordResetInitiateV2Legacy, accountSignUpV2, deviceGetLiveControlGatewayV2, devicesCreateDeviceV2, type Options, shockerSendControl, userSharesBulkPauseUserShareShockers, userSharesBulkRemoveUserShareShockers, userSharesBulkUserShareShockersUpdate, userSharesCreateShareInvite, userSharesDeleteOutgoingInvite, userSharesDenyIncomingInvite, userSharesGetIncomingInvitesList, userSharesGetOutgoingInvitesList, userSharesGetSharesByUsers, userSharesRedeemInvite } from './sdk.gen'; -export { type AccountCheckUsernameData, type AccountCheckUsernameResponse, type AccountCheckUsernameResponses, type AccountLoginV2Data, type AccountLoginV2Error, type AccountLoginV2Errors, type AccountLoginV2Response, type AccountLoginV2Responses, type AccountPasswordResetInitiateV2Data, type AccountPasswordResetInitiateV2Error, type AccountPasswordResetInitiateV2Errors, type AccountPasswordResetInitiateV2LegacyData, type AccountPasswordResetInitiateV2LegacyError, type AccountPasswordResetInitiateV2LegacyErrors, type AccountPasswordResetInitiateV2LegacyResponses, type AccountPasswordResetInitiateV2Responses, type AccountSignUpV2Data, type AccountSignUpV2Error, type AccountSignUpV2Errors, type AccountSignUpV2Responses, type BasicUserInfo, type BulkUserShareShockersUpdateRequest, type ChangeUsernameRequest, type ClientOptions, type Control, type ControlRequest, ControlType, type CreateShareRequest, type DeviceGetLiveControlGatewayV2Data, type DeviceGetLiveControlGatewayV2Error, type DeviceGetLiveControlGatewayV2Errors, type DeviceGetLiveControlGatewayV2Response, type DeviceGetLiveControlGatewayV2Responses, type DevicesCreateDeviceV2Data, type DevicesCreateDeviceV2Response, type DevicesCreateDeviceV2Responses, type HubCreateRequest, type LcgNodeResponseV2, type LegacyEmptyResponse, type LoginV2, type LoginV2OkResponse, type OpenShockProblem, type OpenShockProblemWritable, type PasswordResetRequestV2, type PauseUserShareShockersRequest, type PauseUserShareShockersResponse, type RemoveUserSharesResponse, RoleType, type ShareInviteBaseDetails, type ShockerLimits, type ShockerPermissions, type ShockerPermLimitPairWithId, type ShockerPermLimitPairWithIdAndName, type ShockerSendControlData, type ShockerSendControlError, type ShockerSendControlErrors, type ShockerSendControlResponse, type ShockerSendControlResponses, type SignUpV2, UsernameAvailability, type UsernameCheckResponse, type UsernameError, UsernameErrorType, type UserShareInfo, type UserSharesBulkPauseUserShareShockersData, type UserSharesBulkPauseUserShareShockersResponse, type UserSharesBulkPauseUserShareShockersResponses, type UserSharesBulkRemoveUserShareShockersData, type UserSharesBulkRemoveUserShareShockersResponse, type UserSharesBulkRemoveUserShareShockersResponses, type UserSharesBulkUserShareShockersUpdateData, type UserSharesBulkUserShareShockersUpdateError, type UserSharesBulkUserShareShockersUpdateErrors, type UserSharesBulkUserShareShockersUpdateResponses, type UserSharesCreateShareInviteData, type UserSharesCreateShareInviteError, type UserSharesCreateShareInviteErrors, type UserSharesCreateShareInviteResponse, type UserSharesCreateShareInviteResponses, type UserSharesDeleteOutgoingInviteData, type UserSharesDeleteOutgoingInviteError, type UserSharesDeleteOutgoingInviteErrors, type UserSharesDeleteOutgoingInviteResponses, type UserSharesDenyIncomingInviteData, type UserSharesDenyIncomingInviteError, type UserSharesDenyIncomingInviteErrors, type UserSharesDenyIncomingInviteResponses, type UserSharesGetIncomingInvitesListData, type UserSharesGetIncomingInvitesListResponse, type UserSharesGetIncomingInvitesListResponses, type UserSharesGetOutgoingInvitesListData, type UserSharesGetOutgoingInvitesListResponse, type UserSharesGetOutgoingInvitesListResponses, type UserSharesGetSharesByUsersData, type UserSharesGetSharesByUsersResponse, type UserSharesGetSharesByUsersResponses, type UserSharesRedeemInviteData, type UserSharesRedeemInviteError, type UserSharesRedeemInviteErrors, type UserSharesRedeemInviteResponse, type UserSharesRedeemInviteResponses, type V2UserShares, type V2UserSharesListItem } from './types.gen'; +export { accountCheckUsername, accountLoginV2, accountPasswordResetInitiateV2, accountPasswordResetInitiateV2Legacy, accountSignUpV2, deviceGetLiveControlGatewayV2, devicesCreateDeviceV2, type Options, shockerSendControl, tokensCreateTokenV2, tokensEditTokenV2, tokensGetTokenByIdV2, tokensListTokensV2, tokensReportTokens, tokensSelfGetSelfTokenV2, tokensSetTokenPaused, userSharesBulkPauseUserShareShockers, userSharesBulkRemoveUserShareShockers, userSharesBulkUserShareShockersUpdate, userSharesCreateShareInvite, userSharesDeleteOutgoingInvite, userSharesDenyIncomingInvite, userSharesGetIncomingInvitesList, userSharesGetOutgoingInvitesList, userSharesGetSharesByUsers, userSharesRedeemInvite } from './sdk.gen'; +export { type AccountCheckUsernameData, type AccountCheckUsernameResponse, type AccountCheckUsernameResponses, type AccountLoginV2Data, type AccountLoginV2Error, type AccountLoginV2Errors, type AccountLoginV2Response, type AccountLoginV2Responses, type AccountPasswordResetInitiateV2Data, type AccountPasswordResetInitiateV2Error, type AccountPasswordResetInitiateV2Errors, type AccountPasswordResetInitiateV2LegacyData, type AccountPasswordResetInitiateV2LegacyError, type AccountPasswordResetInitiateV2LegacyErrors, type AccountPasswordResetInitiateV2LegacyResponses, type AccountPasswordResetInitiateV2Responses, type AccountSignUpV2Data, type AccountSignUpV2Error, type AccountSignUpV2Errors, type AccountSignUpV2Responses, type BasicUserInfo, type BulkUserShareShockersUpdateRequest, type ChangeUsernameRequest, type ClientOptions, type Control, ControlLimitMode, type ControlRequest, ControlType, type CreateShareRequest, type CreateTokenRequestV2, type DeviceGetLiveControlGatewayV2Data, type DeviceGetLiveControlGatewayV2Error, type DeviceGetLiveControlGatewayV2Errors, type DeviceGetLiveControlGatewayV2Response, type DeviceGetLiveControlGatewayV2Responses, type DevicesCreateDeviceV2Data, type DevicesCreateDeviceV2Response, type DevicesCreateDeviceV2Responses, type DurationLimitSettings, type EditTokenRequestV2, type HubCreateRequest, type IntensityLimitSettings, type LcgNodeResponseV2, type LegacyEmptyResponse, type LoginV2, type LoginV2OkResponse, type OpenShockProblem, type OpenShockProblemWritable, type PasswordResetRequestV2, type PauseUserShareShockersRequest, type PauseUserShareShockersResponse, PermissionType, type RemoveUserSharesResponse, type ReportTokensRequest, RoleType, type SetTokenPausedRequest, type ShareInviteBaseDetails, type ShockerControlSettings, type ShockerLimits, type ShockerPermissions, type ShockerPermLimitPairWithId, type ShockerPermLimitPairWithIdAndName, type ShockerSendControlData, type ShockerSendControlError, type ShockerSendControlErrors, type ShockerSendControlResponse, type ShockerSendControlResponses, type SignUpV2, type TokenCreatedResponseV2, type TokenPausedResponse, type TokenResponseV2, type TokensCreateTokenV2Data, type TokensCreateTokenV2Response, type TokensCreateTokenV2Responses, type TokensEditTokenV2Data, type TokensEditTokenV2Error, type TokensEditTokenV2Errors, type TokensEditTokenV2Responses, type TokensGetTokenByIdV2Data, type TokensGetTokenByIdV2Error, type TokensGetTokenByIdV2Errors, type TokensGetTokenByIdV2Response, type TokensGetTokenByIdV2Responses, type TokensListTokensV2Data, type TokensListTokensV2Response, type TokensListTokensV2Responses, type TokensReportTokensData, type TokensReportTokensResponses, type TokensSelfGetSelfTokenV2Data, type TokensSelfGetSelfTokenV2Response, type TokensSelfGetSelfTokenV2Responses, type TokensSetTokenPausedData, type TokensSetTokenPausedError, type TokensSetTokenPausedErrors, type TokensSetTokenPausedResponse, type TokensSetTokenPausedResponses, UsernameAvailability, type UsernameCheckResponse, type UsernameError, UsernameErrorType, type UserShareInfo, type UserSharesBulkPauseUserShareShockersData, type UserSharesBulkPauseUserShareShockersResponse, type UserSharesBulkPauseUserShareShockersResponses, type UserSharesBulkRemoveUserShareShockersData, type UserSharesBulkRemoveUserShareShockersResponse, type UserSharesBulkRemoveUserShareShockersResponses, type UserSharesBulkUserShareShockersUpdateData, type UserSharesBulkUserShareShockersUpdateError, type UserSharesBulkUserShareShockersUpdateErrors, type UserSharesBulkUserShareShockersUpdateResponses, type UserSharesCreateShareInviteData, type UserSharesCreateShareInviteError, type UserSharesCreateShareInviteErrors, type UserSharesCreateShareInviteResponse, type UserSharesCreateShareInviteResponses, type UserSharesDeleteOutgoingInviteData, type UserSharesDeleteOutgoingInviteError, type UserSharesDeleteOutgoingInviteErrors, type UserSharesDeleteOutgoingInviteResponses, type UserSharesDenyIncomingInviteData, type UserSharesDenyIncomingInviteError, type UserSharesDenyIncomingInviteErrors, type UserSharesDenyIncomingInviteResponses, type UserSharesGetIncomingInvitesListData, type UserSharesGetIncomingInvitesListResponse, type UserSharesGetIncomingInvitesListResponses, type UserSharesGetOutgoingInvitesListData, type UserSharesGetOutgoingInvitesListResponse, type UserSharesGetOutgoingInvitesListResponses, type UserSharesGetSharesByUsersData, type UserSharesGetSharesByUsersResponse, type UserSharesGetSharesByUsersResponses, type UserSharesRedeemInviteData, type UserSharesRedeemInviteError, type UserSharesRedeemInviteErrors, type UserSharesRedeemInviteResponse, type UserSharesRedeemInviteResponses, type V2UserShares, type V2UserSharesListItem } from './types.gen'; diff --git a/src/lib/api/internal/v2/sdk.gen.ts b/src/lib/api/internal/v2/sdk.gen.ts index 2c9706f2..2247cda4 100644 --- a/src/lib/api/internal/v2/sdk.gen.ts +++ b/src/lib/api/internal/v2/sdk.gen.ts @@ -2,8 +2,8 @@ import type { Client, Options as Options2, TDataShape } from './client'; import { client } from './client.gen'; -import { userSharesGetIncomingInvitesListResponseTransformer, userSharesGetOutgoingInvitesListResponseTransformer, userSharesGetSharesByUsersResponseTransformer, userSharesRedeemInviteResponseTransformer } from './transformers.gen'; -import type { AccountCheckUsernameData, AccountCheckUsernameResponses, AccountLoginV2Data, AccountLoginV2Errors, AccountLoginV2Responses, AccountPasswordResetInitiateV2Data, AccountPasswordResetInitiateV2Errors, AccountPasswordResetInitiateV2LegacyData, AccountPasswordResetInitiateV2LegacyErrors, AccountPasswordResetInitiateV2LegacyResponses, AccountPasswordResetInitiateV2Responses, AccountSignUpV2Data, AccountSignUpV2Errors, AccountSignUpV2Responses, DeviceGetLiveControlGatewayV2Data, DeviceGetLiveControlGatewayV2Errors, DeviceGetLiveControlGatewayV2Responses, DevicesCreateDeviceV2Data, DevicesCreateDeviceV2Responses, ShockerSendControlData, ShockerSendControlErrors, ShockerSendControlResponses, UserSharesBulkPauseUserShareShockersData, UserSharesBulkPauseUserShareShockersResponses, UserSharesBulkRemoveUserShareShockersData, UserSharesBulkRemoveUserShareShockersResponses, UserSharesBulkUserShareShockersUpdateData, UserSharesBulkUserShareShockersUpdateErrors, UserSharesBulkUserShareShockersUpdateResponses, UserSharesCreateShareInviteData, UserSharesCreateShareInviteErrors, UserSharesCreateShareInviteResponses, UserSharesDeleteOutgoingInviteData, UserSharesDeleteOutgoingInviteErrors, UserSharesDeleteOutgoingInviteResponses, UserSharesDenyIncomingInviteData, UserSharesDenyIncomingInviteErrors, UserSharesDenyIncomingInviteResponses, UserSharesGetIncomingInvitesListData, UserSharesGetIncomingInvitesListResponses, UserSharesGetOutgoingInvitesListData, UserSharesGetOutgoingInvitesListResponses, UserSharesGetSharesByUsersData, UserSharesGetSharesByUsersResponses, UserSharesRedeemInviteData, UserSharesRedeemInviteErrors, UserSharesRedeemInviteResponses } from './types.gen'; +import { tokensCreateTokenV2ResponseTransformer, tokensGetTokenByIdV2ResponseTransformer, tokensListTokensV2ResponseTransformer, tokensSelfGetSelfTokenV2ResponseTransformer, userSharesGetIncomingInvitesListResponseTransformer, userSharesGetOutgoingInvitesListResponseTransformer, userSharesGetSharesByUsersResponseTransformer, userSharesRedeemInviteResponseTransformer } from './transformers.gen'; +import type { AccountCheckUsernameData, AccountCheckUsernameResponses, AccountLoginV2Data, AccountLoginV2Errors, AccountLoginV2Responses, AccountPasswordResetInitiateV2Data, AccountPasswordResetInitiateV2Errors, AccountPasswordResetInitiateV2LegacyData, AccountPasswordResetInitiateV2LegacyErrors, AccountPasswordResetInitiateV2LegacyResponses, AccountPasswordResetInitiateV2Responses, AccountSignUpV2Data, AccountSignUpV2Errors, AccountSignUpV2Responses, DeviceGetLiveControlGatewayV2Data, DeviceGetLiveControlGatewayV2Errors, DeviceGetLiveControlGatewayV2Responses, DevicesCreateDeviceV2Data, DevicesCreateDeviceV2Responses, ShockerSendControlData, ShockerSendControlErrors, ShockerSendControlResponses, TokensCreateTokenV2Data, TokensCreateTokenV2Responses, TokensEditTokenV2Data, TokensEditTokenV2Errors, TokensEditTokenV2Responses, TokensGetTokenByIdV2Data, TokensGetTokenByIdV2Errors, TokensGetTokenByIdV2Responses, TokensListTokensV2Data, TokensListTokensV2Responses, TokensReportTokensData, TokensReportTokensResponses, TokensSelfGetSelfTokenV2Data, TokensSelfGetSelfTokenV2Responses, TokensSetTokenPausedData, TokensSetTokenPausedErrors, TokensSetTokenPausedResponses, UserSharesBulkPauseUserShareShockersData, UserSharesBulkPauseUserShareShockersResponses, UserSharesBulkRemoveUserShareShockersData, UserSharesBulkRemoveUserShareShockersResponses, UserSharesBulkUserShareShockersUpdateData, UserSharesBulkUserShareShockersUpdateErrors, UserSharesBulkUserShareShockersUpdateResponses, UserSharesCreateShareInviteData, UserSharesCreateShareInviteErrors, UserSharesCreateShareInviteResponses, UserSharesDeleteOutgoingInviteData, UserSharesDeleteOutgoingInviteErrors, UserSharesDeleteOutgoingInviteResponses, UserSharesDenyIncomingInviteData, UserSharesDenyIncomingInviteErrors, UserSharesDenyIncomingInviteResponses, UserSharesGetIncomingInvitesListData, UserSharesGetIncomingInvitesListResponses, UserSharesGetOutgoingInvitesListData, UserSharesGetOutgoingInvitesListResponses, UserSharesGetSharesByUsersData, UserSharesGetSharesByUsersResponses, UserSharesRedeemInviteData, UserSharesRedeemInviteErrors, UserSharesRedeemInviteResponses } from './types.gen'; export type Options = Options2 & { /** @@ -19,6 +19,89 @@ export type Options; }; +/** + * Gets information about the current token used to access this endpoint + */ +export const tokensSelfGetSelfTokenV2 = (options?: Options) => (options?.client ?? client).get({ + responseTransformer: tokensSelfGetSelfTokenV2ResponseTransformer, + responseStyle: 'data', + url: '/2/tokens/self', + ...options +}); + +/** + * Endpoint to delete potentially compromised api tokens + */ +export const tokensReportTokens = (options?: Options) => (options?.client ?? client).post({ + responseStyle: 'data', + url: '/2/tokens/report', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options?.headers + } +}); + +/** + * List all tokens for the current user + */ +export const tokensListTokensV2 = (options?: Options) => (options?.client ?? client).get({ + responseTransformer: tokensListTokensV2ResponseTransformer, + responseStyle: 'data', + url: '/2/tokens', + ...options +}); + +/** + * Create a new token + */ +export const tokensCreateTokenV2 = (options?: Options) => (options?.client ?? client).post({ + responseTransformer: tokensCreateTokenV2ResponseTransformer, + responseStyle: 'data', + url: '/2/tokens', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options?.headers + } +}); + +/** + * Get a token by id + */ +export const tokensGetTokenByIdV2 = (options: Options) => (options.client ?? client).get({ + responseTransformer: tokensGetTokenByIdV2ResponseTransformer, + responseStyle: 'data', + url: '/2/tokens/{tokenId}', + ...options +}); + +/** + * Edit a token + */ +export const tokensEditTokenV2 = (options: Options) => (options.client ?? client).patch({ + responseStyle: 'data', + url: '/2/tokens/{tokenId}', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers + } +}); + +/** + * Set whether a token is paused. A paused token may not send shocker control messages. + */ +export const tokensSetTokenPaused = (options: Options) => (options.client ?? client).patch({ + responseStyle: 'data', + url: '/2/tokens/{tokenId}/paused', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers + } +}); + /** * Check if a username is available */ diff --git a/src/lib/api/internal/v2/transformers.gen.ts b/src/lib/api/internal/v2/transformers.gen.ts index 4b300bfc..2fec6073 100644 --- a/src/lib/api/internal/v2/transformers.gen.ts +++ b/src/lib/api/internal/v2/transformers.gen.ts @@ -1,6 +1,48 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { UserSharesGetIncomingInvitesListResponse, UserSharesGetOutgoingInvitesListResponse, UserSharesGetSharesByUsersResponse, UserSharesRedeemInviteResponse } from './types.gen'; +import type { TokensCreateTokenV2Response, TokensGetTokenByIdV2Response, TokensListTokensV2Response, TokensSelfGetSelfTokenV2Response, UserSharesGetIncomingInvitesListResponse, UserSharesGetOutgoingInvitesListResponse, UserSharesGetSharesByUsersResponse, UserSharesRedeemInviteResponse } from './types.gen'; + +const tokenResponseV2SchemaResponseTransformer = (data: any) => { + data.createdOn = Temporal.Instant.from(data.createdOn); + if (data.validUntil) { + data.validUntil = Temporal.Instant.from(data.validUntil); + } + if (data.lastUsed) { + data.lastUsed = Temporal.Instant.from(data.lastUsed); + } + return data; +}; + +export const tokensSelfGetSelfTokenV2ResponseTransformer = async (data: any): Promise => { + data = tokenResponseV2SchemaResponseTransformer(data); + return data; +}; + +export const tokensListTokensV2ResponseTransformer = async (data: any): Promise => { + data = data.map((item: any) => tokenResponseV2SchemaResponseTransformer(item)); + return data; +}; + +const tokenCreatedResponseV2SchemaResponseTransformer = (data: any) => { + data.createdAt = Temporal.Instant.from(data.createdAt); + if (data.validUntil) { + data.validUntil = Temporal.Instant.from(data.validUntil); + } + if (data.lastUsed) { + data.lastUsed = Temporal.Instant.from(data.lastUsed); + } + return data; +}; + +export const tokensCreateTokenV2ResponseTransformer = async (data: any): Promise => { + data = tokenCreatedResponseV2SchemaResponseTransformer(data); + return data; +}; + +export const tokensGetTokenByIdV2ResponseTransformer = async (data: any): Promise => { + data = tokenResponseV2SchemaResponseTransformer(data); + return data; +}; const userShareInfoSchemaResponseTransformer = (data: any) => { data.createdOn = Temporal.Instant.from(data.createdOn); diff --git a/src/lib/api/internal/v2/types.gen.ts b/src/lib/api/internal/v2/types.gen.ts index 3e394c60..d67ff2be 100644 --- a/src/lib/api/internal/v2/types.gen.ts +++ b/src/lib/api/internal/v2/types.gen.ts @@ -28,6 +28,10 @@ export type Control = { exclusive?: boolean; }; +export const ControlLimitMode = { Clamp: 'Clamp', Lerp: 'Lerp' } as const; + +export type ControlLimitMode = typeof ControlLimitMode[keyof typeof ControlLimitMode]; + export type ControlRequest = { shocks: Array; customName?: string | null; @@ -47,10 +51,35 @@ export type CreateShareRequest = { user?: string | null; }; +export type CreateTokenRequestV2 = { + name: string; + permissions: Array; + shockerControl: ShockerControlSettings; + validUntil?: Temporal.Instant | null; +}; + +export type DurationLimitSettings = { + min: number; + max: number; + mode?: ControlLimitMode; +}; + +export type EditTokenRequestV2 = { + name: string; + permissions: Array; + shockerControl: ShockerControlSettings; +}; + export type HubCreateRequest = { name: string; }; +export type IntensityLimitSettings = { + min: number; + max: number; + mode: ControlLimitMode; +}; + export type LcgNodeResponseV2 = { host: string; port: number; @@ -113,10 +142,25 @@ export type PauseUserShareShockersResponse = { }; }; +export const PermissionType = { + ShockersUse: 'shockers.use', + ShockersEdit: 'shockers.edit', + ShockersPause: 'shockers.pause', + DevicesEdit: 'devices.edit', + DevicesAuth: 'devices.auth' +} as const; + +export type PermissionType = typeof PermissionType[keyof typeof PermissionType]; + export type RemoveUserSharesResponse = { affectedRecords: number; }; +export type ReportTokensRequest = { + turnstileResponse: string; + secrets: Array; +}; + export const RoleType = { Support: 'Support', Staff: 'Staff', @@ -126,6 +170,13 @@ export const RoleType = { export type RoleType = typeof RoleType[keyof typeof RoleType]; +export type SetTokenPausedRequest = { + /** + * When true, the token is paused and may not send shocker control messages. + */ + paused: boolean; +}; + export type ShareInviteBaseDetails = { id: string; createdAt: Temporal.Instant; @@ -134,6 +185,18 @@ export type ShareInviteBaseDetails = { shockers: Array; }; +/** + * Per-token shocker control configuration: a toggle plus min/max limits for intensity and duration. + */ +export type ShockerControlSettings = { + /** + * When true, this token is paused and may not send shocker control messages. + */ + paused: boolean; + intensity: IntensityLimitSettings; + duration: DurationLimitSettings; +}; + export type ShockerLimits = { intensity: number | null; duration: number | null; @@ -166,6 +229,34 @@ export type SignUpV2 = { turnstileResponse: string; }; +export type TokenCreatedResponseV2 = { + id: string; + name: string; + token: string; + createdAt: Temporal.Instant; + validUntil: Temporal.Instant | null; + lastUsed: Temporal.Instant | null; + permissions: Array; + shockerControl: ShockerControlSettings; +}; + +export type TokenPausedResponse = { + /** + * The now-set paused state of the token. + */ + paused: boolean; +}; + +export type TokenResponseV2 = { + id: string; + name: string; + createdOn: Temporal.Instant; + validUntil: Temporal.Instant | null; + lastUsed: Temporal.Instant | null; + permissions: Array; + shockerControl: ShockerControlSettings; +}; + export type UserShareInfo = { id: string; name: string; @@ -237,6 +328,147 @@ export type OpenShockProblemWritable = { [key: string]: unknown; }; +export type TokensSelfGetSelfTokenV2Data = { + body?: never; + path?: never; + query?: never; + url: '/2/tokens/self'; +}; + +export type TokensSelfGetSelfTokenV2Responses = { + /** + * OK + */ + 200: TokenResponseV2; +}; + +export type TokensSelfGetSelfTokenV2Response = TokensSelfGetSelfTokenV2Responses[keyof TokensSelfGetSelfTokenV2Responses]; + +export type TokensReportTokensData = { + body?: ReportTokensRequest; + path?: never; + query?: never; + url: '/2/tokens/report'; +}; + +export type TokensReportTokensResponses = { + /** + * The tokens were deleted if found + */ + 200: unknown; +}; + +export type TokensListTokensV2Data = { + body?: never; + path?: never; + query?: never; + url: '/2/tokens'; +}; + +export type TokensListTokensV2Responses = { + /** + * All tokens for the current user + */ + 200: Array; +}; + +export type TokensListTokensV2Response = TokensListTokensV2Responses[keyof TokensListTokensV2Responses]; + +export type TokensCreateTokenV2Data = { + body?: CreateTokenRequestV2; + path?: never; + query?: never; + url: '/2/tokens'; +}; + +export type TokensCreateTokenV2Responses = { + /** + * The created token + */ + 200: TokenCreatedResponseV2; +}; + +export type TokensCreateTokenV2Response = TokensCreateTokenV2Responses[keyof TokensCreateTokenV2Responses]; + +export type TokensGetTokenByIdV2Data = { + body?: never; + path: { + tokenId: string; + }; + query?: never; + url: '/2/tokens/{tokenId}'; +}; + +export type TokensGetTokenByIdV2Errors = { + /** + * The token does not exist or you do not have access to it. + */ + 404: OpenShockProblem; +}; + +export type TokensGetTokenByIdV2Error = TokensGetTokenByIdV2Errors[keyof TokensGetTokenByIdV2Errors]; + +export type TokensGetTokenByIdV2Responses = { + /** + * The token + */ + 200: TokenResponseV2; +}; + +export type TokensGetTokenByIdV2Response = TokensGetTokenByIdV2Responses[keyof TokensGetTokenByIdV2Responses]; + +export type TokensEditTokenV2Data = { + body?: EditTokenRequestV2; + path: { + tokenId: string; + }; + query?: never; + url: '/2/tokens/{tokenId}'; +}; + +export type TokensEditTokenV2Errors = { + /** + * The token does not exist or you do not have access to it. + */ + 404: OpenShockProblem; +}; + +export type TokensEditTokenV2Error = TokensEditTokenV2Errors[keyof TokensEditTokenV2Errors]; + +export type TokensEditTokenV2Responses = { + /** + * The edited token + */ + 200: unknown; +}; + +export type TokensSetTokenPausedData = { + body?: SetTokenPausedRequest; + path: { + tokenId: string; + }; + query?: never; + url: '/2/tokens/{tokenId}/paused'; +}; + +export type TokensSetTokenPausedErrors = { + /** + * The token does not exist or you do not have access to it. + */ + 404: OpenShockProblem; +}; + +export type TokensSetTokenPausedError = TokensSetTokenPausedErrors[keyof TokensSetTokenPausedErrors]; + +export type TokensSetTokenPausedResponses = { + /** + * The now-set paused state of the token. + */ + 200: TokenPausedResponse; +}; + +export type TokensSetTokenPausedResponse = TokensSetTokenPausedResponses[keyof TokensSetTokenPausedResponses]; + export type AccountCheckUsernameData = { body?: ChangeUsernameRequest; path?: never; diff --git a/src/lib/components/ExpirationPicker.svelte b/src/lib/components/ExpirationPicker.svelte index 37d8e0d7..fe3eb504 100644 --- a/src/lib/components/ExpirationPicker.svelte +++ b/src/lib/components/ExpirationPicker.svelte @@ -1,5 +1,5 @@ - - - API Tokens
- diff --git a/src/routes/(app)/settings/api-tokens/data-table-actions.svelte b/src/routes/(app)/settings/api-tokens/data-table-actions.svelte index 61acfb1d..ddc56b82 100644 --- a/src/routes/(app)/settings/api-tokens/data-table-actions.svelte +++ b/src/routes/(app)/settings/api-tokens/data-table-actions.svelte @@ -1,37 +1,105 @@ - - +{#snippet editSnippet(props: DialogRenderProps)} + +{/snippet} + +{#snippet deleteDescSnippet(t: TokenResponseV2)} + Are you sure you want to delete {t.name}?
+ This action cannot be undone. This will permanently delete the token. +{/snippet} + +
+ + + {#if token.shockerControl.paused} + + {:else} + + {/if} + + +

{token.shockerControl.paused ? 'Resume token' : 'Pause token'}

+
+
- - Copy ID - (editDialogOpen = true)}> - Edit - - Delete - + + Copy ID + + {token.shockerControl.paused ? 'Resume' : 'Pause'} + + Edit + Delete + +
diff --git a/src/routes/(app)/settings/api-tokens/dialog-token-create.svelte b/src/routes/(app)/settings/api-tokens/dialog-token-create.svelte deleted file mode 100644 index 2dcaed52..00000000 --- a/src/routes/(app)/settings/api-tokens/dialog-token-create.svelte +++ /dev/null @@ -1,123 +0,0 @@ - - - - - open, onOpenChange}> - - - New API Token - Please make sure to select the appropriate permissions for the token. - - - diff --git a/src/routes/(app)/settings/api-tokens/dialog-token-created.svelte b/src/routes/(app)/settings/api-tokens/dialog-token-created.svelte deleted file mode 100644 index d90f353d..00000000 --- a/src/routes/(app)/settings/api-tokens/dialog-token-created.svelte +++ /dev/null @@ -1,37 +0,0 @@ - - - token !== null, onOpenChanged}> - - - API Token Generated - - Please copy your API Token now, you will not be able to view it again later! - - -
-
- - {#snippet icon()} - - {/snippet} - -
-
-
-
diff --git a/src/routes/(app)/settings/api-tokens/dialog-token-delete.svelte b/src/routes/(app)/settings/api-tokens/dialog-token-delete.svelte deleted file mode 100644 index df49dbaa..00000000 --- a/src/routes/(app)/settings/api-tokens/dialog-token-delete.svelte +++ /dev/null @@ -1,33 +0,0 @@ - - - - {#snippet description()} - Are you sure you want to delete {token?.name}?
- This action cannot be undone. This will permanently delete the token. - {/snippet} -
diff --git a/src/routes/(app)/settings/api-tokens/dialog-token-edit.svelte b/src/routes/(app)/settings/api-tokens/dialog-token-edit.svelte index 25e01c52..a45b03cc 100644 --- a/src/routes/(app)/settings/api-tokens/dialog-token-edit.svelte +++ b/src/routes/(app)/settings/api-tokens/dialog-token-edit.svelte @@ -1,40 +1,46 @@ - - - - Edit API Token - - -