Skip to content

Commit ef80910

Browse files
authored
🤖 Merge PR DefinitelyTyped#74215 feat(sharetribe-flex-integration-sdk): add missing SDK methods and fix parameter types by @jayenashar
1 parent 0d7ace0 commit ef80910

File tree

2 files changed

+114
-9
lines changed

2 files changed

+114
-9
lines changed

‎types/sharetribe-flex-integration-sdk/index.d.ts‎

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,18 @@ export interface IntegrationSdk {
481481
* Query users
482482
*/
483483
query: (params?: PaginationParams & BaseQueryParams) => Promise<QueryResponse<User>>;
484+
/**
485+
* Update user data (generic method for updating public, protected, or private data)
486+
*/
487+
update: (
488+
params: {
489+
id: UUID | string;
490+
publicData?: Record<string, unknown>;
491+
protectedData?: Record<string, unknown>;
492+
privateData?: Record<string, unknown>;
493+
},
494+
options?: PerRequestOptions,
495+
) => Promise<MutationResponse<User>>;
484496
/**
485497
* Update user profile
486498
*/
@@ -537,35 +549,40 @@ export interface IntegrationSdk {
537549
) => Promise<QueryResponse<Listing>>;
538550
/**
539551
* Create a new listing
552+
* Allows both Money object and plain price object for flexibility
540553
*/
541554
create: (
542555
params: {
543556
authorId: UUID | string;
544557
title: string;
558+
state: "published" | "pendingApproval";
545559
description?: string;
546560
geolocation?: LatLng;
547-
price?: Money;
561+
price?: Money | { amount: number; currency: string };
548562
availabilityPlan?: unknown;
549563
publicData?: Record<string, unknown>;
550564
privateData?: Record<string, unknown>;
551565
metadata?: Record<string, unknown>;
566+
images?: Array<UUID | string>;
552567
},
553-
options?: PerRequestOptions,
568+
options?: PerRequestOptions & { include?: string[] },
554569
) => Promise<MutationResponse<Listing>>;
555570
/**
556571
* Update a listing
572+
* Allows both Money object and plain price object for flexibility
557573
*/
558574
update: (
559575
params: {
560576
id: UUID | string;
561577
title?: string;
562578
description?: string;
563579
geolocation?: LatLng;
564-
price?: Money;
580+
price?: Money | { amount: number; currency: string };
565581
availabilityPlan?: unknown;
566582
publicData?: Record<string, unknown>;
567583
privateData?: Record<string, unknown>;
568584
metadata?: Record<string, unknown>;
585+
images?: Array<UUID | string>;
569586
},
570587
options?: PerRequestOptions,
571588
) => Promise<MutationResponse<Listing>>;
@@ -647,10 +664,11 @@ export interface IntegrationSdk {
647664

648665
images: {
649666
/**
650-
* Upload an image
667+
* Upload an image from a file path
668+
* @param params.image - Path to the image file to upload
651669
*/
652670
upload: (
653-
params: { image: unknown },
671+
params: { image: string },
654672
options?: PerRequestOptions,
655673
) => Promise<MutationResponse<Image>>;
656674
};
@@ -688,14 +706,14 @@ export interface IntegrationSdk {
688706
* Query stock adjustments
689707
*/
690708
query: (
691-
params: { stockId: UUID | string } & PaginationParams & BaseQueryParams,
709+
params: { listingId: UUID | string } & PaginationParams & BaseQueryParams,
692710
) => Promise<QueryResponse<StockAdjustment>>;
693711
/**
694712
* Create stock adjustment
695713
*/
696714
create: (
697715
params: {
698-
stockId: UUID | string;
716+
listingId: UUID | string;
699717
quantity: number;
700718
},
701719
options?: PerRequestOptions,
@@ -705,11 +723,12 @@ export interface IntegrationSdk {
705723
stock: {
706724
/**
707725
* Compare and set stock quantity atomically
726+
* oldTotal can be null for new listings without existing stock
708727
*/
709728
compareAndSet: (
710729
params: {
711-
stockId: UUID | string;
712-
oldTotal: number;
730+
listingId: UUID | string;
731+
oldTotal: number | null;
713732
newTotal: number;
714733
},
715734
options?: PerRequestOptions,

‎types/sharetribe-flex-integration-sdk/sharetribe-flex-integration-sdk-tests.ts‎

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,22 @@ sdk.users.query({ page: 1, include: ["profileImage"] }).then((response) => {
1616
}
1717
});
1818

19+
// Test users.update() method
20+
sdk.users.update({
21+
id: "user-id",
22+
privateData: { shopify: { access_token: "token" } },
23+
}).then((response) => {
24+
const userId: string = response.data.data.id.uuid;
25+
});
26+
27+
sdk.users.update({
28+
id: "user-id",
29+
publicData: { country: "US" },
30+
protectedData: { email: "[email protected]" },
31+
}).then((response) => {
32+
const status: number = response.status;
33+
});
34+
1935
sdk.transactions.transition({
2036
id: "transaction-id",
2137
transition: "request-payment",
@@ -24,5 +40,75 @@ sdk.transactions.transition({
2440
const status: number = response.status;
2541
});
2642

43+
// Test listings.create() with plain price object
44+
sdk.listings.create({
45+
authorId: "user-id",
46+
title: "Test Listing",
47+
state: "published",
48+
price: { amount: 5000, currency: "USD" },
49+
publicData: { category: "electronics" },
50+
}, {
51+
expand: true,
52+
include: ["author"],
53+
}).then((response) => {
54+
const listingId: string = response.data.data.id.uuid;
55+
});
56+
57+
// Test listings.create() with Money type (should still work)
58+
sdk.listings.create({
59+
authorId: "user-id",
60+
title: "Test Listing",
61+
state: "pendingApproval",
62+
price: { _sdkType: "Money", amount: 5000, currency: "USD" },
63+
}).then((response) => {
64+
const status: number = response.status;
65+
});
66+
67+
// Test listings.update() with plain price object
68+
sdk.listings.update({
69+
id: "listing-id",
70+
title: "Updated Title",
71+
price: { amount: 6000, currency: "USD" },
72+
publicData: { updated: true },
73+
}).then((response) => {
74+
const listingId: string = response.data.data.id.uuid;
75+
});
76+
77+
// Test stock.compareAndSet() with null oldTotal (new listing)
78+
sdk.stock.compareAndSet({
79+
listingId: "listing-id",
80+
oldTotal: null,
81+
newTotal: 10,
82+
}).then((response) => {
83+
const quantity: number = response.data.data.attributes.quantity;
84+
});
85+
86+
// Test stock.compareAndSet() with number oldTotal (existing listing)
87+
sdk.stock.compareAndSet({
88+
listingId: "listing-id",
89+
oldTotal: 10,
90+
newTotal: 5,
91+
}).then((response) => {
92+
const status: number = response.status;
93+
});
94+
95+
// Test stockAdjustments.query() with listingId
96+
sdk.stockAdjustments.query({
97+
listingId: "listing-id",
98+
page: 1,
99+
perPage: 10,
100+
}).then((response) => {
101+
const adjustments = response.data.data;
102+
const totalPages: number = response.data.meta.totalPages;
103+
});
104+
105+
// Test stockAdjustments.create() with listingId
106+
sdk.stockAdjustments.create({
107+
listingId: "listing-id",
108+
quantity: 5,
109+
}).then((response) => {
110+
const adjustmentId: string = response.data.data.id.uuid;
111+
});
112+
27113
const rateLimiterConfig = util.prodQueryLimiterConfig;
28114
const rateLimiter = util.createRateLimiter(rateLimiterConfig);

0 commit comments

Comments
 (0)