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
Fix: seller SDK callers of client.me() break after 1.0.0-beta.3 (#14780)
Damian Legawiec95c27af49ace
diff --git a/.changeset/seller-sdk-me-callable.md b/.changeset/seller-sdk-me-callable.mdnew file mode 100644index 0000000000..2b5e3f672d--- /dev/null+++ b/.changeset/seller-sdk-me-callable.md@@ -0,0 +1,7 @@+---+"@spree/seller-sdk": minor+---++`client.me` is now an object: read the signed-in person with `client.me.get()` and edit their own account — first and last name, photo (`avatar`: a direct-upload signed id, or `null` to remove it) and the panel's `selected_locale` — with `client.me.update(params)`. `me.get()` and `me.update()` return `user` as an `Account`, which adds `selected_locale` to the fields `TeamMember` had.++1.0.0-beta.3 made this change without keeping the old form, so code written against beta.1 or beta.2 failed with `client.me is not a function`. Calling `client.me()` works again and returns the same response as `client.me.get()`, but it is deprecated and logs a one-time `console.warn`. To migrate, replace `client.me()` with `client.me.get()`.diff --git a/docs/developer/how-to/build-a-marketplace.mdx b/docs/developer/how-to/build-a-marketplace.mdxindex 12ac49e321..eadaacd074 100644--- a/docs/developer/how-to/build-a-marketplace.mdx+++ b/docs/developer/how-to/build-a-marketplace.mdx@@ -760,9 +760,18 @@ const tokens = await sellerClient.auth.login({sellerClient.setToken(tokens.token)// A user who runs several sellers picks which one they are acting as-sellerClient.setSeller('sel_xxx')+const { sellers } = await sellerClient.me.get()+sellerClient.setSeller(sellers[0].id)++// The signed-in person edits their own account (name, photo, panel language);+// the seller business itself is `sellerClient.profile.update(...)`+await sellerClient.me.update({ first_name: 'Ada', selected_locale: 'de' })```+<Note>+`sellerClient.me` is an object with `get()` and `update()`. Code written against `@spree/seller-sdk` 1.0.0-beta.1 or beta.2 that calls `sellerClient.me()` directly keeps working, but that form is deprecated and logs a one-time warning — switch to `sellerClient.me.get()`.+</Note>+Authentication is JWT only. **There is deliberately no secret-key equivalent**: a key that acts as a seller without a seller signing in is exactly what the Seller API's design exists to prevent. Sign-in fails for a store staff member who runs no seller, even though staff share the same user class.The chosen seller travels as `X-Spree-Seller-Id`. The store is derived from the seller server-side and never sent alongside, so no header a client can set widens what it reaches.diff --git a/packages/seller-sdk/README.md b/packages/seller-sdk/README.mdindex 58e7f331bf..8c6af88915 100644--- a/packages/seller-sdk/README.md+++ b/packages/seller-sdk/README.md@@ -12,12 +12,25 @@ TypeScript client for the [Spree Commerce](https://spreecommerce.org) Seller API## Usage```ts-import { createClient } from '@spree/seller-sdk'+import { createSellerClient } from '@spree/seller-sdk'++const client = createSellerClient({ baseUrl: 'https://your-store.com' })++const { token } = await client.auth.login({ email: '[email protected]', password: '…' })+client.setToken(token)++// Who is signed in, and which sellers they may act for+const { user, sellers } = await client.me.get()+client.setSeller(sellers[0].id)-const client = createClient({ baseUrl: 'https://your-store.com' })const products = await client.products.list()++// The signed-in person's own account: name, photo and panel language+await client.me.update({ first_name: 'Ada', selected_locale: 'de' })```+`client.me()` — the form in 1.0.0-beta.1 and beta.2 — still works but is deprecated and logs a one-time warning; use `client.me.get()`.+Sellers authenticate against the seller branch (`/seller/auth/*`), which issues its own token audience — a seller token is never an admin token.## Documentationdiff --git a/packages/seller-sdk/src/index.ts b/packages/seller-sdk/src/index.tsindex 1c1b58db20..3914bd0c6c 100644--- a/packages/seller-sdk/src/index.ts+++ b/packages/seller-sdk/src/index.ts@@ -15,6 +15,7 @@ export type {DeliveryMethodRuleType,DeliveryPreferenceField,DeliveryZoneListParams,+ MeResource,MeResponse,OnboardingResponse,OrderAddressParams,diff --git a/packages/seller-sdk/src/seller-client.ts b/packages/seller-sdk/src/seller-client.tsindex 3248e695c2..877cbc7452 100644--- a/packages/seller-sdk/src/seller-client.ts+++ b/packages/seller-sdk/src/seller-client.ts@@ -140,22 +140,31 @@ export class SellerClient {** `permission_keys` is empty until a seller is named — capability is per* seller, so there is no answer spanning all of them.+ *+ * Read it with `me.get()` and edit it with `me.update()`. Calling `me()`+ * directly still works for code written against 1.0.0-beta.1/beta.2, but is+ * deprecated and warns once per client.*/- readonly me = {- get: (options?: RequestOptions): Promise<MeResponse> =>- this.request<MeResponse>('GET', '/me', options),+ readonly me: MeResource = Object.assign(+ (options?: RequestOptions): Promise<MeResponse> => {+ if (!this.meCallDeprecationWarned) {+ this.meCallDeprecationWarned = true+ console.warn(+ '[@spree/seller-sdk] `client.me()` is deprecated; use `client.me.get()` instead.',+ )+ }+ return this.me.get(options)+ },+ {+ get: (options?: RequestOptions): Promise<MeResponse> =>+ this.request<MeResponse>('GET', '/me', options),- /**- * Edits the signed-in person's own account — the name and photo their- * team sees, and the panel's language. Not the seller business they act- * for: that is `profile.update`.- *- * `avatar` takes a direct-upload signed id to set the photo, or `null` to- * remove it; omitting it leaves the current one alone.- */- update: (params: AccountUpdateParams, options?: RequestOptions): Promise<MeResponse> =>- this.request<MeResponse>('PATCH', '/me', { ...options, body: params }),- }+ update: (params: AccountUpdateParams, options?: RequestOptions): Promise<MeResponse> =>+ this.request<MeResponse>('PATCH', '/me', { ...options, body: params }),+ },+ )++ private meCallDeprecationWarned = false/** The seller's own record, as they maintain it. */readonly profile = {@@ -1701,6 +1710,26 @@ export interface MeResponse {permission_keys: string[]}+/**+ * `client.me`: an object with `get` and `update`, which is also callable as+ * `client.me()` — the 1.0.0-beta.1/beta.2 form — for backwards compatibility.+ */+export interface MeResource {+ /** @deprecated Use `me.get()` instead. Calling `me()` directly will be removed in a future release. */+ (options?: RequestOptions): Promise<MeResponse>+ /** Reads the signed-in person, the sellers they may act for, and their permissions. */+ get(options?: RequestOptions): Promise<MeResponse>+ /**+ * Edits the signed-in person's own account — the name and photo their+ * team sees, and the panel's language. Not the seller business they act+ * for: that is `profile.update`.+ *+ * `avatar` takes a direct-upload signed id to set the photo, or `null` to+ * remove it; omitting it leaves the current one alone.+ */+ update(params: AccountUpdateParams, options?: RequestOptions): Promise<MeResponse>+}+/** What a seller may change on their own account. */export interface AccountUpdateParams {first_name?: stringdiff --git a/packages/seller-sdk/tests/me.test.ts b/packages/seller-sdk/tests/me.test.tsnew file mode 100644index 0000000000..2051e5d062--- /dev/null+++ b/packages/seller-sdk/tests/me.test.ts@@ -0,0 +1,73 @@+import { HttpResponse, http } from 'msw'+import { afterEach, describe, expect, it, vi } from 'vitest'+import { createSellerClient } from '../src'+import { server } from './mocks/server'++const BASE_URL = 'http://api.test'+const API_PREFIX = `${BASE_URL}/api/v3/seller`++const meResponse = {+ user: {+ id: 'admin_1',+ email: '[email protected]',+ first_name: 'Ada',+ last_name: 'Lovelace',+ full_name: 'Ada Lovelace',+ created_at: '2026-09-01T00:00:00Z',+ avatar_url: null,+ selected_locale: 'de',+ },+ sellers: [],+ permissions: [],+ permission_keys: [],+}++function buildClient() {+ return createSellerClient({ baseUrl: BASE_URL, jwtToken: 'token', retry: false })+}++describe('client.me', () => {+ afterEach(() => {+ vi.restoreAllMocks()+ })++ it('reads the signed-in person with me.get()', async () => {+ server.use(http.get(`${API_PREFIX}/me`, () => HttpResponse.json(meResponse)))+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})++ await expect(buildClient().me.get()).resolves.toEqual(meResponse)+ expect(warn).not.toHaveBeenCalled()+ })++ it('updates the signed-in person with me.update()', async () => {+ let body: unknown+ server.use(+ http.patch(`${API_PREFIX}/me`, async ({ request }) => {+ body = await request.json()+ return HttpResponse.json({+ ...meResponse,+ user: { ...meResponse.user, first_name: 'Grace' },+ })+ }),+ )++ const result = await buildClient().me.update({ first_name: 'Grace', avatar: null })++ expect(body).toEqual({ first_name: 'Grace', avatar: null })+ expect(result.user.first_name).toBe('Grace')+ })++ it('still answers the deprecated me() call, warning once per client', async () => {+ const handler = vi.fn(() => HttpResponse.json(meResponse))+ server.use(http.get(`${API_PREFIX}/me`, handler))+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})+ const client = buildClient()++ await expect(client.me()).resolves.toEqual(meResponse)+ await expect(client.me()).resolves.toEqual(meResponse)++ expect(handler).toHaveBeenCalledTimes(2)+ expect(warn).toHaveBeenCalledTimes(1)+ expect(warn.mock.calls[0]?.[0]).toContain('client.me.get()')+ })+})