@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
package/package.json
CHANGED
|
@@ -1,6 +1,129 @@
|
|
|
1
1
|
{
|
|
2
|
+
"author": "Mountaya",
|
|
3
|
+
"bugs": {
|
|
4
|
+
"email": "support@mountaya.com"
|
|
5
|
+
},
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"@types/geojson": "7946.0.16"
|
|
8
|
+
},
|
|
9
|
+
"description": "The Mountaya API client: Map Studio API, Tile API and the GraphQL Data API, with no runtime dependencies.",
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"@arethetypeswrong/cli": "0.18.5",
|
|
12
|
+
"@types/node": "26.6.5",
|
|
13
|
+
"@typescript/typescript6": "6.0.2",
|
|
14
|
+
"publint": "0.3.25",
|
|
15
|
+
"tsup": "9.0.0",
|
|
16
|
+
"typescript": "7.0.2",
|
|
17
|
+
"vitest": "5.0.5"
|
|
18
|
+
},
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=22.18.0"
|
|
21
|
+
},
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"@mountaya/source": "./src/index.ts",
|
|
25
|
+
"import": {
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"default": "./dist/index.js"
|
|
28
|
+
},
|
|
29
|
+
"require": {
|
|
30
|
+
"types": "./dist/index.d.cts",
|
|
31
|
+
"default": "./dist/index.cjs"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"./admin": {
|
|
35
|
+
"@mountaya/source": "./src/admin/index.ts",
|
|
36
|
+
"import": {
|
|
37
|
+
"types": "./dist/admin/index.d.ts",
|
|
38
|
+
"default": "./dist/admin/index.js"
|
|
39
|
+
},
|
|
40
|
+
"require": {
|
|
41
|
+
"types": "./dist/admin/index.d.cts",
|
|
42
|
+
"default": "./dist/admin/index.cjs"
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"./browser": {
|
|
46
|
+
"@mountaya/source": "./src/browser.ts",
|
|
47
|
+
"import": {
|
|
48
|
+
"types": "./dist/browser.d.ts",
|
|
49
|
+
"default": "./dist/browser.js"
|
|
50
|
+
},
|
|
51
|
+
"require": {
|
|
52
|
+
"types": "./dist/browser.d.cts",
|
|
53
|
+
"default": "./dist/browser.cjs"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"./events": {
|
|
57
|
+
"@mountaya/source": "./src/events/index.ts",
|
|
58
|
+
"import": {
|
|
59
|
+
"types": "./dist/events/index.d.ts",
|
|
60
|
+
"default": "./dist/events/index.js"
|
|
61
|
+
},
|
|
62
|
+
"require": {
|
|
63
|
+
"types": "./dist/events/index.d.cts",
|
|
64
|
+
"default": "./dist/events/index.cjs"
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
"./package.json": "./package.json"
|
|
68
|
+
},
|
|
69
|
+
"files": [
|
|
70
|
+
"dist",
|
|
71
|
+
"src",
|
|
72
|
+
"!src/**/*.test.ts",
|
|
73
|
+
"README.md",
|
|
74
|
+
"CHANGELOG.md",
|
|
75
|
+
"LICENSE.txt",
|
|
76
|
+
"LICENCE.fr.txt"
|
|
77
|
+
],
|
|
78
|
+
"homepage": "https://mountaya.com",
|
|
79
|
+
"keywords": [
|
|
80
|
+
"mountaya",
|
|
81
|
+
"outdoor",
|
|
82
|
+
"routing",
|
|
83
|
+
"geospatial",
|
|
84
|
+
"maps",
|
|
85
|
+
"isochrones",
|
|
86
|
+
"terrain"
|
|
87
|
+
],
|
|
88
|
+
"license": "SEE LICENSE IN LICENSE.txt",
|
|
89
|
+
"main": "./dist/index.cjs",
|
|
90
|
+
"module": "./dist/index.js",
|
|
2
91
|
"name": "@mountaya/client",
|
|
3
|
-
"
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
92
|
+
"publishConfig": {
|
|
93
|
+
"access": "public"
|
|
94
|
+
},
|
|
95
|
+
"repository": {
|
|
96
|
+
"directory": "packages/client",
|
|
97
|
+
"type": "git",
|
|
98
|
+
"url": "git+https://github.com/mountaya/sdk-typescript.git"
|
|
99
|
+
},
|
|
100
|
+
"scripts": {
|
|
101
|
+
"attw": "attw --pack .",
|
|
102
|
+
"build": "NODE_OPTIONS='--import=../../scripts/lib/typescriptApi.mjs --max-old-space-size=4096' tsup",
|
|
103
|
+
"dev": "NODE_OPTIONS='--import=../../scripts/lib/typescriptApi.mjs --max-old-space-size=4096' tsup --watch",
|
|
104
|
+
"generate:readme": "node ../../scripts/generate-readme-exports.mjs && node ../../scripts/generate-readme-props.mjs",
|
|
105
|
+
"lint": "npm run typecheck && node ../../scripts/generate-readme-exports.mjs --check && node ../../scripts/generate-readme-props.mjs --check && node ../../scripts/check-readme-snippets.mjs",
|
|
106
|
+
"prepublishOnly": "npm run build && npm run publint && npm run attw",
|
|
107
|
+
"publint": "publint",
|
|
108
|
+
"test": "vitest run",
|
|
109
|
+
"test:watch": "vitest",
|
|
110
|
+
"typecheck": "node ../../scripts/typecheck.mjs"
|
|
111
|
+
},
|
|
112
|
+
"sideEffects": false,
|
|
113
|
+
"type": "module",
|
|
114
|
+
"types": "./dist/index.d.ts",
|
|
115
|
+
"typesVersions": {
|
|
116
|
+
"*": {
|
|
117
|
+
"admin": [
|
|
118
|
+
"./dist/admin/index.d.ts"
|
|
119
|
+
],
|
|
120
|
+
"browser": [
|
|
121
|
+
"./dist/browser.d.ts"
|
|
122
|
+
],
|
|
123
|
+
"events": [
|
|
124
|
+
"./dist/events/index.d.ts"
|
|
125
|
+
]
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
"version": "0.1.0"
|
|
129
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The admin unit of `@mountaya/client`: what only a server that manages an organization, mints
|
|
3
|
+
* session tokens or receives webhooks needs, apart from the client an application draws a map,
|
|
4
|
+
* edits an itinerary or reads the Data API with.
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { Mountaya } from "@mountaya/client";
|
|
8
|
+
* import { MountayaAdmin } from "@mountaya/client/admin";
|
|
9
|
+
*
|
|
10
|
+
* const mountaya = new Mountaya({ credential: { publishableKey: "pk_…", sessionToken } });
|
|
11
|
+
*
|
|
12
|
+
* // A method resolves to the response envelope: the payload is at `data`.
|
|
13
|
+
* const { data: keys } = await new MountayaAdmin(mountaya).keys.getOrganizationPublishableKeys({
|
|
14
|
+
* organization_id,
|
|
15
|
+
* });
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* It holds the operations of the contract's `admin` group (billing, organizations, webhooks, the
|
|
19
|
+
* acting user's own memberships and preferences, keys, invitations, members, and minting a session
|
|
20
|
+
* token), the schemas only those and the webhook events reach, and webhook receiving. Which unit an
|
|
21
|
+
* operation or a schema belongs to is the contract's to say, so every language's client divides
|
|
22
|
+
* the same way.
|
|
23
|
+
*
|
|
24
|
+
* It takes the client the core builds, of `@mountaya/client` or of `@mountaya/client/browser`,
|
|
25
|
+
* and calls through that client's transport: the credential, the retries and the error classes
|
|
26
|
+
* are the core's. A browser bundle imports it beside the browser entry, and the secret key stays
|
|
27
|
+
* out of it as it does there.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
// The admin unit's operations as free functions, each taking the transport first, as `rest` of
|
|
31
|
+
// the default entry holds the core's.
|
|
32
|
+
export * as rest from "../rest/adminOperations.gen.js";
|
|
33
|
+
// Every schema only the admin unit's operations and webhook events reach, under the contract's
|
|
34
|
+
// name, so a caller names what one of them hands it without reaching through a namespace.
|
|
35
|
+
export type * from "../rest/adminResources.gen.js";
|
|
36
|
+
// A webhook delivery, verified and read as the event it carries, typed by its `type`. The
|
|
37
|
+
// verification takes an endpoint's signing secret, so it runs where a delivery arrives, on a
|
|
38
|
+
// server. `WebhookEvent` shadows the contract's envelope of the same name, which ties no `type` to
|
|
39
|
+
// its `data`; `RestSchema` of the default entry keeps the envelope.
|
|
40
|
+
export {
|
|
41
|
+
type ConstructWebhookEventOptions,
|
|
42
|
+
constructWebhookEvent,
|
|
43
|
+
MountayaWebhookSignatureError,
|
|
44
|
+
type WebhookSignatureFailure,
|
|
45
|
+
} from "../webhooks/rules/constructWebhookEvent.js";
|
|
46
|
+
export type { WebhookEvent } from "../webhooks/rules/webhookEvent.js";
|
|
47
|
+
export { MountayaAdmin } from "./rules/mountayaAdmin.js";
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The admin unit's operations, bound to the transport of a client the core built.
|
|
3
|
+
*
|
|
4
|
+
* The contract ships the client as two units, the core and the admin unit, and an application that
|
|
5
|
+
* draws a map, edits an itinerary or reads the Data API links the core alone. A language with
|
|
6
|
+
* extension members declares the admin namespace on the core's client from inside the unit;
|
|
7
|
+
* TypeScript has none, so the unit publishes {@link MountayaAdmin}, built over a client, and the
|
|
8
|
+
* core's `Mountaya` holds no admin member of its own. What it reaches of the core is its
|
|
9
|
+
* transport, the one object both entries' clients publish, so it serves a client of either.
|
|
10
|
+
*
|
|
11
|
+
* The table it holds is the `admin` half of the generated `bind`, built once per transport and
|
|
12
|
+
* held while the transport lives: a server that writes `new MountayaAdmin(mountaya)` in every
|
|
13
|
+
* handler builds the table once, and every instance over one transport holds the same namespaces.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import type { MountayaTransport } from "../../core/rules/transport.js";
|
|
17
|
+
import { bind } from "../../rest/operations.gen.js";
|
|
18
|
+
|
|
19
|
+
/** The admin half of the generated table: the organization's operations, by resource. */
|
|
20
|
+
type AdminOperations = ReturnType<typeof bind>["admin"];
|
|
21
|
+
|
|
22
|
+
/** The admin half of the generated table, bound to each transport it has been asked for. */
|
|
23
|
+
const bound = new WeakMap<MountayaTransport, AdminOperations>();
|
|
24
|
+
|
|
25
|
+
/** adminOperationsOf answers the admin half bound to `transport`, built at the first ask. */
|
|
26
|
+
const adminOperationsOf = (transport: MountayaTransport): AdminOperations => {
|
|
27
|
+
const held = bound.get(transport);
|
|
28
|
+
if (held !== undefined) {
|
|
29
|
+
return held;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// One bind call, kept whole: the table is one object literal per surface, so asking it for its
|
|
33
|
+
// admin half builds the other two as well, once per transport.
|
|
34
|
+
const table = bind(transport).admin;
|
|
35
|
+
bound.set(transport, table);
|
|
36
|
+
|
|
37
|
+
return table;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* MountayaAdmin is the Map Studio API's organization half for a client: its billing, its
|
|
42
|
+
* organizations, its webhook endpoints, the acting user's memberships and preferences, its keys,
|
|
43
|
+
* invitations and members, and minting a session token. Each method resolves to the response
|
|
44
|
+
* envelope, with the payload at `data`, and calls through the client's own transport, under its
|
|
45
|
+
* credential, retries and error classes.
|
|
46
|
+
*
|
|
47
|
+
* Constructing one is cheap: the operations are bound once per transport, so two instances over
|
|
48
|
+
* one client hold the same namespaces.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* import { Mountaya } from "@mountaya/client";
|
|
53
|
+
* import { MountayaAdmin } from "@mountaya/client/admin";
|
|
54
|
+
*
|
|
55
|
+
* const secretKey = process.env.MOUNTAYA_SECRET_KEY;
|
|
56
|
+
* if (secretKey === undefined) {
|
|
57
|
+
* throw new Error("MOUNTAYA_SECRET_KEY is not set.");
|
|
58
|
+
* }
|
|
59
|
+
*
|
|
60
|
+
* const server = new Mountaya({ credential: { secretKey } });
|
|
61
|
+
* const { data: session } = await new MountayaAdmin(server).sessions.postSession({
|
|
62
|
+
* body: { publishable_key: "pk_…" },
|
|
63
|
+
* });
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export class MountayaAdmin {
|
|
67
|
+
/** The organization's billing: its subscription, its payment methods, its details and invoices. */
|
|
68
|
+
readonly billing: AdminOperations["billing"];
|
|
69
|
+
/** The organization's invitations. */
|
|
70
|
+
readonly invitations: AdminOperations["invitations"];
|
|
71
|
+
/** The organization's publishable keys. */
|
|
72
|
+
readonly keys: AdminOperations["keys"];
|
|
73
|
+
/** The organization's members. */
|
|
74
|
+
readonly members: AdminOperations["members"];
|
|
75
|
+
/** The organizations themselves: their details, settings, usage and AI provider configuration. */
|
|
76
|
+
readonly organizations: AdminOperations["organizations"];
|
|
77
|
+
/** Minting a session token for a publishable key. */
|
|
78
|
+
readonly sessions: AdminOperations["sessions"];
|
|
79
|
+
/** The acting user's own memberships, invitations and preferences. */
|
|
80
|
+
readonly users: AdminOperations["users"];
|
|
81
|
+
/** The organization's webhook endpoints, the events it was sent and their deliveries. */
|
|
82
|
+
readonly webhooks: AdminOperations["webhooks"];
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Binds the admin unit's operations to the transport of `mountaya`.
|
|
86
|
+
*
|
|
87
|
+
* @param mountaya The client whose transport the operations call through: a `Mountaya` of
|
|
88
|
+
* `@mountaya/client` or of `@mountaya/client/browser`.
|
|
89
|
+
*/
|
|
90
|
+
constructor(mountaya: { readonly transport: MountayaTransport }) {
|
|
91
|
+
const operations = adminOperationsOf(mountaya.transport);
|
|
92
|
+
|
|
93
|
+
this.billing = operations.billing;
|
|
94
|
+
this.invitations = operations.invitations;
|
|
95
|
+
this.keys = operations.keys;
|
|
96
|
+
this.members = operations.members;
|
|
97
|
+
this.organizations = operations.organizations;
|
|
98
|
+
this.sessions = operations.sessions;
|
|
99
|
+
this.users = operations.users;
|
|
100
|
+
this.webhooks = operations.webhooks;
|
|
101
|
+
}
|
|
102
|
+
}
|
package/src/browser.ts
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The browser-safe entry point of `@mountaya/client`.
|
|
3
|
+
*
|
|
4
|
+
* Identical to the default entry except for what it refuses to give you: there is no
|
|
5
|
+
* secret-key credential here, so a browser bundle cannot reach one through this import
|
|
6
|
+
* even by mistake.
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { Mountaya } from "@mountaya/client/browser";
|
|
10
|
+
*
|
|
11
|
+
* // A publishable key alone reaches public data on the Map Studio and Tile APIs.
|
|
12
|
+
* const mountaya = new Mountaya({ credential: { publishableKey: "pk_…" } });
|
|
13
|
+
*
|
|
14
|
+
* // A session token minted by your server scopes it up to the organization, and is what
|
|
15
|
+
* // every Data API call requires beside the key.
|
|
16
|
+
* const scoped = new Mountaya({
|
|
17
|
+
* credential: { publishableKey: "pk_…", sessionToken },
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* Mint the session token on your server with `POST /v1/sessions`, using the secret key
|
|
22
|
+
* there, and send only the token to the browser. The token is short-lived and carries an
|
|
23
|
+
* `expires_at`, which is the whole reason it is safe to ship where the secret key is not.
|
|
24
|
+
*
|
|
25
|
+
* This is one of two defences. The other is a runtime guard in `core/rules/auth.ts` that throws
|
|
26
|
+
* if a secret key is constructed where a page's `window` and `document` both exist, or in a React
|
|
27
|
+
* Native application: it catches the cases this entry point cannot, where a bundler resolves the
|
|
28
|
+
* Node condition into browser code anyway, and where a runtime resolves no browser entry point.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
import type { Geometry } from "geojson";
|
|
32
|
+
|
|
33
|
+
import type {
|
|
34
|
+
CookieCredential,
|
|
35
|
+
PublishableCredential,
|
|
36
|
+
ShareCredential,
|
|
37
|
+
} from "./core/rules/auth.js";
|
|
38
|
+
import type { ClientOptions } from "./core/rules/transport.js";
|
|
39
|
+
import { MountayaTransport as CoreTransport } from "./core/rules/transport.js";
|
|
40
|
+
import { bind as bindData } from "./data/operations.gen.js";
|
|
41
|
+
import { bind as bindRest } from "./rest/operations.gen.js";
|
|
42
|
+
import { bind as bindTiles } from "./tiles/operations.gen.js";
|
|
43
|
+
|
|
44
|
+
export {
|
|
45
|
+
SessionTokenEngine,
|
|
46
|
+
type SessionTokenEngineOptions,
|
|
47
|
+
type SessionTokenSnapshot,
|
|
48
|
+
} from "./core/engines/sessionToken.js";
|
|
49
|
+
export type {
|
|
50
|
+
CookieCredential,
|
|
51
|
+
PublishableCredential,
|
|
52
|
+
SessionTokenSource,
|
|
53
|
+
ShareCredential,
|
|
54
|
+
} from "./core/rules/auth.js";
|
|
55
|
+
export type { DateMask } from "./core/rules/dates.js";
|
|
56
|
+
export { decodeRestSchema } from "./core/rules/decode.js";
|
|
57
|
+
export type { MountayaResponse } from "./core/rules/envelope.js";
|
|
58
|
+
export {
|
|
59
|
+
type ApiErrorDetails,
|
|
60
|
+
type ErrorCode,
|
|
61
|
+
type ErrorEntry,
|
|
62
|
+
type ErrorMetadata,
|
|
63
|
+
errorForStatus,
|
|
64
|
+
type IdempotentAnswer,
|
|
65
|
+
isMountayaApiError,
|
|
66
|
+
isMountayaError,
|
|
67
|
+
MountayaApiError,
|
|
68
|
+
MountayaAuthenticationError,
|
|
69
|
+
MountayaBadRequestError,
|
|
70
|
+
MountayaBillingError,
|
|
71
|
+
MountayaConfigurationError,
|
|
72
|
+
MountayaConflictError,
|
|
73
|
+
MountayaConnectionError,
|
|
74
|
+
MountayaDataError,
|
|
75
|
+
MountayaError,
|
|
76
|
+
MountayaForbiddenError,
|
|
77
|
+
MountayaIdempotencyKeyInUseError,
|
|
78
|
+
MountayaIdempotentAnswerUnavailableError,
|
|
79
|
+
MountayaMethodNotAllowedError,
|
|
80
|
+
MountayaNotFoundError,
|
|
81
|
+
MountayaPayloadTooLargeError,
|
|
82
|
+
MountayaPreconditionFailedError,
|
|
83
|
+
MountayaRateLimitError,
|
|
84
|
+
MountayaServerError,
|
|
85
|
+
PAYMENT_REQUIRED_CODE,
|
|
86
|
+
} from "./core/rules/errors.js";
|
|
87
|
+
export { type PagedResponse, type PaginateOptions, paginate } from "./core/rules/paginate.js";
|
|
88
|
+
export {
|
|
89
|
+
parseRateLimit,
|
|
90
|
+
type RateLimitInfo,
|
|
91
|
+
type RateLimitPolicy,
|
|
92
|
+
} from "./core/rules/rateLimit.js";
|
|
93
|
+
export type { ResourceKind, ResourceRef } from "./core/rules/resourceRef.js";
|
|
94
|
+
export type { RetryOptions, Surface } from "./core/rules/retry.js";
|
|
95
|
+
// Data API field selection. `Selection` and `Selected` are the two halves a caller names
|
|
96
|
+
// when it holds a selection in a variable rather than passing it inline.
|
|
97
|
+
export {
|
|
98
|
+
type DataOptions,
|
|
99
|
+
type DataResult,
|
|
100
|
+
type FieldTree,
|
|
101
|
+
MountayaSelectionError,
|
|
102
|
+
type Selected,
|
|
103
|
+
type Selection,
|
|
104
|
+
type SelectionValue,
|
|
105
|
+
} from "./core/rules/selection.js";
|
|
106
|
+
export {
|
|
107
|
+
type BaseUrlOverrides,
|
|
108
|
+
type BinaryBody,
|
|
109
|
+
boundFetch,
|
|
110
|
+
defaultBaseUrls,
|
|
111
|
+
type RequestArgs,
|
|
112
|
+
type RequestOptions,
|
|
113
|
+
type ResponseReport,
|
|
114
|
+
type StreamSeam,
|
|
115
|
+
} from "./core/rules/transport.js";
|
|
116
|
+
export { SCHEMA_VERSION } from "./core/rules/version.gen.js";
|
|
117
|
+
export * as data from "./data/operations.gen.js";
|
|
118
|
+
export type * as DataSchema from "./data/schema.gen.js";
|
|
119
|
+
// The answer of each Data API operation, by the same names the default entry gives them.
|
|
120
|
+
export type {
|
|
121
|
+
AnalyzeGeometryResult,
|
|
122
|
+
DirectionsResult,
|
|
123
|
+
ExportItineraryResult,
|
|
124
|
+
GeocodeResult,
|
|
125
|
+
IsochronesResult,
|
|
126
|
+
ItineraryResult,
|
|
127
|
+
MatrixResult,
|
|
128
|
+
PoisResult,
|
|
129
|
+
ReverseGeocodeResult,
|
|
130
|
+
SearchResult,
|
|
131
|
+
SuggestionsResult,
|
|
132
|
+
TerrainGridResult,
|
|
133
|
+
TerrainProfileResult,
|
|
134
|
+
TerrainSamplesResult,
|
|
135
|
+
} from "./data/schema.gen.js";
|
|
136
|
+
// The selectable field tree of each Data API operation, plus a named `select` type per
|
|
137
|
+
// operation (`DirectionsSelection` and its siblings).
|
|
138
|
+
export * as DataSelection from "./data/selection.gen.js";
|
|
139
|
+
export * as rest from "./rest/coreOperations.gen.js";
|
|
140
|
+
// The same root type surface the default entry offers: the browser build narrows the
|
|
141
|
+
// CREDENTIAL, never the contract. Both publish the core's, and `@mountaya/client/admin` the
|
|
142
|
+
// admin unit's.
|
|
143
|
+
export type * from "./rest/coreResources.gen.js";
|
|
144
|
+
export type * as RestSchema from "./rest/schema.gen.js";
|
|
145
|
+
export * as tiles from "./tiles/operations.gen.js";
|
|
146
|
+
export type * as TileSchema from "./tiles/schema.gen.js";
|
|
147
|
+
// The geometry a Map Studio answer holds. It is declared by `geojson`, a dependency of this
|
|
148
|
+
// package, and a declaration file names an inferred answer through a name an entry point
|
|
149
|
+
// publishes: without this one, an exported function that returns `getItinerary(...)`
|
|
150
|
+
// unannotated does not compile (TS2883) where the installer keeps `@types/geojson` out of the
|
|
151
|
+
// consumer's own directory.
|
|
152
|
+
export type { Geometry };
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* BrowserClientOptions is ClientOptions with the secret-key credential removed.
|
|
156
|
+
*
|
|
157
|
+
* The narrowing is the point of this module: `{ secretKey }` is not assignable here, so
|
|
158
|
+
* the mistake is a type error at the call site rather than a key in a bundle.
|
|
159
|
+
*/
|
|
160
|
+
export interface BrowserClientOptions extends Omit<ClientOptions, "credential"> {
|
|
161
|
+
/** How the client authenticates: a publishable key, a share token or the browser's session. */
|
|
162
|
+
readonly credential: PublishableCredential | ShareCredential | CookieCredential;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* MountayaTransport is the default entry's transport, as a type: the constructor below builds
|
|
167
|
+
* that same class, so a transport this entry hands out is one the default entry's type describes.
|
|
168
|
+
*/
|
|
169
|
+
export type MountayaTransport = CoreTransport;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* MountayaTransport builds a transport from {@link BrowserClientOptions}, so a secret key is a type
|
|
173
|
+
* error at the call site here as it is for {@link Mountaya}, rather than a key in a bundle that
|
|
174
|
+
* only the runtime guard refuses.
|
|
175
|
+
*
|
|
176
|
+
* It is the default entry's class under a narrower constructor type, not a second class, so
|
|
177
|
+
* `instanceof` answers the same against either entry's name. A secret-key transport is built from
|
|
178
|
+
* `@mountaya/client`, on a server.
|
|
179
|
+
*/
|
|
180
|
+
export const MountayaTransport: new (options: BrowserClientOptions) => CoreTransport =
|
|
181
|
+
CoreTransport;
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Mountaya is the browser client. It accepts a publishable key or a share token, and
|
|
185
|
+
* cannot be constructed with a secret key.
|
|
186
|
+
*
|
|
187
|
+
* The organization's operations are the admin unit's: `new MountayaAdmin(mountaya)` of
|
|
188
|
+
* `@mountaya/client/admin` answers them, bound to this client's transport.
|
|
189
|
+
*/
|
|
190
|
+
export class Mountaya {
|
|
191
|
+
/**
|
|
192
|
+
* The AI agent: starting a run, answering it, rating it. Each method resolves to the response
|
|
193
|
+
* envelope, with the payload at `data`; a run's events are read through
|
|
194
|
+
* `createAgentTransport` of `@mountaya/client/events`.
|
|
195
|
+
*/
|
|
196
|
+
readonly agent: ReturnType<typeof bindRest>["agent"];
|
|
197
|
+
/**
|
|
198
|
+
* The GraphQL Data API: directions, search, terrain, isochrones, matrices. Each method resolves
|
|
199
|
+
* to the operation's own field, with no envelope.
|
|
200
|
+
*/
|
|
201
|
+
readonly data: ReturnType<typeof bindData>;
|
|
202
|
+
/**
|
|
203
|
+
* The Map Studio API's map half: itineraries, zones, collections, and their catalogs. Each
|
|
204
|
+
* method resolves to the response envelope, with the payload at `data`.
|
|
205
|
+
*/
|
|
206
|
+
readonly studio: ReturnType<typeof bindRest>["studio"];
|
|
207
|
+
/** The Tile API's style specifications. Each method resolves to the response envelope. */
|
|
208
|
+
readonly tiles: ReturnType<typeof bindTiles>;
|
|
209
|
+
/**
|
|
210
|
+
* The transport every method calls through: for a call this client binds no method for, and
|
|
211
|
+
* for the openers of `@mountaya/client/events`.
|
|
212
|
+
*/
|
|
213
|
+
readonly transport: MountayaTransport;
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Builds a browser client over one credential and its options, checking both before anything
|
|
217
|
+
* is sent.
|
|
218
|
+
*
|
|
219
|
+
* @throws `MountayaConfigurationError` for options that are not an object, a credential that
|
|
220
|
+
* cannot work, or an option outside its range: see {@link ClientOptions}.
|
|
221
|
+
*/
|
|
222
|
+
constructor(options: BrowserClientOptions) {
|
|
223
|
+
this.transport = new MountayaTransport(options);
|
|
224
|
+
|
|
225
|
+
const api = bindRest(this.transport);
|
|
226
|
+
|
|
227
|
+
this.agent = api.agent;
|
|
228
|
+
this.data = bindData(this.transport);
|
|
229
|
+
this.studio = api.studio;
|
|
230
|
+
this.tiles = bindTiles(this.transport);
|
|
231
|
+
}
|
|
232
|
+
}
|