@happyvertical/smrt-types 0.51.31 → 0.51.33

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.
@@ -0,0 +1,153 @@
1
+ /**
2
+ * Universal Signaling System Types
3
+ *
4
+ * This module defines the core types for the SMRT signaling system,
5
+ * which provides automatic method tracking and event distribution
6
+ * for logging, metrics, pub/sub, and other observability needs.
7
+ */
8
+ /**
9
+ * Lifecycle stage of a signal emitted during SMRT method execution.
10
+ *
11
+ * - `'start'` — emitted when a tracked method begins executing
12
+ * - `'step'` — emitted manually within a method for progress tracking
13
+ * - `'end'` — emitted when a method completes successfully
14
+ * - `'error'` — emitted when a method throws an unhandled exception
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * adapter.handle = async (signal: Signal) => {
19
+ * if (signal.type === 'error') {
20
+ * logger.error(`${signal.className}.${signal.method} failed`, signal.error);
21
+ * }
22
+ * };
23
+ * ```
24
+ *
25
+ * @see {@link Signal} for the full signal payload shape
26
+ * @see {@link SignalAdapter} for consuming signals
27
+ */
28
+ export type SignalType = 'start' | 'step' | 'end' | 'error';
29
+ /**
30
+ * Signal emitted during SMRT method execution.
31
+ *
32
+ * Signals provide automatic observability into method execution,
33
+ * enabling logging, metrics, pub/sub updates, and other integrations
34
+ * without requiring manual instrumentation.
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * // Logging adapter
39
+ * const loggingAdapter: SignalAdapter = {
40
+ * async handle(signal: Signal) {
41
+ * const label = `${signal.className}.${signal.method} [${signal.id}]`;
42
+ * if (signal.type === 'start') console.log(`→ ${label}`);
43
+ * if (signal.type === 'end') console.log(`✓ ${label} (${signal.duration}ms)`);
44
+ * if (signal.type === 'error') console.error(`✗ ${label}`, signal.error);
45
+ * },
46
+ * };
47
+ * ```
48
+ *
49
+ * @see {@link SignalType} for the lifecycle stage values
50
+ * @see {@link SignalAdapter} for implementing a consumer
51
+ */
52
+ export interface Signal {
53
+ /**
54
+ * Unique identifier for this specific execution
55
+ * Generated once per method invocation
56
+ */
57
+ id: string;
58
+ /**
59
+ * ID of the SMRT object instance
60
+ */
61
+ objectId: string;
62
+ /**
63
+ * Name of the SMRT class
64
+ */
65
+ className: string;
66
+ /**
67
+ * Name of the method being executed
68
+ */
69
+ method: string;
70
+ /**
71
+ * Signal type indicating lifecycle stage:
72
+ * - 'start': Method execution started
73
+ * - 'step': Manual step within method (optional)
74
+ * - 'end': Method execution completed successfully
75
+ * - 'error': Method execution failed
76
+ */
77
+ type: SignalType;
78
+ /**
79
+ * Optional step label for manual progress tracking
80
+ * Developers can emit custom steps within methods using bus.emit()
81
+ */
82
+ step?: string;
83
+ /**
84
+ * Sanitized method arguments (sensitive data removed)
85
+ * Objects with @sensitive JSDoc tags are excluded
86
+ */
87
+ args?: unknown[];
88
+ /**
89
+ * Method result (only present on 'end' signals)
90
+ */
91
+ result?: unknown;
92
+ /**
93
+ * Error that was thrown (only present on 'error' signals)
94
+ */
95
+ error?: Error;
96
+ /**
97
+ * Method execution duration in milliseconds
98
+ * Only present on 'end' and 'error' signals
99
+ */
100
+ duration?: number;
101
+ /**
102
+ * Timestamp when signal was emitted
103
+ */
104
+ timestamp: Date;
105
+ /**
106
+ * Optional additional context
107
+ * Can include tracing IDs, user context, request metadata, etc.
108
+ */
109
+ metadata?: Record<string, unknown>;
110
+ }
111
+ /**
112
+ * Adapter interface for consuming signals from the SMRT signaling system.
113
+ *
114
+ * Adapters process signals for specific purposes:
115
+ * - **Logging**: write to console, file, or a logging service
116
+ * - **Metrics**: track execution counts, durations, and error rates
117
+ * - **Pub/Sub**: broadcast real-time updates to connected clients
118
+ * - **Tracing**: forward spans to a distributed tracing system (e.g., OpenTelemetry)
119
+ *
120
+ * Adapters are fire-and-forget — errors thrown inside `handle()` are caught
121
+ * by the SignalBus and do not interrupt the main execution flow.
122
+ *
123
+ * @example
124
+ * ```typescript
125
+ * class MetricsAdapter implements SignalAdapter {
126
+ * async handle(signal: Signal): Promise<void> {
127
+ * if (signal.type === 'end') {
128
+ * metrics.histogram('smrt.method.duration', signal.duration ?? 0, {
129
+ * class: signal.className,
130
+ * method: signal.method,
131
+ * });
132
+ * }
133
+ * }
134
+ * }
135
+ * ```
136
+ *
137
+ * @see {@link Signal} for the payload each adapter receives
138
+ * @see {@link SignalType} for the lifecycle stages
139
+ */
140
+ export interface SignalAdapter {
141
+ /**
142
+ * Handle a signal event
143
+ *
144
+ * @param signal - The signal to process
145
+ * @returns Promise that resolves when signal is handled
146
+ *
147
+ * @remarks
148
+ * This method should not throw - errors are caught by the SignalBus.
149
+ * Implementations should handle their own error logging/recovery.
150
+ */
151
+ handle(signal: Signal): Promise<void>;
152
+ }
153
+ //# sourceMappingURL=signals.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signals.d.ts","sourceRoot":"","sources":["../src/signals.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,CAAC;AAE5D;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,WAAW,MAAM;IACrB;;;OAGG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;;;;;OAMG;IACH,IAAI,EAAE,UAAU,CAAC;IAEjB;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC;IAEjB;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,KAAK,CAAC,EAAE,KAAK,CAAC;IAEd;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,SAAS,EAAE,IAAI,CAAC;IAEhB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,WAAW,aAAa;IAC5B;;;;;;;;;OASG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACvC"}
package/dist/user.d.ts ADDED
@@ -0,0 +1,189 @@
1
+ /**
2
+ * User-related type definitions
3
+ *
4
+ * These enums and types are exported from smrt-types to allow
5
+ * browser-safe packages (like smrt-svelte) to import them without
6
+ * pulling in server-side dependencies from smrt-users.
7
+ */
8
+ /**
9
+ * Lifecycle status of a user account.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * if (user.status === UserStatus.SUSPENDED) {
14
+ * throw new ForbiddenError('Account is suspended');
15
+ * }
16
+ * ```
17
+ *
18
+ * @see {@link MembershipStatus} for a user's status within a specific tenant
19
+ * @see {@link SessionStatus} for the status of an active session
20
+ */
21
+ export declare enum UserStatus {
22
+ /** Active user account */
23
+ ACTIVE = "active",
24
+ /** Inactive user account */
25
+ INACTIVE = "inactive",
26
+ /** Suspended user account */
27
+ SUSPENDED = "suspended",
28
+ /** Pending email verification */
29
+ PENDING = "pending"
30
+ }
31
+ /**
32
+ * Lifecycle status of a tenant (organization) within the platform.
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * if (tenant.status === TenantStatus.ARCHIVED) {
37
+ * return; // skip soft-deleted tenants
38
+ * }
39
+ * ```
40
+ *
41
+ * @see {@link MembershipStatus} for a user's membership status within a tenant
42
+ * @see {@link TenantPermissionEffect} for permission inheritance across tenant hierarchies
43
+ */
44
+ export declare enum TenantStatus {
45
+ /** Active tenant */
46
+ ACTIVE = "active",
47
+ /** Inactive tenant */
48
+ INACTIVE = "inactive",
49
+ /** Suspended tenant */
50
+ SUSPENDED = "suspended",
51
+ /** Archived tenant (soft-deleted) */
52
+ ARCHIVED = "archived"
53
+ }
54
+ /**
55
+ * Status of a user's membership within a specific tenant.
56
+ *
57
+ * A user may hold memberships in multiple tenants simultaneously, each with an
58
+ * independent `MembershipStatus`.
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * const active = memberships.filter(m => m.status === MembershipStatus.ACTIVE);
63
+ * ```
64
+ *
65
+ * @see {@link UserStatus} for the global account-level status
66
+ * @see {@link TenantStatus} for the status of the tenant itself
67
+ */
68
+ export declare enum MembershipStatus {
69
+ /** Active membership */
70
+ ACTIVE = "active",
71
+ /** Inactive membership */
72
+ INACTIVE = "inactive",
73
+ /** Pending invitation acceptance */
74
+ PENDING = "pending"
75
+ }
76
+ /**
77
+ * Lifecycle status of an {@link AccessRequest} — the "request access / join the
78
+ * waitlist" identity primitive that captures a prospective user from a public
79
+ * form before they become a real `User`.
80
+ *
81
+ * Operators triage `REQUESTED` records, then either decline them or approve and
82
+ * **graduate** them into a `User` (optionally attached to a tenant).
83
+ *
84
+ * State machine:
85
+ * ```
86
+ * REQUESTED ──approve──> APPROVED ──graduate──> GRADUATED
87
+ * │ │
88
+ * ├──decline──> DECLINED ┘ (decline also valid from APPROVED)
89
+ * └──cancel───> CANCELED
90
+ * ```
91
+ *
92
+ * @example
93
+ * ```typescript
94
+ * if (request.status === AccessRequestStatus.APPROVED) {
95
+ * await service.graduateAccessRequest(request.id, { by: operatorId });
96
+ * }
97
+ * ```
98
+ *
99
+ * @see {@link UserStatus} for the account-level status set when a request graduates
100
+ */
101
+ export declare enum AccessRequestStatus {
102
+ /** Open request awaiting operator triage (the default on creation) */
103
+ REQUESTED = "requested",
104
+ /** Operator approved the request; ready to graduate into a User */
105
+ APPROVED = "approved",
106
+ /** Operator declined the request */
107
+ DECLINED = "declined",
108
+ /** Request was graduated into a real User (terminal) */
109
+ GRADUATED = "graduated",
110
+ /** Request was canceled before a decision (terminal) */
111
+ CANCELED = "canceled"
112
+ }
113
+ /**
114
+ * Status of an authenticated session.
115
+ *
116
+ * Sessions transition from `ACTIVE` to either `EXPIRED` (time-based) or
117
+ * `REVOKED` (explicit action by the user or an administrator).
118
+ *
119
+ * @example
120
+ * ```typescript
121
+ * if (session.status !== SessionStatus.ACTIVE) {
122
+ * redirect(302, '/login');
123
+ * }
124
+ * ```
125
+ *
126
+ * @see {@link UserStatus} for the account-level status checked before session creation
127
+ */
128
+ export declare enum SessionStatus {
129
+ /** Active session */
130
+ ACTIVE = "active",
131
+ /** Expired session (past expiresAt) */
132
+ EXPIRED = "expired",
133
+ /** Revoked by user or admin */
134
+ REVOKED = "revoked"
135
+ }
136
+ /**
137
+ * Effect applied by a user-level permission override.
138
+ *
139
+ * Overrides target a specific user + permission combination and always win
140
+ * over role-based grants. `DENY` overrides are checked before `GRANT` in
141
+ * the 4-level permission cascade.
142
+ *
143
+ * @example
144
+ * ```typescript
145
+ * await override.create({
146
+ * userId,
147
+ * permission: 'billing.view',
148
+ * effect: OverrideEffect.DENY,
149
+ * });
150
+ * ```
151
+ *
152
+ * @see {@link TenantPermissionEffect} for the tenant-level equivalent that supports inheritance
153
+ */
154
+ export declare enum OverrideEffect {
155
+ /** Grant the permission */
156
+ GRANT = "grant",
157
+ /** Deny the permission */
158
+ DENY = "deny"
159
+ }
160
+ /**
161
+ * Effect of a tenant-level permission setting in a hierarchical tenant tree.
162
+ *
163
+ * Unlike `OverrideEffect`, tenant-level effects support `INHERIT` — the default
164
+ * behaviour where a child tenant walks up to its parent to resolve the permission.
165
+ * `DENY` blocks inheritance, preventing child tenants from acquiring the permission
166
+ * even if a grandparent grants it.
167
+ *
168
+ * @example
169
+ * ```typescript
170
+ * // Sub-tenant explicitly blocks billing access regardless of parent settings
171
+ * await tenantPermission.create({
172
+ * tenantId: subTenantId,
173
+ * permission: 'billing.manage',
174
+ * effect: TenantPermissionEffect.DENY,
175
+ * });
176
+ * ```
177
+ *
178
+ * @see {@link OverrideEffect} for user-level overrides (no inheritance step)
179
+ * @see {@link TenantStatus} for the tenant lifecycle status
180
+ */
181
+ export declare enum TenantPermissionEffect {
182
+ /** Inherit from parent tenant (default behavior) */
183
+ INHERIT = "inherit",
184
+ /** Explicitly grant at this tenant level */
185
+ GRANT = "grant",
186
+ /** Explicitly deny at this tenant level (blocks inheritance) */
187
+ DENY = "deny"
188
+ }
189
+ //# sourceMappingURL=user.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../src/user.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH;;;;;;;;;;;;GAYG;AACH,oBAAY,UAAU;IACpB,0BAA0B;IAC1B,MAAM,WAAW;IACjB,4BAA4B;IAC5B,QAAQ,aAAa;IACrB,6BAA6B;IAC7B,SAAS,cAAc;IACvB,iCAAiC;IACjC,OAAO,YAAY;CACpB;AAID;;;;;;;;;;;;GAYG;AACH,oBAAY,YAAY;IACtB,oBAAoB;IACpB,MAAM,WAAW;IACjB,sBAAsB;IACtB,QAAQ,aAAa;IACrB,uBAAuB;IACvB,SAAS,cAAc;IACvB,qCAAqC;IACrC,QAAQ,aAAa;CACtB;AAID;;;;;;;;;;;;;GAaG;AACH,oBAAY,gBAAgB;IAC1B,wBAAwB;IACxB,MAAM,WAAW;IACjB,0BAA0B;IAC1B,QAAQ,aAAa;IACrB,oCAAoC;IACpC,OAAO,YAAY;CACpB;AAID;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,oBAAY,mBAAmB;IAC7B,sEAAsE;IACtE,SAAS,cAAc;IACvB,mEAAmE;IACnE,QAAQ,aAAa;IACrB,oCAAoC;IACpC,QAAQ,aAAa;IACrB,wDAAwD;IACxD,SAAS,cAAc;IACvB,wDAAwD;IACxD,QAAQ,aAAa;CACtB;AAID;;;;;;;;;;;;;;GAcG;AACH,oBAAY,aAAa;IACvB,qBAAqB;IACrB,MAAM,WAAW;IACjB,uCAAuC;IACvC,OAAO,YAAY;IACnB,+BAA+B;IAC/B,OAAO,YAAY;CACpB;AAID;;;;;;;;;;;;;;;;;GAiBG;AACH,oBAAY,cAAc;IACxB,2BAA2B;IAC3B,KAAK,UAAU;IACf,0BAA0B;IAC1B,IAAI,SAAS;CACd;AAID;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,oBAAY,sBAAsB;IAChC,oDAAoD;IACpD,OAAO,YAAY;IACnB,4CAA4C;IAC5C,KAAK,UAAU;IACf,gEAAgE;IAChE,IAAI,SAAS;CACd"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@happyvertical/smrt-types",
3
- "version": "0.51.31",
3
+ "version": "0.51.33",
4
4
  "description": "Shared type definitions for the HAVE SDK",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -13,7 +13,7 @@
13
13
  },
14
14
  "devDependencies": {
15
15
  "@types/node": "24.13.6",
16
- "typescript": "5.9.3",
16
+ "typescript": "6.0.3",
17
17
  "vite": "8.1.4",
18
18
  "vitest": "4.1.10"
19
19
  },