@mountaya/client 0.0.0-stage → 0.1.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 +104 -0
- package/LICENCE.fr.txt +280 -0
- package/LICENSE.txt +262 -0
- package/README.md +1260 -2
- package/dist/admin/index.cjs +3521 -0
- package/dist/admin/index.cjs.map +1 -0
- package/dist/admin/index.d.cts +1070 -0
- package/dist/admin/index.d.ts +1070 -0
- package/dist/admin/index.js +301 -0
- package/dist/admin/index.js.map +1 -0
- package/dist/browser.cjs +8073 -0
- package/dist/browser.cjs.map +1 -0
- package/dist/browser.d.cts +106 -0
- package/dist/browser.d.ts +106 -0
- package/dist/browser.js +53 -0
- package/dist/browser.js.map +1 -0
- package/dist/chunk-BM526BHG.js +342 -0
- package/dist/chunk-BM526BHG.js.map +1 -0
- package/dist/chunk-D2YEVTG7.js +327 -0
- package/dist/chunk-D2YEVTG7.js.map +1 -0
- package/dist/chunk-OHKVUREN.js +3500 -0
- package/dist/chunk-OHKVUREN.js.map +1 -0
- package/dist/chunk-TDTK2L5H.js +3842 -0
- package/dist/chunk-TDTK2L5H.js.map +1 -0
- package/dist/coreOperations.gen-BMYPoBbz.d.ts +1760 -0
- package/dist/coreOperations.gen-BxX5xRxw.d.cts +1760 -0
- package/dist/errors-B-GqAtQv.d.cts +75960 -0
- package/dist/errors-B-GqAtQv.d.ts +75960 -0
- package/dist/events/index.cjs +1972 -0
- package/dist/events/index.cjs.map +1 -0
- package/dist/events/index.d.cts +781 -0
- package/dist/events/index.d.ts +781 -0
- package/dist/events/index.js +826 -0
- package/dist/events/index.js.map +1 -0
- package/dist/index.cjs +8072 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +76 -0
- package/dist/index.d.ts +76 -0
- package/dist/index.js +52 -0
- package/dist/index.js.map +1 -0
- package/dist/operations.gen-CvTyzKNF.d.cts +3993 -0
- package/dist/operations.gen-DUD406TV.d.ts +3993 -0
- package/package.json +127 -4
- package/src/admin/index.ts +47 -0
- package/src/admin/rules/mountayaAdmin.ts +102 -0
- package/src/browser.ts +232 -0
- package/src/core/engines/sessionToken.ts +870 -0
- package/src/core/rules/auth.ts +1017 -0
- package/src/core/rules/clientHeader.ts +28 -0
- package/src/core/rules/dates.ts +200 -0
- package/src/core/rules/decode.ts +154 -0
- package/src/core/rules/envelope.ts +41 -0
- package/src/core/rules/errors.ts +1486 -0
- package/src/core/rules/graphql.ts +576 -0
- package/src/core/rules/headerValue.ts +42 -0
- package/src/core/rules/idempotencyKey.ts +64 -0
- package/src/core/rules/nullMask.ts +127 -0
- package/src/core/rules/nullMasks.gen.ts +416 -0
- package/src/core/rules/paginate.ts +316 -0
- package/src/core/rules/rateLimit.ts +507 -0
- package/src/core/rules/redaction.ts +219 -0
- package/src/core/rules/resourceRef.ts +110 -0
- package/src/core/rules/responseBody.ts +492 -0
- package/src/core/rules/retry.ts +386 -0
- package/src/core/rules/selection.ts +416 -0
- package/src/core/rules/sessionAnswer.ts +90 -0
- package/src/core/rules/sessionSchedule.ts +131 -0
- package/src/core/rules/sessionWait.ts +112 -0
- package/src/core/rules/transport.ts +2386 -0
- package/src/core/rules/version.gen.ts +16 -0
- package/src/core/rules/webAddress.ts +165 -0
- package/src/core/rules/webAddresses.gen.ts +30 -0
- package/src/data/operations.gen.ts +603 -0
- package/src/data/schema.gen.ts +8078 -0
- package/src/data/selection.gen.ts +472 -0
- package/src/events/index.ts +67 -0
- package/src/events/rules/agent.ts +439 -0
- package/src/events/rules/collab.ts +554 -0
- package/src/events/rules/collabNulls.gen.ts +17 -0
- package/src/events/rules/eventStream.ts +94 -0
- package/src/events/rules/openSseStream.ts +594 -0
- package/src/events/rules/sse.ts +349 -0
- package/src/index.ts +231 -0
- package/src/rest/adminOperations.gen.ts +70 -0
- package/src/rest/adminResources.gen.ts +136 -0
- package/src/rest/coreOperations.gen.ts +74 -0
- package/src/rest/coreResources.gen.ts +244 -0
- package/src/rest/dates.gen.ts +217 -0
- package/src/rest/operations.gen.ts +4341 -0
- package/src/rest/resources.gen.ts +369 -0
- package/src/rest/schema.gen.ts +56840 -0
- package/src/tiles/operations.gen.ts +206 -0
- package/src/tiles/schema.gen.ts +8408 -0
- package/src/webhooks/rules/constructWebhookEvent.ts +482 -0
- package/src/webhooks/rules/webhookEvent.ts +38 -0
- package/src/webhooks/rules/webhookEvents.gen.ts +732 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// GENERATED FILE. DO NOT EDIT.
|
|
2
|
+
//
|
|
3
|
+
// The mountaya/schemas tag this client was generated from, read from that
|
|
4
|
+
// repository's VERSION at generation time.
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* SCHEMA_VERSION is the `mountaya/schemas` tag this client was generated from.
|
|
8
|
+
*
|
|
9
|
+
* It answers "which contract is this client speaking" without inspecting the package
|
|
10
|
+
* version, which moves for reasons of its own.
|
|
11
|
+
*
|
|
12
|
+
* It lives here rather than beside the client so that `browser.ts` can re-export it
|
|
13
|
+
* without importing the package root: the root reaches the secret-key credential, and
|
|
14
|
+
* the browser entry's guarantee is that nothing in its module graph does.
|
|
15
|
+
*/
|
|
16
|
+
export const SCHEMA_VERSION = "v0.9.0";
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The web addresses a caller builds into a request's body.
|
|
3
|
+
*
|
|
4
|
+
* A value the contract types `format: uri` is an absolute address, as JSON Schema's `uri` is: a
|
|
5
|
+
* scheme, a colon and at least one more character, none of them a line break. One a caller builds
|
|
6
|
+
* with no scheme, `gateway.example.com/v1` for one, is refused before any request leaves, with a
|
|
7
|
+
* configuration error naming the call, the member and the address, rather than sent to be
|
|
8
|
+
* answered with a 400. Anything else about an address is the API's to judge: a scheme it does not
|
|
9
|
+
* take, a host it refuses, its length.
|
|
10
|
+
*
|
|
11
|
+
* An answer's web address is never held to it: an answer is the API's account of what it holds,
|
|
12
|
+
* and a value with no scheme there is kept as the text the wire sent, as every string is.
|
|
13
|
+
*
|
|
14
|
+
* Which members of which body are web addresses is the contract's, printed per operation from its
|
|
15
|
+
* model into `webAddresses.gen.ts` by `scripts/generate-web-addresses.mjs`, so the refusal reaches
|
|
16
|
+
* the members the contract types `format: uri` and no other string.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { MountayaConfigurationError, refuseOption } from "./errors.js";
|
|
20
|
+
import { requestWebAddresses } from "./webAddresses.gen.js";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* WebAddressMask names the web addresses in a JSON value: the strings of a body the contract types
|
|
24
|
+
* `format: uri`.
|
|
25
|
+
*
|
|
26
|
+
* `true` marks the value itself. An object marks each field it names by that field's own mask, and
|
|
27
|
+
* leaves every field it does not name alone. A one-element array marks every element of a list by
|
|
28
|
+
* that element's mask, as a `DateMask` does.
|
|
29
|
+
*/
|
|
30
|
+
export type WebAddressMask =
|
|
31
|
+
| true
|
|
32
|
+
| { readonly [field: string]: WebAddressMask }
|
|
33
|
+
| readonly [WebAddressMask];
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Matches the least RFC 3986 calls a URI: a scheme, an ASCII letter followed by letters, digits,
|
|
37
|
+
* `+`, `-` or `.`, then a colon, then at least one more character, none of them a line feed, a
|
|
38
|
+
* carriage return, a next line, a line separator or a paragraph separator.
|
|
39
|
+
*/
|
|
40
|
+
const absoluteAddressPattern = /^[A-Za-z][A-Za-z0-9+.-]*:[^\n\r\u0085\u2028\u2029]+$/;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Matches a string that reads as a host name, with a port or a path perhaps, and no scheme: the
|
|
44
|
+
* likeliest slip where an address is wanted, and the one whose fix a refusal can spell exactly.
|
|
45
|
+
*/
|
|
46
|
+
export const bareHostPattern = /^(localhost|[a-z0-9-]+(\.[a-z0-9-]+)+)(:\d+)?(\/\S*)?$/i;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* hasUrlScheme reports whether `text` is an absolute address: a scheme, a colon and at least one
|
|
50
|
+
* more character, none of them a line break. A host such as `www.example.com` and a path such as
|
|
51
|
+
* `/v1/x` have no scheme, so neither is one.
|
|
52
|
+
*/
|
|
53
|
+
export const hasUrlScheme = (text: string): boolean => absoluteAddressPattern.test(text);
|
|
54
|
+
|
|
55
|
+
/** isListMask reports whether a mask marks every element of a list. */
|
|
56
|
+
const isListMask = (mask: WebAddressMask): mask is readonly [WebAddressMask] => Array.isArray(mask);
|
|
57
|
+
|
|
58
|
+
/** isList reports whether a value is a list, as one of unknown elements. */
|
|
59
|
+
const isList = (value: unknown): value is unknown[] => Array.isArray(value);
|
|
60
|
+
|
|
61
|
+
/** A web address a body holds with no scheme, and the path a caller writes its member at. */
|
|
62
|
+
interface Schemeless {
|
|
63
|
+
/** The member, from the body down: `body.contact.website`, `body.media.links[0].url`. */
|
|
64
|
+
readonly path: string;
|
|
65
|
+
/** The address as the body holds it. */
|
|
66
|
+
readonly value: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* schemelessIn finds the first web address `mask` names in `value` that has no scheme, in the order
|
|
71
|
+
* the mask names them, or answers undefined where each has one.
|
|
72
|
+
*
|
|
73
|
+
* Only a string is judged. A value of another shape than its mask, `null` where the contract lets
|
|
74
|
+
* a caller clear an address among them, is the API's to answer for, and a field the value does not
|
|
75
|
+
* own is never read.
|
|
76
|
+
*/
|
|
77
|
+
const schemelessIn = (
|
|
78
|
+
value: unknown,
|
|
79
|
+
mask: WebAddressMask,
|
|
80
|
+
path: string,
|
|
81
|
+
): Schemeless | undefined => {
|
|
82
|
+
if (mask === true) {
|
|
83
|
+
return typeof value === "string" && !hasUrlScheme(value) ? { path, value } : undefined;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (isListMask(mask)) {
|
|
87
|
+
if (!isList(value)) {
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const [element] = mask;
|
|
92
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
93
|
+
const found = schemelessIn(value[index], element, `${path}[${index}]`);
|
|
94
|
+
if (found !== undefined) {
|
|
95
|
+
return found;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (typeof value !== "object" || value === null || isList(value)) {
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
for (const [field, fieldMask] of Object.entries(mask)) {
|
|
107
|
+
if (Object.hasOwn(value, field)) {
|
|
108
|
+
const held: unknown = Reflect.get(value, field);
|
|
109
|
+
const found = schemelessIn(held, fieldMask, `${path}.${field}`);
|
|
110
|
+
if (found !== undefined) {
|
|
111
|
+
return found;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return undefined;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* assertWebAddresses refuses a call whose JSON body holds a web address with no scheme, where the
|
|
121
|
+
* contract types the member `format: uri` for the call's operation, before any request leaves.
|
|
122
|
+
*
|
|
123
|
+
* `text` is the body as the request sends it, so a value is judged as the wire carries it, after
|
|
124
|
+
* any `toJSON`. An operation whose body holds no web address costs a lookup and no parse.
|
|
125
|
+
*
|
|
126
|
+
* @param operationId - The operation the call is made to, which names its body's web addresses.
|
|
127
|
+
* @param text - The body, as the JSON the request sends.
|
|
128
|
+
* @throws `MountayaConfigurationError` naming the call, the member by the path a caller writes it
|
|
129
|
+
* at (`body.contact.website`), the address unless it holds an `@`, and the address with its
|
|
130
|
+
* scheme to pass where it reads as a host.
|
|
131
|
+
*/
|
|
132
|
+
export const assertWebAddresses = (operationId: string, text: string): void => {
|
|
133
|
+
// Read as the table's own member alone: an operation id that names a member every object
|
|
134
|
+
// inherits, `toString` among them, names no body.
|
|
135
|
+
const mask = Object.hasOwn(requestWebAddresses, operationId)
|
|
136
|
+
? requestWebAddresses[operationId]
|
|
137
|
+
: undefined;
|
|
138
|
+
if (mask === undefined) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const found = schemelessIn(JSON.parse(text), mask, "body");
|
|
143
|
+
if (found === undefined) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// What stands before an "@" may be a password, so an address that holds one is not quoted.
|
|
148
|
+
if (found.value.includes("@")) {
|
|
149
|
+
throw new MountayaConfigurationError(
|
|
150
|
+
`${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.`,
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// A host with no scheme is the likeliest slip, and the one whose fix can be spelled out exactly.
|
|
155
|
+
const example = bareHostPattern.test(found.value)
|
|
156
|
+
? `"https://${found.value}"`
|
|
157
|
+
: `"https://" before its host`;
|
|
158
|
+
|
|
159
|
+
throw refuseOption(
|
|
160
|
+
found.path,
|
|
161
|
+
found.value,
|
|
162
|
+
`pass it with its scheme, such as ${example}, since the contract types it an absolute address.`,
|
|
163
|
+
operationId,
|
|
164
|
+
);
|
|
165
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// GENERATED FILE. DO NOT EDIT.
|
|
2
|
+
//
|
|
3
|
+
// Where the JSON body each operation of the Map Studio API takes holds a web address,
|
|
4
|
+
// generated from the mountaya/schemas contract (sdk/model.json, `rest.operations`) by
|
|
5
|
+
// scripts/generate-web-addresses.mjs: every member its request body types `format: uri`.
|
|
6
|
+
//
|
|
7
|
+
// Edit the contract in mountaya/schemas, not this file.
|
|
8
|
+
|
|
9
|
+
import type { WebAddressMask } from "./webAddress.js";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* requestWebAddresses names, by operation id, where the JSON body a caller builds holds a web
|
|
13
|
+
* address, as a {@link WebAddressMask}. An operation whose body holds none is left out.
|
|
14
|
+
*/
|
|
15
|
+
export const requestWebAddresses: { readonly [operationId: string]: WebAddressMask } = {
|
|
16
|
+
/** PATCH /v1/itineraries/{itinerary_id}/waypoints/{waypoint_id} */
|
|
17
|
+
patchItineraryWaypoint: { contact: { booking_url: true, website: true }, media: { links: [{ url: true }], photos: [{ url: true }] } },
|
|
18
|
+
/** PATCH /v1/organizations/{organization_id}/ai-provider-config */
|
|
19
|
+
patchOrganizationAiProviderConfig: { base_url: true },
|
|
20
|
+
/** PATCH /v1/organizations/{organization_id}/webhook-endpoints/{webhook_endpoint_id} */
|
|
21
|
+
patchOrganizationWebhookEndpoint: { url: true },
|
|
22
|
+
/** POST /v1/itineraries/{itinerary_id}/waypoints */
|
|
23
|
+
postItineraryWaypoint: { contact: { booking_url: true, website: true }, media: { links: [{ url: true }], photos: [{ url: true }] } },
|
|
24
|
+
/** POST /v1/organizations */
|
|
25
|
+
postOrganization: { website: true },
|
|
26
|
+
/** POST /v1/organizations/{organization_id}/ai-provider-config */
|
|
27
|
+
postOrganizationAiProviderConfig: { base_url: true },
|
|
28
|
+
/** POST /v1/organizations/{organization_id}/webhook-endpoints */
|
|
29
|
+
postOrganizationWebhookEndpoint: { url: true },
|
|
30
|
+
};
|