UNPKG

@agnostack/next-shopify

Version:

Please contact agnoStack via info@agnostack.com for any questions

216 lines • 6.91 kB
"use strict"; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.APP_QUERY = exports.TRANSFORM = exports.FRAGMENTS = void 0; const display_1 = require("./display"); const theme_1 = require("./theme"); exports.FRAGMENTS = { APP_INSTALLATION: ` id launchUrl uninstallUrl app { id handle installUrl appStoreAppUrl } `, APP_SUBSCRIPTION: ` id name test `, APP_PURCHASE: ` id status name test `, APP_METAFIELD: ` id key type value namespace `, THEME: ` id name role updatedAt files(filenames: $filenames) { nodes { filename body { ... on OnlineStoreThemeFileBodyText { content } } } } `, }; const THEME = ` query getTheme($id: ID!, $filenames: [String!] = ["${theme_1.THEME_ASSET_KEY_DEFAULT}"]) { theme(id: $id) { ${exports.FRAGMENTS.THEME} } } `; const THEME_ACTIVE = ` query getActiveTheme($filenames: [String!] = ["${theme_1.THEME_ASSET_KEY_DEFAULT}"]) { themes(roles: [MAIN], first: 1) { nodes { ${exports.FRAGMENTS.THEME} } } } `; const INSTALLATION_BASIC = ` query getAppInstallationBasic { currentAppInstallation { ${exports.FRAGMENTS.APP_INSTALLATION} } } `; const INSTALLATION_SUBSCRIPTIONS = ` query getAppInstallationSubscriptions { currentAppInstallation { activeSubscriptions { ${exports.FRAGMENTS.APP_SUBSCRIPTION} } } } `; const INSTALLATION = ` query getAppInstallation($namespace: String!) { currentAppInstallation { ${exports.FRAGMENTS.APP_INSTALLATION} activeSubscriptions { ${exports.FRAGMENTS.APP_SUBSCRIPTION} } oneTimePurchases(first: 250, reverse: true) { nodes { ${exports.FRAGMENTS.APP_PURCHASE} } } metafields(namespace: $namespace, first: 50, reverse: true) { nodes { ${exports.FRAGMENTS.APP_METAFIELD} } } } shop { features { captcha giftCards shopifyPlus eligibleForSubscriptions eligibleForSubscriptionMigration } customerAccountsV2 { customerAccountsVersion } } } `; const CANCEL_APP_SUBSCRIPTION = ` mutation cancelAppSubscription($id: ID!) { appSubscriptionCancel(id: $id) { appSubscription { id status } } } `; // NOTE: removing namespace for security const APP_METAFIELDS_TRANSFORM = (metafields) => ((0, display_1.ensureArray)(metafields).reduce((_appMetafields, // eslint-disable-next-line @typescript-eslint/no-unused-vars _a) => { var // eslint-disable-next-line @typescript-eslint/no-unused-vars { namespace: _namespace, key, type: metaFieldType, value: metafieldValue } = _a, metafieldData = __rest(_a, // eslint-disable-next-line @typescript-eslint/no-unused-vars ["namespace", "key", "type", "value"]); if (metaFieldType === 'json') { // eslint-disable-next-line @typescript-eslint/no-unused-vars const _b = JSON.parse(metafieldValue), { value: extendedValue, type: extendedType } = _b, extendedData = __rest(_b, ["value", "type"]); return Object.assign(Object.assign({}, _appMetafields), { [key]: Object.assign(Object.assign(Object.assign({ value: extendedValue }, extendedType && { type: extendedType }), extendedData), metafieldData) }); } return Object.assign(Object.assign({}, _appMetafields), { [key]: Object.assign({ type: metaFieldType, value: metafieldValue }, metafieldData) }); }, {})); const APP_QUERY_TRANSFORM = (data, body) => { const { id: appInstallationId, launchUrl, uninstallUrl, activeSubscriptions, app: { id: appId, handle, installUrl, appStoreAppUrl, } = {}, oneTimePurchases: { nodes: oneTimePurchases, } = {}, metafields: { nodes: metafields, } = {}, } = data !== null && data !== void 0 ? data : {}; const { shop: { features: storeFeatures, customerAccountsV2: { customerAccountsVersion, } = {}, } = {}, } = body !== null && body !== void 0 ? body : {}; const activePurchases = (0, display_1.ensureArray)(oneTimePurchases).reduce((_activePurchases, _a) => { var { status } = _a, oneTimePurchase = __rest(_a, ["status"]); return ([ ..._activePurchases, ...(status === 'ACTIVE') ? [ oneTimePurchase ] : [] ]); }, []); return { appMetafields: APP_METAFIELDS_TRANSFORM(metafields), appInfo: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ id: appId }, handle && { handle }), installUrl && { installUrl }), storeFeatures && { storeFeatures }), appStoreAppUrl && { appStoreAppUrl }), customerAccountsVersion && { customerAccountsVersion }), appInstallation: Object.assign(Object.assign({ id: appInstallationId, activeSubscriptions, activePurchases }, launchUrl && { launchURL: launchUrl, }), uninstallUrl && { uninstallURL: uninstallUrl, }), }; }; const THEME_QUERY_TRANSFORM = (data) => { const { id, name, role, files, updatedAt, } = data !== null && data !== void 0 ? data : {}; if (!id) { return undefined; } return { id, name, updatedAt, isActive: (role === 'MAIN'), assets: (0, display_1.ensureArray)(files === null || files === void 0 ? void 0 : files.nodes).reduce((_assets, node) => { var _a; const content = (0, display_1.safeParse)((0, display_1.removeLeadingComment)((_a = node === null || node === void 0 ? void 0 : node.body) === null || _a === void 0 ? void 0 : _a.content)); if (!(0, display_1.isTypeEnhanced)(content, 'object')) { return _assets; } return [ ..._assets, { filename: node.filename, content, } ]; }, []), }; }; exports.TRANSFORM = { THEME_QUERY: THEME_QUERY_TRANSFORM, APP_QUERY: APP_QUERY_TRANSFORM, APP_METAFIELDS: APP_METAFIELDS_TRANSFORM, }; exports.APP_QUERY = { CANCEL_APP_SUBSCRIPTION, INSTALLATION_SUBSCRIPTIONS, INSTALLATION_BASIC, INSTALLATION, THEME_ACTIVE, THEME, }; //# sourceMappingURL=graph.js.map