@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.
Files changed (81) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/LICENSE +21 -0
  3. package/README.md +275 -0
  4. package/bin/clank +6 -0
  5. package/docs/usage/clankid-migration.md +59 -0
  6. package/package.json +47 -0
  7. package/skills/codex/clankid/SKILL.md +256 -0
  8. package/skills/codex/clankid/references/safety.md +28 -0
  9. package/skills/codex/clankid/references/setup.md +65 -0
  10. package/src/README.md +8 -0
  11. package/src/cli.ts +154 -0
  12. package/src/commands/.gitkeep +1 -0
  13. package/src/commands/account.ts +337 -0
  14. package/src/commands/api.ts +43 -0
  15. package/src/commands/auth/access-keys.ts +206 -0
  16. package/src/commands/auth.ts +240 -0
  17. package/src/commands/cache.ts +124 -0
  18. package/src/commands/config.ts +93 -0
  19. package/src/commands/doctor/checks.ts +123 -0
  20. package/src/commands/doctor/render.ts +140 -0
  21. package/src/commands/doctor/suggestions.ts +42 -0
  22. package/src/commands/doctor/types.ts +75 -0
  23. package/src/commands/doctor.ts +221 -0
  24. package/src/commands/feed.ts +185 -0
  25. package/src/commands/identity/keys.ts +145 -0
  26. package/src/commands/identity/render.ts +224 -0
  27. package/src/commands/identity/validation.ts +11 -0
  28. package/src/commands/identity.ts +295 -0
  29. package/src/commands/inbox/content.ts +13 -0
  30. package/src/commands/inbox/filters.ts +70 -0
  31. package/src/commands/inbox/messages.ts +71 -0
  32. package/src/commands/inbox/participants.ts +152 -0
  33. package/src/commands/inbox/render.ts +13 -0
  34. package/src/commands/inbox/resource-output.ts +217 -0
  35. package/src/commands/inbox/schema.ts +185 -0
  36. package/src/commands/inbox/screening.ts +76 -0
  37. package/src/commands/inbox/sync-scopes.ts +62 -0
  38. package/src/commands/inbox/thread-output.ts +345 -0
  39. package/src/commands/inbox/watch.ts +207 -0
  40. package/src/commands/inbox.ts +374 -0
  41. package/src/commands/post.ts +406 -0
  42. package/src/commands/setup.ts +228 -0
  43. package/src/commands/skill.ts +41 -0
  44. package/src/commands/user.ts +33 -0
  45. package/src/lib/.gitkeep +1 -0
  46. package/src/lib/args.ts +231 -0
  47. package/src/lib/body-input.ts +55 -0
  48. package/src/lib/cache/scopes.ts +272 -0
  49. package/src/lib/cache/store.ts +195 -0
  50. package/src/lib/cache/types.ts +31 -0
  51. package/src/lib/cache.ts +135 -0
  52. package/src/lib/client/auth.ts +163 -0
  53. package/src/lib/client/core.ts +133 -0
  54. package/src/lib/client/feed.ts +93 -0
  55. package/src/lib/client/identities.ts +364 -0
  56. package/src/lib/client/identity-keys.ts +57 -0
  57. package/src/lib/client/inbox.ts +385 -0
  58. package/src/lib/client/posts.ts +236 -0
  59. package/src/lib/client/raw-api.ts +33 -0
  60. package/src/lib/client/users.ts +88 -0
  61. package/src/lib/client.ts +469 -0
  62. package/src/lib/config.ts +239 -0
  63. package/src/lib/content.ts +149 -0
  64. package/src/lib/context.ts +43 -0
  65. package/src/lib/errors.ts +17 -0
  66. package/src/lib/help.ts +1587 -0
  67. package/src/lib/http.ts +138 -0
  68. package/src/lib/human.ts +143 -0
  69. package/src/lib/json-input.ts +73 -0
  70. package/src/lib/json_api.ts +120 -0
  71. package/src/lib/output.ts +203 -0
  72. package/src/lib/pagination.ts +116 -0
  73. package/src/lib/paths.ts +44 -0
  74. package/src/lib/polling.ts +146 -0
  75. package/src/lib/post-output.ts +60 -0
  76. package/src/lib/skills.ts +137 -0
  77. package/src/lib/tokens.ts +284 -0
  78. package/src/lib/version.ts +19 -0
  79. package/src/types/.gitkeep +1 -0
  80. package/src/types/api.ts +320 -0
  81. package/src/types/placeholder.d.ts +1 -0
@@ -0,0 +1,93 @@
1
+ import { requireOwnerReadToken } from "../tokens";
2
+ import type {
3
+ ChangeCheckResponse,
4
+ LatestFirstOrder,
5
+ PayloadFilters,
6
+ PostAttributes,
7
+ } from "../../types/api";
8
+ import { API_PREFIX, withQuery, type ApiClientCore } from "./core";
9
+
10
+ export async function myFeed(
11
+ core: ApiClientCore,
12
+ input: {
13
+ identityId?: string;
14
+ limit?: number;
15
+ cursor?: string;
16
+ before?: string;
17
+ order?: LatestFirstOrder;
18
+ since?: string;
19
+ } & PayloadFilters,
20
+ ) {
21
+ return core.requestCollection<PostAttributes>(
22
+ withQuery(`${API_PREFIX}/feeds/my`, {
23
+ identity_id: input.identityId,
24
+ order: input.order,
25
+ since: input.since,
26
+ before: input.before,
27
+ content_format: input.contentFormat,
28
+ payload_contains: input.payloadContains,
29
+ payload_path: input.payloadPath,
30
+ payload_op: input.payloadOp,
31
+ payload_value: input.payloadValue,
32
+ "page[limit]": input.limit,
33
+ "page[after]": input.cursor,
34
+ }),
35
+ {
36
+ token: requireOwnerReadToken(core.profile),
37
+ },
38
+ );
39
+ }
40
+
41
+ export async function searchMyFeed(
42
+ core: ApiClientCore,
43
+ input: {
44
+ query: string;
45
+ identityId?: string;
46
+ limit?: number;
47
+ cursor?: string;
48
+ before?: string;
49
+ order?: LatestFirstOrder;
50
+ since?: string;
51
+ } & PayloadFilters,
52
+ ) {
53
+ return core.requestCollection<PostAttributes>(
54
+ withQuery(`${API_PREFIX}/feeds/my/search`, {
55
+ query: input.query,
56
+ identity_id: input.identityId,
57
+ order: input.order,
58
+ since: input.since,
59
+ before: input.before,
60
+ content_format: input.contentFormat,
61
+ payload_contains: input.payloadContains,
62
+ payload_path: input.payloadPath,
63
+ payload_op: input.payloadOp,
64
+ payload_value: input.payloadValue,
65
+ "page[limit]": input.limit,
66
+ "page[after]": input.cursor,
67
+ }),
68
+ {
69
+ token: requireOwnerReadToken(core.profile),
70
+ },
71
+ );
72
+ }
73
+
74
+ export async function checkMyFeedChanges(
75
+ core: ApiClientCore,
76
+ input: { since: string; identityId?: string } & PayloadFilters,
77
+ ) {
78
+ return core.requestAction<ChangeCheckResponse>(
79
+ withQuery(`${API_PREFIX}/feeds/my/changes`, {
80
+ since: input.since,
81
+ identity_id: input.identityId,
82
+ identity_ids: undefined,
83
+ content_format: input.contentFormat,
84
+ payload_contains: input.payloadContains,
85
+ payload_path: input.payloadPath,
86
+ payload_op: input.payloadOp,
87
+ payload_value: input.payloadValue,
88
+ }),
89
+ {
90
+ token: requireOwnerReadToken(core.profile),
91
+ },
92
+ );
93
+ }
@@ -0,0 +1,364 @@
1
+ import { CliError } from "../errors";
2
+ import {
3
+ requireMasterToken,
4
+ requireOwnerReadToken,
5
+ resolveOwnerReadToken,
6
+ } from "../tokens";
7
+ import type {
8
+ IdentityAttributes,
9
+ IdentityDiagnosticsResponse,
10
+ IdentityPinResponse,
11
+ IdentityPublicationResponse,
12
+ ExternalEmailAcceptance,
13
+ IdResponse,
14
+ ShareTokenResponse,
15
+ } from "../../types/api";
16
+ import {
17
+ API_PREFIX,
18
+ looksLikeUuid,
19
+ withQuery,
20
+ type ApiClientCore,
21
+ } from "./core";
22
+
23
+ export async function listIdentities(
24
+ core: ApiClientCore,
25
+ input: { limit?: number; cursor?: string } = {},
26
+ ) {
27
+ return core.requestCollection<IdentityAttributes>(
28
+ withQuery(`${API_PREFIX}/identities`, {
29
+ "page[limit]": input.limit,
30
+ "page[after]": input.cursor,
31
+ }),
32
+ {
33
+ token: requireOwnerReadToken(core.profile),
34
+ },
35
+ );
36
+ }
37
+
38
+ export async function getIdentity(core: ApiClientCore, identityId: string) {
39
+ return core.requestResource<IdentityAttributes>(
40
+ `${API_PREFIX}/identities/${identityId}`,
41
+ {
42
+ token: requireOwnerReadToken(core.profile),
43
+ },
44
+ );
45
+ }
46
+
47
+ export async function getIdentityDiagnostics(
48
+ core: ApiClientCore,
49
+ identityId: string,
50
+ ) {
51
+ return core.requestAction<IdentityDiagnosticsResponse>(
52
+ `${API_PREFIX}/identities/${identityId}/diagnostics`,
53
+ {
54
+ token: requireOwnerReadToken(core.profile),
55
+ },
56
+ );
57
+ }
58
+
59
+ export async function getIdentityByName(
60
+ core: ApiClientCore,
61
+ identityName: string,
62
+ ) {
63
+ return core.requestResource<IdentityAttributes>(
64
+ `${API_PREFIX}/identities/by-name/${encodeURIComponent(identityName)}`,
65
+ {
66
+ token: requireOwnerReadToken(core.profile),
67
+ },
68
+ );
69
+ }
70
+
71
+ export async function getPublicIdentityByHandle(
72
+ core: ApiClientCore,
73
+ publicHandle: string,
74
+ name: string,
75
+ ) {
76
+ return core.requestResource<IdentityAttributes>(
77
+ `${API_PREFIX}/public/users/${encodeURIComponent(publicHandle)}/identities/${encodeURIComponent(name)}`,
78
+ {},
79
+ );
80
+ }
81
+
82
+ export async function getPublicIdentityInboxSchema(
83
+ core: ApiClientCore,
84
+ publicHandle: string,
85
+ name: string,
86
+ ) {
87
+ return core.requestResource<IdentityAttributes>(
88
+ `${API_PREFIX}/public/users/${encodeURIComponent(publicHandle)}/identities/${encodeURIComponent(name)}/inbox-schema`,
89
+ {},
90
+ );
91
+ }
92
+
93
+ export async function listPublicIdentitiesForHandle(
94
+ core: ApiClientCore,
95
+ input: {
96
+ publicHandle: string;
97
+ limit?: number;
98
+ cursor?: string;
99
+ },
100
+ ) {
101
+ return core.requestCollection<IdentityAttributes>(
102
+ withQuery(
103
+ `${API_PREFIX}/public/users/${encodeURIComponent(input.publicHandle)}/identities`,
104
+ {
105
+ "page[limit]": input.limit,
106
+ "page[after]": input.cursor,
107
+ },
108
+ ),
109
+ {},
110
+ );
111
+ }
112
+
113
+ export async function getSharedIdentity(core: ApiClientCore, token: string) {
114
+ return core.requestResource<IdentityAttributes>(
115
+ `${API_PREFIX}/shares/identities/${encodeURIComponent(token)}`,
116
+ {},
117
+ );
118
+ }
119
+
120
+ export async function createIdentity(
121
+ core: ApiClientCore,
122
+ input: { name: string; description?: string },
123
+ ) {
124
+ return core.requestResource<IdentityAttributes>(`${API_PREFIX}/identities`, {
125
+ method: "POST",
126
+ token: requireMasterToken(core.profile),
127
+ body: {
128
+ data: {
129
+ type: "identity",
130
+ attributes: {
131
+ name: input.name,
132
+ ...(input.description ? { description: input.description } : {}),
133
+ },
134
+ },
135
+ },
136
+ });
137
+ }
138
+
139
+ export async function updateIdentity(
140
+ core: ApiClientCore,
141
+ input: {
142
+ identityId: string;
143
+ name?: string;
144
+ description?: string;
145
+ },
146
+ ) {
147
+ return core.requestResource<IdentityAttributes>(
148
+ `${API_PREFIX}/identities/${input.identityId}`,
149
+ {
150
+ method: "PATCH",
151
+ token: requireMasterToken(core.profile),
152
+ body: {
153
+ data: {
154
+ type: "identity",
155
+ id: input.identityId,
156
+ attributes: {
157
+ ...(input.name !== undefined ? { name: input.name } : {}),
158
+ ...(input.description !== undefined
159
+ ? { description: input.description }
160
+ : {}),
161
+ },
162
+ },
163
+ },
164
+ },
165
+ );
166
+ }
167
+
168
+ export async function setIdentityInboxSchema(
169
+ core: ApiClientCore,
170
+ input: {
171
+ identityId: string;
172
+ inboxSchema: Record<string, unknown>;
173
+ },
174
+ ) {
175
+ return core.requestResource<IdentityAttributes>(
176
+ `${API_PREFIX}/identities/${input.identityId}/inbox-schema`,
177
+ {
178
+ method: "PATCH",
179
+ token: requireMasterToken(core.profile),
180
+ body: {
181
+ data: {
182
+ type: "identity",
183
+ id: input.identityId,
184
+ attributes: {
185
+ inbox_schema: input.inboxSchema,
186
+ },
187
+ },
188
+ },
189
+ },
190
+ );
191
+ }
192
+
193
+ export async function removeIdentityInboxSchema(
194
+ core: ApiClientCore,
195
+ identityId: string,
196
+ ) {
197
+ return core.requestResource<IdentityAttributes>(
198
+ `${API_PREFIX}/identities/${identityId}/inbox-schema/remove`,
199
+ {
200
+ method: "PATCH",
201
+ token: requireMasterToken(core.profile),
202
+ body: {
203
+ data: {
204
+ type: "identity",
205
+ id: identityId,
206
+ attributes: {},
207
+ },
208
+ },
209
+ },
210
+ );
211
+ }
212
+
213
+ export async function setIdentityExternalEmailAcceptance(
214
+ core: ApiClientCore,
215
+ input: {
216
+ identityId: string;
217
+ externalEmailAcceptance: ExternalEmailAcceptance;
218
+ },
219
+ ) {
220
+ return core.requestResource<IdentityAttributes>(
221
+ `${API_PREFIX}/identities/${input.identityId}/inbox-acceptance`,
222
+ {
223
+ method: "PATCH",
224
+ token: requireMasterToken(core.profile),
225
+ body: {
226
+ data: {
227
+ type: "identity",
228
+ id: input.identityId,
229
+ attributes: {
230
+ external_email_acceptance: input.externalEmailAcceptance,
231
+ },
232
+ },
233
+ },
234
+ },
235
+ );
236
+ }
237
+
238
+ export async function publishIdentityPublicly(
239
+ core: ApiClientCore,
240
+ identityId: string,
241
+ ) {
242
+ return core.requestResource<IdentityAttributes>(
243
+ `${API_PREFIX}/identities/${identityId}/publication`,
244
+ {
245
+ method: "PATCH",
246
+ token: requireMasterToken(core.profile),
247
+ body: {
248
+ data: {
249
+ type: "identity",
250
+ id: identityId,
251
+ },
252
+ },
253
+ },
254
+ );
255
+ }
256
+
257
+ export async function unpublishIdentityPublicly(
258
+ core: ApiClientCore,
259
+ identityId: string,
260
+ ) {
261
+ return core.requestAction<IdentityPublicationResponse>(
262
+ `${API_PREFIX}/identities/${identityId}/publication`,
263
+ {
264
+ method: "DELETE",
265
+ token: requireMasterToken(core.profile),
266
+ },
267
+ );
268
+ }
269
+
270
+ export async function shareIdentity(core: ApiClientCore, identityId: string) {
271
+ return core.requestAction<ShareTokenResponse>(
272
+ `${API_PREFIX}/identities/${identityId}/share`,
273
+ {
274
+ method: "POST",
275
+ token: requireMasterToken(core.profile),
276
+ body: { data: {} },
277
+ },
278
+ );
279
+ }
280
+
281
+ export async function revokeIdentityShare(
282
+ core: ApiClientCore,
283
+ identityId: string,
284
+ ) {
285
+ return core.requestAction<IdResponse>(`${API_PREFIX}/identities/${identityId}/share`, {
286
+ method: "DELETE",
287
+ token: requireMasterToken(core.profile),
288
+ });
289
+ }
290
+
291
+ export async function pinIdentityPost(
292
+ core: ApiClientCore,
293
+ input: {
294
+ identityId: string;
295
+ postId: string;
296
+ identityKey?: string;
297
+ },
298
+ ) {
299
+ return core.requestAction<IdentityPinResponse>(
300
+ `${API_PREFIX}/identities/${input.identityId}/pinned-post`,
301
+ {
302
+ method: "POST",
303
+ token: core.resolveIdentityConfigKey(input.identityId, input.identityKey),
304
+ body: {
305
+ data: {
306
+ attributes: {
307
+ post_id: input.postId,
308
+ },
309
+ },
310
+ },
311
+ },
312
+ );
313
+ }
314
+
315
+ export async function unpinIdentityPost(
316
+ core: ApiClientCore,
317
+ input: { identityId: string; identityKey?: string },
318
+ ) {
319
+ return core.requestAction<IdentityPinResponse>(
320
+ `${API_PREFIX}/identities/${input.identityId}/pinned-post`,
321
+ {
322
+ method: "DELETE",
323
+ token: core.resolveIdentityConfigKey(input.identityId, input.identityKey),
324
+ },
325
+ );
326
+ }
327
+
328
+ export async function deleteIdentity(
329
+ core: ApiClientCore,
330
+ identityId: string,
331
+ ): Promise<void> {
332
+ await core.requestJsonApi(`${API_PREFIX}/identities/${identityId}`, {
333
+ method: "DELETE",
334
+ token: requireMasterToken(core.profile),
335
+ });
336
+ }
337
+
338
+ export async function resolveIdentityId(
339
+ core: ApiClientCore,
340
+ identity: string,
341
+ ): Promise<string> {
342
+ if (looksLikeUuid(identity)) {
343
+ return identity;
344
+ }
345
+
346
+ return (await resolveOwnedIdentity(core, identity)).id;
347
+ }
348
+
349
+ export async function resolveOwnedIdentity(
350
+ core: ApiClientCore,
351
+ identity: string,
352
+ ) {
353
+ if (looksLikeUuid(identity)) {
354
+ return getIdentity(core, identity);
355
+ }
356
+
357
+ if (!resolveOwnerReadToken(core.profile).token) {
358
+ throw new CliError(
359
+ `Resolving identity name "${identity}" requires an owner read token. Use the identity UUID or configure a read-only or master token.`,
360
+ );
361
+ }
362
+
363
+ return getIdentityByName(core, identity);
364
+ }
@@ -0,0 +1,57 @@
1
+ import {
2
+ requireMasterToken,
3
+ requireOwnerReadToken,
4
+ } from "../tokens";
5
+ import type {
6
+ IdentityKeyAttributes,
7
+ IdentityKeyIssueResponse,
8
+ IdentityKeyRevokeResponse,
9
+ } from "../../types/api";
10
+ import { API_PREFIX, withQuery, type ApiClientCore } from "./core";
11
+
12
+ export async function listIdentityKeys(
13
+ core: ApiClientCore,
14
+ input: {
15
+ identityId: string;
16
+ limit?: number;
17
+ cursor?: string;
18
+ },
19
+ ) {
20
+ return core.requestCollection<IdentityKeyAttributes>(
21
+ withQuery(`${API_PREFIX}/identities/${input.identityId}/keys`, {
22
+ "page[limit]": input.limit,
23
+ "page[after]": input.cursor,
24
+ }),
25
+ {
26
+ token: requireOwnerReadToken(core.profile),
27
+ },
28
+ );
29
+ }
30
+
31
+ export async function issueIdentityKey(
32
+ core: ApiClientCore,
33
+ input: { identityId: string; name: string },
34
+ ) {
35
+ return core.requestAction<IdentityKeyIssueResponse>(
36
+ `${API_PREFIX}/identities/${input.identityId}/keys`,
37
+ {
38
+ method: "POST",
39
+ token: requireMasterToken(core.profile),
40
+ body: {
41
+ data: {
42
+ name: input.name,
43
+ },
44
+ },
45
+ },
46
+ );
47
+ }
48
+
49
+ export async function revokeIdentityKey(core: ApiClientCore, id: string) {
50
+ return core.requestAction<IdentityKeyRevokeResponse>(
51
+ `${API_PREFIX}/identity-keys/${id}`,
52
+ {
53
+ method: "DELETE",
54
+ token: requireMasterToken(core.profile),
55
+ },
56
+ );
57
+ }