@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.js
CHANGED
@@ -4075,162 +4075,6 @@ SupportedPlatformSchema.describe("Currently supported social media platforms");
|
|
4075
4075
|
function isPlatformSupported(platform) {
|
4076
4076
|
return SUPPORTED_PLATFORMS.includes(platform);
|
4077
4077
|
}
|
4078
|
-
var ApiResponseSchema = z.object({
|
4079
|
-
data: z.any().describe("Response data"),
|
4080
|
-
meta: z.object({
|
4081
|
-
rateLimit: z.object({
|
4082
|
-
remaining: z.number().describe("Number of requests remaining in the current window"),
|
4083
|
-
limit: z.number().describe("Total number of requests allowed in the window"),
|
4084
|
-
reset: z.number().describe("Timestamp when the rate limit resets (in seconds since epoch)")
|
4085
|
-
}).optional().describe("Rate limit information"),
|
4086
|
-
pagination: z.object({
|
4087
|
-
page: z.number().describe("Current page number"),
|
4088
|
-
perPage: z.number().describe("Number of items per page"),
|
4089
|
-
total: z.number().describe("Total number of items"),
|
4090
|
-
totalPages: z.number().describe("Total number of pages"),
|
4091
|
-
nextCursor: z.string().optional().describe("Next page cursor (if applicable)"),
|
4092
|
-
prevCursor: z.string().optional().describe("Previous page cursor (if applicable)")
|
4093
|
-
}).optional().describe("Pagination information")
|
4094
|
-
}).optional().describe("Response metadata")
|
4095
|
-
}).describe("Standard API response");
|
4096
|
-
var ErrorResponseSchema = z.object({
|
4097
|
-
error: z.object({
|
4098
|
-
type: z.string().describe("Error type"),
|
4099
|
-
message: z.string().describe("Error message"),
|
4100
|
-
code: z.string().optional().describe("Error code (if applicable)"),
|
4101
|
-
details: z.any().optional().describe("Additional error details")
|
4102
|
-
}).describe("Error information")
|
4103
|
-
}).describe("Error response");
|
4104
|
-
var EnhancedResponseMetaSchema = z.object({
|
4105
|
-
requestId: z.string().optional().describe("Unique request identifier"),
|
4106
|
-
timestamp: z.string().optional().describe("Request timestamp"),
|
4107
|
-
rateLimit: z.object({
|
4108
|
-
remaining: z.number().describe("Number of requests remaining in the current window"),
|
4109
|
-
limit: z.number().describe("Total number of requests allowed in the window"),
|
4110
|
-
reset: z.number().describe("Timestamp when the rate limit resets (in seconds since epoch)")
|
4111
|
-
}).optional().describe("Rate limit information"),
|
4112
|
-
pagination: z.object({
|
4113
|
-
page: z.number().describe("Current page number"),
|
4114
|
-
perPage: z.number().describe("Number of items per page"),
|
4115
|
-
total: z.number().describe("Total number of items"),
|
4116
|
-
totalPages: z.number().describe("Total number of pages"),
|
4117
|
-
nextCursor: z.string().optional().describe("Next page cursor (if applicable)"),
|
4118
|
-
prevCursor: z.string().optional().describe("Previous page cursor (if applicable)")
|
4119
|
-
}).optional().describe("Pagination information")
|
4120
|
-
}).optional().describe("Response metadata");
|
4121
|
-
var ErrorDetailSchema = z.object({
|
4122
|
-
platform: z.string().optional().describe("Platform associated with the error (if applicable)"),
|
4123
|
-
userId: z.string().optional().describe("User ID associated with the error (if applicable)"),
|
4124
|
-
status: z.literal("error").describe("Error status"),
|
4125
|
-
error: z.string().describe("Human-readable error message"),
|
4126
|
-
errorCode: z.string().describe("Machine-readable error code"),
|
4127
|
-
recoverable: z.boolean().describe("Whether the error is recoverable (can be retried)"),
|
4128
|
-
details: z.record(z.any()).optional().describe("Additional error details (platform-specific)")
|
4129
|
-
}).describe("Error detail");
|
4130
|
-
var EnhancedErrorResponseSchema = z.object({
|
4131
|
-
success: z.literal(false).describe("Success indicator (always false for error responses)"),
|
4132
|
-
errors: z.array(ErrorDetailSchema).describe("Error information")
|
4133
|
-
}).describe("Enhanced error response");
|
4134
|
-
var SuccessDetailSchema = z.object({
|
4135
|
-
platform: z.string().describe("Platform associated with the success"),
|
4136
|
-
userId: z.string().describe("User ID associated with the success"),
|
4137
|
-
status: z.literal("success").describe("Success status"),
|
4138
|
-
postId: z.string().optional().describe("Post ID (if applicable)"),
|
4139
|
-
postUrl: z.string().optional().describe("Post URL (if applicable)")
|
4140
|
-
}).catchall(z.any()).describe("Success detail");
|
4141
|
-
var MultiStatusResponseSchema = z.object({
|
4142
|
-
success: z.boolean().describe("Success indicator (true if at least one operation succeeded)"),
|
4143
|
-
data: z.object({
|
4144
|
-
summary: z.object({
|
4145
|
-
total: z.number().describe("Total number of operations"),
|
4146
|
-
succeeded: z.number().describe("Number of successful operations"),
|
4147
|
-
failed: z.number().describe("Number of failed operations")
|
4148
|
-
}).describe("Summary of operations"),
|
4149
|
-
results: z.array(SuccessDetailSchema).describe("Successful results"),
|
4150
|
-
errors: z.array(ErrorDetailSchema).describe("Failed results")
|
4151
|
-
}).describe("Response data")
|
4152
|
-
}).describe("Multi-status response");
|
4153
|
-
function EnhancedResponseSchema(schema) {
|
4154
|
-
return z.object({
|
4155
|
-
success: z.boolean().describe("Whether the request was successful"),
|
4156
|
-
data: schema,
|
4157
|
-
meta: EnhancedResponseMetaSchema
|
4158
|
-
});
|
4159
|
-
}
|
4160
|
-
function createEnhancedApiResponse(data, meta) {
|
4161
|
-
return {
|
4162
|
-
success: true,
|
4163
|
-
data,
|
4164
|
-
meta
|
4165
|
-
};
|
4166
|
-
}
|
4167
|
-
function createApiResponse(data, meta) {
|
4168
|
-
return {
|
4169
|
-
data,
|
4170
|
-
meta
|
4171
|
-
};
|
4172
|
-
}
|
4173
|
-
function createErrorResponse(type, message, code, details) {
|
4174
|
-
return {
|
4175
|
-
error: {
|
4176
|
-
type,
|
4177
|
-
message,
|
4178
|
-
...code ? { code } : {},
|
4179
|
-
...details ? { details } : {}
|
4180
|
-
}
|
4181
|
-
};
|
4182
|
-
}
|
4183
|
-
function createEnhancedErrorResponse(errors) {
|
4184
|
-
return {
|
4185
|
-
success: false,
|
4186
|
-
errors
|
4187
|
-
};
|
4188
|
-
}
|
4189
|
-
function createErrorDetail(error, errorCode, recoverable, platform, userId, details) {
|
4190
|
-
return {
|
4191
|
-
platform,
|
4192
|
-
userId,
|
4193
|
-
status: "error",
|
4194
|
-
error,
|
4195
|
-
errorCode,
|
4196
|
-
recoverable,
|
4197
|
-
details
|
4198
|
-
};
|
4199
|
-
}
|
4200
|
-
function createSuccessDetail(platform, userId, additionalData) {
|
4201
|
-
return {
|
4202
|
-
platform,
|
4203
|
-
userId,
|
4204
|
-
status: "success",
|
4205
|
-
...additionalData
|
4206
|
-
};
|
4207
|
-
}
|
4208
|
-
function createMultiStatusResponse(results, errors) {
|
4209
|
-
const total = results.length + errors.length;
|
4210
|
-
const succeeded = results.length;
|
4211
|
-
const failed = errors.length;
|
4212
|
-
return {
|
4213
|
-
success: succeeded > 0,
|
4214
|
-
data: {
|
4215
|
-
summary: {
|
4216
|
-
total,
|
4217
|
-
succeeded,
|
4218
|
-
failed
|
4219
|
-
},
|
4220
|
-
results,
|
4221
|
-
errors
|
4222
|
-
}
|
4223
|
-
};
|
4224
|
-
}
|
4225
|
-
var BaseError = class extends Error {
|
4226
|
-
constructor(message) {
|
4227
|
-
super(message);
|
4228
|
-
this.name = this.constructor.name;
|
4229
|
-
if (Error.captureStackTrace) {
|
4230
|
-
Error.captureStackTrace(this, this.constructor);
|
4231
|
-
}
|
4232
|
-
}
|
4233
|
-
};
|
4234
4078
|
var ApiErrorCode = /* @__PURE__ */ ((ApiErrorCode2) => {
|
4235
4079
|
ApiErrorCode2["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
|
4236
4080
|
ApiErrorCode2["INTERNAL_ERROR"] = "INTERNAL_ERROR";
|
@@ -4245,6 +4089,7 @@ var ApiErrorCode = /* @__PURE__ */ ((ApiErrorCode2) => {
|
|
4245
4089
|
ApiErrorCode2["CONTENT_POLICY_VIOLATION"] = "CONTENT_POLICY_VIOLATION";
|
4246
4090
|
ApiErrorCode2["DUPLICATE_CONTENT"] = "DUPLICATE_CONTENT";
|
4247
4091
|
ApiErrorCode2["MEDIA_UPLOAD_FAILED"] = "MEDIA_UPLOAD_FAILED";
|
4092
|
+
ApiErrorCode2["MULTI_STATUS"] = "MULTI_STATUS";
|
4248
4093
|
ApiErrorCode2["POST_CREATION_FAILED"] = "POST_CREATION_FAILED";
|
4249
4094
|
ApiErrorCode2["THREAD_CREATION_FAILED"] = "THREAD_CREATION_FAILED";
|
4250
4095
|
ApiErrorCode2["POST_DELETION_FAILED"] = "POST_DELETION_FAILED";
|
@@ -4252,100 +4097,125 @@ var ApiErrorCode = /* @__PURE__ */ ((ApiErrorCode2) => {
|
|
4252
4097
|
ApiErrorCode2["NETWORK_ERROR"] = "NETWORK_ERROR";
|
4253
4098
|
return ApiErrorCode2;
|
4254
4099
|
})(ApiErrorCode || {});
|
4255
|
-
var
|
4256
|
-
|
4257
|
-
|
4258
|
-
|
4259
|
-
|
4260
|
-
|
4261
|
-
|
4262
|
-
|
4263
|
-
|
4264
|
-
|
4265
|
-
|
4266
|
-
|
4267
|
-
|
4268
|
-
|
4269
|
-
|
4270
|
-
|
4271
|
-
|
4272
|
-
|
4273
|
-
|
4274
|
-
|
4275
|
-
|
4276
|
-
|
4277
|
-
|
4278
|
-
|
4279
|
-
|
4280
|
-
|
4281
|
-
|
4282
|
-
|
4283
|
-
|
4284
|
-
|
4285
|
-
|
4286
|
-
|
4287
|
-
|
4288
|
-
|
4289
|
-
|
4290
|
-
|
4291
|
-
|
4292
|
-
|
4293
|
-
|
4294
|
-
|
4295
|
-
|
4296
|
-
|
4297
|
-
|
4298
|
-
|
4299
|
-
|
4300
|
-
|
4301
|
-
|
4302
|
-
|
4303
|
-
|
4304
|
-
|
4305
|
-
|
4306
|
-
|
4307
|
-
|
4308
|
-
|
4309
|
-
|
4310
|
-
|
4311
|
-
|
4312
|
-
|
4313
|
-
|
4314
|
-
|
4315
|
-
|
4316
|
-
|
4317
|
-
|
4318
|
-
|
4319
|
-
|
4320
|
-
|
4321
|
-
|
4322
|
-
|
4323
|
-
|
4324
|
-
|
4325
|
-
|
4326
|
-
|
4327
|
-
|
4328
|
-
|
4329
|
-
|
4330
|
-
|
4331
|
-
|
4332
|
-
|
4333
|
-
);
|
4334
|
-
}
|
4335
|
-
};
|
4336
|
-
var PlatformError = class extends Error {
|
4337
|
-
constructor(message, platform, code = "PLATFORM_ERROR", recoverable = false, originalError, status, userId, details) {
|
4338
|
-
super(message);
|
4339
|
-
this.originalError = originalError;
|
4340
|
-
this.status = status;
|
4341
|
-
this.name = "PlatformError";
|
4342
|
-
this.code = code;
|
4343
|
-
this.recoverable = recoverable;
|
4344
|
-
this.platform = platform;
|
4345
|
-
this.userId = userId;
|
4346
|
-
this.details = details;
|
4347
|
-
}
|
4100
|
+
var ApiErrorCodeSchema = z.enum(Object.values(ApiErrorCode));
|
4101
|
+
var errorCodeToStatusCode = {
|
4102
|
+
[
|
4103
|
+
"MULTI_STATUS"
|
4104
|
+
/* MULTI_STATUS */
|
4105
|
+
]: 207,
|
4106
|
+
[
|
4107
|
+
"UNKNOWN_ERROR"
|
4108
|
+
/* UNKNOWN_ERROR */
|
4109
|
+
]: 500,
|
4110
|
+
[
|
4111
|
+
"INTERNAL_ERROR"
|
4112
|
+
/* INTERNAL_ERROR */
|
4113
|
+
]: 500,
|
4114
|
+
[
|
4115
|
+
"VALIDATION_ERROR"
|
4116
|
+
/* VALIDATION_ERROR */
|
4117
|
+
]: 400,
|
4118
|
+
[
|
4119
|
+
"INVALID_REQUEST"
|
4120
|
+
/* INVALID_REQUEST */
|
4121
|
+
]: 400,
|
4122
|
+
[
|
4123
|
+
"NOT_FOUND"
|
4124
|
+
/* NOT_FOUND */
|
4125
|
+
]: 404,
|
4126
|
+
[
|
4127
|
+
"UNAUTHORIZED"
|
4128
|
+
/* UNAUTHORIZED */
|
4129
|
+
]: 401,
|
4130
|
+
[
|
4131
|
+
"FORBIDDEN"
|
4132
|
+
/* FORBIDDEN */
|
4133
|
+
]: 403,
|
4134
|
+
[
|
4135
|
+
"RATE_LIMITED"
|
4136
|
+
/* RATE_LIMITED */
|
4137
|
+
]: 429,
|
4138
|
+
[
|
4139
|
+
"PLATFORM_ERROR"
|
4140
|
+
/* PLATFORM_ERROR */
|
4141
|
+
]: 502,
|
4142
|
+
[
|
4143
|
+
"PLATFORM_UNAVAILABLE"
|
4144
|
+
/* PLATFORM_UNAVAILABLE */
|
4145
|
+
]: 503,
|
4146
|
+
[
|
4147
|
+
"CONTENT_POLICY_VIOLATION"
|
4148
|
+
/* CONTENT_POLICY_VIOLATION */
|
4149
|
+
]: 400,
|
4150
|
+
[
|
4151
|
+
"DUPLICATE_CONTENT"
|
4152
|
+
/* DUPLICATE_CONTENT */
|
4153
|
+
]: 400,
|
4154
|
+
[
|
4155
|
+
"MEDIA_UPLOAD_FAILED"
|
4156
|
+
/* MEDIA_UPLOAD_FAILED */
|
4157
|
+
]: 400,
|
4158
|
+
[
|
4159
|
+
"POST_CREATION_FAILED"
|
4160
|
+
/* POST_CREATION_FAILED */
|
4161
|
+
]: 500,
|
4162
|
+
[
|
4163
|
+
"THREAD_CREATION_FAILED"
|
4164
|
+
/* THREAD_CREATION_FAILED */
|
4165
|
+
]: 500,
|
4166
|
+
[
|
4167
|
+
"POST_DELETION_FAILED"
|
4168
|
+
/* POST_DELETION_FAILED */
|
4169
|
+
]: 500,
|
4170
|
+
[
|
4171
|
+
"POST_INTERACTION_FAILED"
|
4172
|
+
/* POST_INTERACTION_FAILED */
|
4173
|
+
]: 500,
|
4174
|
+
[
|
4175
|
+
"NETWORK_ERROR"
|
4176
|
+
/* NETWORK_ERROR */
|
4177
|
+
]: 503
|
4348
4178
|
};
|
4179
|
+
var ErrorDetailSchema = z.object({
|
4180
|
+
message: z.string().describe("Human-readable error message"),
|
4181
|
+
code: ApiErrorCodeSchema.describe("Machine-readable error code"),
|
4182
|
+
recoverable: z.boolean().describe("Whether the error can be recovered from"),
|
4183
|
+
details: z.record(z.unknown()).optional().describe("Additional error details")
|
4184
|
+
});
|
4185
|
+
var ResponseMetaSchema = z.object({
|
4186
|
+
requestId: z.string().uuid().describe("Unique identifier for the request"),
|
4187
|
+
timestamp: z.string().datetime().describe("ISO timestamp of response generation"),
|
4188
|
+
rateLimit: z.object({
|
4189
|
+
remaining: z.number().int().nonnegative(),
|
4190
|
+
limit: z.number().int().positive(),
|
4191
|
+
reset: z.number().int().positive().describe("Unix timestamp (seconds)")
|
4192
|
+
}).optional().describe("Rate limit information if applicable"),
|
4193
|
+
pagination: z.object({
|
4194
|
+
page: z.number().int().positive().optional(),
|
4195
|
+
perPage: z.number().int().positive().optional(),
|
4196
|
+
total: z.number().int().nonnegative().optional(),
|
4197
|
+
limit: z.number().int().nonnegative().optional(),
|
4198
|
+
offset: z.number().int().nonnegative().optional(),
|
4199
|
+
totalPages: z.number().int().nonnegative().optional(),
|
4200
|
+
nextCursor: z.string().optional(),
|
4201
|
+
prevCursor: z.string().optional()
|
4202
|
+
}).optional().describe("Pagination information if applicable")
|
4203
|
+
});
|
4204
|
+
var SuccessDetailSchema = z.object({
|
4205
|
+
platform: z.string(),
|
4206
|
+
userId: z.string(),
|
4207
|
+
additionalData: z.any().optional(),
|
4208
|
+
status: z.literal("success")
|
4209
|
+
}).catchall(z.any());
|
4210
|
+
var MultiStatusDataSchema = z.object({
|
4211
|
+
summary: z.object({
|
4212
|
+
total: z.number().int().nonnegative(),
|
4213
|
+
succeeded: z.number().int().nonnegative(),
|
4214
|
+
failed: z.number().int().nonnegative()
|
4215
|
+
}),
|
4216
|
+
results: z.array(SuccessDetailSchema),
|
4217
|
+
errors: z.array(ErrorDetailSchema)
|
4218
|
+
});
|
4349
4219
|
var PlatformParamSchema = z.object({
|
4350
4220
|
platform: z.string().describe("Social media platform")
|
4351
4221
|
}).describe("Platform parameter");
|
@@ -4355,44 +4225,37 @@ var AuthInitRequestSchema = z.object({
|
|
4355
4225
|
),
|
4356
4226
|
errorUrl: z.string().url().optional().describe("URL to redirect to on authentication error")
|
4357
4227
|
}).describe("Auth initialization request");
|
4358
|
-
var AuthUrlResponseSchema =
|
4359
|
-
z.
|
4360
|
-
|
4361
|
-
|
4362
|
-
|
4363
|
-
})
|
4364
|
-
).describe("Auth URL response");
|
4228
|
+
var AuthUrlResponseSchema = z.object({
|
4229
|
+
url: z.string().describe("Authentication URL to redirect the user to"),
|
4230
|
+
state: z.string().describe("State parameter for CSRF protection"),
|
4231
|
+
platform: PlatformSchema
|
4232
|
+
}).describe("Auth URL response");
|
4365
4233
|
var AuthCallbackQuerySchema = z.object({
|
4366
4234
|
code: z.string().describe("Authorization code from OAuth provider"),
|
4367
4235
|
state: z.string().describe("State parameter for CSRF protection")
|
4368
4236
|
}).describe("Auth callback query");
|
4369
|
-
var AuthCallbackResponseSchema =
|
4370
|
-
|
4371
|
-
|
4372
|
-
|
4373
|
-
|
4374
|
-
|
4375
|
-
|
4376
|
-
).describe("
|
4377
|
-
|
4378
|
-
z.object({
|
4379
|
-
|
4380
|
-
|
4381
|
-
|
4382
|
-
tokenStatus: z.object({
|
4383
|
-
valid: z.boolean().describe("Whether the token is valid"),
|
4384
|
-
expired: z.boolean().describe("Whether the token is expired"),
|
4385
|
-
expiresAt: z.string().optional().describe("When the token expires")
|
4386
|
-
})
|
4387
|
-
})
|
4388
|
-
).describe("Auth status response");
|
4389
|
-
var AuthRevokeResponseSchema = EnhancedResponseSchema(
|
4390
|
-
z.object({
|
4391
|
-
success: z.boolean().describe("Whether the revocation was successful"),
|
4392
|
-
platform: PlatformSchema,
|
4393
|
-
userId: z.string().describe("User ID")
|
4237
|
+
var AuthCallbackResponseSchema = z.object({
|
4238
|
+
platform: PlatformSchema,
|
4239
|
+
userId: z.string().describe("User ID"),
|
4240
|
+
redirectUrl: z.string().optional().describe("URL to redirect the user to after authentication")
|
4241
|
+
}).describe("Auth callback response");
|
4242
|
+
var AuthStatusResponseSchema = z.object({
|
4243
|
+
platform: PlatformSchema,
|
4244
|
+
userId: z.string().describe("User ID"),
|
4245
|
+
authenticated: z.boolean().describe("Whether the user is authenticated"),
|
4246
|
+
tokenStatus: z.object({
|
4247
|
+
valid: z.boolean().describe("Whether the token is valid"),
|
4248
|
+
expired: z.boolean().describe("Whether the token is expired"),
|
4249
|
+
expiresAt: z.string().optional().describe("When the token expires")
|
4394
4250
|
})
|
4395
|
-
).describe("Auth
|
4251
|
+
}).describe("Auth status response");
|
4252
|
+
var AuthTokenRequestSchema = z.object({
|
4253
|
+
userId: z.string().describe("User ID on the platform")
|
4254
|
+
}).describe("Auth token request");
|
4255
|
+
var AuthRevokeResponseSchema = z.object({
|
4256
|
+
platform: PlatformSchema,
|
4257
|
+
userId: z.string().describe("User ID")
|
4258
|
+
}).describe("Auth revoke response");
|
4396
4259
|
var ConnectedAccountSchema = z.object({
|
4397
4260
|
platform: PlatformSchema,
|
4398
4261
|
userId: z.string().describe("User ID on the platform"),
|
@@ -4400,26 +4263,21 @@ var ConnectedAccountSchema = z.object({
|
|
4400
4263
|
profileUrl: z.string().optional().describe("URL to the user profile"),
|
4401
4264
|
connectedAt: z.string().optional().describe("When the account was connected")
|
4402
4265
|
}).describe("Connected account");
|
4403
|
-
var ConnectedAccountsResponseSchema =
|
4404
|
-
|
4405
|
-
)
|
4266
|
+
var ConnectedAccountsResponseSchema = z.array(ConnectedAccountSchema).describe(
|
4267
|
+
"Connected accounts response"
|
4268
|
+
);
|
4406
4269
|
var NearAuthorizationRequestSchema = z.object({
|
4407
4270
|
// No additional parameters needed, as the NEAR account ID is extracted from the signature
|
4408
4271
|
}).describe("NEAR authorization request");
|
4409
|
-
var NearAuthorizationResponseSchema =
|
4410
|
-
z.
|
4411
|
-
|
4412
|
-
|
4413
|
-
|
4414
|
-
|
4415
|
-
).describe("
|
4416
|
-
|
4417
|
-
|
4418
|
-
nearAccount: z.string().describe("NEAR account ID"),
|
4419
|
-
authorized: z.boolean().describe("Whether the account is authorized"),
|
4420
|
-
authorizedAt: z.string().optional().describe("When the account was authorized")
|
4421
|
-
})
|
4422
|
-
).describe("NEAR authorization status response");
|
4272
|
+
var NearAuthorizationResponseSchema = z.object({
|
4273
|
+
nearAccount: z.string().describe("NEAR account ID"),
|
4274
|
+
authorized: z.boolean().describe("Whether the account is authorized")
|
4275
|
+
}).describe("NEAR authorization response");
|
4276
|
+
var NearAuthorizationStatusResponseSchema = z.object({
|
4277
|
+
nearAccount: z.string().describe("NEAR account ID"),
|
4278
|
+
authorized: z.boolean().describe("Whether the account is authorized"),
|
4279
|
+
authorizedAt: z.string().optional().describe("When the account was authorized")
|
4280
|
+
}).describe("NEAR authorization status response");
|
4423
4281
|
var MediaContentSchema = z.object({
|
4424
4282
|
data: z.union([z.string(), z.instanceof(Blob)]).describe("Media data as string or Blob"),
|
4425
4283
|
mimeType: z.string().optional().describe("Media MIME type"),
|
@@ -4534,65 +4392,33 @@ var UnlikePostRequestSchema = z.object({
|
|
4534
4392
|
platform: PlatformSchema.describe("Platform of the post being unliked"),
|
4535
4393
|
postId: z.string().describe("ID of the post to unlike")
|
4536
4394
|
}).describe("Unlike post request");
|
4537
|
-
var PostResponseSchema =
|
4538
|
-
|
4539
|
-
)
|
4540
|
-
var
|
4541
|
-
"Create post response
|
4395
|
+
var PostResponseSchema = z.union([PostSchema, z.array(PostSchema)]).describe(
|
4396
|
+
"Post response"
|
4397
|
+
);
|
4398
|
+
var CreatePostResponseSchema = PostResponseSchema.describe(
|
4399
|
+
"Create post response"
|
4542
4400
|
);
|
4543
4401
|
var RepostResponseSchema = PostResponseSchema.describe("Repost response");
|
4544
4402
|
var QuotePostResponseSchema = PostResponseSchema.describe("Quote post response");
|
4545
4403
|
var ReplyToPostResponseSchema = PostResponseSchema.describe("Reply to post response");
|
4546
|
-
var DeletePostResponseSchema =
|
4547
|
-
z.
|
4548
|
-
|
4549
|
-
|
4550
|
-
|
4551
|
-
).describe("
|
4552
|
-
var
|
4553
|
-
z.
|
4554
|
-
|
4555
|
-
id: z.string().describe("ID of the liked post")
|
4556
|
-
})
|
4557
|
-
).describe("Like post response");
|
4558
|
-
var UnlikePostResponseSchema = EnhancedResponseSchema(
|
4559
|
-
z.object({
|
4560
|
-
success: z.boolean().describe("Whether the unlike was successful"),
|
4561
|
-
id: z.string().describe("ID of the unliked post")
|
4562
|
-
})
|
4563
|
-
).describe("Unlike post response");
|
4404
|
+
var DeletePostResponseSchema = z.object({
|
4405
|
+
id: z.string().describe("ID of the deleted post")
|
4406
|
+
}).describe("Delete post response");
|
4407
|
+
var LikePostResponseSchema = z.object({
|
4408
|
+
id: z.string().describe("ID of the liked post")
|
4409
|
+
}).describe("Like post response");
|
4410
|
+
var UnlikePostResponseSchema = z.object({
|
4411
|
+
id: z.string().describe("ID of the unliked post")
|
4412
|
+
}).describe("Unlike post response");
|
4564
4413
|
var PostMultiStatusResponseSchema = z.object({
|
4565
|
-
|
4566
|
-
|
4567
|
-
|
4568
|
-
|
4569
|
-
|
4570
|
-
|
4571
|
-
|
4572
|
-
results: z.array(PostSuccessDetailSchema).describe("Successful operations"),
|
4573
|
-
errors: z.array(ErrorDetailSchema).describe("Failed operations")
|
4574
|
-
})
|
4414
|
+
summary: z.object({
|
4415
|
+
total: z.number().describe("Total number of operations"),
|
4416
|
+
succeeded: z.number().describe("Number of successful operations"),
|
4417
|
+
failed: z.number().describe("Number of failed operations")
|
4418
|
+
}),
|
4419
|
+
results: z.array(PostSuccessDetailSchema).describe("Successful operations"),
|
4420
|
+
errors: z.array(ErrorDetailSchema).describe("Failed operations")
|
4575
4421
|
}).describe("Multi-status response for post operations");
|
4576
|
-
var CreatePostTargetResultSchema = z.object({
|
4577
|
-
platform: PlatformSchema.describe("The platform the post was created on"),
|
4578
|
-
userId: z.string().describe("The user ID on the platform"),
|
4579
|
-
result: z.array(z.any()).describe("The result of the post creation")
|
4580
|
-
}).describe("Create post target result");
|
4581
|
-
var CreatePostTargetErrorSchema = z.object({
|
4582
|
-
platform: PlatformSchema.optional().describe(
|
4583
|
-
"The platform where the error occurred (if applicable)"
|
4584
|
-
),
|
4585
|
-
userId: z.string().optional().describe("The user ID where the error occurred (if applicable)"),
|
4586
|
-
error: z.string().describe("The error message")
|
4587
|
-
}).describe("Create post target error");
|
4588
|
-
var CreatePostResponseSchema = EnhancedResponseSchema(
|
4589
|
-
z.object({
|
4590
|
-
results: z.array(CreatePostTargetResultSchema).describe("Array of successful post results"),
|
4591
|
-
errors: z.array(CreatePostTargetErrorSchema).optional().describe(
|
4592
|
-
"Array of errors that occurred (if any)"
|
4593
|
-
)
|
4594
|
-
})
|
4595
|
-
).describe("Create post response");
|
4596
4422
|
var RateLimitEndpointParamSchema = z.object({
|
4597
4423
|
endpoint: z.string().optional().describe(
|
4598
4424
|
"Specific endpoint to get rate limit information for (optional)"
|
@@ -4627,43 +4453,39 @@ var UsageRateLimitSchema = z.object({
|
|
4627
4453
|
resetSeconds: z.number().describe("Seconds until the rate limit will reset"),
|
4628
4454
|
timeWindow: z.string().describe("Time window for the rate limit")
|
4629
4455
|
}).describe("Usage rate limit");
|
4630
|
-
var RateLimitStatusResponseSchema =
|
4631
|
-
|
4632
|
-
|
4633
|
-
|
4634
|
-
|
4635
|
-
|
4636
|
-
|
4637
|
-
|
4638
|
-
|
4639
|
-
|
4640
|
-
|
4641
|
-
|
4642
|
-
|
4643
|
-
|
4644
|
-
|
4645
|
-
|
4646
|
-
|
4647
|
-
|
4648
|
-
|
4649
|
-
|
4650
|
-
|
4651
|
-
|
4652
|
-
|
4653
|
-
|
4654
|
-
|
4655
|
-
|
4656
|
-
).describe("
|
4657
|
-
|
4658
|
-
|
4659
|
-
|
4660
|
-
|
4661
|
-
|
4662
|
-
|
4663
|
-
})
|
4664
|
-
).describe("Rate limits by platform")
|
4665
|
-
})
|
4666
|
-
).describe("All rate limits response");
|
4456
|
+
var RateLimitStatusResponseSchema = z.object({
|
4457
|
+
platform: PlatformSchema,
|
4458
|
+
userId: z.string().optional().describe("User ID"),
|
4459
|
+
endpoints: z.array(RateLimitEndpointSchema).describe("Rate limits for specific endpoints"),
|
4460
|
+
app: z.object({
|
4461
|
+
limit: z.number().describe("App-wide rate limit"),
|
4462
|
+
remaining: z.number().describe("Remaining requests"),
|
4463
|
+
reset: z.number().describe("Reset timestamp (Unix timestamp in seconds)"),
|
4464
|
+
resetDate: z.string().describe("Reset date (ISO string)")
|
4465
|
+
}).optional().describe("App-wide rate limits")
|
4466
|
+
}).describe("Rate limit status response");
|
4467
|
+
var AllRateLimitsResponseSchema = z.object({
|
4468
|
+
platforms: z.record(
|
4469
|
+
PlatformSchema,
|
4470
|
+
z.object({
|
4471
|
+
users: z.record(
|
4472
|
+
z.string(),
|
4473
|
+
z.object({
|
4474
|
+
endpoints: z.array(RateLimitEndpointSchema).describe(
|
4475
|
+
"Rate limits for specific endpoints"
|
4476
|
+
),
|
4477
|
+
lastUpdated: z.string().describe("Last updated date (ISO string)")
|
4478
|
+
})
|
4479
|
+
).describe("User-specific rate limits"),
|
4480
|
+
app: z.object({
|
4481
|
+
limit: z.number().describe("App-wide rate limit"),
|
4482
|
+
remaining: z.number().describe("Remaining requests"),
|
4483
|
+
reset: z.number().describe("Reset timestamp (Unix timestamp in seconds)"),
|
4484
|
+
resetDate: z.string().describe("Reset date (ISO string)")
|
4485
|
+
}).optional().describe("App-wide rate limits")
|
4486
|
+
})
|
4487
|
+
).describe("Rate limits by platform")
|
4488
|
+
}).describe("All rate limits response");
|
4667
4489
|
var RateLimitResponseSchema = z.object({
|
4668
4490
|
platformLimits: z.array(PlatformRateLimitSchema).describe("Platform-specific rate limits"),
|
4669
4491
|
usageLimits: z.record(z.string(), UsageRateLimitSchema).describe(
|
@@ -4708,16 +4530,12 @@ var AccountActivityEntrySchema = z.object({
|
|
4708
4530
|
rank: z.number().describe("Rank on the leaderboard"),
|
4709
4531
|
lastActive: z.string().datetime().describe("Timestamp of last activity")
|
4710
4532
|
}).describe("Account activity entry");
|
4711
|
-
var ActivityLeaderboardResponseSchema =
|
4712
|
-
z.
|
4713
|
-
|
4714
|
-
|
4715
|
-
|
4716
|
-
|
4717
|
-
offset: z.number().describe("Offset for pagination"),
|
4718
|
-
generatedAt: z.string().datetime().describe("Timestamp when the leaderboard was generated")
|
4719
|
-
})
|
4720
|
-
).describe("Activity leaderboard response");
|
4533
|
+
var ActivityLeaderboardResponseSchema = z.object({
|
4534
|
+
timeframe: z.nativeEnum(TimePeriod).describe("Timeframe for the leaderboard"),
|
4535
|
+
entries: z.array(AccountActivityEntrySchema).describe("Leaderboard entries"),
|
4536
|
+
generatedAt: z.string().datetime().describe("Timestamp when the leaderboard was generated"),
|
4537
|
+
platform: PlatformSchema.optional().describe("Platform filter (if applied)")
|
4538
|
+
});
|
4721
4539
|
var AccountActivityParamsSchema = z.object({
|
4722
4540
|
signerId: z.string().describe("NEAR account ID")
|
4723
4541
|
}).describe("Account activity params");
|
@@ -4736,21 +4554,19 @@ var PlatformActivitySchema = z.object({
|
|
4736
4554
|
score: z.number().describe("Activity score on this platform"),
|
4737
4555
|
lastActive: z.string().datetime().describe("Timestamp of last activity on this platform")
|
4738
4556
|
}).describe("Platform activity");
|
4739
|
-
var AccountActivityResponseSchema =
|
4740
|
-
z.
|
4741
|
-
|
4742
|
-
|
4743
|
-
|
4744
|
-
|
4745
|
-
|
4746
|
-
|
4747
|
-
|
4748
|
-
|
4749
|
-
|
4750
|
-
|
4751
|
-
|
4752
|
-
})
|
4753
|
-
).describe("Account activity response");
|
4557
|
+
var AccountActivityResponseSchema = z.object({
|
4558
|
+
signerId: z.string().describe("NEAR account ID"),
|
4559
|
+
timeframe: z.nativeEnum(TimePeriod).describe("Timeframe for the activity"),
|
4560
|
+
totalPosts: z.number().describe("Total number of posts across all platforms"),
|
4561
|
+
totalLikes: z.number().describe("Total number of likes across all platforms"),
|
4562
|
+
totalReposts: z.number().describe("Total number of reposts across all platforms"),
|
4563
|
+
totalReplies: z.number().describe("Total number of replies across all platforms"),
|
4564
|
+
totalQuotes: z.number().describe("Total number of quote posts across all platforms"),
|
4565
|
+
totalScore: z.number().describe("Total activity score across all platforms"),
|
4566
|
+
rank: z.number().describe("Rank on the leaderboard"),
|
4567
|
+
lastActive: z.string().datetime().describe("Timestamp of last activity across all platforms"),
|
4568
|
+
platforms: z.array(PlatformActivitySchema).describe("Activity breakdown by platform")
|
4569
|
+
});
|
4754
4570
|
var AccountPostsParamsSchema = z.object({
|
4755
4571
|
signerId: z.string().describe("NEAR account ID")
|
4756
4572
|
}).describe("Account posts params");
|
@@ -4778,19 +4594,14 @@ var AccountPostSchema = z.object({
|
|
4778
4594
|
inReplyToId: z.string().optional().describe("ID of the post this is a reply to (if applicable)"),
|
4779
4595
|
quotedPostId: z.string().optional().describe("ID of the post this is quoting (if applicable)")
|
4780
4596
|
}).describe("Account post");
|
4781
|
-
var AccountPostsResponseSchema =
|
4782
|
-
z.
|
4783
|
-
|
4784
|
-
|
4785
|
-
|
4786
|
-
|
4787
|
-
|
4788
|
-
|
4789
|
-
type: z.enum(["post", "repost", "reply", "quote", "like", "all"]).optional().describe(
|
4790
|
-
"Post type filter (if applied)"
|
4791
|
-
)
|
4792
|
-
})
|
4793
|
-
).describe("Account posts response");
|
4597
|
+
var AccountPostsResponseSchema = z.object({
|
4598
|
+
signerId: z.string().describe("NEAR account ID"),
|
4599
|
+
posts: z.array(AccountPostSchema).describe("List of posts"),
|
4600
|
+
platform: z.string().optional().describe("Platform filter (if applied)"),
|
4601
|
+
type: z.enum(["post", "repost", "reply", "quote", "like", "all"]).optional().describe(
|
4602
|
+
"Post type filter (if applied)"
|
4603
|
+
)
|
4604
|
+
});
|
4794
4605
|
var UserProfileSchema = z.object({
|
4795
4606
|
userId: z.string().describe("User ID on the platform"),
|
4796
4607
|
username: z.string().describe("Username on the platform"),
|
@@ -4800,118 +4611,107 @@ var UserProfileSchema = z.object({
|
|
4800
4611
|
platform: PlatformSchema.describe("The platform the user profile is from"),
|
4801
4612
|
lastUpdated: z.number().describe("Timestamp when the profile was last updated")
|
4802
4613
|
}).describe("User profile");
|
4803
|
-
var
|
4804
|
-
|
4805
|
-
|
4806
|
-
error: z.string().optional().describe("Error message (if unsuccessful)")
|
4807
|
-
}).describe("Profile refresh result");
|
4808
|
-
var ProfileRefreshResponseSchema = EnhancedResponseSchema(
|
4809
|
-
ProfileRefreshResultSchema
|
4810
|
-
).describe("Profile refresh response");
|
4614
|
+
var ProfileRefreshResponseSchema = z.object({
|
4615
|
+
profile: UserProfileSchema.optional().describe("The refreshed user profile (if successful)")
|
4616
|
+
}).describe("Profile refresh response");
|
4811
4617
|
|
4812
4618
|
// src/core/request.ts
|
4813
4619
|
import { createAuthToken } from "near-sign-verify";
|
4814
4620
|
|
4815
4621
|
// src/utils/error.ts
|
4816
|
-
var
|
4817
|
-
|
4818
|
-
|
4819
|
-
|
4820
|
-
|
4821
|
-
|
4822
|
-
|
4823
|
-
|
4824
|
-
],
|
4825
|
-
NETWORK: [
|
4826
|
-
ApiErrorCode.NETWORK_ERROR
|
4827
|
-
],
|
4828
|
-
PLATFORM: [
|
4829
|
-
ApiErrorCode.PLATFORM_ERROR,
|
4830
|
-
ApiErrorCode.PLATFORM_UNAVAILABLE
|
4831
|
-
],
|
4832
|
-
CONTENT: [
|
4833
|
-
ApiErrorCode.CONTENT_POLICY_VIOLATION,
|
4834
|
-
ApiErrorCode.DUPLICATE_CONTENT
|
4835
|
-
],
|
4836
|
-
RATE_LIMIT: [
|
4837
|
-
ApiErrorCode.RATE_LIMITED
|
4838
|
-
],
|
4839
|
-
POST: [
|
4840
|
-
ApiErrorCode.POST_CREATION_FAILED,
|
4841
|
-
ApiErrorCode.THREAD_CREATION_FAILED,
|
4842
|
-
ApiErrorCode.POST_DELETION_FAILED,
|
4843
|
-
ApiErrorCode.POST_INTERACTION_FAILED
|
4844
|
-
],
|
4845
|
-
MEDIA: [
|
4846
|
-
ApiErrorCode.MEDIA_UPLOAD_FAILED
|
4847
|
-
]
|
4848
|
-
};
|
4849
|
-
function isErrorOfCategory(error, category) {
|
4850
|
-
if (error instanceof ApiError) {
|
4851
|
-
return category.includes(error.code);
|
4622
|
+
var CrosspostError = class extends Error {
|
4623
|
+
constructor(message, code, status, details, recoverable = false) {
|
4624
|
+
super(message);
|
4625
|
+
this.name = "CrosspostError";
|
4626
|
+
this.code = code;
|
4627
|
+
this.status = status;
|
4628
|
+
this.details = details;
|
4629
|
+
this.recoverable = recoverable;
|
4852
4630
|
}
|
4853
|
-
|
4854
|
-
|
4631
|
+
/**
|
4632
|
+
* Get platform from details if available
|
4633
|
+
*/
|
4634
|
+
get platform() {
|
4635
|
+
return this.details?.platform;
|
4855
4636
|
}
|
4856
|
-
|
4857
|
-
|
4637
|
+
/**
|
4638
|
+
* Get userId from details if available
|
4639
|
+
*/
|
4640
|
+
get userId() {
|
4641
|
+
return this.details?.userId;
|
4858
4642
|
}
|
4859
|
-
|
4643
|
+
};
|
4644
|
+
function isErrorCode(error, codes) {
|
4645
|
+
return error instanceof CrosspostError && codes.includes(error.code);
|
4860
4646
|
}
|
4861
4647
|
function isAuthError(error) {
|
4862
|
-
return
|
4648
|
+
return isErrorCode(error, [
|
4649
|
+
ApiErrorCode.UNAUTHORIZED,
|
4650
|
+
ApiErrorCode.FORBIDDEN
|
4651
|
+
]);
|
4863
4652
|
}
|
4864
4653
|
function isValidationError(error) {
|
4865
|
-
return
|
4654
|
+
return isErrorCode(error, [
|
4655
|
+
ApiErrorCode.VALIDATION_ERROR,
|
4656
|
+
ApiErrorCode.INVALID_REQUEST
|
4657
|
+
]);
|
4866
4658
|
}
|
4867
4659
|
function isNetworkError(error) {
|
4868
|
-
return
|
4660
|
+
return isErrorCode(error, [
|
4661
|
+
ApiErrorCode.NETWORK_ERROR,
|
4662
|
+
ApiErrorCode.PLATFORM_UNAVAILABLE
|
4663
|
+
]);
|
4869
4664
|
}
|
4870
4665
|
function isPlatformError(error) {
|
4871
|
-
return
|
4666
|
+
return error instanceof CrosspostError && !!error.details?.platform;
|
4872
4667
|
}
|
4873
4668
|
function isContentError(error) {
|
4874
|
-
return
|
4669
|
+
return isErrorCode(error, [
|
4670
|
+
ApiErrorCode.CONTENT_POLICY_VIOLATION,
|
4671
|
+
ApiErrorCode.DUPLICATE_CONTENT
|
4672
|
+
]);
|
4875
4673
|
}
|
4876
4674
|
function isRateLimitError(error) {
|
4877
|
-
return
|
4675
|
+
return isErrorCode(error, [ApiErrorCode.RATE_LIMITED]);
|
4878
4676
|
}
|
4879
4677
|
function isPostError(error) {
|
4880
|
-
return
|
4678
|
+
return isErrorCode(error, [
|
4679
|
+
ApiErrorCode.POST_CREATION_FAILED,
|
4680
|
+
ApiErrorCode.THREAD_CREATION_FAILED,
|
4681
|
+
ApiErrorCode.POST_DELETION_FAILED,
|
4682
|
+
ApiErrorCode.POST_INTERACTION_FAILED
|
4683
|
+
]);
|
4881
4684
|
}
|
4882
4685
|
function isMediaError(error) {
|
4883
|
-
return
|
4686
|
+
return isErrorCode(error, [ApiErrorCode.MEDIA_UPLOAD_FAILED]);
|
4884
4687
|
}
|
4885
4688
|
function isRecoverableError(error) {
|
4886
|
-
|
4887
|
-
return error.recoverable;
|
4888
|
-
}
|
4889
|
-
return false;
|
4689
|
+
return error instanceof CrosspostError && error.recoverable;
|
4890
4690
|
}
|
4891
4691
|
function getErrorMessage(error, defaultMessage = "An error occurred") {
|
4892
4692
|
if (error instanceof Error) {
|
4893
4693
|
return error.message || defaultMessage;
|
4894
4694
|
}
|
4895
|
-
if (typeof error === "string") {
|
4896
|
-
return error;
|
4897
|
-
}
|
4898
|
-
if (error && typeof error === "object" && "message" in error) {
|
4899
|
-
return error.message || defaultMessage;
|
4900
|
-
}
|
4901
4695
|
return defaultMessage;
|
4902
4696
|
}
|
4903
4697
|
function getErrorDetails(error) {
|
4904
|
-
if (error instanceof
|
4905
|
-
return error.details;
|
4906
|
-
}
|
4907
|
-
if (error && typeof error === "object" && "details" in error) {
|
4698
|
+
if (error instanceof CrosspostError) {
|
4908
4699
|
return error.details;
|
4909
4700
|
}
|
4910
4701
|
return void 0;
|
4911
4702
|
}
|
4703
|
+
function createError(message, code, status, details, recoverable = false) {
|
4704
|
+
return new CrosspostError(
|
4705
|
+
message,
|
4706
|
+
code,
|
4707
|
+
status,
|
4708
|
+
details,
|
4709
|
+
recoverable
|
4710
|
+
);
|
4711
|
+
}
|
4912
4712
|
function enrichErrorWithContext(error, context) {
|
4913
|
-
if (error instanceof
|
4914
|
-
return
|
4713
|
+
if (error instanceof CrosspostError) {
|
4714
|
+
return createError(
|
4915
4715
|
error.message,
|
4916
4716
|
error.code,
|
4917
4717
|
error.status,
|
@@ -4919,25 +4719,12 @@ function enrichErrorWithContext(error, context) {
|
|
4919
4719
|
error.recoverable
|
4920
4720
|
);
|
4921
4721
|
}
|
4922
|
-
if (error instanceof PlatformError) {
|
4923
|
-
return new PlatformError(
|
4924
|
-
error.message,
|
4925
|
-
error.platform,
|
4926
|
-
error.code,
|
4927
|
-
error.recoverable,
|
4928
|
-
error.originalError,
|
4929
|
-
error.status,
|
4930
|
-
error.userId,
|
4931
|
-
{ ...error.details || {}, ...context }
|
4932
|
-
);
|
4933
|
-
}
|
4934
4722
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
4935
|
-
return
|
4723
|
+
return createError(
|
4936
4724
|
errorMessage || "An error occurred",
|
4937
4725
|
ApiErrorCode.INTERNAL_ERROR,
|
4938
4726
|
500,
|
4939
|
-
{ originalError: error, ...context }
|
4940
|
-
false
|
4727
|
+
{ originalError: error, ...context }
|
4941
4728
|
);
|
4942
4729
|
}
|
4943
4730
|
async function apiWrapper(apiCall, context) {
|
@@ -4954,7 +4741,7 @@ async function apiWrapper(apiCall, context) {
|
|
4954
4741
|
} catch (jsonError) {
|
4955
4742
|
if (jsonError instanceof Error && jsonError.name === "SyntaxError") {
|
4956
4743
|
throw enrichErrorWithContext(
|
4957
|
-
|
4744
|
+
createError(
|
4958
4745
|
`API request failed with status ${error.status} and non-JSON response`,
|
4959
4746
|
ApiErrorCode.NETWORK_ERROR,
|
4960
4747
|
error.status,
|
@@ -4966,7 +4753,7 @@ async function apiWrapper(apiCall, context) {
|
|
4966
4753
|
throw jsonError;
|
4967
4754
|
}
|
4968
4755
|
}
|
4969
|
-
if (error instanceof
|
4756
|
+
if (error instanceof CrosspostError) {
|
4970
4757
|
throw enrichErrorWithContext(error, context || {});
|
4971
4758
|
}
|
4972
4759
|
throw enrichErrorWithContext(
|
@@ -4976,50 +4763,68 @@ async function apiWrapper(apiCall, context) {
|
|
4976
4763
|
}
|
4977
4764
|
}
|
4978
4765
|
function handleErrorResponse(data, status) {
|
4979
|
-
|
4980
|
-
|
4981
|
-
|
4982
|
-
|
4983
|
-
|
4984
|
-
|
4985
|
-
|
4986
|
-
|
4987
|
-
if (
|
4988
|
-
|
4989
|
-
|
4990
|
-
|
4991
|
-
|
4992
|
-
|
4993
|
-
|
4994
|
-
|
4995
|
-
|
4766
|
+
if (!data || typeof data !== "object" || !("success" in data)) {
|
4767
|
+
return createError(
|
4768
|
+
"Invalid API response format",
|
4769
|
+
ApiErrorCode.INTERNAL_ERROR,
|
4770
|
+
status,
|
4771
|
+
{ originalResponse: data }
|
4772
|
+
);
|
4773
|
+
}
|
4774
|
+
if (!data.errors || !Array.isArray(data.errors) || data.errors.length === 0) {
|
4775
|
+
return createError(
|
4776
|
+
"Invalid error response format",
|
4777
|
+
ApiErrorCode.INTERNAL_ERROR,
|
4778
|
+
status,
|
4779
|
+
{ originalResponse: data }
|
4780
|
+
);
|
4781
|
+
}
|
4782
|
+
if (data.errors.length === 1) {
|
4783
|
+
const errorDetail = data.errors[0];
|
4784
|
+
if (!errorDetail.message || !errorDetail.code) {
|
4785
|
+
return createError(
|
4786
|
+
"Invalid error detail format",
|
4787
|
+
ApiErrorCode.INTERNAL_ERROR,
|
4788
|
+
status,
|
4789
|
+
{ originalResponse: data }
|
4790
|
+
);
|
4791
|
+
}
|
4792
|
+
const finalDetails = {
|
4793
|
+
...errorDetail.details || {},
|
4794
|
+
...data.meta || {}
|
4795
|
+
};
|
4796
|
+
return createError(
|
4797
|
+
errorDetail.message,
|
4798
|
+
errorDetail.code,
|
4996
4799
|
status,
|
4997
|
-
|
4998
|
-
|
4999
|
-
recoverable
|
4800
|
+
finalDetails,
|
4801
|
+
errorDetail.recoverable ?? false
|
5000
4802
|
);
|
5001
4803
|
} else {
|
5002
|
-
|
5003
|
-
|
5004
|
-
|
5005
|
-
|
4804
|
+
const firstError = data.errors[0];
|
4805
|
+
return createError(
|
4806
|
+
"Multiple errors occurred",
|
4807
|
+
firstError.code,
|
5006
4808
|
status,
|
5007
|
-
|
5008
|
-
|
5009
|
-
|
4809
|
+
{
|
4810
|
+
errors: data.errors,
|
4811
|
+
...data.meta || {},
|
4812
|
+
originalResponse: data
|
4813
|
+
},
|
4814
|
+
false
|
5010
4815
|
);
|
5011
4816
|
}
|
5012
4817
|
}
|
5013
4818
|
function createNetworkError(error, url, timeout) {
|
5014
4819
|
if (error instanceof DOMException && error.name === "AbortError") {
|
5015
|
-
return
|
4820
|
+
return createError(
|
5016
4821
|
`Request timed out after ${timeout}ms`,
|
5017
4822
|
ApiErrorCode.NETWORK_ERROR,
|
5018
4823
|
408,
|
5019
4824
|
{ url }
|
5020
4825
|
);
|
5021
4826
|
}
|
5022
|
-
return
|
4827
|
+
return createError(
|
5023
4828
|
error instanceof Error ? error.message : "An unexpected error occurred during the request",
|
5024
4829
|
ApiErrorCode.INTERNAL_ERROR,
|
5025
4830
|
500,
|
@@ -5042,9 +4847,6 @@ async function makeRequest(method, path, options, data, query) {
|
|
5042
4847
|
url += `?${queryString}`;
|
5043
4848
|
}
|
5044
4849
|
}
|
5045
|
-
if (!options.nearAuthData) {
|
5046
|
-
throw ApiError.unauthorized("Authentication required. Please provide NEAR signature.");
|
5047
|
-
}
|
5048
4850
|
const context = {
|
5049
4851
|
method,
|
5050
4852
|
path,
|
@@ -5075,15 +4877,14 @@ async function makeRequest(method, path, options, data, query) {
|
|
5075
4877
|
responseData = await response.json();
|
5076
4878
|
} catch (jsonError) {
|
5077
4879
|
if (!response.ok) {
|
5078
|
-
throw new
|
4880
|
+
throw new CrosspostError(
|
5079
4881
|
`API request failed with status ${response.status} and non-JSON response`,
|
5080
4882
|
ApiErrorCode.NETWORK_ERROR,
|
5081
4883
|
response.status,
|
5082
4884
|
{ originalStatusText: response.statusText }
|
5083
4885
|
);
|
5084
4886
|
}
|
5085
|
-
|
5086
|
-
throw new ApiError(
|
4887
|
+
throw new CrosspostError(
|
5087
4888
|
`Failed to parse JSON response: ${jsonError instanceof Error ? jsonError.message : String(jsonError)}`,
|
5088
4889
|
ApiErrorCode.INTERNAL_ERROR,
|
5089
4890
|
response.status
|
@@ -5091,23 +4892,26 @@ async function makeRequest(method, path, options, data, query) {
|
|
5091
4892
|
}
|
5092
4893
|
if (!response.ok) {
|
5093
4894
|
lastError = handleErrorResponse(responseData, response.status);
|
5094
|
-
const shouldRetry =
|
4895
|
+
const shouldRetry = lastError instanceof CrosspostError && lastError.code === ApiErrorCode.RATE_LIMITED;
|
5095
4896
|
if (shouldRetry && attempt < options.retries) {
|
5096
4897
|
await new Promise((resolve) => setTimeout(resolve, 1e3 * Math.pow(2, attempt)));
|
5097
4898
|
continue;
|
5098
4899
|
}
|
5099
4900
|
throw lastError;
|
5100
4901
|
}
|
5101
|
-
if (responseData && typeof responseData === "object" && "success" in responseData
|
5102
|
-
|
5103
|
-
|
5104
|
-
|
5105
|
-
|
5106
|
-
|
4902
|
+
if (responseData && typeof responseData === "object" && "success" in responseData) {
|
4903
|
+
if (responseData.success) {
|
4904
|
+
return responseData.data;
|
4905
|
+
} else {
|
4906
|
+
lastError = handleErrorResponse(responseData, response.status);
|
4907
|
+
const shouldRetry = lastError instanceof CrosspostError && lastError.code === ApiErrorCode.RATE_LIMITED;
|
4908
|
+
if (shouldRetry && attempt < options.retries) {
|
4909
|
+
await new Promise((resolve) => setTimeout(resolve, 1e3 * Math.pow(2, attempt)));
|
4910
|
+
continue;
|
4911
|
+
}
|
4912
|
+
throw lastError;
|
5107
4913
|
}
|
5108
|
-
throw lastError;
|
5109
4914
|
}
|
5110
|
-
return responseData;
|
5111
4915
|
} catch (error) {
|
5112
4916
|
clearTimeout(timeoutId);
|
5113
4917
|
lastError = error instanceof Error ? error : new Error(String(error));
|
@@ -5116,13 +4920,13 @@ async function makeRequest(method, path, options, data, query) {
|
|
5116
4920
|
await new Promise((resolve) => setTimeout(resolve, 1e3 * Math.pow(2, attempt)));
|
5117
4921
|
continue;
|
5118
4922
|
}
|
5119
|
-
if (!(error instanceof
|
4923
|
+
if (!(error instanceof CrosspostError)) {
|
5120
4924
|
throw createNetworkError(error, url, options.timeout);
|
5121
4925
|
}
|
5122
4926
|
throw error;
|
5123
4927
|
}
|
5124
4928
|
}
|
5125
|
-
throw lastError || new
|
4929
|
+
throw lastError || new CrosspostError("Request failed after multiple retries", ApiErrorCode.INTERNAL_ERROR, 500);
|
5126
4930
|
}, context);
|
5127
4931
|
}
|
5128
4932
|
|
@@ -5358,7 +5162,7 @@ var PostApi = class {
|
|
5358
5162
|
async likePost(request) {
|
5359
5163
|
return makeRequest(
|
5360
5164
|
"POST",
|
5361
|
-
`/api/post/like
|
5165
|
+
`/api/post/like`,
|
5362
5166
|
this.options,
|
5363
5167
|
request
|
5364
5168
|
);
|
@@ -5371,7 +5175,7 @@ var PostApi = class {
|
|
5371
5175
|
async unlikePost(request) {
|
5372
5176
|
return makeRequest(
|
5373
5177
|
"DELETE",
|
5374
|
-
`/api/post/like
|
5178
|
+
`/api/post/like`,
|
5375
5179
|
this.options,
|
5376
5180
|
request
|
5377
5181
|
);
|
@@ -5382,17 +5186,9 @@ var PostApi = class {
|
|
5382
5186
|
* @returns A promise resolving with the delete response.
|
5383
5187
|
*/
|
5384
5188
|
async deletePost(request) {
|
5385
|
-
const postId = request.posts[0]?.postId || "";
|
5386
|
-
if (!postId) {
|
5387
|
-
throw new ApiError(
|
5388
|
-
"Post ID is required for deletion path",
|
5389
|
-
ApiErrorCode.VALIDATION_ERROR,
|
5390
|
-
400
|
5391
|
-
);
|
5392
|
-
}
|
5393
5189
|
return makeRequest(
|
5394
5190
|
"DELETE",
|
5395
|
-
`/api/post
|
5191
|
+
`/api/post`,
|
5396
5192
|
this.options,
|
5397
5193
|
request
|
5398
5194
|
);
|
@@ -5492,56 +5288,43 @@ export {
|
|
5492
5288
|
AccountActivityEntrySchema,
|
5493
5289
|
AccountActivityParamsSchema,
|
5494
5290
|
AccountActivityQuerySchema,
|
5495
|
-
AccountActivityResponseSchema,
|
5496
5291
|
AccountPostSchema,
|
5497
5292
|
AccountPostsParamsSchema,
|
5498
5293
|
AccountPostsQuerySchema,
|
5499
|
-
AccountPostsResponseSchema,
|
5500
5294
|
ActivityApi,
|
5501
5295
|
ActivityLeaderboardQuerySchema,
|
5502
|
-
ActivityLeaderboardResponseSchema,
|
5503
5296
|
AllRateLimitsResponseSchema,
|
5504
|
-
ApiError,
|
5505
5297
|
ApiErrorCode,
|
5506
|
-
|
5298
|
+
ApiErrorCodeSchema,
|
5507
5299
|
AuthApi,
|
5508
5300
|
AuthCallbackQuerySchema,
|
5509
5301
|
AuthCallbackResponseSchema,
|
5510
5302
|
AuthInitRequestSchema,
|
5511
5303
|
AuthRevokeResponseSchema,
|
5512
5304
|
AuthStatusResponseSchema,
|
5305
|
+
AuthTokenRequestSchema,
|
5513
5306
|
AuthUrlResponseSchema,
|
5514
|
-
BaseError,
|
5515
5307
|
ConnectedAccountSchema,
|
5516
5308
|
ConnectedAccountsResponseSchema,
|
5517
5309
|
CreatePostRequestSchema,
|
5518
|
-
CreatePostResponseLegacySchema,
|
5519
5310
|
CreatePostResponseSchema,
|
5520
|
-
CreatePostTargetErrorSchema,
|
5521
|
-
CreatePostTargetResultSchema,
|
5522
5311
|
CrosspostClient,
|
5523
5312
|
DeletePostRequestSchema,
|
5524
5313
|
DeletePostResponseSchema,
|
5525
5314
|
DeleteResultSchema,
|
5526
|
-
ERROR_CATEGORIES,
|
5527
5315
|
EndpointRateLimitResponseSchema,
|
5528
|
-
EnhancedErrorResponseSchema,
|
5529
|
-
EnhancedResponseMetaSchema,
|
5530
|
-
EnhancedResponseSchema,
|
5531
5316
|
ErrorDetailSchema,
|
5532
|
-
ErrorResponseSchema,
|
5533
5317
|
LikePostRequestSchema,
|
5534
5318
|
LikePostResponseSchema,
|
5535
5319
|
LikeResultSchema,
|
5536
5320
|
MediaContentSchema,
|
5537
5321
|
MediaSchema,
|
5538
|
-
|
5322
|
+
MultiStatusDataSchema,
|
5539
5323
|
NearAuthorizationRequestSchema,
|
5540
5324
|
NearAuthorizationResponseSchema,
|
5541
5325
|
NearAuthorizationStatusResponseSchema,
|
5542
5326
|
Platform,
|
5543
5327
|
PlatformActivitySchema,
|
5544
|
-
PlatformError,
|
5545
5328
|
PlatformParamSchema,
|
5546
5329
|
PlatformRateLimitSchema,
|
5547
5330
|
PlatformSchema,
|
@@ -5555,7 +5338,6 @@ export {
|
|
5555
5338
|
PostSuccessDetailSchema,
|
5556
5339
|
PostToDeleteSchema,
|
5557
5340
|
ProfileRefreshResponseSchema,
|
5558
|
-
ProfileRefreshResultSchema,
|
5559
5341
|
QuotePostRequestSchema,
|
5560
5342
|
QuotePostResponseSchema,
|
5561
5343
|
RateLimitEndpointParamSchema,
|
@@ -5567,6 +5349,7 @@ export {
|
|
5567
5349
|
ReplyToPostResponseSchema,
|
5568
5350
|
RepostRequestSchema,
|
5569
5351
|
RepostResponseSchema,
|
5352
|
+
ResponseMetaSchema,
|
5570
5353
|
SUPPORTED_PLATFORMS,
|
5571
5354
|
SuccessDetailSchema,
|
5572
5355
|
SupportedPlatformSchema,
|
@@ -5578,21 +5361,14 @@ export {
|
|
5578
5361
|
UsageRateLimitSchema,
|
5579
5362
|
UserProfileSchema,
|
5580
5363
|
apiWrapper,
|
5581
|
-
createApiResponse,
|
5582
|
-
createEnhancedApiResponse,
|
5583
|
-
createEnhancedErrorResponse,
|
5584
|
-
createErrorDetail,
|
5585
|
-
createErrorResponse,
|
5586
|
-
createMultiStatusResponse,
|
5587
5364
|
createNetworkError,
|
5588
|
-
createSuccessDetail,
|
5589
5365
|
enrichErrorWithContext,
|
5366
|
+
errorCodeToStatusCode,
|
5590
5367
|
getErrorDetails,
|
5591
5368
|
getErrorMessage,
|
5592
5369
|
handleErrorResponse,
|
5593
5370
|
isAuthError,
|
5594
5371
|
isContentError,
|
5595
|
-
isErrorOfCategory,
|
5596
5372
|
isMediaError,
|
5597
5373
|
isNetworkError,
|
5598
5374
|
isPlatformError,
|