@griffin-app/griffin-executor 0.1.3 → 0.1.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.
@@ -10,7 +10,11 @@ export declare class HubSecretProvider implements SecretProvider {
10
10
  readonly name = "hub";
11
11
  private readonly sdk;
12
12
  private readonly environment;
13
- constructor(sdk: GriffinHubSdk, environment: string);
14
- resolve(ref: string, _options?: SecretResolveOptions): Promise<string>;
13
+ private readonly organizationId;
14
+ private readonly cache?;
15
+ private readonly cacheExpires?;
16
+ private readonly ttlMs;
17
+ constructor(sdk: GriffinHubSdk, environment: string, organizationId: string, cache?: Map<string, string>, ttlMs?: number);
18
+ resolve(ref: string, options?: SecretResolveOptions): Promise<string>;
15
19
  }
16
20
  //# sourceMappingURL=hub.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hub.d.ts","sourceRoot":"","sources":["../../../src/secrets/providers/hub.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,KAAK,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAGxE,qBAAa,iBAAkB,YAAW,cAAc;IACtD,QAAQ,CAAC,IAAI,SAAS;IACtB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAgB;IACpC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;gBAEzB,GAAG,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM;IAK7C,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,MAAM,CAAC;CAc7E"}
1
+ {"version":3,"file":"hub.d.ts","sourceRoot":"","sources":["../../../src/secrets/providers/hub.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,KAAK,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAQxE,qBAAa,iBAAkB,YAAW,cAAc;IACtD,QAAQ,CAAC,IAAI,SAAS;IACtB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAgB;IACpC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAsB;IAC7C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAsB;IACpD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;gBAG7B,GAAG,EAAE,aAAa,EAClB,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,MAAM,EACtB,KAAK,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAC3B,KAAK,CAAC,EAAE,MAAM;IAYV,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,MAAM,CAAC;CAsC5E"}
@@ -5,22 +5,61 @@
5
5
  * The hub is the sole gateway for AWS Secrets Manager — no credentials leave the hub.
6
6
  */
7
7
  import { SecretResolutionError } from "../types.js";
8
+ function cacheKey(ref, options) {
9
+ if (!options?.version && !options?.field)
10
+ return ref;
11
+ return `${ref}\0${options.version ?? ""}\0${options.field ?? ""}`;
12
+ }
8
13
  export class HubSecretProvider {
9
14
  name = "hub";
10
15
  sdk;
11
16
  environment;
12
- constructor(sdk, environment) {
17
+ organizationId;
18
+ cache;
19
+ cacheExpires;
20
+ ttlMs;
21
+ constructor(sdk, environment, organizationId, cache, ttlMs) {
13
22
  this.sdk = sdk;
23
+ this.organizationId = organizationId;
14
24
  this.environment = environment;
25
+ this.cache = cache;
26
+ this.ttlMs = ttlMs ?? 0;
27
+ if (this.cache != null && this.ttlMs > 0) {
28
+ this.cacheExpires = new Map();
29
+ }
15
30
  }
16
- async resolve(ref, _options) {
31
+ async resolve(ref, options) {
32
+ const key = cacheKey(ref, options);
33
+ if (this.cache != null) {
34
+ const expiresAt = this.cacheExpires?.get(key);
35
+ const now = Date.now();
36
+ if (expiresAt == null || now < expiresAt) {
37
+ const cached = this.cache.get(key);
38
+ if (cached !== undefined)
39
+ return cached;
40
+ }
41
+ else {
42
+ this.cache.delete(key);
43
+ this.cacheExpires?.delete(key);
44
+ }
45
+ }
17
46
  const response = await this.sdk.postSecretsResolve({
18
- body: { name: ref, environment: this.environment },
47
+ body: {
48
+ name: ref,
49
+ environment: this.environment,
50
+ organizationId: this.organizationId,
51
+ },
19
52
  });
20
53
  const value = response.data?.data?.value;
21
54
  if (value === undefined) {
22
55
  throw new SecretResolutionError(`Secret "${ref}" not found for environment "${this.environment}"`, { ref });
23
56
  }
57
+ if (this.cache != null) {
58
+ this.cache.set(key, value);
59
+ if (this.cacheExpires != null && this.ttlMs > 0) {
60
+ this.cacheExpires.set(key, Date.now() + this.ttlMs);
61
+ }
62
+ }
24
63
  return value;
25
64
  }
26
65
  }
@@ -1 +1 @@
1
- {"version":3,"file":"hub.js","sourceRoot":"","sources":["../../../src/secrets/providers/hub.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEpD,MAAM,OAAO,iBAAiB;IACnB,IAAI,GAAG,KAAK,CAAC;IACL,GAAG,CAAgB;IACnB,WAAW,CAAS;IAErC,YAAY,GAAkB,EAAE,WAAmB;QACjD,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,GAAW,EAAE,QAA+B;QACxD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,kBAAkB,CAAC;YACjD,IAAI,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE;SACnD,CAAC,CAA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AK,IAAI,IAAI,EAAE,CAAC;YACvB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YAC3B,IAAI,IAAI,CAAC,YAAY,IAAI,IAAI,IAAI,IAAI,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC;gBAChD,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;YACtD,CAAC;QACH,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@griffin-app/griffin-executor",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Executor for griffin JSON test monitors",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -22,7 +22,7 @@
22
22
  "license": "MIT",
23
23
  "dependencies": {
24
24
  "@aws-sdk/client-kinesis": "^3.975.0",
25
- "@griffin-app/griffin-hub-sdk": "1.0.27",
25
+ "@griffin-app/griffin-hub-sdk": "1.0.28",
26
26
  "@griffin-app/griffin-core": "0.2.2",
27
27
  "axios": "^1.13.2",
28
28
  "ts-edge": "^1.0.4",
@@ -9,19 +9,57 @@ import type { GriffinHubSdk } from "@griffin-app/griffin-hub-sdk";
9
9
  import type { SecretProvider, SecretResolveOptions } from "../types.js";
10
10
  import { SecretResolutionError } from "../types.js";
11
11
 
12
+ function cacheKey(ref: string, options?: SecretResolveOptions): string {
13
+ if (!options?.version && !options?.field) return ref;
14
+ return `${ref}\0${options.version ?? ""}\0${options.field ?? ""}`;
15
+ }
16
+
12
17
  export class HubSecretProvider implements SecretProvider {
13
18
  readonly name = "hub";
14
19
  private readonly sdk: GriffinHubSdk;
15
20
  private readonly environment: string;
21
+ private readonly organizationId: string;
22
+ private readonly cache?: Map<string, string>;
23
+ private readonly cacheExpires?: Map<string, number>;
24
+ private readonly ttlMs: number;
16
25
 
17
- constructor(sdk: GriffinHubSdk, environment: string) {
26
+ constructor(
27
+ sdk: GriffinHubSdk,
28
+ environment: string,
29
+ organizationId: string,
30
+ cache?: Map<string, string>,
31
+ ttlMs?: number,
32
+ ) {
18
33
  this.sdk = sdk;
34
+ this.organizationId = organizationId;
19
35
  this.environment = environment;
36
+ this.cache = cache;
37
+ this.ttlMs = ttlMs ?? 0;
38
+ if (this.cache != null && this.ttlMs > 0) {
39
+ this.cacheExpires = new Map();
40
+ }
20
41
  }
21
42
 
22
- async resolve(ref: string, _options?: SecretResolveOptions): Promise<string> {
43
+ async resolve(ref: string, options?: SecretResolveOptions): Promise<string> {
44
+ const key = cacheKey(ref, options);
45
+ if (this.cache != null) {
46
+ const expiresAt = this.cacheExpires?.get(key);
47
+ const now = Date.now();
48
+ if (expiresAt == null || now < expiresAt) {
49
+ const cached = this.cache.get(key);
50
+ if (cached !== undefined) return cached;
51
+ } else {
52
+ this.cache.delete(key);
53
+ this.cacheExpires?.delete(key);
54
+ }
55
+ }
56
+
23
57
  const response = await this.sdk.postSecretsResolve({
24
- body: { name: ref, environment: this.environment },
58
+ body: {
59
+ name: ref,
60
+ environment: this.environment,
61
+ organizationId: this.organizationId,
62
+ },
25
63
  });
26
64
 
27
65
  const value = response.data?.data?.value;
@@ -31,6 +69,13 @@ export class HubSecretProvider implements SecretProvider {
31
69
  { ref },
32
70
  );
33
71
  }
72
+
73
+ if (this.cache != null) {
74
+ this.cache.set(key, value);
75
+ if (this.cacheExpires != null && this.ttlMs > 0) {
76
+ this.cacheExpires.set(key, Date.now() + this.ttlMs);
77
+ }
78
+ }
34
79
  return value;
35
80
  }
36
81
  }