codeapp-js 0.3.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/AI/codeapp.agent.md +105 -0
  2. package/AI/skills/connections/SKILL.md +47 -0
  3. package/AI/skills/dataverse/SKILL.md +99 -0
  4. package/AI/skills/environment-variables/SKILL.md +89 -0
  5. package/AI/skills/frontend-design/SKILL.md +34 -0
  6. package/AI/skills/jira/SKILL.md +81 -0
  7. package/AI/skills/office365-groups/SKILL.md +61 -0
  8. package/AI/skills/office365-outlook/SKILL.md +52 -0
  9. package/AI/skills/office365-users/SKILL.md +78 -0
  10. package/AI/skills/sharepoint/SKILL.md +77 -0
  11. package/AI/skills/sql/SKILL.md +85 -0
  12. package/AI/skills/start/SKILL.md +46 -0
  13. package/AI/skills/teams/SKILL.md +55 -0
  14. package/{examples/combined demo/.power/schemas/office365groups/office365groups.Schema.json → codeApp/.power/schemas/office365groups/office365groups.Schema.json} +2203 -2203
  15. package/codeApp/dist/codeapp.js +95 -1792
  16. package/codeApp/dist/connectors/azureKeyvault.js +459 -0
  17. package/codeApp/dist/connectors/jira.js +1247 -0
  18. package/codeApp/dist/connectors/office365groups.js +642 -0
  19. package/codeApp/dist/connectors/office365users.js +513 -0
  20. package/codeApp/dist/connectors/outlook.js +1393 -0
  21. package/{dev files/sharepoint.js → codeApp/dist/connectors/sharepoint.js} +239 -112
  22. package/codeApp/dist/connectors/sql.js +149 -0
  23. package/codeApp/dist/connectors/teams.js +280 -0
  24. package/codeApp/dist/power-apps-data.js +16 -2
  25. package/examples/{kanban → apps/kanban}/dist/dataverse.js +94 -94
  26. package/examples/{kanban → apps/kanban}/dist/environmentVar.js +55 -55
  27. package/examples/{kanban → apps/kanban}/dist/index.css +605 -605
  28. package/examples/{kanban → apps/kanban}/dist/index.html +21 -21
  29. package/examples/{kanban → apps/kanban}/dist/index.js +860 -860
  30. package/examples/{kanban → apps/kanban}/dist/office365groups.js +97 -97
  31. package/examples/apps/kanban/dist/office365users.js +451 -0
  32. package/examples/{kanban → apps/kanban}/dist/outlook.js +162 -162
  33. package/examples/{planning Poker/dist/power-apps-data.js → apps/kanban/dist/power-apps-data.js} +2953 -2953
  34. package/examples/{kanban → apps/kanban}/dist/sharepoint.js +435 -339
  35. package/examples/{kanban → apps/kanban}/power.config.json +35 -35
  36. package/examples/{planning Poker → apps/planning Poker}/additional files/customizations (tables).xml +6428 -6428
  37. package/examples/{planning Poker → apps/planning Poker}/additional files/dataverse-tables.json +165 -165
  38. package/examples/{planning Poker → apps/planning Poker}/additional files/readme.md +122 -122
  39. package/examples/{planning Poker → apps/planning Poker}/dist/dataverse.js +78 -78
  40. package/examples/{planning Poker → apps/planning Poker}/dist/index.html +198 -198
  41. package/examples/{planning Poker → apps/planning Poker}/dist/index.js +954 -954
  42. package/examples/{todo/dist/power-apps-data.js → apps/planning Poker/dist/power-apps-data.js } +2953 -2953
  43. package/examples/{planning Poker → apps/planning Poker}/dist/styles.css +815 -815
  44. package/examples/{planning Poker → apps/planning Poker}/power.config.json +50 -50
  45. package/examples/{outlook Demo2 → apps/solution explorer}/dist/codeapp.js +9 -245
  46. package/examples/apps/solution explorer/dist/index.html +80 -0
  47. package/examples/apps/solution explorer/dist/index.js +735 -0
  48. package/examples/apps/solution explorer/dist/styles.css +571 -0
  49. package/examples/apps/solution explorer/power.config.json +151 -0
  50. package/examples/{todo → apps/todo}/dist/dataverse.js +64 -64
  51. package/examples/{todo → apps/todo}/dist/index.html +75 -75
  52. package/examples/{todo → apps/todo}/dist/index.js +8 -8
  53. package/examples/{kanban → apps/todo}/dist/power-apps-data.js +2953 -2953
  54. package/examples/{todo → apps/todo}/dist/renderer.js +375 -375
  55. package/examples/{todo → apps/todo}/dist/styles.css +691 -691
  56. package/examples/{todo → apps/todo}/power.config.json +34 -34
  57. package/examples/combined demo/.power/schemas/appschemas/dataSourcesInfo.ts +6275 -7830
  58. package/examples/combined demo/.power/schemas/jira/jira.Schema.json +6903 -0
  59. package/examples/combined demo/.power/schemas/keyvault/keyvault.Schema.json +1600 -0
  60. package/examples/combined demo/.power/schemas/teams/teams.Schema.json +11112 -0
  61. package/examples/combined demo/dist/codeapp.js +394 -1098
  62. package/examples/{outlook Demo2/OutlookDemo_1_0_0_1.zip → combined demo/dist/icon-512.png} +0 -0
  63. package/examples/combined demo/dist/index.html +29 -511
  64. package/examples/combined demo/dist/index.js +490 -470
  65. package/examples/combined demo/dist/office365users.js +513 -0
  66. package/examples/combined demo/dist/outlook.js +1393 -0
  67. package/examples/combined demo/dist/power-apps-data.js +3079 -3006
  68. package/examples/combined demo/dist/styles.css +483 -0
  69. package/examples/combined demo/power.config.json +33 -42
  70. package/examples/combined demo/src/generated/index.ts +12 -14
  71. package/examples/combined demo/src/generated/models/AzureKeyVaultModel.ts +107 -0
  72. package/examples/combined demo/src/generated/models/JiraModel.ts +501 -0
  73. package/examples/combined demo/src/generated/services/AzureKeyVaultService.ts +257 -0
  74. package/examples/combined demo/src/generated/services/JiraService.ts +1124 -0
  75. package/examples/dataverse Demo/dist/codeapp.js +394 -1085
  76. package/examples/dataverse Demo/dist/icon-512.png +0 -0
  77. package/examples/dataverse Demo/dist/index.html +146 -54
  78. package/examples/dataverse Demo/dist/index.js +693 -83
  79. package/examples/dataverse Demo/dist/power-apps-data.js +3079 -2911
  80. package/examples/dataverse Demo/dist/styles.css +528 -0
  81. package/examples/dataverse Demo/power.config.json +41 -35
  82. package/examples/dataverse Demo/readme.md +79 -79
  83. package/examples/groups Demo/dist/codeapp.js +394 -1085
  84. package/examples/groups Demo/dist/icon-512.png +0 -0
  85. package/examples/groups Demo/dist/index.html +21 -25
  86. package/examples/groups Demo/dist/index.js +304 -113
  87. package/examples/groups Demo/dist/office365groups.js +642 -0
  88. package/examples/groups Demo/dist/power-apps-data.js +3079 -2911
  89. package/examples/groups Demo/dist/styles.css +509 -0
  90. package/examples/groups Demo/power.config.json +25 -25
  91. package/examples/myProfile/dist/codeapp.js +398 -0
  92. package/examples/myProfile/dist/index.html +21 -184
  93. package/examples/myProfile/dist/index.js +324 -141
  94. package/examples/myProfile/dist/office365users.js +517 -169
  95. package/examples/myProfile/dist/power-apps-data.js +3080 -2953
  96. package/examples/myProfile/dist/styles.css +458 -0
  97. package/examples/myProfile/power.config.json +24 -23
  98. package/examples/outlook Demo/dist/codeapp.js +394 -1085
  99. package/examples/outlook Demo/dist/index.html +150 -35
  100. package/examples/outlook Demo/dist/index.js +516 -170
  101. package/examples/outlook Demo/dist/outlook.js +1393 -121
  102. package/examples/outlook Demo/dist/power-apps-data.js +3079 -2911
  103. package/examples/outlook Demo/dist/styles.css +408 -84
  104. package/examples/outlook Demo/power.config.json +24 -23
  105. package/examples/outlook Demo/readme.md +92 -82
  106. package/examples/sharePoint Demo/dist/codeapp.js +394 -1085
  107. package/examples/sharePoint Demo/dist/icon-512.png +0 -0
  108. package/examples/sharePoint Demo/dist/index.html +22 -255
  109. package/examples/sharePoint Demo/dist/index.js +899 -262
  110. package/examples/sharePoint Demo/dist/power-apps-data.js +3079 -2911
  111. package/examples/sharePoint Demo/dist/sharepoint.js +466 -0
  112. package/examples/sharePoint Demo/dist/styles.css +587 -0
  113. package/examples/sharePoint Demo/power.config.json +23 -22
  114. package/package.json +1 -1
  115. package/readme.md +465 -76
  116. package/.vscode/settings.json +0 -6
  117. package/dev files/customConnector.js +0 -98
  118. package/dev files/dataverse.js +0 -120
  119. package/dev files/environmentVar.js +0 -55
  120. package/dev files/office365groups.js +0 -65
  121. package/dev files/office365users.js +0 -169
  122. package/dev files/outlook.js +0 -330
  123. package/dev files/power-apps-data.js +0 -2952
  124. package/examples/combined demo/.power/schemas/office365/office365.Schema.json +0 -21098
  125. package/examples/combined demo/.power/schemas/office365users/office365users.Schema.json +0 -2094
  126. package/examples/kanban/agent/decision-log.md +0 -9
  127. package/examples/kanban/agent/mockup-01-editorial-glass.html +0 -159
  128. package/examples/kanban/agent/mockup-02-dark-rail.html +0 -147
  129. package/examples/kanban/agent/mockup-03-paper-grid.html +0 -114
  130. package/examples/kanban/agent/mockup-04-neon-minimal.html +0 -141
  131. package/examples/kanban/agent/mockup-05-mono-architect.html +0 -119
  132. package/examples/kanban/dist/office365users.js +0 -169
  133. package/examples/kanban/src/generated/index.ts +0 -14
  134. package/examples/kanban/src/generated/models/Office365GroupsModel.ts +0 -363
  135. package/examples/kanban/src/generated/models/Office365OutlookModel.ts +0 -2046
  136. package/examples/kanban/src/generated/models/Office365UsersModel.ts +0 -254
  137. package/examples/kanban/src/generated/services/Office365GroupsService.ts +0 -326
  138. package/examples/kanban/src/generated/services/Office365OutlookService.ts +0 -2476
  139. package/examples/kanban/src/generated/services/Office365UsersService.ts +0 -358
  140. package/examples/outlook Demo2/agent/decision-log.md +0 -7
  141. package/examples/outlook Demo2/dist/index.html +0 -98
  142. package/examples/outlook Demo2/dist/index.js +0 -272
  143. package/examples/outlook Demo2/dist/styles.css +0 -639
  144. package/examples/outlook Demo2/power.config.json +0 -23
  145. package/examples/planning Poker/.vscode/settings.json +0 -5
  146. package/examples/sharePoint Demo/agent/decision-log.md +0 -17
  147. /package/examples/{outlook Demo2 → apps/kanban}/src/generated/index.ts +0 -0
  148. /package/examples/{outlook Demo2 → apps/kanban}/src/generated/models/Office365GroupsModel.ts +0 -0
  149. /package/examples/{outlook Demo2 → apps/kanban}/src/generated/models/Office365OutlookModel.ts +0 -0
  150. /package/examples/{outlook Demo2 → apps/kanban}/src/generated/models/Office365UsersModel.ts +0 -0
  151. /package/examples/{outlook Demo2 → apps/kanban}/src/generated/services/Office365GroupsService.ts +0 -0
  152. /package/examples/{outlook Demo2 → apps/kanban}/src/generated/services/Office365OutlookService.ts +0 -0
  153. /package/examples/{outlook Demo2 → apps/kanban}/src/generated/services/Office365UsersService.ts +0 -0
  154. /package/examples/{planning Poker → apps/planning Poker}/additional files/AgilePoker_1_0_0_1.zip +0 -0
  155. /package/examples/{planning Poker → apps/planning Poker}/additional files/PokerTables_1_0_0_1.zip +0 -0
  156. /package/examples/{outlook Demo2 → apps/solution explorer}/dist/icon-512.png +0 -0
  157. /package/examples/{outlook Demo2 → apps/solution explorer}/dist/power-apps-data.js +0 -0
  158. /package/examples/{todo → apps/todo}/dist/icon192.png +0 -0
@@ -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,1022 +326,20 @@ 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;
331
- });
332
- }
333
-
334
- // ────────────────────────────────────────────────────────────────────────────
335
- // ─────────────────────────────── SharePoint ─────────────────────────────────
336
- // ────────────────────────────────────────────────────────────────────────────
337
-
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() {
841
- const dataSourcesInfo = {};
842
-
843
- DATA_SOURCE_CANDIDATES.forEach((sDataSourceName) => {
844
- dataSourcesInfo[sDataSourceName] = {
845
- tableId: "",
846
- version: "",
847
- primaryKey: "",
848
- dataSourceType: "Connector",
849
- apis: OUTLOOK_APIS,
850
- };
851
- });
852
-
853
- return getClient(dataSourcesInfo);
854
- }
855
-
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();
893
- const aErrors = [];
894
-
895
- for (let iIndex = 0; iIndex < DATA_SOURCE_CANDIDATES.length; iIndex += 1) {
896
- const sDataSourceName = DATA_SOURCE_CANDIDATES[iIndex];
897
-
898
- try {
899
- const result = await client.executeAsync({
900
- connectorOperation: {
901
- tableName: sDataSourceName,
902
- operationName,
903
- parameters,
904
- },
905
- });
906
-
907
- return unwrapOutlookResult(result);
908
- } catch (oErr) {
909
- const sMessage = stringifyOutlookError(oErr);
910
- aErrors.push(sDataSourceName + ": " + sMessage);
911
-
912
- if (sMessage.indexOf("Connection reference not found") === -1) {
913
- throw oErr;
914
- }
915
- }
916
- }
917
-
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
- });
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;
1333
343
  });
1334
344
  }
1335
345
 
@@ -1342,10 +352,10 @@ function initConnectorClientWithCandidates(aDataSourceCandidates, oApis) {
1342
352
 
1343
353
  aDataSourceCandidates.forEach(function(sDataSourceName) {
1344
354
  dataSourcesInfo[sDataSourceName] = {
1345
- tableId: "",
1346
- version: "",
1347
- primaryKey: "",
1348
- dataSourceType: "Connector",
355
+ tableId: '',
356
+ version: '',
357
+ primaryKey: '',
358
+ dataSourceType: 'Connector',
1349
359
  apis: oApis,
1350
360
  };
1351
361
  });
@@ -1369,723 +379,16 @@ async function execConnectorOpWithCandidates(aDataSourceCandidates, oApis, sConn
1369
379
  },
1370
380
  });
1371
381
 
1372
- return unwrapOutlookResult(result);
382
+ return unwrapResult(result);
1373
383
  } catch (oErr) {
1374
- const sMessage = stringifyOutlookError(oErr);
1375
- aErrors.push(sDataSourceName + ": " + sMessage);
384
+ const sMessage = stringifyConnectorError(oErr);
385
+ aErrors.push(sDataSourceName + ': ' + sMessage);
1376
386
 
1377
- if (sMessage.indexOf("Connection reference not found") === -1) {
387
+ if (sMessage.indexOf('Connection reference not found') === -1) {
1378
388
  throw oErr;
1379
389
  }
1380
390
  }
1381
391
  }
1382
392
 
1383
- throw new Error("No " + sConnectorName + " connection reference matched. Tried: " + aErrors.join(" || "));
1384
- }
1385
-
1386
- // ────────────────────────────────────────────────────────────────────────────
1387
- // ─────────────────────────────────── Jira ───────────────────────────────────
1388
- // ────────────────────────────────────────────────────────────────────────────
1389
-
1390
- const JIRA_DATA_SOURCE_CANDIDATES = ["jira", "Jira", "JIRA"];
1391
- const JIRA_APIS = {
1392
- AddComment_V2: {
1393
- path: "/{connectionId}/v2/issue/{issueKey}/comment",
1394
- method: "POST",
1395
- parameters: [
1396
- { name: "connectionId", in: "path", required: true },
1397
- { name: "X-Request-Jirainstance", in: "header", required: true },
1398
- { name: "issueKey", in: "path", required: true },
1399
- { name: "body", in: "body", required: true },
1400
- ],
1401
- },
1402
- CancelTask_V2: {
1403
- path: "/{connectionId}/v2/task/{taskId}/cancel",
1404
- method: "POST",
1405
- parameters: [
1406
- { name: "connectionId", in: "path", required: true },
1407
- { name: "X-Request-Jirainstance", in: "header", required: true },
1408
- { name: "taskId", in: "path", required: true },
1409
- { name: "X-Atlassian-Token", in: "header", required: true },
1410
- ],
1411
- },
1412
- CreateIssue_V3: {
1413
- path: "/{connectionId}/v3/issue",
1414
- method: "POST",
1415
- parameters: [
1416
- { name: "connectionId", in: "path", required: true },
1417
- { name: "X-Request-Jirainstance", in: "header", required: true },
1418
- { name: "projectKey", in: "query", required: true },
1419
- { name: "issueTypeIds", in: "query", required: true },
1420
- { name: "item", in: "body", required: false },
1421
- ],
1422
- },
1423
- EditIssue_V2: {
1424
- path: "/{connectionId}/v2/3/issue/{issueIdOrKey}",
1425
- method: "PUT",
1426
- parameters: [
1427
- { name: "connectionId", in: "path", required: true },
1428
- { name: "X-Request-Jirainstance", in: "header", required: true },
1429
- { name: "issueIdOrKey", in: "path", required: true },
1430
- { name: "notifyUsers", in: "query", required: false },
1431
- { name: "overrideScreenSecurity", in: "query", required: false },
1432
- { name: "overrideEditableFlag", in: "query", required: false },
1433
- { name: "body", in: "body", required: false },
1434
- ],
1435
- },
1436
- GetCurrentUser: {
1437
- path: "/{connectionId}/3/myself",
1438
- method: "GET",
1439
- parameters: [
1440
- { name: "connectionId", in: "path", required: true },
1441
- { name: "X-Request-Jirainstance", in: "header", required: true },
1442
- { name: "expand", in: "query", required: false },
1443
- ],
1444
- },
1445
- GetIssue_V2: {
1446
- path: "/{connectionId}/v2/issue/{issueKey}",
1447
- method: "GET",
1448
- parameters: [
1449
- { name: "connectionId", in: "path", required: true },
1450
- { name: "X-Request-Jirainstance", in: "header", required: true },
1451
- { name: "issueKey", in: "path", required: true },
1452
- ],
1453
- },
1454
- ListFilters_V2: {
1455
- path: "/{connectionId}/v2/filter/search",
1456
- method: "GET",
1457
- parameters: [
1458
- { name: "connectionId", in: "path", required: true },
1459
- { name: "X-Request-Jirainstance", in: "header", required: true },
1460
- ],
1461
- },
1462
- ListIssues: {
1463
- path: "/{connectionId}/2/search",
1464
- method: "GET",
1465
- parameters: [
1466
- { name: "connectionId", in: "path", required: true },
1467
- { name: "X-Request-Jirainstance", in: "header", required: true },
1468
- { name: "jql", in: "query", required: false },
1469
- { name: "expand", in: "query", required: false },
1470
- { name: "fields", in: "query", required: false },
1471
- ],
1472
- },
1473
- ListProjects_V2: {
1474
- path: "/{connectionId}/project/search",
1475
- method: "GET",
1476
- parameters: [
1477
- { name: "connectionId", in: "path", required: true },
1478
- ],
1479
- },
1480
- GetTask_V2: {
1481
- path: "/{connectionId}/v2/task/{taskId}",
1482
- method: "GET",
1483
- parameters: [
1484
- { name: "connectionId", in: "path", required: true },
1485
- { name: "X-Request-Jirainstance", in: "header", required: true },
1486
- { name: "taskId", in: "path", required: true },
1487
- ],
1488
- },
1489
- GetUser_V2: {
1490
- path: "/{connectionId}/v2/user",
1491
- method: "GET",
1492
- parameters: [
1493
- { name: "connectionId", in: "path", required: true },
1494
- { name: "X-Request-Jirainstance", in: "header", required: true },
1495
- { name: "accountId", in: "query", required: true },
1496
- { name: "expand", in: "query", required: false },
1497
- ],
1498
- },
1499
- };
1500
-
1501
- async function execJiraOp(operationName, parameters) {
1502
- return execConnectorOpWithCandidates(JIRA_DATA_SOURCE_CANDIDATES, JIRA_APIS, "Jira", operationName, parameters);
1503
- }
1504
-
1505
- export async function callJiraOperation(operationName, parameters = {}) {
1506
- return _dbgWrap('callJiraOperation', [operationName, parameters], async function() {
1507
- return execJiraOp(operationName, parameters);
1508
- });
1509
- }
1510
-
1511
- export async function addJiraComment(sIssueKey, body, sJiraInstance) {
1512
- return _dbgWrap('addJiraComment', [sIssueKey, body, sJiraInstance], async function() {
1513
- return execJiraOp("AddComment_V2", {
1514
- "X-Request-Jirainstance": sJiraInstance,
1515
- issueKey: sIssueKey,
1516
- body,
1517
- });
1518
- });
1519
- }
1520
-
1521
- export async function cancelJiraTask(sTaskId, sJiraInstance, sToken) {
1522
- return _dbgWrap('cancelJiraTask', [sTaskId, sJiraInstance, sToken], async function() {
1523
- return execJiraOp("CancelTask_V2", {
1524
- "X-Request-Jirainstance": sJiraInstance,
1525
- taskId: sTaskId,
1526
- "X-Atlassian-Token": sToken || "nocheck",
1527
- });
1528
- });
1529
- }
1530
-
1531
- export async function createJiraIssueV3({ jiraInstance, projectKey, issueTypeIds, item } = {}) {
1532
- return _dbgWrap('createJiraIssueV3', [{ jiraInstance, projectKey, issueTypeIds, item }], async function() {
1533
- return execJiraOp("CreateIssue_V3", {
1534
- "X-Request-Jirainstance": jiraInstance,
1535
- projectKey,
1536
- issueTypeIds,
1537
- item,
1538
- });
1539
- });
1540
- }
1541
-
1542
- export async function editJiraIssueV2(sIssueIdOrKey, { jiraInstance, body, notifyUsers, overrideScreenSecurity, overrideEditableFlag } = {}) {
1543
- return _dbgWrap('editJiraIssueV2', [sIssueIdOrKey, { jiraInstance, body, notifyUsers, overrideScreenSecurity, overrideEditableFlag }], async function() {
1544
- return execJiraOp("EditIssue_V2", {
1545
- "X-Request-Jirainstance": jiraInstance,
1546
- issueIdOrKey: sIssueIdOrKey,
1547
- notifyUsers,
1548
- overrideScreenSecurity,
1549
- overrideEditableFlag,
1550
- body,
1551
- });
1552
- });
1553
- }
1554
-
1555
- export async function getCurrentJiraUser({ jiraInstance, expand } = {}) {
1556
- return _dbgWrap('getCurrentJiraUser', [{ jiraInstance, expand }], async function() {
1557
- return execJiraOp("GetCurrentUser", {
1558
- "X-Request-Jirainstance": jiraInstance,
1559
- expand,
1560
- });
1561
- });
1562
- }
1563
-
1564
- export async function getJiraIssueByKey(sIssueKey, sJiraInstance) {
1565
- return _dbgWrap('getJiraIssueByKey', [sIssueKey, sJiraInstance], async function() {
1566
- return execJiraOp("GetIssue_V2", {
1567
- "X-Request-Jirainstance": sJiraInstance,
1568
- issueKey: sIssueKey,
1569
- });
1570
- });
1571
- }
1572
-
1573
- export async function listJiraFilters(sJiraInstance) {
1574
- return _dbgWrap('listJiraFilters', [sJiraInstance], async function() {
1575
- return execJiraOp("ListFilters_V2", {
1576
- "X-Request-Jirainstance": sJiraInstance,
1577
- });
1578
- });
1579
- }
1580
-
1581
- export async function listJiraIssues({ jiraInstance, jql, fields, expand } = {}) {
1582
- return _dbgWrap('listJiraIssues', [{ jiraInstance, jql, fields, expand }], async function() {
1583
- return execJiraOp("ListIssues", {
1584
- "X-Request-Jirainstance": jiraInstance,
1585
- jql,
1586
- fields,
1587
- expand,
1588
- });
1589
- });
1590
- }
1591
-
1592
- export async function listJiraProjects() {
1593
- return _dbgWrap('listJiraProjects', [], async function() {
1594
- return execJiraOp("ListProjects_V2", {});
1595
- });
1596
- }
1597
-
1598
- export async function getJiraTask(sTaskId, sJiraInstance) {
1599
- return _dbgWrap('getJiraTask', [sTaskId, sJiraInstance], async function() {
1600
- return execJiraOp("GetTask_V2", {
1601
- "X-Request-Jirainstance": sJiraInstance,
1602
- taskId: sTaskId,
1603
- });
1604
- });
1605
- }
1606
-
1607
- export async function getJiraUser(sAccountId, { jiraInstance, expand } = {}) {
1608
- return _dbgWrap('getJiraUser', [sAccountId, { jiraInstance, expand }], async function() {
1609
- return execJiraOp("GetUser_V2", {
1610
- "X-Request-Jirainstance": jiraInstance,
1611
- accountId: sAccountId,
1612
- expand,
1613
- });
1614
- });
1615
- }
1616
-
1617
- // ────────────────────────────────────────────────────────────────────────────
1618
- // ───────────────────────────── Azure Key Vault ──────────────────────────────
1619
- // ────────────────────────────────────────────────────────────────────────────
1620
-
1621
- const KEY_VAULT_DATA_SOURCE_CANDIDATES = ["keyvault", "KeyVault", "azurekeyvault", "azureKeyVault", "AzureKeyVault"];
1622
- const KEY_VAULT_APIS = {
1623
- GetSecret: {
1624
- path: "/{connectionId}/secrets/{secretName}/value",
1625
- method: "GET",
1626
- parameters: [
1627
- { name: "connectionId", in: "path", required: true },
1628
- { name: "secretName", in: "path", required: true },
1629
- ],
1630
- },
1631
- ListSecrets: {
1632
- path: "/{connectionId}/secrets",
1633
- method: "GET",
1634
- parameters: [
1635
- { name: "connectionId", in: "path", required: true },
1636
- ],
1637
- },
1638
- };
1639
-
1640
- async function execKeyVaultOp(operationName, parameters) {
1641
- return execConnectorOpWithCandidates(KEY_VAULT_DATA_SOURCE_CANDIDATES, KEY_VAULT_APIS, "Azure Key Vault", operationName, parameters);
1642
- }
1643
-
1644
- export async function callKeyVaultOperation(operationName, parameters = {}) {
1645
- return _dbgWrap('callKeyVaultOperation', [operationName, parameters], async function() {
1646
- return execKeyVaultOp(operationName, parameters);
1647
- });
1648
- }
1649
-
1650
- export async function getSecret(sSecretName, sApiVersion) {
1651
- return _dbgWrap('getSecret', [sSecretName, sApiVersion], async function() {
1652
- return execKeyVaultOp("GetSecret", {
1653
- secretName: sSecretName,
1654
- });
1655
- });
1656
- }
1657
-
1658
- export async function listSecrets({ maxresults, apiVersion } = {}) {
1659
- return _dbgWrap('listSecrets', [{ maxresults, apiVersion }], async function() {
1660
- return execKeyVaultOp("ListSecrets", {});
1661
- });
1662
- }
1663
-
1664
- // ────────────────────────────────────────────────────────────────────────────
1665
- // ─────────────────────────────────── SQL ────────────────────────────────────
1666
- // ────────────────────────────────────────────────────────────────────────────
1667
-
1668
- const SQL_DATA_SOURCE_CANDIDATES = ["sql", "Sql", "SQL"];
1669
- const SQL_APIS = {
1670
- GetTables_V2: {
1671
- path: "/GetTables_V2",
1672
- method: "POST",
1673
- parameters: [
1674
- { name: "body", in: "body", required: true },
1675
- ],
1676
- },
1677
- GetItems_V2: {
1678
- path: "/GetItems_V2",
1679
- method: "POST",
1680
- parameters: [
1681
- { name: "body", in: "body", required: true },
1682
- ],
1683
- },
1684
- GetItem_V2: {
1685
- path: "/GetItem_V2",
1686
- method: "POST",
1687
- parameters: [
1688
- { name: "body", in: "body", required: true },
1689
- ],
1690
- },
1691
- PostItem_V2: {
1692
- path: "/PostItem_V2",
1693
- method: "POST",
1694
- parameters: [
1695
- { name: "body", in: "body", required: true },
1696
- ],
1697
- },
1698
- PatchItem_V2: {
1699
- path: "/PatchItem_V2",
1700
- method: "POST",
1701
- parameters: [
1702
- { name: "body", in: "body", required: true },
1703
- ],
1704
- },
1705
- DeleteItem_V2: {
1706
- path: "/DeleteItem_V2",
1707
- method: "POST",
1708
- parameters: [
1709
- { name: "body", in: "body", required: true },
1710
- ],
1711
- },
1712
- ExecutePassThroughNativeQuery_V2: {
1713
- path: "/ExecutePassThroughNativeQuery_V2",
1714
- method: "POST",
1715
- parameters: [
1716
- { name: "body", in: "body", required: true },
1717
- ],
1718
- },
1719
- ExecuteProcedure_V2: {
1720
- path: "/ExecuteProcedure_V2",
1721
- method: "POST",
1722
- parameters: [
1723
- { name: "body", in: "body", required: true },
1724
- ],
1725
- },
1726
- };
1727
-
1728
- async function execSqlOp(operationName, parameters) {
1729
- return execConnectorOpWithCandidates(SQL_DATA_SOURCE_CANDIDATES, SQL_APIS, "SQL Server", operationName, parameters);
1730
- }
1731
-
1732
- export async function callSqlOperation(operationName, parameters = {}) {
1733
- return _dbgWrap('callSqlOperation', [operationName, parameters], async function() {
1734
- return execSqlOp(operationName, parameters);
1735
- });
1736
- }
1737
-
1738
- export async function getSqlTables({ server = "default", database = "default" } = {}) {
1739
- return _dbgWrap('getSqlTables', [{ server, database }], async function() {
1740
- return execSqlOp("GetTables_V2", {
1741
- body: { server, database },
1742
- });
1743
- });
1744
- }
1745
-
1746
- export async function getSqlRows({ server = "default", database = "default", table, apply, filter, orderBy, skip, top, select } = {}) {
1747
- return _dbgWrap('getSqlRows', [{ server, database, table, apply, filter, orderBy, skip, top, select }], async function() {
1748
- const body = { server, database, table };
1749
- if (apply) body.$apply = apply;
1750
- if (filter) body.$filter = filter;
1751
- if (orderBy) body.$orderby = orderBy;
1752
- if (skip != null) body.$skip = skip;
1753
- if (top != null) body.$top = top;
1754
- if (select) body.$select = select;
1755
-
1756
- return execSqlOp("GetItems_V2", { body });
1757
- });
1758
- }
1759
-
1760
- export async function getSqlRow({ server = "default", database = "default", table, id } = {}) {
1761
- return _dbgWrap('getSqlRow', [{ server, database, table, id }], async function() {
1762
- return execSqlOp("GetItem_V2", {
1763
- body: { server, database, table, id },
1764
- });
1765
- });
1766
- }
1767
-
1768
- export async function insertSqlRow({ server = "default", database = "default", table, item } = {}) {
1769
- return _dbgWrap('insertSqlRow', [{ server, database, table, item }], async function() {
1770
- return execSqlOp("PostItem_V2", {
1771
- body: { server, database, table, item },
1772
- });
1773
- });
1774
- }
1775
-
1776
- export async function updateSqlRow({ server = "default", database = "default", table, id, item } = {}) {
1777
- return _dbgWrap('updateSqlRow', [{ server, database, table, id, item }], async function() {
1778
- return execSqlOp("PatchItem_V2", {
1779
- body: { server, database, table, id, item },
1780
- });
1781
- });
1782
- }
1783
-
1784
- export async function deleteSqlRow({ server = "default", database = "default", table, id } = {}) {
1785
- return _dbgWrap('deleteSqlRow', [{ server, database, table, id }], async function() {
1786
- return execSqlOp("DeleteItem_V2", {
1787
- body: { server, database, table, id },
1788
- });
1789
- });
1790
- }
1791
-
1792
- export async function executeSqlQuery({ server = "default", database = "default", query } = {}) {
1793
- return _dbgWrap('executeSqlQuery', [{ server, database, query }], async function() {
1794
- return execSqlOp("ExecutePassThroughNativeQuery_V2", {
1795
- body: { server, database, query },
1796
- });
1797
- });
1798
- }
1799
-
1800
- export async function executeSqlStoredProcedure({ server = "default", database = "default", procedure, parameters } = {}) {
1801
- return _dbgWrap('executeSqlStoredProcedure', [{ server, database, procedure, parameters }], async function() {
1802
- return execSqlOp("ExecuteProcedure_V2", {
1803
- body: {
1804
- server,
1805
- database,
1806
- procedure,
1807
- parameters: parameters || {},
1808
- },
1809
- });
1810
- });
1811
- }
1812
-
1813
- // ────────────────────────────────────────────────────────────────────────────
1814
- // ────────────────────────────────── Teams ───────────────────────────────────
1815
- // ────────────────────────────────────────────────────────────────────────────
1816
-
1817
- const TEAMS_DATA_SOURCE_CANDIDATES = ["teams", "Teams", "microsoftteams", "MicrosoftTeams"];
1818
- const TEAMS_APIS = {
1819
- GetAllTeams: {
1820
- path: "/{connectionId}/GetAllTeams",
1821
- method: "GET",
1822
- parameters: [
1823
- { name: "connectionId", in: "path", required: true },
1824
- ],
1825
- },
1826
- GetChannelsForGroup: {
1827
- path: "/{connectionId}/GetChannelsForGroup",
1828
- method: "GET",
1829
- parameters: [
1830
- { name: "connectionId", in: "path", required: true },
1831
- { name: "groupId", in: "query", required: true },
1832
- ],
1833
- },
1834
- GetTeam: {
1835
- path: "/{connectionId}/GetTeam",
1836
- method: "GET",
1837
- parameters: [
1838
- { name: "connectionId", in: "path", required: true },
1839
- { name: "teamId", in: "query", required: true },
1840
- ],
1841
- },
1842
- GetChannel: {
1843
- path: "/{connectionId}/GetChannel",
1844
- method: "GET",
1845
- parameters: [
1846
- { name: "connectionId", in: "path", required: true },
1847
- { name: "groupId", in: "query", required: true },
1848
- { name: "channelId", in: "query", required: true },
1849
- ],
1850
- },
1851
- AddMemberToTeam: {
1852
- path: "/{connectionId}/AddMemberToTeam",
1853
- method: "POST",
1854
- parameters: [
1855
- { name: "connectionId", in: "path", required: true },
1856
- { name: "teamId", in: "query", required: true },
1857
- { name: "body", in: "body", required: true },
1858
- ],
1859
- },
1860
- AddMemberToChannel: {
1861
- path: "/{connectionId}/AddMemberToChannel",
1862
- method: "POST",
1863
- parameters: [
1864
- { name: "connectionId", in: "path", required: true },
1865
- { name: "groupId", in: "query", required: true },
1866
- { name: "channelId", in: "query", required: true },
1867
- { name: "body", in: "body", required: true },
1868
- ],
1869
- },
1870
- AtMentionUser: {
1871
- path: "/{connectionId}/AtMentionUser",
1872
- method: "GET",
1873
- parameters: [
1874
- { name: "connectionId", in: "path", required: true },
1875
- { name: "userId", in: "query", required: true },
1876
- ],
1877
- },
1878
- AtMentionTag: {
1879
- path: "/{connectionId}/AtMentionTag",
1880
- method: "GET",
1881
- parameters: [
1882
- { name: "connectionId", in: "path", required: true },
1883
- { name: "teamId", in: "query", required: true },
1884
- { name: "tagId", in: "query", required: true },
1885
- ],
1886
- },
1887
- ListChats: {
1888
- path: "/{connectionId}/ListChats",
1889
- method: "GET",
1890
- parameters: [
1891
- { name: "connectionId", in: "path", required: true },
1892
- { name: "$top", in: "query", required: false },
1893
- { name: "$skip", in: "query", required: false },
1894
- ],
1895
- },
1896
- ListMembers: {
1897
- path: "/{connectionId}/ListMembers",
1898
- method: "GET",
1899
- parameters: [
1900
- { name: "connectionId", in: "path", required: true },
1901
- { name: "groupId", in: "query", required: true },
1902
- { name: "channelId", in: "query", required: false },
1903
- ],
1904
- },
1905
- PostUserNotification: {
1906
- path: "/{connectionId}/PostUserNotification",
1907
- method: "POST",
1908
- parameters: [
1909
- { name: "connectionId", in: "path", required: true },
1910
- { name: "PostNotificationRequest", in: "body", required: true },
1911
- ],
1912
- },
1913
- PostChannelNotification: {
1914
- path: "/{connectionId}/PostChannelNotification",
1915
- method: "POST",
1916
- parameters: [
1917
- { name: "connectionId", in: "path", required: true },
1918
- { name: "groupId", in: "query", required: true },
1919
- { name: "PostNotificationRequest", in: "body", required: true },
1920
- ],
1921
- },
1922
- PostCardToConversation: {
1923
- path: "/{connectionId}/PostCardToConversation",
1924
- method: "POST",
1925
- parameters: [
1926
- { name: "connectionId", in: "path", required: true },
1927
- { name: "poster", in: "query", required: true },
1928
- { name: "location", in: "query", required: true },
1929
- { name: "body", in: "body", required: true },
1930
- ],
1931
- },
1932
- PostMessageToConversation: {
1933
- path: "/{connectionId}/PostMessageToConversation",
1934
- method: "POST",
1935
- parameters: [
1936
- { name: "connectionId", in: "path", required: true },
1937
- { name: "poster", in: "query", required: true },
1938
- { name: "location", in: "query", required: true },
1939
- { name: "body", in: "body", required: true },
1940
- ],
1941
- },
1942
- HttpRequest: {
1943
- path: "/{connectionId}/codeless/v1.0/httprequest",
1944
- method: "POST",
1945
- parameters: [
1946
- { name: "connectionId", in: "path", required: true },
1947
- ],
1948
- },
1949
- };
1950
-
1951
- async function execTeamsOp(operationName, parameters) {
1952
- return execConnectorOpWithCandidates(TEAMS_DATA_SOURCE_CANDIDATES, TEAMS_APIS, "Microsoft Teams", operationName, parameters);
1953
- }
1954
-
1955
- export async function callTeamsOperation(operationName, parameters = {}) {
1956
- return _dbgWrap('callTeamsOperation', [operationName, parameters], async function() {
1957
- return execTeamsOp(operationName, parameters);
1958
- });
1959
- }
1960
-
1961
- export async function sendTeamsGraphHttpRequest({ method = "GET", uri, headers, body } = {}) {
1962
- return _dbgWrap('sendTeamsGraphHttpRequest', [{ method, uri, headers, body }], async function() {
1963
- return execTeamsOp("HttpRequest", {
1964
- method,
1965
- uri,
1966
- headers: headers || {},
1967
- body: body || "",
1968
- });
1969
- });
1970
- }
1971
-
1972
- export async function listTeams() {
1973
- return _dbgWrap('listTeams', [], async function() {
1974
- return execTeamsOp("GetAllTeams", {});
1975
- });
1976
- }
1977
-
1978
- export async function listChannels(sTeamId) {
1979
- return _dbgWrap('listChannels', [sTeamId], async function() {
1980
- return execTeamsOp("GetChannelsForGroup", {
1981
- groupId: sTeamId,
1982
- });
1983
- });
1984
- }
1985
-
1986
- export async function getTeam(sTeamId) {
1987
- return _dbgWrap('getTeam', [sTeamId], async function() {
1988
- return execTeamsOp("GetTeam", {
1989
- teamId: sTeamId,
1990
- });
1991
- });
1992
- }
1993
-
1994
- export async function getChannelDetails(sTeamId, sChannelId) {
1995
- return _dbgWrap('getChannelDetails', [sTeamId, sChannelId], async function() {
1996
- return execTeamsOp("GetChannel", {
1997
- groupId: sTeamId,
1998
- channelId: sChannelId,
1999
- });
2000
- });
2001
- }
2002
-
2003
- export async function addMemberToTeam(sTeamId, body) {
2004
- return _dbgWrap('addMemberToTeam', [sTeamId, body], async function() {
2005
- return execTeamsOp("AddMemberToTeam", {
2006
- teamId: sTeamId,
2007
- body,
2008
- });
2009
- });
2010
- }
2011
-
2012
- export async function addMemberToChannel(sTeamId, sChannelId, body) {
2013
- return _dbgWrap('addMemberToChannel', [sTeamId, sChannelId, body], async function() {
2014
- return execTeamsOp("AddMemberToChannel", {
2015
- groupId: sTeamId,
2016
- channelId: sChannelId,
2017
- body,
2018
- });
2019
- });
2020
- }
2021
-
2022
- export async function getUserMentionToken(sUserId) {
2023
- return _dbgWrap('getUserMentionToken', [sUserId], async function() {
2024
- return execTeamsOp("AtMentionUser", {
2025
- userId: sUserId,
2026
- });
2027
- });
2028
- }
2029
-
2030
- export async function getTeamTagMentionToken(sTeamId, sTagId) {
2031
- return _dbgWrap('getTeamTagMentionToken', [sTeamId, sTagId], async function() {
2032
- return execTeamsOp("AtMentionTag", {
2033
- teamId: sTeamId,
2034
- tagId: sTagId,
2035
- });
2036
- });
2037
- }
2038
-
2039
- export async function listChats({ top, skip } = {}) {
2040
- return _dbgWrap('listChats', [{ top, skip }], async function() {
2041
- return execTeamsOp("ListChats", {
2042
- $top: top,
2043
- $skip: skip,
2044
- });
2045
- });
2046
- }
2047
-
2048
- export async function listMembers(sTeamId, sChannelId) {
2049
- return _dbgWrap('listMembers', [sTeamId, sChannelId], async function() {
2050
- return execTeamsOp("ListMembers", {
2051
- groupId: sTeamId,
2052
- channelId: sChannelId,
2053
- });
2054
- });
2055
- }
2056
-
2057
- export async function postFeedNotification({ groupId, body } = {}) {
2058
- return _dbgWrap('postFeedNotification', [{ groupId, body }], async function() {
2059
- if (groupId) {
2060
- return execTeamsOp("PostChannelNotification", {
2061
- groupId,
2062
- PostNotificationRequest: body,
2063
- });
2064
- }
2065
-
2066
- return execTeamsOp("PostUserNotification", {
2067
- PostNotificationRequest: body,
2068
- });
2069
- });
2070
- }
2071
-
2072
- export async function postCardInChatOrChannel({ poster = "Flow bot", location, body } = {}) {
2073
- return _dbgWrap('postCardInChatOrChannel', [{ poster, location, body }], async function() {
2074
- return execTeamsOp("PostCardToConversation", {
2075
- poster,
2076
- location,
2077
- body,
2078
- });
2079
- });
2080
- }
2081
-
2082
- export async function postMessageInChatOrChannel({ poster = "Flow bot", location, body } = {}) {
2083
- return _dbgWrap('postMessageInChatOrChannel', [{ poster, location, body }], async function() {
2084
- return execTeamsOp("PostMessageToConversation", {
2085
- poster,
2086
- location,
2087
- body,
2088
- });
2089
- });
2090
- }
2091
-
393
+ throw new Error('No ' + sConnectorName + ' connection reference matched. Tried: ' + aErrors.join(' || '));
394
+ }