@ionic/portals-react-native 0.0.6 → 0.2.0-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -159
- package/ReactNativePortals.podspec +2 -1
- package/android/build.gradle +1 -1
- package/android/src/main/java/io/ionic/portals/reactnative/PortalView.kt +132 -0
- package/android/src/main/java/io/ionic/portals/reactnative/ReactNativeLiveUpdatesModule.kt +10 -28
- package/android/src/main/java/io/ionic/portals/reactnative/ReactNativePortalManager.kt +149 -0
- package/android/src/main/java/io/ionic/portals/reactnative/ReactNativePortalsModule.kt +76 -215
- package/android/src/main/java/io/ionic/portals/reactnative/ReactNativePortalsPackage.kt +0 -1
- package/android/src/main/java/io/ionic/portals/reactnative/ReactNativePortalsPubSub.kt +45 -0
- package/ios/LiveUpdate+Dict.swift +30 -0
- package/ios/LiveUpdateManager+Async.swift +69 -0
- package/ios/LiveUpdateManagerError+Dict.swift +19 -0
- package/ios/Podfile +2 -1
- package/ios/Podfile.lock +13 -12
- package/ios/Portal+Dict.swift +35 -0
- package/ios/PortalManager.m +10 -4
- package/ios/PortalView.m +2 -3
- package/ios/PortalView.swift +67 -0
- package/ios/PortalsConfig.swift +92 -0
- package/ios/PortalsPubSub.m +3 -3
- package/ios/PortalsPubSub.swift +47 -0
- package/ios/PortalsReactNative.swift +104 -0
- package/ios/ReactNativePortals.xcodeproj/project.pbxproj +32 -8
- package/lib/commonjs/index.js +108 -13
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/index.js +104 -12
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/index.d.ts +106 -3
- package/package.json +3 -1
- package/src/index.ts +127 -13
- package/ios/LiveUpdatesManager.m +0 -16
- package/ios/ReactNativePortals.swift +0 -264
package/lib/module/index.js
CHANGED
|
@@ -1,12 +1,23 @@
|
|
|
1
1
|
import { NativeEventEmitter, NativeModules } from 'react-native';
|
|
2
2
|
const {
|
|
3
3
|
IONPortalPubSub,
|
|
4
|
-
|
|
5
|
-
IONLiveUpdatesManager
|
|
4
|
+
IONPortalsReactNative
|
|
6
5
|
} = NativeModules;
|
|
7
6
|
export { default as PortalView } from './PortalView';
|
|
7
|
+
/**
|
|
8
|
+
* The data that is received from a subscription event.
|
|
9
|
+
*/
|
|
10
|
+
|
|
8
11
|
const PortalsPubSub = new NativeEventEmitter(IONPortalPubSub);
|
|
9
12
|
const subscriptionMap = new Map();
|
|
13
|
+
/**
|
|
14
|
+
* Subscribes to messages for a topic
|
|
15
|
+
*
|
|
16
|
+
* @param topic The topic to subscribe to
|
|
17
|
+
* @param onMessageReceived The callback to invoke when a message is received
|
|
18
|
+
* @returns A Promise<number> containing the unique subscription reference. This will need to be stored for calling {@link unsubscribe}.
|
|
19
|
+
*/
|
|
20
|
+
|
|
10
21
|
export const subscribe = async (topic, onMessageReceived) => {
|
|
11
22
|
const subscriptionRef = await IONPortalPubSub.subscribe(topic);
|
|
12
23
|
const subscriber = PortalsPubSub.addListener('PortalsSubscription', message => {
|
|
@@ -17,6 +28,13 @@ export const subscribe = async (topic, onMessageReceived) => {
|
|
|
17
28
|
subscriptionMap.set(subscriptionRef, subscriber);
|
|
18
29
|
return subscriptionRef;
|
|
19
30
|
};
|
|
31
|
+
/**
|
|
32
|
+
* Unsubscribes from events for the provided topic and subscription reference
|
|
33
|
+
*
|
|
34
|
+
* @param topic The topic to unsubscribe from
|
|
35
|
+
* @param subRef The unique subscription reference received when initially calling {@link subscribe}
|
|
36
|
+
*/
|
|
37
|
+
|
|
20
38
|
export const unsubscribe = (topic, subRef) => {
|
|
21
39
|
IONPortalPubSub.unsubscribe(topic, subRef);
|
|
22
40
|
const subscription = subscriptionMap.get(subRef);
|
|
@@ -26,25 +44,99 @@ export const unsubscribe = (topic, subRef) => {
|
|
|
26
44
|
subscriptionMap.delete(subRef);
|
|
27
45
|
}
|
|
28
46
|
};
|
|
47
|
+
/**
|
|
48
|
+
* Publishes a message to the provided topic
|
|
49
|
+
*
|
|
50
|
+
* @param topic The topic to publish the message to
|
|
51
|
+
* @param data The data to publish to subscribers
|
|
52
|
+
*/
|
|
53
|
+
|
|
29
54
|
export const publish = (topic, data) => {
|
|
30
55
|
const msg = {
|
|
31
56
|
message: data
|
|
32
57
|
};
|
|
33
58
|
IONPortalPubSub.publish(topic, msg);
|
|
34
59
|
};
|
|
35
|
-
|
|
36
|
-
|
|
60
|
+
/**
|
|
61
|
+
* Validates that a valid registration key has been procured from http://ionic.io/register-portals
|
|
62
|
+
* @param key The registration key
|
|
63
|
+
* @returns Promise<void>
|
|
64
|
+
*/
|
|
65
|
+
|
|
66
|
+
export const register = async key => {
|
|
67
|
+
return IONPortalsReactNative.register(key);
|
|
37
68
|
};
|
|
38
|
-
|
|
39
|
-
|
|
69
|
+
/**
|
|
70
|
+
* The configuration of a web application to be embedded in a React Native application.
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Adds a Portal to an internal registry. Must be called before attempting to render a {@link PortalView}.
|
|
75
|
+
*
|
|
76
|
+
* @param portal The portal to add to the internal registry.
|
|
77
|
+
* @returns Promise containing the Portal that was added to the registry.
|
|
78
|
+
*/
|
|
79
|
+
export const addPortal = async portal => {
|
|
80
|
+
return IONPortalsReactNative.addPortal(portal);
|
|
40
81
|
};
|
|
41
|
-
|
|
42
|
-
|
|
82
|
+
/**
|
|
83
|
+
* Adds all portals to an internal registry. This or {@link addPortal} must be called before attempting to render a {@link PortalView}
|
|
84
|
+
*
|
|
85
|
+
* @param portals The portals to add to the internal registry.
|
|
86
|
+
* @returns Promise containing the Portals that were added to the registry.
|
|
87
|
+
*/
|
|
88
|
+
|
|
89
|
+
export const addPortals = async portals => {
|
|
90
|
+
return IONPortalsReactNative.addPortals(portals);
|
|
43
91
|
};
|
|
44
|
-
|
|
45
|
-
|
|
92
|
+
/**
|
|
93
|
+
* Gets a {@link Portal} previously registered via {@link addPortal} or {@link addPortals}.
|
|
94
|
+
*
|
|
95
|
+
* @param name The portal name to retrieve from the internal registry.
|
|
96
|
+
* @returns Promise containing the registered {@link Portal}. If the {@link Portal} was not registered, the Promise will fail.
|
|
97
|
+
*/
|
|
98
|
+
|
|
99
|
+
export const getPortal = async name => {
|
|
100
|
+
return IONPortalsReactNative.getPortal(name);
|
|
46
101
|
};
|
|
47
|
-
|
|
48
|
-
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Configures LiveUpdates to cyrptographically verify the contents of the downloaded bundles.
|
|
105
|
+
* This method must be called before any LiveUpdates are registered otherwise they will no longer be tracked.
|
|
106
|
+
*
|
|
107
|
+
* @param pathToKey The *relative* path to the public key for verification.
|
|
108
|
+
* This path should be the same relatibe to the main application bundle on iOS and the assets directory on Android.
|
|
109
|
+
* @returns Promise<void>
|
|
110
|
+
*/
|
|
111
|
+
export const enableSecureLiveUpdates = async pathToKey => {
|
|
112
|
+
return IONPortalsReactNative.enableSecureLiveUpdates(pathToKey);
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Syncs a single live update.
|
|
116
|
+
*
|
|
117
|
+
* @param appId The AppFlow application ID to sync.
|
|
118
|
+
* @returns A Promise<LiveUpdate>. A failure should result in a {@link LiveUpdateError}.
|
|
119
|
+
*/
|
|
120
|
+
|
|
121
|
+
export const syncOne = async appId => {
|
|
122
|
+
return IONPortalsReactNative.syncOne(appId);
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* Syncs many live updates.
|
|
126
|
+
*
|
|
127
|
+
* @param appIds The AppFlow application IDs to sync.
|
|
128
|
+
* @returns Promise<SyncResults>
|
|
129
|
+
*/
|
|
130
|
+
|
|
131
|
+
export const syncSome = async appIds => {
|
|
132
|
+
return IONPortalsReactNative.syncSome(appIds);
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* Syncs all registered LiveUpdates
|
|
136
|
+
* @returns Promise<SyncResults>
|
|
137
|
+
*/
|
|
138
|
+
|
|
139
|
+
export const syncAll = async () => {
|
|
140
|
+
return IONPortalsReactNative.syncAll();
|
|
49
141
|
};
|
|
50
142
|
//# sourceMappingURL=index.js.map
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NativeEventEmitter","NativeModules","IONPortalPubSub","
|
|
1
|
+
{"version":3,"names":["NativeEventEmitter","NativeModules","IONPortalPubSub","IONPortalsReactNative","default","PortalView","PortalsPubSub","subscriptionMap","Map","subscribe","topic","onMessageReceived","subscriptionRef","subscriber","addListener","message","set","unsubscribe","subRef","subscription","get","undefined","remove","delete","publish","data","msg","register","key","addPortal","portal","addPortals","portals","getPortal","name","enableSecureLiveUpdates","pathToKey","syncOne","appId","syncSome","appIds","syncAll"],"sources":["index.ts"],"sourcesContent":["import {\n EmitterSubscription,\n NativeEventEmitter,\n NativeModules,\n ViewProps,\n} from 'react-native';\n\nconst { IONPortalPubSub, IONPortalsReactNative } = NativeModules;\n\nexport { default as PortalView } from './PortalView';\n\n/**\n * The data that is received from a subscription event.\n */\nexport interface Message {\n /** The unique subscription reference received from {@link subscribe}*/\n subscriptionRef: number;\n data: any;\n /** The topic the message was sent from */\n topic: string;\n}\n\nconst PortalsPubSub = new NativeEventEmitter(IONPortalPubSub);\n\nconst subscriptionMap = new Map<number, EmitterSubscription>();\n\n/**\n * Subscribes to messages for a topic\n *\n * @param topic The topic to subscribe to\n * @param onMessageReceived The callback to invoke when a message is received\n * @returns A Promise<number> containing the unique subscription reference. This will need to be stored for calling {@link unsubscribe}.\n */\nexport const subscribe = async (\n topic: string,\n onMessageReceived: (message: Message) => void\n): Promise<number> => {\n const subscriptionRef = await IONPortalPubSub.subscribe(topic);\n\n const subscriber = PortalsPubSub.addListener(\n 'PortalsSubscription',\n (message: Message) => {\n if (message.subscriptionRef === subscriptionRef) {\n onMessageReceived(message);\n }\n }\n );\n\n subscriptionMap.set(subscriptionRef, subscriber);\n\n return subscriptionRef;\n};\n\n/**\n * Unsubscribes from events for the provided topic and subscription reference\n *\n * @param topic The topic to unsubscribe from\n * @param subRef The unique subscription reference received when initially calling {@link subscribe}\n */\nexport const unsubscribe = (topic: string, subRef: number) => {\n IONPortalPubSub.unsubscribe(topic, subRef);\n\n const subscription = subscriptionMap.get(subRef);\n if (subscription !== undefined) {\n subscription.remove();\n subscriptionMap.delete(subRef);\n }\n};\n\n/**\n * Publishes a message to the provided topic\n *\n * @param topic The topic to publish the message to\n * @param data The data to publish to subscribers\n */\nexport const publish = (topic: string, data: any) => {\n const msg = { message: data };\n IONPortalPubSub.publish(topic, msg);\n};\n\n/**\n * Validates that a valid registration key has been procured from http://ionic.io/register-portals\n * @param key The registration key\n * @returns Promise<void>\n */\nexport const register = async (key: string): Promise<void> => {\n return IONPortalsReactNative.register(key);\n};\n\n/**\n * The configuration of a web application to be embedded in a React Native application.\n */\nexport interface Portal {\n /** The name of the Portal to be referenced. Must be **unique** */\n name: string;\n /** The classpath of all Capacitor plugins used in Android. (e.g. com.capacitorjs.plugins.camera.CameraPlugin) */\n androidPlugins?: string[];\n /**\n * The root directory of the web application relative to Bundle.main on iOS\n * and src/main/assets on Android. If omitted, `name` is used.\n */\n startDir?: string;\n /** The name of the initial file to load. If omitted, 'index.html' is used. */\n index?: string;\n /** Any data needed at initial render when a portal is loaded. */\n initialContext?: {\n [key: string]: any;\n };\n liveUpdate?: LiveUpdateConfig;\n}\n\n/**\n * A subset of {@link Portal} properties needed for rendering a Portal. `initialContext` can be used to override\n * any initialContext defined in the original {@link Portal} definition.\n */\nexport type PortalProp = {\n portal: Pick<Portal, 'name' | 'initialContext'>;\n};\n\n/**\n * Props needed for rendering a {@link Portal}\n */\nexport type PortalProps = PortalProp & ViewProps;\n\n/**\n * Adds a Portal to an internal registry. Must be called before attempting to render a {@link PortalView}.\n *\n * @param portal The portal to add to the internal registry.\n * @returns Promise containing the Portal that was added to the registry.\n */\nexport const addPortal = async (portal: Portal): Promise<Portal> => {\n return IONPortalsReactNative.addPortal(portal);\n};\n\n/**\n * Adds all portals to an internal registry. This or {@link addPortal} must be called before attempting to render a {@link PortalView}\n *\n * @param portals The portals to add to the internal registry.\n * @returns Promise containing the Portals that were added to the registry.\n */\nexport const addPortals = async (portals: Portal[]): Promise<Portal[]> => {\n return IONPortalsReactNative.addPortals(portals);\n};\n\n/**\n * Gets a {@link Portal} previously registered via {@link addPortal} or {@link addPortals}.\n *\n * @param name The portal name to retrieve from the internal registry.\n * @returns Promise containing the registered {@link Portal}. If the {@link Portal} was not registered, the Promise will fail.\n */\nexport const getPortal = async (name: string): Promise<Portal> => {\n return IONPortalsReactNative.getPortal(name);\n};\n\nexport interface LiveUpdate {\n /** The AppFlow application ID */\n appId: string;\n /** The AppFlow distribution channel */\n channel: string;\n}\n\n/** Data needed to register a live update to be managed */\nexport type LiveUpdateConfig = LiveUpdate & { syncOnAdd: boolean };\n\nexport interface LiveUpdateError {\n /** The AppFlow application ID relating to the failure */\n appId: string;\n /** The step in the sync process the LiveUpdate failed on. (e.g. CHECK, UNPACK)*/\n failStep: string;\n /** A human readable error message */\n message: string;\n}\n\n/** Used for communicating sync results of multiple live updates */\nexport interface SyncResults {\n liveUpdates: LiveUpdate[];\n errors: LiveUpdateError[];\n}\n\n/**\n * Configures LiveUpdates to cyrptographically verify the contents of the downloaded bundles.\n * This method must be called before any LiveUpdates are registered otherwise they will no longer be tracked.\n *\n * @param pathToKey The *relative* path to the public key for verification.\n * This path should be the same relatibe to the main application bundle on iOS and the assets directory on Android.\n * @returns Promise<void>\n */\nexport const enableSecureLiveUpdates = async (\n pathToKey: string\n): Promise<void> => {\n return IONPortalsReactNative.enableSecureLiveUpdates(pathToKey);\n};\n\n/**\n * Syncs a single live update.\n *\n * @param appId The AppFlow application ID to sync.\n * @returns A Promise<LiveUpdate>. A failure should result in a {@link LiveUpdateError}.\n */\nexport const syncOne = async (appId: string): Promise<LiveUpdate> => {\n return IONPortalsReactNative.syncOne(appId);\n};\n\n/**\n * Syncs many live updates.\n *\n * @param appIds The AppFlow application IDs to sync.\n * @returns Promise<SyncResults>\n */\nexport const syncSome = async (appIds: string[]): Promise<SyncResults> => {\n return IONPortalsReactNative.syncSome(appIds);\n};\n\n/**\n * Syncs all registered LiveUpdates\n * @returns Promise<SyncResults>\n */\nexport const syncAll = async (): Promise<SyncResults> => {\n return IONPortalsReactNative.syncAll();\n};\n"],"mappings":"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"}
|
|
@@ -1,41 +1,144 @@
|
|
|
1
1
|
import { ViewProps } from 'react-native';
|
|
2
2
|
export { default as PortalView } from './PortalView';
|
|
3
|
+
/**
|
|
4
|
+
* The data that is received from a subscription event.
|
|
5
|
+
*/
|
|
3
6
|
export interface Message {
|
|
7
|
+
/** The unique subscription reference received from {@link subscribe}*/
|
|
4
8
|
subscriptionRef: number;
|
|
5
9
|
data: any;
|
|
10
|
+
/** The topic the message was sent from */
|
|
6
11
|
topic: string;
|
|
7
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Subscribes to messages for a topic
|
|
15
|
+
*
|
|
16
|
+
* @param topic The topic to subscribe to
|
|
17
|
+
* @param onMessageReceived The callback to invoke when a message is received
|
|
18
|
+
* @returns A Promise<number> containing the unique subscription reference. This will need to be stored for calling {@link unsubscribe}.
|
|
19
|
+
*/
|
|
8
20
|
export declare const subscribe: (topic: string, onMessageReceived: (message: Message) => void) => Promise<number>;
|
|
21
|
+
/**
|
|
22
|
+
* Unsubscribes from events for the provided topic and subscription reference
|
|
23
|
+
*
|
|
24
|
+
* @param topic The topic to unsubscribe from
|
|
25
|
+
* @param subRef The unique subscription reference received when initially calling {@link subscribe}
|
|
26
|
+
*/
|
|
9
27
|
export declare const unsubscribe: (topic: string, subRef: number) => void;
|
|
28
|
+
/**
|
|
29
|
+
* Publishes a message to the provided topic
|
|
30
|
+
*
|
|
31
|
+
* @param topic The topic to publish the message to
|
|
32
|
+
* @param data The data to publish to subscribers
|
|
33
|
+
*/
|
|
10
34
|
export declare const publish: (topic: string, data: any) => void;
|
|
11
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Validates that a valid registration key has been procured from http://ionic.io/register-portals
|
|
37
|
+
* @param key The registration key
|
|
38
|
+
* @returns Promise<void>
|
|
39
|
+
*/
|
|
40
|
+
export declare const register: (key: string) => Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* The configuration of a web application to be embedded in a React Native application.
|
|
43
|
+
*/
|
|
12
44
|
export interface Portal {
|
|
45
|
+
/** The name of the Portal to be referenced. Must be **unique** */
|
|
13
46
|
name: string;
|
|
47
|
+
/** The classpath of all Capacitor plugins used in Android. (e.g. com.capacitorjs.plugins.camera.CameraPlugin) */
|
|
14
48
|
androidPlugins?: string[];
|
|
49
|
+
/**
|
|
50
|
+
* The root directory of the web application relative to Bundle.main on iOS
|
|
51
|
+
* and src/main/assets on Android. If omitted, `name` is used.
|
|
52
|
+
*/
|
|
15
53
|
startDir?: string;
|
|
54
|
+
/** The name of the initial file to load. If omitted, 'index.html' is used. */
|
|
55
|
+
index?: string;
|
|
56
|
+
/** Any data needed at initial render when a portal is loaded. */
|
|
16
57
|
initialContext?: {
|
|
17
58
|
[key: string]: any;
|
|
18
59
|
};
|
|
19
60
|
liveUpdate?: LiveUpdateConfig;
|
|
20
61
|
}
|
|
21
|
-
|
|
22
|
-
|
|
62
|
+
/**
|
|
63
|
+
* A subset of {@link Portal} properties needed for rendering a Portal. `initialContext` can be used to override
|
|
64
|
+
* any initialContext defined in the original {@link Portal} definition.
|
|
65
|
+
*/
|
|
66
|
+
export declare type PortalProp = {
|
|
67
|
+
portal: Pick<Portal, 'name' | 'initialContext'>;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Props needed for rendering a {@link Portal}
|
|
71
|
+
*/
|
|
72
|
+
export declare type PortalProps = PortalProp & ViewProps;
|
|
73
|
+
/**
|
|
74
|
+
* Adds a Portal to an internal registry. Must be called before attempting to render a {@link PortalView}.
|
|
75
|
+
*
|
|
76
|
+
* @param portal The portal to add to the internal registry.
|
|
77
|
+
* @returns Promise containing the Portal that was added to the registry.
|
|
78
|
+
*/
|
|
79
|
+
export declare const addPortal: (portal: Portal) => Promise<Portal>;
|
|
80
|
+
/**
|
|
81
|
+
* Adds all portals to an internal registry. This or {@link addPortal} must be called before attempting to render a {@link PortalView}
|
|
82
|
+
*
|
|
83
|
+
* @param portals The portals to add to the internal registry.
|
|
84
|
+
* @returns Promise containing the Portals that were added to the registry.
|
|
85
|
+
*/
|
|
86
|
+
export declare const addPortals: (portals: Portal[]) => Promise<Portal[]>;
|
|
87
|
+
/**
|
|
88
|
+
* Gets a {@link Portal} previously registered via {@link addPortal} or {@link addPortals}.
|
|
89
|
+
*
|
|
90
|
+
* @param name The portal name to retrieve from the internal registry.
|
|
91
|
+
* @returns Promise containing the registered {@link Portal}. If the {@link Portal} was not registered, the Promise will fail.
|
|
92
|
+
*/
|
|
93
|
+
export declare const getPortal: (name: string) => Promise<Portal>;
|
|
23
94
|
export interface LiveUpdate {
|
|
95
|
+
/** The AppFlow application ID */
|
|
24
96
|
appId: string;
|
|
97
|
+
/** The AppFlow distribution channel */
|
|
25
98
|
channel: string;
|
|
26
99
|
}
|
|
100
|
+
/** Data needed to register a live update to be managed */
|
|
27
101
|
export declare type LiveUpdateConfig = LiveUpdate & {
|
|
28
102
|
syncOnAdd: boolean;
|
|
29
103
|
};
|
|
30
104
|
export interface LiveUpdateError {
|
|
105
|
+
/** The AppFlow application ID relating to the failure */
|
|
31
106
|
appId: string;
|
|
107
|
+
/** The step in the sync process the LiveUpdate failed on. (e.g. CHECK, UNPACK)*/
|
|
32
108
|
failStep: string;
|
|
109
|
+
/** A human readable error message */
|
|
33
110
|
message: string;
|
|
34
111
|
}
|
|
112
|
+
/** Used for communicating sync results of multiple live updates */
|
|
35
113
|
export interface SyncResults {
|
|
36
114
|
liveUpdates: LiveUpdate[];
|
|
37
115
|
errors: LiveUpdateError[];
|
|
38
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* Configures LiveUpdates to cyrptographically verify the contents of the downloaded bundles.
|
|
119
|
+
* This method must be called before any LiveUpdates are registered otherwise they will no longer be tracked.
|
|
120
|
+
*
|
|
121
|
+
* @param pathToKey The *relative* path to the public key for verification.
|
|
122
|
+
* This path should be the same relatibe to the main application bundle on iOS and the assets directory on Android.
|
|
123
|
+
* @returns Promise<void>
|
|
124
|
+
*/
|
|
125
|
+
export declare const enableSecureLiveUpdates: (pathToKey: string) => Promise<void>;
|
|
126
|
+
/**
|
|
127
|
+
* Syncs a single live update.
|
|
128
|
+
*
|
|
129
|
+
* @param appId The AppFlow application ID to sync.
|
|
130
|
+
* @returns A Promise<LiveUpdate>. A failure should result in a {@link LiveUpdateError}.
|
|
131
|
+
*/
|
|
39
132
|
export declare const syncOne: (appId: string) => Promise<LiveUpdate>;
|
|
133
|
+
/**
|
|
134
|
+
* Syncs many live updates.
|
|
135
|
+
*
|
|
136
|
+
* @param appIds The AppFlow application IDs to sync.
|
|
137
|
+
* @returns Promise<SyncResults>
|
|
138
|
+
*/
|
|
40
139
|
export declare const syncSome: (appIds: string[]) => Promise<SyncResults>;
|
|
140
|
+
/**
|
|
141
|
+
* Syncs all registered LiveUpdates
|
|
142
|
+
* @returns Promise<SyncResults>
|
|
143
|
+
*/
|
|
41
144
|
export declare const syncAll: () => Promise<SyncResults>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ionic/portals-react-native",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0-1",
|
|
4
4
|
"description": "Ionic Portals for React Native",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"typescript": "tsc --noEmit",
|
|
30
30
|
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
31
31
|
"lint:fix": "eslint \"**/*.{js,ts,tsx}\" --fix",
|
|
32
|
+
"docs": "typedoc --out ./docs/documentation ./src --tsconfig ./tsconfig.build.json",
|
|
32
33
|
"prepare": "bob build",
|
|
33
34
|
"release": "release-it",
|
|
34
35
|
"example": "yarn --cwd example",
|
|
@@ -68,6 +69,7 @@
|
|
|
68
69
|
"react": "16.13.1",
|
|
69
70
|
"react-native": "0.63.4",
|
|
70
71
|
"react-native-builder-bob": "^0.18.2",
|
|
72
|
+
"typedoc": "^0.23.16",
|
|
71
73
|
"typescript": "^4.1.3"
|
|
72
74
|
},
|
|
73
75
|
"peerDependencies": {
|
package/src/index.ts
CHANGED
|
@@ -5,14 +5,18 @@ import {
|
|
|
5
5
|
ViewProps,
|
|
6
6
|
} from 'react-native';
|
|
7
7
|
|
|
8
|
-
const { IONPortalPubSub,
|
|
9
|
-
NativeModules;
|
|
8
|
+
const { IONPortalPubSub, IONPortalsReactNative } = NativeModules;
|
|
10
9
|
|
|
11
10
|
export { default as PortalView } from './PortalView';
|
|
12
11
|
|
|
12
|
+
/**
|
|
13
|
+
* The data that is received from a subscription event.
|
|
14
|
+
*/
|
|
13
15
|
export interface Message {
|
|
16
|
+
/** The unique subscription reference received from {@link subscribe}*/
|
|
14
17
|
subscriptionRef: number;
|
|
15
18
|
data: any;
|
|
19
|
+
/** The topic the message was sent from */
|
|
16
20
|
topic: string;
|
|
17
21
|
}
|
|
18
22
|
|
|
@@ -20,6 +24,13 @@ const PortalsPubSub = new NativeEventEmitter(IONPortalPubSub);
|
|
|
20
24
|
|
|
21
25
|
const subscriptionMap = new Map<number, EmitterSubscription>();
|
|
22
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Subscribes to messages for a topic
|
|
29
|
+
*
|
|
30
|
+
* @param topic The topic to subscribe to
|
|
31
|
+
* @param onMessageReceived The callback to invoke when a message is received
|
|
32
|
+
* @returns A Promise<number> containing the unique subscription reference. This will need to be stored for calling {@link unsubscribe}.
|
|
33
|
+
*/
|
|
23
34
|
export const subscribe = async (
|
|
24
35
|
topic: string,
|
|
25
36
|
onMessageReceived: (message: Message) => void
|
|
@@ -40,6 +51,12 @@ export const subscribe = async (
|
|
|
40
51
|
return subscriptionRef;
|
|
41
52
|
};
|
|
42
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Unsubscribes from events for the provided topic and subscription reference
|
|
56
|
+
*
|
|
57
|
+
* @param topic The topic to unsubscribe from
|
|
58
|
+
* @param subRef The unique subscription reference received when initially calling {@link subscribe}
|
|
59
|
+
*/
|
|
43
60
|
export const unsubscribe = (topic: string, subRef: number) => {
|
|
44
61
|
IONPortalPubSub.unsubscribe(topic, subRef);
|
|
45
62
|
|
|
@@ -50,57 +67,154 @@ export const unsubscribe = (topic: string, subRef: number) => {
|
|
|
50
67
|
}
|
|
51
68
|
};
|
|
52
69
|
|
|
70
|
+
/**
|
|
71
|
+
* Publishes a message to the provided topic
|
|
72
|
+
*
|
|
73
|
+
* @param topic The topic to publish the message to
|
|
74
|
+
* @param data The data to publish to subscribers
|
|
75
|
+
*/
|
|
53
76
|
export const publish = (topic: string, data: any) => {
|
|
54
77
|
const msg = { message: data };
|
|
55
78
|
IONPortalPubSub.publish(topic, msg);
|
|
56
79
|
};
|
|
57
80
|
|
|
58
|
-
|
|
59
|
-
|
|
81
|
+
/**
|
|
82
|
+
* Validates that a valid registration key has been procured from http://ionic.io/register-portals
|
|
83
|
+
* @param key The registration key
|
|
84
|
+
* @returns Promise<void>
|
|
85
|
+
*/
|
|
86
|
+
export const register = async (key: string): Promise<void> => {
|
|
87
|
+
return IONPortalsReactNative.register(key);
|
|
60
88
|
};
|
|
61
89
|
|
|
90
|
+
/**
|
|
91
|
+
* The configuration of a web application to be embedded in a React Native application.
|
|
92
|
+
*/
|
|
62
93
|
export interface Portal {
|
|
94
|
+
/** The name of the Portal to be referenced. Must be **unique** */
|
|
63
95
|
name: string;
|
|
96
|
+
/** The classpath of all Capacitor plugins used in Android. (e.g. com.capacitorjs.plugins.camera.CameraPlugin) */
|
|
64
97
|
androidPlugins?: string[];
|
|
98
|
+
/**
|
|
99
|
+
* The root directory of the web application relative to Bundle.main on iOS
|
|
100
|
+
* and src/main/assets on Android. If omitted, `name` is used.
|
|
101
|
+
*/
|
|
65
102
|
startDir?: string;
|
|
103
|
+
/** The name of the initial file to load. If omitted, 'index.html' is used. */
|
|
104
|
+
index?: string;
|
|
105
|
+
/** Any data needed at initial render when a portal is loaded. */
|
|
66
106
|
initialContext?: {
|
|
67
107
|
[key: string]: any;
|
|
68
108
|
};
|
|
69
109
|
liveUpdate?: LiveUpdateConfig;
|
|
70
110
|
}
|
|
71
111
|
|
|
72
|
-
|
|
112
|
+
/**
|
|
113
|
+
* A subset of {@link Portal} properties needed for rendering a Portal. `initialContext` can be used to override
|
|
114
|
+
* any initialContext defined in the original {@link Portal} definition.
|
|
115
|
+
*/
|
|
116
|
+
export type PortalProp = {
|
|
117
|
+
portal: Pick<Portal, 'name' | 'initialContext'>;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Props needed for rendering a {@link Portal}
|
|
122
|
+
*/
|
|
123
|
+
export type PortalProps = PortalProp & ViewProps;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Adds a Portal to an internal registry. Must be called before attempting to render a {@link PortalView}.
|
|
127
|
+
*
|
|
128
|
+
* @param portal The portal to add to the internal registry.
|
|
129
|
+
* @returns Promise containing the Portal that was added to the registry.
|
|
130
|
+
*/
|
|
131
|
+
export const addPortal = async (portal: Portal): Promise<Portal> => {
|
|
132
|
+
return IONPortalsReactNative.addPortal(portal);
|
|
133
|
+
};
|
|
73
134
|
|
|
74
|
-
|
|
75
|
-
|
|
135
|
+
/**
|
|
136
|
+
* Adds all portals to an internal registry. This or {@link addPortal} must be called before attempting to render a {@link PortalView}
|
|
137
|
+
*
|
|
138
|
+
* @param portals The portals to add to the internal registry.
|
|
139
|
+
* @returns Promise containing the Portals that were added to the registry.
|
|
140
|
+
*/
|
|
141
|
+
export const addPortals = async (portals: Portal[]): Promise<Portal[]> => {
|
|
142
|
+
return IONPortalsReactNative.addPortals(portals);
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Gets a {@link Portal} previously registered via {@link addPortal} or {@link addPortals}.
|
|
147
|
+
*
|
|
148
|
+
* @param name The portal name to retrieve from the internal registry.
|
|
149
|
+
* @returns Promise containing the registered {@link Portal}. If the {@link Portal} was not registered, the Promise will fail.
|
|
150
|
+
*/
|
|
151
|
+
export const getPortal = async (name: string): Promise<Portal> => {
|
|
152
|
+
return IONPortalsReactNative.getPortal(name);
|
|
76
153
|
};
|
|
77
154
|
|
|
78
155
|
export interface LiveUpdate {
|
|
156
|
+
/** The AppFlow application ID */
|
|
79
157
|
appId: string;
|
|
158
|
+
/** The AppFlow distribution channel */
|
|
80
159
|
channel: string;
|
|
81
160
|
}
|
|
82
161
|
|
|
162
|
+
/** Data needed to register a live update to be managed */
|
|
83
163
|
export type LiveUpdateConfig = LiveUpdate & { syncOnAdd: boolean };
|
|
84
164
|
|
|
85
165
|
export interface LiveUpdateError {
|
|
166
|
+
/** The AppFlow application ID relating to the failure */
|
|
86
167
|
appId: string;
|
|
168
|
+
/** The step in the sync process the LiveUpdate failed on. (e.g. CHECK, UNPACK)*/
|
|
87
169
|
failStep: string;
|
|
170
|
+
/** A human readable error message */
|
|
88
171
|
message: string;
|
|
89
172
|
}
|
|
90
173
|
|
|
174
|
+
/** Used for communicating sync results of multiple live updates */
|
|
91
175
|
export interface SyncResults {
|
|
92
176
|
liveUpdates: LiveUpdate[];
|
|
93
177
|
errors: LiveUpdateError[];
|
|
94
178
|
}
|
|
95
179
|
|
|
96
|
-
|
|
97
|
-
|
|
180
|
+
/**
|
|
181
|
+
* Configures LiveUpdates to cyrptographically verify the contents of the downloaded bundles.
|
|
182
|
+
* This method must be called before any LiveUpdates are registered otherwise they will no longer be tracked.
|
|
183
|
+
*
|
|
184
|
+
* @param pathToKey The *relative* path to the public key for verification.
|
|
185
|
+
* This path should be the same relatibe to the main application bundle on iOS and the assets directory on Android.
|
|
186
|
+
* @returns Promise<void>
|
|
187
|
+
*/
|
|
188
|
+
export const enableSecureLiveUpdates = async (
|
|
189
|
+
pathToKey: string
|
|
190
|
+
): Promise<void> => {
|
|
191
|
+
return IONPortalsReactNative.enableSecureLiveUpdates(pathToKey);
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Syncs a single live update.
|
|
196
|
+
*
|
|
197
|
+
* @param appId The AppFlow application ID to sync.
|
|
198
|
+
* @returns A Promise<LiveUpdate>. A failure should result in a {@link LiveUpdateError}.
|
|
199
|
+
*/
|
|
200
|
+
export const syncOne = async (appId: string): Promise<LiveUpdate> => {
|
|
201
|
+
return IONPortalsReactNative.syncOne(appId);
|
|
98
202
|
};
|
|
99
203
|
|
|
100
|
-
|
|
101
|
-
|
|
204
|
+
/**
|
|
205
|
+
* Syncs many live updates.
|
|
206
|
+
*
|
|
207
|
+
* @param appIds The AppFlow application IDs to sync.
|
|
208
|
+
* @returns Promise<SyncResults>
|
|
209
|
+
*/
|
|
210
|
+
export const syncSome = async (appIds: string[]): Promise<SyncResults> => {
|
|
211
|
+
return IONPortalsReactNative.syncSome(appIds);
|
|
102
212
|
};
|
|
103
213
|
|
|
104
|
-
|
|
105
|
-
|
|
214
|
+
/**
|
|
215
|
+
* Syncs all registered LiveUpdates
|
|
216
|
+
* @returns Promise<SyncResults>
|
|
217
|
+
*/
|
|
218
|
+
export const syncAll = async (): Promise<SyncResults> => {
|
|
219
|
+
return IONPortalsReactNative.syncAll();
|
|
106
220
|
};
|
package/ios/LiveUpdatesManager.m
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// LiveUpdatesManager.m
|
|
3
|
-
// ReactNativePortals
|
|
4
|
-
//
|
|
5
|
-
// Created by Steven Sherry on 6/21/22.
|
|
6
|
-
// Copyright © 2022 Facebook. All rights reserved.
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
#import <React/RCTBridgeModule.h>
|
|
10
|
-
|
|
11
|
-
@interface RCT_EXTERN_MODULE(IONLiveUpdatesManager, NSObject)
|
|
12
|
-
RCT_EXTERN_METHOD(addLiveUpdate: (NSDictionary) liveUpdate)
|
|
13
|
-
RCT_EXTERN_METHOD(syncOne: (NSString *) appId resolver: (RCTPromiseResolveBlock) resolver rejector: (RCTPromiseRejectBlock) rejector)
|
|
14
|
-
RCT_EXTERN_METHOD(syncSome: (NSArray) appIds resolver: (RCTPromiseResolveBlock) resolver rejector: (RCTPromiseRejectBlock) rejector)
|
|
15
|
-
RCT_EXTERN_METHOD(syncAll: (RCTPromiseResolveBlock) resolver rejector: (RCTPromiseRejectBlock) rejector)
|
|
16
|
-
@end
|