@amplytools/react-native-amply-sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +178 -0
- package/README.md +714 -0
- package/android/build.gradle +90 -0
- package/android/consumer-rules.pro +1 -0
- package/android/gradle.properties +3 -0
- package/android/settings.gradle +9 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/java/tools/amply/sdk/reactnative/AmplyModule.kt +384 -0
- package/android/src/main/java/tools/amply/sdk/reactnative/AmplyPackage.kt +39 -0
- package/android/src/main/java/tools/amply/sdk/reactnative/core/AmplyClient.kt +30 -0
- package/android/src/main/java/tools/amply/sdk/reactnative/core/DefaultAmplyClient.kt +296 -0
- package/android/src/main/java/tools/amply/sdk/reactnative/model/AmplyInitializationOptions.kt +10 -0
- package/android/src/main/java/tools/amply/sdk/reactnative/model/DataSetType.kt +42 -0
- package/android/src/main/java/tools/amply/sdk/reactnative/model/DataSetTypeMapper.kt +38 -0
- package/android/src/main/java/tools/amply/sdk/reactnative/model/DeepLinkPayload.kt +8 -0
- package/android/src/main/java/tools/amply/sdk/reactnative/model/EventEnvelope.kt +9 -0
- package/android/src/main/jni/AmplyTurboModule.cpp +29 -0
- package/android/src/main/jni/CMakeLists.txt +76 -0
- package/android/src/newarch/java/tools/amply/sdk/reactnative/NativeAmplyModuleSpec.java +75 -0
- package/android/src/newarch/jni/AmplyReactNative-generated.cpp +77 -0
- package/android/src/newarch/jni/AmplyReactNative.h +31 -0
- package/android/src/newarch/jni/CMakeLists.txt +40 -0
- package/app.plugin.js +1 -0
- package/dist/index.js +272 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +234 -0
- package/dist/index.mjs.map +1 -0
- package/dist/plugin/index.d.ts +6 -0
- package/dist/plugin/index.d.ts.map +1 -0
- package/dist/plugin/index.js +186 -0
- package/dist/plugin/index.js.map +1 -0
- package/dist/plugin/index.mjs +169 -0
- package/dist/plugin/index.mjs.map +1 -0
- package/dist/plugin/src/index.d.ts +6 -0
- package/dist/plugin/src/index.d.ts.map +1 -0
- package/dist/plugin/src/index.js +3 -0
- package/dist/plugin/src/withAmply.d.ts +30 -0
- package/dist/plugin/src/withAmply.d.ts.map +1 -0
- package/dist/plugin/src/withAmply.js +51 -0
- package/dist/plugin/withAmply.d.ts +12 -0
- package/dist/plugin/withAmply.d.ts.map +1 -0
- package/dist/src/__tests__/index.test.d.ts +2 -0
- package/dist/src/__tests__/index.test.d.ts.map +1 -0
- package/dist/src/__tests__/index.test.js +70 -0
- package/dist/src/hooks/useAmplySystemEvents.d.ts +12 -0
- package/dist/src/hooks/useAmplySystemEvents.d.ts.map +1 -0
- package/dist/src/hooks/useAmplySystemEvents.js +56 -0
- package/dist/src/index.d.ts +32 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +80 -0
- package/dist/src/nativeModule.d.ts +5 -0
- package/dist/src/nativeModule.d.ts.map +1 -0
- package/dist/src/nativeModule.js +48 -0
- package/dist/src/nativeSpecs/NativeAmplyModule.d.ts +75 -0
- package/dist/src/nativeSpecs/NativeAmplyModule.d.ts.map +1 -0
- package/dist/src/nativeSpecs/NativeAmplyModule.js +2 -0
- package/dist/src/systemEventUtils.d.ts +3 -0
- package/dist/src/systemEventUtils.d.ts.map +1 -0
- package/dist/src/systemEventUtils.js +30 -0
- package/dist/src/systemEvents.d.ts +6 -0
- package/dist/src/systemEvents.d.ts.map +1 -0
- package/dist/src/systemEvents.js +8 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/docs/ARCHITECTURE.md +1115 -0
- package/expo-module.config.json +11 -0
- package/ios/AmplyReactNative.podspec +32 -0
- package/ios/README.md +11 -0
- package/ios/Sources/AmplyReactNative/AmplyModule.mm +332 -0
- package/ios/Sources/AmplyReactNative/AmplyReactNative/AmplyReactNative-generated.mm +111 -0
- package/ios/Sources/AmplyReactNative/AmplyReactNative/AmplyReactNative.h +152 -0
- package/package.json +71 -0
- package/plugin/build/index.d.ts +5 -0
- package/plugin/build/index.js +8 -0
- package/plugin/build/withAmply.d.ts +29 -0
- package/plugin/build/withAmply.js +53 -0
- package/plugin/src/index.ts +7 -0
- package/plugin/src/withAmply.ts +68 -0
- package/plugin/tsconfig.json +8 -0
- package/plugin/tsconfig.tsbuildinfo +1 -0
- package/react-native.config.js +34 -0
- package/scripts/codegen.js +212 -0
- package/src/__tests__/index.test.ts +92 -0
- package/src/hooks/useAmplySystemEvents.ts +75 -0
- package/src/index.ts +115 -0
- package/src/nativeModule.ts +65 -0
- package/src/nativeSpecs/NativeAmplyModule.ts +80 -0
- package/src/systemEventUtils.ts +35 -0
- package/src/systemEvents.ts +13 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// plugin/index.ts
|
|
21
|
+
var plugin_exports = {};
|
|
22
|
+
__export(plugin_exports, {
|
|
23
|
+
default: () => plugin_default
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(plugin_exports);
|
|
26
|
+
|
|
27
|
+
// plugin/withAmply.ts
|
|
28
|
+
var import_config_plugins = require("@expo/config-plugins");
|
|
29
|
+
var import_generateCode = require("@expo/config-plugins/build/utils/generateCode");
|
|
30
|
+
var import_codeMod = require("@expo/config-plugins/build/android/codeMod");
|
|
31
|
+
var DEFAULT_SDK_VERSION = "0.1.7";
|
|
32
|
+
var GITHUB_MAVEN_URL = "https://maven.pkg.github.com/amply/sdk";
|
|
33
|
+
var GITHUB_MAVEN_CREDENTIALS_ENV = {
|
|
34
|
+
username: "AMPLY_MAVEN_USERNAME",
|
|
35
|
+
password: "AMPLY_MAVEN_PASSWORD"
|
|
36
|
+
};
|
|
37
|
+
var GITHUB_GRADLE_REPOSITORY_SNIPPET = `
|
|
38
|
+
maven {
|
|
39
|
+
url '${GITHUB_MAVEN_URL}'
|
|
40
|
+
credentials {
|
|
41
|
+
username findProperty('${GITHUB_MAVEN_CREDENTIALS_ENV.username}') ?: System.getenv('${GITHUB_MAVEN_CREDENTIALS_ENV.username}')
|
|
42
|
+
password findProperty('${GITHUB_MAVEN_CREDENTIALS_ENV.password}') ?: System.getenv('${GITHUB_MAVEN_CREDENTIALS_ENV.password}')
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
`;
|
|
46
|
+
var GRADLE_DEPENDENCY_LINE = ` implementation("tools.amply:sdk-android:${"$"}{project.findProperty('amplySdkVersion') ?: System.getenv('AMPLY_SDK_VERSION') ?: '${DEFAULT_SDK_VERSION}'}")`;
|
|
47
|
+
function applyGithubMavenRepository(contents) {
|
|
48
|
+
if (contents.includes(GITHUB_MAVEN_URL)) {
|
|
49
|
+
return contents;
|
|
50
|
+
}
|
|
51
|
+
const repositoriesBlock = /(repositories\s*\{[\s\S]*?\n\})/;
|
|
52
|
+
if (repositoriesBlock.test(contents)) {
|
|
53
|
+
return contents.replace(repositoriesBlock, (match) => {
|
|
54
|
+
if (match.includes(GITHUB_MAVEN_URL)) {
|
|
55
|
+
return match;
|
|
56
|
+
}
|
|
57
|
+
return match.replace(/\n\}/, `
|
|
58
|
+
${GITHUB_GRADLE_REPOSITORY_SNIPPET} }`);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return `${contents}
|
|
62
|
+
repositories {${GITHUB_GRADLE_REPOSITORY_SNIPPET}}
|
|
63
|
+
`;
|
|
64
|
+
}
|
|
65
|
+
function applyDependency(contents) {
|
|
66
|
+
if (contents.includes("tools.amply:sdk-android")) {
|
|
67
|
+
return contents;
|
|
68
|
+
}
|
|
69
|
+
const dependenciesBlock = /(dependencies\s*\{[\s\S]*?\n\})/;
|
|
70
|
+
if (dependenciesBlock.test(contents)) {
|
|
71
|
+
return contents.replace(dependenciesBlock, (match) => {
|
|
72
|
+
if (match.includes("tools.amply:sdk-android")) {
|
|
73
|
+
return match;
|
|
74
|
+
}
|
|
75
|
+
return match.replace(/\n\}/, `
|
|
76
|
+
${GRADLE_DEPENDENCY_LINE}
|
|
77
|
+
}`);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return `${contents}
|
|
81
|
+
dependencies {
|
|
82
|
+
${GRADLE_DEPENDENCY_LINE}
|
|
83
|
+
}
|
|
84
|
+
`;
|
|
85
|
+
}
|
|
86
|
+
function addAmplyPackageRegistration(contents, language) {
|
|
87
|
+
if (contents.includes("AmplyPackage")) {
|
|
88
|
+
console.log("[Amply] AmplyPackage already registered in MainApplication");
|
|
89
|
+
return contents;
|
|
90
|
+
}
|
|
91
|
+
if (!contents.includes("import com.amply.reactnative.AmplyPackage")) {
|
|
92
|
+
contents = (0, import_codeMod.addImports)(contents, ["com.amply.reactnative.AmplyPackage"], language === "java");
|
|
93
|
+
console.log("[Amply] Added AmplyPackage import to MainApplication");
|
|
94
|
+
}
|
|
95
|
+
const amplyPackageCall = language === "java" ? "add(new AmplyPackage());" : "add(AmplyPackage())";
|
|
96
|
+
const result = (0, import_generateCode.mergeContents)({
|
|
97
|
+
src: contents,
|
|
98
|
+
newSrc: amplyPackageCall,
|
|
99
|
+
tag: "amply-package-registration",
|
|
100
|
+
anchor: /(?<=\.apply\s*\{[\s]*)/,
|
|
101
|
+
offset: 0,
|
|
102
|
+
comment: language === "java" ? "//" : "//"
|
|
103
|
+
});
|
|
104
|
+
if (result.didMerge) {
|
|
105
|
+
console.log("[Amply] Registered AmplyPackage in getPackages() method");
|
|
106
|
+
return result.contents;
|
|
107
|
+
} else {
|
|
108
|
+
console.warn("[Amply] Could not register AmplyPackage - anchor pattern not found");
|
|
109
|
+
return contents;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
var withAmply = (config, props = {}) => {
|
|
113
|
+
const { sdkVersion, useGithubFallbackRepo = false } = props;
|
|
114
|
+
const version = sdkVersion != null ? sdkVersion : DEFAULT_SDK_VERSION;
|
|
115
|
+
config = (0, import_config_plugins.withGradleProperties)(config, (gradleConfig) => {
|
|
116
|
+
const exists = gradleConfig.modResults.find(
|
|
117
|
+
(item) => item.type === "property" && item.key === "amplySdkVersion"
|
|
118
|
+
);
|
|
119
|
+
if (!exists) {
|
|
120
|
+
gradleConfig.modResults.push({ type: "property", key: "amplySdkVersion", value: version });
|
|
121
|
+
}
|
|
122
|
+
return gradleConfig;
|
|
123
|
+
});
|
|
124
|
+
config = (0, import_config_plugins.withProjectBuildGradle)(config, (gradleConfig) => {
|
|
125
|
+
if (useGithubFallbackRepo) {
|
|
126
|
+
gradleConfig.modResults.contents = applyGithubMavenRepository(gradleConfig.modResults.contents);
|
|
127
|
+
}
|
|
128
|
+
gradleConfig.modResults.contents = applyDependency(gradleConfig.modResults.contents);
|
|
129
|
+
return gradleConfig;
|
|
130
|
+
});
|
|
131
|
+
config = (0, import_config_plugins.withSettingsGradle)(config, (gradleConfig) => {
|
|
132
|
+
const contents = gradleConfig.modResults.contents;
|
|
133
|
+
if (contents.includes(":amplyreactnative")) {
|
|
134
|
+
console.log("[Amply] Amply module already configured in settings.gradle");
|
|
135
|
+
return gradleConfig;
|
|
136
|
+
}
|
|
137
|
+
const moduleConfig = "\n\ninclude ':amplyreactnative'\nproject(':amplyreactnative').projectDir = new File(rootProject.projectDir, '../../../android')";
|
|
138
|
+
const lastIncludeBuildMatch = contents.lastIndexOf("includeBuild");
|
|
139
|
+
let modified = contents;
|
|
140
|
+
if (lastIncludeBuildMatch !== -1) {
|
|
141
|
+
const nextNewlineAfterIncludeBuild = contents.indexOf("\n", lastIncludeBuildMatch);
|
|
142
|
+
if (nextNewlineAfterIncludeBuild !== -1) {
|
|
143
|
+
modified = contents.slice(0, nextNewlineAfterIncludeBuild + 1) + moduleConfig + contents.slice(nextNewlineAfterIncludeBuild + 1);
|
|
144
|
+
console.log("[Amply] Added Amply module include to settings.gradle");
|
|
145
|
+
}
|
|
146
|
+
} else {
|
|
147
|
+
modified = contents + moduleConfig;
|
|
148
|
+
console.log("[Amply] Appended Amply module include to settings.gradle (no includeBuild found)");
|
|
149
|
+
}
|
|
150
|
+
gradleConfig.modResults.contents = modified;
|
|
151
|
+
return gradleConfig;
|
|
152
|
+
});
|
|
153
|
+
config = (0, import_config_plugins.withAppBuildGradle)(config, (gradleConfig) => {
|
|
154
|
+
const contents = gradleConfig.modResults.contents;
|
|
155
|
+
if (contents.includes(":amplyreactnative")) {
|
|
156
|
+
console.log("[Amply] Amply module already configured in app/build.gradle");
|
|
157
|
+
return gradleConfig;
|
|
158
|
+
}
|
|
159
|
+
const depsStart = contents.indexOf("dependencies {");
|
|
160
|
+
if (depsStart !== -1) {
|
|
161
|
+
const firstImplAfterDeps = contents.indexOf("implementation", depsStart);
|
|
162
|
+
if (firstImplAfterDeps !== -1) {
|
|
163
|
+
const lineEnd = contents.indexOf("\n", firstImplAfterDeps);
|
|
164
|
+
if (lineEnd !== -1) {
|
|
165
|
+
const moduleImpl = "\n\n // Amply React Native module\n implementation project(':amplyreactnative')";
|
|
166
|
+
gradleConfig.modResults.contents = contents.slice(0, lineEnd) + moduleImpl + contents.slice(lineEnd);
|
|
167
|
+
console.log("[Amply] Added Amply module dependency to app/build.gradle");
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return gradleConfig;
|
|
172
|
+
});
|
|
173
|
+
config = (0, import_config_plugins.withMainApplication)(config, async (config2) => {
|
|
174
|
+
const { contents, language } = config2.modResults;
|
|
175
|
+
const modified = addAmplyPackageRegistration(contents, language);
|
|
176
|
+
config2.modResults.contents = modified;
|
|
177
|
+
return config2;
|
|
178
|
+
});
|
|
179
|
+
return config;
|
|
180
|
+
};
|
|
181
|
+
var withAmply_default = withAmply;
|
|
182
|
+
|
|
183
|
+
// plugin/index.ts
|
|
184
|
+
var plugin = (config, props) => withAmply_default(config, props);
|
|
185
|
+
var plugin_default = plugin;
|
|
186
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../plugin/index.ts","../../plugin/withAmply.ts"],"sourcesContent":["import type {ConfigPlugin} from '@expo/config-plugins';\nimport withAmply from './withAmply';\n\nconst plugin: ConfigPlugin<{ sdkVersion?: string }> = (config, props) =>\n withAmply(config, props);\n\nexport default plugin;\n","import {\n ConfigPlugin,\n withGradleProperties,\n withProjectBuildGradle,\n withMainApplication,\n withSettingsGradle,\n withAppBuildGradle,\n AndroidConfig,\n} from '@expo/config-plugins';\nimport { mergeContents } from '@expo/config-plugins/build/utils/generateCode';\nimport { addImports } from '@expo/config-plugins/build/android/codeMod';\n\nconst DEFAULT_SDK_VERSION = '0.1.7';\nconst GITHUB_MAVEN_URL = 'https://maven.pkg.github.com/amply/sdk';\nconst GITHUB_MAVEN_CREDENTIALS_ENV = {\n username: 'AMPLY_MAVEN_USERNAME',\n password: 'AMPLY_MAVEN_PASSWORD',\n};\n\nconst GITHUB_GRADLE_REPOSITORY_SNIPPET = `\n maven {\n url '${GITHUB_MAVEN_URL}'\n credentials {\n username findProperty('${GITHUB_MAVEN_CREDENTIALS_ENV.username}') ?: System.getenv('${GITHUB_MAVEN_CREDENTIALS_ENV.username}')\n password findProperty('${GITHUB_MAVEN_CREDENTIALS_ENV.password}') ?: System.getenv('${GITHUB_MAVEN_CREDENTIALS_ENV.password}')\n }\n }\n`;\n\nconst GRADLE_DEPENDENCY_LINE = ` implementation(\"tools.amply:sdk-android:${'$'}{project.findProperty('amplySdkVersion') ?: System.getenv('AMPLY_SDK_VERSION') ?: '${DEFAULT_SDK_VERSION}'}\")`;\n\nfunction applyGithubMavenRepository(contents: string): string {\n if (contents.includes(GITHUB_MAVEN_URL)) {\n return contents;\n }\n\n const repositoriesBlock = /(repositories\\s*\\{[\\s\\S]*?\\n\\})/;\n if (repositoriesBlock.test(contents)) {\n return contents.replace(repositoriesBlock, match => {\n if (match.includes(GITHUB_MAVEN_URL)) {\n return match;\n }\n return match.replace(/\\n\\}/, `\\n${GITHUB_GRADLE_REPOSITORY_SNIPPET} }`);\n });\n }\n\n // Fallback: append at the end of settings block\n return `${contents}\\nrepositories {${GITHUB_GRADLE_REPOSITORY_SNIPPET}}\\n`;\n}\n\nfunction applyDependency(contents: string): string {\n if (contents.includes('tools.amply:sdk-android')) {\n return contents;\n }\n\n const dependenciesBlock = /(dependencies\\s*\\{[\\s\\S]*?\\n\\})/;\n if (dependenciesBlock.test(contents)) {\n return contents.replace(dependenciesBlock, match => {\n if (match.includes('tools.amply:sdk-android')) {\n return match;\n }\n return match.replace(/\\n\\}/, `\\n${GRADLE_DEPENDENCY_LINE}\\n}`);\n });\n }\n\n return `${contents}\\ndependencies {\\n${GRADLE_DEPENDENCY_LINE}\\n}\\n`;\n}\n\ntype WithAmplyPluginProps = {\n sdkVersion?: string;\n /**\n * Optional escape hatch for internal builds that still rely on GitHub Packages.\n * Public installs resolve from Maven Central without any additional repositories.\n */\n useGithubFallbackRepo?: boolean;\n};\n\nfunction addAmplyPackageRegistration(contents: string, language: 'java' | 'kt'): string {\n // Check if AmplyPackage is already registered\n if (contents.includes('AmplyPackage')) {\n console.log('[Amply] AmplyPackage already registered in MainApplication');\n return contents;\n }\n\n // Add import if not present\n if (!contents.includes('import com.amply.reactnative.AmplyPackage')) {\n contents = addImports(contents, ['com.amply.reactnative.AmplyPackage'], language === 'java');\n console.log('[Amply] Added AmplyPackage import to MainApplication');\n }\n\n // Determine the correct syntax for the language\n const amplyPackageCall = language === 'java' ? 'add(new AmplyPackage());' : 'add(AmplyPackage())';\n\n // Add AmplyPackage() to the packages list in getPackages() method\n // Use mergeContents for safe, idempotent insertion\n const result = mergeContents({\n src: contents,\n newSrc: amplyPackageCall,\n tag: 'amply-package-registration',\n anchor: /(?<=\\.apply\\s*\\{[\\s]*)/,\n offset: 0,\n comment: language === 'java' ? '//' : '//',\n });\n\n if (result.didMerge) {\n console.log('[Amply] Registered AmplyPackage in getPackages() method');\n return result.contents;\n } else {\n console.warn('[Amply] Could not register AmplyPackage - anchor pattern not found');\n return contents;\n }\n}\n\nconst withAmply: ConfigPlugin<WithAmplyPluginProps> = (config, props = {}) => {\n const {sdkVersion, useGithubFallbackRepo = false} = props;\n const version = sdkVersion ?? DEFAULT_SDK_VERSION;\n\n config = withGradleProperties(config, gradleConfig => {\n const exists = gradleConfig.modResults.find(\n item => item.type === 'property' && item.key === 'amplySdkVersion'\n );\n if (!exists) {\n gradleConfig.modResults.push({ type: 'property', key: 'amplySdkVersion', value: version });\n }\n return gradleConfig;\n });\n\n config = withProjectBuildGradle(config, gradleConfig => {\n if (useGithubFallbackRepo) {\n gradleConfig.modResults.contents = applyGithubMavenRepository(gradleConfig.modResults.contents);\n }\n gradleConfig.modResults.contents = applyDependency(gradleConfig.modResults.contents);\n return gradleConfig;\n });\n\n // Add Amply native module to settings.gradle\n config = withSettingsGradle(config, gradleConfig => {\n const contents = gradleConfig.modResults.contents;\n\n // Only add if not already present\n if (contents.includes(':amplyreactnative')) {\n console.log('[Amply] Amply module already configured in settings.gradle');\n return gradleConfig;\n }\n\n // Add the Amply native module include configuration after the last includeBuild statement\n const moduleConfig = \"\\n\\ninclude ':amplyreactnative'\\nproject(':amplyreactnative').projectDir = new File(rootProject.projectDir, '../../../android')\";\n\n const lastIncludeBuildMatch = contents.lastIndexOf('includeBuild');\n let modified = contents;\n\n if (lastIncludeBuildMatch !== -1) {\n const nextNewlineAfterIncludeBuild = contents.indexOf('\\n', lastIncludeBuildMatch);\n if (nextNewlineAfterIncludeBuild !== -1) {\n modified =\n contents.slice(0, nextNewlineAfterIncludeBuild + 1) +\n moduleConfig +\n contents.slice(nextNewlineAfterIncludeBuild + 1);\n console.log('[Amply] Added Amply module include to settings.gradle');\n }\n } else {\n // Fallback: append at the end\n modified = contents + moduleConfig;\n console.log('[Amply] Appended Amply module include to settings.gradle (no includeBuild found)');\n }\n\n gradleConfig.modResults.contents = modified;\n return gradleConfig;\n });\n\n // Add Amply native module dependency to app/build.gradle\n config = withAppBuildGradle(config, gradleConfig => {\n const contents = gradleConfig.modResults.contents;\n\n // Only add if not already present\n if (contents.includes(':amplyreactnative')) {\n console.log('[Amply] Amply module already configured in app/build.gradle');\n return gradleConfig;\n }\n\n // Add the Amply native module dependency after the first implementation statement\n const depsStart = contents.indexOf('dependencies {');\n if (depsStart !== -1) {\n const firstImplAfterDeps = contents.indexOf('implementation', depsStart);\n if (firstImplAfterDeps !== -1) {\n const lineEnd = contents.indexOf('\\n', firstImplAfterDeps);\n if (lineEnd !== -1) {\n const moduleImpl = \"\\n\\n // Amply React Native module\\n implementation project(':amplyreactnative')\";\n gradleConfig.modResults.contents =\n contents.slice(0, lineEnd) +\n moduleImpl +\n contents.slice(lineEnd);\n console.log('[Amply] Added Amply module dependency to app/build.gradle');\n }\n }\n }\n\n return gradleConfig;\n });\n\n // Register AmplyPackage in MainApplication using proper Expo API\n // This hook runs AFTER the MainApplication file is generated by Expo\n config = withMainApplication(config, async config => {\n const { contents, language } = config.modResults;\n const modified = addAmplyPackageRegistration(contents, language);\n config.modResults.contents = modified;\n return config;\n });\n\n return config;\n};\n\nexport default withAmply;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,4BAQO;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AAC7B,WAAOA;AAAA,EACT,CAAC;AAED,SAAO;AACT;AAEA,IAAO,oBAAQ;;;ADjNf,IAAM,SAAgD,CAAC,QAAQ,UAC7D,kBAAU,QAAQ,KAAK;AAEzB,IAAO,iBAAQ;","names":["config"]}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
// plugin/withAmply.ts
|
|
2
|
+
import {
|
|
3
|
+
withGradleProperties,
|
|
4
|
+
withProjectBuildGradle,
|
|
5
|
+
withMainApplication,
|
|
6
|
+
withSettingsGradle,
|
|
7
|
+
withAppBuildGradle
|
|
8
|
+
} from "@expo/config-plugins";
|
|
9
|
+
import { mergeContents } from "@expo/config-plugins/build/utils/generateCode";
|
|
10
|
+
import { addImports } from "@expo/config-plugins/build/android/codeMod";
|
|
11
|
+
var DEFAULT_SDK_VERSION = "0.1.7";
|
|
12
|
+
var GITHUB_MAVEN_URL = "https://maven.pkg.github.com/amply/sdk";
|
|
13
|
+
var GITHUB_MAVEN_CREDENTIALS_ENV = {
|
|
14
|
+
username: "AMPLY_MAVEN_USERNAME",
|
|
15
|
+
password: "AMPLY_MAVEN_PASSWORD"
|
|
16
|
+
};
|
|
17
|
+
var GITHUB_GRADLE_REPOSITORY_SNIPPET = `
|
|
18
|
+
maven {
|
|
19
|
+
url '${GITHUB_MAVEN_URL}'
|
|
20
|
+
credentials {
|
|
21
|
+
username findProperty('${GITHUB_MAVEN_CREDENTIALS_ENV.username}') ?: System.getenv('${GITHUB_MAVEN_CREDENTIALS_ENV.username}')
|
|
22
|
+
password findProperty('${GITHUB_MAVEN_CREDENTIALS_ENV.password}') ?: System.getenv('${GITHUB_MAVEN_CREDENTIALS_ENV.password}')
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
`;
|
|
26
|
+
var GRADLE_DEPENDENCY_LINE = ` implementation("tools.amply:sdk-android:${"$"}{project.findProperty('amplySdkVersion') ?: System.getenv('AMPLY_SDK_VERSION') ?: '${DEFAULT_SDK_VERSION}'}")`;
|
|
27
|
+
function applyGithubMavenRepository(contents) {
|
|
28
|
+
if (contents.includes(GITHUB_MAVEN_URL)) {
|
|
29
|
+
return contents;
|
|
30
|
+
}
|
|
31
|
+
const repositoriesBlock = /(repositories\s*\{[\s\S]*?\n\})/;
|
|
32
|
+
if (repositoriesBlock.test(contents)) {
|
|
33
|
+
return contents.replace(repositoriesBlock, (match) => {
|
|
34
|
+
if (match.includes(GITHUB_MAVEN_URL)) {
|
|
35
|
+
return match;
|
|
36
|
+
}
|
|
37
|
+
return match.replace(/\n\}/, `
|
|
38
|
+
${GITHUB_GRADLE_REPOSITORY_SNIPPET} }`);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return `${contents}
|
|
42
|
+
repositories {${GITHUB_GRADLE_REPOSITORY_SNIPPET}}
|
|
43
|
+
`;
|
|
44
|
+
}
|
|
45
|
+
function applyDependency(contents) {
|
|
46
|
+
if (contents.includes("tools.amply:sdk-android")) {
|
|
47
|
+
return contents;
|
|
48
|
+
}
|
|
49
|
+
const dependenciesBlock = /(dependencies\s*\{[\s\S]*?\n\})/;
|
|
50
|
+
if (dependenciesBlock.test(contents)) {
|
|
51
|
+
return contents.replace(dependenciesBlock, (match) => {
|
|
52
|
+
if (match.includes("tools.amply:sdk-android")) {
|
|
53
|
+
return match;
|
|
54
|
+
}
|
|
55
|
+
return match.replace(/\n\}/, `
|
|
56
|
+
${GRADLE_DEPENDENCY_LINE}
|
|
57
|
+
}`);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return `${contents}
|
|
61
|
+
dependencies {
|
|
62
|
+
${GRADLE_DEPENDENCY_LINE}
|
|
63
|
+
}
|
|
64
|
+
`;
|
|
65
|
+
}
|
|
66
|
+
function addAmplyPackageRegistration(contents, language) {
|
|
67
|
+
if (contents.includes("AmplyPackage")) {
|
|
68
|
+
console.log("[Amply] AmplyPackage already registered in MainApplication");
|
|
69
|
+
return contents;
|
|
70
|
+
}
|
|
71
|
+
if (!contents.includes("import com.amply.reactnative.AmplyPackage")) {
|
|
72
|
+
contents = addImports(contents, ["com.amply.reactnative.AmplyPackage"], language === "java");
|
|
73
|
+
console.log("[Amply] Added AmplyPackage import to MainApplication");
|
|
74
|
+
}
|
|
75
|
+
const amplyPackageCall = language === "java" ? "add(new AmplyPackage());" : "add(AmplyPackage())";
|
|
76
|
+
const result = mergeContents({
|
|
77
|
+
src: contents,
|
|
78
|
+
newSrc: amplyPackageCall,
|
|
79
|
+
tag: "amply-package-registration",
|
|
80
|
+
anchor: /(?<=\.apply\s*\{[\s]*)/,
|
|
81
|
+
offset: 0,
|
|
82
|
+
comment: language === "java" ? "//" : "//"
|
|
83
|
+
});
|
|
84
|
+
if (result.didMerge) {
|
|
85
|
+
console.log("[Amply] Registered AmplyPackage in getPackages() method");
|
|
86
|
+
return result.contents;
|
|
87
|
+
} else {
|
|
88
|
+
console.warn("[Amply] Could not register AmplyPackage - anchor pattern not found");
|
|
89
|
+
return contents;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
var withAmply = (config, props = {}) => {
|
|
93
|
+
const { sdkVersion, useGithubFallbackRepo = false } = props;
|
|
94
|
+
const version = sdkVersion != null ? sdkVersion : DEFAULT_SDK_VERSION;
|
|
95
|
+
config = withGradleProperties(config, (gradleConfig) => {
|
|
96
|
+
const exists = gradleConfig.modResults.find(
|
|
97
|
+
(item) => item.type === "property" && item.key === "amplySdkVersion"
|
|
98
|
+
);
|
|
99
|
+
if (!exists) {
|
|
100
|
+
gradleConfig.modResults.push({ type: "property", key: "amplySdkVersion", value: version });
|
|
101
|
+
}
|
|
102
|
+
return gradleConfig;
|
|
103
|
+
});
|
|
104
|
+
config = withProjectBuildGradle(config, (gradleConfig) => {
|
|
105
|
+
if (useGithubFallbackRepo) {
|
|
106
|
+
gradleConfig.modResults.contents = applyGithubMavenRepository(gradleConfig.modResults.contents);
|
|
107
|
+
}
|
|
108
|
+
gradleConfig.modResults.contents = applyDependency(gradleConfig.modResults.contents);
|
|
109
|
+
return gradleConfig;
|
|
110
|
+
});
|
|
111
|
+
config = withSettingsGradle(config, (gradleConfig) => {
|
|
112
|
+
const contents = gradleConfig.modResults.contents;
|
|
113
|
+
if (contents.includes(":amplyreactnative")) {
|
|
114
|
+
console.log("[Amply] Amply module already configured in settings.gradle");
|
|
115
|
+
return gradleConfig;
|
|
116
|
+
}
|
|
117
|
+
const moduleConfig = "\n\ninclude ':amplyreactnative'\nproject(':amplyreactnative').projectDir = new File(rootProject.projectDir, '../../../android')";
|
|
118
|
+
const lastIncludeBuildMatch = contents.lastIndexOf("includeBuild");
|
|
119
|
+
let modified = contents;
|
|
120
|
+
if (lastIncludeBuildMatch !== -1) {
|
|
121
|
+
const nextNewlineAfterIncludeBuild = contents.indexOf("\n", lastIncludeBuildMatch);
|
|
122
|
+
if (nextNewlineAfterIncludeBuild !== -1) {
|
|
123
|
+
modified = contents.slice(0, nextNewlineAfterIncludeBuild + 1) + moduleConfig + contents.slice(nextNewlineAfterIncludeBuild + 1);
|
|
124
|
+
console.log("[Amply] Added Amply module include to settings.gradle");
|
|
125
|
+
}
|
|
126
|
+
} else {
|
|
127
|
+
modified = contents + moduleConfig;
|
|
128
|
+
console.log("[Amply] Appended Amply module include to settings.gradle (no includeBuild found)");
|
|
129
|
+
}
|
|
130
|
+
gradleConfig.modResults.contents = modified;
|
|
131
|
+
return gradleConfig;
|
|
132
|
+
});
|
|
133
|
+
config = withAppBuildGradle(config, (gradleConfig) => {
|
|
134
|
+
const contents = gradleConfig.modResults.contents;
|
|
135
|
+
if (contents.includes(":amplyreactnative")) {
|
|
136
|
+
console.log("[Amply] Amply module already configured in app/build.gradle");
|
|
137
|
+
return gradleConfig;
|
|
138
|
+
}
|
|
139
|
+
const depsStart = contents.indexOf("dependencies {");
|
|
140
|
+
if (depsStart !== -1) {
|
|
141
|
+
const firstImplAfterDeps = contents.indexOf("implementation", depsStart);
|
|
142
|
+
if (firstImplAfterDeps !== -1) {
|
|
143
|
+
const lineEnd = contents.indexOf("\n", firstImplAfterDeps);
|
|
144
|
+
if (lineEnd !== -1) {
|
|
145
|
+
const moduleImpl = "\n\n // Amply React Native module\n implementation project(':amplyreactnative')";
|
|
146
|
+
gradleConfig.modResults.contents = contents.slice(0, lineEnd) + moduleImpl + contents.slice(lineEnd);
|
|
147
|
+
console.log("[Amply] Added Amply module dependency to app/build.gradle");
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return gradleConfig;
|
|
152
|
+
});
|
|
153
|
+
config = withMainApplication(config, async (config2) => {
|
|
154
|
+
const { contents, language } = config2.modResults;
|
|
155
|
+
const modified = addAmplyPackageRegistration(contents, language);
|
|
156
|
+
config2.modResults.contents = modified;
|
|
157
|
+
return config2;
|
|
158
|
+
});
|
|
159
|
+
return config;
|
|
160
|
+
};
|
|
161
|
+
var withAmply_default = withAmply;
|
|
162
|
+
|
|
163
|
+
// plugin/index.ts
|
|
164
|
+
var plugin = (config, props) => withAmply_default(config, props);
|
|
165
|
+
var plugin_default = plugin;
|
|
166
|
+
export {
|
|
167
|
+
plugin_default as default
|
|
168
|
+
};
|
|
169
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../plugin/withAmply.ts","../../plugin/index.ts"],"sourcesContent":["import {\n ConfigPlugin,\n withGradleProperties,\n withProjectBuildGradle,\n withMainApplication,\n withSettingsGradle,\n withAppBuildGradle,\n AndroidConfig,\n} from '@expo/config-plugins';\nimport { mergeContents } from '@expo/config-plugins/build/utils/generateCode';\nimport { addImports } from '@expo/config-plugins/build/android/codeMod';\n\nconst DEFAULT_SDK_VERSION = '0.1.7';\nconst GITHUB_MAVEN_URL = 'https://maven.pkg.github.com/amply/sdk';\nconst GITHUB_MAVEN_CREDENTIALS_ENV = {\n username: 'AMPLY_MAVEN_USERNAME',\n password: 'AMPLY_MAVEN_PASSWORD',\n};\n\nconst GITHUB_GRADLE_REPOSITORY_SNIPPET = `\n maven {\n url '${GITHUB_MAVEN_URL}'\n credentials {\n username findProperty('${GITHUB_MAVEN_CREDENTIALS_ENV.username}') ?: System.getenv('${GITHUB_MAVEN_CREDENTIALS_ENV.username}')\n password findProperty('${GITHUB_MAVEN_CREDENTIALS_ENV.password}') ?: System.getenv('${GITHUB_MAVEN_CREDENTIALS_ENV.password}')\n }\n }\n`;\n\nconst GRADLE_DEPENDENCY_LINE = ` implementation(\"tools.amply:sdk-android:${'$'}{project.findProperty('amplySdkVersion') ?: System.getenv('AMPLY_SDK_VERSION') ?: '${DEFAULT_SDK_VERSION}'}\")`;\n\nfunction applyGithubMavenRepository(contents: string): string {\n if (contents.includes(GITHUB_MAVEN_URL)) {\n return contents;\n }\n\n const repositoriesBlock = /(repositories\\s*\\{[\\s\\S]*?\\n\\})/;\n if (repositoriesBlock.test(contents)) {\n return contents.replace(repositoriesBlock, match => {\n if (match.includes(GITHUB_MAVEN_URL)) {\n return match;\n }\n return match.replace(/\\n\\}/, `\\n${GITHUB_GRADLE_REPOSITORY_SNIPPET} }`);\n });\n }\n\n // Fallback: append at the end of settings block\n return `${contents}\\nrepositories {${GITHUB_GRADLE_REPOSITORY_SNIPPET}}\\n`;\n}\n\nfunction applyDependency(contents: string): string {\n if (contents.includes('tools.amply:sdk-android')) {\n return contents;\n }\n\n const dependenciesBlock = /(dependencies\\s*\\{[\\s\\S]*?\\n\\})/;\n if (dependenciesBlock.test(contents)) {\n return contents.replace(dependenciesBlock, match => {\n if (match.includes('tools.amply:sdk-android')) {\n return match;\n }\n return match.replace(/\\n\\}/, `\\n${GRADLE_DEPENDENCY_LINE}\\n}`);\n });\n }\n\n return `${contents}\\ndependencies {\\n${GRADLE_DEPENDENCY_LINE}\\n}\\n`;\n}\n\ntype WithAmplyPluginProps = {\n sdkVersion?: string;\n /**\n * Optional escape hatch for internal builds that still rely on GitHub Packages.\n * Public installs resolve from Maven Central without any additional repositories.\n */\n useGithubFallbackRepo?: boolean;\n};\n\nfunction addAmplyPackageRegistration(contents: string, language: 'java' | 'kt'): string {\n // Check if AmplyPackage is already registered\n if (contents.includes('AmplyPackage')) {\n console.log('[Amply] AmplyPackage already registered in MainApplication');\n return contents;\n }\n\n // Add import if not present\n if (!contents.includes('import com.amply.reactnative.AmplyPackage')) {\n contents = addImports(contents, ['com.amply.reactnative.AmplyPackage'], language === 'java');\n console.log('[Amply] Added AmplyPackage import to MainApplication');\n }\n\n // Determine the correct syntax for the language\n const amplyPackageCall = language === 'java' ? 'add(new AmplyPackage());' : 'add(AmplyPackage())';\n\n // Add AmplyPackage() to the packages list in getPackages() method\n // Use mergeContents for safe, idempotent insertion\n const result = mergeContents({\n src: contents,\n newSrc: amplyPackageCall,\n tag: 'amply-package-registration',\n anchor: /(?<=\\.apply\\s*\\{[\\s]*)/,\n offset: 0,\n comment: language === 'java' ? '//' : '//',\n });\n\n if (result.didMerge) {\n console.log('[Amply] Registered AmplyPackage in getPackages() method');\n return result.contents;\n } else {\n console.warn('[Amply] Could not register AmplyPackage - anchor pattern not found');\n return contents;\n }\n}\n\nconst withAmply: ConfigPlugin<WithAmplyPluginProps> = (config, props = {}) => {\n const {sdkVersion, useGithubFallbackRepo = false} = props;\n const version = sdkVersion ?? DEFAULT_SDK_VERSION;\n\n config = withGradleProperties(config, gradleConfig => {\n const exists = gradleConfig.modResults.find(\n item => item.type === 'property' && item.key === 'amplySdkVersion'\n );\n if (!exists) {\n gradleConfig.modResults.push({ type: 'property', key: 'amplySdkVersion', value: version });\n }\n return gradleConfig;\n });\n\n config = withProjectBuildGradle(config, gradleConfig => {\n if (useGithubFallbackRepo) {\n gradleConfig.modResults.contents = applyGithubMavenRepository(gradleConfig.modResults.contents);\n }\n gradleConfig.modResults.contents = applyDependency(gradleConfig.modResults.contents);\n return gradleConfig;\n });\n\n // Add Amply native module to settings.gradle\n config = withSettingsGradle(config, gradleConfig => {\n const contents = gradleConfig.modResults.contents;\n\n // Only add if not already present\n if (contents.includes(':amplyreactnative')) {\n console.log('[Amply] Amply module already configured in settings.gradle');\n return gradleConfig;\n }\n\n // Add the Amply native module include configuration after the last includeBuild statement\n const moduleConfig = \"\\n\\ninclude ':amplyreactnative'\\nproject(':amplyreactnative').projectDir = new File(rootProject.projectDir, '../../../android')\";\n\n const lastIncludeBuildMatch = contents.lastIndexOf('includeBuild');\n let modified = contents;\n\n if (lastIncludeBuildMatch !== -1) {\n const nextNewlineAfterIncludeBuild = contents.indexOf('\\n', lastIncludeBuildMatch);\n if (nextNewlineAfterIncludeBuild !== -1) {\n modified =\n contents.slice(0, nextNewlineAfterIncludeBuild + 1) +\n moduleConfig +\n contents.slice(nextNewlineAfterIncludeBuild + 1);\n console.log('[Amply] Added Amply module include to settings.gradle');\n }\n } else {\n // Fallback: append at the end\n modified = contents + moduleConfig;\n console.log('[Amply] Appended Amply module include to settings.gradle (no includeBuild found)');\n }\n\n gradleConfig.modResults.contents = modified;\n return gradleConfig;\n });\n\n // Add Amply native module dependency to app/build.gradle\n config = withAppBuildGradle(config, gradleConfig => {\n const contents = gradleConfig.modResults.contents;\n\n // Only add if not already present\n if (contents.includes(':amplyreactnative')) {\n console.log('[Amply] Amply module already configured in app/build.gradle');\n return gradleConfig;\n }\n\n // Add the Amply native module dependency after the first implementation statement\n const depsStart = contents.indexOf('dependencies {');\n if (depsStart !== -1) {\n const firstImplAfterDeps = contents.indexOf('implementation', depsStart);\n if (firstImplAfterDeps !== -1) {\n const lineEnd = contents.indexOf('\\n', firstImplAfterDeps);\n if (lineEnd !== -1) {\n const moduleImpl = \"\\n\\n // Amply React Native module\\n implementation project(':amplyreactnative')\";\n gradleConfig.modResults.contents =\n contents.slice(0, lineEnd) +\n moduleImpl +\n contents.slice(lineEnd);\n console.log('[Amply] Added Amply module dependency to app/build.gradle');\n }\n }\n }\n\n return gradleConfig;\n });\n\n // Register AmplyPackage in MainApplication using proper Expo API\n // This hook runs AFTER the MainApplication file is generated by Expo\n config = withMainApplication(config, async config => {\n const { contents, language } = config.modResults;\n const modified = addAmplyPackageRegistration(contents, language);\n config.modResults.contents = modified;\n return config;\n });\n\n return config;\n};\n\nexport default withAmply;\n","import type {ConfigPlugin} from '@expo/config-plugins';\nimport withAmply from './withAmply';\n\nconst plugin: ConfigPlugin<{ sdkVersion?: string }> = (config, props) =>\n withAmply(config, props);\n\nexport default plugin;\n"],"mappings":";AAAA;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,qBAAqB;AAC9B,SAAS,kBAAkB;AAE3B,IAAM,sBAAsB;AAC5B,IAAM,mBAAmB;AACzB,IAAM,+BAA+B;AAAA,EACnC,UAAU;AAAA,EACV,UAAU;AACZ;AAEA,IAAM,mCAAmC;AAAA;AAAA,mBAEtB,gBAAgB;AAAA;AAAA,yCAEM,6BAA6B,QAAQ,wBAAwB,6BAA6B,QAAQ;AAAA,yCAClG,6BAA6B,QAAQ,wBAAwB,6BAA6B,QAAQ;AAAA;AAAA;AAAA;AAK3I,IAAM,yBAAyB,+CAA+C,GAAG,sFAAsF,mBAAmB;AAE1L,SAAS,2BAA2B,UAA0B;AAC5D,MAAI,SAAS,SAAS,gBAAgB,GAAG;AACvC,WAAO;AAAA,EACT;AAEA,QAAM,oBAAoB;AAC1B,MAAI,kBAAkB,KAAK,QAAQ,GAAG;AACpC,WAAO,SAAS,QAAQ,mBAAmB,WAAS;AAClD,UAAI,MAAM,SAAS,gBAAgB,GAAG;AACpC,eAAO;AAAA,MACT;AACA,aAAO,MAAM,QAAQ,QAAQ;AAAA,EAAK,gCAAgC,OAAO;AAAA,IAC3E,CAAC;AAAA,EACH;AAGA,SAAO,GAAG,QAAQ;AAAA,gBAAmB,gCAAgC;AAAA;AACvE;AAEA,SAAS,gBAAgB,UAA0B;AACjD,MAAI,SAAS,SAAS,yBAAyB,GAAG;AAChD,WAAO;AAAA,EACT;AAEA,QAAM,oBAAoB;AAC1B,MAAI,kBAAkB,KAAK,QAAQ,GAAG;AACpC,WAAO,SAAS,QAAQ,mBAAmB,WAAS;AAClD,U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AAS,MAAM,OAAO;AACxB,kBAAQ,IAAI,2DAA2D;AAAA,QACzE;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT,CAAC;AAID,WAAS,oBAAoB,QAAQ,OAAMA,YAAU;AACnD,UAAM,EAAE,UAAU,SAAS,IAAIA,QAAO;AACtC,UAAM,WAAW,4BAA4B,UAAU,QAAQ;AAC/D,IAAAA,QAAO,WAAW,WAAW;AAC7B,WAAOA;AAAA,EACT,CAAC;AAED,SAAO;AACT;AAEA,IAAO,oBAAQ;;;ACjNf,IAAM,SAAgD,CAAC,QAAQ,UAC7D,kBAAU,QAAQ,KAAK;AAEzB,IAAO,iBAAQ;","names":["config"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../plugin/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,sBAAsB,CAAC;AAGvD,QAAA,MAAM,MAAM,EAAE,YAAY,CAAC;IAAE,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,CACxB,CAAC;AAE3B,eAAe,MAAM,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Expo Config Plugin for Amply React Native SDK
|
|
3
|
+
*
|
|
4
|
+
* The Amply React Native SDK is a TurboModule that uses react-native.config.js
|
|
5
|
+
* for autolinking in Bare React Native. For Expo apps, this plugin ensures
|
|
6
|
+
* AmplyPackage is registered in MainApplication (Android).
|
|
7
|
+
*
|
|
8
|
+
* iOS: AmplySDK is fetched automatically from CocoaPods Trunk via the podspec
|
|
9
|
+
* dependency declaration - no Podfile modifications needed.
|
|
10
|
+
*
|
|
11
|
+
* Architecture:
|
|
12
|
+
* - Bare RN: Uses react-native.config.js autolinking (fully automatic)
|
|
13
|
+
* - Expo: Uses react-native.config.js + Expo config plugin for Android registration
|
|
14
|
+
*
|
|
15
|
+
* Usage:
|
|
16
|
+
* 1. Add to app.json: "@amply/amply-react-native" in plugins array
|
|
17
|
+
* 2. Run: expo prebuild --clean
|
|
18
|
+
* 3. Run: expo start and expo run:android/ios
|
|
19
|
+
*/
|
|
20
|
+
import { ConfigPlugin } from '@expo/config-plugins';
|
|
21
|
+
type WithAmplyPluginProps = {};
|
|
22
|
+
/**
|
|
23
|
+
* Expo Config Plugin for Amply React Native SDK
|
|
24
|
+
*
|
|
25
|
+
* Registers AmplyPackage in MainApplication for Expo apps (Android).
|
|
26
|
+
* iOS uses CocoaPods Trunk for AmplySDK - no modifications needed.
|
|
27
|
+
*/
|
|
28
|
+
declare const withAmply: ConfigPlugin<WithAmplyPluginProps>;
|
|
29
|
+
export default withAmply;
|
|
30
|
+
//# sourceMappingURL=withAmply.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withAmply.d.ts","sourceRoot":"","sources":["../../../plugin/src/withAmply.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,YAAY,EAAuB,MAAM,sBAAsB,CAAC;AAEzE,KAAK,oBAAoB,GAAG,EAE3B,CAAC;AAgCF;;;;;GAKG;AACH,QAAA,MAAM,SAAS,EAAE,YAAY,CAAC,oBAAoB,CAGjD,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Expo Config Plugin for Amply React Native SDK
|
|
3
|
+
*
|
|
4
|
+
* The Amply React Native SDK is a TurboModule that uses react-native.config.js
|
|
5
|
+
* for autolinking in Bare React Native. For Expo apps, this plugin ensures
|
|
6
|
+
* AmplyPackage is registered in MainApplication (Android).
|
|
7
|
+
*
|
|
8
|
+
* iOS: AmplySDK is fetched automatically from CocoaPods Trunk via the podspec
|
|
9
|
+
* dependency declaration - no Podfile modifications needed.
|
|
10
|
+
*
|
|
11
|
+
* Architecture:
|
|
12
|
+
* - Bare RN: Uses react-native.config.js autolinking (fully automatic)
|
|
13
|
+
* - Expo: Uses react-native.config.js + Expo config plugin for Android registration
|
|
14
|
+
*
|
|
15
|
+
* Usage:
|
|
16
|
+
* 1. Add to app.json: "@amply/amply-react-native" in plugins array
|
|
17
|
+
* 2. Run: expo prebuild --clean
|
|
18
|
+
* 3. Run: expo start and expo run:android/ios
|
|
19
|
+
*/
|
|
20
|
+
import { withMainApplication } from '@expo/config-plugins';
|
|
21
|
+
/**
|
|
22
|
+
* Modifies Android MainApplication to register AmplyPackage
|
|
23
|
+
*/
|
|
24
|
+
const withAmplyAndroid = (config) => {
|
|
25
|
+
return withMainApplication(config, async (cfg) => {
|
|
26
|
+
let contents = cfg.modResults.contents;
|
|
27
|
+
// Check if AmplyPackage is already imported
|
|
28
|
+
if (!contents.includes('import tools.amply.sdk.reactnative.AmplyPackage')) {
|
|
29
|
+
// Add import after the expo imports
|
|
30
|
+
contents = contents.replace(/(import expo\.modules\.ReactNativeHostWrapper)/, `import tools.amply.sdk.reactnative.AmplyPackage\n$1`);
|
|
31
|
+
}
|
|
32
|
+
// For Kotlin syntax: packages.apply { ... }
|
|
33
|
+
// We need to add the package instance inside the apply block
|
|
34
|
+
if (!contents.includes('add(AmplyPackage())')) {
|
|
35
|
+
contents = contents.replace(/(PackageList\(this\)\.packages\.apply \{[\s\S]*?)(\/\/ add.*?)\n(\s+\})/, `$1$2\n add(AmplyPackage())\n$3`);
|
|
36
|
+
}
|
|
37
|
+
cfg.modResults.contents = contents;
|
|
38
|
+
return cfg;
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Expo Config Plugin for Amply React Native SDK
|
|
43
|
+
*
|
|
44
|
+
* Registers AmplyPackage in MainApplication for Expo apps (Android).
|
|
45
|
+
* iOS uses CocoaPods Trunk for AmplySDK - no modifications needed.
|
|
46
|
+
*/
|
|
47
|
+
const withAmply = (config) => {
|
|
48
|
+
// Apply Android modifications
|
|
49
|
+
return withAmplyAndroid(config);
|
|
50
|
+
};
|
|
51
|
+
export default withAmply;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ConfigPlugin } from '@expo/config-plugins';
|
|
2
|
+
type WithAmplyPluginProps = {
|
|
3
|
+
sdkVersion?: string;
|
|
4
|
+
/**
|
|
5
|
+
* Optional escape hatch for internal builds that still rely on GitHub Packages.
|
|
6
|
+
* Public installs resolve from Maven Central without any additional repositories.
|
|
7
|
+
*/
|
|
8
|
+
useGithubFallbackRepo?: boolean;
|
|
9
|
+
};
|
|
10
|
+
declare const withAmply: ConfigPlugin<WithAmplyPluginProps>;
|
|
11
|
+
export default withAmply;
|
|
12
|
+
//# sourceMappingURL=withAmply.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withAmply.d.ts","sourceRoot":"","sources":["../../plugin/withAmply.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EAOb,MAAM,sBAAsB,CAAC;AA4D9B,KAAK,oBAAoB,GAAG;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC,CAAC;AAsCF,QAAA,MAAM,SAAS,EAAE,YAAY,CAAC,oBAAoB,CAiGjD,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../../src/__tests__/index.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import * as Amply from '../index';
|
|
2
|
+
import { __setNativeModule } from '../nativeModule';
|
|
3
|
+
const mockNativeModule = {
|
|
4
|
+
initialize: jest.fn(),
|
|
5
|
+
isInitialized: jest.fn(() => true),
|
|
6
|
+
track: jest.fn(),
|
|
7
|
+
getRecentEvents: jest.fn(),
|
|
8
|
+
getDataSetSnapshot: jest.fn(),
|
|
9
|
+
registerDeepLinkListener: jest.fn(),
|
|
10
|
+
addListener: jest.fn(),
|
|
11
|
+
removeListeners: jest.fn(),
|
|
12
|
+
onSystemEvent: jest.fn(),
|
|
13
|
+
onDeepLink: jest.fn(),
|
|
14
|
+
};
|
|
15
|
+
describe('Amply JS API', () => {
|
|
16
|
+
afterEach(() => {
|
|
17
|
+
jest.clearAllMocks();
|
|
18
|
+
__setNativeModule(null);
|
|
19
|
+
});
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
__setNativeModule(mockNativeModule);
|
|
22
|
+
});
|
|
23
|
+
it('initializes the native module', async () => {
|
|
24
|
+
await Amply.initialize({ appId: 'id', apiKeyPublic: 'public' });
|
|
25
|
+
expect(mockNativeModule.initialize).toHaveBeenCalledWith(expect.objectContaining({ appId: 'id', apiKeyPublic: 'public' }));
|
|
26
|
+
});
|
|
27
|
+
it('tracks events through the native layer', async () => {
|
|
28
|
+
await Amply.track({ name: 'Test Event', properties: { foo: 'bar' } });
|
|
29
|
+
expect(mockNativeModule.track).toHaveBeenCalledWith({
|
|
30
|
+
name: 'Test Event',
|
|
31
|
+
properties: { foo: 'bar' },
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
it('reads recent events', async () => {
|
|
35
|
+
const events = [{ name: 'e1' }];
|
|
36
|
+
mockNativeModule.getRecentEvents.mockResolvedValueOnce(events);
|
|
37
|
+
const result = await Amply.getRecentEvents(3);
|
|
38
|
+
expect(mockNativeModule.getRecentEvents).toHaveBeenCalledWith(3);
|
|
39
|
+
expect(result).toBe(events);
|
|
40
|
+
});
|
|
41
|
+
it('requests dataset snapshots', async () => {
|
|
42
|
+
const snapshot = { foo: 'bar' };
|
|
43
|
+
mockNativeModule.getDataSetSnapshot.mockResolvedValueOnce(snapshot);
|
|
44
|
+
const type = { kind: '@device' };
|
|
45
|
+
const result = await Amply.getDataSetSnapshot(type);
|
|
46
|
+
expect(mockNativeModule.getDataSetSnapshot).toHaveBeenCalledWith(type);
|
|
47
|
+
expect(result).toBe(snapshot);
|
|
48
|
+
});
|
|
49
|
+
it('subscribes to system events through the TurboModule emitter', async () => {
|
|
50
|
+
const remove = jest.fn();
|
|
51
|
+
mockNativeModule.onSystemEvent.mockReturnValueOnce({ remove });
|
|
52
|
+
const listener = jest.fn();
|
|
53
|
+
const unsubscribe = await Amply.addSystemEventListener(listener);
|
|
54
|
+
expect(mockNativeModule.onSystemEvent).toHaveBeenCalledWith(listener);
|
|
55
|
+
unsubscribe();
|
|
56
|
+
expect(remove).toHaveBeenCalledTimes(1);
|
|
57
|
+
});
|
|
58
|
+
it('registers deep links once and subscribes via the TurboModule emitter', async () => {
|
|
59
|
+
const remove = jest.fn();
|
|
60
|
+
mockNativeModule.onDeepLink.mockReturnValue({ remove });
|
|
61
|
+
const listener = jest.fn();
|
|
62
|
+
const unsubscribe = await Amply.addDeepLinkListener(listener);
|
|
63
|
+
expect(mockNativeModule.registerDeepLinkListener).toHaveBeenCalledTimes(1);
|
|
64
|
+
expect(mockNativeModule.onDeepLink).toHaveBeenCalledWith(listener);
|
|
65
|
+
await Amply.addDeepLinkListener(() => { });
|
|
66
|
+
expect(mockNativeModule.registerDeepLinkListener).toHaveBeenCalledTimes(1);
|
|
67
|
+
unsubscribe();
|
|
68
|
+
expect(remove).toHaveBeenCalledTimes(1);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { EventRecord } from '../nativeSpecs/NativeAmplyModule';
|
|
2
|
+
export type UseAmplySystemEventsOptions = {
|
|
3
|
+
maxEntries?: number;
|
|
4
|
+
dedupe?: boolean;
|
|
5
|
+
onEvent?: (event: EventRecord) => void;
|
|
6
|
+
};
|
|
7
|
+
export type UseAmplySystemEventsResult = {
|
|
8
|
+
events: EventRecord[];
|
|
9
|
+
reset: () => void;
|
|
10
|
+
};
|
|
11
|
+
export declare function useAmplySystemEvents(options?: UseAmplySystemEventsOptions): UseAmplySystemEventsResult;
|
|
12
|
+
//# sourceMappingURL=useAmplySystemEvents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAmplySystemEvents.d.ts","sourceRoot":"","sources":["../../../src/hooks/useAmplySystemEvents.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,kCAAkC,CAAC;AAGlE,MAAM,MAAM,2BAA2B,GAAG;IACxC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,MAAM,EAAE,WAAW,EAAE,CAAC;IACtB,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB,CAAC;AAEF,wBAAgB,oBAAoB,CAClC,OAAO,GAAE,2BAAgC,GACxC,0BAA0B,CAyD5B"}
|