@khester/create-dynamics-app 1.0.8 → 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.
Files changed (107) hide show
  1. package/bin/create-dynamics-app.js +1 -1
  2. package/dist/index.js +140 -15
  3. package/dist/index.js.map +1 -1
  4. package/dist/utils/consultingHelpers.d.ts +13 -0
  5. package/dist/utils/consultingHelpers.d.ts.map +1 -0
  6. package/dist/utils/consultingHelpers.js +569 -0
  7. package/dist/utils/consultingHelpers.js.map +1 -0
  8. package/dist/utils/copyTemplate.d.ts.map +1 -1
  9. package/dist/utils/copyTemplate.js.map +1 -1
  10. package/dist/utils/initGit.d.ts.map +1 -1
  11. package/dist/utils/initGit.js.map +1 -1
  12. package/dist/utils/installDependencies.d.ts.map +1 -1
  13. package/dist/utils/installDependencies.js +3 -2
  14. package/dist/utils/installDependencies.js.map +1 -1
  15. package/dist/utils/updatePackageJson.d.ts +1 -1
  16. package/dist/utils/updatePackageJson.d.ts.map +1 -1
  17. package/dist/utils/updatePackageJson.js +11 -1
  18. package/dist/utils/updatePackageJson.js.map +1 -1
  19. package/package.json +1 -1
  20. package/templates/dynamics-365-starter/INTEGRATION_TEST_RESULTS.md +302 -0
  21. package/templates/dynamics-365-starter/PHASE_4_COMPLETION_SUMMARY.md +305 -0
  22. package/templates/dynamics-365-starter/README.md +566 -137
  23. package/templates/dynamics-365-starter/deployment/QUICKSTART-MAC.md +507 -0
  24. package/templates/dynamics-365-starter/deployment/QUICKSTART-WINDOWS.md +372 -0
  25. package/templates/dynamics-365-starter/deployment/README.md +484 -0
  26. package/templates/dynamics-365-starter/deployment/pipelines/README.md +375 -0
  27. package/templates/dynamics-365-starter/deployment/pipelines/azure-pipelines.yml +330 -0
  28. package/templates/dynamics-365-starter/deployment/pipelines/github-actions.yml +422 -0
  29. package/templates/dynamics-365-starter/deployment/pipelines/jenkins.groovy +636 -0
  30. package/templates/dynamics-365-starter/deployment/scripts/deploy.ps1 +417 -0
  31. package/templates/dynamics-365-starter/deployment/scripts/deploy.sh +582 -0
  32. package/templates/dynamics-365-starter/deployment/scripts/team-onboarding.ps1 +486 -0
  33. package/templates/dynamics-365-starter/deployment/scripts/team-onboarding.sh +567 -0
  34. package/templates/dynamics-365-starter/deployment/scripts/validate-setup.ps1 +703 -0
  35. package/templates/dynamics-365-starter/deployment/scripts/validate-setup.sh +671 -0
  36. package/templates/dynamics-365-starter/docs/ARCHITECTURE_OVERVIEW.md +506 -0
  37. package/templates/dynamics-365-starter/docs/BEST_PRACTICES.md +723 -0
  38. package/templates/dynamics-365-starter/docs/MIGRATION_GUIDE.md +447 -0
  39. package/templates/dynamics-365-starter/docs/team-standards/README.md +273 -0
  40. package/templates/dynamics-365-starter/docs/team-standards/client-onboarding.md +577 -0
  41. package/templates/dynamics-365-starter/docs/team-standards/code-review-checklist.md +359 -0
  42. package/templates/dynamics-365-starter/docs/team-standards/coding-standards.md +700 -0
  43. package/templates/dynamics-365-starter/docs/team-standards/cross-platform-team-guide.md +736 -0
  44. package/templates/dynamics-365-starter/docs/team-standards/development-workflows.md +727 -0
  45. package/templates/dynamics-365-starter/docs/troubleshooting/common-errors.md +758 -0
  46. package/templates/dynamics-365-starter/docs/troubleshooting/platform-specific-issues.md +878 -0
  47. package/templates/dynamics-365-starter/package.json +22 -1
  48. package/templates/dynamics-365-starter/public/index.html +8 -11
  49. package/templates/dynamics-365-starter/scripts/custom-build.js +255 -0
  50. package/templates/dynamics-365-starter/src/client-project-template/README.md +234 -0
  51. package/templates/dynamics-365-starter/src/client-project-template/config/client.template.json +114 -0
  52. package/templates/dynamics-365-starter/src/client-project-template/config/environments/template.json +186 -0
  53. package/templates/dynamics-365-starter/src/client-project-template/scripts/client-setup.js +667 -0
  54. package/templates/dynamics-365-starter/src/components/AccountForm.css +71 -0
  55. package/templates/dynamics-365-starter/src/components/AccountForm.tsx +541 -0
  56. package/templates/dynamics-365-starter/src/components/AccountManagement.css +86 -0
  57. package/templates/dynamics-365-starter/src/components/AccountManagement.tsx +370 -0
  58. package/templates/dynamics-365-starter/src/components/ContactForm.tsx +149 -63
  59. package/templates/dynamics-365-starter/src/components/ContactManagement.tsx +153 -63
  60. package/templates/dynamics-365-starter/src/components/Logging/LogDialog.tsx +291 -0
  61. package/templates/dynamics-365-starter/src/components/Logging/LoggingContext.tsx +166 -0
  62. package/templates/dynamics-365-starter/src/components/Logging/LoggingDebugPanel.css +192 -0
  63. package/templates/dynamics-365-starter/src/components/Logging/LoggingDebugPanel.tsx +177 -0
  64. package/templates/dynamics-365-starter/src/components/Logging/LoggingProvider.tsx +3 -0
  65. package/templates/dynamics-365-starter/src/components/Logging/logger.ts +193 -0
  66. package/templates/dynamics-365-starter/src/constants/account.ts +410 -0
  67. package/templates/dynamics-365-starter/src/constants/contact.ts +362 -0
  68. package/templates/dynamics-365-starter/src/examples/README.md +52 -0
  69. package/templates/dynamics-365-starter/src/examples/component-examples/opportunity-management.tsx +625 -0
  70. package/templates/dynamics-365-starter/src/examples/entity-examples/opportunity-model.ts +545 -0
  71. package/templates/dynamics-365-starter/src/examples/integration-examples/custom-pcf-wrapper.tsx +722 -0
  72. package/templates/dynamics-365-starter/src/examples/workflow-examples/sales-workflow.ts +662 -0
  73. package/templates/dynamics-365-starter/src/index.tsx +107 -19
  74. package/templates/dynamics-365-starter/src/models/Account.ts +480 -0
  75. package/templates/dynamics-365-starter/src/models/BaseEntity.ts +204 -0
  76. package/templates/dynamics-365-starter/src/models/Contact.ts +580 -0
  77. package/templates/dynamics-365-starter/src/page-templates/EntityDashboard.tsx +519 -0
  78. package/templates/dynamics-365-starter/src/page-templates/EntityDetailPage.tsx +456 -0
  79. package/templates/dynamics-365-starter/src/page-templates/EntityListPage.tsx +406 -0
  80. package/templates/dynamics-365-starter/src/page-templates/RelatedEntitiesPage.tsx +578 -0
  81. package/templates/dynamics-365-starter/src/page-templates/SearchPage.tsx +629 -0
  82. package/templates/dynamics-365-starter/src/pcf/ContactControlWrapper.tsx +75 -22
  83. package/templates/dynamics-365-starter/src/pcf/MultiEntityControlWrapper.tsx +205 -0
  84. package/templates/dynamics-365-starter/src/providers/DynamicsProvider.tsx +297 -80
  85. package/templates/dynamics-365-starter/src/services/MockApiService.ts +260 -0
  86. package/templates/dynamics-365-starter/src/services/ServiceFactory.ts +65 -0
  87. package/templates/dynamics-365-starter/src/services/XrmApiService.ts +213 -0
  88. package/templates/dynamics-365-starter/src/styles/index.css +74 -7
  89. package/templates/dynamics-365-starter/tools/entity-generator/index.js +168 -0
  90. package/templates/dynamics-365-starter/tools/entity-generator/templates/constants.template.ts +124 -0
  91. package/templates/dynamics-365-starter/tools/entity-generator/templates/form.template.css +283 -0
  92. package/templates/dynamics-365-starter/tools/entity-generator/templates/form.template.tsx +275 -0
  93. package/templates/dynamics-365-starter/tools/entity-generator/templates/management.template.css +204 -0
  94. package/templates/dynamics-365-starter/tools/entity-generator/templates/management.template.tsx +413 -0
  95. package/templates/dynamics-365-starter/tools/entity-generator/templates/model.template.ts +250 -0
  96. package/templates/dynamics-365-starter/tools/metadata-sync/d365-client.js +410 -0
  97. package/templates/dynamics-365-starter/tools/metadata-sync/index.js +512 -0
  98. package/templates/dynamics-365-starter/tools/metadata-sync/type-generator.js +675 -0
  99. package/templates/dynamics-365-starter/tsconfig.json +11 -8
  100. package/templates/dynamics-365-starter/webpack.config.js +8 -9
  101. package/templates/power-pages-starter/README.md +7 -1
  102. package/templates/power-pages-starter/public/index.html +8 -11
  103. package/templates/power-pages-starter/src/components/ContactForm.tsx +60 -41
  104. package/templates/power-pages-starter/src/index.tsx +3 -3
  105. package/templates/power-pages-starter/src/providers/PowerPagesProvider.tsx +46 -23
  106. package/templates/power-pages-starter/tsconfig.json +3 -9
  107. package/templates/power-pages-starter/webpack.config.js +8 -3
@@ -0,0 +1,406 @@
1
+ import React, { useState, useEffect, useCallback } from 'react';
2
+ import {
3
+ DetailsList,
4
+ IColumn,
5
+ SelectionMode,
6
+ CommandBar,
7
+ ICommandBarItemProps,
8
+ MessageBar,
9
+ MessageBarType,
10
+ Spinner,
11
+ SpinnerSize,
12
+ SearchBox,
13
+ Stack,
14
+ Text,
15
+ Panel,
16
+ PanelType,
17
+ DefaultButton,
18
+ PrimaryButton,
19
+ } from '@fluentui/react';
20
+ import { BaseEntity } from '../models/BaseEntity';
21
+ import { useDynamicsApi } from '../providers/DynamicsProvider';
22
+ import { Logger } from '../components/Logging/logger';
23
+
24
+ interface EntityListPageProps<T extends BaseEntity> {
25
+ title: string;
26
+ entityLogicalName: string;
27
+ entityClass: any; // Constructor for the entity
28
+ columns: IColumn[];
29
+ fetchXmlTemplate: string;
30
+ maxRecords?: number;
31
+ enableSearch?: boolean;
32
+ searchFields?: string[];
33
+ onItemSelected?: (item: T) => void;
34
+ onNew?: () => void;
35
+ onEdit?: (item: T) => void;
36
+ onDelete?: (item: T) => void;
37
+ customCommands?: ICommandBarItemProps[];
38
+ renderCustomPanel?: (
39
+ item: T | null,
40
+ onDismiss: () => void
41
+ ) => React.ReactNode;
42
+ }
43
+
44
+ /**
45
+ * Generic entity list page template for Dynamics 365
46
+ * Supports any entity with CRUD operations, search, and custom actions
47
+ */
48
+ export function EntityListPage<T extends BaseEntity>({
49
+ title,
50
+ entityLogicalName,
51
+ entityClass,
52
+ columns,
53
+ fetchXmlTemplate,
54
+ maxRecords = 100,
55
+ enableSearch = true,
56
+ searchFields = [],
57
+ onItemSelected,
58
+ onNew,
59
+ onEdit,
60
+ onDelete,
61
+ customCommands = [],
62
+ renderCustomPanel,
63
+ }: EntityListPageProps<T>) {
64
+ const { apiService } = useDynamicsApi();
65
+ const [entities, setEntities] = useState<T[]>([]);
66
+ const [filteredEntities, setFilteredEntities] = useState<T[]>([]);
67
+ const [loading, setLoading] = useState(true);
68
+ const [error, setError] = useState<string | null>(null);
69
+ const [selectedItem, setSelectedItem] = useState<T | null>(null);
70
+ const [searchQuery, setSearchQuery] = useState('');
71
+ const [showPanel, setShowPanel] = useState(false);
72
+ const [refreshTrigger, setRefreshTrigger] = useState(0);
73
+
74
+ // Load entities
75
+ const loadEntities = useCallback(async () => {
76
+ if (!apiService) {
77
+ setError('API service not available');
78
+ setLoading(false);
79
+ return;
80
+ }
81
+
82
+ try {
83
+ setLoading(true);
84
+ setError(null);
85
+ Logger.log(`Loading ${title}...`);
86
+
87
+ const topClause = maxRecords ? `top="${maxRecords}"` : '';
88
+ const fetchXml = fetchXmlTemplate.replace('{{topClause}}', topClause);
89
+
90
+ const result = await apiService.retrieveMultipleRecords(
91
+ entityLogicalName,
92
+ fetchXml
93
+ );
94
+ const entityInstances = (result.entities || []).map(
95
+ (data: any) => new entityClass(data)
96
+ );
97
+
98
+ setEntities(entityInstances);
99
+ setFilteredEntities(entityInstances);
100
+ Logger.log(`Loaded ${entityInstances.length} ${title}`);
101
+ } catch (err) {
102
+ const errorMessage =
103
+ err instanceof Error ? err.message : `Failed to load ${title}`;
104
+ setError(errorMessage);
105
+ Logger.error(`Error loading ${title}:`, 'EntityListPage', err);
106
+ } finally {
107
+ setLoading(false);
108
+ }
109
+ }, [
110
+ apiService,
111
+ title,
112
+ entityLogicalName,
113
+ fetchXmlTemplate,
114
+ maxRecords,
115
+ entityClass,
116
+ ]);
117
+
118
+ useEffect(() => {
119
+ loadEntities();
120
+ }, [loadEntities, refreshTrigger]);
121
+
122
+ // Handle search
123
+ useEffect(() => {
124
+ if (!enableSearch || !searchQuery.trim()) {
125
+ setFilteredEntities(entities);
126
+ return;
127
+ }
128
+
129
+ const filtered = entities.filter((entity) => {
130
+ if (searchFields.length === 0) {
131
+ // Search all string fields if no specific fields specified
132
+ return Object.values(entity).some(
133
+ (value) =>
134
+ typeof value === 'string' &&
135
+ value.toLowerCase().includes(searchQuery.toLowerCase())
136
+ );
137
+ }
138
+
139
+ // Search specific fields
140
+ return searchFields.some((field) => {
141
+ const value = (entity as any)[field];
142
+ return (
143
+ typeof value === 'string' &&
144
+ value.toLowerCase().includes(searchQuery.toLowerCase())
145
+ );
146
+ });
147
+ });
148
+
149
+ setFilteredEntities(filtered);
150
+ }, [entities, searchQuery, enableSearch, searchFields]);
151
+
152
+ // Handle item selection
153
+ const handleItemClick = (item: T) => {
154
+ setSelectedItem(item);
155
+ if (onItemSelected) {
156
+ onItemSelected(item);
157
+ }
158
+ };
159
+
160
+ // Handle refresh
161
+ const handleRefresh = () => {
162
+ setRefreshTrigger((prev) => prev + 1);
163
+ };
164
+
165
+ // Handle new entity
166
+ const handleNew = () => {
167
+ if (onNew) {
168
+ onNew();
169
+ } else if (renderCustomPanel) {
170
+ setSelectedItem(null);
171
+ setShowPanel(true);
172
+ }
173
+ };
174
+
175
+ // Handle edit entity
176
+ const handleEdit = () => {
177
+ if (selectedItem) {
178
+ if (onEdit) {
179
+ onEdit(selectedItem);
180
+ } else if (renderCustomPanel) {
181
+ setShowPanel(true);
182
+ }
183
+ }
184
+ };
185
+
186
+ // Handle delete entity
187
+ const handleDelete = async () => {
188
+ if (!selectedItem || !apiService) {
189
+ setError('Selected item or API service not available');
190
+ return;
191
+ }
192
+
193
+ if (onDelete) {
194
+ onDelete(selectedItem);
195
+ } else {
196
+ try {
197
+ // Use the entity class static method or apiService directly
198
+ if (typeof (selectedItem as any).delete === 'function') {
199
+ await (selectedItem as any).delete(apiService);
200
+ } else {
201
+ // Fallback to direct API call - need to get the entity ID
202
+ const entityId =
203
+ (selectedItem as any).id ||
204
+ (selectedItem as any)[`${entityLogicalName}id`];
205
+ if (entityId) {
206
+ await apiService.deleteRecord(entityLogicalName, entityId);
207
+ } else {
208
+ throw new Error('Could not determine entity ID for deletion');
209
+ }
210
+ }
211
+
212
+ setSelectedItem(null);
213
+ handleRefresh();
214
+ Logger.log(`${title} item deleted successfully`);
215
+ } catch (err) {
216
+ const errorMessage =
217
+ err instanceof Error ? err.message : `Failed to delete ${title} item`;
218
+ setError(errorMessage);
219
+ Logger.error(`Error deleting ${title} item:`, 'EntityListPage', err);
220
+ }
221
+ }
222
+ };
223
+
224
+ // Command bar items
225
+ const commandBarItems: ICommandBarItemProps[] = [
226
+ {
227
+ key: 'new',
228
+ text: `New ${title}`,
229
+ iconProps: { iconName: 'Add' },
230
+ onClick: handleNew,
231
+ },
232
+ {
233
+ key: 'edit',
234
+ text: 'Edit',
235
+ iconProps: { iconName: 'Edit' },
236
+ disabled: !selectedItem,
237
+ onClick: handleEdit,
238
+ },
239
+ {
240
+ key: 'delete',
241
+ text: 'Delete',
242
+ iconProps: { iconName: 'Delete' },
243
+ disabled: !selectedItem,
244
+ onClick: handleDelete,
245
+ },
246
+ {
247
+ key: 'refresh',
248
+ text: 'Refresh',
249
+ iconProps: { iconName: 'Refresh' },
250
+ onClick: handleRefresh,
251
+ },
252
+ ...customCommands,
253
+ ];
254
+
255
+ // Enhanced columns with click handlers
256
+ const enhancedColumns = columns.map((column) => ({
257
+ ...column,
258
+ onRender:
259
+ column.onRender ||
260
+ ((item: T) => {
261
+ const value = (item as any)[column.fieldName || ''];
262
+ if (column.key === columns[0].key) {
263
+ // Make first column clickable
264
+ return (
265
+ <span
266
+ style={{ color: '#0078d4', cursor: 'pointer', fontWeight: 500 }}
267
+ onClick={() => handleItemClick(item)}
268
+ >
269
+ {value || ''}
270
+ </span>
271
+ );
272
+ }
273
+ return <span>{value || ''}</span>;
274
+ }),
275
+ }));
276
+
277
+ return (
278
+ <div style={{ padding: '20px', maxWidth: '100%' }}>
279
+ <Stack tokens={{ childrenGap: 20 }}>
280
+ {/* Header */}
281
+ <Stack
282
+ horizontal
283
+ horizontalAlign="space-between"
284
+ verticalAlign="center"
285
+ >
286
+ <Text variant="xxLarge" style={{ fontWeight: 600, color: '#323130' }}>
287
+ {title}
288
+ </Text>
289
+ <Text variant="medium" style={{ color: '#605e5c' }}>
290
+ {filteredEntities.length} items
291
+ </Text>
292
+ </Stack>
293
+
294
+ {/* Error Message */}
295
+ {error && (
296
+ <MessageBar
297
+ messageBarType={MessageBarType.error}
298
+ onDismiss={() => setError(null)}
299
+ >
300
+ {error}
301
+ </MessageBar>
302
+ )}
303
+
304
+ {/* Search and Commands */}
305
+ <Stack horizontal tokens={{ childrenGap: 16 }}>
306
+ {enableSearch && (
307
+ <SearchBox
308
+ placeholder={`Search ${title}...`}
309
+ value={searchQuery}
310
+ onChange={(_, newValue) => setSearchQuery(newValue || '')}
311
+ style={{ maxWidth: 300 }}
312
+ />
313
+ )}
314
+ <CommandBar items={commandBarItems} style={{ flex: 1 }} />
315
+ </Stack>
316
+
317
+ {/* Content */}
318
+ {loading ? (
319
+ <div
320
+ style={{
321
+ display: 'flex',
322
+ justifyContent: 'center',
323
+ alignItems: 'center',
324
+ minHeight: 200,
325
+ flexDirection: 'column',
326
+ }}
327
+ >
328
+ <Spinner size={SpinnerSize.large} label={`Loading ${title}...`} />
329
+ </div>
330
+ ) : filteredEntities.length === 0 ? (
331
+ <div
332
+ style={{
333
+ textAlign: 'center',
334
+ padding: '40px 20px',
335
+ color: '#605e5c',
336
+ }}
337
+ >
338
+ <div style={{ fontSize: 48, marginBottom: 16, color: '#a19f9d' }}>
339
+ 📋
340
+ </div>
341
+ <Text
342
+ variant="large"
343
+ style={{ fontWeight: 600, marginBottom: 8, color: '#323130' }}
344
+ >
345
+ {searchQuery ? 'No matching items found' : `No ${title} found`}
346
+ </Text>
347
+ <Text variant="medium">
348
+ {searchQuery
349
+ ? `Try adjusting your search criteria`
350
+ : `Click "New ${title}" to get started`}
351
+ </Text>
352
+ </div>
353
+ ) : (
354
+ <DetailsList
355
+ items={filteredEntities}
356
+ columns={enhancedColumns}
357
+ setKey="set"
358
+ layoutMode={0}
359
+ selectionMode={SelectionMode.single}
360
+ onActiveItemChanged={setSelectedItem}
361
+ isHeaderVisible={true}
362
+ />
363
+ )}
364
+
365
+ {/* Custom Panel */}
366
+ {renderCustomPanel && (
367
+ <Panel
368
+ headerText={selectedItem ? `Edit ${title}` : `New ${title}`}
369
+ isOpen={showPanel}
370
+ onDismiss={() => setShowPanel(false)}
371
+ type={PanelType.medium}
372
+ closeButtonAriaLabel="Close"
373
+ >
374
+ {renderCustomPanel(selectedItem, () => {
375
+ setShowPanel(false);
376
+ handleRefresh();
377
+ })}
378
+ </Panel>
379
+ )}
380
+ </Stack>
381
+ </div>
382
+ );
383
+ }
384
+
385
+ // Helper function to create standard FetchXML template
386
+ export function createStandardFetchXml(
387
+ entityName: string,
388
+ attributes: string[],
389
+ orderBy?: string,
390
+ filter?: string
391
+ ): string {
392
+ const attributeElements = attributes
393
+ .map((attr) => `<attribute name="${attr}" />`)
394
+ .join('\n ');
395
+ const orderElement = orderBy ? `<order attribute="${orderBy}" />` : '';
396
+ const filterElement = filter ? `<filter>${filter}</filter>` : '';
397
+
398
+ return `
399
+ <fetch {{topClause}}>
400
+ <entity name="${entityName}">
401
+ ${attributeElements}
402
+ ${orderElement}
403
+ ${filterElement}
404
+ </entity>
405
+ </fetch>`;
406
+ }