@htlkg/data 0.0.1 → 0.0.3
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/README.md +53 -0
- package/dist/client/index.d.ts +117 -31
- package/dist/client/index.js +74 -22
- package/dist/client/index.js.map +1 -1
- package/dist/content-collections/index.js +20 -24
- package/dist/content-collections/index.js.map +1 -1
- package/dist/hooks/index.d.ts +113 -5
- package/dist/hooks/index.js +165 -182
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.d.ts +8 -4
- package/dist/index.js +305 -182
- package/dist/index.js.map +1 -1
- package/dist/queries/index.d.ts +78 -1
- package/dist/queries/index.js +47 -0
- package/dist/queries/index.js.map +1 -1
- package/dist/stores/index.d.ts +106 -0
- package/dist/stores/index.js +108 -0
- package/dist/stores/index.js.map +1 -0
- package/package.json +60 -37
- package/src/client/__tests__/server.test.ts +100 -0
- package/src/client/client.md +91 -0
- package/src/client/index.test.ts +232 -0
- package/src/client/index.ts +145 -0
- package/src/client/server.ts +118 -0
- package/src/content-collections/content-collections.md +87 -0
- package/src/content-collections/generator.ts +314 -0
- package/src/content-collections/index.ts +32 -0
- package/src/content-collections/schemas.ts +75 -0
- package/src/content-collections/sync.ts +139 -0
- package/src/hooks/README.md +293 -0
- package/src/hooks/createDataHook.ts +208 -0
- package/src/hooks/data-hook-errors.property.test.ts +270 -0
- package/src/hooks/data-hook-filters.property.test.ts +263 -0
- package/src/hooks/data-hooks.property.test.ts +190 -0
- package/src/hooks/hooks.test.ts +76 -0
- package/src/hooks/index.ts +21 -0
- package/src/hooks/useAccounts.ts +66 -0
- package/src/hooks/useBrands.ts +95 -0
- package/src/hooks/useProducts.ts +88 -0
- package/src/hooks/useUsers.ts +89 -0
- package/src/index.ts +32 -0
- package/src/mutations/accounts.ts +127 -0
- package/src/mutations/brands.ts +133 -0
- package/src/mutations/index.ts +32 -0
- package/src/mutations/mutations.md +96 -0
- package/src/mutations/users.ts +136 -0
- package/src/queries/accounts.ts +121 -0
- package/src/queries/brands.ts +176 -0
- package/src/queries/index.ts +45 -0
- package/src/queries/products.ts +282 -0
- package/src/queries/queries.md +88 -0
- package/src/queries/server-helpers.ts +114 -0
- package/src/queries/users.ts +199 -0
- package/src/stores/createStores.ts +148 -0
- package/src/stores/index.ts +15 -0
- package/src/stores/stores.md +104 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Account Mutation Functions
|
|
3
|
+
*
|
|
4
|
+
* Provides mutation functions for creating, updating, and deleting accounts.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { Account } from "@htlkg/core/types";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Input type for creating an account
|
|
11
|
+
*/
|
|
12
|
+
export interface CreateAccountInput {
|
|
13
|
+
name: string;
|
|
14
|
+
logo?: string;
|
|
15
|
+
subscription?: Record<string, any>;
|
|
16
|
+
settings?: Record<string, any>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Input type for updating an account
|
|
21
|
+
*/
|
|
22
|
+
export interface UpdateAccountInput {
|
|
23
|
+
id: string;
|
|
24
|
+
name?: string;
|
|
25
|
+
logo?: string;
|
|
26
|
+
subscription?: Record<string, any>;
|
|
27
|
+
settings?: Record<string, any>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Create a new account
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* import { createAccount } from '@htlkg/data/mutations';
|
|
36
|
+
* import { generateClient } from '@htlkg/data/client';
|
|
37
|
+
*
|
|
38
|
+
* const client = generateClient<Schema>();
|
|
39
|
+
* const account = await createAccount(client, {
|
|
40
|
+
* name: 'My Account',
|
|
41
|
+
* subscription: { plan: 'premium' }
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export async function createAccount<TClient = any>(
|
|
46
|
+
client: TClient,
|
|
47
|
+
input: CreateAccountInput,
|
|
48
|
+
): Promise<Account | null> {
|
|
49
|
+
try {
|
|
50
|
+
const { data, errors } = await (client as any).models.Account.create(input);
|
|
51
|
+
|
|
52
|
+
if (errors) {
|
|
53
|
+
console.error("[createAccount] GraphQL errors:", errors);
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return data as Account;
|
|
58
|
+
} catch (error) {
|
|
59
|
+
console.error("[createAccount] Error creating account:", error);
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Update an existing account
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* import { updateAccount } from '@htlkg/data/mutations';
|
|
70
|
+
* import { generateClient } from '@htlkg/data/client';
|
|
71
|
+
*
|
|
72
|
+
* const client = generateClient<Schema>();
|
|
73
|
+
* const account = await updateAccount(client, {
|
|
74
|
+
* id: 'account-123',
|
|
75
|
+
* name: 'Updated Account Name'
|
|
76
|
+
* });
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export async function updateAccount<TClient = any>(
|
|
80
|
+
client: TClient,
|
|
81
|
+
input: UpdateAccountInput,
|
|
82
|
+
): Promise<Account | null> {
|
|
83
|
+
try {
|
|
84
|
+
const { data, errors } = await (client as any).models.Account.update(input);
|
|
85
|
+
|
|
86
|
+
if (errors) {
|
|
87
|
+
console.error("[updateAccount] GraphQL errors:", errors);
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return data as Account;
|
|
92
|
+
} catch (error) {
|
|
93
|
+
console.error("[updateAccount] Error updating account:", error);
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Delete an account
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* import { deleteAccount } from '@htlkg/data/mutations';
|
|
104
|
+
* import { generateClient } from '@htlkg/data/client';
|
|
105
|
+
*
|
|
106
|
+
* const client = generateClient<Schema>();
|
|
107
|
+
* await deleteAccount(client, 'account-123');
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
export async function deleteAccount<TClient = any>(
|
|
111
|
+
client: TClient,
|
|
112
|
+
id: string,
|
|
113
|
+
): Promise<boolean> {
|
|
114
|
+
try {
|
|
115
|
+
const { errors } = await (client as any).models.Account.delete({ id });
|
|
116
|
+
|
|
117
|
+
if (errors) {
|
|
118
|
+
console.error("[deleteAccount] GraphQL errors:", errors);
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return true;
|
|
123
|
+
} catch (error) {
|
|
124
|
+
console.error("[deleteAccount] Error deleting account:", error);
|
|
125
|
+
throw error;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Brand Mutation Functions
|
|
3
|
+
*
|
|
4
|
+
* Provides mutation functions for creating, updating, and deleting brands.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { Brand } from "@htlkg/core/types";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Input type for creating a brand
|
|
11
|
+
*/
|
|
12
|
+
export interface CreateBrandInput {
|
|
13
|
+
accountId: string;
|
|
14
|
+
name: string;
|
|
15
|
+
logo?: string;
|
|
16
|
+
timezone?: string;
|
|
17
|
+
status?: "active" | "inactive" | "maintenance" | "suspended";
|
|
18
|
+
settings?: Record<string, any>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Input type for updating a brand
|
|
23
|
+
*/
|
|
24
|
+
export interface UpdateBrandInput {
|
|
25
|
+
id: string;
|
|
26
|
+
name?: string;
|
|
27
|
+
logo?: string;
|
|
28
|
+
timezone?: string;
|
|
29
|
+
status?: "active" | "inactive" | "maintenance" | "suspended";
|
|
30
|
+
settings?: Record<string, any>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Create a new brand
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* import { createBrand } from '@htlkg/data/mutations';
|
|
39
|
+
* import { generateClient } from '@htlkg/data/client';
|
|
40
|
+
*
|
|
41
|
+
* const client = generateClient<Schema>();
|
|
42
|
+
* const brand = await createBrand(client, {
|
|
43
|
+
* accountId: 'account-123',
|
|
44
|
+
* name: 'My Brand',
|
|
45
|
+
* timezone: 'America/New_York',
|
|
46
|
+
* status: 'active'
|
|
47
|
+
* });
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export async function createBrand<TClient = any>(
|
|
51
|
+
client: TClient,
|
|
52
|
+
input: CreateBrandInput,
|
|
53
|
+
): Promise<Brand | null> {
|
|
54
|
+
try {
|
|
55
|
+
const { data, errors } = await (client as any).models.Brand.create(input);
|
|
56
|
+
|
|
57
|
+
if (errors) {
|
|
58
|
+
console.error("[createBrand] GraphQL errors:", errors);
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return data as Brand;
|
|
63
|
+
} catch (error) {
|
|
64
|
+
console.error("[createBrand] Error creating brand:", error);
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Update an existing brand
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* import { updateBrand } from '@htlkg/data/mutations';
|
|
75
|
+
* import { generateClient } from '@htlkg/data/client';
|
|
76
|
+
*
|
|
77
|
+
* const client = generateClient<Schema>();
|
|
78
|
+
* const brand = await updateBrand(client, {
|
|
79
|
+
* id: 'brand-123',
|
|
80
|
+
* name: 'Updated Brand Name',
|
|
81
|
+
* status: 'maintenance'
|
|
82
|
+
* });
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export async function updateBrand<TClient = any>(
|
|
86
|
+
client: TClient,
|
|
87
|
+
input: UpdateBrandInput,
|
|
88
|
+
): Promise<Brand | null> {
|
|
89
|
+
try {
|
|
90
|
+
const { data, errors } = await (client as any).models.Brand.update(input);
|
|
91
|
+
|
|
92
|
+
if (errors) {
|
|
93
|
+
console.error("[updateBrand] GraphQL errors:", errors);
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return data as Brand;
|
|
98
|
+
} catch (error) {
|
|
99
|
+
console.error("[updateBrand] Error updating brand:", error);
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Delete a brand
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* import { deleteBrand } from '@htlkg/data/mutations';
|
|
110
|
+
* import { generateClient } from '@htlkg/data/client';
|
|
111
|
+
*
|
|
112
|
+
* const client = generateClient<Schema>();
|
|
113
|
+
* await deleteBrand(client, 'brand-123');
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
export async function deleteBrand<TClient = any>(
|
|
117
|
+
client: TClient,
|
|
118
|
+
id: string,
|
|
119
|
+
): Promise<boolean> {
|
|
120
|
+
try {
|
|
121
|
+
const { errors } = await (client as any).models.Brand.delete({ id });
|
|
122
|
+
|
|
123
|
+
if (errors) {
|
|
124
|
+
console.error("[deleteBrand] GraphQL errors:", errors);
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return true;
|
|
129
|
+
} catch (error) {
|
|
130
|
+
console.error("[deleteBrand] Error deleting brand:", error);
|
|
131
|
+
throw error;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mutation Functions for @htlkg/data
|
|
3
|
+
*
|
|
4
|
+
* Provides mutation functions for creating, updating, and deleting data via the GraphQL API.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// Brand mutations
|
|
8
|
+
export {
|
|
9
|
+
createBrand,
|
|
10
|
+
updateBrand,
|
|
11
|
+
deleteBrand,
|
|
12
|
+
type CreateBrandInput,
|
|
13
|
+
type UpdateBrandInput,
|
|
14
|
+
} from "./brands";
|
|
15
|
+
|
|
16
|
+
// Account mutations
|
|
17
|
+
export {
|
|
18
|
+
createAccount,
|
|
19
|
+
updateAccount,
|
|
20
|
+
deleteAccount,
|
|
21
|
+
type CreateAccountInput,
|
|
22
|
+
type UpdateAccountInput,
|
|
23
|
+
} from "./accounts";
|
|
24
|
+
|
|
25
|
+
// User mutations
|
|
26
|
+
export {
|
|
27
|
+
createUser,
|
|
28
|
+
updateUser,
|
|
29
|
+
deleteUser,
|
|
30
|
+
type CreateUserInput,
|
|
31
|
+
type UpdateUserInput,
|
|
32
|
+
} from "./users";
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# Mutations Module
|
|
2
|
+
|
|
3
|
+
GraphQL mutation functions for creating, updating, and deleting resources.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import {
|
|
9
|
+
createAccount,
|
|
10
|
+
updateAccount,
|
|
11
|
+
deleteAccount,
|
|
12
|
+
createBrand,
|
|
13
|
+
updateBrand,
|
|
14
|
+
deleteBrand,
|
|
15
|
+
createUser,
|
|
16
|
+
updateUser,
|
|
17
|
+
deleteUser,
|
|
18
|
+
} from '@htlkg/data/mutations';
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Account Mutations
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
// Create
|
|
25
|
+
const account = await createAccount(client, {
|
|
26
|
+
name: 'New Account',
|
|
27
|
+
settings: {},
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// Update
|
|
31
|
+
const updated = await updateAccount(client, {
|
|
32
|
+
id: 'account-123',
|
|
33
|
+
name: 'Updated Name',
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Delete
|
|
37
|
+
await deleteAccount(client, { id: 'account-123' });
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Brand Mutations
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
// Create
|
|
44
|
+
const brand = await createBrand(client, {
|
|
45
|
+
name: 'New Brand',
|
|
46
|
+
accountId: 'account-123',
|
|
47
|
+
timezone: 'Europe/Madrid',
|
|
48
|
+
status: 'active',
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// Update
|
|
52
|
+
const updated = await updateBrand(client, {
|
|
53
|
+
id: 'brand-456',
|
|
54
|
+
name: 'Updated Brand',
|
|
55
|
+
status: 'inactive',
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// Delete
|
|
59
|
+
await deleteBrand(client, { id: 'brand-456' });
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## User Mutations
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
// Create
|
|
66
|
+
const user = await createUser(client, {
|
|
67
|
+
email: 'user@example.com',
|
|
68
|
+
accountId: 'account-123',
|
|
69
|
+
status: 'active',
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// Update
|
|
73
|
+
const updated = await updateUser(client, {
|
|
74
|
+
id: 'user-789',
|
|
75
|
+
status: 'inactive',
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// Delete
|
|
79
|
+
await deleteUser(client, { id: 'user-789' });
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Error Handling
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
try {
|
|
86
|
+
const brand = await createBrand(client, data);
|
|
87
|
+
} catch (error) {
|
|
88
|
+
if (error.errors) {
|
|
89
|
+
// GraphQL errors
|
|
90
|
+
console.error('Validation errors:', error.errors);
|
|
91
|
+
} else {
|
|
92
|
+
// Network or other errors
|
|
93
|
+
console.error('Mutation failed:', error.message);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
```
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User Mutation Functions
|
|
3
|
+
*
|
|
4
|
+
* Provides mutation functions for creating, updating, and deleting users.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { User } from "@htlkg/core/types";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Input type for creating a user
|
|
11
|
+
*/
|
|
12
|
+
export interface CreateUserInput {
|
|
13
|
+
cognitoId: string;
|
|
14
|
+
email: string;
|
|
15
|
+
accountId: string;
|
|
16
|
+
brandIds?: string[];
|
|
17
|
+
roles?: string[];
|
|
18
|
+
permissions?: Record<string, any>;
|
|
19
|
+
status?: "active" | "inactive" | "pending" | "suspended";
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Input type for updating a user
|
|
24
|
+
*/
|
|
25
|
+
export interface UpdateUserInput {
|
|
26
|
+
id: string;
|
|
27
|
+
email?: string;
|
|
28
|
+
brandIds?: string[];
|
|
29
|
+
roles?: string[];
|
|
30
|
+
permissions?: Record<string, any>;
|
|
31
|
+
lastLogin?: string;
|
|
32
|
+
status?: "active" | "inactive" | "pending" | "suspended";
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Create a new user
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* import { createUser } from '@htlkg/data/mutations';
|
|
41
|
+
* import { generateClient } from '@htlkg/data/client';
|
|
42
|
+
*
|
|
43
|
+
* const client = generateClient<Schema>();
|
|
44
|
+
* const user = await createUser(client, {
|
|
45
|
+
* cognitoId: 'cognito-123',
|
|
46
|
+
* email: 'user@example.com',
|
|
47
|
+
* accountId: 'account-123',
|
|
48
|
+
* roles: ['BRAND_ADMIN'],
|
|
49
|
+
* status: 'active'
|
|
50
|
+
* });
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export async function createUser<TClient = any>(
|
|
54
|
+
client: TClient,
|
|
55
|
+
input: CreateUserInput,
|
|
56
|
+
): Promise<User | null> {
|
|
57
|
+
try {
|
|
58
|
+
const { data, errors } = await (client as any).models.User.create(input);
|
|
59
|
+
|
|
60
|
+
if (errors) {
|
|
61
|
+
console.error("[createUser] GraphQL errors:", errors);
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return data as User;
|
|
66
|
+
} catch (error) {
|
|
67
|
+
console.error("[createUser] Error creating user:", error);
|
|
68
|
+
throw error;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Update an existing user
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* import { updateUser } from '@htlkg/data/mutations';
|
|
78
|
+
* import { generateClient } from '@htlkg/data/client';
|
|
79
|
+
*
|
|
80
|
+
* const client = generateClient<Schema>();
|
|
81
|
+
* const user = await updateUser(client, {
|
|
82
|
+
* id: 'user-123',
|
|
83
|
+
* roles: ['BRAND_ADMIN', 'ACCOUNT_ADMIN'],
|
|
84
|
+
* status: 'active'
|
|
85
|
+
* });
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
export async function updateUser<TClient = any>(
|
|
89
|
+
client: TClient,
|
|
90
|
+
input: UpdateUserInput,
|
|
91
|
+
): Promise<User | null> {
|
|
92
|
+
try {
|
|
93
|
+
const { data, errors } = await (client as any).models.User.update(input);
|
|
94
|
+
|
|
95
|
+
if (errors) {
|
|
96
|
+
console.error("[updateUser] GraphQL errors:", errors);
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return data as User;
|
|
101
|
+
} catch (error) {
|
|
102
|
+
console.error("[updateUser] Error updating user:", error);
|
|
103
|
+
throw error;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Delete a user
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* import { deleteUser } from '@htlkg/data/mutations';
|
|
113
|
+
* import { generateClient } from '@htlkg/data/client';
|
|
114
|
+
*
|
|
115
|
+
* const client = generateClient<Schema>();
|
|
116
|
+
* await deleteUser(client, 'user-123');
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
export async function deleteUser<TClient = any>(
|
|
120
|
+
client: TClient,
|
|
121
|
+
id: string,
|
|
122
|
+
): Promise<boolean> {
|
|
123
|
+
try {
|
|
124
|
+
const { errors } = await (client as any).models.User.delete({ id });
|
|
125
|
+
|
|
126
|
+
if (errors) {
|
|
127
|
+
console.error("[deleteUser] GraphQL errors:", errors);
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return true;
|
|
132
|
+
} catch (error) {
|
|
133
|
+
console.error("[deleteUser] Error deleting user:", error);
|
|
134
|
+
throw error;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Account Query Functions
|
|
3
|
+
*
|
|
4
|
+
* Provides query functions for fetching account data from the GraphQL API.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { Account } from "@htlkg/core/types";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Get a single account by ID
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { getAccount } from '@htlkg/data/queries';
|
|
15
|
+
* import { generateClient } from '@htlkg/data/client';
|
|
16
|
+
*
|
|
17
|
+
* const client = generateClient<Schema>();
|
|
18
|
+
* const account = await getAccount(client, 'account-123');
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export async function getAccount<TClient = any>(
|
|
22
|
+
client: TClient,
|
|
23
|
+
id: string,
|
|
24
|
+
): Promise<Account | null> {
|
|
25
|
+
try {
|
|
26
|
+
const { data, errors } = await (client as any).models.Account.get({ id });
|
|
27
|
+
|
|
28
|
+
if (errors) {
|
|
29
|
+
console.error("[getAccount] GraphQL errors:", errors);
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return data as Account;
|
|
34
|
+
} catch (error) {
|
|
35
|
+
console.error("[getAccount] Error fetching account:", error);
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* List all accounts with optional filtering
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* import { listAccounts } from '@htlkg/data/queries';
|
|
46
|
+
* import { generateClient } from '@htlkg/data/client';
|
|
47
|
+
*
|
|
48
|
+
* const client = generateClient<Schema>();
|
|
49
|
+
* const accounts = await listAccounts(client);
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export async function listAccounts<TClient = any>(
|
|
53
|
+
client: TClient,
|
|
54
|
+
options?: {
|
|
55
|
+
filter?: any;
|
|
56
|
+
limit?: number;
|
|
57
|
+
nextToken?: string;
|
|
58
|
+
},
|
|
59
|
+
): Promise<{ items: Account[]; nextToken?: string }> {
|
|
60
|
+
try {
|
|
61
|
+
const { data, errors, nextToken } = await (
|
|
62
|
+
client as any
|
|
63
|
+
).models.Account.list(options);
|
|
64
|
+
|
|
65
|
+
if (errors) {
|
|
66
|
+
console.error("[listAccounts] GraphQL errors:", errors);
|
|
67
|
+
return { items: [], nextToken: undefined };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
items: (data || []) as Account[],
|
|
72
|
+
nextToken,
|
|
73
|
+
};
|
|
74
|
+
} catch (error) {
|
|
75
|
+
console.error("[listAccounts] Error fetching accounts:", error);
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Get an account with its brands
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* import { getAccountWithBrands } from '@htlkg/data/queries';
|
|
86
|
+
* import { generateClient } from '@htlkg/data/client';
|
|
87
|
+
*
|
|
88
|
+
* const client = generateClient<Schema>();
|
|
89
|
+
* const account = await getAccountWithBrands(client, 'account-123');
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export async function getAccountWithBrands<TClient = any>(
|
|
93
|
+
client: TClient,
|
|
94
|
+
id: string,
|
|
95
|
+
): Promise<Account | null> {
|
|
96
|
+
try {
|
|
97
|
+
const { data, errors } = await (client as any).models.Account.get(
|
|
98
|
+
{ id },
|
|
99
|
+
{
|
|
100
|
+
selectionSet: [
|
|
101
|
+
"id",
|
|
102
|
+
"name",
|
|
103
|
+
"logo",
|
|
104
|
+
"subscription",
|
|
105
|
+
"settings",
|
|
106
|
+
"brands.*",
|
|
107
|
+
],
|
|
108
|
+
},
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
if (errors) {
|
|
112
|
+
console.error("[getAccountWithBrands] GraphQL errors:", errors);
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return data as Account;
|
|
117
|
+
} catch (error) {
|
|
118
|
+
console.error("[getAccountWithBrands] Error fetching account:", error);
|
|
119
|
+
throw error;
|
|
120
|
+
}
|
|
121
|
+
}
|