@acms-subir/client 0.1.12 → 0.1.13

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/README.md CHANGED
@@ -25,7 +25,10 @@ const english = client.withLocale('en');
25
25
  hosting prefix. All methods return **unwrapped `data`**; `openapi()` returns the
26
26
  raw document. Every method accepts `locale` and `signal` in its options object.
27
27
  Locale is sent only for routes that support translations. `withLocale` shares
28
- the cache and transport configuration with the original client.
28
+ the cache and transport configuration with the original client. `site()` and
29
+ `pushTopics()` take a language since core 0.3.32; an older site rejects it, so
30
+ the client asks once more without it and gets the main language. Update the
31
+ site before shipping an app build with a newer client.
29
32
 
30
33
  | Method | Options / behavior |
31
34
  | --- | --- |
package/dist/index.js CHANGED
@@ -27,6 +27,8 @@ export const endpoints = {
27
27
  };
28
28
  // site: its legal links; pushTopics: topic names
29
29
  const localized = new Set(['home', 'page', 'content', 'contentById', 'search', 'events', 'site', 'pushTopics']);
30
+ // localized since core 0.3.32; older sites answer ?locale= with a 400, so ask them again without it
31
+ const lateLocalized = new Set(['site', 'pushTopics']);
30
32
  function uuid() {
31
33
  if (globalThis.crypto?.randomUUID)
32
34
  return globalThis.crypto.randomUUID();
@@ -98,7 +100,7 @@ export function createClient(options) {
98
100
  if (v !== undefined)
99
101
  url.searchParams.set(k, String(v));
100
102
  const locale = opts.locale ?? options.locale;
101
- if (localized.has(name) && locale !== undefined)
103
+ if (localized.has(name) && locale !== undefined && !extra.noLocale)
102
104
  url.searchParams.set('locale', locale);
103
105
  const controller = new AbortController();
104
106
  const abort = () => controller.abort(new AcmsError(0, 'aborted', 'Request aborted.', undefined, undefined, key));
@@ -178,6 +180,9 @@ export function createClient(options) {
178
180
  }
179
181
  throw new AcmsError(res.status, res.ok ? 'invalid_response' : 'http_error', `HTTP ${res.status}: expected a JSON response.`, retryAfter, undefined, key);
180
182
  }
183
+ // a site older than the client: unlocalized words beat no site info at all
184
+ if (res.status === 400 && lateLocalized.has(name) && url.searchParams.has('locale') && /locale/i.test(JSON.stringify(json?.error ?? '')))
185
+ return await request(name, opts, query, param, payload, key, { ...extra, noLocale: true });
181
186
  if (!res.ok)
182
187
  throw new AcmsError(res.status, json?.error?.code ?? 'http_error', json?.error?.message ?? `HTTP ${res.status}`, retryAfter, json?.error?.issues, key);
183
188
  if (name !== 'openapi' && (json?.version !== 1 || !Object.prototype.hasOwnProperty.call(json, 'data')))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acms-subir/client",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
4
4
  "description": "Typed, dependency-free client for the ACMS public mobile API.",
5
5
  "type": "module",
6
6
  "license": "MIT",