@crosspost/sdk 0.1.3 → 0.1.5

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.js CHANGED
@@ -4059,19 +4059,22 @@ var z = /* @__PURE__ */ Object.freeze({
4059
4059
  });
4060
4060
 
4061
4061
  // ../types/dist/index.js
4062
- var PlatformSchema = z.enum([
4063
- "unknown",
4064
- "twitter"
4065
- // Add more platforms as they're implemented
4066
- // 'linkedin',
4067
- // 'facebook',
4068
- // 'instagram',
4069
- ]).describe("Social media platform");
4070
- var Platform = /* @__PURE__ */ ((Platform22) => {
4071
- Platform22["UNKNOWN"] = "unknown";
4072
- Platform22["TWITTER"] = "twitter";
4073
- return Platform22;
4062
+ var Platform = /* @__PURE__ */ ((Platform2) => {
4063
+ Platform2["UNKNOWN"] = "unknown";
4064
+ Platform2["TWITTER"] = "twitter";
4065
+ return Platform2;
4074
4066
  })(Platform || {});
4067
+ var PlatformSchema = z.nativeEnum(Platform).describe("Social media platform");
4068
+ var SUPPORTED_PLATFORMS = [
4069
+ "twitter"
4070
+ /* TWITTER */
4071
+ // Add more platforms here as they're implemented
4072
+ ];
4073
+ var SupportedPlatformSchema = SUPPORTED_PLATFORMS.length > 0 ? z.enum(SUPPORTED_PLATFORMS) : z.never();
4074
+ SupportedPlatformSchema.describe("Currently supported social media platforms");
4075
+ function isPlatformSupported(platform) {
4076
+ return SUPPORTED_PLATFORMS.includes(platform);
4077
+ }
4075
4078
  var ApiResponseSchema = z.object({
4076
4079
  data: z.any().describe("Response data"),
4077
4080
  meta: z.object({
@@ -4680,15 +4683,15 @@ var EndpointRateLimitResponseSchema = z.object({
4680
4683
  signerId: z.string().describe("NEAR account ID")
4681
4684
  }).describe("Endpoint rate limit response");
4682
4685
  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";
4686
+ TimePeriod2["ALL"] = "all";
4687
+ TimePeriod2["YEARLY"] = "year";
4688
+ TimePeriod2["MONTHLY"] = "month";
4689
+ TimePeriod2["WEEKLY"] = "week";
4690
+ TimePeriod2["DAILY"] = "day";
4688
4691
  return TimePeriod2;
4689
4692
  })(TimePeriod || {});
4690
4693
  var ActivityLeaderboardQuerySchema = z.object({
4691
- timeframe: z.enum(["day", "week", "month", "all"]).optional().describe(
4694
+ timeframe: z.nativeEnum(TimePeriod).optional().describe(
4692
4695
  "Timeframe for the leaderboard"
4693
4696
  ),
4694
4697
  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)"),
@@ -4707,7 +4710,7 @@ var AccountActivityEntrySchema = z.object({
4707
4710
  }).describe("Account activity entry");
4708
4711
  var ActivityLeaderboardResponseSchema = EnhancedResponseSchema(
4709
4712
  z.object({
4710
- timeframe: z.enum(["day", "week", "month", "all"]).describe("Timeframe for the leaderboard"),
4713
+ timeframe: z.nativeEnum(TimePeriod).describe("Timeframe for the leaderboard"),
4711
4714
  entries: z.array(AccountActivityEntrySchema).describe("Leaderboard entries"),
4712
4715
  total: z.number().describe("Total number of entries in the leaderboard"),
4713
4716
  limit: z.number().describe("Maximum number of results returned"),
@@ -4719,7 +4722,7 @@ var AccountActivityParamsSchema = z.object({
4719
4722
  signerId: z.string().describe("NEAR account ID")
4720
4723
  }).describe("Account activity params");
4721
4724
  var AccountActivityQuerySchema = z.object({
4722
- timeframe: z.enum(["day", "week", "month", "all"]).optional().describe(
4725
+ timeframe: z.nativeEnum(TimePeriod).optional().describe(
4723
4726
  "Timeframe for the activity"
4724
4727
  )
4725
4728
  }).describe("Account activity query");
@@ -4736,7 +4739,7 @@ var PlatformActivitySchema = z.object({
4736
4739
  var AccountActivityResponseSchema = EnhancedResponseSchema(
4737
4740
  z.object({
4738
4741
  signerId: z.string().describe("NEAR account ID"),
4739
- timeframe: z.enum(["day", "week", "month", "all"]).describe("Timeframe for the activity"),
4742
+ timeframe: z.nativeEnum(TimePeriod).describe("Timeframe for the activity"),
4740
4743
  totalPosts: z.number().describe("Total number of posts across all platforms"),
4741
4744
  totalLikes: z.number().describe("Total number of likes across all platforms"),
4742
4745
  totalReposts: z.number().describe("Total number of reposts across all platforms"),
@@ -4810,59 +4813,6 @@ var ProfileRefreshResponseSchema = EnhancedResponseSchema(
4810
4813
  import { createAuthToken } from "near-sign-verify";
4811
4814
 
4812
4815
  // src/utils/error.ts
4813
- function handleErrorResponse(data, status) {
4814
- const errorData = data?.error || {};
4815
- const message = errorData?.message || data?.message || "An API error occurred";
4816
- const codeString = errorData?.code || data?.code || ApiErrorCode.UNKNOWN_ERROR;
4817
- const code = Object.values(ApiErrorCode).includes(codeString) ? codeString : ApiErrorCode.UNKNOWN_ERROR;
4818
- const details = errorData?.details || data?.details || {};
4819
- const recoverable = errorData?.recoverable ?? data?.recoverable ?? false;
4820
- const platform = errorData?.platform || data?.platform;
4821
- const enhancedDetails = { ...details };
4822
- if (typeof enhancedDetails === "object" && !enhancedDetails.originalResponse) {
4823
- enhancedDetails.originalResponse = data;
4824
- }
4825
- if (platform && Object.values(Platform).includes(platform)) {
4826
- return new PlatformError(
4827
- message,
4828
- platform,
4829
- code,
4830
- // Use the parsed code
4831
- status,
4832
- // Cast status
4833
- enhancedDetails,
4834
- recoverable
4835
- );
4836
- } else {
4837
- return new ApiError(
4838
- message,
4839
- code,
4840
- // Use the parsed code
4841
- status,
4842
- // Cast status
4843
- enhancedDetails,
4844
- recoverable
4845
- );
4846
- }
4847
- }
4848
- function createNetworkError(error, url, timeout) {
4849
- if (error instanceof DOMException && error.name === "AbortError") {
4850
- return new ApiError(
4851
- `Request timed out after ${timeout}ms`,
4852
- ApiErrorCode.NETWORK_ERROR,
4853
- 408,
4854
- { url }
4855
- );
4856
- }
4857
- return new ApiError(
4858
- error instanceof Error ? error.message : "An unexpected error occurred during the request",
4859
- ApiErrorCode.INTERNAL_ERROR,
4860
- 500,
4861
- { originalError: String(error), url }
4862
- );
4863
- }
4864
-
4865
- // src/utils/error-utils.ts
4866
4816
  var ERROR_CATEGORIES = {
4867
4817
  AUTH: [
4868
4818
  ApiErrorCode.UNAUTHORIZED,
@@ -4990,9 +4940,6 @@ function enrichErrorWithContext(error, context) {
4990
4940
  false
4991
4941
  );
4992
4942
  }
4993
- function handleErrorResponse2(data, status) {
4994
- return handleErrorResponse(data, status);
4995
- }
4996
4943
  async function apiWrapper(apiCall, context) {
4997
4944
  try {
4998
4945
  return await apiCall();
@@ -5001,7 +4948,7 @@ async function apiWrapper(apiCall, context) {
5001
4948
  try {
5002
4949
  const errorData = await error.json();
5003
4950
  throw enrichErrorWithContext(
5004
- handleErrorResponse2(errorData, error.status),
4951
+ handleErrorResponse(errorData, error.status),
5005
4952
  context || {}
5006
4953
  );
5007
4954
  } catch (jsonError) {
@@ -5028,63 +4975,56 @@ async function apiWrapper(apiCall, context) {
5028
4975
  );
5029
4976
  }
5030
4977
  }
5031
-
5032
- // src/utils/cookie.ts
5033
- import Cookies from "js-cookie";
5034
- var AUTH_COOKIE_NAME = "__crosspost_auth";
5035
- var CSRF_COOKIE_NAME = "XSRF-TOKEN";
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
- };
5043
- var AUTH_COOKIE_OPTIONS = {
5044
- secure: true,
5045
- sameSite: "lax",
5046
- // Restrict to same-site and top-level navigation
5047
- path: "/",
5048
- expires: 30
5049
- // 30 days
5050
- };
5051
- function getAuthFromCookie() {
5052
- try {
5053
- if (!isBrowser()) {
5054
- return void 0;
5055
- }
5056
- const cookieValue = Cookies.get(AUTH_COOKIE_NAME);
5057
- if (!cookieValue) {
5058
- return void 0;
5059
- }
5060
- return JSON.parse(cookieValue);
5061
- } catch (error) {
5062
- console.error("Failed to parse auth cookie:", error);
5063
- return void 0;
5064
- }
5065
- }
5066
- function storeAuthInCookie(authData) {
5067
- try {
5068
- if (!isBrowser()) {
5069
- return;
5070
- }
5071
- const cookieValue = JSON.stringify(authData);
5072
- Cookies.set(AUTH_COOKIE_NAME, cookieValue, AUTH_COOKIE_OPTIONS);
5073
- } catch (error) {
5074
- console.error("Failed to store auth cookie:", error);
4978
+ function handleErrorResponse(data, status) {
4979
+ const errorData = data?.error || {};
4980
+ const message = errorData?.message || data?.message || "An API error occurred";
4981
+ const codeString = errorData?.code || data?.code || ApiErrorCode.UNKNOWN_ERROR;
4982
+ const code = Object.values(ApiErrorCode).includes(codeString) ? codeString : ApiErrorCode.UNKNOWN_ERROR;
4983
+ const details = errorData?.details || data?.details || {};
4984
+ const recoverable = errorData?.recoverable ?? data?.recoverable ?? false;
4985
+ const platform = errorData?.platform || data?.platform;
4986
+ const enhancedDetails = { ...details };
4987
+ if (typeof enhancedDetails === "object" && !enhancedDetails.originalResponse) {
4988
+ enhancedDetails.originalResponse = data;
5075
4989
  }
5076
- }
5077
- function clearAuthCookie() {
5078
- if (!isBrowser()) {
5079
- return;
4990
+ if (platform && Object.values(Platform).includes(platform)) {
4991
+ return new PlatformError(
4992
+ message,
4993
+ platform,
4994
+ code,
4995
+ // Use the parsed code
4996
+ status,
4997
+ // Cast status
4998
+ enhancedDetails,
4999
+ recoverable
5000
+ );
5001
+ } else {
5002
+ return new ApiError(
5003
+ message,
5004
+ code,
5005
+ // Use the parsed code
5006
+ status,
5007
+ // Cast status
5008
+ enhancedDetails,
5009
+ recoverable
5010
+ );
5080
5011
  }
5081
- Cookies.remove(AUTH_COOKIE_NAME, { path: AUTH_COOKIE_OPTIONS.path });
5082
5012
  }
5083
- function getCsrfToken() {
5084
- if (!isBrowser()) {
5085
- return void 0;
5013
+ function createNetworkError(error, url, timeout) {
5014
+ if (error instanceof DOMException && error.name === "AbortError") {
5015
+ return new ApiError(
5016
+ `Request timed out after ${timeout}ms`,
5017
+ ApiErrorCode.NETWORK_ERROR,
5018
+ 408,
5019
+ { url }
5020
+ );
5086
5021
  }
5087
- return Cookies.get(CSRF_COOKIE_NAME);
5022
+ return new ApiError(
5023
+ error instanceof Error ? error.message : "An unexpected error occurred during the request",
5024
+ ApiErrorCode.INTERNAL_ERROR,
5025
+ 500,
5026
+ { originalError: String(error), url }
5027
+ );
5088
5028
  }
5089
5029
 
5090
5030
  // src/core/request.ts
@@ -5122,12 +5062,6 @@ async function makeRequest(method, path, options, data, query) {
5122
5062
  "Accept": "application/json",
5123
5063
  "Authorization": `Bearer ${createAuthToken(options.nearAuthData)}`
5124
5064
  };
5125
- if (method !== "GET") {
5126
- const csrfToken = getCsrfToken();
5127
- if (csrfToken) {
5128
- headers[CSRF_HEADER_NAME] = csrfToken;
5129
- }
5130
- }
5131
5065
  const requestOptions = {
5132
5066
  method,
5133
5067
  headers,
@@ -5527,7 +5461,7 @@ var CrosspostClient = class {
5527
5461
  const baseUrl = config.baseUrl || DEFAULT_CONFIG.baseUrl;
5528
5462
  const timeout = config.timeout || DEFAULT_CONFIG.timeout;
5529
5463
  const retries = config.retries ?? DEFAULT_CONFIG.retries;
5530
- const nearAuthData = config.nearAuthData || getAuthFromCookie();
5464
+ const nearAuthData = config.nearAuthData;
5531
5465
  this.options = {
5532
5466
  baseUrl,
5533
5467
  timeout,
@@ -5540,12 +5474,11 @@ var CrosspostClient = class {
5540
5474
  this.system = new SystemApi(this.options);
5541
5475
  }
5542
5476
  /**
5543
- * Sets the authentication data (signature) for the client and stores it in a cookie
5544
- * @param signature The NEAR authentication data
5477
+ * Sets the authentication data (signature) for the client
5478
+ * @param nearAuthData The NEAR authentication data
5545
5479
  */
5546
5480
  setAuthentication(nearAuthData) {
5547
5481
  this.options.nearAuthData = nearAuthData;
5548
- storeAuthInCookie(nearAuthData);
5549
5482
  }
5550
5483
  /**
5551
5484
  * Checks if authentication data (signature) exists on client
@@ -5556,8 +5489,6 @@ var CrosspostClient = class {
5556
5489
  }
5557
5490
  };
5558
5491
  export {
5559
- AUTH_COOKIE_NAME,
5560
- AUTH_COOKIE_OPTIONS,
5561
5492
  AccountActivityEntrySchema,
5562
5493
  AccountActivityParamsSchema,
5563
5494
  AccountActivityQuerySchema,
@@ -5581,8 +5512,6 @@ export {
5581
5512
  AuthStatusResponseSchema,
5582
5513
  AuthUrlResponseSchema,
5583
5514
  BaseError,
5584
- CSRF_COOKIE_NAME,
5585
- CSRF_HEADER_NAME,
5586
5515
  ConnectedAccountSchema,
5587
5516
  ConnectedAccountsResponseSchema,
5588
5517
  CreatePostRequestSchema,
@@ -5638,7 +5567,9 @@ export {
5638
5567
  ReplyToPostResponseSchema,
5639
5568
  RepostRequestSchema,
5640
5569
  RepostResponseSchema,
5570
+ SUPPORTED_PLATFORMS,
5641
5571
  SuccessDetailSchema,
5572
+ SupportedPlatformSchema,
5642
5573
  SystemApi,
5643
5574
  TargetSchema,
5644
5575
  TimePeriod,
@@ -5647,7 +5578,6 @@ export {
5647
5578
  UsageRateLimitSchema,
5648
5579
  UserProfileSchema,
5649
5580
  apiWrapper,
5650
- clearAuthCookie,
5651
5581
  createApiResponse,
5652
5582
  createEnhancedApiResponse,
5653
5583
  createEnhancedErrorResponse,
@@ -5657,8 +5587,6 @@ export {
5657
5587
  createNetworkError,
5658
5588
  createSuccessDetail,
5659
5589
  enrichErrorWithContext,
5660
- getAuthFromCookie,
5661
- getCsrfToken,
5662
5590
  getErrorDetails,
5663
5591
  getErrorMessage,
5664
5592
  handleErrorResponse,
@@ -5668,9 +5596,9 @@ export {
5668
5596
  isMediaError,
5669
5597
  isNetworkError,
5670
5598
  isPlatformError,
5599
+ isPlatformSupported,
5671
5600
  isPostError,
5672
5601
  isRateLimitError,
5673
5602
  isRecoverableError,
5674
- isValidationError,
5675
- storeAuthInCookie
5603
+ isValidationError
5676
5604
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crosspost/sdk",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "SDK for interacting with the Crosspost API",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -36,9 +36,7 @@
36
36
  "author": "crosspost.near",
37
37
  "license": "MIT",
38
38
  "dependencies": {
39
- "@types/js-cookie": "^3.0.6",
40
- "js-cookie": "^3.0.5",
41
- "near-sign-verify": "^0.1.1"
39
+ "near-sign-verify": "^0.1.3"
42
40
  },
43
41
  "devDependencies": {
44
42
  "@types/node": "^20.10.5",
@@ -5,7 +5,6 @@ import { PostApi } from '../api/post.ts';
5
5
  import { SystemApi } from '../api/system.ts';
6
6
  import { type CrosspostClientConfig, DEFAULT_CONFIG } from './config.ts';
7
7
  import type { RequestOptions } from './request.ts';
8
- import { getAuthFromCookie, storeAuthInCookie } from '../utils/cookie.ts';
9
8
 
10
9
  /**
11
10
  * Main client for interacting with the Crosspost API service.
@@ -27,7 +26,7 @@ export class CrosspostClient {
27
26
  const timeout = config.timeout || DEFAULT_CONFIG.timeout;
28
27
  const retries = config.retries ?? DEFAULT_CONFIG.retries;
29
28
 
30
- const nearAuthData = config.nearAuthData || getAuthFromCookie();
29
+ const nearAuthData = config.nearAuthData;
31
30
 
32
31
  this.options = {
33
32
  baseUrl,
@@ -43,12 +42,11 @@ export class CrosspostClient {
43
42
  }
44
43
 
45
44
  /**
46
- * Sets the authentication data (signature) for the client and stores it in a cookie
47
- * @param signature The NEAR authentication data
45
+ * Sets the authentication data (signature) for the client
46
+ * @param nearAuthData The NEAR authentication data
48
47
  */
49
48
  public setAuthentication(nearAuthData: NearAuthData): void {
50
49
  this.options.nearAuthData = nearAuthData;
51
- storeAuthInCookie(nearAuthData);
52
50
  }
53
51
 
54
52
  /**
@@ -1,8 +1,6 @@
1
1
  import { ApiError, ApiErrorCode } from '@crosspost/types';
2
2
  import { createAuthToken, type NearAuthData } from 'near-sign-verify';
3
- import { createNetworkError, handleErrorResponse } from '../utils/error.ts';
4
- import { apiWrapper, enrichErrorWithContext } from '../utils/error-utils.ts';
5
- import { CSRF_HEADER_NAME, getCsrfToken } from '../utils/cookie.ts';
3
+ import { apiWrapper, createNetworkError, handleErrorResponse } from '../utils/error.ts';
6
4
 
7
5
  /**
8
6
  * Options for making a request to the API
@@ -85,14 +83,6 @@ export async function makeRequest<T>(
85
83
  'Authorization': `Bearer ${createAuthToken(options.nearAuthData!)}`,
86
84
  };
87
85
 
88
- // Add CSRF token for state-changing requests (non-GET)
89
- if (method !== 'GET') {
90
- const csrfToken = getCsrfToken();
91
- if (csrfToken) {
92
- headers[CSRF_HEADER_NAME] = csrfToken;
93
- }
94
- }
95
-
96
86
  const requestOptions: RequestInit = {
97
87
  method,
98
88
  headers,
package/src/index.ts CHANGED
@@ -14,13 +14,14 @@ export { PostApi } from './api/post.ts';
14
14
  export { SystemApi } from './api/system.ts';
15
15
 
16
16
  // Export utility functions
17
- export { createNetworkError, handleErrorResponse } from './utils/error.ts';
18
17
  export {
19
18
  apiWrapper,
19
+ createNetworkError,
20
20
  enrichErrorWithContext,
21
21
  ERROR_CATEGORIES,
22
22
  getErrorDetails,
23
23
  getErrorMessage,
24
+ handleErrorResponse,
24
25
  isAuthError,
25
26
  isContentError,
26
27
  isErrorOfCategory,
@@ -31,17 +32,7 @@ export {
31
32
  isRateLimitError,
32
33
  isRecoverableError,
33
34
  isValidationError,
34
- } from './utils/error-utils.ts';
35
- export {
36
- AUTH_COOKIE_NAME,
37
- AUTH_COOKIE_OPTIONS,
38
- clearAuthCookie,
39
- CSRF_COOKIE_NAME,
40
- CSRF_HEADER_NAME,
41
- getAuthFromCookie,
42
- getCsrfToken,
43
- storeAuthInCookie,
44
- } from './utils/cookie.ts';
35
+ } from './utils/error.ts';
45
36
 
46
37
  // Re-export types from @crosspost/types for convenience
47
38
  export * from '@crosspost/types';