@classytic/access 0.1.0 → 0.1.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.1
4
+
5
+ Patch — §P8.1 session guard (UnmanagedSessionError), ISO 4217 currency gate via CURRENCY_PATTERN.
6
+
3
7
  ## 0.1.0
4
8
 
5
9
  Initial release — the access **entitlement** engine.
package/dist/index.d.mts CHANGED
@@ -325,6 +325,16 @@ declare class QuotaExhaustedError extends AccessError {
325
325
  declare class InvalidEntitlementTransitionError extends AccessError {
326
326
  constructor(from: string, to: string);
327
327
  }
328
+ /**
329
+ * Thrown when a host passes `ctx.session` (it owns the outer transaction)
330
+ * but NO outbox is wired: there is no correct delivery path for the event.
331
+ * Publishing immediately would leak ghost events if the host rolls back;
332
+ * silently dropping loses the event entirely. Wire an `OutboxStore` —
333
+ * session + outbox is legal durable-relay-only mode (§P8.1).
334
+ */
335
+ declare class UnmanagedSessionError extends AccessError {
336
+ constructor();
337
+ }
328
338
  declare class VersionMismatchError extends AccessError {
329
339
  constructor(id: string, expectedVersion: number);
330
340
  }
@@ -359,4 +369,4 @@ declare class InProcessAccessBus implements EventTransport {
359
369
  close(): Promise<void>;
360
370
  }
361
371
  //#endregion
362
- export { ACCESS_EVENTS, AccessCapabilityError, type AccessConfig, type AccessContext, type AccessDecision, type AccessEngine, AccessError, type AccessEventDefinition, type AccessEventName, type AccessGrantState, type AccessLogger, type AccessModelBundle, AccessModelCollisionError, type AccessModelName, type AccessReason, type AccessRepositories, type AccessTenantOptions, type CheckResult, ENTITLEMENT_STATUS, ENTITLEMENT_STATUS_VALUES, type EntitlementDocument, EntitlementNotFoundError, EntitlementRepository, type EntitlementRepositoryConfig, type EntitlementSource, type EntitlementStatus, type EntitlementTarget, type EntitlementUsage, type GrantInput, InProcessAccessBus, InvalidEntitlementTransitionError, InvalidOutboxEventError, LIVE_STATUSES, type OutboxAcknowledgeOptions, type OutboxClaimOptions, type OutboxFailOptions, OutboxOwnershipError, type OutboxStore, type OutboxWriteOptions, QuotaExhaustedError, VersionMismatchError, accessEventDefinitions, canEntitlementTransition, createAccess, createAccessModels, evaluateAccess, hasAccess, isEntitlementStatus };
372
+ export { ACCESS_EVENTS, AccessCapabilityError, type AccessConfig, type AccessContext, type AccessDecision, type AccessEngine, AccessError, type AccessEventDefinition, type AccessEventName, type AccessGrantState, type AccessLogger, type AccessModelBundle, AccessModelCollisionError, type AccessModelName, type AccessReason, type AccessRepositories, type AccessTenantOptions, type CheckResult, ENTITLEMENT_STATUS, ENTITLEMENT_STATUS_VALUES, type EntitlementDocument, EntitlementNotFoundError, EntitlementRepository, type EntitlementRepositoryConfig, type EntitlementSource, type EntitlementStatus, type EntitlementTarget, type EntitlementUsage, type GrantInput, InProcessAccessBus, InvalidEntitlementTransitionError, InvalidOutboxEventError, LIVE_STATUSES, type OutboxAcknowledgeOptions, type OutboxClaimOptions, type OutboxFailOptions, OutboxOwnershipError, type OutboxStore, type OutboxWriteOptions, QuotaExhaustedError, UnmanagedSessionError, VersionMismatchError, accessEventDefinitions, canEntitlementTransition, createAccess, createAccessModels, evaluateAccess, hasAccess, isEntitlementStatus };
package/dist/index.mjs CHANGED
@@ -2,6 +2,7 @@ import { evaluateAccess, hasAccess } from "./domain/access-decision.mjs";
2
2
  import { l as accessEventDefinitions, u as ACCESS_EVENTS } from "./event-catalog-BVD_rFlc.mjs";
3
3
  import { Repository, createOptionsExtractor, multiTenantPlugin, softDeletePlugin } from "@classytic/mongokit";
4
4
  import { resolveTenantConfig } from "@classytic/repo-core/tenant";
5
+ import { CURRENCY_PATTERN } from "@classytic/primitives/currency";
5
6
  import mongoose, { Schema } from "mongoose";
6
7
  import { createEvent, matchEventPattern } from "@classytic/primitives/events";
7
8
  import { InvalidOutboxEventError, OutboxOwnershipError } from "@classytic/primitives/outbox";
@@ -173,7 +174,9 @@ function buildEntitlementSchema() {
173
174
  },
174
175
  currency: {
175
176
  type: String,
176
- trim: true
177
+ trim: true,
178
+ uppercase: true,
179
+ match: [CURRENCY_PATTERN, "currency must be an ISO 4217 code (3 uppercase letters)"]
177
180
  },
178
181
  renewedFromRef: {
179
182
  type: String,
@@ -320,6 +323,18 @@ var InvalidEntitlementTransitionError = class extends AccessError {
320
323
  super(`Invalid entitlement transition: ${from} → ${to}`, "access.invalid_transition", 409);
321
324
  }
322
325
  };
326
+ /**
327
+ * Thrown when a host passes `ctx.session` (it owns the outer transaction)
328
+ * but NO outbox is wired: there is no correct delivery path for the event.
329
+ * Publishing immediately would leak ghost events if the host rolls back;
330
+ * silently dropping loses the event entirely. Wire an `OutboxStore` —
331
+ * session + outbox is legal durable-relay-only mode (§P8.1).
332
+ */
333
+ var UnmanagedSessionError = class extends AccessError {
334
+ constructor() {
335
+ super("access.session.unmanaged", "ctx.session provided but no OutboxStore is wired — events would be lost. Wire an outbox (durable relay delivers post-commit) or drop the session.", 409);
336
+ }
337
+ };
323
338
  var VersionMismatchError = class extends AccessError {
324
339
  constructor(id, expectedVersion) {
325
340
  super(`Concurrent modification on ${id} (expected version ${expectedVersion}) — retry.`, "access.concurrency.version_mismatch", 409);
@@ -355,6 +370,7 @@ function createEvent$1(type, payload, ctx, meta) {
355
370
  //#region src/events/dispatch.ts
356
371
  async function emitDomainEvent(channels, type, payload, ctx, resourceId) {
357
372
  if (!channels.eventTransport && !channels.outbox) return;
373
+ if (ctx.session && !channels.outbox) throw new UnmanagedSessionError();
358
374
  const meta = {
359
375
  resource: "entitlement",
360
376
  resourceId,
@@ -851,4 +867,4 @@ async function createAccess(config) {
851
867
  };
852
868
  }
853
869
  //#endregion
854
- export { ACCESS_EVENTS, AccessCapabilityError, AccessError, AccessModelCollisionError, ENTITLEMENT_STATUS, ENTITLEMENT_STATUS_VALUES, EntitlementNotFoundError, EntitlementRepository, InProcessAccessBus, InvalidEntitlementTransitionError, InvalidOutboxEventError, LIVE_STATUSES, OutboxOwnershipError, QuotaExhaustedError, VersionMismatchError, accessEventDefinitions, canEntitlementTransition, createAccess, createAccessModels, evaluateAccess, hasAccess, isEntitlementStatus };
870
+ export { ACCESS_EVENTS, AccessCapabilityError, AccessError, AccessModelCollisionError, ENTITLEMENT_STATUS, ENTITLEMENT_STATUS_VALUES, EntitlementNotFoundError, EntitlementRepository, InProcessAccessBus, InvalidEntitlementTransitionError, InvalidOutboxEventError, LIVE_STATUSES, OutboxOwnershipError, QuotaExhaustedError, UnmanagedSessionError, VersionMismatchError, accessEventDefinitions, canEntitlementTransition, createAccess, createAccessModels, evaluateAccess, hasAccess, isEntitlementStatus };
@@ -1,4 +1,5 @@
1
1
  import { metadataSchema, modelSchema, refSchema, scopeKeySchema, sourceSchema } from "./common.mjs";
2
+ import { CURRENCY_PATTERN } from "@classytic/primitives/currency";
2
3
  import { z } from "zod";
3
4
  //#region src/schemas/entitlement.ts
4
5
  /**
@@ -20,7 +21,7 @@ const grantSchema = z.object({
20
21
  originRef: refSchema.optional(),
21
22
  originModel: modelSchema.optional(),
22
23
  amount: z.number().int().nullable().optional(),
23
- currency: z.string().length(3).optional(),
24
+ currency: z.string().regex(CURRENCY_PATTERN, "ISO 4217 (3 uppercase letters)").optional(),
24
25
  metadata: metadataSchema.optional(),
25
26
  renew: z.boolean().optional()
26
27
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@classytic/access",
3
- "version": "0.1.0",
4
- "description": "Access ENTITLEMENT engine — time-bound (or lifetime) grants of access to any resource: course enrollment, file download, API access, membership, feature flag, any service. Like a session, but durable: the grant is a permanent record, the RIGHT to access is COMPUTED (never TTL-deleted). Single responsibility: it answers 'does this subject currently hold a live grant to this resource', NOT the purchase (@classytic/order), the money (@classytic/revenue), or the catalog item (@classytic/catalog). Powered by @classytic/mongokit.",
3
+ "version": "0.1.1",
4
+ "description": "Access ENTITLEMENT engine — time-bound (or lifetime) grants of access to any resource: course enrollment, file download, API access, membership, feature flag, any service. Like a session, but durable: the grant is a permanent record, the RIGHT to access is COMPUTED (never TTL-deleted). Single responsibility: it answers 'does this subject currently hold a live grant to this resource', NOT the purchase (@classytic/order), the money (@classytic/revenue), or the catalog item (@classytic/catalog). Powered by @classytic/mongokit.",
5
5
  "author": "Classytic",
6
6
  "license": "MIT",
7
7
  "type": "module",
@@ -50,17 +50,17 @@
50
50
  "push": "classytic-push"
51
51
  },
52
52
  "peerDependencies": {
53
- "@classytic/mongokit": ">=3.16.0",
54
- "@classytic/primitives": ">=0.7.1",
55
- "@classytic/repo-core": ">=0.6.0",
53
+ "@classytic/mongokit": ">=3.18.0",
54
+ "@classytic/primitives": ">=0.9.1",
55
+ "@classytic/repo-core": ">=0.7.0",
56
56
  "mongoose": ">=9.4.1",
57
57
  "zod": ">=4.0.0"
58
58
  },
59
59
  "devDependencies": {
60
60
  "@classytic/dev-tools": "^0.2.0",
61
- "@classytic/mongokit": "^3.16.1",
62
- "@classytic/primitives": "^0.7.2",
63
- "@classytic/repo-core": "^0.6.0",
61
+ "@classytic/mongokit": "^3.18.0",
62
+ "@classytic/primitives": "^0.9.1",
63
+ "@classytic/repo-core": "^0.7.0",
64
64
  "@types/node": "^22.19.21",
65
65
  "@vitest/coverage-v8": "^4.1.9",
66
66
  "mongodb-memory-server": "^11.2.0",
@@ -85,3 +85,4 @@
85
85
  "classytic"
86
86
  ]
87
87
  }
88
+