{"version":3,"file":"query.mjs","sources":["../../../../../../../src/server/authenticate/admin/scope/query.ts"],"sourcesContent":["import {AuthScopes, Session} from '@shopify/shopify-api';\n\nimport {AdminApiContext} from '../../../clients';\nimport type {BasicParams} from '../../../types';\n\nimport {ScopesDetail} from './types';\nimport {\n  FetchScopesDetailResponse,\n  fetchScopeDetail,\n} from './client/fetch-scopes-details';\n\nexport function queryScopesFactory(\n  params: BasicParams,\n  session: Session,\n  admin: AdminApiContext,\n) {\n  return async function queryScopes() {\n    const {logger} = params;\n\n    logger.debug('Querying scopes details: ', {\n      shop: session.shop,\n    });\n\n    const scopesDetail = await fetchScopeDetail(admin);\n    return mapFetchScopeDetail(scopesDetail);\n  };\n}\n\nexport function mapFetchScopeDetail(\n  scopesDetailResponse: FetchScopesDetailResponse,\n): ScopesDetail {\n  const appInformation = scopesDetailResponse.app;\n\n  const granted = new AuthScopes(\n    appInformation.installation.accessScopes.map((scope) => scope.handle),\n  ).toArray(true);\n\n  const required = new AuthScopes(\n    appInformation.requestedAccessScopes.map((scope) => scope.handle),\n  ).toArray(true);\n\n  const optional = new AuthScopes(\n    appInformation.optionalAccessScopes.map((scope) => scope.handle),\n  ).toArray(true);\n\n  return {\n    granted,\n    required,\n    optional,\n  };\n}\n"],"names":[],"mappings":";;;SAWgB,kBAAkB,CAChC,MAAmB,EACnB,OAAgB,EAChB,KAAsB,EAAA;IAEtB,OAAO,eAAe,WAAW,GAAA;AAC/B,QAAA,MAAM,EAAC,MAAM,EAAC,GAAG,MAAM;AAEvB,QAAA,MAAM,CAAC,KAAK,CAAC,2BAA2B,EAAE;YACxC,IAAI,EAAE,OAAO,CAAC,IAAI;AACnB,SAAA,CAAC;AAEF,QAAA,MAAM,YAAY,GAAG,MAAM,gBAAgB,CAAC,KAAK,CAAC;AAClD,QAAA,OAAO,mBAAmB,CAAC,YAAY,CAAC;AAC1C,IAAA,CAAC;AACH;AAEM,SAAU,mBAAmB,CACjC,oBAA+C,EAAA;AAE/C,IAAA,MAAM,cAAc,GAAG,oBAAoB,CAAC,GAAG;AAE/C,IAAA,MAAM,OAAO,GAAG,IAAI,UAAU,CAC5B,cAAc,CAAC,YAAY,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,KAAK,KAAK,KAAK,CAAC,MAAM,CAAC,CACtE,CAAC,OAAO,CAAC,IAAI,CAAC;IAEf,MAAM,QAAQ,GAAG,IAAI,UAAU,CAC7B,cAAc,CAAC,qBAAqB,CAAC,GAAG,CAAC,CAAC,KAAK,KAAK,KAAK,CAAC,MAAM,CAAC,CAClE,CAAC,OAAO,CAAC,IAAI,CAAC;IAEf,MAAM,QAAQ,GAAG,IAAI,UAAU,CAC7B,cAAc,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC,KAAK,KAAK,KAAK,CAAC,MAAM,CAAC,CACjE,CAAC,OAAO,CAAC,IAAI,CAAC;IAEf,OAAO;QACL,OAAO;QACP,QAAQ;QACR,QAAQ;KACT;AACH;;;;"}