@appcorp/stellar-solutions-modules 0.1.38 → 0.1.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appcorp/stellar-solutions-modules",
3
- "version": "0.1.38",
3
+ "version": "0.1.40",
4
4
  "scripts": {
5
5
  "automate": "./automate.sh",
6
6
  "build": "yarn clean && yarn build:ts && cp package.json lib && cp README.md lib && cp yarn.lock lib",
@@ -1,83 +1,6 @@
1
- /**
2
- * Supabase Client Configuration
3
- *
4
- * This module provides centralized Supabase client configuration and utilities.
5
- * Handles authentication, storage URLs, and client initialization with proper error handling.
6
- *
7
- * Features:
8
- * - Centralized Supabase client configuration
9
- * - Storage URL management for public and private buckets
10
- * - Environment variable validation
11
- * - Type-safe client creation
12
- * - Authentication persistence configuration
13
- *
14
- * Environment Variables Required:
15
- * - NEXT_PUBLIC_SUPABASE_URL: Supabase project URL
16
- * - NEXT_PUBLIC_SUPABASE_ANON_KEY: Supabase anonymous key
17
- * - NEXT_PUBLIC_SUPABASE_STORAGE_URL: Storage base URL
18
- * - NEXT_PUBLIC_SUPABASE_PRIVATE_BUCKET: Private bucket name
19
- * - NEXT_PUBLIC_SUPABASE_PUBLIC_BUCKET: Public bucket name
20
- */
21
- import { SupabaseClient } from "@supabase/supabase-js";
22
- /**
23
- * Storage bucket types for type safety
24
- */
25
- export type StorageBucketType = "public" | "private" | "authenticated";
26
- /**
27
- * Base URL for Supabase storage
28
- */
29
1
  export declare const supabaseStorageBaseUrl: string;
30
- /**
31
- * Private storage URL for authenticated users
32
- * Format: {storageBaseUrl}/authenticated/{privateBucket}
33
- */
34
2
  export declare const supabasePrivateStorageUrl: string;
35
- /**
36
- * Public storage URL for publicly accessible files
37
- * Format: {storageBaseUrl}/public/{publicBucket}
38
- */
39
3
  export declare const supabasePublicStorageUrl: string;
40
- /**
41
- * Main Supabase client instance
42
- * Configured with authentication persistence and optimized settings
43
- */
44
- export declare const supabaseClient: SupabaseClient;
45
- /**
46
- * Get storage URL for a specific bucket type
47
- * @param bucketType - Type of storage bucket
48
- * @returns Full storage URL for the bucket
49
- */
50
- export declare const getStorageUrl: (bucketType: StorageBucketType) => string;
51
- /**
52
- * Get public file URL from Supabase storage
53
- * @param bucket - Bucket name
54
- * @param filePath - Path to the file within the bucket
55
- * @returns Public URL for the file
56
- */
57
- export declare const getPublicFileUrl: (bucket: string, filePath: string) => string;
58
- /**
59
- * Get authenticated file URL from Supabase storage
60
- * @param bucket - Bucket name
61
- * @param filePath - Path to the file within the bucket
62
- * @returns Authenticated URL for the file
63
- */
64
- export declare const getAuthenticatedFileUrl: (bucket: string, filePath: string) => string;
65
- /**
66
- * Check if Supabase client is properly initialized
67
- * @returns True if client is initialized, false otherwise
68
- */
69
- export declare const isSupabaseClientReady: () => boolean;
70
- /**
71
- * Get current session from Supabase auth
72
- * @returns Current user session or null
73
- */
74
- export declare const getCurrentSession: () => Promise<import("@supabase/supabase-js").AuthSession | null>;
75
- /**
76
- * Check if user is authenticated
77
- * @returns True if user is authenticated, false otherwise
78
- */
79
- export declare const isAuthenticated: () => Promise<boolean>;
80
- /**
81
- * Re-export Supabase types for convenience
82
- */
83
- export type { SupabaseClient } from "@supabase/supabase-js";
4
+ export declare const supabaseUrl: string;
5
+ export declare const supabaseKey: string;
6
+ export declare const supabaseClient: import("@supabase/supabase-js").SupabaseClient<any, "public", "public", any, any>;
@@ -1,290 +1,15 @@
1
1
  "use strict";
2
- /**
3
- * Supabase Client Configuration
4
- *
5
- * This module provides centralized Supabase client configuration and utilities.
6
- * Handles authentication, storage URLs, and client initialization with proper error handling.
7
- *
8
- * Features:
9
- * - Centralized Supabase client configuration
10
- * - Storage URL management for public and private buckets
11
- * - Environment variable validation
12
- * - Type-safe client creation
13
- * - Authentication persistence configuration
14
- *
15
- * Environment Variables Required:
16
- * - NEXT_PUBLIC_SUPABASE_URL: Supabase project URL
17
- * - NEXT_PUBLIC_SUPABASE_ANON_KEY: Supabase anonymous key
18
- * - NEXT_PUBLIC_SUPABASE_STORAGE_URL: Storage base URL
19
- * - NEXT_PUBLIC_SUPABASE_PRIVATE_BUCKET: Private bucket name
20
- * - NEXT_PUBLIC_SUPABASE_PUBLIC_BUCKET: Public bucket name
21
- */
22
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
23
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
24
- return new (P || (P = Promise))(function (resolve, reject) {
25
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
26
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
27
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
28
- step((generator = generator.apply(thisArg, _arguments || [])).next());
29
- });
30
- };
31
- var __generator = (this && this.__generator) || function (thisArg, body) {
32
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
33
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
34
- function verb(n) { return function (v) { return step([n, v]); }; }
35
- function step(op) {
36
- if (f) throw new TypeError("Generator is already executing.");
37
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
38
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
39
- if (y = 0, t) op = [op[0] & 2, t.value];
40
- switch (op[0]) {
41
- case 0: case 1: t = op; break;
42
- case 4: _.label++; return { value: op[1], done: false };
43
- case 5: _.label++; y = op[1]; op = [0]; continue;
44
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
45
- default:
46
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
47
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
48
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
49
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
50
- if (t[2]) _.ops.pop();
51
- _.trys.pop(); continue;
52
- }
53
- op = body.call(thisArg, _);
54
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
55
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
56
- }
57
- };
58
2
  Object.defineProperty(exports, "__esModule", { value: true });
59
- exports.isAuthenticated = exports.getCurrentSession = exports.isSupabaseClientReady = exports.getAuthenticatedFileUrl = exports.getPublicFileUrl = exports.getStorageUrl = exports.supabaseClient = exports.supabasePublicStorageUrl = exports.supabasePrivateStorageUrl = exports.supabaseStorageBaseUrl = void 0;
3
+ exports.supabaseClient = exports.supabaseKey = exports.supabaseUrl = exports.supabasePublicStorageUrl = exports.supabasePrivateStorageUrl = exports.supabaseStorageBaseUrl = void 0;
60
4
  var supabase_js_1 = require("@supabase/supabase-js");
61
- // ============================================================================
62
- // ENVIRONMENT VALIDATION
63
- // ============================================================================
64
- /**
65
- * Validates required Supabase environment variables
66
- * Throws an error if any required environment variable is missing
67
- */
68
- var validateEnvironmentVariables = function () {
69
- var requiredVars = [
70
- "NEXT_PUBLIC_SUPABASE_URL",
71
- "NEXT_PUBLIC_SUPABASE_ANON_KEY",
72
- "NEXT_PUBLIC_SUPABASE_STORAGE_URL",
73
- "NEXT_PUBLIC_SUPABASE_PRIVATE_BUCKET",
74
- "NEXT_PUBLIC_SUPABASE_PUBLIC_BUCKET",
75
- ];
76
- var missingVars = requiredVars.filter(function (varName) { return !process.env[varName]; });
77
- if (missingVars.length > 0) {
78
- throw new Error("Missing required Supabase environment variables: ".concat(missingVars.join(", ")));
79
- }
80
- };
81
- // ============================================================================
82
- // CONFIGURATION CONSTANTS
83
- // ============================================================================
84
- /**
85
- * Supabase client configuration options
86
- */
87
- var SUPABASE_CONFIG = {
88
- auth: {
89
- persistSession: true,
90
- autoRefreshToken: true,
91
- detectSessionInUrl: true,
92
- },
93
- realtime: {
94
- params: {
95
- eventsPerSecond: 10,
96
- },
97
- },
98
- global: {
99
- headers: {
100
- "X-Client-Info": "stellar-solutions-modules",
101
- },
102
- },
103
- };
104
- // ============================================================================
105
- // STORAGE URL CONFIGURATION
106
- // ============================================================================
107
- /**
108
- * Base URL for Supabase storage
109
- */
110
5
  exports.supabaseStorageBaseUrl = process.env
111
6
  .NEXT_PUBLIC_SUPABASE_STORAGE_URL;
112
- /**
113
- * Private storage URL for authenticated users
114
- * Format: {storageBaseUrl}/authenticated/{privateBucket}
115
- */
116
7
  exports.supabasePrivateStorageUrl = "".concat(exports.supabaseStorageBaseUrl, "/authenticated/").concat(process.env.NEXT_PUBLIC_SUPABASE_PRIVATE_BUCKET);
117
- /**
118
- * Public storage URL for publicly accessible files
119
- * Format: {storageBaseUrl}/public/{publicBucket}
120
- */
121
8
  exports.supabasePublicStorageUrl = "".concat(exports.supabaseStorageBaseUrl, "/public/").concat(process.env.NEXT_PUBLIC_SUPABASE_PUBLIC_BUCKET);
122
- // ============================================================================
123
- // SUPABASE CLIENT INITIALIZATION
124
- // ============================================================================
125
- /**
126
- * Supabase project URL from environment variables
127
- */
128
- var supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL;
129
- /**
130
- * Supabase anonymous key from environment variables
131
- */
132
- var supabaseKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY;
133
- /**
134
- * Main Supabase client instance
135
- * Configured with authentication persistence and optimized settings
136
- */
137
- exports.supabaseClient = (function () {
138
- // Validate environment variables before creating client
139
- validateEnvironmentVariables();
140
- try {
141
- return (0, supabase_js_1.createClient)(supabaseUrl, supabaseKey, SUPABASE_CONFIG);
142
- }
143
- catch (error) {
144
- console.error("Failed to initialize Supabase client:", error);
145
- throw new Error("Supabase client initialization failed. Check your environment variables.");
146
- }
147
- })();
148
- // ============================================================================
149
- // UTILITY FUNCTIONS
150
- // ============================================================================
151
- /**
152
- * Get storage URL for a specific bucket type
153
- * @param bucketType - Type of storage bucket
154
- * @returns Full storage URL for the bucket
155
- */
156
- var getStorageUrl = function (bucketType) {
157
- switch (bucketType) {
158
- case "public":
159
- return exports.supabasePublicStorageUrl;
160
- case "private":
161
- case "authenticated":
162
- return exports.supabasePrivateStorageUrl;
163
- default:
164
- throw new Error("Invalid bucket type: ".concat(bucketType));
165
- }
166
- };
167
- exports.getStorageUrl = getStorageUrl;
168
- /**
169
- * Get public file URL from Supabase storage
170
- * @param bucket - Bucket name
171
- * @param filePath - Path to the file within the bucket
172
- * @returns Public URL for the file
173
- */
174
- var getPublicFileUrl = function (bucket, filePath) {
175
- return "".concat(exports.supabaseStorageBaseUrl, "/public/").concat(bucket, "/").concat(filePath);
176
- };
177
- exports.getPublicFileUrl = getPublicFileUrl;
178
- /**
179
- * Get authenticated file URL from Supabase storage
180
- * @param bucket - Bucket name
181
- * @param filePath - Path to the file within the bucket
182
- * @returns Authenticated URL for the file
183
- */
184
- var getAuthenticatedFileUrl = function (bucket, filePath) {
185
- return "".concat(exports.supabaseStorageBaseUrl, "/authenticated/").concat(bucket, "/").concat(filePath);
186
- };
187
- exports.getAuthenticatedFileUrl = getAuthenticatedFileUrl;
188
- /**
189
- * Check if Supabase client is properly initialized
190
- * @returns True if client is initialized, false otherwise
191
- */
192
- var isSupabaseClientReady = function () {
193
- try {
194
- return !!exports.supabaseClient && typeof exports.supabaseClient.from === "function";
195
- }
196
- catch (_a) {
197
- return false;
198
- }
199
- };
200
- exports.isSupabaseClientReady = isSupabaseClientReady;
201
- /**
202
- * Get current session from Supabase auth
203
- * @returns Current user session or null
204
- */
205
- var getCurrentSession = function () { return __awaiter(void 0, void 0, void 0, function () {
206
- var _a, session, error, error_1;
207
- return __generator(this, function (_b) {
208
- switch (_b.label) {
209
- case 0:
210
- _b.trys.push([0, 2, , 3]);
211
- return [4 /*yield*/, exports.supabaseClient.auth.getSession()];
212
- case 1:
213
- _a = _b.sent(), session = _a.data.session, error = _a.error;
214
- if (error) {
215
- console.warn("Failed to get current session:", error.message);
216
- return [2 /*return*/, null];
217
- }
218
- return [2 /*return*/, session];
219
- case 2:
220
- error_1 = _b.sent();
221
- console.error("Error getting current session:", error_1);
222
- return [2 /*return*/, null];
223
- case 3: return [2 /*return*/];
224
- }
225
- });
226
- }); };
227
- exports.getCurrentSession = getCurrentSession;
228
- /**
229
- * Check if user is authenticated
230
- * @returns True if user is authenticated, false otherwise
231
- */
232
- var isAuthenticated = function () { return __awaiter(void 0, void 0, void 0, function () {
233
- var session;
234
- return __generator(this, function (_a) {
235
- switch (_a.label) {
236
- case 0: return [4 /*yield*/, (0, exports.getCurrentSession)()];
237
- case 1:
238
- session = _a.sent();
239
- return [2 /*return*/, !!(session === null || session === void 0 ? void 0 : session.user)];
240
- }
241
- });
242
- }); };
243
- exports.isAuthenticated = isAuthenticated;
244
- // ============================================================================
245
- // OPTIMIZATION SUMMARY
246
- // ============================================================================
247
- /*
248
- * Supabase Configuration File Optimizations Applied:
249
- *
250
- * 1. **Comprehensive Documentation**
251
- * - Added detailed JSDoc comments for all exports and functions
252
- * - Explained environment variable requirements
253
- * - Documented configuration options and their purposes
254
- *
255
- * 2. **Enhanced Error Handling**
256
- * - Added environment variable validation with descriptive error messages
257
- * - Wrapped client creation in try-catch with proper error handling
258
- * - Added runtime checks for client initialization
259
- *
260
- * 3. **Improved Configuration**
261
- * - Enhanced Supabase client configuration with additional options
262
- * - Added proper TypeScript types for storage bucket types
263
- * - Organized configuration into logical constants
264
- *
265
- * 4. **Utility Functions**
266
- * - Added helper functions for common storage operations
267
- * - Implemented authentication state checking utilities
268
- * - Created type-safe URL generation functions
269
- *
270
- * 5. **Type Safety Improvements**
271
- * - Added proper TypeScript types and interfaces
272
- * - Exported Supabase types for external use
273
- * - Used const assertions for configuration objects
274
- *
275
- * 6. **Developer Experience**
276
- * - Clear separation of concerns with section headers
277
- * - Self-documenting code with comprehensive comments
278
- * - Easy to extend and maintain
279
- * - Proper error messages for debugging
280
- *
281
- * 7. **Performance Optimizations**
282
- * - Lazy initialization of Supabase client
283
- * - Efficient environment variable validation
284
- * - Optimized configuration for better performance
285
- *
286
- * 8. **Security Enhancements**
287
- * - Proper validation of environment variables
288
- * - Secure handling of authentication tokens
289
- * - Type-safe operations to prevent runtime errors
290
- */
9
+ exports.supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL;
10
+ exports.supabaseKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY;
11
+ exports.supabaseClient = (0, supabase_js_1.createClient)(exports.supabaseUrl, exports.supabaseKey, {
12
+ auth: {
13
+ persistSession: true,
14
+ },
15
+ });