@demokit-ai/core 0.3.0 → 0.5.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/dist/index.cjs +70 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +97 -6
- package/dist/index.d.ts +97 -6
- package/dist/index.js +70 -8
- package/dist/index.js.map +1 -1
- package/package.json +15 -16
- package/LICENSE +0 -190
package/dist/index.d.cts
CHANGED
|
@@ -81,6 +81,43 @@ interface SessionState {
|
|
|
81
81
|
*/
|
|
82
82
|
declare function createSessionState(): SessionState;
|
|
83
83
|
|
|
84
|
+
/**
|
|
85
|
+
* Configuration for automatic demo mode detection based on URL
|
|
86
|
+
*/
|
|
87
|
+
interface DetectionConfig {
|
|
88
|
+
/**
|
|
89
|
+
* Hostnames that should auto-enable demo mode
|
|
90
|
+
* @example ['demo.myapp.com', 'demo.localhost']
|
|
91
|
+
*/
|
|
92
|
+
subdomains?: string[];
|
|
93
|
+
/**
|
|
94
|
+
* Query parameters that trigger demo mode when present
|
|
95
|
+
* @default ['demo']
|
|
96
|
+
* @example With ['demo'], visiting ?demo=true enables demo mode
|
|
97
|
+
*/
|
|
98
|
+
queryParams?: string[];
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Context passed to the onMutationIntercepted callback
|
|
102
|
+
*/
|
|
103
|
+
interface MutationInterceptedContext {
|
|
104
|
+
/**
|
|
105
|
+
* The full URL of the intercepted request
|
|
106
|
+
*/
|
|
107
|
+
url: string;
|
|
108
|
+
/**
|
|
109
|
+
* HTTP method (POST, PUT, PATCH, DELETE)
|
|
110
|
+
*/
|
|
111
|
+
method: string;
|
|
112
|
+
/**
|
|
113
|
+
* URL parameters extracted from the pattern
|
|
114
|
+
*/
|
|
115
|
+
params: Record<string, string>;
|
|
116
|
+
/**
|
|
117
|
+
* The fixture pattern that matched
|
|
118
|
+
*/
|
|
119
|
+
pattern: string;
|
|
120
|
+
}
|
|
84
121
|
/**
|
|
85
122
|
* Configuration for creating a demo interceptor
|
|
86
123
|
*/
|
|
@@ -120,6 +157,44 @@ interface DemoKitConfig {
|
|
|
120
157
|
* @default 'http://localhost'
|
|
121
158
|
*/
|
|
122
159
|
baseUrl?: string;
|
|
160
|
+
/**
|
|
161
|
+
* Auto-detection configuration for enabling demo mode based on URL
|
|
162
|
+
* When configured, demo mode is automatically enabled on matching subdomains
|
|
163
|
+
* or when specific query parameters are present
|
|
164
|
+
*/
|
|
165
|
+
detection?: DetectionConfig;
|
|
166
|
+
/**
|
|
167
|
+
* Path aliases for matching fixtures across equivalent URL prefixes.
|
|
168
|
+
* Common in Next.js apps where `/api/*` rewrites to `/v1/*`.
|
|
169
|
+
* A fixture defined for `/v1/users` will also match `/api/users`.
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* pathAliases: { '/api/': '/v1/' }
|
|
173
|
+
*/
|
|
174
|
+
pathAliases?: Record<string, string>;
|
|
175
|
+
/**
|
|
176
|
+
* Log a warning when a catch-all pattern (containing `*`) matches a request.
|
|
177
|
+
* Helps identify fixtures that need specific patterns.
|
|
178
|
+
* @default true in development, false in production
|
|
179
|
+
*/
|
|
180
|
+
warnOnCatchAll?: boolean;
|
|
181
|
+
/**
|
|
182
|
+
* Guard callback that controls whether demo mode can be disabled.
|
|
183
|
+
* Return `true` to allow disabling, `false` to prevent it,
|
|
184
|
+
* or a string to prevent it and provide a reason message.
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* canDisable: () => {
|
|
188
|
+
* if (isPublicDemo) return 'Sign up to access your own data'
|
|
189
|
+
* return true
|
|
190
|
+
* }
|
|
191
|
+
*/
|
|
192
|
+
canDisable?: () => boolean | string;
|
|
193
|
+
/**
|
|
194
|
+
* Callback fired when a non-GET request is intercepted by a fixture.
|
|
195
|
+
* Useful for showing "simulated in demo mode" toast notifications.
|
|
196
|
+
*/
|
|
197
|
+
onMutationIntercepted?: (context: MutationInterceptedContext) => void;
|
|
123
198
|
}
|
|
124
199
|
/**
|
|
125
200
|
* Map of URL patterns to fixture handlers
|
|
@@ -194,13 +269,19 @@ interface DemoInterceptor {
|
|
|
194
269
|
*/
|
|
195
270
|
enable(): void;
|
|
196
271
|
/**
|
|
197
|
-
* Disable demo mode - fetches will pass through to the real API
|
|
272
|
+
* Disable demo mode - fetches will pass through to the real API.
|
|
273
|
+
* Returns `true` if disabled successfully, `false` or a string reason
|
|
274
|
+
* if prevented by the `canDisable` guard.
|
|
198
275
|
*/
|
|
199
|
-
disable():
|
|
276
|
+
disable(): boolean | string;
|
|
200
277
|
/**
|
|
201
278
|
* Check if demo mode is currently enabled
|
|
202
279
|
*/
|
|
203
280
|
isEnabled(): boolean;
|
|
281
|
+
/**
|
|
282
|
+
* Check if this is a public demo (auto-detected via subdomain)
|
|
283
|
+
*/
|
|
284
|
+
isPublicDemo(): boolean;
|
|
204
285
|
/**
|
|
205
286
|
* Toggle demo mode state and return the new state
|
|
206
287
|
*/
|
|
@@ -273,8 +354,14 @@ interface RemoteConfig {
|
|
|
273
354
|
*/
|
|
274
355
|
apiKey: string;
|
|
275
356
|
/**
|
|
276
|
-
* DemoKit Cloud API URL
|
|
277
|
-
*
|
|
357
|
+
* DemoKit Cloud API URL (base URL)
|
|
358
|
+
* The SDK will append `/fixtures` to this URL.
|
|
359
|
+
* @example 'https://demokit-cloud.kasava.dev/api'
|
|
360
|
+
* @default 'https://api.demokit.cloud/api'
|
|
361
|
+
*/
|
|
362
|
+
apiUrl?: string;
|
|
363
|
+
/**
|
|
364
|
+
* @deprecated Use apiUrl instead. This is kept for backwards compatibility.
|
|
278
365
|
*/
|
|
279
366
|
cloudUrl?: string;
|
|
280
367
|
/**
|
|
@@ -711,7 +798,11 @@ declare function clearDemoState(key?: string): void;
|
|
|
711
798
|
/**
|
|
712
799
|
* Default DemoKit Cloud API URL
|
|
713
800
|
*/
|
|
714
|
-
declare const
|
|
801
|
+
declare const DEFAULT_API_URL = "https://api.demokit.cloud/api";
|
|
802
|
+
/**
|
|
803
|
+
* @deprecated Use DEFAULT_API_URL instead
|
|
804
|
+
*/
|
|
805
|
+
declare const DEFAULT_CLOUD_URL = "https://api.demokit.cloud/api";
|
|
715
806
|
/**
|
|
716
807
|
* Default request timeout in milliseconds
|
|
717
808
|
*/
|
|
@@ -2875,4 +2966,4 @@ declare namespace checks {
|
|
|
2875
2966
|
export { checks_equals as equals, checks_getTypeName as getTypeName, checks_hasArrayMaxLength as hasArrayMaxLength, checks_hasArrayMinLength as hasArrayMinLength, checks_hasMaxLength as hasMaxLength, checks_hasMaximum as hasMaximum, checks_hasMinLength as hasMinLength, checks_hasMinimum as hasMinimum, checks_isAfterOrEqual as isAfterOrEqual, checks_isArray as isArray, checks_isArrayNotEmpty as isArrayNotEmpty, checks_isBeforeOrEqual as isBeforeOrEqual, checks_isBoolean as isBoolean, checks_isDate as isDate, checks_isDateTime as isDateTime, checks_isEmail as isEmail, checks_isEmptyString as isEmptyString, checks_isISO8601 as isISO8601, checks_isInEnum as isInEnum, checks_isInteger as isInteger, checks_isNull as isNull, checks_isNullish as isNullish, checks_isNumber as isNumber, checks_isObject as isObject, checks_isString as isString, checks_isURL as isURL, checks_isUUID as isUUID, checks_isUndefined as isUndefined, checks_matchesPattern as matchesPattern };
|
|
2876
2967
|
}
|
|
2877
2968
|
|
|
2878
|
-
export { type AppContext, type BooleanFieldRule, type Character, type CloudFixtureResponse, type CodebaseFile, DEFAULT_CLOUD_URL, DEFAULT_MAX_RETRIES, DEFAULT_STORAGE_KEY, DEFAULT_TIMEOUT, type DataModel, type Dataset, type DatasetFieldRule, type DemoData, type DemoInterceptor, type DemoKitConfig, type DemoKitRemoteConfig, type DemoNarrative, type DemoState, type DemoStateStore, type DemoStateStoreOptions, type DemokitSchema, type Endpoint, type EndpointMapping, type EntityContext, type EnumFieldRule, FORMAT_PATTERNS, FORMAT_PRIORITY, type FieldRule, FileParseError, type FixtureHandler, type FixtureMap, FormatDetectionError, type FormatDetectionPatterns, type FormatDetectionResult, type GenerationLevel, type GenerationMetadata, type GenerationOptions, type GenerationResult, type GenerationRulesConfig, type HttpMethod, type IntegerFieldRule, type MatchResult, type MergeConflict, type MergeOptions, type MergeResult, type MetricTarget, type ModelData, type ModelSourceMap, type ModelType, type NumberFieldRule, type OutputOptions, type ParameterDef, type ParseCSVResult, type ParseOptions, type ParseResult, type ParseSchemaOptions, type ParseWarning, type ParsedPattern, type PropertyDef, type PropertyDiff, type PropertyType, type QueryKey, type QueryKeyElement, type QueryKeyMatchResult, type Relationship, type RelationshipDetectionMethod, type RelationshipSide, type RelationshipTarget, type RelationshipType, type RemoteConfig, RemoteFetchError, type RemoteLoadingState, type RequestBody, type RequestContext, type ResponseDef, type RuleGeneratorConfig, type SafeResult, type SchemaDiff, type SchemaDiffItem, type SchemaFormat, type SchemaInfo, SchemaMergeError, SchemaParseError, type SchemaRef, type SchemaSource, SchemaValidationError, type SessionState, type StringFieldRule, type TimelineEvent, type ValidationCheck, type ValidationError, type ValidationErrorType, type ValidationResult, type ValidationRule, type ValidationStats, type ValidationWarning, type ValidationWarningType, type ValidatorOptions, aggregateWarnings, buildFixtureMap, checks, clearDemoState, clearPatternCache, createAppContext, createDemoInterceptor, createDemoState, createDemoStateStore, createHandlerForMapping, createRemoteFixtures, createSessionState, describeRule, detectFormat, detectFormatFromFiles, detectRelationshipFromExtension, detectRelationshipFromNaming, detectRelationshipFromRef, detectRelationships, diffSchemas, errorToWarning, extractRefName, fetchCloudFixtures, findMatchingPattern, findMatchingQueryKeyPattern, formatAsCSV, formatAsJSON, formatAsSQL, formatAsTypeScript, generateCuid, generateDatasetId, generateDemoData, generateId, generateIdForModel, generatePrefixedId, generateRulesFromSchema, generateSeededUUID, generateUUID, generateUlid, generateValue, getModelDependencyOrder, getRelationshipRules, getRelationshipsForModel, getRequiredFieldRules, groupFilesByFormat, groupRulesByModel, inferAppContext, isModelReferenced, isRecoverableError, isSchemaRef, isValidApiKey, loadDemoState, matchQueryKey, matchUrl, mergeAppContext, mergeFixtures, mergeSchemas, parseCSV, parseDrizzle, parseGraphQL, parseNextJS, parseOpenAPIFromObject, parseOpenAPIFromPath, parseOpenAPIFromString, parsePrisma, parseSchema, parseSchemaMultiFormat, parseSupabase, parseTRPC, parseTypeScript, parseUrlPattern, parseZod, safeExecute, safeProcessMany, saveDemoState, validateData, validateDatasetName, validateTimestampOrder };
|
|
2969
|
+
export { type AppContext, type BooleanFieldRule, type Character, type CloudFixtureResponse, type CodebaseFile, DEFAULT_API_URL, DEFAULT_CLOUD_URL, DEFAULT_MAX_RETRIES, DEFAULT_STORAGE_KEY, DEFAULT_TIMEOUT, type DataModel, type Dataset, type DatasetFieldRule, type DemoData, type DemoInterceptor, type DemoKitConfig, type DemoKitRemoteConfig, type DemoNarrative, type DemoState, type DemoStateStore, type DemoStateStoreOptions, type DemokitSchema, type DetectionConfig, type Endpoint, type EndpointMapping, type EntityContext, type EnumFieldRule, FORMAT_PATTERNS, FORMAT_PRIORITY, type FieldRule, FileParseError, type FixtureHandler, type FixtureMap, FormatDetectionError, type FormatDetectionPatterns, type FormatDetectionResult, type GenerationLevel, type GenerationMetadata, type GenerationOptions, type GenerationResult, type GenerationRulesConfig, type HttpMethod, type IntegerFieldRule, type MatchResult, type MergeConflict, type MergeOptions, type MergeResult, type MetricTarget, type ModelData, type ModelSourceMap, type ModelType, type MutationInterceptedContext, type NumberFieldRule, type OutputOptions, type ParameterDef, type ParseCSVResult, type ParseOptions, type ParseResult, type ParseSchemaOptions, type ParseWarning, type ParsedPattern, type PropertyDef, type PropertyDiff, type PropertyType, type QueryKey, type QueryKeyElement, type QueryKeyMatchResult, type Relationship, type RelationshipDetectionMethod, type RelationshipSide, type RelationshipTarget, type RelationshipType, type RemoteConfig, RemoteFetchError, type RemoteLoadingState, type RequestBody, type RequestContext, type ResponseDef, type RuleGeneratorConfig, type SafeResult, type SchemaDiff, type SchemaDiffItem, type SchemaFormat, type SchemaInfo, SchemaMergeError, SchemaParseError, type SchemaRef, type SchemaSource, SchemaValidationError, type SessionState, type StringFieldRule, type TimelineEvent, type ValidationCheck, type ValidationError, type ValidationErrorType, type ValidationResult, type ValidationRule, type ValidationStats, type ValidationWarning, type ValidationWarningType, type ValidatorOptions, aggregateWarnings, buildFixtureMap, checks, clearDemoState, clearPatternCache, createAppContext, createDemoInterceptor, createDemoState, createDemoStateStore, createHandlerForMapping, createRemoteFixtures, createSessionState, describeRule, detectFormat, detectFormatFromFiles, detectRelationshipFromExtension, detectRelationshipFromNaming, detectRelationshipFromRef, detectRelationships, diffSchemas, errorToWarning, extractRefName, fetchCloudFixtures, findMatchingPattern, findMatchingQueryKeyPattern, formatAsCSV, formatAsJSON, formatAsSQL, formatAsTypeScript, generateCuid, generateDatasetId, generateDemoData, generateId, generateIdForModel, generatePrefixedId, generateRulesFromSchema, generateSeededUUID, generateUUID, generateUlid, generateValue, getModelDependencyOrder, getRelationshipRules, getRelationshipsForModel, getRequiredFieldRules, groupFilesByFormat, groupRulesByModel, inferAppContext, isModelReferenced, isRecoverableError, isSchemaRef, isValidApiKey, loadDemoState, matchQueryKey, matchUrl, mergeAppContext, mergeFixtures, mergeSchemas, parseCSV, parseDrizzle, parseGraphQL, parseNextJS, parseOpenAPIFromObject, parseOpenAPIFromPath, parseOpenAPIFromString, parsePrisma, parseSchema, parseSchemaMultiFormat, parseSupabase, parseTRPC, parseTypeScript, parseUrlPattern, parseZod, safeExecute, safeProcessMany, saveDemoState, validateData, validateDatasetName, validateTimestampOrder };
|
package/dist/index.d.ts
CHANGED
|
@@ -81,6 +81,43 @@ interface SessionState {
|
|
|
81
81
|
*/
|
|
82
82
|
declare function createSessionState(): SessionState;
|
|
83
83
|
|
|
84
|
+
/**
|
|
85
|
+
* Configuration for automatic demo mode detection based on URL
|
|
86
|
+
*/
|
|
87
|
+
interface DetectionConfig {
|
|
88
|
+
/**
|
|
89
|
+
* Hostnames that should auto-enable demo mode
|
|
90
|
+
* @example ['demo.myapp.com', 'demo.localhost']
|
|
91
|
+
*/
|
|
92
|
+
subdomains?: string[];
|
|
93
|
+
/**
|
|
94
|
+
* Query parameters that trigger demo mode when present
|
|
95
|
+
* @default ['demo']
|
|
96
|
+
* @example With ['demo'], visiting ?demo=true enables demo mode
|
|
97
|
+
*/
|
|
98
|
+
queryParams?: string[];
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Context passed to the onMutationIntercepted callback
|
|
102
|
+
*/
|
|
103
|
+
interface MutationInterceptedContext {
|
|
104
|
+
/**
|
|
105
|
+
* The full URL of the intercepted request
|
|
106
|
+
*/
|
|
107
|
+
url: string;
|
|
108
|
+
/**
|
|
109
|
+
* HTTP method (POST, PUT, PATCH, DELETE)
|
|
110
|
+
*/
|
|
111
|
+
method: string;
|
|
112
|
+
/**
|
|
113
|
+
* URL parameters extracted from the pattern
|
|
114
|
+
*/
|
|
115
|
+
params: Record<string, string>;
|
|
116
|
+
/**
|
|
117
|
+
* The fixture pattern that matched
|
|
118
|
+
*/
|
|
119
|
+
pattern: string;
|
|
120
|
+
}
|
|
84
121
|
/**
|
|
85
122
|
* Configuration for creating a demo interceptor
|
|
86
123
|
*/
|
|
@@ -120,6 +157,44 @@ interface DemoKitConfig {
|
|
|
120
157
|
* @default 'http://localhost'
|
|
121
158
|
*/
|
|
122
159
|
baseUrl?: string;
|
|
160
|
+
/**
|
|
161
|
+
* Auto-detection configuration for enabling demo mode based on URL
|
|
162
|
+
* When configured, demo mode is automatically enabled on matching subdomains
|
|
163
|
+
* or when specific query parameters are present
|
|
164
|
+
*/
|
|
165
|
+
detection?: DetectionConfig;
|
|
166
|
+
/**
|
|
167
|
+
* Path aliases for matching fixtures across equivalent URL prefixes.
|
|
168
|
+
* Common in Next.js apps where `/api/*` rewrites to `/v1/*`.
|
|
169
|
+
* A fixture defined for `/v1/users` will also match `/api/users`.
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* pathAliases: { '/api/': '/v1/' }
|
|
173
|
+
*/
|
|
174
|
+
pathAliases?: Record<string, string>;
|
|
175
|
+
/**
|
|
176
|
+
* Log a warning when a catch-all pattern (containing `*`) matches a request.
|
|
177
|
+
* Helps identify fixtures that need specific patterns.
|
|
178
|
+
* @default true in development, false in production
|
|
179
|
+
*/
|
|
180
|
+
warnOnCatchAll?: boolean;
|
|
181
|
+
/**
|
|
182
|
+
* Guard callback that controls whether demo mode can be disabled.
|
|
183
|
+
* Return `true` to allow disabling, `false` to prevent it,
|
|
184
|
+
* or a string to prevent it and provide a reason message.
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* canDisable: () => {
|
|
188
|
+
* if (isPublicDemo) return 'Sign up to access your own data'
|
|
189
|
+
* return true
|
|
190
|
+
* }
|
|
191
|
+
*/
|
|
192
|
+
canDisable?: () => boolean | string;
|
|
193
|
+
/**
|
|
194
|
+
* Callback fired when a non-GET request is intercepted by a fixture.
|
|
195
|
+
* Useful for showing "simulated in demo mode" toast notifications.
|
|
196
|
+
*/
|
|
197
|
+
onMutationIntercepted?: (context: MutationInterceptedContext) => void;
|
|
123
198
|
}
|
|
124
199
|
/**
|
|
125
200
|
* Map of URL patterns to fixture handlers
|
|
@@ -194,13 +269,19 @@ interface DemoInterceptor {
|
|
|
194
269
|
*/
|
|
195
270
|
enable(): void;
|
|
196
271
|
/**
|
|
197
|
-
* Disable demo mode - fetches will pass through to the real API
|
|
272
|
+
* Disable demo mode - fetches will pass through to the real API.
|
|
273
|
+
* Returns `true` if disabled successfully, `false` or a string reason
|
|
274
|
+
* if prevented by the `canDisable` guard.
|
|
198
275
|
*/
|
|
199
|
-
disable():
|
|
276
|
+
disable(): boolean | string;
|
|
200
277
|
/**
|
|
201
278
|
* Check if demo mode is currently enabled
|
|
202
279
|
*/
|
|
203
280
|
isEnabled(): boolean;
|
|
281
|
+
/**
|
|
282
|
+
* Check if this is a public demo (auto-detected via subdomain)
|
|
283
|
+
*/
|
|
284
|
+
isPublicDemo(): boolean;
|
|
204
285
|
/**
|
|
205
286
|
* Toggle demo mode state and return the new state
|
|
206
287
|
*/
|
|
@@ -273,8 +354,14 @@ interface RemoteConfig {
|
|
|
273
354
|
*/
|
|
274
355
|
apiKey: string;
|
|
275
356
|
/**
|
|
276
|
-
* DemoKit Cloud API URL
|
|
277
|
-
*
|
|
357
|
+
* DemoKit Cloud API URL (base URL)
|
|
358
|
+
* The SDK will append `/fixtures` to this URL.
|
|
359
|
+
* @example 'https://demokit-cloud.kasava.dev/api'
|
|
360
|
+
* @default 'https://api.demokit.cloud/api'
|
|
361
|
+
*/
|
|
362
|
+
apiUrl?: string;
|
|
363
|
+
/**
|
|
364
|
+
* @deprecated Use apiUrl instead. This is kept for backwards compatibility.
|
|
278
365
|
*/
|
|
279
366
|
cloudUrl?: string;
|
|
280
367
|
/**
|
|
@@ -711,7 +798,11 @@ declare function clearDemoState(key?: string): void;
|
|
|
711
798
|
/**
|
|
712
799
|
* Default DemoKit Cloud API URL
|
|
713
800
|
*/
|
|
714
|
-
declare const
|
|
801
|
+
declare const DEFAULT_API_URL = "https://api.demokit.cloud/api";
|
|
802
|
+
/**
|
|
803
|
+
* @deprecated Use DEFAULT_API_URL instead
|
|
804
|
+
*/
|
|
805
|
+
declare const DEFAULT_CLOUD_URL = "https://api.demokit.cloud/api";
|
|
715
806
|
/**
|
|
716
807
|
* Default request timeout in milliseconds
|
|
717
808
|
*/
|
|
@@ -2875,4 +2966,4 @@ declare namespace checks {
|
|
|
2875
2966
|
export { checks_equals as equals, checks_getTypeName as getTypeName, checks_hasArrayMaxLength as hasArrayMaxLength, checks_hasArrayMinLength as hasArrayMinLength, checks_hasMaxLength as hasMaxLength, checks_hasMaximum as hasMaximum, checks_hasMinLength as hasMinLength, checks_hasMinimum as hasMinimum, checks_isAfterOrEqual as isAfterOrEqual, checks_isArray as isArray, checks_isArrayNotEmpty as isArrayNotEmpty, checks_isBeforeOrEqual as isBeforeOrEqual, checks_isBoolean as isBoolean, checks_isDate as isDate, checks_isDateTime as isDateTime, checks_isEmail as isEmail, checks_isEmptyString as isEmptyString, checks_isISO8601 as isISO8601, checks_isInEnum as isInEnum, checks_isInteger as isInteger, checks_isNull as isNull, checks_isNullish as isNullish, checks_isNumber as isNumber, checks_isObject as isObject, checks_isString as isString, checks_isURL as isURL, checks_isUUID as isUUID, checks_isUndefined as isUndefined, checks_matchesPattern as matchesPattern };
|
|
2876
2967
|
}
|
|
2877
2968
|
|
|
2878
|
-
export { type AppContext, type BooleanFieldRule, type Character, type CloudFixtureResponse, type CodebaseFile, DEFAULT_CLOUD_URL, DEFAULT_MAX_RETRIES, DEFAULT_STORAGE_KEY, DEFAULT_TIMEOUT, type DataModel, type Dataset, type DatasetFieldRule, type DemoData, type DemoInterceptor, type DemoKitConfig, type DemoKitRemoteConfig, type DemoNarrative, type DemoState, type DemoStateStore, type DemoStateStoreOptions, type DemokitSchema, type Endpoint, type EndpointMapping, type EntityContext, type EnumFieldRule, FORMAT_PATTERNS, FORMAT_PRIORITY, type FieldRule, FileParseError, type FixtureHandler, type FixtureMap, FormatDetectionError, type FormatDetectionPatterns, type FormatDetectionResult, type GenerationLevel, type GenerationMetadata, type GenerationOptions, type GenerationResult, type GenerationRulesConfig, type HttpMethod, type IntegerFieldRule, type MatchResult, type MergeConflict, type MergeOptions, type MergeResult, type MetricTarget, type ModelData, type ModelSourceMap, type ModelType, type NumberFieldRule, type OutputOptions, type ParameterDef, type ParseCSVResult, type ParseOptions, type ParseResult, type ParseSchemaOptions, type ParseWarning, type ParsedPattern, type PropertyDef, type PropertyDiff, type PropertyType, type QueryKey, type QueryKeyElement, type QueryKeyMatchResult, type Relationship, type RelationshipDetectionMethod, type RelationshipSide, type RelationshipTarget, type RelationshipType, type RemoteConfig, RemoteFetchError, type RemoteLoadingState, type RequestBody, type RequestContext, type ResponseDef, type RuleGeneratorConfig, type SafeResult, type SchemaDiff, type SchemaDiffItem, type SchemaFormat, type SchemaInfo, SchemaMergeError, SchemaParseError, type SchemaRef, type SchemaSource, SchemaValidationError, type SessionState, type StringFieldRule, type TimelineEvent, type ValidationCheck, type ValidationError, type ValidationErrorType, type ValidationResult, type ValidationRule, type ValidationStats, type ValidationWarning, type ValidationWarningType, type ValidatorOptions, aggregateWarnings, buildFixtureMap, checks, clearDemoState, clearPatternCache, createAppContext, createDemoInterceptor, createDemoState, createDemoStateStore, createHandlerForMapping, createRemoteFixtures, createSessionState, describeRule, detectFormat, detectFormatFromFiles, detectRelationshipFromExtension, detectRelationshipFromNaming, detectRelationshipFromRef, detectRelationships, diffSchemas, errorToWarning, extractRefName, fetchCloudFixtures, findMatchingPattern, findMatchingQueryKeyPattern, formatAsCSV, formatAsJSON, formatAsSQL, formatAsTypeScript, generateCuid, generateDatasetId, generateDemoData, generateId, generateIdForModel, generatePrefixedId, generateRulesFromSchema, generateSeededUUID, generateUUID, generateUlid, generateValue, getModelDependencyOrder, getRelationshipRules, getRelationshipsForModel, getRequiredFieldRules, groupFilesByFormat, groupRulesByModel, inferAppContext, isModelReferenced, isRecoverableError, isSchemaRef, isValidApiKey, loadDemoState, matchQueryKey, matchUrl, mergeAppContext, mergeFixtures, mergeSchemas, parseCSV, parseDrizzle, parseGraphQL, parseNextJS, parseOpenAPIFromObject, parseOpenAPIFromPath, parseOpenAPIFromString, parsePrisma, parseSchema, parseSchemaMultiFormat, parseSupabase, parseTRPC, parseTypeScript, parseUrlPattern, parseZod, safeExecute, safeProcessMany, saveDemoState, validateData, validateDatasetName, validateTimestampOrder };
|
|
2969
|
+
export { type AppContext, type BooleanFieldRule, type Character, type CloudFixtureResponse, type CodebaseFile, DEFAULT_API_URL, DEFAULT_CLOUD_URL, DEFAULT_MAX_RETRIES, DEFAULT_STORAGE_KEY, DEFAULT_TIMEOUT, type DataModel, type Dataset, type DatasetFieldRule, type DemoData, type DemoInterceptor, type DemoKitConfig, type DemoKitRemoteConfig, type DemoNarrative, type DemoState, type DemoStateStore, type DemoStateStoreOptions, type DemokitSchema, type DetectionConfig, type Endpoint, type EndpointMapping, type EntityContext, type EnumFieldRule, FORMAT_PATTERNS, FORMAT_PRIORITY, type FieldRule, FileParseError, type FixtureHandler, type FixtureMap, FormatDetectionError, type FormatDetectionPatterns, type FormatDetectionResult, type GenerationLevel, type GenerationMetadata, type GenerationOptions, type GenerationResult, type GenerationRulesConfig, type HttpMethod, type IntegerFieldRule, type MatchResult, type MergeConflict, type MergeOptions, type MergeResult, type MetricTarget, type ModelData, type ModelSourceMap, type ModelType, type MutationInterceptedContext, type NumberFieldRule, type OutputOptions, type ParameterDef, type ParseCSVResult, type ParseOptions, type ParseResult, type ParseSchemaOptions, type ParseWarning, type ParsedPattern, type PropertyDef, type PropertyDiff, type PropertyType, type QueryKey, type QueryKeyElement, type QueryKeyMatchResult, type Relationship, type RelationshipDetectionMethod, type RelationshipSide, type RelationshipTarget, type RelationshipType, type RemoteConfig, RemoteFetchError, type RemoteLoadingState, type RequestBody, type RequestContext, type ResponseDef, type RuleGeneratorConfig, type SafeResult, type SchemaDiff, type SchemaDiffItem, type SchemaFormat, type SchemaInfo, SchemaMergeError, SchemaParseError, type SchemaRef, type SchemaSource, SchemaValidationError, type SessionState, type StringFieldRule, type TimelineEvent, type ValidationCheck, type ValidationError, type ValidationErrorType, type ValidationResult, type ValidationRule, type ValidationStats, type ValidationWarning, type ValidationWarningType, type ValidatorOptions, aggregateWarnings, buildFixtureMap, checks, clearDemoState, clearPatternCache, createAppContext, createDemoInterceptor, createDemoState, createDemoStateStore, createHandlerForMapping, createRemoteFixtures, createSessionState, describeRule, detectFormat, detectFormatFromFiles, detectRelationshipFromExtension, detectRelationshipFromNaming, detectRelationshipFromRef, detectRelationships, diffSchemas, errorToWarning, extractRefName, fetchCloudFixtures, findMatchingPattern, findMatchingQueryKeyPattern, formatAsCSV, formatAsJSON, formatAsSQL, formatAsTypeScript, generateCuid, generateDatasetId, generateDemoData, generateId, generateIdForModel, generatePrefixedId, generateRulesFromSchema, generateSeededUUID, generateUUID, generateUlid, generateValue, getModelDependencyOrder, getRelationshipRules, getRelationshipsForModel, getRequiredFieldRules, groupFilesByFormat, groupRulesByModel, inferAppContext, isModelReferenced, isRecoverableError, isSchemaRef, isValidApiKey, loadDemoState, matchQueryKey, matchUrl, mergeAppContext, mergeFixtures, mergeSchemas, parseCSV, parseDrizzle, parseGraphQL, parseNextJS, parseOpenAPIFromObject, parseOpenAPIFromPath, parseOpenAPIFromString, parsePrisma, parseSchema, parseSchemaMultiFormat, parseSupabase, parseTRPC, parseTypeScript, parseUrlPattern, parseZod, safeExecute, safeProcessMany, saveDemoState, validateData, validateDatasetName, validateTimestampOrder };
|
package/dist/index.js
CHANGED
|
@@ -330,6 +330,26 @@ function extractUrl(input, baseUrl) {
|
|
|
330
330
|
}
|
|
331
331
|
return baseUrl;
|
|
332
332
|
}
|
|
333
|
+
function detectDemoMode(detection) {
|
|
334
|
+
if (!detection || typeof window === "undefined") {
|
|
335
|
+
return { detected: false, isPublicDemo: false };
|
|
336
|
+
}
|
|
337
|
+
if (detection.subdomains?.length) {
|
|
338
|
+
const hostname = window.location.hostname;
|
|
339
|
+
if (detection.subdomains.some((sub) => hostname === sub)) {
|
|
340
|
+
return { detected: true, isPublicDemo: true };
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
const queryParams = detection.queryParams ?? ["demo"];
|
|
344
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
345
|
+
for (const param of queryParams) {
|
|
346
|
+
const value = searchParams.get(param);
|
|
347
|
+
if (value !== null && value !== "false") {
|
|
348
|
+
return { detected: true, isPublicDemo: false };
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
return { detected: false, isPublicDemo: false };
|
|
352
|
+
}
|
|
333
353
|
function createDemoInterceptor(config) {
|
|
334
354
|
const {
|
|
335
355
|
fixtures: initialFixtures,
|
|
@@ -337,9 +357,15 @@ function createDemoInterceptor(config) {
|
|
|
337
357
|
onEnable,
|
|
338
358
|
onDisable,
|
|
339
359
|
initialEnabled,
|
|
340
|
-
baseUrl = "http://localhost"
|
|
360
|
+
baseUrl = "http://localhost",
|
|
361
|
+
detection,
|
|
362
|
+
canDisable,
|
|
363
|
+
onMutationIntercepted,
|
|
364
|
+
pathAliases,
|
|
365
|
+
warnOnCatchAll = typeof process !== "undefined" && process.env?.NODE_ENV !== "production"
|
|
341
366
|
} = config;
|
|
342
|
-
|
|
367
|
+
const detectionResult = detectDemoMode(detection);
|
|
368
|
+
let enabled = detectionResult.detected || (initialEnabled ?? loadDemoState(storageKey));
|
|
343
369
|
let currentFixtures = { ...initialFixtures };
|
|
344
370
|
let sessionState = createSessionState();
|
|
345
371
|
let originalFetch = null;
|
|
@@ -355,11 +381,25 @@ function createDemoInterceptor(config) {
|
|
|
355
381
|
}
|
|
356
382
|
const method = init?.method?.toUpperCase() || "GET";
|
|
357
383
|
const pathname = extractPathname(input, baseUrl);
|
|
358
|
-
|
|
384
|
+
let match = findMatchingPattern(currentFixtures, method, pathname);
|
|
385
|
+
if (!match && pathAliases) {
|
|
386
|
+
for (const [from, to] of Object.entries(pathAliases)) {
|
|
387
|
+
if (pathname.startsWith(from)) {
|
|
388
|
+
const aliasedPath = to + pathname.slice(from.length);
|
|
389
|
+
match = findMatchingPattern(currentFixtures, method, aliasedPath);
|
|
390
|
+
if (match) break;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
359
394
|
if (!match) {
|
|
360
395
|
return originalFetch(input, init);
|
|
361
396
|
}
|
|
362
397
|
const [pattern, matchResult] = match;
|
|
398
|
+
if (warnOnCatchAll && pattern.includes("*")) {
|
|
399
|
+
console.warn(
|
|
400
|
+
`[DemoKit] Catch-all fixture matched: ${method} ${pathname} \u2192 "${pattern}". Consider adding a specific fixture.`
|
|
401
|
+
);
|
|
402
|
+
}
|
|
363
403
|
const handler = currentFixtures[pattern];
|
|
364
404
|
const url = extractUrl(input, baseUrl);
|
|
365
405
|
const headers = new Headers(init?.headers);
|
|
@@ -379,6 +419,14 @@ function createDemoInterceptor(config) {
|
|
|
379
419
|
headers,
|
|
380
420
|
session: sessionState
|
|
381
421
|
};
|
|
422
|
+
if (method !== "GET" && onMutationIntercepted) {
|
|
423
|
+
onMutationIntercepted({
|
|
424
|
+
url,
|
|
425
|
+
method,
|
|
426
|
+
params: matchResult.params,
|
|
427
|
+
pattern
|
|
428
|
+
});
|
|
429
|
+
}
|
|
382
430
|
let result;
|
|
383
431
|
try {
|
|
384
432
|
if (typeof handler === "function") {
|
|
@@ -414,14 +462,24 @@ function createDemoInterceptor(config) {
|
|
|
414
462
|
onEnable?.();
|
|
415
463
|
},
|
|
416
464
|
disable() {
|
|
417
|
-
if (!enabled) return;
|
|
465
|
+
if (!enabled) return true;
|
|
466
|
+
if (canDisable) {
|
|
467
|
+
const result = canDisable();
|
|
468
|
+
if (result !== true) {
|
|
469
|
+
return result;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
418
472
|
enabled = false;
|
|
419
473
|
saveDemoState(storageKey, false);
|
|
420
474
|
onDisable?.();
|
|
475
|
+
return true;
|
|
421
476
|
},
|
|
422
477
|
isEnabled() {
|
|
423
478
|
return enabled;
|
|
424
479
|
},
|
|
480
|
+
isPublicDemo() {
|
|
481
|
+
return detectionResult.isPublicDemo;
|
|
482
|
+
},
|
|
425
483
|
toggle() {
|
|
426
484
|
if (enabled) {
|
|
427
485
|
this.disable();
|
|
@@ -524,7 +582,8 @@ function createDemoStateStore(options = {}) {
|
|
|
524
582
|
}
|
|
525
583
|
|
|
526
584
|
// src/remote.ts
|
|
527
|
-
var
|
|
585
|
+
var DEFAULT_API_URL = "https://api.demokit.cloud/api";
|
|
586
|
+
var DEFAULT_CLOUD_URL = DEFAULT_API_URL;
|
|
528
587
|
var DEFAULT_TIMEOUT = 1e4;
|
|
529
588
|
var DEFAULT_MAX_RETRIES = 3;
|
|
530
589
|
function isValidApiKey(apiKey) {
|
|
@@ -547,13 +606,16 @@ function getBackoffDelay(attempt, baseDelay = 1e3) {
|
|
|
547
606
|
async function fetchCloudFixtures(config) {
|
|
548
607
|
const {
|
|
549
608
|
apiKey,
|
|
550
|
-
|
|
609
|
+
apiUrl,
|
|
610
|
+
cloudUrl,
|
|
611
|
+
// deprecated, for backwards compatibility
|
|
551
612
|
onError,
|
|
552
613
|
onLoad,
|
|
553
614
|
timeout = DEFAULT_TIMEOUT,
|
|
554
615
|
retry = true,
|
|
555
616
|
maxRetries = DEFAULT_MAX_RETRIES
|
|
556
617
|
} = config;
|
|
618
|
+
const baseUrl = apiUrl || cloudUrl || DEFAULT_API_URL;
|
|
557
619
|
if (!isValidApiKey(apiKey)) {
|
|
558
620
|
const error = new RemoteFetchError(
|
|
559
621
|
"Invalid API key format. Expected format: dk_live_xxx",
|
|
@@ -563,7 +625,7 @@ async function fetchCloudFixtures(config) {
|
|
|
563
625
|
onError?.(error);
|
|
564
626
|
throw error;
|
|
565
627
|
}
|
|
566
|
-
const url = `${
|
|
628
|
+
const url = `${baseUrl.replace(/\/$/, "")}/fixtures`;
|
|
567
629
|
let lastError = null;
|
|
568
630
|
const maxAttempts = retry ? maxRetries : 1;
|
|
569
631
|
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
@@ -6847,6 +6909,6 @@ function getRequiredFieldRules(rules) {
|
|
|
6847
6909
|
return rules.filter((rule) => rule.required);
|
|
6848
6910
|
}
|
|
6849
6911
|
|
|
6850
|
-
export { DEFAULT_CLOUD_URL, DEFAULT_MAX_RETRIES, DEFAULT_STORAGE_KEY, DEFAULT_TIMEOUT, FORMAT_PATTERNS, FORMAT_PRIORITY, FileParseError, FormatDetectionError, RemoteFetchError, SchemaMergeError, SchemaParseError, SchemaValidationError, aggregateWarnings, buildFixtureMap, checks_exports as checks, clearDemoState, clearPatternCache, createAppContext, createDemoInterceptor, createDemoState, createDemoStateStore, createHandlerForMapping, createRemoteFixtures, createSessionState, describeRule, detectFormat, detectFormatFromFiles, detectRelationshipFromExtension, detectRelationshipFromNaming, detectRelationshipFromRef, detectRelationships, diffSchemas, errorToWarning, extractRefName, fetchCloudFixtures, findMatchingPattern, findMatchingQueryKeyPattern, formatAsCSV, formatAsJSON, formatAsSQL, formatAsTypeScript, generateCuid, generateDatasetId, generateDemoData, generateId, generateIdForModel, generatePrefixedId, generateRulesFromSchema, generateSeededUUID, generateUUID, generateUlid, generateValue, getModelDependencyOrder, getRelationshipRules, getRelationshipsForModel, getRequiredFieldRules, groupFilesByFormat, groupRulesByModel, inferAppContext, isModelReferenced, isRecoverableError, isSchemaRef, isValidApiKey, loadDemoState, matchQueryKey, matchUrl, mergeAppContext, mergeFixtures, mergeSchemas, parseCSV, parseDrizzle, parseGraphQL, parseNextJS, parseOpenAPIFromObject, parseOpenAPIFromPath, parseOpenAPIFromString, parsePrisma, parseSchema, parseSchemaMultiFormat, parseSupabase, parseTRPC, parseTypeScript, parseUrlPattern, parseZod, safeExecute, safeProcessMany, saveDemoState, validateData, validateDatasetName, validateTimestampOrder };
|
|
6912
|
+
export { DEFAULT_API_URL, DEFAULT_CLOUD_URL, DEFAULT_MAX_RETRIES, DEFAULT_STORAGE_KEY, DEFAULT_TIMEOUT, FORMAT_PATTERNS, FORMAT_PRIORITY, FileParseError, FormatDetectionError, RemoteFetchError, SchemaMergeError, SchemaParseError, SchemaValidationError, aggregateWarnings, buildFixtureMap, checks_exports as checks, clearDemoState, clearPatternCache, createAppContext, createDemoInterceptor, createDemoState, createDemoStateStore, createHandlerForMapping, createRemoteFixtures, createSessionState, describeRule, detectFormat, detectFormatFromFiles, detectRelationshipFromExtension, detectRelationshipFromNaming, detectRelationshipFromRef, detectRelationships, diffSchemas, errorToWarning, extractRefName, fetchCloudFixtures, findMatchingPattern, findMatchingQueryKeyPattern, formatAsCSV, formatAsJSON, formatAsSQL, formatAsTypeScript, generateCuid, generateDatasetId, generateDemoData, generateId, generateIdForModel, generatePrefixedId, generateRulesFromSchema, generateSeededUUID, generateUUID, generateUlid, generateValue, getModelDependencyOrder, getRelationshipRules, getRelationshipsForModel, getRequiredFieldRules, groupFilesByFormat, groupRulesByModel, inferAppContext, isModelReferenced, isRecoverableError, isSchemaRef, isValidApiKey, loadDemoState, matchQueryKey, matchUrl, mergeAppContext, mergeFixtures, mergeSchemas, parseCSV, parseDrizzle, parseGraphQL, parseNextJS, parseOpenAPIFromObject, parseOpenAPIFromPath, parseOpenAPIFromString, parsePrisma, parseSchema, parseSchemaMultiFormat, parseSupabase, parseTRPC, parseTypeScript, parseUrlPattern, parseZod, safeExecute, safeProcessMany, saveDemoState, validateData, validateDatasetName, validateTimestampOrder };
|
|
6851
6913
|
//# sourceMappingURL=index.js.map
|
|
6852
6914
|
//# sourceMappingURL=index.js.map
|