@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,140 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { refusalReason } from './http.js';
|
|
4
|
+
import { personDomainRequest } from './actors.js';
|
|
5
|
+
import { listQueryParams } from './list-query.js';
|
|
6
|
+
export const DRIVE_OUTCOME_TYPES = ['shop.order', 'stored_value.entry', 'stored_value.hold', 'wishlists.claim'];
|
|
7
|
+
|
|
8
|
+
export const DRIVE_MESSAGE_MAXIMUM_LENGTH = 2000;
|
|
9
|
+
|
|
10
|
+
export const DRIVE_SETTLEMENT_REFUSAL = {
|
|
11
|
+
locked: 'drive_settlement_locked',
|
|
12
|
+
invalid: 'drive_settlement_invalid',
|
|
13
|
+
notHeld: 'drive_not_held',
|
|
14
|
+
notOpen: 'drive_not_open',
|
|
15
|
+
notMember: 'drive_not_a_member',
|
|
16
|
+
initiatorOnly: 'drive_initiator_only',
|
|
17
|
+
outcomeInvalid: 'drive_outcome_invalid',
|
|
18
|
+
alreadyPurchased: 'drive_already_purchased',
|
|
19
|
+
outcomeConflict: 'drive_outcome_conflict',
|
|
20
|
+
idempotencyKeyInvalid: 'idempotency_key_invalid',
|
|
21
|
+
idempotencyKeyReused: 'idempotency_key_reused',
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const DRIVE_REFUSAL = {
|
|
25
|
+
revealNotAllowed: 'drive_reveal_not_allowed',
|
|
26
|
+
notRevealed: 'drive_not_revealed',
|
|
27
|
+
alreadyThanked: 'drive_already_thanked',
|
|
28
|
+
messageRefused: 'drive_message_refused',
|
|
29
|
+
withdrawalNotAllowed: 'drive_withdrawal_not_allowed',
|
|
30
|
+
anonymousNotAllowed: 'drive_anonymous_not_allowed',
|
|
31
|
+
outcomeTenantRequired: 'drive_outcome_tenant_required',
|
|
32
|
+
};
|
|
33
|
+
function assertMessageBody(body) {
|
|
34
|
+
const trimmed = typeof body === 'string' ? body.trim() : '';
|
|
35
|
+
if (trimmed === '' || trimmed.length > DRIVE_MESSAGE_MAXIMUM_LENGTH) {
|
|
36
|
+
throw new TypeError(`contributions: a message is 1 to ${DRIVE_MESSAGE_MAXIMUM_LENGTH} characters.`);
|
|
37
|
+
}
|
|
38
|
+
return trimmed;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const CONTRIBUTION_AMOUNT_PATTERN = /^\d{1,15}(\.\d{1,4})?$/;
|
|
42
|
+
|
|
43
|
+
export function driveRefusalReason(error) {
|
|
44
|
+
return refusalReason(error);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function isDriveSettlementLocked(settlement, paidTotal) {
|
|
48
|
+
const holds = settlement?.holds;
|
|
49
|
+
if (holds && holds.held + holds.captured + holds.released > 0)
|
|
50
|
+
return true;
|
|
51
|
+
return paidTotal !== null && /[1-9]/.test(paidTotal);
|
|
52
|
+
}
|
|
53
|
+
function assertAmount(amount) {
|
|
54
|
+
if (typeof amount !== 'string' || !CONTRIBUTION_AMOUNT_PATTERN.test(amount)) {
|
|
55
|
+
|
|
56
|
+
throw new TypeError(`contributions: an amount must be a decimal string, got ${JSON.stringify(amount)}.`);
|
|
57
|
+
}
|
|
58
|
+
return amount;
|
|
59
|
+
}
|
|
60
|
+
const BASE = '/api/person/contribution-drives';
|
|
61
|
+
export function createContributionsNamespace(http) {
|
|
62
|
+
const read = (options) => personDomainRequest(options, false);
|
|
63
|
+
const write = (options) => personDomainRequest(options, true);
|
|
64
|
+
const segment = encodeURIComponent;
|
|
65
|
+
return {
|
|
66
|
+
|
|
67
|
+
list: (query = {}, options) => http.get(BASE, personDomainRequest(options, false, listQueryParams(query))),
|
|
68
|
+
|
|
69
|
+
show: (driveId, options) => http.get(`${BASE}/${segment(driveId)}`, read(options)),
|
|
70
|
+
messages: {
|
|
71
|
+
|
|
72
|
+
list: (driveId, query = {}, options) => http.get(`${BASE}/${segment(driveId)}/messages`, personDomainRequest(options, false, {
|
|
73
|
+
...(query.cursor ? { cursor: query.cursor } : {}),
|
|
74
|
+
...(query.limit ? { limit: query.limit } : {}),
|
|
75
|
+
})),
|
|
76
|
+
|
|
77
|
+
post: (driveId, message, options) => http.post(`${BASE}/${segment(driveId)}/messages`, { kind: message.kind, body: assertMessageBody(message.body) }, write(options)),
|
|
78
|
+
|
|
79
|
+
delete: (driveId, messageId, options) => http.delete(`${BASE}/${segment(driveId)}/messages/${segment(messageId)}`, write(options)),
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
reveal: (driveId, options) => http.post(`${BASE}/${segment(driveId)}/reveal`, undefined, write(options)),
|
|
83
|
+
|
|
84
|
+
thank: (driveId, body, options) => http.post(`${BASE}/${segment(driveId)}/thanks`, { body: assertMessageBody(body) }, write(options)),
|
|
85
|
+
|
|
86
|
+
withdraw: (driveId, contributionHoldId, options) => http.post(`${BASE}/${segment(driveId)}/held-payments/${segment(contributionHoldId)}/withdraw`, undefined, write(options)),
|
|
87
|
+
|
|
88
|
+
start: (request, options) => http.post(BASE, request.target_amount ? { ...request, target_amount: assertAmount(request.target_amount) } : request, write(options)),
|
|
89
|
+
|
|
90
|
+
invite: (driveId, handle, options) => http.post(`${BASE}/${segment(driveId)}/invitations`, { handle }, write(options)),
|
|
91
|
+
|
|
92
|
+
pledge: (driveId, amount, options) => http.post(`${BASE}/${segment(driveId)}/pledge`, { amount: assertAmount(amount), ...(typeof options?.anonymous === 'boolean' ? { anonymous: options.anonymous } : {}) }, write(options)),
|
|
93
|
+
|
|
94
|
+
declarePayment: (driveId, amount, options) => http.post(`${BASE}/${segment(driveId)}/payments`, { amount: assertAmount(amount) }, write(options)),
|
|
95
|
+
|
|
96
|
+
update: (driveId, changes, options) => http.patch(`${BASE}/${segment(driveId)}`, changes, write(options)),
|
|
97
|
+
|
|
98
|
+
close: (driveId, cancelled = false, options) => http.post(`${BASE}/${segment(driveId)}/close`, { cancelled }, write(options)),
|
|
99
|
+
settlement: {
|
|
100
|
+
|
|
101
|
+
choose: (driveId, request, options) => http.put(`${BASE}/${segment(driveId)}/settlement`, request, write(options)),
|
|
102
|
+
|
|
103
|
+
payHeld: (driveId, amount, options) => http.post(`${BASE}/${segment(driveId)}/held-payments`, { amount: assertAmount(amount) }, write(options)),
|
|
104
|
+
|
|
105
|
+
recordPurchase: (driveId, outcome, options) => {
|
|
106
|
+
if (outcome.type === 'shop.order' && !outcome.tenantId) {
|
|
107
|
+
return Promise.reject(new TypeError('contributions: a shop order outcome needs the shop’s tenant id (outcome_tenant_id).'));
|
|
108
|
+
}
|
|
109
|
+
return http.post(`${BASE}/${segment(driveId)}/purchase`, {
|
|
110
|
+
outcome_type: outcome.type,
|
|
111
|
+
outcome_id: outcome.id,
|
|
112
|
+
...(outcome.tenantId ? { outcome_tenant_id: outcome.tenantId } : {}),
|
|
113
|
+
}, write(options));
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
|
|
117
|
+
recipientOrder: {
|
|
118
|
+
|
|
119
|
+
preview: (driveId, query, options) => http.get(`${BASE}/${segment(driveId)}/recipient-order/preview`, personDomainRequest(options, false, {
|
|
120
|
+
shop_slug: query.shopSlug,
|
|
121
|
+
price: assertAmount(query.price),
|
|
122
|
+
...(query.unitKey ? { unit_key: query.unitKey } : {}),
|
|
123
|
+
...(query.topUp ? { top_up: assertAmount(query.topUp) } : {}),
|
|
124
|
+
})),
|
|
125
|
+
|
|
126
|
+
place: (driveId, request, options) => http.post(`${BASE}/${segment(driveId)}/recipient-order`, { ...request, ...(request.top_up ? { top_up: assertAmount(request.top_up) } : {}) }, write(options)),
|
|
127
|
+
|
|
128
|
+
plan: (driveId, request, options) => http.put(`${BASE}/${segment(driveId)}/recipient-order/plan`, request, write(options)),
|
|
129
|
+
|
|
130
|
+
clearPlan: (driveId, options) => http.delete(`${BASE}/${segment(driveId)}/recipient-order/plan`, write(options)),
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export const DRIVE_POOLED_PURCHASE_REFUSALS = {
|
|
136
|
+
poolShort: 'pool_short',
|
|
137
|
+
chooseCheaperItem: 'choose_cheaper_item',
|
|
138
|
+
topUpUnconfirmed: 'top_up_unconfirmed',
|
|
139
|
+
poolHoldUnusable: 'pool_hold_unusable',
|
|
140
|
+
};
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import type { Http } from './http.js';
|
|
2
|
+
import { type BilingualText, type PersonDomainCallOptions } from './actors.js';
|
|
3
|
+
/** Which layer wrote a suggestion: declared facts, a grounded AI draft, or a note to hand over. */
|
|
4
|
+
export type SuggestionLayer = 'rule' | 'ai' | 'handover';
|
|
5
|
+
export type SuggestionState = 'offered' | 'used' | 'dismissed' | 'sent_automatically' | 'superseded';
|
|
6
|
+
/** certain/likely: a rule answer · grounded: an AI draft with no flag · review: flagged · none: a handover. */
|
|
7
|
+
export type AnswerConfidence = 'certain' | 'likely' | 'grounded' | 'review' | 'none';
|
|
8
|
+
export type ConversationTopic = 'price' | 'availability' | 'hours' | 'location' | 'details' | 'booking' | 'delivery' | 'refund' | 'discount' | 'greeting' | 'other';
|
|
9
|
+
export type AssistMode = 'off' | 'suggest' | 'auto_when_certain';
|
|
10
|
+
export interface SuggestionSource {
|
|
11
|
+
/** `catalog_entry` · `profile_hours` · `profile_location` · `faq_entry` · `subject_facts`. */
|
|
12
|
+
kind: string;
|
|
13
|
+
label: BilingualText;
|
|
14
|
+
reference?: string | null;
|
|
15
|
+
}
|
|
16
|
+
export interface ConversationSuggestion {
|
|
17
|
+
id: string;
|
|
18
|
+
conversation_id: string;
|
|
19
|
+
trigger_message_id: string;
|
|
20
|
+
layer: SuggestionLayer;
|
|
21
|
+
resolver_key: string | null;
|
|
22
|
+
topic: ConversationTopic;
|
|
23
|
+
/** Empty for a handover. */
|
|
24
|
+
text: string;
|
|
25
|
+
locale: 'en' | 'ar';
|
|
26
|
+
confidence: AnswerConfidence;
|
|
27
|
+
sources: SuggestionSource[];
|
|
28
|
+
/**
|
|
29
|
+
* Why a member should read it closely, or why it was handed over: `commitment_topic:refund`,
|
|
30
|
+
* `commitment_phrase:…`, `commitment:<kind>`, `invented_number:<n>`, `screening:<decision>`,
|
|
31
|
+
* `language_mismatch`, `classifier_unavailable`, `no_declared_fact`, `inbound_screening:…`, `ai:…`.
|
|
32
|
+
*/
|
|
33
|
+
flags: string[];
|
|
34
|
+
run_id: string | null;
|
|
35
|
+
state: SuggestionState;
|
|
36
|
+
decided_at: string | null;
|
|
37
|
+
sent_message_id: string | null;
|
|
38
|
+
created_at: string;
|
|
39
|
+
}
|
|
40
|
+
export interface ConversationHandling {
|
|
41
|
+
message_id: string;
|
|
42
|
+
outcome: 'suggested' | 'auto_replied' | 'handed_over' | 'skipped_off' | 'skipped_guard' | 'skipped_screening' | 'skipped_budget' | 'ai_unavailable';
|
|
43
|
+
reason: Record<string, unknown>;
|
|
44
|
+
data_used: Array<{
|
|
45
|
+
kind: string;
|
|
46
|
+
reference: string | null;
|
|
47
|
+
}>;
|
|
48
|
+
run_id: string | null;
|
|
49
|
+
created_at: string;
|
|
50
|
+
}
|
|
51
|
+
export interface ConversationAssistView {
|
|
52
|
+
suggestions: ConversationSuggestion[];
|
|
53
|
+
latest_customer_message_id: string | null;
|
|
54
|
+
answered: boolean;
|
|
55
|
+
assistant: {
|
|
56
|
+
mode: AssistMode;
|
|
57
|
+
/** `auto_when_certain` reads as `suggest` until the evaluation evidence holds. */
|
|
58
|
+
effective_mode: AssistMode;
|
|
59
|
+
ai_layer: 'off' | 'on';
|
|
60
|
+
};
|
|
61
|
+
handlings: ConversationHandling[];
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Why the assistant left a message to a person — core's `ConversationAssist\Enums\HandoverReason`.
|
|
65
|
+
* The `reason` of a `handover` answer, and the first flag of the handover suggestion it stores (a
|
|
66
|
+
* flag may carry a detail after a colon: `commitment_topic:refund`, `ai:<the model's words>`).
|
|
67
|
+
*/
|
|
68
|
+
export type HandoverReason = 'no_declared_fact' | 'no_rule_answer' | 'ai_layer_off' | 'commitment_topic' | 'minor_customer' | 'daily_cap' | 'inbound_screening' | 'instruction_like' | 'ai_handover';
|
|
69
|
+
export type SuggestNowStatus = 'offered' | 'handover' | 'already_answered' | 'nothing_to_answer' | 'budget' | 'ai_unavailable';
|
|
70
|
+
export interface SuggestNowResult {
|
|
71
|
+
status: SuggestNowStatus;
|
|
72
|
+
/** A `HandoverReason` with status `handover`; the AI failure's reason with `budget` / `ai_unavailable`. */
|
|
73
|
+
reason?: HandoverReason | string;
|
|
74
|
+
suggestions: ConversationSuggestion[];
|
|
75
|
+
}
|
|
76
|
+
export interface UsedSuggestion {
|
|
77
|
+
message: Record<string, unknown>;
|
|
78
|
+
replayed: boolean;
|
|
79
|
+
suggestion: ConversationSuggestion;
|
|
80
|
+
}
|
|
81
|
+
export interface AssistTopicChoice {
|
|
82
|
+
key: ConversationTopic;
|
|
83
|
+
label: BilingualText;
|
|
84
|
+
may_answer_automatically: boolean;
|
|
85
|
+
commitment: boolean;
|
|
86
|
+
}
|
|
87
|
+
export interface AssistSettings {
|
|
88
|
+
allowed_topics: ConversationTopic[];
|
|
89
|
+
handover_message: BilingualText;
|
|
90
|
+
handover_message_is_default: boolean;
|
|
91
|
+
updated_at: string | null;
|
|
92
|
+
policies: Record<string, {
|
|
93
|
+
value: string;
|
|
94
|
+
decided_at: string;
|
|
95
|
+
}>;
|
|
96
|
+
topics: AssistTopicChoice[];
|
|
97
|
+
}
|
|
98
|
+
export interface AssistSettingsInput {
|
|
99
|
+
allowed_topics?: ConversationTopic[];
|
|
100
|
+
/** Empty strings go back to the platform's default message. */
|
|
101
|
+
handover_message?: Partial<BilingualText>;
|
|
102
|
+
}
|
|
103
|
+
export interface FaqEntry {
|
|
104
|
+
id: string;
|
|
105
|
+
question: BilingualText;
|
|
106
|
+
answer: BilingualText;
|
|
107
|
+
keywords: string[];
|
|
108
|
+
topic: ConversationTopic;
|
|
109
|
+
active: boolean;
|
|
110
|
+
created_at?: string;
|
|
111
|
+
updated_at?: string;
|
|
112
|
+
}
|
|
113
|
+
export interface FaqEntryInput {
|
|
114
|
+
question: Partial<BilingualText>;
|
|
115
|
+
answer: Partial<BilingualText>;
|
|
116
|
+
keywords?: string[];
|
|
117
|
+
topic?: ConversationTopic;
|
|
118
|
+
active?: boolean;
|
|
119
|
+
}
|
|
120
|
+
/** The policy keys, for `actors.choosePolicy`. */
|
|
121
|
+
export declare const CONVERSATION_ASSIST_POLICIES: {
|
|
122
|
+
readonly mode: "conversation_assist.mode";
|
|
123
|
+
readonly aiLayer: "conversation_assist.ai_layer";
|
|
124
|
+
readonly handoverNotice: "conversation_assist.handover_notice";
|
|
125
|
+
readonly minorCustomers: "conversation_assist.minor_customers";
|
|
126
|
+
};
|
|
127
|
+
/** What a profile message says about the assistant that wrote it. */
|
|
128
|
+
export interface AssistantReplyMark {
|
|
129
|
+
layer: SuggestionLayer;
|
|
130
|
+
edited: boolean;
|
|
131
|
+
suggestion_id: string | null;
|
|
132
|
+
/** Sent without a member pressing send. */
|
|
133
|
+
automatic: boolean;
|
|
134
|
+
}
|
|
135
|
+
/** The assistant mark on a message, or null. Read it on messages the profile sent. */
|
|
136
|
+
export declare function assistantReplyMark(message: {
|
|
137
|
+
metadata?: unknown;
|
|
138
|
+
} | null | undefined): AssistantReplyMark | null;
|
|
139
|
+
export interface ConversationAssistNamespace {
|
|
140
|
+
view(conversationId: string, options: PersonDomainCallOptions): Promise<ConversationAssistView>;
|
|
141
|
+
suggestNow(conversationId: string, options: PersonDomainCallOptions): Promise<SuggestNowResult>;
|
|
142
|
+
/** Pass the same `idempotencyKey` when retrying; a replay answers `replayed: true`. */
|
|
143
|
+
use(conversationId: string, suggestionId: string, editedText: string | null, options: PersonDomainCallOptions): Promise<UsedSuggestion>;
|
|
144
|
+
dismiss(conversationId: string, suggestionId: string, options: PersonDomainCallOptions): Promise<ConversationSuggestion>;
|
|
145
|
+
settings(options: PersonDomainCallOptions): Promise<AssistSettings>;
|
|
146
|
+
saveSettings(input: AssistSettingsInput, options: PersonDomainCallOptions): Promise<AssistSettings>;
|
|
147
|
+
/** "Reset to defaults": no automatic topics and the default handover message; audited as `conversation_assist.settings_reset`. Policies return through `actors.choosePolicy(actorId, key, null)`. */
|
|
148
|
+
resetSettings(options: PersonDomainCallOptions): Promise<AssistSettings>;
|
|
149
|
+
faq(options: PersonDomainCallOptions): Promise<FaqEntry[]>;
|
|
150
|
+
createFaq(input: FaqEntryInput, options: PersonDomainCallOptions): Promise<FaqEntry>;
|
|
151
|
+
updateFaq(entryId: string, input: FaqEntryInput, options: PersonDomainCallOptions): Promise<FaqEntry>;
|
|
152
|
+
deleteFaq(entryId: string, options: PersonDomainCallOptions): Promise<void>;
|
|
153
|
+
}
|
|
154
|
+
export declare function createConversationAssistNamespace(http: Http): ConversationAssistNamespace;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { personDomainRequest } from './actors.js';
|
|
2
|
+
const BASE = '/api/person/actor-inbox';
|
|
3
|
+
const segment = encodeURIComponent;
|
|
4
|
+
|
|
5
|
+
export const CONVERSATION_ASSIST_POLICIES = {
|
|
6
|
+
mode: 'conversation_assist.mode',
|
|
7
|
+
aiLayer: 'conversation_assist.ai_layer',
|
|
8
|
+
handoverNotice: 'conversation_assist.handover_notice',
|
|
9
|
+
minorCustomers: 'conversation_assist.minor_customers',
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export function assistantReplyMark(message) {
|
|
13
|
+
const metadata = message?.metadata;
|
|
14
|
+
if (!metadata || typeof metadata !== 'object')
|
|
15
|
+
return null;
|
|
16
|
+
const reply = metadata.actor_reply;
|
|
17
|
+
if (!reply || typeof reply !== 'object')
|
|
18
|
+
return null;
|
|
19
|
+
const assistant = reply.assistant;
|
|
20
|
+
if (!assistant || typeof assistant !== 'object')
|
|
21
|
+
return null;
|
|
22
|
+
const record = assistant;
|
|
23
|
+
const layer = record.layer;
|
|
24
|
+
if (layer !== 'rule' && layer !== 'ai' && layer !== 'handover')
|
|
25
|
+
return null;
|
|
26
|
+
return {
|
|
27
|
+
layer,
|
|
28
|
+
edited: record.edited === true,
|
|
29
|
+
suggestion_id: typeof record.suggestion_id === 'string' ? record.suggestion_id : null,
|
|
30
|
+
automatic: reply.automatic === 'assistant',
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export function createConversationAssistNamespace(http) {
|
|
34
|
+
const room = (conversationId) => `${BASE}/conversations/${segment(conversationId)}/suggestions`;
|
|
35
|
+
const data = async (promise) => (await promise).data;
|
|
36
|
+
return {
|
|
37
|
+
view: (conversationId, options) => data(http.get(room(conversationId), personDomainRequest(options))),
|
|
38
|
+
suggestNow: (conversationId, options) => data(http.post(room(conversationId), undefined, personDomainRequest(options, true))),
|
|
39
|
+
use: (conversationId, suggestionId, editedText, options) => data(http.post(`${room(conversationId)}/${segment(suggestionId)}/use`, editedText === null ? {} : { edited_text: editedText }, personDomainRequest(options, true))),
|
|
40
|
+
dismiss: (conversationId, suggestionId, options) => data(http.post(`${room(conversationId)}/${segment(suggestionId)}/dismiss`, undefined, personDomainRequest(options, true))),
|
|
41
|
+
settings: (options) => data(http.get(`${BASE}/assist/settings`, personDomainRequest(options))),
|
|
42
|
+
saveSettings: (input, options) => data(http.put(`${BASE}/assist/settings`, input, personDomainRequest(options, true))),
|
|
43
|
+
resetSettings: (options) => data(http.delete(`${BASE}/assist/settings`, personDomainRequest(options, true))),
|
|
44
|
+
faq: (options) => data(http.get(`${BASE}/assist/faq`, personDomainRequest(options))),
|
|
45
|
+
createFaq: (input, options) => data(http.post(`${BASE}/assist/faq`, input, personDomainRequest(options, true))),
|
|
46
|
+
updateFaq: (entryId, input, options) => data(http.put(`${BASE}/assist/faq/${segment(entryId)}`, input, personDomainRequest(options, true))),
|
|
47
|
+
deleteFaq: async (entryId, options) => {
|
|
48
|
+
await http.delete(`${BASE}/assist/faq/${segment(entryId)}`, personDomainRequest(options, true));
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import type { Http } from './http.js';
|
|
2
|
+
import { type PersonDomainCallOptions } from './actors.js';
|
|
3
|
+
type Options = Omit<PersonDomainCallOptions, 'actingAs'>;
|
|
4
|
+
export interface ConversationPermissions {
|
|
5
|
+
add_members: boolean;
|
|
6
|
+
edit_details: boolean;
|
|
7
|
+
/** May send here: false in a group that lets only its admins send. */
|
|
8
|
+
send_messages: boolean;
|
|
9
|
+
/** May answer the group's own permissions (its admins). */
|
|
10
|
+
manage_controls: boolean;
|
|
11
|
+
manage_members: boolean;
|
|
12
|
+
manage_invites: boolean;
|
|
13
|
+
clear_history: boolean;
|
|
14
|
+
leave: boolean;
|
|
15
|
+
}
|
|
16
|
+
export type GroupControlKey = 'sending' | 'details_editing' | 'member_adding';
|
|
17
|
+
/** `inherit` follows the platform's and product's answer; `members` is the explicit open choice. */
|
|
18
|
+
export type GroupControlChoice = 'inherit' | 'admins' | 'members';
|
|
19
|
+
/** One group permission: the group's answer, what applies, and whether the product switched it off. */
|
|
20
|
+
export interface GroupControl {
|
|
21
|
+
chosen: GroupControlChoice;
|
|
22
|
+
effective: 'admins' | 'members' | 'off' | string;
|
|
23
|
+
locked: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A group's membership change, as a `system` message carries it in `metadata.system` (ids only;
|
|
27
|
+
* the names are resolved when the page is read). Word it in the reader's language.
|
|
28
|
+
*/
|
|
29
|
+
export interface GroupSystemEvent {
|
|
30
|
+
event: 'member_added' | 'member_joined' | 'member_left' | 'member_removed' | 'admin_promoted' | 'admin_demoted' | 'admin_succeeded' | 'invite_link_reset' | 'controls_changed' | string;
|
|
31
|
+
actor_person_id: string | null;
|
|
32
|
+
subject_person_id: string | null;
|
|
33
|
+
actor_name?: string | null;
|
|
34
|
+
subject_name?: string | null;
|
|
35
|
+
/** `controls_changed`: which control and what now applies. */
|
|
36
|
+
detail?: {
|
|
37
|
+
control?: GroupControlKey;
|
|
38
|
+
effective?: string;
|
|
39
|
+
} | null;
|
|
40
|
+
}
|
|
41
|
+
/** A party as the platform's actor directory describes it. */
|
|
42
|
+
export interface ConversationPartySummary {
|
|
43
|
+
reference: string;
|
|
44
|
+
handle: string | null;
|
|
45
|
+
display_name: {
|
|
46
|
+
en?: string | null;
|
|
47
|
+
ar?: string | null;
|
|
48
|
+
};
|
|
49
|
+
avatar_url: string | null;
|
|
50
|
+
[field: string]: unknown;
|
|
51
|
+
}
|
|
52
|
+
export interface ConversationMember {
|
|
53
|
+
person_id: string;
|
|
54
|
+
display_name: string | null;
|
|
55
|
+
/** `creator` for the group's creator; else `admin` or `member`. */
|
|
56
|
+
role: 'creator' | 'admin' | 'member';
|
|
57
|
+
is_admin: boolean;
|
|
58
|
+
is_creator: boolean;
|
|
59
|
+
is_viewer: boolean;
|
|
60
|
+
joined_at: string;
|
|
61
|
+
profile: ConversationPartySummary | null;
|
|
62
|
+
}
|
|
63
|
+
export interface ConversationInfo {
|
|
64
|
+
id: string;
|
|
65
|
+
type: 'direct' | 'group' | 'actor_inbox' | string;
|
|
66
|
+
title: string | null;
|
|
67
|
+
description: string | null;
|
|
68
|
+
/** The group's picture as a media asset, or null. */
|
|
69
|
+
picture: Record<string, unknown> | null;
|
|
70
|
+
created_at: string;
|
|
71
|
+
member_count: number;
|
|
72
|
+
archived: boolean;
|
|
73
|
+
muted: boolean;
|
|
74
|
+
muted_until: string | null;
|
|
75
|
+
/** When the caller last cleared the chat; nothing before it is shown to them. */
|
|
76
|
+
history_cleared_at: string | null;
|
|
77
|
+
/** Deleted from the caller's list (until a new message arrives). */
|
|
78
|
+
hidden: boolean;
|
|
79
|
+
/** A group's own permissions; null outside a group. */
|
|
80
|
+
controls: Record<GroupControlKey, GroupControl> | null;
|
|
81
|
+
viewer: {
|
|
82
|
+
is_creator: boolean;
|
|
83
|
+
is_admin: boolean;
|
|
84
|
+
has_blocked: boolean;
|
|
85
|
+
permissions: ConversationPermissions;
|
|
86
|
+
};
|
|
87
|
+
counterpart: (ConversationPartySummary & {
|
|
88
|
+
kind: string;
|
|
89
|
+
id: string;
|
|
90
|
+
person_id: string | null;
|
|
91
|
+
}) | null;
|
|
92
|
+
catalogue: {
|
|
93
|
+
actor_id: string | null;
|
|
94
|
+
policy: string | null;
|
|
95
|
+
};
|
|
96
|
+
shared_counts: {
|
|
97
|
+
media: number;
|
|
98
|
+
documents: number;
|
|
99
|
+
links: number;
|
|
100
|
+
};
|
|
101
|
+
members: {
|
|
102
|
+
data: ConversationMember[];
|
|
103
|
+
next_cursor: string | null;
|
|
104
|
+
} | null;
|
|
105
|
+
groups_in_common: {
|
|
106
|
+
id: string;
|
|
107
|
+
title: string | null;
|
|
108
|
+
member_count: number;
|
|
109
|
+
}[];
|
|
110
|
+
latest_message_from_others_id: string | null;
|
|
111
|
+
other_person_id: string | null;
|
|
112
|
+
}
|
|
113
|
+
export interface ConversationSharedItem {
|
|
114
|
+
message_id: string;
|
|
115
|
+
type: string;
|
|
116
|
+
body: string | null;
|
|
117
|
+
sent_by_viewer: boolean;
|
|
118
|
+
created_at: string;
|
|
119
|
+
attachments: Record<string, unknown>[];
|
|
120
|
+
links: string[];
|
|
121
|
+
}
|
|
122
|
+
export interface ConversationInvite {
|
|
123
|
+
id: string;
|
|
124
|
+
/** The whole token: only in the answer that created it; null in every list. */
|
|
125
|
+
token: string | null;
|
|
126
|
+
token_hint: string;
|
|
127
|
+
created_by_person_id: string;
|
|
128
|
+
created_at: string;
|
|
129
|
+
expires_at: string | null;
|
|
130
|
+
revoked_at: string | null;
|
|
131
|
+
joined_count: number;
|
|
132
|
+
live: boolean;
|
|
133
|
+
}
|
|
134
|
+
export interface ConversationInvitePreview {
|
|
135
|
+
conversation_id: string;
|
|
136
|
+
title: string | null;
|
|
137
|
+
description: string | null;
|
|
138
|
+
member_count: number;
|
|
139
|
+
already_member: boolean;
|
|
140
|
+
expires_at: string | null;
|
|
141
|
+
}
|
|
142
|
+
export interface ConversationHistoryState {
|
|
143
|
+
conversation_id: string;
|
|
144
|
+
history_cleared_at: string | null;
|
|
145
|
+
hidden: boolean;
|
|
146
|
+
}
|
|
147
|
+
export interface MessageDeletionResult {
|
|
148
|
+
conversation_id: string;
|
|
149
|
+
scope: 'me' | 'everyone';
|
|
150
|
+
deleted: string[];
|
|
151
|
+
refused: {
|
|
152
|
+
id: string;
|
|
153
|
+
reason: 'not_found' | 'not_yours' | 'window_closed' | 'unsend_off' | string;
|
|
154
|
+
}[];
|
|
155
|
+
}
|
|
156
|
+
export interface ConversationDetailsChange {
|
|
157
|
+
title?: string;
|
|
158
|
+
description?: string | null;
|
|
159
|
+
/** An own Ready image's id, or null to remove the picture. */
|
|
160
|
+
picture_media_id?: string | null;
|
|
161
|
+
}
|
|
162
|
+
interface CursorPage<T> {
|
|
163
|
+
data: T[];
|
|
164
|
+
next_cursor: string | null;
|
|
165
|
+
}
|
|
166
|
+
export declare function createConversationInfoNamespace(http: Http): {
|
|
167
|
+
info: (conversationId: string, options?: Options) => Promise<{
|
|
168
|
+
data: ConversationInfo;
|
|
169
|
+
}>;
|
|
170
|
+
members: (conversationId: string, cursor?: string | null, limit?: number, options?: Options) => Promise<CursorPage<ConversationMember>>;
|
|
171
|
+
shared: (conversationId: string, kind: "media" | "documents" | "links", cursor?: string | null, limit?: number, options?: Options) => Promise<CursorPage<ConversationSharedItem>>;
|
|
172
|
+
/** `until` an ISO moment; omit for "until I unmute". */
|
|
173
|
+
mute: (conversationId: string, until?: string | null, options?: Options) => Promise<unknown>;
|
|
174
|
+
unmute: (conversationId: string, options?: Options) => Promise<unknown>;
|
|
175
|
+
/** Clear the chat for the caller only. Undo restores the previous clear point. */
|
|
176
|
+
clear: (conversationId: string, options?: Options) => Promise<ConversationHistoryState>;
|
|
177
|
+
undoClear: (conversationId: string, options?: Options) => Promise<ConversationHistoryState>;
|
|
178
|
+
/** Delete the chat for the caller: it clears and leaves their list until a new message arrives. */
|
|
179
|
+
hide: (conversationId: string, options?: Options) => Promise<ConversationHistoryState>;
|
|
180
|
+
unhide: (conversationId: string, options?: Options) => Promise<ConversationHistoryState>;
|
|
181
|
+
addMembers: (conversationId: string, personIds: string[], options?: Options) => Promise<{
|
|
182
|
+
added: string[];
|
|
183
|
+
}>;
|
|
184
|
+
removeMember: (conversationId: string, personId: string, options?: Options) => Promise<unknown>;
|
|
185
|
+
setMemberRole: (conversationId: string, personId: string, role: "admin" | "member", options?: Options) => Promise<unknown>;
|
|
186
|
+
editDetails: (conversationId: string, change: ConversationDetailsChange, options?: Options) => Promise<unknown>;
|
|
187
|
+
/** A group's own permissions (its admins). A platform or product `off` cannot be opened (422). */
|
|
188
|
+
setControls: (conversationId: string, change: Partial<Record<GroupControlKey, GroupControlChoice>>, options?: Options) => Promise<{
|
|
189
|
+
data: Record<GroupControlKey, GroupControl>;
|
|
190
|
+
}>;
|
|
191
|
+
/** Leave a group. When the last admin leaves, the longest member becomes one (unless the policy is off). */
|
|
192
|
+
leave: (conversationId: string, options?: Options) => Promise<{
|
|
193
|
+
conversation_id: string;
|
|
194
|
+
successor_person_id: string | null;
|
|
195
|
+
}>;
|
|
196
|
+
/** Delete up to 100 messages for me or for everyone. */
|
|
197
|
+
deleteMessages: (conversationId: string, messageIds: string[], scope: "me" | "everyone", options?: Options) => Promise<MessageDeletionResult>;
|
|
198
|
+
/** Undo "delete for me". */
|
|
199
|
+
restoreMessages: (conversationId: string, messageIds: string[], options?: Options) => Promise<{
|
|
200
|
+
conversation_id: string;
|
|
201
|
+
scope: "me";
|
|
202
|
+
restored: string[];
|
|
203
|
+
}>;
|
|
204
|
+
invites: (conversationId: string, cursor?: string | null, limit?: number, options?: Options) => Promise<CursorPage<ConversationInvite>>;
|
|
205
|
+
/** `expiresAt` an ISO moment; omit for a link that lasts until revoked. */
|
|
206
|
+
createInvite: (conversationId: string, expiresAt?: string | null, options?: Options) => Promise<{
|
|
207
|
+
data: ConversationInvite;
|
|
208
|
+
}>;
|
|
209
|
+
revokeInvite: (conversationId: string, inviteId: string, options?: Options) => Promise<unknown>;
|
|
210
|
+
previewInvite: (token: string, options?: Options) => Promise<{
|
|
211
|
+
data: ConversationInvitePreview;
|
|
212
|
+
}>;
|
|
213
|
+
joinInvite: (token: string, options?: Options) => Promise<{
|
|
214
|
+
conversation_id: string;
|
|
215
|
+
joined: boolean;
|
|
216
|
+
}>;
|
|
217
|
+
};
|
|
218
|
+
export type ConversationInfoNamespace = ReturnType<typeof createConversationInfoNamespace>;
|
|
219
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { personDomainRequest } from './actors.js';
|
|
2
|
+
const BASE = '/api/person';
|
|
3
|
+
const asPerson = (options, write = false, params) => personDomainRequest({ ...options, actingAs: null }, write, params);
|
|
4
|
+
const room = (conversationId) => `${BASE}/conversations/${encodeURIComponent(conversationId)}`;
|
|
5
|
+
const page = (cursor, limit, extra = {}) => ({
|
|
6
|
+
...extra,
|
|
7
|
+
...(limit ? { limit } : {}),
|
|
8
|
+
...(cursor ? { cursor } : {}),
|
|
9
|
+
});
|
|
10
|
+
export function createConversationInfoNamespace(http) {
|
|
11
|
+
return {
|
|
12
|
+
info: (conversationId, options) => http.get(`${room(conversationId)}/info`, asPerson(options)),
|
|
13
|
+
members: (conversationId, cursor, limit, options) => http.get(`${room(conversationId)}/members`, asPerson(options, false, page(cursor, limit))),
|
|
14
|
+
shared: (conversationId, kind, cursor, limit, options) => http.get(`${room(conversationId)}/shared`, asPerson(options, false, page(cursor, limit, { kind }))),
|
|
15
|
+
|
|
16
|
+
mute: (conversationId, until, options) => http.put(`${room(conversationId)}/mute`, until ? { until } : {}, asPerson(options, true)),
|
|
17
|
+
unmute: (conversationId, options) => http.delete(`${room(conversationId)}/mute`, asPerson(options, true)),
|
|
18
|
+
|
|
19
|
+
clear: (conversationId, options) => http.put(`${room(conversationId)}/cleared`, {}, asPerson(options, true)),
|
|
20
|
+
undoClear: (conversationId, options) => http.delete(`${room(conversationId)}/cleared`, asPerson(options, true)),
|
|
21
|
+
|
|
22
|
+
hide: (conversationId, options) => http.put(`${room(conversationId)}/hidden`, {}, asPerson(options, true)),
|
|
23
|
+
unhide: (conversationId, options) => http.delete(`${room(conversationId)}/hidden`, asPerson(options, true)),
|
|
24
|
+
addMembers: (conversationId, personIds, options) => http.post(`${room(conversationId)}/members`, { person_ids: personIds }, asPerson(options, true)),
|
|
25
|
+
removeMember: (conversationId, personId, options) => http.delete(`${room(conversationId)}/members/${encodeURIComponent(personId)}`, asPerson(options, true)),
|
|
26
|
+
setMemberRole: (conversationId, personId, role, options) => http.put(`${room(conversationId)}/members/${encodeURIComponent(personId)}/role`, { role }, asPerson(options, true)),
|
|
27
|
+
editDetails: (conversationId, change, options) => http.patch(`${room(conversationId)}/details`, change, asPerson(options, true)),
|
|
28
|
+
|
|
29
|
+
setControls: (conversationId, change, options) => http.put(`${room(conversationId)}/controls`, change, asPerson(options, true)),
|
|
30
|
+
|
|
31
|
+
leave: (conversationId, options) => http.post(`${room(conversationId)}/leave`, {}, asPerson(options, true)),
|
|
32
|
+
|
|
33
|
+
deleteMessages: (conversationId, messageIds, scope, options) => http.post(`${room(conversationId)}/message-deletions`, { message_ids: messageIds, scope }, asPerson(options, true)),
|
|
34
|
+
|
|
35
|
+
restoreMessages: (conversationId, messageIds, options) => http.post(`${room(conversationId)}/message-restorations`, { message_ids: messageIds }, asPerson(options, true)),
|
|
36
|
+
invites: (conversationId, cursor, limit, options) => http.get(`${room(conversationId)}/invites`, asPerson(options, false, page(cursor, limit))),
|
|
37
|
+
|
|
38
|
+
createInvite: (conversationId, expiresAt, options) => http.post(`${room(conversationId)}/invites`, expiresAt ? { expires_at: expiresAt } : {}, asPerson(options, true)),
|
|
39
|
+
revokeInvite: (conversationId, inviteId, options) => http.delete(`${room(conversationId)}/invites/${encodeURIComponent(inviteId)}`, asPerson(options, true)),
|
|
40
|
+
previewInvite: (token, options) => http.get(`${BASE}/conversation-invites/${encodeURIComponent(token)}`, asPerson(options)),
|
|
41
|
+
joinInvite: (token, options) => http.post(`${BASE}/conversation-invites/${encodeURIComponent(token)}/join`, {}, asPerson(options, true)),
|
|
42
|
+
};
|
|
43
|
+
}
|