@crosspost/sdk 0.1.3 → 0.1.4
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/LICENSE +21 -0
- package/README.md +85 -93
- package/dist/index.cjs +73 -160
- package/dist/index.d.cts +18 -43
- package/dist/index.d.ts +18 -43
- package/dist/index.js +69 -141
- package/package.json +1 -3
- package/src/core/client.ts +3 -5
- package/src/core/request.ts +1 -11
- package/src/index.ts +3 -12
- package/src/utils/error.ts +300 -0
- package/src/utils/cookie.ts +0 -91
- package/src/utils/error-utils.ts +0 -310
package/dist/index.d.cts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { NearAuthData } from 'near-sign-verify';
|
2
|
-
import { ActivityLeaderboardQuery, ActivityLeaderboardResponse, AccountActivityQuery, AccountActivityResponse, AccountPostsQuery, AccountPostsResponse, NearAuthorizationResponse, Platform, EnhancedApiResponse, AuthStatusResponse, AuthRevokeResponse, ConnectedAccountsResponse, CreatePostRequest, CreatePostResponse, RepostRequest, RepostResponse, QuotePostRequest, QuotePostResponse, ReplyToPostRequest, ReplyToPostResponse, LikePostRequest, LikePostResponse, UnlikePostRequest, UnlikePostResponse, DeletePostRequest, DeletePostResponse, RateLimitResponse, EndpointRateLimitResponse, ApiError,
|
2
|
+
import { ActivityLeaderboardQuery, ActivityLeaderboardResponse, AccountActivityQuery, AccountActivityResponse, AccountPostsQuery, AccountPostsResponse, NearAuthorizationResponse, Platform, EnhancedApiResponse, AuthStatusResponse, AuthRevokeResponse, ConnectedAccountsResponse, CreatePostRequest, CreatePostResponse, RepostRequest, RepostResponse, QuotePostRequest, QuotePostResponse, ReplyToPostRequest, ReplyToPostResponse, LikePostRequest, LikePostResponse, UnlikePostRequest, UnlikePostResponse, DeletePostRequest, DeletePostResponse, RateLimitResponse, EndpointRateLimitResponse, ApiError, ApiErrorCode, PlatformError } from '@crosspost/types';
|
3
3
|
export * from '@crosspost/types';
|
4
4
|
|
5
5
|
/**
|
@@ -244,8 +244,8 @@ declare class CrosspostClient {
|
|
244
244
|
*/
|
245
245
|
constructor(config?: CrosspostClientConfig);
|
246
246
|
/**
|
247
|
-
* Sets the authentication data (signature) for the client
|
248
|
-
* @param
|
247
|
+
* Sets the authentication data (signature) for the client
|
248
|
+
* @param nearAuthData The NEAR authentication data
|
249
249
|
*/
|
250
250
|
setAuthentication(nearAuthData: NearAuthData): void;
|
251
251
|
/**
|
@@ -256,25 +256,7 @@ declare class CrosspostClient {
|
|
256
256
|
}
|
257
257
|
|
258
258
|
/**
|
259
|
-
*
|
260
|
-
*
|
261
|
-
* @param data The error response data
|
262
|
-
* @param status The HTTP status code
|
263
|
-
* @returns An ApiError or PlatformError instance
|
264
|
-
*/
|
265
|
-
declare function handleErrorResponse(data: any, status: number): ApiError | PlatformError;
|
266
|
-
/**
|
267
|
-
* Creates a network error with appropriate details
|
268
|
-
*
|
269
|
-
* @param error The original error
|
270
|
-
* @param url The request URL
|
271
|
-
* @param timeout The request timeout
|
272
|
-
* @returns An ApiError instance
|
273
|
-
*/
|
274
|
-
declare function createNetworkError(error: unknown, url: string, timeout: number): ApiError;
|
275
|
-
|
276
|
-
/**
|
277
|
-
* Error categories grouped by type for better organization and usage
|
259
|
+
* Error categories grouped by type
|
278
260
|
*/
|
279
261
|
declare const ERROR_CATEGORIES: {
|
280
262
|
AUTH: ApiErrorCode[];
|
@@ -389,29 +371,22 @@ declare function enrichErrorWithContext(error: unknown, context: Record<string,
|
|
389
371
|
* @throws An enriched error if the API call fails
|
390
372
|
*/
|
391
373
|
declare function apiWrapper<T>(apiCall: () => Promise<T>, context?: Record<string, any>): Promise<T>;
|
392
|
-
|
393
|
-
declare const AUTH_COOKIE_NAME = "__crosspost_auth";
|
394
|
-
declare const CSRF_COOKIE_NAME = "XSRF-TOKEN";
|
395
|
-
declare const CSRF_HEADER_NAME = "X-CSRF-Token";
|
396
|
-
declare const AUTH_COOKIE_OPTIONS: Cookies.CookieAttributes;
|
397
|
-
/**
|
398
|
-
* Gets authentication data from the cookie
|
399
|
-
* @returns The NearAuthData object or undefined if not found
|
400
|
-
*/
|
401
|
-
declare function getAuthFromCookie(): NearAuthData | undefined;
|
402
|
-
/**
|
403
|
-
* Stores authentication data in a secure cookie
|
404
|
-
* @param authData The NearAuthData object to store
|
405
|
-
*/
|
406
|
-
declare function storeAuthInCookie(authData: NearAuthData): void;
|
407
374
|
/**
|
408
|
-
*
|
375
|
+
* Handles error responses from the API and converts them to appropriate error objects.
|
376
|
+
*
|
377
|
+
* @param data The error response data
|
378
|
+
* @param status The HTTP status code
|
379
|
+
* @returns An ApiError or PlatformError instance
|
409
380
|
*/
|
410
|
-
declare function
|
381
|
+
declare function handleErrorResponse(data: any, status: number): ApiError | PlatformError;
|
411
382
|
/**
|
412
|
-
*
|
413
|
-
*
|
383
|
+
* Creates a network error with appropriate details
|
384
|
+
*
|
385
|
+
* @param error The original error
|
386
|
+
* @param url The request URL
|
387
|
+
* @param timeout The request timeout
|
388
|
+
* @returns An ApiError instance
|
414
389
|
*/
|
415
|
-
declare function
|
390
|
+
declare function createNetworkError(error: unknown, url: string, timeout: number): ApiError;
|
416
391
|
|
417
|
-
export {
|
392
|
+
export { ActivityApi, AuthApi, CrosspostClient, type CrosspostClientConfig, ERROR_CATEGORIES, PostApi, SystemApi, apiWrapper, createNetworkError, enrichErrorWithContext, getErrorDetails, getErrorMessage, handleErrorResponse, isAuthError, isContentError, isErrorOfCategory, isMediaError, isNetworkError, isPlatformError, isPostError, isRateLimitError, isRecoverableError, isValidationError };
|
package/dist/index.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { NearAuthData } from 'near-sign-verify';
|
2
|
-
import { ActivityLeaderboardQuery, ActivityLeaderboardResponse, AccountActivityQuery, AccountActivityResponse, AccountPostsQuery, AccountPostsResponse, NearAuthorizationResponse, Platform, EnhancedApiResponse, AuthStatusResponse, AuthRevokeResponse, ConnectedAccountsResponse, CreatePostRequest, CreatePostResponse, RepostRequest, RepostResponse, QuotePostRequest, QuotePostResponse, ReplyToPostRequest, ReplyToPostResponse, LikePostRequest, LikePostResponse, UnlikePostRequest, UnlikePostResponse, DeletePostRequest, DeletePostResponse, RateLimitResponse, EndpointRateLimitResponse, ApiError,
|
2
|
+
import { ActivityLeaderboardQuery, ActivityLeaderboardResponse, AccountActivityQuery, AccountActivityResponse, AccountPostsQuery, AccountPostsResponse, NearAuthorizationResponse, Platform, EnhancedApiResponse, AuthStatusResponse, AuthRevokeResponse, ConnectedAccountsResponse, CreatePostRequest, CreatePostResponse, RepostRequest, RepostResponse, QuotePostRequest, QuotePostResponse, ReplyToPostRequest, ReplyToPostResponse, LikePostRequest, LikePostResponse, UnlikePostRequest, UnlikePostResponse, DeletePostRequest, DeletePostResponse, RateLimitResponse, EndpointRateLimitResponse, ApiError, ApiErrorCode, PlatformError } from '@crosspost/types';
|
3
3
|
export * from '@crosspost/types';
|
4
4
|
|
5
5
|
/**
|
@@ -244,8 +244,8 @@ declare class CrosspostClient {
|
|
244
244
|
*/
|
245
245
|
constructor(config?: CrosspostClientConfig);
|
246
246
|
/**
|
247
|
-
* Sets the authentication data (signature) for the client
|
248
|
-
* @param
|
247
|
+
* Sets the authentication data (signature) for the client
|
248
|
+
* @param nearAuthData The NEAR authentication data
|
249
249
|
*/
|
250
250
|
setAuthentication(nearAuthData: NearAuthData): void;
|
251
251
|
/**
|
@@ -256,25 +256,7 @@ declare class CrosspostClient {
|
|
256
256
|
}
|
257
257
|
|
258
258
|
/**
|
259
|
-
*
|
260
|
-
*
|
261
|
-
* @param data The error response data
|
262
|
-
* @param status The HTTP status code
|
263
|
-
* @returns An ApiError or PlatformError instance
|
264
|
-
*/
|
265
|
-
declare function handleErrorResponse(data: any, status: number): ApiError | PlatformError;
|
266
|
-
/**
|
267
|
-
* Creates a network error with appropriate details
|
268
|
-
*
|
269
|
-
* @param error The original error
|
270
|
-
* @param url The request URL
|
271
|
-
* @param timeout The request timeout
|
272
|
-
* @returns An ApiError instance
|
273
|
-
*/
|
274
|
-
declare function createNetworkError(error: unknown, url: string, timeout: number): ApiError;
|
275
|
-
|
276
|
-
/**
|
277
|
-
* Error categories grouped by type for better organization and usage
|
259
|
+
* Error categories grouped by type
|
278
260
|
*/
|
279
261
|
declare const ERROR_CATEGORIES: {
|
280
262
|
AUTH: ApiErrorCode[];
|
@@ -389,29 +371,22 @@ declare function enrichErrorWithContext(error: unknown, context: Record<string,
|
|
389
371
|
* @throws An enriched error if the API call fails
|
390
372
|
*/
|
391
373
|
declare function apiWrapper<T>(apiCall: () => Promise<T>, context?: Record<string, any>): Promise<T>;
|
392
|
-
|
393
|
-
declare const AUTH_COOKIE_NAME = "__crosspost_auth";
|
394
|
-
declare const CSRF_COOKIE_NAME = "XSRF-TOKEN";
|
395
|
-
declare const CSRF_HEADER_NAME = "X-CSRF-Token";
|
396
|
-
declare const AUTH_COOKIE_OPTIONS: Cookies.CookieAttributes;
|
397
|
-
/**
|
398
|
-
* Gets authentication data from the cookie
|
399
|
-
* @returns The NearAuthData object or undefined if not found
|
400
|
-
*/
|
401
|
-
declare function getAuthFromCookie(): NearAuthData | undefined;
|
402
|
-
/**
|
403
|
-
* Stores authentication data in a secure cookie
|
404
|
-
* @param authData The NearAuthData object to store
|
405
|
-
*/
|
406
|
-
declare function storeAuthInCookie(authData: NearAuthData): void;
|
407
374
|
/**
|
408
|
-
*
|
375
|
+
* Handles error responses from the API and converts them to appropriate error objects.
|
376
|
+
*
|
377
|
+
* @param data The error response data
|
378
|
+
* @param status The HTTP status code
|
379
|
+
* @returns An ApiError or PlatformError instance
|
409
380
|
*/
|
410
|
-
declare function
|
381
|
+
declare function handleErrorResponse(data: any, status: number): ApiError | PlatformError;
|
411
382
|
/**
|
412
|
-
*
|
413
|
-
*
|
383
|
+
* Creates a network error with appropriate details
|
384
|
+
*
|
385
|
+
* @param error The original error
|
386
|
+
* @param url The request URL
|
387
|
+
* @param timeout The request timeout
|
388
|
+
* @returns An ApiError instance
|
414
389
|
*/
|
415
|
-
declare function
|
390
|
+
declare function createNetworkError(error: unknown, url: string, timeout: number): ApiError;
|
416
391
|
|
417
|
-
export {
|
392
|
+
export { ActivityApi, AuthApi, CrosspostClient, type CrosspostClientConfig, ERROR_CATEGORIES, PostApi, SystemApi, apiWrapper, createNetworkError, enrichErrorWithContext, getErrorDetails, getErrorMessage, handleErrorResponse, isAuthError, isContentError, isErrorOfCategory, isMediaError, isNetworkError, isPlatformError, isPostError, isRateLimitError, isRecoverableError, isValidationError };
|
package/dist/index.js
CHANGED
@@ -4059,19 +4059,22 @@ var z = /* @__PURE__ */ Object.freeze({
|
|
4059
4059
|
});
|
4060
4060
|
|
4061
4061
|
// ../types/dist/index.js
|
4062
|
-
var
|
4063
|
-
"unknown"
|
4064
|
-
"twitter"
|
4065
|
-
|
4066
|
-
// 'linkedin',
|
4067
|
-
// 'facebook',
|
4068
|
-
// 'instagram',
|
4069
|
-
]).describe("Social media platform");
|
4070
|
-
var Platform = /* @__PURE__ */ ((Platform22) => {
|
4071
|
-
Platform22["UNKNOWN"] = "unknown";
|
4072
|
-
Platform22["TWITTER"] = "twitter";
|
4073
|
-
return Platform22;
|
4062
|
+
var Platform = /* @__PURE__ */ ((Platform2) => {
|
4063
|
+
Platform2["UNKNOWN"] = "unknown";
|
4064
|
+
Platform2["TWITTER"] = "twitter";
|
4065
|
+
return Platform2;
|
4074
4066
|
})(Platform || {});
|
4067
|
+
var PlatformSchema = z.nativeEnum(Platform).describe("Social media platform");
|
4068
|
+
var SUPPORTED_PLATFORMS = [
|
4069
|
+
"twitter"
|
4070
|
+
/* TWITTER */
|
4071
|
+
// Add more platforms here as they're implemented
|
4072
|
+
];
|
4073
|
+
var SupportedPlatformSchema = SUPPORTED_PLATFORMS.length > 0 ? z.enum(SUPPORTED_PLATFORMS) : z.never();
|
4074
|
+
SupportedPlatformSchema.describe("Currently supported social media platforms");
|
4075
|
+
function isPlatformSupported(platform) {
|
4076
|
+
return SUPPORTED_PLATFORMS.includes(platform);
|
4077
|
+
}
|
4075
4078
|
var ApiResponseSchema = z.object({
|
4076
4079
|
data: z.any().describe("Response data"),
|
4077
4080
|
meta: z.object({
|
@@ -4810,59 +4813,6 @@ var ProfileRefreshResponseSchema = EnhancedResponseSchema(
|
|
4810
4813
|
import { createAuthToken } from "near-sign-verify";
|
4811
4814
|
|
4812
4815
|
// src/utils/error.ts
|
4813
|
-
function handleErrorResponse(data, status) {
|
4814
|
-
const errorData = data?.error || {};
|
4815
|
-
const message = errorData?.message || data?.message || "An API error occurred";
|
4816
|
-
const codeString = errorData?.code || data?.code || ApiErrorCode.UNKNOWN_ERROR;
|
4817
|
-
const code = Object.values(ApiErrorCode).includes(codeString) ? codeString : ApiErrorCode.UNKNOWN_ERROR;
|
4818
|
-
const details = errorData?.details || data?.details || {};
|
4819
|
-
const recoverable = errorData?.recoverable ?? data?.recoverable ?? false;
|
4820
|
-
const platform = errorData?.platform || data?.platform;
|
4821
|
-
const enhancedDetails = { ...details };
|
4822
|
-
if (typeof enhancedDetails === "object" && !enhancedDetails.originalResponse) {
|
4823
|
-
enhancedDetails.originalResponse = data;
|
4824
|
-
}
|
4825
|
-
if (platform && Object.values(Platform).includes(platform)) {
|
4826
|
-
return new PlatformError(
|
4827
|
-
message,
|
4828
|
-
platform,
|
4829
|
-
code,
|
4830
|
-
// Use the parsed code
|
4831
|
-
status,
|
4832
|
-
// Cast status
|
4833
|
-
enhancedDetails,
|
4834
|
-
recoverable
|
4835
|
-
);
|
4836
|
-
} else {
|
4837
|
-
return new ApiError(
|
4838
|
-
message,
|
4839
|
-
code,
|
4840
|
-
// Use the parsed code
|
4841
|
-
status,
|
4842
|
-
// Cast status
|
4843
|
-
enhancedDetails,
|
4844
|
-
recoverable
|
4845
|
-
);
|
4846
|
-
}
|
4847
|
-
}
|
4848
|
-
function createNetworkError(error, url, timeout) {
|
4849
|
-
if (error instanceof DOMException && error.name === "AbortError") {
|
4850
|
-
return new ApiError(
|
4851
|
-
`Request timed out after ${timeout}ms`,
|
4852
|
-
ApiErrorCode.NETWORK_ERROR,
|
4853
|
-
408,
|
4854
|
-
{ url }
|
4855
|
-
);
|
4856
|
-
}
|
4857
|
-
return new ApiError(
|
4858
|
-
error instanceof Error ? error.message : "An unexpected error occurred during the request",
|
4859
|
-
ApiErrorCode.INTERNAL_ERROR,
|
4860
|
-
500,
|
4861
|
-
{ originalError: String(error), url }
|
4862
|
-
);
|
4863
|
-
}
|
4864
|
-
|
4865
|
-
// src/utils/error-utils.ts
|
4866
4816
|
var ERROR_CATEGORIES = {
|
4867
4817
|
AUTH: [
|
4868
4818
|
ApiErrorCode.UNAUTHORIZED,
|
@@ -4990,9 +4940,6 @@ function enrichErrorWithContext(error, context) {
|
|
4990
4940
|
false
|
4991
4941
|
);
|
4992
4942
|
}
|
4993
|
-
function handleErrorResponse2(data, status) {
|
4994
|
-
return handleErrorResponse(data, status);
|
4995
|
-
}
|
4996
4943
|
async function apiWrapper(apiCall, context) {
|
4997
4944
|
try {
|
4998
4945
|
return await apiCall();
|
@@ -5001,7 +4948,7 @@ async function apiWrapper(apiCall, context) {
|
|
5001
4948
|
try {
|
5002
4949
|
const errorData = await error.json();
|
5003
4950
|
throw enrichErrorWithContext(
|
5004
|
-
|
4951
|
+
handleErrorResponse(errorData, error.status),
|
5005
4952
|
context || {}
|
5006
4953
|
);
|
5007
4954
|
} catch (jsonError) {
|
@@ -5028,63 +4975,56 @@ async function apiWrapper(apiCall, context) {
|
|
5028
4975
|
);
|
5029
4976
|
}
|
5030
4977
|
}
|
5031
|
-
|
5032
|
-
|
5033
|
-
|
5034
|
-
|
5035
|
-
|
5036
|
-
|
5037
|
-
|
5038
|
-
|
5039
|
-
};
|
5040
|
-
|
5041
|
-
|
5042
|
-
};
|
5043
|
-
var AUTH_COOKIE_OPTIONS = {
|
5044
|
-
secure: true,
|
5045
|
-
sameSite: "lax",
|
5046
|
-
// Restrict to same-site and top-level navigation
|
5047
|
-
path: "/",
|
5048
|
-
expires: 30
|
5049
|
-
// 30 days
|
5050
|
-
};
|
5051
|
-
function getAuthFromCookie() {
|
5052
|
-
try {
|
5053
|
-
if (!isBrowser()) {
|
5054
|
-
return void 0;
|
5055
|
-
}
|
5056
|
-
const cookieValue = Cookies.get(AUTH_COOKIE_NAME);
|
5057
|
-
if (!cookieValue) {
|
5058
|
-
return void 0;
|
5059
|
-
}
|
5060
|
-
return JSON.parse(cookieValue);
|
5061
|
-
} catch (error) {
|
5062
|
-
console.error("Failed to parse auth cookie:", error);
|
5063
|
-
return void 0;
|
5064
|
-
}
|
5065
|
-
}
|
5066
|
-
function storeAuthInCookie(authData) {
|
5067
|
-
try {
|
5068
|
-
if (!isBrowser()) {
|
5069
|
-
return;
|
5070
|
-
}
|
5071
|
-
const cookieValue = JSON.stringify(authData);
|
5072
|
-
Cookies.set(AUTH_COOKIE_NAME, cookieValue, AUTH_COOKIE_OPTIONS);
|
5073
|
-
} catch (error) {
|
5074
|
-
console.error("Failed to store auth cookie:", error);
|
4978
|
+
function handleErrorResponse(data, status) {
|
4979
|
+
const errorData = data?.error || {};
|
4980
|
+
const message = errorData?.message || data?.message || "An API error occurred";
|
4981
|
+
const codeString = errorData?.code || data?.code || ApiErrorCode.UNKNOWN_ERROR;
|
4982
|
+
const code = Object.values(ApiErrorCode).includes(codeString) ? codeString : ApiErrorCode.UNKNOWN_ERROR;
|
4983
|
+
const details = errorData?.details || data?.details || {};
|
4984
|
+
const recoverable = errorData?.recoverable ?? data?.recoverable ?? false;
|
4985
|
+
const platform = errorData?.platform || data?.platform;
|
4986
|
+
const enhancedDetails = { ...details };
|
4987
|
+
if (typeof enhancedDetails === "object" && !enhancedDetails.originalResponse) {
|
4988
|
+
enhancedDetails.originalResponse = data;
|
5075
4989
|
}
|
5076
|
-
|
5077
|
-
|
5078
|
-
|
5079
|
-
|
4990
|
+
if (platform && Object.values(Platform).includes(platform)) {
|
4991
|
+
return new PlatformError(
|
4992
|
+
message,
|
4993
|
+
platform,
|
4994
|
+
code,
|
4995
|
+
// Use the parsed code
|
4996
|
+
status,
|
4997
|
+
// Cast status
|
4998
|
+
enhancedDetails,
|
4999
|
+
recoverable
|
5000
|
+
);
|
5001
|
+
} else {
|
5002
|
+
return new ApiError(
|
5003
|
+
message,
|
5004
|
+
code,
|
5005
|
+
// Use the parsed code
|
5006
|
+
status,
|
5007
|
+
// Cast status
|
5008
|
+
enhancedDetails,
|
5009
|
+
recoverable
|
5010
|
+
);
|
5080
5011
|
}
|
5081
|
-
Cookies.remove(AUTH_COOKIE_NAME, { path: AUTH_COOKIE_OPTIONS.path });
|
5082
5012
|
}
|
5083
|
-
function
|
5084
|
-
if (
|
5085
|
-
return
|
5013
|
+
function createNetworkError(error, url, timeout) {
|
5014
|
+
if (error instanceof DOMException && error.name === "AbortError") {
|
5015
|
+
return new ApiError(
|
5016
|
+
`Request timed out after ${timeout}ms`,
|
5017
|
+
ApiErrorCode.NETWORK_ERROR,
|
5018
|
+
408,
|
5019
|
+
{ url }
|
5020
|
+
);
|
5086
5021
|
}
|
5087
|
-
return
|
5022
|
+
return new ApiError(
|
5023
|
+
error instanceof Error ? error.message : "An unexpected error occurred during the request",
|
5024
|
+
ApiErrorCode.INTERNAL_ERROR,
|
5025
|
+
500,
|
5026
|
+
{ originalError: String(error), url }
|
5027
|
+
);
|
5088
5028
|
}
|
5089
5029
|
|
5090
5030
|
// src/core/request.ts
|
@@ -5122,12 +5062,6 @@ async function makeRequest(method, path, options, data, query) {
|
|
5122
5062
|
"Accept": "application/json",
|
5123
5063
|
"Authorization": `Bearer ${createAuthToken(options.nearAuthData)}`
|
5124
5064
|
};
|
5125
|
-
if (method !== "GET") {
|
5126
|
-
const csrfToken = getCsrfToken();
|
5127
|
-
if (csrfToken) {
|
5128
|
-
headers[CSRF_HEADER_NAME] = csrfToken;
|
5129
|
-
}
|
5130
|
-
}
|
5131
5065
|
const requestOptions = {
|
5132
5066
|
method,
|
5133
5067
|
headers,
|
@@ -5527,7 +5461,7 @@ var CrosspostClient = class {
|
|
5527
5461
|
const baseUrl = config.baseUrl || DEFAULT_CONFIG.baseUrl;
|
5528
5462
|
const timeout = config.timeout || DEFAULT_CONFIG.timeout;
|
5529
5463
|
const retries = config.retries ?? DEFAULT_CONFIG.retries;
|
5530
|
-
const nearAuthData = config.nearAuthData
|
5464
|
+
const nearAuthData = config.nearAuthData;
|
5531
5465
|
this.options = {
|
5532
5466
|
baseUrl,
|
5533
5467
|
timeout,
|
@@ -5540,12 +5474,11 @@ var CrosspostClient = class {
|
|
5540
5474
|
this.system = new SystemApi(this.options);
|
5541
5475
|
}
|
5542
5476
|
/**
|
5543
|
-
* Sets the authentication data (signature) for the client
|
5544
|
-
* @param
|
5477
|
+
* Sets the authentication data (signature) for the client
|
5478
|
+
* @param nearAuthData The NEAR authentication data
|
5545
5479
|
*/
|
5546
5480
|
setAuthentication(nearAuthData) {
|
5547
5481
|
this.options.nearAuthData = nearAuthData;
|
5548
|
-
storeAuthInCookie(nearAuthData);
|
5549
5482
|
}
|
5550
5483
|
/**
|
5551
5484
|
* Checks if authentication data (signature) exists on client
|
@@ -5556,8 +5489,6 @@ var CrosspostClient = class {
|
|
5556
5489
|
}
|
5557
5490
|
};
|
5558
5491
|
export {
|
5559
|
-
AUTH_COOKIE_NAME,
|
5560
|
-
AUTH_COOKIE_OPTIONS,
|
5561
5492
|
AccountActivityEntrySchema,
|
5562
5493
|
AccountActivityParamsSchema,
|
5563
5494
|
AccountActivityQuerySchema,
|
@@ -5581,8 +5512,6 @@ export {
|
|
5581
5512
|
AuthStatusResponseSchema,
|
5582
5513
|
AuthUrlResponseSchema,
|
5583
5514
|
BaseError,
|
5584
|
-
CSRF_COOKIE_NAME,
|
5585
|
-
CSRF_HEADER_NAME,
|
5586
5515
|
ConnectedAccountSchema,
|
5587
5516
|
ConnectedAccountsResponseSchema,
|
5588
5517
|
CreatePostRequestSchema,
|
@@ -5638,7 +5567,9 @@ export {
|
|
5638
5567
|
ReplyToPostResponseSchema,
|
5639
5568
|
RepostRequestSchema,
|
5640
5569
|
RepostResponseSchema,
|
5570
|
+
SUPPORTED_PLATFORMS,
|
5641
5571
|
SuccessDetailSchema,
|
5572
|
+
SupportedPlatformSchema,
|
5642
5573
|
SystemApi,
|
5643
5574
|
TargetSchema,
|
5644
5575
|
TimePeriod,
|
@@ -5647,7 +5578,6 @@ export {
|
|
5647
5578
|
UsageRateLimitSchema,
|
5648
5579
|
UserProfileSchema,
|
5649
5580
|
apiWrapper,
|
5650
|
-
clearAuthCookie,
|
5651
5581
|
createApiResponse,
|
5652
5582
|
createEnhancedApiResponse,
|
5653
5583
|
createEnhancedErrorResponse,
|
@@ -5657,8 +5587,6 @@ export {
|
|
5657
5587
|
createNetworkError,
|
5658
5588
|
createSuccessDetail,
|
5659
5589
|
enrichErrorWithContext,
|
5660
|
-
getAuthFromCookie,
|
5661
|
-
getCsrfToken,
|
5662
5590
|
getErrorDetails,
|
5663
5591
|
getErrorMessage,
|
5664
5592
|
handleErrorResponse,
|
@@ -5668,9 +5596,9 @@ export {
|
|
5668
5596
|
isMediaError,
|
5669
5597
|
isNetworkError,
|
5670
5598
|
isPlatformError,
|
5599
|
+
isPlatformSupported,
|
5671
5600
|
isPostError,
|
5672
5601
|
isRateLimitError,
|
5673
5602
|
isRecoverableError,
|
5674
|
-
isValidationError
|
5675
|
-
storeAuthInCookie
|
5603
|
+
isValidationError
|
5676
5604
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@crosspost/sdk",
|
3
|
-
"version": "0.1.
|
3
|
+
"version": "0.1.4",
|
4
4
|
"description": "SDK for interacting with the Crosspost API",
|
5
5
|
"type": "module",
|
6
6
|
"main": "dist/index.cjs",
|
@@ -36,8 +36,6 @@
|
|
36
36
|
"author": "crosspost.near",
|
37
37
|
"license": "MIT",
|
38
38
|
"dependencies": {
|
39
|
-
"@types/js-cookie": "^3.0.6",
|
40
|
-
"js-cookie": "^3.0.5",
|
41
39
|
"near-sign-verify": "^0.1.1"
|
42
40
|
},
|
43
41
|
"devDependencies": {
|
package/src/core/client.ts
CHANGED
@@ -5,7 +5,6 @@ import { PostApi } from '../api/post.ts';
|
|
5
5
|
import { SystemApi } from '../api/system.ts';
|
6
6
|
import { type CrosspostClientConfig, DEFAULT_CONFIG } from './config.ts';
|
7
7
|
import type { RequestOptions } from './request.ts';
|
8
|
-
import { getAuthFromCookie, storeAuthInCookie } from '../utils/cookie.ts';
|
9
8
|
|
10
9
|
/**
|
11
10
|
* Main client for interacting with the Crosspost API service.
|
@@ -27,7 +26,7 @@ export class CrosspostClient {
|
|
27
26
|
const timeout = config.timeout || DEFAULT_CONFIG.timeout;
|
28
27
|
const retries = config.retries ?? DEFAULT_CONFIG.retries;
|
29
28
|
|
30
|
-
const nearAuthData = config.nearAuthData
|
29
|
+
const nearAuthData = config.nearAuthData;
|
31
30
|
|
32
31
|
this.options = {
|
33
32
|
baseUrl,
|
@@ -43,12 +42,11 @@ export class CrosspostClient {
|
|
43
42
|
}
|
44
43
|
|
45
44
|
/**
|
46
|
-
* Sets the authentication data (signature) for the client
|
47
|
-
* @param
|
45
|
+
* Sets the authentication data (signature) for the client
|
46
|
+
* @param nearAuthData The NEAR authentication data
|
48
47
|
*/
|
49
48
|
public setAuthentication(nearAuthData: NearAuthData): void {
|
50
49
|
this.options.nearAuthData = nearAuthData;
|
51
|
-
storeAuthInCookie(nearAuthData);
|
52
50
|
}
|
53
51
|
|
54
52
|
/**
|
package/src/core/request.ts
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
import { ApiError, ApiErrorCode } from '@crosspost/types';
|
2
2
|
import { createAuthToken, type NearAuthData } from 'near-sign-verify';
|
3
|
-
import { createNetworkError, handleErrorResponse } from '../utils/error.ts';
|
4
|
-
import { apiWrapper, enrichErrorWithContext } from '../utils/error-utils.ts';
|
5
|
-
import { CSRF_HEADER_NAME, getCsrfToken } from '../utils/cookie.ts';
|
3
|
+
import { apiWrapper, createNetworkError, handleErrorResponse } from '../utils/error.ts';
|
6
4
|
|
7
5
|
/**
|
8
6
|
* Options for making a request to the API
|
@@ -85,14 +83,6 @@ export async function makeRequest<T>(
|
|
85
83
|
'Authorization': `Bearer ${createAuthToken(options.nearAuthData!)}`,
|
86
84
|
};
|
87
85
|
|
88
|
-
// Add CSRF token for state-changing requests (non-GET)
|
89
|
-
if (method !== 'GET') {
|
90
|
-
const csrfToken = getCsrfToken();
|
91
|
-
if (csrfToken) {
|
92
|
-
headers[CSRF_HEADER_NAME] = csrfToken;
|
93
|
-
}
|
94
|
-
}
|
95
|
-
|
96
86
|
const requestOptions: RequestInit = {
|
97
87
|
method,
|
98
88
|
headers,
|
package/src/index.ts
CHANGED
@@ -14,13 +14,14 @@ export { PostApi } from './api/post.ts';
|
|
14
14
|
export { SystemApi } from './api/system.ts';
|
15
15
|
|
16
16
|
// Export utility functions
|
17
|
-
export { createNetworkError, handleErrorResponse } from './utils/error.ts';
|
18
17
|
export {
|
19
18
|
apiWrapper,
|
19
|
+
createNetworkError,
|
20
20
|
enrichErrorWithContext,
|
21
21
|
ERROR_CATEGORIES,
|
22
22
|
getErrorDetails,
|
23
23
|
getErrorMessage,
|
24
|
+
handleErrorResponse,
|
24
25
|
isAuthError,
|
25
26
|
isContentError,
|
26
27
|
isErrorOfCategory,
|
@@ -31,17 +32,7 @@ export {
|
|
31
32
|
isRateLimitError,
|
32
33
|
isRecoverableError,
|
33
34
|
isValidationError,
|
34
|
-
} from './utils/error
|
35
|
-
export {
|
36
|
-
AUTH_COOKIE_NAME,
|
37
|
-
AUTH_COOKIE_OPTIONS,
|
38
|
-
clearAuthCookie,
|
39
|
-
CSRF_COOKIE_NAME,
|
40
|
-
CSRF_HEADER_NAME,
|
41
|
-
getAuthFromCookie,
|
42
|
-
getCsrfToken,
|
43
|
-
storeAuthInCookie,
|
44
|
-
} from './utils/cookie.ts';
|
35
|
+
} from './utils/error.ts';
|
45
36
|
|
46
37
|
// Re-export types from @crosspost/types for convenience
|
47
38
|
export * from '@crosspost/types';
|