@inneropen/marvin-sdk 2.0.0-next.18 → 2.0.0-next.2

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/README.md CHANGED
@@ -1,35 +1,7 @@
1
1
  # Marvin TypeScript SDK
2
2
 
3
- > 🔒 **Enterprise-Grade Security** | ✅ **Zero Vulnerabilities** | 🚀 **Production-Ready**
4
-
5
3
  The official TypeScript SDK for Marvin CMS. A modern, workspace-first SDK for building applications that integrate with Marvin.
6
4
 
7
- [![Security Status](https://img.shields.io/badge/security-enterprise%20grade-brightgreen)](./SECURITY_FIXES_SUMMARY.md)
8
- [![Version](https://img.shields.io/badge/version-2.0.1-blue)](https://github.com/inneropen/marvin-sdk/releases)
9
- [![TypeScript](https://img.shields.io/badge/TypeScript-100%25-blue)](https://www.typescriptlang.org/)
10
-
11
- ## Security First
12
-
13
- **The Marvin SDK has undergone a comprehensive security audit and achieved zero security vulnerabilities.** All 20 identified issues have been fixed, including:
14
-
15
- - ✅ 8 HIGH priority vulnerabilities eliminated
16
- - ✅ 7 MEDIUM priority security issues resolved
17
- - ✅ 5 LOW priority code quality improvements implemented
18
-
19
- **[View Complete Security Audit →](./COMPLETE_SECURITY_AUDIT.md)**
20
-
21
- ### Key Security Features
22
-
23
- - 🔐 **Token Sanitization** - Automatic redaction of sensitive data in logs/errors
24
- - 🛡️ **Input Validation** - Path injection, XSS, and SSRF prevention
25
- - 📧 **Email Validation** - RFC 5322 compliant validation
26
- - 📁 **File Upload Security** - Size, type, and filename validation
27
- - 🔄 **Network Resilience** - Automatic retry with exponential backoff
28
- - 🔒 **CSRF Protection** - Session authentication security
29
- - ✅ **Type Safety** - 100% TypeScript with zero `any` types
30
-
31
- **[View Security Best Practices →](./AUTHENTICATION.md#security-best-practices)**
32
-
33
5
  ## Why This SDK?
34
6
 
35
7
  Marvin is becoming a platform, not simply a CMS. This SDK is the primary way to integrate with Marvin across:
@@ -47,64 +19,42 @@ The SDK provides:
47
19
  - 📘 **Fully Typed** - Complete TypeScript support
48
20
  - 🔄 **Backwards Compatible** - Works with existing publishing APIs
49
21
  - 🎨 **Object-Oriented** - Rich objects instead of raw JSON
50
- - 🔒 **Enterprise Security** - Production-ready with comprehensive security features
22
+ - 🔒 **Secure** - Site client tokens, never user tokens
51
23
 
52
24
  ## Installation
53
25
 
54
26
  ```bash
55
- npm install @inneropen/marvin-sdk@^2.0.1
56
- ```
57
-
58
- **Latest stable version:** v2.0.1 with complete security fixes and enterprise-grade quality.
59
-
60
- ## Entry Points
61
-
62
- The SDK provides three distinct entry points for different use cases:
63
-
64
- ### 📖 Publishing API (`/publish`)
65
- Read-only access to published content (frontends, websites)
66
- ```typescript
67
- import { createMarvinClient } from '@inneropen/marvin-sdk/publish';
27
+ # Copy into your project
28
+ cp -r /path/to/marvin/packages/marvin-sdk src/lib/marvin
68
29
  ```
69
- **Auth:** Site client tokens (`MARVIN_SITE_CLIENT_TOKEN`)
70
30
 
71
- ### ⚙️ Platform API (`/platform`)
72
- Full CRUD admin operations (backend, CLI, automation)
73
- ```typescript
74
- import { createPlatformClient } from '@inneropen/marvin-sdk/platform';
75
- ```
76
- **Auth:** User tokens (`MARVIN_USER_TOKEN`) or session cookies
31
+ Or symlink for development:
77
32
 
78
- ### 🔐 Auth API (Default export)
79
- Public registration, login, password reset
80
- ```typescript
81
- import { createAuthClient } from '@inneropen/marvin-sdk';
33
+ ```bash
34
+ ln -s /path/to/marvin/packages/marvin-sdk src/lib/marvin
82
35
  ```
83
- **Auth:** None required (public endpoints)
84
-
85
- 📚 **[See complete authentication guide →](./AUTHENTICATION.md)**
86
36
 
87
- ## Quick Start - Publishing API
37
+ ## Quick Start
88
38
 
89
39
  ### 1. Configure Environment
90
40
 
91
41
  ```env
92
42
  MARVIN_API_URL=https://marvin.example.com
93
- MARVIN_SITE_CLIENT_TOKEN=your-site-client-token
43
+ MARVIN_SITE_CLIENT_TOKEN=your-token-here
94
44
  MARVIN_WORKSPACE_SLUG=your-workspace
95
45
  ```
96
46
 
97
47
  ### 2. Create Client
98
48
 
99
- ```typescript
100
- import { createMarvinClient } from '@inneropen/marvin-sdk/publish';
49
+ ```ts
50
+ import { createMarvinClient } from './marvin-sdk';
101
51
 
102
52
  const marvin = createMarvinClient();
103
53
  ```
104
54
 
105
55
  ### 3. Fetch Content
106
56
 
107
- ```typescript
57
+ ```ts
108
58
  // Get workspace
109
59
  const workspace = await marvin.getWorkspace();
110
60
  console.log(workspace.site?.title);
@@ -121,35 +71,6 @@ const projects = await marvin.collection('projects');
121
71
  const projectEntries = await projects.entries();
122
72
  ```
123
73
 
124
- ## Quick Start - Platform API
125
-
126
- ### Programmatic Admin Access
127
-
128
- ```typescript
129
- import { createPlatformClient } from '@inneropen/marvin-sdk/platform';
130
-
131
- // From environment (MARVIN_USER_TOKEN)
132
- const platform = createPlatformClient();
133
-
134
- // Or explicit token
135
- const platform = createPlatformClient({
136
- userToken: 'your-user-token'
137
- });
138
-
139
- // Full CRUD operations
140
- await platform.entries.create({
141
- title: 'New Post',
142
- content: 'Content here...',
143
- collection_id: collectionId
144
- });
145
-
146
- await platform.entries.update(entryId, {
147
- title: 'Updated Title'
148
- });
149
-
150
- await platform.entries.delete(entryId);
151
- ```
152
-
153
74
  ## Architecture
154
75
 
155
76
  ### Workspace-First Design
@@ -713,31 +634,6 @@ The SDK uses these Marvin publishing API endpoints:
713
634
 
714
635
  ## Security
715
636
 
716
- ### Security Features
717
-
718
- The SDK includes comprehensive security protections:
719
-
720
- #### Input Validation
721
- - **Path Injection Prevention** - Validates all path parameters to prevent `../` attacks
722
- - **Email Validation** - RFC 5322 compliant email format checking
723
- - **Webhook URL Validation** - SSRF prevention for webhook endpoints
724
- - **File Upload Validation** - Size limits (10MB), type checking, and filename sanitization
725
- - **Form Submission Validation** - XSS prevention with script tag detection
726
-
727
- #### Data Protection
728
- - **Token Sanitization** - Automatic redaction of sensitive data in debug logs and errors
729
- - Tokens, passwords, secrets, API keys automatically masked
730
- - Recursive sanitization for nested objects and arrays
731
- - **Email Password Security** - Passwords never returned in API responses
732
- - **CSRF Protection** - Session authentication with CSRF token support
733
-
734
- #### Network Security
735
- - **Retry Logic** - Automatic exponential backoff for transient failures (3 retries, configurable)
736
- - **Timeout Limits** - Maximum 2-minute timeout to prevent resource exhaustion
737
- - **Error Handling** - Comprehensive error types with actionable messages
738
-
739
- **[Complete Security Documentation →](./SECURITY_FIXES_SUMMARY.md)**
740
-
741
637
  ### Site Client Tokens
742
638
 
743
639
  Always use **site client tokens**, never user tokens.
@@ -764,17 +660,6 @@ const marvin = createMarvinClient();
764
660
  </script>
765
661
  ```
766
662
 
767
- ### Security Best Practices
768
-
769
- 1. **Environment Variables** - Never commit tokens to version control
770
- 2. **Token Rotation** - Regenerate user tokens periodically
771
- 3. **Debug Mode** - Tokens are automatically sanitized in logs, but still use caution
772
- 4. **Input Validation** - The SDK validates all inputs, but validate on your side too
773
- 5. **HTTPS Only** - Always use HTTPS in production (enforced by default)
774
- 6. **CSRF Tokens** - Enable CSRF protection for browser-based admin UIs
775
-
776
- **[Complete Authentication Guide →](./AUTHENTICATION.md)**
777
-
778
663
  ## Future Modules
779
664
 
780
665
  The SDK architecture supports future expansion:
@@ -829,18 +714,8 @@ Make sure your `tsconfig.json` includes:
829
714
 
830
715
  MIT - Part of the Marvin project.
831
716
 
832
- ## Documentation
833
-
834
- - 🔒 [Security Audit Report](./COMPLETE_SECURITY_AUDIT.md) - Complete security fixes (20 issues resolved)
835
- - 📋 [Security Fixes Summary](./SECURITY_FIXES_SUMMARY.md) - Key improvements and migration guide
836
- - 🔐 [Authentication Guide](./AUTHENTICATION.md) - Complete auth documentation and security best practices
837
- - ⚠️ [Error Handling Guide](./ERROR_HANDLING_GUIDE.md) - Comprehensive error handling patterns
838
- - 🧪 [Testing Guide](./TESTING.md) - Testing strategy and security test examples
839
- - 🔄 [Migration Guide v2.0](./MIGRATION-v2.md) - Upgrade from v1.x to v2.0
840
-
841
717
  ## Support
842
718
 
843
719
  - 📖 [Full Documentation](./examples.md)
844
720
  - 🚀 [Quick Start Guide](./QUICKSTART.md)
845
721
  - 🐛 [Report Issues](https://github.com/jmashburn/Marvin/issues)
846
- - 🔒 [Security Policy](./SECURITY.md) - Vulnerability reporting and security policy
@@ -33,22 +33,11 @@ declare class BearerTokenAuth implements AuthStrategy {
33
33
  /**
34
34
  * Session-based authentication (Platform/Admin APIs in browser)
35
35
  * Relies on HTTP-only cookies set by the server
36
- * Optionally supports CSRF token protection
37
36
  */
38
37
  declare class SessionAuth implements AuthStrategy {
39
38
  private sessionToken?;
40
39
  private onUnauthorized?;
41
- private csrfToken?;
42
40
  constructor(sessionToken?: string | undefined, onUnauthorized?: (() => Promise<void>) | undefined);
43
- /**
44
- * Set CSRF token for cross-site request forgery protection
45
- * The token should be obtained from the server after login
46
- */
47
- setCsrfToken(token: string): void;
48
- /**
49
- * Get current CSRF token
50
- */
51
- getCsrfToken(): string | undefined;
52
41
  injectAuth(headers: Headers): void;
53
42
  handleUnauthorized(): Promise<void>;
54
43
  getDescription(): string;
@@ -65,29 +54,12 @@ declare class NoAuth implements AuthStrategy {
65
54
  * Base HTTP client for Marvin APIs
66
55
  */
67
56
 
68
- interface RetryConfig {
69
- /** Maximum number of retry attempts (default: 3) */
70
- maxRetries: number;
71
- /** Initial delay in ms before first retry (default: 1000) */
72
- initialDelay: number;
73
- /** Maximum delay in ms between retries (default: 10000) */
74
- maxDelay: number;
75
- /** HTTP status codes that should trigger a retry (default: [408, 429, 500, 502, 503, 504]) */
76
- retryableStatuses: number[];
77
- }
78
57
  interface HttpClientConfig {
79
58
  baseUrl: string;
80
59
  auth: AuthStrategy;
81
60
  defaultHeaders?: Record<string, string>;
82
61
  credentials?: RequestCredentials;
83
62
  timeout?: number;
84
- debug?: boolean;
85
- retry?: Partial<RetryConfig>;
86
- logger?: {
87
- log: (message: string, ...args: unknown[]) => void;
88
- warn: (message: string, ...args: unknown[]) => void;
89
- error: (message: string, ...args: unknown[]) => void;
90
- };
91
63
  }
92
64
  declare class HttpClient {
93
65
  private baseUrl;
@@ -95,14 +67,7 @@ declare class HttpClient {
95
67
  private defaultHeaders;
96
68
  private credentials;
97
69
  private timeout;
98
- private debug;
99
- private retryConfig;
100
- private logger;
101
70
  constructor(config: HttpClientConfig);
102
- /**
103
- * Validate path parameter to prevent path traversal attacks
104
- */
105
- validatePathParam(param: string | number, paramName?: string): string;
106
71
  /**
107
72
  * Build full URL from endpoint
108
73
  */
@@ -116,25 +81,13 @@ declare class HttpClient {
116
81
  */
117
82
  buildQueryString(params: Record<string, string | number | boolean | undefined>): string;
118
83
  /**
119
- * Sanitize data for logging by redacting sensitive fields
120
- */
121
- private sanitizeForLogging;
122
- /**
123
- * Calculate delay for retry with exponential backoff
124
- */
125
- private calculateRetryDelay;
126
- /**
127
- * Sleep for specified milliseconds
128
- */
129
- private sleep;
130
- /**
131
- * Perform HTTP request with automatic retry on transient failures
84
+ * Perform HTTP request
132
85
  */
133
86
  request<T>(method: string, endpoint: string, options?: {
134
87
  body?: unknown;
135
88
  headers?: Record<string, string>;
136
89
  params?: Record<string, string | number | boolean | undefined>;
137
- }, retryAttempt?: number): Promise<T>;
90
+ }): Promise<T>;
138
91
  /**
139
92
  * GET request
140
93
  */
@@ -33,22 +33,11 @@ declare class BearerTokenAuth implements AuthStrategy {
33
33
  /**
34
34
  * Session-based authentication (Platform/Admin APIs in browser)
35
35
  * Relies on HTTP-only cookies set by the server
36
- * Optionally supports CSRF token protection
37
36
  */
38
37
  declare class SessionAuth implements AuthStrategy {
39
38
  private sessionToken?;
40
39
  private onUnauthorized?;
41
- private csrfToken?;
42
40
  constructor(sessionToken?: string | undefined, onUnauthorized?: (() => Promise<void>) | undefined);
43
- /**
44
- * Set CSRF token for cross-site request forgery protection
45
- * The token should be obtained from the server after login
46
- */
47
- setCsrfToken(token: string): void;
48
- /**
49
- * Get current CSRF token
50
- */
51
- getCsrfToken(): string | undefined;
52
41
  injectAuth(headers: Headers): void;
53
42
  handleUnauthorized(): Promise<void>;
54
43
  getDescription(): string;
@@ -65,29 +54,12 @@ declare class NoAuth implements AuthStrategy {
65
54
  * Base HTTP client for Marvin APIs
66
55
  */
67
56
 
68
- interface RetryConfig {
69
- /** Maximum number of retry attempts (default: 3) */
70
- maxRetries: number;
71
- /** Initial delay in ms before first retry (default: 1000) */
72
- initialDelay: number;
73
- /** Maximum delay in ms between retries (default: 10000) */
74
- maxDelay: number;
75
- /** HTTP status codes that should trigger a retry (default: [408, 429, 500, 502, 503, 504]) */
76
- retryableStatuses: number[];
77
- }
78
57
  interface HttpClientConfig {
79
58
  baseUrl: string;
80
59
  auth: AuthStrategy;
81
60
  defaultHeaders?: Record<string, string>;
82
61
  credentials?: RequestCredentials;
83
62
  timeout?: number;
84
- debug?: boolean;
85
- retry?: Partial<RetryConfig>;
86
- logger?: {
87
- log: (message: string, ...args: unknown[]) => void;
88
- warn: (message: string, ...args: unknown[]) => void;
89
- error: (message: string, ...args: unknown[]) => void;
90
- };
91
63
  }
92
64
  declare class HttpClient {
93
65
  private baseUrl;
@@ -95,14 +67,7 @@ declare class HttpClient {
95
67
  private defaultHeaders;
96
68
  private credentials;
97
69
  private timeout;
98
- private debug;
99
- private retryConfig;
100
- private logger;
101
70
  constructor(config: HttpClientConfig);
102
- /**
103
- * Validate path parameter to prevent path traversal attacks
104
- */
105
- validatePathParam(param: string | number, paramName?: string): string;
106
71
  /**
107
72
  * Build full URL from endpoint
108
73
  */
@@ -116,25 +81,13 @@ declare class HttpClient {
116
81
  */
117
82
  buildQueryString(params: Record<string, string | number | boolean | undefined>): string;
118
83
  /**
119
- * Sanitize data for logging by redacting sensitive fields
120
- */
121
- private sanitizeForLogging;
122
- /**
123
- * Calculate delay for retry with exponential backoff
124
- */
125
- private calculateRetryDelay;
126
- /**
127
- * Sleep for specified milliseconds
128
- */
129
- private sleep;
130
- /**
131
- * Perform HTTP request with automatic retry on transient failures
84
+ * Perform HTTP request
132
85
  */
133
86
  request<T>(method: string, endpoint: string, options?: {
134
87
  body?: unknown;
135
88
  headers?: Record<string, string>;
136
89
  params?: Record<string, string | number | boolean | undefined>;
137
- }, retryAttempt?: number): Promise<T>;
90
+ }): Promise<T>;
138
91
  /**
139
92
  * GET request
140
93
  */