@scalar/workspace-store 0.18.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/client.d.ts.map +1 -1
  3. package/dist/client.js +1 -1
  4. package/dist/client.js.map +2 -2
  5. package/dist/events/bus.d.ts +14 -4
  6. package/dist/events/bus.d.ts.map +1 -1
  7. package/dist/events/bus.js +12 -10
  8. package/dist/events/bus.js.map +2 -2
  9. package/dist/events/definitions/analytics.d.ts +3 -3
  10. package/dist/events/definitions/analytics.d.ts.map +1 -1
  11. package/dist/events/definitions/auth.d.ts +59 -14
  12. package/dist/events/definitions/auth.d.ts.map +1 -1
  13. package/dist/events/definitions/common.d.ts +5 -0
  14. package/dist/events/definitions/common.d.ts.map +1 -0
  15. package/dist/events/definitions/common.js +1 -0
  16. package/dist/events/definitions/common.js.map +7 -0
  17. package/dist/events/definitions/document.d.ts +2 -2
  18. package/dist/events/definitions/environment.d.ts +37 -0
  19. package/dist/events/definitions/environment.d.ts.map +1 -0
  20. package/dist/events/definitions/environment.js +1 -0
  21. package/dist/events/definitions/environment.js.map +7 -0
  22. package/dist/events/definitions/index.d.ts +3 -1
  23. package/dist/events/definitions/index.d.ts.map +1 -1
  24. package/dist/events/definitions/meta.d.ts +9 -3
  25. package/dist/events/definitions/meta.d.ts.map +1 -1
  26. package/dist/events/definitions/operation.d.ts +200 -0
  27. package/dist/events/definitions/operation.d.ts.map +1 -1
  28. package/dist/events/definitions/ui.d.ts +5 -0
  29. package/dist/events/definitions/ui.d.ts.map +1 -1
  30. package/dist/events/index.d.ts +1 -0
  31. package/dist/events/index.d.ts.map +1 -1
  32. package/dist/events/index.js.map +2 -2
  33. package/dist/helpers/generate-unique-value.d.ts +40 -0
  34. package/dist/helpers/generate-unique-value.d.ts.map +1 -0
  35. package/dist/helpers/generate-unique-value.js +42 -0
  36. package/dist/helpers/generate-unique-value.js.map +7 -0
  37. package/dist/helpers/overrides-proxy.d.ts.map +1 -1
  38. package/dist/helpers/overrides-proxy.js +1 -1
  39. package/dist/helpers/overrides-proxy.js.map +2 -2
  40. package/dist/helpers/unpack-proxy.d.ts +1 -1
  41. package/dist/helpers/unpack-proxy.d.ts.map +1 -1
  42. package/dist/helpers/unpack-proxy.js.map +2 -2
  43. package/dist/mutators/auth.d.ts +210 -0
  44. package/dist/mutators/auth.d.ts.map +1 -0
  45. package/dist/mutators/auth.js +223 -0
  46. package/dist/mutators/auth.js.map +7 -0
  47. package/dist/mutators/environment.d.ts +21 -13
  48. package/dist/mutators/environment.d.ts.map +1 -1
  49. package/dist/mutators/environment.js +46 -25
  50. package/dist/mutators/environment.js.map +2 -2
  51. package/dist/mutators/index.d.ts +6 -12
  52. package/dist/mutators/index.d.ts.map +1 -1
  53. package/dist/mutators/index.js +45 -4
  54. package/dist/mutators/index.js.map +2 -2
  55. package/dist/mutators/operation.d.ts +313 -0
  56. package/dist/mutators/operation.d.ts.map +1 -0
  57. package/dist/mutators/operation.js +340 -0
  58. package/dist/mutators/operation.js.map +7 -0
  59. package/dist/schemas/extensions/document/x-scalar-environments.d.ts +52 -0
  60. package/dist/schemas/extensions/document/x-scalar-environments.d.ts.map +1 -0
  61. package/dist/schemas/extensions/document/x-scalar-environments.js +25 -0
  62. package/dist/schemas/extensions/document/x-scalar-environments.js.map +7 -0
  63. package/dist/schemas/extensions/operation/x-scalar-operation-identifiers.d.ts +13 -0
  64. package/dist/schemas/extensions/operation/x-scalar-operation-identifiers.d.ts.map +1 -0
  65. package/dist/schemas/extensions/operation/x-scalar-operation-identifiers.js +9 -0
  66. package/dist/schemas/extensions/operation/x-scalar-operation-identifiers.js.map +7 -0
  67. package/dist/schemas/extensions/operation/x-scalar-selected-content-type.d.ts +21 -0
  68. package/dist/schemas/extensions/operation/x-scalar-selected-content-type.d.ts.map +1 -0
  69. package/dist/schemas/extensions/operation/x-scalar-selected-content-type.js +8 -0
  70. package/dist/schemas/extensions/operation/x-scalar-selected-content-type.js.map +7 -0
  71. package/dist/schemas/extensions/security/x-scalar-selected-security.d.ts +17 -0
  72. package/dist/schemas/extensions/security/x-scalar-selected-security.d.ts.map +1 -0
  73. package/dist/schemas/extensions/security/x-scalar-selected-security.js +14 -0
  74. package/dist/schemas/extensions/security/x-scalar-selected-security.js.map +7 -0
  75. package/dist/schemas/extensions/workspace/x-scalar-active-environment.d.ts +8 -0
  76. package/dist/schemas/extensions/workspace/x-scalar-active-environment.d.ts.map +1 -0
  77. package/dist/schemas/extensions/workspace/x-scalar-active-environment.js +8 -0
  78. package/dist/schemas/extensions/workspace/x-scalar-active-environment.js.map +7 -0
  79. package/dist/schemas/inmemory-workspace.d.ts +56 -24
  80. package/dist/schemas/inmemory-workspace.d.ts.map +1 -1
  81. package/dist/schemas/reference-config/index.d.ts +28 -12
  82. package/dist/schemas/reference-config/index.d.ts.map +1 -1
  83. package/dist/schemas/reference-config/settings.d.ts +28 -12
  84. package/dist/schemas/reference-config/settings.d.ts.map +1 -1
  85. package/dist/schemas/v3.1/strict/openapi-document.d.ts +956 -413
  86. package/dist/schemas/v3.1/strict/openapi-document.d.ts.map +1 -1
  87. package/dist/schemas/v3.1/strict/openapi-document.js +9 -6
  88. package/dist/schemas/v3.1/strict/openapi-document.js.map +2 -2
  89. package/dist/schemas/v3.1/strict/operation.d.ts +10 -6
  90. package/dist/schemas/v3.1/strict/operation.d.ts.map +1 -1
  91. package/dist/schemas/v3.1/strict/operation.js +9 -7
  92. package/dist/schemas/v3.1/strict/operation.js.map +2 -2
  93. package/dist/schemas/v3.1/strict/request-body.d.ts +6 -3
  94. package/dist/schemas/v3.1/strict/request-body.d.ts.map +1 -1
  95. package/dist/schemas/v3.1/strict/request-body.js +15 -8
  96. package/dist/schemas/v3.1/strict/request-body.js.map +2 -2
  97. package/dist/schemas/workspace-specification/config.d.ts +28 -12
  98. package/dist/schemas/workspace-specification/config.d.ts.map +1 -1
  99. package/dist/schemas/workspace-specification/index.d.ts +28 -12
  100. package/dist/schemas/workspace-specification/index.d.ts.map +1 -1
  101. package/dist/schemas/workspace.d.ts +227 -103
  102. package/dist/schemas/workspace.d.ts.map +1 -1
  103. package/dist/schemas/workspace.js +16 -10
  104. package/dist/schemas/workspace.js.map +2 -2
  105. package/package.json +9 -4
  106. package/dist/schemas/v3.1/strict/client-config-extensions/x-scalar-client-config-environments.d.ts +0 -33
  107. package/dist/schemas/v3.1/strict/client-config-extensions/x-scalar-client-config-environments.d.ts.map +0 -1
  108. package/dist/schemas/v3.1/strict/client-config-extensions/x-scalar-client-config-environments.js +0 -23
  109. package/dist/schemas/v3.1/strict/client-config-extensions/x-scalar-client-config-environments.js.map +0 -7
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/helpers/overrides-proxy.ts"],
4
- "sourcesContent": ["import { isObject } from '@/helpers/general'\n\nconst isOverridesProxy = Symbol('isOverridesProxy')\nexport const getOverridesTarget = Symbol('getOverridesTarget')\n\n/**\n * Recursively makes all properties of a type optional.\n *\n * - If T is an object, recursively applies DeepPartial to each property, making them optional.\n * - Otherwise, T is returned as-is.\n *\n * @template T - The type to make deeply partial (optional).\n * @example\n * type Example = { a: { b: number } }\n * type PartialExample = DeepPartial<Example>\n * // Result: { a?: { b?: number } }\n */\nexport type DeepPartial<T> = T extends object ? { [K in keyof T]?: DeepPartial<T[K]> } : T\n\n/**\n * Creates a proxy object that overlays \"overrides\" on top of a target object.\n *\n * - When reading a property, if an override exists, it is returned; otherwise, the original value is returned.\n * - When writing to a property, if an override exists, it is updated; otherwise, the original object is updated.\n * - This works recursively for nested objects, so overrides can be deeply partial.\n * - Special symbols are used to identify the proxy and to access the original target.\n *\n * @template T - The type of the target object.\n * @param target - The original object to proxy.\n * @param overrides - An optional object containing override values (deeply partial).\n * @returns A proxy object that reflects overrides on top of the target.\n *\n * @example\n * const original = { a: 1, b: { c: 2 } }\n * const overrides = { b: { c: 42 } }\n * const proxy = createOverridesProxy(original, { overrides })\n *\n * console.log(proxy.a) // 1 (from original)\n * console.log(proxy.b.c) // 42 (from overrides)\n *\n * proxy.a = 100\n * console.log(original.a) // 100\n *\n * proxy.b.c = 99\n * console.log(overrides.b.c) // 99\n */\nexport const createOverridesProxy = <T extends Record<string, unknown>>(\n target: T,\n options?: {\n overrides?: DeepPartial<T>\n },\n args: {\n cache: WeakMap<object, any>\n } = {\n cache: new WeakMap(),\n },\n): T => {\n if (!target || typeof target !== 'object') {\n return target\n }\n\n // Return existing proxy for the same target to ensure referential stability\n if (args.cache.has(target)) {\n return args.cache.get(target)!\n }\n\n const { overrides } = options ?? {}\n\n // Proxy handler to intercept get/set operations\n const handler: ProxyHandler<T> = {\n get(target, prop, receiver) {\n // Special symbol to identify this as an overrides proxy\n if (prop === isOverridesProxy) {\n return true\n }\n\n // Special symbol to access the original target object\n if (prop === getOverridesTarget) {\n return target\n }\n\n const value = Reflect.get(target, prop, receiver)\n\n // Return early if the value is already an overrides proxy\n if (isOverridesProxyObject(value)) {\n return value\n }\n\n // If the value is not an object, return the override if it exists, else the original value\n if (!isObject(value)) {\n return Reflect.get(overrides ?? {}, prop) ?? value\n }\n\n // For nested objects, recursively create a proxy with the corresponding overrides\n return createOverridesProxy(value, { overrides: Reflect.get(overrides ?? {}, prop) }, args)\n },\n\n set(target, prop, value, receiver) {\n // Prevent setting special symbols\n if (prop === isOverridesProxy || prop === getOverridesTarget) {\n return false\n }\n\n // If an override exists for this property, update it\n const hasOverride = overrides && Reflect.has(overrides, prop)\n\n if (hasOverride && overrides && typeof overrides === 'object') {\n ;(overrides as any)[prop] = value\n return true\n }\n\n // Otherwise, update the original target\n return Reflect.set(target, prop, value, receiver)\n },\n }\n\n // Return the proxy object\n const proxy = new Proxy<T>(target, handler)\n args.cache.set(target, proxy)\n return proxy\n}\n\nexport const isOverridesProxyObject = (obj: unknown): boolean => {\n return typeof obj === 'object' && obj !== null && (obj as { [isOverridesProxy]: boolean })[isOverridesProxy] === true\n}\n\n/**\n * Unpacks an object from the overrides proxy, returning the original (unproxied) target object.\n * If the input is not an overrides proxy, returns the object as-is.\n *\n * @param input - The potentially proxied object\n * @returns The original unproxied target object or the input object\n */\nexport function unpackOverridesProxy<T>(input: T): T {\n if ((input as T & { [isOverridesProxy]: boolean | undefined })[isOverridesProxy]) {\n return (input as T & { [getOverridesTarget]: T })[getOverridesTarget]\n }\n\n return input\n}\n"],
5
- "mappings": "AAAA,SAAS,gBAAgB;AAEzB,MAAM,mBAAmB,OAAO,kBAAkB;AAC3C,MAAM,qBAAqB,OAAO,oBAAoB;AA2CtD,MAAM,uBAAuB,CAClC,QACA,SAGA,OAEI;AAAA,EACF,OAAO,oBAAI,QAAQ;AACrB,MACM;AACN,MAAI,CAAC,UAAU,OAAO,WAAW,UAAU;AACzC,WAAO;AAAA,EACT;AAGA,MAAI,KAAK,MAAM,IAAI,MAAM,GAAG;AAC1B,WAAO,KAAK,MAAM,IAAI,MAAM;AAAA,EAC9B;AAEA,QAAM,EAAE,UAAU,IAAI,WAAW,CAAC;AAGlC,QAAM,UAA2B;AAAA,IAC/B,IAAIA,SAAQ,MAAM,UAAU;AAE1B,UAAI,SAAS,kBAAkB;AAC7B,eAAO;AAAA,MACT;AAGA,UAAI,SAAS,oBAAoB;AAC/B,eAAOA;AAAA,MACT;AAEA,YAAM,QAAQ,QAAQ,IAAIA,SAAQ,MAAM,QAAQ;AAGhD,UAAI,uBAAuB,KAAK,GAAG;AACjC,eAAO;AAAA,MACT;AAGA,UAAI,CAAC,SAAS,KAAK,GAAG;AACpB,eAAO,QAAQ,IAAI,aAAa,CAAC,GAAG,IAAI,KAAK;AAAA,MAC/C;AAGA,aAAO,qBAAqB,OAAO,EAAE,WAAW,QAAQ,IAAI,aAAa,CAAC,GAAG,IAAI,EAAE,GAAG,IAAI;AAAA,IAC5F;AAAA,IAEA,IAAIA,SAAQ,MAAM,OAAO,UAAU;AAEjC,UAAI,SAAS,oBAAoB,SAAS,oBAAoB;AAC5D,eAAO;AAAA,MACT;AAGA,YAAM,cAAc,aAAa,QAAQ,IAAI,WAAW,IAAI;AAE5D,UAAI,eAAe,aAAa,OAAO,cAAc,UAAU;AAC7D;AAAC,QAAC,UAAkB,IAAI,IAAI;AAC5B,eAAO;AAAA,MACT;AAGA,aAAO,QAAQ,IAAIA,SAAQ,MAAM,OAAO,QAAQ;AAAA,IAClD;AAAA,EACF;AAGA,QAAM,QAAQ,IAAI,MAAS,QAAQ,OAAO;AAC1C,OAAK,MAAM,IAAI,QAAQ,KAAK;AAC5B,SAAO;AACT;AAEO,MAAM,yBAAyB,CAAC,QAA0B;AAC/D,SAAO,OAAO,QAAQ,YAAY,QAAQ,QAAS,IAAwC,gBAAgB,MAAM;AACnH;AASO,SAAS,qBAAwB,OAAa;AACnD,MAAK,MAA0D,gBAAgB,GAAG;AAChF,WAAQ,MAA0C,kBAAkB;AAAA,EACtE;AAEA,SAAO;AACT;",
4
+ "sourcesContent": ["import { isObject } from '@/helpers/general'\n\nconst isOverridesProxy = Symbol('isOverridesProxy')\nexport const getOverridesTarget = Symbol('getOverridesTarget')\n\n/**\n * Recursively makes all properties of a type optional.\n *\n * - If T is an object, recursively applies DeepPartial to each property, making them optional.\n * - Otherwise, T is returned as-is.\n *\n * @template T - The type to make deeply partial (optional).\n * @example\n * type Example = { a: { b: number } }\n * type PartialExample = DeepPartial<Example>\n * // Result: { a?: { b?: number } }\n */\nexport type DeepPartial<T> = T extends object ? { [K in keyof T]?: DeepPartial<T[K]> } : T\n\n/**\n * Creates a proxy object that overlays \"overrides\" on top of a target object.\n *\n * - When reading a property, if an override exists, it is returned; otherwise, the original value is returned.\n * - When writing to a property, if an override exists, it is updated; otherwise, the original object is updated.\n * - This works recursively for nested objects, so overrides can be deeply partial.\n * - Special symbols are used to identify the proxy and to access the original target.\n *\n * @template T - The type of the target object.\n * @param target - The original object to proxy.\n * @param overrides - An optional object containing override values (deeply partial).\n * @returns A proxy object that reflects overrides on top of the target.\n *\n * @example\n * const original = { a: 1, b: { c: 2 } }\n * const overrides = { b: { c: 42 } }\n * const proxy = createOverridesProxy(original, { overrides })\n *\n * console.log(proxy.a) // 1 (from original)\n * console.log(proxy.b.c) // 42 (from overrides)\n *\n * proxy.a = 100\n * console.log(original.a) // 100\n *\n * proxy.b.c = 99\n * console.log(overrides.b.c) // 99\n */\nexport const createOverridesProxy = <T extends Record<string, unknown>>(\n target: T,\n options?: {\n overrides?: DeepPartial<T>\n },\n args: {\n cache: WeakMap<object, any>\n } = {\n cache: new WeakMap(),\n },\n): T => {\n if (!target || typeof target !== 'object') {\n return target\n }\n\n // Return existing proxy for the same target to ensure referential stability\n if (args.cache.has(target)) {\n return args.cache.get(target)!\n }\n\n const { overrides } = options ?? {}\n\n // Proxy handler to intercept get/set operations\n const handler: ProxyHandler<T> = {\n get(target, prop, receiver) {\n // Special symbol to identify this as an overrides proxy\n if (prop === isOverridesProxy) {\n return true\n }\n\n // Special symbol to access the original target object\n if (prop === getOverridesTarget) {\n return target\n }\n\n const value = Reflect.get(target, prop, receiver)\n\n // Return early if the value is already an overrides proxy\n if (isOverridesProxyObject(value)) {\n return value\n }\n\n // If the value is not an object, return the override if it exists, else the original value\n if (!isObject(value)) {\n return Reflect.get(overrides ?? {}, prop) ?? value\n }\n\n // For nested objects, recursively create a proxy with the corresponding overrides\n return createOverridesProxy(value, { overrides: Reflect.get(overrides ?? {}, prop) }, args)\n },\n\n set(target, prop, value, receiver) {\n // Prevent setting special symbols\n if (prop === isOverridesProxy || prop === getOverridesTarget) {\n return false\n }\n\n // If an override exists for this property, update it\n const hasOverride = overrides && Reflect.has(overrides, prop)\n\n if (hasOverride && overrides && typeof overrides === 'object') {\n ;(overrides as any)[prop] = value\n return true\n }\n\n // Otherwise, update the original target\n return Reflect.set(target, prop, value, receiver)\n },\n }\n\n // Return the proxy object\n const proxy = new Proxy<T>(target, handler)\n args.cache.set(target, proxy)\n return proxy\n}\n\nexport const isOverridesProxyObject = (obj: unknown): boolean => {\n return typeof obj === 'object' && obj !== null && (obj as { [isOverridesProxy]: boolean })[isOverridesProxy] === true\n}\n\n/**\n * Unpacks an object from the overrides proxy, returning the original (unproxied) target object.\n * If the input is not an overrides proxy, returns the object as-is.\n *\n * @param input - The potentially proxied object\n * @returns The original unproxied target object or the input object\n */\nexport function unpackOverridesProxy<T>(input: T): T {\n if (\n typeof input === 'object' &&\n input !== null &&\n (input as T & { [isOverridesProxy]: boolean | undefined })[isOverridesProxy]\n ) {\n return (input as T & { [getOverridesTarget]: T })[getOverridesTarget]\n }\n\n return input\n}\n"],
5
+ "mappings": "AAAA,SAAS,gBAAgB;AAEzB,MAAM,mBAAmB,OAAO,kBAAkB;AAC3C,MAAM,qBAAqB,OAAO,oBAAoB;AA2CtD,MAAM,uBAAuB,CAClC,QACA,SAGA,OAEI;AAAA,EACF,OAAO,oBAAI,QAAQ;AACrB,MACM;AACN,MAAI,CAAC,UAAU,OAAO,WAAW,UAAU;AACzC,WAAO;AAAA,EACT;AAGA,MAAI,KAAK,MAAM,IAAI,MAAM,GAAG;AAC1B,WAAO,KAAK,MAAM,IAAI,MAAM;AAAA,EAC9B;AAEA,QAAM,EAAE,UAAU,IAAI,WAAW,CAAC;AAGlC,QAAM,UAA2B;AAAA,IAC/B,IAAIA,SAAQ,MAAM,UAAU;AAE1B,UAAI,SAAS,kBAAkB;AAC7B,eAAO;AAAA,MACT;AAGA,UAAI,SAAS,oBAAoB;AAC/B,eAAOA;AAAA,MACT;AAEA,YAAM,QAAQ,QAAQ,IAAIA,SAAQ,MAAM,QAAQ;AAGhD,UAAI,uBAAuB,KAAK,GAAG;AACjC,eAAO;AAAA,MACT;AAGA,UAAI,CAAC,SAAS,KAAK,GAAG;AACpB,eAAO,QAAQ,IAAI,aAAa,CAAC,GAAG,IAAI,KAAK;AAAA,MAC/C;AAGA,aAAO,qBAAqB,OAAO,EAAE,WAAW,QAAQ,IAAI,aAAa,CAAC,GAAG,IAAI,EAAE,GAAG,IAAI;AAAA,IAC5F;AAAA,IAEA,IAAIA,SAAQ,MAAM,OAAO,UAAU;AAEjC,UAAI,SAAS,oBAAoB,SAAS,oBAAoB;AAC5D,eAAO;AAAA,MACT;AAGA,YAAM,cAAc,aAAa,QAAQ,IAAI,WAAW,IAAI;AAE5D,UAAI,eAAe,aAAa,OAAO,cAAc,UAAU;AAC7D;AAAC,QAAC,UAAkB,IAAI,IAAI;AAC5B,eAAO;AAAA,MACT;AAGA,aAAO,QAAQ,IAAIA,SAAQ,MAAM,OAAO,QAAQ;AAAA,IAClD;AAAA,EACF;AAGA,QAAM,QAAQ,IAAI,MAAS,QAAQ,OAAO;AAC1C,OAAK,MAAM,IAAI,QAAQ,KAAK;AAC5B,SAAO;AACT;AAEO,MAAM,yBAAyB,CAAC,QAA0B;AAC/D,SAAO,OAAO,QAAQ,YAAY,QAAQ,QAAS,IAAwC,gBAAgB,MAAM;AACnH;AASO,SAAS,qBAAwB,OAAa;AACnD,MACE,OAAO,UAAU,YACjB,UAAU,QACT,MAA0D,gBAAgB,GAC3E;AACA,WAAQ,MAA0C,kBAAkB;AAAA,EACtE;AAEA,SAAO;AACT;",
6
6
  "names": ["target"]
7
7
  }
@@ -2,5 +2,5 @@
2
2
  * Unpacks special vue reactivity & override & detect-changes & magic proxy from an input object or array,
3
3
  * returning the "raw" plain object or array.
4
4
  */
5
- export declare const unpackProxyObject: <T extends object | Array<unknown>>(input: T) => T;
5
+ export declare const unpackProxyObject: <T>(input: T) => T;
6
6
  //# sourceMappingURL=unpack-proxy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"unpack-proxy.d.ts","sourceRoot":"","sources":["../../src/helpers/unpack-proxy.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,KAAG,CACV,CAAA"}
1
+ {"version":3,"file":"unpack-proxy.d.ts","sourceRoot":"","sources":["../../src/helpers/unpack-proxy.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,EAAE,OAAO,CAAC,KAAG,CACsB,CAAA"}
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/helpers/unpack-proxy.ts"],
4
- "sourcesContent": ["import { getRaw } from '@scalar/json-magic/magic-proxy'\nimport { toRaw } from 'vue'\n\nimport { unpackDetectChangesProxy } from '@/helpers/detect-changes-proxy'\nimport { unpackOverridesProxy } from '@/helpers/overrides-proxy'\n\n/**\n * Unpacks special vue reactivity & override & detect-changes & magic proxy from an input object or array,\n * returning the \"raw\" plain object or array.\n */\nexport const unpackProxyObject = <T extends object | Array<unknown>>(input: T): T =>\n unpackDetectChangesProxy(toRaw(getRaw(unpackOverridesProxy(input))))\n"],
5
- "mappings": "AAAA,SAAS,cAAc;AACvB,SAAS,aAAa;AAEtB,SAAS,gCAAgC;AACzC,SAAS,4BAA4B;AAM9B,MAAM,oBAAoB,CAAoC,UACnE,yBAAyB,MAAM,OAAO,qBAAqB,KAAK,CAAC,CAAC,CAAC;",
4
+ "sourcesContent": ["import { getRaw } from '@scalar/json-magic/magic-proxy'\nimport { toRaw } from 'vue'\n\nimport { unpackDetectChangesProxy } from '@/helpers/detect-changes-proxy'\nimport { unpackOverridesProxy } from '@/helpers/overrides-proxy'\n\n/**\n * Unpacks special vue reactivity & override & detect-changes & magic proxy from an input object or array,\n * returning the \"raw\" plain object or array.\n */\nexport const unpackProxyObject = <T>(input: T): T =>\n unpackDetectChangesProxy(toRaw(getRaw(unpackOverridesProxy(input))))\n"],
5
+ "mappings": "AAAA,SAAS,cAAc;AACvB,SAAS,aAAa;AAEtB,SAAS,gCAAgC;AACzC,SAAS,4BAA4B;AAM9B,MAAM,oBAAoB,CAAI,UACnC,yBAAyB,MAAM,OAAO,qBAAqB,KAAK,CAAC,CAAC,CAAC;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,210 @@
1
+ import type { HttpMethod } from '@scalar/helpers/http/http-methods';
2
+ import type { WorkspaceDocument } from '../schemas.js';
3
+ import type { SecurityRequirementObject } from '../schemas/v3.1/strict/security-requirement.js';
4
+ import type { SecuritySchemeObject } from '../schemas/v3.1/strict/security-scheme.js';
5
+ /**
6
+ * AuthMeta defines the meta information needed to specify whether the authentication operation
7
+ * is being performed at the document level (entire API), or for a specific operation (specific path and method).
8
+ *
9
+ * - If type is 'document', the operation applies to the whole OpenAPI document.
10
+ * - If type is 'operation', it targets a specific operation, identified by its path and method.
11
+ */
12
+ export type AuthMeta = {
13
+ type: 'document';
14
+ } | {
15
+ type: 'operation';
16
+ path: string;
17
+ method: HttpMethod;
18
+ };
19
+ /**
20
+ * Updates the selected security schemes for either the entire document or a specific operation.
21
+ * - Adds newly created security schemes (if any) to the workspace document's components.
22
+ * - Ensures that each new scheme name is unique within the document by using `generateUniqueValue`.
23
+ * - Updates the `x-scalar-selected-security` property on the target (document or operation) to reflect the new set of selected security schemes.
24
+ * - Corrects and maintains the selected index so it points to a valid security scheme.
25
+ *
26
+ * @param document - The workspace OpenAPI document to mutate (can be null, in which case nothing happens)
27
+ * @param selectedSecuritySchemes - The current list of selected security scheme objects
28
+ * @param create - Array of new schemes to create, each with a name and a scheme definition
29
+ * @param meta - Location to update: whole document or a specific operation (`{ type: 'document' }` or `{ type: 'operation', path, method }`)
30
+ *
31
+ * Example usage:
32
+ * ```
33
+ * updateSelectedSecuritySchemes({
34
+ * document,
35
+ * selectedSecuritySchemes: [{ bearerAuth: [] }],
36
+ * create: [
37
+ * { name: 'ApiKeyAuth', scheme: { type: 'apiKey', in: 'header', name: 'X-API-Key' } }
38
+ * ],
39
+ * meta: { type: 'document' }
40
+ * })
41
+ * ```
42
+ */
43
+ export declare const updateSelectedSecuritySchemes: ({ document, selectedRequirements, newSchemes, meta, }: {
44
+ document: WorkspaceDocument | null;
45
+ selectedRequirements: SecurityRequirementObject[];
46
+ newSchemes: {
47
+ name: string;
48
+ scheme: SecuritySchemeObject;
49
+ }[];
50
+ meta: AuthMeta;
51
+ }) => void;
52
+ /**
53
+ * SecuritySchemeUpdate represents the possible updates that can be made
54
+ * to an OpenAPI security scheme object via UI interactions.
55
+ *
56
+ * - `http`: Updates to HTTP type schemes (e.g. basic, bearer), allowing token, username, and password changes.
57
+ * - `apiKey`: Updates to API Key type schemes, allowing the key name and its value to be updated.
58
+ * - `oauth2`: Updates to OAuth2 type schemes for each supported OAuth2 flow.
59
+ * - Can set various properties such as auth/token URLs, tokens, PKCE method, client credentials, etc.
60
+ */
61
+ export type SecuritySchemeUpdate = {
62
+ type: 'http';
63
+ payload: Partial<{
64
+ token: string;
65
+ username: string;
66
+ password: string;
67
+ }>;
68
+ } | {
69
+ type: 'apiKey';
70
+ payload: Partial<{
71
+ name: string;
72
+ value: string;
73
+ }>;
74
+ } | {
75
+ type: 'oauth2';
76
+ flow: 'implicit' | 'password' | 'clientCredentials' | 'authorizationCode';
77
+ payload: Partial<{
78
+ authUrl: string;
79
+ tokenUrl: string;
80
+ token: string;
81
+ redirectUrl: string;
82
+ clientId: string;
83
+ clientSecret: string;
84
+ usePkce: 'no' | 'SHA-256' | 'plain';
85
+ username: string;
86
+ password: string;
87
+ }>;
88
+ };
89
+ /**
90
+ * Updates a security scheme in the OpenAPI document's components object.
91
+ * Handles updates for HTTP, API Key, and OAuth2 types, saving secret information and configuration for UI-auth flows.
92
+ *
93
+ * @param document - The OpenAPI workspace document (can be null)
94
+ * @param data - The update information, including type and payload
95
+ * @param name - The name of the security scheme in document.components.securitySchemes
96
+ *
97
+ * Example usage:
98
+ *
99
+ * updateSecurityScheme({
100
+ * document,
101
+ * data: {
102
+ * type: 'http',
103
+ * payload: {
104
+ * username: 'user123',
105
+ * password: 'pw123',
106
+ * token: 'tokenval'
107
+ * }
108
+ * },
109
+ * name: 'MyHttpAuth',
110
+ * })
111
+ */
112
+ export declare const updateSecurityScheme: ({ document, data, name, }: {
113
+ document: WorkspaceDocument | null;
114
+ data: SecuritySchemeUpdate;
115
+ name: string;
116
+ }) => void;
117
+ /**
118
+ * Sets the selected authentication tab (scheme) index for the given OpenAPI document or operation.
119
+ * - When on the document level, updates the 'x-selected-index' on the document's x-scalar-selected-security extension.
120
+ * - When on an operation (endpoint) level, updates the 'x-selected-index' for that operation's x-scalar-selected-security.
121
+ *
122
+ * Also initializes the x-scalar-selected-security extension if it does not exist.
123
+ *
124
+ * @param document The OpenAPI document object (may be null)
125
+ * @param index The index to set as selected
126
+ * @param meta Context where the selection applies ('document' or specific operation)
127
+ *
128
+ * @example
129
+ * // Document-level tab selection
130
+ * updateSelectedAuthTab({
131
+ * document,
132
+ * index: 1,
133
+ * meta: { type: 'document' }
134
+ * });
135
+ *
136
+ * // Operation-level tab selection (e.g., GET /pets)
137
+ * updateSelectedAuthTab({
138
+ * document,
139
+ * index: 0,
140
+ * meta: { type: 'operation', path: '/pets', method: 'get' }
141
+ * });
142
+ */
143
+ export declare const updateSelectedAuthTab: ({ document, index, meta, }: {
144
+ document: WorkspaceDocument | null;
145
+ index: number;
146
+ meta: AuthMeta;
147
+ }) => void;
148
+ /**
149
+ * Updates the scopes for a specific security requirement in the selected security schemes of
150
+ * a document or operation.
151
+ *
152
+ * @param document - The OpenAPI WorkspaceDocument to update.
153
+ * @param id - An array of scheme names that uniquely identifies the target security requirement.
154
+ * For example: ['OAuth', 'ApiKeyAuth']
155
+ * @param name - The security scheme name to update scopes for (e.g., 'OAuth').
156
+ * @param scopes - The new list of scopes to set. For example: ['read:pets', 'write:pets']
157
+ * @param meta - The context specifying whether the update is at the document-level or operation-level.
158
+ *
159
+ * Example usage:
160
+ * ```ts
161
+ * // Suppose your document (or operation) x-scalar-selected-security looks like:
162
+ * // "x-scalar-selected-security": {
163
+ * // "x-selected-index": 0,
164
+ * // "x-schemes": [
165
+ * // { "OAuth": ["read:pets"] },
166
+ * // { "ApiKeyAuth": [] }
167
+ * // ]
168
+ * // }
169
+ *
170
+ * updateSelectedScopes({
171
+ * document,
172
+ * id: ["OAuth"], // identifies the scheme object: { "OAuth": [...] }
173
+ * name: "OAuth", // scheme name to update within this security requirement
174
+ * scopes: ["write:pets"], // new scopes array
175
+ * meta: { type: "document" }
176
+ * })
177
+ * // After, the first scheme becomes: { "OAuth": ["write:pets"] }
178
+ * ```
179
+ */
180
+ export declare const updateSelectedScopes: ({ document, id, name, scopes, meta, }: {
181
+ document: WorkspaceDocument | null;
182
+ id: string[];
183
+ name: string;
184
+ scopes: string[];
185
+ meta: AuthMeta;
186
+ }) => void;
187
+ /**
188
+ * Deletes one or more security schemes from an OpenAPI WorkspaceDocument,
189
+ * and removes all references to those schemes from selected security, document-level security,
190
+ * and operation-level security/selected security (e.g., on paths).
191
+ *
192
+ * Example usage:
193
+ *
194
+ * ```ts
195
+ * deleteSecurityScheme({
196
+ * document, // The OpenAPI document to update
197
+ * names: ['ApiKeyAuth', 'BearerAuth'], // The names of security schemes you want to delete
198
+ * });
199
+ * ```
200
+ *
201
+ * After running this function:
202
+ * - The named security schemes are removed from the components.securitySchemes section.
203
+ * - All document-level and operation-level security entries referencing those schemes are removed.
204
+ * - Any extended x-scalar-selected-security references to those schemes are also removed.
205
+ */
206
+ export declare const deleteSecurityScheme: ({ document, names }: {
207
+ document: WorkspaceDocument | null;
208
+ names: string[];
209
+ }) => void;
210
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/mutators/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAA;AAInE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAClD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,4CAA4C,CAAA;AAC3F,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAA;AAEjF;;;;;;GAMG;AACH,MAAM,MAAM,QAAQ,GAChB;IACE,IAAI,EAAE,UAAU,CAAA;CACjB,GACD;IACE,IAAI,EAAE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;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,oBAAoB,GAAI,2BAIlC;IACD,QAAQ,EAAE,iBAAiB,GAAG,IAAI,CAAA;IAClC,IAAI,EAAE,oBAAoB,CAAA;IAC1B,IAAI,EAAE,MAAM,CAAA;CACb,SAwEA,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,qBAAqB,GAAI,4BAInC;IACD,QAAQ,EAAE,iBAAiB,GAAG,IAAI,CAAA;IAClC,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,QAAQ,CAAA;CACf,SA8BA,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,oBAAoB,GAAI,uCAMlC;IACD,QAAQ,EAAE,iBAAiB,GAAG,IAAI,CAAA;IAClC,EAAE,EAAE,MAAM,EAAE,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,EAAE,CAAA;IAChB,IAAI,EAAE,QAAQ,CAAA;CACf,SAoCA,CAAA;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,oBAAoB,GAAI,qBAAqB;IAAE,QAAQ,EAAE,iBAAiB,GAAG,IAAI,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,SA4DhH,CAAA"}
@@ -0,0 +1,223 @@
1
+ import { generateUniqueValue } from "../helpers/generate-unique-value.js";
2
+ import { getResolvedRef } from "../helpers/get-resolved-ref.js";
3
+ const updateSelectedSecuritySchemes = ({
4
+ document,
5
+ selectedRequirements,
6
+ newSchemes,
7
+ meta
8
+ }) => {
9
+ if (!document) {
10
+ return;
11
+ }
12
+ const getTarget = () => {
13
+ if (meta.type === "document") {
14
+ return document;
15
+ }
16
+ return getResolvedRef(document.paths?.[meta.path]?.[meta.method]);
17
+ };
18
+ const createdSchemes = newSchemes.map((scheme) => {
19
+ const name = generateUniqueValue({
20
+ defaultValue: scheme.name,
21
+ validation: (value) => !document.components?.securitySchemes?.[value],
22
+ maxRetries: 100
23
+ });
24
+ if (!name) {
25
+ return;
26
+ }
27
+ if (!document.components) {
28
+ document.components = {};
29
+ }
30
+ if (!document.components.securitySchemes) {
31
+ document.components.securitySchemes = {};
32
+ }
33
+ document.components.securitySchemes[name] = scheme.scheme;
34
+ return {
35
+ [name]: []
36
+ };
37
+ }).filter(Boolean);
38
+ const target = getTarget();
39
+ const newSelectedSecuritySchemes = [...selectedRequirements, ...createdSchemes];
40
+ if (!target) {
41
+ return;
42
+ }
43
+ if (!target["x-scalar-selected-security"]) {
44
+ target["x-scalar-selected-security"] = {
45
+ "x-selected-index": -1,
46
+ "x-schemes": []
47
+ };
48
+ }
49
+ const selectedIndex = target["x-scalar-selected-security"]["x-selected-index"];
50
+ target["x-scalar-selected-security"]["x-schemes"] = newSelectedSecuritySchemes;
51
+ if (newSelectedSecuritySchemes.length > 0 && selectedIndex < 0) {
52
+ target["x-scalar-selected-security"]["x-selected-index"] = 0;
53
+ }
54
+ if (selectedIndex >= newSelectedSecuritySchemes.length) {
55
+ target["x-scalar-selected-security"]["x-selected-index"] = newSelectedSecuritySchemes.length - 1;
56
+ }
57
+ };
58
+ const updateSecurityScheme = ({
59
+ document,
60
+ data,
61
+ name
62
+ }) => {
63
+ if (!document) {
64
+ return;
65
+ }
66
+ const target = getResolvedRef(document.components?.securitySchemes?.[name]);
67
+ if (!target) {
68
+ return;
69
+ }
70
+ if (target.type === "http" && data.type === "http") {
71
+ if (data.payload.username) {
72
+ target["x-scalar-secret-username"] = data.payload.username;
73
+ }
74
+ if (data.payload.password) {
75
+ target["x-scalar-secret-password"] = data.payload.password;
76
+ }
77
+ if (data.payload.token) {
78
+ target["x-scalar-secret-token"] = data.payload.token;
79
+ }
80
+ } else if (target.type === "apiKey" && data.type === "apiKey") {
81
+ if (data.payload.name) {
82
+ target.name = data.payload.name;
83
+ }
84
+ if (data.payload.value) {
85
+ target["x-scalar-secret-token"] = data.payload.value;
86
+ }
87
+ } else if (target.type === "oauth2" && data.type === "oauth2") {
88
+ const flow = target.flows[data.flow];
89
+ if (!flow) {
90
+ return;
91
+ }
92
+ if (data.payload.authUrl && "authorizationUrl" in flow) {
93
+ flow.authorizationUrl = data.payload.authUrl;
94
+ }
95
+ if (data.payload.tokenUrl && "tokenUrl" in flow) {
96
+ flow.tokenUrl = data.payload.tokenUrl;
97
+ }
98
+ if (data.payload.token && "x-scalar-secret-token" in flow) {
99
+ flow["x-scalar-secret-token"] = data.payload.token;
100
+ }
101
+ if (data.payload.redirectUrl && "x-scalar-secret-redirect-uri" in flow) {
102
+ flow["x-scalar-secret-redirect-uri"] = data.payload.redirectUrl;
103
+ }
104
+ if (data.payload.clientId && "x-scalar-secret-client-id" in flow) {
105
+ flow["x-scalar-secret-client-id"] = data.payload.clientId;
106
+ }
107
+ if (data.payload.clientSecret && "x-scalar-secret-client-secret" in flow) {
108
+ flow["x-scalar-secret-client-secret"] = data.payload.clientSecret;
109
+ }
110
+ if (data.payload.usePkce && "x-usePkce" in flow) {
111
+ flow["x-usePkce"] = data.payload.usePkce;
112
+ }
113
+ if (data.payload.username && "x-scalar-secret-username" in flow) {
114
+ flow["x-scalar-secret-username"] = data.payload.username;
115
+ }
116
+ if (data.payload.password && "x-scalar-secret-password" in flow) {
117
+ flow["x-scalar-secret-password"] = data.payload.password;
118
+ }
119
+ }
120
+ return;
121
+ };
122
+ const updateSelectedAuthTab = ({
123
+ document,
124
+ index,
125
+ meta
126
+ }) => {
127
+ if (!document) {
128
+ return;
129
+ }
130
+ const getTarget = () => {
131
+ if (meta.type === "document") {
132
+ return document;
133
+ }
134
+ return getResolvedRef(document.paths?.[meta.path]?.[meta.method]);
135
+ };
136
+ const target = getTarget();
137
+ if (!target) {
138
+ return;
139
+ }
140
+ if (!target["x-scalar-selected-security"]) {
141
+ target["x-scalar-selected-security"] = {
142
+ "x-selected-index": 0,
143
+ "x-schemes": []
144
+ };
145
+ }
146
+ target["x-scalar-selected-security"]["x-selected-index"] = index;
147
+ };
148
+ const updateSelectedScopes = ({
149
+ document,
150
+ id,
151
+ name,
152
+ scopes,
153
+ meta
154
+ }) => {
155
+ if (!document) {
156
+ return;
157
+ }
158
+ const getTarget = () => {
159
+ if (meta.type === "document") {
160
+ return document;
161
+ }
162
+ return getResolvedRef(document.paths?.[meta.path]?.[meta.method]);
163
+ };
164
+ const target = getTarget();
165
+ if (!target) {
166
+ return;
167
+ }
168
+ const selectedSchemes = target["x-scalar-selected-security"]?.["x-schemes"];
169
+ if (!selectedSchemes) {
170
+ return;
171
+ }
172
+ const scheme = selectedSchemes.find((scheme2) => JSON.stringify(Object.keys(scheme2)) === JSON.stringify(id));
173
+ if (!scheme) {
174
+ return;
175
+ }
176
+ scheme[name] = scopes;
177
+ };
178
+ const deleteSecurityScheme = ({ document, names }) => {
179
+ if (!document) {
180
+ return;
181
+ }
182
+ const target = getResolvedRef(document.components?.securitySchemes);
183
+ if (!target) {
184
+ return;
185
+ }
186
+ names.forEach((name) => {
187
+ delete target[name];
188
+ });
189
+ const filterSecuritySchemes = (schemes) => {
190
+ return schemes.filter((scheme) => !names.some((name) => Object.keys(scheme).includes(name)));
191
+ };
192
+ if (document["x-scalar-selected-security"]) {
193
+ const selectedSecurity = document["x-scalar-selected-security"];
194
+ selectedSecurity["x-schemes"] = filterSecuritySchemes(selectedSecurity["x-schemes"]);
195
+ }
196
+ if (document["security"]) {
197
+ document["security"] = filterSecuritySchemes(document["security"]);
198
+ }
199
+ Object.values(document.paths ?? {}).forEach((path) => {
200
+ Object.values(path).forEach((operation) => {
201
+ if (typeof operation !== "object") {
202
+ return;
203
+ }
204
+ const resolvedOperation = getResolvedRef(operation);
205
+ if ("security" in resolvedOperation && resolvedOperation["security"]) {
206
+ resolvedOperation["security"] = filterSecuritySchemes(resolvedOperation["security"]);
207
+ }
208
+ if ("x-scalar-selected-security" in resolvedOperation && resolvedOperation["x-scalar-selected-security"]) {
209
+ resolvedOperation["x-scalar-selected-security"]["x-schemes"] = filterSecuritySchemes(
210
+ resolvedOperation["x-scalar-selected-security"]["x-schemes"]
211
+ );
212
+ }
213
+ });
214
+ });
215
+ };
216
+ export {
217
+ deleteSecurityScheme,
218
+ updateSecurityScheme,
219
+ updateSelectedAuthTab,
220
+ updateSelectedScopes,
221
+ updateSelectedSecuritySchemes
222
+ };
223
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/mutators/auth.ts"],
4
+ "sourcesContent": ["import type { HttpMethod } from '@scalar/helpers/http/http-methods'\n\nimport { generateUniqueValue } from '@/helpers/generate-unique-value'\nimport { getResolvedRef } from '@/helpers/get-resolved-ref'\nimport type { WorkspaceDocument } from '@/schemas'\nimport type { SecurityRequirementObject } from '@/schemas/v3.1/strict/security-requirement'\nimport type { SecuritySchemeObject } from '@/schemas/v3.1/strict/security-scheme'\n\n/**\n * AuthMeta defines the meta information needed to specify whether the authentication operation\n * is being performed at the document level (entire API), or for a specific operation (specific path and method).\n *\n * - If type is 'document', the operation applies to the whole OpenAPI document.\n * - If type is 'operation', it targets a specific operation, identified by its path and method.\n */\nexport type AuthMeta =\n | {\n type: 'document'\n }\n | {\n type: 'operation'\n path: string\n method: HttpMethod\n }\n\n/**\n * Updates the selected security schemes for either the entire document or a specific operation.\n * - Adds newly created security schemes (if any) to the workspace document's components.\n * - Ensures that each new scheme name is unique within the document by using `generateUniqueValue`.\n * - Updates the `x-scalar-selected-security` property on the target (document or operation) to reflect the new set of selected security schemes.\n * - Corrects and maintains the selected index so it points to a valid security scheme.\n *\n * @param document - The workspace OpenAPI document to mutate (can be null, in which case nothing happens)\n * @param selectedSecuritySchemes - The current list of selected security scheme objects\n * @param create - Array of new schemes to create, each with a name and a scheme definition\n * @param meta - Location to update: whole document or a specific operation (`{ type: 'document' }` or `{ type: 'operation', path, method }`)\n *\n * Example usage:\n * ```\n * updateSelectedSecuritySchemes({\n * document,\n * selectedSecuritySchemes: [{ bearerAuth: [] }],\n * create: [\n * { name: 'ApiKeyAuth', scheme: { type: 'apiKey', in: 'header', name: 'X-API-Key' } }\n * ],\n * meta: { type: 'document' }\n * })\n * ```\n */\nexport const updateSelectedSecuritySchemes = ({\n document,\n selectedRequirements,\n newSchemes,\n meta,\n}: {\n document: WorkspaceDocument | null\n selectedRequirements: SecurityRequirementObject[]\n newSchemes: { name: string; scheme: SecuritySchemeObject }[]\n meta: AuthMeta\n}) => {\n if (!document) {\n return\n }\n\n // Helper to get the target (whole document or a specific operation)\n const getTarget = () => {\n if (meta.type === 'document') {\n return document\n }\n\n return getResolvedRef(document.paths?.[meta.path]?.[meta.method])\n }\n\n // Create any new security schemes required, ensuring unique names for the components\n const createdSchemes = newSchemes\n .map((scheme) => {\n const name = generateUniqueValue({\n defaultValue: scheme.name,\n validation: (value) => !document.components?.securitySchemes?.[value],\n maxRetries: 100,\n })\n\n if (!name) {\n return\n }\n\n // Ensure components and securitySchemes exist\n if (!document.components) {\n document.components = {}\n }\n if (!document.components.securitySchemes) {\n document.components.securitySchemes = {}\n }\n\n // Add the new security scheme definition\n document.components.securitySchemes[name] = scheme.scheme\n\n // Return an OpenAPI Security Requirement Object for this new scheme (empty scope array)\n return {\n [name]: [],\n }\n })\n .filter(Boolean) as SecurityRequirementObject[]\n\n const target = getTarget()\n\n const newSelectedSecuritySchemes = [...selectedRequirements, ...createdSchemes]\n\n // If the target (document/operation) doesn't exist, do nothing\n if (!target) {\n return\n }\n\n // Ensure the x-scalar-selected-security structure exists on the target\n if (!target['x-scalar-selected-security']) {\n target['x-scalar-selected-security'] = {\n 'x-selected-index': -1,\n 'x-schemes': [],\n }\n }\n\n const selectedIndex = target['x-scalar-selected-security']['x-selected-index']\n\n // Update the schemes array\n target['x-scalar-selected-security']['x-schemes'] = newSelectedSecuritySchemes\n\n // Adjust selected index if there are schemes and the index is unset/invalid\n if (newSelectedSecuritySchemes.length > 0 && selectedIndex < 0) {\n target['x-scalar-selected-security']['x-selected-index'] = 0\n }\n\n // If the selected index is now out of bounds, select the last available\n if (selectedIndex >= newSelectedSecuritySchemes.length) {\n target['x-scalar-selected-security']['x-selected-index'] = newSelectedSecuritySchemes.length - 1\n }\n}\n\n/**\n * SecuritySchemeUpdate represents the possible updates that can be made\n * to an OpenAPI security scheme object via UI interactions.\n *\n * - `http`: Updates to HTTP type schemes (e.g. basic, bearer), allowing token, username, and password changes.\n * - `apiKey`: Updates to API Key type schemes, allowing the key name and its value to be updated.\n * - `oauth2`: Updates to OAuth2 type schemes for each supported OAuth2 flow.\n * - Can set various properties such as auth/token URLs, tokens, PKCE method, client credentials, etc.\n */\nexport type SecuritySchemeUpdate =\n | {\n type: 'http'\n payload: Partial<{\n token: string\n username: string\n password: string\n }>\n }\n | {\n type: 'apiKey'\n payload: Partial<{\n name: string\n value: string\n }>\n }\n | {\n type: 'oauth2'\n flow: 'implicit' | 'password' | 'clientCredentials' | 'authorizationCode'\n payload: Partial<{\n authUrl: string\n tokenUrl: string\n token: string\n redirectUrl: string\n clientId: string\n clientSecret: string\n usePkce: 'no' | 'SHA-256' | 'plain'\n username: string\n password: string\n }>\n }\n\n/**\n * Updates a security scheme in the OpenAPI document's components object.\n * Handles updates for HTTP, API Key, and OAuth2 types, saving secret information and configuration for UI-auth flows.\n *\n * @param document - The OpenAPI workspace document (can be null)\n * @param data - The update information, including type and payload\n * @param name - The name of the security scheme in document.components.securitySchemes\n *\n * Example usage:\n *\n * updateSecurityScheme({\n * document,\n * data: {\n * type: 'http',\n * payload: {\n * username: 'user123',\n * password: 'pw123',\n * token: 'tokenval'\n * }\n * },\n * name: 'MyHttpAuth',\n * })\n */\nexport const updateSecurityScheme = ({\n document,\n data,\n name,\n}: {\n document: WorkspaceDocument | null\n data: SecuritySchemeUpdate\n name: string\n}) => {\n if (!document) {\n return\n }\n\n const target = getResolvedRef(document.components?.securitySchemes?.[name])\n\n if (!target) {\n return\n }\n\n // Handle HTTP (basic, bearer, etc.)\n if (target.type === 'http' && data.type === 'http') {\n if (data.payload.username) {\n target['x-scalar-secret-username'] = data.payload.username\n }\n if (data.payload.password) {\n target['x-scalar-secret-password'] = data.payload.password\n }\n if (data.payload.token) {\n target['x-scalar-secret-token'] = data.payload.token\n }\n\n // Handle API Key\n } else if (target.type === 'apiKey' && data.type === 'apiKey') {\n if (data.payload.name) {\n target.name = data.payload.name\n }\n if (data.payload.value) {\n target['x-scalar-secret-token'] = data.payload.value\n }\n\n // Handle OAuth2 (various flows)\n } else if (target.type === 'oauth2' && data.type === 'oauth2') {\n const flow = target.flows[data.flow]\n if (!flow) {\n // If the flow is not found, do nothing\n return\n }\n\n if (data.payload.authUrl && 'authorizationUrl' in flow) {\n flow.authorizationUrl = data.payload.authUrl\n }\n if (data.payload.tokenUrl && 'tokenUrl' in flow) {\n flow.tokenUrl = data.payload.tokenUrl\n }\n if (data.payload.token && 'x-scalar-secret-token' in flow) {\n flow['x-scalar-secret-token'] = data.payload.token\n }\n if (data.payload.redirectUrl && 'x-scalar-secret-redirect-uri' in flow) {\n flow['x-scalar-secret-redirect-uri'] = data.payload.redirectUrl\n }\n if (data.payload.clientId && 'x-scalar-secret-client-id' in flow) {\n flow['x-scalar-secret-client-id'] = data.payload.clientId\n }\n if (data.payload.clientSecret && 'x-scalar-secret-client-secret' in flow) {\n flow['x-scalar-secret-client-secret'] = data.payload.clientSecret\n }\n if (data.payload.usePkce && 'x-usePkce' in flow) {\n flow['x-usePkce'] = data.payload.usePkce\n }\n if (data.payload.username && 'x-scalar-secret-username' in flow) {\n flow['x-scalar-secret-username'] = data.payload.username\n }\n if (data.payload.password && 'x-scalar-secret-password' in flow) {\n flow['x-scalar-secret-password'] = data.payload.password\n }\n }\n\n // TODO: handle openid connect type in the future\n\n return\n}\n\n/**\n * Sets the selected authentication tab (scheme) index for the given OpenAPI document or operation.\n * - When on the document level, updates the 'x-selected-index' on the document's x-scalar-selected-security extension.\n * - When on an operation (endpoint) level, updates the 'x-selected-index' for that operation's x-scalar-selected-security.\n *\n * Also initializes the x-scalar-selected-security extension if it does not exist.\n *\n * @param document The OpenAPI document object (may be null)\n * @param index The index to set as selected\n * @param meta Context where the selection applies ('document' or specific operation)\n *\n * @example\n * // Document-level tab selection\n * updateSelectedAuthTab({\n * document,\n * index: 1,\n * meta: { type: 'document' }\n * });\n *\n * // Operation-level tab selection (e.g., GET /pets)\n * updateSelectedAuthTab({\n * document,\n * index: 0,\n * meta: { type: 'operation', path: '/pets', method: 'get' }\n * });\n */\nexport const updateSelectedAuthTab = ({\n document,\n index,\n meta,\n}: {\n document: WorkspaceDocument | null\n index: number\n meta: AuthMeta\n}) => {\n if (!document) {\n return\n }\n\n // Determine the target object for setting the auth tab index:\n // - Document/root level\n // - Operation/endpoint level (if meta specifies operation)\n const getTarget = () => {\n if (meta.type === 'document') {\n return document\n }\n return getResolvedRef(document.paths?.[meta.path]?.[meta.method])\n }\n\n const target = getTarget()\n if (!target) {\n return\n }\n\n // Ensure the 'x-scalar-selected-security' extension exists\n if (!target['x-scalar-selected-security']) {\n target['x-scalar-selected-security'] = {\n 'x-selected-index': 0,\n 'x-schemes': [],\n }\n }\n\n // Set the selected auth tab index\n target['x-scalar-selected-security']['x-selected-index'] = index\n}\n\n/**\n * Updates the scopes for a specific security requirement in the selected security schemes of\n * a document or operation.\n *\n * @param document - The OpenAPI WorkspaceDocument to update.\n * @param id - An array of scheme names that uniquely identifies the target security requirement.\n * For example: ['OAuth', 'ApiKeyAuth']\n * @param name - The security scheme name to update scopes for (e.g., 'OAuth').\n * @param scopes - The new list of scopes to set. For example: ['read:pets', 'write:pets']\n * @param meta - The context specifying whether the update is at the document-level or operation-level.\n *\n * Example usage:\n * ```ts\n * // Suppose your document (or operation) x-scalar-selected-security looks like:\n * // \"x-scalar-selected-security\": {\n * // \"x-selected-index\": 0,\n * // \"x-schemes\": [\n * // { \"OAuth\": [\"read:pets\"] },\n * // { \"ApiKeyAuth\": [] }\n * // ]\n * // }\n *\n * updateSelectedScopes({\n * document,\n * id: [\"OAuth\"], // identifies the scheme object: { \"OAuth\": [...] }\n * name: \"OAuth\", // scheme name to update within this security requirement\n * scopes: [\"write:pets\"], // new scopes array\n * meta: { type: \"document\" }\n * })\n * // After, the first scheme becomes: { \"OAuth\": [\"write:pets\"] }\n * ```\n */\nexport const updateSelectedScopes = ({\n document,\n id,\n name,\n scopes,\n meta,\n}: {\n document: WorkspaceDocument | null\n id: string[]\n name: string\n scopes: string[]\n meta: AuthMeta\n}) => {\n if (!document) {\n return\n }\n\n // Determine the target object (document or the operation)\n const getTarget = () => {\n if (meta.type === 'document') {\n return document\n }\n return getResolvedRef(document.paths?.[meta.path]?.[meta.method])\n }\n\n const target = getTarget()\n\n if (!target) {\n return\n }\n\n // Array of security requirement objects under x-scalar-selected-security\n const selectedSchemes = target['x-scalar-selected-security']?.['x-schemes']\n\n if (!selectedSchemes) {\n return\n }\n\n // Find the security requirement that matches the given id (scheme key names)\n // For example: if id = [\"OAuth\"], matches { OAuth: [...] }\n const scheme = selectedSchemes.find((scheme) => JSON.stringify(Object.keys(scheme)) === JSON.stringify(id))\n\n if (!scheme) {\n return\n }\n\n // Set the scopes array for the named security scheme within the found security requirement\n scheme[name] = scopes\n}\n\n/**\n * Deletes one or more security schemes from an OpenAPI WorkspaceDocument,\n * and removes all references to those schemes from selected security, document-level security,\n * and operation-level security/selected security (e.g., on paths).\n *\n * Example usage:\n *\n * ```ts\n * deleteSecurityScheme({\n * document, // The OpenAPI document to update\n * names: ['ApiKeyAuth', 'BearerAuth'], // The names of security schemes you want to delete\n * });\n * ```\n *\n * After running this function:\n * - The named security schemes are removed from the components.securitySchemes section.\n * - All document-level and operation-level security entries referencing those schemes are removed.\n * - Any extended x-scalar-selected-security references to those schemes are also removed.\n */\nexport const deleteSecurityScheme = ({ document, names }: { document: WorkspaceDocument | null; names: string[] }) => {\n if (!document) {\n // Early exit if there is no document to modify\n return\n }\n\n // Get the mutable reference to securitySchemes in components (may be a proxy/resolved reference)\n const target = getResolvedRef(document.components?.securitySchemes)\n\n if (!target) {\n // If there are no security schemes to delete from, return early\n return\n }\n\n // Remove each named security scheme from the components.securitySchemes object\n names.forEach((name) => {\n delete target[name]\n })\n\n // Function to remove any security requirement objects that reference given scheme names.\n const filterSecuritySchemes = (schemes: SecurityRequirementObject[]) => {\n // Remove schemes whose key is included in the `names` to be deleted.\n return schemes.filter((scheme) => !names.some((name) => Object.keys(scheme).includes(name)))\n }\n\n // -- Remove from document-level `x-scalar-selected-security` extension, if present\n if (document['x-scalar-selected-security']) {\n const selectedSecurity = document['x-scalar-selected-security']\n selectedSecurity['x-schemes'] = filterSecuritySchemes(selectedSecurity['x-schemes'])\n }\n\n // -- Remove from document-level `security` property, if present\n if (document['security']) {\n document['security'] = filterSecuritySchemes(document['security'])\n }\n\n // -- For each path and operation, remove deleted security schemes from operation-level security and custom extension\n Object.values(document.paths ?? {}).forEach((path) => {\n Object.values(path).forEach((operation) => {\n if (typeof operation !== 'object') {\n // Ignore operations that are not objects (could be undefined)\n return\n }\n\n // Get mutable reference for the operation (could resolve $ref proxies)\n const resolvedOperation = getResolvedRef(operation)\n\n // Remove from operation-level security array\n if ('security' in resolvedOperation && resolvedOperation['security']) {\n resolvedOperation['security'] = filterSecuritySchemes(resolvedOperation['security'])\n }\n\n // Remove from operation-level x-scalar-selected-security array\n if ('x-scalar-selected-security' in resolvedOperation && resolvedOperation['x-scalar-selected-security']) {\n resolvedOperation['x-scalar-selected-security']['x-schemes'] = filterSecuritySchemes(\n resolvedOperation['x-scalar-selected-security']['x-schemes'],\n )\n }\n })\n })\n}\n"],
5
+ "mappings": "AAEA,SAAS,2BAA2B;AACpC,SAAS,sBAAsB;AA8CxB,MAAM,gCAAgC,CAAC;AAAA,EAC5C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAKM;AACJ,MAAI,CAAC,UAAU;AACb;AAAA,EACF;AAGA,QAAM,YAAY,MAAM;AACtB,QAAI,KAAK,SAAS,YAAY;AAC5B,aAAO;AAAA,IACT;AAEA,WAAO,eA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AI,sBAAsB,kBAAkB,UAAU,CAAC;AAAA,MACrF;AAGA,UAAI,gCAAgC,qBAAqB,kBAAkB,4BAA4B,GAAG;AACxG,0BAAkB,4BAA4B,EAAE,WAAW,IAAI;AAAA,UAC7D,kBAAkB,4BAA4B,EAAE,WAAW;AAAA,QAC7D;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH;",
6
+ "names": ["scheme"]
7
+ }
@@ -1,17 +1,25 @@
1
- import type { UnknownObject } from '../helpers/general.js';
2
- import type { XScalarClientConfigEnvironments, xScalarClientConfigEnvironment } from '../schemas/v3.1/strict/client-config-extensions/x-scalar-client-config-environments.js';
1
+ import type { EnvironmentEvents } from '../events/definitions/environment.js';
2
+ import type { Workspace, WorkspaceDocument } from '../schemas.js';
3
+ import { type XScalarEnvVar, type XScalarEnvironment } from '../schemas/extensions/document/x-scalar-environments.js';
3
4
  /**
4
- * Environment mutators for managing client configuration environments in OpenAPI documents.
5
- * Provides functions to add and delete environments from the document's x-scalar-client-config-environments extension.
5
+ * Adds OR updates an environment to the document or workspace.
6
6
  *
7
- * @param store - The workspace store containing the documents
8
- * @param documentName - The name of the document to operate on
9
- * @returns Object containing addEnvironment and deleteEnvironment functions
7
+ * @param document - current document if available
8
+ * @param workspace - current workspace if available
9
+ * @param environmentName - Name of the environment to add
10
+ * @param payload - The environment configuration to add
11
+ * @param oldEnvironmentName - Only needed when renaming the environment
12
+ * @returns the parsed environment that was added or updated or undefined if the collection is not found
10
13
  */
11
- export declare const environmentMutators: (document?: UnknownObject & {
12
- "x-scalar-client-config-environments"?: XScalarClientConfigEnvironments;
13
- }) => {
14
- addEnvironment: (name: string, environment: xScalarClientConfigEnvironment) => boolean;
15
- deleteEnvironment: (environmentName: string) => boolean;
16
- };
14
+ export declare const upsertEnvironment: (document: WorkspaceDocument | null, workspace: Workspace, { environmentName, payload, collectionType, oldEnvironmentName }: EnvironmentEvents["environment:upsert:environment"]) => XScalarEnvironment | undefined;
15
+ /**
16
+ * Adds OR updates an environment variable to the document or workspace.
17
+ *
18
+ * @param collection - Workspace OR document
19
+ * @param environmentName - Name of the environment to add the variable to
20
+ * @param variableName - Name of the variable to add
21
+ * @param value - Value of the variable to add
22
+ * @returns the parsed variable that was added or updated or undefined if the collection is not found
23
+ */
24
+ export declare const upsertEnvironmentVariable: (collection: WorkspaceDocument | Workspace | null, { environmentName, variable, index }: EnvironmentEvents["environment:upsert:environment-variable"]) => XScalarEnvVar | undefined;
17
25
  //# sourceMappingURL=environment.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../src/mutators/environment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,KAAK,EACV,+BAA+B,EAC/B,8BAA8B,EAC/B,MAAM,oFAAoF,CAAA;AAE3F;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,GAC9B,WAAW,aAAa,GAAG;IAAE,qCAAqC,CAAC,EAAE,+BAA+B,CAAA;CAAE;2BAsBxE,MAAM,eAAe,8BAA8B;yCA6BrC,MAAM;CAanD,CAAA"}
1
+ {"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../src/mutators/environment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAA;AACzE,OAAO,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAC7D,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,kBAAkB,EAGxB,MAAM,qDAAqD,CAAA;AAG5D;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,GAC5B,UAAU,iBAAiB,GAAG,IAAI,EAClC,WAAW,SAAS,EACpB,kEAAkE,iBAAiB,CAAC,gCAAgC,CAAC,KACpH,kBAAkB,GAAG,SAqCvB,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,yBAAyB,GACpC,YAAY,iBAAiB,GAAG,SAAS,GAAG,IAAI,EAChD,sCAAsC,iBAAiB,CAAC,yCAAyC,CAAC,KACjG,aAAa,GAAG,SA0BlB,CAAA"}