@solvapay/core 1.0.0-preview.2 → 1.0.0-preview.21

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.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 SolvaPay Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,15 +1,87 @@
1
1
  # @solvapay/core
2
2
 
3
- Shared types, schemas, and errors.
3
+ Shared types, schemas, errors, and utilities used across all SolvaPay SDK packages.
4
+
5
+ This package is **runtime-agnostic** -- it contains no Node.js or browser globals and has `"sideEffects": false`.
4
6
 
5
7
  ## Install
8
+
6
9
  ```bash
10
+ npm install @solvapay/core
11
+ # or
12
+ yarn add @solvapay/core
13
+ # or
7
14
  pnpm add @solvapay/core
8
15
  ```
9
16
 
10
- ## Usage
11
- ```ts
12
- import { SolvaPayError, Env } from '@solvapay/core';
17
+ ## Exports
18
+
19
+ ### `SolvaPayError`
20
+
21
+ Base error class for all SolvaPay SDK errors. Useful for catching SDK-specific errors:
22
+
23
+ ```typescript
24
+ import { SolvaPayError } from '@solvapay/core'
25
+
26
+ try {
27
+ const config = getSolvaPayConfig()
28
+ } catch (error) {
29
+ if (error instanceof SolvaPayError) {
30
+ console.error('SolvaPay error:', error.message)
31
+ }
32
+ }
33
+ ```
34
+
35
+ ### `SolvaPayConfig`
36
+
37
+ Configuration interface for the SDK:
38
+
39
+ ```typescript
40
+ import type { SolvaPayConfig } from '@solvapay/core'
41
+
42
+ const config: SolvaPayConfig = {
43
+ apiKey: 'sk_live_...',
44
+ apiBaseUrl: 'https://api.solvapay.com', // optional
45
+ }
13
46
  ```
14
47
 
15
- More: docs/architecture.md
48
+ ### `getSolvaPayConfig()`
49
+
50
+ Validates and returns configuration from environment variables. Reads `SOLVAPAY_SECRET_KEY` and optional `SOLVAPAY_API_BASE_URL`:
51
+
52
+ ```typescript
53
+ import { getSolvaPayConfig } from '@solvapay/core'
54
+
55
+ const config = getSolvaPayConfig()
56
+ // config.apiKey - from SOLVAPAY_SECRET_KEY
57
+ // config.apiBaseUrl - from SOLVAPAY_API_BASE_URL (optional)
58
+ ```
59
+
60
+ Throws `SolvaPayError` if `SOLVAPAY_SECRET_KEY` is not set.
61
+
62
+ ### `Env`
63
+
64
+ Zod schema for validating environment variables:
65
+
66
+ ```typescript
67
+ import { Env } from '@solvapay/core'
68
+
69
+ const result = Env.safeParse(process.env)
70
+ if (!result.success) {
71
+ console.error('Invalid environment:', result.error)
72
+ }
73
+ ```
74
+
75
+ ### `version`
76
+
77
+ The current SDK version string.
78
+
79
+ ## When to Use This Package
80
+
81
+ Most developers don't need to install `@solvapay/core` directly -- it's automatically included as a dependency of `@solvapay/server`, `@solvapay/react`, and other packages. Install it directly only if you need access to the shared types or error classes without pulling in a full SDK package.
82
+
83
+ ## More Information
84
+
85
+ - [Architecture Guide](../../docs/guides/architecture.md) - Package design and boundaries
86
+ - [Server SDK](../server/README.md) - Server-side paywall protection
87
+ - [React SDK](../react/README.md) - Client-side payment components
package/dist/index.cjs CHANGED
@@ -22,6 +22,7 @@ var index_exports = {};
22
22
  __export(index_exports, {
23
23
  Env: () => Env,
24
24
  SolvaPayError: () => SolvaPayError,
25
+ getSolvaPayConfig: () => getSolvaPayConfig,
25
26
  version: () => version
26
27
  });
27
28
  module.exports = __toCommonJS(index_exports);
@@ -31,15 +32,34 @@ var Env = import_zod.z.object({
31
32
  SOLVAPAY_API_BASE_URL: import_zod.z.string().url().optional()
32
33
  });
33
34
  var SolvaPayError = class extends Error {
35
+ /**
36
+ * Creates a new SolvaPayError instance.
37
+ *
38
+ * @param message - Error message
39
+ */
34
40
  constructor(message) {
35
41
  super(message);
36
42
  this.name = "SolvaPayError";
37
43
  }
38
44
  };
45
+ function getSolvaPayConfig() {
46
+ const solvapaySecretKey = process.env.SOLVAPAY_SECRET_KEY;
47
+ const solvapayApiBaseUrl = process.env.SOLVAPAY_API_BASE_URL;
48
+ if (!solvapaySecretKey) {
49
+ throw new SolvaPayError(
50
+ "Server configuration error: SolvaPay secret key not configured. Missing SOLVAPAY_SECRET_KEY environment variable."
51
+ );
52
+ }
53
+ return {
54
+ apiKey: solvapaySecretKey,
55
+ apiBaseUrl: solvapayApiBaseUrl
56
+ };
57
+ }
39
58
  var version = "0.1.0";
40
59
  // Annotate the CommonJS export names for ESM import in node:
41
60
  0 && (module.exports = {
42
61
  Env,
43
62
  SolvaPayError,
63
+ getSolvaPayConfig,
44
64
  version
45
65
  });
package/dist/index.d.cts CHANGED
@@ -11,9 +11,69 @@ declare const Env: z.ZodObject<{
11
11
  SOLVAPAY_API_BASE_URL?: string | undefined;
12
12
  }>;
13
13
  type Env = z.infer<typeof Env>;
14
+ /**
15
+ * Base error class for SolvaPay SDK errors.
16
+ *
17
+ * All SolvaPay SDK errors extend this class, making it easy to catch
18
+ * and handle SDK-specific errors separately from other errors.
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * import { SolvaPayError } from '@solvapay/core';
23
+ *
24
+ * try {
25
+ * const config = getSolvaPayConfig();
26
+ * } catch (error) {
27
+ * if (error instanceof SolvaPayError) {
28
+ * // Handle SolvaPay-specific error
29
+ * console.error('SolvaPay error:', error.message);
30
+ * } else {
31
+ * // Handle other errors
32
+ * throw error;
33
+ * }
34
+ * }
35
+ * ```
36
+ *
37
+ * @since 1.0.0
38
+ */
14
39
  declare class SolvaPayError extends Error {
40
+ /**
41
+ * Creates a new SolvaPayError instance.
42
+ *
43
+ * @param message - Error message
44
+ */
15
45
  constructor(message: string);
16
46
  }
47
+ interface SolvaPayConfig {
48
+ apiKey: string;
49
+ apiBaseUrl?: string;
50
+ }
51
+ /**
52
+ * Validates and returns SolvaPay configuration from environment variables.
53
+ *
54
+ * Reads `SOLVAPAY_SECRET_KEY` and optional `SOLVAPAY_API_BASE_URL` from
55
+ * environment variables and returns a validated configuration object.
56
+ *
57
+ * @returns SolvaPayConfig object with apiKey and optional apiBaseUrl
58
+ * @throws {SolvaPayError} If SOLVAPAY_SECRET_KEY is missing
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * import { getSolvaPayConfig } from '@solvapay/core';
63
+ *
64
+ * try {
65
+ * const config = getSolvaPayConfig();
66
+ * console.log('API Key configured:', config.apiKey);
67
+ * } catch (error) {
68
+ * console.error('Configuration error:', error.message);
69
+ * }
70
+ * ```
71
+ *
72
+ * @see {@link SolvaPayConfig} for the return type
73
+ * @see {@link SolvaPayError} for error handling
74
+ * @since 1.0.0
75
+ */
76
+ declare function getSolvaPayConfig(): SolvaPayConfig;
17
77
  declare const version = "0.1.0";
18
78
 
19
- export { Env, SolvaPayError, version };
79
+ export { Env, type SolvaPayConfig, SolvaPayError, getSolvaPayConfig, version };
package/dist/index.d.ts CHANGED
@@ -11,9 +11,69 @@ declare const Env: z.ZodObject<{
11
11
  SOLVAPAY_API_BASE_URL?: string | undefined;
12
12
  }>;
13
13
  type Env = z.infer<typeof Env>;
14
+ /**
15
+ * Base error class for SolvaPay SDK errors.
16
+ *
17
+ * All SolvaPay SDK errors extend this class, making it easy to catch
18
+ * and handle SDK-specific errors separately from other errors.
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * import { SolvaPayError } from '@solvapay/core';
23
+ *
24
+ * try {
25
+ * const config = getSolvaPayConfig();
26
+ * } catch (error) {
27
+ * if (error instanceof SolvaPayError) {
28
+ * // Handle SolvaPay-specific error
29
+ * console.error('SolvaPay error:', error.message);
30
+ * } else {
31
+ * // Handle other errors
32
+ * throw error;
33
+ * }
34
+ * }
35
+ * ```
36
+ *
37
+ * @since 1.0.0
38
+ */
14
39
  declare class SolvaPayError extends Error {
40
+ /**
41
+ * Creates a new SolvaPayError instance.
42
+ *
43
+ * @param message - Error message
44
+ */
15
45
  constructor(message: string);
16
46
  }
47
+ interface SolvaPayConfig {
48
+ apiKey: string;
49
+ apiBaseUrl?: string;
50
+ }
51
+ /**
52
+ * Validates and returns SolvaPay configuration from environment variables.
53
+ *
54
+ * Reads `SOLVAPAY_SECRET_KEY` and optional `SOLVAPAY_API_BASE_URL` from
55
+ * environment variables and returns a validated configuration object.
56
+ *
57
+ * @returns SolvaPayConfig object with apiKey and optional apiBaseUrl
58
+ * @throws {SolvaPayError} If SOLVAPAY_SECRET_KEY is missing
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * import { getSolvaPayConfig } from '@solvapay/core';
63
+ *
64
+ * try {
65
+ * const config = getSolvaPayConfig();
66
+ * console.log('API Key configured:', config.apiKey);
67
+ * } catch (error) {
68
+ * console.error('Configuration error:', error.message);
69
+ * }
70
+ * ```
71
+ *
72
+ * @see {@link SolvaPayConfig} for the return type
73
+ * @see {@link SolvaPayError} for error handling
74
+ * @since 1.0.0
75
+ */
76
+ declare function getSolvaPayConfig(): SolvaPayConfig;
17
77
  declare const version = "0.1.0";
18
78
 
19
- export { Env, SolvaPayError, version };
79
+ export { Env, type SolvaPayConfig, SolvaPayError, getSolvaPayConfig, version };
package/dist/index.js CHANGED
@@ -5,14 +5,33 @@ var Env = z.object({
5
5
  SOLVAPAY_API_BASE_URL: z.string().url().optional()
6
6
  });
7
7
  var SolvaPayError = class extends Error {
8
+ /**
9
+ * Creates a new SolvaPayError instance.
10
+ *
11
+ * @param message - Error message
12
+ */
8
13
  constructor(message) {
9
14
  super(message);
10
15
  this.name = "SolvaPayError";
11
16
  }
12
17
  };
18
+ function getSolvaPayConfig() {
19
+ const solvapaySecretKey = process.env.SOLVAPAY_SECRET_KEY;
20
+ const solvapayApiBaseUrl = process.env.SOLVAPAY_API_BASE_URL;
21
+ if (!solvapaySecretKey) {
22
+ throw new SolvaPayError(
23
+ "Server configuration error: SolvaPay secret key not configured. Missing SOLVAPAY_SECRET_KEY environment variable."
24
+ );
25
+ }
26
+ return {
27
+ apiKey: solvapaySecretKey,
28
+ apiBaseUrl: solvapayApiBaseUrl
29
+ };
30
+ }
13
31
  var version = "0.1.0";
14
32
  export {
15
33
  Env,
16
34
  SolvaPayError,
35
+ getSolvaPayConfig,
17
36
  version
18
37
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solvapay/core",
3
- "version": "1.0.0-preview.2",
3
+ "version": "1.0.0-preview.21",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -38,6 +38,7 @@
38
38
  "test": "vitest run || exit 0",
39
39
  "test:unit": "vitest run || exit 0",
40
40
  "test:watch": "vitest",
41
- "lint": "echo 'no lint yet'"
41
+ "lint": "eslint src",
42
+ "lint:fix": "eslint src --fix"
42
43
  }
43
44
  }