@auth-gate/testing 0.7.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,177 @@
1
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined") return require.apply(this, arguments);
5
+ throw Error('Dynamic require of "' + x + '" is not supported');
6
+ });
7
+
8
+ // src/constants.ts
9
+ var TEST_EMAIL_DOMAIN = "test.authgate.dev";
10
+ var TEST_OTP_CODE = "424242";
11
+
12
+ // src/client.ts
13
+ var AuthGateTest = class {
14
+ constructor(config) {
15
+ if (!config.apiKey) throw new Error("apiKey is required");
16
+ if (!config.baseUrl) throw new Error("baseUrl is required");
17
+ this.apiKey = config.apiKey;
18
+ this.baseUrl = config.baseUrl.replace(/\/$/, "");
19
+ }
20
+ async request(method, path, body) {
21
+ var _a;
22
+ const url = `${this.baseUrl}/api/v1/testing${path}`;
23
+ const res = await fetch(url, {
24
+ method,
25
+ headers: {
26
+ "Content-Type": "application/json",
27
+ Authorization: `Bearer ${this.apiKey}`
28
+ },
29
+ body: body ? JSON.stringify(body) : void 0
30
+ });
31
+ if (!res.ok) {
32
+ const error = await res.json().catch(() => ({ error: res.statusText }));
33
+ throw new Error(
34
+ `AuthGate Testing API error (${res.status}): ${(_a = error.error) != null ? _a : res.statusText}`
35
+ );
36
+ }
37
+ return res.json();
38
+ }
39
+ async createUser(options) {
40
+ var _a;
41
+ if (!options.email.endsWith(`@${TEST_EMAIL_DOMAIN}`)) {
42
+ throw new Error(`Email must end with @${TEST_EMAIL_DOMAIN}`);
43
+ }
44
+ return this.request("POST", "/users", {
45
+ email: options.email,
46
+ password: options.password,
47
+ name: options.name,
48
+ emailVerified: (_a = options.emailVerified) != null ? _a : true
49
+ });
50
+ }
51
+ async createSession(userId) {
52
+ return this.request("POST", "/sessions", { userId });
53
+ }
54
+ async deleteUser(userId) {
55
+ return this.request("DELETE", `/users/${userId}`);
56
+ }
57
+ async cleanup() {
58
+ return this.request("DELETE", "/users");
59
+ }
60
+ async apiRequest(method, path, body) {
61
+ var _a;
62
+ const url = `${this.baseUrl}/api/v1${path}`;
63
+ const res = await fetch(url, {
64
+ method,
65
+ headers: {
66
+ "Content-Type": "application/json",
67
+ Authorization: `Bearer ${this.apiKey}`
68
+ },
69
+ body: body ? JSON.stringify(body) : void 0
70
+ });
71
+ if (!res.ok) {
72
+ const error = await res.json().catch(() => ({ error: res.statusText }));
73
+ throw new Error(
74
+ `AuthGate API error (${res.status}): ${(_a = error.error) != null ? _a : res.statusText}`
75
+ );
76
+ }
77
+ return res.json();
78
+ }
79
+ async createOrg(options) {
80
+ var _a, _b, _c;
81
+ const res = await this.apiRequest(
82
+ "POST",
83
+ "/orgs",
84
+ {
85
+ name: options.name,
86
+ slug: options.slug,
87
+ max_members: options.maxMembers,
88
+ metadata: options.metadata
89
+ }
90
+ );
91
+ const org = res.organization;
92
+ return {
93
+ id: org.id,
94
+ name: org.name,
95
+ slug: org.slug,
96
+ imageUrl: (_a = org.image_url) != null ? _a : null,
97
+ maxMembers: (_b = org.max_members) != null ? _b : null,
98
+ metadata: (_c = org.metadata) != null ? _c : null,
99
+ createdAt: org.created_at
100
+ };
101
+ }
102
+ async createRole(options) {
103
+ var _a, _b, _c;
104
+ const res = await this.apiRequest(
105
+ "POST",
106
+ "/roles",
107
+ {
108
+ key: options.key,
109
+ name: options.name,
110
+ description: options.description,
111
+ is_default: options.isDefault,
112
+ permissions: options.permissions
113
+ }
114
+ );
115
+ return {
116
+ id: res.id,
117
+ key: res.key,
118
+ name: res.name,
119
+ description: (_a = res.description) != null ? _a : null,
120
+ isDefault: (_b = res.is_default) != null ? _b : false,
121
+ permissions: (_c = res.permissions) != null ? _c : [],
122
+ createdAt: res.created_at
123
+ };
124
+ }
125
+ async addOrgMember(orgId, userId, roleKey) {
126
+ const res = await this.apiRequest(
127
+ "POST",
128
+ `/orgs/${orgId}/members`,
129
+ {
130
+ end_user_id: userId,
131
+ role_key: roleKey
132
+ }
133
+ );
134
+ return {
135
+ id: res.id,
136
+ organizationId: res.organization_id,
137
+ endUserId: res.end_user_id,
138
+ roleKey: res.role_key,
139
+ createdAt: res.created_at
140
+ };
141
+ }
142
+ async deleteOrg(orgId) {
143
+ return this.apiRequest("DELETE", `/orgs/${orgId}`);
144
+ }
145
+ async deleteRole(roleId) {
146
+ return this.apiRequest("DELETE", `/roles/${roleId}`);
147
+ }
148
+ async cleanupOrgs() {
149
+ var _a;
150
+ const res = await this.apiRequest("GET", "/orgs");
151
+ const orgs = (_a = res.organizations) != null ? _a : [];
152
+ let deleted = 0;
153
+ for (const org of orgs) {
154
+ await this.deleteOrg(org.id);
155
+ deleted++;
156
+ }
157
+ return { deleted };
158
+ }
159
+ async cleanupRoles() {
160
+ var _a;
161
+ const res = await this.apiRequest("GET", "/roles");
162
+ const roles = (_a = res.roles) != null ? _a : [];
163
+ let deleted = 0;
164
+ for (const role of roles) {
165
+ await this.deleteRole(role.id);
166
+ deleted++;
167
+ }
168
+ return { deleted };
169
+ }
170
+ };
171
+
172
+ export {
173
+ __require,
174
+ TEST_EMAIL_DOMAIN,
175
+ TEST_OTP_CODE,
176
+ AuthGateTest
177
+ };
@@ -0,0 +1,95 @@
1
+ interface AuthGateTestConfig {
2
+ apiKey: string;
3
+ baseUrl: string;
4
+ }
5
+ interface CreateTestUserOptions {
6
+ email: string;
7
+ password: string;
8
+ name?: string;
9
+ emailVerified?: boolean;
10
+ }
11
+ interface TestUser {
12
+ id: string;
13
+ email: string;
14
+ name: string | null;
15
+ token: string;
16
+ refreshToken: string;
17
+ expiresAt: string;
18
+ }
19
+ interface TestSession {
20
+ token: string;
21
+ refreshToken: string;
22
+ expiresAt: string;
23
+ }
24
+ interface CleanupResult {
25
+ deleted: number;
26
+ }
27
+ interface CreateTestOrgOptions {
28
+ name: string;
29
+ slug?: string;
30
+ maxMembers?: number;
31
+ metadata?: Record<string, unknown>;
32
+ }
33
+ interface TestOrg {
34
+ id: string;
35
+ name: string;
36
+ slug: string;
37
+ imageUrl: string | null;
38
+ maxMembers: number | null;
39
+ metadata: Record<string, unknown> | null;
40
+ createdAt: string;
41
+ }
42
+ interface CreateTestRoleOptions {
43
+ key: string;
44
+ name: string;
45
+ description?: string;
46
+ isDefault?: boolean;
47
+ permissions?: string[];
48
+ }
49
+ interface TestRole {
50
+ id: string;
51
+ key: string;
52
+ name: string;
53
+ description: string | null;
54
+ isDefault: boolean;
55
+ permissions: string[];
56
+ createdAt: string;
57
+ }
58
+ interface TestOrgMember {
59
+ id: string;
60
+ organizationId: string;
61
+ endUserId: string;
62
+ roleKey: string;
63
+ createdAt: string;
64
+ }
65
+
66
+ declare class AuthGateTest {
67
+ private apiKey;
68
+ private baseUrl;
69
+ constructor(config: AuthGateTestConfig);
70
+ private request;
71
+ createUser(options: CreateTestUserOptions): Promise<TestUser>;
72
+ createSession(userId: string): Promise<TestSession>;
73
+ deleteUser(userId: string): Promise<{
74
+ deleted: boolean;
75
+ }>;
76
+ cleanup(): Promise<CleanupResult>;
77
+ private apiRequest;
78
+ createOrg(options: CreateTestOrgOptions): Promise<TestOrg>;
79
+ createRole(options: CreateTestRoleOptions): Promise<TestRole>;
80
+ addOrgMember(orgId: string, userId: string, roleKey: string): Promise<TestOrgMember>;
81
+ deleteOrg(orgId: string): Promise<{
82
+ deleted: boolean;
83
+ }>;
84
+ deleteRole(roleId: string): Promise<{
85
+ deleted: boolean;
86
+ }>;
87
+ cleanupOrgs(): Promise<{
88
+ deleted: number;
89
+ }>;
90
+ cleanupRoles(): Promise<{
91
+ deleted: number;
92
+ }>;
93
+ }
94
+
95
+ export { type AuthGateTestConfig as A, type CreateTestUserOptions as C, type TestUser as T, type CleanupResult as a, AuthGateTest as b, type TestSession as c, type CreateTestOrgOptions as d, type CreateTestRoleOptions as e, type TestOrg as f, type TestOrgMember as g, type TestRole as h };
@@ -0,0 +1,95 @@
1
+ interface AuthGateTestConfig {
2
+ apiKey: string;
3
+ baseUrl: string;
4
+ }
5
+ interface CreateTestUserOptions {
6
+ email: string;
7
+ password: string;
8
+ name?: string;
9
+ emailVerified?: boolean;
10
+ }
11
+ interface TestUser {
12
+ id: string;
13
+ email: string;
14
+ name: string | null;
15
+ token: string;
16
+ refreshToken: string;
17
+ expiresAt: string;
18
+ }
19
+ interface TestSession {
20
+ token: string;
21
+ refreshToken: string;
22
+ expiresAt: string;
23
+ }
24
+ interface CleanupResult {
25
+ deleted: number;
26
+ }
27
+ interface CreateTestOrgOptions {
28
+ name: string;
29
+ slug?: string;
30
+ maxMembers?: number;
31
+ metadata?: Record<string, unknown>;
32
+ }
33
+ interface TestOrg {
34
+ id: string;
35
+ name: string;
36
+ slug: string;
37
+ imageUrl: string | null;
38
+ maxMembers: number | null;
39
+ metadata: Record<string, unknown> | null;
40
+ createdAt: string;
41
+ }
42
+ interface CreateTestRoleOptions {
43
+ key: string;
44
+ name: string;
45
+ description?: string;
46
+ isDefault?: boolean;
47
+ permissions?: string[];
48
+ }
49
+ interface TestRole {
50
+ id: string;
51
+ key: string;
52
+ name: string;
53
+ description: string | null;
54
+ isDefault: boolean;
55
+ permissions: string[];
56
+ createdAt: string;
57
+ }
58
+ interface TestOrgMember {
59
+ id: string;
60
+ organizationId: string;
61
+ endUserId: string;
62
+ roleKey: string;
63
+ createdAt: string;
64
+ }
65
+
66
+ declare class AuthGateTest {
67
+ private apiKey;
68
+ private baseUrl;
69
+ constructor(config: AuthGateTestConfig);
70
+ private request;
71
+ createUser(options: CreateTestUserOptions): Promise<TestUser>;
72
+ createSession(userId: string): Promise<TestSession>;
73
+ deleteUser(userId: string): Promise<{
74
+ deleted: boolean;
75
+ }>;
76
+ cleanup(): Promise<CleanupResult>;
77
+ private apiRequest;
78
+ createOrg(options: CreateTestOrgOptions): Promise<TestOrg>;
79
+ createRole(options: CreateTestRoleOptions): Promise<TestRole>;
80
+ addOrgMember(orgId: string, userId: string, roleKey: string): Promise<TestOrgMember>;
81
+ deleteOrg(orgId: string): Promise<{
82
+ deleted: boolean;
83
+ }>;
84
+ deleteRole(roleId: string): Promise<{
85
+ deleted: boolean;
86
+ }>;
87
+ cleanupOrgs(): Promise<{
88
+ deleted: number;
89
+ }>;
90
+ cleanupRoles(): Promise<{
91
+ deleted: number;
92
+ }>;
93
+ }
94
+
95
+ export { type AuthGateTestConfig as A, type CreateTestUserOptions as C, type TestUser as T, type CleanupResult as a, AuthGateTest as b, type TestSession as c, type CreateTestOrgOptions as d, type CreateTestRoleOptions as e, type TestOrg as f, type TestOrgMember as g, type TestRole as h };
package/dist/cypress.cjs CHANGED
@@ -78,6 +78,116 @@ var AuthGateTest = class {
78
78
  async cleanup() {
79
79
  return this.request("DELETE", "/users");
80
80
  }
81
+ async apiRequest(method, path, body) {
82
+ var _a;
83
+ const url = `${this.baseUrl}/api/v1${path}`;
84
+ const res = await fetch(url, {
85
+ method,
86
+ headers: {
87
+ "Content-Type": "application/json",
88
+ Authorization: `Bearer ${this.apiKey}`
89
+ },
90
+ body: body ? JSON.stringify(body) : void 0
91
+ });
92
+ if (!res.ok) {
93
+ const error = await res.json().catch(() => ({ error: res.statusText }));
94
+ throw new Error(
95
+ `AuthGate API error (${res.status}): ${(_a = error.error) != null ? _a : res.statusText}`
96
+ );
97
+ }
98
+ return res.json();
99
+ }
100
+ async createOrg(options) {
101
+ var _a, _b, _c;
102
+ const res = await this.apiRequest(
103
+ "POST",
104
+ "/orgs",
105
+ {
106
+ name: options.name,
107
+ slug: options.slug,
108
+ max_members: options.maxMembers,
109
+ metadata: options.metadata
110
+ }
111
+ );
112
+ const org = res.organization;
113
+ return {
114
+ id: org.id,
115
+ name: org.name,
116
+ slug: org.slug,
117
+ imageUrl: (_a = org.image_url) != null ? _a : null,
118
+ maxMembers: (_b = org.max_members) != null ? _b : null,
119
+ metadata: (_c = org.metadata) != null ? _c : null,
120
+ createdAt: org.created_at
121
+ };
122
+ }
123
+ async createRole(options) {
124
+ var _a, _b, _c;
125
+ const res = await this.apiRequest(
126
+ "POST",
127
+ "/roles",
128
+ {
129
+ key: options.key,
130
+ name: options.name,
131
+ description: options.description,
132
+ is_default: options.isDefault,
133
+ permissions: options.permissions
134
+ }
135
+ );
136
+ return {
137
+ id: res.id,
138
+ key: res.key,
139
+ name: res.name,
140
+ description: (_a = res.description) != null ? _a : null,
141
+ isDefault: (_b = res.is_default) != null ? _b : false,
142
+ permissions: (_c = res.permissions) != null ? _c : [],
143
+ createdAt: res.created_at
144
+ };
145
+ }
146
+ async addOrgMember(orgId, userId, roleKey) {
147
+ const res = await this.apiRequest(
148
+ "POST",
149
+ `/orgs/${orgId}/members`,
150
+ {
151
+ end_user_id: userId,
152
+ role_key: roleKey
153
+ }
154
+ );
155
+ return {
156
+ id: res.id,
157
+ organizationId: res.organization_id,
158
+ endUserId: res.end_user_id,
159
+ roleKey: res.role_key,
160
+ createdAt: res.created_at
161
+ };
162
+ }
163
+ async deleteOrg(orgId) {
164
+ return this.apiRequest("DELETE", `/orgs/${orgId}`);
165
+ }
166
+ async deleteRole(roleId) {
167
+ return this.apiRequest("DELETE", `/roles/${roleId}`);
168
+ }
169
+ async cleanupOrgs() {
170
+ var _a;
171
+ const res = await this.apiRequest("GET", "/orgs");
172
+ const orgs = (_a = res.organizations) != null ? _a : [];
173
+ let deleted = 0;
174
+ for (const org of orgs) {
175
+ await this.deleteOrg(org.id);
176
+ deleted++;
177
+ }
178
+ return { deleted };
179
+ }
180
+ async cleanupRoles() {
181
+ var _a;
182
+ const res = await this.apiRequest("GET", "/roles");
183
+ const roles = (_a = res.roles) != null ? _a : [];
184
+ let deleted = 0;
185
+ for (const role of roles) {
186
+ await this.deleteRole(role.id);
187
+ deleted++;
188
+ }
189
+ return { deleted };
190
+ }
81
191
  };
82
192
 
83
193
  // src/cypress.ts
@@ -1,5 +1,5 @@
1
- import { C as CreateTestUserOptions, T as TestUser, a as CleanupResult, A as AuthGateTestConfig } from './client-DdLppI95.cjs';
2
- export { b as AuthGateTest, c as TestSession } from './client-DdLppI95.cjs';
1
+ import { C as CreateTestUserOptions, T as TestUser, a as CleanupResult, A as AuthGateTestConfig } from './client-BOr5JC3V.cjs';
2
+ export { b as AuthGateTest, c as TestSession } from './client-BOr5JC3V.cjs';
3
3
 
4
4
  /**
5
5
  * Options for setting up the AuthGate Cypress plugin.
package/dist/cypress.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as CreateTestUserOptions, T as TestUser, a as CleanupResult, A as AuthGateTestConfig } from './client-DdLppI95.js';
2
- export { b as AuthGateTest, c as TestSession } from './client-DdLppI95.js';
1
+ import { C as CreateTestUserOptions, T as TestUser, a as CleanupResult, A as AuthGateTestConfig } from './client-BOr5JC3V.js';
2
+ export { b as AuthGateTest, c as TestSession } from './client-BOr5JC3V.js';
3
3
 
4
4
  /**
5
5
  * Options for setting up the AuthGate Cypress plugin.
package/dist/cypress.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  AuthGateTest
3
- } from "./chunk-VFBHRWNY.mjs";
3
+ } from "./chunk-OV3AFWVB.mjs";
4
4
 
5
5
  // src/cypress.ts
6
6
  import { createAuthGateClient } from "@auth-gate/core";
package/dist/index.cjs CHANGED
@@ -78,6 +78,116 @@ var AuthGateTest = class {
78
78
  async cleanup() {
79
79
  return this.request("DELETE", "/users");
80
80
  }
81
+ async apiRequest(method, path, body) {
82
+ var _a;
83
+ const url = `${this.baseUrl}/api/v1${path}`;
84
+ const res = await fetch(url, {
85
+ method,
86
+ headers: {
87
+ "Content-Type": "application/json",
88
+ Authorization: `Bearer ${this.apiKey}`
89
+ },
90
+ body: body ? JSON.stringify(body) : void 0
91
+ });
92
+ if (!res.ok) {
93
+ const error = await res.json().catch(() => ({ error: res.statusText }));
94
+ throw new Error(
95
+ `AuthGate API error (${res.status}): ${(_a = error.error) != null ? _a : res.statusText}`
96
+ );
97
+ }
98
+ return res.json();
99
+ }
100
+ async createOrg(options) {
101
+ var _a, _b, _c;
102
+ const res = await this.apiRequest(
103
+ "POST",
104
+ "/orgs",
105
+ {
106
+ name: options.name,
107
+ slug: options.slug,
108
+ max_members: options.maxMembers,
109
+ metadata: options.metadata
110
+ }
111
+ );
112
+ const org = res.organization;
113
+ return {
114
+ id: org.id,
115
+ name: org.name,
116
+ slug: org.slug,
117
+ imageUrl: (_a = org.image_url) != null ? _a : null,
118
+ maxMembers: (_b = org.max_members) != null ? _b : null,
119
+ metadata: (_c = org.metadata) != null ? _c : null,
120
+ createdAt: org.created_at
121
+ };
122
+ }
123
+ async createRole(options) {
124
+ var _a, _b, _c;
125
+ const res = await this.apiRequest(
126
+ "POST",
127
+ "/roles",
128
+ {
129
+ key: options.key,
130
+ name: options.name,
131
+ description: options.description,
132
+ is_default: options.isDefault,
133
+ permissions: options.permissions
134
+ }
135
+ );
136
+ return {
137
+ id: res.id,
138
+ key: res.key,
139
+ name: res.name,
140
+ description: (_a = res.description) != null ? _a : null,
141
+ isDefault: (_b = res.is_default) != null ? _b : false,
142
+ permissions: (_c = res.permissions) != null ? _c : [],
143
+ createdAt: res.created_at
144
+ };
145
+ }
146
+ async addOrgMember(orgId, userId, roleKey) {
147
+ const res = await this.apiRequest(
148
+ "POST",
149
+ `/orgs/${orgId}/members`,
150
+ {
151
+ end_user_id: userId,
152
+ role_key: roleKey
153
+ }
154
+ );
155
+ return {
156
+ id: res.id,
157
+ organizationId: res.organization_id,
158
+ endUserId: res.end_user_id,
159
+ roleKey: res.role_key,
160
+ createdAt: res.created_at
161
+ };
162
+ }
163
+ async deleteOrg(orgId) {
164
+ return this.apiRequest("DELETE", `/orgs/${orgId}`);
165
+ }
166
+ async deleteRole(roleId) {
167
+ return this.apiRequest("DELETE", `/roles/${roleId}`);
168
+ }
169
+ async cleanupOrgs() {
170
+ var _a;
171
+ const res = await this.apiRequest("GET", "/orgs");
172
+ const orgs = (_a = res.organizations) != null ? _a : [];
173
+ let deleted = 0;
174
+ for (const org of orgs) {
175
+ await this.deleteOrg(org.id);
176
+ deleted++;
177
+ }
178
+ return { deleted };
179
+ }
180
+ async cleanupRoles() {
181
+ var _a;
182
+ const res = await this.apiRequest("GET", "/roles");
183
+ const roles = (_a = res.roles) != null ? _a : [];
184
+ let deleted = 0;
185
+ for (const role of roles) {
186
+ await this.deleteRole(role.id);
187
+ deleted++;
188
+ }
189
+ return { deleted };
190
+ }
81
191
  };
82
192
  // Annotate the CommonJS export names for ESM import in node:
83
193
  0 && (module.exports = {
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- export { b as AuthGateTest, A as AuthGateTestConfig, a as CleanupResult, C as CreateTestUserOptions, c as TestSession, T as TestUser } from './client-DdLppI95.cjs';
1
+ export { b as AuthGateTest, A as AuthGateTestConfig, a as CleanupResult, d as CreateTestOrgOptions, e as CreateTestRoleOptions, C as CreateTestUserOptions, f as TestOrg, g as TestOrgMember, h as TestRole, c as TestSession, T as TestUser } from './client-BOr5JC3V.cjs';
2
2
 
3
3
  declare const TEST_EMAIL_DOMAIN = "test.authgate.dev";
4
4
  declare const TEST_OTP_CODE = "424242";
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { b as AuthGateTest, A as AuthGateTestConfig, a as CleanupResult, C as CreateTestUserOptions, c as TestSession, T as TestUser } from './client-DdLppI95.js';
1
+ export { b as AuthGateTest, A as AuthGateTestConfig, a as CleanupResult, d as CreateTestOrgOptions, e as CreateTestRoleOptions, C as CreateTestUserOptions, f as TestOrg, g as TestOrgMember, h as TestRole, c as TestSession, T as TestUser } from './client-BOr5JC3V.js';
2
2
 
3
3
  declare const TEST_EMAIL_DOMAIN = "test.authgate.dev";
4
4
  declare const TEST_OTP_CODE = "424242";
package/dist/index.mjs CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  AuthGateTest,
3
3
  TEST_EMAIL_DOMAIN,
4
4
  TEST_OTP_CODE
5
- } from "./chunk-VFBHRWNY.mjs";
5
+ } from "./chunk-OV3AFWVB.mjs";
6
6
  export {
7
7
  AuthGateTest,
8
8
  TEST_EMAIL_DOMAIN,
@@ -91,6 +91,116 @@ var AuthGateTest = class {
91
91
  async cleanup() {
92
92
  return this.request("DELETE", "/users");
93
93
  }
94
+ async apiRequest(method, path, body) {
95
+ var _a;
96
+ const url = `${this.baseUrl}/api/v1${path}`;
97
+ const res = await fetch(url, {
98
+ method,
99
+ headers: {
100
+ "Content-Type": "application/json",
101
+ Authorization: `Bearer ${this.apiKey}`
102
+ },
103
+ body: body ? JSON.stringify(body) : void 0
104
+ });
105
+ if (!res.ok) {
106
+ const error = await res.json().catch(() => ({ error: res.statusText }));
107
+ throw new Error(
108
+ `AuthGate API error (${res.status}): ${(_a = error.error) != null ? _a : res.statusText}`
109
+ );
110
+ }
111
+ return res.json();
112
+ }
113
+ async createOrg(options) {
114
+ var _a, _b, _c;
115
+ const res = await this.apiRequest(
116
+ "POST",
117
+ "/orgs",
118
+ {
119
+ name: options.name,
120
+ slug: options.slug,
121
+ max_members: options.maxMembers,
122
+ metadata: options.metadata
123
+ }
124
+ );
125
+ const org = res.organization;
126
+ return {
127
+ id: org.id,
128
+ name: org.name,
129
+ slug: org.slug,
130
+ imageUrl: (_a = org.image_url) != null ? _a : null,
131
+ maxMembers: (_b = org.max_members) != null ? _b : null,
132
+ metadata: (_c = org.metadata) != null ? _c : null,
133
+ createdAt: org.created_at
134
+ };
135
+ }
136
+ async createRole(options) {
137
+ var _a, _b, _c;
138
+ const res = await this.apiRequest(
139
+ "POST",
140
+ "/roles",
141
+ {
142
+ key: options.key,
143
+ name: options.name,
144
+ description: options.description,
145
+ is_default: options.isDefault,
146
+ permissions: options.permissions
147
+ }
148
+ );
149
+ return {
150
+ id: res.id,
151
+ key: res.key,
152
+ name: res.name,
153
+ description: (_a = res.description) != null ? _a : null,
154
+ isDefault: (_b = res.is_default) != null ? _b : false,
155
+ permissions: (_c = res.permissions) != null ? _c : [],
156
+ createdAt: res.created_at
157
+ };
158
+ }
159
+ async addOrgMember(orgId, userId, roleKey) {
160
+ const res = await this.apiRequest(
161
+ "POST",
162
+ `/orgs/${orgId}/members`,
163
+ {
164
+ end_user_id: userId,
165
+ role_key: roleKey
166
+ }
167
+ );
168
+ return {
169
+ id: res.id,
170
+ organizationId: res.organization_id,
171
+ endUserId: res.end_user_id,
172
+ roleKey: res.role_key,
173
+ createdAt: res.created_at
174
+ };
175
+ }
176
+ async deleteOrg(orgId) {
177
+ return this.apiRequest("DELETE", `/orgs/${orgId}`);
178
+ }
179
+ async deleteRole(roleId) {
180
+ return this.apiRequest("DELETE", `/roles/${roleId}`);
181
+ }
182
+ async cleanupOrgs() {
183
+ var _a;
184
+ const res = await this.apiRequest("GET", "/orgs");
185
+ const orgs = (_a = res.organizations) != null ? _a : [];
186
+ let deleted = 0;
187
+ for (const org of orgs) {
188
+ await this.deleteOrg(org.id);
189
+ deleted++;
190
+ }
191
+ return { deleted };
192
+ }
193
+ async cleanupRoles() {
194
+ var _a;
195
+ const res = await this.apiRequest("GET", "/roles");
196
+ const roles = (_a = res.roles) != null ? _a : [];
197
+ let deleted = 0;
198
+ for (const role of roles) {
199
+ await this.deleteRole(role.id);
200
+ deleted++;
201
+ }
202
+ return { deleted };
203
+ }
94
204
  };
95
205
 
96
206
  // src/playwright.ts
@@ -1,5 +1,5 @@
1
- import { A as AuthGateTestConfig, C as CreateTestUserOptions, T as TestUser } from './client-DdLppI95.cjs';
2
- export { b as AuthGateTest, c as TestSession } from './client-DdLppI95.cjs';
1
+ import { A as AuthGateTestConfig, C as CreateTestUserOptions, T as TestUser } from './client-BOr5JC3V.cjs';
2
+ export { b as AuthGateTest, c as TestSession } from './client-BOr5JC3V.cjs';
3
3
 
4
4
  interface AuthGateSetupOptions extends AuthGateTestConfig {
5
5
  cleanupOnStart?: boolean;
@@ -1,5 +1,5 @@
1
- import { A as AuthGateTestConfig, C as CreateTestUserOptions, T as TestUser } from './client-DdLppI95.js';
2
- export { b as AuthGateTest, c as TestSession } from './client-DdLppI95.js';
1
+ import { A as AuthGateTestConfig, C as CreateTestUserOptions, T as TestUser } from './client-BOr5JC3V.js';
2
+ export { b as AuthGateTest, c as TestSession } from './client-BOr5JC3V.js';
3
3
 
4
4
  interface AuthGateSetupOptions extends AuthGateTestConfig {
5
5
  cleanupOnStart?: boolean;
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  AuthGateTest,
3
3
  __require
4
- } from "./chunk-VFBHRWNY.mjs";
4
+ } from "./chunk-OV3AFWVB.mjs";
5
5
 
6
6
  // src/playwright.ts
7
7
  import { createAuthGateClient } from "@auth-gate/core";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@auth-gate/testing",
3
- "version": "0.7.1",
3
+ "version": "0.8.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -26,7 +26,7 @@
26
26
  "dist"
27
27
  ],
28
28
  "dependencies": {
29
- "@auth-gate/core": "0.7.1"
29
+ "@auth-gate/core": "0.8.0"
30
30
  },
31
31
  "peerDependencies": {
32
32
  "@playwright/test": ">=1.40",
@@ -1,67 +0,0 @@
1
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
- }) : x)(function(x) {
4
- if (typeof require !== "undefined") return require.apply(this, arguments);
5
- throw Error('Dynamic require of "' + x + '" is not supported');
6
- });
7
-
8
- // src/constants.ts
9
- var TEST_EMAIL_DOMAIN = "test.authgate.dev";
10
- var TEST_OTP_CODE = "424242";
11
-
12
- // src/client.ts
13
- var AuthGateTest = class {
14
- constructor(config) {
15
- if (!config.apiKey) throw new Error("apiKey is required");
16
- if (!config.baseUrl) throw new Error("baseUrl is required");
17
- this.apiKey = config.apiKey;
18
- this.baseUrl = config.baseUrl.replace(/\/$/, "");
19
- }
20
- async request(method, path, body) {
21
- var _a;
22
- const url = `${this.baseUrl}/api/v1/testing${path}`;
23
- const res = await fetch(url, {
24
- method,
25
- headers: {
26
- "Content-Type": "application/json",
27
- Authorization: `Bearer ${this.apiKey}`
28
- },
29
- body: body ? JSON.stringify(body) : void 0
30
- });
31
- if (!res.ok) {
32
- const error = await res.json().catch(() => ({ error: res.statusText }));
33
- throw new Error(
34
- `AuthGate Testing API error (${res.status}): ${(_a = error.error) != null ? _a : res.statusText}`
35
- );
36
- }
37
- return res.json();
38
- }
39
- async createUser(options) {
40
- var _a;
41
- if (!options.email.endsWith(`@${TEST_EMAIL_DOMAIN}`)) {
42
- throw new Error(`Email must end with @${TEST_EMAIL_DOMAIN}`);
43
- }
44
- return this.request("POST", "/users", {
45
- email: options.email,
46
- password: options.password,
47
- name: options.name,
48
- emailVerified: (_a = options.emailVerified) != null ? _a : true
49
- });
50
- }
51
- async createSession(userId) {
52
- return this.request("POST", "/sessions", { userId });
53
- }
54
- async deleteUser(userId) {
55
- return this.request("DELETE", `/users/${userId}`);
56
- }
57
- async cleanup() {
58
- return this.request("DELETE", "/users");
59
- }
60
- };
61
-
62
- export {
63
- __require,
64
- TEST_EMAIL_DOMAIN,
65
- TEST_OTP_CODE,
66
- AuthGateTest
67
- };
@@ -1,41 +0,0 @@
1
- interface AuthGateTestConfig {
2
- apiKey: string;
3
- baseUrl: string;
4
- }
5
- interface CreateTestUserOptions {
6
- email: string;
7
- password: string;
8
- name?: string;
9
- emailVerified?: boolean;
10
- }
11
- interface TestUser {
12
- id: string;
13
- email: string;
14
- name: string | null;
15
- token: string;
16
- refreshToken: string;
17
- expiresAt: string;
18
- }
19
- interface TestSession {
20
- token: string;
21
- refreshToken: string;
22
- expiresAt: string;
23
- }
24
- interface CleanupResult {
25
- deleted: number;
26
- }
27
-
28
- declare class AuthGateTest {
29
- private apiKey;
30
- private baseUrl;
31
- constructor(config: AuthGateTestConfig);
32
- private request;
33
- createUser(options: CreateTestUserOptions): Promise<TestUser>;
34
- createSession(userId: string): Promise<TestSession>;
35
- deleteUser(userId: string): Promise<{
36
- deleted: boolean;
37
- }>;
38
- cleanup(): Promise<CleanupResult>;
39
- }
40
-
41
- export { type AuthGateTestConfig as A, type CreateTestUserOptions as C, type TestUser as T, type CleanupResult as a, AuthGateTest as b, type TestSession as c };
@@ -1,41 +0,0 @@
1
- interface AuthGateTestConfig {
2
- apiKey: string;
3
- baseUrl: string;
4
- }
5
- interface CreateTestUserOptions {
6
- email: string;
7
- password: string;
8
- name?: string;
9
- emailVerified?: boolean;
10
- }
11
- interface TestUser {
12
- id: string;
13
- email: string;
14
- name: string | null;
15
- token: string;
16
- refreshToken: string;
17
- expiresAt: string;
18
- }
19
- interface TestSession {
20
- token: string;
21
- refreshToken: string;
22
- expiresAt: string;
23
- }
24
- interface CleanupResult {
25
- deleted: number;
26
- }
27
-
28
- declare class AuthGateTest {
29
- private apiKey;
30
- private baseUrl;
31
- constructor(config: AuthGateTestConfig);
32
- private request;
33
- createUser(options: CreateTestUserOptions): Promise<TestUser>;
34
- createSession(userId: string): Promise<TestSession>;
35
- deleteUser(userId: string): Promise<{
36
- deleted: boolean;
37
- }>;
38
- cleanup(): Promise<CleanupResult>;
39
- }
40
-
41
- export { type AuthGateTestConfig as A, type CreateTestUserOptions as C, type TestUser as T, type CleanupResult as a, AuthGateTest as b, type TestSession as c };