@shopify/shopify-app-remix
Version:
Shopify Remix - to simplify the building of Shopify Apps with Remix
1 lines • 2.21 kB
Source Map (JSON)
{"version":3,"file":"render-app-bridge.mjs","sources":["../../../../../../../src/server/authenticate/admin/helpers/render-app-bridge.ts"],"sourcesContent":["import {BasicParams} from '../../../types';\nimport {appBridgeUrl} from '../../helpers/app-bridge-url';\nimport {addDocumentResponseHeaders} from '../../helpers/add-response-headers';\n\nimport {sanitizeRedirectUrl} from './validate-redirect-url';\n\nimport type {RedirectTarget} from '.';\n\nexport interface RedirectToOptions {\n url: string | URL;\n target?: RedirectTarget;\n}\n\nexport function renderAppBridge(\n {config}: BasicParams,\n request: Request,\n redirectTo?: RedirectToOptions,\n): never {\n let redirectToScript = '';\n if (redirectTo) {\n const destination = sanitizeRedirectUrl(config.appUrl, redirectTo.url);\n\n const target = redirectTo.target ?? '_top';\n\n redirectToScript = `<script>window.open(${JSON.stringify(\n destination.toString(),\n )}, ${JSON.stringify(target)})</script>`;\n }\n\n const responseHeaders = new Headers({\n 'content-type': 'text/html;charset=utf-8',\n });\n addDocumentResponseHeaders(\n responseHeaders,\n config.isEmbeddedApp,\n new URL(request.url).searchParams.get('shop'),\n );\n\n throw new Response(\n `\n <script data-api-key=\"${config.apiKey}\" src=\"${appBridgeUrl()}\"></script>\n ${redirectToScript}\n `,\n {headers: responseHeaders},\n );\n}\n"],"names":[],"mappings":";;;;AAaM,SAAU,eAAe,CAC7B,EAAC,MAAM,EAAc,EACrB,OAAgB,EAChB,UAA8B,EAAA;IAE9B,IAAI,gBAAgB,GAAG,EAAE;IACzB,IAAI,UAAU,EAAE;AACd,QAAA,MAAM,WAAW,GAAG,mBAAmB,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,GAAG,CAAC;AAEtE,QAAA,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,IAAI,MAAM;AAE1C,QAAA,gBAAgB,GAAG,CAAA,oBAAA,EAAuB,IAAI,CAAC,SAAS,CACtD,WAAW,CAAC,QAAQ,EAAE,CACvB,CAAA,EAAA,EAAK,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,YAAY;IAC1C;AAEA,IAAA,MAAM,eAAe,GAAG,IAAI,OAAO,CAAC;AAClC,QAAA,cAAc,EAAE,yBAAyB;AAC1C,KAAA,CAAC;IACF,0BAA0B,CACxB,eAAe,EACf,MAAM,CAAC,aAAa,EACpB,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC,CAC9C;IAED,MAAM,IAAI,QAAQ,CAChB;AAC0B,4BAAA,EAAA,MAAM,CAAC,MAAM,CAAA,OAAA,EAAU,YAAY,EAAE,CAAA;QAC3D,gBAAgB;AACnB,IAAA,CAAA,EACD,EAAC,OAAO,EAAE,eAAe,EAAC,CAC3B;AACH;;;;"}