@ziggs-ai/api-client 0.36.1 → 0.36.2
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { marketplaceFormation } from '../engagementGuide.js';
|
|
2
|
-
import {
|
|
2
|
+
import { pullOffersPage, pullRequests } from '../http/MarketplaceClient.js';
|
|
3
3
|
import { fullCreds } from './types.js';
|
|
4
4
|
import { nextCall } from './nextCall.js';
|
|
5
5
|
import { LIST_FIELDS_PARAM, parseListFields, pickListedRows } from './listedFields.js';
|
|
@@ -94,10 +94,13 @@ export const marketplaceViewCapability = {
|
|
|
94
94
|
limit: typeof args['limit'] === 'number' ? args['limit'] : 20,
|
|
95
95
|
...(args['since'] ? { since: args['since'] } : {}),
|
|
96
96
|
};
|
|
97
|
-
const [requests,
|
|
97
|
+
const [requests, offerPage] = await Promise.all([
|
|
98
98
|
kind === 'offers' ? Promise.resolve([]) : pullRequests(options, creds),
|
|
99
|
-
kind === 'requests'
|
|
99
|
+
kind === 'requests'
|
|
100
|
+
? Promise.resolve({ offers: [], total: null, hasMore: false })
|
|
101
|
+
: pullOffersPage(options, creds),
|
|
100
102
|
]);
|
|
103
|
+
const offers = offerPage.offers;
|
|
101
104
|
const fields = parseListFields(args['fields']);
|
|
102
105
|
const requestRows = pickListedRows(requests.map((q) => toListingRow(q, 'request')), fields);
|
|
103
106
|
const offerRows = pickListedRows(offers.map((o) => toListingRow(o, 'offer')), fields);
|
|
@@ -110,7 +113,20 @@ export const marketplaceViewCapability = {
|
|
|
110
113
|
? { requests: requestRows, requestCount: requests.length }
|
|
111
114
|
: {}),
|
|
112
115
|
...(kind !== 'requests'
|
|
113
|
-
? {
|
|
116
|
+
? {
|
|
117
|
+
offers: offerRows,
|
|
118
|
+
offerCount: offers.length,
|
|
119
|
+
// The board is capped: say so only when more exist, so the count
|
|
120
|
+
// above is never read as all of them.
|
|
121
|
+
...(offerPage.hasMore
|
|
122
|
+
? {
|
|
123
|
+
moreOffers: {
|
|
124
|
+
total: offerPage.total,
|
|
125
|
+
note: 'More listings exist than this read returned. Read again with a larger limit (at most 100) or narrow with since.',
|
|
126
|
+
},
|
|
127
|
+
}
|
|
128
|
+
: {}),
|
|
129
|
+
}
|
|
114
130
|
: {}),
|
|
115
131
|
engagement,
|
|
116
132
|
// Claiming is the move after browsing, and the id is in the row the
|
|
@@ -47,6 +47,16 @@ export interface PullOffersOptions {
|
|
|
47
47
|
since?: string;
|
|
48
48
|
}
|
|
49
49
|
export declare function pullOffers(options: PullOffersOptions | undefined, creds: Creds): Promise<Agreement[]>;
|
|
50
|
+
/**
|
|
51
|
+
* The board read with its total. The board is capped (at most 100 rows), so
|
|
52
|
+
* the number of rows returned is not the number of listings. `total` and
|
|
53
|
+
* `hasMore` are absent from an older server; read them as unknown, not none.
|
|
54
|
+
*/
|
|
55
|
+
export declare function pullOffersPage(options: PullOffersOptions | undefined, creds: Creds): Promise<{
|
|
56
|
+
offers: Agreement[];
|
|
57
|
+
total: number | null;
|
|
58
|
+
hasMore: boolean;
|
|
59
|
+
}>;
|
|
50
60
|
export interface PullRequestsOptions {
|
|
51
61
|
limit?: number;
|
|
52
62
|
since?: string;
|
|
@@ -64,6 +64,14 @@ async function setOfferPaused(agreementId, verb, creds) {
|
|
|
64
64
|
return shapeAgreement(data['agreement']);
|
|
65
65
|
}
|
|
66
66
|
export async function pullOffers(options, creds) {
|
|
67
|
+
return (await pullOffersPage(options, creds)).offers;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The board read with its total. The board is capped (at most 100 rows), so
|
|
71
|
+
* the number of rows returned is not the number of listings. `total` and
|
|
72
|
+
* `hasMore` are absent from an older server; read them as unknown, not none.
|
|
73
|
+
*/
|
|
74
|
+
export async function pullOffersPage(options, creds) {
|
|
67
75
|
assertCreds(creds, 'marketplace offers pull');
|
|
68
76
|
const params = new URLSearchParams();
|
|
69
77
|
if (options?.limit != null)
|
|
@@ -80,7 +88,9 @@ export async function pullOffers(options, creds) {
|
|
|
80
88
|
throwApiError(res, body, `Marketplace offers pull failed: ${res.status}`);
|
|
81
89
|
}
|
|
82
90
|
const data = await res.json().catch(() => null);
|
|
83
|
-
|
|
91
|
+
const offers = data?.['offers'] ?? [];
|
|
92
|
+
const total = typeof data?.['total'] === 'number' ? data['total'] : null;
|
|
93
|
+
return { offers, total, hasMore: data?.['hasMore'] === true };
|
|
84
94
|
}
|
|
85
95
|
export async function pullRequests(options, creds) {
|
|
86
96
|
assertCreds(creds, 'request pull');
|