codeapp-js 0.2.2 → 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 (176) 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/codeApp/.power/schemas/appschemas/dataSourcesInfo.ts +6275 -0
  15. package/codeApp/.power/schemas/jira/jira.Schema.json +6903 -0
  16. package/codeApp/.power/schemas/keyvault/keyvault.Schema.json +1600 -0
  17. package/{examples/combined demo/.power/schemas/office365groups/office365groups.Schema.json → codeApp/.power/schemas/office365groups/office365groups.Schema.json} +2203 -2203
  18. package/codeApp/.power/schemas/teams/teams.Schema.json +11112 -0
  19. package/codeApp/dist/codeapp.js +103 -1043
  20. package/codeApp/dist/connectors/azureKeyvault.js +459 -0
  21. package/codeApp/dist/connectors/jira.js +1247 -0
  22. package/codeApp/dist/connectors/office365groups.js +642 -0
  23. package/codeApp/dist/connectors/office365users.js +513 -0
  24. package/codeApp/dist/connectors/outlook.js +1393 -0
  25. package/{examples/kanban/dist → codeApp/dist/connectors}/sharepoint.js +466 -339
  26. package/codeApp/dist/connectors/sql.js +149 -0
  27. package/codeApp/dist/connectors/teams.js +280 -0
  28. package/codeApp/dist/index.js +1 -1
  29. package/codeApp/dist/power-apps-data.js +725 -176
  30. package/codeApp/src/generated/index.ts +12 -0
  31. package/codeApp/src/generated/models/AzureKeyVaultModel.ts +107 -0
  32. package/codeApp/src/generated/models/JiraModel.ts +501 -0
  33. package/codeApp/src/generated/services/AzureKeyVaultService.ts +257 -0
  34. package/codeApp/src/generated/services/JiraService.ts +1124 -0
  35. package/examples/{kanban → apps/kanban}/dist/dataverse.js +94 -94
  36. package/examples/{kanban → apps/kanban}/dist/index.css +605 -605
  37. package/examples/{kanban → apps/kanban}/dist/index.html +21 -21
  38. package/examples/{kanban → apps/kanban}/dist/index.js +860 -860
  39. package/examples/{kanban → apps/kanban}/dist/office365groups.js +97 -97
  40. package/examples/apps/kanban/dist/office365users.js +451 -0
  41. package/examples/{kanban → apps/kanban}/dist/outlook.js +162 -162
  42. package/examples/{planning Poker/dist/power-apps-data.js → apps/kanban/dist/power-apps-data.js} +2953 -2953
  43. package/{dev files/sharepoint.js → examples/apps/kanban/dist/sharepoint.js} +195 -99
  44. package/examples/{kanban → apps/kanban}/power.config.json +35 -35
  45. package/examples/{planning Poker → apps/planning Poker}/additional files/customizations (tables).xml +6428 -6428
  46. package/examples/{planning Poker → apps/planning Poker}/additional files/dataverse-tables.json +165 -165
  47. package/examples/{planning Poker → apps/planning Poker}/additional files/readme.md +122 -122
  48. package/examples/{planning Poker → apps/planning Poker}/dist/dataverse.js +78 -78
  49. package/examples/{planning Poker → apps/planning Poker}/dist/index.html +198 -198
  50. package/examples/{planning Poker → apps/planning Poker}/dist/index.js +954 -954
  51. package/examples/{kanban/dist/power-apps-data.js → apps/planning Poker/dist/power-apps-data.js } +2953 -2953
  52. package/examples/{planning Poker → apps/planning Poker}/dist/styles.css +815 -815
  53. package/examples/{planning Poker → apps/planning Poker}/power.config.json +50 -50
  54. package/examples/{solution explorer → apps/solution explorer}/dist/codeapp.js +1098 -1098
  55. package/examples/{solution explorer → apps/solution explorer}/dist/index.html +80 -80
  56. package/examples/{solution explorer → apps/solution explorer}/dist/index.js +735 -735
  57. package/examples/{solution explorer → apps/solution explorer}/dist/styles.css +571 -571
  58. package/examples/{solution explorer → apps/solution explorer}/power.config.json +150 -150
  59. package/examples/{todo → apps/todo}/dist/dataverse.js +64 -64
  60. package/examples/{todo → apps/todo}/dist/index.html +75 -75
  61. package/examples/{todo → apps/todo}/dist/index.js +8 -8
  62. package/examples/{todo → apps/todo}/dist/power-apps-data.js +2953 -2953
  63. package/examples/{todo → apps/todo}/dist/renderer.js +375 -375
  64. package/examples/{todo → apps/todo}/dist/styles.css +691 -691
  65. package/examples/{todo → apps/todo}/power.config.json +34 -34
  66. package/examples/combined demo/.power/schemas/appschemas/dataSourcesInfo.ts +6275 -7830
  67. package/examples/combined demo/.power/schemas/jira/jira.Schema.json +6903 -0
  68. package/examples/combined demo/.power/schemas/keyvault/keyvault.Schema.json +1600 -0
  69. package/examples/combined demo/.power/schemas/teams/teams.Schema.json +11112 -0
  70. package/examples/combined demo/dist/codeapp.js +394 -1098
  71. package/examples/combined demo/dist/index.html +29 -511
  72. package/examples/combined demo/dist/index.js +490 -470
  73. package/examples/combined demo/dist/office365users.js +513 -0
  74. package/examples/combined demo/dist/outlook.js +1393 -0
  75. package/examples/combined demo/dist/power-apps-data.js +3079 -3006
  76. package/examples/combined demo/dist/styles.css +483 -0
  77. package/examples/combined demo/power.config.json +33 -42
  78. package/examples/combined demo/src/generated/index.ts +12 -14
  79. package/examples/combined demo/src/generated/models/AzureKeyVaultModel.ts +107 -0
  80. package/examples/combined demo/src/generated/models/JiraModel.ts +501 -0
  81. package/examples/combined demo/src/generated/services/AzureKeyVaultService.ts +257 -0
  82. package/examples/combined demo/src/generated/services/JiraService.ts +1124 -0
  83. package/examples/dataverse Demo/dist/codeapp.js +394 -1085
  84. package/examples/{outlook Demo2/OutlookDemo_1_0_0_1.zip → dataverse Demo/dist/icon-512.png} +0 -0
  85. package/examples/dataverse Demo/dist/index.html +146 -54
  86. package/examples/dataverse Demo/dist/index.js +693 -83
  87. package/examples/dataverse Demo/dist/power-apps-data.js +3079 -2911
  88. package/examples/dataverse Demo/dist/styles.css +528 -0
  89. package/examples/dataverse Demo/power.config.json +41 -35
  90. package/examples/dataverse Demo/readme.md +79 -79
  91. package/examples/groups Demo/dist/codeapp.js +394 -1085
  92. package/examples/groups Demo/dist/icon-512.png +0 -0
  93. package/examples/groups Demo/dist/index.html +21 -25
  94. package/examples/groups Demo/dist/index.js +304 -113
  95. package/examples/groups Demo/dist/office365groups.js +642 -0
  96. package/examples/groups Demo/dist/power-apps-data.js +3079 -2911
  97. package/examples/groups Demo/dist/styles.css +509 -0
  98. package/examples/groups Demo/power.config.json +25 -25
  99. package/examples/myProfile/dist/codeapp.js +398 -0
  100. package/examples/myProfile/dist/index.html +21 -184
  101. package/examples/myProfile/dist/index.js +324 -141
  102. package/examples/myProfile/dist/office365users.js +517 -169
  103. package/examples/myProfile/dist/power-apps-data.js +3080 -2953
  104. package/examples/myProfile/dist/styles.css +458 -0
  105. package/examples/myProfile/power.config.json +24 -23
  106. package/examples/outlook Demo/dist/codeapp.js +394 -1085
  107. package/examples/outlook Demo/dist/index.html +150 -35
  108. package/examples/outlook Demo/dist/index.js +516 -170
  109. package/examples/outlook Demo/dist/outlook.js +1393 -121
  110. package/examples/outlook Demo/dist/power-apps-data.js +3079 -2911
  111. package/examples/outlook Demo/dist/styles.css +408 -84
  112. package/examples/outlook Demo/power.config.json +24 -23
  113. package/examples/outlook Demo/readme.md +92 -82
  114. package/examples/sharePoint Demo/dist/codeapp.js +394 -1085
  115. package/examples/sharePoint Demo/dist/icon-512.png +0 -0
  116. package/examples/sharePoint Demo/dist/index.html +22 -255
  117. package/examples/sharePoint Demo/dist/index.js +899 -262
  118. package/examples/sharePoint Demo/dist/power-apps-data.js +3079 -2911
  119. package/examples/sharePoint Demo/dist/sharepoint.js +466 -0
  120. package/examples/sharePoint Demo/dist/styles.css +587 -0
  121. package/examples/sharePoint Demo/power.config.json +23 -22
  122. package/package.json +1 -1
  123. package/readme.md +479 -61
  124. package/.github/instructions/wyattdave.instructions.md +0 -39
  125. package/.vscode/settings.json +0 -6
  126. package/dev files/dataverse.js +0 -105
  127. package/dev files/office365groups.js +0 -65
  128. package/dev files/office365users.js +0 -169
  129. package/dev files/outlook.js +0 -330
  130. package/examples/combined demo/.power/schemas/office365/office365.Schema.json +0 -21098
  131. package/examples/combined demo/.power/schemas/office365users/office365users.Schema.json +0 -2094
  132. package/examples/kanban/agent/decision-log.md +0 -9
  133. package/examples/kanban/agent/mockup-01-editorial-glass.html +0 -159
  134. package/examples/kanban/agent/mockup-02-dark-rail.html +0 -147
  135. package/examples/kanban/agent/mockup-03-paper-grid.html +0 -114
  136. package/examples/kanban/agent/mockup-04-neon-minimal.html +0 -141
  137. package/examples/kanban/agent/mockup-05-mono-architect.html +0 -119
  138. package/examples/kanban/dist/environmentVar.js +0 -55
  139. package/examples/kanban/dist/office365users.js +0 -169
  140. package/examples/kanban/src/generated/index.ts +0 -14
  141. package/examples/outlook Demo2/agent/decision-log.md +0 -7
  142. package/examples/outlook Demo2/dist/codeapp.js +0 -1334
  143. package/examples/outlook Demo2/dist/index.html +0 -98
  144. package/examples/outlook Demo2/dist/index.js +0 -346
  145. package/examples/outlook Demo2/dist/styles.css +0 -639
  146. package/examples/outlook Demo2/power.config.json +0 -23
  147. package/examples/planning Poker/.vscode/settings.json +0 -5
  148. package/examples/sharePoint Demo/agent/decision-log.md +0 -17
  149. package/examples/solution explorer/agent/decision-log.md +0 -27
  150. package/examples/solution explorer/agent/mockup-01-swiss-grid.html +0 -452
  151. package/examples/solution explorer/agent/mockup-02-dark-glass.html +0 -496
  152. package/examples/solution explorer/agent/mockup-03-paper-console.html +0 -510
  153. package/examples/solution explorer/agent/mockup-04-neon-noir.html +0 -546
  154. package/examples/solution explorer/agent/mockup-05-zen-garden.html +0 -534
  155. package/examples/solution explorer/dist/power-apps-data.js +0 -3007
  156. package/scripts/build-power-sdk.mjs +0 -69
  157. /package/{examples/kanban → codeApp}/src/generated/models/Office365GroupsModel.ts +0 -0
  158. /package/{examples/kanban → codeApp}/src/generated/models/Office365OutlookModel.ts +0 -0
  159. /package/{examples/kanban → codeApp}/src/generated/models/Office365UsersModel.ts +0 -0
  160. /package/{examples/kanban → codeApp}/src/generated/services/Office365GroupsService.ts +0 -0
  161. /package/{examples/kanban → codeApp}/src/generated/services/Office365OutlookService.ts +0 -0
  162. /package/{examples/kanban → codeApp}/src/generated/services/Office365UsersService.ts +0 -0
  163. /package/{dev files → examples/apps/kanban/dist}/environmentVar.js +0 -0
  164. /package/examples/{outlook Demo2 → apps/kanban}/src/generated/index.ts +0 -0
  165. /package/examples/{outlook Demo2 → apps/kanban}/src/generated/models/Office365GroupsModel.ts +0 -0
  166. /package/examples/{outlook Demo2 → apps/kanban}/src/generated/models/Office365OutlookModel.ts +0 -0
  167. /package/examples/{outlook Demo2 → apps/kanban}/src/generated/models/Office365UsersModel.ts +0 -0
  168. /package/examples/{outlook Demo2 → apps/kanban}/src/generated/services/Office365GroupsService.ts +0 -0
  169. /package/examples/{outlook Demo2 → apps/kanban}/src/generated/services/Office365OutlookService.ts +0 -0
  170. /package/examples/{outlook Demo2 → apps/kanban}/src/generated/services/Office365UsersService.ts +0 -0
  171. /package/examples/{planning Poker → apps/planning Poker}/additional files/AgilePoker_1_0_0_1.zip +0 -0
  172. /package/examples/{planning Poker → apps/planning Poker}/additional files/PokerTables_1_0_0_1.zip +0 -0
  173. /package/examples/{outlook Demo2 → apps/solution explorer}/dist/icon-512.png +0 -0
  174. /package/examples/{outlook Demo2 → apps/solution explorer}/dist/power-apps-data.js +0 -0
  175. /package/examples/{todo → apps/todo}/dist/icon192.png +0 -0
  176. /package/examples/{solution explorer → combined demo}/dist/icon-512.png +0 -0
@@ -1,142 +1,325 @@
1
- import { getMyProfile, getUserPhoto, getManager, getDirectReports } from "./office365users.js";
2
-
3
- const root = document.getElementById("root");
4
-
5
- // ── SVG icons ──────────────────────────────────────────────────
6
- const icons = {
7
- mail: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor"><path d="M3 4a2 2 0 00-2 2v1.161l8.441 4.221a1.25 1.25 0 001.118 0L19 7.162V6a2 2 0 00-2-2H3z"/><path d="M19 8.839l-7.77 3.885a2.75 2.75 0 01-2.46 0L1 8.839V14a2 2 0 002 2h14a2 2 0 002-2V8.839z"/></svg>`,
8
- phone: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M2 3.5A1.5 1.5 0 013.5 2h1.148a1.5 1.5 0 011.465 1.175l.716 3.223a1.5 1.5 0 01-.638 1.59l-.558.372a.5.5 0 00-.183.548c.4 1.347 1.394 2.34 2.74 2.74a.5.5 0 00.548-.183l.372-.558a1.5 1.5 0 011.59-.638l3.223.716A1.5 1.5 0 0118 12.352v1.148A1.5 1.5 0 0116.5 15h-1.5A11.5 11.5 0 012 3.5z" clip-rule="evenodd"/></svg>`,
9
- office: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M4 16.5v-13h-.25a.75.75 0 010-1.5h12.5a.75.75 0 010 1.5H16v13h.25a.75.75 0 010 1.5H3.75a.75.75 0 010-1.5H4zm3-11a.5.5 0 01.5-.5h1a.5.5 0 01.5.5v1a.5.5 0 01-.5.5h-1a.5.5 0 01-.5-.5v-1zm.5 2.5a.5.5 0 00-.5.5v1a.5.5 0 00.5.5h1a.5.5 0 00.5-.5v-1a.5.5 0 00-.5-.5h-1zm-.5 3.5a.5.5 0 01.5-.5h1a.5.5 0 01.5.5v1a.5.5 0 01-.5.5h-1a.5.5 0 01-.5-.5v-1zm3.5-6.5a.5.5 0 00-.5.5v1a.5.5 0 00.5.5h1a.5.5 0 00.5-.5v-1a.5.5 0 00-.5-.5h-1zm-.5 3.5a.5.5 0 01.5-.5h1a.5.5 0 01.5.5v1a.5.5 0 01-.5.5h-1a.5.5 0 01-.5-.5v-1zm.5 2.5a.5.5 0 00-.5.5v1a.5.5 0 00.5.5h1a.5.5 0 00.5-.5v-1a.5.5 0 00-.5-.5h-1z" clip-rule="evenodd"/></svg>`,
10
- dept: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor"><path d="M7 8a3 3 0 100-6 3 3 0 000 6zm7.5 1a2.5 2.5 0 100-5 2.5 2.5 0 000 5zM1.615 16.428a1.224 1.224 0 01-.569-1.175 6.002 6.002 0 0111.908 0c.058.467-.172.92-.57 1.174A9.953 9.953 0 017 18a9.953 9.953 0 01-5.385-1.572zM14.5 16h-.106c.07-.297.088-.611.048-.933a7.47 7.47 0 00-1.588-3.755 4.502 4.502 0 015.874 2.636.818.818 0 01-.36.98A7.465 7.465 0 0114.5 16z"/></svg>`,
11
- };
12
-
13
- // ── Helpers ────────────────────────────────────────────────────
14
- function getInitials(name) {
15
- if (!name) return "?";
16
- return name.split(" ").map(w => w[0]).join("").toUpperCase().slice(0, 2);
17
- }
18
-
19
- function renderChip(icon, text) {
20
- if (!text) return "";
21
- return `<span class="chip">${icon}${escapeHtml(text)}</span>`;
22
- }
23
-
24
- function escapeHtml(str) {
25
- const d = document.createElement("div");
26
- d.textContent = str;
27
- return d.innerHTML;
28
- }
29
-
30
- function personRow(name, title, photoData) {
31
- const avatarContent = photoData
32
- ? `<img src="data:image/jpeg;base64,${photoData}" alt="">`
33
- : `<span>${getInitials(name)}</span>`;
34
- return `
35
- <div class="person-row">
36
- <div class="person-avatar">${avatarContent}</div>
37
- <div class="person-meta">
38
- <div class="person-name">${escapeHtml(name || "Unknown")}</div>
39
- <div class="person-title">${escapeHtml(title || "")}</div>
40
- </div>
41
- </div>`;
42
- }
43
-
44
- // ── Load photo (returns base64 or null) ────────────────────────
45
- async function loadPhoto(userId) {
46
- try {
47
- const res = await getUserPhoto(userId);
48
- return res?.value || res || null;
49
- } catch { return null; }
50
- }
51
-
52
- // ── Boot ───────────────────────────────────────────────────────
53
- async function boot() {
54
- try {
55
- // 1. Fetch profile
56
- const me = await getMyProfile();
57
- const userId = me.id || me.mail || me.userPrincipalName;
58
-
59
- // 2. Fetch photo, manager, and direct reports in parallel
60
- const [photo, manager, reports] = await Promise.all([
61
- loadPhoto(userId),
62
- getManager(userId).catch(() => null),
63
- getDirectReports(userId).catch(() => ({ value: [] })),
64
- ]);
65
-
66
- // 3. Load manager photo
67
- const mgrId = manager?.id || manager?.mail || manager?.userPrincipalName;
68
- const mgrPhoto = mgrId ? await loadPhoto(mgrId) : null;
69
-
70
- // 4. Load report photos in parallel
71
- const reportList = reports?.value || [];
72
- const reportPhotos = await Promise.all(
73
- reportList.map(r => loadPhoto(r.id || r.mail || r.userPrincipalName))
74
- );
75
-
76
- // 5. Render
77
- render(me, photo, manager, mgrPhoto, reportList, reportPhotos);
78
- } catch (err) {
79
- root.innerHTML = `<div class="app"><div class="card" style="text-align:center;padding:40px;color:var(--text-muted)">
80
- <p style="font-size:15px;font-weight:600;margin-bottom:8px">Unable to load profile</p>
81
- <p style="font-size:13px">${escapeHtml(String(err))}</p>
82
- </div></div>`;
83
- }
84
- }
85
-
86
- function render(me, photo, manager, mgrPhoto, reports, reportPhotos) {
87
- const avatarContent = photo
88
- ? `<img src="data:image/jpeg;base64,${photo}" alt="Profile photo">`
89
- : `<span class="initials">${getInitials(me.displayName)}</span>`;
90
-
91
- const chips = [
92
- renderChip(icons.mail, me.mail),
93
- renderChip(icons.phone, me.businessPhones?.[0] || me.mobilePhone),
94
- renderChip(icons.office, me.officeLocation),
95
- renderChip(icons.dept, me.department),
96
- ].filter(Boolean).join("");
97
-
98
- // Manager section
99
- const managerHtml = manager
100
- ? personRow(manager.displayName, manager.jobTitle, mgrPhoto)
101
- : `<div class="empty-state">No manager found</div>`;
102
-
103
- // Direct reports section
104
- let reportsHtml;
105
- if (reports.length === 0) {
106
- reportsHtml = `<div class="empty-state">No direct reports</div>`;
107
- } else {
108
- reportsHtml = reports
109
- .map((r, i) => personRow(r.displayName, r.jobTitle, reportPhotos[i]))
110
- .join("");
111
- }
112
-
113
- root.innerHTML = `
114
- <div class="app">
115
- <!-- Hero -->
116
- <div class="hero">
117
- <div class="hero-banner"></div>
118
- <div class="hero-body">
119
- <div class="avatar-ring">${avatarContent}</div>
120
- <div class="hero-info">
121
- <h1>${escapeHtml(me.displayName || "")}</h1>
122
- <p>${escapeHtml(me.jobTitle || "")}</p>
123
- </div>
124
- </div>
125
- <div class="details">${chips}</div>
126
- </div>
127
-
128
- <!-- Manager & Reports -->
129
- <div class="columns">
130
- <div>
131
- <div class="section-title">Manager</div>
132
- <div class="card">${managerHtml}</div>
133
- </div>
134
- <div>
135
- <div class="section-title">Direct Reports</div>
136
- <div class="card">${reportsHtml}</div>
137
- </div>
138
- </div>
139
- </div>`;
140
- }
141
-
1
+ import { getMyProfile, getUserPhoto } from './office365users.js';
2
+ import { enableDebugger } from "./codeapp.js";
3
+
4
+ enableDebugger();
5
+
6
+ const eRoot = document.getElementById('root');
7
+ const aProfileSelect = [
8
+ 'id',
9
+ 'displayName',
10
+ 'givenName',
11
+ 'surname',
12
+ 'mail',
13
+ 'userPrincipalName',
14
+ 'jobTitle',
15
+ 'department',
16
+ 'officeLocation',
17
+ 'mobilePhone',
18
+ 'businessPhones',
19
+ 'city',
20
+ 'state',
21
+ 'country',
22
+ 'companyName',
23
+ 'preferredLanguage'
24
+ ];
25
+
26
+ const oState = {
27
+ bLoading: true,
28
+ sError: '',
29
+ oProfile: null,
30
+ sPhotoSrc: '',
31
+ sLastUpdated: ''
32
+ };
33
+
34
+ function escapeHtml(oValue) {
35
+ return String(oValue || '')
36
+ .replace(new RegExp('&', 'g'), '&amp;')
37
+ .replace(new RegExp('<', 'g'), '&lt;')
38
+ .replace(new RegExp('>', 'g'), '&gt;')
39
+ .replace(new RegExp('"', 'g'), '&quot;');
40
+ }
41
+
42
+ function isNonEmptyString(oValue) {
43
+ return typeof oValue === 'string' && oValue.trim() !== '';
44
+ }
45
+
46
+ function toTextOrEmpty(oValue) {
47
+ return isNonEmptyString(oValue) ? oValue.trim() : '';
48
+ }
49
+
50
+ function toArray(oValue) {
51
+ return Array.isArray(oValue) ? oValue.filter(Boolean) : [];
52
+ }
53
+
54
+ function getDisplayName(oProfile) {
55
+ return toTextOrEmpty(oProfile.displayName) || toTextOrEmpty(oProfile.mail) || 'Your profile';
56
+ }
57
+
58
+ function getProfileId(oProfile) {
59
+ return toTextOrEmpty(oProfile.id) || toTextOrEmpty(oProfile.mail) || toTextOrEmpty(oProfile.userPrincipalName);
60
+ }
61
+
62
+ function getInitials(sName) {
63
+ const aParts = String(sName || '')
64
+ .split(/\s+/)
65
+ .filter(Boolean)
66
+ .slice(0, 2);
67
+
68
+ if (aParts.length === 0) return 'ME';
69
+ return aParts.map(function (sPart) {
70
+ return sPart.charAt(0).toUpperCase();
71
+ }).join('');
72
+ }
73
+
74
+ function getHeadline(oProfile) {
75
+ const aParts = [
76
+ toTextOrEmpty(oProfile.jobTitle),
77
+ toTextOrEmpty(oProfile.department),
78
+ toTextOrEmpty(oProfile.officeLocation)
79
+ ].filter(Boolean);
80
+
81
+ return aParts.join(' | ') || 'Signed-in Office 365 profile';
82
+ }
83
+
84
+ function getLocationLabel(oProfile) {
85
+ const aParts = [
86
+ toTextOrEmpty(oProfile.city),
87
+ toTextOrEmpty(oProfile.state),
88
+ toTextOrEmpty(oProfile.country)
89
+ ].filter(Boolean);
90
+
91
+ return aParts.join(', ') || 'Location not available';
92
+ }
93
+
94
+ function getPhoneLabel(oProfile) {
95
+ const aBusinessPhones = toArray(oProfile.businessPhones);
96
+ return toTextOrEmpty(oProfile.mobilePhone) || aBusinessPhones.join(', ') || 'No phone listed';
97
+ }
98
+
99
+ function normalizePhotoSource(oPhotoResult) {
100
+ let sValue = '';
101
+
102
+ if (typeof oPhotoResult === 'string') {
103
+ sValue = oPhotoResult;
104
+ } else if (oPhotoResult && typeof oPhotoResult === 'object') {
105
+ sValue = toTextOrEmpty(oPhotoResult.value) || toTextOrEmpty(oPhotoResult.$content) || toTextOrEmpty(oPhotoResult.content);
106
+ }
107
+
108
+ if (!sValue) return '';
109
+ if (sValue.indexOf('data:') === 0 || sValue.indexOf('blob:') === 0 || sValue.indexOf('http') === 0) return sValue;
110
+ return 'data:image/jpeg;base64,' + sValue;
111
+ }
112
+
113
+ function formatUpdatedTime() {
114
+ return new Date().toLocaleTimeString([], {
115
+ hour: '2-digit',
116
+ minute: '2-digit'
117
+ });
118
+ }
119
+
120
+ function renderActionLink(sHref, sLabel) {
121
+ if (!sHref || !sLabel) return '';
122
+ return '<a class="button button-secondary" href="' + escapeHtml(sHref) + '">' + escapeHtml(sLabel) + '</a>';
123
+ }
124
+
125
+ function renderInfoItems(aItems) {
126
+ return aItems.filter(function (oItem) {
127
+ return Boolean(oItem.sValue);
128
+ }).map(function (oItem) {
129
+ let sValueHtml = escapeHtml(oItem.sValue);
130
+
131
+ if (oItem.sHref) {
132
+ sValueHtml = '<a href="' + escapeHtml(oItem.sHref) + '">' + sValueHtml + '</a>';
133
+ }
134
+
135
+ return '<li class="info-item">'
136
+ + '<span class="info-label">' + escapeHtml(oItem.sLabel) + '</span>'
137
+ + '<div class="info-value">' + sValueHtml + '</div>'
138
+ + '</li>';
139
+ }).join('');
140
+ }
141
+
142
+ function renderSummaryCard(sLabel, sValue, sNote) {
143
+ return '<article class="summary-card">'
144
+ + '<p class="summary-label">' + escapeHtml(sLabel) + '</p>'
145
+ + '<p class="summary-value">' + escapeHtml(sValue) + '</p>'
146
+ + '<p class="summary-note">' + escapeHtml(sNote) + '</p>'
147
+ + '</article>';
148
+ }
149
+
150
+ function bindEvents() {
151
+ const eRefresh = document.getElementById('refreshProfile');
152
+ if (eRefresh) {
153
+ eRefresh.onclick = function () {
154
+ loadProfile();
155
+ };
156
+ }
157
+ }
158
+
159
+ function renderLoading() {
160
+ eRoot.innerHTML = '<section class="status-shell">'
161
+ + '<div class="status-card" role="status" aria-live="polite">'
162
+ + '<p class="eyebrow">Office 365 Users Demo</p>'
163
+ + '<h1 class="status-title">Loading your Microsoft 365 profile</h1>'
164
+ + '<p class="status-text">The app is calling the Office 365 Users connector for your profile details and profile photo.</p>'
165
+ + '<div class="status-actions"><button class="button" id="refreshProfile" disabled>Loading...</button></div>'
166
+ + '</div>'
167
+ + '</section>';
168
+ bindEvents();
169
+ }
170
+
171
+ function renderError() {
172
+ eRoot.innerHTML = '<section class="status-shell">'
173
+ + '<div class="status-card is-error">'
174
+ + '<p class="eyebrow">Office 365 Users Demo</p>'
175
+ + '<h1 class="status-title">Unable to load your profile</h1>'
176
+ + '<p class="status-text">' + escapeHtml(oState.sError) + '</p>'
177
+ + '<div class="status-actions"><button class="button" id="refreshProfile">Try again</button></div>'
178
+ + '</div>'
179
+ + '</section>';
180
+ bindEvents();
181
+ }
182
+
183
+ function renderApp() {
184
+ if (!eRoot) return;
185
+
186
+ if (oState.bLoading) {
187
+ renderLoading();
188
+ return;
189
+ }
190
+
191
+ if (oState.sError) {
192
+ renderError();
193
+ return;
194
+ }
195
+
196
+ const oProfile = oState.oProfile || {};
197
+ const sDisplayName = getDisplayName(oProfile);
198
+ const sHeadline = getHeadline(oProfile);
199
+ const sInitials = getInitials(sDisplayName);
200
+ const aChips = [
201
+ toTextOrEmpty(oProfile.department),
202
+ toTextOrEmpty(oProfile.officeLocation),
203
+ toTextOrEmpty(oProfile.companyName),
204
+ toTextOrEmpty(oProfile.preferredLanguage)
205
+ ].filter(Boolean);
206
+ const aIdentityItems = [
207
+ { sLabel: 'Name', sValue: sDisplayName },
208
+ { sLabel: 'Job title', sValue: toTextOrEmpty(oProfile.jobTitle) || 'Not listed' },
209
+ { sLabel: 'Department', sValue: toTextOrEmpty(oProfile.department) || 'Not listed' },
210
+ { sLabel: 'Company', sValue: toTextOrEmpty(oProfile.companyName) || 'Not listed' }
211
+ ];
212
+ const aContactItems = [
213
+ { sLabel: 'Email', sValue: toTextOrEmpty(oProfile.mail), sHref: toTextOrEmpty(oProfile.mail) ? 'mailto:' + toTextOrEmpty(oProfile.mail) : '' },
214
+ { sLabel: 'Mobile phone', sValue: toTextOrEmpty(oProfile.mobilePhone), sHref: toTextOrEmpty(oProfile.mobilePhone) ? 'tel:' + toTextOrEmpty(oProfile.mobilePhone) : '' },
215
+ { sLabel: 'Business phones', sValue: toArray(oProfile.businessPhones).join(', ') },
216
+ { sLabel: 'User principal name', sValue: toTextOrEmpty(oProfile.userPrincipalName) }
217
+ ];
218
+ const aWorkItems = [
219
+ { sLabel: 'Office', sValue: toTextOrEmpty(oProfile.officeLocation) || 'Not listed' },
220
+ { sLabel: 'Location', sValue: getLocationLabel(oProfile) },
221
+ { sLabel: 'Preferred language', sValue: toTextOrEmpty(oProfile.preferredLanguage) || 'Not listed' },
222
+ { sLabel: 'Profile photo', sValue: oState.sPhotoSrc ? 'Available' : 'Not available' }
223
+ ];
224
+ const iFilledFields = aProfileSelect.reduce(function (iCount, sKey) {
225
+ const oValue = oProfile[sKey];
226
+ if (Array.isArray(oValue)) return iCount + (oValue.filter(Boolean).length > 0 ? 1 : 0);
227
+ return iCount + (toTextOrEmpty(oValue) ? 1 : 0);
228
+ }, 0);
229
+ const sEmailHref = toTextOrEmpty(oProfile.mail) ? 'mailto:' + toTextOrEmpty(oProfile.mail) : '';
230
+ const sPhotoMarkup = oState.sPhotoSrc
231
+ ? '<img class="photo-image" src="' + escapeHtml(oState.sPhotoSrc) + '" alt="' + escapeHtml(sDisplayName) + ' profile photo" />'
232
+ : '<div class="photo-fallback" aria-label="Avatar fallback">' + escapeHtml(sInitials) + '</div>';
233
+ const sChipMarkup = aChips.map(function (sChip) {
234
+ return '<li class="hero-chip">' + escapeHtml(sChip) + '</li>';
235
+ }).join('');
236
+
237
+ eRoot.innerHTML = '<main class="page-shell">'
238
+ + '<section class="hero-card">'
239
+ + '<div class="photo-column">'
240
+ + '<div class="photo-frame">' + sPhotoMarkup + '</div>'
241
+ + '<div class="photo-caption">'
242
+ + '<p class="caption-label">Profile image</p>'
243
+ + '<p class="caption-value">' + escapeHtml(oState.sPhotoSrc ? 'Synced from Office 365 Users' : 'Using initials fallback') + '</p>'
244
+ + '</div>'
245
+ + '</div>'
246
+ + '<div class="hero-copy">'
247
+ + '<p class="eyebrow">Office 365 Users Demo</p>'
248
+ + '<h1 class="hero-title">' + escapeHtml(sDisplayName) + '</h1>'
249
+ + '<p class="hero-subtitle">' + escapeHtml(sHeadline) + '</p>'
250
+ + '<ul class="hero-chips">' + sChipMarkup + '</ul>'
251
+ + '<div class="action-row">'
252
+ + '<button class="button" id="refreshProfile">Refresh profile</button>'
253
+ + renderActionLink(sEmailHref, 'Email me')
254
+ + '</div>'
255
+ + '</div>'
256
+ + '</section>'
257
+ + '<section class="summary-grid">'
258
+ + renderSummaryCard('Fields loaded', String(iFilledFields), 'Values returned across the selected Office 365 profile fields.')
259
+ + renderSummaryCard('Best contact', getPhoneLabel(oProfile), 'Primary phone detail chosen from mobile or business phone fields.')
260
+ + renderSummaryCard('Last updated', oState.sLastUpdated || '--:--', 'Timestamp from the latest successful connector refresh in this session.')
261
+ + '</section>'
262
+ + '<section class="detail-grid">'
263
+ + '<article class="panel">'
264
+ + '<h2 class="panel-title">Identity</h2>'
265
+ + '<p class="panel-text">The essentials returned for the signed-in user account.</p>'
266
+ + '<ul class="info-list">' + renderInfoItems(aIdentityItems) + '</ul>'
267
+ + '</article>'
268
+ + '<article class="panel">'
269
+ + '<h2 class="panel-title">Contact</h2>'
270
+ + '<p class="panel-text">Direct contact values from the Office 365 Users connector response.</p>'
271
+ + '<ul class="info-list">' + renderInfoItems(aContactItems) + '</ul>'
272
+ + '</article>'
273
+ + '<article class="panel panel-accent">'
274
+ + '<h2 class="panel-title">Account Snapshot</h2>'
275
+ + '<p class="panel-text">A small readout of the fields that usually matter first in a profile demo.</p>'
276
+ + '<div class="account-highlight">'
277
+ + '<div class="highlight-item"><p class="highlight-label">Office</p><p class="highlight-value">' + escapeHtml(toTextOrEmpty(oProfile.officeLocation) || 'No office listed') + '</p></div>'
278
+ + '<div class="highlight-item"><p class="highlight-label">Location</p><p class="highlight-value">' + escapeHtml(getLocationLabel(oProfile)) + '</p></div>'
279
+ + '<div class="highlight-item"><p class="highlight-label">Profile status</p><p class="highlight-value">' + escapeHtml(oState.sPhotoSrc ? 'Photo and key fields available' : 'Key fields available, photo fallback active') + '</p></div>'
280
+ + '</div>'
281
+ + '<ul class="info-list">' + renderInfoItems(aWorkItems) + '</ul>'
282
+ + '<p class="footer-note">The demo reads your signed-in profile and converts the returned photo payload into an image source when a photo is available.</p>'
283
+ + '</article>'
284
+ + '</section>'
285
+ + '</main>';
286
+
287
+ bindEvents();
288
+ }
289
+
290
+ async function loadProfile() {
291
+ oState.bLoading = true;
292
+ oState.sError = '';
293
+ renderApp();
294
+
295
+ try {
296
+ const oProfile = await getMyProfile({ select: aProfileSelect });
297
+ const sUserId = getProfileId(oProfile);
298
+ let sPhotoSrc = '';
299
+
300
+ if (sUserId) {
301
+ try {
302
+ const oPhotoResult = await getUserPhoto(sUserId);
303
+ sPhotoSrc = normalizePhotoSource(oPhotoResult);
304
+ } catch (oPhotoError) {
305
+ sPhotoSrc = '';
306
+ }
307
+ }
308
+
309
+ oState.oProfile = oProfile;
310
+ oState.sPhotoSrc = sPhotoSrc;
311
+ oState.sLastUpdated = formatUpdatedTime();
312
+ } catch (oError) {
313
+ oState.sError = oError && oError.message ? oError.message : 'An unexpected error occurred while loading your Office 365 profile.';
314
+ } finally {
315
+ oState.bLoading = false;
316
+ renderApp();
317
+ }
318
+ }
319
+
320
+ async function boot() {
321
+ renderApp();
322
+ await loadProfile();
323
+ }
324
+
142
325
  boot();