@awsless/awsless 0.0.85 → 0.0.87

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.
Files changed (28) hide show
  1. package/dist/bin.js +516 -170
  2. package/dist/features/cognito-client-secret/HASH +1 -0
  3. package/dist/features/cognito-client-secret/bundle.zip +0 -0
  4. package/dist/features/cognito-client-secret/index.js +61 -0
  5. package/dist/features/cognito-client-secret/index.mjs +59 -0
  6. package/dist/features/delete-bucket/HASH +1 -0
  7. package/dist/features/delete-bucket/bundle.zip +0 -0
  8. package/dist/features/delete-bucket/index.js +88 -0
  9. package/dist/features/{delete-bucket.js → delete-bucket/index.mjs} +2 -2
  10. package/dist/features/delete-hosted-zone/HASH +1 -0
  11. package/dist/features/delete-hosted-zone/bundle.zip +0 -0
  12. package/dist/features/delete-hosted-zone/index.js +130 -0
  13. package/dist/features/{delete-hosted-zone.js → delete-hosted-zone/index.mjs} +2 -2
  14. package/dist/features/global-exports/HASH +1 -0
  15. package/dist/features/global-exports/bundle.zip +0 -0
  16. package/dist/features/global-exports/index.js +63 -0
  17. package/dist/features/{global-exports.js → global-exports/index.mjs} +2 -2
  18. package/dist/features/invalidate-cache/HASH +1 -0
  19. package/dist/features/invalidate-cache/bundle.zip +0 -0
  20. package/dist/features/invalidate-cache/index.js +63 -0
  21. package/dist/features/{invalidate-cache.js → invalidate-cache/index.mjs} +2 -2
  22. package/dist/features/upload-bucket-asset/HASH +1 -0
  23. package/dist/features/upload-bucket-asset/bundle.zip +0 -0
  24. package/dist/features/upload-bucket-asset/index.js +22015 -0
  25. package/dist/features/{upload-bucket-asset.js → upload-bucket-asset/index.mjs} +2 -2
  26. package/dist/index.d.ts +93 -13
  27. package/dist/index.js +60 -16
  28. package/package.json +8 -4
@@ -0,0 +1 @@
1
+ 64ab50c75f36adcc289b9470606a9a989516e8b1
@@ -0,0 +1,61 @@
1
+ 'use strict';
2
+
3
+ var clientCognitoIdentityProvider = require('@aws-sdk/client-cognito-identity-provider');
4
+
5
+ const send = async (event, id, status, data, reason = '')=>{
6
+ const body = JSON.stringify({
7
+ Status: status,
8
+ Reason: reason,
9
+ PhysicalResourceId: id,
10
+ StackId: event.StackId,
11
+ RequestId: event.RequestId,
12
+ LogicalResourceId: event.LogicalResourceId,
13
+ NoEcho: false,
14
+ Data: data
15
+ });
16
+ await fetch(event.ResponseURL, {
17
+ method: 'PUT',
18
+ // @ts-ignore
19
+ port: 443,
20
+ body,
21
+ headers: {
22
+ 'content-type': '',
23
+ 'content-length': Buffer.from(body).byteLength.toString()
24
+ }
25
+ });
26
+ };
27
+
28
+ const client = new clientCognitoIdentityProvider.CognitoIdentityProviderClient({});
29
+ const handler = async (event)=>{
30
+ const type = event.RequestType;
31
+ const userPoolId = event.ResourceProperties.userPoolId;
32
+ const clientId = event.ResourceProperties.clientId;
33
+ console.log('Type:', type);
34
+ console.log('UserPoolId:', userPoolId);
35
+ console.log('ClientId:', clientId);
36
+ try {
37
+ if (type === 'Create' || type === 'Update') {
38
+ const input = {
39
+ UserPoolId: userPoolId,
40
+ ClientId: clientId
41
+ };
42
+ const command = new clientCognitoIdentityProvider.DescribeUserPoolClientCommand(input);
43
+ const response = await client.send(command);
44
+ const secret = response.UserPoolClient?.ClientSecret;
45
+ await send(event, clientId, 'SUCCESS', {
46
+ secret
47
+ });
48
+ } else {
49
+ await send(event, clientId, 'SUCCESS');
50
+ }
51
+ } catch (error) {
52
+ if (error instanceof Error) {
53
+ await send(event, clientId, 'FAILED', {}, error.message);
54
+ } else {
55
+ await send(event, clientId, 'FAILED', {}, 'Unknown error');
56
+ }
57
+ console.error(error);
58
+ }
59
+ };
60
+
61
+ exports.handler = handler;
@@ -0,0 +1,59 @@
1
+ import { CognitoIdentityProviderClient, DescribeUserPoolClientCommand } from '@aws-sdk/client-cognito-identity-provider';
2
+
3
+ const send = async (event, id, status, data, reason = '')=>{
4
+ const body = JSON.stringify({
5
+ Status: status,
6
+ Reason: reason,
7
+ PhysicalResourceId: id,
8
+ StackId: event.StackId,
9
+ RequestId: event.RequestId,
10
+ LogicalResourceId: event.LogicalResourceId,
11
+ NoEcho: false,
12
+ Data: data
13
+ });
14
+ await fetch(event.ResponseURL, {
15
+ method: 'PUT',
16
+ // @ts-ignore
17
+ port: 443,
18
+ body,
19
+ headers: {
20
+ 'content-type': '',
21
+ 'content-length': Buffer.from(body).byteLength.toString()
22
+ }
23
+ });
24
+ };
25
+
26
+ const client = new CognitoIdentityProviderClient({});
27
+ const handler = async (event)=>{
28
+ const type = event.RequestType;
29
+ const userPoolId = event.ResourceProperties.userPoolId;
30
+ const clientId = event.ResourceProperties.clientId;
31
+ console.log('Type:', type);
32
+ console.log('UserPoolId:', userPoolId);
33
+ console.log('ClientId:', clientId);
34
+ try {
35
+ if (type === 'Create' || type === 'Update') {
36
+ const input = {
37
+ UserPoolId: userPoolId,
38
+ ClientId: clientId
39
+ };
40
+ const command = new DescribeUserPoolClientCommand(input);
41
+ const response = await client.send(command);
42
+ const secret = response.UserPoolClient?.ClientSecret;
43
+ await send(event, clientId, 'SUCCESS', {
44
+ secret
45
+ });
46
+ } else {
47
+ await send(event, clientId, 'SUCCESS');
48
+ }
49
+ } catch (error) {
50
+ if (error instanceof Error) {
51
+ await send(event, clientId, 'FAILED', {}, error.message);
52
+ } else {
53
+ await send(event, clientId, 'FAILED', {}, 'Unknown error');
54
+ }
55
+ console.error(error);
56
+ }
57
+ };
58
+
59
+ export { handler };
@@ -0,0 +1 @@
1
+ 9ef61dd651048b674d78dd0938766f5abfb1574a
@@ -0,0 +1,88 @@
1
+ 'use strict';
2
+
3
+ var clientS3 = require('@aws-sdk/client-s3');
4
+
5
+ const send = async (event, id, status, data, reason = '')=>{
6
+ const body = JSON.stringify({
7
+ Status: status,
8
+ Reason: reason,
9
+ PhysicalResourceId: id,
10
+ StackId: event.StackId,
11
+ RequestId: event.RequestId,
12
+ LogicalResourceId: event.LogicalResourceId,
13
+ NoEcho: false,
14
+ Data: data
15
+ });
16
+ await fetch(event.ResponseURL, {
17
+ method: 'PUT',
18
+ // @ts-ignore
19
+ port: 443,
20
+ body,
21
+ headers: {
22
+ 'content-type': '',
23
+ 'content-length': Buffer.from(body).byteLength.toString()
24
+ }
25
+ });
26
+ };
27
+
28
+ const client = new clientS3.S3Client({});
29
+ const handler = async (event)=>{
30
+ const type = event.RequestType;
31
+ const bucketName = event.ResourceProperties.bucketName;
32
+ console.log('Type:', type);
33
+ console.log('BucketName:', bucketName);
34
+ try {
35
+ if (type === 'Delete') {
36
+ console.log('Deleting bucket objects...');
37
+ await emptyBucket(bucketName);
38
+ console.log('Done');
39
+ }
40
+ await send(event, bucketName, 'SUCCESS');
41
+ } catch (error) {
42
+ if (error instanceof Error) {
43
+ await send(event, bucketName, 'FAILED', {}, error.message);
44
+ } else {
45
+ await send(event, bucketName, 'FAILED', {}, 'Unknown error');
46
+ }
47
+ console.error(error);
48
+ }
49
+ };
50
+ const emptyBucket = async (bucket)=>{
51
+ while(true){
52
+ const result = await client.send(new clientS3.ListObjectsV2Command({
53
+ Bucket: bucket,
54
+ MaxKeys: 1000
55
+ }));
56
+ if (!result.Contents || result.Contents.length === 0) {
57
+ break;
58
+ }
59
+ await client.send(new clientS3.DeleteObjectsCommand({
60
+ Bucket: bucket,
61
+ Delete: {
62
+ Objects: result.Contents.map((object)=>({
63
+ Key: object.Key
64
+ }))
65
+ }
66
+ }));
67
+ }
68
+ while(true){
69
+ const result = await client.send(new clientS3.ListObjectVersionsCommand({
70
+ Bucket: bucket,
71
+ MaxKeys: 1000
72
+ }));
73
+ if (!result.Versions || result.Versions.length === 0) {
74
+ break;
75
+ }
76
+ await client.send(new clientS3.DeleteObjectsCommand({
77
+ Bucket: bucket,
78
+ Delete: {
79
+ Objects: result.Versions.map((object)=>({
80
+ Key: object.Key,
81
+ VersionId: object.VersionId
82
+ }))
83
+ }
84
+ }));
85
+ }
86
+ };
87
+
88
+ exports.handler = handler;
@@ -11,14 +11,14 @@ const send = async (event, id, status, data, reason = '')=>{
11
11
  NoEcho: false,
12
12
  Data: data
13
13
  });
14
- // @ts-ignore
15
14
  await fetch(event.ResponseURL, {
16
15
  method: 'PUT',
16
+ // @ts-ignore
17
17
  port: 443,
18
18
  body,
19
19
  headers: {
20
20
  'content-type': '',
21
- 'content-length': Buffer.from(body).byteLength
21
+ 'content-length': Buffer.from(body).byteLength.toString()
22
22
  }
23
23
  });
24
24
  };
@@ -0,0 +1 @@
1
+ 8752aafdfc559d1e4b7002f66a35e58c71ec17f4
@@ -0,0 +1,130 @@
1
+ 'use strict';
2
+
3
+ var clientRoute53 = require('@aws-sdk/client-route-53');
4
+
5
+ const send = async (event, id, status, data, reason = '')=>{
6
+ const body = JSON.stringify({
7
+ Status: status,
8
+ Reason: reason,
9
+ PhysicalResourceId: id,
10
+ StackId: event.StackId,
11
+ RequestId: event.RequestId,
12
+ LogicalResourceId: event.LogicalResourceId,
13
+ NoEcho: false,
14
+ Data: data
15
+ });
16
+ await fetch(event.ResponseURL, {
17
+ method: 'PUT',
18
+ // @ts-ignore
19
+ port: 443,
20
+ body,
21
+ headers: {
22
+ 'content-type': '',
23
+ 'content-length': Buffer.from(body).byteLength.toString()
24
+ }
25
+ });
26
+ };
27
+
28
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
29
+
30
+ function getDefaultExportFromCjs (x) {
31
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
32
+ }
33
+
34
+ var chunk$1 = {exports: {}};
35
+
36
+ (function (module, exports) {
37
+
38
+ (function () {
39
+ function chunk(collection, size) {
40
+ var result = [];
41
+
42
+ // default size to two item
43
+ size = parseInt(size) || 2;
44
+
45
+ // add each chunk to the result
46
+ for (var x = 0; x < Math.ceil(collection.length / size); x++) {
47
+ var start = x * size;
48
+ var end = start + size;
49
+
50
+ result.push(collection.slice(start, end));
51
+ }
52
+
53
+ return result;
54
+ }
55
+
56
+ // export in node or browser
57
+ {
58
+ if (module.exports) {
59
+ exports = module.exports = chunk;
60
+ }
61
+ exports.chunk = chunk;
62
+ }
63
+ }.call(commonjsGlobal));
64
+ } (chunk$1, chunk$1.exports));
65
+
66
+ var chunkExports = chunk$1.exports;
67
+ var chunk = /*@__PURE__*/getDefaultExportFromCjs(chunkExports);
68
+
69
+ const client = new clientRoute53.Route53Client({});
70
+ const handler = async (event)=>{
71
+ const type = event.RequestType;
72
+ const hostedZoneId = event.ResourceProperties.hostedZoneId;
73
+ console.log('Type:', type);
74
+ console.log('HostedZoneId:', hostedZoneId);
75
+ try {
76
+ if (type === 'Delete') {
77
+ const records = await listHostedZoneRecords(hostedZoneId);
78
+ console.log('Records:', records);
79
+ await deleteHostedZoneRecords(hostedZoneId, records);
80
+ }
81
+ await send(event, hostedZoneId, 'SUCCESS');
82
+ } catch (error) {
83
+ if (error instanceof Error) {
84
+ await send(event, hostedZoneId, 'FAILED', {}, error.message);
85
+ } else {
86
+ await send(event, hostedZoneId, 'FAILED', {}, 'Unknown error');
87
+ }
88
+ console.error(error);
89
+ }
90
+ };
91
+ const deleteHostedZoneRecords = async (hostedZoneId, records)=>{
92
+ records = records.filter((record)=>![
93
+ 'SOA',
94
+ 'NS'
95
+ ].includes(record.Type));
96
+ if (records.length === 0) {
97
+ return;
98
+ }
99
+ await Promise.all(chunk(records, 100).map(async (records)=>{
100
+ await client.send(new clientRoute53.ChangeResourceRecordSetsCommand({
101
+ HostedZoneId: hostedZoneId,
102
+ ChangeBatch: {
103
+ Changes: records.map((record)=>({
104
+ Action: 'DELETE',
105
+ ResourceRecordSet: record
106
+ }))
107
+ }
108
+ }));
109
+ }));
110
+ };
111
+ const listHostedZoneRecords = async (hostedZoneId)=>{
112
+ const records = [];
113
+ let token;
114
+ while(true){
115
+ const result = await client.send(new clientRoute53.ListResourceRecordSetsCommand({
116
+ HostedZoneId: hostedZoneId,
117
+ StartRecordName: token
118
+ }));
119
+ if (result.ResourceRecordSets && result.ResourceRecordSets.length) {
120
+ records.push(...result.ResourceRecordSets);
121
+ }
122
+ if (result.NextRecordName) {
123
+ token = result.NextRecordName;
124
+ } else {
125
+ return records;
126
+ }
127
+ }
128
+ };
129
+
130
+ exports.handler = handler;
@@ -11,14 +11,14 @@ const send = async (event, id, status, data, reason = '')=>{
11
11
  NoEcho: false,
12
12
  Data: data
13
13
  });
14
- // @ts-ignore
15
14
  await fetch(event.ResponseURL, {
16
15
  method: 'PUT',
16
+ // @ts-ignore
17
17
  port: 443,
18
18
  body,
19
19
  headers: {
20
20
  'content-type': '',
21
- 'content-length': Buffer.from(body).byteLength
21
+ 'content-length': Buffer.from(body).byteLength.toString()
22
22
  }
23
23
  });
24
24
  };
@@ -0,0 +1 @@
1
+ 24e4c709abee1432751de78eedbf776fa574e8e4
@@ -0,0 +1,63 @@
1
+ 'use strict';
2
+
3
+ var clientCloudformation = require('@aws-sdk/client-cloudformation');
4
+
5
+ const send = async (event, id, status, data, reason = '')=>{
6
+ const body = JSON.stringify({
7
+ Status: status,
8
+ Reason: reason,
9
+ PhysicalResourceId: id,
10
+ StackId: event.StackId,
11
+ RequestId: event.RequestId,
12
+ LogicalResourceId: event.LogicalResourceId,
13
+ NoEcho: false,
14
+ Data: data
15
+ });
16
+ await fetch(event.ResponseURL, {
17
+ method: 'PUT',
18
+ // @ts-ignore
19
+ port: 443,
20
+ body,
21
+ headers: {
22
+ 'content-type': '',
23
+ 'content-length': Buffer.from(body).byteLength.toString()
24
+ }
25
+ });
26
+ };
27
+
28
+ const handler = async (event)=>{
29
+ const region = event.ResourceProperties.region;
30
+ try {
31
+ const data = await listExports(region);
32
+ await send(event, region, 'SUCCESS', data);
33
+ } catch (error) {
34
+ if (error instanceof Error) {
35
+ await send(event, region, 'FAILED', {}, error.message);
36
+ } else {
37
+ await send(event, region, 'FAILED', {}, 'Unknown error');
38
+ }
39
+ console.error(error);
40
+ }
41
+ };
42
+ const listExports = async (region)=>{
43
+ const client = new clientCloudformation.CloudFormationClient({
44
+ region
45
+ });
46
+ const data = {};
47
+ let token;
48
+ while(true){
49
+ const result = await client.send(new clientCloudformation.ListExportsCommand({
50
+ NextToken: token
51
+ }));
52
+ result.Exports?.forEach((item)=>{
53
+ data[item.Name] = item.Value;
54
+ });
55
+ if (result.NextToken) {
56
+ token = result.NextToken;
57
+ } else {
58
+ return data;
59
+ }
60
+ }
61
+ };
62
+
63
+ exports.handler = handler;
@@ -11,14 +11,14 @@ const send = async (event, id, status, data, reason = '')=>{
11
11
  NoEcho: false,
12
12
  Data: data
13
13
  });
14
- // @ts-ignore
15
14
  await fetch(event.ResponseURL, {
16
15
  method: 'PUT',
16
+ // @ts-ignore
17
17
  port: 443,
18
18
  body,
19
19
  headers: {
20
20
  'content-type': '',
21
- 'content-length': Buffer.from(body).byteLength
21
+ 'content-length': Buffer.from(body).byteLength.toString()
22
22
  }
23
23
  });
24
24
  };
@@ -0,0 +1 @@
1
+ 57596b321a7e724d843a87434ff5bb3cc0b46931
@@ -0,0 +1,63 @@
1
+ 'use strict';
2
+
3
+ var clientCloudfront = require('@aws-sdk/client-cloudfront');
4
+
5
+ const send = async (event, id, status, data, reason = '')=>{
6
+ const body = JSON.stringify({
7
+ Status: status,
8
+ Reason: reason,
9
+ PhysicalResourceId: id,
10
+ StackId: event.StackId,
11
+ RequestId: event.RequestId,
12
+ LogicalResourceId: event.LogicalResourceId,
13
+ NoEcho: false,
14
+ Data: data
15
+ });
16
+ await fetch(event.ResponseURL, {
17
+ method: 'PUT',
18
+ // @ts-ignore
19
+ port: 443,
20
+ body,
21
+ headers: {
22
+ 'content-type': '',
23
+ 'content-length': Buffer.from(body).byteLength.toString()
24
+ }
25
+ });
26
+ };
27
+
28
+ const client = new clientCloudfront.CloudFrontClient({});
29
+ const handler = async (event)=>{
30
+ const type = event.RequestType;
31
+ const { distributionId, paths } = event.ResourceProperties;
32
+ console.log('Type', type);
33
+ console.log('DistributionId', distributionId);
34
+ console.log('Paths', paths);
35
+ try {
36
+ if (type === 'Update') {
37
+ await invalidateCache(distributionId, paths);
38
+ }
39
+ await send(event, distributionId, 'SUCCESS');
40
+ } catch (error) {
41
+ if (error instanceof Error) {
42
+ await send(event, distributionId, 'FAILED', {}, error.message);
43
+ } else {
44
+ await send(event, distributionId, 'FAILED', {}, 'Unknown error');
45
+ }
46
+ console.error(error);
47
+ }
48
+ };
49
+ const invalidateCache = async (distributionId, paths)=>{
50
+ const result = await client.send(new clientCloudfront.CreateInvalidationCommand({
51
+ DistributionId: distributionId,
52
+ InvalidationBatch: {
53
+ CallerReference: Date.now().toString(),
54
+ Paths: {
55
+ Quantity: paths.length,
56
+ Items: paths
57
+ }
58
+ }
59
+ }));
60
+ return result.Invalidation.Id;
61
+ };
62
+
63
+ exports.handler = handler;
@@ -11,14 +11,14 @@ const send = async (event, id, status, data, reason = '')=>{
11
11
  NoEcho: false,
12
12
  Data: data
13
13
  });
14
- // @ts-ignore
15
14
  await fetch(event.ResponseURL, {
16
15
  method: 'PUT',
16
+ // @ts-ignore
17
17
  port: 443,
18
18
  body,
19
19
  headers: {
20
20
  'content-type': '',
21
- 'content-length': Buffer.from(body).byteLength
21
+ 'content-length': Buffer.from(body).byteLength.toString()
22
22
  }
23
23
  });
24
24
  };
@@ -0,0 +1 @@
1
+ 022a1f0af1891993ff757275d5ed82fc70eabb74