@microsoft/power-apps-native-host 0.2.22 → 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 (156) hide show
  1. package/README.md +162 -26
  2. package/compatibility/current.json +87 -0
  3. package/lib/NOTICE.txt +140 -1226
  4. package/lib/commonjs/auth/AuthContext.js +74 -18
  5. package/lib/commonjs/auth/AuthContext.web.js +32 -0
  6. package/lib/commonjs/auth/completePowerAppsAuthSession.js +16 -0
  7. package/lib/commonjs/bridge/NativePowerAppsBridge.js +20 -17
  8. package/lib/commonjs/bridge/PowerPagesBridge.js +157 -0
  9. package/lib/commonjs/bridge/bridgeState.js +40 -0
  10. package/lib/commonjs/connections/ConnectionSetupScreen.js +459 -80
  11. package/lib/commonjs/connections/PowerPlatformConnectionApi.js +946 -0
  12. package/lib/commonjs/connections/connectionMetadata.js +127 -0
  13. package/lib/commonjs/connections/connectionState.js +96 -0
  14. package/lib/commonjs/connections/disambiguate.js +19 -11
  15. package/lib/commonjs/connections/resolveConnections.js +347 -0
  16. package/lib/commonjs/connections/types.js +106 -0
  17. package/lib/commonjs/{platform → connections}/useConnectionRefs.js +128 -65
  18. package/lib/commonjs/connections/useConnectionSetup.js +111 -52
  19. package/lib/commonjs/controls/FilePicker.js +6 -0
  20. package/lib/commonjs/controls/ImagePicker.js +8 -0
  21. package/lib/commonjs/index.js +188 -6
  22. package/lib/commonjs/logger.js +9 -6
  23. package/lib/commonjs/offline/createOfflineHostActivationCallbacks.js +61 -0
  24. package/lib/commonjs/offline/useOfflineIntegration.js +12 -0
  25. package/lib/commonjs/offline/useOfflineIntegration.web.js +11 -0
  26. package/lib/commonjs/offline/useOfflineIntegrationWithStartupGate.js +46 -0
  27. package/lib/commonjs/offline/useOfflineIntegrationWithStartupGate.web.js +13 -0
  28. package/lib/commonjs/platform/DataverseDataSources.js +14 -0
  29. package/lib/commonjs/platform/DataverseGlobalDiscoveryApi.js +49 -0
  30. package/lib/commonjs/platform/GlobalDiscovery.js +51 -0
  31. package/lib/commonjs/platform/PowerPlatformEnvironmentApi.js +6 -106
  32. package/lib/commonjs/provider/PowerAppsHostProvider.js +156 -25
  33. package/lib/commonjs/provider/PowerAppsHostProvider.web.js +41 -0
  34. package/lib/commonjs/provider/PowerAppsProvider.js +229 -133
  35. package/lib/commonjs/provider/SessionDetailsGesture.js +216 -0
  36. package/lib/commonjs/telemetry/OfflineSdkTelemetry.js +95 -0
  37. package/lib/commonjs/telemetry/OfflineSdkTelemetry.web.js +9 -0
  38. package/lib/commonjs/telemetry/index.js +22 -3
  39. package/lib/module/auth/AuthContext.js +74 -18
  40. package/lib/module/auth/AuthContext.web.js +26 -0
  41. package/lib/module/auth/completePowerAppsAuthSession.js +11 -0
  42. package/lib/module/bridge/NativePowerAppsBridge.js +21 -18
  43. package/lib/module/bridge/PowerPagesBridge.js +151 -0
  44. package/lib/module/bridge/bridgeState.js +34 -0
  45. package/lib/module/connections/ConnectionSetupScreen.js +460 -81
  46. package/lib/module/connections/PowerPlatformConnectionApi.js +932 -0
  47. package/lib/module/connections/connectionMetadata.js +112 -0
  48. package/lib/module/connections/connectionState.js +82 -0
  49. package/lib/module/connections/disambiguate.js +19 -12
  50. package/lib/module/connections/resolveConnections.js +342 -0
  51. package/lib/module/connections/types.js +91 -0
  52. package/lib/module/{platform → connections}/useConnectionRefs.js +129 -66
  53. package/lib/module/connections/useConnectionSetup.js +113 -54
  54. package/lib/module/controls/FilePicker.js +6 -0
  55. package/lib/module/controls/ImagePicker.js +8 -0
  56. package/lib/module/index.js +14 -6
  57. package/lib/module/logger.js +8 -6
  58. package/lib/module/offline/createOfflineHostActivationCallbacks.js +55 -0
  59. package/lib/module/offline/useOfflineIntegration.js +3 -0
  60. package/lib/module/offline/useOfflineIntegration.web.js +7 -0
  61. package/lib/module/offline/useOfflineIntegrationWithStartupGate.js +42 -0
  62. package/lib/module/offline/useOfflineIntegrationWithStartupGate.web.js +9 -0
  63. package/lib/module/platform/DataverseDataSources.js +10 -0
  64. package/lib/module/platform/DataverseGlobalDiscoveryApi.js +45 -0
  65. package/lib/module/platform/GlobalDiscovery.js +45 -0
  66. package/lib/module/platform/PowerPlatformEnvironmentApi.js +5 -104
  67. package/lib/module/provider/PowerAppsHostProvider.js +159 -28
  68. package/lib/module/provider/PowerAppsHostProvider.web.js +36 -0
  69. package/lib/module/provider/PowerAppsProvider.js +233 -137
  70. package/lib/module/provider/SessionDetailsGesture.js +211 -0
  71. package/lib/module/telemetry/OfflineSdkTelemetry.js +91 -0
  72. package/lib/module/telemetry/OfflineSdkTelemetry.web.js +5 -0
  73. package/lib/module/telemetry/index.js +15 -4
  74. package/lib/typescript/commonjs/auth/AuthContext.d.ts +3 -1
  75. package/lib/typescript/commonjs/auth/AuthContext.web.d.ts +21 -0
  76. package/lib/typescript/commonjs/auth/completePowerAppsAuthSession.d.ts +8 -0
  77. package/lib/typescript/commonjs/bridge/PowerPagesBridge.d.ts +18 -0
  78. package/lib/typescript/commonjs/bridge/bridgeState.d.ts +5 -0
  79. package/lib/typescript/commonjs/connections/ConnectionSetupScreen.d.ts +28 -7
  80. package/lib/typescript/commonjs/{platform → connections}/PowerPlatformConnectionApi.d.ts +52 -43
  81. package/lib/typescript/commonjs/connections/connectionMetadata.d.ts +66 -0
  82. package/lib/typescript/commonjs/connections/connectionState.d.ts +16 -0
  83. package/lib/typescript/commonjs/connections/disambiguate.d.ts +4 -2
  84. package/lib/typescript/commonjs/{platform → connections}/resolveConnections.d.ts +19 -19
  85. package/lib/typescript/commonjs/connections/types.d.ts +129 -1
  86. package/lib/typescript/commonjs/{platform → connections}/useConnectionRefs.d.ts +33 -24
  87. package/lib/typescript/commonjs/connections/useConnectionSetup.d.ts +12 -8
  88. package/lib/typescript/commonjs/controls/FilePicker.d.ts +7 -1
  89. package/lib/typescript/commonjs/controls/ImagePicker.d.ts +9 -1
  90. package/lib/typescript/commonjs/index.d.ts +20 -10
  91. package/lib/typescript/commonjs/logger.d.ts +4 -4
  92. package/lib/typescript/commonjs/offline/createOfflineHostActivationCallbacks.d.ts +12 -0
  93. package/lib/typescript/commonjs/offline/useOfflineIntegration.d.ts +2 -0
  94. package/lib/typescript/commonjs/offline/useOfflineIntegration.web.d.ts +4 -0
  95. package/lib/typescript/commonjs/offline/useOfflineIntegrationWithStartupGate.d.ts +15 -0
  96. package/lib/typescript/commonjs/offline/useOfflineIntegrationWithStartupGate.web.d.ts +6 -0
  97. package/lib/typescript/commonjs/platform/DataverseDataSources.d.ts +27 -0
  98. package/lib/typescript/commonjs/platform/DataverseGlobalDiscoveryApi.d.ts +3 -0
  99. package/lib/typescript/commonjs/platform/GlobalDiscovery.d.ts +4 -0
  100. package/lib/typescript/commonjs/platform/PowerPlatformEnvironmentApi.d.ts +3 -74
  101. package/lib/typescript/commonjs/provider/PowerAppsHostProvider.d.ts +29 -18
  102. package/lib/typescript/commonjs/provider/PowerAppsHostProvider.web.d.ts +5 -0
  103. package/lib/typescript/commonjs/provider/PowerAppsProvider.d.ts +32 -10
  104. package/lib/typescript/commonjs/provider/SessionDetailsGesture.d.ts +13 -0
  105. package/lib/typescript/commonjs/telemetry/OfflineSdkTelemetry.d.ts +15 -0
  106. package/lib/typescript/commonjs/telemetry/OfflineSdkTelemetry.web.d.ts +2 -0
  107. package/lib/typescript/commonjs/telemetry/index.d.ts +13 -1
  108. package/lib/typescript/module/auth/AuthContext.d.ts +3 -1
  109. package/lib/typescript/module/auth/AuthContext.web.d.ts +21 -0
  110. package/lib/typescript/module/auth/completePowerAppsAuthSession.d.ts +8 -0
  111. package/lib/typescript/module/bridge/PowerPagesBridge.d.ts +18 -0
  112. package/lib/typescript/module/bridge/bridgeState.d.ts +5 -0
  113. package/lib/typescript/module/connections/ConnectionSetupScreen.d.ts +28 -7
  114. package/lib/typescript/module/{platform → connections}/PowerPlatformConnectionApi.d.ts +52 -43
  115. package/lib/typescript/module/connections/connectionMetadata.d.ts +66 -0
  116. package/lib/typescript/module/connections/connectionState.d.ts +16 -0
  117. package/lib/typescript/module/connections/disambiguate.d.ts +4 -2
  118. package/lib/typescript/module/{platform → connections}/resolveConnections.d.ts +19 -19
  119. package/lib/typescript/module/connections/types.d.ts +129 -1
  120. package/lib/typescript/module/{platform → connections}/useConnectionRefs.d.ts +33 -24
  121. package/lib/typescript/module/connections/useConnectionSetup.d.ts +12 -8
  122. package/lib/typescript/module/controls/FilePicker.d.ts +7 -1
  123. package/lib/typescript/module/controls/ImagePicker.d.ts +9 -1
  124. package/lib/typescript/module/index.d.ts +24 -14
  125. package/lib/typescript/module/logger.d.ts +4 -4
  126. package/lib/typescript/module/offline/createOfflineHostActivationCallbacks.d.ts +12 -0
  127. package/lib/typescript/module/offline/useOfflineIntegration.d.ts +2 -0
  128. package/lib/typescript/module/offline/useOfflineIntegration.web.d.ts +4 -0
  129. package/lib/typescript/module/offline/useOfflineIntegrationWithStartupGate.d.ts +15 -0
  130. package/lib/typescript/module/offline/useOfflineIntegrationWithStartupGate.web.d.ts +6 -0
  131. package/lib/typescript/module/platform/DataverseDataSources.d.ts +27 -0
  132. package/lib/typescript/module/platform/DataverseGlobalDiscoveryApi.d.ts +3 -0
  133. package/lib/typescript/module/platform/GlobalDiscovery.d.ts +4 -0
  134. package/lib/typescript/module/platform/PowerPlatformEnvironmentApi.d.ts +3 -74
  135. package/lib/typescript/module/provider/PowerAppsHostProvider.d.ts +29 -18
  136. package/lib/typescript/module/provider/PowerAppsHostProvider.web.d.ts +5 -0
  137. package/lib/typescript/module/provider/PowerAppsProvider.d.ts +34 -12
  138. package/lib/typescript/module/provider/SessionDetailsGesture.d.ts +13 -0
  139. package/lib/typescript/module/telemetry/OfflineSdkTelemetry.d.ts +15 -0
  140. package/lib/typescript/module/telemetry/OfflineSdkTelemetry.web.d.ts +2 -0
  141. package/lib/typescript/module/telemetry/index.d.ts +13 -1
  142. package/package.json +43 -18
  143. package/scripts/build-ios-base.js +66 -27
  144. package/scripts/bundle.js +212 -5
  145. package/scripts/generate-connector-schemas.js +8 -6
  146. package/scripts/metro-logger.js +213 -0
  147. package/scripts/start-web.mjs +137 -0
  148. package/scripts/upgrade/runtime.js +463 -0
  149. package/scripts/upgrade/system.js +244 -0
  150. package/scripts/upgrade-authoring.js +534 -0
  151. package/scripts/upgrade.js +188 -0
  152. package/scripts/wrap.js +536 -0
  153. package/lib/commonjs/platform/PowerPlatformConnectionApi.js +0 -606
  154. package/lib/commonjs/platform/resolveConnections.js +0 -264
  155. package/lib/module/platform/PowerPlatformConnectionApi.js +0 -595
  156. package/lib/module/platform/resolveConnections.js +0 -259
@@ -1,264 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.applyAclGrants = applyAclGrants;
7
- exports.resolveViaStaticRefs = resolveViaStaticRefs;
8
- var _PowerPlatformConnectionApi = require("./PowerPlatformConnectionApi.js");
9
- var _PowerPlatformEnvironmentApi = require("./PowerPlatformEnvironmentApi.js");
10
- var _disambiguate = require("../connections/disambiguate.js");
11
- var _types = require("../connections/types.js");
12
- /*!
13
- * power-apps-native-host — resolveConnections
14
- *
15
- * Pure async helpers for the two connection-resolution strategies used by
16
- * useConnectionRefs:
17
- *
18
- * • resolveViaStaticRefs — per-connector resolution using the static
19
- * connectionReferences map from power.config.json. Used by the Dev Player
20
- * and during local development (no appId) or when the launch API is
21
- * unavailable. Handles pre-disambiguation ACL grants so inaccessible
22
- * connections are excluded before the user is asked to pick.
23
- *
24
- * • applyAclGrants — post-resolution ACL grants used by the fast path
25
- * (production APKs via fetchAppLaunchData).
26
- *
27
- * Both helpers return / consume the shared AppLaunchResult shape so the
28
- * hook orchestrator can handle them uniformly.
29
- */
30
-
31
- const API_VERSION = '1';
32
-
33
- // ---------------------------------------------------------------------------
34
- // ConnectorSchema
35
- // ---------------------------------------------------------------------------
36
-
37
- /**
38
- * Connector schema entry generated by `generate-connector-schemas`.
39
- * Keyed by data source name in the `schemaMap` passed to `useConnectionRefs`.
40
- */
41
-
42
- // ---------------------------------------------------------------------------
43
- // resolveViaStaticRefs
44
- // ---------------------------------------------------------------------------
45
-
46
- /**
47
- * Resolve connections from the static `connectionReferences` map.
48
- *
49
- * Steps:
50
- * 1. Build an apiId → schema lookup.
51
- * 2. In parallel: fetch the Dataverse instanceUrl and all connection instances
52
- * for every connector.
53
- * 3. If `isvClientId` is set, run pre-disambiguation ACL grants — connections
54
- * where the grant fails are marked `NeedsAclGrant` and excluded from
55
- * resolution, prompting the user to create a new connection.
56
- * 4. Disambiguate: resolve single matches, invoke callbacks for ambiguous /
57
- * missing cases, perform one-shot retries when `onMissingConnection` returns
58
- * `true`.
59
- * 5. Build and return an `AppLaunchResult`-shaped object.
60
- */
61
- async function resolveViaStaticRefs({
62
- connectionReferences,
63
- schemaMap,
64
- environmentId,
65
- region,
66
- acquireToken,
67
- token,
68
- isvClientId,
69
- onDisambiguationNeeded,
70
- onMissingConnection
71
- }) {
72
- // Build apiId → schema lookup from the static refs.
73
- const schemaByApiId = Object.fromEntries(Object.values(connectionReferences).map(ref => {
74
- const schema = ref.dataSources.map(ds => schemaMap[ds]).find(Boolean);
75
- return schema ? [ref.id, schema] : null;
76
- }).filter(entry => entry !== null));
77
- const base = (0, _PowerPlatformEnvironmentApi.buildEnvironmentEndpoint)(environmentId, region);
78
- const headers = {
79
- Authorization: `Bearer ${token}`
80
- };
81
-
82
- // Fetch Dataverse instanceUrl and all connection instances in parallel.
83
- const [instanceUrl, ...connResults] = await Promise.all([(0, _PowerPlatformEnvironmentApi.fetchInstanceUrl)(environmentId, region, acquireToken, token), ...Object.entries(connectionReferences).map(async ([localRefId, ref]) => {
84
- const schema = schemaByApiId[ref.id];
85
- if (!schema) {
86
- return {
87
- localRefId,
88
- apiId: ref.id,
89
- dataSources: ref.dataSources,
90
- instances: []
91
- };
92
- }
93
- const url = `${base}/connectivity/apis/${schema.name}/connections` + `?api-version=${API_VERSION}&$filter=environment eq '${environmentId}'`;
94
- try {
95
- const res = await fetch(url, {
96
- headers
97
- });
98
- if (!res.ok) {
99
- return {
100
- localRefId,
101
- apiId: ref.id,
102
- dataSources: ref.dataSources,
103
- instances: []
104
- };
105
- }
106
- const body = await res.json();
107
- const instances = (body.value ?? []).map(c => ({
108
- id: (0, _disambiguate.extractConnectionId)(c.name),
109
- name: c.name,
110
- apiId: ref.id,
111
- status: c.properties?.statuses?.[0]?.status === 'Connected' ? _types.ConnectionStatus.Connected : _types.ConnectionStatus.NotConnected,
112
- displayName: c.properties?.displayName
113
- }));
114
- return {
115
- localRefId,
116
- apiId: ref.id,
117
- dataSources: ref.dataSources,
118
- instances
119
- };
120
- } catch {
121
- return {
122
- localRefId,
123
- apiId: ref.id,
124
- dataSources: ref.dataSources,
125
- instances: []
126
- };
127
- }
128
- })]);
129
-
130
- // Pre-disambiguation ACL grants (ISV apps only).
131
- //
132
- // Connections where the grant fails are marked NeedsAclGrant so
133
- // disambiguation treats them as unavailable and surfaces the
134
- // "missing connection" flow, steering the user to create a new one.
135
- if (isvClientId) {
136
- const paToken = await acquireToken([_PowerPlatformConnectionApi.SERVICE_POWERAPPS_SCOPE]);
137
- const paOid = paToken ? (0, _PowerPlatformConnectionApi.parseJwtOid)(paToken) : null;
138
- if (paToken && paOid) {
139
- await Promise.all(connResults.map(async r => {
140
- const connId = schemaByApiId[r.apiId]?.name;
141
- if (!connId) return;
142
- await Promise.all(r.instances.map(async inst => {
143
- if (inst.status !== _types.ConnectionStatus.Connected) return;
144
- const ok = await (0, _PowerPlatformConnectionApi.addAadAppToConnectionAcl)(connId, inst.id, environmentId, isvClientId, paOid, paToken);
145
- if (!ok) inst.status = _types.ConnectionStatus.NeedsAclGrant;
146
- }));
147
- }));
148
- }
149
- }
150
-
151
- // Disambiguation.
152
- const allConnectionsByApiId = {};
153
- for (const r of connResults) {
154
- allConnectionsByApiId[r.apiId] = r.instances;
155
- }
156
- const disambiguationResults = (0, _disambiguate.disambiguateConnections)(connectionReferences, allConnectionsByApiId);
157
- const resolvedIds = {};
158
- const unresolvedApiIds = [];
159
- for (const dr of disambiguationResults) {
160
- if (dr.result.kind === 'resolved') {
161
- resolvedIds[dr.localRefId] = dr.result.connectionId;
162
- } else if (dr.result.kind === 'ambiguous') {
163
- const picked = onDisambiguationNeeded ? await onDisambiguationNeeded({
164
- localRefId: dr.localRefId,
165
- apiId: dr.apiId,
166
- candidates: dr.result.candidates
167
- }) : null;
168
- // Fall back to the first Connected candidate so the app can still start.
169
- resolvedIds[dr.localRefId] = picked ?? dr.result.candidates[0]?.id ?? '';
170
- } else {
171
- // kind === 'missing'
172
- let retried = false;
173
- if (onMissingConnection) {
174
- retried = await onMissingConnection({
175
- localRefId: dr.localRefId,
176
- apiId: dr.apiId
177
- });
178
- }
179
- if (retried) {
180
- // One-shot retry for this specific connector.
181
- const schema = schemaByApiId[dr.apiId];
182
- if (schema) {
183
- try {
184
- const url = `${base}/connectivity/apis/${schema.name}/connections` + `?api-version=${API_VERSION}&$filter=environment eq '${environmentId}'`;
185
- const res = await fetch(url, {
186
- headers
187
- });
188
- if (res.ok) {
189
- const body = await res.json();
190
- const retryInstances = (body.value ?? []).map(c => ({
191
- id: (0, _disambiguate.extractConnectionId)(c.name),
192
- name: c.name,
193
- apiId: dr.apiId,
194
- status: c.properties?.statuses?.[0]?.status === 'Connected' ? _types.ConnectionStatus.Connected : _types.ConnectionStatus.NotConnected
195
- }));
196
- const connected = retryInstances.find(i => i.status === _types.ConnectionStatus.Connected);
197
- if (connected) {
198
- resolvedIds[dr.localRefId] = connected.id;
199
- continue;
200
- }
201
- }
202
- } catch {
203
- // Fall through to missing.
204
- }
205
- }
206
- }
207
- resolvedIds[dr.localRefId] = '';
208
- unresolvedApiIds.push(dr.apiId);
209
- }
210
- }
211
- const dataverseOrgUrl = (instanceUrl ?? '').replace(/\/$/, '');
212
-
213
- // Build the final AppConnectionReference map.
214
- const connectionRefs = {};
215
- for (const [localRefId, ref] of Object.entries(connectionReferences)) {
216
- const schema = schemaByApiId[ref.id];
217
- const connectionName = resolvedIds[localRefId] ?? '';
218
- const isDataverse = ref.id.includes('commondataserviceforapps');
219
- const entry = {
220
- apiId: ref.id,
221
- runtimeUrl: schema?.properties.primaryRuntimeUrl ?? '',
222
- connectionName,
223
- datasetName: isDataverse ? dataverseOrgUrl : ''
224
- };
225
- for (const ds of ref.dataSources) {
226
- connectionRefs[ds] = entry;
227
- }
228
- }
229
- return {
230
- connectionRefs,
231
- dataverseOrgUrl,
232
- missingConnectors: unresolvedApiIds
233
- };
234
- }
235
-
236
- // ---------------------------------------------------------------------------
237
- // applyAclGrants
238
- // ---------------------------------------------------------------------------
239
-
240
- /**
241
- * Run idempotent post-resolution ACL grants on behalf of the ISV app.
242
- *
243
- * Used by the fast path (production APKs via `fetchAppLaunchData`) where the
244
- * launch API has already resolved the user's connections — grants are applied
245
- * after the fact so APIM accepts tokens issued to the ISV's AAD app.
246
- *
247
- * For the slow path the grants run before disambiguation inside
248
- * `resolveViaStaticRefs`, where they can still influence which connections
249
- * are considered available.
250
- *
251
- * Failures are swallowed — a failed grant will surface as a 403 at runtime
252
- * when the connector is called.
253
- */
254
- async function applyAclGrants(connectionRefs, environmentId, isvClientId, acquireToken) {
255
- const paToken = await acquireToken([_PowerPlatformConnectionApi.SERVICE_POWERAPPS_SCOPE]);
256
- const paOid = paToken ? (0, _PowerPlatformConnectionApi.parseJwtOid)(paToken) : null;
257
- if (!paToken || !paOid) return;
258
- const seen = new Set();
259
- await Promise.all(Object.values(connectionRefs).map(async ref => {
260
- if (!ref.connectionName || seen.has(ref.connectionName)) return;
261
- seen.add(ref.connectionName);
262
- await (0, _PowerPlatformConnectionApi.addAadAppToConnectionAcl)(ref.apiId, ref.connectionName, environmentId, isvClientId, paOid, paToken);
263
- }));
264
- }