This operation is only available on the server.
import { whopSdk } from "@/lib/whop-sdk";

const result = await whopSdk.promoCodes.listPromoCodes({
	// ID of the company, either the tag (biz_xxx) or the page route (whop-dev)
	companyId: "biz_XXXXXXXX" /* Required! */,

	after: "pageInfo.endCursor",

	before: "pageInfo.startCursor",

	first: 10,

	last: 10,

	filters: {
		// How to order the results.
		direction: "asc" /* Valid values: asc | desc */,

		// Filter whether to return active or expired (archived and inactive).
		newStatus: "active" /* Valid values: active | expired */,

		// What to order the results by.
		order: "code" /* Valid values: code | created_at */,

		// The text that is being searched.
		query: "some string",

		// The state of promo code.
		status: "active" /* Valid values: active | archived | inactive */,
	},
});

Example output:
const response = {
	// All of a company's promo codes, with searching capabilities.
	promoCodes: {
		// The total number of items in this connection.
		totalCount: 10,

		// Information to aid in pagination.
		pageInfo: {
			// When paginating backwards, the cursor to continue.
			startCursor: "some string",

			// When paginating backwards, are there more items?
			hasPreviousPage: true,

			// When paginating forwards, are there more items?
			hasNextPage: true,

			// When paginating forwards, the cursor to continue.
			endCursor: "some string",
		},

		// A list of nodes.
		nodes: [
			{
				// The ID of the promo.
				id: "xxxxxxxxxxx",

				// The specific code used to apply the promo at checkout.
				code: "some string",

				// The type (% or flat amount) of the promo.
				promoType: "flat_amount" /* Valid values: flat_amount | percentage */,

				// The duration of the promo.
				duration: "forever" /* Valid values: forever | once | repeating */,

				// The timestamp of when the promo was created.
				createdAt: 1716931200,

				// The date/time of when the promo expires.
				expirationDatetime: 1716931200,

				// The monetary currency of the promo code.
				baseCurrency:
					"aed" /* Valid values: aed | all | amd | ape | ars | aud | bam | bgn | bhd | bob | brl | bsd | btc | cad | chf | clp | cop | crc | czk | dkk | dop | dzd | egp | etb | eth | eur | gbp | ghs | gmd | gtq | gyd | hkd | huf | idr | ils | inr | jmd | jod | jpy | kes | khr | krw | kwd | lkr | mad | mdl | mga | mkd | mnt | mop | mur | mxn | myr | nad | ngn | nok | nzd | omr | pen | php | pkr | pln | pyg | qar | ron | rsd | rub | rwf | sar | sek | sgd | thb | tnd | try | ttd | twd | tzs | usd | uyu | uzs | vnd | xcd | xof | zar */,

				// The amount off (% or flat amount) for the promo.
				amountOff: 10,

				// The amount off formatted for display.
				discountOff: "some string",

				// Restricts promo use to only be applied to already purchased memberships.
				existingMembershipsOnly: true,

				// The number of billing cycles the promo is applied for.
				numberOfIntervals: 10,

				// Indicates if the promo code is live or disabled.
				status: "active" /* Valid values: active | archived | inactive */,

				// The quantity limit on the number of uses.
				stock: 10,

				// Whether or not the promo code has unlimited stock.
				unlimitedStock: true,

				// The amount of times the promo codes has been used.
				uses: 10,

				// Restricts promo use to only be applied once per customer.
				onePerCustomer: true,

				// Restricts promo use to only users who have churned from the company before.
				churnedUsersOnly: true,

				// Restricts promo use to only users who have never purchased from the company before.
				newUsersOnly: true,

				// The access pass associated with the promo code.
				accessPass: {
					// The internal ID of the public access pass.
					id: "xxxxxxxxxxx",

					// The title of the access pass. Use for Whop 4.0.
					title: "some string",
				},
			},
		],
	},
};