@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.
- package/LICENSE +17 -0
- package/README.md +229 -2
- package/bin/nuwah-contract-check-rules.d.mts +41 -0
- package/bin/nuwah-contract-check-rules.mjs +333 -0
- package/bin/nuwah-contract-check.mjs +64 -0
- package/dist/accounting.d.ts +1417 -0
- package/dist/accounting.js +274 -0
- package/dist/active-org.d.ts +13 -0
- package/dist/active-org.js +59 -0
- package/dist/actors.d.ts +448 -0
- package/dist/actors.js +143 -0
- package/dist/ai.d.ts +359 -0
- package/dist/ai.js +229 -0
- package/dist/analytics.d.ts +37 -0
- package/dist/analytics.js +8 -0
- package/dist/atlas.d.ts +291 -0
- package/dist/atlas.js +78 -0
- package/dist/audit.d.ts +193 -0
- package/dist/audit.js +26 -0
- package/dist/authentication.d.ts +119 -0
- package/dist/authentication.js +83 -0
- package/dist/awards.d.ts +38 -0
- package/dist/awards.js +10 -0
- package/dist/blueprint/document.d.ts +178 -0
- package/dist/blueprint/document.js +17 -0
- package/dist/blueprint/index.d.ts +3 -0
- package/dist/blueprint/index.js +5 -0
- package/dist/blueprint/manifest.d.ts +105 -0
- package/dist/blueprint/manifest.js +11 -0
- package/dist/blueprint/validate.d.ts +14 -0
- package/dist/blueprint/validate.js +416 -0
- package/dist/bookings-directory.d.ts +118 -0
- package/dist/bookings-directory.js +289 -0
- package/dist/bookings-extra.d.ts +1448 -0
- package/dist/bookings-extra.js +582 -0
- package/dist/bookings.d.ts +1365 -0
- package/dist/bookings.js +305 -0
- package/dist/builder-code.d.ts +164 -0
- package/dist/builder-code.js +12 -0
- package/dist/builder-core-gaps.d.ts +83 -0
- package/dist/builder-core-gaps.js +8 -0
- package/dist/builder-repos.d.ts +73 -0
- package/dist/builder-repos.js +37 -0
- package/dist/builder.d.ts +730 -0
- package/dist/builder.js +105 -0
- package/dist/campaigns.d.ts +105 -0
- package/dist/campaigns.js +25 -0
- package/dist/catalogs.d.ts +188 -0
- package/dist/catalogs.js +36 -0
- package/dist/commerce-ai.d.ts +182 -0
- package/dist/commerce-ai.js +27 -0
- package/dist/connections.d.ts +278 -0
- package/dist/connections.js +96 -0
- package/dist/content-control.d.ts +121 -0
- package/dist/content-control.js +23 -0
- package/dist/contributions.d.ts +560 -0
- package/dist/contributions.js +140 -0
- package/dist/conversation-assist.d.ts +154 -0
- package/dist/conversation-assist.js +51 -0
- package/dist/conversation-info.d.ts +219 -0
- package/dist/conversation-info.js +43 -0
- package/dist/crm.d.ts +533 -0
- package/dist/crm.js +142 -0
- package/dist/dashboards.d.ts +119 -0
- package/dist/dashboards.js +22 -0
- package/dist/delegations.d.ts +161 -0
- package/dist/delegations.js +39 -0
- package/dist/docs.d.ts +289 -0
- package/dist/docs.js +49 -0
- package/dist/documents.d.ts +317 -0
- package/dist/documents.js +84 -0
- package/dist/drafts.d.ts +132 -0
- package/dist/drafts.js +56 -0
- package/dist/engagements.d.ts +133 -0
- package/dist/engagements.js +15 -0
- package/dist/event-stream.d.ts +54 -0
- package/dist/event-stream.js +228 -0
- package/dist/exchanges.d.ts +447 -0
- package/dist/exchanges.js +145 -0
- package/dist/exports.d.ts +113 -0
- package/dist/exports.js +81 -0
- package/dist/feeds.d.ts +228 -0
- package/dist/feeds.js +52 -0
- package/dist/files.d.ts +56 -0
- package/dist/files.js +55 -0
- package/dist/finance-insights.d.ts +41 -0
- package/dist/finance-insights.js +61 -0
- package/dist/fixed-assets.d.ts +155 -0
- package/dist/fixed-assets.js +28 -0
- package/dist/fulfilment-jobs.d.ts +405 -0
- package/dist/fulfilment-jobs.js +76 -0
- package/dist/fulfilment.d.ts +205 -0
- package/dist/fulfilment.js +39 -0
- package/dist/hr.d.ts +350 -0
- package/dist/hr.js +94 -0
- package/dist/http.d.ts +124 -0
- package/dist/http.js +392 -0
- package/dist/inbox.d.ts +206 -0
- package/dist/inbox.js +36 -0
- package/dist/index.d.ts +384 -0
- package/dist/index.js +294 -0
- package/dist/insights.d.ts +176 -0
- package/dist/insights.js +52 -0
- package/dist/inventory.d.ts +797 -0
- package/dist/inventory.js +120 -0
- package/dist/list-query.d.ts +211 -0
- package/dist/list-query.js +158 -0
- package/dist/listings.d.ts +381 -0
- package/dist/listings.js +173 -0
- package/dist/location-sharing.d.ts +83 -0
- package/dist/location-sharing.js +20 -0
- package/dist/marketplace.d.ts +268 -0
- package/dist/marketplace.js +59 -0
- package/dist/matching.d.ts +103 -0
- package/dist/matching.js +22 -0
- package/dist/media.d.ts +221 -0
- package/dist/media.js +239 -0
- package/dist/metrics.d.ts +125 -0
- package/dist/metrics.js +45 -0
- package/dist/moderation.d.ts +240 -0
- package/dist/moderation.js +40 -0
- package/dist/money.d.ts +41 -0
- package/dist/money.js +79 -0
- package/dist/my-data.d.ts +266 -0
- package/dist/my-data.js +32 -0
- package/dist/names.d.ts +14 -0
- package/dist/names.js +17 -0
- package/dist/occasions.d.ts +256 -0
- package/dist/occasions.js +40 -0
- package/dist/onboarding.d.ts +88 -0
- package/dist/onboarding.js +38 -0
- package/dist/pagination.d.ts +204 -0
- package/dist/pagination.js +141 -0
- package/dist/party-baseline-attributes.d.ts +245 -0
- package/dist/party-baseline-attributes.js +36 -0
- package/dist/party.d.ts +401 -0
- package/dist/party.js +56 -0
- package/dist/patient.d.ts +161 -0
- package/dist/patient.js +45 -0
- package/dist/payroll.d.ts +378 -0
- package/dist/payroll.js +60 -0
- package/dist/person-addresses.d.ts +88 -0
- package/dist/person-addresses.js +18 -0
- package/dist/person-cart.d.ts +250 -0
- package/dist/person-cart.js +63 -0
- package/dist/person-chat-assist.d.ts +47 -0
- package/dist/person-chat-assist.js +13 -0
- package/dist/person-data-webhooks.d.ts +72 -0
- package/dist/person-data-webhooks.js +86 -0
- package/dist/person-data.d.ts +212 -0
- package/dist/person-data.js +162 -0
- package/dist/person-locations.d.ts +54 -0
- package/dist/person-locations.js +6 -0
- package/dist/person-messaging.d.ts +405 -0
- package/dist/person-messaging.js +112 -0
- package/dist/person-notifications.d.ts +319 -0
- package/dist/person-notifications.js +164 -0
- package/dist/personalisation.d.ts +21 -0
- package/dist/personalisation.js +8 -0
- package/dist/platform.d.ts +63 -0
- package/dist/platform.js +45 -0
- package/dist/portfolio.d.ts +163 -0
- package/dist/portfolio.js +28 -0
- package/dist/pos.d.ts +743 -0
- package/dist/pos.js +129 -0
- package/dist/procurement.d.ts +664 -0
- package/dist/procurement.js +157 -0
- package/dist/promotions.d.ts +169 -0
- package/dist/promotions.js +39 -0
- package/dist/publications.d.ts +583 -0
- package/dist/publications.js +164 -0
- package/dist/ranking.d.ts +43 -0
- package/dist/ranking.js +34 -0
- package/dist/ratings.d.ts +293 -0
- package/dist/ratings.js +109 -0
- package/dist/reactions.d.ts +123 -0
- package/dist/reactions.js +41 -0
- package/dist/recipient-orders.d.ts +294 -0
- package/dist/recipient-orders.js +73 -0
- package/dist/relationships.d.ts +18 -0
- package/dist/relationships.js +8 -0
- package/dist/reporting.d.ts +107 -0
- package/dist/reporting.js +56 -0
- package/dist/sales.d.ts +270 -0
- package/dist/sales.js +66 -0
- package/dist/shares.d.ts +105 -0
- package/dist/shares.js +27 -0
- package/dist/shop.d.ts +993 -0
- package/dist/shop.js +215 -0
- package/dist/shopping-assistant.d.ts +65 -0
- package/dist/shopping-assistant.js +14 -0
- package/dist/spaces.d.ts +422 -0
- package/dist/spaces.js +118 -0
- package/dist/stored-value.d.ts +754 -0
- package/dist/stored-value.js +177 -0
- package/dist/types.d.ts +83 -0
- package/dist/types.js +2 -0
- package/dist/vault.d.ts +290 -0
- package/dist/vault.js +55 -0
- package/dist/vertical-runtime.d.ts +17 -0
- package/dist/vertical-runtime.js +8 -0
- package/dist/vite/build-manifest-plugin.d.ts +42 -0
- package/dist/vite/build-manifest-plugin.js +42 -0
- package/dist/vite/first-paint-plugin.d.ts +26 -0
- package/dist/vite/first-paint-plugin.js +57 -0
- package/dist/wishlists.d.ts +591 -0
- package/dist/wishlists.js +188 -0
- package/dist/workbench.d.ts +114 -0
- package/dist/workbench.js +22 -0
- package/dist/workspace.d.ts +190 -0
- package/dist/workspace.js +41 -0
- package/package.json +52 -4
- package/templates/extension-image.Dockerfile +38 -0
- package/templates/nuwah-vertical.yml +102 -0
- package/templates/vertical-app/.env.example +34 -0
- package/templates/vertical-app/README.md +108 -0
- package/templates/vertical-app/github/workflows/ci.yml +51 -0
- package/templates/vertical-app/gitignore +5 -0
- package/templates/vertical-app/index.html +12 -0
- package/templates/vertical-app/package.json +28 -0
- package/templates/vertical-app/src/App.tsx +64 -0
- package/templates/vertical-app/src/blueprint/blueprint.ts +45 -0
- package/templates/vertical-app/src/blueprint/screens.ts +15 -0
- package/templates/vertical-app/src/env.d.ts +18 -0
- package/templates/vertical-app/src/index.css +139 -0
- package/templates/vertical-app/src/lib/i18n.ts +5 -0
- package/templates/vertical-app/src/lib/iam.ts +19 -0
- package/templates/vertical-app/src/lib/operations.ts +93 -0
- package/templates/vertical-app/src/lib/router.ts +24 -0
- package/templates/vertical-app/src/lib/sdk.ts +21 -0
- package/templates/vertical-app/src/lib/theme.ts +18 -0
- package/templates/vertical-app/src/lib/words.ts +39 -0
- package/templates/vertical-app/src/main.tsx +25 -0
- package/templates/vertical-app/src/pages/AppScreens.tsx +71 -0
- package/templates/vertical-app/src/pages/AuthCallback.tsx +44 -0
- package/templates/vertical-app/src/pages/Home.tsx +36 -0
- package/templates/vertical-app/tsconfig.json +24 -0
- package/templates/vertical-app/vite.config.ts +23 -0
- package/templates/vertical-ci.yml +192 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { listQueryParams } from './list-query.js';
|
|
2
|
+
import { personDomainRequest, } from './actors.js';
|
|
3
|
+
|
|
4
|
+
export const PUBLICATION_BATCH_MAXIMUM = 50;
|
|
5
|
+
|
|
6
|
+
export const PUBLICATION_MEDIA_PURPOSE = 'publications.item_media';
|
|
7
|
+
|
|
8
|
+
export const PUBLICATION_REFERENCE_NOTIFICATION_KEYS = ['publications.item.reposted', 'publications.item.quoted'];
|
|
9
|
+
|
|
10
|
+
export const CLOSE_CIRCLE_AUDIENCE_KEY = 'publications.close_circle';
|
|
11
|
+
const BASE = '/api/person/publications';
|
|
12
|
+
export function createPublicationsNamespace(http) {
|
|
13
|
+
const read = (options, query) => personDomainRequest(options, false, query ? { cursor: query.cursor ?? undefined, limit: query.limit } : undefined);
|
|
14
|
+
const write = (options) => personDomainRequest(options, true);
|
|
15
|
+
const list = (options, query) => personDomainRequest(options, false, listQueryParams(query ?? {}));
|
|
16
|
+
return {
|
|
17
|
+
|
|
18
|
+
kinds: (options) => http.get(`${BASE}/kinds`, read(options)),
|
|
19
|
+
|
|
20
|
+
create: (request, options) => http.post(BASE, request, write(options)),
|
|
21
|
+
|
|
22
|
+
show: (itemId, options) => http.get(`${BASE}/${itemId}`, read(options)),
|
|
23
|
+
|
|
24
|
+
many: async (itemIds, options) => {
|
|
25
|
+
const unique = [...new Set(itemIds.map((id) => id.toLowerCase()))];
|
|
26
|
+
const answer = { data: [], missing: [] };
|
|
27
|
+
for (let start = 0; start < unique.length; start += PUBLICATION_BATCH_MAXIMUM) {
|
|
28
|
+
const page = await http.get(BASE, personDomainRequest(options, false, { ids: unique.slice(start, start + PUBLICATION_BATCH_MAXIMUM) }));
|
|
29
|
+
answer.data.push(...page.data);
|
|
30
|
+
answer.missing.push(...page.missing);
|
|
31
|
+
}
|
|
32
|
+
return answer;
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
edit: (itemId, request, options) => http.patch(`${BASE}/${itemId}`, request, write(options)),
|
|
36
|
+
|
|
37
|
+
remove: (itemId, options) => http.delete(`${BASE}/${itemId}`, write(options)),
|
|
38
|
+
|
|
39
|
+
schedule: (itemId, request, options) => http.post(`${BASE}/${itemId}/schedule`, request, write(options)),
|
|
40
|
+
|
|
41
|
+
replies: (itemId, query, options) => http.get(`${BASE}/${itemId}/replies`, list(options, query)),
|
|
42
|
+
|
|
43
|
+
quotes: (itemId, query, options) => http.get(`${BASE}/${itemId}/quotes`, list(options, query)),
|
|
44
|
+
|
|
45
|
+
repost: (itemId, request = {}, options) => http.post(`${BASE}/${itemId}/repost`, request, write(options)),
|
|
46
|
+
|
|
47
|
+
undoRepost: (itemId, options) => http.delete(`${BASE}/${itemId}/repost`, write(options)),
|
|
48
|
+
|
|
49
|
+
quote: (itemId, request, options) => http.post(BASE, { ...request, quoted_item_id: itemId }, write(options)),
|
|
50
|
+
|
|
51
|
+
authored: (actorId, query, options) => http.get(`${BASE}/by/${actorId}`, list(options, query)),
|
|
52
|
+
|
|
53
|
+
report: (itemId, reason, notes, options) => http.post(`${BASE}/${itemId}/reports`, { reason, notes: notes ?? null }, write(options)),
|
|
54
|
+
|
|
55
|
+
decisions: (itemId, options) => http.get(`${BASE}/${itemId}/decisions`, read(options)),
|
|
56
|
+
|
|
57
|
+
appeal: (decisionId, note, options) => http.post(`${BASE}/decisions/${decisionId}/appeal`, { note: note ?? null }, write(options)),
|
|
58
|
+
|
|
59
|
+
uploadMedia: (file, altText, options) => {
|
|
60
|
+
const body = new FormData();
|
|
61
|
+
body.append('file', file);
|
|
62
|
+
if (altText?.en)
|
|
63
|
+
body.append('alt_text[en]', altText.en);
|
|
64
|
+
if (altText?.ar)
|
|
65
|
+
body.append('alt_text[ar]', altText.ar);
|
|
66
|
+
return http.post(`${BASE}/media`, body, write(options));
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
requestMediaUpload: (request, options) => http.post(`${BASE}/media/uploads`, request, write(options)),
|
|
70
|
+
|
|
71
|
+
completeMediaUpload: (mediaId, options) => http.post(`${BASE}/media/${mediaId}/complete`, undefined, write(options)),
|
|
72
|
+
|
|
73
|
+
audienceFamilies: (options) => http.get(`${BASE}/audiences`, read(options)),
|
|
74
|
+
|
|
75
|
+
audienceOptions: (audienceKey, query, options) => http.get(`${BASE}/audiences/${encodeURIComponent(audienceKey)}/options`, read(options, query ?? {})),
|
|
76
|
+
|
|
77
|
+
drafts: (statusOrQuery = 'draft', query, options) => {
|
|
78
|
+
const question = typeof statusOrQuery === 'string' ? { ...(query ?? {}) } : statusOrQuery;
|
|
79
|
+
if (typeof statusOrQuery === 'string' && statusOrQuery !== 'all') {
|
|
80
|
+
question.filter = { ...(question.filter ?? {}), status: [statusOrQuery] };
|
|
81
|
+
}
|
|
82
|
+
return http.get(`${BASE}/drafts`, list(options, question));
|
|
83
|
+
},
|
|
84
|
+
|
|
85
|
+
revisions: (itemId, options) => http.get(`${BASE}/${itemId}/revisions`, read(options)),
|
|
86
|
+
|
|
87
|
+
pin: (itemId, options) => http.post(`${BASE}/${itemId}/pin`, undefined, write(options)),
|
|
88
|
+
unpin: (itemId, options) => http.delete(`${BASE}/${itemId}/pin`, write(options)),
|
|
89
|
+
|
|
90
|
+
pinned: (actorId, options) => http.get(`${BASE}/by/${actorId}/pinned`, read(options)),
|
|
91
|
+
|
|
92
|
+
recordView: (itemId, options) => http.post(`${BASE}/${itemId}/views`, undefined, write(options)),
|
|
93
|
+
|
|
94
|
+
viewers: (itemId, query, options) => http.get(`${BASE}/${itemId}/viewers`, read(options, query ?? {})),
|
|
95
|
+
|
|
96
|
+
privateReply: (itemId, body, options) => http.post(`${BASE}/${itemId}/private-replies`, { body }, write(options)),
|
|
97
|
+
|
|
98
|
+
highlights: (actorId, options) => http.get(`${BASE}/by/${actorId}/highlights`, read(options)),
|
|
99
|
+
createHighlight: (title, itemIds, options) => http.post(`${BASE}/highlights`, { title, item_ids: itemIds }, write(options)),
|
|
100
|
+
editHighlight: (highlightId, request, options) => http.patch(`${BASE}/highlights/${highlightId}`, request, write(options)),
|
|
101
|
+
removeHighlight: (highlightId, options) => http.delete(`${BASE}/highlights/${highlightId}`, write(options)),
|
|
102
|
+
addToHighlight: (highlightId, itemId, options) => http.post(`${BASE}/highlights/${highlightId}/items`, { item_id: itemId }, write(options)),
|
|
103
|
+
removeFromHighlight: (highlightId, itemId, options) => http.delete(`${BASE}/highlights/${highlightId}/items/${itemId}`, write(options)),
|
|
104
|
+
highlightItems: (highlightId, query, options) => http.get(`${BASE}/highlights/${highlightId}/items`, read(options, query ?? {})),
|
|
105
|
+
|
|
106
|
+
tagged: (tag, query, options) => http.get(`${BASE}/tags/${encodeURIComponent(tag.replace(/^#/, ''))}`, list(options, query)),
|
|
107
|
+
trendingTags: (window = '24h', limit, options) => http.get(`${BASE}/tags/trending`, personDomainRequest(options, false, { window, limit })),
|
|
108
|
+
suggestTags: (text, limit, options) => http.get(`${BASE}/tags/suggest`, personDomainRequest(options, false, { q: text, limit })),
|
|
109
|
+
|
|
110
|
+
search: (text, query, options) => {
|
|
111
|
+
const trimmed = (text ?? '').trim();
|
|
112
|
+
const question = { ...(query ?? {}) };
|
|
113
|
+
if (trimmed.startsWith('#')) {
|
|
114
|
+
question.filter = { ...(question.filter ?? {}), tag: trimmed.replace(/^#+/, '') };
|
|
115
|
+
}
|
|
116
|
+
else if (trimmed !== '') {
|
|
117
|
+
question.search = trimmed;
|
|
118
|
+
}
|
|
119
|
+
return http.get(`${BASE}/search`, list(options, question));
|
|
120
|
+
},
|
|
121
|
+
|
|
122
|
+
pendingMediaTags: (query, options) => http.get(`${BASE}/media-tags/pending`, read(options, query ?? {})),
|
|
123
|
+
approveMediaTag: (tagId, options) => http.post(`${BASE}/media-tags/${tagId}/approve`, undefined, write(options)),
|
|
124
|
+
|
|
125
|
+
removeMediaTag: (tagId, options) => http.delete(`${BASE}/media-tags/${tagId}`, write(options)),
|
|
126
|
+
|
|
127
|
+
vote: (itemId, optionIds, options) => http.put(`${BASE}/${itemId}/poll/votes`, { option_ids: optionIds }, write(options)),
|
|
128
|
+
|
|
129
|
+
retractVote: (itemId, options) => http.delete(`${BASE}/${itemId}/poll/votes`, write(options)),
|
|
130
|
+
|
|
131
|
+
pollResults: (itemIds, options) => http.get(`${BASE}/polls/results`, personDomainRequest(options, false, { ids: itemIds.slice(0, 100) })),
|
|
132
|
+
|
|
133
|
+
save: (itemId, collectionId, options) => http.post(`${BASE}/${itemId}/save`, collectionId ? { collection_id: collectionId } : {}, write(options)),
|
|
134
|
+
unsave: (itemId, options) => http.delete(`${BASE}/${itemId}/save`, write(options)),
|
|
135
|
+
|
|
136
|
+
saved: (collectionOrQuery, query, options) => {
|
|
137
|
+
const question = collectionOrQuery !== null && typeof collectionOrQuery === 'object'
|
|
138
|
+
? collectionOrQuery
|
|
139
|
+
: { ...(query ?? {}) };
|
|
140
|
+
if (typeof collectionOrQuery === 'string' && collectionOrQuery !== '') {
|
|
141
|
+
question.filter = { ...(question.filter ?? {}), collection: collectionOrQuery };
|
|
142
|
+
}
|
|
143
|
+
return http.get(`${BASE}/saved`, list(options, question));
|
|
144
|
+
},
|
|
145
|
+
|
|
146
|
+
savedCollections: (options) => http.get(`${BASE}/saved/collections`, read(options)),
|
|
147
|
+
|
|
148
|
+
savedCollectionsPage: (query, options) => http.get(`${BASE}/saved/collections`, list(options, query)),
|
|
149
|
+
createSavedCollection: (name, options) => http.post(`${BASE}/saved/collections`, { name }, write(options)),
|
|
150
|
+
renameSavedCollection: (collectionId, name, expectedVersion, options) => http.patch(`${BASE}/saved/collections/${collectionId}`, { name, expected_version: expectedVersion }, write(options)),
|
|
151
|
+
removeSavedCollection: (collectionId, options) => http.delete(`${BASE}/saved/collections/${collectionId}`, write(options)),
|
|
152
|
+
|
|
153
|
+
reorderSavedCollections: (collectionIds, options) => http.put(`${BASE}/saved/collections/order`, { collection_ids: collectionIds.slice(0, 100) }, write(options)),
|
|
154
|
+
removeFromSavedCollection: (collectionId, itemId, options) => http.delete(`${BASE}/saved/collections/${collectionId}/items/${itemId}`, write(options)),
|
|
155
|
+
|
|
156
|
+
closeCircle: (query, options) => http.get(`${BASE}/close-circle`, read(options, query ?? {})),
|
|
157
|
+
addToCloseCircle: (parties, options) => http.post(`${BASE}/close-circle/members`, { parties: parties.slice(0, 100) }, write(options)),
|
|
158
|
+
removeFromCloseCircle: (party, options) => http.delete(`${BASE}/close-circle/members/${party.kind}/${party.id}`, write(options)),
|
|
159
|
+
|
|
160
|
+
insights: (itemId, options) => http.get(`${BASE}/${itemId}/insights`, read(options)),
|
|
161
|
+
|
|
162
|
+
dailyInsights: (from, to, options) => http.get(`${BASE}/insights/daily`, personDomainRequest(options, false, { from, to })),
|
|
163
|
+
};
|
|
164
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Http } from './http.js';
|
|
2
|
+
import { type PersonDomainCallOptions } from './actors.js';
|
|
3
|
+
export interface RankingReasonText {
|
|
4
|
+
en: string;
|
|
5
|
+
ar: string;
|
|
6
|
+
}
|
|
7
|
+
export type RankingReasonKey = 'follow.author' | 'affinity.category' | 'affinity.author' | 'engagement.popular' | 'recency.not_personalised' | 'recency.newest' | 'sponsored' | (string & {});
|
|
8
|
+
export interface RankingReason {
|
|
9
|
+
key: RankingReasonKey;
|
|
10
|
+
label: RankingReasonText;
|
|
11
|
+
params: Record<string, string | number | boolean>;
|
|
12
|
+
signal: string | null;
|
|
13
|
+
}
|
|
14
|
+
/** Keeps only well-formed reasons (a key, both labels); a malformed one is dropped, never shown half-empty. */
|
|
15
|
+
export declare function parseRankingReasons(value: unknown): RankingReason[];
|
|
16
|
+
export type SearchSurface = `search.${string}`;
|
|
17
|
+
/** The sponsored block a re-ranked search row carries (`null` for an organic row). */
|
|
18
|
+
export interface SponsoredSearchResult {
|
|
19
|
+
label: RankingReasonText;
|
|
20
|
+
advertiser: {
|
|
21
|
+
reference: string;
|
|
22
|
+
handle: string | null;
|
|
23
|
+
display_name: RankingReasonText;
|
|
24
|
+
avatar_url: string | null;
|
|
25
|
+
};
|
|
26
|
+
campaign_key: string;
|
|
27
|
+
reasons: RankingReason[];
|
|
28
|
+
}
|
|
29
|
+
/** The answer of `GET api/person/search/why/{surface}/{subjectType}/{id}?q=`. Fits `WhyAmISeeingSheet`'s `load`. */
|
|
30
|
+
export interface SearchResultExplanation {
|
|
31
|
+
surface: SearchSurface;
|
|
32
|
+
subject_type: string;
|
|
33
|
+
id: string;
|
|
34
|
+
query: string | null;
|
|
35
|
+
reasons: RankingReason[];
|
|
36
|
+
/** False: the viewer's own interests took no part (not chosen, not answered, or a minor). */
|
|
37
|
+
personalised: boolean;
|
|
38
|
+
sponsored: null;
|
|
39
|
+
}
|
|
40
|
+
export declare function createSearchRankingNamespace(http: Http): {
|
|
41
|
+
why: (surface: SearchSurface, subjectType: string, id: string, query?: string | null, options?: PersonDomainCallOptions) => Promise<SearchResultExplanation>;
|
|
42
|
+
};
|
|
43
|
+
export type SearchRankingNamespace = ReturnType<typeof createSearchRankingNamespace>;
|
package/dist/ranking.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { personDomainRequest } from './actors.js';
|
|
2
|
+
const KEY_PATTERN = /^[a-z][a-z0-9_]*(\.[a-z][a-z0-9_]*)*$/;
|
|
3
|
+
|
|
4
|
+
export function parseRankingReasons(value) {
|
|
5
|
+
if (!Array.isArray(value))
|
|
6
|
+
return [];
|
|
7
|
+
const reasons = [];
|
|
8
|
+
for (const item of value) {
|
|
9
|
+
if (!item || typeof item !== 'object')
|
|
10
|
+
continue;
|
|
11
|
+
const record = item;
|
|
12
|
+
const label = record.label;
|
|
13
|
+
if (typeof record.key !== 'string' || !KEY_PATTERN.test(record.key) || record.key.length > 80)
|
|
14
|
+
continue;
|
|
15
|
+
if (!label || typeof label.en !== 'string' || typeof label.ar !== 'string' || !label.en.trim() || !label.ar.trim())
|
|
16
|
+
continue;
|
|
17
|
+
reasons.push({
|
|
18
|
+
key: record.key,
|
|
19
|
+
label: { en: label.en, ar: label.ar },
|
|
20
|
+
params: record.params && typeof record.params === 'object' ? record.params : {},
|
|
21
|
+
signal: typeof record.signal === 'string' ? record.signal : null,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return reasons;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function createSearchRankingNamespace(http) {
|
|
28
|
+
return {
|
|
29
|
+
why: async (surface, subjectType, id, query, options) => {
|
|
30
|
+
const answer = await http.get(`/api/person/search/why/${encodeURIComponent(surface)}/${encodeURIComponent(subjectType)}/${encodeURIComponent(id)}`, personDomainRequest(options, false, { q: query ?? undefined }));
|
|
31
|
+
return { ...answer.data, reasons: parseRankingReasons(answer.data.reasons) };
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Person-plane ratings — `/api/person/ratings/*`: the central rating store behind core's ONE rating
|
|
3
|
+
* contract, for rateable types declared person-plane-resident (an exchange today).
|
|
4
|
+
*
|
|
5
|
+
* Blind by default: until both sides rated, or the window closed, the other side's score and
|
|
6
|
+
* comment are withheld (`withheld: true`), and once revealed the answers are frozen. The rater
|
|
7
|
+
* and the viewer are always the token's person — there is no acting header here.
|
|
8
|
+
*
|
|
9
|
+
* `rate` REQUIRES an `Idempotency-Key`; pass the same key when retrying one press. Reputations
|
|
10
|
+
* (`summaries`) count revealed ratings only.
|
|
11
|
+
*
|
|
12
|
+
* Names are prefixed `PersonPlane…` because `bookings.ts` already exports `RatingRow` and
|
|
13
|
+
* friends for the tenant-plane session ratings.
|
|
14
|
+
*/
|
|
15
|
+
import type { Http } from './http.js';
|
|
16
|
+
import type { MediaAsset } from './media.js';
|
|
17
|
+
import { type ActorSummary, type BilingualText, type PersonDomainCallOptions, type PersonDomainCursorPage, type PersonDomainEnvelope } from './actors.js';
|
|
18
|
+
export type PersonPlaneRatingSideKey = 'primary' | 'counterparty';
|
|
19
|
+
export interface PersonPlaneRatingSide {
|
|
20
|
+
side: PersonPlaneRatingSideKey;
|
|
21
|
+
person_id: string;
|
|
22
|
+
rated: boolean;
|
|
23
|
+
/** True while the score and comment are hidden from this viewer (blind until both rated). */
|
|
24
|
+
withheld: boolean;
|
|
25
|
+
score: number | null;
|
|
26
|
+
comment: string | null;
|
|
27
|
+
rated_at: string | null;
|
|
28
|
+
}
|
|
29
|
+
export interface PersonPlaneRating {
|
|
30
|
+
id: string;
|
|
31
|
+
rateable_type: string;
|
|
32
|
+
rateable_id: string;
|
|
33
|
+
revealed: boolean;
|
|
34
|
+
/** Which side the viewer is on; null for a viewer who is neither. */
|
|
35
|
+
viewer_side: PersonPlaneRatingSideKey | null;
|
|
36
|
+
closes_at: string | null;
|
|
37
|
+
primary: PersonPlaneRatingSide;
|
|
38
|
+
counterparty: PersonPlaneRatingSide;
|
|
39
|
+
}
|
|
40
|
+
export interface PersonPlaneRatingSummary {
|
|
41
|
+
rateable_type: string;
|
|
42
|
+
rated_person_id: string;
|
|
43
|
+
count: number;
|
|
44
|
+
/** Average of revealed scores as core computed it; null when there are none. */
|
|
45
|
+
average: number | string | null;
|
|
46
|
+
/** score ("1".."5") → times given. */
|
|
47
|
+
distribution: Record<string, number>;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* What one PARTY (`person:<id>` or a business profile `actor:<id>`) received — a profile's ratings
|
|
51
|
+
* are the profile's, never the member's who acted for it. `count` is always there; `average` (a
|
|
52
|
+
* two-place decimal string) and `distribution` are null below `minimum_for_average`, the declared
|
|
53
|
+
* display minimum (`ratings.summary_minimum_count`, default 3, 0 = none). Draw "3 ratings", never
|
|
54
|
+
* "0 stars".
|
|
55
|
+
*/
|
|
56
|
+
export interface PersonPlanePartyRatingSummary {
|
|
57
|
+
rateable_type: string;
|
|
58
|
+
party: string;
|
|
59
|
+
count: number;
|
|
60
|
+
average: string | null;
|
|
61
|
+
distribution: Record<string, number> | null;
|
|
62
|
+
minimum_for_average: number;
|
|
63
|
+
}
|
|
64
|
+
export interface RatePersonPlaneRequest {
|
|
65
|
+
/** A whole number from {@link PERSON_PLANE_RATING_LOWEST_SCORE} to {@link PERSON_PLANE_RATING_HIGHEST_SCORE}. */
|
|
66
|
+
score: number;
|
|
67
|
+
comment?: string | null;
|
|
68
|
+
}
|
|
69
|
+
export declare const PERSON_PLANE_RATING_LOWEST_SCORE = 1;
|
|
70
|
+
export declare const PERSON_PLANE_RATING_HIGHEST_SCORE = 5;
|
|
71
|
+
/** The most people one `summaries` call accepts. */
|
|
72
|
+
export declare const MAXIMUM_PERSON_PLANE_RATING_SUMMARY_PEOPLE = 100;
|
|
73
|
+
export declare function createRatingsNamespace(http: Http): {
|
|
74
|
+
/** Public written reviews of businesses, shops, listings and products — `/api/person/reviews/*`. */
|
|
75
|
+
reviews: {
|
|
76
|
+
/** GET /types/{type} — the aspects, evidence types and sorts a review of this type uses. */
|
|
77
|
+
type: (subjectType: string, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<ReviewableTypeDeclaration>>;
|
|
78
|
+
/** GET /summaries — up to 100 subjects' summaries in one call (one per screen, never per card). */
|
|
79
|
+
summaries: (subjectType: string, subjectIds: string[], options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<PublicReviewSummary[]>>;
|
|
80
|
+
/** GET /{type}/{id} — a cursor page of public reviews. Follow `next_cursor` with the SAME filters. */
|
|
81
|
+
list: (subjectType: string, subjectId: string, query?: ReviewListQuery, options?: PersonDomainCallOptions) => Promise<PersonDomainCursorPage<PublicReview>>;
|
|
82
|
+
/**
|
|
83
|
+
* GET /written — every review the CALLER wrote, across every subject, newest first
|
|
84
|
+
* (published and hidden: the author may still read a hidden one). A cursor is bound to
|
|
85
|
+
* the caller and the type filter; follow `next_cursor` with the SAME `subject_type`.
|
|
86
|
+
*/
|
|
87
|
+
written: (query?: {
|
|
88
|
+
subject_type?: string;
|
|
89
|
+
cursor?: string | null;
|
|
90
|
+
limit?: number;
|
|
91
|
+
}, options?: PersonDomainCallOptions) => Promise<PersonDomainCursorPage<PublicReview>>;
|
|
92
|
+
/** GET /{type}/{id}/mine — the caller's own review and what their composer may do. */
|
|
93
|
+
mine: (subjectType: string, subjectId: string, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<OwnReviewContext>>;
|
|
94
|
+
/** PUT /{type}/{id}/mine — post the caller's review, or edit it. Refused locally when the score is out of range. */
|
|
95
|
+
write: (subjectType: string, subjectId: string, request: WriteReviewRequest, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<PublicReview>>;
|
|
96
|
+
/** DELETE /{type}/{id}/mine — withdraw the caller's review (204). */
|
|
97
|
+
withdraw: (subjectType: string, subjectId: string, options?: PersonDomainCallOptions) => Promise<void>;
|
|
98
|
+
/** PUT /entries/{review}/helpful — mark it helpful (not your own); idempotent. */
|
|
99
|
+
markHelpful: (reviewId: string, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<PublicReview>>;
|
|
100
|
+
/** DELETE /entries/{review}/helpful — take the mark back. */
|
|
101
|
+
unmarkHelpful: (reviewId: string, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<PublicReview>>;
|
|
102
|
+
/** PUT /entries/{review}/reply — the owner's one reply, created or edited. Pass `actingAs` for a business. */
|
|
103
|
+
reply: (reviewId: string, body: string, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<PublicReview>>;
|
|
104
|
+
/** DELETE /entries/{review}/reply — remove the owner's reply. */
|
|
105
|
+
removeReply: (reviewId: string, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<PublicReview>>;
|
|
106
|
+
};
|
|
107
|
+
/** GET /summaries — revealed-only reputations for up to 100 people, one call per screen. */
|
|
108
|
+
summaries: (rateableType: string, personIds: string[], options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<PersonPlaneRatingSummary[]>>;
|
|
109
|
+
/**
|
|
110
|
+
* GET /summaries?parties[]= — revealed-only reputations by PARTY reference (persons and
|
|
111
|
+
* business profiles), up to 100 per call, with the display minimum applied by core.
|
|
112
|
+
*/
|
|
113
|
+
partySummaries: (rateableType: string, parties: string[], options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<PersonPlanePartyRatingSummary[]>>;
|
|
114
|
+
/** GET /{type} — the caller's own ratings of a type, newest first, as a cursor page. */
|
|
115
|
+
mine: (rateableType: string, query?: {
|
|
116
|
+
cursor?: string | null;
|
|
117
|
+
limit?: number;
|
|
118
|
+
}, options?: PersonDomainCallOptions) => Promise<PersonDomainCursorPage<PersonPlaneRating>>;
|
|
119
|
+
/** GET /{type}/{id} — one rating as the caller may see it (404 when they are not a side). */
|
|
120
|
+
show: (rateableType: string, rateableId: string, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<PersonPlaneRating>>;
|
|
121
|
+
/** PUT /{type}/{id} — rate. Refused locally when the score is not a whole number in range. */
|
|
122
|
+
rate: (rateableType: string, rateableId: string, request: RatePersonPlaneRequest, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<PersonPlaneRating>>;
|
|
123
|
+
};
|
|
124
|
+
export type RatingsNamespace = ReturnType<typeof createRatingsNamespace>;
|
|
125
|
+
export type ReviewSort = 'newest' | 'highest' | 'lowest' | 'most_helpful';
|
|
126
|
+
export type ReviewStatus = 'published' | 'hidden';
|
|
127
|
+
export type ReviewMediaKind = 'file' | 'media';
|
|
128
|
+
export type ReviewEvidencePolicy = 'open' | 'verified_only';
|
|
129
|
+
export type ReviewEditWindowPolicy = 'none' | 'one_day' | 'seven_days' | 'thirty_days' | 'always';
|
|
130
|
+
export type ReviewOwnerRepliesPolicy = 'allowed' | 'off';
|
|
131
|
+
/** Refusal `reason` values the review routes answer with (`{reason, message}`). */
|
|
132
|
+
export type ReviewRefusalReason = 'review_type_unknown' | 'review_not_found' | 'review_of_own_subject' | 'review_evidence_required' | 'review_evidence_not_accepted' | 'review_aspect_unknown' | 'review_edit_window_closed' | 'review_daily_limit_reached' | 'review_replies_off' | 'review_reply_not_the_owner' | 'review_hidden' | 'review_batch_too_large';
|
|
133
|
+
export interface ReviewMediaReference {
|
|
134
|
+
kind: ReviewMediaKind;
|
|
135
|
+
id: string;
|
|
136
|
+
/**
|
|
137
|
+
* On a read: the attached pipeline file as this viewer may see it, or null (a legacy `file`
|
|
138
|
+
* reference, or a file not ready or not visible). Never sent on a write.
|
|
139
|
+
*/
|
|
140
|
+
asset?: ReviewMediaAsset | null;
|
|
141
|
+
}
|
|
142
|
+
/** The fields of {@link MediaAsset} a review carries for each of its photos and videos. */
|
|
143
|
+
export type ReviewMediaAsset = Pick<MediaAsset, 'id' | 'kind' | 'status' | 'mime_type' | 'width' | 'height' | 'duration_milliseconds' | 'alt_text' | 'placeholder' | 'sources' | 'poster' | 'renditions'> & {
|
|
144
|
+
position: number;
|
|
145
|
+
};
|
|
146
|
+
export interface PublicReviewReply {
|
|
147
|
+
/** The owner's visible profile, or null when the viewer may not see it. */
|
|
148
|
+
owner: ActorSummary | null;
|
|
149
|
+
body: string;
|
|
150
|
+
replied_at: string;
|
|
151
|
+
edited_at: string | null;
|
|
152
|
+
/** The review was edited after this reply was written — the reply may answer an older text. */
|
|
153
|
+
review_edited_since: boolean;
|
|
154
|
+
}
|
|
155
|
+
export interface PublicReview {
|
|
156
|
+
id: string;
|
|
157
|
+
subject_type: string;
|
|
158
|
+
subject_id: string;
|
|
159
|
+
author: ActorSummary | null;
|
|
160
|
+
viewer_is_author: boolean;
|
|
161
|
+
score: number;
|
|
162
|
+
title: string | null;
|
|
163
|
+
body: string | null;
|
|
164
|
+
/** The author's declared language tag, or `ar` detected from Arabic script; null when unknown. */
|
|
165
|
+
language: string | null;
|
|
166
|
+
/** aspect key → 1..5; `{}` when none were given. */
|
|
167
|
+
aspects: Record<string, number>;
|
|
168
|
+
media: ReviewMediaReference[];
|
|
169
|
+
verified: boolean;
|
|
170
|
+
/** The evidence TYPE that verified it (`exchanges.exchange`, `shop.order`), never its id. */
|
|
171
|
+
verified_by: string | null;
|
|
172
|
+
helpful_count: number;
|
|
173
|
+
viewer_marked_helpful: boolean;
|
|
174
|
+
status: ReviewStatus;
|
|
175
|
+
created_at: string;
|
|
176
|
+
edited_at: string | null;
|
|
177
|
+
/** Only for the author: when editing closes; null means always editable (or not yours). */
|
|
178
|
+
editable_until: string | null;
|
|
179
|
+
viewer_may_reply: boolean;
|
|
180
|
+
reply: PublicReviewReply | null;
|
|
181
|
+
}
|
|
182
|
+
export interface ReviewAspectSummary {
|
|
183
|
+
count: number;
|
|
184
|
+
/** Two-place decimal string, e.g. "4.50". */
|
|
185
|
+
average: string;
|
|
186
|
+
}
|
|
187
|
+
export interface PublicReviewSummary {
|
|
188
|
+
subject_type: string;
|
|
189
|
+
subject_id: string;
|
|
190
|
+
count: number;
|
|
191
|
+
/** Two-place decimal string, e.g. "4.33"; "0.00" when there are none. */
|
|
192
|
+
average: string;
|
|
193
|
+
/** "1".."5" → count; every key present. */
|
|
194
|
+
distribution: Record<'1' | '2' | '3' | '4' | '5', number>;
|
|
195
|
+
verified_count: number;
|
|
196
|
+
with_media_count: number;
|
|
197
|
+
aspects: Record<string, ReviewAspectSummary>;
|
|
198
|
+
last_reviewed_at: string | null;
|
|
199
|
+
}
|
|
200
|
+
export interface ReviewAspectDeclaration {
|
|
201
|
+
key: string;
|
|
202
|
+
label: BilingualText;
|
|
203
|
+
}
|
|
204
|
+
export interface ReviewableTypeDeclaration {
|
|
205
|
+
subject_type: string;
|
|
206
|
+
aspects: ReviewAspectDeclaration[];
|
|
207
|
+
evidence_types: string[];
|
|
208
|
+
sorts: Array<{
|
|
209
|
+
value: ReviewSort;
|
|
210
|
+
label: BilingualText;
|
|
211
|
+
}>;
|
|
212
|
+
limits: {
|
|
213
|
+
title: number;
|
|
214
|
+
body: number;
|
|
215
|
+
reply: number;
|
|
216
|
+
media: number;
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
/** The caller's position on one subject: their review, whether they may review, and the policy. */
|
|
220
|
+
export interface OwnReviewContext {
|
|
221
|
+
review: PublicReview | null;
|
|
222
|
+
may_review: boolean;
|
|
223
|
+
refusal: ReviewRefusalReason | null;
|
|
224
|
+
viewer_may_reply: boolean;
|
|
225
|
+
policy: {
|
|
226
|
+
evidence: ReviewEvidencePolicy;
|
|
227
|
+
edit_window: ReviewEditWindowPolicy;
|
|
228
|
+
owner_replies: ReviewOwnerRepliesPolicy;
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
export interface ReviewListQuery {
|
|
232
|
+
sort?: ReviewSort;
|
|
233
|
+
stars?: number[];
|
|
234
|
+
has_media?: boolean;
|
|
235
|
+
verified?: boolean;
|
|
236
|
+
language?: string;
|
|
237
|
+
/** Searched in title and body, folded for Arabic; 2–100 characters. */
|
|
238
|
+
q?: string;
|
|
239
|
+
cursor?: string | null;
|
|
240
|
+
limit?: number;
|
|
241
|
+
}
|
|
242
|
+
export interface WriteReviewRequest {
|
|
243
|
+
score: number;
|
|
244
|
+
title?: string | null;
|
|
245
|
+
body?: string | null;
|
|
246
|
+
language?: string | null;
|
|
247
|
+
aspects?: Record<string, number>;
|
|
248
|
+
media?: ReviewMediaReference[];
|
|
249
|
+
/** The completed order or exchange that verifies the review. */
|
|
250
|
+
evidence?: {
|
|
251
|
+
type: string;
|
|
252
|
+
id: string;
|
|
253
|
+
} | null;
|
|
254
|
+
}
|
|
255
|
+
export declare const REVIEW_TITLE_MAXIMUM_LENGTH = 120;
|
|
256
|
+
export declare const REVIEW_BODY_MAXIMUM_LENGTH = 5000;
|
|
257
|
+
export declare const REVIEW_REPLY_MAXIMUM_LENGTH = 3000;
|
|
258
|
+
export declare const REVIEW_MEDIA_MAXIMUM = 6;
|
|
259
|
+
/** The most subjects one `summaries` call accepts. */
|
|
260
|
+
export declare const MAXIMUM_REVIEW_SUMMARY_SUBJECTS = 100;
|
|
261
|
+
export declare function createReviewsNamespace(http: Http): {
|
|
262
|
+
/** GET /types/{type} — the aspects, evidence types and sorts a review of this type uses. */
|
|
263
|
+
type: (subjectType: string, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<ReviewableTypeDeclaration>>;
|
|
264
|
+
/** GET /summaries — up to 100 subjects' summaries in one call (one per screen, never per card). */
|
|
265
|
+
summaries: (subjectType: string, subjectIds: string[], options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<PublicReviewSummary[]>>;
|
|
266
|
+
/** GET /{type}/{id} — a cursor page of public reviews. Follow `next_cursor` with the SAME filters. */
|
|
267
|
+
list: (subjectType: string, subjectId: string, query?: ReviewListQuery, options?: PersonDomainCallOptions) => Promise<PersonDomainCursorPage<PublicReview>>;
|
|
268
|
+
/**
|
|
269
|
+
* GET /written — every review the CALLER wrote, across every subject, newest first
|
|
270
|
+
* (published and hidden: the author may still read a hidden one). A cursor is bound to
|
|
271
|
+
* the caller and the type filter; follow `next_cursor` with the SAME `subject_type`.
|
|
272
|
+
*/
|
|
273
|
+
written: (query?: {
|
|
274
|
+
subject_type?: string;
|
|
275
|
+
cursor?: string | null;
|
|
276
|
+
limit?: number;
|
|
277
|
+
}, options?: PersonDomainCallOptions) => Promise<PersonDomainCursorPage<PublicReview>>;
|
|
278
|
+
/** GET /{type}/{id}/mine — the caller's own review and what their composer may do. */
|
|
279
|
+
mine: (subjectType: string, subjectId: string, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<OwnReviewContext>>;
|
|
280
|
+
/** PUT /{type}/{id}/mine — post the caller's review, or edit it. Refused locally when the score is out of range. */
|
|
281
|
+
write: (subjectType: string, subjectId: string, request: WriteReviewRequest, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<PublicReview>>;
|
|
282
|
+
/** DELETE /{type}/{id}/mine — withdraw the caller's review (204). */
|
|
283
|
+
withdraw: (subjectType: string, subjectId: string, options?: PersonDomainCallOptions) => Promise<void>;
|
|
284
|
+
/** PUT /entries/{review}/helpful — mark it helpful (not your own); idempotent. */
|
|
285
|
+
markHelpful: (reviewId: string, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<PublicReview>>;
|
|
286
|
+
/** DELETE /entries/{review}/helpful — take the mark back. */
|
|
287
|
+
unmarkHelpful: (reviewId: string, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<PublicReview>>;
|
|
288
|
+
/** PUT /entries/{review}/reply — the owner's one reply, created or edited. Pass `actingAs` for a business. */
|
|
289
|
+
reply: (reviewId: string, body: string, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<PublicReview>>;
|
|
290
|
+
/** DELETE /entries/{review}/reply — remove the owner's reply. */
|
|
291
|
+
removeReply: (reviewId: string, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<PublicReview>>;
|
|
292
|
+
};
|
|
293
|
+
export type ReviewsNamespace = ReturnType<typeof createReviewsNamespace>;
|
package/dist/ratings.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { personDomainRequest, } from './actors.js';
|
|
2
|
+
export const PERSON_PLANE_RATING_LOWEST_SCORE = 1;
|
|
3
|
+
export const PERSON_PLANE_RATING_HIGHEST_SCORE = 5;
|
|
4
|
+
|
|
5
|
+
export const MAXIMUM_PERSON_PLANE_RATING_SUMMARY_PEOPLE = 100;
|
|
6
|
+
const BASE = '/api/person/ratings';
|
|
7
|
+
export function createRatingsNamespace(http) {
|
|
8
|
+
return {
|
|
9
|
+
|
|
10
|
+
reviews: createReviewsNamespace(http),
|
|
11
|
+
|
|
12
|
+
summaries: (rateableType, personIds, options) => http.get(`${BASE}/summaries`, personDomainRequest(options, false, { rateable_type: rateableType, person_ids: personIds })),
|
|
13
|
+
|
|
14
|
+
partySummaries: (rateableType, parties, options) => {
|
|
15
|
+
if (parties.length > MAXIMUM_PERSON_PLANE_RATING_SUMMARY_PEOPLE) {
|
|
16
|
+
throw new RangeError(`At most ${MAXIMUM_PERSON_PLANE_RATING_SUMMARY_PEOPLE} parties per summaries call.`);
|
|
17
|
+
}
|
|
18
|
+
return http.get(`${BASE}/summaries`, personDomainRequest(options, false, { rateable_type: rateableType, parties }));
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
mine: (rateableType, query = {}, options) => http.get(`${BASE}/${rateableType}`, personDomainRequest(options, false, { cursor: query.cursor ?? undefined, limit: query.limit })),
|
|
22
|
+
|
|
23
|
+
show: (rateableType, rateableId, options) => http.get(`${BASE}/${rateableType}/${rateableId}`, personDomainRequest(options)),
|
|
24
|
+
|
|
25
|
+
rate: (rateableType, rateableId, request, options) => {
|
|
26
|
+
if (!Number.isInteger(request.score)
|
|
27
|
+
|| request.score < PERSON_PLANE_RATING_LOWEST_SCORE
|
|
28
|
+
|| request.score > PERSON_PLANE_RATING_HIGHEST_SCORE) {
|
|
29
|
+
throw new TypeError(`A rating score is a whole number from ${PERSON_PLANE_RATING_LOWEST_SCORE} to ${PERSON_PLANE_RATING_HIGHEST_SCORE}.`);
|
|
30
|
+
}
|
|
31
|
+
return http.put(`${BASE}/${rateableType}/${rateableId}`, { score: request.score, comment: request.comment ?? null }, personDomainRequest(options, true));
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export const REVIEW_TITLE_MAXIMUM_LENGTH = 120;
|
|
36
|
+
export const REVIEW_BODY_MAXIMUM_LENGTH = 5000;
|
|
37
|
+
export const REVIEW_REPLY_MAXIMUM_LENGTH = 3000;
|
|
38
|
+
export const REVIEW_MEDIA_MAXIMUM = 6;
|
|
39
|
+
|
|
40
|
+
export const MAXIMUM_REVIEW_SUMMARY_SUBJECTS = 100;
|
|
41
|
+
const REVIEWS = '/api/person/reviews';
|
|
42
|
+
function reviewSubjectPath(subjectType, subjectId) {
|
|
43
|
+
return `${REVIEWS}/${encodeURIComponent(subjectType)}/${encodeURIComponent(subjectId)}`;
|
|
44
|
+
}
|
|
45
|
+
function assertReviewScore(score) {
|
|
46
|
+
if (!Number.isInteger(score) || score < PERSON_PLANE_RATING_LOWEST_SCORE || score > PERSON_PLANE_RATING_HIGHEST_SCORE) {
|
|
47
|
+
throw new TypeError(`A review score is a whole number from ${PERSON_PLANE_RATING_LOWEST_SCORE} to ${PERSON_PLANE_RATING_HIGHEST_SCORE}.`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export function createReviewsNamespace(http) {
|
|
51
|
+
return {
|
|
52
|
+
|
|
53
|
+
type: (subjectType, options) => http.get(`${REVIEWS}/types/${encodeURIComponent(subjectType)}`, personDomainRequest(options)),
|
|
54
|
+
|
|
55
|
+
summaries: (subjectType, subjectIds, options) => {
|
|
56
|
+
if (subjectIds.length > MAXIMUM_REVIEW_SUMMARY_SUBJECTS) {
|
|
57
|
+
throw new RangeError(`At most ${MAXIMUM_REVIEW_SUMMARY_SUBJECTS} subjects per summaries call.`);
|
|
58
|
+
}
|
|
59
|
+
return http.get(`${REVIEWS}/summaries`, personDomainRequest(options, false, { subject_type: subjectType, subject_ids: subjectIds }));
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
list: (subjectType, subjectId, query = {}, options) => http.get(reviewSubjectPath(subjectType, subjectId), personDomainRequest(options, false, {
|
|
63
|
+
sort: query.sort,
|
|
64
|
+
stars: query.stars,
|
|
65
|
+
has_media: query.has_media === undefined ? undefined : (query.has_media ? 1 : 0),
|
|
66
|
+
verified: query.verified === undefined ? undefined : (query.verified ? 1 : 0),
|
|
67
|
+
language: query.language,
|
|
68
|
+
q: query.q,
|
|
69
|
+
cursor: query.cursor ?? undefined,
|
|
70
|
+
limit: query.limit,
|
|
71
|
+
})),
|
|
72
|
+
|
|
73
|
+
written: (query = {}, options) => http.get(`${REVIEWS}/written`, personDomainRequest(options, false, {
|
|
74
|
+
subject_type: query.subject_type,
|
|
75
|
+
cursor: query.cursor ?? undefined,
|
|
76
|
+
limit: query.limit,
|
|
77
|
+
})),
|
|
78
|
+
|
|
79
|
+
mine: (subjectType, subjectId, options) => http.get(`${reviewSubjectPath(subjectType, subjectId)}/mine`, personDomainRequest(options)),
|
|
80
|
+
|
|
81
|
+
write: (subjectType, subjectId, request, options) => {
|
|
82
|
+
assertReviewScore(request.score);
|
|
83
|
+
return http.put(`${reviewSubjectPath(subjectType, subjectId)}/mine`, {
|
|
84
|
+
score: request.score,
|
|
85
|
+
title: request.title ?? null,
|
|
86
|
+
body: request.body ?? null,
|
|
87
|
+
language: request.language ?? null,
|
|
88
|
+
aspects: request.aspects ?? {},
|
|
89
|
+
media: request.media ?? [],
|
|
90
|
+
evidence: request.evidence ?? null,
|
|
91
|
+
}, personDomainRequest(options, true));
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
withdraw: (subjectType, subjectId, options) => http.delete(`${reviewSubjectPath(subjectType, subjectId)}/mine`, personDomainRequest(options)),
|
|
95
|
+
|
|
96
|
+
markHelpful: (reviewId, options) => http.put(`${REVIEWS}/entries/${encodeURIComponent(reviewId)}/helpful`, {}, personDomainRequest(options, true)),
|
|
97
|
+
|
|
98
|
+
unmarkHelpful: (reviewId, options) => http.delete(`${REVIEWS}/entries/${encodeURIComponent(reviewId)}/helpful`, personDomainRequest(options)),
|
|
99
|
+
|
|
100
|
+
reply: (reviewId, body, options) => {
|
|
101
|
+
if (body.trim() === '' || body.length > REVIEW_REPLY_MAXIMUM_LENGTH) {
|
|
102
|
+
throw new RangeError(`A reply is 1 to ${REVIEW_REPLY_MAXIMUM_LENGTH} characters.`);
|
|
103
|
+
}
|
|
104
|
+
return http.put(`${REVIEWS}/entries/${encodeURIComponent(reviewId)}/reply`, { body }, personDomainRequest(options, true));
|
|
105
|
+
},
|
|
106
|
+
|
|
107
|
+
removeReply: (reviewId, options) => http.delete(`${REVIEWS}/entries/${encodeURIComponent(reviewId)}/reply`, personDomainRequest(options)),
|
|
108
|
+
};
|
|
109
|
+
}
|