@guildeducationinc/benefits-admin-policy-sdk 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +78 -0
- package/dist/adapters/index.d.ts +3 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +6 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/s3-adapter.d.ts +41 -0
- package/dist/adapters/s3-adapter.d.ts.map +1 -0
- package/dist/adapters/s3-adapter.js +96 -0
- package/dist/adapters/s3-adapter.js.map +1 -0
- package/dist/clients/policy-client.d.ts +141 -0
- package/dist/clients/policy-client.d.ts.map +1 -0
- package/dist/clients/policy-client.js +427 -0
- package/dist/clients/policy-client.js.map +1 -0
- package/dist/constants.d.ts +18 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +21 -0
- package/dist/constants.js.map +1 -0
- package/dist/errors/index.d.ts +38 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +75 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/guildeducationinc-benefits-admin-policy-sdk-1.1.0.tgz +0 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/models/index.d.ts +8 -0
- package/dist/models/index.d.ts.map +1 -0
- package/dist/models/index.js +7 -0
- package/dist/models/index.js.map +1 -0
- package/dist/models/policy-override.d.ts +528 -0
- package/dist/models/policy-override.d.ts.map +1 -0
- package/dist/models/policy-override.js +7 -0
- package/dist/models/policy-override.js.map +1 -0
- package/dist/models/policy-version.d.ts +948 -0
- package/dist/models/policy-version.d.ts.map +1 -0
- package/dist/models/policy-version.js +7 -0
- package/dist/models/policy-version.js.map +1 -0
- package/dist/models/policy.d.ts +34 -0
- package/dist/models/policy.d.ts.map +1 -0
- package/dist/models/policy.js +7 -0
- package/dist/models/policy.js.map +1 -0
- package/dist/schemas/index.d.ts +23 -0
- package/dist/schemas/index.d.ts.map +1 -0
- package/dist/schemas/index.js +31 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/schemas/policy-override.schema.json +627 -0
- package/dist/schemas/policy-version.schema.json +1242 -0
- package/dist/schemas/policy.schema.json +31 -0
- package/package.json +64 -0
package/README.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# Benefits Admin Policy SDK (TypeScript)
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for interacting with the Benefits Admin Policy service.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Retrieve policy versions from S3
|
|
8
|
+
- Type-safe policy models with hand-rolled TypeScript types
|
|
9
|
+
- JSON Schema exports for runtime validation
|
|
10
|
+
- Support for policy requirements, benefits, and exceptions
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
yarn install
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import { PolicyClient, PolicyVersion } from '@guildeducationinc/benefits-admin-policy-sdk';
|
|
22
|
+
|
|
23
|
+
// Create a client instance
|
|
24
|
+
const client = new PolicyClient();
|
|
25
|
+
|
|
26
|
+
// Retrieve a policy version by URI
|
|
27
|
+
const policyVersion: PolicyVersion = await client.retrievePolicyVersion('policies/policy123/version456.json');
|
|
28
|
+
|
|
29
|
+
// Access typed policy data
|
|
30
|
+
const { name, populations, benefits } = policyVersion;
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Runtime Validation with JSON Schema
|
|
34
|
+
|
|
35
|
+
The SDK exports JSON schemas that can be used for runtime validation:
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
import { policySchema, policyVersionSchema, policyOverrideSchema } from '@guildeducationinc/benefits-admin-policy-sdk';
|
|
39
|
+
import Ajv from 'ajv';
|
|
40
|
+
|
|
41
|
+
const ajv = new Ajv();
|
|
42
|
+
const validatePolicyVersion = ajv.compile(policyVersionSchema);
|
|
43
|
+
|
|
44
|
+
if (!validatePolicyVersion(data)) {
|
|
45
|
+
throw new Error('Invalid policy version data');
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Available schemas:
|
|
50
|
+
|
|
51
|
+
- `policySchema` - Validates Policy documents
|
|
52
|
+
- `policyVersionSchema` - Validates PolicyVersion documents
|
|
53
|
+
- `policyOverrideSchema` - Validates PolicyOverride documents
|
|
54
|
+
|
|
55
|
+
## Development
|
|
56
|
+
|
|
57
|
+
### Setup
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
yarn install
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Run Tests
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
yarn test
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Linting
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
yarn lint # Check for issues
|
|
73
|
+
yarn lint:fix # Auto-fix issues
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Types
|
|
77
|
+
|
|
78
|
+
This SDK uses hand-rolled TypeScript types derived from JSON Schema definitions. The types are located in [src/models/](src/models/) and provide full type safety for policy domain models.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapters/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.S3Adapter = void 0;
|
|
4
|
+
var s3_adapter_1 = require("./s3-adapter");
|
|
5
|
+
Object.defineProperty(exports, "S3Adapter", { enumerable: true, get: function () { return s3_adapter_1.S3Adapter; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/adapters/index.ts"],"names":[],"mappings":";;;AAAA,2CAAyC;AAAhC,uGAAA,SAAS,OAAA"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AWS credentials interface
|
|
3
|
+
*/
|
|
4
|
+
export interface S3Credentials {
|
|
5
|
+
accessKeyId: string;
|
|
6
|
+
secretAccessKey: string;
|
|
7
|
+
sessionToken?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* S3 adapter for policy client operations
|
|
11
|
+
* Provides methods to list and retrieve objects from S3
|
|
12
|
+
*/
|
|
13
|
+
export declare class S3Adapter {
|
|
14
|
+
private bucketName;
|
|
15
|
+
private client;
|
|
16
|
+
constructor(bucketName: string, regionName: string | undefined, credentials: S3Credentials);
|
|
17
|
+
/**
|
|
18
|
+
* List all object keys with the given prefix
|
|
19
|
+
* Returns an async generator that yields keys in lexicographic order
|
|
20
|
+
*/
|
|
21
|
+
listUrisByPrefix(prefix: string): AsyncGenerator<string>;
|
|
22
|
+
/**
|
|
23
|
+
* List all object keys with the given prefix (non-generator version)
|
|
24
|
+
* Returns a promise that resolves to an array of keys
|
|
25
|
+
*/
|
|
26
|
+
listAllUrisByPrefix(prefix: string): Promise<string[]>;
|
|
27
|
+
/**
|
|
28
|
+
* Retrieve an object from S3 by its key
|
|
29
|
+
* Returns the object body as a string, or null if not found
|
|
30
|
+
*/
|
|
31
|
+
retrieveObject(key: string): Promise<string | null>;
|
|
32
|
+
/**
|
|
33
|
+
* Get the bucket name
|
|
34
|
+
*/
|
|
35
|
+
getBucketName(): string;
|
|
36
|
+
/**
|
|
37
|
+
* Convert a readable stream to string
|
|
38
|
+
*/
|
|
39
|
+
private streamToString;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=s3-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s3-adapter.d.ts","sourceRoot":"","sources":["../../src/adapters/s3-adapter.ts"],"names":[],"mappings":"AAOA;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;GAGG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,MAAM,CAAW;gBAGvB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,YAAc,EAChC,WAAW,EAAE,aAAa;IAgB5B;;;OAGG;IACI,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,cAAc,CAAC,MAAM,CAAC;IAgB/D;;;OAGG;IACG,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAQ5D;;;OAGG;IACG,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IA4BzD;;OAEG;IACH,aAAa,IAAI,MAAM;IAIvB;;OAEG;YAEW,cAAc;CAU7B"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.S3Adapter = void 0;
|
|
4
|
+
const client_s3_1 = require("@aws-sdk/client-s3");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
/**
|
|
7
|
+
* S3 adapter for policy client operations
|
|
8
|
+
* Provides methods to list and retrieve objects from S3
|
|
9
|
+
*/
|
|
10
|
+
class S3Adapter {
|
|
11
|
+
constructor(bucketName, regionName = 'us-west-2', credentials) {
|
|
12
|
+
if (!bucketName) {
|
|
13
|
+
throw new Error('Bucket name is required');
|
|
14
|
+
}
|
|
15
|
+
if (!regionName) {
|
|
16
|
+
throw new Error('Region is required');
|
|
17
|
+
}
|
|
18
|
+
this.bucketName = bucketName;
|
|
19
|
+
this.client = new client_s3_1.S3Client({
|
|
20
|
+
region: regionName,
|
|
21
|
+
credentials,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* List all object keys with the given prefix
|
|
26
|
+
* Returns an async generator that yields keys in lexicographic order
|
|
27
|
+
*/
|
|
28
|
+
async *listUrisByPrefix(prefix) {
|
|
29
|
+
const paginator = (0, client_s3_1.paginateListObjectsV2)({ client: this.client, pageSize: constants_1.S3_PAGE_SIZE }, { Bucket: this.bucketName, Prefix: prefix });
|
|
30
|
+
for await (const page of paginator) {
|
|
31
|
+
const contents = page.Contents || [];
|
|
32
|
+
for (const obj of contents) {
|
|
33
|
+
if (obj.Key) {
|
|
34
|
+
yield obj.Key;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* List all object keys with the given prefix (non-generator version)
|
|
41
|
+
* Returns a promise that resolves to an array of keys
|
|
42
|
+
*/
|
|
43
|
+
async listAllUrisByPrefix(prefix) {
|
|
44
|
+
const keys = [];
|
|
45
|
+
for await (const key of this.listUrisByPrefix(prefix)) {
|
|
46
|
+
keys.push(key);
|
|
47
|
+
}
|
|
48
|
+
return keys;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Retrieve an object from S3 by its key
|
|
52
|
+
* Returns the object body as a string, or null if not found
|
|
53
|
+
*/
|
|
54
|
+
async retrieveObject(key) {
|
|
55
|
+
try {
|
|
56
|
+
const response = await this.client.send(new client_s3_1.GetObjectCommand({
|
|
57
|
+
Bucket: this.bucketName,
|
|
58
|
+
Key: key,
|
|
59
|
+
}));
|
|
60
|
+
if (!response.Body) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
// Convert the readable stream to string
|
|
64
|
+
return await this.streamToString(response.Body);
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
// Check for NoSuchKey error
|
|
68
|
+
if (error instanceof Error &&
|
|
69
|
+
'name' in error &&
|
|
70
|
+
error.name === 'NoSuchKey') {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Get the bucket name
|
|
78
|
+
*/
|
|
79
|
+
getBucketName() {
|
|
80
|
+
return this.bucketName;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Convert a readable stream to string
|
|
84
|
+
*/
|
|
85
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
86
|
+
async streamToString(stream) {
|
|
87
|
+
const chunks = [];
|
|
88
|
+
for await (const chunk of stream) {
|
|
89
|
+
chunks.push(chunk);
|
|
90
|
+
}
|
|
91
|
+
const buffer = Buffer.concat(chunks);
|
|
92
|
+
return buffer.toString('utf-8');
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.S3Adapter = S3Adapter;
|
|
96
|
+
//# sourceMappingURL=s3-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s3-adapter.js","sourceRoot":"","sources":["../../src/adapters/s3-adapter.ts"],"names":[],"mappings":";;;AAAA,kDAI4B;AAC5B,4CAA4C;AAW5C;;;GAGG;AACH,MAAa,SAAS;IAIpB,YACE,UAAkB,EAClB,aAAqB,WAAW,EAChC,WAA0B;QAE1B,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;QAC7C,CAAC;QACD,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;QACxC,CAAC;QAED,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,MAAM,GAAG,IAAI,oBAAQ,CAAC;YACzB,MAAM,EAAE,UAAU;YAClB,WAAW;SACZ,CAAC,CAAC;IACL,CAAC;IA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CAAC;QAClD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,4BAA4B;YAC5B,IACE,KAAK,YAAY,KAAK;gBACtB,MAAM,IAAI,KAAK;gBACf,KAAK,CAAC,IAAI,KAAK,WAAW,EAC1B,CAAC;gBACD,OAAO,IAAI,CAAC;YACd,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAED;;OAEG;IACH,aAAa;QACX,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,8DAA8D;IACtD,KAAK,CAAC,cAAc,CAAC,MAAW;QACtC,MAAM,MAAM,GAAiB,EAAE,CAAC;QAEhC,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YACjC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACrB,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACrC,OAAO,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAClC,CAAC;CACF;AA5GD,8BA4GC"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import type { PolicyVersion } from '../models';
|
|
2
|
+
/**
|
|
3
|
+
* Client for retrieving Policy documents from S3 storage.
|
|
4
|
+
*
|
|
5
|
+
* Provides methods to list policies for employers and retrieve policy versions
|
|
6
|
+
* from S3 storage. Automatically handles AWS credential management and S3
|
|
7
|
+
* client configuration with TTL-based caching.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* // Create a client instance
|
|
12
|
+
* const client = new PolicyClient();
|
|
13
|
+
*
|
|
14
|
+
* // List all policies for an employer
|
|
15
|
+
* const policyUris = await client.listPolicies('employer-uuid');
|
|
16
|
+
*
|
|
17
|
+
* // Retrieve a specific policy version by URI
|
|
18
|
+
* const policyVersion = await client.retrievePolicyVersion('path/to/policy.json');
|
|
19
|
+
*
|
|
20
|
+
* // Retrieve the current active policy version
|
|
21
|
+
* const currentPolicy = await client.retrieveCurrentPolicyVersion('policy-uuid');
|
|
22
|
+
*
|
|
23
|
+
* // Retrieve policy version as of a specific date
|
|
24
|
+
* const historicalPolicy = await client.retrieveCurrentPolicyVersion('policy-uuid', '2025-01-15');
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare class PolicyClient {
|
|
28
|
+
private s3Adapter;
|
|
29
|
+
private s3AdapterExpiresAt;
|
|
30
|
+
private bucketName;
|
|
31
|
+
private policyUriPrefix;
|
|
32
|
+
private policyUriPrefixExpiresAt;
|
|
33
|
+
private region;
|
|
34
|
+
constructor();
|
|
35
|
+
/**
|
|
36
|
+
* Get the AWS region
|
|
37
|
+
*/
|
|
38
|
+
getRegion(): string;
|
|
39
|
+
/**
|
|
40
|
+
* List all policy URIs for a given employer.
|
|
41
|
+
*
|
|
42
|
+
* @param employerId - The UUID of the employer to list policies for
|
|
43
|
+
* @returns A list of full S3 URIs for all policies under the given employer
|
|
44
|
+
*/
|
|
45
|
+
listPolicies(employerId: string): Promise<string[]>;
|
|
46
|
+
/**
|
|
47
|
+
* Retrieve a PolicyVersion from S3 using the given URI.
|
|
48
|
+
*
|
|
49
|
+
* @param uri - The S3 URI or resource path for the PolicyVersion. Can be:
|
|
50
|
+
* - Full S3 URI (e.g., "s3://bucket/path/file.json")
|
|
51
|
+
* - Relative resource path (e.g., "path/to/policy.json")
|
|
52
|
+
*
|
|
53
|
+
* @returns The deserialized PolicyVersion object
|
|
54
|
+
*
|
|
55
|
+
* @throws PolicySdkConfigurationError - If the uri format is invalid
|
|
56
|
+
* @throws PolicyVersionNotFoundError - If the PolicyVersion resource is not found
|
|
57
|
+
* @throws PolicyVersionDeserializationError - If the JSON cannot be deserialized
|
|
58
|
+
*/
|
|
59
|
+
retrievePolicyVersion(uri: string): Promise<PolicyVersion>;
|
|
60
|
+
/**
|
|
61
|
+
* Retrieve the most recent active PolicyVersion for a given policy.
|
|
62
|
+
*
|
|
63
|
+
* This function finds the most recently published policy version for the specified date.
|
|
64
|
+
* If no date is provided, it defaults to the current "coverage day" (4am ET - 4am ET).
|
|
65
|
+
* If no policy version exists for the target date, it finds the most recently published
|
|
66
|
+
* version prior to that date.
|
|
67
|
+
*
|
|
68
|
+
* @param policyId - The policy identifier, which can be:
|
|
69
|
+
* - UUID string (e.g., "a1b2c3d4-e5f6-7a8b-9c0d-1e2f3a4b5c6d")
|
|
70
|
+
* - Full S3 URI (e.g., "s3://{bucket}/{dataset}/employers/{employer_id}/policies/{policy_uuid}.json")
|
|
71
|
+
* - Relative resource path (e.g., "{dataset}/employers/{employer_id}/policies/{policy_uuid}.json")
|
|
72
|
+
*
|
|
73
|
+
* @param asOf - Optional date to use when finding the current policy version.
|
|
74
|
+
* Can be a Date object or a date string in 'YYYY-MM-DD' format.
|
|
75
|
+
* Defaults to the current coverage day (4am ET - 4am ET) if not provided.
|
|
76
|
+
*
|
|
77
|
+
* @returns The most recent active PolicyVersion for the specified date
|
|
78
|
+
*
|
|
79
|
+
* @throws PolicyVersionNotFoundError - If no active policy version is found
|
|
80
|
+
* @throws PolicyVersionDeserializationError - If the JSON cannot be deserialized
|
|
81
|
+
* @throws PolicySdkConfigurationError - If the policy_id or as_of format is invalid
|
|
82
|
+
*/
|
|
83
|
+
retrieveCurrentPolicyVersion(policyId: string, asOf?: Date | string | null): Promise<PolicyVersion>;
|
|
84
|
+
/**
|
|
85
|
+
* Get the S3 bucket name based on the STAGE environment variable
|
|
86
|
+
*/
|
|
87
|
+
private getBucketName;
|
|
88
|
+
/**
|
|
89
|
+
* Get the BA consumer role ARN from SSM parameter store
|
|
90
|
+
*/
|
|
91
|
+
private getConsumerRoleArn;
|
|
92
|
+
/**
|
|
93
|
+
* Assume the BA consumer role using STS
|
|
94
|
+
*/
|
|
95
|
+
private assumeRole;
|
|
96
|
+
/**
|
|
97
|
+
* Get or create the S3 adapter with caching
|
|
98
|
+
*/
|
|
99
|
+
private getS3Client;
|
|
100
|
+
/**
|
|
101
|
+
* Get the policy URI prefix from SSM Parameter Store
|
|
102
|
+
*/
|
|
103
|
+
private getPolicyUriPrefix;
|
|
104
|
+
/**
|
|
105
|
+
* Get the current coverage day based on ET timezone.
|
|
106
|
+
*
|
|
107
|
+
* A "coverage day" runs from 4am ET to 4am ET the next calendar day.
|
|
108
|
+
* This prevents timezone-related edge cases where UTC midnight doesn't align
|
|
109
|
+
* with business operations.
|
|
110
|
+
*/
|
|
111
|
+
private getCoverageDay;
|
|
112
|
+
/**
|
|
113
|
+
* Format a date as YYYY-MM-DD string
|
|
114
|
+
*/
|
|
115
|
+
private formatDate;
|
|
116
|
+
/**
|
|
117
|
+
* Parse a date string or Date object into a Date
|
|
118
|
+
*/
|
|
119
|
+
private parseAsOfDate;
|
|
120
|
+
/**
|
|
121
|
+
* Validate and convert a policy version URI to a resource path
|
|
122
|
+
*/
|
|
123
|
+
private validatePolicyVersionUri;
|
|
124
|
+
/**
|
|
125
|
+
* Parse policy_id and extract UUID and optional dataset prefix
|
|
126
|
+
*/
|
|
127
|
+
private parsePolicyId;
|
|
128
|
+
/**
|
|
129
|
+
* Extract dataset prefix and UUID from a resource path
|
|
130
|
+
*/
|
|
131
|
+
private extractDatasetAndUuid;
|
|
132
|
+
/**
|
|
133
|
+
* Filter policy version keys by date, keeping only those on or before target_date
|
|
134
|
+
*/
|
|
135
|
+
private filterPolicyVersionsByDate;
|
|
136
|
+
/**
|
|
137
|
+
* Deserialize JSON string to PolicyVersion
|
|
138
|
+
*/
|
|
139
|
+
private deserializePolicyVersion;
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=policy-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy-client.d.ts","sourceRoot":"","sources":["../../src/clients/policy-client.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE/C;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH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