diff --git a/types/sharetribe-flex-integration-sdk/index.d.ts b/types/sharetribe-flex-integration-sdk/index.d.ts index 7b5db341e7f357..39bc42df7d789d 100644 --- a/types/sharetribe-flex-integration-sdk/index.d.ts +++ b/types/sharetribe-flex-integration-sdk/index.d.ts @@ -481,6 +481,18 @@ export interface IntegrationSdk { * Query users */ query: (params?: PaginationParams & BaseQueryParams) => Promise>; + /** + * Update user data (generic method for updating public, protected, or private data) + */ + update: ( + params: { + id: UUID | string; + publicData?: Record; + protectedData?: Record; + privateData?: Record; + }, + options?: PerRequestOptions, + ) => Promise>; /** * Update user profile */ @@ -537,23 +549,27 @@ export interface IntegrationSdk { ) => Promise>; /** * Create a new listing + * Allows both Money object and plain price object for flexibility */ create: ( params: { authorId: UUID | string; title: string; + state: "published" | "pendingApproval"; description?: string; geolocation?: LatLng; - price?: Money; + price?: Money | { amount: number; currency: string }; availabilityPlan?: unknown; publicData?: Record; privateData?: Record; metadata?: Record; + images?: Array; }, - options?: PerRequestOptions, + options?: PerRequestOptions & { include?: string[] }, ) => Promise>; /** * Update a listing + * Allows both Money object and plain price object for flexibility */ update: ( params: { @@ -561,11 +577,12 @@ export interface IntegrationSdk { title?: string; description?: string; geolocation?: LatLng; - price?: Money; + price?: Money | { amount: number; currency: string }; availabilityPlan?: unknown; publicData?: Record; privateData?: Record; metadata?: Record; + images?: Array; }, options?: PerRequestOptions, ) => Promise>; @@ -647,10 +664,11 @@ export interface IntegrationSdk { images: { /** - * Upload an image + * Upload an image from a file path + * @param params.image - Path to the image file to upload */ upload: ( - params: { image: unknown }, + params: { image: string }, options?: PerRequestOptions, ) => Promise>; }; @@ -688,14 +706,14 @@ export interface IntegrationSdk { * Query stock adjustments */ query: ( - params: { stockId: UUID | string } & PaginationParams & BaseQueryParams, + params: { listingId: UUID | string } & PaginationParams & BaseQueryParams, ) => Promise>; /** * Create stock adjustment */ create: ( params: { - stockId: UUID | string; + listingId: UUID | string; quantity: number; }, options?: PerRequestOptions, @@ -705,11 +723,12 @@ export interface IntegrationSdk { stock: { /** * Compare and set stock quantity atomically + * oldTotal can be null for new listings without existing stock */ compareAndSet: ( params: { - stockId: UUID | string; - oldTotal: number; + listingId: UUID | string; + oldTotal: number | null; newTotal: number; }, options?: PerRequestOptions, diff --git a/types/sharetribe-flex-integration-sdk/sharetribe-flex-integration-sdk-tests.ts b/types/sharetribe-flex-integration-sdk/sharetribe-flex-integration-sdk-tests.ts index d30a49e6c0c106..97ad6c98a6d747 100644 --- a/types/sharetribe-flex-integration-sdk/sharetribe-flex-integration-sdk-tests.ts +++ b/types/sharetribe-flex-integration-sdk/sharetribe-flex-integration-sdk-tests.ts @@ -16,6 +16,22 @@ sdk.users.query({ page: 1, include: ["profileImage"] }).then((response) => { } }); +// Test users.update() method +sdk.users.update({ + id: "user-id", + privateData: { shopify: { access_token: "token" } }, +}).then((response) => { + const userId: string = response.data.data.id.uuid; +}); + +sdk.users.update({ + id: "user-id", + publicData: { country: "US" }, + protectedData: { email: "test@example.com" }, +}).then((response) => { + const status: number = response.status; +}); + sdk.transactions.transition({ id: "transaction-id", transition: "request-payment", @@ -24,5 +40,75 @@ sdk.transactions.transition({ const status: number = response.status; }); +// Test listings.create() with plain price object +sdk.listings.create({ + authorId: "user-id", + title: "Test Listing", + state: "published", + price: { amount: 5000, currency: "USD" }, + publicData: { category: "electronics" }, +}, { + expand: true, + include: ["author"], +}).then((response) => { + const listingId: string = response.data.data.id.uuid; +}); + +// Test listings.create() with Money type (should still work) +sdk.listings.create({ + authorId: "user-id", + title: "Test Listing", + state: "pendingApproval", + price: { _sdkType: "Money", amount: 5000, currency: "USD" }, +}).then((response) => { + const status: number = response.status; +}); + +// Test listings.update() with plain price object +sdk.listings.update({ + id: "listing-id", + title: "Updated Title", + price: { amount: 6000, currency: "USD" }, + publicData: { updated: true }, +}).then((response) => { + const listingId: string = response.data.data.id.uuid; +}); + +// Test stock.compareAndSet() with null oldTotal (new listing) +sdk.stock.compareAndSet({ + listingId: "listing-id", + oldTotal: null, + newTotal: 10, +}).then((response) => { + const quantity: number = response.data.data.attributes.quantity; +}); + +// Test stock.compareAndSet() with number oldTotal (existing listing) +sdk.stock.compareAndSet({ + listingId: "listing-id", + oldTotal: 10, + newTotal: 5, +}).then((response) => { + const status: number = response.status; +}); + +// Test stockAdjustments.query() with listingId +sdk.stockAdjustments.query({ + listingId: "listing-id", + page: 1, + perPage: 10, +}).then((response) => { + const adjustments = response.data.data; + const totalPages: number = response.data.meta.totalPages; +}); + +// Test stockAdjustments.create() with listingId +sdk.stockAdjustments.create({ + listingId: "listing-id", + quantity: 5, +}).then((response) => { + const adjustmentId: string = response.data.data.id.uuid; +}); + const rateLimiterConfig = util.prodQueryLimiterConfig; const rateLimiter = util.createRateLimiter(rateLimiterConfig);