codeapp-js 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. package/AI/skills/autoreview/SKILL.md +69 -0
  2. package/AI/skills/connections/SKILL.md +4 -4
  3. package/AI/skills/dataverse/SKILL.md +4 -2
  4. package/AI/skills/frontend-design/SKILL.md +32 -20
  5. package/AI/skills/keyvault/SKILL.md +139 -0
  6. package/AI/skills/office365-groups/SKILL.md +46 -25
  7. package/AI/skills/office365-outlook/SKILL.md +56 -25
  8. package/AI/skills/office365-users/SKILL.md +41 -36
  9. package/AI/skills/sharepoint/SKILL.md +174 -31
  10. package/AI/skills/start/SKILL.md +38 -30
  11. package/codeApp/dist/connectors/autoreview.js +1654 -0
  12. package/codeApp/dist/connectors/office365groups.js +2995 -432
  13. package/{examples/outlook Demo/.power/schemas/office365/office365.Schema.json → codeApp/dist/connectors/office365outlook.js} +7439 -16
  14. package/codeApp/dist/connectors/office365users.js +2990 -349
  15. package/codeApp/dist/connectors/sharepoint.js +529 -308
  16. package/examples/combined demo/dist/connectors/office365outlook.js +28521 -0
  17. package/examples/combined demo/dist/connectors/office365users.js +3154 -0
  18. package/examples/combined demo/dist/index.js +2 -6
  19. package/examples/combined demo/power.config.json +1 -1
  20. package/examples/groups Demo/{.power/schemas/office365groups/office365groups.Schema.json → dist/connectors/office365groups.js } +3205 -2204
  21. package/examples/groups Demo/dist/index.js +1 -5
  22. package/examples/groups Demo/power.config.json +1 -1
  23. package/examples/myProfile/dist/connectors/office365users.js +3154 -0
  24. package/examples/myProfile/dist/index.js +1 -5
  25. package/examples/myProfile/power.config.json +1 -1
  26. package/examples/outlook Demo/dist/connectors/office365outlook.js +28521 -0
  27. package/examples/outlook Demo/dist/index.js +2 -5
  28. package/examples/outlook Demo/power.config.json +1 -1
  29. package/examples/sharePoint Demo/dist/connectors/sharepoint.js +687 -0
  30. package/examples/sharePoint Demo/dist/index.js +86 -127
  31. package/examples/sharePoint Demo/power.config.json +1 -1
  32. package/package.json +1 -1
  33. package/codeApp/.power/schemas/appschemas/dataSourcesInfo.ts +0 -6275
  34. package/codeApp/.power/schemas/jira/jira.Schema.json +0 -6903
  35. package/codeApp/.power/schemas/keyvault/keyvault.Schema.json +0 -1600
  36. package/codeApp/.power/schemas/office365groups/office365groups.Schema.json +0 -2204
  37. package/codeApp/.power/schemas/teams/teams.Schema.json +0 -11112
  38. package/codeApp/dist/connectors/outlook.js +0 -1393
  39. package/codeApp/src/generated/index.ts +0 -12
  40. package/codeApp/src/generated/models/AzureKeyVaultModel.ts +0 -107
  41. package/codeApp/src/generated/models/JiraModel.ts +0 -501
  42. package/codeApp/src/generated/models/Office365GroupsModel.ts +0 -363
  43. package/codeApp/src/generated/models/Office365OutlookModel.ts +0 -2046
  44. package/codeApp/src/generated/models/Office365UsersModel.ts +0 -254
  45. package/codeApp/src/generated/services/AzureKeyVaultService.ts +0 -257
  46. package/codeApp/src/generated/services/JiraService.ts +0 -1124
  47. package/codeApp/src/generated/services/Office365GroupsService.ts +0 -326
  48. package/codeApp/src/generated/services/Office365OutlookService.ts +0 -2476
  49. package/codeApp/src/generated/services/Office365UsersService.ts +0 -358
  50. package/examples/apps/kanban/dist/dataverse.js +0 -94
  51. package/examples/apps/kanban/dist/environmentVar.js +0 -55
  52. package/examples/apps/kanban/dist/index.css +0 -605
  53. package/examples/apps/kanban/dist/index.html +0 -21
  54. package/examples/apps/kanban/dist/index.js +0 -860
  55. package/examples/apps/kanban/dist/office365groups.js +0 -97
  56. package/examples/apps/kanban/dist/office365users.js +0 -451
  57. package/examples/apps/kanban/dist/outlook.js +0 -162
  58. package/examples/apps/kanban/dist/power-apps-data.js +0 -2953
  59. package/examples/apps/kanban/dist/sharepoint.js +0 -435
  60. package/examples/apps/kanban/power.config.json +0 -35
  61. package/examples/apps/kanban/src/generated/index.ts +0 -14
  62. package/examples/apps/kanban/src/generated/models/Office365GroupsModel.ts +0 -363
  63. package/examples/apps/kanban/src/generated/models/Office365OutlookModel.ts +0 -2046
  64. package/examples/apps/kanban/src/generated/models/Office365UsersModel.ts +0 -254
  65. package/examples/apps/kanban/src/generated/services/Office365GroupsService.ts +0 -326
  66. package/examples/apps/kanban/src/generated/services/Office365OutlookService.ts +0 -2476
  67. package/examples/apps/kanban/src/generated/services/Office365UsersService.ts +0 -358
  68. package/examples/apps/planning Poker/additional files/AgilePoker_1_0_0_1.zip +0 -0
  69. package/examples/apps/planning Poker/additional files/PokerTables_1_0_0_1.zip +0 -0
  70. package/examples/apps/planning Poker/additional files/customizations (tables).xml +0 -6429
  71. package/examples/apps/planning Poker/additional files/dataverse-tables.json +0 -165
  72. package/examples/apps/planning Poker/additional files/readme.md +0 -122
  73. package/examples/apps/planning Poker/dist/dataverse.js +0 -78
  74. package/examples/apps/planning Poker/dist/index.html +0 -198
  75. package/examples/apps/planning Poker/dist/index.js +0 -955
  76. package/examples/apps/planning Poker/dist/power-apps-data.js +0 -2953
  77. package/examples/apps/planning Poker/dist/styles.css +0 -815
  78. package/examples/apps/planning Poker/power.config.json +0 -50
  79. package/examples/apps/solution explorer/dist/codeapp.js +0 -1098
  80. package/examples/apps/solution explorer/dist/icon-512.png +0 -0
  81. package/examples/apps/solution explorer/dist/index.html +0 -80
  82. package/examples/apps/solution explorer/dist/index.js +0 -735
  83. package/examples/apps/solution explorer/dist/power-apps-data.js +0 -3007
  84. package/examples/apps/solution explorer/dist/styles.css +0 -571
  85. package/examples/apps/solution explorer/power.config.json +0 -151
  86. package/examples/apps/todo/dist/dataverse.js +0 -64
  87. package/examples/apps/todo/dist/icon192.png +0 -0
  88. package/examples/apps/todo/dist/index.html +0 -75
  89. package/examples/apps/todo/dist/index.js +0 -9
  90. package/examples/apps/todo/dist/power-apps-data.js +0 -2953
  91. package/examples/apps/todo/dist/renderer.js +0 -375
  92. package/examples/apps/todo/dist/styles.css +0 -691
  93. package/examples/apps/todo/power.config.json +0 -35
  94. package/examples/combined demo/.power/schemas/appschemas/dataSourcesInfo.ts +0 -6275
  95. package/examples/combined demo/.power/schemas/jira/jira.Schema.json +0 -6903
  96. package/examples/combined demo/.power/schemas/keyvault/keyvault.Schema.json +0 -1600
  97. package/examples/combined demo/.power/schemas/teams/teams.Schema.json +0 -11112
  98. package/examples/combined demo/dist/office365users.js +0 -513
  99. package/examples/combined demo/dist/outlook.js +0 -1393
  100. package/examples/combined demo/src/generated/index.ts +0 -12
  101. package/examples/combined demo/src/generated/models/AzureKeyVaultModel.ts +0 -107
  102. package/examples/combined demo/src/generated/models/JiraModel.ts +0 -501
  103. package/examples/combined demo/src/generated/models/Office365GroupsModel.ts +0 -363
  104. package/examples/combined demo/src/generated/models/Office365OutlookModel.ts +0 -2046
  105. package/examples/combined demo/src/generated/models/Office365UsersModel.ts +0 -254
  106. package/examples/combined demo/src/generated/services/AzureKeyVaultService.ts +0 -257
  107. package/examples/combined demo/src/generated/services/JiraService.ts +0 -1124
  108. package/examples/combined demo/src/generated/services/Office365GroupsService.ts +0 -326
  109. package/examples/combined demo/src/generated/services/Office365OutlookService.ts +0 -2476
  110. package/examples/combined demo/src/generated/services/Office365UsersService.ts +0 -358
  111. package/examples/groups Demo/.power/schemas/appschemas/dataSourcesInfo.ts +0 -613
  112. package/examples/groups Demo/dist/office365groups.js +0 -642
  113. package/examples/groups Demo/src/generated/index.ts +0 -10
  114. package/examples/groups Demo/src/generated/models/Office365GroupsModel.ts +0 -363
  115. package/examples/groups Demo/src/generated/services/Office365GroupsService.ts +0 -326
  116. package/examples/myProfile/dist/office365users.js +0 -517
  117. package/examples/outlook Demo/.power/schemas/appschemas/dataSourcesInfo.ts +0 -6512
  118. package/examples/outlook Demo/dist/outlook.js +0 -1393
  119. package/examples/outlook Demo/src/generated/index.ts +0 -10
  120. package/examples/outlook Demo/src/generated/models/Office365OutlookModel.ts +0 -2046
  121. package/examples/outlook Demo/src/generated/services/Office365OutlookService.ts +0 -2476
  122. package/examples/sharePoint Demo/dist/sharepoint.js +0 -466
  123. package/examples/sharePoint Demo/src/generated/index.ts +0 -14
  124. package/examples/sharePoint Demo/src/generated/models/Office365GroupsModel.ts +0 -363
  125. package/examples/sharePoint Demo/src/generated/models/Office365OutlookModel.ts +0 -2046
  126. package/examples/sharePoint Demo/src/generated/models/Office365UsersModel.ts +0 -254
  127. package/examples/sharePoint Demo/src/generated/services/Office365GroupsService.ts +0 -326
  128. package/examples/sharePoint Demo/src/generated/services/Office365OutlookService.ts +0 -2476
  129. package/examples/sharePoint Demo/src/generated/services/Office365UsersService.ts +0 -358
  130. package/readme.md +0 -590
@@ -0,0 +1,687 @@
1
+ import { getClient } from '../power-apps-data.js';
2
+ import { _dbgWrap } from '../codeapp.js';
3
+
4
+ const DATA_SOURCE_NAME = 'sharepointonline';
5
+
6
+ const dataSourcesInfo = {
7
+ [DATA_SOURCE_NAME]: {
8
+ tableId: '',
9
+ version: '',
10
+ primaryKey: '',
11
+ dataSourceType: 'Connector',
12
+ apis: {
13
+ GetItems: {
14
+ path: '/{connectionId}/datasets/{siteUrl}/tables/{table}/items',
15
+ method: 'GET',
16
+ parameters: [
17
+ { name: 'connectionId', in: 'path', required: true, type: 'string' },
18
+ { name: 'siteUrl', in: 'path', required: true, type: 'string' },
19
+ { name: 'table', in: 'path', required: true, type: 'string' },
20
+ { name: '$filter', in: 'query', required: false, type: 'string' },
21
+ { name: '$orderby', in: 'query', required: false, type: 'string' },
22
+ { name: '$top', in: 'query', required: false, type: 'integer' },
23
+ { name: '$skip', in: 'query', required: false, type: 'integer' },
24
+ ],
25
+ },
26
+ GetItem: {
27
+ path: '/{connectionId}/datasets/{siteUrl}/tables/{table}/items/{id}',
28
+ method: 'GET',
29
+ parameters: [
30
+ { name: 'connectionId', in: 'path', required: true, type: 'string' },
31
+ { name: 'siteUrl', in: 'path', required: true, type: 'string' },
32
+ { name: 'table', in: 'path', required: true, type: 'string' },
33
+ { name: 'id', in: 'path', required: true, type: 'string' },
34
+ ],
35
+ },
36
+ PostItem: {
37
+ path: '/{connectionId}/datasets/{siteUrl}/tables/{table}/items',
38
+ method: 'POST',
39
+ parameters: [
40
+ { name: 'connectionId', in: 'path', required: true, type: 'string' },
41
+ { name: 'siteUrl', in: 'path', required: true, type: 'string' },
42
+ { name: 'table', in: 'path', required: true, type: 'string' },
43
+ { name: 'item', in: 'body', required: true, type: 'object' },
44
+ ],
45
+ },
46
+ PatchItem: {
47
+ path: '/{connectionId}/datasets/{siteUrl}/tables/{table}/items/{id}',
48
+ method: 'PATCH',
49
+ parameters: [
50
+ { name: 'connectionId', in: 'path', required: true, type: 'string' },
51
+ { name: 'siteUrl', in: 'path', required: true, type: 'string' },
52
+ { name: 'table', in: 'path', required: true, type: 'string' },
53
+ { name: 'id', in: 'path', required: true, type: 'string' },
54
+ { name: 'item', in: 'body', required: true, type: 'object' },
55
+ ],
56
+ },
57
+ DeleteItem: {
58
+ path: '/{connectionId}/datasets/{siteUrl}/tables/{table}/items/{id}',
59
+ method: 'DELETE',
60
+ parameters: [
61
+ { name: 'connectionId', in: 'path', required: true, type: 'string' },
62
+ { name: 'siteUrl', in: 'path', required: true, type: 'string' },
63
+ { name: 'table', in: 'path', required: true, type: 'string' },
64
+ { name: 'id', in: 'path', required: true, type: 'string' },
65
+ ],
66
+ },
67
+ GetTables: {
68
+ path: '/{connectionId}/datasets/{siteUrl}/tables',
69
+ method: 'GET',
70
+ parameters: [
71
+ { name: 'connectionId', in: 'path', required: true, type: 'string' },
72
+ { name: 'siteUrl', in: 'path', required: true, type: 'string' },
73
+ ],
74
+ },
75
+ GetDataSetsMetadata: {
76
+ path: '/{connectionId}/datasets/{siteUrl}',
77
+ method: 'GET',
78
+ parameters: [
79
+ { name: 'connectionId', in: 'path', required: true, type: 'string' },
80
+ { name: 'siteUrl', in: 'path', required: true, type: 'string' },
81
+ ],
82
+ },
83
+ CreateFile: {
84
+ path: '/{connectionId}/datasets/{siteUrl}/files',
85
+ method: 'POST',
86
+ parameters: [
87
+ { name: 'connectionId', in: 'path', required: true, type: 'string' },
88
+ { name: 'siteUrl', in: 'path', required: true, type: 'string' },
89
+ { name: 'folderPath', in: 'query', required: true, type: 'string' },
90
+ { name: 'name', in: 'query', required: true, type: 'string' },
91
+ { name: 'body', in: 'body', required: true, type: 'object' },
92
+ ],
93
+ },
94
+ UpdateFile: {
95
+ path: '/{connectionId}/datasets/{siteUrl}/files/{id}',
96
+ method: 'PUT',
97
+ parameters: [
98
+ { name: 'connectionId', in: 'path', required: true, type: 'string' },
99
+ { name: 'siteUrl', in: 'path', required: true, type: 'string' },
100
+ { name: 'id', in: 'path', required: true, type: 'string' },
101
+ { name: 'body', in: 'body', required: true, type: 'object' },
102
+ ],
103
+ },
104
+ DeleteFile: {
105
+ path: '/{connectionId}/datasets/{siteUrl}/files/{id}',
106
+ method: 'DELETE',
107
+ parameters: [
108
+ { name: 'connectionId', in: 'path', required: true, type: 'string' },
109
+ { name: 'siteUrl', in: 'path', required: true, type: 'string' },
110
+ { name: 'id', in: 'path', required: true, type: 'string' },
111
+ ],
112
+ },
113
+ MoveFile: {
114
+ path: '/{connectionId}/datasets/{siteUrl}/files/{id}/moveto',
115
+ method: 'POST',
116
+ parameters: [
117
+ { name: 'connectionId', in: 'path', required: true, type: 'string' },
118
+ { name: 'siteUrl', in: 'path', required: true, type: 'string' },
119
+ { name: 'id', in: 'path', required: true, type: 'string' },
120
+ { name: 'destinationFolderPath', in: 'query', required: true, type: 'string' },
121
+ { name: 'newFileName', in: 'query', required: false, type: 'string' },
122
+ ],
123
+ },
124
+ GetFileMetadata: {
125
+ path: '/{connectionId}/datasets/{siteUrl}/files/{id}',
126
+ method: 'GET',
127
+ parameters: [
128
+ { name: 'connectionId', in: 'path', required: true, type: 'string' },
129
+ { name: 'siteUrl', in: 'path', required: true, type: 'string' },
130
+ { name: 'id', in: 'path', required: true, type: 'string' },
131
+ ],
132
+ },
133
+ HttpRequest: {
134
+ path: '/{connectionId}/httprequest',
135
+ method: 'POST',
136
+ parameters: [
137
+ { name: 'connectionId', in: 'path', required: true, type: 'string' },
138
+ { name: 'method', in: 'body', required: true, type: 'string' },
139
+ { name: 'uri', in: 'body', required: true, type: 'string' },
140
+ { name: 'headers', in: 'body', required: false, type: 'object' },
141
+ { name: 'body', in: 'body', required: false, type: 'string' },
142
+ ],
143
+ },
144
+ },
145
+ },
146
+ };
147
+
148
+ const sharePointListCache = new Map();
149
+
150
+ function initSharePointClient() {
151
+ return getClient(dataSourcesInfo);
152
+ }
153
+
154
+ async function executeConnectorOperation(operationName, parameters = {}) {
155
+ try {
156
+ const oClient = await initSharePointClient();
157
+ const oResult = await oClient.executeAsync({
158
+ connectorOperation: {
159
+ tableName: DATA_SOURCE_NAME,
160
+ operationName,
161
+ parameters,
162
+ },
163
+ });
164
+
165
+ if (!oResult) {
166
+ throw new Error('No result returned');
167
+ }
168
+
169
+ if (oResult.success === false) {
170
+ throw new Error(getSpErrorMessage(oResult.error));
171
+ }
172
+
173
+ return Object.prototype.hasOwnProperty.call(oResult, 'data') ? oResult.data : oResult;
174
+ } catch (oError) {
175
+ throw new Error('SharePoint ' + operationName + ' failed: ' + getSpErrorMessage(oError));
176
+ }
177
+ }
178
+
179
+ function pickSharePointValue() {
180
+ for (let iIndex = 0; iIndex < arguments.length; iIndex += 1) {
181
+ const oValue = arguments[iIndex];
182
+ if (oValue !== undefined && oValue !== null) {
183
+ return oValue;
184
+ }
185
+ }
186
+
187
+ return undefined;
188
+ }
189
+
190
+ function isSharePointRecord(oValue) {
191
+ return !!oValue && typeof oValue === 'object' && !Array.isArray(oValue);
192
+ }
193
+
194
+ function getSpErrorMessage(oError) {
195
+ if (!oError) {
196
+ return 'Unknown error';
197
+ }
198
+
199
+ if (typeof oError === 'string') {
200
+ return oError;
201
+ }
202
+
203
+ if (oError instanceof Error && oError.message) {
204
+ return oError.message;
205
+ }
206
+
207
+ const aCandidates = [
208
+ oError.message,
209
+ oError.error && oError.error.message,
210
+ oError.body && oError.body.message,
211
+ oError.body && oError.body.error && oError.body.error.message,
212
+ oError.data && oError.data.message,
213
+ oError.detail,
214
+ ];
215
+
216
+ const sCandidate = aCandidates.find((sValue) => typeof sValue === 'string' && sValue.trim() !== '');
217
+ if (sCandidate) {
218
+ return sCandidate;
219
+ }
220
+
221
+ try {
222
+ return JSON.stringify(oError);
223
+ } catch (oStringifyError) {
224
+ return String(oError);
225
+ }
226
+ }
227
+
228
+ function requireNonEmptyString(sValue, sLabel) {
229
+ if (typeof sValue !== 'string' || sValue.trim() === '') {
230
+ throw new Error('SharePoint ' + sLabel + ' is required.');
231
+ }
232
+
233
+ return sValue.trim();
234
+ }
235
+
236
+ function requireRecord(oValue, sLabel) {
237
+ if (!oValue || typeof oValue !== 'object' || Array.isArray(oValue)) {
238
+ throw new Error('SharePoint ' + sLabel + ' must be an object.');
239
+ }
240
+
241
+ return oValue;
242
+ }
243
+
244
+ function normalizeHeaders(oHeaders) {
245
+ if (oHeaders == null) {
246
+ return {};
247
+ }
248
+
249
+ if (typeof oHeaders !== 'object' || Array.isArray(oHeaders)) {
250
+ throw new Error('SharePoint request headers must be an object.');
251
+ }
252
+
253
+ return oHeaders;
254
+ }
255
+
256
+ function normalizeNumericQueryValue(value, sLabel) {
257
+ if (value == null || value === '') {
258
+ return null;
259
+ }
260
+
261
+ const iValue = Number(value);
262
+ if (!Number.isFinite(iValue)) {
263
+ throw new Error('SharePoint ' + sLabel + ' must be numeric.');
264
+ }
265
+
266
+ return iValue;
267
+ }
268
+
269
+ function requireItemId(iItemId) {
270
+ if ((typeof iItemId !== 'string' && typeof iItemId !== 'number') || String(iItemId).trim() === '') {
271
+ throw new Error('SharePoint item ID is required.');
272
+ }
273
+
274
+ return iItemId;
275
+ }
276
+
277
+ function buildSiteUrlParam(siteUrl) {
278
+ return encodeURIComponent(requireNonEmptyString(siteUrl, 'site URL'));
279
+ }
280
+
281
+ function buildListContext(siteUrl, listId) {
282
+ return {
283
+ siteUrl: buildSiteUrlParam(siteUrl),
284
+ table: requireNonEmptyString(String(listId || ''), 'list ID'),
285
+ };
286
+ }
287
+
288
+ function buildItemQueryParameters(siteUrl, listId, { filter, orderBy, top, skip } = {}) {
289
+ const oParameters = buildListContext(siteUrl, listId);
290
+ if (filter) {
291
+ oParameters.$filter = String(filter);
292
+ }
293
+ if (orderBy) {
294
+ oParameters.$orderby = String(orderBy);
295
+ }
296
+
297
+ const iTop = normalizeNumericQueryValue(top, 'top');
298
+ const iSkip = normalizeNumericQueryValue(skip, 'skip');
299
+ if (iTop != null) {
300
+ oParameters.$top = iTop;
301
+ }
302
+ if (iSkip != null) {
303
+ oParameters.$skip = iSkip;
304
+ }
305
+
306
+ return oParameters;
307
+ }
308
+
309
+ function normalizeCollection(oPayload) {
310
+ if (Array.isArray(oPayload)) {
311
+ return oPayload;
312
+ }
313
+
314
+ const aCandidates = [
315
+ oPayload,
316
+ oPayload && oPayload.value,
317
+ oPayload && oPayload.items,
318
+ oPayload && oPayload.results,
319
+ oPayload && oPayload.body,
320
+ oPayload && oPayload.data,
321
+ oPayload && oPayload.result,
322
+ oPayload && oPayload.response,
323
+ oPayload && oPayload.d && oPayload.d.results,
324
+ ];
325
+
326
+ const aMatch = aCandidates.find((oCandidate) => Array.isArray(oCandidate));
327
+ return aMatch || [];
328
+ }
329
+
330
+ function normalizeSharePointLookupValue(value) {
331
+ if (value === undefined || value === null) {
332
+ return '';
333
+ }
334
+
335
+ return String(value).trim().toLowerCase();
336
+ }
337
+
338
+ function normalizeSharePointListReference(listReference) {
339
+ if (typeof listReference === 'string' || typeof listReference === 'number') {
340
+ const sValue = String(listReference).trim();
341
+ if (!sValue) {
342
+ throw new Error('SharePoint list reference is required.');
343
+ }
344
+
345
+ return { listName: sValue };
346
+ }
347
+
348
+ if (!isSharePointRecord(listReference)) {
349
+ throw new Error('SharePoint list reference must be a string or object.');
350
+ }
351
+
352
+ return listReference;
353
+ }
354
+
355
+ function getSharePointTableToken(oTable) {
356
+ const sCandidate = pickSharePointValue(
357
+ oTable && oTable.Name,
358
+ oTable && oTable.name,
359
+ oTable && oTable.table,
360
+ oTable && oTable.TableName,
361
+ oTable && oTable.tableName,
362
+ oTable && oTable.LogicalName,
363
+ oTable && oTable.logicalName
364
+ );
365
+
366
+ return typeof sCandidate === 'string' ? sCandidate.trim() : '';
367
+ }
368
+
369
+ function getSharePointExternalListId(oTable) {
370
+ const sCandidate = pickSharePointValue(
371
+ oTable && oTable.Id,
372
+ oTable && oTable.id,
373
+ oTable && oTable.TableId,
374
+ oTable && oTable.tableId,
375
+ oTable && oTable.ListId,
376
+ oTable && oTable.listId,
377
+ oTable && oTable.UniqueId,
378
+ oTable && oTable.uniqueId,
379
+ getSharePointTableToken(oTable)
380
+ );
381
+
382
+ return typeof sCandidate === 'string' ? sCandidate.trim() : '';
383
+ }
384
+
385
+ function getSharePointTableNames(oTable) {
386
+ const aCandidates = [
387
+ oTable && oTable.DisplayName,
388
+ oTable && oTable.displayName,
389
+ oTable && oTable.Title,
390
+ oTable && oTable.title,
391
+ oTable && oTable.ListName,
392
+ oTable && oTable.listName,
393
+ oTable && oTable.Name,
394
+ oTable && oTable.name,
395
+ ];
396
+
397
+ return aCandidates
398
+ .filter((sValue, iIndex, aValues) => typeof sValue === 'string' && sValue.trim() !== '' && aValues.indexOf(sValue) === iIndex)
399
+ .map((sValue) => sValue.trim());
400
+ }
401
+
402
+ function getSharePointPreferredListName(oTable, sFallback) {
403
+ return pickSharePointValue(...getSharePointTableNames(oTable), sFallback, '');
404
+ }
405
+
406
+ function getSharePointListCacheKey(siteUrl, { listId, listName } = {}) {
407
+ return [
408
+ buildSiteUrlParam(siteUrl),
409
+ normalizeSharePointLookupValue(listId),
410
+ normalizeSharePointLookupValue(listName),
411
+ ].join('::');
412
+ }
413
+
414
+ function createResolvedSharePointList(siteUrl, oTable, { listId, listName, accessLabel, matchedBy } = {}) {
415
+ const sSiteUrl = requireNonEmptyString(siteUrl, 'site URL');
416
+ const sTableToken = requireNonEmptyString(getSharePointTableToken(oTable) || getSharePointExternalListId(oTable), 'table token');
417
+ const sResolvedListId = requireNonEmptyString(getSharePointExternalListId(oTable) || listId || sTableToken, 'list ID');
418
+ const sResolvedListName = getSharePointPreferredListName(oTable, listName || sResolvedListId);
419
+ const sAccessLabel = pickSharePointValue(accessLabel, 'Connector table API');
420
+ const sMatchedBy = pickSharePointValue(matchedBy, 'connector table lookup');
421
+
422
+ return {
423
+ siteUrl: sSiteUrl,
424
+ listId: sResolvedListId,
425
+ listName: sResolvedListName,
426
+ table: sTableToken,
427
+ accessLabel: sAccessLabel,
428
+ matchedBy: sMatchedBy,
429
+ rawTable: oTable || null,
430
+ sSiteUrl: sSiteUrl,
431
+ sListId: sResolvedListId,
432
+ sListName: sResolvedListName,
433
+ sAccessLabel: sAccessLabel,
434
+ sMatchedBy: sMatchedBy,
435
+ oTable: oTable || null,
436
+ };
437
+ }
438
+
439
+ function createConfiguredSharePointList(siteUrl, { listId, listName, accessLabel, matchedBy } = {}) {
440
+ const sSiteUrl = requireNonEmptyString(siteUrl, 'site URL');
441
+ const sResolvedListId = requireNonEmptyString(String(listId || ''), 'list ID');
442
+ const sResolvedListName = requireNonEmptyString(String(listName || sResolvedListId), 'list name');
443
+ const sAccessLabel = pickSharePointValue(accessLabel, 'Configured list ID');
444
+ const sMatchedBy = pickSharePointValue(matchedBy, 'configured list ID');
445
+
446
+ return {
447
+ siteUrl: sSiteUrl,
448
+ listId: sResolvedListId,
449
+ listName: sResolvedListName,
450
+ table: sResolvedListId,
451
+ accessLabel: sAccessLabel,
452
+ matchedBy: sMatchedBy,
453
+ rawTable: null,
454
+ sSiteUrl: sSiteUrl,
455
+ sListId: sResolvedListId,
456
+ sListName: sResolvedListName,
457
+ sAccessLabel: sAccessLabel,
458
+ sMatchedBy: sMatchedBy,
459
+ oTable: null,
460
+ };
461
+ }
462
+
463
+ function findSharePointTable(aTables, { listId, listName } = {}) {
464
+ const sNormalizedListId = normalizeSharePointLookupValue(listId);
465
+ const sNormalizedListName = normalizeSharePointLookupValue(listName);
466
+
467
+ return normalizeCollection(aTables).find((oTable) => {
468
+ const aIdCandidates = [
469
+ getSharePointTableToken(oTable),
470
+ getSharePointExternalListId(oTable),
471
+ ].map((sValue) => normalizeSharePointLookupValue(sValue)).filter(Boolean);
472
+
473
+ if (sNormalizedListId && aIdCandidates.indexOf(sNormalizedListId) !== -1) {
474
+ return true;
475
+ }
476
+
477
+ if (!sNormalizedListName) {
478
+ return false;
479
+ }
480
+
481
+ return getSharePointTableNames(oTable).some((sCandidate) => normalizeSharePointLookupValue(sCandidate) === sNormalizedListName);
482
+ }) || null;
483
+ }
484
+
485
+ export const callSharePointOperation = async (operationName, parameters = {}) => _dbgWrap('callSharePointOperation', [operationName, parameters], async function() {
486
+ return executeConnectorOperation(operationName, parameters);
487
+ });
488
+
489
+ export const sendHttpRequest = async ({ method = 'GET', uri, headers, body } = {}) => _dbgWrap('sendHttpRequest', [{ method, uri, headers, body }], async function() {
490
+ return executeConnectorOperation('HttpRequest', {
491
+ method: String(method || 'GET').toUpperCase(),
492
+ uri: requireNonEmptyString(uri, 'request URI'),
493
+ headers: normalizeHeaders(headers),
494
+ body: body == null ? '' : body,
495
+ });
496
+ });
497
+
498
+ export const getItems = async (siteUrl, listId, { filter, orderBy, top, skip } = {}) => _dbgWrap('getItems', [siteUrl, listId, { filter, orderBy, top, skip }], async function() {
499
+ return executeConnectorOperation('GetItems', buildItemQueryParameters(siteUrl, listId, { filter, orderBy, top, skip }));
500
+ });
501
+
502
+ export const getSpItem = async (siteUrl, listId, itemId) => _dbgWrap('getSpItem', [siteUrl, listId, itemId], async function() {
503
+ return executeConnectorOperation('GetItem', Object.assign(buildListContext(siteUrl, listId), {
504
+ id: requireItemId(itemId),
505
+ }));
506
+ });
507
+
508
+ export const createSpItem = async (siteUrl, listId, fields) => _dbgWrap('createSpItem', [siteUrl, listId, fields], async function() {
509
+ return executeConnectorOperation('PostItem', Object.assign(buildListContext(siteUrl, listId), {
510
+ item: requireRecord(fields, 'item payload'),
511
+ }));
512
+ });
513
+
514
+ export const updateSpItem = async (siteUrl, listId, itemId, changedFields) => _dbgWrap('updateSpItem', [siteUrl, listId, itemId, changedFields], async function() {
515
+ return executeConnectorOperation('PatchItem', Object.assign(buildListContext(siteUrl, listId), {
516
+ id: requireItemId(itemId),
517
+ item: requireRecord(changedFields, 'item payload'),
518
+ }));
519
+ });
520
+
521
+ export const deleteSpItem = async (siteUrl, listId, itemId) => _dbgWrap('deleteSpItem', [siteUrl, listId, itemId], async function() {
522
+ return executeConnectorOperation('DeleteItem', Object.assign(buildListContext(siteUrl, listId), {
523
+ id: requireItemId(itemId),
524
+ }));
525
+ });
526
+
527
+ export const listTables = async (siteUrl) => _dbgWrap('listTables', [siteUrl], async function() {
528
+ return normalizeCollection(await executeConnectorOperation('GetTables', {
529
+ siteUrl: buildSiteUrlParam(siteUrl),
530
+ }));
531
+ });
532
+
533
+ export const listLibrary = async (siteUrl) => _dbgWrap('listLibrary', [siteUrl], async function() {
534
+ return executeConnectorOperation('GetDataSetsMetadata', {
535
+ siteUrl: buildSiteUrlParam(siteUrl),
536
+ });
537
+ });
538
+
539
+ export const resolveSharePointList = async (siteUrl, listReference = {}) => _dbgWrap('resolveSharePointList', [siteUrl, listReference], async function() {
540
+ const sSiteUrl = requireNonEmptyString(siteUrl, 'site URL');
541
+ const oReference = normalizeSharePointListReference(listReference);
542
+ const sListId = typeof pickSharePointValue(oReference.listId, oReference.sListId, oReference.table) === 'string' ? pickSharePointValue(oReference.listId, oReference.sListId, oReference.table).trim() : '';
543
+ const sListName = typeof pickSharePointValue(oReference.listName, oReference.sListName, oReference.name, oReference.title) === 'string' ? pickSharePointValue(oReference.listName, oReference.sListName, oReference.name, oReference.title).trim() : '';
544
+ const bRefresh = oReference.refresh === true;
545
+ const bSkipTableLookup = oReference.skipTableLookup === true;
546
+
547
+ if (!sListId && !sListName) {
548
+ throw new Error('Provide a SharePoint listId or listName.');
549
+ }
550
+
551
+ const sCacheKey = getSharePointListCacheKey(sSiteUrl, { listId: sListId, listName: sListName });
552
+ if (!bRefresh && sharePointListCache.has(sCacheKey)) {
553
+ return sharePointListCache.get(sCacheKey);
554
+ }
555
+
556
+ let oResolvedList = null;
557
+ let oLookupError = null;
558
+
559
+ if (!bSkipTableLookup) {
560
+ try {
561
+ const aTables = await listTables(sSiteUrl);
562
+ const oMatchedTable = findSharePointTable(aTables, {
563
+ listId: sListId,
564
+ listName: sListName,
565
+ });
566
+
567
+ if (oMatchedTable) {
568
+ oResolvedList = createResolvedSharePointList(sSiteUrl, oMatchedTable, {
569
+ listId: sListId,
570
+ listName: sListName,
571
+ matchedBy: sListId ? 'connector table ID' : 'connector table name',
572
+ });
573
+ }
574
+ } catch (oError) {
575
+ oLookupError = oError;
576
+ }
577
+ }
578
+
579
+ if (!oResolvedList && sListId) {
580
+ oResolvedList = createConfiguredSharePointList(sSiteUrl, {
581
+ listId: sListId,
582
+ listName: sListName,
583
+ });
584
+ }
585
+
586
+ if (!oResolvedList && oLookupError) {
587
+ throw oLookupError;
588
+ }
589
+
590
+ if (!oResolvedList) {
591
+ throw new Error('SharePoint list "' + sListName + '" was not found for site ' + sSiteUrl + '.');
592
+ }
593
+
594
+ sharePointListCache.set(sCacheKey, oResolvedList);
595
+ return oResolvedList;
596
+ });
597
+
598
+ export const getItemsByList = async (siteUrl, listReference, queryOptions = {}) => _dbgWrap('getItemsByList', [siteUrl, listReference, queryOptions], async function() {
599
+ const oResolvedList = await resolveSharePointList(siteUrl, listReference);
600
+ return getItems(oResolvedList.siteUrl, pickSharePointValue(oResolvedList.table, oResolvedList.listId), queryOptions);
601
+ });
602
+
603
+ export const getSpItemByList = async (siteUrl, listReference, itemId) => _dbgWrap('getSpItemByList', [siteUrl, listReference, itemId], async function() {
604
+ const oResolvedList = await resolveSharePointList(siteUrl, listReference);
605
+ return getSpItem(oResolvedList.siteUrl, pickSharePointValue(oResolvedList.table, oResolvedList.listId), itemId);
606
+ });
607
+
608
+ export const createSpItemByList = async (siteUrl, listReference, fields) => _dbgWrap('createSpItemByList', [siteUrl, listReference, fields], async function() {
609
+ const oResolvedList = await resolveSharePointList(siteUrl, listReference);
610
+ return createSpItem(oResolvedList.siteUrl, pickSharePointValue(oResolvedList.table, oResolvedList.listId), fields);
611
+ });
612
+
613
+ export const updateSpItemByList = async (siteUrl, listReference, itemId, changedFields) => _dbgWrap('updateSpItemByList', [siteUrl, listReference, itemId, changedFields], async function() {
614
+ const oResolvedList = await resolveSharePointList(siteUrl, listReference);
615
+ return updateSpItem(oResolvedList.siteUrl, pickSharePointValue(oResolvedList.table, oResolvedList.listId), itemId, changedFields);
616
+ });
617
+
618
+ export const deleteSpItemByList = async (siteUrl, listReference, itemId) => _dbgWrap('deleteSpItemByList', [siteUrl, listReference, itemId], async function() {
619
+ const oResolvedList = await resolveSharePointList(siteUrl, listReference);
620
+ return deleteSpItem(oResolvedList.siteUrl, pickSharePointValue(oResolvedList.table, oResolvedList.listId), itemId);
621
+ });
622
+
623
+ export const createFile = async (siteUrl, folderPath, fileName, fileContent) => _dbgWrap('createFile', [siteUrl, folderPath, fileName, fileContent], async function() {
624
+ return executeConnectorOperation('CreateFile', {
625
+ siteUrl: buildSiteUrlParam(siteUrl),
626
+ folderPath: requireNonEmptyString(folderPath, 'folder path'),
627
+ name: requireNonEmptyString(fileName, 'file name'),
628
+ body: fileContent,
629
+ });
630
+ });
631
+
632
+ export const updateFile = async (siteUrl, fileId, fileContent) => _dbgWrap('updateFile', [siteUrl, fileId, fileContent], async function() {
633
+ return executeConnectorOperation('UpdateFile', {
634
+ siteUrl: buildSiteUrlParam(siteUrl),
635
+ id: requireNonEmptyString(String(fileId || ''), 'file ID'),
636
+ body: fileContent,
637
+ });
638
+ });
639
+
640
+ export const deleteFile = async (siteUrl, fileId) => _dbgWrap('deleteFile', [siteUrl, fileId], async function() {
641
+ return executeConnectorOperation('DeleteFile', {
642
+ siteUrl: buildSiteUrlParam(siteUrl),
643
+ id: requireNonEmptyString(String(fileId || ''), 'file ID'),
644
+ });
645
+ });
646
+
647
+ export const moveFile = async (siteUrl, sourceFileId, destinationFolderPath, newFileName) => _dbgWrap('moveFile', [siteUrl, sourceFileId, destinationFolderPath, newFileName], async function() {
648
+ return executeConnectorOperation('MoveFile', {
649
+ siteUrl: buildSiteUrlParam(siteUrl),
650
+ id: requireNonEmptyString(String(sourceFileId || ''), 'source file ID'),
651
+ destinationFolderPath: requireNonEmptyString(destinationFolderPath, 'destination folder path'),
652
+ newFileName: newFileName || '',
653
+ });
654
+ });
655
+
656
+ export const getFileMetadata = async (siteUrl, fileId) => _dbgWrap('getFileMetadata', [siteUrl, fileId], async function() {
657
+ return executeConnectorOperation('GetFileMetadata', {
658
+ siteUrl: buildSiteUrlParam(siteUrl),
659
+ id: requireNonEmptyString(String(fileId || ''), 'file ID'),
660
+ });
661
+ });
662
+
663
+ const SharePointService = {
664
+ callSharePointOperation,
665
+ sendHttpRequest,
666
+ resolveSharePointList,
667
+ getItems,
668
+ getSpItem,
669
+ createSpItem,
670
+ updateSpItem,
671
+ deleteSpItem,
672
+ getItemsByList,
673
+ getSpItemByList,
674
+ createSpItemByList,
675
+ updateSpItemByList,
676
+ deleteSpItemByList,
677
+ listTables,
678
+ listLibrary,
679
+ createFile,
680
+ updateFile,
681
+ deleteFile,
682
+ moveFile,
683
+ getFileMetadata,
684
+ };
685
+
686
+ export { SharePointService };
687
+ export default SharePointService;