@bid-scents/shared-sdk 1.0.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 (74) hide show
  1. package/README.md +123 -0
  2. package/dist/api/core/ApiError.d.ts +11 -0
  3. package/dist/api/core/ApiError.d.ts.map +1 -0
  4. package/dist/api/core/ApiError.js +11 -0
  5. package/dist/api/core/ApiRequestOptions.d.ts +14 -0
  6. package/dist/api/core/ApiRequestOptions.d.ts.map +1 -0
  7. package/dist/api/core/ApiRequestOptions.js +1 -0
  8. package/dist/api/core/ApiResult.d.ts +8 -0
  9. package/dist/api/core/ApiResult.d.ts.map +1 -0
  10. package/dist/api/core/ApiResult.js +1 -0
  11. package/dist/api/core/CancelablePromise.d.ts +21 -0
  12. package/dist/api/core/CancelablePromise.d.ts.map +1 -0
  13. package/dist/api/core/CancelablePromise.js +111 -0
  14. package/dist/api/core/OpenAPI.d.ts +17 -0
  15. package/dist/api/core/OpenAPI.d.ts.map +1 -0
  16. package/dist/api/core/OpenAPI.js +11 -0
  17. package/dist/api/core/request.d.ts +31 -0
  18. package/dist/api/core/request.d.ts.map +1 -0
  19. package/dist/api/core/request.js +275 -0
  20. package/dist/api/index.d.ts +14 -0
  21. package/dist/api/index.d.ts.map +1 -0
  22. package/dist/api/index.js +9 -0
  23. package/dist/api/models/CheckUniqueUsernameResponse.d.ts +7 -0
  24. package/dist/api/models/CheckUniqueUsernameResponse.d.ts.map +1 -0
  25. package/dist/api/models/CheckUniqueUsernameResponse.js +1 -0
  26. package/dist/api/models/HTTPValidationError.d.ts +5 -0
  27. package/dist/api/models/HTTPValidationError.d.ts.map +1 -0
  28. package/dist/api/models/HTTPValidationError.js +1 -0
  29. package/dist/api/models/LoginResponse.d.ts +12 -0
  30. package/dist/api/models/LoginResponse.d.ts.map +1 -0
  31. package/dist/api/models/LoginResponse.js +1 -0
  32. package/dist/api/models/OnboardRequest.d.ts +27 -0
  33. package/dist/api/models/OnboardRequest.d.ts.map +1 -0
  34. package/dist/api/models/OnboardRequest.js +1 -0
  35. package/dist/api/models/OnboardResponse.d.ts +12 -0
  36. package/dist/api/models/OnboardResponse.d.ts.map +1 -0
  37. package/dist/api/models/OnboardResponse.js +1 -0
  38. package/dist/api/models/User.d.ts +15 -0
  39. package/dist/api/models/User.d.ts.map +1 -0
  40. package/dist/api/models/User.js +1 -0
  41. package/dist/api/models/ValidationError.d.ts +6 -0
  42. package/dist/api/models/ValidationError.d.ts.map +1 -0
  43. package/dist/api/models/ValidationError.js +1 -0
  44. package/dist/api/services/AuthService.d.ts +31 -0
  45. package/dist/api/services/AuthService.d.ts.map +1 -0
  46. package/dist/api/services/AuthService.js +53 -0
  47. package/dist/api/services/DefaultService.d.ts +10 -0
  48. package/dist/api/services/DefaultService.d.ts.map +1 -0
  49. package/dist/api/services/DefaultService.js +15 -0
  50. package/dist/config/index.d.ts +1 -0
  51. package/dist/config/index.d.ts.map +1 -0
  52. package/dist/config/index.js +1 -0
  53. package/dist/index.d.ts +4 -0
  54. package/dist/index.d.ts.map +1 -0
  55. package/dist/index.js +7 -0
  56. package/dist/stores/auth.d.ts +41 -0
  57. package/dist/stores/auth.d.ts.map +1 -0
  58. package/dist/stores/auth.js +58 -0
  59. package/dist/stores/index.d.ts +2 -0
  60. package/dist/stores/index.d.ts.map +1 -0
  61. package/dist/stores/index.js +2 -0
  62. package/dist/types/index.d.ts +1 -0
  63. package/dist/types/index.d.ts.map +1 -0
  64. package/dist/types/index.js +1 -0
  65. package/dist/utils/auth/supabase-config.d.ts +17 -0
  66. package/dist/utils/auth/supabase-config.d.ts.map +1 -0
  67. package/dist/utils/auth/supabase-config.js +44 -0
  68. package/dist/utils/index.d.ts +4 -0
  69. package/dist/utils/index.d.ts.map +1 -0
  70. package/dist/utils/index.js +3 -0
  71. package/dist/utils/validation/schemas.d.ts +40 -0
  72. package/dist/utils/validation/schemas.d.ts.map +1 -0
  73. package/dist/utils/validation/schemas.js +46 -0
  74. package/package.json +46 -0
@@ -0,0 +1,58 @@
1
+ // Manages user authentication state with Supabase integration.
2
+ import { create } from 'zustand';
3
+ import { persist } from 'zustand/middleware';
4
+ /**
5
+ * Zustand store for authentication state management with Supabase.
6
+ *
7
+ * Manages user data and Supabase session which contains tokens.
8
+ * Supabase automatically handles token refresh in the background.
9
+ *
10
+ * @returns Auth store with user state, session, and actions
11
+ */
12
+ export const useAuthStore = create()(persist((set) => ({
13
+ user: null,
14
+ session: null,
15
+ isAuthenticated: false,
16
+ isOnboarded: false,
17
+ /**
18
+ * Updates the current user and onboarding status.
19
+ *
20
+ * @param user - User profile data or null to clear
21
+ */
22
+ setUser: (user) => {
23
+ set({
24
+ user,
25
+ isOnboarded: !!user?.onboarded_at
26
+ });
27
+ },
28
+ /**
29
+ * Updates the Supabase session and authentication status.
30
+ *
31
+ * @param session - Supabase session object containing tokens
32
+ */
33
+ setSession: (session) => {
34
+ set({
35
+ session,
36
+ isAuthenticated: !!session
37
+ });
38
+ },
39
+ /**
40
+ * Clears all authentication state.
41
+ */
42
+ logout: () => {
43
+ set({
44
+ user: null,
45
+ session: null,
46
+ isAuthenticated: false,
47
+ isOnboarded: false
48
+ });
49
+ }
50
+ }), {
51
+ name: 'auth-storage',
52
+ partialize: (state) => ({
53
+ user: state.user,
54
+ session: state.session,
55
+ isAuthenticated: state.isAuthenticated,
56
+ isOnboarded: state.isOnboarded
57
+ })
58
+ }));
@@ -0,0 +1,2 @@
1
+ export { useAuthStore } from './auth';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/stores/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA"}
@@ -0,0 +1,2 @@
1
+ // Central export for all Zustand stores.
2
+ export { useAuthStore } from './auth';
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Handles Supabase authentication state changes.
3
+ *
4
+ * Call this function from Supabase's onAuthStateChange callback
5
+ * to sync the session with your app state and configure API client.
6
+ *
7
+ * @param event - Auth event type from Supabase
8
+ * @param session - Current Supabase session or null
9
+ */
10
+ export declare const handleAuthStateChange: (event: string, session: any) => void;
11
+ /**
12
+ * Initializes authentication system on app startup.
13
+ *
14
+ * Configures API client with stored tokens. Call this once during app initialization.
15
+ */
16
+ export declare const initializeAuth: () => void;
17
+ //# sourceMappingURL=supabase-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"supabase-config.d.ts","sourceRoot":"","sources":["../../../src/utils/auth/supabase-config.ts"],"names":[],"mappings":"AAqBA;;;;;;;;GAQG;AACH,eAAO,MAAM,qBAAqB,GAAI,OAAO,MAAM,EAAE,SAAS,GAAG,KAAG,IAUnE,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,cAAc,QAAO,IAEjC,CAAA"}
@@ -0,0 +1,44 @@
1
+ // Supabase authentication configuration and token management.
2
+ import { useAuthStore } from '../../stores/auth';
3
+ import { OpenAPI } from '../../api/core/OpenAPI';
4
+ /**
5
+ * Configures the OpenAPI client with the current Supabase access token.
6
+ *
7
+ * Internal function that extracts the access token from the Supabase session
8
+ * and configures all API requests to include it in the Authorization header.
9
+ */
10
+ const configureApiWithSupabaseToken = () => {
11
+ const { session } = useAuthStore.getState();
12
+ if (session?.access_token) {
13
+ OpenAPI.TOKEN = session.access_token;
14
+ }
15
+ else {
16
+ OpenAPI.TOKEN = undefined;
17
+ }
18
+ };
19
+ /**
20
+ * Handles Supabase authentication state changes.
21
+ *
22
+ * Call this function from Supabase's onAuthStateChange callback
23
+ * to sync the session with your app state and configure API client.
24
+ *
25
+ * @param event - Auth event type from Supabase
26
+ * @param session - Current Supabase session or null
27
+ */
28
+ export const handleAuthStateChange = (event, session) => {
29
+ const { setSession, logout } = useAuthStore.getState();
30
+ setSession(session);
31
+ configureApiWithSupabaseToken();
32
+ // Clear user data on logout
33
+ if (event === 'SIGNED_OUT' || !session) {
34
+ logout();
35
+ }
36
+ };
37
+ /**
38
+ * Initializes authentication system on app startup.
39
+ *
40
+ * Configures API client with stored tokens. Call this once during app initialization.
41
+ */
42
+ export const initializeAuth = () => {
43
+ configureApiWithSupabaseToken();
44
+ };
@@ -0,0 +1,4 @@
1
+ export { handleAuthStateChange, initializeAuth } from './auth/supabase-config';
2
+ export { onboardingSchema, usernameSchema } from './validation/schemas';
3
+ export type { OnboardingFormData } from './validation/schemas';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACH,qBAAqB,EACrB,cAAc,EACf,MAAM,wBAAwB,CAAA;AAEjC,OAAO,EACH,gBAAgB,EAChB,cAAc,EACf,MAAM,sBAAsB,CAAA;AAE/B,YAAY,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA"}
@@ -0,0 +1,3 @@
1
+ // Central export for all utilities.
2
+ export { handleAuthStateChange, initializeAuth } from './auth/supabase-config';
3
+ export { onboardingSchema, usernameSchema } from './validation/schemas';
@@ -0,0 +1,40 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * Validation schema for user onboarding form data.
4
+ *
5
+ * Enforces username format rules, name requirements, and optional profile fields.
6
+ * Used for client-side validation before API submission.
7
+ */
8
+ export declare const onboardingSchema: z.ZodObject<{
9
+ username: z.ZodString;
10
+ first_name: z.ZodString;
11
+ last_name: z.ZodString;
12
+ profile_image_url: z.ZodOptional<z.ZodString>;
13
+ cover_image_url: z.ZodOptional<z.ZodString>;
14
+ bio: z.ZodOptional<z.ZodString>;
15
+ }, "strip", z.ZodTypeAny, {
16
+ username: string;
17
+ first_name: string;
18
+ last_name: string;
19
+ profile_image_url?: string | undefined;
20
+ cover_image_url?: string | undefined;
21
+ bio?: string | undefined;
22
+ }, {
23
+ username: string;
24
+ first_name: string;
25
+ last_name: string;
26
+ profile_image_url?: string | undefined;
27
+ cover_image_url?: string | undefined;
28
+ bio?: string | undefined;
29
+ }>;
30
+ /**
31
+ * TypeScript type inferred from the onboarding validation schema.
32
+ * Use this type for form components and validation results.
33
+ */
34
+ export type OnboardingFormData = z.infer<typeof onboardingSchema>;
35
+ /**
36
+ * Validation schema for username availability checking.
37
+ * Used for real-time username validation during form input.
38
+ */
39
+ export declare const usernameSchema: z.ZodString;
40
+ //# sourceMappingURL=schemas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../src/utils/validation/schemas.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;EAiC3B,CAAA;AAGF;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAA;AAEjE;;;GAGG;AACH,eAAO,MAAM,cAAc,aAI+D,CAAA"}
@@ -0,0 +1,46 @@
1
+ // Zod validation schemas for form inputs and data validation.
2
+ import { z } from 'zod';
3
+ /**
4
+ * Validation schema for user onboarding form data.
5
+ *
6
+ * Enforces username format rules, name requirements, and optional profile fields.
7
+ * Used for client-side validation before API submission.
8
+ */
9
+ export const onboardingSchema = z.object({
10
+ username: z
11
+ .string()
12
+ .min(3, 'Username must be at least 3 characters')
13
+ .max(50, 'Username must be less than 50 characters')
14
+ .regex(/^[a-zA-Z0-9_]+$/, 'Username can only contain letters, numbers, and underscores'),
15
+ first_name: z
16
+ .string()
17
+ .min(1, 'First name is required')
18
+ .max(50, 'First name must be less than 50 characters')
19
+ .trim(),
20
+ last_name: z
21
+ .string()
22
+ .min(1, 'Last name is required')
23
+ .max(50, 'Last name must be less than 50 characters')
24
+ .trim(),
25
+ profile_image_url: z
26
+ .string()
27
+ .url('Must be a valid URL')
28
+ .optional(),
29
+ cover_image_url: z
30
+ .string()
31
+ .url('Must be a valid URL')
32
+ .optional(),
33
+ bio: z
34
+ .string()
35
+ .max(500, 'Bio must be less than 500 characters')
36
+ .optional()
37
+ });
38
+ /**
39
+ * Validation schema for username availability checking.
40
+ * Used for real-time username validation during form input.
41
+ */
42
+ export const usernameSchema = z
43
+ .string()
44
+ .min(3, 'Username must be at least 3 characters')
45
+ .max(50, 'Username must be less than 50 characters')
46
+ .regex(/^[a-zA-Z0-9_]+$/, 'Username can only contain letters, numbers, and underscores');
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@bid-scents/shared-sdk",
3
+ "version": "1.0.0",
4
+ "description": "Shared SDK for marketplace applications",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist",
10
+ "README.md"
11
+ ],
12
+ "scripts": {
13
+ "build": "tsc",
14
+ "dev": "tsc --watch",
15
+ "clean": "rm -rf dist",
16
+ "test": "vitest",
17
+ "lint": "eslint src --ext .ts,.tsx",
18
+ "type-check": "tsc --noEmit",
19
+ "generate-api": "openapi -i http://localhost:8000/openapi.json -o src/api",
20
+ "prepublishOnly": "bun run clean && bun run build"
21
+ },
22
+ "keywords": ["marketplace", "sdk", "react", "typescript"],
23
+ "author": "Shawarmaa",
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://github.com/BidScents/shared-sdk.git"
27
+ },
28
+ "peerDependencies": {
29
+ "react": ">=18.0.0",
30
+ "typescript": "^5.0.0"
31
+ },
32
+ "dependencies": {
33
+ "zustand": "^5.0.5",
34
+ "zod": "^3.25.64",
35
+ "@tanstack/react-query": "^5.80.7"
36
+ },
37
+ "devDependencies": {
38
+ "@types/bun": "latest",
39
+ "@types/node": "^24.0.3",
40
+ "@types/react": "^19.1.8",
41
+ "eslint": "^8.0.0",
42
+ "openapi-typescript-codegen": "^0.29.0",
43
+ "typescript": "^5.8.3",
44
+ "vitest": "^1.0.0"
45
+ }
46
+ }