@uniforge/core 0.1.0-alpha.2
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/dist/auth/index.d.cts +165 -0
- package/dist/auth/index.d.ts +165 -0
- package/dist/auth/index.js +443 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/index.mjs +406 -0
- package/dist/auth/index.mjs.map +1 -0
- package/dist/billing/index.d.cts +34 -0
- package/dist/billing/index.d.ts +34 -0
- package/dist/billing/index.js +254 -0
- package/dist/billing/index.js.map +1 -0
- package/dist/billing/index.mjs +225 -0
- package/dist/billing/index.mjs.map +1 -0
- package/dist/config/index.d.cts +12 -0
- package/dist/config/index.d.ts +12 -0
- package/dist/config/index.js +186 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/index.mjs +156 -0
- package/dist/config/index.mjs.map +1 -0
- package/dist/database/index.d.cts +33 -0
- package/dist/database/index.d.ts +33 -0
- package/dist/database/index.js +127 -0
- package/dist/database/index.js.map +1 -0
- package/dist/database/index.mjs +95 -0
- package/dist/database/index.mjs.map +1 -0
- package/dist/graphql/index.d.cts +36 -0
- package/dist/graphql/index.d.ts +36 -0
- package/dist/graphql/index.js +209 -0
- package/dist/graphql/index.js.map +1 -0
- package/dist/graphql/index.mjs +179 -0
- package/dist/graphql/index.mjs.map +1 -0
- package/dist/index.d.cts +16 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +10 -0
- package/dist/index.mjs.map +1 -0
- package/dist/multi-store/index.d.cts +11 -0
- package/dist/multi-store/index.d.ts +11 -0
- package/dist/multi-store/index.js +473 -0
- package/dist/multi-store/index.js.map +1 -0
- package/dist/multi-store/index.mjs +447 -0
- package/dist/multi-store/index.mjs.map +1 -0
- package/dist/multi-tenant/index.d.cts +23 -0
- package/dist/multi-tenant/index.d.ts +23 -0
- package/dist/multi-tenant/index.js +69 -0
- package/dist/multi-tenant/index.js.map +1 -0
- package/dist/multi-tenant/index.mjs +41 -0
- package/dist/multi-tenant/index.mjs.map +1 -0
- package/dist/performance/index.d.cts +34 -0
- package/dist/performance/index.d.ts +34 -0
- package/dist/performance/index.js +319 -0
- package/dist/performance/index.js.map +1 -0
- package/dist/performance/index.mjs +290 -0
- package/dist/performance/index.mjs.map +1 -0
- package/dist/platform/index.d.cts +25 -0
- package/dist/platform/index.d.ts +25 -0
- package/dist/platform/index.js +91 -0
- package/dist/platform/index.js.map +1 -0
- package/dist/platform/index.mjs +62 -0
- package/dist/platform/index.mjs.map +1 -0
- package/dist/rbac/index.d.cts +24 -0
- package/dist/rbac/index.d.ts +24 -0
- package/dist/rbac/index.js +267 -0
- package/dist/rbac/index.js.map +1 -0
- package/dist/rbac/index.mjs +236 -0
- package/dist/rbac/index.mjs.map +1 -0
- package/dist/schema-CM7mHj_H.d.cts +53 -0
- package/dist/schema-CM7mHj_H.d.ts +53 -0
- package/dist/security/index.d.cts +47 -0
- package/dist/security/index.d.ts +47 -0
- package/dist/security/index.js +505 -0
- package/dist/security/index.js.map +1 -0
- package/dist/security/index.mjs +474 -0
- package/dist/security/index.mjs.map +1 -0
- package/dist/session-storage/index.d.cts +70 -0
- package/dist/session-storage/index.d.ts +70 -0
- package/dist/session-storage/index.js +271 -0
- package/dist/session-storage/index.js.map +1 -0
- package/dist/session-storage/index.mjs +242 -0
- package/dist/session-storage/index.mjs.map +1 -0
- package/dist/webhooks/index.d.cts +89 -0
- package/dist/webhooks/index.d.ts +89 -0
- package/dist/webhooks/index.js +380 -0
- package/dist/webhooks/index.js.map +1 -0
- package/dist/webhooks/index.mjs +348 -0
- package/dist/webhooks/index.mjs.map +1 -0
- package/package.json +119 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { AuthEventType, AuthEvent, AuthConfig, TokenEncryptionService, EncryptionConfig, EncryptedPayload, SessionStorage, Session, SessionConfig, TokenRefreshConfig, RouteProtectionConfig, AuthMiddleware } from '@uniforge/platform-core/auth';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Auth event factory.
|
|
5
|
+
*
|
|
6
|
+
* Creates structured authentication events with automatic UUID generation,
|
|
7
|
+
* timestamp setting, and sensitive metadata key rejection.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** Input parameters for creating an auth event. */
|
|
11
|
+
interface CreateAuthEventInput {
|
|
12
|
+
type: AuthEventType;
|
|
13
|
+
shopDomain: string;
|
|
14
|
+
outcome: 'success' | 'failure';
|
|
15
|
+
sessionId?: string | null;
|
|
16
|
+
userId?: number | null;
|
|
17
|
+
metadata?: Record<string, string>;
|
|
18
|
+
}
|
|
19
|
+
/** Create a structured auth event with auto-generated ID and timestamp. Rejects sensitive metadata keys. */
|
|
20
|
+
declare function createAuthEvent(input: CreateAuthEventInput): AuthEvent;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Auth config factory with validation and defaults.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/** Input parameters for creating a validated auth configuration. */
|
|
27
|
+
interface CreateAuthConfigInput {
|
|
28
|
+
apiKey: string;
|
|
29
|
+
apiSecretKey: string;
|
|
30
|
+
scopes: string[];
|
|
31
|
+
hostName: string;
|
|
32
|
+
apiVersion: string;
|
|
33
|
+
isEmbeddedApp?: boolean;
|
|
34
|
+
sessionStorage: AuthConfig['sessionStorage'];
|
|
35
|
+
encryption: AuthConfig['encryption'];
|
|
36
|
+
eventHandler?: AuthConfig['eventHandler'];
|
|
37
|
+
session?: AuthConfig['session'];
|
|
38
|
+
tokenRefresh?: AuthConfig['tokenRefresh'];
|
|
39
|
+
}
|
|
40
|
+
/** Create a validated AuthConfig with sensible defaults. Throws on invalid input. */
|
|
41
|
+
declare function createAuthConfig(input: CreateAuthConfigInput): AuthConfig;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* AES-256-GCM token encryption with key rotation.
|
|
45
|
+
*
|
|
46
|
+
* Implements TokenEncryptionService using Node.js built-in crypto.
|
|
47
|
+
* Each encrypt call generates a unique 12-byte random IV.
|
|
48
|
+
* Key rotation is supported via a key registry — decrypt looks up
|
|
49
|
+
* the key by keyId, while encrypt always uses the active (first) key.
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
declare class TokenEncryptionServiceImpl implements TokenEncryptionService {
|
|
53
|
+
private readonly keys;
|
|
54
|
+
private readonly activeKeyId;
|
|
55
|
+
constructor(config: EncryptionConfig);
|
|
56
|
+
/** Encrypt plaintext using the active (first) key. Generates a unique IV per call. */
|
|
57
|
+
encrypt(plaintext: string): EncryptedPayload;
|
|
58
|
+
/** Decrypt an encrypted payload. Looks up the key by keyId from the registry. */
|
|
59
|
+
decrypt(payload: EncryptedPayload): string;
|
|
60
|
+
/** Check if a payload was encrypted with the currently active key. */
|
|
61
|
+
isEncryptedWithActiveKey(payload: EncryptedPayload): boolean;
|
|
62
|
+
private toBuffer;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Encrypting session storage decorator.
|
|
67
|
+
*
|
|
68
|
+
* Wraps any SessionStorage implementation, transparently encrypting
|
|
69
|
+
* accessToken and refreshToken on store, and decrypting on load/find.
|
|
70
|
+
* Delete operations pass through unchanged.
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
declare class EncryptedSessionStorage implements SessionStorage {
|
|
74
|
+
private readonly inner;
|
|
75
|
+
private readonly encryption;
|
|
76
|
+
constructor(inner: SessionStorage, encryption: TokenEncryptionService);
|
|
77
|
+
/** Store a session with encrypted tokens. */
|
|
78
|
+
storeSession(session: Session): Promise<boolean>;
|
|
79
|
+
/** Load a session and decrypt its tokens. */
|
|
80
|
+
loadSession(id: string): Promise<Session | undefined>;
|
|
81
|
+
/** Delete a session by ID (pass-through). */
|
|
82
|
+
deleteSession(id: string): Promise<boolean>;
|
|
83
|
+
/** Delete multiple sessions by ID (pass-through). */
|
|
84
|
+
deleteSessions(ids: string[]): Promise<boolean>;
|
|
85
|
+
/** Find sessions by shop and decrypt their tokens. */
|
|
86
|
+
findSessionsByShop(shop: string): Promise<Session[]>;
|
|
87
|
+
private encryptTokens;
|
|
88
|
+
private decryptTokens;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Session expiration and token refresh utilities.
|
|
93
|
+
*
|
|
94
|
+
* Platform-agnostic helpers for determining session validity
|
|
95
|
+
* and whether tokens should be proactively refreshed.
|
|
96
|
+
*/
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Check if a session has expired.
|
|
100
|
+
*
|
|
101
|
+
* Returns true if the session's `expires` date is in the past (or now).
|
|
102
|
+
* Non-expiring sessions (null expires) are never considered expired.
|
|
103
|
+
*/
|
|
104
|
+
declare function isSessionExpired(session: Session, _config?: SessionConfig): boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Check if a session's token should be proactively refreshed.
|
|
107
|
+
*
|
|
108
|
+
* Returns true if the session will expire within the refresh buffer window.
|
|
109
|
+
* Non-expiring sessions (null expires) never need refresh.
|
|
110
|
+
*/
|
|
111
|
+
declare function shouldRefreshToken(session: Session, config?: TokenRefreshConfig): boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Calculate a session expiration date based on config.
|
|
114
|
+
*
|
|
115
|
+
* Returns a Date that is `expirationTimeoutSeconds` from now.
|
|
116
|
+
*/
|
|
117
|
+
declare function getSessionExpirationDate(config?: SessionConfig): Date;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Route matcher utility for auth middleware.
|
|
121
|
+
*
|
|
122
|
+
* Determines whether a given URL path is public (no auth required)
|
|
123
|
+
* or protected (auth required) based on glob pattern configuration.
|
|
124
|
+
*/
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Check if a URL path is a public route that does not require authentication.
|
|
128
|
+
*
|
|
129
|
+
* Public routes take precedence over protected routes.
|
|
130
|
+
* Auth callback paths (/auth/callback, /auth/STAR/callback) are always public.
|
|
131
|
+
*/
|
|
132
|
+
declare function isPublicRoute(url: string, config: RouteProtectionConfig): boolean;
|
|
133
|
+
/**
|
|
134
|
+
* Normalize a URL path by stripping query parameters and trailing slashes.
|
|
135
|
+
*/
|
|
136
|
+
declare function normalizePath(url: string): string;
|
|
137
|
+
/**
|
|
138
|
+
* Simple glob pattern matcher supporting:
|
|
139
|
+
* - Exact matches: `/health` matches `/health`
|
|
140
|
+
* - Single segment wildcard `*`: `/admin/*` matches `/admin/foo` but not `/admin/foo/bar`
|
|
141
|
+
* - Multi-segment wildcard `**`: `/api/**` matches `/api/foo`, `/api/foo/bar`, etc.
|
|
142
|
+
*/
|
|
143
|
+
declare function matchGlob(path: string, pattern: string): boolean;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Authentication middleware factory.
|
|
147
|
+
*
|
|
148
|
+
* Creates a framework-agnostic auth middleware that:
|
|
149
|
+
* - Checks if the route is public (skip auth)
|
|
150
|
+
* - Extracts shop domain from the request
|
|
151
|
+
* - Loads and validates the session from storage
|
|
152
|
+
* - Constructs ShopContext on success
|
|
153
|
+
* - Returns redirect or error on failure
|
|
154
|
+
* - Emits middleware auth events
|
|
155
|
+
*/
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Create an auth middleware instance.
|
|
159
|
+
*
|
|
160
|
+
* @param config - The auth configuration
|
|
161
|
+
* @param routeConfig - Optional route protection configuration. If not provided, all routes are protected.
|
|
162
|
+
*/
|
|
163
|
+
declare function createAuthMiddleware(config: AuthConfig, routeConfig?: RouteProtectionConfig): AuthMiddleware;
|
|
164
|
+
|
|
165
|
+
export { type CreateAuthConfigInput, type CreateAuthEventInput, EncryptedSessionStorage, TokenEncryptionServiceImpl, createAuthConfig, createAuthEvent, createAuthMiddleware, getSessionExpirationDate, isPublicRoute, isSessionExpired, matchGlob, normalizePath, shouldRefreshToken };
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { AuthEventType, AuthEvent, AuthConfig, TokenEncryptionService, EncryptionConfig, EncryptedPayload, SessionStorage, Session, SessionConfig, TokenRefreshConfig, RouteProtectionConfig, AuthMiddleware } from '@uniforge/platform-core/auth';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Auth event factory.
|
|
5
|
+
*
|
|
6
|
+
* Creates structured authentication events with automatic UUID generation,
|
|
7
|
+
* timestamp setting, and sensitive metadata key rejection.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** Input parameters for creating an auth event. */
|
|
11
|
+
interface CreateAuthEventInput {
|
|
12
|
+
type: AuthEventType;
|
|
13
|
+
shopDomain: string;
|
|
14
|
+
outcome: 'success' | 'failure';
|
|
15
|
+
sessionId?: string | null;
|
|
16
|
+
userId?: number | null;
|
|
17
|
+
metadata?: Record<string, string>;
|
|
18
|
+
}
|
|
19
|
+
/** Create a structured auth event with auto-generated ID and timestamp. Rejects sensitive metadata keys. */
|
|
20
|
+
declare function createAuthEvent(input: CreateAuthEventInput): AuthEvent;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Auth config factory with validation and defaults.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/** Input parameters for creating a validated auth configuration. */
|
|
27
|
+
interface CreateAuthConfigInput {
|
|
28
|
+
apiKey: string;
|
|
29
|
+
apiSecretKey: string;
|
|
30
|
+
scopes: string[];
|
|
31
|
+
hostName: string;
|
|
32
|
+
apiVersion: string;
|
|
33
|
+
isEmbeddedApp?: boolean;
|
|
34
|
+
sessionStorage: AuthConfig['sessionStorage'];
|
|
35
|
+
encryption: AuthConfig['encryption'];
|
|
36
|
+
eventHandler?: AuthConfig['eventHandler'];
|
|
37
|
+
session?: AuthConfig['session'];
|
|
38
|
+
tokenRefresh?: AuthConfig['tokenRefresh'];
|
|
39
|
+
}
|
|
40
|
+
/** Create a validated AuthConfig with sensible defaults. Throws on invalid input. */
|
|
41
|
+
declare function createAuthConfig(input: CreateAuthConfigInput): AuthConfig;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* AES-256-GCM token encryption with key rotation.
|
|
45
|
+
*
|
|
46
|
+
* Implements TokenEncryptionService using Node.js built-in crypto.
|
|
47
|
+
* Each encrypt call generates a unique 12-byte random IV.
|
|
48
|
+
* Key rotation is supported via a key registry — decrypt looks up
|
|
49
|
+
* the key by keyId, while encrypt always uses the active (first) key.
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
declare class TokenEncryptionServiceImpl implements TokenEncryptionService {
|
|
53
|
+
private readonly keys;
|
|
54
|
+
private readonly activeKeyId;
|
|
55
|
+
constructor(config: EncryptionConfig);
|
|
56
|
+
/** Encrypt plaintext using the active (first) key. Generates a unique IV per call. */
|
|
57
|
+
encrypt(plaintext: string): EncryptedPayload;
|
|
58
|
+
/** Decrypt an encrypted payload. Looks up the key by keyId from the registry. */
|
|
59
|
+
decrypt(payload: EncryptedPayload): string;
|
|
60
|
+
/** Check if a payload was encrypted with the currently active key. */
|
|
61
|
+
isEncryptedWithActiveKey(payload: EncryptedPayload): boolean;
|
|
62
|
+
private toBuffer;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Encrypting session storage decorator.
|
|
67
|
+
*
|
|
68
|
+
* Wraps any SessionStorage implementation, transparently encrypting
|
|
69
|
+
* accessToken and refreshToken on store, and decrypting on load/find.
|
|
70
|
+
* Delete operations pass through unchanged.
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
declare class EncryptedSessionStorage implements SessionStorage {
|
|
74
|
+
private readonly inner;
|
|
75
|
+
private readonly encryption;
|
|
76
|
+
constructor(inner: SessionStorage, encryption: TokenEncryptionService);
|
|
77
|
+
/** Store a session with encrypted tokens. */
|
|
78
|
+
storeSession(session: Session): Promise<boolean>;
|
|
79
|
+
/** Load a session and decrypt its tokens. */
|
|
80
|
+
loadSession(id: string): Promise<Session | undefined>;
|
|
81
|
+
/** Delete a session by ID (pass-through). */
|
|
82
|
+
deleteSession(id: string): Promise<boolean>;
|
|
83
|
+
/** Delete multiple sessions by ID (pass-through). */
|
|
84
|
+
deleteSessions(ids: string[]): Promise<boolean>;
|
|
85
|
+
/** Find sessions by shop and decrypt their tokens. */
|
|
86
|
+
findSessionsByShop(shop: string): Promise<Session[]>;
|
|
87
|
+
private encryptTokens;
|
|
88
|
+
private decryptTokens;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Session expiration and token refresh utilities.
|
|
93
|
+
*
|
|
94
|
+
* Platform-agnostic helpers for determining session validity
|
|
95
|
+
* and whether tokens should be proactively refreshed.
|
|
96
|
+
*/
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Check if a session has expired.
|
|
100
|
+
*
|
|
101
|
+
* Returns true if the session's `expires` date is in the past (or now).
|
|
102
|
+
* Non-expiring sessions (null expires) are never considered expired.
|
|
103
|
+
*/
|
|
104
|
+
declare function isSessionExpired(session: Session, _config?: SessionConfig): boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Check if a session's token should be proactively refreshed.
|
|
107
|
+
*
|
|
108
|
+
* Returns true if the session will expire within the refresh buffer window.
|
|
109
|
+
* Non-expiring sessions (null expires) never need refresh.
|
|
110
|
+
*/
|
|
111
|
+
declare function shouldRefreshToken(session: Session, config?: TokenRefreshConfig): boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Calculate a session expiration date based on config.
|
|
114
|
+
*
|
|
115
|
+
* Returns a Date that is `expirationTimeoutSeconds` from now.
|
|
116
|
+
*/
|
|
117
|
+
declare function getSessionExpirationDate(config?: SessionConfig): Date;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Route matcher utility for auth middleware.
|
|
121
|
+
*
|
|
122
|
+
* Determines whether a given URL path is public (no auth required)
|
|
123
|
+
* or protected (auth required) based on glob pattern configuration.
|
|
124
|
+
*/
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Check if a URL path is a public route that does not require authentication.
|
|
128
|
+
*
|
|
129
|
+
* Public routes take precedence over protected routes.
|
|
130
|
+
* Auth callback paths (/auth/callback, /auth/STAR/callback) are always public.
|
|
131
|
+
*/
|
|
132
|
+
declare function isPublicRoute(url: string, config: RouteProtectionConfig): boolean;
|
|
133
|
+
/**
|
|
134
|
+
* Normalize a URL path by stripping query parameters and trailing slashes.
|
|
135
|
+
*/
|
|
136
|
+
declare function normalizePath(url: string): string;
|
|
137
|
+
/**
|
|
138
|
+
* Simple glob pattern matcher supporting:
|
|
139
|
+
* - Exact matches: `/health` matches `/health`
|
|
140
|
+
* - Single segment wildcard `*`: `/admin/*` matches `/admin/foo` but not `/admin/foo/bar`
|
|
141
|
+
* - Multi-segment wildcard `**`: `/api/**` matches `/api/foo`, `/api/foo/bar`, etc.
|
|
142
|
+
*/
|
|
143
|
+
declare function matchGlob(path: string, pattern: string): boolean;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Authentication middleware factory.
|
|
147
|
+
*
|
|
148
|
+
* Creates a framework-agnostic auth middleware that:
|
|
149
|
+
* - Checks if the route is public (skip auth)
|
|
150
|
+
* - Extracts shop domain from the request
|
|
151
|
+
* - Loads and validates the session from storage
|
|
152
|
+
* - Constructs ShopContext on success
|
|
153
|
+
* - Returns redirect or error on failure
|
|
154
|
+
* - Emits middleware auth events
|
|
155
|
+
*/
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Create an auth middleware instance.
|
|
159
|
+
*
|
|
160
|
+
* @param config - The auth configuration
|
|
161
|
+
* @param routeConfig - Optional route protection configuration. If not provided, all routes are protected.
|
|
162
|
+
*/
|
|
163
|
+
declare function createAuthMiddleware(config: AuthConfig, routeConfig?: RouteProtectionConfig): AuthMiddleware;
|
|
164
|
+
|
|
165
|
+
export { type CreateAuthConfigInput, type CreateAuthEventInput, EncryptedSessionStorage, TokenEncryptionServiceImpl, createAuthConfig, createAuthEvent, createAuthMiddleware, getSessionExpirationDate, isPublicRoute, isSessionExpired, matchGlob, normalizePath, shouldRefreshToken };
|