@microsoft/power-apps-native-host 0.3.3 → 0.5.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 (111) hide show
  1. package/README.md +60 -0
  2. package/compatibility/current.json +1 -1
  3. package/lib/NOTICE.txt +2957 -371
  4. package/lib/commonjs/auth/AuthContext.js +49 -22
  5. package/lib/commonjs/auth/targetAuthorization.js +53 -0
  6. package/lib/commonjs/bridge/NativePowerAppsBridge.js +33 -2
  7. package/lib/commonjs/bridge/PowerPagesBridge.js +1 -3
  8. package/lib/commonjs/bridge/setupNativeHost.js +6 -0
  9. package/lib/commonjs/config/expoConfig.js +14 -0
  10. package/lib/commonjs/config/runtimeTenantMode.js +16 -0
  11. package/lib/commonjs/config/runtimeTenantMode.web.js +9 -0
  12. package/lib/commonjs/config/tenantMode.js +68 -0
  13. package/lib/commonjs/connections/PowerPlatformConnectionApi.js +24 -27
  14. package/lib/commonjs/connections/connectionMetadata.js +2 -2
  15. package/lib/commonjs/connections/resolveConnections.js +8 -3
  16. package/lib/commonjs/connections/types.js +9 -2
  17. package/lib/commonjs/connections/useConnectionRefs.js +19 -10
  18. package/lib/commonjs/index.js +41 -2
  19. package/lib/commonjs/platform/CanvasAppResolution.js +33 -0
  20. package/lib/commonjs/platform/CanvasAppResolutionApi.js +69 -0
  21. package/lib/commonjs/platform/DataverseGlobalDiscoveryApi.js +50 -13
  22. package/lib/commonjs/platform/GlobalDiscovery.js +40 -1
  23. package/lib/commonjs/provider/PowerAppsHostProvider.js +47 -8
  24. package/lib/commonjs/provider/PowerAppsProvider.js +175 -9
  25. package/lib/commonjs/target/DefaultPowerAppsExperience.js +564 -0
  26. package/lib/commonjs/target/PowerAppsExperience.js +41 -0
  27. package/lib/commonjs/target/PowerAppsTargetBootstrap.js +534 -0
  28. package/lib/commonjs/target/errors.js +24 -0
  29. package/lib/commonjs/target/types.js +1 -0
  30. package/lib/commonjs/telemetry/index.js +2 -2
  31. package/lib/module/auth/AuthContext.js +49 -22
  32. package/lib/module/auth/targetAuthorization.js +48 -0
  33. package/lib/module/bridge/NativePowerAppsBridge.js +33 -2
  34. package/lib/module/bridge/PowerPagesBridge.js +1 -3
  35. package/lib/module/bridge/setupNativeHost.js +5 -0
  36. package/lib/module/config/expoConfig.js +14 -0
  37. package/lib/module/config/runtimeTenantMode.js +12 -0
  38. package/lib/module/config/runtimeTenantMode.web.js +5 -0
  39. package/lib/module/config/tenantMode.js +61 -0
  40. package/lib/module/connections/PowerPlatformConnectionApi.js +24 -27
  41. package/lib/module/connections/connectionMetadata.js +2 -2
  42. package/lib/module/connections/resolveConnections.js +9 -4
  43. package/lib/module/connections/types.js +9 -2
  44. package/lib/module/connections/useConnectionRefs.js +20 -11
  45. package/lib/module/index.js +5 -2
  46. package/lib/module/platform/CanvasAppResolution.js +27 -0
  47. package/lib/module/platform/CanvasAppResolutionApi.js +65 -0
  48. package/lib/module/platform/DataverseGlobalDiscoveryApi.js +49 -14
  49. package/lib/module/platform/GlobalDiscovery.js +37 -1
  50. package/lib/module/provider/PowerAppsHostProvider.js +47 -8
  51. package/lib/module/provider/PowerAppsProvider.js +179 -13
  52. package/lib/module/target/DefaultPowerAppsExperience.js +559 -0
  53. package/lib/module/target/PowerAppsExperience.js +34 -0
  54. package/lib/module/target/PowerAppsTargetBootstrap.js +529 -0
  55. package/lib/module/target/errors.js +19 -0
  56. package/lib/module/target/types.js +1 -0
  57. package/lib/module/telemetry/index.js +1 -1
  58. package/lib/typescript/commonjs/auth/AuthContext.d.ts +11 -2
  59. package/lib/typescript/commonjs/auth/targetAuthorization.d.ts +15 -0
  60. package/lib/typescript/commonjs/bridge/NativePowerAppsBridge.d.ts +6 -0
  61. package/lib/typescript/commonjs/bridge/setupNativeHost.d.ts +2 -0
  62. package/lib/typescript/commonjs/config/runtimeTenantMode.d.ts +3 -0
  63. package/lib/typescript/commonjs/config/runtimeTenantMode.web.d.ts +3 -0
  64. package/lib/typescript/commonjs/config/tenantMode.d.ts +14 -0
  65. package/lib/typescript/commonjs/connections/PowerPlatformConnectionApi.d.ts +5 -2
  66. package/lib/typescript/commonjs/connections/connectionMetadata.d.ts +1 -1
  67. package/lib/typescript/commonjs/connections/types.d.ts +7 -1
  68. package/lib/typescript/commonjs/connections/useConnectionRefs.d.ts +11 -2
  69. package/lib/typescript/commonjs/index.d.ts +7 -3
  70. package/lib/typescript/commonjs/platform/CanvasAppResolution.d.ts +4 -0
  71. package/lib/typescript/commonjs/platform/CanvasAppResolutionApi.d.ts +6 -0
  72. package/lib/typescript/commonjs/platform/DataverseGlobalDiscoveryApi.d.ts +12 -2
  73. package/lib/typescript/commonjs/platform/GlobalDiscovery.d.ts +12 -0
  74. package/lib/typescript/commonjs/provider/PowerAppsHostProvider.d.ts +9 -1
  75. package/lib/typescript/commonjs/provider/PowerAppsProvider.d.ts +14 -16
  76. package/lib/typescript/commonjs/target/DefaultPowerAppsExperience.d.ts +6 -0
  77. package/lib/typescript/commonjs/target/PowerAppsExperience.d.ts +61 -0
  78. package/lib/typescript/commonjs/target/PowerAppsTargetBootstrap.d.ts +15 -0
  79. package/lib/typescript/commonjs/target/errors.d.ts +13 -0
  80. package/lib/typescript/commonjs/target/types.d.ts +34 -0
  81. package/lib/typescript/commonjs/telemetry/index.d.ts +2 -2
  82. package/lib/typescript/module/auth/AuthContext.d.ts +11 -2
  83. package/lib/typescript/module/auth/targetAuthorization.d.ts +15 -0
  84. package/lib/typescript/module/bridge/NativePowerAppsBridge.d.ts +6 -0
  85. package/lib/typescript/module/bridge/setupNativeHost.d.ts +2 -0
  86. package/lib/typescript/module/config/runtimeTenantMode.d.ts +3 -0
  87. package/lib/typescript/module/config/runtimeTenantMode.web.d.ts +3 -0
  88. package/lib/typescript/module/config/tenantMode.d.ts +14 -0
  89. package/lib/typescript/module/connections/PowerPlatformConnectionApi.d.ts +5 -2
  90. package/lib/typescript/module/connections/connectionMetadata.d.ts +1 -1
  91. package/lib/typescript/module/connections/types.d.ts +7 -1
  92. package/lib/typescript/module/connections/useConnectionRefs.d.ts +11 -2
  93. package/lib/typescript/module/index.d.ts +7 -3
  94. package/lib/typescript/module/platform/CanvasAppResolution.d.ts +4 -0
  95. package/lib/typescript/module/platform/CanvasAppResolutionApi.d.ts +6 -0
  96. package/lib/typescript/module/platform/DataverseGlobalDiscoveryApi.d.ts +12 -2
  97. package/lib/typescript/module/platform/GlobalDiscovery.d.ts +12 -0
  98. package/lib/typescript/module/provider/PowerAppsHostProvider.d.ts +9 -1
  99. package/lib/typescript/module/provider/PowerAppsProvider.d.ts +14 -16
  100. package/lib/typescript/module/target/DefaultPowerAppsExperience.d.ts +6 -0
  101. package/lib/typescript/module/target/PowerAppsExperience.d.ts +61 -0
  102. package/lib/typescript/module/target/PowerAppsTargetBootstrap.d.ts +15 -0
  103. package/lib/typescript/module/target/errors.d.ts +13 -0
  104. package/lib/typescript/module/target/types.d.ts +34 -0
  105. package/lib/typescript/module/telemetry/index.d.ts +2 -2
  106. package/package.json +12 -5
  107. package/scripts/build-codegen-package.js +34 -3
  108. package/scripts/dev.js +405 -0
  109. package/scripts/upgrade-authoring.js +85 -28
  110. package/scripts/wrap.js +42 -5
  111. package/src/config/generated-config.d.ts +21 -0
@@ -0,0 +1,534 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.PowerAppsTargetBootstrap = PowerAppsTargetBootstrap;
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ var _reactNative = require("react-native");
9
+ var SecureStore = _interopRequireWildcard(require("expo-secure-store"));
10
+ var _AuthContext = require("../auth/AuthContext");
11
+ var _DataverseGlobalDiscoveryApi = require("../platform/DataverseGlobalDiscoveryApi.js");
12
+ var _CanvasAppResolution = require("../platform/CanvasAppResolution.js");
13
+ var _CanvasAppResolutionApi = require("../platform/CanvasAppResolutionApi.js");
14
+ var _GlobalDiscovery = require("../platform/GlobalDiscovery.js");
15
+ var _PowerPlatformEnvironmentApi = require("../platform/PowerPlatformEnvironmentApi.js");
16
+ var _errors = require("./errors.js");
17
+ var _tenantMode = require("../config/tenantMode.js");
18
+ var _PowerAppsExperience = require("./PowerAppsExperience.js");
19
+ var _DefaultPowerAppsExperience = require("./DefaultPowerAppsExperience.js");
20
+ var _jsxRuntime = require("react/jsx-runtime");
21
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
22
+ const TARGET_STORAGE_KEY = 'microsoft.power-apps-native-host.selected-target.v1';
23
+ const EMPTY_ENVIRONMENT_STABILITY_MS = 500;
24
+ function LoadingScreen({
25
+ message
26
+ }) {
27
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
28
+ style: {
29
+ flex: 1,
30
+ alignItems: 'center',
31
+ justifyContent: 'center',
32
+ gap: 12,
33
+ padding: 24
34
+ },
35
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.ActivityIndicator, {
36
+ size: "large"
37
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
38
+ style: {
39
+ color: '#605E5C'
40
+ },
41
+ children: message
42
+ })]
43
+ });
44
+ }
45
+ function toEnvironmentSummary(target) {
46
+ return {
47
+ id: target.id,
48
+ label: target.label
49
+ };
50
+ }
51
+ function toExperienceError(error) {
52
+ return {
53
+ code: error.code,
54
+ message: error.userMessage,
55
+ retryable: error.retryable
56
+ };
57
+ }
58
+ function TargetRuntime({
59
+ target,
60
+ generation,
61
+ msalConfig,
62
+ isCurrent,
63
+ children,
64
+ onBack,
65
+ experienceComponent
66
+ }) {
67
+ const auth = (0, _AuthContext.useAuth)();
68
+ const [state, setState] = (0, _react.useState)('authenticating');
69
+ const [resolvedTarget, setResolvedTarget] = (0, _react.useState)();
70
+ const [error, setError] = (0, _react.useState)();
71
+ const [retry, setRetry] = (0, _react.useState)(0);
72
+ (0, _react.useEffect)(() => {
73
+ if (!auth.isAuthReady || !auth.account) return;
74
+ let active = true;
75
+ setState('resolving');
76
+ setError(undefined);
77
+ void (async () => {
78
+ try {
79
+ const dataverseApiUrl = target.dataverseApiUrl;
80
+ const resolved = await (0, _CanvasAppResolutionApi.resolveCanvasApp)(target, dataverseApiUrl, auth.acquireToken, {
81
+ value: generation,
82
+ isCurrent
83
+ });
84
+ if (!active || !isCurrent(generation)) return;
85
+ setResolvedTarget(resolved);
86
+ setState('ready');
87
+ } catch (cause) {
88
+ if (!active || !isCurrent(generation)) return;
89
+ setError(cause instanceof _errors.TargetRuntimeError ? cause : new _errors.TargetRuntimeError('service-unavailable', 'discovery', true, 'The selected environment could not be loaded. Try again.', target.id, cause));
90
+ setState('error');
91
+ }
92
+ })();
93
+ return () => {
94
+ active = false;
95
+ };
96
+ }, [auth.account, auth.acquireToken, auth.isAuthReady, generation, isCurrent, retry, target]);
97
+ if (auth.isLoading || !auth.isAuthReady) {
98
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_PowerAppsExperience.PowerAppsExperienceBoundary, {
99
+ experience: {
100
+ status: 'connecting',
101
+ environment: toEnvironmentSummary(target)
102
+ },
103
+ appDisplayName: target.appDisplayName,
104
+ component: experienceComponent,
105
+ fallback: /*#__PURE__*/(0, _jsxRuntime.jsx)(LoadingScreen, {
106
+ message: "Connecting to the selected environment..."
107
+ })
108
+ });
109
+ }
110
+ if (!auth.account) {
111
+ const fallback = /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
112
+ style: {
113
+ flex: 1,
114
+ alignItems: 'center',
115
+ justifyContent: 'center',
116
+ gap: 16,
117
+ padding: 24
118
+ },
119
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
120
+ children: auth.error?.message ?? 'Sign in to access the selected environment.'
121
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Pressable, {
122
+ accessibilityRole: "button",
123
+ onPress: () => {
124
+ void auth.signIn();
125
+ },
126
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
127
+ style: {
128
+ color: '#0F6CBD',
129
+ fontWeight: '600'
130
+ },
131
+ children: "Sign in"
132
+ })
133
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Pressable, {
134
+ accessibilityRole: "button",
135
+ onPress: onBack,
136
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
137
+ children: "Choose another environment"
138
+ })
139
+ })]
140
+ });
141
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_PowerAppsExperience.PowerAppsExperienceBoundary, {
142
+ experience: {
143
+ status: 'signIn',
144
+ error: auth.error?.message,
145
+ signIn: auth.signIn,
146
+ goBack: onBack
147
+ },
148
+ appDisplayName: target.appDisplayName,
149
+ component: experienceComponent,
150
+ fallback: fallback
151
+ });
152
+ }
153
+ if (state === 'error' && error) {
154
+ const retryResolution = () => setRetry(value => value + 1);
155
+ const fallback = /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
156
+ style: {
157
+ flex: 1,
158
+ alignItems: 'center',
159
+ justifyContent: 'center',
160
+ gap: 16,
161
+ padding: 24
162
+ },
163
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
164
+ style: {
165
+ fontWeight: '700'
166
+ },
167
+ children: "Unable to open environment"
168
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
169
+ children: error.userMessage
170
+ }), error.retryable ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Pressable, {
171
+ accessibilityRole: "button",
172
+ onPress: retryResolution,
173
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
174
+ style: {
175
+ color: '#0F6CBD',
176
+ fontWeight: '600'
177
+ },
178
+ children: "Try again"
179
+ })
180
+ }) : null, /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Pressable, {
181
+ accessibilityRole: "button",
182
+ onPress: onBack,
183
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
184
+ style: {
185
+ color: '#0F6CBD'
186
+ },
187
+ children: "Choose another environment"
188
+ })
189
+ })]
190
+ });
191
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_PowerAppsExperience.PowerAppsExperienceBoundary, {
192
+ experience: {
193
+ status: 'error',
194
+ error: toExperienceError(error),
195
+ retry: error.retryable ? retryResolution : undefined,
196
+ goBack: onBack
197
+ },
198
+ appDisplayName: target.appDisplayName,
199
+ component: experienceComponent,
200
+ fallback: fallback
201
+ });
202
+ }
203
+ if (!resolvedTarget) {
204
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_PowerAppsExperience.PowerAppsExperienceBoundary, {
205
+ experience: {
206
+ status: 'resolvingApp',
207
+ environment: toEnvironmentSummary(target)
208
+ },
209
+ appDisplayName: target.appDisplayName,
210
+ component: experienceComponent,
211
+ fallback: /*#__PURE__*/(0, _jsxRuntime.jsx)(LoadingScreen, {
212
+ message: "Loading app details..."
213
+ })
214
+ });
215
+ }
216
+ const broker = {
217
+ tenantId: target.tenantId,
218
+ generation,
219
+ acquireGlobalDiscoveryToken: async () => requireToken(await auth.acquireToken([(0, _GlobalDiscovery.globalDiscoveryScope)(target.region)])),
220
+ acquireDataverseToken: async apiUrl => {
221
+ if (!(0, _CanvasAppResolution.areDataverseOriginAliases)(apiUrl, resolvedTarget.dataverseApiUrl)) {
222
+ throw new Error('Dataverse token audience does not match the selected environment');
223
+ }
224
+ return requireToken(await auth.acquireToken([`${(0, _CanvasAppResolution.canonicalizeDataverseOrigin)(apiUrl)}/.default`]));
225
+ },
226
+ acquirePowerPlatformToken: async region => {
227
+ if (region.toLowerCase() !== target.region.toLowerCase()) throw new Error('Power Platform region does not match the selected environment');
228
+ return requireToken(await auth.acquireToken([(0, _PowerPlatformEnvironmentApi.powerPlatformScope)(target.region)]));
229
+ },
230
+ acquireConnectionUserConsentToken: async region => {
231
+ if (region.toLowerCase() !== target.region.toLowerCase()) throw new Error('Power Platform region does not match the selected environment');
232
+ return requireToken(await auth.acquireToken([(0, _PowerPlatformEnvironmentApi.connectionUserConsentScope)(target.region)]));
233
+ },
234
+ acquireApiHubToken: async () => requireToken(await auth.acquireToken(['https://apihub.azure.com/.default']))
235
+ };
236
+ const runtime = children(resolvedTarget, {
237
+ clientId: msalConfig.clientId,
238
+ accountIdentifier: auth.account.identifier,
239
+ accountTenantId: auth.account.tenantId,
240
+ generation,
241
+ tokenBroker: broker,
242
+ signOut: auth.signOut
243
+ });
244
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_PowerAppsExperience.PowerAppsExperienceBoundary, {
245
+ experience: {
246
+ status: 'ready',
247
+ environment: toEnvironmentSummary(resolvedTarget)
248
+ },
249
+ appDisplayName: target.appDisplayName,
250
+ component: experienceComponent,
251
+ fallback: runtime,
252
+ children: runtime
253
+ });
254
+ }
255
+ function requireToken(token) {
256
+ if (!token) throw new Error('Authentication token is unavailable');
257
+ return token;
258
+ }
259
+ function EnvironmentSelector({
260
+ appDisplayName,
261
+ appName,
262
+ tenantPolicy,
263
+ onSelect,
264
+ experienceComponent
265
+ }) {
266
+ const auth = (0, _AuthContext.useAuth)();
267
+ const [environments, setEnvironments] = (0, _react.useState)();
268
+ const [emptyResultReady, setEmptyResultReady] = (0, _react.useState)(false);
269
+ const [error, setError] = (0, _react.useState)();
270
+ const [retry, setRetry] = (0, _react.useState)(0);
271
+ (0, _react.useEffect)(() => {
272
+ if (!auth.account) return;
273
+ const accountIdentifier = auth.account.identifier;
274
+ let active = true;
275
+ let emptyResultTimer;
276
+ setEnvironments(undefined);
277
+ setEmptyResultReady(false);
278
+ setError(undefined);
279
+ if (!(0, _tenantMode.isTenantAllowed)(auth.account.tenantId, tenantPolicy)) {
280
+ setError(new _errors.TargetRuntimeError('tenant-mismatch', 'authentication', false, 'Your organization is not approved to use this app.'));
281
+ return () => {
282
+ active = false;
283
+ };
284
+ }
285
+ void (0, _DataverseGlobalDiscoveryApi.fetchAccessibleEnvironments)(auth.account.tenantId, appDisplayName, appName, auth.acquireToken).then(async discovered => {
286
+ if (!active) return;
287
+ const storedId = await SecureStore.getItemAsync(TARGET_STORAGE_KEY).catch(() => null);
288
+ if (!active) return;
289
+ const restored = discovered.find(environment => environment.id === storedId);
290
+ if (restored) onSelect(restored, accountIdentifier);else {
291
+ if (storedId) void SecureStore.deleteItemAsync(TARGET_STORAGE_KEY);
292
+ setEnvironments(discovered);
293
+ if (discovered.length === 0) {
294
+ emptyResultTimer = setTimeout(() => {
295
+ if (active) setEmptyResultReady(true);
296
+ }, EMPTY_ENVIRONMENT_STABILITY_MS);
297
+ }
298
+ }
299
+ }).catch(cause => {
300
+ if (!active) return;
301
+ setError(cause instanceof _errors.TargetRuntimeError ? cause : new _errors.TargetRuntimeError('discovery-failed', 'discovery', true, 'Your environments could not be loaded. Try again.', undefined, cause));
302
+ });
303
+ return () => {
304
+ active = false;
305
+ if (emptyResultTimer) clearTimeout(emptyResultTimer);
306
+ };
307
+ }, [appDisplayName, appName, auth.account, auth.acquireToken, onSelect, retry, tenantPolicy]);
308
+ if (auth.isLoading || !auth.isAuthReady) {
309
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_PowerAppsExperience.PowerAppsExperienceBoundary, {
310
+ experience: {
311
+ status: 'preparing'
312
+ },
313
+ appDisplayName: appDisplayName,
314
+ component: experienceComponent,
315
+ fallback: /*#__PURE__*/(0, _jsxRuntime.jsx)(LoadingScreen, {
316
+ message: "Preparing your environments..."
317
+ })
318
+ });
319
+ }
320
+ if (!auth.account) {
321
+ const fallback = /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
322
+ style: {
323
+ flex: 1,
324
+ alignItems: 'center',
325
+ justifyContent: 'center',
326
+ gap: 16,
327
+ padding: 24
328
+ },
329
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
330
+ children: auth.error?.message ?? 'Sign in with your work or school account.'
331
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Pressable, {
332
+ accessibilityRole: "button",
333
+ onPress: () => {
334
+ void auth.signIn();
335
+ },
336
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
337
+ style: {
338
+ color: '#0F6CBD',
339
+ fontWeight: '600'
340
+ },
341
+ children: "Sign in"
342
+ })
343
+ })]
344
+ });
345
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_PowerAppsExperience.PowerAppsExperienceBoundary, {
346
+ experience: {
347
+ status: 'signIn',
348
+ error: auth.error?.message,
349
+ signIn: auth.signIn
350
+ },
351
+ appDisplayName: appDisplayName,
352
+ component: experienceComponent,
353
+ fallback: fallback
354
+ });
355
+ }
356
+ if (error) {
357
+ const retryDiscovery = () => setRetry(value => value + 1);
358
+ const fallback = /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
359
+ style: {
360
+ flex: 1,
361
+ alignItems: 'center',
362
+ justifyContent: 'center',
363
+ gap: 16,
364
+ padding: 24
365
+ },
366
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
367
+ style: {
368
+ fontWeight: '700'
369
+ },
370
+ children: "Unable to load environments"
371
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
372
+ children: error.userMessage
373
+ }), error.retryable ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Pressable, {
374
+ accessibilityRole: "button",
375
+ onPress: retryDiscovery,
376
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
377
+ style: {
378
+ color: '#0F6CBD'
379
+ },
380
+ children: "Try again"
381
+ })
382
+ }) : null, /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Pressable, {
383
+ accessibilityRole: "button",
384
+ onPress: () => {
385
+ void auth.signOut();
386
+ },
387
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
388
+ children: "Sign in with another account"
389
+ })
390
+ })]
391
+ });
392
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_PowerAppsExperience.PowerAppsExperienceBoundary, {
393
+ experience: {
394
+ status: 'error',
395
+ error: toExperienceError(error),
396
+ retry: error.retryable ? retryDiscovery : undefined,
397
+ signOut: auth.signOut
398
+ },
399
+ appDisplayName: appDisplayName,
400
+ component: experienceComponent,
401
+ fallback: fallback
402
+ });
403
+ }
404
+ if (!environments || environments.length === 0 && !emptyResultReady) {
405
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_PowerAppsExperience.PowerAppsExperienceBoundary, {
406
+ experience: {
407
+ status: 'discovering'
408
+ },
409
+ appDisplayName: appDisplayName,
410
+ component: experienceComponent,
411
+ fallback: /*#__PURE__*/(0, _jsxRuntime.jsx)(LoadingScreen, {
412
+ message: "Finding your environments..."
413
+ })
414
+ });
415
+ }
416
+ const fallback = /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
417
+ style: {
418
+ flex: 1,
419
+ justifyContent: 'center',
420
+ gap: 12,
421
+ padding: 24
422
+ },
423
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
424
+ style: {
425
+ fontSize: 20,
426
+ fontWeight: '700'
427
+ },
428
+ children: "Choose an environment"
429
+ }), environments.length === 0 ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
430
+ children: "No accessible Dataverse environments were found."
431
+ }) : environments.map(target => /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Pressable, {
432
+ accessibilityRole: "button",
433
+ onPress: () => onSelect(target, auth.account.identifier),
434
+ style: {
435
+ paddingVertical: 12
436
+ },
437
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
438
+ style: {
439
+ color: '#0F6CBD',
440
+ fontWeight: '600'
441
+ },
442
+ children: target.label
443
+ })
444
+ }, target.id)), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Pressable, {
445
+ accessibilityRole: "button",
446
+ onPress: () => {
447
+ void auth.signOut();
448
+ },
449
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
450
+ children: "Sign out"
451
+ })
452
+ })]
453
+ });
454
+ if (environments.length === 0) {
455
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_PowerAppsExperience.PowerAppsExperienceBoundary, {
456
+ experience: {
457
+ status: 'empty',
458
+ retry: () => setRetry(value => value + 1),
459
+ signOut: auth.signOut
460
+ },
461
+ appDisplayName: appDisplayName,
462
+ component: experienceComponent,
463
+ fallback: fallback
464
+ });
465
+ }
466
+ const selectEnvironment = environmentId => {
467
+ const target = environments.find(environment => environment.id === environmentId);
468
+ if (target) onSelect(target, auth.account.identifier);
469
+ };
470
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_PowerAppsExperience.PowerAppsExperienceBoundary, {
471
+ experience: {
472
+ status: 'selectEnvironment',
473
+ environments: environments.map(toEnvironmentSummary),
474
+ selectEnvironment,
475
+ signOut: auth.signOut
476
+ },
477
+ appDisplayName: appDisplayName,
478
+ component: experienceComponent,
479
+ fallback: fallback
480
+ });
481
+ }
482
+ function PowerAppsTargetBootstrap({
483
+ msalConfig,
484
+ appDisplayName,
485
+ appName,
486
+ tenantPolicy,
487
+ experienceComponent,
488
+ children
489
+ }) {
490
+ const ExperienceComponent = experienceComponent ?? _DefaultPowerAppsExperience.DefaultPowerAppsExperience;
491
+ const [selected, setSelected] = (0, _react.useState)();
492
+ const [bootstrapAccountIdentifier, setBootstrapAccountIdentifier] = (0, _react.useState)();
493
+ const generationRef = (0, _react.useRef)(0);
494
+ const [generation, setGeneration] = (0, _react.useState)(0);
495
+ const isCurrentGeneration = (0, _react.useCallback)(value => generationRef.current === value, []);
496
+ const select = (0, _react.useCallback)((target, accountIdentifier) => {
497
+ generationRef.current += 1;
498
+ setGeneration(generationRef.current);
499
+ setSelected(target);
500
+ setBootstrapAccountIdentifier(accountIdentifier);
501
+ if (target) void SecureStore.setItemAsync(TARGET_STORAGE_KEY, target.id);else void SecureStore.deleteItemAsync(TARGET_STORAGE_KEY);
502
+ }, []);
503
+ if (!selected) {
504
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_AuthContext.AuthProvider, {
505
+ msalConfig: msalConfig,
506
+ authorityTenant: _tenantMode.MULTI_TENANT_AUTHORITY,
507
+ requiredScopes: [(0, _GlobalDiscovery.globalDiscoveryScope)('prod')],
508
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(EnvironmentSelector, {
509
+ appDisplayName: appDisplayName,
510
+ appName: appName,
511
+ tenantPolicy: tenantPolicy,
512
+ onSelect: select,
513
+ experienceComponent: ExperienceComponent
514
+ })
515
+ }, `bootstrap:${generation}`);
516
+ }
517
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_AuthContext.AuthProvider, {
518
+ msalConfig: msalConfig,
519
+ authorityTenant: selected.tenantId,
520
+ expectedTenantId: selected.tenantId,
521
+ preferredAccountIdentifier: bootstrapAccountIdentifier,
522
+ autoAuthorizeMissingScopes: true,
523
+ requiredScopes: [`${selected.dataverseApiUrl}/user_impersonation`, (0, _PowerPlatformEnvironmentApi.powerPlatformScope)(selected.region), 'https://apihub.azure.com/.default'],
524
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(TargetRuntime, {
525
+ target: selected,
526
+ generation: generation,
527
+ msalConfig: msalConfig,
528
+ isCurrent: isCurrentGeneration,
529
+ onBack: () => select(undefined),
530
+ experienceComponent: ExperienceComponent,
531
+ children: children
532
+ })
533
+ }, `${selected.id}:${generation}`);
534
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.TargetRuntimeError = void 0;
7
+ class TargetRuntimeError extends Error {
8
+ name = 'TargetRuntimeError';
9
+ constructor(code, stage, retryable, userMessage, targetId, cause) {
10
+ super(userMessage);
11
+ this.code = code;
12
+ this.stage = stage;
13
+ this.retryable = retryable;
14
+ this.userMessage = userMessage;
15
+ this.targetId = targetId;
16
+ Object.defineProperty(this, 'cause', {
17
+ value: cause,
18
+ enumerable: false,
19
+ configurable: false,
20
+ writable: false
21
+ });
22
+ }
23
+ }
24
+ exports.TargetRuntimeError = TargetRuntimeError;
@@ -0,0 +1 @@
1
+ "use strict";
@@ -16,10 +16,10 @@ Object.defineProperty(exports, "getAppLogger", {
16
16
  return _powerAppsNativeCommon.getAppLogger;
17
17
  }
18
18
  });
19
- Object.defineProperty(exports, "getCustomerTelemetryLogger", {
19
+ Object.defineProperty(exports, "getCustomEventsLogger", {
20
20
  enumerable: true,
21
21
  get: function () {
22
- return _powerAppsNativeCommon.getCustomerTelemetryLogger;
22
+ return _powerAppsNativeCommon.getCustomEventsLogger;
23
23
  }
24
24
  });
25
25
  exports.platformHttpClient = void 0;