@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,447 @@
|
|
|
1
|
+
import { type Http } from './http.js';
|
|
2
|
+
import { type PartyReferenceString, type PersonDomainCallOptions, type PersonDomainEnvelope } from './actors.js';
|
|
3
|
+
import { type DateRangeValue, type ListPage, type ListQueryState } from './list-query.js';
|
|
4
|
+
/** A decimal string at scale ≤ 4 (`"12.5000"`). Never a number. */
|
|
5
|
+
export type ExchangeAmount = string;
|
|
6
|
+
export type ExchangeStatus = 'draft' | 'proposed' | 'accepted' | 'fulfilling' | 'disputed' | 'completed' | 'cancelled' | 'declined' | 'withdrawn' | 'expired';
|
|
7
|
+
/** The list filter core accepts: live offers, binding agreements, or closed ones. */
|
|
8
|
+
export type ExchangeListGroup = 'open' | 'binding' | 'closed';
|
|
9
|
+
/**
|
|
10
|
+
* What a party may ask of their exchanges (the server's `exchanges.mine` declaration).
|
|
11
|
+
*
|
|
12
|
+
* `status` (a stage) and `awaiting` are the list's original parameters and keep working; the
|
|
13
|
+
* declared forms are `filter.stage` and `filter.awaiting`. `filter.status` is an EXACT status.
|
|
14
|
+
*/
|
|
15
|
+
export interface ExchangeListQuery extends Omit<ListQueryState, 'sort' | 'filter'> {
|
|
16
|
+
/** @deprecated use `filter.stage` */
|
|
17
|
+
status?: ExchangeListGroup | null;
|
|
18
|
+
/** @deprecated use `filter.awaiting` */
|
|
19
|
+
awaiting?: boolean;
|
|
20
|
+
sort?: 'updated_at' | '-updated_at' | 'deadline' | '-deadline' | null;
|
|
21
|
+
filter?: {
|
|
22
|
+
status?: ExchangeStatus[] | null;
|
|
23
|
+
stage?: ExchangeListGroup[] | null;
|
|
24
|
+
awaiting?: boolean | null;
|
|
25
|
+
consideration_type?: string[] | null;
|
|
26
|
+
/** v2: exchanges with this counterpart (`person:…` / `actor:…`). */
|
|
27
|
+
counterpart?: PartyReferenceString | null;
|
|
28
|
+
/** v2: started on these days. */
|
|
29
|
+
created_at?: DateRangeValue | null;
|
|
30
|
+
/** v2: where the exchange started from (`listings.listing`) and, optionally, which one. */
|
|
31
|
+
origin_subject_type?: string | null;
|
|
32
|
+
origin_subject_id?: string | null;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/** The terms history (`exchanges.versions`): newest first by default. */
|
|
36
|
+
export interface ExchangeVersionListQuery extends Omit<ListQueryState, 'sort' | 'filter'> {
|
|
37
|
+
sort?: 'number' | '-number' | null;
|
|
38
|
+
filter?: {
|
|
39
|
+
proposed_by?: PartyReferenceString | null;
|
|
40
|
+
created_at?: DateRangeValue | null;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/** A dispute's thread (`exchanges.dispute_messages`): oldest first by default. */
|
|
44
|
+
export interface ExchangeDisputeMessageListQuery extends Omit<ListQueryState, 'sort' | 'filter' | 'search'> {
|
|
45
|
+
sort?: 'created_at' | '-created_at' | null;
|
|
46
|
+
filter?: {
|
|
47
|
+
author?: Array<'side' | 'operator'> | null;
|
|
48
|
+
has_evidence?: boolean | null;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/** What a leg carries. Verticals declare narrower consideration TYPES on one of these shapes. */
|
|
52
|
+
export type ExchangeConsiderationShape = 'stored_value' | 'subject_reference' | 'described_item' | 'service';
|
|
53
|
+
/** How a leg's fulfilment is confirmed — declared by its consideration type. */
|
|
54
|
+
export type ExchangeFulfilmentConfirmation = 'receiver_confirms' | 'both_confirm' | 'automatic_on_capture';
|
|
55
|
+
export type ExchangeLegFulfilment = 'pending' | 'delivered' | 'confirmed' | 'disputed';
|
|
56
|
+
export type ExchangeEscrowState = 'none' | 'held' | 'captured' | 'released';
|
|
57
|
+
export type ExchangeDisputeReason = 'not_delivered' | 'not_as_described' | 'damaged' | 'late' | 'other';
|
|
58
|
+
export type ExchangeDisputeOutcome = 'proceed' | 'unwind';
|
|
59
|
+
export type ExchangeDisputeStatus = 'open' | 'settled' | 'decided' | 'withdrawn';
|
|
60
|
+
export type ExchangeDisputeResolution = 'parties_then_operator' | 'operator_only';
|
|
61
|
+
export type ExchangeClosingReason = 'completed' | 'declined' | 'withdrawn' | 'expired' | 'mutual_cancellation' | 'cancelled_before_delivery' | 'dispute_unwound' | 'party_erased' | 'escrow_lost' | 'draft_discarded';
|
|
62
|
+
export interface ExchangeParty {
|
|
63
|
+
party: PartyReferenceString;
|
|
64
|
+
position: number;
|
|
65
|
+
accepted_current_version: boolean;
|
|
66
|
+
cancellation_requested: boolean;
|
|
67
|
+
/** True once the party was erased: their reference no longer names a person. */
|
|
68
|
+
pseudonymised: boolean;
|
|
69
|
+
}
|
|
70
|
+
export interface ExchangeLeg {
|
|
71
|
+
id: string;
|
|
72
|
+
position: number;
|
|
73
|
+
giver: PartyReferenceString;
|
|
74
|
+
receiver: PartyReferenceString;
|
|
75
|
+
consideration_type: string;
|
|
76
|
+
shape: ExchangeConsiderationShape;
|
|
77
|
+
confirmation: ExchangeFulfilmentConfirmation;
|
|
78
|
+
/** Credit legs: the stored-value unit and amount. */
|
|
79
|
+
unit_key: string | null;
|
|
80
|
+
/**
|
|
81
|
+
* Credit legs: the unit's currency and precision, so "40.000 JOD" needs no second request.
|
|
82
|
+
* Null on other legs, and when core could not read the unit.
|
|
83
|
+
*/
|
|
84
|
+
currency_code: string | null;
|
|
85
|
+
decimals: number | null;
|
|
86
|
+
amount: ExchangeAmount | null;
|
|
87
|
+
/** Subject-reference legs: the registered subject. */
|
|
88
|
+
subject: {
|
|
89
|
+
type: string;
|
|
90
|
+
id: string;
|
|
91
|
+
} | null;
|
|
92
|
+
description: string | null;
|
|
93
|
+
quantity: number;
|
|
94
|
+
media: string[];
|
|
95
|
+
window_starts_at: string | null;
|
|
96
|
+
window_ends_at: string | null;
|
|
97
|
+
declared_value: {
|
|
98
|
+
amount: ExchangeAmount;
|
|
99
|
+
currency: string | null;
|
|
100
|
+
} | null;
|
|
101
|
+
attributes: Record<string, unknown>;
|
|
102
|
+
fulfilment: ExchangeLegFulfilment;
|
|
103
|
+
delivered_at: string | null;
|
|
104
|
+
giver_confirmed_at: string | null;
|
|
105
|
+
receiver_confirmed_at: string | null;
|
|
106
|
+
confirmed_at: string | null;
|
|
107
|
+
escrow: ExchangeEscrowState;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* One terms version: the one on the table (`Exchange.current_version`) or a row of the history
|
|
111
|
+
* (`versions()`, newest first). A version is never edited.
|
|
112
|
+
*/
|
|
113
|
+
export interface ExchangeVersion {
|
|
114
|
+
id: string;
|
|
115
|
+
number: number;
|
|
116
|
+
proposed_by: PartyReferenceString;
|
|
117
|
+
note: string | null;
|
|
118
|
+
created_at: string;
|
|
119
|
+
/** References of the parties that accepted THIS version. */
|
|
120
|
+
accepted_by: PartyReferenceString[];
|
|
121
|
+
legs: ExchangeLeg[];
|
|
122
|
+
}
|
|
123
|
+
export interface ExchangeDispute {
|
|
124
|
+
id: string;
|
|
125
|
+
exchange_id: string;
|
|
126
|
+
leg_id: string;
|
|
127
|
+
raised_by: PartyReferenceString;
|
|
128
|
+
reason: ExchangeDisputeReason;
|
|
129
|
+
statement: string | null;
|
|
130
|
+
evidence_media: string[];
|
|
131
|
+
resolution_mode: ExchangeDisputeResolution;
|
|
132
|
+
status: ExchangeDisputeStatus;
|
|
133
|
+
outcome: ExchangeDisputeOutcome | null;
|
|
134
|
+
/** Keyed by party reference: what each side answered so far. */
|
|
135
|
+
answers: Record<string, ExchangeDisputeOutcome>;
|
|
136
|
+
escalate_at: string | null;
|
|
137
|
+
escalated_at: string | null;
|
|
138
|
+
opened_at: string;
|
|
139
|
+
resolved_at: string | null;
|
|
140
|
+
resolution_note: string | null;
|
|
141
|
+
}
|
|
142
|
+
/** The policies frozen into the exchange at proposal (`exchanges.<key>` → option). */
|
|
143
|
+
export type ExchangePolicySnapshot = Partial<Record<'exchanges.offer_lifetime' | 'exchanges.maximum_parties' | 'exchanges.counter_limit' | 'exchanges.dispute_resolution' | 'exchanges.dispute_escalation' | 'exchanges.rating_window' | 'exchanges.stored_value_legs' | 'exchanges.fulfilment_period' | 'exchanges.cancellation_after_acceptance', string>> & Record<string, string>;
|
|
144
|
+
export interface Exchange {
|
|
145
|
+
id: string;
|
|
146
|
+
status: ExchangeStatus;
|
|
147
|
+
initiator: PartyReferenceString;
|
|
148
|
+
parties: ExchangeParty[];
|
|
149
|
+
current_version: ExchangeVersion;
|
|
150
|
+
accepted_version_id: string | null;
|
|
151
|
+
counter_count: number;
|
|
152
|
+
discoverable: boolean;
|
|
153
|
+
origin_subject: {
|
|
154
|
+
type: string;
|
|
155
|
+
id: string;
|
|
156
|
+
} | null;
|
|
157
|
+
policies: ExchangePolicySnapshot;
|
|
158
|
+
attributes: Record<string, unknown>;
|
|
159
|
+
disputes: ExchangeDispute[];
|
|
160
|
+
expires_at: string | null;
|
|
161
|
+
proposed_at: string | null;
|
|
162
|
+
accepted_at: string | null;
|
|
163
|
+
fulfilment_due_at: string | null;
|
|
164
|
+
completed_at: string | null;
|
|
165
|
+
closed_at: string | null;
|
|
166
|
+
closing_reason: ExchangeClosingReason | null;
|
|
167
|
+
created_at: string;
|
|
168
|
+
updated_at: string;
|
|
169
|
+
}
|
|
170
|
+
/** A write's answer: the exchange as it now stands; `replayed` when the key matched a retry. */
|
|
171
|
+
export interface ExchangeWriteAnswer extends PersonDomainEnvelope<Exchange> {
|
|
172
|
+
replayed: boolean;
|
|
173
|
+
}
|
|
174
|
+
/** One row of the person's exchanges. */
|
|
175
|
+
export interface ExchangeSummary {
|
|
176
|
+
id: string;
|
|
177
|
+
status: ExchangeStatus;
|
|
178
|
+
initiator: PartyReferenceString;
|
|
179
|
+
parties: PartyReferenceString[];
|
|
180
|
+
current_version_number: number;
|
|
181
|
+
leg_count: number;
|
|
182
|
+
/**
|
|
183
|
+
* A step is waiting on the acting party — accept, deliver, confirm, answer a dispute or a
|
|
184
|
+
* request to call it off. Decided by the same rules core applies when the party acts.
|
|
185
|
+
*/
|
|
186
|
+
awaiting_viewer: boolean;
|
|
187
|
+
expires_at: string | null;
|
|
188
|
+
updated_at: string;
|
|
189
|
+
/** v2: where the exchange started from (a listing), or null. */
|
|
190
|
+
origin_subject?: {
|
|
191
|
+
type: string;
|
|
192
|
+
id: string;
|
|
193
|
+
} | null;
|
|
194
|
+
/** v2: when it was started. */
|
|
195
|
+
created_at?: string;
|
|
196
|
+
/**
|
|
197
|
+
* v2: each party's RECEIVED exchange ratings, keyed by party reference; null = none yet, or
|
|
198
|
+
* a business profile (not summarised yet). Empty object when ratings could not be read.
|
|
199
|
+
*/
|
|
200
|
+
party_ratings?: Record<string, ExchangePartyRating | null>;
|
|
201
|
+
}
|
|
202
|
+
/** A party's received ratings of exchanges: how many, and the average as a decimal string. */
|
|
203
|
+
export interface ExchangePartyRating {
|
|
204
|
+
count: number;
|
|
205
|
+
average: string;
|
|
206
|
+
}
|
|
207
|
+
/** One file of dispute evidence as the viewer may see it (from the media pipeline). */
|
|
208
|
+
export interface ExchangeEvidenceMedia {
|
|
209
|
+
id: string;
|
|
210
|
+
kind: 'image' | 'video' | 'audio';
|
|
211
|
+
status: string;
|
|
212
|
+
mime_type: string;
|
|
213
|
+
size_bytes: number | null;
|
|
214
|
+
width: number | null;
|
|
215
|
+
height: number | null;
|
|
216
|
+
duration_milliseconds: number | null;
|
|
217
|
+
alt_text: {
|
|
218
|
+
en: string | null;
|
|
219
|
+
ar: string | null;
|
|
220
|
+
};
|
|
221
|
+
placeholder: {
|
|
222
|
+
blurhash: string | null;
|
|
223
|
+
dominant_colour: string | null;
|
|
224
|
+
aspect_ratio: number | null;
|
|
225
|
+
};
|
|
226
|
+
/** `<picture>`-ready: best format first; URLs are relative, signed and short-lived. */
|
|
227
|
+
sources: Array<{
|
|
228
|
+
format: string;
|
|
229
|
+
mime_type: string;
|
|
230
|
+
srcset: Array<{
|
|
231
|
+
url: string | null;
|
|
232
|
+
width: number | null;
|
|
233
|
+
height: number | null;
|
|
234
|
+
}>;
|
|
235
|
+
}>;
|
|
236
|
+
renditions: Array<{
|
|
237
|
+
key: string;
|
|
238
|
+
mime_type: string;
|
|
239
|
+
width: number | null;
|
|
240
|
+
height: number | null;
|
|
241
|
+
url: string | null;
|
|
242
|
+
}>;
|
|
243
|
+
}
|
|
244
|
+
/** One message in a dispute's thread. */
|
|
245
|
+
export interface ExchangeDisputeMessage {
|
|
246
|
+
id: string;
|
|
247
|
+
dispute_id: string;
|
|
248
|
+
exchange_id: string;
|
|
249
|
+
/** The party that wrote it; null for the operator (never named to parties). */
|
|
250
|
+
author: PartyReferenceString | null;
|
|
251
|
+
by_operator: boolean;
|
|
252
|
+
/** Null when the message is evidence only, or its author was erased. */
|
|
253
|
+
body: string | null;
|
|
254
|
+
/** The statement the dispute was raised with. */
|
|
255
|
+
opens_dispute: boolean;
|
|
256
|
+
author_erased: boolean;
|
|
257
|
+
/** How many files were attached — `evidence` lists the ones the viewer may see now. */
|
|
258
|
+
evidence_count: number;
|
|
259
|
+
evidence: ExchangeEvidenceMedia[];
|
|
260
|
+
created_at: string;
|
|
261
|
+
}
|
|
262
|
+
export interface PostExchangeDisputeMessageRequest {
|
|
263
|
+
/** Up to 4,000 characters. Required unless evidence is attached. */
|
|
264
|
+
body?: string | null;
|
|
265
|
+
/** Up to ten media ids uploaded under purpose {@link EXCHANGE_DISPUTE_EVIDENCE_PURPOSE}. */
|
|
266
|
+
evidence_media?: string[] | null;
|
|
267
|
+
}
|
|
268
|
+
/** The media purpose dispute evidence is uploaded under (images and short video). */
|
|
269
|
+
export declare const EXCHANGE_DISPUTE_EVIDENCE_PURPOSE = "exchanges.dispute_evidence";
|
|
270
|
+
/** At most this many evidence files per message, and characters per message body. */
|
|
271
|
+
export declare const EXCHANGE_DISPUTE_MAXIMUM_EVIDENCE = 10;
|
|
272
|
+
export declare const EXCHANGE_DISPUTE_MAXIMUM_BODY = 4000;
|
|
273
|
+
/** Who must own a referenced subject for a consideration type to accept it. */
|
|
274
|
+
export type ExchangeSubjectOwnership = 'any' | 'giver_owns' | 'receiver_owns';
|
|
275
|
+
/** One consideration type a party may put on a leg in this vertical (`consideration-types`). */
|
|
276
|
+
export interface ExchangeConsiderationType {
|
|
277
|
+
key: string;
|
|
278
|
+
label: {
|
|
279
|
+
en: string;
|
|
280
|
+
ar: string;
|
|
281
|
+
};
|
|
282
|
+
shape: ExchangeConsiderationShape;
|
|
283
|
+
confirmation: ExchangeFulfilmentConfirmation;
|
|
284
|
+
/** Subject types a subject-reference leg of this type accepts; empty = any registered type. */
|
|
285
|
+
subject_types: string[];
|
|
286
|
+
subject_ownership: ExchangeSubjectOwnership;
|
|
287
|
+
/** The `Platform/Attributes` subject whose declared fields a leg of this type may carry. */
|
|
288
|
+
attribute_subject_key: string | null;
|
|
289
|
+
/** Null for core's types; the vertical's key for its own. */
|
|
290
|
+
vertical_key: string | null;
|
|
291
|
+
}
|
|
292
|
+
/** One leg as proposed. Only the fields its consideration type's shape needs are read. */
|
|
293
|
+
export interface ProposedExchangeLeg {
|
|
294
|
+
giver: PartyReferenceString;
|
|
295
|
+
receiver: PartyReferenceString;
|
|
296
|
+
/** `lower_snake_case`, declared by core or a vertical. */
|
|
297
|
+
consideration_type: string;
|
|
298
|
+
unit_key?: string | null;
|
|
299
|
+
amount?: ExchangeAmount | null;
|
|
300
|
+
subject_type?: string | null;
|
|
301
|
+
subject_id?: string | null;
|
|
302
|
+
description?: string | null;
|
|
303
|
+
quantity?: number | null;
|
|
304
|
+
media?: string[] | null;
|
|
305
|
+
window_starts_at?: string | null;
|
|
306
|
+
window_ends_at?: string | null;
|
|
307
|
+
declared_value?: ExchangeAmount | null;
|
|
308
|
+
declared_value_currency?: string | null;
|
|
309
|
+
attributes?: Record<string, unknown> | null;
|
|
310
|
+
}
|
|
311
|
+
export interface ProposeExchangeRequest {
|
|
312
|
+
/** Every party, the acting one included (1–9 references; `person:` or `actor:` only). */
|
|
313
|
+
parties: PartyReferenceString[];
|
|
314
|
+
legs: ProposedExchangeLeg[];
|
|
315
|
+
note?: string | null;
|
|
316
|
+
/** Save without sending; `submit` sends it later. */
|
|
317
|
+
draft?: boolean;
|
|
318
|
+
discoverable?: boolean;
|
|
319
|
+
origin_subject_type?: string | null;
|
|
320
|
+
origin_subject_id?: string | null;
|
|
321
|
+
attributes?: Record<string, unknown> | null;
|
|
322
|
+
}
|
|
323
|
+
/** A counter-offer: new legs (and note) for the same parties. */
|
|
324
|
+
export interface CounterExchangeRequest {
|
|
325
|
+
legs: ProposedExchangeLeg[];
|
|
326
|
+
note?: string | null;
|
|
327
|
+
}
|
|
328
|
+
export interface RaiseExchangeDisputeRequest {
|
|
329
|
+
reason: ExchangeDisputeReason;
|
|
330
|
+
statement?: string | null;
|
|
331
|
+
/** Up to ten uploaded file ids. */
|
|
332
|
+
evidence_media?: string[] | null;
|
|
333
|
+
}
|
|
334
|
+
/** The regex core validates every amount against. Exported so a form can check before sending. */
|
|
335
|
+
export declare const EXCHANGE_AMOUNT_PATTERN: RegExp;
|
|
336
|
+
/** At most this many party references in one proposal (core's `parties` rule, max:9). */
|
|
337
|
+
export declare const EXCHANGE_MAXIMUM_PARTIES_IN_REQUEST = 9;
|
|
338
|
+
/** The stable reason keys a screen may react to (core's `ExchangeRefused`). */
|
|
339
|
+
export declare const EXCHANGE_REFUSAL: {
|
|
340
|
+
readonly notFound: "exchange_not_found";
|
|
341
|
+
readonly notPermittedAsParty: "exchange_not_permitted_as_party";
|
|
342
|
+
readonly invalidState: "exchange_invalid_state";
|
|
343
|
+
readonly versionStale: "exchange_version_stale";
|
|
344
|
+
readonly expired: "exchange_expired";
|
|
345
|
+
readonly partyCount: "exchange_party_count";
|
|
346
|
+
readonly partyUnavailable: "exchange_party_unavailable";
|
|
347
|
+
readonly partyKindNotAccepted: "exchange_party_kind_not_accepted";
|
|
348
|
+
readonly termsInvalid: "exchange_terms_invalid";
|
|
349
|
+
readonly considerationTypeUnknown: "exchange_consideration_type_unknown";
|
|
350
|
+
readonly storedValueNotAllowed: "exchange_stored_value_not_allowed";
|
|
351
|
+
readonly storedValueUnavailable: "exchange_stored_value_unavailable";
|
|
352
|
+
readonly subjectUnavailable: "exchange_subject_unavailable";
|
|
353
|
+
readonly counterLimitReached: "exchange_counter_limit_reached";
|
|
354
|
+
readonly openProposalLimitReached: "exchange_open_proposal_limit_reached";
|
|
355
|
+
readonly notYourTurn: "exchange_not_your_turn";
|
|
356
|
+
readonly legNotFound: "exchange_leg_not_found";
|
|
357
|
+
readonly legInvalidState: "exchange_leg_invalid_state";
|
|
358
|
+
readonly disputeNotFound: "exchange_dispute_not_found";
|
|
359
|
+
readonly disputeClosed: "exchange_dispute_closed";
|
|
360
|
+
readonly disputeOperatorOnly: "exchange_dispute_operator_only";
|
|
361
|
+
readonly idempotencyKeyReused: "exchange_idempotency_key_reused";
|
|
362
|
+
readonly safetyCheckUnavailable: "exchange_safety_check_unavailable";
|
|
363
|
+
};
|
|
364
|
+
export type ExchangeRefusalReason = (typeof EXCHANGE_REFUSAL)[keyof typeof EXCHANGE_REFUSAL];
|
|
365
|
+
/** The stable `reason` of a refused call (core's `{message, reason}`), else the global middleware's `code` (`idempotency_key_reused`), or null. See {@link refusalReason}. */
|
|
366
|
+
export declare function exchangeRefusalReason(error: unknown): string | null;
|
|
367
|
+
/** True when core refused because a newer version replaced the one acted on. */
|
|
368
|
+
export declare function isStaleExchangeVersion(error: unknown): boolean;
|
|
369
|
+
/**
|
|
370
|
+
* Refuses terms that would send a credit amount as anything but an exact decimal string — a
|
|
371
|
+
* number (`12.5` is already a float), an exponent, a sign, five decimals. Called by `propose`
|
|
372
|
+
* and `counter` before sending; exported for forms that want to check early.
|
|
373
|
+
*/
|
|
374
|
+
export declare function assertExchangeTermsAreExact(legs: ProposedExchangeLeg[]): void;
|
|
375
|
+
export declare function createExchangesNamespace(http: Http): {
|
|
376
|
+
/**
|
|
377
|
+
* GET / — the acting party's exchanges as a declared list (`exchanges.mine`): newest
|
|
378
|
+
* activity first by default; `sort: 'deadline'` for the next date that matters;
|
|
379
|
+
* `filter: { status, stage, awaiting, consideration_type }`; `search` over what the current
|
|
380
|
+
* terms offer; `describe: true` for `meta.list`. The original `status` (a stage) and
|
|
381
|
+
* `awaiting: true` are still sent as before, so older callers answer identically.
|
|
382
|
+
*/
|
|
383
|
+
list: (query?: ExchangeListQuery, options?: PersonDomainCallOptions) => Promise<ListPage<ExchangeSummary>>;
|
|
384
|
+
/**
|
|
385
|
+
* GET /consideration-types?shape= — what may go on a leg here: core's types and the bound
|
|
386
|
+
* vertical's own, less credit where the party's policy forbids it. Exactly what `propose`
|
|
387
|
+
* accepts.
|
|
388
|
+
*/
|
|
389
|
+
considerationTypes: (query?: {
|
|
390
|
+
shape?: ExchangeConsiderationShape | null;
|
|
391
|
+
}, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<ExchangeConsiderationType[]>>;
|
|
392
|
+
/** GET /{id} — one exchange as a party sees it. Not a party: 404. */
|
|
393
|
+
show: (exchangeId: string, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<Exchange>>;
|
|
394
|
+
/**
|
|
395
|
+
* GET /{id}/versions — the terms history as a declared list (`exchanges.versions`): newest
|
|
396
|
+
* first by default, `sort: 'number'` for oldest first, `filter: { proposed_by, created_at }`.
|
|
397
|
+
* Not a party: 404.
|
|
398
|
+
*/
|
|
399
|
+
versions: (exchangeId: string, query?: ExchangeVersionListQuery, options?: PersonDomainCallOptions) => Promise<ListPage<ExchangeVersion>>;
|
|
400
|
+
/** POST / — propose (or save a draft). 201 new, 200 replayed. Proposing accepts your own terms. */
|
|
401
|
+
propose: (request: ProposeExchangeRequest, options?: PersonDomainCallOptions) => Promise<ExchangeWriteAnswer>;
|
|
402
|
+
/** POST /{id}/versions/{version}/counter — new terms replacing the version named. */
|
|
403
|
+
counter: (exchangeId: string, versionId: string, request: CounterExchangeRequest, options?: PersonDomainCallOptions) => Promise<ExchangeWriteAnswer>;
|
|
404
|
+
/**
|
|
405
|
+
* POST /{id}/versions/{version}/accept — accept THE VERSION SHOWN. Holds the acting party's
|
|
406
|
+
* outgoing credit. A newer version → `exchange_version_stale` ({@link isStaleExchangeVersion}).
|
|
407
|
+
*/
|
|
408
|
+
accept: (exchangeId: string, versionId: string, options?: PersonDomainCallOptions) => Promise<ExchangeWriteAnswer>;
|
|
409
|
+
/** POST /{id}/versions/{version}/decline — decline the version shown; closes the exchange. */
|
|
410
|
+
decline: (exchangeId: string, versionId: string, options?: PersonDomainCallOptions) => Promise<ExchangeWriteAnswer>;
|
|
411
|
+
/** POST /{id}/submit — send a saved draft. */
|
|
412
|
+
submit: (exchangeId: string, options?: PersonDomainCallOptions) => Promise<ExchangeWriteAnswer>;
|
|
413
|
+
/** POST /{id}/withdraw — withdraw a live proposal, or discard a draft. */
|
|
414
|
+
withdraw: (exchangeId: string, options?: PersonDomainCallOptions) => Promise<ExchangeWriteAnswer>;
|
|
415
|
+
legs: {
|
|
416
|
+
/** POST /{id}/legs/{leg}/delivered — the giving party says it was handed over. */
|
|
417
|
+
markDelivered: (exchangeId: string, legId: string, options?: PersonDomainCallOptions) => Promise<ExchangeWriteAnswer>;
|
|
418
|
+
/** POST /{id}/legs/{leg}/confirm — the receiving party (and, for `both_confirm`, the giver) confirms. */
|
|
419
|
+
confirm: (exchangeId: string, legId: string, options?: PersonDomainCallOptions) => Promise<ExchangeWriteAnswer>;
|
|
420
|
+
/** POST /{id}/legs/{leg}/disputes — report a problem with a non-credit leg. 201 new, 200 replayed. */
|
|
421
|
+
dispute: (exchangeId: string, legId: string, request: RaiseExchangeDisputeRequest, options?: PersonDomainCallOptions) => Promise<ExchangeWriteAnswer>;
|
|
422
|
+
};
|
|
423
|
+
cancellation: {
|
|
424
|
+
/** POST /{id}/cancellation — ask to cancel (policy: mutual, or any party before delivery). */
|
|
425
|
+
request: (exchangeId: string, options?: PersonDomainCallOptions) => Promise<ExchangeWriteAnswer>;
|
|
426
|
+
/** DELETE /{id}/cancellation — take the request back. */
|
|
427
|
+
retract: (exchangeId: string, options?: PersonDomainCallOptions) => Promise<ExchangeWriteAnswer>;
|
|
428
|
+
};
|
|
429
|
+
disputes: {
|
|
430
|
+
/** POST /{id}/disputes/{dispute}/answer — `proceed` (the leg counts as done) or `unwind`. */
|
|
431
|
+
answer: (exchangeId: string, disputeId: string, outcome: ExchangeDisputeOutcome, note?: string | null, options?: PersonDomainCallOptions) => Promise<ExchangeWriteAnswer>;
|
|
432
|
+
/** POST /{id}/disputes/{dispute}/withdraw — the raiser takes it back. */
|
|
433
|
+
withdraw: (exchangeId: string, disputeId: string, options?: PersonDomainCallOptions) => Promise<ExchangeWriteAnswer>;
|
|
434
|
+
/**
|
|
435
|
+
* GET /{id}/disputes/{dispute}/messages — the dispute's thread (`exchanges.dispute_messages`),
|
|
436
|
+
* oldest first; evidence resolved for the viewer. Parties only (404 otherwise).
|
|
437
|
+
*/
|
|
438
|
+
messages: (exchangeId: string, disputeId: string, query?: ExchangeDisputeMessageListQuery, options?: PersonDomainCallOptions) => Promise<ListPage<ExchangeDisputeMessage>>;
|
|
439
|
+
/**
|
|
440
|
+
* POST /{id}/disputes/{dispute}/messages — a side of the disputed leg adds words and/or
|
|
441
|
+
* evidence while the dispute is open. Upload files first under
|
|
442
|
+
* {@link EXCHANGE_DISPUTE_EVIDENCE_PURPOSE}, then name their ids. 201 new, 200 replayed.
|
|
443
|
+
*/
|
|
444
|
+
postMessage: (exchangeId: string, disputeId: string, request: PostExchangeDisputeMessageRequest, options?: PersonDomainCallOptions) => Promise<ExchangeWriteAnswer>;
|
|
445
|
+
};
|
|
446
|
+
};
|
|
447
|
+
export type ExchangesNamespace = ReturnType<typeof createExchangesNamespace>;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { refusalReason } from './http.js';
|
|
4
|
+
import { personDomainRequest, } from './actors.js';
|
|
5
|
+
import { listQueryParams } from './list-query.js';
|
|
6
|
+
|
|
7
|
+
export const EXCHANGE_DISPUTE_EVIDENCE_PURPOSE = 'exchanges.dispute_evidence';
|
|
8
|
+
|
|
9
|
+
export const EXCHANGE_DISPUTE_MAXIMUM_EVIDENCE = 10;
|
|
10
|
+
export const EXCHANGE_DISPUTE_MAXIMUM_BODY = 4000;
|
|
11
|
+
|
|
12
|
+
export const EXCHANGE_AMOUNT_PATTERN = /^\d{1,15}(\.\d{1,4})?$/;
|
|
13
|
+
|
|
14
|
+
export const EXCHANGE_MAXIMUM_PARTIES_IN_REQUEST = 9;
|
|
15
|
+
|
|
16
|
+
export const EXCHANGE_REFUSAL = {
|
|
17
|
+
notFound: 'exchange_not_found',
|
|
18
|
+
notPermittedAsParty: 'exchange_not_permitted_as_party',
|
|
19
|
+
invalidState: 'exchange_invalid_state',
|
|
20
|
+
versionStale: 'exchange_version_stale',
|
|
21
|
+
expired: 'exchange_expired',
|
|
22
|
+
partyCount: 'exchange_party_count',
|
|
23
|
+
partyUnavailable: 'exchange_party_unavailable',
|
|
24
|
+
partyKindNotAccepted: 'exchange_party_kind_not_accepted',
|
|
25
|
+
termsInvalid: 'exchange_terms_invalid',
|
|
26
|
+
considerationTypeUnknown: 'exchange_consideration_type_unknown',
|
|
27
|
+
storedValueNotAllowed: 'exchange_stored_value_not_allowed',
|
|
28
|
+
storedValueUnavailable: 'exchange_stored_value_unavailable',
|
|
29
|
+
subjectUnavailable: 'exchange_subject_unavailable',
|
|
30
|
+
counterLimitReached: 'exchange_counter_limit_reached',
|
|
31
|
+
openProposalLimitReached: 'exchange_open_proposal_limit_reached',
|
|
32
|
+
notYourTurn: 'exchange_not_your_turn',
|
|
33
|
+
legNotFound: 'exchange_leg_not_found',
|
|
34
|
+
legInvalidState: 'exchange_leg_invalid_state',
|
|
35
|
+
disputeNotFound: 'exchange_dispute_not_found',
|
|
36
|
+
disputeClosed: 'exchange_dispute_closed',
|
|
37
|
+
disputeOperatorOnly: 'exchange_dispute_operator_only',
|
|
38
|
+
idempotencyKeyReused: 'exchange_idempotency_key_reused',
|
|
39
|
+
safetyCheckUnavailable: 'exchange_safety_check_unavailable',
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export function exchangeRefusalReason(error) {
|
|
43
|
+
return refusalReason(error);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function isStaleExchangeVersion(error) {
|
|
47
|
+
return exchangeRefusalReason(error) === EXCHANGE_REFUSAL.versionStale;
|
|
48
|
+
}
|
|
49
|
+
const UUID = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
|
|
50
|
+
function assertIdentifier(value, what) {
|
|
51
|
+
if (typeof value !== 'string' || !UUID.test(value)) {
|
|
52
|
+
|
|
53
|
+
throw new TypeError(`exchanges: ${what} must be a uuid, got ${JSON.stringify(value)}.`);
|
|
54
|
+
}
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function assertExchangeTermsAreExact(legs) {
|
|
59
|
+
legs.forEach((leg, index) => {
|
|
60
|
+
for (const field of ['amount', 'declared_value']) {
|
|
61
|
+
const value = leg[field];
|
|
62
|
+
if (value === undefined || value === null)
|
|
63
|
+
continue;
|
|
64
|
+
if (typeof value !== 'string' || !EXCHANGE_AMOUNT_PATTERN.test(value)) {
|
|
65
|
+
throw new TypeError(`exchanges: legs[${index}].${field} must be a decimal string with at most four decimals, got ${JSON.stringify(value)}.`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
const BASE = '/api/person/exchanges';
|
|
71
|
+
export function createExchangesNamespace(http) {
|
|
72
|
+
const read = (options, params) => personDomainRequest(options, false, params);
|
|
73
|
+
const write = (options) => personDomainRequest(options, true);
|
|
74
|
+
const exchangePath = (exchangeId) => `${BASE}/${assertIdentifier(exchangeId, 'exchangeId')}`;
|
|
75
|
+
return {
|
|
76
|
+
|
|
77
|
+
list: (query = {}, options) => {
|
|
78
|
+
const { status, awaiting, ...declared } = query;
|
|
79
|
+
return http.get(BASE, read(options, {
|
|
80
|
+
status: status ?? undefined,
|
|
81
|
+
awaiting: awaiting ? 1 : undefined,
|
|
82
|
+
...listQueryParams(declared),
|
|
83
|
+
}));
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
considerationTypes: (query = {}, options) => http.get(`${BASE}/consideration-types`, read(options, { shape: query.shape ?? undefined })),
|
|
87
|
+
|
|
88
|
+
show: (exchangeId, options) => http.get(exchangePath(exchangeId), read(options)),
|
|
89
|
+
|
|
90
|
+
versions: (exchangeId, query = {}, options) => http.get(`${exchangePath(exchangeId)}/versions`, read(options, listQueryParams(query))),
|
|
91
|
+
|
|
92
|
+
propose: (request, options) => {
|
|
93
|
+
assertExchangeTermsAreExact(request.legs);
|
|
94
|
+
return http.post(BASE, request, write(options));
|
|
95
|
+
},
|
|
96
|
+
|
|
97
|
+
counter: (exchangeId, versionId, request, options) => {
|
|
98
|
+
assertExchangeTermsAreExact(request.legs);
|
|
99
|
+
return http.post(`${exchangePath(exchangeId)}/versions/${assertIdentifier(versionId, 'versionId')}/counter`, request, write(options));
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
accept: (exchangeId, versionId, options) => http.post(`${exchangePath(exchangeId)}/versions/${assertIdentifier(versionId, 'versionId')}/accept`, undefined, write(options)),
|
|
103
|
+
|
|
104
|
+
decline: (exchangeId, versionId, options) => http.post(`${exchangePath(exchangeId)}/versions/${assertIdentifier(versionId, 'versionId')}/decline`, undefined, write(options)),
|
|
105
|
+
|
|
106
|
+
submit: (exchangeId, options) => http.post(`${exchangePath(exchangeId)}/submit`, undefined, write(options)),
|
|
107
|
+
|
|
108
|
+
withdraw: (exchangeId, options) => http.post(`${exchangePath(exchangeId)}/withdraw`, undefined, write(options)),
|
|
109
|
+
legs: {
|
|
110
|
+
|
|
111
|
+
markDelivered: (exchangeId, legId, options) => http.post(`${exchangePath(exchangeId)}/legs/${assertIdentifier(legId, 'legId')}/delivered`, undefined, write(options)),
|
|
112
|
+
|
|
113
|
+
confirm: (exchangeId, legId, options) => http.post(`${exchangePath(exchangeId)}/legs/${assertIdentifier(legId, 'legId')}/confirm`, undefined, write(options)),
|
|
114
|
+
|
|
115
|
+
dispute: (exchangeId, legId, request, options) => http.post(`${exchangePath(exchangeId)}/legs/${assertIdentifier(legId, 'legId')}/disputes`, request, write(options)),
|
|
116
|
+
},
|
|
117
|
+
cancellation: {
|
|
118
|
+
|
|
119
|
+
request: (exchangeId, options) => http.post(`${exchangePath(exchangeId)}/cancellation`, undefined, write(options)),
|
|
120
|
+
|
|
121
|
+
retract: (exchangeId, options) => http.delete(`${exchangePath(exchangeId)}/cancellation`, write(options)),
|
|
122
|
+
},
|
|
123
|
+
disputes: {
|
|
124
|
+
|
|
125
|
+
answer: (exchangeId, disputeId, outcome, note, options) => http.post(`${exchangePath(exchangeId)}/disputes/${assertIdentifier(disputeId, 'disputeId')}/answer`, { outcome, note: note ?? null }, write(options)),
|
|
126
|
+
|
|
127
|
+
withdraw: (exchangeId, disputeId, options) => http.post(`${exchangePath(exchangeId)}/disputes/${assertIdentifier(disputeId, 'disputeId')}/withdraw`, undefined, write(options)),
|
|
128
|
+
|
|
129
|
+
messages: (exchangeId, disputeId, query = {}, options) => http.get(`${exchangePath(exchangeId)}/disputes/${assertIdentifier(disputeId, 'disputeId')}/messages`, read(options, listQueryParams(query))),
|
|
130
|
+
|
|
131
|
+
postMessage: (exchangeId, disputeId, request, options) => {
|
|
132
|
+
const body = request.body?.trim() ?? '';
|
|
133
|
+
const evidence = request.evidence_media ?? [];
|
|
134
|
+
if (body === '' && evidence.length === 0) {
|
|
135
|
+
throw new TypeError('exchanges: a dispute message needs words or evidence.');
|
|
136
|
+
}
|
|
137
|
+
if (evidence.length > EXCHANGE_DISPUTE_MAXIMUM_EVIDENCE) {
|
|
138
|
+
throw new TypeError(`exchanges: at most ${EXCHANGE_DISPUTE_MAXIMUM_EVIDENCE} evidence files per message.`);
|
|
139
|
+
}
|
|
140
|
+
evidence.forEach((id) => assertIdentifier(id, 'evidence_media[]'));
|
|
141
|
+
return http.post(`${exchangePath(exchangeId)}/disputes/${assertIdentifier(disputeId, 'disputeId')}/messages`, { body: body === '' ? null : body, evidence_media: evidence }, write(options));
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
}
|