Skip to content

Commit

Permalink
added group featured events api; added ordered data stores api; added…
Browse files Browse the repository at this point in the history
… standard datastore snapshot api
  • Loading branch information
Cameron Campbell authored and Cameron Campbell committed Jul 29, 2024
1 parent ba2c17b commit 12b4cf3
Show file tree
Hide file tree
Showing 9 changed files with 364 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "openblox",
"type": "commonjs",
"version": "1.0.23",
"version": "1.0.24",
"license": "MIT",
"bugs": {
"url": "https://github.com/MightyPart/openblox/issues"
Expand Down
45 changes: 34 additions & 11 deletions src/apis/classic/groups/groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { readFile } from "../../../file"


// [ Types ] /////////////////////////////////////////////////////////////////////
import type { ArrayNonEmpty, Identifier, UnionToArray } from "typeforge"
import type { Identifier, UnionToArray } from "typeforge"

import type { ApiMethod } from "../../apiGroup"
import type { AddGroupSocialLinkData, AuthenticatedUserGroupMembershipInfoData, FormattedAllGroupRolesForUserData_V1, GroupAuditLogActionType, GroupPayoutRestrictionsInfoData, GroupRelationshipType, GroupRolePermissions, GroupRolePermissionsData, GroupsConfigMetadataData, GroupSettingsData, GroupsMetadataData, NewSocialLinkRequest, PrettifiedAllGroupRolesForUserData_V2, PrettifiedAllRolesForGroupData, PrettifiedAuthenticatedUserPendingGroupsData, PrettifiedGroupAuditLogData, PrettifiedGroupIdsToGroupsInfoData, PrettifiedGroupInfoData, PrettifiedGroupJoinRequestForUser, PrettifiedGroupJoinRequests, PrettifiedGroupLookupSearch, PrettifiedGroupMembersData, PrettifiedGroupMembersWithRoleData, PrettifiedGroupNameHistoryData, PrettifiedGroupPayoutsInfoData, PrettifiedGroupPermissionsForAllRoles, PrettifiedGroupPolicyInfoData, PrettifiedGroupRelationshipsData, PrettifiedGroupRolesFromIdsData, PrettifiedGroupSearchData, PrettifiedGroupSearchMetadata, PrettifiedGroupShoutData, PrettifiedGroupSocialLinksData, PrettifiedGroupsThatUsersFriendsAreInData, PrettifiedGroupWallPostsData_V1, PrettifiedGroupWallPostsData_V2, PrettifiedPrimaryGroupForUserData, RawAllGroupRolesForUserData_V1, RawAllGroupRolesForUserData_V2, RawAllRolesForGroupData, RawAuthenticatedUserPendingGroupsData, RawGroupAuditLogData, RawGroupIdsToGroupsInfoData, RawGroupInfoData, RawGroupJoinRequestForUser, RawGroupJoinRequests, RawGroupLookupSearch, RawGroupMembersData, RawGroupMembersWithRoleData, RawGroupNameHistoryData, RawGroupPayoutsInfoData, RawGroupPermissionsForAllRoles, RawGroupPolicyInfoData, RawGroupRelationshipsData, RawGroupRolesFromIdsData, RawGroupSearchData, RawGroupSearchMetadata, RawGroupShoutData, RawGroupSocialLinksData, RawGroupsThatUsersFriendsAreInData, RawGroupWallPostsData_V1, RawGroupWallPostsData_V2, RawPrimaryGroupForUserData, UpdateRoleSetData, UpdateRoleSetRequest } from "./groups.types"
Expand Down Expand Up @@ -43,24 +43,47 @@ export const featuredEvent = addApiMethod(async <GroupId extends Identifier>(


/**
* Sets the featured event for a group.
* @endpoint REST /...
* Sets a featured event for a group.
* @endpoint POST /v1/featured-content/event
*
* @param
* @param groupId The ID of the group to set the event for.
* @param eventId The ID of the event to set.
*
* @example
* @exampleData
* @exampleRawBody
* @example const { data:eventId } = await ClassicGroupsApi.setFeaturedEvent({ groupId: 15842838, eventId: "5904751593700196492" })
* @exampleData 5904751593700196492
* @exampleRawBody {"groupId":15842838,"contentType":"event","contentId":"6533473338141704368"}
*/
export const setFeaturedEvent = addApiMethod(async <GroupId extends Identifier>(
{ groupId, eventId }: { groupId: Identifier, eventId: Identifier }
): ApiMethod<{ groupId: GroupId, contentType: "event", contentId: Identifier }, Identifier> => ({
export const setFeaturedEvent = addApiMethod(async <GroupId extends Identifier, EventId extends Identifier>(
{ groupId, eventId }: { groupId: Identifier, eventId: EventId }
): ApiMethod<{ groupId: GroupId, contentType: "event", contentId: EventId }, EventId> => ({
method: "POST",
path: `/v1/featured-content/event`,
searchParams: { groupId, eventId },
name: `setFeaturedEvent`,

prettifyFn: ({ contentId }) => contentId
prettifyFn: ({ contentId }) => contentId as any
}))

/**
* Removes a featured event for a group.
* @endpoint POST /v1/featured-content/event
*
* @param groupId The ID of the group to remove the event from.
* @param eventId The ID of the event to remove.
*
* @example const { data:success } = await ClassicGroupsApi.removeFeaturedEvent({ groupId: 15842838, eventId: "5904751593700196492" })
* @exampleData true
* @exampleRawBody ""
*/
export const removeFeaturedEvent = addApiMethod(async <GroupId extends Identifier, EventId extends Identifier>(
{ groupId, eventId }: { groupId: Identifier, eventId: EventId }
): ApiMethod<"", boolean> => ({
method: "DELETE",
path: `/v1/featured-content/event`,
searchParams: { groupId, eventId },
name: `removeFeaturedEvent`,

prettifyFn: rawData => rawData === ""
}))
/////////////////////////////////////////////////////////////////////////////////

Expand Down
1 change: 1 addition & 0 deletions src/apis/cloud/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export * as CreatorStoreApi from "./creatorStore"
export * as StandardDatastoresApi_V1 from "./standardDataStores_V1"
export * as OrderedDatastoresApi_V1 from "./orderedDataStores_V1"
export * as StandardDataStoresApi_V2 from "./standardDataStores_V2"
export * as OrderedDatastoresApi_V2 from "./orderedDataStores_V2"
export * as UserRestrictionsApi from "./userRestrictions"
export * as EngineApi from "./engine"
export * as AssetsApi from "./assets"
Expand Down
1 change: 1 addition & 0 deletions src/apis/cloud/orderedDataStores_V2/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./orderedDataStores_V2"
216 changes: 216 additions & 0 deletions src/apis/cloud/orderedDataStores_V2/orderedDataStores_V2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
// [ Modules ] ///////////////////////////////////////////////////////////////////
import { createApiGroup } from "../../apiGroup"
//////////////////////////////////////////////////////////////////////////////////


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

import type { MinimalOrderedDataStoreEntry, PrettifiedListOrderedDatastoreEntries, RawListOrderedDatastoreEntries } from "./orderedDataStores_V2.types"
import type { ApiMethod } from "../../apiGroup"
import type { SortOrder } from "../../../utils/utils.types"
import { dataIsSuccess } from "../../../utils/utils"
//////////////////////////////////////////////////////////////////////////////////


// [ Variables ] /////////////////////////////////////////////////////////////////
const addApiMethod = createApiGroup({ groupName: "OrderedDatastores_V2", baseUrl: "https://apis.roblox.com/cloud" })
//////////////////////////////////////////////////////////////////////////////////


// [ Helper Functions ] //////////////////////////////////////////////////////////
const formatEntryFilter = (lessThanOrEq?: number, moreThanOrEq?: number) => {
return `${
lessThanOrEq ? `entry <= ${lessThanOrEq}` : ""
}${(lessThanOrEq && moreThanOrEq) ? " && " : ""}${
moreThanOrEq ? `entry >= ${moreThanOrEq}` : ""
}`
}
//////////////////////////////////////////////////////////////////////////////////


/**
* Lists entries in an ordered data store.
* @endpoint GET /v2/universes/{universeId}/ordered-data-stores/{dataStoreId}/scopes/{scope}/entries
*
* @param universeId The ID of the universe to get ordered data store entries from.
* @param dataStoreId The ID (name) of the data store to get entries from.
* @param scope The scope to get entries from.
* @param sortOrder Whether to return the results from biggest to smallest (Desc) or smallest to biggest (Asc).
* @param lessThanOrEq Filters the results to include those less than or equal to a specific number (can be used in tangent with `moreThabOrEq`).
* @param moreThanOrEq Filters the results to include those more than or equal to a specific number (can be used in tangent with `lessThabOrEq`).
*
* @example
* const { data:entries } = await OrderedDatastoresApi_V2.listOrderedDatastoreEntries({
universeId: 5097539509, dataStoreId: "PointsStore", scope: "global", sortOrder: "Desc", lessThanOrEq: 80, moreThanOrEq: 70
})
* @exampleData [{"path":"universes/5097539509/ordered-data-stores/PointsStore/scopes/global/entries/45348281","value":78,"id":"45348281"}]
* @exampleRawBody {"orderedDataStoreEntries":[{"path":"universes/5097539509/ordered-data-stores/PointsStore/scopes/global/entries/45348281","value":78,"id":"45348281"}]}
*/
export const listOrderedDatastoreEntries = addApiMethod(async <UniverseId extends Identifier, DataStoreId extends string, Scope extends string>(
{ universeId, dataStoreId, scope, sortOrder, lessThanOrEq, moreThanOrEq }:
{
universeId: UniverseId, dataStoreId: DataStoreId, scope: Scope,
sortOrder?: SortOrder, lessThanOrEq?: number, moreThanOrEq?: number
}
): ApiMethod<
RawListOrderedDatastoreEntries<UniverseId, DataStoreId, Scope>, PrettifiedListOrderedDatastoreEntries<UniverseId, DataStoreId, Scope>
> => ({
method: "GET",
path: `/v2/universes/${universeId}/ordered-data-stores/${dataStoreId}/scopes/${scope}/entries`,
searchParams: { orderBy: sortOrder == "Desc" ? "value desc" : "", filter: formatEntryFilter(lessThanOrEq, moreThanOrEq) },
name: `listOrderedDatastoreEntries`,

prettifyFn: ({ orderedDataStoreEntries }) => orderedDataStoreEntries
}))


/**
* Creates a new entry in an ordered data store.
* @endpoint POST /v2/universes/{universeId}/ordered-data-stores/{dataStoreId}/scopes/{scope}/entries
*
* @param universeId The ID of the universe to create the entry in.
* @param dataStoreId The ID (name) of the data store to create the entry in.
* @param scope The scope for the data store entry.
* @param entryId the ID (name) for the entry.
*
* @example
* const { data:entry } = await OrderedDatastoresApi_V2.createOrderedDataStoreEntry({
universeId: 5097539509, dataStoreId: "PointsStore", scope: "global", entryId: "453482811", entryValue: 15
})
* @exampleData {"path":"universes/5097539509/ordered-data-stores/PointsStore/scopes/global/entries/45348281","value":15,"id":"45348281"}
* @exampleRawBody {"path":"universes/5097539509/ordered-data-stores/PointsStore/scopes/global/entries/45348281","value":15,"id":"45348281"}
*/
export const createOrderedDataStoreEntry = addApiMethod(async <
UniverseId extends Identifier, DataStoreId extends string, Scope extends string, EntryId extends string, EntryValue extends number
>(
{universeId, dataStoreId, scope, entryId, entryValue }:
{
universeId: UniverseId, dataStoreId: DataStoreId, scope: Scope, entryId: EntryId, entryValue: EntryValue
}
): ApiMethod<MinimalOrderedDataStoreEntry<UniverseId, DataStoreId, Scope, EntryId, EntryValue>> => ({
method: "POST",
path: `/v2/universes/${universeId}/ordered-data-stores/${dataStoreId}/scopes/${scope}/entries`,
searchParams: { id: entryId },
body: { value: entryValue },
name: `createOrderedDataStoreEntry`,
}))


/**
* Gets an new entry in an ordered data store.
* @endpoint GET /v2/universes/{universeId}/ordered-data-stores/{dataStoreId}/scopes/{scope}/entries
*
* @param universeId The ID of the universe to get the entry from.
* @param dataStoreId The ID (name) of the data store to get the entry from.
* @param scope The scope of the data store entry.
* @param entryId the ID (name) of the entry.
*
* @example
* const { data:entry } = await OrderedDatastoresApi_V2.orderedDataStoreEntry({
universeId: 5097539509, dataStoreId: "PointsStore", scope: "global", entryId: "45348281"
})
* @exampleData {"path":"universes/5097539509/ordered-data-stores/PointsStore/scopes/global/entries/45348281","value":78,"id":"45348281"}
* @exampleRawBody {"path":"universes/5097539509/ordered-data-stores/PointsStore/scopes/global/entries/45348281","value":78,"id":"45348281"}
*/
export const orderedDataStoreEntry = addApiMethod(async <
UniverseId extends Identifier, DataStoreId extends string, Scope extends string, EntryId extends string
>(
{universeId, dataStoreId, scope, entryId }: { universeId: UniverseId, dataStoreId: DataStoreId, scope: Scope, entryId: EntryId }
): ApiMethod<MinimalOrderedDataStoreEntry<UniverseId, DataStoreId, Scope, EntryId>> => ({
method: "GET",
path: `/v2/universes/${universeId}/ordered-data-stores/${dataStoreId}/scopes/${scope}/entries/${entryId}`,
name: `orderedDataStoreEntry`,
}))


/**
* Deletes an entry from an ordered data store.
* @endpoint DELETE /v2/universes/{universeId}/ordered-data-stores/{dataStoreId}/scopes/{scope}/entries
*
* @param universeId The ID of the universe to delete the entry from.
* @param dataStoreId The ID (name) of the data store to delete the entry from.
* @param scope The scope of the data store entry to delete.
* @param entryId the ID (name) of the entry to delete.
*
* @example
* const { data:success } = await OrderedDatastoresApi_V2.deleteOrderedDataStoreEntry({
universeId: 5097539509, dataStoreId: "PointsStore", scope: "global", entryId: "45348281"
})
* @exampleData true
* @exampleRawBody {}
*/
export const deleteOrderedDataStoreEntry = addApiMethod(async <
UniverseId extends Identifier, DataStoreId extends string, Scope extends string, EntryId extends string
>(
{universeId, dataStoreId, scope, entryId }: { universeId: UniverseId, dataStoreId: DataStoreId, scope: Scope, entryId: EntryId }
): ApiMethod<{}, boolean> => ({
method: "DELETE",
path: `/v2/universes/${universeId}/ordered-data-stores/${dataStoreId}/scopes/${scope}/entries/${entryId}`,
name: `deleteOrderedDataStoreEntry`,

prettifyFn: dataIsSuccess
}))


/**
* Updates an entry in an ordered data store.
* @endpoint PATCH /v2/universes/{universeId}/ordered-data-stores/{dataStoreId}/scopes/{scope}/entries/{entryId}
*
* @param universeId The ID of the universe to update the entry in.
* @param dataStoreId The ID (name) of the data store to update the entry in.
* @param scope The scope of the data store entry to update.
* @param entryId the ID (name) of the entry to update.
*
* @example
* const { data:entry } = await OrderedDatastoresApi_V2.updateOrderedDataStoreEntry({
universeId: 5097539509, dataStoreId: "PointsStore", scope: "global", entryId: "45348281", newEntryValue: 45
})
* @exampleData {"path":"universes/5097539509/ordered-data-stores/PointsStore/scopes/global/entries/45348281","value":45,"id":"45348281"}
* @exampleRawBody {"path":"universes/5097539509/ordered-data-stores/PointsStore/scopes/global/entries/45348281","value":45,"id":"45348281"}
*/
export const updateOrderedDataStoreEntry = addApiMethod(async <
UniverseId extends Identifier, DataStoreId extends string, Scope extends string, EntryId extends string, EntryValue extends number
>(
{universeId, dataStoreId, scope, entryId, newEntryValue, allowIfMissing }:
{
universeId: UniverseId, dataStoreId: DataStoreId, scope: Scope, entryId: EntryId, newEntryValue: EntryValue, allowIfMissing?: boolean
}
): ApiMethod<MinimalOrderedDataStoreEntry<UniverseId, DataStoreId, Scope, EntryId, EntryValue>> => ({
method: "PATCH",
path: `/v2/universes/${universeId}/ordered-data-stores/${dataStoreId}/scopes/${scope}/entries/${entryId}`,
searchParams: { allowIfMissing },
body: { value: newEntryValue },
name: `updateOrderedDataStoreEntry`,
}))


/**
* Updates an entry in an ordered data store.
* @endpoint PATCH /v2/universes/{universeId}/ordered-data-stores/{dataStoreId}/scopes/{scope}/entries/{entryId}:increment
*
* @param universeId The ID of the universe to update the entry in.
* @param dataStoreId The ID (name) of the data store to update the entry in.
* @param scope The scope of the data store entry to update.
* @param entryId the ID (name) of the entry to update.
*
* @example
* const { data:entry } = await OrderedDatastoresApi_V2.incrementOrderedDataStoreEntry({
universeId: 5097539509, dataStoreId: "PointsStore", scope: "global", entryId: "45348281", incrementBy: 42
})
* @exampleData {"path":"universes/5097539509/ordered-data-stores/PointsStore/scopes/global/entries/45348281","value":42,"id":"45348281"}
* @exampleRawBody {"path":"universes/5097539509/ordered-data-stores/PointsStore/scopes/global/entries/45348281","value":42,"id":"45348281"}
*/
export const incrementOrderedDataStoreEntry = addApiMethod(async <
UniverseId extends Identifier, DataStoreId extends string, Scope extends string, EntryId extends string
>(
{universeId, dataStoreId, scope, entryId, incrementBy }:
{
universeId: UniverseId, dataStoreId: DataStoreId, scope: Scope, entryId: EntryId, incrementBy: number
}
): ApiMethod<MinimalOrderedDataStoreEntry<UniverseId, DataStoreId, Scope, EntryId>> => ({
method: "POST",
path: `/v2/universes/${universeId}/ordered-data-stores/${dataStoreId}/scopes/${scope}/entries/${entryId}:increment`,
body: { amount: incrementBy },
name: `incrementOrderedDataStoreEntry`,
}))
21 changes: 21 additions & 0 deletions src/apis/cloud/orderedDataStores_V2/orderedDataStores_V2.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Identifier, ObjectPrettify } from "typeforge"

export type MinimalOrderedDataStoreEntry<
UniverseId extends Identifier, DataStoreId extends string, Scope extends string,
EntryId extends string = string, EntryValue extends number = number
> = ObjectPrettify<{
path: `universes/${UniverseId}/ordered-data-stores/${DataStoreId}/scopes/${Scope}/entries/${EntryId}`,
value: EntryValue,
id: EntryId
}>



// GET /v2/universes/{universeId}/ordered-data-stores/{dataStoreId}/scopes/{scope}/entries ---------------------------
export type RawListOrderedDatastoreEntries<UniverseId extends Identifier, DataStoreId extends string, Scope extends string> = {
orderedDataStoreEntries: MinimalOrderedDataStoreEntry<UniverseId, DataStoreId, Scope>[]
}

export type PrettifiedListOrderedDatastoreEntries<UniverseId extends Identifier, DataStoreId extends string, Scope extends string> =
MinimalOrderedDataStoreEntry<UniverseId, DataStoreId, Scope>[]
// -------------------------------------------------------------------------------------------------------------------
Loading

0 comments on commit 12b4cf3

Please sign in to comment.