@oxyhq/contracts 0.21.0 → 0.22.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/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/accountGraph.js +80 -3
- package/dist/cjs/index.js +11 -5
- package/dist/cjs/userResponse.js +21 -1
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/accountGraph.js +77 -2
- package/dist/esm/index.js +1 -1
- package/dist/esm/userResponse.js +22 -2
- package/dist/types/.tsbuildinfo +1 -1
- package/dist/types/accountGraph.d.ts +77 -6
- package/dist/types/index.d.ts +2 -2
- package/dist/types/recommendations.d.ts +14 -14
- package/dist/types/userResponse.d.ts +278 -28
- package/package.json +1 -1
|
@@ -1,11 +1,75 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Account graph wire contracts —
|
|
2
|
+
* Account graph wire contracts — the account-kind vocabulary, organization
|
|
3
|
+
* taxonomy, and create-account input.
|
|
3
4
|
*
|
|
4
5
|
* `organizationCategory` classifies `kind: 'organization'` accounts (agency,
|
|
5
6
|
* cooperative, landlord, …) without polluting `User.kind`. Meaningful only when
|
|
6
7
|
* `kind === 'organization'`.
|
|
7
8
|
*/
|
|
8
9
|
import { z } from 'zod';
|
|
10
|
+
/**
|
|
11
|
+
* Account-graph classification — the ONE authority for the kind vocabulary.
|
|
12
|
+
*
|
|
13
|
+
* `personal` is the only kind minted by signup and the only one that carries
|
|
14
|
+
* its own credentials; every other kind is a child account created under a
|
|
15
|
+
* parent and operated through `account_members`. The API schema, the Mongoose
|
|
16
|
+
* model and the SDK all derive from this list rather than restating it, so a
|
|
17
|
+
* new kind is one edit here instead of four literals that can drift.
|
|
18
|
+
*/
|
|
19
|
+
export type AccountKind = 'personal' | 'organization' | 'project' | 'bot' | 'channel';
|
|
20
|
+
/**
|
|
21
|
+
* The union is spelled out above and the array proves coverage BOTH ways
|
|
22
|
+
* (`satisfies` here, the `Gap` alias below) — the same shape this package's
|
|
23
|
+
* `ORGANIZATION_CATEGORIES` / `TRUST_TIERS` pairs use, and the one
|
|
24
|
+
* `db/schema/users.ts` mirrors to keep the `users_kind_check` CHECK honest.
|
|
25
|
+
*
|
|
26
|
+
* Deriving the union from the array instead would cost nothing here and be paid
|
|
27
|
+
* by consumers: `kind` travels into `@oxyhq/services` through
|
|
28
|
+
* `SwitchableAccount`, where an indexed-access type is materially more
|
|
29
|
+
* expensive to check than a literal union.
|
|
30
|
+
*/
|
|
31
|
+
export declare const ACCOUNT_KINDS: readonly ["personal", "organization", "project", "bot", "channel"];
|
|
32
|
+
/** `never` while `ACCOUNT_KINDS` covers the union. */
|
|
33
|
+
export type AccountKindGap = Exclude<AccountKind, (typeof ACCOUNT_KINDS)[number]>;
|
|
34
|
+
export declare const accountKindSchema: z.ZodEnum<["personal", "organization", "project", "bot", "channel"]>;
|
|
35
|
+
/**
|
|
36
|
+
* Kinds that may be CREATED as children of another account. Exactly
|
|
37
|
+
* `ACCOUNT_KINDS` minus `personal`, which is always a tree root.
|
|
38
|
+
*/
|
|
39
|
+
export type ChildAccountKind = Exclude<AccountKind, 'personal'>;
|
|
40
|
+
export declare const CHILD_ACCOUNT_KINDS: readonly ["organization", "project", "bot", "channel"];
|
|
41
|
+
/** `never` while `CHILD_ACCOUNT_KINDS` covers the child union. */
|
|
42
|
+
export type ChildAccountKindGap = Exclude<ChildAccountKind, (typeof CHILD_ACCOUNT_KINDS)[number]>;
|
|
43
|
+
export declare const childAccountKindSchema: z.ZodEnum<["organization", "project", "bot", "channel"]>;
|
|
44
|
+
/**
|
|
45
|
+
* Whether an operator may ACT AS an account of this kind — switch the whole app
|
|
46
|
+
* into it (`POST /accounts/:id/switch`) or authorise an app to act as it
|
|
47
|
+
* (an OAuth delegated subject).
|
|
48
|
+
*
|
|
49
|
+
* Two kinds are refused, for opposite reasons:
|
|
50
|
+
*
|
|
51
|
+
* - `personal` is a human login, so assuming it would be impersonation.
|
|
52
|
+
* - `channel` is a CONTENT identity, not an operating one. A channel exists so
|
|
53
|
+
* that posts can be authored BY it; it is never a seat anybody occupies. Its
|
|
54
|
+
* operators act on it through their own membership, and an application
|
|
55
|
+
* publishes to it with its own credential. Refusing act-as is what makes
|
|
56
|
+
* "no login, ever" structural rather than incidental: no session can be
|
|
57
|
+
* minted whose subject is a channel, so no bearer exists that could add an
|
|
58
|
+
* auth method to one (every auth-method write resolves its target from the
|
|
59
|
+
* authenticated subject, never from a parameter).
|
|
60
|
+
*
|
|
61
|
+
* Consumers must gate on this predicate rather than testing `kind === 'personal'`,
|
|
62
|
+
* which silently admits every kind added after it was written.
|
|
63
|
+
*/
|
|
64
|
+
export declare function isActAsEligibleKind(kind: AccountKind | null | undefined): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Narrow an unknown value to an {@link AccountKind}.
|
|
67
|
+
*
|
|
68
|
+
* The user-DTO serializers read from structurally-permissive `unknown` sources
|
|
69
|
+
* (a Drizzle row, a Mongo document, an already-formatted object), so each one
|
|
70
|
+
* would otherwise hand-roll this check and they would drift on what counts.
|
|
71
|
+
*/
|
|
72
|
+
export declare function isAccountKind(value: unknown): value is AccountKind;
|
|
9
73
|
export declare const ORGANIZATION_CATEGORIES: readonly ["agency", "cooperative", "landlord", "other"];
|
|
10
74
|
export type OrganizationCategory = (typeof ORGANIZATION_CATEGORIES)[number];
|
|
11
75
|
export declare const organizationCategorySchema: z.ZodEnum<["agency", "cooperative", "landlord", "other"]>;
|
|
@@ -15,65 +79,72 @@ export declare const organizationCategorySchema: z.ZodEnum<["agency", "cooperati
|
|
|
15
79
|
*/
|
|
16
80
|
export declare const createAccountRequestSchema: z.ZodEffects<z.ZodObject<{
|
|
17
81
|
parentAccountId: z.ZodOptional<z.ZodString>;
|
|
18
|
-
kind: z.ZodEnum<["organization", "project", "bot"]>;
|
|
82
|
+
kind: z.ZodEnum<["organization", "project", "bot", "channel"]>;
|
|
19
83
|
username: z.ZodString;
|
|
20
84
|
name: z.ZodOptional<z.ZodObject<{
|
|
21
85
|
first: z.ZodOptional<z.ZodString>;
|
|
22
86
|
last: z.ZodOptional<z.ZodString>;
|
|
87
|
+
displayName: z.ZodOptional<z.ZodString>;
|
|
23
88
|
}, "strip", z.ZodTypeAny, {
|
|
24
89
|
first?: string | undefined;
|
|
25
90
|
last?: string | undefined;
|
|
91
|
+
displayName?: string | undefined;
|
|
26
92
|
}, {
|
|
27
93
|
first?: string | undefined;
|
|
28
94
|
last?: string | undefined;
|
|
95
|
+
displayName?: string | undefined;
|
|
29
96
|
}>>;
|
|
30
97
|
bio: z.ZodOptional<z.ZodString>;
|
|
31
98
|
avatar: z.ZodOptional<z.ZodString>;
|
|
32
99
|
description: z.ZodOptional<z.ZodString>;
|
|
33
100
|
organizationCategory: z.ZodOptional<z.ZodEnum<["agency", "cooperative", "landlord", "other"]>>;
|
|
34
101
|
}, "strip", z.ZodTypeAny, {
|
|
35
|
-
kind: "organization" | "project" | "bot";
|
|
102
|
+
kind: "organization" | "project" | "bot" | "channel";
|
|
36
103
|
username: string;
|
|
37
104
|
parentAccountId?: string | undefined;
|
|
38
105
|
name?: {
|
|
39
106
|
first?: string | undefined;
|
|
40
107
|
last?: string | undefined;
|
|
108
|
+
displayName?: string | undefined;
|
|
41
109
|
} | undefined;
|
|
42
110
|
bio?: string | undefined;
|
|
43
111
|
avatar?: string | undefined;
|
|
44
112
|
description?: string | undefined;
|
|
45
113
|
organizationCategory?: "agency" | "cooperative" | "landlord" | "other" | undefined;
|
|
46
114
|
}, {
|
|
47
|
-
kind: "organization" | "project" | "bot";
|
|
115
|
+
kind: "organization" | "project" | "bot" | "channel";
|
|
48
116
|
username: string;
|
|
49
117
|
parentAccountId?: string | undefined;
|
|
50
118
|
name?: {
|
|
51
119
|
first?: string | undefined;
|
|
52
120
|
last?: string | undefined;
|
|
121
|
+
displayName?: string | undefined;
|
|
53
122
|
} | undefined;
|
|
54
123
|
bio?: string | undefined;
|
|
55
124
|
avatar?: string | undefined;
|
|
56
125
|
description?: string | undefined;
|
|
57
126
|
organizationCategory?: "agency" | "cooperative" | "landlord" | "other" | undefined;
|
|
58
127
|
}>, {
|
|
59
|
-
kind: "organization" | "project" | "bot";
|
|
128
|
+
kind: "organization" | "project" | "bot" | "channel";
|
|
60
129
|
username: string;
|
|
61
130
|
parentAccountId?: string | undefined;
|
|
62
131
|
name?: {
|
|
63
132
|
first?: string | undefined;
|
|
64
133
|
last?: string | undefined;
|
|
134
|
+
displayName?: string | undefined;
|
|
65
135
|
} | undefined;
|
|
66
136
|
bio?: string | undefined;
|
|
67
137
|
avatar?: string | undefined;
|
|
68
138
|
description?: string | undefined;
|
|
69
139
|
organizationCategory?: "agency" | "cooperative" | "landlord" | "other" | undefined;
|
|
70
140
|
}, {
|
|
71
|
-
kind: "organization" | "project" | "bot";
|
|
141
|
+
kind: "organization" | "project" | "bot" | "channel";
|
|
72
142
|
username: string;
|
|
73
143
|
parentAccountId?: string | undefined;
|
|
74
144
|
name?: {
|
|
75
145
|
first?: string | undefined;
|
|
76
146
|
last?: string | undefined;
|
|
147
|
+
displayName?: string | undefined;
|
|
77
148
|
} | undefined;
|
|
78
149
|
bio?: string | undefined;
|
|
79
150
|
avatar?: string | undefined;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
* Platform-agnostic — zod is the only runtime dependency. No react/react-native/
|
|
10
10
|
* expo, no `require()` in the ESM build.
|
|
11
11
|
*/
|
|
12
|
-
export { ORGANIZATION_CATEGORIES, organizationCategorySchema, createAccountRequestSchema, } from './accountGraph';
|
|
13
|
-
export type { OrganizationCategory, CreateAccountRequest, } from './accountGraph';
|
|
12
|
+
export { ACCOUNT_KINDS, accountKindSchema, CHILD_ACCOUNT_KINDS, childAccountKindSchema, isAccountKind, isActAsEligibleKind, ORGANIZATION_CATEGORIES, organizationCategorySchema, createAccountRequestSchema, } from './accountGraph';
|
|
13
|
+
export type { AccountKind, ChildAccountKind, OrganizationCategory, CreateAccountRequest, } from './accountGraph';
|
|
14
14
|
export { userNameSchema, userRelationshipSchema, themePreferenceSchema, userResponseSchema, userProfileUpdateSchema, currentUserResponseSchema, deviceLinkedSessionSchema, deviceLinkedSessionsResponseSchema, resolveUserId, safeParseContract, } from './userResponse';
|
|
15
15
|
export type { UserNameResponse, UserRelationship, ThemePreference, UserResponse, UserProfileUpdate, CurrentUserResponseContract, DeviceLinkedSessionResponse, DeviceLinkedSessionsResponseContract, } from './userResponse';
|
|
16
16
|
export { applicationTypeSchema, publicApplicationSchema, sessionStatusSchema, } from './sessionStatus';
|
|
@@ -172,11 +172,11 @@ export declare const recommendationCountSchema: z.ZodObject<{
|
|
|
172
172
|
followers: z.ZodNumber;
|
|
173
173
|
following: z.ZodNumber;
|
|
174
174
|
}, "strip", z.ZodTypeAny, {
|
|
175
|
-
following: number;
|
|
176
175
|
followers: number;
|
|
177
|
-
}, {
|
|
178
176
|
following: number;
|
|
177
|
+
}, {
|
|
179
178
|
followers: number;
|
|
179
|
+
following: number;
|
|
180
180
|
}>;
|
|
181
181
|
export type RecommendationCount = z.infer<typeof recommendationCountSchema>;
|
|
182
182
|
/**
|
|
@@ -205,11 +205,11 @@ export declare const recommendationItemSchema: z.ZodObject<{
|
|
|
205
205
|
followers: z.ZodNumber;
|
|
206
206
|
following: z.ZodNumber;
|
|
207
207
|
}, "strip", z.ZodTypeAny, {
|
|
208
|
-
following: number;
|
|
209
208
|
followers: number;
|
|
210
|
-
}, {
|
|
211
209
|
following: number;
|
|
210
|
+
}, {
|
|
212
211
|
followers: number;
|
|
212
|
+
following: number;
|
|
213
213
|
}>;
|
|
214
214
|
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
215
215
|
id: z.ZodString;
|
|
@@ -230,11 +230,11 @@ export declare const recommendationItemSchema: z.ZodObject<{
|
|
|
230
230
|
followers: z.ZodNumber;
|
|
231
231
|
following: z.ZodNumber;
|
|
232
232
|
}, "strip", z.ZodTypeAny, {
|
|
233
|
-
following: number;
|
|
234
233
|
followers: number;
|
|
235
|
-
}, {
|
|
236
234
|
following: number;
|
|
235
|
+
}, {
|
|
237
236
|
followers: number;
|
|
237
|
+
following: number;
|
|
238
238
|
}>;
|
|
239
239
|
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
240
240
|
id: z.ZodString;
|
|
@@ -255,11 +255,11 @@ export declare const recommendationItemSchema: z.ZodObject<{
|
|
|
255
255
|
followers: z.ZodNumber;
|
|
256
256
|
following: z.ZodNumber;
|
|
257
257
|
}, "strip", z.ZodTypeAny, {
|
|
258
|
-
following: number;
|
|
259
258
|
followers: number;
|
|
260
|
-
}, {
|
|
261
259
|
following: number;
|
|
260
|
+
}, {
|
|
262
261
|
followers: number;
|
|
262
|
+
following: number;
|
|
263
263
|
}>;
|
|
264
264
|
}, z.ZodTypeAny, "passthrough">>;
|
|
265
265
|
export type RecommendationItem = z.infer<typeof recommendationItemSchema>;
|
|
@@ -283,11 +283,11 @@ export declare const recommendationResponseSchema: z.ZodArray<z.ZodObject<{
|
|
|
283
283
|
followers: z.ZodNumber;
|
|
284
284
|
following: z.ZodNumber;
|
|
285
285
|
}, "strip", z.ZodTypeAny, {
|
|
286
|
-
following: number;
|
|
287
286
|
followers: number;
|
|
288
|
-
}, {
|
|
289
287
|
following: number;
|
|
288
|
+
}, {
|
|
290
289
|
followers: number;
|
|
290
|
+
following: number;
|
|
291
291
|
}>;
|
|
292
292
|
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
293
293
|
id: z.ZodString;
|
|
@@ -308,11 +308,11 @@ export declare const recommendationResponseSchema: z.ZodArray<z.ZodObject<{
|
|
|
308
308
|
followers: z.ZodNumber;
|
|
309
309
|
following: z.ZodNumber;
|
|
310
310
|
}, "strip", z.ZodTypeAny, {
|
|
311
|
-
following: number;
|
|
312
311
|
followers: number;
|
|
313
|
-
}, {
|
|
314
312
|
following: number;
|
|
313
|
+
}, {
|
|
315
314
|
followers: number;
|
|
315
|
+
following: number;
|
|
316
316
|
}>;
|
|
317
317
|
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
318
318
|
id: z.ZodString;
|
|
@@ -333,11 +333,11 @@ export declare const recommendationResponseSchema: z.ZodArray<z.ZodObject<{
|
|
|
333
333
|
followers: z.ZodNumber;
|
|
334
334
|
following: z.ZodNumber;
|
|
335
335
|
}, "strip", z.ZodTypeAny, {
|
|
336
|
-
following: number;
|
|
337
336
|
followers: number;
|
|
338
|
-
}, {
|
|
339
337
|
following: number;
|
|
338
|
+
}, {
|
|
340
339
|
followers: number;
|
|
340
|
+
following: number;
|
|
341
341
|
}>;
|
|
342
342
|
}, z.ZodTypeAny, "passthrough">>, "many">;
|
|
343
343
|
export type RecommendationResponse = z.infer<typeof recommendationResponseSchema>;
|