Skip to content

Commit 3cf99c4

Browse files
committed
Add package version support for getPackageListingDetails Dapper method
PackageListing as a concept is version-agnostic, but to ensure we don't serve pages for rejected package versions, they need to be community-scoped, as rejection is tied to PackageListing object. This commit adds the support to Dapper and listingUtils, the actual usage will be done in a separate commit. Since by default a PackageListing shows the latest package version, the version argument remains optional.
1 parent 76a882e commit 3cf99c4

File tree

6 files changed

+24
-11
lines changed

6 files changed

+24
-11
lines changed

apps/cyberstorm-remix/app/p/listingUtils.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export interface ListingIdentifiers {
55
communityId: string;
66
namespaceId: string;
77
packageId: string;
8+
packageVersion?: string;
89
}
910

1011
/**
@@ -16,12 +17,13 @@ export async function getPublicListing(
1617
dapper: DapperTs,
1718
ids: ListingIdentifiers
1819
) {
19-
const { communityId, namespaceId, packageId } = ids;
20+
const { communityId, namespaceId, packageId, packageVersion } = ids;
2021
try {
2122
return await dapper.getPackageListingDetails(
2223
communityId,
2324
namespaceId,
24-
packageId
25+
packageId,
26+
packageVersion
2527
);
2628
} catch (e) {
2729
if (isApiError(e) && e.response.status === 404) {
@@ -42,13 +44,14 @@ export async function getPrivateListing(
4244
dapper: DapperTs,
4345
ids: ListingIdentifiers
4446
) {
45-
const { communityId, namespaceId, packageId } = ids;
47+
const { communityId, namespaceId, packageId, packageVersion } = ids;
4648

4749
try {
4850
return await dapper.getPackageListingDetails(
4951
communityId,
5052
namespaceId,
51-
packageId
53+
packageId,
54+
packageVersion
5255
);
5356
} catch (e) {
5457
const is404 = isApiError(e) && e.response?.status === 404;
@@ -61,6 +64,7 @@ export async function getPrivateListing(
6164
communityId,
6265
namespaceId,
6366
packageId,
67+
packageVersion,
6468
true
6569
);
6670

packages/dapper-fake/src/fakers/package.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,13 @@ export const getFakePackagePermissions = async (
127127
export const getFakePackageListingDetails = async (
128128
community: string,
129129
namespace: string,
130-
name: string
130+
name: string,
131+
version?: string
131132
) => {
132133
const seed = `${community}-${namespace}-${name}`;
133134
setSeed(seed);
134135

135-
const version = getVersionNumber();
136+
const ver = version ?? getVersionNumber();
136137
const dependencies = await getFakeDependencies(community, namespace, name);
137138

138139
return {
@@ -143,10 +144,10 @@ export const getFakePackageListingDetails = async (
143144
dependant_count: faker.number.int({ min: 0, max: 2000 }),
144145
dependencies,
145146
dependency_count: dependencies.length,
146-
download_url: `https://thunderstore.io/package/download/${namespace}/${name}/${version}/`,
147-
full_version_name: `${namespace}-${name}-${version}}`,
147+
download_url: `https://thunderstore.io/package/download/${namespace}/${name}/${ver}/`,
148+
full_version_name: `${namespace}-${name}-${ver}`,
148149
has_changelog: true,
149-
install_url: `ror2mm://v1/install/thunderstore.io/${namespace}/${name}/${version}/`,
150+
install_url: `ror2mm://v1/install/thunderstore.io/${namespace}/${name}/${ver}/`,
150151
latest_version_number: getVersionNumber(),
151152
team: {
152153
name: faker.word.words(3),

packages/dapper-ts/src/methods/packageListings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ export async function getPackageListingDetails(
123123
communityId: string,
124124
namespaceId: string,
125125
packageName: string,
126+
version: string | undefined = undefined,
126127
useSession = false
127128
) {
128129
const data = await fetchPackageListingDetails({
@@ -131,6 +132,7 @@ export async function getPackageListingDetails(
131132
community_id: communityId,
132133
namespace_id: namespaceId,
133134
package_name: packageName,
135+
version_number: version,
134136
},
135137
data: {},
136138
queryParams: {},

packages/dapper/src/types/methods.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ export type GetPackageChangelog = (
4444
export type GetPackageListingDetails = (
4545
community: string,
4646
namespace: string,
47-
name: string
47+
name: string,
48+
version?: string
4849
) => Promise<PackageListingDetails>;
4950

5051
export type GetPackageListings = (

packages/thunderstore-api/src/get/packageListingDetails.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ export async function fetchPackageListingDetails(
1616
props: ApiEndpointProps<PackageListingDetailsRequestParams, object, object>
1717
): Promise<PackageListingDetailsResponseData> {
1818
const { config, params, useSession } = props;
19-
const path = `${BASE_LISTING_PATH}${params.community_id}/${params.namespace_id}/${params.package_name}/`;
19+
let path = `${BASE_LISTING_PATH}${params.community_id}/${params.namespace_id}/${params.package_name}/`;
20+
21+
if (params.version_number) {
22+
path = `${path}v/${params.version_number}/`;
23+
}
2024

2125
return await apiFetch({
2226
args: {

packages/thunderstore-api/src/schemas/requestSchemas.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ export const packageListingDetailsRequestParamsSchema = z.object({
170170
community_id: z.string(),
171171
namespace_id: z.string(),
172172
package_name: z.string(),
173+
version_number: z.string().optional(),
173174
});
174175

175176
export type PackageListingDetailsRequestParams = z.infer<

0 commit comments

Comments
 (0)