@mountaya/client 0.1.0 → 0.2.0
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/CHANGELOG.md +45 -0
- package/README.md +2 -2
- package/dist/admin/index.cjs +2876 -3502
- package/dist/admin/index.cjs.map +1 -1
- package/dist/admin/index.d.cts +731 -912
- package/dist/admin/index.d.ts +731 -912
- package/dist/admin/index.js +188 -285
- package/dist/admin/index.js.map +1 -1
- package/dist/browser.cjs +5913 -7993
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +42 -78
- package/dist/browser.d.ts +42 -78
- package/dist/browser.js +18 -49
- package/dist/browser.js.map +1 -1
- package/dist/chunk-CeEX7ayk.d.cts +75531 -0
- package/dist/chunk-CeEX7ayk.d.ts +75531 -0
- package/dist/chunk-Cg7Dtcb4.js +2987 -0
- package/dist/chunk-Cg7Dtcb4.js.map +1 -0
- package/dist/chunk-DJqUsgsy.d.ts +1463 -0
- package/dist/chunk-DNc8T5K1.js +241 -0
- package/dist/chunk-DNc8T5K1.js.map +1 -0
- package/dist/chunk-DTxzw3hu.d.cts +1463 -0
- package/dist/chunk-DmxQID5X.js +2289 -0
- package/dist/chunk-DmxQID5X.js.map +1 -0
- package/dist/chunk-DoZt_oIV.d.ts +3991 -0
- package/dist/chunk-DpJrqANO.js +11 -0
- package/dist/chunk-Dx8mPAdC.d.cts +3991 -0
- package/dist/chunk-X2ukY3ho.js +419 -0
- package/dist/chunk-X2ukY3ho.js.map +1 -0
- package/dist/events/index.cjs +1338 -1874
- package/dist/events/index.cjs.map +1 -1
- package/dist/events/index.d.cts +373 -382
- package/dist/events/index.d.ts +373 -382
- package/dist/events/index.js +523 -806
- package/dist/events/index.js.map +1 -1
- package/dist/index.cjs +5908 -7988
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +37 -69
- package/dist/index.d.ts +37 -69
- package/dist/index.js +17 -48
- package/dist/index.js.map +1 -1
- package/package.json +7 -8
- package/src/browser.ts +1 -0
- package/src/core/rules/clientHeader.ts +1 -1
- package/src/core/rules/errors.ts +1 -1
- package/src/core/rules/nullMasks.gen.ts +14 -2
- package/src/core/rules/version.gen.ts +1 -1
- package/src/events/index.ts +1 -5
- package/src/rest/adminResources.gen.ts +2 -0
- package/src/rest/dates.gen.ts +1 -1
- package/src/rest/resources.gen.ts +2 -0
- package/src/rest/schema.gen.ts +247 -60
- package/src/tiles/schema.gen.ts +1 -3
- package/dist/chunk-BM526BHG.js +0 -342
- package/dist/chunk-BM526BHG.js.map +0 -1
- package/dist/chunk-D2YEVTG7.js +0 -327
- package/dist/chunk-D2YEVTG7.js.map +0 -1
- package/dist/chunk-OHKVUREN.js +0 -3500
- package/dist/chunk-OHKVUREN.js.map +0 -1
- package/dist/chunk-TDTK2L5H.js +0 -3842
- package/dist/chunk-TDTK2L5H.js.map +0 -1
- package/dist/coreOperations.gen-BMYPoBbz.d.ts +0 -1760
- package/dist/coreOperations.gen-BxX5xRxw.d.cts +0 -1760
- package/dist/errors-B-GqAtQv.d.cts +0 -75960
- package/dist/errors-B-GqAtQv.d.ts +0 -75960
- package/dist/operations.gen-CvTyzKNF.d.cts +0 -3993
- package/dist/operations.gen-DUD406TV.d.ts +0 -3993
|
@@ -0,0 +1,2289 @@
|
|
|
1
|
+
import { t as __exportAll } from "./chunk-DpJrqANO.js";
|
|
2
|
+
import { $n as parseRetryAfter, A as getCollections, An as MountayaConnectionError, At as patchZone, Bt as postItineraryCollab, C as getAgentRunEvents, D as getCollectionItineraries, E as getCollection, F as getItineraryPace, Ft as postCollectionItineraries, Gn as entriesOf, Gt as postItinerarySegment, Ht as postItineraryImport, I as getItineraryShareLink, It as postCollectionShareLink, Jt as postItinerarySegmentMerge, Kn as errorForStatus, Kt as postItinerarySegmentConvert, L as getLayers, Lt as postCollectionShareLinkRotate, M as getItinerary, Mn as MountayaError, Mt as postAgentRunFeedback, N as getItineraryEvents, Nt as postAgentRunInput, O as getCollectionShareLink, On as MountayaConfigurationError, P as getItineraryExport, Pt as postCollection, Qn as metadataOf, Qt as postItineraryWaypoint, Rt as postCollectionZones, S as getActivities, Un as answerDetailsOf, Ut as postItineraryPreview, Vt as postItineraryDuplicate, Wn as describeType, Wt as postItineraryPublication, Xt as postItineraryShareLink, Y as getOrganizationEvents, Yn as failureMessage, Yt as postItinerarySegmentSplit, Zt as postItineraryShareLinkRotate, _t as patchItinerary, a as deleteCollectionZone, b as deleteZone, bn as parseJsonWithDates, bt as patchItineraryWaypoint, c as deleteItinerarySegment, cn as postOrganizationLookup, d as deleteItineraryWaypoint, er as refuseOption, ft as getZone, gt as patchCollectionItinerary, hn as postZonePublication, ht as patchCollection, i as deleteCollectionShareLink, j as getItineraries, jn as MountayaDataError, jt as postAgentRun, k as getCollectionZones, l as deleteItinerarySegmentGroup, mn as postZoneCollab, mt as getZones, n as deleteCollection, nr as statesErrors, o as deleteItinerary, pn as postZone, pt as getZoneEvents, qn as errorFromBody, qt as postItinerarySegmentGroup, r as deleteCollectionItinerary, s as deleteItineraryPublication, tr as replayedOf, u as deleteItineraryShareLink, vt as patchItinerarySegment, wn as MountayaApiError, x as deleteZonePublication, xn as withAbsentNulls, yt as patchItinerarySegmentGroup, zt as postItinerary } from "./chunk-Cg7Dtcb4.js";
|
|
3
|
+
import { _ as shouldRetry, a as readFailure, b as isHeaderValue, c as KEY_IN_USE_MIN_WAIT_MS, d as backoffDelay, f as defaultRetry, g as resolveRetry, h as namedError, i as readBytes, l as MAX_TIMER_DELAY_MS, m as jitteredDelay, n as isAborted, o as readFailureText, p as isKeyInUse, r as parseSuccessBody, s as readText, t as decodeSuccessDates, u as abortReasonOf, v as sleep, y as isEmptyHeaderValue } from "./chunk-DNc8T5K1.js";
|
|
4
|
+
import { r as responseNulls } from "./chunk-X2ukY3ho.js";
|
|
5
|
+
const PUBLISHABLE_PREFIX = "pk_";
|
|
6
|
+
const SECRET_PREFIX = "sk_";
|
|
7
|
+
const SESSION_PREFIX = "sess_";
|
|
8
|
+
const SHARE_PREFIX = "share_";
|
|
9
|
+
const KEY_MEMBERS = [
|
|
10
|
+
"publishableKey",
|
|
11
|
+
"secretKey",
|
|
12
|
+
"sessionToken",
|
|
13
|
+
"shareToken"
|
|
14
|
+
];
|
|
15
|
+
const assertHeaderValue = (member, value) => {
|
|
16
|
+
if (isHeaderValue(value) || isEmptyHeaderValue(value)) return;
|
|
17
|
+
throw new MountayaConfigurationError(`credential.${member} holds a character no request header carries, since a header carries printable ASCII alone: a line break, a tab or another control character, at either end or inside it, or a character past ASCII, a letter of Latin-1 such as \u00e9 among them. ` + (value.includes("…") ? "It reads as a placeholder: replace it with the value your organization was issued." : "Pass it as it was issued, with no line break around it."));
|
|
18
|
+
};
|
|
19
|
+
const startOf = (value) => `Received a value starting with "${value.slice(0, 3)}".`;
|
|
20
|
+
const assertPrefix = (member, prefix, value, detail) => {
|
|
21
|
+
if (value.startsWith(prefix)) return;
|
|
22
|
+
const refusal = `credential.${member} must start with "${prefix}".`;
|
|
23
|
+
throw new MountayaConfigurationError(detail === void 0 ? refusal : `${refusal} ${detail}`);
|
|
24
|
+
};
|
|
25
|
+
const CREDENTIAL_SHAPES = "{ publishableKey } (with a sessionToken where a call needs one), { shareToken } for a share link, { cookie: true } for the browser's own session, or { secretKey } on a server";
|
|
26
|
+
const memberOf = (credential, member) => Reflect.get(credential, member);
|
|
27
|
+
const holdsKey = (credential, member) => {
|
|
28
|
+
const value = memberOf(credential, member);
|
|
29
|
+
return value !== void 0 && !(typeof value === "string" && isEmptyHeaderValue(value));
|
|
30
|
+
};
|
|
31
|
+
const isSecretCredential = (credential) => holdsKey(credential, "secretKey");
|
|
32
|
+
const isShareCredential = (credential) => holdsKey(credential, "shareToken");
|
|
33
|
+
const isPublishableCredential = (credential) => holdsKey(credential, "publishableKey");
|
|
34
|
+
const isCookie = (credential) => memberOf(credential, "cookie") === true && KEY_MEMBERS.every((member) => !holdsKey(credential, member));
|
|
35
|
+
const isSessionTokenSource = (value) => typeof value === "object" && value !== null && typeof Reflect.get(value, "getSnapshot") === "function" && typeof Reflect.get(value, "subscribe") === "function";
|
|
36
|
+
const assertSourceMembers = (value) => {
|
|
37
|
+
if (typeof value !== "object" || value === null) return;
|
|
38
|
+
if (!("getSnapshot" in value) && !("subscribe" in value)) return;
|
|
39
|
+
for (const name of ["getSnapshot", "subscribe"]) {
|
|
40
|
+
const found = Reflect.get(value, name);
|
|
41
|
+
if (typeof found !== "function") throw new MountayaConfigurationError(`credential.sessionToken.${name} is ${describeType(found)}; a session token source states getSnapshot and subscribe as functions, as a SessionTokenEngine does.`);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const assertMemberTypes = (credential) => {
|
|
45
|
+
for (const member of KEY_MEMBERS) {
|
|
46
|
+
const value = memberOf(credential, member);
|
|
47
|
+
const readPerRequest = member === "sessionToken" && (typeof value === "function" || isSessionTokenSource(value));
|
|
48
|
+
if (member === "sessionToken" && !readPerRequest) assertSourceMembers(value);
|
|
49
|
+
if (value !== void 0 && typeof value !== "string" && !readPerRequest) throw new MountayaConfigurationError(`credential.${member} is ${describeType(value)}; pass it as a string, ` + (member === "sessionToken" ? "a function answering one, or a SessionTokenEngine, " : "") + "or leave it out.");
|
|
50
|
+
if (typeof value === "string") {
|
|
51
|
+
if (member === "sessionToken" && isEmptyHeaderValue(value)) throw new MountayaConfigurationError(`credential.sessionToken is ${value === "" ? "an empty string" : "whitespace alone"}; pass the token your server minted, or leave it out.`);
|
|
52
|
+
assertHeaderValue(member, value);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const cookie = memberOf(credential, "cookie");
|
|
56
|
+
if (cookie !== void 0 && typeof cookie !== "boolean") throw new MountayaConfigurationError(`credential.cookie is ${describeType(cookie)}; pass true to send the browser's own cookies, or leave it out.`);
|
|
57
|
+
};
|
|
58
|
+
const refuseCookieBesideKey = (key) => new MountayaConfigurationError(`credential carries ${key} and cookie together, which no credential does: a cookie credential carries no key, and a key credential sends no cookie. Drop cookie to authenticate with the key, or pass { cookie: true } alone to ride the browser's own session.`);
|
|
59
|
+
const wantsCookies = (credential) => isCookie(credential) || isShareCredential(credential) && credential.cookie === true;
|
|
60
|
+
const inShippedRuntime = () => {
|
|
61
|
+
if (typeof globalThis !== "object") return false;
|
|
62
|
+
if ("window" in globalThis && "document" in globalThis) return true;
|
|
63
|
+
return globalThis.navigator?.product === "ReactNative";
|
|
64
|
+
};
|
|
65
|
+
const assertSessionToken = (token) => {
|
|
66
|
+
assertHeaderValue("sessionToken", token);
|
|
67
|
+
assertPrefix("sessionToken", SESSION_PREFIX, token);
|
|
68
|
+
};
|
|
69
|
+
const sessionTokenOf = (credential) => {
|
|
70
|
+
const member = credential.sessionToken;
|
|
71
|
+
if (member === void 0 || typeof member === "string") return member;
|
|
72
|
+
const answer = typeof member === "function" ? member() : member.getSnapshot().token;
|
|
73
|
+
if (answer === void 0) return;
|
|
74
|
+
if (typeof answer !== "string") throw new MountayaConfigurationError(`credential.sessionToken answered ${describeType(answer)}; answer the current token as a string, or undefined while there is none.`);
|
|
75
|
+
assertSessionToken(answer);
|
|
76
|
+
return answer;
|
|
77
|
+
};
|
|
78
|
+
const sessionSourceOf = (credential) => {
|
|
79
|
+
const member = memberOf(credential, "sessionToken");
|
|
80
|
+
return isPublishableCredential(credential) && isSessionTokenSource(member) ? member : void 0;
|
|
81
|
+
};
|
|
82
|
+
const sessionUserOf = (credential) => {
|
|
83
|
+
const source = sessionSourceOf(credential);
|
|
84
|
+
if (source === void 0) return;
|
|
85
|
+
const user = source.getSnapshot().userId;
|
|
86
|
+
return typeof user === "string" || user === null ? user : void 0;
|
|
87
|
+
};
|
|
88
|
+
const sessionExpiryOf = (credential) => {
|
|
89
|
+
const expiry = sessionSourceOf(credential)?.getSnapshot().expiresAt;
|
|
90
|
+
return expiry instanceof Date && !Number.isNaN(expiry.getTime()) ? expiry : void 0;
|
|
91
|
+
};
|
|
92
|
+
const holdsSession = (credential) => {
|
|
93
|
+
const member = credential.sessionToken;
|
|
94
|
+
if (member === void 0 || typeof member === "string") return member !== void 0;
|
|
95
|
+
if (typeof member === "function") return typeof member() === "string";
|
|
96
|
+
const snapshot = member.getSnapshot();
|
|
97
|
+
return snapshot.token !== void 0 || snapshot.isLoading;
|
|
98
|
+
};
|
|
99
|
+
const assertCredential = (credential) => {
|
|
100
|
+
const value = credential;
|
|
101
|
+
if (typeof value !== "object" || value === null) throw new MountayaConfigurationError(`credential is ${describeType(value)}; pass ${CREDENTIAL_SHAPES}.`);
|
|
102
|
+
assertMemberTypes(credential);
|
|
103
|
+
if (isSecretCredential(credential)) {
|
|
104
|
+
if (memberOf(credential, "cookie") !== void 0) throw refuseCookieBesideKey("secretKey");
|
|
105
|
+
const beside = KEY_MEMBERS.find((member) => member !== "secretKey" && holdsKey(credential, member));
|
|
106
|
+
if (beside !== void 0) throw new MountayaConfigurationError(`credential carries secretKey beside ${beside}, which no credential does: a secret key is sent alone, to postSession. Drop ${beside} to mint sessions with the secret key, or drop secretKey ${beside === "sessionToken" ? "and pass { publishableKey, sessionToken }, since a session token accompanies a publishable key." : `to authenticate with the ${beside}.`}`);
|
|
107
|
+
assertPrefix("secretKey", SECRET_PREFIX, credential.secretKey, credential.secretKey.startsWith(PUBLISHABLE_PREFIX) ? "This looks like a publishable key: pass it as { publishableKey }." : "Pass the secret key as it was issued: nothing of the value is quoted here.");
|
|
108
|
+
if (inShippedRuntime()) throw new MountayaConfigurationError("A secret key must never reach a browser or a mobile application: anyone can read it out of the bundle. Mint a session token on your server with POST /v1/sessions and send that to the client instead.");
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (isShareCredential(credential)) {
|
|
112
|
+
assertPrefix("shareToken", SHARE_PREFIX, credential.shareToken);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (isPublishableCredential(credential)) {
|
|
116
|
+
if (memberOf(credential, "cookie") !== void 0) throw refuseCookieBesideKey("publishableKey");
|
|
117
|
+
assertPrefix("publishableKey", PUBLISHABLE_PREFIX, credential.publishableKey, credential.publishableKey.startsWith(SECRET_PREFIX) ? "This looks like a secret key: pass it as { secretKey }, and only from a server." : startOf(credential.publishableKey));
|
|
118
|
+
if (typeof credential.sessionToken === "string") assertSessionToken(credential.sessionToken);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (memberOf(credential, "cookie") !== void 0) {
|
|
122
|
+
const blank = KEY_MEMBERS.find((member) => member !== "sessionToken" && memberOf(credential, member) !== void 0);
|
|
123
|
+
if (blank !== void 0) throw new MountayaConfigurationError(`credential carries cookie beside an empty ${blank}, which is how an unset environment variable arrives: set ${blank}, or pass { cookie: true } alone to ride the browser's own session.`);
|
|
124
|
+
}
|
|
125
|
+
if (isCookie(credential)) return;
|
|
126
|
+
const blanks = KEY_MEMBERS.filter((member) => member !== "sessionToken" && memberOf(credential, member) !== void 0).map((member) => `credential.${member}`);
|
|
127
|
+
const blankNote = blanks.length === 0 ? "" : ` (${blanks.join(" and ")} ${blanks.length === 1 ? "is" : "are"} empty or blank, which is how an unset environment variable arrives, and counts as none)`;
|
|
128
|
+
throw new MountayaConfigurationError(memberOf(credential, "sessionToken") === void 0 ? `credential carries no publishableKey, secretKey, shareToken or cookie: true${blankNote}, so it authenticates nothing; pass ${CREDENTIAL_SHAPES}.` : "credential carries a sessionToken and no publishableKey, which the session token accompanies rather than replaces; pass { publishableKey, sessionToken }.");
|
|
129
|
+
};
|
|
130
|
+
const subjectOf = (operation) => operation.operationId ?? `A ${operation.method.toUpperCase()}`;
|
|
131
|
+
const isWrite = (operation) => {
|
|
132
|
+
const upper = operation.method.toUpperCase();
|
|
133
|
+
return operation.read !== true && upper !== "GET" && upper !== "HEAD" && upper !== "OPTIONS";
|
|
134
|
+
};
|
|
135
|
+
const credentialHeaders = (credential, operation) => {
|
|
136
|
+
if (operation.takesNoCredential === true) return {};
|
|
137
|
+
if (isCookie(credential)) return {};
|
|
138
|
+
if (operation.requiresSecretKey === true) {
|
|
139
|
+
if (isSecretCredential(credential)) return { "X-API-Key": credential.secretKey };
|
|
140
|
+
throw new MountayaConfigurationError(`${subjectOf(operation)} is authenticated by a secret key alone, which must never reach a browser. Call it on your server with { secretKey }, and give the caller the session token it mints as { publishableKey, sessionToken }.`);
|
|
141
|
+
}
|
|
142
|
+
if (isSecretCredential(credential)) throw new MountayaConfigurationError(`${subjectOf(operation)} does not take a secret key: a secret key authenticates postSession alone, and the API answers one here with a 401 as if nothing had been sent. ` + (operation.requiresSession !== true ? "Call this one with a publishable key, and keep the secret key on the server that mints sessions." : operation.actsAsMember === true ? "Mint a session token with it on your server, giving postSession's user_id the member this call acts as, and call this one with { publishableKey, sessionToken }." : "Mint a session token with it on your server, and call this one with { publishableKey, sessionToken }."));
|
|
143
|
+
if (isShareCredential(credential)) {
|
|
144
|
+
if (operation.acceptsShareToken === true) return { "X-Share-Token": credential.shareToken };
|
|
145
|
+
if (credential.cookie === true && !isWrite(operation)) return {};
|
|
146
|
+
throw new MountayaConfigurationError(`${subjectOf(operation)} does not accept a share token. A share token is read-only and reaches the one itinerary, collection or zone it was minted for, through the operations that declare it. ` + (isWrite(operation) ? "Minting, rotating and disabling a share link take a publishable key with the `studio-embedded` scope and a session token minted for `studio-embedded` naming a member with a write role." : "Call this one with a publishable key."));
|
|
147
|
+
}
|
|
148
|
+
const sessionToken = sessionTokenOf(credential);
|
|
149
|
+
if (operation.requiresSession === true && sessionToken === void 0) {
|
|
150
|
+
const forMember = operation.actsAsMember === true ? " This call acts as a member, so mint the token with postSession's user_id set to the user it acts as." : "";
|
|
151
|
+
const source = sessionSourceOf(credential);
|
|
152
|
+
if (source !== void 0) {
|
|
153
|
+
const { error } = source.getSnapshot();
|
|
154
|
+
throw new MountayaConfigurationError(`${subjectOf(operation)} requires a session token beside the publishable key, and credential.sessionToken holds none: ` + (error === void 0 ? "no token has been minted, or minting is disabled. " : "its last mint failed, which this error carries as its cause. ") + `Make the call once it holds the token your server minted.${forMember}`, error === void 0 ? void 0 : { cause: error });
|
|
155
|
+
}
|
|
156
|
+
if (typeof credential.sessionToken === "function") throw new MountayaConfigurationError(`${subjectOf(operation)} requires a session token beside the publishable key, and credential.sessionToken answered none: no token has been minted yet, or the session has ended. Make the call once it answers the token your server minted.${forMember}`);
|
|
157
|
+
throw new MountayaConfigurationError(operation.actsAsMember === true ? `${subjectOf(operation)} acts as a member, so it requires a session token minted for that member beside the publishable key. Mint one on your server with POST /v1/sessions, giving user_id the user it acts as, and pass { publishableKey, sessionToken } when constructing the client.` : `${subjectOf(operation)} requires a session token beside the publishable key. Mint one on your server with POST /v1/sessions and pass { publishableKey, sessionToken } when constructing the client.`);
|
|
158
|
+
}
|
|
159
|
+
if (operation.actsAsMember === true && sessionToken !== void 0 && sessionUserOf(credential) === null) throw new MountayaConfigurationError(`${subjectOf(operation)} acts as the user its session token was minted for, and credential.sessionToken holds a token minted without user_id, which reads and never acts as a member. Mint the token on your server with postSession's user_id set to the user signed in.`);
|
|
160
|
+
const headers = { "X-API-Key": credential.publishableKey };
|
|
161
|
+
if (sessionToken !== void 0) headers["X-Session-Token"] = sessionToken;
|
|
162
|
+
return headers;
|
|
163
|
+
};
|
|
164
|
+
const CLIENT_HEADER_VALUE = `mountaya-typescript/0.2.0`;
|
|
165
|
+
const randomSource = () => {
|
|
166
|
+
const source = Reflect.get(globalThis, "crypto");
|
|
167
|
+
return typeof source === "object" && source !== null ? source : void 0;
|
|
168
|
+
};
|
|
169
|
+
const uuidOf = (bytes) => {
|
|
170
|
+
bytes[6] = (bytes[6] ?? 0) & 15 | 64;
|
|
171
|
+
bytes[8] = (bytes[8] ?? 0) & 63 | 128;
|
|
172
|
+
const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
173
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
174
|
+
};
|
|
175
|
+
const mintIdempotencyKey = () => {
|
|
176
|
+
const source = randomSource();
|
|
177
|
+
if (typeof source?.randomUUID === "function") return source.randomUUID().toLowerCase();
|
|
178
|
+
if (typeof source?.getRandomValues === "function") return uuidOf(source.getRandomValues(/* @__PURE__ */ new Uint8Array(16)));
|
|
179
|
+
};
|
|
180
|
+
const INSPECT = Symbol.for("nodejs.util.inspect.custom");
|
|
181
|
+
const CREDENTIAL_MEMBERS = [
|
|
182
|
+
["cookie"],
|
|
183
|
+
["publishableKey"],
|
|
184
|
+
["secretKey", "sk_"],
|
|
185
|
+
["sessionToken", "sess_"],
|
|
186
|
+
["shareToken", "share_"]
|
|
187
|
+
];
|
|
188
|
+
const redactedSecret = (value, prefix) => value.startsWith(prefix) ? `${prefix}…` : "…";
|
|
189
|
+
const redactedSessionToken = (token) => {
|
|
190
|
+
const [, prefix] = CREDENTIAL_MEMBERS.find(([member]) => member === "sessionToken") ?? [];
|
|
191
|
+
return prefix === void 0 ? "…" : redactedSecret(token, prefix);
|
|
192
|
+
};
|
|
193
|
+
const printedText = (printed) => {
|
|
194
|
+
try {
|
|
195
|
+
return JSON.stringify(printed);
|
|
196
|
+
} catch {
|
|
197
|
+
return "[object Object]";
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
const printsAs = (holder, printed) => Object.defineProperties(holder, {
|
|
201
|
+
[INSPECT]: { value: () => printed(holder) },
|
|
202
|
+
toJSON: { value: () => printed(holder) },
|
|
203
|
+
toString: { value: () => printedText(printed(holder)) }
|
|
204
|
+
});
|
|
205
|
+
const printedSecret = (value, secretPrefix) => {
|
|
206
|
+
if (secretPrefix === void 0) return value;
|
|
207
|
+
if (typeof value === "string") return redactedSecret(value, secretPrefix);
|
|
208
|
+
if (typeof value !== "object" || value === null) return value;
|
|
209
|
+
const getSnapshot = Reflect.get(value, "getSnapshot");
|
|
210
|
+
if (typeof getSnapshot !== "function") return value;
|
|
211
|
+
const snapshot = Reflect.apply(getSnapshot, value, []);
|
|
212
|
+
if (typeof snapshot !== "object" || snapshot === null) return snapshot;
|
|
213
|
+
const token = Reflect.get(snapshot, "token");
|
|
214
|
+
return {
|
|
215
|
+
...snapshot,
|
|
216
|
+
token: typeof token === "string" ? redactedSecret(token, secretPrefix) : token
|
|
217
|
+
};
|
|
218
|
+
};
|
|
219
|
+
const printedCredential = (credential) => {
|
|
220
|
+
const printed = {};
|
|
221
|
+
for (const [member, secretPrefix] of CREDENTIAL_MEMBERS) {
|
|
222
|
+
const value = Reflect.get(credential, member);
|
|
223
|
+
if (value !== void 0) printed[member] = printedSecret(value, secretPrefix);
|
|
224
|
+
}
|
|
225
|
+
return printed;
|
|
226
|
+
};
|
|
227
|
+
const printableCredential = (credential) => {
|
|
228
|
+
const view = {};
|
|
229
|
+
for (const [member] of CREDENTIAL_MEMBERS) Object.defineProperty(view, member, {
|
|
230
|
+
enumerable: true,
|
|
231
|
+
get: () => Reflect.get(credential, member)
|
|
232
|
+
});
|
|
233
|
+
return printsAs(view, () => printedCredential(credential));
|
|
234
|
+
};
|
|
235
|
+
const printableProjection = (projection) => printsAs(projection, () => printedCredential(projection));
|
|
236
|
+
const secretDigest = (secret) => {
|
|
237
|
+
let first = 3735928559;
|
|
238
|
+
let second = 1103547991;
|
|
239
|
+
for (let index = 0; index < secret.length; index += 1) {
|
|
240
|
+
const unit = secret.charCodeAt(index);
|
|
241
|
+
first = Math.imul(first ^ unit, 2654435761);
|
|
242
|
+
second = Math.imul(second ^ unit, 1597334677);
|
|
243
|
+
}
|
|
244
|
+
first = Math.imul(first ^ first >>> 16, 2246822507) ^ Math.imul(second ^ second >>> 13, 3266489909);
|
|
245
|
+
second = Math.imul(second ^ second >>> 16, 2246822507) ^ Math.imul(first ^ first >>> 13, 3266489909);
|
|
246
|
+
return (4294967296 * (2097151 & second) + (first >>> 0)).toString(36);
|
|
247
|
+
};
|
|
248
|
+
const waitForSessionToken = (source, bounds) => {
|
|
249
|
+
const held = source.getSnapshot();
|
|
250
|
+
if (held.token !== void 0 || !held.isLoading) return;
|
|
251
|
+
const { operationId, signal, timeoutMs } = bounds;
|
|
252
|
+
if (signal !== void 0 && isAborted(signal)) return Promise.reject(abortReasonOf(signal));
|
|
253
|
+
return new Promise((resolve, reject) => {
|
|
254
|
+
let ended = false;
|
|
255
|
+
let release;
|
|
256
|
+
let timer;
|
|
257
|
+
const end = (settle) => {
|
|
258
|
+
if (ended) return;
|
|
259
|
+
ended = true;
|
|
260
|
+
clearTimeout(timer);
|
|
261
|
+
signal?.removeEventListener("abort", onAbort);
|
|
262
|
+
release?.();
|
|
263
|
+
settle();
|
|
264
|
+
};
|
|
265
|
+
const onAbort = () => {
|
|
266
|
+
end(() => {
|
|
267
|
+
reject(signal === void 0 ? void 0 : abortReasonOf(signal));
|
|
268
|
+
});
|
|
269
|
+
};
|
|
270
|
+
const check = () => {
|
|
271
|
+
const snapshot = source.getSnapshot();
|
|
272
|
+
if (snapshot.token !== void 0 || !snapshot.isLoading) end(resolve);
|
|
273
|
+
};
|
|
274
|
+
const unsubscribe = source.subscribe(check);
|
|
275
|
+
if (ended) {
|
|
276
|
+
unsubscribe();
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
release = unsubscribe;
|
|
280
|
+
check();
|
|
281
|
+
if (ended) return;
|
|
282
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
283
|
+
timer = setTimeout(() => {
|
|
284
|
+
end(() => {
|
|
285
|
+
reject(new MountayaConnectionError(`${operationId}: no session token within ${timeoutMs} ms: the session token mint has not answered. Raise timeoutMs, or check the endpoint the mint calls.`));
|
|
286
|
+
});
|
|
287
|
+
}, timeoutMs);
|
|
288
|
+
});
|
|
289
|
+
};
|
|
290
|
+
const requestWebAddresses = {
|
|
291
|
+
patchItineraryWaypoint: {
|
|
292
|
+
contact: {
|
|
293
|
+
booking_url: true,
|
|
294
|
+
website: true
|
|
295
|
+
},
|
|
296
|
+
media: {
|
|
297
|
+
links: [{ url: true }],
|
|
298
|
+
photos: [{ url: true }]
|
|
299
|
+
}
|
|
300
|
+
},
|
|
301
|
+
patchOrganizationAiProviderConfig: { base_url: true },
|
|
302
|
+
patchOrganizationWebhookEndpoint: { url: true },
|
|
303
|
+
postItineraryWaypoint: {
|
|
304
|
+
contact: {
|
|
305
|
+
booking_url: true,
|
|
306
|
+
website: true
|
|
307
|
+
},
|
|
308
|
+
media: {
|
|
309
|
+
links: [{ url: true }],
|
|
310
|
+
photos: [{ url: true }]
|
|
311
|
+
}
|
|
312
|
+
},
|
|
313
|
+
postOrganization: { website: true },
|
|
314
|
+
postOrganizationAiProviderConfig: { base_url: true },
|
|
315
|
+
postOrganizationWebhookEndpoint: { url: true }
|
|
316
|
+
};
|
|
317
|
+
const absoluteAddressPattern = /^[A-Za-z][A-Za-z0-9+.-]*:[^\n\r\u0085\u2028\u2029]+$/;
|
|
318
|
+
const bareHostPattern = /^(localhost|[a-z0-9-]+(\.[a-z0-9-]+)+)(:\d+)?(\/\S*)?$/i;
|
|
319
|
+
const hasUrlScheme = (text) => absoluteAddressPattern.test(text);
|
|
320
|
+
const isListMask = (mask) => Array.isArray(mask);
|
|
321
|
+
const isList = (value) => Array.isArray(value);
|
|
322
|
+
const schemelessIn = (value, mask, path) => {
|
|
323
|
+
if (mask === true) return typeof value === "string" && !hasUrlScheme(value) ? {
|
|
324
|
+
path,
|
|
325
|
+
value
|
|
326
|
+
} : void 0;
|
|
327
|
+
if (isListMask(mask)) {
|
|
328
|
+
if (!isList(value)) return;
|
|
329
|
+
const [element] = mask;
|
|
330
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
331
|
+
const found = schemelessIn(value[index], element, `${path}[${index}]`);
|
|
332
|
+
if (found !== void 0) return found;
|
|
333
|
+
}
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
if (typeof value !== "object" || value === null || isList(value)) return;
|
|
337
|
+
for (const [field, fieldMask] of Object.entries(mask)) if (Object.hasOwn(value, field)) {
|
|
338
|
+
const held = Reflect.get(value, field);
|
|
339
|
+
const found = schemelessIn(held, fieldMask, `${path}.${field}`);
|
|
340
|
+
if (found !== void 0) return found;
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
const assertWebAddresses = (operationId, text) => {
|
|
344
|
+
const mask = Object.hasOwn(requestWebAddresses, operationId) ? requestWebAddresses[operationId] : void 0;
|
|
345
|
+
if (mask === void 0) return;
|
|
346
|
+
const found = schemelessIn(JSON.parse(text), mask, "body");
|
|
347
|
+
if (found === void 0) return;
|
|
348
|
+
if (found.value.includes("@")) throw new MountayaConfigurationError(`${operationId}: ${found.path} is a web address with no scheme, and holds an "@", so its value is not quoted. Pass it with its scheme, such as "https://", since the contract types it an absolute address.`);
|
|
349
|
+
const example = bareHostPattern.test(found.value) ? `"https://${found.value}"` : `"https://" before its host`;
|
|
350
|
+
throw refuseOption(found.path, found.value, `pass it with its scheme, such as ${example}, since the contract types it an absolute address.`, operationId);
|
|
351
|
+
};
|
|
352
|
+
const defaultBaseUrls = {
|
|
353
|
+
data: "https://data.mountaya.com",
|
|
354
|
+
rest: "https://api.mountaya.com",
|
|
355
|
+
tiles: "https://tiles.mountaya.com"
|
|
356
|
+
};
|
|
357
|
+
const DEFAULT_TIMEOUT_MS = 3e4;
|
|
358
|
+
const SERVER_BUDGET_MARGIN_MS = 5e3;
|
|
359
|
+
const responseNullMask = (operationId) => Object.hasOwn(responseNulls, operationId) ? responseNulls[operationId] : void 0;
|
|
360
|
+
const isFormData = (body) => typeof FormData !== "undefined" && body instanceof FormData;
|
|
361
|
+
const encodeBody = (body, operationId) => {
|
|
362
|
+
if (body === void 0) return;
|
|
363
|
+
if (isFormData(body)) return body;
|
|
364
|
+
try {
|
|
365
|
+
return JSON.stringify(body);
|
|
366
|
+
} catch (cause) {
|
|
367
|
+
const reason = cause instanceof Error ? cause.message.split("\n", 1)[0] : `threw ${describeType(cause)}`;
|
|
368
|
+
throw new MountayaConfigurationError(`${operationId}: the body cannot be sent as JSON (${reason}). Pass a body JSON.stringify accepts, with no cycle and no BigInt.`, { cause });
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
const extendedFilenamePattern = /(?:^|;)[ \t]*filename\*[ \t]*=[ \t]*([^;]*)/i;
|
|
372
|
+
const plainFilenamePattern = /(?:^|;)[ \t]*filename[ \t]*=[ \t]*("(?:[^"\\]|\\.)*"|[^;]*)/i;
|
|
373
|
+
const percentEncodedPattern = /^(?:%[0-9a-f]{2}|[^%])*$/i;
|
|
374
|
+
const decodeExtendedValue = (raw) => {
|
|
375
|
+
const value = raw.trim().replace(/^"(.*)"$/, "$1");
|
|
376
|
+
const charsetEnd = value.indexOf("'");
|
|
377
|
+
const languageEnd = charsetEnd < 0 ? -1 : value.indexOf("'", charsetEnd + 1);
|
|
378
|
+
const charset = languageEnd < 0 ? "utf-8" : value.slice(0, charsetEnd).toLowerCase();
|
|
379
|
+
const encoded = languageEnd < 0 ? value : value.slice(languageEnd + 1);
|
|
380
|
+
if (!percentEncodedPattern.test(encoded)) return;
|
|
381
|
+
if (charset === "iso-8859-1") return encoded.replace(/%([0-9a-f]{2})/gi, (_escape, byte) => String.fromCharCode(Number.parseInt(byte, 16)));
|
|
382
|
+
if (charset !== "utf-8") return;
|
|
383
|
+
try {
|
|
384
|
+
return decodeURIComponent(encoded);
|
|
385
|
+
} catch {
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
const filenameFromContentDisposition = (header) => {
|
|
390
|
+
if (header === null || header === "") return;
|
|
391
|
+
const extended = extendedFilenamePattern.exec(header)?.[1];
|
|
392
|
+
const decoded = extended === void 0 ? void 0 : decodeExtendedValue(extended);
|
|
393
|
+
if (decoded !== void 0 && decoded !== "") return decoded;
|
|
394
|
+
const plain = plainFilenamePattern.exec(header)?.[1]?.trim() ?? "";
|
|
395
|
+
const quoted = /^"((?:[^"\\]|\\.)*)"$/.exec(plain)?.[1];
|
|
396
|
+
const name = quoted === void 0 ? plain.replace(/^"|"$/g, "") : quoted.replace(/\\(.)/g, "$1");
|
|
397
|
+
return name === "" ? void 0 : name;
|
|
398
|
+
};
|
|
399
|
+
const absoluteUrlPattern = /^[a-z][a-z0-9+.-]*:\/\//i;
|
|
400
|
+
const SAME_ORIGIN_BASE = "http://same-origin.invalid";
|
|
401
|
+
const pageOrigin = () => {
|
|
402
|
+
const href = globalThis.location?.href;
|
|
403
|
+
if (typeof href !== "string") return;
|
|
404
|
+
let address;
|
|
405
|
+
try {
|
|
406
|
+
address = new URL(href);
|
|
407
|
+
} catch {
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
return address.protocol === "http:" || address.protocol === "https:" ? address.origin : void 0;
|
|
411
|
+
};
|
|
412
|
+
const dotSegmentPattern = /^(?:\.|%2e){1,2}$/i;
|
|
413
|
+
const edgeControlPattern = /^[\0-\x20]+|[\0-\x20]+$/g;
|
|
414
|
+
const refusePath = (path, why, context) => new MountayaConfigurationError(`${context === void 0 ? "" : `${context}: `}the path ${JSON.stringify(path)} ${why}`);
|
|
415
|
+
const joinUrl = (baseUrl, path, query, context) => {
|
|
416
|
+
const absolute = absoluteUrlPattern.test(baseUrl);
|
|
417
|
+
const base = absolute ? baseUrl : `${SAME_ORIGIN_BASE}${baseUrl.startsWith("/") ? "" : "/"}${baseUrl}`;
|
|
418
|
+
const root = new URL(base.endsWith("/") ? base : `${base}/`);
|
|
419
|
+
const relative = path.replace(edgeControlPattern, "").replace(/[\t\n\r]/g, "").replace(/^[/\\]/, "");
|
|
420
|
+
const written = relative.replace(/[?#].*$/s, "").replaceAll("\\", "/");
|
|
421
|
+
if (written !== "" && written.split("/").some((part) => part === "" || dotSegmentPattern.test(part))) throw refusePath(path, "holds an empty segment or a dot segment (\".\" or \"..\"), which addresses another route than the one written. Pass each identifier as the platform issued it.", context);
|
|
422
|
+
const url = new URL(`./${relative}`, root);
|
|
423
|
+
if (!url.href.startsWith(root.href)) throw refusePath(path, "resolves outside the base URL it is joined onto, so the request would leave the API with the client's credential. Pass a path of the API, starting with one \"/\".", context);
|
|
424
|
+
if (query !== void 0) {
|
|
425
|
+
for (const [key, value] of Object.entries(query)) if (value !== void 0) url.searchParams.set(key, String(value));
|
|
426
|
+
}
|
|
427
|
+
return absolute ? url.toString() : url.toString().slice(26);
|
|
428
|
+
};
|
|
429
|
+
const buildUrl = (baseUrl, path, query, context) => {
|
|
430
|
+
const joined = joinUrl(baseUrl, path, query, context);
|
|
431
|
+
return absoluteUrlPattern.test(baseUrl) ? joined : `${pageOrigin() ?? ""}${joined}`;
|
|
432
|
+
};
|
|
433
|
+
const isJoinableBase = (base) => {
|
|
434
|
+
if (base === "") return true;
|
|
435
|
+
if (base.trim() !== base || base.includes("?") || base.includes("#")) return false;
|
|
436
|
+
const absolute = absoluteUrlPattern.test(base);
|
|
437
|
+
if (!absolute && (!base.startsWith("/") || base.startsWith("//"))) return false;
|
|
438
|
+
let joined;
|
|
439
|
+
try {
|
|
440
|
+
joined = joinUrl(base, "/", void 0);
|
|
441
|
+
} catch {
|
|
442
|
+
return false;
|
|
443
|
+
}
|
|
444
|
+
if (!absolute) return !joined.startsWith("//");
|
|
445
|
+
const { host, protocol } = new URL(joined);
|
|
446
|
+
return (protocol === "http:" || protocol === "https:") && host !== "";
|
|
447
|
+
};
|
|
448
|
+
const carriesUserinfo = (base) => {
|
|
449
|
+
if (!absoluteUrlPattern.test(base)) return false;
|
|
450
|
+
try {
|
|
451
|
+
const { password, username } = new URL(base);
|
|
452
|
+
return username !== "" || password !== "";
|
|
453
|
+
} catch {
|
|
454
|
+
return false;
|
|
455
|
+
}
|
|
456
|
+
};
|
|
457
|
+
const resolveBaseUrls = (baseUrls) => {
|
|
458
|
+
if (baseUrls === void 0) return { ...defaultBaseUrls };
|
|
459
|
+
if (typeof baseUrls !== "object" || baseUrls === null) throw refuseOption("baseUrls", baseUrls, "pass an object naming a base URL per surface, such as { rest: \"http://localhost:8080\" }.");
|
|
460
|
+
const entry = (surface) => {
|
|
461
|
+
const value = baseUrls[surface];
|
|
462
|
+
if (value === void 0) return defaultBaseUrls[surface];
|
|
463
|
+
if (typeof value === "string" && carriesUserinfo(value)) throw new MountayaConfigurationError(`baseUrls.${surface} carries a username or a password before its host, which fetch refuses in a request's URL; pass the URL without them, and authenticate through the client's credential.`);
|
|
464
|
+
if (typeof value === "string" && isJoinableBase(value)) {
|
|
465
|
+
if (!absoluteUrlPattern.test(value) && pageOrigin() === void 0) throw new MountayaConfigurationError(`baseUrls.${surface} is ${value.includes("@") ? "a path" : JSON.stringify(value)}, a path read against the page's own origin, and no page here names an http or https origin to read it against; pass an http or https URL, such as "https://maps.example.com${value.includes("@") ? "" : value}".`);
|
|
466
|
+
return value;
|
|
467
|
+
}
|
|
468
|
+
if (typeof value === "string" && value.includes("@")) throw new MountayaConfigurationError(`baseUrls.${surface} holds an "@" and is no base URL this client can join a path onto, so its value is not quoted: a username or a password may stand before the "@". Pass an http or https URL with no username, password, query or fragment, a path starting with one "/" that does not resolve to "//", or "" for the page's own origin, with no whitespace at either end.`);
|
|
469
|
+
const scheme = typeof value === "string" && bareHostPattern.test(value) ? ` For a host, add its scheme: "https://${value}".` : "";
|
|
470
|
+
throw refuseOption(`baseUrls.${surface}`, value, `pass an http or https URL with no query or fragment, a path starting with one "/" that does not resolve to "//", or "" for the page's own origin, with no whitespace at either end.${scheme}`);
|
|
471
|
+
};
|
|
472
|
+
return {
|
|
473
|
+
data: entry("data"),
|
|
474
|
+
rest: entry("rest"),
|
|
475
|
+
tiles: entry("tiles")
|
|
476
|
+
};
|
|
477
|
+
};
|
|
478
|
+
const resolveTimeout = (timeoutMs, context) => {
|
|
479
|
+
if (timeoutMs === void 0) return DEFAULT_TIMEOUT_MS;
|
|
480
|
+
if (Number.isInteger(timeoutMs) && timeoutMs >= 1 && timeoutMs <= MAX_TIMER_DELAY_MS) return timeoutMs;
|
|
481
|
+
throw refuseOption("timeoutMs", timeoutMs, context === void 0 ? `pass a whole number of milliseconds from 1 to ${MAX_TIMER_DELAY_MS}, or leave it out for the default of ${DEFAULT_TIMEOUT_MS}.` : `pass a whole number of milliseconds from 1 to ${MAX_TIMER_DELAY_MS}, or leave it out for the client's own.`, context);
|
|
482
|
+
};
|
|
483
|
+
const NO_LANGUAGE = "*";
|
|
484
|
+
const resolveLanguage = (language) => {
|
|
485
|
+
const given = language;
|
|
486
|
+
if (given === void 0) return;
|
|
487
|
+
if (typeof given === "string" && isHeaderValue(given) && !isEmptyHeaderValue(given)) return given;
|
|
488
|
+
throw refuseOption("language", given, `pass a BCP 47 tag such as "fr" or "pt-BR", in printable ASCII with no line break around it, or leave it out to send "${NO_LANGUAGE}", which asks for no language in particular.`);
|
|
489
|
+
};
|
|
490
|
+
const resolveFetch = (fetchImpl) => {
|
|
491
|
+
const given = fetchImpl;
|
|
492
|
+
if (given !== void 0 && typeof given !== "function") throw refuseOption("fetch", given, "pass a function that takes what the global fetch takes, or leave it out to call the global one.");
|
|
493
|
+
return boundFetch(fetchImpl);
|
|
494
|
+
};
|
|
495
|
+
const boundFetch = (fetchImpl) => fetchImpl ?? ((input, init) => globalThis.fetch(input, init));
|
|
496
|
+
const attemptSignal = (timeoutMs, caller) => {
|
|
497
|
+
const controller = new AbortController();
|
|
498
|
+
let timedOut = false;
|
|
499
|
+
const timer = setTimeout(() => {
|
|
500
|
+
timedOut = true;
|
|
501
|
+
controller.abort(namedError("TimeoutError", `no response within ${timeoutMs} ms`));
|
|
502
|
+
}, timeoutMs);
|
|
503
|
+
const stopTimer = () => {
|
|
504
|
+
clearTimeout(timer);
|
|
505
|
+
};
|
|
506
|
+
if (caller === void 0) return {
|
|
507
|
+
release: stopTimer,
|
|
508
|
+
signal: controller.signal,
|
|
509
|
+
timedOut: () => timedOut
|
|
510
|
+
};
|
|
511
|
+
if (typeof Reflect.get(AbortSignal, "any") === "function") return {
|
|
512
|
+
release: stopTimer,
|
|
513
|
+
signal: AbortSignal.any([caller, controller.signal]),
|
|
514
|
+
timedOut: () => timedOut
|
|
515
|
+
};
|
|
516
|
+
const forward = () => {
|
|
517
|
+
controller.abort(abortReasonOf(caller));
|
|
518
|
+
};
|
|
519
|
+
if (caller.aborted) forward();
|
|
520
|
+
else caller.addEventListener("abort", forward, { once: true });
|
|
521
|
+
return {
|
|
522
|
+
release: () => {
|
|
523
|
+
stopTimer();
|
|
524
|
+
caller.removeEventListener("abort", forward);
|
|
525
|
+
},
|
|
526
|
+
signal: controller.signal,
|
|
527
|
+
timedOut: () => timedOut
|
|
528
|
+
};
|
|
529
|
+
};
|
|
530
|
+
const refuseEventStream = (args) => {
|
|
531
|
+
if (!(args.accept ?? "").split(",").some((range) => range.split(";")[0]?.trim().toLowerCase() === "text/event-stream")) return;
|
|
532
|
+
const opener = args.operationId === "getAgentRunEvents" ? "createAgentTransport" : args.operationId === "getItineraryEvents" || args.operationId === "getOrganizationEvents" || args.operationId === "getZoneEvents" ? "createCollabTransport" : "openSseStream";
|
|
533
|
+
throw new MountayaConfigurationError(`${args.operationId} answers an event stream, which has no end for a request to read to. Open it with ${opener} from @mountaya/client/events, which reads it frame by frame.`);
|
|
534
|
+
};
|
|
535
|
+
const discardBody = (response) => {
|
|
536
|
+
const body = response.body;
|
|
537
|
+
if (typeof body?.cancel !== "function") return;
|
|
538
|
+
try {
|
|
539
|
+
Promise.resolve(body.cancel()).catch(() => void 0);
|
|
540
|
+
} catch {}
|
|
541
|
+
};
|
|
542
|
+
const resolveServerBudget = (budget, context) => {
|
|
543
|
+
if (budget === void 0) return;
|
|
544
|
+
if (Number.isInteger(budget) && budget >= 1 && budget <= MAX_TIMER_DELAY_MS) return budget;
|
|
545
|
+
throw refuseOption("serverBudgetMs", budget, `pass the operation's x-timeout-ms, a whole number of milliseconds from 1 to ${MAX_TIMER_DELAY_MS}, or leave it out where it declares none.`, context);
|
|
546
|
+
};
|
|
547
|
+
const attemptBudget = (clientMs, args) => {
|
|
548
|
+
if (args.timeoutMs !== void 0) return resolveTimeout(args.timeoutMs, args.operationId);
|
|
549
|
+
const server = resolveServerBudget(args.serverBudgetMs, args.operationId);
|
|
550
|
+
return server === void 0 ? clientMs : Math.min(MAX_TIMER_DELAY_MS, Math.max(clientMs, server + SERVER_BUDGET_MARGIN_MS));
|
|
551
|
+
};
|
|
552
|
+
const callerHeaderRemedies = {
|
|
553
|
+
accept: "pass the media type the call answers in, such as application/json, or leave it out for application/json.",
|
|
554
|
+
idempotencyKey: "pass a key of printable ASCII, such as a UUID, or leave it out for the client to draw one.",
|
|
555
|
+
ifMatch: "pass the etag the resource was read under, as the API wrote it, or leave it out for an unconditional write."
|
|
556
|
+
};
|
|
557
|
+
const assertCallerHeader = (member, value, context) => {
|
|
558
|
+
if (value === void 0) return;
|
|
559
|
+
if (typeof value === "string" && isHeaderValue(value) && !isEmptyHeaderValue(value)) return;
|
|
560
|
+
throw new MountayaConfigurationError(`${context}: ${member} is ${typeof value === "string" ? "a string no request header carries" : describeType(value)}; ${callerHeaderRemedies[member]}`);
|
|
561
|
+
};
|
|
562
|
+
const surfaceFault$1 = (fault) => {
|
|
563
|
+
queueMicrotask(() => {
|
|
564
|
+
throw fault;
|
|
565
|
+
});
|
|
566
|
+
};
|
|
567
|
+
const resolveHook = (hook) => {
|
|
568
|
+
const given = hook;
|
|
569
|
+
if (given === void 0 || typeof given === "function") return hook;
|
|
570
|
+
throw refuseOption("onResponse", given, "pass a function told of each answer, or leave it out.");
|
|
571
|
+
};
|
|
572
|
+
const firstCodeOf = (text) => {
|
|
573
|
+
let body;
|
|
574
|
+
try {
|
|
575
|
+
body = JSON.parse(text);
|
|
576
|
+
} catch {
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
return entriesOf(body)[0]?.extensions?.code;
|
|
580
|
+
};
|
|
581
|
+
const rereadable = (response, text) => new Response(text === "" ? null : text, {
|
|
582
|
+
headers: response.headers,
|
|
583
|
+
status: response.status,
|
|
584
|
+
statusText: response.statusText
|
|
585
|
+
});
|
|
586
|
+
const carryingKey = (failure, idempotencyKey) => {
|
|
587
|
+
if (idempotencyKey === void 0) return failure;
|
|
588
|
+
if (failure instanceof MountayaConfigurationError) return new MountayaConfigurationError(failure.message, {
|
|
589
|
+
cause: failure.cause,
|
|
590
|
+
idempotencyKey
|
|
591
|
+
});
|
|
592
|
+
if (failure instanceof MountayaConnectionError) return new MountayaConnectionError(failure.message, failure.cause, idempotencyKey);
|
|
593
|
+
return failure;
|
|
594
|
+
};
|
|
595
|
+
var MountayaTransport = class {
|
|
596
|
+
credential;
|
|
597
|
+
baseUrls;
|
|
598
|
+
timeoutMs;
|
|
599
|
+
retry;
|
|
600
|
+
language;
|
|
601
|
+
doFetch;
|
|
602
|
+
credentialsMode;
|
|
603
|
+
onResponse;
|
|
604
|
+
constructor(options) {
|
|
605
|
+
const given = options;
|
|
606
|
+
if (typeof given !== "object" || given === null) throw new MountayaConfigurationError(`options is ${describeType(given)}; pass { credential }, with any other option beside it, such as { credential: { publishableKey } }.`);
|
|
607
|
+
assertCredential(options.credential);
|
|
608
|
+
this.credential = printableCredential(options.credential);
|
|
609
|
+
this.credentialsMode = wantsCookies(options.credential) ? "include" : "omit";
|
|
610
|
+
this.baseUrls = resolveBaseUrls(options.baseUrls);
|
|
611
|
+
this.timeoutMs = resolveTimeout(options.timeoutMs);
|
|
612
|
+
this.retry = resolveRetry(defaultRetry, options.retry);
|
|
613
|
+
this.language = resolveLanguage(options.language);
|
|
614
|
+
this.onResponse = resolveHook(options.onResponse);
|
|
615
|
+
this.doFetch = resolveFetch(options.fetch);
|
|
616
|
+
}
|
|
617
|
+
get mapCredential() {
|
|
618
|
+
const credential = this.credential;
|
|
619
|
+
const cookie = wantsCookies(credential) ? { cookie: true } : {};
|
|
620
|
+
if (isShareCredential(credential)) return printableProjection({
|
|
621
|
+
...cookie,
|
|
622
|
+
shareToken: credential.shareToken
|
|
623
|
+
});
|
|
624
|
+
if (isPublishableCredential(credential)) {
|
|
625
|
+
const sessionToken = sessionTokenOf(credential);
|
|
626
|
+
return printableProjection(sessionToken === void 0 ? { publishableKey: credential.publishableKey } : {
|
|
627
|
+
publishableKey: credential.publishableKey,
|
|
628
|
+
sessionToken
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
return printableProjection(cookie);
|
|
632
|
+
}
|
|
633
|
+
applyAuth(init = {}, method = "GET", declaration = {}) {
|
|
634
|
+
const projected = credentialHeaders(this.credential, {
|
|
635
|
+
...declaration,
|
|
636
|
+
method
|
|
637
|
+
});
|
|
638
|
+
const headers = new Headers(init.headers);
|
|
639
|
+
for (const [name, value] of Object.entries(projected)) headers.set(name, value);
|
|
640
|
+
headers.set("Accept-Language", this.language ?? NO_LANGUAGE);
|
|
641
|
+
headers.set("X-Mountaya-Client", CLIENT_HEADER_VALUE);
|
|
642
|
+
return {
|
|
643
|
+
...init,
|
|
644
|
+
credentials: this.credentialsMode,
|
|
645
|
+
headers
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
get streamSeam() {
|
|
649
|
+
return {
|
|
650
|
+
applyAuth: (init, method, declaration) => this.applyAuth(init, method, declaration),
|
|
651
|
+
doFetch: this.doFetch,
|
|
652
|
+
report: (response, operationId) => {
|
|
653
|
+
this.report(response, {
|
|
654
|
+
operationId,
|
|
655
|
+
surface: "rest"
|
|
656
|
+
}, 0);
|
|
657
|
+
},
|
|
658
|
+
sessionExpiresAt: () => sessionExpiryOf(this.credential),
|
|
659
|
+
sessionUserId: () => sessionUserOf(this.credential),
|
|
660
|
+
timeoutMs: this.timeoutMs,
|
|
661
|
+
url: (path, operationId) => buildUrl(this.baseUrls.rest, path, void 0, operationId),
|
|
662
|
+
waitForSession: (operationId, signal) => {
|
|
663
|
+
const source = sessionSourceOf(this.credential);
|
|
664
|
+
return source === void 0 ? void 0 : waitForSessionToken(source, {
|
|
665
|
+
operationId,
|
|
666
|
+
signal,
|
|
667
|
+
timeoutMs: this.timeoutMs
|
|
668
|
+
});
|
|
669
|
+
}
|
|
670
|
+
};
|
|
671
|
+
}
|
|
672
|
+
get credentialScope() {
|
|
673
|
+
const credential = this.credential;
|
|
674
|
+
if (isShareCredential(credential)) return `share:${secretDigest(credential.shareToken)}`;
|
|
675
|
+
if (isSecretCredential(credential)) return "secret";
|
|
676
|
+
if (!isPublishableCredential(credential)) return "cookie";
|
|
677
|
+
const key = `key:${encodeURIComponent(credential.publishableKey)}`;
|
|
678
|
+
if (!holdsSession(credential)) return key;
|
|
679
|
+
const member = credential.sessionToken;
|
|
680
|
+
if (typeof member === "string") return `${key} session:${secretDigest(member)}`;
|
|
681
|
+
const user = sessionUserOf(credential);
|
|
682
|
+
if (user === null) return `${key} session nobody`;
|
|
683
|
+
return user === void 0 ? `${key} session` : `${key} session user:${encodeURIComponent(user)}`;
|
|
684
|
+
}
|
|
685
|
+
get credentialScopePending() {
|
|
686
|
+
const source = sessionSourceOf(this.credential);
|
|
687
|
+
if (source === void 0) return false;
|
|
688
|
+
const snapshot = source.getSnapshot();
|
|
689
|
+
return snapshot.token === void 0 && snapshot.isLoading;
|
|
690
|
+
}
|
|
691
|
+
subscribeCredentialScope(listener) {
|
|
692
|
+
const source = sessionSourceOf(this.credential);
|
|
693
|
+
if (source === void 0) return () => void 0;
|
|
694
|
+
let lastScope = this.credentialScope;
|
|
695
|
+
let lastPending = this.credentialScopePending;
|
|
696
|
+
return source.subscribe(() => {
|
|
697
|
+
const scope = this.credentialScope;
|
|
698
|
+
const pending = this.credentialScopePending;
|
|
699
|
+
if (scope === lastScope && pending === lastPending) return;
|
|
700
|
+
lastScope = scope;
|
|
701
|
+
lastPending = pending;
|
|
702
|
+
try {
|
|
703
|
+
listener();
|
|
704
|
+
} catch (fault) {
|
|
705
|
+
surfaceFault$1(fault);
|
|
706
|
+
}
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
get actsAsMember() {
|
|
710
|
+
const credential = this.credential;
|
|
711
|
+
if (isSecretCredential(credential) || isShareCredential(credential)) return false;
|
|
712
|
+
if (!isPublishableCredential(credential)) return;
|
|
713
|
+
if (credential.sessionToken === void 0) return false;
|
|
714
|
+
const user = sessionUserOf(credential);
|
|
715
|
+
return user === void 0 ? void 0 : user !== null;
|
|
716
|
+
}
|
|
717
|
+
get reachesSessionOperations() {
|
|
718
|
+
const credential = this.credential;
|
|
719
|
+
if (isSecretCredential(credential) || isShareCredential(credential)) return false;
|
|
720
|
+
return isPublishableCredential(credential) ? credential.sessionToken !== void 0 : true;
|
|
721
|
+
}
|
|
722
|
+
get tilesBaseUrl() {
|
|
723
|
+
return this.baseUrls.tiles;
|
|
724
|
+
}
|
|
725
|
+
get restBaseUrl() {
|
|
726
|
+
return this.baseUrls.rest;
|
|
727
|
+
}
|
|
728
|
+
get requestLanguage() {
|
|
729
|
+
return this.language;
|
|
730
|
+
}
|
|
731
|
+
async requestRaw(args) {
|
|
732
|
+
return (await this.send(args)).response;
|
|
733
|
+
}
|
|
734
|
+
async send(args) {
|
|
735
|
+
assertCallerHeader("accept", args.accept, args.operationId);
|
|
736
|
+
refuseEventStream(args);
|
|
737
|
+
const timeoutMs = attemptBudget(this.timeoutMs, args);
|
|
738
|
+
const takesKey = args.takesIdempotencyKey === true;
|
|
739
|
+
if (takesKey) assertCallerHeader("idempotencyKey", args.idempotencyKey, args.operationId);
|
|
740
|
+
assertCallerHeader("ifMatch", args.ifMatch, args.operationId);
|
|
741
|
+
const url = buildUrl(this.baseUrls[args.surface], args.path, args.query, args.operationId);
|
|
742
|
+
const retry = resolveRetry(this.retry, args.retry, args.operationId);
|
|
743
|
+
const body = encodeBody(args.body, args.operationId);
|
|
744
|
+
if (args.surface === "rest" && typeof body === "string") assertWebAddresses(args.operationId, body);
|
|
745
|
+
const source = args.takesNoCredential === true || args.requiresSecretKey === true ? void 0 : sessionSourceOf(this.credential);
|
|
746
|
+
const waitForSession = () => source === void 0 ? void 0 : waitForSessionToken(source, {
|
|
747
|
+
operationId: args.operationId,
|
|
748
|
+
signal: args.signal,
|
|
749
|
+
timeoutMs: args.timeoutMs === void 0 ? this.timeoutMs : timeoutMs
|
|
750
|
+
});
|
|
751
|
+
const idempotencyKey = takesKey ? args.idempotencyKey ?? mintIdempotencyKey() : void 0;
|
|
752
|
+
const keyed = idempotencyKey !== void 0;
|
|
753
|
+
let headers;
|
|
754
|
+
try {
|
|
755
|
+
const firstWait = waitForSession();
|
|
756
|
+
if (firstWait !== void 0) await firstWait;
|
|
757
|
+
headers = this.headers(args, idempotencyKey);
|
|
758
|
+
} catch (error) {
|
|
759
|
+
throw carryingKey(error, idempotencyKey);
|
|
760
|
+
}
|
|
761
|
+
const credentials = args.takesNoCredential === true ? "omit" : this.credentialsMode;
|
|
762
|
+
let waitedMs = 0;
|
|
763
|
+
let retries = 0;
|
|
764
|
+
for (let attempt = 0;; attempt += 1) {
|
|
765
|
+
if (attempt > 0) try {
|
|
766
|
+
const waiting = waitForSession();
|
|
767
|
+
if (waiting !== void 0) await waiting;
|
|
768
|
+
headers = this.headers(args, idempotencyKey);
|
|
769
|
+
} catch (error) {
|
|
770
|
+
throw carryingKey(error, idempotencyKey);
|
|
771
|
+
}
|
|
772
|
+
const deadline = attemptSignal(timeoutMs, args.signal);
|
|
773
|
+
let response;
|
|
774
|
+
try {
|
|
775
|
+
response = await this.doFetch(url, {
|
|
776
|
+
body,
|
|
777
|
+
credentials,
|
|
778
|
+
headers,
|
|
779
|
+
method: args.method,
|
|
780
|
+
signal: deadline.signal
|
|
781
|
+
});
|
|
782
|
+
} catch (cause) {
|
|
783
|
+
deadline.release();
|
|
784
|
+
if (args.signal !== void 0 && isAborted(args.signal)) throw abortReasonOf(args.signal);
|
|
785
|
+
const failure = new MountayaConnectionError(deadline.timedOut() ? `${args.operationId}: no response within ${timeoutMs} ms. Raise timeoutMs for a call that is slow to answer, or check the network path to the API.` : `${args.operationId}: the request failed before a response arrived. Check the network, and that baseUrls.${args.surface} names a host that answers.`, cause, idempotencyKey);
|
|
786
|
+
if (!shouldRetry({
|
|
787
|
+
idempotent: args.idempotent,
|
|
788
|
+
keyed,
|
|
789
|
+
maxRetries: retry.maxRetries,
|
|
790
|
+
retries
|
|
791
|
+
})) throw failure;
|
|
792
|
+
const delay = jitteredDelay({
|
|
793
|
+
attempt,
|
|
794
|
+
baseDelayMs: retry.baseDelayMs,
|
|
795
|
+
maxDelayMs: retry.maxDelayMs
|
|
796
|
+
});
|
|
797
|
+
if (waitedMs + delay > retry.maxWaitMs) throw failure;
|
|
798
|
+
waitedMs += delay;
|
|
799
|
+
retries += 1;
|
|
800
|
+
await sleep(delay, args.signal);
|
|
801
|
+
continue;
|
|
802
|
+
}
|
|
803
|
+
deadline.release();
|
|
804
|
+
this.report(response, args, attempt);
|
|
805
|
+
if (response.ok) return {
|
|
806
|
+
idempotencyKey,
|
|
807
|
+
response
|
|
808
|
+
};
|
|
809
|
+
let code;
|
|
810
|
+
if (response.status === 409 && keyed || response.status === 429) {
|
|
811
|
+
const text = await readFailureText(response, args.signal);
|
|
812
|
+
code = firstCodeOf(text);
|
|
813
|
+
response = rereadable(response, text);
|
|
814
|
+
}
|
|
815
|
+
const answered = {
|
|
816
|
+
code,
|
|
817
|
+
idempotent: args.idempotent,
|
|
818
|
+
keyed,
|
|
819
|
+
status: response.status
|
|
820
|
+
};
|
|
821
|
+
if (!shouldRetry({
|
|
822
|
+
...answered,
|
|
823
|
+
maxRetries: retry.maxRetries,
|
|
824
|
+
retries
|
|
825
|
+
})) return {
|
|
826
|
+
idempotencyKey,
|
|
827
|
+
response
|
|
828
|
+
};
|
|
829
|
+
const inUse = isKeyInUse(answered);
|
|
830
|
+
const scheduled = backoffDelay({
|
|
831
|
+
attempt,
|
|
832
|
+
baseDelayMs: retry.baseDelayMs,
|
|
833
|
+
maxDelayMs: retry.maxDelayMs,
|
|
834
|
+
retryAfterSeconds: parseRetryAfter(response.headers.get("Retry-After"))
|
|
835
|
+
});
|
|
836
|
+
const delay = inUse ? Math.max(KEY_IN_USE_MIN_WAIT_MS, scheduled) : scheduled;
|
|
837
|
+
if (waitedMs + delay > retry.maxWaitMs) return {
|
|
838
|
+
idempotencyKey,
|
|
839
|
+
response
|
|
840
|
+
};
|
|
841
|
+
discardBody(response);
|
|
842
|
+
waitedMs += delay;
|
|
843
|
+
if (!inUse) retries += 1;
|
|
844
|
+
await sleep(delay, args.signal);
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
async request(args) {
|
|
848
|
+
const { idempotencyKey, response } = await this.send(args);
|
|
849
|
+
const call = {
|
|
850
|
+
...args,
|
|
851
|
+
idempotencyKey
|
|
852
|
+
};
|
|
853
|
+
if (!response.ok) throw await readFailure(response, call);
|
|
854
|
+
const text = await readText(response, call);
|
|
855
|
+
const decoded = decodeSuccessDates(parseSuccessBody(text, response, call), args.dates, response, call);
|
|
856
|
+
return withAbsentNulls(decoded, args.surface === "rest" ? responseNullMask(args.operationId) : void 0);
|
|
857
|
+
}
|
|
858
|
+
async requestBinary(args) {
|
|
859
|
+
const { idempotencyKey, response } = await this.send(args);
|
|
860
|
+
const call = {
|
|
861
|
+
...args,
|
|
862
|
+
idempotencyKey
|
|
863
|
+
};
|
|
864
|
+
if (!response.ok) throw await readFailure(response, call);
|
|
865
|
+
return {
|
|
866
|
+
bytes: await readBytes(response, call),
|
|
867
|
+
contentType: response.headers.get("Content-Type") ?? void 0,
|
|
868
|
+
filename: filenameFromContentDisposition(response.headers.get("Content-Disposition"))
|
|
869
|
+
};
|
|
870
|
+
}
|
|
871
|
+
headers(args, idempotencyKey) {
|
|
872
|
+
const operation = args;
|
|
873
|
+
const headers = {
|
|
874
|
+
Accept: args.accept ?? "application/json",
|
|
875
|
+
...credentialHeaders(this.credential, operation)
|
|
876
|
+
};
|
|
877
|
+
if (args.body !== void 0 && !isFormData(args.body)) headers["Content-Type"] = "application/json";
|
|
878
|
+
headers["Accept-Language"] = this.language ?? NO_LANGUAGE;
|
|
879
|
+
headers["X-Mountaya-Client"] = CLIENT_HEADER_VALUE;
|
|
880
|
+
if (idempotencyKey !== void 0) headers["Idempotency-Key"] = idempotencyKey;
|
|
881
|
+
if (args.ifMatch !== void 0) headers["If-Match"] = args.ifMatch;
|
|
882
|
+
return headers;
|
|
883
|
+
}
|
|
884
|
+
report(response, call, attempt) {
|
|
885
|
+
if (this.onResponse === void 0) return;
|
|
886
|
+
try {
|
|
887
|
+
this.onResponse({
|
|
888
|
+
attempt,
|
|
889
|
+
operationId: call.operationId,
|
|
890
|
+
replayed: replayedOf(response.headers),
|
|
891
|
+
status: response.status,
|
|
892
|
+
surface: call.surface,
|
|
893
|
+
...answerDetailsOf(response.headers)
|
|
894
|
+
});
|
|
895
|
+
} catch (fault) {
|
|
896
|
+
surfaceFault$1(fault);
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
};
|
|
900
|
+
const DATA_API_BUDGET_MS = 3e4;
|
|
901
|
+
const apqUnsupported = /* @__PURE__ */ new WeakSet();
|
|
902
|
+
const MAX_MEMOISED_DIGESTS = 256;
|
|
903
|
+
const documentHashes = /* @__PURE__ */ new Map();
|
|
904
|
+
const subtleCrypto = () => {
|
|
905
|
+
return globalThis.crypto?.subtle;
|
|
906
|
+
};
|
|
907
|
+
const hashDocument = (query) => {
|
|
908
|
+
const memoised = documentHashes.get(query);
|
|
909
|
+
if (memoised !== void 0) return memoised;
|
|
910
|
+
const subtle = subtleCrypto();
|
|
911
|
+
if (subtle === void 0) return;
|
|
912
|
+
const digest = subtle.digest("SHA-256", new TextEncoder().encode(query)).then((bytes) => Array.from(new Uint8Array(bytes), (byte) => byte.toString(16).padStart(2, "0")).join(""));
|
|
913
|
+
digest.catch(() => documentHashes.delete(query));
|
|
914
|
+
if (documentHashes.size >= MAX_MEMOISED_DIGESTS) {
|
|
915
|
+
const oldest = documentHashes.keys().next().value;
|
|
916
|
+
if (oldest !== void 0) documentHashes.delete(oldest);
|
|
917
|
+
}
|
|
918
|
+
documentHashes.set(query, digest);
|
|
919
|
+
return digest;
|
|
920
|
+
};
|
|
921
|
+
const persistedQueryFor = async (transport, query) => {
|
|
922
|
+
if (apqUnsupported.has(transport)) return;
|
|
923
|
+
const digest = hashDocument(query);
|
|
924
|
+
if (digest === void 0) return;
|
|
925
|
+
try {
|
|
926
|
+
return {
|
|
927
|
+
sha256Hash: await digest,
|
|
928
|
+
version: 1
|
|
929
|
+
};
|
|
930
|
+
} catch {
|
|
931
|
+
return;
|
|
932
|
+
}
|
|
933
|
+
};
|
|
934
|
+
const named = (entries, message) => entries.some((entry) => entry.message === message);
|
|
935
|
+
const coded = (entries, code) => entries.some((entry) => entry.extensions?.code === code);
|
|
936
|
+
const codedAndNamed = (entries, code, message) => entries.some((entry) => entry.extensions?.code === code && entry.message === message);
|
|
937
|
+
const declinesProtocol = (entries) => named(entries, "PersistedQueryNotSupported") || coded(entries, "PERSISTED_QUERY_NOT_SUPPORTED");
|
|
938
|
+
const apqRefusal = (entries) => {
|
|
939
|
+
if (declinesProtocol(entries) || codedAndNamed(entries, "GRAPHQL_VALIDATION_FAILED", "no operation provided")) return "unsupported";
|
|
940
|
+
if (named(entries, "PersistedQueryNotFound") || coded(entries, "PERSISTED_QUERY_NOT_FOUND")) return "register";
|
|
941
|
+
};
|
|
942
|
+
const execute = async (transport, operationId, body, options) => {
|
|
943
|
+
const response = await transport.requestRaw({
|
|
944
|
+
body,
|
|
945
|
+
idempotent: true,
|
|
946
|
+
method: "POST",
|
|
947
|
+
operationId,
|
|
948
|
+
path: "/graphql",
|
|
949
|
+
read: true,
|
|
950
|
+
requiresSession: true,
|
|
951
|
+
retry: options?.retry,
|
|
952
|
+
serverBudgetMs: DATA_API_BUDGET_MS,
|
|
953
|
+
signal: options?.signal,
|
|
954
|
+
surface: "data",
|
|
955
|
+
timeoutMs: options?.timeoutMs
|
|
956
|
+
});
|
|
957
|
+
const raw = response.ok ? await readText(response, {
|
|
958
|
+
idempotent: true,
|
|
959
|
+
operationId,
|
|
960
|
+
signal: options?.signal
|
|
961
|
+
}) : await readFailureText(response, options?.signal);
|
|
962
|
+
const envelope = (() => {
|
|
963
|
+
if (response.ok) return parseSuccessBody(raw, response, {
|
|
964
|
+
operationId,
|
|
965
|
+
surface: "data"
|
|
966
|
+
});
|
|
967
|
+
try {
|
|
968
|
+
return parseJsonWithDates(raw);
|
|
969
|
+
} catch {
|
|
970
|
+
return;
|
|
971
|
+
}
|
|
972
|
+
})();
|
|
973
|
+
return {
|
|
974
|
+
entries: entriesOf(envelope),
|
|
975
|
+
envelope,
|
|
976
|
+
raw,
|
|
977
|
+
response
|
|
978
|
+
};
|
|
979
|
+
};
|
|
980
|
+
const unwrap = async (operationId, attempt, dates) => {
|
|
981
|
+
const { entries, envelope, raw, response } = attempt;
|
|
982
|
+
const details = answerDetailsOf(response.headers);
|
|
983
|
+
if (!response.ok) {
|
|
984
|
+
if (entries.length > 0) {
|
|
985
|
+
const retryAfterSeconds = parseRetryAfter(response.headers.get("Retry-After"));
|
|
986
|
+
throw errorForStatus(failureMessage(operationId, response.status, entries, {
|
|
987
|
+
rateLimit: details.rateLimit,
|
|
988
|
+
requestId: details.requestId,
|
|
989
|
+
retryAfterSeconds
|
|
990
|
+
}), response.status, entries, {
|
|
991
|
+
...details,
|
|
992
|
+
metadata: metadataOf(envelope),
|
|
993
|
+
retryAfter: retryAfterSeconds
|
|
994
|
+
});
|
|
995
|
+
}
|
|
996
|
+
throw errorFromBody(raw, response, operationId);
|
|
997
|
+
}
|
|
998
|
+
if (statesErrors(envelope)) {
|
|
999
|
+
const message = failureMessage(operationId, void 0, entries);
|
|
1000
|
+
const summary = message === operationId ? `${operationId}: the Data API returned an error` : message;
|
|
1001
|
+
throw new MountayaDataError(details.requestId === void 0 ? summary : `${summary} (request ${details.requestId})`, 200, entries, {
|
|
1002
|
+
...details,
|
|
1003
|
+
metadata: metadataOf(envelope)
|
|
1004
|
+
});
|
|
1005
|
+
}
|
|
1006
|
+
const data = envelope?.data;
|
|
1007
|
+
if (data === void 0 || data === null) throw new MountayaDataError(`${operationId}: the Data API returned no data`, 200, [], details);
|
|
1008
|
+
const result = data[operationId];
|
|
1009
|
+
if (result === void 0) throw new MountayaDataError(`${operationId}: the Data API answered without a '${operationId}' field`, 200, [], details);
|
|
1010
|
+
return decodeSuccessDates(result, dates, response, { operationId });
|
|
1011
|
+
};
|
|
1012
|
+
const runOperation = async (transport, operationId, query, input, options, dates) => {
|
|
1013
|
+
const variables = { input };
|
|
1014
|
+
const persistedQuery = await persistedQueryFor(transport, query);
|
|
1015
|
+
if (persistedQuery === void 0) {
|
|
1016
|
+
const attempt = await execute(transport, operationId, {
|
|
1017
|
+
query,
|
|
1018
|
+
variables
|
|
1019
|
+
}, options);
|
|
1020
|
+
return unwrap(operationId, attempt, dates);
|
|
1021
|
+
}
|
|
1022
|
+
const probe = await execute(transport, operationId, {
|
|
1023
|
+
extensions: { persistedQuery },
|
|
1024
|
+
variables
|
|
1025
|
+
}, options);
|
|
1026
|
+
const refusal = apqRefusal(probe.entries);
|
|
1027
|
+
if (refusal === void 0) return unwrap(operationId, probe, dates);
|
|
1028
|
+
if (refusal === "unsupported") apqUnsupported.add(transport);
|
|
1029
|
+
const registration = await execute(transport, operationId, refusal === "register" ? {
|
|
1030
|
+
extensions: { persistedQuery },
|
|
1031
|
+
query,
|
|
1032
|
+
variables
|
|
1033
|
+
} : {
|
|
1034
|
+
query,
|
|
1035
|
+
variables
|
|
1036
|
+
}, options);
|
|
1037
|
+
if (refusal === "register" && declinesProtocol(registration.entries)) {
|
|
1038
|
+
apqUnsupported.add(transport);
|
|
1039
|
+
return unwrap(operationId, await execute(transport, operationId, {
|
|
1040
|
+
query,
|
|
1041
|
+
variables
|
|
1042
|
+
}, options), dates);
|
|
1043
|
+
}
|
|
1044
|
+
return unwrap(operationId, registration, dates);
|
|
1045
|
+
};
|
|
1046
|
+
const INDENT = " ";
|
|
1047
|
+
var MountayaSelectionError = class extends MountayaError {
|
|
1048
|
+
name = "MountayaSelectionError";
|
|
1049
|
+
};
|
|
1050
|
+
const MAX_MEMOISED_DOCUMENTS = 256;
|
|
1051
|
+
const documents = /* @__PURE__ */ new WeakMap();
|
|
1052
|
+
const selectionKey = (selection, tree) => {
|
|
1053
|
+
const prototype = Object.getPrototypeOf(selection);
|
|
1054
|
+
if (prototype !== Object.prototype && prototype !== null) return;
|
|
1055
|
+
let key = "{";
|
|
1056
|
+
for (const [name, picked] of Object.entries(selection)) {
|
|
1057
|
+
if (picked === void 0) continue;
|
|
1058
|
+
const node = Object.hasOwn(tree, name) ? tree[name] : void 0;
|
|
1059
|
+
if (node === void 0) return;
|
|
1060
|
+
if (picked === true) {
|
|
1061
|
+
key += `${JSON.stringify(name)}:true,`;
|
|
1062
|
+
continue;
|
|
1063
|
+
}
|
|
1064
|
+
if (node === true || typeof picked !== "object" || picked === null) return;
|
|
1065
|
+
const nested = selectionKey(picked, node);
|
|
1066
|
+
if (nested === void 0) return;
|
|
1067
|
+
key += `${JSON.stringify(name)}:${nested},`;
|
|
1068
|
+
}
|
|
1069
|
+
return `${key}}`;
|
|
1070
|
+
};
|
|
1071
|
+
const documentFor = (operation, inputType, tree, fullDocument, selection) => {
|
|
1072
|
+
if (selection === void 0) return fullDocument;
|
|
1073
|
+
if (typeof selection !== "object" || selection === null) return printDocument(operation, inputType, tree, selection);
|
|
1074
|
+
const content = selectionKey(selection, tree);
|
|
1075
|
+
if (content === void 0) return printDocument(operation, inputType, tree, selection);
|
|
1076
|
+
const key = `${operation}\u0000${inputType}\u0000${content}`;
|
|
1077
|
+
const memo = documents.get(tree) ?? /* @__PURE__ */ new Map();
|
|
1078
|
+
const memoised = memo.get(key);
|
|
1079
|
+
if (memoised !== void 0) return memoised;
|
|
1080
|
+
const document = printDocument(operation, inputType, tree, selection);
|
|
1081
|
+
if (memo.size >= MAX_MEMOISED_DOCUMENTS) {
|
|
1082
|
+
const oldest = memo.keys().next().value;
|
|
1083
|
+
if (oldest !== void 0) memo.delete(oldest);
|
|
1084
|
+
}
|
|
1085
|
+
memo.set(key, document);
|
|
1086
|
+
documents.set(tree, memo);
|
|
1087
|
+
return document;
|
|
1088
|
+
};
|
|
1089
|
+
const printDocument = (operation, inputType, tree, selection) => {
|
|
1090
|
+
const body = printSelection(operation, tree, selection, 1);
|
|
1091
|
+
if (body === "") throw new MountayaSelectionError(`${operation}: a selection must name at least one field`);
|
|
1092
|
+
return `query ${exportName(operation)}($input: ${inputType}) {\n${INDENT}${operation}(input: $input) {\n${body}${INDENT}}\n}\n`;
|
|
1093
|
+
};
|
|
1094
|
+
const printSelection = (at, tree, selection, depth) => {
|
|
1095
|
+
if (selection !== void 0) assertSelectable(at, tree, selection);
|
|
1096
|
+
const indent = INDENT.repeat(depth + 1);
|
|
1097
|
+
let out = "";
|
|
1098
|
+
for (const [name, node] of Object.entries(tree)) {
|
|
1099
|
+
const picked = selection === void 0 ? true : selection[name];
|
|
1100
|
+
if (picked === void 0) continue;
|
|
1101
|
+
if (node === true) {
|
|
1102
|
+
out += `${indent}${name}\n`;
|
|
1103
|
+
continue;
|
|
1104
|
+
}
|
|
1105
|
+
const sub = printSelection(`${at}.${name}`, node, picked === true ? void 0 : picked, depth + 1);
|
|
1106
|
+
if (sub === "") throw new MountayaSelectionError(`${at}.${name}: a selection must name at least one field`);
|
|
1107
|
+
out += `${indent}${name} {\n${sub}${indent}}\n`;
|
|
1108
|
+
}
|
|
1109
|
+
return out;
|
|
1110
|
+
};
|
|
1111
|
+
const isSelectionValue = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1112
|
+
const spell = (value) => {
|
|
1113
|
+
if (typeof value === "string") return JSON.stringify(value);
|
|
1114
|
+
return typeof value === "object" || typeof value === "function" ? describeType(value) : String(value);
|
|
1115
|
+
};
|
|
1116
|
+
function assertSelectable(at, tree, selection) {
|
|
1117
|
+
if (!isSelectionValue(selection)) throw new MountayaSelectionError(`${at}: a selection is an object naming fields, and this one is ${spell(selection)}; valid fields are: ${Object.keys(tree).join(", ")}`);
|
|
1118
|
+
for (const [name, picked] of Object.entries(selection)) {
|
|
1119
|
+
if (picked === void 0) continue;
|
|
1120
|
+
const node = Object.hasOwn(tree, name) ? tree[name] : void 0;
|
|
1121
|
+
if (node === void 0) throw new MountayaSelectionError(`${at}: unknown field "${name}"; valid fields are: ${Object.keys(tree).join(", ")}`);
|
|
1122
|
+
if (picked !== true && !isSelectionValue(picked)) throw new MountayaSelectionError(`${at}.${name} is ${spell(picked)}; select a field with true, or leave it out.`);
|
|
1123
|
+
if (node === true && picked !== true) throw new MountayaSelectionError(`${at}: field "${name}" is a leaf and takes no sub-selection`);
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
const exportName = (name) => name === "" ? name : `${name[0]?.toUpperCase() ?? ""}${name.slice(1)}`;
|
|
1127
|
+
var selection_gen_exports = /* @__PURE__ */ __exportAll({
|
|
1128
|
+
analyzeGeometryFields: () => analyzeGeometryFields,
|
|
1129
|
+
directionsFields: () => directionsFields,
|
|
1130
|
+
exportItineraryFields: () => exportItineraryFields,
|
|
1131
|
+
geocodeFields: () => geocodeFields,
|
|
1132
|
+
isochronesFields: () => isochronesFields,
|
|
1133
|
+
itineraryFields: () => itineraryFields,
|
|
1134
|
+
matrixFields: () => matrixFields,
|
|
1135
|
+
poisFields: () => poisFields,
|
|
1136
|
+
reverseGeocodeFields: () => reverseGeocodeFields,
|
|
1137
|
+
searchFields: () => searchFields,
|
|
1138
|
+
suggestionsFields: () => suggestionsFields,
|
|
1139
|
+
terrainGridFields: () => terrainGridFields,
|
|
1140
|
+
terrainProfileFields: () => terrainProfileFields,
|
|
1141
|
+
terrainSamplesFields: () => terrainSamplesFields
|
|
1142
|
+
});
|
|
1143
|
+
const analyzeGeometryFields = {
|
|
1144
|
+
analysis: {
|
|
1145
|
+
elevation: {
|
|
1146
|
+
altitude: {
|
|
1147
|
+
max: true,
|
|
1148
|
+
min: true
|
|
1149
|
+
},
|
|
1150
|
+
ascent: true,
|
|
1151
|
+
descent: true,
|
|
1152
|
+
gradient: {
|
|
1153
|
+
max: true,
|
|
1154
|
+
min: true
|
|
1155
|
+
}
|
|
1156
|
+
},
|
|
1157
|
+
elevations: true,
|
|
1158
|
+
slopeInfo: {
|
|
1159
|
+
fromIndex: true,
|
|
1160
|
+
toIndex: true,
|
|
1161
|
+
value: true
|
|
1162
|
+
},
|
|
1163
|
+
speedInfo: {
|
|
1164
|
+
fromIndex: true,
|
|
1165
|
+
toIndex: true,
|
|
1166
|
+
value: true
|
|
1167
|
+
},
|
|
1168
|
+
surfaceInfo: {
|
|
1169
|
+
fromIndex: true,
|
|
1170
|
+
toIndex: true,
|
|
1171
|
+
value: true
|
|
1172
|
+
},
|
|
1173
|
+
trailDifficultyInfo: {
|
|
1174
|
+
fromIndex: true,
|
|
1175
|
+
toIndex: true,
|
|
1176
|
+
value: true
|
|
1177
|
+
},
|
|
1178
|
+
wayTypeInfo: {
|
|
1179
|
+
fromIndex: true,
|
|
1180
|
+
toIndex: true,
|
|
1181
|
+
value: true
|
|
1182
|
+
},
|
|
1183
|
+
advisories: {
|
|
1184
|
+
tollway: true,
|
|
1185
|
+
restrictedAccess: true,
|
|
1186
|
+
tollwayInfo: {
|
|
1187
|
+
fromIndex: true,
|
|
1188
|
+
toIndex: true,
|
|
1189
|
+
value: true
|
|
1190
|
+
},
|
|
1191
|
+
roadAccessInfo: {
|
|
1192
|
+
fromIndex: true,
|
|
1193
|
+
toIndex: true,
|
|
1194
|
+
values: true
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
},
|
|
1198
|
+
duration: true
|
|
1199
|
+
};
|
|
1200
|
+
const directionsFields = { routes: {
|
|
1201
|
+
distance: true,
|
|
1202
|
+
duration: true,
|
|
1203
|
+
elevation: {
|
|
1204
|
+
altitude: {
|
|
1205
|
+
max: true,
|
|
1206
|
+
min: true
|
|
1207
|
+
},
|
|
1208
|
+
ascent: true,
|
|
1209
|
+
descent: true,
|
|
1210
|
+
gradient: {
|
|
1211
|
+
max: true,
|
|
1212
|
+
min: true
|
|
1213
|
+
}
|
|
1214
|
+
},
|
|
1215
|
+
geometry: true,
|
|
1216
|
+
analysis: {
|
|
1217
|
+
elevation: {
|
|
1218
|
+
altitude: {
|
|
1219
|
+
max: true,
|
|
1220
|
+
min: true
|
|
1221
|
+
},
|
|
1222
|
+
ascent: true,
|
|
1223
|
+
descent: true,
|
|
1224
|
+
gradient: {
|
|
1225
|
+
max: true,
|
|
1226
|
+
min: true
|
|
1227
|
+
}
|
|
1228
|
+
},
|
|
1229
|
+
elevations: true,
|
|
1230
|
+
slopeInfo: {
|
|
1231
|
+
fromIndex: true,
|
|
1232
|
+
toIndex: true,
|
|
1233
|
+
value: true
|
|
1234
|
+
},
|
|
1235
|
+
speedInfo: {
|
|
1236
|
+
fromIndex: true,
|
|
1237
|
+
toIndex: true,
|
|
1238
|
+
value: true
|
|
1239
|
+
},
|
|
1240
|
+
surfaceInfo: {
|
|
1241
|
+
fromIndex: true,
|
|
1242
|
+
toIndex: true,
|
|
1243
|
+
value: true
|
|
1244
|
+
},
|
|
1245
|
+
trailDifficultyInfo: {
|
|
1246
|
+
fromIndex: true,
|
|
1247
|
+
toIndex: true,
|
|
1248
|
+
value: true
|
|
1249
|
+
},
|
|
1250
|
+
wayTypeInfo: {
|
|
1251
|
+
fromIndex: true,
|
|
1252
|
+
toIndex: true,
|
|
1253
|
+
value: true
|
|
1254
|
+
},
|
|
1255
|
+
advisories: {
|
|
1256
|
+
tollway: true,
|
|
1257
|
+
restrictedAccess: true,
|
|
1258
|
+
tollwayInfo: {
|
|
1259
|
+
fromIndex: true,
|
|
1260
|
+
toIndex: true,
|
|
1261
|
+
value: true
|
|
1262
|
+
},
|
|
1263
|
+
roadAccessInfo: {
|
|
1264
|
+
fromIndex: true,
|
|
1265
|
+
toIndex: true,
|
|
1266
|
+
values: true
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
},
|
|
1270
|
+
avoidance: true,
|
|
1271
|
+
summary: true,
|
|
1272
|
+
steps: {
|
|
1273
|
+
fromIndex: true,
|
|
1274
|
+
toIndex: true,
|
|
1275
|
+
type: true,
|
|
1276
|
+
name: true,
|
|
1277
|
+
distance: true,
|
|
1278
|
+
duration: true,
|
|
1279
|
+
exitNumber: true
|
|
1280
|
+
}
|
|
1281
|
+
} };
|
|
1282
|
+
const exportItineraryFields = {
|
|
1283
|
+
url: true,
|
|
1284
|
+
filename: true,
|
|
1285
|
+
format: true,
|
|
1286
|
+
expiresAt: true
|
|
1287
|
+
};
|
|
1288
|
+
const geocodeFields = {
|
|
1289
|
+
count: true,
|
|
1290
|
+
places: {
|
|
1291
|
+
osm: {
|
|
1292
|
+
id: true,
|
|
1293
|
+
type: true,
|
|
1294
|
+
key: true,
|
|
1295
|
+
value: true
|
|
1296
|
+
},
|
|
1297
|
+
name: true,
|
|
1298
|
+
label: true,
|
|
1299
|
+
layer: true,
|
|
1300
|
+
category: true,
|
|
1301
|
+
point: true,
|
|
1302
|
+
bounds: true,
|
|
1303
|
+
country: true,
|
|
1304
|
+
countryName: true,
|
|
1305
|
+
region: true,
|
|
1306
|
+
county: true,
|
|
1307
|
+
city: true,
|
|
1308
|
+
postcode: true,
|
|
1309
|
+
street: true,
|
|
1310
|
+
houseNumber: true
|
|
1311
|
+
}
|
|
1312
|
+
};
|
|
1313
|
+
const isochronesFields = { isochrones: {
|
|
1314
|
+
value: true,
|
|
1315
|
+
area: true,
|
|
1316
|
+
reachFactor: true,
|
|
1317
|
+
center: true,
|
|
1318
|
+
geometry: true
|
|
1319
|
+
} };
|
|
1320
|
+
const itineraryFields = {
|
|
1321
|
+
id: true,
|
|
1322
|
+
name: true,
|
|
1323
|
+
description: true,
|
|
1324
|
+
activitySlug: true,
|
|
1325
|
+
distance: true,
|
|
1326
|
+
ascent: true,
|
|
1327
|
+
isPrivate: true,
|
|
1328
|
+
organizationId: true,
|
|
1329
|
+
segments: {
|
|
1330
|
+
id: true,
|
|
1331
|
+
name: true,
|
|
1332
|
+
description: true,
|
|
1333
|
+
position: true,
|
|
1334
|
+
groupId: true,
|
|
1335
|
+
distance: true,
|
|
1336
|
+
duration: true,
|
|
1337
|
+
ascent: true,
|
|
1338
|
+
descent: true,
|
|
1339
|
+
altitude: {
|
|
1340
|
+
max: true,
|
|
1341
|
+
min: true
|
|
1342
|
+
},
|
|
1343
|
+
gradient: {
|
|
1344
|
+
max: true,
|
|
1345
|
+
min: true
|
|
1346
|
+
},
|
|
1347
|
+
geometry: true
|
|
1348
|
+
},
|
|
1349
|
+
waypoints: {
|
|
1350
|
+
id: true,
|
|
1351
|
+
name: true,
|
|
1352
|
+
description: true,
|
|
1353
|
+
position: true,
|
|
1354
|
+
point: true,
|
|
1355
|
+
amenities: true,
|
|
1356
|
+
timing: {
|
|
1357
|
+
cutoffAt: true,
|
|
1358
|
+
stopDuration: true
|
|
1359
|
+
},
|
|
1360
|
+
contact: {
|
|
1361
|
+
website: true,
|
|
1362
|
+
phone: true,
|
|
1363
|
+
email: true,
|
|
1364
|
+
address: true,
|
|
1365
|
+
openingHours: true,
|
|
1366
|
+
bookingUrl: true
|
|
1367
|
+
},
|
|
1368
|
+
media: {
|
|
1369
|
+
photos: {
|
|
1370
|
+
url: true,
|
|
1371
|
+
caption: true
|
|
1372
|
+
},
|
|
1373
|
+
links: {
|
|
1374
|
+
label: true,
|
|
1375
|
+
url: true
|
|
1376
|
+
}
|
|
1377
|
+
},
|
|
1378
|
+
properties: {
|
|
1379
|
+
key: true,
|
|
1380
|
+
label: true,
|
|
1381
|
+
value: true,
|
|
1382
|
+
format: true
|
|
1383
|
+
}
|
|
1384
|
+
},
|
|
1385
|
+
groups: {
|
|
1386
|
+
id: true,
|
|
1387
|
+
name: true,
|
|
1388
|
+
color: true,
|
|
1389
|
+
speed: true
|
|
1390
|
+
},
|
|
1391
|
+
segmentCount: true,
|
|
1392
|
+
waypointCount: true,
|
|
1393
|
+
groupCount: true
|
|
1394
|
+
};
|
|
1395
|
+
const matrixFields = {
|
|
1396
|
+
durations: true,
|
|
1397
|
+
distances: true
|
|
1398
|
+
};
|
|
1399
|
+
const poisFields = {
|
|
1400
|
+
count: true,
|
|
1401
|
+
pois: {
|
|
1402
|
+
osm: {
|
|
1403
|
+
id: true,
|
|
1404
|
+
type: true,
|
|
1405
|
+
key: true,
|
|
1406
|
+
value: true
|
|
1407
|
+
},
|
|
1408
|
+
name: true,
|
|
1409
|
+
category: true,
|
|
1410
|
+
point: true,
|
|
1411
|
+
elevation: true,
|
|
1412
|
+
tags: {
|
|
1413
|
+
key: true,
|
|
1414
|
+
value: true
|
|
1415
|
+
},
|
|
1416
|
+
distanceMeters: true,
|
|
1417
|
+
country: true,
|
|
1418
|
+
countryName: true,
|
|
1419
|
+
region: true,
|
|
1420
|
+
city: true
|
|
1421
|
+
}
|
|
1422
|
+
};
|
|
1423
|
+
const reverseGeocodeFields = {
|
|
1424
|
+
point: true,
|
|
1425
|
+
places: {
|
|
1426
|
+
osm: {
|
|
1427
|
+
id: true,
|
|
1428
|
+
type: true,
|
|
1429
|
+
key: true,
|
|
1430
|
+
value: true
|
|
1431
|
+
},
|
|
1432
|
+
name: true,
|
|
1433
|
+
label: true,
|
|
1434
|
+
layer: true,
|
|
1435
|
+
category: true,
|
|
1436
|
+
point: true,
|
|
1437
|
+
bounds: true,
|
|
1438
|
+
country: true,
|
|
1439
|
+
countryName: true,
|
|
1440
|
+
region: true,
|
|
1441
|
+
county: true,
|
|
1442
|
+
city: true,
|
|
1443
|
+
postcode: true,
|
|
1444
|
+
street: true,
|
|
1445
|
+
houseNumber: true
|
|
1446
|
+
},
|
|
1447
|
+
count: true
|
|
1448
|
+
};
|
|
1449
|
+
const searchFields = {
|
|
1450
|
+
query: true,
|
|
1451
|
+
language: true,
|
|
1452
|
+
targets: {
|
|
1453
|
+
places: true,
|
|
1454
|
+
pois: true,
|
|
1455
|
+
ways: true,
|
|
1456
|
+
itineraries: true,
|
|
1457
|
+
collections: true,
|
|
1458
|
+
zones: true
|
|
1459
|
+
},
|
|
1460
|
+
places: {
|
|
1461
|
+
count: true,
|
|
1462
|
+
places: {
|
|
1463
|
+
osm: {
|
|
1464
|
+
id: true,
|
|
1465
|
+
type: true,
|
|
1466
|
+
key: true,
|
|
1467
|
+
value: true
|
|
1468
|
+
},
|
|
1469
|
+
name: true,
|
|
1470
|
+
label: true,
|
|
1471
|
+
layer: true,
|
|
1472
|
+
category: true,
|
|
1473
|
+
point: true,
|
|
1474
|
+
bounds: true,
|
|
1475
|
+
country: true,
|
|
1476
|
+
countryName: true,
|
|
1477
|
+
region: true,
|
|
1478
|
+
county: true,
|
|
1479
|
+
city: true,
|
|
1480
|
+
postcode: true,
|
|
1481
|
+
street: true,
|
|
1482
|
+
houseNumber: true
|
|
1483
|
+
}
|
|
1484
|
+
},
|
|
1485
|
+
pois: {
|
|
1486
|
+
count: true,
|
|
1487
|
+
pois: {
|
|
1488
|
+
osm: {
|
|
1489
|
+
id: true,
|
|
1490
|
+
type: true,
|
|
1491
|
+
key: true,
|
|
1492
|
+
value: true
|
|
1493
|
+
},
|
|
1494
|
+
name: true,
|
|
1495
|
+
category: true,
|
|
1496
|
+
point: true,
|
|
1497
|
+
elevation: true,
|
|
1498
|
+
tags: {
|
|
1499
|
+
key: true,
|
|
1500
|
+
value: true
|
|
1501
|
+
},
|
|
1502
|
+
distanceMeters: true,
|
|
1503
|
+
country: true,
|
|
1504
|
+
countryName: true,
|
|
1505
|
+
region: true,
|
|
1506
|
+
city: true
|
|
1507
|
+
}
|
|
1508
|
+
},
|
|
1509
|
+
ways: {
|
|
1510
|
+
count: true,
|
|
1511
|
+
ways: {
|
|
1512
|
+
osm: {
|
|
1513
|
+
id: true,
|
|
1514
|
+
type: true,
|
|
1515
|
+
key: true,
|
|
1516
|
+
value: true
|
|
1517
|
+
},
|
|
1518
|
+
name: true,
|
|
1519
|
+
highway: true,
|
|
1520
|
+
surface: true,
|
|
1521
|
+
sacScale: true,
|
|
1522
|
+
point: true,
|
|
1523
|
+
bounds: true,
|
|
1524
|
+
coordinates: true,
|
|
1525
|
+
activityCompatible: true,
|
|
1526
|
+
country: true,
|
|
1527
|
+
countryName: true,
|
|
1528
|
+
region: true,
|
|
1529
|
+
city: true
|
|
1530
|
+
},
|
|
1531
|
+
activityApplied: true
|
|
1532
|
+
},
|
|
1533
|
+
itineraries: {
|
|
1534
|
+
count: true,
|
|
1535
|
+
itineraries: {
|
|
1536
|
+
id: true,
|
|
1537
|
+
name: true,
|
|
1538
|
+
description: true,
|
|
1539
|
+
distance: true,
|
|
1540
|
+
ascent: true,
|
|
1541
|
+
activitySlug: true,
|
|
1542
|
+
start: true,
|
|
1543
|
+
bounds: true,
|
|
1544
|
+
isPrivate: true,
|
|
1545
|
+
organizationId: true,
|
|
1546
|
+
score: true,
|
|
1547
|
+
matchedField: true
|
|
1548
|
+
}
|
|
1549
|
+
},
|
|
1550
|
+
collections: {
|
|
1551
|
+
count: true,
|
|
1552
|
+
collections: {
|
|
1553
|
+
id: true,
|
|
1554
|
+
name: true,
|
|
1555
|
+
description: true,
|
|
1556
|
+
count: {
|
|
1557
|
+
itineraries: true,
|
|
1558
|
+
zones: true
|
|
1559
|
+
},
|
|
1560
|
+
bounds: true,
|
|
1561
|
+
isPrivate: true,
|
|
1562
|
+
organizationId: true,
|
|
1563
|
+
score: true,
|
|
1564
|
+
matchedField: true
|
|
1565
|
+
}
|
|
1566
|
+
},
|
|
1567
|
+
zones: {
|
|
1568
|
+
count: true,
|
|
1569
|
+
zones: {
|
|
1570
|
+
id: true,
|
|
1571
|
+
name: true,
|
|
1572
|
+
description: true,
|
|
1573
|
+
level: true,
|
|
1574
|
+
mode: true,
|
|
1575
|
+
point: true,
|
|
1576
|
+
bounds: true,
|
|
1577
|
+
isPrivate: true,
|
|
1578
|
+
organizationId: true,
|
|
1579
|
+
score: true,
|
|
1580
|
+
matchedField: true
|
|
1581
|
+
}
|
|
1582
|
+
},
|
|
1583
|
+
errors: {
|
|
1584
|
+
target: true,
|
|
1585
|
+
code: true,
|
|
1586
|
+
message: true
|
|
1587
|
+
}
|
|
1588
|
+
};
|
|
1589
|
+
const suggestionsFields = { routes: {
|
|
1590
|
+
distance: true,
|
|
1591
|
+
duration: true,
|
|
1592
|
+
elevation: {
|
|
1593
|
+
altitude: {
|
|
1594
|
+
max: true,
|
|
1595
|
+
min: true
|
|
1596
|
+
},
|
|
1597
|
+
ascent: true,
|
|
1598
|
+
descent: true,
|
|
1599
|
+
gradient: {
|
|
1600
|
+
max: true,
|
|
1601
|
+
min: true
|
|
1602
|
+
}
|
|
1603
|
+
},
|
|
1604
|
+
geometry: true,
|
|
1605
|
+
analysis: {
|
|
1606
|
+
elevation: {
|
|
1607
|
+
altitude: {
|
|
1608
|
+
max: true,
|
|
1609
|
+
min: true
|
|
1610
|
+
},
|
|
1611
|
+
ascent: true,
|
|
1612
|
+
descent: true,
|
|
1613
|
+
gradient: {
|
|
1614
|
+
max: true,
|
|
1615
|
+
min: true
|
|
1616
|
+
}
|
|
1617
|
+
},
|
|
1618
|
+
elevations: true,
|
|
1619
|
+
slopeInfo: {
|
|
1620
|
+
fromIndex: true,
|
|
1621
|
+
toIndex: true,
|
|
1622
|
+
value: true
|
|
1623
|
+
},
|
|
1624
|
+
speedInfo: {
|
|
1625
|
+
fromIndex: true,
|
|
1626
|
+
toIndex: true,
|
|
1627
|
+
value: true
|
|
1628
|
+
},
|
|
1629
|
+
surfaceInfo: {
|
|
1630
|
+
fromIndex: true,
|
|
1631
|
+
toIndex: true,
|
|
1632
|
+
value: true
|
|
1633
|
+
},
|
|
1634
|
+
trailDifficultyInfo: {
|
|
1635
|
+
fromIndex: true,
|
|
1636
|
+
toIndex: true,
|
|
1637
|
+
value: true
|
|
1638
|
+
},
|
|
1639
|
+
wayTypeInfo: {
|
|
1640
|
+
fromIndex: true,
|
|
1641
|
+
toIndex: true,
|
|
1642
|
+
value: true
|
|
1643
|
+
},
|
|
1644
|
+
advisories: {
|
|
1645
|
+
tollway: true,
|
|
1646
|
+
restrictedAccess: true,
|
|
1647
|
+
tollwayInfo: {
|
|
1648
|
+
fromIndex: true,
|
|
1649
|
+
toIndex: true,
|
|
1650
|
+
value: true
|
|
1651
|
+
},
|
|
1652
|
+
roadAccessInfo: {
|
|
1653
|
+
fromIndex: true,
|
|
1654
|
+
toIndex: true,
|
|
1655
|
+
values: true
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
},
|
|
1659
|
+
summary: true,
|
|
1660
|
+
steps: {
|
|
1661
|
+
fromIndex: true,
|
|
1662
|
+
toIndex: true,
|
|
1663
|
+
type: true,
|
|
1664
|
+
name: true,
|
|
1665
|
+
distance: true,
|
|
1666
|
+
duration: true,
|
|
1667
|
+
exitNumber: true
|
|
1668
|
+
},
|
|
1669
|
+
seed: true
|
|
1670
|
+
} };
|
|
1671
|
+
const terrainGridFields = {
|
|
1672
|
+
count: true,
|
|
1673
|
+
coveredCount: true,
|
|
1674
|
+
zoom: true,
|
|
1675
|
+
resolutionMeters: true,
|
|
1676
|
+
cols: true,
|
|
1677
|
+
rows: true,
|
|
1678
|
+
cells: {
|
|
1679
|
+
point: true,
|
|
1680
|
+
elevation: true,
|
|
1681
|
+
slope: true,
|
|
1682
|
+
aspect: true,
|
|
1683
|
+
aspectOctant: true,
|
|
1684
|
+
steepnessBand: true,
|
|
1685
|
+
distanceMeters: true
|
|
1686
|
+
}
|
|
1687
|
+
};
|
|
1688
|
+
const terrainProfileFields = {
|
|
1689
|
+
count: true,
|
|
1690
|
+
coveredCount: true,
|
|
1691
|
+
zoom: true,
|
|
1692
|
+
resolutionMeters: true,
|
|
1693
|
+
samples: {
|
|
1694
|
+
point: true,
|
|
1695
|
+
elevation: true,
|
|
1696
|
+
slope: true,
|
|
1697
|
+
aspect: true,
|
|
1698
|
+
aspectOctant: true,
|
|
1699
|
+
steepnessBand: true,
|
|
1700
|
+
distanceMeters: true
|
|
1701
|
+
}
|
|
1702
|
+
};
|
|
1703
|
+
const terrainSamplesFields = {
|
|
1704
|
+
count: true,
|
|
1705
|
+
coveredCount: true,
|
|
1706
|
+
zoom: true,
|
|
1707
|
+
resolutionMeters: true,
|
|
1708
|
+
samples: {
|
|
1709
|
+
point: true,
|
|
1710
|
+
elevation: true,
|
|
1711
|
+
slope: true,
|
|
1712
|
+
aspect: true,
|
|
1713
|
+
aspectOctant: true,
|
|
1714
|
+
steepnessBand: true,
|
|
1715
|
+
distanceMeters: true
|
|
1716
|
+
}
|
|
1717
|
+
};
|
|
1718
|
+
var operations_gen_exports$1 = /* @__PURE__ */ __exportAll({
|
|
1719
|
+
analyzeGeometry: () => analyzeGeometry,
|
|
1720
|
+
bind: () => bind$1,
|
|
1721
|
+
directions: () => directions,
|
|
1722
|
+
exportItinerary: () => exportItinerary,
|
|
1723
|
+
geocode: () => geocode,
|
|
1724
|
+
isochrones: () => isochrones,
|
|
1725
|
+
itinerary: () => itinerary,
|
|
1726
|
+
matrix: () => matrix,
|
|
1727
|
+
pois: () => pois,
|
|
1728
|
+
reverseGeocode: () => reverseGeocode,
|
|
1729
|
+
search: () => search,
|
|
1730
|
+
suggestions: () => suggestions,
|
|
1731
|
+
terrainGrid: () => terrainGrid,
|
|
1732
|
+
terrainProfile: () => terrainProfile,
|
|
1733
|
+
terrainSamples: () => terrainSamples
|
|
1734
|
+
});
|
|
1735
|
+
const analyzeGeometry = (transport, input, options) => runOperation(transport, "analyzeGeometry", documentFor("analyzeGeometry", "AnalyzeGeometryInput!", analyzeGeometryFields, "query AnalyzeGeometry($input: AnalyzeGeometryInput!) {\n analyzeGeometry(input: $input) {\n analysis {\n elevation {\n altitude {\n max\n min\n }\n ascent\n descent\n gradient {\n max\n min\n }\n }\n elevations\n slopeInfo {\n fromIndex\n toIndex\n value\n }\n speedInfo {\n fromIndex\n toIndex\n value\n }\n surfaceInfo {\n fromIndex\n toIndex\n value\n }\n trailDifficultyInfo {\n fromIndex\n toIndex\n value\n }\n wayTypeInfo {\n fromIndex\n toIndex\n value\n }\n advisories {\n tollway\n restrictedAccess\n tollwayInfo {\n fromIndex\n toIndex\n value\n }\n roadAccessInfo {\n fromIndex\n toIndex\n values\n }\n }\n }\n duration\n }\n}\n", options?.select), input, options);
|
|
1736
|
+
const directions = (transport, input, options) => runOperation(transport, "directions", documentFor("directions", "DirectionsInput!", directionsFields, "query Directions($input: DirectionsInput!) {\n directions(input: $input) {\n routes {\n distance\n duration\n elevation {\n altitude {\n max\n min\n }\n ascent\n descent\n gradient {\n max\n min\n }\n }\n geometry\n analysis {\n elevation {\n altitude {\n max\n min\n }\n ascent\n descent\n gradient {\n max\n min\n }\n }\n elevations\n slopeInfo {\n fromIndex\n toIndex\n value\n }\n speedInfo {\n fromIndex\n toIndex\n value\n }\n surfaceInfo {\n fromIndex\n toIndex\n value\n }\n trailDifficultyInfo {\n fromIndex\n toIndex\n value\n }\n wayTypeInfo {\n fromIndex\n toIndex\n value\n }\n advisories {\n tollway\n restrictedAccess\n tollwayInfo {\n fromIndex\n toIndex\n value\n }\n roadAccessInfo {\n fromIndex\n toIndex\n values\n }\n }\n }\n avoidance\n summary\n steps {\n fromIndex\n toIndex\n type\n name\n distance\n duration\n exitNumber\n }\n }\n }\n}\n", options?.select), input, options);
|
|
1737
|
+
const exportItinerary = (transport, input, options) => runOperation(transport, "exportItinerary", documentFor("exportItinerary", "ExportItineraryInput!", exportItineraryFields, "query ExportItinerary($input: ExportItineraryInput!) {\n exportItinerary(input: $input) {\n url\n filename\n format\n expiresAt\n }\n}\n", options?.select), input, options, { expiresAt: true });
|
|
1738
|
+
const geocode = (transport, input, options) => runOperation(transport, "geocode", documentFor("geocode", "GeocodeInput!", geocodeFields, "query Geocode($input: GeocodeInput!) {\n geocode(input: $input) {\n count\n places {\n osm {\n id\n type\n key\n value\n }\n name\n label\n layer\n category\n point\n bounds\n country\n countryName\n region\n county\n city\n postcode\n street\n houseNumber\n }\n }\n}\n", options?.select), input, options);
|
|
1739
|
+
const isochrones = (transport, input, options) => runOperation(transport, "isochrones", documentFor("isochrones", "IsochronesInput!", isochronesFields, "query Isochrones($input: IsochronesInput!) {\n isochrones(input: $input) {\n isochrones {\n value\n area\n reachFactor\n center\n geometry\n }\n }\n}\n", options?.select), input, options);
|
|
1740
|
+
const itinerary = (transport, input, options) => runOperation(transport, "itinerary", documentFor("itinerary", "ItineraryInput!", itineraryFields, "query Itinerary($input: ItineraryInput!) {\n itinerary(input: $input) {\n id\n name\n description\n activitySlug\n distance\n ascent\n isPrivate\n organizationId\n segments {\n id\n name\n description\n position\n groupId\n distance\n duration\n ascent\n descent\n altitude {\n max\n min\n }\n gradient {\n max\n min\n }\n geometry\n }\n waypoints {\n id\n name\n description\n position\n point\n amenities\n timing {\n cutoffAt\n stopDuration\n }\n contact {\n website\n phone\n email\n address\n openingHours\n bookingUrl\n }\n media {\n photos {\n url\n caption\n }\n links {\n label\n url\n }\n }\n properties {\n key\n label\n value\n format\n }\n }\n groups {\n id\n name\n color\n speed\n }\n segmentCount\n waypointCount\n groupCount\n }\n}\n", options?.select), input, options, { waypoints: [{ timing: { cutoffAt: true } }] });
|
|
1741
|
+
const matrix = (transport, input, options) => runOperation(transport, "matrix", documentFor("matrix", "MatrixInput!", matrixFields, "query Matrix($input: MatrixInput!) {\n matrix(input: $input) {\n durations\n distances\n }\n}\n", options?.select), input, options);
|
|
1742
|
+
const pois = (transport, input, options) => runOperation(transport, "pois", documentFor("pois", "PoisInput!", poisFields, "query Pois($input: PoisInput!) {\n pois(input: $input) {\n count\n pois {\n osm {\n id\n type\n key\n value\n }\n name\n category\n point\n elevation\n tags {\n key\n value\n }\n distanceMeters\n country\n countryName\n region\n city\n }\n }\n}\n", options?.select), input, options);
|
|
1743
|
+
const reverseGeocode = (transport, input, options) => runOperation(transport, "reverseGeocode", documentFor("reverseGeocode", "ReverseGeocodeInput!", reverseGeocodeFields, "query ReverseGeocode($input: ReverseGeocodeInput!) {\n reverseGeocode(input: $input) {\n point\n places {\n osm {\n id\n type\n key\n value\n }\n name\n label\n layer\n category\n point\n bounds\n country\n countryName\n region\n county\n city\n postcode\n street\n houseNumber\n }\n count\n }\n}\n", options?.select), input, options);
|
|
1744
|
+
const search = (transport, input, options) => runOperation(transport, "search", documentFor("search", "SearchInput!", searchFields, "query Search($input: SearchInput!) {\n search(input: $input) {\n query\n language\n targets {\n places\n pois\n ways\n itineraries\n collections\n zones\n }\n places {\n count\n places {\n osm {\n id\n type\n key\n value\n }\n name\n label\n layer\n category\n point\n bounds\n country\n countryName\n region\n county\n city\n postcode\n street\n houseNumber\n }\n }\n pois {\n count\n pois {\n osm {\n id\n type\n key\n value\n }\n name\n category\n point\n elevation\n tags {\n key\n value\n }\n distanceMeters\n country\n countryName\n region\n city\n }\n }\n ways {\n count\n ways {\n osm {\n id\n type\n key\n value\n }\n name\n highway\n surface\n sacScale\n point\n bounds\n coordinates\n activityCompatible\n country\n countryName\n region\n city\n }\n activityApplied\n }\n itineraries {\n count\n itineraries {\n id\n name\n description\n distance\n ascent\n activitySlug\n start\n bounds\n isPrivate\n organizationId\n score\n matchedField\n }\n }\n collections {\n count\n collections {\n id\n name\n description\n count {\n itineraries\n zones\n }\n bounds\n isPrivate\n organizationId\n score\n matchedField\n }\n }\n zones {\n count\n zones {\n id\n name\n description\n level\n mode\n point\n bounds\n isPrivate\n organizationId\n score\n matchedField\n }\n }\n errors {\n target\n code\n message\n }\n }\n}\n", options?.select), input, options);
|
|
1745
|
+
const suggestions = (transport, input, options) => runOperation(transport, "suggestions", documentFor("suggestions", "SuggestionsInput!", suggestionsFields, "query Suggestions($input: SuggestionsInput!) {\n suggestions(input: $input) {\n routes {\n distance\n duration\n elevation {\n altitude {\n max\n min\n }\n ascent\n descent\n gradient {\n max\n min\n }\n }\n geometry\n analysis {\n elevation {\n altitude {\n max\n min\n }\n ascent\n descent\n gradient {\n max\n min\n }\n }\n elevations\n slopeInfo {\n fromIndex\n toIndex\n value\n }\n speedInfo {\n fromIndex\n toIndex\n value\n }\n surfaceInfo {\n fromIndex\n toIndex\n value\n }\n trailDifficultyInfo {\n fromIndex\n toIndex\n value\n }\n wayTypeInfo {\n fromIndex\n toIndex\n value\n }\n advisories {\n tollway\n restrictedAccess\n tollwayInfo {\n fromIndex\n toIndex\n value\n }\n roadAccessInfo {\n fromIndex\n toIndex\n values\n }\n }\n }\n summary\n steps {\n fromIndex\n toIndex\n type\n name\n distance\n duration\n exitNumber\n }\n seed\n }\n }\n}\n", options?.select), input, options);
|
|
1746
|
+
const terrainGrid = (transport, input, options) => runOperation(transport, "terrainGrid", documentFor("terrainGrid", "TerrainGridInput!", terrainGridFields, "query TerrainGrid($input: TerrainGridInput!) {\n terrainGrid(input: $input) {\n count\n coveredCount\n zoom\n resolutionMeters\n cols\n rows\n cells {\n point\n elevation\n slope\n aspect\n aspectOctant\n steepnessBand\n distanceMeters\n }\n }\n}\n", options?.select), input, options);
|
|
1747
|
+
const terrainProfile = (transport, input, options) => runOperation(transport, "terrainProfile", documentFor("terrainProfile", "TerrainProfileInput!", terrainProfileFields, "query TerrainProfile($input: TerrainProfileInput!) {\n terrainProfile(input: $input) {\n count\n coveredCount\n zoom\n resolutionMeters\n samples {\n point\n elevation\n slope\n aspect\n aspectOctant\n steepnessBand\n distanceMeters\n }\n }\n}\n", options?.select), input, options);
|
|
1748
|
+
const terrainSamples = (transport, input, options) => runOperation(transport, "terrainSamples", documentFor("terrainSamples", "TerrainSamplesInput!", terrainSamplesFields, "query TerrainSamples($input: TerrainSamplesInput!) {\n terrainSamples(input: $input) {\n count\n coveredCount\n zoom\n resolutionMeters\n samples {\n point\n elevation\n slope\n aspect\n aspectOctant\n steepnessBand\n distanceMeters\n }\n }\n}\n", options?.select), input, options);
|
|
1749
|
+
const bind$1 = (transport) => ({
|
|
1750
|
+
analyzeGeometry: (input, options) => analyzeGeometry(transport, input, options),
|
|
1751
|
+
directions: (input, options) => directions(transport, input, options),
|
|
1752
|
+
exportItinerary: (input, options) => exportItinerary(transport, input, options),
|
|
1753
|
+
geocode: (input, options) => geocode(transport, input, options),
|
|
1754
|
+
isochrones: (input, options) => isochrones(transport, input, options),
|
|
1755
|
+
itinerary: (input, options) => itinerary(transport, input, options),
|
|
1756
|
+
matrix: (input, options) => matrix(transport, input, options),
|
|
1757
|
+
pois: (input, options) => pois(transport, input, options),
|
|
1758
|
+
reverseGeocode: (input, options) => reverseGeocode(transport, input, options),
|
|
1759
|
+
search: (input, options) => search(transport, input, options),
|
|
1760
|
+
suggestions: (input, options) => suggestions(transport, input, options),
|
|
1761
|
+
terrainGrid: (input, options) => terrainGrid(transport, input, options),
|
|
1762
|
+
terrainProfile: (input, options) => terrainProfile(transport, input, options),
|
|
1763
|
+
terrainSamples: (input, options) => terrainSamples(transport, input, options)
|
|
1764
|
+
});
|
|
1765
|
+
var operations_gen_exports = /* @__PURE__ */ __exportAll({
|
|
1766
|
+
bind: () => bind,
|
|
1767
|
+
getCollectionSpecification: () => getCollectionSpecification,
|
|
1768
|
+
getItinerariesSpecification: () => getItinerariesSpecification,
|
|
1769
|
+
getItinerarySpecification: () => getItinerarySpecification,
|
|
1770
|
+
getOverlaySpecification: () => getOverlaySpecification,
|
|
1771
|
+
getTileLayers: () => getTileLayers,
|
|
1772
|
+
getZonesSpecification: () => getZonesSpecification
|
|
1773
|
+
});
|
|
1774
|
+
const getCollectionSpecification = (transport, args, options) => transport.request({
|
|
1775
|
+
acceptsShareToken: true,
|
|
1776
|
+
idempotent: true,
|
|
1777
|
+
method: "GET",
|
|
1778
|
+
operationId: "getCollectionSpecification",
|
|
1779
|
+
path: `/v1/collections/${encodeURIComponent(String(args.collection_id))}/specification`,
|
|
1780
|
+
query: args.query,
|
|
1781
|
+
retry: options?.retry,
|
|
1782
|
+
serverBudgetMs: 3e4,
|
|
1783
|
+
signal: options?.signal,
|
|
1784
|
+
surface: "tiles",
|
|
1785
|
+
timeoutMs: options?.timeoutMs
|
|
1786
|
+
});
|
|
1787
|
+
const getItinerariesSpecification = (transport, options) => transport.request({
|
|
1788
|
+
acceptsShareToken: true,
|
|
1789
|
+
idempotent: true,
|
|
1790
|
+
method: "GET",
|
|
1791
|
+
operationId: "getItinerariesSpecification",
|
|
1792
|
+
path: "/v1/itineraries/specification",
|
|
1793
|
+
retry: options?.retry,
|
|
1794
|
+
serverBudgetMs: 3e4,
|
|
1795
|
+
signal: options?.signal,
|
|
1796
|
+
surface: "tiles",
|
|
1797
|
+
timeoutMs: options?.timeoutMs
|
|
1798
|
+
});
|
|
1799
|
+
const getItinerarySpecification = (transport, args, options) => transport.request({
|
|
1800
|
+
acceptsShareToken: true,
|
|
1801
|
+
idempotent: true,
|
|
1802
|
+
method: "GET",
|
|
1803
|
+
operationId: "getItinerarySpecification",
|
|
1804
|
+
path: `/v1/itineraries/${encodeURIComponent(String(args.itinerary_id))}/specification`,
|
|
1805
|
+
retry: options?.retry,
|
|
1806
|
+
serverBudgetMs: 3e4,
|
|
1807
|
+
signal: options?.signal,
|
|
1808
|
+
surface: "tiles",
|
|
1809
|
+
timeoutMs: options?.timeoutMs
|
|
1810
|
+
});
|
|
1811
|
+
const getOverlaySpecification = (transport, args, options) => transport.request({
|
|
1812
|
+
acceptsShareToken: true,
|
|
1813
|
+
idempotent: true,
|
|
1814
|
+
method: "GET",
|
|
1815
|
+
operationId: "getOverlaySpecification",
|
|
1816
|
+
path: `/v1/overlays/${encodeURIComponent(String(args.overlay))}/specification`,
|
|
1817
|
+
query: args.query,
|
|
1818
|
+
retry: options?.retry,
|
|
1819
|
+
serverBudgetMs: 3e4,
|
|
1820
|
+
signal: options?.signal,
|
|
1821
|
+
surface: "tiles",
|
|
1822
|
+
timeoutMs: options?.timeoutMs
|
|
1823
|
+
});
|
|
1824
|
+
const getTileLayers = (transport, args = {}, options) => transport.request({
|
|
1825
|
+
acceptsShareToken: true,
|
|
1826
|
+
idempotent: true,
|
|
1827
|
+
method: "GET",
|
|
1828
|
+
operationId: "getTileLayers",
|
|
1829
|
+
path: "/v1/tile-layers",
|
|
1830
|
+
query: args.query,
|
|
1831
|
+
retry: options?.retry,
|
|
1832
|
+
serverBudgetMs: 3e4,
|
|
1833
|
+
signal: options?.signal,
|
|
1834
|
+
surface: "tiles",
|
|
1835
|
+
timeoutMs: options?.timeoutMs
|
|
1836
|
+
});
|
|
1837
|
+
const getZonesSpecification = (transport, options) => transport.request({
|
|
1838
|
+
acceptsShareToken: true,
|
|
1839
|
+
idempotent: true,
|
|
1840
|
+
method: "GET",
|
|
1841
|
+
operationId: "getZonesSpecification",
|
|
1842
|
+
path: "/v1/zones/specification",
|
|
1843
|
+
retry: options?.retry,
|
|
1844
|
+
serverBudgetMs: 3e4,
|
|
1845
|
+
signal: options?.signal,
|
|
1846
|
+
surface: "tiles",
|
|
1847
|
+
timeoutMs: options?.timeoutMs
|
|
1848
|
+
});
|
|
1849
|
+
const bind = (transport) => ({
|
|
1850
|
+
getCollectionSpecification: (args, options) => getCollectionSpecification(transport, args, options),
|
|
1851
|
+
getItinerariesSpecification: (options) => getItinerariesSpecification(transport, options),
|
|
1852
|
+
getItinerarySpecification: (args, options) => getItinerarySpecification(transport, args, options),
|
|
1853
|
+
getOverlaySpecification: (args, options) => getOverlaySpecification(transport, args, options),
|
|
1854
|
+
getTileLayers: (args, options) => getTileLayers(transport, args, options),
|
|
1855
|
+
getZonesSpecification: (options) => getZonesSpecification(transport, options)
|
|
1856
|
+
});
|
|
1857
|
+
const REMEDY = "Answer the { token, expires_at, user_id } that POST /v1/sessions returns, and reject where your endpoint fails, as a mint that checks the response's status does.";
|
|
1858
|
+
const isDate = (value) => Object.prototype.toString.call(value) === "[object Date]";
|
|
1859
|
+
const readSessionAnswer = (answer) => {
|
|
1860
|
+
if (typeof answer !== "object" || answer === null) throw new MountayaConnectionError(`mint: the answer is ${describeType(answer)}, so it is no session. ${REMEDY}`);
|
|
1861
|
+
const token = Reflect.get(answer, "token");
|
|
1862
|
+
if (typeof token !== "string" || token === "") throw new MountayaConnectionError(`mint: the answer holds no token (token is ${token === "" ? "an empty string" : describeType(token)}), so it is no session. ${REMEDY}`);
|
|
1863
|
+
const expiry = Reflect.get(answer, "expires_at");
|
|
1864
|
+
if (typeof expiry !== "string" && typeof expiry !== "number" && !isDate(expiry)) throw new MountayaConnectionError(`mint: the answer holds no expiry to read (expires_at is ${describeType(expiry)}), so it is no session. ${REMEDY}`);
|
|
1865
|
+
const parsed = new Date(expiry);
|
|
1866
|
+
const user = Reflect.get(answer, "user_id");
|
|
1867
|
+
return {
|
|
1868
|
+
expiresAt: Number.isNaN(parsed.getTime()) ? void 0 : parsed,
|
|
1869
|
+
token,
|
|
1870
|
+
userId: typeof user === "string" && user !== "" ? user : user === null ? null : void 0
|
|
1871
|
+
};
|
|
1872
|
+
};
|
|
1873
|
+
const REFRESH_MARGIN_MS = 6e4;
|
|
1874
|
+
const MAX_TIMER_MS = 6e5;
|
|
1875
|
+
const MIN_TIMER_MS = 5e3;
|
|
1876
|
+
const refreshSchedule = ({ consecutiveSpent, lifetimeMs }) => {
|
|
1877
|
+
if (consecutiveSpent !== void 0) return {
|
|
1878
|
+
armed: true,
|
|
1879
|
+
delayMs: Math.min(REFRESH_MARGIN_MS, MIN_TIMER_MS * 2 ** (consecutiveSpent - 1))
|
|
1880
|
+
};
|
|
1881
|
+
if (lifetimeMs === void 0) return {
|
|
1882
|
+
armed: true,
|
|
1883
|
+
delayMs: REFRESH_MARGIN_MS
|
|
1884
|
+
};
|
|
1885
|
+
const delayMs = lifetimeMs - Math.min(REFRESH_MARGIN_MS, lifetimeMs / 2);
|
|
1886
|
+
return {
|
|
1887
|
+
armed: delayMs >= MIN_TIMER_MS,
|
|
1888
|
+
delayMs
|
|
1889
|
+
};
|
|
1890
|
+
};
|
|
1891
|
+
const CONTEXT$1 = "SessionTokenEngine";
|
|
1892
|
+
const assertMint = (mint) => {
|
|
1893
|
+
if (typeof mint !== "function") throw refuseOption("mint", mint, "pass a function that calls your session endpoint and answers its { token, expires_at, user_id }.", CONTEXT$1);
|
|
1894
|
+
};
|
|
1895
|
+
const assertEnabled = (enabled) => {
|
|
1896
|
+
if (enabled !== void 0 && typeof enabled !== "boolean") throw refuseOption("enabled", enabled, "pass true to mint, false to stop, or leave it out to mint.", CONTEXT$1);
|
|
1897
|
+
};
|
|
1898
|
+
const snapshotOf = (fields) => printsAs({ ...fields }, (snapshot) => ({
|
|
1899
|
+
...snapshot,
|
|
1900
|
+
token: snapshot.token === void 0 ? void 0 : redactedSessionToken(snapshot.token)
|
|
1901
|
+
}));
|
|
1902
|
+
const emptySnapshot = snapshotOf({
|
|
1903
|
+
error: void 0,
|
|
1904
|
+
expiresAt: void 0,
|
|
1905
|
+
isLoading: false,
|
|
1906
|
+
token: void 0,
|
|
1907
|
+
userId: void 0
|
|
1908
|
+
});
|
|
1909
|
+
const isCancellation = (failure) => typeof failure === "object" && failure !== null && "name" in failure && failure.name === "AbortError";
|
|
1910
|
+
const abortedByApplication = ({ controller: { signal } }) => signal.aborted && !(typeof signal.reason === "object" && signal.reason !== null && "name" in signal.reason && signal.reason.name === "TimeoutError");
|
|
1911
|
+
const surfaceFault = (fault) => {
|
|
1912
|
+
queueMicrotask(() => {
|
|
1913
|
+
throw fault;
|
|
1914
|
+
});
|
|
1915
|
+
};
|
|
1916
|
+
var SessionTokenEngine = class {
|
|
1917
|
+
mintFn;
|
|
1918
|
+
enabled;
|
|
1919
|
+
snapshot;
|
|
1920
|
+
listeners = /* @__PURE__ */ new Set();
|
|
1921
|
+
parked = true;
|
|
1922
|
+
disposed = false;
|
|
1923
|
+
cancelled = false;
|
|
1924
|
+
timer = null;
|
|
1925
|
+
deadline = void 0;
|
|
1926
|
+
minting = false;
|
|
1927
|
+
call = void 0;
|
|
1928
|
+
generation = 0;
|
|
1929
|
+
backoff = 0;
|
|
1930
|
+
constructor(options) {
|
|
1931
|
+
const given = options;
|
|
1932
|
+
if (typeof given !== "object" || given === null) throw new MountayaConfigurationError(`${CONTEXT$1}: options is ${describeType(given)}; pass { mint }, a function that calls your session endpoint.`);
|
|
1933
|
+
assertMint(options.mint);
|
|
1934
|
+
assertEnabled(options.enabled);
|
|
1935
|
+
this.mintFn = options.mint;
|
|
1936
|
+
this.enabled = options.enabled ?? true;
|
|
1937
|
+
this.snapshot = this.enabled ? snapshotOf({
|
|
1938
|
+
...emptySnapshot,
|
|
1939
|
+
isLoading: true
|
|
1940
|
+
}) : emptySnapshot;
|
|
1941
|
+
}
|
|
1942
|
+
getSnapshot() {
|
|
1943
|
+
return this.snapshot;
|
|
1944
|
+
}
|
|
1945
|
+
subscribe(listener) {
|
|
1946
|
+
this.listeners.add(listener);
|
|
1947
|
+
if ((this.parked || this.cancelled) && !this.disposed) {
|
|
1948
|
+
this.parked = false;
|
|
1949
|
+
this.run();
|
|
1950
|
+
}
|
|
1951
|
+
return () => {
|
|
1952
|
+
this.listeners.delete(listener);
|
|
1953
|
+
if (this.listeners.size > 0 || this.parked) return;
|
|
1954
|
+
this.parked = true;
|
|
1955
|
+
this.park();
|
|
1956
|
+
};
|
|
1957
|
+
}
|
|
1958
|
+
refresh() {
|
|
1959
|
+
if (this.minting) return;
|
|
1960
|
+
this.run();
|
|
1961
|
+
}
|
|
1962
|
+
checkNow() {
|
|
1963
|
+
const deadline = this.deadline;
|
|
1964
|
+
if (!this.enabled || this.parked || this.disposed || deadline === void 0) return;
|
|
1965
|
+
if (Date.now() < deadline.at && !deadline.retriesFailure) {
|
|
1966
|
+
this.armAt(deadline);
|
|
1967
|
+
return;
|
|
1968
|
+
}
|
|
1969
|
+
this.disarm();
|
|
1970
|
+
deadline.fire();
|
|
1971
|
+
}
|
|
1972
|
+
setMint(mint) {
|
|
1973
|
+
assertMint(mint);
|
|
1974
|
+
this.mintFn = mint;
|
|
1975
|
+
}
|
|
1976
|
+
setEnabled(enabled) {
|
|
1977
|
+
const given = enabled;
|
|
1978
|
+
assertEnabled(given);
|
|
1979
|
+
const next = given !== false;
|
|
1980
|
+
if (this.enabled === next) return;
|
|
1981
|
+
this.enabled = next;
|
|
1982
|
+
if (!next) {
|
|
1983
|
+
this.retire();
|
|
1984
|
+
this.call = void 0;
|
|
1985
|
+
this.backoff = 0;
|
|
1986
|
+
this.commit(emptySnapshot);
|
|
1987
|
+
return;
|
|
1988
|
+
}
|
|
1989
|
+
if (this.disposed) return;
|
|
1990
|
+
if (!this.parked) {
|
|
1991
|
+
this.run();
|
|
1992
|
+
return;
|
|
1993
|
+
}
|
|
1994
|
+
this.reportResting();
|
|
1995
|
+
}
|
|
1996
|
+
dispose() {
|
|
1997
|
+
if (this.disposed) return;
|
|
1998
|
+
this.disposed = true;
|
|
1999
|
+
this.parked = true;
|
|
2000
|
+
this.retire();
|
|
2001
|
+
this.call = void 0;
|
|
2002
|
+
this.backoff = 0;
|
|
2003
|
+
this.commit(emptySnapshot);
|
|
2004
|
+
this.listeners.clear();
|
|
2005
|
+
}
|
|
2006
|
+
commit(next) {
|
|
2007
|
+
if (next === this.snapshot) return;
|
|
2008
|
+
this.snapshot = next;
|
|
2009
|
+
let fault;
|
|
2010
|
+
for (const listener of this.listeners) try {
|
|
2011
|
+
listener();
|
|
2012
|
+
} catch (thrown) {
|
|
2013
|
+
fault ??= { thrown };
|
|
2014
|
+
}
|
|
2015
|
+
if (fault !== void 0) surfaceFault(fault.thrown);
|
|
2016
|
+
}
|
|
2017
|
+
disarm() {
|
|
2018
|
+
if (this.timer !== null) {
|
|
2019
|
+
clearTimeout(this.timer);
|
|
2020
|
+
this.timer = null;
|
|
2021
|
+
}
|
|
2022
|
+
this.deadline = void 0;
|
|
2023
|
+
}
|
|
2024
|
+
retire() {
|
|
2025
|
+
this.generation += 1;
|
|
2026
|
+
this.minting = false;
|
|
2027
|
+
this.disarm();
|
|
2028
|
+
}
|
|
2029
|
+
park() {
|
|
2030
|
+
this.retire();
|
|
2031
|
+
this.reportResting();
|
|
2032
|
+
}
|
|
2033
|
+
reportResting() {
|
|
2034
|
+
const onItsWay = this.enabled && !this.disposed && this.snapshot.token === void 0;
|
|
2035
|
+
if (this.snapshot.isLoading !== onItsWay) this.commit(snapshotOf({
|
|
2036
|
+
...this.snapshot,
|
|
2037
|
+
isLoading: onItsWay
|
|
2038
|
+
}));
|
|
2039
|
+
}
|
|
2040
|
+
armAt(deadline) {
|
|
2041
|
+
this.disarm();
|
|
2042
|
+
this.deadline = deadline;
|
|
2043
|
+
const hop = () => {
|
|
2044
|
+
const remaining = deadline.at - Date.now();
|
|
2045
|
+
if (remaining <= 0) {
|
|
2046
|
+
this.timer = null;
|
|
2047
|
+
this.deadline = void 0;
|
|
2048
|
+
deadline.fire();
|
|
2049
|
+
return;
|
|
2050
|
+
}
|
|
2051
|
+
this.timer = setTimeout(hop, Math.min(MAX_TIMER_MS, remaining));
|
|
2052
|
+
};
|
|
2053
|
+
this.timer = setTimeout(hop, Math.min(MAX_TIMER_MS, Math.max(0, deadline.at - Date.now())));
|
|
2054
|
+
}
|
|
2055
|
+
armRefresh(delay, retriesFailure = false) {
|
|
2056
|
+
this.armAt({
|
|
2057
|
+
at: Date.now() + delay,
|
|
2058
|
+
fire: () => {
|
|
2059
|
+
this.run();
|
|
2060
|
+
},
|
|
2061
|
+
retriesFailure
|
|
2062
|
+
});
|
|
2063
|
+
}
|
|
2064
|
+
callOut() {
|
|
2065
|
+
const out = this.call;
|
|
2066
|
+
return out !== void 0 && Date.now() - out.startedAt < 6e4 ? out : void 0;
|
|
2067
|
+
}
|
|
2068
|
+
startCall() {
|
|
2069
|
+
const controller = new AbortController();
|
|
2070
|
+
let answer;
|
|
2071
|
+
try {
|
|
2072
|
+
answer = Promise.resolve(this.mintFn(controller));
|
|
2073
|
+
} catch (cause) {
|
|
2074
|
+
answer = Promise.reject(cause);
|
|
2075
|
+
}
|
|
2076
|
+
const call = {
|
|
2077
|
+
answer,
|
|
2078
|
+
controller,
|
|
2079
|
+
startedAt: Date.now()
|
|
2080
|
+
};
|
|
2081
|
+
this.call = call;
|
|
2082
|
+
const settle = () => {
|
|
2083
|
+
if (this.call === call) this.call = void 0;
|
|
2084
|
+
};
|
|
2085
|
+
answer.then(settle, settle);
|
|
2086
|
+
return call;
|
|
2087
|
+
}
|
|
2088
|
+
abandon(generation) {
|
|
2089
|
+
if (generation !== this.generation) return;
|
|
2090
|
+
this.retire();
|
|
2091
|
+
this.call = void 0;
|
|
2092
|
+
this.backoff += 1;
|
|
2093
|
+
const delayMs = refreshSchedule({ consecutiveSpent: this.backoff }).delayMs;
|
|
2094
|
+
this.armRefresh(delayMs, true);
|
|
2095
|
+
this.commit(snapshotOf({
|
|
2096
|
+
...this.snapshot,
|
|
2097
|
+
error: new MountayaConnectionError(`mint: no answer within ${REFRESH_MARGIN_MS} ms, so the mint is abandoned and tried again in ${delayMs} ms. Check that the endpoint it calls answers.`),
|
|
2098
|
+
isLoading: false
|
|
2099
|
+
}));
|
|
2100
|
+
}
|
|
2101
|
+
async run() {
|
|
2102
|
+
if (!this.enabled || this.parked || this.disposed) return;
|
|
2103
|
+
this.cancelled = false;
|
|
2104
|
+
this.generation += 1;
|
|
2105
|
+
const generation = this.generation;
|
|
2106
|
+
const isCurrent = () => this.generation === generation;
|
|
2107
|
+
this.minting = true;
|
|
2108
|
+
const joined = this.callOut();
|
|
2109
|
+
this.armAt({
|
|
2110
|
+
at: (joined?.startedAt ?? Date.now()) + REFRESH_MARGIN_MS,
|
|
2111
|
+
fire: () => {
|
|
2112
|
+
this.abandon(generation);
|
|
2113
|
+
},
|
|
2114
|
+
retriesFailure: false
|
|
2115
|
+
});
|
|
2116
|
+
this.commit(snapshotOf({
|
|
2117
|
+
...this.snapshot,
|
|
2118
|
+
isLoading: true
|
|
2119
|
+
}));
|
|
2120
|
+
if (!isCurrent()) return;
|
|
2121
|
+
const call = joined ?? this.startCall();
|
|
2122
|
+
let session;
|
|
2123
|
+
try {
|
|
2124
|
+
session = readSessionAnswer(await call.answer);
|
|
2125
|
+
} catch (cause) {
|
|
2126
|
+
if (!isCurrent()) return;
|
|
2127
|
+
this.minting = false;
|
|
2128
|
+
if (isCancellation(cause) || abortedByApplication(call)) {
|
|
2129
|
+
this.disarm();
|
|
2130
|
+
this.cancelled = true;
|
|
2131
|
+
this.commit(snapshotOf({
|
|
2132
|
+
...this.snapshot,
|
|
2133
|
+
error: cause,
|
|
2134
|
+
isLoading: false
|
|
2135
|
+
}));
|
|
2136
|
+
return;
|
|
2137
|
+
}
|
|
2138
|
+
this.backoff += 1;
|
|
2139
|
+
this.armRefresh(refreshSchedule({ consecutiveSpent: this.backoff }).delayMs, true);
|
|
2140
|
+
this.commit(snapshotOf({
|
|
2141
|
+
...this.snapshot,
|
|
2142
|
+
error: cause,
|
|
2143
|
+
isLoading: false
|
|
2144
|
+
}));
|
|
2145
|
+
return;
|
|
2146
|
+
}
|
|
2147
|
+
if (!isCurrent()) return;
|
|
2148
|
+
this.minting = false;
|
|
2149
|
+
const expiry = session.expiresAt;
|
|
2150
|
+
this.commit(snapshotOf({
|
|
2151
|
+
error: void 0,
|
|
2152
|
+
expiresAt: expiry,
|
|
2153
|
+
isLoading: false,
|
|
2154
|
+
token: session.token,
|
|
2155
|
+
userId: session.userId
|
|
2156
|
+
}));
|
|
2157
|
+
if (!isCurrent()) return;
|
|
2158
|
+
const lifetime = expiry === void 0 ? void 0 : expiry.getTime() - Date.now();
|
|
2159
|
+
const schedule = refreshSchedule({ lifetimeMs: lifetime });
|
|
2160
|
+
if (schedule.armed) {
|
|
2161
|
+
this.backoff = 0;
|
|
2162
|
+
this.armRefresh(schedule.delayMs);
|
|
2163
|
+
return;
|
|
2164
|
+
}
|
|
2165
|
+
this.backoff += 1;
|
|
2166
|
+
this.armRefresh(refreshSchedule({ consecutiveSpent: this.backoff }).delayMs);
|
|
2167
|
+
}
|
|
2168
|
+
};
|
|
2169
|
+
const MAX_PAGE_SIZE = 100;
|
|
2170
|
+
const DEFAULT_PAGE_SIZE = 50;
|
|
2171
|
+
const CONTEXT = "paginate";
|
|
2172
|
+
const wholeNumberOption = (name, value, max, fallback) => {
|
|
2173
|
+
if (value === void 0) return fallback;
|
|
2174
|
+
if (typeof value === "number" && Number.isInteger(value) && value >= 1 && value <= max) return value;
|
|
2175
|
+
const range = Number.isFinite(max) ? `from 1 to ${max}` : "of 1 or more";
|
|
2176
|
+
const omitted = Number.isFinite(fallback) ? `for the default of ${fallback}` : "to walk to the listing's last page";
|
|
2177
|
+
throw refuseOption(name, value, `pass a whole number ${range}, or leave it out ${omitted}.`, CONTEXT);
|
|
2178
|
+
};
|
|
2179
|
+
const pageOf = (answer) => {
|
|
2180
|
+
const rows = answer?.data;
|
|
2181
|
+
const next = answer?.extensions?.metadata?.pagination?.next_cursor;
|
|
2182
|
+
if (!Array.isArray(rows) || typeof next !== "string" && next !== null) throw new MountayaConfigurationError(`${CONTEXT}: the operation answered no page: a paged listing answers a list at data and a cursor or null at extensions.metadata.pagination.next_cursor. Pass an operation that takes cursor and limit under query.`);
|
|
2183
|
+
return {
|
|
2184
|
+
next,
|
|
2185
|
+
rows
|
|
2186
|
+
};
|
|
2187
|
+
};
|
|
2188
|
+
const paginate = (operation, args, options = {}) => {
|
|
2189
|
+
if (typeof operation !== "function") throw refuseOption("operation", operation, "pass a method of the client that takes cursor and limit under query, such as mountaya.studio.itineraries.getItineraries.", CONTEXT);
|
|
2190
|
+
if (typeof args !== "object" || args === null) throw refuseOption("args", args, "pass the operation's own arguments as an object, {} where it takes none.", CONTEXT);
|
|
2191
|
+
if (typeof options !== "object" || options === null) throw refuseOption("options", options, "pass an object such as { pageSize: 25 }, or leave it out for the defaults.", CONTEXT);
|
|
2192
|
+
const pageSize = wholeNumberOption("pageSize", options.pageSize, MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE);
|
|
2193
|
+
const maxPages = wholeNumberOption("maxPages", options.maxPages, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY);
|
|
2194
|
+
const { retry, signal, timeoutMs } = options;
|
|
2195
|
+
const { cursor: start, limit: _replaced, ...query } = ("query" in args && typeof args.query === "object" && args.query !== null ? { ...args.query } : void 0) ?? {};
|
|
2196
|
+
return { async *[Symbol.asyncIterator]() {
|
|
2197
|
+
let cursor = typeof start === "string" ? start : void 0;
|
|
2198
|
+
const sent = /* @__PURE__ */ new Set();
|
|
2199
|
+
for (let requested = 0; requested < maxPages; requested += 1) {
|
|
2200
|
+
if (signal?.aborted === true) throw abortReasonOf(signal);
|
|
2201
|
+
sent.add(cursor);
|
|
2202
|
+
const { next, rows } = pageOf(await operation({
|
|
2203
|
+
...args,
|
|
2204
|
+
query: {
|
|
2205
|
+
...query,
|
|
2206
|
+
...cursor === void 0 ? {} : { cursor },
|
|
2207
|
+
limit: pageSize
|
|
2208
|
+
}
|
|
2209
|
+
}, {
|
|
2210
|
+
retry,
|
|
2211
|
+
signal,
|
|
2212
|
+
timeoutMs
|
|
2213
|
+
}));
|
|
2214
|
+
for (const row of rows) yield row;
|
|
2215
|
+
if (next === null) return;
|
|
2216
|
+
if (sent.has(next)) throw new MountayaApiError(`${CONTEXT}: the listing named the cursor ${JSON.stringify(next)} again, which this walk already followed, so following it would read the listing again without end. Read the listing again from its start.`, 200, []);
|
|
2217
|
+
cursor = next;
|
|
2218
|
+
}
|
|
2219
|
+
} };
|
|
2220
|
+
};
|
|
2221
|
+
const SCHEMA_VERSION = "v0.10.0";
|
|
2222
|
+
var coreOperations_gen_exports = /* @__PURE__ */ __exportAll({
|
|
2223
|
+
deleteCollection: () => deleteCollection,
|
|
2224
|
+
deleteCollectionItinerary: () => deleteCollectionItinerary,
|
|
2225
|
+
deleteCollectionShareLink: () => deleteCollectionShareLink,
|
|
2226
|
+
deleteCollectionZone: () => deleteCollectionZone,
|
|
2227
|
+
deleteItinerary: () => deleteItinerary,
|
|
2228
|
+
deleteItineraryPublication: () => deleteItineraryPublication,
|
|
2229
|
+
deleteItinerarySegment: () => deleteItinerarySegment,
|
|
2230
|
+
deleteItinerarySegmentGroup: () => deleteItinerarySegmentGroup,
|
|
2231
|
+
deleteItineraryShareLink: () => deleteItineraryShareLink,
|
|
2232
|
+
deleteItineraryWaypoint: () => deleteItineraryWaypoint,
|
|
2233
|
+
deleteZone: () => deleteZone,
|
|
2234
|
+
deleteZonePublication: () => deleteZonePublication,
|
|
2235
|
+
getActivities: () => getActivities,
|
|
2236
|
+
getAgentRunEvents: () => getAgentRunEvents,
|
|
2237
|
+
getCollection: () => getCollection,
|
|
2238
|
+
getCollectionItineraries: () => getCollectionItineraries,
|
|
2239
|
+
getCollectionShareLink: () => getCollectionShareLink,
|
|
2240
|
+
getCollectionZones: () => getCollectionZones,
|
|
2241
|
+
getCollections: () => getCollections,
|
|
2242
|
+
getItineraries: () => getItineraries,
|
|
2243
|
+
getItinerary: () => getItinerary,
|
|
2244
|
+
getItineraryEvents: () => getItineraryEvents,
|
|
2245
|
+
getItineraryExport: () => getItineraryExport,
|
|
2246
|
+
getItineraryPace: () => getItineraryPace,
|
|
2247
|
+
getItineraryShareLink: () => getItineraryShareLink,
|
|
2248
|
+
getLayers: () => getLayers,
|
|
2249
|
+
getOrganizationEvents: () => getOrganizationEvents,
|
|
2250
|
+
getZone: () => getZone,
|
|
2251
|
+
getZoneEvents: () => getZoneEvents,
|
|
2252
|
+
getZones: () => getZones,
|
|
2253
|
+
patchCollection: () => patchCollection,
|
|
2254
|
+
patchCollectionItinerary: () => patchCollectionItinerary,
|
|
2255
|
+
patchItinerary: () => patchItinerary,
|
|
2256
|
+
patchItinerarySegment: () => patchItinerarySegment,
|
|
2257
|
+
patchItinerarySegmentGroup: () => patchItinerarySegmentGroup,
|
|
2258
|
+
patchItineraryWaypoint: () => patchItineraryWaypoint,
|
|
2259
|
+
patchZone: () => patchZone,
|
|
2260
|
+
postAgentRun: () => postAgentRun,
|
|
2261
|
+
postAgentRunFeedback: () => postAgentRunFeedback,
|
|
2262
|
+
postAgentRunInput: () => postAgentRunInput,
|
|
2263
|
+
postCollection: () => postCollection,
|
|
2264
|
+
postCollectionItineraries: () => postCollectionItineraries,
|
|
2265
|
+
postCollectionShareLink: () => postCollectionShareLink,
|
|
2266
|
+
postCollectionShareLinkRotate: () => postCollectionShareLinkRotate,
|
|
2267
|
+
postCollectionZones: () => postCollectionZones,
|
|
2268
|
+
postItinerary: () => postItinerary,
|
|
2269
|
+
postItineraryCollab: () => postItineraryCollab,
|
|
2270
|
+
postItineraryDuplicate: () => postItineraryDuplicate,
|
|
2271
|
+
postItineraryImport: () => postItineraryImport,
|
|
2272
|
+
postItineraryPreview: () => postItineraryPreview,
|
|
2273
|
+
postItineraryPublication: () => postItineraryPublication,
|
|
2274
|
+
postItinerarySegment: () => postItinerarySegment,
|
|
2275
|
+
postItinerarySegmentConvert: () => postItinerarySegmentConvert,
|
|
2276
|
+
postItinerarySegmentGroup: () => postItinerarySegmentGroup,
|
|
2277
|
+
postItinerarySegmentMerge: () => postItinerarySegmentMerge,
|
|
2278
|
+
postItinerarySegmentSplit: () => postItinerarySegmentSplit,
|
|
2279
|
+
postItineraryShareLink: () => postItineraryShareLink,
|
|
2280
|
+
postItineraryShareLinkRotate: () => postItineraryShareLinkRotate,
|
|
2281
|
+
postItineraryWaypoint: () => postItineraryWaypoint,
|
|
2282
|
+
postOrganizationLookup: () => postOrganizationLookup,
|
|
2283
|
+
postZone: () => postZone,
|
|
2284
|
+
postZoneCollab: () => postZoneCollab,
|
|
2285
|
+
postZonePublication: () => postZonePublication
|
|
2286
|
+
});
|
|
2287
|
+
export { bind as a, operations_gen_exports$1 as c, MountayaTransport as d, boundFetch as f, SessionTokenEngine as i, selection_gen_exports as l, SCHEMA_VERSION as n, operations_gen_exports as o, defaultBaseUrls as p, paginate as r, bind$1 as s, coreOperations_gen_exports as t, MountayaSelectionError as u };
|
|
2288
|
+
|
|
2289
|
+
//# sourceMappingURL=chunk-DmxQID5X.js.map
|