anymal-protocol 1.0.86 → 1.0.87

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.d.mts CHANGED
@@ -293,6 +293,10 @@ interface FetchActionsResponse {
293
293
  interface FetchActionDefinitionsResponse {
294
294
  data: ActionDefinition[];
295
295
  }
296
+ declare const convertToActionRecord: (fr: any) => ActionRecord;
297
+ declare const convertToActionDefinition: (fr: any) => ActionDefinition;
298
+ declare const convertToMultipleActionRecords: (frs: ActionRecord[]) => ActionRecord[];
299
+ declare const convertToMultipleActionDefinitions: (frs: ActionDefinition[]) => ActionDefinition[];
296
300
 
297
301
  /**
298
302
  * Base fields sent with every action
@@ -356,7 +360,7 @@ interface WishlistPurchaseActionPayload extends MarketplaceActionPayload {
356
360
  */
357
361
  interface ExternalActionPayload extends BaseActionPayload {
358
362
  endpoint: string;
359
- method: 'GET' | 'POST' | 'PUT' | 'DELETE';
363
+ method: "GET" | "POST" | "PUT" | "DELETE";
360
364
  requestBody?: Record<string, any>;
361
365
  responseStatus?: number;
362
366
  responseBody?: any;
@@ -397,4 +401,6 @@ declare function useClaimOrgActionReward(): (orgContractAddress: string, rewarda
397
401
  message: string;
398
402
  }>;
399
403
 
400
- export { AUTH_API_ENDPOINTS, type ActionDefinition, type ActionPayload, type ActionRecord, ActionSourceType, ActionStatus, ActionType, type AnymalNftMetadataInputData, type AuthEnvelope, type ContractActionPayload, type CreateAnymalInputData, type ExternalActionPayload, type GraphQLActionPayload, type JWTOptions, type MarketplaceActionPayload, MarketplacePaymentType, NETWORK_HOSTS, Network, type SubmitResponse, type WishlistPurchaseActionPayload, createAuthEnvelope, fetchAnymals, generateAppSignature, generateBytes32Nonce, generateJWT, loadExistingSecp256k1PrivateKey, serializePublicKeyCompressed, submitAction, useAddAnymalToDatabase, useApproveKibbleToken, useApproveOrgPartialPayment, useClaimActionReward, useClaimOrgActionReward, useCreateOrganizationAppData, useCreateOrganizationBase, useCreateUserAppData, useCreateWeb3Account, useDeleteAnymalFromDatabase, useFetchActionDefinitions, useFetchActions, useFetchAnymals, useFetchBalance, useFetchNotifications, useFetchUserData, useMintAnymalNFT, useProcessOrgPartialKibblePayment, useProcessPartialKibblePayment, useSaveAnymalMetadata, useUpdateAnymalWithNFT, useUpdateOrgWalletAddress, useUpdateUserAsVerified, useUpdateUserEmail, useUpdateUserName, useUpdateUserPid, useUploadAnymalImage, useVerifyAccount, useVerifyWeb3AuthSession };
404
+ declare function useSubmitContractAction(): (idToken: string, pid: string, source: ActionSourceType, endpoint: string, payload: ActionPayload) => Promise<SubmitResponse> | undefined;
405
+
406
+ export { AUTH_API_ENDPOINTS, type ActionDefinition, type ActionPayload, type ActionRecord, ActionSourceType, ActionStatus, ActionType, type AnymalNftMetadataInputData, type AuthEnvelope, type ContractActionPayload, type CreateAnymalInputData, type ExternalActionPayload, type GraphQLActionPayload, type JWTOptions, type MarketplaceActionPayload, MarketplacePaymentType, NETWORK_HOSTS, Network, type SubmitResponse, type WishlistPurchaseActionPayload, convertToActionDefinition, convertToActionRecord, convertToMultipleActionDefinitions, convertToMultipleActionRecords, createAuthEnvelope, fetchAnymals, generateAppSignature, generateBytes32Nonce, generateJWT, loadExistingSecp256k1PrivateKey, serializePublicKeyCompressed, submitAction, useAddAnymalToDatabase, useApproveKibbleToken, useApproveOrgPartialPayment, useClaimActionReward, useClaimOrgActionReward, useCreateOrganizationAppData, useCreateOrganizationBase, useCreateUserAppData, useCreateWeb3Account, useDeleteAnymalFromDatabase, useFetchActionDefinitions, useFetchActions, useFetchAnymals, useFetchBalance, useFetchNotifications, useFetchUserData, useMintAnymalNFT, useProcessOrgPartialKibblePayment, useProcessPartialKibblePayment, useSaveAnymalMetadata, useSubmitContractAction, useUpdateAnymalWithNFT, useUpdateOrgWalletAddress, useUpdateUserAsVerified, useUpdateUserEmail, useUpdateUserName, useUpdateUserPid, useUploadAnymalImage, useVerifyAccount, useVerifyWeb3AuthSession };
package/dist/index.d.ts CHANGED
@@ -293,6 +293,10 @@ interface FetchActionsResponse {
293
293
  interface FetchActionDefinitionsResponse {
294
294
  data: ActionDefinition[];
295
295
  }
296
+ declare const convertToActionRecord: (fr: any) => ActionRecord;
297
+ declare const convertToActionDefinition: (fr: any) => ActionDefinition;
298
+ declare const convertToMultipleActionRecords: (frs: ActionRecord[]) => ActionRecord[];
299
+ declare const convertToMultipleActionDefinitions: (frs: ActionDefinition[]) => ActionDefinition[];
296
300
 
297
301
  /**
298
302
  * Base fields sent with every action
@@ -356,7 +360,7 @@ interface WishlistPurchaseActionPayload extends MarketplaceActionPayload {
356
360
  */
357
361
  interface ExternalActionPayload extends BaseActionPayload {
358
362
  endpoint: string;
359
- method: 'GET' | 'POST' | 'PUT' | 'DELETE';
363
+ method: "GET" | "POST" | "PUT" | "DELETE";
360
364
  requestBody?: Record<string, any>;
361
365
  responseStatus?: number;
362
366
  responseBody?: any;
@@ -397,4 +401,6 @@ declare function useClaimOrgActionReward(): (orgContractAddress: string, rewarda
397
401
  message: string;
398
402
  }>;
399
403
 
400
- export { AUTH_API_ENDPOINTS, type ActionDefinition, type ActionPayload, type ActionRecord, ActionSourceType, ActionStatus, ActionType, type AnymalNftMetadataInputData, type AuthEnvelope, type ContractActionPayload, type CreateAnymalInputData, type ExternalActionPayload, type GraphQLActionPayload, type JWTOptions, type MarketplaceActionPayload, MarketplacePaymentType, NETWORK_HOSTS, Network, type SubmitResponse, type WishlistPurchaseActionPayload, createAuthEnvelope, fetchAnymals, generateAppSignature, generateBytes32Nonce, generateJWT, loadExistingSecp256k1PrivateKey, serializePublicKeyCompressed, submitAction, useAddAnymalToDatabase, useApproveKibbleToken, useApproveOrgPartialPayment, useClaimActionReward, useClaimOrgActionReward, useCreateOrganizationAppData, useCreateOrganizationBase, useCreateUserAppData, useCreateWeb3Account, useDeleteAnymalFromDatabase, useFetchActionDefinitions, useFetchActions, useFetchAnymals, useFetchBalance, useFetchNotifications, useFetchUserData, useMintAnymalNFT, useProcessOrgPartialKibblePayment, useProcessPartialKibblePayment, useSaveAnymalMetadata, useUpdateAnymalWithNFT, useUpdateOrgWalletAddress, useUpdateUserAsVerified, useUpdateUserEmail, useUpdateUserName, useUpdateUserPid, useUploadAnymalImage, useVerifyAccount, useVerifyWeb3AuthSession };
404
+ declare function useSubmitContractAction(): (idToken: string, pid: string, source: ActionSourceType, endpoint: string, payload: ActionPayload) => Promise<SubmitResponse> | undefined;
405
+
406
+ export { AUTH_API_ENDPOINTS, type ActionDefinition, type ActionPayload, type ActionRecord, ActionSourceType, ActionStatus, ActionType, type AnymalNftMetadataInputData, type AuthEnvelope, type ContractActionPayload, type CreateAnymalInputData, type ExternalActionPayload, type GraphQLActionPayload, type JWTOptions, type MarketplaceActionPayload, MarketplacePaymentType, NETWORK_HOSTS, Network, type SubmitResponse, type WishlistPurchaseActionPayload, convertToActionDefinition, convertToActionRecord, convertToMultipleActionDefinitions, convertToMultipleActionRecords, createAuthEnvelope, fetchAnymals, generateAppSignature, generateBytes32Nonce, generateJWT, loadExistingSecp256k1PrivateKey, serializePublicKeyCompressed, submitAction, useAddAnymalToDatabase, useApproveKibbleToken, useApproveOrgPartialPayment, useClaimActionReward, useClaimOrgActionReward, useCreateOrganizationAppData, useCreateOrganizationBase, useCreateUserAppData, useCreateWeb3Account, useDeleteAnymalFromDatabase, useFetchActionDefinitions, useFetchActions, useFetchAnymals, useFetchBalance, useFetchNotifications, useFetchUserData, useMintAnymalNFT, useProcessOrgPartialKibblePayment, useProcessPartialKibblePayment, useSaveAnymalMetadata, useSubmitContractAction, useUpdateAnymalWithNFT, useUpdateOrgWalletAddress, useUpdateUserAsVerified, useUpdateUserEmail, useUpdateUserName, useUpdateUserPid, useUploadAnymalImage, useVerifyAccount, useVerifyWeb3AuthSession };
package/dist/index.js CHANGED
@@ -27,6 +27,10 @@ __export(index_exports, {
27
27
  MarketplacePaymentType: () => MarketplacePaymentType,
28
28
  NETWORK_HOSTS: () => NETWORK_HOSTS,
29
29
  Network: () => Network,
30
+ convertToActionDefinition: () => convertToActionDefinition,
31
+ convertToActionRecord: () => convertToActionRecord,
32
+ convertToMultipleActionDefinitions: () => convertToMultipleActionDefinitions,
33
+ convertToMultipleActionRecords: () => convertToMultipleActionRecords,
30
34
  createAuthEnvelope: () => createAuthEnvelope,
31
35
  fetchAnymals: () => fetchAnymals,
32
36
  generateAppSignature: () => generateAppSignature,
@@ -55,6 +59,7 @@ __export(index_exports, {
55
59
  useProcessOrgPartialKibblePayment: () => useProcessOrgPartialKibblePayment,
56
60
  useProcessPartialKibblePayment: () => useProcessPartialKibblePayment,
57
61
  useSaveAnymalMetadata: () => useSaveAnymalMetadata,
62
+ useSubmitContractAction: () => useSubmitContractAction,
58
63
  useUpdateAnymalWithNFT: () => useUpdateAnymalWithNFT,
59
64
  useUpdateOrgWalletAddress: () => useUpdateOrgWalletAddress,
60
65
  useUpdateUserAsVerified: () => useUpdateUserAsVerified,
@@ -2127,8 +2132,16 @@ async function submitAction(idToken, pid, sourceType, payload, endpointBaseUrl)
2127
2132
  const api = endpointBaseUrl + "/actions";
2128
2133
  const response = await fetch(api, {
2129
2134
  method: "POST",
2130
- headers: { "Content-Type": "application/json", "Authorization": "Bearer " + idToken },
2131
- body: JSON.stringify({ actionId: payload.actionId, pid, source_type: sourceType, payload })
2135
+ headers: {
2136
+ "Content-Type": "application/json",
2137
+ Authorization: "Bearer " + idToken
2138
+ },
2139
+ body: JSON.stringify({
2140
+ actionId: payload.actionId,
2141
+ pid,
2142
+ source_type: sourceType,
2143
+ payload
2144
+ })
2132
2145
  });
2133
2146
  if (!response.ok) {
2134
2147
  const err = await response.json();
@@ -2204,11 +2217,11 @@ var ActionType = /* @__PURE__ */ ((ActionType2) => {
2204
2217
  ActionType2["WISHLIST_PURCHASE"] = "WISHLIST_PURCHASE";
2205
2218
  return ActionType2;
2206
2219
  })(ActionType || {});
2207
- var ActionSourceType = /* @__PURE__ */ ((ActionSourceType2) => {
2208
- ActionSourceType2["USER"] = "USER";
2209
- ActionSourceType2["ORGANIZATION"] = "ORGANIZATION";
2210
- ActionSourceType2["APP"] = "APP";
2211
- return ActionSourceType2;
2220
+ var ActionSourceType = /* @__PURE__ */ ((ActionSourceType3) => {
2221
+ ActionSourceType3["USER"] = "USER";
2222
+ ActionSourceType3["ORGANIZATION"] = "ORGANIZATION";
2223
+ ActionSourceType3["APP"] = "APP";
2224
+ return ActionSourceType3;
2212
2225
  })(ActionSourceType || {});
2213
2226
  var ActionStatus = /* @__PURE__ */ ((ActionStatus2) => {
2214
2227
  ActionStatus2["PENDING"] = "PENDING";
@@ -2223,6 +2236,46 @@ var MarketplacePaymentType = /* @__PURE__ */ ((MarketplacePaymentType2) => {
2223
2236
  MarketplacePaymentType2["ANYMAL"] = "ANYMAL";
2224
2237
  return MarketplacePaymentType2;
2225
2238
  })(MarketplacePaymentType || {});
2239
+ var convertToActionRecord = (fr) => {
2240
+ return {
2241
+ id: fr.id || "",
2242
+ wallet: fr.wallet || "",
2243
+ pid: fr.pid || "",
2244
+ action_id: fr.action_id || "",
2245
+ metadata: fr.metadata || {},
2246
+ version_cid: fr.version_cid || void 0,
2247
+ quantity: fr.quantity ?? 0,
2248
+ reward_amount: fr.reward_amount ?? void 0,
2249
+ status: fr.status || "PENDING",
2250
+ createdAt: fr.createdAt ? typeof fr.createdAt === "string" ? fr.createdAt : fr.createdAt.toDate().toISOString() : (/* @__PURE__ */ new Date()).toISOString(),
2251
+ updatedAt: fr.updatedAt ? typeof fr.updatedAt === "string" ? fr.updatedAt : fr.updatedAt.toDate().toISOString() : (/* @__PURE__ */ new Date()).toISOString(),
2252
+ validatedAt: fr.validatedAt ? typeof fr.validatedAt === "string" ? fr.validatedAt : fr.validatedAt.toDate().toISOString() : fr.createdAt ? typeof fr.createdAt === "string" ? fr.createdAt : fr.createdAt.toDate().toISOString() : null,
2253
+ claimIndex: fr.claimIndex ?? null,
2254
+ claimedAt: fr.claimedAt ?? null,
2255
+ claimQuantity: fr.claimQuantity ?? null,
2256
+ failure_reason: fr.failure_reason ?? null
2257
+ };
2258
+ };
2259
+ var convertToActionDefinition = (fr) => {
2260
+ return {
2261
+ id: fr.id || "NO_ID",
2262
+ key: fr.key || "",
2263
+ actionId: fr.action_id || "",
2264
+ name: fr.name || "",
2265
+ namespace: fr.namespace || "",
2266
+ description: fr.description || "",
2267
+ rewardAmount: Math.round(fr.reward_amount / 1e18 * 100) / 100 || 0,
2268
+ maxClaims: typeof fr.max_claims === "number" ? fr.max_claims : 0,
2269
+ ruleType: fr.rule_type || "",
2270
+ requiresReview: !!fr.requires_review,
2271
+ isActive: !!fr.isActive,
2272
+ updatedAt: fr.updatedAt ? typeof fr.updatedAt === "string" ? fr.updatedAt : fr.updatedAt.toDate().toISOString() : (/* @__PURE__ */ new Date()).toISOString(),
2273
+ createdAt: fr.createdAt ? typeof fr.createdAt === "string" ? fr.createdAt : fr.createdAt.toDate().toISOString() : null,
2274
+ ruleConfig: fr.rule_config
2275
+ };
2276
+ };
2277
+ var convertToMultipleActionRecords = (frs) => frs.map(convertToActionRecord);
2278
+ var convertToMultipleActionDefinitions = (frs) => frs.map(convertToActionDefinition);
2226
2279
 
2227
2280
  // src/utils/application/useCreateUserAppData.ts
2228
2281
  var import_react25 = require("react");
@@ -2441,6 +2494,115 @@ function useClaimOrgActionReward() {
2441
2494
  []
2442
2495
  );
2443
2496
  }
2497
+
2498
+ // src/utils/actions/useSubmitContractAction.ts
2499
+ var import_react30 = require("react");
2500
+ function useSubmitContractAction() {
2501
+ return (0, import_react30.useCallback)(
2502
+ (idToken, pid, source, endpoint, payload) => {
2503
+ if (!idToken || !pid || !source || !endpoint || !payload) return;
2504
+ let sourceTypePayload = {};
2505
+ const basisType = {
2506
+ actionId: payload.actionId,
2507
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
2508
+ nonce: crypto.randomUUID(),
2509
+ source: payload.source,
2510
+ clientInfo: {
2511
+ userAgent: navigator.userAgent,
2512
+ locale: navigator.language
2513
+ }
2514
+ };
2515
+ switch (payload.source) {
2516
+ case "GRAPHQL" /* GRAPHQL */:
2517
+ if (isGraphQLAction(payload)) {
2518
+ sourceTypePayload = {
2519
+ ...basisType,
2520
+ resource: "Anymal",
2521
+ resourceId: payload.resourceId,
2522
+ versionCid: payload.versionCid
2523
+ };
2524
+ }
2525
+ break;
2526
+ case "CONTRACT" /* CONTRACT */:
2527
+ if (isContractAction(payload)) {
2528
+ sourceTypePayload = {
2529
+ ...basisType,
2530
+ txHash: payload.txHash,
2531
+ chainId: payload.chainId,
2532
+ contract: payload.contract,
2533
+ functionName: payload.functionName,
2534
+ args: payload.args,
2535
+ receipt: payload.receipt
2536
+ };
2537
+ }
2538
+ break;
2539
+ case "EXTERNAL" /* EXTERNAL */:
2540
+ if (isExternalAction(payload)) {
2541
+ sourceTypePayload = {
2542
+ ...basisType,
2543
+ endpoint: payload.endpoint,
2544
+ method: payload.method,
2545
+ requestBody: payload.requestBody,
2546
+ responseStatus: payload.responseStatus,
2547
+ responseBody: payload.responseBody
2548
+ };
2549
+ }
2550
+ break;
2551
+ case "WISHLIST_PURCHASE" /* WISHLIST_PURCHASE */:
2552
+ if (isWishlistPurchaseAction(payload)) {
2553
+ sourceTypePayload = {
2554
+ ...basisType,
2555
+ wishlistId: payload.wishlistId
2556
+ };
2557
+ }
2558
+ break;
2559
+ case "PURCHASE" /* PURCHASE */:
2560
+ if (isMarketplacePurchaseAction(payload)) {
2561
+ sourceTypePayload = {
2562
+ ...basisType,
2563
+ orderId: payload.orderId,
2564
+ totalSpent: payload.totalSpent,
2565
+ // Amount of USD or Anymal spent (minus any applied kibble, etc)
2566
+ paymentTxId: payload.paymentTxId,
2567
+ // Stripe tx confirmation or Anymal payment transaction
2568
+ paymentSource: payload.paymentSource,
2569
+ // STRIPE, ANYMAL, etc.
2570
+ kibblePaymentTxId: payload.kibblePaymentTxId,
2571
+ // If any kibble was applied to the order
2572
+ lineItems: payload.lineItems || []
2573
+ // Line item details (e.g. product id, price, etc)
2574
+ };
2575
+ }
2576
+ break;
2577
+ }
2578
+ return submitAction(
2579
+ idToken,
2580
+ pid,
2581
+ source,
2582
+ sourceTypePayload,
2583
+ endpoint
2584
+ ).then((res) => {
2585
+ return res;
2586
+ });
2587
+ },
2588
+ []
2589
+ );
2590
+ }
2591
+ function isGraphQLAction(payload) {
2592
+ return payload.source === "GRAPHQL" /* GRAPHQL */;
2593
+ }
2594
+ function isContractAction(payload) {
2595
+ return payload.source === "CONTRACT" /* CONTRACT */;
2596
+ }
2597
+ function isExternalAction(payload) {
2598
+ return payload.source === "EXTERNAL" /* EXTERNAL */;
2599
+ }
2600
+ function isWishlistPurchaseAction(payload) {
2601
+ return payload.source === "WISHLIST_PURCHASE" /* WISHLIST_PURCHASE */;
2602
+ }
2603
+ function isMarketplacePurchaseAction(payload) {
2604
+ return payload.source === "PURCHASE" /* PURCHASE */;
2605
+ }
2444
2606
  // Annotate the CommonJS export names for ESM import in node:
2445
2607
  0 && (module.exports = {
2446
2608
  AUTH_API_ENDPOINTS,
@@ -2450,6 +2612,10 @@ function useClaimOrgActionReward() {
2450
2612
  MarketplacePaymentType,
2451
2613
  NETWORK_HOSTS,
2452
2614
  Network,
2615
+ convertToActionDefinition,
2616
+ convertToActionRecord,
2617
+ convertToMultipleActionDefinitions,
2618
+ convertToMultipleActionRecords,
2453
2619
  createAuthEnvelope,
2454
2620
  fetchAnymals,
2455
2621
  generateAppSignature,
@@ -2478,6 +2644,7 @@ function useClaimOrgActionReward() {
2478
2644
  useProcessOrgPartialKibblePayment,
2479
2645
  useProcessPartialKibblePayment,
2480
2646
  useSaveAnymalMetadata,
2647
+ useSubmitContractAction,
2481
2648
  useUpdateAnymalWithNFT,
2482
2649
  useUpdateOrgWalletAddress,
2483
2650
  useUpdateUserAsVerified,
package/dist/index.mjs CHANGED
@@ -1989,8 +1989,16 @@ async function submitAction(idToken, pid, sourceType, payload, endpointBaseUrl)
1989
1989
  const api = endpointBaseUrl + "/actions";
1990
1990
  const response = await fetch(api, {
1991
1991
  method: "POST",
1992
- headers: { "Content-Type": "application/json", "Authorization": "Bearer " + idToken },
1993
- body: JSON.stringify({ actionId: payload.actionId, pid, source_type: sourceType, payload })
1992
+ headers: {
1993
+ "Content-Type": "application/json",
1994
+ Authorization: "Bearer " + idToken
1995
+ },
1996
+ body: JSON.stringify({
1997
+ actionId: payload.actionId,
1998
+ pid,
1999
+ source_type: sourceType,
2000
+ payload
2001
+ })
1994
2002
  });
1995
2003
  if (!response.ok) {
1996
2004
  const err = await response.json();
@@ -2066,11 +2074,11 @@ var ActionType = /* @__PURE__ */ ((ActionType2) => {
2066
2074
  ActionType2["WISHLIST_PURCHASE"] = "WISHLIST_PURCHASE";
2067
2075
  return ActionType2;
2068
2076
  })(ActionType || {});
2069
- var ActionSourceType = /* @__PURE__ */ ((ActionSourceType2) => {
2070
- ActionSourceType2["USER"] = "USER";
2071
- ActionSourceType2["ORGANIZATION"] = "ORGANIZATION";
2072
- ActionSourceType2["APP"] = "APP";
2073
- return ActionSourceType2;
2077
+ var ActionSourceType = /* @__PURE__ */ ((ActionSourceType3) => {
2078
+ ActionSourceType3["USER"] = "USER";
2079
+ ActionSourceType3["ORGANIZATION"] = "ORGANIZATION";
2080
+ ActionSourceType3["APP"] = "APP";
2081
+ return ActionSourceType3;
2074
2082
  })(ActionSourceType || {});
2075
2083
  var ActionStatus = /* @__PURE__ */ ((ActionStatus2) => {
2076
2084
  ActionStatus2["PENDING"] = "PENDING";
@@ -2085,6 +2093,46 @@ var MarketplacePaymentType = /* @__PURE__ */ ((MarketplacePaymentType2) => {
2085
2093
  MarketplacePaymentType2["ANYMAL"] = "ANYMAL";
2086
2094
  return MarketplacePaymentType2;
2087
2095
  })(MarketplacePaymentType || {});
2096
+ var convertToActionRecord = (fr) => {
2097
+ return {
2098
+ id: fr.id || "",
2099
+ wallet: fr.wallet || "",
2100
+ pid: fr.pid || "",
2101
+ action_id: fr.action_id || "",
2102
+ metadata: fr.metadata || {},
2103
+ version_cid: fr.version_cid || void 0,
2104
+ quantity: fr.quantity ?? 0,
2105
+ reward_amount: fr.reward_amount ?? void 0,
2106
+ status: fr.status || "PENDING",
2107
+ createdAt: fr.createdAt ? typeof fr.createdAt === "string" ? fr.createdAt : fr.createdAt.toDate().toISOString() : (/* @__PURE__ */ new Date()).toISOString(),
2108
+ updatedAt: fr.updatedAt ? typeof fr.updatedAt === "string" ? fr.updatedAt : fr.updatedAt.toDate().toISOString() : (/* @__PURE__ */ new Date()).toISOString(),
2109
+ validatedAt: fr.validatedAt ? typeof fr.validatedAt === "string" ? fr.validatedAt : fr.validatedAt.toDate().toISOString() : fr.createdAt ? typeof fr.createdAt === "string" ? fr.createdAt : fr.createdAt.toDate().toISOString() : null,
2110
+ claimIndex: fr.claimIndex ?? null,
2111
+ claimedAt: fr.claimedAt ?? null,
2112
+ claimQuantity: fr.claimQuantity ?? null,
2113
+ failure_reason: fr.failure_reason ?? null
2114
+ };
2115
+ };
2116
+ var convertToActionDefinition = (fr) => {
2117
+ return {
2118
+ id: fr.id || "NO_ID",
2119
+ key: fr.key || "",
2120
+ actionId: fr.action_id || "",
2121
+ name: fr.name || "",
2122
+ namespace: fr.namespace || "",
2123
+ description: fr.description || "",
2124
+ rewardAmount: Math.round(fr.reward_amount / 1e18 * 100) / 100 || 0,
2125
+ maxClaims: typeof fr.max_claims === "number" ? fr.max_claims : 0,
2126
+ ruleType: fr.rule_type || "",
2127
+ requiresReview: !!fr.requires_review,
2128
+ isActive: !!fr.isActive,
2129
+ updatedAt: fr.updatedAt ? typeof fr.updatedAt === "string" ? fr.updatedAt : fr.updatedAt.toDate().toISOString() : (/* @__PURE__ */ new Date()).toISOString(),
2130
+ createdAt: fr.createdAt ? typeof fr.createdAt === "string" ? fr.createdAt : fr.createdAt.toDate().toISOString() : null,
2131
+ ruleConfig: fr.rule_config
2132
+ };
2133
+ };
2134
+ var convertToMultipleActionRecords = (frs) => frs.map(convertToActionRecord);
2135
+ var convertToMultipleActionDefinitions = (frs) => frs.map(convertToActionDefinition);
2088
2136
 
2089
2137
  // src/utils/application/useCreateUserAppData.ts
2090
2138
  import { useCallback as useCallback25 } from "react";
@@ -2303,6 +2351,115 @@ function useClaimOrgActionReward() {
2303
2351
  []
2304
2352
  );
2305
2353
  }
2354
+
2355
+ // src/utils/actions/useSubmitContractAction.ts
2356
+ import { useCallback as useCallback30 } from "react";
2357
+ function useSubmitContractAction() {
2358
+ return useCallback30(
2359
+ (idToken, pid, source, endpoint, payload) => {
2360
+ if (!idToken || !pid || !source || !endpoint || !payload) return;
2361
+ let sourceTypePayload = {};
2362
+ const basisType = {
2363
+ actionId: payload.actionId,
2364
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
2365
+ nonce: crypto.randomUUID(),
2366
+ source: payload.source,
2367
+ clientInfo: {
2368
+ userAgent: navigator.userAgent,
2369
+ locale: navigator.language
2370
+ }
2371
+ };
2372
+ switch (payload.source) {
2373
+ case "GRAPHQL" /* GRAPHQL */:
2374
+ if (isGraphQLAction(payload)) {
2375
+ sourceTypePayload = {
2376
+ ...basisType,
2377
+ resource: "Anymal",
2378
+ resourceId: payload.resourceId,
2379
+ versionCid: payload.versionCid
2380
+ };
2381
+ }
2382
+ break;
2383
+ case "CONTRACT" /* CONTRACT */:
2384
+ if (isContractAction(payload)) {
2385
+ sourceTypePayload = {
2386
+ ...basisType,
2387
+ txHash: payload.txHash,
2388
+ chainId: payload.chainId,
2389
+ contract: payload.contract,
2390
+ functionName: payload.functionName,
2391
+ args: payload.args,
2392
+ receipt: payload.receipt
2393
+ };
2394
+ }
2395
+ break;
2396
+ case "EXTERNAL" /* EXTERNAL */:
2397
+ if (isExternalAction(payload)) {
2398
+ sourceTypePayload = {
2399
+ ...basisType,
2400
+ endpoint: payload.endpoint,
2401
+ method: payload.method,
2402
+ requestBody: payload.requestBody,
2403
+ responseStatus: payload.responseStatus,
2404
+ responseBody: payload.responseBody
2405
+ };
2406
+ }
2407
+ break;
2408
+ case "WISHLIST_PURCHASE" /* WISHLIST_PURCHASE */:
2409
+ if (isWishlistPurchaseAction(payload)) {
2410
+ sourceTypePayload = {
2411
+ ...basisType,
2412
+ wishlistId: payload.wishlistId
2413
+ };
2414
+ }
2415
+ break;
2416
+ case "PURCHASE" /* PURCHASE */:
2417
+ if (isMarketplacePurchaseAction(payload)) {
2418
+ sourceTypePayload = {
2419
+ ...basisType,
2420
+ orderId: payload.orderId,
2421
+ totalSpent: payload.totalSpent,
2422
+ // Amount of USD or Anymal spent (minus any applied kibble, etc)
2423
+ paymentTxId: payload.paymentTxId,
2424
+ // Stripe tx confirmation or Anymal payment transaction
2425
+ paymentSource: payload.paymentSource,
2426
+ // STRIPE, ANYMAL, etc.
2427
+ kibblePaymentTxId: payload.kibblePaymentTxId,
2428
+ // If any kibble was applied to the order
2429
+ lineItems: payload.lineItems || []
2430
+ // Line item details (e.g. product id, price, etc)
2431
+ };
2432
+ }
2433
+ break;
2434
+ }
2435
+ return submitAction(
2436
+ idToken,
2437
+ pid,
2438
+ source,
2439
+ sourceTypePayload,
2440
+ endpoint
2441
+ ).then((res) => {
2442
+ return res;
2443
+ });
2444
+ },
2445
+ []
2446
+ );
2447
+ }
2448
+ function isGraphQLAction(payload) {
2449
+ return payload.source === "GRAPHQL" /* GRAPHQL */;
2450
+ }
2451
+ function isContractAction(payload) {
2452
+ return payload.source === "CONTRACT" /* CONTRACT */;
2453
+ }
2454
+ function isExternalAction(payload) {
2455
+ return payload.source === "EXTERNAL" /* EXTERNAL */;
2456
+ }
2457
+ function isWishlistPurchaseAction(payload) {
2458
+ return payload.source === "WISHLIST_PURCHASE" /* WISHLIST_PURCHASE */;
2459
+ }
2460
+ function isMarketplacePurchaseAction(payload) {
2461
+ return payload.source === "PURCHASE" /* PURCHASE */;
2462
+ }
2306
2463
  export {
2307
2464
  AUTH_API_ENDPOINTS,
2308
2465
  ActionSourceType,
@@ -2311,6 +2468,10 @@ export {
2311
2468
  MarketplacePaymentType,
2312
2469
  NETWORK_HOSTS,
2313
2470
  Network,
2471
+ convertToActionDefinition,
2472
+ convertToActionRecord,
2473
+ convertToMultipleActionDefinitions,
2474
+ convertToMultipleActionRecords,
2314
2475
  createAuthEnvelope,
2315
2476
  fetchAnymals,
2316
2477
  generateAppSignature,
@@ -2339,6 +2500,7 @@ export {
2339
2500
  useProcessOrgPartialKibblePayment,
2340
2501
  useProcessPartialKibblePayment,
2341
2502
  useSaveAnymalMetadata,
2503
+ useSubmitContractAction,
2342
2504
  useUpdateAnymalWithNFT,
2343
2505
  useUpdateOrgWalletAddress,
2344
2506
  useUpdateUserAsVerified,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anymal-protocol",
3
- "version": "1.0.86",
3
+ "version": "1.0.87",
4
4
  "description": "A React/TypeScript-based utility library for reusable functions and hooks inside of the Anymal Ecosystem.",
5
5
  "main": "dist/index.js",
6
6
  "bin": {