@digia-engage/core 1.0.0-beta.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 (56) hide show
  1. package/DigiaEngageReactNative.podspec +21 -0
  2. package/README.md +277 -0
  3. package/android/build.gradle +82 -0
  4. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  5. package/android/gradlew +185 -0
  6. package/android/gradlew.bat +89 -0
  7. package/android/settings.gradle +33 -0
  8. package/android/src/main/AndroidManifest.xml +2 -0
  9. package/android/src/main/java/com/digia/engage/rn/DigiaModule.kt +234 -0
  10. package/android/src/main/java/com/digia/engage/rn/DigiaPackage.kt +69 -0
  11. package/android/src/main/java/com/digia/engage/rn/DigiaSlotViewManager.kt +64 -0
  12. package/android/src/main/java/com/digia/engage/rn/DigiaViewManager.kt +63 -0
  13. package/ios/DigiaEngageModule.m +71 -0
  14. package/lib/commonjs/Digia.js +106 -0
  15. package/lib/commonjs/Digia.js.map +1 -0
  16. package/lib/commonjs/DigiaHostView.js +73 -0
  17. package/lib/commonjs/DigiaHostView.js.map +1 -0
  18. package/lib/commonjs/DigiaSlotView.js +73 -0
  19. package/lib/commonjs/DigiaSlotView.js.map +1 -0
  20. package/lib/commonjs/NativeDigiaModule.js +56 -0
  21. package/lib/commonjs/NativeDigiaModule.js.map +1 -0
  22. package/lib/commonjs/index.js +27 -0
  23. package/lib/commonjs/index.js.map +1 -0
  24. package/lib/commonjs/types.js +2 -0
  25. package/lib/commonjs/types.js.map +1 -0
  26. package/lib/module/Digia.js +100 -0
  27. package/lib/module/Digia.js.map +1 -0
  28. package/lib/module/DigiaHostView.js +67 -0
  29. package/lib/module/DigiaHostView.js.map +1 -0
  30. package/lib/module/DigiaSlotView.js +66 -0
  31. package/lib/module/DigiaSlotView.js.map +1 -0
  32. package/lib/module/NativeDigiaModule.js +51 -0
  33. package/lib/module/NativeDigiaModule.js.map +1 -0
  34. package/lib/module/index.js +15 -0
  35. package/lib/module/index.js.map +1 -0
  36. package/lib/module/types.js +2 -0
  37. package/lib/module/types.js.map +1 -0
  38. package/lib/typescript/Digia.d.ts +62 -0
  39. package/lib/typescript/Digia.d.ts.map +1 -0
  40. package/lib/typescript/DigiaHostView.d.ts +40 -0
  41. package/lib/typescript/DigiaHostView.d.ts.map +1 -0
  42. package/lib/typescript/DigiaSlotView.d.ts +52 -0
  43. package/lib/typescript/DigiaSlotView.d.ts.map +1 -0
  44. package/lib/typescript/NativeDigiaModule.d.ts +45 -0
  45. package/lib/typescript/NativeDigiaModule.d.ts.map +1 -0
  46. package/lib/typescript/index.d.ts +15 -0
  47. package/lib/typescript/index.d.ts.map +1 -0
  48. package/lib/typescript/types.d.ts +58 -0
  49. package/lib/typescript/types.d.ts.map +1 -0
  50. package/package.json +89 -0
  51. package/src/Digia.ts +104 -0
  52. package/src/DigiaHostView.tsx +83 -0
  53. package/src/DigiaSlotView.tsx +79 -0
  54. package/src/NativeDigiaModule.ts +86 -0
  55. package/src/index.ts +15 -0
  56. package/src/types.ts +61 -0
@@ -0,0 +1,86 @@
1
+ /**
2
+ * NativeDigiaModule
3
+ *
4
+ * Low-level TurboModule binding to the native Digia Engage module.
5
+ *
6
+ * The module is resolved lazily on first use (not at import time) so that
7
+ * module evaluation before native initialisation doesn't throw.
8
+ * Resolution order:
9
+ * 1. TurboModuleRegistry.get() — New Architecture / JSI path
10
+ * 2. NativeModules — bridge interop layer (RN 0.73+ New Arch
11
+ * with isTurboModule: false in ReactModuleInfo)
12
+ * 3. null — non-Android environments; methods no-op
13
+ *
14
+ * Prefer using the high-level `Digia` singleton from `index.ts`.
15
+ */
16
+ import type { TurboModule } from 'react-native';
17
+ import { NativeModules, TurboModuleRegistry } from 'react-native';
18
+
19
+ /**
20
+ * Codegen spec — drives Android/iOS TurboModule generation.
21
+ *
22
+ * Rules for codegen compatibility:
23
+ * • File must be named `Native*.ts` (already satisfied).
24
+ * • All method parameter types must be scalar, Promise, Object, or Array.
25
+ * • `Object` maps to ReadableMap on Android, NSDictionary on iOS.
26
+ */
27
+ export interface Spec extends TurboModule {
28
+ /** Initialise the SDK. Call once before anything else. */
29
+ initialize(apiKey: string, environment: string, logLevel: string): Promise<void>;
30
+
31
+ /**
32
+ * Wire the internal RNEventBridgePlugin with the native SDK.
33
+ * Called automatically by Digia.register() on first plugin registration.
34
+ * Never call this directly.
35
+ */
36
+ registerBridge(): void;
37
+
38
+ /** Notify the SDK of the currently visible screen. */
39
+ setCurrentScreen(name: string): void;
40
+
41
+ /**
42
+ * Forward a campaign payload from a JS CEP plugin into the native
43
+ * rendering engine via the DigiaCEPDelegate.
44
+ */
45
+ triggerCampaign(
46
+ id: string,
47
+ content: Object,
48
+ cepContext: Object,
49
+ ): void;
50
+
51
+ /** Invalidate / dismiss a campaign by its ID. */
52
+ invalidateCampaign(campaignId: string): void;
53
+ }
54
+
55
+ // Try TurboModuleRegistry first (New Architecture / JSI).
56
+ // Fall back to NativeModules (bridge interop layer — enabled by default in
57
+ // RN 0.73+ New Architecture when the module is registered with
58
+ // isTurboModule: false in ReactModuleInfo).
59
+ // If neither resolves, warn in DEV and use no-op stubs so non-Android
60
+ // environments (web, Storybook) don't crash.
61
+ let _resolved: Spec | null = null;
62
+ function getModule(): Spec | null {
63
+ if (_resolved !== null) return _resolved;
64
+ _resolved =
65
+ TurboModuleRegistry.get<Spec>('DigiaEngageModule') ??
66
+ (NativeModules.DigiaEngageModule as Spec | undefined) ??
67
+ null;
68
+ if (__DEV__ && !_resolved) {
69
+ console.warn(
70
+ '[Digia] DigiaEngageModule not found.\n' +
71
+ 'Make sure @digia/engage is linked and the app has been rebuilt.',
72
+ );
73
+ }
74
+ return _resolved;
75
+ }
76
+
77
+ export const nativeDigiaModule: Spec = {
78
+ initialize: (apiKey, environment, logLevel) =>
79
+ getModule()?.initialize(apiKey, environment, logLevel) ?? Promise.resolve(),
80
+ registerBridge: () => getModule()?.registerBridge(),
81
+ setCurrentScreen: (name) => getModule()?.setCurrentScreen(name),
82
+ triggerCampaign: (id, content, cepContext) =>
83
+ getModule()?.triggerCampaign(id, content, cepContext),
84
+ invalidateCampaign: (campaignId) => getModule()?.invalidateCampaign(campaignId),
85
+ getConstants: () => getModule()?.getConstants?.() ?? {},
86
+ };
package/src/index.ts ADDED
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @digia/engage-react-native
3
+ *
4
+ * React Native bridge for the Digia Engage SDK.
5
+ *
6
+ * The SDK surfaces Digia Compose UI inside React Native via:
7
+ * • `Digia` – SDK lifecycle (initialize, setCurrentScreen)
8
+ * • `DigiaHostView` – Transparent native overlay view that hosts Compose dialogs/
9
+ * bottom-sheets managed by the Digia CEP engine.
10
+ */
11
+
12
+ export { Digia } from './Digia';
13
+ export { DigiaHostView } from './DigiaHostView';
14
+ export { DigiaSlotView } from './DigiaSlotView';
15
+ export type { DigiaConfig, DigiaDelegate, DigiaPlugin, InAppPayload } from './types';
package/src/types.ts ADDED
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Payload delivered to the Digia rendering engine for a CEP campaign.
3
+ *
4
+ * Mirrors InAppPayload on Android / Flutter.
5
+ */
6
+ export interface InAppPayload {
7
+ /** Unique campaign ID from the CEP platform. */
8
+ id: string;
9
+ /** Marketer-authored content map (JSON-serialisable). */
10
+ content: Record<string, unknown>;
11
+ /** CEP-platform metadata, e.g. { campaignId, campaignName }. */
12
+ cepContext: Record<string, unknown>;
13
+ }
14
+
15
+ /**
16
+ * Delegate passed by the Digia SDK to each registered plugin via setup().
17
+ *
18
+ * Mirrors DigiaCEPDelegate on Android / Flutter.
19
+ * Call these instead of touching Digia directly from inside a plugin.
20
+ */
21
+ export interface DigiaDelegate {
22
+ /** Deliver a campaign payload into the Digia rendering engine. */
23
+ onCampaignTriggered(payload: InAppPayload): void;
24
+ /** Invalidate / dismiss a campaign by its ID. */
25
+ onCampaignInvalidated(campaignId: string): void;
26
+ }
27
+
28
+ /**
29
+ * Interface that every Digia CEP plugin must implement.
30
+ *
31
+ * Mirrors DigiaCEPPlugin on Android / Flutter.
32
+ * Register plugins via `Digia.register(plugin)` — do NOT call setup() directly.
33
+ */
34
+ export interface DigiaPlugin {
35
+ readonly identifier: string;
36
+ /** Called by Digia.register() — do not call manually. */
37
+ setup(delegate: DigiaDelegate): void;
38
+ /** Called by Digia.setCurrentScreen() — do not call manually. */
39
+ forwardScreen(name: string): void;
40
+ /** Called by Digia.unregister() or when tearing down the app. */
41
+ teardown(): void;
42
+ }
43
+
44
+ /**
45
+ * Configuration for initialising the Digia Engage SDK.
46
+ */
47
+ export interface DigiaConfig {
48
+ /** The API key provided by Digia. */
49
+ apiKey: string;
50
+ /**
51
+ * The target environment.
52
+ * @default 'production'
53
+ */
54
+ environment?: 'production' | 'sandbox';
55
+ /**
56
+ * Log verbosity.
57
+ * @default 'error'
58
+ */
59
+ logLevel?: 'none' | 'error' | 'verbose';
60
+ }
61
+