@solvapay/core 1.0.0-preview.8 → 1.0.1-preview.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -32,6 +32,11 @@ var Env = import_zod.z.object({
32
32
  SOLVAPAY_API_BASE_URL: import_zod.z.string().url().optional()
33
33
  });
34
34
  var SolvaPayError = class extends Error {
35
+ /**
36
+ * Creates a new SolvaPayError instance.
37
+ *
38
+ * @param message - Error message
39
+ */
35
40
  constructor(message) {
36
41
  super(message);
37
42
  this.name = "SolvaPayError";
@@ -41,7 +46,9 @@ function getSolvaPayConfig() {
41
46
  const solvapaySecretKey = process.env.SOLVAPAY_SECRET_KEY;
42
47
  const solvapayApiBaseUrl = process.env.SOLVAPAY_API_BASE_URL;
43
48
  if (!solvapaySecretKey) {
44
- throw new SolvaPayError("Server configuration error: SolvaPay secret key not configured. Missing SOLVAPAY_SECRET_KEY environment variable.");
49
+ throw new SolvaPayError(
50
+ "Server configuration error: SolvaPay secret key not configured. Missing SOLVAPAY_SECRET_KEY environment variable."
51
+ );
45
52
  }
46
53
  return {
47
54
  apiKey: solvapaySecretKey,
package/dist/index.d.cts CHANGED
@@ -3,15 +3,39 @@ import { z } from 'zod';
3
3
  declare const Env: z.ZodObject<{
4
4
  SOLVAPAY_SECRET_KEY: z.ZodString;
5
5
  SOLVAPAY_API_BASE_URL: z.ZodOptional<z.ZodString>;
6
- }, "strip", z.ZodTypeAny, {
7
- SOLVAPAY_SECRET_KEY: string;
8
- SOLVAPAY_API_BASE_URL?: string | undefined;
9
- }, {
10
- SOLVAPAY_SECRET_KEY: string;
11
- SOLVAPAY_API_BASE_URL?: string | undefined;
12
- }>;
6
+ }, z.core.$strip>;
13
7
  type Env = z.infer<typeof Env>;
8
+ /**
9
+ * Base error class for SolvaPay SDK errors.
10
+ *
11
+ * All SolvaPay SDK errors extend this class, making it easy to catch
12
+ * and handle SDK-specific errors separately from other errors.
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * import { SolvaPayError } from '@solvapay/core';
17
+ *
18
+ * try {
19
+ * const config = getSolvaPayConfig();
20
+ * } catch (error) {
21
+ * if (error instanceof SolvaPayError) {
22
+ * // Handle SolvaPay-specific error
23
+ * console.error('SolvaPay error:', error.message);
24
+ * } else {
25
+ * // Handle other errors
26
+ * throw error;
27
+ * }
28
+ * }
29
+ * ```
30
+ *
31
+ * @since 1.0.0
32
+ */
14
33
  declare class SolvaPayError extends Error {
34
+ /**
35
+ * Creates a new SolvaPayError instance.
36
+ *
37
+ * @param message - Error message
38
+ */
15
39
  constructor(message: string);
16
40
  }
17
41
  interface SolvaPayConfig {
@@ -20,10 +44,28 @@ interface SolvaPayConfig {
20
44
  }
21
45
  /**
22
46
  * Validates and returns SolvaPay configuration from environment variables.
23
- * Throws SolvaPayError if required environment variables are missing.
47
+ *
48
+ * Reads `SOLVAPAY_SECRET_KEY` and optional `SOLVAPAY_API_BASE_URL` from
49
+ * environment variables and returns a validated configuration object.
24
50
  *
25
51
  * @returns SolvaPayConfig object with apiKey and optional apiBaseUrl
26
- * @throws SolvaPayError if SOLVAPAY_SECRET_KEY is missing
52
+ * @throws {SolvaPayError} If SOLVAPAY_SECRET_KEY is missing
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * import { getSolvaPayConfig } from '@solvapay/core';
57
+ *
58
+ * try {
59
+ * const config = getSolvaPayConfig();
60
+ * console.log('API Key configured:', config.apiKey);
61
+ * } catch (error) {
62
+ * console.error('Configuration error:', error.message);
63
+ * }
64
+ * ```
65
+ *
66
+ * @see {@link SolvaPayConfig} for the return type
67
+ * @see {@link SolvaPayError} for error handling
68
+ * @since 1.0.0
27
69
  */
28
70
  declare function getSolvaPayConfig(): SolvaPayConfig;
29
71
  declare const version = "0.1.0";
package/dist/index.d.ts CHANGED
@@ -3,15 +3,39 @@ import { z } from 'zod';
3
3
  declare const Env: z.ZodObject<{
4
4
  SOLVAPAY_SECRET_KEY: z.ZodString;
5
5
  SOLVAPAY_API_BASE_URL: z.ZodOptional<z.ZodString>;
6
- }, "strip", z.ZodTypeAny, {
7
- SOLVAPAY_SECRET_KEY: string;
8
- SOLVAPAY_API_BASE_URL?: string | undefined;
9
- }, {
10
- SOLVAPAY_SECRET_KEY: string;
11
- SOLVAPAY_API_BASE_URL?: string | undefined;
12
- }>;
6
+ }, z.core.$strip>;
13
7
  type Env = z.infer<typeof Env>;
8
+ /**
9
+ * Base error class for SolvaPay SDK errors.
10
+ *
11
+ * All SolvaPay SDK errors extend this class, making it easy to catch
12
+ * and handle SDK-specific errors separately from other errors.
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * import { SolvaPayError } from '@solvapay/core';
17
+ *
18
+ * try {
19
+ * const config = getSolvaPayConfig();
20
+ * } catch (error) {
21
+ * if (error instanceof SolvaPayError) {
22
+ * // Handle SolvaPay-specific error
23
+ * console.error('SolvaPay error:', error.message);
24
+ * } else {
25
+ * // Handle other errors
26
+ * throw error;
27
+ * }
28
+ * }
29
+ * ```
30
+ *
31
+ * @since 1.0.0
32
+ */
14
33
  declare class SolvaPayError extends Error {
34
+ /**
35
+ * Creates a new SolvaPayError instance.
36
+ *
37
+ * @param message - Error message
38
+ */
15
39
  constructor(message: string);
16
40
  }
17
41
  interface SolvaPayConfig {
@@ -20,10 +44,28 @@ interface SolvaPayConfig {
20
44
  }
21
45
  /**
22
46
  * Validates and returns SolvaPay configuration from environment variables.
23
- * Throws SolvaPayError if required environment variables are missing.
47
+ *
48
+ * Reads `SOLVAPAY_SECRET_KEY` and optional `SOLVAPAY_API_BASE_URL` from
49
+ * environment variables and returns a validated configuration object.
24
50
  *
25
51
  * @returns SolvaPayConfig object with apiKey and optional apiBaseUrl
26
- * @throws SolvaPayError if SOLVAPAY_SECRET_KEY is missing
52
+ * @throws {SolvaPayError} If SOLVAPAY_SECRET_KEY is missing
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * import { getSolvaPayConfig } from '@solvapay/core';
57
+ *
58
+ * try {
59
+ * const config = getSolvaPayConfig();
60
+ * console.log('API Key configured:', config.apiKey);
61
+ * } catch (error) {
62
+ * console.error('Configuration error:', error.message);
63
+ * }
64
+ * ```
65
+ *
66
+ * @see {@link SolvaPayConfig} for the return type
67
+ * @see {@link SolvaPayError} for error handling
68
+ * @since 1.0.0
27
69
  */
28
70
  declare function getSolvaPayConfig(): SolvaPayConfig;
29
71
  declare const version = "0.1.0";
package/dist/index.js CHANGED
@@ -5,6 +5,11 @@ 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";
@@ -14,7 +19,9 @@ function getSolvaPayConfig() {
14
19
  const solvapaySecretKey = process.env.SOLVAPAY_SECRET_KEY;
15
20
  const solvapayApiBaseUrl = process.env.SOLVAPAY_API_BASE_URL;
16
21
  if (!solvapaySecretKey) {
17
- throw new SolvaPayError("Server configuration error: SolvaPay secret key not configured. Missing SOLVAPAY_SECRET_KEY environment variable.");
22
+ throw new SolvaPayError(
23
+ "Server configuration error: SolvaPay secret key not configured. Missing SOLVAPAY_SECRET_KEY environment variable."
24
+ );
18
25
  }
19
26
  return {
20
27
  apiKey: solvapaySecretKey,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solvapay/core",
3
- "version": "1.0.0-preview.8",
3
+ "version": "1.0.1-preview.1",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -26,18 +26,19 @@
26
26
  },
27
27
  "sideEffects": false,
28
28
  "dependencies": {
29
- "zod": "^3.23.8"
29
+ "zod": "^4.3.6"
30
30
  },
31
31
  "devDependencies": {
32
- "tsup": "^8.0.1",
33
- "typescript": "^5.5.4",
34
- "vitest": "^2.0.5"
32
+ "tsup": "^8.5.1",
33
+ "typescript": "^5.9.3",
34
+ "vitest": "^4.1.2"
35
35
  },
36
36
  "scripts": {
37
37
  "build": "tsup src/index.ts --format esm,cjs --dts --tsconfig tsconfig.build.json",
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
  }