@dmptool/utils 1.0.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/LICENSE +21 -0
- package/README.md +788 -0
- package/dist/cloudFormation.d.ts +8 -0
- package/dist/cloudFormation.js +54 -0
- package/dist/dynamo.d.ts +105 -0
- package/dist/dynamo.js +651 -0
- package/dist/eventBridge.d.ts +13 -0
- package/dist/eventBridge.js +48 -0
- package/dist/general.d.ts +56 -0
- package/dist/general.js +142 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +27 -0
- package/dist/logger.d.ts +17 -0
- package/dist/logger.js +36 -0
- package/dist/maDMP.d.ts +41 -0
- package/dist/maDMP.js +982 -0
- package/dist/maDMPTypes.d.ts +273 -0
- package/dist/maDMPTypes.js +12 -0
- package/dist/rds.d.ts +11 -0
- package/dist/rds.js +108 -0
- package/dist/s3.d.ts +44 -0
- package/dist/s3.js +98 -0
- package/dist/ssm.d.ts +8 -0
- package/dist/ssm.js +33 -0
- package/package.json +66 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fetch the value for the specified CloudFormation stack export.
|
|
3
|
+
*
|
|
4
|
+
* @param name The name of the CloudFormation stack export to fetch.
|
|
5
|
+
* @returns The value of the CloudFormation stack export, or undefined if the
|
|
6
|
+
* export could not be found.
|
|
7
|
+
*/
|
|
8
|
+
export declare const getExport: (name: string) => Promise<string | undefined>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getExport = void 0;
|
|
4
|
+
const client_cloudformation_1 = require("@aws-sdk/client-cloudformation");
|
|
5
|
+
// If you want to make a CloudFormation stack output available for to this Lambda Layer, you need to
|
|
6
|
+
// ensure that your CloudFormation template "exports" the output variable. Note that you should try
|
|
7
|
+
// to make sure that the "Name" you use for your export is namespaced to make it unique!
|
|
8
|
+
//
|
|
9
|
+
// Outputs:
|
|
10
|
+
// UserPoolArn:
|
|
11
|
+
// Value: !GetAtt UserPool.Arn
|
|
12
|
+
// Export:
|
|
13
|
+
// Name: !Sub 'my-namespace-CognitoUserPoolArn'
|
|
14
|
+
//
|
|
15
|
+
// You would then import the `getExport` function below into your Lambda function and pass in the
|
|
16
|
+
// export name. e.g. `const val = await getExport("my-namespace-CognitoUserPoolArn");`
|
|
17
|
+
const cfClient = new client_cloudformation_1.CloudFormationClient({});
|
|
18
|
+
// Example of a CloudFormation stack export:
|
|
19
|
+
// {
|
|
20
|
+
// ExportingStackId: 'arn:aws:cloudformation:us-west-2:00000000:stack/my-stack-name/unique-id',
|
|
21
|
+
// Name: 'DynamoDBTable1234',
|
|
22
|
+
// Value: 'arn:aws:dynamodb:us-west-2:00000000:table/my-dynamo-table-19RCAN1IAZXQ4'
|
|
23
|
+
// }
|
|
24
|
+
const cfExports = [];
|
|
25
|
+
// Collect all the CloudFormation exported outputs
|
|
26
|
+
const loadExports = async () => {
|
|
27
|
+
let nextToken;
|
|
28
|
+
// if the cfExports have already been collected
|
|
29
|
+
if (!cfExports || !Array.isArray(cfExports) || cfExports.length === 0) {
|
|
30
|
+
do {
|
|
31
|
+
const command = new client_cloudformation_1.ListExportsCommand({ NextToken: nextToken });
|
|
32
|
+
const response = await cfClient.send(command);
|
|
33
|
+
for (const exp of response.Exports) {
|
|
34
|
+
cfExports.push(exp);
|
|
35
|
+
}
|
|
36
|
+
nextToken = response.NextToken;
|
|
37
|
+
} while (nextToken);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Fetch the value for the specified CloudFormation stack export.
|
|
42
|
+
*
|
|
43
|
+
* @param name The name of the CloudFormation stack export to fetch.
|
|
44
|
+
* @returns The value of the CloudFormation stack export, or undefined if the
|
|
45
|
+
* export could not be found.
|
|
46
|
+
*/
|
|
47
|
+
const getExport = async (name) => {
|
|
48
|
+
await loadExports();
|
|
49
|
+
const response = cfExports.find((exp) => {
|
|
50
|
+
return (exp === null || exp === void 0 ? void 0 : exp.Name.toLowerCase().trim()) === name.toLowerCase().trim();
|
|
51
|
+
});
|
|
52
|
+
return response ? response.Value : undefined;
|
|
53
|
+
};
|
|
54
|
+
exports.getExport = getExport;
|
package/dist/dynamo.d.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { DMPToolDMPType } from '@dmptool/types';
|
|
2
|
+
export declare const DMP_LATEST_VERSION = "latest";
|
|
3
|
+
export declare const DMP_TOMBSTONE_VERSION = "tombstone";
|
|
4
|
+
interface DMPVersionType {
|
|
5
|
+
PK: string;
|
|
6
|
+
SK: string;
|
|
7
|
+
modified: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Lightweight query just to check if the DMP exists.
|
|
11
|
+
*
|
|
12
|
+
* @param dmpId
|
|
13
|
+
* @returns true if the DMP exists, false otherwise.
|
|
14
|
+
* @throws DMPToolDynamoError if the record could not be fetched due to an error
|
|
15
|
+
*/
|
|
16
|
+
export declare const DMPExists: (dmpId: string) => Promise<boolean>;
|
|
17
|
+
/**
|
|
18
|
+
* Fetch the version timestamps (including DMP_LATEST_VERSION) for the specified DMP ID.
|
|
19
|
+
*
|
|
20
|
+
* @param dmpId
|
|
21
|
+
* @returns The timestamps as strings (e.g. '2026-11-01T13:08:19Z' or 'latest')
|
|
22
|
+
* @throws DMPToolDynamoError if the records could not be fetched due to an error
|
|
23
|
+
*/
|
|
24
|
+
export declare const getDMPVersions: (dmpId: string) => Promise<DMPVersionType[] | []>;
|
|
25
|
+
/**
|
|
26
|
+
* Fetch the RDA Common Standard metadata record with DMP Tool specific extensions
|
|
27
|
+
* for the specified DMP ID.
|
|
28
|
+
*
|
|
29
|
+
* @param dmpId
|
|
30
|
+
* @param version The version of the DMP metadata record to persist
|
|
31
|
+
* (e.g. '2026-11-01T13:08:19Z').
|
|
32
|
+
* If not provided, the latest version will be used. Defaults to DMP_LATEST_VERSION.
|
|
33
|
+
* @param includeExtensions Whether or not to include the DMP Tool specific
|
|
34
|
+
* extensions in the returned record. Defaults to true.
|
|
35
|
+
* @returns The complete RDA Common Standard metadata record with the DMP extension
|
|
36
|
+
* metadata or an empty array if none were found.
|
|
37
|
+
* @throws DMPToolDynamoError if the records could not be fetched due to an error
|
|
38
|
+
*/
|
|
39
|
+
export declare const getDMPs: (dmpId: string, version: string | null, includeExtensions?: boolean) => Promise<DMPToolDMPType[] | []>;
|
|
40
|
+
/**
|
|
41
|
+
* Persists the specified DMP metadata record to the DynamoDB table.
|
|
42
|
+
* This function will handle the separation of RDA Common Standard and DMP Tool
|
|
43
|
+
* specific metadata.
|
|
44
|
+
*
|
|
45
|
+
* @param dmpId The DMP ID (e.g. '123456789')
|
|
46
|
+
* @param dmp The DMP metadata record to persist as either an RDA Common Standard
|
|
47
|
+
* or the standard with DMP Tool specific extensions.
|
|
48
|
+
* @param version The version of the DMP metadata record to persist
|
|
49
|
+
* (e.g. '2026-11-01T13:08:19Z').
|
|
50
|
+
* If not provided, the latest version will be used. Defaults to DMP_LATEST_VERSION.
|
|
51
|
+
* @param includeExtensions Whether or not to include the DMP Tool specific
|
|
52
|
+
* extensions in the returned record. Defaults to true.
|
|
53
|
+
* @returns The persisted DMP metadata record as an RDA Common Standard DMP
|
|
54
|
+
* metadata record with the DMP Tool specific extensions merged in.
|
|
55
|
+
* @throws DMPToolDynamoError if the record could not be persisted
|
|
56
|
+
*/
|
|
57
|
+
export declare const createDMP: (dmpId: string, dmp: DMPToolDMPType, version?: string, includeExtensions?: boolean) => Promise<DMPToolDMPType | undefined>;
|
|
58
|
+
/**
|
|
59
|
+
* Update the specified DMP metadata record.
|
|
60
|
+
* This function will handle the separation of RDA Common Standard and DMP Tool
|
|
61
|
+
* specific metadata. We always update the latest version of the DMP metadata record.
|
|
62
|
+
* Historical versions are immutable.
|
|
63
|
+
*
|
|
64
|
+
* A snapshot of the current "latest" version of the DMP's metadata will be taken
|
|
65
|
+
* under the following circumstances:
|
|
66
|
+
* - If the `provenance` of the incoming record does not match the one on the
|
|
67
|
+
* latest record
|
|
68
|
+
* - If the `modified` timestamp of the latest record is older than 2 hours ago
|
|
69
|
+
*
|
|
70
|
+
* If a snapshot is made, the timestamp and link to retrieve it will appear
|
|
71
|
+
* in the `versions` array
|
|
72
|
+
*
|
|
73
|
+
* @param dmp
|
|
74
|
+
* @param includeExtensions Whether or not to include the DMP Tool specific
|
|
75
|
+
* extensions in the returned record. Defaults to true.
|
|
76
|
+
* @returns The persisted DMP metadata record as an RDA Common Standard DMP
|
|
77
|
+
* metadata record with the DMP Tool specific extensions merged in.
|
|
78
|
+
* @throws DMPToolDynamoError if the record could not be persisted
|
|
79
|
+
*/
|
|
80
|
+
export declare const updateDMP: (dmp: DMPToolDMPType, includeExtensions?: boolean) => Promise<DMPToolDMPType>;
|
|
81
|
+
/**
|
|
82
|
+
* Create a Tombstone for the specified DMP metadata record
|
|
83
|
+
* (registered/published DMPs only!)
|
|
84
|
+
*
|
|
85
|
+
* @param dmpId The DMP ID (e.g. '11.12345/A1B2C3')
|
|
86
|
+
* @param includeExtensions Whether or not to include the DMP Tool specific
|
|
87
|
+
* extensions in the returned record. Defaults to true.
|
|
88
|
+
* @returns The new tombstone DMP metadata record as an RDA Common Standard DMP
|
|
89
|
+
* metadata record with the DMP Tool specific extensions merged in.
|
|
90
|
+
* @throws DMPToolDynamoError if a tombstone could not be created
|
|
91
|
+
*/
|
|
92
|
+
export declare const tombstoneDMP: (dmpId: string, includeExtensions?: boolean) => Promise<DMPToolDMPType>;
|
|
93
|
+
/**
|
|
94
|
+
* Delete the specified DMP metadata record and any associated DMP Tool extension records.
|
|
95
|
+
* This will NOT work on DMPs that have been registered/published.
|
|
96
|
+
*
|
|
97
|
+
* @param dmpId The DMP ID (e.g. '11.12345/A1B2C3')
|
|
98
|
+
* @param includeExtensions Whether or not to include the DMP Tool specific extensions
|
|
99
|
+
* in the returned record. Defaults to true.
|
|
100
|
+
* @returns The deleted DMP metadata record as an RDA Common Standard DMP metadata
|
|
101
|
+
* record with the DMP Tool specific extensions merged in.
|
|
102
|
+
* @throws DMPToolDynamoError if the record could not be deleted
|
|
103
|
+
*/
|
|
104
|
+
export declare const deleteDMP: (dmpId: string, includeExtensions?: boolean) => Promise<DMPToolDMPType>;
|
|
105
|
+
export {};
|