@uniforge/testing 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 (85) hide show
  1. package/dist/auth/index.d.cts +177 -0
  2. package/dist/auth/index.d.ts +177 -0
  3. package/dist/auth/index.js +459 -0
  4. package/dist/auth/index.js.map +1 -0
  5. package/dist/auth/index.mjs +418 -0
  6. package/dist/auth/index.mjs.map +1 -0
  7. package/dist/billing/index.d.cts +27 -0
  8. package/dist/billing/index.d.ts +27 -0
  9. package/dist/billing/index.js +208 -0
  10. package/dist/billing/index.js.map +1 -0
  11. package/dist/billing/index.mjs +178 -0
  12. package/dist/billing/index.mjs.map +1 -0
  13. package/dist/database/index.d.cts +399 -0
  14. package/dist/database/index.d.ts +399 -0
  15. package/dist/database/index.js +19054 -0
  16. package/dist/database/index.js.map +1 -0
  17. package/dist/database/index.mjs +19046 -0
  18. package/dist/database/index.mjs.map +1 -0
  19. package/dist/graphql/index.d.cts +23 -0
  20. package/dist/graphql/index.d.ts +23 -0
  21. package/dist/graphql/index.js +18511 -0
  22. package/dist/graphql/index.js.map +1 -0
  23. package/dist/graphql/index.mjs +18505 -0
  24. package/dist/graphql/index.mjs.map +1 -0
  25. package/dist/index.d.cts +10 -0
  26. package/dist/index.d.ts +10 -0
  27. package/dist/index.js +31 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/index.mjs +6 -0
  30. package/dist/index.mjs.map +1 -0
  31. package/dist/multi-store/index.d.cts +66 -0
  32. package/dist/multi-store/index.d.ts +66 -0
  33. package/dist/multi-store/index.js +319 -0
  34. package/dist/multi-store/index.js.map +1 -0
  35. package/dist/multi-store/index.mjs +287 -0
  36. package/dist/multi-store/index.mjs.map +1 -0
  37. package/dist/multi-tenant/index.d.cts +15 -0
  38. package/dist/multi-tenant/index.d.ts +15 -0
  39. package/dist/multi-tenant/index.js +87 -0
  40. package/dist/multi-tenant/index.js.map +1 -0
  41. package/dist/multi-tenant/index.mjs +57 -0
  42. package/dist/multi-tenant/index.mjs.map +1 -0
  43. package/dist/performance/index.d.cts +60 -0
  44. package/dist/performance/index.d.ts +60 -0
  45. package/dist/performance/index.js +280 -0
  46. package/dist/performance/index.js.map +1 -0
  47. package/dist/performance/index.mjs +246 -0
  48. package/dist/performance/index.mjs.map +1 -0
  49. package/dist/platform/index.d.cts +71 -0
  50. package/dist/platform/index.d.ts +71 -0
  51. package/dist/platform/index.js +435 -0
  52. package/dist/platform/index.js.map +1 -0
  53. package/dist/platform/index.mjs +396 -0
  54. package/dist/platform/index.mjs.map +1 -0
  55. package/dist/rbac/index.d.cts +21 -0
  56. package/dist/rbac/index.d.ts +21 -0
  57. package/dist/rbac/index.js +178 -0
  58. package/dist/rbac/index.js.map +1 -0
  59. package/dist/rbac/index.mjs +150 -0
  60. package/dist/rbac/index.mjs.map +1 -0
  61. package/dist/security/index.d.cts +73 -0
  62. package/dist/security/index.d.ts +73 -0
  63. package/dist/security/index.js +246 -0
  64. package/dist/security/index.js.map +1 -0
  65. package/dist/security/index.mjs +211 -0
  66. package/dist/security/index.mjs.map +1 -0
  67. package/dist/shopify-api/index.d.cts +139 -0
  68. package/dist/shopify-api/index.d.ts +139 -0
  69. package/dist/shopify-api/index.js +469 -0
  70. package/dist/shopify-api/index.js.map +1 -0
  71. package/dist/shopify-api/index.mjs +439 -0
  72. package/dist/shopify-api/index.mjs.map +1 -0
  73. package/dist/shopify-compliance/index.d.cts +85 -0
  74. package/dist/shopify-compliance/index.d.ts +85 -0
  75. package/dist/shopify-compliance/index.js +287 -0
  76. package/dist/shopify-compliance/index.js.map +1 -0
  77. package/dist/shopify-compliance/index.mjs +259 -0
  78. package/dist/shopify-compliance/index.mjs.map +1 -0
  79. package/dist/webhooks/index.d.cts +127 -0
  80. package/dist/webhooks/index.d.ts +127 -0
  81. package/dist/webhooks/index.js +18934 -0
  82. package/dist/webhooks/index.js.map +1 -0
  83. package/dist/webhooks/index.mjs +18916 -0
  84. package/dist/webhooks/index.mjs.map +1 -0
  85. package/package.json +112 -0
@@ -0,0 +1,177 @@
1
+ import { SessionStorage, Session, Shop, AuthEvent, OnlineAccessInfo, ShopContext, AuthEventType } from '@uniforge/platform-core/auth';
2
+
3
+ /**
4
+ * In-memory session storage for testing.
5
+ */
6
+
7
+ declare class MemorySessionStorage implements SessionStorage {
8
+ private sessions;
9
+ storeSession(session: Session): Promise<boolean>;
10
+ loadSession(id: string): Promise<Session | undefined>;
11
+ deleteSession(id: string): Promise<boolean>;
12
+ deleteSessions(ids: string[]): Promise<boolean>;
13
+ findSessionsByShop(shop: string): Promise<Session[]>;
14
+ clear(): void;
15
+ get size(): number;
16
+ }
17
+
18
+ /**
19
+ * Test data factories for authentication types.
20
+ *
21
+ * Each factory provides sensible defaults that can be overridden.
22
+ */
23
+
24
+ declare function createMockSession(overrides?: Partial<Session>): Session;
25
+ declare function createMockShop(overrides?: Partial<Shop>): Shop;
26
+ declare function createMockAuthEvent(overrides?: Partial<AuthEvent>): AuthEvent;
27
+
28
+ /**
29
+ * Mock Shopify API response factories for testing.
30
+ *
31
+ * These mocks simulate Shopify API responses for token exchange,
32
+ * OAuth callback, and token refresh flows.
33
+ */
34
+ interface MockTokenExchangeResponse {
35
+ access_token: string;
36
+ scope: string;
37
+ expires_in?: number;
38
+ associated_user_scope?: string;
39
+ associated_user?: {
40
+ id: number;
41
+ first_name: string;
42
+ last_name: string;
43
+ email: string;
44
+ email_verified: boolean;
45
+ account_owner: boolean;
46
+ locale: string;
47
+ collaborator: boolean;
48
+ };
49
+ }
50
+ interface MockOAuthCallbackResponse {
51
+ access_token: string;
52
+ scope: string;
53
+ }
54
+ interface MockRefreshTokenResponse {
55
+ access_token: string;
56
+ refresh_token: string;
57
+ expires_in: number;
58
+ scope: string;
59
+ }
60
+ declare function mockTokenExchangeResponse(overrides?: Partial<MockTokenExchangeResponse>): MockTokenExchangeResponse;
61
+ declare function mockOnlineTokenExchangeResponse(overrides?: Partial<MockTokenExchangeResponse>): MockTokenExchangeResponse;
62
+ declare function mockOAuthCallbackResponse(overrides?: Partial<MockOAuthCallbackResponse>): MockOAuthCallbackResponse;
63
+ declare function mockRefreshTokenResponse(overrides?: Partial<MockRefreshTokenResponse>): MockRefreshTokenResponse;
64
+
65
+ /**
66
+ * Fluent builder for creating session test fixtures in various states.
67
+ *
68
+ * Provides a chainable API for constructing Session objects with
69
+ * controlled expiry, tokens, and online access information.
70
+ */
71
+
72
+ declare class SessionFixtureBuilder {
73
+ private data;
74
+ private constructor();
75
+ static offline(shop?: string): SessionFixtureBuilder;
76
+ static online(shop?: string, userId?: number): SessionFixtureBuilder;
77
+ withAccessToken(token: string): this;
78
+ withScopes(scopes: string[] | string): this;
79
+ expired(minutesAgo?: number): this;
80
+ expiringSoon(minutesUntil?: number): this;
81
+ valid(hoursUntil?: number): this;
82
+ withRefreshToken(token: string, expiresAt?: Date): this;
83
+ withOnlineAccessInfo(info: Partial<OnlineAccessInfo>): this;
84
+ withState(state: string): this;
85
+ withId(id: string): this;
86
+ build(): Session;
87
+ }
88
+
89
+ /**
90
+ * HMAC test utilities for Shopify authentication testing.
91
+ *
92
+ * Provides helpers for computing and verifying HMACs used in
93
+ * OAuth callbacks and webhook validation.
94
+ */
95
+ /**
96
+ * Compute Shopify HMAC for query params.
97
+ * Sorts params alphabetically, joins as key=value pairs with &,
98
+ * and returns a hex HMAC-SHA256 digest.
99
+ */
100
+ declare function computeShopifyHmac(params: Record<string, string>, secret: string): string;
101
+ /**
102
+ * Compute webhook HMAC (base64 digest).
103
+ * Used for validating Shopify webhook request bodies.
104
+ */
105
+ declare function computeWebhookHmac(body: string | Buffer, secret: string): string;
106
+ /**
107
+ * Verify HMAC with timing-safe comparison.
108
+ * Returns true if computed matches provided.
109
+ */
110
+ declare function verifyHmac(computed: string, provided: string): boolean;
111
+ /**
112
+ * Generate a query string with HMAC appended.
113
+ * Sorts params, computes HMAC, and returns the full query string.
114
+ */
115
+ declare function createSignedQueryString(params: Record<string, string>, secret: string): string;
116
+ /**
117
+ * Create a complete signed URL for OAuth callbacks.
118
+ * Appends signed query params to the base URL.
119
+ */
120
+ declare function createSignedUrl(baseUrl: string, params: Record<string, string>, secret: string): string;
121
+
122
+ /**
123
+ * Auth flow simulator for testing authentication workflows.
124
+ *
125
+ * Simulates token exchange, OAuth flows, token refresh, and
126
+ * generates auth events without requiring a real Shopify API.
127
+ */
128
+
129
+ interface AuthFlowSimulatorConfig {
130
+ apiKey?: string;
131
+ apiSecretKey?: string;
132
+ scopes?: string[];
133
+ hostName?: string;
134
+ }
135
+ interface TokenExchangeResult {
136
+ session: Session;
137
+ shopContext: ShopContext;
138
+ }
139
+ interface OAuthFlowResult {
140
+ authorizeUrl: string;
141
+ authCode: string;
142
+ callbackSession: Session;
143
+ shopContext: ShopContext;
144
+ }
145
+ declare class AuthFlowSimulator {
146
+ private readonly config;
147
+ constructor(config?: AuthFlowSimulatorConfig);
148
+ simulateTokenExchange(shopDomain: string, options?: {
149
+ isOnline?: boolean;
150
+ userId?: number;
151
+ scopes?: string[];
152
+ accessToken?: string;
153
+ }): TokenExchangeResult;
154
+ simulateOAuthFlow(shopDomain: string, options?: {
155
+ isOnline?: boolean;
156
+ userId?: number;
157
+ scopes?: string[];
158
+ }): OAuthFlowResult;
159
+ simulateTokenRefresh(session: Session, options?: {
160
+ newAccessToken?: string;
161
+ newRefreshToken?: string;
162
+ newScopes?: string[];
163
+ }): Session;
164
+ createExpiredSession(shopDomain: string, options?: {
165
+ isOnline?: boolean;
166
+ expiredMinutesAgo?: number;
167
+ }): Session;
168
+ generateAuthEvent(type: AuthEventType, shopDomain: string, options?: {
169
+ sessionId?: string;
170
+ userId?: number;
171
+ outcome?: 'success' | 'failure';
172
+ metadata?: Record<string, string>;
173
+ }): AuthEvent;
174
+ get secret(): string;
175
+ }
176
+
177
+ export { AuthFlowSimulator, type AuthFlowSimulatorConfig, MemorySessionStorage, type MockOAuthCallbackResponse, type MockRefreshTokenResponse, type MockTokenExchangeResponse, type OAuthFlowResult, SessionFixtureBuilder, type TokenExchangeResult, computeShopifyHmac, computeWebhookHmac, createMockAuthEvent, createMockSession, createMockShop, createSignedQueryString, createSignedUrl, mockOAuthCallbackResponse, mockOnlineTokenExchangeResponse, mockRefreshTokenResponse, mockTokenExchangeResponse, verifyHmac };
@@ -0,0 +1,177 @@
1
+ import { SessionStorage, Session, Shop, AuthEvent, OnlineAccessInfo, ShopContext, AuthEventType } from '@uniforge/platform-core/auth';
2
+
3
+ /**
4
+ * In-memory session storage for testing.
5
+ */
6
+
7
+ declare class MemorySessionStorage implements SessionStorage {
8
+ private sessions;
9
+ storeSession(session: Session): Promise<boolean>;
10
+ loadSession(id: string): Promise<Session | undefined>;
11
+ deleteSession(id: string): Promise<boolean>;
12
+ deleteSessions(ids: string[]): Promise<boolean>;
13
+ findSessionsByShop(shop: string): Promise<Session[]>;
14
+ clear(): void;
15
+ get size(): number;
16
+ }
17
+
18
+ /**
19
+ * Test data factories for authentication types.
20
+ *
21
+ * Each factory provides sensible defaults that can be overridden.
22
+ */
23
+
24
+ declare function createMockSession(overrides?: Partial<Session>): Session;
25
+ declare function createMockShop(overrides?: Partial<Shop>): Shop;
26
+ declare function createMockAuthEvent(overrides?: Partial<AuthEvent>): AuthEvent;
27
+
28
+ /**
29
+ * Mock Shopify API response factories for testing.
30
+ *
31
+ * These mocks simulate Shopify API responses for token exchange,
32
+ * OAuth callback, and token refresh flows.
33
+ */
34
+ interface MockTokenExchangeResponse {
35
+ access_token: string;
36
+ scope: string;
37
+ expires_in?: number;
38
+ associated_user_scope?: string;
39
+ associated_user?: {
40
+ id: number;
41
+ first_name: string;
42
+ last_name: string;
43
+ email: string;
44
+ email_verified: boolean;
45
+ account_owner: boolean;
46
+ locale: string;
47
+ collaborator: boolean;
48
+ };
49
+ }
50
+ interface MockOAuthCallbackResponse {
51
+ access_token: string;
52
+ scope: string;
53
+ }
54
+ interface MockRefreshTokenResponse {
55
+ access_token: string;
56
+ refresh_token: string;
57
+ expires_in: number;
58
+ scope: string;
59
+ }
60
+ declare function mockTokenExchangeResponse(overrides?: Partial<MockTokenExchangeResponse>): MockTokenExchangeResponse;
61
+ declare function mockOnlineTokenExchangeResponse(overrides?: Partial<MockTokenExchangeResponse>): MockTokenExchangeResponse;
62
+ declare function mockOAuthCallbackResponse(overrides?: Partial<MockOAuthCallbackResponse>): MockOAuthCallbackResponse;
63
+ declare function mockRefreshTokenResponse(overrides?: Partial<MockRefreshTokenResponse>): MockRefreshTokenResponse;
64
+
65
+ /**
66
+ * Fluent builder for creating session test fixtures in various states.
67
+ *
68
+ * Provides a chainable API for constructing Session objects with
69
+ * controlled expiry, tokens, and online access information.
70
+ */
71
+
72
+ declare class SessionFixtureBuilder {
73
+ private data;
74
+ private constructor();
75
+ static offline(shop?: string): SessionFixtureBuilder;
76
+ static online(shop?: string, userId?: number): SessionFixtureBuilder;
77
+ withAccessToken(token: string): this;
78
+ withScopes(scopes: string[] | string): this;
79
+ expired(minutesAgo?: number): this;
80
+ expiringSoon(minutesUntil?: number): this;
81
+ valid(hoursUntil?: number): this;
82
+ withRefreshToken(token: string, expiresAt?: Date): this;
83
+ withOnlineAccessInfo(info: Partial<OnlineAccessInfo>): this;
84
+ withState(state: string): this;
85
+ withId(id: string): this;
86
+ build(): Session;
87
+ }
88
+
89
+ /**
90
+ * HMAC test utilities for Shopify authentication testing.
91
+ *
92
+ * Provides helpers for computing and verifying HMACs used in
93
+ * OAuth callbacks and webhook validation.
94
+ */
95
+ /**
96
+ * Compute Shopify HMAC for query params.
97
+ * Sorts params alphabetically, joins as key=value pairs with &,
98
+ * and returns a hex HMAC-SHA256 digest.
99
+ */
100
+ declare function computeShopifyHmac(params: Record<string, string>, secret: string): string;
101
+ /**
102
+ * Compute webhook HMAC (base64 digest).
103
+ * Used for validating Shopify webhook request bodies.
104
+ */
105
+ declare function computeWebhookHmac(body: string | Buffer, secret: string): string;
106
+ /**
107
+ * Verify HMAC with timing-safe comparison.
108
+ * Returns true if computed matches provided.
109
+ */
110
+ declare function verifyHmac(computed: string, provided: string): boolean;
111
+ /**
112
+ * Generate a query string with HMAC appended.
113
+ * Sorts params, computes HMAC, and returns the full query string.
114
+ */
115
+ declare function createSignedQueryString(params: Record<string, string>, secret: string): string;
116
+ /**
117
+ * Create a complete signed URL for OAuth callbacks.
118
+ * Appends signed query params to the base URL.
119
+ */
120
+ declare function createSignedUrl(baseUrl: string, params: Record<string, string>, secret: string): string;
121
+
122
+ /**
123
+ * Auth flow simulator for testing authentication workflows.
124
+ *
125
+ * Simulates token exchange, OAuth flows, token refresh, and
126
+ * generates auth events without requiring a real Shopify API.
127
+ */
128
+
129
+ interface AuthFlowSimulatorConfig {
130
+ apiKey?: string;
131
+ apiSecretKey?: string;
132
+ scopes?: string[];
133
+ hostName?: string;
134
+ }
135
+ interface TokenExchangeResult {
136
+ session: Session;
137
+ shopContext: ShopContext;
138
+ }
139
+ interface OAuthFlowResult {
140
+ authorizeUrl: string;
141
+ authCode: string;
142
+ callbackSession: Session;
143
+ shopContext: ShopContext;
144
+ }
145
+ declare class AuthFlowSimulator {
146
+ private readonly config;
147
+ constructor(config?: AuthFlowSimulatorConfig);
148
+ simulateTokenExchange(shopDomain: string, options?: {
149
+ isOnline?: boolean;
150
+ userId?: number;
151
+ scopes?: string[];
152
+ accessToken?: string;
153
+ }): TokenExchangeResult;
154
+ simulateOAuthFlow(shopDomain: string, options?: {
155
+ isOnline?: boolean;
156
+ userId?: number;
157
+ scopes?: string[];
158
+ }): OAuthFlowResult;
159
+ simulateTokenRefresh(session: Session, options?: {
160
+ newAccessToken?: string;
161
+ newRefreshToken?: string;
162
+ newScopes?: string[];
163
+ }): Session;
164
+ createExpiredSession(shopDomain: string, options?: {
165
+ isOnline?: boolean;
166
+ expiredMinutesAgo?: number;
167
+ }): Session;
168
+ generateAuthEvent(type: AuthEventType, shopDomain: string, options?: {
169
+ sessionId?: string;
170
+ userId?: number;
171
+ outcome?: 'success' | 'failure';
172
+ metadata?: Record<string, string>;
173
+ }): AuthEvent;
174
+ get secret(): string;
175
+ }
176
+
177
+ export { AuthFlowSimulator, type AuthFlowSimulatorConfig, MemorySessionStorage, type MockOAuthCallbackResponse, type MockRefreshTokenResponse, type MockTokenExchangeResponse, type OAuthFlowResult, SessionFixtureBuilder, type TokenExchangeResult, computeShopifyHmac, computeWebhookHmac, createMockAuthEvent, createMockSession, createMockShop, createSignedQueryString, createSignedUrl, mockOAuthCallbackResponse, mockOnlineTokenExchangeResponse, mockRefreshTokenResponse, mockTokenExchangeResponse, verifyHmac };