From 2acce86be3627a437647a280a0e05d188be6c282 Mon Sep 17 00:00:00 2001 From: Jayen Ashar Date: Mon, 8 Dec 2025 20:33:08 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Merge=20PR=20#74174=20[@types/sh?= =?UTF-8?q?aretribe-flex-sdk,=20@types/sharetribe-flex-integration-sdk]=20?= =?UTF-8?q?Update=20to=20v1.22=20with=20complete=20API=20coverage=20by=20@?= =?UTF-8?q?jayenashar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../index.d.ts | 661 ++++++++- .../sharetribe-flex-integration-sdk-tests.ts | 2 +- types/sharetribe-flex-sdk/index.d.ts | 1193 ++++++++++++++++- types/sharetribe-flex-sdk/package.json | 2 +- .../sharetribe-flex-sdk-tests.ts | 9 +- 5 files changed, 1771 insertions(+), 96 deletions(-) diff --git a/types/sharetribe-flex-integration-sdk/index.d.ts b/types/sharetribe-flex-integration-sdk/index.d.ts index 594785ff90c15b..7b5db341e7f357 100644 --- a/types/sharetribe-flex-integration-sdk/index.d.ts +++ b/types/sharetribe-flex-integration-sdk/index.d.ts @@ -1,27 +1,78 @@ +/** + * Represents a universally unique identifier for Sharetribe resources + */ export interface UUID { _sdkType: "UUID"; uuid: string; } +/** + * Represents monetary values with currency information + */ export interface Money { _sdkType: "Money"; amount: number; currency: string; } +/** + * Represents a geographic location with latitude and longitude + */ +export interface LatLng { + _sdkType: "LatLng"; + lat: number; + lng: number; +} + +/** + * Reference to a related resource + */ export interface ResourceReference { id: UUID; type: string; } +/** + * Generic included resource in API responses + */ export interface IncludedResource { + id: UUID; type: string; - id?: { - uuid: string; - }; - [key: string]: unknown; + attributes?: Record; + relationships?: Record; } +/** + * Transaction attributes + */ +export interface TransactionAttributes { + createdAt?: string; + processName?: string; + processVersion?: number; + lastTransition?: string; + lastTransitionedAt?: string; + transitions?: Array<{ + transition: string; + createdAt: string; + by: string; + }>; + payinTotal?: Money; + payoutTotal?: Money; + lineItems?: Array<{ + code: string; + unitPrice: Money; + quantity?: number; + lineTotal: Money; + includeFor: string[]; + reversal?: boolean; + }>; + protectedData?: Record; + metadata?: Record; +} + +/** + * Transaction relationships + */ export interface TransactionRelationships { customer: { data: ResourceReference; @@ -35,72 +86,105 @@ export interface TransactionRelationships { marketplace?: { data: ResourceReference; }; - messages: { + booking?: { + data: ResourceReference; + }; + reviews?: { data: ResourceReference[]; }; -} - -export interface TransactionAttributes { - lastTransition?: string; - payinTotal?: Money; - processName?: string; - metadata?: { - lastUpdatedAt?: string; + messages?: { + data: ResourceReference[]; }; - transitions?: unknown[]; - createdAt?: number; } +/** + * Transaction resource + */ export interface Transaction { id: UUID; - type: string; + type: "transaction"; attributes: TransactionAttributes; relationships: TransactionRelationships; } +/** + * User profile information + */ export interface UserProfile { displayName?: string; firstName?: string; lastName?: string; - publicData?: { - userType?: string; - [key: string]: unknown; - }; + bio?: string; + abbreviatedName?: string; + publicData?: Record; + protectedData?: Record; + metadata?: Record; } +/** + * User attributes + */ export interface UserAttributes { - email: string; + banned?: boolean; + deleted?: boolean; + email?: string; + emailVerified?: boolean; + pendingEmail?: string; profile: UserProfile; - state?: string; + createdAt?: string; } +/** + * User relationships + */ export interface UserRelationships { profileImage?: { data?: ResourceReference; }; + stripeAccount?: { + data?: ResourceReference; + }; } +/** + * User resource + */ export interface User { id: UUID; - type: string; + type: "user"; attributes: UserAttributes; relationships?: UserRelationships; } +/** + * Listing attributes + */ export interface ListingAttributes { title: string; description?: string; + geolocation?: LatLng; + deleted?: boolean; state?: string; + createdAt?: string; price?: Money; + availabilityPlan?: { + type: string; + timezone?: string; + entries?: Array<{ + dayOfWeek: string; + startTime: string; + endTime: string; + seats?: number; + }>; + }; publicData?: Record; privateData?: Record; - deleted?: boolean; - geolocation?: unknown; - createdAt?: number; - availabilityPlan?: unknown; metadata?: Record; } +/** + * Listing relationships + */ export interface ListingRelationships { author?: { data: ResourceReference; @@ -116,43 +200,49 @@ export interface ListingRelationships { }; } +/** + * Listing resource + */ export interface Listing { id: UUID; - type: string; + type: "listing"; attributes: ListingAttributes; relationships?: ListingRelationships; } +/** + * Message attributes + */ export interface MessageAttributes { content: string; - createdAt: { - _seconds: number; - _nanoseconds: number; - }; + createdAt: string; } +/** + * Message relationships + */ export interface MessageRelationships { transaction: { data: ResourceReference; }; - sender?: { - data: ResourceReference; - }; - customer?: { - data: ResourceReference; - }; - provider?: { + sender: { data: ResourceReference; }; } +/** + * Message resource + */ export interface Message { id: UUID; - type: string; + type: "message"; attributes: MessageAttributes; relationships: MessageRelationships; } +/** + * Event attributes + */ export interface EventAttributes { sequenceId: number; marketplaceId: string; @@ -165,31 +255,132 @@ export interface EventAttributes { createdAt: string; } +/** + * Event resource + */ export interface Event { id: UUID; - type: string; + type: "event"; attributes: EventAttributes; } +/** + * Image attributes + */ +export interface ImageAttributes { + variants: Record; +} + +/** + * Image resource + */ +export interface Image { + id: UUID; + type: "image"; + attributes: ImageAttributes; +} + +/** + * Availability exception attributes + */ +export interface AvailabilityExceptionAttributes { + start: string; + end: string; + seats?: number; +} + +/** + * Availability exception resource + */ +export interface AvailabilityException { + id: UUID; + type: "availabilityException"; + attributes: AvailabilityExceptionAttributes; +} + +/** + * Stock adjustment attributes + */ +export interface StockAdjustmentAttributes { + quantity: number; + at: string; +} + +/** + * Stock adjustment relationships + */ +export interface StockAdjustmentRelationships { + listing: { + data: ResourceReference; + }; + stock: { + data: ResourceReference; + }; +} + +/** + * Stock adjustment resource + */ +export interface StockAdjustment { + id: UUID; + type: "stockAdjustment"; + attributes: StockAdjustmentAttributes; + relationships: StockAdjustmentRelationships; +} + +/** + * Stock resource + */ +export interface Stock { + id: UUID; + type: "stock"; + attributes: { + quantity: number; + }; +} + +/** + * Stock reservation attributes + */ +export interface StockReservationAttributes { + quantity: number; + state: string; +} + +/** + * Stock reservation resource + */ +export interface StockReservation { + id: UUID; + type: "stockReservation"; + attributes: StockReservationAttributes; +} + +/** + * Marketplace attributes + */ export interface MarketplaceAttributes { name: string; description: string | null; } -export interface MarketplaceData { +/** + * Marketplace resource + */ +export interface Marketplace { id: UUID; - type: string; + type: "marketplace"; attributes: MarketplaceAttributes; } -export interface MarketplaceShowResponse { - status: number; - statusText: string; - data: { - data: MarketplaceData; - }; -} - +/** + * Metadata for paginated query responses + */ export interface QueryMeta { totalPages: number; totalItems?: number; @@ -197,8 +388,12 @@ export interface QueryMeta { perPage?: number; } -export interface QueryResponse { +/** + * Standard response structure for queries returning multiple resources + */ +export interface QueryResponse { status: number; + statusText: string; data: { data: T[]; included?: IncludedResource[]; @@ -206,55 +401,381 @@ export interface QueryResponse { }; } -export interface ShowResponse { +/** + * Standard response structure for operations returning a single resource + */ +export interface ShowResponse { status: number; + statusText: string; data: { data: T; included?: IncludedResource[]; }; } -export interface MutationResponse { +/** + * Standard response structure for mutation operations + */ +export interface MutationResponse { status: number; - data: unknown; + statusText: string; + data: { + data: T; + included?: IncludedResource[]; + }; +} + +/** + * Common query parameters for GET requests + */ +export interface BaseQueryParams { + include?: string[]; + "fields.user"?: string[]; + "fields.listing"?: string[]; + "fields.transaction"?: string[]; + "fields.image"?: string[]; +} + +/** + * Pagination parameters + */ +export interface PaginationParams { + page?: number; + perPage?: number; +} + +/** + * Options for per-request configuration + */ +export interface PerRequestOptions { + expand?: boolean; } +/** + * Main Sharetribe Integration SDK interface + */ export interface IntegrationSdk { marketplace: { - show: () => Promise; + /** + * Show marketplace information + */ + show: (params?: BaseQueryParams) => Promise>; }; + events: { - query: (params?: { startAfterSequenceId?: number }) => Promise>; + /** + * Query events from the Integration API + * Polls for new events using sequence IDs + */ + query: ( + params?: { startAfterSequenceId?: number } & BaseQueryParams, + ) => Promise>; }; + users: { - query: (params?: { page?: number; include?: string[] }) => Promise>; - show: (params: { id: string; include?: string[] }) => Promise>; - updatePermissions: (params: Record) => Promise; + /** + * Show a specific user + */ + show: (params: { id: UUID | string } & BaseQueryParams) => Promise>; + /** + * Query users + */ + query: (params?: PaginationParams & BaseQueryParams) => Promise>; + /** + * Update user profile + */ + updateProfile: ( + params: { + id: UUID | string; + firstName?: string; + lastName?: string; + displayName?: string; + bio?: string; + publicData?: Record; + protectedData?: Record; + privateData?: Record; + profileImageId?: UUID; + }, + options?: PerRequestOptions, + ) => Promise>; + /** + * Approve a user + */ + approve: ( + params: { id: UUID | string }, + options?: PerRequestOptions, + ) => Promise>; + /** + * Update user permissions + */ + updatePermissions: ( + params: { + id: UUID | string; + permissions?: Record; + }, + options?: PerRequestOptions, + ) => Promise>; + }; + + listings: { + /** + * Show a specific listing + */ + show: (params: { id: UUID | string } & BaseQueryParams) => Promise>; + /** + * Query listings + */ + query: ( + params?: + & { + authorId?: UUID | string; + ids?: Array; + states?: string[]; + } + & PaginationParams + & BaseQueryParams, + ) => Promise>; + /** + * Create a new listing + */ + create: ( + params: { + authorId: UUID | string; + title: string; + description?: string; + geolocation?: LatLng; + price?: Money; + availabilityPlan?: unknown; + publicData?: Record; + privateData?: Record; + metadata?: Record; + }, + options?: PerRequestOptions, + ) => Promise>; + /** + * Update a listing + */ + update: ( + params: { + id: UUID | string; + title?: string; + description?: string; + geolocation?: LatLng; + price?: Money; + availabilityPlan?: unknown; + publicData?: Record; + privateData?: Record; + metadata?: Record; + }, + options?: PerRequestOptions, + ) => Promise>; + /** + * Approve a listing + */ + approve: ( + params: { id: UUID | string }, + options?: PerRequestOptions, + ) => Promise>; + /** + * Open a listing + */ + open: ( + params: { id: UUID | string }, + options?: PerRequestOptions, + ) => Promise>; + /** + * Close a listing + */ + close: ( + params: { id: UUID | string }, + options?: PerRequestOptions, + ) => Promise>; }; + transactions: { - query: (params?: { page?: number; include?: string[] }) => Promise>; + /** + * Show a specific transaction + */ + show: (params: { id: UUID | string } & BaseQueryParams) => Promise>; + /** + * Query transactions + */ + query: ( + params?: + & { + customerId?: UUID | string; + providerId?: UUID | string; + listingId?: UUID | string; + lastTransitions?: string[]; + } + & PaginationParams + & BaseQueryParams, + ) => Promise>; + /** + * Transition a transaction to a new state + */ transition: ( - params: { id: string; transition: string; params: Record }, - ) => Promise; + params: { + id: UUID | string; + transition: string; + params?: Record; + }, + options?: PerRequestOptions, + ) => Promise>; + /** + * Transition transaction speculatively (preview without applying) + */ + transitionSpeculative: ( + params: { + id: UUID | string; + transition: string; + params?: Record; + }, + options?: PerRequestOptions, + ) => Promise>; + /** + * Update transaction metadata + */ updateMetadata: ( - params: { id: string; metadata: Record }, - options?: { expand?: boolean }, - ) => Promise; + params: { + id: UUID | string; + metadata: Record; + }, + options?: PerRequestOptions, + ) => Promise>; }; - listings: { - query: (params?: { page?: number; include?: string[] }) => Promise>; + + images: { + /** + * Upload an image + */ + upload: ( + params: { image: unknown }, + options?: PerRequestOptions, + ) => Promise>; }; + + availabilityExceptions: { + /** + * Query availability exceptions for a listing + */ + query: ( + params: { listingId: UUID | string; start?: string; end?: string } & PaginationParams & BaseQueryParams, + ) => Promise>; + /** + * Create availability exception + */ + create: ( + params: { + listingId: UUID | string; + start: string; + end: string; + seats?: number; + }, + options?: PerRequestOptions, + ) => Promise>; + /** + * Delete availability exception + */ + delete: ( + params: { id: UUID | string }, + options?: PerRequestOptions, + ) => Promise>; + }; + + stockAdjustments: { + /** + * Query stock adjustments + */ + query: ( + params: { stockId: UUID | string } & PaginationParams & BaseQueryParams, + ) => Promise>; + /** + * Create stock adjustment + */ + create: ( + params: { + stockId: UUID | string; + quantity: number; + }, + options?: PerRequestOptions, + ) => Promise>; + }; + + stock: { + /** + * Compare and set stock quantity atomically + */ + compareAndSet: ( + params: { + stockId: UUID | string; + oldTotal: number; + newTotal: number; + }, + options?: PerRequestOptions, + ) => Promise>; + }; + + stockReservations: { + /** + * Show a specific stock reservation + */ + show: (params: { id: UUID | string } & BaseQueryParams) => Promise>; + }; + + /** + * Revoke authentication token + */ + revoke: () => Promise; + + /** + * Get authentication information + */ + authInfo: () => Promise; } -export function createInstance(config: { +/** + * SDK configuration options for Integration API + */ +export interface IntegrationSdkConfig { clientId: string; clientSecret: string; + baseUrl?: string; queryLimiter?: unknown; commandLimiter?: unknown; -}): IntegrationSdk; + adapter?: unknown; + tokenStore?: unknown; + typeHandlers?: unknown[]; + transitVerbose?: boolean; + httpAgent?: unknown; + httpsAgent?: unknown; +} +/** + * Create a new Sharetribe Integration SDK instance + * @param config - SDK configuration including required clientId and clientSecret + * @returns Configured Integration SDK instance + */ +export function createInstance(config: IntegrationSdkConfig): IntegrationSdk; + +/** + * Utility functions for SDK configuration + */ export namespace util { + /** + * Create a rate limiter for API requests + * @param config - Rate limiter configuration + * @returns Rate limiter instance + */ function createRateLimiter(config: unknown): unknown; + + /** + * Production-ready query rate limiter configuration + */ const prodQueryLimiterConfig: unknown; + + /** + * Production-ready command rate limiter configuration + */ const prodCommandLimiterConfig: unknown; } 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 14c3ed725dd910..d30a49e6c0c106 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 @@ -11,7 +11,7 @@ sdk.marketplace.show().then((response) => { sdk.users.query({ page: 1, include: ["profileImage"] }).then((response) => { const firstUser = response.data.data[0]; - if (firstUser) { + if (firstUser && firstUser.attributes.email) { const email: string = firstUser.attributes.email; } }); diff --git a/types/sharetribe-flex-sdk/index.d.ts b/types/sharetribe-flex-sdk/index.d.ts index 25e4adc47898d3..aa0cef162657e6 100644 --- a/types/sharetribe-flex-sdk/index.d.ts +++ b/types/sharetribe-flex-sdk/index.d.ts @@ -1,3 +1,106 @@ +/** + * Represents a universally unique identifier for Sharetribe resources + */ +export interface UUID { + _sdkType?: "UUID"; + uuid: string; +} + +/** + * Represents monetary values with currency information + */ +export interface Money { + _sdkType?: "Money"; + amount: number; + currency: string; +} + +/** + * Represents a geographic location with latitude and longitude + */ +export interface LatLng { + _sdkType?: "LatLng"; + lat: number; + lng: number; +} + +/** + * Represents a geographic bounding box + */ +export interface LatLngBounds { + _sdkType?: "LatLngBounds"; + ne: LatLng; + sw: LatLng; +} + +/** + * Reference to a related resource + */ +export interface ResourceReference { + id: UUID; + type: string; +} + +/** + * Generic included resource in API responses + */ +export interface IncludedResource { + id: UUID; + type: string; + attributes?: Record; + relationships?: Record; +} + +/** + * Metadata for paginated query responses + */ +export interface QueryMeta { + totalPages: number; + totalItems?: number; + page?: number; + perPage?: number; +} + +/** + * Standard response structure for queries returning multiple resources + */ +export interface QueryResponse { + status: number; + statusText: string; + data: { + data: T[]; + included?: IncludedResource[]; + meta: QueryMeta; + }; +} + +/** + * Standard response structure for operations returning a single resource + */ +export interface ShowResponse { + status: number; + statusText: string; + data: { + data: T; + included?: IncludedResource[]; + }; +} + +/** + * Standard response structure for mutation operations + */ +export interface MutationResponse { + status: number; + statusText: string; + data: { + data: T; + included?: IncludedResource[]; + }; +} + +/** + * Image variant with dimensions and URL + */ export interface ImageVariant { name: string; width: number; @@ -5,61 +108,1117 @@ export interface ImageVariant { url: string; } +/** + * Collection of image variants by name + */ export interface ImageVariants { [key: string]: ImageVariant; } -export interface BrandingImageAttributes { +/** + * Attributes for an image resource + */ +export interface ImageAttributes { variants: ImageVariants; } -export interface BrandingImage { - id: string; - type: string; - attributes: BrandingImageAttributes; +/** + * Image resource + */ +export interface Image { + id: UUID; + type: "image"; + attributes: ImageAttributes; } +/** + * Marketplace color scheme configuration + */ export interface MarketplaceColors { primaryButton: string; notificationPrimaryButton: string; mainColor: string; } +/** + * Branding configuration data + */ export interface BrandingData { marketplaceColors: MarketplaceColors; } +/** + * Branding information including images + */ export interface Branding { data: BrandingData; - included: BrandingImage[]; -} - -export interface UUID { - _sdkType?: "UUID"; - uuid: string; + included: Image[]; } +/** + * Marketplace attributes + */ export interface MarketplaceAttributes { name: string; description: string | null; } -export interface MarketplaceData { +/** + * Marketplace resource + */ +export interface Marketplace { id: UUID; type: "marketplace"; attributes: MarketplaceAttributes; } -export interface MarketplaceDataResponse { - data: MarketplaceData; +/** + * User profile information + */ +export interface UserProfile { + displayName?: string; + firstName?: string; + lastName?: string; + bio?: string; + abbreviatedName?: string; + publicData?: Record; + protectedData?: Record; + metadata?: Record; +} + +/** + * User attributes + */ +export interface UserAttributes { + banned?: boolean; + deleted?: boolean; + email?: string; + emailVerified?: boolean; + pendingEmail?: string; + profile: UserProfile; + createdAt?: string; +} + +/** + * User relationships + */ +export interface UserRelationships { + profileImage?: { + data?: ResourceReference; + }; + stripeAccount?: { + data?: ResourceReference; + }; +} + +/** + * User resource + */ +export interface User { + id: UUID; + type: "user"; + attributes: UserAttributes; + relationships?: UserRelationships; +} + +/** + * Current user attributes (includes private fields) + */ +export interface CurrentUserAttributes extends UserAttributes { + stripeConnected?: boolean; + stripePayoutsEnabled?: boolean; + stripeChargesEnabled?: boolean; + identityProviders?: Array<{ + idpId: string; + userId: string; + }>; +} + +/** + * Current user resource + */ +export interface CurrentUser extends Omit { + type: "currentUser"; + attributes: CurrentUserAttributes; +} + +/** + * Availability exception attributes + */ +export interface AvailabilityExceptionAttributes { + start: string; + end: string; + seats?: number; +} + +/** + * Availability exception resource + */ +export interface AvailabilityException { + id: UUID; + type: "availabilityException"; + attributes: AvailabilityExceptionAttributes; +} + +/** + * Listing attributes + */ +export interface ListingAttributes { + title: string; + description?: string; + geolocation?: LatLng; + deleted?: boolean; + state?: string; + createdAt?: string; + price?: Money; + availabilityPlan?: { + type: string; + timezone?: string; + entries?: Array<{ + dayOfWeek: string; + startTime: string; + endTime: string; + seats?: number; + }>; + }; + publicData?: Record; + privateData?: Record; + metadata?: Record; +} + +/** + * Listing relationships + */ +export interface ListingRelationships { + author?: { + data: ResourceReference; + }; + images?: { + data: ResourceReference[]; + }; + currentStock?: { + data: ResourceReference; + }; +} + +/** + * Listing resource + */ +export interface Listing { + id: UUID; + type: "listing"; + attributes: ListingAttributes; + relationships?: ListingRelationships; +} + +/** + * Own listing resource (has additional private fields) + */ +export interface OwnListing extends Omit { + type: "ownListing"; +} + +/** + * Transaction attributes + */ +export interface TransactionAttributes { + createdAt?: string; + processName?: string; + processVersion?: number; + lastTransition?: string; + lastTransitionedAt?: string; + transitions?: Array<{ + transition: string; + createdAt: string; + by: string; + }>; + payinTotal?: Money; + payoutTotal?: Money; + lineItems?: Array<{ + code: string; + unitPrice: Money; + quantity?: number; + lineTotal: Money; + includeFor: string[]; + reversal?: boolean; + }>; + protectedData?: Record; + metadata?: Record; +} + +/** + * Transaction relationships + */ +export interface TransactionRelationships { + customer: { + data: ResourceReference; + }; + provider: { + data: ResourceReference; + }; + listing: { + data: ResourceReference; + }; + booking?: { + data: ResourceReference; + }; + reviews?: { + data: ResourceReference[]; + }; + messages?: { + data: ResourceReference[]; + }; +} + +/** + * Transaction resource + */ +export interface Transaction { + id: UUID; + type: "transaction"; + attributes: TransactionAttributes; + relationships: TransactionRelationships; +} + +/** + * Booking attributes + */ +export interface BookingAttributes { + start: string; + end: string; + displayStart?: string; + displayEnd?: string; + seats?: number; + state?: string; +} + +/** + * Booking resource + */ +export interface Booking { + id: UUID; + type: "booking"; + attributes: BookingAttributes; +} + +/** + * Message attributes + */ +export interface MessageAttributes { + content: string; + createdAt: string; +} + +/** + * Message relationships + */ +export interface MessageRelationships { + sender: { + data: ResourceReference; + }; +} + +/** + * Message resource + */ +export interface Message { + id: UUID; + type: "message"; + attributes: MessageAttributes; + relationships: MessageRelationships; +} + +/** + * Review attributes + */ +export interface ReviewAttributes { + type: string; + state: string; + rating: number; + content?: string; + createdAt?: string; +} + +/** + * Review relationships + */ +export interface ReviewRelationships { + author: { + data: ResourceReference; + }; + subject: { + data: ResourceReference; + }; + listing: { + data: ResourceReference; + }; +} + +/** + * Review resource + */ +export interface Review { + id: UUID; + type: "review"; + attributes: ReviewAttributes; + relationships: ReviewRelationships; +} + +/** + * Time slot attributes + */ +export interface TimeSlotAttributes { + type: string; + start: string; + end: string; + seats?: number; +} + +/** + * Time slot resource + */ +export interface TimeSlot { + id: UUID; + type: "timeSlot"; + attributes: TimeSlotAttributes; +} + +/** + * Stock adjustment attributes + */ +export interface StockAdjustmentAttributes { + quantity: number; + at: string; +} + +/** + * Stock adjustment resource + */ +export interface StockAdjustment { + id: UUID; + type: "stockAdjustment"; + attributes: StockAdjustmentAttributes; +} + +/** + * Stock resource + */ +export interface Stock { + id: UUID; + type: "stock"; + attributes: { + quantity: number; + }; +} + +/** + * Stripe account attributes + */ +export interface StripeAccountAttributes { + stripeAccountId: string; + stripeAccountData?: Record; +} + +/** + * Stripe account resource + */ +export interface StripeAccount { + id: UUID; + type: "stripeAccount"; + attributes: StripeAccountAttributes; } +/** + * Stripe customer attributes + */ +export interface StripeCustomerAttributes { + stripeCustomerId: string; +} + +/** + * Stripe customer resource + */ +export interface StripeCustomer { + id: UUID; + type: "stripeCustomer"; + attributes: StripeCustomerAttributes; +} + +/** + * Common query parameters for GET requests + */ +export interface BaseQueryParams { + include?: string[]; + "fields.user"?: string[]; + "fields.listing"?: string[]; + "fields.image"?: string[]; +} + +/** + * Pagination parameters + */ +export interface PaginationParams { + page?: number; + perPage?: number; +} + +/** + * Options for per-request configuration + */ +export interface PerRequestOptions { + onUploadProgress?: (progressEvent: unknown) => void; + expand?: boolean; +} + +/** + * Main Sharetribe Flex SDK interface + */ export interface MarketplaceSdk { marketplace: { - show: () => Promise<{ status: number; statusText: string; data: MarketplaceDataResponse }>; + /** + * Show marketplace information + */ + show: (params?: BaseQueryParams) => Promise>; }; + + users: { + /** + * Show a specific user + */ + show: (params: { id: UUID } & BaseQueryParams) => Promise>; + }; + + currentUser: { + /** + * Show current user information + */ + show: (params?: BaseQueryParams) => Promise>; + /** + * Create a new user + */ + create: ( + params: { + email: string; + password: string; + firstName: string; + lastName: string; + displayName?: string; + bio?: string; + publicData?: Record; + protectedData?: Record; + privateData?: Record; + }, + queryParams?: { expand?: boolean }, + opts?: PerRequestOptions, + ) => Promise>; + /** + * Create a new user with identity provider + */ + createWithIdp: ( + params: { + idpToken: string; + idpId: string; + firstName?: string; + lastName?: string; + displayName?: string; + bio?: string; + publicData?: Record; + protectedData?: Record; + privateData?: Record; + }, + queryParams?: { expand?: boolean }, + opts?: PerRequestOptions, + ) => Promise>; + /** + * Update current user profile + */ + updateProfile: ( + params: { + firstName?: string; + lastName?: string; + displayName?: string; + bio?: string; + publicData?: Record; + protectedData?: Record; + privateData?: Record; + profileImageId?: UUID; + }, + queryParams?: { expand?: boolean }, + opts?: PerRequestOptions, + ) => Promise>; + /** + * Change current user email + */ + changeEmail: ( + params: { currentPassword: string; email: string }, + queryParams?: { expand?: boolean }, + opts?: PerRequestOptions, + ) => Promise>; + /** + * Change current user password + */ + changePassword: ( + params: { currentPassword: string; newPassword: string }, + queryParams?: { expand?: boolean }, + opts?: PerRequestOptions, + ) => Promise>; + /** + * Delete current user + */ + delete: ( + params?: Record, + queryParams?: { expand?: boolean }, + opts?: PerRequestOptions, + ) => Promise>; + /** + * Verify current user email + */ + verifyEmail: ( + params: { verificationToken: string }, + queryParams?: { expand?: boolean }, + opts?: PerRequestOptions, + ) => Promise>; + /** + * Send verification email to current user + */ + sendVerificationEmail: ( + params?: Record, + queryParams?: { expand?: boolean }, + opts?: PerRequestOptions, + ) => Promise; + /** + * Create Stripe account for current user + */ + createStripeAccount: ( + params: { + country?: string; + accountToken?: string; + bankAccountToken?: string; + requestedCapabilities?: string[]; + }, + queryParams?: { expand?: boolean }, + opts?: PerRequestOptions, + ) => Promise>; + /** + * Update Stripe account for current user + */ + updateStripeAccount: ( + params: { accountToken?: string; bankAccountToken?: string; requestedCapabilities?: string[] }, + queryParams?: { expand?: boolean }, + opts?: PerRequestOptions, + ) => Promise>; + /** + * Delete Stripe account for current user + */ + deleteStripeAccount: ( + params?: Record, + queryParams?: { expand?: boolean }, + opts?: PerRequestOptions, + ) => Promise>; + }; + + passwordReset: { + /** + * Request password reset + */ + request: ( + params: { email: string }, + queryParams?: Record, + opts?: PerRequestOptions, + ) => Promise; + /** + * Reset password using token + */ + reset: ( + params: { passwordResetToken: string; newPassword: string }, + queryParams?: Record, + opts?: PerRequestOptions, + ) => Promise; + }; + + listings: { + /** + * Show a specific listing + */ + show: (params: { id: UUID } & BaseQueryParams) => Promise>; + /** + * Query listings + */ + query: ( + params?: + & { + authorId?: UUID; + ids?: UUID[]; + start?: string; + end?: string; + availability?: string; + states?: string[]; + minPrice?: string; + maxPrice?: string; + keywords?: string; + sort?: string; + origin?: LatLng; + bounds?: LatLngBounds; + pub_category?: string; + [key: string]: unknown; + } + & PaginationParams + & BaseQueryParams, + ) => Promise>; + /** + * Search listings (alias for query with search-specific defaults) + */ + search: ( + params?: + & { + origin?: LatLng; + bounds?: LatLngBounds; + keywords?: string; + [key: string]: unknown; + } + & PaginationParams + & BaseQueryParams, + ) => Promise>; + }; + + ownListings: { + /** + * Show own listing + */ + show: (params: { id: UUID } & BaseQueryParams) => Promise>; + /** + * Query own listings + */ + query: (params?: PaginationParams & BaseQueryParams) => Promise>; + /** + * Create a new listing + */ + create: ( + params: { + title: string; + description?: string; + geolocation?: LatLng; + price?: Money; + availabilityPlan?: unknown; + publicData?: Record; + privateData?: Record; + }, + queryParams?: { expand?: boolean }, + opts?: PerRequestOptions, + ) => Promise>; + /** + * Create a draft listing + */ + createDraft: ( + params: { + title: string; + description?: string; + geolocation?: LatLng; + price?: Money; + availabilityPlan?: unknown; + publicData?: Record; + privateData?: Record; + }, + queryParams?: { expand?: boolean }, + opts?: PerRequestOptions, + ) => Promise>; + /** + * Publish a draft listing + */ + publishDraft: ( + params: { id: UUID }, + queryParams?: { expand?: boolean }, + opts?: PerRequestOptions, + ) => Promise>; + /** + * Discard a draft listing + */ + discardDraft: ( + params: { id: UUID }, + queryParams?: { expand?: boolean }, + opts?: PerRequestOptions, + ) => Promise>; + /** + * Update a listing + */ + update: ( + params: { + id: UUID; + title?: string; + description?: string; + geolocation?: LatLng; + price?: Money; + availabilityPlan?: unknown; + publicData?: Record; + privateData?: Record; + }, + queryParams?: { expand?: boolean }, + opts?: PerRequestOptions, + ) => Promise>; + /** + * Open a listing + */ + open: ( + params: { id: UUID }, + queryParams?: { expand?: boolean }, + opts?: PerRequestOptions, + ) => Promise>; + /** + * Close a listing + */ + close: ( + params: { id: UUID }, + queryParams?: { expand?: boolean }, + opts?: PerRequestOptions, + ) => Promise>; + /** + * Add image to listing + */ + addImage: ( + params: { id: UUID; imageId: UUID }, + queryParams?: { expand?: boolean }, + opts?: PerRequestOptions, + ) => Promise>; + }; + + availabilityExceptions: { + /** + * Query availability exceptions for a listing + */ + query: ( + params: { listingId: UUID; start?: string; end?: string } & PaginationParams & BaseQueryParams, + ) => Promise>; + /** + * Create availability exception + */ + create: ( + params: { listingId: UUID; start: string; end: string; seats?: number }, + queryParams?: { expand?: boolean }, + opts?: PerRequestOptions, + ) => Promise>; + /** + * Delete availability exception + */ + delete: ( + params: { id: UUID }, + queryParams?: { expand?: boolean }, + opts?: PerRequestOptions, + ) => Promise>; + }; + + images: { + /** + * Upload an image + */ + upload: ( + params: { image: unknown }, + queryParams?: { expand?: boolean }, + opts?: PerRequestOptions, + ) => Promise>; + }; + + transactions: { + /** + * Show a specific transaction + */ + show: (params: { id: UUID } & BaseQueryParams) => Promise>; + /** + * Query transactions + */ + query: ( + params?: + & { + only?: string; + lastTransitions?: string[]; + } + & PaginationParams + & BaseQueryParams, + ) => Promise>; + /** + * Initiate a new transaction + */ + initiate: ( + params: { + processAlias?: string; + transition?: string; + params?: Record; + }, + queryParams?: { expand?: boolean }, + opts?: PerRequestOptions, + ) => Promise>; + /** + * Initiate transaction speculatively (preview without creating) + */ + initiateSpeculative: ( + params: { + processAlias?: string; + transition?: string; + params?: Record; + }, + queryParams?: { expand?: boolean }, + opts?: PerRequestOptions, + ) => Promise>; + /** + * Transition a transaction to a new state + */ + transition: ( + params: { + id: UUID; + transition: string; + params?: Record; + }, + queryParams?: { expand?: boolean }, + opts?: PerRequestOptions, + ) => Promise>; + /** + * Transition transaction speculatively (preview without applying) + */ + transitionSpeculative: ( + params: { + id: UUID; + transition: string; + params?: Record; + }, + queryParams?: { expand?: boolean }, + opts?: PerRequestOptions, + ) => Promise>; + }; + + processTransitions: { + /** + * Query available process transitions + */ + query: (params?: BaseQueryParams) => Promise; + }; + + bookings: { + /** + * Query bookings + */ + query: ( + params?: + & { + listingId?: UUID; + start?: string; + end?: string; + state?: string; + } + & PaginationParams + & BaseQueryParams, + ) => Promise>; + }; + + messages: { + /** + * Query messages in a transaction + */ + query: ( + params: { transactionId: UUID } & PaginationParams & BaseQueryParams, + ) => Promise>; + /** + * Send a message in a transaction + */ + send: ( + params: { transactionId: UUID; content: string }, + queryParams?: { expand?: boolean }, + opts?: PerRequestOptions, + ) => Promise>; + }; + + reviews: { + /** + * Show a specific review + */ + show: (params: { id: UUID } & BaseQueryParams) => Promise>; + /** + * Query reviews + */ + query: ( + params?: + & { + listingId?: UUID; + subjectId?: UUID; + state?: string; + type?: string; + } + & PaginationParams + & BaseQueryParams, + ) => Promise>; + }; + + timeslots: { + /** + * Query available time slots for a listing + */ + query: ( + params: { listingId: UUID; start: string; end: string } & BaseQueryParams, + ) => Promise>; + }; + + stripeAccount: { + /** + * Create Stripe account + */ + create: ( + params: { country?: string; accountToken?: string; bankAccountToken?: string }, + queryParams?: { expand?: boolean }, + opts?: PerRequestOptions, + ) => Promise>; + /** + * Fetch Stripe account information + */ + fetch: (params?: BaseQueryParams) => Promise>; + /** + * Update Stripe account + */ + update: ( + params: { accountToken?: string; bankAccountToken?: string }, + queryParams?: { expand?: boolean }, + opts?: PerRequestOptions, + ) => Promise>; + }; + + stripeAccountLinks: { + /** + * Create Stripe account link for onboarding + */ + create: ( + params: { + failureURL: string; + successURL: string; + type: string; + collect?: string; + }, + queryParams?: { expand?: boolean }, + opts?: PerRequestOptions, + ) => Promise; + }; + + stripePersons: { + /** + * Create Stripe person for an account + */ + create: ( + params: { personToken: string }, + queryParams?: { expand?: boolean }, + opts?: PerRequestOptions, + ) => Promise; + }; + + stripeSetupIntents: { + /** + * Create Stripe setup intent for saving payment method + */ + create: ( + params?: Record, + queryParams?: { expand?: boolean }, + opts?: PerRequestOptions, + ) => Promise; + }; + + stripeCustomer: { + /** + * Create Stripe customer for current user + */ + create: ( + params?: { stripePaymentMethodId?: string }, + queryParams?: { expand?: boolean }, + opts?: PerRequestOptions, + ) => Promise>; + /** + * Add payment method to Stripe customer + */ + addPaymentMethod: ( + params: { stripePaymentMethodId: string }, + queryParams?: { expand?: boolean }, + opts?: PerRequestOptions, + ) => Promise>; + /** + * Delete payment method from Stripe customer + */ + deletePaymentMethod: ( + params: { stripePaymentMethodId: string }, + queryParams?: { expand?: boolean }, + opts?: PerRequestOptions, + ) => Promise>; + }; + + stockAdjustments: { + /** + * Query stock adjustments for a listing + */ + query: ( + params: { listingId: UUID } & PaginationParams & BaseQueryParams, + ) => Promise>; + /** + * Create stock adjustment + */ + create: ( + params: { listingId: UUID; quantity: number }, + queryParams?: { expand?: boolean }, + opts?: PerRequestOptions, + ) => Promise>; + }; + + stock: { + /** + * Compare and set stock quantity atomically + */ + compareAndSet: ( + params: { listingId: UUID; oldTotal: number; newTotal: number }, + queryParams?: { expand?: boolean }, + opts?: PerRequestOptions, + ) => Promise>; + }; + + sitemapData: { + /** + * Query listings for sitemap generation + */ + queryListings: (params?: PaginationParams & BaseQueryParams) => Promise>; + /** + * Query assets for sitemap generation + */ + queryAssets: (params?: PaginationParams) => Promise; + }; + + /** + * Authentication methods + */ + login: (params: { username: string; password: string }) => Promise; + loginAs: (params: { userId: UUID }) => Promise; + logout: () => Promise; + authInfo: () => Promise; + exchangeToken: (params?: Record) => Promise; + loginWithIdp: (params: { idpId: string; idpToken: string; idpClientId: string }) => Promise; + + /** + * Asset delivery methods + */ assetByAlias: (params: { path: string; alias: string }) => Promise<{ status?: number; data: unknown }>; - Branding: Branding; + assetByVersion: (params: { path: string; version: string }) => Promise<{ status?: number; data: unknown }>; + assetsByAlias: (params: { paths: string[]; alias: string }) => Promise<{ status?: number; data: unknown }>; + assetsByVersion: (params: { paths: string[]; version: string }) => Promise<{ status?: number; data: unknown }>; +} + +/** + * SDK configuration options + */ +export interface SdkConfig { + clientId: string; + baseUrl?: string; + assetCdnBaseUrl?: string; + adapter?: unknown; + tokenStore?: unknown; + typeHandlers?: unknown[]; + transitVerbose?: boolean; + httpAgent?: unknown; + httpsAgent?: unknown; } -export function createInstance(config: { clientId: string }): MarketplaceSdk; +/** + * Create a new Sharetribe SDK instance + * @param config - SDK configuration including required clientId + * @returns Configured SDK instance + */ +export function createInstance(config: SdkConfig): MarketplaceSdk; diff --git a/types/sharetribe-flex-sdk/package.json b/types/sharetribe-flex-sdk/package.json index 54f5eeda4e78ec..628a81767a35b4 100644 --- a/types/sharetribe-flex-sdk/package.json +++ b/types/sharetribe-flex-sdk/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "@types/sharetribe-flex-sdk", - "version": "1.21.9999", + "version": "1.22.9999", "projects": [ "https://github.com/sharetribe/flex-sdk-js" ], diff --git a/types/sharetribe-flex-sdk/sharetribe-flex-sdk-tests.ts b/types/sharetribe-flex-sdk/sharetribe-flex-sdk-tests.ts index a57a63daa99c81..1fb9a73a25fd19 100644 --- a/types/sharetribe-flex-sdk/sharetribe-flex-sdk-tests.ts +++ b/types/sharetribe-flex-sdk/sharetribe-flex-sdk-tests.ts @@ -1,8 +1,8 @@ -import { createInstance, MarketplaceDataResponse } from "sharetribe-flex-sdk"; +import { createInstance, Marketplace, ShowResponse } from "sharetribe-flex-sdk"; const sdk = createInstance({ clientId: "client-id" }); -sdk.marketplace.show().then((response: { status: number; statusText: string; data: MarketplaceDataResponse }) => { +sdk.marketplace.show().then((response: ShowResponse) => { const name: string = response.data.data.attributes.name; const description: string | null = response.data.data.attributes.description; }); @@ -11,8 +11,3 @@ sdk.assetByAlias({ path: "/assets", alias: "logo" }).then((result: { status?: nu const status: number | undefined = result.status; const data: unknown = result.data; }); - -const colors = sdk.Branding.data.marketplaceColors; -const primary: string = colors.primaryButton; -const notification: string = colors.notificationPrimaryButton; -const mainColor: string = colors.mainColor;