@webiny/api-core 0.0.0-unstable.7c2def32a7 → 0.0.0-unstable.9609e4e0c9
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.
- package/features/debugger/__tests__/serialize.test.js.map +1 -1
- package/features/encryption/BuildParamsEncryptionConfig.d.ts +13 -0
- package/features/encryption/BuildParamsEncryptionConfig.js +19 -0
- package/features/encryption/BuildParamsEncryptionConfig.js.map +1 -0
- package/features/encryption/EncryptionService.d.ts +2 -2
- package/features/encryption/EncryptionService.js +9 -14
- package/features/encryption/EncryptionService.js.map +1 -1
- package/features/encryption/abstractions.d.ts +15 -0
- package/features/encryption/abstractions.js +2 -1
- package/features/encryption/abstractions.js.map +1 -1
- package/features/encryption/feature.js +2 -0
- package/features/encryption/feature.js.map +1 -1
- package/features/encryption/index.d.ts +2 -0
- package/features/encryption/index.js +2 -1
- package/features/hashing/BuildParamsHashingConfig.d.ts +11 -0
- package/features/hashing/BuildParamsHashingConfig.js +18 -0
- package/features/hashing/BuildParamsHashingConfig.js.map +1 -0
- package/features/hashing/ScryptHasher.d.ts +2 -2
- package/features/hashing/ScryptHasher.js +6 -8
- package/features/hashing/ScryptHasher.js.map +1 -1
- package/features/hashing/abstractions.d.ts +15 -0
- package/features/hashing/abstractions.js +2 -1
- package/features/hashing/abstractions.js.map +1 -1
- package/features/hashing/feature.js +2 -0
- package/features/hashing/feature.js.map +1 -1
- package/features/hashing/index.d.ts +1 -0
- package/features/hashing/index.js +1 -1
- package/features/security/IdentityContext/IdentityContext.d.ts +1 -0
- package/features/security/IdentityContext/IdentityContext.js +3 -0
- package/features/security/IdentityContext/IdentityContext.js.map +1 -1
- package/features/security/IdentityContext/abstractions.d.ts +5 -0
- package/features/security/IdentityContext/abstractions.js.map +1 -1
- package/features/security/authorization/AuthorizationContext/AuthorizationContext.d.ts +12 -3
- package/features/security/authorization/AuthorizationContext/AuthorizationContext.js +31 -18
- package/features/security/authorization/AuthorizationContext/AuthorizationContext.js.map +1 -1
- package/features/security/authorization/AuthorizationContext/abstractions.d.ts +2 -0
- package/features/security/authorization/AuthorizationContext/abstractions.js.map +1 -1
- package/features/security/authorization/AuthorizationContext/feature.js +6 -1
- package/features/security/authorization/AuthorizationContext/feature.js.map +1 -1
- package/features/users/shared/loaders.js.map +1 -1
- package/features/users/shared/types.d.ts +9 -7
- package/package.json +20 -20
- package/types/users.d.ts +2 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/debugger/__tests__/serialize.test.js","sources":["../../../../src/features/debugger/__tests__/serialize.test.ts"],"sourcesContent":["import { describe, expect, it } from \"vitest\";\nimport { serialize } from \"../serialize.js\";\nimport { DEFAULT_LIMITS, type IDebuggerLimits } from \"../limits.js\";\n\nconst limits = (overrides: Partial<IDebuggerLimits> = {}): IDebuggerLimits => {\n return { ...DEFAULT_LIMITS, ...overrides };\n};\n\nconst parse = (value: unknown, overrides: Partial<IDebuggerLimits> = {}) => {\n const result = serialize(value, limits(overrides));\n return { ...result, parsed: JSON.parse(result.json) };\n};\n\ndescribe(\"serialize\", () => {\n it(\"should always produce parseable JSON\", () => {\n const circular: Record<string, unknown> = { name: \"root\" };\n circular.self = circular;\n\n const { parsed } = parse(circular);\n\n expect(parsed).toEqual({ name: \"root\", self: \"#[Circular]\" });\n });\n\n it(\"should not report siblings as circular\", () => {\n const shared = { id: 1 };\n\n const { parsed } = parse({ a: shared, b: shared });\n\n expect(parsed).toEqual({ a: { id: 1 }, b: { id: 1 } });\n });\n\n it(\"should serialize an Error, which JSON.stringify renders as an empty object\", () => {\n const error = new Error(\"Boom\");\n\n const { parsed } = parse({ error });\n\n expect(parsed.error.name).toBe(\"Error\");\n expect(parsed.error.message).toBe(\"Boom\");\n expect(typeof parsed.error.stack).toBe(\"string\");\n });\n\n it(\"should serialize a BigInt, which JSON.stringify throws on\", () => {\n const { parsed } = parse({ value: BigInt(123) });\n\n expect(parsed).toEqual({ value: \"123n\" });\n });\n\n it(\"should describe binary data without including its contents\", () => {\n const { parsed } = parse({ buffer: Buffer.from(\"hello world\") });\n\n expect(parsed).toEqual({ buffer: \"#[Buffer 11 bytes]\" });\n });\n\n it(\"should serialize Map and Set\", () => {\n const { parsed } = parse({\n map: new Map([[\"a\", 1]]),\n set: new Set([1, 2])\n });\n\n expect(parsed.map).toEqual({ __type: \"Map\", entries: [[\"a\", 1]] });\n expect(parsed.set).toEqual({ __type: \"Set\", items: [1, 2] });\n });\n\n it(\"should drop an undefined property, so a logged payload matches what was sent\", () => {\n const { parsed } = parse({ kept: 1, dropped: undefined });\n\n expect(parsed).toEqual({ kept: 1 });\n });\n\n it(\"should keep undefined array elements, where dropping would shift every later index\", () => {\n const { parsed } = parse({ items: [1, undefined, 3] });\n\n expect(parsed).toEqual({ items: [1, \"#[Undefined value]\", 3] });\n });\n\n it(\"should not throw when a getter throws\", () => {\n const value = {\n get exploding() {\n throw new Error(\"Nope\");\n },\n safe: 1\n };\n\n const { parsed } = parse(value);\n\n expect(parsed.exploding).toBe(\"#[Throws: Nope]\");\n expect(parsed.safe).toBe(1);\n });\n\n it(\"should cap depth\", () => {\n const { parsed } = parse({ a: { b: { c: { d: \"deep\" } } } }, { depth: 2 });\n\n expect(parsed).toEqual({ a: { b: \"#[Depth limit]\" } });\n });\n\n it(\"should cap string length and say how much was cut\", () => {\n const { parsed } = parse({ text: \"x\".repeat(20) }, { stringLength: 5 });\n\n expect(parsed).toEqual({ text: \"xxxxx…(15 more)\" });\n });\n\n it(\"should cap array length and say how much was cut\", () => {\n const { parsed } = parse({ items: [1, 2, 3, 4, 5] }, { arrayLength: 2 });\n\n expect(parsed).toEqual({ items: [1, 2, \"…(3 more items)\"] });\n });\n\n it(\"should replace the payload wholesale when it exceeds the per-entry cap\", () => {\n const result = parse({ text: \"x\".repeat(5000) }, { entryBytes: 100, stringLength: 100000 });\n\n expect(result.truncated).toBe(true);\n expect(result.parsed.truncated).toBe(true);\n expect(result.parsed.originalBytes).toBeGreaterThan(100);\n expect(result.bytes).toBeLessThanOrEqual(100);\n });\n\n it(\"should never invoke a custom toJSON, so it cannot be broken by one\", () => {\n const value = {\n id: 1,\n toJSON() {\n throw new Error(\"Nope\");\n }\n };\n\n const { parsed } = parse({ value });\n\n expect(parsed.value.id).toBe(1);\n expect(parsed.value.toJSON).toBe(\"#[Function: toJSON]\");\n });\n\n it(\"should keep non-finite numbers readable instead of turning them into null\", () => {\n const { parsed } = parse({ a: Infinity, b: NaN });\n\n expect(parsed).toEqual({ a: \"Infinity\", b: \"NaN\" });\n });\n});\n"],"names":["limits","overrides","DEFAULT_LIMITS","parse","value","result","serialize","JSON","describe","it","circular","parsed","expect","shared","error","Error","BigInt","Buffer","Map","Set","undefined","Infinity","NaN"],"mappings":";;;AAIA,MAAMA,SAAS,CAACC,YAAsC,CAAC,CAAC,GAC7C;QAAE,GAAGC,cAAc;QAAE,GAAGD,SAAS;IAAC;AAG7C,MAAME,QAAQ,CAACC,OAAgBH,YAAsC,CAAC,CAAC;IACnE,MAAMI,SAASC,UAAUF,OAAOJ,OAAOC;IACvC,OAAO;QAAE,GAAGI,MAAM;QAAE,QAAQE,KAAK,KAAK,CAACF,OAAO,IAAI;IAAE;AACxD;AAEAG,SAAS,aAAa;IAClBC,GAAG,wCAAwC;QACvC,MAAMC,WAAoC;YAAE,MAAM;QAAO;QACzDA,SAAS,IAAI,GAAGA;QAEhB,MAAM,EAAEC,MAAM,EAAE,GAAGR,MAAMO;QAEzBE,OAAOD,QAAQ,OAAO,CAAC;YAAE,MAAM;YAAQ,MAAM;QAAc;IAC/D;IAEAF,GAAG,0CAA0C;QACzC,MAAMI,SAAS;YAAE,IAAI;QAAE;QAEvB,MAAM,EAAEF,MAAM,EAAE,GAAGR,MAAM;YAAE,GAAGU;YAAQ,GAAGA;QAAO;QAEhDD,OAAOD,QAAQ,OAAO,CAAC;YAAE,GAAG;gBAAE,IAAI;YAAE;YAAG,GAAG;gBAAE,IAAI;YAAE;QAAE;IACxD;IAEAF,GAAG,8EAA8E;QAC7E,MAAMK,QAAQ,IAAIC,MAAM;QAExB,MAAM,EAAEJ,MAAM,EAAE,GAAGR,MAAM;YAAEW;QAAM;QAEjCF,OAAOD,OAAO,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC;QAC/BC,OAAOD,OAAO,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC;QAClCC,OAAO,OAAOD,OAAO,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC;IAC3C;IAEAF,GAAG,6DAA6D;QAC5D,MAAM,EAAEE,MAAM,EAAE,GAAGR,MAAM;YAAE,OAAOa,OAAO;QAAK;QAE9CJ,OAAOD,QAAQ,OAAO,CAAC;YAAE,OAAO;QAAO;IAC3C;IAEAF,GAAG,8DAA8D;QAC7D,MAAM,EAAEE,MAAM,EAAE,GAAGR,MAAM;YAAE,QAAQc,OAAO,IAAI,CAAC;QAAe;QAE9DL,OAAOD,QAAQ,OAAO,CAAC;YAAE,QAAQ;QAAqB;IAC1D;IAEAF,GAAG,gCAAgC;QAC/B,MAAM,EAAEE,MAAM,EAAE,GAAGR,MAAM;YACrB,KAAK,IAAIe,IAAI;gBAAC;oBAAC;oBAAK;iBAAE;aAAC;YACvB,KAAK,IAAIC,IAAI;gBAAC;gBAAG;aAAE;QACvB;QAEAP,OAAOD,OAAO,GAAG,EAAE,OAAO,CAAC;YAAE,QAAQ;YAAO,SAAS;gBAAC;oBAAC;oBAAK;iBAAE;aAAC;QAAC;QAChEC,OAAOD,OAAO,GAAG,EAAE,OAAO,CAAC;YAAE,QAAQ;YAAO,OAAO;gBAAC;gBAAG;aAAE;QAAC;IAC9D;IAEAF,GAAG,gFAAgF;QAC/E,MAAM,EAAEE,MAAM,EAAE,GAAGR,MAAM;YAAE,MAAM;YAAG,SAASiB;QAAU;QAEvDR,OAAOD,QAAQ,OAAO,CAAC;YAAE,MAAM;QAAE;IACrC;IAEAF,GAAG,sFAAsF;QACrF,MAAM,EAAEE,MAAM,EAAE,GAAGR,MAAM;YAAE,OAAO;gBAAC;gBAAGiB;gBAAW;aAAE;QAAC;QAEpDR,OAAOD,QAAQ,OAAO,CAAC;YAAE,OAAO;gBAAC;gBAAG;gBAAsB;aAAE;QAAC;IACjE;IAEAF,GAAG,yCAAyC;QACxC,MAAML,QAAQ;YACV,IAAI
|
|
1
|
+
{"version":3,"file":"features/debugger/__tests__/serialize.test.js","sources":["../../../../src/features/debugger/__tests__/serialize.test.ts"],"sourcesContent":["import { describe, expect, it } from \"vitest\";\nimport { serialize } from \"../serialize.js\";\nimport { DEFAULT_LIMITS, type IDebuggerLimits } from \"../limits.js\";\n\nconst limits = (overrides: Partial<IDebuggerLimits> = {}): IDebuggerLimits => {\n return { ...DEFAULT_LIMITS, ...overrides };\n};\n\nconst parse = (value: unknown, overrides: Partial<IDebuggerLimits> = {}) => {\n const result = serialize(value, limits(overrides));\n return { ...result, parsed: JSON.parse(result.json) };\n};\n\ndescribe(\"serialize\", () => {\n it(\"should always produce parseable JSON\", () => {\n const circular: Record<string, unknown> = { name: \"root\" };\n circular.self = circular;\n\n const { parsed } = parse(circular);\n\n expect(parsed).toEqual({ name: \"root\", self: \"#[Circular]\" });\n });\n\n it(\"should not report siblings as circular\", () => {\n const shared = { id: 1 };\n\n const { parsed } = parse({ a: shared, b: shared });\n\n expect(parsed).toEqual({ a: { id: 1 }, b: { id: 1 } });\n });\n\n it(\"should serialize an Error, which JSON.stringify renders as an empty object\", () => {\n const error = new Error(\"Boom\");\n\n const { parsed } = parse({ error });\n\n expect(parsed.error.name).toBe(\"Error\");\n expect(parsed.error.message).toBe(\"Boom\");\n expect(typeof parsed.error.stack).toBe(\"string\");\n });\n\n it(\"should serialize a BigInt, which JSON.stringify throws on\", () => {\n const { parsed } = parse({ value: BigInt(123) });\n\n expect(parsed).toEqual({ value: \"123n\" });\n });\n\n it(\"should describe binary data without including its contents\", () => {\n const { parsed } = parse({ buffer: Buffer.from(\"hello world\") });\n\n expect(parsed).toEqual({ buffer: \"#[Buffer 11 bytes]\" });\n });\n\n it(\"should serialize Map and Set\", () => {\n const { parsed } = parse({\n map: new Map([[\"a\", 1]]),\n set: new Set([1, 2])\n });\n\n expect(parsed.map).toEqual({ __type: \"Map\", entries: [[\"a\", 1]] });\n expect(parsed.set).toEqual({ __type: \"Set\", items: [1, 2] });\n });\n\n it(\"should drop an undefined property, so a logged payload matches what was sent\", () => {\n const { parsed } = parse({ kept: 1, dropped: undefined });\n\n expect(parsed).toEqual({ kept: 1 });\n });\n\n it(\"should keep undefined array elements, where dropping would shift every later index\", () => {\n const { parsed } = parse({ items: [1, undefined, 3] });\n\n expect(parsed).toEqual({ items: [1, \"#[Undefined value]\", 3] });\n });\n\n it(\"should not throw when a getter throws\", () => {\n const value = {\n get exploding() {\n throw new Error(\"Nope\");\n },\n safe: 1\n };\n\n const { parsed } = parse(value);\n\n expect(parsed.exploding).toBe(\"#[Throws: Nope]\");\n expect(parsed.safe).toBe(1);\n });\n\n it(\"should cap depth\", () => {\n const { parsed } = parse({ a: { b: { c: { d: \"deep\" } } } }, { depth: 2 });\n\n expect(parsed).toEqual({ a: { b: \"#[Depth limit]\" } });\n });\n\n it(\"should cap string length and say how much was cut\", () => {\n const { parsed } = parse({ text: \"x\".repeat(20) }, { stringLength: 5 });\n\n expect(parsed).toEqual({ text: \"xxxxx…(15 more)\" });\n });\n\n it(\"should cap array length and say how much was cut\", () => {\n const { parsed } = parse({ items: [1, 2, 3, 4, 5] }, { arrayLength: 2 });\n\n expect(parsed).toEqual({ items: [1, 2, \"…(3 more items)\"] });\n });\n\n it(\"should replace the payload wholesale when it exceeds the per-entry cap\", () => {\n const result = parse({ text: \"x\".repeat(5000) }, { entryBytes: 100, stringLength: 100000 });\n\n expect(result.truncated).toBe(true);\n expect(result.parsed.truncated).toBe(true);\n expect(result.parsed.originalBytes).toBeGreaterThan(100);\n expect(result.bytes).toBeLessThanOrEqual(100);\n });\n\n it(\"should never invoke a custom toJSON, so it cannot be broken by one\", () => {\n const value = {\n id: 1,\n toJSON() {\n throw new Error(\"Nope\");\n }\n };\n\n const { parsed } = parse({ value });\n\n expect(parsed.value.id).toBe(1);\n expect(parsed.value.toJSON).toBe(\"#[Function: toJSON]\");\n });\n\n it(\"should keep non-finite numbers readable instead of turning them into null\", () => {\n const { parsed } = parse({ a: Infinity, b: NaN });\n\n expect(parsed).toEqual({ a: \"Infinity\", b: \"NaN\" });\n });\n});\n"],"names":["limits","overrides","DEFAULT_LIMITS","parse","value","result","serialize","JSON","describe","it","circular","parsed","expect","shared","error","Error","BigInt","Buffer","Map","Set","undefined","Infinity","NaN"],"mappings":";;;AAIA,MAAMA,SAAS,CAACC,YAAsC,CAAC,CAAC,GAC7C;QAAE,GAAGC,cAAc;QAAE,GAAGD,SAAS;IAAC;AAG7C,MAAME,QAAQ,CAACC,OAAgBH,YAAsC,CAAC,CAAC;IACnE,MAAMI,SAASC,UAAUF,OAAOJ,OAAOC;IACvC,OAAO;QAAE,GAAGI,MAAM;QAAE,QAAQE,KAAK,KAAK,CAACF,OAAO,IAAI;IAAE;AACxD;AAEAG,SAAS,aAAa;IAClBC,GAAG,wCAAwC;QACvC,MAAMC,WAAoC;YAAE,MAAM;QAAO;QACzDA,SAAS,IAAI,GAAGA;QAEhB,MAAM,EAAEC,MAAM,EAAE,GAAGR,MAAMO;QAEzBE,OAAOD,QAAQ,OAAO,CAAC;YAAE,MAAM;YAAQ,MAAM;QAAc;IAC/D;IAEAF,GAAG,0CAA0C;QACzC,MAAMI,SAAS;YAAE,IAAI;QAAE;QAEvB,MAAM,EAAEF,MAAM,EAAE,GAAGR,MAAM;YAAE,GAAGU;YAAQ,GAAGA;QAAO;QAEhDD,OAAOD,QAAQ,OAAO,CAAC;YAAE,GAAG;gBAAE,IAAI;YAAE;YAAG,GAAG;gBAAE,IAAI;YAAE;QAAE;IACxD;IAEAF,GAAG,8EAA8E;QAC7E,MAAMK,QAAQ,IAAIC,MAAM;QAExB,MAAM,EAAEJ,MAAM,EAAE,GAAGR,MAAM;YAAEW;QAAM;QAEjCF,OAAOD,OAAO,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC;QAC/BC,OAAOD,OAAO,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC;QAClCC,OAAO,OAAOD,OAAO,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC;IAC3C;IAEAF,GAAG,6DAA6D;QAC5D,MAAM,EAAEE,MAAM,EAAE,GAAGR,MAAM;YAAE,OAAOa,OAAO;QAAK;QAE9CJ,OAAOD,QAAQ,OAAO,CAAC;YAAE,OAAO;QAAO;IAC3C;IAEAF,GAAG,8DAA8D;QAC7D,MAAM,EAAEE,MAAM,EAAE,GAAGR,MAAM;YAAE,QAAQc,OAAO,IAAI,CAAC;QAAe;QAE9DL,OAAOD,QAAQ,OAAO,CAAC;YAAE,QAAQ;QAAqB;IAC1D;IAEAF,GAAG,gCAAgC;QAC/B,MAAM,EAAEE,MAAM,EAAE,GAAGR,MAAM;YACrB,KAAK,IAAIe,IAAI;gBAAC;oBAAC;oBAAK;iBAAE;aAAC;YACvB,KAAK,IAAIC,IAAI;gBAAC;gBAAG;aAAE;QACvB;QAEAP,OAAOD,OAAO,GAAG,EAAE,OAAO,CAAC;YAAE,QAAQ;YAAO,SAAS;gBAAC;oBAAC;oBAAK;iBAAE;aAAC;QAAC;QAChEC,OAAOD,OAAO,GAAG,EAAE,OAAO,CAAC;YAAE,QAAQ;YAAO,OAAO;gBAAC;gBAAG;aAAE;QAAC;IAC9D;IAEAF,GAAG,gFAAgF;QAC/E,MAAM,EAAEE,MAAM,EAAE,GAAGR,MAAM;YAAE,MAAM;YAAG,SAASiB;QAAU;QAEvDR,OAAOD,QAAQ,OAAO,CAAC;YAAE,MAAM;QAAE;IACrC;IAEAF,GAAG,sFAAsF;QACrF,MAAM,EAAEE,MAAM,EAAE,GAAGR,MAAM;YAAE,OAAO;gBAAC;gBAAGiB;gBAAW;aAAE;QAAC;QAEpDR,OAAOD,QAAQ,OAAO,CAAC;YAAE,OAAO;gBAAC;gBAAG;gBAAsB;aAAE;QAAC;IACjE;IAEAF,GAAG,yCAAyC;QACxC,MAAML,QAAQ;YACV,IAAI;gBACA,MAAM,IAAIW,MAAM;YACpB;YACA,MAAM;QACV;QAEA,MAAM,EAAEJ,MAAM,EAAE,GAAGR,MAAMC;QAEzBQ,OAAOD,OAAO,SAAS,EAAE,IAAI,CAAC;QAC9BC,OAAOD,OAAO,IAAI,EAAE,IAAI,CAAC;IAC7B;IAEAF,GAAG,oBAAoB;QACnB,MAAM,EAAEE,MAAM,EAAE,GAAGR,MAAM;YAAE,GAAG;gBAAE,GAAG;oBAAE,GAAG;wBAAE,GAAG;oBAAO;gBAAE;YAAE;QAAE,GAAG;YAAE,OAAO;QAAE;QAExES,OAAOD,QAAQ,OAAO,CAAC;YAAE,GAAG;gBAAE,GAAG;YAAiB;QAAE;IACxD;IAEAF,GAAG,qDAAqD;QACpD,MAAM,EAAEE,MAAM,EAAE,GAAGR,MAAM;YAAE,MAAM,IAAI,MAAM,CAAC;QAAI,GAAG;YAAE,cAAc;QAAE;QAErES,OAAOD,QAAQ,OAAO,CAAC;YAAE,MAAM;QAAkB;IACrD;IAEAF,GAAG,oDAAoD;QACnD,MAAM,EAAEE,MAAM,EAAE,GAAGR,MAAM;YAAE,OAAO;gBAAC;gBAAG;gBAAG;gBAAG;gBAAG;aAAE;QAAC,GAAG;YAAE,aAAa;QAAE;QAEtES,OAAOD,QAAQ,OAAO,CAAC;YAAE,OAAO;gBAAC;gBAAG;gBAAG;aAAkB;QAAC;IAC9D;IAEAF,GAAG,0EAA0E;QACzE,MAAMJ,SAASF,MAAM;YAAE,MAAM,IAAI,MAAM,CAAC;QAAM,GAAG;YAAE,YAAY;YAAK,cAAc;QAAO;QAEzFS,OAAOP,OAAO,SAAS,EAAE,IAAI,CAAC;QAC9BO,OAAOP,OAAO,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC;QACrCO,OAAOP,OAAO,MAAM,CAAC,aAAa,EAAE,eAAe,CAAC;QACpDO,OAAOP,OAAO,KAAK,EAAE,mBAAmB,CAAC;IAC7C;IAEAI,GAAG,sEAAsE;QACrE,MAAML,QAAQ;YACV,IAAI;YACJ;gBACI,MAAM,IAAIW,MAAM;YACpB;QACJ;QAEA,MAAM,EAAEJ,MAAM,EAAE,GAAGR,MAAM;YAAEC;QAAM;QAEjCQ,OAAOD,OAAO,KAAK,CAAC,EAAE,EAAE,IAAI,CAAC;QAC7BC,OAAOD,OAAO,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC;IACrC;IAEAF,GAAG,6EAA6E;QAC5E,MAAM,EAAEE,MAAM,EAAE,GAAGR,MAAM;YAAE,GAAGkB,KAAQ;YAAE,GAAGC,KAAG;QAAC;QAE/CV,OAAOD,QAAQ,OAAO,CAAC;YAAE,GAAG;YAAY,GAAG;QAAM;IACrD;AACJ"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { EncryptionConfig } from "./abstractions.js";
|
|
2
|
+
import { BuildParams } from "../buildParams/abstractions.js";
|
|
3
|
+
export declare const DEFAULT_ENCRYPTION_ALGORITHM = "aes-256-gcm";
|
|
4
|
+
declare class BuildParamsEncryptionConfigImpl implements EncryptionConfig.Interface {
|
|
5
|
+
readonly passphrase: string | null;
|
|
6
|
+
readonly salt: string;
|
|
7
|
+
readonly algorithm: string;
|
|
8
|
+
constructor(buildParams: BuildParams.Interface);
|
|
9
|
+
}
|
|
10
|
+
export declare const BuildParamsEncryptionConfig: typeof BuildParamsEncryptionConfigImpl & {
|
|
11
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IEncryptionConfig>;
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { EncryptionConfig } from "./abstractions.js";
|
|
2
|
+
import { BuildParams } from "../buildParams/abstractions.js";
|
|
3
|
+
const DEFAULT_ENCRYPTION_ALGORITHM = "aes-256-gcm";
|
|
4
|
+
class BuildParamsEncryptionConfigImpl {
|
|
5
|
+
constructor(buildParams){
|
|
6
|
+
this.passphrase = buildParams.get("EncryptionPassphrase") || null;
|
|
7
|
+
this.salt = buildParams.get("EncryptionSalt") ?? "";
|
|
8
|
+
this.algorithm = buildParams.get("EncryptionAlgorithm") ?? DEFAULT_ENCRYPTION_ALGORITHM;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
const BuildParamsEncryptionConfig = EncryptionConfig.createImplementation({
|
|
12
|
+
implementation: BuildParamsEncryptionConfigImpl,
|
|
13
|
+
dependencies: [
|
|
14
|
+
BuildParams
|
|
15
|
+
]
|
|
16
|
+
});
|
|
17
|
+
export { BuildParamsEncryptionConfig, DEFAULT_ENCRYPTION_ALGORITHM };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=BuildParamsEncryptionConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/encryption/BuildParamsEncryptionConfig.js","sources":["../../../src/features/encryption/BuildParamsEncryptionConfig.ts"],"sourcesContent":["import { EncryptionConfig } from \"./abstractions.js\";\nimport { BuildParams } from \"../buildParams/abstractions.js\";\n\nexport const DEFAULT_ENCRYPTION_ALGORITHM = \"aes-256-gcm\";\n\nclass BuildParamsEncryptionConfigImpl implements EncryptionConfig.Interface {\n readonly passphrase: string | null;\n readonly salt: string;\n readonly algorithm: string;\n\n constructor(buildParams: BuildParams.Interface) {\n this.passphrase = buildParams.get<string>(\"EncryptionPassphrase\") || null;\n this.salt = buildParams.get<string>(\"EncryptionSalt\") ?? \"\";\n this.algorithm =\n buildParams.get<string>(\"EncryptionAlgorithm\") ?? DEFAULT_ENCRYPTION_ALGORITHM;\n }\n}\n\nexport const BuildParamsEncryptionConfig = EncryptionConfig.createImplementation({\n implementation: BuildParamsEncryptionConfigImpl,\n dependencies: [BuildParams]\n});\n"],"names":["DEFAULT_ENCRYPTION_ALGORITHM","BuildParamsEncryptionConfigImpl","buildParams","BuildParamsEncryptionConfig","EncryptionConfig","BuildParams"],"mappings":";;AAGO,MAAMA,+BAA+B;AAE5C,MAAMC;IAKF,YAAYC,WAAkC,CAAE;QAC5C,IAAI,CAAC,UAAU,GAAGA,YAAY,GAAG,CAAS,2BAA2B;QACrE,IAAI,CAAC,IAAI,GAAGA,YAAY,GAAG,CAAS,qBAAqB;QACzD,IAAI,CAAC,SAAS,GACVA,YAAY,GAAG,CAAS,0BAA0BF;IAC1D;AACJ;AAEO,MAAMG,8BAA8BC,iBAAiB,oBAAoB,CAAC;IAC7E,gBAAgBH;IAChB,cAAc;QAACI;KAAY;AAC/B"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Encryption as EncryptionAbstraction } from "./abstractions.js";
|
|
2
2
|
import { EncryptionKeyCache } from "./abstractions.js";
|
|
3
|
-
import {
|
|
3
|
+
import { EncryptionConfig } from "./abstractions.js";
|
|
4
4
|
export declare class EncryptionImpl implements EncryptionAbstraction.Interface {
|
|
5
5
|
private key;
|
|
6
6
|
private algorithm;
|
|
7
|
-
constructor(
|
|
7
|
+
constructor(config: EncryptionConfig.Interface, keyCache: EncryptionKeyCache.Interface | undefined);
|
|
8
8
|
encrypt(value: string): Promise<string>;
|
|
9
9
|
decrypt(value: string): Promise<string>;
|
|
10
10
|
}
|
|
@@ -1,26 +1,21 @@
|
|
|
1
1
|
import node_crypto from "node:crypto";
|
|
2
2
|
import { createImplementation } from "@webiny/feature/api";
|
|
3
|
-
import { Encryption, EncryptionKeyCache } from "./abstractions.js";
|
|
4
|
-
import { BuildParams } from "../buildParams/abstractions.js";
|
|
5
|
-
const DEFAULT_ALGORITHM = "aes-256-gcm";
|
|
3
|
+
import { Encryption, EncryptionConfig, EncryptionKeyCache } from "./abstractions.js";
|
|
6
4
|
function keyLengthForAlgorithm(algorithm) {
|
|
7
5
|
const bits = parseInt(algorithm.split("-")[1]);
|
|
8
6
|
if (isNaN(bits)) throw new Error(`Cannot determine key length from algorithm "${algorithm}".`);
|
|
9
7
|
return bits / 8;
|
|
10
8
|
}
|
|
11
9
|
class EncryptionImpl {
|
|
12
|
-
constructor(
|
|
13
|
-
|
|
14
|
-
if (passphrase) {
|
|
15
|
-
const salt = buildParams.get("EncryptionSalt") ?? "";
|
|
16
|
-
this.algorithm = buildParams.get("EncryptionAlgorithm") ?? DEFAULT_ALGORITHM;
|
|
17
|
-
const keyLength = keyLengthForAlgorithm(this.algorithm);
|
|
18
|
-
if (keyCache) this.key = keyCache.getOrDerive(passphrase, salt, keyLength);
|
|
19
|
-
else this.key = node_crypto.scryptSync(passphrase, salt, keyLength);
|
|
20
|
-
} else {
|
|
10
|
+
constructor(config, keyCache){
|
|
11
|
+
this.algorithm = config.algorithm;
|
|
12
|
+
if (!config.passphrase) {
|
|
21
13
|
this.key = null;
|
|
22
|
-
|
|
14
|
+
return;
|
|
23
15
|
}
|
|
16
|
+
const keyLength = keyLengthForAlgorithm(this.algorithm);
|
|
17
|
+
if (keyCache) this.key = keyCache.getOrDerive(config.passphrase, config.salt, keyLength);
|
|
18
|
+
else this.key = node_crypto.scryptSync(config.passphrase, config.salt, keyLength);
|
|
24
19
|
}
|
|
25
20
|
async encrypt(value) {
|
|
26
21
|
if (!this.key) return value;
|
|
@@ -55,7 +50,7 @@ const EncryptionService_Encryption = createImplementation({
|
|
|
55
50
|
abstraction: Encryption,
|
|
56
51
|
implementation: EncryptionImpl,
|
|
57
52
|
dependencies: [
|
|
58
|
-
|
|
53
|
+
EncryptionConfig,
|
|
59
54
|
[
|
|
60
55
|
EncryptionKeyCache,
|
|
61
56
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/encryption/EncryptionService.js","sources":["../../../src/features/encryption/EncryptionService.ts"],"sourcesContent":["import crypto from \"node:crypto\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { Encryption as EncryptionAbstraction } from \"./abstractions.js\";\nimport { EncryptionKeyCache } from \"./abstractions.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"features/encryption/EncryptionService.js","sources":["../../../src/features/encryption/EncryptionService.ts"],"sourcesContent":["import crypto from \"node:crypto\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { Encryption as EncryptionAbstraction } from \"./abstractions.js\";\nimport { EncryptionKeyCache } from \"./abstractions.js\";\nimport { EncryptionConfig } from \"./abstractions.js\";\n\nfunction keyLengthForAlgorithm(algorithm: string): number {\n // Parse key size in bits from algorithm name (e.g. \"aes-256-gcm\" → 32 bytes).\n const bits = parseInt(algorithm.split(\"-\")[1]);\n if (isNaN(bits)) {\n throw new Error(`Cannot determine key length from algorithm \"${algorithm}\".`);\n }\n return bits / 8;\n}\n\nexport class EncryptionImpl implements EncryptionAbstraction.Interface {\n private key: Buffer | null;\n private algorithm: string;\n\n constructor(\n config: EncryptionConfig.Interface,\n // Registered in the root container, so the derived key outlives the request. Without it (in\n // tests, for example) the key is derived for every instance.\n keyCache: EncryptionKeyCache.Interface | undefined\n ) {\n this.algorithm = config.algorithm;\n\n if (!config.passphrase) {\n this.key = null;\n return;\n }\n\n // Salt is optional. It ensures two projects using the same passphrase derive different keys,\n // but since passphrases should be unique per project anyway, it's extra insurance rather than a necessity.\n const keyLength = keyLengthForAlgorithm(this.algorithm);\n if (keyCache) {\n this.key = keyCache.getOrDerive(config.passphrase, config.salt, keyLength);\n } else {\n this.key = crypto.scryptSync(config.passphrase, config.salt, keyLength);\n }\n }\n\n async encrypt(value: string): Promise<string> {\n if (!this.key) {\n return value;\n }\n const iv = crypto.randomBytes(12);\n const cipher = crypto.createCipheriv(this.algorithm, this.key, iv);\n const encrypted = Buffer.concat([cipher.update(value, \"utf8\"), cipher.final()]);\n const authTag = (cipher as crypto.CipherGCM).getAuthTag();\n return Buffer.concat([iv, authTag, encrypted]).toString(\"base64\");\n }\n\n async decrypt(value: string): Promise<string> {\n if (!this.key) {\n return value;\n }\n const data = Buffer.from(value, \"base64\");\n const iv = data.subarray(0, 12);\n const authTag = data.subarray(12, 28);\n const ciphertext = data.subarray(28);\n const decipher = crypto.createDecipheriv(this.algorithm, this.key, iv);\n (decipher as crypto.DecipherGCM).setAuthTag(authTag);\n return Buffer.concat([decipher.update(ciphertext), decipher.final()]).toString(\"utf8\");\n }\n}\n\nexport const Encryption = createImplementation({\n abstraction: EncryptionAbstraction,\n implementation: EncryptionImpl,\n dependencies: [EncryptionConfig, [EncryptionKeyCache, { optional: true }]]\n});\n"],"names":["keyLengthForAlgorithm","algorithm","bits","parseInt","isNaN","Error","EncryptionImpl","config","keyCache","keyLength","crypto","value","iv","cipher","encrypted","Buffer","authTag","data","ciphertext","decipher","Encryption","createImplementation","EncryptionAbstraction","EncryptionConfig","EncryptionKeyCache"],"mappings":";;;AAMA,SAASA,sBAAsBC,SAAiB;IAE5C,MAAMC,OAAOC,SAASF,UAAU,KAAK,CAAC,IAAI,CAAC,EAAE;IAC7C,IAAIG,MAAMF,OACN,MAAM,IAAIG,MAAM,CAAC,4CAA4C,EAAEJ,UAAU,EAAE,CAAC;IAEhF,OAAOC,OAAO;AAClB;AAEO,MAAMI;IAIT,YACIC,MAAkC,EAGlCC,QAAkD,CACpD;QACE,IAAI,CAAC,SAAS,GAAGD,OAAO,SAAS;QAEjC,IAAI,CAACA,OAAO,UAAU,EAAE;YACpB,IAAI,CAAC,GAAG,GAAG;YACX;QACJ;QAIA,MAAME,YAAYT,sBAAsB,IAAI,CAAC,SAAS;QACtD,IAAIQ,UACA,IAAI,CAAC,GAAG,GAAGA,SAAS,WAAW,CAACD,OAAO,UAAU,EAAEA,OAAO,IAAI,EAAEE;aAEhE,IAAI,CAAC,GAAG,GAAGC,YAAAA,UAAiB,CAACH,OAAO,UAAU,EAAEA,OAAO,IAAI,EAAEE;IAErE;IAEA,MAAM,QAAQE,KAAa,EAAmB;QAC1C,IAAI,CAAC,IAAI,CAAC,GAAG,EACT,OAAOA;QAEX,MAAMC,KAAKF,YAAAA,WAAkB,CAAC;QAC9B,MAAMG,SAASH,YAAAA,cAAqB,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,GAAG,EAAEE;QAC/D,MAAME,YAAYC,OAAO,MAAM,CAAC;YAACF,OAAO,MAAM,CAACF,OAAO;YAASE,OAAO,KAAK;SAAG;QAC9E,MAAMG,UAAWH,OAA4B,UAAU;QACvD,OAAOE,OAAO,MAAM,CAAC;YAACH;YAAII;YAASF;SAAU,EAAE,QAAQ,CAAC;IAC5D;IAEA,MAAM,QAAQH,KAAa,EAAmB;QAC1C,IAAI,CAAC,IAAI,CAAC,GAAG,EACT,OAAOA;QAEX,MAAMM,OAAOF,OAAO,IAAI,CAACJ,OAAO;QAChC,MAAMC,KAAKK,KAAK,QAAQ,CAAC,GAAG;QAC5B,MAAMD,UAAUC,KAAK,QAAQ,CAAC,IAAI;QAClC,MAAMC,aAAaD,KAAK,QAAQ,CAAC;QACjC,MAAME,WAAWT,YAAAA,gBAAuB,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,GAAG,EAAEE;QAClEO,SAAgC,UAAU,CAACH;QAC5C,OAAOD,OAAO,MAAM,CAAC;YAACI,SAAS,MAAM,CAACD;YAAaC,SAAS,KAAK;SAAG,EAAE,QAAQ,CAAC;IACnF;AACJ;AAEO,MAAMC,+BAAaC,qBAAqB;IAC3C,aAAaC;IACb,gBAAgBhB;IAChB,cAAc;QAACiB;QAAkB;YAACC;YAAoB;gBAAE,UAAU;YAAK;SAAE;KAAC;AAC9E"}
|
|
@@ -18,3 +18,18 @@ export declare const EncryptionKeyCache: import("@webiny/di").Abstraction<IEncry
|
|
|
18
18
|
export declare namespace EncryptionKeyCache {
|
|
19
19
|
type Interface = IEncryptionKeyCache;
|
|
20
20
|
}
|
|
21
|
+
export interface IEncryptionConfig {
|
|
22
|
+
/** `null` turns encryption off: values are stored as given. */
|
|
23
|
+
readonly passphrase: string | null;
|
|
24
|
+
readonly salt: string;
|
|
25
|
+
readonly algorithm: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Where `Encryption` gets its key material. The default reads the `EncryptionPassphrase`,
|
|
29
|
+
* `EncryptionSalt` and `EncryptionAlgorithm` build params (`<Infra.Crypto.Encryption>`). A hosting
|
|
30
|
+
* type can replace it, e.g. to read the passphrase from env at startup.
|
|
31
|
+
*/
|
|
32
|
+
export declare const EncryptionConfig: import("@webiny/di").Abstraction<IEncryptionConfig>;
|
|
33
|
+
export declare namespace EncryptionConfig {
|
|
34
|
+
type Interface = IEncryptionConfig;
|
|
35
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createAbstraction } from "@webiny/feature/api";
|
|
2
2
|
const Encryption = createAbstraction("Encryption");
|
|
3
3
|
const EncryptionKeyCache = createAbstraction("EncryptionKeyCache");
|
|
4
|
-
|
|
4
|
+
const EncryptionConfig = createAbstraction("EncryptionConfig");
|
|
5
|
+
export { Encryption, EncryptionConfig, EncryptionKeyCache };
|
|
5
6
|
|
|
6
7
|
//# sourceMappingURL=abstractions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/encryption/abstractions.js","sources":["../../../src/features/encryption/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\n\nexport interface IEncryption {\n encrypt(value: string): Promise<string>;\n decrypt(value: string): Promise<string>;\n}\n\n/** Symmetric encryption and decryption using a configured secret key. */\nexport const Encryption = createAbstraction<IEncryption>(\"Encryption\");\n\nexport namespace Encryption {\n export type Interface = IEncryption;\n}\n\nexport interface IEncryptionKeyCache {\n getOrDerive(passphrase: string, salt: string, keyLength: number): Buffer;\n}\n\n/**\n * Derives encryption keys and keeps them. Deriving a key runs scrypt, which costs tens of\n * milliseconds of CPU on purpose, so the key is derived once instead of on every request.\n */\nexport const EncryptionKeyCache = createAbstraction<IEncryptionKeyCache>(\"EncryptionKeyCache\");\n\nexport namespace EncryptionKeyCache {\n export type Interface = IEncryptionKeyCache;\n}\n"],"names":["Encryption","createAbstraction","EncryptionKeyCache"],"mappings":";AAQO,MAAMA,aAAaC,kBAA+B;AAclD,MAAMC,qBAAqBD,kBAAuC"}
|
|
1
|
+
{"version":3,"file":"features/encryption/abstractions.js","sources":["../../../src/features/encryption/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\n\nexport interface IEncryption {\n encrypt(value: string): Promise<string>;\n decrypt(value: string): Promise<string>;\n}\n\n/** Symmetric encryption and decryption using a configured secret key. */\nexport const Encryption = createAbstraction<IEncryption>(\"Encryption\");\n\nexport namespace Encryption {\n export type Interface = IEncryption;\n}\n\nexport interface IEncryptionKeyCache {\n getOrDerive(passphrase: string, salt: string, keyLength: number): Buffer;\n}\n\n/**\n * Derives encryption keys and keeps them. Deriving a key runs scrypt, which costs tens of\n * milliseconds of CPU on purpose, so the key is derived once instead of on every request.\n */\nexport const EncryptionKeyCache = createAbstraction<IEncryptionKeyCache>(\"EncryptionKeyCache\");\n\nexport namespace EncryptionKeyCache {\n export type Interface = IEncryptionKeyCache;\n}\n\nexport interface IEncryptionConfig {\n /** `null` turns encryption off: values are stored as given. */\n readonly passphrase: string | null;\n readonly salt: string;\n readonly algorithm: string;\n}\n\n/**\n * Where `Encryption` gets its key material. The default reads the `EncryptionPassphrase`,\n * `EncryptionSalt` and `EncryptionAlgorithm` build params (`<Infra.Crypto.Encryption>`). A hosting\n * type can replace it, e.g. to read the passphrase from env at startup.\n */\nexport const EncryptionConfig = createAbstraction<IEncryptionConfig>(\"EncryptionConfig\");\n\nexport namespace EncryptionConfig {\n export type Interface = IEncryptionConfig;\n}\n"],"names":["Encryption","createAbstraction","EncryptionKeyCache","EncryptionConfig"],"mappings":";AAQO,MAAMA,aAAaC,kBAA+B;AAclD,MAAMC,qBAAqBD,kBAAuC;AAkBlE,MAAME,mBAAmBF,kBAAqC"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { createFeature } from "@webiny/feature/api";
|
|
2
2
|
import { Encryption } from "./EncryptionService.js";
|
|
3
|
+
import { BuildParamsEncryptionConfig } from "./BuildParamsEncryptionConfig.js";
|
|
3
4
|
const EncryptionFeature = createFeature({
|
|
4
5
|
name: "EncryptionFeature",
|
|
5
6
|
register (container) {
|
|
7
|
+
container.register(BuildParamsEncryptionConfig);
|
|
6
8
|
container.register(Encryption);
|
|
7
9
|
}
|
|
8
10
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/encryption/feature.js","sources":["../../../src/features/encryption/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { Encryption } from \"./EncryptionService.js\";\n\nexport const EncryptionFeature = createFeature({\n name: \"EncryptionFeature\",\n register(container) {\n container.register(Encryption);\n }\n});\n"],"names":["EncryptionFeature","createFeature","container","Encryption"],"mappings":"
|
|
1
|
+
{"version":3,"file":"features/encryption/feature.js","sources":["../../../src/features/encryption/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { Encryption } from \"./EncryptionService.js\";\nimport { BuildParamsEncryptionConfig } from \"./BuildParamsEncryptionConfig.js\";\n\nexport const EncryptionFeature = createFeature({\n name: \"EncryptionFeature\",\n register(container) {\n container.register(BuildParamsEncryptionConfig);\n container.register(Encryption);\n }\n});\n"],"names":["EncryptionFeature","createFeature","container","BuildParamsEncryptionConfig","Encryption"],"mappings":";;;AAIO,MAAMA,oBAAoBC,cAAc;IAC3C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE;IACvB;AACJ"}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export { Encryption } from "./abstractions.js";
|
|
1
|
+
export { Encryption, EncryptionConfig } from "./abstractions.js";
|
|
2
|
+
export { DEFAULT_ENCRYPTION_ALGORITHM } from "./BuildParamsEncryptionConfig.js";
|
|
2
3
|
export { EncryptionKeyCacheFeature } from "./EncryptionKeyCacheFeature.js";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { HashingConfig } from "./abstractions.js";
|
|
2
|
+
import { BuildParams } from "../buildParams/abstractions.js";
|
|
3
|
+
declare class BuildParamsHashingConfigImpl implements HashingConfig.Interface {
|
|
4
|
+
readonly pepper: string;
|
|
5
|
+
readonly costN: number | null;
|
|
6
|
+
constructor(buildParams: BuildParams.Interface);
|
|
7
|
+
}
|
|
8
|
+
export declare const BuildParamsHashingConfig: typeof BuildParamsHashingConfigImpl & {
|
|
9
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IHashingConfig>;
|
|
10
|
+
};
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { HashingConfig } from "./abstractions.js";
|
|
2
|
+
import { BuildParams } from "../buildParams/abstractions.js";
|
|
3
|
+
class BuildParamsHashingConfigImpl {
|
|
4
|
+
constructor(buildParams){
|
|
5
|
+
this.pepper = buildParams.get("HashingPepper") ?? "";
|
|
6
|
+
const costN = buildParams.get("HashingCost");
|
|
7
|
+
this.costN = costN ? Number(costN) : null;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
const BuildParamsHashingConfig = HashingConfig.createImplementation({
|
|
11
|
+
implementation: BuildParamsHashingConfigImpl,
|
|
12
|
+
dependencies: [
|
|
13
|
+
BuildParams
|
|
14
|
+
]
|
|
15
|
+
});
|
|
16
|
+
export { BuildParamsHashingConfig };
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=BuildParamsHashingConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/hashing/BuildParamsHashingConfig.js","sources":["../../../src/features/hashing/BuildParamsHashingConfig.ts"],"sourcesContent":["import { HashingConfig } from \"./abstractions.js\";\nimport { BuildParams } from \"../buildParams/abstractions.js\";\n\nclass BuildParamsHashingConfigImpl implements HashingConfig.Interface {\n readonly pepper: string;\n readonly costN: number | null;\n\n constructor(buildParams: BuildParams.Interface) {\n this.pepper = buildParams.get<string>(\"HashingPepper\") ?? \"\";\n const costN = buildParams.get<number | string>(\"HashingCost\");\n this.costN = costN ? Number(costN) : null;\n }\n}\n\nexport const BuildParamsHashingConfig = HashingConfig.createImplementation({\n implementation: BuildParamsHashingConfigImpl,\n dependencies: [BuildParams]\n});\n"],"names":["BuildParamsHashingConfigImpl","buildParams","costN","Number","BuildParamsHashingConfig","HashingConfig","BuildParams"],"mappings":";;AAGA,MAAMA;IAIF,YAAYC,WAAkC,CAAE;QAC5C,IAAI,CAAC,MAAM,GAAGA,YAAY,GAAG,CAAS,oBAAoB;QAC1D,MAAMC,QAAQD,YAAY,GAAG,CAAkB;QAC/C,IAAI,CAAC,KAAK,GAAGC,QAAQC,OAAOD,SAAS;IACzC;AACJ;AAEO,MAAME,2BAA2BC,cAAc,oBAAoB,CAAC;IACvE,gBAAgBL;IAChB,cAAc;QAACM;KAAY;AAC/B"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { IHasher } from "./abstractions.js";
|
|
2
|
-
import {
|
|
2
|
+
import { HashingConfig } from "./abstractions.js";
|
|
3
3
|
export declare class ScryptHasher implements IHasher {
|
|
4
4
|
private readonly cost;
|
|
5
5
|
private readonly pepper;
|
|
6
|
-
constructor(
|
|
6
|
+
constructor(config: HashingConfig.Interface);
|
|
7
7
|
hash(value: string): Promise<string>;
|
|
8
8
|
verify(value: string, storedHash: string): Promise<boolean>;
|
|
9
9
|
private withPepper;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { randomBytes, scrypt, timingSafeEqual } from "node:crypto";
|
|
2
2
|
import { createImplementation } from "@webiny/feature/api";
|
|
3
|
-
import { Hasher } from "./abstractions.js";
|
|
4
|
-
import { BuildParams } from "../buildParams/abstractions.js";
|
|
3
|
+
import { Hasher, HashingConfig } from "./abstractions.js";
|
|
5
4
|
const ScryptHasher_scrypt = (value, salt, keylen, options)=>new Promise((resolve, reject)=>{
|
|
6
5
|
scrypt(value, salt, keylen, options, (err, derivedKey)=>{
|
|
7
6
|
if (err) reject(err);
|
|
@@ -17,12 +16,11 @@ const DEFAULT_COST = {
|
|
|
17
16
|
p: 1
|
|
18
17
|
};
|
|
19
18
|
class ScryptHasher {
|
|
20
|
-
constructor(
|
|
21
|
-
this.pepper =
|
|
22
|
-
|
|
23
|
-
this.cost = costN ? {
|
|
19
|
+
constructor(config){
|
|
20
|
+
this.pepper = config.pepper;
|
|
21
|
+
this.cost = config.costN ? {
|
|
24
22
|
...DEFAULT_COST,
|
|
25
|
-
N:
|
|
23
|
+
N: config.costN
|
|
26
24
|
} : DEFAULT_COST;
|
|
27
25
|
}
|
|
28
26
|
async hash(value) {
|
|
@@ -66,7 +64,7 @@ const ScryptHasher_Hasher = createImplementation({
|
|
|
66
64
|
abstraction: Hasher,
|
|
67
65
|
implementation: ScryptHasher,
|
|
68
66
|
dependencies: [
|
|
69
|
-
|
|
67
|
+
HashingConfig
|
|
70
68
|
]
|
|
71
69
|
});
|
|
72
70
|
export { ScryptHasher, ScryptHasher_Hasher as Hasher };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/hashing/ScryptHasher.js","sources":["../../../src/features/hashing/ScryptHasher.ts"],"sourcesContent":["import { randomBytes, scrypt as scryptCb, timingSafeEqual } from \"node:crypto\";\nimport type { ScryptOptions } from \"node:crypto\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { Hasher as HasherAbstraction } from \"./abstractions.js\";\nimport type { IHasher } from \"./abstractions.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"features/hashing/ScryptHasher.js","sources":["../../../src/features/hashing/ScryptHasher.ts"],"sourcesContent":["import { randomBytes, scrypt as scryptCb, timingSafeEqual } from \"node:crypto\";\nimport type { ScryptOptions } from \"node:crypto\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { Hasher as HasherAbstraction } from \"./abstractions.js\";\nimport type { IHasher } from \"./abstractions.js\";\nimport { HashingConfig } from \"./abstractions.js\";\n\n// `promisify(scryptCb)` resolves to the no-options overload, so we wrap by hand\n// to keep the cost parameters (N, r, p).\nconst scrypt = (\n value: string,\n salt: Buffer,\n keylen: number,\n options: ScryptOptions\n): Promise<Buffer> =>\n new Promise((resolve, reject) => {\n scryptCb(value, salt, keylen, options, (err, derivedKey) => {\n if (err) {\n reject(err);\n } else {\n resolve(derivedKey);\n }\n });\n });\n\n/**\n * Default hasher, built on Node's `crypto.scrypt` — no native dependency, so it runs anywhere Node\n * runs.\n *\n * Configuration (from `webiny.config.tsx` via `<Infra.Hashing>` → BuildParams):\n * - `HashingPepper` — an optional server-side secret folded into every hash. Unlike the per-value\n * salt (stored alongside the hash), the pepper is NOT stored, so a stolen database alone cannot\n * be brute-forced without also holding the pepper. Changing it invalidates existing hashes (same\n * trade-off as rotating the encryption passphrase). Omitted → no pepper, salt only.\n * - `HashingCost` — optional override of the scrypt cost parameter N. Defaults to 16384.\n *\n * The stored value is self-describing (`scrypt$N$r$p$salt$hash`), so switching to Argon2id later is\n * a matter of registering a different `Hasher` — old scrypt hashes keep verifying.\n */\nconst PREFIX = \"scrypt\";\nconst KEYLEN = 64;\nconst SALT_BYTES = 16;\n\ninterface ScryptCost {\n N: number;\n r: number;\n p: number;\n}\n\nconst DEFAULT_COST: ScryptCost = { N: 16384, r: 8, p: 1 };\n\nexport class ScryptHasher implements IHasher {\n private readonly cost: ScryptCost;\n private readonly pepper: string;\n\n constructor(config: HashingConfig.Interface) {\n this.pepper = config.pepper;\n this.cost = config.costN ? { ...DEFAULT_COST, N: config.costN } : DEFAULT_COST;\n }\n\n async hash(value: string): Promise<string> {\n const { N, r, p } = this.cost;\n const salt = randomBytes(SALT_BYTES);\n const derived = (await scrypt(this.withPepper(value), salt, KEYLEN, { N, r, p })) as Buffer;\n\n return [PREFIX, N, r, p, salt.toString(\"base64\"), derived.toString(\"base64\")].join(\"$\");\n }\n\n async verify(value: string, storedHash: string): Promise<boolean> {\n const parts = storedHash.split(\"$\");\n if (parts.length !== 6 || parts[0] !== PREFIX) {\n return false;\n }\n\n const [, nRaw, rRaw, pRaw, saltB64, hashB64] = parts;\n const N = Number(nRaw);\n const r = Number(rRaw);\n const p = Number(pRaw);\n const salt = Buffer.from(saltB64, \"base64\");\n const expected = Buffer.from(hashB64, \"base64\");\n\n const derived = (await scrypt(this.withPepper(value), salt, expected.length, {\n N,\n r,\n p\n })) as Buffer;\n\n // Lengths always match here, so timingSafeEqual is safe to call directly.\n return timingSafeEqual(derived, expected);\n }\n\n private withPepper(value: string): string {\n return this.pepper ? `${value}${this.pepper}` : value;\n }\n}\n\nexport const Hasher = createImplementation({\n abstraction: HasherAbstraction,\n implementation: ScryptHasher,\n dependencies: [HashingConfig]\n});\n"],"names":["scrypt","value","salt","keylen","options","Promise","resolve","reject","scryptCb","err","derivedKey","PREFIX","KEYLEN","SALT_BYTES","DEFAULT_COST","ScryptHasher","config","N","r","p","randomBytes","derived","storedHash","parts","nRaw","rRaw","pRaw","saltB64","hashB64","Number","Buffer","expected","timingSafeEqual","Hasher","createImplementation","HasherAbstraction","HashingConfig"],"mappings":";;;AASA,MAAMA,sBAAS,CACXC,OACAC,MACAC,QACAC,UAEA,IAAIC,QAAQ,CAACC,SAASC;QAClBC,OAASP,OAAOC,MAAMC,QAAQC,SAAS,CAACK,KAAKC;YACzC,IAAID,KACAF,OAAOE;iBAEPH,QAAQI;QAEhB;IACJ;AAgBJ,MAAMC,SAAS;AACf,MAAMC,SAAS;AACf,MAAMC,aAAa;AAQnB,MAAMC,eAA2B;IAAE,GAAG;IAAO,GAAG;IAAG,GAAG;AAAE;AAEjD,MAAMC;IAIT,YAAYC,MAA+B,CAAE;QACzC,IAAI,CAAC,MAAM,GAAGA,OAAO,MAAM;QAC3B,IAAI,CAAC,IAAI,GAAGA,OAAO,KAAK,GAAG;YAAE,GAAGF,YAAY;YAAE,GAAGE,OAAO,KAAK;QAAC,IAAIF;IACtE;IAEA,MAAM,KAAKb,KAAa,EAAmB;QACvC,MAAM,EAAEgB,CAAC,EAAEC,CAAC,EAAEC,CAAC,EAAE,GAAG,IAAI,CAAC,IAAI;QAC7B,MAAMjB,OAAOkB,YAAYP;QACzB,MAAMQ,UAAW,MAAMrB,oBAAO,IAAI,CAAC,UAAU,CAACC,QAAQC,MAAMU,QAAQ;YAAEK;YAAGC;YAAGC;QAAE;QAE9E,OAAO;YAACR;YAAQM;YAAGC;YAAGC;YAAGjB,KAAK,QAAQ,CAAC;YAAWmB,QAAQ,QAAQ,CAAC;SAAU,CAAC,IAAI,CAAC;IACvF;IAEA,MAAM,OAAOpB,KAAa,EAAEqB,UAAkB,EAAoB;QAC9D,MAAMC,QAAQD,WAAW,KAAK,CAAC;QAC/B,IAAIC,AAAiB,MAAjBA,MAAM,MAAM,IAAUA,KAAK,CAAC,EAAE,KAAKZ,QACnC,OAAO;QAGX,MAAM,GAAGa,MAAMC,MAAMC,MAAMC,SAASC,QAAQ,GAAGL;QAC/C,MAAMN,IAAIY,OAAOL;QACjB,MAAMN,IAAIW,OAAOJ;QACjB,MAAMN,IAAIU,OAAOH;QACjB,MAAMxB,OAAO4B,OAAO,IAAI,CAACH,SAAS;QAClC,MAAMI,WAAWD,OAAO,IAAI,CAACF,SAAS;QAEtC,MAAMP,UAAW,MAAMrB,oBAAO,IAAI,CAAC,UAAU,CAACC,QAAQC,MAAM6B,SAAS,MAAM,EAAE;YACzEd;YACAC;YACAC;QACJ;QAGA,OAAOa,gBAAgBX,SAASU;IACpC;IAEQ,WAAW9B,KAAa,EAAU;QACtC,OAAO,IAAI,CAAC,MAAM,GAAG,GAAGA,QAAQ,IAAI,CAAC,MAAM,EAAE,GAAGA;IACpD;AACJ;AAEO,MAAMgC,sBAASC,qBAAqB;IACvC,aAAaC;IACb,gBAAgBpB;IAChB,cAAc;QAACqB;KAAc;AACjC"}
|
|
@@ -16,3 +16,18 @@ export declare const Hasher: import("@webiny/di").Abstraction<IHasher>;
|
|
|
16
16
|
export declare namespace Hasher {
|
|
17
17
|
type Interface = IHasher;
|
|
18
18
|
}
|
|
19
|
+
export interface IHashingConfig {
|
|
20
|
+
/** Server-side secret folded into every hash. Empty when none is configured. */
|
|
21
|
+
readonly pepper: string;
|
|
22
|
+
/** scrypt cost parameter N. `null` uses the default. */
|
|
23
|
+
readonly costN: number | null;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Where `Hasher` gets its pepper and cost. The default reads the `HashingPepper` and `HashingCost`
|
|
27
|
+
* build params (`<Infra.Crypto.Hashing>`). A hosting type can replace it, e.g. to read the pepper
|
|
28
|
+
* from env at startup.
|
|
29
|
+
*/
|
|
30
|
+
export declare const HashingConfig: import("@webiny/di").Abstraction<IHashingConfig>;
|
|
31
|
+
export declare namespace HashingConfig {
|
|
32
|
+
type Interface = IHashingConfig;
|
|
33
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/hashing/abstractions.js","sources":["../../../src/features/hashing/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\n\nexport interface IHasher {\n hash(value: string): Promise<string>;\n /** Constant-time compare of `value` against a previously produced hash string. */\n verify(value: string, storedHash: string): Promise<boolean>;\n}\n\n/**\n * Hashes and verifies secret values (passwords, API-key secrets, tokens, …) with a slow, salted\n * KDF — built for the \"store a hash, later verify a presented value\" pattern.\n *\n * NOT a general-purpose digest: output is salted and non-deterministic, so this is the wrong tool\n * for checksums / cache keys / dedup (use a fast deterministic digest util for those). Swap the\n * implementation to change algorithms (e.g. Argon2id); stored hashes are self-describing, so old\n * hashes keep verifying after a swap.\n */\nexport const Hasher = createAbstraction<IHasher>(\"Hasher\");\n\nexport namespace Hasher {\n export type Interface = IHasher;\n}\n"],"names":["Hasher","createAbstraction"],"mappings":";AAiBO,MAAMA,SAASC,kBAA2B"}
|
|
1
|
+
{"version":3,"file":"features/hashing/abstractions.js","sources":["../../../src/features/hashing/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\n\nexport interface IHasher {\n hash(value: string): Promise<string>;\n /** Constant-time compare of `value` against a previously produced hash string. */\n verify(value: string, storedHash: string): Promise<boolean>;\n}\n\n/**\n * Hashes and verifies secret values (passwords, API-key secrets, tokens, …) with a slow, salted\n * KDF — built for the \"store a hash, later verify a presented value\" pattern.\n *\n * NOT a general-purpose digest: output is salted and non-deterministic, so this is the wrong tool\n * for checksums / cache keys / dedup (use a fast deterministic digest util for those). Swap the\n * implementation to change algorithms (e.g. Argon2id); stored hashes are self-describing, so old\n * hashes keep verifying after a swap.\n */\nexport const Hasher = createAbstraction<IHasher>(\"Hasher\");\n\nexport namespace Hasher {\n export type Interface = IHasher;\n}\n\nexport interface IHashingConfig {\n /** Server-side secret folded into every hash. Empty when none is configured. */\n readonly pepper: string;\n /** scrypt cost parameter N. `null` uses the default. */\n readonly costN: number | null;\n}\n\n/**\n * Where `Hasher` gets its pepper and cost. The default reads the `HashingPepper` and `HashingCost`\n * build params (`<Infra.Crypto.Hashing>`). A hosting type can replace it, e.g. to read the pepper\n * from env at startup.\n */\nexport const HashingConfig = createAbstraction<IHashingConfig>(\"HashingConfig\");\n\nexport namespace HashingConfig {\n export type Interface = IHashingConfig;\n}\n"],"names":["Hasher","createAbstraction","HashingConfig"],"mappings":";AAiBO,MAAMA,SAASC,kBAA2B;AAkB1C,MAAMC,gBAAgBD,kBAAkC"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { createFeature } from "@webiny/feature/api";
|
|
2
2
|
import { Hasher } from "./ScryptHasher.js";
|
|
3
|
+
import { BuildParamsHashingConfig } from "./BuildParamsHashingConfig.js";
|
|
3
4
|
const HasherFeature = createFeature({
|
|
4
5
|
name: "HasherFeature",
|
|
5
6
|
register (container) {
|
|
7
|
+
container.register(BuildParamsHashingConfig);
|
|
6
8
|
container.register(Hasher);
|
|
7
9
|
}
|
|
8
10
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/hashing/feature.js","sources":["../../../src/features/hashing/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { Hasher } from \"./ScryptHasher.js\";\n\nexport const HasherFeature = createFeature({\n name: \"HasherFeature\",\n register(container) {\n container.register(Hasher);\n }\n});\n"],"names":["HasherFeature","createFeature","container","Hasher"],"mappings":"
|
|
1
|
+
{"version":3,"file":"features/hashing/feature.js","sources":["../../../src/features/hashing/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { Hasher } from \"./ScryptHasher.js\";\nimport { BuildParamsHashingConfig } from \"./BuildParamsHashingConfig.js\";\n\nexport const HasherFeature = createFeature({\n name: \"HasherFeature\",\n register(container) {\n container.register(BuildParamsHashingConfig);\n container.register(Hasher);\n }\n});\n"],"names":["HasherFeature","createFeature","container","BuildParamsHashingConfig","Hasher"],"mappings":";;;AAIO,MAAMA,gBAAgBC,cAAc;IACvC,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE;IACvB;AACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { Hasher } from "./abstractions.js";
|
|
1
|
+
export { Hasher, HashingConfig } from "./abstractions.js";
|
|
@@ -12,6 +12,7 @@ declare class IdentityContextImpl implements Abstraction.Interface {
|
|
|
12
12
|
setIdentity(identity: Identity | undefined): void;
|
|
13
13
|
withIdentity<T>(identity: Identity | undefined, cb: () => Promise<T>): Promise<T>;
|
|
14
14
|
withoutAuthorization<T>(cb: () => Promise<T>): Promise<T>;
|
|
15
|
+
withAuthorization<T>(cb: () => Promise<T>): Promise<T>;
|
|
15
16
|
isAuthorizationEnabled(): boolean;
|
|
16
17
|
getPermission<TPermission extends SecurityPermission = SecurityPermission>(name: string): Promise<TPermission | null>;
|
|
17
18
|
getPermissions<TPermission extends SecurityPermission = SecurityPermission>(name: string): Promise<TPermission[]>;
|
|
@@ -28,6 +28,9 @@ class IdentityContextImpl {
|
|
|
28
28
|
withoutAuthorization(cb) {
|
|
29
29
|
return this.authorizationContext.withoutAuthorization(cb);
|
|
30
30
|
}
|
|
31
|
+
withAuthorization(cb) {
|
|
32
|
+
return this.authorizationContext.withAuthorization(cb);
|
|
33
|
+
}
|
|
31
34
|
isAuthorizationEnabled() {
|
|
32
35
|
return this.authorizationContext.isAuthorizationEnabled();
|
|
33
36
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/security/IdentityContext/IdentityContext.js","sources":["../../../../src/features/security/IdentityContext/IdentityContext.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"async_hooks\";\nimport { minimatch } from \"minimatch\";\nimport { createImplementation } from \"@webiny/di\";\nimport { IdentityContext as Abstraction } from \"./abstractions.js\";\nimport { Identity } from \"./Identity.js\";\nimport { AnonymousIdentity } from \"./AnonymousIdentity.js\";\nimport { AuthorizationContext } from \"../authorization/AuthorizationContext/index.js\";\nimport { filterOutCustomWbyAppsPermissions } from \"../utils/filterOutCustomWbyAppsPermissions.js\";\nimport type { SecurityPermission } from \"~/types/security.js\";\nimport type { AaclPermission } from \"../../wcp/WcpContext/types.js\";\nimport { FeatureFlags } from \"../../featureFlags/abstractions.js\";\n\nconst identityStorage = new AsyncLocalStorage<Identity | undefined>();\n\nclass IdentityContextImpl implements Abstraction.Interface {\n private identity: Identity = new AnonymousIdentity();\n\n constructor(\n private authorizationContext: AuthorizationContext.Interface,\n private featureFlags: FeatureFlags.Interface\n ) {}\n\n // ========================================================================\n // Identity Methods\n // ========================================================================\n\n getIdentity(): Identity {\n // Check for identity override first (from withIdentity())\n const override = identityStorage.getStore();\n if (override !== undefined) {\n return override;\n }\n return this.identity;\n }\n\n setIdentity(identity: Identity | undefined): void {\n // If undefined, set to anonymous identity\n this.identity = identity ?? new AnonymousIdentity();\n\n // Clear permissions cache when identity changes\n this.authorizationContext.clearPermissionsCache();\n }\n\n withIdentity<T>(identity: Identity | undefined, cb: () => Promise<T>): Promise<T> {\n return identityStorage.run(identity, cb);\n }\n\n // ========================================================================\n // Authorization State Methods\n // ========================================================================\n\n withoutAuthorization<T>(cb: () => Promise<T>): Promise<T> {\n return this.authorizationContext.withoutAuthorization(cb);\n }\n\n isAuthorizationEnabled(): boolean {\n return this.authorizationContext.isAuthorizationEnabled();\n }\n\n // ========================================================================\n // Permission Methods\n // ========================================================================\n\n async getPermission<TPermission extends SecurityPermission = SecurityPermission>(\n name: string\n ): Promise<TPermission | null> {\n if (!this.isAuthorizationEnabled()) {\n return { name: \"*\" } as TPermission;\n }\n\n const permissions = await this.listPermissions();\n\n // Try exact match first\n const exactMatch = permissions.find(p => p.name === name);\n if (exactMatch) {\n return exactMatch as TPermission;\n }\n\n // Try pattern matching\n const patternMatch = permissions.find(p => minimatch(name, p.name));\n if (patternMatch) {\n return patternMatch as TPermission;\n }\n\n return null;\n }\n\n async getPermissions<TPermission extends SecurityPermission = SecurityPermission>(\n name: string\n ): Promise<TPermission[]> {\n if (!this.isAuthorizationEnabled()) {\n return [{ name: \"*\" }] as TPermission[];\n }\n\n const permissions = await this.listPermissions();\n\n return permissions.filter(p => {\n if (p.name === name) {\n return true;\n }\n return minimatch(name, p.name);\n }) as TPermission[];\n }\n\n async listPermissions(): Promise<SecurityPermission[]> {\n const permissions = await this.authorizationContext.loadPermissions(this.getIdentity());\n // TODO: extract this into a decorator\n return this.applyAaclLogic(permissions);\n }\n\n async hasFullAccess(): Promise<boolean> {\n const permissions = await this.listPermissions();\n return permissions.some(p => p.name === \"*\");\n }\n\n // ========================================================================\n // Private Helper Methods\n // ========================================================================\n\n private applyAaclLogic(permissions: SecurityPermission[]): SecurityPermission[] {\n const aaclEnabled = this.featureFlags.get().isEnabled(\"advancedAccessControlLayer\");\n const teamsEnabled = this.featureFlags.get().isEnabled(\"advancedAccessControlLayer.teams\");\n\n if (aaclEnabled) {\n // Add AACL metadata permission\n return [\n ...permissions,\n {\n name: \"aacl\",\n teams: teamsEnabled\n } as AaclPermission\n ];\n }\n\n // If AACL is not enabled, filter out custom Webiny apps permissions\n return filterOutCustomWbyAppsPermissions(permissions);\n }\n}\n\nexport const IdentityContext = createImplementation({\n abstraction: Abstraction,\n implementation: IdentityContextImpl,\n dependencies: [AuthorizationContext, FeatureFlags]\n});\n"],"names":["identityStorage","AsyncLocalStorage","IdentityContextImpl","authorizationContext","featureFlags","AnonymousIdentity","override","undefined","identity","cb","name","permissions","exactMatch","p","patternMatch","minimatch","aaclEnabled","teamsEnabled","filterOutCustomWbyAppsPermissions","IdentityContext","createImplementation","Abstraction","AuthorizationContext","FeatureFlags"],"mappings":";;;;;;;;AAYA,MAAMA,kBAAkB,IAAIC;AAE5B,MAAMC;IAGF,YACYC,oBAAoD,EACpDC,YAAoC,CAC9C;aAFUD,oBAAoB,GAApBA;aACAC,YAAY,GAAZA;aAJJ,QAAQ,GAAa,IAAIC;IAK9B;IAMH,cAAwB;QAEpB,MAAMC,WAAWN,gBAAgB,QAAQ;QACzC,IAAIM,AAAaC,WAAbD,UACA,OAAOA;QAEX,OAAO,IAAI,CAAC,QAAQ;IACxB;IAEA,YAAYE,QAA8B,EAAQ;QAE9C,IAAI,CAAC,QAAQ,GAAGA,YAAY,IAAIH;QAGhC,IAAI,CAAC,oBAAoB,CAAC,qBAAqB;IACnD;IAEA,aAAgBG,QAA8B,EAAEC,EAAoB,EAAc;QAC9E,OAAOT,gBAAgB,GAAG,CAACQ,UAAUC;IACzC;IAMA,qBAAwBA,EAAoB,EAAc;QACtD,OAAO,IAAI,CAAC,oBAAoB,CAAC,oBAAoB,CAACA;IAC1D;IAEA,yBAAkC;QAC9B,OAAO,IAAI,CAAC,oBAAoB,CAAC,sBAAsB;IAC3D;IAMA,MAAM,cACFC,IAAY,EACe;QAC3B,IAAI,CAAC,IAAI,CAAC,sBAAsB,IAC5B,OAAO;YAAE,MAAM;QAAI;QAGvB,MAAMC,cAAc,MAAM,IAAI,CAAC,eAAe;QAG9C,MAAMC,aAAaD,YAAY,IAAI,CAACE,CAAAA,IAAKA,EAAE,IAAI,KAAKH;QACpD,IAAIE,YACA,OAAOA;QAIX,MAAME,eAAeH,YAAY,IAAI,CAACE,CAAAA,IAAKE,UAAUL,MAAMG,EAAE,IAAI;QACjE,IAAIC,cACA,OAAOA;QAGX,OAAO;IACX;IAEA,MAAM,eACFJ,IAAY,EACU;QACtB,IAAI,CAAC,IAAI,CAAC,sBAAsB,IAC5B,OAAO;YAAC;gBAAE,MAAM;YAAI;SAAE;QAG1B,MAAMC,cAAc,MAAM,IAAI,CAAC,eAAe;QAE9C,OAAOA,YAAY,MAAM,CAACE,CAAAA;YACtB,IAAIA,EAAE,IAAI,KAAKH,MACX,OAAO;YAEX,OAAOK,UAAUL,MAAMG,EAAE,IAAI;QACjC;IACJ;IAEA,MAAM,kBAAiD;QACnD,MAAMF,cAAc,MAAM,IAAI,CAAC,oBAAoB,CAAC,eAAe,CAAC,IAAI,CAAC,WAAW;QAEpF,OAAO,IAAI,CAAC,cAAc,CAACA;IAC/B;IAEA,MAAM,gBAAkC;QACpC,MAAMA,cAAc,MAAM,IAAI,CAAC,eAAe;QAC9C,OAAOA,YAAY,IAAI,CAACE,CAAAA,IAAKA,AAAW,QAAXA,EAAE,IAAI;IACvC;IAMQ,eAAeF,WAAiC,EAAwB;QAC5E,MAAMK,cAAc,IAAI,CAAC,YAAY,CAAC,GAAG,GAAG,SAAS,CAAC;QACtD,MAAMC,eAAe,IAAI,CAAC,YAAY,CAAC,GAAG,GAAG,SAAS,CAAC;QAEvD,IAAID,aAEA,OAAO;eACAL;YACH;gBACI,MAAM;gBACN,OAAOM;YACX;SACH;QAIL,OAAOC,kCAAkCP;IAC7C;AACJ;AAEO,MAAMQ,kCAAkBC,qBAAqB;IAChD,aAAaC;IACb,gBAAgBnB;IAChB,cAAc;QAACoB;QAAsBC;KAAa;AACtD"}
|
|
1
|
+
{"version":3,"file":"features/security/IdentityContext/IdentityContext.js","sources":["../../../../src/features/security/IdentityContext/IdentityContext.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"async_hooks\";\nimport { minimatch } from \"minimatch\";\nimport { createImplementation } from \"@webiny/di\";\nimport { IdentityContext as Abstraction } from \"./abstractions.js\";\nimport { Identity } from \"./Identity.js\";\nimport { AnonymousIdentity } from \"./AnonymousIdentity.js\";\nimport { AuthorizationContext } from \"../authorization/AuthorizationContext/index.js\";\nimport { filterOutCustomWbyAppsPermissions } from \"../utils/filterOutCustomWbyAppsPermissions.js\";\nimport type { SecurityPermission } from \"~/types/security.js\";\nimport type { AaclPermission } from \"../../wcp/WcpContext/types.js\";\nimport { FeatureFlags } from \"../../featureFlags/abstractions.js\";\n\nconst identityStorage = new AsyncLocalStorage<Identity | undefined>();\n\nclass IdentityContextImpl implements Abstraction.Interface {\n private identity: Identity = new AnonymousIdentity();\n\n constructor(\n private authorizationContext: AuthorizationContext.Interface,\n private featureFlags: FeatureFlags.Interface\n ) {}\n\n // ========================================================================\n // Identity Methods\n // ========================================================================\n\n getIdentity(): Identity {\n // Check for identity override first (from withIdentity())\n const override = identityStorage.getStore();\n if (override !== undefined) {\n return override;\n }\n return this.identity;\n }\n\n setIdentity(identity: Identity | undefined): void {\n // If undefined, set to anonymous identity\n this.identity = identity ?? new AnonymousIdentity();\n\n // Clear permissions cache when identity changes\n this.authorizationContext.clearPermissionsCache();\n }\n\n withIdentity<T>(identity: Identity | undefined, cb: () => Promise<T>): Promise<T> {\n return identityStorage.run(identity, cb);\n }\n\n // ========================================================================\n // Authorization State Methods\n // ========================================================================\n\n withoutAuthorization<T>(cb: () => Promise<T>): Promise<T> {\n return this.authorizationContext.withoutAuthorization(cb);\n }\n\n withAuthorization<T>(cb: () => Promise<T>): Promise<T> {\n return this.authorizationContext.withAuthorization(cb);\n }\n\n isAuthorizationEnabled(): boolean {\n return this.authorizationContext.isAuthorizationEnabled();\n }\n\n // ========================================================================\n // Permission Methods\n // ========================================================================\n\n async getPermission<TPermission extends SecurityPermission = SecurityPermission>(\n name: string\n ): Promise<TPermission | null> {\n if (!this.isAuthorizationEnabled()) {\n return { name: \"*\" } as TPermission;\n }\n\n const permissions = await this.listPermissions();\n\n // Try exact match first\n const exactMatch = permissions.find(p => p.name === name);\n if (exactMatch) {\n return exactMatch as TPermission;\n }\n\n // Try pattern matching\n const patternMatch = permissions.find(p => minimatch(name, p.name));\n if (patternMatch) {\n return patternMatch as TPermission;\n }\n\n return null;\n }\n\n async getPermissions<TPermission extends SecurityPermission = SecurityPermission>(\n name: string\n ): Promise<TPermission[]> {\n if (!this.isAuthorizationEnabled()) {\n return [{ name: \"*\" }] as TPermission[];\n }\n\n const permissions = await this.listPermissions();\n\n return permissions.filter(p => {\n if (p.name === name) {\n return true;\n }\n return minimatch(name, p.name);\n }) as TPermission[];\n }\n\n async listPermissions(): Promise<SecurityPermission[]> {\n const permissions = await this.authorizationContext.loadPermissions(this.getIdentity());\n // TODO: extract this into a decorator\n return this.applyAaclLogic(permissions);\n }\n\n async hasFullAccess(): Promise<boolean> {\n const permissions = await this.listPermissions();\n return permissions.some(p => p.name === \"*\");\n }\n\n // ========================================================================\n // Private Helper Methods\n // ========================================================================\n\n private applyAaclLogic(permissions: SecurityPermission[]): SecurityPermission[] {\n const aaclEnabled = this.featureFlags.get().isEnabled(\"advancedAccessControlLayer\");\n const teamsEnabled = this.featureFlags.get().isEnabled(\"advancedAccessControlLayer.teams\");\n\n if (aaclEnabled) {\n // Add AACL metadata permission\n return [\n ...permissions,\n {\n name: \"aacl\",\n teams: teamsEnabled\n } as AaclPermission\n ];\n }\n\n // If AACL is not enabled, filter out custom Webiny apps permissions\n return filterOutCustomWbyAppsPermissions(permissions);\n }\n}\n\nexport const IdentityContext = createImplementation({\n abstraction: Abstraction,\n implementation: IdentityContextImpl,\n dependencies: [AuthorizationContext, FeatureFlags]\n});\n"],"names":["identityStorage","AsyncLocalStorage","IdentityContextImpl","authorizationContext","featureFlags","AnonymousIdentity","override","undefined","identity","cb","name","permissions","exactMatch","p","patternMatch","minimatch","aaclEnabled","teamsEnabled","filterOutCustomWbyAppsPermissions","IdentityContext","createImplementation","Abstraction","AuthorizationContext","FeatureFlags"],"mappings":";;;;;;;;AAYA,MAAMA,kBAAkB,IAAIC;AAE5B,MAAMC;IAGF,YACYC,oBAAoD,EACpDC,YAAoC,CAC9C;aAFUD,oBAAoB,GAApBA;aACAC,YAAY,GAAZA;aAJJ,QAAQ,GAAa,IAAIC;IAK9B;IAMH,cAAwB;QAEpB,MAAMC,WAAWN,gBAAgB,QAAQ;QACzC,IAAIM,AAAaC,WAAbD,UACA,OAAOA;QAEX,OAAO,IAAI,CAAC,QAAQ;IACxB;IAEA,YAAYE,QAA8B,EAAQ;QAE9C,IAAI,CAAC,QAAQ,GAAGA,YAAY,IAAIH;QAGhC,IAAI,CAAC,oBAAoB,CAAC,qBAAqB;IACnD;IAEA,aAAgBG,QAA8B,EAAEC,EAAoB,EAAc;QAC9E,OAAOT,gBAAgB,GAAG,CAACQ,UAAUC;IACzC;IAMA,qBAAwBA,EAAoB,EAAc;QACtD,OAAO,IAAI,CAAC,oBAAoB,CAAC,oBAAoB,CAACA;IAC1D;IAEA,kBAAqBA,EAAoB,EAAc;QACnD,OAAO,IAAI,CAAC,oBAAoB,CAAC,iBAAiB,CAACA;IACvD;IAEA,yBAAkC;QAC9B,OAAO,IAAI,CAAC,oBAAoB,CAAC,sBAAsB;IAC3D;IAMA,MAAM,cACFC,IAAY,EACe;QAC3B,IAAI,CAAC,IAAI,CAAC,sBAAsB,IAC5B,OAAO;YAAE,MAAM;QAAI;QAGvB,MAAMC,cAAc,MAAM,IAAI,CAAC,eAAe;QAG9C,MAAMC,aAAaD,YAAY,IAAI,CAACE,CAAAA,IAAKA,EAAE,IAAI,KAAKH;QACpD,IAAIE,YACA,OAAOA;QAIX,MAAME,eAAeH,YAAY,IAAI,CAACE,CAAAA,IAAKE,UAAUL,MAAMG,EAAE,IAAI;QACjE,IAAIC,cACA,OAAOA;QAGX,OAAO;IACX;IAEA,MAAM,eACFJ,IAAY,EACU;QACtB,IAAI,CAAC,IAAI,CAAC,sBAAsB,IAC5B,OAAO;YAAC;gBAAE,MAAM;YAAI;SAAE;QAG1B,MAAMC,cAAc,MAAM,IAAI,CAAC,eAAe;QAE9C,OAAOA,YAAY,MAAM,CAACE,CAAAA;YACtB,IAAIA,EAAE,IAAI,KAAKH,MACX,OAAO;YAEX,OAAOK,UAAUL,MAAMG,EAAE,IAAI;QACjC;IACJ;IAEA,MAAM,kBAAiD;QACnD,MAAMF,cAAc,MAAM,IAAI,CAAC,oBAAoB,CAAC,eAAe,CAAC,IAAI,CAAC,WAAW;QAEpF,OAAO,IAAI,CAAC,cAAc,CAACA;IAC/B;IAEA,MAAM,gBAAkC;QACpC,MAAMA,cAAc,MAAM,IAAI,CAAC,eAAe;QAC9C,OAAOA,YAAY,IAAI,CAACE,CAAAA,IAAKA,AAAW,QAAXA,EAAE,IAAI;IACvC;IAMQ,eAAeF,WAAiC,EAAwB;QAC5E,MAAMK,cAAc,IAAI,CAAC,YAAY,CAAC,GAAG,GAAG,SAAS,CAAC;QACtD,MAAMC,eAAe,IAAI,CAAC,YAAY,CAAC,GAAG,GAAG,SAAS,CAAC;QAEvD,IAAID,aAEA,OAAO;eACAL;YACH;gBACI,MAAM;gBACN,OAAOM;YACX;SACH;QAIL,OAAOC,kCAAkCP;IAC7C;AACJ;AAEO,MAAMQ,kCAAkBC,qBAAqB;IAChD,aAAaC;IACb,gBAAgBnB;IAChB,cAAc;QAACoB;QAAsBC;KAAa;AACtD"}
|
|
@@ -9,6 +9,11 @@ export interface IIdentityContext {
|
|
|
9
9
|
listPermissions(): Promise<SecurityPermission[]>;
|
|
10
10
|
hasFullAccess(): Promise<boolean>;
|
|
11
11
|
withoutAuthorization<T>(cb: () => Promise<T>): Promise<T>;
|
|
12
|
+
/**
|
|
13
|
+
* Runs `cb` with authorization enabled, also inside `withoutAuthorization`. Combine with
|
|
14
|
+
* `withIdentity` to evaluate another user's real permissions from a background task.
|
|
15
|
+
*/
|
|
16
|
+
withAuthorization<T>(cb: () => Promise<T>): Promise<T>;
|
|
12
17
|
isAuthorizationEnabled(): boolean;
|
|
13
18
|
}
|
|
14
19
|
/** Provides access to the current identity and its permissions. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/security/IdentityContext/abstractions.js","sources":["../../../../src/features/security/IdentityContext/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { Identity } from \"./Identity.js\";\nimport type { SecurityPermission } from \"~/types/security.js\";\n\nexport interface IIdentityContext {\n // Identity methods\n getIdentity(): Identity;\n setIdentity(identity: Identity | undefined): void;\n withIdentity<T>(identity: Identity | undefined, cb: () => Promise<T>): Promise<T>;\n\n // Permission methods\n getPermission<TPermission extends SecurityPermission = SecurityPermission>(\n name: string\n ): Promise<TPermission | null>;\n\n getPermissions<TPermission extends SecurityPermission = SecurityPermission>(\n name: string\n ): Promise<TPermission[]>;\n\n listPermissions(): Promise<SecurityPermission[]>;\n\n hasFullAccess(): Promise<boolean>;\n\n // Authorization context methods\n withoutAuthorization<T>(cb: () => Promise<T>): Promise<T>;\n isAuthorizationEnabled(): boolean;\n}\n\n/** Provides access to the current identity and its permissions. */\nexport const IdentityContext = createAbstraction<IIdentityContext>(\"IdentityContext\");\n\nexport namespace IdentityContext {\n export type Interface = IIdentityContext;\n}\n"],"names":["IdentityContext","createAbstraction"],"mappings":";
|
|
1
|
+
{"version":3,"file":"features/security/IdentityContext/abstractions.js","sources":["../../../../src/features/security/IdentityContext/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { Identity } from \"./Identity.js\";\nimport type { SecurityPermission } from \"~/types/security.js\";\n\nexport interface IIdentityContext {\n // Identity methods\n getIdentity(): Identity;\n setIdentity(identity: Identity | undefined): void;\n withIdentity<T>(identity: Identity | undefined, cb: () => Promise<T>): Promise<T>;\n\n // Permission methods\n getPermission<TPermission extends SecurityPermission = SecurityPermission>(\n name: string\n ): Promise<TPermission | null>;\n\n getPermissions<TPermission extends SecurityPermission = SecurityPermission>(\n name: string\n ): Promise<TPermission[]>;\n\n listPermissions(): Promise<SecurityPermission[]>;\n\n hasFullAccess(): Promise<boolean>;\n\n // Authorization context methods\n withoutAuthorization<T>(cb: () => Promise<T>): Promise<T>;\n /**\n * Runs `cb` with authorization enabled, also inside `withoutAuthorization`. Combine with\n * `withIdentity` to evaluate another user's real permissions from a background task.\n */\n withAuthorization<T>(cb: () => Promise<T>): Promise<T>;\n isAuthorizationEnabled(): boolean;\n}\n\n/** Provides access to the current identity and its permissions. */\nexport const IdentityContext = createAbstraction<IIdentityContext>(\"IdentityContext\");\n\nexport namespace IdentityContext {\n export type Interface = IIdentityContext;\n}\n"],"names":["IdentityContext","createAbstraction"],"mappings":";AAkCO,MAAMA,kBAAkBC,kBAAoC"}
|
|
@@ -2,16 +2,25 @@ import { AuthorizationContext as Abstraction, PermissionTransformer } from "./ab
|
|
|
2
2
|
import { Authorizer } from "../Authorizer/index.js";
|
|
3
3
|
import type { SecurityPermission } from "../../../../types/security.js";
|
|
4
4
|
import { Identity } from "../../../../features/security/IdentityContext/index.js";
|
|
5
|
+
/**
|
|
6
|
+
* Loads and caches permissions per identity object and tenant for the lifetime of the request.
|
|
7
|
+
* `IdentityContext.withIdentity` can switch the identity mid-request and `TenantContext` the
|
|
8
|
+
* tenant, so permissions loaded for one identity or tenant never answer for another. Keying by the
|
|
9
|
+
* object (not by id or a fingerprint) means two identities with the same id but a different
|
|
10
|
+
* context never share an entry (R69). A failed load is evicted, so the next check retries.
|
|
11
|
+
*/
|
|
5
12
|
export declare class AuthorizationContext implements Abstraction.Interface {
|
|
6
13
|
private getAuthorizers;
|
|
7
14
|
private getTransformers;
|
|
8
|
-
private
|
|
9
|
-
private
|
|
10
|
-
constructor(getAuthorizers: () => Authorizer.Interface[], getTransformers: () => PermissionTransformer.Interface[]);
|
|
15
|
+
private getTenantId;
|
|
16
|
+
private permissionsByIdentity;
|
|
17
|
+
constructor(getAuthorizers: () => Authorizer.Interface[], getTransformers: () => PermissionTransformer.Interface[], getTenantId: () => string | null);
|
|
11
18
|
loadPermissions(identity: Identity): Promise<SecurityPermission[]>;
|
|
12
19
|
isAuthorizationEnabled(): boolean;
|
|
13
20
|
withoutAuthorization<T>(cb: () => Promise<T>): Promise<T>;
|
|
21
|
+
withAuthorization<T>(cb: () => Promise<T>): Promise<T>;
|
|
14
22
|
clearPermissionsCache(): void;
|
|
23
|
+
private authorize;
|
|
15
24
|
private transformPermissions;
|
|
16
25
|
private deduplicatePermissions;
|
|
17
26
|
}
|
|
@@ -1,26 +1,29 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from "async_hooks";
|
|
2
2
|
const authorizationEnabledStorage = new AsyncLocalStorage();
|
|
3
|
+
const NO_TENANT = "";
|
|
3
4
|
class AuthorizationContext {
|
|
4
|
-
constructor(getAuthorizers, getTransformers){
|
|
5
|
+
constructor(getAuthorizers, getTransformers, getTenantId){
|
|
5
6
|
this.getAuthorizers = getAuthorizers;
|
|
6
7
|
this.getTransformers = getTransformers;
|
|
8
|
+
this.getTenantId = getTenantId;
|
|
9
|
+
this.permissionsByIdentity = new WeakMap();
|
|
7
10
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
11
|
+
loadPermissions(identity) {
|
|
12
|
+
let byTenant = this.permissionsByIdentity.get(identity);
|
|
13
|
+
if (!byTenant) {
|
|
14
|
+
byTenant = new Map();
|
|
15
|
+
this.permissionsByIdentity.set(identity, byTenant);
|
|
16
|
+
}
|
|
17
|
+
const tenantKey = this.getTenantId() ?? NO_TENANT;
|
|
18
|
+
const cached = byTenant.get(tenantKey);
|
|
19
|
+
if (cached) return cached;
|
|
20
|
+
const loader = this.authorize(identity);
|
|
21
|
+
byTenant.set(tenantKey, loader);
|
|
22
|
+
const cache = byTenant;
|
|
23
|
+
loader.catch(()=>{
|
|
24
|
+
if (cache.get(tenantKey) === loader) cache.delete(tenantKey);
|
|
22
25
|
});
|
|
23
|
-
return
|
|
26
|
+
return loader;
|
|
24
27
|
}
|
|
25
28
|
isAuthorizationEnabled() {
|
|
26
29
|
const override = authorizationEnabledStorage.getStore();
|
|
@@ -29,9 +32,19 @@ class AuthorizationContext {
|
|
|
29
32
|
withoutAuthorization(cb) {
|
|
30
33
|
return authorizationEnabledStorage.run(false, cb);
|
|
31
34
|
}
|
|
35
|
+
withAuthorization(cb) {
|
|
36
|
+
return authorizationEnabledStorage.run(true, cb);
|
|
37
|
+
}
|
|
32
38
|
clearPermissionsCache() {
|
|
33
|
-
this.
|
|
34
|
-
|
|
39
|
+
this.permissionsByIdentity = new WeakMap();
|
|
40
|
+
}
|
|
41
|
+
async authorize(identity) {
|
|
42
|
+
const authorizers = this.getAuthorizers();
|
|
43
|
+
for (const authorizer of authorizers){
|
|
44
|
+
const permissions = await authorizer.authorize(identity);
|
|
45
|
+
if (Array.isArray(permissions)) return this.transformPermissions(permissions);
|
|
46
|
+
}
|
|
47
|
+
return [];
|
|
35
48
|
}
|
|
36
49
|
transformPermissions(permissions) {
|
|
37
50
|
const transformers = this.getTransformers();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/security/authorization/AuthorizationContext/AuthorizationContext.js","sources":["../../../../../src/features/security/authorization/AuthorizationContext/AuthorizationContext.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"async_hooks\";\nimport { AuthorizationContext as Abstraction, PermissionTransformer } from \"./abstractions.js\";\nimport { Authorizer } from \"../Authorizer/index.js\";\nimport type { SecurityPermission } from \"~/types/security.js\";\nimport { Identity } from \"~/features/security/IdentityContext/index.js\";\n\nconst authorizationEnabledStorage = new AsyncLocalStorage<boolean>();\n\nexport class AuthorizationContext implements Abstraction.Interface {\n private
|
|
1
|
+
{"version":3,"file":"features/security/authorization/AuthorizationContext/AuthorizationContext.js","sources":["../../../../../src/features/security/authorization/AuthorizationContext/AuthorizationContext.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"async_hooks\";\nimport { AuthorizationContext as Abstraction, PermissionTransformer } from \"./abstractions.js\";\nimport { Authorizer } from \"../Authorizer/index.js\";\nimport type { SecurityPermission } from \"~/types/security.js\";\nimport { Identity } from \"~/features/security/IdentityContext/index.js\";\n\nconst authorizationEnabledStorage = new AsyncLocalStorage<boolean>();\n\n/** Tenant key used when no tenant is set yet (before the tenant is resolved). */\nconst NO_TENANT = \"\";\n\ntype PermissionsByTenant = Map<string, Promise<SecurityPermission[]>>;\n\n/**\n * Loads and caches permissions per identity object and tenant for the lifetime of the request.\n * `IdentityContext.withIdentity` can switch the identity mid-request and `TenantContext` the\n * tenant, so permissions loaded for one identity or tenant never answer for another. Keying by the\n * object (not by id or a fingerprint) means two identities with the same id but a different\n * context never share an entry (R69). A failed load is evicted, so the next check retries.\n */\nexport class AuthorizationContext implements Abstraction.Interface {\n private permissionsByIdentity = new WeakMap<Identity, PermissionsByTenant>();\n\n constructor(\n private getAuthorizers: () => Authorizer.Interface[],\n private getTransformers: () => PermissionTransformer.Interface[],\n private getTenantId: () => string | null\n ) {}\n\n loadPermissions(identity: Identity): Promise<SecurityPermission[]> {\n let byTenant = this.permissionsByIdentity.get(identity);\n if (!byTenant) {\n byTenant = new Map();\n this.permissionsByIdentity.set(identity, byTenant);\n }\n\n const tenantKey = this.getTenantId() ?? NO_TENANT;\n const cached = byTenant.get(tenantKey);\n if (cached) {\n return cached;\n }\n\n const loader = this.authorize(identity);\n byTenant.set(tenantKey, loader);\n const cache = byTenant;\n loader.catch(() => {\n if (cache.get(tenantKey) === loader) {\n cache.delete(tenantKey);\n }\n });\n return loader;\n }\n\n isAuthorizationEnabled(): boolean {\n const override = authorizationEnabledStorage.getStore();\n return override ?? true;\n }\n\n withoutAuthorization<T>(cb: () => Promise<T>): Promise<T> {\n return authorizationEnabledStorage.run(false, cb);\n }\n\n withAuthorization<T>(cb: () => Promise<T>): Promise<T> {\n return authorizationEnabledStorage.run(true, cb);\n }\n\n clearPermissionsCache(): void {\n this.permissionsByIdentity = new WeakMap();\n }\n\n private async authorize(identity: Identity): Promise<SecurityPermission[]> {\n // Execute authorizers in sequence until one returns permissions\n const authorizers = this.getAuthorizers();\n for (const authorizer of authorizers) {\n const permissions = await authorizer.authorize(identity);\n if (Array.isArray(permissions)) {\n return this.transformPermissions(permissions);\n }\n }\n\n // No authorizer returned permissions\n return [];\n }\n\n private transformPermissions(permissions: SecurityPermission[]) {\n const transformers = this.getTransformers();\n if (transformers.length === 0) {\n return this.deduplicatePermissions(permissions);\n }\n\n const transformed = permissions\n .map(permission => {\n // A transformer can return one or multiple permissions, so we flatten the result.\n return transformers.map(t => t.execute(permission)).flat();\n })\n .flat();\n\n return this.deduplicatePermissions(transformed);\n }\n\n private deduplicatePermissions(permissions: SecurityPermission[]) {\n const seen = new Set<string>();\n\n return permissions.filter(permission => {\n const key = JSON.stringify(permission);\n if (seen.has(key)) {\n return false;\n }\n seen.add(key);\n return true;\n });\n }\n}\n"],"names":["authorizationEnabledStorage","AsyncLocalStorage","NO_TENANT","AuthorizationContext","getAuthorizers","getTransformers","getTenantId","WeakMap","identity","byTenant","Map","tenantKey","cached","loader","cache","override","cb","authorizers","authorizer","permissions","Array","transformers","transformed","permission","t","seen","Set","key","JSON"],"mappings":";AAMA,MAAMA,8BAA8B,IAAIC;AAGxC,MAAMC,YAAY;AAWX,MAAMC;IAGT,YACYC,cAA4C,EAC5CC,eAAwD,EACxDC,WAAgC,CAC1C;aAHUF,cAAc,GAAdA;aACAC,eAAe,GAAfA;aACAC,WAAW,GAAXA;aALJ,qBAAqB,GAAG,IAAIC;IAMjC;IAEH,gBAAgBC,QAAkB,EAAiC;QAC/D,IAAIC,WAAW,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAACD;QAC9C,IAAI,CAACC,UAAU;YACXA,WAAW,IAAIC;YACf,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAACF,UAAUC;QAC7C;QAEA,MAAME,YAAY,IAAI,CAAC,WAAW,MAAMT;QACxC,MAAMU,SAASH,SAAS,GAAG,CAACE;QAC5B,IAAIC,QACA,OAAOA;QAGX,MAAMC,SAAS,IAAI,CAAC,SAAS,CAACL;QAC9BC,SAAS,GAAG,CAACE,WAAWE;QACxB,MAAMC,QAAQL;QACdI,OAAO,KAAK,CAAC;YACT,IAAIC,MAAM,GAAG,CAACH,eAAeE,QACzBC,MAAM,MAAM,CAACH;QAErB;QACA,OAAOE;IACX;IAEA,yBAAkC;QAC9B,MAAME,WAAWf,4BAA4B,QAAQ;QACrD,OAAOe,YAAY;IACvB;IAEA,qBAAwBC,EAAoB,EAAc;QACtD,OAAOhB,4BAA4B,GAAG,CAAC,OAAOgB;IAClD;IAEA,kBAAqBA,EAAoB,EAAc;QACnD,OAAOhB,4BAA4B,GAAG,CAAC,MAAMgB;IACjD;IAEA,wBAA8B;QAC1B,IAAI,CAAC,qBAAqB,GAAG,IAAIT;IACrC;IAEA,MAAc,UAAUC,QAAkB,EAAiC;QAEvE,MAAMS,cAAc,IAAI,CAAC,cAAc;QACvC,KAAK,MAAMC,cAAcD,YAAa;YAClC,MAAME,cAAc,MAAMD,WAAW,SAAS,CAACV;YAC/C,IAAIY,MAAM,OAAO,CAACD,cACd,OAAO,IAAI,CAAC,oBAAoB,CAACA;QAEzC;QAGA,OAAO,EAAE;IACb;IAEQ,qBAAqBA,WAAiC,EAAE;QAC5D,MAAME,eAAe,IAAI,CAAC,eAAe;QACzC,IAAIA,AAAwB,MAAxBA,aAAa,MAAM,EACnB,OAAO,IAAI,CAAC,sBAAsB,CAACF;QAGvC,MAAMG,cAAcH,YACf,GAAG,CAACI,CAAAA,aAEMF,aAAa,GAAG,CAACG,CAAAA,IAAKA,EAAE,OAAO,CAACD,aAAa,IAAI,IAE3D,IAAI;QAET,OAAO,IAAI,CAAC,sBAAsB,CAACD;IACvC;IAEQ,uBAAuBH,WAAiC,EAAE;QAC9D,MAAMM,OAAO,IAAIC;QAEjB,OAAOP,YAAY,MAAM,CAACI,CAAAA;YACtB,MAAMI,MAAMC,KAAK,SAAS,CAACL;YAC3B,IAAIE,KAAK,GAAG,CAACE,MACT,OAAO;YAEXF,KAAK,GAAG,CAACE;YACT,OAAO;QACX;IACJ;AACJ"}
|
|
@@ -4,6 +4,8 @@ export interface IAuthorizationContext {
|
|
|
4
4
|
loadPermissions(identity: Identity): Promise<SecurityPermission[]>;
|
|
5
5
|
isAuthorizationEnabled(): boolean;
|
|
6
6
|
withoutAuthorization<T>(cb: () => Promise<T>): Promise<T>;
|
|
7
|
+
/** Runs `cb` with authorization enabled, also inside `withoutAuthorization`. */
|
|
8
|
+
withAuthorization<T>(cb: () => Promise<T>): Promise<T>;
|
|
7
9
|
clearPermissionsCache(): void;
|
|
8
10
|
}
|
|
9
11
|
/** Load and cache security permissions for the current identity. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/security/authorization/AuthorizationContext/abstractions.js","sources":["../../../../../src/features/security/authorization/AuthorizationContext/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { SecurityPermission } from \"~/types/security.js\";\nimport { Identity } from \"~/features/security/IdentityContext/index.js\";\n\nexport interface IAuthorizationContext {\n loadPermissions(identity: Identity): Promise<SecurityPermission[]>;\n isAuthorizationEnabled(): boolean;\n withoutAuthorization<T>(cb: () => Promise<T>): Promise<T>;\n clearPermissionsCache(): void;\n}\n\n/** Load and cache security permissions for the current identity. */\nexport const AuthorizationContext =\n createAbstraction<IAuthorizationContext>(\"AuthorizationContext\");\n\nexport namespace AuthorizationContext {\n export type Interface = IAuthorizationContext;\n}\n\nexport interface IPermissionTransformer {\n execute(permission: SecurityPermission): SecurityPermission | SecurityPermission[];\n}\n\n/** Transform security permissions before they are applied. */\nexport const PermissionTransformer =\n createAbstraction<IPermissionTransformer>(\"PermissionTransformer\");\n\nexport namespace PermissionTransformer {\n export type Interface = IPermissionTransformer;\n export type Permission = SecurityPermission;\n export type Return = SecurityPermission | SecurityPermission[];\n}\n"],"names":["AuthorizationContext","createAbstraction","PermissionTransformer"],"mappings":";
|
|
1
|
+
{"version":3,"file":"features/security/authorization/AuthorizationContext/abstractions.js","sources":["../../../../../src/features/security/authorization/AuthorizationContext/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { SecurityPermission } from \"~/types/security.js\";\nimport { Identity } from \"~/features/security/IdentityContext/index.js\";\n\nexport interface IAuthorizationContext {\n loadPermissions(identity: Identity): Promise<SecurityPermission[]>;\n isAuthorizationEnabled(): boolean;\n withoutAuthorization<T>(cb: () => Promise<T>): Promise<T>;\n /** Runs `cb` with authorization enabled, also inside `withoutAuthorization`. */\n withAuthorization<T>(cb: () => Promise<T>): Promise<T>;\n clearPermissionsCache(): void;\n}\n\n/** Load and cache security permissions for the current identity. */\nexport const AuthorizationContext =\n createAbstraction<IAuthorizationContext>(\"AuthorizationContext\");\n\nexport namespace AuthorizationContext {\n export type Interface = IAuthorizationContext;\n}\n\nexport interface IPermissionTransformer {\n execute(permission: SecurityPermission): SecurityPermission | SecurityPermission[];\n}\n\n/** Transform security permissions before they are applied. */\nexport const PermissionTransformer =\n createAbstraction<IPermissionTransformer>(\"PermissionTransformer\");\n\nexport namespace PermissionTransformer {\n export type Interface = IPermissionTransformer;\n export type Permission = SecurityPermission;\n export type Return = SecurityPermission | SecurityPermission[];\n}\n"],"names":["AuthorizationContext","createAbstraction","PermissionTransformer"],"mappings":";AAcO,MAAMA,uBACTC,kBAAyC;AAWtC,MAAMC,wBACTD,kBAA0C"}
|
|
@@ -2,12 +2,17 @@ import { createFeature } from "@webiny/feature/api";
|
|
|
2
2
|
import { AuthorizationContext } from "./AuthorizationContext.js";
|
|
3
3
|
import { AuthorizationContext as external_abstractions_js_AuthorizationContext, PermissionTransformer } from "./abstractions.js";
|
|
4
4
|
import { Authorizer } from "../Authorizer/index.js";
|
|
5
|
+
import { TenantContext } from "../../../tenancy/TenantContext/index.js";
|
|
5
6
|
const AuthorizationContextFeature = createFeature({
|
|
6
7
|
name: "AuthorizationContext",
|
|
7
8
|
register (container) {
|
|
8
9
|
const getAuthorizers = ()=>container.resolveAll(Authorizer);
|
|
9
10
|
const getTransformers = ()=>container.resolveAll(PermissionTransformer);
|
|
10
|
-
const
|
|
11
|
+
const getTenantId = ()=>{
|
|
12
|
+
const tenantContext = container.resolveAll(TenantContext).at(-1);
|
|
13
|
+
return tenantContext?.getTenant()?.id ?? null;
|
|
14
|
+
};
|
|
15
|
+
const authorizationContext = new AuthorizationContext(getAuthorizers, getTransformers, getTenantId);
|
|
11
16
|
container.registerInstance(external_abstractions_js_AuthorizationContext, authorizationContext);
|
|
12
17
|
}
|
|
13
18
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/security/authorization/AuthorizationContext/feature.js","sources":["../../../../../src/features/security/authorization/AuthorizationContext/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { AuthorizationContext } from \"./AuthorizationContext.js\";\nimport { AuthorizationContext as Abstraction, PermissionTransformer } from \"./abstractions.js\";\nimport { Authorizer } from \"~/features/security/authorization/Authorizer/index.js\";\n\nexport const AuthorizationContextFeature = createFeature({\n name: \"AuthorizationContext\",\n register(container) {\n const getAuthorizers = () => container.resolveAll(Authorizer);\n const getTransformers = () => container.resolveAll(PermissionTransformer);\n\n const authorizationContext = new AuthorizationContext(getAuthorizers
|
|
1
|
+
{"version":3,"file":"features/security/authorization/AuthorizationContext/feature.js","sources":["../../../../../src/features/security/authorization/AuthorizationContext/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { AuthorizationContext } from \"./AuthorizationContext.js\";\nimport { AuthorizationContext as Abstraction, PermissionTransformer } from \"./abstractions.js\";\nimport { Authorizer } from \"~/features/security/authorization/Authorizer/index.js\";\nimport { TenantContext } from \"~/features/tenancy/TenantContext/index.js\";\n\nexport const AuthorizationContextFeature = createFeature({\n name: \"AuthorizationContext\",\n register(container) {\n const getAuthorizers = () => container.resolveAll(Authorizer);\n const getTransformers = () => container.resolveAll(PermissionTransformer);\n // Read lazily: the tenant is set after registration, and slim test containers have none\n // (`resolve` would throw there). The last registration is the one `resolve` returns, so a\n // project override wins over the platform's.\n const getTenantId = (): string | null => {\n const tenantContext = container.resolveAll(TenantContext).at(-1);\n return tenantContext?.getTenant()?.id ?? null;\n };\n\n const authorizationContext = new AuthorizationContext(\n getAuthorizers,\n getTransformers,\n getTenantId\n );\n\n container.registerInstance(Abstraction, authorizationContext);\n }\n});\n"],"names":["AuthorizationContextFeature","createFeature","container","getAuthorizers","Authorizer","getTransformers","PermissionTransformer","getTenantId","tenantContext","TenantContext","authorizationContext","AuthorizationContext","Abstraction"],"mappings":";;;;;AAMO,MAAMA,8BAA8BC,cAAc;IACrD,MAAM;IACN,UAASC,SAAS;QACd,MAAMC,iBAAiB,IAAMD,UAAU,UAAU,CAACE;QAClD,MAAMC,kBAAkB,IAAMH,UAAU,UAAU,CAACI;QAInD,MAAMC,cAAc;YAChB,MAAMC,gBAAgBN,UAAU,UAAU,CAACO,eAAe,EAAE,CAAC;YAC7D,OAAOD,eAAe,aAAa,MAAM;QAC7C;QAEA,MAAME,uBAAuB,IAAIC,qBAC7BR,gBACAE,iBACAE;QAGJL,UAAU,gBAAgB,CAACU,+CAAaF;IAC5C;AACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/users/shared/loaders.js","sources":["../../../../src/features/users/shared/loaders.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\nimport WebinyError from \"@webiny/error\";\nimport flatten from \"lodash/flatten.js\";\nimport type { AdminUsersStorageOperations } from \"~/types/users.js\";\nimport type { AdminUser } from \"./types.js\";\n\ninterface Config {\n getTenant(): string;\n storageOperations: AdminUsersStorageOperations;\n}\n\ninterface GetUserLoaderKey {\n id: string;\n tenant: string;\n}\n\nexport const createUserLoaders = ({ storageOperations }: Config) => {\n const loaders = new Map<string, DataLoader<any, any>>();\n\n async function getUserLoader(ids: readonly GetUserLoaderKey[]) {\n if (ids.length === 0) {\n return [];\n }\n\n // Group by tenant\n const byTenant = ids.reduce(\n (acc, item) => {\n acc[item.tenant] = [...(acc[item.tenant] || []), item.id];\n return acc;\n },\n {} as Record<string, string[]>\n );\n\n try {\n const results = await Promise.all(\n Object.keys(byTenant).map(tenant => {\n return storageOperations.listUsers({\n where: {\n tenant,\n id_in: byTenant[tenant]\n }\n });\n })\n ).then(res => flatten(res));\n\n return ids.map(({ tenant, id }) => {\n const user = results.find(item => item.id === id && item.tenant === tenant);\n /**\n * Casting because DataLoader expect error. But we do not.\n */\n return user || (null as unknown as Error);\n });\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not execute batch read in getUser.\",\n code: \"BATCH_READ_ERROR\",\n data: { ids }\n });\n }\n }\n\n return {\n get getUser() {\n let userLoader = loaders.get(\"getUser\");\n if (userLoader) {\n return userLoader;\n }\n userLoader = new DataLoader<GetUserLoaderKey, AdminUser, string>(getUserLoader, {\n cacheKeyFn(key) {\n return `${key.tenant}:${key.id}`;\n }\n });\n loaders.set(\"getUser\", userLoader);\n return userLoader;\n },\n\n clearLoadersCache(ids: GetUserLoaderKey[]) {\n for (const id of ids) {\n this.getUser.clear(id);\n }\n },\n\n async updateDataLoaderUserCache(id: GetUserLoaderKey, data: Partial<AdminUser>) {\n const user = await this.getUser.load(id);\n this.getUser.clear(id).prime(id, Object.assign({}, user, data));\n }\n };\n};\n"],"names":["createUserLoaders","storageOperations","loaders","Map","getUserLoader","ids","byTenant","acc","item","results","Promise","Object","tenant","res","flatten","id","user","err","WebinyError","userLoader","DataLoader","key","data"],"mappings":";;;AAgBO,MAAMA,oBAAoB,CAAC,EAAEC,iBAAiB,EAAU;IAC3D,MAAMC,UAAU,IAAIC;IAEpB,eAAeC,cAAcC,GAAgC;QACzD,IAAIA,AAAe,MAAfA,IAAI,MAAM,EACV,OAAO,EAAE;QAIb,MAAMC,WAAWD,IAAI,MAAM,CACvB,CAACE,KAAKC;YACFD,GAAG,CAACC,KAAK,MAAM,CAAC,GAAG;mBAAKD,GAAG,CAACC,KAAK,MAAM,CAAC,IAAI,EAAE;gBAAGA,KAAK,EAAE;aAAC;YACzD,OAAOD;QACX,GACA,CAAC;QAGL,IAAI;YACA,MAAME,UAAU,MAAMC,QAAQ,GAAG,CAC7BC,OAAO,IAAI,CAACL,UAAU,GAAG,CAACM,CAAAA,SACfX,kBAAkB,SAAS,CAAC;oBAC/B,OAAO;wBACHW;wBACA,OAAON,QAAQ,CAACM,OAAO;oBAC3B;gBACJ,KAEN,IAAI,CAACC,CAAAA,MAAOC,QAAQD;YAEtB,OAAOR,IAAI,GAAG,CAAC,CAAC,EAAEO,MAAM,EAAEG,EAAE,EAAE;gBAC1B,MAAMC,OAAOP,QAAQ,IAAI,CAACD,CAAAA,OAAQA,KAAK,EAAE,KAAKO,MAAMP,KAAK,MAAM,KAAKI;gBAIpE,OAAOI,QAAS;YACpB;QACJ,EAAE,OAAOC,KAAK;YACV,MAAMC,MAAAA,IAAgB,CAACD,KAAK;gBACxB,SAAS;gBACT,MAAM;gBACN,MAAM;oBAAEZ;gBAAI;YAChB;QACJ;IACJ;IAEA,OAAO;QACH,IAAI
|
|
1
|
+
{"version":3,"file":"features/users/shared/loaders.js","sources":["../../../../src/features/users/shared/loaders.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\nimport WebinyError from \"@webiny/error\";\nimport flatten from \"lodash/flatten.js\";\nimport type { AdminUsersStorageOperations } from \"~/types/users.js\";\nimport type { AdminUser } from \"./types.js\";\n\ninterface Config {\n getTenant(): string;\n storageOperations: AdminUsersStorageOperations;\n}\n\ninterface GetUserLoaderKey {\n id: string;\n tenant: string;\n}\n\nexport const createUserLoaders = ({ storageOperations }: Config) => {\n const loaders = new Map<string, DataLoader<any, any>>();\n\n async function getUserLoader(ids: readonly GetUserLoaderKey[]) {\n if (ids.length === 0) {\n return [];\n }\n\n // Group by tenant\n const byTenant = ids.reduce(\n (acc, item) => {\n acc[item.tenant] = [...(acc[item.tenant] || []), item.id];\n return acc;\n },\n {} as Record<string, string[]>\n );\n\n try {\n const results = await Promise.all(\n Object.keys(byTenant).map(tenant => {\n return storageOperations.listUsers({\n where: {\n tenant,\n id_in: byTenant[tenant]\n }\n });\n })\n ).then(res => flatten(res));\n\n return ids.map(({ tenant, id }) => {\n const user = results.find(item => item.id === id && item.tenant === tenant);\n /**\n * Casting because DataLoader expect error. But we do not.\n */\n return user || (null as unknown as Error);\n });\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not execute batch read in getUser.\",\n code: \"BATCH_READ_ERROR\",\n data: { ids }\n });\n }\n }\n\n return {\n get getUser() {\n let userLoader = loaders.get(\"getUser\");\n if (userLoader) {\n return userLoader;\n }\n userLoader = new DataLoader<GetUserLoaderKey, AdminUser, string>(getUserLoader, {\n cacheKeyFn(key) {\n return `${key.tenant}:${key.id}`;\n }\n });\n loaders.set(\"getUser\", userLoader);\n return userLoader;\n },\n\n clearLoadersCache(ids: GetUserLoaderKey[]) {\n for (const id of ids) {\n this.getUser.clear(id);\n }\n },\n\n async updateDataLoaderUserCache(id: GetUserLoaderKey, data: Partial<AdminUser>) {\n const user = await this.getUser.load(id);\n this.getUser.clear(id).prime(id, Object.assign({}, user, data));\n }\n };\n};\n"],"names":["createUserLoaders","storageOperations","loaders","Map","getUserLoader","ids","byTenant","acc","item","results","Promise","Object","tenant","res","flatten","id","user","err","WebinyError","userLoader","DataLoader","key","data"],"mappings":";;;AAgBO,MAAMA,oBAAoB,CAAC,EAAEC,iBAAiB,EAAU;IAC3D,MAAMC,UAAU,IAAIC;IAEpB,eAAeC,cAAcC,GAAgC;QACzD,IAAIA,AAAe,MAAfA,IAAI,MAAM,EACV,OAAO,EAAE;QAIb,MAAMC,WAAWD,IAAI,MAAM,CACvB,CAACE,KAAKC;YACFD,GAAG,CAACC,KAAK,MAAM,CAAC,GAAG;mBAAKD,GAAG,CAACC,KAAK,MAAM,CAAC,IAAI,EAAE;gBAAGA,KAAK,EAAE;aAAC;YACzD,OAAOD;QACX,GACA,CAAC;QAGL,IAAI;YACA,MAAME,UAAU,MAAMC,QAAQ,GAAG,CAC7BC,OAAO,IAAI,CAACL,UAAU,GAAG,CAACM,CAAAA,SACfX,kBAAkB,SAAS,CAAC;oBAC/B,OAAO;wBACHW;wBACA,OAAON,QAAQ,CAACM,OAAO;oBAC3B;gBACJ,KAEN,IAAI,CAACC,CAAAA,MAAOC,QAAQD;YAEtB,OAAOR,IAAI,GAAG,CAAC,CAAC,EAAEO,MAAM,EAAEG,EAAE,EAAE;gBAC1B,MAAMC,OAAOP,QAAQ,IAAI,CAACD,CAAAA,OAAQA,KAAK,EAAE,KAAKO,MAAMP,KAAK,MAAM,KAAKI;gBAIpE,OAAOI,QAAS;YACpB;QACJ,EAAE,OAAOC,KAAK;YACV,MAAMC,MAAAA,IAAgB,CAACD,KAAK;gBACxB,SAAS;gBACT,MAAM;gBACN,MAAM;oBAAEZ;gBAAI;YAChB;QACJ;IACJ;IAEA,OAAO;QACH,IAAI;YACA,IAAIc,aAAajB,QAAQ,GAAG,CAAC;YAC7B,IAAIiB,YACA,OAAOA;YAEXA,aAAa,IAAIC,WAAgDhB,eAAe;gBAC5E,YAAWiB,GAAG;oBACV,OAAO,GAAGA,IAAI,MAAM,CAAC,CAAC,EAAEA,IAAI,EAAE,EAAE;gBACpC;YACJ;YACAnB,QAAQ,GAAG,CAAC,WAAWiB;YACvB,OAAOA;QACX;QAEA,mBAAkBd,GAAuB;YACrC,KAAK,MAAMU,MAAMV,IACb,IAAI,CAAC,OAAO,CAAC,KAAK,CAACU;QAE3B;QAEA,MAAM,2BAA0BA,EAAoB,EAAEO,IAAwB;YAC1E,MAAMN,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAACD;YACrC,IAAI,CAAC,OAAO,CAAC,KAAK,CAACA,IAAI,KAAK,CAACA,IAAIJ,OAAO,MAAM,CAAC,CAAC,GAAGK,MAAMM;QAC7D;IACJ;AACJ"}
|
|
@@ -27,10 +27,12 @@ export type GetUserInput = {
|
|
|
27
27
|
id?: never;
|
|
28
28
|
email: string;
|
|
29
29
|
};
|
|
30
|
+
export interface ListUsersWhere {
|
|
31
|
+
id_in?: string[];
|
|
32
|
+
teams_in?: string[];
|
|
33
|
+
}
|
|
30
34
|
export interface ListUsersInput {
|
|
31
|
-
where?:
|
|
32
|
-
id_in?: string[];
|
|
33
|
-
};
|
|
35
|
+
where?: ListUsersWhere;
|
|
34
36
|
sort?: string[];
|
|
35
37
|
}
|
|
36
38
|
export interface StorageOperationsGetUserParams {
|
|
@@ -40,10 +42,10 @@ export interface StorageOperationsGetUserParams {
|
|
|
40
42
|
email?: string;
|
|
41
43
|
};
|
|
42
44
|
}
|
|
45
|
+
export interface StorageOperationsListUsersWhere extends ListUsersWhere {
|
|
46
|
+
tenant: string;
|
|
47
|
+
}
|
|
43
48
|
export interface StorageOperationsListUsersParams {
|
|
44
|
-
where:
|
|
45
|
-
tenant: string;
|
|
46
|
-
id_in?: string[];
|
|
47
|
-
};
|
|
49
|
+
where: StorageOperationsListUsersWhere;
|
|
48
50
|
sort?: string[];
|
|
49
51
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-core",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
3
|
+
"version": "0.0.0-unstable.9609e4e0c9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,38 +14,38 @@
|
|
|
14
14
|
"./*": "./*"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@ai-sdk/anthropic": "4.0.
|
|
18
|
-
"@ai-sdk/google": "4.0.
|
|
19
|
-
"@ai-sdk/openai": "4.0.
|
|
17
|
+
"@ai-sdk/anthropic": "4.0.92",
|
|
18
|
+
"@ai-sdk/google": "4.0.108",
|
|
19
|
+
"@ai-sdk/openai": "4.0.105",
|
|
20
20
|
"@openrouter/ai-sdk-provider": "3.1.0",
|
|
21
|
-
"@webiny/api": "0.0.0-unstable.
|
|
22
|
-
"@webiny/api-graphql": "0.0.0-unstable.
|
|
21
|
+
"@webiny/api": "0.0.0-unstable.9609e4e0c9",
|
|
22
|
+
"@webiny/api-graphql": "0.0.0-unstable.9609e4e0c9",
|
|
23
23
|
"@webiny/di": "2.0.0",
|
|
24
|
-
"@webiny/error": "0.0.0-unstable.
|
|
25
|
-
"@webiny/event-handler-core": "0.0.0-unstable.
|
|
26
|
-
"@webiny/feature": "0.0.0-unstable.
|
|
27
|
-
"@webiny/feature-flags": "0.0.0-unstable.
|
|
28
|
-
"@webiny/handler": "0.0.0-unstable.
|
|
29
|
-
"@webiny/utils": "0.0.0-unstable.
|
|
30
|
-
"@webiny/wcp": "0.0.0-unstable.
|
|
31
|
-
"ai": "7.0.
|
|
24
|
+
"@webiny/error": "0.0.0-unstable.9609e4e0c9",
|
|
25
|
+
"@webiny/event-handler-core": "0.0.0-unstable.9609e4e0c9",
|
|
26
|
+
"@webiny/feature": "0.0.0-unstable.9609e4e0c9",
|
|
27
|
+
"@webiny/feature-flags": "0.0.0-unstable.9609e4e0c9",
|
|
28
|
+
"@webiny/handler": "0.0.0-unstable.9609e4e0c9",
|
|
29
|
+
"@webiny/utils": "0.0.0-unstable.9609e4e0c9",
|
|
30
|
+
"@webiny/wcp": "0.0.0-unstable.9609e4e0c9",
|
|
31
|
+
"ai": "7.0.157",
|
|
32
32
|
"dataloader": "2.2.3",
|
|
33
33
|
"graphql": "16.14.2",
|
|
34
|
-
"jose": "6.2.
|
|
34
|
+
"jose": "6.2.14",
|
|
35
35
|
"jsonwebtoken": "9.0.3",
|
|
36
36
|
"lodash": "4.18.1",
|
|
37
|
-
"minimatch": "
|
|
38
|
-
"pino": "10.
|
|
37
|
+
"minimatch": "11.0.3",
|
|
38
|
+
"pino": "10.4.0",
|
|
39
39
|
"pino-lambda": "4.4.1",
|
|
40
40
|
"slugify": "1.6.9",
|
|
41
|
-
"zod": "4.
|
|
41
|
+
"zod": "4.6.7"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@types/jsonwebtoken": "9.0.10",
|
|
45
|
-
"@webiny/build-tools": "0.0.0-unstable.
|
|
45
|
+
"@webiny/build-tools": "0.0.0-unstable.9609e4e0c9",
|
|
46
46
|
"rimraf": "6.1.3",
|
|
47
47
|
"typescript": "7.0.2",
|
|
48
|
-
"vitest": "
|
|
48
|
+
"vitest": "5.0.5"
|
|
49
49
|
},
|
|
50
50
|
"publishConfig": {
|
|
51
51
|
"access": "public"
|
package/types/users.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ListUsersWhere } from "../features/users/shared/types.js";
|
|
1
2
|
export interface CreatedBy {
|
|
2
3
|
id: string;
|
|
3
4
|
displayName: string | null;
|
|
@@ -35,9 +36,7 @@ export interface GetUserParams {
|
|
|
35
36
|
};
|
|
36
37
|
}
|
|
37
38
|
export interface ListUsersParams {
|
|
38
|
-
where?:
|
|
39
|
-
id_in?: string[];
|
|
40
|
-
};
|
|
39
|
+
where?: ListUsersWhere;
|
|
41
40
|
sort?: string[];
|
|
42
41
|
}
|
|
43
42
|
export interface StorageOperationsListUsersParams extends ListUsersParams {
|