@turtleclub/hooks 0.4.0-beta.0 → 0.4.0-beta.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.
- package/dist/index.cjs +144 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +139 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/v2/index.ts +3 -1
- package/src/v2/products/api.ts +105 -0
- package/src/v2/products/hooks.ts +47 -0
- package/src/v2/products/index.ts +21 -0
- package/src/v2/products/queries.ts +21 -0
- package/src/v2/products/schema.ts +33 -0
package/dist/index.cjs
CHANGED
|
@@ -35,15 +35,19 @@ __export(index_exports, {
|
|
|
35
35
|
defaultQueryClient: () => defaultQueryClient,
|
|
36
36
|
getOpportunities: () => getOpportunities,
|
|
37
37
|
getOpportunityById: () => getOpportunityById,
|
|
38
|
+
getProducts: () => getProducts,
|
|
38
39
|
incentiveSchema: () => incentiveSchema2,
|
|
39
40
|
lendingConfigSchema: () => lendingConfigSchema,
|
|
40
41
|
opportunitiesQueries: () => opportunitiesQueries,
|
|
41
42
|
opportunitySchema: () => opportunitySchema,
|
|
42
43
|
organizationSchema: () => organizationSchema2,
|
|
43
44
|
productSchema: () => productSchema,
|
|
45
|
+
productsQueries: () => productsQueries,
|
|
44
46
|
queries: () => queries,
|
|
45
47
|
tokenSchema: () => tokenSchema2,
|
|
46
48
|
useConfig: () => useConfig,
|
|
49
|
+
useCreateProduct: () => useCreateProduct,
|
|
50
|
+
useDeleteProduct: () => useDeleteProduct,
|
|
47
51
|
useEarnCampaigns: () => useEarnCampaigns,
|
|
48
52
|
useEarnDeals: () => useEarnDeals,
|
|
49
53
|
useEarnRoute: () => useEarnRoute,
|
|
@@ -59,8 +63,11 @@ __export(index_exports, {
|
|
|
59
63
|
usePartnerCampaigns: () => usePartnerCampaigns,
|
|
60
64
|
usePartnerDeals: () => usePartnerDeals,
|
|
61
65
|
usePrepareSignup: () => usePrepareSignup,
|
|
66
|
+
useProduct: () => useProduct,
|
|
67
|
+
useProducts: () => useProducts,
|
|
62
68
|
useProjectTvl: () => useProjectTvl,
|
|
63
69
|
useSignup: () => useSignup,
|
|
70
|
+
useUpdateProduct: () => useUpdateProduct,
|
|
64
71
|
vaultConfigSchema: () => vaultConfigSchema
|
|
65
72
|
});
|
|
66
73
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -4312,7 +4319,7 @@ function useUserCampaignPositions({
|
|
|
4312
4319
|
}
|
|
4313
4320
|
|
|
4314
4321
|
// src/v2/index.ts
|
|
4315
|
-
var
|
|
4322
|
+
var import_query_key_factory3 = require("@lukemorales/query-key-factory");
|
|
4316
4323
|
|
|
4317
4324
|
// src/v2/opportunities/queries.ts
|
|
4318
4325
|
var import_query_key_factory = require("@lukemorales/query-key-factory");
|
|
@@ -4571,6 +4578,116 @@ var opportunitiesQueries = (0, import_query_key_factory.createQueryKeys)("opport
|
|
|
4571
4578
|
})
|
|
4572
4579
|
});
|
|
4573
4580
|
|
|
4581
|
+
// src/v2/products/queries.ts
|
|
4582
|
+
var import_query_key_factory2 = require("@lukemorales/query-key-factory");
|
|
4583
|
+
|
|
4584
|
+
// src/v2/products/schema.ts
|
|
4585
|
+
var import_zod15 = require("zod");
|
|
4586
|
+
var productsResponseSchema = import_zod15.z.object({
|
|
4587
|
+
products: import_zod15.z.array(productSchema),
|
|
4588
|
+
total: import_zod15.z.number().optional()
|
|
4589
|
+
});
|
|
4590
|
+
var productCreateInputSchema = import_zod15.z.object({
|
|
4591
|
+
name: import_zod15.z.string(),
|
|
4592
|
+
title: import_zod15.z.string().optional().nullable(),
|
|
4593
|
+
subtitle: import_zod15.z.string().optional().nullable(),
|
|
4594
|
+
description: import_zod15.z.string().optional().nullable(),
|
|
4595
|
+
logoUrl: import_zod15.z.string().optional().nullable(),
|
|
4596
|
+
productUrl: import_zod15.z.string().optional().nullable(),
|
|
4597
|
+
startedAt: import_zod15.z.string().optional().nullable(),
|
|
4598
|
+
status: import_zod15.z.string().optional().nullable(),
|
|
4599
|
+
productType: import_zod15.z.string().optional().nullable(),
|
|
4600
|
+
// Relations
|
|
4601
|
+
organizationId: import_zod15.z.string().uuid()
|
|
4602
|
+
});
|
|
4603
|
+
var productUpdateInputSchema = productCreateInputSchema.extend({
|
|
4604
|
+
id: import_zod15.z.string().uuid()
|
|
4605
|
+
});
|
|
4606
|
+
|
|
4607
|
+
// src/v2/products/api.ts
|
|
4608
|
+
async function getProducts(options) {
|
|
4609
|
+
const params = new URLSearchParams();
|
|
4610
|
+
const queryString = params.toString();
|
|
4611
|
+
const endpoint = `/turtle/products${queryString ? `?${queryString}` : ""}`;
|
|
4612
|
+
const data = await apiClient(endpoint, {
|
|
4613
|
+
method: "GET",
|
|
4614
|
+
debug: options?.debug
|
|
4615
|
+
});
|
|
4616
|
+
const result = productsResponseSchema.safeParse(data);
|
|
4617
|
+
if (result.success === false) {
|
|
4618
|
+
console.log("[ZOD ERROR]", result.error);
|
|
4619
|
+
throw new Error(`Failed to parse products: ${result.error.message}`);
|
|
4620
|
+
}
|
|
4621
|
+
return result.data;
|
|
4622
|
+
}
|
|
4623
|
+
async function createProduct(input, options) {
|
|
4624
|
+
const endpoint = `/turtle/products`;
|
|
4625
|
+
const data = await apiClient(endpoint, {
|
|
4626
|
+
method: "POST",
|
|
4627
|
+
body: JSON.stringify(input),
|
|
4628
|
+
headers: {
|
|
4629
|
+
"Content-Type": "application/json"
|
|
4630
|
+
},
|
|
4631
|
+
debug: options?.debug
|
|
4632
|
+
});
|
|
4633
|
+
const result = productSchema.safeParse(data);
|
|
4634
|
+
if (result.success === false) {
|
|
4635
|
+
console.log("[ZOD ERROR]", result.error);
|
|
4636
|
+
throw new Error(`Failed to create product: ${result.error.message}`);
|
|
4637
|
+
}
|
|
4638
|
+
return result.data;
|
|
4639
|
+
}
|
|
4640
|
+
async function updateProduct(input, options) {
|
|
4641
|
+
const endpoint = `/turtle/products/${input.id}`;
|
|
4642
|
+
const data = await apiClient(endpoint, {
|
|
4643
|
+
method: "PUT",
|
|
4644
|
+
body: JSON.stringify(input),
|
|
4645
|
+
headers: {
|
|
4646
|
+
"Content-Type": "application/json"
|
|
4647
|
+
},
|
|
4648
|
+
debug: options?.debug
|
|
4649
|
+
});
|
|
4650
|
+
const result = productSchema.safeParse(data);
|
|
4651
|
+
if (result.success === false) {
|
|
4652
|
+
console.log("[ZOD ERROR]", result.error);
|
|
4653
|
+
throw new Error(`Failed to update product: ${result.error.message}`);
|
|
4654
|
+
}
|
|
4655
|
+
return result.data;
|
|
4656
|
+
}
|
|
4657
|
+
async function deleteProduct(id, options) {
|
|
4658
|
+
const endpoint = `/turtle/products/${id}`;
|
|
4659
|
+
const data = await apiClient(endpoint, {
|
|
4660
|
+
method: "DELETE",
|
|
4661
|
+
headers: {
|
|
4662
|
+
"Content-Type": "application/json"
|
|
4663
|
+
},
|
|
4664
|
+
debug: options?.debug
|
|
4665
|
+
});
|
|
4666
|
+
const result = productSchema.safeParse(data);
|
|
4667
|
+
if (result.success === false) {
|
|
4668
|
+
console.log("[ZOD ERROR]", result.error);
|
|
4669
|
+
throw new Error(`Failed to delete product: ${result.error.message}`);
|
|
4670
|
+
}
|
|
4671
|
+
}
|
|
4672
|
+
|
|
4673
|
+
// src/v2/products/queries.ts
|
|
4674
|
+
var productsQueries = (0, import_query_key_factory2.createQueryKeys)("products", {
|
|
4675
|
+
// Get all products (no filters)
|
|
4676
|
+
all: {
|
|
4677
|
+
queryKey: null,
|
|
4678
|
+
queryFn: () => getProducts()
|
|
4679
|
+
},
|
|
4680
|
+
// Get single product by ID
|
|
4681
|
+
byId: (id) => ({
|
|
4682
|
+
queryKey: [id],
|
|
4683
|
+
// Replace by true query then
|
|
4684
|
+
queryFn: async () => {
|
|
4685
|
+
const products = await getProducts();
|
|
4686
|
+
return products.products.find((product) => product.id === id);
|
|
4687
|
+
}
|
|
4688
|
+
})
|
|
4689
|
+
});
|
|
4690
|
+
|
|
4574
4691
|
// src/v2/opportunities/hooks.ts
|
|
4575
4692
|
var import_react_query19 = require("@tanstack/react-query");
|
|
4576
4693
|
|
|
@@ -4594,8 +4711,26 @@ function useOpportunity({ id, ...options }) {
|
|
|
4594
4711
|
return (0, import_react_query19.useQuery)({ ...opportunitiesQueries.byId(id), ...queryDefaults });
|
|
4595
4712
|
}
|
|
4596
4713
|
|
|
4714
|
+
// src/v2/products/hooks.ts
|
|
4715
|
+
var import_react_query20 = require("@tanstack/react-query");
|
|
4716
|
+
function useProducts(options) {
|
|
4717
|
+
return (0, import_react_query20.useQuery)({ ...productsQueries.all, ...queryDefaults });
|
|
4718
|
+
}
|
|
4719
|
+
function useProduct({ id, ...options }) {
|
|
4720
|
+
return (0, import_react_query20.useQuery)({ ...productsQueries.byId(id), ...queryDefaults });
|
|
4721
|
+
}
|
|
4722
|
+
function useCreateProduct({ ...options }) {
|
|
4723
|
+
return (0, import_react_query20.useMutation)({ mutationFn: createProduct });
|
|
4724
|
+
}
|
|
4725
|
+
function useUpdateProduct({ ...options }) {
|
|
4726
|
+
return (0, import_react_query20.useMutation)({ mutationFn: updateProduct });
|
|
4727
|
+
}
|
|
4728
|
+
function useDeleteProduct({ ...options }) {
|
|
4729
|
+
return (0, import_react_query20.useMutation)({ mutationFn: deleteProduct });
|
|
4730
|
+
}
|
|
4731
|
+
|
|
4597
4732
|
// src/v2/index.ts
|
|
4598
|
-
var queries = (0,
|
|
4733
|
+
var queries = (0, import_query_key_factory3.mergeQueryKeys)(opportunitiesQueries, productsQueries);
|
|
4599
4734
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4600
4735
|
0 && (module.exports = {
|
|
4601
4736
|
campaignsV2,
|
|
@@ -4603,15 +4738,19 @@ var queries = (0, import_query_key_factory2.mergeQueryKeys)(opportunitiesQueries
|
|
|
4603
4738
|
defaultQueryClient,
|
|
4604
4739
|
getOpportunities,
|
|
4605
4740
|
getOpportunityById,
|
|
4741
|
+
getProducts,
|
|
4606
4742
|
incentiveSchema,
|
|
4607
4743
|
lendingConfigSchema,
|
|
4608
4744
|
opportunitiesQueries,
|
|
4609
4745
|
opportunitySchema,
|
|
4610
4746
|
organizationSchema,
|
|
4611
4747
|
productSchema,
|
|
4748
|
+
productsQueries,
|
|
4612
4749
|
queries,
|
|
4613
4750
|
tokenSchema,
|
|
4614
4751
|
useConfig,
|
|
4752
|
+
useCreateProduct,
|
|
4753
|
+
useDeleteProduct,
|
|
4615
4754
|
useEarnCampaigns,
|
|
4616
4755
|
useEarnDeals,
|
|
4617
4756
|
useEarnRoute,
|
|
@@ -4627,8 +4766,11 @@ var queries = (0, import_query_key_factory2.mergeQueryKeys)(opportunitiesQueries
|
|
|
4627
4766
|
usePartnerCampaigns,
|
|
4628
4767
|
usePartnerDeals,
|
|
4629
4768
|
usePrepareSignup,
|
|
4769
|
+
useProduct,
|
|
4770
|
+
useProducts,
|
|
4630
4771
|
useProjectTvl,
|
|
4631
4772
|
useSignup,
|
|
4773
|
+
useUpdateProduct,
|
|
4632
4774
|
vaultConfigSchema
|
|
4633
4775
|
});
|
|
4634
4776
|
//# sourceMappingURL=index.cjs.map
|