@oxy.so/contracts 1.4.0 → 1.5.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/dist/esm/index.js CHANGED
@@ -178,3 +178,5 @@ export { AUTONOMY_LEVELS, CAPABILITY_PACKAGES, autonomyLevelSchema, capabilityPa
178
178
  export { emailContextAddressSchema, emailContextMailboxSchema, emailContextMessageSchema, emailAgentContextSchema, } from './emailAgentContext.js';
179
179
  export { inboxComposeRequestSchema, inboxDailyBriefRequestSchema, inboxNaturalSearchRequestSchema, inboxMessageInferenceParamsSchema, inboxInferenceTextResponseSchema, inboxNaturalSearchResponseSchema, inboxSmartRepliesResponseSchema, inboxThreadSummaryResponseSchema, inboxInferenceStreamEventSchema, } from './inference/inbox.js';
180
180
  export * from './externalIdentity.js';
181
+ export * from './linkedAccounts.js';
182
+ export * from './notifications.js';
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Wire contract for Oxy linked accounts — external accounts (any Mastodon-API
3
+ * server, Bluesky) a LOCAL Oxy user has proven they own by completing an OAuth
4
+ * authorization there.
5
+ *
6
+ * Every response schema is `.strict()` and carries no field a third-party token
7
+ * could occupy: Oxy uses the OAuth flow only to learn which account authorized
8
+ * it, then discards the token. See `docs/identity/linked-accounts.md`.
9
+ *
10
+ * Platform-agnostic — zod only, no react/react-native/expo.
11
+ */
12
+ import { z } from 'zod';
13
+ export const LINKED_ACCOUNT_NETWORKS = ['activitypub', 'atproto'];
14
+ export const linkedAccountNetworkSchema = z.enum(LINKED_ACCOUNT_NETWORKS);
15
+ /**
16
+ * `POST /linked-accounts/:network/start`.
17
+ *
18
+ * - `instance` (activitypub): `mastodon.social`, `https://mastodon.social` or
19
+ * `@user@mastodon.social`.
20
+ * - `handle` (atproto): a handle (`alice.bsky.social`) or a DID.
21
+ * - `returnTo` + `clientId`: where the browser lands afterwards, with
22
+ * `?link_code=` or `?link_error=`. `returnTo` must exactly match a redirect
23
+ * URI registered on the TRUSTED (first-party) application `clientId` names.
24
+ */
25
+ export const startLinkedAccountRequestSchema = z
26
+ .object({
27
+ instance: z.string().trim().min(1).max(320).optional(),
28
+ handle: z.string().trim().min(1).max(320).optional(),
29
+ clientId: z.string().trim().min(1).max(256),
30
+ returnTo: z.string().trim().min(1).max(2048),
31
+ })
32
+ .strict();
33
+ export const startLinkedAccountResponseSchema = z
34
+ .object({
35
+ authorizeUrl: z.string().url(),
36
+ expiresAt: z.string().datetime(),
37
+ })
38
+ .strict();
39
+ /**
40
+ * `POST /linked-accounts/complete`, with the session of the user who STARTED
41
+ * the flow: `code` is the one-time `link_code` the callback appended to
42
+ * `returnTo`. It expires five minutes after the callback. Presented by any
43
+ * other user it is refused (403) and burned.
44
+ */
45
+ export const completeLinkedAccountRequestSchema = z
46
+ .object({ code: z.string().trim().min(1).max(256) })
47
+ .strict();
48
+ /** One live linked account, as its owner sees it. */
49
+ export const linkedAccountSchema = z
50
+ .object({
51
+ id: z.string().min(1),
52
+ network: linkedAccountNetworkSchema,
53
+ /** `username@domain` for ActivityPub; the DID for atproto. */
54
+ accountKey: z.string().min(1),
55
+ /** ActivityPub actor id, or the DID for atproto. */
56
+ actorUri: z.string().min(1),
57
+ handle: z.string().min(1),
58
+ host: z.string().min(1),
59
+ proofMethod: z.literal('oauth'),
60
+ verifiedAt: z.string().datetime(),
61
+ createdAt: z.string().datetime(),
62
+ })
63
+ .strict();
64
+ export const completeLinkedAccountResponseSchema = z
65
+ .object({ linkedAccount: linkedAccountSchema })
66
+ .strict();
67
+ export const linkedAccountListResponseSchema = z
68
+ .object({ linkedAccounts: z.array(linkedAccountSchema) })
69
+ .strict();
70
+ /**
71
+ * `GET /linked-accounts/by-user/:userId` (service token with the privileged
72
+ * `linked-accounts:read`). Adds `federatedUserId`: the FEDERATED shadow user Oxy
73
+ * already holds for that external account, if any — the anchor for adopting
74
+ * content Oxy federated in before the account was linked.
75
+ */
76
+ export const serviceLinkedAccountSchema = linkedAccountSchema
77
+ .extend({ federatedUserId: z.string().min(1).nullable() })
78
+ .strict();
79
+ export const serviceLinkedAccountListResponseSchema = z
80
+ .object({ userId: z.string().min(1), linkedAccounts: z.array(serviceLinkedAccountSchema) })
81
+ .strict();
82
+ /**
83
+ * Error codes the callback appends as `?link_error=<code>` to `returnTo`. An
84
+ * account already linked to someone else is reported by `/complete` (409).
85
+ */
86
+ export const LINKED_ACCOUNT_CALLBACK_ERRORS = [
87
+ 'access_denied',
88
+ 'verification_failed',
89
+ 'provider_unavailable',
90
+ ];
@@ -0,0 +1,78 @@
1
+ /**
2
+ * The closed set of Oxy in-app notification types — owned here so the API's
3
+ * CHECK constraint (`notifications.type`), its request validation and the SDK
4
+ * all read one tuple.
5
+ *
6
+ * `system` is a message from an Oxy service about the recipient's OWN account
7
+ * (Oxy Move's "your migration finished"): the actor is the recipient, and the
8
+ * entity is their profile or an `app` id. It is the only type an actor does not
9
+ * cause.
10
+ *
11
+ * Platform-agnostic — zod only, no react/react-native/expo.
12
+ */
13
+ import { z } from 'zod';
14
+ export const OXY_NOTIFICATION_TYPES = [
15
+ 'like',
16
+ 'reply',
17
+ 'mention',
18
+ 'follow',
19
+ 'repost',
20
+ 'quote',
21
+ 'welcome',
22
+ 'system',
23
+ ];
24
+ /**
25
+ * What a notification's `entityId` names.
26
+ *
27
+ * `app` means `entityId` is an OPAQUE id in the notifying application's own
28
+ * namespace (Oxy Move's migration job id). Oxy never resolves it; it exists so
29
+ * a `system` notification about something that is not a post or a profile does
30
+ * not have to pretend to be one. Valid only with `type: 'system'`.
31
+ */
32
+ export const OXY_NOTIFICATION_ENTITY_TYPES = ['post', 'reply', 'profile', 'app'];
33
+ /** Length caps on the text a `system` notification carries (enforced by CHECKs too). */
34
+ export const OXY_SYSTEM_NOTIFICATION_TITLE_MAX = 120;
35
+ export const OXY_SYSTEM_NOTIFICATION_MESSAGE_MAX = 500;
36
+ export const OXY_NOTIFICATION_URL_MAX = 2048;
37
+ /**
38
+ * `POST /notifications` (service token with `notifications:write`).
39
+ *
40
+ * Only a `system` notification carries text: `title` and `message` are REQUIRED
41
+ * for it and stored, and `url` is an optional deep link (https, or a custom
42
+ * scheme registered as a redirect URI on the calling application). For every
43
+ * other type the client renders from `type` + entity, and `title` / `message` /
44
+ * `data` are accepted but discarded, as they always were.
45
+ *
46
+ * `system` notifications share the duplicate guard (recipient, actor, type,
47
+ * entityId): use a caller-unique `entityId` (a job id) for each distinct event.
48
+ */
49
+ export const createOxyNotificationRequestSchema = z
50
+ .object({
51
+ recipientId: z.string().min(1),
52
+ actorId: z.string().min(1),
53
+ type: z.enum(OXY_NOTIFICATION_TYPES),
54
+ entityId: z.string().min(1),
55
+ entityType: z.enum(OXY_NOTIFICATION_ENTITY_TYPES),
56
+ title: z.string().trim().min(1).max(OXY_SYSTEM_NOTIFICATION_TITLE_MAX).optional(),
57
+ message: z.string().trim().min(1).max(OXY_SYSTEM_NOTIFICATION_MESSAGE_MAX).optional(),
58
+ url: z.string().trim().min(1).max(OXY_NOTIFICATION_URL_MAX).optional(),
59
+ data: z.record(z.string(), z.unknown()).optional(),
60
+ })
61
+ .superRefine((value, context) => {
62
+ if (value.type === 'system') {
63
+ if (value.actorId !== value.recipientId)
64
+ context.addIssue({ code: z.ZodIssueCode.custom, path: ['actorId'], message: 'a system notification is from the recipient\'s own account' });
65
+ if (!value.title)
66
+ context.addIssue({ code: z.ZodIssueCode.custom, path: ['title'], message: 'title is required for a system notification' });
67
+ if (!value.message)
68
+ context.addIssue({ code: z.ZodIssueCode.custom, path: ['message'], message: 'message is required for a system notification' });
69
+ }
70
+ else {
71
+ if (value.url !== undefined) {
72
+ context.addIssue({ code: z.ZodIssueCode.custom, path: ['url'], message: 'url is only stored for a system notification' });
73
+ }
74
+ if (value.entityType === 'app') {
75
+ context.addIssue({ code: z.ZodIssueCode.custom, path: ['entityType'], message: "entityType 'app' is only valid for a system notification" });
76
+ }
77
+ }
78
+ });