Back to Arky

Packages

One concept for shops, price lists, memberships, newsletters and lent equipment: what a package holds, what to fill in, and the rules people and their AI agents need.

A package is a set of things you can buy, get or rent. It’s open to people, or they belong to it.

This guide is for the people who run a store and for the AI agents that set one up.

In one line: a catalog in Arky is a package. So is a price list, a customer group, a membership plan and a newsletter. These aren’t kinds of package, because there is no package type. A package is one record, and what you fill in decides what it does. One record can do several of these jobs at once.

What You Want And What To Fill In

You wantMake a package with
A shopPriced items, and an access row for everyone. A new store already has one, keyed public
A price list for one companyPriced items, and an access row for that company
A seasonal range or a salePriced items and a schedule
A club or a subscriptionA renewal that repeats, and automatic items for what members get
Club pricesproduct items in the club package itself, which its members buy in a cart of the club
Money off for members in the normal shopNo extra package: a promotion with a package condition naming the club
A newsletterNo items at all and no renewal, priced at zero in a shop so people can join
A list the team assigns people toNo items at all. Nobody needs to buy it
Equipment on loan with a monthly minimumA rent_product automatic item and a minimum
Plans to choose betweenOne package per plan, grouped in a package offering: a family of plans

What A Package Holds

  • Priced items are what a buyer chooses and pays for. A priced item lists one product, booking service or package in one market, with its prices inside it: a product item holds one price for each variant it sells, a booking_service item one for each offering, and a package item exactly one price, for the plan it sells.
  • Automatic items are what a member gets on joining: get_product (goods, a service or a download) and rent_product (something on loan). They have no price of their own, and they freeze when someone joins, so a later edit never changes what an existing member agreed to.
  • A get_product delivery is none (never shipped: services, downloads and an item that only carries a fee), once_per_period (one delivery window in each period) or repeating_in_period (several windows on their own cadence inside each period of a package that renews).
  • Access rows say who may browse, see prices or buy, and in which sales channels. A member has buy on its own package without a row.
  • renewal is never, or every with a cadence. Prices decide whether joining costs anything.
  • stay is any_time, or at_least a length, with what happens when that block ends: renew, renew_once, continue_without_stay or stop. It works on any package and charges no fee of its own.
  • minimum is none, or a monthly purchase minimum that counts a category or a hand-picked list of variant_ids, each unit by its variant’s measure. A shortfall is only reported: it never charges or blocks anyone.
  • schedule and status say when it is open. The status table says what each status stops.

A package has no market and no currency. Its priced items do, so one package can sell in several markets by pricing an item in each.

Build A Shop

A new store’s public package is open to everyone in every channel. Put a product in it, one item for the product, then one price for each variant:

const shop = await sdk.eshop.package.getByKey({ store_id: storeId, key: "public" });

const shirtInShop = await sdk.eshop.packageItem.create({
	store_id: storeId,
	id: crypto.randomUUID(),
	package_id: shop.id,
	market_id: market.id,
	item: { type: "product", product_id: product.id },
});

await sdk.eshop.packageItemPrice.create({
	store_id: storeId,
	id: crypto.randomUUID(),
	package_item_id: shirtInShop.id,
	sellable: { type: "product_variant", variant_id: variant.id },
	amount: 2900,
	compare_at: { type: "none" },
	changes: [],
	schedule: { type: "always" },
	status: { type: "active" },
});

An item read answers its prices in type.prices as { variant_id, price }, so each price says which variant it sells. The site names the package on every read and cart, and the market comes from the client:

const { items: packages } = await arky.eshop.package.find();
const shopPackage = packages.find((candidate) => candidate.key === "public");
if (!shopPackage) throw new Error("This buyer can't shop here");

const { items } = await arky.eshop.packageItem.find({
	package_id: shopPackage.id,
	include_price: true,
	selection: { types: ["product"], price: { max_amount: 5000 } },
	limit: 24,
});
const { items: prices } = await arky.eshop.packageItem.findPrices({
	package_item_id: items[0].package_item_id,
	package_id: shopPackage.id,
	include_price: true,
});

const cart = arky.eshop.cart({ buyer: { type: "customer" }, package_id: shopPackage.id });
await cart.ensure();
if (prices[0]?.sellable.type === "product_variant") {
	await cart.addProduct({
		variant_id: prices[0].sellable.variant_id,
		quantity: 1,
		price: {
			package_id: shopPackage.id,
			package_item_id: items[0].package_item_id,
			price_id: prices[0].price_id,
		},
	});
}

Search answers one result per priced item, with its price range in that market. Its fields use the package item’s names: package_item_id, package_id, market_id, item and position. The filters work on the product, not on a variant: there is no SKU filter, and a price range matches a product whose prices overlap it. A page that needs one variant filters its own read of the item’s prices.

To stop selling a product, setAllPrices archives or schedules all its prices at once. It forgets which were already archived, so bringing the product back means choosing which prices to reactivate.

Sell In Another Market

A market fixes a currency and whether prices include tax, and an item belongs to one market. Price the same product again for the new market, or copy one market’s items and prices when both markets share a currency and tax mode. Run the copy until its cursor is null; running it again changes nothing the target already has:

import type { PackageCopyResult } from "arky-sdk";

const shop = await sdk.eshop.package.getByKey({ store_id: storeId, key: "public" });

let cursor: string | null = null;
do {
	const step: PackageCopyResult = await sdk.eshop.package.copy({
		store_id: storeId,
		id: shop.id,
		source_package_id: shop.id,
		source_market_id: market.id,
		target_market_id: croatiaMarket.id,
		cursor,
	});
	cursor = step.cursor;
} while (cursor !== null);

Give One Company Its Own Prices

There is no base package, and no price list layered over another. A negotiated price is a company’s own package, usually a copy, with an access row for that company:

const northwindPrices = await sdk.eshop.package.create({
	store_id: storeId,
	id: crypto.randomUUID(),
	key: "northwind-prices",
	blocks: [],
	renewal: { type: "never" },
	stay: { type: "any_time" },
	minimum: { type: "none" },
	schedule: { type: "always" },
	status: { type: "active" },
	items: [],
});

await sdk.eshop.packageAccess.create({
	store_id: storeId,
	id: crypto.randomUUID(),
	package_id: northwindPrices.id,
	audience: { type: "company", company_id: northwind.id },
	channels: { type: "all" },
	level: { type: "buy" },
});

Copy the items into it and edit the prices you agreed. The company’s buyers then see it in arky.eshop.package.find({ company_id }), and the site names it on their cart. Arky never merges packages or looks for the lowest price across them.

Run A Club

A club is a package that renews, with automatic items for what members get. It is sold as a plan: a package item in a shop, saved together with its one price:

const shop = await sdk.eshop.package.getByKey({ store_id: storeId, key: "public" });

const club = await sdk.eshop.package.create({
	store_id: storeId,
	id: crypto.randomUUID(),
	key: "club",
	blocks: [],
	renewal: {
		type: "every",
		agreed: {
			cadence: { interval: "month", interval_count: 1 },
			on_exhaustion: { type: "pause" },
			unpaid_order: { type: "retain_debt" },
		},
		timing: {
			retry_offsets_seconds: [3600, 86400],
			recovery_window_seconds: 604800,
			reminder: { type: "days_before", days: 3 },
		},
	},
	stay: { type: "any_time" },
	minimum: { type: "none" },
	schedule: { type: "always" },
	status: { type: "active" },
	items: [
		{
			action: "create",
			id: crypto.randomUUID(),
			type: {
				type: "get_product",
				variant_ids: [giftVariantId],
				quantity: 1,
				delivery: { type: "once_per_period", offset_days: 0, window_days: 3 },
				allocation_weight: 1,
			},
		},
	],
});

await sdk.eshop.packageItem.create({
	store_id: storeId,
	id: crypto.randomUUID(),
	package_id: shop.id,
	market_id: market.id,
	item: {
		type: "package",
		package_id: club.id,
		price: {
			id: crypto.randomUUID(),
			amount: 900,
			compare_at: { type: "none" },
			changes: [],
			schedule: { type: "always" },
			status: { type: "active" },
		},
	},
});

Club prices are product items in the club package itself. A member has buy on its own package without an access row, so it shops in a cart of the club package, at those prices, and promotions apply there as in any other cart:

const shirtInClub = await sdk.eshop.packageItem.create({
	store_id: storeId,
	id: crypto.randomUUID(),
	package_id: club.id,
	market_id: market.id,
	item: { type: "product", product_id: product.id },
});

await sdk.eshop.packageItemPrice.create({
	store_id: storeId,
	id: crypto.randomUUID(),
	package_item_id: shirtInClub.id,
	sellable: { type: "product_variant", variant_id: variant.id },
	amount: 2400,
	compare_at: { type: "amount", amount: 2900 },
	changes: [],
	schedule: { type: "always" },
	status: { type: "active" },
});

On the site, a signed-in member finds the club in arky.eshop.package.find() and names it on the cart it buys club prices in:

const { items: packages } = await arky.eshop.package.find();
const memberPackage = packages.find((candidate) => candidate.key === "club");
if (!memberPackage) throw new Error("Only club members buy at club prices");

const clubCart = arky.eshop.cart({ buyer: { type: "customer" }, package_id: memberPackage.id });
await clubCart.ensure();

Money off for members in the normal shop is a promotion with a package condition. The condition holds for the packages that count for the buyer, not for the package the cart shops in, and a customer_limit caps each buyer’s uses, counted per email:

const shop = await sdk.eshop.package.getByKey({ store_id: storeId, key: "public" });

await sdk.eshop.promotion.create({
	store_id: storeId,
	id: crypto.randomUUID(),
	key: "club-members-10-off",
	blocks: [{ id: crypto.randomUUID(), key: "name", type: "localized_text", value: { en: "10% off for club members" } }],
	activation: { type: "automatic" },
	conditions: [{ type: "package", ids: [club.id] }],
	effects: [
		{
			type: "item_percentage",
			id: crypto.randomUUID(),
			target: { type: "listed_in_packages", package_ids: [shop.id] },
			basis_points: 1_000,
		},
	],
	stacking: { type: "continue" },
	priority: 20,
	limit: { type: "unlimited" },
	customer_limit: { type: "limited", max_uses: 3 },
	schedule: { type: "always" },
	status: { type: "active" },
});
  • A cart never takes one line’s price from another package: every line is priced from the cart’s own package. So a member price inside another package’s cart doesn’t exist, and neither does a member price capped anew each period.
  • A package with no automatic items is free. A paid club whose only benefit is its prices carries its fee on a never-delivered get_product, with delivery: { type: "none" }, like every paid package that ships nothing.
  • A package’s automatic items change only through its create and update, in one all-or-nothing save.
  • Joining makes a member at checkout. See Joining By Buying for the cart line and Member Changes for what a member can do afterwards.

For a free sign-up list, see Newsletters and Broadcasts.

Offer Plans To Choose Between

A package offering is a family of plans, such as Basic and Premium. It lists related packages: a customer, company or location holds at most one plan of the family at a time, and a member moves between its plans instead of holding two. A package belongs to at most one offering.

await sdk.eshop.packageOffering.create({
	store_id: storeId,
	id: crypto.randomUUID(),
	key: "memberships",
	blocks: [],
	package_ids: [basic.id, premium.id],
});
  • An offering is never an item. Adding a plan to an offering publishes it nowhere: list each plan as its own package item, with its one price, in each shop that sells it.
  • The site groups the plans it shows by their offering. A package’s storefront read names its package_offering_id, and the offering’s read answers its package_ids: the plans of it that this shop sells in the current market, in the offering’s order.
  • A move is priced by the target plan’s own item. A member’s move names the price of the target plan’s package item in the member’s market.
  • An offering has no status. Each plan sells, takes joins and moves, and stops under its own status and schedule.

Rules To Remember

  • One cart, one package, one market. Every line is priced from the cart’s own package.
  • Every line names its exact price, as { package_id, package_item_id, price_id }. An item id alone never chooses one. On a package line, the line’s own package_id is the package being joined, and the price’s package_id is the package holding that price.
  • A plan’s item holds exactly one price. It is saved with that price, zero when the plan is free, and that price is never deleted on its own: archive it or remove the item.
  • A package is usable in a market when it has an item priced there, or no priced items at all. A read in a market with nothing priced answers an empty page, not a refusal.
  • Status and schedule apply to every market of a package. A shop closed in one market only needs its own package, or archiving that market’s prices.
  • A store that wants a join window and a shop that outlasts it uses two packages, because a package outside its schedule takes no joins and no shopping.
  • The plan counts only packages with automatic items that aren’t archived. Price lists and newsletters use none of the plan’s packages limit.
LimitAt most
Packages per store2,000
Variants per product100
Offerings per booking service100
Packages per package offering100
Prices per item100
Dated changes per price20
Automatic items per package100
Access rows per package1,000

For AI Agents

  1. Read before you create. List packages with sdk.eshop.package.find, and use public unless the store needs another audience, schedule or club. Create a package by what it must do, from the table above; there is no type to pick.
  2. Don’t call a variable package. It is a reserved word in strict TypeScript. A local holding a package a buyer shops in is shopPackage, and one a member belongs to is memberPackage. Properties such as eshop.package and package_id are fine.
  3. Pick each id once. Every create names a UUID v4 you pick per action and resend on a retry, the id of a plan’s price included. Every change sends the expected_updated_at it read; an access row, which is only created or deleted, is deleted by its id alone.
  4. Change prices by name. Use packageItemPrice.create, update, delete and batch, and packageItem.setAllPrices. No call sends an item’s whole list of prices. A plan’s one price comes with its item’s create.
  5. Change automatic items through the package. Send them as items operations on package.create and package.update.
  6. Build on a test store. It has the same packages and rules, so a run there shows what a live store will do.

When a call is refused, the code says what to change:

CodeWhat it means
409 PACKAGE.CLOSEDThe package isn’t open: it isn’t active or closed, or it is outside its schedule
409 PACKAGE.NOT_ON_SALEIt takes no joins now: it isn’t active, or it is outside its schedule
409 PACKAGE.NOT_PRICEDThe cart’s package doesn’t hold that price, or the named price isn’t in force
409 PACKAGE.OTHER_MARKETThe line names a price of another market
409 PACKAGE.ITEM_NOT_LISTEDNo price of that item is in force
409 PACKAGE.FREE_PACKAGE_PRICEDA package with no automatic items can only be priced at zero
409 PACKAGE.EVERY_NEEDS_ITEMA package that renews needs an automatic item once it leaves draft
409 PACKAGE.STAY_LENGTHA stay on a renewing package must be a whole number of its cadence
409 PACKAGE.MINIMUM_NOT_COUNTEDA variants minimum adds a variant whose measure counts nothing
409 PACKAGE_ITEM.ALREADY_LISTEDThe package already lists that product, service or package in that market
409 PACKAGE_ITEM_PRICE.ALREADY_EXISTSThat choice already has a price in this item: edit or restore it. A plan’s item takes no second price
409 PACKAGE_ITEM_PRICE.REQUIREDA plan’s one price can’t be deleted on its own: archive it or remove the item
409 PACKAGE_ITEM_PRICE.WRONG_CHOICEThe variant_id belongs to another product, or the booking_offering_id to another service
402 STORE.USAGE_LIMIT_EXCEEDEDThe plan’s limit is reached, such as packages with automatic items

The Packages reference has every field, call and rule.