@simpleapps-com/augur-server 0.4.4 → 0.5.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/auth.d.ts +3 -40
- package/dist/auth.js.map +1 -1
- package/dist/index.d.ts +10 -106
- package/dist/index.js +77 -33
- package/dist/index.js.map +1 -1
- package/dist/{site-IpNMQZr5.d.ts → site-D21WJ8z1.d.ts} +178 -862
- package/dist/testing.d.ts +2 -1
- package/package.json +4 -4
package/dist/auth.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AugurAPI } from '@simpleapps-com/augur-api';
|
|
1
2
|
import { NextAuthConfig } from 'next-auth';
|
|
2
3
|
|
|
3
4
|
/** Base user fields shared across all Augur sites. */
|
|
@@ -34,46 +35,8 @@ interface AugurAuthCallbacks {
|
|
|
34
35
|
cartHdrUid?: number;
|
|
35
36
|
} | null>;
|
|
36
37
|
}
|
|
37
|
-
/**
|
|
38
|
-
|
|
39
|
-
* Any `AugurAPI` instance from `@simpleapps-com/augur-api` satisfies this.
|
|
40
|
-
*/
|
|
41
|
-
interface AugurAuthClient {
|
|
42
|
-
joomla: {
|
|
43
|
-
users: {
|
|
44
|
-
doc: {
|
|
45
|
-
get(userId: number, params?: {
|
|
46
|
-
edgeCache?: number | string;
|
|
47
|
-
}): Promise<{
|
|
48
|
-
data: {
|
|
49
|
-
id: number;
|
|
50
|
-
name: string;
|
|
51
|
-
username: string;
|
|
52
|
-
email: string;
|
|
53
|
-
customerId?: string;
|
|
54
|
-
contactId?: string;
|
|
55
|
-
};
|
|
56
|
-
}>;
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
};
|
|
60
|
-
commerce: {
|
|
61
|
-
cartHdr: {
|
|
62
|
-
lookup: {
|
|
63
|
-
get(params: {
|
|
64
|
-
userId: number;
|
|
65
|
-
customerId: number;
|
|
66
|
-
contactId: number;
|
|
67
|
-
cartToken?: string;
|
|
68
|
-
}): Promise<{
|
|
69
|
-
data: {
|
|
70
|
-
cartHdrUid?: number;
|
|
71
|
-
};
|
|
72
|
-
}>;
|
|
73
|
-
};
|
|
74
|
-
};
|
|
75
|
-
};
|
|
76
|
-
}
|
|
38
|
+
/** Derived from augur-api SDK — keeps types in sync automatically. */
|
|
39
|
+
type AugurAuthClient = Pick<AugurAPI, "joomla" | "commerce">;
|
|
77
40
|
interface CreateAuthConfigOptions {
|
|
78
41
|
/** Augur SDK client. When provided, auth SDK calls are handled internally. */
|
|
79
42
|
augurClient?: AugurAuthClient;
|
package/dist/auth.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/auth.ts"],"sourcesContent":["// @simpleapps-com/augur-server/auth\n// NextAuth 5 configuration factory for Augur ecommerce sites.\n\nimport type { NextAuthConfig } from \"next-auth\";\nimport Credentials from \"next-auth/providers/credentials\";\n\n/** Base user fields shared across all Augur sites. */\nexport interface AugurUser {\n id: string;\n username: string;\n isVerified: boolean;\n name?: string;\n email?: string;\n customerId?: string | number;\n contactId?: string | number;\n cartHdrUid?: number;\n token?: string;\n}\n\n/** Session shape returned by all Augur sites. */\nexport interface AugurSession {\n user: AugurUser;\n token?: string;\n expires: string;\n}\n\n/** JWT token shape used by Augur auth. */\nexport interface AugurJWT {\n id: string;\n username: string;\n isVerified: boolean;\n token?: string;\n}\n\n/** Site-specific callbacks the consumer can provide. */\nexport interface AugurAuthCallbacks {\n /** Fetch user profile from the Augur API given the user's Joomla ID. */\n getUserProfile: (userId: string) => Promise<AugurUser | null>;\n /** Look up or create a cart header for the authenticated user. */\n cartHdrLookup?: (\n userId: string | number,\n token: string,\n contactId: string | number,\n customerId: string | number,\n ) => Promise<{ cartHdrUid?: number } | null>;\n}\n\n/**\n * Minimal interface for the Augur SDK client used by auth internals.\n * Any `AugurAPI` instance from `@simpleapps-com/augur-api` satisfies this.\n */\nexport interface AugurAuthClient {\n joomla: {\n users: {\n doc: {\n get(\n userId: number,\n params?: { edgeCache?: number | string },\n ): Promise<{\n data: {\n id: number;\n name: string;\n username: string;\n email: string;\n customerId?: string;\n contactId?: string;\n };\n }>;\n };\n };\n };\n commerce: {\n cartHdr: {\n lookup: {\n get(params: {\n userId: number;\n customerId: number;\n contactId: number;\n cartToken?: string;\n }): Promise<{\n data: { cartHdrUid?: number };\n }>;\n };\n };\n };\n}\n\nexport interface CreateAuthConfigOptions {\n /** Augur SDK client. When provided, auth SDK calls are handled internally. */\n augurClient?: AugurAuthClient;\n /** Site-specific callbacks. Override internal SDK calls when custom behavior is needed. */\n callbacks?: Partial<AugurAuthCallbacks>;\n /** NextAuth secret (defaults to NEXT_PUBLIC_AUTH_SECRET env var). */\n secret?: string;\n /** Session max age in seconds (defaults to 4 hours). */\n maxAge?: number;\n /** Default customer ID when profile doesn't provide one. */\n defaultCustomerId?: string | number;\n /** Default contact ID for cart header lookups. */\n defaultContactId?: string | number;\n /** Enable NextAuth debug logging (defaults to NODE_ENV === \"development\"). */\n debug?: boolean;\n}\n\n/** Build internal callbacks that call the Augur SDK directly. */\nfunction buildInternalCallbacks(\n augurClient: AugurAuthClient,\n): AugurAuthCallbacks {\n return {\n async getUserProfile(userId: string): Promise<AugurUser | null> {\n if (!userId) return null;\n const uid = parseInt(userId, 10);\n if (isNaN(uid)) return null;\n const result = await augurClient.joomla.users.doc.get(uid, {\n edgeCache: 1,\n });\n const data = result.data;\n if (!data) return null;\n return {\n id: String(data.id),\n name: data.name,\n username: data.username,\n email: data.email,\n isVerified: true,\n customerId: data.customerId,\n contactId: data.contactId,\n };\n },\n async cartHdrLookup(\n userId: string | number,\n _token: string,\n contactId: string | number,\n customerId: string | number,\n ): Promise<{ cartHdrUid?: number } | null> {\n const result = await augurClient.commerce.cartHdr.lookup.get({\n userId: Number(userId) || 0,\n customerId: Number(customerId) || 0,\n contactId: Number(contactId) || 0,\n });\n return result.data ?? null;\n },\n };\n}\n\n/** Resolve final callbacks: callback overrides take priority over internal SDK calls. */\nfunction resolveCallbacks(\n options: CreateAuthConfigOptions,\n): AugurAuthCallbacks {\n const { augurClient, callbacks } = options;\n\n if (augurClient) {\n const internal = buildInternalCallbacks(augurClient);\n return {\n getUserProfile: callbacks?.getUserProfile ?? internal.getUserProfile,\n cartHdrLookup: callbacks?.cartHdrLookup ?? internal.cartHdrLookup,\n };\n }\n\n if (!callbacks?.getUserProfile) {\n throw new Error(\n \"createAuthConfig requires either `augurClient` or `callbacks.getUserProfile`\",\n );\n }\n\n return {\n getUserProfile: callbacks.getUserProfile,\n cartHdrLookup: callbacks.cartHdrLookup,\n };\n}\n\n/**\n * Create a NextAuth 5 configuration for an Augur ecommerce site.\n *\n * Accepts either an `augurClient` (recommended) for zero-boilerplate auth,\n * or explicit `callbacks` for custom behavior. Callback overrides take\n * priority when both are provided.\n *\n * @example\n * ```ts\n * // Recommended: pass the SDK client directly\n * import NextAuth from \"next-auth\";\n * import { createAuthConfig } from \"@simpleapps-com/augur-server/auth\";\n * import { augurClient } from \"@/lib/augur-client\";\n *\n * export const { handlers, signIn, signOut, auth } = NextAuth(\n * createAuthConfig({\n * augurClient,\n * defaultCustomerId: process.env.NEXT_PUBLIC_DEFAULT_CUSTOMER_ID,\n * defaultContactId: process.env.NEXT_PUBLIC_DEFAULT_CONTACT_ID,\n * }),\n * );\n * ```\n *\n * @example\n * ```ts\n * // Custom callbacks (backward-compatible)\n * import NextAuth from \"next-auth\";\n * import { createAuthConfig } from \"@simpleapps-com/augur-server/auth\";\n *\n * export const { handlers, signIn, signOut, auth } = NextAuth(\n * createAuthConfig({\n * callbacks: { getUserProfile, cartHdrLookup },\n * defaultCustomerId: process.env.NEXT_PUBLIC_DEFAULT_CUSTOMER_ID,\n * }),\n * );\n * ```\n */\nasync function lookupCartHdr(\n siteCallbacks: AugurAuthCallbacks,\n profile: AugurUser,\n defaultCustomerId?: string | number,\n defaultContactId?: string | number,\n): Promise<number | undefined> {\n if (!siteCallbacks.cartHdrLookup || !profile.id) return undefined;\n const cartHdr = await siteCallbacks.cartHdrLookup(\n profile.id,\n \"\",\n profile.contactId ?? defaultContactId ?? \"\",\n profile.customerId ?? defaultCustomerId ?? \"\",\n );\n return cartHdr?.cartHdrUid;\n}\n\nexport function createAuthConfig(\n options: CreateAuthConfigOptions,\n): NextAuthConfig {\n const {\n secret = process.env.NEXT_PUBLIC_AUTH_SECRET,\n maxAge = 4 * 60 * 60,\n defaultCustomerId,\n defaultContactId,\n debug = process.env.NODE_ENV === \"development\",\n } = options;\n\n const siteCallbacks = resolveCallbacks(options);\n\n return {\n providers: [\n Credentials({\n name: \"Credentials\",\n credentials: {\n username: { label: \"Username\", type: \"text\" },\n password: { label: \"Password\", type: \"password\" },\n id: { label: \"ID\", type: \"text\" },\n isVerified: { label: \"Is Verified\", type: \"text\" },\n token: { label: \"Token\", type: \"text\" },\n },\n async authorize(credentials) {\n if (!credentials) return null;\n\n const { id, isVerified, username, token } = credentials as {\n id: string;\n isVerified: string;\n username: string;\n token: string;\n };\n\n return {\n id,\n isVerified: isVerified === \"true\",\n username,\n token,\n };\n },\n }),\n ],\n callbacks: {\n async signIn() {\n return true;\n },\n async redirect({ baseUrl }) {\n return baseUrl;\n },\n async session({ session, token }) {\n const baseUser = {\n id: (token.id as string) || \"\",\n username: (token.username as string) || \"\",\n isVerified: (token.isVerified as boolean) || false,\n };\n\n const buildSession = (userOverrides = {}) => ({\n ...session,\n user: { ...session.user, ...baseUser, ...userOverrides },\n token: token.token as string | undefined,\n });\n\n try {\n const userProfile = await siteCallbacks.getUserProfile(baseUser.id);\n if (!userProfile) return buildSession();\n\n const cartHdrUid = await lookupCartHdr(\n siteCallbacks,\n userProfile,\n defaultCustomerId,\n defaultContactId,\n );\n\n return buildSession({\n name: userProfile.name ?? session.user?.name,\n email: userProfile.email ?? session.user?.email,\n customerId: userProfile.customerId ?? defaultCustomerId,\n contactId: userProfile.contactId,\n cartHdrUid,\n });\n } catch {\n return buildSession();\n }\n },\n async jwt({ token, user }) {\n if (user) {\n const typedUser = user as {\n id: string;\n isVerified: boolean;\n username: string;\n token: string;\n };\n\n return {\n ...token,\n id: typedUser.id,\n isVerified: typedUser.isVerified,\n username: typedUser.username,\n token: typedUser.token,\n };\n }\n return token;\n },\n },\n secret,\n debug,\n session: {\n strategy: \"jwt\",\n maxAge,\n },\n trustHost: true,\n };\n}\n"],"mappings":";AAIA,OAAO,iBAAiB;AAqGxB,SAAS,uBACP,aACoB;AACpB,SAAO;AAAA,IACL,MAAM,eAAe,QAA2C;AAC9D,UAAI,CAAC,OAAQ,QAAO;AACpB,YAAM,MAAM,SAAS,QAAQ,EAAE;AAC/B,UAAI,MAAM,GAAG,EAAG,QAAO;AACvB,YAAM,SAAS,MAAM,YAAY,OAAO,MAAM,IAAI,IAAI,KAAK;AAAA,QACzD,WAAW;AAAA,MACb,CAAC;AACD,YAAM,OAAO,OAAO;AACpB,UAAI,CAAC,KAAM,QAAO;AAClB,aAAO;AAAA,QACL,IAAI,OAAO,KAAK,EAAE;AAAA,QAClB,MAAM,KAAK;AAAA,QACX,UAAU,KAAK;AAAA,QACf,OAAO,KAAK;AAAA,QACZ,YAAY;AAAA,QACZ,YAAY,KAAK;AAAA,QACjB,WAAW,KAAK;AAAA,MAClB;AAAA,IACF;AAAA,IACA,MAAM,cACJ,QACA,QACA,WACA,YACyC;AACzC,YAAM,SAAS,MAAM,YAAY,SAAS,QAAQ,OAAO,IAAI;AAAA,QAC3D,QAAQ,OAAO,MAAM,KAAK;AAAA,QAC1B,YAAY,OAAO,UAAU,KAAK;AAAA,QAClC,WAAW,OAAO,SAAS,KAAK;AAAA,MAClC,CAAC;AACD,aAAO,OAAO,QAAQ;AAAA,IACxB;AAAA,EACF;AACF;AAGA,SAAS,iBACP,SACoB;AACpB,QAAM,EAAE,aAAa,UAAU,IAAI;AAEnC,MAAI,aAAa;AACf,UAAM,WAAW,uBAAuB,WAAW;AACnD,WAAO;AAAA,MACL,gBAAgB,WAAW,kBAAkB,SAAS;AAAA,MACtD,eAAe,WAAW,iBAAiB,SAAS;AAAA,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ACA,WAAW;AAAA,EACb;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/auth.ts"],"sourcesContent":["// @simpleapps-com/augur-server/auth\n// NextAuth 5 configuration factory for Augur ecommerce sites.\n\nimport type { AugurAPI } from \"@simpleapps-com/augur-api\";\nimport type { NextAuthConfig } from \"next-auth\";\nimport Credentials from \"next-auth/providers/credentials\";\n\n/** Base user fields shared across all Augur sites. */\nexport interface AugurUser {\n id: string;\n username: string;\n isVerified: boolean;\n name?: string;\n email?: string;\n customerId?: string | number;\n contactId?: string | number;\n cartHdrUid?: number;\n token?: string;\n}\n\n/** Session shape returned by all Augur sites. */\nexport interface AugurSession {\n user: AugurUser;\n token?: string;\n expires: string;\n}\n\n/** JWT token shape used by Augur auth. */\nexport interface AugurJWT {\n id: string;\n username: string;\n isVerified: boolean;\n token?: string;\n}\n\n/** Site-specific callbacks the consumer can provide. */\nexport interface AugurAuthCallbacks {\n /** Fetch user profile from the Augur API given the user's Joomla ID. */\n getUserProfile: (userId: string) => Promise<AugurUser | null>;\n /** Look up or create a cart header for the authenticated user. */\n cartHdrLookup?: (\n userId: string | number,\n token: string,\n contactId: string | number,\n customerId: string | number,\n ) => Promise<{ cartHdrUid?: number } | null>;\n}\n\n/** Derived from augur-api SDK — keeps types in sync automatically. */\nexport type AugurAuthClient = Pick<AugurAPI, \"joomla\" | \"commerce\">;\n\nexport interface CreateAuthConfigOptions {\n /** Augur SDK client. When provided, auth SDK calls are handled internally. */\n augurClient?: AugurAuthClient;\n /** Site-specific callbacks. Override internal SDK calls when custom behavior is needed. */\n callbacks?: Partial<AugurAuthCallbacks>;\n /** NextAuth secret (defaults to NEXT_PUBLIC_AUTH_SECRET env var). */\n secret?: string;\n /** Session max age in seconds (defaults to 4 hours). */\n maxAge?: number;\n /** Default customer ID when profile doesn't provide one. */\n defaultCustomerId?: string | number;\n /** Default contact ID for cart header lookups. */\n defaultContactId?: string | number;\n /** Enable NextAuth debug logging (defaults to NODE_ENV === \"development\"). */\n debug?: boolean;\n}\n\n/** Build internal callbacks that call the Augur SDK directly. */\nfunction buildInternalCallbacks(\n augurClient: AugurAuthClient,\n): AugurAuthCallbacks {\n return {\n async getUserProfile(userId: string): Promise<AugurUser | null> {\n if (!userId) return null;\n const uid = parseInt(userId, 10);\n if (isNaN(uid)) return null;\n const result = await augurClient.joomla.users.doc.get(uid, {\n edgeCache: 1,\n });\n const data = result.data;\n if (!data) return null;\n return {\n id: String(data.id),\n name: data.name,\n username: data.username,\n email: data.email,\n isVerified: true,\n customerId: data.customerId,\n contactId: data.contactId,\n };\n },\n async cartHdrLookup(\n userId: string | number,\n _token: string,\n contactId: string | number,\n customerId: string | number,\n ): Promise<{ cartHdrUid?: number } | null> {\n const result = await augurClient.commerce.cartHdr.lookup.get({\n userId: Number(userId) || 0,\n customerId: Number(customerId) || 0,\n contactId: Number(contactId) || 0,\n });\n return result.data ?? null;\n },\n };\n}\n\n/** Resolve final callbacks: callback overrides take priority over internal SDK calls. */\nfunction resolveCallbacks(\n options: CreateAuthConfigOptions,\n): AugurAuthCallbacks {\n const { augurClient, callbacks } = options;\n\n if (augurClient) {\n const internal = buildInternalCallbacks(augurClient);\n return {\n getUserProfile: callbacks?.getUserProfile ?? internal.getUserProfile,\n cartHdrLookup: callbacks?.cartHdrLookup ?? internal.cartHdrLookup,\n };\n }\n\n if (!callbacks?.getUserProfile) {\n throw new Error(\n \"createAuthConfig requires either `augurClient` or `callbacks.getUserProfile`\",\n );\n }\n\n return {\n getUserProfile: callbacks.getUserProfile,\n cartHdrLookup: callbacks.cartHdrLookup,\n };\n}\n\n/**\n * Create a NextAuth 5 configuration for an Augur ecommerce site.\n *\n * Accepts either an `augurClient` (recommended) for zero-boilerplate auth,\n * or explicit `callbacks` for custom behavior. Callback overrides take\n * priority when both are provided.\n *\n * @example\n * ```ts\n * // Recommended: pass the SDK client directly\n * import NextAuth from \"next-auth\";\n * import { createAuthConfig } from \"@simpleapps-com/augur-server/auth\";\n * import { augurClient } from \"@/lib/augur-client\";\n *\n * export const { handlers, signIn, signOut, auth } = NextAuth(\n * createAuthConfig({\n * augurClient,\n * defaultCustomerId: process.env.NEXT_PUBLIC_DEFAULT_CUSTOMER_ID,\n * defaultContactId: process.env.NEXT_PUBLIC_DEFAULT_CONTACT_ID,\n * }),\n * );\n * ```\n *\n * @example\n * ```ts\n * // Custom callbacks (backward-compatible)\n * import NextAuth from \"next-auth\";\n * import { createAuthConfig } from \"@simpleapps-com/augur-server/auth\";\n *\n * export const { handlers, signIn, signOut, auth } = NextAuth(\n * createAuthConfig({\n * callbacks: { getUserProfile, cartHdrLookup },\n * defaultCustomerId: process.env.NEXT_PUBLIC_DEFAULT_CUSTOMER_ID,\n * }),\n * );\n * ```\n */\nasync function lookupCartHdr(\n siteCallbacks: AugurAuthCallbacks,\n profile: AugurUser,\n defaultCustomerId?: string | number,\n defaultContactId?: string | number,\n): Promise<number | undefined> {\n if (!siteCallbacks.cartHdrLookup || !profile.id) return undefined;\n const cartHdr = await siteCallbacks.cartHdrLookup(\n profile.id,\n \"\",\n profile.contactId ?? defaultContactId ?? \"\",\n profile.customerId ?? defaultCustomerId ?? \"\",\n );\n return cartHdr?.cartHdrUid;\n}\n\nexport function createAuthConfig(\n options: CreateAuthConfigOptions,\n): NextAuthConfig {\n const {\n secret = process.env.NEXT_PUBLIC_AUTH_SECRET,\n maxAge = 4 * 60 * 60,\n defaultCustomerId,\n defaultContactId,\n debug = process.env.NODE_ENV === \"development\",\n } = options;\n\n const siteCallbacks = resolveCallbacks(options);\n\n return {\n providers: [\n Credentials({\n name: \"Credentials\",\n credentials: {\n username: { label: \"Username\", type: \"text\" },\n password: { label: \"Password\", type: \"password\" },\n id: { label: \"ID\", type: \"text\" },\n isVerified: { label: \"Is Verified\", type: \"text\" },\n token: { label: \"Token\", type: \"text\" },\n },\n async authorize(credentials) {\n if (!credentials) return null;\n\n const { id, isVerified, username, token } = credentials as {\n id: string;\n isVerified: string;\n username: string;\n token: string;\n };\n\n return {\n id,\n isVerified: isVerified === \"true\",\n username,\n token,\n };\n },\n }),\n ],\n callbacks: {\n async signIn() {\n return true;\n },\n async redirect({ baseUrl }) {\n return baseUrl;\n },\n async session({ session, token }) {\n const baseUser = {\n id: (token.id as string) || \"\",\n username: (token.username as string) || \"\",\n isVerified: (token.isVerified as boolean) || false,\n };\n\n const buildSession = (userOverrides = {}) => ({\n ...session,\n user: { ...session.user, ...baseUser, ...userOverrides },\n token: token.token as string | undefined,\n });\n\n try {\n const userProfile = await siteCallbacks.getUserProfile(baseUser.id);\n if (!userProfile) return buildSession();\n\n const cartHdrUid = await lookupCartHdr(\n siteCallbacks,\n userProfile,\n defaultCustomerId,\n defaultContactId,\n );\n\n return buildSession({\n name: userProfile.name ?? session.user?.name,\n email: userProfile.email ?? session.user?.email,\n customerId: userProfile.customerId ?? defaultCustomerId,\n contactId: userProfile.contactId,\n cartHdrUid,\n });\n } catch {\n return buildSession();\n }\n },\n async jwt({ token, user }) {\n if (user) {\n const typedUser = user as {\n id: string;\n isVerified: boolean;\n username: string;\n token: string;\n };\n\n return {\n ...token,\n id: typedUser.id,\n isVerified: typedUser.isVerified,\n username: typedUser.username,\n token: typedUser.token,\n };\n }\n return token;\n },\n },\n secret,\n debug,\n session: {\n strategy: \"jwt\",\n maxAge,\n },\n trustHost: true,\n };\n}\n"],"mappings":";AAKA,OAAO,iBAAiB;AAgExB,SAAS,uBACP,aACoB;AACpB,SAAO;AAAA,IACL,MAAM,eAAe,QAA2C;AAC9D,UAAI,CAAC,OAAQ,QAAO;AACpB,YAAM,MAAM,SAAS,QAAQ,EAAE;AAC/B,UAAI,MAAM,GAAG,EAAG,QAAO;AACvB,YAAM,SAAS,MAAM,YAAY,OAAO,MAAM,IAAI,IAAI,KAAK;AAAA,QACzD,WAAW;AAAA,MACb,CAAC;AACD,YAAM,OAAO,OAAO;AACpB,UAAI,CAAC,KAAM,QAAO;AAClB,aAAO;AAAA,QACL,IAAI,OAAO,KAAK,EAAE;AAAA,QAClB,MAAM,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AA,YACA;AAAA,YACA;AAAA,UACF;AAEA,iBAAO,aAAa;AAAA,YAClB,MAAM,YAAY,QAAQ,QAAQ,MAAM;AAAA,YACxC,OAAO,YAAY,SAAS,QAAQ,MAAM;AAAA,YAC1C,YAAY,YAAY,cAAc;AAAA,YACtC,WAAW,YAAY;AAAA,YACvB;AAAA,UACF,CAAC;AAAA,QACH,QAAQ;AACN,iBAAO,aAAa;AAAA,QACtB;AAAA,MACF;AAAA,MACA,MAAM,IAAI,EAAE,OAAO,KAAK,GAAG;AACzB,YAAI,MAAM;AACR,gBAAM,YAAY;AAOlB,iBAAO;AAAA,YACL,GAAG;AAAA,YACH,IAAI,UAAU;AAAA,YACd,YAAY,UAAU;AAAA,YACtB,UAAU,UAAU;AAAA,YACpB,OAAO,UAAU;AAAA,UACnB;AAAA,QACF;AACA,eAAO;AAAA,MACT;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA,SAAS;AAAA,MACP,UAAU;AAAA,MACV;AAAA,IACF;AAAA,IACA,WAAW;AAAA,EACb;AACF;","names":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { E as EdgeCacheValue } from './site-D21WJ8z1.js';
|
|
2
|
+
export { A as ActionResult, a as AddressValidationResult, b as AgrInfoActions, c as AgrInfoActionsConfig, d as AgrInfoApiClient, e as AgrSiteActions, f as AgrSiteActionsConfig, g as AgrSiteApiClient, h as AgrWorkActions, i as AgrWorkActionsConfig, j as AgrWorkApiClient, k as AvalaraActions, l as AvalaraActionsConfig, m as AvalaraApiClient, B as Basecamp2Actions, n as Basecamp2ActionsConfig, o as Basecamp2ApiClient, p as BrandFolderActions, q as BrandFolderActionsConfig, r as BrandFolderApiClient, C as CommerceActions, s as CommerceActionsConfig, t as CommerceApiClient, u as CustomerListResult, v as CustomersActions, w as CustomersActionsConfig, x as CustomersApiClient, G as GregorovichActions, y as GregorovichActionsConfig, z as GregorovichApiClient, I as ItemActions, D as ItemActionsConfig, F as ItemsApiClient, J as JoomlaActions, H as JoomlaActionsConfig, K as JoomlaApiClient, L as LegacyActions, M as LegacyActionsConfig, N as LegacyApiClient, O as LogisticsActions, P as LogisticsActionsConfig, Q as LogisticsApiClient, R as NexusActions, S as NexusActionsConfig, T as NexusApiClient, U as NormalizedUserProfile, V as OrderActions, W as OrderActionsConfig, X as OrderApiClient, Y as P21ApisActions, Z as P21ApisActionsConfig, _ as P21ApisApiClient, $ as P21CoreActions, a0 as P21CoreActionsConfig, a1 as P21CoreApiClient, a2 as P21PimActions, a3 as P21PimActionsConfig, a4 as P21PimApiClient, a5 as P21SismActions, a6 as P21SismActionsConfig, a7 as P21SismApiClient, a8 as PaymentsActions, a9 as PaymentsActionsConfig, aa as PaymentsApiClient, ab as PricingActions, ac as PricingActionsConfig, ad as PricingApiClient, ae as SearchActions, af as SearchActionsConfig, ag as SearchApiClient, ah as SearchPage, ai as ShippingActions, aj as ShippingActionsConfig, ak as ShippingAddress, al as ShippingApiClient, am as SiteActions, an as SiteActionsConfig, ao as SlackActions, ap as SlackActionsConfig, aq as SlackApiClient, ar as SmartyStreetsActions, as as SmartyStreetsActionsConfig, at as SmartyStreetsApiClient, au as UpsActions, av as UpsActionsConfig, aw as UpsApiClient, ax as VmiActions, ay as VmiActionsConfig, az as VmiApiClient, aA as createAgrInfoActions, aB as createAgrSiteActions, aC as createAgrWorkActions, aD as createAvalaraActions, aE as createBasecamp2Actions, aF as createBrandFolderActions, aG as createCommerceActions, aH as createCustomersActions, aI as createGregorovichActions, aJ as createItemActions, aK as createJoomlaActions, aL as createLegacyActions, aM as createLogisticsActions, aN as createNexusActions, aO as createOrderActions, aP as createP21ApisActions, aQ as createP21CoreActions, aR as createP21PimActions, aS as createP21SismActions, aT as createPaymentsActions, aU as createPricingActions, aV as createSearchActions, aW as createShippingActions, aX as createSiteActions, aY as createSlackActions, aZ as createSmartyStreetsActions, a_ as createUpsActions, a$ as createVmiActions, b0 as safeAction, b1 as sdkCall } from './site-D21WJ8z1.js';
|
|
1
3
|
import { QueryClient } from '@tanstack/react-query';
|
|
2
4
|
export { QueryOptionsConfig, createQueryOptions, createSuspenseQueryOptions } from './query.js';
|
|
3
|
-
|
|
5
|
+
import { AugurAPI } from '@simpleapps-com/augur-api';
|
|
4
6
|
import '@simpleapps-com/augur-utils';
|
|
5
7
|
|
|
6
8
|
declare const env: "development" | "staging" | "production";
|
|
@@ -13,71 +15,6 @@ declare function cacheSet(key: string, value: string, ttlSeconds: number): Promi
|
|
|
13
15
|
declare function getCircuitState(): "closed" | "open";
|
|
14
16
|
declare function isRedisConnected(): boolean;
|
|
15
17
|
|
|
16
|
-
/**
|
|
17
|
-
* Calls an Augur SDK method, forwarding all arguments with full type safety.
|
|
18
|
-
*
|
|
19
|
-
* With augur-api >= 0.9.6, SDK methods properly declare their `CacheParams`
|
|
20
|
-
* option (including `edgeCache`), so this wrapper preserves both parameter
|
|
21
|
-
* and return-type inference end-to-end.
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```ts
|
|
25
|
-
* const result = await sdkCall(
|
|
26
|
-
* augurServices.items.invMast.get,
|
|
27
|
-
* invMastUid,
|
|
28
|
-
* { edgeCache: 4 },
|
|
29
|
-
* );
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
declare function sdkCall<TArgs extends unknown[], TResult>(method: (...args: TArgs) => Promise<TResult>, ...args: TArgs): Promise<TResult>;
|
|
33
|
-
/**
|
|
34
|
-
* Discriminated union for safe action results.
|
|
35
|
-
* Same pattern as next-safe-action — callers check `result.ok` to
|
|
36
|
-
* determine success or failure with typed error info.
|
|
37
|
-
*/
|
|
38
|
-
type ActionResult<T> = {
|
|
39
|
-
ok: true;
|
|
40
|
-
data: T;
|
|
41
|
-
} | {
|
|
42
|
-
ok: false;
|
|
43
|
-
error: string;
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* Wraps an async function call with error handling, returning an
|
|
47
|
-
* `ActionResult<T>` instead of throwing.
|
|
48
|
-
*
|
|
49
|
-
* Use this to eliminate try/catch boilerplate in server actions.
|
|
50
|
-
* Reads that go through React Query should NOT use this — let errors
|
|
51
|
-
* propagate so React Query can handle retries and error state.
|
|
52
|
-
*
|
|
53
|
-
* @param fn — The async function to execute
|
|
54
|
-
* @param onError — Optional callback for logging/reporting
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* ```ts
|
|
58
|
-
* // Before (boilerplate wrapper):
|
|
59
|
-
* export async function addToCart(cartId: number, items: CartItem[]) {
|
|
60
|
-
* try {
|
|
61
|
-
* return await actions.commerce.addToCart(cartId, items);
|
|
62
|
-
* } catch (error) {
|
|
63
|
-
* console.error("addToCart error:", error);
|
|
64
|
-
* return undefined;
|
|
65
|
-
* }
|
|
66
|
-
* }
|
|
67
|
-
*
|
|
68
|
-
* // After (one-liner):
|
|
69
|
-
* const result = await safeAction(
|
|
70
|
-
* () => actions.commerce.addToCart(cartId, items),
|
|
71
|
-
* );
|
|
72
|
-
* if (result.ok) {
|
|
73
|
-
* // result.data is the response
|
|
74
|
-
* } else {
|
|
75
|
-
* // result.error is the error message
|
|
76
|
-
* }
|
|
77
|
-
* ```
|
|
78
|
-
*/
|
|
79
|
-
declare function safeAction<T>(fn: () => Promise<T>, onError?: (error: Error) => void): Promise<ActionResult<T>>;
|
|
80
|
-
|
|
81
18
|
/**
|
|
82
19
|
* Fetches data for multiple params in parallel, returning a Record keyed by
|
|
83
20
|
* `getKey(param)`. Individual failures are silently excluded from the result
|
|
@@ -152,35 +89,13 @@ interface PaginatedResult<T> {
|
|
|
152
89
|
*/
|
|
153
90
|
declare function paginateOffset<T>(items: T[], pageParam: number, limit: number, total?: number): PaginatedResult<T>;
|
|
154
91
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
itemWishlist: {
|
|
158
|
-
list: (userId: number, params?: Record<string, unknown>) => Promise<{
|
|
159
|
-
data: unknown[];
|
|
160
|
-
}>;
|
|
161
|
-
create: (userId: number, data: Record<string, unknown>) => Promise<{
|
|
162
|
-
data: unknown;
|
|
163
|
-
}>;
|
|
164
|
-
hdr: {
|
|
165
|
-
get: (userId: number, wishlistId: number, params?: Record<string, unknown>) => Promise<{
|
|
166
|
-
data: unknown;
|
|
167
|
-
}>;
|
|
168
|
-
delete: (userId: number, wishlistId: number) => Promise<void>;
|
|
169
|
-
create: (userId: number, wishlistId: number, items: Record<string, unknown>[]) => Promise<{
|
|
170
|
-
data: unknown;
|
|
171
|
-
}>;
|
|
172
|
-
line: {
|
|
173
|
-
delete: (userId: number, wishlistId: number, lineId: number) => Promise<void>;
|
|
174
|
-
};
|
|
175
|
-
};
|
|
176
|
-
};
|
|
177
|
-
};
|
|
178
|
-
}
|
|
92
|
+
/** Derived from augur-api SDK — keeps types in sync automatically. */
|
|
93
|
+
type WishlistsApiClient = Pick<AugurAPI, "items">;
|
|
179
94
|
interface WishlistActionsConfig {
|
|
180
95
|
/** Cache key prefix (e.g. "ampro:"). Default: "". */
|
|
181
96
|
cachePrefix?: string;
|
|
182
97
|
/** CDN edge cache value passed to SDK. Default: 1 (hour). */
|
|
183
|
-
edgeCache?:
|
|
98
|
+
edgeCache?: EdgeCacheValue;
|
|
184
99
|
/** Redis TTL in seconds. Default: 3600 (1 hour). */
|
|
185
100
|
redisTtl?: number;
|
|
186
101
|
}
|
|
@@ -199,24 +114,13 @@ interface WishlistActions {
|
|
|
199
114
|
}
|
|
200
115
|
declare function createWishlistActions(api: WishlistsApiClient, config?: WishlistActionsConfig): WishlistActions;
|
|
201
116
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
itemFavorites: {
|
|
205
|
-
list: (userId: number, params?: Record<string, unknown>) => Promise<{
|
|
206
|
-
data: unknown[];
|
|
207
|
-
}>;
|
|
208
|
-
create: (userId: number, data: Record<string, unknown>) => Promise<{
|
|
209
|
-
data: unknown;
|
|
210
|
-
}>;
|
|
211
|
-
delete: (userId: number, invMastUid: number) => Promise<void>;
|
|
212
|
-
};
|
|
213
|
-
};
|
|
214
|
-
}
|
|
117
|
+
/** Derived from augur-api SDK — keeps types in sync automatically. */
|
|
118
|
+
type FavoritesApiClient = Pick<AugurAPI, "items">;
|
|
215
119
|
interface FavoritesActionsConfig {
|
|
216
120
|
/** Cache key prefix (e.g. "ampro:"). Default: "". */
|
|
217
121
|
cachePrefix?: string;
|
|
218
122
|
/** CDN edge cache value passed to SDK. Default: 1 (hour). */
|
|
219
|
-
edgeCache?:
|
|
123
|
+
edgeCache?: EdgeCacheValue;
|
|
220
124
|
/** Redis TTL in seconds. Default: 3600 (1 hour). */
|
|
221
125
|
redisTtl?: number;
|
|
222
126
|
}
|
|
@@ -227,4 +131,4 @@ interface FavoritesActions {
|
|
|
227
131
|
}
|
|
228
132
|
declare function createFavoritesActions(api: FavoritesApiClient, config?: FavoritesActionsConfig): FavoritesActions;
|
|
229
133
|
|
|
230
|
-
export {
|
|
134
|
+
export { EdgeCacheValue, type FavoritesActions, type FavoritesActionsConfig, type FavoritesApiClient, type PaginatedResult, type WishlistActions, type WishlistActionsConfig, type WishlistsApiClient, batchFetch, cacheGet, cacheSet, createFavoritesActions, createServerQueryClient, createWishlistActions, env, getCircuitState, getServerQueryClient, isDev, isProduction, isRedisConnected, isStaging, paginateOffset, withServerCache };
|
package/dist/index.js
CHANGED
|
@@ -296,9 +296,10 @@ function createItemActions(api, config = {}) {
|
|
|
296
296
|
uid,
|
|
297
297
|
options
|
|
298
298
|
);
|
|
299
|
+
const cat = category;
|
|
299
300
|
return {
|
|
300
|
-
...
|
|
301
|
-
children: sortCategoryChildren(
|
|
301
|
+
...cat,
|
|
302
|
+
children: sortCategoryChildren(cat.children)
|
|
302
303
|
};
|
|
303
304
|
}
|
|
304
305
|
async function getCategoryItems(uid, filters) {
|
|
@@ -508,6 +509,7 @@ function createCommerceActions(api, config = {}) {
|
|
|
508
509
|
}));
|
|
509
510
|
const response = await api.commerce.cartLine.add.create(
|
|
510
511
|
cartHdrUid,
|
|
512
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
511
513
|
{ items: mappedItems }
|
|
512
514
|
);
|
|
513
515
|
return response.data;
|
|
@@ -523,6 +525,7 @@ function createCommerceActions(api, config = {}) {
|
|
|
523
525
|
}));
|
|
524
526
|
const response = await api.commerce.cartLine.update.create(
|
|
525
527
|
cartHdrUid,
|
|
528
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
526
529
|
{ lines: mappedLines }
|
|
527
530
|
);
|
|
528
531
|
return response.data;
|
|
@@ -565,26 +568,26 @@ function createCommerceActions(api, config = {}) {
|
|
|
565
568
|
// src/actions/orders.ts
|
|
566
569
|
function createOrderActions(api, config = {}) {
|
|
567
570
|
const { cachePrefix = "", edgeCache = 1, redisTtl = 3600 } = config;
|
|
568
|
-
async function getOrderDoc(orderNo,
|
|
569
|
-
const params = { orderNo, zipCode, edgeCache };
|
|
571
|
+
async function getOrderDoc(orderNo, postalCode) {
|
|
570
572
|
return withServerCache(
|
|
571
573
|
cachePrefix,
|
|
572
574
|
redisTtl,
|
|
573
575
|
"orders.oeHdr.doc.get",
|
|
574
576
|
async () => {
|
|
575
|
-
const response = await api.orders.oeHdr.doc.get(
|
|
577
|
+
const response = await api.orders.oeHdr.doc.get(Number(orderNo), {
|
|
578
|
+
postalCode,
|
|
579
|
+
edgeCache
|
|
580
|
+
});
|
|
576
581
|
return response.data;
|
|
577
582
|
},
|
|
578
|
-
|
|
583
|
+
orderNo,
|
|
584
|
+
postalCode
|
|
579
585
|
);
|
|
580
586
|
}
|
|
581
587
|
return { getOrderDoc };
|
|
582
588
|
}
|
|
583
589
|
|
|
584
590
|
// src/actions/search.ts
|
|
585
|
-
function getOpenSearch(api) {
|
|
586
|
-
return "openSearch" in api ? api.openSearch : api.opensearch;
|
|
587
|
-
}
|
|
588
591
|
function createSearchActions(api, config = {}) {
|
|
589
592
|
const {
|
|
590
593
|
cachePrefix = "",
|
|
@@ -592,7 +595,7 @@ function createSearchActions(api, config = {}) {
|
|
|
592
595
|
redisTtl = 3600,
|
|
593
596
|
defaultSourceFields = "display_desc"
|
|
594
597
|
} = config;
|
|
595
|
-
const openSearch =
|
|
598
|
+
const openSearch = api.opensearch;
|
|
596
599
|
async function getSearchAttributes(q) {
|
|
597
600
|
const params = { q, edgeCache };
|
|
598
601
|
return withServerCache(
|
|
@@ -600,7 +603,10 @@ function createSearchActions(api, config = {}) {
|
|
|
600
603
|
redisTtl,
|
|
601
604
|
"openSearch.itemSearch.attributes.list",
|
|
602
605
|
async () => {
|
|
603
|
-
const response =
|
|
606
|
+
const response = (
|
|
607
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
608
|
+
await openSearch.itemSearch.attributes.list(params)
|
|
609
|
+
);
|
|
604
610
|
return response.data.attributes;
|
|
605
611
|
},
|
|
606
612
|
q
|
|
@@ -615,7 +621,10 @@ function createSearchActions(api, config = {}) {
|
|
|
615
621
|
redisTtl,
|
|
616
622
|
"openSearch.suggestions.suggest.list",
|
|
617
623
|
async () => {
|
|
618
|
-
const response =
|
|
624
|
+
const response = (
|
|
625
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
626
|
+
await openSearch.suggestions.suggest.list(params)
|
|
627
|
+
);
|
|
619
628
|
return response.data;
|
|
620
629
|
},
|
|
621
630
|
q
|
|
@@ -768,9 +777,7 @@ function createJoomlaActions(api, config = {}) {
|
|
|
768
777
|
redisTtl,
|
|
769
778
|
"joomla.menu.doc.get",
|
|
770
779
|
async () => {
|
|
771
|
-
const response = await api.joomla.menu.doc.get(menuId
|
|
772
|
-
edgeCache
|
|
773
|
-
});
|
|
780
|
+
const response = await api.joomla.menu.doc.get(String(menuId));
|
|
774
781
|
return response.data;
|
|
775
782
|
},
|
|
776
783
|
menuId
|
|
@@ -909,6 +916,7 @@ function createCustomersActions(api, config = {}) {
|
|
|
909
916
|
const response = await api.customers.customer.lookup.get({
|
|
910
917
|
...params,
|
|
911
918
|
edgeCache
|
|
919
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
912
920
|
});
|
|
913
921
|
return response.data;
|
|
914
922
|
},
|
|
@@ -919,9 +927,9 @@ function createCustomersActions(api, config = {}) {
|
|
|
919
927
|
return withServerCache(
|
|
920
928
|
cachePrefix,
|
|
921
929
|
redisTtl,
|
|
922
|
-
"customers.customer.doc.
|
|
930
|
+
"customers.customer.doc.get",
|
|
923
931
|
async () => {
|
|
924
|
-
const response = await api.customers.customer.doc.
|
|
932
|
+
const response = await api.customers.customer.doc.get(customerId, {
|
|
925
933
|
edgeCache
|
|
926
934
|
});
|
|
927
935
|
return response.data;
|
|
@@ -970,6 +978,7 @@ function createCustomersActions(api, config = {}) {
|
|
|
970
978
|
async () => {
|
|
971
979
|
const response = await api.customers.customer.invoices.list(
|
|
972
980
|
customerId,
|
|
981
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
973
982
|
{ ...params, edgeCache }
|
|
974
983
|
);
|
|
975
984
|
return { data: response.data, total: response.total };
|
|
@@ -1102,9 +1111,7 @@ function createP21PimActions(api, config = {}) {
|
|
|
1102
1111
|
redisTtl,
|
|
1103
1112
|
"p21Pim.invMastExt.get",
|
|
1104
1113
|
async () => {
|
|
1105
|
-
const response = await api.p21Pim.invMastExt.get(invMastUid
|
|
1106
|
-
edgeCache
|
|
1107
|
-
});
|
|
1114
|
+
const response = await api.p21Pim.invMastExt.get(invMastUid);
|
|
1108
1115
|
return response.data;
|
|
1109
1116
|
},
|
|
1110
1117
|
invMastUid
|
|
@@ -1147,6 +1154,7 @@ function createAgrSiteActions(api, config = {}) {
|
|
|
1147
1154
|
const response = await api.agrSite.settings.list({
|
|
1148
1155
|
...serviceName ? { serviceName } : {},
|
|
1149
1156
|
edgeCache: longEdgeCache
|
|
1157
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1150
1158
|
});
|
|
1151
1159
|
return response.data;
|
|
1152
1160
|
},
|
|
@@ -1194,7 +1202,10 @@ function createPaymentsActions(api, config = {}) {
|
|
|
1194
1202
|
}
|
|
1195
1203
|
async function transactionSetup(params) {
|
|
1196
1204
|
try {
|
|
1197
|
-
const response =
|
|
1205
|
+
const response = (
|
|
1206
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1207
|
+
await api.payments.unified.transactionSetup.get(withMode(params))
|
|
1208
|
+
);
|
|
1198
1209
|
return response.data;
|
|
1199
1210
|
} catch {
|
|
1200
1211
|
return void 0;
|
|
@@ -1202,7 +1213,10 @@ function createPaymentsActions(api, config = {}) {
|
|
|
1202
1213
|
}
|
|
1203
1214
|
async function accountQuery(params) {
|
|
1204
1215
|
try {
|
|
1205
|
-
const response =
|
|
1216
|
+
const response = (
|
|
1217
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1218
|
+
await api.payments.unified.accountQuery.get(withMode(params))
|
|
1219
|
+
);
|
|
1206
1220
|
return response.data;
|
|
1207
1221
|
} catch {
|
|
1208
1222
|
return void 0;
|
|
@@ -1210,7 +1224,10 @@ function createPaymentsActions(api, config = {}) {
|
|
|
1210
1224
|
}
|
|
1211
1225
|
async function getSurcharge(params) {
|
|
1212
1226
|
try {
|
|
1213
|
-
const response =
|
|
1227
|
+
const response = (
|
|
1228
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1229
|
+
await api.payments.unified.surcharge.get(withMode(params))
|
|
1230
|
+
);
|
|
1214
1231
|
return response.data;
|
|
1215
1232
|
} catch {
|
|
1216
1233
|
return void 0;
|
|
@@ -1218,7 +1235,10 @@ function createPaymentsActions(api, config = {}) {
|
|
|
1218
1235
|
}
|
|
1219
1236
|
async function cardInfo(params) {
|
|
1220
1237
|
try {
|
|
1221
|
-
const response =
|
|
1238
|
+
const response = (
|
|
1239
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1240
|
+
await api.payments.unified.cardInfo.get(withMode(params))
|
|
1241
|
+
);
|
|
1222
1242
|
return response.data;
|
|
1223
1243
|
} catch {
|
|
1224
1244
|
return void 0;
|
|
@@ -1226,7 +1246,10 @@ function createPaymentsActions(api, config = {}) {
|
|
|
1226
1246
|
}
|
|
1227
1247
|
async function billingUpdate(params) {
|
|
1228
1248
|
try {
|
|
1229
|
-
const response =
|
|
1249
|
+
const response = (
|
|
1250
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1251
|
+
await api.payments.unified.billingUpdate.get(withMode(params))
|
|
1252
|
+
);
|
|
1230
1253
|
return response.data;
|
|
1231
1254
|
} catch {
|
|
1232
1255
|
return void 0;
|
|
@@ -1234,7 +1257,10 @@ function createPaymentsActions(api, config = {}) {
|
|
|
1234
1257
|
}
|
|
1235
1258
|
async function validatePayment(params) {
|
|
1236
1259
|
try {
|
|
1237
|
-
const response =
|
|
1260
|
+
const response = (
|
|
1261
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1262
|
+
await api.payments.unified.validate.get(withMode(params))
|
|
1263
|
+
);
|
|
1238
1264
|
return response.data;
|
|
1239
1265
|
} catch {
|
|
1240
1266
|
return void 0;
|
|
@@ -1290,6 +1316,7 @@ function createLogisticsActions(api, config = {}) {
|
|
|
1290
1316
|
const response = await api.logistics.shipvia.rates.list({
|
|
1291
1317
|
...params,
|
|
1292
1318
|
edgeCache: longEdgeCache
|
|
1319
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1293
1320
|
});
|
|
1294
1321
|
return response.data;
|
|
1295
1322
|
},
|
|
@@ -1419,6 +1446,7 @@ function createVmiActions(api, config = {}) {
|
|
|
1419
1446
|
async () => {
|
|
1420
1447
|
const response = await api.vmi.warehouse.availability.get(
|
|
1421
1448
|
warehouseUid,
|
|
1449
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1422
1450
|
{ ...params, edgeCache }
|
|
1423
1451
|
);
|
|
1424
1452
|
return response.data;
|
|
@@ -1466,6 +1494,7 @@ function createVmiActions(api, config = {}) {
|
|
|
1466
1494
|
const response = await api.vmi.invProfileHdr.list({
|
|
1467
1495
|
...params,
|
|
1468
1496
|
edgeCache
|
|
1497
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1469
1498
|
});
|
|
1470
1499
|
return response.data;
|
|
1471
1500
|
},
|
|
@@ -1481,6 +1510,7 @@ function createVmiActions(api, config = {}) {
|
|
|
1481
1510
|
const response = await api.vmi.restockHdr.list({
|
|
1482
1511
|
...params,
|
|
1483
1512
|
edgeCache
|
|
1513
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1484
1514
|
});
|
|
1485
1515
|
return response.data;
|
|
1486
1516
|
},
|
|
@@ -1496,6 +1526,7 @@ function createVmiActions(api, config = {}) {
|
|
|
1496
1526
|
const response = await api.vmi.sections.list({
|
|
1497
1527
|
...params,
|
|
1498
1528
|
edgeCache
|
|
1529
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1499
1530
|
});
|
|
1500
1531
|
return response.data;
|
|
1501
1532
|
},
|
|
@@ -1621,6 +1652,7 @@ function createP21CoreActions(api, config = {}) {
|
|
|
1621
1652
|
const response = await api.p21Core.codeP21.list({
|
|
1622
1653
|
...params,
|
|
1623
1654
|
edgeCache: longEdgeCache
|
|
1655
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1624
1656
|
});
|
|
1625
1657
|
return response.data;
|
|
1626
1658
|
},
|
|
@@ -1737,7 +1769,10 @@ function createP21ApisActions(api, config = {}) {
|
|
|
1737
1769
|
}
|
|
1738
1770
|
async function refreshContacts(params) {
|
|
1739
1771
|
try {
|
|
1740
|
-
const response =
|
|
1772
|
+
const response = (
|
|
1773
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1774
|
+
await api.p21Apis.entityContacts.refresh.create(params)
|
|
1775
|
+
);
|
|
1741
1776
|
return response.data;
|
|
1742
1777
|
} catch {
|
|
1743
1778
|
return void 0;
|
|
@@ -1745,7 +1780,10 @@ function createP21ApisActions(api, config = {}) {
|
|
|
1745
1780
|
}
|
|
1746
1781
|
async function refreshCustomers(params) {
|
|
1747
1782
|
try {
|
|
1748
|
-
const response =
|
|
1783
|
+
const response = (
|
|
1784
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1785
|
+
await api.p21Apis.entityCustomers.refresh.create(params)
|
|
1786
|
+
);
|
|
1749
1787
|
return response.data;
|
|
1750
1788
|
} catch {
|
|
1751
1789
|
return void 0;
|
|
@@ -1959,6 +1997,7 @@ function createBasecamp2Actions(api, config = {}) {
|
|
|
1959
1997
|
const response = await api.basecamp2.todos.list({
|
|
1960
1998
|
...params,
|
|
1961
1999
|
edgeCache
|
|
2000
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1962
2001
|
});
|
|
1963
2002
|
return response.data;
|
|
1964
2003
|
},
|
|
@@ -1986,6 +2025,7 @@ function createBasecamp2Actions(api, config = {}) {
|
|
|
1986
2025
|
const response = await api.basecamp2.todosSummary.list({
|
|
1987
2026
|
...params,
|
|
1988
2027
|
edgeCache
|
|
2028
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1989
2029
|
});
|
|
1990
2030
|
return response.data;
|
|
1991
2031
|
},
|
|
@@ -2001,6 +2041,7 @@ function createBasecamp2Actions(api, config = {}) {
|
|
|
2001
2041
|
const response = await api.basecamp2.comments.list({
|
|
2002
2042
|
...params,
|
|
2003
2043
|
edgeCache
|
|
2044
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2004
2045
|
});
|
|
2005
2046
|
return response.data;
|
|
2006
2047
|
},
|
|
@@ -2016,6 +2057,7 @@ function createBasecamp2Actions(api, config = {}) {
|
|
|
2016
2057
|
const response = await api.basecamp2.people.list({
|
|
2017
2058
|
...params,
|
|
2018
2059
|
edgeCache: longEdgeCache
|
|
2060
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2019
2061
|
});
|
|
2020
2062
|
return response.data;
|
|
2021
2063
|
},
|
|
@@ -2031,6 +2073,7 @@ function createBasecamp2Actions(api, config = {}) {
|
|
|
2031
2073
|
const response = await api.basecamp2.projects.list({
|
|
2032
2074
|
...params,
|
|
2033
2075
|
edgeCache
|
|
2076
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2034
2077
|
});
|
|
2035
2078
|
return response.data;
|
|
2036
2079
|
},
|
|
@@ -2046,6 +2089,7 @@ function createBasecamp2Actions(api, config = {}) {
|
|
|
2046
2089
|
const response = await api.basecamp2.events.list({
|
|
2047
2090
|
...params,
|
|
2048
2091
|
edgeCache
|
|
2092
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2049
2093
|
});
|
|
2050
2094
|
return response.data;
|
|
2051
2095
|
},
|
|
@@ -2061,6 +2105,7 @@ function createBasecamp2Actions(api, config = {}) {
|
|
|
2061
2105
|
const response = await api.basecamp2.metrics.list({
|
|
2062
2106
|
...params,
|
|
2063
2107
|
edgeCache
|
|
2108
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2064
2109
|
});
|
|
2065
2110
|
return response.data;
|
|
2066
2111
|
},
|
|
@@ -2076,6 +2121,7 @@ function createBasecamp2Actions(api, config = {}) {
|
|
|
2076
2121
|
const response = await api.basecamp2.todolists.list({
|
|
2077
2122
|
...params,
|
|
2078
2123
|
edgeCache
|
|
2124
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2079
2125
|
});
|
|
2080
2126
|
return response.data;
|
|
2081
2127
|
},
|
|
@@ -2147,7 +2193,7 @@ function createBrandFolderActions(api, config = {}) {
|
|
|
2147
2193
|
|
|
2148
2194
|
// src/actions/gregorovich.ts
|
|
2149
2195
|
function createGregorovichActions(api, config = {}) {
|
|
2150
|
-
const { cachePrefix = "",
|
|
2196
|
+
const { cachePrefix = "", redisTtl = 3600 } = config;
|
|
2151
2197
|
async function askChatGpt(params) {
|
|
2152
2198
|
try {
|
|
2153
2199
|
const response = await api.gregorovich.chatGpt.ask.get(params);
|
|
@@ -2162,10 +2208,7 @@ function createGregorovichActions(api, config = {}) {
|
|
|
2162
2208
|
redisTtl,
|
|
2163
2209
|
"gregorovich.documents.list",
|
|
2164
2210
|
async () => {
|
|
2165
|
-
const response = await api.gregorovich.documents.list(
|
|
2166
|
-
...params,
|
|
2167
|
-
edgeCache
|
|
2168
|
-
});
|
|
2211
|
+
const response = await api.gregorovich.documents.list();
|
|
2169
2212
|
return response.data;
|
|
2170
2213
|
},
|
|
2171
2214
|
params
|
|
@@ -2272,6 +2315,7 @@ function createWishlistActions(api, config = {}) {
|
|
|
2272
2315
|
const response = await api.items.itemWishlist.hdr.create(
|
|
2273
2316
|
userId,
|
|
2274
2317
|
wishlistId,
|
|
2318
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2275
2319
|
items
|
|
2276
2320
|
);
|
|
2277
2321
|
return response.data;
|