@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.
Files changed (71) hide show
  1. package/dist/auth/index.d.cts +184 -0
  2. package/dist/auth/index.d.ts +184 -0
  3. package/dist/auth/index.js +62 -0
  4. package/dist/auth/index.js.map +1 -0
  5. package/dist/auth/index.mjs +33 -0
  6. package/dist/auth/index.mjs.map +1 -0
  7. package/dist/billing/index.d.cts +213 -0
  8. package/dist/billing/index.d.ts +213 -0
  9. package/dist/billing/index.js +43 -0
  10. package/dist/billing/index.js.map +1 -0
  11. package/dist/billing/index.mjs +16 -0
  12. package/dist/billing/index.mjs.map +1 -0
  13. package/dist/graphql/index.d.cts +100 -0
  14. package/dist/graphql/index.d.ts +100 -0
  15. package/dist/graphql/index.js +19 -0
  16. package/dist/graphql/index.js.map +1 -0
  17. package/dist/graphql/index.mjs +1 -0
  18. package/dist/graphql/index.mjs.map +1 -0
  19. package/dist/index.d.cts +19 -0
  20. package/dist/index.d.ts +19 -0
  21. package/dist/index.js +31 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/index.mjs +6 -0
  24. package/dist/index.mjs.map +1 -0
  25. package/dist/multi-store/index.d.cts +242 -0
  26. package/dist/multi-store/index.d.ts +242 -0
  27. package/dist/multi-store/index.js +53 -0
  28. package/dist/multi-store/index.js.map +1 -0
  29. package/dist/multi-store/index.mjs +23 -0
  30. package/dist/multi-store/index.mjs.map +1 -0
  31. package/dist/multi-tenant/index.d.cts +64 -0
  32. package/dist/multi-tenant/index.d.ts +64 -0
  33. package/dist/multi-tenant/index.js +19 -0
  34. package/dist/multi-tenant/index.js.map +1 -0
  35. package/dist/multi-tenant/index.mjs +1 -0
  36. package/dist/multi-tenant/index.mjs.map +1 -0
  37. package/dist/performance/index.d.cts +118 -0
  38. package/dist/performance/index.d.ts +118 -0
  39. package/dist/performance/index.js +19 -0
  40. package/dist/performance/index.js.map +1 -0
  41. package/dist/performance/index.mjs +1 -0
  42. package/dist/performance/index.mjs.map +1 -0
  43. package/dist/platform/index.d.cts +156 -0
  44. package/dist/platform/index.d.ts +156 -0
  45. package/dist/platform/index.js +64 -0
  46. package/dist/platform/index.js.map +1 -0
  47. package/dist/platform/index.mjs +37 -0
  48. package/dist/platform/index.mjs.map +1 -0
  49. package/dist/rbac/index.d.cts +140 -0
  50. package/dist/rbac/index.d.ts +140 -0
  51. package/dist/rbac/index.js +55 -0
  52. package/dist/rbac/index.js.map +1 -0
  53. package/dist/rbac/index.mjs +27 -0
  54. package/dist/rbac/index.mjs.map +1 -0
  55. package/dist/registry-efvajmOd.d.cts +118 -0
  56. package/dist/registry-efvajmOd.d.ts +118 -0
  57. package/dist/security/index.d.cts +148 -0
  58. package/dist/security/index.d.ts +148 -0
  59. package/dist/security/index.js +40 -0
  60. package/dist/security/index.js.map +1 -0
  61. package/dist/security/index.mjs +13 -0
  62. package/dist/security/index.mjs.map +1 -0
  63. package/dist/types-CgnJiK8Z.d.cts +74 -0
  64. package/dist/types-CgnJiK8Z.d.ts +74 -0
  65. package/dist/webhooks/index.d.cts +114 -0
  66. package/dist/webhooks/index.d.ts +114 -0
  67. package/dist/webhooks/index.js +19 -0
  68. package/dist/webhooks/index.js.map +1 -0
  69. package/dist/webhooks/index.mjs +1 -0
  70. package/dist/webhooks/index.mjs.map +1 -0
  71. package/package.json +94 -0
@@ -0,0 +1,148 @@
1
+ /**
2
+ * Security types and configuration interfaces.
3
+ */
4
+ interface SanitizeOptions {
5
+ stripHtml: boolean;
6
+ maxLength?: number;
7
+ allowedPattern?: RegExp;
8
+ }
9
+ interface InputValidationRule {
10
+ field: string;
11
+ type: 'shopDomain' | 'email' | 'url' | 'apiKey' | 'string' | 'custom';
12
+ required?: boolean;
13
+ maxLength?: number;
14
+ pattern?: RegExp;
15
+ message?: string;
16
+ }
17
+ interface InputValidationError {
18
+ field: string;
19
+ message: string;
20
+ code: string;
21
+ }
22
+ interface InputValidationResult {
23
+ valid: boolean;
24
+ errors: InputValidationError[];
25
+ sanitized: Record<string, string>;
26
+ }
27
+ interface RateLimitConfig {
28
+ windowMs: number;
29
+ maxRequests: number;
30
+ keyPrefix?: string;
31
+ }
32
+ interface RateLimitResult {
33
+ allowed: boolean;
34
+ remaining: number;
35
+ resetAt: number;
36
+ retryAfter?: number;
37
+ }
38
+ interface SecurityHeadersConfig {
39
+ hsts: boolean;
40
+ hstsMaxAge?: number;
41
+ hstsIncludeSubDomains?: boolean;
42
+ noSniff: boolean;
43
+ frameOptions: 'DENY' | 'SAMEORIGIN';
44
+ xssProtection: boolean;
45
+ referrerPolicy: string;
46
+ }
47
+ interface CSPDirectives {
48
+ defaultSrc: string[];
49
+ scriptSrc: string[];
50
+ styleSrc: string[];
51
+ imgSrc: string[];
52
+ connectSrc: string[];
53
+ fontSrc: string[];
54
+ frameSrc: string[];
55
+ frameAncestors: string[];
56
+ }
57
+ type SecurityFindingSeverity = 'critical' | 'high' | 'medium' | 'low' | 'info';
58
+ interface SecurityAuditFinding {
59
+ id: string;
60
+ severity: SecurityFindingSeverity;
61
+ category: string;
62
+ title: string;
63
+ description: string;
64
+ recommendation: string;
65
+ }
66
+ interface SecurityAuditResult {
67
+ passed: boolean;
68
+ score: number;
69
+ findings: SecurityAuditFinding[];
70
+ timestamp: string;
71
+ }
72
+
73
+ /**
74
+ * Input validation interface.
75
+ */
76
+
77
+ interface InputValidator {
78
+ /** Validate input against a set of rules */
79
+ validate(input: Record<string, unknown>, rules: InputValidationRule[]): InputValidationResult;
80
+ /** Sanitize a string value */
81
+ sanitize(value: string, options?: SanitizeOptions): string;
82
+ /** Validate a shop domain format */
83
+ isValidShopDomain(domain: string): boolean;
84
+ /** Validate an email format */
85
+ isValidEmail(email: string): boolean;
86
+ /** Validate a URL format */
87
+ isValidUrl(url: string): boolean;
88
+ /** Validate an API key format */
89
+ isValidApiKey(key: string): boolean;
90
+ }
91
+
92
+ /**
93
+ * Security middleware interfaces.
94
+ */
95
+
96
+ /** HTTP request/response abstraction for middleware */
97
+ interface SecurityRequest {
98
+ ip?: string;
99
+ headers: Record<string, string | string[] | undefined>;
100
+ path: string;
101
+ method: string;
102
+ }
103
+ interface SecurityResponse {
104
+ setHeader(name: string, value: string): void;
105
+ }
106
+ /** Applies security headers to HTTP responses */
107
+ interface SecurityHeadersMiddleware {
108
+ readonly config: SecurityHeadersConfig;
109
+ applyHeaders(res: SecurityResponse): void;
110
+ }
111
+ /** Applies Content Security Policy headers */
112
+ interface CSPMiddleware {
113
+ readonly directives: CSPDirectives;
114
+ applyCSP(res: SecurityResponse): void;
115
+ toHeaderString(): string;
116
+ }
117
+ /** Rate limiter for HTTP requests */
118
+ interface RequestRateLimiter {
119
+ readonly config: RateLimitConfig;
120
+ /** Check if a request is allowed. Key is typically IP or shop domain. */
121
+ check(key: string): Promise<RateLimitResult>;
122
+ /** Reset rate limit for a key */
123
+ reset(key: string): Promise<void>;
124
+ }
125
+
126
+ /**
127
+ * Security audit interface.
128
+ */
129
+
130
+ interface SecurityAuditConfig {
131
+ checkEncryption: boolean;
132
+ checkHeaders: boolean;
133
+ checkRateLimiting: boolean;
134
+ checkInputValidation: boolean;
135
+ checkWebhookSecurity: boolean;
136
+ checkSessionSecurity: boolean;
137
+ }
138
+ interface SecurityAuditor {
139
+ /** Run a full security audit */
140
+ audit(config: SecurityAuditConfig): SecurityAuditResult;
141
+ /** Check if encryption is properly configured */
142
+ checkEncryption(config: Record<string, unknown>): SecurityAuditResult;
143
+ /** Check if security headers are configured */
144
+ checkHeaders(headers: Record<string, string>): SecurityAuditResult;
145
+ }
146
+ declare const DEFAULT_AUDIT_CONFIG: SecurityAuditConfig;
147
+
148
+ export { type CSPDirectives, type CSPMiddleware, DEFAULT_AUDIT_CONFIG, type InputValidationError, type InputValidationResult, type InputValidationRule, type InputValidator, type RateLimitConfig, type RateLimitResult, type RequestRateLimiter, type SanitizeOptions, type SecurityAuditConfig, type SecurityAuditFinding, type SecurityAuditResult, type SecurityAuditor, type SecurityFindingSeverity, type SecurityHeadersConfig, type SecurityHeadersMiddleware, type SecurityRequest, type SecurityResponse };
@@ -0,0 +1,148 @@
1
+ /**
2
+ * Security types and configuration interfaces.
3
+ */
4
+ interface SanitizeOptions {
5
+ stripHtml: boolean;
6
+ maxLength?: number;
7
+ allowedPattern?: RegExp;
8
+ }
9
+ interface InputValidationRule {
10
+ field: string;
11
+ type: 'shopDomain' | 'email' | 'url' | 'apiKey' | 'string' | 'custom';
12
+ required?: boolean;
13
+ maxLength?: number;
14
+ pattern?: RegExp;
15
+ message?: string;
16
+ }
17
+ interface InputValidationError {
18
+ field: string;
19
+ message: string;
20
+ code: string;
21
+ }
22
+ interface InputValidationResult {
23
+ valid: boolean;
24
+ errors: InputValidationError[];
25
+ sanitized: Record<string, string>;
26
+ }
27
+ interface RateLimitConfig {
28
+ windowMs: number;
29
+ maxRequests: number;
30
+ keyPrefix?: string;
31
+ }
32
+ interface RateLimitResult {
33
+ allowed: boolean;
34
+ remaining: number;
35
+ resetAt: number;
36
+ retryAfter?: number;
37
+ }
38
+ interface SecurityHeadersConfig {
39
+ hsts: boolean;
40
+ hstsMaxAge?: number;
41
+ hstsIncludeSubDomains?: boolean;
42
+ noSniff: boolean;
43
+ frameOptions: 'DENY' | 'SAMEORIGIN';
44
+ xssProtection: boolean;
45
+ referrerPolicy: string;
46
+ }
47
+ interface CSPDirectives {
48
+ defaultSrc: string[];
49
+ scriptSrc: string[];
50
+ styleSrc: string[];
51
+ imgSrc: string[];
52
+ connectSrc: string[];
53
+ fontSrc: string[];
54
+ frameSrc: string[];
55
+ frameAncestors: string[];
56
+ }
57
+ type SecurityFindingSeverity = 'critical' | 'high' | 'medium' | 'low' | 'info';
58
+ interface SecurityAuditFinding {
59
+ id: string;
60
+ severity: SecurityFindingSeverity;
61
+ category: string;
62
+ title: string;
63
+ description: string;
64
+ recommendation: string;
65
+ }
66
+ interface SecurityAuditResult {
67
+ passed: boolean;
68
+ score: number;
69
+ findings: SecurityAuditFinding[];
70
+ timestamp: string;
71
+ }
72
+
73
+ /**
74
+ * Input validation interface.
75
+ */
76
+
77
+ interface InputValidator {
78
+ /** Validate input against a set of rules */
79
+ validate(input: Record<string, unknown>, rules: InputValidationRule[]): InputValidationResult;
80
+ /** Sanitize a string value */
81
+ sanitize(value: string, options?: SanitizeOptions): string;
82
+ /** Validate a shop domain format */
83
+ isValidShopDomain(domain: string): boolean;
84
+ /** Validate an email format */
85
+ isValidEmail(email: string): boolean;
86
+ /** Validate a URL format */
87
+ isValidUrl(url: string): boolean;
88
+ /** Validate an API key format */
89
+ isValidApiKey(key: string): boolean;
90
+ }
91
+
92
+ /**
93
+ * Security middleware interfaces.
94
+ */
95
+
96
+ /** HTTP request/response abstraction for middleware */
97
+ interface SecurityRequest {
98
+ ip?: string;
99
+ headers: Record<string, string | string[] | undefined>;
100
+ path: string;
101
+ method: string;
102
+ }
103
+ interface SecurityResponse {
104
+ setHeader(name: string, value: string): void;
105
+ }
106
+ /** Applies security headers to HTTP responses */
107
+ interface SecurityHeadersMiddleware {
108
+ readonly config: SecurityHeadersConfig;
109
+ applyHeaders(res: SecurityResponse): void;
110
+ }
111
+ /** Applies Content Security Policy headers */
112
+ interface CSPMiddleware {
113
+ readonly directives: CSPDirectives;
114
+ applyCSP(res: SecurityResponse): void;
115
+ toHeaderString(): string;
116
+ }
117
+ /** Rate limiter for HTTP requests */
118
+ interface RequestRateLimiter {
119
+ readonly config: RateLimitConfig;
120
+ /** Check if a request is allowed. Key is typically IP or shop domain. */
121
+ check(key: string): Promise<RateLimitResult>;
122
+ /** Reset rate limit for a key */
123
+ reset(key: string): Promise<void>;
124
+ }
125
+
126
+ /**
127
+ * Security audit interface.
128
+ */
129
+
130
+ interface SecurityAuditConfig {
131
+ checkEncryption: boolean;
132
+ checkHeaders: boolean;
133
+ checkRateLimiting: boolean;
134
+ checkInputValidation: boolean;
135
+ checkWebhookSecurity: boolean;
136
+ checkSessionSecurity: boolean;
137
+ }
138
+ interface SecurityAuditor {
139
+ /** Run a full security audit */
140
+ audit(config: SecurityAuditConfig): SecurityAuditResult;
141
+ /** Check if encryption is properly configured */
142
+ checkEncryption(config: Record<string, unknown>): SecurityAuditResult;
143
+ /** Check if security headers are configured */
144
+ checkHeaders(headers: Record<string, string>): SecurityAuditResult;
145
+ }
146
+ declare const DEFAULT_AUDIT_CONFIG: SecurityAuditConfig;
147
+
148
+ export { type CSPDirectives, type CSPMiddleware, DEFAULT_AUDIT_CONFIG, type InputValidationError, type InputValidationResult, type InputValidationRule, type InputValidator, type RateLimitConfig, type RateLimitResult, type RequestRateLimiter, type SanitizeOptions, type SecurityAuditConfig, type SecurityAuditFinding, type SecurityAuditResult, type SecurityAuditor, type SecurityFindingSeverity, type SecurityHeadersConfig, type SecurityHeadersMiddleware, type SecurityRequest, type SecurityResponse };
@@ -0,0 +1,40 @@
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/security/index.ts
21
+ var security_exports = {};
22
+ __export(security_exports, {
23
+ DEFAULT_AUDIT_CONFIG: () => DEFAULT_AUDIT_CONFIG
24
+ });
25
+ module.exports = __toCommonJS(security_exports);
26
+
27
+ // src/security/audit.ts
28
+ var DEFAULT_AUDIT_CONFIG = {
29
+ checkEncryption: true,
30
+ checkHeaders: true,
31
+ checkRateLimiting: true,
32
+ checkInputValidation: true,
33
+ checkWebhookSecurity: true,
34
+ checkSessionSecurity: true
35
+ };
36
+ // Annotate the CommonJS export names for ESM import in node:
37
+ 0 && (module.exports = {
38
+ DEFAULT_AUDIT_CONFIG
39
+ });
40
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/security/index.ts","../../src/security/audit.ts"],"sourcesContent":["/**\n * @uniforge/platform-core/security\n *\n * Security interfaces for input validation, security headers,\n * CSP, rate limiting, and security auditing.\n */\n\nexport type {\n SanitizeOptions,\n InputValidationRule,\n InputValidationError,\n InputValidationResult,\n RateLimitConfig,\n RateLimitResult,\n SecurityHeadersConfig,\n CSPDirectives,\n SecurityFindingSeverity,\n SecurityAuditFinding,\n SecurityAuditResult,\n} from './types';\n\nexport type { InputValidator } from './input-validation';\n\nexport type {\n SecurityRequest,\n SecurityResponse,\n SecurityHeadersMiddleware,\n CSPMiddleware,\n RequestRateLimiter,\n} from './middleware';\n\nexport type { SecurityAuditConfig, SecurityAuditor } from './audit';\nexport { DEFAULT_AUDIT_CONFIG } from './audit';\n","/**\n * Security audit interface.\n */\n\nimport type { SecurityAuditResult } from './types';\n\nexport interface SecurityAuditConfig {\n checkEncryption: boolean;\n checkHeaders: boolean;\n checkRateLimiting: boolean;\n checkInputValidation: boolean;\n checkWebhookSecurity: boolean;\n checkSessionSecurity: boolean;\n}\n\nexport interface SecurityAuditor {\n /** Run a full security audit */\n audit(config: SecurityAuditConfig): SecurityAuditResult;\n\n /** Check if encryption is properly configured */\n checkEncryption(config: Record<string, unknown>): SecurityAuditResult;\n\n /** Check if security headers are configured */\n checkHeaders(headers: Record<string, string>): SecurityAuditResult;\n}\n\nexport const DEFAULT_AUDIT_CONFIG: SecurityAuditConfig = {\n checkEncryption: true,\n checkHeaders: true,\n checkRateLimiting: true,\n checkInputValidation: true,\n checkWebhookSecurity: true,\n checkSessionSecurity: true,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC0BO,IAAM,uBAA4C;AAAA,EACvD,iBAAiB;AAAA,EACjB,cAAc;AAAA,EACd,mBAAmB;AAAA,EACnB,sBAAsB;AAAA,EACtB,sBAAsB;AAAA,EACtB,sBAAsB;AACxB;","names":[]}
@@ -0,0 +1,13 @@
1
+ // src/security/audit.ts
2
+ var DEFAULT_AUDIT_CONFIG = {
3
+ checkEncryption: true,
4
+ checkHeaders: true,
5
+ checkRateLimiting: true,
6
+ checkInputValidation: true,
7
+ checkWebhookSecurity: true,
8
+ checkSessionSecurity: true
9
+ };
10
+ export {
11
+ DEFAULT_AUDIT_CONFIG
12
+ };
13
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/security/audit.ts"],"sourcesContent":["/**\n * Security audit interface.\n */\n\nimport type { SecurityAuditResult } from './types';\n\nexport interface SecurityAuditConfig {\n checkEncryption: boolean;\n checkHeaders: boolean;\n checkRateLimiting: boolean;\n checkInputValidation: boolean;\n checkWebhookSecurity: boolean;\n checkSessionSecurity: boolean;\n}\n\nexport interface SecurityAuditor {\n /** Run a full security audit */\n audit(config: SecurityAuditConfig): SecurityAuditResult;\n\n /** Check if encryption is properly configured */\n checkEncryption(config: Record<string, unknown>): SecurityAuditResult;\n\n /** Check if security headers are configured */\n checkHeaders(headers: Record<string, string>): SecurityAuditResult;\n}\n\nexport const DEFAULT_AUDIT_CONFIG: SecurityAuditConfig = {\n checkEncryption: true,\n checkHeaders: true,\n checkRateLimiting: true,\n checkInputValidation: true,\n checkWebhookSecurity: true,\n checkSessionSecurity: true,\n};\n"],"mappings":";AA0BO,IAAM,uBAA4C;AAAA,EACvD,iBAAiB;AAAA,EACjB,cAAc;AAAA,EACd,mBAAmB;AAAA,EACnB,sBAAsB;AAAA,EACtB,sBAAsB;AAAA,EACtB,sBAAsB;AACxB;","names":[]}
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Platform-agnostic authentication types.
3
+ *
4
+ * These types define the session data model used across all platform adapters.
5
+ * Closely maps to Shopify's Session type but extends it with UniForge-specific
6
+ * fields for encryption metadata and refresh token support.
7
+ */
8
+ /** Represents an authenticated session with a Shopify store. */
9
+ interface Session {
10
+ readonly id: string;
11
+ shop: string;
12
+ state: string;
13
+ isOnline: boolean;
14
+ scope: string;
15
+ expires: Date | null;
16
+ accessToken?: string;
17
+ refreshToken?: string;
18
+ refreshTokenExpiresAt?: Date | null;
19
+ onlineAccessInfo?: OnlineAccessInfo;
20
+ createdAt: Date;
21
+ updatedAt: Date;
22
+ }
23
+ /** Online access information for user-scoped sessions. */
24
+ interface OnlineAccessInfo {
25
+ expiresIn: number;
26
+ associatedUserScope: string;
27
+ associatedUser: AssociatedUser;
28
+ }
29
+ /** Shopify user associated with an online session. */
30
+ interface AssociatedUser {
31
+ id: number;
32
+ firstName: string;
33
+ lastName: string;
34
+ email: string;
35
+ emailVerified: boolean;
36
+ accountOwner: boolean;
37
+ locale: string;
38
+ collaborator: boolean;
39
+ }
40
+ /** Serialized session data for storage and transport. */
41
+ interface SessionData {
42
+ id: string;
43
+ shop: string;
44
+ state: string;
45
+ isOnline: boolean;
46
+ scope: string;
47
+ expires: string | null;
48
+ accessToken?: string;
49
+ refreshToken?: string;
50
+ refreshTokenExpiresAt?: string | null;
51
+ onlineAccessInfo?: OnlineAccessInfo;
52
+ createdAt: string;
53
+ updatedAt: string;
54
+ }
55
+ /** Shopify store record for tracking installation state. */
56
+ interface Shop {
57
+ shopDomain: string;
58
+ isInstalled: boolean;
59
+ installedAt: Date | null;
60
+ uninstalledAt: Date | null;
61
+ scopes: string;
62
+ shopifyPlan: string | null;
63
+ createdAt: Date;
64
+ updatedAt: Date;
65
+ }
66
+ /** Request-scoped context containing shop details and session. */
67
+ interface ShopContext {
68
+ shopDomain: string;
69
+ accessToken: string;
70
+ scopes: string[];
71
+ session: Session;
72
+ }
73
+
74
+ export type { AssociatedUser as A, OnlineAccessInfo as O, Session as S, ShopContext as a, SessionData as b, Shop as c };
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Platform-agnostic authentication types.
3
+ *
4
+ * These types define the session data model used across all platform adapters.
5
+ * Closely maps to Shopify's Session type but extends it with UniForge-specific
6
+ * fields for encryption metadata and refresh token support.
7
+ */
8
+ /** Represents an authenticated session with a Shopify store. */
9
+ interface Session {
10
+ readonly id: string;
11
+ shop: string;
12
+ state: string;
13
+ isOnline: boolean;
14
+ scope: string;
15
+ expires: Date | null;
16
+ accessToken?: string;
17
+ refreshToken?: string;
18
+ refreshTokenExpiresAt?: Date | null;
19
+ onlineAccessInfo?: OnlineAccessInfo;
20
+ createdAt: Date;
21
+ updatedAt: Date;
22
+ }
23
+ /** Online access information for user-scoped sessions. */
24
+ interface OnlineAccessInfo {
25
+ expiresIn: number;
26
+ associatedUserScope: string;
27
+ associatedUser: AssociatedUser;
28
+ }
29
+ /** Shopify user associated with an online session. */
30
+ interface AssociatedUser {
31
+ id: number;
32
+ firstName: string;
33
+ lastName: string;
34
+ email: string;
35
+ emailVerified: boolean;
36
+ accountOwner: boolean;
37
+ locale: string;
38
+ collaborator: boolean;
39
+ }
40
+ /** Serialized session data for storage and transport. */
41
+ interface SessionData {
42
+ id: string;
43
+ shop: string;
44
+ state: string;
45
+ isOnline: boolean;
46
+ scope: string;
47
+ expires: string | null;
48
+ accessToken?: string;
49
+ refreshToken?: string;
50
+ refreshTokenExpiresAt?: string | null;
51
+ onlineAccessInfo?: OnlineAccessInfo;
52
+ createdAt: string;
53
+ updatedAt: string;
54
+ }
55
+ /** Shopify store record for tracking installation state. */
56
+ interface Shop {
57
+ shopDomain: string;
58
+ isInstalled: boolean;
59
+ installedAt: Date | null;
60
+ uninstalledAt: Date | null;
61
+ scopes: string;
62
+ shopifyPlan: string | null;
63
+ createdAt: Date;
64
+ updatedAt: Date;
65
+ }
66
+ /** Request-scoped context containing shop details and session. */
67
+ interface ShopContext {
68
+ shopDomain: string;
69
+ accessToken: string;
70
+ scopes: string[];
71
+ session: Session;
72
+ }
73
+
74
+ export type { AssociatedUser as A, OnlineAccessInfo as O, Session as S, ShopContext as a, SessionData as b, Shop as c };
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Core webhook types and interfaces.
3
+ *
4
+ * Platform-agnostic types for webhook handling including
5
+ * payloads, handlers, and registration.
6
+ */
7
+ /** Common Shopify webhook topics. */
8
+ type WebhookTopic = 'APP_UNINSTALLED' | 'APP_SUBSCRIPTIONS_UPDATE' | 'PRODUCTS_CREATE' | 'PRODUCTS_UPDATE' | 'PRODUCTS_DELETE' | 'ORDERS_CREATE' | 'ORDERS_UPDATED' | 'ORDERS_PAID' | 'ORDERS_FULFILLED' | 'CUSTOMERS_CREATE' | 'CUSTOMERS_UPDATE' | 'CUSTOMERS_DELETE' | 'SHOP_UPDATE' | string;
9
+ interface WebhookPayload {
10
+ topic: string;
11
+ shopDomain: string;
12
+ apiVersion: string;
13
+ payload: unknown;
14
+ webhookId: string;
15
+ timestamp: Date;
16
+ }
17
+ interface WebhookHandler {
18
+ handle(payload: WebhookPayload): Promise<WebhookHandlerResult>;
19
+ }
20
+ interface WebhookHandlerResult {
21
+ success: boolean;
22
+ error?: string;
23
+ }
24
+ interface WebhookRegistration {
25
+ topic: string;
26
+ address: string;
27
+ format?: 'json' | 'xml';
28
+ }
29
+
30
+ /**
31
+ * Webhook HMAC validation interfaces.
32
+ *
33
+ * Defines the contract for validating incoming webhook requests
34
+ * using HMAC-SHA256 signatures (base64-encoded for Shopify webhooks).
35
+ */
36
+ interface WebhookValidator {
37
+ validate(request: WebhookValidationRequest): boolean;
38
+ }
39
+ interface WebhookValidationRequest {
40
+ rawBody: Buffer;
41
+ hmac: string;
42
+ secret: string;
43
+ }
44
+
45
+ /**
46
+ * Webhook queue interfaces.
47
+ *
48
+ * Defines the contract for a Redis-backed webhook processing queue
49
+ * with retry support and dead letter handling.
50
+ */
51
+
52
+ type WebhookJobStatus = 'pending' | 'processing' | 'completed' | 'failed' | 'dead';
53
+ interface WebhookQueue {
54
+ enqueue(payload: WebhookPayload): Promise<string>;
55
+ dequeueNext(): Promise<WebhookJob | undefined>;
56
+ getJob(jobId: string): Promise<WebhookJob | undefined>;
57
+ acknowledgeJob(jobId: string, result: WebhookHandlerResult): Promise<void>;
58
+ requeueJob(jobId: string, error: string): Promise<void>;
59
+ getDeadLetterJobs(limit?: number): Promise<WebhookJob[]>;
60
+ }
61
+ interface WebhookJob {
62
+ id: string;
63
+ payload: WebhookPayload;
64
+ status: WebhookJobStatus;
65
+ attempts: number;
66
+ maxAttempts: number;
67
+ lastError?: string;
68
+ createdAt: Date;
69
+ updatedAt: Date;
70
+ nextRetryAt?: Date;
71
+ }
72
+ interface WebhookQueueConfig {
73
+ maxAttempts?: number;
74
+ baseRetryDelayMs?: number;
75
+ maxRetryDelayMs?: number;
76
+ keyPrefix?: string;
77
+ }
78
+
79
+ /**
80
+ * GDPR webhook types.
81
+ *
82
+ * Defines the Shopify mandatory GDPR webhook payload shapes
83
+ * and the handler interface for processing them.
84
+ */
85
+ interface CustomersDataRequest {
86
+ shop_domain: string;
87
+ customer: {
88
+ id: number;
89
+ email: string;
90
+ phone?: string;
91
+ };
92
+ orders_requested: number[];
93
+ }
94
+ interface CustomersRedact {
95
+ shop_domain: string;
96
+ customer: {
97
+ id: number;
98
+ email: string;
99
+ phone?: string;
100
+ };
101
+ orders_to_redact: number[];
102
+ }
103
+ interface ShopRedact {
104
+ shop_domain: string;
105
+ shop_id: number;
106
+ }
107
+ type GdprWebhookType = 'customers/data_request' | 'customers/redact' | 'shop/redact';
108
+ interface GdprHandler {
109
+ handleDataRequest(payload: CustomersDataRequest): Promise<void>;
110
+ handleCustomerRedact(payload: CustomersRedact): Promise<void>;
111
+ handleShopRedact(payload: ShopRedact): Promise<void>;
112
+ }
113
+
114
+ export type { CustomersDataRequest, CustomersRedact, GdprHandler, GdprWebhookType, ShopRedact, WebhookHandler, WebhookHandlerResult, WebhookJob, WebhookJobStatus, WebhookPayload, WebhookQueue, WebhookQueueConfig, WebhookRegistration, WebhookTopic, WebhookValidationRequest, WebhookValidator };