@cancia/toolbar 0.4.1 → 0.4.2

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/cancia.js CHANGED
@@ -68,6 +68,13 @@ function headers() {
68
68
  if (state.sessionToken) h["Authorization"] = `Bearer ${state.sessionToken}`;
69
69
  return h;
70
70
  }
71
+ function currentRoute() {
72
+ return typeof location !== "undefined" ? location.pathname : "";
73
+ }
74
+ function routeParam() {
75
+ const r = currentRoute();
76
+ return r ? `&route=${encodeURIComponent(r)}` : "";
77
+ }
71
78
  async function fetchContent() {
72
79
  const { apiUrl, site } = state.config;
73
80
  const res = await fetch(`${apiUrl}/api/cancia/content?site=${encodeURIComponent(site)}`, {
@@ -81,7 +88,8 @@ async function saveEntry(key, lang, value) {
81
88
  const res = await fetch(`${apiUrl}/api/cancia/save`, {
82
89
  method: "POST",
83
90
  headers: headers(),
84
- body: JSON.stringify({ key, lang, value, site })
91
+ // `route` lets the server invalidate this page's cache tag (034, invalidate mode).
92
+ body: JSON.stringify({ key, lang, value, site, route: currentRoute() })
85
93
  });
86
94
  if (!res.ok) throw new Error(`Cancia: failed to save (${res.status})`);
87
95
  }
@@ -157,7 +165,7 @@ async function fetchTranslations(listName) {
157
165
  async function createListEntry(listName, data, locale, id) {
158
166
  const { apiUrl, site } = state.config;
159
167
  const res = await fetch(
160
- `${apiUrl}/api/cancia/lists/${encodeURIComponent(listName)}?site=${encodeURIComponent(site)}${localeParam(locale)}`,
168
+ `${apiUrl}/api/cancia/lists/${encodeURIComponent(listName)}?site=${encodeURIComponent(site)}${localeParam(locale)}${routeParam()}`,
161
169
  { method: "POST", headers: headers(), body: JSON.stringify({ data, id }) }
162
170
  );
163
171
  if (!res.ok) {
@@ -170,7 +178,7 @@ async function createListEntry(listName, data, locale, id) {
170
178
  async function updateListEntry(listName, id, data, rev, locale) {
171
179
  const { apiUrl, site } = state.config;
172
180
  const res = await fetch(
173
- `${apiUrl}/api/cancia/lists/${encodeURIComponent(listName)}/${encodeURIComponent(id)}?site=${encodeURIComponent(site)}${localeParam(locale)}`,
181
+ `${apiUrl}/api/cancia/lists/${encodeURIComponent(listName)}/${encodeURIComponent(id)}?site=${encodeURIComponent(site)}${localeParam(locale)}${routeParam()}`,
174
182
  { method: "PATCH", headers: headers(), body: JSON.stringify({ data, _rev: rev }) }
175
183
  );
176
184
  if (!res.ok) {
@@ -184,7 +192,7 @@ async function updateListEntry(listName, id, data, rev, locale) {
184
192
  async function deleteListEntry(listName, id, locale) {
185
193
  const { apiUrl, site } = state.config;
186
194
  const res = await fetch(
187
- `${apiUrl}/api/cancia/lists/${encodeURIComponent(listName)}/${encodeURIComponent(id)}?site=${encodeURIComponent(site)}${localeParam(locale)}`,
195
+ `${apiUrl}/api/cancia/lists/${encodeURIComponent(listName)}/${encodeURIComponent(id)}?site=${encodeURIComponent(site)}${localeParam(locale)}${routeParam()}`,
188
196
  { method: "DELETE", headers: headers() }
189
197
  );
190
198
  if (!res.ok) throw new Error(`Cancia: failed to delete entry (${res.status})`);
@@ -192,7 +200,7 @@ async function deleteListEntry(listName, id, locale) {
192
200
  async function reorderList(listName, ids) {
193
201
  const { apiUrl, site } = state.config;
194
202
  const res = await fetch(
195
- `${apiUrl}/api/cancia/lists/${encodeURIComponent(listName)}/reorder?site=${encodeURIComponent(site)}`,
203
+ `${apiUrl}/api/cancia/lists/${encodeURIComponent(listName)}/reorder?site=${encodeURIComponent(site)}${routeParam()}`,
196
204
  { method: "POST", headers: headers(), body: JSON.stringify({ ids }) }
197
205
  );
198
206
  if (!res.ok) throw new Error(`Cancia: failed to reorder list (${res.status})`);