@ehrenkind/shopify-lib 0.2.0 → 0.2.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 CHANGED
@@ -34,7 +34,9 @@ __export(index_exports, {
34
34
  getLeanProductVariants: () => getLeanProductVariants,
35
35
  getOrderById: () => getOrderById,
36
36
  getOrderByName: () => getOrderByName,
37
- getOrderPaymentDetailsById: () => getOrderPaymentDetailsById
37
+ getOrderPaymentDetailsById: () => getOrderPaymentDetailsById,
38
+ parseGid: () => parseGid,
39
+ toRestFormat: () => toRestFormat
38
40
  });
39
41
  module.exports = __toCommonJS(index_exports);
40
42
 
@@ -341,12 +343,9 @@ var queryOrderByIdFull = gql`#graphql
341
343
  }
342
344
  customer {
343
345
  id
344
- lastName
345
- defaultEmailAddress {
346
- emailAddress
347
- }
348
- displayName
349
346
  firstName
347
+ lastName
348
+ email
350
349
  phone
351
350
  }
352
351
  displayFinancialStatus
@@ -493,10 +492,11 @@ var GetLeanOrderByIdReturn = import_zod5.default.object({
493
492
  shippingAddress: AddressSchema
494
493
  }).nullable();
495
494
  async function getOrderById(id, detailLevel = "lean") {
495
+ const bigIntId = typeof id === "number" ? BigInt(id) : id;
496
496
  if (detailLevel === "lean") {
497
- return getLeanOrderById(id);
497
+ return getLeanOrderById(bigIntId);
498
498
  }
499
- return getFullOrderById(id);
499
+ return getFullOrderById(bigIntId);
500
500
  }
501
501
  async function getLeanOrderById(id) {
502
502
  const variables = {
@@ -1137,12 +1137,56 @@ async function getOrderPaymentDetailsById(id) {
1137
1137
  }
1138
1138
  return await returnOutputParsed(response, GetOrderPaymentDetailsByIdReturn);
1139
1139
  }
1140
+
1141
+ // src/utils/toRestFormat.ts
1142
+ function camelToSnake(str) {
1143
+ return str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
1144
+ }
1145
+ function extractNumericId(gid) {
1146
+ const match = gid.match(/\d+$/);
1147
+ return match ? parseInt(match[0], 10) : 0;
1148
+ }
1149
+ function toRestFormat(obj) {
1150
+ if (obj === null || obj === void 0) {
1151
+ return obj;
1152
+ }
1153
+ if (Array.isArray(obj)) {
1154
+ return obj.map(toRestFormat);
1155
+ }
1156
+ if (typeof obj === "object") {
1157
+ const record = obj;
1158
+ const result = {};
1159
+ for (const [key, value] of Object.entries(record)) {
1160
+ if (key === "edges" && Array.isArray(value) && value.every(
1161
+ (item) => typeof item === "object" && item !== null && "node" in item
1162
+ )) {
1163
+ return value.map((edge) => toRestFormat(edge.node));
1164
+ }
1165
+ if (key === "id" && typeof value === "string" && value.startsWith("gid://")) {
1166
+ result[key] = extractNumericId(value);
1167
+ continue;
1168
+ }
1169
+ const snakeKey = camelToSnake(key);
1170
+ result[snakeKey] = toRestFormat(value);
1171
+ }
1172
+ return result;
1173
+ }
1174
+ return obj;
1175
+ }
1176
+
1177
+ // src/utils/parseGid.ts
1178
+ function parseGid(gid) {
1179
+ const match = gid.match(/\d+$/);
1180
+ return match ? parseInt(match[0], 10) : 0;
1181
+ }
1140
1182
  // Annotate the CommonJS export names for ESM import in node:
1141
1183
  0 && (module.exports = {
1142
1184
  deleteCustomerById,
1143
1185
  getLeanProductVariants,
1144
1186
  getOrderById,
1145
1187
  getOrderByName,
1146
- getOrderPaymentDetailsById
1188
+ getOrderPaymentDetailsById,
1189
+ parseGid,
1190
+ toRestFormat
1147
1191
  });
1148
1192
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/mutations/customers/deleteCustomerById.ts","../src/utils/logger.ts","../src/utils/shopifyClient.ts","../src/utils/shopifyFetch.ts","../src/utils/zod.ts","../src/queries/orders/getOrderById.ts","../src/queries/orders/getOrderById.queries.ts","../src/queries/orders/getOrderByName.ts","../src/queries/orders/getOrderByName.queries.ts","../src/queries/productVariants/getLeanProductVariants.ts","../src/queries/orders/getOrderPaymentDetails.ts","../src/queries/orders/getOrderPaymentDetails.queries.ts"],"sourcesContent":["export { deleteCustomerById } from './mutations/customers/deleteCustomerById.js'\nexport {\n getOrderById,\n type FullOrder,\n type LeanOrder,\n} from './queries/orders/getOrderById.js'\nexport { getOrderByName } from './queries/orders/getOrderByName.js'\nexport { getLeanProductVariants } from './queries/productVariants/getLeanProductVariants.js'\nexport { getOrderPaymentDetailsById } from './queries/orders/getOrderPaymentDetails.js'\n","import z from 'zod'\nimport type {\n CustomerDeleteMutation,\n CustomerDeleteMutationVariables,\n} from '../../generated-api-types/2025-04/admin.generated'\nimport { gql } from '../../utils/logger'\nimport { fetchShopifyGraphql } from '../../utils/shopifyFetch'\nimport { returnOutputParsed } from '../../utils/zod'\n\nexport const DeleteCustomerByIdReturn = z.string().nullable()\n\ntype SingleNode = { deletedCustomerId: string | null }\n\nexport async function deleteCustomerById(\n customerId: string,\n): Promise<z.infer<typeof DeleteCustomerByIdReturn>> {\n const mutation = gql`#graphql\n mutation customerDelete($input: CustomerDeleteInput!) {\n customerDelete(input: $input) {\n deletedCustomerId\n userErrors {\n field\n message\n }\n }\n }\n `\n\n const variables: CustomerDeleteMutationVariables = {\n input: { id: customerId },\n }\n\n const response = await fetchShopifyGraphql<\n SingleNode,\n CustomerDeleteMutation\n >({\n query: mutation,\n variables,\n dataExtractor: (data: CustomerDeleteMutation) => {\n if (!data.customerDelete) {\n throw new Error(\"GraphQL response missing 'customerDelete' field\")\n }\n return {\n nodes: [\n { deletedCustomerId: data.customerDelete.deletedCustomerId ?? null },\n ],\n userErrors: data.customerDelete.userErrors,\n }\n },\n })\n\n return returnOutputParsed(\n response[0]?.deletedCustomerId ?? null,\n DeleteCustomerByIdReturn,\n )\n}\n","const { env } = process\n\nexport const gql = String.raw\n\nconst logLevels = {\n silent: 0,\n error: 1,\n warn: 2,\n info: 3,\n debug: 4,\n} as const\n\ntype LogLevelName = keyof typeof logLevels\n\nfunction getLogLevel(\n nodeEnv: string | undefined,\n logLevelEnv: string | undefined,\n): LogLevelName {\n if (logLevelEnv && logLevelEnv in logLevels) {\n return logLevelEnv as LogLevelName\n }\n\n if (nodeEnv === 'test') {\n return 'silent'\n }\n\n if (nodeEnv === 'production') {\n return 'info'\n }\n return 'debug'\n}\n\nexport const activeLogLevelName = getLogLevel(env.NODE_ENV, env.LOG_LEVEL)\nconst activeLogLevelValue = logLevels[activeLogLevelName]\n\nexport const logger = {\n debug: (...args: unknown[]) => {\n if (logLevels.debug <= activeLogLevelValue) {\n // biome-ignore lint/suspicious/noConsole: <explanation>\n console.debug(...args)\n }\n },\n info: (...args: unknown[]) => {\n if (logLevels.info <= activeLogLevelValue) {\n // biome-ignore lint/suspicious/noConsole: <explanation>\n console.info(...args)\n }\n },\n warn: (...args: unknown[]) => {\n if (logLevels.warn <= activeLogLevelValue) {\n // biome-ignore lint/suspicious/noConsole: <explanation>\n console.warn(...args)\n }\n },\n error: (...args: unknown[]) => {\n if (logLevels.error <= activeLogLevelValue) {\n // biome-ignore lint/suspicious/noConsole: <explanation>\n console.error(...args)\n }\n },\n}\n","import {\n ApiVersion,\n type GraphqlClient,\n LogSeverity,\n Session,\n shopifyApi,\n} from '@shopify/shopify-api'\nimport '@shopify/shopify-api/adapters/node'\nimport dotenv from 'dotenv'\nimport { z } from 'zod'\nimport { activeLogLevelName, logger } from './logger.js'\n\n// https://shopify.dev/docs/api/admin-graphql/2025-04/\nexport const SHOPIFY_API_VERSION = ApiVersion.April25\n\ndotenv.config()\n\nconst envSchema = z.object({\n SHOPIFY_API_KEY: z.string({\n required_error: 'SHOPIFY_API_KEY is required',\n }),\n SHOPIFY_API_SECRET: z.string({\n required_error: 'SHOPIFY_API_SECRET is required',\n }),\n SHOPIFY_API_HOSTNAME: z.string({\n required_error: 'SHOPIFY_API_HOSTNAME is required',\n }),\n SHOPIFY_ACCESS_TOKEN: z.string({\n required_error: 'SHOPIFY_ACCESS_TOKEN is required',\n }),\n NODE_ENV: z\n .enum(['development', 'production', 'test'])\n .default('development'),\n})\n\nconst mapLogLevelToShopifySeverity = (level: string): LogSeverity => {\n switch (level) {\n case 'silent':\n return LogSeverity.Error\n case 'debug':\n return LogSeverity.Debug\n case 'info':\n return LogSeverity.Info\n case 'warn':\n return LogSeverity.Warning\n case 'error':\n return LogSeverity.Error\n default:\n return LogSeverity.Info\n }\n}\n\nlet shopifyGraphqlClient: GraphqlClient\n\ntry {\n // biome-ignore lint/nursery/noProcessEnv: <explanation>\n const env = envSchema.parse(process.env)\n\n const shopify = shopifyApi({\n apiKey: env.SHOPIFY_API_KEY,\n apiSecretKey: env.SHOPIFY_API_SECRET,\n hostName: env.SHOPIFY_API_HOSTNAME,\n apiVersion: SHOPIFY_API_VERSION,\n isEmbeddedApp: false,\n logger: { level: mapLogLevelToShopifySeverity(activeLogLevelName) },\n future: {\n customerAddressDefaultFix: true,\n lineItemBilling: true,\n unstable_managedPricingSupport: false,\n },\n })\n\n const shopifySession = new Session({\n id: `custom-session-${env.SHOPIFY_API_HOSTNAME}`,\n shop: env.SHOPIFY_API_HOSTNAME,\n state: 'authenticated',\n isOnline: true,\n accessToken: env.SHOPIFY_ACCESS_TOKEN,\n })\n\n shopifyGraphqlClient = new shopify.clients.Graphql({\n session: shopifySession,\n })\n\n logger.info('Shopify API client initialized successfully.')\n} catch (error) {\n if (error instanceof z.ZodError) {\n const msg = JSON.stringify(error.format(), null, 2)\n logger.error(msg)\n } else {\n logger.error('Failed to initialize Shopify API client:', error)\n }\n throw error\n}\n\nexport { shopifyGraphqlClient as shopifyClient }\n","import { logger } from './logger.js'\nimport { shopifyClient } from './shopifyClient.js'\n\nexport function convertIdIntoGid(\n id: bigint,\n type: 'Order' | 'Customer',\n): string {\n return `gid://shopify/${type}/${id}`\n}\n\ninterface PageInfo {\n hasNextPage: boolean\n endCursor?: string | null | undefined\n}\n\ninterface ShopifyErrorWithMessage {\n message?: string\n [key: string]: unknown\n}\n\ntype TExtractorFunctionType<TResultNode, TPageData> = (pageData: TPageData) => {\n nodes: TResultNode[]\n pageInfo?: PageInfo\n userErrors?: { message?: string }[]\n}\n\nexport async function fetchShopifyGraphql<TResultNode, TPageData>(params: {\n query: string\n variables: Record<string, unknown>\n dataExtractor?: TExtractorFunctionType<TResultNode, TPageData>\n fetchAllPages?: boolean\n}): Promise<TResultNode[]>\nexport async function fetchShopifyGraphql<TReturnType>(params: {\n query: string\n variables: Record<string, unknown>\n}): Promise<TReturnType>\nexport async function fetchShopifyGraphql<\n TResultNode,\n TPageData,\n TReturnType,\n>(params: {\n query: string\n variables: Record<string, unknown>\n dataExtractor?: TExtractorFunctionType<TResultNode, TPageData>\n fetchAllPages?: boolean\n}): Promise<TResultNode[] | TReturnType> {\n const {\n query,\n variables: initialVariables,\n dataExtractor,\n fetchAllPages = false,\n } = params\n\n let currentVariables = { ...initialVariables }\n\n if (!dataExtractor) {\n return makeRequest<NonNullable<TReturnType>>(query, currentVariables)\n }\n\n const allNodes: TResultNode[] = []\n let hasNextLoop = true\n\n do {\n const response = await makeRequest<TPageData>(query, currentVariables)\n const { nodes, pageInfo, userErrors } = dataExtractor(response)\n\n // Handle Shopify mutation userErrors pattern\n if (Array.isArray(userErrors) && userErrors.length > 0) {\n const errorMessages = userErrors\n .map((e) => e.message || JSON.stringify(e))\n .join('\\n')\n logger.error('Shopify mutation userErrors:', errorMessages)\n throw new Error(`Shopify mutation userErrors: ${errorMessages}`)\n }\n\n allNodes.push(...nodes)\n\n hasNextLoop = fetchAllPages ? !!pageInfo?.hasNextPage : false\n if (hasNextLoop && pageInfo?.endCursor) {\n currentVariables = {\n ...currentVariables,\n after: pageInfo.endCursor,\n }\n }\n } while (hasNextLoop)\n\n return allNodes\n}\n\nasync function makeRequest<TReturnDataType>(\n query: string,\n variables: Record<string, unknown>,\n): Promise<NonNullable<TReturnDataType>> {\n type ShopifyRequestErrorType = {\n errors?: ShopifyErrorWithMessage | ShopifyErrorWithMessage[]\n }\n\n const response = (await shopifyClient.request<TReturnDataType>(query, {\n variables,\n })) as { data?: TReturnDataType } & ShopifyRequestErrorType\n\n if (response.errors) {\n let errorMessages = 'GraphQL query failed.'\n const errors = response.errors\n if (Array.isArray(errors)) {\n errorMessages = errors\n .map((e: ShopifyErrorWithMessage) => e.message || JSON.stringify(e))\n .join('\\n')\n } else if (\n typeof errors === 'object' &&\n errors !== null &&\n 'message' in errors\n ) {\n errorMessages = errors.message || JSON.stringify(errors)\n } else if (typeof errors === 'string') {\n errorMessages = errors\n } else {\n errorMessages = JSON.stringify(errors)\n }\n logger.error('GraphQL query failed:', errorMessages)\n throw new Error(`GraphQL errors: ${errorMessages}`)\n }\n\n if (!response.data) {\n throw new Error('No data in Shopify API response')\n }\n\n return response.data\n}\n","import z from 'zod'\nimport { logger } from './logger.js'\n\nexport async function returnOutputParsed<T>(\n data: unknown,\n Model: z.ZodType<T>,\n) {\n const parsed = await Model.safeParseAsync(data)\n if (!parsed.success) {\n if (parsed.error instanceof z.ZodError) {\n const msg = JSON.stringify(parsed.error.format(), null, 2)\n logger.error(msg)\n } else {\n logger.error('Failed to parse:', parsed.error)\n }\n // throw parsedVariants.error\n throw new Error('Failed to parse product variants')\n }\n logger.info('Parsed data successfully')\n return parsed.data\n}\n","import z from 'zod'\nimport type {\n OrderByIdFullQuery,\n OrderByIdQuery,\n OrderByIdQueryVariables,\n} from '../../generated-api-types/2025-04/admin.generated.js'\nimport { logger } from '../../utils/logger.js'\nimport {\n convertIdIntoGid,\n fetchShopifyGraphql,\n} from '../../utils/shopifyFetch.js'\nimport { returnOutputParsed } from '../../utils/zod.js'\nimport { queryOrderById, queryOrderByIdFull } from './getOrderById.queries.js'\n\n// Address schema (shared between lean and full)\nconst AddressSchema = z\n .object({\n firstName: z.string().nullable(),\n lastName: z.string().nullable(),\n address1: z.string().nullable(),\n address2: z.string().nullable(),\n city: z.string().nullable(),\n province: z.string().nullable(),\n country: z.string().nullable(),\n zip: z.string().nullable(),\n })\n .nullable()\n\n// Lean order schema\nconst GetLeanOrderByIdReturn = z\n .object({\n id: z.string(),\n name: z.string(),\n createdAt: z.string(),\n updatedAt: z.string(),\n cancelledAt: z.string().nullable(),\n cancelReason: z.string().nullable(),\n totalPrice: z.object({\n amount: z.string(),\n currencyCode: z.string(),\n }),\n customer: z\n .object({\n id: z.string(),\n displayName: z.string(),\n firstName: z.string().nullable(),\n lastName: z.string().nullable(),\n emailAddress: z.string().nullable(),\n })\n .nullable(),\n financialStatus: z.string().nullable(),\n fulfillmentStatus: z.string().nullable(),\n shippingAddress: AddressSchema,\n })\n .nullable()\n\nexport type LeanOrder = z.infer<typeof GetLeanOrderByIdReturn>\n\n// Full order type - derived from the generated GraphQL types\nexport type FullOrder = NonNullable<OrderByIdFullQuery['order']> | null\n\ntype OrderDetailLevel = 'lean' | 'full'\n\n// Function overloads\nexport function getOrderById(id: bigint): Promise<LeanOrder>\nexport function getOrderById(id: bigint, detailLevel: 'lean'): Promise<LeanOrder>\nexport function getOrderById(id: bigint, detailLevel: 'full'): Promise<FullOrder>\n\n/**\n * Retrieves a single order from Shopify by its numeric ID.\n * Returns null if no order is found with the specified ID.\n *\n * @param {bigint} id - The numerical Shopify order ID (e.g., 12345678n).\n * @param {OrderDetailLevel} detailLevel - The level of detail to return ('lean' or 'full'). Defaults to 'lean'.\n * @returns {Promise<LeanOrder | FullOrder>} A promise that resolves to the order data or null if not found.\n * @throws {Error} If the GraphQL query fails or if the response structure is invalid.\n */\nexport async function getOrderById(\n id: bigint,\n detailLevel: OrderDetailLevel = 'lean',\n): Promise<LeanOrder | FullOrder> {\n if (detailLevel === 'lean') {\n return getLeanOrderById(id)\n }\n return getFullOrderById(id)\n}\n\nasync function getLeanOrderById(id: bigint): Promise<LeanOrder> {\n const variables: OrderByIdQueryVariables = {\n id: convertIdIntoGid(id, 'Order'),\n }\n\n const response = await fetchShopifyGraphql<OrderByIdQuery>({\n query: queryOrderById,\n variables,\n })\n\n if (!response.order) {\n logger.debug(`No order found with ID: ${id}`)\n return null\n }\n\n const order = response.order\n\n const leanOrder = {\n id: order.id,\n name: order.name,\n createdAt: order.createdAt,\n updatedAt: order.updatedAt,\n cancelledAt: order.cancelledAt ?? null,\n cancelReason: order.cancelReason ?? null,\n totalPrice: {\n amount: order.totalPriceSet?.shopMoney?.amount ?? '',\n currencyCode: order.totalPriceSet?.shopMoney?.currencyCode ?? '',\n },\n customer: order.customer\n ? {\n id: order.customer.id,\n displayName: order.customer.displayName,\n firstName: order.customer.firstName ?? null,\n lastName: order.customer.lastName ?? null,\n emailAddress:\n order.customer.defaultEmailAddress?.emailAddress ?? null,\n }\n : null,\n financialStatus: order.displayFinancialStatus ?? null,\n fulfillmentStatus: order.displayFulfillmentStatus ?? null,\n shippingAddress: order.shippingAddress\n ? {\n firstName: order.shippingAddress.firstName ?? null,\n lastName: order.shippingAddress.lastName ?? null,\n address1: order.shippingAddress.address1 ?? null,\n address2: order.shippingAddress.address2 ?? null,\n city: order.shippingAddress.city ?? null,\n province: order.shippingAddress.province ?? null,\n country: order.shippingAddress.country ?? null,\n zip: order.shippingAddress.zip ?? null,\n }\n : null,\n }\n\n return await returnOutputParsed(leanOrder, GetLeanOrderByIdReturn)\n}\n\nasync function getFullOrderById(id: bigint): Promise<FullOrder> {\n const variables: OrderByIdQueryVariables = {\n id: convertIdIntoGid(id, 'Order'),\n }\n\n const response = await fetchShopifyGraphql<OrderByIdFullQuery>({\n query: queryOrderByIdFull,\n variables,\n })\n\n if (!response.order) {\n logger.debug(`No order found with ID: ${id}`)\n return null\n }\n\n return response.order\n}\n","import { gql } from '../../utils/logger'\n\nexport const queryOrderById = gql`#graphql\n query orderById($id: ID!) {\n order(id: $id) {\n id\n name\n createdAt\n updatedAt\n cancelledAt\n cancelReason\n totalPriceSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n customer {\n id\n lastName\n defaultEmailAddress {\n emailAddress\n }\n displayName\n firstName\n }\n displayFinancialStatus\n displayFulfillmentStatus\n shippingAddress {\n firstName\n lastName\n address1\n address2\n city\n province\n country\n zip\n }\n }\n }\n`\n\nexport const queryOrderByIdFull = gql`#graphql\n query orderByIdFull($id: ID!) {\n order(id: $id) {\n id\n name\n createdAt\n updatedAt\n processedAt\n closedAt\n cancelledAt\n cancelReason\n totalPriceSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n customer {\n id\n lastName\n defaultEmailAddress {\n emailAddress\n }\n displayName\n firstName\n phone\n }\n displayFinancialStatus\n displayFulfillmentStatus\n shippingAddress {\n firstName\n lastName\n address1\n address2\n city\n province\n country\n zip\n }\n billingAddress {\n firstName\n lastName\n address1\n address2\n city\n province\n country\n zip\n }\n lineItems(first: 100) {\n edges {\n node {\n id\n sku\n title\n variantTitle\n quantity\n customAttributes {\n key\n value\n }\n originalUnitPriceSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n vendor\n image {\n url\n width\n height\n altText\n }\n }\n }\n }\n fulfillments {\n id\n name\n totalQuantity\n status\n createdAt\n estimatedDeliveryAt\n deliveredAt\n trackingInfo {\n company\n number\n url\n }\n fulfillmentLineItems(first: 100) {\n edges {\n node {\n id\n quantity\n lineItem {\n id\n }\n }\n }\n }\n }\n shippingLine {\n originalPriceSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n }\n taxLines {\n priceSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n }\n totalDiscountsSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n discountCodes\n refunds {\n totalRefundedSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n }\n }\n }\n`\n","import z from 'zod'\nimport type {\n OrdersByNameFullQuery,\n OrdersByNameQuery,\n OrdersByNameQueryVariables,\n} from '../../generated-api-types/2025-04/admin.generated.js'\nimport { logger } from '../../utils/logger.js'\nimport { fetchShopifyGraphql } from '../../utils/shopifyFetch.js'\nimport { returnOutputParsed } from '../../utils/zod.js'\nimport {\n queryOrdersByName,\n queryOrdersByNameFull,\n} from './getOrderByName.queries.js'\n\nconst GetLeanOrderByNameReturn = z\n .object({\n id: z.string(),\n name: z.string(),\n createdAt: z.string(),\n updatedAt: z.string(),\n totalPrice: z.object({\n amount: z.string(),\n currencyCode: z.string(),\n }),\n customer: z\n .object({\n id: z.string(),\n displayName: z.string(),\n emailAddress: z.string().nullable(),\n })\n .nullable(),\n financialStatus: z.string().nullable(),\n fulfillmentStatus: z.string().nullable(),\n })\n .nullable()\n\ntype GetLeanOrderByNameReturnType = z.infer<typeof GetLeanOrderByNameReturn>\n\ntype GetFullOrderByNameReturnType = NonNullable<\n NonNullable<OrdersByNameFullQuery['orders']>['edges'][number]['node']\n> | null\n\ntype OrderDetailLevel = 'lean' | 'full'\n\n// Function overloads\nexport function getOrderByName(\n orderName: string,\n detailLevel: 'lean',\n): Promise<GetLeanOrderByNameReturnType>\nexport function getOrderByName(\n orderName: string,\n detailLevel: 'full',\n): Promise<GetFullOrderByNameReturnType>\nexport function getOrderByName(\n orderName: string,\n): Promise<GetLeanOrderByNameReturnType>\n\n/**\n * Retrieves a single order from Shopify by its order name (e.g., \"B12345\").\n * Returns null if no order is found with the specified name.\n *\n * @param {string} orderName - The order name to search for (e.g., \"B12345\").\n * @param {OrderDetailLevel} detailLevel - The level of detail to return ('lean' or 'full'). Defaults to 'lean'.\n * @returns {Promise<GetLeanOrderByNameReturnType | GetFullOrderByNameReturnType>} A promise that resolves to the order data or null if not found.\n * @throws {Error} If the GraphQL query fails or if the response structure is invalid.\n */\nexport async function getOrderByName(\n orderName: string,\n detailLevel: OrderDetailLevel = 'lean',\n): Promise<GetLeanOrderByNameReturnType | GetFullOrderByNameReturnType> {\n if (detailLevel === 'lean') {\n return getLeanOrderByName(orderName)\n }\n return getFullOrderByName(orderName)\n}\n\nasync function getLeanOrderByName(\n orderName: string,\n): Promise<GetLeanOrderByNameReturnType> {\n const variables: OrdersByNameQueryVariables = {\n first: 1,\n queryFilter: `name:${orderName}`,\n }\n\n type SingleNode = NonNullable<\n NonNullable<OrdersByNameQuery['orders']>['edges'][number]['node']\n >\n\n const extractedNodes = await fetchShopifyGraphql<\n SingleNode,\n OrdersByNameQuery\n >({\n query: queryOrdersByName,\n variables,\n dataExtractor: (pageData: OrdersByNameQuery) => {\n if (!pageData.orders) {\n throw new Error(\n \"GraphQL response for orders is missing the 'orders' field.\",\n )\n }\n const nodes: SingleNode[] = pageData.orders.edges.map(\n (edge: { node: SingleNode }) => edge.node,\n )\n return {\n nodes,\n }\n },\n fetchAllPages: false,\n })\n\n const order = extractedNodes[0]\n if (!order) {\n logger.debug(`No order found with name: ${orderName}`)\n return null\n }\n\n const leanOrder = {\n id: order.id,\n name: order.name,\n createdAt: order.createdAt,\n updatedAt: order.updatedAt,\n totalPrice: {\n amount: order.totalPriceSet?.shopMoney?.amount ?? '',\n currencyCode: order.totalPriceSet?.shopMoney?.currencyCode ?? '',\n },\n customer: order.customer\n ? {\n id: order.customer.id,\n displayName: order.customer.displayName,\n emailAddress:\n order.customer.defaultEmailAddress?.emailAddress ?? null,\n }\n : null,\n financialStatus: order.displayFinancialStatus ?? null,\n fulfillmentStatus: order.displayFulfillmentStatus ?? null,\n }\n\n return await returnOutputParsed(leanOrder, GetLeanOrderByNameReturn)\n}\n\nasync function getFullOrderByName(\n orderName: string,\n): Promise<GetFullOrderByNameReturnType> {\n const variables: OrdersByNameQueryVariables = {\n first: 1,\n queryFilter: `name:${orderName}`,\n }\n\n type SingleNode = NonNullable<\n NonNullable<OrdersByNameFullQuery['orders']>['edges'][number]['node']\n >\n\n const extractedNodes = await fetchShopifyGraphql<\n SingleNode,\n OrdersByNameFullQuery\n >({\n query: queryOrdersByNameFull,\n variables,\n dataExtractor: (pageData: OrdersByNameFullQuery) => {\n if (!pageData.orders) {\n throw new Error(\n \"GraphQL response for orders is missing the 'orders' field.\",\n )\n }\n const nodes: SingleNode[] = pageData.orders.edges.map(\n (edge: { node: SingleNode }) => edge.node,\n )\n return {\n nodes,\n }\n },\n fetchAllPages: false,\n })\n\n if (extractedNodes.length === 0) {\n logger.debug(`No order found with name: ${orderName}`)\n return null\n }\n\n const order = extractedNodes[0]\n if (!order) {\n logger.debug(`No order found with name: ${orderName}`)\n return null\n }\n\n return order\n}\n","import { gql } from '../../utils/logger'\n\nexport const queryOrdersByName = gql`#graphql\n query ordersByName($first: Int!, $queryFilter: String!) {\n orders(first: $first, query: $queryFilter) {\n edges {\n node {\n id\n name\n createdAt\n updatedAt\n totalPriceSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n customer {\n id\n lastName\n defaultEmailAddress {\n emailAddress\n }\n displayName\n firstName\n }\n displayFinancialStatus\n displayFulfillmentStatus\n }\n }\n pageInfo {\n hasNextPage\n endCursor\n }\n }\n }\n`\n\nexport const queryOrdersByNameFull = gql`#graphql\n query ordersByNameFull($first: Int!, $queryFilter: String!) {\n orders(first: $first, query: $queryFilter) {\n edges {\n node {\n billingAddress {\n address1\n address2\n city\n company\n country\n countryCodeV2\n firstName\n formattedArea\n id\n lastName\n name\n phone\n province\n provinceCode\n timeZone\n zip\n }\n billingAddressMatchesShippingAddress\n cancelReason\n cancellation {\n staffNote\n }\n cancelledAt\n capturable\n clientIp\n closed\n closedAt\n confirmed\n createdAt\n currencyCode\n currentCartDiscountAmountSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n currentShippingPriceSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n currentSubtotalLineItemsQuantity\n currentSubtotalPriceSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n currentTaxLines {\n channelLiable\n rate\n ratePercentage\n source\n title\n priceSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n }\n currentTotalAdditionalFeesSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n currentTotalDiscountsSet {\n presentmentMoney {\n amount\n currencyCode\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n currentTotalDutiesSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n currentTotalPriceSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n currentTotalTaxSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n currentTotalWeight\n customer {\n id\n lastName\n defaultEmailAddress {\n emailAddress\n }\n displayName\n firstName\n }\n customerAcceptsMarketing\n discountCodes\n discountCode\n displayAddress {\n address1\n address2\n city\n company\n country\n countryCodeV2\n firstName\n formattedArea\n id\n lastName\n name\n phone\n province\n provinceCode\n timeZone\n zip\n }\n displayFinancialStatus\n displayFulfillmentStatus\n dutiesIncluded\n edited\n email\n estimatedTaxes\n fulfillable\n fulfillments(first: 20) {\n createdAt\n deliveredAt\n displayStatus\n estimatedDeliveryAt\n updatedAt\n trackingInfo(first: 10) {\n company\n url\n }\n totalQuantity\n status\n name\n id\n }\n fullyPaid\n id\n lineItems(first: 50) {\n edges {\n node {\n id\n name\n originalUnitPriceSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n quantity\n requiresShipping\n sku\n title\n variantTitle\n }\n }\n }\n name\n note\n processedAt\n shippingAddress {\n address1\n address2\n city\n company\n country\n countryCodeV2\n firstName\n formattedArea\n id\n lastName\n name\n phone\n province\n provinceCode\n timeZone\n zip\n }\n statusPageUrl\n tags\n totalPriceSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n totalReceivedSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n totalRefundedSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n totalShippingPriceSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n totalTaxSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n totalWeight\n unpaid\n updatedAt\n }\n }\n pageInfo {\n hasNextPage\n endCursor\n }\n }\n }\n`\n","import z from 'zod'\nimport type {\n LeanProductVariantsQuery,\n LeanProductVariantsQueryVariables,\n} from '../../generated-api-types/2025-04/admin.generated.js'\nimport { gql, logger } from '../../utils/logger.js'\nimport { fetchShopifyGraphql } from '../../utils/shopifyFetch.js'\nimport { returnOutputParsed } from '../../utils/zod.js'\n\nconst GetLeanProductVariantsReturn = z.array(\n z.object({\n productId: z.string(),\n productTitle: z.string(),\n variantId: z.string(),\n variantTitle: z.string(),\n sku: z.string(),\n }),\n)\n\ntype GetLeanProductVariantsReturnType = z.infer<\n typeof GetLeanProductVariantsReturn\n>\n\n/**\n * Retrieves a lean list of product variants from Shopify, optionally filtered by SKUs.\n * Product variants are mapped to a simpler output structure.\n * Variants missing essential properties (e.g., SKU) will be filtered out and logged.\n *\n * @param {string[]} [skus] - An optional array of SKUs to filter by. If provided, only variants matching these SKUs will be fetched.\n * @returns {Promise<GetLeanProductVariantsReturnType>} A promise that resolves to an array of lean product variant data.\n * @throws {Error} If the GraphQL query fails, returns no data, or if the `productVariants` field is missing in the response.\n */\nexport async function getLeanProductVariants(\n skus?: string[],\n): Promise<GetLeanProductVariantsReturnType> {\n const queryGql = gql`#graphql\n query leanProductVariants($first: Int!, $after: String, $queryFilter: String) {\n productVariants(first: $first, after: $after, query: $queryFilter) {\n edges {\n node { \n id\n title\n sku\n product {\n id\n title\n }\n }\n }\n pageInfo { \n hasNextPage\n endCursor\n }\n }\n }\n `\n\n const initialVariables: LeanProductVariantsQueryVariables = { first: 250 }\n if (skus && skus.length > 0) {\n initialVariables.queryFilter = skus\n .map((sku: string) => `sku:${sku}`)\n .join(' OR ')\n }\n\n // Type for a single node from the productVariants query\n type SingleNode = NonNullable<\n NonNullable<\n LeanProductVariantsQuery['productVariants']\n >['edges'][number]['node']\n >\n\n const extractedNodes = await fetchShopifyGraphql<\n SingleNode,\n LeanProductVariantsQuery\n >({\n query: queryGql,\n variables: initialVariables,\n dataExtractor: (pageData: LeanProductVariantsQuery) => {\n if (!pageData.productVariants) {\n throw new Error(\n \"GraphQL response for product variants is missing the 'productVariants' field.\",\n )\n }\n const nodes: SingleNode[] = pageData.productVariants.edges.map(\n (edge: { node: SingleNode }) => edge.node,\n )\n return {\n nodes,\n pageInfo: pageData.productVariants.pageInfo,\n }\n },\n fetchAllPages: true,\n })\n\n const allVariants = extractedNodes.flatMap<\n GetLeanProductVariantsReturnType[number]\n >((v) => {\n if (v.sku) {\n return [\n {\n productId: v.product.id,\n productTitle: v.product.title,\n variantId: v.id,\n variantTitle: v.title,\n sku: v.sku,\n },\n ]\n }\n logger.debug(\n `Product ${v.product.title} (ID: ${v.product.id}) has a variant (ID: ${v.id}) with no SKU. Filtering out.`,\n )\n return []\n })\n\n return await returnOutputParsed(allVariants, GetLeanProductVariantsReturn)\n}\n","import z from 'zod'\nimport type {\n OrderPaymentDetailsByIdQuery,\n OrderPaymentDetailsByIdQueryVariables,\n} from '../../generated-api-types/2025-04/admin.generated.js'\nimport { logger } from '../../utils/logger.js'\nimport {\n convertIdIntoGid,\n fetchShopifyGraphql,\n} from '../../utils/shopifyFetch.js'\nimport { returnOutputParsed } from '../../utils/zod.js'\nimport { queryOrderPaymentDetails } from './getOrderPaymentDetails.queries.js'\n\nconst GetOrderPaymentDetailsByIdReturn = z.object({\n order: z.object({\n transactions: z.array(\n z.object({\n amountSet: z.object({\n shopMoney: z.object({\n amount: z.string(),\n currencyCode: z.string(),\n }),\n }),\n createdAt: z.string(),\n gateway: z.string(),\n formattedGateway: z.string(),\n kind: z.string(),\n paymentId: z.string(),\n }),\n ),\n }),\n})\n\ntype GetOrderPaymentDetailsByIdReturnType = z.infer<\n typeof GetOrderPaymentDetailsByIdReturn\n>\n\n/**\n * Retrieves payment details for a single order from Shopify by its ID.\n * Returns null if no order is found with the specified ID.\n *\n * @param {bigint} id - The numerical Shopify order ID (e.g., 12345678n).\n * @returns {Promise<GetOrderPaymentDetailsByIdReturnType | null>} A promise that resolves to the order payment data or null if not found.\n * @throws {Error} If the GraphQL query fails or if the response structure is invalid.\n */\nexport async function getOrderPaymentDetailsById(\n id: bigint,\n): Promise<GetOrderPaymentDetailsByIdReturnType | null> {\n const variables: OrderPaymentDetailsByIdQueryVariables = {\n id: convertIdIntoGid(id, 'Order'),\n }\n\n const response = await fetchShopifyGraphql<OrderPaymentDetailsByIdQuery>({\n query: queryOrderPaymentDetails,\n variables,\n })\n\n if (!response.order) {\n logger.debug(`No order found with ID: ${id}`)\n return null\n }\n\n return await returnOutputParsed(response, GetOrderPaymentDetailsByIdReturn)\n}\n","import { gql } from '../../utils/logger.js'\n\nexport const queryOrderPaymentDetails = gql`#graphql\n query orderPaymentDetailsById($id: ID!) {\n order(id: $id) {\n transactions {\n amountSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n createdAt\n gateway\n formattedGateway\n kind\n paymentId\n }\n }\n }\n`\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,cAAc;;;ACAd,IAAM,EAAE,IAAI,IAAI;AAET,IAAM,MAAM,OAAO;AAE1B,IAAM,YAAY;AAAA,EAChB,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AACT;AAIA,SAAS,YACP,SACA,aACc;AACd,MAAI,eAAe,eAAe,WAAW;AAC3C,WAAO;AAAA,EACT;AAEA,MAAI,YAAY,QAAQ;AACtB,WAAO;AAAA,EACT;AAEA,MAAI,YAAY,cAAc;AAC5B,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAEO,IAAM,qBAAqB,YAAY,IAAI,UAAU,IAAI,SAAS;AACzE,IAAM,sBAAsB,UAAU,kBAAkB;AAEjD,IAAM,SAAS;AAAA,EACpB,OAAO,IAAI,SAAoB;AAC7B,QAAI,UAAU,SAAS,qBAAqB;AAE1C,cAAQ,MAAM,GAAG,IAAI;AAAA,IACvB;AAAA,EACF;AAAA,EACA,MAAM,IAAI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AAC;AAAA,EACV,CAAC;AAED,SAAO,MAAM,mBAAmB,aAAa,4BAA4B;AAC3E;;;ACnHA,IAAAC,eAAc;;;ACEP,IAAM,2BAA2B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ADWxC,IAAM,mCAAmC,aAAAC,QAAE,OAAO;AAAA,EAChD,OAAO,aAAAA,QAAE,OAAO;AAAA,IACd,cAAc,aAAAA,QAAE;AAAA,MACd,aAAAA,QAAE,OAAO;AAAA,QACP,WAAW,aAAAA,QAAE,OAAO;AAAA,UAClB,WAAW,aAAAA,QAAE,OAAO;AAAA,YAClB,QAAQ,aAAAA,QAAE,OAAO;AAAA,YACjB,cAAc,aAAAA,QAAE,OAAO;AAAA,UACzB,CAAC;AAAA,QACH,CAAC;AAAA,QACD,WAAW,aAAAA,QAAE,OAAO;AAAA,QACpB,SAAS,aAAAA,QAAE,OAAO;AAAA,QAClB,kBAAkB,aAAAA,QAAE,OAAO;AAAA,QAC3B,MAAM,aAAAA,QAAE,OAAO;AAAA,QACf,WAAW,aAAAA,QAAE,OAAO;AAAA,MACtB,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AACH,CAAC;AAcD,eAAsB,2BACpB,IACsD;AACtD,QAAM,YAAmD;AAAA,IACvD,IAAI,iBAAiB,IAAI,OAAO;AAAA,EAClC;AAEA,QAAM,WAAW,MAAM,oBAAkD;AAAA,IACvE,OAAO;AAAA,IACP;AAAA,EACF,CAAC;AAED,MAAI,CAAC,SAAS,OAAO;AACnB,WAAO,MAAM,2BAA2B,EAAE,EAAE;AAC5C,WAAO;AAAA,EACT;AAEA,SAAO,MAAM,mBAAmB,UAAU,gCAAgC;AAC5E;","names":["import_zod","dotenv","env","import_zod","z","z","import_zod","z","import_zod","z","import_zod","z","import_zod","z"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/mutations/customers/deleteCustomerById.ts","../src/utils/logger.ts","../src/utils/shopifyClient.ts","../src/utils/shopifyFetch.ts","../src/utils/zod.ts","../src/queries/orders/getOrderById.ts","../src/queries/orders/getOrderById.queries.ts","../src/queries/orders/getOrderByName.ts","../src/queries/orders/getOrderByName.queries.ts","../src/queries/productVariants/getLeanProductVariants.ts","../src/queries/orders/getOrderPaymentDetails.ts","../src/queries/orders/getOrderPaymentDetails.queries.ts","../src/utils/toRestFormat.ts","../src/utils/parseGid.ts"],"sourcesContent":["export { deleteCustomerById } from './mutations/customers/deleteCustomerById.js'\nexport {\n getOrderById,\n type FullOrder,\n type LeanOrder,\n} from './queries/orders/getOrderById.js'\nexport {\n getOrderByName,\n type FullOrderByName,\n type LeanOrderByName,\n} from './queries/orders/getOrderByName.js'\nexport { getLeanProductVariants } from './queries/productVariants/getLeanProductVariants.js'\nexport { getOrderPaymentDetailsById } from './queries/orders/getOrderPaymentDetails.js'\nexport { toRestFormat } from './utils/toRestFormat.js'\nexport { parseGid } from './utils/parseGid.js'\n","import z from 'zod'\nimport type {\n CustomerDeleteMutation,\n CustomerDeleteMutationVariables,\n} from '../../generated-api-types/2025-04/admin.generated'\nimport { gql } from '../../utils/logger'\nimport { fetchShopifyGraphql } from '../../utils/shopifyFetch'\nimport { returnOutputParsed } from '../../utils/zod'\n\nexport const DeleteCustomerByIdReturn = z.string().nullable()\n\ntype SingleNode = { deletedCustomerId: string | null }\n\nexport async function deleteCustomerById(\n customerId: string,\n): Promise<z.infer<typeof DeleteCustomerByIdReturn>> {\n const mutation = gql`#graphql\n mutation customerDelete($input: CustomerDeleteInput!) {\n customerDelete(input: $input) {\n deletedCustomerId\n userErrors {\n field\n message\n }\n }\n }\n `\n\n const variables: CustomerDeleteMutationVariables = {\n input: { id: customerId },\n }\n\n const response = await fetchShopifyGraphql<\n SingleNode,\n CustomerDeleteMutation\n >({\n query: mutation,\n variables,\n dataExtractor: (data: CustomerDeleteMutation) => {\n if (!data.customerDelete) {\n throw new Error(\"GraphQL response missing 'customerDelete' field\")\n }\n return {\n nodes: [\n { deletedCustomerId: data.customerDelete.deletedCustomerId ?? null },\n ],\n userErrors: data.customerDelete.userErrors,\n }\n },\n })\n\n return returnOutputParsed(\n response[0]?.deletedCustomerId ?? null,\n DeleteCustomerByIdReturn,\n )\n}\n","const { env } = process\n\nexport const gql = String.raw\n\nconst logLevels = {\n silent: 0,\n error: 1,\n warn: 2,\n info: 3,\n debug: 4,\n} as const\n\ntype LogLevelName = keyof typeof logLevels\n\nfunction getLogLevel(\n nodeEnv: string | undefined,\n logLevelEnv: string | undefined,\n): LogLevelName {\n if (logLevelEnv && logLevelEnv in logLevels) {\n return logLevelEnv as LogLevelName\n }\n\n if (nodeEnv === 'test') {\n return 'silent'\n }\n\n if (nodeEnv === 'production') {\n return 'info'\n }\n return 'debug'\n}\n\nexport const activeLogLevelName = getLogLevel(env.NODE_ENV, env.LOG_LEVEL)\nconst activeLogLevelValue = logLevels[activeLogLevelName]\n\nexport const logger = {\n debug: (...args: unknown[]) => {\n if (logLevels.debug <= activeLogLevelValue) {\n // biome-ignore lint/suspicious/noConsole: <explanation>\n console.debug(...args)\n }\n },\n info: (...args: unknown[]) => {\n if (logLevels.info <= activeLogLevelValue) {\n // biome-ignore lint/suspicious/noConsole: <explanation>\n console.info(...args)\n }\n },\n warn: (...args: unknown[]) => {\n if (logLevels.warn <= activeLogLevelValue) {\n // biome-ignore lint/suspicious/noConsole: <explanation>\n console.warn(...args)\n }\n },\n error: (...args: unknown[]) => {\n if (logLevels.error <= activeLogLevelValue) {\n // biome-ignore lint/suspicious/noConsole: <explanation>\n console.error(...args)\n }\n },\n}\n","import {\n ApiVersion,\n type GraphqlClient,\n LogSeverity,\n Session,\n shopifyApi,\n} from '@shopify/shopify-api'\nimport '@shopify/shopify-api/adapters/node'\nimport dotenv from 'dotenv'\nimport { z } from 'zod'\nimport { activeLogLevelName, logger } from './logger.js'\n\n// https://shopify.dev/docs/api/admin-graphql/2025-04/\nexport const SHOPIFY_API_VERSION = ApiVersion.April25\n\ndotenv.config()\n\nconst envSchema = z.object({\n SHOPIFY_API_KEY: z.string({\n required_error: 'SHOPIFY_API_KEY is required',\n }),\n SHOPIFY_API_SECRET: z.string({\n required_error: 'SHOPIFY_API_SECRET is required',\n }),\n SHOPIFY_API_HOSTNAME: z.string({\n required_error: 'SHOPIFY_API_HOSTNAME is required',\n }),\n SHOPIFY_ACCESS_TOKEN: z.string({\n required_error: 'SHOPIFY_ACCESS_TOKEN is required',\n }),\n NODE_ENV: z\n .enum(['development', 'production', 'test'])\n .default('development'),\n})\n\nconst mapLogLevelToShopifySeverity = (level: string): LogSeverity => {\n switch (level) {\n case 'silent':\n return LogSeverity.Error\n case 'debug':\n return LogSeverity.Debug\n case 'info':\n return LogSeverity.Info\n case 'warn':\n return LogSeverity.Warning\n case 'error':\n return LogSeverity.Error\n default:\n return LogSeverity.Info\n }\n}\n\nlet shopifyGraphqlClient: GraphqlClient\n\ntry {\n // biome-ignore lint/nursery/noProcessEnv: <explanation>\n const env = envSchema.parse(process.env)\n\n const shopify = shopifyApi({\n apiKey: env.SHOPIFY_API_KEY,\n apiSecretKey: env.SHOPIFY_API_SECRET,\n hostName: env.SHOPIFY_API_HOSTNAME,\n apiVersion: SHOPIFY_API_VERSION,\n isEmbeddedApp: false,\n logger: { level: mapLogLevelToShopifySeverity(activeLogLevelName) },\n future: {\n customerAddressDefaultFix: true,\n lineItemBilling: true,\n unstable_managedPricingSupport: false,\n },\n })\n\n const shopifySession = new Session({\n id: `custom-session-${env.SHOPIFY_API_HOSTNAME}`,\n shop: env.SHOPIFY_API_HOSTNAME,\n state: 'authenticated',\n isOnline: true,\n accessToken: env.SHOPIFY_ACCESS_TOKEN,\n })\n\n shopifyGraphqlClient = new shopify.clients.Graphql({\n session: shopifySession,\n })\n\n logger.info('Shopify API client initialized successfully.')\n} catch (error) {\n if (error instanceof z.ZodError) {\n const msg = JSON.stringify(error.format(), null, 2)\n logger.error(msg)\n } else {\n logger.error('Failed to initialize Shopify API client:', error)\n }\n throw error\n}\n\nexport { shopifyGraphqlClient as shopifyClient }\n","import { logger } from './logger.js'\nimport { shopifyClient } from './shopifyClient.js'\n\nexport function convertIdIntoGid(\n id: bigint,\n type: 'Order' | 'Customer',\n): string {\n return `gid://shopify/${type}/${id}`\n}\n\ninterface PageInfo {\n hasNextPage: boolean\n endCursor?: string | null | undefined\n}\n\ninterface ShopifyErrorWithMessage {\n message?: string\n [key: string]: unknown\n}\n\ntype TExtractorFunctionType<TResultNode, TPageData> = (pageData: TPageData) => {\n nodes: TResultNode[]\n pageInfo?: PageInfo\n userErrors?: { message?: string }[]\n}\n\nexport async function fetchShopifyGraphql<TResultNode, TPageData>(params: {\n query: string\n variables: Record<string, unknown>\n dataExtractor?: TExtractorFunctionType<TResultNode, TPageData>\n fetchAllPages?: boolean\n}): Promise<TResultNode[]>\nexport async function fetchShopifyGraphql<TReturnType>(params: {\n query: string\n variables: Record<string, unknown>\n}): Promise<TReturnType>\nexport async function fetchShopifyGraphql<\n TResultNode,\n TPageData,\n TReturnType,\n>(params: {\n query: string\n variables: Record<string, unknown>\n dataExtractor?: TExtractorFunctionType<TResultNode, TPageData>\n fetchAllPages?: boolean\n}): Promise<TResultNode[] | TReturnType> {\n const {\n query,\n variables: initialVariables,\n dataExtractor,\n fetchAllPages = false,\n } = params\n\n let currentVariables = { ...initialVariables }\n\n if (!dataExtractor) {\n return makeRequest<NonNullable<TReturnType>>(query, currentVariables)\n }\n\n const allNodes: TResultNode[] = []\n let hasNextLoop = true\n\n do {\n const response = await makeRequest<TPageData>(query, currentVariables)\n const { nodes, pageInfo, userErrors } = dataExtractor(response)\n\n // Handle Shopify mutation userErrors pattern\n if (Array.isArray(userErrors) && userErrors.length > 0) {\n const errorMessages = userErrors\n .map((e) => e.message || JSON.stringify(e))\n .join('\\n')\n logger.error('Shopify mutation userErrors:', errorMessages)\n throw new Error(`Shopify mutation userErrors: ${errorMessages}`)\n }\n\n allNodes.push(...nodes)\n\n hasNextLoop = fetchAllPages ? !!pageInfo?.hasNextPage : false\n if (hasNextLoop && pageInfo?.endCursor) {\n currentVariables = {\n ...currentVariables,\n after: pageInfo.endCursor,\n }\n }\n } while (hasNextLoop)\n\n return allNodes\n}\n\nasync function makeRequest<TReturnDataType>(\n query: string,\n variables: Record<string, unknown>,\n): Promise<NonNullable<TReturnDataType>> {\n type ShopifyRequestErrorType = {\n errors?: ShopifyErrorWithMessage | ShopifyErrorWithMessage[]\n }\n\n const response = (await shopifyClient.request<TReturnDataType>(query, {\n variables,\n })) as { data?: TReturnDataType } & ShopifyRequestErrorType\n\n if (response.errors) {\n let errorMessages = 'GraphQL query failed.'\n const errors = response.errors\n if (Array.isArray(errors)) {\n errorMessages = errors\n .map((e: ShopifyErrorWithMessage) => e.message || JSON.stringify(e))\n .join('\\n')\n } else if (\n typeof errors === 'object' &&\n errors !== null &&\n 'message' in errors\n ) {\n errorMessages = errors.message || JSON.stringify(errors)\n } else if (typeof errors === 'string') {\n errorMessages = errors\n } else {\n errorMessages = JSON.stringify(errors)\n }\n logger.error('GraphQL query failed:', errorMessages)\n throw new Error(`GraphQL errors: ${errorMessages}`)\n }\n\n if (!response.data) {\n throw new Error('No data in Shopify API response')\n }\n\n return response.data\n}\n","import z from 'zod'\nimport { logger } from './logger.js'\n\nexport async function returnOutputParsed<T>(\n data: unknown,\n Model: z.ZodType<T>,\n) {\n const parsed = await Model.safeParseAsync(data)\n if (!parsed.success) {\n if (parsed.error instanceof z.ZodError) {\n const msg = JSON.stringify(parsed.error.format(), null, 2)\n logger.error(msg)\n } else {\n logger.error('Failed to parse:', parsed.error)\n }\n // throw parsedVariants.error\n throw new Error('Failed to parse product variants')\n }\n logger.info('Parsed data successfully')\n return parsed.data\n}\n","import z from 'zod'\nimport type {\n OrderByIdFullQuery,\n OrderByIdQuery,\n OrderByIdQueryVariables,\n} from '../../generated-api-types/2025-04/admin.generated.js'\nimport { logger } from '../../utils/logger.js'\nimport {\n convertIdIntoGid,\n fetchShopifyGraphql,\n} from '../../utils/shopifyFetch.js'\nimport { returnOutputParsed } from '../../utils/zod.js'\nimport { queryOrderById, queryOrderByIdFull } from './getOrderById.queries.js'\n\n// Address schema (shared between lean and full)\nconst AddressSchema = z\n .object({\n firstName: z.string().nullable(),\n lastName: z.string().nullable(),\n address1: z.string().nullable(),\n address2: z.string().nullable(),\n city: z.string().nullable(),\n province: z.string().nullable(),\n country: z.string().nullable(),\n zip: z.string().nullable(),\n })\n .nullable()\n\n// Lean order schema\nconst GetLeanOrderByIdReturn = z\n .object({\n id: z.string(),\n name: z.string(),\n createdAt: z.string(),\n updatedAt: z.string(),\n cancelledAt: z.string().nullable(),\n cancelReason: z.string().nullable(),\n totalPrice: z.object({\n amount: z.string(),\n currencyCode: z.string(),\n }),\n customer: z\n .object({\n id: z.string(),\n displayName: z.string(),\n firstName: z.string().nullable(),\n lastName: z.string().nullable(),\n emailAddress: z.string().nullable(),\n })\n .nullable(),\n financialStatus: z.string().nullable(),\n fulfillmentStatus: z.string().nullable(),\n shippingAddress: AddressSchema,\n })\n .nullable()\n\nexport type LeanOrder = z.infer<typeof GetLeanOrderByIdReturn>\n\n// Full order type - derived from the generated GraphQL types\nexport type FullOrder = NonNullable<OrderByIdFullQuery['order']> | null\n\ntype OrderDetailLevel = 'lean' | 'full'\n\n// Function overloads\nexport function getOrderById(id: number | bigint): Promise<LeanOrder>\nexport function getOrderById(\n id: number | bigint,\n detailLevel: 'lean',\n): Promise<LeanOrder>\nexport function getOrderById(\n id: number | bigint,\n detailLevel: 'full',\n): Promise<FullOrder>\n\n/**\n * Retrieves a single order from Shopify by its numeric ID.\n * Returns null if no order is found with the specified ID.\n *\n * @param {number | bigint} id - The numerical Shopify order ID (e.g., 12345678 or 12345678n).\n * @param {OrderDetailLevel} detailLevel - The level of detail to return ('lean' or 'full'). Defaults to 'lean'.\n * @returns {Promise<LeanOrder | FullOrder>} A promise that resolves to the order data or null if not found.\n * @throws {Error} If the GraphQL query fails or if the response structure is invalid.\n */\nexport async function getOrderById(\n id: number | bigint,\n detailLevel: OrderDetailLevel = 'lean',\n): Promise<LeanOrder | FullOrder> {\n const bigIntId = typeof id === 'number' ? BigInt(id) : id\n if (detailLevel === 'lean') {\n return getLeanOrderById(bigIntId)\n }\n return getFullOrderById(bigIntId)\n}\n\nasync function getLeanOrderById(id: bigint): Promise<LeanOrder> {\n const variables: OrderByIdQueryVariables = {\n id: convertIdIntoGid(id, 'Order'),\n }\n\n const response = await fetchShopifyGraphql<OrderByIdQuery>({\n query: queryOrderById,\n variables,\n })\n\n if (!response.order) {\n logger.debug(`No order found with ID: ${id}`)\n return null\n }\n\n const order = response.order\n\n const leanOrder = {\n id: order.id,\n name: order.name,\n createdAt: order.createdAt,\n updatedAt: order.updatedAt,\n cancelledAt: order.cancelledAt ?? null,\n cancelReason: order.cancelReason ?? null,\n totalPrice: {\n amount: order.totalPriceSet?.shopMoney?.amount ?? '',\n currencyCode: order.totalPriceSet?.shopMoney?.currencyCode ?? '',\n },\n customer: order.customer\n ? {\n id: order.customer.id,\n displayName: order.customer.displayName,\n firstName: order.customer.firstName ?? null,\n lastName: order.customer.lastName ?? null,\n emailAddress:\n order.customer.defaultEmailAddress?.emailAddress ?? null,\n }\n : null,\n financialStatus: order.displayFinancialStatus ?? null,\n fulfillmentStatus: order.displayFulfillmentStatus ?? null,\n shippingAddress: order.shippingAddress\n ? {\n firstName: order.shippingAddress.firstName ?? null,\n lastName: order.shippingAddress.lastName ?? null,\n address1: order.shippingAddress.address1 ?? null,\n address2: order.shippingAddress.address2 ?? null,\n city: order.shippingAddress.city ?? null,\n province: order.shippingAddress.province ?? null,\n country: order.shippingAddress.country ?? null,\n zip: order.shippingAddress.zip ?? null,\n }\n : null,\n }\n\n return await returnOutputParsed(leanOrder, GetLeanOrderByIdReturn)\n}\n\nasync function getFullOrderById(id: bigint): Promise<FullOrder> {\n const variables: OrderByIdQueryVariables = {\n id: convertIdIntoGid(id, 'Order'),\n }\n\n const response = await fetchShopifyGraphql<OrderByIdFullQuery>({\n query: queryOrderByIdFull,\n variables,\n })\n\n if (!response.order) {\n logger.debug(`No order found with ID: ${id}`)\n return null\n }\n\n return response.order\n}\n","import { gql } from '../../utils/logger'\n\nexport const queryOrderById = gql`#graphql\n query orderById($id: ID!) {\n order(id: $id) {\n id\n name\n createdAt\n updatedAt\n cancelledAt\n cancelReason\n totalPriceSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n customer {\n id\n lastName\n defaultEmailAddress {\n emailAddress\n }\n displayName\n firstName\n }\n displayFinancialStatus\n displayFulfillmentStatus\n shippingAddress {\n firstName\n lastName\n address1\n address2\n city\n province\n country\n zip\n }\n }\n }\n`\n\nexport const queryOrderByIdFull = gql`#graphql\n query orderByIdFull($id: ID!) {\n order(id: $id) {\n id\n name\n createdAt\n updatedAt\n processedAt\n closedAt\n cancelledAt\n cancelReason\n totalPriceSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n customer {\n id\n firstName\n lastName\n email\n phone\n }\n displayFinancialStatus\n displayFulfillmentStatus\n shippingAddress {\n firstName\n lastName\n address1\n address2\n city\n province\n country\n zip\n }\n billingAddress {\n firstName\n lastName\n address1\n address2\n city\n province\n country\n zip\n }\n lineItems(first: 100) {\n edges {\n node {\n id\n sku\n title\n variantTitle\n quantity\n customAttributes {\n key\n value\n }\n originalUnitPriceSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n vendor\n image {\n url\n width\n height\n altText\n }\n }\n }\n }\n fulfillments {\n id\n name\n totalQuantity\n status\n createdAt\n estimatedDeliveryAt\n deliveredAt\n trackingInfo {\n company\n number\n url\n }\n fulfillmentLineItems(first: 100) {\n edges {\n node {\n id\n quantity\n lineItem {\n id\n }\n }\n }\n }\n }\n shippingLine {\n originalPriceSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n }\n taxLines {\n priceSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n }\n totalDiscountsSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n discountCodes\n refunds {\n totalRefundedSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n }\n }\n }\n`\n","import z from 'zod'\nimport type {\n OrdersByNameFullQuery,\n OrdersByNameQuery,\n OrdersByNameQueryVariables,\n} from '../../generated-api-types/2025-04/admin.generated.js'\nimport { logger } from '../../utils/logger.js'\nimport { fetchShopifyGraphql } from '../../utils/shopifyFetch.js'\nimport { returnOutputParsed } from '../../utils/zod.js'\nimport {\n queryOrdersByName,\n queryOrdersByNameFull,\n} from './getOrderByName.queries.js'\n\nconst GetLeanOrderByNameReturn = z\n .object({\n id: z.string(),\n name: z.string(),\n createdAt: z.string(),\n updatedAt: z.string(),\n totalPrice: z.object({\n amount: z.string(),\n currencyCode: z.string(),\n }),\n customer: z\n .object({\n id: z.string(),\n displayName: z.string(),\n emailAddress: z.string().nullable(),\n })\n .nullable(),\n financialStatus: z.string().nullable(),\n fulfillmentStatus: z.string().nullable(),\n })\n .nullable()\n\nexport type LeanOrderByName = z.infer<typeof GetLeanOrderByNameReturn>\n\nexport type FullOrderByName = NonNullable<\n NonNullable<OrdersByNameFullQuery['orders']>['edges'][number]['node']\n> | null\n\ntype OrderDetailLevel = 'lean' | 'full'\n\n// Function overloads\nexport function getOrderByName(\n orderName: string,\n detailLevel: 'lean',\n): Promise<LeanOrderByName>\nexport function getOrderByName(\n orderName: string,\n detailLevel: 'full',\n): Promise<FullOrderByName>\nexport function getOrderByName(orderName: string): Promise<LeanOrderByName>\n\n/**\n * Retrieves a single order from Shopify by its order name (e.g., \"B12345\").\n * Returns null if no order is found with the specified name.\n *\n * @param {string} orderName - The order name to search for (e.g., \"B12345\").\n * @param {OrderDetailLevel} detailLevel - The level of detail to return ('lean' or 'full'). Defaults to 'lean'.\n * @returns {Promise<LeanOrderByName | FullOrderByName>} A promise that resolves to the order data or null if not found.\n * @throws {Error} If the GraphQL query fails or if the response structure is invalid.\n */\nexport async function getOrderByName(\n orderName: string,\n detailLevel: OrderDetailLevel = 'lean',\n): Promise<LeanOrderByName | FullOrderByName> {\n if (detailLevel === 'lean') {\n return getLeanOrderByName(orderName)\n }\n return getFullOrderByName(orderName)\n}\n\nasync function getLeanOrderByName(orderName: string): Promise<LeanOrderByName> {\n const variables: OrdersByNameQueryVariables = {\n first: 1,\n queryFilter: `name:${orderName}`,\n }\n\n type SingleNode = NonNullable<\n NonNullable<OrdersByNameQuery['orders']>['edges'][number]['node']\n >\n\n const extractedNodes = await fetchShopifyGraphql<\n SingleNode,\n OrdersByNameQuery\n >({\n query: queryOrdersByName,\n variables,\n dataExtractor: (pageData: OrdersByNameQuery) => {\n if (!pageData.orders) {\n throw new Error(\n \"GraphQL response for orders is missing the 'orders' field.\",\n )\n }\n const nodes: SingleNode[] = pageData.orders.edges.map(\n (edge: { node: SingleNode }) => edge.node,\n )\n return {\n nodes,\n }\n },\n fetchAllPages: false,\n })\n\n const order = extractedNodes[0]\n if (!order) {\n logger.debug(`No order found with name: ${orderName}`)\n return null\n }\n\n const leanOrder = {\n id: order.id,\n name: order.name,\n createdAt: order.createdAt,\n updatedAt: order.updatedAt,\n totalPrice: {\n amount: order.totalPriceSet?.shopMoney?.amount ?? '',\n currencyCode: order.totalPriceSet?.shopMoney?.currencyCode ?? '',\n },\n customer: order.customer\n ? {\n id: order.customer.id,\n displayName: order.customer.displayName,\n emailAddress:\n order.customer.defaultEmailAddress?.emailAddress ?? null,\n }\n : null,\n financialStatus: order.displayFinancialStatus ?? null,\n fulfillmentStatus: order.displayFulfillmentStatus ?? null,\n }\n\n return await returnOutputParsed(leanOrder, GetLeanOrderByNameReturn)\n}\n\nasync function getFullOrderByName(orderName: string): Promise<FullOrderByName> {\n const variables: OrdersByNameQueryVariables = {\n first: 1,\n queryFilter: `name:${orderName}`,\n }\n\n type SingleNode = NonNullable<\n NonNullable<OrdersByNameFullQuery['orders']>['edges'][number]['node']\n >\n\n const extractedNodes = await fetchShopifyGraphql<\n SingleNode,\n OrdersByNameFullQuery\n >({\n query: queryOrdersByNameFull,\n variables,\n dataExtractor: (pageData: OrdersByNameFullQuery) => {\n if (!pageData.orders) {\n throw new Error(\n \"GraphQL response for orders is missing the 'orders' field.\",\n )\n }\n const nodes: SingleNode[] = pageData.orders.edges.map(\n (edge: { node: SingleNode }) => edge.node,\n )\n return {\n nodes,\n }\n },\n fetchAllPages: false,\n })\n\n if (extractedNodes.length === 0) {\n logger.debug(`No order found with name: ${orderName}`)\n return null\n }\n\n const order = extractedNodes[0]\n if (!order) {\n logger.debug(`No order found with name: ${orderName}`)\n return null\n }\n\n return order\n}\n","import { gql } from '../../utils/logger'\n\nexport const queryOrdersByName = gql`#graphql\n query ordersByName($first: Int!, $queryFilter: String!) {\n orders(first: $first, query: $queryFilter) {\n edges {\n node {\n id\n name\n createdAt\n updatedAt\n totalPriceSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n customer {\n id\n lastName\n defaultEmailAddress {\n emailAddress\n }\n displayName\n firstName\n }\n displayFinancialStatus\n displayFulfillmentStatus\n }\n }\n pageInfo {\n hasNextPage\n endCursor\n }\n }\n }\n`\n\nexport const queryOrdersByNameFull = gql`#graphql\n query ordersByNameFull($first: Int!, $queryFilter: String!) {\n orders(first: $first, query: $queryFilter) {\n edges {\n node {\n billingAddress {\n address1\n address2\n city\n company\n country\n countryCodeV2\n firstName\n formattedArea\n id\n lastName\n name\n phone\n province\n provinceCode\n timeZone\n zip\n }\n billingAddressMatchesShippingAddress\n cancelReason\n cancellation {\n staffNote\n }\n cancelledAt\n capturable\n clientIp\n closed\n closedAt\n confirmed\n createdAt\n currencyCode\n currentCartDiscountAmountSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n currentShippingPriceSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n currentSubtotalLineItemsQuantity\n currentSubtotalPriceSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n currentTaxLines {\n channelLiable\n rate\n ratePercentage\n source\n title\n priceSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n }\n currentTotalAdditionalFeesSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n currentTotalDiscountsSet {\n presentmentMoney {\n amount\n currencyCode\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n currentTotalDutiesSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n currentTotalPriceSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n currentTotalTaxSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n currentTotalWeight\n customer {\n id\n lastName\n defaultEmailAddress {\n emailAddress\n }\n displayName\n firstName\n }\n customerAcceptsMarketing\n discountCodes\n discountCode\n displayAddress {\n address1\n address2\n city\n company\n country\n countryCodeV2\n firstName\n formattedArea\n id\n lastName\n name\n phone\n province\n provinceCode\n timeZone\n zip\n }\n displayFinancialStatus\n displayFulfillmentStatus\n dutiesIncluded\n edited\n email\n estimatedTaxes\n fulfillable\n fulfillments(first: 20) {\n createdAt\n deliveredAt\n displayStatus\n estimatedDeliveryAt\n updatedAt\n trackingInfo(first: 10) {\n company\n url\n }\n totalQuantity\n status\n name\n id\n }\n fullyPaid\n id\n lineItems(first: 50) {\n edges {\n node {\n id\n name\n originalUnitPriceSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n quantity\n requiresShipping\n sku\n title\n variantTitle\n }\n }\n }\n name\n note\n processedAt\n shippingAddress {\n address1\n address2\n city\n company\n country\n countryCodeV2\n firstName\n formattedArea\n id\n lastName\n name\n phone\n province\n provinceCode\n timeZone\n zip\n }\n statusPageUrl\n tags\n totalPriceSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n totalReceivedSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n totalRefundedSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n totalShippingPriceSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n totalTaxSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n totalWeight\n unpaid\n updatedAt\n }\n }\n pageInfo {\n hasNextPage\n endCursor\n }\n }\n }\n`\n","import z from 'zod'\nimport type {\n LeanProductVariantsQuery,\n LeanProductVariantsQueryVariables,\n} from '../../generated-api-types/2025-04/admin.generated.js'\nimport { gql, logger } from '../../utils/logger.js'\nimport { fetchShopifyGraphql } from '../../utils/shopifyFetch.js'\nimport { returnOutputParsed } from '../../utils/zod.js'\n\nconst GetLeanProductVariantsReturn = z.array(\n z.object({\n productId: z.string(),\n productTitle: z.string(),\n variantId: z.string(),\n variantTitle: z.string(),\n sku: z.string(),\n }),\n)\n\ntype GetLeanProductVariantsReturnType = z.infer<\n typeof GetLeanProductVariantsReturn\n>\n\n/**\n * Retrieves a lean list of product variants from Shopify, optionally filtered by SKUs.\n * Product variants are mapped to a simpler output structure.\n * Variants missing essential properties (e.g., SKU) will be filtered out and logged.\n *\n * @param {string[]} [skus] - An optional array of SKUs to filter by. If provided, only variants matching these SKUs will be fetched.\n * @returns {Promise<GetLeanProductVariantsReturnType>} A promise that resolves to an array of lean product variant data.\n * @throws {Error} If the GraphQL query fails, returns no data, or if the `productVariants` field is missing in the response.\n */\nexport async function getLeanProductVariants(\n skus?: string[],\n): Promise<GetLeanProductVariantsReturnType> {\n const queryGql = gql`#graphql\n query leanProductVariants($first: Int!, $after: String, $queryFilter: String) {\n productVariants(first: $first, after: $after, query: $queryFilter) {\n edges {\n node { \n id\n title\n sku\n product {\n id\n title\n }\n }\n }\n pageInfo { \n hasNextPage\n endCursor\n }\n }\n }\n `\n\n const initialVariables: LeanProductVariantsQueryVariables = { first: 250 }\n if (skus && skus.length > 0) {\n initialVariables.queryFilter = skus\n .map((sku: string) => `sku:${sku}`)\n .join(' OR ')\n }\n\n // Type for a single node from the productVariants query\n type SingleNode = NonNullable<\n NonNullable<\n LeanProductVariantsQuery['productVariants']\n >['edges'][number]['node']\n >\n\n const extractedNodes = await fetchShopifyGraphql<\n SingleNode,\n LeanProductVariantsQuery\n >({\n query: queryGql,\n variables: initialVariables,\n dataExtractor: (pageData: LeanProductVariantsQuery) => {\n if (!pageData.productVariants) {\n throw new Error(\n \"GraphQL response for product variants is missing the 'productVariants' field.\",\n )\n }\n const nodes: SingleNode[] = pageData.productVariants.edges.map(\n (edge: { node: SingleNode }) => edge.node,\n )\n return {\n nodes,\n pageInfo: pageData.productVariants.pageInfo,\n }\n },\n fetchAllPages: true,\n })\n\n const allVariants = extractedNodes.flatMap<\n GetLeanProductVariantsReturnType[number]\n >((v) => {\n if (v.sku) {\n return [\n {\n productId: v.product.id,\n productTitle: v.product.title,\n variantId: v.id,\n variantTitle: v.title,\n sku: v.sku,\n },\n ]\n }\n logger.debug(\n `Product ${v.product.title} (ID: ${v.product.id}) has a variant (ID: ${v.id}) with no SKU. Filtering out.`,\n )\n return []\n })\n\n return await returnOutputParsed(allVariants, GetLeanProductVariantsReturn)\n}\n","import z from 'zod'\nimport type {\n OrderPaymentDetailsByIdQuery,\n OrderPaymentDetailsByIdQueryVariables,\n} from '../../generated-api-types/2025-04/admin.generated.js'\nimport { logger } from '../../utils/logger.js'\nimport {\n convertIdIntoGid,\n fetchShopifyGraphql,\n} from '../../utils/shopifyFetch.js'\nimport { returnOutputParsed } from '../../utils/zod.js'\nimport { queryOrderPaymentDetails } from './getOrderPaymentDetails.queries.js'\n\nconst GetOrderPaymentDetailsByIdReturn = z.object({\n order: z.object({\n transactions: z.array(\n z.object({\n amountSet: z.object({\n shopMoney: z.object({\n amount: z.string(),\n currencyCode: z.string(),\n }),\n }),\n createdAt: z.string(),\n gateway: z.string(),\n formattedGateway: z.string(),\n kind: z.string(),\n paymentId: z.string(),\n }),\n ),\n }),\n})\n\ntype GetOrderPaymentDetailsByIdReturnType = z.infer<\n typeof GetOrderPaymentDetailsByIdReturn\n>\n\n/**\n * Retrieves payment details for a single order from Shopify by its ID.\n * Returns null if no order is found with the specified ID.\n *\n * @param {bigint} id - The numerical Shopify order ID (e.g., 12345678n).\n * @returns {Promise<GetOrderPaymentDetailsByIdReturnType | null>} A promise that resolves to the order payment data or null if not found.\n * @throws {Error} If the GraphQL query fails or if the response structure is invalid.\n */\nexport async function getOrderPaymentDetailsById(\n id: bigint,\n): Promise<GetOrderPaymentDetailsByIdReturnType | null> {\n const variables: OrderPaymentDetailsByIdQueryVariables = {\n id: convertIdIntoGid(id, 'Order'),\n }\n\n const response = await fetchShopifyGraphql<OrderPaymentDetailsByIdQuery>({\n query: queryOrderPaymentDetails,\n variables,\n })\n\n if (!response.order) {\n logger.debug(`No order found with ID: ${id}`)\n return null\n }\n\n return await returnOutputParsed(response, GetOrderPaymentDetailsByIdReturn)\n}\n","import { gql } from '../../utils/logger.js'\n\nexport const queryOrderPaymentDetails = gql`#graphql\n query orderPaymentDetailsById($id: ID!) {\n order(id: $id) {\n transactions {\n amountSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n createdAt\n gateway\n formattedGateway\n kind\n paymentId\n }\n }\n }\n`\n","/**\n * Transforms GraphQL responses to REST-like format.\n *\n * This utility recursively:\n * 1. Flattens `{ edges: [{ node: ... }] }` → `[...]`\n * 2. Converts camelCase to snake_case (`lineItems` → `line_items`)\n * 3. Extracts numeric IDs from GIDs (`gid://shopify/Order/123` → `123`)\n */\n\n/**\n * Convert a camelCase string to snake_case\n */\nfunction camelToSnake(str: string): string {\n return str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`)\n}\n\n/**\n * Extract numeric ID from a Shopify GID string\n */\nfunction extractNumericId(gid: string): number {\n const match = gid.match(/\\d+$/)\n return match ? parseInt(match[0], 10) : 0\n}\n\n/**\n * Transform a GraphQL response object to REST-like format.\n *\n * @example\n * ```typescript\n * const graphqlOrder = {\n * id: 'gid://shopify/Order/123',\n * lineItems: {\n * edges: [{ node: { id: 'gid://shopify/LineItem/456', sku: 'ABC' } }]\n * }\n * };\n *\n * const restOrder = toRestFormat(graphqlOrder);\n * // Result:\n * // {\n * // id: 123,\n * // line_items: [{ id: 456, sku: 'ABC' }]\n * // }\n * ```\n */\nexport function toRestFormat<T>(obj: T): unknown {\n if (obj === null || obj === undefined) {\n return obj\n }\n\n if (Array.isArray(obj)) {\n return obj.map(toRestFormat)\n }\n\n if (typeof obj === 'object') {\n const record = obj as Record<string, unknown>\n const result: Record<string, unknown> = {}\n\n for (const [key, value] of Object.entries(record)) {\n // Flatten edges/node pattern: { edges: [{ node: ... }] } → [...]\n if (\n key === 'edges' &&\n Array.isArray(value) &&\n value.every(\n (item) =>\n typeof item === 'object' && item !== null && 'node' in item,\n )\n ) {\n return value.map((edge: { node: unknown }) => toRestFormat(edge.node))\n }\n\n // Convert GID to numeric ID\n if (\n key === 'id' &&\n typeof value === 'string' &&\n value.startsWith('gid://')\n ) {\n result[key] = extractNumericId(value)\n continue\n }\n\n // Convert camelCase to snake_case and recurse\n const snakeKey = camelToSnake(key)\n result[snakeKey] = toRestFormat(value)\n }\n\n return result\n }\n\n return obj\n}\n","/**\n * Extract numeric ID from a Shopify GID string.\n *\n * @example\n * parseGid('gid://shopify/Order/12345678901234') // → 12345678901234\n * parseGid('gid://shopify/LineItem/999') // → 999\n */\nexport function parseGid(gid: string): number {\n const match = gid.match(/\\d+$/)\n return match ? parseInt(match[0], 10) : 0\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,cAAc;;;ACAd,IAAM,EAAE,IAAI,IAAI;AAET,IAAM,MAAM,OAAO;AAE1B,IAAM,YAAY;AAAA,EAChB,Q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AM,WAAW,QAAQ,GACzB;AACA,eAAO,GAAG,IAAI,iBAAiB,KAAK;AACpC;AAAA,MACF;AAGA,YAAM,WAAW,aAAa,GAAG;AACjC,aAAO,QAAQ,IAAI,aAAa,KAAK;AAAA,IACvC;AAEA,WAAO;AAAA,EACT;AAEA,SAAO;AACT;;;AClFO,SAAS,SAAS,KAAqB;AAC5C,QAAM,QAAQ,IAAI,MAAM,MAAM;AAC9B,SAAO,QAAQ,SAAS,MAAM,CAAC,GAAG,EAAE,IAAI;AAC1C;","names":["import_zod","dotenv","env","import_zod","z","z","import_zod","z","import_zod","z","import_zod","z","import_zod","z"]}
package/dist/index.d.cts CHANGED
@@ -18539,9 +18539,7 @@ type OrderByIdFullQuery = {
18539
18539
  totalPriceSet: {
18540
18540
  shopMoney: Pick<MoneyV2, 'amount' | 'currencyCode'>;
18541
18541
  };
18542
- customer?: Maybe<(Pick<Customer, 'id' | 'lastName' | 'displayName' | 'firstName' | 'phone'> & {
18543
- defaultEmailAddress?: Maybe<Pick<CustomerEmailAddress, 'emailAddress'>>;
18544
- })>;
18542
+ customer?: Maybe<Pick<Customer, 'id' | 'firstName' | 'lastName' | 'email' | 'phone'>>;
18545
18543
  shippingAddress?: Maybe<Pick<MailingAddress, 'firstName' | 'lastName' | 'address1' | 'address2' | 'city' | 'province' | 'country' | 'zip'>>;
18546
18544
  billingAddress?: Maybe<Pick<MailingAddress, 'firstName' | 'lastName' | 'address1' | 'address2' | 'city' | 'province' | 'country' | 'zip'>>;
18547
18545
  lineItems: {
@@ -18737,7 +18735,7 @@ interface GeneratedQueryTypes {
18737
18735
  return: OrderByIdQuery;
18738
18736
  variables: OrderByIdQueryVariables;
18739
18737
  };
18740
- "#graphql\n query orderByIdFull($id: ID!) {\n order(id: $id) {\n id\n name\n createdAt\n updatedAt\n processedAt\n closedAt\n cancelledAt\n cancelReason\n totalPriceSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n customer {\n id\n lastName\n defaultEmailAddress {\n emailAddress\n }\n displayName\n firstName\n phone\n }\n displayFinancialStatus\n displayFulfillmentStatus\n shippingAddress {\n firstName\n lastName\n address1\n address2\n city\n province\n country\n zip\n }\n billingAddress {\n firstName\n lastName\n address1\n address2\n city\n province\n country\n zip\n }\n lineItems(first: 100) {\n edges {\n node {\n id\n sku\n title\n variantTitle\n quantity\n customAttributes {\n key\n value\n }\n originalUnitPriceSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n vendor\n image {\n url\n width\n height\n altText\n }\n }\n }\n }\n fulfillments {\n id\n name\n totalQuantity\n status\n createdAt\n estimatedDeliveryAt\n deliveredAt\n trackingInfo {\n company\n number\n url\n }\n fulfillmentLineItems(first: 100) {\n edges {\n node {\n id\n quantity\n lineItem {\n id\n }\n }\n }\n }\n }\n shippingLine {\n originalPriceSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n }\n taxLines {\n priceSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n }\n totalDiscountsSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n discountCodes\n refunds {\n totalRefundedSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n }\n }\n }\n": {
18738
+ "#graphql\n query orderByIdFull($id: ID!) {\n order(id: $id) {\n id\n name\n createdAt\n updatedAt\n processedAt\n closedAt\n cancelledAt\n cancelReason\n totalPriceSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n customer {\n id\n firstName\n lastName\n email\n phone\n }\n displayFinancialStatus\n displayFulfillmentStatus\n shippingAddress {\n firstName\n lastName\n address1\n address2\n city\n province\n country\n zip\n }\n billingAddress {\n firstName\n lastName\n address1\n address2\n city\n province\n country\n zip\n }\n lineItems(first: 100) {\n edges {\n node {\n id\n sku\n title\n variantTitle\n quantity\n customAttributes {\n key\n value\n }\n originalUnitPriceSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n vendor\n image {\n url\n width\n height\n altText\n }\n }\n }\n }\n fulfillments {\n id\n name\n totalQuantity\n status\n createdAt\n estimatedDeliveryAt\n deliveredAt\n trackingInfo {\n company\n number\n url\n }\n fulfillmentLineItems(first: 100) {\n edges {\n node {\n id\n quantity\n lineItem {\n id\n }\n }\n }\n }\n }\n shippingLine {\n originalPriceSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n }\n taxLines {\n priceSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n }\n totalDiscountsSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n discountCodes\n refunds {\n totalRefundedSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n }\n }\n }\n": {
18741
18739
  return: OrderByIdFullQuery;
18742
18740
  variables: OrderByIdFullQueryVariables;
18743
18741
  };
@@ -18909,9 +18907,9 @@ declare const GetLeanOrderByIdReturn: z.ZodNullable<z.ZodObject<{
18909
18907
  }>>;
18910
18908
  type LeanOrder = z.infer<typeof GetLeanOrderByIdReturn>;
18911
18909
  type FullOrder = NonNullable<OrderByIdFullQuery['order']> | null;
18912
- declare function getOrderById(id: bigint): Promise<LeanOrder>;
18913
- declare function getOrderById(id: bigint, detailLevel: 'lean'): Promise<LeanOrder>;
18914
- declare function getOrderById(id: bigint, detailLevel: 'full'): Promise<FullOrder>;
18910
+ declare function getOrderById(id: number | bigint): Promise<LeanOrder>;
18911
+ declare function getOrderById(id: number | bigint, detailLevel: 'lean'): Promise<LeanOrder>;
18912
+ declare function getOrderById(id: number | bigint, detailLevel: 'full'): Promise<FullOrder>;
18915
18913
 
18916
18914
  declare const GetLeanOrderByNameReturn: z.ZodNullable<z.ZodObject<{
18917
18915
  id: z.ZodString;
@@ -18976,11 +18974,11 @@ declare const GetLeanOrderByNameReturn: z.ZodNullable<z.ZodObject<{
18976
18974
  fulfillmentStatus: string | null;
18977
18975
  financialStatus: string | null;
18978
18976
  }>>;
18979
- type GetLeanOrderByNameReturnType = z.infer<typeof GetLeanOrderByNameReturn>;
18980
- type GetFullOrderByNameReturnType = NonNullable<NonNullable<OrdersByNameFullQuery['orders']>['edges'][number]['node']> | null;
18981
- declare function getOrderByName(orderName: string, detailLevel: 'lean'): Promise<GetLeanOrderByNameReturnType>;
18982
- declare function getOrderByName(orderName: string, detailLevel: 'full'): Promise<GetFullOrderByNameReturnType>;
18983
- declare function getOrderByName(orderName: string): Promise<GetLeanOrderByNameReturnType>;
18977
+ type LeanOrderByName = z.infer<typeof GetLeanOrderByNameReturn>;
18978
+ type FullOrderByName = NonNullable<NonNullable<OrdersByNameFullQuery['orders']>['edges'][number]['node']> | null;
18979
+ declare function getOrderByName(orderName: string, detailLevel: 'lean'): Promise<LeanOrderByName>;
18980
+ declare function getOrderByName(orderName: string, detailLevel: 'full'): Promise<FullOrderByName>;
18981
+ declare function getOrderByName(orderName: string): Promise<LeanOrderByName>;
18984
18982
 
18985
18983
  declare const GetLeanProductVariantsReturn: z.ZodArray<z.ZodObject<{
18986
18984
  productId: z.ZodString;
@@ -19141,4 +19139,43 @@ type GetOrderPaymentDetailsByIdReturnType = z.infer<typeof GetOrderPaymentDetail
19141
19139
  */
19142
19140
  declare function getOrderPaymentDetailsById(id: bigint): Promise<GetOrderPaymentDetailsByIdReturnType | null>;
19143
19141
 
19144
- export { type FullOrder, type LeanOrder, deleteCustomerById, getLeanProductVariants, getOrderById, getOrderByName, getOrderPaymentDetailsById };
19142
+ /**
19143
+ * Transforms GraphQL responses to REST-like format.
19144
+ *
19145
+ * This utility recursively:
19146
+ * 1. Flattens `{ edges: [{ node: ... }] }` → `[...]`
19147
+ * 2. Converts camelCase to snake_case (`lineItems` → `line_items`)
19148
+ * 3. Extracts numeric IDs from GIDs (`gid://shopify/Order/123` → `123`)
19149
+ */
19150
+ /**
19151
+ * Transform a GraphQL response object to REST-like format.
19152
+ *
19153
+ * @example
19154
+ * ```typescript
19155
+ * const graphqlOrder = {
19156
+ * id: 'gid://shopify/Order/123',
19157
+ * lineItems: {
19158
+ * edges: [{ node: { id: 'gid://shopify/LineItem/456', sku: 'ABC' } }]
19159
+ * }
19160
+ * };
19161
+ *
19162
+ * const restOrder = toRestFormat(graphqlOrder);
19163
+ * // Result:
19164
+ * // {
19165
+ * // id: 123,
19166
+ * // line_items: [{ id: 456, sku: 'ABC' }]
19167
+ * // }
19168
+ * ```
19169
+ */
19170
+ declare function toRestFormat<T>(obj: T): unknown;
19171
+
19172
+ /**
19173
+ * Extract numeric ID from a Shopify GID string.
19174
+ *
19175
+ * @example
19176
+ * parseGid('gid://shopify/Order/12345678901234') // → 12345678901234
19177
+ * parseGid('gid://shopify/LineItem/999') // → 999
19178
+ */
19179
+ declare function parseGid(gid: string): number;
19180
+
19181
+ export { type FullOrder, type FullOrderByName, type LeanOrder, type LeanOrderByName, deleteCustomerById, getLeanProductVariants, getOrderById, getOrderByName, getOrderPaymentDetailsById, parseGid, toRestFormat };
package/dist/index.d.ts CHANGED
@@ -3,4 +3,5 @@ export { getOrderById, type FullOrder, type LeanOrder, } from './queries/orders/
3
3
  export { getOrderByName, type FullOrderByName, type LeanOrderByName, } from './queries/orders/getOrderByName.js';
4
4
  export { getLeanProductVariants } from './queries/productVariants/getLeanProductVariants.js';
5
5
  export { getOrderPaymentDetailsById } from './queries/orders/getOrderPaymentDetails.js';
6
+ export { parseGid } from './utils/parseGid.js';
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,6CAA6C,CAAA;AAChF,OAAO,EACL,YAAY,EACZ,KAAK,SAAS,EACd,KAAK,SAAS,GACf,MAAM,kCAAkC,CAAA;AACzC,OAAO,EACL,cAAc,EACd,KAAK,eAAe,EACpB,KAAK,eAAe,GACrB,MAAM,oCAAoC,CAAA;AAC3C,OAAO,EAAE,sBAAsB,EAAE,MAAM,qDAAqD,CAAA;AAC5F,OAAO,EAAE,0BAA0B,EAAE,MAAM,4CAA4C,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,6CAA6C,CAAA;AAChF,OAAO,EACL,YAAY,EACZ,KAAK,SAAS,EACd,KAAK,SAAS,GACf,MAAM,kCAAkC,CAAA;AACzC,OAAO,EACL,cAAc,EACd,KAAK,eAAe,EACpB,KAAK,eAAe,GACrB,MAAM,oCAAoC,CAAA;AAC3C,OAAO,EAAE,sBAAsB,EAAE,MAAM,qDAAqD,CAAA;AAC5F,OAAO,EAAE,0BAA0B,EAAE,MAAM,4CAA4C,CAAA;AACvF,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA"}
package/dist/index.js CHANGED
@@ -3,4 +3,5 @@ export { getOrderById, } from './queries/orders/getOrderById.js';
3
3
  export { getOrderByName, } from './queries/orders/getOrderByName.js';
4
4
  export { getLeanProductVariants } from './queries/productVariants/getLeanProductVariants.js';
5
5
  export { getOrderPaymentDetailsById } from './queries/orders/getOrderPaymentDetails.js';
6
+ export { parseGid } from './utils/parseGid.js';
6
7
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,6CAA6C,CAAA;AAChF,OAAO,EACL,YAAY,GAGb,MAAM,kCAAkC,CAAA;AACzC,OAAO,EACL,cAAc,GAGf,MAAM,oCAAoC,CAAA;AAC3C,OAAO,EAAE,sBAAsB,EAAE,MAAM,qDAAqD,CAAA;AAC5F,OAAO,EAAE,0BAA0B,EAAE,MAAM,4CAA4C,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,6CAA6C,CAAA;AAChF,OAAO,EACL,YAAY,GAGb,MAAM,kCAAkC,CAAA;AACzC,OAAO,EACL,cAAc,GAGf,MAAM,oCAAoC,CAAA;AAC3C,OAAO,EAAE,sBAAsB,EAAE,MAAM,qDAAqD,CAAA;AAC5F,OAAO,EAAE,0BAA0B,EAAE,MAAM,4CAA4C,CAAA;AACvF,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA"}
package/dist/index.mjs CHANGED
@@ -306,12 +306,9 @@ var queryOrderByIdFull = gql`#graphql
306
306
  }
307
307
  customer {
308
308
  id
309
- lastName
310
- defaultEmailAddress {
311
- emailAddress
312
- }
313
- displayName
314
309
  firstName
310
+ lastName
311
+ email
315
312
  phone
316
313
  }
317
314
  displayFinancialStatus
@@ -458,10 +455,11 @@ var GetLeanOrderByIdReturn = z4.object({
458
455
  shippingAddress: AddressSchema
459
456
  }).nullable();
460
457
  async function getOrderById(id, detailLevel = "lean") {
458
+ const bigIntId = typeof id === "number" ? BigInt(id) : id;
461
459
  if (detailLevel === "lean") {
462
- return getLeanOrderById(id);
460
+ return getLeanOrderById(bigIntId);
463
461
  }
464
- return getFullOrderById(id);
462
+ return getFullOrderById(bigIntId);
465
463
  }
466
464
  async function getLeanOrderById(id) {
467
465
  const variables = {
@@ -1102,11 +1100,55 @@ async function getOrderPaymentDetailsById(id) {
1102
1100
  }
1103
1101
  return await returnOutputParsed(response, GetOrderPaymentDetailsByIdReturn);
1104
1102
  }
1103
+
1104
+ // src/utils/toRestFormat.ts
1105
+ function camelToSnake(str) {
1106
+ return str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
1107
+ }
1108
+ function extractNumericId(gid) {
1109
+ const match = gid.match(/\d+$/);
1110
+ return match ? parseInt(match[0], 10) : 0;
1111
+ }
1112
+ function toRestFormat(obj) {
1113
+ if (obj === null || obj === void 0) {
1114
+ return obj;
1115
+ }
1116
+ if (Array.isArray(obj)) {
1117
+ return obj.map(toRestFormat);
1118
+ }
1119
+ if (typeof obj === "object") {
1120
+ const record = obj;
1121
+ const result = {};
1122
+ for (const [key, value] of Object.entries(record)) {
1123
+ if (key === "edges" && Array.isArray(value) && value.every(
1124
+ (item) => typeof item === "object" && item !== null && "node" in item
1125
+ )) {
1126
+ return value.map((edge) => toRestFormat(edge.node));
1127
+ }
1128
+ if (key === "id" && typeof value === "string" && value.startsWith("gid://")) {
1129
+ result[key] = extractNumericId(value);
1130
+ continue;
1131
+ }
1132
+ const snakeKey = camelToSnake(key);
1133
+ result[snakeKey] = toRestFormat(value);
1134
+ }
1135
+ return result;
1136
+ }
1137
+ return obj;
1138
+ }
1139
+
1140
+ // src/utils/parseGid.ts
1141
+ function parseGid(gid) {
1142
+ const match = gid.match(/\d+$/);
1143
+ return match ? parseInt(match[0], 10) : 0;
1144
+ }
1105
1145
  export {
1106
1146
  deleteCustomerById,
1107
1147
  getLeanProductVariants,
1108
1148
  getOrderById,
1109
1149
  getOrderByName,
1110
- getOrderPaymentDetailsById
1150
+ getOrderPaymentDetailsById,
1151
+ parseGid,
1152
+ toRestFormat
1111
1153
  };
1112
1154
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/mutations/customers/deleteCustomerById.ts","../src/utils/logger.ts","../src/utils/shopifyClient.ts","../src/utils/shopifyFetch.ts","../src/utils/zod.ts","../src/queries/orders/getOrderById.ts","../src/queries/orders/getOrderById.queries.ts","../src/queries/orders/getOrderByName.ts","../src/queries/orders/getOrderByName.queries.ts","../src/queries/productVariants/getLeanProductVariants.ts","../src/queries/orders/getOrderPaymentDetails.ts","../src/queries/orders/getOrderPaymentDetails.queries.ts"],"sourcesContent":["import z from 'zod'\nimport type {\n CustomerDeleteMutation,\n CustomerDeleteMutationVariables,\n} from '../../generated-api-types/2025-04/admin.generated'\nimport { gql } from '../../utils/logger'\nimport { fetchShopifyGraphql } from '../../utils/shopifyFetch'\nimport { returnOutputParsed } from '../../utils/zod'\n\nexport const DeleteCustomerByIdReturn = z.string().nullable()\n\ntype SingleNode = { deletedCustomerId: string | null }\n\nexport async function deleteCustomerById(\n customerId: string,\n): Promise<z.infer<typeof DeleteCustomerByIdReturn>> {\n const mutation = gql`#graphql\n mutation customerDelete($input: CustomerDeleteInput!) {\n customerDelete(input: $input) {\n deletedCustomerId\n userErrors {\n field\n message\n }\n }\n }\n `\n\n const variables: CustomerDeleteMutationVariables = {\n input: { id: customerId },\n }\n\n const response = await fetchShopifyGraphql<\n SingleNode,\n CustomerDeleteMutation\n >({\n query: mutation,\n variables,\n dataExtractor: (data: CustomerDeleteMutation) => {\n if (!data.customerDelete) {\n throw new Error(\"GraphQL response missing 'customerDelete' field\")\n }\n return {\n nodes: [\n { deletedCustomerId: data.customerDelete.deletedCustomerId ?? null },\n ],\n userErrors: data.customerDelete.userErrors,\n }\n },\n })\n\n return returnOutputParsed(\n response[0]?.deletedCustomerId ?? null,\n DeleteCustomerByIdReturn,\n )\n}\n","const { env } = process\n\nexport const gql = String.raw\n\nconst logLevels = {\n silent: 0,\n error: 1,\n warn: 2,\n info: 3,\n debug: 4,\n} as const\n\ntype LogLevelName = keyof typeof logLevels\n\nfunction getLogLevel(\n nodeEnv: string | undefined,\n logLevelEnv: string | undefined,\n): LogLevelName {\n if (logLevelEnv && logLevelEnv in logLevels) {\n return logLevelEnv as LogLevelName\n }\n\n if (nodeEnv === 'test') {\n return 'silent'\n }\n\n if (nodeEnv === 'production') {\n return 'info'\n }\n return 'debug'\n}\n\nexport const activeLogLevelName = getLogLevel(env.NODE_ENV, env.LOG_LEVEL)\nconst activeLogLevelValue = logLevels[activeLogLevelName]\n\nexport const logger = {\n debug: (...args: unknown[]) => {\n if (logLevels.debug <= activeLogLevelValue) {\n // biome-ignore lint/suspicious/noConsole: <explanation>\n console.debug(...args)\n }\n },\n info: (...args: unknown[]) => {\n if (logLevels.info <= activeLogLevelValue) {\n // biome-ignore lint/suspicious/noConsole: <explanation>\n console.info(...args)\n }\n },\n warn: (...args: unknown[]) => {\n if (logLevels.warn <= activeLogLevelValue) {\n // biome-ignore lint/suspicious/noConsole: <explanation>\n console.warn(...args)\n }\n },\n error: (...args: unknown[]) => {\n if (logLevels.error <= activeLogLevelValue) {\n // biome-ignore lint/suspicious/noConsole: <explanation>\n console.error(...args)\n }\n },\n}\n","import {\n ApiVersion,\n type GraphqlClient,\n LogSeverity,\n Session,\n shopifyApi,\n} from '@shopify/shopify-api'\nimport '@shopify/shopify-api/adapters/node'\nimport dotenv from 'dotenv'\nimport { z } from 'zod'\nimport { activeLogLevelName, logger } from './logger.js'\n\n// https://shopify.dev/docs/api/admin-graphql/2025-04/\nexport const SHOPIFY_API_VERSION = ApiVersion.April25\n\ndotenv.config()\n\nconst envSchema = z.object({\n SHOPIFY_API_KEY: z.string({\n required_error: 'SHOPIFY_API_KEY is required',\n }),\n SHOPIFY_API_SECRET: z.string({\n required_error: 'SHOPIFY_API_SECRET is required',\n }),\n SHOPIFY_API_HOSTNAME: z.string({\n required_error: 'SHOPIFY_API_HOSTNAME is required',\n }),\n SHOPIFY_ACCESS_TOKEN: z.string({\n required_error: 'SHOPIFY_ACCESS_TOKEN is required',\n }),\n NODE_ENV: z\n .enum(['development', 'production', 'test'])\n .default('development'),\n})\n\nconst mapLogLevelToShopifySeverity = (level: string): LogSeverity => {\n switch (level) {\n case 'silent':\n return LogSeverity.Error\n case 'debug':\n return LogSeverity.Debug\n case 'info':\n return LogSeverity.Info\n case 'warn':\n return LogSeverity.Warning\n case 'error':\n return LogSeverity.Error\n default:\n return LogSeverity.Info\n }\n}\n\nlet shopifyGraphqlClient: GraphqlClient\n\ntry {\n // biome-ignore lint/nursery/noProcessEnv: <explanation>\n const env = envSchema.parse(process.env)\n\n const shopify = shopifyApi({\n apiKey: env.SHOPIFY_API_KEY,\n apiSecretKey: env.SHOPIFY_API_SECRET,\n hostName: env.SHOPIFY_API_HOSTNAME,\n apiVersion: SHOPIFY_API_VERSION,\n isEmbeddedApp: false,\n logger: { level: mapLogLevelToShopifySeverity(activeLogLevelName) },\n future: {\n customerAddressDefaultFix: true,\n lineItemBilling: true,\n unstable_managedPricingSupport: false,\n },\n })\n\n const shopifySession = new Session({\n id: `custom-session-${env.SHOPIFY_API_HOSTNAME}`,\n shop: env.SHOPIFY_API_HOSTNAME,\n state: 'authenticated',\n isOnline: true,\n accessToken: env.SHOPIFY_ACCESS_TOKEN,\n })\n\n shopifyGraphqlClient = new shopify.clients.Graphql({\n session: shopifySession,\n })\n\n logger.info('Shopify API client initialized successfully.')\n} catch (error) {\n if (error instanceof z.ZodError) {\n const msg = JSON.stringify(error.format(), null, 2)\n logger.error(msg)\n } else {\n logger.error('Failed to initialize Shopify API client:', error)\n }\n throw error\n}\n\nexport { shopifyGraphqlClient as shopifyClient }\n","import { logger } from './logger.js'\nimport { shopifyClient } from './shopifyClient.js'\n\nexport function convertIdIntoGid(\n id: bigint,\n type: 'Order' | 'Customer',\n): string {\n return `gid://shopify/${type}/${id}`\n}\n\ninterface PageInfo {\n hasNextPage: boolean\n endCursor?: string | null | undefined\n}\n\ninterface ShopifyErrorWithMessage {\n message?: string\n [key: string]: unknown\n}\n\ntype TExtractorFunctionType<TResultNode, TPageData> = (pageData: TPageData) => {\n nodes: TResultNode[]\n pageInfo?: PageInfo\n userErrors?: { message?: string }[]\n}\n\nexport async function fetchShopifyGraphql<TResultNode, TPageData>(params: {\n query: string\n variables: Record<string, unknown>\n dataExtractor?: TExtractorFunctionType<TResultNode, TPageData>\n fetchAllPages?: boolean\n}): Promise<TResultNode[]>\nexport async function fetchShopifyGraphql<TReturnType>(params: {\n query: string\n variables: Record<string, unknown>\n}): Promise<TReturnType>\nexport async function fetchShopifyGraphql<\n TResultNode,\n TPageData,\n TReturnType,\n>(params: {\n query: string\n variables: Record<string, unknown>\n dataExtractor?: TExtractorFunctionType<TResultNode, TPageData>\n fetchAllPages?: boolean\n}): Promise<TResultNode[] | TReturnType> {\n const {\n query,\n variables: initialVariables,\n dataExtractor,\n fetchAllPages = false,\n } = params\n\n let currentVariables = { ...initialVariables }\n\n if (!dataExtractor) {\n return makeRequest<NonNullable<TReturnType>>(query, currentVariables)\n }\n\n const allNodes: TResultNode[] = []\n let hasNextLoop = true\n\n do {\n const response = await makeRequest<TPageData>(query, currentVariables)\n const { nodes, pageInfo, userErrors } = dataExtractor(response)\n\n // Handle Shopify mutation userErrors pattern\n if (Array.isArray(userErrors) && userErrors.length > 0) {\n const errorMessages = userErrors\n .map((e) => e.message || JSON.stringify(e))\n .join('\\n')\n logger.error('Shopify mutation userErrors:', errorMessages)\n throw new Error(`Shopify mutation userErrors: ${errorMessages}`)\n }\n\n allNodes.push(...nodes)\n\n hasNextLoop = fetchAllPages ? !!pageInfo?.hasNextPage : false\n if (hasNextLoop && pageInfo?.endCursor) {\n currentVariables = {\n ...currentVariables,\n after: pageInfo.endCursor,\n }\n }\n } while (hasNextLoop)\n\n return allNodes\n}\n\nasync function makeRequest<TReturnDataType>(\n query: string,\n variables: Record<string, unknown>,\n): Promise<NonNullable<TReturnDataType>> {\n type ShopifyRequestErrorType = {\n errors?: ShopifyErrorWithMessage | ShopifyErrorWithMessage[]\n }\n\n const response = (await shopifyClient.request<TReturnDataType>(query, {\n variables,\n })) as { data?: TReturnDataType } & ShopifyRequestErrorType\n\n if (response.errors) {\n let errorMessages = 'GraphQL query failed.'\n const errors = response.errors\n if (Array.isArray(errors)) {\n errorMessages = errors\n .map((e: ShopifyErrorWithMessage) => e.message || JSON.stringify(e))\n .join('\\n')\n } else if (\n typeof errors === 'object' &&\n errors !== null &&\n 'message' in errors\n ) {\n errorMessages = errors.message || JSON.stringify(errors)\n } else if (typeof errors === 'string') {\n errorMessages = errors\n } else {\n errorMessages = JSON.stringify(errors)\n }\n logger.error('GraphQL query failed:', errorMessages)\n throw new Error(`GraphQL errors: ${errorMessages}`)\n }\n\n if (!response.data) {\n throw new Error('No data in Shopify API response')\n }\n\n return response.data\n}\n","import z from 'zod'\nimport { logger } from './logger.js'\n\nexport async function returnOutputParsed<T>(\n data: unknown,\n Model: z.ZodType<T>,\n) {\n const parsed = await Model.safeParseAsync(data)\n if (!parsed.success) {\n if (parsed.error instanceof z.ZodError) {\n const msg = JSON.stringify(parsed.error.format(), null, 2)\n logger.error(msg)\n } else {\n logger.error('Failed to parse:', parsed.error)\n }\n // throw parsedVariants.error\n throw new Error('Failed to parse product variants')\n }\n logger.info('Parsed data successfully')\n return parsed.data\n}\n","import z from 'zod'\nimport type {\n OrderByIdFullQuery,\n OrderByIdQuery,\n OrderByIdQueryVariables,\n} from '../../generated-api-types/2025-04/admin.generated.js'\nimport { logger } from '../../utils/logger.js'\nimport {\n convertIdIntoGid,\n fetchShopifyGraphql,\n} from '../../utils/shopifyFetch.js'\nimport { returnOutputParsed } from '../../utils/zod.js'\nimport { queryOrderById, queryOrderByIdFull } from './getOrderById.queries.js'\n\n// Address schema (shared between lean and full)\nconst AddressSchema = z\n .object({\n firstName: z.string().nullable(),\n lastName: z.string().nullable(),\n address1: z.string().nullable(),\n address2: z.string().nullable(),\n city: z.string().nullable(),\n province: z.string().nullable(),\n country: z.string().nullable(),\n zip: z.string().nullable(),\n })\n .nullable()\n\n// Lean order schema\nconst GetLeanOrderByIdReturn = z\n .object({\n id: z.string(),\n name: z.string(),\n createdAt: z.string(),\n updatedAt: z.string(),\n cancelledAt: z.string().nullable(),\n cancelReason: z.string().nullable(),\n totalPrice: z.object({\n amount: z.string(),\n currencyCode: z.string(),\n }),\n customer: z\n .object({\n id: z.string(),\n displayName: z.string(),\n firstName: z.string().nullable(),\n lastName: z.string().nullable(),\n emailAddress: z.string().nullable(),\n })\n .nullable(),\n financialStatus: z.string().nullable(),\n fulfillmentStatus: z.string().nullable(),\n shippingAddress: AddressSchema,\n })\n .nullable()\n\nexport type LeanOrder = z.infer<typeof GetLeanOrderByIdReturn>\n\n// Full order type - derived from the generated GraphQL types\nexport type FullOrder = NonNullable<OrderByIdFullQuery['order']> | null\n\ntype OrderDetailLevel = 'lean' | 'full'\n\n// Function overloads\nexport function getOrderById(id: bigint): Promise<LeanOrder>\nexport function getOrderById(id: bigint, detailLevel: 'lean'): Promise<LeanOrder>\nexport function getOrderById(id: bigint, detailLevel: 'full'): Promise<FullOrder>\n\n/**\n * Retrieves a single order from Shopify by its numeric ID.\n * Returns null if no order is found with the specified ID.\n *\n * @param {bigint} id - The numerical Shopify order ID (e.g., 12345678n).\n * @param {OrderDetailLevel} detailLevel - The level of detail to return ('lean' or 'full'). Defaults to 'lean'.\n * @returns {Promise<LeanOrder | FullOrder>} A promise that resolves to the order data or null if not found.\n * @throws {Error} If the GraphQL query fails or if the response structure is invalid.\n */\nexport async function getOrderById(\n id: bigint,\n detailLevel: OrderDetailLevel = 'lean',\n): Promise<LeanOrder | FullOrder> {\n if (detailLevel === 'lean') {\n return getLeanOrderById(id)\n }\n return getFullOrderById(id)\n}\n\nasync function getLeanOrderById(id: bigint): Promise<LeanOrder> {\n const variables: OrderByIdQueryVariables = {\n id: convertIdIntoGid(id, 'Order'),\n }\n\n const response = await fetchShopifyGraphql<OrderByIdQuery>({\n query: queryOrderById,\n variables,\n })\n\n if (!response.order) {\n logger.debug(`No order found with ID: ${id}`)\n return null\n }\n\n const order = response.order\n\n const leanOrder = {\n id: order.id,\n name: order.name,\n createdAt: order.createdAt,\n updatedAt: order.updatedAt,\n cancelledAt: order.cancelledAt ?? null,\n cancelReason: order.cancelReason ?? null,\n totalPrice: {\n amount: order.totalPriceSet?.shopMoney?.amount ?? '',\n currencyCode: order.totalPriceSet?.shopMoney?.currencyCode ?? '',\n },\n customer: order.customer\n ? {\n id: order.customer.id,\n displayName: order.customer.displayName,\n firstName: order.customer.firstName ?? null,\n lastName: order.customer.lastName ?? null,\n emailAddress:\n order.customer.defaultEmailAddress?.emailAddress ?? null,\n }\n : null,\n financialStatus: order.displayFinancialStatus ?? null,\n fulfillmentStatus: order.displayFulfillmentStatus ?? null,\n shippingAddress: order.shippingAddress\n ? {\n firstName: order.shippingAddress.firstName ?? null,\n lastName: order.shippingAddress.lastName ?? null,\n address1: order.shippingAddress.address1 ?? null,\n address2: order.shippingAddress.address2 ?? null,\n city: order.shippingAddress.city ?? null,\n province: order.shippingAddress.province ?? null,\n country: order.shippingAddress.country ?? null,\n zip: order.shippingAddress.zip ?? null,\n }\n : null,\n }\n\n return await returnOutputParsed(leanOrder, GetLeanOrderByIdReturn)\n}\n\nasync function getFullOrderById(id: bigint): Promise<FullOrder> {\n const variables: OrderByIdQueryVariables = {\n id: convertIdIntoGid(id, 'Order'),\n }\n\n const response = await fetchShopifyGraphql<OrderByIdFullQuery>({\n query: queryOrderByIdFull,\n variables,\n })\n\n if (!response.order) {\n logger.debug(`No order found with ID: ${id}`)\n return null\n }\n\n return response.order\n}\n","import { gql } from '../../utils/logger'\n\nexport const queryOrderById = gql`#graphql\n query orderById($id: ID!) {\n order(id: $id) {\n id\n name\n createdAt\n updatedAt\n cancelledAt\n cancelReason\n totalPriceSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n customer {\n id\n lastName\n defaultEmailAddress {\n emailAddress\n }\n displayName\n firstName\n }\n displayFinancialStatus\n displayFulfillmentStatus\n shippingAddress {\n firstName\n lastName\n address1\n address2\n city\n province\n country\n zip\n }\n }\n }\n`\n\nexport const queryOrderByIdFull = gql`#graphql\n query orderByIdFull($id: ID!) {\n order(id: $id) {\n id\n name\n createdAt\n updatedAt\n processedAt\n closedAt\n cancelledAt\n cancelReason\n totalPriceSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n customer {\n id\n lastName\n defaultEmailAddress {\n emailAddress\n }\n displayName\n firstName\n phone\n }\n displayFinancialStatus\n displayFulfillmentStatus\n shippingAddress {\n firstName\n lastName\n address1\n address2\n city\n province\n country\n zip\n }\n billingAddress {\n firstName\n lastName\n address1\n address2\n city\n province\n country\n zip\n }\n lineItems(first: 100) {\n edges {\n node {\n id\n sku\n title\n variantTitle\n quantity\n customAttributes {\n key\n value\n }\n originalUnitPriceSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n vendor\n image {\n url\n width\n height\n altText\n }\n }\n }\n }\n fulfillments {\n id\n name\n totalQuantity\n status\n createdAt\n estimatedDeliveryAt\n deliveredAt\n trackingInfo {\n company\n number\n url\n }\n fulfillmentLineItems(first: 100) {\n edges {\n node {\n id\n quantity\n lineItem {\n id\n }\n }\n }\n }\n }\n shippingLine {\n originalPriceSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n }\n taxLines {\n priceSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n }\n totalDiscountsSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n discountCodes\n refunds {\n totalRefundedSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n }\n }\n }\n`\n","import z from 'zod'\nimport type {\n OrdersByNameFullQuery,\n OrdersByNameQuery,\n OrdersByNameQueryVariables,\n} from '../../generated-api-types/2025-04/admin.generated.js'\nimport { logger } from '../../utils/logger.js'\nimport { fetchShopifyGraphql } from '../../utils/shopifyFetch.js'\nimport { returnOutputParsed } from '../../utils/zod.js'\nimport {\n queryOrdersByName,\n queryOrdersByNameFull,\n} from './getOrderByName.queries.js'\n\nconst GetLeanOrderByNameReturn = z\n .object({\n id: z.string(),\n name: z.string(),\n createdAt: z.string(),\n updatedAt: z.string(),\n totalPrice: z.object({\n amount: z.string(),\n currencyCode: z.string(),\n }),\n customer: z\n .object({\n id: z.string(),\n displayName: z.string(),\n emailAddress: z.string().nullable(),\n })\n .nullable(),\n financialStatus: z.string().nullable(),\n fulfillmentStatus: z.string().nullable(),\n })\n .nullable()\n\ntype GetLeanOrderByNameReturnType = z.infer<typeof GetLeanOrderByNameReturn>\n\ntype GetFullOrderByNameReturnType = NonNullable<\n NonNullable<OrdersByNameFullQuery['orders']>['edges'][number]['node']\n> | null\n\ntype OrderDetailLevel = 'lean' | 'full'\n\n// Function overloads\nexport function getOrderByName(\n orderName: string,\n detailLevel: 'lean',\n): Promise<GetLeanOrderByNameReturnType>\nexport function getOrderByName(\n orderName: string,\n detailLevel: 'full',\n): Promise<GetFullOrderByNameReturnType>\nexport function getOrderByName(\n orderName: string,\n): Promise<GetLeanOrderByNameReturnType>\n\n/**\n * Retrieves a single order from Shopify by its order name (e.g., \"B12345\").\n * Returns null if no order is found with the specified name.\n *\n * @param {string} orderName - The order name to search for (e.g., \"B12345\").\n * @param {OrderDetailLevel} detailLevel - The level of detail to return ('lean' or 'full'). Defaults to 'lean'.\n * @returns {Promise<GetLeanOrderByNameReturnType | GetFullOrderByNameReturnType>} A promise that resolves to the order data or null if not found.\n * @throws {Error} If the GraphQL query fails or if the response structure is invalid.\n */\nexport async function getOrderByName(\n orderName: string,\n detailLevel: OrderDetailLevel = 'lean',\n): Promise<GetLeanOrderByNameReturnType | GetFullOrderByNameReturnType> {\n if (detailLevel === 'lean') {\n return getLeanOrderByName(orderName)\n }\n return getFullOrderByName(orderName)\n}\n\nasync function getLeanOrderByName(\n orderName: string,\n): Promise<GetLeanOrderByNameReturnType> {\n const variables: OrdersByNameQueryVariables = {\n first: 1,\n queryFilter: `name:${orderName}`,\n }\n\n type SingleNode = NonNullable<\n NonNullable<OrdersByNameQuery['orders']>['edges'][number]['node']\n >\n\n const extractedNodes = await fetchShopifyGraphql<\n SingleNode,\n OrdersByNameQuery\n >({\n query: queryOrdersByName,\n variables,\n dataExtractor: (pageData: OrdersByNameQuery) => {\n if (!pageData.orders) {\n throw new Error(\n \"GraphQL response for orders is missing the 'orders' field.\",\n )\n }\n const nodes: SingleNode[] = pageData.orders.edges.map(\n (edge: { node: SingleNode }) => edge.node,\n )\n return {\n nodes,\n }\n },\n fetchAllPages: false,\n })\n\n const order = extractedNodes[0]\n if (!order) {\n logger.debug(`No order found with name: ${orderName}`)\n return null\n }\n\n const leanOrder = {\n id: order.id,\n name: order.name,\n createdAt: order.createdAt,\n updatedAt: order.updatedAt,\n totalPrice: {\n amount: order.totalPriceSet?.shopMoney?.amount ?? '',\n currencyCode: order.totalPriceSet?.shopMoney?.currencyCode ?? '',\n },\n customer: order.customer\n ? {\n id: order.customer.id,\n displayName: order.customer.displayName,\n emailAddress:\n order.customer.defaultEmailAddress?.emailAddress ?? null,\n }\n : null,\n financialStatus: order.displayFinancialStatus ?? null,\n fulfillmentStatus: order.displayFulfillmentStatus ?? null,\n }\n\n return await returnOutputParsed(leanOrder, GetLeanOrderByNameReturn)\n}\n\nasync function getFullOrderByName(\n orderName: string,\n): Promise<GetFullOrderByNameReturnType> {\n const variables: OrdersByNameQueryVariables = {\n first: 1,\n queryFilter: `name:${orderName}`,\n }\n\n type SingleNode = NonNullable<\n NonNullable<OrdersByNameFullQuery['orders']>['edges'][number]['node']\n >\n\n const extractedNodes = await fetchShopifyGraphql<\n SingleNode,\n OrdersByNameFullQuery\n >({\n query: queryOrdersByNameFull,\n variables,\n dataExtractor: (pageData: OrdersByNameFullQuery) => {\n if (!pageData.orders) {\n throw new Error(\n \"GraphQL response for orders is missing the 'orders' field.\",\n )\n }\n const nodes: SingleNode[] = pageData.orders.edges.map(\n (edge: { node: SingleNode }) => edge.node,\n )\n return {\n nodes,\n }\n },\n fetchAllPages: false,\n })\n\n if (extractedNodes.length === 0) {\n logger.debug(`No order found with name: ${orderName}`)\n return null\n }\n\n const order = extractedNodes[0]\n if (!order) {\n logger.debug(`No order found with name: ${orderName}`)\n return null\n }\n\n return order\n}\n","import { gql } from '../../utils/logger'\n\nexport const queryOrdersByName = gql`#graphql\n query ordersByName($first: Int!, $queryFilter: String!) {\n orders(first: $first, query: $queryFilter) {\n edges {\n node {\n id\n name\n createdAt\n updatedAt\n totalPriceSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n customer {\n id\n lastName\n defaultEmailAddress {\n emailAddress\n }\n displayName\n firstName\n }\n displayFinancialStatus\n displayFulfillmentStatus\n }\n }\n pageInfo {\n hasNextPage\n endCursor\n }\n }\n }\n`\n\nexport const queryOrdersByNameFull = gql`#graphql\n query ordersByNameFull($first: Int!, $queryFilter: String!) {\n orders(first: $first, query: $queryFilter) {\n edges {\n node {\n billingAddress {\n address1\n address2\n city\n company\n country\n countryCodeV2\n firstName\n formattedArea\n id\n lastName\n name\n phone\n province\n provinceCode\n timeZone\n zip\n }\n billingAddressMatchesShippingAddress\n cancelReason\n cancellation {\n staffNote\n }\n cancelledAt\n capturable\n clientIp\n closed\n closedAt\n confirmed\n createdAt\n currencyCode\n currentCartDiscountAmountSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n currentShippingPriceSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n currentSubtotalLineItemsQuantity\n currentSubtotalPriceSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n currentTaxLines {\n channelLiable\n rate\n ratePercentage\n source\n title\n priceSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n }\n currentTotalAdditionalFeesSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n currentTotalDiscountsSet {\n presentmentMoney {\n amount\n currencyCode\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n currentTotalDutiesSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n currentTotalPriceSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n currentTotalTaxSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n currentTotalWeight\n customer {\n id\n lastName\n defaultEmailAddress {\n emailAddress\n }\n displayName\n firstName\n }\n customerAcceptsMarketing\n discountCodes\n discountCode\n displayAddress {\n address1\n address2\n city\n company\n country\n countryCodeV2\n firstName\n formattedArea\n id\n lastName\n name\n phone\n province\n provinceCode\n timeZone\n zip\n }\n displayFinancialStatus\n displayFulfillmentStatus\n dutiesIncluded\n edited\n email\n estimatedTaxes\n fulfillable\n fulfillments(first: 20) {\n createdAt\n deliveredAt\n displayStatus\n estimatedDeliveryAt\n updatedAt\n trackingInfo(first: 10) {\n company\n url\n }\n totalQuantity\n status\n name\n id\n }\n fullyPaid\n id\n lineItems(first: 50) {\n edges {\n node {\n id\n name\n originalUnitPriceSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n quantity\n requiresShipping\n sku\n title\n variantTitle\n }\n }\n }\n name\n note\n processedAt\n shippingAddress {\n address1\n address2\n city\n company\n country\n countryCodeV2\n firstName\n formattedArea\n id\n lastName\n name\n phone\n province\n provinceCode\n timeZone\n zip\n }\n statusPageUrl\n tags\n totalPriceSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n totalReceivedSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n totalRefundedSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n totalShippingPriceSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n totalTaxSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n totalWeight\n unpaid\n updatedAt\n }\n }\n pageInfo {\n hasNextPage\n endCursor\n }\n }\n }\n`\n","import z from 'zod'\nimport type {\n LeanProductVariantsQuery,\n LeanProductVariantsQueryVariables,\n} from '../../generated-api-types/2025-04/admin.generated.js'\nimport { gql, logger } from '../../utils/logger.js'\nimport { fetchShopifyGraphql } from '../../utils/shopifyFetch.js'\nimport { returnOutputParsed } from '../../utils/zod.js'\n\nconst GetLeanProductVariantsReturn = z.array(\n z.object({\n productId: z.string(),\n productTitle: z.string(),\n variantId: z.string(),\n variantTitle: z.string(),\n sku: z.string(),\n }),\n)\n\ntype GetLeanProductVariantsReturnType = z.infer<\n typeof GetLeanProductVariantsReturn\n>\n\n/**\n * Retrieves a lean list of product variants from Shopify, optionally filtered by SKUs.\n * Product variants are mapped to a simpler output structure.\n * Variants missing essential properties (e.g., SKU) will be filtered out and logged.\n *\n * @param {string[]} [skus] - An optional array of SKUs to filter by. If provided, only variants matching these SKUs will be fetched.\n * @returns {Promise<GetLeanProductVariantsReturnType>} A promise that resolves to an array of lean product variant data.\n * @throws {Error} If the GraphQL query fails, returns no data, or if the `productVariants` field is missing in the response.\n */\nexport async function getLeanProductVariants(\n skus?: string[],\n): Promise<GetLeanProductVariantsReturnType> {\n const queryGql = gql`#graphql\n query leanProductVariants($first: Int!, $after: String, $queryFilter: String) {\n productVariants(first: $first, after: $after, query: $queryFilter) {\n edges {\n node { \n id\n title\n sku\n product {\n id\n title\n }\n }\n }\n pageInfo { \n hasNextPage\n endCursor\n }\n }\n }\n `\n\n const initialVariables: LeanProductVariantsQueryVariables = { first: 250 }\n if (skus && skus.length > 0) {\n initialVariables.queryFilter = skus\n .map((sku: string) => `sku:${sku}`)\n .join(' OR ')\n }\n\n // Type for a single node from the productVariants query\n type SingleNode = NonNullable<\n NonNullable<\n LeanProductVariantsQuery['productVariants']\n >['edges'][number]['node']\n >\n\n const extractedNodes = await fetchShopifyGraphql<\n SingleNode,\n LeanProductVariantsQuery\n >({\n query: queryGql,\n variables: initialVariables,\n dataExtractor: (pageData: LeanProductVariantsQuery) => {\n if (!pageData.productVariants) {\n throw new Error(\n \"GraphQL response for product variants is missing the 'productVariants' field.\",\n )\n }\n const nodes: SingleNode[] = pageData.productVariants.edges.map(\n (edge: { node: SingleNode }) => edge.node,\n )\n return {\n nodes,\n pageInfo: pageData.productVariants.pageInfo,\n }\n },\n fetchAllPages: true,\n })\n\n const allVariants = extractedNodes.flatMap<\n GetLeanProductVariantsReturnType[number]\n >((v) => {\n if (v.sku) {\n return [\n {\n productId: v.product.id,\n productTitle: v.product.title,\n variantId: v.id,\n variantTitle: v.title,\n sku: v.sku,\n },\n ]\n }\n logger.debug(\n `Product ${v.product.title} (ID: ${v.product.id}) has a variant (ID: ${v.id}) with no SKU. Filtering out.`,\n )\n return []\n })\n\n return await returnOutputParsed(allVariants, GetLeanProductVariantsReturn)\n}\n","import z from 'zod'\nimport type {\n OrderPaymentDetailsByIdQuery,\n OrderPaymentDetailsByIdQueryVariables,\n} from '../../generated-api-types/2025-04/admin.generated.js'\nimport { logger } from '../../utils/logger.js'\nimport {\n convertIdIntoGid,\n fetchShopifyGraphql,\n} from '../../utils/shopifyFetch.js'\nimport { returnOutputParsed } from '../../utils/zod.js'\nimport { queryOrderPaymentDetails } from './getOrderPaymentDetails.queries.js'\n\nconst GetOrderPaymentDetailsByIdReturn = z.object({\n order: z.object({\n transactions: z.array(\n z.object({\n amountSet: z.object({\n shopMoney: z.object({\n amount: z.string(),\n currencyCode: z.string(),\n }),\n }),\n createdAt: z.string(),\n gateway: z.string(),\n formattedGateway: z.string(),\n kind: z.string(),\n paymentId: z.string(),\n }),\n ),\n }),\n})\n\ntype GetOrderPaymentDetailsByIdReturnType = z.infer<\n typeof GetOrderPaymentDetailsByIdReturn\n>\n\n/**\n * Retrieves payment details for a single order from Shopify by its ID.\n * Returns null if no order is found with the specified ID.\n *\n * @param {bigint} id - The numerical Shopify order ID (e.g., 12345678n).\n * @returns {Promise<GetOrderPaymentDetailsByIdReturnType | null>} A promise that resolves to the order payment data or null if not found.\n * @throws {Error} If the GraphQL query fails or if the response structure is invalid.\n */\nexport async function getOrderPaymentDetailsById(\n id: bigint,\n): Promise<GetOrderPaymentDetailsByIdReturnType | null> {\n const variables: OrderPaymentDetailsByIdQueryVariables = {\n id: convertIdIntoGid(id, 'Order'),\n }\n\n const response = await fetchShopifyGraphql<OrderPaymentDetailsByIdQuery>({\n query: queryOrderPaymentDetails,\n variables,\n })\n\n if (!response.order) {\n logger.debug(`No order found with ID: ${id}`)\n return null\n }\n\n return await returnOutputParsed(response, GetOrderPaymentDetailsByIdReturn)\n}\n","import { gql } from '../../utils/logger.js'\n\nexport const queryOrderPaymentDetails = gql`#graphql\n query orderPaymentDetailsById($id: ID!) {\n order(id: $id) {\n transactions {\n amountSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n createdAt\n gateway\n formattedGateway\n kind\n paymentId\n }\n }\n }\n`\n"],"mappings":";AAAA,OAAOA,QAAO;;;ACAd,IAAM,EAAE,IAAI,IAAI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AAM,2BAA2B,EAAE,EAAE;AAC5C,WAAO;AAAA,EACT;AAEA,SAAO,MAAM,mBAAmB,UAAU,gCAAgC;AAC5E;","names":["z","env","z","z","z","z","z","z","z","z","z","z","z"]}
1
+ {"version":3,"sources":["../src/mutations/customers/deleteCustomerById.ts","../src/utils/logger.ts","../src/utils/shopifyClient.ts","../src/utils/shopifyFetch.ts","../src/utils/zod.ts","../src/queries/orders/getOrderById.ts","../src/queries/orders/getOrderById.queries.ts","../src/queries/orders/getOrderByName.ts","../src/queries/orders/getOrderByName.queries.ts","../src/queries/productVariants/getLeanProductVariants.ts","../src/queries/orders/getOrderPaymentDetails.ts","../src/queries/orders/getOrderPaymentDetails.queries.ts","../src/utils/toRestFormat.ts","../src/utils/parseGid.ts"],"sourcesContent":["import z from 'zod'\nimport type {\n CustomerDeleteMutation,\n CustomerDeleteMutationVariables,\n} from '../../generated-api-types/2025-04/admin.generated'\nimport { gql } from '../../utils/logger'\nimport { fetchShopifyGraphql } from '../../utils/shopifyFetch'\nimport { returnOutputParsed } from '../../utils/zod'\n\nexport const DeleteCustomerByIdReturn = z.string().nullable()\n\ntype SingleNode = { deletedCustomerId: string | null }\n\nexport async function deleteCustomerById(\n customerId: string,\n): Promise<z.infer<typeof DeleteCustomerByIdReturn>> {\n const mutation = gql`#graphql\n mutation customerDelete($input: CustomerDeleteInput!) {\n customerDelete(input: $input) {\n deletedCustomerId\n userErrors {\n field\n message\n }\n }\n }\n `\n\n const variables: CustomerDeleteMutationVariables = {\n input: { id: customerId },\n }\n\n const response = await fetchShopifyGraphql<\n SingleNode,\n CustomerDeleteMutation\n >({\n query: mutation,\n variables,\n dataExtractor: (data: CustomerDeleteMutation) => {\n if (!data.customerDelete) {\n throw new Error(\"GraphQL response missing 'customerDelete' field\")\n }\n return {\n nodes: [\n { deletedCustomerId: data.customerDelete.deletedCustomerId ?? null },\n ],\n userErrors: data.customerDelete.userErrors,\n }\n },\n })\n\n return returnOutputParsed(\n response[0]?.deletedCustomerId ?? null,\n DeleteCustomerByIdReturn,\n )\n}\n","const { env } = process\n\nexport const gql = String.raw\n\nconst logLevels = {\n silent: 0,\n error: 1,\n warn: 2,\n info: 3,\n debug: 4,\n} as const\n\ntype LogLevelName = keyof typeof logLevels\n\nfunction getLogLevel(\n nodeEnv: string | undefined,\n logLevelEnv: string | undefined,\n): LogLevelName {\n if (logLevelEnv && logLevelEnv in logLevels) {\n return logLevelEnv as LogLevelName\n }\n\n if (nodeEnv === 'test') {\n return 'silent'\n }\n\n if (nodeEnv === 'production') {\n return 'info'\n }\n return 'debug'\n}\n\nexport const activeLogLevelName = getLogLevel(env.NODE_ENV, env.LOG_LEVEL)\nconst activeLogLevelValue = logLevels[activeLogLevelName]\n\nexport const logger = {\n debug: (...args: unknown[]) => {\n if (logLevels.debug <= activeLogLevelValue) {\n // biome-ignore lint/suspicious/noConsole: <explanation>\n console.debug(...args)\n }\n },\n info: (...args: unknown[]) => {\n if (logLevels.info <= activeLogLevelValue) {\n // biome-ignore lint/suspicious/noConsole: <explanation>\n console.info(...args)\n }\n },\n warn: (...args: unknown[]) => {\n if (logLevels.warn <= activeLogLevelValue) {\n // biome-ignore lint/suspicious/noConsole: <explanation>\n console.warn(...args)\n }\n },\n error: (...args: unknown[]) => {\n if (logLevels.error <= activeLogLevelValue) {\n // biome-ignore lint/suspicious/noConsole: <explanation>\n console.error(...args)\n }\n },\n}\n","import {\n ApiVersion,\n type GraphqlClient,\n LogSeverity,\n Session,\n shopifyApi,\n} from '@shopify/shopify-api'\nimport '@shopify/shopify-api/adapters/node'\nimport dotenv from 'dotenv'\nimport { z } from 'zod'\nimport { activeLogLevelName, logger } from './logger.js'\n\n// https://shopify.dev/docs/api/admin-graphql/2025-04/\nexport const SHOPIFY_API_VERSION = ApiVersion.April25\n\ndotenv.config()\n\nconst envSchema = z.object({\n SHOPIFY_API_KEY: z.string({\n required_error: 'SHOPIFY_API_KEY is required',\n }),\n SHOPIFY_API_SECRET: z.string({\n required_error: 'SHOPIFY_API_SECRET is required',\n }),\n SHOPIFY_API_HOSTNAME: z.string({\n required_error: 'SHOPIFY_API_HOSTNAME is required',\n }),\n SHOPIFY_ACCESS_TOKEN: z.string({\n required_error: 'SHOPIFY_ACCESS_TOKEN is required',\n }),\n NODE_ENV: z\n .enum(['development', 'production', 'test'])\n .default('development'),\n})\n\nconst mapLogLevelToShopifySeverity = (level: string): LogSeverity => {\n switch (level) {\n case 'silent':\n return LogSeverity.Error\n case 'debug':\n return LogSeverity.Debug\n case 'info':\n return LogSeverity.Info\n case 'warn':\n return LogSeverity.Warning\n case 'error':\n return LogSeverity.Error\n default:\n return LogSeverity.Info\n }\n}\n\nlet shopifyGraphqlClient: GraphqlClient\n\ntry {\n // biome-ignore lint/nursery/noProcessEnv: <explanation>\n const env = envSchema.parse(process.env)\n\n const shopify = shopifyApi({\n apiKey: env.SHOPIFY_API_KEY,\n apiSecretKey: env.SHOPIFY_API_SECRET,\n hostName: env.SHOPIFY_API_HOSTNAME,\n apiVersion: SHOPIFY_API_VERSION,\n isEmbeddedApp: false,\n logger: { level: mapLogLevelToShopifySeverity(activeLogLevelName) },\n future: {\n customerAddressDefaultFix: true,\n lineItemBilling: true,\n unstable_managedPricingSupport: false,\n },\n })\n\n const shopifySession = new Session({\n id: `custom-session-${env.SHOPIFY_API_HOSTNAME}`,\n shop: env.SHOPIFY_API_HOSTNAME,\n state: 'authenticated',\n isOnline: true,\n accessToken: env.SHOPIFY_ACCESS_TOKEN,\n })\n\n shopifyGraphqlClient = new shopify.clients.Graphql({\n session: shopifySession,\n })\n\n logger.info('Shopify API client initialized successfully.')\n} catch (error) {\n if (error instanceof z.ZodError) {\n const msg = JSON.stringify(error.format(), null, 2)\n logger.error(msg)\n } else {\n logger.error('Failed to initialize Shopify API client:', error)\n }\n throw error\n}\n\nexport { shopifyGraphqlClient as shopifyClient }\n","import { logger } from './logger.js'\nimport { shopifyClient } from './shopifyClient.js'\n\nexport function convertIdIntoGid(\n id: bigint,\n type: 'Order' | 'Customer',\n): string {\n return `gid://shopify/${type}/${id}`\n}\n\ninterface PageInfo {\n hasNextPage: boolean\n endCursor?: string | null | undefined\n}\n\ninterface ShopifyErrorWithMessage {\n message?: string\n [key: string]: unknown\n}\n\ntype TExtractorFunctionType<TResultNode, TPageData> = (pageData: TPageData) => {\n nodes: TResultNode[]\n pageInfo?: PageInfo\n userErrors?: { message?: string }[]\n}\n\nexport async function fetchShopifyGraphql<TResultNode, TPageData>(params: {\n query: string\n variables: Record<string, unknown>\n dataExtractor?: TExtractorFunctionType<TResultNode, TPageData>\n fetchAllPages?: boolean\n}): Promise<TResultNode[]>\nexport async function fetchShopifyGraphql<TReturnType>(params: {\n query: string\n variables: Record<string, unknown>\n}): Promise<TReturnType>\nexport async function fetchShopifyGraphql<\n TResultNode,\n TPageData,\n TReturnType,\n>(params: {\n query: string\n variables: Record<string, unknown>\n dataExtractor?: TExtractorFunctionType<TResultNode, TPageData>\n fetchAllPages?: boolean\n}): Promise<TResultNode[] | TReturnType> {\n const {\n query,\n variables: initialVariables,\n dataExtractor,\n fetchAllPages = false,\n } = params\n\n let currentVariables = { ...initialVariables }\n\n if (!dataExtractor) {\n return makeRequest<NonNullable<TReturnType>>(query, currentVariables)\n }\n\n const allNodes: TResultNode[] = []\n let hasNextLoop = true\n\n do {\n const response = await makeRequest<TPageData>(query, currentVariables)\n const { nodes, pageInfo, userErrors } = dataExtractor(response)\n\n // Handle Shopify mutation userErrors pattern\n if (Array.isArray(userErrors) && userErrors.length > 0) {\n const errorMessages = userErrors\n .map((e) => e.message || JSON.stringify(e))\n .join('\\n')\n logger.error('Shopify mutation userErrors:', errorMessages)\n throw new Error(`Shopify mutation userErrors: ${errorMessages}`)\n }\n\n allNodes.push(...nodes)\n\n hasNextLoop = fetchAllPages ? !!pageInfo?.hasNextPage : false\n if (hasNextLoop && pageInfo?.endCursor) {\n currentVariables = {\n ...currentVariables,\n after: pageInfo.endCursor,\n }\n }\n } while (hasNextLoop)\n\n return allNodes\n}\n\nasync function makeRequest<TReturnDataType>(\n query: string,\n variables: Record<string, unknown>,\n): Promise<NonNullable<TReturnDataType>> {\n type ShopifyRequestErrorType = {\n errors?: ShopifyErrorWithMessage | ShopifyErrorWithMessage[]\n }\n\n const response = (await shopifyClient.request<TReturnDataType>(query, {\n variables,\n })) as { data?: TReturnDataType } & ShopifyRequestErrorType\n\n if (response.errors) {\n let errorMessages = 'GraphQL query failed.'\n const errors = response.errors\n if (Array.isArray(errors)) {\n errorMessages = errors\n .map((e: ShopifyErrorWithMessage) => e.message || JSON.stringify(e))\n .join('\\n')\n } else if (\n typeof errors === 'object' &&\n errors !== null &&\n 'message' in errors\n ) {\n errorMessages = errors.message || JSON.stringify(errors)\n } else if (typeof errors === 'string') {\n errorMessages = errors\n } else {\n errorMessages = JSON.stringify(errors)\n }\n logger.error('GraphQL query failed:', errorMessages)\n throw new Error(`GraphQL errors: ${errorMessages}`)\n }\n\n if (!response.data) {\n throw new Error('No data in Shopify API response')\n }\n\n return response.data\n}\n","import z from 'zod'\nimport { logger } from './logger.js'\n\nexport async function returnOutputParsed<T>(\n data: unknown,\n Model: z.ZodType<T>,\n) {\n const parsed = await Model.safeParseAsync(data)\n if (!parsed.success) {\n if (parsed.error instanceof z.ZodError) {\n const msg = JSON.stringify(parsed.error.format(), null, 2)\n logger.error(msg)\n } else {\n logger.error('Failed to parse:', parsed.error)\n }\n // throw parsedVariants.error\n throw new Error('Failed to parse product variants')\n }\n logger.info('Parsed data successfully')\n return parsed.data\n}\n","import z from 'zod'\nimport type {\n OrderByIdFullQuery,\n OrderByIdQuery,\n OrderByIdQueryVariables,\n} from '../../generated-api-types/2025-04/admin.generated.js'\nimport { logger } from '../../utils/logger.js'\nimport {\n convertIdIntoGid,\n fetchShopifyGraphql,\n} from '../../utils/shopifyFetch.js'\nimport { returnOutputParsed } from '../../utils/zod.js'\nimport { queryOrderById, queryOrderByIdFull } from './getOrderById.queries.js'\n\n// Address schema (shared between lean and full)\nconst AddressSchema = z\n .object({\n firstName: z.string().nullable(),\n lastName: z.string().nullable(),\n address1: z.string().nullable(),\n address2: z.string().nullable(),\n city: z.string().nullable(),\n province: z.string().nullable(),\n country: z.string().nullable(),\n zip: z.string().nullable(),\n })\n .nullable()\n\n// Lean order schema\nconst GetLeanOrderByIdReturn = z\n .object({\n id: z.string(),\n name: z.string(),\n createdAt: z.string(),\n updatedAt: z.string(),\n cancelledAt: z.string().nullable(),\n cancelReason: z.string().nullable(),\n totalPrice: z.object({\n amount: z.string(),\n currencyCode: z.string(),\n }),\n customer: z\n .object({\n id: z.string(),\n displayName: z.string(),\n firstName: z.string().nullable(),\n lastName: z.string().nullable(),\n emailAddress: z.string().nullable(),\n })\n .nullable(),\n financialStatus: z.string().nullable(),\n fulfillmentStatus: z.string().nullable(),\n shippingAddress: AddressSchema,\n })\n .nullable()\n\nexport type LeanOrder = z.infer<typeof GetLeanOrderByIdReturn>\n\n// Full order type - derived from the generated GraphQL types\nexport type FullOrder = NonNullable<OrderByIdFullQuery['order']> | null\n\ntype OrderDetailLevel = 'lean' | 'full'\n\n// Function overloads\nexport function getOrderById(id: number | bigint): Promise<LeanOrder>\nexport function getOrderById(\n id: number | bigint,\n detailLevel: 'lean',\n): Promise<LeanOrder>\nexport function getOrderById(\n id: number | bigint,\n detailLevel: 'full',\n): Promise<FullOrder>\n\n/**\n * Retrieves a single order from Shopify by its numeric ID.\n * Returns null if no order is found with the specified ID.\n *\n * @param {number | bigint} id - The numerical Shopify order ID (e.g., 12345678 or 12345678n).\n * @param {OrderDetailLevel} detailLevel - The level of detail to return ('lean' or 'full'). Defaults to 'lean'.\n * @returns {Promise<LeanOrder | FullOrder>} A promise that resolves to the order data or null if not found.\n * @throws {Error} If the GraphQL query fails or if the response structure is invalid.\n */\nexport async function getOrderById(\n id: number | bigint,\n detailLevel: OrderDetailLevel = 'lean',\n): Promise<LeanOrder | FullOrder> {\n const bigIntId = typeof id === 'number' ? BigInt(id) : id\n if (detailLevel === 'lean') {\n return getLeanOrderById(bigIntId)\n }\n return getFullOrderById(bigIntId)\n}\n\nasync function getLeanOrderById(id: bigint): Promise<LeanOrder> {\n const variables: OrderByIdQueryVariables = {\n id: convertIdIntoGid(id, 'Order'),\n }\n\n const response = await fetchShopifyGraphql<OrderByIdQuery>({\n query: queryOrderById,\n variables,\n })\n\n if (!response.order) {\n logger.debug(`No order found with ID: ${id}`)\n return null\n }\n\n const order = response.order\n\n const leanOrder = {\n id: order.id,\n name: order.name,\n createdAt: order.createdAt,\n updatedAt: order.updatedAt,\n cancelledAt: order.cancelledAt ?? null,\n cancelReason: order.cancelReason ?? null,\n totalPrice: {\n amount: order.totalPriceSet?.shopMoney?.amount ?? '',\n currencyCode: order.totalPriceSet?.shopMoney?.currencyCode ?? '',\n },\n customer: order.customer\n ? {\n id: order.customer.id,\n displayName: order.customer.displayName,\n firstName: order.customer.firstName ?? null,\n lastName: order.customer.lastName ?? null,\n emailAddress:\n order.customer.defaultEmailAddress?.emailAddress ?? null,\n }\n : null,\n financialStatus: order.displayFinancialStatus ?? null,\n fulfillmentStatus: order.displayFulfillmentStatus ?? null,\n shippingAddress: order.shippingAddress\n ? {\n firstName: order.shippingAddress.firstName ?? null,\n lastName: order.shippingAddress.lastName ?? null,\n address1: order.shippingAddress.address1 ?? null,\n address2: order.shippingAddress.address2 ?? null,\n city: order.shippingAddress.city ?? null,\n province: order.shippingAddress.province ?? null,\n country: order.shippingAddress.country ?? null,\n zip: order.shippingAddress.zip ?? null,\n }\n : null,\n }\n\n return await returnOutputParsed(leanOrder, GetLeanOrderByIdReturn)\n}\n\nasync function getFullOrderById(id: bigint): Promise<FullOrder> {\n const variables: OrderByIdQueryVariables = {\n id: convertIdIntoGid(id, 'Order'),\n }\n\n const response = await fetchShopifyGraphql<OrderByIdFullQuery>({\n query: queryOrderByIdFull,\n variables,\n })\n\n if (!response.order) {\n logger.debug(`No order found with ID: ${id}`)\n return null\n }\n\n return response.order\n}\n","import { gql } from '../../utils/logger'\n\nexport const queryOrderById = gql`#graphql\n query orderById($id: ID!) {\n order(id: $id) {\n id\n name\n createdAt\n updatedAt\n cancelledAt\n cancelReason\n totalPriceSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n customer {\n id\n lastName\n defaultEmailAddress {\n emailAddress\n }\n displayName\n firstName\n }\n displayFinancialStatus\n displayFulfillmentStatus\n shippingAddress {\n firstName\n lastName\n address1\n address2\n city\n province\n country\n zip\n }\n }\n }\n`\n\nexport const queryOrderByIdFull = gql`#graphql\n query orderByIdFull($id: ID!) {\n order(id: $id) {\n id\n name\n createdAt\n updatedAt\n processedAt\n closedAt\n cancelledAt\n cancelReason\n totalPriceSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n customer {\n id\n firstName\n lastName\n email\n phone\n }\n displayFinancialStatus\n displayFulfillmentStatus\n shippingAddress {\n firstName\n lastName\n address1\n address2\n city\n province\n country\n zip\n }\n billingAddress {\n firstName\n lastName\n address1\n address2\n city\n province\n country\n zip\n }\n lineItems(first: 100) {\n edges {\n node {\n id\n sku\n title\n variantTitle\n quantity\n customAttributes {\n key\n value\n }\n originalUnitPriceSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n vendor\n image {\n url\n width\n height\n altText\n }\n }\n }\n }\n fulfillments {\n id\n name\n totalQuantity\n status\n createdAt\n estimatedDeliveryAt\n deliveredAt\n trackingInfo {\n company\n number\n url\n }\n fulfillmentLineItems(first: 100) {\n edges {\n node {\n id\n quantity\n lineItem {\n id\n }\n }\n }\n }\n }\n shippingLine {\n originalPriceSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n }\n taxLines {\n priceSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n }\n totalDiscountsSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n discountCodes\n refunds {\n totalRefundedSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n }\n }\n }\n`\n","import z from 'zod'\nimport type {\n OrdersByNameFullQuery,\n OrdersByNameQuery,\n OrdersByNameQueryVariables,\n} from '../../generated-api-types/2025-04/admin.generated.js'\nimport { logger } from '../../utils/logger.js'\nimport { fetchShopifyGraphql } from '../../utils/shopifyFetch.js'\nimport { returnOutputParsed } from '../../utils/zod.js'\nimport {\n queryOrdersByName,\n queryOrdersByNameFull,\n} from './getOrderByName.queries.js'\n\nconst GetLeanOrderByNameReturn = z\n .object({\n id: z.string(),\n name: z.string(),\n createdAt: z.string(),\n updatedAt: z.string(),\n totalPrice: z.object({\n amount: z.string(),\n currencyCode: z.string(),\n }),\n customer: z\n .object({\n id: z.string(),\n displayName: z.string(),\n emailAddress: z.string().nullable(),\n })\n .nullable(),\n financialStatus: z.string().nullable(),\n fulfillmentStatus: z.string().nullable(),\n })\n .nullable()\n\nexport type LeanOrderByName = z.infer<typeof GetLeanOrderByNameReturn>\n\nexport type FullOrderByName = NonNullable<\n NonNullable<OrdersByNameFullQuery['orders']>['edges'][number]['node']\n> | null\n\ntype OrderDetailLevel = 'lean' | 'full'\n\n// Function overloads\nexport function getOrderByName(\n orderName: string,\n detailLevel: 'lean',\n): Promise<LeanOrderByName>\nexport function getOrderByName(\n orderName: string,\n detailLevel: 'full',\n): Promise<FullOrderByName>\nexport function getOrderByName(orderName: string): Promise<LeanOrderByName>\n\n/**\n * Retrieves a single order from Shopify by its order name (e.g., \"B12345\").\n * Returns null if no order is found with the specified name.\n *\n * @param {string} orderName - The order name to search for (e.g., \"B12345\").\n * @param {OrderDetailLevel} detailLevel - The level of detail to return ('lean' or 'full'). Defaults to 'lean'.\n * @returns {Promise<LeanOrderByName | FullOrderByName>} A promise that resolves to the order data or null if not found.\n * @throws {Error} If the GraphQL query fails or if the response structure is invalid.\n */\nexport async function getOrderByName(\n orderName: string,\n detailLevel: OrderDetailLevel = 'lean',\n): Promise<LeanOrderByName | FullOrderByName> {\n if (detailLevel === 'lean') {\n return getLeanOrderByName(orderName)\n }\n return getFullOrderByName(orderName)\n}\n\nasync function getLeanOrderByName(orderName: string): Promise<LeanOrderByName> {\n const variables: OrdersByNameQueryVariables = {\n first: 1,\n queryFilter: `name:${orderName}`,\n }\n\n type SingleNode = NonNullable<\n NonNullable<OrdersByNameQuery['orders']>['edges'][number]['node']\n >\n\n const extractedNodes = await fetchShopifyGraphql<\n SingleNode,\n OrdersByNameQuery\n >({\n query: queryOrdersByName,\n variables,\n dataExtractor: (pageData: OrdersByNameQuery) => {\n if (!pageData.orders) {\n throw new Error(\n \"GraphQL response for orders is missing the 'orders' field.\",\n )\n }\n const nodes: SingleNode[] = pageData.orders.edges.map(\n (edge: { node: SingleNode }) => edge.node,\n )\n return {\n nodes,\n }\n },\n fetchAllPages: false,\n })\n\n const order = extractedNodes[0]\n if (!order) {\n logger.debug(`No order found with name: ${orderName}`)\n return null\n }\n\n const leanOrder = {\n id: order.id,\n name: order.name,\n createdAt: order.createdAt,\n updatedAt: order.updatedAt,\n totalPrice: {\n amount: order.totalPriceSet?.shopMoney?.amount ?? '',\n currencyCode: order.totalPriceSet?.shopMoney?.currencyCode ?? '',\n },\n customer: order.customer\n ? {\n id: order.customer.id,\n displayName: order.customer.displayName,\n emailAddress:\n order.customer.defaultEmailAddress?.emailAddress ?? null,\n }\n : null,\n financialStatus: order.displayFinancialStatus ?? null,\n fulfillmentStatus: order.displayFulfillmentStatus ?? null,\n }\n\n return await returnOutputParsed(leanOrder, GetLeanOrderByNameReturn)\n}\n\nasync function getFullOrderByName(orderName: string): Promise<FullOrderByName> {\n const variables: OrdersByNameQueryVariables = {\n first: 1,\n queryFilter: `name:${orderName}`,\n }\n\n type SingleNode = NonNullable<\n NonNullable<OrdersByNameFullQuery['orders']>['edges'][number]['node']\n >\n\n const extractedNodes = await fetchShopifyGraphql<\n SingleNode,\n OrdersByNameFullQuery\n >({\n query: queryOrdersByNameFull,\n variables,\n dataExtractor: (pageData: OrdersByNameFullQuery) => {\n if (!pageData.orders) {\n throw new Error(\n \"GraphQL response for orders is missing the 'orders' field.\",\n )\n }\n const nodes: SingleNode[] = pageData.orders.edges.map(\n (edge: { node: SingleNode }) => edge.node,\n )\n return {\n nodes,\n }\n },\n fetchAllPages: false,\n })\n\n if (extractedNodes.length === 0) {\n logger.debug(`No order found with name: ${orderName}`)\n return null\n }\n\n const order = extractedNodes[0]\n if (!order) {\n logger.debug(`No order found with name: ${orderName}`)\n return null\n }\n\n return order\n}\n","import { gql } from '../../utils/logger'\n\nexport const queryOrdersByName = gql`#graphql\n query ordersByName($first: Int!, $queryFilter: String!) {\n orders(first: $first, query: $queryFilter) {\n edges {\n node {\n id\n name\n createdAt\n updatedAt\n totalPriceSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n customer {\n id\n lastName\n defaultEmailAddress {\n emailAddress\n }\n displayName\n firstName\n }\n displayFinancialStatus\n displayFulfillmentStatus\n }\n }\n pageInfo {\n hasNextPage\n endCursor\n }\n }\n }\n`\n\nexport const queryOrdersByNameFull = gql`#graphql\n query ordersByNameFull($first: Int!, $queryFilter: String!) {\n orders(first: $first, query: $queryFilter) {\n edges {\n node {\n billingAddress {\n address1\n address2\n city\n company\n country\n countryCodeV2\n firstName\n formattedArea\n id\n lastName\n name\n phone\n province\n provinceCode\n timeZone\n zip\n }\n billingAddressMatchesShippingAddress\n cancelReason\n cancellation {\n staffNote\n }\n cancelledAt\n capturable\n clientIp\n closed\n closedAt\n confirmed\n createdAt\n currencyCode\n currentCartDiscountAmountSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n currentShippingPriceSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n currentSubtotalLineItemsQuantity\n currentSubtotalPriceSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n currentTaxLines {\n channelLiable\n rate\n ratePercentage\n source\n title\n priceSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n }\n currentTotalAdditionalFeesSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n currentTotalDiscountsSet {\n presentmentMoney {\n amount\n currencyCode\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n currentTotalDutiesSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n currentTotalPriceSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n currentTotalTaxSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n currentTotalWeight\n customer {\n id\n lastName\n defaultEmailAddress {\n emailAddress\n }\n displayName\n firstName\n }\n customerAcceptsMarketing\n discountCodes\n discountCode\n displayAddress {\n address1\n address2\n city\n company\n country\n countryCodeV2\n firstName\n formattedArea\n id\n lastName\n name\n phone\n province\n provinceCode\n timeZone\n zip\n }\n displayFinancialStatus\n displayFulfillmentStatus\n dutiesIncluded\n edited\n email\n estimatedTaxes\n fulfillable\n fulfillments(first: 20) {\n createdAt\n deliveredAt\n displayStatus\n estimatedDeliveryAt\n updatedAt\n trackingInfo(first: 10) {\n company\n url\n }\n totalQuantity\n status\n name\n id\n }\n fullyPaid\n id\n lineItems(first: 50) {\n edges {\n node {\n id\n name\n originalUnitPriceSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n quantity\n requiresShipping\n sku\n title\n variantTitle\n }\n }\n }\n name\n note\n processedAt\n shippingAddress {\n address1\n address2\n city\n company\n country\n countryCodeV2\n firstName\n formattedArea\n id\n lastName\n name\n phone\n province\n provinceCode\n timeZone\n zip\n }\n statusPageUrl\n tags\n totalPriceSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n totalReceivedSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n totalRefundedSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n totalShippingPriceSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n totalTaxSet {\n presentmentMoney {\n amount\n currencyCode\n }\n shopMoney {\n amount\n currencyCode\n }\n }\n totalWeight\n unpaid\n updatedAt\n }\n }\n pageInfo {\n hasNextPage\n endCursor\n }\n }\n }\n`\n","import z from 'zod'\nimport type {\n LeanProductVariantsQuery,\n LeanProductVariantsQueryVariables,\n} from '../../generated-api-types/2025-04/admin.generated.js'\nimport { gql, logger } from '../../utils/logger.js'\nimport { fetchShopifyGraphql } from '../../utils/shopifyFetch.js'\nimport { returnOutputParsed } from '../../utils/zod.js'\n\nconst GetLeanProductVariantsReturn = z.array(\n z.object({\n productId: z.string(),\n productTitle: z.string(),\n variantId: z.string(),\n variantTitle: z.string(),\n sku: z.string(),\n }),\n)\n\ntype GetLeanProductVariantsReturnType = z.infer<\n typeof GetLeanProductVariantsReturn\n>\n\n/**\n * Retrieves a lean list of product variants from Shopify, optionally filtered by SKUs.\n * Product variants are mapped to a simpler output structure.\n * Variants missing essential properties (e.g., SKU) will be filtered out and logged.\n *\n * @param {string[]} [skus] - An optional array of SKUs to filter by. If provided, only variants matching these SKUs will be fetched.\n * @returns {Promise<GetLeanProductVariantsReturnType>} A promise that resolves to an array of lean product variant data.\n * @throws {Error} If the GraphQL query fails, returns no data, or if the `productVariants` field is missing in the response.\n */\nexport async function getLeanProductVariants(\n skus?: string[],\n): Promise<GetLeanProductVariantsReturnType> {\n const queryGql = gql`#graphql\n query leanProductVariants($first: Int!, $after: String, $queryFilter: String) {\n productVariants(first: $first, after: $after, query: $queryFilter) {\n edges {\n node { \n id\n title\n sku\n product {\n id\n title\n }\n }\n }\n pageInfo { \n hasNextPage\n endCursor\n }\n }\n }\n `\n\n const initialVariables: LeanProductVariantsQueryVariables = { first: 250 }\n if (skus && skus.length > 0) {\n initialVariables.queryFilter = skus\n .map((sku: string) => `sku:${sku}`)\n .join(' OR ')\n }\n\n // Type for a single node from the productVariants query\n type SingleNode = NonNullable<\n NonNullable<\n LeanProductVariantsQuery['productVariants']\n >['edges'][number]['node']\n >\n\n const extractedNodes = await fetchShopifyGraphql<\n SingleNode,\n LeanProductVariantsQuery\n >({\n query: queryGql,\n variables: initialVariables,\n dataExtractor: (pageData: LeanProductVariantsQuery) => {\n if (!pageData.productVariants) {\n throw new Error(\n \"GraphQL response for product variants is missing the 'productVariants' field.\",\n )\n }\n const nodes: SingleNode[] = pageData.productVariants.edges.map(\n (edge: { node: SingleNode }) => edge.node,\n )\n return {\n nodes,\n pageInfo: pageData.productVariants.pageInfo,\n }\n },\n fetchAllPages: true,\n })\n\n const allVariants = extractedNodes.flatMap<\n GetLeanProductVariantsReturnType[number]\n >((v) => {\n if (v.sku) {\n return [\n {\n productId: v.product.id,\n productTitle: v.product.title,\n variantId: v.id,\n variantTitle: v.title,\n sku: v.sku,\n },\n ]\n }\n logger.debug(\n `Product ${v.product.title} (ID: ${v.product.id}) has a variant (ID: ${v.id}) with no SKU. Filtering out.`,\n )\n return []\n })\n\n return await returnOutputParsed(allVariants, GetLeanProductVariantsReturn)\n}\n","import z from 'zod'\nimport type {\n OrderPaymentDetailsByIdQuery,\n OrderPaymentDetailsByIdQueryVariables,\n} from '../../generated-api-types/2025-04/admin.generated.js'\nimport { logger } from '../../utils/logger.js'\nimport {\n convertIdIntoGid,\n fetchShopifyGraphql,\n} from '../../utils/shopifyFetch.js'\nimport { returnOutputParsed } from '../../utils/zod.js'\nimport { queryOrderPaymentDetails } from './getOrderPaymentDetails.queries.js'\n\nconst GetOrderPaymentDetailsByIdReturn = z.object({\n order: z.object({\n transactions: z.array(\n z.object({\n amountSet: z.object({\n shopMoney: z.object({\n amount: z.string(),\n currencyCode: z.string(),\n }),\n }),\n createdAt: z.string(),\n gateway: z.string(),\n formattedGateway: z.string(),\n kind: z.string(),\n paymentId: z.string(),\n }),\n ),\n }),\n})\n\ntype GetOrderPaymentDetailsByIdReturnType = z.infer<\n typeof GetOrderPaymentDetailsByIdReturn\n>\n\n/**\n * Retrieves payment details for a single order from Shopify by its ID.\n * Returns null if no order is found with the specified ID.\n *\n * @param {bigint} id - The numerical Shopify order ID (e.g., 12345678n).\n * @returns {Promise<GetOrderPaymentDetailsByIdReturnType | null>} A promise that resolves to the order payment data or null if not found.\n * @throws {Error} If the GraphQL query fails or if the response structure is invalid.\n */\nexport async function getOrderPaymentDetailsById(\n id: bigint,\n): Promise<GetOrderPaymentDetailsByIdReturnType | null> {\n const variables: OrderPaymentDetailsByIdQueryVariables = {\n id: convertIdIntoGid(id, 'Order'),\n }\n\n const response = await fetchShopifyGraphql<OrderPaymentDetailsByIdQuery>({\n query: queryOrderPaymentDetails,\n variables,\n })\n\n if (!response.order) {\n logger.debug(`No order found with ID: ${id}`)\n return null\n }\n\n return await returnOutputParsed(response, GetOrderPaymentDetailsByIdReturn)\n}\n","import { gql } from '../../utils/logger.js'\n\nexport const queryOrderPaymentDetails = gql`#graphql\n query orderPaymentDetailsById($id: ID!) {\n order(id: $id) {\n transactions {\n amountSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n createdAt\n gateway\n formattedGateway\n kind\n paymentId\n }\n }\n }\n`\n","/**\n * Transforms GraphQL responses to REST-like format.\n *\n * This utility recursively:\n * 1. Flattens `{ edges: [{ node: ... }] }` → `[...]`\n * 2. Converts camelCase to snake_case (`lineItems` → `line_items`)\n * 3. Extracts numeric IDs from GIDs (`gid://shopify/Order/123` → `123`)\n */\n\n/**\n * Convert a camelCase string to snake_case\n */\nfunction camelToSnake(str: string): string {\n return str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`)\n}\n\n/**\n * Extract numeric ID from a Shopify GID string\n */\nfunction extractNumericId(gid: string): number {\n const match = gid.match(/\\d+$/)\n return match ? parseInt(match[0], 10) : 0\n}\n\n/**\n * Transform a GraphQL response object to REST-like format.\n *\n * @example\n * ```typescript\n * const graphqlOrder = {\n * id: 'gid://shopify/Order/123',\n * lineItems: {\n * edges: [{ node: { id: 'gid://shopify/LineItem/456', sku: 'ABC' } }]\n * }\n * };\n *\n * const restOrder = toRestFormat(graphqlOrder);\n * // Result:\n * // {\n * // id: 123,\n * // line_items: [{ id: 456, sku: 'ABC' }]\n * // }\n * ```\n */\nexport function toRestFormat<T>(obj: T): unknown {\n if (obj === null || obj === undefined) {\n return obj\n }\n\n if (Array.isArray(obj)) {\n return obj.map(toRestFormat)\n }\n\n if (typeof obj === 'object') {\n const record = obj as Record<string, unknown>\n const result: Record<string, unknown> = {}\n\n for (const [key, value] of Object.entries(record)) {\n // Flatten edges/node pattern: { edges: [{ node: ... }] } → [...]\n if (\n key === 'edges' &&\n Array.isArray(value) &&\n value.every(\n (item) =>\n typeof item === 'object' && item !== null && 'node' in item,\n )\n ) {\n return value.map((edge: { node: unknown }) => toRestFormat(edge.node))\n }\n\n // Convert GID to numeric ID\n if (\n key === 'id' &&\n typeof value === 'string' &&\n value.startsWith('gid://')\n ) {\n result[key] = extractNumericId(value)\n continue\n }\n\n // Convert camelCase to snake_case and recurse\n const snakeKey = camelToSnake(key)\n result[snakeKey] = toRestFormat(value)\n }\n\n return result\n }\n\n return obj\n}\n","/**\n * Extract numeric ID from a Shopify GID string.\n *\n * @example\n * parseGid('gid://shopify/Order/12345678901234') // → 12345678901234\n * parseGid('gid://shopify/LineItem/999') // → 999\n */\nexport function parseGid(gid: string): number {\n const match = gid.match(/\\d+$/)\n return match ? parseInt(match[0], 10) : 0\n}\n"],"mappings":";AAAA,OAAOA,QAAO;;;ACAd,IAAM,EAAE,IAAI,IAAI;AAET,IAAM,MAAM,OAAO;AAE1B,IAAM,YAAY;AAAA,EAChB,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AACT;AAIA,SAAS,YACP,SACA,aACc;AACd,MAAI,eAAe,eAAe,WAAW;AAC3C,WAAO;AAAA,EACT;AAEA,MAAI,YAAY,QAAQ;AACtB,WAAO;AAAA,EACT;AAEA,MAAI,YAAY,cAAc;AAC5B,WA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Q,IAAI,MAAM,MAAM;AAC9B,SAAO,QAAQ,SAAS,MAAM,CAAC,GAAG,EAAE,IAAI;AAC1C;AAsBO,SAAS,aAAgB,KAAiB;AAC/C,MAAI,QAAQ,QAAQ,QAAQ,QAAW;AACrC,WAAO;AAAA,EACT;AAEA,MAAI,MAAM,QAAQ,GAAG,GAAG;AACtB,WAAO,IAAI,IAAI,YAAY;AAAA,EAC7B;AAEA,MAAI,OAAO,QAAQ,UAAU;AAC3B,UAAM,SAAS;AACf,UAAM,SAAkC,CAAC;AAEzC,eAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,MAAM,GAAG;AAEjD,UACE,QAAQ,WACR,MAAM,QAAQ,KAAK,KACnB,MAAM;AAAA,QACJ,CAAC,SACC,OAAO,SAAS,YAAY,SAAS,QAAQ,UAAU;AAAA,MAC3D,GACA;AACA,eAAO,MAAM,IAAI,CAAC,SAA4B,aAAa,KAAK,IAAI,CAAC;AAAA,MACvE;AAGA,UACE,QAAQ,QACR,OAAO,UAAU,YACjB,MAAM,WAAW,QAAQ,GACzB;AACA,eAAO,GAAG,IAAI,iBAAiB,KAAK;AACpC;AAAA,MACF;AAGA,YAAM,WAAW,aAAa,GAAG;AACjC,aAAO,QAAQ,IAAI,aAAa,KAAK;AAAA,IACvC;AAEA,WAAO;AAAA,EACT;AAEA,SAAO;AACT;;;AClFO,SAAS,SAAS,KAAqB;AAC5C,QAAM,QAAQ,IAAI,MAAM,MAAM;AAC9B,SAAO,QAAQ,SAAS,MAAM,CAAC,GAAG,EAAE,IAAI;AAC1C;","names":["z","env","z","z","z","z","z","z","z","z","z","z","z"]}
@@ -129,8 +129,8 @@ declare const GetLeanOrderByIdReturn: z.ZodNullable<z.ZodObject<{
129
129
  }>>;
130
130
  export type LeanOrder = z.infer<typeof GetLeanOrderByIdReturn>;
131
131
  export type FullOrder = NonNullable<OrderByIdFullQuery['order']> | null;
132
- export declare function getOrderById(id: bigint): Promise<LeanOrder>;
133
- export declare function getOrderById(id: bigint, detailLevel: 'lean'): Promise<LeanOrder>;
134
- export declare function getOrderById(id: bigint, detailLevel: 'full'): Promise<FullOrder>;
132
+ export declare function getOrderById(id: number | bigint): Promise<LeanOrder>;
133
+ export declare function getOrderById(id: number | bigint, detailLevel: 'lean'): Promise<LeanOrder>;
134
+ export declare function getOrderById(id: number | bigint, detailLevel: 'full'): Promise<FullOrder>;
135
135
  export {};
136
136
  //# sourceMappingURL=getOrderById.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getOrderById.d.ts","sourceRoot":"","sources":["../../../src/queries/orders/getOrderById.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAA;AACnB,OAAO,KAAK,EACV,kBAAkB,EAGnB,MAAM,sDAAsD,CAAA;AAwB7D,QAAA,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyBf,CAAA;AAEb,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAA;AAG9D,MAAM,MAAM,SAAS,GAAG,WAAW,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,GAAG,IAAI,CAAA;AAKvE,wBAAgB,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAAA;AAC5D,wBAAgB,YAAY,CAC1B,EAAE,EAAE,MAAM,EACV,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,SAAS,CAAC,CAAA;AACrB,wBAAgB,YAAY,CAC1B,EAAE,EAAE,MAAM,EACV,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,SAAS,CAAC,CAAA"}
1
+ {"version":3,"file":"getOrderById.d.ts","sourceRoot":"","sources":["../../../src/queries/orders/getOrderById.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAA;AACnB,OAAO,KAAK,EACV,kBAAkB,EAGnB,MAAM,sDAAsD,CAAA;AAwB7D,QAAA,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyBf,CAAA;AAEb,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAA;AAG9D,MAAM,MAAM,SAAS,GAAG,WAAW,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,GAAG,IAAI,CAAA;AAKvE,wBAAgB,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAAA;AACrE,wBAAgB,YAAY,CAC1B,EAAE,EAAE,MAAM,GAAG,MAAM,EACnB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,SAAS,CAAC,CAAA;AACrB,wBAAgB,YAAY,CAC1B,EAAE,EAAE,MAAM,GAAG,MAAM,EACnB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,SAAS,CAAC,CAAA"}
@@ -47,16 +47,17 @@ const GetLeanOrderByIdReturn = z
47
47
  * Retrieves a single order from Shopify by its numeric ID.
48
48
  * Returns null if no order is found with the specified ID.
49
49
  *
50
- * @param {bigint} id - The numerical Shopify order ID (e.g., 12345678n).
50
+ * @param {number | bigint} id - The numerical Shopify order ID (e.g., 12345678 or 12345678n).
51
51
  * @param {OrderDetailLevel} detailLevel - The level of detail to return ('lean' or 'full'). Defaults to 'lean'.
52
52
  * @returns {Promise<LeanOrder | FullOrder>} A promise that resolves to the order data or null if not found.
53
53
  * @throws {Error} If the GraphQL query fails or if the response structure is invalid.
54
54
  */
55
55
  export async function getOrderById(id, detailLevel = 'lean') {
56
+ const bigIntId = typeof id === 'number' ? BigInt(id) : id;
56
57
  if (detailLevel === 'lean') {
57
- return getLeanOrderById(id);
58
+ return getLeanOrderById(bigIntId);
58
59
  }
59
- return getFullOrderById(id);
60
+ return getFullOrderById(bigIntId);
60
61
  }
61
62
  async function getLeanOrderById(id) {
62
63
  const variables = {
@@ -1 +1 @@
1
- {"version":3,"file":"getOrderById.js","sourceRoot":"","sources":["../../../src/queries/orders/getOrderById.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAA;AAMnB,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAC9C,OAAO,EACL,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,6BAA6B,CAAA;AACpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAE9E,gDAAgD;AAChD,MAAM,aAAa,GAAG,CAAC;KACpB,MAAM,CAAC;IACN,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAChC,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC/B,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC/B,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC/B,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC3B,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC/B,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC9B,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC3B,CAAC;KACD,QAAQ,EAAE,CAAA;AAEb,oBAAoB;AACpB,MAAM,sBAAsB,GAAG,CAAC;KAC7B,MAAM,CAAC;IACN,EAAE,EAAE,CAAC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AS,EAAE,KAAK,CAAC,eAAe,CAAC,SAAS,IAAI,IAAI;gBAClD,QAAQ,EAAE,KAAK,CAAC,eAAe,CAAC,QAAQ,IAAI,IAAI;gBAChD,QAAQ,EAAE,KAAK,CAAC,eAAe,CAAC,QAAQ,IAAI,IAAI;gBAChD,QAAQ,EAAE,KAAK,CAAC,eAAe,CAAC,QAAQ,IAAI,IAAI;gBAChD,IAAI,EAAE,KAAK,CAAC,eAAe,CAAC,IAAI,IAAI,IAAI;gBACxC,QAAQ,EAAE,KAAK,CAAC,eAAe,CAAC,QAAQ,IAAI,IAAI;gBAChD,OAAO,EAAE,KAAK,CAAC,eAAe,CAAC,OAAO,IAAI,IAAI;gBAC9C,GAAG,EAAE,KAAK,CAAC,eAAe,CAAC,GAAG,IAAI,IAAI;aACvC;YACH,CAAC,CAAC,IAAI;KACT,CAAA;IAED,OAAO,MAAM,kBAAkB,CAAC,SAAS,EAAE,sBAAsB,CAAC,CAAA;AACpE,CAAC;AAED,KAAK,UAAU,gBAAgB,CAAC,EAAU;IACxC,MAAM,SAAS,GAA4B;QACzC,EAAE,EAAE,gBAAgB,CAAC,EAAE,EAAE,OAAO,CAAC;KAClC,CAAA;IAED,MAAM,QAAQ,GAAG,MAAM,mBAAmB,CAAqB;QAC7D,KAAK,EAAE,kBAAkB;QACzB,SAAS;KACV,CAAC,CAAA;IAEF,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACpB,MAAM,CAAC,KAAK,CAAC,2BAA2B,EAAE,EAAE,CAAC,CAAA;QAC7C,OAAO,IAAI,CAAA;IACb,CAAC;IAED,OAAO,QAAQ,CAAC,KAAK,CAAA;AACvB,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Extract numeric ID from a Shopify GID string.
3
+ *
4
+ * @example
5
+ * parseGid('gid://shopify/Order/12345678901234') // → 12345678901234
6
+ * parseGid('gid://shopify/LineItem/999') // → 999
7
+ */
8
+ export declare function parseGid(gid: string): number;
9
+ //# sourceMappingURL=parseGid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseGid.d.ts","sourceRoot":"","sources":["../../src/utils/parseGid.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAG5C"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Extract numeric ID from a Shopify GID string.
3
+ *
4
+ * @example
5
+ * parseGid('gid://shopify/Order/12345678901234') // → 12345678901234
6
+ * parseGid('gid://shopify/LineItem/999') // → 999
7
+ */
8
+ export function parseGid(gid) {
9
+ const match = gid.match(/\d+$/);
10
+ return match ? Number.parseInt(match[0], 10) : 0;
11
+ }
12
+ //# sourceMappingURL=parseGid.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseGid.js","sourceRoot":"","sources":["../../src/utils/parseGid.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,UAAU,QAAQ,CAAC,GAAW;IAClC,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;IAC/B,OAAO,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AAClD,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=parseGid.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseGid.test.d.ts","sourceRoot":"","sources":["../../src/utils/parseGid.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,26 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { parseGid } from './parseGid';
3
+ describe('parseGid', () => {
4
+ it('extracts numeric ID from Order GID', () => {
5
+ expect(parseGid('gid://shopify/Order/12345678901234')).toBe(12345678901234);
6
+ });
7
+ it('extracts numeric ID from LineItem GID', () => {
8
+ expect(parseGid('gid://shopify/LineItem/999')).toBe(999);
9
+ });
10
+ it('extracts numeric ID from Fulfillment GID', () => {
11
+ expect(parseGid('gid://shopify/Fulfillment/222222222222')).toBe(222222222222);
12
+ });
13
+ it('extracts numeric ID from Customer GID', () => {
14
+ expect(parseGid('gid://shopify/Customer/98765432101234')).toBe(98765432101234);
15
+ });
16
+ it('returns 0 for invalid GID without numbers', () => {
17
+ expect(parseGid('gid://shopify/Order/')).toBe(0);
18
+ });
19
+ it('returns 0 for empty string', () => {
20
+ expect(parseGid('')).toBe(0);
21
+ });
22
+ it('extracts ID from string with only numbers at end', () => {
23
+ expect(parseGid('some-prefix-123')).toBe(123);
24
+ });
25
+ });
26
+ //# sourceMappingURL=parseGid.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseGid.test.js","sourceRoot":"","sources":["../../src/utils/parseGid.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAErC,QAAQ,CAAC,UAAU,EAAE,GAAG,EAAE;IACxB,EAAE,CAAC,oCAAoC,EAAE,GAAG,EAAE;QAC5C,MAAM,CAAC,QAAQ,CAAC,oCAAoC,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;IAC7E,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,uCAAuC,EAAE,GAAG,EAAE;QAC/C,MAAM,CAAC,QAAQ,CAAC,4BAA4B,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAC1D,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,0CAA0C,EAAE,GAAG,EAAE;QAClD,MAAM,CAAC,QAAQ,CAAC,wCAAwC,CAAC,CAAC,CAAC,IAAI,CAC7D,YAAY,CACb,CAAA;IACH,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,uCAAuC,EAAE,GAAG,EAAE;QAC/C,MAAM,CA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