@omnibase/core-js 0.1.2 → 0.1.4

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,18 @@
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 __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+
16
+ // src/auth/index.ts
17
+ var auth_exports = {};
18
+ module.exports = __toCommonJS(auth_exports);
@@ -0,0 +1,103 @@
1
+ import { LoginFlow as LoginFlow$1, RecoveryFlow as RecoveryFlow$1, VerificationFlow as VerificationFlow$1, RegistrationFlow as RegistrationFlow$1, SettingsFlow as SettingsFlow$1, SessionAuthenticationMethod, AuthenticatorAssuranceLevel, SessionDevice, Identity } from '@ory/client-fetch';
2
+
3
+ type FlowType = LoginFlow | RecoveryFlow | VerificationFlow | RegistrationFlow | SettingsFlow;
4
+ /**
5
+ * This object represents a login flow. A login flow is initiated at the "Initiate Login API / Browser Flow" endpoint by a client.
6
+ *
7
+ * Once a login flow is completed successfully, a session cookie or session token will be issued.
8
+ */
9
+ type LoginFlow = LoginFlow$1;
10
+ /**
11
+ * This flow is used when an identity wants to recover their account.
12
+ */
13
+ type RecoveryFlow = RecoveryFlow$1;
14
+ /**
15
+ * Used to verify an out-of-band communication channel such as an email address or a phone number.
16
+ */
17
+ type VerificationFlow = VerificationFlow$1;
18
+ /**
19
+ * Used when a user is registering an account
20
+ */
21
+ type RegistrationFlow = RegistrationFlow$1;
22
+ /**
23
+ * This flow is used when an identity wants to update settings (e.g. profile data, passwords, ...) in a selfservice manner.
24
+ */
25
+ type SettingsFlow = SettingsFlow$1;
26
+ /**
27
+ * A Session
28
+ * @export
29
+ * @interface Session
30
+ */
31
+ type Session = {
32
+ /**
33
+ * Active state. If false the session is no longer active.
34
+ * @type {boolean}
35
+ * @memberof Session
36
+ */
37
+ active?: boolean;
38
+ /**
39
+ * The Session Authentication Timestamp
40
+ *
41
+ * When this session was authenticated at. If multi-factor authentication was used this
42
+ * is the time when the last factor was authenticated (e.g. the TOTP code challenge was completed).
43
+ * @type {Date}
44
+ * @memberof Session
45
+ */
46
+ authenticated_at?: Date;
47
+ /**
48
+ * A list of authenticators which were used to authenticate the session.
49
+ * @type {Array<SessionAuthenticationMethod>}
50
+ * @memberof Session
51
+ */
52
+ authentication_methods?: Array<SessionAuthenticationMethod>;
53
+ /**
54
+ *
55
+ * @type {AuthenticatorAssuranceLevel}
56
+ * @memberof Session
57
+ */
58
+ authenticator_assurance_level?: AuthenticatorAssuranceLevel;
59
+ /**
60
+ * Devices has history of all endpoints where the session was used
61
+ * @type {Array<SessionDevice>}
62
+ * @memberof Session
63
+ */
64
+ devices?: Array<SessionDevice>;
65
+ /**
66
+ * The Session Expiry
67
+ *
68
+ * When this session expires at.
69
+ * @type {Date}
70
+ * @memberof Session
71
+ */
72
+ expires_at?: Date;
73
+ /**
74
+ * Session ID
75
+ * @type {string}
76
+ * @memberof Session
77
+ */
78
+ id: string;
79
+ /**
80
+ *
81
+ * @type {Identity}
82
+ * @memberof Session
83
+ */
84
+ identity?: Identity;
85
+ /**
86
+ * The Session Issuance Timestamp
87
+ *
88
+ * When this session was issued at. Usually equal or close to `authenticated_at`.
89
+ * @type {Date}
90
+ * @memberof Session
91
+ */
92
+ issued_at?: Date;
93
+ /**
94
+ * Tokenized is the tokenized (e.g. JWT) version of the session.
95
+ *
96
+ * It is only set when the `tokenize_as` query parameter was set to a valid tokenize template during calls to `/session/whoami`.
97
+ * @type {string}
98
+ * @memberof Session
99
+ */
100
+ tokenized?: string;
101
+ };
102
+
103
+ export type { FlowType, LoginFlow, RecoveryFlow, RegistrationFlow, Session, SettingsFlow, VerificationFlow };
@@ -0,0 +1,103 @@
1
+ import { LoginFlow as LoginFlow$1, RecoveryFlow as RecoveryFlow$1, VerificationFlow as VerificationFlow$1, RegistrationFlow as RegistrationFlow$1, SettingsFlow as SettingsFlow$1, SessionAuthenticationMethod, AuthenticatorAssuranceLevel, SessionDevice, Identity } from '@ory/client-fetch';
2
+
3
+ type FlowType = LoginFlow | RecoveryFlow | VerificationFlow | RegistrationFlow | SettingsFlow;
4
+ /**
5
+ * This object represents a login flow. A login flow is initiated at the "Initiate Login API / Browser Flow" endpoint by a client.
6
+ *
7
+ * Once a login flow is completed successfully, a session cookie or session token will be issued.
8
+ */
9
+ type LoginFlow = LoginFlow$1;
10
+ /**
11
+ * This flow is used when an identity wants to recover their account.
12
+ */
13
+ type RecoveryFlow = RecoveryFlow$1;
14
+ /**
15
+ * Used to verify an out-of-band communication channel such as an email address or a phone number.
16
+ */
17
+ type VerificationFlow = VerificationFlow$1;
18
+ /**
19
+ * Used when a user is registering an account
20
+ */
21
+ type RegistrationFlow = RegistrationFlow$1;
22
+ /**
23
+ * This flow is used when an identity wants to update settings (e.g. profile data, passwords, ...) in a selfservice manner.
24
+ */
25
+ type SettingsFlow = SettingsFlow$1;
26
+ /**
27
+ * A Session
28
+ * @export
29
+ * @interface Session
30
+ */
31
+ type Session = {
32
+ /**
33
+ * Active state. If false the session is no longer active.
34
+ * @type {boolean}
35
+ * @memberof Session
36
+ */
37
+ active?: boolean;
38
+ /**
39
+ * The Session Authentication Timestamp
40
+ *
41
+ * When this session was authenticated at. If multi-factor authentication was used this
42
+ * is the time when the last factor was authenticated (e.g. the TOTP code challenge was completed).
43
+ * @type {Date}
44
+ * @memberof Session
45
+ */
46
+ authenticated_at?: Date;
47
+ /**
48
+ * A list of authenticators which were used to authenticate the session.
49
+ * @type {Array<SessionAuthenticationMethod>}
50
+ * @memberof Session
51
+ */
52
+ authentication_methods?: Array<SessionAuthenticationMethod>;
53
+ /**
54
+ *
55
+ * @type {AuthenticatorAssuranceLevel}
56
+ * @memberof Session
57
+ */
58
+ authenticator_assurance_level?: AuthenticatorAssuranceLevel;
59
+ /**
60
+ * Devices has history of all endpoints where the session was used
61
+ * @type {Array<SessionDevice>}
62
+ * @memberof Session
63
+ */
64
+ devices?: Array<SessionDevice>;
65
+ /**
66
+ * The Session Expiry
67
+ *
68
+ * When this session expires at.
69
+ * @type {Date}
70
+ * @memberof Session
71
+ */
72
+ expires_at?: Date;
73
+ /**
74
+ * Session ID
75
+ * @type {string}
76
+ * @memberof Session
77
+ */
78
+ id: string;
79
+ /**
80
+ *
81
+ * @type {Identity}
82
+ * @memberof Session
83
+ */
84
+ identity?: Identity;
85
+ /**
86
+ * The Session Issuance Timestamp
87
+ *
88
+ * When this session was issued at. Usually equal or close to `authenticated_at`.
89
+ * @type {Date}
90
+ * @memberof Session
91
+ */
92
+ issued_at?: Date;
93
+ /**
94
+ * Tokenized is the tokenized (e.g. JWT) version of the session.
95
+ *
96
+ * It is only set when the `tokenize_as` query parameter was set to a valid tokenize template during calls to `/session/whoami`.
97
+ * @type {string}
98
+ * @memberof Session
99
+ */
100
+ tokenized?: string;
101
+ };
102
+
103
+ export type { FlowType, LoginFlow, RecoveryFlow, RegistrationFlow, Session, SettingsFlow, VerificationFlow };
File without changes
package/dist/index.cjs CHANGED
@@ -3,10 +3,6 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
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
6
  var __copyProps = (to, from, except, desc) => {
11
7
  if (from && typeof from === "object" || typeof from === "function") {
12
8
  for (let key of __getOwnPropNames(from))
@@ -19,200 +15,4 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
15
 
20
16
  // src/index.ts
21
17
  var index_exports = {};
22
- __export(index_exports, {
23
- acceptTenantInvite: () => acceptTenantInvite,
24
- createClient: () => createClient,
25
- createTenant: () => createTenant,
26
- createTenantUserInvite: () => createTenantUserInvite,
27
- deleteTenant: () => deleteTenant,
28
- switchActiveTenant: () => switchActiveTenant
29
- });
30
18
  module.exports = __toCommonJS(index_exports);
31
-
32
- // src/database/client.ts
33
- var import_postgrest_js = require("@supabase/postgrest-js");
34
- var createClient = (url, anonKey, getCookie) => {
35
- const jwt = getCookie("postgrest_jwt") || anonKey;
36
- return new import_postgrest_js.PostgrestClient(url, {
37
- headers: {
38
- Authorization: `Bearer ${jwt}`
39
- }
40
- });
41
- };
42
-
43
- // src/tenants/switch-tenant.ts
44
- async function switchActiveTenant(tenantId) {
45
- const baseUrl = process.env.OMNIBASE_API_URL;
46
- if (!baseUrl) {
47
- throw new Error("OMNIBASE_API_URL is not configured");
48
- }
49
- const requestBody = {
50
- tenant_id: tenantId
51
- };
52
- try {
53
- const response = await fetch(`${baseUrl}/api/v1/tenants/switch-active`, {
54
- method: "PUT",
55
- headers: {
56
- "Content-Type": "application/json"
57
- },
58
- body: JSON.stringify(requestBody),
59
- credentials: "include"
60
- });
61
- if (!response.ok) {
62
- const errorData = await response.text();
63
- throw new Error(
64
- `Failed to switch tenant: ${response.status} - ${errorData}`
65
- );
66
- }
67
- const data = await response.json();
68
- return data;
69
- } catch (error) {
70
- console.error("Error switching active tenant:", error);
71
- throw error;
72
- }
73
- }
74
-
75
- // src/tenants/create-invite.ts
76
- async function createTenantUserInvite(tenantId, inviteData) {
77
- const baseUrl = process.env.OMNIBASE_API_URL;
78
- if (!baseUrl) {
79
- throw new Error("OMNIBASE_API_URL is not configured");
80
- }
81
- if (!tenantId) {
82
- throw new Error("Tenant ID is required");
83
- }
84
- if (!inviteData.email || !inviteData.role) {
85
- throw new Error("Email and role are required");
86
- }
87
- try {
88
- const response = await fetch(
89
- `${baseUrl}/api/v1/tenants/${tenantId}/invites`,
90
- {
91
- method: "POST",
92
- headers: {
93
- "Content-Type": "application/json"
94
- },
95
- body: JSON.stringify(inviteData),
96
- credentials: "include"
97
- }
98
- );
99
- if (!response.ok) {
100
- const errorData = await response.text();
101
- throw new Error(
102
- `Failed to create invite: ${response.status} - ${errorData}`
103
- );
104
- }
105
- const data = await response.json();
106
- return data;
107
- } catch (error) {
108
- console.error("Error creating tenant user invite:", error);
109
- throw error;
110
- }
111
- }
112
-
113
- // src/tenants/create-tenant.ts
114
- async function createTenant(tenantData) {
115
- const baseUrl = process.env.OMNIBASE_API_URL;
116
- if (!baseUrl) {
117
- throw new Error("OMNIBASE_API_URL is not configured");
118
- }
119
- if (!tenantData.name || !tenantData.user_id) {
120
- throw new Error("Name and user_id are required");
121
- }
122
- try {
123
- const response = await fetch(`${baseUrl}/api/v1/tenants`, {
124
- method: "POST",
125
- headers: {
126
- "Content-Type": "application/json"
127
- },
128
- body: JSON.stringify(tenantData),
129
- credentials: "include"
130
- });
131
- if (!response.ok) {
132
- const errorData = await response.text();
133
- throw new Error(
134
- `Failed to create tenant: ${response.status} - ${errorData}`
135
- );
136
- }
137
- const data = await response.json();
138
- return data;
139
- } catch (error) {
140
- console.error("Error creating tenant:", error);
141
- throw error;
142
- }
143
- }
144
-
145
- // src/tenants/accept-invite.ts
146
- async function acceptTenantInvite(token) {
147
- const baseUrl = process.env.OMNIBASE_API_URL;
148
- if (!baseUrl) {
149
- throw new Error("OMNIBASE_API_URL is not configured");
150
- }
151
- if (!token) {
152
- throw new Error("Invite token is required");
153
- }
154
- const requestBody = {
155
- token
156
- };
157
- try {
158
- const response = await fetch(`${baseUrl}/api/v1/tenants/invites/accept`, {
159
- method: "PUT",
160
- headers: {
161
- "Content-Type": "application/json"
162
- },
163
- body: JSON.stringify(requestBody),
164
- credentials: "include"
165
- });
166
- if (!response.ok) {
167
- const errorData = await response.text();
168
- throw new Error(
169
- `Failed to accept invite: ${response.status} - ${errorData}`
170
- );
171
- }
172
- const data = await response.json();
173
- return data;
174
- } catch (error) {
175
- console.error("Error accepting tenant invite:", error);
176
- throw error;
177
- }
178
- }
179
-
180
- // src/tenants/delete-tenant.ts
181
- async function deleteTenant(tenantId) {
182
- const baseUrl = process.env.OMNIBASE_API_URL;
183
- if (!baseUrl) {
184
- throw new Error("OMNIBASE_API_URL is not configured");
185
- }
186
- if (!tenantId) {
187
- throw new Error("Tenant ID is required");
188
- }
189
- try {
190
- const response = await fetch(`${baseUrl}/api/v1/tenants/${tenantId}`, {
191
- method: "DELETE",
192
- headers: {
193
- "Content-Type": "application/json"
194
- },
195
- credentials: "include"
196
- });
197
- if (!response.ok) {
198
- const errorData = await response.text();
199
- throw new Error(
200
- `Failed to delete tenant: ${response.status} - ${errorData}`
201
- );
202
- }
203
- const data = await response.json();
204
- return data;
205
- } catch (error) {
206
- console.error("Error deleting tenant:", error);
207
- throw error;
208
- }
209
- }
210
- // Annotate the CommonJS export names for ESM import in node:
211
- 0 && (module.exports = {
212
- acceptTenantInvite,
213
- createClient,
214
- createTenant,
215
- createTenantUserInvite,
216
- deleteTenant,
217
- switchActiveTenant
218
- });
package/dist/index.d.cts CHANGED
@@ -1,159 +1,3 @@
1
- import * as _supabase_postgrest_js from '@supabase/postgrest-js';
2
- import { PostgrestClient } from '@supabase/postgrest-js';
3
- import { LoginFlow as LoginFlow$1, RecoveryFlow as RecoveryFlow$1, VerificationFlow as VerificationFlow$1, RegistrationFlow as RegistrationFlow$1, SettingsFlow as SettingsFlow$1 } from '@ory/client-fetch';
4
-
5
- declare type GenericRelationship = {
6
- foreignKeyName: string;
7
- columns: string[];
8
- isOneToOne?: boolean;
9
- referencedRelation: string;
10
- referencedColumns: string[];
11
- };
12
- declare type GenericTable = {
13
- Row: Record<string, unknown>;
14
- Insert: Record<string, unknown>;
15
- Update: Record<string, unknown>;
16
- Relationships: GenericRelationship[];
17
- };
18
- declare type GenericUpdatableView = {
19
- Row: Record<string, unknown>;
20
- Insert: Record<string, unknown>;
21
- Update: Record<string, unknown>;
22
- Relationships: GenericRelationship[];
23
- };
24
- declare type GenericNonUpdatableView = {
25
- Row: Record<string, unknown>;
26
- Relationships: GenericRelationship[];
27
- };
28
- declare type GenericView = GenericUpdatableView | GenericNonUpdatableView;
29
- declare type GenericFunction = {
30
- Args: Record<string, unknown>;
31
- Returns: unknown;
32
- };
33
- declare type GenericSchema = {
34
- Tables: Record<string, GenericTable>;
35
- Views: Record<string, GenericView>;
36
- Functions: Record<string, GenericFunction>;
37
- };
38
-
39
- /**
40
- * PostgREST client.
41
- *
42
- * @typeParam
43
- * Database - Types for the schema from the type generator
44
- *
45
- * @typeParam
46
- * SchemaName - Postgres schema to switch to. Must be a string literal, the same one passed to the constructor. If the schema is not "public", this must be supplied manually.
47
- *
48
- * @param url - Your Postgres RESTapi url
49
- * @param anonKey - Your Postgres RESTapi anon JWT key
50
- * @param getCookie - Custom callback to get cookie by name
51
- * @returns
52
- */
53
- declare const createClient: <T = any>(url: string, anonKey: string, getCookie: (cookie: string) => string) => PostgrestClient<T, T extends {
54
- __InternalSupabase: infer I extends _supabase_postgrest_js.PostgrestClientOptions;
55
- } ? I : {}, "public" extends Exclude<keyof T, "__InternalSupabase"> ? Exclude<keyof T, "__InternalSupabase"> & "public" : string & Exclude<keyof T, "__InternalSupabase">, Omit<T, "__InternalSupabase">["public" extends Exclude<keyof T, "__InternalSupabase"> ? Exclude<keyof T, "__InternalSupabase"> & "public" : string & Exclude<keyof T, "__InternalSupabase">] extends GenericSchema ? Omit<T, "__InternalSupabase">["public" extends Exclude<keyof T, "__InternalSupabase"> ? Exclude<keyof T, "__InternalSupabase"> & "public" : string & Exclude<keyof T, "__InternalSupabase">] : any>;
56
-
57
- /**
58
- * Return type of the `acceptTenantInvite` function
59
- */
60
- type AcceptTenantInviteResponse = ApiResponse<{
61
- tenant_id: string;
62
- message: string;
63
- }>;
64
- /**
65
- * Accept a tenant invite using token
66
- * Calls PUT /api/v1/tenants/invites/accept
67
- */
68
- declare function acceptTenantInvite(token: string): Promise<ApiResponse<{
69
- tenant_id: string;
70
- message: string;
71
- }>>;
72
-
73
- /**
74
- * Return type of the `createTenantUserInvite` function
75
- */
76
- type CreateTenantUserInviteResponse = ApiResponse<{
77
- invite: TenantInvite;
78
- message: string;
79
- }>;
80
- /**
81
- * The TenantInvite Schema that maps directly to `auth.tenant_invites`
82
- */
83
- interface TenantInvite {
84
- id: string;
85
- tenant_id: string;
86
- email: string;
87
- role: string;
88
- token: string;
89
- inviter_id: string;
90
- expires_at: string;
91
- created_at: string;
92
- used_at?: string;
93
- }
94
- /**
95
- * Invite Data describing who the invite is going to `email` and their
96
- * role `role`
97
- */
98
- type CreateTenantUserInviteRequest = {
99
- email: string;
100
- role: string;
101
- };
102
- /**
103
- * Create a tenant user invite
104
- * Calls POST /api/v1/tenants/{id}/invites
105
- */
106
- declare function createTenantUserInvite(tenantId: string, inviteData: CreateTenantUserInviteRequest): Promise<CreateTenantUserInviteResponse>;
107
-
108
- /**
109
- * Return type of the `createTenant` function
110
- *
111
- * The `token` is the authenticated users `postgrest_jwt` cookie for RLS policies specific to the active tenant
112
- */
113
- type CreateTenantResponse = ApiResponse<{
114
- tenant: Tenant;
115
- message: string;
116
- token: string;
117
- }>;
118
- /**
119
- * The Tenant Schema that maps directly to `auth.tenants`
120
- */
121
- type Tenant = {
122
- id: string;
123
- name: string;
124
- stripe_customer_id: string;
125
- type: string;
126
- created_at: string;
127
- updated_at: string;
128
- };
129
- /**
130
- * The data required to create a tenant.
131
- */
132
- type CreateTenantRequest = {
133
- name: string;
134
- billing_email: string;
135
- user_id: string;
136
- };
137
- /**
138
- * Create a new tenant
139
- *
140
- * Calls POST /api/v1/tenants
141
- */
142
- declare function createTenant(tenantData: CreateTenantRequest): Promise<CreateTenantResponse>;
143
-
144
- /**
145
- * Return type of the `deleteTenant` function
146
- */
147
- type DeleteTenantResponse = ApiResponse<{
148
- message: string;
149
- }>;
150
- /**
151
- * Delete a tenant (only owners can delete)
152
- *
153
- * Calls DELETE /api/v1/tenants/{id}
154
- */
155
- declare function deleteTenant(tenantId: string): Promise<DeleteTenantResponse>;
156
-
157
1
  /**
158
2
  * Base API Response structure for API
159
3
  */
@@ -163,42 +7,4 @@ type ApiResponse<T> = {
163
7
  error?: string;
164
8
  };
165
9
 
166
- /**
167
- * Return type of the `switchActiveTenant` function
168
- */
169
- type SwitchActiveTenantResponse = ApiResponse<{
170
- token: string;
171
- message: string;
172
- }>;
173
- /**
174
- * Switch the user's active tenant
175
- *
176
- * Calls PUT /api/v1/tenants/switch-active
177
- */
178
- declare function switchActiveTenant(tenantId: string): Promise<SwitchActiveTenantResponse>;
179
-
180
- type FlowType = LoginFlow | RecoveryFlow | VerificationFlow | RegistrationFlow | SettingsFlow;
181
- /**
182
- * This object represents a login flow. A login flow is initiated at the "Initiate Login API / Browser Flow" endpoint by a client.
183
- *
184
- * Once a login flow is completed successfully, a session cookie or session token will be issued.
185
- */
186
- type LoginFlow = LoginFlow$1;
187
- /**
188
- * This flow is used when an identity wants to recover their account.
189
- */
190
- type RecoveryFlow = RecoveryFlow$1;
191
- /**
192
- * Used to verify an out-of-band communication channel such as an email address or a phone number.
193
- */
194
- type VerificationFlow = VerificationFlow$1;
195
- /**
196
- * Used when a user is registering an account
197
- */
198
- type RegistrationFlow = RegistrationFlow$1;
199
- /**
200
- * This flow is used when an identity wants to update settings (e.g. profile data, passwords, ...) in a selfservice manner.
201
- */
202
- type SettingsFlow = SettingsFlow$1;
203
-
204
- export { type AcceptTenantInviteResponse, type CreateTenantRequest, type CreateTenantResponse, type CreateTenantUserInviteRequest, type CreateTenantUserInviteResponse, type DeleteTenantResponse, type FlowType, type LoginFlow, type RecoveryFlow, type RegistrationFlow, type SettingsFlow, type SwitchActiveTenantResponse, type Tenant, type TenantInvite, type VerificationFlow, acceptTenantInvite, createClient, createTenant, createTenantUserInvite, deleteTenant, switchActiveTenant };
10
+ export type { ApiResponse };
package/dist/index.d.ts CHANGED
@@ -1,159 +1,3 @@
1
- import * as _supabase_postgrest_js from '@supabase/postgrest-js';
2
- import { PostgrestClient } from '@supabase/postgrest-js';
3
- import { LoginFlow as LoginFlow$1, RecoveryFlow as RecoveryFlow$1, VerificationFlow as VerificationFlow$1, RegistrationFlow as RegistrationFlow$1, SettingsFlow as SettingsFlow$1 } from '@ory/client-fetch';
4
-
5
- declare type GenericRelationship = {
6
- foreignKeyName: string;
7
- columns: string[];
8
- isOneToOne?: boolean;
9
- referencedRelation: string;
10
- referencedColumns: string[];
11
- };
12
- declare type GenericTable = {
13
- Row: Record<string, unknown>;
14
- Insert: Record<string, unknown>;
15
- Update: Record<string, unknown>;
16
- Relationships: GenericRelationship[];
17
- };
18
- declare type GenericUpdatableView = {
19
- Row: Record<string, unknown>;
20
- Insert: Record<string, unknown>;
21
- Update: Record<string, unknown>;
22
- Relationships: GenericRelationship[];
23
- };
24
- declare type GenericNonUpdatableView = {
25
- Row: Record<string, unknown>;
26
- Relationships: GenericRelationship[];
27
- };
28
- declare type GenericView = GenericUpdatableView | GenericNonUpdatableView;
29
- declare type GenericFunction = {
30
- Args: Record<string, unknown>;
31
- Returns: unknown;
32
- };
33
- declare type GenericSchema = {
34
- Tables: Record<string, GenericTable>;
35
- Views: Record<string, GenericView>;
36
- Functions: Record<string, GenericFunction>;
37
- };
38
-
39
- /**
40
- * PostgREST client.
41
- *
42
- * @typeParam
43
- * Database - Types for the schema from the type generator
44
- *
45
- * @typeParam
46
- * SchemaName - Postgres schema to switch to. Must be a string literal, the same one passed to the constructor. If the schema is not "public", this must be supplied manually.
47
- *
48
- * @param url - Your Postgres RESTapi url
49
- * @param anonKey - Your Postgres RESTapi anon JWT key
50
- * @param getCookie - Custom callback to get cookie by name
51
- * @returns
52
- */
53
- declare const createClient: <T = any>(url: string, anonKey: string, getCookie: (cookie: string) => string) => PostgrestClient<T, T extends {
54
- __InternalSupabase: infer I extends _supabase_postgrest_js.PostgrestClientOptions;
55
- } ? I : {}, "public" extends Exclude<keyof T, "__InternalSupabase"> ? Exclude<keyof T, "__InternalSupabase"> & "public" : string & Exclude<keyof T, "__InternalSupabase">, Omit<T, "__InternalSupabase">["public" extends Exclude<keyof T, "__InternalSupabase"> ? Exclude<keyof T, "__InternalSupabase"> & "public" : string & Exclude<keyof T, "__InternalSupabase">] extends GenericSchema ? Omit<T, "__InternalSupabase">["public" extends Exclude<keyof T, "__InternalSupabase"> ? Exclude<keyof T, "__InternalSupabase"> & "public" : string & Exclude<keyof T, "__InternalSupabase">] : any>;
56
-
57
- /**
58
- * Return type of the `acceptTenantInvite` function
59
- */
60
- type AcceptTenantInviteResponse = ApiResponse<{
61
- tenant_id: string;
62
- message: string;
63
- }>;
64
- /**
65
- * Accept a tenant invite using token
66
- * Calls PUT /api/v1/tenants/invites/accept
67
- */
68
- declare function acceptTenantInvite(token: string): Promise<ApiResponse<{
69
- tenant_id: string;
70
- message: string;
71
- }>>;
72
-
73
- /**
74
- * Return type of the `createTenantUserInvite` function
75
- */
76
- type CreateTenantUserInviteResponse = ApiResponse<{
77
- invite: TenantInvite;
78
- message: string;
79
- }>;
80
- /**
81
- * The TenantInvite Schema that maps directly to `auth.tenant_invites`
82
- */
83
- interface TenantInvite {
84
- id: string;
85
- tenant_id: string;
86
- email: string;
87
- role: string;
88
- token: string;
89
- inviter_id: string;
90
- expires_at: string;
91
- created_at: string;
92
- used_at?: string;
93
- }
94
- /**
95
- * Invite Data describing who the invite is going to `email` and their
96
- * role `role`
97
- */
98
- type CreateTenantUserInviteRequest = {
99
- email: string;
100
- role: string;
101
- };
102
- /**
103
- * Create a tenant user invite
104
- * Calls POST /api/v1/tenants/{id}/invites
105
- */
106
- declare function createTenantUserInvite(tenantId: string, inviteData: CreateTenantUserInviteRequest): Promise<CreateTenantUserInviteResponse>;
107
-
108
- /**
109
- * Return type of the `createTenant` function
110
- *
111
- * The `token` is the authenticated users `postgrest_jwt` cookie for RLS policies specific to the active tenant
112
- */
113
- type CreateTenantResponse = ApiResponse<{
114
- tenant: Tenant;
115
- message: string;
116
- token: string;
117
- }>;
118
- /**
119
- * The Tenant Schema that maps directly to `auth.tenants`
120
- */
121
- type Tenant = {
122
- id: string;
123
- name: string;
124
- stripe_customer_id: string;
125
- type: string;
126
- created_at: string;
127
- updated_at: string;
128
- };
129
- /**
130
- * The data required to create a tenant.
131
- */
132
- type CreateTenantRequest = {
133
- name: string;
134
- billing_email: string;
135
- user_id: string;
136
- };
137
- /**
138
- * Create a new tenant
139
- *
140
- * Calls POST /api/v1/tenants
141
- */
142
- declare function createTenant(tenantData: CreateTenantRequest): Promise<CreateTenantResponse>;
143
-
144
- /**
145
- * Return type of the `deleteTenant` function
146
- */
147
- type DeleteTenantResponse = ApiResponse<{
148
- message: string;
149
- }>;
150
- /**
151
- * Delete a tenant (only owners can delete)
152
- *
153
- * Calls DELETE /api/v1/tenants/{id}
154
- */
155
- declare function deleteTenant(tenantId: string): Promise<DeleteTenantResponse>;
156
-
157
1
  /**
158
2
  * Base API Response structure for API
159
3
  */
@@ -163,42 +7,4 @@ type ApiResponse<T> = {
163
7
  error?: string;
164
8
  };
165
9
 
166
- /**
167
- * Return type of the `switchActiveTenant` function
168
- */
169
- type SwitchActiveTenantResponse = ApiResponse<{
170
- token: string;
171
- message: string;
172
- }>;
173
- /**
174
- * Switch the user's active tenant
175
- *
176
- * Calls PUT /api/v1/tenants/switch-active
177
- */
178
- declare function switchActiveTenant(tenantId: string): Promise<SwitchActiveTenantResponse>;
179
-
180
- type FlowType = LoginFlow | RecoveryFlow | VerificationFlow | RegistrationFlow | SettingsFlow;
181
- /**
182
- * This object represents a login flow. A login flow is initiated at the "Initiate Login API / Browser Flow" endpoint by a client.
183
- *
184
- * Once a login flow is completed successfully, a session cookie or session token will be issued.
185
- */
186
- type LoginFlow = LoginFlow$1;
187
- /**
188
- * This flow is used when an identity wants to recover their account.
189
- */
190
- type RecoveryFlow = RecoveryFlow$1;
191
- /**
192
- * Used to verify an out-of-band communication channel such as an email address or a phone number.
193
- */
194
- type VerificationFlow = VerificationFlow$1;
195
- /**
196
- * Used when a user is registering an account
197
- */
198
- type RegistrationFlow = RegistrationFlow$1;
199
- /**
200
- * This flow is used when an identity wants to update settings (e.g. profile data, passwords, ...) in a selfservice manner.
201
- */
202
- type SettingsFlow = SettingsFlow$1;
203
-
204
- export { type AcceptTenantInviteResponse, type CreateTenantRequest, type CreateTenantResponse, type CreateTenantUserInviteRequest, type CreateTenantUserInviteResponse, type DeleteTenantResponse, type FlowType, type LoginFlow, type RecoveryFlow, type RegistrationFlow, type SettingsFlow, type SwitchActiveTenantResponse, type Tenant, type TenantInvite, type VerificationFlow, acceptTenantInvite, createClient, createTenant, createTenantUserInvite, deleteTenant, switchActiveTenant };
10
+ export type { ApiResponse };
package/dist/index.js CHANGED
@@ -1,186 +0,0 @@
1
- // src/database/client.ts
2
- import { PostgrestClient } from "@supabase/postgrest-js";
3
- var createClient = (url, anonKey, getCookie) => {
4
- const jwt = getCookie("postgrest_jwt") || anonKey;
5
- return new PostgrestClient(url, {
6
- headers: {
7
- Authorization: `Bearer ${jwt}`
8
- }
9
- });
10
- };
11
-
12
- // src/tenants/switch-tenant.ts
13
- async function switchActiveTenant(tenantId) {
14
- const baseUrl = process.env.OMNIBASE_API_URL;
15
- if (!baseUrl) {
16
- throw new Error("OMNIBASE_API_URL is not configured");
17
- }
18
- const requestBody = {
19
- tenant_id: tenantId
20
- };
21
- try {
22
- const response = await fetch(`${baseUrl}/api/v1/tenants/switch-active`, {
23
- method: "PUT",
24
- headers: {
25
- "Content-Type": "application/json"
26
- },
27
- body: JSON.stringify(requestBody),
28
- credentials: "include"
29
- });
30
- if (!response.ok) {
31
- const errorData = await response.text();
32
- throw new Error(
33
- `Failed to switch tenant: ${response.status} - ${errorData}`
34
- );
35
- }
36
- const data = await response.json();
37
- return data;
38
- } catch (error) {
39
- console.error("Error switching active tenant:", error);
40
- throw error;
41
- }
42
- }
43
-
44
- // src/tenants/create-invite.ts
45
- async function createTenantUserInvite(tenantId, inviteData) {
46
- const baseUrl = process.env.OMNIBASE_API_URL;
47
- if (!baseUrl) {
48
- throw new Error("OMNIBASE_API_URL is not configured");
49
- }
50
- if (!tenantId) {
51
- throw new Error("Tenant ID is required");
52
- }
53
- if (!inviteData.email || !inviteData.role) {
54
- throw new Error("Email and role are required");
55
- }
56
- try {
57
- const response = await fetch(
58
- `${baseUrl}/api/v1/tenants/${tenantId}/invites`,
59
- {
60
- method: "POST",
61
- headers: {
62
- "Content-Type": "application/json"
63
- },
64
- body: JSON.stringify(inviteData),
65
- credentials: "include"
66
- }
67
- );
68
- if (!response.ok) {
69
- const errorData = await response.text();
70
- throw new Error(
71
- `Failed to create invite: ${response.status} - ${errorData}`
72
- );
73
- }
74
- const data = await response.json();
75
- return data;
76
- } catch (error) {
77
- console.error("Error creating tenant user invite:", error);
78
- throw error;
79
- }
80
- }
81
-
82
- // src/tenants/create-tenant.ts
83
- async function createTenant(tenantData) {
84
- const baseUrl = process.env.OMNIBASE_API_URL;
85
- if (!baseUrl) {
86
- throw new Error("OMNIBASE_API_URL is not configured");
87
- }
88
- if (!tenantData.name || !tenantData.user_id) {
89
- throw new Error("Name and user_id are required");
90
- }
91
- try {
92
- const response = await fetch(`${baseUrl}/api/v1/tenants`, {
93
- method: "POST",
94
- headers: {
95
- "Content-Type": "application/json"
96
- },
97
- body: JSON.stringify(tenantData),
98
- credentials: "include"
99
- });
100
- if (!response.ok) {
101
- const errorData = await response.text();
102
- throw new Error(
103
- `Failed to create tenant: ${response.status} - ${errorData}`
104
- );
105
- }
106
- const data = await response.json();
107
- return data;
108
- } catch (error) {
109
- console.error("Error creating tenant:", error);
110
- throw error;
111
- }
112
- }
113
-
114
- // src/tenants/accept-invite.ts
115
- async function acceptTenantInvite(token) {
116
- const baseUrl = process.env.OMNIBASE_API_URL;
117
- if (!baseUrl) {
118
- throw new Error("OMNIBASE_API_URL is not configured");
119
- }
120
- if (!token) {
121
- throw new Error("Invite token is required");
122
- }
123
- const requestBody = {
124
- token
125
- };
126
- try {
127
- const response = await fetch(`${baseUrl}/api/v1/tenants/invites/accept`, {
128
- method: "PUT",
129
- headers: {
130
- "Content-Type": "application/json"
131
- },
132
- body: JSON.stringify(requestBody),
133
- credentials: "include"
134
- });
135
- if (!response.ok) {
136
- const errorData = await response.text();
137
- throw new Error(
138
- `Failed to accept invite: ${response.status} - ${errorData}`
139
- );
140
- }
141
- const data = await response.json();
142
- return data;
143
- } catch (error) {
144
- console.error("Error accepting tenant invite:", error);
145
- throw error;
146
- }
147
- }
148
-
149
- // src/tenants/delete-tenant.ts
150
- async function deleteTenant(tenantId) {
151
- const baseUrl = process.env.OMNIBASE_API_URL;
152
- if (!baseUrl) {
153
- throw new Error("OMNIBASE_API_URL is not configured");
154
- }
155
- if (!tenantId) {
156
- throw new Error("Tenant ID is required");
157
- }
158
- try {
159
- const response = await fetch(`${baseUrl}/api/v1/tenants/${tenantId}`, {
160
- method: "DELETE",
161
- headers: {
162
- "Content-Type": "application/json"
163
- },
164
- credentials: "include"
165
- });
166
- if (!response.ok) {
167
- const errorData = await response.text();
168
- throw new Error(
169
- `Failed to delete tenant: ${response.status} - ${errorData}`
170
- );
171
- }
172
- const data = await response.json();
173
- return data;
174
- } catch (error) {
175
- console.error("Error deleting tenant:", error);
176
- throw error;
177
- }
178
- }
179
- export {
180
- acceptTenantInvite,
181
- createClient,
182
- createTenant,
183
- createTenantUserInvite,
184
- deleteTenant,
185
- switchActiveTenant
186
- };
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@omnibase/core-js",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "OmniBase core Javascript SDK - framework agnostic",
5
5
  "files": [
6
6
  "dist/**/*"
7
7
  ],
8
8
  "type": "module",
9
9
  "scripts": {
10
- "build": "tsup src/database/index.ts src/tenants/index.ts src/auth/types.ts --format cjs,esm --dts",
10
+ "build": "tsup src/database/index.ts src/tenants/index.ts src/auth/index.ts --format cjs,esm --dts",
11
11
  "prepublishOnly": "npm run build"
12
12
  },
13
13
  "exports": {