codeapp-js 0.2.1 → 0.3.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 (100) hide show
  1. package/codeApp/.power/schemas/appschemas/dataSourcesInfo.ts +6275 -0
  2. package/codeApp/.power/schemas/jira/jira.Schema.json +6903 -0
  3. package/codeApp/.power/schemas/keyvault/keyvault.Schema.json +1600 -0
  4. package/codeApp/.power/schemas/teams/teams.Schema.json +11112 -0
  5. package/codeApp/dist/codeapp.js +992 -4
  6. package/codeApp/dist/power-apps-data.js +145 -31
  7. package/codeApp/src/generated/index.ts +12 -0
  8. package/codeApp/src/generated/models/AzureKeyVaultModel.ts +107 -0
  9. package/codeApp/src/generated/models/JiraModel.ts +501 -0
  10. package/codeApp/src/generated/models/Office365GroupsModel.ts +363 -0
  11. package/codeApp/src/generated/models/Office365OutlookModel.ts +2046 -0
  12. package/codeApp/src/generated/models/Office365UsersModel.ts +254 -0
  13. package/codeApp/src/generated/services/AzureKeyVaultService.ts +257 -0
  14. package/codeApp/src/generated/services/JiraService.ts +1124 -0
  15. package/codeApp/src/generated/services/Office365GroupsService.ts +326 -0
  16. package/codeApp/src/generated/services/Office365OutlookService.ts +2476 -0
  17. package/codeApp/src/generated/services/Office365UsersService.ts +358 -0
  18. package/dev files/outlook.js +218 -9
  19. package/examples/combined demo/dist/codeapp.js +1098 -1098
  20. package/examples/combined demo/dist/index.js +470 -470
  21. package/examples/combined demo/dist/power-apps-data.js +3006 -3006
  22. package/examples/combined demo/power.config.json +42 -42
  23. package/examples/dataverse Demo/dist/codeapp.js +1085 -1085
  24. package/examples/dataverse Demo/dist/index.html +54 -54
  25. package/examples/dataverse Demo/dist/index.js +82 -82
  26. package/examples/dataverse Demo/dist/power-apps-data.js +2911 -2911
  27. package/examples/dataverse Demo/power.config.json +34 -34
  28. package/examples/dataverse Demo/readme.md +79 -79
  29. package/examples/groups Demo/dist/codeapp.js +1085 -1085
  30. package/examples/groups Demo/dist/index.js +113 -113
  31. package/examples/groups Demo/dist/power-apps-data.js +2911 -2911
  32. package/examples/kanban/dist/dataverse.js +94 -94
  33. package/examples/kanban/dist/environmentVar.js +55 -55
  34. package/examples/kanban/dist/office365groups.js +97 -97
  35. package/examples/kanban/dist/office365users.js +169 -169
  36. package/examples/kanban/dist/outlook.js +162 -162
  37. package/examples/kanban/dist/power-apps-data.js +2953 -2953
  38. package/examples/kanban/dist/sharepoint.js +339 -339
  39. package/examples/myProfile/dist/index.html +184 -184
  40. package/examples/myProfile/dist/index.js +141 -141
  41. package/examples/myProfile/dist/office365users.js +169 -169
  42. package/examples/myProfile/dist/power-apps-data.js +2953 -2953
  43. package/examples/myProfile/power.config.json +22 -22
  44. package/examples/myProfile/readme.md +79 -79
  45. package/examples/outlook Demo/dist/codeapp.js +1085 -1085
  46. package/examples/outlook Demo/dist/index.html +35 -35
  47. package/examples/outlook Demo/dist/index.js +170 -170
  48. package/examples/outlook Demo/dist/outlook.js +121 -121
  49. package/examples/outlook Demo/dist/power-apps-data.js +2911 -2911
  50. package/examples/outlook Demo/dist/styles.css +84 -84
  51. package/examples/outlook Demo/readme.md +82 -82
  52. package/examples/outlook Demo2/OutlookDemo_1_0_0_1.zip +0 -0
  53. package/examples/outlook Demo2/agent/decision-log.md +7 -0
  54. package/examples/{solution explorer → outlook Demo2}/dist/codeapp.js +245 -9
  55. package/examples/outlook Demo2/dist/index.html +98 -0
  56. package/examples/outlook Demo2/dist/index.js +272 -0
  57. package/examples/outlook Demo2/dist/styles.css +639 -0
  58. package/examples/outlook Demo2/power.config.json +23 -0
  59. package/examples/outlook Demo2/src/generated/index.ts +14 -0
  60. package/examples/outlook Demo2/src/generated/models/Office365GroupsModel.ts +363 -0
  61. package/examples/outlook Demo2/src/generated/models/Office365OutlookModel.ts +2046 -0
  62. package/examples/outlook Demo2/src/generated/models/Office365UsersModel.ts +254 -0
  63. package/examples/outlook Demo2/src/generated/services/Office365GroupsService.ts +326 -0
  64. package/examples/outlook Demo2/src/generated/services/Office365OutlookService.ts +2476 -0
  65. package/examples/outlook Demo2/src/generated/services/Office365UsersService.ts +358 -0
  66. package/examples/planning Poker/.vscode/settings.json +4 -4
  67. package/examples/planning Poker/additional files/customizations (tables).xml +6428 -6428
  68. package/examples/planning Poker/additional files/dataverse-tables.json +165 -165
  69. package/examples/planning Poker/additional files/readme.md +122 -122
  70. package/examples/planning Poker/dist/dataverse.js +78 -78
  71. package/examples/planning Poker/dist/index.html +198 -198
  72. package/examples/planning Poker/dist/index.js +954 -954
  73. package/examples/planning Poker/dist/power-apps-data.js +2953 -2953
  74. package/examples/planning Poker/dist/styles.css +815 -815
  75. package/examples/sharePoint Demo/agent/decision-log.md +5 -5
  76. package/examples/sharePoint Demo/dist/codeapp.js +1085 -1085
  77. package/examples/sharePoint Demo/dist/index.js +262 -262
  78. package/examples/sharePoint Demo/dist/power-apps-data.js +2911 -2911
  79. package/examples/sharePoint Demo/power.config.json +22 -22
  80. package/examples/todo/dist/dataverse.js +64 -64
  81. package/examples/todo/dist/index.html +75 -75
  82. package/examples/todo/dist/index.js +8 -8
  83. package/examples/todo/dist/power-apps-data.js +2953 -2953
  84. package/examples/todo/dist/renderer.js +375 -375
  85. package/examples/todo/dist/styles.css +691 -691
  86. package/examples/todo/power.config.json +34 -34
  87. package/package.json +1 -1
  88. package/readme.md +33 -4
  89. package/examples/solution explorer/agent/decision-log.md +0 -27
  90. package/examples/solution explorer/agent/mockup-01-swiss-grid.html +0 -452
  91. package/examples/solution explorer/agent/mockup-02-dark-glass.html +0 -496
  92. package/examples/solution explorer/agent/mockup-03-paper-console.html +0 -510
  93. package/examples/solution explorer/agent/mockup-04-neon-noir.html +0 -546
  94. package/examples/solution explorer/agent/mockup-05-zen-garden.html +0 -534
  95. package/examples/solution explorer/dist/index.html +0 -80
  96. package/examples/solution explorer/dist/index.js +0 -735
  97. package/examples/solution explorer/dist/styles.css +0 -571
  98. package/examples/solution explorer/power.config.json +0 -151
  99. /package/examples/{solution explorer → outlook Demo2}/dist/icon-512.png +0 -0
  100. /package/examples/{solution explorer → outlook Demo2}/dist/power-apps-data.js +0 -0
@@ -1,10 +1,15 @@
1
1
  /* power-apps-data.js - Standalone Power Apps SDK for Code Apps
2
2
  Converted from @microsoft/power-apps v1.0.4
3
- Zero dependencies - all code is self-contained */
3
+ Zero dependencies - all code is self-contained
4
+ Version 2.0.1: add error handling and fix for invalid response formats from plugins
5
+ */
4
6
  var __defProp = Object.defineProperty;
5
7
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
8
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
7
9
 
10
+ const BRIDGE_INIT_TIMEOUT_MS = 8000;
11
+ const PLUGIN_CALL_TIMEOUT_MS = 30000;
12
+
8
13
  var DefaultPowerAppsBridge = class {
9
14
  constructor() {
10
15
  __publicField(this, "_antiCSRFToken");
@@ -14,6 +19,7 @@ var DefaultPowerAppsBridge = class {
14
19
  __publicField(this, "_messageChannel", new window.MessageChannel());
15
20
  __publicField(this, "_postMessageQueue", []);
16
21
  __publicField(this, "_postMessageSource");
22
+ __publicField(this, "_initializePromise");
17
23
  __publicField(this, "_handleMessageEvent", (messageEvent) => {
18
24
  const message = messageEvent.data;
19
25
  if (message && typeof message.isPluginCall === "boolean") {
@@ -52,21 +58,55 @@ var DefaultPowerAppsBridge = class {
52
58
  this._postMessageQueue[i].antiCSRFToken = this._antiCSRFToken;
53
59
  this._postMessageSource.postMessage(this._postMessageQueue[i]);
54
60
  }
61
+ this._postMessageQueue = [];
55
62
  }
56
63
  }
57
64
  });
58
65
  }
59
66
  async initialize() {
60
- this._messageChannel.port1.onmessage = this._handleMessageEvent;
61
- window.parent.postMessage({
62
- messageType: "initCommunicationWithPort",
63
- instanceId: this._instanceId
64
- }, "*", [this._messageChannel.port2]);
67
+ if (this._initializePromise) {
68
+ return this._initializePromise;
69
+ }
70
+ this._initializePromise = new Promise((resolve, reject) => {
71
+ if (window.parent === window) {
72
+ reject(new Error("Power Apps host was not detected. Open this app from the Power Apps Code Apps host instead of a standalone browser tab."));
73
+ return;
74
+ }
75
+ this._messageChannel.port1.onmessage = (messageEvent) => {
76
+ this._handleMessageEvent(messageEvent);
77
+ if (this._postMessageSource) {
78
+ clearTimeout(timeoutId);
79
+ resolve();
80
+ }
81
+ };
82
+ const timeoutId = window.setTimeout(() => {
83
+ reject(new Error("Timed out waiting for the Power Apps host to initialize the message bridge."));
84
+ }, BRIDGE_INIT_TIMEOUT_MS);
85
+ window.parent.postMessage({
86
+ messageType: "initCommunicationWithPort",
87
+ instanceId: this._instanceId
88
+ }, "*", [this._messageChannel.port2]);
89
+ });
90
+ return this._initializePromise;
65
91
  }
66
92
  async executePluginAsync(pluginName, pluginAction, params = [], onUpdate) {
67
93
  return new Promise((resolve, reject) => {
68
94
  const callbackId = this._getCallbackId(pluginName);
69
- this._callbacks[callbackId] = { resolve, reject, onUpdate };
95
+ const timeoutId = window.setTimeout(() => {
96
+ delete this._callbacks[callbackId];
97
+ reject(new Error(`Timed out waiting for ${pluginName}.${pluginAction} to return from the Power Apps host.`));
98
+ }, PLUGIN_CALL_TIMEOUT_MS);
99
+ this._callbacks[callbackId] = {
100
+ resolve: (value) => {
101
+ clearTimeout(timeoutId);
102
+ resolve(value);
103
+ },
104
+ reject: (error) => {
105
+ clearTimeout(timeoutId);
106
+ reject(error);
107
+ },
108
+ onUpdate
109
+ };
70
110
  this._sendMessage({
71
111
  isPluginCall: true,
72
112
  callbackId,
@@ -102,6 +142,7 @@ async function getBridge() {
102
142
  await bridge.initialize();
103
143
  resolve(bridge);
104
144
  } catch (error) {
145
+ bridgePromise = void 0;
105
146
  reject(error);
106
147
  }
107
148
  });
@@ -1310,13 +1351,23 @@ var _RuntimeMetadataClient = class _RuntimeMetadataClient {
1310
1351
  async _executeOperation(config) {
1311
1352
  try {
1312
1353
  const result = await this._powerOperationExecutor.execute(config.service, config.action, config.params || []);
1313
- const lowerCaseResult = Object.keys(result.data).reduce((acc, key) => {
1314
- acc[key.toLowerCase()] = (result.data ?? {})[key];
1354
+ const rawResult = result && typeof result === "object" && "data" in result ? result.data : result;
1355
+ const normalizedResult = Array.isArray(rawResult) && rawResult.length === 1 && rawResult[0] && typeof rawResult[0] === "object"
1356
+ ? rawResult[0]
1357
+ : rawResult;
1358
+ if (!normalizedResult || typeof normalizedResult !== "object" || Array.isArray(normalizedResult)) {
1359
+ throw new PowerDataRuntimeError(ErrorCodes.InvalidMetadataResponse, JSON.stringify(rawResult));
1360
+ }
1361
+ const lowerCaseResult = Object.keys(normalizedResult).reduce((acc, key) => {
1362
+ acc[key.toLowerCase()] = normalizedResult[key];
1315
1363
  return acc;
1316
1364
  }, {});
1317
1365
  return lowerCaseResult;
1318
- } catch {
1319
- throw new PowerDataRuntimeError(ErrorCodes.InvalidMetadataResponse);
1366
+ } catch (error) {
1367
+ if (error instanceof PowerDataRuntimeError) {
1368
+ throw error;
1369
+ }
1370
+ throw new PowerDataRuntimeError(ErrorCodes.InvalidMetadataResponse, getErrorMessage(error));
1320
1371
  }
1321
1372
  }
1322
1373
  };
@@ -2601,8 +2652,16 @@ async function loadConnections() {
2601
2652
  return;
2602
2653
  }
2603
2654
  connectionsLoaded = true;
2604
- await loadNonCompositeConnectionsAsync();
2605
- await resolveCompositeConnectionsAsync();
2655
+ try {
2656
+ await loadNonCompositeConnectionsAsync();
2657
+ } catch (error) {
2658
+ console.warn("Power Apps connection preload failed; continuing with runtime metadata fetch.", error);
2659
+ }
2660
+ try {
2661
+ await resolveCompositeConnectionsAsync();
2662
+ } catch (error) {
2663
+ console.warn("Power Apps composite connection resolution failed; continuing with runtime metadata fetch.", error);
2664
+ }
2606
2665
  }
2607
2666
  async function loadNonCompositeConnectionsAsync() {
2608
2667
  return executePluginAsync("AppPowerAppsClientPlugin", "loadNonCompositeConnectionsAsync", []);
@@ -2676,8 +2735,7 @@ async function executeAsync(dataSourcesInfo, operation) {
2676
2735
 
2677
2736
  async function callActionAsync(dataSourcesInfo, actionName, params) {
2678
2737
  var sdkInstance = await getPowerSdkInstance(dataSourcesInfo);
2679
- var orchestrator = sdkInstance.Data;
2680
- var dvExecutor = orchestrator._dataverseOperation;
2738
+ var dvExecutor = sdkInstance.Data._dataverseOperation;
2681
2739
  var dataClient = await dvExecutor._getDataClient();
2682
2740
  var dbRefs = await dvExecutor.getDatabaseReferences();
2683
2741
  var sInstanceUrl = null;
@@ -2691,26 +2749,82 @@ async function callActionAsync(dataSourcesInfo, actionName, params) {
2691
2749
  }
2692
2750
  }
2693
2751
  if (!sInstanceUrl) {
2694
- throw new Error("Cannot call unbound action: no Dataverse instance URL found. At least one Dataverse table must be registered.");
2752
+ throw new Error("Cannot call unbound action: no Dataverse instance URL found. Ensure at least one Dataverse table is registered.");
2695
2753
  }
2696
2754
  var sBaseUrl = sInstanceUrl.endsWith("/") ? sInstanceUrl : sInstanceUrl + "/";
2697
2755
  var sRequestUrl = sBaseUrl + "api/data/v9.0/" + actionName;
2698
- var oResponse = await dataClient.createDataAsync(
2699
- sRequestUrl,
2700
- DataSources.Dataverse,
2701
- actionName,
2702
- params || {},
2703
- {
2704
- operationName: DataverseOperationName.CreateRecord,
2705
- datasetName: sDatasetName,
2706
- isDataVerseOperation: true
2707
- }
2708
- );
2709
- return {
2710
- success: oResponse.success,
2711
- data: oResponse.data,
2712
- error: oResponse.error
2756
+ var oContext = {
2757
+ operationName: DataverseOperationName.CreateRecord,
2758
+ datasetName: sDatasetName,
2759
+ isDataVerseOperation: true
2713
2760
  };
2761
+ var sToken = await dataClient._getAccessToken(DataSources.Dataverse, sDatasetName);
2762
+ var oHeaders = dataClient._createHeaders(sToken, {
2763
+ url: sRequestUrl,
2764
+ method: HttpMethod.POST,
2765
+ apiId: DataSources.Dataverse,
2766
+ tableName: actionName,
2767
+ body: JSON.stringify(params || {})
2768
+ }, oContext);
2769
+ var oRequestBody = new Blob([JSON.stringify(params || {})], { type: "application/json" });
2770
+ var oRawResult;
2771
+ try {
2772
+ oRawResult = await dataClient._powerOperationExecutor.execute(
2773
+ "AppHttpClientPlugin", "sendHttpAsync",
2774
+ [
2775
+ {
2776
+ url: sRequestUrl,
2777
+ method: HttpMethod.POST,
2778
+ requestSource: "PublishedApp",
2779
+ allowSessionStorage: true,
2780
+ returnDirectResponse: true,
2781
+ headers: oHeaders
2782
+ },
2783
+ oRequestBody,
2784
+ "arraybuffer"
2785
+ ]
2786
+ );
2787
+ } catch (oErr) {
2788
+ return { success: false, data: null, error: oErr };
2789
+ }
2790
+ var aResponseData = oRawResult.data;
2791
+ var oRespHeaders = aResponseData[0] ? aResponseData[0].headers || {} : {};
2792
+ var iStatus = aResponseData[0] ? aResponseData[0].status : 0;
2793
+ var sContentType = oRespHeaders["Content-Type"] || "";
2794
+ // HTTP 2xx with no body or no parseable content = success (void actions like GrantAccess)
2795
+ if (iStatus >= 200 && iStatus < 300 && (!sContentType || !aResponseData[1])) {
2796
+ return { success: true, data: null, error: null };
2797
+ }
2798
+ // Try to parse JSON response
2799
+ if (sContentType.indexOf("application/json") !== -1 && aResponseData[1]) {
2800
+ try {
2801
+ var sText = "";
2802
+ if (aResponseData[1] instanceof ArrayBuffer) {
2803
+ sText = new TextDecoder().decode(aResponseData[1]);
2804
+ } else if (typeof aResponseData[1] === "string") {
2805
+ sText = aResponseData[1];
2806
+ }
2807
+ if (!sText) sText = "{}";
2808
+ var oParsed = JSON.parse(sText);
2809
+ if (iStatus >= 200 && iStatus < 300) {
2810
+ return { success: true, data: oParsed, error: null };
2811
+ }
2812
+ // Error response from server
2813
+ var sErrMsg = oParsed.error ? (oParsed.error.message || JSON.stringify(oParsed.error)) : JSON.stringify(oParsed);
2814
+ return { success: false, data: null, error: { message: sErrMsg } };
2815
+ } catch (oParseErr) {
2816
+ if (iStatus >= 200 && iStatus < 300) {
2817
+ return { success: true, data: null, error: null };
2818
+ }
2819
+ return { success: false, data: null, error: { message: "Failed to parse action response" } };
2820
+ }
2821
+ }
2822
+ // Any other 2xx = success
2823
+ if (iStatus >= 200 && iStatus < 300) {
2824
+ return { success: true, data: null, error: null };
2825
+ }
2826
+ // Non-2xx with non-JSON body
2827
+ return { success: false, data: null, error: { message: "Action failed with status " + iStatus } };
2714
2828
  }
2715
2829
 
2716
2830
  var _dataOperationExecutor;
@@ -0,0 +1,12 @@
1
+ /*!
2
+ * Copyright (C) Microsoft Corporation. All rights reserved.
3
+ * This file is autogenerated. Do not edit this file directly.
4
+ */
5
+
6
+ // Models
7
+ export * as AzureKeyVaultModel from './models/AzureKeyVaultModel';
8
+ export * as JiraModel from './models/JiraModel';
9
+
10
+ // Services
11
+ export * from './services/AzureKeyVaultService';
12
+ export * from './services/JiraService';
@@ -0,0 +1,107 @@
1
+ /*!
2
+ * Copyright (C) Microsoft Corporation. All rights reserved.
3
+ * This file is autogenerated. Do not edit this file directly.
4
+ */
5
+
6
+ export interface KeyMetadataCollection {
7
+ // The keys
8
+ value?: KeyMetadata[];
9
+ // Continuation token
10
+ continuationToken?: string;
11
+ }
12
+
13
+ export interface KeyMetadata {
14
+ // Name of the key
15
+ name?: string;
16
+ // Version of the key
17
+ version?: string;
18
+ // A flag indicating whether the key is enabled
19
+ isEnabled?: boolean;
20
+ // Time when the key was created
21
+ createdTime?: string;
22
+ // Time when the key was last updated
23
+ lastUpdatedTime?: string;
24
+ // Time when the key validity starts.
25
+ validityStartTime?: string;
26
+ // Time when the key validity ends.
27
+ validityEndTime?: string;
28
+ // Operations allowed using the key
29
+ allowedOperations?: string[];
30
+ // Type of the key
31
+ keyType?: string;
32
+ }
33
+
34
+ export type KeyEncryptInputalgorithm = 'RSA-OAEP-256'|'RSA-OAEP'|'RSA1_5';
35
+
36
+ export interface KeyEncryptInput {
37
+ // Algorithm to use for encrypting the data
38
+ algorithm: KeyEncryptInputalgorithm;
39
+ // Data to encrypt
40
+ rawData: string;
41
+ }
42
+
43
+ export interface KeyEncryptOutput {
44
+ // Encrypted data
45
+ encryptedData?: string;
46
+ }
47
+
48
+ export type KeyDecryptInputalgorithm = 'RSA-OAEP-256'|'RSA-OAEP'|'RSA1_5';
49
+
50
+ export interface KeyDecryptInput {
51
+ // Algorithm to use for decrypting the data
52
+ algorithm: KeyDecryptInputalgorithm;
53
+ // Data to decrypt
54
+ encryptedData: string;
55
+ }
56
+
57
+ export interface KeyDecryptOutput {
58
+ // Raw data
59
+ rawData?: string;
60
+ }
61
+
62
+ export interface SecretMetadataCollection {
63
+ // The secrets
64
+ value?: SecretMetadata[];
65
+ // Continuation token
66
+ continuationToken?: string;
67
+ }
68
+
69
+ export interface SecretMetadata {
70
+ // Name of the secret
71
+ name?: string;
72
+ // Version of the secret
73
+ version?: string;
74
+ // Content type of the secret
75
+ contentType?: string;
76
+ // A flag indicating whether the secret is enabled
77
+ isEnabled?: boolean;
78
+ // Time when the secret was created
79
+ createdTime?: string;
80
+ // Time when the secret was last updated
81
+ lastUpdatedTime?: string;
82
+ // Time when the secret validity starts.
83
+ validityStartTime?: string;
84
+ // Time when the secret validity ends.
85
+ validityEndTime?: string;
86
+ }
87
+
88
+ export interface Secret {
89
+ // Value of the secret
90
+ value?: string;
91
+ // Name of the secret
92
+ name?: string;
93
+ // Version of the secret
94
+ version?: string;
95
+ // Content type of the secret
96
+ contentType?: string;
97
+ // A flag indicating whether the secret is enabled
98
+ isEnabled?: boolean;
99
+ // Time when the secret was created
100
+ createdTime?: string;
101
+ // Time when the secret was last updated
102
+ lastUpdatedTime?: string;
103
+ // Time when the secret validity starts.
104
+ validityStartTime?: string;
105
+ // Time when the secret validity ends.
106
+ validityEndTime?: string;
107
+ }