codeapp-js 0.3.0 → 1.0.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 (158) hide show
  1. package/AI/codeapp.agent.md +105 -0
  2. package/AI/skills/connections/SKILL.md +47 -0
  3. package/AI/skills/dataverse/SKILL.md +99 -0
  4. package/AI/skills/environment-variables/SKILL.md +89 -0
  5. package/AI/skills/frontend-design/SKILL.md +34 -0
  6. package/AI/skills/jira/SKILL.md +81 -0
  7. package/AI/skills/office365-groups/SKILL.md +61 -0
  8. package/AI/skills/office365-outlook/SKILL.md +52 -0
  9. package/AI/skills/office365-users/SKILL.md +78 -0
  10. package/AI/skills/sharepoint/SKILL.md +77 -0
  11. package/AI/skills/sql/SKILL.md +85 -0
  12. package/AI/skills/start/SKILL.md +46 -0
  13. package/AI/skills/teams/SKILL.md +55 -0
  14. package/{examples/combined demo/.power/schemas/office365groups/office365groups.Schema.json → codeApp/.power/schemas/office365groups/office365groups.Schema.json} +2203 -2203
  15. package/codeApp/dist/codeapp.js +95 -1792
  16. package/codeApp/dist/connectors/azureKeyvault.js +459 -0
  17. package/codeApp/dist/connectors/jira.js +1247 -0
  18. package/codeApp/dist/connectors/office365groups.js +642 -0
  19. package/codeApp/dist/connectors/office365users.js +513 -0
  20. package/codeApp/dist/connectors/outlook.js +1393 -0
  21. package/{dev files/sharepoint.js → codeApp/dist/connectors/sharepoint.js} +239 -112
  22. package/codeApp/dist/connectors/sql.js +149 -0
  23. package/codeApp/dist/connectors/teams.js +280 -0
  24. package/codeApp/dist/power-apps-data.js +16 -2
  25. package/examples/{kanban → apps/kanban}/dist/dataverse.js +94 -94
  26. package/examples/{kanban → apps/kanban}/dist/environmentVar.js +55 -55
  27. package/examples/{kanban → apps/kanban}/dist/index.css +605 -605
  28. package/examples/{kanban → apps/kanban}/dist/index.html +21 -21
  29. package/examples/{kanban → apps/kanban}/dist/index.js +860 -860
  30. package/examples/{kanban → apps/kanban}/dist/office365groups.js +97 -97
  31. package/examples/apps/kanban/dist/office365users.js +451 -0
  32. package/examples/{kanban → apps/kanban}/dist/outlook.js +162 -162
  33. package/examples/{planning Poker/dist/power-apps-data.js → apps/kanban/dist/power-apps-data.js} +2953 -2953
  34. package/examples/{kanban → apps/kanban}/dist/sharepoint.js +435 -339
  35. package/examples/{kanban → apps/kanban}/power.config.json +35 -35
  36. package/examples/{planning Poker → apps/planning Poker}/additional files/customizations (tables).xml +6428 -6428
  37. package/examples/{planning Poker → apps/planning Poker}/additional files/dataverse-tables.json +165 -165
  38. package/examples/{planning Poker → apps/planning Poker}/additional files/readme.md +122 -122
  39. package/examples/{planning Poker → apps/planning Poker}/dist/dataverse.js +78 -78
  40. package/examples/{planning Poker → apps/planning Poker}/dist/index.html +198 -198
  41. package/examples/{planning Poker → apps/planning Poker}/dist/index.js +954 -954
  42. package/examples/{todo/dist/power-apps-data.js → apps/planning Poker/dist/power-apps-data.js } +2953 -2953
  43. package/examples/{planning Poker → apps/planning Poker}/dist/styles.css +815 -815
  44. package/examples/{planning Poker → apps/planning Poker}/power.config.json +50 -50
  45. package/examples/{outlook Demo2 → apps/solution explorer}/dist/codeapp.js +9 -245
  46. package/examples/apps/solution explorer/dist/index.html +80 -0
  47. package/examples/apps/solution explorer/dist/index.js +735 -0
  48. package/examples/apps/solution explorer/dist/styles.css +571 -0
  49. package/examples/apps/solution explorer/power.config.json +151 -0
  50. package/examples/{todo → apps/todo}/dist/dataverse.js +64 -64
  51. package/examples/{todo → apps/todo}/dist/index.html +75 -75
  52. package/examples/{todo → apps/todo}/dist/index.js +8 -8
  53. package/examples/{kanban → apps/todo}/dist/power-apps-data.js +2953 -2953
  54. package/examples/{todo → apps/todo}/dist/renderer.js +375 -375
  55. package/examples/{todo → apps/todo}/dist/styles.css +691 -691
  56. package/examples/{todo → apps/todo}/power.config.json +34 -34
  57. package/examples/combined demo/.power/schemas/appschemas/dataSourcesInfo.ts +6275 -7830
  58. package/examples/combined demo/.power/schemas/jira/jira.Schema.json +6903 -0
  59. package/examples/combined demo/.power/schemas/keyvault/keyvault.Schema.json +1600 -0
  60. package/examples/combined demo/.power/schemas/teams/teams.Schema.json +11112 -0
  61. package/examples/combined demo/dist/codeapp.js +394 -1098
  62. package/examples/{outlook Demo2/OutlookDemo_1_0_0_1.zip → combined demo/dist/icon-512.png} +0 -0
  63. package/examples/combined demo/dist/index.html +29 -511
  64. package/examples/combined demo/dist/index.js +490 -470
  65. package/examples/combined demo/dist/office365users.js +513 -0
  66. package/examples/combined demo/dist/outlook.js +1393 -0
  67. package/examples/combined demo/dist/power-apps-data.js +3079 -3006
  68. package/examples/combined demo/dist/styles.css +483 -0
  69. package/examples/combined demo/power.config.json +33 -42
  70. package/examples/combined demo/src/generated/index.ts +12 -14
  71. package/examples/combined demo/src/generated/models/AzureKeyVaultModel.ts +107 -0
  72. package/examples/combined demo/src/generated/models/JiraModel.ts +501 -0
  73. package/examples/combined demo/src/generated/services/AzureKeyVaultService.ts +257 -0
  74. package/examples/combined demo/src/generated/services/JiraService.ts +1124 -0
  75. package/examples/dataverse Demo/dist/codeapp.js +394 -1085
  76. package/examples/dataverse Demo/dist/icon-512.png +0 -0
  77. package/examples/dataverse Demo/dist/index.html +146 -54
  78. package/examples/dataverse Demo/dist/index.js +693 -83
  79. package/examples/dataverse Demo/dist/power-apps-data.js +3079 -2911
  80. package/examples/dataverse Demo/dist/styles.css +528 -0
  81. package/examples/dataverse Demo/power.config.json +41 -35
  82. package/examples/dataverse Demo/readme.md +79 -79
  83. package/examples/groups Demo/dist/codeapp.js +394 -1085
  84. package/examples/groups Demo/dist/icon-512.png +0 -0
  85. package/examples/groups Demo/dist/index.html +21 -25
  86. package/examples/groups Demo/dist/index.js +304 -113
  87. package/examples/groups Demo/dist/office365groups.js +642 -0
  88. package/examples/groups Demo/dist/power-apps-data.js +3079 -2911
  89. package/examples/groups Demo/dist/styles.css +509 -0
  90. package/examples/groups Demo/power.config.json +25 -25
  91. package/examples/myProfile/dist/codeapp.js +398 -0
  92. package/examples/myProfile/dist/index.html +21 -184
  93. package/examples/myProfile/dist/index.js +324 -141
  94. package/examples/myProfile/dist/office365users.js +517 -169
  95. package/examples/myProfile/dist/power-apps-data.js +3080 -2953
  96. package/examples/myProfile/dist/styles.css +458 -0
  97. package/examples/myProfile/power.config.json +24 -23
  98. package/examples/outlook Demo/dist/codeapp.js +394 -1085
  99. package/examples/outlook Demo/dist/index.html +150 -35
  100. package/examples/outlook Demo/dist/index.js +516 -170
  101. package/examples/outlook Demo/dist/outlook.js +1393 -121
  102. package/examples/outlook Demo/dist/power-apps-data.js +3079 -2911
  103. package/examples/outlook Demo/dist/styles.css +408 -84
  104. package/examples/outlook Demo/power.config.json +24 -23
  105. package/examples/outlook Demo/readme.md +92 -82
  106. package/examples/sharePoint Demo/dist/codeapp.js +394 -1085
  107. package/examples/sharePoint Demo/dist/icon-512.png +0 -0
  108. package/examples/sharePoint Demo/dist/index.html +22 -255
  109. package/examples/sharePoint Demo/dist/index.js +899 -262
  110. package/examples/sharePoint Demo/dist/power-apps-data.js +3079 -2911
  111. package/examples/sharePoint Demo/dist/sharepoint.js +466 -0
  112. package/examples/sharePoint Demo/dist/styles.css +587 -0
  113. package/examples/sharePoint Demo/power.config.json +23 -22
  114. package/package.json +1 -1
  115. package/readme.md +465 -76
  116. package/.vscode/settings.json +0 -6
  117. package/dev files/customConnector.js +0 -98
  118. package/dev files/dataverse.js +0 -120
  119. package/dev files/environmentVar.js +0 -55
  120. package/dev files/office365groups.js +0 -65
  121. package/dev files/office365users.js +0 -169
  122. package/dev files/outlook.js +0 -330
  123. package/dev files/power-apps-data.js +0 -2952
  124. package/examples/combined demo/.power/schemas/office365/office365.Schema.json +0 -21098
  125. package/examples/combined demo/.power/schemas/office365users/office365users.Schema.json +0 -2094
  126. package/examples/kanban/agent/decision-log.md +0 -9
  127. package/examples/kanban/agent/mockup-01-editorial-glass.html +0 -159
  128. package/examples/kanban/agent/mockup-02-dark-rail.html +0 -147
  129. package/examples/kanban/agent/mockup-03-paper-grid.html +0 -114
  130. package/examples/kanban/agent/mockup-04-neon-minimal.html +0 -141
  131. package/examples/kanban/agent/mockup-05-mono-architect.html +0 -119
  132. package/examples/kanban/dist/office365users.js +0 -169
  133. package/examples/kanban/src/generated/index.ts +0 -14
  134. package/examples/kanban/src/generated/models/Office365GroupsModel.ts +0 -363
  135. package/examples/kanban/src/generated/models/Office365OutlookModel.ts +0 -2046
  136. package/examples/kanban/src/generated/models/Office365UsersModel.ts +0 -254
  137. package/examples/kanban/src/generated/services/Office365GroupsService.ts +0 -326
  138. package/examples/kanban/src/generated/services/Office365OutlookService.ts +0 -2476
  139. package/examples/kanban/src/generated/services/Office365UsersService.ts +0 -358
  140. package/examples/outlook Demo2/agent/decision-log.md +0 -7
  141. package/examples/outlook Demo2/dist/index.html +0 -98
  142. package/examples/outlook Demo2/dist/index.js +0 -272
  143. package/examples/outlook Demo2/dist/styles.css +0 -639
  144. package/examples/outlook Demo2/power.config.json +0 -23
  145. package/examples/planning Poker/.vscode/settings.json +0 -5
  146. package/examples/sharePoint Demo/agent/decision-log.md +0 -17
  147. /package/examples/{outlook Demo2 → apps/kanban}/src/generated/index.ts +0 -0
  148. /package/examples/{outlook Demo2 → apps/kanban}/src/generated/models/Office365GroupsModel.ts +0 -0
  149. /package/examples/{outlook Demo2 → apps/kanban}/src/generated/models/Office365OutlookModel.ts +0 -0
  150. /package/examples/{outlook Demo2 → apps/kanban}/src/generated/models/Office365UsersModel.ts +0 -0
  151. /package/examples/{outlook Demo2 → apps/kanban}/src/generated/services/Office365GroupsService.ts +0 -0
  152. /package/examples/{outlook Demo2 → apps/kanban}/src/generated/services/Office365OutlookService.ts +0 -0
  153. /package/examples/{outlook Demo2 → apps/kanban}/src/generated/services/Office365UsersService.ts +0 -0
  154. /package/examples/{planning Poker → apps/planning Poker}/additional files/AgilePoker_1_0_0_1.zip +0 -0
  155. /package/examples/{planning Poker → apps/planning Poker}/additional files/PokerTables_1_0_0_1.zip +0 -0
  156. /package/examples/{outlook Demo2 → apps/solution explorer}/dist/icon-512.png +0 -0
  157. /package/examples/{outlook Demo2 → apps/solution explorer}/dist/power-apps-data.js +0 -0
  158. /package/examples/{todo → apps/todo}/dist/icon192.png +0 -0
@@ -0,0 +1,735 @@
1
+
2
+ import { initDataSources, registerTable, listItems, getItem, callUnboundAction, enableDebugger } from './codeapp.js';
3
+
4
+ enableDebugger();
5
+
6
+ /* ── Data Sources (tables used by this app) ─────────────────── */
7
+ function dsEntry(sPrimaryKey) {
8
+ return { tableId: '', version: '', primaryKey: sPrimaryKey, dataSourceType: 'Dataverse', apis: {} };
9
+ }
10
+ initDataSources({
11
+ solutions: dsEntry('solutionid'),
12
+ solutioncomponents: dsEntry('solutioncomponentid'),
13
+ entities: dsEntry('entityid'),
14
+ roles: dsEntry('roleid'),
15
+ workflows: dsEntry('workflowid'),
16
+ reports: dsEntry('reportid'),
17
+ connectionroles: dsEntry('connectionroleid'),
18
+ systemforms: dsEntry('formid'),
19
+ savedqueryvisualizations: dsEntry('savedqueryvisualizationid'),
20
+ savedqueries: dsEntry('savedqueryid'),
21
+ webresourceset: dsEntry('webresourceid'),
22
+ plugintypes: dsEntry('plugintypeid'),
23
+ pluginassemblies: dsEntry('pluginassemblyid'),
24
+ sdkmessageprocessingsteps: dsEntry('sdkmessageprocessingstepid'),
25
+ customcontrols: dsEntry('customcontrolid'),
26
+ appmodules: dsEntry('appmoduleid'),
27
+ canvasapps: dsEntry('canvasappid'),
28
+ sitemaps: dsEntry('sitemapid'),
29
+ connectionreferences: dsEntry('connectionreferenceid'),
30
+ environmentvariabledefinitions: dsEntry('environmentvariabledefinitionid'),
31
+ environmentvariablevalues: dsEntry('environmentvariablevalueid'),
32
+ fxexpressions: dsEntry('fxexpressionid'),
33
+ systemusers: dsEntry('systemuserid'),
34
+ teams: dsEntry('teamid')
35
+ });
36
+
37
+ /* ── Well-known Component Types (hardcoded table mappings) ─── */
38
+ var oComponentTypes = {
39
+ 1: { sLabel: 'Entity', sTable: 'entities', sPrimaryKey: 'entityid' },
40
+ 2: { sLabel: 'Attribute', sTable: null },
41
+ 9: { sLabel: 'Option Set', sTable: null },
42
+ 10: { sLabel: 'Entity Relationship', sTable: null },
43
+ 20: { sLabel: 'Security Role', sTable: 'roles', sPrimaryKey: 'roleid' },
44
+ 24: { sLabel: 'Form', sTable: 'systemforms', sPrimaryKey: 'formid' },
45
+ 26: { sLabel: 'View', sTable: 'savedqueries', sPrimaryKey: 'savedqueryid' },
46
+ 29: { sLabel: 'Workflow', sTable: 'workflows', sPrimaryKey: 'workflowid' },
47
+ 31: { sLabel: 'Report', sTable: 'reports', sPrimaryKey: 'reportid' },
48
+ 59: { sLabel: 'Chart', sTable: 'savedqueryvisualizations', sPrimaryKey: 'savedqueryvisualizationid' },
49
+ 60: { sLabel: 'System Form', sTable: 'systemforms', sPrimaryKey: 'formid' },
50
+ 61: { sLabel: 'Web Resource', sTable: 'webresourceset', sPrimaryKey: 'webresourceid' },
51
+ 62: { sLabel: 'Site Map', sTable: 'sitemaps', sPrimaryKey: 'sitemapid' },
52
+ 63: { sLabel: 'Connection Role', sTable: 'connectionroles', sPrimaryKey: 'connectionroleid' },
53
+ 66: { sLabel: 'Custom Control', sTable: 'customcontrols', sPrimaryKey: 'customcontrolid' },
54
+ 70: { sLabel: 'Model-driven App', sTable: 'appmodules', sPrimaryKey: 'appmoduleid' },
55
+ 71: { sLabel: 'Plugin Type', sTable: 'plugintypes', sPrimaryKey: 'plugintypeid' },
56
+ 72: { sLabel: 'Plugin Assembly', sTable: 'pluginassemblies', sPrimaryKey: 'pluginassemblyid' },
57
+ 80: { sLabel: 'Model-driven App', sTable: 'appmodules', sPrimaryKey: 'appmoduleid' },
58
+ 91: { sLabel: 'SDK Message Step', sTable: 'sdkmessageprocessingsteps', sPrimaryKey: 'sdkmessageprocessingstepid' },
59
+ 300: { sLabel: 'Canvas App', sTable: 'canvasapps', sPrimaryKey: 'canvasappid' }
60
+ };
61
+
62
+ /* ── Dynamic Entity Cache (componenttype → discovered metadata) */
63
+ var oEntityCache = {};
64
+
65
+ /* ── State ──────────────────────────────────────────────────── */
66
+ var aSolutions = [];
67
+ var sActiveId = '';
68
+
69
+ /* ── DOM References ─────────────────────────────────────────── */
70
+ const eSolList = document.getElementById('solList');
71
+ const eSolCount = document.getElementById('solCount');
72
+ const eDetailPanel = document.getElementById('detailPanel');
73
+ const eSearchInput = document.getElementById('searchInput');
74
+ const eManagedFilter = document.getElementById('managedFilter');
75
+
76
+ /* ── Register Core Tables ───────────────────────────────────── */
77
+ function registerCoreTables() {
78
+ registerTable('solutions', 'solutionid');
79
+ registerTable('solutioncomponents', 'solutioncomponentid');
80
+ registerTable('entities', 'entityid');
81
+
82
+ registerTable('systemusers', 'systemuserid');
83
+ registerTable('teams', 'teamid');
84
+
85
+ /* Register well-known component tables */
86
+ var oRegistered = {};
87
+ Object.keys(oComponentTypes).forEach(function(sKey) {
88
+ var oDef = oComponentTypes[sKey];
89
+ if (oDef.sTable && !oRegistered[oDef.sTable]) {
90
+ registerTable(oDef.sTable, oDef.sPrimaryKey);
91
+ oRegistered[oDef.sTable] = true;
92
+ }
93
+ });
94
+ }
95
+
96
+ /* ── Lookup entity metadata for an unknown componenttype ────── */
97
+ async function lookupEntityType(iType) {
98
+ if (oEntityCache[iType]) return oEntityCache[iType];
99
+ var oResult = await listItems('entities', 'entityid', {
100
+ filter: 'objecttypecode eq ' + iType,
101
+ select: ['logicalcollectionname', 'logicalname', 'originallocalizedname'],
102
+ top: 1
103
+ });
104
+ var aEntities = oResult.entities || [];
105
+ if (aEntities.length > 0) {
106
+ var oEnt = aEntities[0];
107
+ oEntityCache[iType] = {
108
+ sLabel: oEnt.originallocalizedname || oEnt.logicalname,
109
+ sTable: oEnt.logicalcollectionname,
110
+ sPrimaryKey: oEnt.logicalname + 'id'
111
+ };
112
+ return oEntityCache[iType];
113
+ }
114
+ return null;
115
+ }
116
+
117
+ /* ── Extract display name from a record ─────────────────────── */
118
+ var aNameFields = ['name', 'displayname', 'friendlyname', 'sitemapname', 'fullname', 'title', 'subject'];
119
+ function extractName(oRecord) {
120
+ for (var i = 0; i < aNameFields.length; i++) {
121
+ if (oRecord[aNameFields[i]]) return oRecord[aNameFields[i]];
122
+ }
123
+ /* Fallback: first string value that is not a guid, url, or odata field */
124
+ var sGuidPattern = new RegExp('^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$', 'i');
125
+ var aKeys = Object.keys(oRecord);
126
+ for (var j = 0; j < aKeys.length; j++) {
127
+ var sKey = aKeys[j];
128
+ if (sKey.indexOf('@') === 0) continue;
129
+ if (sKey.indexOf('_') === 0) continue;
130
+ var val = oRecord[sKey];
131
+ if (typeof val === 'string' && val.length > 0 && val.length < 200 && !sGuidPattern.test(val) && val.indexOf('http') !== 0 && val.indexOf('/') === -1) return val;
132
+ }
133
+ return '';
134
+ }
135
+
136
+ /* ── Load Solutions ─────────────────────────────────────────── */
137
+ async function loadSolutions() {
138
+ var oResult = await listItems('solutions', 'solutionid', {
139
+ select: ['solutionid', 'friendlyname', 'uniquename', 'version', 'ismanaged', 'modifiedon', 'description'],
140
+ orderBy: ['friendlyname asc'],
141
+ top: 5000
142
+ });
143
+ return oResult.entities || [];
144
+ }
145
+
146
+ /* ── Load Solution Components ───────────────────────────────── */
147
+ async function loadComponents(sSolutionId) {
148
+ var oResult = await listItems('solutioncomponents', 'solutioncomponentid', {
149
+ filter: '_solutionid_value eq ' + sSolutionId,
150
+ select: ['solutioncomponentid', 'componenttype', 'objectid'],
151
+ top: 5000
152
+ });
153
+ return oResult.entities || [];
154
+ }
155
+
156
+ /* ── Resolve a single component name ─────────────────────────── */
157
+ function resolveOneComponent(oItem, oDef) {
158
+ /* Entity (type 1) does not support Retrieve — must use filter */
159
+ if (oItem.iType === 1) {
160
+ return listItems('entities', 'entityid', {
161
+ filter: 'entityid eq ' + oItem.sObjectId,
162
+ select: ['name', 'logicalname', 'originallocalizedname'],
163
+ top: 1
164
+ })
165
+ .then(function(oResult) {
166
+ var aRows = oResult.entities || [];
167
+ if (aRows.length > 0) {
168
+ oItem.sName = aRows[0].originallocalizedname || aRows[0].name || aRows[0].logicalname || oItem.sObjectId;
169
+ } else {
170
+ oItem.sName = oItem.sObjectId;
171
+ }
172
+ })
173
+ .catch(function() {
174
+ oItem.sName = oItem.sObjectId;
175
+ });
176
+ }
177
+ /* All other types — direct retrieve by ID */
178
+ return getItem(oDef.sTable, oDef.sPrimaryKey, oItem.sObjectId)
179
+ .then(function(oRecord) {
180
+ oItem.sName = extractName(oRecord) || oItem.sObjectId;
181
+ })
182
+ .catch(function() {
183
+ oItem.sName = (oDef.sLabel || oDef.sTable) + ' (' + oItem.sObjectId.substring(0, 8) + '…)';
184
+ });
185
+ }
186
+
187
+ /* ── Resolve Component Names ────────────────────────────────── */
188
+ async function resolveComponentNames(aComponents) {
189
+ var aResolved = aComponents.map(function(oComp) {
190
+ return {
191
+ iType: oComp.componenttype,
192
+ sObjectId: oComp.objectid,
193
+ sName: ''
194
+ };
195
+ });
196
+
197
+ /* Discover unknown types via entity metadata */
198
+ var oUnknown = {};
199
+ aResolved.forEach(function(oItem) {
200
+ if (!oComponentTypes[oItem.iType] && !oUnknown[oItem.iType]) {
201
+ oUnknown[oItem.iType] = true;
202
+ }
203
+ });
204
+ var aLookups = Object.keys(oUnknown).map(function(sKey) {
205
+ return lookupEntityType(parseInt(sKey)).catch(function() { return null; });
206
+ });
207
+ await Promise.allSettled(aLookups);
208
+
209
+ /* Register dynamically discovered tables */
210
+ var oRegistered = {};
211
+ Object.keys(oEntityCache).forEach(function(sKey) {
212
+ var oDef = oEntityCache[sKey];
213
+ if (oDef && oDef.sTable && !oRegistered[oDef.sTable]) {
214
+ registerTable(oDef.sTable, oDef.sPrimaryKey);
215
+ oRegistered[oDef.sTable] = true;
216
+ }
217
+ });
218
+
219
+ /* Build lookup promises */
220
+ var aPromises = aResolved.map(function(oItem) {
221
+ var oDef = oComponentTypes[oItem.iType] || oEntityCache[oItem.iType];
222
+ if (!oDef || !oDef.sTable) {
223
+ oItem.sName = oItem.sObjectId;
224
+ return Promise.resolve();
225
+ }
226
+ return resolveOneComponent(oItem, oDef);
227
+ });
228
+
229
+ await Promise.allSettled(aPromises);
230
+ return aResolved;
231
+ }
232
+
233
+ /* ── Format Date ────────────────────────────────────────────── */
234
+ function formatDate(sISO) {
235
+ if (!sISO) return '';
236
+ var d = new Date(sISO);
237
+ return d.toLocaleDateString('en-GB', { day: '2-digit', month: 'short', year: 'numeric' });
238
+ }
239
+
240
+ /* ── Render Solutions List ──────────────────────────────────── */
241
+ function renderSolutions(aFiltered) {
242
+ eSolList.innerHTML = '';
243
+ eSolCount.textContent = aFiltered.length;
244
+
245
+ if (aFiltered.length === 0) {
246
+ eSolList.innerHTML = '<div class="loading-msg">No solutions found</div>';
247
+ return;
248
+ }
249
+
250
+ aFiltered.forEach(function(oSol, i) {
251
+ var eItem = document.createElement('div');
252
+ eItem.className = 'sol-item' + (oSol.ismanaged ? ' managed' : '');
253
+ if (oSol.solutionid === sActiveId) {
254
+ eItem.classList.add('active');
255
+ }
256
+ eItem.style.animationDelay = (i * 0.04) + 's';
257
+ eItem.innerHTML =
258
+ '<div class="sol-indicator"></div>' +
259
+ '<div>' +
260
+ '<div class="sol-name">' + oSol.friendlyname + '</div>' +
261
+ '<div class="sol-version">' + oSol.uniquename + ' &middot; v' + oSol.version + '</div>' +
262
+ '</div>' +
263
+ '<div>' +
264
+ '<div class="sol-managed">' + (oSol.ismanaged ? 'Managed' : 'Unmanaged') + '</div>' +
265
+ '<div class="sol-modified">' + formatDate(oSol.modifiedon) + '</div>' +
266
+ '</div>';
267
+ eItem.addEventListener('click', function() {
268
+ sActiveId = oSol.solutionid;
269
+ renderSolutions(aFiltered);
270
+ showDetail(oSol);
271
+ });
272
+ eSolList.appendChild(eItem);
273
+ });
274
+ }
275
+
276
+ /* ── Show Detail Panel ──────────────────────────────────────── */
277
+ async function showDetail(oSol) {
278
+ eDetailPanel.innerHTML =
279
+ '<div class="detail-header">' +
280
+ '<h2>' + oSol.friendlyname + '</h2>' +
281
+ '<div class="detail-meta">' +
282
+ '<span>Unique Name: <b>' + oSol.uniquename + '</b></span>' +
283
+ '<span>Version: <b>' + oSol.version + '</b></span>' +
284
+ '<span>' + (oSol.ismanaged ? 'Managed' : 'Unmanaged') + '</span>' +
285
+ '</div>' +
286
+ '</div>' +
287
+ (oSol.description ? '<div class="detail-desc">' + oSol.description + '</div>' : '') +
288
+ '<div class="comp-bar"><span>Components</span><span class="comp-total">Loading…</span></div>';
289
+
290
+ try {
291
+ var aRawComps = await loadComponents(oSol.solutionid);
292
+ var aComps = await resolveComponentNames(aRawComps);
293
+
294
+ /* Group by type label */
295
+ var oGroups = {};
296
+ aComps.forEach(function(oComp) {
297
+ var oDef = oComponentTypes[oComp.iType] || oEntityCache[oComp.iType];
298
+ var sLabel = oDef ? oDef.sLabel : 'Type ' + oComp.iType;
299
+ if (!oGroups[sLabel]) {
300
+ oGroups[sLabel] = [];
301
+ }
302
+ oGroups[sLabel].push(oComp);
303
+ });
304
+
305
+ /* Build components HTML */
306
+ var sCompHTML =
307
+ '<div class="comp-bar">' +
308
+ '<span>Components</span>' +
309
+ '<span class="comp-total">' + aComps.length + ' items</span>' +
310
+ '</div>' +
311
+ '<div class="comp-groups">';
312
+
313
+ var iGroupIdx = 0;
314
+ Object.keys(oGroups).sort().forEach(function(sType) {
315
+ sCompHTML +=
316
+ '<div class="comp-group" style="animation-delay:' + (iGroupIdx * 0.08) + 's">' +
317
+ '<div class="comp-group-title">' + sType + ' (' + oGroups[sType].length + ')</div>';
318
+ oGroups[sType].forEach(function(oComp) {
319
+ var sEscName = oComp.sName.replace(/'/g, "\\'").replace(/"/g, '&quot;');
320
+ sCompHTML +=
321
+ '<div class="comp-row" onclick="window._openShareModal(\'' + sEscName + '\', \'' + oComp.sObjectId + '\', ' + oComp.iType + ')">' +
322
+ '<span class="comp-row-name">' + oComp.sName + '</span>' +
323
+ '<span class="comp-row-id">' + oComp.sObjectId + '</span>' +
324
+ '</div>';
325
+ });
326
+ sCompHTML += '</div>';
327
+ iGroupIdx++;
328
+ });
329
+ sCompHTML += '</div>';
330
+
331
+ /* Replace only the components section */
332
+ eDetailPanel.innerHTML =
333
+ '<div class="detail-header">' +
334
+ '<h2>' + oSol.friendlyname + '</h2>' +
335
+ '<div class="detail-meta">' +
336
+ '<span>Unique Name: <b>' + oSol.uniquename + '</b></span>' +
337
+ '<span>Version: <b>' + oSol.version + '</b></span>' +
338
+ '<span>' + (oSol.ismanaged ? 'Managed' : 'Unmanaged') + '</span>' +
339
+ '</div>' +
340
+ '</div>' +
341
+ (oSol.description ? '<div class="detail-desc">' + oSol.description + '</div>' : '') +
342
+ sCompHTML;
343
+
344
+ } catch (oErr) {
345
+ eDetailPanel.querySelector('.comp-bar .comp-total').textContent = 'Error loading components';
346
+ }
347
+ }
348
+
349
+ /* ── Filter Solutions ───────────────────────────────────────── */
350
+ function filterSolutions(sQuery, sManagedValue) {
351
+ return aSolutions.filter(function(oSol) {
352
+ var bMatchesSearch = !sQuery ||
353
+ oSol.friendlyname.toLowerCase().indexOf(sQuery) !== -1 ||
354
+ oSol.uniquename.toLowerCase().indexOf(sQuery) !== -1;
355
+ var bMatchesManaged = sManagedValue === 'all' ||
356
+ (sManagedValue === 'managed' && oSol.ismanaged) ||
357
+ (sManagedValue === 'unmanaged' && !oSol.ismanaged);
358
+ return bMatchesSearch && bMatchesManaged;
359
+ });
360
+ }
361
+
362
+ /* ── Search & Filter Handlers ──────────────────────────────── */
363
+ function applyFilters() {
364
+ var sQuery = eSearchInput.value.toLowerCase();
365
+ var sManagedValue = eManagedFilter.value;
366
+ renderSolutions(filterSolutions(sQuery, sManagedValue));
367
+ }
368
+ eSearchInput.addEventListener('input', applyFilters);
369
+ eManagedFilter.addEventListener('change', applyFilters);
370
+
371
+ /* ── Boot ────────────────────────────────────────────────────── */
372
+ async function boot() {
373
+ try {
374
+ registerCoreTables();
375
+ aSolutions = await loadSolutions();
376
+ renderSolutions(aSolutions);
377
+ } catch (oErr) {
378
+ eSolList.innerHTML = '<div class="error-msg">Failed to load solutions: ' + oErr.message + '</div>';
379
+ }
380
+ }
381
+
382
+ boot();
383
+
384
+ /* ══════════════════════════════════════════════════════════════
385
+ Share Component Modal
386
+ ══════════════════════════════════════════════════════════════ */
387
+
388
+ /* ── Share Modal State ──────────────────────────────────────── */
389
+ let oShareContext = { sComponentName: '', sObjectId: '', iType: 0 };
390
+ let sShareTab = 'user';
391
+ let aShareSelected = []; // { sId, sName, sType ('user'|'team'), sDetail }
392
+ let iShareSearchTimer = 0;
393
+
394
+ /* ── Share Modal DOM References ─────────────────────────────── */
395
+ const eShareBackdrop = document.getElementById('shareBackdrop');
396
+ const eShareModalTitle = document.getElementById('shareModalTitle');
397
+ const eShareCloseBtn = document.getElementById('shareCloseBtn');
398
+ const eShareSearchInput = document.getElementById('shareSearchInput');
399
+ const eShareResults = document.getElementById('shareResults');
400
+ const eShareSelectedSection = document.getElementById('shareSelectedSection');
401
+ const eShareSelectedList = document.getElementById('shareSelectedList');
402
+ const eShareCancelBtn = document.getElementById('shareCancelBtn');
403
+ const eShareConfirmBtn = document.getElementById('shareConfirmBtn');
404
+ const aShareTabs = document.querySelectorAll('.share-tab');
405
+
406
+ /* ── Open Share Modal ───────────────────────────────────────── */
407
+ function openShareModal(sComponentName, sObjectId, iType) {
408
+ oShareContext = { sComponentName, sObjectId, iType };
409
+ aShareSelected = [];
410
+ sShareTab = 'user';
411
+
412
+ eShareModalTitle.textContent = 'Share — ' + sComponentName;
413
+ eShareSearchInput.value = '';
414
+ eShareSearchInput.placeholder = 'Search users…';
415
+ eShareResults.innerHTML = '<div class="share-empty-msg">Type to search</div>';
416
+ renderShareSelected();
417
+ updateShareTabs();
418
+
419
+ eShareBackdrop.classList.add('open');
420
+ setTimeout(() => eShareSearchInput.focus(), 100);
421
+ }
422
+
423
+ /* ── Close Share Modal ──────────────────────────────────────── */
424
+ function closeShareModal() {
425
+ eShareBackdrop.classList.remove('open');
426
+ oShareContext = { sComponentName: '', sObjectId: '', iType: 0 };
427
+ aShareSelected = [];
428
+ }
429
+
430
+ /* ── Tab Switching ──────────────────────────────────────────── */
431
+ function updateShareTabs() {
432
+ aShareTabs.forEach((eTab) => {
433
+ if (eTab.dataset.tab === sShareTab) {
434
+ eTab.classList.add('active');
435
+ } else {
436
+ eTab.classList.remove('active');
437
+ }
438
+ });
439
+ }
440
+
441
+ aShareTabs.forEach((eTab) => {
442
+ eTab.addEventListener('click', () => {
443
+ sShareTab = eTab.dataset.tab;
444
+ updateShareTabs();
445
+ eShareSearchInput.value = '';
446
+ eShareSearchInput.placeholder = sShareTab === 'user' ? 'Search users…' : 'Search teams…';
447
+ eShareResults.innerHTML = '<div class="share-empty-msg">Type to search</div>';
448
+ eShareSearchInput.focus();
449
+ });
450
+ });
451
+
452
+ /* ── Search Users (Dataverse systemusers) ───────────────────── */
453
+ async function searchUsers(sQuery) {
454
+ try {
455
+ const oResult = await listItems('systemusers', 'systemuserid', {
456
+ filter: "contains(fullname,'" + sQuery.replace(/'/g, "''") + "') and isdisabled eq false",
457
+ select: ['systemuserid', 'fullname', 'internalemailaddress', 'jobtitle'],
458
+ orderBy: ['fullname asc'],
459
+ top: 20
460
+ });
461
+ return (oResult.entities || []).map((oUser) => ({
462
+ sId: oUser.systemuserid,
463
+ sName: oUser.fullname || 'Unknown',
464
+ sDetail: oUser.internalemailaddress || oUser.jobtitle || '',
465
+ sType: 'user'
466
+ }));
467
+ } catch (oErr) {
468
+ console.error('User search failed:', oErr);
469
+ return [];
470
+ }
471
+ }
472
+
473
+ /* ── Search Teams (Dataverse teams) ─────────────────────────── */
474
+ async function searchTeams(sQuery) {
475
+ try {
476
+ const oResult = await listItems('teams', 'teamid', {
477
+ filter: "contains(name,'" + sQuery.replace(/'/g, "''") + "')",
478
+ select: ['teamid', 'name', 'description', 'teamtype'],
479
+ orderBy: ['name asc'],
480
+ top: 20
481
+ });
482
+ const aTeamTypeLabels = { 0: 'Owner', 1: 'Access', 2: 'AAD Security', 3: 'AAD Office' };
483
+ return (oResult.entities || []).map((oTeam) => ({
484
+ sId: oTeam.teamid,
485
+ sName: oTeam.name || 'Unknown',
486
+ sDetail: aTeamTypeLabels[oTeam.teamtype] || ('Type ' + oTeam.teamtype),
487
+ sType: 'team'
488
+ }));
489
+ } catch (oErr) {
490
+ console.error('Team search failed:', oErr);
491
+ return [];
492
+ }
493
+ }
494
+
495
+ /* ── Render Search Results ──────────────────────────────────── */
496
+ function renderShareResults(aResults) {
497
+ if (!aResults || aResults.length === 0) {
498
+ eShareResults.innerHTML = '<div class="share-empty-msg">No results found</div>';
499
+ return;
500
+ }
501
+
502
+ eShareResults.innerHTML = '';
503
+ aResults.forEach((oItem) => {
504
+ const bSelected = aShareSelected.some((s) => s.sId === oItem.sId);
505
+ const eRow = document.createElement('div');
506
+ eRow.className = 'share-result-item' + (bSelected ? ' selected' : '');
507
+
508
+ const sInitials = getInitials(oItem.sName);
509
+ const sAvatarClass = oItem.sType === 'team' ? 'share-result-avatar team-avatar' : 'share-result-avatar';
510
+
511
+ eRow.innerHTML =
512
+ '<div class="' + sAvatarClass + '">' + sInitials + '</div>' +
513
+ '<div class="share-result-info">' +
514
+ '<div class="share-result-name">' + escapeHtml(oItem.sName) + '</div>' +
515
+ '<div class="share-result-detail">' + escapeHtml(oItem.sDetail) + '</div>' +
516
+ '</div>' +
517
+ '<div class="share-result-check">' + (bSelected ? '&#10003;' : '') + '</div>';
518
+
519
+ eRow.addEventListener('click', () => {
520
+ toggleShareSelection(oItem);
521
+ renderShareResults(aResults);
522
+ });
523
+
524
+ eShareResults.appendChild(eRow);
525
+ });
526
+ }
527
+
528
+ /* ── Toggle Selection ───────────────────────────────────────── */
529
+ function toggleShareSelection(oItem) {
530
+ const iIdx = aShareSelected.findIndex((s) => s.sId === oItem.sId);
531
+ if (iIdx >= 0) {
532
+ aShareSelected.splice(iIdx, 1);
533
+ } else {
534
+ aShareSelected.push(oItem);
535
+ }
536
+ renderShareSelected();
537
+ }
538
+
539
+ /* ── Render Selected Chips ──────────────────────────────────── */
540
+ function renderShareSelected() {
541
+ if (aShareSelected.length === 0) {
542
+ eShareSelectedSection.style.display = 'none';
543
+ eShareConfirmBtn.disabled = true;
544
+ return;
545
+ }
546
+
547
+ eShareSelectedSection.style.display = '';
548
+ eShareConfirmBtn.disabled = false;
549
+
550
+ eShareSelectedList.innerHTML = '';
551
+ aShareSelected.forEach((oItem) => {
552
+ const eChip = document.createElement('span');
553
+ eChip.className = 'share-selected-chip';
554
+ eChip.innerHTML =
555
+ escapeHtml(oItem.sName) +
556
+ '<span class="share-chip-remove" data-id="' + oItem.sId + '">&times;</span>';
557
+ eShareSelectedList.appendChild(eChip);
558
+ });
559
+
560
+ eShareSelectedList.querySelectorAll('.share-chip-remove').forEach((eBtn) => {
561
+ eBtn.addEventListener('click', (e) => {
562
+ e.stopPropagation();
563
+ const sRemoveId = eBtn.dataset.id;
564
+ aShareSelected = aShareSelected.filter((s) => s.sId !== sRemoveId);
565
+ renderShareSelected();
566
+ /* Re-render results if visible */
567
+ const aCurrentRows = eShareResults.querySelectorAll('.share-result-item');
568
+ if (aCurrentRows.length > 0) {
569
+ const sCurrentQuery = eShareSearchInput.value.trim();
570
+ if (sCurrentQuery.length >= 2) {
571
+ doShareSearch(sCurrentQuery);
572
+ }
573
+ }
574
+ });
575
+ });
576
+ }
577
+
578
+ /* ── Debounced Search ───────────────────────────────────────── */
579
+ eShareSearchInput.addEventListener('input', () => {
580
+ clearTimeout(iShareSearchTimer);
581
+ const sQuery = eShareSearchInput.value.trim();
582
+ if (sQuery.length < 2) {
583
+ eShareResults.innerHTML = '<div class="share-empty-msg">Type to search</div>';
584
+ return;
585
+ }
586
+ eShareResults.innerHTML = '<div class="share-loading">Searching</div>';
587
+ iShareSearchTimer = setTimeout(() => doShareSearch(sQuery), 350);
588
+ });
589
+
590
+ async function doShareSearch(sQuery) {
591
+ let aResults = [];
592
+ if (sShareTab === 'user') {
593
+ aResults = await searchUsers(sQuery);
594
+ } else {
595
+ aResults = await searchTeams(sQuery);
596
+ }
597
+ renderShareResults(aResults);
598
+ }
599
+
600
+ /* ── Resolve entity logical name from component type ────────── */
601
+ const oTypeToLogicalName = {
602
+ 1: 'entity',
603
+ 20: 'role',
604
+ 24: 'systemform',
605
+ 26: 'savedquery',
606
+ 29: 'workflow',
607
+ 31: 'report',
608
+ 59: 'savedqueryvisualization',
609
+ 60: 'systemform',
610
+ 61: 'webresource',
611
+ 62: 'sitemap',
612
+ 63: 'connectionrole',
613
+ 66: 'customcontrol',
614
+ 70: 'appmodule',
615
+ 71: 'plugintype',
616
+ 72: 'pluginassembly',
617
+ 80: 'appmodule',
618
+ 91: 'sdkmessageprocessingstep',
619
+ 300: 'canvasapp'
620
+ };
621
+
622
+ function getLogicalNameForType(iType) {
623
+ if (oTypeToLogicalName[iType]) return oTypeToLogicalName[iType];
624
+ /* Try the entity cache for dynamically discovered types */
625
+ if (oEntityCache[iType] && oEntityCache[iType].sTable) {
626
+ /* logicalname is singular; sTable is the collection name */
627
+ const sDef = oEntityCache[iType];
628
+ /* sPrimaryKey is usually "<logicalname>id", so strip "id" */
629
+ if (sDef.sPrimaryKey && sDef.sPrimaryKey.endsWith('id')) {
630
+ return sDef.sPrimaryKey.slice(0, -2);
631
+ }
632
+ return sDef.sTable;
633
+ }
634
+ return null;
635
+ }
636
+
637
+ /* ── Call GrantAccess for one principal ──────────────────────── */
638
+ async function grantAccess(sTargetLogicalName, sTargetId, sPrincipalType, sPrincipalId) {
639
+ const sPrincipalLogical = sPrincipalType === 'user' ? 'systemuser' : 'team';
640
+ const sPrincipalKeyField = sPrincipalType === 'user' ? 'systemuserid' : 'teamid';
641
+
642
+ const oParams = {
643
+ Target: {
644
+ [sTargetLogicalName + 'id']: sTargetId,
645
+ '@odata.type': 'Microsoft.Dynamics.CRM.' + sTargetLogicalName
646
+ },
647
+ PrincipalAccess: {
648
+ Principal: {
649
+ [sPrincipalKeyField]: sPrincipalId,
650
+ '@odata.type': 'Microsoft.Dynamics.CRM.' + sPrincipalLogical
651
+ },
652
+ AccessMask: 'ReadAccess,WriteAccess,AppendAccess,AppendToAccess,ShareAccess,AssignAccess'
653
+ }
654
+ };
655
+
656
+ return await callUnboundAction('', '', 'GrantAccess', oParams);
657
+ }
658
+
659
+ /* ── Confirm Share ──────────────────────────────────────────── */
660
+ eShareConfirmBtn.addEventListener('click', async () => {
661
+ if (aShareSelected.length === 0) return;
662
+
663
+ const sLogicalName = getLogicalNameForType(oShareContext.iType);
664
+ if (!sLogicalName) {
665
+ showShareToast('Error: Cannot share this component type (type ' + oShareContext.iType + ')');
666
+ return;
667
+ }
668
+
669
+ /* Disable button while processing */
670
+ eShareConfirmBtn.disabled = true;
671
+ eShareConfirmBtn.textContent = 'Sharing…';
672
+
673
+ const aResults = await Promise.allSettled(
674
+ aShareSelected.map((oItem) =>
675
+ grantAccess(sLogicalName, oShareContext.sObjectId, oItem.sType, oItem.sId)
676
+ )
677
+ );
678
+
679
+ const aFailed = aResults.filter((r) => r.status === 'rejected');
680
+ const aSucceeded = aResults.filter((r) => r.status === 'fulfilled');
681
+
682
+ if (aFailed.length === 0) {
683
+ const sNames = aShareSelected.map((s) => s.sName).join(', ');
684
+ showShareToast('Shared "' + oShareContext.sComponentName + '" with ' + sNames);
685
+ } else if (aSucceeded.length > 0) {
686
+ showShareToast(
687
+ aSucceeded.length + ' shared OK, ' + aFailed.length + ' failed: ' +
688
+ (aFailed[0].reason?.message || 'Unknown error')
689
+ );
690
+ } else {
691
+ showShareToast('Share failed: ' + (aFailed[0].reason?.message || 'Unknown error'));
692
+ }
693
+
694
+ eShareConfirmBtn.textContent = 'Share';
695
+ eShareConfirmBtn.disabled = false;
696
+ closeShareModal();
697
+ });
698
+
699
+ /* ── Close Handlers ─────────────────────────────────────────── */
700
+ eShareCloseBtn.addEventListener('click', closeShareModal);
701
+ eShareCancelBtn.addEventListener('click', closeShareModal);
702
+ eShareBackdrop.addEventListener('click', (e) => {
703
+ if (e.target === eShareBackdrop) closeShareModal();
704
+ });
705
+
706
+ /* ── Toast Notification ─────────────────────────────────────── */
707
+ function showShareToast(sMessage) {
708
+ let eToast = document.querySelector('.share-toast');
709
+ if (!eToast) {
710
+ eToast = document.createElement('div');
711
+ eToast.className = 'share-toast';
712
+ document.body.appendChild(eToast);
713
+ }
714
+ eToast.textContent = sMessage;
715
+ eToast.classList.remove('show');
716
+ void eToast.offsetWidth; /* force reflow */
717
+ eToast.classList.add('show');
718
+ setTimeout(() => eToast.classList.remove('show'), 3000);
719
+ }
720
+
721
+ /* ── Utilities ──────────────────────────────────────────────── */
722
+ function getInitials(sName) {
723
+ if (!sName) return '?';
724
+ const aParts = sName.trim().split(/\s+/);
725
+ if (aParts.length >= 2) return (aParts[0][0] + aParts[aParts.length - 1][0]).toUpperCase();
726
+ return sName.substring(0, 2).toUpperCase();
727
+ }
728
+
729
+ function escapeHtml(sStr) {
730
+ if (typeof sStr !== 'string') return '';
731
+ return sStr.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
732
+ }
733
+
734
+ /* ── Expose openShareModal to the detail panel ──────────────── */
735
+ window._openShareModal = openShareModal;