{"version":3,"file":"useScimConnectionGroups.mjs","sources":["../../../../../../../../web/src/adminPortal/utils/useScimConnectionGroups.ts"],"sourcesContent":["import { B2BSCIMGetConnectionGroupsResponse } from '@stytch/core/public';\nimport useSWR from 'swr';\n\nimport { useStytchClient } from '../utils/useStytchClient';\n\nexport const MAX_LIMIT_CONNECTION_GROUPS = 1000;\n\nexport const scimGetConnectionGroupsKey = (orgId: string | undefined) => ['scim.getConnectionGroups', orgId];\n\nexport const useScimConnectionGroups = ({ shouldFetch }: { shouldFetch: boolean }) => {\n  const client = useStytchClient();\n  const org = client.organization.getSync();\n  const orgId = org?.organization_id;\n\n  return useSWR(shouldFetch ? scimGetConnectionGroupsKey(orgId) : null, async () => {\n    let response = await client.scim.getConnectionGroups({ limit: MAX_LIMIT_CONNECTION_GROUPS });\n\n    while (response.next_cursor) {\n      await client.scim\n        .getConnectionGroups({ limit: MAX_LIMIT_CONNECTION_GROUPS, cursor: response.next_cursor })\n        .then((newResponse: B2BSCIMGetConnectionGroupsResponse) => {\n          response = {\n            ...response,\n            scim_groups: [...response.scim_groups, ...newResponse.scim_groups],\n            next_cursor: newResponse.next_cursor,\n          };\n        });\n    }\n    return response;\n  });\n};\n"],"names":["MAX_LIMIT_CONNECTION_GROUPS","scimGetConnectionGroupsKey","orgId","useScimConnectionGroups","shouldFetch","client","useStytchClient","org","organization","getSync","organization_id","useSWR","response","scim","getConnectionGroups","limit","next_cursor","cursor","then","newResponse","scim_groups"],"mappings":";;;AAKO,MAAMA,8BAA8B;AAEpC,MAAMC,0BAAAA,GAA6B,CAACC,KAAAA,GAA8B;AAAC,QAAA,0BAAA;AAA4BA,QAAAA;;AAE/F,MAAMC,uBAAAA,GAA0B,CAAC,EAAEC,WAAW,EAA4B,GAAA;AAC/E,IAAA,MAAMC,MAAAA,GAASC,eAAAA,EAAAA;AACf,IAAA,MAAMC,GAAAA,GAAMF,MAAAA,CAAOG,YAAY,CAACC,OAAO,EAAA;AACvC,IAAA,MAAMP,QAAQK,GAAAA,EAAKG,eAAAA;AAEnB,IAAA,OAAOC,MAAAA,CAAOP,WAAAA,GAAcH,0BAAAA,CAA2BC,KAAAA,CAAAA,GAAS,IAAA,EAAM,UAAA;AACpE,QAAA,IAAIU,WAAW,MAAMP,MAAAA,CAAOQ,IAAI,CAACC,mBAAmB,CAAC;YAAEC,KAAAA,EAAOf;AAA4B,SAAA,CAAA;QAE1F,MAAOY,QAAAA,CAASI,WAAW,CAAE;AAC3B,YAAA,MAAMX,MAAAA,CAAOQ,IAAI,CACdC,mBAAmB,CAAC;gBAAEC,KAAAA,EAAOf,2BAAAA;AAA6BiB,gBAAAA,MAAAA,EAAQL,SAASI;aAAY,CAAA,CACvFE,IAAI,CAAC,CAACC,WAAAA,GAAAA;gBACLP,QAAAA,GAAW;AACT,oBAAA,GAAGA,QAAQ;oBACXQ,WAAAA,EAAa;AAAIR,wBAAAA,GAAAA,QAAAA,CAASQ,WAAW;AAAKD,wBAAAA,GAAAA,WAAAA,CAAYC;AAAY,qBAAA;AAClEJ,oBAAAA,WAAAA,EAAaG,YAAYH;AAC3B,iBAAA;AACF,YAAA,CAAA,CAAA;AACJ,QAAA;QACA,OAAOJ,QAAAA;AACT,IAAA,CAAA,CAAA;AACF;;;;"}