{"version":3,"file":"scope.cjs","sources":["../../src/interfaces/scope.ts"],"sourcesContent":["// SCOPE_SEED defines the basic scope structure.\n// When you need to set different permissions for Admin and User\n// on specific endpoints (like /me), use SCOPE rather than modifying SCOPE_SEED.\n\n// If you want to add a new scope:\n// 1. Add a new key to the SCOPE_SEED object below\n// 2. Add the corresponding scope strings to the Scope type union at the bottom of this file\n// 3. Change translation file contents (accesstoken_scopes_desc) when scope structure is modified\n\nconst SCOPE_SEED_ADMIN = {\n  admin: {\n    top: {},\n    app: {},\n    security: {},\n    markdown: {},\n    customize: {},\n    import_data: {},\n    export_data: {},\n    data_transfer: {},\n    external_notification: {},\n    slack_integration: {},\n    legacy_slack_integration: {},\n    user_management: {},\n    user_group_management: {},\n    audit_log: {},\n    plugin: {},\n    ai_integration: {},\n    full_text_search: {},\n  },\n} as const;\n\nconst SCOPE_SEED_USER = {\n  user_settings: {\n    info: {},\n    external_account: {},\n    password: {},\n    api: {\n      api_token: {},\n      access_token: {},\n    },\n    in_app_notification: {},\n    other: {},\n  },\n  features: {\n    ai_assistant: {},\n    page: {},\n    share_link: {},\n    bookmark: {},\n    attachment: {},\n    page_bulk_export: {},\n    in_app_notification: {},\n  },\n} as const;\n\nconst SCOPE_SEED = {\n  ...SCOPE_SEED_ADMIN,\n  ...SCOPE_SEED_USER,\n} as const;\n\nexport const ACTION = {\n  READ: 'read',\n  WRITE: 'write',\n} as const;\n\ntype ACTION_TYPE = (typeof ACTION)[keyof typeof ACTION];\nexport const ALL_SIGN = '*';\n\nconst SCOPE_SEED_WITH_ACTION = Object.values(ACTION).reduce(\n  (acc, action) => {\n    acc[action] = SCOPE_SEED;\n    return acc;\n  },\n  {} as Record<ACTION_TYPE, typeof SCOPE_SEED>,\n);\n\n// ============================================================================\n// SCOPE LITERAL TYPE\n// ============================================================================\n// This type is explicitly defined to avoid TS2589 \"Type instantiation is\n// excessively deep\" errors that occur with recursive type definitions.\n//\n// IMPORTANT: When modifying SCOPE_SEED above, update this type union accordingly.\n// The scope strings follow the pattern: {action}:{category}[:{subcategory}[:{item}]]\n// Wildcard scopes use '*' at any level: {action}:{category}:*\n// ============================================================================\n\n// Read scopes - Admin\ntype ReadAdminScope =\n  | 'read:admin:top'\n  | 'read:admin:app'\n  | 'read:admin:security'\n  | 'read:admin:markdown'\n  | 'read:admin:customize'\n  | 'read:admin:import_data'\n  | 'read:admin:export_data'\n  | 'read:admin:data_transfer'\n  | 'read:admin:external_notification'\n  | 'read:admin:slack_integration'\n  | 'read:admin:legacy_slack_integration'\n  | 'read:admin:user_management'\n  | 'read:admin:user_group_management'\n  | 'read:admin:audit_log'\n  | 'read:admin:plugin'\n  | 'read:admin:ai_integration'\n  | 'read:admin:full_text_search'\n  | 'read:admin:*';\n\n// Read scopes - User Settings\ntype ReadUserSettingsScope =\n  | 'read:user_settings:info'\n  | 'read:user_settings:external_account'\n  | 'read:user_settings:password'\n  | 'read:user_settings:api:api_token'\n  | 'read:user_settings:api:access_token'\n  | 'read:user_settings:api:*'\n  | 'read:user_settings:in_app_notification'\n  | 'read:user_settings:other'\n  | 'read:user_settings:*';\n\n// Read scopes - Features\ntype ReadFeaturesScope =\n  | 'read:features:ai_assistant'\n  | 'read:features:page'\n  | 'read:features:share_link'\n  | 'read:features:bookmark'\n  | 'read:features:attachment'\n  | 'read:features:page_bulk_export'\n  | 'read:features:in_app_notification'\n  | 'read:features:*';\n\n// Write scopes - Admin\ntype WriteAdminScope =\n  | 'write:admin:top'\n  | 'write:admin:app'\n  | 'write:admin:security'\n  | 'write:admin:markdown'\n  | 'write:admin:customize'\n  | 'write:admin:import_data'\n  | 'write:admin:export_data'\n  | 'write:admin:data_transfer'\n  | 'write:admin:external_notification'\n  | 'write:admin:slack_integration'\n  | 'write:admin:legacy_slack_integration'\n  | 'write:admin:user_management'\n  | 'write:admin:user_group_management'\n  | 'write:admin:audit_log'\n  | 'write:admin:plugin'\n  | 'write:admin:ai_integration'\n  | 'write:admin:full_text_search'\n  | 'write:admin:*';\n\n// Write scopes - User Settings\ntype WriteUserSettingsScope =\n  | 'write:user_settings:info'\n  | 'write:user_settings:external_account'\n  | 'write:user_settings:password'\n  | 'write:user_settings:api:api_token'\n  | 'write:user_settings:api:access_token'\n  | 'write:user_settings:api:*'\n  | 'write:user_settings:in_app_notification'\n  | 'write:user_settings:other'\n  | 'write:user_settings:*';\n\n// Write scopes - Features\ntype WriteFeaturesScope =\n  | 'write:features:ai_assistant'\n  | 'write:features:page'\n  | 'write:features:share_link'\n  | 'write:features:bookmark'\n  | 'write:features:attachment'\n  | 'write:features:page_bulk_export'\n  | 'write:features:in_app_notification'\n  | 'write:features:*';\n\n// Combined Scope type - all valid scope strings\nexport type Scope =\n  | ReadAdminScope\n  | ReadUserSettingsScope\n  | ReadFeaturesScope\n  | WriteAdminScope\n  | WriteUserSettingsScope\n  | WriteFeaturesScope\n  | 'read:*'\n  | 'write:*';\n\n// ScopeConstants type definition\ntype ScopeConstantLeaf = Scope;\n\ntype ScopeConstantNode<T> = {\n  [K in keyof T as Uppercase<string & K>]: T[K] extends object\n    ? keyof T[K] extends never\n      ? ScopeConstantLeaf\n      : ScopeConstantNode<T[K]> & { ALL: Scope }\n    : ScopeConstantLeaf;\n};\n\ntype ScopeConstantType = {\n  [A in keyof typeof SCOPE_SEED_WITH_ACTION as Uppercase<\n    string & A\n  >]: ScopeConstantNode<typeof SCOPE_SEED> & { ALL: Scope };\n};\n\nconst buildScopeConstants = (): ScopeConstantType => {\n  const result = {} as Partial<ScopeConstantType>;\n\n  const processObject = (\n    // biome-ignore lint/suspicious/noExplicitAny: ignore\n    obj: Record<string, any>,\n    path: string[] = [],\n    // biome-ignore lint/suspicious/noExplicitAny: ignore\n    resultObj: Record<string, any>,\n  ) => {\n    for (const [key, value] of Object.entries(obj)) {\n      const upperKey = key.toUpperCase();\n      const currentPath = [...path, key];\n      const scopePath = currentPath.join(':');\n\n      if (value == null) {\n        continue; // Changed from 'return' to 'continue' to match the loop behavior\n      }\n\n      if (typeof value === 'object' && Object.keys(value).length === 0) {\n        resultObj[upperKey] = `${scopePath}` as Scope;\n      } else if (typeof value === 'object') {\n        resultObj[upperKey] = {\n          ALL: `${scopePath}:${ALL_SIGN}` as Scope,\n        };\n\n        processObject(value, currentPath, resultObj[upperKey]);\n      }\n    }\n  };\n  processObject(SCOPE_SEED_WITH_ACTION, [], result);\n\n  return result as ScopeConstantType;\n};\n\nexport const SCOPE = buildScopeConstants();\n"],"names":["SCOPE_SEED_ADMIN","SCOPE_SEED_USER","SCOPE_SEED","ACTION","ALL_SIGN","SCOPE_SEED_WITH_ACTION","acc","action","buildScopeConstants","result","processObject","obj","path","resultObj","key","value","upperKey","currentPath","scopePath","SCOPE"],"mappings":"gFASA,MAAMA,EAAmB,CACvB,MAAO,CACL,IAAK,CAAC,EACN,IAAK,CAAC,EACN,SAAU,CAAC,EACX,SAAU,CAAC,EACX,UAAW,CAAC,EACZ,YAAa,CAAC,EACd,YAAa,CAAC,EACd,cAAe,CAAC,EAChB,sBAAuB,CAAC,EACxB,kBAAmB,CAAC,EACpB,yBAA0B,CAAC,EAC3B,gBAAiB,CAAC,EAClB,sBAAuB,CAAC,EACxB,UAAW,CAAC,EACZ,OAAQ,CAAC,EACT,eAAgB,CAAC,EACjB,iBAAkB,CAAA,CAAC,CAEvB,EAEMC,EAAkB,CACtB,cAAe,CACb,KAAM,CAAC,EACP,iBAAkB,CAAC,EACnB,SAAU,CAAC,EACX,IAAK,CACH,UAAW,CAAC,EACZ,aAAc,CAAA,CAChB,EACA,oBAAqB,CAAC,EACtB,MAAO,CAAA,CACT,EACA,SAAU,CACR,aAAc,CAAC,EACf,KAAM,CAAC,EACP,WAAY,CAAC,EACb,SAAU,CAAC,EACX,WAAY,CAAC,EACb,iBAAkB,CAAC,EACnB,oBAAqB,CAAA,CAAC,CAE1B,EAEMC,EAAa,CACjB,GAAGF,EACH,GAAGC,CACL,EAEaE,EAAS,CACpB,KAAM,OACN,MAAO,OACT,EAGaC,EAAW,IAElBC,EAAyB,OAAO,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