Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Added package types and freight fields to the SDKs
Damian Legawiec16121ff44853
diff --git a/packages/admin-sdk/examples/package-types/create.ts b/packages/admin-sdk/examples/package-types/create.tsnew file mode 100644index 0000000000..d6619111a0--- /dev/null+++ b/packages/admin-sdk/examples/package-types/create.ts@@ -0,0 +1,22 @@+import { createAdminClient } from '@spree/admin-sdk'++const client = createAdminClient({+ baseUrl: 'https://your-store.com',+ secretKey: 'sk_xxx',+})++// region:example+const carton = await client.packageTypes.create({+ name: 'Master carton',+ kind: 'carton',+ length: 40,+ width: 30,+ height: 25,+ dimensions_unit: 'cm',+ max_weight: 20,+ weight_unit: 'kg',+})++// endregion:example++export { carton }diff --git a/packages/admin-sdk/examples/package-types/delete.ts b/packages/admin-sdk/examples/package-types/delete.tsnew file mode 100644index 0000000000..1d9466aafe--- /dev/null+++ b/packages/admin-sdk/examples/package-types/delete.ts@@ -0,0 +1,11 @@+import { createAdminClient } from '@spree/admin-sdk'++const client = createAdminClient({+ baseUrl: 'https://your-store.com',+ secretKey: 'sk_xxx',+})++// region:example+await client.packageTypes.delete('pkgtype_123')++// endregion:examplediff --git a/packages/admin-sdk/examples/package-types/get.ts b/packages/admin-sdk/examples/package-types/get.tsnew file mode 100644index 0000000000..c3b477fae3--- /dev/null+++ b/packages/admin-sdk/examples/package-types/get.ts@@ -0,0 +1,13 @@+import { createAdminClient } from '@spree/admin-sdk'++const client = createAdminClient({+ baseUrl: 'https://your-store.com',+ secretKey: 'sk_xxx',+})++// region:example+const packageType = await client.packageTypes.get('pkgtype_123')++// endregion:example++export { packageType }diff --git a/packages/admin-sdk/examples/package-types/list.ts b/packages/admin-sdk/examples/package-types/list.tsnew file mode 100644index 0000000000..7685a9d797--- /dev/null+++ b/packages/admin-sdk/examples/package-types/list.ts@@ -0,0 +1,13 @@+import { createAdminClient } from '@spree/admin-sdk'++const client = createAdminClient({+ baseUrl: 'https://your-store.com',+ secretKey: 'sk_xxx',+})++// region:example+const { data: packageTypes } = await client.packageTypes.list()++// endregion:example++export { packageTypes }diff --git a/packages/admin-sdk/examples/package-types/update.ts b/packages/admin-sdk/examples/package-types/update.tsnew file mode 100644index 0000000000..00b4684b86--- /dev/null+++ b/packages/admin-sdk/examples/package-types/update.ts@@ -0,0 +1,15 @@+import { createAdminClient } from '@spree/admin-sdk'++const client = createAdminClient({+ baseUrl: 'https://your-store.com',+ secretKey: 'sk_xxx',+})++// region:example+const carton = await client.packageTypes.update('pkgtype_123', {+ max_weight: 25,+})++// endregion:example++export { carton }diff --git a/packages/admin-sdk/src/admin-client.ts b/packages/admin-sdk/src/admin-client.tsindex 4f37ea0352..3645847bca 100644--- a/packages/admin-sdk/src/admin-client.ts+++ b/packages/admin-sdk/src/admin-client.ts@@ -183,6 +183,8 @@ import type {OrderRoutingRuleCreateParams,OrderRoutingRuleUpdateParams,OrderUpdateParams,+ PackageTypeCreateParams,+ PackageTypeUpdateParams,PasswordResetParams,PasswordResetRequestParams,PaymentCreateParams,@@ -312,6 +314,7 @@ import type {Order,OrderCancellationReason,OrderRoutingRule,+ PackageType,Payment,PaymentMethod,Permission,@@ -2411,6 +2414,35 @@ export class AdminClient {this.request<void>('DELETE', `/delivery_zones/${id}`, options),}+ readonly packageTypes = {+ list: (+ params?: ListParams & Record<string, unknown>,+ options?: RequestOptions,+ ): Promise<PaginatedResponse<PackageType>> =>+ this.request<PaginatedResponse<PackageType>>('GET', '/package_types', {+ ...options,+ params: params ? transformListParams(params) : undefined,+ }),++ get: (id: string, options?: RequestOptions): Promise<PackageType> =>+ this.request<PackageType>('GET', `/package_types/${id}`, options),++ create: (params: PackageTypeCreateParams, options?: RequestOptions): Promise<PackageType> =>+ this.request<PackageType>('POST', '/package_types', { ...options, body: params }),++ /** Setting `default` demotes whichever row was the store's box before. */+ update: (+ id: string,+ params: PackageTypeUpdateParams,+ options?: RequestOptions,+ ): Promise<PackageType> =>+ this.request<PackageType>('PATCH', `/package_types/${id}`, { ...options, body: params }),++ /** Refused while a variant is packed into it. */+ delete: (id: string, options?: RequestOptions): Promise<void> =>+ this.request<void>('DELETE', `/package_types/${id}`, options),+ }+readonly paymentMethods = {list: (params?: ListParams & Record<string, unknown>,diff --git a/packages/admin-sdk/src/params.ts b/packages/admin-sdk/src/params.tsindex 17bb1e30f4..f260ebcc7d 100644--- a/packages/admin-sdk/src/params.ts+++ b/packages/admin-sdk/src/params.ts@@ -44,12 +44,6 @@ export interface StoreUpdateParams {preferred_admin_locale?: stringpreferred_timezone?: stringpreferred_weight_unit?: string- /** Packaging tare added to every package's content weight for rate calculation, in the store's weight unit. */- preferred_default_package_weight?: number- /** Default package (box) dimensions for carrier dimensional-weight pricing — inches when imperial, centimeters when metric. All three required to take effect. */- preferred_default_package_length?: number- preferred_default_package_width?: number- preferred_default_package_height?: numberpreferred_unit_system?: string/*** Store-wide default storefront posture: `public`, `prices_hidden`, or@@ -961,6 +955,16 @@ export interface ProductVariantInput {* pre-orders. Null = unlimited. */backorder_limit?: number | nulltax_category_id?: string+ /** The carton this variant is packed into — a `PackageType` of kind+ * `carton`. Its dimensions are shared by every product packed the same+ * way, so a corrected carton size fixes all of them at once. */+ carton_package_type_id?: string | null+ /** How many units fill one carton. */+ units_per_carton?: number | null+ /** What one packed carton weighs, in the variant's weight unit. */+ carton_weight?: string | number | null+ /** How many cartons stack on one pallet. */+ cartons_per_pallet?: number | nullposition?: numberbarcode?: string/** Omit for a simple no-options product (upserts onto the default variant). */@@ -1158,6 +1162,16 @@ export interface VariantCreateParams {preorder_ships_at?: string | nullbackorder_limit?: number | nulltax_category_id?: string+ /** The carton this variant is packed into — a `PackageType` of kind+ * `carton`. Its dimensions are shared by every product packed the same+ * way, so a corrected carton size fixes all of them at once. */+ carton_package_type_id?: string | null+ /** How many units fill one carton. */+ units_per_carton?: number | null+ /** What one packed carton weighs, in the variant's weight unit. */+ carton_weight?: string | number | null+ /** How many cartons stack on one pallet. */+ cartons_per_pallet?: number | nullposition?: numberbarcode?: string/**@@ -1189,6 +1203,16 @@ export interface VariantUpdateParams {preorder_ships_at?: string | nullbackorder_limit?: number | nulltax_category_id?: string+ /** The carton this variant is packed into — a `PackageType` of kind+ * `carton`. Its dimensions are shared by every product packed the same+ * way, so a corrected carton size fixes all of them at once. */+ carton_package_type_id?: string | null+ /** How many units fill one carton. */+ units_per_carton?: number | null+ /** What one packed carton weighs, in the variant's weight unit. */+ carton_weight?: string | number | null+ /** How many cartons stack on one pallet. */+ cartons_per_pallet?: number | nullposition?: numberbarcode?: string/** Partial update — omit to leave option values untouched. */@@ -2678,6 +2702,29 @@ export interface DeliveryZoneParams {members?: DeliveryZoneMemberParams[]}+export interface PackageTypeCreateParams {+ /** Unique within the store. */+ name: string+ /** What this packaging is: the box parcels ship in, or the carton, pallet or container a wholesale order leaves on. */+ kind: 'box' | 'envelope' | 'carton' | 'pallet' | 'container'+ length?: number | null+ width?: number | null+ height?: number | null+ /** Unit the three dimensions are in; falls back to the store's unit system. */+ dimensions_unit?: 'mm' | 'cm' | 'in' | 'ft' | null+ /** The empty package's own weight, added to content weight on every quote. */+ weight?: number | null+ /** What the package can hold — not the same as its own weight. */+ max_weight?: number | null+ weight_unit?: 'g' | 'kg' | 'lb' | 'oz' | null+ /** The box every parcel quote is built on. Setting this demotes whichever row held it. */+ default?: boolean+ metadata?: Record<string, unknown>+}++/** Every field is optional: correcting one measurement is a valid update. */+export type PackageTypeUpdateParams = Partial<PackageTypeCreateParams>+export interface CompanyParams {name?: string/**diff --git a/packages/admin-sdk/src/types/index.ts b/packages/admin-sdk/src/types/index.tsindex 736d148547..97170d58bb 100644--- a/packages/admin-sdk/src/types/index.ts+++ b/packages/admin-sdk/src/types/index.ts@@ -62,6 +62,8 @@ export type { default as Exchange } from './generated/Exchange'export type { default as ExchangeLineItem } from './generated/ExchangeLineItem'export type { default as Export } from './generated/Export'export type { default as Fee } from './generated/Fee'+export type { default as FreightSummary } from './generated/FreightSummary'+export type { default as FreightSummaryLine } from './generated/FreightSummaryLine'export type { default as Fulfillment } from './generated/Fulfillment'export type { default as FulfillmentItem } from './generated/FulfillmentItem'export type { default as GiftCard } from './generated/GiftCard'@@ -79,6 +81,7 @@ export type { default as OptionValue } from './generated/OptionValue'export type { default as Order } from './generated/Order'export type { default as OrderCancellationReason } from './generated/OrderCancellationReason'export type { default as OrderRoutingRule } from './generated/OrderRoutingRule'+export type { default as PackageType } from './generated/PackageType'export type { default as Payment } from './generated/Payment'export type { default as PaymentMethod } from './generated/PaymentMethod'export type { default as PaymentSource } from './generated/PaymentSource'diff --git a/packages/sdk/src/types/index.ts b/packages/sdk/src/types/index.tsindex 64837b3032..47f0136cdb 100644--- a/packages/sdk/src/types/index.ts+++ b/packages/sdk/src/types/index.ts@@ -25,6 +25,7 @@ export type {DigitalAsset,DigitalLink,Discount,+ FreightSummary,Fulfillment,GiftCard,GiftCardBatch,