@crosspost/sdk 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -40,6 +40,9 @@ __export(index_exports, {
40
40
  AccountPostsParamsSchema: () => AccountPostsParamsSchema,
41
41
  AccountPostsQuerySchema: () => AccountPostsQuerySchema,
42
42
  AccountPostsResponseSchema: () => AccountPostsResponseSchema,
43
+ ActivityApi: () => ActivityApi,
44
+ ActivityLeaderboardQuerySchema: () => ActivityLeaderboardQuerySchema,
45
+ ActivityLeaderboardResponseSchema: () => ActivityLeaderboardResponseSchema,
43
46
  AllRateLimitsResponseSchema: () => AllRateLimitsResponseSchema,
44
47
  ApiError: () => ApiError,
45
48
  ApiErrorCode: () => ApiErrorCode,
@@ -65,14 +68,13 @@ __export(index_exports, {
65
68
  DeletePostRequestSchema: () => DeletePostRequestSchema,
66
69
  DeletePostResponseSchema: () => DeletePostResponseSchema,
67
70
  DeleteResultSchema: () => DeleteResultSchema,
71
+ ERROR_CATEGORIES: () => ERROR_CATEGORIES,
68
72
  EndpointRateLimitResponseSchema: () => EndpointRateLimitResponseSchema,
69
73
  EnhancedErrorResponseSchema: () => EnhancedErrorResponseSchema,
70
74
  EnhancedResponseMetaSchema: () => EnhancedResponseMetaSchema,
71
75
  EnhancedResponseSchema: () => EnhancedResponseSchema,
72
76
  ErrorDetailSchema: () => ErrorDetailSchema,
73
77
  ErrorResponseSchema: () => ErrorResponseSchema,
74
- LeaderboardQuerySchema: () => LeaderboardQuerySchema,
75
- LeaderboardResponseSchema: () => LeaderboardResponseSchema,
76
78
  LikePostRequestSchema: () => LikePostRequestSchema,
77
79
  LikePostResponseSchema: () => LikePostResponseSchema,
78
80
  LikeResultSchema: () => LikeResultSchema,
@@ -111,11 +113,14 @@ __export(index_exports, {
111
113
  RepostRequestSchema: () => RepostRequestSchema,
112
114
  RepostResponseSchema: () => RepostResponseSchema,
113
115
  SuccessDetailSchema: () => SuccessDetailSchema,
116
+ SystemApi: () => SystemApi,
114
117
  TargetSchema: () => TargetSchema,
118
+ TimePeriod: () => TimePeriod,
115
119
  UnlikePostRequestSchema: () => UnlikePostRequestSchema,
116
120
  UnlikePostResponseSchema: () => UnlikePostResponseSchema,
117
121
  UsageRateLimitSchema: () => UsageRateLimitSchema,
118
122
  UserProfileSchema: () => UserProfileSchema,
123
+ apiWrapper: () => apiWrapper,
119
124
  clearAuthCookie: () => clearAuthCookie,
120
125
  createApiResponse: () => createApiResponse,
121
126
  createEnhancedApiResponse: () => createEnhancedApiResponse,
@@ -125,9 +130,22 @@ __export(index_exports, {
125
130
  createMultiStatusResponse: () => createMultiStatusResponse,
126
131
  createNetworkError: () => createNetworkError,
127
132
  createSuccessDetail: () => createSuccessDetail,
133
+ enrichErrorWithContext: () => enrichErrorWithContext,
128
134
  getAuthFromCookie: () => getAuthFromCookie,
129
135
  getCsrfToken: () => getCsrfToken,
136
+ getErrorDetails: () => getErrorDetails,
137
+ getErrorMessage: () => getErrorMessage,
130
138
  handleErrorResponse: () => handleErrorResponse,
139
+ isAuthError: () => isAuthError,
140
+ isContentError: () => isContentError,
141
+ isErrorOfCategory: () => isErrorOfCategory,
142
+ isMediaError: () => isMediaError,
143
+ isNetworkError: () => isNetworkError,
144
+ isPlatformError: () => isPlatformError,
145
+ isPostError: () => isPostError,
146
+ isRateLimitError: () => isRateLimitError,
147
+ isRecoverableError: () => isRecoverableError,
148
+ isValidationError: () => isValidationError,
131
149
  storeAuthInCookie: () => storeAuthInCookie
132
150
  });
133
151
  module.exports = __toCommonJS(index_exports);
@@ -4201,10 +4219,10 @@ var PlatformSchema = z.enum([
4201
4219
  // 'facebook',
4202
4220
  // 'instagram',
4203
4221
  ]).describe("Social media platform");
4204
- var Platform = /* @__PURE__ */ ((Platform2) => {
4205
- Platform2["UNKNOWN"] = "unknown";
4206
- Platform2["TWITTER"] = "twitter";
4207
- return Platform2;
4222
+ var Platform = /* @__PURE__ */ ((Platform22) => {
4223
+ Platform22["UNKNOWN"] = "unknown";
4224
+ Platform22["TWITTER"] = "twitter";
4225
+ return Platform22;
4208
4226
  })(Platform || {});
4209
4227
  var ApiResponseSchema = z.object({
4210
4228
  data: z.any().describe("Response data"),
@@ -4813,13 +4831,21 @@ var EndpointRateLimitResponseSchema = z.object({
4813
4831
  endpoint: z.string().describe("API endpoint or action"),
4814
4832
  signerId: z.string().describe("NEAR account ID")
4815
4833
  }).describe("Endpoint rate limit response");
4816
- var LeaderboardQuerySchema = z.object({
4834
+ var TimePeriod = /* @__PURE__ */ ((TimePeriod2) => {
4835
+ TimePeriod2["ALL_TIME"] = "all";
4836
+ TimePeriod2["YEARLY"] = "yearly";
4837
+ TimePeriod2["MONTHLY"] = "monthly";
4838
+ TimePeriod2["WEEKLY"] = "weekly";
4839
+ TimePeriod2["DAILY"] = "daily";
4840
+ return TimePeriod2;
4841
+ })(TimePeriod || {});
4842
+ var ActivityLeaderboardQuerySchema = z.object({
4817
4843
  timeframe: z.enum(["day", "week", "month", "all"]).optional().describe(
4818
4844
  "Timeframe for the leaderboard"
4819
4845
  ),
4820
4846
  limit: z.string().optional().transform((val) => val ? parseInt(val, 10) : void 0).pipe(z.number().min(1).max(100).optional()).describe("Maximum number of results to return (1-100)"),
4821
4847
  offset: z.string().optional().transform((val) => val ? parseInt(val, 10) : void 0).pipe(z.number().min(0).optional()).describe("Offset for pagination")
4822
- }).describe("Leaderboard query");
4848
+ }).describe("Activity leaderboard query");
4823
4849
  var AccountActivityEntrySchema = z.object({
4824
4850
  signerId: z.string().describe("NEAR account ID"),
4825
4851
  totalPosts: z.number().describe("Total number of posts"),
@@ -4831,7 +4857,7 @@ var AccountActivityEntrySchema = z.object({
4831
4857
  rank: z.number().describe("Rank on the leaderboard"),
4832
4858
  lastActive: z.string().datetime().describe("Timestamp of last activity")
4833
4859
  }).describe("Account activity entry");
4834
- var LeaderboardResponseSchema = EnhancedResponseSchema(
4860
+ var ActivityLeaderboardResponseSchema = EnhancedResponseSchema(
4835
4861
  z.object({
4836
4862
  timeframe: z.enum(["day", "week", "month", "all"]).describe("Timeframe for the leaderboard"),
4837
4863
  entries: z.array(AccountActivityEntrySchema).describe("Leaderboard entries"),
@@ -4840,7 +4866,7 @@ var LeaderboardResponseSchema = EnhancedResponseSchema(
4840
4866
  offset: z.number().describe("Offset for pagination"),
4841
4867
  generatedAt: z.string().datetime().describe("Timestamp when the leaderboard was generated")
4842
4868
  })
4843
- ).describe("Leaderboard response");
4869
+ ).describe("Activity leaderboard response");
4844
4870
  var AccountActivityParamsSchema = z.object({
4845
4871
  signerId: z.string().describe("NEAR account ID")
4846
4872
  }).describe("Account activity params");
@@ -4988,22 +5014,195 @@ function createNetworkError(error, url, timeout) {
4988
5014
  );
4989
5015
  }
4990
5016
 
5017
+ // src/utils/error-utils.ts
5018
+ var ERROR_CATEGORIES = {
5019
+ AUTH: [
5020
+ ApiErrorCode.UNAUTHORIZED,
5021
+ ApiErrorCode.FORBIDDEN
5022
+ ],
5023
+ VALIDATION: [
5024
+ ApiErrorCode.VALIDATION_ERROR,
5025
+ ApiErrorCode.INVALID_REQUEST
5026
+ ],
5027
+ NETWORK: [
5028
+ ApiErrorCode.NETWORK_ERROR
5029
+ ],
5030
+ PLATFORM: [
5031
+ ApiErrorCode.PLATFORM_ERROR,
5032
+ ApiErrorCode.PLATFORM_UNAVAILABLE
5033
+ ],
5034
+ CONTENT: [
5035
+ ApiErrorCode.CONTENT_POLICY_VIOLATION,
5036
+ ApiErrorCode.DUPLICATE_CONTENT
5037
+ ],
5038
+ RATE_LIMIT: [
5039
+ ApiErrorCode.RATE_LIMITED
5040
+ ],
5041
+ POST: [
5042
+ ApiErrorCode.POST_CREATION_FAILED,
5043
+ ApiErrorCode.THREAD_CREATION_FAILED,
5044
+ ApiErrorCode.POST_DELETION_FAILED,
5045
+ ApiErrorCode.POST_INTERACTION_FAILED
5046
+ ],
5047
+ MEDIA: [
5048
+ ApiErrorCode.MEDIA_UPLOAD_FAILED
5049
+ ]
5050
+ };
5051
+ function isErrorOfCategory(error, category) {
5052
+ if (error instanceof ApiError) {
5053
+ return category.includes(error.code);
5054
+ }
5055
+ if (error instanceof PlatformError) {
5056
+ return category.includes(error.code);
5057
+ }
5058
+ if (error && typeof error === "object" && "code" in error) {
5059
+ return category.includes(error.code);
5060
+ }
5061
+ return false;
5062
+ }
5063
+ function isAuthError(error) {
5064
+ return isErrorOfCategory(error, ERROR_CATEGORIES.AUTH);
5065
+ }
5066
+ function isValidationError(error) {
5067
+ return isErrorOfCategory(error, ERROR_CATEGORIES.VALIDATION);
5068
+ }
5069
+ function isNetworkError(error) {
5070
+ return isErrorOfCategory(error, ERROR_CATEGORIES.NETWORK);
5071
+ }
5072
+ function isPlatformError(error) {
5073
+ return isErrorOfCategory(error, ERROR_CATEGORIES.PLATFORM) || error instanceof PlatformError;
5074
+ }
5075
+ function isContentError(error) {
5076
+ return isErrorOfCategory(error, ERROR_CATEGORIES.CONTENT);
5077
+ }
5078
+ function isRateLimitError(error) {
5079
+ return isErrorOfCategory(error, ERROR_CATEGORIES.RATE_LIMIT);
5080
+ }
5081
+ function isPostError(error) {
5082
+ return isErrorOfCategory(error, ERROR_CATEGORIES.POST);
5083
+ }
5084
+ function isMediaError(error) {
5085
+ return isErrorOfCategory(error, ERROR_CATEGORIES.MEDIA);
5086
+ }
5087
+ function isRecoverableError(error) {
5088
+ if (error instanceof ApiError || error instanceof PlatformError) {
5089
+ return error.recoverable;
5090
+ }
5091
+ return false;
5092
+ }
5093
+ function getErrorMessage(error, defaultMessage = "An error occurred") {
5094
+ if (error instanceof Error) {
5095
+ return error.message || defaultMessage;
5096
+ }
5097
+ if (typeof error === "string") {
5098
+ return error;
5099
+ }
5100
+ if (error && typeof error === "object" && "message" in error) {
5101
+ return error.message || defaultMessage;
5102
+ }
5103
+ return defaultMessage;
5104
+ }
5105
+ function getErrorDetails(error) {
5106
+ if (error instanceof ApiError || error instanceof PlatformError) {
5107
+ return error.details;
5108
+ }
5109
+ if (error && typeof error === "object" && "details" in error) {
5110
+ return error.details;
5111
+ }
5112
+ return void 0;
5113
+ }
5114
+ function enrichErrorWithContext(error, context) {
5115
+ if (error instanceof ApiError) {
5116
+ return new ApiError(
5117
+ error.message,
5118
+ error.code,
5119
+ error.status,
5120
+ { ...error.details || {}, ...context },
5121
+ error.recoverable
5122
+ );
5123
+ }
5124
+ if (error instanceof PlatformError) {
5125
+ return new PlatformError(
5126
+ error.message,
5127
+ error.platform,
5128
+ error.code,
5129
+ error.recoverable,
5130
+ error.originalError,
5131
+ error.status,
5132
+ error.userId,
5133
+ { ...error.details || {}, ...context }
5134
+ );
5135
+ }
5136
+ const errorMessage = error instanceof Error ? error.message : String(error);
5137
+ return new ApiError(
5138
+ errorMessage || "An error occurred",
5139
+ ApiErrorCode.INTERNAL_ERROR,
5140
+ 500,
5141
+ { originalError: error, ...context },
5142
+ false
5143
+ );
5144
+ }
5145
+ function handleErrorResponse2(data, status) {
5146
+ return handleErrorResponse(data, status);
5147
+ }
5148
+ async function apiWrapper(apiCall, context) {
5149
+ try {
5150
+ return await apiCall();
5151
+ } catch (error) {
5152
+ if (error instanceof Response) {
5153
+ try {
5154
+ const errorData = await error.json();
5155
+ throw enrichErrorWithContext(
5156
+ handleErrorResponse2(errorData, error.status),
5157
+ context || {}
5158
+ );
5159
+ } catch (jsonError) {
5160
+ if (jsonError instanceof Error && jsonError.name === "SyntaxError") {
5161
+ throw enrichErrorWithContext(
5162
+ new ApiError(
5163
+ `API request failed with status ${error.status} and non-JSON response`,
5164
+ ApiErrorCode.NETWORK_ERROR,
5165
+ error.status,
5166
+ { originalResponse: error.statusText }
5167
+ ),
5168
+ context || {}
5169
+ );
5170
+ }
5171
+ throw jsonError;
5172
+ }
5173
+ }
5174
+ if (error instanceof ApiError || error instanceof PlatformError) {
5175
+ throw enrichErrorWithContext(error, context || {});
5176
+ }
5177
+ throw enrichErrorWithContext(
5178
+ error instanceof Error ? error : new Error(String(error)),
5179
+ context || {}
5180
+ );
5181
+ }
5182
+ }
5183
+
4991
5184
  // src/utils/cookie.ts
4992
5185
  var import_js_cookie = __toESM(require("js-cookie"), 1);
4993
5186
  var AUTH_COOKIE_NAME = "__crosspost_auth";
4994
5187
  var CSRF_COOKIE_NAME = "XSRF-TOKEN";
4995
5188
  var CSRF_HEADER_NAME = "X-CSRF-Token";
5189
+ var isDeno = () => {
5190
+ return typeof globalThis.Deno !== "undefined";
5191
+ };
5192
+ var isBrowser = () => {
5193
+ return !isDeno() && typeof globalThis.window !== "undefined";
5194
+ };
4996
5195
  var AUTH_COOKIE_OPTIONS = {
4997
5196
  secure: true,
4998
5197
  sameSite: "lax",
4999
- // how could we make this none?
5198
+ // Restrict to same-site and top-level navigation
5000
5199
  path: "/",
5001
5200
  expires: 30
5002
5201
  // 30 days
5003
5202
  };
5004
5203
  function getAuthFromCookie() {
5005
5204
  try {
5006
- if (typeof document === "undefined") {
5205
+ if (!isBrowser()) {
5007
5206
  return void 0;
5008
5207
  }
5009
5208
  const cookieValue = import_js_cookie.default.get(AUTH_COOKIE_NAME);
@@ -5018,7 +5217,7 @@ function getAuthFromCookie() {
5018
5217
  }
5019
5218
  function storeAuthInCookie(authData) {
5020
5219
  try {
5021
- if (typeof document === "undefined") {
5220
+ if (!isBrowser()) {
5022
5221
  return;
5023
5222
  }
5024
5223
  const cookieValue = JSON.stringify(authData);
@@ -5028,105 +5227,178 @@ function storeAuthInCookie(authData) {
5028
5227
  }
5029
5228
  }
5030
5229
  function clearAuthCookie() {
5031
- if (typeof document === "undefined") {
5230
+ if (!isBrowser()) {
5032
5231
  return;
5033
5232
  }
5034
5233
  import_js_cookie.default.remove(AUTH_COOKIE_NAME, { path: AUTH_COOKIE_OPTIONS.path });
5035
5234
  }
5036
5235
  function getCsrfToken() {
5037
- if (typeof document === "undefined") {
5236
+ if (!isBrowser()) {
5038
5237
  return void 0;
5039
5238
  }
5040
5239
  return import_js_cookie.default.get(CSRF_COOKIE_NAME);
5041
5240
  }
5042
5241
 
5043
5242
  // src/core/request.ts
5044
- async function makeRequest(method, path, options, data) {
5045
- const url = `${options.baseUrl}${path.startsWith("/") ? path : `/${path}`}`;
5046
- let lastError = null;
5047
- if (!options.signature) {
5243
+ async function makeRequest(method, path, options, data, query) {
5244
+ let url = `${options.baseUrl}${path.startsWith("/") ? path : `/${path}`}`;
5245
+ if (query && Object.keys(query).length > 0) {
5246
+ const queryParams = new URLSearchParams();
5247
+ for (const [key, value] of Object.entries(query)) {
5248
+ if (value !== void 0 && value !== null) {
5249
+ queryParams.append(key, String(value));
5250
+ }
5251
+ }
5252
+ const queryString = queryParams.toString();
5253
+ if (queryString) {
5254
+ url += `?${queryString}`;
5255
+ }
5256
+ }
5257
+ if (!options.nearAuthData) {
5048
5258
  throw ApiError.unauthorized("Authentication required. Please provide NEAR signature.");
5049
5259
  }
5050
- for (let attempt = 0; attempt <= options.retries; attempt++) {
5051
- const controller = new AbortController();
5052
- const timeoutId = setTimeout(() => controller.abort(), options.timeout);
5053
- try {
5054
- const headers = {
5055
- "Content-Type": "application/json",
5056
- "Accept": "application/json",
5057
- "Authorization": `Bearer ${(0, import_near_sign_verify.createAuthToken)(options.signature)}`
5058
- };
5059
- if (method !== "GET") {
5060
- const csrfToken = getCsrfToken();
5061
- if (csrfToken) {
5062
- headers[CSRF_HEADER_NAME] = csrfToken;
5063
- }
5064
- }
5065
- const requestOptions = {
5066
- method,
5067
- headers,
5068
- body: method !== "GET" && data ? JSON.stringify(data) : void 0,
5069
- signal: controller.signal
5070
- };
5071
- const response = await fetch(url, requestOptions);
5072
- clearTimeout(timeoutId);
5073
- let responseData;
5260
+ const context = {
5261
+ method,
5262
+ path,
5263
+ url,
5264
+ retries: options.retries
5265
+ };
5266
+ return apiWrapper(async () => {
5267
+ let lastError = null;
5268
+ for (let attempt = 0; attempt <= options.retries; attempt++) {
5269
+ const controller = new AbortController();
5270
+ const timeoutId = setTimeout(() => controller.abort(), options.timeout);
5074
5271
  try {
5075
- responseData = await response.json();
5076
- } catch (jsonError) {
5077
- if (!response.ok) {
5272
+ const headers = {
5273
+ "Content-Type": "application/json",
5274
+ "Accept": "application/json",
5275
+ "Authorization": `Bearer ${(0, import_near_sign_verify.createAuthToken)(options.nearAuthData)}`
5276
+ };
5277
+ if (method !== "GET") {
5278
+ const csrfToken = getCsrfToken();
5279
+ if (csrfToken) {
5280
+ headers[CSRF_HEADER_NAME] = csrfToken;
5281
+ }
5282
+ }
5283
+ const requestOptions = {
5284
+ method,
5285
+ headers,
5286
+ body: method !== "GET" && data ? JSON.stringify(data) : void 0,
5287
+ signal: controller.signal
5288
+ };
5289
+ const response = await fetch(url, requestOptions);
5290
+ clearTimeout(timeoutId);
5291
+ let responseData;
5292
+ try {
5293
+ responseData = await response.json();
5294
+ } catch (jsonError) {
5295
+ if (!response.ok) {
5296
+ throw new ApiError(
5297
+ `API request failed with status ${response.status} and non-JSON response`,
5298
+ ApiErrorCode.NETWORK_ERROR,
5299
+ response.status,
5300
+ { originalStatusText: response.statusText }
5301
+ );
5302
+ }
5303
+ if (response.status === 204) return {};
5078
5304
  throw new ApiError(
5079
- `API request failed with status ${response.status} and non-JSON response`,
5080
- ApiErrorCode.NETWORK_ERROR,
5081
- // Or a more specific code
5082
- response.status,
5083
- { originalStatusText: response.statusText }
5305
+ `Failed to parse JSON response: ${jsonError instanceof Error ? jsonError.message : String(jsonError)}`,
5306
+ ApiErrorCode.INTERNAL_ERROR,
5307
+ response.status
5084
5308
  );
5085
5309
  }
5086
- if (response.status === 204) return {};
5087
- throw new ApiError(
5088
- `Failed to parse JSON response: ${jsonError instanceof Error ? jsonError.message : String(jsonError)}`,
5089
- ApiErrorCode.INTERNAL_ERROR,
5090
- // Or NETWORK_ERROR?
5091
- response.status
5092
- );
5093
- }
5094
- if (!response.ok) {
5095
- lastError = handleErrorResponse(responseData, response.status);
5096
- const shouldRetry = response.status >= 500 || lastError instanceof ApiError && lastError.recoverable;
5097
- if (shouldRetry && attempt < options.retries) {
5098
- await new Promise((resolve) => setTimeout(resolve, 1e3 * Math.pow(2, attempt)));
5099
- continue;
5310
+ if (!response.ok) {
5311
+ lastError = handleErrorResponse(responseData, response.status);
5312
+ const shouldRetry = response.status >= 500 || lastError instanceof ApiError && lastError.recoverable;
5313
+ if (shouldRetry && attempt < options.retries) {
5314
+ await new Promise((resolve) => setTimeout(resolve, 1e3 * Math.pow(2, attempt)));
5315
+ continue;
5316
+ }
5317
+ throw lastError;
5100
5318
  }
5101
- throw lastError;
5102
- }
5103
- if (responseData && typeof responseData === "object" && "success" in responseData && !responseData.success && responseData.error) {
5104
- lastError = handleErrorResponse(responseData, response.status);
5105
- const shouldRetry = lastError instanceof ApiError && lastError.recoverable;
5106
- if (shouldRetry && attempt < options.retries) {
5319
+ if (responseData && typeof responseData === "object" && "success" in responseData && !responseData.success && responseData.error) {
5320
+ lastError = handleErrorResponse(responseData, response.status);
5321
+ const shouldRetry = lastError instanceof ApiError && lastError.recoverable;
5322
+ if (shouldRetry && attempt < options.retries) {
5323
+ await new Promise((resolve) => setTimeout(resolve, 1e3 * Math.pow(2, attempt)));
5324
+ continue;
5325
+ }
5326
+ throw lastError;
5327
+ }
5328
+ return responseData;
5329
+ } catch (error) {
5330
+ clearTimeout(timeoutId);
5331
+ lastError = error instanceof Error ? error : new Error(String(error));
5332
+ const isNetworkError2 = error instanceof TypeError || error instanceof DOMException && error.name === "AbortError";
5333
+ if (isNetworkError2 && attempt < options.retries) {
5107
5334
  await new Promise((resolve) => setTimeout(resolve, 1e3 * Math.pow(2, attempt)));
5108
5335
  continue;
5109
5336
  }
5110
- throw lastError;
5111
- }
5112
- return responseData;
5113
- } catch (error) {
5114
- clearTimeout(timeoutId);
5115
- lastError = error;
5116
- const isNetworkError = error instanceof TypeError || error instanceof DOMException && error.name === "AbortError";
5117
- if (isNetworkError && attempt < options.retries) {
5118
- await new Promise((resolve) => setTimeout(resolve, 1e3 * Math.pow(2, attempt)));
5119
- continue;
5120
- }
5121
- if (!(error instanceof ApiError)) {
5122
- throw createNetworkError(error, url, options.timeout);
5337
+ if (!(error instanceof ApiError)) {
5338
+ throw createNetworkError(error, url, options.timeout);
5339
+ }
5340
+ throw error;
5123
5341
  }
5124
- throw error;
5125
5342
  }
5126
- }
5127
- throw lastError || new ApiError("Request failed after multiple retries", ApiErrorCode.INTERNAL_ERROR, 500);
5343
+ throw lastError || new ApiError("Request failed after multiple retries", ApiErrorCode.INTERNAL_ERROR, 500);
5344
+ }, context);
5128
5345
  }
5129
5346
 
5347
+ // src/api/activity.ts
5348
+ var ActivityApi = class {
5349
+ /**
5350
+ * Creates an instance of ActivityApi
5351
+ * @param options Request options
5352
+ */
5353
+ constructor(options) {
5354
+ this.options = options;
5355
+ }
5356
+ /**
5357
+ * Gets the global activity leaderboard
5358
+ * @param query Optional query parameters
5359
+ * @returns A promise resolving with the leaderboard response
5360
+ */
5361
+ async getLeaderboard(query) {
5362
+ return makeRequest(
5363
+ "GET",
5364
+ "/api/activity",
5365
+ this.options,
5366
+ void 0,
5367
+ query
5368
+ );
5369
+ }
5370
+ /**
5371
+ * Gets activity for a specific account
5372
+ * @param signerId The NEAR account ID
5373
+ * @param query Optional query parameters
5374
+ * @returns A promise resolving with the account activity response
5375
+ */
5376
+ async getAccountActivity(signerId, query) {
5377
+ return makeRequest(
5378
+ "GET",
5379
+ `/api/activity/${signerId}`,
5380
+ this.options,
5381
+ void 0,
5382
+ query
5383
+ );
5384
+ }
5385
+ /**
5386
+ * Gets posts for a specific account
5387
+ * @param signerId The NEAR account ID
5388
+ * @param query Optional query parameters
5389
+ * @returns A promise resolving with the account posts response
5390
+ */
5391
+ async getAccountPosts(signerId, query) {
5392
+ return makeRequest(
5393
+ "GET",
5394
+ `/api/activity/${signerId}/posts`,
5395
+ this.options,
5396
+ void 0,
5397
+ query
5398
+ );
5399
+ }
5400
+ };
5401
+
5130
5402
  // src/api/auth.ts
5131
5403
  var AuthApi = class {
5132
5404
  /**
@@ -5345,6 +5617,51 @@ var PostApi = class {
5345
5617
  }
5346
5618
  };
5347
5619
 
5620
+ // src/api/system.ts
5621
+ var SystemApi = class {
5622
+ /**
5623
+ * Creates an instance of SystemApi
5624
+ * @param options Request options
5625
+ */
5626
+ constructor(options) {
5627
+ this.options = options;
5628
+ }
5629
+ /**
5630
+ * Gets the current rate limit status
5631
+ * @returns A promise resolving with the rate limit response
5632
+ */
5633
+ async getRateLimits() {
5634
+ return makeRequest(
5635
+ "GET",
5636
+ "/api/rate-limit",
5637
+ this.options
5638
+ );
5639
+ }
5640
+ /**
5641
+ * Gets the rate limit status for a specific endpoint
5642
+ * @param endpoint The endpoint to get rate limit for
5643
+ * @returns A promise resolving with the endpoint rate limit response
5644
+ */
5645
+ async getEndpointRateLimit(endpoint) {
5646
+ return makeRequest(
5647
+ "GET",
5648
+ `/api/rate-limit/${endpoint}`,
5649
+ this.options
5650
+ );
5651
+ }
5652
+ /**
5653
+ * Gets the health status of the API
5654
+ * @returns A promise resolving with the health status
5655
+ */
5656
+ async getHealthStatus() {
5657
+ return makeRequest(
5658
+ "GET",
5659
+ "/health",
5660
+ this.options
5661
+ );
5662
+ }
5663
+ };
5664
+
5348
5665
  // src/core/config.ts
5349
5666
  var DEFAULT_CONFIG = {
5350
5667
  baseUrl: "https://open-crosspost-proxy.deno.dev/",
@@ -5362,23 +5679,32 @@ var CrosspostClient = class {
5362
5679
  const baseUrl = config.baseUrl || DEFAULT_CONFIG.baseUrl;
5363
5680
  const timeout = config.timeout || DEFAULT_CONFIG.timeout;
5364
5681
  const retries = config.retries ?? DEFAULT_CONFIG.retries;
5365
- const signature = config.signature || getAuthFromCookie();
5682
+ const nearAuthData = config.nearAuthData || getAuthFromCookie();
5366
5683
  this.options = {
5367
5684
  baseUrl,
5368
5685
  timeout,
5369
5686
  retries,
5370
- signature
5687
+ nearAuthData
5371
5688
  };
5372
5689
  this.auth = new AuthApi(this.options);
5373
5690
  this.post = new PostApi(this.options);
5691
+ this.activity = new ActivityApi(this.options);
5692
+ this.system = new SystemApi(this.options);
5374
5693
  }
5375
5694
  /**
5376
5695
  * Sets the authentication data (signature) for the client and stores it in a cookie
5377
5696
  * @param signature The NEAR authentication data
5378
5697
  */
5379
- async setAuthentication(signature) {
5380
- this.options.signature = signature;
5381
- storeAuthInCookie(signature);
5698
+ setAuthentication(nearAuthData) {
5699
+ this.options.nearAuthData = nearAuthData;
5700
+ storeAuthInCookie(nearAuthData);
5701
+ }
5702
+ /**
5703
+ * Checks if authentication data (signature) exists on client
5704
+ * @param signature The NEAR authentication data
5705
+ */
5706
+ isAuthenticated() {
5707
+ return !!this.options.nearAuthData;
5382
5708
  }
5383
5709
  };
5384
5710
  // Annotate the CommonJS export names for ESM import in node:
@@ -5393,6 +5719,9 @@ var CrosspostClient = class {
5393
5719
  AccountPostsParamsSchema,
5394
5720
  AccountPostsQuerySchema,
5395
5721
  AccountPostsResponseSchema,
5722
+ ActivityApi,
5723
+ ActivityLeaderboardQuerySchema,
5724
+ ActivityLeaderboardResponseSchema,
5396
5725
  AllRateLimitsResponseSchema,
5397
5726
  ApiError,
5398
5727
  ApiErrorCode,
@@ -5418,14 +5747,13 @@ var CrosspostClient = class {
5418
5747
  DeletePostRequestSchema,
5419
5748
  DeletePostResponseSchema,
5420
5749
  DeleteResultSchema,
5750
+ ERROR_CATEGORIES,
5421
5751
  EndpointRateLimitResponseSchema,
5422
5752
  EnhancedErrorResponseSchema,
5423
5753
  EnhancedResponseMetaSchema,
5424
5754
  EnhancedResponseSchema,
5425
5755
  ErrorDetailSchema,
5426
5756
  ErrorResponseSchema,
5427
- LeaderboardQuerySchema,
5428
- LeaderboardResponseSchema,
5429
5757
  LikePostRequestSchema,
5430
5758
  LikePostResponseSchema,
5431
5759
  LikeResultSchema,
@@ -5464,11 +5792,14 @@ var CrosspostClient = class {
5464
5792
  RepostRequestSchema,
5465
5793
  RepostResponseSchema,
5466
5794
  SuccessDetailSchema,
5795
+ SystemApi,
5467
5796
  TargetSchema,
5797
+ TimePeriod,
5468
5798
  UnlikePostRequestSchema,
5469
5799
  UnlikePostResponseSchema,
5470
5800
  UsageRateLimitSchema,
5471
5801
  UserProfileSchema,
5802
+ apiWrapper,
5472
5803
  clearAuthCookie,
5473
5804
  createApiResponse,
5474
5805
  createEnhancedApiResponse,
@@ -5478,8 +5809,21 @@ var CrosspostClient = class {
5478
5809
  createMultiStatusResponse,
5479
5810
  createNetworkError,
5480
5811
  createSuccessDetail,
5812
+ enrichErrorWithContext,
5481
5813
  getAuthFromCookie,
5482
5814
  getCsrfToken,
5815
+ getErrorDetails,
5816
+ getErrorMessage,
5483
5817
  handleErrorResponse,
5818
+ isAuthError,
5819
+ isContentError,
5820
+ isErrorOfCategory,
5821
+ isMediaError,
5822
+ isNetworkError,
5823
+ isPlatformError,
5824
+ isPostError,
5825
+ isRateLimitError,
5826
+ isRecoverableError,
5827
+ isValidationError,
5484
5828
  storeAuthInCookie
5485
5829
  });