codeapp-js 1.0.1 → 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 (130) hide show
  1. package/AI/skills/autoreview/SKILL.md +69 -0
  2. package/AI/skills/connections/SKILL.md +4 -4
  3. package/AI/skills/dataverse/SKILL.md +4 -2
  4. package/AI/skills/frontend-design/SKILL.md +32 -20
  5. package/AI/skills/keyvault/SKILL.md +139 -0
  6. package/AI/skills/office365-groups/SKILL.md +46 -25
  7. package/AI/skills/office365-outlook/SKILL.md +56 -25
  8. package/AI/skills/office365-users/SKILL.md +41 -36
  9. package/AI/skills/sharepoint/SKILL.md +174 -31
  10. package/AI/skills/start/SKILL.md +38 -30
  11. package/codeApp/dist/connectors/autoreview.js +1654 -0
  12. package/codeApp/dist/connectors/office365groups.js +2995 -432
  13. package/{examples/outlook Demo/.power/schemas/office365/office365.Schema.json → codeApp/dist/connectors/office365outlook.js} +7439 -16
  14. package/codeApp/dist/connectors/office365users.js +2990 -349
  15. package/codeApp/dist/connectors/sharepoint.js +529 -308
  16. package/examples/combined demo/dist/connectors/office365outlook.js +28521 -0
  17. package/examples/combined demo/dist/connectors/office365users.js +3154 -0
  18. package/examples/combined demo/dist/index.js +2 -6
  19. package/examples/combined demo/power.config.json +1 -1
  20. package/examples/groups Demo/{.power/schemas/office365groups/office365groups.Schema.json → dist/connectors/office365groups.js } +3205 -2204
  21. package/examples/groups Demo/dist/index.js +1 -5
  22. package/examples/groups Demo/power.config.json +1 -1
  23. package/examples/myProfile/dist/connectors/office365users.js +3154 -0
  24. package/examples/myProfile/dist/index.js +1 -5
  25. package/examples/myProfile/power.config.json +1 -1
  26. package/examples/outlook Demo/dist/connectors/office365outlook.js +28521 -0
  27. package/examples/outlook Demo/dist/index.js +2 -5
  28. package/examples/outlook Demo/power.config.json +1 -1
  29. package/examples/sharePoint Demo/dist/connectors/sharepoint.js +687 -0
  30. package/examples/sharePoint Demo/dist/index.js +86 -127
  31. package/examples/sharePoint Demo/power.config.json +1 -1
  32. package/package.json +1 -1
  33. package/codeApp/.power/schemas/appschemas/dataSourcesInfo.ts +0 -6275
  34. package/codeApp/.power/schemas/jira/jira.Schema.json +0 -6903
  35. package/codeApp/.power/schemas/keyvault/keyvault.Schema.json +0 -1600
  36. package/codeApp/.power/schemas/office365groups/office365groups.Schema.json +0 -2204
  37. package/codeApp/.power/schemas/teams/teams.Schema.json +0 -11112
  38. package/codeApp/dist/connectors/outlook.js +0 -1393
  39. package/codeApp/src/generated/index.ts +0 -12
  40. package/codeApp/src/generated/models/AzureKeyVaultModel.ts +0 -107
  41. package/codeApp/src/generated/models/JiraModel.ts +0 -501
  42. package/codeApp/src/generated/models/Office365GroupsModel.ts +0 -363
  43. package/codeApp/src/generated/models/Office365OutlookModel.ts +0 -2046
  44. package/codeApp/src/generated/models/Office365UsersModel.ts +0 -254
  45. package/codeApp/src/generated/services/AzureKeyVaultService.ts +0 -257
  46. package/codeApp/src/generated/services/JiraService.ts +0 -1124
  47. package/codeApp/src/generated/services/Office365GroupsService.ts +0 -326
  48. package/codeApp/src/generated/services/Office365OutlookService.ts +0 -2476
  49. package/codeApp/src/generated/services/Office365UsersService.ts +0 -358
  50. package/examples/apps/kanban/dist/dataverse.js +0 -94
  51. package/examples/apps/kanban/dist/environmentVar.js +0 -55
  52. package/examples/apps/kanban/dist/index.css +0 -605
  53. package/examples/apps/kanban/dist/index.html +0 -21
  54. package/examples/apps/kanban/dist/index.js +0 -860
  55. package/examples/apps/kanban/dist/office365groups.js +0 -97
  56. package/examples/apps/kanban/dist/office365users.js +0 -451
  57. package/examples/apps/kanban/dist/outlook.js +0 -162
  58. package/examples/apps/kanban/dist/power-apps-data.js +0 -2953
  59. package/examples/apps/kanban/dist/sharepoint.js +0 -435
  60. package/examples/apps/kanban/power.config.json +0 -35
  61. package/examples/apps/kanban/src/generated/index.ts +0 -14
  62. package/examples/apps/kanban/src/generated/models/Office365GroupsModel.ts +0 -363
  63. package/examples/apps/kanban/src/generated/models/Office365OutlookModel.ts +0 -2046
  64. package/examples/apps/kanban/src/generated/models/Office365UsersModel.ts +0 -254
  65. package/examples/apps/kanban/src/generated/services/Office365GroupsService.ts +0 -326
  66. package/examples/apps/kanban/src/generated/services/Office365OutlookService.ts +0 -2476
  67. package/examples/apps/kanban/src/generated/services/Office365UsersService.ts +0 -358
  68. package/examples/apps/planning Poker/additional files/AgilePoker_1_0_0_1.zip +0 -0
  69. package/examples/apps/planning Poker/additional files/PokerTables_1_0_0_1.zip +0 -0
  70. package/examples/apps/planning Poker/additional files/customizations (tables).xml +0 -6429
  71. package/examples/apps/planning Poker/additional files/dataverse-tables.json +0 -165
  72. package/examples/apps/planning Poker/additional files/readme.md +0 -122
  73. package/examples/apps/planning Poker/dist/dataverse.js +0 -78
  74. package/examples/apps/planning Poker/dist/index.html +0 -198
  75. package/examples/apps/planning Poker/dist/index.js +0 -955
  76. package/examples/apps/planning Poker/dist/power-apps-data.js +0 -2953
  77. package/examples/apps/planning Poker/dist/styles.css +0 -815
  78. package/examples/apps/planning Poker/power.config.json +0 -50
  79. package/examples/apps/solution explorer/dist/codeapp.js +0 -1098
  80. package/examples/apps/solution explorer/dist/icon-512.png +0 -0
  81. package/examples/apps/solution explorer/dist/index.html +0 -80
  82. package/examples/apps/solution explorer/dist/index.js +0 -735
  83. package/examples/apps/solution explorer/dist/power-apps-data.js +0 -3007
  84. package/examples/apps/solution explorer/dist/styles.css +0 -571
  85. package/examples/apps/solution explorer/power.config.json +0 -151
  86. package/examples/apps/todo/dist/dataverse.js +0 -64
  87. package/examples/apps/todo/dist/icon192.png +0 -0
  88. package/examples/apps/todo/dist/index.html +0 -75
  89. package/examples/apps/todo/dist/index.js +0 -9
  90. package/examples/apps/todo/dist/power-apps-data.js +0 -2953
  91. package/examples/apps/todo/dist/renderer.js +0 -375
  92. package/examples/apps/todo/dist/styles.css +0 -691
  93. package/examples/apps/todo/power.config.json +0 -35
  94. package/examples/combined demo/.power/schemas/appschemas/dataSourcesInfo.ts +0 -6275
  95. package/examples/combined demo/.power/schemas/jira/jira.Schema.json +0 -6903
  96. package/examples/combined demo/.power/schemas/keyvault/keyvault.Schema.json +0 -1600
  97. package/examples/combined demo/.power/schemas/teams/teams.Schema.json +0 -11112
  98. package/examples/combined demo/dist/office365users.js +0 -513
  99. package/examples/combined demo/dist/outlook.js +0 -1393
  100. package/examples/combined demo/src/generated/index.ts +0 -12
  101. package/examples/combined demo/src/generated/models/AzureKeyVaultModel.ts +0 -107
  102. package/examples/combined demo/src/generated/models/JiraModel.ts +0 -501
  103. package/examples/combined demo/src/generated/models/Office365GroupsModel.ts +0 -363
  104. package/examples/combined demo/src/generated/models/Office365OutlookModel.ts +0 -2046
  105. package/examples/combined demo/src/generated/models/Office365UsersModel.ts +0 -254
  106. package/examples/combined demo/src/generated/services/AzureKeyVaultService.ts +0 -257
  107. package/examples/combined demo/src/generated/services/JiraService.ts +0 -1124
  108. package/examples/combined demo/src/generated/services/Office365GroupsService.ts +0 -326
  109. package/examples/combined demo/src/generated/services/Office365OutlookService.ts +0 -2476
  110. package/examples/combined demo/src/generated/services/Office365UsersService.ts +0 -358
  111. package/examples/groups Demo/.power/schemas/appschemas/dataSourcesInfo.ts +0 -613
  112. package/examples/groups Demo/dist/office365groups.js +0 -642
  113. package/examples/groups Demo/src/generated/index.ts +0 -10
  114. package/examples/groups Demo/src/generated/models/Office365GroupsModel.ts +0 -363
  115. package/examples/groups Demo/src/generated/services/Office365GroupsService.ts +0 -326
  116. package/examples/myProfile/dist/office365users.js +0 -517
  117. package/examples/outlook Demo/.power/schemas/appschemas/dataSourcesInfo.ts +0 -6512
  118. package/examples/outlook Demo/dist/outlook.js +0 -1393
  119. package/examples/outlook Demo/src/generated/index.ts +0 -10
  120. package/examples/outlook Demo/src/generated/models/Office365OutlookModel.ts +0 -2046
  121. package/examples/outlook Demo/src/generated/services/Office365OutlookService.ts +0 -2476
  122. package/examples/sharePoint Demo/dist/sharepoint.js +0 -466
  123. package/examples/sharePoint Demo/src/generated/index.ts +0 -14
  124. package/examples/sharePoint Demo/src/generated/models/Office365GroupsModel.ts +0 -363
  125. package/examples/sharePoint Demo/src/generated/models/Office365OutlookModel.ts +0 -2046
  126. package/examples/sharePoint Demo/src/generated/models/Office365UsersModel.ts +0 -254
  127. package/examples/sharePoint Demo/src/generated/services/Office365GroupsService.ts +0 -326
  128. package/examples/sharePoint Demo/src/generated/services/Office365OutlookService.ts +0 -2476
  129. package/examples/sharePoint Demo/src/generated/services/Office365UsersService.ts +0 -358
  130. package/readme.md +0 -590
@@ -1,1098 +0,0 @@
1
- import { getClient, callActionAsync } from "./power-apps-data.js";
2
-
3
- // ── Initialize SDK & Client ────────────────────────────────────
4
- let oSharedClient = null;
5
- let oInitialDataSources = {};
6
-
7
- // ── Set initial data sources (call before any API calls) ───────
8
- export function initDataSources(oSources) {
9
- return _dbgWrap('initDataSources', [oSources], function() {
10
- oInitialDataSources = oSources || {};
11
- oSharedClient = null;
12
- });
13
- }
14
-
15
- function getSharedClient() {
16
- if (!oSharedClient) {
17
- oSharedClient = getClient(Object.assign({}, oInitialDataSources, oDataSources));
18
- }
19
- return oSharedClient;
20
- }
21
-
22
- // ── Unwrap SDK response ────────────────────────────────────────
23
- function unwrapResult(result) {
24
- if (result && result.success === false) {
25
- let sMsg = result.error ? (result.error.message || JSON.stringify(result.error)) : "Operation failed";
26
- throw new Error(sMsg);
27
- }
28
- return result && "data" in result ? result.data : result;
29
- }
30
-
31
- // ── Debugger ───────────────────────────────────────────────────
32
- let _bDebugActive = false;
33
- let _aDebugEntries = [];
34
- let _eDebugPanel = null;
35
- let _eDebugIcon = null;
36
- let _eDebugList = null;
37
- let _iDebugCounter = 0;
38
-
39
- function _dbgWrap(sName, aArgs, fnBody) {
40
- if (!_bDebugActive) return fnBody();
41
- let oEntry = { iId: ++_iDebugCounter, sName: sName, aArgs: _dbgClone(aArgs), iTime: Date.now() };
42
- _aDebugEntries.unshift(oEntry);
43
- _dbgRenderEntry(oEntry, true);
44
- let oResult;
45
- try {
46
- oResult = fnBody();
47
- } catch (oErr) {
48
- oEntry.oError = oErr && oErr.message ? oErr.message : String(oErr);
49
- oEntry.iDuration = Date.now() - oEntry.iTime;
50
- _dbgRenderEntry(oEntry, false);
51
- throw oErr;
52
- }
53
- if (oResult && typeof oResult.then === 'function') {
54
- return oResult.then(function(oVal) {
55
- oEntry.oResult = _dbgClone(oVal);
56
- oEntry.iDuration = Date.now() - oEntry.iTime;
57
- _dbgRenderEntry(oEntry, false);
58
- return oVal;
59
- }, function(oErr) {
60
- oEntry.oError = oErr && oErr.message ? oErr.message : String(oErr);
61
- oEntry.iDuration = Date.now() - oEntry.iTime;
62
- _dbgRenderEntry(oEntry, false);
63
- throw oErr;
64
- });
65
- }
66
- oEntry.oResult = _dbgClone(oResult);
67
- oEntry.iDuration = Date.now() - oEntry.iTime;
68
- _dbgRenderEntry(oEntry, false);
69
- return oResult;
70
- }
71
- function _dbgClone(oVal) {
72
- try { return JSON.parse(JSON.stringify(oVal)); }
73
- catch (oErr) { return String(oVal); }
74
- }
75
-
76
- function _dbgFormatTime(iTimestamp) {
77
- let oDate = new Date(iTimestamp);
78
- let sH = String(oDate.getHours()).padStart(2, '0');
79
- let sM = String(oDate.getMinutes()).padStart(2, '0');
80
- let sS = String(oDate.getSeconds()).padStart(2, '0');
81
- let sMs = String(oDate.getMilliseconds()).padStart(3, '0');
82
- return sH + ':' + sM + ':' + sS + '.' + sMs;
83
- }
84
-
85
- function _dbgEscapeHtml(sStr) {
86
- if (typeof sStr !== 'string') sStr = String(sStr);
87
- return sStr.replace(new RegExp('&', 'g'), '&amp;').replace(new RegExp('<', 'g'), '&lt;').replace(new RegExp('>', 'g'), '&gt;');
88
- }
89
-
90
- function _dbgRenderEntry(oEntry, bPending) {
91
- if (!_eDebugList) return;
92
- let sId = 'dbg-' + oEntry.iId;
93
- let eRow = _eDebugList.querySelector('[data-dbg-id="' + sId + '"]');
94
- if (!eRow) {
95
- eRow = document.createElement('div');
96
- eRow.setAttribute('data-dbg-id', sId);
97
- eRow.style.cssText = 'border-bottom:1px solid #333;padding:6px 8px;font-size:12px;cursor:pointer;';
98
- _eDebugList.prepend(eRow);
99
- }
100
- let sStatus = bPending ? '\u23F3' : (oEntry.oError ? '\u274C' : '\u2705');
101
- let sDuration = bPending ? '\u2026' : oEntry.iDuration + 'ms';
102
- eRow.innerHTML = '<div style="display:flex;justify-content:space-between;align-items:center;gap:6px;">'
103
- + '<span style="flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;"><strong>' + sStatus + ' ' + _dbgEscapeHtml(oEntry.sName) + '</strong></span>'
104
- + '<span style="color:#888;font-size:11px;white-space:nowrap;">' + _dbgFormatTime(oEntry.iTime) + ' | ' + sDuration + '</span>'
105
- + '<button class="dbg-copy" style="background:#333;color:#e0e0e0;border:1px solid #555;border-radius:3px;padding:1px 6px;cursor:pointer;font-size:11px;white-space:nowrap;" title="Copy to clipboard">⎘</button>'
106
- + '</div>';
107
- eRow.querySelector('.dbg-copy').onclick = function(e) {
108
- e.stopPropagation();
109
- let oData = { name: oEntry.sName, args: oEntry.aArgs, time: _dbgFormatTime(oEntry.iTime) };
110
- if (oEntry.oError) { oData.error = oEntry.oError; }
111
- else if (oEntry.oResult !== undefined) { oData.result = oEntry.oResult; }
112
- if (oEntry.iDuration !== undefined) { oData.duration = oEntry.iDuration + 'ms'; }
113
- navigator.clipboard.writeText(JSON.stringify(oData, null, 2)).then(function() {
114
- let eBtn = eRow.querySelector('.dbg-copy');
115
- eBtn.textContent = '\u2713';
116
- setTimeout(function() { eBtn.textContent = '\u2398'; }, 1000);
117
- });
118
- };
119
- eRow.onclick = function() {
120
- let eDetail = eRow.querySelector('.dbg-detail');
121
- if (eDetail) { eDetail.remove(); return; }
122
- eDetail = document.createElement('div');
123
- eDetail.className = 'dbg-detail';
124
- eDetail.style.cssText = 'margin-top:4px;padding:4px;background:#1a1a2e;border-radius:4px;font-size:11px;overflow:auto;max-height:300px;';
125
- let sArgsHtml = '<div style="color:#61dafb;margin-bottom:4px;"><b>Args:</b> <pre style="margin:2px 0;white-space:pre-wrap;word-break:break-all;">' + _dbgEscapeHtml(JSON.stringify(oEntry.aArgs, null, 2)) + '</pre></div>';
126
- let sResultHtml = '';
127
- if (oEntry.oError) {
128
- sResultHtml = '<div style="color:#ff6b6b;"><b>Error:</b> <pre style="margin:2px 0;white-space:pre-wrap;word-break:break-all;">' + _dbgEscapeHtml(oEntry.oError) + '</pre></div>';
129
- } else if (!bPending) {
130
- sResultHtml = '<div style="color:#a8e6cf;"><b>Result:</b> <pre style="margin:2px 0;white-space:pre-wrap;word-break:break-all;">' + _dbgEscapeHtml(JSON.stringify(oEntry.oResult, null, 2)) + '</pre></div>';
131
- }
132
- eDetail.innerHTML = sArgsHtml + sResultHtml;
133
- eRow.appendChild(eDetail);
134
- };
135
- if (_eDebugIcon) {
136
- let eBadge = _eDebugIcon.querySelector('.dbg-badge');
137
- if (eBadge) eBadge.textContent = String(_aDebugEntries.length);
138
- }
139
- }
140
-
141
- function _dbgInjectUI() {
142
- _eDebugIcon = document.createElement('div');
143
- _eDebugIcon.id = 'codeapp-debug-icon';
144
- _eDebugIcon.innerHTML = '<span style="font-size:18px;">\uD83D\uDC1B</span>'
145
- + '<span class="dbg-badge" style="position:absolute;top:-4px;right:-4px;background:#ff6b6b;color:#fff;font-size:10px;border-radius:50%;width:18px;height:18px;display:flex;align-items:center;justify-content:center;">0</span>';
146
- _eDebugIcon.style.cssText = 'position:fixed;top:10px;right:70px;z-index:999999;width:36px;height:36px;background:#1e1e2e;border:1px solid #444;border-radius:50%;display:flex;align-items:center;justify-content:center;cursor:pointer;box-shadow:0 2px 8px rgba(0,0,0,0.4);user-select:none;';
147
- _eDebugIcon.onclick = function() {
148
- _eDebugPanel.style.display = _eDebugPanel.style.display === 'none' ? 'flex' : 'none';
149
- };
150
- document.body.appendChild(_eDebugIcon);
151
-
152
- _eDebugPanel = document.createElement('div');
153
- _eDebugPanel.id = 'codeapp-debug-panel';
154
- _eDebugPanel.style.cssText = 'position:fixed;top:0;right:0;z-index:999998;width:420px;height:100vh;background:#16161e;color:#e0e0e0;font-family:monospace;display:none;flex-direction:column;box-shadow:-4px 0 16px rgba(0,0,0,0.5);';
155
-
156
- let eHeader = document.createElement('div');
157
- eHeader.style.cssText = 'padding:10px 12px;background:#1e1e2e;border-bottom:1px solid #333;display:flex;justify-content:space-between;align-items:center;flex-shrink:0;';
158
- eHeader.innerHTML = '<span style="font-weight:bold;font-size:14px;">\uD83D\uDC1B codeapp.js Debugger</span>';
159
- let eClear = document.createElement('button');
160
- eClear.textContent = 'Clear';
161
- eClear.style.cssText = 'background:#333;color:#e0e0e0;border:1px solid #555;border-radius:4px;padding:3px 10px;cursor:pointer;font-size:12px;';
162
- eClear.onclick = function() {
163
- _aDebugEntries = [];
164
- _eDebugList.innerHTML = '';
165
- let eBadge = _eDebugIcon.querySelector('.dbg-badge');
166
- if (eBadge) eBadge.textContent = '0';
167
- };
168
- eHeader.appendChild(eClear);
169
- _eDebugPanel.appendChild(eHeader);
170
-
171
- _eDebugList = document.createElement('div');
172
- _eDebugList.style.cssText = 'flex:1;overflow-y:auto;';
173
- _eDebugPanel.appendChild(_eDebugList);
174
- document.body.appendChild(_eDebugPanel);
175
-
176
- // Render entries logged before UI was ready
177
- _aDebugEntries.slice().reverse().forEach(function(oEntry) {
178
- _dbgRenderEntry(oEntry, false);
179
- });
180
- }
181
-
182
- export function enableDebugger() {
183
- console.warn("Debug mode enabled: all API calls will be logged in the debug panel. Call enableDebugger() only in development environments.");
184
- if (_bDebugActive) return;
185
- _bDebugActive = true;
186
- if (document.body) {
187
- _dbgInjectUI();
188
- } else {
189
- document.addEventListener('DOMContentLoaded', _dbgInjectUI);
190
- }
191
- }
192
-
193
- // ── Get Environment Variable (single query with expand) ────────
194
- export async function getEnvironmentVariable(sSchemaName) {
195
- return _dbgWrap('getEnvironmentVariable', [sSchemaName], async function() {
196
- let client = getSharedClient();
197
-
198
- // Try single query: filter values by expanded definition schema name
199
- let valResult = await client.retrieveMultipleRecordsAsync("environmentvariablevalues", {
200
- filter: "EnvironmentVariableDefinitionId/schemaname eq '" + sSchemaName + "'",
201
- select: ["value"],
202
- expand: [{ name: "EnvironmentVariableDefinitionId", select: ["defaultvalue", "schemaname"] }],
203
- });
204
- let aVals = unwrapResult(valResult);
205
-
206
- // If value record exists, return it
207
- if (Array.isArray(aVals) && aVals.length > 0 && aVals[0].value) {
208
- return aVals[0].value;
209
- }
210
-
211
- // No value record — fall back to definition default value
212
- let defResult = await client.retrieveMultipleRecordsAsync("environmentvariabledefinitions", {
213
- filter: "schemaname eq '" + sSchemaName + "'",
214
- select: ["defaultvalue"],
215
- });
216
- let aDefs = unwrapResult(defResult);
217
- if (!Array.isArray(aDefs) || aDefs.length === 0) {
218
- throw new Error("Environment variable not found: " + sSchemaName);
219
- }
220
- return aDefs[0].defaultvalue || "";
221
- });
222
- }
223
-
224
- // ────────────────────────────────────────────────────────────────────────────
225
- // ─────────────────────────────── Dataverse ──────────────────────────────────
226
- // ────────────────────────────────────────────────────────────────────────────
227
-
228
- // ── Table Registry (populated at runtime via registerTable) ────
229
- let oDataSources = {};
230
-
231
- // ── Register a Dataverse table for use by the library ──────────
232
- export function registerTable(sTableName, sPrimaryKey) {
233
- return _dbgWrap('registerTable', [sTableName, sPrimaryKey], function() {
234
- oDataSources[sTableName] = {
235
- tableId: '',
236
- version: '',
237
- primaryKey: sPrimaryKey,
238
- dataSourceType: 'Dataverse',
239
- apis: {}
240
- };
241
- // reset client so it picks up the new table on next call
242
- oSharedClient = null;
243
- });
244
- }
245
-
246
- // ── Ensure value is an array (accepts array or comma-separated string)
247
- function ensureArray(value) {
248
- if (!value) return value;
249
- if (Array.isArray(value)) return value;
250
- if (typeof value === 'string') return value.split(',').map(function (s) { return s.trim(); });
251
- return value;
252
- }
253
-
254
- // ── Create ─────────────────────────────────────────────────────
255
- export async function createItem(tableName, primaryKey, record) {
256
- return _dbgWrap('createItem', [tableName, primaryKey, record], async function() {
257
- const client = getSharedClient();
258
- const result = await client.createRecordAsync(tableName, record);
259
- return unwrapResult(result);
260
- });
261
- }
262
-
263
- // ── Read (single) ──────────────────────────────────────────────
264
- export async function getItem(tableName, primaryKey, id, select) {
265
- return _dbgWrap('getItem', [tableName, primaryKey, id, select], async function() {
266
- const client = getSharedClient();
267
- select = ensureArray(select);
268
- const options = select ? { select } : undefined;
269
- const result = await client.retrieveRecordAsync(tableName, id, options);
270
- return unwrapResult(result);
271
- });
272
- }
273
-
274
- // ── List (multiple) ────────────────────────────────────────────
275
- export async function listItems(tableName, primaryKey, { filter, select, orderBy, top, skip } = {}) {
276
- return _dbgWrap('listItems', [tableName, primaryKey, { filter, select, orderBy, top, skip }], async function() {
277
- const client = getSharedClient();
278
- select = ensureArray(select);
279
- orderBy = ensureArray(orderBy);
280
- const result = await client.retrieveMultipleRecordsAsync(tableName, {
281
- filter,
282
- select,
283
- orderBy,
284
- top,
285
- skip,
286
- });
287
- var unwrapped = unwrapResult(result);
288
- return { entities: Array.isArray(unwrapped) ? unwrapped : [] };
289
- });
290
- }
291
-
292
- // ── Update ─────────────────────────────────────────────────────
293
- export async function updateItem(tableName, primaryKey, id, changedFields) {
294
- return _dbgWrap('updateItem', [tableName, primaryKey, id, changedFields], async function() {
295
- const client = getSharedClient();
296
- const result = await client.updateRecordAsync(tableName, id, changedFields);
297
- return unwrapResult(result);
298
- });
299
- }
300
-
301
- // ── Delete ─────────────────────────────────────────────────────
302
- export async function deleteItem(tableName, primaryKey, id) {
303
- return _dbgWrap('deleteItem', [tableName, primaryKey, id], async function() {
304
- const client = getSharedClient();
305
- const result = await client.deleteRecordAsync(tableName, id);
306
- return unwrapResult(result);
307
- });
308
- }
309
-
310
- // ── Unbound Action ─────────────────────────────────────────────
311
- export async function callUnboundAction(tableName, primaryKey, actionName, params) {
312
- return _dbgWrap('callUnboundAction', [tableName, primaryKey, actionName, params], async function() {
313
- var oAllSources = Object.assign({}, oInitialDataSources, oDataSources);
314
- var result = await callActionAsync(oAllSources, actionName, params || {});
315
- return unwrapResult(result);
316
- });
317
- }
318
-
319
- // ── WhoAmI ─────────────────────────────────────────────────────
320
- export async function whoAmI() {
321
- return _dbgWrap('whoAmI', [], async function() {
322
- var oAllSources = Object.assign({}, oInitialDataSources, oDataSources);
323
- var result = await callActionAsync(oAllSources, 'WhoAmI', {});
324
- var data = unwrapResult(result);
325
- return data.UserId || data.userid || data.systemuserid || data;
326
- });
327
- }
328
-
329
- // ────────────────────────────────────────────────────────────────────────────
330
- // ─────────────────────────────── SharePoint ─────────────────────────────────
331
- // ────────────────────────────────────────────────────────────────────────────
332
-
333
- // ── Data source name (must match connectionReferences in power.config.json) ──
334
- const DATA_SOURCE_SP = "sharepointonline";
335
-
336
- // ── Initialize SDK client for the SharePoint connector ─────────
337
- function initSpClient() {
338
- const dataSourcesInfo = {
339
- [DATA_SOURCE_SP]: {
340
- tableId: "",
341
- version: "",
342
- primaryKey: "",
343
- dataSourceType: "Connector",
344
- apis: {
345
- GetItems: {
346
- path: "/{connectionId}/datasets/{siteUrl}/tables/{table}/items",
347
- method: "GET",
348
- parameters: [
349
- { name: "connectionId", in: "path", required: true },
350
- { name: "siteUrl", in: "path", required: true },
351
- { name: "table", in: "path", required: true },
352
- { name: "$filter", in: "query", required: false },
353
- { name: "$orderby", in: "query", required: false },
354
- { name: "$top", in: "query", required: false },
355
- { name: "$skip", in: "query", required: false },
356
- ],
357
- },
358
- GetItem: {
359
- path: "/{connectionId}/datasets/{siteUrl}/tables/{table}/items/{id}",
360
- method: "GET",
361
- parameters: [
362
- { name: "connectionId", in: "path", required: true },
363
- { name: "siteUrl", in: "path", required: true },
364
- { name: "table", in: "path", required: true },
365
- { name: "id", in: "path", required: true },
366
- ],
367
- },
368
- PostItem: {
369
- path: "/{connectionId}/datasets/{siteUrl}/tables/{table}/items",
370
- method: "POST",
371
- parameters: [
372
- { name: "connectionId", in: "path", required: true },
373
- { name: "siteUrl", in: "path", required: true },
374
- { name: "table", in: "path", required: true },
375
- { name: "item", in: "body", required: true },
376
- ],
377
- },
378
- PatchItem: {
379
- path: "/{connectionId}/datasets/{siteUrl}/tables/{table}/items/{id}",
380
- method: "PATCH",
381
- parameters: [
382
- { name: "connectionId", in: "path", required: true },
383
- { name: "siteUrl", in: "path", required: true },
384
- { name: "table", in: "path", required: true },
385
- { name: "id", in: "path", required: true },
386
- { name: "item", in: "body", required: true },
387
- ],
388
- },
389
- DeleteItem: {
390
- path: "/{connectionId}/datasets/{siteUrl}/tables/{table}/items/{id}",
391
- method: "DELETE",
392
- parameters: [
393
- { name: "connectionId", in: "path", required: true },
394
- { name: "siteUrl", in: "path", required: true },
395
- { name: "table", in: "path", required: true },
396
- { name: "id", in: "path", required: true },
397
- ],
398
- },
399
- GetTables: {
400
- path: "/{connectionId}/datasets/{siteUrl}/tables",
401
- method: "GET",
402
- parameters: [
403
- { name: "connectionId", in: "path", required: true },
404
- { name: "siteUrl", in: "path", required: true },
405
- ],
406
- },
407
- GetDataSetsMetadata: {
408
- path: "/{connectionId}/datasets/{siteUrl}",
409
- method: "GET",
410
- parameters: [
411
- { name: "connectionId", in: "path", required: true },
412
- { name: "siteUrl", in: "path", required: true },
413
- ],
414
- },
415
- CreateFile: {
416
- path: "/{connectionId}/datasets/{siteUrl}/files",
417
- method: "POST",
418
- parameters: [
419
- { name: "connectionId", in: "path", required: true },
420
- { name: "siteUrl", in: "path", required: true },
421
- { name: "folderPath", in: "query", required: true },
422
- { name: "name", in: "query", required: true },
423
- { name: "body", in: "body", required: true },
424
- ],
425
- },
426
- UpdateFile: {
427
- path: "/{connectionId}/datasets/{siteUrl}/files/{id}",
428
- method: "PUT",
429
- parameters: [
430
- { name: "connectionId", in: "path", required: true },
431
- { name: "siteUrl", in: "path", required: true },
432
- { name: "id", in: "path", required: true },
433
- { name: "body", in: "body", required: true },
434
- ],
435
- },
436
- DeleteFile: {
437
- path: "/{connectionId}/datasets/{siteUrl}/files/{id}",
438
- method: "DELETE",
439
- parameters: [
440
- { name: "connectionId", in: "path", required: true },
441
- { name: "siteUrl", in: "path", required: true },
442
- { name: "id", in: "path", required: true },
443
- ],
444
- },
445
- MoveFile: {
446
- path: "/{connectionId}/datasets/{siteUrl}/files/{id}/moveto",
447
- method: "POST",
448
- parameters: [
449
- { name: "connectionId", in: "path", required: true },
450
- { name: "siteUrl", in: "path", required: true },
451
- { name: "id", in: "path", required: true },
452
- { name: "destinationFolderPath", in: "query", required: true },
453
- { name: "newFileName", in: "query", required: false },
454
- ],
455
- },
456
- GetFileMetadata: {
457
- path: "/{connectionId}/datasets/{siteUrl}/files/{id}",
458
- method: "GET",
459
- parameters: [
460
- { name: "connectionId", in: "path", required: true },
461
- { name: "siteUrl", in: "path", required: true },
462
- { name: "id", in: "path", required: true },
463
- ],
464
- },
465
- HttpRequest: {
466
- path: "/{connectionId}/httprequest",
467
- method: "POST",
468
- parameters: [
469
- { name: "connectionId", in: "path", required: true },
470
- ],
471
- },
472
- },
473
- },
474
- };
475
- return getClient(dataSourcesInfo);
476
- }
477
-
478
- // ── Internal: execute a connector operation ────────────────────
479
- async function execSpOp(operationName, parameters) {
480
- const client = await initSpClient();
481
- const result = await client.executeAsync({
482
- connectorOperation: {
483
- tableName: DATA_SOURCE_SP,
484
- operationName,
485
- parameters,
486
- },
487
- });
488
- if (!result.success) {
489
- throw new Error(result.error?.message || "Operation failed");
490
- }
491
- return result.data;
492
- }
493
-
494
- // ═══════════════════════════════════════════════════════════════
495
- // GENERIC
496
- // ═══════════════════════════════════════════════════════════════
497
-
498
- // ── Call any SharePoint connector operation by name ─────────────
499
- export async function callSharePointOperation(operationName, parameters = {}) {
500
- return _dbgWrap('callSharePointOperation', [operationName, parameters], async function() {
501
- return execSpOp(operationName, parameters);
502
- });
503
- }
504
-
505
- // ── Send HTTP Request (for list-name-based operations) ─────────
506
- export async function sendHttpRequest({ method = "GET", uri, headers, body }) {
507
- return _dbgWrap('sendHttpRequest', [{ method, uri, headers, body }], async function() {
508
- return execSpOp("HttpRequest", {
509
- method,
510
- uri,
511
- headers: headers || {},
512
- body: body || "",
513
- });
514
- });
515
- }
516
-
517
- // ═══════════════════════════════════════════════════════════════
518
- // ITEMS (standard API — uses list ID)
519
- // ═══════════════════════════════════════════════════════════════
520
-
521
- // ── Get Items ──────────────────────────────────────────────────
522
- export async function getItems(sSiteUrl, sListId, { filter, orderBy, top, skip } = {}) {
523
- return _dbgWrap('getItems', [sSiteUrl, sListId, { filter, orderBy, top, skip }], async function() {
524
- let params = { siteUrl: encodeURIComponent(sSiteUrl), table: sListId };
525
- if (filter) params.$filter = filter;
526
- if (orderBy) params.$orderby = orderBy;
527
- if (top != null) params.$top = top;
528
- if (skip != null) params.$skip = skip;
529
- return execSpOp("GetItems", params);
530
- });
531
- }
532
-
533
- // ── Get Item ───────────────────────────────────────────────────
534
- export async function getSpItem(sSiteUrl, sListId, iItemId) {
535
- return _dbgWrap('getSpItem', [sSiteUrl, sListId, iItemId], async function() {
536
- return execSpOp("GetItem", {
537
- siteUrl: encodeURIComponent(sSiteUrl),
538
- table: sListId,
539
- id: iItemId,
540
- });
541
- });
542
- }
543
-
544
- // ── Create Item ────────────────────────────────────────────────
545
- export async function createSpItem(sSiteUrl, sListId, oFields) {
546
- return _dbgWrap('createSpItem', [sSiteUrl, sListId, oFields], async function() {
547
- return execSpOp("PostItem", {
548
- siteUrl: encodeURIComponent(sSiteUrl),
549
- table: sListId,
550
- item: oFields,
551
- });
552
- });
553
- }
554
-
555
- // ── Update Item ────────────────────────────────────────────────
556
- export async function updateSpItem(sSiteUrl, sListId, iItemId, oChangedFields) {
557
- return _dbgWrap('updateSpItem', [sSiteUrl, sListId, iItemId, oChangedFields], async function() {
558
- return execSpOp("PatchItem", {
559
- siteUrl: encodeURIComponent(sSiteUrl),
560
- table: sListId,
561
- id: iItemId,
562
- item: oChangedFields,
563
- });
564
- });
565
- }
566
-
567
- // ── Delete Item ────────────────────────────────────────────────
568
- export async function deleteSpItem(sSiteUrl, sListId, iItemId) {
569
- return _dbgWrap('deleteSpItem', [sSiteUrl, sListId, iItemId], async function() {
570
- return execSpOp("DeleteItem", {
571
- siteUrl: encodeURIComponent(sSiteUrl),
572
- table: sListId,
573
- id: iItemId,
574
- });
575
- });
576
- }
577
-
578
- // ═══════════════════════════════════════════════════════════════
579
- // ITEMS (HTTP API — uses list name)
580
- // ═══════════════════════════════════════════════════════════════
581
-
582
- // ── Get Items by List Name ─────────────────────────────────────
583
- export async function getItemsByName(sSiteUrl, sListName, { filter, orderBy, top, skip } = {}) {
584
- return _dbgWrap('getItemsByName', [sSiteUrl, sListName, { filter, orderBy, top, skip }], async function() {
585
- let sUri = sSiteUrl + "/_api/web/lists/getbytitle('" + sListName + "')/items";
586
- let aQuery = [];
587
- if (filter) aQuery.push("$filter=" + filter);
588
- if (orderBy) aQuery.push("$orderby=" + orderBy);
589
- if (top != null) aQuery.push("$top=" + top);
590
- if (skip != null) aQuery.push("$skip=" + skip);
591
- if (aQuery.length > 0) sUri = sUri + "?" + aQuery.join("&");
592
- return sendHttpRequest({ method: "GET", uri: sUri, headers: { Accept: "application/json;odata=nometadata" } });
593
- });
594
- }
595
-
596
- // ── Get Item by List Name ──────────────────────────────────────
597
- export async function getItemByName(sSiteUrl, sListName, iItemId) {
598
- return _dbgWrap('getItemByName', [sSiteUrl, sListName, iItemId], async function() {
599
- let sUri = sSiteUrl + "/_api/web/lists/getbytitle('" + sListName + "')/items(" + iItemId + ")";
600
- return sendHttpRequest({ method: "GET", uri: sUri, headers: { Accept: "application/json;odata=nometadata" } });
601
- });
602
- }
603
-
604
- // ── Create Item by List Name ───────────────────────────────────
605
- export async function createItemByName(sSiteUrl, sListName, oFields) {
606
- return _dbgWrap('createItemByName', [sSiteUrl, sListName, oFields], async function() {
607
- let sUri = sSiteUrl + "/_api/web/lists/getbytitle('" + sListName + "')/items";
608
- return sendHttpRequest({ method: "POST", uri: sUri, headers: { Accept: "application/json;odata=nometadata", "Content-Type": "application/json;odata=nometadata" }, body: JSON.stringify(oFields) });
609
- });
610
- }
611
-
612
- // ── Update Item by List Name ───────────────────────────────────
613
- export async function updateItemByName(sSiteUrl, sListName, iItemId, oChangedFields) {
614
- return _dbgWrap('updateItemByName', [sSiteUrl, sListName, iItemId, oChangedFields], async function() {
615
- let sUri = sSiteUrl + "/_api/web/lists/getbytitle('" + sListName + "')/items(" + iItemId + ")";
616
- return sendHttpRequest({ method: "PATCH", uri: sUri, headers: { Accept: "application/json;odata=nometadata", "Content-Type": "application/json;odata=nometadata", "If-Match": "*" }, body: JSON.stringify(oChangedFields) });
617
- });
618
- }
619
-
620
- // ── Delete Item by List Name ───────────────────────────────────
621
- export async function deleteItemByName(sSiteUrl, sListName, iItemId) {
622
- return _dbgWrap('deleteItemByName', [sSiteUrl, sListName, iItemId], async function() {
623
- let sUri = sSiteUrl + "/_api/web/lists/getbytitle('" + sListName + "')/items(" + iItemId + ")";
624
- return sendHttpRequest({ method: "DELETE", uri: sUri, headers: { Accept: "application/json;odata=nometadata", "If-Match": "*" } });
625
- });
626
- }
627
-
628
- // ═══════════════════════════════════════════════════════════════
629
- // TABLES / LISTS
630
- // ═══════════════════════════════════════════════════════════════
631
-
632
- // ── List Tables (Lists) ────────────────────────────────────────
633
- export async function listTables(sSiteUrl) {
634
- return _dbgWrap('listTables', [sSiteUrl], async function() {
635
- return execSpOp("GetTables", {
636
- siteUrl: encodeURIComponent(sSiteUrl),
637
- });
638
- });
639
- }
640
-
641
- // ── List Library (Document Libraries) ──────────────────────────
642
- export async function listLibrary(sSiteUrl) {
643
- return _dbgWrap('listLibrary', [sSiteUrl], async function() {
644
- return execSpOp("GetDataSetsMetadata", {
645
- siteUrl: encodeURIComponent(sSiteUrl),
646
- });
647
- });
648
- }
649
-
650
- // ═══════════════════════════════════════════════════════════════
651
- // FILES
652
- // ═══════════════════════════════════════════════════════════════
653
-
654
- // ── Create File ────────────────────────────────────────────────
655
- export async function createFile(sSiteUrl, sLibraryName, sFileName, fileContent) {
656
- return _dbgWrap('createFile', [sSiteUrl, sLibraryName, sFileName, fileContent], async function() {
657
- return execSpOp("CreateFile", {
658
- siteUrl: encodeURIComponent(sSiteUrl),
659
- folderPath: sLibraryName,
660
- name: sFileName,
661
- body: fileContent,
662
- });
663
- });
664
- }
665
-
666
- // ── Update File ────────────────────────────────────────────────
667
- export async function updateFile(sSiteUrl, sFileId, fileContent) {
668
- return _dbgWrap('updateFile', [sSiteUrl, sFileId, fileContent], async function() {
669
- return execSpOp("UpdateFile", {
670
- siteUrl: encodeURIComponent(sSiteUrl),
671
- id: sFileId,
672
- body: fileContent,
673
- });
674
- });
675
- }
676
-
677
- // ── Delete File ────────────────────────────────────────────────
678
- export async function deleteFile(sSiteUrl, sFileId) {
679
- return _dbgWrap('deleteFile', [sSiteUrl, sFileId], async function() {
680
- return execSpOp("DeleteFile", {
681
- siteUrl: encodeURIComponent(sSiteUrl),
682
- id: sFileId,
683
- });
684
- });
685
- }
686
-
687
- // ── Move File ──────────────────────────────────────────────────
688
- export async function moveFile(sSiteUrl, sSourceFileId, sDestinationFolderPath, sNewFileName) {
689
- return _dbgWrap('moveFile', [sSiteUrl, sSourceFileId, sDestinationFolderPath, sNewFileName], async function() {
690
- return execSpOp("MoveFile", {
691
- siteUrl: encodeURIComponent(sSiteUrl),
692
- id: sSourceFileId,
693
- destinationFolderPath: sDestinationFolderPath,
694
- newFileName: sNewFileName || "",
695
- });
696
- });
697
- }
698
-
699
- // ── Get File Metadata ──────────────────────────────────────────
700
- export async function getFileMetadata(sSiteUrl, sFileId) {
701
- return _dbgWrap('getFileMetadata', [sSiteUrl, sFileId], async function() {
702
- return execSpOp("GetFileMetadata", {
703
- siteUrl: encodeURIComponent(sSiteUrl),
704
- id: sFileId,
705
- });
706
- });
707
- }
708
-
709
- // ────────────────────────────────────────────────────────────────────────────
710
- // ────────────────────────────── Outlook365 ──────────────────────────────────
711
- // ────────────────────────────────────────────────────────────────────────────
712
-
713
- // ── Data source name (must match connectionReferences in power.config.json) ──
714
- const DATA_SOURCE_CANDIDATES = ["office365outlook", "Office365Outlook", "office365"];
715
- const OUTLOOK_APIS = {
716
- GetEmailsV3: {
717
- path: "/{connectionId}/v3/Mail",
718
- method: "GET",
719
- parameters: [
720
- { name: "connectionId", in: "path", required: true },
721
- { name: "folderPath", in: "query", required: false },
722
- { name: "to", in: "query", required: false },
723
- { name: "cc", in: "query", required: false },
724
- { name: "toOrCc", in: "query", required: false },
725
- { name: "from", in: "query", required: false },
726
- { name: "importance", in: "query", required: false },
727
- { name: "fetchOnlyWithAttachment", in: "query", required: false },
728
- { name: "subjectFilter", in: "query", required: false },
729
- { name: "fetchOnlyUnread", in: "query", required: false },
730
- { name: "fetchOnlyFlagged", in: "query", required: false },
731
- { name: "mailboxAddress", in: "query", required: false },
732
- { name: "includeAttachments", in: "query", required: false },
733
- { name: "searchQuery", in: "query", required: false },
734
- { name: "top", in: "query", required: false },
735
- ],
736
- },
737
- };
738
-
739
- // ── Initialize SDK client for the Office 365 Outlook connector ──
740
- function initOutlookClient() {
741
- const dataSourcesInfo = {};
742
-
743
- DATA_SOURCE_CANDIDATES.forEach((sDataSourceName) => {
744
- dataSourcesInfo[sDataSourceName] = {
745
- tableId: "",
746
- version: "",
747
- primaryKey: "",
748
- dataSourceType: "Connector",
749
- apis: OUTLOOK_APIS,
750
- };
751
- });
752
-
753
- return getClient(dataSourcesInfo);
754
- }
755
-
756
- function stringifyOutlookError(oError) {
757
- if (!oError) return "Operation failed";
758
- if (typeof oError === "string") return oError;
759
- if (oError instanceof Error) return oError.message || "Operation failed";
760
-
761
- var aPropertyNames = Object.getOwnPropertyNames(oError);
762
- var oSerializable = {};
763
- aPropertyNames.forEach((sName) => {
764
- oSerializable[sName] = oError[sName];
765
- });
766
-
767
- try {
768
- return JSON.stringify(oSerializable);
769
- } catch {
770
- return String(oError);
771
- }
772
- }
773
-
774
- function unwrapOutlookResult(oResult) {
775
- if (oResult && oResult.success === false) {
776
- var sMessage = stringifyOutlookError(oResult.error);
777
- if (oResult.data !== undefined) {
778
- sMessage += " | data: " + stringifyOutlookError(oResult.data);
779
- }
780
- throw new Error(sMessage);
781
- }
782
-
783
- if (oResult && Object.prototype.hasOwnProperty.call(oResult, "data")) {
784
- return oResult.data;
785
- }
786
-
787
- return oResult;
788
- }
789
-
790
- // ── Internal: execute a connector operation ────────────────────
791
- async function execOutlookOp(operationName, parameters) {
792
- const client = await initOutlookClient();
793
- const aErrors = [];
794
-
795
- for (let iIndex = 0; iIndex < DATA_SOURCE_CANDIDATES.length; iIndex += 1) {
796
- const sDataSourceName = DATA_SOURCE_CANDIDATES[iIndex];
797
-
798
- try {
799
- const result = await client.executeAsync({
800
- connectorOperation: {
801
- tableName: sDataSourceName,
802
- operationName,
803
- parameters,
804
- },
805
- });
806
-
807
- return unwrapOutlookResult(result);
808
- } catch (oErr) {
809
- const sMessage = stringifyOutlookError(oErr);
810
- aErrors.push(sDataSourceName + ": " + sMessage);
811
-
812
- if (sMessage.indexOf("Connection reference not found") === -1) {
813
- throw oErr;
814
- }
815
- }
816
- }
817
-
818
- throw new Error("No Outlook connection reference matched. Tried: " + aErrors.join(" || "));
819
- }
820
-
821
- // ── List Emails ────────────────────────────────────────────────
822
- export async function listEmails({ folderId = "Inbox", fetchOnlyUnread, searchQuery, top, skip } = {}) {
823
- return _dbgWrap('listEmails', [{ folderId, fetchOnlyUnread, searchQuery, top, skip }], async function() {
824
- void skip;
825
-
826
- return execOutlookOp("GetEmailsV3", {
827
- folderPath: folderId,
828
- fetchOnlyUnread,
829
- searchQuery,
830
- top: top != null ? top : 10,
831
- });
832
- });
833
- }
834
-
835
- // ────────────────────────────────────────────────────────────────────────────
836
- // ─────────────────────────────── O365 User ──────────────────────────────────
837
- // ────────────────────────────────────────────────────────────────────────────
838
-
839
- // ── Data source name (must match connectionReferences in power.config.json) ──
840
- const DATA_SOURCE_USERS = "office365users";
841
-
842
- // ── Initialize SDK client for the Office 365 Users connector ───
843
- function initUsersClient() {
844
- const dataSourcesInfo = {
845
- [DATA_SOURCE_USERS]: {
846
- tableId: "",
847
- version: "",
848
- primaryKey: "",
849
- dataSourceType: "Connector",
850
- apis: {
851
- MyProfile_V2: {
852
- path: "/{connectionId}/codeless/v1.0/me",
853
- method: "GET",
854
- parameters: [
855
- { name: "connectionId", in: "path", required: true },
856
- ],
857
- },
858
- UserProfile_V2: {
859
- path: "/{connectionId}/codeless/v1.0/users/{id}",
860
- method: "GET",
861
- parameters: [
862
- { name: "connectionId", in: "path", required: true },
863
- { name: "id", in: "path", required: true },
864
- ],
865
- },
866
- Manager_V2: {
867
- path: "/{connectionId}/codeless/v1.0/users/{id}/manager",
868
- method: "GET",
869
- parameters: [
870
- { name: "connectionId", in: "path", required: true },
871
- { name: "id", in: "path", required: true },
872
- ],
873
- },
874
- DirectReports_V2: {
875
- path: "/{connectionId}/codeless/v1.0/users/{id}/directReports",
876
- method: "GET",
877
- parameters: [
878
- { name: "connectionId", in: "path", required: true },
879
- { name: "id", in: "path", required: true },
880
- ],
881
- },
882
- UserPhoto_V2: {
883
- path: "/{connectionId}/codeless/v1.0/users/{id}/photo/$value",
884
- method: "GET",
885
- parameters: [
886
- { name: "connectionId", in: "path", required: true },
887
- { name: "id", in: "path", required: true },
888
- ],
889
- responseInfo: { "200": "image/jpeg" },
890
- },
891
- SearchUser_V2: {
892
- path: "/{connectionId}/codeless/v1.0/users",
893
- method: "GET",
894
- parameters: [
895
- { name: "connectionId", in: "path", required: true },
896
- { name: "searchTerm", in: "query", required: false },
897
- { name: "$top", in: "query", required: false },
898
- { name: "$skip", in: "query", required: false },
899
- ],
900
- },
901
- HttpRequest: {
902
- path: "/{connectionId}/codeless/v1.0/httprequest",
903
- method: "POST",
904
- parameters: [
905
- { name: "connectionId", in: "path", required: true },
906
- ],
907
- },
908
- },
909
- },
910
- };
911
- return getClient(dataSourcesInfo);
912
- }
913
-
914
- // ── Internal: execute a connector operation ────────────────────
915
- async function execUsersOp(operationName, parameters) {
916
- const client = await initUsersClient();
917
- const result = await client.executeAsync({
918
- connectorOperation: {
919
- tableName: DATA_SOURCE_USERS,
920
- operationName,
921
- parameters,
922
- },
923
- });
924
- if (!result.success) {
925
- throw new Error(result.error?.message || "Operation failed");
926
- }
927
- return result.data;
928
- }
929
-
930
- // ═══════════════════════════════════════════════════════════════
931
- // GENERIC
932
- // ═══════════════════════════════════════════════════════════════
933
-
934
- // ── Call any Office 365 Users operation by name ────────────────
935
- export async function callUsersOperation(operationName, parameters = {}) {
936
- return _dbgWrap('callUsersOperation', [operationName, parameters], async function() {
937
- return execUsersOp(operationName, parameters);
938
- });
939
- }
940
-
941
- // ── Open HTTP Request ──────────────────────────────────────────
942
- export async function openUsersHttpRequest({ method = "GET", uri, headers, body }) {
943
- return _dbgWrap('openUsersHttpRequest', [{ method, uri, headers, body }], async function() {
944
- return execUsersOp("HttpRequest", {
945
- method,
946
- uri,
947
- headers: headers || {},
948
- body: body || "",
949
- });
950
- });
951
- }
952
-
953
- // ═══════════════════════════════════════════════════════════════
954
- // PROFILE
955
- // ═══════════════════════════════════════════════════════════════
956
-
957
- // ── Get My Profile ─────────────────────────────────────────────
958
- export async function getMyProfile() {
959
- return _dbgWrap('getMyProfile', [], async function() {
960
- return execUsersOp("MyProfile_V2", {});
961
- });
962
- }
963
-
964
- // ── Get User Profile ───────────────────────────────────────────
965
- export async function getUserProfile(userId) {
966
- return _dbgWrap('getUserProfile', [userId], async function() {
967
- return execUsersOp("UserProfile_V2", {
968
- id: userId,
969
- });
970
- });
971
- }
972
-
973
- // ═══════════════════════════════════════════════════════════════
974
- // MANAGER & REPORTS
975
- // ═══════════════════════════════════════════════════════════════
976
-
977
- // ── Get Manager ────────────────────────────────────────────────
978
- export async function getManager(userId) {
979
- return _dbgWrap('getManager', [userId], async function() {
980
- return execUsersOp("Manager_V2", {
981
- id: userId,
982
- });
983
- });
984
- }
985
-
986
- // ── Get Direct Reports ─────────────────────────────────────────
987
- export async function getDirectReports(userId) {
988
- return _dbgWrap('getDirectReports', [userId], async function() {
989
- return execUsersOp("DirectReports_V2", {
990
- id: userId,
991
- });
992
- });
993
- }
994
-
995
- // ═══════════════════════════════════════════════════════════════
996
- // PHOTO
997
- // ═══════════════════════════════════════════════════════════════
998
-
999
- // ── Get User Photo ─────────────────────────────────────────────
1000
- export async function getUserPhoto(userId) {
1001
- return _dbgWrap('getUserPhoto', [userId], async function() {
1002
- return execUsersOp("UserPhoto_V2", {
1003
- id: userId,
1004
- });
1005
- });
1006
- }
1007
-
1008
- // ═══════════════════════════════════════════════════════════════
1009
- // SEARCH
1010
- // ═══════════════════════════════════════════════════════════════
1011
-
1012
- // ── Search for Users ───────────────────────────────────────────
1013
- export async function searchForUsers({ searchTerm, top, skip } = {}) {
1014
- return _dbgWrap('searchForUsers', [{ searchTerm, top, skip }], async function() {
1015
- const params = {};
1016
- if (searchTerm) params.searchTerm = searchTerm;
1017
- if (top != null) params.$top = top;
1018
- if (skip != null) params.$skip = skip;
1019
- return execUsersOp("SearchUser_V2", params);
1020
- });
1021
- }
1022
-
1023
- // ────────────────────────────────────────────────────────────────────────────
1024
- // ────────────────────────────── O365 Groups──────────────────────────────────
1025
- // ────────────────────────────────────────────────────────────────────────────
1026
-
1027
-
1028
- // ── Data source name (must match connectionReferences in power.config.json) ──
1029
- const DATA_SOURCE_GROUPS = "Office365Groups";
1030
-
1031
- // ── Initialize SDK client for the Office 365 Groups connector ──
1032
- function initGroupsClient() {
1033
- const dataSourcesInfo = {
1034
- [DATA_SOURCE_GROUPS]: {
1035
- tableId: "",
1036
- version: "",
1037
- primaryKey: "",
1038
- dataSourceType: "Connector",
1039
- apis: {},
1040
- },
1041
- };
1042
- return getClient(dataSourcesInfo);
1043
- }
1044
-
1045
- // ── Internal: execute a connector operation ────────────────────
1046
- async function execGroupsOp(operationName, parameters) {
1047
- const client = await initGroupsClient();
1048
- return client.executeAsync({
1049
- connectorOperation: {
1050
- tableName: DATA_SOURCE_GROUPS,
1051
- operationName,
1052
- parameters,
1053
- },
1054
- });
1055
- }
1056
-
1057
- // ═══════════════════════════════════════════════════════════════
1058
- // GENERIC
1059
- // ═══════════════════════════════════════════════════════════════
1060
-
1061
- // ── Call any Office 365 Groups operation by name ───────────────
1062
- export async function callGroupsOperation(operationName, parameters = {}) {
1063
- return _dbgWrap('callGroupsOperation', [operationName, parameters], async function() {
1064
- return execGroupsOp(operationName, parameters);
1065
- });
1066
- }
1067
-
1068
- // ── Open HTTP Request ──────────────────────────────────────────
1069
- export async function openGroupsHttpRequest({ method = "GET", uri, headers, body }) {
1070
- return _dbgWrap('openGroupsHttpRequest', [{ method, uri, headers, body }], async function() {
1071
- return execGroupsOp("HttpRequest", {
1072
- method,
1073
- uri,
1074
- headers: headers || {},
1075
- body: body || "",
1076
- });
1077
- });
1078
- }
1079
-
1080
- // ═══════════════════════════════════════════════════════════════
1081
- // GROUPS
1082
- // ═══════════════════════════════════════════════════════════════
1083
-
1084
- // ── List My Groups ─────────────────────────────────────────────
1085
- export async function listMyGroups() {
1086
- return _dbgWrap('listMyGroups', [], async function() {
1087
- return execGroupsOp("ListOwnedGroups", {});
1088
- });
1089
- }
1090
-
1091
- // ── List Members of a Group ────────────────────────────────────
1092
- export async function listGroupMembers(groupId) {
1093
- return _dbgWrap('listGroupMembers', [groupId], async function() {
1094
- return execGroupsOp("ListGroupMembers", {
1095
- groupId,
1096
- });
1097
- });
1098
- }