@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 +376 -665
- package/dist/index.d.cts +32 -79
- package/dist/index.d.ts +32 -79
- package/dist/index.js +371 -639
- 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 +150 -247
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,120 +4089,133 @@ 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";
|
|
4251
4096
|
ApiErrorCode2["POST_INTERACTION_FAILED"] = "POST_INTERACTION_FAILED";
|
|
4252
4097
|
ApiErrorCode2["NETWORK_ERROR"] = "NETWORK_ERROR";
|
|
4253
|
-
ApiErrorCode2["MULTI_STATUS"] = "MULTI_STATUS";
|
|
4254
4098
|
return ApiErrorCode2;
|
|
4255
4099
|
})(ApiErrorCode || {});
|
|
4256
|
-
var
|
|
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
|
-
};
|
|
4337
|
-
var PlatformError = class extends Error {
|
|
4338
|
-
constructor(message, platform, code = "PLATFORM_ERROR", recoverable = false, originalError, status, userId, details) {
|
|
4339
|
-
super(message);
|
|
4340
|
-
this.originalError = originalError;
|
|
4341
|
-
this.status = status;
|
|
4342
|
-
this.name = "PlatformError";
|
|
4343
|
-
this.code = code;
|
|
4344
|
-
this.recoverable = recoverable;
|
|
4345
|
-
this.platform = platform;
|
|
4346
|
-
this.userId = userId;
|
|
4347
|
-
this.details = details;
|
|
4348
|
-
}
|
|
4349
|
-
};
|
|
4350
|
-
var CompositeApiError = class extends ApiError {
|
|
4351
|
-
constructor(message, errors, status = 207, details, recoverable = false) {
|
|
4352
|
-
super(
|
|
4353
|
-
message,
|
|
4354
|
-
"MULTI_STATUS",
|
|
4355
|
-
status,
|
|
4356
|
-
{ ...details, errors },
|
|
4357
|
-
recoverable
|
|
4358
|
-
);
|
|
4359
|
-
this.errors = errors;
|
|
4360
|
-
}
|
|
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
|
|
4361
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
|
+
});
|
|
4362
4219
|
var PlatformParamSchema = z.object({
|
|
4363
4220
|
platform: z.string().describe("Social media platform")
|
|
4364
4221
|
}).describe("Platform parameter");
|
|
@@ -4368,44 +4225,37 @@ var AuthInitRequestSchema = z.object({
|
|
|
4368
4225
|
),
|
|
4369
4226
|
errorUrl: z.string().url().optional().describe("URL to redirect to on authentication error")
|
|
4370
4227
|
}).describe("Auth initialization request");
|
|
4371
|
-
var AuthUrlResponseSchema =
|
|
4372
|
-
z.
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
|
|
4376
|
-
})
|
|
4377
|
-
).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");
|
|
4378
4233
|
var AuthCallbackQuerySchema = z.object({
|
|
4379
4234
|
code: z.string().describe("Authorization code from OAuth provider"),
|
|
4380
4235
|
state: z.string().describe("State parameter for CSRF protection")
|
|
4381
4236
|
}).describe("Auth callback query");
|
|
4382
|
-
var AuthCallbackResponseSchema =
|
|
4383
|
-
|
|
4384
|
-
|
|
4385
|
-
|
|
4386
|
-
|
|
4387
|
-
|
|
4388
|
-
|
|
4389
|
-
).describe("
|
|
4390
|
-
|
|
4391
|
-
z.object({
|
|
4392
|
-
|
|
4393
|
-
|
|
4394
|
-
|
|
4395
|
-
tokenStatus: z.object({
|
|
4396
|
-
valid: z.boolean().describe("Whether the token is valid"),
|
|
4397
|
-
expired: z.boolean().describe("Whether the token is expired"),
|
|
4398
|
-
expiresAt: z.string().optional().describe("When the token expires")
|
|
4399
|
-
})
|
|
4400
|
-
})
|
|
4401
|
-
).describe("Auth status response");
|
|
4402
|
-
var AuthRevokeResponseSchema = EnhancedResponseSchema(
|
|
4403
|
-
z.object({
|
|
4404
|
-
success: z.boolean().describe("Whether the revocation was successful"),
|
|
4405
|
-
platform: PlatformSchema,
|
|
4406
|
-
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")
|
|
4407
4250
|
})
|
|
4408
|
-
).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");
|
|
4409
4259
|
var ConnectedAccountSchema = z.object({
|
|
4410
4260
|
platform: PlatformSchema,
|
|
4411
4261
|
userId: z.string().describe("User ID on the platform"),
|
|
@@ -4413,26 +4263,21 @@ var ConnectedAccountSchema = z.object({
|
|
|
4413
4263
|
profileUrl: z.string().optional().describe("URL to the user profile"),
|
|
4414
4264
|
connectedAt: z.string().optional().describe("When the account was connected")
|
|
4415
4265
|
}).describe("Connected account");
|
|
4416
|
-
var ConnectedAccountsResponseSchema =
|
|
4417
|
-
|
|
4418
|
-
)
|
|
4266
|
+
var ConnectedAccountsResponseSchema = z.array(ConnectedAccountSchema).describe(
|
|
4267
|
+
"Connected accounts response"
|
|
4268
|
+
);
|
|
4419
4269
|
var NearAuthorizationRequestSchema = z.object({
|
|
4420
4270
|
// No additional parameters needed, as the NEAR account ID is extracted from the signature
|
|
4421
4271
|
}).describe("NEAR authorization request");
|
|
4422
|
-
var NearAuthorizationResponseSchema =
|
|
4423
|
-
z.
|
|
4424
|
-
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
|
|
4428
|
-
).describe("
|
|
4429
|
-
|
|
4430
|
-
|
|
4431
|
-
nearAccount: z.string().describe("NEAR account ID"),
|
|
4432
|
-
authorized: z.boolean().describe("Whether the account is authorized"),
|
|
4433
|
-
authorizedAt: z.string().optional().describe("When the account was authorized")
|
|
4434
|
-
})
|
|
4435
|
-
).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");
|
|
4436
4281
|
var MediaContentSchema = z.object({
|
|
4437
4282
|
data: z.union([z.string(), z.instanceof(Blob)]).describe("Media data as string or Blob"),
|
|
4438
4283
|
mimeType: z.string().optional().describe("Media MIME type"),
|
|
@@ -4547,65 +4392,33 @@ var UnlikePostRequestSchema = z.object({
|
|
|
4547
4392
|
platform: PlatformSchema.describe("Platform of the post being unliked"),
|
|
4548
4393
|
postId: z.string().describe("ID of the post to unlike")
|
|
4549
4394
|
}).describe("Unlike post request");
|
|
4550
|
-
var PostResponseSchema =
|
|
4551
|
-
|
|
4552
|
-
)
|
|
4553
|
-
var
|
|
4554
|
-
"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"
|
|
4555
4400
|
);
|
|
4556
4401
|
var RepostResponseSchema = PostResponseSchema.describe("Repost response");
|
|
4557
4402
|
var QuotePostResponseSchema = PostResponseSchema.describe("Quote post response");
|
|
4558
4403
|
var ReplyToPostResponseSchema = PostResponseSchema.describe("Reply to post response");
|
|
4559
|
-
var DeletePostResponseSchema =
|
|
4560
|
-
z.
|
|
4561
|
-
|
|
4562
|
-
|
|
4563
|
-
|
|
4564
|
-
).describe("
|
|
4565
|
-
var
|
|
4566
|
-
z.
|
|
4567
|
-
|
|
4568
|
-
id: z.string().describe("ID of the liked post")
|
|
4569
|
-
})
|
|
4570
|
-
).describe("Like post response");
|
|
4571
|
-
var UnlikePostResponseSchema = EnhancedResponseSchema(
|
|
4572
|
-
z.object({
|
|
4573
|
-
success: z.boolean().describe("Whether the unlike was successful"),
|
|
4574
|
-
id: z.string().describe("ID of the unliked post")
|
|
4575
|
-
})
|
|
4576
|
-
).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");
|
|
4577
4413
|
var PostMultiStatusResponseSchema = z.object({
|
|
4578
|
-
|
|
4579
|
-
|
|
4580
|
-
|
|
4581
|
-
|
|
4582
|
-
|
|
4583
|
-
|
|
4584
|
-
|
|
4585
|
-
results: z.array(PostSuccessDetailSchema).describe("Successful operations"),
|
|
4586
|
-
errors: z.array(ErrorDetailSchema).describe("Failed operations")
|
|
4587
|
-
})
|
|
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")
|
|
4588
4421
|
}).describe("Multi-status response for post operations");
|
|
4589
|
-
var CreatePostTargetResultSchema = z.object({
|
|
4590
|
-
platform: PlatformSchema.describe("The platform the post was created on"),
|
|
4591
|
-
userId: z.string().describe("The user ID on the platform"),
|
|
4592
|
-
result: z.array(z.any()).describe("The result of the post creation")
|
|
4593
|
-
}).describe("Create post target result");
|
|
4594
|
-
var CreatePostTargetErrorSchema = z.object({
|
|
4595
|
-
platform: PlatformSchema.optional().describe(
|
|
4596
|
-
"The platform where the error occurred (if applicable)"
|
|
4597
|
-
),
|
|
4598
|
-
userId: z.string().optional().describe("The user ID where the error occurred (if applicable)"),
|
|
4599
|
-
error: z.string().describe("The error message")
|
|
4600
|
-
}).describe("Create post target error");
|
|
4601
|
-
var CreatePostResponseSchema = EnhancedResponseSchema(
|
|
4602
|
-
z.object({
|
|
4603
|
-
results: z.array(CreatePostTargetResultSchema).describe("Array of successful post results"),
|
|
4604
|
-
errors: z.array(CreatePostTargetErrorSchema).optional().describe(
|
|
4605
|
-
"Array of errors that occurred (if any)"
|
|
4606
|
-
)
|
|
4607
|
-
})
|
|
4608
|
-
).describe("Create post response");
|
|
4609
4422
|
var RateLimitEndpointParamSchema = z.object({
|
|
4610
4423
|
endpoint: z.string().optional().describe(
|
|
4611
4424
|
"Specific endpoint to get rate limit information for (optional)"
|
|
@@ -4640,43 +4453,39 @@ var UsageRateLimitSchema = z.object({
|
|
|
4640
4453
|
resetSeconds: z.number().describe("Seconds until the rate limit will reset"),
|
|
4641
4454
|
timeWindow: z.string().describe("Time window for the rate limit")
|
|
4642
4455
|
}).describe("Usage rate limit");
|
|
4643
|
-
var RateLimitStatusResponseSchema =
|
|
4644
|
-
|
|
4645
|
-
|
|
4646
|
-
|
|
4647
|
-
|
|
4648
|
-
|
|
4649
|
-
|
|
4650
|
-
|
|
4651
|
-
|
|
4652
|
-
|
|
4653
|
-
|
|
4654
|
-
|
|
4655
|
-
|
|
4656
|
-
|
|
4657
|
-
|
|
4658
|
-
|
|
4659
|
-
|
|
4660
|
-
|
|
4661
|
-
|
|
4662
|
-
|
|
4663
|
-
|
|
4664
|
-
|
|
4665
|
-
|
|
4666
|
-
|
|
4667
|
-
|
|
4668
|
-
|
|
4669
|
-
).describe("
|
|
4670
|
-
|
|
4671
|
-
|
|
4672
|
-
|
|
4673
|
-
|
|
4674
|
-
|
|
4675
|
-
|
|
4676
|
-
})
|
|
4677
|
-
).describe("Rate limits by platform")
|
|
4678
|
-
})
|
|
4679
|
-
).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");
|
|
4680
4489
|
var RateLimitResponseSchema = z.object({
|
|
4681
4490
|
platformLimits: z.array(PlatformRateLimitSchema).describe("Platform-specific rate limits"),
|
|
4682
4491
|
usageLimits: z.record(z.string(), UsageRateLimitSchema).describe(
|
|
@@ -4721,16 +4530,12 @@ var AccountActivityEntrySchema = z.object({
|
|
|
4721
4530
|
rank: z.number().describe("Rank on the leaderboard"),
|
|
4722
4531
|
lastActive: z.string().datetime().describe("Timestamp of last activity")
|
|
4723
4532
|
}).describe("Account activity entry");
|
|
4724
|
-
var ActivityLeaderboardResponseSchema =
|
|
4725
|
-
z.
|
|
4726
|
-
|
|
4727
|
-
|
|
4728
|
-
|
|
4729
|
-
|
|
4730
|
-
offset: z.number().describe("Offset for pagination"),
|
|
4731
|
-
generatedAt: z.string().datetime().describe("Timestamp when the leaderboard was generated")
|
|
4732
|
-
})
|
|
4733
|
-
).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
|
+
});
|
|
4734
4539
|
var AccountActivityParamsSchema = z.object({
|
|
4735
4540
|
signerId: z.string().describe("NEAR account ID")
|
|
4736
4541
|
}).describe("Account activity params");
|
|
@@ -4749,21 +4554,19 @@ var PlatformActivitySchema = z.object({
|
|
|
4749
4554
|
score: z.number().describe("Activity score on this platform"),
|
|
4750
4555
|
lastActive: z.string().datetime().describe("Timestamp of last activity on this platform")
|
|
4751
4556
|
}).describe("Platform activity");
|
|
4752
|
-
var AccountActivityResponseSchema =
|
|
4753
|
-
z.
|
|
4754
|
-
|
|
4755
|
-
|
|
4756
|
-
|
|
4757
|
-
|
|
4758
|
-
|
|
4759
|
-
|
|
4760
|
-
|
|
4761
|
-
|
|
4762
|
-
|
|
4763
|
-
|
|
4764
|
-
|
|
4765
|
-
})
|
|
4766
|
-
).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
|
+
});
|
|
4767
4570
|
var AccountPostsParamsSchema = z.object({
|
|
4768
4571
|
signerId: z.string().describe("NEAR account ID")
|
|
4769
4572
|
}).describe("Account posts params");
|
|
@@ -4791,19 +4594,14 @@ var AccountPostSchema = z.object({
|
|
|
4791
4594
|
inReplyToId: z.string().optional().describe("ID of the post this is a reply to (if applicable)"),
|
|
4792
4595
|
quotedPostId: z.string().optional().describe("ID of the post this is quoting (if applicable)")
|
|
4793
4596
|
}).describe("Account post");
|
|
4794
|
-
var AccountPostsResponseSchema =
|
|
4795
|
-
z.
|
|
4796
|
-
|
|
4797
|
-
|
|
4798
|
-
|
|
4799
|
-
|
|
4800
|
-
|
|
4801
|
-
|
|
4802
|
-
type: z.enum(["post", "repost", "reply", "quote", "like", "all"]).optional().describe(
|
|
4803
|
-
"Post type filter (if applied)"
|
|
4804
|
-
)
|
|
4805
|
-
})
|
|
4806
|
-
).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
|
+
});
|
|
4807
4605
|
var UserProfileSchema = z.object({
|
|
4808
4606
|
userId: z.string().describe("User ID on the platform"),
|
|
4809
4607
|
username: z.string().describe("Username on the platform"),
|
|
@@ -4813,118 +4611,107 @@ var UserProfileSchema = z.object({
|
|
|
4813
4611
|
platform: PlatformSchema.describe("The platform the user profile is from"),
|
|
4814
4612
|
lastUpdated: z.number().describe("Timestamp when the profile was last updated")
|
|
4815
4613
|
}).describe("User profile");
|
|
4816
|
-
var
|
|
4817
|
-
|
|
4818
|
-
|
|
4819
|
-
error: z.string().optional().describe("Error message (if unsuccessful)")
|
|
4820
|
-
}).describe("Profile refresh result");
|
|
4821
|
-
var ProfileRefreshResponseSchema = EnhancedResponseSchema(
|
|
4822
|
-
ProfileRefreshResultSchema
|
|
4823
|
-
).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");
|
|
4824
4617
|
|
|
4825
4618
|
// src/core/request.ts
|
|
4826
4619
|
import { createAuthToken } from "near-sign-verify";
|
|
4827
4620
|
|
|
4828
4621
|
// src/utils/error.ts
|
|
4829
|
-
var
|
|
4830
|
-
|
|
4831
|
-
|
|
4832
|
-
|
|
4833
|
-
|
|
4834
|
-
|
|
4835
|
-
|
|
4836
|
-
|
|
4837
|
-
],
|
|
4838
|
-
NETWORK: [
|
|
4839
|
-
ApiErrorCode.NETWORK_ERROR
|
|
4840
|
-
],
|
|
4841
|
-
PLATFORM: [
|
|
4842
|
-
ApiErrorCode.PLATFORM_ERROR,
|
|
4843
|
-
ApiErrorCode.PLATFORM_UNAVAILABLE
|
|
4844
|
-
],
|
|
4845
|
-
CONTENT: [
|
|
4846
|
-
ApiErrorCode.CONTENT_POLICY_VIOLATION,
|
|
4847
|
-
ApiErrorCode.DUPLICATE_CONTENT
|
|
4848
|
-
],
|
|
4849
|
-
RATE_LIMIT: [
|
|
4850
|
-
ApiErrorCode.RATE_LIMITED
|
|
4851
|
-
],
|
|
4852
|
-
POST: [
|
|
4853
|
-
ApiErrorCode.POST_CREATION_FAILED,
|
|
4854
|
-
ApiErrorCode.THREAD_CREATION_FAILED,
|
|
4855
|
-
ApiErrorCode.POST_DELETION_FAILED,
|
|
4856
|
-
ApiErrorCode.POST_INTERACTION_FAILED
|
|
4857
|
-
],
|
|
4858
|
-
MEDIA: [
|
|
4859
|
-
ApiErrorCode.MEDIA_UPLOAD_FAILED
|
|
4860
|
-
]
|
|
4861
|
-
};
|
|
4862
|
-
function isErrorOfCategory(error, category) {
|
|
4863
|
-
if (error instanceof ApiError) {
|
|
4864
|
-
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;
|
|
4865
4630
|
}
|
|
4866
|
-
|
|
4867
|
-
|
|
4631
|
+
/**
|
|
4632
|
+
* Get platform from details if available
|
|
4633
|
+
*/
|
|
4634
|
+
get platform() {
|
|
4635
|
+
return this.details?.platform;
|
|
4868
4636
|
}
|
|
4869
|
-
|
|
4870
|
-
|
|
4637
|
+
/**
|
|
4638
|
+
* Get userId from details if available
|
|
4639
|
+
*/
|
|
4640
|
+
get userId() {
|
|
4641
|
+
return this.details?.userId;
|
|
4871
4642
|
}
|
|
4872
|
-
|
|
4643
|
+
};
|
|
4644
|
+
function isErrorCode(error, codes) {
|
|
4645
|
+
return error instanceof CrosspostError && codes.includes(error.code);
|
|
4873
4646
|
}
|
|
4874
4647
|
function isAuthError(error) {
|
|
4875
|
-
return
|
|
4648
|
+
return isErrorCode(error, [
|
|
4649
|
+
ApiErrorCode.UNAUTHORIZED,
|
|
4650
|
+
ApiErrorCode.FORBIDDEN
|
|
4651
|
+
]);
|
|
4876
4652
|
}
|
|
4877
4653
|
function isValidationError(error) {
|
|
4878
|
-
return
|
|
4654
|
+
return isErrorCode(error, [
|
|
4655
|
+
ApiErrorCode.VALIDATION_ERROR,
|
|
4656
|
+
ApiErrorCode.INVALID_REQUEST
|
|
4657
|
+
]);
|
|
4879
4658
|
}
|
|
4880
4659
|
function isNetworkError(error) {
|
|
4881
|
-
return
|
|
4660
|
+
return isErrorCode(error, [
|
|
4661
|
+
ApiErrorCode.NETWORK_ERROR,
|
|
4662
|
+
ApiErrorCode.PLATFORM_UNAVAILABLE
|
|
4663
|
+
]);
|
|
4882
4664
|
}
|
|
4883
4665
|
function isPlatformError(error) {
|
|
4884
|
-
return
|
|
4666
|
+
return error instanceof CrosspostError && !!error.details?.platform;
|
|
4885
4667
|
}
|
|
4886
4668
|
function isContentError(error) {
|
|
4887
|
-
return
|
|
4669
|
+
return isErrorCode(error, [
|
|
4670
|
+
ApiErrorCode.CONTENT_POLICY_VIOLATION,
|
|
4671
|
+
ApiErrorCode.DUPLICATE_CONTENT
|
|
4672
|
+
]);
|
|
4888
4673
|
}
|
|
4889
4674
|
function isRateLimitError(error) {
|
|
4890
|
-
return
|
|
4675
|
+
return isErrorCode(error, [ApiErrorCode.RATE_LIMITED]);
|
|
4891
4676
|
}
|
|
4892
4677
|
function isPostError(error) {
|
|
4893
|
-
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
|
+
]);
|
|
4894
4684
|
}
|
|
4895
4685
|
function isMediaError(error) {
|
|
4896
|
-
return
|
|
4686
|
+
return isErrorCode(error, [ApiErrorCode.MEDIA_UPLOAD_FAILED]);
|
|
4897
4687
|
}
|
|
4898
4688
|
function isRecoverableError(error) {
|
|
4899
|
-
|
|
4900
|
-
return error.recoverable;
|
|
4901
|
-
}
|
|
4902
|
-
return false;
|
|
4689
|
+
return error instanceof CrosspostError && error.recoverable;
|
|
4903
4690
|
}
|
|
4904
4691
|
function getErrorMessage(error, defaultMessage = "An error occurred") {
|
|
4905
4692
|
if (error instanceof Error) {
|
|
4906
4693
|
return error.message || defaultMessage;
|
|
4907
4694
|
}
|
|
4908
|
-
if (typeof error === "string") {
|
|
4909
|
-
return error;
|
|
4910
|
-
}
|
|
4911
|
-
if (error && typeof error === "object" && "message" in error) {
|
|
4912
|
-
return error.message || defaultMessage;
|
|
4913
|
-
}
|
|
4914
4695
|
return defaultMessage;
|
|
4915
4696
|
}
|
|
4916
4697
|
function getErrorDetails(error) {
|
|
4917
|
-
if (error instanceof
|
|
4918
|
-
return error.details;
|
|
4919
|
-
}
|
|
4920
|
-
if (error && typeof error === "object" && "details" in error) {
|
|
4698
|
+
if (error instanceof CrosspostError) {
|
|
4921
4699
|
return error.details;
|
|
4922
4700
|
}
|
|
4923
4701
|
return void 0;
|
|
4924
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
|
+
}
|
|
4925
4712
|
function enrichErrorWithContext(error, context) {
|
|
4926
|
-
if (error instanceof
|
|
4927
|
-
return
|
|
4713
|
+
if (error instanceof CrosspostError) {
|
|
4714
|
+
return createError(
|
|
4928
4715
|
error.message,
|
|
4929
4716
|
error.code,
|
|
4930
4717
|
error.status,
|
|
@@ -4932,25 +4719,12 @@ function enrichErrorWithContext(error, context) {
|
|
|
4932
4719
|
error.recoverable
|
|
4933
4720
|
);
|
|
4934
4721
|
}
|
|
4935
|
-
if (error instanceof PlatformError) {
|
|
4936
|
-
return new PlatformError(
|
|
4937
|
-
error.message,
|
|
4938
|
-
error.platform,
|
|
4939
|
-
error.code,
|
|
4940
|
-
error.recoverable,
|
|
4941
|
-
error.originalError,
|
|
4942
|
-
error.status,
|
|
4943
|
-
error.userId,
|
|
4944
|
-
{ ...error.details || {}, ...context }
|
|
4945
|
-
);
|
|
4946
|
-
}
|
|
4947
4722
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
4948
|
-
return
|
|
4723
|
+
return createError(
|
|
4949
4724
|
errorMessage || "An error occurred",
|
|
4950
4725
|
ApiErrorCode.INTERNAL_ERROR,
|
|
4951
4726
|
500,
|
|
4952
|
-
{ originalError: error, ...context }
|
|
4953
|
-
false
|
|
4727
|
+
{ originalError: error, ...context }
|
|
4954
4728
|
);
|
|
4955
4729
|
}
|
|
4956
4730
|
async function apiWrapper(apiCall, context) {
|
|
@@ -4967,7 +4741,7 @@ async function apiWrapper(apiCall, context) {
|
|
|
4967
4741
|
} catch (jsonError) {
|
|
4968
4742
|
if (jsonError instanceof Error && jsonError.name === "SyntaxError") {
|
|
4969
4743
|
throw enrichErrorWithContext(
|
|
4970
|
-
|
|
4744
|
+
createError(
|
|
4971
4745
|
`API request failed with status ${error.status} and non-JSON response`,
|
|
4972
4746
|
ApiErrorCode.NETWORK_ERROR,
|
|
4973
4747
|
error.status,
|
|
@@ -4979,7 +4753,7 @@ async function apiWrapper(apiCall, context) {
|
|
|
4979
4753
|
throw jsonError;
|
|
4980
4754
|
}
|
|
4981
4755
|
}
|
|
4982
|
-
if (error instanceof
|
|
4756
|
+
if (error instanceof CrosspostError) {
|
|
4983
4757
|
throw enrichErrorWithContext(error, context || {});
|
|
4984
4758
|
}
|
|
4985
4759
|
throw enrichErrorWithContext(
|
|
@@ -4989,80 +4763,68 @@ async function apiWrapper(apiCall, context) {
|
|
|
4989
4763
|
}
|
|
4990
4764
|
}
|
|
4991
4765
|
function handleErrorResponse(data, status) {
|
|
4992
|
-
if (data
|
|
4993
|
-
|
|
4994
|
-
|
|
4995
|
-
|
|
4996
|
-
|
|
4997
|
-
|
|
4998
|
-
|
|
4999
|
-
|
|
5000
|
-
|
|
5001
|
-
|
|
5002
|
-
|
|
5003
|
-
|
|
5004
|
-
|
|
5005
|
-
|
|
5006
|
-
|
|
5007
|
-
|
|
5008
|
-
|
|
5009
|
-
|
|
5010
|
-
|
|
5011
|
-
|
|
5012
|
-
|
|
5013
|
-
|
|
5014
|
-
}
|
|
5015
|
-
} else if (data.errors.length > 1) {
|
|
5016
|
-
return new CompositeApiError(
|
|
5017
|
-
"Multiple errors occurred",
|
|
5018
|
-
data.errors,
|
|
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,
|
|
5019
4788
|
status,
|
|
5020
4789
|
{ originalResponse: data }
|
|
5021
4790
|
);
|
|
5022
4791
|
}
|
|
5023
|
-
|
|
5024
|
-
|
|
5025
|
-
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
|
|
5029
|
-
|
|
5030
|
-
const platform = errorData?.platform || data?.platform;
|
|
5031
|
-
const enhancedDetails = { ...details };
|
|
5032
|
-
if (typeof enhancedDetails === "object" && !enhancedDetails.originalResponse) {
|
|
5033
|
-
enhancedDetails.originalResponse = data;
|
|
5034
|
-
}
|
|
5035
|
-
if (platform && Object.values(Platform).includes(platform)) {
|
|
5036
|
-
return new PlatformError(
|
|
5037
|
-
message,
|
|
5038
|
-
platform,
|
|
5039
|
-
code,
|
|
5040
|
-
recoverable,
|
|
5041
|
-
void 0,
|
|
4792
|
+
const finalDetails = {
|
|
4793
|
+
...errorDetail.details || {},
|
|
4794
|
+
...data.meta || {}
|
|
4795
|
+
};
|
|
4796
|
+
return createError(
|
|
4797
|
+
errorDetail.message,
|
|
4798
|
+
errorDetail.code,
|
|
5042
4799
|
status,
|
|
5043
|
-
|
|
5044
|
-
|
|
4800
|
+
finalDetails,
|
|
4801
|
+
errorDetail.recoverable ?? false
|
|
5045
4802
|
);
|
|
5046
4803
|
} else {
|
|
5047
|
-
|
|
5048
|
-
|
|
5049
|
-
|
|
4804
|
+
const firstError = data.errors[0];
|
|
4805
|
+
return createError(
|
|
4806
|
+
"Multiple errors occurred",
|
|
4807
|
+
firstError.code,
|
|
5050
4808
|
status,
|
|
5051
|
-
|
|
5052
|
-
|
|
4809
|
+
{
|
|
4810
|
+
errors: data.errors,
|
|
4811
|
+
...data.meta || {},
|
|
4812
|
+
originalResponse: data
|
|
4813
|
+
},
|
|
4814
|
+
false
|
|
5053
4815
|
);
|
|
5054
4816
|
}
|
|
5055
4817
|
}
|
|
5056
4818
|
function createNetworkError(error, url, timeout) {
|
|
5057
4819
|
if (error instanceof DOMException && error.name === "AbortError") {
|
|
5058
|
-
return
|
|
4820
|
+
return createError(
|
|
5059
4821
|
`Request timed out after ${timeout}ms`,
|
|
5060
4822
|
ApiErrorCode.NETWORK_ERROR,
|
|
5061
4823
|
408,
|
|
5062
4824
|
{ url }
|
|
5063
4825
|
);
|
|
5064
4826
|
}
|
|
5065
|
-
return
|
|
4827
|
+
return createError(
|
|
5066
4828
|
error instanceof Error ? error.message : "An unexpected error occurred during the request",
|
|
5067
4829
|
ApiErrorCode.INTERNAL_ERROR,
|
|
5068
4830
|
500,
|
|
@@ -5085,9 +4847,6 @@ async function makeRequest(method, path, options, data, query) {
|
|
|
5085
4847
|
url += `?${queryString}`;
|
|
5086
4848
|
}
|
|
5087
4849
|
}
|
|
5088
|
-
if (!options.nearAuthData) {
|
|
5089
|
-
throw ApiError.unauthorized("Authentication required. Please provide NEAR signature.");
|
|
5090
|
-
}
|
|
5091
4850
|
const context = {
|
|
5092
4851
|
method,
|
|
5093
4852
|
path,
|
|
@@ -5118,15 +4877,14 @@ async function makeRequest(method, path, options, data, query) {
|
|
|
5118
4877
|
responseData = await response.json();
|
|
5119
4878
|
} catch (jsonError) {
|
|
5120
4879
|
if (!response.ok) {
|
|
5121
|
-
throw new
|
|
4880
|
+
throw new CrosspostError(
|
|
5122
4881
|
`API request failed with status ${response.status} and non-JSON response`,
|
|
5123
4882
|
ApiErrorCode.NETWORK_ERROR,
|
|
5124
4883
|
response.status,
|
|
5125
4884
|
{ originalStatusText: response.statusText }
|
|
5126
4885
|
);
|
|
5127
4886
|
}
|
|
5128
|
-
|
|
5129
|
-
throw new ApiError(
|
|
4887
|
+
throw new CrosspostError(
|
|
5130
4888
|
`Failed to parse JSON response: ${jsonError instanceof Error ? jsonError.message : String(jsonError)}`,
|
|
5131
4889
|
ApiErrorCode.INTERNAL_ERROR,
|
|
5132
4890
|
response.status
|
|
@@ -5134,23 +4892,26 @@ async function makeRequest(method, path, options, data, query) {
|
|
|
5134
4892
|
}
|
|
5135
4893
|
if (!response.ok) {
|
|
5136
4894
|
lastError = handleErrorResponse(responseData, response.status);
|
|
5137
|
-
const shouldRetry =
|
|
4895
|
+
const shouldRetry = lastError instanceof CrosspostError && lastError.code === ApiErrorCode.RATE_LIMITED;
|
|
5138
4896
|
if (shouldRetry && attempt < options.retries) {
|
|
5139
4897
|
await new Promise((resolve) => setTimeout(resolve, 1e3 * Math.pow(2, attempt)));
|
|
5140
4898
|
continue;
|
|
5141
4899
|
}
|
|
5142
4900
|
throw lastError;
|
|
5143
4901
|
}
|
|
5144
|
-
if (responseData && typeof responseData === "object" && "success" in responseData
|
|
5145
|
-
|
|
5146
|
-
|
|
5147
|
-
|
|
5148
|
-
|
|
5149
|
-
|
|
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;
|
|
5150
4913
|
}
|
|
5151
|
-
throw lastError;
|
|
5152
4914
|
}
|
|
5153
|
-
return responseData;
|
|
5154
4915
|
} catch (error) {
|
|
5155
4916
|
clearTimeout(timeoutId);
|
|
5156
4917
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
@@ -5159,13 +4920,13 @@ async function makeRequest(method, path, options, data, query) {
|
|
|
5159
4920
|
await new Promise((resolve) => setTimeout(resolve, 1e3 * Math.pow(2, attempt)));
|
|
5160
4921
|
continue;
|
|
5161
4922
|
}
|
|
5162
|
-
if (!(error instanceof
|
|
4923
|
+
if (!(error instanceof CrosspostError)) {
|
|
5163
4924
|
throw createNetworkError(error, url, options.timeout);
|
|
5164
4925
|
}
|
|
5165
4926
|
throw error;
|
|
5166
4927
|
}
|
|
5167
4928
|
}
|
|
5168
|
-
throw lastError || new
|
|
4929
|
+
throw lastError || new CrosspostError("Request failed after multiple retries", ApiErrorCode.INTERNAL_ERROR, 500);
|
|
5169
4930
|
}, context);
|
|
5170
4931
|
}
|
|
5171
4932
|
|
|
@@ -5401,7 +5162,7 @@ var PostApi = class {
|
|
|
5401
5162
|
async likePost(request) {
|
|
5402
5163
|
return makeRequest(
|
|
5403
5164
|
"POST",
|
|
5404
|
-
`/api/post/like
|
|
5165
|
+
`/api/post/like`,
|
|
5405
5166
|
this.options,
|
|
5406
5167
|
request
|
|
5407
5168
|
);
|
|
@@ -5414,7 +5175,7 @@ var PostApi = class {
|
|
|
5414
5175
|
async unlikePost(request) {
|
|
5415
5176
|
return makeRequest(
|
|
5416
5177
|
"DELETE",
|
|
5417
|
-
`/api/post/like
|
|
5178
|
+
`/api/post/like`,
|
|
5418
5179
|
this.options,
|
|
5419
5180
|
request
|
|
5420
5181
|
);
|
|
@@ -5425,17 +5186,9 @@ var PostApi = class {
|
|
|
5425
5186
|
* @returns A promise resolving with the delete response.
|
|
5426
5187
|
*/
|
|
5427
5188
|
async deletePost(request) {
|
|
5428
|
-
const postId = request.posts[0]?.postId || "";
|
|
5429
|
-
if (!postId) {
|
|
5430
|
-
throw new ApiError(
|
|
5431
|
-
"Post ID is required for deletion path",
|
|
5432
|
-
ApiErrorCode.VALIDATION_ERROR,
|
|
5433
|
-
400
|
|
5434
|
-
);
|
|
5435
|
-
}
|
|
5436
5189
|
return makeRequest(
|
|
5437
5190
|
"DELETE",
|
|
5438
|
-
`/api/post
|
|
5191
|
+
`/api/post`,
|
|
5439
5192
|
this.options,
|
|
5440
5193
|
request
|
|
5441
5194
|
);
|
|
@@ -5535,57 +5288,43 @@ export {
|
|
|
5535
5288
|
AccountActivityEntrySchema,
|
|
5536
5289
|
AccountActivityParamsSchema,
|
|
5537
5290
|
AccountActivityQuerySchema,
|
|
5538
|
-
AccountActivityResponseSchema,
|
|
5539
5291
|
AccountPostSchema,
|
|
5540
5292
|
AccountPostsParamsSchema,
|
|
5541
5293
|
AccountPostsQuerySchema,
|
|
5542
|
-
AccountPostsResponseSchema,
|
|
5543
5294
|
ActivityApi,
|
|
5544
5295
|
ActivityLeaderboardQuerySchema,
|
|
5545
|
-
ActivityLeaderboardResponseSchema,
|
|
5546
5296
|
AllRateLimitsResponseSchema,
|
|
5547
|
-
ApiError,
|
|
5548
5297
|
ApiErrorCode,
|
|
5549
|
-
|
|
5298
|
+
ApiErrorCodeSchema,
|
|
5550
5299
|
AuthApi,
|
|
5551
5300
|
AuthCallbackQuerySchema,
|
|
5552
5301
|
AuthCallbackResponseSchema,
|
|
5553
5302
|
AuthInitRequestSchema,
|
|
5554
5303
|
AuthRevokeResponseSchema,
|
|
5555
5304
|
AuthStatusResponseSchema,
|
|
5305
|
+
AuthTokenRequestSchema,
|
|
5556
5306
|
AuthUrlResponseSchema,
|
|
5557
|
-
BaseError,
|
|
5558
|
-
CompositeApiError,
|
|
5559
5307
|
ConnectedAccountSchema,
|
|
5560
5308
|
ConnectedAccountsResponseSchema,
|
|
5561
5309
|
CreatePostRequestSchema,
|
|
5562
|
-
CreatePostResponseLegacySchema,
|
|
5563
5310
|
CreatePostResponseSchema,
|
|
5564
|
-
CreatePostTargetErrorSchema,
|
|
5565
|
-
CreatePostTargetResultSchema,
|
|
5566
5311
|
CrosspostClient,
|
|
5567
5312
|
DeletePostRequestSchema,
|
|
5568
5313
|
DeletePostResponseSchema,
|
|
5569
5314
|
DeleteResultSchema,
|
|
5570
|
-
ERROR_CATEGORIES,
|
|
5571
5315
|
EndpointRateLimitResponseSchema,
|
|
5572
|
-
EnhancedErrorResponseSchema,
|
|
5573
|
-
EnhancedResponseMetaSchema,
|
|
5574
|
-
EnhancedResponseSchema,
|
|
5575
5316
|
ErrorDetailSchema,
|
|
5576
|
-
ErrorResponseSchema,
|
|
5577
5317
|
LikePostRequestSchema,
|
|
5578
5318
|
LikePostResponseSchema,
|
|
5579
5319
|
LikeResultSchema,
|
|
5580
5320
|
MediaContentSchema,
|
|
5581
5321
|
MediaSchema,
|
|
5582
|
-
|
|
5322
|
+
MultiStatusDataSchema,
|
|
5583
5323
|
NearAuthorizationRequestSchema,
|
|
5584
5324
|
NearAuthorizationResponseSchema,
|
|
5585
5325
|
NearAuthorizationStatusResponseSchema,
|
|
5586
5326
|
Platform,
|
|
5587
5327
|
PlatformActivitySchema,
|
|
5588
|
-
PlatformError,
|
|
5589
5328
|
PlatformParamSchema,
|
|
5590
5329
|
PlatformRateLimitSchema,
|
|
5591
5330
|
PlatformSchema,
|
|
@@ -5599,7 +5338,6 @@ export {
|
|
|
5599
5338
|
PostSuccessDetailSchema,
|
|
5600
5339
|
PostToDeleteSchema,
|
|
5601
5340
|
ProfileRefreshResponseSchema,
|
|
5602
|
-
ProfileRefreshResultSchema,
|
|
5603
5341
|
QuotePostRequestSchema,
|
|
5604
5342
|
QuotePostResponseSchema,
|
|
5605
5343
|
RateLimitEndpointParamSchema,
|
|
@@ -5611,6 +5349,7 @@ export {
|
|
|
5611
5349
|
ReplyToPostResponseSchema,
|
|
5612
5350
|
RepostRequestSchema,
|
|
5613
5351
|
RepostResponseSchema,
|
|
5352
|
+
ResponseMetaSchema,
|
|
5614
5353
|
SUPPORTED_PLATFORMS,
|
|
5615
5354
|
SuccessDetailSchema,
|
|
5616
5355
|
SupportedPlatformSchema,
|
|
@@ -5622,21 +5361,14 @@ export {
|
|
|
5622
5361
|
UsageRateLimitSchema,
|
|
5623
5362
|
UserProfileSchema,
|
|
5624
5363
|
apiWrapper,
|
|
5625
|
-
createApiResponse,
|
|
5626
|
-
createEnhancedApiResponse,
|
|
5627
|
-
createEnhancedErrorResponse,
|
|
5628
|
-
createErrorDetail,
|
|
5629
|
-
createErrorResponse,
|
|
5630
|
-
createMultiStatusResponse,
|
|
5631
5364
|
createNetworkError,
|
|
5632
|
-
createSuccessDetail,
|
|
5633
5365
|
enrichErrorWithContext,
|
|
5366
|
+
errorCodeToStatusCode,
|
|
5634
5367
|
getErrorDetails,
|
|
5635
5368
|
getErrorMessage,
|
|
5636
5369
|
handleErrorResponse,
|
|
5637
5370
|
isAuthError,
|
|
5638
5371
|
isContentError,
|
|
5639
|
-
isErrorOfCategory,
|
|
5640
5372
|
isMediaError,
|
|
5641
5373
|
isNetworkError,
|
|
5642
5374
|
isPlatformError,
|