@umituz/react-native-google-stitch-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.
- package/LICENSE +20 -0
- package/README.md +88 -0
- package/package.json +61 -0
- package/src/domain/entities/index.ts +6 -0
- package/src/domain/entities/stitch.entity.ts +15 -0
- package/src/domain/interfaces/index.ts +6 -0
- package/src/domain/interfaces/stitch-service.interface.ts +33 -0
- package/src/domains/core/index.ts +23 -0
- package/src/index.ts +18 -0
- package/src/infrastructure/constants/index.ts +6 -0
- package/src/infrastructure/constants/stitch.constants.ts +15 -0
- package/src/infrastructure/services/index.ts +7 -0
- package/src/infrastructure/services/stitch.service.ts +87 -0
- package/src/infrastructure/utils/index.ts +6 -0
- package/src/init/index.ts +23 -0
- package/src/presentation/components/index.ts +6 -0
- package/src/presentation/hooks/index.ts +7 -0
- package/src/presentation/hooks/useStitch.ts +119 -0
- package/src/presentation/stores/index.ts +6 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# @umituz/react-native-google-stitch-sdk
|
|
2
|
+
|
|
3
|
+
React Native wrapper for Google Labs Stitch SDK with TypeScript support.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @umituz/react-native-google-stitch-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
// Initialize the SDK
|
|
15
|
+
import { initializeStitchSDK } from '@umituz/react-native-google-stitch-sdk/init';
|
|
16
|
+
|
|
17
|
+
initializeStitchSDK({
|
|
18
|
+
apiKey: 'your-api-key',
|
|
19
|
+
baseUrl: 'https://api.example.com',
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// Use the hook in your component
|
|
23
|
+
import { useStitch } from '@umituz/react-native-google-stitch-sdk/core';
|
|
24
|
+
|
|
25
|
+
function MyComponent() {
|
|
26
|
+
const { readProject, writeProject, isLoading, error } = useStitch();
|
|
27
|
+
|
|
28
|
+
const handleRead = async () => {
|
|
29
|
+
const project = await readProject('project-id');
|
|
30
|
+
console.log(project);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
// Your JSX
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Available Subpaths
|
|
40
|
+
|
|
41
|
+
### `/core`
|
|
42
|
+
Core SDK functionality - services, hooks, and types.
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import { useStitch, stitchService } from '@umituz/react-native-google-stitch-sdk/core';
|
|
46
|
+
import type { StitchProject } from '@umituz/react-native-google-stitch-sdk/core';
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### `/init`
|
|
50
|
+
Initialization utilities.
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
import { initializeStitchSDK, isStitchSDKInitialized } from '@umituz/react-native-google-stitch-sdk/init';
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## API Reference
|
|
57
|
+
|
|
58
|
+
### `useStitch` Hook
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
const {
|
|
62
|
+
isLoading,
|
|
63
|
+
error,
|
|
64
|
+
readProject,
|
|
65
|
+
writeProject,
|
|
66
|
+
updateProject,
|
|
67
|
+
deleteProject,
|
|
68
|
+
listProjects,
|
|
69
|
+
} = useStitch({ apiKey: 'your-key', autoInitialize: true });
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Direct Service Usage
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
import { stitchService } from '@umituz/react-native-google-stitch-sdk/core';
|
|
76
|
+
|
|
77
|
+
stitchService.initialize({ apiKey: 'your-key' });
|
|
78
|
+
const project = await stitchService.readProject('project-id');
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## License
|
|
82
|
+
|
|
83
|
+
MIT
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
**@umituz** - React Native packages
|
|
88
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@umituz/react-native-google-stitch-sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "React Native wrapper for Google Labs Stitch SDK with TypeScript support",
|
|
5
|
+
"main": "./src/index.ts",
|
|
6
|
+
"types": "./src/index.ts",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./src/index.ts",
|
|
10
|
+
"./core": "./src/domains/core/index.ts",
|
|
11
|
+
"./init": "./src/init/index.ts",
|
|
12
|
+
"./package.json": "./package.json"
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"typecheck": "tsc --noEmit",
|
|
16
|
+
"lint": "eslint \"src/**/*.{ts,tsx}\"",
|
|
17
|
+
"version:patch": "npm version patch -m 'chore: release v%s'",
|
|
18
|
+
"version:minor": "npm version minor -m 'chore: release v%s'",
|
|
19
|
+
"version:major": "npm version major -m 'chore: release v%s'"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"react-native",
|
|
23
|
+
"google",
|
|
24
|
+
"stitch",
|
|
25
|
+
"sdk",
|
|
26
|
+
"typescript"
|
|
27
|
+
],
|
|
28
|
+
"author": "umituz",
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "https://github.com/umituz/react-native-google-stitch-sdk.git"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"react": ">=18.2.0",
|
|
39
|
+
"react-native": ">=0.74.0"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@eslint/compat": "^1.3.2",
|
|
43
|
+
"@eslint/eslintrc": "^3.3.1",
|
|
44
|
+
"@eslint/js": "^9.35.0",
|
|
45
|
+
"@types/react": "^19.1.12",
|
|
46
|
+
"@typescript-eslint/eslint-plugin": "^8.57.1",
|
|
47
|
+
"@typescript-eslint/parser": "^8.57.1",
|
|
48
|
+
"eslint": "^9.35.0",
|
|
49
|
+
"eslint-config-prettier": "^10.1.8",
|
|
50
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
51
|
+
"prettier": "^3.0.0",
|
|
52
|
+
"react": "19.2.0",
|
|
53
|
+
"react-native": "0.83.2",
|
|
54
|
+
"typescript": "^5.9.2"
|
|
55
|
+
},
|
|
56
|
+
"files": [
|
|
57
|
+
"src",
|
|
58
|
+
"README.md",
|
|
59
|
+
"LICENSE"
|
|
60
|
+
]
|
|
61
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stitch Project Entity
|
|
3
|
+
* @description Represents a Google Labs Stitch SDK project
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export interface StitchProject {
|
|
7
|
+
readonly id: string;
|
|
8
|
+
readonly name: string;
|
|
9
|
+
readonly description?: string;
|
|
10
|
+
readonly createdAt: Date;
|
|
11
|
+
readonly updatedAt: Date;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type StitchProjectCreateInput = Omit<StitchProject, 'id' | 'createdAt' | 'updatedAt'>;
|
|
15
|
+
export type StitchProjectUpdateInput = Partial<StitchProjectCreateInput>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stitch Service Interface
|
|
3
|
+
* @description Contract for Stitch SDK service implementations
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { StitchProject, StitchProjectCreateInput, StitchProjectUpdateInput } from '../entities';
|
|
7
|
+
|
|
8
|
+
export interface IStitchService {
|
|
9
|
+
/**
|
|
10
|
+
* Read a project by ID
|
|
11
|
+
*/
|
|
12
|
+
readProject(_projectId: string): Promise<StitchProject>;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Write/create a new project
|
|
16
|
+
*/
|
|
17
|
+
writeProject(_input: StitchProjectCreateInput): Promise<StitchProject>;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Update an existing project
|
|
21
|
+
*/
|
|
22
|
+
updateProject(_projectId: string, _input: StitchProjectUpdateInput): Promise<StitchProject>;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Delete a project
|
|
26
|
+
*/
|
|
27
|
+
deleteProject(_projectId: string): Promise<void>;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* List all projects
|
|
31
|
+
*/
|
|
32
|
+
listProjects(): Promise<StitchProject[]>;
|
|
33
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core Domain
|
|
3
|
+
* @description Core Stitch SDK functionality
|
|
4
|
+
* Subpath: @umituz/react-native-google-stitch-sdk/core
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// Domain entities
|
|
8
|
+
export type {
|
|
9
|
+
StitchProject,
|
|
10
|
+
StitchProjectCreateInput,
|
|
11
|
+
StitchProjectUpdateInput,
|
|
12
|
+
} from '../../domain/entities';
|
|
13
|
+
|
|
14
|
+
// Infrastructure services
|
|
15
|
+
export { stitchService } from '../../infrastructure/services';
|
|
16
|
+
export type { StitchServiceConfig } from '../../infrastructure/services';
|
|
17
|
+
|
|
18
|
+
// Presentation hooks
|
|
19
|
+
export { useStitch } from '../../presentation/hooks';
|
|
20
|
+
export type { UseStitchConfig, UseStitchReturn } from '../../presentation/hooks';
|
|
21
|
+
|
|
22
|
+
// Constants
|
|
23
|
+
export { STITCH_DEFAULT_CONFIG, STITCH_ERROR_MESSAGES } from '../../infrastructure/constants';
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @umituz/react-native-google-stitch-sdk
|
|
3
|
+
* React Native wrapper for Google Labs Stitch SDK with TypeScript support
|
|
4
|
+
*
|
|
5
|
+
* ⚠️ IMPORTANT: Apps should NOT use this root barrel import.
|
|
6
|
+
* Use subpath imports instead for better tree-shaking:
|
|
7
|
+
*
|
|
8
|
+
* ❌ DON'T: import { useStitch } from '@umituz/react-native-google-stitch-sdk'
|
|
9
|
+
* ✅ DO: import { useStitch } from '@umituz/react-native-google-stitch-sdk/core'
|
|
10
|
+
*
|
|
11
|
+
* Available subpaths:
|
|
12
|
+
* - /core: Core SDK functionality (services, hooks, types)
|
|
13
|
+
* - /init: Initialization utilities
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
// Re-export everything for backward compatibility
|
|
17
|
+
export * from './domains/core';
|
|
18
|
+
export * from './init';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stitch Constants
|
|
3
|
+
* @description Configuration constants for Stitch SDK
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export const STITCH_DEFAULT_CONFIG = {
|
|
7
|
+
API_TIMEOUT: 30000,
|
|
8
|
+
MAX_RETRIES: 3,
|
|
9
|
+
} as const;
|
|
10
|
+
|
|
11
|
+
export const STITCH_ERROR_MESSAGES = {
|
|
12
|
+
NOT_INITIALIZED: 'StitchService not initialized. Call initialize() first.',
|
|
13
|
+
INVALID_PROJECT_ID: 'Invalid project ID provided.',
|
|
14
|
+
NETWORK_ERROR: 'Network error occurred while communicating with Stitch SDK.',
|
|
15
|
+
} as const;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stitch Service
|
|
3
|
+
* @description Main service implementation for Google Labs Stitch SDK wrapper
|
|
4
|
+
* @note This is a placeholder implementation. Replace with actual SDK calls when available.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { IStitchService } from '../../domain/interfaces';
|
|
8
|
+
import type { StitchProject, StitchProjectCreateInput, StitchProjectUpdateInput } from '../../domain/entities';
|
|
9
|
+
|
|
10
|
+
export interface StitchServiceConfig {
|
|
11
|
+
apiKey?: string;
|
|
12
|
+
baseUrl?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
class StitchService implements IStitchService {
|
|
16
|
+
private config: StitchServiceConfig | null = null;
|
|
17
|
+
|
|
18
|
+
initialize(config: StitchServiceConfig): void {
|
|
19
|
+
this.config = config;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
isInitialized(): boolean {
|
|
23
|
+
return this.config !== null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async readProject(projectId: string): Promise<StitchProject> {
|
|
27
|
+
this.ensureInitialized();
|
|
28
|
+
|
|
29
|
+
// TODO: Replace with actual SDK call
|
|
30
|
+
// Example: const response = await fetch(`${this.config.baseUrl}/projects/${projectId}`);
|
|
31
|
+
return {
|
|
32
|
+
id: projectId,
|
|
33
|
+
name: 'Sample Project',
|
|
34
|
+
description: 'Placeholder project',
|
|
35
|
+
createdAt: new Date(),
|
|
36
|
+
updatedAt: new Date(),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async writeProject(input: StitchProjectCreateInput): Promise<StitchProject> {
|
|
41
|
+
this.ensureInitialized();
|
|
42
|
+
|
|
43
|
+
// TODO: Replace with actual SDK call
|
|
44
|
+
const newProject: StitchProject = {
|
|
45
|
+
id: `project_${Date.now()}`,
|
|
46
|
+
...input,
|
|
47
|
+
createdAt: new Date(),
|
|
48
|
+
updatedAt: new Date(),
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
return newProject;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async updateProject(projectId: string, input: StitchProjectUpdateInput): Promise<StitchProject> {
|
|
55
|
+
this.ensureInitialized();
|
|
56
|
+
|
|
57
|
+
// TODO: Replace with actual SDK call
|
|
58
|
+
const existing = await this.readProject(projectId);
|
|
59
|
+
return {
|
|
60
|
+
...existing,
|
|
61
|
+
...input,
|
|
62
|
+
updatedAt: new Date(),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async deleteProject(_projectId: string): Promise<void> {
|
|
67
|
+
this.ensureInitialized();
|
|
68
|
+
|
|
69
|
+
// TODO: Replace with actual SDK call
|
|
70
|
+
// Placeholder: no-op delete operation
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async listProjects(): Promise<StitchProject[]> {
|
|
74
|
+
this.ensureInitialized();
|
|
75
|
+
|
|
76
|
+
// TODO: Replace with actual SDK call
|
|
77
|
+
return [];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
private ensureInitialized(): void {
|
|
81
|
+
if (!this.isInitialized()) {
|
|
82
|
+
throw new Error('StitchService not initialized. Call initialize() first.');
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export const stitchService = new StitchService();
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Initialization Module
|
|
3
|
+
* @description Initialize Stitch SDK with configuration
|
|
4
|
+
* Subpath: @umituz/react-native-google-stitch-sdk/init
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { stitchService } from '../infrastructure/services';
|
|
8
|
+
import type { StitchServiceConfig } from '../infrastructure/services';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Initialize the Stitch SDK
|
|
12
|
+
* @param config - Configuration object
|
|
13
|
+
*/
|
|
14
|
+
export function initializeStitchSDK(config: StitchServiceConfig): void {
|
|
15
|
+
stitchService.initialize(config);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Check if SDK is initialized
|
|
20
|
+
*/
|
|
21
|
+
export function isStitchSDKInitialized(): boolean {
|
|
22
|
+
return stitchService.isInitialized();
|
|
23
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useStitch Hook
|
|
3
|
+
* @description React hook for Stitch SDK operations
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
7
|
+
import type { StitchProject, StitchProjectCreateInput, StitchProjectUpdateInput } from '../../domain/entities';
|
|
8
|
+
import { stitchService } from '../../infrastructure/services';
|
|
9
|
+
|
|
10
|
+
export interface UseStitchConfig {
|
|
11
|
+
apiKey?: string;
|
|
12
|
+
baseUrl?: string;
|
|
13
|
+
autoInitialize?: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface UseStitchReturn {
|
|
17
|
+
isLoading: boolean;
|
|
18
|
+
error: Error | null;
|
|
19
|
+
readProject: (_projectId: string) => Promise<StitchProject>;
|
|
20
|
+
writeProject: (_input: StitchProjectCreateInput) => Promise<StitchProject>;
|
|
21
|
+
updateProject: (_projectId: string, _input: StitchProjectUpdateInput) => Promise<StitchProject>;
|
|
22
|
+
deleteProject: (_projectId: string) => Promise<void>;
|
|
23
|
+
listProjects: () => Promise<StitchProject[]>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function useStitch(config?: UseStitchConfig): UseStitchReturn {
|
|
27
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
28
|
+
const [error, setError] = useState<Error | null>(null);
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (config?.autoInitialize && config.apiKey) {
|
|
32
|
+
stitchService.initialize({ apiKey: config.apiKey, baseUrl: config.baseUrl });
|
|
33
|
+
}
|
|
34
|
+
}, [config]);
|
|
35
|
+
|
|
36
|
+
const readProject = useCallback(async (projectId: string) => {
|
|
37
|
+
setIsLoading(true);
|
|
38
|
+
setError(null);
|
|
39
|
+
try {
|
|
40
|
+
const project = await stitchService.readProject(projectId);
|
|
41
|
+
return project;
|
|
42
|
+
} catch (err) {
|
|
43
|
+
const error = err instanceof Error ? err : new Error('Failed to read project');
|
|
44
|
+
setError(error);
|
|
45
|
+
throw error;
|
|
46
|
+
} finally {
|
|
47
|
+
setIsLoading(false);
|
|
48
|
+
}
|
|
49
|
+
}, []);
|
|
50
|
+
|
|
51
|
+
const writeProject = useCallback(async (input: StitchProjectCreateInput) => {
|
|
52
|
+
setIsLoading(true);
|
|
53
|
+
setError(null);
|
|
54
|
+
try {
|
|
55
|
+
const project = await stitchService.writeProject(input);
|
|
56
|
+
return project;
|
|
57
|
+
} catch (err) {
|
|
58
|
+
const error = err instanceof Error ? err : new Error('Failed to write project');
|
|
59
|
+
setError(error);
|
|
60
|
+
throw error;
|
|
61
|
+
} finally {
|
|
62
|
+
setIsLoading(false);
|
|
63
|
+
}
|
|
64
|
+
}, []);
|
|
65
|
+
|
|
66
|
+
const updateProject = useCallback(async (projectId: string, input: StitchProjectUpdateInput) => {
|
|
67
|
+
setIsLoading(true);
|
|
68
|
+
setError(null);
|
|
69
|
+
try {
|
|
70
|
+
const project = await stitchService.updateProject(projectId, input);
|
|
71
|
+
return project;
|
|
72
|
+
} catch (err) {
|
|
73
|
+
const error = err instanceof Error ? err : new Error('Failed to update project');
|
|
74
|
+
setError(error);
|
|
75
|
+
throw error;
|
|
76
|
+
} finally {
|
|
77
|
+
setIsLoading(false);
|
|
78
|
+
}
|
|
79
|
+
}, []);
|
|
80
|
+
|
|
81
|
+
const deleteProject = useCallback(async (projectId: string) => {
|
|
82
|
+
setIsLoading(true);
|
|
83
|
+
setError(null);
|
|
84
|
+
try {
|
|
85
|
+
await stitchService.deleteProject(projectId);
|
|
86
|
+
} catch (err) {
|
|
87
|
+
const error = err instanceof Error ? err : new Error('Failed to delete project');
|
|
88
|
+
setError(error);
|
|
89
|
+
throw error;
|
|
90
|
+
} finally {
|
|
91
|
+
setIsLoading(false);
|
|
92
|
+
}
|
|
93
|
+
}, []);
|
|
94
|
+
|
|
95
|
+
const listProjects = useCallback(async () => {
|
|
96
|
+
setIsLoading(true);
|
|
97
|
+
setError(null);
|
|
98
|
+
try {
|
|
99
|
+
const projects = await stitchService.listProjects();
|
|
100
|
+
return projects;
|
|
101
|
+
} catch (err) {
|
|
102
|
+
const error = err instanceof Error ? err : new Error('Failed to list projects');
|
|
103
|
+
setError(error);
|
|
104
|
+
throw error;
|
|
105
|
+
} finally {
|
|
106
|
+
setIsLoading(false);
|
|
107
|
+
}
|
|
108
|
+
}, []);
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
isLoading,
|
|
112
|
+
error,
|
|
113
|
+
readProject,
|
|
114
|
+
writeProject,
|
|
115
|
+
updateProject,
|
|
116
|
+
deleteProject,
|
|
117
|
+
listProjects,
|
|
118
|
+
};
|
|
119
|
+
}
|