@oxy.so/app-preset 1.0.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.
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Expo Config Plugin: withOxyAppPreset
3
+ *
4
+ * The single config-plugin entry every Oxy app adds in place of the four
5
+ * copy-pasted plugin entries (`withSharedUserId`, keychain entitlement,
6
+ * `expo-build-properties`, `@oxy.so/services/plugins/withSharedIdentityReader`).
7
+ *
8
+ * In app.config.js / app.json:
9
+ *
10
+ * plugins: [
11
+ * // …app-specific plugins…
12
+ * ['@oxy.so/app-preset', {}],
13
+ * ]
14
+ *
15
+ * Each piece is individually disableable by passing its option as `false`:
16
+ *
17
+ * ['@oxy.so/app-preset', {
18
+ * sharedUserId: 'so.oxy.shared', // false → skip android:sharedUserId
19
+ * keychainGroup: 'group.so.oxy.shared', // false → skip iOS keychain entitlement
20
+ * ios: { deploymentTarget: '17.0' }, // false → skip iOS build properties
21
+ * android: { targetSdkVersion: 34 }, // false → skip Android build properties
22
+ * sharedIdentityReader: true, // false → skip @oxy.so/services reader plugin
23
+ * }]
24
+ *
25
+ * @param {import('expo/config').ExpoConfig} config
26
+ * @param {object} [options]
27
+ * @param {string|false} [options.sharedUserId='so.oxy.shared']
28
+ * @param {string|false} [options.keychainGroup='group.so.oxy.shared']
29
+ * @param {object|false} [options.ios]
30
+ * @param {object|false} [options.android]
31
+ * @param {boolean} [options.sharedIdentityReader=true]
32
+ */
33
+ const withSharedUserId = require('./withSharedUserId');
34
+ const withOxyKeychain = require('./withOxyKeychain');
35
+ const withOxyBuildProperties = require('./withOxyBuildProperties');
36
+
37
+ module.exports = function withOxyAppPreset(config, options = {}) {
38
+ const {
39
+ sharedUserId = 'so.oxy.shared',
40
+ keychainGroup = 'group.so.oxy.shared',
41
+ ios = {},
42
+ android = {},
43
+ sharedIdentityReader = true,
44
+ } = options;
45
+
46
+ let next = config;
47
+
48
+ if (sharedUserId !== false) {
49
+ next = withSharedUserId(next, sharedUserId);
50
+ }
51
+
52
+ if (keychainGroup !== false) {
53
+ next = withOxyKeychain(next, keychainGroup);
54
+ }
55
+
56
+ if (ios !== false || android !== false) {
57
+ next = withOxyBuildProperties(next, { ios, android });
58
+ }
59
+
60
+ if (sharedIdentityReader !== false) {
61
+ let withSharedIdentityReader;
62
+ try {
63
+ withSharedIdentityReader = require('@oxy.so/services/plugins/withSharedIdentityReader');
64
+ } catch (error) {
65
+ throw new Error(
66
+ "[@oxy.so/app-preset] sharedIdentityReader is enabled but the peer dependency '@oxy.so/services' "
67
+ + 'is not installed. Install it, or pass `{ sharedIdentityReader: false }` to the preset.',
68
+ );
69
+ }
70
+ next = withSharedIdentityReader(next);
71
+ }
72
+
73
+ return next;
74
+ };
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Expo Config Plugin: withOxyBuildProperties
3
+ *
4
+ * Wraps `expo-build-properties` with the native build defaults every Oxy app
5
+ * ships with — iOS deployment target and the Android SDK / minification knobs —
6
+ * so apps stop copy-pasting the same `expo-build-properties` block. Caller
7
+ * overrides deep-merge over these defaults.
8
+ *
9
+ * `expo-build-properties` is required lazily (it is an optional peer): a missing
10
+ * install throws a clear, actionable error only when this plugin actually runs
11
+ * with build properties enabled.
12
+ *
13
+ * @param {import('expo/config').ExpoConfig} config
14
+ * @param {object} [options]
15
+ * @param {object|false} [options.ios] iOS overrides, or `false` to skip iOS.
16
+ * @param {object|false} [options.android] Android overrides, or `false` to skip Android.
17
+ */
18
+ const DEFAULTS = {
19
+ ios: {
20
+ deploymentTarget: '16.4',
21
+ },
22
+ android: {
23
+ compileSdkVersion: 36,
24
+ targetSdkVersion: 35,
25
+ buildToolsVersion: '36.0.0',
26
+ enableProguardInReleaseBuilds: true,
27
+ enableShrinkResourcesInReleaseBuilds: true,
28
+ useLegacyPackaging: false,
29
+ },
30
+ };
31
+
32
+ function isPlainObject(value) {
33
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
34
+ }
35
+
36
+ function deepMerge(base, override) {
37
+ if (!isPlainObject(override)) {
38
+ return base;
39
+ }
40
+ const result = { ...base };
41
+ for (const [key, value] of Object.entries(override)) {
42
+ result[key] = isPlainObject(value) && isPlainObject(result[key])
43
+ ? deepMerge(result[key], value)
44
+ : value;
45
+ }
46
+ return result;
47
+ }
48
+
49
+ function resolveBuildPropertiesPlugin() {
50
+ let mod;
51
+ try {
52
+ mod = require('expo-build-properties');
53
+ } catch (error) {
54
+ throw new Error(
55
+ "[@oxy.so/app-preset] withOxyBuildProperties requires the peer dependency 'expo-build-properties'. "
56
+ + "Install it with `npx expo install expo-build-properties`, or disable it by passing "
57
+ + '`{ ios: false, android: false }` to the preset.',
58
+ );
59
+ }
60
+ const plugin = typeof mod === 'function' ? mod : mod.withBuildProperties || mod.default;
61
+ if (typeof plugin !== 'function') {
62
+ throw new Error(
63
+ "[@oxy.so/app-preset] Could not resolve the 'expo-build-properties' config plugin from the installed package.",
64
+ );
65
+ }
66
+ return plugin;
67
+ }
68
+
69
+ module.exports = function withOxyBuildProperties(config, options = {}) {
70
+ const { ios = {}, android = {} } = options;
71
+
72
+ if (ios === false && android === false) {
73
+ return config;
74
+ }
75
+
76
+ const props = {};
77
+ if (ios !== false) {
78
+ props.ios = deepMerge(DEFAULTS.ios, ios);
79
+ }
80
+ if (android !== false) {
81
+ props.android = deepMerge(DEFAULTS.android, android);
82
+ }
83
+
84
+ const withBuildProperties = resolveBuildPropertiesPlugin();
85
+ return withBuildProperties(config, props);
86
+ };
87
+
88
+ module.exports.DEFAULTS = DEFAULTS;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Expo Config Plugin: withOxyKeychain
3
+ *
4
+ * Adds an iOS `keychain-access-groups` entitlement so Oxy apps signed with the
5
+ * same Team ID can share Keychain items — the iOS half of "sign in once, use
6
+ * everywhere" (the Android half is withSharedUserId + the shared-identity
7
+ * native module). The group is prefixed with `$(AppIdentifierPrefix)` so Xcode
8
+ * expands it to the Team ID at build time.
9
+ *
10
+ * Merge-not-overwrite: if the app (or another plugin, e.g. expo-build-properties)
11
+ * already declared keychain-access-groups, the Oxy group is appended without
12
+ * dropping the existing entries.
13
+ *
14
+ * @param {import('expo/config').ExpoConfig} config
15
+ * @param {string} [keychainGroup='group.so.oxy.shared'] The keychain group,
16
+ * without the `$(AppIdentifierPrefix)` prefix.
17
+ */
18
+ const { withEntitlementsPlist } = require('expo/config-plugins');
19
+
20
+ module.exports = function withOxyKeychain(config, keychainGroup = 'group.so.oxy.shared') {
21
+ const entry = `$(AppIdentifierPrefix)${keychainGroup}`;
22
+
23
+ return withEntitlementsPlist(config, (config) => {
24
+ const key = 'keychain-access-groups';
25
+ const existing = config.modResults[key];
26
+ const groups = Array.isArray(existing) ? [...existing] : [];
27
+
28
+ if (!groups.includes(entry)) {
29
+ groups.push(entry);
30
+ }
31
+
32
+ config.modResults[key] = groups;
33
+ return config;
34
+ });
35
+ };
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Expo Config Plugin: withOxyUpdates
3
+ *
4
+ * Points `expo-updates` at the self-hosted **Oxy Updates** server (`/updates/v1`
5
+ * in oxy-api) and wires the ecosystem code-signing certificate, so an app opts
6
+ * into OTA with one plugin entry plus its own client id instead of a hand-written
7
+ * `updates` block, a per-repo certificate copy, and a per-repo runtime-version
8
+ * policy that drift apart.
9
+ *
10
+ * In app.config.js:
11
+ *
12
+ * plugins: [
13
+ * 'expo-updates',
14
+ * ['@oxy.so/app-preset/plugin/withOxyUpdates', { clientId: OXY_CLIENT_ID }],
15
+ * ]
16
+ *
17
+ * What it sets:
18
+ * - `updates.url` = `<apiOrigin>/updates/v1/apps/<clientId>/manifest`
19
+ * - `updates.requestHeaders['expo-channel-name']` = the release channel
20
+ * - `updates.codeSigningCertificate` + `updates.codeSigningMetadata` (see below)
21
+ * - `runtimeVersion` = `{ policy: 'appVersion' }`
22
+ *
23
+ * **runtimeVersion policy: `appVersion`, deliberately.** It is the only policy the
24
+ * whole Oxy toolchain can resolve end to end. `oxy-ship` derives the publish
25
+ * runtime from `expo config --json --type public`, and `fingerprint` resolves
26
+ * there to the sentinel `file:fingerprint` (it is computed at BUILD time, not at
27
+ * config time), so a fingerprint app would have to pass `--runtime-version` by
28
+ * hand on every publish. The consequence is a rule to keep: **the app `version`
29
+ * is the OTA compatibility boundary.** Bump it whenever native code changes.
30
+ * Installs on the old `version` then correctly stop receiving updates published
31
+ * under the new one, whereas installs on an UNBUMPED version would receive JS
32
+ * that assumes native modules they do not have.
33
+ *
34
+ * **Code signing.** The Oxy Updates server signs manifests with
35
+ * `rsa-v1_5-sha256` under keyid `main` (`CODE_SIGNING_ALG` / `CODE_SIGNING_KEY_ID`
36
+ * in oxy-api's `services/updates/signing.service.ts`); those two values are
37
+ * mirrored here and must be changed together. The matching PUBLIC certificate is
38
+ * a single ecosystem-wide file shipped inside this package
39
+ * (`certs/oxy-updates-code-signing.pem`) rather than copied into every app repo,
40
+ * so a key rotation is one preset bump instead of thirteen.
41
+ *
42
+ * Until that certificate is committed the plugin wires the update URL but NOT
43
+ * signature verification, and warns on both platforms. A binary built in that
44
+ * state can never verify a manifest signature for its whole lifetime, because the
45
+ * certificate is baked into the native build, so **do not ship a store build of
46
+ * an OTA-enabled app before the certificate exists.** Pass
47
+ * `{ codeSigning: 'require' }` to turn that warning into a hard build failure.
48
+ *
49
+ * @param {import('expo/config').ExpoConfig} config
50
+ * @param {object} options
51
+ * @param {string} options.clientId Registered `ApplicationCredential` publicKey
52
+ * (`oxy_dk_...`) identifying this app to the update server. Required.
53
+ * @param {string} [options.apiOrigin='https://api.oxy.so'] Origin serving `/updates/v1`.
54
+ * @param {string} [options.channel='production'] Release channel this binary tracks.
55
+ * @param {'auto'|'require'|false} [options.codeSigning='auto'] `auto` wires
56
+ * signing when the certificate is present and warns when it is not; `require`
57
+ * throws when it is absent; `false` skips signing entirely.
58
+ * @param {string} [options.certificatePath] Absolute path to a different
59
+ * certificate than the bundled one. Normally unset; it exists for the overlap
60
+ * window of a key rotation, where one binary has to trust an incoming
61
+ * certificate the rest of the ecosystem has not moved to yet.
62
+ * @param {'appVersion'|'nativeVersion'|'sdkVersion'|'fingerprint'|false} [options.runtimeVersionPolicy='appVersion']
63
+ * `false` leaves whatever the app declared.
64
+ */
65
+ const fs = require('fs');
66
+ const path = require('path');
67
+ const { WarningAggregator } = require('expo/config-plugins');
68
+
69
+ /** Origin of the Oxy Updates server. `updates.oxy.so` does not exist; oxy-api serves it. */
70
+ const DEFAULT_API_ORIGIN = 'https://api.oxy.so';
71
+
72
+ /** Channel a binary tracks unless it opts into a preview track. */
73
+ const DEFAULT_CHANNEL = 'production';
74
+
75
+ /** Mirrors `CODE_SIGNING_KEY_ID` in oxy-api `services/updates/signing.service.ts`. */
76
+ const CODE_SIGNING_KEY_ID = 'main';
77
+
78
+ /** Mirrors `CODE_SIGNING_ALG` in oxy-api `services/updates/signing.service.ts`. */
79
+ const CODE_SIGNING_ALG = 'rsa-v1_5-sha256';
80
+
81
+ /**
82
+ * The one ecosystem-wide PUBLIC code-signing certificate, generated together with
83
+ * the server's private key by oxy-api's `scripts/generate-updates-code-signing.ts`.
84
+ */
85
+ const CERTIFICATE_PATH = path.join(__dirname, '..', 'certs', 'oxy-updates-code-signing.pem');
86
+
87
+ /** Plugin name used in build warnings and errors. */
88
+ const PLUGIN_NAME = '@oxy.so/app-preset/plugin/withOxyUpdates';
89
+
90
+ module.exports = function withOxyUpdates(config, options = {}) {
91
+ const {
92
+ clientId,
93
+ apiOrigin = DEFAULT_API_ORIGIN,
94
+ channel = DEFAULT_CHANNEL,
95
+ codeSigning = 'auto',
96
+ certificatePath = CERTIFICATE_PATH,
97
+ runtimeVersionPolicy = 'appVersion',
98
+ } = options;
99
+
100
+ if (typeof clientId !== 'string' || clientId.trim().length === 0) {
101
+ throw new Error(
102
+ `[${PLUGIN_NAME}] a non-empty \`clientId\` is required. Pass this app's registered `
103
+ + 'ApplicationCredential publicKey (oxy_dk_...), normally from an '
104
+ + 'EXPO_PUBLIC_OXY_CLIENT_ID-backed constant.',
105
+ );
106
+ }
107
+
108
+ // Trimmed with a loop rather than a `/\/+$/` regex: an anchored repetition is
109
+ // the polynomial-ReDoS shape CodeQL flags (js/polynomial-redos), and this is
110
+ // linear and just as clear.
111
+ let origin = apiOrigin;
112
+ while (origin.endsWith('/')) {
113
+ origin = origin.slice(0, -1);
114
+ }
115
+
116
+ const updates = { ...config.updates };
117
+ updates.url = `${origin}/updates/v1/apps/${clientId}/manifest`;
118
+ updates.requestHeaders = { ...updates.requestHeaders, 'expo-channel-name': channel };
119
+
120
+ if (codeSigning !== false) {
121
+ if (fs.existsSync(certificatePath)) {
122
+ const projectRoot = config._internal?.projectRoot;
123
+ if (typeof projectRoot !== 'string') {
124
+ throw new Error(
125
+ `[${PLUGIN_NAME}] could not resolve the project root from the Expo config, so the `
126
+ + 'code-signing certificate path cannot be made project-relative (expo-updates joins it '
127
+ + 'onto the project root). Upgrade @expo/config, or pass `{ codeSigning: false }`.',
128
+ );
129
+ }
130
+ // expo-updates reads this as `path.join(projectRoot, value)`, so it must be
131
+ // relative: an absolute path would be appended to the project root.
132
+ updates.codeSigningCertificate = path.relative(projectRoot, certificatePath);
133
+ updates.codeSigningMetadata = { keyid: CODE_SIGNING_KEY_ID, alg: CODE_SIGNING_ALG };
134
+ } else if (codeSigning === 'require') {
135
+ throw new Error(
136
+ `[${PLUGIN_NAME}] code signing is required but the Oxy Updates certificate is missing at `
137
+ + `${certificatePath}. Generate the ecosystem keypair with oxy-api's `
138
+ + '`bun scripts/generate-updates-code-signing.ts`, commit the certificate into '
139
+ + '@oxy.so/app-preset, and set the private key as UPDATES_CODE_SIGNING_PRIVATE_KEY on oxy-api.',
140
+ );
141
+ } else {
142
+ const warning =
143
+ 'The Oxy Updates code-signing certificate is not present in @oxy.so/app-preset, so this build '
144
+ + 'will accept UNSIGNED update manifests for its entire lifetime (the certificate is baked in '
145
+ + 'at build time). Do not ship this binary to a store. See the app-preset README, section '
146
+ + '"Oxy Updates (OTA)".';
147
+ WarningAggregator.addWarningForPlatform('android', PLUGIN_NAME, warning);
148
+ WarningAggregator.addWarningForPlatform('ios', PLUGIN_NAME, warning);
149
+ }
150
+ }
151
+
152
+ const next = { ...config, updates };
153
+
154
+ if (runtimeVersionPolicy !== false) {
155
+ next.runtimeVersion = { policy: runtimeVersionPolicy };
156
+ }
157
+
158
+ return next;
159
+ };
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Expo Config Plugin: withSharedUserId
3
+ *
4
+ * Adds android:sharedUserId to AndroidManifest.xml to enable cross-app data
5
+ * sharing between Oxy apps (Mention, Homiio, accounts, Commons, …).
6
+ *
7
+ * This allows:
8
+ * - Shared cryptographic identity storage
9
+ * - Cross-app authentication (sign in once, use everywhere)
10
+ * - Shared session tokens
11
+ *
12
+ * IMPORTANT:
13
+ * - All Oxy apps MUST use the same sharedUserId: "so.oxy.shared"
14
+ * - Apps MUST be signed with the same certificate
15
+ * - Cannot change sharedUserId after publishing (requires reinstall)
16
+ *
17
+ * @see https://developer.android.com/guide/topics/manifest/manifest-element#uid
18
+ *
19
+ * @param {import('expo/config').ExpoConfig} config
20
+ * @param {string} [sharedUserId='so.oxy.shared'] The android:sharedUserId value.
21
+ */
22
+ const { withAndroidManifest } = require('expo/config-plugins');
23
+
24
+ module.exports = function withSharedUserId(config, sharedUserId = 'so.oxy.shared') {
25
+ return withAndroidManifest(config, async (config) => {
26
+ const androidManifest = config.modResults.manifest;
27
+
28
+ // Add sharedUserId to the manifest root element
29
+ androidManifest.$ = {
30
+ ...androidManifest.$,
31
+ 'android:sharedUserId': sharedUserId,
32
+ };
33
+
34
+ return config;
35
+ });
36
+ };
@@ -0,0 +1,11 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "//": "@oxy.so/app-preset — Node/Bun backend TypeScript config. Compiled with tsc to dist/ (CommonJS) and THAT emitted output is what the Docker/ECS image runs — module format and emit layout are a runtime contract. Overrides the Oxy base only where this becomes an emitting CommonJS Node service. Consumers set their own `rootDir`/`outDir`/`include` (and `paths` to resolve workspace deps from source during type-check).",
4
+ "extends": "./base.json",
5
+ "compilerOptions": {
6
+ "module": "commonjs",
7
+ "moduleResolution": "node",
8
+ "noEmit": false,
9
+ "declaration": true
10
+ }
11
+ }
@@ -0,0 +1,31 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "//": "@oxy.so/app-preset — shared, runtime-neutral TypeScript base. The strict/safety defaults every Oxy package inherits. This base is TYPE-CHECK ONLY (noEmit): the frontend (tsconfig/frontend.json) and emitting Node packages (tsconfig/backend.json) override module/target/emit for their runtime. Does NOT extend expo/tsconfig.base — that sets customConditions:[\"react-native\"], only valid with bundler/nodenext resolution, which would break the CJS/node packages. The frontend config layers the Expo base on top where bundler resolution is in effect.",
4
+ "compilerOptions": {
5
+ "target": "ES2020",
6
+ "lib": ["ES2020"],
7
+ "module": "ES2020",
8
+ "moduleResolution": "bundler",
9
+
10
+ "strict": true,
11
+ "esModuleInterop": true,
12
+ "allowSyntheticDefaultImports": true,
13
+ "skipLibCheck": true,
14
+ "forceConsistentCasingInFileNames": true,
15
+ "resolveJsonModule": true,
16
+
17
+ "composite": true,
18
+ "declaration": true,
19
+ "declarationMap": true,
20
+ "sourceMap": true,
21
+
22
+ "noEmit": true
23
+ },
24
+ "exclude": [
25
+ "node_modules",
26
+ "**/node_modules",
27
+ "**/dist",
28
+ "**/build",
29
+ "**/.expo"
30
+ ]
31
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "//": "@oxy.so/app-preset — Expo / React Native frontend TypeScript config. Not compiled by tsc (Metro/Expo bundles the source); tsc is only for type-checking. Extends BOTH the Oxy base (strict/composite defaults) AND expo/tsconfig.base (React-Native JSX, customConditions:[\"react-native\"], bundler resolution). Later entries win, so the Expo base overrides the Oxy base where they differ; the explicit overrides below win over both. Consumers extend this and add their own `paths` (e.g. \"@/*\") + `include`.",
4
+ "extends": ["./base.json", "expo/tsconfig.base"],
5
+ "compilerOptions": {
6
+ "jsx": "react-native",
7
+ "strict": true,
8
+ "composite": true,
9
+ "noEmit": false
10
+ }
11
+ }