@ankhorage/expo-runtime 6.0.2 → 6.0.3
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.
- package/CHANGELOG.md +6 -0
- package/README.md +1 -2
- package/dist/capabilityBridge.d.ts +1 -1
- package/dist/capabilityBridge.d.ts.map +1 -1
- package/dist/capabilityBridge.js.map +1 -1
- package/dist/features/capabilities/executeExpoRuntimeCapabilityAsync.d.ts +2 -2
- package/dist/features/capabilities/executeExpoRuntimeCapabilityAsync.d.ts.map +1 -1
- package/dist/features/capabilities/executeExpoRuntimeCapabilityAsync.js +58 -12
- package/dist/features/capabilities/executeExpoRuntimeCapabilityAsync.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/types/expoRuntimeCapability.d.ts +11 -0
- package/dist/types/expoRuntimeCapability.d.ts.map +1 -1
- package/dist/types/expoRuntimeCapability.js.map +1 -1
- package/package.json +1 -1
- package/src/capabilityBridge.ts +3 -0
- package/src/expoCapabilityBridge.test.ts +119 -3
- package/src/features/capabilities/executeExpoRuntimeCapabilityAsync.ts +72 -14
- package/src/index.ts +3 -0
- package/src/types/expoRuntimeCapability.ts +19 -0
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
# EXPO-RUNTIME
|
|
5
5
|
|
|
6
|
-
         
|
|
7
7
|
|
|
8
8
|
Declarative runtime integration for Expo apps: maps app capabilities to permissions, packages, config plugins, providers, and adapters
|
|
9
9
|
|
|
@@ -55,7 +55,6 @@ export function createBasicExpoRuntimePlan() {
|
|
|
55
55
|
- [Module relationships](././paradox/diagrams/module-relationships.mmd)
|
|
56
56
|
- [Export graph](././paradox/diagrams/export-graph.mmd)
|
|
57
57
|
- [createExpoRuntimeRegistry sequence](././paradox/diagrams/sequences/create-expo-runtime-registry.mmd)
|
|
58
|
-
- [executeExpoRuntimeCapabilityAsync sequence](././paradox/diagrams/sequences/execute-expo-runtime-capability-async.mmd)
|
|
59
58
|
- [ExpoBarcodeScannerAdapter sequence](././paradox/diagrams/sequences/expo-barcode-scanner-adapter.mmd)
|
|
60
59
|
- [ExpoZoraIconFontProvider sequence](././paradox/diagrams/sequences/expo-zora-icon-font-provider.mmd)
|
|
61
60
|
- [getExpoBundledMediaRegistrySource sequence](././paradox/diagrams/sequences/get-expo-bundled-media-registry-source.mmd)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { executeExpoRuntimeCapabilityAsync } from './features/capabilities/executeExpoRuntimeCapabilityAsync';
|
|
2
2
|
export { resolveExpoRuntimeRoutePath } from './features/navigation/resolveExpoRuntimeRoutePath';
|
|
3
|
-
export type { ExecuteExpoRuntimeCapabilityArgs, ExpoRuntimeCapabilityHandler, ExpoRuntimeCapabilityHandlerArgs, } from './types/expoRuntimeCapability';
|
|
3
|
+
export type { ExecuteExpoRuntimeCapabilityArgs, ExpoRuntimeCapabilityDiagnostic, ExpoRuntimeCapabilityDiagnosticCode, ExpoRuntimeCapabilityExecutionResult, ExpoRuntimeCapabilityHandler, ExpoRuntimeCapabilityHandlerArgs, } from './types/expoRuntimeCapability';
|
|
4
4
|
export type { ExpoRuntimeRouteResolution } from './types/expoRuntimeRoute';
|
|
5
5
|
//# sourceMappingURL=capabilityBridge.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capabilityBridge.d.ts","sourceRoot":"","sources":["../src/capabilityBridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iCAAiC,EAAE,MAAM,2DAA2D,CAAC;AAC9G,OAAO,EAAE,2BAA2B,EAAE,MAAM,mDAAmD,CAAC;AAChG,YAAY,EACV,gCAAgC,EAChC,4BAA4B,EAC5B,gCAAgC,GACjC,MAAM,+BAA+B,CAAC;AACvC,YAAY,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAC"}
|
|
1
|
+
{"version":3,"file":"capabilityBridge.d.ts","sourceRoot":"","sources":["../src/capabilityBridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iCAAiC,EAAE,MAAM,2DAA2D,CAAC;AAC9G,OAAO,EAAE,2BAA2B,EAAE,MAAM,mDAAmD,CAAC;AAChG,YAAY,EACV,gCAAgC,EAChC,+BAA+B,EAC/B,mCAAmC,EACnC,oCAAoC,EACpC,4BAA4B,EAC5B,gCAAgC,GACjC,MAAM,+BAA+B,CAAC;AACvC,YAAY,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capabilityBridge.js","sourceRoot":"","sources":["../src/capabilityBridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iCAAiC,EAAE,MAAM,2DAA2D,CAAC;AAC9G,OAAO,EAAE,2BAA2B,EAAE,MAAM,mDAAmD,CAAC","sourcesContent":["export { executeExpoRuntimeCapabilityAsync } from './features/capabilities/executeExpoRuntimeCapabilityAsync';\nexport { resolveExpoRuntimeRoutePath } from './features/navigation/resolveExpoRuntimeRoutePath';\nexport type {\n ExecuteExpoRuntimeCapabilityArgs,\n ExpoRuntimeCapabilityHandler,\n ExpoRuntimeCapabilityHandlerArgs,\n} from './types/expoRuntimeCapability';\nexport type { ExpoRuntimeRouteResolution } from './types/expoRuntimeRoute';\n"]}
|
|
1
|
+
{"version":3,"file":"capabilityBridge.js","sourceRoot":"","sources":["../src/capabilityBridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iCAAiC,EAAE,MAAM,2DAA2D,CAAC;AAC9G,OAAO,EAAE,2BAA2B,EAAE,MAAM,mDAAmD,CAAC","sourcesContent":["export { executeExpoRuntimeCapabilityAsync } from './features/capabilities/executeExpoRuntimeCapabilityAsync';\nexport { resolveExpoRuntimeRoutePath } from './features/navigation/resolveExpoRuntimeRoutePath';\nexport type {\n ExecuteExpoRuntimeCapabilityArgs,\n ExpoRuntimeCapabilityDiagnostic,\n ExpoRuntimeCapabilityDiagnosticCode,\n ExpoRuntimeCapabilityExecutionResult,\n ExpoRuntimeCapabilityHandler,\n ExpoRuntimeCapabilityHandlerArgs,\n} from './types/expoRuntimeCapability';\nexport type { ExpoRuntimeRouteResolution } from './types/expoRuntimeRoute';\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ExecuteExpoRuntimeCapabilityArgs } from '../../types/expoRuntimeCapability';
|
|
1
|
+
import type { ExecuteExpoRuntimeCapabilityArgs, ExpoRuntimeCapabilityExecutionResult } from '../../types/expoRuntimeCapability';
|
|
2
2
|
/*** Execute an Expo-owned capability or delegate another canonical capability to its runtime handler. */
|
|
3
|
-
export declare function executeExpoRuntimeCapabilityAsync(args: ExecuteExpoRuntimeCapabilityArgs): Promise<
|
|
3
|
+
export declare function executeExpoRuntimeCapabilityAsync(args: ExecuteExpoRuntimeCapabilityArgs): Promise<ExpoRuntimeCapabilityExecutionResult>;
|
|
4
4
|
//# sourceMappingURL=executeExpoRuntimeCapabilityAsync.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executeExpoRuntimeCapabilityAsync.d.ts","sourceRoot":"","sources":["../../../src/features/capabilities/executeExpoRuntimeCapabilityAsync.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,gCAAgC,
|
|
1
|
+
{"version":3,"file":"executeExpoRuntimeCapabilityAsync.d.ts","sourceRoot":"","sources":["../../../src/features/capabilities/executeExpoRuntimeCapabilityAsync.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,gCAAgC,EAEhC,oCAAoC,EAGrC,MAAM,mCAAmC,CAAC;AAE3C,yGAAyG;AACzG,wBAAsB,iCAAiC,CACrD,IAAI,EAAE,gCAAgC,GACrC,OAAO,CAAC,oCAAoC,CAAC,CAqB/C"}
|
|
@@ -2,13 +2,36 @@ import { isCapability } from '@ankhorage/capability';
|
|
|
2
2
|
/*** Execute an Expo-owned capability or delegate another canonical capability to its runtime handler. */
|
|
3
3
|
export async function executeExpoRuntimeCapabilityAsync(args) {
|
|
4
4
|
const { capability, input, capabilityHandlers, alertImpl } = args;
|
|
5
|
-
if (!isCapability(capability))
|
|
6
|
-
return
|
|
5
|
+
if (!isCapability(capability)) {
|
|
6
|
+
return rejectCapabilityExecution({
|
|
7
|
+
code: 'invalid-capability-descriptor',
|
|
8
|
+
message: 'The capability descriptor is invalid.',
|
|
9
|
+
});
|
|
10
|
+
}
|
|
7
11
|
if (capability.id === 'expo.alert') {
|
|
8
|
-
executeExpoAlert(input, alertImpl);
|
|
9
|
-
|
|
12
|
+
return executeExpoAlert(input, alertImpl);
|
|
13
|
+
}
|
|
14
|
+
const handler = findCapabilityHandler(capabilityHandlers, capability.id);
|
|
15
|
+
if (!handler) {
|
|
16
|
+
return rejectCapabilityExecution({
|
|
17
|
+
code: 'missing-capability-handler',
|
|
18
|
+
message: `No Expo Runtime capability handler is configured for '${capability.id}'.`,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return executeForeignCapabilityHandlerAsync(handler, capability, input);
|
|
22
|
+
}
|
|
23
|
+
/*** Execute a foreign capability handler and translate its failure into the bridge result contract. */
|
|
24
|
+
async function executeForeignCapabilityHandlerAsync(handler, capability, input) {
|
|
25
|
+
try {
|
|
26
|
+
await handler({ capability, input });
|
|
27
|
+
return { ok: true };
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
return rejectCapabilityExecution({
|
|
31
|
+
code: 'capability-handler-failed',
|
|
32
|
+
message: `The handler for '${capability.id}' failed: ${getFailureMessage(error)}`,
|
|
33
|
+
});
|
|
10
34
|
}
|
|
11
|
-
await findCapabilityHandler(capabilityHandlers, capability.id)?.({ capability, input });
|
|
12
35
|
}
|
|
13
36
|
/*** Find the configured executor for one canonical capability without dynamic record access. */
|
|
14
37
|
function findCapabilityHandler(capabilityHandlers, capabilityId) {
|
|
@@ -16,15 +39,38 @@ function findCapabilityHandler(capabilityHandlers, capabilityId) {
|
|
|
16
39
|
}
|
|
17
40
|
/*** Display a valid Expo-owned alert invocation without exposing alert as a generic action. */
|
|
18
41
|
function executeExpoAlert(input, alertImpl) {
|
|
19
|
-
if (!isExpoAlertInput(input))
|
|
20
|
-
return
|
|
21
|
-
|
|
42
|
+
if (!isExpoAlertInput(input)) {
|
|
43
|
+
return rejectCapabilityExecution({
|
|
44
|
+
code: 'invalid-expo-alert-input',
|
|
45
|
+
message: "The 'expo.alert' capability requires an input object with only a string 'message'.",
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
if (!alertImpl) {
|
|
49
|
+
return rejectCapabilityExecution({
|
|
50
|
+
code: 'missing-expo-alert-handler',
|
|
51
|
+
message: "No Expo alert host callback is configured for 'expo.alert'.",
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
alertImpl(input.message);
|
|
55
|
+
return { ok: true };
|
|
22
56
|
}
|
|
23
57
|
/*** Validate the serializable input accepted by the Expo alert capability. */
|
|
24
58
|
function isExpoAlertInput(input) {
|
|
25
|
-
|
|
26
|
-
input
|
|
27
|
-
|
|
28
|
-
|
|
59
|
+
if (typeof input !== 'object' ||
|
|
60
|
+
input === null ||
|
|
61
|
+
Array.isArray(input) ||
|
|
62
|
+
!('message' in input)) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
const entries = Object.entries(input);
|
|
66
|
+
return entries.length === 1 && typeof input.message === 'string';
|
|
67
|
+
}
|
|
68
|
+
/*** Report a rejected capability invocation with a diagnostic that a runtime owner can surface. */
|
|
69
|
+
function rejectCapabilityExecution(diagnostic) {
|
|
70
|
+
return { ok: false, diagnostics: [diagnostic] };
|
|
71
|
+
}
|
|
72
|
+
/*** Convert any foreign handler failure into a diagnostic-safe message. */
|
|
73
|
+
function getFailureMessage(error) {
|
|
74
|
+
return error instanceof Error ? error.message : String(error);
|
|
29
75
|
}
|
|
30
76
|
//# sourceMappingURL=executeExpoRuntimeCapabilityAsync.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executeExpoRuntimeCapabilityAsync.js","sourceRoot":"","sources":["../../../src/features/capabilities/executeExpoRuntimeCapabilityAsync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"executeExpoRuntimeCapabilityAsync.js","sourceRoot":"","sources":["../../../src/features/capabilities/executeExpoRuntimeCapabilityAsync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAWrD,yGAAyG;AACzG,MAAM,CAAC,KAAK,UAAU,iCAAiC,CACrD,IAAsC;IAEtC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,kBAAkB,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;IAClE,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,EAAE,CAAC;QAC9B,OAAO,yBAAyB,CAAC;YAC/B,IAAI,EAAE,+BAA+B;YACrC,OAAO,EAAE,uCAAuC;SACjD,CAAC,CAAC;IACL,CAAC;IAED,IAAI,UAAU,CAAC,EAAE,KAAK,YAAY,EAAE,CAAC;QACnC,OAAO,gBAAgB,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IAC5C,CAAC;IAED,MAAM,OAAO,GAAG,qBAAqB,CAAC,kBAAkB,EAAE,UAAU,CAAC,EAAE,CAAC,CAAC;IACzE,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,yBAAyB,CAAC;YAC/B,IAAI,EAAE,4BAA4B;YAClC,OAAO,EAAE,yDAAyD,UAAU,CAAC,EAAE,IAAI;SACpF,CAAC,CAAC;IACL,CAAC;IACD,OAAO,oCAAoC,CAAC,OAAO,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC;AAC1E,CAAC;AAED,uGAAuG;AACvG,KAAK,UAAU,oCAAoC,CACjD,OAAyE,EACzE,UAAsB,EACtB,KAAc;IAEd,IAAI,CAAC;QACH,MAAM,OAAO,CAAC,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OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACtC,OAAO,OAAO,CAAC,MAAM,KAAK,CAAC,IAAI,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ,CAAC;AACnE,CAAC;AAED,mGAAmG;AACnG,SAAS,yBAAyB,CAChC,UAA2C;IAE3C,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC;AAClD,CAAC;AAED,2EAA2E;AAC3E,SAAS,iBAAiB,CAAC,KAAc;IACvC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAChE,CAAC","sourcesContent":["import { isCapability } from '@ankhorage/capability';\nimport type { Capability } from '@ankhorage/contracts/capability';\n\nimport type {\n ExecuteExpoRuntimeCapabilityArgs,\n ExpoRuntimeCapabilityDiagnostic,\n ExpoRuntimeCapabilityExecutionResult,\n ExpoRuntimeCapabilityHandler,\n ExpoRuntimeCapabilityHandlerArgs,\n} from '../../types/expoRuntimeCapability';\n\n/*** Execute an Expo-owned capability or delegate another canonical capability to its runtime handler. */\nexport async function executeExpoRuntimeCapabilityAsync(\n args: ExecuteExpoRuntimeCapabilityArgs,\n): Promise<ExpoRuntimeCapabilityExecutionResult> {\n const { capability, input, capabilityHandlers, alertImpl } = args;\n if (!isCapability(capability)) {\n return rejectCapabilityExecution({\n code: 'invalid-capability-descriptor',\n message: 'The capability descriptor is invalid.',\n });\n }\n\n if (capability.id === 'expo.alert') {\n return executeExpoAlert(input, alertImpl);\n }\n\n const handler = findCapabilityHandler(capabilityHandlers, capability.id);\n if (!handler) {\n return rejectCapabilityExecution({\n code: 'missing-capability-handler',\n message: `No Expo Runtime capability handler is configured for '${capability.id}'.`,\n });\n }\n return executeForeignCapabilityHandlerAsync(handler, capability, input);\n}\n\n/*** Execute a foreign capability handler and translate its failure into the bridge result contract. */\nasync function executeForeignCapabilityHandlerAsync(\n handler: (args: ExpoRuntimeCapabilityHandlerArgs) => Promise<void> | void,\n capability: Capability,\n input: unknown,\n): Promise<ExpoRuntimeCapabilityExecutionResult> {\n try {\n await handler({ capability, input });\n return { ok: true };\n } catch (error) {\n return rejectCapabilityExecution({\n code: 'capability-handler-failed',\n message: `The handler for '${capability.id}' failed: ${getFailureMessage(error)}`,\n });\n }\n}\n\n/*** Find the configured executor for one canonical capability without dynamic record access. */\nfunction findCapabilityHandler(\n capabilityHandlers: readonly ExpoRuntimeCapabilityHandler[] | undefined,\n capabilityId: Capability['id'],\n): ((args: ExpoRuntimeCapabilityHandlerArgs) => Promise<void> | void) | undefined {\n return capabilityHandlers?.find((handler) => handler.capabilityId === capabilityId)?.execute;\n}\n\n/*** Display a valid Expo-owned alert invocation without exposing alert as a generic action. */\nfunction executeExpoAlert(\n input: unknown,\n alertImpl: ((message: string) => void) | undefined,\n): ExpoRuntimeCapabilityExecutionResult {\n if (!isExpoAlertInput(input)) {\n return rejectCapabilityExecution({\n code: 'invalid-expo-alert-input',\n message: \"The 'expo.alert' capability requires an input object with only a string 'message'.\",\n });\n }\n if (!alertImpl) {\n return rejectCapabilityExecution({\n code: 'missing-expo-alert-handler',\n message: \"No Expo alert host callback is configured for 'expo.alert'.\",\n });\n }\n alertImpl(input.message);\n return { ok: true };\n}\n\n/*** Validate the serializable input accepted by the Expo alert capability. */\nfunction isExpoAlertInput(input: unknown): input is { readonly message: string } {\n if (\n typeof input !== 'object' ||\n input === null ||\n Array.isArray(input) ||\n !('message' in input)\n ) {\n return false;\n }\n const entries = Object.entries(input);\n return entries.length === 1 && typeof input.message === 'string';\n}\n\n/*** Report a rejected capability invocation with a diagnostic that a runtime owner can surface. */\nfunction rejectCapabilityExecution(\n diagnostic: ExpoRuntimeCapabilityDiagnostic,\n): ExpoRuntimeCapabilityExecutionResult {\n return { ok: false, diagnostics: [diagnostic] };\n}\n\n/*** Convert any foreign handler failure into a diagnostic-safe message. */\nfunction getFailureMessage(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { BARCODE_SCAN_DEDUPE_WINDOW_MS, BARCODE_SCANNER_TYPES, type BarcodeScanRecord, type ExpoBarcodeScanResultLike, mapPermissionStatusToCameraPermissionStatus, normalizeExpoBarcodeScanResult, shouldIgnoreBarcodeScan, } from './barcodeScanRuntime';
|
|
2
2
|
export { type ExpoBundledMediaRegistrySourceEntry, getExpoBundledMediaRegistrySource, } from './bundledMediaRegistrySource';
|
|
3
3
|
export { createExpoBundledMediaResolver, type ExpoBundledMediaRegistry, type ExpoBundledMediaResolver, type ExpoBundledMediaResolverArgs, type ExpoBundledMediaValue, resolveExpoBundledMediaAsset, } from './bundledMediaResolver';
|
|
4
|
-
export { type ExecuteExpoRuntimeCapabilityArgs, executeExpoRuntimeCapabilityAsync, type ExpoRuntimeCapabilityHandler, type ExpoRuntimeCapabilityHandlerArgs, type ExpoRuntimeRouteResolution, resolveExpoRuntimeRoutePath, } from './capabilityBridge';
|
|
4
|
+
export { type ExecuteExpoRuntimeCapabilityArgs, executeExpoRuntimeCapabilityAsync, type ExpoRuntimeCapabilityDiagnostic, type ExpoRuntimeCapabilityDiagnosticCode, type ExpoRuntimeCapabilityExecutionResult, type ExpoRuntimeCapabilityHandler, type ExpoRuntimeCapabilityHandlerArgs, type ExpoRuntimeRouteResolution, resolveExpoRuntimeRoutePath, } from './capabilityBridge';
|
|
5
5
|
export type { ComponentRegistry } from './componentRegistry';
|
|
6
6
|
export { createComponentRegistry } from './componentRegistry';
|
|
7
7
|
export { createExpoRuntimeRegistry } from './createExpoRuntimeRegistry';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,6BAA6B,EAC7B,qBAAqB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pC,8BAA8B,GAC/B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,+BAA+B,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,EACL,KAAK,gCAAgC,EACrC,mCAAmC,GACpC,MAAM,6BAA6B,CAAC;AACrC,YAAY,EACV,oBAAoB,EACpB,eAAe,EACf,qBAAqB,GACtB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,6BAA6B,EAC7B,qBAAqB,EAGrB,2CAA2C,EAC3C,8BAA8B,EAC9B,uBAAuB,GACxB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAEL,iCAAiC,GAClC,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,8BAA8B,EAK9B,4BAA4B,GAC7B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAEL,iCAAiC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,6BAA6B,EAC7B,qBAAqB,EAGrB,2CAA2C,EAC3C,8BAA8B,EAC9B,uBAAuB,GACxB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAEL,iCAAiC,GAClC,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,8BAA8B,EAK9B,4BAA4B,GAC7B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAEL,iCAAiC,EAOjC,2BAA2B,GAC5B,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAkC,MAAM,wBAAwB,CAAC;AAC9F,OAAO,EACL,wBAAwB,GAEzB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAKL,oCAAoC,EACpC,+BAA+B,EAC/B,oCAAoC,EACpC,8BAA8B,GAC/B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,+BAA+B,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,EAEL,mCAAmC,GACpC,MAAM,6BAA6B,CAAC;AAMrC,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC","sourcesContent":["export {\n BARCODE_SCAN_DEDUPE_WINDOW_MS,\n BARCODE_SCANNER_TYPES,\n type BarcodeScanRecord,\n type ExpoBarcodeScanResultLike,\n mapPermissionStatusToCameraPermissionStatus,\n normalizeExpoBarcodeScanResult,\n shouldIgnoreBarcodeScan,\n} from './barcodeScanRuntime';\nexport {\n type ExpoBundledMediaRegistrySourceEntry,\n getExpoBundledMediaRegistrySource,\n} from './bundledMediaRegistrySource';\nexport {\n createExpoBundledMediaResolver,\n type ExpoBundledMediaRegistry,\n type ExpoBundledMediaResolver,\n type ExpoBundledMediaResolverArgs,\n type ExpoBundledMediaValue,\n resolveExpoBundledMediaAsset,\n} from './bundledMediaResolver';\nexport {\n type ExecuteExpoRuntimeCapabilityArgs,\n executeExpoRuntimeCapabilityAsync,\n type ExpoRuntimeCapabilityDiagnostic,\n type ExpoRuntimeCapabilityDiagnosticCode,\n type ExpoRuntimeCapabilityExecutionResult,\n type ExpoRuntimeCapabilityHandler,\n type ExpoRuntimeCapabilityHandlerArgs,\n type ExpoRuntimeRouteResolution,\n resolveExpoRuntimeRoutePath,\n} from './capabilityBridge';\nexport type { ComponentRegistry } from './componentRegistry';\nexport { createComponentRegistry } from './componentRegistry';\nexport { createExpoRuntimeRegistry } from './createExpoRuntimeRegistry';\nexport { ExpoBarcodeScannerAdapter } from './ExpoBarcodeScannerAdapter';\nexport { ExpoRuntimeProviders, type ExpoRuntimeProvidersProps } from './ExpoRuntimeProviders';\nexport {\n ExpoZoraIconFontProvider,\n type ExpoZoraIconFontProviderProps,\n} from './ExpoZoraIconFontProvider';\nexport {\n type ExpoRuntimeConfigPluginOutput,\n type ExpoRuntimeDependencyMap,\n type ExpoRuntimeGeneratedAppOutputPlan,\n type ExpoRuntimeNativeOutputPlan,\n resolveExpoRuntimeConfigPluginOutput,\n resolveExpoRuntimeDependencyMap,\n resolveExpoRuntimeGeneratedAppOutput,\n resolveExpoRuntimeNativeOutput,\n} from './generatedAppOutput';\nexport { getExpoBarcodeScannerViewSource } from './generatedSources';\nexport {\n type ExpoRuntimeLayoutIntegrationPlan,\n resolveExpoRuntimeLayoutIntegration,\n} from './layoutIntegrationPlanning';\nexport type {\n ExpoRuntimeAdapterId,\n ExpoRuntimePlan,\n ExpoRuntimeProviderId,\n} from './resolveExpoRuntimePlan';\nexport { resolveExpoRuntimePlan } from './resolveExpoRuntimePlan';\n"]}
|
|
@@ -7,6 +7,17 @@ export interface ExpoRuntimeCapabilityHandler {
|
|
|
7
7
|
readonly capabilityId: Capability['id'];
|
|
8
8
|
readonly execute: (args: ExpoRuntimeCapabilityHandlerArgs) => Promise<void> | void;
|
|
9
9
|
}
|
|
10
|
+
export type ExpoRuntimeCapabilityDiagnosticCode = 'invalid-capability-descriptor' | 'invalid-expo-alert-input' | 'capability-handler-failed' | 'missing-capability-handler' | 'missing-expo-alert-handler';
|
|
11
|
+
export interface ExpoRuntimeCapabilityDiagnostic {
|
|
12
|
+
readonly code: ExpoRuntimeCapabilityDiagnosticCode;
|
|
13
|
+
readonly message: string;
|
|
14
|
+
}
|
|
15
|
+
export type ExpoRuntimeCapabilityExecutionResult = {
|
|
16
|
+
readonly ok: true;
|
|
17
|
+
} | {
|
|
18
|
+
readonly ok: false;
|
|
19
|
+
readonly diagnostics: readonly ExpoRuntimeCapabilityDiagnostic[];
|
|
20
|
+
};
|
|
10
21
|
export interface ExecuteExpoRuntimeCapabilityArgs {
|
|
11
22
|
readonly capability: unknown;
|
|
12
23
|
readonly input?: unknown;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expoRuntimeCapability.d.ts","sourceRoot":"","sources":["../../src/types/expoRuntimeCapability.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAElE,MAAM,WAAW,gCAAgC;IAC/C,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB;AAED,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,CAAC,YAAY,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;IACxC,QAAQ,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,gCAAgC,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CACpF;AAED,MAAM,WAAW,gCAAgC;IAC/C,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,kBAAkB,CAAC,EAAE,SAAS,4BAA4B,EAAE,CAAC;IACtE,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CAChD"}
|
|
1
|
+
{"version":3,"file":"expoRuntimeCapability.d.ts","sourceRoot":"","sources":["../../src/types/expoRuntimeCapability.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAElE,MAAM,WAAW,gCAAgC;IAC/C,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB;AAED,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,CAAC,YAAY,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;IACxC,QAAQ,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,gCAAgC,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CACpF;AAED,MAAM,MAAM,mCAAmC,GAC3C,+BAA+B,GAC/B,0BAA0B,GAC1B,2BAA2B,GAC3B,4BAA4B,GAC5B,4BAA4B,CAAC;AAEjC,MAAM,WAAW,+BAA+B;IAC9C,QAAQ,CAAC,IAAI,EAAE,mCAAmC,CAAC;IACnD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,MAAM,oCAAoC,GAC5C;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAA;CAAE,GACrB;IACE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IACnB,QAAQ,CAAC,WAAW,EAAE,SAAS,+BAA+B,EAAE,CAAC;CAClE,CAAC;AAEN,MAAM,WAAW,gCAAgC;IAC/C,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,kBAAkB,CAAC,EAAE,SAAS,4BAA4B,EAAE,CAAC;IACtE,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CAChD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expoRuntimeCapability.js","sourceRoot":"","sources":["../../src/types/expoRuntimeCapability.ts"],"names":[],"mappings":"","sourcesContent":["import type { Capability } from '@ankhorage/contracts/capability';\n\nexport interface ExpoRuntimeCapabilityHandlerArgs {\n readonly capability: Capability;\n readonly input: unknown;\n}\n\nexport interface ExpoRuntimeCapabilityHandler {\n readonly capabilityId: Capability['id'];\n readonly execute: (args: ExpoRuntimeCapabilityHandlerArgs) => Promise<void> | void;\n}\n\nexport interface ExecuteExpoRuntimeCapabilityArgs {\n readonly capability: unknown;\n readonly input?: unknown;\n readonly capabilityHandlers?: readonly ExpoRuntimeCapabilityHandler[];\n readonly alertImpl?: (message: string) => void;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"expoRuntimeCapability.js","sourceRoot":"","sources":["../../src/types/expoRuntimeCapability.ts"],"names":[],"mappings":"","sourcesContent":["import type { Capability } from '@ankhorage/contracts/capability';\n\nexport interface ExpoRuntimeCapabilityHandlerArgs {\n readonly capability: Capability;\n readonly input: unknown;\n}\n\nexport interface ExpoRuntimeCapabilityHandler {\n readonly capabilityId: Capability['id'];\n readonly execute: (args: ExpoRuntimeCapabilityHandlerArgs) => Promise<void> | void;\n}\n\nexport type ExpoRuntimeCapabilityDiagnosticCode =\n | 'invalid-capability-descriptor'\n | 'invalid-expo-alert-input'\n | 'capability-handler-failed'\n | 'missing-capability-handler'\n | 'missing-expo-alert-handler';\n\nexport interface ExpoRuntimeCapabilityDiagnostic {\n readonly code: ExpoRuntimeCapabilityDiagnosticCode;\n readonly message: string;\n}\n\nexport type ExpoRuntimeCapabilityExecutionResult =\n | { readonly ok: true }\n | {\n readonly ok: false;\n readonly diagnostics: readonly ExpoRuntimeCapabilityDiagnostic[];\n };\n\nexport interface ExecuteExpoRuntimeCapabilityArgs {\n readonly capability: unknown;\n readonly input?: unknown;\n readonly capabilityHandlers?: readonly ExpoRuntimeCapabilityHandler[];\n readonly alertImpl?: (message: string) => void;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ankhorage/expo-runtime",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "6.0.
|
|
4
|
+
"version": "6.0.3",
|
|
5
5
|
"description": "Declarative runtime integration for Expo apps: maps app capabilities to permissions, packages, config plugins, providers, and adapters",
|
|
6
6
|
"homepage": "https://github.com/ankhorage/expo-runtime#readme",
|
|
7
7
|
"bugs": {
|
package/src/capabilityBridge.ts
CHANGED
|
@@ -2,6 +2,9 @@ export { executeExpoRuntimeCapabilityAsync } from './features/capabilities/execu
|
|
|
2
2
|
export { resolveExpoRuntimeRoutePath } from './features/navigation/resolveExpoRuntimeRoutePath';
|
|
3
3
|
export type {
|
|
4
4
|
ExecuteExpoRuntimeCapabilityArgs,
|
|
5
|
+
ExpoRuntimeCapabilityDiagnostic,
|
|
6
|
+
ExpoRuntimeCapabilityDiagnosticCode,
|
|
7
|
+
ExpoRuntimeCapabilityExecutionResult,
|
|
5
8
|
ExpoRuntimeCapabilityHandler,
|
|
6
9
|
ExpoRuntimeCapabilityHandlerArgs,
|
|
7
10
|
} from './types/expoRuntimeCapability';
|
|
@@ -4,7 +4,7 @@ import { describe, expect, test } from 'bun:test';
|
|
|
4
4
|
import { CAPABILITIES } from './capabilities';
|
|
5
5
|
import { executeExpoRuntimeCapabilityAsync, resolveExpoRuntimeRoutePath } from './capabilityBridge';
|
|
6
6
|
|
|
7
|
-
describe('expoCapabilityBridge', () => {
|
|
7
|
+
describe('expoCapabilityBridge Expo-owned capabilities', () => {
|
|
8
8
|
test('resolves dynamic route params and keeps unused params', () => {
|
|
9
9
|
expect(resolveExpoRuntimeRoutePath('/users/[id]', { id: 42, tab: 'profile' })).toEqual({
|
|
10
10
|
resolvedPath: '/users/42',
|
|
@@ -17,15 +17,74 @@ describe('expoCapabilityBridge', () => {
|
|
|
17
17
|
|
|
18
18
|
const expoAlertCapability = findCapabilityById('expo.alert');
|
|
19
19
|
|
|
20
|
-
await executeExpoRuntimeCapabilityAsync({
|
|
20
|
+
const result = await executeExpoRuntimeCapabilityAsync({
|
|
21
21
|
capability: expoAlertCapability,
|
|
22
22
|
input: { message: 'Saved' },
|
|
23
23
|
alertImpl: (message) => messages.push(message),
|
|
24
24
|
});
|
|
25
25
|
|
|
26
|
+
expect(result).toEqual({ ok: true });
|
|
26
27
|
expect(messages).toEqual(['Saved']);
|
|
27
28
|
});
|
|
28
29
|
|
|
30
|
+
test('rejects malformed Expo alert input without invoking the host callback', async () => {
|
|
31
|
+
const messages: string[] = [];
|
|
32
|
+
|
|
33
|
+
const result = await executeExpoRuntimeCapabilityAsync({
|
|
34
|
+
capability: findCapabilityById('expo.alert'),
|
|
35
|
+
input: { message: 42 },
|
|
36
|
+
alertImpl: (message) => messages.push(message),
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
expect(result).toEqual({
|
|
40
|
+
ok: false,
|
|
41
|
+
diagnostics: [
|
|
42
|
+
{
|
|
43
|
+
code: 'invalid-expo-alert-input',
|
|
44
|
+
message:
|
|
45
|
+
"The 'expo.alert' capability requires an input object with only a string 'message'.",
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
});
|
|
49
|
+
expect(messages).toEqual([]);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
describe('expoCapabilityBridge rejected Expo-owned capabilities', () => {
|
|
53
|
+
test('rejects a valid Expo alert invocation when no alert host is configured', async () => {
|
|
54
|
+
const result = await executeExpoRuntimeCapabilityAsync({
|
|
55
|
+
capability: findCapabilityById('expo.alert'),
|
|
56
|
+
input: { message: 'Saved' },
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
expect(result).toEqual({
|
|
60
|
+
ok: false,
|
|
61
|
+
diagnostics: [
|
|
62
|
+
{
|
|
63
|
+
code: 'missing-expo-alert-handler',
|
|
64
|
+
message: "No Expo alert host callback is configured for 'expo.alert'.",
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('rejects an invalid capability descriptor', async () => {
|
|
71
|
+
const result = await executeExpoRuntimeCapabilityAsync({
|
|
72
|
+
capability: { id: 'expo.alert' },
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
expect(result).toEqual({
|
|
76
|
+
ok: false,
|
|
77
|
+
diagnostics: [
|
|
78
|
+
{
|
|
79
|
+
code: 'invalid-capability-descriptor',
|
|
80
|
+
message: 'The capability descriptor is invalid.',
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
describe('expoCapabilityBridge foreign capabilities', () => {
|
|
29
88
|
test('delegates foreign canonical capabilities to their configured runtime handler', async () => {
|
|
30
89
|
const calls: string[] = [];
|
|
31
90
|
const capability = {
|
|
@@ -35,7 +94,7 @@ describe('expoCapabilityBridge', () => {
|
|
|
35
94
|
binding: { kind: 'action', bindableAs: ['target'] },
|
|
36
95
|
} as const;
|
|
37
96
|
|
|
38
|
-
await executeExpoRuntimeCapabilityAsync({
|
|
97
|
+
const result = await executeExpoRuntimeCapabilityAsync({
|
|
39
98
|
capability,
|
|
40
99
|
input: { route: 'users/[id]', params: { id: 42 } },
|
|
41
100
|
capabilityHandlers: [
|
|
@@ -46,8 +105,65 @@ describe('expoCapabilityBridge', () => {
|
|
|
46
105
|
],
|
|
47
106
|
});
|
|
48
107
|
|
|
108
|
+
expect(result).toEqual({ ok: true });
|
|
49
109
|
expect(calls).toEqual(['navigator.navigate']);
|
|
50
110
|
});
|
|
111
|
+
|
|
112
|
+
test('rejects a foreign canonical capability without a configured runtime handler', async () => {
|
|
113
|
+
const result = await executeExpoRuntimeCapabilityAsync({
|
|
114
|
+
capability: {
|
|
115
|
+
id: 'theme.setMode',
|
|
116
|
+
owner: '@ankhorage/surface',
|
|
117
|
+
access: ['invoke'],
|
|
118
|
+
binding: { kind: 'action', bindableAs: ['target'] },
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
expect(result).toEqual({
|
|
123
|
+
ok: false,
|
|
124
|
+
diagnostics: [
|
|
125
|
+
{
|
|
126
|
+
code: 'missing-capability-handler',
|
|
127
|
+
message: "No Expo Runtime capability handler is configured for 'theme.setMode'.",
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
describe('expoCapabilityBridge failed foreign capability handlers', () => {
|
|
134
|
+
test('rejects synchronous and asynchronous foreign handler failures', async () => {
|
|
135
|
+
const capability = {
|
|
136
|
+
id: 'navigator.navigate',
|
|
137
|
+
owner: '@ankhorage/navigator',
|
|
138
|
+
access: ['invoke'],
|
|
139
|
+
binding: { kind: 'action', bindableAs: ['target'] },
|
|
140
|
+
} as const;
|
|
141
|
+
const failures = [
|
|
142
|
+
() => {
|
|
143
|
+
throw new Error('synchronous failure');
|
|
144
|
+
},
|
|
145
|
+
() => Promise.reject(new Error('asynchronous failure')),
|
|
146
|
+
];
|
|
147
|
+
|
|
148
|
+
for (const execute of failures) {
|
|
149
|
+
const result = await executeExpoRuntimeCapabilityAsync({
|
|
150
|
+
capability,
|
|
151
|
+
capabilityHandlers: [{ capabilityId: 'navigator.navigate', execute }],
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
expect(result).toEqual({
|
|
155
|
+
ok: false,
|
|
156
|
+
diagnostics: [
|
|
157
|
+
{
|
|
158
|
+
code: 'capability-handler-failed',
|
|
159
|
+
message: `The handler for 'navigator.navigate' failed: ${
|
|
160
|
+
execute === failures[0] ? 'synchronous failure' : 'asynchronous failure'
|
|
161
|
+
}`,
|
|
162
|
+
},
|
|
163
|
+
],
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
});
|
|
51
167
|
});
|
|
52
168
|
|
|
53
169
|
function findCapabilityById(capabilityId: string): Capability {
|
|
@@ -3,6 +3,8 @@ import type { Capability } from '@ankhorage/contracts/capability';
|
|
|
3
3
|
|
|
4
4
|
import type {
|
|
5
5
|
ExecuteExpoRuntimeCapabilityArgs,
|
|
6
|
+
ExpoRuntimeCapabilityDiagnostic,
|
|
7
|
+
ExpoRuntimeCapabilityExecutionResult,
|
|
6
8
|
ExpoRuntimeCapabilityHandler,
|
|
7
9
|
ExpoRuntimeCapabilityHandlerArgs,
|
|
8
10
|
} from '../../types/expoRuntimeCapability';
|
|
@@ -10,16 +12,44 @@ import type {
|
|
|
10
12
|
/*** Execute an Expo-owned capability or delegate another canonical capability to its runtime handler. */
|
|
11
13
|
export async function executeExpoRuntimeCapabilityAsync(
|
|
12
14
|
args: ExecuteExpoRuntimeCapabilityArgs,
|
|
13
|
-
): Promise<
|
|
15
|
+
): Promise<ExpoRuntimeCapabilityExecutionResult> {
|
|
14
16
|
const { capability, input, capabilityHandlers, alertImpl } = args;
|
|
15
|
-
if (!isCapability(capability))
|
|
17
|
+
if (!isCapability(capability)) {
|
|
18
|
+
return rejectCapabilityExecution({
|
|
19
|
+
code: 'invalid-capability-descriptor',
|
|
20
|
+
message: 'The capability descriptor is invalid.',
|
|
21
|
+
});
|
|
22
|
+
}
|
|
16
23
|
|
|
17
24
|
if (capability.id === 'expo.alert') {
|
|
18
|
-
executeExpoAlert(input, alertImpl);
|
|
19
|
-
return;
|
|
25
|
+
return executeExpoAlert(input, alertImpl);
|
|
20
26
|
}
|
|
21
27
|
|
|
22
|
-
|
|
28
|
+
const handler = findCapabilityHandler(capabilityHandlers, capability.id);
|
|
29
|
+
if (!handler) {
|
|
30
|
+
return rejectCapabilityExecution({
|
|
31
|
+
code: 'missing-capability-handler',
|
|
32
|
+
message: `No Expo Runtime capability handler is configured for '${capability.id}'.`,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return executeForeignCapabilityHandlerAsync(handler, capability, input);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/*** Execute a foreign capability handler and translate its failure into the bridge result contract. */
|
|
39
|
+
async function executeForeignCapabilityHandlerAsync(
|
|
40
|
+
handler: (args: ExpoRuntimeCapabilityHandlerArgs) => Promise<void> | void,
|
|
41
|
+
capability: Capability,
|
|
42
|
+
input: unknown,
|
|
43
|
+
): Promise<ExpoRuntimeCapabilityExecutionResult> {
|
|
44
|
+
try {
|
|
45
|
+
await handler({ capability, input });
|
|
46
|
+
return { ok: true };
|
|
47
|
+
} catch (error) {
|
|
48
|
+
return rejectCapabilityExecution({
|
|
49
|
+
code: 'capability-handler-failed',
|
|
50
|
+
message: `The handler for '${capability.id}' failed: ${getFailureMessage(error)}`,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
23
53
|
}
|
|
24
54
|
|
|
25
55
|
/*** Find the configured executor for one canonical capability without dynamic record access. */
|
|
@@ -34,17 +64,45 @@ function findCapabilityHandler(
|
|
|
34
64
|
function executeExpoAlert(
|
|
35
65
|
input: unknown,
|
|
36
66
|
alertImpl: ((message: string) => void) | undefined,
|
|
37
|
-
):
|
|
38
|
-
if (!isExpoAlertInput(input))
|
|
39
|
-
|
|
67
|
+
): ExpoRuntimeCapabilityExecutionResult {
|
|
68
|
+
if (!isExpoAlertInput(input)) {
|
|
69
|
+
return rejectCapabilityExecution({
|
|
70
|
+
code: 'invalid-expo-alert-input',
|
|
71
|
+
message: "The 'expo.alert' capability requires an input object with only a string 'message'.",
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
if (!alertImpl) {
|
|
75
|
+
return rejectCapabilityExecution({
|
|
76
|
+
code: 'missing-expo-alert-handler',
|
|
77
|
+
message: "No Expo alert host callback is configured for 'expo.alert'.",
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
alertImpl(input.message);
|
|
81
|
+
return { ok: true };
|
|
40
82
|
}
|
|
41
83
|
|
|
42
84
|
/*** Validate the serializable input accepted by the Expo alert capability. */
|
|
43
85
|
function isExpoAlertInput(input: unknown): input is { readonly message: string } {
|
|
44
|
-
|
|
45
|
-
typeof input
|
|
46
|
-
input
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
)
|
|
86
|
+
if (
|
|
87
|
+
typeof input !== 'object' ||
|
|
88
|
+
input === null ||
|
|
89
|
+
Array.isArray(input) ||
|
|
90
|
+
!('message' in input)
|
|
91
|
+
) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
const entries = Object.entries(input);
|
|
95
|
+
return entries.length === 1 && typeof input.message === 'string';
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/*** Report a rejected capability invocation with a diagnostic that a runtime owner can surface. */
|
|
99
|
+
function rejectCapabilityExecution(
|
|
100
|
+
diagnostic: ExpoRuntimeCapabilityDiagnostic,
|
|
101
|
+
): ExpoRuntimeCapabilityExecutionResult {
|
|
102
|
+
return { ok: false, diagnostics: [diagnostic] };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/*** Convert any foreign handler failure into a diagnostic-safe message. */
|
|
106
|
+
function getFailureMessage(error: unknown): string {
|
|
107
|
+
return error instanceof Error ? error.message : String(error);
|
|
50
108
|
}
|
package/src/index.ts
CHANGED
|
@@ -22,6 +22,9 @@ export {
|
|
|
22
22
|
export {
|
|
23
23
|
type ExecuteExpoRuntimeCapabilityArgs,
|
|
24
24
|
executeExpoRuntimeCapabilityAsync,
|
|
25
|
+
type ExpoRuntimeCapabilityDiagnostic,
|
|
26
|
+
type ExpoRuntimeCapabilityDiagnosticCode,
|
|
27
|
+
type ExpoRuntimeCapabilityExecutionResult,
|
|
25
28
|
type ExpoRuntimeCapabilityHandler,
|
|
26
29
|
type ExpoRuntimeCapabilityHandlerArgs,
|
|
27
30
|
type ExpoRuntimeRouteResolution,
|
|
@@ -10,6 +10,25 @@ export interface ExpoRuntimeCapabilityHandler {
|
|
|
10
10
|
readonly execute: (args: ExpoRuntimeCapabilityHandlerArgs) => Promise<void> | void;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
export type ExpoRuntimeCapabilityDiagnosticCode =
|
|
14
|
+
| 'invalid-capability-descriptor'
|
|
15
|
+
| 'invalid-expo-alert-input'
|
|
16
|
+
| 'capability-handler-failed'
|
|
17
|
+
| 'missing-capability-handler'
|
|
18
|
+
| 'missing-expo-alert-handler';
|
|
19
|
+
|
|
20
|
+
export interface ExpoRuntimeCapabilityDiagnostic {
|
|
21
|
+
readonly code: ExpoRuntimeCapabilityDiagnosticCode;
|
|
22
|
+
readonly message: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type ExpoRuntimeCapabilityExecutionResult =
|
|
26
|
+
| { readonly ok: true }
|
|
27
|
+
| {
|
|
28
|
+
readonly ok: false;
|
|
29
|
+
readonly diagnostics: readonly ExpoRuntimeCapabilityDiagnostic[];
|
|
30
|
+
};
|
|
31
|
+
|
|
13
32
|
export interface ExecuteExpoRuntimeCapabilityArgs {
|
|
14
33
|
readonly capability: unknown;
|
|
15
34
|
readonly input?: unknown;
|