@hubspot/ui-extensions 0.13.0 → 0.13.1

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.
Files changed (28) hide show
  1. package/dist/__generated__/version.d.ts +2 -0
  2. package/dist/__generated__/version.js +4 -0
  3. package/dist/__tests__/crm/hooks/useAssociations.spec.js +51 -0
  4. package/dist/__tests__/crm/utils/fetchAssociations.spec.js +0 -10
  5. package/dist/__tests__/experimental/hooks/useCrmSearch.spec.d.ts +1 -0
  6. package/dist/__tests__/experimental/hooks/useCrmSearch.spec.js +586 -0
  7. package/dist/__tests__/experimental/hooks/utils/fetchCrmSearch.spec.d.ts +1 -0
  8. package/dist/__tests__/experimental/hooks/utils/fetchCrmSearch.spec.js +217 -0
  9. package/dist/crm/hooks/useAssociations.d.ts +1 -1
  10. package/dist/crm/hooks/useAssociations.js +14 -5
  11. package/dist/crm/utils/fetchAssociations.js +0 -3
  12. package/dist/experimental/hooks/useCrmSearch.d.ts +2 -0
  13. package/dist/experimental/hooks/useCrmSearch.js +206 -0
  14. package/dist/experimental/hooks/utils/fetchCrmSearch.d.ts +6 -0
  15. package/dist/experimental/hooks/utils/fetchCrmSearch.js +39 -0
  16. package/dist/experimental/index.d.ts +1 -0
  17. package/dist/experimental/index.js +1 -0
  18. package/dist/shared/types/components/table.d.ts +16 -0
  19. package/dist/shared/types/context.d.ts +1 -0
  20. package/dist/shared/types/experimental.d.ts +1 -1
  21. package/dist/shared/types/hooks.d.ts +72 -0
  22. package/dist/shared/types/hooks.js +1 -0
  23. package/dist/shared/types/worker-globals.d.ts +5 -0
  24. package/dist/testing/internal/mocks/mock-hooks.js +26 -0
  25. package/dist/testing/internal/types-internal.d.ts +2 -0
  26. package/dist/testing/types.d.ts +10 -0
  27. package/dist/utils/pagination.d.ts +0 -9
  28. package/package.json +2 -1
@@ -0,0 +1,72 @@
1
+ export interface PaginationResult {
2
+ hasNextPage: boolean;
3
+ hasPreviousPage: boolean;
4
+ currentPage: number;
5
+ pageSize: number;
6
+ nextPage: () => void;
7
+ previousPage: () => void;
8
+ reset: () => void;
9
+ }
10
+ export type FormattingOptions = {
11
+ date?: {
12
+ format?: string;
13
+ relative?: boolean;
14
+ };
15
+ dateTime?: {
16
+ format?: string;
17
+ relative?: boolean;
18
+ };
19
+ currency?: {
20
+ addSymbol?: boolean;
21
+ };
22
+ };
23
+ export type FetchHookOptions = {
24
+ propertiesToFormat?: string[] | 'all';
25
+ formattingOptions?: FormattingOptions;
26
+ };
27
+ export type CrmSearchFilter = {
28
+ propertyName: string;
29
+ operator: string;
30
+ value?: string | number | boolean;
31
+ values?: (string | number | boolean)[];
32
+ highValue?: string | number | boolean;
33
+ };
34
+ export type CrmSearchFilterGroup = {
35
+ filters: CrmSearchFilter[];
36
+ };
37
+ export type CrmSearchSort = {
38
+ propertyName: string;
39
+ direction: 'ASCENDING' | 'DESCENDING';
40
+ };
41
+ export type FetchCrmSearchRequest = {
42
+ objectType: string;
43
+ properties?: string[];
44
+ query?: string;
45
+ filterGroups?: CrmSearchFilterGroup[];
46
+ sorts?: CrmSearchSort[];
47
+ pageSize?: number;
48
+ after?: string;
49
+ };
50
+ export type CrmSearchResultItem = {
51
+ objectId: number;
52
+ properties: Record<string, string | null>;
53
+ };
54
+ export type CrmSearchResponse = {
55
+ results: CrmSearchResultItem[];
56
+ total: number;
57
+ hasMore: boolean;
58
+ after?: string;
59
+ };
60
+ export type UseCrmSearchOptions = {
61
+ propertiesToFormat?: 'all' | string[];
62
+ formattingOptions?: FetchHookOptions['formattingOptions'];
63
+ };
64
+ export interface UseCrmSearchResult {
65
+ results: CrmSearchResultItem[];
66
+ total: number;
67
+ error: Error | null;
68
+ isLoading: boolean;
69
+ isRefetching: boolean;
70
+ pagination: PaginationResult;
71
+ refetch: () => Promise<void>;
72
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,5 +1,6 @@
1
1
  import type { HubspotExtendFunction } from './extend.ts';
2
2
  import type { ExtensionPointApiActions, ExtensionPointApiContext, ExtensionPointFullApi, ExtensionPoints } from './extension-points.ts';
3
+ import type { FetchCrmSearchRequest, FetchHookOptions } from './hooks.ts';
3
4
  import type { Logger } from './logger.ts';
4
5
  import type { AppPageLocation } from './shared.ts';
5
6
  export interface WorkersApi {
@@ -19,6 +20,10 @@ export interface WorkersApi {
19
20
  * Hook added to worker globals so page router can access the current app page location at runtime.
20
21
  */
21
22
  useAppPageLocation: () => AppPageLocation;
23
+ /**
24
+ * Runner for the CRM search hook, proxies search requests to the host.
25
+ */
26
+ fetchCrmSearch: (request: FetchCrmSearchRequest, options?: FetchHookOptions) => Promise<Response>;
22
27
  }
23
28
  export interface WorkerGlobalsInternal {
24
29
  /**
@@ -67,6 +67,32 @@ export const createMockHooks = () => {
67
67
  },
68
68
  };
69
69
  },
70
+ useCrmSearch: (config) => {
71
+ const { properties: propertyNames } = config;
72
+ const properties = createFakeProperties(propertyNames);
73
+ return {
74
+ results: [
75
+ {
76
+ objectId: 456,
77
+ properties,
78
+ },
79
+ ],
80
+ total: 1,
81
+ error: null,
82
+ isLoading: false,
83
+ isRefetching: false,
84
+ refetch: async () => { },
85
+ pagination: {
86
+ hasNextPage: false,
87
+ hasPreviousPage: false,
88
+ currentPage: 1,
89
+ pageSize: 10,
90
+ nextPage: () => { },
91
+ previousPage: () => { },
92
+ reset: () => { },
93
+ },
94
+ };
95
+ },
70
96
  useExtensionContext: () => {
71
97
  const { mocks } = useRequiredMocksContext();
72
98
  return mocks.context;
@@ -1,5 +1,6 @@
1
1
  import type { RemoteComponent, RemoteFragment, RemoteRoot, RemoteText } from '@remote-ui/core';
2
2
  import type { useAssociations, useCrmProperties } from '../../crm/index.ts';
3
+ import type { useCrmSearch } from '../../experimental/hooks/useCrmSearch.ts';
3
4
  import type { useExtensionActions } from '../../hooks/useExtensionActions.tsx';
4
5
  import type { useExtensionApi } from '../../hooks/useExtensionApi.tsx';
5
6
  import type { useExtensionContext } from '../../hooks/useExtensionContext.tsx';
@@ -62,6 +63,7 @@ export type RenderedNodeInternal = RenderedElementNodeInternal | RenderedTextNod
62
63
  export interface RendererMockHooksInternal {
63
64
  useCrmProperties: typeof useCrmProperties;
64
65
  useAssociations: typeof useAssociations;
66
+ useCrmSearch: typeof useCrmSearch;
65
67
  useExtensionContext: typeof useExtensionContext;
66
68
  useExtensionActions: typeof useExtensionActions;
67
69
  useExtensionApi: typeof useExtensionApi;
@@ -1,5 +1,6 @@
1
1
  import type { SpyImpl } from 'tinyspy';
2
2
  import type { useAssociations, useCrmProperties } from '../crm/index.ts';
3
+ import type { useCrmSearch } from '../experimental/hooks/useCrmSearch.ts';
3
4
  import type { useExtensionActions } from '../hooks/useExtensionActions.tsx';
4
5
  import type { useExtensionApi } from '../hooks/useExtensionApi.tsx';
5
6
  import type { useExtensionContext } from '../hooks/useExtensionContext.tsx';
@@ -281,6 +282,15 @@ export interface RendererMocks<TExtensionPointLocation extends ExtensionPointLoc
281
282
  * information about spies and the supported API.
282
283
  */
283
284
  useAssociations: FunctionSpy<typeof useAssociations>;
285
+ /**
286
+ * A spy for the `useCrmSearch` hook function.
287
+ * The spy can be used to track the calls to the hook function and also control the
288
+ * return result of the hook function.
289
+ *
290
+ * See the [tinyspy](https://github.com/tiny-spy/tinyspy) library for more
291
+ * information about spies and the supported API.
292
+ */
293
+ useCrmSearch: FunctionSpy<typeof useCrmSearch>;
284
294
  /**
285
295
  * A spy for the `useExtensionContext` hook function.
286
296
  * The spy can be used to track the calls to the hook function and also control the
@@ -1,12 +1,3 @@
1
- export interface PaginationResult {
2
- hasNextPage: boolean;
3
- hasPreviousPage: boolean;
4
- currentPage: number;
5
- pageSize: number;
6
- nextPage: () => void;
7
- previousPage: () => void;
8
- reset: () => void;
9
- }
10
1
  export declare const DEFAULT_PAGE_SIZE = 10;
11
2
  /**
12
3
  * Calculate pagination flags based on current page and API hasMore flag
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/ui-extensions",
3
- "version": "0.13.0",
3
+ "version": "0.13.1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -77,6 +77,7 @@
77
77
  "format:check": "prettier --check . --ignore-path ../../.prettierignore",
78
78
  "lint": "eslint src/",
79
79
  "lint:fix": "eslint src/ --fix",
80
+ "generate": "node scripts/generate-version.js",
80
81
  "tsc": "tsc",
81
82
  "test": "vitest run && tsd",
82
83
  "test:coverage": "vitest run --coverage",