@lobehub/market-sdk 0.27.1-beta.2 → 0.27.1-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1342,6 +1342,10 @@ interface OAuthConnection {
1342
1342
  * When the connection was created
1343
1343
  */
1344
1344
  createdAt: string;
1345
+ /**
1346
+ * Provider user email (if available)
1347
+ */
1348
+ providerEmail?: string;
1345
1349
  /**
1346
1350
  * Provider identifier
1347
1351
  */
@@ -1350,10 +1354,6 @@ interface OAuthConnection {
1350
1354
  * Provider display name
1351
1355
  */
1352
1356
  providerName: string;
1353
- /**
1354
- * Provider user email (if available)
1355
- */
1356
- providerEmail?: string;
1357
1357
  /**
1358
1358
  * Provider user ID
1359
1359
  */
@@ -1400,22 +1400,22 @@ interface ConnectionHealth {
1400
1400
  * Connection statistics
1401
1401
  */
1402
1402
  interface ConnectionStats {
1403
- /**
1404
- * Total number of connections
1405
- */
1406
- total: number;
1407
1403
  /**
1408
1404
  * Number of active/healthy connections
1409
1405
  */
1410
1406
  active: number;
1407
+ /**
1408
+ * Number of expired connections
1409
+ */
1410
+ expired: number;
1411
1411
  /**
1412
1412
  * Number of connections expiring soon
1413
1413
  */
1414
1414
  expiringSoon: number;
1415
1415
  /**
1416
- * Number of expired connections
1416
+ * Total number of connections
1417
1417
  */
1418
- expired: number;
1418
+ total: number;
1419
1419
  }
1420
1420
  /**
1421
1421
  * Response for listing providers
@@ -1490,6 +1490,10 @@ interface GetConnectionStatsResponse {
1490
1490
  * Response for connection health check
1491
1491
  */
1492
1492
  interface GetConnectionHealthResponse {
1493
+ /**
1494
+ * Token expiry time (ISO string)
1495
+ */
1496
+ expiresAt?: string;
1493
1497
  /**
1494
1498
  * Whether the connection is healthy
1495
1499
  */
@@ -1506,10 +1510,6 @@ interface GetConnectionHealthResponse {
1506
1510
  * Token status
1507
1511
  */
1508
1512
  tokenStatus: 'valid' | 'expiring_soon' | 'expired' | 'unknown';
1509
- /**
1510
- * Token expiry time (ISO string)
1511
- */
1512
- expiresAt?: string;
1513
1513
  }
1514
1514
  /**
1515
1515
  * Response for all connections health check
@@ -1527,11 +1527,11 @@ interface GetAllConnectionsHealthResponse {
1527
1527
  * Health summary
1528
1528
  */
1529
1529
  summary: {
1530
- total: number;
1530
+ expired: number;
1531
+ expiringSoon: number;
1531
1532
  healthy: number;
1533
+ total: number;
1532
1534
  unhealthy: number;
1533
- expiringSoon: number;
1534
- expired: number;
1535
1535
  };
1536
1536
  }
1537
1537
  /**
@@ -1564,14 +1564,53 @@ interface RevokeConnectionResponse {
1564
1564
  * Parameters for getting authorize URL
1565
1565
  */
1566
1566
  interface GetAuthorizeUrlParams {
1567
+ /**
1568
+ * Redirect URI after authorization (optional)
1569
+ */
1570
+ redirectUri?: string;
1567
1571
  /**
1568
1572
  * Custom scopes to request (optional, uses provider defaults if not specified)
1569
1573
  */
1570
1574
  scopes?: string[];
1575
+ }
1576
+ /**
1577
+ * Parameters for authorize request
1578
+ */
1579
+ interface AuthorizeParams {
1571
1580
  /**
1572
1581
  * Redirect URI after authorization (optional)
1573
1582
  */
1574
- redirectUri?: string;
1583
+ redirect_uri?: string;
1584
+ /**
1585
+ * Custom scopes to request (optional, uses provider defaults if not specified)
1586
+ */
1587
+ scopes?: string[];
1588
+ }
1589
+ /**
1590
+ * Response for authorize request
1591
+ *
1592
+ * Returns a signed authorization code that can be used to initiate
1593
+ * the OAuth flow in a browser context where Bearer tokens cannot be sent.
1594
+ */
1595
+ interface AuthorizeResponse {
1596
+ /**
1597
+ * The full URL to open in browser to start OAuth flow
1598
+ * Includes the signed code as a query parameter
1599
+ */
1600
+ authorize_url: string;
1601
+ /**
1602
+ * Signed authorization code
1603
+ * Can be used with GET /api/connect/:provider/start?code=xxx
1604
+ */
1605
+ code: string;
1606
+ /**
1607
+ * Code expiration time in seconds (typically 300 = 5 minutes)
1608
+ */
1609
+ expires_in: number;
1610
+ /**
1611
+ * Whether the request was successful
1612
+ */
1613
+ success: boolean;
1575
1614
  }
1576
1615
 
1577
1616
  /**
@@ -3719,36 +3758,64 @@ declare class ConnectService extends BaseSDK {
3719
3758
  */
3720
3759
  getProvider(provider: string, options?: globalThis.RequestInit): Promise<GetConnectProviderResponse>;
3721
3760
  /**
3722
- * Generates the OAuth authorization URL for a provider
3761
+ * Requests an authorization code for initiating OAuth flow
3723
3762
  *
3724
- * This URL should be opened in a browser (popup or redirect) for the user
3725
- * to authorize the connection. After authorization, the user will be
3726
- * redirected back to the callback URL.
3763
+ * This method obtains a signed, short-lived authorization code that can be
3764
+ * used to start the OAuth flow in a browser context where Bearer tokens
3765
+ * cannot be sent (e.g., opening a popup or redirecting the page).
3727
3766
  *
3728
- * Note: This method does NOT make an API request. It constructs the URL
3729
- * that the user should visit to start the OAuth flow.
3767
+ * The returned `authorize_url` can be directly opened in a browser.
3730
3768
  *
3731
- * @param provider - The provider ID (e.g., 'linear', 'github')
3769
+ * **This is the recommended way to initiate OAuth authorization.**
3770
+ *
3771
+ * @param provider - The provider ID (e.g., 'linear', 'github', 'microsoft')
3732
3772
  * @param params - Optional parameters for scopes and redirect URI
3733
- * @returns The authorization URL to redirect the user to
3773
+ * @param options - Optional request options (must include authentication)
3774
+ * @returns Promise resolving to the authorization code and URL
3734
3775
  *
3735
3776
  * @example
3736
3777
  * ```typescript
3737
- * // Basic usage - opens in popup
3738
- * const url = sdk.connect.getAuthorizeUrl('linear');
3739
- * const popup = window.open(url, 'oauth', 'width=600,height=700');
3778
+ * // Get authorization code and URL
3779
+ * const { authorize_url, code, expires_in } = await sdk.connect.authorize('linear');
3780
+ *
3781
+ * // Open the URL in a popup
3782
+ * const popup = window.open(authorize_url, 'oauth', 'width=600,height=700,popup=yes');
3740
3783
  *
3741
3784
  * // With custom scopes
3742
- * const url = sdk.connect.getAuthorizeUrl('github', {
3785
+ * const { authorize_url } = await sdk.connect.authorize('github', {
3743
3786
  * scopes: ['user', 'repo', 'read:org']
3744
3787
  * });
3745
3788
  *
3746
3789
  * // With redirect URI
3747
- * const url = sdk.connect.getAuthorizeUrl('linear', {
3748
- * redirectUri: 'https://myapp.com/oauth/callback'
3790
+ * const { authorize_url } = await sdk.connect.authorize('microsoft', {
3791
+ * scopes: ['Calendars.ReadWrite'],
3792
+ * redirect_uri: 'https://myapp.com/oauth/callback'
3749
3793
  * });
3750
3794
  * ```
3751
3795
  */
3796
+ authorize(provider: string, params?: AuthorizeParams, options?: globalThis.RequestInit): Promise<AuthorizeResponse>;
3797
+ /**
3798
+ * Generates the OAuth authorization URL for a provider (deprecated)
3799
+ *
3800
+ * @deprecated Use `authorize()` instead. This method constructs a URL that
3801
+ * requires Bearer token authentication, which doesn't work in browser redirects.
3802
+ * The new `authorize()` method returns a URL with a signed code that works
3803
+ * in browser contexts.
3804
+ *
3805
+ * @param provider - The provider ID (e.g., 'linear', 'github')
3806
+ * @param params - Optional parameters for scopes and redirect URI
3807
+ * @returns The authorization URL (requires Bearer token, won't work in browser)
3808
+ *
3809
+ * @example
3810
+ * ```typescript
3811
+ * // OLD way (deprecated) - won't work in browser
3812
+ * const url = sdk.connect.getAuthorizeUrl('linear');
3813
+ *
3814
+ * // NEW way (recommended) - works in browser
3815
+ * const { authorize_url } = await sdk.connect.authorize('linear');
3816
+ * window.open(authorize_url, 'oauth', 'width=600,height=700');
3817
+ * ```
3818
+ */
3752
3819
  getAuthorizeUrl(provider: string, params?: GetAuthorizeUrlParams): string;
3753
3820
  /**
3754
3821
  * Gets the connection status for a specific provider
@@ -4678,4 +4745,4 @@ declare function buildTrustedClientPayload(params: {
4678
4745
  userId: string;
4679
4746
  }): TrustedClientPayload;
4680
4747
 
4681
- export { type AccountMeta, type AdminListQueryParams, type AdminListResponse, type AdminPluginParams, type AgentCreateRequest, type AgentCreateResponse, type AgentDetailQuery, type AgentExtension, type AgentInstallCountRequest, type AgentInstallCountResponse, type AgentInterface, type AgentItemDetail, type AgentListQuery, type AgentListResponse, type AgentModifyRequest, type AgentModifyResponse, type AgentSecurityRequirement, type AgentSecurityScheme, type AgentSkill, type AgentStatus, type AgentStatusChangeResponse, type AgentUploadRequest, type AgentUploadResponse, type AgentUploadVersion, type AgentVersionCreateRequest, type AgentVersionCreateResponse, type AgentVersionLocalization, type AgentVersionModifyRequest, type AgentVersionModifyResponse, type AuthorizationCodeTokenRequest, type CallSkillToolResponse, type CheckFavoriteQuery, type CheckFavoriteResponse, type CheckFollowQuery, type CheckFollowResponse, type CheckLikeQuery, type CheckLikeResponse, type ClientRegistrationError, type ClientRegistrationRequest, type ClientRegistrationResponse, type CodeInterpreterToolName, type CodeInterpreterToolParams, type ConnectProvider, type ConnectProviderDetail, type ConnectProviderScopes, type ConnectionHealth, type ConnectionStats, type DiscoveryDocument, type EditLocalFileParams, type ExecuteCodeParams, type ExportFileParams, type FavoriteListResponse, type FavoriteQuery, type FavoriteRequest, type FeedbackClientInfo, type FollowListItem, type FollowListResponse, type FollowRequest, type GetAllConnectionsHealthResponse, type GetAuthorizeUrlParams, type GetCommandOutputParams, type GetConnectProviderResponse, type GetConnectionHealthResponse, type GetConnectionStatsResponse, type GetConnectionStatusResponse, type GetSkillStatusResponse, type GetSkillToolResponse, type GlobLocalFilesParams, type GrepContentParams, type InteractionTargetType, type KillCommandParams, type LikeListResponse, type LikeQuery, type LikeRequest, type ListConnectProvidersResponse, type ListConnectionsResponse, type ListLocalFilesParams, type ListSkillProvidersResponse, type ListSkillToolsResponse, MarketAdmin, MarketSDK, type MarketSDKOptions, type MoveLocalFilesParams, type MoveOperation, type OAuthConnection, type OAuthTokenResponse, type OwnAgentListQuery, type PaginationQuery, type PluginI18nImportParams, type PluginI18nImportResponse, type PluginItem, type PluginListResponse, type PluginLocalization, type PluginQueryParams, type PluginUpdateParams, type PluginVersionCreateParams, type PluginVersionUpdateParams, type ProgrammingLanguage, type ReadLocalFileParams, type RefreshConnectionResponse, type RefreshTokenRequest, type RenameLocalFileParams, type ReviewStatus, ReviewStatusEnumSchema, type RevokeConnectionResponse, type RunBuildInToolsError, type RunBuildInToolsRequest, type RunBuildInToolsResponse, type RunBuildInToolsSuccessData, type RunCommandParams, type SearchLocalFilesParams, type SharedTokenState, type SkillCallParams, type SkillErrorResponse, type SkillProviderInfo, type SkillProviderStatus, type SkillTool, StatusEnumSchema, type SubmitFeedbackRequest, type SubmitFeedbackResponse, type SuccessResponse, type ToggleLikeResponse, type TrustedClientPayload, type UnclaimedPluginItem, type UpdateUserInfoRequest, type UpdateUserInfoResponse, type UserAgentItem, type UserInfoQuery, type UserInfoResponse, type UserProfile, VisibilityEnumSchema, type WriteLocalFileParams, buildTrustedClientPayload, createTrustedClientToken, generateNonce };
4748
+ export { type AccountMeta, type AdminListQueryParams, type AdminListResponse, type AdminPluginParams, type AgentCreateRequest, type AgentCreateResponse, type AgentDetailQuery, type AgentExtension, type AgentInstallCountRequest, type AgentInstallCountResponse, type AgentInterface, type AgentItemDetail, type AgentListQuery, type AgentListResponse, type AgentModifyRequest, type AgentModifyResponse, type AgentSecurityRequirement, type AgentSecurityScheme, type AgentSkill, type AgentStatus, type AgentStatusChangeResponse, type AgentUploadRequest, type AgentUploadResponse, type AgentUploadVersion, type AgentVersionCreateRequest, type AgentVersionCreateResponse, type AgentVersionLocalization, type AgentVersionModifyRequest, type AgentVersionModifyResponse, type AuthorizationCodeTokenRequest, type AuthorizeParams, type AuthorizeResponse, type CallSkillToolResponse, type CheckFavoriteQuery, type CheckFavoriteResponse, type CheckFollowQuery, type CheckFollowResponse, type CheckLikeQuery, type CheckLikeResponse, type ClientRegistrationError, type ClientRegistrationRequest, type ClientRegistrationResponse, type CodeInterpreterToolName, type CodeInterpreterToolParams, type ConnectProvider, type ConnectProviderDetail, type ConnectProviderScopes, type ConnectionHealth, type ConnectionStats, type DiscoveryDocument, type EditLocalFileParams, type ExecuteCodeParams, type ExportFileParams, type FavoriteListResponse, type FavoriteQuery, type FavoriteRequest, type FeedbackClientInfo, type FollowListItem, type FollowListResponse, type FollowRequest, type GetAllConnectionsHealthResponse, type GetAuthorizeUrlParams, type GetCommandOutputParams, type GetConnectProviderResponse, type GetConnectionHealthResponse, type GetConnectionStatsResponse, type GetConnectionStatusResponse, type GetSkillStatusResponse, type GetSkillToolResponse, type GlobLocalFilesParams, type GrepContentParams, type InteractionTargetType, type KillCommandParams, type LikeListResponse, type LikeQuery, type LikeRequest, type ListConnectProvidersResponse, type ListConnectionsResponse, type ListLocalFilesParams, type ListSkillProvidersResponse, type ListSkillToolsResponse, MarketAdmin, MarketSDK, type MarketSDKOptions, type MoveLocalFilesParams, type MoveOperation, type OAuthConnection, type OAuthTokenResponse, type OwnAgentListQuery, type PaginationQuery, type PluginI18nImportParams, type PluginI18nImportResponse, type PluginItem, type PluginListResponse, type PluginLocalization, type PluginQueryParams, type PluginUpdateParams, type PluginVersionCreateParams, type PluginVersionUpdateParams, type ProgrammingLanguage, type ReadLocalFileParams, type RefreshConnectionResponse, type RefreshTokenRequest, type RenameLocalFileParams, type ReviewStatus, ReviewStatusEnumSchema, type RevokeConnectionResponse, type RunBuildInToolsError, type RunBuildInToolsRequest, type RunBuildInToolsResponse, type RunBuildInToolsSuccessData, type RunCommandParams, type SearchLocalFilesParams, type SharedTokenState, type SkillCallParams, type SkillErrorResponse, type SkillProviderInfo, type SkillProviderStatus, type SkillTool, StatusEnumSchema, type SubmitFeedbackRequest, type SubmitFeedbackResponse, type SuccessResponse, type ToggleLikeResponse, type TrustedClientPayload, type UnclaimedPluginItem, type UpdateUserInfoRequest, type UpdateUserInfoResponse, type UserAgentItem, type UserInfoQuery, type UserInfoResponse, type UserProfile, VisibilityEnumSchema, type WriteLocalFileParams, buildTrustedClientPayload, createTrustedClientToken, generateNonce };
package/dist/index.mjs CHANGED
@@ -2199,10 +2199,7 @@ var ConnectService = class extends BaseSDK {
2199
2199
  async listProviders(options) {
2200
2200
  var _a;
2201
2201
  log12("Listing connect providers");
2202
- const result = await this.request(
2203
- "/connect/providers",
2204
- options
2205
- );
2202
+ const result = await this.request("/connect/providers", options);
2206
2203
  log12("Found %d connect providers", ((_a = result.providers) == null ? void 0 : _a.length) || 0);
2207
2204
  return result;
2208
2205
  }
@@ -2226,38 +2223,81 @@ var ConnectService = class extends BaseSDK {
2226
2223
  return result;
2227
2224
  }
2228
2225
  /**
2229
- * Generates the OAuth authorization URL for a provider
2226
+ * Requests an authorization code for initiating OAuth flow
2230
2227
  *
2231
- * This URL should be opened in a browser (popup or redirect) for the user
2232
- * to authorize the connection. After authorization, the user will be
2233
- * redirected back to the callback URL.
2228
+ * This method obtains a signed, short-lived authorization code that can be
2229
+ * used to start the OAuth flow in a browser context where Bearer tokens
2230
+ * cannot be sent (e.g., opening a popup or redirecting the page).
2234
2231
  *
2235
- * Note: This method does NOT make an API request. It constructs the URL
2236
- * that the user should visit to start the OAuth flow.
2232
+ * The returned `authorize_url` can be directly opened in a browser.
2237
2233
  *
2238
- * @param provider - The provider ID (e.g., 'linear', 'github')
2234
+ * **This is the recommended way to initiate OAuth authorization.**
2235
+ *
2236
+ * @param provider - The provider ID (e.g., 'linear', 'github', 'microsoft')
2239
2237
  * @param params - Optional parameters for scopes and redirect URI
2240
- * @returns The authorization URL to redirect the user to
2238
+ * @param options - Optional request options (must include authentication)
2239
+ * @returns Promise resolving to the authorization code and URL
2241
2240
  *
2242
2241
  * @example
2243
2242
  * ```typescript
2244
- * // Basic usage - opens in popup
2245
- * const url = sdk.connect.getAuthorizeUrl('linear');
2246
- * const popup = window.open(url, 'oauth', 'width=600,height=700');
2243
+ * // Get authorization code and URL
2244
+ * const { authorize_url, code, expires_in } = await sdk.connect.authorize('linear');
2245
+ *
2246
+ * // Open the URL in a popup
2247
+ * const popup = window.open(authorize_url, 'oauth', 'width=600,height=700,popup=yes');
2247
2248
  *
2248
2249
  * // With custom scopes
2249
- * const url = sdk.connect.getAuthorizeUrl('github', {
2250
+ * const { authorize_url } = await sdk.connect.authorize('github', {
2250
2251
  * scopes: ['user', 'repo', 'read:org']
2251
2252
  * });
2252
2253
  *
2253
2254
  * // With redirect URI
2254
- * const url = sdk.connect.getAuthorizeUrl('linear', {
2255
- * redirectUri: 'https://myapp.com/oauth/callback'
2255
+ * const { authorize_url } = await sdk.connect.authorize('microsoft', {
2256
+ * scopes: ['Calendars.ReadWrite'],
2257
+ * redirect_uri: 'https://myapp.com/oauth/callback'
2256
2258
  * });
2257
2259
  * ```
2258
2260
  */
2261
+ async authorize(provider, params, options) {
2262
+ log12("Requesting authorization code for provider: %s", provider);
2263
+ const result = await this.request(
2264
+ `/connect/${encodeURIComponent(provider)}/authorize`,
2265
+ {
2266
+ body: params ? JSON.stringify(params) : void 0,
2267
+ headers: {
2268
+ "Content-Type": "application/json"
2269
+ },
2270
+ method: "POST",
2271
+ ...options
2272
+ }
2273
+ );
2274
+ log12("Authorization code obtained, expires in %d seconds", result.expires_in);
2275
+ return result;
2276
+ }
2277
+ /**
2278
+ * Generates the OAuth authorization URL for a provider (deprecated)
2279
+ *
2280
+ * @deprecated Use `authorize()` instead. This method constructs a URL that
2281
+ * requires Bearer token authentication, which doesn't work in browser redirects.
2282
+ * The new `authorize()` method returns a URL with a signed code that works
2283
+ * in browser contexts.
2284
+ *
2285
+ * @param provider - The provider ID (e.g., 'linear', 'github')
2286
+ * @param params - Optional parameters for scopes and redirect URI
2287
+ * @returns The authorization URL (requires Bearer token, won't work in browser)
2288
+ *
2289
+ * @example
2290
+ * ```typescript
2291
+ * // OLD way (deprecated) - won't work in browser
2292
+ * const url = sdk.connect.getAuthorizeUrl('linear');
2293
+ *
2294
+ * // NEW way (recommended) - works in browser
2295
+ * const { authorize_url } = await sdk.connect.authorize('linear');
2296
+ * window.open(authorize_url, 'oauth', 'width=600,height=700');
2297
+ * ```
2298
+ */
2259
2299
  getAuthorizeUrl(provider, params) {
2260
- log12("Generating authorize URL for provider: %s", provider);
2300
+ log12("Generating authorize URL for provider: %s (deprecated, use authorize() instead)", provider);
2261
2301
  const queryParams = new URLSearchParams();
2262
2302
  if ((params == null ? void 0 : params.scopes) && params.scopes.length > 0) {
2263
2303
  queryParams.set("scope", params.scopes.join(","));