@pikku/azure-functions 0.12.4 → 0.12.5

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/CHANGELOG.md CHANGED
@@ -1,3 +1,47 @@
1
+ ## 0.12.5
2
+
3
+ ### Patch Changes
4
+
5
+ - 78b29f0: `SecretService` now returns a `SecretValue<T>` rather than the bare value, so a
6
+ vault secret cannot reach a sink by accident.
7
+
8
+ `SecretValue` is nominally typed, which means it is not assignable to `string`
9
+ (or to any other concretely-typed field). Every sink with a real type — a
10
+ database column, an email body, a session payload — rejects it with no lint
11
+ rule involved. The sinks typed `any`, `unknown`, or a free generic — the logger,
12
+ queue payloads, webhook and email inputs, and a function's own output — are
13
+ guarded with `Safe<T>`, which collapses a `SecretValue` found anywhere inside
14
+ `T`, however deeply nested, to `never`.
15
+
16
+ Unwrap deliberately at the point the secret reaches the wire:
17
+
18
+ ```ts
19
+ const secret = await secrets.getSecret('BETTER_AUTH_SECRET')
20
+ betterAuth({ secret: secret.reveal() })
21
+ ```
22
+
23
+ Two behaviours cover what types cannot see. Structured serialization redacts —
24
+ `JSON.stringify` and node's inspect both yield `[secret]`, so an audit or log
25
+ write stays honest without crashing the request. String coercion throws
26
+ `SecretCoercionError`, because a template literal is always a leak.
27
+
28
+ `AuditLog.write` is guarded the same way as the logger, since an audit event
29
+ carries `input` and `metadata` as `unknown` and nominality alone cannot stop a
30
+ secret landing in one.
31
+
32
+ `.reveal()` is the deliberate escape hatch, and what it hands back is an
33
+ ordinary string as far as every sink signature is concerned. **PKU953** closes
34
+ that gap: under `pikku all --security` the inspector reports a revealed secret
35
+ that flows into a logger, an audit, a queue, an email or a webhook — `console` included.
36
+
37
+ This also fixed a real one: `remote-addon-auth.ts` called `String(token)` on an
38
+ `unknown` and wrote the result straight into an `Authorization` header.
39
+
40
+ - Updated dependencies [62ea4cc]
41
+ - Updated dependencies [9dddff8]
42
+ - Updated dependencies [78b29f0]
43
+ - @pikku/core@0.12.76
44
+
1
45
  ## 0.12.4
2
46
 
3
47
  ### Patch Changes
@@ -1,12 +1,23 @@
1
1
  import type { InvocationContext } from '@azure/functions';
2
2
  import type { Logger, LogLevel } from '@pikku/core/services';
3
+ import type { Safe } from '@pikku/core';
3
4
  export declare class AzInvocationLogger implements Logger {
4
5
  private context;
5
6
  constructor(context: InvocationContext);
6
- info(messageOrObj: string | Record<string, any>): void;
7
- warn(messageOrObj: string | Record<string, any>): void;
8
- error(messageOrObj: string | Record<string, any> | Error): void;
9
- debug(message: string): void;
10
- trace(message: string): void;
7
+ info<M extends string | Record<string, any>, A extends unknown[]>(messageOrObj: Safe<M>, ...meta: {
8
+ [K in keyof A]: Safe<A[K]>;
9
+ }): void;
10
+ warn<M extends string | Record<string, any>, A extends unknown[]>(messageOrObj: Safe<M>, ...meta: {
11
+ [K in keyof A]: Safe<A[K]>;
12
+ }): void;
13
+ error<M extends string | Record<string, any> | Error, A extends unknown[]>(messageOrObj: Safe<M>, ...meta: {
14
+ [K in keyof A]: Safe<A[K]>;
15
+ }): void;
16
+ debug<A extends unknown[]>(message: string, ...meta: {
17
+ [K in keyof A]: Safe<A[K]>;
18
+ }): void;
19
+ trace<A extends unknown[]>(message: string, ...meta: {
20
+ [K in keyof A]: Safe<A[K]>;
21
+ }): void;
11
22
  setLevel(level: LogLevel): void;
12
23
  }
@@ -3,20 +3,20 @@ export class AzInvocationLogger {
3
3
  constructor(context) {
4
4
  this.context = context;
5
5
  }
6
- info(messageOrObj) {
7
- this.context.info(messageOrObj);
6
+ info(messageOrObj, ...meta) {
7
+ this.context.info(messageOrObj, ...meta);
8
8
  }
9
- warn(messageOrObj) {
10
- this.context.warn(messageOrObj);
9
+ warn(messageOrObj, ...meta) {
10
+ this.context.warn(messageOrObj, ...meta);
11
11
  }
12
- error(messageOrObj) {
13
- this.context.error(messageOrObj);
12
+ error(messageOrObj, ...meta) {
13
+ this.context.error(messageOrObj, ...meta);
14
14
  }
15
- debug(message) {
16
- this.context.debug(message);
15
+ debug(message, ...meta) {
16
+ this.context.debug(message, ...meta);
17
17
  }
18
- trace(message) {
19
- this.context.trace(message);
18
+ trace(message, ...meta) {
19
+ this.context.trace(message, ...meta);
20
20
  }
21
21
  setLevel(level) {
22
22
  }
@@ -1 +1 @@
1
- {"version":3,"file":"pikku-az-functions-logger.js","sourceRoot":"","sources":["../src/pikku-az-functions-logger.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,kBAAkB;IAGT;IAApB,YAAoB,OAA0B;QAA1B,YAAO,GAAP,OAAO,CAAmB;IAAG,CAAC;IAE3C,IAAI,CAAC,YAA0C;QACpD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;IACjC,CAAC;IAEM,IAAI,CAAC,YAA0C;QACpD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;IACjC,CAAC;IAEM,KAAK,CAAC,YAAkD;QAC7D,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,CAAA;IAClC,CAAC;IAEM,KAAK,CAAC,OAAe;QAC1B,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IAC7B,CAAC;IAEM,KAAK,CAAC,OAAe;QAC1B,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IAC7B,CAAC;IAEM,QAAQ,CAAC,KAAe;IAE/B,CAAC;CACF"}
1
+ {"version":3,"file":"pikku-az-functions-logger.js","sourceRoot":"","sources":["../src/pikku-az-functions-logger.ts"],"names":[],"mappings":"AAIA,MAAM,OAAO,kBAAkB;IAGT;IAApB,YAAoB,OAA0B;QAA1B,YAAO,GAAP,OAAO,CAAmB;IAAG,CAAC;IAE3C,IAAI,CACT,YAAqB,EACrB,GAAG,IAAoC;QAEvC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,YAAmB,EAAE,GAAG,IAAI,CAAC,CAAA;IACjD,CAAC;IAEM,IAAI,CACT,YAAqB,EACrB,GAAG,IAAoC;QAEvC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,YAAmB,EAAE,GAAG,IAAI,CAAC,CAAA;IACjD,CAAC;IAEM,KAAK,CAGV,YAAqB,EAAE,GAAG,IAAoC;QAC9D,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,YAAmB,EAAE,GAAG,IAAI,CAAC,CAAA;IAClD,CAAC;IAEM,KAAK,CACV,OAAe,EACf,GAAG,IAAoC;QAEvC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAA;IACtC,CAAC;IAEM,KAAK,CACV,OAAe,EACf,GAAG,IAAoC;QAEvC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAA;IACtC,CAAC;IAEM,QAAQ,CAAC,KAAe;IAE/B,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pikku/azure-functions",
3
- "version": "0.12.4",
3
+ "version": "0.12.5",
4
4
  "description": "Azure Functions runtime for Pikku — HTTP, timer and storage-queue handlers",
5
5
  "license": "MIT",
6
6
  "author": "yasser.fadl@gmail.com",
@@ -8,7 +8,7 @@
8
8
  "main": "dist/index.js",
9
9
  "type": "module",
10
10
  "scripts": {
11
- "tsc": "tsc",
11
+ "tsc": "tsc && tsc -p tsconfig.type-tests.json",
12
12
  "ncu": "npx npm-check-updates",
13
13
  "build": "tsc -b",
14
14
  "release": "npm run build && npm test",
@@ -18,7 +18,7 @@
18
18
  "prepublishOnly": "yarn build"
19
19
  },
20
20
  "peerDependencies": {
21
- "@pikku/core": "^0.12.74"
21
+ "@pikku/core": "^0.12.76"
22
22
  },
23
23
  "devDependencies": {
24
24
  "typescript": "^6.0.3"
@@ -1,29 +1,45 @@
1
1
  import type { InvocationContext } from '@azure/functions'
2
2
  import type { Logger, LogLevel } from '@pikku/core/services'
3
+ import type { Safe } from '@pikku/core'
3
4
 
4
5
  export class AzInvocationLogger implements Logger {
5
6
  // private logLevel: LogLevel = LogLevel.info
6
7
 
7
8
  constructor(private context: InvocationContext) {}
8
9
 
9
- public info(messageOrObj: string | Record<string, any>): void {
10
- this.context.info(messageOrObj)
10
+ public info<M extends string | Record<string, any>, A extends unknown[]>(
11
+ messageOrObj: Safe<M>,
12
+ ...meta: { [K in keyof A]: Safe<A[K]> }
13
+ ): void {
14
+ this.context.info(messageOrObj as any, ...meta)
11
15
  }
12
16
 
13
- public warn(messageOrObj: string | Record<string, any>): void {
14
- this.context.warn(messageOrObj)
17
+ public warn<M extends string | Record<string, any>, A extends unknown[]>(
18
+ messageOrObj: Safe<M>,
19
+ ...meta: { [K in keyof A]: Safe<A[K]> }
20
+ ): void {
21
+ this.context.warn(messageOrObj as any, ...meta)
15
22
  }
16
23
 
17
- public error(messageOrObj: string | Record<string, any> | Error): void {
18
- this.context.error(messageOrObj)
24
+ public error<
25
+ M extends string | Record<string, any> | Error,
26
+ A extends unknown[],
27
+ >(messageOrObj: Safe<M>, ...meta: { [K in keyof A]: Safe<A[K]> }): void {
28
+ this.context.error(messageOrObj as any, ...meta)
19
29
  }
20
30
 
21
- public debug(message: string): void {
22
- this.context.debug(message)
31
+ public debug<A extends unknown[]>(
32
+ message: string,
33
+ ...meta: { [K in keyof A]: Safe<A[K]> }
34
+ ): void {
35
+ this.context.debug(message, ...meta)
23
36
  }
24
37
 
25
- public trace(message: string): void {
26
- this.context.trace(message)
38
+ public trace<A extends unknown[]>(
39
+ message: string,
40
+ ...meta: { [K in keyof A]: Safe<A[K]> }
41
+ ): void {
42
+ this.context.trace(message, ...meta)
27
43
  }
28
44
 
29
45
  public setLevel(level: LogLevel): void {
@@ -0,0 +1,18 @@
1
+ import { createSecretValue } from '@pikku/core'
2
+ import type { AzInvocationLogger } from './pikku-az-functions-logger.js'
3
+
4
+ // A concrete logger must not be a way around the `Logger` guard.
5
+ const _assertions = (logger: AzInvocationLogger) => {
6
+ const secret = createSecretValue('sk-live-DEADBEEF')
7
+
8
+ // @ts-expect-error a secret cannot be logged
9
+ logger.info(secret)
10
+ // @ts-expect-error nor nested in the message
11
+ logger.info({ token: secret })
12
+ // @ts-expect-error nor in the metadata
13
+ logger.warn('using', { token: secret })
14
+
15
+ logger.info('fine')
16
+ logger.info({ count: 1 })
17
+ }
18
+ void _assertions
@@ -0,0 +1,12 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "noEmit": true,
5
+ "composite": false,
6
+ "declaration": false,
7
+ "declarationMap": false
8
+ },
9
+ "files": [
10
+ "src/pikku-az-functions-logger.type.test.ts"
11
+ ]
12
+ }