Skip to content

Commit 4b4d088

Browse files
authored
Add sharetribe flex SDK typings (DefinitelyTyped#74127)
1 parent 5a51809 commit 4b4d088

10 files changed

Lines changed: 463 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*
2+
!**/*.d.ts
3+
!**/*.d.cts
4+
!**/*.d.mts
5+
!**/*.d.*.ts
Lines changed: 260 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,260 @@
1+
export interface UUID {
2+
_sdkType: "UUID";
3+
uuid: string;
4+
}
5+
6+
export interface Money {
7+
_sdkType: "Money";
8+
amount: number;
9+
currency: string;
10+
}
11+
12+
export interface ResourceReference {
13+
id: UUID;
14+
type: string;
15+
}
16+
17+
export interface IncludedResource {
18+
type: string;
19+
id?: {
20+
uuid: string;
21+
};
22+
[key: string]: unknown;
23+
}
24+
25+
export interface TransactionRelationships {
26+
customer: {
27+
data: ResourceReference;
28+
};
29+
provider: {
30+
data: ResourceReference;
31+
};
32+
listing: {
33+
data: ResourceReference;
34+
};
35+
marketplace?: {
36+
data: ResourceReference;
37+
};
38+
messages: {
39+
data: ResourceReference[];
40+
};
41+
}
42+
43+
export interface TransactionAttributes {
44+
lastTransition?: string;
45+
payinTotal?: Money;
46+
processName?: string;
47+
metadata?: {
48+
lastUpdatedAt?: string;
49+
};
50+
transitions?: unknown[];
51+
createdAt?: number;
52+
}
53+
54+
export interface Transaction {
55+
id: UUID;
56+
type: string;
57+
attributes: TransactionAttributes;
58+
relationships: TransactionRelationships;
59+
}
60+
61+
export interface UserProfile {
62+
displayName?: string;
63+
firstName?: string;
64+
lastName?: string;
65+
publicData?: {
66+
userType?: string;
67+
[key: string]: unknown;
68+
};
69+
}
70+
71+
export interface UserAttributes {
72+
email: string;
73+
profile: UserProfile;
74+
state?: string;
75+
}
76+
77+
export interface UserRelationships {
78+
profileImage?: {
79+
data?: ResourceReference;
80+
};
81+
}
82+
83+
export interface User {
84+
id: UUID;
85+
type: string;
86+
attributes: UserAttributes;
87+
relationships?: UserRelationships;
88+
}
89+
90+
export interface ListingAttributes {
91+
title: string;
92+
description?: string;
93+
state?: string;
94+
price?: Money;
95+
publicData?: Record<string, unknown>;
96+
privateData?: Record<string, unknown>;
97+
deleted?: boolean;
98+
geolocation?: unknown;
99+
createdAt?: number;
100+
availabilityPlan?: unknown;
101+
metadata?: Record<string, unknown>;
102+
}
103+
104+
export interface ListingRelationships {
105+
author?: {
106+
data: ResourceReference;
107+
};
108+
marketplace?: {
109+
data: ResourceReference;
110+
};
111+
currentStock?: {
112+
data: ResourceReference;
113+
};
114+
images?: {
115+
data: ResourceReference[];
116+
};
117+
}
118+
119+
export interface Listing {
120+
id: UUID;
121+
type: string;
122+
attributes: ListingAttributes;
123+
relationships?: ListingRelationships;
124+
}
125+
126+
export interface MessageAttributes {
127+
content: string;
128+
createdAt: {
129+
_seconds: number;
130+
_nanoseconds: number;
131+
};
132+
}
133+
134+
export interface MessageRelationships {
135+
transaction: {
136+
data: ResourceReference;
137+
};
138+
sender?: {
139+
data: ResourceReference;
140+
};
141+
customer?: {
142+
data: ResourceReference;
143+
};
144+
provider?: {
145+
data: ResourceReference;
146+
};
147+
}
148+
149+
export interface Message {
150+
id: UUID;
151+
type: string;
152+
attributes: MessageAttributes;
153+
relationships: MessageRelationships;
154+
}
155+
156+
export interface EventAttributes {
157+
sequenceId: number;
158+
marketplaceId: string;
159+
eventType: string;
160+
resourceType: string;
161+
resourceId: string;
162+
resource: unknown;
163+
previousValues?: Record<string, unknown>;
164+
source?: string;
165+
createdAt: string;
166+
}
167+
168+
export interface Event {
169+
id: UUID;
170+
type: string;
171+
attributes: EventAttributes;
172+
}
173+
174+
export interface MarketplaceAttributes {
175+
name: string;
176+
description: string | null;
177+
}
178+
179+
export interface MarketplaceData {
180+
id: UUID;
181+
type: string;
182+
attributes: MarketplaceAttributes;
183+
}
184+
185+
export interface MarketplaceShowResponse {
186+
status: number;
187+
statusText: string;
188+
data: {
189+
data: MarketplaceData;
190+
};
191+
}
192+
193+
export interface QueryMeta {
194+
totalPages: number;
195+
totalItems?: number;
196+
page?: number;
197+
perPage?: number;
198+
}
199+
200+
export interface QueryResponse<T> {
201+
status: number;
202+
data: {
203+
data: T[];
204+
included?: IncludedResource[];
205+
meta: QueryMeta;
206+
};
207+
}
208+
209+
export interface ShowResponse<T> {
210+
status: number;
211+
data: {
212+
data: T;
213+
included?: IncludedResource[];
214+
};
215+
}
216+
217+
export interface MutationResponse {
218+
status: number;
219+
data: unknown;
220+
}
221+
222+
export interface IntegrationSdk {
223+
marketplace: {
224+
show: () => Promise<MarketplaceShowResponse>;
225+
};
226+
events: {
227+
query: (params?: { startAfterSequenceId?: number }) => Promise<QueryResponse<Event>>;
228+
};
229+
users: {
230+
query: (params?: { page?: number; include?: string[] }) => Promise<QueryResponse<User>>;
231+
show: (params: { id: string; include?: string[] }) => Promise<ShowResponse<User>>;
232+
updatePermissions: (params: Record<string, unknown>) => Promise<MutationResponse>;
233+
};
234+
transactions: {
235+
query: (params?: { page?: number; include?: string[] }) => Promise<QueryResponse<Transaction>>;
236+
transition: (
237+
params: { id: string; transition: string; params: Record<string, unknown> },
238+
) => Promise<MutationResponse>;
239+
updateMetadata: (
240+
params: { id: string; metadata: Record<string, unknown> },
241+
options?: { expand?: boolean },
242+
) => Promise<MutationResponse>;
243+
};
244+
listings: {
245+
query: (params?: { page?: number; include?: string[] }) => Promise<QueryResponse<Listing>>;
246+
};
247+
}
248+
249+
export function createInstance(config: {
250+
clientId: string;
251+
clientSecret: string;
252+
queryLimiter?: unknown;
253+
commandLimiter?: unknown;
254+
}): IntegrationSdk;
255+
256+
export namespace util {
257+
function createRateLimiter(config: unknown): unknown;
258+
const prodQueryLimiterConfig: unknown;
259+
const prodCommandLimiterConfig: unknown;
260+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"private": true,
3+
"name": "@types/sharetribe-flex-integration-sdk",
4+
"version": "1.11.9999",
5+
"projects": [
6+
"https://github.com/sharetribe/flex-integration-sdk-js"
7+
],
8+
"minimumTypeScriptVersion": "4.5",
9+
"devDependencies": {
10+
"@types/sharetribe-flex-integration-sdk": "workspace:."
11+
},
12+
"owners": [
13+
{
14+
"name": "Jayen Ashar",
15+
"githubUsername": "jayenashar"
16+
},
17+
{
18+
"name": "Adam Martinovic",
19+
"githubUsername": "venmartin"
20+
}
21+
]
22+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { createInstance, util } from "sharetribe-flex-integration-sdk";
2+
3+
const sdk = createInstance({
4+
clientId: "client-id",
5+
clientSecret: "client-secret",
6+
});
7+
8+
sdk.marketplace.show().then((response) => {
9+
const name: string = response.data.data.attributes.name;
10+
});
11+
12+
sdk.users.query({ page: 1, include: ["profileImage"] }).then((response) => {
13+
const firstUser = response.data.data[0];
14+
if (firstUser) {
15+
const email: string = firstUser.attributes.email;
16+
}
17+
});
18+
19+
sdk.transactions.transition({
20+
id: "transaction-id",
21+
transition: "request-payment",
22+
params: { listingId: "listing-id" },
23+
}).then((response) => {
24+
const status: number = response.status;
25+
});
26+
27+
const rateLimiterConfig = util.prodQueryLimiterConfig;
28+
const rateLimiter = util.createRateLimiter(rateLimiterConfig);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"lib": [
5+
"es6"
6+
],
7+
"noImplicitAny": true,
8+
"noImplicitThis": true,
9+
"strictFunctionTypes": true,
10+
"strictNullChecks": true,
11+
"noEmit": true,
12+
"forceConsistentCasingInFileNames": true,
13+
"types": []
14+
},
15+
"files": [
16+
"index.d.ts",
17+
"sharetribe-flex-integration-sdk-tests.ts"
18+
]
19+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*
2+
!**/*.d.ts
3+
!**/*.d.cts
4+
!**/*.d.mts
5+
!**/*.d.*.ts

0 commit comments

Comments
 (0)