@crosspost/types 0.2.0 → 0.2.1
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 +65 -29
- package/dist/index.d.cts +172 -65
- package/dist/index.d.ts +172 -65
- package/dist/index.js +62 -29
- package/package.json +1 -1
- package/src/activity.ts +87 -28
- package/src/response.ts +1 -6
package/src/activity.ts
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
import { z } from 'zod';
|
2
|
-
import { PlatformSchema } from './common.ts';
|
2
|
+
import { Platform, PlatformSchema } from './common.ts';
|
3
|
+
|
4
|
+
export enum ActivityType {
|
5
|
+
POST = 'post',
|
6
|
+
REPOST = 'repost',
|
7
|
+
REPLY = 'reply',
|
8
|
+
QUOTE = 'quote',
|
9
|
+
LIKE = 'like',
|
10
|
+
UNLIKE = 'unlike',
|
11
|
+
DELETE = 'delete',
|
12
|
+
}
|
3
13
|
|
4
14
|
export enum TimePeriod {
|
5
15
|
ALL = 'all',
|
@@ -9,10 +19,57 @@ export enum TimePeriod {
|
|
9
19
|
DAILY = 'day',
|
10
20
|
}
|
11
21
|
|
12
|
-
|
13
|
-
|
14
|
-
|
22
|
+
/**
|
23
|
+
* Schema for filtering by platform, activity type, and timeframe
|
24
|
+
* Handles comma-separated lists for platforms and types
|
25
|
+
*/
|
26
|
+
export const FilterSchema = z.object({
|
27
|
+
platforms: z.string().optional()
|
28
|
+
.transform((val) => {
|
29
|
+
if (!val) return undefined;
|
30
|
+
return val.split(',')
|
31
|
+
.map((p) => p.trim())
|
32
|
+
.map((p) => {
|
33
|
+
try {
|
34
|
+
return Platform[p.toUpperCase() as keyof typeof Platform];
|
35
|
+
} catch (_e) {
|
36
|
+
return p;
|
37
|
+
}
|
38
|
+
});
|
39
|
+
})
|
40
|
+
.pipe(
|
41
|
+
z.array(z.nativeEnum(Platform)).optional(),
|
42
|
+
)
|
43
|
+
.describe('Filter by platforms (comma-separated list, optional)'),
|
44
|
+
types: z.string().optional()
|
45
|
+
.transform((val) => {
|
46
|
+
if (!val) return undefined;
|
47
|
+
return val.split(',')
|
48
|
+
.map((t) => t.trim())
|
49
|
+
.map((t) => {
|
50
|
+
try {
|
51
|
+
return ActivityType[t.toUpperCase() as keyof typeof ActivityType];
|
52
|
+
} catch (_e) {
|
53
|
+
return t;
|
54
|
+
}
|
55
|
+
});
|
56
|
+
})
|
57
|
+
.pipe(
|
58
|
+
z.array(z.nativeEnum(ActivityType)).optional(),
|
59
|
+
)
|
60
|
+
.describe('Filter by activity types (comma-separated list, optional)'),
|
61
|
+
timeframe: z.nativeEnum(TimePeriod).optional().transform((val) => {
|
62
|
+
if (!val) return TimePeriod.ALL;
|
63
|
+
return val;
|
64
|
+
}).describe(
|
65
|
+
'Timeframe for filtering (optional)',
|
15
66
|
),
|
67
|
+
}).describe('Filter parameters');
|
68
|
+
|
69
|
+
/**
|
70
|
+
* Common pagination schema used across queries
|
71
|
+
*/
|
72
|
+
export const PaginationSchema = z.object({
|
16
73
|
limit: z.string().optional()
|
17
74
|
.transform((val) => val ? parseInt(val, 10) : undefined)
|
18
75
|
.pipe(z.number().min(1).max(100).optional())
|
@@ -21,7 +78,14 @@ export const ActivityLeaderboardQuerySchema = z.object({
|
|
21
78
|
.transform((val) => val ? parseInt(val, 10) : undefined)
|
22
79
|
.pipe(z.number().min(0).optional())
|
23
80
|
.describe('Offset for pagination'),
|
24
|
-
}).describe('
|
81
|
+
}).describe('Pagination parameters');
|
82
|
+
|
83
|
+
/**
|
84
|
+
* Query schema for leaderboard endpoints
|
85
|
+
*/
|
86
|
+
export const ActivityLeaderboardQuerySchema = z.object({
|
87
|
+
filter: FilterSchema.optional(),
|
88
|
+
}).describe('Account leaderboard query').merge(PaginationSchema);
|
25
89
|
|
26
90
|
export const AccountActivityEntrySchema = z.object({
|
27
91
|
signerId: z.string().describe('NEAR account ID'),
|
@@ -33,24 +97,26 @@ export const AccountActivityEntrySchema = z.object({
|
|
33
97
|
totalScore: z.number().describe('Total activity score'),
|
34
98
|
rank: z.number().describe('Rank on the leaderboard'),
|
35
99
|
lastActive: z.string().datetime().describe('Timestamp of last activity'),
|
100
|
+
firstPostTimestamp: z.string().datetime().describe('Timestamp of the first post'),
|
36
101
|
}).describe('Account activity entry');
|
37
102
|
|
38
103
|
const ActivityLeaderboardResponseSchema = z.object({
|
39
104
|
timeframe: z.nativeEnum(TimePeriod).describe('Timeframe for the leaderboard'),
|
40
105
|
entries: z.array(AccountActivityEntrySchema).describe('Leaderboard entries'),
|
41
106
|
generatedAt: z.string().datetime().describe('Timestamp when the leaderboard was generated'),
|
42
|
-
|
107
|
+
platforms: z.array(PlatformSchema).optional().describe('Platform filters (if applied)'),
|
43
108
|
});
|
44
109
|
|
45
110
|
export const AccountActivityParamsSchema = z.object({
|
46
111
|
signerId: z.string().describe('NEAR account ID'),
|
47
112
|
}).describe('Account activity params');
|
48
113
|
|
114
|
+
/**
|
115
|
+
* Query schema for account activity endpoints
|
116
|
+
*/
|
49
117
|
export const AccountActivityQuerySchema = z.object({
|
50
|
-
|
51
|
-
|
52
|
-
),
|
53
|
-
}).describe('Account activity query');
|
118
|
+
filter: FilterSchema.optional(),
|
119
|
+
}).describe('Account activity query').merge(PaginationSchema);
|
54
120
|
|
55
121
|
export const PlatformActivitySchema = z.object({
|
56
122
|
platform: PlatformSchema,
|
@@ -81,25 +147,18 @@ export const AccountPostsParamsSchema = z.object({
|
|
81
147
|
signerId: z.string().describe('NEAR account ID'),
|
82
148
|
}).describe('Account posts params');
|
83
149
|
|
150
|
+
/**
|
151
|
+
* Query schema for account posts endpoints
|
152
|
+
*/
|
84
153
|
export const AccountPostsQuerySchema = z.object({
|
85
|
-
|
86
|
-
|
87
|
-
.transform((val) => val ? parseInt(val, 10) : undefined)
|
88
|
-
.pipe(z.number().min(1).max(100).optional())
|
89
|
-
.describe('Maximum number of results to return (1-100)'),
|
90
|
-
offset: z.string().optional()
|
91
|
-
.transform((val) => val ? parseInt(val, 10) : undefined)
|
92
|
-
.pipe(z.number().min(0).optional())
|
93
|
-
.describe('Offset for pagination'),
|
94
|
-
type: z.enum(['post', 'repost', 'reply', 'quote', 'like', 'all']).optional().describe(
|
95
|
-
'Filter by post type (optional)',
|
96
|
-
),
|
97
|
-
}).describe('Account posts query');
|
154
|
+
filter: FilterSchema.optional(),
|
155
|
+
}).describe('Account posts query').merge(PaginationSchema);
|
98
156
|
|
99
157
|
export const AccountPostSchema = z.object({
|
100
158
|
id: z.string().describe('Post ID'),
|
101
159
|
platform: PlatformSchema,
|
102
|
-
|
160
|
+
userId: z.string().describe('User ID on the platform'),
|
161
|
+
type: z.nativeEnum(ActivityType).describe('Type of post'),
|
103
162
|
content: z.string().optional().describe('Post content (if available)'),
|
104
163
|
url: z.string().url().optional().describe('URL to the post on the platform (if available)'),
|
105
164
|
createdAt: z.string().datetime().describe('Timestamp when the post was created'),
|
@@ -116,10 +175,8 @@ export const AccountPostSchema = z.object({
|
|
116
175
|
const AccountPostsResponseSchema = z.object({
|
117
176
|
signerId: z.string().describe('NEAR account ID'),
|
118
177
|
posts: z.array(AccountPostSchema).describe('List of posts'),
|
119
|
-
|
120
|
-
|
121
|
-
'Post type filter (if applied)',
|
122
|
-
),
|
178
|
+
platforms: z.array(z.string()).optional().describe('Platform filters (if applied)'),
|
179
|
+
types: z.array(z.string()).optional().describe('Post type filters (if applied)'),
|
123
180
|
});
|
124
181
|
|
125
182
|
/**
|
@@ -147,6 +204,7 @@ export interface PostRecord {
|
|
147
204
|
p: string; // platform
|
148
205
|
t: number; // timestamp
|
149
206
|
u: string; // userId
|
207
|
+
ty: string; // activity type ('post', 'like', 'repost', etc.)
|
150
208
|
}
|
151
209
|
|
152
210
|
export type ActivityLeaderboardQuery = z.infer<typeof ActivityLeaderboardQuerySchema>;
|
@@ -160,3 +218,4 @@ export type AccountPostsParams = z.infer<typeof AccountPostsParamsSchema>;
|
|
160
218
|
export type AccountPostsQuery = z.infer<typeof AccountPostsQuerySchema>;
|
161
219
|
export type AccountPost = z.infer<typeof AccountPostSchema>;
|
162
220
|
export type AccountPostsResponse = z.infer<typeof AccountPostsResponseSchema>;
|
221
|
+
export type Filter = z.infer<typeof FilterSchema>;
|
package/src/response.ts
CHANGED
@@ -10,14 +10,9 @@ export const ResponseMetaSchema = z.object({
|
|
10
10
|
reset: z.number().int().positive().describe('Unix timestamp (seconds)'),
|
11
11
|
}).optional().describe('Rate limit information if applicable'),
|
12
12
|
pagination: z.object({
|
13
|
-
page: z.number().int().positive().optional(),
|
14
|
-
perPage: z.number().int().positive().optional(),
|
15
|
-
total: z.number().int().nonnegative().optional(),
|
16
13
|
limit: z.number().int().nonnegative().optional(),
|
17
14
|
offset: z.number().int().nonnegative().optional(),
|
18
|
-
|
19
|
-
nextCursor: z.string().optional(),
|
20
|
-
prevCursor: z.string().optional(),
|
15
|
+
total: z.number().int().nonnegative().optional(),
|
21
16
|
}).optional().describe('Pagination information if applicable'),
|
22
17
|
});
|
23
18
|
|