@crosspost/sdk 0.1.5 → 0.1.7
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 +380 -624
- package/dist/index.d.cts +29 -84
- package/dist/index.d.ts +29 -84
- package/dist/index.js +375 -599
- package/package.json +1 -1
- package/src/api/auth.ts +7 -7
- package/src/api/post.ts +3 -15
- package/src/api/system.ts +3 -3
- package/src/core/request.ts +33 -32
- package/src/index.ts +0 -10
- package/src/utils/error.ts +158 -199
package/dist/index.cjs
CHANGED
@@ -23,56 +23,43 @@ __export(index_exports, {
|
|
23
23
|
AccountActivityEntrySchema: () => AccountActivityEntrySchema,
|
24
24
|
AccountActivityParamsSchema: () => AccountActivityParamsSchema,
|
25
25
|
AccountActivityQuerySchema: () => AccountActivityQuerySchema,
|
26
|
-
AccountActivityResponseSchema: () => AccountActivityResponseSchema,
|
27
26
|
AccountPostSchema: () => AccountPostSchema,
|
28
27
|
AccountPostsParamsSchema: () => AccountPostsParamsSchema,
|
29
28
|
AccountPostsQuerySchema: () => AccountPostsQuerySchema,
|
30
|
-
AccountPostsResponseSchema: () => AccountPostsResponseSchema,
|
31
29
|
ActivityApi: () => ActivityApi,
|
32
30
|
ActivityLeaderboardQuerySchema: () => ActivityLeaderboardQuerySchema,
|
33
|
-
ActivityLeaderboardResponseSchema: () => ActivityLeaderboardResponseSchema,
|
34
31
|
AllRateLimitsResponseSchema: () => AllRateLimitsResponseSchema,
|
35
|
-
ApiError: () => ApiError,
|
36
32
|
ApiErrorCode: () => ApiErrorCode,
|
37
|
-
|
33
|
+
ApiErrorCodeSchema: () => ApiErrorCodeSchema,
|
38
34
|
AuthApi: () => AuthApi,
|
39
35
|
AuthCallbackQuerySchema: () => AuthCallbackQuerySchema,
|
40
36
|
AuthCallbackResponseSchema: () => AuthCallbackResponseSchema,
|
41
37
|
AuthInitRequestSchema: () => AuthInitRequestSchema,
|
42
38
|
AuthRevokeResponseSchema: () => AuthRevokeResponseSchema,
|
43
39
|
AuthStatusResponseSchema: () => AuthStatusResponseSchema,
|
40
|
+
AuthTokenRequestSchema: () => AuthTokenRequestSchema,
|
44
41
|
AuthUrlResponseSchema: () => AuthUrlResponseSchema,
|
45
|
-
BaseError: () => BaseError,
|
46
42
|
ConnectedAccountSchema: () => ConnectedAccountSchema,
|
47
43
|
ConnectedAccountsResponseSchema: () => ConnectedAccountsResponseSchema,
|
48
44
|
CreatePostRequestSchema: () => CreatePostRequestSchema,
|
49
|
-
CreatePostResponseLegacySchema: () => CreatePostResponseLegacySchema,
|
50
45
|
CreatePostResponseSchema: () => CreatePostResponseSchema,
|
51
|
-
CreatePostTargetErrorSchema: () => CreatePostTargetErrorSchema,
|
52
|
-
CreatePostTargetResultSchema: () => CreatePostTargetResultSchema,
|
53
46
|
CrosspostClient: () => CrosspostClient,
|
54
47
|
DeletePostRequestSchema: () => DeletePostRequestSchema,
|
55
48
|
DeletePostResponseSchema: () => DeletePostResponseSchema,
|
56
49
|
DeleteResultSchema: () => DeleteResultSchema,
|
57
|
-
ERROR_CATEGORIES: () => ERROR_CATEGORIES,
|
58
50
|
EndpointRateLimitResponseSchema: () => EndpointRateLimitResponseSchema,
|
59
|
-
EnhancedErrorResponseSchema: () => EnhancedErrorResponseSchema,
|
60
|
-
EnhancedResponseMetaSchema: () => EnhancedResponseMetaSchema,
|
61
|
-
EnhancedResponseSchema: () => EnhancedResponseSchema,
|
62
51
|
ErrorDetailSchema: () => ErrorDetailSchema,
|
63
|
-
ErrorResponseSchema: () => ErrorResponseSchema,
|
64
52
|
LikePostRequestSchema: () => LikePostRequestSchema,
|
65
53
|
LikePostResponseSchema: () => LikePostResponseSchema,
|
66
54
|
LikeResultSchema: () => LikeResultSchema,
|
67
55
|
MediaContentSchema: () => MediaContentSchema,
|
68
56
|
MediaSchema: () => MediaSchema,
|
69
|
-
|
57
|
+
MultiStatusDataSchema: () => MultiStatusDataSchema,
|
70
58
|
NearAuthorizationRequestSchema: () => NearAuthorizationRequestSchema,
|
71
59
|
NearAuthorizationResponseSchema: () => NearAuthorizationResponseSchema,
|
72
60
|
NearAuthorizationStatusResponseSchema: () => NearAuthorizationStatusResponseSchema,
|
73
61
|
Platform: () => Platform,
|
74
62
|
PlatformActivitySchema: () => PlatformActivitySchema,
|
75
|
-
PlatformError: () => PlatformError,
|
76
63
|
PlatformParamSchema: () => PlatformParamSchema,
|
77
64
|
PlatformRateLimitSchema: () => PlatformRateLimitSchema,
|
78
65
|
PlatformSchema: () => PlatformSchema,
|
@@ -86,7 +73,6 @@ __export(index_exports, {
|
|
86
73
|
PostSuccessDetailSchema: () => PostSuccessDetailSchema,
|
87
74
|
PostToDeleteSchema: () => PostToDeleteSchema,
|
88
75
|
ProfileRefreshResponseSchema: () => ProfileRefreshResponseSchema,
|
89
|
-
ProfileRefreshResultSchema: () => ProfileRefreshResultSchema,
|
90
76
|
QuotePostRequestSchema: () => QuotePostRequestSchema,
|
91
77
|
QuotePostResponseSchema: () => QuotePostResponseSchema,
|
92
78
|
RateLimitEndpointParamSchema: () => RateLimitEndpointParamSchema,
|
@@ -98,6 +84,7 @@ __export(index_exports, {
|
|
98
84
|
ReplyToPostResponseSchema: () => ReplyToPostResponseSchema,
|
99
85
|
RepostRequestSchema: () => RepostRequestSchema,
|
100
86
|
RepostResponseSchema: () => RepostResponseSchema,
|
87
|
+
ResponseMetaSchema: () => ResponseMetaSchema,
|
101
88
|
SUPPORTED_PLATFORMS: () => SUPPORTED_PLATFORMS,
|
102
89
|
SuccessDetailSchema: () => SuccessDetailSchema,
|
103
90
|
SupportedPlatformSchema: () => SupportedPlatformSchema,
|
@@ -109,21 +96,14 @@ __export(index_exports, {
|
|
109
96
|
UsageRateLimitSchema: () => UsageRateLimitSchema,
|
110
97
|
UserProfileSchema: () => UserProfileSchema,
|
111
98
|
apiWrapper: () => apiWrapper,
|
112
|
-
createApiResponse: () => createApiResponse,
|
113
|
-
createEnhancedApiResponse: () => createEnhancedApiResponse,
|
114
|
-
createEnhancedErrorResponse: () => createEnhancedErrorResponse,
|
115
|
-
createErrorDetail: () => createErrorDetail,
|
116
|
-
createErrorResponse: () => createErrorResponse,
|
117
|
-
createMultiStatusResponse: () => createMultiStatusResponse,
|
118
99
|
createNetworkError: () => createNetworkError,
|
119
|
-
createSuccessDetail: () => createSuccessDetail,
|
120
100
|
enrichErrorWithContext: () => enrichErrorWithContext,
|
101
|
+
errorCodeToStatusCode: () => errorCodeToStatusCode,
|
121
102
|
getErrorDetails: () => getErrorDetails,
|
122
103
|
getErrorMessage: () => getErrorMessage,
|
123
104
|
handleErrorResponse: () => handleErrorResponse,
|
124
105
|
isAuthError: () => isAuthError,
|
125
106
|
isContentError: () => isContentError,
|
126
|
-
isErrorOfCategory: () => isErrorOfCategory,
|
127
107
|
isMediaError: () => isMediaError,
|
128
108
|
isNetworkError: () => isNetworkError,
|
129
109
|
isPlatformError: () => isPlatformError,
|
@@ -4212,162 +4192,6 @@ SupportedPlatformSchema.describe("Currently supported social media platforms");
|
|
4212
4192
|
function isPlatformSupported(platform) {
|
4213
4193
|
return SUPPORTED_PLATFORMS.includes(platform);
|
4214
4194
|
}
|
4215
|
-
var ApiResponseSchema = z.object({
|
4216
|
-
data: z.any().describe("Response data"),
|
4217
|
-
meta: z.object({
|
4218
|
-
rateLimit: z.object({
|
4219
|
-
remaining: z.number().describe("Number of requests remaining in the current window"),
|
4220
|
-
limit: z.number().describe("Total number of requests allowed in the window"),
|
4221
|
-
reset: z.number().describe("Timestamp when the rate limit resets (in seconds since epoch)")
|
4222
|
-
}).optional().describe("Rate limit information"),
|
4223
|
-
pagination: z.object({
|
4224
|
-
page: z.number().describe("Current page number"),
|
4225
|
-
perPage: z.number().describe("Number of items per page"),
|
4226
|
-
total: z.number().describe("Total number of items"),
|
4227
|
-
totalPages: z.number().describe("Total number of pages"),
|
4228
|
-
nextCursor: z.string().optional().describe("Next page cursor (if applicable)"),
|
4229
|
-
prevCursor: z.string().optional().describe("Previous page cursor (if applicable)")
|
4230
|
-
}).optional().describe("Pagination information")
|
4231
|
-
}).optional().describe("Response metadata")
|
4232
|
-
}).describe("Standard API response");
|
4233
|
-
var ErrorResponseSchema = z.object({
|
4234
|
-
error: z.object({
|
4235
|
-
type: z.string().describe("Error type"),
|
4236
|
-
message: z.string().describe("Error message"),
|
4237
|
-
code: z.string().optional().describe("Error code (if applicable)"),
|
4238
|
-
details: z.any().optional().describe("Additional error details")
|
4239
|
-
}).describe("Error information")
|
4240
|
-
}).describe("Error response");
|
4241
|
-
var EnhancedResponseMetaSchema = z.object({
|
4242
|
-
requestId: z.string().optional().describe("Unique request identifier"),
|
4243
|
-
timestamp: z.string().optional().describe("Request timestamp"),
|
4244
|
-
rateLimit: z.object({
|
4245
|
-
remaining: z.number().describe("Number of requests remaining in the current window"),
|
4246
|
-
limit: z.number().describe("Total number of requests allowed in the window"),
|
4247
|
-
reset: z.number().describe("Timestamp when the rate limit resets (in seconds since epoch)")
|
4248
|
-
}).optional().describe("Rate limit information"),
|
4249
|
-
pagination: z.object({
|
4250
|
-
page: z.number().describe("Current page number"),
|
4251
|
-
perPage: z.number().describe("Number of items per page"),
|
4252
|
-
total: z.number().describe("Total number of items"),
|
4253
|
-
totalPages: z.number().describe("Total number of pages"),
|
4254
|
-
nextCursor: z.string().optional().describe("Next page cursor (if applicable)"),
|
4255
|
-
prevCursor: z.string().optional().describe("Previous page cursor (if applicable)")
|
4256
|
-
}).optional().describe("Pagination information")
|
4257
|
-
}).optional().describe("Response metadata");
|
4258
|
-
var ErrorDetailSchema = z.object({
|
4259
|
-
platform: z.string().optional().describe("Platform associated with the error (if applicable)"),
|
4260
|
-
userId: z.string().optional().describe("User ID associated with the error (if applicable)"),
|
4261
|
-
status: z.literal("error").describe("Error status"),
|
4262
|
-
error: z.string().describe("Human-readable error message"),
|
4263
|
-
errorCode: z.string().describe("Machine-readable error code"),
|
4264
|
-
recoverable: z.boolean().describe("Whether the error is recoverable (can be retried)"),
|
4265
|
-
details: z.record(z.any()).optional().describe("Additional error details (platform-specific)")
|
4266
|
-
}).describe("Error detail");
|
4267
|
-
var EnhancedErrorResponseSchema = z.object({
|
4268
|
-
success: z.literal(false).describe("Success indicator (always false for error responses)"),
|
4269
|
-
errors: z.array(ErrorDetailSchema).describe("Error information")
|
4270
|
-
}).describe("Enhanced error response");
|
4271
|
-
var SuccessDetailSchema = z.object({
|
4272
|
-
platform: z.string().describe("Platform associated with the success"),
|
4273
|
-
userId: z.string().describe("User ID associated with the success"),
|
4274
|
-
status: z.literal("success").describe("Success status"),
|
4275
|
-
postId: z.string().optional().describe("Post ID (if applicable)"),
|
4276
|
-
postUrl: z.string().optional().describe("Post URL (if applicable)")
|
4277
|
-
}).catchall(z.any()).describe("Success detail");
|
4278
|
-
var MultiStatusResponseSchema = z.object({
|
4279
|
-
success: z.boolean().describe("Success indicator (true if at least one operation succeeded)"),
|
4280
|
-
data: z.object({
|
4281
|
-
summary: z.object({
|
4282
|
-
total: z.number().describe("Total number of operations"),
|
4283
|
-
succeeded: z.number().describe("Number of successful operations"),
|
4284
|
-
failed: z.number().describe("Number of failed operations")
|
4285
|
-
}).describe("Summary of operations"),
|
4286
|
-
results: z.array(SuccessDetailSchema).describe("Successful results"),
|
4287
|
-
errors: z.array(ErrorDetailSchema).describe("Failed results")
|
4288
|
-
}).describe("Response data")
|
4289
|
-
}).describe("Multi-status response");
|
4290
|
-
function EnhancedResponseSchema(schema) {
|
4291
|
-
return z.object({
|
4292
|
-
success: z.boolean().describe("Whether the request was successful"),
|
4293
|
-
data: schema,
|
4294
|
-
meta: EnhancedResponseMetaSchema
|
4295
|
-
});
|
4296
|
-
}
|
4297
|
-
function createEnhancedApiResponse(data, meta) {
|
4298
|
-
return {
|
4299
|
-
success: true,
|
4300
|
-
data,
|
4301
|
-
meta
|
4302
|
-
};
|
4303
|
-
}
|
4304
|
-
function createApiResponse(data, meta) {
|
4305
|
-
return {
|
4306
|
-
data,
|
4307
|
-
meta
|
4308
|
-
};
|
4309
|
-
}
|
4310
|
-
function createErrorResponse(type, message, code, details) {
|
4311
|
-
return {
|
4312
|
-
error: {
|
4313
|
-
type,
|
4314
|
-
message,
|
4315
|
-
...code ? { code } : {},
|
4316
|
-
...details ? { details } : {}
|
4317
|
-
}
|
4318
|
-
};
|
4319
|
-
}
|
4320
|
-
function createEnhancedErrorResponse(errors) {
|
4321
|
-
return {
|
4322
|
-
success: false,
|
4323
|
-
errors
|
4324
|
-
};
|
4325
|
-
}
|
4326
|
-
function createErrorDetail(error, errorCode, recoverable, platform, userId, details) {
|
4327
|
-
return {
|
4328
|
-
platform,
|
4329
|
-
userId,
|
4330
|
-
status: "error",
|
4331
|
-
error,
|
4332
|
-
errorCode,
|
4333
|
-
recoverable,
|
4334
|
-
details
|
4335
|
-
};
|
4336
|
-
}
|
4337
|
-
function createSuccessDetail(platform, userId, additionalData) {
|
4338
|
-
return {
|
4339
|
-
platform,
|
4340
|
-
userId,
|
4341
|
-
status: "success",
|
4342
|
-
...additionalData
|
4343
|
-
};
|
4344
|
-
}
|
4345
|
-
function createMultiStatusResponse(results, errors) {
|
4346
|
-
const total = results.length + errors.length;
|
4347
|
-
const succeeded = results.length;
|
4348
|
-
const failed = errors.length;
|
4349
|
-
return {
|
4350
|
-
success: succeeded > 0,
|
4351
|
-
data: {
|
4352
|
-
summary: {
|
4353
|
-
total,
|
4354
|
-
succeeded,
|
4355
|
-
failed
|
4356
|
-
},
|
4357
|
-
results,
|
4358
|
-
errors
|
4359
|
-
}
|
4360
|
-
};
|
4361
|
-
}
|
4362
|
-
var BaseError = class extends Error {
|
4363
|
-
constructor(message) {
|
4364
|
-
super(message);
|
4365
|
-
this.name = this.constructor.name;
|
4366
|
-
if (Error.captureStackTrace) {
|
4367
|
-
Error.captureStackTrace(this, this.constructor);
|
4368
|
-
}
|
4369
|
-
}
|
4370
|
-
};
|
4371
4195
|
var ApiErrorCode = /* @__PURE__ */ ((ApiErrorCode2) => {
|
4372
4196
|
ApiErrorCode2["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
|
4373
4197
|
ApiErrorCode2["INTERNAL_ERROR"] = "INTERNAL_ERROR";
|
@@ -4382,6 +4206,7 @@ var ApiErrorCode = /* @__PURE__ */ ((ApiErrorCode2) => {
|
|
4382
4206
|
ApiErrorCode2["CONTENT_POLICY_VIOLATION"] = "CONTENT_POLICY_VIOLATION";
|
4383
4207
|
ApiErrorCode2["DUPLICATE_CONTENT"] = "DUPLICATE_CONTENT";
|
4384
4208
|
ApiErrorCode2["MEDIA_UPLOAD_FAILED"] = "MEDIA_UPLOAD_FAILED";
|
4209
|
+
ApiErrorCode2["MULTI_STATUS"] = "MULTI_STATUS";
|
4385
4210
|
ApiErrorCode2["POST_CREATION_FAILED"] = "POST_CREATION_FAILED";
|
4386
4211
|
ApiErrorCode2["THREAD_CREATION_FAILED"] = "THREAD_CREATION_FAILED";
|
4387
4212
|
ApiErrorCode2["POST_DELETION_FAILED"] = "POST_DELETION_FAILED";
|
@@ -4389,100 +4214,125 @@ var ApiErrorCode = /* @__PURE__ */ ((ApiErrorCode2) => {
|
|
4389
4214
|
ApiErrorCode2["NETWORK_ERROR"] = "NETWORK_ERROR";
|
4390
4215
|
return ApiErrorCode2;
|
4391
4216
|
})(ApiErrorCode || {});
|
4392
|
-
var
|
4393
|
-
|
4394
|
-
|
4395
|
-
|
4396
|
-
|
4397
|
-
|
4398
|
-
|
4399
|
-
|
4400
|
-
|
4401
|
-
|
4402
|
-
|
4403
|
-
|
4404
|
-
|
4405
|
-
|
4406
|
-
|
4407
|
-
|
4408
|
-
|
4409
|
-
|
4410
|
-
|
4411
|
-
|
4412
|
-
|
4413
|
-
|
4414
|
-
|
4415
|
-
|
4416
|
-
|
4417
|
-
|
4418
|
-
|
4419
|
-
|
4420
|
-
|
4421
|
-
|
4422
|
-
|
4423
|
-
|
4424
|
-
|
4425
|
-
|
4426
|
-
|
4427
|
-
|
4428
|
-
|
4429
|
-
|
4430
|
-
|
4431
|
-
|
4432
|
-
|
4433
|
-
|
4434
|
-
|
4435
|
-
|
4436
|
-
|
4437
|
-
|
4438
|
-
|
4439
|
-
|
4440
|
-
|
4441
|
-
|
4442
|
-
|
4443
|
-
|
4444
|
-
|
4445
|
-
|
4446
|
-
|
4447
|
-
|
4448
|
-
|
4449
|
-
|
4450
|
-
|
4451
|
-
|
4452
|
-
|
4453
|
-
|
4454
|
-
|
4455
|
-
|
4456
|
-
|
4457
|
-
|
4458
|
-
|
4459
|
-
|
4460
|
-
|
4461
|
-
|
4462
|
-
|
4463
|
-
|
4464
|
-
|
4465
|
-
|
4466
|
-
|
4467
|
-
|
4468
|
-
|
4469
|
-
|
4470
|
-
);
|
4471
|
-
}
|
4472
|
-
};
|
4473
|
-
var PlatformError = class extends Error {
|
4474
|
-
constructor(message, platform, code = "PLATFORM_ERROR", recoverable = false, originalError, status, userId, details) {
|
4475
|
-
super(message);
|
4476
|
-
this.originalError = originalError;
|
4477
|
-
this.status = status;
|
4478
|
-
this.name = "PlatformError";
|
4479
|
-
this.code = code;
|
4480
|
-
this.recoverable = recoverable;
|
4481
|
-
this.platform = platform;
|
4482
|
-
this.userId = userId;
|
4483
|
-
this.details = details;
|
4484
|
-
}
|
4217
|
+
var ApiErrorCodeSchema = z.enum(Object.values(ApiErrorCode));
|
4218
|
+
var errorCodeToStatusCode = {
|
4219
|
+
[
|
4220
|
+
"MULTI_STATUS"
|
4221
|
+
/* MULTI_STATUS */
|
4222
|
+
]: 207,
|
4223
|
+
[
|
4224
|
+
"UNKNOWN_ERROR"
|
4225
|
+
/* UNKNOWN_ERROR */
|
4226
|
+
]: 500,
|
4227
|
+
[
|
4228
|
+
"INTERNAL_ERROR"
|
4229
|
+
/* INTERNAL_ERROR */
|
4230
|
+
]: 500,
|
4231
|
+
[
|
4232
|
+
"VALIDATION_ERROR"
|
4233
|
+
/* VALIDATION_ERROR */
|
4234
|
+
]: 400,
|
4235
|
+
[
|
4236
|
+
"INVALID_REQUEST"
|
4237
|
+
/* INVALID_REQUEST */
|
4238
|
+
]: 400,
|
4239
|
+
[
|
4240
|
+
"NOT_FOUND"
|
4241
|
+
/* NOT_FOUND */
|
4242
|
+
]: 404,
|
4243
|
+
[
|
4244
|
+
"UNAUTHORIZED"
|
4245
|
+
/* UNAUTHORIZED */
|
4246
|
+
]: 401,
|
4247
|
+
[
|
4248
|
+
"FORBIDDEN"
|
4249
|
+
/* FORBIDDEN */
|
4250
|
+
]: 403,
|
4251
|
+
[
|
4252
|
+
"RATE_LIMITED"
|
4253
|
+
/* RATE_LIMITED */
|
4254
|
+
]: 429,
|
4255
|
+
[
|
4256
|
+
"PLATFORM_ERROR"
|
4257
|
+
/* PLATFORM_ERROR */
|
4258
|
+
]: 502,
|
4259
|
+
[
|
4260
|
+
"PLATFORM_UNAVAILABLE"
|
4261
|
+
/* PLATFORM_UNAVAILABLE */
|
4262
|
+
]: 503,
|
4263
|
+
[
|
4264
|
+
"CONTENT_POLICY_VIOLATION"
|
4265
|
+
/* CONTENT_POLICY_VIOLATION */
|
4266
|
+
]: 400,
|
4267
|
+
[
|
4268
|
+
"DUPLICATE_CONTENT"
|
4269
|
+
/* DUPLICATE_CONTENT */
|
4270
|
+
]: 400,
|
4271
|
+
[
|
4272
|
+
"MEDIA_UPLOAD_FAILED"
|
4273
|
+
/* MEDIA_UPLOAD_FAILED */
|
4274
|
+
]: 400,
|
4275
|
+
[
|
4276
|
+
"POST_CREATION_FAILED"
|
4277
|
+
/* POST_CREATION_FAILED */
|
4278
|
+
]: 500,
|
4279
|
+
[
|
4280
|
+
"THREAD_CREATION_FAILED"
|
4281
|
+
/* THREAD_CREATION_FAILED */
|
4282
|
+
]: 500,
|
4283
|
+
[
|
4284
|
+
"POST_DELETION_FAILED"
|
4285
|
+
/* POST_DELETION_FAILED */
|
4286
|
+
]: 500,
|
4287
|
+
[
|
4288
|
+
"POST_INTERACTION_FAILED"
|
4289
|
+
/* POST_INTERACTION_FAILED */
|
4290
|
+
]: 500,
|
4291
|
+
[
|
4292
|
+
"NETWORK_ERROR"
|
4293
|
+
/* NETWORK_ERROR */
|
4294
|
+
]: 503
|
4485
4295
|
};
|
4296
|
+
var ErrorDetailSchema = z.object({
|
4297
|
+
message: z.string().describe("Human-readable error message"),
|
4298
|
+
code: ApiErrorCodeSchema.describe("Machine-readable error code"),
|
4299
|
+
recoverable: z.boolean().describe("Whether the error can be recovered from"),
|
4300
|
+
details: z.record(z.unknown()).optional().describe("Additional error details")
|
4301
|
+
});
|
4302
|
+
var ResponseMetaSchema = z.object({
|
4303
|
+
requestId: z.string().uuid().describe("Unique identifier for the request"),
|
4304
|
+
timestamp: z.string().datetime().describe("ISO timestamp of response generation"),
|
4305
|
+
rateLimit: z.object({
|
4306
|
+
remaining: z.number().int().nonnegative(),
|
4307
|
+
limit: z.number().int().positive(),
|
4308
|
+
reset: z.number().int().positive().describe("Unix timestamp (seconds)")
|
4309
|
+
}).optional().describe("Rate limit information if applicable"),
|
4310
|
+
pagination: z.object({
|
4311
|
+
page: z.number().int().positive().optional(),
|
4312
|
+
perPage: z.number().int().positive().optional(),
|
4313
|
+
total: z.number().int().nonnegative().optional(),
|
4314
|
+
limit: z.number().int().nonnegative().optional(),
|
4315
|
+
offset: z.number().int().nonnegative().optional(),
|
4316
|
+
totalPages: z.number().int().nonnegative().optional(),
|
4317
|
+
nextCursor: z.string().optional(),
|
4318
|
+
prevCursor: z.string().optional()
|
4319
|
+
}).optional().describe("Pagination information if applicable")
|
4320
|
+
});
|
4321
|
+
var SuccessDetailSchema = z.object({
|
4322
|
+
platform: z.string(),
|
4323
|
+
userId: z.string(),
|
4324
|
+
additionalData: z.any().optional(),
|
4325
|
+
status: z.literal("success")
|
4326
|
+
}).catchall(z.any());
|
4327
|
+
var MultiStatusDataSchema = z.object({
|
4328
|
+
summary: z.object({
|
4329
|
+
total: z.number().int().nonnegative(),
|
4330
|
+
succeeded: z.number().int().nonnegative(),
|
4331
|
+
failed: z.number().int().nonnegative()
|
4332
|
+
}),
|
4333
|
+
results: z.array(SuccessDetailSchema),
|
4334
|
+
errors: z.array(ErrorDetailSchema)
|
4335
|
+
});
|
4486
4336
|
var PlatformParamSchema = z.object({
|
4487
4337
|
platform: z.string().describe("Social media platform")
|
4488
4338
|
}).describe("Platform parameter");
|
@@ -4492,44 +4342,37 @@ var AuthInitRequestSchema = z.object({
|
|
4492
4342
|
),
|
4493
4343
|
errorUrl: z.string().url().optional().describe("URL to redirect to on authentication error")
|
4494
4344
|
}).describe("Auth initialization request");
|
4495
|
-
var AuthUrlResponseSchema =
|
4496
|
-
z.
|
4497
|
-
|
4498
|
-
|
4499
|
-
|
4500
|
-
})
|
4501
|
-
).describe("Auth URL response");
|
4345
|
+
var AuthUrlResponseSchema = z.object({
|
4346
|
+
url: z.string().describe("Authentication URL to redirect the user to"),
|
4347
|
+
state: z.string().describe("State parameter for CSRF protection"),
|
4348
|
+
platform: PlatformSchema
|
4349
|
+
}).describe("Auth URL response");
|
4502
4350
|
var AuthCallbackQuerySchema = z.object({
|
4503
4351
|
code: z.string().describe("Authorization code from OAuth provider"),
|
4504
4352
|
state: z.string().describe("State parameter for CSRF protection")
|
4505
4353
|
}).describe("Auth callback query");
|
4506
|
-
var AuthCallbackResponseSchema =
|
4507
|
-
|
4508
|
-
|
4509
|
-
|
4510
|
-
|
4511
|
-
|
4512
|
-
|
4513
|
-
).describe("
|
4514
|
-
|
4515
|
-
z.object({
|
4516
|
-
|
4517
|
-
|
4518
|
-
|
4519
|
-
tokenStatus: z.object({
|
4520
|
-
valid: z.boolean().describe("Whether the token is valid"),
|
4521
|
-
expired: z.boolean().describe("Whether the token is expired"),
|
4522
|
-
expiresAt: z.string().optional().describe("When the token expires")
|
4523
|
-
})
|
4524
|
-
})
|
4525
|
-
).describe("Auth status response");
|
4526
|
-
var AuthRevokeResponseSchema = EnhancedResponseSchema(
|
4527
|
-
z.object({
|
4528
|
-
success: z.boolean().describe("Whether the revocation was successful"),
|
4529
|
-
platform: PlatformSchema,
|
4530
|
-
userId: z.string().describe("User ID")
|
4354
|
+
var AuthCallbackResponseSchema = z.object({
|
4355
|
+
platform: PlatformSchema,
|
4356
|
+
userId: z.string().describe("User ID"),
|
4357
|
+
redirectUrl: z.string().optional().describe("URL to redirect the user to after authentication")
|
4358
|
+
}).describe("Auth callback response");
|
4359
|
+
var AuthStatusResponseSchema = z.object({
|
4360
|
+
platform: PlatformSchema,
|
4361
|
+
userId: z.string().describe("User ID"),
|
4362
|
+
authenticated: z.boolean().describe("Whether the user is authenticated"),
|
4363
|
+
tokenStatus: z.object({
|
4364
|
+
valid: z.boolean().describe("Whether the token is valid"),
|
4365
|
+
expired: z.boolean().describe("Whether the token is expired"),
|
4366
|
+
expiresAt: z.string().optional().describe("When the token expires")
|
4531
4367
|
})
|
4532
|
-
).describe("Auth
|
4368
|
+
}).describe("Auth status response");
|
4369
|
+
var AuthTokenRequestSchema = z.object({
|
4370
|
+
userId: z.string().describe("User ID on the platform")
|
4371
|
+
}).describe("Auth token request");
|
4372
|
+
var AuthRevokeResponseSchema = z.object({
|
4373
|
+
platform: PlatformSchema,
|
4374
|
+
userId: z.string().describe("User ID")
|
4375
|
+
}).describe("Auth revoke response");
|
4533
4376
|
var ConnectedAccountSchema = z.object({
|
4534
4377
|
platform: PlatformSchema,
|
4535
4378
|
userId: z.string().describe("User ID on the platform"),
|
@@ -4537,26 +4380,21 @@ var ConnectedAccountSchema = z.object({
|
|
4537
4380
|
profileUrl: z.string().optional().describe("URL to the user profile"),
|
4538
4381
|
connectedAt: z.string().optional().describe("When the account was connected")
|
4539
4382
|
}).describe("Connected account");
|
4540
|
-
var ConnectedAccountsResponseSchema =
|
4541
|
-
|
4542
|
-
)
|
4383
|
+
var ConnectedAccountsResponseSchema = z.array(ConnectedAccountSchema).describe(
|
4384
|
+
"Connected accounts response"
|
4385
|
+
);
|
4543
4386
|
var NearAuthorizationRequestSchema = z.object({
|
4544
4387
|
// No additional parameters needed, as the NEAR account ID is extracted from the signature
|
4545
4388
|
}).describe("NEAR authorization request");
|
4546
|
-
var NearAuthorizationResponseSchema =
|
4547
|
-
z.
|
4548
|
-
|
4549
|
-
|
4550
|
-
|
4551
|
-
|
4552
|
-
).describe("
|
4553
|
-
|
4554
|
-
|
4555
|
-
nearAccount: z.string().describe("NEAR account ID"),
|
4556
|
-
authorized: z.boolean().describe("Whether the account is authorized"),
|
4557
|
-
authorizedAt: z.string().optional().describe("When the account was authorized")
|
4558
|
-
})
|
4559
|
-
).describe("NEAR authorization status response");
|
4389
|
+
var NearAuthorizationResponseSchema = z.object({
|
4390
|
+
nearAccount: z.string().describe("NEAR account ID"),
|
4391
|
+
authorized: z.boolean().describe("Whether the account is authorized")
|
4392
|
+
}).describe("NEAR authorization response");
|
4393
|
+
var NearAuthorizationStatusResponseSchema = z.object({
|
4394
|
+
nearAccount: z.string().describe("NEAR account ID"),
|
4395
|
+
authorized: z.boolean().describe("Whether the account is authorized"),
|
4396
|
+
authorizedAt: z.string().optional().describe("When the account was authorized")
|
4397
|
+
}).describe("NEAR authorization status response");
|
4560
4398
|
var MediaContentSchema = z.object({
|
4561
4399
|
data: z.union([z.string(), z.instanceof(Blob)]).describe("Media data as string or Blob"),
|
4562
4400
|
mimeType: z.string().optional().describe("Media MIME type"),
|
@@ -4671,65 +4509,33 @@ var UnlikePostRequestSchema = z.object({
|
|
4671
4509
|
platform: PlatformSchema.describe("Platform of the post being unliked"),
|
4672
4510
|
postId: z.string().describe("ID of the post to unlike")
|
4673
4511
|
}).describe("Unlike post request");
|
4674
|
-
var PostResponseSchema =
|
4675
|
-
|
4676
|
-
)
|
4677
|
-
var
|
4678
|
-
"Create post response
|
4512
|
+
var PostResponseSchema = z.union([PostSchema, z.array(PostSchema)]).describe(
|
4513
|
+
"Post response"
|
4514
|
+
);
|
4515
|
+
var CreatePostResponseSchema = PostResponseSchema.describe(
|
4516
|
+
"Create post response"
|
4679
4517
|
);
|
4680
4518
|
var RepostResponseSchema = PostResponseSchema.describe("Repost response");
|
4681
4519
|
var QuotePostResponseSchema = PostResponseSchema.describe("Quote post response");
|
4682
4520
|
var ReplyToPostResponseSchema = PostResponseSchema.describe("Reply to post response");
|
4683
|
-
var DeletePostResponseSchema =
|
4684
|
-
z.
|
4685
|
-
|
4686
|
-
|
4687
|
-
|
4688
|
-
).describe("
|
4689
|
-
var
|
4690
|
-
z.
|
4691
|
-
|
4692
|
-
id: z.string().describe("ID of the liked post")
|
4693
|
-
})
|
4694
|
-
).describe("Like post response");
|
4695
|
-
var UnlikePostResponseSchema = EnhancedResponseSchema(
|
4696
|
-
z.object({
|
4697
|
-
success: z.boolean().describe("Whether the unlike was successful"),
|
4698
|
-
id: z.string().describe("ID of the unliked post")
|
4699
|
-
})
|
4700
|
-
).describe("Unlike post response");
|
4521
|
+
var DeletePostResponseSchema = z.object({
|
4522
|
+
id: z.string().describe("ID of the deleted post")
|
4523
|
+
}).describe("Delete post response");
|
4524
|
+
var LikePostResponseSchema = z.object({
|
4525
|
+
id: z.string().describe("ID of the liked post")
|
4526
|
+
}).describe("Like post response");
|
4527
|
+
var UnlikePostResponseSchema = z.object({
|
4528
|
+
id: z.string().describe("ID of the unliked post")
|
4529
|
+
}).describe("Unlike post response");
|
4701
4530
|
var PostMultiStatusResponseSchema = z.object({
|
4702
|
-
|
4703
|
-
|
4704
|
-
|
4705
|
-
|
4706
|
-
|
4707
|
-
|
4708
|
-
|
4709
|
-
results: z.array(PostSuccessDetailSchema).describe("Successful operations"),
|
4710
|
-
errors: z.array(ErrorDetailSchema).describe("Failed operations")
|
4711
|
-
})
|
4531
|
+
summary: z.object({
|
4532
|
+
total: z.number().describe("Total number of operations"),
|
4533
|
+
succeeded: z.number().describe("Number of successful operations"),
|
4534
|
+
failed: z.number().describe("Number of failed operations")
|
4535
|
+
}),
|
4536
|
+
results: z.array(PostSuccessDetailSchema).describe("Successful operations"),
|
4537
|
+
errors: z.array(ErrorDetailSchema).describe("Failed operations")
|
4712
4538
|
}).describe("Multi-status response for post operations");
|
4713
|
-
var CreatePostTargetResultSchema = z.object({
|
4714
|
-
platform: PlatformSchema.describe("The platform the post was created on"),
|
4715
|
-
userId: z.string().describe("The user ID on the platform"),
|
4716
|
-
result: z.array(z.any()).describe("The result of the post creation")
|
4717
|
-
}).describe("Create post target result");
|
4718
|
-
var CreatePostTargetErrorSchema = z.object({
|
4719
|
-
platform: PlatformSchema.optional().describe(
|
4720
|
-
"The platform where the error occurred (if applicable)"
|
4721
|
-
),
|
4722
|
-
userId: z.string().optional().describe("The user ID where the error occurred (if applicable)"),
|
4723
|
-
error: z.string().describe("The error message")
|
4724
|
-
}).describe("Create post target error");
|
4725
|
-
var CreatePostResponseSchema = EnhancedResponseSchema(
|
4726
|
-
z.object({
|
4727
|
-
results: z.array(CreatePostTargetResultSchema).describe("Array of successful post results"),
|
4728
|
-
errors: z.array(CreatePostTargetErrorSchema).optional().describe(
|
4729
|
-
"Array of errors that occurred (if any)"
|
4730
|
-
)
|
4731
|
-
})
|
4732
|
-
).describe("Create post response");
|
4733
4539
|
var RateLimitEndpointParamSchema = z.object({
|
4734
4540
|
endpoint: z.string().optional().describe(
|
4735
4541
|
"Specific endpoint to get rate limit information for (optional)"
|
@@ -4764,43 +4570,39 @@ var UsageRateLimitSchema = z.object({
|
|
4764
4570
|
resetSeconds: z.number().describe("Seconds until the rate limit will reset"),
|
4765
4571
|
timeWindow: z.string().describe("Time window for the rate limit")
|
4766
4572
|
}).describe("Usage rate limit");
|
4767
|
-
var RateLimitStatusResponseSchema =
|
4768
|
-
|
4769
|
-
|
4770
|
-
|
4771
|
-
|
4772
|
-
|
4773
|
-
|
4774
|
-
|
4775
|
-
|
4776
|
-
|
4777
|
-
|
4778
|
-
|
4779
|
-
|
4780
|
-
|
4781
|
-
|
4782
|
-
|
4783
|
-
|
4784
|
-
|
4785
|
-
|
4786
|
-
|
4787
|
-
|
4788
|
-
|
4789
|
-
|
4790
|
-
|
4791
|
-
|
4792
|
-
|
4793
|
-
).describe("
|
4794
|
-
|
4795
|
-
|
4796
|
-
|
4797
|
-
|
4798
|
-
|
4799
|
-
|
4800
|
-
})
|
4801
|
-
).describe("Rate limits by platform")
|
4802
|
-
})
|
4803
|
-
).describe("All rate limits response");
|
4573
|
+
var RateLimitStatusResponseSchema = z.object({
|
4574
|
+
platform: PlatformSchema,
|
4575
|
+
userId: z.string().optional().describe("User ID"),
|
4576
|
+
endpoints: z.array(RateLimitEndpointSchema).describe("Rate limits for specific endpoints"),
|
4577
|
+
app: z.object({
|
4578
|
+
limit: z.number().describe("App-wide rate limit"),
|
4579
|
+
remaining: z.number().describe("Remaining requests"),
|
4580
|
+
reset: z.number().describe("Reset timestamp (Unix timestamp in seconds)"),
|
4581
|
+
resetDate: z.string().describe("Reset date (ISO string)")
|
4582
|
+
}).optional().describe("App-wide rate limits")
|
4583
|
+
}).describe("Rate limit status response");
|
4584
|
+
var AllRateLimitsResponseSchema = z.object({
|
4585
|
+
platforms: z.record(
|
4586
|
+
PlatformSchema,
|
4587
|
+
z.object({
|
4588
|
+
users: z.record(
|
4589
|
+
z.string(),
|
4590
|
+
z.object({
|
4591
|
+
endpoints: z.array(RateLimitEndpointSchema).describe(
|
4592
|
+
"Rate limits for specific endpoints"
|
4593
|
+
),
|
4594
|
+
lastUpdated: z.string().describe("Last updated date (ISO string)")
|
4595
|
+
})
|
4596
|
+
).describe("User-specific rate limits"),
|
4597
|
+
app: z.object({
|
4598
|
+
limit: z.number().describe("App-wide rate limit"),
|
4599
|
+
remaining: z.number().describe("Remaining requests"),
|
4600
|
+
reset: z.number().describe("Reset timestamp (Unix timestamp in seconds)"),
|
4601
|
+
resetDate: z.string().describe("Reset date (ISO string)")
|
4602
|
+
}).optional().describe("App-wide rate limits")
|
4603
|
+
})
|
4604
|
+
).describe("Rate limits by platform")
|
4605
|
+
}).describe("All rate limits response");
|
4804
4606
|
var RateLimitResponseSchema = z.object({
|
4805
4607
|
platformLimits: z.array(PlatformRateLimitSchema).describe("Platform-specific rate limits"),
|
4806
4608
|
usageLimits: z.record(z.string(), UsageRateLimitSchema).describe(
|
@@ -4845,16 +4647,12 @@ var AccountActivityEntrySchema = z.object({
|
|
4845
4647
|
rank: z.number().describe("Rank on the leaderboard"),
|
4846
4648
|
lastActive: z.string().datetime().describe("Timestamp of last activity")
|
4847
4649
|
}).describe("Account activity entry");
|
4848
|
-
var ActivityLeaderboardResponseSchema =
|
4849
|
-
z.
|
4850
|
-
|
4851
|
-
|
4852
|
-
|
4853
|
-
|
4854
|
-
offset: z.number().describe("Offset for pagination"),
|
4855
|
-
generatedAt: z.string().datetime().describe("Timestamp when the leaderboard was generated")
|
4856
|
-
})
|
4857
|
-
).describe("Activity leaderboard response");
|
4650
|
+
var ActivityLeaderboardResponseSchema = z.object({
|
4651
|
+
timeframe: z.nativeEnum(TimePeriod).describe("Timeframe for the leaderboard"),
|
4652
|
+
entries: z.array(AccountActivityEntrySchema).describe("Leaderboard entries"),
|
4653
|
+
generatedAt: z.string().datetime().describe("Timestamp when the leaderboard was generated"),
|
4654
|
+
platform: PlatformSchema.optional().describe("Platform filter (if applied)")
|
4655
|
+
});
|
4858
4656
|
var AccountActivityParamsSchema = z.object({
|
4859
4657
|
signerId: z.string().describe("NEAR account ID")
|
4860
4658
|
}).describe("Account activity params");
|
@@ -4873,21 +4671,19 @@ var PlatformActivitySchema = z.object({
|
|
4873
4671
|
score: z.number().describe("Activity score on this platform"),
|
4874
4672
|
lastActive: z.string().datetime().describe("Timestamp of last activity on this platform")
|
4875
4673
|
}).describe("Platform activity");
|
4876
|
-
var AccountActivityResponseSchema =
|
4877
|
-
z.
|
4878
|
-
|
4879
|
-
|
4880
|
-
|
4881
|
-
|
4882
|
-
|
4883
|
-
|
4884
|
-
|
4885
|
-
|
4886
|
-
|
4887
|
-
|
4888
|
-
|
4889
|
-
})
|
4890
|
-
).describe("Account activity response");
|
4674
|
+
var AccountActivityResponseSchema = z.object({
|
4675
|
+
signerId: z.string().describe("NEAR account ID"),
|
4676
|
+
timeframe: z.nativeEnum(TimePeriod).describe("Timeframe for the activity"),
|
4677
|
+
totalPosts: z.number().describe("Total number of posts across all platforms"),
|
4678
|
+
totalLikes: z.number().describe("Total number of likes across all platforms"),
|
4679
|
+
totalReposts: z.number().describe("Total number of reposts across all platforms"),
|
4680
|
+
totalReplies: z.number().describe("Total number of replies across all platforms"),
|
4681
|
+
totalQuotes: z.number().describe("Total number of quote posts across all platforms"),
|
4682
|
+
totalScore: z.number().describe("Total activity score across all platforms"),
|
4683
|
+
rank: z.number().describe("Rank on the leaderboard"),
|
4684
|
+
lastActive: z.string().datetime().describe("Timestamp of last activity across all platforms"),
|
4685
|
+
platforms: z.array(PlatformActivitySchema).describe("Activity breakdown by platform")
|
4686
|
+
});
|
4891
4687
|
var AccountPostsParamsSchema = z.object({
|
4892
4688
|
signerId: z.string().describe("NEAR account ID")
|
4893
4689
|
}).describe("Account posts params");
|
@@ -4915,19 +4711,14 @@ var AccountPostSchema = z.object({
|
|
4915
4711
|
inReplyToId: z.string().optional().describe("ID of the post this is a reply to (if applicable)"),
|
4916
4712
|
quotedPostId: z.string().optional().describe("ID of the post this is quoting (if applicable)")
|
4917
4713
|
}).describe("Account post");
|
4918
|
-
var AccountPostsResponseSchema =
|
4919
|
-
z.
|
4920
|
-
|
4921
|
-
|
4922
|
-
|
4923
|
-
|
4924
|
-
|
4925
|
-
|
4926
|
-
type: z.enum(["post", "repost", "reply", "quote", "like", "all"]).optional().describe(
|
4927
|
-
"Post type filter (if applied)"
|
4928
|
-
)
|
4929
|
-
})
|
4930
|
-
).describe("Account posts response");
|
4714
|
+
var AccountPostsResponseSchema = z.object({
|
4715
|
+
signerId: z.string().describe("NEAR account ID"),
|
4716
|
+
posts: z.array(AccountPostSchema).describe("List of posts"),
|
4717
|
+
platform: z.string().optional().describe("Platform filter (if applied)"),
|
4718
|
+
type: z.enum(["post", "repost", "reply", "quote", "like", "all"]).optional().describe(
|
4719
|
+
"Post type filter (if applied)"
|
4720
|
+
)
|
4721
|
+
});
|
4931
4722
|
var UserProfileSchema = z.object({
|
4932
4723
|
userId: z.string().describe("User ID on the platform"),
|
4933
4724
|
username: z.string().describe("Username on the platform"),
|
@@ -4937,118 +4728,107 @@ var UserProfileSchema = z.object({
|
|
4937
4728
|
platform: PlatformSchema.describe("The platform the user profile is from"),
|
4938
4729
|
lastUpdated: z.number().describe("Timestamp when the profile was last updated")
|
4939
4730
|
}).describe("User profile");
|
4940
|
-
var
|
4941
|
-
|
4942
|
-
|
4943
|
-
error: z.string().optional().describe("Error message (if unsuccessful)")
|
4944
|
-
}).describe("Profile refresh result");
|
4945
|
-
var ProfileRefreshResponseSchema = EnhancedResponseSchema(
|
4946
|
-
ProfileRefreshResultSchema
|
4947
|
-
).describe("Profile refresh response");
|
4731
|
+
var ProfileRefreshResponseSchema = z.object({
|
4732
|
+
profile: UserProfileSchema.optional().describe("The refreshed user profile (if successful)")
|
4733
|
+
}).describe("Profile refresh response");
|
4948
4734
|
|
4949
4735
|
// src/core/request.ts
|
4950
4736
|
var import_near_sign_verify = require("near-sign-verify");
|
4951
4737
|
|
4952
4738
|
// src/utils/error.ts
|
4953
|
-
var
|
4954
|
-
|
4955
|
-
|
4956
|
-
|
4957
|
-
|
4958
|
-
|
4959
|
-
|
4960
|
-
|
4961
|
-
],
|
4962
|
-
NETWORK: [
|
4963
|
-
ApiErrorCode.NETWORK_ERROR
|
4964
|
-
],
|
4965
|
-
PLATFORM: [
|
4966
|
-
ApiErrorCode.PLATFORM_ERROR,
|
4967
|
-
ApiErrorCode.PLATFORM_UNAVAILABLE
|
4968
|
-
],
|
4969
|
-
CONTENT: [
|
4970
|
-
ApiErrorCode.CONTENT_POLICY_VIOLATION,
|
4971
|
-
ApiErrorCode.DUPLICATE_CONTENT
|
4972
|
-
],
|
4973
|
-
RATE_LIMIT: [
|
4974
|
-
ApiErrorCode.RATE_LIMITED
|
4975
|
-
],
|
4976
|
-
POST: [
|
4977
|
-
ApiErrorCode.POST_CREATION_FAILED,
|
4978
|
-
ApiErrorCode.THREAD_CREATION_FAILED,
|
4979
|
-
ApiErrorCode.POST_DELETION_FAILED,
|
4980
|
-
ApiErrorCode.POST_INTERACTION_FAILED
|
4981
|
-
],
|
4982
|
-
MEDIA: [
|
4983
|
-
ApiErrorCode.MEDIA_UPLOAD_FAILED
|
4984
|
-
]
|
4985
|
-
};
|
4986
|
-
function isErrorOfCategory(error, category) {
|
4987
|
-
if (error instanceof ApiError) {
|
4988
|
-
return category.includes(error.code);
|
4739
|
+
var CrosspostError = class extends Error {
|
4740
|
+
constructor(message, code, status, details, recoverable = false) {
|
4741
|
+
super(message);
|
4742
|
+
this.name = "CrosspostError";
|
4743
|
+
this.code = code;
|
4744
|
+
this.status = status;
|
4745
|
+
this.details = details;
|
4746
|
+
this.recoverable = recoverable;
|
4989
4747
|
}
|
4990
|
-
|
4991
|
-
|
4748
|
+
/**
|
4749
|
+
* Get platform from details if available
|
4750
|
+
*/
|
4751
|
+
get platform() {
|
4752
|
+
return this.details?.platform;
|
4992
4753
|
}
|
4993
|
-
|
4994
|
-
|
4754
|
+
/**
|
4755
|
+
* Get userId from details if available
|
4756
|
+
*/
|
4757
|
+
get userId() {
|
4758
|
+
return this.details?.userId;
|
4995
4759
|
}
|
4996
|
-
|
4760
|
+
};
|
4761
|
+
function isErrorCode(error, codes) {
|
4762
|
+
return error instanceof CrosspostError && codes.includes(error.code);
|
4997
4763
|
}
|
4998
4764
|
function isAuthError(error) {
|
4999
|
-
return
|
4765
|
+
return isErrorCode(error, [
|
4766
|
+
ApiErrorCode.UNAUTHORIZED,
|
4767
|
+
ApiErrorCode.FORBIDDEN
|
4768
|
+
]);
|
5000
4769
|
}
|
5001
4770
|
function isValidationError(error) {
|
5002
|
-
return
|
4771
|
+
return isErrorCode(error, [
|
4772
|
+
ApiErrorCode.VALIDATION_ERROR,
|
4773
|
+
ApiErrorCode.INVALID_REQUEST
|
4774
|
+
]);
|
5003
4775
|
}
|
5004
4776
|
function isNetworkError(error) {
|
5005
|
-
return
|
4777
|
+
return isErrorCode(error, [
|
4778
|
+
ApiErrorCode.NETWORK_ERROR,
|
4779
|
+
ApiErrorCode.PLATFORM_UNAVAILABLE
|
4780
|
+
]);
|
5006
4781
|
}
|
5007
4782
|
function isPlatformError(error) {
|
5008
|
-
return
|
4783
|
+
return error instanceof CrosspostError && !!error.details?.platform;
|
5009
4784
|
}
|
5010
4785
|
function isContentError(error) {
|
5011
|
-
return
|
4786
|
+
return isErrorCode(error, [
|
4787
|
+
ApiErrorCode.CONTENT_POLICY_VIOLATION,
|
4788
|
+
ApiErrorCode.DUPLICATE_CONTENT
|
4789
|
+
]);
|
5012
4790
|
}
|
5013
4791
|
function isRateLimitError(error) {
|
5014
|
-
return
|
4792
|
+
return isErrorCode(error, [ApiErrorCode.RATE_LIMITED]);
|
5015
4793
|
}
|
5016
4794
|
function isPostError(error) {
|
5017
|
-
return
|
4795
|
+
return isErrorCode(error, [
|
4796
|
+
ApiErrorCode.POST_CREATION_FAILED,
|
4797
|
+
ApiErrorCode.THREAD_CREATION_FAILED,
|
4798
|
+
ApiErrorCode.POST_DELETION_FAILED,
|
4799
|
+
ApiErrorCode.POST_INTERACTION_FAILED
|
4800
|
+
]);
|
5018
4801
|
}
|
5019
4802
|
function isMediaError(error) {
|
5020
|
-
return
|
4803
|
+
return isErrorCode(error, [ApiErrorCode.MEDIA_UPLOAD_FAILED]);
|
5021
4804
|
}
|
5022
4805
|
function isRecoverableError(error) {
|
5023
|
-
|
5024
|
-
return error.recoverable;
|
5025
|
-
}
|
5026
|
-
return false;
|
4806
|
+
return error instanceof CrosspostError && error.recoverable;
|
5027
4807
|
}
|
5028
4808
|
function getErrorMessage(error, defaultMessage = "An error occurred") {
|
5029
4809
|
if (error instanceof Error) {
|
5030
4810
|
return error.message || defaultMessage;
|
5031
4811
|
}
|
5032
|
-
if (typeof error === "string") {
|
5033
|
-
return error;
|
5034
|
-
}
|
5035
|
-
if (error && typeof error === "object" && "message" in error) {
|
5036
|
-
return error.message || defaultMessage;
|
5037
|
-
}
|
5038
4812
|
return defaultMessage;
|
5039
4813
|
}
|
5040
4814
|
function getErrorDetails(error) {
|
5041
|
-
if (error instanceof
|
5042
|
-
return error.details;
|
5043
|
-
}
|
5044
|
-
if (error && typeof error === "object" && "details" in error) {
|
4815
|
+
if (error instanceof CrosspostError) {
|
5045
4816
|
return error.details;
|
5046
4817
|
}
|
5047
4818
|
return void 0;
|
5048
4819
|
}
|
4820
|
+
function createError(message, code, status, details, recoverable = false) {
|
4821
|
+
return new CrosspostError(
|
4822
|
+
message,
|
4823
|
+
code,
|
4824
|
+
status,
|
4825
|
+
details,
|
4826
|
+
recoverable
|
4827
|
+
);
|
4828
|
+
}
|
5049
4829
|
function enrichErrorWithContext(error, context) {
|
5050
|
-
if (error instanceof
|
5051
|
-
return
|
4830
|
+
if (error instanceof CrosspostError) {
|
4831
|
+
return createError(
|
5052
4832
|
error.message,
|
5053
4833
|
error.code,
|
5054
4834
|
error.status,
|
@@ -5056,25 +4836,12 @@ function enrichErrorWithContext(error, context) {
|
|
5056
4836
|
error.recoverable
|
5057
4837
|
);
|
5058
4838
|
}
|
5059
|
-
if (error instanceof PlatformError) {
|
5060
|
-
return new PlatformError(
|
5061
|
-
error.message,
|
5062
|
-
error.platform,
|
5063
|
-
error.code,
|
5064
|
-
error.recoverable,
|
5065
|
-
error.originalError,
|
5066
|
-
error.status,
|
5067
|
-
error.userId,
|
5068
|
-
{ ...error.details || {}, ...context }
|
5069
|
-
);
|
5070
|
-
}
|
5071
4839
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
5072
|
-
return
|
4840
|
+
return createError(
|
5073
4841
|
errorMessage || "An error occurred",
|
5074
4842
|
ApiErrorCode.INTERNAL_ERROR,
|
5075
4843
|
500,
|
5076
|
-
{ originalError: error, ...context }
|
5077
|
-
false
|
4844
|
+
{ originalError: error, ...context }
|
5078
4845
|
);
|
5079
4846
|
}
|
5080
4847
|
async function apiWrapper(apiCall, context) {
|
@@ -5091,7 +4858,7 @@ async function apiWrapper(apiCall, context) {
|
|
5091
4858
|
} catch (jsonError) {
|
5092
4859
|
if (jsonError instanceof Error && jsonError.name === "SyntaxError") {
|
5093
4860
|
throw enrichErrorWithContext(
|
5094
|
-
|
4861
|
+
createError(
|
5095
4862
|
`API request failed with status ${error.status} and non-JSON response`,
|
5096
4863
|
ApiErrorCode.NETWORK_ERROR,
|
5097
4864
|
error.status,
|
@@ -5103,7 +4870,7 @@ async function apiWrapper(apiCall, context) {
|
|
5103
4870
|
throw jsonError;
|
5104
4871
|
}
|
5105
4872
|
}
|
5106
|
-
if (error instanceof
|
4873
|
+
if (error instanceof CrosspostError) {
|
5107
4874
|
throw enrichErrorWithContext(error, context || {});
|
5108
4875
|
}
|
5109
4876
|
throw enrichErrorWithContext(
|
@@ -5113,50 +4880,68 @@ async function apiWrapper(apiCall, context) {
|
|
5113
4880
|
}
|
5114
4881
|
}
|
5115
4882
|
function handleErrorResponse(data, status) {
|
5116
|
-
|
5117
|
-
|
5118
|
-
|
5119
|
-
|
5120
|
-
|
5121
|
-
|
5122
|
-
|
5123
|
-
|
5124
|
-
if (
|
5125
|
-
|
5126
|
-
|
5127
|
-
|
5128
|
-
|
5129
|
-
|
5130
|
-
|
5131
|
-
|
5132
|
-
|
4883
|
+
if (!data || typeof data !== "object" || !("success" in data)) {
|
4884
|
+
return createError(
|
4885
|
+
"Invalid API response format",
|
4886
|
+
ApiErrorCode.INTERNAL_ERROR,
|
4887
|
+
status,
|
4888
|
+
{ originalResponse: data }
|
4889
|
+
);
|
4890
|
+
}
|
4891
|
+
if (!data.errors || !Array.isArray(data.errors) || data.errors.length === 0) {
|
4892
|
+
return createError(
|
4893
|
+
"Invalid error response format",
|
4894
|
+
ApiErrorCode.INTERNAL_ERROR,
|
4895
|
+
status,
|
4896
|
+
{ originalResponse: data }
|
4897
|
+
);
|
4898
|
+
}
|
4899
|
+
if (data.errors.length === 1) {
|
4900
|
+
const errorDetail = data.errors[0];
|
4901
|
+
if (!errorDetail.message || !errorDetail.code) {
|
4902
|
+
return createError(
|
4903
|
+
"Invalid error detail format",
|
4904
|
+
ApiErrorCode.INTERNAL_ERROR,
|
4905
|
+
status,
|
4906
|
+
{ originalResponse: data }
|
4907
|
+
);
|
4908
|
+
}
|
4909
|
+
const finalDetails = {
|
4910
|
+
...errorDetail.details || {},
|
4911
|
+
...data.meta || {}
|
4912
|
+
};
|
4913
|
+
return createError(
|
4914
|
+
errorDetail.message,
|
4915
|
+
errorDetail.code,
|
5133
4916
|
status,
|
5134
|
-
|
5135
|
-
|
5136
|
-
recoverable
|
4917
|
+
finalDetails,
|
4918
|
+
errorDetail.recoverable ?? false
|
5137
4919
|
);
|
5138
4920
|
} else {
|
5139
|
-
|
5140
|
-
|
5141
|
-
|
5142
|
-
|
4921
|
+
const firstError = data.errors[0];
|
4922
|
+
return createError(
|
4923
|
+
"Multiple errors occurred",
|
4924
|
+
firstError.code,
|
5143
4925
|
status,
|
5144
|
-
|
5145
|
-
|
5146
|
-
|
4926
|
+
{
|
4927
|
+
errors: data.errors,
|
4928
|
+
...data.meta || {},
|
4929
|
+
originalResponse: data
|
4930
|
+
},
|
4931
|
+
false
|
5147
4932
|
);
|
5148
4933
|
}
|
5149
4934
|
}
|
5150
4935
|
function createNetworkError(error, url, timeout) {
|
5151
4936
|
if (error instanceof DOMException && error.name === "AbortError") {
|
5152
|
-
return
|
4937
|
+
return createError(
|
5153
4938
|
`Request timed out after ${timeout}ms`,
|
5154
4939
|
ApiErrorCode.NETWORK_ERROR,
|
5155
4940
|
408,
|
5156
4941
|
{ url }
|
5157
4942
|
);
|
5158
4943
|
}
|
5159
|
-
return
|
4944
|
+
return createError(
|
5160
4945
|
error instanceof Error ? error.message : "An unexpected error occurred during the request",
|
5161
4946
|
ApiErrorCode.INTERNAL_ERROR,
|
5162
4947
|
500,
|
@@ -5179,9 +4964,6 @@ async function makeRequest(method, path, options, data, query) {
|
|
5179
4964
|
url += `?${queryString}`;
|
5180
4965
|
}
|
5181
4966
|
}
|
5182
|
-
if (!options.nearAuthData) {
|
5183
|
-
throw ApiError.unauthorized("Authentication required. Please provide NEAR signature.");
|
5184
|
-
}
|
5185
4967
|
const context = {
|
5186
4968
|
method,
|
5187
4969
|
path,
|
@@ -5212,15 +4994,14 @@ async function makeRequest(method, path, options, data, query) {
|
|
5212
4994
|
responseData = await response.json();
|
5213
4995
|
} catch (jsonError) {
|
5214
4996
|
if (!response.ok) {
|
5215
|
-
throw new
|
4997
|
+
throw new CrosspostError(
|
5216
4998
|
`API request failed with status ${response.status} and non-JSON response`,
|
5217
4999
|
ApiErrorCode.NETWORK_ERROR,
|
5218
5000
|
response.status,
|
5219
5001
|
{ originalStatusText: response.statusText }
|
5220
5002
|
);
|
5221
5003
|
}
|
5222
|
-
|
5223
|
-
throw new ApiError(
|
5004
|
+
throw new CrosspostError(
|
5224
5005
|
`Failed to parse JSON response: ${jsonError instanceof Error ? jsonError.message : String(jsonError)}`,
|
5225
5006
|
ApiErrorCode.INTERNAL_ERROR,
|
5226
5007
|
response.status
|
@@ -5228,23 +5009,26 @@ async function makeRequest(method, path, options, data, query) {
|
|
5228
5009
|
}
|
5229
5010
|
if (!response.ok) {
|
5230
5011
|
lastError = handleErrorResponse(responseData, response.status);
|
5231
|
-
const shouldRetry =
|
5012
|
+
const shouldRetry = lastError instanceof CrosspostError && lastError.code === ApiErrorCode.RATE_LIMITED;
|
5232
5013
|
if (shouldRetry && attempt < options.retries) {
|
5233
5014
|
await new Promise((resolve) => setTimeout(resolve, 1e3 * Math.pow(2, attempt)));
|
5234
5015
|
continue;
|
5235
5016
|
}
|
5236
5017
|
throw lastError;
|
5237
5018
|
}
|
5238
|
-
if (responseData && typeof responseData === "object" && "success" in responseData
|
5239
|
-
|
5240
|
-
|
5241
|
-
|
5242
|
-
|
5243
|
-
|
5019
|
+
if (responseData && typeof responseData === "object" && "success" in responseData) {
|
5020
|
+
if (responseData.success) {
|
5021
|
+
return responseData.data;
|
5022
|
+
} else {
|
5023
|
+
lastError = handleErrorResponse(responseData, response.status);
|
5024
|
+
const shouldRetry = lastError instanceof CrosspostError && lastError.code === ApiErrorCode.RATE_LIMITED;
|
5025
|
+
if (shouldRetry && attempt < options.retries) {
|
5026
|
+
await new Promise((resolve) => setTimeout(resolve, 1e3 * Math.pow(2, attempt)));
|
5027
|
+
continue;
|
5028
|
+
}
|
5029
|
+
throw lastError;
|
5244
5030
|
}
|
5245
|
-
throw lastError;
|
5246
5031
|
}
|
5247
|
-
return responseData;
|
5248
5032
|
} catch (error) {
|
5249
5033
|
clearTimeout(timeoutId);
|
5250
5034
|
lastError = error instanceof Error ? error : new Error(String(error));
|
@@ -5253,13 +5037,13 @@ async function makeRequest(method, path, options, data, query) {
|
|
5253
5037
|
await new Promise((resolve) => setTimeout(resolve, 1e3 * Math.pow(2, attempt)));
|
5254
5038
|
continue;
|
5255
5039
|
}
|
5256
|
-
if (!(error instanceof
|
5040
|
+
if (!(error instanceof CrosspostError)) {
|
5257
5041
|
throw createNetworkError(error, url, options.timeout);
|
5258
5042
|
}
|
5259
5043
|
throw error;
|
5260
5044
|
}
|
5261
5045
|
}
|
5262
|
-
throw lastError || new
|
5046
|
+
throw lastError || new CrosspostError("Request failed after multiple retries", ApiErrorCode.INTERNAL_ERROR, 500);
|
5263
5047
|
}, context);
|
5264
5048
|
}
|
5265
5049
|
|
@@ -5495,7 +5279,7 @@ var PostApi = class {
|
|
5495
5279
|
async likePost(request) {
|
5496
5280
|
return makeRequest(
|
5497
5281
|
"POST",
|
5498
|
-
`/api/post/like
|
5282
|
+
`/api/post/like`,
|
5499
5283
|
this.options,
|
5500
5284
|
request
|
5501
5285
|
);
|
@@ -5508,7 +5292,7 @@ var PostApi = class {
|
|
5508
5292
|
async unlikePost(request) {
|
5509
5293
|
return makeRequest(
|
5510
5294
|
"DELETE",
|
5511
|
-
`/api/post/like
|
5295
|
+
`/api/post/like`,
|
5512
5296
|
this.options,
|
5513
5297
|
request
|
5514
5298
|
);
|
@@ -5519,17 +5303,9 @@ var PostApi = class {
|
|
5519
5303
|
* @returns A promise resolving with the delete response.
|
5520
5304
|
*/
|
5521
5305
|
async deletePost(request) {
|
5522
|
-
const postId = request.posts[0]?.postId || "";
|
5523
|
-
if (!postId) {
|
5524
|
-
throw new ApiError(
|
5525
|
-
"Post ID is required for deletion path",
|
5526
|
-
ApiErrorCode.VALIDATION_ERROR,
|
5527
|
-
400
|
5528
|
-
);
|
5529
|
-
}
|
5530
5306
|
return makeRequest(
|
5531
5307
|
"DELETE",
|
5532
|
-
`/api/post
|
5308
|
+
`/api/post`,
|
5533
5309
|
this.options,
|
5534
5310
|
request
|
5535
5311
|
);
|
@@ -5630,56 +5406,43 @@ var CrosspostClient = class {
|
|
5630
5406
|
AccountActivityEntrySchema,
|
5631
5407
|
AccountActivityParamsSchema,
|
5632
5408
|
AccountActivityQuerySchema,
|
5633
|
-
AccountActivityResponseSchema,
|
5634
5409
|
AccountPostSchema,
|
5635
5410
|
AccountPostsParamsSchema,
|
5636
5411
|
AccountPostsQuerySchema,
|
5637
|
-
AccountPostsResponseSchema,
|
5638
5412
|
ActivityApi,
|
5639
5413
|
ActivityLeaderboardQuerySchema,
|
5640
|
-
ActivityLeaderboardResponseSchema,
|
5641
5414
|
AllRateLimitsResponseSchema,
|
5642
|
-
ApiError,
|
5643
5415
|
ApiErrorCode,
|
5644
|
-
|
5416
|
+
ApiErrorCodeSchema,
|
5645
5417
|
AuthApi,
|
5646
5418
|
AuthCallbackQuerySchema,
|
5647
5419
|
AuthCallbackResponseSchema,
|
5648
5420
|
AuthInitRequestSchema,
|
5649
5421
|
AuthRevokeResponseSchema,
|
5650
5422
|
AuthStatusResponseSchema,
|
5423
|
+
AuthTokenRequestSchema,
|
5651
5424
|
AuthUrlResponseSchema,
|
5652
|
-
BaseError,
|
5653
5425
|
ConnectedAccountSchema,
|
5654
5426
|
ConnectedAccountsResponseSchema,
|
5655
5427
|
CreatePostRequestSchema,
|
5656
|
-
CreatePostResponseLegacySchema,
|
5657
5428
|
CreatePostResponseSchema,
|
5658
|
-
CreatePostTargetErrorSchema,
|
5659
|
-
CreatePostTargetResultSchema,
|
5660
5429
|
CrosspostClient,
|
5661
5430
|
DeletePostRequestSchema,
|
5662
5431
|
DeletePostResponseSchema,
|
5663
5432
|
DeleteResultSchema,
|
5664
|
-
ERROR_CATEGORIES,
|
5665
5433
|
EndpointRateLimitResponseSchema,
|
5666
|
-
EnhancedErrorResponseSchema,
|
5667
|
-
EnhancedResponseMetaSchema,
|
5668
|
-
EnhancedResponseSchema,
|
5669
5434
|
ErrorDetailSchema,
|
5670
|
-
ErrorResponseSchema,
|
5671
5435
|
LikePostRequestSchema,
|
5672
5436
|
LikePostResponseSchema,
|
5673
5437
|
LikeResultSchema,
|
5674
5438
|
MediaContentSchema,
|
5675
5439
|
MediaSchema,
|
5676
|
-
|
5440
|
+
MultiStatusDataSchema,
|
5677
5441
|
NearAuthorizationRequestSchema,
|
5678
5442
|
NearAuthorizationResponseSchema,
|
5679
5443
|
NearAuthorizationStatusResponseSchema,
|
5680
5444
|
Platform,
|
5681
5445
|
PlatformActivitySchema,
|
5682
|
-
PlatformError,
|
5683
5446
|
PlatformParamSchema,
|
5684
5447
|
PlatformRateLimitSchema,
|
5685
5448
|
PlatformSchema,
|
@@ -5693,7 +5456,6 @@ var CrosspostClient = class {
|
|
5693
5456
|
PostSuccessDetailSchema,
|
5694
5457
|
PostToDeleteSchema,
|
5695
5458
|
ProfileRefreshResponseSchema,
|
5696
|
-
ProfileRefreshResultSchema,
|
5697
5459
|
QuotePostRequestSchema,
|
5698
5460
|
QuotePostResponseSchema,
|
5699
5461
|
RateLimitEndpointParamSchema,
|
@@ -5705,6 +5467,7 @@ var CrosspostClient = class {
|
|
5705
5467
|
ReplyToPostResponseSchema,
|
5706
5468
|
RepostRequestSchema,
|
5707
5469
|
RepostResponseSchema,
|
5470
|
+
ResponseMetaSchema,
|
5708
5471
|
SUPPORTED_PLATFORMS,
|
5709
5472
|
SuccessDetailSchema,
|
5710
5473
|
SupportedPlatformSchema,
|
@@ -5716,21 +5479,14 @@ var CrosspostClient = class {
|
|
5716
5479
|
UsageRateLimitSchema,
|
5717
5480
|
UserProfileSchema,
|
5718
5481
|
apiWrapper,
|
5719
|
-
createApiResponse,
|
5720
|
-
createEnhancedApiResponse,
|
5721
|
-
createEnhancedErrorResponse,
|
5722
|
-
createErrorDetail,
|
5723
|
-
createErrorResponse,
|
5724
|
-
createMultiStatusResponse,
|
5725
5482
|
createNetworkError,
|
5726
|
-
createSuccessDetail,
|
5727
5483
|
enrichErrorWithContext,
|
5484
|
+
errorCodeToStatusCode,
|
5728
5485
|
getErrorDetails,
|
5729
5486
|
getErrorMessage,
|
5730
5487
|
handleErrorResponse,
|
5731
5488
|
isAuthError,
|
5732
5489
|
isContentError,
|
5733
|
-
isErrorOfCategory,
|
5734
5490
|
isMediaError,
|
5735
5491
|
isNetworkError,
|
5736
5492
|
isPlatformError,
|