@reventlessdev/rescript-aws-sdk 2.2.0-alpha.20

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 (47) hide show
  1. package/CHANGELOG.md +174 -0
  2. package/LICENSE +202 -0
  3. package/README.md +21 -0
  4. package/package.json +44 -0
  5. package/rescript.json +23 -0
  6. package/src/CloudWatchEvents.res +162 -0
  7. package/src/CloudWatchEvents.res.mjs +94 -0
  8. package/src/CognitoIdentityServiceProvider.res +117 -0
  9. package/src/CognitoIdentityServiceProvider.res.mjs +70 -0
  10. package/src/DynamoDb.res +3 -0
  11. package/src/DynamoDb.res.mjs +15 -0
  12. package/src/DynamoDb_DocumentClient.res +905 -0
  13. package/src/DynamoDb_DocumentClient.res.mjs +338 -0
  14. package/src/DynamoDb_DynamoDb.res +189 -0
  15. package/src/DynamoDb_DynamoDb.res.mjs +70 -0
  16. package/src/DynamoDb_Util.res +128 -0
  17. package/src/DynamoDb_Util.res.mjs +35 -0
  18. package/src/DynamoDb_Util_Helpers.res +7 -0
  19. package/src/DynamoDb_Util_Helpers.res.mjs +23 -0
  20. package/src/ECS.res +96 -0
  21. package/src/ECS.res.mjs +46 -0
  22. package/src/IAM.res +20 -0
  23. package/src/IAM.res.mjs +9 -0
  24. package/src/Kinesis.res +50 -0
  25. package/src/Kinesis.res.mjs +39 -0
  26. package/src/Metadata.res +9 -0
  27. package/src/Metadata.res.mjs +2 -0
  28. package/src/NodeHttpHandler.res +6 -0
  29. package/src/NodeHttpHandler.res.mjs +2 -0
  30. package/src/S3.res +152 -0
  31. package/src/S3.res.mjs +61 -0
  32. package/src/S3_Helpers.res +20 -0
  33. package/src/S3_Helpers.res.mjs +26 -0
  34. package/src/SES.res +113 -0
  35. package/src/SES.res.mjs +59 -0
  36. package/src/SNS.res +167 -0
  37. package/src/SNS.res.mjs +98 -0
  38. package/src/SNS_Helpers.res +45 -0
  39. package/src/SNS_Helpers.res.mjs +57 -0
  40. package/src/SQS.res +241 -0
  41. package/src/SQS.res.mjs +121 -0
  42. package/src/SQS_Helpers.res +267 -0
  43. package/src/SQS_Helpers.res.mjs +227 -0
  44. package/src/SecretsManager.res +61 -0
  45. package/src/SecretsManager.res.mjs +46 -0
  46. package/src/example/DynamoDbUtilExample.res +20 -0
  47. package/src/example/DynamoDbUtilExample.res.mjs +66 -0
package/src/SES.res ADDED
@@ -0,0 +1,113 @@
1
+ type client
2
+
3
+ module Raw = {
4
+ @module("@aws-sdk/client-sesv2") @new
5
+ external client: unit => client = "SESv2Client"
6
+ }
7
+
8
+ let clientInstance = ref(None)
9
+
10
+ let client = () => {
11
+ switch clientInstance.contents {
12
+ | None =>
13
+ let client = Raw.client()
14
+ clientInstance := Some(client)
15
+ client
16
+ | Some(client) => client
17
+ }
18
+ }
19
+
20
+ module SendEmailCommand = {
21
+ /*** see: https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/sesv2/command/SendEmailCommand/ */
22
+
23
+ type t
24
+
25
+ type content = {
26
+ @as("Data") data: string,
27
+ @as("Charset") charset?: string,
28
+ }
29
+
30
+ type raw // FIXME: implement
31
+
32
+ type template // FIXME: implement
33
+
34
+ type messageBody = {
35
+ @as("Html") html?: content,
36
+ @as("Text") text?: content,
37
+ }
38
+
39
+ type nameValue = {
40
+ @as("Name") name: string,
41
+ @as("Value") value: string,
42
+ }
43
+
44
+ type message = {
45
+ @as("Body") body: messageBody,
46
+ @as("Subject") subject: content,
47
+ @as("Headers") headers?: array<nameValue>,
48
+ }
49
+
50
+ type emailContent = {
51
+ @as("Raw") raw?: raw,
52
+ @as("Simple") simple?: message,
53
+ @as("Template") template?: template,
54
+ }
55
+
56
+ type destination = {
57
+ @as("ToAddresses") toAddresses?: array<string>,
58
+ @as("CcAddresses") ccAddresses?: array<string>,
59
+ @as("BccAddresses") bccAddresses?: array<string>,
60
+ }
61
+
62
+ type listManagementOptions = {
63
+ @as("ContactListName") listName: string,
64
+ @as("TopicName") topicName?: string,
65
+ }
66
+
67
+ type input = {
68
+ @as("Content") content: emailContent,
69
+ @as("ConfigurationSetName") configurationSetName?: string,
70
+ @as("Destination") destination: destination,
71
+ @as("EmailTags") emailTags?: array<nameValue>,
72
+ @as("FeedbackForwardingEmailAddress") feedbackForwardingEmailAddress?: string,
73
+ @as("FeedbackForwardingEmailAddressIdentityArn")
74
+ feedbackForwardingEmailAddressIdentityArn?: string,
75
+ @as("FromEmailAddress") fromEmailAddress?: string,
76
+ @as("FromEmailAddressIdentityArn") fromEmailAddressIdentityArn?: string,
77
+ @as("ListManagementOptions") listManagementOptions?: listManagementOptions,
78
+ @as("ReplyToAddresses") replyToAddresses?: array<string>,
79
+ }
80
+
81
+ type output = {
82
+ @as("$metadata") metadata: Metadata.t,
83
+ @as("MessageId") messageId?: string,
84
+ }
85
+
86
+ @new @module("@aws-sdk/client-sesv2")
87
+ external make: input => t = "SendEmailCommand"
88
+
89
+ module Raw = {
90
+ @send
91
+ external send: (client, t) => promise<output> = "send"
92
+ }
93
+
94
+ let send: t => promise<output> = input => Raw.send(client(), input)
95
+ }
96
+
97
+ let sendTextEmail = (
98
+ ~source: string,
99
+ ~destination: SendEmailCommand.destination,
100
+ ~subject: string,
101
+ ~message: string,
102
+ ) => {
103
+ SendEmailCommand.fromEmailAddress: source,
104
+ destination,
105
+ content: {
106
+ simple: {
107
+ subject: {data: subject},
108
+ body: {
109
+ text: {data: message},
110
+ },
111
+ },
112
+ },
113
+ }
@@ -0,0 +1,59 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+ import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
4
+ import * as ClientSesv2 from "@aws-sdk/client-sesv2";
5
+
6
+ let Raw = {};
7
+
8
+ let clientInstance = {
9
+ contents: undefined
10
+ };
11
+
12
+ function client() {
13
+ let client$1 = clientInstance.contents;
14
+ if (client$1 !== undefined) {
15
+ return Primitive_option.valFromOption(client$1);
16
+ }
17
+ let client$2 = new ClientSesv2.SESv2Client();
18
+ clientInstance.contents = Primitive_option.some(client$2);
19
+ return client$2;
20
+ }
21
+
22
+ let Raw$1 = {};
23
+
24
+ function send(input) {
25
+ return client().send(input);
26
+ }
27
+
28
+ let SendEmailCommand = {
29
+ Raw: Raw$1,
30
+ send: send
31
+ };
32
+
33
+ function sendTextEmail(source, destination, subject, message) {
34
+ return {
35
+ Content: {
36
+ Simple: {
37
+ Body: {
38
+ Text: {
39
+ Data: message
40
+ }
41
+ },
42
+ Subject: {
43
+ Data: subject
44
+ }
45
+ }
46
+ },
47
+ Destination: destination,
48
+ FromEmailAddress: source
49
+ };
50
+ }
51
+
52
+ export {
53
+ Raw,
54
+ clientInstance,
55
+ client,
56
+ SendEmailCommand,
57
+ sendTextEmail,
58
+ }
59
+ /* @aws-sdk/client-sesv2 Not a pure module */
package/src/SNS.res ADDED
@@ -0,0 +1,167 @@
1
+ /*** @aws-sdk/client-sns
2
+ see: https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/sns/
3
+ */
4
+ type client
5
+
6
+ type options = {
7
+ maxAttempts?: int,
8
+ region?: string,
9
+ requestHandler?: NodeHttpHandler.t,
10
+ }
11
+
12
+ module Raw = {
13
+ @module("@aws-sdk/client-sns") @new
14
+ external client: (~options: options, unit) => client = "SNSClient"
15
+ }
16
+
17
+ let clientInstance = ref(None)
18
+
19
+ // TODO: instead of mutating snsInstance, use lazy
20
+ let client = () =>
21
+ switch clientInstance.contents {
22
+ | None =>
23
+ let client = Raw.client(
24
+ ~options={
25
+ maxAttempts: 5,
26
+ requestHandler: NodeHttpHandler.make({
27
+ connectionTimeout: 5000,
28
+ requestTimeout: 5000,
29
+ }),
30
+ },
31
+ (),
32
+ )
33
+ clientInstance := Some(client)
34
+ client
35
+ | Some(client) => client
36
+ }
37
+
38
+ module PublishCommand = {
39
+ type input = {
40
+ @as("Message") message: string,
41
+ @as("MessageStructure") messageStructure?: string,
42
+ @as("PhoneNumber") phoneNumber?: string,
43
+ @as("TargetArn") targetArn?: string,
44
+ @as("TopicArn") topicArn?: string,
45
+ @as("Subject") subject?: string,
46
+ @as("MessageDeduplicationId") messageDeduplicationId?: string,
47
+ @as("MessageGroupId") messageGroupId?: string,
48
+ }
49
+
50
+ type output = {@as("MessageId") messageId: string}
51
+
52
+ type t
53
+ @new @module("@aws-sdk/client-sns")
54
+ external make: input => t = "PublishCommand"
55
+
56
+ module Raw = {
57
+ @send
58
+ external send: (client, t) => promise<output> = "send"
59
+ }
60
+
61
+ let send: t => promise<output> = command => Raw.send(client(), command)
62
+ }
63
+
64
+ module SubscribeCommand = {
65
+ type redrivePolicy = {deadLetterTargetArn?: string}
66
+
67
+ type attributes = {
68
+ @as("DeliveryPolicy") deliveryPolicy?: string,
69
+ @as("FilterPolicy") filterPolicy?: string,
70
+ @as("RawMessageDelivery") rawMessageDelivery?: string,
71
+ @as("RedrivePolicy") redrivePolicy?: redrivePolicy,
72
+ }
73
+
74
+ type t
75
+
76
+ type input = {
77
+ @as("TopicArn") topicArn: string,
78
+ @as("Protocol")
79
+ protocol: [
80
+ | #http
81
+ | #https
82
+ | #email
83
+ | #"email-json"
84
+ | #sms
85
+ | #sqs
86
+ | #application
87
+ | #lambda
88
+ ],
89
+ @as("Endpoint") endpoint: string,
90
+ @as("Attributes") attributes?: attributes,
91
+ @as("ReturnSubscriptionArn") returnSubscriptionArn?: bool,
92
+ }
93
+
94
+ type output = {
95
+ @as("SubscriptionArn")
96
+ subscriptionArn: string /* either the actual arn or "pending confirmation" */,
97
+ }
98
+
99
+ let getSubscriptionArn: output => result<string, string> = response => {
100
+ let subscriptionArn = response.subscriptionArn
101
+ if subscriptionArn == "pending confirmation" {
102
+ Error(subscriptionArn)
103
+ } else {
104
+ Ok(subscriptionArn)
105
+ }
106
+ }
107
+
108
+ @new @module("@aws-sdk/client-sns")
109
+ external make: input => /* default: false */ t = "SubscribeCommand"
110
+
111
+ module Raw = {
112
+ @send
113
+ external send: (client, t) => promise<output> = "send"
114
+ }
115
+
116
+ let send: t => promise<output> = command => Raw.send(client(), command)
117
+ }
118
+
119
+ module UnsubscribeCommand = {
120
+ type t
121
+
122
+ type input = {@as("SubscriptionArn") subscriptionArn: string}
123
+
124
+ type output = {.}
125
+
126
+ @new @module("@aws-sdk/client-sns") external make: input => t = "UnsubscribeCommand"
127
+
128
+ module Raw = {
129
+ @send
130
+ external send: (client, t) => promise<output> = "send"
131
+ }
132
+
133
+ let send: t => promise<output> = command => Raw.send(client(), command)
134
+ }
135
+
136
+ module ListSubscriptionsByTopicCommand = {
137
+ type t
138
+
139
+ type input = {
140
+ @as("TopicArn") topicArn: string,
141
+ @as("NextToken") nextToken?: string,
142
+ }
143
+
144
+ type subscription = {
145
+ @as("SubscriptionArn") subscriptionArn: string,
146
+ @as("Owner") owner: string,
147
+ @as("TopicArn") topicArn: string,
148
+ @as("Protocol") protocol: string,
149
+ @as("Endpoint") endpoint: string,
150
+ }
151
+
152
+ type output = {
153
+ @as("Subscriptions") subscriptions: array<subscription>,
154
+ @as("NextToken") nextToken: string,
155
+ }
156
+
157
+ @new @module("@aws-sdk/client-sns")
158
+ external make: input => t = "ListSubscriptionsByTopicCommand"
159
+
160
+ module Raw = {
161
+ @send
162
+ external send: (client, t) => promise<output> = "send"
163
+ }
164
+
165
+ let send: t => promise<output> = command => Raw.send(client(), command)
166
+ }
167
+
@@ -0,0 +1,98 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+ import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
4
+ import * as ClientSns from "@aws-sdk/client-sns";
5
+ import * as NodeHttpHandler from "@smithy/node-http-handler";
6
+
7
+ let Raw = {};
8
+
9
+ let clientInstance = {
10
+ contents: undefined
11
+ };
12
+
13
+ function client() {
14
+ let client$1 = clientInstance.contents;
15
+ if (client$1 !== undefined) {
16
+ return Primitive_option.valFromOption(client$1);
17
+ }
18
+ let client$2 = new ClientSns.SNSClient({
19
+ maxAttempts: 5,
20
+ requestHandler: Primitive_option.some(new NodeHttpHandler.NodeHttpHandler({
21
+ connectionTimeout: 5000,
22
+ requestTimeout: 5000
23
+ }))
24
+ });
25
+ clientInstance.contents = Primitive_option.some(client$2);
26
+ return client$2;
27
+ }
28
+
29
+ let Raw$1 = {};
30
+
31
+ function send(command) {
32
+ return client().send(command);
33
+ }
34
+
35
+ let PublishCommand = {
36
+ Raw: Raw$1,
37
+ send: send
38
+ };
39
+
40
+ function getSubscriptionArn(response) {
41
+ let subscriptionArn = response.SubscriptionArn;
42
+ if (subscriptionArn === "pending confirmation") {
43
+ return {
44
+ TAG: "Error",
45
+ _0: subscriptionArn
46
+ };
47
+ } else {
48
+ return {
49
+ TAG: "Ok",
50
+ _0: subscriptionArn
51
+ };
52
+ }
53
+ }
54
+
55
+ let Raw$2 = {};
56
+
57
+ function send$1(command) {
58
+ return client().send(command);
59
+ }
60
+
61
+ let SubscribeCommand = {
62
+ getSubscriptionArn: getSubscriptionArn,
63
+ Raw: Raw$2,
64
+ send: send$1
65
+ };
66
+
67
+ let Raw$3 = {};
68
+
69
+ function send$2(command) {
70
+ return client().send(command);
71
+ }
72
+
73
+ let UnsubscribeCommand = {
74
+ Raw: Raw$3,
75
+ send: send$2
76
+ };
77
+
78
+ let Raw$4 = {};
79
+
80
+ function send$3(command) {
81
+ return client().send(command);
82
+ }
83
+
84
+ let ListSubscriptionsByTopicCommand = {
85
+ Raw: Raw$4,
86
+ send: send$3
87
+ };
88
+
89
+ export {
90
+ Raw,
91
+ clientInstance,
92
+ client,
93
+ PublishCommand,
94
+ SubscribeCommand,
95
+ UnsubscribeCommand,
96
+ ListSubscriptionsByTopicCommand,
97
+ }
98
+ /* @aws-sdk/client-sns Not a pure module */
@@ -0,0 +1,45 @@
1
+ let publish = (~topicArn, ~messageGroupId=?, message) =>
2
+ SNS.PublishCommand.send(
3
+ SNS.PublishCommand.make({
4
+ topicArn,
5
+ messageGroupId: ?(messageGroupId->Option.map(id => id->String.replaceRegExp(/ /g, ""))),
6
+ message,
7
+ }),
8
+ )
9
+
10
+ let findSubscription = async (queueArn, topicArn) => {
11
+ let response = await SNS.ListSubscriptionsByTopicCommand.send(
12
+ SNS.ListSubscriptionsByTopicCommand.make({topicArn: topicArn}),
13
+ ) // TODO: handle paging of subscriptions
14
+ response.subscriptions->Array.find(subscription => subscription.endpoint == queueArn)
15
+ }
16
+
17
+ let subscribeQueueToTopic = async (queueArn, topicArn) =>
18
+ // TODO: add dlq in RedrivePolicy
19
+ switch await findSubscription(queueArn, topicArn) {
20
+ | None =>
21
+ let subscriptionResponse = await SNS.SubscribeCommand.send(
22
+ SNS.SubscribeCommand.make({
23
+ topicArn,
24
+ protocol: #sqs,
25
+ endpoint: queueArn,
26
+ attributes: {
27
+ rawMessageDelivery: "true",
28
+ },
29
+ }),
30
+ )
31
+ Console.log2("subscribed:", subscriptionResponse.subscriptionArn)
32
+
33
+ | Some(subscription) =>
34
+ Console.log2("re-using existing subscription:", subscription.subscriptionArn)
35
+ }
36
+
37
+ let unsubscribeQueueFromTopic = async (queueArn, topicArn) =>
38
+ switch await findSubscription(queueArn, topicArn) {
39
+ | Some(subscription) =>
40
+ let _unsubscribeResponse = await SNS.UnsubscribeCommand.send(
41
+ SNS.UnsubscribeCommand.make({subscriptionArn: subscription.subscriptionArn}),
42
+ )
43
+ let _ = Console.log2("unsubscribed:", subscription.subscriptionArn)
44
+ | None => Console.log2("there is no subscription for queue:", queueArn)
45
+ }
@@ -0,0 +1,57 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+ import * as SNS$AwsSdk from "./SNS.res.mjs";
4
+ import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
5
+ import * as ClientSns from "@aws-sdk/client-sns";
6
+
7
+ function publish(topicArn, messageGroupId, message) {
8
+ return SNS$AwsSdk.PublishCommand.send(new ClientSns.PublishCommand({
9
+ Message: message,
10
+ TopicArn: topicArn,
11
+ MessageGroupId: Stdlib_Option.map(messageGroupId, id => id.replace(/ /g, ""))
12
+ }));
13
+ }
14
+
15
+ async function findSubscription(queueArn, topicArn) {
16
+ let response = await SNS$AwsSdk.ListSubscriptionsByTopicCommand.send(new ClientSns.ListSubscriptionsByTopicCommand({
17
+ TopicArn: topicArn
18
+ }));
19
+ return response.Subscriptions.find(subscription => subscription.Endpoint === queueArn);
20
+ }
21
+
22
+ async function subscribeQueueToTopic(queueArn, topicArn) {
23
+ let subscription = await findSubscription(queueArn, topicArn);
24
+ if (subscription !== undefined) {
25
+ console.log("re-using existing subscription:", subscription.SubscriptionArn);
26
+ return;
27
+ }
28
+ let subscriptionResponse = await SNS$AwsSdk.SubscribeCommand.send(new ClientSns.SubscribeCommand({
29
+ TopicArn: topicArn,
30
+ Protocol: "sqs",
31
+ Endpoint: queueArn,
32
+ Attributes: {
33
+ RawMessageDelivery: "true"
34
+ }
35
+ }));
36
+ console.log("subscribed:", subscriptionResponse.SubscriptionArn);
37
+ }
38
+
39
+ async function unsubscribeQueueFromTopic(queueArn, topicArn) {
40
+ let subscription = await findSubscription(queueArn, topicArn);
41
+ if (subscription !== undefined) {
42
+ await SNS$AwsSdk.UnsubscribeCommand.send(new ClientSns.UnsubscribeCommand({
43
+ SubscriptionArn: subscription.SubscriptionArn
44
+ }));
45
+ console.log("unsubscribed:", subscription.SubscriptionArn);
46
+ } else {
47
+ console.log("there is no subscription for queue:", queueArn);
48
+ }
49
+ }
50
+
51
+ export {
52
+ publish,
53
+ findSubscription,
54
+ subscribeQueueToTopic,
55
+ unsubscribeQueueFromTopic,
56
+ }
57
+ /* SNS-AwsSdk Not a pure module */