@wrelik/config 0.1.0 → 0.2.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/.turbo/turbo-build.log +26 -0
- package/CHANGELOG.md +12 -0
- package/dist/chunk-DKD5KYQQ.mjs +20 -0
- package/dist/index.d.mts +11 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +79 -0
- package/dist/index.mjs +28 -0
- package/dist/react-native.d.mts +15 -0
- package/dist/react-native.d.ts +15 -0
- package/dist/react-native.js +65 -0
- package/dist/react-native.mjs +25 -0
- package/dist/shared-D4fnBEvF.d.mts +16 -0
- package/dist/shared-D4fnBEvF.d.ts +16 -0
- package/package.json +17 -4
- package/src/index.ts +7 -5
- package/src/react-native.test.ts +32 -0
- package/src/react-native.ts +25 -0
- package/src/shared.ts +19 -0
- package/tsconfig.json +1 -1
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
|
|
2
|
+
> @wrelik/config@0.2.0 build /home/runner/work/wrelik-kit/wrelik-kit/packages/config
|
|
3
|
+
> tsup src/index.ts src/react-native.ts --format cjs,esm --dts --clean
|
|
4
|
+
|
|
5
|
+
[34mCLI[39m Building entry: src/index.ts, src/react-native.ts
|
|
6
|
+
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
|
+
[34mCLI[39m tsup v8.5.1
|
|
8
|
+
[34mCLI[39m Target: es2022
|
|
9
|
+
[34mCLI[39m Cleaning output folder
|
|
10
|
+
[34mCJS[39m Build start
|
|
11
|
+
[34mESM[39m Build start
|
|
12
|
+
[32mCJS[39m [1mdist/react-native.js [22m[32m2.36 KB[39m
|
|
13
|
+
[32mCJS[39m [1mdist/index.js [22m[32m3.10 KB[39m
|
|
14
|
+
[32mCJS[39m ⚡️ Build success in 59ms
|
|
15
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m693.00 B[39m
|
|
16
|
+
[32mESM[39m [1mdist/chunk-DKD5KYQQ.mjs [22m[32m675.00 B[39m
|
|
17
|
+
[32mESM[39m [1mdist/react-native.mjs [22m[32m599.00 B[39m
|
|
18
|
+
[32mESM[39m ⚡️ Build success in 59ms
|
|
19
|
+
[34mDTS[39m Build start
|
|
20
|
+
[32mDTS[39m ⚡️ Build success in 3287ms
|
|
21
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m536.00 B[39m
|
|
22
|
+
[32mDTS[39m [1mdist/react-native.d.ts [22m[32m892.00 B[39m
|
|
23
|
+
[32mDTS[39m [1mdist/shared-D4fnBEvF.d.ts [22m[32m670.00 B[39m
|
|
24
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m537.00 B[39m
|
|
25
|
+
[32mDTS[39m [1mdist/react-native.d.mts [22m[32m893.00 B[39m
|
|
26
|
+
[32mDTS[39m [1mdist/shared-D4fnBEvF.d.mts [22m[32m670.00 B[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @wrelik/config
|
|
2
2
|
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- a38ebcb: Add React Native / Expo support and enforce server-only boundaries.
|
|
8
|
+
|
|
9
|
+
## 0.1.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Update publishConfig to access:public for all packages.
|
|
14
|
+
|
|
3
15
|
## 0.1.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// src/shared.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
var commonSchema = {
|
|
4
|
+
NODE_ENV: z.enum(["development", "test", "production"]).default("development").optional()
|
|
5
|
+
};
|
|
6
|
+
var clientSchema = {
|
|
7
|
+
EXPO_PUBLIC_APP_NAME: z.string().default("DRX App"),
|
|
8
|
+
EXPO_PUBLIC_APP_ENV: z.enum(["development", "staging", "production"]).default("development"),
|
|
9
|
+
EXPO_PUBLIC_API_URL: z.string().url().optional(),
|
|
10
|
+
// Vendors
|
|
11
|
+
EXPO_PUBLIC_POSTHOG_KEY: z.string().optional(),
|
|
12
|
+
EXPO_PUBLIC_POSTHOG_HOST: z.string().default("https://app.posthog.com"),
|
|
13
|
+
EXPO_PUBLIC_SENTRY_DSN: z.string().optional(),
|
|
14
|
+
EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY: z.string().optional()
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export {
|
|
18
|
+
commonSchema,
|
|
19
|
+
clientSchema
|
|
20
|
+
};
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export { c as clientSchema, a as commonSchema } from './shared-D4fnBEvF.mjs';
|
|
3
|
+
|
|
4
|
+
declare function createEnv<T extends z.ZodRawShape>(schema: T): z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
|
|
5
|
+
NODE_ENV: z.ZodOptional<z.ZodDefault<z.ZodEnum<["development", "test", "production"]>>>;
|
|
6
|
+
} & T>, any> extends infer T_1 ? { [k in keyof T_1]: T_1[k]; } : never;
|
|
7
|
+
declare function loadServerConfig(): {
|
|
8
|
+
NODE_ENV?: "development" | "test" | "production" | undefined;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { createEnv, loadServerConfig };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export { c as clientSchema, a as commonSchema } from './shared-D4fnBEvF.js';
|
|
3
|
+
|
|
4
|
+
declare function createEnv<T extends z.ZodRawShape>(schema: T): z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
|
|
5
|
+
NODE_ENV: z.ZodOptional<z.ZodDefault<z.ZodEnum<["development", "test", "production"]>>>;
|
|
6
|
+
} & T>, any> extends infer T_1 ? { [k in keyof T_1]: T_1[k]; } : never;
|
|
7
|
+
declare function loadServerConfig(): {
|
|
8
|
+
NODE_ENV?: "development" | "test" | "production" | undefined;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { createEnv, loadServerConfig };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
clientSchema: () => clientSchema,
|
|
34
|
+
commonSchema: () => commonSchema,
|
|
35
|
+
createEnv: () => createEnv,
|
|
36
|
+
loadServerConfig: () => loadServerConfig
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(index_exports);
|
|
39
|
+
var import_zod2 = require("zod");
|
|
40
|
+
var import_dotenv = __toESM(require("dotenv"));
|
|
41
|
+
var import_path = __toESM(require("path"));
|
|
42
|
+
|
|
43
|
+
// src/shared.ts
|
|
44
|
+
var import_zod = require("zod");
|
|
45
|
+
var commonSchema = {
|
|
46
|
+
NODE_ENV: import_zod.z.enum(["development", "test", "production"]).default("development").optional()
|
|
47
|
+
};
|
|
48
|
+
var clientSchema = {
|
|
49
|
+
EXPO_PUBLIC_APP_NAME: import_zod.z.string().default("DRX App"),
|
|
50
|
+
EXPO_PUBLIC_APP_ENV: import_zod.z.enum(["development", "staging", "production"]).default("development"),
|
|
51
|
+
EXPO_PUBLIC_API_URL: import_zod.z.string().url().optional(),
|
|
52
|
+
// Vendors
|
|
53
|
+
EXPO_PUBLIC_POSTHOG_KEY: import_zod.z.string().optional(),
|
|
54
|
+
EXPO_PUBLIC_POSTHOG_HOST: import_zod.z.string().default("https://app.posthog.com"),
|
|
55
|
+
EXPO_PUBLIC_SENTRY_DSN: import_zod.z.string().optional(),
|
|
56
|
+
EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY: import_zod.z.string().optional()
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// src/index.ts
|
|
60
|
+
import_dotenv.default.config({ path: import_path.default.resolve(process.cwd(), ".env") });
|
|
61
|
+
function createEnv(schema) {
|
|
62
|
+
const envSchema = import_zod2.z.object({ ...commonSchema, ...schema });
|
|
63
|
+
const result = envSchema.safeParse(process.env);
|
|
64
|
+
if (!result.success) {
|
|
65
|
+
console.error("\u274C Invalid environment variables:", result.error.format());
|
|
66
|
+
throw new Error("Invalid environment variables");
|
|
67
|
+
}
|
|
68
|
+
return result.data;
|
|
69
|
+
}
|
|
70
|
+
function loadServerConfig() {
|
|
71
|
+
return createEnv({});
|
|
72
|
+
}
|
|
73
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
74
|
+
0 && (module.exports = {
|
|
75
|
+
clientSchema,
|
|
76
|
+
commonSchema,
|
|
77
|
+
createEnv,
|
|
78
|
+
loadServerConfig
|
|
79
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {
|
|
2
|
+
clientSchema,
|
|
3
|
+
commonSchema
|
|
4
|
+
} from "./chunk-DKD5KYQQ.mjs";
|
|
5
|
+
|
|
6
|
+
// src/index.ts
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
import dotenv from "dotenv";
|
|
9
|
+
import path from "path";
|
|
10
|
+
dotenv.config({ path: path.resolve(process.cwd(), ".env") });
|
|
11
|
+
function createEnv(schema) {
|
|
12
|
+
const envSchema = z.object({ ...commonSchema, ...schema });
|
|
13
|
+
const result = envSchema.safeParse(process.env);
|
|
14
|
+
if (!result.success) {
|
|
15
|
+
console.error("\u274C Invalid environment variables:", result.error.format());
|
|
16
|
+
throw new Error("Invalid environment variables");
|
|
17
|
+
}
|
|
18
|
+
return result.data;
|
|
19
|
+
}
|
|
20
|
+
function loadServerConfig() {
|
|
21
|
+
return createEnv({});
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
clientSchema,
|
|
25
|
+
commonSchema,
|
|
26
|
+
createEnv,
|
|
27
|
+
loadServerConfig
|
|
28
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export { c as clientSchema, a as commonSchema } from './shared-D4fnBEvF.mjs';
|
|
3
|
+
|
|
4
|
+
declare function loadClientConfig<T extends z.ZodRawShape>(extraSchema?: T, env?: Record<string, any>): z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
|
|
5
|
+
EXPO_PUBLIC_APP_NAME: z.ZodDefault<z.ZodString>;
|
|
6
|
+
EXPO_PUBLIC_APP_ENV: z.ZodDefault<z.ZodEnum<["development", "staging", "production"]>>;
|
|
7
|
+
EXPO_PUBLIC_API_URL: z.ZodOptional<z.ZodString>;
|
|
8
|
+
EXPO_PUBLIC_POSTHOG_KEY: z.ZodOptional<z.ZodString>;
|
|
9
|
+
EXPO_PUBLIC_POSTHOG_HOST: z.ZodDefault<z.ZodString>;
|
|
10
|
+
EXPO_PUBLIC_SENTRY_DSN: z.ZodOptional<z.ZodString>;
|
|
11
|
+
EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY: z.ZodOptional<z.ZodString>;
|
|
12
|
+
NODE_ENV: z.ZodOptional<z.ZodDefault<z.ZodEnum<["development", "test", "production"]>>>;
|
|
13
|
+
} & T>, any> extends infer T_1 ? { [k in keyof T_1]: T_1[k]; } : never;
|
|
14
|
+
|
|
15
|
+
export { loadClientConfig };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export { c as clientSchema, a as commonSchema } from './shared-D4fnBEvF.js';
|
|
3
|
+
|
|
4
|
+
declare function loadClientConfig<T extends z.ZodRawShape>(extraSchema?: T, env?: Record<string, any>): z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
|
|
5
|
+
EXPO_PUBLIC_APP_NAME: z.ZodDefault<z.ZodString>;
|
|
6
|
+
EXPO_PUBLIC_APP_ENV: z.ZodDefault<z.ZodEnum<["development", "staging", "production"]>>;
|
|
7
|
+
EXPO_PUBLIC_API_URL: z.ZodOptional<z.ZodString>;
|
|
8
|
+
EXPO_PUBLIC_POSTHOG_KEY: z.ZodOptional<z.ZodString>;
|
|
9
|
+
EXPO_PUBLIC_POSTHOG_HOST: z.ZodDefault<z.ZodString>;
|
|
10
|
+
EXPO_PUBLIC_SENTRY_DSN: z.ZodOptional<z.ZodString>;
|
|
11
|
+
EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY: z.ZodOptional<z.ZodString>;
|
|
12
|
+
NODE_ENV: z.ZodOptional<z.ZodDefault<z.ZodEnum<["development", "test", "production"]>>>;
|
|
13
|
+
} & T>, any> extends infer T_1 ? { [k in keyof T_1]: T_1[k]; } : never;
|
|
14
|
+
|
|
15
|
+
export { loadClientConfig };
|
|
@@ -0,0 +1,65 @@
|
|
|
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
|
+
// src/react-native.ts
|
|
21
|
+
var react_native_exports = {};
|
|
22
|
+
__export(react_native_exports, {
|
|
23
|
+
clientSchema: () => clientSchema,
|
|
24
|
+
commonSchema: () => commonSchema,
|
|
25
|
+
loadClientConfig: () => loadClientConfig
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(react_native_exports);
|
|
28
|
+
var import_zod2 = require("zod");
|
|
29
|
+
|
|
30
|
+
// src/shared.ts
|
|
31
|
+
var import_zod = require("zod");
|
|
32
|
+
var commonSchema = {
|
|
33
|
+
NODE_ENV: import_zod.z.enum(["development", "test", "production"]).default("development").optional()
|
|
34
|
+
};
|
|
35
|
+
var clientSchema = {
|
|
36
|
+
EXPO_PUBLIC_APP_NAME: import_zod.z.string().default("DRX App"),
|
|
37
|
+
EXPO_PUBLIC_APP_ENV: import_zod.z.enum(["development", "staging", "production"]).default("development"),
|
|
38
|
+
EXPO_PUBLIC_API_URL: import_zod.z.string().url().optional(),
|
|
39
|
+
// Vendors
|
|
40
|
+
EXPO_PUBLIC_POSTHOG_KEY: import_zod.z.string().optional(),
|
|
41
|
+
EXPO_PUBLIC_POSTHOG_HOST: import_zod.z.string().default("https://app.posthog.com"),
|
|
42
|
+
EXPO_PUBLIC_SENTRY_DSN: import_zod.z.string().optional(),
|
|
43
|
+
EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY: import_zod.z.string().optional()
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// src/react-native.ts
|
|
47
|
+
function loadClientConfig(extraSchema = {}, env = process.env) {
|
|
48
|
+
const mergedSchema = import_zod2.z.object({
|
|
49
|
+
...commonSchema,
|
|
50
|
+
...clientSchema,
|
|
51
|
+
...extraSchema
|
|
52
|
+
});
|
|
53
|
+
const result = mergedSchema.safeParse(env);
|
|
54
|
+
if (!result.success) {
|
|
55
|
+
console.error("\u274C Invalid client environment variables:", result.error.format());
|
|
56
|
+
throw new Error("Invalid client environment variables");
|
|
57
|
+
}
|
|
58
|
+
return result.data;
|
|
59
|
+
}
|
|
60
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
61
|
+
0 && (module.exports = {
|
|
62
|
+
clientSchema,
|
|
63
|
+
commonSchema,
|
|
64
|
+
loadClientConfig
|
|
65
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
clientSchema,
|
|
3
|
+
commonSchema
|
|
4
|
+
} from "./chunk-DKD5KYQQ.mjs";
|
|
5
|
+
|
|
6
|
+
// src/react-native.ts
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
function loadClientConfig(extraSchema = {}, env = process.env) {
|
|
9
|
+
const mergedSchema = z.object({
|
|
10
|
+
...commonSchema,
|
|
11
|
+
...clientSchema,
|
|
12
|
+
...extraSchema
|
|
13
|
+
});
|
|
14
|
+
const result = mergedSchema.safeParse(env);
|
|
15
|
+
if (!result.success) {
|
|
16
|
+
console.error("\u274C Invalid client environment variables:", result.error.format());
|
|
17
|
+
throw new Error("Invalid client environment variables");
|
|
18
|
+
}
|
|
19
|
+
return result.data;
|
|
20
|
+
}
|
|
21
|
+
export {
|
|
22
|
+
clientSchema,
|
|
23
|
+
commonSchema,
|
|
24
|
+
loadClientConfig
|
|
25
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
declare const commonSchema: {
|
|
4
|
+
NODE_ENV: z.ZodOptional<z.ZodDefault<z.ZodEnum<["development", "test", "production"]>>>;
|
|
5
|
+
};
|
|
6
|
+
declare const clientSchema: {
|
|
7
|
+
EXPO_PUBLIC_APP_NAME: z.ZodDefault<z.ZodString>;
|
|
8
|
+
EXPO_PUBLIC_APP_ENV: z.ZodDefault<z.ZodEnum<["development", "staging", "production"]>>;
|
|
9
|
+
EXPO_PUBLIC_API_URL: z.ZodOptional<z.ZodString>;
|
|
10
|
+
EXPO_PUBLIC_POSTHOG_KEY: z.ZodOptional<z.ZodString>;
|
|
11
|
+
EXPO_PUBLIC_POSTHOG_HOST: z.ZodDefault<z.ZodString>;
|
|
12
|
+
EXPO_PUBLIC_SENTRY_DSN: z.ZodOptional<z.ZodString>;
|
|
13
|
+
EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY: z.ZodOptional<z.ZodString>;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { commonSchema as a, clientSchema as c };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
declare const commonSchema: {
|
|
4
|
+
NODE_ENV: z.ZodOptional<z.ZodDefault<z.ZodEnum<["development", "test", "production"]>>>;
|
|
5
|
+
};
|
|
6
|
+
declare const clientSchema: {
|
|
7
|
+
EXPO_PUBLIC_APP_NAME: z.ZodDefault<z.ZodString>;
|
|
8
|
+
EXPO_PUBLIC_APP_ENV: z.ZodDefault<z.ZodEnum<["development", "staging", "production"]>>;
|
|
9
|
+
EXPO_PUBLIC_API_URL: z.ZodOptional<z.ZodString>;
|
|
10
|
+
EXPO_PUBLIC_POSTHOG_KEY: z.ZodOptional<z.ZodString>;
|
|
11
|
+
EXPO_PUBLIC_POSTHOG_HOST: z.ZodDefault<z.ZodString>;
|
|
12
|
+
EXPO_PUBLIC_SENTRY_DSN: z.ZodOptional<z.ZodString>;
|
|
13
|
+
EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY: z.ZodOptional<z.ZodString>;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { commonSchema as a, clientSchema as c };
|
package/package.json
CHANGED
|
@@ -1,20 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wrelik/config",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/lwhite702/wrelik-kit.git",
|
|
10
|
+
"directory": "packages/config"
|
|
11
|
+
},
|
|
4
12
|
"main": "./dist/index.js",
|
|
5
13
|
"types": "./dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": "./dist/index.js",
|
|
16
|
+
"./react-native": "./dist/react-native.js"
|
|
17
|
+
},
|
|
6
18
|
"dependencies": {
|
|
7
19
|
"dotenv": "^16.4.1",
|
|
8
20
|
"zod": "^3.22.4"
|
|
9
21
|
},
|
|
10
22
|
"devDependencies": {
|
|
23
|
+
"@types/node": "^25.2.0",
|
|
11
24
|
"tsup": "^8.0.1",
|
|
12
25
|
"vitest": "^1.2.2",
|
|
13
|
-
"@wrelik/eslint-config": "0.1.
|
|
14
|
-
"@wrelik/tsconfig": "0.1.
|
|
26
|
+
"@wrelik/eslint-config": "0.1.1",
|
|
27
|
+
"@wrelik/tsconfig": "0.1.1"
|
|
15
28
|
},
|
|
16
29
|
"scripts": {
|
|
17
|
-
"build": "tsup src/index.ts --format cjs,esm --dts --clean",
|
|
30
|
+
"build": "tsup src/index.ts src/react-native.ts --format cjs,esm --dts --clean",
|
|
18
31
|
"lint": "eslint src/",
|
|
19
32
|
"test": "vitest run --passWithNoTests"
|
|
20
33
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import dotenv from 'dotenv';
|
|
3
3
|
import path from 'path';
|
|
4
|
+
import { commonSchema } from './shared';
|
|
5
|
+
|
|
6
|
+
export * from './shared';
|
|
4
7
|
|
|
5
8
|
// Load .env from project root
|
|
6
9
|
dotenv.config({ path: path.resolve(process.cwd(), '.env') });
|
|
7
10
|
|
|
8
11
|
export function createEnv<T extends z.ZodRawShape>(schema: T) {
|
|
9
|
-
const envSchema = z.object(schema);
|
|
12
|
+
const envSchema = z.object({ ...commonSchema, ...schema });
|
|
10
13
|
const result = envSchema.safeParse(process.env);
|
|
11
14
|
|
|
12
15
|
if (!result.success) {
|
|
@@ -17,7 +20,6 @@ export function createEnv<T extends z.ZodRawShape>(schema: T) {
|
|
|
17
20
|
return result.data;
|
|
18
21
|
}
|
|
19
22
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
};
|
|
23
|
+
export function loadServerConfig() {
|
|
24
|
+
return createEnv({});
|
|
25
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { loadClientConfig, clientSchema } from './react-native';
|
|
3
|
+
|
|
4
|
+
describe('Config React Native', () => {
|
|
5
|
+
it('validates client config', () => {
|
|
6
|
+
// Basic validation test implicitly covered by loadClientConfig calls below
|
|
7
|
+
// or we can test specific schema constraints if we export schema
|
|
8
|
+
expect(clientSchema).toBeDefined();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('loads valid config', () => {
|
|
12
|
+
const env = {
|
|
13
|
+
EXPO_PUBLIC_APP_NAME: 'Test App',
|
|
14
|
+
EXPO_PUBLIC_APP_ENV: 'development',
|
|
15
|
+
EXPO_PUBLIC_POSTHOG_HOST: 'https://test.com',
|
|
16
|
+
};
|
|
17
|
+
const config = loadClientConfig({}, env);
|
|
18
|
+
expect(config.EXPO_PUBLIC_APP_NAME).toBe('Test App');
|
|
19
|
+
expect(config.EXPO_PUBLIC_POSTHOG_HOST).toBe('https://test.com');
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('throws on invalid config', () => {
|
|
23
|
+
const env = {
|
|
24
|
+
EXPO_PUBLIC_APP_ENV: 'invalid_env',
|
|
25
|
+
};
|
|
26
|
+
// Mock console.error to avoid noise
|
|
27
|
+
const originalError = console.error;
|
|
28
|
+
console.error = () => {};
|
|
29
|
+
expect(() => loadClientConfig({}, env)).toThrow('Invalid client environment variables');
|
|
30
|
+
console.error = originalError;
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { clientSchema, commonSchema } from './shared';
|
|
3
|
+
|
|
4
|
+
export * from './shared';
|
|
5
|
+
|
|
6
|
+
export function loadClientConfig<T extends z.ZodRawShape>(
|
|
7
|
+
extraSchema: T = {} as T,
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
+
env: Record<string, any> = process.env,
|
|
10
|
+
) {
|
|
11
|
+
const mergedSchema = z.object({
|
|
12
|
+
...commonSchema,
|
|
13
|
+
...clientSchema,
|
|
14
|
+
...extraSchema,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const result = mergedSchema.safeParse(env);
|
|
18
|
+
|
|
19
|
+
if (!result.success) {
|
|
20
|
+
console.error('❌ Invalid client environment variables:', result.error.format());
|
|
21
|
+
throw new Error('Invalid client environment variables');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return result.data;
|
|
25
|
+
}
|
package/src/shared.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
// Common schemas that can be used effectively in both environments
|
|
4
|
+
export const commonSchema = {
|
|
5
|
+
NODE_ENV: z.enum(['development', 'test', 'production']).default('development').optional(),
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
// Client-safe schemas (EXPO_PUBLIC_*)
|
|
9
|
+
export const clientSchema = {
|
|
10
|
+
EXPO_PUBLIC_APP_NAME: z.string().default('DRX App'),
|
|
11
|
+
EXPO_PUBLIC_APP_ENV: z.enum(['development', 'staging', 'production']).default('development'),
|
|
12
|
+
EXPO_PUBLIC_API_URL: z.string().url().optional(),
|
|
13
|
+
|
|
14
|
+
// Vendors
|
|
15
|
+
EXPO_PUBLIC_POSTHOG_KEY: z.string().optional(),
|
|
16
|
+
EXPO_PUBLIC_POSTHOG_HOST: z.string().default('https://app.posthog.com'),
|
|
17
|
+
EXPO_PUBLIC_SENTRY_DSN: z.string().optional(),
|
|
18
|
+
EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY: z.string().optional(),
|
|
19
|
+
};
|