Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 28 additions & 9 deletions types/sharetribe-flex-integration-sdk/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,18 @@ export interface IntegrationSdk {
* Query users
*/
query: (params?: PaginationParams & BaseQueryParams) => Promise<QueryResponse<User>>;
/**
* Update user data (generic method for updating public, protected, or private data)
*/
update: (
params: {
id: UUID | string;
publicData?: Record<string, unknown>;
protectedData?: Record<string, unknown>;
privateData?: Record<string, unknown>;
},
options?: PerRequestOptions,
) => Promise<MutationResponse<User>>;
/**
* Update user profile
*/
Expand Down Expand Up @@ -537,35 +549,40 @@ export interface IntegrationSdk {
) => Promise<QueryResponse<Listing>>;
/**
* 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<string, unknown>;
privateData?: Record<string, unknown>;
metadata?: Record<string, unknown>;
images?: Array<UUID | string>;
},
options?: PerRequestOptions,
options?: PerRequestOptions & { include?: string[] },
) => Promise<MutationResponse<Listing>>;
/**
* Update a listing
* Allows both Money object and plain price object for flexibility
*/
update: (
params: {
id: UUID | string;
title?: string;
description?: string;
geolocation?: LatLng;
price?: Money;
price?: Money | { amount: number; currency: string };
availabilityPlan?: unknown;
publicData?: Record<string, unknown>;
privateData?: Record<string, unknown>;
metadata?: Record<string, unknown>;
images?: Array<UUID | string>;
},
options?: PerRequestOptions,
) => Promise<MutationResponse<Listing>>;
Expand Down Expand Up @@ -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<MutationResponse<Image>>;
};
Expand Down Expand Up @@ -688,14 +706,14 @@ export interface IntegrationSdk {
* Query stock adjustments
*/
query: (
params: { stockId: UUID | string } & PaginationParams & BaseQueryParams,
params: { listingId: UUID | string } & PaginationParams & BaseQueryParams,
) => Promise<QueryResponse<StockAdjustment>>;
/**
* Create stock adjustment
*/
create: (
params: {
stockId: UUID | string;
listingId: UUID | string;
quantity: number;
},
options?: PerRequestOptions,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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);