@crosspost/sdk 0.1.9 → 0.1.10
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/README.md +23 -13
- package/dist/index.cjs +131 -4822
- package/dist/index.d.cts +7 -6
- package/dist/index.d.ts +7 -6
- package/dist/index.js +107 -4725
- package/package.json +2 -1
- package/src/api/auth.ts +31 -12
- package/src/core/request.ts +17 -2
- package/src/utils/popup.ts +129 -0
package/README.md
CHANGED
@@ -11,7 +11,7 @@ bun install @crosspost/sdk
|
|
11
11
|
## Quick Start
|
12
12
|
|
13
13
|
```typescript
|
14
|
-
import {
|
14
|
+
import { CrosspostClient, CrosspostError, isAuthError } from '@crosspost/sdk';
|
15
15
|
|
16
16
|
// Initialize the client (authentication can be provided later)
|
17
17
|
const client = new CrosspostClient({
|
@@ -43,7 +43,7 @@ async function authorizeNearAccount() {
|
|
43
43
|
return true;
|
44
44
|
} catch (error) {
|
45
45
|
console.error('NEAR authorization failed');
|
46
|
-
if (error instanceof
|
46
|
+
if (error instanceof CrosspostError) {
|
47
47
|
console.error('Error code:', error.code);
|
48
48
|
console.error('Status:', error.status);
|
49
49
|
console.error('Details:', error.details);
|
@@ -64,7 +64,7 @@ async function unauthorizeNearAccount() {
|
|
64
64
|
return true;
|
65
65
|
} catch (error) {
|
66
66
|
console.error('Failed to unauthorize NEAR account');
|
67
|
-
if (error instanceof
|
67
|
+
if (error instanceof CrosspostError) {
|
68
68
|
console.error('Error code:', error.code);
|
69
69
|
console.error('Status:', error.status);
|
70
70
|
console.error('Details:', error.details);
|
@@ -85,7 +85,7 @@ async function revokePlatformAuth(platform) {
|
|
85
85
|
return true;
|
86
86
|
} catch (error) {
|
87
87
|
console.error(`Failed to revoke ${platform} authorization`);
|
88
|
-
if (error instanceof
|
88
|
+
if (error instanceof CrosspostError) {
|
89
89
|
console.error('Error code:', error.code);
|
90
90
|
console.error('Status:', error.status);
|
91
91
|
console.error('Details:', error.details);
|
@@ -120,15 +120,25 @@ async function createPost() {
|
|
120
120
|
} else {
|
121
121
|
// Handle other error types
|
122
122
|
console.error('Error creating post:', error);
|
123
|
-
if (error instanceof
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
123
|
+
if (error instanceof CrosspostError) {
|
124
|
+
// Use error utility functions to handle specific cases
|
125
|
+
if (isPlatformError(error)) {
|
126
|
+
console.error('Platform:', error.platform);
|
127
|
+
console.error('Error code:', error.code);
|
128
|
+
console.error('Details:', error.details);
|
129
|
+
} else if (isRateLimitError(error)) {
|
130
|
+
console.error('Rate limited until:', error.details?.rateLimit?.reset);
|
131
|
+
} else if (isValidationError(error)) {
|
132
|
+
console.error('Validation errors:', error.details?.validationErrors);
|
133
|
+
}
|
134
|
+
|
135
|
+
// Check if error is recoverable
|
136
|
+
if (error.recoverable) {
|
137
|
+
console.log('This error is recoverable - retry may succeed');
|
138
|
+
}
|
139
|
+
} else if (error instanceof Error) {
|
140
|
+
// Handle non-API errors (network issues, etc)
|
141
|
+
console.error('Unexpected error:', error.message);
|
132
142
|
}
|
133
143
|
}
|
134
144
|
}
|