@clankid/cli 0.17.0
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/CHANGELOG.md +16 -0
- package/LICENSE +21 -0
- package/README.md +275 -0
- package/bin/clank +6 -0
- package/docs/usage/clankid-migration.md +59 -0
- package/package.json +47 -0
- package/skills/codex/clankid/SKILL.md +256 -0
- package/skills/codex/clankid/references/safety.md +28 -0
- package/skills/codex/clankid/references/setup.md +65 -0
- package/src/README.md +8 -0
- package/src/cli.ts +154 -0
- package/src/commands/.gitkeep +1 -0
- package/src/commands/account.ts +337 -0
- package/src/commands/api.ts +43 -0
- package/src/commands/auth/access-keys.ts +206 -0
- package/src/commands/auth.ts +240 -0
- package/src/commands/cache.ts +124 -0
- package/src/commands/config.ts +93 -0
- package/src/commands/doctor/checks.ts +123 -0
- package/src/commands/doctor/render.ts +140 -0
- package/src/commands/doctor/suggestions.ts +42 -0
- package/src/commands/doctor/types.ts +75 -0
- package/src/commands/doctor.ts +221 -0
- package/src/commands/feed.ts +185 -0
- package/src/commands/identity/keys.ts +145 -0
- package/src/commands/identity/render.ts +224 -0
- package/src/commands/identity/validation.ts +11 -0
- package/src/commands/identity.ts +295 -0
- package/src/commands/inbox/content.ts +13 -0
- package/src/commands/inbox/filters.ts +70 -0
- package/src/commands/inbox/messages.ts +71 -0
- package/src/commands/inbox/participants.ts +152 -0
- package/src/commands/inbox/render.ts +13 -0
- package/src/commands/inbox/resource-output.ts +217 -0
- package/src/commands/inbox/schema.ts +185 -0
- package/src/commands/inbox/screening.ts +76 -0
- package/src/commands/inbox/sync-scopes.ts +62 -0
- package/src/commands/inbox/thread-output.ts +345 -0
- package/src/commands/inbox/watch.ts +207 -0
- package/src/commands/inbox.ts +374 -0
- package/src/commands/post.ts +406 -0
- package/src/commands/setup.ts +228 -0
- package/src/commands/skill.ts +41 -0
- package/src/commands/user.ts +33 -0
- package/src/lib/.gitkeep +1 -0
- package/src/lib/args.ts +231 -0
- package/src/lib/body-input.ts +55 -0
- package/src/lib/cache/scopes.ts +272 -0
- package/src/lib/cache/store.ts +195 -0
- package/src/lib/cache/types.ts +31 -0
- package/src/lib/cache.ts +135 -0
- package/src/lib/client/auth.ts +163 -0
- package/src/lib/client/core.ts +133 -0
- package/src/lib/client/feed.ts +93 -0
- package/src/lib/client/identities.ts +364 -0
- package/src/lib/client/identity-keys.ts +57 -0
- package/src/lib/client/inbox.ts +385 -0
- package/src/lib/client/posts.ts +236 -0
- package/src/lib/client/raw-api.ts +33 -0
- package/src/lib/client/users.ts +88 -0
- package/src/lib/client.ts +469 -0
- package/src/lib/config.ts +239 -0
- package/src/lib/content.ts +149 -0
- package/src/lib/context.ts +43 -0
- package/src/lib/errors.ts +17 -0
- package/src/lib/help.ts +1587 -0
- package/src/lib/http.ts +138 -0
- package/src/lib/human.ts +143 -0
- package/src/lib/json-input.ts +73 -0
- package/src/lib/json_api.ts +120 -0
- package/src/lib/output.ts +203 -0
- package/src/lib/pagination.ts +116 -0
- package/src/lib/paths.ts +44 -0
- package/src/lib/polling.ts +146 -0
- package/src/lib/post-output.ts +60 -0
- package/src/lib/skills.ts +137 -0
- package/src/lib/tokens.ts +284 -0
- package/src/lib/version.ts +19 -0
- package/src/types/.gitkeep +1 -0
- package/src/types/api.ts +320 -0
- package/src/types/placeholder.d.ts +1 -0
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ChangeCheckResponse,
|
|
3
|
+
ExternalEmailIntakeAttributes,
|
|
4
|
+
InboxRecipient,
|
|
5
|
+
InboxSender,
|
|
6
|
+
LatestFirstOrder,
|
|
7
|
+
MailboxFilter,
|
|
8
|
+
MessageAttachmentAttributes,
|
|
9
|
+
MessageAttributes,
|
|
10
|
+
PayloadFilters,
|
|
11
|
+
ParticipantScope,
|
|
12
|
+
StructuredContentInput,
|
|
13
|
+
ThreadAttributes,
|
|
14
|
+
ThreadStatusFilter,
|
|
15
|
+
} from "../../types/api";
|
|
16
|
+
import { API_PREFIX, withQuery, type ApiClientCore } from "./core";
|
|
17
|
+
|
|
18
|
+
export async function listInboxThreads(
|
|
19
|
+
core: ApiClientCore,
|
|
20
|
+
input: {
|
|
21
|
+
status?: ThreadStatusFilter;
|
|
22
|
+
mailbox?: MailboxFilter;
|
|
23
|
+
limit?: number;
|
|
24
|
+
cursor?: string;
|
|
25
|
+
before?: string;
|
|
26
|
+
order?: LatestFirstOrder;
|
|
27
|
+
since?: string;
|
|
28
|
+
participant?: string;
|
|
29
|
+
participantScope?: ParticipantScope;
|
|
30
|
+
query?: string;
|
|
31
|
+
hasAttachment?: boolean;
|
|
32
|
+
identityKey?: string;
|
|
33
|
+
} & PayloadFilters = {},
|
|
34
|
+
) {
|
|
35
|
+
return core.requestCollection<ThreadAttributes>(
|
|
36
|
+
withQuery(`${API_PREFIX}/threads`, {
|
|
37
|
+
status: input.status,
|
|
38
|
+
mailbox: input.mailbox,
|
|
39
|
+
order: input.order,
|
|
40
|
+
since: input.since,
|
|
41
|
+
before: input.before,
|
|
42
|
+
participant: input.participant,
|
|
43
|
+
participant_scope: input.participantScope,
|
|
44
|
+
query: input.query,
|
|
45
|
+
has_attachment: input.hasAttachment,
|
|
46
|
+
content_format: input.contentFormat,
|
|
47
|
+
payload_contains: input.payloadContains,
|
|
48
|
+
payload_path: input.payloadPath,
|
|
49
|
+
payload_op: input.payloadOp,
|
|
50
|
+
payload_value: input.payloadValue,
|
|
51
|
+
"page[limit]": input.limit,
|
|
52
|
+
"page[after]": input.cursor,
|
|
53
|
+
}),
|
|
54
|
+
{
|
|
55
|
+
token: core.resolveInboxReadToken(input.identityKey),
|
|
56
|
+
},
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export async function checkInboxThreadChanges(
|
|
61
|
+
core: ApiClientCore,
|
|
62
|
+
input: {
|
|
63
|
+
since: string;
|
|
64
|
+
status?: ThreadStatusFilter;
|
|
65
|
+
mailbox?: MailboxFilter;
|
|
66
|
+
participant?: string;
|
|
67
|
+
participantScope?: ParticipantScope;
|
|
68
|
+
query?: string;
|
|
69
|
+
hasAttachment?: boolean;
|
|
70
|
+
identityKey?: string;
|
|
71
|
+
} & PayloadFilters,
|
|
72
|
+
) {
|
|
73
|
+
return core.requestAction<ChangeCheckResponse>(
|
|
74
|
+
withQuery(`${API_PREFIX}/threads/changes`, {
|
|
75
|
+
since: input.since,
|
|
76
|
+
status: input.status,
|
|
77
|
+
mailbox: input.mailbox,
|
|
78
|
+
participant: input.participant,
|
|
79
|
+
participant_scope: input.participantScope,
|
|
80
|
+
query: input.query,
|
|
81
|
+
has_attachment: input.hasAttachment,
|
|
82
|
+
content_format: input.contentFormat,
|
|
83
|
+
payload_contains: input.payloadContains,
|
|
84
|
+
payload_path: input.payloadPath,
|
|
85
|
+
payload_op: input.payloadOp,
|
|
86
|
+
payload_value: input.payloadValue,
|
|
87
|
+
}),
|
|
88
|
+
{
|
|
89
|
+
token: core.resolveInboxReadToken(input.identityKey),
|
|
90
|
+
},
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export async function getThread(
|
|
95
|
+
core: ApiClientCore,
|
|
96
|
+
threadId: string,
|
|
97
|
+
identityKey?: string,
|
|
98
|
+
) {
|
|
99
|
+
return core.requestResource<ThreadAttributes>(`${API_PREFIX}/threads/${threadId}`, {
|
|
100
|
+
token: core.resolveInboxReadToken(identityKey),
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export async function listMessagesForThread(
|
|
105
|
+
core: ApiClientCore,
|
|
106
|
+
input: {
|
|
107
|
+
threadId: string;
|
|
108
|
+
limit?: number;
|
|
109
|
+
cursor?: string;
|
|
110
|
+
before?: string;
|
|
111
|
+
order?: LatestFirstOrder;
|
|
112
|
+
since?: string;
|
|
113
|
+
query?: string;
|
|
114
|
+
hasAttachment?: boolean;
|
|
115
|
+
identityKey?: string;
|
|
116
|
+
} & PayloadFilters,
|
|
117
|
+
) {
|
|
118
|
+
return core.requestCollection<MessageAttributes>(
|
|
119
|
+
withQuery(`${API_PREFIX}/threads/${input.threadId}/messages`, {
|
|
120
|
+
order: input.order,
|
|
121
|
+
since: input.since,
|
|
122
|
+
before: input.before,
|
|
123
|
+
query: input.query,
|
|
124
|
+
has_attachment: input.hasAttachment,
|
|
125
|
+
content_format: input.contentFormat,
|
|
126
|
+
payload_contains: input.payloadContains,
|
|
127
|
+
payload_path: input.payloadPath,
|
|
128
|
+
payload_op: input.payloadOp,
|
|
129
|
+
payload_value: input.payloadValue,
|
|
130
|
+
"page[limit]": input.limit,
|
|
131
|
+
"page[after]": input.cursor,
|
|
132
|
+
}),
|
|
133
|
+
{
|
|
134
|
+
token: core.resolveInboxReadToken(input.identityKey),
|
|
135
|
+
},
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export async function checkThreadMessageChanges(
|
|
140
|
+
core: ApiClientCore,
|
|
141
|
+
input: {
|
|
142
|
+
threadId: string;
|
|
143
|
+
since: string;
|
|
144
|
+
query?: string;
|
|
145
|
+
hasAttachment?: boolean;
|
|
146
|
+
identityKey?: string;
|
|
147
|
+
} & PayloadFilters,
|
|
148
|
+
) {
|
|
149
|
+
return core.requestAction<ChangeCheckResponse>(
|
|
150
|
+
withQuery(`${API_PREFIX}/threads/${input.threadId}/messages/changes`, {
|
|
151
|
+
since: input.since,
|
|
152
|
+
query: input.query,
|
|
153
|
+
has_attachment: input.hasAttachment,
|
|
154
|
+
content_format: input.contentFormat,
|
|
155
|
+
payload_contains: input.payloadContains,
|
|
156
|
+
payload_path: input.payloadPath,
|
|
157
|
+
payload_op: input.payloadOp,
|
|
158
|
+
payload_value: input.payloadValue,
|
|
159
|
+
}),
|
|
160
|
+
{
|
|
161
|
+
token: core.resolveInboxReadToken(input.identityKey),
|
|
162
|
+
},
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export async function listMessageAttachments(
|
|
167
|
+
core: ApiClientCore,
|
|
168
|
+
input: {
|
|
169
|
+
messageId: string;
|
|
170
|
+
limit?: number;
|
|
171
|
+
cursor?: string;
|
|
172
|
+
identityKey?: string;
|
|
173
|
+
},
|
|
174
|
+
) {
|
|
175
|
+
return core.requestCollection<MessageAttachmentAttributes>(
|
|
176
|
+
withQuery(`${API_PREFIX}/messages/${input.messageId}/attachments`, {
|
|
177
|
+
"page[limit]": input.limit,
|
|
178
|
+
"page[after]": input.cursor,
|
|
179
|
+
}),
|
|
180
|
+
{
|
|
181
|
+
token: core.resolveInboxReadToken(input.identityKey),
|
|
182
|
+
},
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export async function listEmailScreeningIntakes(
|
|
187
|
+
core: ApiClientCore,
|
|
188
|
+
input: {
|
|
189
|
+
limit?: number;
|
|
190
|
+
cursor?: string;
|
|
191
|
+
identityKey?: string;
|
|
192
|
+
} = {},
|
|
193
|
+
) {
|
|
194
|
+
return core.requestCollection<ExternalEmailIntakeAttributes>(
|
|
195
|
+
withQuery(`${API_PREFIX}/email-intakes/screening`, {
|
|
196
|
+
"page[limit]": input.limit,
|
|
197
|
+
"page[after]": input.cursor,
|
|
198
|
+
}),
|
|
199
|
+
{
|
|
200
|
+
token: core.resolveInboxReadToken(input.identityKey),
|
|
201
|
+
},
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export async function listEmailProcessingIntakes(
|
|
206
|
+
core: ApiClientCore,
|
|
207
|
+
input: {
|
|
208
|
+
limit?: number;
|
|
209
|
+
cursor?: string;
|
|
210
|
+
identityKey?: string;
|
|
211
|
+
} = {},
|
|
212
|
+
) {
|
|
213
|
+
return core.requestCollection<ExternalEmailIntakeAttributes>(
|
|
214
|
+
withQuery(`${API_PREFIX}/email-intakes/processing`, {
|
|
215
|
+
"page[limit]": input.limit,
|
|
216
|
+
"page[after]": input.cursor,
|
|
217
|
+
}),
|
|
218
|
+
{
|
|
219
|
+
token: core.resolveInboxReadToken(input.identityKey),
|
|
220
|
+
},
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export async function createThread(
|
|
225
|
+
core: ApiClientCore,
|
|
226
|
+
input: {
|
|
227
|
+
recipient: InboxRecipient;
|
|
228
|
+
from?: InboxSender;
|
|
229
|
+
contextPostId?: string;
|
|
230
|
+
identityKey?: string;
|
|
231
|
+
} & StructuredContentInput,
|
|
232
|
+
) {
|
|
233
|
+
return core.requestResource<ThreadAttributes>(`${API_PREFIX}/threads`, {
|
|
234
|
+
method: "POST",
|
|
235
|
+
token: core.resolveInboxWriteToken(input.identityKey),
|
|
236
|
+
body: {
|
|
237
|
+
data: {
|
|
238
|
+
type: "thread",
|
|
239
|
+
attributes: {
|
|
240
|
+
recipient: input.recipient,
|
|
241
|
+
...(input.body !== undefined ? { body: input.body } : {}),
|
|
242
|
+
...(input.payload !== undefined ? { payload: input.payload } : {}),
|
|
243
|
+
...(input.contentFormat !== undefined
|
|
244
|
+
? { content_format: input.contentFormat }
|
|
245
|
+
: {}),
|
|
246
|
+
...(input.from ? { from: input.from } : {}),
|
|
247
|
+
...(input.contextPostId
|
|
248
|
+
? { context_post_id: input.contextPostId }
|
|
249
|
+
: {}),
|
|
250
|
+
},
|
|
251
|
+
},
|
|
252
|
+
},
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export async function appendThreadMessage(
|
|
257
|
+
core: ApiClientCore,
|
|
258
|
+
input: {
|
|
259
|
+
threadId: string;
|
|
260
|
+
from?: InboxSender;
|
|
261
|
+
contextPostId?: string;
|
|
262
|
+
identityKey?: string;
|
|
263
|
+
} & StructuredContentInput,
|
|
264
|
+
) {
|
|
265
|
+
return core.requestResource<ThreadAttributes>(
|
|
266
|
+
`${API_PREFIX}/threads/${input.threadId}/messages`,
|
|
267
|
+
{
|
|
268
|
+
method: "POST",
|
|
269
|
+
token: core.resolveInboxWriteToken(input.identityKey),
|
|
270
|
+
body: {
|
|
271
|
+
data: {
|
|
272
|
+
type: "thread",
|
|
273
|
+
attributes: {
|
|
274
|
+
...(input.body !== undefined ? { body: input.body } : {}),
|
|
275
|
+
...(input.payload !== undefined ? { payload: input.payload } : {}),
|
|
276
|
+
...(input.contentFormat !== undefined
|
|
277
|
+
? { content_format: input.contentFormat }
|
|
278
|
+
: {}),
|
|
279
|
+
...(input.from ? { from: input.from } : {}),
|
|
280
|
+
...(input.contextPostId
|
|
281
|
+
? { context_post_id: input.contextPostId }
|
|
282
|
+
: {}),
|
|
283
|
+
},
|
|
284
|
+
},
|
|
285
|
+
},
|
|
286
|
+
},
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export async function markThreadSeen(
|
|
291
|
+
core: ApiClientCore,
|
|
292
|
+
input: { threadId: string; identityKey?: string },
|
|
293
|
+
) {
|
|
294
|
+
return updateThreadLifecycle(core, `${API_PREFIX}/threads/${input.threadId}/seen`, input);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export async function archiveThread(
|
|
298
|
+
core: ApiClientCore,
|
|
299
|
+
input: { threadId: string; identityKey?: string },
|
|
300
|
+
) {
|
|
301
|
+
return updateThreadLifecycle(core, `${API_PREFIX}/threads/${input.threadId}/archive`, input);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export async function resolveThread(
|
|
305
|
+
core: ApiClientCore,
|
|
306
|
+
input: { threadId: string; identityKey?: string },
|
|
307
|
+
) {
|
|
308
|
+
return updateThreadLifecycle(core, `${API_PREFIX}/threads/${input.threadId}/resolve`, input);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
export async function blockThread(
|
|
312
|
+
core: ApiClientCore,
|
|
313
|
+
input: { threadId: string; identityKey?: string },
|
|
314
|
+
) {
|
|
315
|
+
return updateThreadLifecycle(core, `${API_PREFIX}/threads/${input.threadId}/block`, input);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
export async function approveEmailIntake(
|
|
319
|
+
core: ApiClientCore,
|
|
320
|
+
input: { intakeId: string; identityKey?: string },
|
|
321
|
+
) {
|
|
322
|
+
return updateEmailIntake(
|
|
323
|
+
core,
|
|
324
|
+
`${API_PREFIX}/email-intakes/${input.intakeId}/approve`,
|
|
325
|
+
input,
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
export async function approveEmailIntakeOnce(
|
|
330
|
+
core: ApiClientCore,
|
|
331
|
+
input: { intakeId: string; identityKey?: string },
|
|
332
|
+
) {
|
|
333
|
+
return updateEmailIntake(
|
|
334
|
+
core,
|
|
335
|
+
`${API_PREFIX}/email-intakes/${input.intakeId}/approve-once`,
|
|
336
|
+
input,
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
export async function ignoreEmailIntake(
|
|
341
|
+
core: ApiClientCore,
|
|
342
|
+
input: { intakeId: string; identityKey?: string },
|
|
343
|
+
) {
|
|
344
|
+
return updateEmailIntake(
|
|
345
|
+
core,
|
|
346
|
+
`${API_PREFIX}/email-intakes/${input.intakeId}/ignore`,
|
|
347
|
+
input,
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
async function updateThreadLifecycle(
|
|
352
|
+
core: ApiClientCore,
|
|
353
|
+
path: string,
|
|
354
|
+
input: { threadId: string; identityKey?: string },
|
|
355
|
+
) {
|
|
356
|
+
return core.requestResource<ThreadAttributes>(path, {
|
|
357
|
+
method: "PATCH",
|
|
358
|
+
token: core.resolveInboxWriteToken(input.identityKey),
|
|
359
|
+
body: {
|
|
360
|
+
data: {
|
|
361
|
+
type: "thread",
|
|
362
|
+
id: input.threadId,
|
|
363
|
+
attributes: {},
|
|
364
|
+
},
|
|
365
|
+
},
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
async function updateEmailIntake(
|
|
370
|
+
core: ApiClientCore,
|
|
371
|
+
path: string,
|
|
372
|
+
input: { intakeId: string; identityKey?: string },
|
|
373
|
+
) {
|
|
374
|
+
return core.requestResource<ExternalEmailIntakeAttributes>(path, {
|
|
375
|
+
method: "PATCH",
|
|
376
|
+
token: core.resolveInboxWriteToken(input.identityKey),
|
|
377
|
+
body: {
|
|
378
|
+
data: {
|
|
379
|
+
type: "external_email_intake",
|
|
380
|
+
id: input.intakeId,
|
|
381
|
+
attributes: {},
|
|
382
|
+
},
|
|
383
|
+
},
|
|
384
|
+
});
|
|
385
|
+
}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { CliError } from "../errors";
|
|
2
|
+
import {
|
|
3
|
+
requireMasterToken,
|
|
4
|
+
requireOwnerReadToken,
|
|
5
|
+
resolveIdentityCredential,
|
|
6
|
+
} from "../tokens";
|
|
7
|
+
import type {
|
|
8
|
+
IdResponse,
|
|
9
|
+
LatestFirstOrder,
|
|
10
|
+
PayloadFilters,
|
|
11
|
+
PostAttributes,
|
|
12
|
+
ShareTokenResponse,
|
|
13
|
+
StructuredContentInput,
|
|
14
|
+
} from "../../types/api";
|
|
15
|
+
import { API_PREFIX, withQuery, type ApiClientCore } from "./core";
|
|
16
|
+
|
|
17
|
+
export async function publishPost(
|
|
18
|
+
core: ApiClientCore,
|
|
19
|
+
input: {
|
|
20
|
+
identityId: string;
|
|
21
|
+
identityKey?: string;
|
|
22
|
+
} & StructuredContentInput,
|
|
23
|
+
) {
|
|
24
|
+
const resolved = resolveIdentityCredential(
|
|
25
|
+
core.profile,
|
|
26
|
+
input.identityId,
|
|
27
|
+
input.identityKey,
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
if (!resolved.token) {
|
|
31
|
+
throw new CliError(
|
|
32
|
+
`No identity key available for identity ${input.identityId}. Provide --identity-key, set identity key env vars, save an identity key, or configure a master token.`,
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return core.requestResource<PostAttributes>(
|
|
37
|
+
`${API_PREFIX}/identities/${input.identityId}/posts`,
|
|
38
|
+
{
|
|
39
|
+
method: "POST",
|
|
40
|
+
token: resolved.token,
|
|
41
|
+
body: {
|
|
42
|
+
data: {
|
|
43
|
+
type: "post",
|
|
44
|
+
attributes: {
|
|
45
|
+
...(input.body !== undefined ? { body: input.body } : {}),
|
|
46
|
+
...(input.payload !== undefined ? { payload: input.payload } : {}),
|
|
47
|
+
...(input.contentFormat !== undefined
|
|
48
|
+
? { content_format: input.contentFormat }
|
|
49
|
+
: {}),
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export async function listIdentityPosts(
|
|
58
|
+
core: ApiClientCore,
|
|
59
|
+
input: {
|
|
60
|
+
identityId: string;
|
|
61
|
+
limit?: number;
|
|
62
|
+
cursor?: string;
|
|
63
|
+
before?: string;
|
|
64
|
+
order?: LatestFirstOrder;
|
|
65
|
+
since?: string;
|
|
66
|
+
} & PayloadFilters,
|
|
67
|
+
) {
|
|
68
|
+
return core.requestCollection<PostAttributes>(
|
|
69
|
+
withQuery(`${API_PREFIX}/identities/${input.identityId}/posts`, {
|
|
70
|
+
order: input.order,
|
|
71
|
+
since: input.since,
|
|
72
|
+
before: input.before,
|
|
73
|
+
content_format: input.contentFormat,
|
|
74
|
+
payload_contains: input.payloadContains,
|
|
75
|
+
payload_path: input.payloadPath,
|
|
76
|
+
payload_op: input.payloadOp,
|
|
77
|
+
payload_value: input.payloadValue,
|
|
78
|
+
"page[limit]": input.limit,
|
|
79
|
+
"page[after]": input.cursor,
|
|
80
|
+
}),
|
|
81
|
+
{
|
|
82
|
+
token: requireOwnerReadToken(core.profile),
|
|
83
|
+
},
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export async function listPublicIdentityPosts(
|
|
88
|
+
core: ApiClientCore,
|
|
89
|
+
input: {
|
|
90
|
+
publicHandle: string;
|
|
91
|
+
identityName: string;
|
|
92
|
+
limit?: number;
|
|
93
|
+
cursor?: string;
|
|
94
|
+
before?: string;
|
|
95
|
+
order?: LatestFirstOrder;
|
|
96
|
+
since?: string;
|
|
97
|
+
} & PayloadFilters,
|
|
98
|
+
) {
|
|
99
|
+
return core.requestCollection<PostAttributes>(
|
|
100
|
+
withQuery(
|
|
101
|
+
`${API_PREFIX}/public/users/${encodeURIComponent(input.publicHandle)}/identities/${encodeURIComponent(input.identityName)}/posts`,
|
|
102
|
+
{
|
|
103
|
+
order: input.order,
|
|
104
|
+
since: input.since,
|
|
105
|
+
before: input.before,
|
|
106
|
+
content_format: input.contentFormat,
|
|
107
|
+
payload_contains: input.payloadContains,
|
|
108
|
+
payload_path: input.payloadPath,
|
|
109
|
+
payload_op: input.payloadOp,
|
|
110
|
+
payload_value: input.payloadValue,
|
|
111
|
+
"page[limit]": input.limit,
|
|
112
|
+
"page[after]": input.cursor,
|
|
113
|
+
},
|
|
114
|
+
),
|
|
115
|
+
{},
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export async function listSharedIdentityPosts(
|
|
120
|
+
core: ApiClientCore,
|
|
121
|
+
input: {
|
|
122
|
+
token: string;
|
|
123
|
+
limit?: number;
|
|
124
|
+
cursor?: string;
|
|
125
|
+
before?: string;
|
|
126
|
+
order?: LatestFirstOrder;
|
|
127
|
+
since?: string;
|
|
128
|
+
} & PayloadFilters,
|
|
129
|
+
) {
|
|
130
|
+
return core.requestCollection<PostAttributes>(
|
|
131
|
+
withQuery(`${API_PREFIX}/shares/identities/${encodeURIComponent(input.token)}/posts`, {
|
|
132
|
+
order: input.order,
|
|
133
|
+
since: input.since,
|
|
134
|
+
before: input.before,
|
|
135
|
+
content_format: input.contentFormat,
|
|
136
|
+
payload_contains: input.payloadContains,
|
|
137
|
+
payload_path: input.payloadPath,
|
|
138
|
+
payload_op: input.payloadOp,
|
|
139
|
+
payload_value: input.payloadValue,
|
|
140
|
+
"page[limit]": input.limit,
|
|
141
|
+
"page[after]": input.cursor,
|
|
142
|
+
}),
|
|
143
|
+
{},
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export async function getPost(core: ApiClientCore, postId: string) {
|
|
148
|
+
return core.requestResource<PostAttributes>(
|
|
149
|
+
`${API_PREFIX}/posts/${postId}`,
|
|
150
|
+
{
|
|
151
|
+
token: requireOwnerReadToken(core.profile),
|
|
152
|
+
},
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export async function getPublicPostByHandle(
|
|
157
|
+
core: ApiClientCore,
|
|
158
|
+
input: {
|
|
159
|
+
publicHandle: string;
|
|
160
|
+
identityName: string;
|
|
161
|
+
postId: string;
|
|
162
|
+
},
|
|
163
|
+
) {
|
|
164
|
+
return core.requestResource<PostAttributes>(
|
|
165
|
+
`${API_PREFIX}/public/users/${encodeURIComponent(input.publicHandle)}/identities/${encodeURIComponent(input.identityName)}/posts/${input.postId}`,
|
|
166
|
+
{},
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export async function getSharedPost(core: ApiClientCore, token: string) {
|
|
171
|
+
return core.requestResource<PostAttributes>(
|
|
172
|
+
`${API_PREFIX}/shares/posts/${encodeURIComponent(token)}`,
|
|
173
|
+
{},
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export async function editPost(
|
|
178
|
+
core: ApiClientCore,
|
|
179
|
+
input: {
|
|
180
|
+
postId: string;
|
|
181
|
+
identityKey?: string;
|
|
182
|
+
} & StructuredContentInput,
|
|
183
|
+
) {
|
|
184
|
+
const token = core.resolvePostLifecycleToken(input.identityKey);
|
|
185
|
+
|
|
186
|
+
return core.requestResource<PostAttributes>(
|
|
187
|
+
`${API_PREFIX}/posts/${input.postId}`,
|
|
188
|
+
{
|
|
189
|
+
method: "PATCH",
|
|
190
|
+
token,
|
|
191
|
+
body: {
|
|
192
|
+
data: {
|
|
193
|
+
type: "post",
|
|
194
|
+
id: input.postId,
|
|
195
|
+
attributes: {
|
|
196
|
+
...(input.body !== undefined ? { body: input.body } : {}),
|
|
197
|
+
...(input.payload !== undefined ? { payload: input.payload } : {}),
|
|
198
|
+
...(input.contentFormat !== undefined
|
|
199
|
+
? { content_format: input.contentFormat }
|
|
200
|
+
: {}),
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export async function deletePost(
|
|
209
|
+
core: ApiClientCore,
|
|
210
|
+
input: {
|
|
211
|
+
postId: string;
|
|
212
|
+
identityKey?: string;
|
|
213
|
+
},
|
|
214
|
+
): Promise<void> {
|
|
215
|
+
const token = core.resolvePostLifecycleToken(input.identityKey);
|
|
216
|
+
|
|
217
|
+
await core.requestJsonApi(`${API_PREFIX}/posts/${input.postId}`, {
|
|
218
|
+
method: "DELETE",
|
|
219
|
+
token,
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export async function sharePost(core: ApiClientCore, postId: string) {
|
|
224
|
+
return core.requestAction<ShareTokenResponse>(`${API_PREFIX}/posts/${postId}/share`, {
|
|
225
|
+
method: "POST",
|
|
226
|
+
token: requireMasterToken(core.profile),
|
|
227
|
+
body: { data: {} },
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export async function revokePostShare(core: ApiClientCore, postId: string) {
|
|
232
|
+
return core.requestAction<IdResponse>(`${API_PREFIX}/posts/${postId}/share`, {
|
|
233
|
+
method: "DELETE",
|
|
234
|
+
token: requireMasterToken(core.profile),
|
|
235
|
+
});
|
|
236
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { requestJson } from "../http";
|
|
2
|
+
import { resolveMasterToken } from "../tokens";
|
|
3
|
+
import {
|
|
4
|
+
API_PREFIX,
|
|
5
|
+
inferMediaType,
|
|
6
|
+
type ApiClientCore,
|
|
7
|
+
} from "./core";
|
|
8
|
+
|
|
9
|
+
export async function fetchOpenApi(core: ApiClientCore): Promise<unknown> {
|
|
10
|
+
return (await requestJson(core.profile.baseUrl, `${API_PREFIX}/open_api`))
|
|
11
|
+
.data;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function apiRequest(
|
|
15
|
+
core: ApiClientCore,
|
|
16
|
+
input: {
|
|
17
|
+
method: string;
|
|
18
|
+
path: string;
|
|
19
|
+
body?: string;
|
|
20
|
+
identityKey?: string;
|
|
21
|
+
},
|
|
22
|
+
): Promise<unknown> {
|
|
23
|
+
return (
|
|
24
|
+
await requestJson(core.profile.baseUrl, input.path, {
|
|
25
|
+
method: input.method,
|
|
26
|
+
token: input.identityKey ?? resolveMasterToken(core.profile).token,
|
|
27
|
+
rawBody: input.body,
|
|
28
|
+
accept: inferMediaType(input.path),
|
|
29
|
+
contentType:
|
|
30
|
+
input.body === undefined ? undefined : inferMediaType(input.path),
|
|
31
|
+
})
|
|
32
|
+
).data;
|
|
33
|
+
}
|