@digitraffic/common 2025.7.30-2 → 2025.8.13-1

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.
@@ -14,8 +14,13 @@ export declare const PUBLIC_REST_API_CORS_CONFIG: {
14
14
  export declare class DigitrafficRestApi extends RestApi {
15
15
  readonly apiKeyIds: string[];
16
16
  readonly enableDocumentation: boolean;
17
+ private readonly _stack;
17
18
  constructor(stack: DigitrafficStack, apiId: string, apiName: string, allowFromIpAddresses?: string[] | undefined, config?: Partial<RestApiProps>);
18
19
  hostname(): string;
20
+ /** Export end point and api key to Parameter store */
21
+ exportEndpoint(): void;
22
+ /** Export end point and given api key to Parameter store */
23
+ exportEndpoint(apiKeyId: string): void;
19
24
  createUsagePlan(apiKeyId: string, apiKeyName: string): string;
20
25
  createUsagePlanV2(apiName: string, apiKey?: string): string;
21
26
  addJsonModel(modelName: string, schema: JsonSchema): ModelWithReference;
@@ -4,6 +4,7 @@ import { getModelReference } from "../../../utils/api-model.js";
4
4
  import { MediaType } from "../../types/mediatypes.js";
5
5
  import { createDefaultUsagePlan, createUsagePlan } from "../usage-plans.js";
6
6
  import { set } from "lodash-es";
7
+ import { StringParameter } from "aws-cdk-lib/aws-ssm";
7
8
  export const PUBLIC_REST_API_CORS_CONFIG = {
8
9
  defaultCorsPreflightOptions: {
9
10
  allowOrigins: Cors.ALL_ORIGINS,
@@ -21,6 +22,7 @@ export const PUBLIC_REST_API_CORS_CONFIG = {
21
22
  export class DigitrafficRestApi extends RestApi {
22
23
  apiKeyIds;
23
24
  enableDocumentation;
25
+ _stack;
24
26
  constructor(stack, apiId, apiName, allowFromIpAddresses, config) {
25
27
  const policyDocument = allowFromIpAddresses === null || allowFromIpAddresses === undefined
26
28
  ? createDefaultPolicyDocument()
@@ -38,6 +40,7 @@ export class DigitrafficRestApi extends RestApi {
38
40
  ...config,
39
41
  };
40
42
  super(stack, apiId, apiConfig);
43
+ this._stack = stack;
41
44
  this.apiKeyIds = [];
42
45
  this.enableDocumentation =
43
46
  stack.configuration.stackFeatures?.enableDocumentation ?? true;
@@ -46,6 +49,26 @@ export class DigitrafficRestApi extends RestApi {
46
49
  hostname() {
47
50
  return `${this.restApiId}.execute-api.${this.stack.region}.amazonaws.com`;
48
51
  }
52
+ exportEndpoint(apiKeyId) {
53
+ const firstKey = this.apiKeyIds[0];
54
+ if (!apiKeyId) {
55
+ if (this.apiKeyIds.length > 1) {
56
+ throw new Error("Multiple apikeys, configure which to export");
57
+ }
58
+ if (!firstKey) {
59
+ throw new Error("No apikeys to export");
60
+ }
61
+ apiKeyId = firstKey;
62
+ }
63
+ new StringParameter(this._stack, "export.endpoint", {
64
+ parameterName: `/digitraffic/${this._stack.configuration.shortName}/endpointUrl`,
65
+ stringValue: this.url,
66
+ });
67
+ new StringParameter(this._stack, "export.apiKeyId", {
68
+ parameterName: `/digitraffic/${this._stack.configuration.shortName}/apiKeyId`,
69
+ stringValue: apiKeyId,
70
+ });
71
+ }
49
72
  createUsagePlan(apiKeyId, apiKeyName) {
50
73
  const newKeyId = createUsagePlan(this, apiKeyId, apiKeyName).keyId;
51
74
  this.apiKeyIds.push(newKeyId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitraffic/common",
3
- "version": "2025.7.30-2",
3
+ "version": "2025.8.13-1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "repository": {