codeapp-js 0.3.0 → 1.0.1

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/codeApp/dist/connectors/sharepoint.js +466 -0
  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/{dev files → examples/sharePoint Demo/dist}/sharepoint.js +239 -112
  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
@@ -1,339 +1,435 @@
1
- import { getClient } from "@microsoft/power-apps/data";
2
-
3
- // ── Data source name (must match connectionReferences in power.config.json) ──
4
- const DATA_SOURCE = "sharepointonline";
5
-
6
- // ── Initialize SDK client for the SharePoint connector ─────────
7
- function initClient() {
8
- const dataSourcesInfo = {
9
- [DATA_SOURCE]: {
10
- tableId: "",
11
- version: "",
12
- primaryKey: "",
13
- dataSourceType: "Connector",
14
- apis: {
15
- GetItems: {
16
- path: "/{connectionId}/datasets/{siteUrl}/tables/{table}/items",
17
- method: "GET",
18
- parameters: [
19
- { name: "connectionId", in: "path", required: true },
20
- { name: "siteUrl", in: "path", required: true },
21
- { name: "table", in: "path", required: true },
22
- { name: "$filter", in: "query", required: false },
23
- { name: "$orderby", in: "query", required: false },
24
- { name: "$top", in: "query", required: false },
25
- { name: "$skip", in: "query", required: false },
26
- ],
27
- },
28
- GetItem: {
29
- path: "/{connectionId}/datasets/{siteUrl}/tables/{table}/items/{id}",
30
- method: "GET",
31
- parameters: [
32
- { name: "connectionId", in: "path", required: true },
33
- { name: "siteUrl", in: "path", required: true },
34
- { name: "table", in: "path", required: true },
35
- { name: "id", in: "path", required: true },
36
- ],
37
- },
38
- PostItem: {
39
- path: "/{connectionId}/datasets/{siteUrl}/tables/{table}/items",
40
- method: "POST",
41
- parameters: [
42
- { name: "connectionId", in: "path", required: true },
43
- { name: "siteUrl", in: "path", required: true },
44
- { name: "table", in: "path", required: true },
45
- { name: "item", in: "body", required: true },
46
- ],
47
- },
48
- PatchItem: {
49
- path: "/{connectionId}/datasets/{siteUrl}/tables/{table}/items/{id}",
50
- method: "PATCH",
51
- parameters: [
52
- { name: "connectionId", in: "path", required: true },
53
- { name: "siteUrl", in: "path", required: true },
54
- { name: "table", in: "path", required: true },
55
- { name: "id", in: "path", required: true },
56
- { name: "item", in: "body", required: true },
57
- ],
58
- },
59
- DeleteItem: {
60
- path: "/{connectionId}/datasets/{siteUrl}/tables/{table}/items/{id}",
61
- method: "DELETE",
62
- parameters: [
63
- { name: "connectionId", in: "path", required: true },
64
- { name: "siteUrl", in: "path", required: true },
65
- { name: "table", in: "path", required: true },
66
- { name: "id", in: "path", required: true },
67
- ],
68
- },
69
- GetTables: {
70
- path: "/{connectionId}/datasets/{siteUrl}/tables",
71
- method: "GET",
72
- parameters: [
73
- { name: "connectionId", in: "path", required: true },
74
- { name: "siteUrl", in: "path", required: true },
75
- ],
76
- },
77
- GetDataSetsMetadata: {
78
- path: "/{connectionId}/datasets/{siteUrl}",
79
- method: "GET",
80
- parameters: [
81
- { name: "connectionId", in: "path", required: true },
82
- { name: "siteUrl", in: "path", required: true },
83
- ],
84
- },
85
- CreateFile: {
86
- path: "/{connectionId}/datasets/{siteUrl}/files",
87
- method: "POST",
88
- parameters: [
89
- { name: "connectionId", in: "path", required: true },
90
- { name: "siteUrl", in: "path", required: true },
91
- { name: "folderPath", in: "query", required: true },
92
- { name: "name", in: "query", required: true },
93
- { name: "body", in: "body", required: true },
94
- ],
95
- },
96
- UpdateFile: {
97
- path: "/{connectionId}/datasets/{siteUrl}/files/{id}",
98
- method: "PUT",
99
- parameters: [
100
- { name: "connectionId", in: "path", required: true },
101
- { name: "siteUrl", in: "path", required: true },
102
- { name: "id", in: "path", required: true },
103
- { name: "body", in: "body", required: true },
104
- ],
105
- },
106
- DeleteFile: {
107
- path: "/{connectionId}/datasets/{siteUrl}/files/{id}",
108
- method: "DELETE",
109
- parameters: [
110
- { name: "connectionId", in: "path", required: true },
111
- { name: "siteUrl", in: "path", required: true },
112
- { name: "id", in: "path", required: true },
113
- ],
114
- },
115
- MoveFile: {
116
- path: "/{connectionId}/datasets/{siteUrl}/files/{id}/moveto",
117
- method: "POST",
118
- parameters: [
119
- { name: "connectionId", in: "path", required: true },
120
- { name: "siteUrl", in: "path", required: true },
121
- { name: "id", in: "path", required: true },
122
- { name: "destinationFolderPath", in: "query", required: true },
123
- { name: "newFileName", in: "query", required: false },
124
- ],
125
- },
126
- GetFileMetadata: {
127
- path: "/{connectionId}/datasets/{siteUrl}/files/{id}",
128
- method: "GET",
129
- parameters: [
130
- { name: "connectionId", in: "path", required: true },
131
- { name: "siteUrl", in: "path", required: true },
132
- { name: "id", in: "path", required: true },
133
- ],
134
- },
135
- HttpRequest: {
136
- path: "/{connectionId}/httprequest",
137
- method: "POST",
138
- parameters: [
139
- { name: "connectionId", in: "path", required: true },
140
- ],
141
- },
142
- },
143
- },
144
- };
145
- return getClient(dataSourcesInfo);
146
- }
147
-
148
- // ── Internal: execute a connector operation ────────────────────
149
- async function execOp(operationName, parameters) {
150
- const client = await initClient();
151
- const result = await client.executeAsync({
152
- connectorOperation: {
153
- tableName: DATA_SOURCE,
154
- operationName,
155
- parameters,
156
- },
157
- });
158
- if (!result.success) {
159
- throw new Error(result.error?.message || "Operation failed");
160
- }
161
- return result.data;
162
- }
163
-
164
- // ═══════════════════════════════════════════════════════════════
165
- // GENERIC
166
- // ═══════════════════════════════════════════════════════════════
167
-
168
- // ── Call any SharePoint connector operation by name ─────────────
169
- export async function callSharePointOperation(operationName, parameters = {}) {
170
- return execOp(operationName, parameters);
171
- }
172
-
173
- // ── Send HTTP Request (for list-name-based operations) ─────────
174
- export async function sendHttpRequest({ method = "GET", uri, headers, body }) {
175
- return execOp("HttpRequest", {
176
- method,
177
- uri,
178
- headers: headers || {},
179
- body: body || "",
180
- });
181
- }
182
-
183
- // ═══════════════════════════════════════════════════════════════
184
- // ITEMS (standard API — uses list ID)
185
- // ═══════════════════════════════════════════════════════════════
186
-
187
- // ── Get Items ──────────────────────────────────────────────────
188
- export async function getItems(sSiteUrl, sListId, { filter, orderBy, top, skip } = {}) {
189
- let params = { siteUrl: encodeURIComponent(sSiteUrl), table: sListId };
190
- if (filter) params.$filter = filter;
191
- if (orderBy) params.$orderby = orderBy;
192
- if (top != null) params.$top = top;
193
- if (skip != null) params.$skip = skip;
194
- return execOp("GetItems", params);
195
- }
196
-
197
- // ── Get Item ───────────────────────────────────────────────────
198
- export async function getItem(sSiteUrl, sListId, iItemId) {
199
- return execOp("GetItem", {
200
- siteUrl: encodeURIComponent(sSiteUrl),
201
- table: sListId,
202
- id: iItemId,
203
- });
204
- }
205
-
206
- // ── Create Item ────────────────────────────────────────────────
207
- export async function createItem(sSiteUrl, sListId, oFields) {
208
- return execOp("PostItem", {
209
- siteUrl: encodeURIComponent(sSiteUrl),
210
- table: sListId,
211
- item: oFields,
212
- });
213
- }
214
-
215
- // ── Update Item ────────────────────────────────────────────────
216
- export async function updateItem(sSiteUrl, sListId, iItemId, oChangedFields) {
217
- return execOp("PatchItem", {
218
- siteUrl: encodeURIComponent(sSiteUrl),
219
- table: sListId,
220
- id: iItemId,
221
- item: oChangedFields,
222
- });
223
- }
224
-
225
- // ── Delete Item ────────────────────────────────────────────────
226
- export async function deleteItem(sSiteUrl, sListId, iItemId) {
227
- return execOp("DeleteItem", {
228
- siteUrl: encodeURIComponent(sSiteUrl),
229
- table: sListId,
230
- id: iItemId,
231
- });
232
- }
233
-
234
- // ═══════════════════════════════════════════════════════════════
235
- // ITEMS (HTTP API — uses list name)
236
- // ═══════════════════════════════════════════════════════════════
237
-
238
- // ── Get Items by List Name ─────────────────────────────────────
239
- export async function getItemsByName(sSiteUrl, sListName, { filter, orderBy, top, skip } = {}) {
240
- let sUri = sSiteUrl + "/_api/web/lists/getbytitle('" + sListName + "')/items";
241
- let aQuery = [];
242
- if (filter) aQuery.push("$filter=" + filter);
243
- if (orderBy) aQuery.push("$orderby=" + orderBy);
244
- if (top != null) aQuery.push("$top=" + top);
245
- if (skip != null) aQuery.push("$skip=" + skip);
246
- if (aQuery.length > 0) sUri = sUri + "?" + aQuery.join("&");
247
- return sendHttpRequest({ method: "GET", uri: sUri, headers: { Accept: "application/json;odata=nometadata" } });
248
- }
249
-
250
- // ── Get Item by List Name ──────────────────────────────────────
251
- export async function getItemByName(sSiteUrl, sListName, iItemId) {
252
- let sUri = sSiteUrl + "/_api/web/lists/getbytitle('" + sListName + "')/items(" + iItemId + ")";
253
- return sendHttpRequest({ method: "GET", uri: sUri, headers: { Accept: "application/json;odata=nometadata" } });
254
- }
255
-
256
- // ── Create Item by List Name ───────────────────────────────────
257
- export async function createItemByName(sSiteUrl, sListName, oFields) {
258
- let sUri = sSiteUrl + "/_api/web/lists/getbytitle('" + sListName + "')/items";
259
- return sendHttpRequest({ method: "POST", uri: sUri, headers: { Accept: "application/json;odata=nometadata", "Content-Type": "application/json;odata=nometadata" }, body: JSON.stringify(oFields) });
260
- }
261
-
262
- // ── Update Item by List Name ───────────────────────────────────
263
- export async function updateItemByName(sSiteUrl, sListName, iItemId, oChangedFields) {
264
- let sUri = sSiteUrl + "/_api/web/lists/getbytitle('" + sListName + "')/items(" + iItemId + ")";
265
- return sendHttpRequest({ method: "PATCH", uri: sUri, headers: { Accept: "application/json;odata=nometadata", "Content-Type": "application/json;odata=nometadata", "If-Match": "*" }, body: JSON.stringify(oChangedFields) });
266
- }
267
-
268
- // ── Delete Item by List Name ───────────────────────────────────
269
- export async function deleteItemByName(sSiteUrl, sListName, iItemId) {
270
- let sUri = sSiteUrl + "/_api/web/lists/getbytitle('" + sListName + "')/items(" + iItemId + ")";
271
- return sendHttpRequest({ method: "DELETE", uri: sUri, headers: { Accept: "application/json;odata=nometadata", "If-Match": "*" } });
272
- }
273
-
274
- // ═══════════════════════════════════════════════════════════════
275
- // TABLES / LISTS
276
- // ═══════════════════════════════════════════════════════════════
277
-
278
- // ── List Tables (Lists) ────────────────────────────────────────
279
- export async function listTables(sSiteUrl) {
280
- return execOp("GetTables", {
281
- siteUrl: encodeURIComponent(sSiteUrl),
282
- });
283
- }
284
-
285
- // ── List Library (Document Libraries) ──────────────────────────
286
- export async function listLibrary(sSiteUrl) {
287
- return execOp("GetDataSetsMetadata", {
288
- siteUrl: encodeURIComponent(sSiteUrl),
289
- });
290
- }
291
-
292
- // ═══════════════════════════════════════════════════════════════
293
- // FILES
294
- // ═══════════════════════════════════════════════════════════════
295
-
296
- // ── Create File ────────────────────────────────────────────────
297
- export async function createFile(sSiteUrl, sLibraryName, sFileName, fileContent) {
298
- return execOp("CreateFile", {
299
- siteUrl: encodeURIComponent(sSiteUrl),
300
- folderPath: sLibraryName,
301
- name: sFileName,
302
- body: fileContent,
303
- });
304
- }
305
-
306
- // ── Update File ────────────────────────────────────────────────
307
- export async function updateFile(sSiteUrl, sFileId, fileContent) {
308
- return execOp("UpdateFile", {
309
- siteUrl: encodeURIComponent(sSiteUrl),
310
- id: sFileId,
311
- body: fileContent,
312
- });
313
- }
314
-
315
- // ── Delete File ────────────────────────────────────────────────
316
- export async function deleteFile(sSiteUrl, sFileId) {
317
- return execOp("DeleteFile", {
318
- siteUrl: encodeURIComponent(sSiteUrl),
319
- id: sFileId,
320
- });
321
- }
322
-
323
- // ── Move File ──────────────────────────────────────────────────
324
- export async function moveFile(sSiteUrl, sSourceFileId, sDestinationFolderPath, sNewFileName) {
325
- return execOp("MoveFile", {
326
- siteUrl: encodeURIComponent(sSiteUrl),
327
- id: sSourceFileId,
328
- destinationFolderPath: sDestinationFolderPath,
329
- newFileName: sNewFileName || "",
330
- });
331
- }
332
-
333
- // ── Get File Metadata ──────────────────────────────────────────
334
- export async function getFileMetadata(sSiteUrl, sFileId) {
335
- return execOp("GetFileMetadata", {
336
- siteUrl: encodeURIComponent(sSiteUrl),
337
- id: sFileId,
338
- });
339
- }
1
+ import { getClient } from "@microsoft/power-apps/data";
2
+
3
+ // ── Data source name (must match connectionReferences in power.config.json) ──
4
+ const DATA_SOURCE = "sharepointonline";
5
+
6
+ // ── Initialize SDK client for the SharePoint connector ─────────
7
+ function initClient() {
8
+ const dataSourcesInfo = {
9
+ [DATA_SOURCE]: {
10
+ tableId: "",
11
+ version: "",
12
+ primaryKey: "",
13
+ dataSourceType: "Connector",
14
+ apis: {
15
+ GetItems: {
16
+ path: "/{connectionId}/datasets/{siteUrl}/tables/{table}/items",
17
+ method: "GET",
18
+ parameters: [
19
+ { name: "connectionId", in: "path", required: true },
20
+ { name: "siteUrl", in: "path", required: true },
21
+ { name: "table", in: "path", required: true },
22
+ { name: "$filter", in: "query", required: false },
23
+ { name: "$orderby", in: "query", required: false },
24
+ { name: "$top", in: "query", required: false },
25
+ { name: "$skip", in: "query", required: false },
26
+ ],
27
+ },
28
+ GetItem: {
29
+ path: "/{connectionId}/datasets/{siteUrl}/tables/{table}/items/{id}",
30
+ method: "GET",
31
+ parameters: [
32
+ { name: "connectionId", in: "path", required: true },
33
+ { name: "siteUrl", in: "path", required: true },
34
+ { name: "table", in: "path", required: true },
35
+ { name: "id", in: "path", required: true },
36
+ ],
37
+ },
38
+ PostItem: {
39
+ path: "/{connectionId}/datasets/{siteUrl}/tables/{table}/items",
40
+ method: "POST",
41
+ parameters: [
42
+ { name: "connectionId", in: "path", required: true },
43
+ { name: "siteUrl", in: "path", required: true },
44
+ { name: "table", in: "path", required: true },
45
+ { name: "item", in: "body", required: true },
46
+ ],
47
+ },
48
+ PatchItem: {
49
+ path: "/{connectionId}/datasets/{siteUrl}/tables/{table}/items/{id}",
50
+ method: "PATCH",
51
+ parameters: [
52
+ { name: "connectionId", in: "path", required: true },
53
+ { name: "siteUrl", in: "path", required: true },
54
+ { name: "table", in: "path", required: true },
55
+ { name: "id", in: "path", required: true },
56
+ { name: "item", in: "body", required: true },
57
+ ],
58
+ },
59
+ DeleteItem: {
60
+ path: "/{connectionId}/datasets/{siteUrl}/tables/{table}/items/{id}",
61
+ method: "DELETE",
62
+ parameters: [
63
+ { name: "connectionId", in: "path", required: true },
64
+ { name: "siteUrl", in: "path", required: true },
65
+ { name: "table", in: "path", required: true },
66
+ { name: "id", in: "path", required: true },
67
+ ],
68
+ },
69
+ GetTables: {
70
+ path: "/{connectionId}/datasets/{siteUrl}/tables",
71
+ method: "GET",
72
+ parameters: [
73
+ { name: "connectionId", in: "path", required: true },
74
+ { name: "siteUrl", in: "path", required: true },
75
+ ],
76
+ },
77
+ GetDataSetsMetadata: {
78
+ path: "/{connectionId}/datasets/{siteUrl}",
79
+ method: "GET",
80
+ parameters: [
81
+ { name: "connectionId", in: "path", required: true },
82
+ { name: "siteUrl", in: "path", required: true },
83
+ ],
84
+ },
85
+ CreateFile: {
86
+ path: "/{connectionId}/datasets/{siteUrl}/files",
87
+ method: "POST",
88
+ parameters: [
89
+ { name: "connectionId", in: "path", required: true },
90
+ { name: "siteUrl", in: "path", required: true },
91
+ { name: "folderPath", in: "query", required: true },
92
+ { name: "name", in: "query", required: true },
93
+ { name: "body", in: "body", required: true },
94
+ ],
95
+ },
96
+ UpdateFile: {
97
+ path: "/{connectionId}/datasets/{siteUrl}/files/{id}",
98
+ method: "PUT",
99
+ parameters: [
100
+ { name: "connectionId", in: "path", required: true },
101
+ { name: "siteUrl", in: "path", required: true },
102
+ { name: "id", in: "path", required: true },
103
+ { name: "body", in: "body", required: true },
104
+ ],
105
+ },
106
+ DeleteFile: {
107
+ path: "/{connectionId}/datasets/{siteUrl}/files/{id}",
108
+ method: "DELETE",
109
+ parameters: [
110
+ { name: "connectionId", in: "path", required: true },
111
+ { name: "siteUrl", in: "path", required: true },
112
+ { name: "id", in: "path", required: true },
113
+ ],
114
+ },
115
+ MoveFile: {
116
+ path: "/{connectionId}/datasets/{siteUrl}/files/{id}/moveto",
117
+ method: "POST",
118
+ parameters: [
119
+ { name: "connectionId", in: "path", required: true },
120
+ { name: "siteUrl", in: "path", required: true },
121
+ { name: "id", in: "path", required: true },
122
+ { name: "destinationFolderPath", in: "query", required: true },
123
+ { name: "newFileName", in: "query", required: false },
124
+ ],
125
+ },
126
+ GetFileMetadata: {
127
+ path: "/{connectionId}/datasets/{siteUrl}/files/{id}",
128
+ method: "GET",
129
+ parameters: [
130
+ { name: "connectionId", in: "path", required: true },
131
+ { name: "siteUrl", in: "path", required: true },
132
+ { name: "id", in: "path", required: true },
133
+ ],
134
+ },
135
+ HttpRequest: {
136
+ path: "/{connectionId}/httprequest",
137
+ method: "POST",
138
+ parameters: [
139
+ { name: "connectionId", in: "path", required: true },
140
+ ],
141
+ },
142
+ },
143
+ },
144
+ };
145
+ return getClient(dataSourcesInfo);
146
+ }
147
+
148
+ // ── Internal: execute a connector operation ────────────────────
149
+ async function execOp(operationName, parameters) {
150
+ try {
151
+ const client = await initClient();
152
+ const result = await client.executeAsync({
153
+ connectorOperation: {
154
+ tableName: DATA_SOURCE,
155
+ operationName,
156
+ parameters: parameters || {},
157
+ },
158
+ });
159
+
160
+ if (!result) {
161
+ throw new Error("No result returned");
162
+ }
163
+
164
+ if (result.success === false) {
165
+ throw new Error(getSpErrorMessage(result.error));
166
+ }
167
+
168
+ return Object.prototype.hasOwnProperty.call(result, "data") ? result.data : result;
169
+ } catch (oError) {
170
+ throw new Error("SharePoint " + operationName + " failed: " + getSpErrorMessage(oError));
171
+ }
172
+ }
173
+
174
+ function getSpErrorMessage(oError) {
175
+ if (!oError) {
176
+ return "Unknown error";
177
+ }
178
+
179
+ if (typeof oError === "string") {
180
+ return oError;
181
+ }
182
+
183
+ if (oError instanceof Error && oError.message) {
184
+ return oError.message;
185
+ }
186
+
187
+ const aCandidates = [
188
+ oError.message,
189
+ oError.error && oError.error.message,
190
+ oError.body && oError.body.message,
191
+ oError.body && oError.body.error && oError.body.error.message,
192
+ oError.data && oError.data.message,
193
+ oError.detail,
194
+ ];
195
+
196
+ const sCandidate = aCandidates.find(function(sValue) {
197
+ return typeof sValue === "string" && sValue.trim() !== "";
198
+ });
199
+
200
+ if (sCandidate) {
201
+ return sCandidate;
202
+ }
203
+
204
+ try {
205
+ return JSON.stringify(oError);
206
+ } catch (oStringifyError) {
207
+ return String(oError);
208
+ }
209
+ }
210
+
211
+ function requireNonEmptyString(sValue, sLabel) {
212
+ if (typeof sValue !== "string" || sValue.trim() === "") {
213
+ throw new Error("SharePoint " + sLabel + " is required.");
214
+ }
215
+
216
+ return sValue.trim();
217
+ }
218
+
219
+ function requireRecord(oValue, sLabel) {
220
+ if (!oValue || typeof oValue !== "object" || Array.isArray(oValue)) {
221
+ throw new Error("SharePoint " + sLabel + " must be an object.");
222
+ }
223
+
224
+ return oValue;
225
+ }
226
+
227
+ function normalizeHeaders(oHeaders) {
228
+ if (oHeaders == null) {
229
+ return {};
230
+ }
231
+
232
+ if (typeof oHeaders !== "object" || Array.isArray(oHeaders)) {
233
+ throw new Error("SharePoint request headers must be an object.");
234
+ }
235
+
236
+ return oHeaders;
237
+ }
238
+
239
+ function normalizeNumericQueryValue(value, sLabel) {
240
+ if (value == null || value === "") {
241
+ return null;
242
+ }
243
+
244
+ const iValue = Number(value);
245
+ if (!Number.isFinite(iValue)) {
246
+ throw new Error("SharePoint " + sLabel + " must be numeric.");
247
+ }
248
+
249
+ return iValue;
250
+ }
251
+
252
+ function requireItemId(iItemId) {
253
+ if ((typeof iItemId !== "string" && typeof iItemId !== "number") || String(iItemId).trim() === "") {
254
+ throw new Error("SharePoint item ID is required.");
255
+ }
256
+
257
+ return iItemId;
258
+ }
259
+
260
+ function buildListContext(sSiteUrl, sListId) {
261
+ return {
262
+ siteUrl: encodeURIComponent(requireNonEmptyString(sSiteUrl, "site URL")),
263
+ table: requireNonEmptyString(sListId, "list ID"),
264
+ };
265
+ }
266
+
267
+ function buildItemQueryParameters(sSiteUrl, sListId, { filter, orderBy, top, skip } = {}) {
268
+ const oParams = buildListContext(sSiteUrl, sListId);
269
+
270
+ if (filter) {
271
+ oParams.$filter = String(filter);
272
+ }
273
+ if (orderBy) {
274
+ oParams.$orderby = String(orderBy);
275
+ }
276
+
277
+ const iTop = normalizeNumericQueryValue(top, "top");
278
+ const iSkip = normalizeNumericQueryValue(skip, "skip");
279
+ if (iTop != null) {
280
+ oParams.$top = iTop;
281
+ }
282
+ if (iSkip != null) {
283
+ oParams.$skip = iSkip;
284
+ }
285
+
286
+ return oParams;
287
+ }
288
+
289
+ function normalizeCollection(oPayload) {
290
+ if (Array.isArray(oPayload)) {
291
+ return oPayload;
292
+ }
293
+
294
+ const aCandidates = [
295
+ oPayload,
296
+ oPayload && oPayload.value,
297
+ oPayload && oPayload.items,
298
+ oPayload && oPayload.results,
299
+ oPayload && oPayload.body,
300
+ oPayload && oPayload.data,
301
+ oPayload && oPayload.result,
302
+ oPayload && oPayload.response,
303
+ oPayload && oPayload.d && oPayload.d.results,
304
+ ];
305
+
306
+ const aMatch = aCandidates.find(function(oCandidate) {
307
+ return Array.isArray(oCandidate);
308
+ });
309
+
310
+ return aMatch || [];
311
+ }
312
+
313
+ // ═══════════════════════════════════════════════════════════════
314
+ // GENERIC
315
+ // ═══════════════════════════════════════════════════════════════
316
+
317
+ // ── Call any SharePoint connector operation by name ─────────────
318
+ export async function callSharePointOperation(operationName, parameters = {}) {
319
+ return execOp(operationName, parameters);
320
+ }
321
+
322
+ // ── Send HTTP Request (raw escape hatch) ───────────────────────
323
+ export async function sendHttpRequest({ method = "GET", uri, headers, body } = {}) {
324
+ return execOp("HttpRequest", {
325
+ method: String(method || "GET").toUpperCase(),
326
+ uri: requireNonEmptyString(uri, "request URI"),
327
+ headers: normalizeHeaders(headers),
328
+ body: body == null ? "" : body,
329
+ });
330
+ }
331
+
332
+ // ═══════════════════════════════════════════════════════════════
333
+ // ITEMS (standard API uses list ID)
334
+ // ═══════════════════════════════════════════════════════════════
335
+
336
+ // ── Get Items ──────────────────────────────────────────────────
337
+ export async function getItems(sSiteUrl, sListId, { filter, orderBy, top, skip } = {}) {
338
+ return execOp("GetItems", buildItemQueryParameters(sSiteUrl, sListId, { filter, orderBy, top, skip }));
339
+ }
340
+
341
+ // ── Get Item ───────────────────────────────────────────────────
342
+ export async function getItem(sSiteUrl, sListId, iItemId) {
343
+ return execOp("GetItem", Object.assign(buildListContext(sSiteUrl, sListId), {
344
+ id: requireItemId(iItemId),
345
+ }));
346
+ }
347
+
348
+ // ── Create Item ────────────────────────────────────────────────
349
+ export async function createItem(sSiteUrl, sListId, oFields) {
350
+ return execOp("PostItem", Object.assign(buildListContext(sSiteUrl, sListId), {
351
+ item: requireRecord(oFields, "item payload"),
352
+ }));
353
+ }
354
+
355
+ // ── Update Item ────────────────────────────────────────────────
356
+ export async function updateItem(sSiteUrl, sListId, iItemId, oChangedFields) {
357
+ return execOp("PatchItem", Object.assign(buildListContext(sSiteUrl, sListId), {
358
+ id: requireItemId(iItemId),
359
+ item: requireRecord(oChangedFields, "item payload"),
360
+ }));
361
+ }
362
+
363
+ // ── Delete Item ────────────────────────────────────────────────
364
+ export async function deleteItem(sSiteUrl, sListId, iItemId) {
365
+ return execOp("DeleteItem", Object.assign(buildListContext(sSiteUrl, sListId), {
366
+ id: requireItemId(iItemId),
367
+ }));
368
+ }
369
+
370
+ // ═══════════════════════════════════════════════════════════════
371
+ // TABLES / LISTS
372
+ // ═══════════════════════════════════════════════════════════════
373
+
374
+ // ── List Tables (Lists) ────────────────────────────────────────
375
+ export async function listTables(sSiteUrl) {
376
+ return normalizeCollection(await execOp("GetTables", {
377
+ siteUrl: encodeURIComponent(requireNonEmptyString(sSiteUrl, "site URL")),
378
+ }));
379
+ }
380
+
381
+ // ── List Library (Document Libraries) ──────────────────────────
382
+ export async function listLibrary(sSiteUrl) {
383
+ return execOp("GetDataSetsMetadata", {
384
+ siteUrl: encodeURIComponent(requireNonEmptyString(sSiteUrl, "site URL")),
385
+ });
386
+ }
387
+
388
+ // ═══════════════════════════════════════════════════════════════
389
+ // FILES
390
+ // ═══════════════════════════════════════════════════════════════
391
+
392
+ // ── Create File ────────────────────────────────────────────────
393
+ export async function createFile(sSiteUrl, sLibraryName, sFileName, fileContent) {
394
+ return execOp("CreateFile", {
395
+ siteUrl: encodeURIComponent(requireNonEmptyString(sSiteUrl, "site URL")),
396
+ folderPath: requireNonEmptyString(sLibraryName, "folder path"),
397
+ name: requireNonEmptyString(sFileName, "file name"),
398
+ body: fileContent,
399
+ });
400
+ }
401
+
402
+ // ── Update File ────────────────────────────────────────────────
403
+ export async function updateFile(sSiteUrl, sFileId, fileContent) {
404
+ return execOp("UpdateFile", {
405
+ siteUrl: encodeURIComponent(requireNonEmptyString(sSiteUrl, "site URL")),
406
+ id: requireNonEmptyString(String(sFileId || ""), "file ID"),
407
+ body: fileContent,
408
+ });
409
+ }
410
+
411
+ // ── Delete File ────────────────────────────────────────────────
412
+ export async function deleteFile(sSiteUrl, sFileId) {
413
+ return execOp("DeleteFile", {
414
+ siteUrl: encodeURIComponent(requireNonEmptyString(sSiteUrl, "site URL")),
415
+ id: requireNonEmptyString(String(sFileId || ""), "file ID"),
416
+ });
417
+ }
418
+
419
+ // ── Move File ──────────────────────────────────────────────────
420
+ export async function moveFile(sSiteUrl, sSourceFileId, sDestinationFolderPath, sNewFileName) {
421
+ return execOp("MoveFile", {
422
+ siteUrl: encodeURIComponent(requireNonEmptyString(sSiteUrl, "site URL")),
423
+ id: requireNonEmptyString(String(sSourceFileId || ""), "source file ID"),
424
+ destinationFolderPath: requireNonEmptyString(sDestinationFolderPath, "destination folder path"),
425
+ newFileName: sNewFileName || "",
426
+ });
427
+ }
428
+
429
+ // ── Get File Metadata ──────────────────────────────────────────
430
+ export async function getFileMetadata(sSiteUrl, sFileId) {
431
+ return execOp("GetFileMetadata", {
432
+ siteUrl: encodeURIComponent(requireNonEmptyString(sSiteUrl, "site URL")),
433
+ id: requireNonEmptyString(String(sFileId || ""), "file ID"),
434
+ });
435
+ }