@crosspost/sdk 0.1.6 → 0.1.8
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 +484 -681
- package/dist/index.d.cts +70 -89
- package/dist/index.d.ts +70 -89
- package/dist/index.js +476 -655
- package/package.json +1 -1
- package/src/api/activity.ts +3 -3
- package/src/api/auth.ts +44 -18
- package/src/api/post.ts +10 -22
- package/src/api/system.ts +12 -5
- package/src/core/client.ts +40 -1
- package/src/core/request.ts +71 -39
- 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,138 @@ 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 HealthStatusSchema = z.object({
|
|
4211
|
+
status: z.string().describe("Health status of the API"),
|
|
4212
|
+
version: z.string().optional().describe("API version"),
|
|
4213
|
+
timestamp: z.string().datetime().describe("Current server time")
|
|
4214
|
+
}).describe("Health status response");
|
|
4215
|
+
var MultiStatusDataSchema = z.object({
|
|
4216
|
+
summary: z.object({
|
|
4217
|
+
total: z.number().int().nonnegative(),
|
|
4218
|
+
succeeded: z.number().int().nonnegative(),
|
|
4219
|
+
failed: z.number().int().nonnegative()
|
|
4220
|
+
}),
|
|
4221
|
+
results: z.array(SuccessDetailSchema),
|
|
4222
|
+
errors: z.array(ErrorDetailSchema)
|
|
4223
|
+
});
|
|
4362
4224
|
var PlatformParamSchema = z.object({
|
|
4363
4225
|
platform: z.string().describe("Social media platform")
|
|
4364
4226
|
}).describe("Platform parameter");
|
|
@@ -4368,44 +4230,45 @@ var AuthInitRequestSchema = z.object({
|
|
|
4368
4230
|
),
|
|
4369
4231
|
errorUrl: z.string().url().optional().describe("URL to redirect to on authentication error")
|
|
4370
4232
|
}).describe("Auth initialization request");
|
|
4371
|
-
var AuthUrlResponseSchema =
|
|
4372
|
-
z.
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
|
|
4376
|
-
})
|
|
4377
|
-
).describe("Auth URL response");
|
|
4233
|
+
var AuthUrlResponseSchema = z.object({
|
|
4234
|
+
url: z.string().describe("Authentication URL to redirect the user to"),
|
|
4235
|
+
state: z.string().describe("State parameter for CSRF protection"),
|
|
4236
|
+
platform: PlatformSchema
|
|
4237
|
+
}).describe("Auth URL response");
|
|
4378
4238
|
var AuthCallbackQuerySchema = z.object({
|
|
4379
4239
|
code: z.string().describe("Authorization code from OAuth provider"),
|
|
4380
4240
|
state: z.string().describe("State parameter for CSRF protection")
|
|
4381
4241
|
}).describe("Auth callback query");
|
|
4382
|
-
var AuthCallbackResponseSchema =
|
|
4383
|
-
|
|
4384
|
-
|
|
4385
|
-
|
|
4386
|
-
|
|
4387
|
-
|
|
4388
|
-
|
|
4389
|
-
).describe("
|
|
4390
|
-
|
|
4391
|
-
|
|
4392
|
-
|
|
4393
|
-
|
|
4394
|
-
|
|
4395
|
-
|
|
4396
|
-
|
|
4397
|
-
|
|
4398
|
-
|
|
4399
|
-
|
|
4400
|
-
|
|
4401
|
-
).describe("
|
|
4402
|
-
|
|
4403
|
-
z.object({
|
|
4404
|
-
success: z.boolean().describe("Whether the revocation was successful"),
|
|
4405
|
-
platform: PlatformSchema,
|
|
4406
|
-
userId: z.string().describe("User ID")
|
|
4242
|
+
var AuthCallbackResponseSchema = z.object({
|
|
4243
|
+
platform: PlatformSchema,
|
|
4244
|
+
userId: z.string().describe("User ID"),
|
|
4245
|
+
redirectUrl: z.string().optional().describe("URL to redirect the user to after authentication")
|
|
4246
|
+
}).describe("Auth callback response");
|
|
4247
|
+
var AuthStatusParamsSchema = z.object({
|
|
4248
|
+
platform: z.string().describe("Social media platform"),
|
|
4249
|
+
userId: z.string().describe("User ID on the platform")
|
|
4250
|
+
}).describe("Token status parameters");
|
|
4251
|
+
var NearUnauthorizationResponseSchema = z.object({
|
|
4252
|
+
success: z.boolean().describe("Whether the unauthorized operation was successful"),
|
|
4253
|
+
nearAccount: z.string().describe("NEAR account ID that was unauthorized")
|
|
4254
|
+
}).describe("NEAR unauthorized response");
|
|
4255
|
+
var AuthStatusResponseSchema = z.object({
|
|
4256
|
+
platform: PlatformSchema,
|
|
4257
|
+
userId: z.string().describe("User ID"),
|
|
4258
|
+
authenticated: z.boolean().describe("Whether the user is authenticated"),
|
|
4259
|
+
tokenStatus: z.object({
|
|
4260
|
+
valid: z.boolean().describe("Whether the token is valid"),
|
|
4261
|
+
expired: z.boolean().describe("Whether the token is expired"),
|
|
4262
|
+
expiresAt: z.string().optional().describe("When the token expires")
|
|
4407
4263
|
})
|
|
4408
|
-
).describe("Auth
|
|
4264
|
+
}).describe("Auth status response");
|
|
4265
|
+
var AuthTokenRequestSchema = z.object({
|
|
4266
|
+
userId: z.string().describe("User ID on the platform")
|
|
4267
|
+
}).describe("Auth token request");
|
|
4268
|
+
var AuthRevokeResponseSchema = z.object({
|
|
4269
|
+
platform: PlatformSchema,
|
|
4270
|
+
userId: z.string().describe("User ID")
|
|
4271
|
+
}).describe("Auth revoke response");
|
|
4409
4272
|
var ConnectedAccountSchema = z.object({
|
|
4410
4273
|
platform: PlatformSchema,
|
|
4411
4274
|
userId: z.string().describe("User ID on the platform"),
|
|
@@ -4413,26 +4276,21 @@ var ConnectedAccountSchema = z.object({
|
|
|
4413
4276
|
profileUrl: z.string().optional().describe("URL to the user profile"),
|
|
4414
4277
|
connectedAt: z.string().optional().describe("When the account was connected")
|
|
4415
4278
|
}).describe("Connected account");
|
|
4416
|
-
var ConnectedAccountsResponseSchema =
|
|
4417
|
-
|
|
4418
|
-
)
|
|
4279
|
+
var ConnectedAccountsResponseSchema = z.array(ConnectedAccountSchema).describe(
|
|
4280
|
+
"Connected accounts response"
|
|
4281
|
+
);
|
|
4419
4282
|
var NearAuthorizationRequestSchema = z.object({
|
|
4420
4283
|
// No additional parameters needed, as the NEAR account ID is extracted from the signature
|
|
4421
4284
|
}).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");
|
|
4285
|
+
var NearAuthorizationResponseSchema = z.object({
|
|
4286
|
+
nearAccount: z.string().describe("NEAR account ID"),
|
|
4287
|
+
authorized: z.boolean().describe("Whether the account is authorized")
|
|
4288
|
+
}).describe("NEAR authorization response");
|
|
4289
|
+
var NearAuthorizationStatusResponseSchema = z.object({
|
|
4290
|
+
nearAccount: z.string().describe("NEAR account ID"),
|
|
4291
|
+
authorized: z.boolean().describe("Whether the account is authorized"),
|
|
4292
|
+
authorizedAt: z.string().optional().describe("When the account was authorized")
|
|
4293
|
+
}).describe("NEAR authorization status response");
|
|
4436
4294
|
var MediaContentSchema = z.object({
|
|
4437
4295
|
data: z.union([z.string(), z.instanceof(Blob)]).describe("Media data as string or Blob"),
|
|
4438
4296
|
mimeType: z.string().optional().describe("Media MIME type"),
|
|
@@ -4547,65 +4405,33 @@ var UnlikePostRequestSchema = z.object({
|
|
|
4547
4405
|
platform: PlatformSchema.describe("Platform of the post being unliked"),
|
|
4548
4406
|
postId: z.string().describe("ID of the post to unlike")
|
|
4549
4407
|
}).describe("Unlike post request");
|
|
4550
|
-
var PostResponseSchema =
|
|
4551
|
-
|
|
4552
|
-
)
|
|
4553
|
-
var
|
|
4554
|
-
"Create post response
|
|
4408
|
+
var PostResponseSchema = z.union([PostSchema, z.array(PostSchema)]).describe(
|
|
4409
|
+
"Post response"
|
|
4410
|
+
);
|
|
4411
|
+
var CreatePostResponseSchema = PostResponseSchema.describe(
|
|
4412
|
+
"Create post response"
|
|
4555
4413
|
);
|
|
4556
4414
|
var RepostResponseSchema = PostResponseSchema.describe("Repost response");
|
|
4557
4415
|
var QuotePostResponseSchema = PostResponseSchema.describe("Quote post response");
|
|
4558
4416
|
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");
|
|
4417
|
+
var DeletePostResponseSchema = z.object({
|
|
4418
|
+
id: z.string().describe("ID of the deleted post")
|
|
4419
|
+
}).describe("Delete post response");
|
|
4420
|
+
var LikePostResponseSchema = z.object({
|
|
4421
|
+
id: z.string().describe("ID of the liked post")
|
|
4422
|
+
}).describe("Like post response");
|
|
4423
|
+
var UnlikePostResponseSchema = z.object({
|
|
4424
|
+
id: z.string().describe("ID of the unliked post")
|
|
4425
|
+
}).describe("Unlike post response");
|
|
4577
4426
|
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
|
-
})
|
|
4427
|
+
summary: z.object({
|
|
4428
|
+
total: z.number().describe("Total number of operations"),
|
|
4429
|
+
succeeded: z.number().describe("Number of successful operations"),
|
|
4430
|
+
failed: z.number().describe("Number of failed operations")
|
|
4431
|
+
}),
|
|
4432
|
+
results: z.array(PostSuccessDetailSchema).describe("Successful operations"),
|
|
4433
|
+
errors: z.array(ErrorDetailSchema).describe("Failed operations")
|
|
4588
4434
|
}).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
4435
|
var RateLimitEndpointParamSchema = z.object({
|
|
4610
4436
|
endpoint: z.string().optional().describe(
|
|
4611
4437
|
"Specific endpoint to get rate limit information for (optional)"
|
|
@@ -4640,43 +4466,39 @@ var UsageRateLimitSchema = z.object({
|
|
|
4640
4466
|
resetSeconds: z.number().describe("Seconds until the rate limit will reset"),
|
|
4641
4467
|
timeWindow: z.string().describe("Time window for the rate limit")
|
|
4642
4468
|
}).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");
|
|
4469
|
+
var RateLimitStatusResponseSchema = z.object({
|
|
4470
|
+
platform: PlatformSchema,
|
|
4471
|
+
userId: z.string().optional().describe("User ID"),
|
|
4472
|
+
endpoints: z.array(RateLimitEndpointSchema).describe("Rate limits for specific endpoints"),
|
|
4473
|
+
app: z.object({
|
|
4474
|
+
limit: z.number().describe("App-wide rate limit"),
|
|
4475
|
+
remaining: z.number().describe("Remaining requests"),
|
|
4476
|
+
reset: z.number().describe("Reset timestamp (Unix timestamp in seconds)"),
|
|
4477
|
+
resetDate: z.string().describe("Reset date (ISO string)")
|
|
4478
|
+
}).optional().describe("App-wide rate limits")
|
|
4479
|
+
}).describe("Rate limit status response");
|
|
4480
|
+
var AllRateLimitsResponseSchema = z.object({
|
|
4481
|
+
platforms: z.record(
|
|
4482
|
+
PlatformSchema,
|
|
4483
|
+
z.object({
|
|
4484
|
+
users: z.record(
|
|
4485
|
+
z.string(),
|
|
4486
|
+
z.object({
|
|
4487
|
+
endpoints: z.array(RateLimitEndpointSchema).describe(
|
|
4488
|
+
"Rate limits for specific endpoints"
|
|
4489
|
+
),
|
|
4490
|
+
lastUpdated: z.string().describe("Last updated date (ISO string)")
|
|
4491
|
+
})
|
|
4492
|
+
).describe("User-specific rate limits"),
|
|
4493
|
+
app: z.object({
|
|
4494
|
+
limit: z.number().describe("App-wide rate limit"),
|
|
4495
|
+
remaining: z.number().describe("Remaining requests"),
|
|
4496
|
+
reset: z.number().describe("Reset timestamp (Unix timestamp in seconds)"),
|
|
4497
|
+
resetDate: z.string().describe("Reset date (ISO string)")
|
|
4498
|
+
}).optional().describe("App-wide rate limits")
|
|
4499
|
+
})
|
|
4500
|
+
).describe("Rate limits by platform")
|
|
4501
|
+
}).describe("All rate limits response");
|
|
4680
4502
|
var RateLimitResponseSchema = z.object({
|
|
4681
4503
|
platformLimits: z.array(PlatformRateLimitSchema).describe("Platform-specific rate limits"),
|
|
4682
4504
|
usageLimits: z.record(z.string(), UsageRateLimitSchema).describe(
|
|
@@ -4721,16 +4543,12 @@ var AccountActivityEntrySchema = z.object({
|
|
|
4721
4543
|
rank: z.number().describe("Rank on the leaderboard"),
|
|
4722
4544
|
lastActive: z.string().datetime().describe("Timestamp of last activity")
|
|
4723
4545
|
}).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");
|
|
4546
|
+
var ActivityLeaderboardResponseSchema = z.object({
|
|
4547
|
+
timeframe: z.nativeEnum(TimePeriod).describe("Timeframe for the leaderboard"),
|
|
4548
|
+
entries: z.array(AccountActivityEntrySchema).describe("Leaderboard entries"),
|
|
4549
|
+
generatedAt: z.string().datetime().describe("Timestamp when the leaderboard was generated"),
|
|
4550
|
+
platform: PlatformSchema.optional().describe("Platform filter (if applied)")
|
|
4551
|
+
});
|
|
4734
4552
|
var AccountActivityParamsSchema = z.object({
|
|
4735
4553
|
signerId: z.string().describe("NEAR account ID")
|
|
4736
4554
|
}).describe("Account activity params");
|
|
@@ -4749,21 +4567,19 @@ var PlatformActivitySchema = z.object({
|
|
|
4749
4567
|
score: z.number().describe("Activity score on this platform"),
|
|
4750
4568
|
lastActive: z.string().datetime().describe("Timestamp of last activity on this platform")
|
|
4751
4569
|
}).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");
|
|
4570
|
+
var AccountActivityResponseSchema = z.object({
|
|
4571
|
+
signerId: z.string().describe("NEAR account ID"),
|
|
4572
|
+
timeframe: z.nativeEnum(TimePeriod).describe("Timeframe for the activity"),
|
|
4573
|
+
totalPosts: z.number().describe("Total number of posts across all platforms"),
|
|
4574
|
+
totalLikes: z.number().describe("Total number of likes across all platforms"),
|
|
4575
|
+
totalReposts: z.number().describe("Total number of reposts across all platforms"),
|
|
4576
|
+
totalReplies: z.number().describe("Total number of replies across all platforms"),
|
|
4577
|
+
totalQuotes: z.number().describe("Total number of quote posts across all platforms"),
|
|
4578
|
+
totalScore: z.number().describe("Total activity score across all platforms"),
|
|
4579
|
+
rank: z.number().describe("Rank on the leaderboard"),
|
|
4580
|
+
lastActive: z.string().datetime().describe("Timestamp of last activity across all platforms"),
|
|
4581
|
+
platforms: z.array(PlatformActivitySchema).describe("Activity breakdown by platform")
|
|
4582
|
+
});
|
|
4767
4583
|
var AccountPostsParamsSchema = z.object({
|
|
4768
4584
|
signerId: z.string().describe("NEAR account ID")
|
|
4769
4585
|
}).describe("Account posts params");
|
|
@@ -4791,19 +4607,14 @@ var AccountPostSchema = z.object({
|
|
|
4791
4607
|
inReplyToId: z.string().optional().describe("ID of the post this is a reply to (if applicable)"),
|
|
4792
4608
|
quotedPostId: z.string().optional().describe("ID of the post this is quoting (if applicable)")
|
|
4793
4609
|
}).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");
|
|
4610
|
+
var AccountPostsResponseSchema = z.object({
|
|
4611
|
+
signerId: z.string().describe("NEAR account ID"),
|
|
4612
|
+
posts: z.array(AccountPostSchema).describe("List of posts"),
|
|
4613
|
+
platform: z.string().optional().describe("Platform filter (if applied)"),
|
|
4614
|
+
type: z.enum(["post", "repost", "reply", "quote", "like", "all"]).optional().describe(
|
|
4615
|
+
"Post type filter (if applied)"
|
|
4616
|
+
)
|
|
4617
|
+
});
|
|
4807
4618
|
var UserProfileSchema = z.object({
|
|
4808
4619
|
userId: z.string().describe("User ID on the platform"),
|
|
4809
4620
|
username: z.string().describe("Username on the platform"),
|
|
@@ -4813,118 +4624,107 @@ var UserProfileSchema = z.object({
|
|
|
4813
4624
|
platform: PlatformSchema.describe("The platform the user profile is from"),
|
|
4814
4625
|
lastUpdated: z.number().describe("Timestamp when the profile was last updated")
|
|
4815
4626
|
}).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");
|
|
4627
|
+
var ProfileRefreshResponseSchema = z.object({
|
|
4628
|
+
profile: UserProfileSchema.optional().describe("The refreshed user profile (if successful)")
|
|
4629
|
+
}).describe("Profile refresh response");
|
|
4824
4630
|
|
|
4825
4631
|
// src/core/request.ts
|
|
4826
4632
|
import { createAuthToken } from "near-sign-verify";
|
|
4827
4633
|
|
|
4828
4634
|
// 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);
|
|
4635
|
+
var CrosspostError = class extends Error {
|
|
4636
|
+
constructor(message, code, status, details, recoverable = false) {
|
|
4637
|
+
super(message);
|
|
4638
|
+
this.name = "CrosspostError";
|
|
4639
|
+
this.code = code;
|
|
4640
|
+
this.status = status;
|
|
4641
|
+
this.details = details;
|
|
4642
|
+
this.recoverable = recoverable;
|
|
4865
4643
|
}
|
|
4866
|
-
|
|
4867
|
-
|
|
4644
|
+
/**
|
|
4645
|
+
* Get platform from details if available
|
|
4646
|
+
*/
|
|
4647
|
+
get platform() {
|
|
4648
|
+
return this.details?.platform;
|
|
4868
4649
|
}
|
|
4869
|
-
|
|
4870
|
-
|
|
4650
|
+
/**
|
|
4651
|
+
* Get userId from details if available
|
|
4652
|
+
*/
|
|
4653
|
+
get userId() {
|
|
4654
|
+
return this.details?.userId;
|
|
4871
4655
|
}
|
|
4872
|
-
|
|
4656
|
+
};
|
|
4657
|
+
function isErrorCode(error, codes) {
|
|
4658
|
+
return error instanceof CrosspostError && codes.includes(error.code);
|
|
4873
4659
|
}
|
|
4874
4660
|
function isAuthError(error) {
|
|
4875
|
-
return
|
|
4661
|
+
return isErrorCode(error, [
|
|
4662
|
+
ApiErrorCode.UNAUTHORIZED,
|
|
4663
|
+
ApiErrorCode.FORBIDDEN
|
|
4664
|
+
]);
|
|
4876
4665
|
}
|
|
4877
4666
|
function isValidationError(error) {
|
|
4878
|
-
return
|
|
4667
|
+
return isErrorCode(error, [
|
|
4668
|
+
ApiErrorCode.VALIDATION_ERROR,
|
|
4669
|
+
ApiErrorCode.INVALID_REQUEST
|
|
4670
|
+
]);
|
|
4879
4671
|
}
|
|
4880
4672
|
function isNetworkError(error) {
|
|
4881
|
-
return
|
|
4673
|
+
return isErrorCode(error, [
|
|
4674
|
+
ApiErrorCode.NETWORK_ERROR,
|
|
4675
|
+
ApiErrorCode.PLATFORM_UNAVAILABLE
|
|
4676
|
+
]);
|
|
4882
4677
|
}
|
|
4883
4678
|
function isPlatformError(error) {
|
|
4884
|
-
return
|
|
4679
|
+
return error instanceof CrosspostError && !!error.details?.platform;
|
|
4885
4680
|
}
|
|
4886
4681
|
function isContentError(error) {
|
|
4887
|
-
return
|
|
4682
|
+
return isErrorCode(error, [
|
|
4683
|
+
ApiErrorCode.CONTENT_POLICY_VIOLATION,
|
|
4684
|
+
ApiErrorCode.DUPLICATE_CONTENT
|
|
4685
|
+
]);
|
|
4888
4686
|
}
|
|
4889
4687
|
function isRateLimitError(error) {
|
|
4890
|
-
return
|
|
4688
|
+
return isErrorCode(error, [ApiErrorCode.RATE_LIMITED]);
|
|
4891
4689
|
}
|
|
4892
4690
|
function isPostError(error) {
|
|
4893
|
-
return
|
|
4691
|
+
return isErrorCode(error, [
|
|
4692
|
+
ApiErrorCode.POST_CREATION_FAILED,
|
|
4693
|
+
ApiErrorCode.THREAD_CREATION_FAILED,
|
|
4694
|
+
ApiErrorCode.POST_DELETION_FAILED,
|
|
4695
|
+
ApiErrorCode.POST_INTERACTION_FAILED
|
|
4696
|
+
]);
|
|
4894
4697
|
}
|
|
4895
4698
|
function isMediaError(error) {
|
|
4896
|
-
return
|
|
4699
|
+
return isErrorCode(error, [ApiErrorCode.MEDIA_UPLOAD_FAILED]);
|
|
4897
4700
|
}
|
|
4898
4701
|
function isRecoverableError(error) {
|
|
4899
|
-
|
|
4900
|
-
return error.recoverable;
|
|
4901
|
-
}
|
|
4902
|
-
return false;
|
|
4702
|
+
return error instanceof CrosspostError && error.recoverable;
|
|
4903
4703
|
}
|
|
4904
4704
|
function getErrorMessage(error, defaultMessage = "An error occurred") {
|
|
4905
4705
|
if (error instanceof Error) {
|
|
4906
4706
|
return error.message || defaultMessage;
|
|
4907
4707
|
}
|
|
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
4708
|
return defaultMessage;
|
|
4915
4709
|
}
|
|
4916
4710
|
function getErrorDetails(error) {
|
|
4917
|
-
if (error instanceof
|
|
4918
|
-
return error.details;
|
|
4919
|
-
}
|
|
4920
|
-
if (error && typeof error === "object" && "details" in error) {
|
|
4711
|
+
if (error instanceof CrosspostError) {
|
|
4921
4712
|
return error.details;
|
|
4922
4713
|
}
|
|
4923
4714
|
return void 0;
|
|
4924
4715
|
}
|
|
4716
|
+
function createError(message, code, status, details, recoverable = false) {
|
|
4717
|
+
return new CrosspostError(
|
|
4718
|
+
message,
|
|
4719
|
+
code,
|
|
4720
|
+
status,
|
|
4721
|
+
details,
|
|
4722
|
+
recoverable
|
|
4723
|
+
);
|
|
4724
|
+
}
|
|
4925
4725
|
function enrichErrorWithContext(error, context) {
|
|
4926
|
-
if (error instanceof
|
|
4927
|
-
return
|
|
4726
|
+
if (error instanceof CrosspostError) {
|
|
4727
|
+
return createError(
|
|
4928
4728
|
error.message,
|
|
4929
4729
|
error.code,
|
|
4930
4730
|
error.status,
|
|
@@ -4932,25 +4732,12 @@ function enrichErrorWithContext(error, context) {
|
|
|
4932
4732
|
error.recoverable
|
|
4933
4733
|
);
|
|
4934
4734
|
}
|
|
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
4735
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
4948
|
-
return
|
|
4736
|
+
return createError(
|
|
4949
4737
|
errorMessage || "An error occurred",
|
|
4950
4738
|
ApiErrorCode.INTERNAL_ERROR,
|
|
4951
4739
|
500,
|
|
4952
|
-
{ originalError: error, ...context }
|
|
4953
|
-
false
|
|
4740
|
+
{ originalError: error, ...context }
|
|
4954
4741
|
);
|
|
4955
4742
|
}
|
|
4956
4743
|
async function apiWrapper(apiCall, context) {
|
|
@@ -4967,7 +4754,7 @@ async function apiWrapper(apiCall, context) {
|
|
|
4967
4754
|
} catch (jsonError) {
|
|
4968
4755
|
if (jsonError instanceof Error && jsonError.name === "SyntaxError") {
|
|
4969
4756
|
throw enrichErrorWithContext(
|
|
4970
|
-
|
|
4757
|
+
createError(
|
|
4971
4758
|
`API request failed with status ${error.status} and non-JSON response`,
|
|
4972
4759
|
ApiErrorCode.NETWORK_ERROR,
|
|
4973
4760
|
error.status,
|
|
@@ -4979,7 +4766,7 @@ async function apiWrapper(apiCall, context) {
|
|
|
4979
4766
|
throw jsonError;
|
|
4980
4767
|
}
|
|
4981
4768
|
}
|
|
4982
|
-
if (error instanceof
|
|
4769
|
+
if (error instanceof CrosspostError) {
|
|
4983
4770
|
throw enrichErrorWithContext(error, context || {});
|
|
4984
4771
|
}
|
|
4985
4772
|
throw enrichErrorWithContext(
|
|
@@ -4989,80 +4776,68 @@ async function apiWrapper(apiCall, context) {
|
|
|
4989
4776
|
}
|
|
4990
4777
|
}
|
|
4991
4778
|
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,
|
|
4779
|
+
if (!data || typeof data !== "object" || !("success" in data)) {
|
|
4780
|
+
return createError(
|
|
4781
|
+
"Invalid API response format",
|
|
4782
|
+
ApiErrorCode.INTERNAL_ERROR,
|
|
4783
|
+
status,
|
|
4784
|
+
{ originalResponse: data }
|
|
4785
|
+
);
|
|
4786
|
+
}
|
|
4787
|
+
if (!data.errors || !Array.isArray(data.errors) || data.errors.length === 0) {
|
|
4788
|
+
return createError(
|
|
4789
|
+
"Invalid error response format",
|
|
4790
|
+
ApiErrorCode.INTERNAL_ERROR,
|
|
4791
|
+
status,
|
|
4792
|
+
{ originalResponse: data }
|
|
4793
|
+
);
|
|
4794
|
+
}
|
|
4795
|
+
if (data.errors.length === 1) {
|
|
4796
|
+
const errorDetail = data.errors[0];
|
|
4797
|
+
if (!errorDetail.message || !errorDetail.code) {
|
|
4798
|
+
return createError(
|
|
4799
|
+
"Invalid error detail format",
|
|
4800
|
+
ApiErrorCode.INTERNAL_ERROR,
|
|
5019
4801
|
status,
|
|
5020
4802
|
{ originalResponse: data }
|
|
5021
4803
|
);
|
|
5022
4804
|
}
|
|
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,
|
|
4805
|
+
const finalDetails = {
|
|
4806
|
+
...errorDetail.details || {},
|
|
4807
|
+
...data.meta || {}
|
|
4808
|
+
};
|
|
4809
|
+
return createError(
|
|
4810
|
+
errorDetail.message,
|
|
4811
|
+
errorDetail.code,
|
|
5042
4812
|
status,
|
|
5043
|
-
|
|
5044
|
-
|
|
4813
|
+
finalDetails,
|
|
4814
|
+
errorDetail.recoverable ?? false
|
|
5045
4815
|
);
|
|
5046
4816
|
} else {
|
|
5047
|
-
|
|
5048
|
-
|
|
5049
|
-
|
|
4817
|
+
const firstError = data.errors[0];
|
|
4818
|
+
return createError(
|
|
4819
|
+
"Multiple errors occurred",
|
|
4820
|
+
firstError.code,
|
|
5050
4821
|
status,
|
|
5051
|
-
|
|
5052
|
-
|
|
4822
|
+
{
|
|
4823
|
+
errors: data.errors,
|
|
4824
|
+
...data.meta || {},
|
|
4825
|
+
originalResponse: data
|
|
4826
|
+
},
|
|
4827
|
+
false
|
|
5053
4828
|
);
|
|
5054
4829
|
}
|
|
5055
4830
|
}
|
|
5056
4831
|
function createNetworkError(error, url, timeout) {
|
|
5057
4832
|
if (error instanceof DOMException && error.name === "AbortError") {
|
|
5058
|
-
return
|
|
4833
|
+
return createError(
|
|
5059
4834
|
`Request timed out after ${timeout}ms`,
|
|
5060
4835
|
ApiErrorCode.NETWORK_ERROR,
|
|
5061
4836
|
408,
|
|
5062
4837
|
{ url }
|
|
5063
4838
|
);
|
|
5064
4839
|
}
|
|
5065
|
-
return
|
|
4840
|
+
return createError(
|
|
5066
4841
|
error instanceof Error ? error.message : "An unexpected error occurred during the request",
|
|
5067
4842
|
ApiErrorCode.INTERNAL_ERROR,
|
|
5068
4843
|
500,
|
|
@@ -5073,7 +4848,7 @@ function createNetworkError(error, url, timeout) {
|
|
|
5073
4848
|
// src/core/request.ts
|
|
5074
4849
|
async function makeRequest(method, path, options, data, query) {
|
|
5075
4850
|
let url = `${options.baseUrl}${path.startsWith("/") ? path : `/${path}`}`;
|
|
5076
|
-
if (query && Object.keys(query).length > 0) {
|
|
4851
|
+
if (query && typeof query === "object" && Object.keys(query).length > 0) {
|
|
5077
4852
|
const queryParams = new URLSearchParams();
|
|
5078
4853
|
for (const [key, value] of Object.entries(query)) {
|
|
5079
4854
|
if (value !== void 0 && value !== null) {
|
|
@@ -5085,9 +4860,6 @@ async function makeRequest(method, path, options, data, query) {
|
|
|
5085
4860
|
url += `?${queryString}`;
|
|
5086
4861
|
}
|
|
5087
4862
|
}
|
|
5088
|
-
if (!options.nearAuthData) {
|
|
5089
|
-
throw ApiError.unauthorized("Authentication required. Please provide NEAR signature.");
|
|
5090
|
-
}
|
|
5091
4863
|
const context = {
|
|
5092
4864
|
method,
|
|
5093
4865
|
path,
|
|
@@ -5102,9 +4874,28 @@ async function makeRequest(method, path, options, data, query) {
|
|
|
5102
4874
|
try {
|
|
5103
4875
|
const headers = {
|
|
5104
4876
|
"Content-Type": "application/json",
|
|
5105
|
-
"Accept": "application/json"
|
|
5106
|
-
"Authorization": `Bearer ${createAuthToken(options.nearAuthData)}`
|
|
4877
|
+
"Accept": "application/json"
|
|
5107
4878
|
};
|
|
4879
|
+
if (method === "GET") {
|
|
4880
|
+
const nearAccount = options.nearAccount || options.nearAuthData?.account_id;
|
|
4881
|
+
if (!nearAccount) {
|
|
4882
|
+
throw new CrosspostError(
|
|
4883
|
+
"No NEAR account provided for GET request",
|
|
4884
|
+
ApiErrorCode.UNAUTHORIZED,
|
|
4885
|
+
401
|
|
4886
|
+
);
|
|
4887
|
+
}
|
|
4888
|
+
headers["X-Near-Account"] = nearAccount;
|
|
4889
|
+
} else {
|
|
4890
|
+
if (!options.nearAuthData) {
|
|
4891
|
+
throw new CrosspostError(
|
|
4892
|
+
"NEAR authentication data required for non-GET request",
|
|
4893
|
+
ApiErrorCode.UNAUTHORIZED,
|
|
4894
|
+
401
|
|
4895
|
+
);
|
|
4896
|
+
}
|
|
4897
|
+
headers["Authorization"] = `Bearer ${createAuthToken(options.nearAuthData)}`;
|
|
4898
|
+
}
|
|
5108
4899
|
const requestOptions = {
|
|
5109
4900
|
method,
|
|
5110
4901
|
headers,
|
|
@@ -5118,15 +4909,14 @@ async function makeRequest(method, path, options, data, query) {
|
|
|
5118
4909
|
responseData = await response.json();
|
|
5119
4910
|
} catch (jsonError) {
|
|
5120
4911
|
if (!response.ok) {
|
|
5121
|
-
throw new
|
|
4912
|
+
throw new CrosspostError(
|
|
5122
4913
|
`API request failed with status ${response.status} and non-JSON response`,
|
|
5123
4914
|
ApiErrorCode.NETWORK_ERROR,
|
|
5124
4915
|
response.status,
|
|
5125
4916
|
{ originalStatusText: response.statusText }
|
|
5126
4917
|
);
|
|
5127
4918
|
}
|
|
5128
|
-
|
|
5129
|
-
throw new ApiError(
|
|
4919
|
+
throw new CrosspostError(
|
|
5130
4920
|
`Failed to parse JSON response: ${jsonError instanceof Error ? jsonError.message : String(jsonError)}`,
|
|
5131
4921
|
ApiErrorCode.INTERNAL_ERROR,
|
|
5132
4922
|
response.status
|
|
@@ -5134,23 +4924,26 @@ async function makeRequest(method, path, options, data, query) {
|
|
|
5134
4924
|
}
|
|
5135
4925
|
if (!response.ok) {
|
|
5136
4926
|
lastError = handleErrorResponse(responseData, response.status);
|
|
5137
|
-
const shouldRetry =
|
|
4927
|
+
const shouldRetry = lastError instanceof CrosspostError && lastError.code === ApiErrorCode.RATE_LIMITED;
|
|
5138
4928
|
if (shouldRetry && attempt < options.retries) {
|
|
5139
4929
|
await new Promise((resolve) => setTimeout(resolve, 1e3 * Math.pow(2, attempt)));
|
|
5140
4930
|
continue;
|
|
5141
4931
|
}
|
|
5142
4932
|
throw lastError;
|
|
5143
4933
|
}
|
|
5144
|
-
if (responseData && typeof responseData === "object" && "success" in responseData
|
|
5145
|
-
|
|
5146
|
-
|
|
5147
|
-
|
|
5148
|
-
|
|
5149
|
-
|
|
4934
|
+
if (responseData && typeof responseData === "object" && "success" in responseData) {
|
|
4935
|
+
if (responseData.success) {
|
|
4936
|
+
return responseData.data;
|
|
4937
|
+
} else {
|
|
4938
|
+
lastError = handleErrorResponse(responseData, response.status);
|
|
4939
|
+
const shouldRetry = lastError instanceof CrosspostError && lastError.code === ApiErrorCode.RATE_LIMITED;
|
|
4940
|
+
if (shouldRetry && attempt < options.retries) {
|
|
4941
|
+
await new Promise((resolve) => setTimeout(resolve, 1e3 * Math.pow(2, attempt)));
|
|
4942
|
+
continue;
|
|
4943
|
+
}
|
|
4944
|
+
throw lastError;
|
|
5150
4945
|
}
|
|
5151
|
-
throw lastError;
|
|
5152
4946
|
}
|
|
5153
|
-
return responseData;
|
|
5154
4947
|
} catch (error) {
|
|
5155
4948
|
clearTimeout(timeoutId);
|
|
5156
4949
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
@@ -5159,13 +4952,13 @@ async function makeRequest(method, path, options, data, query) {
|
|
|
5159
4952
|
await new Promise((resolve) => setTimeout(resolve, 1e3 * Math.pow(2, attempt)));
|
|
5160
4953
|
continue;
|
|
5161
4954
|
}
|
|
5162
|
-
if (!(error instanceof
|
|
4955
|
+
if (!(error instanceof CrosspostError)) {
|
|
5163
4956
|
throw createNetworkError(error, url, options.timeout);
|
|
5164
4957
|
}
|
|
5165
4958
|
throw error;
|
|
5166
4959
|
}
|
|
5167
4960
|
}
|
|
5168
|
-
throw lastError || new
|
|
4961
|
+
throw lastError || new CrosspostError("Request failed after multiple retries", ApiErrorCode.INTERNAL_ERROR, 500);
|
|
5169
4962
|
}, context);
|
|
5170
4963
|
}
|
|
5171
4964
|
|
|
@@ -5274,25 +5067,28 @@ var AuthApi = class {
|
|
|
5274
5067
|
/**
|
|
5275
5068
|
* Refreshes the authentication token for the specified platform.
|
|
5276
5069
|
* @param platform The target platform.
|
|
5277
|
-
* @returns A promise resolving with the refresh response.
|
|
5070
|
+
* @returns A promise resolving with the refresh response containing updated auth details.
|
|
5278
5071
|
*/
|
|
5279
|
-
async refreshToken(platform) {
|
|
5072
|
+
async refreshToken(platform, userId) {
|
|
5280
5073
|
return makeRequest(
|
|
5281
5074
|
"POST",
|
|
5282
5075
|
`/auth/${platform}/refresh`,
|
|
5283
|
-
this.options
|
|
5076
|
+
this.options,
|
|
5077
|
+
{ userId }
|
|
5284
5078
|
);
|
|
5285
5079
|
}
|
|
5286
5080
|
/**
|
|
5287
5081
|
* Refreshes the user's profile information from the specified platform.
|
|
5288
5082
|
* @param platform The target platform.
|
|
5289
|
-
* @
|
|
5083
|
+
* @param userId The user ID on the platform
|
|
5084
|
+
* @returns A promise resolving with the updated account profile information.
|
|
5290
5085
|
*/
|
|
5291
|
-
async refreshProfile(platform) {
|
|
5086
|
+
async refreshProfile(platform, userId) {
|
|
5292
5087
|
return makeRequest(
|
|
5293
5088
|
"POST",
|
|
5294
5089
|
`/auth/${platform}/refresh-profile`,
|
|
5295
|
-
this.options
|
|
5090
|
+
this.options,
|
|
5091
|
+
{ userId }
|
|
5296
5092
|
);
|
|
5297
5093
|
}
|
|
5298
5094
|
/**
|
|
@@ -5300,11 +5096,25 @@ var AuthApi = class {
|
|
|
5300
5096
|
* @param platform The target platform.
|
|
5301
5097
|
* @returns A promise resolving with the authentication status response.
|
|
5302
5098
|
*/
|
|
5303
|
-
async getAuthStatus(platform) {
|
|
5099
|
+
async getAuthStatus(platform, userId) {
|
|
5304
5100
|
return makeRequest(
|
|
5305
5101
|
"GET",
|
|
5306
|
-
`/auth/${platform}/status`,
|
|
5307
|
-
this.options
|
|
5102
|
+
`/auth/${platform}/status/${userId}`,
|
|
5103
|
+
this.options,
|
|
5104
|
+
void 0,
|
|
5105
|
+
{ platform, userId }
|
|
5106
|
+
);
|
|
5107
|
+
}
|
|
5108
|
+
/**
|
|
5109
|
+
* Unauthorizes a NEAR account from using the service
|
|
5110
|
+
* @returns A promise resolving with the unauthorized response
|
|
5111
|
+
*/
|
|
5112
|
+
async unauthorizeNear() {
|
|
5113
|
+
return makeRequest(
|
|
5114
|
+
"DELETE",
|
|
5115
|
+
"/auth/unauthorize/near",
|
|
5116
|
+
this.options,
|
|
5117
|
+
{}
|
|
5308
5118
|
);
|
|
5309
5119
|
}
|
|
5310
5120
|
/**
|
|
@@ -5312,11 +5122,12 @@ var AuthApi = class {
|
|
|
5312
5122
|
* @param platform The target platform.
|
|
5313
5123
|
* @returns A promise resolving with the revocation response.
|
|
5314
5124
|
*/
|
|
5315
|
-
async revokeAuth(platform) {
|
|
5125
|
+
async revokeAuth(platform, userId) {
|
|
5316
5126
|
return makeRequest(
|
|
5317
5127
|
"DELETE",
|
|
5318
5128
|
`/auth/${platform}/revoke`,
|
|
5319
|
-
this.options
|
|
5129
|
+
this.options,
|
|
5130
|
+
{ userId }
|
|
5320
5131
|
);
|
|
5321
5132
|
}
|
|
5322
5133
|
/**
|
|
@@ -5401,7 +5212,7 @@ var PostApi = class {
|
|
|
5401
5212
|
async likePost(request) {
|
|
5402
5213
|
return makeRequest(
|
|
5403
5214
|
"POST",
|
|
5404
|
-
`/api/post/like
|
|
5215
|
+
`/api/post/like`,
|
|
5405
5216
|
this.options,
|
|
5406
5217
|
request
|
|
5407
5218
|
);
|
|
@@ -5414,7 +5225,7 @@ var PostApi = class {
|
|
|
5414
5225
|
async unlikePost(request) {
|
|
5415
5226
|
return makeRequest(
|
|
5416
5227
|
"DELETE",
|
|
5417
|
-
`/api/post/like
|
|
5228
|
+
`/api/post/like`,
|
|
5418
5229
|
this.options,
|
|
5419
5230
|
request
|
|
5420
5231
|
);
|
|
@@ -5425,17 +5236,9 @@ var PostApi = class {
|
|
|
5425
5236
|
* @returns A promise resolving with the delete response.
|
|
5426
5237
|
*/
|
|
5427
5238
|
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
5239
|
return makeRequest(
|
|
5437
5240
|
"DELETE",
|
|
5438
|
-
`/api/post
|
|
5241
|
+
`/api/post`,
|
|
5439
5242
|
this.options,
|
|
5440
5243
|
request
|
|
5441
5244
|
);
|
|
@@ -5471,7 +5274,9 @@ var SystemApi = class {
|
|
|
5471
5274
|
return makeRequest(
|
|
5472
5275
|
"GET",
|
|
5473
5276
|
`/api/rate-limit/${endpoint}`,
|
|
5474
|
-
this.options
|
|
5277
|
+
this.options,
|
|
5278
|
+
void 0,
|
|
5279
|
+
{ endpoint }
|
|
5475
5280
|
);
|
|
5476
5281
|
}
|
|
5477
5282
|
/**
|
|
@@ -5518,74 +5323,97 @@ var CrosspostClient = class {
|
|
|
5518
5323
|
}
|
|
5519
5324
|
/**
|
|
5520
5325
|
* Sets the authentication data (signature) for the client
|
|
5326
|
+
* Required for non-GET requests
|
|
5521
5327
|
* @param nearAuthData The NEAR authentication data
|
|
5522
5328
|
*/
|
|
5523
5329
|
setAuthentication(nearAuthData) {
|
|
5524
5330
|
this.options.nearAuthData = nearAuthData;
|
|
5331
|
+
if (!this.options.nearAccount) {
|
|
5332
|
+
this.options.nearAccount = nearAuthData.account_id;
|
|
5333
|
+
}
|
|
5334
|
+
}
|
|
5335
|
+
/**
|
|
5336
|
+
* Sets the NEAR account ID for simplified GET request authentication
|
|
5337
|
+
* If not set, will use account_id from nearAuthData
|
|
5338
|
+
* @param nearAccount The NEAR account ID
|
|
5339
|
+
*/
|
|
5340
|
+
setNearAccount(nearAccount) {
|
|
5341
|
+
this.options.nearAccount = nearAccount;
|
|
5342
|
+
}
|
|
5343
|
+
/**
|
|
5344
|
+
* Gets the current NEAR account ID being used for authentication
|
|
5345
|
+
* @returns The NEAR account ID from nearAccount or nearAuthData
|
|
5346
|
+
*/
|
|
5347
|
+
getNearAccount() {
|
|
5348
|
+
return this.options.nearAccount || this.options.nearAuthData?.account_id;
|
|
5525
5349
|
}
|
|
5526
5350
|
/**
|
|
5527
5351
|
* Checks if authentication data (signature) exists on client
|
|
5528
|
-
* @
|
|
5352
|
+
* @returns true if nearAuthData is set (required for non-GET requests)
|
|
5529
5353
|
*/
|
|
5530
5354
|
isAuthenticated() {
|
|
5531
5355
|
return !!this.options.nearAuthData;
|
|
5532
5356
|
}
|
|
5357
|
+
/**
|
|
5358
|
+
* Checks if a NEAR account is set for GET request authentication
|
|
5359
|
+
* @returns true if either nearAccount or nearAuthData.account_id is set
|
|
5360
|
+
*/
|
|
5361
|
+
hasNearAccount() {
|
|
5362
|
+
return !!(this.options.nearAccount || this.options.nearAuthData?.account_id);
|
|
5363
|
+
}
|
|
5364
|
+
/**
|
|
5365
|
+
* Clears all authentication data from the client
|
|
5366
|
+
* This will prevent all requests from working until new authentication is set
|
|
5367
|
+
*/
|
|
5368
|
+
clear() {
|
|
5369
|
+
this.options.nearAuthData = void 0;
|
|
5370
|
+
this.options.nearAccount = void 0;
|
|
5371
|
+
}
|
|
5533
5372
|
};
|
|
5534
5373
|
export {
|
|
5535
5374
|
AccountActivityEntrySchema,
|
|
5536
5375
|
AccountActivityParamsSchema,
|
|
5537
5376
|
AccountActivityQuerySchema,
|
|
5538
|
-
AccountActivityResponseSchema,
|
|
5539
5377
|
AccountPostSchema,
|
|
5540
5378
|
AccountPostsParamsSchema,
|
|
5541
5379
|
AccountPostsQuerySchema,
|
|
5542
|
-
AccountPostsResponseSchema,
|
|
5543
5380
|
ActivityApi,
|
|
5544
5381
|
ActivityLeaderboardQuerySchema,
|
|
5545
|
-
ActivityLeaderboardResponseSchema,
|
|
5546
5382
|
AllRateLimitsResponseSchema,
|
|
5547
|
-
ApiError,
|
|
5548
5383
|
ApiErrorCode,
|
|
5549
|
-
|
|
5384
|
+
ApiErrorCodeSchema,
|
|
5550
5385
|
AuthApi,
|
|
5551
5386
|
AuthCallbackQuerySchema,
|
|
5552
5387
|
AuthCallbackResponseSchema,
|
|
5553
5388
|
AuthInitRequestSchema,
|
|
5554
5389
|
AuthRevokeResponseSchema,
|
|
5390
|
+
AuthStatusParamsSchema,
|
|
5555
5391
|
AuthStatusResponseSchema,
|
|
5392
|
+
AuthTokenRequestSchema,
|
|
5556
5393
|
AuthUrlResponseSchema,
|
|
5557
|
-
BaseError,
|
|
5558
|
-
CompositeApiError,
|
|
5559
5394
|
ConnectedAccountSchema,
|
|
5560
5395
|
ConnectedAccountsResponseSchema,
|
|
5561
5396
|
CreatePostRequestSchema,
|
|
5562
|
-
CreatePostResponseLegacySchema,
|
|
5563
5397
|
CreatePostResponseSchema,
|
|
5564
|
-
CreatePostTargetErrorSchema,
|
|
5565
|
-
CreatePostTargetResultSchema,
|
|
5566
5398
|
CrosspostClient,
|
|
5567
5399
|
DeletePostRequestSchema,
|
|
5568
5400
|
DeletePostResponseSchema,
|
|
5569
5401
|
DeleteResultSchema,
|
|
5570
|
-
ERROR_CATEGORIES,
|
|
5571
5402
|
EndpointRateLimitResponseSchema,
|
|
5572
|
-
EnhancedErrorResponseSchema,
|
|
5573
|
-
EnhancedResponseMetaSchema,
|
|
5574
|
-
EnhancedResponseSchema,
|
|
5575
5403
|
ErrorDetailSchema,
|
|
5576
|
-
|
|
5404
|
+
HealthStatusSchema,
|
|
5577
5405
|
LikePostRequestSchema,
|
|
5578
5406
|
LikePostResponseSchema,
|
|
5579
5407
|
LikeResultSchema,
|
|
5580
5408
|
MediaContentSchema,
|
|
5581
5409
|
MediaSchema,
|
|
5582
|
-
|
|
5410
|
+
MultiStatusDataSchema,
|
|
5583
5411
|
NearAuthorizationRequestSchema,
|
|
5584
5412
|
NearAuthorizationResponseSchema,
|
|
5585
5413
|
NearAuthorizationStatusResponseSchema,
|
|
5414
|
+
NearUnauthorizationResponseSchema,
|
|
5586
5415
|
Platform,
|
|
5587
5416
|
PlatformActivitySchema,
|
|
5588
|
-
PlatformError,
|
|
5589
5417
|
PlatformParamSchema,
|
|
5590
5418
|
PlatformRateLimitSchema,
|
|
5591
5419
|
PlatformSchema,
|
|
@@ -5599,7 +5427,6 @@ export {
|
|
|
5599
5427
|
PostSuccessDetailSchema,
|
|
5600
5428
|
PostToDeleteSchema,
|
|
5601
5429
|
ProfileRefreshResponseSchema,
|
|
5602
|
-
ProfileRefreshResultSchema,
|
|
5603
5430
|
QuotePostRequestSchema,
|
|
5604
5431
|
QuotePostResponseSchema,
|
|
5605
5432
|
RateLimitEndpointParamSchema,
|
|
@@ -5611,6 +5438,7 @@ export {
|
|
|
5611
5438
|
ReplyToPostResponseSchema,
|
|
5612
5439
|
RepostRequestSchema,
|
|
5613
5440
|
RepostResponseSchema,
|
|
5441
|
+
ResponseMetaSchema,
|
|
5614
5442
|
SUPPORTED_PLATFORMS,
|
|
5615
5443
|
SuccessDetailSchema,
|
|
5616
5444
|
SupportedPlatformSchema,
|
|
@@ -5622,21 +5450,14 @@ export {
|
|
|
5622
5450
|
UsageRateLimitSchema,
|
|
5623
5451
|
UserProfileSchema,
|
|
5624
5452
|
apiWrapper,
|
|
5625
|
-
createApiResponse,
|
|
5626
|
-
createEnhancedApiResponse,
|
|
5627
|
-
createEnhancedErrorResponse,
|
|
5628
|
-
createErrorDetail,
|
|
5629
|
-
createErrorResponse,
|
|
5630
|
-
createMultiStatusResponse,
|
|
5631
5453
|
createNetworkError,
|
|
5632
|
-
createSuccessDetail,
|
|
5633
5454
|
enrichErrorWithContext,
|
|
5455
|
+
errorCodeToStatusCode,
|
|
5634
5456
|
getErrorDetails,
|
|
5635
5457
|
getErrorMessage,
|
|
5636
5458
|
handleErrorResponse,
|
|
5637
5459
|
isAuthError,
|
|
5638
5460
|
isContentError,
|
|
5639
|
-
isErrorOfCategory,
|
|
5640
5461
|
isMediaError,
|
|
5641
5462
|
isNetworkError,
|
|
5642
5463
|
isPlatformError,
|