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
@@ -7,8 +7,8 @@ let oInitialDataSources = {};
7
7
  // ── Set initial data sources (call before any API calls) ───────
8
8
  export function initDataSources(oSources) {
9
9
  return _dbgWrap('initDataSources', [oSources], function() {
10
- oInitialDataSources = oSources || {};
11
- oSharedClient = null;
10
+ oInitialDataSources = oSources || {};
11
+ oSharedClient = null;
12
12
  });
13
13
  }
14
14
 
@@ -20,12 +20,24 @@ function getSharedClient() {
20
20
  }
21
21
 
22
22
  // ── Unwrap SDK response ────────────────────────────────────────
23
- function unwrapResult(result) {
23
+ export function unwrapResult(result) {
24
24
  if (result && result.success === false) {
25
- let sMsg = result.error ? (result.error.message || JSON.stringify(result.error)) : "Operation failed";
25
+ let sMsg = result.error ? (result.error.message || JSON.stringify(result.error)) : 'Operation failed';
26
26
  throw new Error(sMsg);
27
27
  }
28
- return result && "data" in result ? result.data : result;
28
+ return result && 'data' in result ? result.data : result;
29
+ }
30
+
31
+ function stringifyConnectorError(oError) {
32
+ if (!oError) return 'Unknown error';
33
+ if (typeof oError === 'string') return oError;
34
+ if (typeof oError.message === 'string' && oError.message) return oError.message;
35
+
36
+ try {
37
+ return JSON.stringify(oError);
38
+ } catch (oErr) {
39
+ return String(oError);
40
+ }
29
41
  }
30
42
 
31
43
  // ── Debugger ───────────────────────────────────────────────────
@@ -36,7 +48,7 @@ let _eDebugIcon = null;
36
48
  let _eDebugList = null;
37
49
  let _iDebugCounter = 0;
38
50
 
39
- function _dbgWrap(sName, aArgs, fnBody) {
51
+ export function _dbgWrap(sName, aArgs, fnBody) {
40
52
  if (!_bDebugActive) return fnBody();
41
53
  let oEntry = { iId: ++_iDebugCounter, sName: sName, aArgs: _dbgClone(aArgs), iTime: Date.now() };
42
54
  _aDebugEntries.unshift(oEntry);
@@ -181,7 +193,7 @@ function _dbgInjectUI() {
181
193
  }
182
194
 
183
195
  export function enableDebugger() {
184
- console.warn("Debug mode enabled: all API calls will be logged in the debug panel. Call enableDebugger() only in development environments.");
196
+ console.warn('Debug mode enabled: all API calls will be logged in the debug panel. Call enableDebugger() only in development environments.');
185
197
  if (_bDebugActive) return;
186
198
  _bDebugActive = true;
187
199
  if (document.body) {
@@ -194,31 +206,31 @@ export function enableDebugger() {
194
206
  // ── Get Environment Variable (single query with expand) ────────
195
207
  export async function getEnvironmentVariable(sSchemaName) {
196
208
  return _dbgWrap('getEnvironmentVariable', [sSchemaName], async function() {
197
- let client = getSharedClient();
209
+ let client = getSharedClient();
198
210
 
199
- // Try single query: filter values by expanded definition schema name
200
- let valResult = await client.retrieveMultipleRecordsAsync("environmentvariablevalues", {
201
- filter: "EnvironmentVariableDefinitionId/schemaname eq '" + sSchemaName + "'",
202
- select: ["value"],
203
- expand: [{ name: "EnvironmentVariableDefinitionId", select: ["defaultvalue", "schemaname"] }],
204
- });
205
- let aVals = unwrapResult(valResult);
211
+ // Try single query: filter values by expanded definition schema name
212
+ let valResult = await client.retrieveMultipleRecordsAsync('environmentvariablevalues', {
213
+ filter: "EnvironmentVariableDefinitionId/schemaname eq '" + sSchemaName + "'",
214
+ select: ['value'],
215
+ expand: [{ name: 'EnvironmentVariableDefinitionId', select: ['defaultvalue', 'schemaname'] }],
216
+ });
217
+ let aVals = unwrapResult(valResult);
206
218
 
207
- // If value record exists, return it
208
- if (Array.isArray(aVals) && aVals.length > 0 && aVals[0].value) {
209
- return aVals[0].value;
210
- }
219
+ // If value record exists, return it
220
+ if (Array.isArray(aVals) && aVals.length > 0 && aVals[0].value) {
221
+ return aVals[0].value;
222
+ }
211
223
 
212
- // No value record — fall back to definition default value
213
- let defResult = await client.retrieveMultipleRecordsAsync("environmentvariabledefinitions", {
214
- filter: "schemaname eq '" + sSchemaName + "'",
215
- select: ["defaultvalue"],
216
- });
217
- let aDefs = unwrapResult(defResult);
218
- if (!Array.isArray(aDefs) || aDefs.length === 0) {
219
- throw new Error("Environment variable not found: " + sSchemaName);
220
- }
221
- return aDefs[0].defaultvalue || "";
224
+ // No value record — fall back to definition default value
225
+ let defResult = await client.retrieveMultipleRecordsAsync('environmentvariabledefinitions', {
226
+ filter: "schemaname eq '" + sSchemaName + "'",
227
+ select: ['defaultvalue'],
228
+ });
229
+ let aDefs = unwrapResult(defResult);
230
+ if (!Array.isArray(aDefs) || aDefs.length === 0) {
231
+ throw new Error('Environment variable not found: ' + sSchemaName);
232
+ }
233
+ return aDefs[0].defaultvalue || '';
222
234
  });
223
235
  }
224
236
 
@@ -232,15 +244,15 @@ let oDataSources = {};
232
244
  // ── Register a Dataverse table for use by the library ──────────
233
245
  export function registerTable(sTableName, sPrimaryKey) {
234
246
  return _dbgWrap('registerTable', [sTableName, sPrimaryKey], function() {
235
- oDataSources[sTableName] = {
236
- tableId: '',
237
- version: '',
238
- primaryKey: sPrimaryKey,
239
- dataSourceType: 'Dataverse',
240
- apis: {}
241
- };
242
- // reset client so it picks up the new table on next call
243
- oSharedClient = null;
247
+ oDataSources[sTableName] = {
248
+ tableId: '',
249
+ version: '',
250
+ primaryKey: sPrimaryKey,
251
+ dataSourceType: 'Dataverse',
252
+ apis: {},
253
+ };
254
+ // reset client so it picks up the new table on next call
255
+ oSharedClient = null;
244
256
  });
245
257
  }
246
258
 
@@ -248,63 +260,63 @@ export function registerTable(sTableName, sPrimaryKey) {
248
260
  function ensureArray(value) {
249
261
  if (!value) return value;
250
262
  if (Array.isArray(value)) return value;
251
- if (typeof value === 'string') return value.split(',').map(function (s) { return s.trim(); });
263
+ if (typeof value === 'string') return value.split(',').map(function(s) { return s.trim(); });
252
264
  return value;
253
265
  }
254
266
 
255
267
  // ── Create ─────────────────────────────────────────────────────
256
268
  export async function createItem(tableName, primaryKey, record) {
257
269
  return _dbgWrap('createItem', [tableName, primaryKey, record], async function() {
258
- const client = getSharedClient();
259
- const result = await client.createRecordAsync(tableName, record);
260
- return unwrapResult(result);
270
+ const client = getSharedClient();
271
+ const result = await client.createRecordAsync(tableName, record);
272
+ return unwrapResult(result);
261
273
  });
262
274
  }
263
275
 
264
276
  // ── Read (single) ──────────────────────────────────────────────
265
277
  export async function getItem(tableName, primaryKey, id, select) {
266
278
  return _dbgWrap('getItem', [tableName, primaryKey, id, select], async function() {
267
- const client = getSharedClient();
268
- select = ensureArray(select);
269
- const options = select ? { select } : undefined;
270
- const result = await client.retrieveRecordAsync(tableName, id, options);
271
- return unwrapResult(result);
279
+ const client = getSharedClient();
280
+ select = ensureArray(select);
281
+ const options = select ? { select } : undefined;
282
+ const result = await client.retrieveRecordAsync(tableName, id, options);
283
+ return unwrapResult(result);
272
284
  });
273
285
  }
274
286
 
275
287
  // ── List (multiple) ────────────────────────────────────────────
276
288
  export async function listItems(tableName, primaryKey, { filter, select, orderBy, top, skip } = {}) {
277
289
  return _dbgWrap('listItems', [tableName, primaryKey, { filter, select, orderBy, top, skip }], async function() {
278
- const client = getSharedClient();
279
- select = ensureArray(select);
280
- orderBy = ensureArray(orderBy);
281
- const result = await client.retrieveMultipleRecordsAsync(tableName, {
282
- filter,
283
- select,
284
- orderBy,
285
- top,
286
- skip,
287
- });
288
- var unwrapped = unwrapResult(result);
289
- return { entities: Array.isArray(unwrapped) ? unwrapped : [] };
290
+ const client = getSharedClient();
291
+ select = ensureArray(select);
292
+ orderBy = ensureArray(orderBy);
293
+ const result = await client.retrieveMultipleRecordsAsync(tableName, {
294
+ filter,
295
+ select,
296
+ orderBy,
297
+ top,
298
+ skip,
299
+ });
300
+ let oUnwrapped = unwrapResult(result);
301
+ return { entities: Array.isArray(oUnwrapped) ? oUnwrapped : [] };
290
302
  });
291
303
  }
292
304
 
293
305
  // ── Update ─────────────────────────────────────────────────────
294
306
  export async function updateItem(tableName, primaryKey, id, changedFields) {
295
307
  return _dbgWrap('updateItem', [tableName, primaryKey, id, changedFields], async function() {
296
- const client = getSharedClient();
297
- const result = await client.updateRecordAsync(tableName, id, changedFields);
298
- return unwrapResult(result);
308
+ const client = getSharedClient();
309
+ const result = await client.updateRecordAsync(tableName, id, changedFields);
310
+ return unwrapResult(result);
299
311
  });
300
312
  }
301
313
 
302
314
  // ── Delete ─────────────────────────────────────────────────────
303
315
  export async function deleteItem(tableName, primaryKey, id) {
304
316
  return _dbgWrap('deleteItem', [tableName, primaryKey, id], async function() {
305
- const client = getSharedClient();
306
- const result = await client.deleteRecordAsync(tableName, id);
307
- return unwrapResult(result);
317
+ const client = getSharedClient();
318
+ const result = await client.deleteRecordAsync(tableName, id);
319
+ return unwrapResult(result);
308
320
  });
309
321
  }
310
322
 
@@ -314,586 +326,49 @@ export async function deleteItem(tableName, primaryKey, id) {
314
326
  // not entities and will cause deploy errors.
315
327
  export async function callUnboundAction(tableName, primaryKey, actionName, params) {
316
328
  return _dbgWrap('callUnboundAction', [tableName, primaryKey, actionName, params], async function() {
317
- var oAllSources = Object.assign({}, oInitialDataSources, oDataSources);
318
- var result = await callActionAsync(oAllSources, actionName, params || {});
319
- return unwrapResult(result);
329
+ let oAllSources = Object.assign({}, oInitialDataSources, oDataSources);
330
+ let result = await callActionAsync(oAllSources, actionName, params || {});
331
+ return unwrapResult(result);
320
332
  });
321
333
  }
322
334
 
323
335
  // ── WhoAmI ─────────────────────────────────────────────────────
324
336
  export async function whoAmI() {
325
337
  return _dbgWrap('whoAmI', [], async function() {
326
- var oCtx = await getContext();
327
- var sId = oCtx.UserId || oCtx.userId || oCtx.systemuserid;
328
- if (sId) return sId;
329
- if (oCtx.userSettings && oCtx.userSettings.userId) return oCtx.userSettings.userId;
330
- return oCtx;
338
+ let oCtx = await getContext();
339
+ let sId = oCtx.UserId || oCtx.userId || oCtx.systemuserid;
340
+ if (sId) return sId;
341
+ if (oCtx.userSettings && oCtx.userSettings.userId) return oCtx.userSettings.userId;
342
+ return oCtx;
331
343
  });
332
344
  }
333
345
 
334
346
  // ────────────────────────────────────────────────────────────────────────────
335
- // ─────────────────────────────── SharePoint ─────────────────────────────────
347
+ // ───────────────────────── Connector Helpers ────────────────────────────────
336
348
  // ────────────────────────────────────────────────────────────────────────────
337
349
 
338
- // ── Data source name (must match connectionReferences in power.config.json) ──
339
- const DATA_SOURCE_SP = "sharepointonline";
340
-
341
- // ── Initialize SDK client for the SharePoint connector ─────────
342
- function initSpClient() {
343
- const dataSourcesInfo = {
344
- [DATA_SOURCE_SP]: {
345
- tableId: "",
346
- version: "",
347
- primaryKey: "",
348
- dataSourceType: "Connector",
349
- apis: {
350
- GetItems: {
351
- path: "/{connectionId}/datasets/{siteUrl}/tables/{table}/items",
352
- method: "GET",
353
- parameters: [
354
- { name: "connectionId", in: "path", required: true },
355
- { name: "siteUrl", in: "path", required: true },
356
- { name: "table", in: "path", required: true },
357
- { name: "$filter", in: "query", required: false },
358
- { name: "$orderby", in: "query", required: false },
359
- { name: "$top", in: "query", required: false },
360
- { name: "$skip", in: "query", required: false },
361
- ],
362
- },
363
- GetItem: {
364
- path: "/{connectionId}/datasets/{siteUrl}/tables/{table}/items/{id}",
365
- method: "GET",
366
- parameters: [
367
- { name: "connectionId", in: "path", required: true },
368
- { name: "siteUrl", in: "path", required: true },
369
- { name: "table", in: "path", required: true },
370
- { name: "id", in: "path", required: true },
371
- ],
372
- },
373
- PostItem: {
374
- path: "/{connectionId}/datasets/{siteUrl}/tables/{table}/items",
375
- method: "POST",
376
- parameters: [
377
- { name: "connectionId", in: "path", required: true },
378
- { name: "siteUrl", in: "path", required: true },
379
- { name: "table", in: "path", required: true },
380
- { name: "item", in: "body", required: true },
381
- ],
382
- },
383
- PatchItem: {
384
- path: "/{connectionId}/datasets/{siteUrl}/tables/{table}/items/{id}",
385
- method: "PATCH",
386
- parameters: [
387
- { name: "connectionId", in: "path", required: true },
388
- { name: "siteUrl", in: "path", required: true },
389
- { name: "table", in: "path", required: true },
390
- { name: "id", in: "path", required: true },
391
- { name: "item", in: "body", required: true },
392
- ],
393
- },
394
- DeleteItem: {
395
- path: "/{connectionId}/datasets/{siteUrl}/tables/{table}/items/{id}",
396
- method: "DELETE",
397
- parameters: [
398
- { name: "connectionId", in: "path", required: true },
399
- { name: "siteUrl", in: "path", required: true },
400
- { name: "table", in: "path", required: true },
401
- { name: "id", in: "path", required: true },
402
- ],
403
- },
404
- GetTables: {
405
- path: "/{connectionId}/datasets/{siteUrl}/tables",
406
- method: "GET",
407
- parameters: [
408
- { name: "connectionId", in: "path", required: true },
409
- { name: "siteUrl", in: "path", required: true },
410
- ],
411
- },
412
- GetDataSetsMetadata: {
413
- path: "/{connectionId}/datasets/{siteUrl}",
414
- method: "GET",
415
- parameters: [
416
- { name: "connectionId", in: "path", required: true },
417
- { name: "siteUrl", in: "path", required: true },
418
- ],
419
- },
420
- CreateFile: {
421
- path: "/{connectionId}/datasets/{siteUrl}/files",
422
- method: "POST",
423
- parameters: [
424
- { name: "connectionId", in: "path", required: true },
425
- { name: "siteUrl", in: "path", required: true },
426
- { name: "folderPath", in: "query", required: true },
427
- { name: "name", in: "query", required: true },
428
- { name: "body", in: "body", required: true },
429
- ],
430
- },
431
- UpdateFile: {
432
- path: "/{connectionId}/datasets/{siteUrl}/files/{id}",
433
- method: "PUT",
434
- parameters: [
435
- { name: "connectionId", in: "path", required: true },
436
- { name: "siteUrl", in: "path", required: true },
437
- { name: "id", in: "path", required: true },
438
- { name: "body", in: "body", required: true },
439
- ],
440
- },
441
- DeleteFile: {
442
- path: "/{connectionId}/datasets/{siteUrl}/files/{id}",
443
- method: "DELETE",
444
- parameters: [
445
- { name: "connectionId", in: "path", required: true },
446
- { name: "siteUrl", in: "path", required: true },
447
- { name: "id", in: "path", required: true },
448
- ],
449
- },
450
- MoveFile: {
451
- path: "/{connectionId}/datasets/{siteUrl}/files/{id}/moveto",
452
- method: "POST",
453
- parameters: [
454
- { name: "connectionId", in: "path", required: true },
455
- { name: "siteUrl", in: "path", required: true },
456
- { name: "id", in: "path", required: true },
457
- { name: "destinationFolderPath", in: "query", required: true },
458
- { name: "newFileName", in: "query", required: false },
459
- ],
460
- },
461
- GetFileMetadata: {
462
- path: "/{connectionId}/datasets/{siteUrl}/files/{id}",
463
- method: "GET",
464
- parameters: [
465
- { name: "connectionId", in: "path", required: true },
466
- { name: "siteUrl", in: "path", required: true },
467
- { name: "id", in: "path", required: true },
468
- ],
469
- },
470
- HttpRequest: {
471
- path: "/{connectionId}/httprequest",
472
- method: "POST",
473
- parameters: [
474
- { name: "connectionId", in: "path", required: true },
475
- ],
476
- },
477
- },
478
- },
479
- };
480
- return getClient(dataSourcesInfo);
481
- }
482
-
483
- // ── Internal: execute a connector operation ────────────────────
484
- async function execSpOp(operationName, parameters) {
485
- const client = await initSpClient();
486
- const result = await client.executeAsync({
487
- connectorOperation: {
488
- tableName: DATA_SOURCE_SP,
489
- operationName,
490
- parameters,
491
- },
492
- });
493
- if (!result.success) {
494
- throw new Error(result.error?.message || "Operation failed");
495
- }
496
- return result.data;
497
- }
498
-
499
- // ═══════════════════════════════════════════════════════════════
500
- // GENERIC
501
- // ═══════════════════════════════════════════════════════════════
502
-
503
- // ── Call any SharePoint connector operation by name ─────────────
504
- export async function callSharePointOperation(operationName, parameters = {}) {
505
- return _dbgWrap('callSharePointOperation', [operationName, parameters], async function() {
506
- return execSpOp(operationName, parameters);
507
- });
508
- }
509
-
510
- // ── Send HTTP Request (for list-name-based operations) ─────────
511
- export async function sendHttpRequest({ method = "GET", uri, headers, body }) {
512
- return _dbgWrap('sendHttpRequest', [{ method, uri, headers, body }], async function() {
513
- return execSpOp("HttpRequest", {
514
- method,
515
- uri,
516
- headers: headers || {},
517
- body: body || "",
518
- });
519
- });
520
- }
521
-
522
- // ═══════════════════════════════════════════════════════════════
523
- // ITEMS (standard API — uses list ID)
524
- // ═══════════════════════════════════════════════════════════════
525
-
526
- // ── Get Items ──────────────────────────────────────────────────
527
- export async function getItems(sSiteUrl, sListId, { filter, orderBy, top, skip } = {}) {
528
- return _dbgWrap('getItems', [sSiteUrl, sListId, { filter, orderBy, top, skip }], async function() {
529
- let params = { siteUrl: encodeURIComponent(sSiteUrl), table: sListId };
530
- if (filter) params.$filter = filter;
531
- if (orderBy) params.$orderby = orderBy;
532
- if (top != null) params.$top = top;
533
- if (skip != null) params.$skip = skip;
534
- return execSpOp("GetItems", params);
535
- });
536
- }
537
-
538
- // ── Get Item ───────────────────────────────────────────────────
539
- export async function getSpItem(sSiteUrl, sListId, iItemId) {
540
- return _dbgWrap('getSpItem', [sSiteUrl, sListId, iItemId], async function() {
541
- return execSpOp("GetItem", {
542
- siteUrl: encodeURIComponent(sSiteUrl),
543
- table: sListId,
544
- id: iItemId,
545
- });
546
- });
547
- }
548
-
549
- // ── Create Item ────────────────────────────────────────────────
550
- export async function createSpItem(sSiteUrl, sListId, oFields) {
551
- return _dbgWrap('createSpItem', [sSiteUrl, sListId, oFields], async function() {
552
- return execSpOp("PostItem", {
553
- siteUrl: encodeURIComponent(sSiteUrl),
554
- table: sListId,
555
- item: oFields,
556
- });
557
- });
558
- }
559
-
560
- // ── Update Item ────────────────────────────────────────────────
561
- export async function updateSpItem(sSiteUrl, sListId, iItemId, oChangedFields) {
562
- return _dbgWrap('updateSpItem', [sSiteUrl, sListId, iItemId, oChangedFields], async function() {
563
- return execSpOp("PatchItem", {
564
- siteUrl: encodeURIComponent(sSiteUrl),
565
- table: sListId,
566
- id: iItemId,
567
- item: oChangedFields,
568
- });
569
- });
570
- }
571
-
572
- // ── Delete Item ────────────────────────────────────────────────
573
- export async function deleteSpItem(sSiteUrl, sListId, iItemId) {
574
- return _dbgWrap('deleteSpItem', [sSiteUrl, sListId, iItemId], async function() {
575
- return execSpOp("DeleteItem", {
576
- siteUrl: encodeURIComponent(sSiteUrl),
577
- table: sListId,
578
- id: iItemId,
579
- });
580
- });
581
- }
582
-
583
- // ═══════════════════════════════════════════════════════════════
584
- // ITEMS (HTTP API — uses list name)
585
- // ═══════════════════════════════════════════════════════════════
586
-
587
- // ── Get Items by List Name ─────────────────────────────────────
588
- export async function getItemsByName(sSiteUrl, sListName, { filter, orderBy, top, skip } = {}) {
589
- return _dbgWrap('getItemsByName', [sSiteUrl, sListName, { filter, orderBy, top, skip }], async function() {
590
- let sUri = sSiteUrl + "/_api/web/lists/getbytitle('" + sListName + "')/items";
591
- let aQuery = [];
592
- if (filter) aQuery.push("$filter=" + filter);
593
- if (orderBy) aQuery.push("$orderby=" + orderBy);
594
- if (top != null) aQuery.push("$top=" + top);
595
- if (skip != null) aQuery.push("$skip=" + skip);
596
- if (aQuery.length > 0) sUri = sUri + "?" + aQuery.join("&");
597
- return sendHttpRequest({ method: "GET", uri: sUri, headers: { Accept: "application/json;odata=nometadata" } });
598
- });
599
- }
600
-
601
- // ── Get Item by List Name ──────────────────────────────────────
602
- export async function getItemByName(sSiteUrl, sListName, iItemId) {
603
- return _dbgWrap('getItemByName', [sSiteUrl, sListName, iItemId], async function() {
604
- let sUri = sSiteUrl + "/_api/web/lists/getbytitle('" + sListName + "')/items(" + iItemId + ")";
605
- return sendHttpRequest({ method: "GET", uri: sUri, headers: { Accept: "application/json;odata=nometadata" } });
606
- });
607
- }
608
-
609
- // ── Create Item by List Name ───────────────────────────────────
610
- export async function createItemByName(sSiteUrl, sListName, oFields) {
611
- return _dbgWrap('createItemByName', [sSiteUrl, sListName, oFields], async function() {
612
- let sUri = sSiteUrl + "/_api/web/lists/getbytitle('" + sListName + "')/items";
613
- return sendHttpRequest({ method: "POST", uri: sUri, headers: { Accept: "application/json;odata=nometadata", "Content-Type": "application/json;odata=nometadata" }, body: JSON.stringify(oFields) });
614
- });
615
- }
616
-
617
- // ── Update Item by List Name ───────────────────────────────────
618
- export async function updateItemByName(sSiteUrl, sListName, iItemId, oChangedFields) {
619
- return _dbgWrap('updateItemByName', [sSiteUrl, sListName, iItemId, oChangedFields], async function() {
620
- let sUri = sSiteUrl + "/_api/web/lists/getbytitle('" + sListName + "')/items(" + iItemId + ")";
621
- return sendHttpRequest({ method: "PATCH", uri: sUri, headers: { Accept: "application/json;odata=nometadata", "Content-Type": "application/json;odata=nometadata", "If-Match": "*" }, body: JSON.stringify(oChangedFields) });
622
- });
623
- }
624
-
625
- // ── Delete Item by List Name ───────────────────────────────────
626
- export async function deleteItemByName(sSiteUrl, sListName, iItemId) {
627
- return _dbgWrap('deleteItemByName', [sSiteUrl, sListName, iItemId], async function() {
628
- let sUri = sSiteUrl + "/_api/web/lists/getbytitle('" + sListName + "')/items(" + iItemId + ")";
629
- return sendHttpRequest({ method: "DELETE", uri: sUri, headers: { Accept: "application/json;odata=nometadata", "If-Match": "*" } });
630
- });
631
- }
632
-
633
- // ═══════════════════════════════════════════════════════════════
634
- // TABLES / LISTS
635
- // ═══════════════════════════════════════════════════════════════
636
-
637
- // ── List Tables (Lists) ────────────────────────────────────────
638
- export async function listTables(sSiteUrl) {
639
- return _dbgWrap('listTables', [sSiteUrl], async function() {
640
- return execSpOp("GetTables", {
641
- siteUrl: encodeURIComponent(sSiteUrl),
642
- });
643
- });
644
- }
645
-
646
- // ── List Library (Document Libraries) ──────────────────────────
647
- export async function listLibrary(sSiteUrl) {
648
- return _dbgWrap('listLibrary', [sSiteUrl], async function() {
649
- return execSpOp("GetDataSetsMetadata", {
650
- siteUrl: encodeURIComponent(sSiteUrl),
651
- });
652
- });
653
- }
654
-
655
- // ═══════════════════════════════════════════════════════════════
656
- // FILES
657
- // ═══════════════════════════════════════════════════════════════
658
-
659
- // ── Create File ────────────────────────────────────────────────
660
- export async function createFile(sSiteUrl, sLibraryName, sFileName, fileContent) {
661
- return _dbgWrap('createFile', [sSiteUrl, sLibraryName, sFileName, fileContent], async function() {
662
- return execSpOp("CreateFile", {
663
- siteUrl: encodeURIComponent(sSiteUrl),
664
- folderPath: sLibraryName,
665
- name: sFileName,
666
- body: fileContent,
667
- });
668
- });
669
- }
670
-
671
- // ── Update File ────────────────────────────────────────────────
672
- export async function updateFile(sSiteUrl, sFileId, fileContent) {
673
- return _dbgWrap('updateFile', [sSiteUrl, sFileId, fileContent], async function() {
674
- return execSpOp("UpdateFile", {
675
- siteUrl: encodeURIComponent(sSiteUrl),
676
- id: sFileId,
677
- body: fileContent,
678
- });
679
- });
680
- }
681
-
682
- // ── Delete File ────────────────────────────────────────────────
683
- export async function deleteFile(sSiteUrl, sFileId) {
684
- return _dbgWrap('deleteFile', [sSiteUrl, sFileId], async function() {
685
- return execSpOp("DeleteFile", {
686
- siteUrl: encodeURIComponent(sSiteUrl),
687
- id: sFileId,
688
- });
689
- });
690
- }
691
-
692
- // ── Move File ──────────────────────────────────────────────────
693
- export async function moveFile(sSiteUrl, sSourceFileId, sDestinationFolderPath, sNewFileName) {
694
- return _dbgWrap('moveFile', [sSiteUrl, sSourceFileId, sDestinationFolderPath, sNewFileName], async function() {
695
- return execSpOp("MoveFile", {
696
- siteUrl: encodeURIComponent(sSiteUrl),
697
- id: sSourceFileId,
698
- destinationFolderPath: sDestinationFolderPath,
699
- newFileName: sNewFileName || "",
700
- });
701
- });
702
- }
703
-
704
- // ── Get File Metadata ──────────────────────────────────────────
705
- export async function getFileMetadata(sSiteUrl, sFileId) {
706
- return _dbgWrap('getFileMetadata', [sSiteUrl, sFileId], async function() {
707
- return execSpOp("GetFileMetadata", {
708
- siteUrl: encodeURIComponent(sSiteUrl),
709
- id: sFileId,
710
- });
711
- });
712
- }
713
-
714
- // ────────────────────────────────────────────────────────────────────────────
715
- // ────────────────────────────── Outlook365 ──────────────────────────────────
716
- // ────────────────────────────────────────────────────────────────────────────
717
-
718
- // ── Data source name (must match connectionReferences in power.config.json) ──
719
- const DATA_SOURCE_CANDIDATES = ["office365outlook", "Office365Outlook", "office365"];
720
- const OUTLOOK_APIS = {
721
- // ── Email operations ──
722
- GetEmailsV3: {
723
- path: "/{connectionId}/v3/Mail",
724
- method: "GET",
725
- parameters: [
726
- { name: "connectionId", in: "path", required: true },
727
- { name: "folderPath", in: "query", required: false },
728
- { name: "to", in: "query", required: false },
729
- { name: "cc", in: "query", required: false },
730
- { name: "toOrCc", in: "query", required: false },
731
- { name: "from", in: "query", required: false },
732
- { name: "importance", in: "query", required: false },
733
- { name: "fetchOnlyWithAttachment", in: "query", required: false },
734
- { name: "subjectFilter", in: "query", required: false },
735
- { name: "fetchOnlyUnread", in: "query", required: false },
736
- { name: "fetchOnlyFlagged", in: "query", required: false },
737
- { name: "mailboxAddress", in: "query", required: false },
738
- { name: "includeAttachments", in: "query", required: false },
739
- { name: "searchQuery", in: "query", required: false },
740
- { name: "top", in: "query", required: false },
741
- ],
742
- },
743
- SendEmailV2: {
744
- path: "/{connectionId}/v2/Mail",
745
- method: "POST",
746
- parameters: [
747
- { name: "connectionId", in: "path", required: true },
748
- { name: "emailMessage", in: "body", required: true },
749
- ],
750
- },
751
- ForwardEmail: {
752
- path: "/{connectionId}/codeless/api/v2.0/me/messages/{message_id}/forward",
753
- method: "POST",
754
- parameters: [
755
- { name: "connectionId", in: "path", required: true },
756
- { name: "message_id", in: "path", required: true },
757
- { name: "body", in: "body", required: true },
758
- ],
759
- },
760
- ReplyToV3: {
761
- path: "/{connectionId}/v3/Mail/ReplyTo/{messageId}",
762
- method: "POST",
763
- parameters: [
764
- { name: "connectionId", in: "path", required: true },
765
- { name: "messageId", in: "path", required: true },
766
- { name: "replyParameters", in: "body", required: true },
767
- { name: "mailboxAddress", in: "query", required: false },
768
- ],
769
- },
770
- MoveV2: {
771
- path: "/{connectionId}/v2/Mail/Move/{messageId}",
772
- method: "POST",
773
- parameters: [
774
- { name: "connectionId", in: "path", required: true },
775
- { name: "messageId", in: "path", required: true },
776
- { name: "folderPath", in: "query", required: true },
777
- { name: "mailboxAddress", in: "query", required: false },
778
- ],
779
- },
780
- DeleteEmail: {
781
- path: "/{connectionId}/Mail/{messageId}",
782
- method: "DELETE",
783
- parameters: [
784
- { name: "connectionId", in: "path", required: true },
785
- { name: "messageId", in: "path", required: true },
786
- ],
787
- },
788
- SharedMailboxSendEmailV2: {
789
- path: "/{connectionId}/v2/SharedMailbox/Mail",
790
- method: "POST",
791
- parameters: [
792
- { name: "connectionId", in: "path", required: true },
793
- { name: "emailMessage", in: "body", required: true },
794
- ],
795
- },
796
- // ── Calendar operations ──
797
- V4CalendarGetItems: {
798
- path: "/{connectionId}/datasets/calendars/v4/tables/{table}/items",
799
- method: "GET",
800
- parameters: [
801
- { name: "connectionId", in: "path", required: true },
802
- { name: "table", in: "path", required: true },
803
- { name: "$filter", in: "query", required: false },
804
- { name: "$orderby", in: "query", required: false },
805
- { name: "$top", in: "query", required: false },
806
- { name: "$skip", in: "query", required: false },
807
- ],
808
- },
809
- V4CalendarPostItem: {
810
- path: "/{connectionId}/datasets/calendars/v4/tables/{table}/items",
811
- method: "POST",
812
- parameters: [
813
- { name: "connectionId", in: "path", required: true },
814
- { name: "table", in: "path", required: true },
815
- { name: "item", in: "body", required: true },
816
- ],
817
- },
818
- V4CalendarPatchItem: {
819
- path: "/{connectionId}/datasets/calendars/v4/tables/{table}/items/{id}",
820
- method: "PATCH",
821
- parameters: [
822
- { name: "connectionId", in: "path", required: true },
823
- { name: "table", in: "path", required: true },
824
- { name: "id", in: "path", required: true },
825
- { name: "item", in: "body", required: true },
826
- ],
827
- },
828
- CalendarDeleteItem: {
829
- path: "/{connectionId}/datasets/calendars/tables/{table}/items/{id}",
830
- method: "DELETE",
831
- parameters: [
832
- { name: "connectionId", in: "path", required: true },
833
- { name: "table", in: "path", required: true },
834
- { name: "id", in: "path", required: true },
835
- ],
836
- },
837
- };
838
-
839
- // ── Initialize SDK client for the Office 365 Outlook connector ──
840
- function initOutlookClient() {
350
+ function initConnectorClientWithCandidates(aDataSourceCandidates, oApis) {
841
351
  const dataSourcesInfo = {};
842
352
 
843
- DATA_SOURCE_CANDIDATES.forEach((sDataSourceName) => {
353
+ aDataSourceCandidates.forEach(function(sDataSourceName) {
844
354
  dataSourcesInfo[sDataSourceName] = {
845
- tableId: "",
846
- version: "",
847
- primaryKey: "",
848
- dataSourceType: "Connector",
849
- apis: OUTLOOK_APIS,
355
+ tableId: '',
356
+ version: '',
357
+ primaryKey: '',
358
+ dataSourceType: 'Connector',
359
+ apis: oApis,
850
360
  };
851
361
  });
852
362
 
853
363
  return getClient(dataSourcesInfo);
854
364
  }
855
365
 
856
- function stringifyOutlookError(oError) {
857
- if (!oError) return "Operation failed";
858
- if (typeof oError === "string") return oError;
859
- if (oError instanceof Error) return oError.message || "Operation failed";
860
-
861
- var aPropertyNames = Object.getOwnPropertyNames(oError);
862
- var oSerializable = {};
863
- aPropertyNames.forEach((sName) => {
864
- oSerializable[sName] = oError[sName];
865
- });
866
-
867
- try {
868
- return JSON.stringify(oSerializable);
869
- } catch {
870
- return String(oError);
871
- }
872
- }
873
-
874
- function unwrapOutlookResult(oResult) {
875
- if (oResult && oResult.success === false) {
876
- var sMessage = stringifyOutlookError(oResult.error);
877
- if (oResult.data !== undefined) {
878
- sMessage += " | data: " + stringifyOutlookError(oResult.data);
879
- }
880
- throw new Error(sMessage);
881
- }
882
-
883
- if (oResult && Object.prototype.hasOwnProperty.call(oResult, "data")) {
884
- return oResult.data;
885
- }
886
-
887
- return oResult;
888
- }
889
-
890
- // ── Internal: execute a connector operation ────────────────────
891
- async function execOutlookOp(operationName, parameters) {
892
- const client = await initOutlookClient();
366
+ async function execConnectorOpWithCandidates(aDataSourceCandidates, oApis, sConnectorName, operationName, parameters) {
367
+ const client = await initConnectorClientWithCandidates(aDataSourceCandidates, oApis);
893
368
  const aErrors = [];
894
369
 
895
- for (let iIndex = 0; iIndex < DATA_SOURCE_CANDIDATES.length; iIndex += 1) {
896
- const sDataSourceName = DATA_SOURCE_CANDIDATES[iIndex];
370
+ for (let iIndex = 0; iIndex < aDataSourceCandidates.length; iIndex += 1) {
371
+ const sDataSourceName = aDataSourceCandidates[iIndex];
897
372
 
898
373
  try {
899
374
  const result = await client.executeAsync({
@@ -904,431 +379,16 @@ async function execOutlookOp(operationName, parameters) {
904
379
  },
905
380
  });
906
381
 
907
- return unwrapOutlookResult(result);
382
+ return unwrapResult(result);
908
383
  } catch (oErr) {
909
- const sMessage = stringifyOutlookError(oErr);
910
- aErrors.push(sDataSourceName + ": " + sMessage);
384
+ const sMessage = stringifyConnectorError(oErr);
385
+ aErrors.push(sDataSourceName + ': ' + sMessage);
911
386
 
912
- if (sMessage.indexOf("Connection reference not found") === -1) {
387
+ if (sMessage.indexOf('Connection reference not found') === -1) {
913
388
  throw oErr;
914
389
  }
915
390
  }
916
391
  }
917
392
 
918
- throw new Error("No Outlook connection reference matched. Tried: " + aErrors.join(" || "));
919
- }
920
-
921
- // ── Generic: call any Outlook connector operation ──────────────
922
- export async function callOutlookOperation(sOperationName, oParameters) {
923
- return _dbgWrap('callOutlookOperation', [sOperationName, oParameters], async function() {
924
- return execOutlookOp(sOperationName, oParameters);
925
- });
926
- }
927
-
928
- // ── Send Email ─────────────────────────────────────────────────
929
- export async function sendEmail({ to, cc, bcc, subject, body, isHtml, importance, attachments } = {}) {
930
- return _dbgWrap('sendEmail', [{ to, cc, bcc, subject, body, isHtml, importance, attachments }], async function() {
931
- var oMessage = {
932
- To: to,
933
- Subject: subject,
934
- Body: body,
935
- };
936
- if (cc) oMessage.Cc = cc;
937
- if (bcc) oMessage.Bcc = bcc;
938
- if (importance) oMessage.Importance = importance;
939
- if (attachments) oMessage.Attachments = attachments;
940
- if (isHtml === false) oMessage.IsHtml = false;
941
-
942
- return execOutlookOp("SendEmailV2", { emailMessage: oMessage });
943
- });
944
- }
945
-
946
- // ── Forward Email ──────────────────────────────────────────────
947
- export async function forwardEmail(sMessageId, { to, comment } = {}) {
948
- return _dbgWrap('forwardEmail', [sMessageId, { to, comment }], async function() {
949
- return execOutlookOp("ForwardEmail", {
950
- message_id: sMessageId,
951
- body: { ToRecipients: to, Comment: comment },
952
- });
953
- });
954
- }
955
-
956
- // ── Reply to Email ─────────────────────────────────────────────
957
- export async function replyToEmail(sMessageId, { comment, replyAll } = {}) {
958
- return _dbgWrap('replyToEmail', [sMessageId, { comment, replyAll }], async function() {
959
- return execOutlookOp("ReplyToV3", {
960
- messageId: sMessageId,
961
- replyParameters: { Body: comment, ReplyAll: replyAll === true },
962
- });
963
- });
964
- }
965
-
966
- // ── List Emails ────────────────────────────────────────────────
967
- export async function listEmails({ folderId = "Inbox", fetchOnlyUnread, searchQuery, top, skip } = {}) {
968
- return _dbgWrap('listEmails', [{ folderId, fetchOnlyUnread, searchQuery, top, skip }], async function() {
969
- return execOutlookOp("GetEmailsV3", {
970
- folderPath: folderId,
971
- fetchOnlyUnread: fetchOnlyUnread,
972
- searchQuery: searchQuery,
973
- top: top != null ? top : 10,
974
- skip: skip,
975
- });
976
- });
977
- }
978
-
979
- // ── Send from Shared Mailbox ───────────────────────────────────
980
- export async function sendFromSharedMailbox(sSharedMailbox, { to, cc, bcc, subject, body, importance, attachments } = {}) {
981
- return _dbgWrap('sendFromSharedMailbox', [sSharedMailbox, { to, cc, bcc, subject, body, importance, attachments }], async function() {
982
- var oMessage = {
983
- MailboxAddress: sSharedMailbox,
984
- To: to,
985
- Subject: subject,
986
- Body: body,
987
- };
988
- if (cc) oMessage.Cc = cc;
989
- if (bcc) oMessage.Bcc = bcc;
990
- if (importance) oMessage.Importance = importance;
991
- if (attachments) oMessage.Attachments = attachments;
992
-
993
- return execOutlookOp("SharedMailboxSendEmailV2", { emailMessage: oMessage });
994
- });
995
- }
996
-
997
- // ── Move Email ─────────────────────────────────────────────────
998
- export async function moveEmail(sMessageId, sDestinationFolderId) {
999
- return _dbgWrap('moveEmail', [sMessageId, sDestinationFolderId], async function() {
1000
- return execOutlookOp("MoveV2", {
1001
- messageId: sMessageId,
1002
- folderPath: sDestinationFolderId,
1003
- });
1004
- });
1005
- }
1006
-
1007
- // ── Delete Email ───────────────────────────────────────────────
1008
- export async function deleteEmail(sMessageId) {
1009
- return _dbgWrap('deleteEmail', [sMessageId], async function() {
1010
- return execOutlookOp("DeleteEmail", { messageId: sMessageId });
1011
- });
1012
- }
1013
-
1014
- // ── Create Event ───────────────────────────────────────────────
1015
- export async function createEvent({ subject, start, end, attendees, body, location, importance, isAllDay, timeZone, calendarId } = {}) {
1016
- return _dbgWrap('createEvent', [{ subject, start, end, attendees, body, location, importance, isAllDay, timeZone, calendarId }], async function() {
1017
- var sAttendees = Array.isArray(attendees) ? attendees.join(";") : attendees;
1018
- var oItem = {
1019
- subject: subject,
1020
- start: start,
1021
- end: end,
1022
- timeZone: timeZone || "",
1023
- };
1024
- if (sAttendees) oItem.requiredAttendees = sAttendees;
1025
- if (body) oItem.body = body;
1026
- if (location) oItem.location = location;
1027
- if (importance) oItem.importance = importance;
1028
- if (isAllDay) oItem.isAllDay = true;
1029
-
1030
- return execOutlookOp("V4CalendarPostItem", {
1031
- table: calendarId || "Calendar",
1032
- item: oItem,
1033
- });
1034
- });
1035
- }
1036
-
1037
- // ── List Events ────────────────────────────────────────────────
1038
- export async function listEvents({ calendarId = "Calendar", filter, orderBy, top, skip } = {}) {
1039
- return _dbgWrap('listEvents', [{ calendarId, filter, orderBy, top, skip }], async function() {
1040
- return execOutlookOp("V4CalendarGetItems", {
1041
- table: calendarId,
1042
- $filter: filter,
1043
- $orderby: orderBy,
1044
- $top: top,
1045
- $skip: skip,
1046
- });
1047
- });
1048
- }
1049
-
1050
- // ── Edit Event ─────────────────────────────────────────────────
1051
- export async function editEvent(sEventId, oChangedFields, sCalendarId) {
1052
- return _dbgWrap('editEvent', [sEventId, oChangedFields, sCalendarId], async function() {
1053
- return execOutlookOp("V4CalendarPatchItem", {
1054
- table: sCalendarId || "Calendar",
1055
- id: sEventId,
1056
- item: oChangedFields,
1057
- });
1058
- });
1059
- }
1060
-
1061
- // ── Delete Event ───────────────────────────────────────────────
1062
- export async function deleteEvent(sEventId, sCalendarId) {
1063
- return _dbgWrap('deleteEvent', [sEventId, sCalendarId], async function() {
1064
- return execOutlookOp("CalendarDeleteItem", {
1065
- table: sCalendarId || "Calendar",
1066
- id: sEventId,
1067
- });
1068
- });
1069
- }
1070
-
1071
- // ────────────────────────────────────────────────────────────────────────────
1072
- // ─────────────────────────────── O365 User ──────────────────────────────────
1073
- // ────────────────────────────────────────────────────────────────────────────
1074
-
1075
- // ── Data source name (must match connectionReferences in power.config.json) ──
1076
- const DATA_SOURCE_USERS = "office365users";
1077
-
1078
- // ── Initialize SDK client for the Office 365 Users connector ───
1079
- function initUsersClient() {
1080
- const dataSourcesInfo = {
1081
- [DATA_SOURCE_USERS]: {
1082
- tableId: "",
1083
- version: "",
1084
- primaryKey: "",
1085
- dataSourceType: "Connector",
1086
- apis: {
1087
- MyProfile_V2: {
1088
- path: "/{connectionId}/codeless/v1.0/me",
1089
- method: "GET",
1090
- parameters: [
1091
- { name: "connectionId", in: "path", required: true },
1092
- ],
1093
- },
1094
- UserProfile_V2: {
1095
- path: "/{connectionId}/codeless/v1.0/users/{id}",
1096
- method: "GET",
1097
- parameters: [
1098
- { name: "connectionId", in: "path", required: true },
1099
- { name: "id", in: "path", required: true },
1100
- ],
1101
- },
1102
- Manager_V2: {
1103
- path: "/{connectionId}/codeless/v1.0/users/{id}/manager",
1104
- method: "GET",
1105
- parameters: [
1106
- { name: "connectionId", in: "path", required: true },
1107
- { name: "id", in: "path", required: true },
1108
- ],
1109
- },
1110
- DirectReports_V2: {
1111
- path: "/{connectionId}/codeless/v1.0/users/{id}/directReports",
1112
- method: "GET",
1113
- parameters: [
1114
- { name: "connectionId", in: "path", required: true },
1115
- { name: "id", in: "path", required: true },
1116
- ],
1117
- },
1118
- UserPhoto_V2: {
1119
- path: "/{connectionId}/codeless/v1.0/users/{id}/photo/$value",
1120
- method: "GET",
1121
- parameters: [
1122
- { name: "connectionId", in: "path", required: true },
1123
- { name: "id", in: "path", required: true },
1124
- ],
1125
- responseInfo: { "200": "image/jpeg" },
1126
- },
1127
- SearchUser_V2: {
1128
- path: "/{connectionId}/codeless/v1.0/users",
1129
- method: "GET",
1130
- parameters: [
1131
- { name: "connectionId", in: "path", required: true },
1132
- { name: "searchTerm", in: "query", required: false },
1133
- { name: "$top", in: "query", required: false },
1134
- { name: "$skip", in: "query", required: false },
1135
- ],
1136
- },
1137
- HttpRequest: {
1138
- path: "/{connectionId}/codeless/v1.0/httprequest",
1139
- method: "POST",
1140
- parameters: [
1141
- { name: "connectionId", in: "path", required: true },
1142
- ],
1143
- },
1144
- },
1145
- },
1146
- };
1147
- return getClient(dataSourcesInfo);
1148
- }
1149
-
1150
- // ── Internal: execute a connector operation ────────────────────
1151
- async function execUsersOp(operationName, parameters) {
1152
- const client = await initUsersClient();
1153
- const result = await client.executeAsync({
1154
- connectorOperation: {
1155
- tableName: DATA_SOURCE_USERS,
1156
- operationName,
1157
- parameters,
1158
- },
1159
- });
1160
- if (!result.success) {
1161
- throw new Error(result.error?.message || "Operation failed");
1162
- }
1163
- return result.data;
1164
- }
1165
-
1166
- // ═══════════════════════════════════════════════════════════════
1167
- // GENERIC
1168
- // ═══════════════════════════════════════════════════════════════
1169
-
1170
- // ── Call any Office 365 Users operation by name ────────────────
1171
- export async function callUsersOperation(operationName, parameters = {}) {
1172
- return _dbgWrap('callUsersOperation', [operationName, parameters], async function() {
1173
- return execUsersOp(operationName, parameters);
1174
- });
1175
- }
1176
-
1177
- // ── Open HTTP Request ──────────────────────────────────────────
1178
- export async function openUsersHttpRequest({ method = "GET", uri, headers, body }) {
1179
- return _dbgWrap('openUsersHttpRequest', [{ method, uri, headers, body }], async function() {
1180
- return execUsersOp("HttpRequest", {
1181
- method,
1182
- uri,
1183
- headers: headers || {},
1184
- body: body || "",
1185
- });
1186
- });
1187
- }
1188
-
1189
- // ═══════════════════════════════════════════════════════════════
1190
- // PROFILE
1191
- // ═══════════════════════════════════════════════════════════════
1192
-
1193
- // ── Get My Profile ─────────────────────────────────────────────
1194
- export async function getMyProfile() {
1195
- return _dbgWrap('getMyProfile', [], async function() {
1196
- return execUsersOp("MyProfile_V2", {});
1197
- });
1198
- }
1199
-
1200
- // ── Get User Profile ───────────────────────────────────────────
1201
- export async function getUserProfile(userId) {
1202
- return _dbgWrap('getUserProfile', [userId], async function() {
1203
- return execUsersOp("UserProfile_V2", {
1204
- id: userId,
1205
- });
1206
- });
1207
- }
1208
-
1209
- // ═══════════════════════════════════════════════════════════════
1210
- // MANAGER & REPORTS
1211
- // ═══════════════════════════════════════════════════════════════
1212
-
1213
- // ── Get Manager ────────────────────────────────────────────────
1214
- export async function getManager(userId) {
1215
- return _dbgWrap('getManager', [userId], async function() {
1216
- return execUsersOp("Manager_V2", {
1217
- id: userId,
1218
- });
1219
- });
1220
- }
1221
-
1222
- // ── Get Direct Reports ─────────────────────────────────────────
1223
- export async function getDirectReports(userId) {
1224
- return _dbgWrap('getDirectReports', [userId], async function() {
1225
- return execUsersOp("DirectReports_V2", {
1226
- id: userId,
1227
- });
1228
- });
1229
- }
1230
-
1231
- // ═══════════════════════════════════════════════════════════════
1232
- // PHOTO
1233
- // ═══════════════════════════════════════════════════════════════
1234
-
1235
- // ── Get User Photo ─────────────────────────────────────────────
1236
- export async function getUserPhoto(userId) {
1237
- return _dbgWrap('getUserPhoto', [userId], async function() {
1238
- return execUsersOp("UserPhoto_V2", {
1239
- id: userId,
1240
- });
1241
- });
1242
- }
1243
-
1244
- // ═══════════════════════════════════════════════════════════════
1245
- // SEARCH
1246
- // ═══════════════════════════════════════════════════════════════
1247
-
1248
- // ── Search for Users ───────────────────────────────────────────
1249
- export async function searchForUsers({ searchTerm, top, skip } = {}) {
1250
- return _dbgWrap('searchForUsers', [{ searchTerm, top, skip }], async function() {
1251
- const params = {};
1252
- if (searchTerm) params.searchTerm = searchTerm;
1253
- if (top != null) params.$top = top;
1254
- if (skip != null) params.$skip = skip;
1255
- return execUsersOp("SearchUser_V2", params);
1256
- });
1257
- }
1258
-
1259
- // ────────────────────────────────────────────────────────────────────────────
1260
- // ────────────────────────────── O365 Groups──────────────────────────────────
1261
- // ────────────────────────────────────────────────────────────────────────────
1262
-
1263
-
1264
- // ── Data source name (must match connectionReferences in power.config.json) ──
1265
- const DATA_SOURCE_GROUPS = "Office365Groups";
1266
-
1267
- // ── Initialize SDK client for the Office 365 Groups connector ──
1268
- function initGroupsClient() {
1269
- const dataSourcesInfo = {
1270
- [DATA_SOURCE_GROUPS]: {
1271
- tableId: "",
1272
- version: "",
1273
- primaryKey: "",
1274
- dataSourceType: "Connector",
1275
- apis: {},
1276
- },
1277
- };
1278
- return getClient(dataSourcesInfo);
1279
- }
1280
-
1281
- // ── Internal: execute a connector operation ────────────────────
1282
- async function execGroupsOp(operationName, parameters) {
1283
- const client = await initGroupsClient();
1284
- return client.executeAsync({
1285
- connectorOperation: {
1286
- tableName: DATA_SOURCE_GROUPS,
1287
- operationName,
1288
- parameters,
1289
- },
1290
- });
1291
- }
1292
-
1293
- // ═══════════════════════════════════════════════════════════════
1294
- // GENERIC
1295
- // ═══════════════════════════════════════════════════════════════
1296
-
1297
- // ── Call any Office 365 Groups operation by name ───────────────
1298
- export async function callGroupsOperation(operationName, parameters = {}) {
1299
- return _dbgWrap('callGroupsOperation', [operationName, parameters], async function() {
1300
- return execGroupsOp(operationName, parameters);
1301
- });
1302
- }
1303
-
1304
- // ── Open HTTP Request ──────────────────────────────────────────
1305
- export async function openGroupsHttpRequest({ method = "GET", uri, headers, body }) {
1306
- return _dbgWrap('openGroupsHttpRequest', [{ method, uri, headers, body }], async function() {
1307
- return execGroupsOp("HttpRequest", {
1308
- method,
1309
- uri,
1310
- headers: headers || {},
1311
- body: body || "",
1312
- });
1313
- });
1314
- }
1315
-
1316
- // ═══════════════════════════════════════════════════════════════
1317
- // GROUPS
1318
- // ═══════════════════════════════════════════════════════════════
1319
-
1320
- // ── List My Groups ─────────────────────────────────────────────
1321
- export async function listMyGroups() {
1322
- return _dbgWrap('listMyGroups', [], async function() {
1323
- return execGroupsOp("ListOwnedGroups", {});
1324
- });
1325
- }
1326
-
1327
- // ── List Members of a Group ────────────────────────────────────
1328
- export async function listGroupMembers(groupId) {
1329
- return _dbgWrap('listGroupMembers', [groupId], async function() {
1330
- return execGroupsOp("ListGroupMembers", {
1331
- groupId,
1332
- });
1333
- });
1334
- }
393
+ throw new Error('No ' + sConnectorName + ' connection reference matched. Tried: ' + aErrors.join(' || '));
394
+ }