@fewchurs/react 1.0.1 → 1.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/dist/index.mjs CHANGED
@@ -4,7 +4,7 @@
4
4
  import { createContext, useContext, useEffect, useMemo, useRef, useState } from "react";
5
5
 
6
6
  // src/client/version.ts
7
- var SDK_VERSION = "1.0.1";
7
+ var SDK_VERSION = "1.1.0";
8
8
 
9
9
  // src/client/constants.ts
10
10
  var SDK_HEADER = `react/${SDK_VERSION}`;
@@ -47,6 +47,8 @@ function errorFromResponse(status, body) {
47
47
  switch (code) {
48
48
  case "invalid_key":
49
49
  return { code: "invalid_key", status: 401, message };
50
+ case "wrong_app":
51
+ return { code: "invalid_key", status: 403, message };
50
52
  // missing_device_id is a client mistake the caller fixes the same way a bad field is fixed,
51
53
  // so it collapses into validation_failed rather than widening the public union.
52
54
  case "missing_device_id":
@@ -196,6 +198,7 @@ function createFewchursClient(options = {}) {
196
198
  const deviceId = getDeviceId();
197
199
  if (deviceId) result["X-Device-Id"] = deviceId;
198
200
  if (options.language) result["Accept-Language"] = options.language;
201
+ if (options.appId) result["X-Fewchurs-App-Id"] = options.appId;
199
202
  return result;
200
203
  }
201
204
  function url(path, query) {
@@ -234,7 +237,7 @@ function createFewchursClient(options = {}) {
234
237
  continue;
235
238
  }
236
239
  const failure = errorFromResponse(response.status, await readJson(response));
237
- warnAboutKey(failure.code);
240
+ warnAboutKey(failure);
238
241
  return { ok: false, error: failure };
239
242
  }
240
243
  return { ok: false, error: networkError() };
@@ -326,12 +329,12 @@ function messageOf(error) {
326
329
  return error instanceof Error ? error.message : "Network request failed.";
327
330
  }
328
331
  var warnedAboutKey = false;
329
- function warnAboutKey(code) {
330
- if (code !== "invalid_key" || warnedAboutKey) return;
332
+ function warnAboutKey(error) {
333
+ if (error.code !== "invalid_key" || warnedAboutKey) return;
331
334
  if (typeof process !== "undefined" && process.env?.NODE_ENV === "production") return;
332
335
  warnedAboutKey = true;
333
336
  console.error(
334
- "[fewchurs] The API key was rejected. Check FEWCHURS_API_KEY (server) or the apiKey passed to FewchursProvider, and that the key is active in your Fewchurs dashboard."
337
+ error.status === 403 ? `[fewchurs] ${error.message}` : "[fewchurs] The API key was rejected. Check FEWCHURS_API_KEY (server) or the apiKey passed to FewchursProvider, and that the key is active in your Fewchurs dashboard."
335
338
  );
336
339
  }
337
340