@crosspost/sdk 0.1.11 → 0.1.13

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.cjs CHANGED
@@ -544,15 +544,13 @@ var AuthApi = class {
544
544
  * @throws Error if popups are blocked or if running in a non-browser environment.
545
545
  */
546
546
  async loginToPlatform(platform, options) {
547
- const baseUrl = this.options.baseUrl || "";
548
- const loginUrl = new URL(`/auth/${platform}/login`, baseUrl);
549
- if (options?.successUrl) {
550
- loginUrl.searchParams.set("successUrl", options.successUrl);
551
- }
552
- if (options?.errorUrl) {
553
- loginUrl.searchParams.set("errorUrl", options.errorUrl);
554
- }
555
- const result = await openAuthPopup(loginUrl.toString());
547
+ const { url } = await makeRequest(
548
+ "POST",
549
+ `/auth/${platform}/login`,
550
+ this.options,
551
+ options || { redirect: false }
552
+ );
553
+ const result = await openAuthPopup(url);
556
554
  if (!result.success || !result.userId) {
557
555
  throw new Error(result.error || "Authentication failed");
558
556
  }
package/dist/index.js CHANGED
@@ -498,15 +498,13 @@ var AuthApi = class {
498
498
  * @throws Error if popups are blocked or if running in a non-browser environment.
499
499
  */
500
500
  async loginToPlatform(platform, options) {
501
- const baseUrl = this.options.baseUrl || "";
502
- const loginUrl = new URL(`/auth/${platform}/login`, baseUrl);
503
- if (options?.successUrl) {
504
- loginUrl.searchParams.set("successUrl", options.successUrl);
505
- }
506
- if (options?.errorUrl) {
507
- loginUrl.searchParams.set("errorUrl", options.errorUrl);
508
- }
509
- const result = await openAuthPopup(loginUrl.toString());
501
+ const { url } = await makeRequest(
502
+ "POST",
503
+ `/auth/${platform}/login`,
504
+ this.options,
505
+ options || { redirect: false }
506
+ );
507
+ const result = await openAuthPopup(url);
510
508
  if (!result.success || !result.userId) {
511
509
  throw new Error(result.error || "Authentication failed");
512
510
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crosspost/sdk",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "description": "SDK for interacting with the Crosspost API",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
package/src/api/auth.ts CHANGED
@@ -5,6 +5,7 @@ import type {
5
5
  AuthStatusParams,
6
6
  AuthStatusResponse,
7
7
  AuthTokenRequest,
8
+ AuthUrlResponse,
8
9
  ConnectedAccount,
9
10
  ConnectedAccountsResponse,
10
11
  NearAuthorizationRequest,
@@ -65,20 +66,16 @@ export class AuthApi {
65
66
  platform: Platform,
66
67
  options?: AuthInitRequest,
67
68
  ): Promise<AuthCallbackResponse> {
68
- // Construct the login URL
69
- const baseUrl = this.options.baseUrl || '';
70
- const loginUrl = new URL(`/auth/${platform}/login`, baseUrl);
71
-
72
- // Add successUrl and errorUrl if provided
73
- if (options?.successUrl) {
74
- loginUrl.searchParams.set('successUrl', options.successUrl);
75
- }
76
- if (options?.errorUrl) {
77
- loginUrl.searchParams.set('errorUrl', options.errorUrl);
78
- }
69
+ // Make POST request to get auth URL
70
+ const { url } = await makeRequest<AuthUrlResponse, AuthInitRequest>(
71
+ 'POST',
72
+ `/auth/${platform}/login`,
73
+ this.options,
74
+ options || { redirect: false },
75
+ );
79
76
 
80
- // Open the popup and wait for the result
81
- const result = await openAuthPopup(loginUrl.toString());
77
+ // Open the popup with the auth URL
78
+ const result = await openAuthPopup(url);
82
79
 
83
80
  if (!result.success || !result.userId) {
84
81
  throw new Error(result.error || 'Authentication failed');
@@ -1,13 +1,6 @@
1
1
  // @ts-nocheck
2
-
3
2
  import type { PlatformName } from '@crosspost/types';
4
-
5
3
  declare global {
6
- interface Window {
7
- innerWidth: number;
8
- innerHeight: number;
9
- open(url: string, target: string, features: string): Window | null;
10
- }
11
4
  interface WindowEventMap {
12
5
  message: MessageEvent<AuthCallbackMessage>;
13
6
  }