@marcwelti/mw-core 0.2.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.
Files changed (40) hide show
  1. package/README.md +141 -0
  2. package/dist/context/index.d.mts +95 -0
  3. package/dist/context/index.d.ts +95 -0
  4. package/dist/context/index.js +280 -0
  5. package/dist/context/index.js.map +1 -0
  6. package/dist/context/index.mjs +276 -0
  7. package/dist/context/index.mjs.map +1 -0
  8. package/dist/firebase/index.d.mts +176 -0
  9. package/dist/firebase/index.d.ts +176 -0
  10. package/dist/firebase/index.js +393 -0
  11. package/dist/firebase/index.js.map +1 -0
  12. package/dist/firebase/index.mjs +318 -0
  13. package/dist/firebase/index.mjs.map +1 -0
  14. package/dist/hooks/index.d.mts +97 -0
  15. package/dist/hooks/index.d.ts +97 -0
  16. package/dist/hooks/index.js +618 -0
  17. package/dist/hooks/index.js.map +1 -0
  18. package/dist/hooks/index.mjs +611 -0
  19. package/dist/hooks/index.mjs.map +1 -0
  20. package/dist/index.d.mts +12 -0
  21. package/dist/index.d.ts +12 -0
  22. package/dist/index.js +922 -0
  23. package/dist/index.js.map +1 -0
  24. package/dist/index.mjs +843 -0
  25. package/dist/index.mjs.map +1 -0
  26. package/dist/server/index.d.mts +216 -0
  27. package/dist/server/index.d.ts +216 -0
  28. package/dist/server/index.js +309 -0
  29. package/dist/server/index.js.map +1 -0
  30. package/dist/server/index.mjs +276 -0
  31. package/dist/server/index.mjs.map +1 -0
  32. package/dist/storage-BU_rfYCi.d.mts +43 -0
  33. package/dist/storage-BU_rfYCi.d.ts +43 -0
  34. package/dist/types/index.d.mts +108 -0
  35. package/dist/types/index.d.ts +108 -0
  36. package/dist/types/index.js +12 -0
  37. package/dist/types/index.js.map +1 -0
  38. package/dist/types/index.mjs +3 -0
  39. package/dist/types/index.mjs.map +1 -0
  40. package/package.json +91 -0
@@ -0,0 +1,43 @@
1
+ import { FullMetadata, StorageReference, ListResult, UploadMetadata, UploadTask } from 'firebase/storage';
2
+
3
+ /**
4
+ * Get a reference to a storage location
5
+ */
6
+ declare function getStorageRef(path: string): StorageReference;
7
+ /**
8
+ * Upload a file to storage
9
+ */
10
+ declare function uploadFile(path: string, file: Blob | Uint8Array | ArrayBuffer, metadata?: UploadMetadata): Promise<string>;
11
+ /**
12
+ * Upload a file with progress tracking
13
+ */
14
+ declare function uploadFileWithProgress(path: string, file: Blob | Uint8Array | ArrayBuffer, onProgress?: (progress: number) => void, metadata?: UploadMetadata): {
15
+ task: UploadTask;
16
+ promise: Promise<string>;
17
+ };
18
+ /**
19
+ * Get the download URL for a file
20
+ */
21
+ declare function getFileURL(path: string): Promise<string>;
22
+ /**
23
+ * Delete a file from storage
24
+ */
25
+ declare function deleteFile(path: string): Promise<void>;
26
+ /**
27
+ * List all files in a directory
28
+ */
29
+ declare function listFiles(path: string): Promise<ListResult>;
30
+ /**
31
+ * Get metadata for a file
32
+ */
33
+ declare function getFileMetadata(path: string): Promise<FullMetadata>;
34
+ /**
35
+ * Update metadata for a file
36
+ */
37
+ declare function updateFileMetadata(path: string, metadata: Partial<UploadMetadata>): Promise<FullMetadata>;
38
+ /**
39
+ * Generate a unique file path with timestamp
40
+ */
41
+ declare function generateFilePath(folder: string, filename: string, userId?: string): string;
42
+
43
+ export { getFileMetadata as a, getFileURL as b, getStorageRef as c, deleteFile as d, uploadFile as e, uploadFileWithProgress as f, generateFilePath as g, listFiles as l, updateFileMetadata as u };
@@ -0,0 +1,43 @@
1
+ import { FullMetadata, StorageReference, ListResult, UploadMetadata, UploadTask } from 'firebase/storage';
2
+
3
+ /**
4
+ * Get a reference to a storage location
5
+ */
6
+ declare function getStorageRef(path: string): StorageReference;
7
+ /**
8
+ * Upload a file to storage
9
+ */
10
+ declare function uploadFile(path: string, file: Blob | Uint8Array | ArrayBuffer, metadata?: UploadMetadata): Promise<string>;
11
+ /**
12
+ * Upload a file with progress tracking
13
+ */
14
+ declare function uploadFileWithProgress(path: string, file: Blob | Uint8Array | ArrayBuffer, onProgress?: (progress: number) => void, metadata?: UploadMetadata): {
15
+ task: UploadTask;
16
+ promise: Promise<string>;
17
+ };
18
+ /**
19
+ * Get the download URL for a file
20
+ */
21
+ declare function getFileURL(path: string): Promise<string>;
22
+ /**
23
+ * Delete a file from storage
24
+ */
25
+ declare function deleteFile(path: string): Promise<void>;
26
+ /**
27
+ * List all files in a directory
28
+ */
29
+ declare function listFiles(path: string): Promise<ListResult>;
30
+ /**
31
+ * Get metadata for a file
32
+ */
33
+ declare function getFileMetadata(path: string): Promise<FullMetadata>;
34
+ /**
35
+ * Update metadata for a file
36
+ */
37
+ declare function updateFileMetadata(path: string, metadata: Partial<UploadMetadata>): Promise<FullMetadata>;
38
+ /**
39
+ * Generate a unique file path with timestamp
40
+ */
41
+ declare function generateFilePath(folder: string, filename: string, userId?: string): string;
42
+
43
+ export { getFileMetadata as a, getFileURL as b, getStorageRef as c, deleteFile as d, uploadFile as e, uploadFileWithProgress as f, generateFilePath as g, listFiles as l, updateFileMetadata as u };
@@ -0,0 +1,108 @@
1
+ import { Timestamp } from 'firebase/firestore';
2
+ export { Timestamp } from 'firebase/firestore';
3
+ export { User, UserCredential } from 'firebase/auth';
4
+
5
+ /**
6
+ * Base interface for all Firestore documents
7
+ * Includes common fields like id and timestamps
8
+ */
9
+ interface BaseDocument {
10
+ id: string;
11
+ createdAt?: Timestamp;
12
+ updatedAt?: Timestamp;
13
+ }
14
+ /**
15
+ * User profile stored in Firestore
16
+ * Extends the Firebase Auth user with additional fields
17
+ */
18
+ interface UserProfile extends BaseDocument {
19
+ uid: string;
20
+ email: string;
21
+ displayName?: string;
22
+ photoURL?: string;
23
+ phoneNumber?: string;
24
+ role: UserRole;
25
+ isActive: boolean;
26
+ metadata?: Record<string, unknown>;
27
+ }
28
+ /**
29
+ * User roles for authorization
30
+ */
31
+ type UserRole = 'admin' | 'user' | 'guest';
32
+ /**
33
+ * Generic API response type
34
+ */
35
+ interface ApiResponse<T = unknown> {
36
+ success: boolean;
37
+ data?: T;
38
+ error?: {
39
+ code: string;
40
+ message: string;
41
+ };
42
+ }
43
+ /**
44
+ * Pagination parameters
45
+ */
46
+ interface PaginationParams {
47
+ page?: number;
48
+ limit?: number;
49
+ cursor?: string;
50
+ }
51
+ /**
52
+ * Paginated response
53
+ */
54
+ interface PaginatedResponse<T> {
55
+ items: T[];
56
+ total: number;
57
+ page: number;
58
+ limit: number;
59
+ hasMore: boolean;
60
+ nextCursor?: string;
61
+ }
62
+ /**
63
+ * Sort direction
64
+ */
65
+ type SortDirection = 'asc' | 'desc';
66
+ /**
67
+ * Sort parameters
68
+ */
69
+ interface SortParams<T = string> {
70
+ field: T;
71
+ direction: SortDirection;
72
+ }
73
+ /**
74
+ * Filter operator types
75
+ */
76
+ type FilterOperator = 'eq' | 'neq' | 'gt' | 'gte' | 'lt' | 'lte' | 'contains' | 'in' | 'notIn';
77
+ /**
78
+ * Filter parameter
79
+ */
80
+ interface FilterParam<T = string> {
81
+ field: T;
82
+ operator: FilterOperator;
83
+ value: unknown;
84
+ }
85
+ /**
86
+ * Async operation state
87
+ */
88
+ interface AsyncState<T = unknown> {
89
+ data: T | null;
90
+ loading: boolean;
91
+ error: Error | null;
92
+ }
93
+ /**
94
+ * Form field error
95
+ */
96
+ interface FieldError {
97
+ field: string;
98
+ message: string;
99
+ }
100
+ /**
101
+ * Form validation result
102
+ */
103
+ interface ValidationResult {
104
+ valid: boolean;
105
+ errors: FieldError[];
106
+ }
107
+
108
+ export type { ApiResponse, AsyncState, BaseDocument, FieldError, FilterOperator, FilterParam, PaginatedResponse, PaginationParams, SortDirection, SortParams, UserProfile, UserRole, ValidationResult };
@@ -0,0 +1,108 @@
1
+ import { Timestamp } from 'firebase/firestore';
2
+ export { Timestamp } from 'firebase/firestore';
3
+ export { User, UserCredential } from 'firebase/auth';
4
+
5
+ /**
6
+ * Base interface for all Firestore documents
7
+ * Includes common fields like id and timestamps
8
+ */
9
+ interface BaseDocument {
10
+ id: string;
11
+ createdAt?: Timestamp;
12
+ updatedAt?: Timestamp;
13
+ }
14
+ /**
15
+ * User profile stored in Firestore
16
+ * Extends the Firebase Auth user with additional fields
17
+ */
18
+ interface UserProfile extends BaseDocument {
19
+ uid: string;
20
+ email: string;
21
+ displayName?: string;
22
+ photoURL?: string;
23
+ phoneNumber?: string;
24
+ role: UserRole;
25
+ isActive: boolean;
26
+ metadata?: Record<string, unknown>;
27
+ }
28
+ /**
29
+ * User roles for authorization
30
+ */
31
+ type UserRole = 'admin' | 'user' | 'guest';
32
+ /**
33
+ * Generic API response type
34
+ */
35
+ interface ApiResponse<T = unknown> {
36
+ success: boolean;
37
+ data?: T;
38
+ error?: {
39
+ code: string;
40
+ message: string;
41
+ };
42
+ }
43
+ /**
44
+ * Pagination parameters
45
+ */
46
+ interface PaginationParams {
47
+ page?: number;
48
+ limit?: number;
49
+ cursor?: string;
50
+ }
51
+ /**
52
+ * Paginated response
53
+ */
54
+ interface PaginatedResponse<T> {
55
+ items: T[];
56
+ total: number;
57
+ page: number;
58
+ limit: number;
59
+ hasMore: boolean;
60
+ nextCursor?: string;
61
+ }
62
+ /**
63
+ * Sort direction
64
+ */
65
+ type SortDirection = 'asc' | 'desc';
66
+ /**
67
+ * Sort parameters
68
+ */
69
+ interface SortParams<T = string> {
70
+ field: T;
71
+ direction: SortDirection;
72
+ }
73
+ /**
74
+ * Filter operator types
75
+ */
76
+ type FilterOperator = 'eq' | 'neq' | 'gt' | 'gte' | 'lt' | 'lte' | 'contains' | 'in' | 'notIn';
77
+ /**
78
+ * Filter parameter
79
+ */
80
+ interface FilterParam<T = string> {
81
+ field: T;
82
+ operator: FilterOperator;
83
+ value: unknown;
84
+ }
85
+ /**
86
+ * Async operation state
87
+ */
88
+ interface AsyncState<T = unknown> {
89
+ data: T | null;
90
+ loading: boolean;
91
+ error: Error | null;
92
+ }
93
+ /**
94
+ * Form field error
95
+ */
96
+ interface FieldError {
97
+ field: string;
98
+ message: string;
99
+ }
100
+ /**
101
+ * Form validation result
102
+ */
103
+ interface ValidationResult {
104
+ valid: boolean;
105
+ errors: FieldError[];
106
+ }
107
+
108
+ export type { ApiResponse, AsyncState, BaseDocument, FieldError, FilterOperator, FilterParam, PaginatedResponse, PaginationParams, SortDirection, SortParams, UserProfile, UserRole, ValidationResult };
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ var firestore = require('firebase/firestore');
4
+
5
+
6
+
7
+ Object.defineProperty(exports, "Timestamp", {
8
+ enumerable: true,
9
+ get: function () { return firestore.Timestamp; }
10
+ });
11
+ //# sourceMappingURL=index.js.map
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js","sourcesContent":[]}
@@ -0,0 +1,3 @@
1
+ export { Timestamp } from 'firebase/firestore';
2
+ //# sourceMappingURL=index.mjs.map
3
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.mjs","sourcesContent":[]}
package/package.json ADDED
@@ -0,0 +1,91 @@
1
+ {
2
+ "name": "@marcwelti/mw-core",
3
+ "version": "0.2.0",
4
+ "description": "Marc Welti - Shared Firebase utilities, React hooks, and server-side auth",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ },
14
+ "./firebase": {
15
+ "types": "./dist/firebase/index.d.ts",
16
+ "import": "./dist/firebase/index.mjs",
17
+ "require": "./dist/firebase/index.js"
18
+ },
19
+ "./hooks": {
20
+ "types": "./dist/hooks/index.d.ts",
21
+ "import": "./dist/hooks/index.mjs",
22
+ "require": "./dist/hooks/index.js"
23
+ },
24
+ "./context": {
25
+ "types": "./dist/context/index.d.ts",
26
+ "import": "./dist/context/index.mjs",
27
+ "require": "./dist/context/index.js"
28
+ },
29
+ "./types": {
30
+ "types": "./dist/types/index.d.ts",
31
+ "import": "./dist/types/index.mjs",
32
+ "require": "./dist/types/index.js"
33
+ },
34
+ "./server": {
35
+ "types": "./dist/server/index.d.ts",
36
+ "import": "./dist/server/index.mjs",
37
+ "require": "./dist/server/index.js"
38
+ }
39
+ },
40
+ "files": [
41
+ "dist"
42
+ ],
43
+ "scripts": {
44
+ "build": "tsup",
45
+ "dev": "tsup --watch",
46
+ "clean": "rm -rf dist",
47
+ "prepublishOnly": "npm run build",
48
+ "typecheck": "tsc --noEmit"
49
+ },
50
+ "peerDependencies": {
51
+ "react": "^18.0.0 || ^19.0.0",
52
+ "react-dom": "^18.0.0 || ^19.0.0",
53
+ "firebase": "^10.0.0 || ^11.0.0 || ^12.0.0",
54
+ "firebase-admin": "^12.0.0 || ^13.0.0"
55
+ },
56
+ "peerDependenciesMeta": {
57
+ "firebase-admin": {
58
+ "optional": true
59
+ }
60
+ },
61
+ "devDependencies": {
62
+ "@types/node": "^20.10.0",
63
+ "@types/react": "^19.0.0",
64
+ "@types/react-dom": "^19.0.0",
65
+ "firebase": "^11.0.0",
66
+ "firebase-admin": "^13.0.0",
67
+ "react": "^19.0.0",
68
+ "react-dom": "^19.0.0",
69
+ "tsup": "^8.0.0",
70
+ "typescript": "^5.3.0"
71
+ },
72
+ "keywords": [
73
+ "firebase",
74
+ "firebase-admin",
75
+ "react",
76
+ "hooks",
77
+ "authentication",
78
+ "firestore",
79
+ "session",
80
+ "marc-welti"
81
+ ],
82
+ "author": "Marc Welti",
83
+ "license": "UNLICENSED",
84
+ "repository": {
85
+ "type": "git",
86
+ "url": "https://github.com/marcwelti/mw-core.git"
87
+ },
88
+ "publishConfig": {
89
+ "access": "restricted"
90
+ }
91
+ }