@ingestkorea/client-sens 1.4.0 → 1.4.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.
@@ -0,0 +1,14 @@
1
+ ### Issue
2
+ Issue number, if available, prefixed with "#"
3
+
4
+ ### Description
5
+ What does this implement/fix? Explain your changes.
6
+
7
+ ### Testing
8
+ How was this change tested?
9
+
10
+ ### Additional context
11
+ Add any other context about the PR here.
12
+
13
+ ---
14
+ By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
package/README.md CHANGED
@@ -83,14 +83,17 @@ let command = new SendAlimtalkCommand(params);
83
83
  ```ts
84
84
  /**
85
85
  * Automatically set message type('SMS' | 'LMS') according to content-length(euc-kr)
86
- * SMS: max 80bytes
86
+ * SMS: max 90bytes
87
87
  * LMS: max 2000bytes
88
88
  */
89
89
  let params: SendSMSCommandInput = {
90
90
  from: '01012345678',
91
- content: CONTENT,
91
+ content: DEFAULT_CONTENT,
92
92
  messages: [
93
- { to: '01087654321' }
93
+ {
94
+ to: '01087654321',
95
+ content: OPTIONAL_CONTENT // optional // this OPTIONAL_CONTENT override above DEFAULT_CONTENT
96
+ }
94
97
  ]
95
98
  };
96
99
  let command = new SendSMSCommand(params);
@@ -18,11 +18,10 @@ const util_error_handler_1 = require("@ingestkorea/util-error-handler");
18
18
  class SendSMSCommand extends models_1.SensCommand {
19
19
  constructor(input) {
20
20
  super(input);
21
- const content = textTrimming(input.content);
22
- const messageType = messageTypeChecker(content);
23
- this.input = Object.assign(Object.assign({}, input), { from: phoneNumPretty(input.from), content: content, type: input.type === messageType ? input.type : messageType, messages: input.messages.map(message => {
24
- return Object.assign(Object.assign({ to: phoneNumPretty(message.to) }, (message.content != undefined && { content: textTrimming(message.content) })), (message.subject != undefined && messageType === 'LMS' && { subject: textTrimming(message.subject) }));
25
- }) });
21
+ const content = trimText(input.content);
22
+ const { messages, messageType: childMessageType } = resolveInputMessages(input.messages);
23
+ const messageType = childMessageType == 'LMS' ? childMessageType : checkMessageType(content);
24
+ this.input = Object.assign(Object.assign({}, input), { from: prettyPhoneNum(input.from), content: content, type: messageType, messages: messages });
26
25
  }
27
26
  ;
28
27
  serialize(input, config) {
@@ -46,25 +45,41 @@ class SendSMSCommand extends models_1.SensCommand {
46
45
  }
47
46
  exports.SendSMSCommand = SendSMSCommand;
48
47
  ;
49
- const textTrimming = (input) => input.trim();
50
- const phoneNumPretty = (input) => input.replace(/\-/gi, "");
51
- const messageTypeChecker = (input) => {
52
- const MAXIMUM = 2000;
53
- const euckrByte = input.split('').reduce((acc, text) => {
48
+ const trimText = (input) => input.trim();
49
+ const prettyPhoneNum = (input) => input.replace(/\-/gi, "");
50
+ const getTextBytes = (input) => {
51
+ return input.split('').reduce((acc, text) => {
54
52
  let byte = Buffer.from(text).length;
55
53
  let modulo = byte % 3;
56
54
  modulo ? acc += 1 : acc += 2;
57
55
  return acc;
58
56
  }, 0);
59
- if (!euckrByte)
57
+ };
58
+ const checkMessageType = (input) => {
59
+ const SMS_MAX = 90;
60
+ const LMS_MAX = 2000;
61
+ const euckrBytes = getTextBytes(input);
62
+ if (!euckrBytes)
60
63
  throw new util_error_handler_1.IngestkoreaError({
61
64
  code: 400, type: 'Bad Request',
62
65
  message: 'Invalid Request', description: `Please check input message`
63
66
  });
64
- if (euckrByte > MAXIMUM)
67
+ if (euckrBytes > LMS_MAX)
65
68
  throw new util_error_handler_1.IngestkoreaError({
66
69
  code: 400, type: 'Bad Request',
67
- message: 'Invalid Request', description: `Maximum message length is ${MAXIMUM}bytes`
70
+ message: 'Invalid Request', description: `Maximum message length is ${LMS_MAX}bytes`
68
71
  });
69
- return euckrByte > 80 ? 'LMS' : 'SMS';
72
+ return euckrBytes > SMS_MAX ? 'LMS' : 'SMS';
73
+ };
74
+ const resolveInputMessages = (messages) => {
75
+ let resolvedMessageType = 'SMS';
76
+ let resolvedMessages = messages.map(message => {
77
+ const resolvedContent = message.content != undefined ? trimText(message.content) : '';
78
+ const resolvedSubject = message.subject != undefined ? trimText(message.subject) : '';
79
+ const messageType = !!resolvedContent != false ? checkMessageType(resolvedContent) : 'SMS';
80
+ if (messageType === 'LMS')
81
+ resolvedMessageType = messageType;
82
+ return Object.assign(Object.assign({ to: prettyPhoneNum(message.to) }, (!!resolvedContent != false && { content: resolvedContent })), (!!resolvedSubject != false && messageType === 'LMS' && { subject: resolvedSubject }));
83
+ });
84
+ return { messages: resolvedMessages, messageType: resolvedMessageType };
70
85
  };
@@ -6,20 +6,15 @@ import { IngestkoreaError } from '@ingestkorea/util-error-handler';
6
6
  export class SendSMSCommand extends SensCommand {
7
7
  constructor(input) {
8
8
  super(input);
9
- const content = textTrimming(input.content);
10
- const messageType = messageTypeChecker(content);
9
+ const content = trimText(input.content);
10
+ const { messages, messageType: childMessageType } = resolveInputMessages(input.messages);
11
+ const messageType = childMessageType == 'LMS' ? childMessageType : checkMessageType(content);
11
12
  this.input = {
12
13
  ...input,
13
- from: phoneNumPretty(input.from),
14
+ from: prettyPhoneNum(input.from),
14
15
  content: content,
15
- type: input.type === messageType ? input.type : messageType,
16
- messages: input.messages.map(message => {
17
- return {
18
- to: phoneNumPretty(message.to),
19
- ...(message.content != undefined && { content: textTrimming(message.content) }),
20
- ...(message.subject != undefined && messageType === 'LMS' && { subject: textTrimming(message.subject) }),
21
- };
22
- })
16
+ type: messageType,
17
+ messages: messages
23
18
  };
24
19
  }
25
20
  ;
@@ -39,25 +34,45 @@ export class SendSMSCommand extends SensCommand {
39
34
  ;
40
35
  }
41
36
  ;
42
- const textTrimming = (input) => input.trim();
43
- const phoneNumPretty = (input) => input.replace(/\-/gi, "");
44
- const messageTypeChecker = (input) => {
45
- const MAXIMUM = 2000;
46
- const euckrByte = input.split('').reduce((acc, text) => {
37
+ const trimText = (input) => input.trim();
38
+ const prettyPhoneNum = (input) => input.replace(/\-/gi, "");
39
+ const getTextBytes = (input) => {
40
+ return input.split('').reduce((acc, text) => {
47
41
  let byte = Buffer.from(text).length;
48
42
  let modulo = byte % 3;
49
43
  modulo ? acc += 1 : acc += 2;
50
44
  return acc;
51
45
  }, 0);
52
- if (!euckrByte)
46
+ };
47
+ const checkMessageType = (input) => {
48
+ const SMS_MAX = 90;
49
+ const LMS_MAX = 2000;
50
+ const euckrBytes = getTextBytes(input);
51
+ if (!euckrBytes)
53
52
  throw new IngestkoreaError({
54
53
  code: 400, type: 'Bad Request',
55
54
  message: 'Invalid Request', description: `Please check input message`
56
55
  });
57
- if (euckrByte > MAXIMUM)
56
+ if (euckrBytes > LMS_MAX)
58
57
  throw new IngestkoreaError({
59
58
  code: 400, type: 'Bad Request',
60
- message: 'Invalid Request', description: `Maximum message length is ${MAXIMUM}bytes`
59
+ message: 'Invalid Request', description: `Maximum message length is ${LMS_MAX}bytes`
61
60
  });
62
- return euckrByte > 80 ? 'LMS' : 'SMS';
61
+ return euckrBytes > SMS_MAX ? 'LMS' : 'SMS';
62
+ };
63
+ const resolveInputMessages = (messages) => {
64
+ let resolvedMessageType = 'SMS';
65
+ let resolvedMessages = messages.map(message => {
66
+ const resolvedContent = message.content != undefined ? trimText(message.content) : '';
67
+ const resolvedSubject = message.subject != undefined ? trimText(message.subject) : '';
68
+ const messageType = !!resolvedContent != false ? checkMessageType(resolvedContent) : 'SMS';
69
+ if (messageType === 'LMS')
70
+ resolvedMessageType = messageType;
71
+ return {
72
+ to: prettyPhoneNum(message.to),
73
+ ...(!!resolvedContent != false && { content: resolvedContent }),
74
+ ...(!!resolvedSubject != false && messageType === 'LMS' && { subject: resolvedSubject }),
75
+ };
76
+ });
77
+ return { messages: resolvedMessages, messageType: resolvedMessageType };
63
78
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ingestkorea/client-sens",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "description": "INGESTKOREA SDK Naver Cloud Platform SENS Client for Node.js.",
5
5
  "main": "./dist-cjs/index.js",
6
6
  "module": "./dist-es/index.js",