@nyaruka/temba-components 0.170.1 → 0.172.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.
@@ -0,0 +1,28 @@
1
+ const UNHYPHENATED_UUID = /^[0-9a-f]{32}$/;
2
+
3
+ /**
4
+ * Canonicalizes a uuid the way the server does, so a reference embedded in a
5
+ * flow definition in some other form (uppercase, braced, unhyphenated) still
6
+ * matches the normalized uuid the endpoint echoes back.
7
+ *
8
+ * This lives in its own module with no imports so both the store's asset cache
9
+ * and the flow definition rewriter can share it - they sit on opposite sides of
10
+ * a `Store -> AppState -> dependencies` chain, so a shared helper in either one
11
+ * would close an import cycle.
12
+ */
13
+ export const normalizeUuid = (uuid: string): string => {
14
+ const trimmed = uuid
15
+ .trim()
16
+ .replace(/^\{|\}$/g, '')
17
+ .toLowerCase();
18
+ if (UNHYPHENATED_UUID.test(trimmed)) {
19
+ return [
20
+ trimmed.slice(0, 8),
21
+ trimmed.slice(8, 12),
22
+ trimmed.slice(12, 16),
23
+ trimmed.slice(16, 20),
24
+ trimmed.slice(20)
25
+ ].join('-');
26
+ }
27
+ return trimmed;
28
+ };
package/src/utils.ts CHANGED
@@ -47,8 +47,8 @@ interface KeyedAsset {
47
47
  key?: string;
48
48
  }
49
49
 
50
- interface AssetPage {
51
- assets: Asset[];
50
+ interface AssetPage<T = Asset> {
51
+ assets: T[];
52
52
  next: string;
53
53
  }
54
54
 
@@ -233,8 +233,10 @@ export const fetchResults = async (
233
233
  return results;
234
234
  };
235
235
 
236
- export const getAssetPage = (url: string): Promise<AssetPage> => {
237
- return new Promise<AssetPage>((resolve, reject) => {
236
+ /** Fetches one page of an asset endpoint. The caller names the shape it
237
+ * expects, since these endpoints serve everything from groups to shortcuts. */
238
+ export const getAssetPage = <T = Asset>(url: string): Promise<AssetPage<T>> => {
239
+ return new Promise<AssetPage<T>>((resolve, reject) => {
238
240
  getUrl(url)
239
241
  .then((response: WebResponse) => {
240
242
  if (response.status >= 200 && response.status < 300) {
@@ -250,15 +252,15 @@ export const getAssetPage = (url: string): Promise<AssetPage> => {
250
252
  });
251
253
  };
252
254
 
253
- export const getAssets = async (url: string): Promise<Asset[]> => {
255
+ export const getAssets = async <T = Asset>(url: string): Promise<T[]> => {
254
256
  if (!url) {
255
- return new Promise<Asset[]>((resolve) => resolve([]));
257
+ return new Promise<T[]>((resolve) => resolve([]));
256
258
  }
257
259
 
258
- let assets: Asset[] = [];
260
+ let assets: T[] = [];
259
261
  let pageUrl = url;
260
262
  while (pageUrl) {
261
- const assetPage = await getAssetPage(pageUrl);
263
+ const assetPage = await getAssetPage<T>(pageUrl);
262
264
  if (assetPage.assets) {
263
265
  assets = assets.concat(assetPage.assets);
264
266
  pageUrl = assetPage.next;
package/temba-modules.ts CHANGED
@@ -95,6 +95,7 @@ import { CardStack } from './src/layout/CardStack';
95
95
  import { CardLayout } from './src/layout/CardLayout';
96
96
  import { Simulator } from './src/simulator/Simulator';
97
97
  import { FlowSearch } from './src/flow/FlowSearch';
98
+ import { TicketSearch } from './src/live/TicketSearch';
98
99
  import { IssuesWindow } from './src/flow/IssuesWindow';
99
100
  import { RevisionsWindow } from './src/flow/RevisionsWindow';
100
101
  import { AutoTranslate } from './src/flow/AutoTranslate';
@@ -205,6 +206,7 @@ addCustomElement('temba-floating-tab', FloatingTab);
205
206
  addCustomElement('temba-floating-window', FloatingWindow);
206
207
  addCustomElement('temba-simulator', Simulator);
207
208
  addCustomElement('temba-flow-search', FlowSearch);
209
+ addCustomElement('temba-ticket-search', TicketSearch);
208
210
  addCustomElement('temba-issues-window', IssuesWindow);
209
211
  addCustomElement('temba-revisions-window', RevisionsWindow);
210
212
  addCustomElement('temba-auto-translate', AutoTranslate);