@uniforge/platform-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 +184 -0
- package/dist/auth/index.d.ts +184 -0
- package/dist/auth/index.js +62 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/index.mjs +33 -0
- package/dist/auth/index.mjs.map +1 -0
- package/dist/billing/index.d.cts +213 -0
- package/dist/billing/index.d.ts +213 -0
- package/dist/billing/index.js +43 -0
- package/dist/billing/index.js.map +1 -0
- package/dist/billing/index.mjs +16 -0
- package/dist/billing/index.mjs.map +1 -0
- package/dist/graphql/index.d.cts +100 -0
- package/dist/graphql/index.d.ts +100 -0
- package/dist/graphql/index.js +19 -0
- package/dist/graphql/index.js.map +1 -0
- package/dist/graphql/index.mjs +1 -0
- package/dist/graphql/index.mjs.map +1 -0
- package/dist/index.d.cts +19 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +6 -0
- package/dist/index.mjs.map +1 -0
- package/dist/multi-store/index.d.cts +242 -0
- package/dist/multi-store/index.d.ts +242 -0
- package/dist/multi-store/index.js +53 -0
- package/dist/multi-store/index.js.map +1 -0
- package/dist/multi-store/index.mjs +23 -0
- package/dist/multi-store/index.mjs.map +1 -0
- package/dist/multi-tenant/index.d.cts +64 -0
- package/dist/multi-tenant/index.d.ts +64 -0
- package/dist/multi-tenant/index.js +19 -0
- package/dist/multi-tenant/index.js.map +1 -0
- package/dist/multi-tenant/index.mjs +1 -0
- package/dist/multi-tenant/index.mjs.map +1 -0
- package/dist/performance/index.d.cts +118 -0
- package/dist/performance/index.d.ts +118 -0
- package/dist/performance/index.js +19 -0
- package/dist/performance/index.js.map +1 -0
- package/dist/performance/index.mjs +1 -0
- package/dist/performance/index.mjs.map +1 -0
- package/dist/platform/index.d.cts +156 -0
- package/dist/platform/index.d.ts +156 -0
- package/dist/platform/index.js +64 -0
- package/dist/platform/index.js.map +1 -0
- package/dist/platform/index.mjs +37 -0
- package/dist/platform/index.mjs.map +1 -0
- package/dist/rbac/index.d.cts +140 -0
- package/dist/rbac/index.d.ts +140 -0
- package/dist/rbac/index.js +55 -0
- package/dist/rbac/index.js.map +1 -0
- package/dist/rbac/index.mjs +27 -0
- package/dist/rbac/index.mjs.map +1 -0
- package/dist/registry-efvajmOd.d.cts +118 -0
- package/dist/registry-efvajmOd.d.ts +118 -0
- package/dist/security/index.d.cts +148 -0
- package/dist/security/index.d.ts +148 -0
- package/dist/security/index.js +40 -0
- package/dist/security/index.js.map +1 -0
- package/dist/security/index.mjs +13 -0
- package/dist/security/index.mjs.map +1 -0
- package/dist/types-CgnJiK8Z.d.cts +74 -0
- package/dist/types-CgnJiK8Z.d.ts +74 -0
- package/dist/webhooks/index.d.cts +114 -0
- package/dist/webhooks/index.d.ts +114 -0
- package/dist/webhooks/index.js +19 -0
- package/dist/webhooks/index.js.map +1 -0
- package/dist/webhooks/index.mjs +1 -0
- package/dist/webhooks/index.mjs.map +1 -0
- package/package.json +94 -0
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { S as Session, a as ShopContext } from '../types-CgnJiK8Z.cjs';
|
|
2
|
+
export { A as AssociatedUser, O as OnlineAccessInfo, b as SessionData, c as Shop } from '../types-CgnJiK8Z.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Pluggable session storage interface.
|
|
6
|
+
*
|
|
7
|
+
* Consumers implement this interface for their persistence backend
|
|
8
|
+
* (e.g., Prisma/PostgreSQL, Redis, in-memory). The framework wraps
|
|
9
|
+
* this with an encrypting decorator so storage adapters never see
|
|
10
|
+
* plaintext tokens.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** Pluggable session storage backend. */
|
|
14
|
+
interface SessionStorage {
|
|
15
|
+
/** Persist a session. Returns true on success. */
|
|
16
|
+
storeSession(session: Session): Promise<boolean>;
|
|
17
|
+
/** Load a session by ID. Returns undefined if not found. */
|
|
18
|
+
loadSession(id: string): Promise<Session | undefined>;
|
|
19
|
+
/** Delete a session by ID. Returns true on success. */
|
|
20
|
+
deleteSession(id: string): Promise<boolean>;
|
|
21
|
+
/** Delete multiple sessions by ID. Returns true on success. */
|
|
22
|
+
deleteSessions(ids: string[]): Promise<boolean>;
|
|
23
|
+
/** Find all sessions for a given shop domain. */
|
|
24
|
+
findSessionsByShop(shop: string): Promise<Session[]>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Framework-agnostic authentication middleware interfaces.
|
|
29
|
+
*
|
|
30
|
+
* These are implemented in @uniforge/core and adapted to specific
|
|
31
|
+
* HTTP frameworks via platform adapters.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/** Normalized HTTP request for auth middleware. */
|
|
35
|
+
interface AuthRequest {
|
|
36
|
+
method: string;
|
|
37
|
+
url: string;
|
|
38
|
+
headers: Record<string, string | string[] | undefined>;
|
|
39
|
+
query: Record<string, string>;
|
|
40
|
+
rawBody?: Buffer;
|
|
41
|
+
}
|
|
42
|
+
/** Discriminated union of auth middleware outcomes. */
|
|
43
|
+
type AuthResult = AuthResultSuccess | AuthResultRedirect | AuthResultError;
|
|
44
|
+
/** Successful authentication result with session and shop context. */
|
|
45
|
+
interface AuthResultSuccess {
|
|
46
|
+
authenticated: true;
|
|
47
|
+
session: Session;
|
|
48
|
+
shopContext: ShopContext;
|
|
49
|
+
}
|
|
50
|
+
/** Auth result requiring a redirect (e.g., to OAuth). */
|
|
51
|
+
interface AuthResultRedirect {
|
|
52
|
+
authenticated: false;
|
|
53
|
+
redirectUrl: string;
|
|
54
|
+
statusCode: 302 | 307;
|
|
55
|
+
}
|
|
56
|
+
/** Auth result representing an authentication failure. */
|
|
57
|
+
interface AuthResultError {
|
|
58
|
+
authenticated: false;
|
|
59
|
+
error: AuthError;
|
|
60
|
+
}
|
|
61
|
+
/** Structured authentication error with code and HTTP status. */
|
|
62
|
+
interface AuthError {
|
|
63
|
+
code: AuthErrorCode;
|
|
64
|
+
message: string;
|
|
65
|
+
statusCode: number;
|
|
66
|
+
}
|
|
67
|
+
/** All possible authentication error codes. */
|
|
68
|
+
type AuthErrorCode = 'SESSION_NOT_FOUND' | 'SESSION_EXPIRED' | 'TOKEN_EXCHANGE_FAILED' | 'TOKEN_REFRESH_FAILED' | 'HMAC_VALIDATION_FAILED' | 'INVALID_SHOP' | 'SCOPE_MISMATCH' | 'SHOPIFY_UNAVAILABLE' | 'ENCRYPTION_ERROR' | 'UNKNOWN_ERROR';
|
|
69
|
+
/** Framework-agnostic authentication middleware. */
|
|
70
|
+
interface AuthMiddleware {
|
|
71
|
+
authenticate(request: AuthRequest): Promise<AuthResult>;
|
|
72
|
+
}
|
|
73
|
+
/** Configuration for public and protected route patterns. */
|
|
74
|
+
interface RouteProtectionConfig {
|
|
75
|
+
protectedRoutes?: string[];
|
|
76
|
+
publicRoutes?: string[];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Token encryption interfaces.
|
|
81
|
+
*
|
|
82
|
+
* Defines AES-256-GCM encryption types for access tokens at rest
|
|
83
|
+
* with key rotation support via key registry pattern.
|
|
84
|
+
*/
|
|
85
|
+
/** Encryption configuration with key registry. */
|
|
86
|
+
interface EncryptionConfig {
|
|
87
|
+
keys: EncryptionKey[];
|
|
88
|
+
}
|
|
89
|
+
/** An encryption key with its identifier and creation date. */
|
|
90
|
+
interface EncryptionKey {
|
|
91
|
+
id: string;
|
|
92
|
+
key: Buffer | string;
|
|
93
|
+
createdAt: Date;
|
|
94
|
+
}
|
|
95
|
+
/** AES-256-GCM encrypted payload with metadata. */
|
|
96
|
+
interface EncryptedPayload {
|
|
97
|
+
ciphertext: string;
|
|
98
|
+
iv: string;
|
|
99
|
+
authTag: string;
|
|
100
|
+
keyId: string;
|
|
101
|
+
}
|
|
102
|
+
/** Service for encrypting and decrypting access tokens. */
|
|
103
|
+
interface TokenEncryptionService {
|
|
104
|
+
/** Encrypt a plaintext string using the active key. */
|
|
105
|
+
encrypt(plaintext: string): EncryptedPayload;
|
|
106
|
+
/** Decrypt an encrypted payload back to plaintext. */
|
|
107
|
+
decrypt(payload: EncryptedPayload): string;
|
|
108
|
+
/** Check if a payload was encrypted with the current active key. */
|
|
109
|
+
isEncryptedWithActiveKey(payload: EncryptedPayload): boolean;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Authentication event types and handler interface.
|
|
114
|
+
*
|
|
115
|
+
* Defines structured event types for audit logging of all
|
|
116
|
+
* authentication-related actions across the framework.
|
|
117
|
+
*/
|
|
118
|
+
/** All possible authentication event types for audit logging. */
|
|
119
|
+
type AuthEventType = 'token_exchange_success' | 'token_exchange_failure' | 'oauth_begin' | 'oauth_callback_success' | 'oauth_callback_failure' | 'session_created' | 'session_expired' | 'session_deleted' | 'token_refreshed' | 'token_refresh_failed' | 'hmac_validation_failed' | 'middleware_authorized' | 'middleware_unauthorized';
|
|
120
|
+
/** Structured authentication event for audit logging. */
|
|
121
|
+
interface AuthEvent {
|
|
122
|
+
id: string;
|
|
123
|
+
type: AuthEventType;
|
|
124
|
+
shopDomain: string;
|
|
125
|
+
sessionId: string | null;
|
|
126
|
+
userId: number | null;
|
|
127
|
+
outcome: 'success' | 'failure';
|
|
128
|
+
metadata: Record<string, string>;
|
|
129
|
+
timestamp: Date;
|
|
130
|
+
}
|
|
131
|
+
/** Handler for processing authentication events. */
|
|
132
|
+
interface AuthEventHandler {
|
|
133
|
+
onAuthEvent(event: AuthEvent): Promise<void> | void;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Core authentication configuration types.
|
|
138
|
+
*
|
|
139
|
+
* These interfaces define the configuration surface for UniForge's
|
|
140
|
+
* authentication system.
|
|
141
|
+
*/
|
|
142
|
+
|
|
143
|
+
/** Core authentication configuration. */
|
|
144
|
+
interface AuthConfig {
|
|
145
|
+
apiKey: string;
|
|
146
|
+
apiSecretKey: string;
|
|
147
|
+
scopes: string[];
|
|
148
|
+
hostName: string;
|
|
149
|
+
apiVersion: string;
|
|
150
|
+
isEmbeddedApp?: boolean;
|
|
151
|
+
sessionStorage: SessionStorage;
|
|
152
|
+
encryption: EncryptionConfig;
|
|
153
|
+
eventHandler?: AuthEventHandler;
|
|
154
|
+
session?: SessionConfig;
|
|
155
|
+
tokenRefresh?: TokenRefreshConfig;
|
|
156
|
+
}
|
|
157
|
+
/** Session behavior configuration. */
|
|
158
|
+
interface SessionConfig {
|
|
159
|
+
expirationTimeoutSeconds?: number;
|
|
160
|
+
useExpiringOfflineTokens?: boolean;
|
|
161
|
+
}
|
|
162
|
+
/** Token refresh retry configuration. */
|
|
163
|
+
interface TokenRefreshConfig {
|
|
164
|
+
maxRetries?: number;
|
|
165
|
+
refreshBufferSeconds?: number;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Session ID and shop domain validation helpers.
|
|
170
|
+
*/
|
|
171
|
+
/** Result of parsing a session ID string. */
|
|
172
|
+
interface ParsedSessionId {
|
|
173
|
+
type: 'offline' | 'online';
|
|
174
|
+
shop: string;
|
|
175
|
+
userId: number | null;
|
|
176
|
+
}
|
|
177
|
+
/** Validate that a string is a valid Shopify myshopify.com domain. */
|
|
178
|
+
declare function isValidShopDomain(domain: string): boolean;
|
|
179
|
+
/** Validate that a string is a valid session ID format. */
|
|
180
|
+
declare function isValidSessionId(id: string): boolean;
|
|
181
|
+
/** Parse a session ID string into its components (type, shop, userId). */
|
|
182
|
+
declare function parseSessionId(id: string): ParsedSessionId | null;
|
|
183
|
+
|
|
184
|
+
export { type AuthConfig, type AuthError, type AuthErrorCode, type AuthEvent, type AuthEventHandler, type AuthEventType, type AuthMiddleware, type AuthRequest, type AuthResult, type AuthResultError, type AuthResultRedirect, type AuthResultSuccess, type EncryptedPayload, type EncryptionConfig, type EncryptionKey, type ParsedSessionId, type RouteProtectionConfig, Session, type SessionConfig, type SessionStorage, ShopContext, type TokenEncryptionService, type TokenRefreshConfig, isValidSessionId, isValidShopDomain, parseSessionId };
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { S as Session, a as ShopContext } from '../types-CgnJiK8Z.js';
|
|
2
|
+
export { A as AssociatedUser, O as OnlineAccessInfo, b as SessionData, c as Shop } from '../types-CgnJiK8Z.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Pluggable session storage interface.
|
|
6
|
+
*
|
|
7
|
+
* Consumers implement this interface for their persistence backend
|
|
8
|
+
* (e.g., Prisma/PostgreSQL, Redis, in-memory). The framework wraps
|
|
9
|
+
* this with an encrypting decorator so storage adapters never see
|
|
10
|
+
* plaintext tokens.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** Pluggable session storage backend. */
|
|
14
|
+
interface SessionStorage {
|
|
15
|
+
/** Persist a session. Returns true on success. */
|
|
16
|
+
storeSession(session: Session): Promise<boolean>;
|
|
17
|
+
/** Load a session by ID. Returns undefined if not found. */
|
|
18
|
+
loadSession(id: string): Promise<Session | undefined>;
|
|
19
|
+
/** Delete a session by ID. Returns true on success. */
|
|
20
|
+
deleteSession(id: string): Promise<boolean>;
|
|
21
|
+
/** Delete multiple sessions by ID. Returns true on success. */
|
|
22
|
+
deleteSessions(ids: string[]): Promise<boolean>;
|
|
23
|
+
/** Find all sessions for a given shop domain. */
|
|
24
|
+
findSessionsByShop(shop: string): Promise<Session[]>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Framework-agnostic authentication middleware interfaces.
|
|
29
|
+
*
|
|
30
|
+
* These are implemented in @uniforge/core and adapted to specific
|
|
31
|
+
* HTTP frameworks via platform adapters.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/** Normalized HTTP request for auth middleware. */
|
|
35
|
+
interface AuthRequest {
|
|
36
|
+
method: string;
|
|
37
|
+
url: string;
|
|
38
|
+
headers: Record<string, string | string[] | undefined>;
|
|
39
|
+
query: Record<string, string>;
|
|
40
|
+
rawBody?: Buffer;
|
|
41
|
+
}
|
|
42
|
+
/** Discriminated union of auth middleware outcomes. */
|
|
43
|
+
type AuthResult = AuthResultSuccess | AuthResultRedirect | AuthResultError;
|
|
44
|
+
/** Successful authentication result with session and shop context. */
|
|
45
|
+
interface AuthResultSuccess {
|
|
46
|
+
authenticated: true;
|
|
47
|
+
session: Session;
|
|
48
|
+
shopContext: ShopContext;
|
|
49
|
+
}
|
|
50
|
+
/** Auth result requiring a redirect (e.g., to OAuth). */
|
|
51
|
+
interface AuthResultRedirect {
|
|
52
|
+
authenticated: false;
|
|
53
|
+
redirectUrl: string;
|
|
54
|
+
statusCode: 302 | 307;
|
|
55
|
+
}
|
|
56
|
+
/** Auth result representing an authentication failure. */
|
|
57
|
+
interface AuthResultError {
|
|
58
|
+
authenticated: false;
|
|
59
|
+
error: AuthError;
|
|
60
|
+
}
|
|
61
|
+
/** Structured authentication error with code and HTTP status. */
|
|
62
|
+
interface AuthError {
|
|
63
|
+
code: AuthErrorCode;
|
|
64
|
+
message: string;
|
|
65
|
+
statusCode: number;
|
|
66
|
+
}
|
|
67
|
+
/** All possible authentication error codes. */
|
|
68
|
+
type AuthErrorCode = 'SESSION_NOT_FOUND' | 'SESSION_EXPIRED' | 'TOKEN_EXCHANGE_FAILED' | 'TOKEN_REFRESH_FAILED' | 'HMAC_VALIDATION_FAILED' | 'INVALID_SHOP' | 'SCOPE_MISMATCH' | 'SHOPIFY_UNAVAILABLE' | 'ENCRYPTION_ERROR' | 'UNKNOWN_ERROR';
|
|
69
|
+
/** Framework-agnostic authentication middleware. */
|
|
70
|
+
interface AuthMiddleware {
|
|
71
|
+
authenticate(request: AuthRequest): Promise<AuthResult>;
|
|
72
|
+
}
|
|
73
|
+
/** Configuration for public and protected route patterns. */
|
|
74
|
+
interface RouteProtectionConfig {
|
|
75
|
+
protectedRoutes?: string[];
|
|
76
|
+
publicRoutes?: string[];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Token encryption interfaces.
|
|
81
|
+
*
|
|
82
|
+
* Defines AES-256-GCM encryption types for access tokens at rest
|
|
83
|
+
* with key rotation support via key registry pattern.
|
|
84
|
+
*/
|
|
85
|
+
/** Encryption configuration with key registry. */
|
|
86
|
+
interface EncryptionConfig {
|
|
87
|
+
keys: EncryptionKey[];
|
|
88
|
+
}
|
|
89
|
+
/** An encryption key with its identifier and creation date. */
|
|
90
|
+
interface EncryptionKey {
|
|
91
|
+
id: string;
|
|
92
|
+
key: Buffer | string;
|
|
93
|
+
createdAt: Date;
|
|
94
|
+
}
|
|
95
|
+
/** AES-256-GCM encrypted payload with metadata. */
|
|
96
|
+
interface EncryptedPayload {
|
|
97
|
+
ciphertext: string;
|
|
98
|
+
iv: string;
|
|
99
|
+
authTag: string;
|
|
100
|
+
keyId: string;
|
|
101
|
+
}
|
|
102
|
+
/** Service for encrypting and decrypting access tokens. */
|
|
103
|
+
interface TokenEncryptionService {
|
|
104
|
+
/** Encrypt a plaintext string using the active key. */
|
|
105
|
+
encrypt(plaintext: string): EncryptedPayload;
|
|
106
|
+
/** Decrypt an encrypted payload back to plaintext. */
|
|
107
|
+
decrypt(payload: EncryptedPayload): string;
|
|
108
|
+
/** Check if a payload was encrypted with the current active key. */
|
|
109
|
+
isEncryptedWithActiveKey(payload: EncryptedPayload): boolean;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Authentication event types and handler interface.
|
|
114
|
+
*
|
|
115
|
+
* Defines structured event types for audit logging of all
|
|
116
|
+
* authentication-related actions across the framework.
|
|
117
|
+
*/
|
|
118
|
+
/** All possible authentication event types for audit logging. */
|
|
119
|
+
type AuthEventType = 'token_exchange_success' | 'token_exchange_failure' | 'oauth_begin' | 'oauth_callback_success' | 'oauth_callback_failure' | 'session_created' | 'session_expired' | 'session_deleted' | 'token_refreshed' | 'token_refresh_failed' | 'hmac_validation_failed' | 'middleware_authorized' | 'middleware_unauthorized';
|
|
120
|
+
/** Structured authentication event for audit logging. */
|
|
121
|
+
interface AuthEvent {
|
|
122
|
+
id: string;
|
|
123
|
+
type: AuthEventType;
|
|
124
|
+
shopDomain: string;
|
|
125
|
+
sessionId: string | null;
|
|
126
|
+
userId: number | null;
|
|
127
|
+
outcome: 'success' | 'failure';
|
|
128
|
+
metadata: Record<string, string>;
|
|
129
|
+
timestamp: Date;
|
|
130
|
+
}
|
|
131
|
+
/** Handler for processing authentication events. */
|
|
132
|
+
interface AuthEventHandler {
|
|
133
|
+
onAuthEvent(event: AuthEvent): Promise<void> | void;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Core authentication configuration types.
|
|
138
|
+
*
|
|
139
|
+
* These interfaces define the configuration surface for UniForge's
|
|
140
|
+
* authentication system.
|
|
141
|
+
*/
|
|
142
|
+
|
|
143
|
+
/** Core authentication configuration. */
|
|
144
|
+
interface AuthConfig {
|
|
145
|
+
apiKey: string;
|
|
146
|
+
apiSecretKey: string;
|
|
147
|
+
scopes: string[];
|
|
148
|
+
hostName: string;
|
|
149
|
+
apiVersion: string;
|
|
150
|
+
isEmbeddedApp?: boolean;
|
|
151
|
+
sessionStorage: SessionStorage;
|
|
152
|
+
encryption: EncryptionConfig;
|
|
153
|
+
eventHandler?: AuthEventHandler;
|
|
154
|
+
session?: SessionConfig;
|
|
155
|
+
tokenRefresh?: TokenRefreshConfig;
|
|
156
|
+
}
|
|
157
|
+
/** Session behavior configuration. */
|
|
158
|
+
interface SessionConfig {
|
|
159
|
+
expirationTimeoutSeconds?: number;
|
|
160
|
+
useExpiringOfflineTokens?: boolean;
|
|
161
|
+
}
|
|
162
|
+
/** Token refresh retry configuration. */
|
|
163
|
+
interface TokenRefreshConfig {
|
|
164
|
+
maxRetries?: number;
|
|
165
|
+
refreshBufferSeconds?: number;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Session ID and shop domain validation helpers.
|
|
170
|
+
*/
|
|
171
|
+
/** Result of parsing a session ID string. */
|
|
172
|
+
interface ParsedSessionId {
|
|
173
|
+
type: 'offline' | 'online';
|
|
174
|
+
shop: string;
|
|
175
|
+
userId: number | null;
|
|
176
|
+
}
|
|
177
|
+
/** Validate that a string is a valid Shopify myshopify.com domain. */
|
|
178
|
+
declare function isValidShopDomain(domain: string): boolean;
|
|
179
|
+
/** Validate that a string is a valid session ID format. */
|
|
180
|
+
declare function isValidSessionId(id: string): boolean;
|
|
181
|
+
/** Parse a session ID string into its components (type, shop, userId). */
|
|
182
|
+
declare function parseSessionId(id: string): ParsedSessionId | null;
|
|
183
|
+
|
|
184
|
+
export { type AuthConfig, type AuthError, type AuthErrorCode, type AuthEvent, type AuthEventHandler, type AuthEventType, type AuthMiddleware, type AuthRequest, type AuthResult, type AuthResultError, type AuthResultRedirect, type AuthResultSuccess, type EncryptedPayload, type EncryptionConfig, type EncryptionKey, type ParsedSessionId, type RouteProtectionConfig, Session, type SessionConfig, type SessionStorage, ShopContext, type TokenEncryptionService, type TokenRefreshConfig, isValidSessionId, isValidShopDomain, parseSessionId };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/auth/index.ts
|
|
21
|
+
var auth_exports = {};
|
|
22
|
+
__export(auth_exports, {
|
|
23
|
+
isValidSessionId: () => isValidSessionId,
|
|
24
|
+
isValidShopDomain: () => isValidShopDomain,
|
|
25
|
+
parseSessionId: () => parseSessionId
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(auth_exports);
|
|
28
|
+
|
|
29
|
+
// src/auth/validators.ts
|
|
30
|
+
var SHOP_DOMAIN_REGEX = /^[a-zA-Z0-9][a-zA-Z0-9-]*\.myshopify\.com$/;
|
|
31
|
+
function isValidShopDomain(domain) {
|
|
32
|
+
return SHOP_DOMAIN_REGEX.test(domain);
|
|
33
|
+
}
|
|
34
|
+
function isValidSessionId(id) {
|
|
35
|
+
return parseSessionId(id) !== null;
|
|
36
|
+
}
|
|
37
|
+
function parseSessionId(id) {
|
|
38
|
+
if (!id) return null;
|
|
39
|
+
if (id.startsWith("offline_")) {
|
|
40
|
+
const shop = id.slice("offline_".length);
|
|
41
|
+
if (!isValidShopDomain(shop)) return null;
|
|
42
|
+
return { type: "offline", shop, userId: null };
|
|
43
|
+
}
|
|
44
|
+
if (id.startsWith("online_")) {
|
|
45
|
+
const rest = id.slice("online_".length);
|
|
46
|
+
const lastUnderscore = rest.lastIndexOf("_");
|
|
47
|
+
if (lastUnderscore === -1) return null;
|
|
48
|
+
const shop = rest.slice(0, lastUnderscore);
|
|
49
|
+
const userIdStr = rest.slice(lastUnderscore + 1);
|
|
50
|
+
if (!isValidShopDomain(shop)) return null;
|
|
51
|
+
if (!/^\d+$/.test(userIdStr)) return null;
|
|
52
|
+
return { type: "online", shop, userId: parseInt(userIdStr, 10) };
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
57
|
+
0 && (module.exports = {
|
|
58
|
+
isValidSessionId,
|
|
59
|
+
isValidShopDomain,
|
|
60
|
+
parseSessionId
|
|
61
|
+
});
|
|
62
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/auth/index.ts","../../src/auth/validators.ts"],"sourcesContent":["/**\n * @uniforge/platform-core - Authentication\n *\n * Platform-agnostic authentication interfaces and types.\n */\n\n// Types\nexport type {\n Session,\n SessionData,\n OnlineAccessInfo,\n AssociatedUser,\n Shop,\n ShopContext,\n} from './types';\n\n// Session Storage\nexport type { SessionStorage } from './session-storage';\n\n// Middleware\nexport type {\n AuthRequest,\n AuthResult,\n AuthResultSuccess,\n AuthResultRedirect,\n AuthResultError,\n AuthError,\n AuthErrorCode,\n AuthMiddleware,\n RouteProtectionConfig,\n} from './middleware';\n\n// Encryption\nexport type {\n EncryptionConfig,\n EncryptionKey,\n EncryptedPayload,\n TokenEncryptionService,\n} from './encryption';\n\n// Events\nexport type {\n AuthEventType,\n AuthEvent,\n AuthEventHandler,\n} from './events';\n\n// Configuration\nexport type {\n AuthConfig,\n SessionConfig,\n TokenRefreshConfig,\n} from './config';\n\n// Validators\nexport {\n isValidSessionId,\n isValidShopDomain,\n parseSessionId,\n} from './validators';\nexport type { ParsedSessionId } from './validators';\n","/**\n * Session ID and shop domain validation helpers.\n */\n\nconst SHOP_DOMAIN_REGEX = /^[a-zA-Z0-9][a-zA-Z0-9-]*\\.myshopify\\.com$/;\n\n/** Result of parsing a session ID string. */\nexport interface ParsedSessionId {\n type: 'offline' | 'online';\n shop: string;\n userId: number | null;\n}\n\n/** Validate that a string is a valid Shopify myshopify.com domain. */\nexport function isValidShopDomain(domain: string): boolean {\n return SHOP_DOMAIN_REGEX.test(domain);\n}\n\n/** Validate that a string is a valid session ID format. */\nexport function isValidSessionId(id: string): boolean {\n return parseSessionId(id) !== null;\n}\n\n/** Parse a session ID string into its components (type, shop, userId). */\nexport function parseSessionId(id: string): ParsedSessionId | null {\n if (!id) return null;\n\n if (id.startsWith('offline_')) {\n const shop = id.slice('offline_'.length);\n if (!isValidShopDomain(shop)) return null;\n return { type: 'offline', shop, userId: null };\n }\n\n if (id.startsWith('online_')) {\n const rest = id.slice('online_'.length);\n const lastUnderscore = rest.lastIndexOf('_');\n if (lastUnderscore === -1) return null;\n\n const shop = rest.slice(0, lastUnderscore);\n const userIdStr = rest.slice(lastUnderscore + 1);\n\n if (!isValidShopDomain(shop)) return null;\n if (!/^\\d+$/.test(userIdStr)) return null;\n\n return { type: 'online', shop, userId: parseInt(userIdStr, 10) };\n }\n\n return null;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACIA,IAAM,oBAAoB;AAUnB,SAAS,kBAAkB,QAAyB;AACzD,SAAO,kBAAkB,KAAK,MAAM;AACtC;AAGO,SAAS,iBAAiB,IAAqB;AACpD,SAAO,eAAe,EAAE,MAAM;AAChC;AAGO,SAAS,eAAe,IAAoC;AACjE,MAAI,CAAC,GAAI,QAAO;AAEhB,MAAI,GAAG,WAAW,UAAU,GAAG;AAC7B,UAAM,OAAO,GAAG,MAAM,WAAW,MAAM;AACvC,QAAI,CAAC,kBAAkB,IAAI,EAAG,QAAO;AACrC,WAAO,EAAE,MAAM,WAAW,MAAM,QAAQ,KAAK;AAAA,EAC/C;AAEA,MAAI,GAAG,WAAW,SAAS,GAAG;AAC5B,UAAM,OAAO,GAAG,MAAM,UAAU,MAAM;AACtC,UAAM,iBAAiB,KAAK,YAAY,GAAG;AAC3C,QAAI,mBAAmB,GAAI,QAAO;AAElC,UAAM,OAAO,KAAK,MAAM,GAAG,cAAc;AACzC,UAAM,YAAY,KAAK,MAAM,iBAAiB,CAAC;AAE/C,QAAI,CAAC,kBAAkB,IAAI,EAAG,QAAO;AACrC,QAAI,CAAC,QAAQ,KAAK,SAAS,EAAG,QAAO;AAErC,WAAO,EAAE,MAAM,UAAU,MAAM,QAAQ,SAAS,WAAW,EAAE,EAAE;AAAA,EACjE;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// src/auth/validators.ts
|
|
2
|
+
var SHOP_DOMAIN_REGEX = /^[a-zA-Z0-9][a-zA-Z0-9-]*\.myshopify\.com$/;
|
|
3
|
+
function isValidShopDomain(domain) {
|
|
4
|
+
return SHOP_DOMAIN_REGEX.test(domain);
|
|
5
|
+
}
|
|
6
|
+
function isValidSessionId(id) {
|
|
7
|
+
return parseSessionId(id) !== null;
|
|
8
|
+
}
|
|
9
|
+
function parseSessionId(id) {
|
|
10
|
+
if (!id) return null;
|
|
11
|
+
if (id.startsWith("offline_")) {
|
|
12
|
+
const shop = id.slice("offline_".length);
|
|
13
|
+
if (!isValidShopDomain(shop)) return null;
|
|
14
|
+
return { type: "offline", shop, userId: null };
|
|
15
|
+
}
|
|
16
|
+
if (id.startsWith("online_")) {
|
|
17
|
+
const rest = id.slice("online_".length);
|
|
18
|
+
const lastUnderscore = rest.lastIndexOf("_");
|
|
19
|
+
if (lastUnderscore === -1) return null;
|
|
20
|
+
const shop = rest.slice(0, lastUnderscore);
|
|
21
|
+
const userIdStr = rest.slice(lastUnderscore + 1);
|
|
22
|
+
if (!isValidShopDomain(shop)) return null;
|
|
23
|
+
if (!/^\d+$/.test(userIdStr)) return null;
|
|
24
|
+
return { type: "online", shop, userId: parseInt(userIdStr, 10) };
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
isValidSessionId,
|
|
30
|
+
isValidShopDomain,
|
|
31
|
+
parseSessionId
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/auth/validators.ts"],"sourcesContent":["/**\n * Session ID and shop domain validation helpers.\n */\n\nconst SHOP_DOMAIN_REGEX = /^[a-zA-Z0-9][a-zA-Z0-9-]*\\.myshopify\\.com$/;\n\n/** Result of parsing a session ID string. */\nexport interface ParsedSessionId {\n type: 'offline' | 'online';\n shop: string;\n userId: number | null;\n}\n\n/** Validate that a string is a valid Shopify myshopify.com domain. */\nexport function isValidShopDomain(domain: string): boolean {\n return SHOP_DOMAIN_REGEX.test(domain);\n}\n\n/** Validate that a string is a valid session ID format. */\nexport function isValidSessionId(id: string): boolean {\n return parseSessionId(id) !== null;\n}\n\n/** Parse a session ID string into its components (type, shop, userId). */\nexport function parseSessionId(id: string): ParsedSessionId | null {\n if (!id) return null;\n\n if (id.startsWith('offline_')) {\n const shop = id.slice('offline_'.length);\n if (!isValidShopDomain(shop)) return null;\n return { type: 'offline', shop, userId: null };\n }\n\n if (id.startsWith('online_')) {\n const rest = id.slice('online_'.length);\n const lastUnderscore = rest.lastIndexOf('_');\n if (lastUnderscore === -1) return null;\n\n const shop = rest.slice(0, lastUnderscore);\n const userIdStr = rest.slice(lastUnderscore + 1);\n\n if (!isValidShopDomain(shop)) return null;\n if (!/^\\d+$/.test(userIdStr)) return null;\n\n return { type: 'online', shop, userId: parseInt(userIdStr, 10) };\n }\n\n return null;\n}\n"],"mappings":";AAIA,IAAM,oBAAoB;AAUnB,SAAS,kBAAkB,QAAyB;AACzD,SAAO,kBAAkB,KAAK,MAAM;AACtC;AAGO,SAAS,iBAAiB,IAAqB;AACpD,SAAO,eAAe,EAAE,MAAM;AAChC;AAGO,SAAS,eAAe,IAAoC;AACjE,MAAI,CAAC,GAAI,QAAO;AAEhB,MAAI,GAAG,WAAW,UAAU,GAAG;AAC7B,UAAM,OAAO,GAAG,MAAM,WAAW,MAAM;AACvC,QAAI,CAAC,kBAAkB,IAAI,EAAG,QAAO;AACrC,WAAO,EAAE,MAAM,WAAW,MAAM,QAAQ,KAAK;AAAA,EAC/C;AAEA,MAAI,GAAG,WAAW,SAAS,GAAG;AAC5B,UAAM,OAAO,GAAG,MAAM,UAAU,MAAM;AACtC,UAAM,iBAAiB,KAAK,YAAY,GAAG;AAC3C,QAAI,mBAAmB,GAAI,QAAO;AAElC,UAAM,OAAO,KAAK,MAAM,GAAG,cAAc;AACzC,UAAM,YAAY,KAAK,MAAM,iBAAiB,CAAC;AAE/C,QAAI,CAAC,kBAAkB,IAAI,EAAG,QAAO;AACrC,QAAI,CAAC,QAAQ,KAAK,SAAS,EAAG,QAAO;AAErC,WAAO,EAAE,MAAM,UAAU,MAAM,QAAQ,SAAS,WAAW,EAAE,EAAE;AAAA,EACjE;AAEA,SAAO;AACT;","names":[]}
|