@stacknet/stacks 0.2.0 → 0.2.2
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 +136 -0
- package/dist/{billing-eQZIWeNW.d.cts → billing-cj0eSVrp.d.cts} +59 -1
- package/dist/{billing-eQZIWeNW.d.ts → billing-cj0eSVrp.d.ts} +59 -1
- package/dist/clients/index.cjs +4 -4
- package/dist/clients/index.d.cts +24 -1
- package/dist/clients/index.d.ts +24 -1
- package/dist/clients/index.js +4 -4
- package/dist/index.cjs +7 -7
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +7 -7
- package/dist/proxy/index.cjs +2 -2
- package/dist/proxy/index.js +2 -2
- package/dist/streaming/index.cjs +5 -5
- package/dist/streaming/index.js +5 -5
- package/dist/types/index.d.cts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/package.json +15 -13
- package/src/clients/agents.ts +0 -250
- package/src/clients/billing.ts +0 -197
- package/src/clients/coder.ts +0 -655
- package/src/clients/files.ts +0 -86
- package/src/clients/index.ts +0 -93
- package/src/clients/magma.ts +0 -299
- package/src/clients/mcp.ts +0 -208
- package/src/clients/network.ts +0 -118
- package/src/clients/points.ts +0 -403
- package/src/clients/skills.ts +0 -236
- package/src/clients/social.ts +0 -286
- package/src/clients/stack-management.ts +0 -279
- package/src/clients/task-network.ts +0 -303
- package/src/clients/user.ts +0 -84
- package/src/clients/widgets.ts +0 -171
- package/src/index.ts +0 -387
- package/src/managers/index.ts +0 -10
- package/src/managers/task-manager.ts +0 -332
- package/src/proxy/forwarder.ts +0 -235
- package/src/proxy/index.ts +0 -32
- package/src/proxy/route-handlers.ts +0 -1107
- package/src/streaming/component-stream.ts +0 -319
- package/src/streaming/index.ts +0 -21
- package/src/streaming/sse.ts +0 -266
- package/src/types/agent.ts +0 -108
- package/src/types/billing.ts +0 -121
- package/src/types/chat.ts +0 -58
- package/src/types/coder.ts +0 -345
- package/src/types/credential.ts +0 -111
- package/src/types/file.ts +0 -15
- package/src/types/imagination.ts +0 -50
- package/src/types/index.ts +0 -20
- package/src/types/mcp.ts +0 -35
- package/src/types/network.ts +0 -97
- package/src/types/points.ts +0 -250
- package/src/types/skill.ts +0 -107
- package/src/types/social.ts +0 -109
- package/src/types/stack.ts +0 -269
- package/src/types/task.ts +0 -41
- package/src/types/user.ts +0 -29
- package/src/types/widget.ts +0 -57
- package/src/utils/constants.ts +0 -26
- package/src/utils/errors.ts +0 -169
- package/src/utils/helpers.ts +0 -85
- package/src/utils/index.ts +0 -7
package/src/clients/skills.ts
DELETED
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Skills Client
|
|
3
|
-
*
|
|
4
|
-
* Client for interacting with the Skills API via the Agent Coprocessor
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { DEFAULT_MAGMA_RPC_URL } from '../utils/constants';
|
|
8
|
-
import type {
|
|
9
|
-
Skill,
|
|
10
|
-
SkillsListResponse,
|
|
11
|
-
SkillResponse,
|
|
12
|
-
SkillCreateInput,
|
|
13
|
-
SkillUpdateInput,
|
|
14
|
-
SkillsClientConfig,
|
|
15
|
-
SkillVerifyResponse,
|
|
16
|
-
SkillMapResponse,
|
|
17
|
-
SkillMapPromptResponse,
|
|
18
|
-
SkillSummaryResponse,
|
|
19
|
-
} from '../types/skill';
|
|
20
|
-
|
|
21
|
-
export type { SkillsClientConfig };
|
|
22
|
-
|
|
23
|
-
export class SkillsClient {
|
|
24
|
-
private baseUrl: string;
|
|
25
|
-
private useCpxApi: boolean;
|
|
26
|
-
|
|
27
|
-
constructor(config: SkillsClientConfig = {}) {
|
|
28
|
-
this.baseUrl = config.baseUrl || DEFAULT_MAGMA_RPC_URL;
|
|
29
|
-
// Use coprocessor API by default (can be disabled for backwards compatibility)
|
|
30
|
-
this.useCpxApi = config.useCpxApi !== false;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
private get skillsUrl(): string {
|
|
34
|
-
// Route through Agent Coprocessor at /cpx/agent/skills
|
|
35
|
-
return this.useCpxApi
|
|
36
|
-
? `${this.baseUrl}/cpx/agent/skills`
|
|
37
|
-
: `${this.baseUrl}/skills`;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* List skills
|
|
42
|
-
*/
|
|
43
|
-
async list(options?: {
|
|
44
|
-
scope?: 'public' | 'private' | 'all';
|
|
45
|
-
creatorMid?: string;
|
|
46
|
-
contentType?: 'code' | 'text' | 'image' | 'video' | 'music' | string;
|
|
47
|
-
precompiled?: boolean;
|
|
48
|
-
}): Promise<SkillsListResponse> {
|
|
49
|
-
const params = new URLSearchParams();
|
|
50
|
-
|
|
51
|
-
// Precompiled filter takes priority
|
|
52
|
-
if (options?.precompiled) {
|
|
53
|
-
params.set('precompiled', 'true');
|
|
54
|
-
if (options?.contentType) {
|
|
55
|
-
params.set('content_type', options.contentType);
|
|
56
|
-
}
|
|
57
|
-
} else if (options?.contentType) {
|
|
58
|
-
params.set('content_type', options.contentType);
|
|
59
|
-
} else if (options?.creatorMid) {
|
|
60
|
-
params.set('creator_mid', options.creatorMid);
|
|
61
|
-
} else if (options?.scope && options.scope !== 'all') {
|
|
62
|
-
params.set('scope', options.scope);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const url = params.toString()
|
|
66
|
-
? `${this.skillsUrl}?${params.toString()}`
|
|
67
|
-
: this.skillsUrl;
|
|
68
|
-
|
|
69
|
-
const response = await fetch(url);
|
|
70
|
-
if (!response.ok) {
|
|
71
|
-
throw new Error(`Failed to list skills: ${response.statusText}`);
|
|
72
|
-
}
|
|
73
|
-
return response.json();
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Get a skill by ID
|
|
78
|
-
*/
|
|
79
|
-
async get(id: string): Promise<Skill> {
|
|
80
|
-
const response = await fetch(`${this.skillsUrl}/${id}`);
|
|
81
|
-
if (!response.ok) {
|
|
82
|
-
throw new Error(`Skill not found: ${id}`);
|
|
83
|
-
}
|
|
84
|
-
return response.json();
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Create a new skill
|
|
89
|
-
*/
|
|
90
|
-
async create(skill: SkillCreateInput): Promise<SkillResponse> {
|
|
91
|
-
const response = await fetch(this.skillsUrl, {
|
|
92
|
-
method: 'POST',
|
|
93
|
-
headers: { 'Content-Type': 'application/json' },
|
|
94
|
-
body: JSON.stringify(skill),
|
|
95
|
-
});
|
|
96
|
-
if (!response.ok) {
|
|
97
|
-
const error = await response.json().catch(() => ({}));
|
|
98
|
-
throw new Error(error.error || `Failed to create skill: ${response.statusText}`);
|
|
99
|
-
}
|
|
100
|
-
return response.json();
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Update a skill
|
|
105
|
-
*/
|
|
106
|
-
async update(id: string, updates: SkillUpdateInput): Promise<SkillResponse> {
|
|
107
|
-
const response = await fetch(`${this.skillsUrl}/${id}`, {
|
|
108
|
-
method: 'PUT',
|
|
109
|
-
headers: { 'Content-Type': 'application/json' },
|
|
110
|
-
body: JSON.stringify(updates),
|
|
111
|
-
});
|
|
112
|
-
if (!response.ok) {
|
|
113
|
-
const error = await response.json().catch(() => ({}));
|
|
114
|
-
throw new Error(error.error || `Failed to update skill: ${response.statusText}`);
|
|
115
|
-
}
|
|
116
|
-
return response.json();
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Delete a skill
|
|
121
|
-
*/
|
|
122
|
-
async delete(id: string): Promise<SkillResponse> {
|
|
123
|
-
const response = await fetch(`${this.skillsUrl}/${id}`, {
|
|
124
|
-
method: 'DELETE',
|
|
125
|
-
});
|
|
126
|
-
if (!response.ok) {
|
|
127
|
-
const error = await response.json().catch(() => ({}));
|
|
128
|
-
throw new Error(error.error || `Failed to delete skill: ${response.statusText}`);
|
|
129
|
-
}
|
|
130
|
-
return response.json();
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Track skill usage
|
|
135
|
-
*/
|
|
136
|
-
async trackUsage(id: string): Promise<void> {
|
|
137
|
-
try {
|
|
138
|
-
await fetch(`${this.skillsUrl}/${id}/usage`, {
|
|
139
|
-
method: 'POST',
|
|
140
|
-
});
|
|
141
|
-
} catch {
|
|
142
|
-
// Silently ignore usage tracking errors
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Verify skill hash integrity
|
|
148
|
-
*/
|
|
149
|
-
async verify(id: string): Promise<SkillVerifyResponse> {
|
|
150
|
-
const response = await fetch(`${this.skillsUrl}/${id}/verify`);
|
|
151
|
-
if (!response.ok) {
|
|
152
|
-
throw new Error(`Failed to verify skill: ${response.statusText}`);
|
|
153
|
-
}
|
|
154
|
-
return response.json();
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Rehash a skill (recompute its hash)
|
|
159
|
-
*/
|
|
160
|
-
async rehash(id: string): Promise<{ skillId: string; hash: string | null }> {
|
|
161
|
-
const response = await fetch(`${this.skillsUrl}/${id}/rehash`, {
|
|
162
|
-
method: 'POST',
|
|
163
|
-
});
|
|
164
|
-
if (!response.ok) {
|
|
165
|
-
throw new Error(`Failed to rehash skill: ${response.statusText}`);
|
|
166
|
-
}
|
|
167
|
-
return response.json();
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Rehash all skills
|
|
172
|
-
*/
|
|
173
|
-
async rehashAll(): Promise<{ updated: number; total: number }> {
|
|
174
|
-
const response = await fetch(`${this.skillsUrl}/rehash-all`, {
|
|
175
|
-
method: 'POST',
|
|
176
|
-
});
|
|
177
|
-
if (!response.ok) {
|
|
178
|
-
throw new Error(`Failed to rehash all skills: ${response.statusText}`);
|
|
179
|
-
}
|
|
180
|
-
return response.json();
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Get skill map (JSON format)
|
|
185
|
-
*/
|
|
186
|
-
async getMap(contentType?: string): Promise<SkillMapResponse> {
|
|
187
|
-
const params = contentType ? `?content_type=${contentType}` : '';
|
|
188
|
-
const response = await fetch(`${this.skillsUrl}/map${params}`);
|
|
189
|
-
if (!response.ok) {
|
|
190
|
-
throw new Error(`Failed to get skill map: ${response.statusText}`);
|
|
191
|
-
}
|
|
192
|
-
return response.json();
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Get skill map as system prompt
|
|
197
|
-
*/
|
|
198
|
-
async getMapPrompt(contentType?: string): Promise<SkillMapPromptResponse> {
|
|
199
|
-
const params = contentType ? `?content_type=${contentType}` : '';
|
|
200
|
-
const response = await fetch(`${this.skillsUrl}/map/prompt${params}`);
|
|
201
|
-
if (!response.ok) {
|
|
202
|
-
throw new Error(`Failed to get skill map prompt: ${response.statusText}`);
|
|
203
|
-
}
|
|
204
|
-
return response.json();
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* Get non-code skill map prompt
|
|
209
|
-
*/
|
|
210
|
-
async getNonCodeMap(): Promise<SkillMapPromptResponse> {
|
|
211
|
-
const response = await fetch(`${this.skillsUrl}/map/noncode`);
|
|
212
|
-
if (!response.ok) {
|
|
213
|
-
throw new Error(`Failed to get non-code skill map: ${response.statusText}`);
|
|
214
|
-
}
|
|
215
|
-
return response.json();
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* Get non-code skill summary
|
|
220
|
-
*/
|
|
221
|
-
async getNonCodeSummary(): Promise<SkillSummaryResponse> {
|
|
222
|
-
const response = await fetch(`${this.skillsUrl}/summary/noncode`);
|
|
223
|
-
if (!response.ok) {
|
|
224
|
-
throw new Error(`Failed to get non-code skill summary: ${response.statusText}`);
|
|
225
|
-
}
|
|
226
|
-
return response.json();
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
// Factory function
|
|
231
|
-
export function createSkillsClient(config?: SkillsClientConfig): SkillsClient {
|
|
232
|
-
return new SkillsClient(config);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
// Default instance
|
|
236
|
-
export const skillsClient = createSkillsClient();
|
package/src/clients/social.ts
DELETED
|
@@ -1,286 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Social Network Client
|
|
3
|
-
* Client for interacting with the P2P social network API
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { DEFAULT_TASK_NETWORK_URL, JSON_HEADERS } from '../utils/constants';
|
|
7
|
-
import { StacksSDKError } from '../utils/errors';
|
|
8
|
-
import type {
|
|
9
|
-
SocialClientConfig,
|
|
10
|
-
FeedResponse,
|
|
11
|
-
PostResponse,
|
|
12
|
-
CommentsResponse,
|
|
13
|
-
RemixesResponse,
|
|
14
|
-
LikeCheckResponse,
|
|
15
|
-
LikeResponse,
|
|
16
|
-
CommentResponse,
|
|
17
|
-
CreatePostInput,
|
|
18
|
-
CreatePostResponse,
|
|
19
|
-
ProfileResponse,
|
|
20
|
-
MediaType,
|
|
21
|
-
} from '../types/social';
|
|
22
|
-
|
|
23
|
-
export type { SocialClientConfig } from '../types/social';
|
|
24
|
-
|
|
25
|
-
export class SocialClient {
|
|
26
|
-
private baseUrl: string;
|
|
27
|
-
|
|
28
|
-
constructor(config: SocialClientConfig = {}) {
|
|
29
|
-
this.baseUrl = config.baseUrl || DEFAULT_TASK_NETWORK_URL;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
private get socialUrl(): string {
|
|
33
|
-
return `${this.baseUrl}/social`;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Fetch feed with pagination
|
|
38
|
-
*/
|
|
39
|
-
async getFeed(options: {
|
|
40
|
-
page?: number;
|
|
41
|
-
limit?: number;
|
|
42
|
-
mediaType?: MediaType;
|
|
43
|
-
} = {}): Promise<FeedResponse> {
|
|
44
|
-
const { page = 1, limit = 10, mediaType } = options;
|
|
45
|
-
|
|
46
|
-
const params = new URLSearchParams({
|
|
47
|
-
page: String(page),
|
|
48
|
-
limit: String(limit),
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
if (mediaType) {
|
|
52
|
-
params.set('media_type', mediaType);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const response = await fetch(`${this.socialUrl}/feed?${params}`);
|
|
56
|
-
|
|
57
|
-
if (!response.ok) {
|
|
58
|
-
throw new StacksSDKError(
|
|
59
|
-
'bad_request:api',
|
|
60
|
-
`Failed to fetch feed: ${response.statusText}`
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return response.json();
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Fetch a single post by ID
|
|
69
|
-
*/
|
|
70
|
-
async getPost(postId: string): Promise<PostResponse> {
|
|
71
|
-
const response = await fetch(`${this.socialUrl}/posts/${postId}`);
|
|
72
|
-
|
|
73
|
-
if (!response.ok) {
|
|
74
|
-
throw new StacksSDKError(
|
|
75
|
-
response.status === 404 ? 'not_found:api' : 'bad_request:api',
|
|
76
|
-
`Failed to fetch post: ${response.statusText}`
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return response.json();
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Fetch comments for a post
|
|
85
|
-
*/
|
|
86
|
-
async getComments(postId: string): Promise<CommentsResponse> {
|
|
87
|
-
const response = await fetch(`${this.socialUrl}/posts/${postId}/comments`);
|
|
88
|
-
|
|
89
|
-
if (!response.ok) {
|
|
90
|
-
throw new StacksSDKError(
|
|
91
|
-
'bad_request:api',
|
|
92
|
-
`Failed to fetch comments: ${response.statusText}`
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return response.json();
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Fetch remixes for a post
|
|
101
|
-
*/
|
|
102
|
-
async getRemixes(postId: string): Promise<RemixesResponse> {
|
|
103
|
-
const response = await fetch(`${this.socialUrl}/posts/${postId}/remixes`);
|
|
104
|
-
|
|
105
|
-
if (!response.ok) {
|
|
106
|
-
throw new StacksSDKError(
|
|
107
|
-
'bad_request:api',
|
|
108
|
-
`Failed to fetch remixes: ${response.statusText}`
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return response.json();
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Check if a user has liked a post
|
|
117
|
-
*/
|
|
118
|
-
async checkLike(postId: string, userMid: string): Promise<LikeCheckResponse> {
|
|
119
|
-
const response = await fetch(
|
|
120
|
-
`${this.socialUrl}/posts/${postId}/likes/check?userMid=${encodeURIComponent(userMid)}`
|
|
121
|
-
);
|
|
122
|
-
|
|
123
|
-
if (!response.ok) {
|
|
124
|
-
throw new StacksSDKError(
|
|
125
|
-
'bad_request:api',
|
|
126
|
-
`Failed to check like status: ${response.statusText}`
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
return response.json();
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Like a post
|
|
135
|
-
*/
|
|
136
|
-
async likePost(postId: string, userMid: string): Promise<LikeResponse> {
|
|
137
|
-
const response = await fetch(`${this.socialUrl}/like`, {
|
|
138
|
-
method: 'POST',
|
|
139
|
-
headers: JSON_HEADERS,
|
|
140
|
-
body: JSON.stringify({ postId, userMid }),
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
if (!response.ok) {
|
|
144
|
-
throw new StacksSDKError(
|
|
145
|
-
'bad_request:api',
|
|
146
|
-
`Failed to like post: ${response.statusText}`
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return response.json();
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Unlike a post
|
|
155
|
-
*/
|
|
156
|
-
async unlikePost(postId: string, userMid: string): Promise<LikeResponse> {
|
|
157
|
-
const response = await fetch(`${this.socialUrl}/unlike`, {
|
|
158
|
-
method: 'POST',
|
|
159
|
-
headers: JSON_HEADERS,
|
|
160
|
-
body: JSON.stringify({ postId, userMid }),
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
if (!response.ok) {
|
|
164
|
-
throw new StacksSDKError(
|
|
165
|
-
'bad_request:api',
|
|
166
|
-
`Failed to unlike post: ${response.statusText}`
|
|
167
|
-
);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
return response.json();
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Add a comment to a post
|
|
175
|
-
*/
|
|
176
|
-
async addComment(
|
|
177
|
-
postId: string,
|
|
178
|
-
userMid: string,
|
|
179
|
-
content: string
|
|
180
|
-
): Promise<CommentResponse> {
|
|
181
|
-
const response = await fetch(`${this.socialUrl}/comment`, {
|
|
182
|
-
method: 'POST',
|
|
183
|
-
headers: JSON_HEADERS,
|
|
184
|
-
body: JSON.stringify({ postId, userMid, content }),
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
if (!response.ok) {
|
|
188
|
-
throw new StacksSDKError(
|
|
189
|
-
'bad_request:api',
|
|
190
|
-
`Failed to add comment: ${response.statusText}`
|
|
191
|
-
);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
return response.json();
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Create a new post
|
|
199
|
-
*/
|
|
200
|
-
async createPost(input: CreatePostInput): Promise<CreatePostResponse> {
|
|
201
|
-
const response = await fetch(`${this.socialUrl}/post`, {
|
|
202
|
-
method: 'POST',
|
|
203
|
-
headers: JSON_HEADERS,
|
|
204
|
-
body: JSON.stringify({
|
|
205
|
-
userMid: input.creatorMid,
|
|
206
|
-
content: input.content,
|
|
207
|
-
mediaUrl: input.mediaUrl,
|
|
208
|
-
mediaType: input.mediaType,
|
|
209
|
-
orientation: input.orientation,
|
|
210
|
-
posterUrl: input.posterUrl,
|
|
211
|
-
remixOf: input.remixOf,
|
|
212
|
-
}),
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
if (!response.ok) {
|
|
216
|
-
throw new StacksSDKError(
|
|
217
|
-
'bad_request:api',
|
|
218
|
-
`Failed to create post: ${response.statusText}`
|
|
219
|
-
);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
return response.json();
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Track a view on a post
|
|
227
|
-
*/
|
|
228
|
-
async trackView(postId: string, userMid?: string): Promise<void> {
|
|
229
|
-
await fetch(`${this.socialUrl}/posts/${postId}/view`, {
|
|
230
|
-
method: 'POST',
|
|
231
|
-
headers: JSON_HEADERS,
|
|
232
|
-
body: JSON.stringify({ userMid }),
|
|
233
|
-
}).catch(() => {
|
|
234
|
-
// Silently fail view tracking
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* Track a play on audio/video post
|
|
240
|
-
*/
|
|
241
|
-
async trackPlay(postId: string, userMid?: string): Promise<void> {
|
|
242
|
-
await fetch(`${this.socialUrl}/posts/${postId}/play`, {
|
|
243
|
-
method: 'POST',
|
|
244
|
-
headers: JSON_HEADERS,
|
|
245
|
-
body: JSON.stringify({ userMid }),
|
|
246
|
-
}).catch(() => {
|
|
247
|
-
// Silently fail play tracking
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* Get user profile by MID
|
|
253
|
-
*/
|
|
254
|
-
async getProfile(mid: string): Promise<ProfileResponse | null> {
|
|
255
|
-
try {
|
|
256
|
-
const response = await fetch(`${this.socialUrl}/profile/${mid}`);
|
|
257
|
-
|
|
258
|
-
if (!response.ok) {
|
|
259
|
-
if (response.status === 404) {
|
|
260
|
-
return null;
|
|
261
|
-
}
|
|
262
|
-
throw new StacksSDKError(
|
|
263
|
-
'bad_request:api',
|
|
264
|
-
`Failed to fetch profile: ${response.statusText}`
|
|
265
|
-
);
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
return response.json();
|
|
269
|
-
} catch (error) {
|
|
270
|
-
if (error instanceof StacksSDKError) throw error;
|
|
271
|
-
return null;
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
* Create a SocialClient instance
|
|
278
|
-
*/
|
|
279
|
-
export function createSocialClient(config: SocialClientConfig = {}): SocialClient {
|
|
280
|
-
return new SocialClient(config);
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* Default social client instance
|
|
285
|
-
*/
|
|
286
|
-
export const socialClient = createSocialClient();
|