@scalemule/nextjs 0.0.1

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,2 @@
1
+ export { h as createWebhookHandler } from '../webhook-handler-C-5_Ey1T.mjs';
2
+ import '../index-BkacIKdu.mjs';
@@ -0,0 +1,2 @@
1
+ export { h as createWebhookHandler } from '../webhook-handler-BPNqhuwL.js';
2
+ import '../index-BkacIKdu.js';
@@ -0,0 +1,56 @@
1
+ 'use strict';
2
+
3
+ var crypto = require('crypto');
4
+
5
+ // src/server/webhooks.ts
6
+ function verifyWebhookSignature(payload, signature, secret) {
7
+ if (!signature.startsWith("sha256=")) {
8
+ return false;
9
+ }
10
+ const providedSig = signature.slice(7);
11
+ const expectedSig = crypto.createHmac("sha256", secret).update(payload).digest("hex");
12
+ try {
13
+ return crypto.timingSafeEqual(
14
+ Buffer.from(providedSig, "hex"),
15
+ Buffer.from(expectedSig, "hex")
16
+ );
17
+ } catch {
18
+ return false;
19
+ }
20
+ }
21
+ function parseWebhookEvent(payload) {
22
+ return JSON.parse(payload);
23
+ }
24
+
25
+ // src/server/webhook-handler.ts
26
+ function createWebhookHandler(config = {}) {
27
+ return async (request) => {
28
+ const signature = request.headers.get("x-webhook-signature");
29
+ const body = await request.text();
30
+ if (config.secret) {
31
+ if (!signature || !verifyWebhookSignature(body, signature, config.secret)) {
32
+ return new Response(JSON.stringify({ error: "Invalid signature" }), {
33
+ status: 401,
34
+ headers: { "Content-Type": "application/json" }
35
+ });
36
+ }
37
+ }
38
+ try {
39
+ const event = parseWebhookEvent(body);
40
+ if (config.onEvent && event.event && config.onEvent[event.event]) {
41
+ await config.onEvent[event.event](event);
42
+ }
43
+ return new Response(JSON.stringify({ received: true }), {
44
+ status: 200,
45
+ headers: { "Content-Type": "application/json" }
46
+ });
47
+ } catch (error) {
48
+ return new Response(JSON.stringify({ error: "Webhook processing failed" }), {
49
+ status: 500,
50
+ headers: { "Content-Type": "application/json" }
51
+ });
52
+ }
53
+ };
54
+ }
55
+
56
+ exports.createWebhookHandler = createWebhookHandler;
@@ -0,0 +1,54 @@
1
+ import { createHmac, timingSafeEqual } from 'crypto';
2
+
3
+ // src/server/webhooks.ts
4
+ function verifyWebhookSignature(payload, signature, secret) {
5
+ if (!signature.startsWith("sha256=")) {
6
+ return false;
7
+ }
8
+ const providedSig = signature.slice(7);
9
+ const expectedSig = createHmac("sha256", secret).update(payload).digest("hex");
10
+ try {
11
+ return timingSafeEqual(
12
+ Buffer.from(providedSig, "hex"),
13
+ Buffer.from(expectedSig, "hex")
14
+ );
15
+ } catch {
16
+ return false;
17
+ }
18
+ }
19
+ function parseWebhookEvent(payload) {
20
+ return JSON.parse(payload);
21
+ }
22
+
23
+ // src/server/webhook-handler.ts
24
+ function createWebhookHandler(config = {}) {
25
+ return async (request) => {
26
+ const signature = request.headers.get("x-webhook-signature");
27
+ const body = await request.text();
28
+ if (config.secret) {
29
+ if (!signature || !verifyWebhookSignature(body, signature, config.secret)) {
30
+ return new Response(JSON.stringify({ error: "Invalid signature" }), {
31
+ status: 401,
32
+ headers: { "Content-Type": "application/json" }
33
+ });
34
+ }
35
+ }
36
+ try {
37
+ const event = parseWebhookEvent(body);
38
+ if (config.onEvent && event.event && config.onEvent[event.event]) {
39
+ await config.onEvent[event.event](event);
40
+ }
41
+ return new Response(JSON.stringify({ received: true }), {
42
+ status: 200,
43
+ headers: { "Content-Type": "application/json" }
44
+ });
45
+ } catch (error) {
46
+ return new Response(JSON.stringify({ error: "Webhook processing failed" }), {
47
+ status: 500,
48
+ headers: { "Content-Type": "application/json" }
49
+ });
50
+ }
51
+ };
52
+ }
53
+
54
+ export { createWebhookHandler };
@@ -0,0 +1,109 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ReactNode } from 'react';
3
+ import { U as User, K as StorageFile, j as ApiResponse, A as ApiError } from './index-BkacIKdu.mjs';
4
+
5
+ interface MockUserOptions {
6
+ id?: string;
7
+ email?: string;
8
+ email_verified?: boolean;
9
+ phone?: string | null;
10
+ phone_verified?: boolean;
11
+ full_name?: string | null;
12
+ username?: string | null;
13
+ avatar_url?: string | null;
14
+ status?: 'active' | 'suspended' | 'pending_verification';
15
+ created_at?: string;
16
+ }
17
+ declare function createMockUser(options?: MockUserOptions): User;
18
+ interface MockFileOptions {
19
+ id?: string;
20
+ filename?: string;
21
+ content_type?: string;
22
+ size_bytes?: number;
23
+ is_public?: boolean;
24
+ created_at?: string;
25
+ scan_status?: string;
26
+ url?: string;
27
+ }
28
+ declare function createMockFile(options?: MockFileOptions): StorageFile;
29
+ interface MockClientConfig {
30
+ /** Simulated responses for specific paths */
31
+ responses?: Record<string, ApiResponse<unknown>>;
32
+ /** Default delay in ms (simulates network latency) */
33
+ delay?: number;
34
+ /** Whether to simulate errors */
35
+ simulateErrors?: boolean;
36
+ }
37
+ declare class MockScaleMuleClient {
38
+ private responses;
39
+ private delay;
40
+ private simulateErrors;
41
+ constructor(config?: MockClientConfig);
42
+ private simulateDelay;
43
+ initialize(): Promise<void>;
44
+ setSession(): Promise<void>;
45
+ clearSession(): Promise<void>;
46
+ getSessionToken(): string | null;
47
+ getUserId(): string | null;
48
+ isAuthenticated(): boolean;
49
+ request<T>(path: string): Promise<ApiResponse<T>>;
50
+ get<T>(path: string): Promise<ApiResponse<T>>;
51
+ post<T>(path: string): Promise<ApiResponse<T>>;
52
+ patch<T>(path: string): Promise<ApiResponse<T>>;
53
+ put<T>(path: string): Promise<ApiResponse<T>>;
54
+ delete<T>(path: string): Promise<ApiResponse<T>>;
55
+ upload<T>(): Promise<ApiResponse<T>>;
56
+ }
57
+ interface MockScaleMuleContextValue {
58
+ client: MockScaleMuleClient;
59
+ user: User | null;
60
+ setUser: (user: User | null) => void;
61
+ initializing: boolean;
62
+ error: ApiError | null;
63
+ setError: (error: ApiError | null) => void;
64
+ }
65
+ interface MockScaleMuleProviderProps {
66
+ children: ReactNode;
67
+ /** Initial user (null = not logged in) */
68
+ user?: User | null;
69
+ /** Initial loading state */
70
+ initializing?: boolean;
71
+ /** Initial error */
72
+ error?: ApiError | null;
73
+ /** Mock client config */
74
+ clientConfig?: MockClientConfig;
75
+ }
76
+ /**
77
+ * Mock provider for testing ScaleMule hooks
78
+ *
79
+ * @example
80
+ * ```tsx
81
+ * // Test authenticated state
82
+ * render(
83
+ * <MockScaleMuleProvider user={createMockUser()}>
84
+ * <MyComponent />
85
+ * </MockScaleMuleProvider>
86
+ * )
87
+ *
88
+ * // Test loading state
89
+ * render(
90
+ * <MockScaleMuleProvider initializing={true}>
91
+ * <MyComponent />
92
+ * </MockScaleMuleProvider>
93
+ * )
94
+ *
95
+ * // Test error state
96
+ * render(
97
+ * <MockScaleMuleProvider error={{ code: 'TEST', message: 'Error' }}>
98
+ * <MyComponent />
99
+ * </MockScaleMuleProvider>
100
+ * )
101
+ * ```
102
+ */
103
+ declare function MockScaleMuleProvider({ children, user: initialUser, initializing: initialInitializing, error: initialError, clientConfig, }: MockScaleMuleProviderProps): react_jsx_runtime.JSX.Element;
104
+ /**
105
+ * Hook to use mock context (for testing hook internals)
106
+ */
107
+ declare function useMockScaleMule(): MockScaleMuleContextValue;
108
+
109
+ export { type MockClientConfig, type MockFileOptions, MockScaleMuleClient, MockScaleMuleProvider, type MockScaleMuleProviderProps, type MockUserOptions, createMockFile, createMockUser, useMockScaleMule };
@@ -0,0 +1,109 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ReactNode } from 'react';
3
+ import { U as User, K as StorageFile, j as ApiResponse, A as ApiError } from './index-BkacIKdu.js';
4
+
5
+ interface MockUserOptions {
6
+ id?: string;
7
+ email?: string;
8
+ email_verified?: boolean;
9
+ phone?: string | null;
10
+ phone_verified?: boolean;
11
+ full_name?: string | null;
12
+ username?: string | null;
13
+ avatar_url?: string | null;
14
+ status?: 'active' | 'suspended' | 'pending_verification';
15
+ created_at?: string;
16
+ }
17
+ declare function createMockUser(options?: MockUserOptions): User;
18
+ interface MockFileOptions {
19
+ id?: string;
20
+ filename?: string;
21
+ content_type?: string;
22
+ size_bytes?: number;
23
+ is_public?: boolean;
24
+ created_at?: string;
25
+ scan_status?: string;
26
+ url?: string;
27
+ }
28
+ declare function createMockFile(options?: MockFileOptions): StorageFile;
29
+ interface MockClientConfig {
30
+ /** Simulated responses for specific paths */
31
+ responses?: Record<string, ApiResponse<unknown>>;
32
+ /** Default delay in ms (simulates network latency) */
33
+ delay?: number;
34
+ /** Whether to simulate errors */
35
+ simulateErrors?: boolean;
36
+ }
37
+ declare class MockScaleMuleClient {
38
+ private responses;
39
+ private delay;
40
+ private simulateErrors;
41
+ constructor(config?: MockClientConfig);
42
+ private simulateDelay;
43
+ initialize(): Promise<void>;
44
+ setSession(): Promise<void>;
45
+ clearSession(): Promise<void>;
46
+ getSessionToken(): string | null;
47
+ getUserId(): string | null;
48
+ isAuthenticated(): boolean;
49
+ request<T>(path: string): Promise<ApiResponse<T>>;
50
+ get<T>(path: string): Promise<ApiResponse<T>>;
51
+ post<T>(path: string): Promise<ApiResponse<T>>;
52
+ patch<T>(path: string): Promise<ApiResponse<T>>;
53
+ put<T>(path: string): Promise<ApiResponse<T>>;
54
+ delete<T>(path: string): Promise<ApiResponse<T>>;
55
+ upload<T>(): Promise<ApiResponse<T>>;
56
+ }
57
+ interface MockScaleMuleContextValue {
58
+ client: MockScaleMuleClient;
59
+ user: User | null;
60
+ setUser: (user: User | null) => void;
61
+ initializing: boolean;
62
+ error: ApiError | null;
63
+ setError: (error: ApiError | null) => void;
64
+ }
65
+ interface MockScaleMuleProviderProps {
66
+ children: ReactNode;
67
+ /** Initial user (null = not logged in) */
68
+ user?: User | null;
69
+ /** Initial loading state */
70
+ initializing?: boolean;
71
+ /** Initial error */
72
+ error?: ApiError | null;
73
+ /** Mock client config */
74
+ clientConfig?: MockClientConfig;
75
+ }
76
+ /**
77
+ * Mock provider for testing ScaleMule hooks
78
+ *
79
+ * @example
80
+ * ```tsx
81
+ * // Test authenticated state
82
+ * render(
83
+ * <MockScaleMuleProvider user={createMockUser()}>
84
+ * <MyComponent />
85
+ * </MockScaleMuleProvider>
86
+ * )
87
+ *
88
+ * // Test loading state
89
+ * render(
90
+ * <MockScaleMuleProvider initializing={true}>
91
+ * <MyComponent />
92
+ * </MockScaleMuleProvider>
93
+ * )
94
+ *
95
+ * // Test error state
96
+ * render(
97
+ * <MockScaleMuleProvider error={{ code: 'TEST', message: 'Error' }}>
98
+ * <MyComponent />
99
+ * </MockScaleMuleProvider>
100
+ * )
101
+ * ```
102
+ */
103
+ declare function MockScaleMuleProvider({ children, user: initialUser, initializing: initialInitializing, error: initialError, clientConfig, }: MockScaleMuleProviderProps): react_jsx_runtime.JSX.Element;
104
+ /**
105
+ * Hook to use mock context (for testing hook internals)
106
+ */
107
+ declare function useMockScaleMule(): MockScaleMuleContextValue;
108
+
109
+ export { type MockClientConfig, type MockFileOptions, MockScaleMuleClient, MockScaleMuleProvider, type MockScaleMuleProviderProps, type MockUserOptions, createMockFile, createMockUser, useMockScaleMule };
@@ -0,0 +1,134 @@
1
+ 'use strict';
2
+
3
+ var react = require('react');
4
+ var jsxRuntime = require('react/jsx-runtime');
5
+
6
+ function createMockUser(options = {}) {
7
+ return {
8
+ id: options.id ?? "mock-user-id-123",
9
+ email: options.email ?? "test@example.com",
10
+ email_verified: options.email_verified ?? true,
11
+ phone: options.phone ?? null,
12
+ phone_verified: options.phone_verified ?? false,
13
+ full_name: options.full_name ?? "Test User",
14
+ username: options.username ?? null,
15
+ avatar_url: options.avatar_url ?? null,
16
+ status: options.status ?? "active",
17
+ created_at: options.created_at ?? (/* @__PURE__ */ new Date()).toISOString()
18
+ };
19
+ }
20
+ function createMockFile(options = {}) {
21
+ const id = options.id ?? `mock-file-${Math.random().toString(36).slice(2)}`;
22
+ return {
23
+ id,
24
+ filename: options.filename ?? "test-file.jpg",
25
+ content_type: options.content_type ?? "image/jpeg",
26
+ size_bytes: options.size_bytes ?? 1024,
27
+ is_public: options.is_public ?? false,
28
+ created_at: options.created_at ?? (/* @__PURE__ */ new Date()).toISOString(),
29
+ scan_status: options.scan_status ?? "clean",
30
+ url: options.url ?? `https://storage.scalemule.com/files/${id}`
31
+ };
32
+ }
33
+ var MockScaleMuleClient = class {
34
+ constructor(config = {}) {
35
+ this.responses = config.responses ?? {};
36
+ this.delay = config.delay ?? 0;
37
+ this.simulateErrors = config.simulateErrors ?? false;
38
+ }
39
+ async simulateDelay() {
40
+ if (this.delay > 0) {
41
+ await new Promise((resolve) => setTimeout(resolve, this.delay));
42
+ }
43
+ }
44
+ async initialize() {
45
+ await this.simulateDelay();
46
+ }
47
+ async setSession() {
48
+ await this.simulateDelay();
49
+ }
50
+ async clearSession() {
51
+ await this.simulateDelay();
52
+ }
53
+ getSessionToken() {
54
+ return "mock-session-token";
55
+ }
56
+ getUserId() {
57
+ return "mock-user-id";
58
+ }
59
+ isAuthenticated() {
60
+ return true;
61
+ }
62
+ async request(path) {
63
+ await this.simulateDelay();
64
+ if (this.simulateErrors) {
65
+ return {
66
+ success: false,
67
+ error: { code: "MOCK_ERROR", message: "Simulated error" }
68
+ };
69
+ }
70
+ if (this.responses[path]) {
71
+ return this.responses[path];
72
+ }
73
+ return { success: true, data: {} };
74
+ }
75
+ async get(path) {
76
+ return this.request(path);
77
+ }
78
+ async post(path) {
79
+ return this.request(path);
80
+ }
81
+ async patch(path) {
82
+ return this.request(path);
83
+ }
84
+ async put(path) {
85
+ return this.request(path);
86
+ }
87
+ async delete(path) {
88
+ return this.request(path);
89
+ }
90
+ async upload() {
91
+ await this.simulateDelay();
92
+ return { success: true, data: {} };
93
+ }
94
+ };
95
+ var MockScaleMuleContext = react.createContext(null);
96
+ function MockScaleMuleProvider({
97
+ children,
98
+ user: initialUser = null,
99
+ initializing: initialInitializing = false,
100
+ error: initialError = null,
101
+ clientConfig
102
+ }) {
103
+ const [user, setUser] = react.useState(initialUser);
104
+ const [error, setError] = react.useState(initialError);
105
+ const client = react.useMemo(
106
+ () => new MockScaleMuleClient(clientConfig),
107
+ [clientConfig]
108
+ );
109
+ const value = react.useMemo(
110
+ () => ({
111
+ client,
112
+ user,
113
+ setUser,
114
+ initializing: initialInitializing,
115
+ error,
116
+ setError
117
+ }),
118
+ [client, user, initialInitializing, error]
119
+ );
120
+ return /* @__PURE__ */ jsxRuntime.jsx(MockScaleMuleContext.Provider, { value, children });
121
+ }
122
+ function useMockScaleMule() {
123
+ const context = react.useContext(MockScaleMuleContext);
124
+ if (!context) {
125
+ throw new Error("useMockScaleMule must be used within MockScaleMuleProvider");
126
+ }
127
+ return context;
128
+ }
129
+
130
+ exports.MockScaleMuleClient = MockScaleMuleClient;
131
+ exports.MockScaleMuleProvider = MockScaleMuleProvider;
132
+ exports.createMockFile = createMockFile;
133
+ exports.createMockUser = createMockUser;
134
+ exports.useMockScaleMule = useMockScaleMule;
@@ -0,0 +1,128 @@
1
+ import { createContext, useState, useMemo, useContext } from 'react';
2
+ import { jsx } from 'react/jsx-runtime';
3
+
4
+ function createMockUser(options = {}) {
5
+ return {
6
+ id: options.id ?? "mock-user-id-123",
7
+ email: options.email ?? "test@example.com",
8
+ email_verified: options.email_verified ?? true,
9
+ phone: options.phone ?? null,
10
+ phone_verified: options.phone_verified ?? false,
11
+ full_name: options.full_name ?? "Test User",
12
+ username: options.username ?? null,
13
+ avatar_url: options.avatar_url ?? null,
14
+ status: options.status ?? "active",
15
+ created_at: options.created_at ?? (/* @__PURE__ */ new Date()).toISOString()
16
+ };
17
+ }
18
+ function createMockFile(options = {}) {
19
+ const id = options.id ?? `mock-file-${Math.random().toString(36).slice(2)}`;
20
+ return {
21
+ id,
22
+ filename: options.filename ?? "test-file.jpg",
23
+ content_type: options.content_type ?? "image/jpeg",
24
+ size_bytes: options.size_bytes ?? 1024,
25
+ is_public: options.is_public ?? false,
26
+ created_at: options.created_at ?? (/* @__PURE__ */ new Date()).toISOString(),
27
+ scan_status: options.scan_status ?? "clean",
28
+ url: options.url ?? `https://storage.scalemule.com/files/${id}`
29
+ };
30
+ }
31
+ var MockScaleMuleClient = class {
32
+ constructor(config = {}) {
33
+ this.responses = config.responses ?? {};
34
+ this.delay = config.delay ?? 0;
35
+ this.simulateErrors = config.simulateErrors ?? false;
36
+ }
37
+ async simulateDelay() {
38
+ if (this.delay > 0) {
39
+ await new Promise((resolve) => setTimeout(resolve, this.delay));
40
+ }
41
+ }
42
+ async initialize() {
43
+ await this.simulateDelay();
44
+ }
45
+ async setSession() {
46
+ await this.simulateDelay();
47
+ }
48
+ async clearSession() {
49
+ await this.simulateDelay();
50
+ }
51
+ getSessionToken() {
52
+ return "mock-session-token";
53
+ }
54
+ getUserId() {
55
+ return "mock-user-id";
56
+ }
57
+ isAuthenticated() {
58
+ return true;
59
+ }
60
+ async request(path) {
61
+ await this.simulateDelay();
62
+ if (this.simulateErrors) {
63
+ return {
64
+ success: false,
65
+ error: { code: "MOCK_ERROR", message: "Simulated error" }
66
+ };
67
+ }
68
+ if (this.responses[path]) {
69
+ return this.responses[path];
70
+ }
71
+ return { success: true, data: {} };
72
+ }
73
+ async get(path) {
74
+ return this.request(path);
75
+ }
76
+ async post(path) {
77
+ return this.request(path);
78
+ }
79
+ async patch(path) {
80
+ return this.request(path);
81
+ }
82
+ async put(path) {
83
+ return this.request(path);
84
+ }
85
+ async delete(path) {
86
+ return this.request(path);
87
+ }
88
+ async upload() {
89
+ await this.simulateDelay();
90
+ return { success: true, data: {} };
91
+ }
92
+ };
93
+ var MockScaleMuleContext = createContext(null);
94
+ function MockScaleMuleProvider({
95
+ children,
96
+ user: initialUser = null,
97
+ initializing: initialInitializing = false,
98
+ error: initialError = null,
99
+ clientConfig
100
+ }) {
101
+ const [user, setUser] = useState(initialUser);
102
+ const [error, setError] = useState(initialError);
103
+ const client = useMemo(
104
+ () => new MockScaleMuleClient(clientConfig),
105
+ [clientConfig]
106
+ );
107
+ const value = useMemo(
108
+ () => ({
109
+ client,
110
+ user,
111
+ setUser,
112
+ initializing: initialInitializing,
113
+ error,
114
+ setError
115
+ }),
116
+ [client, user, initialInitializing, error]
117
+ );
118
+ return /* @__PURE__ */ jsx(MockScaleMuleContext.Provider, { value, children });
119
+ }
120
+ function useMockScaleMule() {
121
+ const context = useContext(MockScaleMuleContext);
122
+ if (!context) {
123
+ throw new Error("useMockScaleMule must be used within MockScaleMuleProvider");
124
+ }
125
+ return context;
126
+ }
127
+
128
+ export { MockScaleMuleClient, MockScaleMuleProvider, createMockFile, createMockUser, useMockScaleMule };