Skip to content

Commit

Permalink
restrictionForUser
Browse files Browse the repository at this point in the history
  • Loading branch information
Cameron Campbell authored and Cameron Campbell committed Aug 20, 2024
1 parent 393677a commit 92c187b
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 49 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "openblox",
"description": "Roblox API Wrapper For Both Classic And OpenCloud APIs.",
"type": "commonjs",
"version": "1.0.45",
"version": "1.0.46",
"license": "MIT",
"bugs": {
"url": "https://github.com/MightyPart/openblox/issues"
Expand Down
51 changes: 31 additions & 20 deletions src/apis/cloud/userRestrictions/userRestrictions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { cloneAndMutateObject } from "../../../utils/utils"


// [ Types ] /////////////////////////////////////////////////////////////////////
import type { Identifier, ISODateTime } from "typeforge"
import type { Identifier, ISODateTime, StringIsLiteral } from "typeforge"

import type { ApiMethod } from "../../apiGroup"
import type { PrettifiedListRestrictionLogsData, PrettifiedUserRestrictionsData, RawListRestrictionLogsData, RawUserRestrictionsData, UpdateUserRestrictionsData } from "./userRestrictions.types"
import type { PrettifiedListRestrictionLogsData, RawListRestrictionLogsData, UpdateRestrictionsForUserData, UpdateUserRestrictionsData, UserRestrictionsData } from "./userRestrictions.types"
//////////////////////////////////////////////////////////////////////////////////


Expand All @@ -33,31 +33,48 @@ const addApiMethod = createApiGroup({ name: "UserRestrictions", baseUrl: "https:
* @param userId The ID of the uset to get restrictions to get.
*
* @example
* const { data:restrictions } = await UserRestrictionsApi.restrictions({
* const { data:restrictions } = await UserRestrictionsApi.listRestrictions({
universeId: 5795192361, placeId: 18210254887, userId: 6193495014
})
* @exampleData {"path":"universes/5795192361/places/18210254887/user-restrictions/6193495014","user":"users/6193495014","gameJoinRestriction":{"active":true,"startTime":"2024-06-25T22:56:58.873Z","duration":"31540000s","privateReason":"Being a meanie :/","displayReason":"Annoying other players.","excludeAltAccounts":false,"inherited":false}}
* @exampleRawBody {"path":"universes/5795192361/places/18210254887/user-restrictions/6193495014","user":"users/6193495014","gameJoinRestriction":{"active":true,"startTime":"2024-06-25T22:56:58.873Z","duration":"31540000s","privateReason":"Being a meanie :/","displayReason":"Annoying other players.","excludeAltAccounts":false,"inherited":false}}
*/
export const restrictions = addApiMethod(async <
export const listRestrictions = addApiMethod(async <
UniverseId extends Identifier, UserId extends Identifier, PlaceId extends Identifier | undefined = undefined
>(
{ universeId, placeId, userId }:
{ universeId: UniverseId, placeId?: PlaceId, userId: UserId }
): ApiMethod<RawUserRestrictionsData<UniverseId, UserId, PlaceId>, PrettifiedUserRestrictionsData<UniverseId, UserId, PlaceId>> => ({
): ApiMethod<UserRestrictionsData<UniverseId, UserId, PlaceId>> => ({
method: "GET",
path: (
placeId ? `/v2/universes/${universeId}/places/${placeId}/user-restrictions/${userId}`
: `/v2/universes/${universeId}/user-restrictions/${userId}`
),
name: `restrictions`,

formatRawDataFn: (rawData) => cloneAndMutateObject(rawData, ({ gameJoinRestriction }) => {
gameJoinRestriction.startTime = new Date(gameJoinRestriction.startTime)
})
name: `listRestrictions`
}))


/**
* Gets the active restriction for a user in a given universe.
* @endpoint GET /cloud/v2/universes/{universeId}/user-restrictions/{userId}
*
* @param universeId The ID of the universe to get restriction from.
* @param userId The ID of the user to get restriction for.
*
* @example
* @exampleData
* @exampleRawBody
*/
export const restrictionForUser = addApiMethod(async <UniverseId extends Identifier, UserId extends Identifier, PlaceId extends Identifier>(
{ universeId, placeId, userId }: { universeId: Identifier, placeId?: Identifier, userId: Identifier }
): ApiMethod<UserRestrictionsData<UniverseId, UserId, PlaceId>> => ({
method: "GET",
path: (
placeId ? `/v2/universes/${universeId}/places/${placeId}/user-restrictions/${userId}`
: `/v2/universes/${universeId}/places/${placeId}/user-restrictions/${userId}`
),
name: `restrictionForUser`,
}))


/**
Expand All @@ -84,8 +101,7 @@ export const restrictions = addApiMethod(async <
duration: "31540000s", // 1 year.
privateReason: "Being a meanie :/",
displayReason: "Annoying other players.",
excludeAltAccounts: false,
inherited: true
excludeAltAccounts: false
}
}
})
Expand All @@ -102,21 +118,16 @@ export const updateRestrictionsForUser = addApiMethod(async <
updatedData: UpdatedData, idempotencyKey?: string, firstSent?: Date | ISODateTime
}
): ApiMethod<
RawUserRestrictionsData<UniverseId, UserId, PlaceId, UpdatedData>,
PrettifiedUserRestrictionsData<UniverseId, UserId, PlaceId, UpdatedData>
> => ({
UpdateRestrictionsForUserData<UniverseId, UserId, PlaceId, UpdatedData>
> => ({
method: "PATCH",
path: (
placeId ? `/v2/universes/${universeId}/places/${placeId}/user-restrictions/${userId}`
: `/v2/universes/${universeId}/user-restrictions/${userId}`
),
searchParams: { "idempotencyKey.key": idempotencyKey, "idempotencyKey.firstSent": firstSent },
body: updatedData,
name: `updateRestrictionsForUser`,

formatRawDataFn: (rawData) => cloneAndMutateObject(rawData, ({ gameJoinRestriction }) => {
gameJoinRestriction.startTime = new Date(gameJoinRestriction.startTime)
})
name: `updateRestrictionsForUser`
}))


Expand Down
76 changes: 48 additions & 28 deletions src/apis/cloud/userRestrictions/userRestrictions.types.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,25 @@
import type { Identifier, ISODateTime, ObjectPrettify } from "typeforge";
import type { Identifier, ObjectPrettify, StringIsLiteral } from "typeforge";


type UserRestrictionsData<
TemporalType,
UniverseId extends Identifier, UserId extends Identifier, PlaceId extends Identifier | undefined = undefined,

UpdatedData extends UpdateUserRestrictionsData = UpdateUserRestrictionsData,
_GameJoinRestriction extends UpdatedData["gameJoinRestriction"] = UpdatedData["gameJoinRestriction"]
export type UserRestrictionsData<
UniverseId extends Identifier, UserId extends Identifier, PlaceId extends Identifier | undefined = undefined
> = {
path: (
PlaceId extends Identifier ? `universes/${UniverseId}/places/${PlaceId}/user-restrictions/${UserId}`
: `universes/${UniverseId}/user-restrictions/${UserId}`
),
user: `users/${UserId}`,

gameJoinRestriction: {
active: _GameJoinRestriction["active"],
startTime: TemporalType,
duration: _GameJoinRestriction["duration"],
privateReason: _GameJoinRestriction["privateReason"],
displayReason: _GameJoinRestriction["displayReason"],
excludeAltAccounts: _GameJoinRestriction["excludeAltAccounts"],
active: boolean,
startTime: string,
duration?: `${number}s`,
privateReason: string,
displayReason: string,
excludeAltAccounts: boolean,
inherited: boolean
}
}

export type RawUserRestrictionsData<
UniverseId extends Identifier, UserId extends Identifier,
PlaceId extends Identifier | undefined = undefined,
UpdatedData extends UpdateUserRestrictionsData = UpdateUserRestrictionsData,
> = UserRestrictionsData<ISODateTime, UniverseId, UserId, PlaceId, UpdatedData>

export type PrettifiedUserRestrictionsData<
UniverseId extends Identifier, UserId extends Identifier,
PlaceId extends Identifier | undefined = undefined,
UpdatedData extends UpdateUserRestrictionsData = UpdateUserRestrictionsData,
> = UserRestrictionsData<Date, UniverseId, UserId, PlaceId, UpdatedData>


/* PATCH /v2/universes/{universe}/user-restrictions/{user-restriction}
PATCH /v2/universes/{universeId}/places/{placeId}/user-restrictions/{userId --------------------------------- */
Expand All @@ -46,9 +29,46 @@ export type UpdateUserRestrictionsData = {
duration?: `${number}s`,
privateReason: string,
displayReason: string,
excludeAltAccounts?: boolean,
excludeAltAccounts: boolean,
}
}



export type UpdateRestrictionsForUserData<
UniverseId extends Identifier, UserId extends Identifier, PlaceId extends Identifier | undefined = undefined,

UpdatedData extends UpdateUserRestrictionsData = UpdateUserRestrictionsData,

_GameJoinRestriction extends UpdatedData["gameJoinRestriction"] = UpdatedData["gameJoinRestriction"],
_Active = _GameJoinRestriction["active"], _Duration = _GameJoinRestriction["duration"]
> = {
path: (
PlaceId extends Identifier ? `universes/${UniverseId}/places/${PlaceId}/user-restrictions/${UserId}`
: `universes/${UniverseId}/user-restrictions/${UserId}`
),
user: `users/${UserId}`,

gameJoinRestriction: {
[Key in keyof Omit<{
active: _Active,
startTime: string,
duration: _Duration,
privateReason: _GameJoinRestriction["privateReason"],
displayReason: _GameJoinRestriction["displayReason"],
excludeAltAccounts: _GameJoinRestriction["excludeAltAccounts"],
inherited: boolean
}, StringIsLiteral<_Duration> extends true ? "" : "duration">]: Omit<{
active: _Active,
startTime: string,
duration: _Duration,
privateReason: _GameJoinRestriction["privateReason"],
displayReason: _GameJoinRestriction["displayReason"],
excludeAltAccounts: _GameJoinRestriction["excludeAltAccounts"],
inherited: boolean
}, StringIsLiteral<_Duration> extends true ? "" : "duration">[Key]
}
}
// -------------------------------------------------------------------------------------------------------------------


Expand All @@ -69,7 +89,7 @@ type RestrictionLogEntry<TemporalType, UserId extends Identifier = Identifier, P
}>

export type RawListRestrictionLogsData<UserId extends Identifier = Identifier, PlaceId extends Identifier = Identifier> = {
logs: RestrictionLogEntry<ISODateTime, UserId, PlaceId>[],
logs: RestrictionLogEntry<string, UserId, PlaceId>[],
nextPageToken: string
}

Expand Down

0 comments on commit 92c187b

Please sign in to comment.