@turtleclub/hooks 0.4.0-beta.0 → 0.4.0-beta.2

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 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 import_query_key_factory2 = require("@lukemorales/query-key-factory");
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");
@@ -4328,9 +4335,15 @@ var ApiError = class extends Error {
4328
4335
  this.name = "ApiError";
4329
4336
  }
4330
4337
  };
4338
+ var getEarnUrl = () => {
4339
+ return process.env.NEXT_PUBLIC_EARN_URL || process.env.VITE_EARN_URL || EARN_BASE_URL;
4340
+ };
4341
+ var getApiUrl = () => {
4342
+ return process.env.NEXT_PUBLIC_API_URL || process.env.VITE_API_URL || API_BASE_URL;
4343
+ };
4331
4344
  async function apiClient(endpoint, options) {
4332
4345
  const { debug, domain = "api", ...fetchOptions } = options ?? {};
4333
- const baseUrl = domain === "earn" ? EARN_BASE_URL : API_BASE_URL;
4346
+ const baseUrl = domain === "earn" ? getEarnUrl() : getApiUrl();
4334
4347
  const url = `${baseUrl}${endpoint}`;
4335
4348
  if (debug) {
4336
4349
  console.log("[API Request]", {
@@ -4371,11 +4384,7 @@ async function apiClient(endpoint, options) {
4371
4384
  if (error instanceof ApiError) {
4372
4385
  throw error;
4373
4386
  }
4374
- throw new ApiError(
4375
- error instanceof Error ? error.message : "Unknown error",
4376
- 0,
4377
- error
4378
- );
4387
+ throw new ApiError(error instanceof Error ? error.message : "Unknown error", 0, error);
4379
4388
  }
4380
4389
  }
4381
4390
 
@@ -4571,6 +4580,116 @@ var opportunitiesQueries = (0, import_query_key_factory.createQueryKeys)("opport
4571
4580
  })
4572
4581
  });
4573
4582
 
4583
+ // src/v2/products/queries.ts
4584
+ var import_query_key_factory2 = require("@lukemorales/query-key-factory");
4585
+
4586
+ // src/v2/products/schema.ts
4587
+ var import_zod15 = require("zod");
4588
+ var productsResponseSchema = import_zod15.z.object({
4589
+ products: import_zod15.z.array(productSchema),
4590
+ total: import_zod15.z.number().optional()
4591
+ });
4592
+ var productCreateInputSchema = import_zod15.z.object({
4593
+ name: import_zod15.z.string(),
4594
+ title: import_zod15.z.string().optional().nullable(),
4595
+ subtitle: import_zod15.z.string().optional().nullable(),
4596
+ description: import_zod15.z.string().optional().nullable(),
4597
+ logoUrl: import_zod15.z.string().optional().nullable(),
4598
+ productUrl: import_zod15.z.string().optional().nullable(),
4599
+ startedAt: import_zod15.z.string().optional().nullable(),
4600
+ status: import_zod15.z.string().optional().nullable(),
4601
+ productType: import_zod15.z.string().optional().nullable(),
4602
+ // Relations
4603
+ organizationId: import_zod15.z.string().uuid()
4604
+ });
4605
+ var productUpdateInputSchema = productCreateInputSchema.extend({
4606
+ id: import_zod15.z.string().uuid()
4607
+ });
4608
+
4609
+ // src/v2/products/api.ts
4610
+ async function getProducts(options) {
4611
+ const params = new URLSearchParams();
4612
+ const queryString = params.toString();
4613
+ const endpoint = `/admin/products${queryString ? `?${queryString}` : ""}`;
4614
+ const data = await apiClient(endpoint, {
4615
+ method: "GET",
4616
+ debug: options?.debug
4617
+ });
4618
+ const result = productsResponseSchema.safeParse(data);
4619
+ if (result.success === false) {
4620
+ console.log("[ZOD ERROR]", result.error);
4621
+ throw new Error(`Failed to parse products: ${result.error.message}`);
4622
+ }
4623
+ return result.data;
4624
+ }
4625
+ async function createProduct(input, options) {
4626
+ const endpoint = `/admin/products`;
4627
+ const data = await apiClient(endpoint, {
4628
+ method: "POST",
4629
+ body: JSON.stringify(input),
4630
+ headers: {
4631
+ "Content-Type": "application/json"
4632
+ },
4633
+ debug: options?.debug
4634
+ });
4635
+ const result = productSchema.safeParse(data);
4636
+ if (result.success === false) {
4637
+ console.log("[ZOD ERROR]", result.error);
4638
+ throw new Error(`Failed to create product: ${result.error.message}`);
4639
+ }
4640
+ return result.data;
4641
+ }
4642
+ async function updateProduct(input, options) {
4643
+ const endpoint = `/admin/products/${input.id}`;
4644
+ const data = await apiClient(endpoint, {
4645
+ method: "PUT",
4646
+ body: JSON.stringify(input),
4647
+ headers: {
4648
+ "Content-Type": "application/json"
4649
+ },
4650
+ debug: options?.debug
4651
+ });
4652
+ const result = productSchema.safeParse(data);
4653
+ if (result.success === false) {
4654
+ console.log("[ZOD ERROR]", result.error);
4655
+ throw new Error(`Failed to update product: ${result.error.message}`);
4656
+ }
4657
+ return result.data;
4658
+ }
4659
+ async function deleteProduct(id, options) {
4660
+ const endpoint = `/admin/products/${id}`;
4661
+ const data = await apiClient(endpoint, {
4662
+ method: "DELETE",
4663
+ headers: {
4664
+ "Content-Type": "application/json"
4665
+ },
4666
+ debug: options?.debug
4667
+ });
4668
+ const result = productSchema.safeParse(data);
4669
+ if (result.success === false) {
4670
+ console.log("[ZOD ERROR]", result.error);
4671
+ throw new Error(`Failed to delete product: ${result.error.message}`);
4672
+ }
4673
+ }
4674
+
4675
+ // src/v2/products/queries.ts
4676
+ var productsQueries = (0, import_query_key_factory2.createQueryKeys)("products", {
4677
+ // Get all products (no filters)
4678
+ all: {
4679
+ queryKey: null,
4680
+ queryFn: () => getProducts()
4681
+ },
4682
+ // Get single product by ID
4683
+ byId: (id) => ({
4684
+ queryKey: [id],
4685
+ // Replace by true query then
4686
+ queryFn: async () => {
4687
+ const products = await getProducts();
4688
+ return products.products.find((product) => product.id === id);
4689
+ }
4690
+ })
4691
+ });
4692
+
4574
4693
  // src/v2/opportunities/hooks.ts
4575
4694
  var import_react_query19 = require("@tanstack/react-query");
4576
4695
 
@@ -4594,8 +4713,26 @@ function useOpportunity({ id, ...options }) {
4594
4713
  return (0, import_react_query19.useQuery)({ ...opportunitiesQueries.byId(id), ...queryDefaults });
4595
4714
  }
4596
4715
 
4716
+ // src/v2/products/hooks.ts
4717
+ var import_react_query20 = require("@tanstack/react-query");
4718
+ function useProducts(options) {
4719
+ return (0, import_react_query20.useQuery)({ ...productsQueries.all, ...queryDefaults });
4720
+ }
4721
+ function useProduct({ id, ...options }) {
4722
+ return (0, import_react_query20.useQuery)({ ...productsQueries.byId(id), ...queryDefaults });
4723
+ }
4724
+ function useCreateProduct({ ...options }) {
4725
+ return (0, import_react_query20.useMutation)({ mutationFn: createProduct });
4726
+ }
4727
+ function useUpdateProduct({ ...options }) {
4728
+ return (0, import_react_query20.useMutation)({ mutationFn: updateProduct });
4729
+ }
4730
+ function useDeleteProduct({ ...options }) {
4731
+ return (0, import_react_query20.useMutation)({ mutationFn: deleteProduct });
4732
+ }
4733
+
4597
4734
  // src/v2/index.ts
4598
- var queries = (0, import_query_key_factory2.mergeQueryKeys)(opportunitiesQueries);
4735
+ var queries = (0, import_query_key_factory3.mergeQueryKeys)(opportunitiesQueries, productsQueries);
4599
4736
  // Annotate the CommonJS export names for ESM import in node:
4600
4737
  0 && (module.exports = {
4601
4738
  campaignsV2,
@@ -4603,15 +4740,19 @@ var queries = (0, import_query_key_factory2.mergeQueryKeys)(opportunitiesQueries
4603
4740
  defaultQueryClient,
4604
4741
  getOpportunities,
4605
4742
  getOpportunityById,
4743
+ getProducts,
4606
4744
  incentiveSchema,
4607
4745
  lendingConfigSchema,
4608
4746
  opportunitiesQueries,
4609
4747
  opportunitySchema,
4610
4748
  organizationSchema,
4611
4749
  productSchema,
4750
+ productsQueries,
4612
4751
  queries,
4613
4752
  tokenSchema,
4614
4753
  useConfig,
4754
+ useCreateProduct,
4755
+ useDeleteProduct,
4615
4756
  useEarnCampaigns,
4616
4757
  useEarnDeals,
4617
4758
  useEarnRoute,
@@ -4627,8 +4768,11 @@ var queries = (0, import_query_key_factory2.mergeQueryKeys)(opportunitiesQueries
4627
4768
  usePartnerCampaigns,
4628
4769
  usePartnerDeals,
4629
4770
  usePrepareSignup,
4771
+ useProduct,
4772
+ useProducts,
4630
4773
  useProjectTvl,
4631
4774
  useSignup,
4775
+ useUpdateProduct,
4632
4776
  vaultConfigSchema
4633
4777
  });
4634
4778
  //# sourceMappingURL=index.cjs.map