@crosspost/types 0.1.2 → 0.1.4
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/LICENSE +21 -0
- package/README.md +4 -32
- package/dist/index.cjs +37 -19
- package/dist/index.d.cts +273 -228
- package/dist/index.d.ts +273 -228
- package/dist/index.js +30 -16
- package/package.json +1 -1
- package/src/activity.ts +247 -0
- package/src/common.ts +32 -16
- package/src/index.ts +1 -1
package/dist/index.js
CHANGED
@@ -1,18 +1,20 @@
|
|
1
1
|
// src/common.ts
|
2
2
|
import { z } from "zod";
|
3
|
-
var PlatformSchema = z.enum([
|
4
|
-
"unknown",
|
5
|
-
"twitter"
|
6
|
-
// Add more platforms as they're implemented
|
7
|
-
// 'linkedin',
|
8
|
-
// 'facebook',
|
9
|
-
// 'instagram',
|
10
|
-
]).describe("Social media platform");
|
11
3
|
var Platform = /* @__PURE__ */ ((Platform2) => {
|
12
4
|
Platform2["UNKNOWN"] = "unknown";
|
13
5
|
Platform2["TWITTER"] = "twitter";
|
14
6
|
return Platform2;
|
15
7
|
})(Platform || {});
|
8
|
+
var PlatformSchema = z.nativeEnum(Platform).describe("Social media platform");
|
9
|
+
var SUPPORTED_PLATFORMS = [
|
10
|
+
"twitter" /* TWITTER */
|
11
|
+
// Add more platforms here as they're implemented
|
12
|
+
];
|
13
|
+
var SupportedPlatformSchema = SUPPORTED_PLATFORMS.length > 0 ? z.enum(SUPPORTED_PLATFORMS) : z.never();
|
14
|
+
SupportedPlatformSchema.describe("Currently supported social media platforms");
|
15
|
+
function isPlatformSupported(platform) {
|
16
|
+
return SUPPORTED_PLATFORMS.includes(platform);
|
17
|
+
}
|
16
18
|
|
17
19
|
// src/response.ts
|
18
20
|
import { z as z2 } from "zod";
|
@@ -639,15 +641,23 @@ var EndpointRateLimitResponseSchema = z5.object({
|
|
639
641
|
signerId: z5.string().describe("NEAR account ID")
|
640
642
|
}).describe("Endpoint rate limit response");
|
641
643
|
|
642
|
-
// src/
|
644
|
+
// src/activity.ts
|
643
645
|
import { z as z6 } from "zod";
|
644
|
-
var
|
646
|
+
var TimePeriod = /* @__PURE__ */ ((TimePeriod2) => {
|
647
|
+
TimePeriod2["ALL_TIME"] = "all";
|
648
|
+
TimePeriod2["YEARLY"] = "yearly";
|
649
|
+
TimePeriod2["MONTHLY"] = "monthly";
|
650
|
+
TimePeriod2["WEEKLY"] = "weekly";
|
651
|
+
TimePeriod2["DAILY"] = "daily";
|
652
|
+
return TimePeriod2;
|
653
|
+
})(TimePeriod || {});
|
654
|
+
var ActivityLeaderboardQuerySchema = z6.object({
|
645
655
|
timeframe: z6.enum(["day", "week", "month", "all"]).optional().describe(
|
646
656
|
"Timeframe for the leaderboard"
|
647
657
|
),
|
648
658
|
limit: z6.string().optional().transform((val) => val ? parseInt(val, 10) : void 0).pipe(z6.number().min(1).max(100).optional()).describe("Maximum number of results to return (1-100)"),
|
649
659
|
offset: z6.string().optional().transform((val) => val ? parseInt(val, 10) : void 0).pipe(z6.number().min(0).optional()).describe("Offset for pagination")
|
650
|
-
}).describe("
|
660
|
+
}).describe("Activity leaderboard query");
|
651
661
|
var AccountActivityEntrySchema = z6.object({
|
652
662
|
signerId: z6.string().describe("NEAR account ID"),
|
653
663
|
totalPosts: z6.number().describe("Total number of posts"),
|
@@ -659,7 +669,7 @@ var AccountActivityEntrySchema = z6.object({
|
|
659
669
|
rank: z6.number().describe("Rank on the leaderboard"),
|
660
670
|
lastActive: z6.string().datetime().describe("Timestamp of last activity")
|
661
671
|
}).describe("Account activity entry");
|
662
|
-
var
|
672
|
+
var ActivityLeaderboardResponseSchema = EnhancedResponseSchema(
|
663
673
|
z6.object({
|
664
674
|
timeframe: z6.enum(["day", "week", "month", "all"]).describe("Timeframe for the leaderboard"),
|
665
675
|
entries: z6.array(AccountActivityEntrySchema).describe("Leaderboard entries"),
|
@@ -668,7 +678,7 @@ var LeaderboardResponseSchema = EnhancedResponseSchema(
|
|
668
678
|
offset: z6.number().describe("Offset for pagination"),
|
669
679
|
generatedAt: z6.string().datetime().describe("Timestamp when the leaderboard was generated")
|
670
680
|
})
|
671
|
-
).describe("
|
681
|
+
).describe("Activity leaderboard response");
|
672
682
|
var AccountActivityParamsSchema = z6.object({
|
673
683
|
signerId: z6.string().describe("NEAR account ID")
|
674
684
|
}).describe("Account activity params");
|
@@ -771,6 +781,8 @@ export {
|
|
771
781
|
AccountPostsParamsSchema,
|
772
782
|
AccountPostsQuerySchema,
|
773
783
|
AccountPostsResponseSchema,
|
784
|
+
ActivityLeaderboardQuerySchema,
|
785
|
+
ActivityLeaderboardResponseSchema,
|
774
786
|
AllRateLimitsResponseSchema,
|
775
787
|
ApiError,
|
776
788
|
ApiErrorCode,
|
@@ -798,8 +810,6 @@ export {
|
|
798
810
|
EnhancedResponseSchema,
|
799
811
|
ErrorDetailSchema,
|
800
812
|
ErrorResponseSchema,
|
801
|
-
LeaderboardQuerySchema,
|
802
|
-
LeaderboardResponseSchema,
|
803
813
|
LikePostRequestSchema,
|
804
814
|
LikePostResponseSchema,
|
805
815
|
LikeResultSchema,
|
@@ -836,8 +846,11 @@ export {
|
|
836
846
|
ReplyToPostResponseSchema,
|
837
847
|
RepostRequestSchema,
|
838
848
|
RepostResponseSchema,
|
849
|
+
SUPPORTED_PLATFORMS,
|
839
850
|
SuccessDetailSchema,
|
851
|
+
SupportedPlatformSchema,
|
840
852
|
TargetSchema,
|
853
|
+
TimePeriod,
|
841
854
|
UnlikePostRequestSchema,
|
842
855
|
UnlikePostResponseSchema,
|
843
856
|
UsageRateLimitSchema,
|
@@ -848,5 +861,6 @@ export {
|
|
848
861
|
createErrorDetail,
|
849
862
|
createErrorResponse,
|
850
863
|
createMultiStatusResponse,
|
851
|
-
createSuccessDetail
|
864
|
+
createSuccessDetail,
|
865
|
+
isPlatformSupported
|
852
866
|
};
|
package/package.json
CHANGED
package/src/activity.ts
ADDED
@@ -0,0 +1,247 @@
|
|
1
|
+
/**
|
2
|
+
* Activity Schemas and Types
|
3
|
+
* Defines Zod schemas for activity-related requests and responses
|
4
|
+
* TypeScript types are derived from Zod schemas for type safety
|
5
|
+
*/
|
6
|
+
|
7
|
+
import { z } from 'zod';
|
8
|
+
import { EnhancedResponseSchema } from './response.ts';
|
9
|
+
import { PlatformSchema } from './common.ts';
|
10
|
+
|
11
|
+
/**
|
12
|
+
* Time periods for activity filtering
|
13
|
+
*/
|
14
|
+
export enum TimePeriod {
|
15
|
+
ALL_TIME = 'all',
|
16
|
+
YEARLY = 'yearly',
|
17
|
+
MONTHLY = 'monthly',
|
18
|
+
WEEKLY = 'weekly',
|
19
|
+
DAILY = 'daily',
|
20
|
+
}
|
21
|
+
|
22
|
+
/**
|
23
|
+
* Activity leaderboard query schema
|
24
|
+
*/
|
25
|
+
export const ActivityLeaderboardQuerySchema = z.object({
|
26
|
+
timeframe: z.enum(['day', 'week', 'month', 'all']).optional().describe(
|
27
|
+
'Timeframe for the leaderboard',
|
28
|
+
),
|
29
|
+
limit: z.string().optional()
|
30
|
+
.transform((val) => val ? parseInt(val, 10) : undefined)
|
31
|
+
.pipe(z.number().min(1).max(100).optional())
|
32
|
+
.describe('Maximum number of results to return (1-100)'),
|
33
|
+
offset: z.string().optional()
|
34
|
+
.transform((val) => val ? parseInt(val, 10) : undefined)
|
35
|
+
.pipe(z.number().min(0).optional())
|
36
|
+
.describe('Offset for pagination'),
|
37
|
+
}).describe('Activity leaderboard query');
|
38
|
+
|
39
|
+
/**
|
40
|
+
* Account activity entry schema
|
41
|
+
*/
|
42
|
+
export const AccountActivityEntrySchema = z.object({
|
43
|
+
signerId: z.string().describe('NEAR account ID'),
|
44
|
+
totalPosts: z.number().describe('Total number of posts'),
|
45
|
+
totalLikes: z.number().describe('Total number of likes'),
|
46
|
+
totalReposts: z.number().describe('Total number of reposts'),
|
47
|
+
totalReplies: z.number().describe('Total number of replies'),
|
48
|
+
totalQuotes: z.number().describe('Total number of quote posts'),
|
49
|
+
totalScore: z.number().describe('Total activity score'),
|
50
|
+
rank: z.number().describe('Rank on the leaderboard'),
|
51
|
+
lastActive: z.string().datetime().describe('Timestamp of last activity'),
|
52
|
+
}).describe('Account activity entry');
|
53
|
+
|
54
|
+
/**
|
55
|
+
* Activity leaderboard response schema
|
56
|
+
*/
|
57
|
+
export const ActivityLeaderboardResponseSchema = EnhancedResponseSchema(
|
58
|
+
z.object({
|
59
|
+
timeframe: z.enum(['day', 'week', 'month', 'all']).describe('Timeframe for the leaderboard'),
|
60
|
+
entries: z.array(AccountActivityEntrySchema).describe('Leaderboard entries'),
|
61
|
+
total: z.number().describe('Total number of entries in the leaderboard'),
|
62
|
+
limit: z.number().describe('Maximum number of results returned'),
|
63
|
+
offset: z.number().describe('Offset for pagination'),
|
64
|
+
generatedAt: z.string().datetime().describe('Timestamp when the leaderboard was generated'),
|
65
|
+
}),
|
66
|
+
).describe('Activity leaderboard response');
|
67
|
+
|
68
|
+
/**
|
69
|
+
* Account activity params schema
|
70
|
+
*/
|
71
|
+
export const AccountActivityParamsSchema = z.object({
|
72
|
+
signerId: z.string().describe('NEAR account ID'),
|
73
|
+
}).describe('Account activity params');
|
74
|
+
|
75
|
+
/**
|
76
|
+
* Account activity query schema
|
77
|
+
*/
|
78
|
+
export const AccountActivityQuerySchema = z.object({
|
79
|
+
timeframe: z.enum(['day', 'week', 'month', 'all']).optional().describe(
|
80
|
+
'Timeframe for the activity',
|
81
|
+
),
|
82
|
+
}).describe('Account activity query');
|
83
|
+
|
84
|
+
/**
|
85
|
+
* Platform activity schema
|
86
|
+
*/
|
87
|
+
export const PlatformActivitySchema = z.object({
|
88
|
+
platform: PlatformSchema,
|
89
|
+
posts: z.number().describe('Number of posts on this platform'),
|
90
|
+
likes: z.number().describe('Number of likes on this platform'),
|
91
|
+
reposts: z.number().describe('Number of reposts on this platform'),
|
92
|
+
replies: z.number().describe('Number of replies on this platform'),
|
93
|
+
quotes: z.number().describe('Number of quote posts on this platform'),
|
94
|
+
score: z.number().describe('Activity score on this platform'),
|
95
|
+
lastActive: z.string().datetime().describe('Timestamp of last activity on this platform'),
|
96
|
+
}).describe('Platform activity');
|
97
|
+
|
98
|
+
/**
|
99
|
+
* Account activity response schema
|
100
|
+
*/
|
101
|
+
export const AccountActivityResponseSchema = EnhancedResponseSchema(
|
102
|
+
z.object({
|
103
|
+
signerId: z.string().describe('NEAR account ID'),
|
104
|
+
timeframe: z.enum(['day', 'week', 'month', 'all']).describe('Timeframe for the activity'),
|
105
|
+
totalPosts: z.number().describe('Total number of posts across all platforms'),
|
106
|
+
totalLikes: z.number().describe('Total number of likes across all platforms'),
|
107
|
+
totalReposts: z.number().describe('Total number of reposts across all platforms'),
|
108
|
+
totalReplies: z.number().describe('Total number of replies across all platforms'),
|
109
|
+
totalQuotes: z.number().describe('Total number of quote posts across all platforms'),
|
110
|
+
totalScore: z.number().describe('Total activity score across all platforms'),
|
111
|
+
rank: z.number().describe('Rank on the leaderboard'),
|
112
|
+
lastActive: z.string().datetime().describe('Timestamp of last activity across all platforms'),
|
113
|
+
platforms: z.array(PlatformActivitySchema).describe('Activity breakdown by platform'),
|
114
|
+
}),
|
115
|
+
).describe('Account activity response');
|
116
|
+
|
117
|
+
/**
|
118
|
+
* Account posts params schema
|
119
|
+
*/
|
120
|
+
export const AccountPostsParamsSchema = z.object({
|
121
|
+
signerId: z.string().describe('NEAR account ID'),
|
122
|
+
}).describe('Account posts params');
|
123
|
+
|
124
|
+
/**
|
125
|
+
* Account posts query schema
|
126
|
+
*/
|
127
|
+
export const AccountPostsQuerySchema = z.object({
|
128
|
+
platform: z.string().optional().describe('Filter by platform (optional)'),
|
129
|
+
limit: z.string().optional()
|
130
|
+
.transform((val) => val ? parseInt(val, 10) : undefined)
|
131
|
+
.pipe(z.number().min(1).max(100).optional())
|
132
|
+
.describe('Maximum number of results to return (1-100)'),
|
133
|
+
offset: z.string().optional()
|
134
|
+
.transform((val) => val ? parseInt(val, 10) : undefined)
|
135
|
+
.pipe(z.number().min(0).optional())
|
136
|
+
.describe('Offset for pagination'),
|
137
|
+
type: z.enum(['post', 'repost', 'reply', 'quote', 'like', 'all']).optional().describe(
|
138
|
+
'Filter by post type (optional)',
|
139
|
+
),
|
140
|
+
}).describe('Account posts query');
|
141
|
+
|
142
|
+
/**
|
143
|
+
* Account post schema
|
144
|
+
*/
|
145
|
+
export const AccountPostSchema = z.object({
|
146
|
+
id: z.string().describe('Post ID'),
|
147
|
+
platform: PlatformSchema,
|
148
|
+
type: z.enum(['post', 'repost', 'reply', 'quote', 'like']).describe('Type of post'),
|
149
|
+
content: z.string().optional().describe('Post content (if available)'),
|
150
|
+
url: z.string().url().optional().describe('URL to the post on the platform (if available)'),
|
151
|
+
createdAt: z.string().datetime().describe('Timestamp when the post was created'),
|
152
|
+
metrics: z.object({
|
153
|
+
likes: z.number().optional().describe('Number of likes (if available)'),
|
154
|
+
reposts: z.number().optional().describe('Number of reposts (if available)'),
|
155
|
+
replies: z.number().optional().describe('Number of replies (if available)'),
|
156
|
+
quotes: z.number().optional().describe('Number of quotes (if available)'),
|
157
|
+
}).optional().describe('Post metrics (if available)'),
|
158
|
+
inReplyToId: z.string().optional().describe('ID of the post this is a reply to (if applicable)'),
|
159
|
+
quotedPostId: z.string().optional().describe('ID of the post this is quoting (if applicable)'),
|
160
|
+
}).describe('Account post');
|
161
|
+
|
162
|
+
/**
|
163
|
+
* Account posts response schema
|
164
|
+
*/
|
165
|
+
export const AccountPostsResponseSchema = EnhancedResponseSchema(
|
166
|
+
z.object({
|
167
|
+
signerId: z.string().describe('NEAR account ID'),
|
168
|
+
posts: z.array(AccountPostSchema).describe('List of posts'),
|
169
|
+
total: z.number().describe('Total number of posts matching the query'),
|
170
|
+
limit: z.number().describe('Maximum number of results returned'),
|
171
|
+
offset: z.number().describe('Offset for pagination'),
|
172
|
+
platform: z.string().optional().describe('Platform filter (if applied)'),
|
173
|
+
type: z.enum(['post', 'repost', 'reply', 'quote', 'like', 'all']).optional().describe(
|
174
|
+
'Post type filter (if applied)',
|
175
|
+
),
|
176
|
+
}),
|
177
|
+
).describe('Account posts response');
|
178
|
+
|
179
|
+
/**
|
180
|
+
* Interface for account activity data
|
181
|
+
*/
|
182
|
+
export interface AccountActivity {
|
183
|
+
signerId: string;
|
184
|
+
postCount: number;
|
185
|
+
firstPostTimestamp: number;
|
186
|
+
lastPostTimestamp: number;
|
187
|
+
}
|
188
|
+
|
189
|
+
/**
|
190
|
+
* Interface for platform-specific account activity data
|
191
|
+
*/
|
192
|
+
export interface PlatformAccountActivity extends AccountActivity {
|
193
|
+
platform: string;
|
194
|
+
}
|
195
|
+
|
196
|
+
/**
|
197
|
+
* Interface for post record data (storage optimized)
|
198
|
+
*/
|
199
|
+
export interface PostRecord {
|
200
|
+
id: string; // postId
|
201
|
+
p: string; // platform
|
202
|
+
t: number; // timestamp
|
203
|
+
u: string; // userId
|
204
|
+
}
|
205
|
+
|
206
|
+
/**
|
207
|
+
* Interface for post record data (API response)
|
208
|
+
*/
|
209
|
+
export interface PostRecordResponse {
|
210
|
+
postId: string;
|
211
|
+
platform: string;
|
212
|
+
timestamp: string;
|
213
|
+
userId: string;
|
214
|
+
}
|
215
|
+
|
216
|
+
/**
|
217
|
+
* Interface for leaderboard entry
|
218
|
+
*/
|
219
|
+
export interface LeaderboardEntry {
|
220
|
+
signerId: string;
|
221
|
+
postCount: number;
|
222
|
+
lastPostTimestamp: number;
|
223
|
+
}
|
224
|
+
|
225
|
+
/**
|
226
|
+
* Interface for platform-specific leaderboard entry
|
227
|
+
*/
|
228
|
+
export interface PlatformLeaderboardEntry extends LeaderboardEntry {
|
229
|
+
platform: string;
|
230
|
+
}
|
231
|
+
|
232
|
+
// Derive TypeScript types from Zod schemas
|
233
|
+
export type ActivityLeaderboardQuery = z.infer<typeof ActivityLeaderboardQuerySchema>;
|
234
|
+
export type AccountActivityEntry = z.infer<typeof AccountActivityEntrySchema>;
|
235
|
+
export type ActivityLeaderboardResponse = z.infer<typeof ActivityLeaderboardResponseSchema>;
|
236
|
+
export type AccountActivityParams = z.infer<typeof AccountActivityParamsSchema>;
|
237
|
+
export type AccountActivityQuery = z.infer<typeof AccountActivityQuerySchema>;
|
238
|
+
export type PlatformActivity = z.infer<typeof PlatformActivitySchema>;
|
239
|
+
export type AccountActivityResponse = z.infer<typeof AccountActivityResponseSchema>;
|
240
|
+
export type AccountPostsParams = z.infer<typeof AccountPostsParamsSchema>;
|
241
|
+
export type AccountPostsQuery = z.infer<typeof AccountPostsQuerySchema>;
|
242
|
+
export type AccountPost = z.infer<typeof AccountPostSchema>;
|
243
|
+
export type AccountPostsResponse = z.infer<typeof AccountPostsResponseSchema>;
|
244
|
+
|
245
|
+
// Legacy type aliases for backward compatibility
|
246
|
+
export type LeaderboardQuery = ActivityLeaderboardQuery;
|
247
|
+
export type LeaderboardResponse = ActivityLeaderboardResponse;
|
package/src/common.ts
CHANGED
@@ -6,22 +6,7 @@
|
|
6
6
|
import { z } from 'zod';
|
7
7
|
|
8
8
|
/**
|
9
|
-
* Platform
|
10
|
-
*/
|
11
|
-
export const PlatformSchema = z.enum([
|
12
|
-
'unknown',
|
13
|
-
'twitter',
|
14
|
-
// Add more platforms as they're implemented
|
15
|
-
// 'linkedin',
|
16
|
-
// 'facebook',
|
17
|
-
// 'instagram',
|
18
|
-
]).describe('Social media platform');
|
19
|
-
|
20
|
-
// Derive TypeScript types from Zod schemas
|
21
|
-
export type PlatformName = z.infer<typeof PlatformSchema>;
|
22
|
-
|
23
|
-
/**
|
24
|
-
* Enum for supported platforms (for backward compatibility)
|
9
|
+
* Platform enum - All platforms (including planned ones)
|
25
10
|
*/
|
26
11
|
export enum Platform {
|
27
12
|
UNKNOWN = 'unknown',
|
@@ -31,3 +16,34 @@ export enum Platform {
|
|
31
16
|
// FACEBOOK = 'facebook',
|
32
17
|
// INSTAGRAM = 'instagram',
|
33
18
|
}
|
19
|
+
|
20
|
+
export const PlatformSchema = z.nativeEnum(Platform)
|
21
|
+
.describe('Social media platform');
|
22
|
+
|
23
|
+
/**
|
24
|
+
* Platform type - Derived from the Platform enum
|
25
|
+
*/
|
26
|
+
export type PlatformName = Platform;
|
27
|
+
|
28
|
+
/**
|
29
|
+
* Array of currently supported platforms
|
30
|
+
*/
|
31
|
+
export const SUPPORTED_PLATFORMS = [
|
32
|
+
Platform.TWITTER,
|
33
|
+
// Add more platforms here as they're implemented
|
34
|
+
] as const;
|
35
|
+
|
36
|
+
export type SupportedPlatformName = typeof SUPPORTED_PLATFORMS[number];
|
37
|
+
|
38
|
+
export const SupportedPlatformSchema = SUPPORTED_PLATFORMS.length > 0
|
39
|
+
? z.enum(SUPPORTED_PLATFORMS)
|
40
|
+
: z.never();
|
41
|
+
|
42
|
+
SupportedPlatformSchema.describe('Currently supported social media platforms');
|
43
|
+
|
44
|
+
/**
|
45
|
+
* Check if a platform is currently supported
|
46
|
+
*/
|
47
|
+
export function isPlatformSupported(platform: Platform): platform is SupportedPlatformName {
|
48
|
+
return (SUPPORTED_PLATFORMS as readonly Platform[]).includes(platform);
|
49
|
+
}
|
package/src/index.ts
CHANGED