@sentropic/artifacts 0.1.4 → 0.2.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 (69) hide show
  1. package/README.md +17 -0
  2. package/dist/adapters/postgres-commit.d.ts +15 -0
  3. package/dist/adapters/postgres-commit.js +80 -0
  4. package/dist/adapters/postgres.d.ts +5 -2
  5. package/dist/adapters/postgres.js +39 -0
  6. package/dist/http.d.ts +41 -30
  7. package/dist/http.js +168 -507
  8. package/dist/index.d.ts +2 -0
  9. package/dist/index.js +2 -0
  10. package/dist/mcp-core.d.ts +29 -39
  11. package/dist/mcp-core.js +83 -244
  12. package/dist/mcp.js +5 -5
  13. package/dist/profile/contracts.d.ts +67 -0
  14. package/dist/profile/contracts.js +31 -0
  15. package/dist/profile/index.d.ts +6 -0
  16. package/dist/profile/index.js +117 -0
  17. package/dist/profile/json.d.ts +10 -0
  18. package/dist/profile/json.js +76 -0
  19. package/dist/profile/radar.d.ts +3 -0
  20. package/dist/profile/radar.js +21 -0
  21. package/dist/profile/schemas.d.ts +6 -0
  22. package/dist/profile/schemas.js +76 -0
  23. package/dist/profile/validation.d.ts +5 -0
  24. package/dist/profile/validation.js +104 -0
  25. package/dist/profile/validators.d.ts +3 -0
  26. package/dist/profile/validators.js +51 -0
  27. package/dist/server/authorized-replay.d.ts +33 -0
  28. package/dist/server/authorized-replay.js +31 -0
  29. package/dist/server/command-identity.d.ts +52 -0
  30. package/dist/server/command-identity.js +71 -0
  31. package/dist/server/commit/brands.d.ts +7 -0
  32. package/dist/server/commit/brands.js +3 -0
  33. package/dist/server/commit/coordinator.d.ts +2 -0
  34. package/dist/server/commit/coordinator.js +729 -0
  35. package/dist/server/commit/types.d.ts +379 -0
  36. package/dist/server/commit/types.js +94 -0
  37. package/dist/server/commit-contract.d.ts +4 -0
  38. package/dist/server/commit-contract.js +2 -0
  39. package/dist/server/failures.d.ts +84 -0
  40. package/dist/server/failures.js +133 -0
  41. package/dist/server/gc.d.ts +42 -1
  42. package/dist/server/gc.js +168 -5
  43. package/dist/server/idempotency.d.ts +4 -0
  44. package/dist/server/idempotency.js +14 -0
  45. package/dist/server/lifecycle.d.ts +2 -1
  46. package/dist/server/lifecycle.js +15 -1
  47. package/dist/server/object-intents.d.ts +14 -1
  48. package/dist/server/object-intents.js +31 -0
  49. package/dist/server/outcome-contract.d.ts +3 -0
  50. package/dist/server/outcome-contract.js +3 -0
  51. package/dist/server/outcome-projection.d.ts +21 -0
  52. package/dist/server/outcome-projection.js +29 -0
  53. package/dist/server/preparation-cleanup.d.ts +31 -0
  54. package/dist/server/preparation-cleanup.js +106 -0
  55. package/dist/server/publication.d.ts +76 -0
  56. package/dist/server/publication.js +270 -31
  57. package/dist/server/service.d.ts +60 -0
  58. package/dist/server/service.js +181 -0
  59. package/dist/testing.d.ts +50 -0
  60. package/dist/testing.js +86 -0
  61. package/docs/migration-l6.md +129 -0
  62. package/examples/radar-commit-setup.ts +299 -0
  63. package/l0-freeze/command-identity-contract.ts +303 -0
  64. package/l0-freeze/commit-contract.ts +421 -0
  65. package/l0-freeze/failure-contract.ts +174 -0
  66. package/l0-freeze/profile-contract.ts +219 -0
  67. package/migrations/0003_coordinator.sql +28 -0
  68. package/package.json +27 -1
  69. package/src/contracts.ts +125 -0
@@ -0,0 +1,71 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { isArtifactId } from '../contracts.js';
3
+ import { assertCompiledArtifactsProfile, ArtifactProfileInputError } from '../profile/index.js';
4
+ import { assertWellFormed, copyJson, freezeDeep, orderedDigest } from '../profile/json.js';
5
+ export const COMMAND_CODEC_VERSION = 'artifacts-command/v1';
6
+ /** Preserve Radar's durable bytes only within an explicitly qualified domain. */
7
+ export function createRadarKeyDerivation(config) {
8
+ if (typeof config.storageScopeId !== 'string' || config.storageScopeId.trim() !== config.storageScopeId ||
9
+ !/^[A-Za-z0-9_-]+$/.test(config.storageScopeId) ||
10
+ !Array.isArray(config.actorIds) || !config.actorIds.length) {
11
+ throw new Error('unqualified Radar key domain');
12
+ }
13
+ const scope = config.storageScopeId;
14
+ const actors = new Set(config.actorIds);
15
+ for (const actor of actors) {
16
+ if (typeof actor !== 'string' || !actor.length)
17
+ throw new Error('invalid Radar actor domain');
18
+ assertWellFormed(actor);
19
+ for (const other of actors) {
20
+ if (other === actor || !other.startsWith(`${actor}|`))
21
+ continue;
22
+ const [operation, objectId] = other.slice(actor.length + 1).split('|');
23
+ if ((operation === 'ensure' && objectId === '') || (operation === 'publish' && isArtifactId(objectId))) {
24
+ throw new Error('ambiguous Radar actor domain');
25
+ }
26
+ }
27
+ }
28
+ return Object.freeze({
29
+ algorithm: 'radar-derive-idempotency-v1',
30
+ derive(input) {
31
+ const { storageScopeId, actorId, operation, objectId, callerKey } = input;
32
+ if (storageScopeId !== scope || !actors.has(actorId) ||
33
+ (operation !== 'ensure' && operation !== 'publish') ||
34
+ (operation === 'ensure' ? objectId !== '' : !isArtifactId(objectId)))
35
+ throw new ArtifactProfileInputError();
36
+ assertWellFormed(callerKey);
37
+ if (!callerKey.trim() || callerKey.length > 256)
38
+ throw new ArtifactProfileInputError();
39
+ return createHash('sha256').update([scope, actorId, operation, objectId, callerKey].join('|'), 'utf8')
40
+ .digest('hex');
41
+ },
42
+ });
43
+ }
44
+ export const commandDigest = orderedDigest;
45
+ /** No caller hash, actor, scope, transport or audit identifier enters this API through arguments. */
46
+ export function createArtifactCommand(profile, name, args, authority, derivation, envelopeKey) {
47
+ assertCompiledArtifactsProfile(profile);
48
+ if (derivation.algorithm !== profile.profile.rules.keyDerivationAlgorithm)
49
+ throw new Error('profile/derivation mismatch');
50
+ const normalized = profile.validate(name, args, envelopeKey);
51
+ if (name !== 'artifacts_ensure' && name !== 'artifacts_publish')
52
+ throw new ArtifactProfileInputError(true);
53
+ const operation = name === 'artifacts_ensure' ? 'ensure' : 'publish';
54
+ const { idempotencyKey, ...payload } = normalized;
55
+ const scopeBinding = authority.storageScopeId;
56
+ if (typeof scopeBinding !== 'string' || typeof authority.actorId !== 'string')
57
+ throw new ArtifactProfileInputError();
58
+ assertWellFormed(scopeBinding);
59
+ assertWellFormed(authority.actorId);
60
+ if (!scopeBinding || !authority.actorId)
61
+ throw new ArtifactProfileInputError();
62
+ const provenance = { kind: 'inline-original' };
63
+ const effective = copyJson({ operation, scopeBinding, payload: { ...payload, provenance } });
64
+ const internalKey = derivation.derive({ storageScopeId: scopeBinding, actorId: authority.actorId, operation,
65
+ objectId: operation === 'publish' ? normalized.artifactId : '',
66
+ callerKey: idempotencyKey });
67
+ if (!/^[0-9a-f]{64}$/.test(internalKey) || !derivation.algorithm)
68
+ throw new Error('invalid key derivation binding');
69
+ return freezeDeep({ ...effective, provenance, identity: { internalKey,
70
+ commandHash: commandDigest(effective), codecVersion: COMMAND_CODEC_VERSION } });
71
+ }
@@ -0,0 +1,7 @@
1
+ import type { ArtifactAuthorizationFence, ArtifactCommitTransaction } from '#artifacts-frozen-commit';
2
+ type CommitFenceBrand = Extract<keyof ArtifactAuthorizationFence, symbol>;
3
+ type CommitTransactionBrand = Extract<keyof ArtifactCommitTransaction, symbol>;
4
+ /** Runtime credentials implement the frozen brands without changing the freeze. */
5
+ export declare const commitFenceBrand: CommitFenceBrand;
6
+ export declare const commitTransactionBrand: CommitTransactionBrand;
7
+ export {};
@@ -0,0 +1,3 @@
1
+ /** Runtime credentials implement the frozen brands without changing the freeze. */
2
+ export const commitFenceBrand = Symbol('artifact-authorization-fence');
3
+ export const commitTransactionBrand = Symbol('artifact-commit-transaction');
@@ -0,0 +1,2 @@
1
+ import { type ArtifactCommitCoordinator, type CommitCoordinatorOptions } from './types.js';
2
+ export declare function createArtifactCommitCoordinator(options: CommitCoordinatorOptions): ArtifactCommitCoordinator;