@mobile-reality/mdma-runtime 0.1.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.
Files changed (66) hide show
  1. package/LICENSE +21 -0
  2. package/dist/attachable/registry.d.ts +37 -0
  3. package/dist/attachable/registry.d.ts.map +1 -0
  4. package/dist/attachable/registry.js +19 -0
  5. package/dist/attachable/registry.js.map +1 -0
  6. package/dist/compliance/compliance-reporter.d.ts +20 -0
  7. package/dist/compliance/compliance-reporter.d.ts.map +1 -0
  8. package/dist/compliance/compliance-reporter.js +69 -0
  9. package/dist/compliance/compliance-reporter.js.map +1 -0
  10. package/dist/core/binding-resolver.d.ts +7 -0
  11. package/dist/core/binding-resolver.d.ts.map +1 -0
  12. package/dist/core/binding-resolver.js +29 -0
  13. package/dist/core/binding-resolver.js.map +1 -0
  14. package/dist/core/document-store.d.ts +32 -0
  15. package/dist/core/document-store.d.ts.map +1 -0
  16. package/dist/core/document-store.js +251 -0
  17. package/dist/core/document-store.js.map +1 -0
  18. package/dist/core/event-bus.d.ts +11 -0
  19. package/dist/core/event-bus.d.ts.map +1 -0
  20. package/dist/core/event-bus.js +35 -0
  21. package/dist/core/event-bus.js.map +1 -0
  22. package/dist/core/event-log-integrity.d.ts +30 -0
  23. package/dist/core/event-log-integrity.d.ts.map +1 -0
  24. package/dist/core/event-log-integrity.js +90 -0
  25. package/dist/core/event-log-integrity.js.map +1 -0
  26. package/dist/core/event-log.d.ts +19 -0
  27. package/dist/core/event-log.d.ts.map +1 -0
  28. package/dist/core/event-log.js +29 -0
  29. package/dist/core/event-log.js.map +1 -0
  30. package/dist/index.d.ts +16 -0
  31. package/dist/index.d.ts.map +1 -0
  32. package/dist/index.js +17 -0
  33. package/dist/index.js.map +1 -0
  34. package/dist/policy/policy-engine.d.ts +20 -0
  35. package/dist/policy/policy-engine.d.ts.map +1 -0
  36. package/dist/policy/policy-engine.js +65 -0
  37. package/dist/policy/policy-engine.js.map +1 -0
  38. package/dist/redaction/hash.d.ts +3 -0
  39. package/dist/redaction/hash.d.ts.map +1 -0
  40. package/dist/redaction/hash.js +11 -0
  41. package/dist/redaction/hash.js.map +1 -0
  42. package/dist/redaction/pii-detector.d.ts +16 -0
  43. package/dist/redaction/pii-detector.d.ts.map +1 -0
  44. package/dist/redaction/pii-detector.js +70 -0
  45. package/dist/redaction/pii-detector.js.map +1 -0
  46. package/dist/redaction/redactor.d.ts +12 -0
  47. package/dist/redaction/redactor.d.ts.map +1 -0
  48. package/dist/redaction/redactor.js +26 -0
  49. package/dist/redaction/redactor.js.map +1 -0
  50. package/dist/redaction/strategies/hash-strategy.d.ts +3 -0
  51. package/dist/redaction/strategies/hash-strategy.d.ts.map +1 -0
  52. package/dist/redaction/strategies/hash-strategy.js +8 -0
  53. package/dist/redaction/strategies/hash-strategy.js.map +1 -0
  54. package/dist/redaction/strategies/mask-strategy.d.ts +3 -0
  55. package/dist/redaction/strategies/mask-strategy.d.ts.map +1 -0
  56. package/dist/redaction/strategies/mask-strategy.js +11 -0
  57. package/dist/redaction/strategies/mask-strategy.js.map +1 -0
  58. package/dist/redaction/strategies/omit-strategy.d.ts +3 -0
  59. package/dist/redaction/strategies/omit-strategy.d.ts.map +1 -0
  60. package/dist/redaction/strategies/omit-strategy.js +7 -0
  61. package/dist/redaction/strategies/omit-strategy.js.map +1 -0
  62. package/dist/redaction/strategies/types.d.ts +5 -0
  63. package/dist/redaction/strategies/types.d.ts.map +1 -0
  64. package/dist/redaction/strategies/types.js +2 -0
  65. package/dist/redaction/strategies/types.js.map +1 -0
  66. package/package.json +35 -0
@@ -0,0 +1,90 @@
1
+ const GENESIS_HASH = '0000000000000000';
2
+ /** Simple hash function for log chain integrity (non-cryptographic) */
3
+ function computeHash(data) {
4
+ let hash = 0x811c9dc5; // FNV offset basis
5
+ for (let i = 0; i < data.length; i++) {
6
+ hash ^= data.charCodeAt(i);
7
+ hash = (hash * 0x01000193) | 0; // FNV prime
8
+ }
9
+ return (hash >>> 0).toString(16).padStart(8, '0');
10
+ }
11
+ function hashEntry(entry) {
12
+ const data = JSON.stringify({
13
+ sequence: entry.sequence,
14
+ previousHash: entry.previousHash,
15
+ timestamp: entry.timestamp,
16
+ sessionId: entry.sessionId,
17
+ documentId: entry.documentId,
18
+ eventType: entry.eventType,
19
+ componentId: entry.componentId,
20
+ payload: entry.payload,
21
+ redacted: entry.redacted,
22
+ });
23
+ return computeHash(data);
24
+ }
25
+ export class ChainedEventLog {
26
+ entries = [];
27
+ sessionId;
28
+ documentId;
29
+ constructor(sessionId, documentId) {
30
+ this.sessionId = sessionId;
31
+ this.documentId = documentId;
32
+ }
33
+ append(entry) {
34
+ const sequence = this.entries.length;
35
+ const previousHash = sequence === 0 ? GENESIS_HASH : this.entries[sequence - 1].hash;
36
+ const chained = {
37
+ timestamp: new Date().toISOString(),
38
+ sessionId: this.sessionId,
39
+ documentId: this.documentId,
40
+ eventType: entry.eventType,
41
+ componentId: entry.componentId,
42
+ payload: entry.payload,
43
+ redacted: entry.redacted ?? false,
44
+ actor: entry.actor,
45
+ sequence,
46
+ previousHash,
47
+ hash: '', // computed below
48
+ };
49
+ chained.hash = hashEntry(chained);
50
+ this.entries.push(chained);
51
+ return chained;
52
+ }
53
+ verifyIntegrity() {
54
+ for (let i = 0; i < this.entries.length; i++) {
55
+ const entry = this.entries[i];
56
+ // Verify chain link
57
+ const expectedPrev = i === 0 ? GENESIS_HASH : this.entries[i - 1].hash;
58
+ if (entry.previousHash !== expectedPrev) {
59
+ return {
60
+ valid: false,
61
+ brokenAt: i,
62
+ reason: `Chain broken at entry ${i}: expected previousHash "${expectedPrev}", got "${entry.previousHash}"`,
63
+ };
64
+ }
65
+ // Verify hash
66
+ const expectedHash = hashEntry(entry);
67
+ if (entry.hash !== expectedHash) {
68
+ return {
69
+ valid: false,
70
+ brokenAt: i,
71
+ reason: `Hash mismatch at entry ${i}: expected "${expectedHash}", got "${entry.hash}"`,
72
+ };
73
+ }
74
+ }
75
+ return { valid: true };
76
+ }
77
+ toJSON() {
78
+ return [...this.entries];
79
+ }
80
+ toJSONL() {
81
+ return this.entries.map((e) => JSON.stringify(e)).join('\n');
82
+ }
83
+ forComponent(componentId) {
84
+ return this.entries.filter((e) => e.componentId === componentId);
85
+ }
86
+ get size() {
87
+ return this.entries.length;
88
+ }
89
+ }
90
+ //# sourceMappingURL=event-log-integrity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-log-integrity.js","sourceRoot":"","sources":["../../src/core/event-log-integrity.ts"],"names":[],"mappings":"AAQA,MAAM,YAAY,GAAG,kBAAkB,CAAC;AAExC,uEAAuE;AACvE,SAAS,WAAW,CAAC,IAAY;IAC/B,IAAI,IAAI,GAAG,UAAU,CAAC,CAAC,mBAAmB;IAC1C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,IAAI,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAC3B,IAAI,GAAG,CAAC,IAAI,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,YAAY;IAC9C,CAAC;IACD,OAAO,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;AACpD,CAAC;AAED,SAAS,SAAS,CAAC,KAA2B;IAC5C,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC;QAC1B,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,OAAO,EAAE,KAAK,CAAC,OAAO;Q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AAK,WAAW,CAAC,CAAC;IACnE,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;IAC7B,CAAC;CACF"}
@@ -0,0 +1,19 @@
1
+ import type { EventLogEntry, EventType, EventActor } from '@mobile-reality/mdma-spec';
2
+ export interface EventLogOptions {
3
+ sessionId: string;
4
+ documentId: string;
5
+ }
6
+ export interface AppendOnlyEventLog {
7
+ append(entry: {
8
+ eventType: EventType;
9
+ componentId: string;
10
+ payload: Record<string, unknown>;
11
+ redacted?: boolean;
12
+ actor?: EventActor;
13
+ }): EventLogEntry;
14
+ entries(): ReadonlyArray<Readonly<EventLogEntry>>;
15
+ forComponent(componentId: string): EventLogEntry[];
16
+ size(): number;
17
+ }
18
+ export declare function createEventLog(options: EventLogOptions): AppendOnlyEventLog;
19
+ //# sourceMappingURL=event-log.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-log.d.ts","sourceRoot":"","sources":["../../src/core/event-log.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAEtF,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,CAAC,KAAK,EAAE;QACZ,SAAS,EAAE,SAAS,CAAC;QACrB,WAAW,EAAE,MAAM,CAAC;QACpB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACjC,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB,KAAK,CAAC,EAAE,UAAU,CAAC;KACpB,GAAG,aAAa,CAAC;IAClB,OAAO,IAAI,aAAa,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC;IAClD,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,aAAa,EAAE,CAAC;IACnD,IAAI,IAAI,MAAM,CAAC;CAChB;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,eAAe,GAAG,kBAAkB,CA+B3E"}
@@ -0,0 +1,29 @@
1
+ export function createEventLog(options) {
2
+ const log = [];
3
+ return {
4
+ append(entry) {
5
+ const full = {
6
+ timestamp: new Date().toISOString(),
7
+ sessionId: options.sessionId,
8
+ documentId: options.documentId,
9
+ eventType: entry.eventType,
10
+ componentId: entry.componentId,
11
+ payload: entry.payload,
12
+ redacted: entry.redacted ?? false,
13
+ actor: entry.actor,
14
+ };
15
+ log.push(full);
16
+ return full;
17
+ },
18
+ entries() {
19
+ return log;
20
+ },
21
+ forComponent(componentId) {
22
+ return log.filter((e) => e.componentId === componentId);
23
+ },
24
+ size() {
25
+ return log.length;
26
+ },
27
+ };
28
+ }
29
+ //# sourceMappingURL=event-log.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-log.js","sourceRoot":"","sources":["../../src/core/event-log.ts"],"names":[],"mappings":"AAoBA,MAAM,UAAU,cAAc,CAAC,OAAwB;IACrD,MAAM,GAAG,GAAoB,EAAE,CAAC;IAEhC,OAAO;QACL,MAAM,CAAC,KAAK;YACV,MAAM,IAAI,GAAkB;gBAC1B,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;gBACnC,SAAS,EAAE,OAAO,CAAC,SAAS;gBAC5B,UAAU,EAAE,OAAO,CAAC,UAAU;gBAC9B,SAAS,EAAE,KAAK,CAAC,SAAS;gBAC1B,WAAW,EAAE,KAAK,CAAC,WAAW;gBAC9B,OAAO,EAAE,KAAK,CAAC,OAAO;gBACtB,QAAQ,EAAE,KAAK,CAAC,QAAQ,IAAI,KAAK;gBACjC,KAAK,EAAE,KAAK,CAAC,KAAK;aACnB,CAAC;YACF,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACf,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO;YACL,OAAO,GAAG,CAAC;QACb,CAAC;QAED,YAAY,CAAC,WAAW;YACtB,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,KAAK,WAAW,CAAC,CAAC;QAC1D,CAAC;QAED,IAAI;YACF,OAAO,GAAG,CAAC,MAAM,CAAC;QACpB,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,16 @@
1
+ export { createDocumentStore, type DocumentStore, type DocumentState, type DocumentStoreOptions, } from './core/document-store.js';
2
+ export { createEventBus, type TypedEventBus, type EventHandler } from './core/event-bus.js';
3
+ export { createEventLog, type AppendOnlyEventLog, type EventLogOptions } from './core/event-log.js';
4
+ export { resolveBindingPath, resolveValue, parseBindingExpression, } from './core/binding-resolver.js';
5
+ export { redactPayload, type RedactionContext } from './redaction/redactor.js';
6
+ export { hashValue } from './redaction/hash.js';
7
+ export { PolicyEngine, PolicyViolationError, createDefaultPolicy, type PolicyEvaluationResult, } from './policy/policy-engine.js';
8
+ export { AttachableRegistry, type AttachableHandler, type AttachableContext, type ComponentState, } from './attachable/registry.js';
9
+ export { ChainedEventLog, type ChainedEventLogEntry, type IntegrityVerificationResult, } from './core/event-log-integrity.js';
10
+ export { type RedactionStrategy } from './redaction/strategies/types.js';
11
+ export { hashStrategy } from './redaction/strategies/hash-strategy.js';
12
+ export { maskStrategy } from './redaction/strategies/mask-strategy.js';
13
+ export { omitStrategy } from './redaction/strategies/omit-strategy.js';
14
+ export { detectPii, auditSensitiveFields, type PiiDetectionResult, type PiiType, } from './redaction/pii-detector.js';
15
+ export { generateComplianceReport, type ComplianceReport, type ComplianceCheck, } from './compliance/compliance-reporter.js';
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,oBAAoB,GAC1B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,cAAc,EAAE,KAAK,aAAa,EAAE,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC5F,OAAO,EAAE,cAAc,EAAE,KAAK,kBAAkB,EAAE,KAAK,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACpG,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,sBAAsB,GACvB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,KAAK,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC/E,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EACL,YAAY,EACZ,oBAAoB,EACpB,mBAAmB,EACnB,KAAK,sBAAsB,GAC5B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,kBAAkB,EAClB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,cAAc,GACpB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EACL,eAAe,EACf,KAAK,oBAAoB,EACzB,KAAK,2BAA2B,GACjC,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAC;AACvE,OAAO,EACL,SAAS,EACT,oBAAoB,EACpB,KAAK,kBAAkB,EACvB,KAAK,OAAO,GACb,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,wBAAwB,EACxB,KAAK,gBAAgB,EACrB,KAAK,eAAe,GACrB,MAAM,qCAAqC,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,17 @@
1
+ export { createDocumentStore, } from './core/document-store.js';
2
+ export { createEventBus } from './core/event-bus.js';
3
+ export { createEventLog } from './core/event-log.js';
4
+ export { resolveBindingPath, resolveValue, parseBindingExpression, } from './core/binding-resolver.js';
5
+ export { redactPayload } from './redaction/redactor.js';
6
+ export { hashValue } from './redaction/hash.js';
7
+ export { PolicyEngine, PolicyViolationError, createDefaultPolicy, } from './policy/policy-engine.js';
8
+ export { AttachableRegistry, } from './attachable/registry.js';
9
+ // Enterprise features
10
+ export { ChainedEventLog, } from './core/event-log-integrity.js';
11
+ export {} from './redaction/strategies/types.js';
12
+ export { hashStrategy } from './redaction/strategies/hash-strategy.js';
13
+ export { maskStrategy } from './redaction/strategies/mask-strategy.js';
14
+ export { omitStrategy } from './redaction/strategies/omit-strategy.js';
15
+ export { detectPii, auditSensitiveFields, } from './redaction/pii-detector.js';
16
+ export { generateComplianceReport, } from './compliance/compliance-reporter.js';
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,GAIpB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,cAAc,EAAyC,MAAM,qBAAqB,CAAC;AAC5F,OAAO,EAAE,cAAc,EAAiD,MAAM,qBAAqB,CAAC;AACpG,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,sBAAsB,GACvB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,aAAa,EAAyB,MAAM,yBAAyB,CAAC;AAC/E,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EACL,YAAY,EACZ,oBAAoB,EACpB,mBAAmB,GAEpB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,kBAAkB,GAInB,MAAM,0BAA0B,CAAC;AAElC,sBAAsB;AACtB,OAAO,EACL,eAAe,GAGhB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAA0B,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAC;AACvE,OAAO,EACL,SAAS,EACT,oBAAoB,GAGrB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,wBAAwB,GAGzB,MAAM,qCAAqC,CAAC"}
@@ -0,0 +1,20 @@
1
+ import type { Policy, PolicyRule } from '@mobile-reality/mdma-spec';
2
+ export interface PolicyEvaluationResult {
3
+ allowed: boolean;
4
+ rule?: PolicyRule;
5
+ reason?: string;
6
+ }
7
+ export declare class PolicyViolationError extends Error {
8
+ readonly rule?: PolicyRule;
9
+ constructor(message: string, rule?: PolicyRule);
10
+ }
11
+ export declare class PolicyEngine {
12
+ private readonly policy;
13
+ private readonly environment;
14
+ constructor(policy: Policy, environment: string);
15
+ evaluate(action: string): PolicyEvaluationResult;
16
+ enforce(action: string): void;
17
+ get currentEnvironment(): string;
18
+ }
19
+ export declare function createDefaultPolicy(): Policy;
20
+ //# sourceMappingURL=policy-engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policy-engine.d.ts","sourceRoot":"","sources":["../../src/policy/policy-engine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAEpE,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,QAAQ,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC;gBAEf,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,UAAU;CAK/C;AAED,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;gBAEzB,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM;IAK/C,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,sBAAsB;IAyBhD,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAU7B,IAAI,kBAAkB,IAAI,MAAM,CAE/B;CACF;AAED,wBAAgB,mBAAmB,IAAI,MAAM,CAmB5C"}
@@ -0,0 +1,65 @@
1
+ export class PolicyViolationError extends Error {
2
+ rule;
3
+ constructor(message, rule) {
4
+ super(message);
5
+ this.name = 'PolicyViolationError';
6
+ this.rule = rule;
7
+ }
8
+ }
9
+ export class PolicyEngine {
10
+ policy;
11
+ environment;
12
+ constructor(policy, environment) {
13
+ this.policy = policy;
14
+ this.environment = environment;
15
+ }
16
+ evaluate(action) {
17
+ // Find matching rules for this action and environment
18
+ const matchingRules = this.policy.rules.filter((rule) => rule.action === action &&
19
+ rule.environments.includes(this.environment));
20
+ // If we have explicit rules, use the first matching one
21
+ if (matchingRules.length > 0) {
22
+ const rule = matchingRules[0];
23
+ return {
24
+ allowed: rule.effect === 'allow',
25
+ rule,
26
+ reason: rule.reason,
27
+ };
28
+ }
29
+ // Fall back to default effect
30
+ return {
31
+ allowed: this.policy.defaultEffect === 'allow',
32
+ reason: `Default policy: ${this.policy.defaultEffect}`,
33
+ };
34
+ }
35
+ enforce(action) {
36
+ const result = this.evaluate(action);
37
+ if (!result.allowed) {
38
+ throw new PolicyViolationError(result.reason ?? `Action "${action}" denied by policy`, result.rule);
39
+ }
40
+ }
41
+ get currentEnvironment() {
42
+ return this.environment;
43
+ }
44
+ }
45
+ export function createDefaultPolicy() {
46
+ return {
47
+ version: 1,
48
+ rules: [
49
+ {
50
+ action: 'send_email',
51
+ environments: ['preview', 'test'],
52
+ effect: 'deny',
53
+ reason: 'Email sending is blocked in non-production environments',
54
+ },
55
+ {
56
+ action: 'webhook_call',
57
+ environments: ['preview'],
58
+ effect: 'deny',
59
+ reason: 'External webhook calls are blocked in preview',
60
+ },
61
+ ],
62
+ defaultEffect: 'allow',
63
+ };
64
+ }
65
+ //# sourceMappingURL=policy-engine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,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACrC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACpB,MAAM,IAAI,oBAAoB,CAC5B,MAAM,CAAC,MAAM,IAAI,WAAW,MAAM,oBAAoB,EACtD,MAAM,CAAC,IAAI,CACZ,CAAC;QACJ,CAAC;IACH,CAAC;IAED,IAAI,kBAAkB;QACpB,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;CACF;AAED,MAAM,UAAU,mBAAmB;IACjC,OAAO;QACL,OAAO,EAAE,CAAC;QACV,KAAK,EAAE;YACL;gBACE,MAAM,EAAE,YAAY;gBACpB,YAAY,EAAE,CAAC,SAAS,EAAE,MAAM,CAAC;gBACjC,MAAM,EAAE,MAAM;gBACd,MAAM,EAAE,yDAAyD;aAClE;YACD;gBACE,MAAM,EAAE,cAAc;gBACtB,YAAY,EAAE,CAAC,SAAS,CAAC;gBACzB,MAAM,EAAE,MAAM;gBACd,MAAM,EAAE,+CAA+C;aACxD;SACF;QACD,aAAa,EAAE,OAAO;KACvB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,3 @@
1
+ /** Simple hash for redacting sensitive values (non-cryptographic, for logging only) */
2
+ export declare function hashValue(value: unknown): string;
3
+ //# sourceMappingURL=hash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/redaction/hash.ts"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAQhD"}
@@ -0,0 +1,11 @@
1
+ /** Simple hash for redacting sensitive values (non-cryptographic, for logging only) */
2
+ export function hashValue(value) {
3
+ const str = typeof value === 'string' ? value : JSON.stringify(value);
4
+ let hash = 0;
5
+ for (let i = 0; i < str.length; i++) {
6
+ const char = str.charCodeAt(i);
7
+ hash = ((hash << 5) - hash + char) | 0;
8
+ }
9
+ return `redacted:${(hash >>> 0).toString(16).padStart(8, '0')}`;
10
+ }
11
+ //# sourceMappingURL=hash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.js","sourceRoot":"","sources":["../../src/redaction/hash.ts"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,MAAM,UAAU,SAAS,CAAC,KAAc;IACtC,MAAM,GAAG,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACtE,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACpC,MAAM,IAAI,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAC/B,IAAI,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;IACzC,CAAC;IACD,OAAO,YAAY,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;AAClE,CAAC"}
@@ -0,0 +1,16 @@
1
+ export type PiiType = 'email' | 'phone' | 'ssn' | 'credit_card' | 'name_like';
2
+ export interface PiiDetectionResult {
3
+ field: string;
4
+ detectedTypes: PiiType[];
5
+ confidence: number;
6
+ suggestion: string;
7
+ }
8
+ /** Detect potential PII in a field based on field name and/or value */
9
+ export declare function detectPii(fieldName: string, value: unknown): PiiDetectionResult | null;
10
+ /** Scan all fields in a component's form fields for potential PII not marked sensitive */
11
+ export declare function auditSensitiveFields(fields: Array<{
12
+ name: string;
13
+ sensitive?: boolean;
14
+ defaultValue?: unknown;
15
+ }>): PiiDetectionResult[];
16
+ //# sourceMappingURL=pii-detector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pii-detector.d.ts","sourceRoot":"","sources":["../../src/redaction/pii-detector.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,KAAK,GAAG,aAAa,GAAG,WAAW,CAAC;AAE9E,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,OAAO,EAAE,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB;AA8BD,uEAAuE;AACvE,wBAAgB,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,kBAAkB,GAAG,IAAI,CAgCtF;AAED,0FAA0F;AAC1F,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,OAAO,CAAC;IAAC,YAAY,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC,GAC3E,kBAAkB,EAAE,CAUtB"}
@@ -0,0 +1,70 @@
1
+ const PATTERNS = [
2
+ {
3
+ type: 'email',
4
+ regex: /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
5
+ fieldHints: /email|e.?mail/i,
6
+ },
7
+ {
8
+ type: 'phone',
9
+ regex: /^[\d\s\-+()]{7,15}$/,
10
+ fieldHints: /phone|tel|mobile|cell|fax/i,
11
+ },
12
+ {
13
+ type: 'ssn',
14
+ regex: /^\d{3}-?\d{2}-?\d{4}$/,
15
+ fieldHints: /ssn|social.?security|national.?id|pesel/i,
16
+ },
17
+ {
18
+ type: 'credit_card',
19
+ regex: /^\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}$/,
20
+ fieldHints: /card|credit|cc.?num/i,
21
+ },
22
+ {
23
+ type: 'name_like',
24
+ regex: /^[A-Z][a-z]+ [A-Z][a-z]+$/,
25
+ fieldHints: /name|first.?name|last.?name|full.?name|patient|customer/i,
26
+ },
27
+ ];
28
+ /** Detect potential PII in a field based on field name and/or value */
29
+ export function detectPii(fieldName, value) {
30
+ const detectedTypes = [];
31
+ let confidence = 0;
32
+ const str = typeof value === 'string' ? value : '';
33
+ for (const pattern of PATTERNS) {
34
+ let score = 0;
35
+ // Check field name
36
+ if (pattern.fieldHints.test(fieldName)) {
37
+ score += 0.6;
38
+ }
39
+ // Check value pattern
40
+ if (str && pattern.regex.test(str)) {
41
+ score += 0.4;
42
+ }
43
+ if (score > 0.3) {
44
+ detectedTypes.push(pattern.type);
45
+ confidence = Math.max(confidence, score);
46
+ }
47
+ }
48
+ if (detectedTypes.length === 0)
49
+ return null;
50
+ return {
51
+ field: fieldName,
52
+ detectedTypes,
53
+ confidence: Math.min(confidence, 1),
54
+ suggestion: `Field "${fieldName}" may contain PII (${detectedTypes.join(', ')}). Consider adding sensitive: true.`,
55
+ };
56
+ }
57
+ /** Scan all fields in a component's form fields for potential PII not marked sensitive */
58
+ export function auditSensitiveFields(fields) {
59
+ const results = [];
60
+ for (const field of fields) {
61
+ if (field.sensitive)
62
+ continue; // Already marked
63
+ const detection = detectPii(field.name, field.defaultValue);
64
+ if (detection) {
65
+ results.push(detection);
66
+ }
67
+ }
68
+ return results;
69
+ }
70
+ //# sourceMappingURL=pii-detector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pii-detector.js","sourceRoot":"","sources":["../../src/redaction/pii-detector.ts"],"names":[],"mappings":"AASA,MAAM,QAAQ,GAAgE;IAC5E;QACE,IAAI,EAAE,OAAO;QACb,KAAK,EAAE,4BAA4B;QACnC,UAAU,EAAE,gBAAgB;KAC7B;IACD;QACE,IAAI,EAAE,OAAO;QACb,KAAK,EAAE,qBAAqB;QAC5B,UAAU,EAAE,4BAA4B;KACzC;IACD;QACE,IAAI,EAAE,KAAK;QACX,KAAK,EAAE,uBAAuB;QAC9B,UAAU,EAAE,0CAA0C;KACvD;IACD;QACE,IAAI,EAAE,aAAa;QACnB,KAAK,EAA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C1F,MAAM,UAAU,oBAAoB,CAClC,MAA4E;IAE5E,MAAM,OAAO,GAAyB,EAAE,CAAC;IACzC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,IAAI,KAAK,CAAC,SAAS;YAAE,SAAS,CAAC,iBAAiB;QAChD,MAAM,SAAS,GAAG,SAAS,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;QAC5D,IAAI,SAAS,EAAE,CAAC;YACd,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,12 @@
1
+ export interface RedactionContext {
2
+ /** Set of component IDs that have sensitive:true */
3
+ sensitiveComponents: Set<string>;
4
+ /** Set of specific field names that are sensitive */
5
+ sensitiveFields: Set<string>;
6
+ }
7
+ /** Redact sensitive values in a payload before logging */
8
+ export declare function redactPayload(payload: Record<string, unknown>, componentId: string, ctx: RedactionContext): {
9
+ payload: Record<string, unknown>;
10
+ redacted: boolean;
11
+ };
12
+ //# sourceMappingURL=redactor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redactor.d.ts","sourceRoot":"","sources":["../../src/redaction/redactor.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,gBAAgB;IAC/B,oDAAoD;IACpD,mBAAmB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACjC,qDAAqD;IACrD,eAAe,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CAC9B;AAED,0DAA0D;AAC1D,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,WAAW,EAAE,MAAM,EACnB,GAAG,EAAE,gBAAgB,GACpB;IAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,CAiBzD"}
@@ -0,0 +1,26 @@
1
+ import { hashValue } from './hash.js';
2
+ /** Redact sensitive values in a payload before logging */
3
+ export function redactPayload(payload, componentId, ctx) {
4
+ const isSensitiveComponent = ctx.sensitiveComponents.has(componentId);
5
+ if (!isSensitiveComponent && !hasSensitiveFields(payload, ctx.sensitiveFields)) {
6
+ return { payload, redacted: false };
7
+ }
8
+ const redacted = {};
9
+ for (const [key, value] of Object.entries(payload)) {
10
+ if (isSensitiveComponent || ctx.sensitiveFields.has(key)) {
11
+ redacted[key] = hashValue(value);
12
+ }
13
+ else {
14
+ redacted[key] = value;
15
+ }
16
+ }
17
+ return { payload: redacted, redacted: true };
18
+ }
19
+ function hasSensitiveFields(payload, sensitiveFields) {
20
+ for (const key of Object.keys(payload)) {
21
+ if (sensitiveFields.has(key))
22
+ return true;
23
+ }
24
+ return false;
25
+ }
26
+ //# sourceMappingURL=redactor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redactor.js","sourceRoot":"","sources":["../../src/redaction/redactor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAStC,0DAA0D;AAC1D,MAAM,UAAU,aAAa,CAC3B,OAAgC,EAChC,WAAmB,EACnB,GAAqB;IAErB,MAAM,oBAAoB,GAAG,GAAG,CAAC,mBAAmB,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAEtE,IAAI,CAAC,oBAAoB,IAAI,CAAC,kBAAkB,CAAC,OAAO,EAAE,GAAG,CAAC,eAAe,CAAC,EAAE,CAAC;QAC/E,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;IACtC,CAAC;IAED,MAAM,QAAQ,GAA4B,EAAE,CAAC;IAC7C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACnD,IAAI,oBAAoB,IAAI,GAAG,CAAC,eAAe,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACzD,QAAQ,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;QACnC,CAAC;aAAM,CAAC;YACN,QAAQ,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACxB,CAAC;IACH,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;AAC/C,CAAC;AAED,SAAS,kBAAkB,CACzB,OAAgC,EAChC,eAA4B;IAE5B,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QACvC,IAAI,eAAe,CAAC,GAAG,CAAC,GAAG,CAAC;YAAE,OAAO,IAAI,CAAC;IAC5C,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { RedactionStrategy } from './types.js';
2
+ export declare const hashStrategy: RedactionStrategy;
3
+ //# sourceMappingURL=hash-strategy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash-strategy.d.ts","sourceRoot":"","sources":["../../../src/redaction/strategies/hash-strategy.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD,eAAO,MAAM,YAAY,EAAE,iBAK1B,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { hashValue } from '../hash.js';
2
+ export const hashStrategy = {
3
+ name: 'hash',
4
+ redact(value) {
5
+ return hashValue(value);
6
+ },
7
+ };
8
+ //# sourceMappingURL=hash-strategy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash-strategy.js","sourceRoot":"","sources":["../../../src/redaction/strategies/hash-strategy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAGvC,MAAM,CAAC,MAAM,YAAY,GAAsB;IAC7C,IAAI,EAAE,MAAM;IACZ,MAAM,CAAC,KAAc;QACnB,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC;CACF,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { RedactionStrategy } from './types.js';
2
+ export declare const maskStrategy: RedactionStrategy;
3
+ //# sourceMappingURL=mask-strategy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mask-strategy.d.ts","sourceRoot":"","sources":["../../../src/redaction/strategies/mask-strategy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD,eAAO,MAAM,YAAY,EAAE,iBAQ1B,CAAC"}
@@ -0,0 +1,11 @@
1
+ export const maskStrategy = {
2
+ name: 'mask',
3
+ redact(value) {
4
+ const str = String(value);
5
+ if (str.length <= 3)
6
+ return '***';
7
+ const visible = Math.min(3, Math.floor(str.length / 3));
8
+ return str.slice(0, visible) + '***';
9
+ },
10
+ };
11
+ //# sourceMappingURL=mask-strategy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mask-strategy.js","sourceRoot":"","sources":["../../../src/redaction/strategies/mask-strategy.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,YAAY,GAAsB;IAC7C,IAAI,EAAE,MAAM;IACZ,MAAM,CAAC,KAAc;QACnB,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QAC1B,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC;YAAE,OAAO,KAAK,CAAC;QAClC,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;QACxD,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,GAAG,KAAK,CAAC;IACvC,CAAC;CACF,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { RedactionStrategy } from './types.js';
2
+ export declare const omitStrategy: RedactionStrategy;
3
+ //# sourceMappingURL=omit-strategy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"omit-strategy.d.ts","sourceRoot":"","sources":["../../../src/redaction/strategies/omit-strategy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD,eAAO,MAAM,YAAY,EAAE,iBAK1B,CAAC"}
@@ -0,0 +1,7 @@
1
+ export const omitStrategy = {
2
+ name: 'omit',
3
+ redact(_value) {
4
+ return '[REDACTED]';
5
+ },
6
+ };
7
+ //# sourceMappingURL=omit-strategy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"omit-strategy.js","sourceRoot":"","sources":["../../../src/redaction/strategies/omit-strategy.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,YAAY,GAAsB;IAC7C,IAAI,EAAE,MAAM;IACZ,MAAM,CAAC,MAAe;QACpB,OAAO,YAAY,CAAC;IACtB,CAAC;CACF,CAAC"}
@@ -0,0 +1,5 @@
1
+ export interface RedactionStrategy {
2
+ name: string;
3
+ redact(value: unknown): unknown;
4
+ }
5
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/redaction/strategies/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;CACjC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/redaction/strategies/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@mobile-reality/mdma-runtime",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": {
7
+ "import": "./dist/index.js",
8
+ "types": "./dist/index.d.ts"
9
+ }
10
+ },
11
+ "dependencies": {
12
+ "@mobile-reality/mdma-spec": "0.1.0"
13
+ },
14
+ "devDependencies": {
15
+ "typescript": "^5.7.0",
16
+ "vitest": "^3.2.0"
17
+ },
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://github.com/MobileReality/mdma.git",
27
+ "directory": "packages/runtime"
28
+ },
29
+ "scripts": {
30
+ "build": "tsc -p tsconfig.json",
31
+ "test": "vitest run",
32
+ "lint": "eslint src/",
33
+ "typecheck": "tsc --noEmit"
34
+ }
35
+ }