@tiledev/tile-push-cli 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/LICENSE ADDED
@@ -0,0 +1,49 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Apptile / Tile Push
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ ---
24
+
25
+ This package wraps and depends on `@hot-updater/react-native`, which is the
26
+ work of upstream contributors and is licensed separately under MIT. The
27
+ upstream copyright and license are reproduced below as required by MIT.
28
+
29
+ MIT License
30
+
31
+ Copyright (c) 2023 Sungyu Kang
32
+
33
+ Permission is hereby granted, free of charge, to any person obtaining a copy
34
+ of this software and associated documentation files (the "Software"), to deal
35
+ in the Software without restriction, including without limitation the rights
36
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
37
+ copies of the Software, and to permit persons to whom the Software is
38
+ furnished to do so, subject to the following conditions:
39
+
40
+ The above copyright notice and this permission notice shall be included in all
41
+ copies or substantial portions of the Software.
42
+
43
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
44
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
45
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
46
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
47
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
48
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
49
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,183 @@
1
+ # Tile Updater
2
+
3
+ Over-the-air (OTA) code-push updates for React Native — ship JS/asset changes to
4
+ installed apps without an app-store release. Multi-tenant, fingerprint-safe, and
5
+ self-contained: the SDK and CLI are plain npm packages.
6
+
7
+ - **`@tiledev/tile-updater`** — the runtime SDK (wrap your app; devices auto-update on launch).
8
+ - **`@tiledev/tile-push-cli`** — the `tile-push` CLI (init, fingerprint, deploy, manage bundles).
9
+
10
+ Built on [hot-updater](https://github.com/gronxb/hot-updater).
11
+
12
+ ---
13
+
14
+ ## Install
15
+
16
+ ```bash
17
+ npm install @tiledev/tile-updater @hot-updater/react-native @hot-updater/core
18
+ npm install --save-dev @tiledev/tile-push-cli @hot-updater/expo
19
+ ```
20
+
21
+ `@hot-updater/react-native` and `@hot-updater/core` are **peer dependencies** of the
22
+ SDK — install them explicitly. Use `@hot-updater/metro` instead of `@hot-updater/expo`
23
+ for a bare React Native (non-Expo) project.
24
+
25
+ > **Using the Tile platform?** Skip all of this — `tile init --blueprint default`
26
+ > installs and wires the SDK, the config plugin, `tile-push.config.ts`, the app
27
+ > wrap, and a reconciled lockfile automatically. Jump to [Ship an update](#ship-an-update).
28
+
29
+ ---
30
+
31
+ ## Wire it up (3 steps)
32
+
33
+ ### 1. Wrap your root component
34
+
35
+ ```tsx
36
+ // App.tsx
37
+ import { TileUpdater } from '@tiledev/tile-updater';
38
+
39
+ function App() {
40
+ return <YourAppRoot />;
41
+ }
42
+
43
+ export default TileUpdater.wrap({
44
+ appId: 'your-app-id', // your Tile Push tenant id
45
+ apiUrl: 'https://ota.tile.dev', // the OTA backend
46
+ updateStrategy: 'fingerprint', // or 'appVersion'
47
+ })(App);
48
+ ```
49
+
50
+ ### 2. Register the Expo config plugin
51
+
52
+ `app.json` → `expo.plugins`. This injects the native **fingerprint** into the build
53
+ so devices only receive bundles built from a matching native tree:
54
+
55
+ ```json
56
+ {
57
+ "expo": {
58
+ "plugins": ["@tiledev/tile-updater"]
59
+ }
60
+ }
61
+ ```
62
+
63
+ ### 3. Create `tile-push.config.ts`
64
+
65
+ Run `npx tile-push init --app-id <id> --token <deploy-token>`, or write it by hand:
66
+
67
+ ```ts
68
+ import 'dotenv/config';
69
+ import { defineConfig } from 'hot-updater';
70
+ import { expo } from '@hot-updater/expo';
71
+ import { tilePushDatabase, tilePushStorage } from '@tiledev/tile-push-cli';
72
+
73
+ const appId = process.env.TILE_PUSH_APP_ID;
74
+ if (!appId) throw new Error('TILE_PUSH_APP_ID is not set (see .env).');
75
+
76
+ export default defineConfig({
77
+ build: expo({ enableHermes: true }),
78
+ storage: tilePushStorage({ appId }),
79
+ database: tilePushDatabase({ appId }),
80
+ updateStrategy: 'fingerprint',
81
+ });
82
+ ```
83
+
84
+ ---
85
+
86
+ ## Ship an update
87
+
88
+ The **fingerprint** is a hash of your native inputs (deps, native config). A bundle
89
+ is only served to devices whose installed build has the same fingerprint — so a JS
90
+ push can never land on an incompatible native app. Keep `fingerprint.json` committed
91
+ as the single source of truth.
92
+
93
+ ### 1. Fingerprint (once per native change)
94
+
95
+ ```bash
96
+ npx tile-push fingerprint create # writes fingerprint.json
97
+ ```
98
+
99
+ For Expo prebuild projects the order is **prebuild → fingerprint create → prebuild
100
+ (injects the hash) → build**. The value is stable across re-injection.
101
+
102
+ ### 2. Build the native app
103
+
104
+ Any normal build works — the SDK is just a package, and the config plugin injects
105
+ the fingerprint at `expo prebuild`. **No OTA/deploy step happens during the build.**
106
+
107
+ ### 3. Deploy
108
+
109
+ ```bash
110
+ npx tile-push deploy --platform android --rollout 10 # ship to 10% of devices
111
+ npx tile-push deploy --platform android # ship to everyone
112
+ ```
113
+
114
+ `deploy` bundles your JS (Hermes), verifies its fingerprint matches `fingerprint.json`,
115
+ tags the bundle, and uploads it. Devices whose native build matches pick it up on
116
+ next launch; others are correctly skipped.
117
+
118
+ ---
119
+
120
+ ## Commands
121
+
122
+ | Command | Description |
123
+ | --- | --- |
124
+ | `tile-push init` | Write `tile-push.config.ts` + `~/.tile-push/credentials.json` |
125
+ | `tile-push fingerprint create` | Compute/snapshot the native fingerprint |
126
+ | `tile-push deploy` | Build and ship a new bundle (supports staged `--rollout`) |
127
+ | `tile-push bundle list/show/enable/disable/update/promote/delete` | Manage bundles |
128
+ | `tile-push rollback <channel>` | Disable the most recent enabled bundle |
129
+ | `tile-push channel [set]` | Read/write the channel baked into the native app |
130
+ | `tile-push whoami` | Show the active tenant + token |
131
+ | `tile-push doctor` | Diagnose config / credentials / server / project |
132
+ | `tile-push console` | Open the web console for this tenant |
133
+
134
+ ### Credentials
135
+
136
+ The CLI reads credentials in this order:
137
+
138
+ 1. `TILE_PUSH_APP_ID` + `TILE_PUSH_TOKEN` env vars (preferred for CI)
139
+ 2. `~/.tile-push/credentials.json` (written by `tile-push init`, chmod 600)
140
+
141
+ Never put tokens in `tile-push.config.ts` — it's committed to your repo. Override
142
+ the API base URL with `TILE_PUSH_API_URL`.
143
+
144
+ ---
145
+
146
+ ## On the Tile platform
147
+
148
+ Apptile customers manage the same thing through the unified CLI — `tile ota`
149
+ forwards to this binary with the app id + session token injected automatically:
150
+
151
+ ```bash
152
+ tile ota deploy --platform android --rollout 10
153
+ tile ota bundle list
154
+ tile ota rollback production
155
+ ```
156
+
157
+ `tile init --blueprint default` installs and wires everything above, so a fresh app
158
+ is code-push-ready after `npm install`.
159
+
160
+ ---
161
+
162
+ ## Roadmap
163
+
164
+ - **Cloud Push** — deploy an OTA bundle **remotely** from a `tile save` or git ref,
165
+ the same way native builds already run in the cloud. The bundle is built in the
166
+ same container as the APK, so the fingerprint matches by construction — no local
167
+ toolchain, no fingerprint drift. Planned surface: `tile ota deploy --source
168
+ save|git`, with a reach-check that refuses a push no installed build can receive.
169
+ - iOS build/deploy parity docs.
170
+ - First-class staged-rollout cohort tooling in the CLI.
171
+ - `tile-push login` — browser device-code flow that mints and stores a token.
172
+
173
+ ---
174
+
175
+ ## Acknowledgements
176
+
177
+ Built on [hot-updater](https://github.com/gronxb/hot-updater) (MIT). Tile Push wraps
178
+ it with hosted storage, auth, multi-tenancy, and a unified deploy CLI. The bundle
179
+ pipeline, fingerprinting, and bundle metadata model are hot-updater's work.
180
+
181
+ ## License
182
+
183
+ MIT. See `LICENSE`.
@@ -0,0 +1,200 @@
1
+ require("./bin/tile-push.cjs");
2
+ let node_fs_promises = require("node:fs/promises");
3
+ let node_path = require("node:path");
4
+ let node_os = require("node:os");
5
+ //#region src/auth/tokenStore.ts
6
+ const DEFAULT_API_URL = "https://ota.tile.dev";
7
+ const credentialsPath = () => (0, node_path.join)((0, node_os.homedir)(), ".tile-push", "credentials.json");
8
+ const credentialsDir = () => (0, node_path.join)((0, node_os.homedir)(), ".tile-push");
9
+ /**
10
+ * Resolve credentials with env precedence:
11
+ * 1. TILE_PUSH_APP_ID + TILE_PUSH_TOKEN env vars (preferred for CI)
12
+ * 2. ~/.tile-push/credentials.json (interactive / dev machines)
13
+ * 3. null if neither set
14
+ *
15
+ * TILE_PUSH_API_URL overrides the API base URL in either case.
16
+ */
17
+ const loadCredentials = async () => {
18
+ const envAppId = process.env.TILE_PUSH_APP_ID;
19
+ const envToken = process.env.TILE_PUSH_TOKEN;
20
+ const envApiUrl = process.env.TILE_PUSH_API_URL;
21
+ if (envAppId && envToken) return {
22
+ appId: envAppId,
23
+ token: envToken,
24
+ apiUrl: envApiUrl ?? DEFAULT_API_URL
25
+ };
26
+ try {
27
+ const raw = await (0, node_fs_promises.readFile)(credentialsPath(), "utf8");
28
+ const parsed = JSON.parse(raw);
29
+ if (!parsed.appId || !parsed.token) return null;
30
+ return {
31
+ appId: parsed.appId,
32
+ token: parsed.token,
33
+ apiUrl: envApiUrl ?? parsed.apiUrl ?? DEFAULT_API_URL
34
+ };
35
+ } catch (err) {
36
+ if (err.code === "ENOENT") return null;
37
+ throw err;
38
+ }
39
+ };
40
+ const saveCredentials = async (creds) => {
41
+ await (0, node_fs_promises.mkdir)(credentialsDir(), {
42
+ recursive: true,
43
+ mode: 448
44
+ });
45
+ await (0, node_fs_promises.writeFile)(credentialsPath(), JSON.stringify(creds, null, 2), { mode: 384 });
46
+ };
47
+ /**
48
+ * Throws a helpful message if no credentials are configured. Use this at the
49
+ * top of any command that needs server access.
50
+ */
51
+ const requireCredentials = async () => {
52
+ const creds = await loadCredentials();
53
+ if (!creds) throw new Error("No Tile Push credentials found. Run `tile-push init` to set up, or export TILE_PUSH_APP_ID and TILE_PUSH_TOKEN environment variables.");
54
+ return creds;
55
+ };
56
+ /** Test helper — confirms creds file exists and is 0600 (or just env vars). */
57
+ const credentialsDiagnostic = async () => {
58
+ if (process.env.TILE_PUSH_APP_ID && process.env.TILE_PUSH_TOKEN) return {
59
+ source: "env",
60
+ pathOrEnv: "TILE_PUSH_APP_ID / TILE_PUSH_TOKEN"
61
+ };
62
+ try {
63
+ const s = await (0, node_fs_promises.stat)(credentialsPath());
64
+ return {
65
+ source: "file",
66
+ pathOrEnv: credentialsPath(),
67
+ modeOk: (s.mode & 511) === 384
68
+ };
69
+ } catch {
70
+ return {
71
+ source: "none",
72
+ pathOrEnv: credentialsPath()
73
+ };
74
+ }
75
+ };
76
+ //#endregion
77
+ //#region src/auth/apiClient.ts
78
+ /**
79
+ * Thin fetch wrapper that injects the Bearer token, prepends the tenant
80
+ * prefix to relative paths, parses JSON, and throws typed errors.
81
+ *
82
+ * Usage:
83
+ * const client = await TilePushClient.create();
84
+ * const me = await client.get<{ appId, tenantName, tokenLabel }>("/me");
85
+ *
86
+ * All `pathSuffix` arguments are appended to `/api/cli/t/{appId}/`, so
87
+ * the client never has to think about tenant routing.
88
+ */
89
+ var TilePushApiError = class extends Error {
90
+ constructor(message, status, body) {
91
+ super(message);
92
+ this.status = status;
93
+ this.body = body;
94
+ this.name = "TilePushApiError";
95
+ }
96
+ };
97
+ var TilePushClient = class TilePushClient {
98
+ constructor(creds) {
99
+ this.creds = creds;
100
+ }
101
+ static async create() {
102
+ return new TilePushClient(await requireCredentials());
103
+ }
104
+ /** Like create() but returns null instead of throwing if no creds set. */
105
+ static async createOptional() {
106
+ const creds = await loadCredentials();
107
+ return creds ? new TilePushClient(creds) : null;
108
+ }
109
+ get appId() {
110
+ return this.creds.appId;
111
+ }
112
+ get apiUrl() {
113
+ return this.creds.apiUrl ?? "https://api.tile-push.app";
114
+ }
115
+ buildUrl(pathSuffix) {
116
+ const base = this.apiUrl.replace(/\/+$/, "");
117
+ const suffix = pathSuffix.startsWith("/") ? pathSuffix : `/${pathSuffix}`;
118
+ return `${base}/api/cli/t/${encodeURIComponent(this.creds.appId)}${suffix}`;
119
+ }
120
+ async request(method, pathSuffix, options = {}) {
121
+ const headers = {
122
+ Authorization: `Bearer ${this.creds.token}`,
123
+ ...options.headers
124
+ };
125
+ let body;
126
+ if (options.json !== void 0) {
127
+ body = JSON.stringify(options.json);
128
+ headers["Content-Type"] = options.contentType ?? "application/json";
129
+ } else if (options.body !== void 0) {
130
+ body = options.body;
131
+ if (options.contentType) headers["Content-Type"] = options.contentType;
132
+ }
133
+ const url = this.buildUrl(pathSuffix);
134
+ const response = await fetch(url, {
135
+ method,
136
+ headers,
137
+ body
138
+ });
139
+ if (!response.ok) {
140
+ const text = await response.text().catch(() => "");
141
+ let parsed = text;
142
+ try {
143
+ parsed = JSON.parse(text);
144
+ } catch {}
145
+ throw new TilePushApiError(`${method} ${pathSuffix} failed: ${typeof parsed === "object" && parsed && "error" in parsed ? String(parsed.error) : `HTTP ${response.status}`}`, response.status, parsed);
146
+ }
147
+ if (options.raw) return response;
148
+ if (response.status === 204) return void 0;
149
+ return await response.json();
150
+ }
151
+ get(pathSuffix, options) {
152
+ return this.request("GET", pathSuffix, options);
153
+ }
154
+ post(pathSuffix, options) {
155
+ return this.request("POST", pathSuffix, options);
156
+ }
157
+ patch(pathSuffix, options) {
158
+ return this.request("PATCH", pathSuffix, options);
159
+ }
160
+ delete(pathSuffix, options) {
161
+ return this.request("DELETE", pathSuffix, options);
162
+ }
163
+ };
164
+ //#endregion
165
+ Object.defineProperty(exports, "TilePushApiError", {
166
+ enumerable: true,
167
+ get: function() {
168
+ return TilePushApiError;
169
+ }
170
+ });
171
+ Object.defineProperty(exports, "TilePushClient", {
172
+ enumerable: true,
173
+ get: function() {
174
+ return TilePushClient;
175
+ }
176
+ });
177
+ Object.defineProperty(exports, "credentialsDiagnostic", {
178
+ enumerable: true,
179
+ get: function() {
180
+ return credentialsDiagnostic;
181
+ }
182
+ });
183
+ Object.defineProperty(exports, "loadCredentials", {
184
+ enumerable: true,
185
+ get: function() {
186
+ return loadCredentials;
187
+ }
188
+ });
189
+ Object.defineProperty(exports, "requireCredentials", {
190
+ enumerable: true,
191
+ get: function() {
192
+ return requireCredentials;
193
+ }
194
+ });
195
+ Object.defineProperty(exports, "saveCredentials", {
196
+ enumerable: true,
197
+ get: function() {
198
+ return saveCredentials;
199
+ }
200
+ });
@@ -0,0 +1,164 @@
1
+ import { mkdir, readFile, stat, writeFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import { homedir } from "node:os";
4
+ //#region src/auth/tokenStore.ts
5
+ const DEFAULT_API_URL = "https://ota.tile.dev";
6
+ const credentialsPath = () => join(homedir(), ".tile-push", "credentials.json");
7
+ const credentialsDir = () => join(homedir(), ".tile-push");
8
+ /**
9
+ * Resolve credentials with env precedence:
10
+ * 1. TILE_PUSH_APP_ID + TILE_PUSH_TOKEN env vars (preferred for CI)
11
+ * 2. ~/.tile-push/credentials.json (interactive / dev machines)
12
+ * 3. null if neither set
13
+ *
14
+ * TILE_PUSH_API_URL overrides the API base URL in either case.
15
+ */
16
+ const loadCredentials = async () => {
17
+ const envAppId = process.env.TILE_PUSH_APP_ID;
18
+ const envToken = process.env.TILE_PUSH_TOKEN;
19
+ const envApiUrl = process.env.TILE_PUSH_API_URL;
20
+ if (envAppId && envToken) return {
21
+ appId: envAppId,
22
+ token: envToken,
23
+ apiUrl: envApiUrl ?? DEFAULT_API_URL
24
+ };
25
+ try {
26
+ const raw = await readFile(credentialsPath(), "utf8");
27
+ const parsed = JSON.parse(raw);
28
+ if (!parsed.appId || !parsed.token) return null;
29
+ return {
30
+ appId: parsed.appId,
31
+ token: parsed.token,
32
+ apiUrl: envApiUrl ?? parsed.apiUrl ?? DEFAULT_API_URL
33
+ };
34
+ } catch (err) {
35
+ if (err.code === "ENOENT") return null;
36
+ throw err;
37
+ }
38
+ };
39
+ const saveCredentials = async (creds) => {
40
+ await mkdir(credentialsDir(), {
41
+ recursive: true,
42
+ mode: 448
43
+ });
44
+ await writeFile(credentialsPath(), JSON.stringify(creds, null, 2), { mode: 384 });
45
+ };
46
+ /**
47
+ * Throws a helpful message if no credentials are configured. Use this at the
48
+ * top of any command that needs server access.
49
+ */
50
+ const requireCredentials = async () => {
51
+ const creds = await loadCredentials();
52
+ if (!creds) throw new Error("No Tile Push credentials found. Run `tile-push init` to set up, or export TILE_PUSH_APP_ID and TILE_PUSH_TOKEN environment variables.");
53
+ return creds;
54
+ };
55
+ /** Test helper — confirms creds file exists and is 0600 (or just env vars). */
56
+ const credentialsDiagnostic = async () => {
57
+ if (process.env.TILE_PUSH_APP_ID && process.env.TILE_PUSH_TOKEN) return {
58
+ source: "env",
59
+ pathOrEnv: "TILE_PUSH_APP_ID / TILE_PUSH_TOKEN"
60
+ };
61
+ try {
62
+ const s = await stat(credentialsPath());
63
+ return {
64
+ source: "file",
65
+ pathOrEnv: credentialsPath(),
66
+ modeOk: (s.mode & 511) === 384
67
+ };
68
+ } catch {
69
+ return {
70
+ source: "none",
71
+ pathOrEnv: credentialsPath()
72
+ };
73
+ }
74
+ };
75
+ //#endregion
76
+ //#region src/auth/apiClient.ts
77
+ /**
78
+ * Thin fetch wrapper that injects the Bearer token, prepends the tenant
79
+ * prefix to relative paths, parses JSON, and throws typed errors.
80
+ *
81
+ * Usage:
82
+ * const client = await TilePushClient.create();
83
+ * const me = await client.get<{ appId, tenantName, tokenLabel }>("/me");
84
+ *
85
+ * All `pathSuffix` arguments are appended to `/api/cli/t/{appId}/`, so
86
+ * the client never has to think about tenant routing.
87
+ */
88
+ var TilePushApiError = class extends Error {
89
+ constructor(message, status, body) {
90
+ super(message);
91
+ this.status = status;
92
+ this.body = body;
93
+ this.name = "TilePushApiError";
94
+ }
95
+ };
96
+ var TilePushClient = class TilePushClient {
97
+ constructor(creds) {
98
+ this.creds = creds;
99
+ }
100
+ static async create() {
101
+ return new TilePushClient(await requireCredentials());
102
+ }
103
+ /** Like create() but returns null instead of throwing if no creds set. */
104
+ static async createOptional() {
105
+ const creds = await loadCredentials();
106
+ return creds ? new TilePushClient(creds) : null;
107
+ }
108
+ get appId() {
109
+ return this.creds.appId;
110
+ }
111
+ get apiUrl() {
112
+ return this.creds.apiUrl ?? "https://api.tile-push.app";
113
+ }
114
+ buildUrl(pathSuffix) {
115
+ const base = this.apiUrl.replace(/\/+$/, "");
116
+ const suffix = pathSuffix.startsWith("/") ? pathSuffix : `/${pathSuffix}`;
117
+ return `${base}/api/cli/t/${encodeURIComponent(this.creds.appId)}${suffix}`;
118
+ }
119
+ async request(method, pathSuffix, options = {}) {
120
+ const headers = {
121
+ Authorization: `Bearer ${this.creds.token}`,
122
+ ...options.headers
123
+ };
124
+ let body;
125
+ if (options.json !== void 0) {
126
+ body = JSON.stringify(options.json);
127
+ headers["Content-Type"] = options.contentType ?? "application/json";
128
+ } else if (options.body !== void 0) {
129
+ body = options.body;
130
+ if (options.contentType) headers["Content-Type"] = options.contentType;
131
+ }
132
+ const url = this.buildUrl(pathSuffix);
133
+ const response = await fetch(url, {
134
+ method,
135
+ headers,
136
+ body
137
+ });
138
+ if (!response.ok) {
139
+ const text = await response.text().catch(() => "");
140
+ let parsed = text;
141
+ try {
142
+ parsed = JSON.parse(text);
143
+ } catch {}
144
+ throw new TilePushApiError(`${method} ${pathSuffix} failed: ${typeof parsed === "object" && parsed && "error" in parsed ? String(parsed.error) : `HTTP ${response.status}`}`, response.status, parsed);
145
+ }
146
+ if (options.raw) return response;
147
+ if (response.status === 204) return void 0;
148
+ return await response.json();
149
+ }
150
+ get(pathSuffix, options) {
151
+ return this.request("GET", pathSuffix, options);
152
+ }
153
+ post(pathSuffix, options) {
154
+ return this.request("POST", pathSuffix, options);
155
+ }
156
+ patch(pathSuffix, options) {
157
+ return this.request("PATCH", pathSuffix, options);
158
+ }
159
+ delete(pathSuffix, options) {
160
+ return this.request("DELETE", pathSuffix, options);
161
+ }
162
+ };
163
+ //#endregion
164
+ export { requireCredentials as a, loadCredentials as i, TilePushClient as n, saveCredentials as o, credentialsDiagnostic as r, TilePushApiError as t };