Skip to content

armgit / spree

Public Imported from GitHub
0

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.

Added digital assets to the Seller SDK

Damian Legawiec575e16a96a8a
diff --git a/packages/seller-sdk/examples/products/digital-assets/create.ts b/packages/seller-sdk/examples/products/digital-assets/create.ts
new file mode 100644
index 0000000000..268b802903
--- /dev/null
+++ b/packages/seller-sdk/examples/products/digital-assets/create.ts
@@ -0,0 +1,19 @@
+import { createSellerClient } from '@spree/seller-sdk'
+
+const client = createSellerClient({
+ baseUrl: 'https://your-store.com',
+ jwtToken: 'eyJhbGciOi...',
+ sellerId: 'sel_UkLWZg9DAJ',
+})
+
+// region:example
+// `signed_id` comes from `files.upload()` with `visibility: 'private'`.
+const digitalAsset = await client.products.digitalAssets.create('prod_UkLWZg9DAJ', {
+ signed_id: 'eyJfcmFpbHMiOnsiZGF0YSI6MTIzfX0=--abc123',
+ authorized_clicks: 5,
+ authorized_days: 30,
+})
+
+// endregion:example
+
+export { digitalAsset }
diff --git a/packages/seller-sdk/examples/products/digital-assets/delete.ts b/packages/seller-sdk/examples/products/digital-assets/delete.ts
new file mode 100644
index 0000000000..d3df179ba5
--- /dev/null
+++ b/packages/seller-sdk/examples/products/digital-assets/delete.ts
@@ -0,0 +1,11 @@
+import { createSellerClient } from '@spree/seller-sdk'
+
+const client = createSellerClient({
+ baseUrl: 'https://your-store.com',
+ jwtToken: 'eyJhbGciOi...',
+ sellerId: 'sel_UkLWZg9DAJ',
+})
+
+// region:example
+await client.products.digitalAssets.delete('prod_UkLWZg9DAJ', 'dig_k5nR8xLqPz')
+// endregion:example
diff --git a/packages/seller-sdk/examples/products/digital-assets/get.ts b/packages/seller-sdk/examples/products/digital-assets/get.ts
new file mode 100644
index 0000000000..201803046a
--- /dev/null
+++ b/packages/seller-sdk/examples/products/digital-assets/get.ts
@@ -0,0 +1,14 @@
+import { createSellerClient } from '@spree/seller-sdk'
+
+const client = createSellerClient({
+ baseUrl: 'https://your-store.com',
+ jwtToken: 'eyJhbGciOi...',
+ sellerId: 'sel_UkLWZg9DAJ',
+})
+
+// region:example
+const digitalAsset = await client.products.digitalAssets.get('prod_UkLWZg9DAJ', 'dig_k5nR8xLqPz')
+
+// endregion:example
+
+export { digitalAsset }
diff --git a/packages/seller-sdk/examples/products/digital-assets/list.ts b/packages/seller-sdk/examples/products/digital-assets/list.ts
new file mode 100644
index 0000000000..9dcbb080c5
--- /dev/null
+++ b/packages/seller-sdk/examples/products/digital-assets/list.ts
@@ -0,0 +1,14 @@
+import { createSellerClient } from '@spree/seller-sdk'
+
+const client = createSellerClient({
+ baseUrl: 'https://your-store.com',
+ jwtToken: 'eyJhbGciOi...',
+ sellerId: 'sel_UkLWZg9DAJ',
+})
+
+// region:example
+const { data: digitalAssets } = await client.products.digitalAssets.list('prod_UkLWZg9DAJ')
+
+// endregion:example
+
+export { digitalAssets }
diff --git a/packages/seller-sdk/examples/products/digital-assets/update.ts b/packages/seller-sdk/examples/products/digital-assets/update.ts
new file mode 100644
index 0000000000..a78e3146b7
--- /dev/null
+++ b/packages/seller-sdk/examples/products/digital-assets/update.ts
@@ -0,0 +1,19 @@
+import { createSellerClient } from '@spree/seller-sdk'
+
+const client = createSellerClient({
+ baseUrl: 'https://your-store.com',
+ jwtToken: 'eyJhbGciOi...',
+ sellerId: 'sel_UkLWZg9DAJ',
+})
+
+// region:example
+// `null` falls back to the marketplace's download settings.
+const digitalAsset = await client.products.digitalAssets.update(
+ 'prod_UkLWZg9DAJ',
+ 'dig_k5nR8xLqPz',
+ { authorized_clicks: 10, authorized_days: null },
+)
+
+// endregion:example
+
+export { digitalAsset }
diff --git a/packages/seller-sdk/src/seller-client.ts b/packages/seller-sdk/src/seller-client.ts
index 9b95cf4f38..60c2e0187c 100644
--- a/packages/seller-sdk/src/seller-client.ts
+++ b/packages/seller-sdk/src/seller-client.ts
@@ -18,6 +18,7 @@ import type {
DeliveryMethod,
DeliveryProfile,
DeliveryZone,
+ DigitalAsset,
Exchange,
Export,
FileUpload,
@@ -53,6 +54,8 @@ import type {
DeliveryMethodSort,
DeliveryProfileFilters,
DeliveryProfileSort,
+ DigitalAssetFilters,
+ DigitalAssetSort,
OrderFilters,
OrderSort,
PackageTypeFilters,
@@ -80,6 +83,8 @@ import type {
DeliveryMethodCreateParams,
DeliveryMethodUpdateParams,
DeliveryUpdateParams,
+ DigitalAssetCreateParams,
+ DigitalAssetUpdateParams,
ExchangeCancelParams,
ExchangeCreateParams,
ExchangeFulfillParams,
@@ -493,6 +498,54 @@ export class SellerClient {
options?: RequestOptions,
): Promise<BulkProductResult> =>
this.request('DELETE', '/products/bulk_destroy', { ...options, body: params }),
+
+ /**
+ * The downloadable files on one of this seller's products. Upload a file
+ * with `files.upload(file, { visibility: 'private' })` first and send its
+ * `signed_id`.
+ */
+ digitalAssets: {
+ list: (
+ productId: string,
+ params?: ListParams<DigitalAssetFilters, DigitalAssetSort>,
+ options?: RequestOptions,
+ ): Promise<PaginatedResponse<DigitalAsset>> =>
+ this.request<PaginatedResponse<DigitalAsset>>(
+ 'GET',
+ `/products/${productId}/digital_assets`,
+ {
+ ...options,
+ params: params ? transformListParams(params) : undefined,
+ },
+ ),
+
+ get: (productId: string, id: string, options?: RequestOptions): Promise<DigitalAsset> =>
+ this.request<DigitalAsset>('GET', `/products/${productId}/digital_assets/${id}`, options),
+
+ create: (
+ productId: string,
+ params: DigitalAssetCreateParams,
+ options?: RequestOptions,
+ ): Promise<DigitalAsset> =>
+ this.request<DigitalAsset>('POST', `/products/${productId}/digital_assets`, {
+ ...options,
+ body: params,
+ }),
+
+ update: (
+ productId: string,
+ id: string,
+ params: DigitalAssetUpdateParams,
+ options?: RequestOptions,
+ ): Promise<DigitalAsset> =>
+ this.request<DigitalAsset>('PATCH', `/products/${productId}/digital_assets/${id}`, {
+ ...options,
+ body: params,
+ }),
+
+ delete: (productId: string, id: string, options?: RequestOptions): Promise<void> =>
+ this.request<void>('DELETE', `/products/${productId}/digital_assets/${id}`, options),
+ },
}
/**