@crosspost/sdk 0.1.6 → 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 CHANGED
@@ -23,57 +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
- ApiResponseSchema: () => ApiResponseSchema,
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
- CompositeApiError: () => CompositeApiError,
47
42
  ConnectedAccountSchema: () => ConnectedAccountSchema,
48
43
  ConnectedAccountsResponseSchema: () => ConnectedAccountsResponseSchema,
49
44
  CreatePostRequestSchema: () => CreatePostRequestSchema,
50
- CreatePostResponseLegacySchema: () => CreatePostResponseLegacySchema,
51
45
  CreatePostResponseSchema: () => CreatePostResponseSchema,
52
- CreatePostTargetErrorSchema: () => CreatePostTargetErrorSchema,
53
- CreatePostTargetResultSchema: () => CreatePostTargetResultSchema,
54
46
  CrosspostClient: () => CrosspostClient,
55
47
  DeletePostRequestSchema: () => DeletePostRequestSchema,
56
48
  DeletePostResponseSchema: () => DeletePostResponseSchema,
57
49
  DeleteResultSchema: () => DeleteResultSchema,
58
- ERROR_CATEGORIES: () => ERROR_CATEGORIES,
59
50
  EndpointRateLimitResponseSchema: () => EndpointRateLimitResponseSchema,
60
- EnhancedErrorResponseSchema: () => EnhancedErrorResponseSchema,
61
- EnhancedResponseMetaSchema: () => EnhancedResponseMetaSchema,
62
- EnhancedResponseSchema: () => EnhancedResponseSchema,
63
51
  ErrorDetailSchema: () => ErrorDetailSchema,
64
- ErrorResponseSchema: () => ErrorResponseSchema,
65
52
  LikePostRequestSchema: () => LikePostRequestSchema,
66
53
  LikePostResponseSchema: () => LikePostResponseSchema,
67
54
  LikeResultSchema: () => LikeResultSchema,
68
55
  MediaContentSchema: () => MediaContentSchema,
69
56
  MediaSchema: () => MediaSchema,
70
- MultiStatusResponseSchema: () => MultiStatusResponseSchema,
57
+ MultiStatusDataSchema: () => MultiStatusDataSchema,
71
58
  NearAuthorizationRequestSchema: () => NearAuthorizationRequestSchema,
72
59
  NearAuthorizationResponseSchema: () => NearAuthorizationResponseSchema,
73
60
  NearAuthorizationStatusResponseSchema: () => NearAuthorizationStatusResponseSchema,
74
61
  Platform: () => Platform,
75
62
  PlatformActivitySchema: () => PlatformActivitySchema,
76
- PlatformError: () => PlatformError,
77
63
  PlatformParamSchema: () => PlatformParamSchema,
78
64
  PlatformRateLimitSchema: () => PlatformRateLimitSchema,
79
65
  PlatformSchema: () => PlatformSchema,
@@ -87,7 +73,6 @@ __export(index_exports, {
87
73
  PostSuccessDetailSchema: () => PostSuccessDetailSchema,
88
74
  PostToDeleteSchema: () => PostToDeleteSchema,
89
75
  ProfileRefreshResponseSchema: () => ProfileRefreshResponseSchema,
90
- ProfileRefreshResultSchema: () => ProfileRefreshResultSchema,
91
76
  QuotePostRequestSchema: () => QuotePostRequestSchema,
92
77
  QuotePostResponseSchema: () => QuotePostResponseSchema,
93
78
  RateLimitEndpointParamSchema: () => RateLimitEndpointParamSchema,
@@ -99,6 +84,7 @@ __export(index_exports, {
99
84
  ReplyToPostResponseSchema: () => ReplyToPostResponseSchema,
100
85
  RepostRequestSchema: () => RepostRequestSchema,
101
86
  RepostResponseSchema: () => RepostResponseSchema,
87
+ ResponseMetaSchema: () => ResponseMetaSchema,
102
88
  SUPPORTED_PLATFORMS: () => SUPPORTED_PLATFORMS,
103
89
  SuccessDetailSchema: () => SuccessDetailSchema,
104
90
  SupportedPlatformSchema: () => SupportedPlatformSchema,
@@ -110,21 +96,14 @@ __export(index_exports, {
110
96
  UsageRateLimitSchema: () => UsageRateLimitSchema,
111
97
  UserProfileSchema: () => UserProfileSchema,
112
98
  apiWrapper: () => apiWrapper,
113
- createApiResponse: () => createApiResponse,
114
- createEnhancedApiResponse: () => createEnhancedApiResponse,
115
- createEnhancedErrorResponse: () => createEnhancedErrorResponse,
116
- createErrorDetail: () => createErrorDetail,
117
- createErrorResponse: () => createErrorResponse,
118
- createMultiStatusResponse: () => createMultiStatusResponse,
119
99
  createNetworkError: () => createNetworkError,
120
- createSuccessDetail: () => createSuccessDetail,
121
100
  enrichErrorWithContext: () => enrichErrorWithContext,
101
+ errorCodeToStatusCode: () => errorCodeToStatusCode,
122
102
  getErrorDetails: () => getErrorDetails,
123
103
  getErrorMessage: () => getErrorMessage,
124
104
  handleErrorResponse: () => handleErrorResponse,
125
105
  isAuthError: () => isAuthError,
126
106
  isContentError: () => isContentError,
127
- isErrorOfCategory: () => isErrorOfCategory,
128
107
  isMediaError: () => isMediaError,
129
108
  isNetworkError: () => isNetworkError,
130
109
  isPlatformError: () => isPlatformError,
@@ -4213,162 +4192,6 @@ SupportedPlatformSchema.describe("Currently supported social media platforms");
4213
4192
  function isPlatformSupported(platform) {
4214
4193
  return SUPPORTED_PLATFORMS.includes(platform);
4215
4194
  }
4216
- var ApiResponseSchema = z.object({
4217
- data: z.any().describe("Response data"),
4218
- meta: z.object({
4219
- rateLimit: z.object({
4220
- remaining: z.number().describe("Number of requests remaining in the current window"),
4221
- limit: z.number().describe("Total number of requests allowed in the window"),
4222
- reset: z.number().describe("Timestamp when the rate limit resets (in seconds since epoch)")
4223
- }).optional().describe("Rate limit information"),
4224
- pagination: z.object({
4225
- page: z.number().describe("Current page number"),
4226
- perPage: z.number().describe("Number of items per page"),
4227
- total: z.number().describe("Total number of items"),
4228
- totalPages: z.number().describe("Total number of pages"),
4229
- nextCursor: z.string().optional().describe("Next page cursor (if applicable)"),
4230
- prevCursor: z.string().optional().describe("Previous page cursor (if applicable)")
4231
- }).optional().describe("Pagination information")
4232
- }).optional().describe("Response metadata")
4233
- }).describe("Standard API response");
4234
- var ErrorResponseSchema = z.object({
4235
- error: z.object({
4236
- type: z.string().describe("Error type"),
4237
- message: z.string().describe("Error message"),
4238
- code: z.string().optional().describe("Error code (if applicable)"),
4239
- details: z.any().optional().describe("Additional error details")
4240
- }).describe("Error information")
4241
- }).describe("Error response");
4242
- var EnhancedResponseMetaSchema = z.object({
4243
- requestId: z.string().optional().describe("Unique request identifier"),
4244
- timestamp: z.string().optional().describe("Request timestamp"),
4245
- rateLimit: z.object({
4246
- remaining: z.number().describe("Number of requests remaining in the current window"),
4247
- limit: z.number().describe("Total number of requests allowed in the window"),
4248
- reset: z.number().describe("Timestamp when the rate limit resets (in seconds since epoch)")
4249
- }).optional().describe("Rate limit information"),
4250
- pagination: z.object({
4251
- page: z.number().describe("Current page number"),
4252
- perPage: z.number().describe("Number of items per page"),
4253
- total: z.number().describe("Total number of items"),
4254
- totalPages: z.number().describe("Total number of pages"),
4255
- nextCursor: z.string().optional().describe("Next page cursor (if applicable)"),
4256
- prevCursor: z.string().optional().describe("Previous page cursor (if applicable)")
4257
- }).optional().describe("Pagination information")
4258
- }).optional().describe("Response metadata");
4259
- var ErrorDetailSchema = z.object({
4260
- platform: z.string().optional().describe("Platform associated with the error (if applicable)"),
4261
- userId: z.string().optional().describe("User ID associated with the error (if applicable)"),
4262
- status: z.literal("error").describe("Error status"),
4263
- error: z.string().describe("Human-readable error message"),
4264
- errorCode: z.string().describe("Machine-readable error code"),
4265
- recoverable: z.boolean().describe("Whether the error is recoverable (can be retried)"),
4266
- details: z.record(z.any()).optional().describe("Additional error details (platform-specific)")
4267
- }).describe("Error detail");
4268
- var EnhancedErrorResponseSchema = z.object({
4269
- success: z.literal(false).describe("Success indicator (always false for error responses)"),
4270
- errors: z.array(ErrorDetailSchema).describe("Error information")
4271
- }).describe("Enhanced error response");
4272
- var SuccessDetailSchema = z.object({
4273
- platform: z.string().describe("Platform associated with the success"),
4274
- userId: z.string().describe("User ID associated with the success"),
4275
- status: z.literal("success").describe("Success status"),
4276
- postId: z.string().optional().describe("Post ID (if applicable)"),
4277
- postUrl: z.string().optional().describe("Post URL (if applicable)")
4278
- }).catchall(z.any()).describe("Success detail");
4279
- var MultiStatusResponseSchema = z.object({
4280
- success: z.boolean().describe("Success indicator (true if at least one operation succeeded)"),
4281
- data: z.object({
4282
- summary: z.object({
4283
- total: z.number().describe("Total number of operations"),
4284
- succeeded: z.number().describe("Number of successful operations"),
4285
- failed: z.number().describe("Number of failed operations")
4286
- }).describe("Summary of operations"),
4287
- results: z.array(SuccessDetailSchema).describe("Successful results"),
4288
- errors: z.array(ErrorDetailSchema).describe("Failed results")
4289
- }).describe("Response data")
4290
- }).describe("Multi-status response");
4291
- function EnhancedResponseSchema(schema) {
4292
- return z.object({
4293
- success: z.boolean().describe("Whether the request was successful"),
4294
- data: schema,
4295
- meta: EnhancedResponseMetaSchema
4296
- });
4297
- }
4298
- function createEnhancedApiResponse(data, meta) {
4299
- return {
4300
- success: true,
4301
- data,
4302
- meta
4303
- };
4304
- }
4305
- function createApiResponse(data, meta) {
4306
- return {
4307
- data,
4308
- meta
4309
- };
4310
- }
4311
- function createErrorResponse(type, message, code, details) {
4312
- return {
4313
- error: {
4314
- type,
4315
- message,
4316
- ...code ? { code } : {},
4317
- ...details ? { details } : {}
4318
- }
4319
- };
4320
- }
4321
- function createEnhancedErrorResponse(errors) {
4322
- return {
4323
- success: false,
4324
- errors
4325
- };
4326
- }
4327
- function createErrorDetail(error, errorCode, recoverable, platform, userId, details) {
4328
- return {
4329
- platform,
4330
- userId,
4331
- status: "error",
4332
- error,
4333
- errorCode,
4334
- recoverable,
4335
- details
4336
- };
4337
- }
4338
- function createSuccessDetail(platform, userId, additionalData) {
4339
- return {
4340
- platform,
4341
- userId,
4342
- status: "success",
4343
- ...additionalData
4344
- };
4345
- }
4346
- function createMultiStatusResponse(results, errors) {
4347
- const total = results.length + errors.length;
4348
- const succeeded = results.length;
4349
- const failed = errors.length;
4350
- return {
4351
- success: succeeded > 0,
4352
- data: {
4353
- summary: {
4354
- total,
4355
- succeeded,
4356
- failed
4357
- },
4358
- results,
4359
- errors
4360
- }
4361
- };
4362
- }
4363
- var BaseError = class extends Error {
4364
- constructor(message) {
4365
- super(message);
4366
- this.name = this.constructor.name;
4367
- if (Error.captureStackTrace) {
4368
- Error.captureStackTrace(this, this.constructor);
4369
- }
4370
- }
4371
- };
4372
4195
  var ApiErrorCode = /* @__PURE__ */ ((ApiErrorCode2) => {
4373
4196
  ApiErrorCode2["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
4374
4197
  ApiErrorCode2["INTERNAL_ERROR"] = "INTERNAL_ERROR";
@@ -4383,120 +4206,133 @@ var ApiErrorCode = /* @__PURE__ */ ((ApiErrorCode2) => {
4383
4206
  ApiErrorCode2["CONTENT_POLICY_VIOLATION"] = "CONTENT_POLICY_VIOLATION";
4384
4207
  ApiErrorCode2["DUPLICATE_CONTENT"] = "DUPLICATE_CONTENT";
4385
4208
  ApiErrorCode2["MEDIA_UPLOAD_FAILED"] = "MEDIA_UPLOAD_FAILED";
4209
+ ApiErrorCode2["MULTI_STATUS"] = "MULTI_STATUS";
4386
4210
  ApiErrorCode2["POST_CREATION_FAILED"] = "POST_CREATION_FAILED";
4387
4211
  ApiErrorCode2["THREAD_CREATION_FAILED"] = "THREAD_CREATION_FAILED";
4388
4212
  ApiErrorCode2["POST_DELETION_FAILED"] = "POST_DELETION_FAILED";
4389
4213
  ApiErrorCode2["POST_INTERACTION_FAILED"] = "POST_INTERACTION_FAILED";
4390
4214
  ApiErrorCode2["NETWORK_ERROR"] = "NETWORK_ERROR";
4391
- ApiErrorCode2["MULTI_STATUS"] = "MULTI_STATUS";
4392
4215
  return ApiErrorCode2;
4393
4216
  })(ApiErrorCode || {});
4394
- var ApiError = class _ApiError extends BaseError {
4395
- constructor(message, code = "INTERNAL_ERROR", status = 500, details, recoverable = false) {
4396
- super(message);
4397
- this.code = code;
4398
- this.status = status;
4399
- this.details = details;
4400
- this.recoverable = recoverable;
4401
- }
4402
- /**
4403
- * Create a validation error
4404
- */
4405
- static validation(message, details) {
4406
- return new _ApiError(
4407
- message,
4408
- "VALIDATION_ERROR",
4409
- 400,
4410
- details,
4411
- true
4412
- );
4413
- }
4414
- /**
4415
- * Create an unauthorized error
4416
- */
4417
- static unauthorized(message = "Unauthorized") {
4418
- return new _ApiError(
4419
- message,
4420
- "UNAUTHORIZED",
4421
- 401,
4422
- void 0,
4423
- true
4424
- );
4425
- }
4426
- /**
4427
- * Create a forbidden error
4428
- */
4429
- static forbidden(message = "Forbidden") {
4430
- return new _ApiError(
4431
- message,
4432
- "FORBIDDEN",
4433
- 403,
4434
- void 0,
4435
- false
4436
- );
4437
- }
4438
- /**
4439
- * Create a not found error
4440
- */
4441
- static notFound(message = "Resource not found") {
4442
- return new _ApiError(
4443
- message,
4444
- "NOT_FOUND",
4445
- 404,
4446
- void 0,
4447
- false
4448
- );
4449
- }
4450
- /**
4451
- * Create a rate limit error
4452
- */
4453
- static rateLimited(message = "Rate limit exceeded", details) {
4454
- return new _ApiError(
4455
- message,
4456
- "RATE_LIMITED",
4457
- 429,
4458
- details,
4459
- true
4460
- );
4461
- }
4462
- /**
4463
- * Create an internal server error
4464
- */
4465
- static internal(message = "Internal server error", details) {
4466
- return new _ApiError(
4467
- message,
4468
- "INTERNAL_ERROR",
4469
- 500,
4470
- details,
4471
- false
4472
- );
4473
- }
4474
- };
4475
- var PlatformError = class extends Error {
4476
- constructor(message, platform, code = "PLATFORM_ERROR", recoverable = false, originalError, status, userId, details) {
4477
- super(message);
4478
- this.originalError = originalError;
4479
- this.status = status;
4480
- this.name = "PlatformError";
4481
- this.code = code;
4482
- this.recoverable = recoverable;
4483
- this.platform = platform;
4484
- this.userId = userId;
4485
- this.details = details;
4486
- }
4487
- };
4488
- var CompositeApiError = class extends ApiError {
4489
- constructor(message, errors, status = 207, details, recoverable = false) {
4490
- super(
4491
- message,
4492
- "MULTI_STATUS",
4493
- status,
4494
- { ...details, errors },
4495
- recoverable
4496
- );
4497
- this.errors = errors;
4498
- }
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
4499
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
+ });
4500
4336
  var PlatformParamSchema = z.object({
4501
4337
  platform: z.string().describe("Social media platform")
4502
4338
  }).describe("Platform parameter");
@@ -4506,44 +4342,37 @@ var AuthInitRequestSchema = z.object({
4506
4342
  ),
4507
4343
  errorUrl: z.string().url().optional().describe("URL to redirect to on authentication error")
4508
4344
  }).describe("Auth initialization request");
4509
- var AuthUrlResponseSchema = EnhancedResponseSchema(
4510
- z.object({
4511
- url: z.string().describe("Authentication URL to redirect the user to"),
4512
- state: z.string().describe("State parameter for CSRF protection"),
4513
- platform: PlatformSchema
4514
- })
4515
- ).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");
4516
4350
  var AuthCallbackQuerySchema = z.object({
4517
4351
  code: z.string().describe("Authorization code from OAuth provider"),
4518
4352
  state: z.string().describe("State parameter for CSRF protection")
4519
4353
  }).describe("Auth callback query");
4520
- var AuthCallbackResponseSchema = EnhancedResponseSchema(
4521
- z.object({
4522
- success: z.boolean().describe("Whether the authentication was successful"),
4523
- platform: PlatformSchema,
4524
- userId: z.string().describe("User ID"),
4525
- redirectUrl: z.string().optional().describe("URL to redirect the user to after authentication")
4526
- })
4527
- ).describe("Auth callback response");
4528
- var AuthStatusResponseSchema = EnhancedResponseSchema(
4529
- z.object({
4530
- platform: PlatformSchema,
4531
- userId: z.string().describe("User ID"),
4532
- authenticated: z.boolean().describe("Whether the user is authenticated"),
4533
- tokenStatus: z.object({
4534
- valid: z.boolean().describe("Whether the token is valid"),
4535
- expired: z.boolean().describe("Whether the token is expired"),
4536
- expiresAt: z.string().optional().describe("When the token expires")
4537
- })
4538
- })
4539
- ).describe("Auth status response");
4540
- var AuthRevokeResponseSchema = EnhancedResponseSchema(
4541
- z.object({
4542
- success: z.boolean().describe("Whether the revocation was successful"),
4543
- platform: PlatformSchema,
4544
- 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")
4545
4367
  })
4546
- ).describe("Auth revoke response");
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");
4547
4376
  var ConnectedAccountSchema = z.object({
4548
4377
  platform: PlatformSchema,
4549
4378
  userId: z.string().describe("User ID on the platform"),
@@ -4551,26 +4380,21 @@ var ConnectedAccountSchema = z.object({
4551
4380
  profileUrl: z.string().optional().describe("URL to the user profile"),
4552
4381
  connectedAt: z.string().optional().describe("When the account was connected")
4553
4382
  }).describe("Connected account");
4554
- var ConnectedAccountsResponseSchema = EnhancedResponseSchema(
4555
- z.array(ConnectedAccountSchema)
4556
- ).describe("Connected accounts response");
4383
+ var ConnectedAccountsResponseSchema = z.array(ConnectedAccountSchema).describe(
4384
+ "Connected accounts response"
4385
+ );
4557
4386
  var NearAuthorizationRequestSchema = z.object({
4558
4387
  // No additional parameters needed, as the NEAR account ID is extracted from the signature
4559
4388
  }).describe("NEAR authorization request");
4560
- var NearAuthorizationResponseSchema = EnhancedResponseSchema(
4561
- z.object({
4562
- success: z.boolean().describe("Whether the authorization was successful"),
4563
- nearAccount: z.string().describe("NEAR account ID"),
4564
- authorized: z.boolean().describe("Whether the account is authorized")
4565
- })
4566
- ).describe("NEAR authorization response");
4567
- var NearAuthorizationStatusResponseSchema = EnhancedResponseSchema(
4568
- z.object({
4569
- nearAccount: z.string().describe("NEAR account ID"),
4570
- authorized: z.boolean().describe("Whether the account is authorized"),
4571
- authorizedAt: z.string().optional().describe("When the account was authorized")
4572
- })
4573
- ).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");
4574
4398
  var MediaContentSchema = z.object({
4575
4399
  data: z.union([z.string(), z.instanceof(Blob)]).describe("Media data as string or Blob"),
4576
4400
  mimeType: z.string().optional().describe("Media MIME type"),
@@ -4685,65 +4509,33 @@ var UnlikePostRequestSchema = z.object({
4685
4509
  platform: PlatformSchema.describe("Platform of the post being unliked"),
4686
4510
  postId: z.string().describe("ID of the post to unlike")
4687
4511
  }).describe("Unlike post request");
4688
- var PostResponseSchema = EnhancedResponseSchema(
4689
- z.union([PostSchema, z.array(PostSchema)])
4690
- ).describe("Post response");
4691
- var CreatePostResponseLegacySchema = PostResponseSchema.describe(
4692
- "Create post response (legacy)"
4512
+ var PostResponseSchema = z.union([PostSchema, z.array(PostSchema)]).describe(
4513
+ "Post response"
4514
+ );
4515
+ var CreatePostResponseSchema = PostResponseSchema.describe(
4516
+ "Create post response"
4693
4517
  );
4694
4518
  var RepostResponseSchema = PostResponseSchema.describe("Repost response");
4695
4519
  var QuotePostResponseSchema = PostResponseSchema.describe("Quote post response");
4696
4520
  var ReplyToPostResponseSchema = PostResponseSchema.describe("Reply to post response");
4697
- var DeletePostResponseSchema = EnhancedResponseSchema(
4698
- z.object({
4699
- success: z.boolean().describe("Whether the deletion was successful"),
4700
- id: z.string().describe("ID of the deleted post")
4701
- })
4702
- ).describe("Delete post response");
4703
- var LikePostResponseSchema = EnhancedResponseSchema(
4704
- z.object({
4705
- success: z.boolean().describe("Whether the like was successful"),
4706
- id: z.string().describe("ID of the liked post")
4707
- })
4708
- ).describe("Like post response");
4709
- var UnlikePostResponseSchema = EnhancedResponseSchema(
4710
- z.object({
4711
- success: z.boolean().describe("Whether the unlike was successful"),
4712
- id: z.string().describe("ID of the unliked post")
4713
- })
4714
- ).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");
4715
4530
  var PostMultiStatusResponseSchema = z.object({
4716
- success: z.boolean().describe("Whether the operation was partially or fully successful"),
4717
- data: z.object({
4718
- summary: z.object({
4719
- total: z.number().describe("Total number of operations"),
4720
- succeeded: z.number().describe("Number of successful operations"),
4721
- failed: z.number().describe("Number of failed operations")
4722
- }),
4723
- results: z.array(PostSuccessDetailSchema).describe("Successful operations"),
4724
- errors: z.array(ErrorDetailSchema).describe("Failed operations")
4725
- })
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")
4726
4538
  }).describe("Multi-status response for post operations");
4727
- var CreatePostTargetResultSchema = z.object({
4728
- platform: PlatformSchema.describe("The platform the post was created on"),
4729
- userId: z.string().describe("The user ID on the platform"),
4730
- result: z.array(z.any()).describe("The result of the post creation")
4731
- }).describe("Create post target result");
4732
- var CreatePostTargetErrorSchema = z.object({
4733
- platform: PlatformSchema.optional().describe(
4734
- "The platform where the error occurred (if applicable)"
4735
- ),
4736
- userId: z.string().optional().describe("The user ID where the error occurred (if applicable)"),
4737
- error: z.string().describe("The error message")
4738
- }).describe("Create post target error");
4739
- var CreatePostResponseSchema = EnhancedResponseSchema(
4740
- z.object({
4741
- results: z.array(CreatePostTargetResultSchema).describe("Array of successful post results"),
4742
- errors: z.array(CreatePostTargetErrorSchema).optional().describe(
4743
- "Array of errors that occurred (if any)"
4744
- )
4745
- })
4746
- ).describe("Create post response");
4747
4539
  var RateLimitEndpointParamSchema = z.object({
4748
4540
  endpoint: z.string().optional().describe(
4749
4541
  "Specific endpoint to get rate limit information for (optional)"
@@ -4778,43 +4570,39 @@ var UsageRateLimitSchema = z.object({
4778
4570
  resetSeconds: z.number().describe("Seconds until the rate limit will reset"),
4779
4571
  timeWindow: z.string().describe("Time window for the rate limit")
4780
4572
  }).describe("Usage rate limit");
4781
- var RateLimitStatusResponseSchema = EnhancedResponseSchema(
4782
- z.object({
4783
- platform: PlatformSchema,
4784
- userId: z.string().optional().describe("User ID"),
4785
- endpoints: z.array(RateLimitEndpointSchema).describe("Rate limits for specific endpoints"),
4786
- app: z.object({
4787
- limit: z.number().describe("App-wide rate limit"),
4788
- remaining: z.number().describe("Remaining requests"),
4789
- reset: z.number().describe("Reset timestamp (Unix timestamp in seconds)"),
4790
- resetDate: z.string().describe("Reset date (ISO string)")
4791
- }).optional().describe("App-wide rate limits")
4792
- })
4793
- ).describe("Rate limit status response");
4794
- var AllRateLimitsResponseSchema = EnhancedResponseSchema(
4795
- z.object({
4796
- platforms: z.record(
4797
- PlatformSchema,
4798
- z.object({
4799
- users: z.record(
4800
- z.string(),
4801
- z.object({
4802
- endpoints: z.array(RateLimitEndpointSchema).describe(
4803
- "Rate limits for specific endpoints"
4804
- ),
4805
- lastUpdated: z.string().describe("Last updated date (ISO string)")
4806
- })
4807
- ).describe("User-specific rate limits"),
4808
- app: z.object({
4809
- limit: z.number().describe("App-wide rate limit"),
4810
- remaining: z.number().describe("Remaining requests"),
4811
- reset: z.number().describe("Reset timestamp (Unix timestamp in seconds)"),
4812
- resetDate: z.string().describe("Reset date (ISO string)")
4813
- }).optional().describe("App-wide rate limits")
4814
- })
4815
- ).describe("Rate limits by platform")
4816
- })
4817
- ).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");
4818
4606
  var RateLimitResponseSchema = z.object({
4819
4607
  platformLimits: z.array(PlatformRateLimitSchema).describe("Platform-specific rate limits"),
4820
4608
  usageLimits: z.record(z.string(), UsageRateLimitSchema).describe(
@@ -4859,16 +4647,12 @@ var AccountActivityEntrySchema = z.object({
4859
4647
  rank: z.number().describe("Rank on the leaderboard"),
4860
4648
  lastActive: z.string().datetime().describe("Timestamp of last activity")
4861
4649
  }).describe("Account activity entry");
4862
- var ActivityLeaderboardResponseSchema = EnhancedResponseSchema(
4863
- z.object({
4864
- timeframe: z.nativeEnum(TimePeriod).describe("Timeframe for the leaderboard"),
4865
- entries: z.array(AccountActivityEntrySchema).describe("Leaderboard entries"),
4866
- total: z.number().describe("Total number of entries in the leaderboard"),
4867
- limit: z.number().describe("Maximum number of results returned"),
4868
- offset: z.number().describe("Offset for pagination"),
4869
- generatedAt: z.string().datetime().describe("Timestamp when the leaderboard was generated")
4870
- })
4871
- ).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
+ });
4872
4656
  var AccountActivityParamsSchema = z.object({
4873
4657
  signerId: z.string().describe("NEAR account ID")
4874
4658
  }).describe("Account activity params");
@@ -4887,21 +4671,19 @@ var PlatformActivitySchema = z.object({
4887
4671
  score: z.number().describe("Activity score on this platform"),
4888
4672
  lastActive: z.string().datetime().describe("Timestamp of last activity on this platform")
4889
4673
  }).describe("Platform activity");
4890
- var AccountActivityResponseSchema = EnhancedResponseSchema(
4891
- z.object({
4892
- signerId: z.string().describe("NEAR account ID"),
4893
- timeframe: z.nativeEnum(TimePeriod).describe("Timeframe for the activity"),
4894
- totalPosts: z.number().describe("Total number of posts across all platforms"),
4895
- totalLikes: z.number().describe("Total number of likes across all platforms"),
4896
- totalReposts: z.number().describe("Total number of reposts across all platforms"),
4897
- totalReplies: z.number().describe("Total number of replies across all platforms"),
4898
- totalQuotes: z.number().describe("Total number of quote posts across all platforms"),
4899
- totalScore: z.number().describe("Total activity score across all platforms"),
4900
- rank: z.number().describe("Rank on the leaderboard"),
4901
- lastActive: z.string().datetime().describe("Timestamp of last activity across all platforms"),
4902
- platforms: z.array(PlatformActivitySchema).describe("Activity breakdown by platform")
4903
- })
4904
- ).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
+ });
4905
4687
  var AccountPostsParamsSchema = z.object({
4906
4688
  signerId: z.string().describe("NEAR account ID")
4907
4689
  }).describe("Account posts params");
@@ -4929,19 +4711,14 @@ var AccountPostSchema = z.object({
4929
4711
  inReplyToId: z.string().optional().describe("ID of the post this is a reply to (if applicable)"),
4930
4712
  quotedPostId: z.string().optional().describe("ID of the post this is quoting (if applicable)")
4931
4713
  }).describe("Account post");
4932
- var AccountPostsResponseSchema = EnhancedResponseSchema(
4933
- z.object({
4934
- signerId: z.string().describe("NEAR account ID"),
4935
- posts: z.array(AccountPostSchema).describe("List of posts"),
4936
- total: z.number().describe("Total number of posts matching the query"),
4937
- limit: z.number().describe("Maximum number of results returned"),
4938
- offset: z.number().describe("Offset for pagination"),
4939
- platform: z.string().optional().describe("Platform filter (if applied)"),
4940
- type: z.enum(["post", "repost", "reply", "quote", "like", "all"]).optional().describe(
4941
- "Post type filter (if applied)"
4942
- )
4943
- })
4944
- ).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
+ });
4945
4722
  var UserProfileSchema = z.object({
4946
4723
  userId: z.string().describe("User ID on the platform"),
4947
4724
  username: z.string().describe("Username on the platform"),
@@ -4951,118 +4728,107 @@ var UserProfileSchema = z.object({
4951
4728
  platform: PlatformSchema.describe("The platform the user profile is from"),
4952
4729
  lastUpdated: z.number().describe("Timestamp when the profile was last updated")
4953
4730
  }).describe("User profile");
4954
- var ProfileRefreshResultSchema = z.object({
4955
- success: z.boolean().describe("Whether the profile refresh was successful"),
4956
- profile: UserProfileSchema.optional().describe("The refreshed user profile (if successful)"),
4957
- error: z.string().optional().describe("Error message (if unsuccessful)")
4958
- }).describe("Profile refresh result");
4959
- var ProfileRefreshResponseSchema = EnhancedResponseSchema(
4960
- ProfileRefreshResultSchema
4961
- ).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");
4962
4734
 
4963
4735
  // src/core/request.ts
4964
4736
  var import_near_sign_verify = require("near-sign-verify");
4965
4737
 
4966
4738
  // src/utils/error.ts
4967
- var ERROR_CATEGORIES = {
4968
- AUTH: [
4969
- ApiErrorCode.UNAUTHORIZED,
4970
- ApiErrorCode.FORBIDDEN
4971
- ],
4972
- VALIDATION: [
4973
- ApiErrorCode.VALIDATION_ERROR,
4974
- ApiErrorCode.INVALID_REQUEST
4975
- ],
4976
- NETWORK: [
4977
- ApiErrorCode.NETWORK_ERROR
4978
- ],
4979
- PLATFORM: [
4980
- ApiErrorCode.PLATFORM_ERROR,
4981
- ApiErrorCode.PLATFORM_UNAVAILABLE
4982
- ],
4983
- CONTENT: [
4984
- ApiErrorCode.CONTENT_POLICY_VIOLATION,
4985
- ApiErrorCode.DUPLICATE_CONTENT
4986
- ],
4987
- RATE_LIMIT: [
4988
- ApiErrorCode.RATE_LIMITED
4989
- ],
4990
- POST: [
4991
- ApiErrorCode.POST_CREATION_FAILED,
4992
- ApiErrorCode.THREAD_CREATION_FAILED,
4993
- ApiErrorCode.POST_DELETION_FAILED,
4994
- ApiErrorCode.POST_INTERACTION_FAILED
4995
- ],
4996
- MEDIA: [
4997
- ApiErrorCode.MEDIA_UPLOAD_FAILED
4998
- ]
4999
- };
5000
- function isErrorOfCategory(error, category) {
5001
- if (error instanceof ApiError) {
5002
- 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;
5003
4747
  }
5004
- if (error instanceof PlatformError) {
5005
- return category.includes(error.code);
4748
+ /**
4749
+ * Get platform from details if available
4750
+ */
4751
+ get platform() {
4752
+ return this.details?.platform;
5006
4753
  }
5007
- if (error && typeof error === "object" && "code" in error) {
5008
- return category.includes(error.code);
4754
+ /**
4755
+ * Get userId from details if available
4756
+ */
4757
+ get userId() {
4758
+ return this.details?.userId;
5009
4759
  }
5010
- return false;
4760
+ };
4761
+ function isErrorCode(error, codes) {
4762
+ return error instanceof CrosspostError && codes.includes(error.code);
5011
4763
  }
5012
4764
  function isAuthError(error) {
5013
- return isErrorOfCategory(error, ERROR_CATEGORIES.AUTH);
4765
+ return isErrorCode(error, [
4766
+ ApiErrorCode.UNAUTHORIZED,
4767
+ ApiErrorCode.FORBIDDEN
4768
+ ]);
5014
4769
  }
5015
4770
  function isValidationError(error) {
5016
- return isErrorOfCategory(error, ERROR_CATEGORIES.VALIDATION);
4771
+ return isErrorCode(error, [
4772
+ ApiErrorCode.VALIDATION_ERROR,
4773
+ ApiErrorCode.INVALID_REQUEST
4774
+ ]);
5017
4775
  }
5018
4776
  function isNetworkError(error) {
5019
- return isErrorOfCategory(error, ERROR_CATEGORIES.NETWORK);
4777
+ return isErrorCode(error, [
4778
+ ApiErrorCode.NETWORK_ERROR,
4779
+ ApiErrorCode.PLATFORM_UNAVAILABLE
4780
+ ]);
5020
4781
  }
5021
4782
  function isPlatformError(error) {
5022
- return isErrorOfCategory(error, ERROR_CATEGORIES.PLATFORM) || error instanceof PlatformError;
4783
+ return error instanceof CrosspostError && !!error.details?.platform;
5023
4784
  }
5024
4785
  function isContentError(error) {
5025
- return isErrorOfCategory(error, ERROR_CATEGORIES.CONTENT);
4786
+ return isErrorCode(error, [
4787
+ ApiErrorCode.CONTENT_POLICY_VIOLATION,
4788
+ ApiErrorCode.DUPLICATE_CONTENT
4789
+ ]);
5026
4790
  }
5027
4791
  function isRateLimitError(error) {
5028
- return isErrorOfCategory(error, ERROR_CATEGORIES.RATE_LIMIT);
4792
+ return isErrorCode(error, [ApiErrorCode.RATE_LIMITED]);
5029
4793
  }
5030
4794
  function isPostError(error) {
5031
- return isErrorOfCategory(error, ERROR_CATEGORIES.POST);
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
+ ]);
5032
4801
  }
5033
4802
  function isMediaError(error) {
5034
- return isErrorOfCategory(error, ERROR_CATEGORIES.MEDIA);
4803
+ return isErrorCode(error, [ApiErrorCode.MEDIA_UPLOAD_FAILED]);
5035
4804
  }
5036
4805
  function isRecoverableError(error) {
5037
- if (error instanceof ApiError || error instanceof PlatformError) {
5038
- return error.recoverable;
5039
- }
5040
- return false;
4806
+ return error instanceof CrosspostError && error.recoverable;
5041
4807
  }
5042
4808
  function getErrorMessage(error, defaultMessage = "An error occurred") {
5043
4809
  if (error instanceof Error) {
5044
4810
  return error.message || defaultMessage;
5045
4811
  }
5046
- if (typeof error === "string") {
5047
- return error;
5048
- }
5049
- if (error && typeof error === "object" && "message" in error) {
5050
- return error.message || defaultMessage;
5051
- }
5052
4812
  return defaultMessage;
5053
4813
  }
5054
4814
  function getErrorDetails(error) {
5055
- if (error instanceof ApiError || error instanceof PlatformError) {
5056
- return error.details;
5057
- }
5058
- if (error && typeof error === "object" && "details" in error) {
4815
+ if (error instanceof CrosspostError) {
5059
4816
  return error.details;
5060
4817
  }
5061
4818
  return void 0;
5062
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
+ }
5063
4829
  function enrichErrorWithContext(error, context) {
5064
- if (error instanceof ApiError) {
5065
- return new ApiError(
4830
+ if (error instanceof CrosspostError) {
4831
+ return createError(
5066
4832
  error.message,
5067
4833
  error.code,
5068
4834
  error.status,
@@ -5070,25 +4836,12 @@ function enrichErrorWithContext(error, context) {
5070
4836
  error.recoverable
5071
4837
  );
5072
4838
  }
5073
- if (error instanceof PlatformError) {
5074
- return new PlatformError(
5075
- error.message,
5076
- error.platform,
5077
- error.code,
5078
- error.recoverable,
5079
- error.originalError,
5080
- error.status,
5081
- error.userId,
5082
- { ...error.details || {}, ...context }
5083
- );
5084
- }
5085
4839
  const errorMessage = error instanceof Error ? error.message : String(error);
5086
- return new ApiError(
4840
+ return createError(
5087
4841
  errorMessage || "An error occurred",
5088
4842
  ApiErrorCode.INTERNAL_ERROR,
5089
4843
  500,
5090
- { originalError: error, ...context },
5091
- false
4844
+ { originalError: error, ...context }
5092
4845
  );
5093
4846
  }
5094
4847
  async function apiWrapper(apiCall, context) {
@@ -5105,7 +4858,7 @@ async function apiWrapper(apiCall, context) {
5105
4858
  } catch (jsonError) {
5106
4859
  if (jsonError instanceof Error && jsonError.name === "SyntaxError") {
5107
4860
  throw enrichErrorWithContext(
5108
- new ApiError(
4861
+ createError(
5109
4862
  `API request failed with status ${error.status} and non-JSON response`,
5110
4863
  ApiErrorCode.NETWORK_ERROR,
5111
4864
  error.status,
@@ -5117,7 +4870,7 @@ async function apiWrapper(apiCall, context) {
5117
4870
  throw jsonError;
5118
4871
  }
5119
4872
  }
5120
- if (error instanceof ApiError || error instanceof PlatformError) {
4873
+ if (error instanceof CrosspostError) {
5121
4874
  throw enrichErrorWithContext(error, context || {});
5122
4875
  }
5123
4876
  throw enrichErrorWithContext(
@@ -5127,80 +4880,68 @@ async function apiWrapper(apiCall, context) {
5127
4880
  }
5128
4881
  }
5129
4882
  function handleErrorResponse(data, status) {
5130
- if (data?.errors && Array.isArray(data.errors)) {
5131
- if (data.errors.length === 1) {
5132
- const errorDetail = data.errors[0];
5133
- if (errorDetail.platform && Object.values(Platform).includes(errorDetail.platform)) {
5134
- return new PlatformError(
5135
- errorDetail.message,
5136
- errorDetail.platform,
5137
- errorDetail.code,
5138
- errorDetail.recoverable ?? false,
5139
- void 0,
5140
- status,
5141
- errorDetail.userId,
5142
- errorDetail.details
5143
- );
5144
- } else {
5145
- return new ApiError(
5146
- errorDetail.message,
5147
- errorDetail.code,
5148
- status,
5149
- errorDetail.details,
5150
- errorDetail.recoverable ?? false
5151
- );
5152
- }
5153
- } else if (data.errors.length > 1) {
5154
- return new CompositeApiError(
5155
- "Multiple errors occurred",
5156
- data.errors,
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,
5157
4905
  status,
5158
4906
  { originalResponse: data }
5159
4907
  );
5160
4908
  }
5161
- }
5162
- const errorData = data?.error || {};
5163
- const message = errorData?.message || data?.message || "An API error occurred";
5164
- const codeString = errorData?.code || data?.code || ApiErrorCode.UNKNOWN_ERROR;
5165
- const code = Object.values(ApiErrorCode).includes(codeString) ? codeString : ApiErrorCode.UNKNOWN_ERROR;
5166
- const details = errorData?.details || data?.details || {};
5167
- const recoverable = errorData?.recoverable ?? data?.recoverable ?? false;
5168
- const platform = errorData?.platform || data?.platform;
5169
- const enhancedDetails = { ...details };
5170
- if (typeof enhancedDetails === "object" && !enhancedDetails.originalResponse) {
5171
- enhancedDetails.originalResponse = data;
5172
- }
5173
- if (platform && Object.values(Platform).includes(platform)) {
5174
- return new PlatformError(
5175
- message,
5176
- platform,
5177
- code,
5178
- recoverable,
5179
- void 0,
4909
+ const finalDetails = {
4910
+ ...errorDetail.details || {},
4911
+ ...data.meta || {}
4912
+ };
4913
+ return createError(
4914
+ errorDetail.message,
4915
+ errorDetail.code,
5180
4916
  status,
5181
- void 0,
5182
- enhancedDetails
4917
+ finalDetails,
4918
+ errorDetail.recoverable ?? false
5183
4919
  );
5184
4920
  } else {
5185
- return new ApiError(
5186
- message,
5187
- code,
4921
+ const firstError = data.errors[0];
4922
+ return createError(
4923
+ "Multiple errors occurred",
4924
+ firstError.code,
5188
4925
  status,
5189
- enhancedDetails,
5190
- recoverable
4926
+ {
4927
+ errors: data.errors,
4928
+ ...data.meta || {},
4929
+ originalResponse: data
4930
+ },
4931
+ false
5191
4932
  );
5192
4933
  }
5193
4934
  }
5194
4935
  function createNetworkError(error, url, timeout) {
5195
4936
  if (error instanceof DOMException && error.name === "AbortError") {
5196
- return new ApiError(
4937
+ return createError(
5197
4938
  `Request timed out after ${timeout}ms`,
5198
4939
  ApiErrorCode.NETWORK_ERROR,
5199
4940
  408,
5200
4941
  { url }
5201
4942
  );
5202
4943
  }
5203
- return new ApiError(
4944
+ return createError(
5204
4945
  error instanceof Error ? error.message : "An unexpected error occurred during the request",
5205
4946
  ApiErrorCode.INTERNAL_ERROR,
5206
4947
  500,
@@ -5223,9 +4964,6 @@ async function makeRequest(method, path, options, data, query) {
5223
4964
  url += `?${queryString}`;
5224
4965
  }
5225
4966
  }
5226
- if (!options.nearAuthData) {
5227
- throw ApiError.unauthorized("Authentication required. Please provide NEAR signature.");
5228
- }
5229
4967
  const context = {
5230
4968
  method,
5231
4969
  path,
@@ -5256,15 +4994,14 @@ async function makeRequest(method, path, options, data, query) {
5256
4994
  responseData = await response.json();
5257
4995
  } catch (jsonError) {
5258
4996
  if (!response.ok) {
5259
- throw new ApiError(
4997
+ throw new CrosspostError(
5260
4998
  `API request failed with status ${response.status} and non-JSON response`,
5261
4999
  ApiErrorCode.NETWORK_ERROR,
5262
5000
  response.status,
5263
5001
  { originalStatusText: response.statusText }
5264
5002
  );
5265
5003
  }
5266
- if (response.status === 204) return {};
5267
- throw new ApiError(
5004
+ throw new CrosspostError(
5268
5005
  `Failed to parse JSON response: ${jsonError instanceof Error ? jsonError.message : String(jsonError)}`,
5269
5006
  ApiErrorCode.INTERNAL_ERROR,
5270
5007
  response.status
@@ -5272,23 +5009,26 @@ async function makeRequest(method, path, options, data, query) {
5272
5009
  }
5273
5010
  if (!response.ok) {
5274
5011
  lastError = handleErrorResponse(responseData, response.status);
5275
- const shouldRetry = response.status >= 500 || lastError instanceof ApiError && lastError.recoverable;
5012
+ const shouldRetry = lastError instanceof CrosspostError && lastError.code === ApiErrorCode.RATE_LIMITED;
5276
5013
  if (shouldRetry && attempt < options.retries) {
5277
5014
  await new Promise((resolve) => setTimeout(resolve, 1e3 * Math.pow(2, attempt)));
5278
5015
  continue;
5279
5016
  }
5280
5017
  throw lastError;
5281
5018
  }
5282
- if (responseData && typeof responseData === "object" && "success" in responseData && !responseData.success && responseData.error) {
5283
- lastError = handleErrorResponse(responseData, response.status);
5284
- const shouldRetry = lastError instanceof ApiError && lastError.recoverable;
5285
- if (shouldRetry && attempt < options.retries) {
5286
- await new Promise((resolve) => setTimeout(resolve, 1e3 * Math.pow(2, attempt)));
5287
- continue;
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;
5288
5030
  }
5289
- throw lastError;
5290
5031
  }
5291
- return responseData;
5292
5032
  } catch (error) {
5293
5033
  clearTimeout(timeoutId);
5294
5034
  lastError = error instanceof Error ? error : new Error(String(error));
@@ -5297,13 +5037,13 @@ async function makeRequest(method, path, options, data, query) {
5297
5037
  await new Promise((resolve) => setTimeout(resolve, 1e3 * Math.pow(2, attempt)));
5298
5038
  continue;
5299
5039
  }
5300
- if (!(error instanceof ApiError)) {
5040
+ if (!(error instanceof CrosspostError)) {
5301
5041
  throw createNetworkError(error, url, options.timeout);
5302
5042
  }
5303
5043
  throw error;
5304
5044
  }
5305
5045
  }
5306
- throw lastError || new ApiError("Request failed after multiple retries", ApiErrorCode.INTERNAL_ERROR, 500);
5046
+ throw lastError || new CrosspostError("Request failed after multiple retries", ApiErrorCode.INTERNAL_ERROR, 500);
5307
5047
  }, context);
5308
5048
  }
5309
5049
 
@@ -5539,7 +5279,7 @@ var PostApi = class {
5539
5279
  async likePost(request) {
5540
5280
  return makeRequest(
5541
5281
  "POST",
5542
- `/api/post/like/${request.postId}`,
5282
+ `/api/post/like`,
5543
5283
  this.options,
5544
5284
  request
5545
5285
  );
@@ -5552,7 +5292,7 @@ var PostApi = class {
5552
5292
  async unlikePost(request) {
5553
5293
  return makeRequest(
5554
5294
  "DELETE",
5555
- `/api/post/like/${request.postId}`,
5295
+ `/api/post/like`,
5556
5296
  this.options,
5557
5297
  request
5558
5298
  );
@@ -5563,17 +5303,9 @@ var PostApi = class {
5563
5303
  * @returns A promise resolving with the delete response.
5564
5304
  */
5565
5305
  async deletePost(request) {
5566
- const postId = request.posts[0]?.postId || "";
5567
- if (!postId) {
5568
- throw new ApiError(
5569
- "Post ID is required for deletion path",
5570
- ApiErrorCode.VALIDATION_ERROR,
5571
- 400
5572
- );
5573
- }
5574
5306
  return makeRequest(
5575
5307
  "DELETE",
5576
- `/api/post/${postId}`,
5308
+ `/api/post`,
5577
5309
  this.options,
5578
5310
  request
5579
5311
  );
@@ -5674,57 +5406,43 @@ var CrosspostClient = class {
5674
5406
  AccountActivityEntrySchema,
5675
5407
  AccountActivityParamsSchema,
5676
5408
  AccountActivityQuerySchema,
5677
- AccountActivityResponseSchema,
5678
5409
  AccountPostSchema,
5679
5410
  AccountPostsParamsSchema,
5680
5411
  AccountPostsQuerySchema,
5681
- AccountPostsResponseSchema,
5682
5412
  ActivityApi,
5683
5413
  ActivityLeaderboardQuerySchema,
5684
- ActivityLeaderboardResponseSchema,
5685
5414
  AllRateLimitsResponseSchema,
5686
- ApiError,
5687
5415
  ApiErrorCode,
5688
- ApiResponseSchema,
5416
+ ApiErrorCodeSchema,
5689
5417
  AuthApi,
5690
5418
  AuthCallbackQuerySchema,
5691
5419
  AuthCallbackResponseSchema,
5692
5420
  AuthInitRequestSchema,
5693
5421
  AuthRevokeResponseSchema,
5694
5422
  AuthStatusResponseSchema,
5423
+ AuthTokenRequestSchema,
5695
5424
  AuthUrlResponseSchema,
5696
- BaseError,
5697
- CompositeApiError,
5698
5425
  ConnectedAccountSchema,
5699
5426
  ConnectedAccountsResponseSchema,
5700
5427
  CreatePostRequestSchema,
5701
- CreatePostResponseLegacySchema,
5702
5428
  CreatePostResponseSchema,
5703
- CreatePostTargetErrorSchema,
5704
- CreatePostTargetResultSchema,
5705
5429
  CrosspostClient,
5706
5430
  DeletePostRequestSchema,
5707
5431
  DeletePostResponseSchema,
5708
5432
  DeleteResultSchema,
5709
- ERROR_CATEGORIES,
5710
5433
  EndpointRateLimitResponseSchema,
5711
- EnhancedErrorResponseSchema,
5712
- EnhancedResponseMetaSchema,
5713
- EnhancedResponseSchema,
5714
5434
  ErrorDetailSchema,
5715
- ErrorResponseSchema,
5716
5435
  LikePostRequestSchema,
5717
5436
  LikePostResponseSchema,
5718
5437
  LikeResultSchema,
5719
5438
  MediaContentSchema,
5720
5439
  MediaSchema,
5721
- MultiStatusResponseSchema,
5440
+ MultiStatusDataSchema,
5722
5441
  NearAuthorizationRequestSchema,
5723
5442
  NearAuthorizationResponseSchema,
5724
5443
  NearAuthorizationStatusResponseSchema,
5725
5444
  Platform,
5726
5445
  PlatformActivitySchema,
5727
- PlatformError,
5728
5446
  PlatformParamSchema,
5729
5447
  PlatformRateLimitSchema,
5730
5448
  PlatformSchema,
@@ -5738,7 +5456,6 @@ var CrosspostClient = class {
5738
5456
  PostSuccessDetailSchema,
5739
5457
  PostToDeleteSchema,
5740
5458
  ProfileRefreshResponseSchema,
5741
- ProfileRefreshResultSchema,
5742
5459
  QuotePostRequestSchema,
5743
5460
  QuotePostResponseSchema,
5744
5461
  RateLimitEndpointParamSchema,
@@ -5750,6 +5467,7 @@ var CrosspostClient = class {
5750
5467
  ReplyToPostResponseSchema,
5751
5468
  RepostRequestSchema,
5752
5469
  RepostResponseSchema,
5470
+ ResponseMetaSchema,
5753
5471
  SUPPORTED_PLATFORMS,
5754
5472
  SuccessDetailSchema,
5755
5473
  SupportedPlatformSchema,
@@ -5761,21 +5479,14 @@ var CrosspostClient = class {
5761
5479
  UsageRateLimitSchema,
5762
5480
  UserProfileSchema,
5763
5481
  apiWrapper,
5764
- createApiResponse,
5765
- createEnhancedApiResponse,
5766
- createEnhancedErrorResponse,
5767
- createErrorDetail,
5768
- createErrorResponse,
5769
- createMultiStatusResponse,
5770
5482
  createNetworkError,
5771
- createSuccessDetail,
5772
5483
  enrichErrorWithContext,
5484
+ errorCodeToStatusCode,
5773
5485
  getErrorDetails,
5774
5486
  getErrorMessage,
5775
5487
  handleErrorResponse,
5776
5488
  isAuthError,
5777
5489
  isContentError,
5778
- isErrorOfCategory,
5779
5490
  isMediaError,
5780
5491
  isNetworkError,
5781
5492
  isPlatformError,