diff --git a/index.ts b/index.ts index 9852b9d..d65f9e5 100644 --- a/index.ts +++ b/index.ts @@ -137,7 +137,7 @@ export interface CreatorCode { * * @returns {Promise} */ -export async function Request(method: Method | string, route: Route, path: string, params?: KeyValuePair, body?: Body): Promise { +export async function Request(method: Method | string, identifier: string | null, route: Route, path: string, params?: KeyValuePair, body?: Body): Promise { if (params) { for (const [key, value] of Object.entries(params)) { if (typeof value === "boolean") { @@ -147,7 +147,7 @@ export async function Request(method: Method | string, route: Route, pa } const response = await axios.request({ - url: `${baseUrl}/api/${route}/${webstoreIdentifier}${path}`, + url: `${baseUrl}/api/${route}/${identifier}${path}`, params: params, method: method, data: body, @@ -190,7 +190,7 @@ export type Category = BaseItem & { * @returns {Promise>} */ export async function GetCategories(includePackages?: boolean, basketIdent?: string, ipAddress?: string): Promise { - const { data }: Data = await Request("get", "accounts", "/categories", { + const { data }: Data = await Request("get", webstoreIdentifier, "accounts", "/categories", { includePackages, basketIdent, ipAddress @@ -211,7 +211,7 @@ export async function GetCategories(includePackages?: boolean, basketIdent?: str * @returns {Promise>} */ export async function GetCategory(id: number, includePackages?: boolean, basketIdent?: string, ipAddress?: string): Promise { - const { data }: Data = await Request("get", "accounts", `/categories/${id}`, { + const { data }: Data = await Request("get", webstoreIdentifier, "accounts", `/categories/${id}`, { includePackages, basketIdent, ipAddress @@ -231,7 +231,7 @@ export async function GetCategory(id: number, includePackages?: boolean, basketI * @returns {Promise} */ export async function Apply(t: T, basketIdent: string, type: ApplyType): Promise { - return await Request("post", "accounts", `/baskets/${basketIdent}/${type}`, {}, t); + return await Request("post", webstoreIdentifier, "accounts", `/baskets/${basketIdent}/${type}`, {}, t); } /** @@ -245,7 +245,7 @@ export async function Apply(t: T, basketIdent: string, type: ApplyType): Prom * @returns {Promise} */ export async function Remove(t: T, basketIdent: string, type: ApplyType): Promise { - return await Request("post", "accounts", `/baskets/${basketIdent}/${type}/remove`, {}, t); + return await Request("post", webstoreIdentifier, "accounts", `/baskets/${basketIdent}/${type}/remove`, {}, t); } /** @@ -304,7 +304,7 @@ export type Package = BaseItem & { * @returns {Promise>} */ export async function GetPackage(id: number, basketIdent?: string, ipAddress?: string): Promise { - const { data }: Data = await Request("get", "accounts", `/packages/${id}`, { + const { data }: Data = await Request("get", webstoreIdentifier, "accounts", `/packages/${id}`, { basketIdent, ipAddress }) @@ -322,7 +322,7 @@ export async function GetPackage(id: number, basketIdent?: string, ipAddress?: s * @returns {Promise>} */ export async function GetPackages(basketIdent?: string, ipAddress?: string): Promise { - const { data }: Data = await Request("get", "accounts", `/packages`, { + const { data }: Data = await Request("get", webstoreIdentifier, "accounts", `/packages`, { basketIdent, ipAddress }) @@ -428,7 +428,7 @@ export interface Basket { * @returns {Promise>} */ export async function GetBasket(basketIdent: string): Promise { - const { data }: Data = await Request("get", "accounts", `/baskets/${basketIdent}`); + const { data }: Data = await Request("get", webstoreIdentifier, "accounts", `/baskets/${basketIdent}`); return data; } @@ -453,7 +453,7 @@ export type Urls = { * @returns {Promise>} */ export async function CreateBasket(complete_url: string, cancel_url: string): Promise { - const { data }: Data = await Request, Urls>("post", "accounts", "/baskets", { + const { data }: Data = await Request, Urls>("post", webstoreIdentifier, "accounts", "/baskets", { complete_url, cancel_url }); @@ -483,7 +483,7 @@ export interface AuthUrl { * @returns {Promise} The data returned or an axios error */ export async function GetBasketAuthUrl(basketIdent: string, returnUrl: string): Promise { - return await Request("get", "accounts", `/baskets/${basketIdent}/auth`, {}, { + return await Request("get", basketIdent, "accounts", `/baskets/${basketIdent}/auth`, {}, { returnUrl }); } @@ -514,7 +514,7 @@ export interface PackageBody { * @returns {Promise>} */ export async function AddPackageToBasket(basketIdent: string, package_id: number, quantity: number, type: PackageType): Promise { - const { data }: Data = await Request("post", "baskets", `/${basketIdent}/packages`, {}, { + const { data }: Data = await Request("post", basketIdent, "baskets", "/packages", {}, { package_id, quantity, type @@ -534,7 +534,7 @@ export async function AddPackageToBasket(basketIdent: string, package_id: number * @returns {Promise>} */ export async function GiftPackage(basketIdent: string, package_id: number, target_username_id: string): Promise { - const { data }: Data = await Request("post", "baskets", `/${basketIdent}/packages`, {}, { + const { data }: Data = await Request("post", basketIdent, "baskets", "/packages", {}, { package_id, target_username_id }) @@ -552,7 +552,7 @@ export async function GiftPackage(basketIdent: string, package_id: number, targe * @returns {Promise>} */ export async function RemovePackage(basketIdent: string, package_id: number): Promise { - const { data }: Data = await Request("post", "baskets", `/${basketIdent}/packages/remove`, {}, { + const { data }: Data = await Request("post", basketIdent, "baskets", "/packages/remove", {}, { package_id }) @@ -570,7 +570,7 @@ export async function RemovePackage(basketIdent: string, package_id: number): Pr * @returns {Promise>} */ export async function UpdateQuantity(basketIdent: string, package_id: number, quantity: number): Promise { - const { data }: Data = await Request("post", "baskets", `/${basketIdent}/packages/${package_id}`, {}, { + const { data }: Data = await Request("post", basketIdent, "baskets", `/packages/${package_id}`, {}, { quantity }) @@ -610,6 +610,6 @@ export interface Webstore { * @returns {Promise>} */ export async function GetWebstore(): Promise { - const { data }: Data = await Request("get", "accounts", "/webstore"); + const { data }: Data = await Request("get", webstoreIdentifier, "accounts", "/webstore"); return data; } \ No newline at end of file