@semiont/core 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 (95) hide show
  1. package/README.md +265 -0
  2. package/dist/annotation-history-utils.d.ts +42 -0
  3. package/dist/annotation-history-utils.d.ts.map +1 -0
  4. package/dist/annotation-history-utils.js +258 -0
  5. package/dist/annotation-history-utils.js.map +1 -0
  6. package/dist/annotation-types.d.ts +15 -0
  7. package/dist/annotation-types.d.ts.map +1 -0
  8. package/dist/annotation-types.js +6 -0
  9. package/dist/annotation-types.js.map +1 -0
  10. package/dist/annotation-utils.d.ts +18 -0
  11. package/dist/annotation-utils.d.ts.map +1 -0
  12. package/dist/annotation-utils.js +70 -0
  13. package/dist/annotation-utils.js.map +1 -0
  14. package/dist/auth-types.d.ts +8 -0
  15. package/dist/auth-types.d.ts.map +1 -0
  16. package/dist/auth-types.js +6 -0
  17. package/dist/auth-types.js.map +1 -0
  18. package/dist/config/config-validator.d.ts +25 -0
  19. package/dist/config/config-validator.d.ts.map +1 -0
  20. package/dist/config/config-validator.js +112 -0
  21. package/dist/config/config-validator.js.map +1 -0
  22. package/dist/config/config.schema.json +678 -0
  23. package/dist/config/config.types.d.ts +574 -0
  24. package/dist/config/config.types.d.ts.map +1 -0
  25. package/dist/config/config.types.js +4 -0
  26. package/dist/config/config.types.js.map +1 -0
  27. package/dist/config/configuration-error.d.ts +17 -0
  28. package/dist/config/configuration-error.d.ts.map +1 -0
  29. package/dist/config/configuration-error.js +36 -0
  30. package/dist/config/configuration-error.js.map +1 -0
  31. package/dist/config/environment-loader.d.ts +98 -0
  32. package/dist/config/environment-loader.d.ts.map +1 -0
  33. package/dist/config/environment-loader.js +229 -0
  34. package/dist/config/environment-loader.js.map +1 -0
  35. package/dist/config/environment-validator.d.ts +22 -0
  36. package/dist/config/environment-validator.d.ts.map +1 -0
  37. package/dist/config/environment-validator.js +50 -0
  38. package/dist/config/environment-validator.js.map +1 -0
  39. package/dist/config/platform-types.d.ts +26 -0
  40. package/dist/config/platform-types.d.ts.map +1 -0
  41. package/dist/config/platform-types.js +28 -0
  42. package/dist/config/platform-types.js.map +1 -0
  43. package/dist/config/project-discovery.d.ts +35 -0
  44. package/dist/config/project-discovery.d.ts.map +1 -0
  45. package/dist/config/project-discovery.js +99 -0
  46. package/dist/config/project-discovery.js.map +1 -0
  47. package/dist/config/validate-config.d.ts +56 -0
  48. package/dist/config/validate-config.d.ts.map +1 -0
  49. package/dist/config/validate-config.js +114 -0
  50. package/dist/config/validate-config.js.map +1 -0
  51. package/dist/creation-methods.d.ts +19 -0
  52. package/dist/creation-methods.d.ts.map +1 -0
  53. package/dist/creation-methods.js +18 -0
  54. package/dist/creation-methods.js.map +1 -0
  55. package/dist/crypto.d.ts +32 -0
  56. package/dist/crypto.d.ts.map +1 -0
  57. package/dist/crypto.js +52 -0
  58. package/dist/crypto.js.map +1 -0
  59. package/dist/did-utils.d.ts +51 -0
  60. package/dist/did-utils.d.ts.map +1 -0
  61. package/dist/did-utils.js +62 -0
  62. package/dist/did-utils.js.map +1 -0
  63. package/dist/errors.d.ts +51 -0
  64. package/dist/errors.d.ts.map +1 -0
  65. package/dist/errors.js +89 -0
  66. package/dist/errors.js.map +1 -0
  67. package/dist/events.d.ts +223 -0
  68. package/dist/events.d.ts.map +1 -0
  69. package/dist/events.js +45 -0
  70. package/dist/events.js.map +1 -0
  71. package/dist/graph.d.ts +31 -0
  72. package/dist/graph.d.ts.map +1 -0
  73. package/dist/graph.js +6 -0
  74. package/dist/graph.js.map +1 -0
  75. package/dist/http-client.d.ts +32 -0
  76. package/dist/http-client.d.ts.map +1 -0
  77. package/dist/http-client.js +56 -0
  78. package/dist/http-client.js.map +1 -0
  79. package/dist/identifiers.d.ts +24 -0
  80. package/dist/identifiers.d.ts.map +1 -0
  81. package/dist/identifiers.js +40 -0
  82. package/dist/identifiers.js.map +1 -0
  83. package/dist/index.d.ts +33 -0
  84. package/dist/index.d.ts.map +1 -0
  85. package/dist/index.js +80 -0
  86. package/dist/index.js.map +1 -0
  87. package/dist/resource-types.d.ts +15 -0
  88. package/dist/resource-types.d.ts.map +1 -0
  89. package/dist/resource-types.js +6 -0
  90. package/dist/resource-types.js.map +1 -0
  91. package/dist/type-guards.d.ts +44 -0
  92. package/dist/type-guards.d.ts.map +1 -0
  93. package/dist/type-guards.js +76 -0
  94. package/dist/type-guards.js.map +1 -0
  95. package/package.json +49 -0
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Runtime Configuration Validation
3
+ *
4
+ * Uses AJV to validate configuration files against the JSON Schema at runtime.
5
+ * This catches invalid configurations before they cause runtime errors.
6
+ */
7
+ import type { SemiontConfig } from './config.types.js';
8
+ /**
9
+ * Error thrown when configuration validation fails
10
+ */
11
+ export declare class ConfigValidationError extends Error {
12
+ readonly errors: unknown[];
13
+ constructor(message: string, errors: unknown[]);
14
+ /**
15
+ * Get a formatted error message with all validation failures
16
+ */
17
+ getDetailedMessage(): string;
18
+ }
19
+ /**
20
+ * Validates a configuration object against the JSON Schema
21
+ *
22
+ * @param config - The configuration object to validate
23
+ * @returns The validated config, typed as SemiontConfig
24
+ * @throws ConfigValidationError if validation fails
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * import { validateConfig } from '@semiont/core';
29
+ *
30
+ * try {
31
+ * const config = validateConfig(loadedConfig);
32
+ * // config is now typed and validated
33
+ * } catch (error) {
34
+ * if (error instanceof ConfigValidationError) {
35
+ * console.error(error.getDetailedMessage());
36
+ * }
37
+ * }
38
+ * ```
39
+ */
40
+ export declare function validateConfig(config: unknown): SemiontConfig;
41
+ /**
42
+ * Type guard that checks if a configuration is valid
43
+ * Does not throw, returns boolean instead
44
+ *
45
+ * @param config - The configuration to check
46
+ * @returns True if valid, false otherwise
47
+ */
48
+ export declare function isValidConfig(config: unknown): config is SemiontConfig;
49
+ /**
50
+ * Get validation errors for a config without throwing
51
+ *
52
+ * @param config - The configuration to validate
53
+ * @returns Array of validation errors, or null if valid
54
+ */
55
+ export declare function getConfigErrors(config: unknown): unknown[] | null;
56
+ //# sourceMappingURL=validate-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate-config.d.ts","sourceRoot":"","sources":["../../src/config/validate-config.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAkBvD;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,KAAK;aAG5B,MAAM,EAAE,OAAO,EAAE;gBADjC,OAAO,EAAE,MAAM,EACC,MAAM,EAAE,OAAO,EAAE;IAMnC;;OAEG;IACH,kBAAkB,IAAI,MAAM;CAiB7B;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,OAAO,GAAG,aAAa,CAS7D;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,aAAa,CAEtE;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,EAAE,GAAG,IAAI,CAKjE"}
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ /**
3
+ * Runtime Configuration Validation
4
+ *
5
+ * Uses AJV to validate configuration files against the JSON Schema at runtime.
6
+ * This catches invalid configurations before they cause runtime errors.
7
+ */
8
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ConfigValidationError = void 0;
13
+ exports.validateConfig = validateConfig;
14
+ exports.isValidConfig = isValidConfig;
15
+ exports.getConfigErrors = getConfigErrors;
16
+ const ajv_1 = __importDefault(require("ajv"));
17
+ const ajv_formats_1 = __importDefault(require("ajv-formats"));
18
+ const config_schema_json_1 = __importDefault(require("./config.schema.json"));
19
+ // Initialize AJV with strict schema validation
20
+ const ajv = new ajv_1.default({
21
+ strict: true,
22
+ strictSchema: true,
23
+ strictNumbers: true,
24
+ strictTypes: true,
25
+ allErrors: true,
26
+ verbose: true,
27
+ });
28
+ // Add format validators (email, uri, date-time, etc.)
29
+ (0, ajv_formats_1.default)(ajv);
30
+ // Compile the schema once at module load
31
+ const validate = ajv.compile(config_schema_json_1.default);
32
+ /**
33
+ * Error thrown when configuration validation fails
34
+ */
35
+ class ConfigValidationError extends Error {
36
+ errors;
37
+ constructor(message, errors) {
38
+ super(message);
39
+ this.errors = errors;
40
+ this.name = 'ConfigValidationError';
41
+ }
42
+ /**
43
+ * Get a formatted error message with all validation failures
44
+ */
45
+ getDetailedMessage() {
46
+ const lines = [this.message, ''];
47
+ if (Array.isArray(this.errors)) {
48
+ this.errors.forEach((err, idx) => {
49
+ lines.push(`Error ${idx + 1}:`);
50
+ lines.push(` Path: ${err.instancePath || '(root)'}`);
51
+ lines.push(` Message: ${err.message}`);
52
+ if (err.params) {
53
+ lines.push(` Details: ${JSON.stringify(err.params)}`);
54
+ }
55
+ lines.push('');
56
+ });
57
+ }
58
+ return lines.join('\n');
59
+ }
60
+ }
61
+ exports.ConfigValidationError = ConfigValidationError;
62
+ /**
63
+ * Validates a configuration object against the JSON Schema
64
+ *
65
+ * @param config - The configuration object to validate
66
+ * @returns The validated config, typed as SemiontConfig
67
+ * @throws ConfigValidationError if validation fails
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * import { validateConfig } from '@semiont/core';
72
+ *
73
+ * try {
74
+ * const config = validateConfig(loadedConfig);
75
+ * // config is now typed and validated
76
+ * } catch (error) {
77
+ * if (error instanceof ConfigValidationError) {
78
+ * console.error(error.getDetailedMessage());
79
+ * }
80
+ * }
81
+ * ```
82
+ */
83
+ function validateConfig(config) {
84
+ if (!validate(config)) {
85
+ const errors = validate.errors || [];
86
+ const errorCount = errors.length;
87
+ const message = `Configuration validation failed with ${errorCount} error${errorCount === 1 ? '' : 's'}`;
88
+ throw new ConfigValidationError(message, errors);
89
+ }
90
+ return config;
91
+ }
92
+ /**
93
+ * Type guard that checks if a configuration is valid
94
+ * Does not throw, returns boolean instead
95
+ *
96
+ * @param config - The configuration to check
97
+ * @returns True if valid, false otherwise
98
+ */
99
+ function isValidConfig(config) {
100
+ return validate(config) === true;
101
+ }
102
+ /**
103
+ * Get validation errors for a config without throwing
104
+ *
105
+ * @param config - The configuration to validate
106
+ * @returns Array of validation errors, or null if valid
107
+ */
108
+ function getConfigErrors(config) {
109
+ if (validate(config)) {
110
+ return null;
111
+ }
112
+ return validate.errors || [];
113
+ }
114
+ //# sourceMappingURL=validate-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate-config.js","sourceRoot":"","sources":["../../src/config/validate-config.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;AA8EH,wCASC;AASD,sCAEC;AAQD,0CAKC;AA7GD,8CAAsB;AACtB,8DAAqC;AACrC,8EAA0C;AAG1C,+CAA+C;AAC/C,MAAM,GAAG,GAAG,IAAI,aAAG,CAAC;IAClB,MAAM,EAAE,IAAI;IACZ,YAAY,EAAE,IAAI;IAClB,aAAa,EAAE,IAAI;IACnB,WAAW,EAAE,IAAI;IACjB,SAAS,EAAE,IAAI;IACf,OAAO,EAAE,IAAI;CACd,CAAC,CAAC;AAEH,sDAAsD;AACtD,IAAA,qBAAU,EAAC,GAAG,CAAC,CAAC;AAEhB,yCAAyC;AACzC,MAAM,QAAQ,GAAG,GAAG,CAAC,OAAO,CAAC,4BAAM,CAAC,CAAC;AAErC;;GAEG;AACH,MAAa,qBAAsB,SAAQ,KAAK;IAG5B;IAFlB,YACE,OAAe,EACC,MAAiB;QAEjC,KAAK,CAAC,OAAO,CAAC,CAAC;QAFC,WAAM,GAAN,MAAM,CAAW;QAGjC,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACtC,CAAC;IAED;;OAEG;IACH,kBAAkB;QAChB,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QAEjC,IAAI,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,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC;AACnC,CAAC;AAED;;;;;GAKG;AACH,SAAgB,eAAe,CAAC,MAAe;IAC7C,IAAI,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QACrB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,QAAQ,CAAC,MAAM,IAAI,EAAE,CAAC;AAC/B,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Resource creation methods - How resources are created in the system
3
+ */
4
+ /**
5
+ * Enumeration of all possible resource creation methods
6
+ */
7
+ export declare const CREATION_METHODS: {
8
+ readonly API: "api";
9
+ readonly UPLOAD: "upload";
10
+ readonly UI: "ui";
11
+ readonly REFERENCE: "reference";
12
+ readonly CLONE: "clone";
13
+ readonly GENERATED: "generated";
14
+ };
15
+ /**
16
+ * Type for resource creation methods
17
+ */
18
+ export type CreationMethod = typeof CREATION_METHODS[keyof typeof CREATION_METHODS];
19
+ //# sourceMappingURL=creation-methods.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"creation-methods.d.ts","sourceRoot":"","sources":["../src/creation-methods.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,eAAO,MAAM,gBAAgB;;;;;;;CAOnB,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,OAAO,gBAAgB,CAAC,MAAM,OAAO,gBAAgB,CAAC,CAAC"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ /**
3
+ * Resource creation methods - How resources are created in the system
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CREATION_METHODS = void 0;
7
+ /**
8
+ * Enumeration of all possible resource creation methods
9
+ */
10
+ exports.CREATION_METHODS = {
11
+ API: 'api',
12
+ UPLOAD: 'upload',
13
+ UI: 'ui',
14
+ REFERENCE: 'reference',
15
+ CLONE: 'clone',
16
+ GENERATED: 'generated',
17
+ };
18
+ //# sourceMappingURL=creation-methods.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"creation-methods.js","sourceRoot":"","sources":["../src/creation-methods.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH;;GAEG;AACU,QAAA,gBAAgB,GAAG;IAC9B,GAAG,EAAE,KAAK;IACV,MAAM,EAAE,QAAQ;IAChB,EAAE,EAAE,IAAI;IACR,SAAS,EAAE,WAAW;IACtB,KAAK,EAAE,OAAO;IACd,SAAS,EAAE,WAAW;CACd,CAAC"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Cryptographic utilities
3
+ */
4
+ /**
5
+ * Calculate SHA-256 checksum of content
6
+ * @param content The content to hash
7
+ * @returns Hex-encoded SHA-256 hash
8
+ */
9
+ export declare function calculateChecksum(content: string | Buffer): string;
10
+ /**
11
+ * Verify content against a checksum
12
+ * @param content The content to verify
13
+ * @param checksum The expected checksum
14
+ * @returns True if content matches checksum
15
+ */
16
+ export declare function verifyChecksum(content: string | Buffer, checksum: string): boolean;
17
+ /**
18
+ * Generate a random ID (12 character hex string)
19
+ * Similar to MongoDB ObjectId but simpler
20
+ */
21
+ export declare function generateId(): string;
22
+ /**
23
+ * Generate a UUID v4-like ID (without dashes)
24
+ */
25
+ export declare function generateUuid(): string;
26
+ /**
27
+ * Generate a secure random token
28
+ * @param bytes Number of random bytes (default 32)
29
+ * @returns Base64 encoded random token
30
+ */
31
+ export declare function generateToken(bytes?: number): string;
32
+ //# sourceMappingURL=crypto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../src/crypto.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAIlE;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAElF;AAED;;;GAGG;AACH,wBAAgB,UAAU,IAAI,MAAM,CAEnC;AAED;;GAEG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAErC;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,GAAE,MAAW,GAAG,MAAM,CAExD"}
package/dist/crypto.js ADDED
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ /**
3
+ * Cryptographic utilities
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.calculateChecksum = calculateChecksum;
7
+ exports.verifyChecksum = verifyChecksum;
8
+ exports.generateId = generateId;
9
+ exports.generateUuid = generateUuid;
10
+ exports.generateToken = generateToken;
11
+ const crypto_1 = require("crypto");
12
+ /**
13
+ * Calculate SHA-256 checksum of content
14
+ * @param content The content to hash
15
+ * @returns Hex-encoded SHA-256 hash
16
+ */
17
+ function calculateChecksum(content) {
18
+ const hash = (0, crypto_1.createHash)('sha256');
19
+ hash.update(content);
20
+ return hash.digest('hex');
21
+ }
22
+ /**
23
+ * Verify content against a checksum
24
+ * @param content The content to verify
25
+ * @param checksum The expected checksum
26
+ * @returns True if content matches checksum
27
+ */
28
+ function verifyChecksum(content, checksum) {
29
+ return calculateChecksum(content) === checksum;
30
+ }
31
+ /**
32
+ * Generate a random ID (12 character hex string)
33
+ * Similar to MongoDB ObjectId but simpler
34
+ */
35
+ function generateId() {
36
+ return (0, crypto_1.randomBytes)(6).toString('hex');
37
+ }
38
+ /**
39
+ * Generate a UUID v4-like ID (without dashes)
40
+ */
41
+ function generateUuid() {
42
+ return (0, crypto_1.randomBytes)(16).toString('hex');
43
+ }
44
+ /**
45
+ * Generate a secure random token
46
+ * @param bytes Number of random bytes (default 32)
47
+ * @returns Base64 encoded random token
48
+ */
49
+ function generateToken(bytes = 32) {
50
+ return (0, crypto_1.randomBytes)(bytes).toString('base64url');
51
+ }
52
+ //# sourceMappingURL=crypto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto.js","sourceRoot":"","sources":["../src/crypto.ts"],"names":[],"mappings":";AAAA;;GAEG;;AASH,8CAIC;AAQD,wCAEC;AAMD,gCAEC;AAKD,oCAEC;AAOD,sCAEC;AA7CD,mCAAiD;AAEjD;;;;GAIG;AACH,SAAgB,iBAAiB,CAAC,OAAwB;IACxD,MAAM,IAAI,GAAG,IAAA,mBAAU,EAAC,QAAQ,CAAC,CAAC;IAClC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACrB,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC5B,CAAC;AAED;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,OAAwB,EAAE,QAAgB;IACvE,OAAO,iBAAiB,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC;AACjD,CAAC;AAED;;;GAGG;AACH,SAAgB,UAAU;IACxB,OAAO,IAAA,oBAAW,EAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACxC,CAAC;AAED;;GAEG;AACH,SAAgB,YAAY;IAC1B,OAAO,IAAA,oBAAW,EAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACzC,CAAC;AAED;;;;GAIG;AACH,SAAgB,aAAa,CAAC,QAAgB,EAAE;IAC9C,OAAO,IAAA,oBAAW,EAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;AAClD,CAAC"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * DID (Decentralized Identifier) and W3C Agent utilities
3
+ *
4
+ * Provides utilities for working with DID:WEB identifiers and converting
5
+ * between user representations and W3C Web Annotation Agent objects.
6
+ */
7
+ import type { components } from '@semiont/api-client';
8
+ type Agent = components['schemas']['Agent'];
9
+ /**
10
+ * Convert a user object to a DID:WEB identifier
11
+ *
12
+ * Format: did:web:domain.com:users:userId
13
+ * Example: did:web:example.com:users:abc123
14
+ *
15
+ * This is used for W3C Web Annotation compliance and federation readiness.
16
+ *
17
+ * @param user - User object with id and domain
18
+ * @returns DID:WEB identifier string
19
+ */
20
+ export declare function userToDid(user: {
21
+ id: string;
22
+ domain: string;
23
+ }): string;
24
+ /**
25
+ * Convert a user object to a W3C Agent object with DID:WEB identifier
26
+ *
27
+ * Creates a full Agent object for W3C Web Annotation compliance.
28
+ * Includes DID:WEB identifier, type, and name.
29
+ *
30
+ * @param user - User object with id, domain, name, and email
31
+ * @returns W3C Agent object
32
+ */
33
+ export declare function userToAgent(user: {
34
+ id: string;
35
+ domain: string;
36
+ name: string | null;
37
+ email: string;
38
+ }): Agent;
39
+ /**
40
+ * Convert a DID string to a minimal W3C Agent object
41
+ *
42
+ * Used when reconstructing annotations from events where only the DID is available.
43
+ * Creates a minimal Agent with just the required fields (id, type).
44
+ * Name is derived from the DID for display purposes.
45
+ *
46
+ * @param did - DID:WEB identifier string
47
+ * @returns Minimal W3C Agent object
48
+ */
49
+ export declare function didToAgent(did: string): Agent;
50
+ export {};
51
+ //# sourceMappingURL=did-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"did-utils.d.ts","sourceRoot":"","sources":["../src/did-utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEtD,KAAK,KAAK,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,CAAC;AAE5C;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAEtE;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;CACf,GAAG,KAAK,CAMR;AAED;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CAU7C"}
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ /**
3
+ * DID (Decentralized Identifier) and W3C Agent utilities
4
+ *
5
+ * Provides utilities for working with DID:WEB identifiers and converting
6
+ * between user representations and W3C Web Annotation Agent objects.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.userToDid = userToDid;
10
+ exports.userToAgent = userToAgent;
11
+ exports.didToAgent = didToAgent;
12
+ /**
13
+ * Convert a user object to a DID:WEB identifier
14
+ *
15
+ * Format: did:web:domain.com:users:userId
16
+ * Example: did:web:example.com:users:abc123
17
+ *
18
+ * This is used for W3C Web Annotation compliance and federation readiness.
19
+ *
20
+ * @param user - User object with id and domain
21
+ * @returns DID:WEB identifier string
22
+ */
23
+ function userToDid(user) {
24
+ return `did:web:${user.domain}:users:${user.id}`;
25
+ }
26
+ /**
27
+ * Convert a user object to a W3C Agent object with DID:WEB identifier
28
+ *
29
+ * Creates a full Agent object for W3C Web Annotation compliance.
30
+ * Includes DID:WEB identifier, type, and name.
31
+ *
32
+ * @param user - User object with id, domain, name, and email
33
+ * @returns W3C Agent object
34
+ */
35
+ function userToAgent(user) {
36
+ return {
37
+ type: 'Person',
38
+ id: userToDid(user),
39
+ name: user.name || user.email,
40
+ };
41
+ }
42
+ /**
43
+ * Convert a DID string to a minimal W3C Agent object
44
+ *
45
+ * Used when reconstructing annotations from events where only the DID is available.
46
+ * Creates a minimal Agent with just the required fields (id, type).
47
+ * Name is derived from the DID for display purposes.
48
+ *
49
+ * @param did - DID:WEB identifier string
50
+ * @returns Minimal W3C Agent object
51
+ */
52
+ function didToAgent(did) {
53
+ // Extract user ID from DID format: did:web:domain.com:users:userId
54
+ const parts = did.split(':');
55
+ const userId = parts[parts.length - 1] || 'unknown';
56
+ return {
57
+ type: 'Person',
58
+ id: did,
59
+ name: userId, // Use user ID as name since we don't have full user data
60
+ };
61
+ }
62
+ //# sourceMappingURL=did-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"did-utils.js","sourceRoot":"","sources":["../src/did-utils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAiBH,8BAEC;AAWD,kCAWC;AAYD,gCAUC;AAzDD;;;;;;;;;;GAUG;AACH,SAAgB,SAAS,CAAC,IAAoC;IAC5D,OAAO,WAAW,IAAI,CAAC,MAAM,UAAU,IAAI,CAAC,EAAE,EAAE,CAAC;AACnD,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,WAAW,CAAC,IAK3B;IACC,OAAO;QACL,IAAI,EAAE,QAAiB;QACvB,EAAE,EAAE,SAAS,CAAC,IAAI,CAAC;QACnB,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK;KAC9B,CAAC;AACJ,CAAC;AAED;;;;;;;;;GASG;AACH,SAAgB,UAAU,CAAC,GAAW;IACpC,mEAAmE;IACnE,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC7B,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,SAAS,CAAC;IAEpD,OAAO;QACL,IAAI,EAAE,QAAiB;QACvB,EAAE,EAAE,GAAG;QACP,IAAI,EAAE,MAAM,EAAE,yDAAyD;KACxE,CAAC;AACJ,CAAC"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Common error classes
3
+ */
4
+ /**
5
+ * Base error class for Semiont applications
6
+ */
7
+ export declare class SemiontError extends Error {
8
+ code: string;
9
+ details?: Record<string, any> | undefined;
10
+ constructor(message: string, code: string, details?: Record<string, any> | undefined);
11
+ }
12
+ /**
13
+ * Error thrown when validation fails
14
+ */
15
+ export declare class ValidationError extends SemiontError {
16
+ constructor(message: string, details?: Record<string, any>);
17
+ }
18
+ /**
19
+ * Error thrown by scripts
20
+ */
21
+ export declare class ScriptError extends SemiontError {
22
+ constructor(message: string, code?: string, details?: Record<string, any>);
23
+ }
24
+ /**
25
+ * Error thrown when a resource is not found
26
+ */
27
+ export declare class NotFoundError extends SemiontError {
28
+ constructor(resource: string, id?: string);
29
+ }
30
+ /**
31
+ * Error thrown when user is not authorized
32
+ */
33
+ export declare class UnauthorizedError extends SemiontError {
34
+ constructor(message?: string, details?: Record<string, any>);
35
+ }
36
+ /**
37
+ * Error thrown when operation would conflict with existing data
38
+ */
39
+ export declare class ConflictError extends SemiontError {
40
+ constructor(message: string, details?: Record<string, any>);
41
+ }
42
+ /**
43
+ * API Error class for handling HTTP errors
44
+ * Used by API clients to represent failed HTTP requests
45
+ */
46
+ export declare class APIError extends Error {
47
+ status: number;
48
+ data: any;
49
+ constructor(status: number, data: any, message?: string);
50
+ }
51
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,qBAAa,YAAa,SAAQ,KAAK;IAG5B,IAAI,EAAE,MAAM;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;gBAFpC,OAAO,EAAE,MAAM,EACR,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,YAAA;CAMvC;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,YAAY;gBACnC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;CAI3D;AAED;;GAEG;AACH,qBAAa,WAAY,SAAQ,YAAY;gBAC/B,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,MAAuB,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;CAI1F;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,YAAY;gBACjC,QAAQ,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM;CAK1C;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,YAAY;gBACrC,OAAO,GAAE,MAAuB,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;CAI5E;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,YAAY;gBACjC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;CAI3D;AAED;;;GAGG;AACH,qBAAa,QAAS,SAAQ,KAAK;IAExB,MAAM,EAAE,MAAM;IACd,IAAI,EAAE,GAAG;gBADT,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,GAAG,EAChB,OAAO,CAAC,EAAE,MAAM;CAMnB"}
package/dist/errors.js ADDED
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ /**
3
+ * Common error classes
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.APIError = exports.ConflictError = exports.UnauthorizedError = exports.NotFoundError = exports.ScriptError = exports.ValidationError = exports.SemiontError = void 0;
7
+ /**
8
+ * Base error class for Semiont applications
9
+ */
10
+ class SemiontError extends Error {
11
+ code;
12
+ details;
13
+ constructor(message, code, details) {
14
+ super(message);
15
+ this.code = code;
16
+ this.details = details;
17
+ this.name = 'SemiontError';
18
+ Error.captureStackTrace(this, this.constructor);
19
+ }
20
+ }
21
+ exports.SemiontError = SemiontError;
22
+ /**
23
+ * Error thrown when validation fails
24
+ */
25
+ class ValidationError extends SemiontError {
26
+ constructor(message, details) {
27
+ super(message, 'VALIDATION_ERROR', details);
28
+ this.name = 'ValidationError';
29
+ }
30
+ }
31
+ exports.ValidationError = ValidationError;
32
+ /**
33
+ * Error thrown by scripts
34
+ */
35
+ class ScriptError extends SemiontError {
36
+ constructor(message, code = 'SCRIPT_ERROR', details) {
37
+ super(message, code, details);
38
+ this.name = 'ScriptError';
39
+ }
40
+ }
41
+ exports.ScriptError = ScriptError;
42
+ /**
43
+ * Error thrown when a resource is not found
44
+ */
45
+ class NotFoundError extends SemiontError {
46
+ constructor(resource, id) {
47
+ const message = id ? `${resource} with id '${id}' not found` : `${resource} not found`;
48
+ super(message, 'NOT_FOUND', { resource, id });
49
+ this.name = 'NotFoundError';
50
+ }
51
+ }
52
+ exports.NotFoundError = NotFoundError;
53
+ /**
54
+ * Error thrown when user is not authorized
55
+ */
56
+ class UnauthorizedError extends SemiontError {
57
+ constructor(message = 'Unauthorized', details) {
58
+ super(message, 'UNAUTHORIZED', details);
59
+ this.name = 'UnauthorizedError';
60
+ }
61
+ }
62
+ exports.UnauthorizedError = UnauthorizedError;
63
+ /**
64
+ * Error thrown when operation would conflict with existing data
65
+ */
66
+ class ConflictError extends SemiontError {
67
+ constructor(message, details) {
68
+ super(message, 'CONFLICT', details);
69
+ this.name = 'ConflictError';
70
+ }
71
+ }
72
+ exports.ConflictError = ConflictError;
73
+ /**
74
+ * API Error class for handling HTTP errors
75
+ * Used by API clients to represent failed HTTP requests
76
+ */
77
+ class APIError extends Error {
78
+ status;
79
+ data;
80
+ constructor(status, data, message) {
81
+ super(message || `API Error: ${status}`);
82
+ this.status = status;
83
+ this.data = data;
84
+ this.name = 'APIError';
85
+ Error.captureStackTrace(this, this.constructor);
86
+ }
87
+ }
88
+ exports.APIError = APIError;
89
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH;;GAEG;AACH,MAAa,YAAa,SAAQ,KAAK;IAG5B;IACA;IAHT,YACE,OAAe,EACR,IAAY,EACZ,OAA6B;QAEpC,KAAK,CAAC,OAAO,CAAC,CAAC;QAHR,SAAI,GAAJ,IAAI,CAAQ;QACZ,YAAO,GAAP,OAAO,CAAsB;QAGpC,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;IAClD,CAAC;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