@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/README.md +287 -176
- package/dist/index.cjs +438 -94
- package/dist/index.d.cts +193 -12
- package/dist/index.d.ts +193 -12
- package/dist/index.js +418 -92
- package/package.json +1 -1
- package/src/api/activity.ts +77 -0
- package/src/api/system.ts +55 -0
- package/src/core/client.ts +19 -16
- package/src/core/config.ts +4 -4
- package/src/core/request.ts +120 -94
- package/src/index.ts +25 -6
- package/src/utils/cookie.ts +21 -5
- package/src/utils/error-utils.ts +310 -0
package/dist/index.js
CHANGED
@@ -4067,10 +4067,10 @@ var PlatformSchema = z.enum([
|
|
4067
4067
|
// 'facebook',
|
4068
4068
|
// 'instagram',
|
4069
4069
|
]).describe("Social media platform");
|
4070
|
-
var Platform = /* @__PURE__ */ ((
|
4071
|
-
|
4072
|
-
|
4073
|
-
return
|
4070
|
+
var Platform = /* @__PURE__ */ ((Platform22) => {
|
4071
|
+
Platform22["UNKNOWN"] = "unknown";
|
4072
|
+
Platform22["TWITTER"] = "twitter";
|
4073
|
+
return Platform22;
|
4074
4074
|
})(Platform || {});
|
4075
4075
|
var ApiResponseSchema = z.object({
|
4076
4076
|
data: z.any().describe("Response data"),
|
@@ -4679,13 +4679,21 @@ var EndpointRateLimitResponseSchema = z.object({
|
|
4679
4679
|
endpoint: z.string().describe("API endpoint or action"),
|
4680
4680
|
signerId: z.string().describe("NEAR account ID")
|
4681
4681
|
}).describe("Endpoint rate limit response");
|
4682
|
-
var
|
4682
|
+
var TimePeriod = /* @__PURE__ */ ((TimePeriod2) => {
|
4683
|
+
TimePeriod2["ALL_TIME"] = "all";
|
4684
|
+
TimePeriod2["YEARLY"] = "yearly";
|
4685
|
+
TimePeriod2["MONTHLY"] = "monthly";
|
4686
|
+
TimePeriod2["WEEKLY"] = "weekly";
|
4687
|
+
TimePeriod2["DAILY"] = "daily";
|
4688
|
+
return TimePeriod2;
|
4689
|
+
})(TimePeriod || {});
|
4690
|
+
var ActivityLeaderboardQuerySchema = z.object({
|
4683
4691
|
timeframe: z.enum(["day", "week", "month", "all"]).optional().describe(
|
4684
4692
|
"Timeframe for the leaderboard"
|
4685
4693
|
),
|
4686
4694
|
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)"),
|
4687
4695
|
offset: z.string().optional().transform((val) => val ? parseInt(val, 10) : void 0).pipe(z.number().min(0).optional()).describe("Offset for pagination")
|
4688
|
-
}).describe("
|
4696
|
+
}).describe("Activity leaderboard query");
|
4689
4697
|
var AccountActivityEntrySchema = z.object({
|
4690
4698
|
signerId: z.string().describe("NEAR account ID"),
|
4691
4699
|
totalPosts: z.number().describe("Total number of posts"),
|
@@ -4697,7 +4705,7 @@ var AccountActivityEntrySchema = z.object({
|
|
4697
4705
|
rank: z.number().describe("Rank on the leaderboard"),
|
4698
4706
|
lastActive: z.string().datetime().describe("Timestamp of last activity")
|
4699
4707
|
}).describe("Account activity entry");
|
4700
|
-
var
|
4708
|
+
var ActivityLeaderboardResponseSchema = EnhancedResponseSchema(
|
4701
4709
|
z.object({
|
4702
4710
|
timeframe: z.enum(["day", "week", "month", "all"]).describe("Timeframe for the leaderboard"),
|
4703
4711
|
entries: z.array(AccountActivityEntrySchema).describe("Leaderboard entries"),
|
@@ -4706,7 +4714,7 @@ var LeaderboardResponseSchema = EnhancedResponseSchema(
|
|
4706
4714
|
offset: z.number().describe("Offset for pagination"),
|
4707
4715
|
generatedAt: z.string().datetime().describe("Timestamp when the leaderboard was generated")
|
4708
4716
|
})
|
4709
|
-
).describe("
|
4717
|
+
).describe("Activity leaderboard response");
|
4710
4718
|
var AccountActivityParamsSchema = z.object({
|
4711
4719
|
signerId: z.string().describe("NEAR account ID")
|
4712
4720
|
}).describe("Account activity params");
|
@@ -4854,22 +4862,195 @@ function createNetworkError(error, url, timeout) {
|
|
4854
4862
|
);
|
4855
4863
|
}
|
4856
4864
|
|
4865
|
+
// src/utils/error-utils.ts
|
4866
|
+
var ERROR_CATEGORIES = {
|
4867
|
+
AUTH: [
|
4868
|
+
ApiErrorCode.UNAUTHORIZED,
|
4869
|
+
ApiErrorCode.FORBIDDEN
|
4870
|
+
],
|
4871
|
+
VALIDATION: [
|
4872
|
+
ApiErrorCode.VALIDATION_ERROR,
|
4873
|
+
ApiErrorCode.INVALID_REQUEST
|
4874
|
+
],
|
4875
|
+
NETWORK: [
|
4876
|
+
ApiErrorCode.NETWORK_ERROR
|
4877
|
+
],
|
4878
|
+
PLATFORM: [
|
4879
|
+
ApiErrorCode.PLATFORM_ERROR,
|
4880
|
+
ApiErrorCode.PLATFORM_UNAVAILABLE
|
4881
|
+
],
|
4882
|
+
CONTENT: [
|
4883
|
+
ApiErrorCode.CONTENT_POLICY_VIOLATION,
|
4884
|
+
ApiErrorCode.DUPLICATE_CONTENT
|
4885
|
+
],
|
4886
|
+
RATE_LIMIT: [
|
4887
|
+
ApiErrorCode.RATE_LIMITED
|
4888
|
+
],
|
4889
|
+
POST: [
|
4890
|
+
ApiErrorCode.POST_CREATION_FAILED,
|
4891
|
+
ApiErrorCode.THREAD_CREATION_FAILED,
|
4892
|
+
ApiErrorCode.POST_DELETION_FAILED,
|
4893
|
+
ApiErrorCode.POST_INTERACTION_FAILED
|
4894
|
+
],
|
4895
|
+
MEDIA: [
|
4896
|
+
ApiErrorCode.MEDIA_UPLOAD_FAILED
|
4897
|
+
]
|
4898
|
+
};
|
4899
|
+
function isErrorOfCategory(error, category) {
|
4900
|
+
if (error instanceof ApiError) {
|
4901
|
+
return category.includes(error.code);
|
4902
|
+
}
|
4903
|
+
if (error instanceof PlatformError) {
|
4904
|
+
return category.includes(error.code);
|
4905
|
+
}
|
4906
|
+
if (error && typeof error === "object" && "code" in error) {
|
4907
|
+
return category.includes(error.code);
|
4908
|
+
}
|
4909
|
+
return false;
|
4910
|
+
}
|
4911
|
+
function isAuthError(error) {
|
4912
|
+
return isErrorOfCategory(error, ERROR_CATEGORIES.AUTH);
|
4913
|
+
}
|
4914
|
+
function isValidationError(error) {
|
4915
|
+
return isErrorOfCategory(error, ERROR_CATEGORIES.VALIDATION);
|
4916
|
+
}
|
4917
|
+
function isNetworkError(error) {
|
4918
|
+
return isErrorOfCategory(error, ERROR_CATEGORIES.NETWORK);
|
4919
|
+
}
|
4920
|
+
function isPlatformError(error) {
|
4921
|
+
return isErrorOfCategory(error, ERROR_CATEGORIES.PLATFORM) || error instanceof PlatformError;
|
4922
|
+
}
|
4923
|
+
function isContentError(error) {
|
4924
|
+
return isErrorOfCategory(error, ERROR_CATEGORIES.CONTENT);
|
4925
|
+
}
|
4926
|
+
function isRateLimitError(error) {
|
4927
|
+
return isErrorOfCategory(error, ERROR_CATEGORIES.RATE_LIMIT);
|
4928
|
+
}
|
4929
|
+
function isPostError(error) {
|
4930
|
+
return isErrorOfCategory(error, ERROR_CATEGORIES.POST);
|
4931
|
+
}
|
4932
|
+
function isMediaError(error) {
|
4933
|
+
return isErrorOfCategory(error, ERROR_CATEGORIES.MEDIA);
|
4934
|
+
}
|
4935
|
+
function isRecoverableError(error) {
|
4936
|
+
if (error instanceof ApiError || error instanceof PlatformError) {
|
4937
|
+
return error.recoverable;
|
4938
|
+
}
|
4939
|
+
return false;
|
4940
|
+
}
|
4941
|
+
function getErrorMessage(error, defaultMessage = "An error occurred") {
|
4942
|
+
if (error instanceof Error) {
|
4943
|
+
return error.message || defaultMessage;
|
4944
|
+
}
|
4945
|
+
if (typeof error === "string") {
|
4946
|
+
return error;
|
4947
|
+
}
|
4948
|
+
if (error && typeof error === "object" && "message" in error) {
|
4949
|
+
return error.message || defaultMessage;
|
4950
|
+
}
|
4951
|
+
return defaultMessage;
|
4952
|
+
}
|
4953
|
+
function getErrorDetails(error) {
|
4954
|
+
if (error instanceof ApiError || error instanceof PlatformError) {
|
4955
|
+
return error.details;
|
4956
|
+
}
|
4957
|
+
if (error && typeof error === "object" && "details" in error) {
|
4958
|
+
return error.details;
|
4959
|
+
}
|
4960
|
+
return void 0;
|
4961
|
+
}
|
4962
|
+
function enrichErrorWithContext(error, context) {
|
4963
|
+
if (error instanceof ApiError) {
|
4964
|
+
return new ApiError(
|
4965
|
+
error.message,
|
4966
|
+
error.code,
|
4967
|
+
error.status,
|
4968
|
+
{ ...error.details || {}, ...context },
|
4969
|
+
error.recoverable
|
4970
|
+
);
|
4971
|
+
}
|
4972
|
+
if (error instanceof PlatformError) {
|
4973
|
+
return new PlatformError(
|
4974
|
+
error.message,
|
4975
|
+
error.platform,
|
4976
|
+
error.code,
|
4977
|
+
error.recoverable,
|
4978
|
+
error.originalError,
|
4979
|
+
error.status,
|
4980
|
+
error.userId,
|
4981
|
+
{ ...error.details || {}, ...context }
|
4982
|
+
);
|
4983
|
+
}
|
4984
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
4985
|
+
return new ApiError(
|
4986
|
+
errorMessage || "An error occurred",
|
4987
|
+
ApiErrorCode.INTERNAL_ERROR,
|
4988
|
+
500,
|
4989
|
+
{ originalError: error, ...context },
|
4990
|
+
false
|
4991
|
+
);
|
4992
|
+
}
|
4993
|
+
function handleErrorResponse2(data, status) {
|
4994
|
+
return handleErrorResponse(data, status);
|
4995
|
+
}
|
4996
|
+
async function apiWrapper(apiCall, context) {
|
4997
|
+
try {
|
4998
|
+
return await apiCall();
|
4999
|
+
} catch (error) {
|
5000
|
+
if (error instanceof Response) {
|
5001
|
+
try {
|
5002
|
+
const errorData = await error.json();
|
5003
|
+
throw enrichErrorWithContext(
|
5004
|
+
handleErrorResponse2(errorData, error.status),
|
5005
|
+
context || {}
|
5006
|
+
);
|
5007
|
+
} catch (jsonError) {
|
5008
|
+
if (jsonError instanceof Error && jsonError.name === "SyntaxError") {
|
5009
|
+
throw enrichErrorWithContext(
|
5010
|
+
new ApiError(
|
5011
|
+
`API request failed with status ${error.status} and non-JSON response`,
|
5012
|
+
ApiErrorCode.NETWORK_ERROR,
|
5013
|
+
error.status,
|
5014
|
+
{ originalResponse: error.statusText }
|
5015
|
+
),
|
5016
|
+
context || {}
|
5017
|
+
);
|
5018
|
+
}
|
5019
|
+
throw jsonError;
|
5020
|
+
}
|
5021
|
+
}
|
5022
|
+
if (error instanceof ApiError || error instanceof PlatformError) {
|
5023
|
+
throw enrichErrorWithContext(error, context || {});
|
5024
|
+
}
|
5025
|
+
throw enrichErrorWithContext(
|
5026
|
+
error instanceof Error ? error : new Error(String(error)),
|
5027
|
+
context || {}
|
5028
|
+
);
|
5029
|
+
}
|
5030
|
+
}
|
5031
|
+
|
4857
5032
|
// src/utils/cookie.ts
|
4858
5033
|
import Cookies from "js-cookie";
|
4859
5034
|
var AUTH_COOKIE_NAME = "__crosspost_auth";
|
4860
5035
|
var CSRF_COOKIE_NAME = "XSRF-TOKEN";
|
4861
5036
|
var CSRF_HEADER_NAME = "X-CSRF-Token";
|
5037
|
+
var isDeno = () => {
|
5038
|
+
return typeof globalThis.Deno !== "undefined";
|
5039
|
+
};
|
5040
|
+
var isBrowser = () => {
|
5041
|
+
return !isDeno() && typeof globalThis.window !== "undefined";
|
5042
|
+
};
|
4862
5043
|
var AUTH_COOKIE_OPTIONS = {
|
4863
5044
|
secure: true,
|
4864
5045
|
sameSite: "lax",
|
4865
|
-
//
|
5046
|
+
// Restrict to same-site and top-level navigation
|
4866
5047
|
path: "/",
|
4867
5048
|
expires: 30
|
4868
5049
|
// 30 days
|
4869
5050
|
};
|
4870
5051
|
function getAuthFromCookie() {
|
4871
5052
|
try {
|
4872
|
-
if (
|
5053
|
+
if (!isBrowser()) {
|
4873
5054
|
return void 0;
|
4874
5055
|
}
|
4875
5056
|
const cookieValue = Cookies.get(AUTH_COOKIE_NAME);
|
@@ -4884,7 +5065,7 @@ function getAuthFromCookie() {
|
|
4884
5065
|
}
|
4885
5066
|
function storeAuthInCookie(authData) {
|
4886
5067
|
try {
|
4887
|
-
if (
|
5068
|
+
if (!isBrowser()) {
|
4888
5069
|
return;
|
4889
5070
|
}
|
4890
5071
|
const cookieValue = JSON.stringify(authData);
|
@@ -4894,105 +5075,178 @@ function storeAuthInCookie(authData) {
|
|
4894
5075
|
}
|
4895
5076
|
}
|
4896
5077
|
function clearAuthCookie() {
|
4897
|
-
if (
|
5078
|
+
if (!isBrowser()) {
|
4898
5079
|
return;
|
4899
5080
|
}
|
4900
5081
|
Cookies.remove(AUTH_COOKIE_NAME, { path: AUTH_COOKIE_OPTIONS.path });
|
4901
5082
|
}
|
4902
5083
|
function getCsrfToken() {
|
4903
|
-
if (
|
5084
|
+
if (!isBrowser()) {
|
4904
5085
|
return void 0;
|
4905
5086
|
}
|
4906
5087
|
return Cookies.get(CSRF_COOKIE_NAME);
|
4907
5088
|
}
|
4908
5089
|
|
4909
5090
|
// src/core/request.ts
|
4910
|
-
async function makeRequest(method, path, options, data) {
|
4911
|
-
|
4912
|
-
|
4913
|
-
|
5091
|
+
async function makeRequest(method, path, options, data, query) {
|
5092
|
+
let url = `${options.baseUrl}${path.startsWith("/") ? path : `/${path}`}`;
|
5093
|
+
if (query && Object.keys(query).length > 0) {
|
5094
|
+
const queryParams = new URLSearchParams();
|
5095
|
+
for (const [key, value] of Object.entries(query)) {
|
5096
|
+
if (value !== void 0 && value !== null) {
|
5097
|
+
queryParams.append(key, String(value));
|
5098
|
+
}
|
5099
|
+
}
|
5100
|
+
const queryString = queryParams.toString();
|
5101
|
+
if (queryString) {
|
5102
|
+
url += `?${queryString}`;
|
5103
|
+
}
|
5104
|
+
}
|
5105
|
+
if (!options.nearAuthData) {
|
4914
5106
|
throw ApiError.unauthorized("Authentication required. Please provide NEAR signature.");
|
4915
5107
|
}
|
4916
|
-
|
4917
|
-
|
4918
|
-
|
4919
|
-
|
4920
|
-
|
4921
|
-
|
4922
|
-
|
4923
|
-
|
4924
|
-
|
4925
|
-
|
4926
|
-
|
4927
|
-
if (csrfToken) {
|
4928
|
-
headers[CSRF_HEADER_NAME] = csrfToken;
|
4929
|
-
}
|
4930
|
-
}
|
4931
|
-
const requestOptions = {
|
4932
|
-
method,
|
4933
|
-
headers,
|
4934
|
-
body: method !== "GET" && data ? JSON.stringify(data) : void 0,
|
4935
|
-
signal: controller.signal
|
4936
|
-
};
|
4937
|
-
const response = await fetch(url, requestOptions);
|
4938
|
-
clearTimeout(timeoutId);
|
4939
|
-
let responseData;
|
5108
|
+
const context = {
|
5109
|
+
method,
|
5110
|
+
path,
|
5111
|
+
url,
|
5112
|
+
retries: options.retries
|
5113
|
+
};
|
5114
|
+
return apiWrapper(async () => {
|
5115
|
+
let lastError = null;
|
5116
|
+
for (let attempt = 0; attempt <= options.retries; attempt++) {
|
5117
|
+
const controller = new AbortController();
|
5118
|
+
const timeoutId = setTimeout(() => controller.abort(), options.timeout);
|
4940
5119
|
try {
|
4941
|
-
|
4942
|
-
|
4943
|
-
|
5120
|
+
const headers = {
|
5121
|
+
"Content-Type": "application/json",
|
5122
|
+
"Accept": "application/json",
|
5123
|
+
"Authorization": `Bearer ${createAuthToken(options.nearAuthData)}`
|
5124
|
+
};
|
5125
|
+
if (method !== "GET") {
|
5126
|
+
const csrfToken = getCsrfToken();
|
5127
|
+
if (csrfToken) {
|
5128
|
+
headers[CSRF_HEADER_NAME] = csrfToken;
|
5129
|
+
}
|
5130
|
+
}
|
5131
|
+
const requestOptions = {
|
5132
|
+
method,
|
5133
|
+
headers,
|
5134
|
+
body: method !== "GET" && data ? JSON.stringify(data) : void 0,
|
5135
|
+
signal: controller.signal
|
5136
|
+
};
|
5137
|
+
const response = await fetch(url, requestOptions);
|
5138
|
+
clearTimeout(timeoutId);
|
5139
|
+
let responseData;
|
5140
|
+
try {
|
5141
|
+
responseData = await response.json();
|
5142
|
+
} catch (jsonError) {
|
5143
|
+
if (!response.ok) {
|
5144
|
+
throw new ApiError(
|
5145
|
+
`API request failed with status ${response.status} and non-JSON response`,
|
5146
|
+
ApiErrorCode.NETWORK_ERROR,
|
5147
|
+
response.status,
|
5148
|
+
{ originalStatusText: response.statusText }
|
5149
|
+
);
|
5150
|
+
}
|
5151
|
+
if (response.status === 204) return {};
|
4944
5152
|
throw new ApiError(
|
4945
|
-
`
|
4946
|
-
ApiErrorCode.
|
4947
|
-
|
4948
|
-
response.status,
|
4949
|
-
{ originalStatusText: response.statusText }
|
5153
|
+
`Failed to parse JSON response: ${jsonError instanceof Error ? jsonError.message : String(jsonError)}`,
|
5154
|
+
ApiErrorCode.INTERNAL_ERROR,
|
5155
|
+
response.status
|
4950
5156
|
);
|
4951
5157
|
}
|
4952
|
-
if (response.
|
4953
|
-
|
4954
|
-
|
4955
|
-
|
4956
|
-
|
4957
|
-
|
4958
|
-
|
4959
|
-
|
4960
|
-
if (!response.ok) {
|
4961
|
-
lastError = handleErrorResponse(responseData, response.status);
|
4962
|
-
const shouldRetry = response.status >= 500 || lastError instanceof ApiError && lastError.recoverable;
|
4963
|
-
if (shouldRetry && attempt < options.retries) {
|
4964
|
-
await new Promise((resolve) => setTimeout(resolve, 1e3 * Math.pow(2, attempt)));
|
4965
|
-
continue;
|
5158
|
+
if (!response.ok) {
|
5159
|
+
lastError = handleErrorResponse(responseData, response.status);
|
5160
|
+
const shouldRetry = response.status >= 500 || lastError instanceof ApiError && lastError.recoverable;
|
5161
|
+
if (shouldRetry && attempt < options.retries) {
|
5162
|
+
await new Promise((resolve) => setTimeout(resolve, 1e3 * Math.pow(2, attempt)));
|
5163
|
+
continue;
|
5164
|
+
}
|
5165
|
+
throw lastError;
|
4966
5166
|
}
|
4967
|
-
|
4968
|
-
|
4969
|
-
|
4970
|
-
|
4971
|
-
|
4972
|
-
|
5167
|
+
if (responseData && typeof responseData === "object" && "success" in responseData && !responseData.success && responseData.error) {
|
5168
|
+
lastError = handleErrorResponse(responseData, response.status);
|
5169
|
+
const shouldRetry = lastError instanceof ApiError && lastError.recoverable;
|
5170
|
+
if (shouldRetry && attempt < options.retries) {
|
5171
|
+
await new Promise((resolve) => setTimeout(resolve, 1e3 * Math.pow(2, attempt)));
|
5172
|
+
continue;
|
5173
|
+
}
|
5174
|
+
throw lastError;
|
5175
|
+
}
|
5176
|
+
return responseData;
|
5177
|
+
} catch (error) {
|
5178
|
+
clearTimeout(timeoutId);
|
5179
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
5180
|
+
const isNetworkError2 = error instanceof TypeError || error instanceof DOMException && error.name === "AbortError";
|
5181
|
+
if (isNetworkError2 && attempt < options.retries) {
|
4973
5182
|
await new Promise((resolve) => setTimeout(resolve, 1e3 * Math.pow(2, attempt)));
|
4974
5183
|
continue;
|
4975
5184
|
}
|
4976
|
-
|
4977
|
-
|
4978
|
-
|
4979
|
-
|
4980
|
-
clearTimeout(timeoutId);
|
4981
|
-
lastError = error;
|
4982
|
-
const isNetworkError = error instanceof TypeError || error instanceof DOMException && error.name === "AbortError";
|
4983
|
-
if (isNetworkError && attempt < options.retries) {
|
4984
|
-
await new Promise((resolve) => setTimeout(resolve, 1e3 * Math.pow(2, attempt)));
|
4985
|
-
continue;
|
4986
|
-
}
|
4987
|
-
if (!(error instanceof ApiError)) {
|
4988
|
-
throw createNetworkError(error, url, options.timeout);
|
5185
|
+
if (!(error instanceof ApiError)) {
|
5186
|
+
throw createNetworkError(error, url, options.timeout);
|
5187
|
+
}
|
5188
|
+
throw error;
|
4989
5189
|
}
|
4990
|
-
throw error;
|
4991
5190
|
}
|
4992
|
-
|
4993
|
-
|
5191
|
+
throw lastError || new ApiError("Request failed after multiple retries", ApiErrorCode.INTERNAL_ERROR, 500);
|
5192
|
+
}, context);
|
4994
5193
|
}
|
4995
5194
|
|
5195
|
+
// src/api/activity.ts
|
5196
|
+
var ActivityApi = class {
|
5197
|
+
/**
|
5198
|
+
* Creates an instance of ActivityApi
|
5199
|
+
* @param options Request options
|
5200
|
+
*/
|
5201
|
+
constructor(options) {
|
5202
|
+
this.options = options;
|
5203
|
+
}
|
5204
|
+
/**
|
5205
|
+
* Gets the global activity leaderboard
|
5206
|
+
* @param query Optional query parameters
|
5207
|
+
* @returns A promise resolving with the leaderboard response
|
5208
|
+
*/
|
5209
|
+
async getLeaderboard(query) {
|
5210
|
+
return makeRequest(
|
5211
|
+
"GET",
|
5212
|
+
"/api/activity",
|
5213
|
+
this.options,
|
5214
|
+
void 0,
|
5215
|
+
query
|
5216
|
+
);
|
5217
|
+
}
|
5218
|
+
/**
|
5219
|
+
* Gets activity for a specific account
|
5220
|
+
* @param signerId The NEAR account ID
|
5221
|
+
* @param query Optional query parameters
|
5222
|
+
* @returns A promise resolving with the account activity response
|
5223
|
+
*/
|
5224
|
+
async getAccountActivity(signerId, query) {
|
5225
|
+
return makeRequest(
|
5226
|
+
"GET",
|
5227
|
+
`/api/activity/${signerId}`,
|
5228
|
+
this.options,
|
5229
|
+
void 0,
|
5230
|
+
query
|
5231
|
+
);
|
5232
|
+
}
|
5233
|
+
/**
|
5234
|
+
* Gets posts for a specific account
|
5235
|
+
* @param signerId The NEAR account ID
|
5236
|
+
* @param query Optional query parameters
|
5237
|
+
* @returns A promise resolving with the account posts response
|
5238
|
+
*/
|
5239
|
+
async getAccountPosts(signerId, query) {
|
5240
|
+
return makeRequest(
|
5241
|
+
"GET",
|
5242
|
+
`/api/activity/${signerId}/posts`,
|
5243
|
+
this.options,
|
5244
|
+
void 0,
|
5245
|
+
query
|
5246
|
+
);
|
5247
|
+
}
|
5248
|
+
};
|
5249
|
+
|
4996
5250
|
// src/api/auth.ts
|
4997
5251
|
var AuthApi = class {
|
4998
5252
|
/**
|
@@ -5211,6 +5465,51 @@ var PostApi = class {
|
|
5211
5465
|
}
|
5212
5466
|
};
|
5213
5467
|
|
5468
|
+
// src/api/system.ts
|
5469
|
+
var SystemApi = class {
|
5470
|
+
/**
|
5471
|
+
* Creates an instance of SystemApi
|
5472
|
+
* @param options Request options
|
5473
|
+
*/
|
5474
|
+
constructor(options) {
|
5475
|
+
this.options = options;
|
5476
|
+
}
|
5477
|
+
/**
|
5478
|
+
* Gets the current rate limit status
|
5479
|
+
* @returns A promise resolving with the rate limit response
|
5480
|
+
*/
|
5481
|
+
async getRateLimits() {
|
5482
|
+
return makeRequest(
|
5483
|
+
"GET",
|
5484
|
+
"/api/rate-limit",
|
5485
|
+
this.options
|
5486
|
+
);
|
5487
|
+
}
|
5488
|
+
/**
|
5489
|
+
* Gets the rate limit status for a specific endpoint
|
5490
|
+
* @param endpoint The endpoint to get rate limit for
|
5491
|
+
* @returns A promise resolving with the endpoint rate limit response
|
5492
|
+
*/
|
5493
|
+
async getEndpointRateLimit(endpoint) {
|
5494
|
+
return makeRequest(
|
5495
|
+
"GET",
|
5496
|
+
`/api/rate-limit/${endpoint}`,
|
5497
|
+
this.options
|
5498
|
+
);
|
5499
|
+
}
|
5500
|
+
/**
|
5501
|
+
* Gets the health status of the API
|
5502
|
+
* @returns A promise resolving with the health status
|
5503
|
+
*/
|
5504
|
+
async getHealthStatus() {
|
5505
|
+
return makeRequest(
|
5506
|
+
"GET",
|
5507
|
+
"/health",
|
5508
|
+
this.options
|
5509
|
+
);
|
5510
|
+
}
|
5511
|
+
};
|
5512
|
+
|
5214
5513
|
// src/core/config.ts
|
5215
5514
|
var DEFAULT_CONFIG = {
|
5216
5515
|
baseUrl: "https://open-crosspost-proxy.deno.dev/",
|
@@ -5228,23 +5527,32 @@ var CrosspostClient = class {
|
|
5228
5527
|
const baseUrl = config.baseUrl || DEFAULT_CONFIG.baseUrl;
|
5229
5528
|
const timeout = config.timeout || DEFAULT_CONFIG.timeout;
|
5230
5529
|
const retries = config.retries ?? DEFAULT_CONFIG.retries;
|
5231
|
-
const
|
5530
|
+
const nearAuthData = config.nearAuthData || getAuthFromCookie();
|
5232
5531
|
this.options = {
|
5233
5532
|
baseUrl,
|
5234
5533
|
timeout,
|
5235
5534
|
retries,
|
5236
|
-
|
5535
|
+
nearAuthData
|
5237
5536
|
};
|
5238
5537
|
this.auth = new AuthApi(this.options);
|
5239
5538
|
this.post = new PostApi(this.options);
|
5539
|
+
this.activity = new ActivityApi(this.options);
|
5540
|
+
this.system = new SystemApi(this.options);
|
5240
5541
|
}
|
5241
5542
|
/**
|
5242
5543
|
* Sets the authentication data (signature) for the client and stores it in a cookie
|
5243
5544
|
* @param signature The NEAR authentication data
|
5244
5545
|
*/
|
5245
|
-
|
5246
|
-
this.options.
|
5247
|
-
storeAuthInCookie(
|
5546
|
+
setAuthentication(nearAuthData) {
|
5547
|
+
this.options.nearAuthData = nearAuthData;
|
5548
|
+
storeAuthInCookie(nearAuthData);
|
5549
|
+
}
|
5550
|
+
/**
|
5551
|
+
* Checks if authentication data (signature) exists on client
|
5552
|
+
* @param signature The NEAR authentication data
|
5553
|
+
*/
|
5554
|
+
isAuthenticated() {
|
5555
|
+
return !!this.options.nearAuthData;
|
5248
5556
|
}
|
5249
5557
|
};
|
5250
5558
|
export {
|
@@ -5258,6 +5566,9 @@ export {
|
|
5258
5566
|
AccountPostsParamsSchema,
|
5259
5567
|
AccountPostsQuerySchema,
|
5260
5568
|
AccountPostsResponseSchema,
|
5569
|
+
ActivityApi,
|
5570
|
+
ActivityLeaderboardQuerySchema,
|
5571
|
+
ActivityLeaderboardResponseSchema,
|
5261
5572
|
AllRateLimitsResponseSchema,
|
5262
5573
|
ApiError,
|
5263
5574
|
ApiErrorCode,
|
@@ -5283,14 +5594,13 @@ export {
|
|
5283
5594
|
DeletePostRequestSchema,
|
5284
5595
|
DeletePostResponseSchema,
|
5285
5596
|
DeleteResultSchema,
|
5597
|
+
ERROR_CATEGORIES,
|
5286
5598
|
EndpointRateLimitResponseSchema,
|
5287
5599
|
EnhancedErrorResponseSchema,
|
5288
5600
|
EnhancedResponseMetaSchema,
|
5289
5601
|
EnhancedResponseSchema,
|
5290
5602
|
ErrorDetailSchema,
|
5291
5603
|
ErrorResponseSchema,
|
5292
|
-
LeaderboardQuerySchema,
|
5293
|
-
LeaderboardResponseSchema,
|
5294
5604
|
LikePostRequestSchema,
|
5295
5605
|
LikePostResponseSchema,
|
5296
5606
|
LikeResultSchema,
|
@@ -5329,11 +5639,14 @@ export {
|
|
5329
5639
|
RepostRequestSchema,
|
5330
5640
|
RepostResponseSchema,
|
5331
5641
|
SuccessDetailSchema,
|
5642
|
+
SystemApi,
|
5332
5643
|
TargetSchema,
|
5644
|
+
TimePeriod,
|
5333
5645
|
UnlikePostRequestSchema,
|
5334
5646
|
UnlikePostResponseSchema,
|
5335
5647
|
UsageRateLimitSchema,
|
5336
5648
|
UserProfileSchema,
|
5649
|
+
apiWrapper,
|
5337
5650
|
clearAuthCookie,
|
5338
5651
|
createApiResponse,
|
5339
5652
|
createEnhancedApiResponse,
|
@@ -5343,8 +5656,21 @@ export {
|
|
5343
5656
|
createMultiStatusResponse,
|
5344
5657
|
createNetworkError,
|
5345
5658
|
createSuccessDetail,
|
5659
|
+
enrichErrorWithContext,
|
5346
5660
|
getAuthFromCookie,
|
5347
5661
|
getCsrfToken,
|
5662
|
+
getErrorDetails,
|
5663
|
+
getErrorMessage,
|
5348
5664
|
handleErrorResponse,
|
5665
|
+
isAuthError,
|
5666
|
+
isContentError,
|
5667
|
+
isErrorOfCategory,
|
5668
|
+
isMediaError,
|
5669
|
+
isNetworkError,
|
5670
|
+
isPlatformError,
|
5671
|
+
isPostError,
|
5672
|
+
isRateLimitError,
|
5673
|
+
isRecoverableError,
|
5674
|
+
isValidationError,
|
5349
5675
|
storeAuthInCookie
|
5350
5676
|
};
|