@nuwah/vertical-sdk 0.0.0-stage → 0.2.0-rc.1

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 (239) hide show
  1. package/LICENSE +17 -0
  2. package/README.md +229 -2
  3. package/bin/nuwah-contract-check-rules.d.mts +41 -0
  4. package/bin/nuwah-contract-check-rules.mjs +333 -0
  5. package/bin/nuwah-contract-check.mjs +64 -0
  6. package/dist/accounting.d.ts +1417 -0
  7. package/dist/accounting.js +274 -0
  8. package/dist/active-org.d.ts +13 -0
  9. package/dist/active-org.js +59 -0
  10. package/dist/actors.d.ts +448 -0
  11. package/dist/actors.js +143 -0
  12. package/dist/ai.d.ts +359 -0
  13. package/dist/ai.js +229 -0
  14. package/dist/analytics.d.ts +37 -0
  15. package/dist/analytics.js +8 -0
  16. package/dist/atlas.d.ts +291 -0
  17. package/dist/atlas.js +78 -0
  18. package/dist/audit.d.ts +193 -0
  19. package/dist/audit.js +26 -0
  20. package/dist/authentication.d.ts +119 -0
  21. package/dist/authentication.js +83 -0
  22. package/dist/awards.d.ts +38 -0
  23. package/dist/awards.js +10 -0
  24. package/dist/blueprint/document.d.ts +178 -0
  25. package/dist/blueprint/document.js +17 -0
  26. package/dist/blueprint/index.d.ts +3 -0
  27. package/dist/blueprint/index.js +5 -0
  28. package/dist/blueprint/manifest.d.ts +105 -0
  29. package/dist/blueprint/manifest.js +11 -0
  30. package/dist/blueprint/validate.d.ts +14 -0
  31. package/dist/blueprint/validate.js +416 -0
  32. package/dist/bookings-directory.d.ts +118 -0
  33. package/dist/bookings-directory.js +289 -0
  34. package/dist/bookings-extra.d.ts +1448 -0
  35. package/dist/bookings-extra.js +582 -0
  36. package/dist/bookings.d.ts +1365 -0
  37. package/dist/bookings.js +305 -0
  38. package/dist/builder-code.d.ts +164 -0
  39. package/dist/builder-code.js +12 -0
  40. package/dist/builder-core-gaps.d.ts +83 -0
  41. package/dist/builder-core-gaps.js +8 -0
  42. package/dist/builder-repos.d.ts +73 -0
  43. package/dist/builder-repos.js +37 -0
  44. package/dist/builder.d.ts +730 -0
  45. package/dist/builder.js +105 -0
  46. package/dist/campaigns.d.ts +105 -0
  47. package/dist/campaigns.js +25 -0
  48. package/dist/catalogs.d.ts +188 -0
  49. package/dist/catalogs.js +36 -0
  50. package/dist/commerce-ai.d.ts +182 -0
  51. package/dist/commerce-ai.js +27 -0
  52. package/dist/connections.d.ts +278 -0
  53. package/dist/connections.js +96 -0
  54. package/dist/content-control.d.ts +121 -0
  55. package/dist/content-control.js +23 -0
  56. package/dist/contributions.d.ts +560 -0
  57. package/dist/contributions.js +140 -0
  58. package/dist/conversation-assist.d.ts +154 -0
  59. package/dist/conversation-assist.js +51 -0
  60. package/dist/conversation-info.d.ts +219 -0
  61. package/dist/conversation-info.js +43 -0
  62. package/dist/crm.d.ts +533 -0
  63. package/dist/crm.js +142 -0
  64. package/dist/dashboards.d.ts +119 -0
  65. package/dist/dashboards.js +22 -0
  66. package/dist/delegations.d.ts +161 -0
  67. package/dist/delegations.js +39 -0
  68. package/dist/docs.d.ts +289 -0
  69. package/dist/docs.js +49 -0
  70. package/dist/documents.d.ts +317 -0
  71. package/dist/documents.js +84 -0
  72. package/dist/drafts.d.ts +132 -0
  73. package/dist/drafts.js +56 -0
  74. package/dist/engagements.d.ts +133 -0
  75. package/dist/engagements.js +15 -0
  76. package/dist/event-stream.d.ts +54 -0
  77. package/dist/event-stream.js +228 -0
  78. package/dist/exchanges.d.ts +447 -0
  79. package/dist/exchanges.js +145 -0
  80. package/dist/exports.d.ts +113 -0
  81. package/dist/exports.js +81 -0
  82. package/dist/feeds.d.ts +228 -0
  83. package/dist/feeds.js +52 -0
  84. package/dist/files.d.ts +56 -0
  85. package/dist/files.js +55 -0
  86. package/dist/finance-insights.d.ts +41 -0
  87. package/dist/finance-insights.js +61 -0
  88. package/dist/fixed-assets.d.ts +155 -0
  89. package/dist/fixed-assets.js +28 -0
  90. package/dist/fulfilment-jobs.d.ts +405 -0
  91. package/dist/fulfilment-jobs.js +76 -0
  92. package/dist/fulfilment.d.ts +205 -0
  93. package/dist/fulfilment.js +39 -0
  94. package/dist/hr.d.ts +350 -0
  95. package/dist/hr.js +94 -0
  96. package/dist/http.d.ts +124 -0
  97. package/dist/http.js +392 -0
  98. package/dist/inbox.d.ts +206 -0
  99. package/dist/inbox.js +36 -0
  100. package/dist/index.d.ts +384 -0
  101. package/dist/index.js +294 -0
  102. package/dist/insights.d.ts +176 -0
  103. package/dist/insights.js +52 -0
  104. package/dist/inventory.d.ts +797 -0
  105. package/dist/inventory.js +120 -0
  106. package/dist/list-query.d.ts +211 -0
  107. package/dist/list-query.js +158 -0
  108. package/dist/listings.d.ts +381 -0
  109. package/dist/listings.js +173 -0
  110. package/dist/location-sharing.d.ts +83 -0
  111. package/dist/location-sharing.js +20 -0
  112. package/dist/marketplace.d.ts +268 -0
  113. package/dist/marketplace.js +59 -0
  114. package/dist/matching.d.ts +103 -0
  115. package/dist/matching.js +22 -0
  116. package/dist/media.d.ts +221 -0
  117. package/dist/media.js +239 -0
  118. package/dist/metrics.d.ts +125 -0
  119. package/dist/metrics.js +45 -0
  120. package/dist/moderation.d.ts +240 -0
  121. package/dist/moderation.js +40 -0
  122. package/dist/money.d.ts +41 -0
  123. package/dist/money.js +79 -0
  124. package/dist/my-data.d.ts +266 -0
  125. package/dist/my-data.js +32 -0
  126. package/dist/names.d.ts +14 -0
  127. package/dist/names.js +17 -0
  128. package/dist/occasions.d.ts +256 -0
  129. package/dist/occasions.js +40 -0
  130. package/dist/onboarding.d.ts +88 -0
  131. package/dist/onboarding.js +38 -0
  132. package/dist/pagination.d.ts +204 -0
  133. package/dist/pagination.js +141 -0
  134. package/dist/party-baseline-attributes.d.ts +245 -0
  135. package/dist/party-baseline-attributes.js +36 -0
  136. package/dist/party.d.ts +401 -0
  137. package/dist/party.js +56 -0
  138. package/dist/patient.d.ts +161 -0
  139. package/dist/patient.js +45 -0
  140. package/dist/payroll.d.ts +378 -0
  141. package/dist/payroll.js +60 -0
  142. package/dist/person-addresses.d.ts +88 -0
  143. package/dist/person-addresses.js +18 -0
  144. package/dist/person-cart.d.ts +250 -0
  145. package/dist/person-cart.js +63 -0
  146. package/dist/person-chat-assist.d.ts +47 -0
  147. package/dist/person-chat-assist.js +13 -0
  148. package/dist/person-data-webhooks.d.ts +72 -0
  149. package/dist/person-data-webhooks.js +86 -0
  150. package/dist/person-data.d.ts +212 -0
  151. package/dist/person-data.js +162 -0
  152. package/dist/person-locations.d.ts +54 -0
  153. package/dist/person-locations.js +6 -0
  154. package/dist/person-messaging.d.ts +405 -0
  155. package/dist/person-messaging.js +112 -0
  156. package/dist/person-notifications.d.ts +319 -0
  157. package/dist/person-notifications.js +164 -0
  158. package/dist/personalisation.d.ts +21 -0
  159. package/dist/personalisation.js +8 -0
  160. package/dist/platform.d.ts +63 -0
  161. package/dist/platform.js +45 -0
  162. package/dist/portfolio.d.ts +163 -0
  163. package/dist/portfolio.js +28 -0
  164. package/dist/pos.d.ts +743 -0
  165. package/dist/pos.js +129 -0
  166. package/dist/procurement.d.ts +664 -0
  167. package/dist/procurement.js +157 -0
  168. package/dist/promotions.d.ts +169 -0
  169. package/dist/promotions.js +39 -0
  170. package/dist/publications.d.ts +583 -0
  171. package/dist/publications.js +164 -0
  172. package/dist/ranking.d.ts +43 -0
  173. package/dist/ranking.js +34 -0
  174. package/dist/ratings.d.ts +293 -0
  175. package/dist/ratings.js +109 -0
  176. package/dist/reactions.d.ts +123 -0
  177. package/dist/reactions.js +41 -0
  178. package/dist/recipient-orders.d.ts +294 -0
  179. package/dist/recipient-orders.js +73 -0
  180. package/dist/relationships.d.ts +18 -0
  181. package/dist/relationships.js +8 -0
  182. package/dist/reporting.d.ts +107 -0
  183. package/dist/reporting.js +56 -0
  184. package/dist/sales.d.ts +270 -0
  185. package/dist/sales.js +66 -0
  186. package/dist/shares.d.ts +105 -0
  187. package/dist/shares.js +27 -0
  188. package/dist/shop.d.ts +993 -0
  189. package/dist/shop.js +215 -0
  190. package/dist/shopping-assistant.d.ts +65 -0
  191. package/dist/shopping-assistant.js +14 -0
  192. package/dist/spaces.d.ts +422 -0
  193. package/dist/spaces.js +118 -0
  194. package/dist/stored-value.d.ts +754 -0
  195. package/dist/stored-value.js +177 -0
  196. package/dist/types.d.ts +83 -0
  197. package/dist/types.js +2 -0
  198. package/dist/vault.d.ts +290 -0
  199. package/dist/vault.js +55 -0
  200. package/dist/vertical-runtime.d.ts +17 -0
  201. package/dist/vertical-runtime.js +8 -0
  202. package/dist/vite/build-manifest-plugin.d.ts +42 -0
  203. package/dist/vite/build-manifest-plugin.js +42 -0
  204. package/dist/vite/first-paint-plugin.d.ts +26 -0
  205. package/dist/vite/first-paint-plugin.js +57 -0
  206. package/dist/wishlists.d.ts +591 -0
  207. package/dist/wishlists.js +188 -0
  208. package/dist/workbench.d.ts +114 -0
  209. package/dist/workbench.js +22 -0
  210. package/dist/workspace.d.ts +190 -0
  211. package/dist/workspace.js +41 -0
  212. package/package.json +52 -4
  213. package/templates/extension-image.Dockerfile +38 -0
  214. package/templates/nuwah-vertical.yml +102 -0
  215. package/templates/vertical-app/.env.example +34 -0
  216. package/templates/vertical-app/README.md +108 -0
  217. package/templates/vertical-app/github/workflows/ci.yml +51 -0
  218. package/templates/vertical-app/gitignore +5 -0
  219. package/templates/vertical-app/index.html +12 -0
  220. package/templates/vertical-app/package.json +28 -0
  221. package/templates/vertical-app/src/App.tsx +64 -0
  222. package/templates/vertical-app/src/blueprint/blueprint.ts +45 -0
  223. package/templates/vertical-app/src/blueprint/screens.ts +15 -0
  224. package/templates/vertical-app/src/env.d.ts +18 -0
  225. package/templates/vertical-app/src/index.css +139 -0
  226. package/templates/vertical-app/src/lib/i18n.ts +5 -0
  227. package/templates/vertical-app/src/lib/iam.ts +19 -0
  228. package/templates/vertical-app/src/lib/operations.ts +93 -0
  229. package/templates/vertical-app/src/lib/router.ts +24 -0
  230. package/templates/vertical-app/src/lib/sdk.ts +21 -0
  231. package/templates/vertical-app/src/lib/theme.ts +18 -0
  232. package/templates/vertical-app/src/lib/words.ts +39 -0
  233. package/templates/vertical-app/src/main.tsx +25 -0
  234. package/templates/vertical-app/src/pages/AppScreens.tsx +71 -0
  235. package/templates/vertical-app/src/pages/AuthCallback.tsx +44 -0
  236. package/templates/vertical-app/src/pages/Home.tsx +36 -0
  237. package/templates/vertical-app/tsconfig.json +24 -0
  238. package/templates/vertical-app/vite.config.ts +23 -0
  239. package/templates/vertical-ci.yml +192 -0
@@ -0,0 +1,422 @@
1
+ /**
2
+ * Spaces — `/api/person/spaces/*`: communities owned by a person or a profile.
3
+ *
4
+ * One product-neutral mechanism — space, member, role, join rule — that a product names in its
5
+ * own words ("group", "channel", "club", "cohort"). Core declares two kinds, `community` and
6
+ * `broadcast`; a vertical declares its own (`<vertical>.<name>`); `kinds()` lists what may be
7
+ * created and which choices each kind allows.
8
+ *
9
+ * Every space the acting party may not see answers 404 `not_found` — unknown, hidden, suspended
10
+ * and banned-from alike. A client must not tell those apart either. Every list is a cursor page
11
+ * (`{data, next_cursor}`): follow `next_cursor`, never count. `member_count` is folded
12
+ * asynchronously and may trail a join by a few seconds.
13
+ *
14
+ * Spaces never holds posts: publish into a space through `publications` with the audience
15
+ * `spaces.space` and the space id; `feed()` returns pointers to render through the owning module.
16
+ *
17
+ * Act through a profile with `actingAs` (see `actors.ts`); writes carry an `Idempotency-Key`.
18
+ */
19
+ import type { Http } from './http.js';
20
+ import { type BilingualText, type PartyReference, type PersonDomainCallOptions, type PersonDomainCursorPage, type PersonDomainEnvelope } from './actors.js';
21
+ import type { MediaAsset } from './media.js';
22
+ import type { ModerationReasonKey, ModerationReportReceipt } from './moderation.js';
23
+ /**
24
+ * A space's avatar or cover, from the Media pipeline: the `<picture>`-ready subset of a media
25
+ * asset, with the same key names, so the media components draw it unchanged.
26
+ */
27
+ export type SpacePicture = Pick<MediaAsset, 'id' | 'alt_text' | 'placeholder' | 'sources'>;
28
+ /** The Media purpose to upload each slot under, before `setImage`. */
29
+ export declare const SPACE_PICTURE_PURPOSES: {
30
+ readonly avatar: "spaces.avatar";
31
+ readonly cover: "spaces.cover";
32
+ };
33
+ export type SpaceVisibility = 'public' | 'listed' | 'hidden';
34
+ export type SpaceJoinRule = 'open' | 'approval' | 'questions' | 'invitation';
35
+ export type SpacePostingRule = 'members' | 'approved_members' | 'administrators';
36
+ export type SpaceRole = 'owner' | 'administrator' | 'moderator' | 'member';
37
+ export type SpaceMembershipState = 'active' | 'left' | 'removed';
38
+ export type SpaceJoinRequestState = 'pending' | 'approved' | 'declined' | 'withdrawn' | 'expired';
39
+ export type SpaceInvitationState = 'pending' | 'accepted' | 'declined' | 'revoked' | 'expired';
40
+ export type SpaceSanctionKind = 'ban' | 'mute';
41
+ export type SpaceSanctionDuration = '1_hour' | '1_day' | '7_days' | '30_days' | 'until_lifted';
42
+ export type SpaceSanctionReason = 'spam' | 'harassment' | 'off_topic' | 'rule_violation' | 'impersonation' | 'other';
43
+ export type SpaceContentReviewState = 'pending' | 'approved' | 'rejected' | 'withdrawn';
44
+ export type SpaceDirectorySort = 'members' | 'activity' | 'newest';
45
+ export type SpaceMemberSort = 'newest' | 'oldest' | 'role';
46
+ export type SpaceImageSlot = 'avatar' | 'cover';
47
+ /** The roles in rank order, highest first — what a role menu offers below the viewer's own. */
48
+ export declare const SPACE_ROLES_BY_RANK: readonly SpaceRole[];
49
+ /** Up to five questions; at most 300 characters each, answers at most 1000. */
50
+ export interface SpaceJoinQuestion {
51
+ id: string;
52
+ text: string;
53
+ required: boolean;
54
+ }
55
+ /** The viewer's own standing in a space; null when nobody is signed in. */
56
+ export interface SpaceStanding {
57
+ space_id: string;
58
+ is_member: boolean;
59
+ role: SpaceRole | null;
60
+ pending_request_id: string | null;
61
+ pending_invitation_id: string | null;
62
+ banned: boolean;
63
+ muted: boolean;
64
+ muted_until: string | null;
65
+ posting_trusted: boolean;
66
+ /** The space capabilities the viewer holds (`spaces.members.invite`, …). */
67
+ capabilities: string[];
68
+ }
69
+ export interface Space {
70
+ id: string;
71
+ type: 'spaces.space';
72
+ handle: string | null;
73
+ names: BilingualText;
74
+ description: string | null;
75
+ rules: string | null;
76
+ kind: string;
77
+ visibility: SpaceVisibility;
78
+ join_rule: SpaceJoinRule;
79
+ posting_rule: SpacePostingRule;
80
+ join_questions: SpaceJoinQuestion[];
81
+ tags: string[];
82
+ member_count: number;
83
+ owner: PartyReference;
84
+ /** The owner's name and picture as this viewer may see them; null when not shown (additive in v1). */
85
+ owner_summary?: SpacePartySummary | null;
86
+ /** One plain URL for a single `<img>`; prefer `avatar` / `cover` for `<picture>`. */
87
+ avatar_url: string | null;
88
+ cover_url: string | null;
89
+ avatar: SpacePicture | null;
90
+ cover: SpacePicture | null;
91
+ /** Send back as `expected_version` on an edit; a stale one answers 409 `version_conflict`. */
92
+ version: number;
93
+ created_at: string;
94
+ last_activity_at: string | null;
95
+ viewer: SpaceStanding | null;
96
+ }
97
+ export interface SpaceKind {
98
+ key: string;
99
+ label: BilingualText;
100
+ default_visibility: SpaceVisibility;
101
+ default_join_rule: SpaceJoinRule;
102
+ default_posting_rule: SpacePostingRule;
103
+ allowed_visibilities: SpaceVisibility[];
104
+ allowed_join_rules: SpaceJoinRule[];
105
+ allowed_posting_rules: SpacePostingRule[];
106
+ persons_may_own: boolean;
107
+ }
108
+ /**
109
+ * How a party is shown beside a row — the same shape on every spaces row (`party` on a member,
110
+ * `*_summary` on requests, invitations, sanctions and decisions). Null when the viewer may not see
111
+ * who it is (a bare person is described only to themselves): show a placeholder.
112
+ */
113
+ export interface SpacePartySummary {
114
+ handle: string | null;
115
+ display_name: BilingualText;
116
+ avatar_url: string | null;
117
+ verified: boolean;
118
+ }
119
+ /** A compact space, embedded in the rows that point at one (an invitation). */
120
+ export interface SpaceSummary {
121
+ id: string;
122
+ handle: string | null;
123
+ names: BilingualText;
124
+ kind: string;
125
+ visibility: SpaceVisibility;
126
+ member_count: number;
127
+ avatar_url: string | null;
128
+ }
129
+ /** One row of a member list; `party` is null when the viewer may not see who it is. */
130
+ export interface SpaceMember {
131
+ id: string;
132
+ member: PartyReference;
133
+ role: SpaceRole;
134
+ posting_trusted: boolean;
135
+ joined_at: string;
136
+ party: SpacePartySummary | null;
137
+ }
138
+ export interface SpaceMembership {
139
+ id: string;
140
+ space_id: string;
141
+ member: PartyReference;
142
+ role: SpaceRole;
143
+ state: SpaceMembershipState;
144
+ source: string;
145
+ posting_trusted: boolean;
146
+ joined_at: string;
147
+ ended_at: string | null;
148
+ }
149
+ export interface SpaceJoinRequest {
150
+ id: string;
151
+ space_id: string;
152
+ requester: PartyReference;
153
+ requester_summary?: SpacePartySummary | null;
154
+ state: SpaceJoinRequestState;
155
+ answers: Array<{
156
+ question_id: string;
157
+ answer: string;
158
+ }>;
159
+ created_at: string;
160
+ decided_at: string | null;
161
+ expires_at: string | null;
162
+ }
163
+ export interface SpaceInvitation {
164
+ id: string;
165
+ space_id: string;
166
+ /** The space it is for — on the invitee's own list and answers; null elsewhere or when unknowable. */
167
+ space?: SpaceSummary | null;
168
+ invitee: PartyReference;
169
+ invitee_summary?: SpacePartySummary | null;
170
+ inviter: PartyReference;
171
+ inviter_summary?: SpacePartySummary | null;
172
+ state: SpaceInvitationState;
173
+ created_at: string;
174
+ decided_at: string | null;
175
+ expires_at: string | null;
176
+ }
177
+ export interface SpaceSanction {
178
+ id: string;
179
+ space_id: string;
180
+ party: PartyReference;
181
+ party_summary?: SpacePartySummary | null;
182
+ kind: SpaceSanctionKind;
183
+ reason: string;
184
+ expires_at: string | null;
185
+ lifted_at: string | null;
186
+ in_force: boolean;
187
+ created_at: string;
188
+ }
189
+ /** An item waiting in the pending-posts queue: a pointer to render through its owning module. */
190
+ export interface SpaceContentReview {
191
+ id: string;
192
+ space_id: string;
193
+ subject_type: string;
194
+ subject_id: string;
195
+ author: PartyReference;
196
+ state: SpaceContentReviewState;
197
+ created_at: string;
198
+ decided_at: string | null;
199
+ }
200
+ export interface SpaceModerationDecision {
201
+ id: string;
202
+ action: string;
203
+ target: PartyReference | null;
204
+ target_summary?: SpacePartySummary | null;
205
+ subject: {
206
+ type: string;
207
+ id: string;
208
+ } | null;
209
+ /** The party the moderator acted as, or `{kind: 'operator'}`; the person is never named. */
210
+ decided_by: PartyReference | {
211
+ kind: 'operator';
212
+ } | null;
213
+ /** Null for an operator, or when the viewer may not see the party. */
214
+ decided_by_summary?: SpacePartySummary | null;
215
+ reason: string | null;
216
+ created_at: string;
217
+ }
218
+ export interface SpacePost {
219
+ id: string;
220
+ subject_type: string;
221
+ space_id: string;
222
+ author: PartyReference;
223
+ published_at: string;
224
+ }
225
+ export interface SpaceFeedPage {
226
+ data: SpacePost[];
227
+ /** Pass as `before` for the next page; null at the end. */
228
+ next_before: string | null;
229
+ }
230
+ export interface SpaceInput {
231
+ names?: BilingualText;
232
+ handle?: string | null;
233
+ description?: string | null;
234
+ rules?: string | null;
235
+ visibility?: SpaceVisibility;
236
+ join_rule?: SpaceJoinRule;
237
+ posting_rule?: SpacePostingRule;
238
+ /** `id` is optional on create; the server assigns one. */
239
+ join_questions?: Array<{
240
+ id?: string;
241
+ text: string;
242
+ required?: boolean;
243
+ }>;
244
+ tags?: string[];
245
+ attributes?: Record<string, unknown>;
246
+ }
247
+ export interface SpaceDirectoryQuery {
248
+ /** Matched against names (Arabic folded: diacritics and letter forms ignored), handle and tags. */
249
+ q?: string;
250
+ kind?: string;
251
+ tag?: string;
252
+ sort?: SpaceDirectorySort;
253
+ cursor?: string | null;
254
+ limit?: number;
255
+ }
256
+ export interface SpaceMemberQuery {
257
+ q?: string;
258
+ role?: SpaceRole;
259
+ sort?: SpaceMemberSort;
260
+ cursor?: string | null;
261
+ limit?: number;
262
+ }
263
+ export interface SpacePageQuery {
264
+ cursor?: string | null;
265
+ limit?: number;
266
+ }
267
+ /** A declared list's query (the platform ListQuery): `filter[key]=…`, `sort=-key`, `describe`. */
268
+ export interface SpaceDeclaredListQuery<TSort extends string, TFilter extends string> extends SpacePageQuery {
269
+ sort?: TSort | `-${TSort}`;
270
+ filter?: Partial<Record<TFilter, string>>;
271
+ /** Ask once, on the first page, for `meta.list` (sorts, filters, labels). */
272
+ describe?: boolean;
273
+ }
274
+ /** `moderation.queue` — pending by default; `filter.state` opens the decided history. */
275
+ export type SpaceContentReviewQuery = SpaceDeclaredListQuery<'submitted_at', 'state' | 'author' | 'subject_type'>;
276
+ /** `invitations.sent` — pending by default (what can still be revoked). */
277
+ export type SpaceSentInvitationQuery = SpaceDeclaredListQuery<'invited_at', 'state' | 'invitee' | 'inviter'>;
278
+ /** A declared list's page: `meta.query` always, `meta.list` when `describe` was sent. */
279
+ export type SpaceDeclaredPage<T> = PersonDomainCursorPage<T> & {
280
+ meta?: {
281
+ query: Record<string, unknown>;
282
+ list?: Record<string, unknown>;
283
+ };
284
+ };
285
+ export interface SpaceSanctionInput {
286
+ party: PartyReference;
287
+ kind: SpaceSanctionKind;
288
+ reason: SpaceSanctionReason;
289
+ duration: SpaceSanctionDuration;
290
+ }
291
+ export interface SpaceReportInput {
292
+ /** Omit both to report the space itself. */
293
+ subject_type?: string;
294
+ subject_id?: string;
295
+ /** One of the platform's moderation reasons — the same list everywhere. */
296
+ reason: ModerationReasonKey;
297
+ notes?: string | null;
298
+ }
299
+ /** Outcome of a write that may already have happened: `created` false = the same call again. */
300
+ export type SpaceWriteOutcome<T> = PersonDomainEnvelope<T> & {
301
+ created: boolean;
302
+ };
303
+ /** `requests.ask` answers a membership when the space admitted at once, else the request. */
304
+ export type SpaceAskOutcome = (PersonDomainEnvelope<SpaceMembership> & {
305
+ created: boolean;
306
+ joined: true;
307
+ }) | (PersonDomainEnvelope<SpaceJoinRequest> & {
308
+ created: boolean;
309
+ joined: false;
310
+ });
311
+ export declare function createSpacesNamespace(http: Http): {
312
+ /** GET /kinds — what may be created, with each kind's defaults and allowed choices. */
313
+ kinds: (options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<SpaceKind[]>>;
314
+ /** GET /directory — public and listed spaces only; hidden spaces are never found. */
315
+ directory: (query?: SpaceDirectoryQuery, options?: PersonDomainCallOptions) => Promise<PersonDomainCursorPage<Space>>;
316
+ /** GET /mine — the acting party's spaces, newest membership first. */
317
+ mine: (query?: SpacePageQuery, options?: PersonDomainCallOptions) => Promise<PersonDomainCursorPage<Space>>;
318
+ /** GET /{space} */
319
+ get: (spaceId: string, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<Space>>;
320
+ /**
321
+ * GET /by-handle/{handle} — the same answer as `get`, by handle: a hidden space only to its
322
+ * members and invitees; ONE 404 for unknown, malformed, closed and not-yours alike.
323
+ */
324
+ byHandle: (handle: string, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<Space>>;
325
+ /** POST / — owned by the acting party (a profile needs `spaces.own`). */
326
+ create: (kind: string, input: SpaceInput & {
327
+ names: BilingualText;
328
+ }, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<Space>>;
329
+ /** PATCH /{space} — only the fields sent change. */
330
+ update: (spaceId: string, changes: SpaceInput, expectedVersion?: number, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<Space>>;
331
+ /**
332
+ * POST /{space}/images/{slot} `{media_id}` — attach a picture uploaded first through
333
+ * `media.upload(file, { purpose: SPACE_PICTURE_PURPOSES[slot] })`. Replacing the avatar
334
+ * never touches the cover. Refusals from Media (not yours, not ready) pass through.
335
+ */
336
+ setImage: (spaceId: string, slot: SpaceImageSlot, mediaId: string, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<Space>>;
337
+ removeImage: (spaceId: string, slot: SpaceImageSlot, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<Space>>;
338
+ /** DELETE /{space} — the owner closes it; memberships, requests and invitations end. */
339
+ close: (spaceId: string, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<{
340
+ closed: boolean;
341
+ }>>;
342
+ /** POST /{space}/owner — the owner hands the space to a current member and becomes an administrator. */
343
+ transfer: (spaceId: string, successor: PartyReference, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<Space>>;
344
+ /** POST /{space}/join — join an open space, or accept the invitation the party holds. */
345
+ join: (spaceId: string, options?: PersonDomainCallOptions) => Promise<SpaceWriteOutcome<SpaceMembership>>;
346
+ /** POST /{space}/leave — the owner must `transfer` first (409 `owner_must_transfer`). */
347
+ leave: (spaceId: string, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<{
348
+ left: boolean;
349
+ }>>;
350
+ /** GET /{space}/feed — pointers, newest first; page with `before`. */
351
+ feed: (spaceId: string, query?: {
352
+ before?: string | null;
353
+ limit?: number;
354
+ }, options?: PersonDomainCallOptions) => Promise<SpaceFeedPage>;
355
+ /** GET /feed — across the acting party's spaces. */
356
+ myFeed: (query?: {
357
+ before?: string | null;
358
+ limit?: number;
359
+ }, options?: PersonDomainCallOptions) => Promise<SpaceFeedPage>;
360
+ /**
361
+ * POST /{space}/reports — any reader; filed into the platform's one report intake. Cases on
362
+ * what the space hosts are decided by its moderators in `moderation.queue({ host: 'space:<id>' })`;
363
+ * cases on the space itself by the platform's operators.
364
+ */
365
+ report: (spaceId: string, input: SpaceReportInput, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<ModerationReportReceipt>>;
366
+ members: {
367
+ /** GET /{space}/members — members only unless the product opens the list. */
368
+ list: (spaceId: string, query?: SpaceMemberQuery, options?: PersonDomainCallOptions) => Promise<PersonDomainCursorPage<SpaceMember>>;
369
+ /** PUT role — only to a role below the viewer's own (403 `outranked` otherwise). */
370
+ setRole: (spaceId: string, membershipId: string, role: SpaceRole, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<SpaceMembership>>;
371
+ /** PUT posting-trust — under `approved_members`, this member's posts skip the queue. */
372
+ setPostingTrust: (spaceId: string, membershipId: string, trusted: boolean, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<SpaceMembership>>;
373
+ remove: (spaceId: string, membershipId: string, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<{
374
+ removed: boolean;
375
+ }>>;
376
+ };
377
+ requests: {
378
+ /** POST /{space}/requests — answers keyed by question id. */
379
+ ask: (spaceId: string, answers?: Record<string, string>, options?: PersonDomainCallOptions) => Promise<SpaceAskOutcome>;
380
+ /** GET /{space}/requests — pending, oldest first (holders of `spaces.members.review_requests`). */
381
+ pending: (spaceId: string, query?: SpacePageQuery, options?: PersonDomainCallOptions) => Promise<PersonDomainCursorPage<SpaceJoinRequest>>;
382
+ get: (spaceId: string, requestId: string, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<SpaceJoinRequest>>;
383
+ approve: (spaceId: string, requestId: string, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<SpaceJoinRequest>>;
384
+ decline: (spaceId: string, requestId: string, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<SpaceJoinRequest>>;
385
+ withdraw: (spaceId: string, requestId: string, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<{
386
+ withdrawn: boolean;
387
+ }>>;
388
+ };
389
+ invitations: {
390
+ /** GET /invitations — the acting party's pending invitations, newest first, each with its `space`. */
391
+ mine: (query?: SpacePageQuery, options?: PersonDomainCallOptions) => Promise<PersonDomainCursorPage<SpaceInvitation>>;
392
+ /** GET /{space}/invitations — what the space sent (holders of `spaces.members.invite`); pending by default. */
393
+ sent: (spaceId: string, query?: SpaceSentInvitationQuery, options?: PersonDomainCallOptions) => Promise<SpaceDeclaredPage<SpaceInvitation>>;
394
+ send: (spaceId: string, invitee: PartyReference, options?: PersonDomainCallOptions) => Promise<SpaceWriteOutcome<SpaceInvitation>>;
395
+ revoke: (spaceId: string, invitationId: string, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<{
396
+ revoked: boolean;
397
+ }>>;
398
+ accept: (invitationId: string, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<SpaceInvitation>>;
399
+ decline: (invitationId: string, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<SpaceInvitation>>;
400
+ };
401
+ moderation: {
402
+ /** GET /{space}/moderation/queue — held posts, oldest first; `filter.state` for the history. */
403
+ queue: (spaceId: string, query?: SpaceContentReviewQuery, options?: PersonDomainCallOptions) => Promise<SpaceDeclaredPage<SpaceContentReview>>;
404
+ approve: (spaceId: string, reviewId: string, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<SpaceContentReview>>;
405
+ reject: (spaceId: string, reviewId: string, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<SpaceContentReview>>;
406
+ sanctions: (spaceId: string, query?: SpacePageQuery, options?: PersonDomainCallOptions) => Promise<PersonDomainCursorPage<SpaceSanction>>;
407
+ sanction: (spaceId: string, input: SpaceSanctionInput, options?: PersonDomainCallOptions) => Promise<SpaceWriteOutcome<SpaceSanction>>;
408
+ lift: (spaceId: string, sanctionId: string, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<{
409
+ lifted: boolean;
410
+ }>>;
411
+ /** GET /{space}/moderation/log — the append-only decision record, newest first. */
412
+ log: (spaceId: string, query?: SpacePageQuery, options?: PersonDomainCallOptions) => Promise<PersonDomainCursorPage<SpaceModerationDecision>>;
413
+ };
414
+ };
415
+ export type SpacesNamespace = ReturnType<typeof createSpacesNamespace>;
416
+ /** Whether the viewer may do `capability` in this space, from the standing the server sent. */
417
+ export declare function spaceStandingHolds(standing: SpaceStanding | null | undefined, capability: string): boolean;
418
+ /**
419
+ * The roles the viewer may give: strictly below their own. An owner gives administrator and
420
+ * below; nobody gives `owner` (that is `transfer`).
421
+ */
422
+ export declare function spaceRolesAssignableBy(viewerRole: SpaceRole | null | undefined): SpaceRole[];
package/dist/spaces.js ADDED
@@ -0,0 +1,118 @@
1
+ import { personDomainRequest, } from './actors.js';
2
+
3
+ export const SPACE_PICTURE_PURPOSES = { avatar: 'spaces.avatar', cover: 'spaces.cover' };
4
+
5
+ export const SPACE_ROLES_BY_RANK = ['owner', 'administrator', 'moderator', 'member'];
6
+ const BASE = '/api/person/spaces';
7
+ const page = (query = {}) => ({ cursor: query.cursor ?? undefined, limit: query.limit });
8
+
9
+ const declared = (query = {}) => {
10
+ const params = {
11
+ ...page(query),
12
+ sort: query.sort,
13
+ describe: query.describe ? 1 : undefined,
14
+ };
15
+ for (const [key, value] of Object.entries(query.filter ?? {})) {
16
+ if (value !== undefined && value !== '') {
17
+ params[`filter[${key}]`] = value;
18
+ }
19
+ }
20
+ return params;
21
+ };
22
+ export function createSpacesNamespace(http) {
23
+ const read = (options, params) => personDomainRequest(options, false, params);
24
+ const write = (options) => personDomainRequest(options, true);
25
+ const space = (spaceId) => `${BASE}/${encodeURIComponent(spaceId)}`;
26
+ return {
27
+
28
+ kinds: (options) => http.get(`${BASE}/kinds`, read(options)),
29
+
30
+ directory: (query = {}, options) => http.get(`${BASE}/directory`, read(options, {
31
+ q: query.q?.trim() || undefined,
32
+ kind: query.kind,
33
+ tag: query.tag,
34
+ sort: query.sort,
35
+ ...page(query),
36
+ })),
37
+
38
+ mine: (query, options) => http.get(`${BASE}/mine`, read(options, page(query))),
39
+
40
+ get: (spaceId, options) => http.get(space(spaceId), read(options)),
41
+
42
+ byHandle: (handle, options) => http.get(`${BASE}/by-handle/${encodeURIComponent(handle.trim().replace(/^@/, ''))}`, read(options)),
43
+
44
+ create: (kind, input, options) => http.post(`${BASE}`, { kind, ...input }, write(options)),
45
+
46
+ update: (spaceId, changes, expectedVersion, options) => http.patch(space(spaceId), expectedVersion === undefined ? changes : { ...changes, expected_version: expectedVersion }, write(options)),
47
+
48
+ setImage: (spaceId, slot, mediaId, options) => http.post(`${space(spaceId)}/images/${slot}`, { media_id: mediaId }, write(options)),
49
+ removeImage: (spaceId, slot, options) => http.delete(`${space(spaceId)}/images/${slot}`, write(options)),
50
+
51
+ close: (spaceId, options) => http.delete(space(spaceId), write(options)),
52
+
53
+ transfer: (spaceId, successor, options) => http.post(`${space(spaceId)}/owner`, { party: successor }, write(options)),
54
+
55
+ join: (spaceId, options) => http.post(`${space(spaceId)}/join`, undefined, write(options)),
56
+
57
+ leave: (spaceId, options) => http.post(`${space(spaceId)}/leave`, undefined, write(options)),
58
+
59
+ feed: (spaceId, query = {}, options) => http.get(`${space(spaceId)}/feed`, read(options, { before: query.before ?? undefined, limit: query.limit })),
60
+
61
+ myFeed: (query = {}, options) => http.get(`${BASE}/feed`, read(options, { before: query.before ?? undefined, limit: query.limit })),
62
+
63
+ report: (spaceId, input, options) => http.post(`${space(spaceId)}/reports`, input, write(options)),
64
+ members: {
65
+
66
+ list: (spaceId, query = {}, options) => http.get(`${space(spaceId)}/members`, read(options, {
67
+ q: query.q?.trim() || undefined, role: query.role, sort: query.sort, ...page(query),
68
+ })),
69
+
70
+ setRole: (spaceId, membershipId, role, options) => http.put(`${space(spaceId)}/members/${membershipId}/role`, { role }, write(options)),
71
+
72
+ setPostingTrust: (spaceId, membershipId, trusted, options) => http.put(`${space(spaceId)}/members/${membershipId}/posting-trust`, { trusted }, write(options)),
73
+ remove: (spaceId, membershipId, options) => http.delete(`${space(spaceId)}/members/${membershipId}`, write(options)),
74
+ },
75
+ requests: {
76
+
77
+ ask: (spaceId, answers = {}, options) => http.post(`${space(spaceId)}/requests`, { answers }, write(options)),
78
+
79
+ pending: (spaceId, query, options) => http.get(`${space(spaceId)}/requests`, read(options, page(query))),
80
+ get: (spaceId, requestId, options) => http.get(`${space(spaceId)}/requests/${requestId}`, read(options)),
81
+ approve: (spaceId, requestId, options) => http.post(`${space(spaceId)}/requests/${requestId}/approve`, undefined, write(options)),
82
+ decline: (spaceId, requestId, options) => http.post(`${space(spaceId)}/requests/${requestId}/decline`, undefined, write(options)),
83
+ withdraw: (spaceId, requestId, options) => http.post(`${space(spaceId)}/requests/${requestId}/withdraw`, undefined, write(options)),
84
+ },
85
+ invitations: {
86
+
87
+ mine: (query, options) => http.get(`${BASE}/invitations`, read(options, page(query))),
88
+
89
+ sent: (spaceId, query, options) => http.get(`${space(spaceId)}/invitations`, read(options, declared(query))),
90
+ send: (spaceId, invitee, options) => http.post(`${space(spaceId)}/invitations`, { party: invitee }, write(options)),
91
+ revoke: (spaceId, invitationId, options) => http.delete(`${space(spaceId)}/invitations/${invitationId}`, write(options)),
92
+ accept: (invitationId, options) => http.post(`${BASE}/invitations/${invitationId}/accept`, undefined, write(options)),
93
+ decline: (invitationId, options) => http.post(`${BASE}/invitations/${invitationId}/decline`, undefined, write(options)),
94
+ },
95
+ moderation: {
96
+
97
+ queue: (spaceId, query, options) => http.get(`${space(spaceId)}/moderation/queue`, read(options, declared(query))),
98
+ approve: (spaceId, reviewId, options) => http.post(`${space(spaceId)}/moderation/queue/${reviewId}/approve`, undefined, write(options)),
99
+ reject: (spaceId, reviewId, options) => http.post(`${space(spaceId)}/moderation/queue/${reviewId}/reject`, undefined, write(options)),
100
+ sanctions: (spaceId, query, options) => http.get(`${space(spaceId)}/moderation/sanctions`, read(options, page(query))),
101
+ sanction: (spaceId, input, options) => http.post(`${space(spaceId)}/moderation/sanctions`, input, write(options)),
102
+ lift: (spaceId, sanctionId, options) => http.delete(`${space(spaceId)}/moderation/sanctions/${sanctionId}`, write(options)),
103
+
104
+ log: (spaceId, query, options) => http.get(`${space(spaceId)}/moderation/log`, read(options, page(query))),
105
+ },
106
+ };
107
+ }
108
+
109
+ export function spaceStandingHolds(standing, capability) {
110
+ return standing?.capabilities.includes(capability) ?? false;
111
+ }
112
+
113
+ export function spaceRolesAssignableBy(viewerRole) {
114
+ if (!viewerRole)
115
+ return [];
116
+ const rank = SPACE_ROLES_BY_RANK.indexOf(viewerRole);
117
+ return SPACE_ROLES_BY_RANK.filter((role, index) => index > rank && role !== 'owner');
118
+ }