@bubltec/mycota-sms 0.4.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/dist/fake.adapter.d.ts +12 -0
- package/dist/fake.adapter.d.ts.map +1 -0
- package/dist/fake.adapter.js +19 -0
- package/dist/fake.adapter.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/phone.d.ts +6 -0
- package/dist/phone.d.ts.map +1 -0
- package/dist/phone.js +17 -0
- package/dist/phone.js.map +1 -0
- package/dist/ports.d.ts +30 -0
- package/dist/ports.d.ts.map +1 -0
- package/dist/ports.js +2 -0
- package/dist/ports.js.map +1 -0
- package/dist/sms.spec.d.ts +2 -0
- package/dist/sms.spec.d.ts.map +1 -0
- package/dist/sms.spec.js +35 -0
- package/dist/sms.spec.js.map +1 -0
- package/dist/sns.adapter.d.ts +17 -0
- package/dist/sns.adapter.d.ts.map +1 -0
- package/dist/sns.adapter.js +35 -0
- package/dist/sns.adapter.js.map +1 -0
- package/package.json +35 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Genome
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { SendSmsResult, SmsMessage, SmsSender } from './ports.js';
|
|
2
|
+
/**
|
|
3
|
+
* Process-local SMS for tests and local boot. Messages stay in `sent`.
|
|
4
|
+
*/
|
|
5
|
+
export declare class FakeSmsSender implements SmsSender {
|
|
6
|
+
readonly sent: Array<SmsMessage & {
|
|
7
|
+
to: string;
|
|
8
|
+
}>;
|
|
9
|
+
private seq;
|
|
10
|
+
send(message: SmsMessage): Promise<SendSmsResult>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=fake.adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fake.adapter.d.ts","sourceRoot":"","sources":["../src/fake.adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAGvE;;GAEG;AACH,qBAAa,aAAc,YAAW,SAAS;IAC7C,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,UAAU,GAAG;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC,CAAM;IACvD,OAAO,CAAC,GAAG,CAAK;IAEV,IAAI,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,aAAa,CAAC;CAQxD"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { toE164 } from './phone.js';
|
|
2
|
+
/**
|
|
3
|
+
* Process-local SMS for tests and local boot. Messages stay in `sent`.
|
|
4
|
+
*/
|
|
5
|
+
export class FakeSmsSender {
|
|
6
|
+
sent = [];
|
|
7
|
+
seq = 0;
|
|
8
|
+
async send(message) {
|
|
9
|
+
const to = toE164(message.to);
|
|
10
|
+
if (!to.startsWith('+') || to.length < 8)
|
|
11
|
+
throw new Error('sms to must be an E.164 phone number');
|
|
12
|
+
if (!message.body)
|
|
13
|
+
throw new Error('sms body is required');
|
|
14
|
+
this.seq += 1;
|
|
15
|
+
this.sent.push({ ...message, to });
|
|
16
|
+
return { messageId: `fake_sms_${this.seq}` };
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=fake.adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fake.adapter.js","sourceRoot":"","sources":["../src/fake.adapter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEpC;;GAEG;AACH,MAAM,OAAO,aAAa;IACf,IAAI,GAAuC,EAAE,CAAC;IAC/C,GAAG,GAAG,CAAC,CAAC;IAEhB,KAAK,CAAC,IAAI,CAAC,OAAmB;QAC5B,MAAM,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAC9B,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;QAClG,IAAI,CAAC,OAAO,CAAC,IAAI;YAAE,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;QAC3D,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;QACd,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC;QACnC,OAAO,EAAE,SAAS,EAAE,YAAY,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;IAC/C,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { SendSmsResult, SmsMessage, SmsSender, SnsSmsClient } from './ports.js';
|
|
2
|
+
export { toE164 } from './phone.js';
|
|
3
|
+
export { FakeSmsSender } from './fake.adapter.js';
|
|
4
|
+
export { SnsSmsSender, type SnsSmsSenderOptions } from './sns.adapter.js';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AACrF,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,KAAK,mBAAmB,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,YAAY,EAA4B,MAAM,kBAAkB,CAAC"}
|
package/dist/phone.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"phone.d.ts","sourceRoot":"","sources":["../src/phone.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAO1C"}
|
package/dist/phone.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalize a phone number to E.164 for SNS. Bare 10-digit US numbers
|
|
3
|
+
* become `+1…`. Already-prefixed values are left as digits-plus-plus only.
|
|
4
|
+
*/
|
|
5
|
+
export function toE164(raw) {
|
|
6
|
+
const digits = raw.replace(/[^\d+]/g, '');
|
|
7
|
+
if (!digits)
|
|
8
|
+
return '';
|
|
9
|
+
if (digits.startsWith('+'))
|
|
10
|
+
return digits;
|
|
11
|
+
if (digits.length === 10)
|
|
12
|
+
return `+1${digits}`;
|
|
13
|
+
if (digits.length === 11 && digits.startsWith('1'))
|
|
14
|
+
return `+${digits}`;
|
|
15
|
+
return `+${digits}`;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=phone.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"phone.js","sourceRoot":"","sources":["../src/phone.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,MAAM,CAAC,GAAW;IAChC,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;IAC1C,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,CAAC;IACvB,IAAI,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,OAAO,MAAM,CAAC;IAC1C,IAAI,MAAM,CAAC,MAAM,KAAK,EAAE;QAAE,OAAO,KAAK,MAAM,EAAE,CAAC;IAC/C,IAAI,MAAM,CAAC,MAAM,KAAK,EAAE,IAAI,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,OAAO,IAAI,MAAM,EAAE,CAAC;IACxE,OAAO,IAAI,MAAM,EAAE,CAAC;AACtB,CAAC"}
|
package/dist/ports.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export interface SmsMessage {
|
|
2
|
+
to: string;
|
|
3
|
+
body: string;
|
|
4
|
+
/** Optional sender ID — supported in some SNS regions only. */
|
|
5
|
+
senderId?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface SendSmsResult {
|
|
8
|
+
messageId: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Outbound transactional SMS. Inner layers never import SNS — they send a
|
|
12
|
+
* message and get a provider id.
|
|
13
|
+
*/
|
|
14
|
+
export interface SmsSender {
|
|
15
|
+
send(message: SmsMessage): Promise<SendSmsResult>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Narrow SNS SMS surface so `@bubltec/mycota-sms` does not take an AWS SDK
|
|
19
|
+
* dependency. The consuming app constructs SNS (or a test double).
|
|
20
|
+
*/
|
|
21
|
+
export interface SnsSmsClient {
|
|
22
|
+
publishSms(input: {
|
|
23
|
+
phoneNumber: string;
|
|
24
|
+
message: string;
|
|
25
|
+
senderId?: string;
|
|
26
|
+
}): Promise<{
|
|
27
|
+
messageId: string;
|
|
28
|
+
}>;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=ports.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ports.d.ts","sourceRoot":"","sources":["../src/ports.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,+DAA+D;IAC/D,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB,IAAI,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;CACnD;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,UAAU,CAAC,KAAK,EAAE;QAChB,WAAW,EAAE,MAAM,CAAC;QACpB,OAAO,EAAE,MAAM,CAAC;QAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,GAAG,OAAO,CAAC;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACpC"}
|
package/dist/ports.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ports.js","sourceRoot":"","sources":["../src/ports.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sms.spec.d.ts","sourceRoot":"","sources":["../src/sms.spec.ts"],"names":[],"mappings":""}
|
package/dist/sms.spec.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { FakeSmsSender } from './fake.adapter.js';
|
|
3
|
+
import { toE164 } from './phone.js';
|
|
4
|
+
import { SnsSmsSender } from './index.js';
|
|
5
|
+
describe('toE164', () => {
|
|
6
|
+
it('normalizes US numbers', () => {
|
|
7
|
+
expect(toE164('555-123-4567')).toBe('+15551234567');
|
|
8
|
+
expect(toE164('15551234567')).toBe('+15551234567');
|
|
9
|
+
expect(toE164('+15551234567')).toBe('+15551234567');
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
describe('FakeSmsSender', () => {
|
|
13
|
+
it('records normalized destinations', async () => {
|
|
14
|
+
const sms = new FakeSmsSender();
|
|
15
|
+
const result = await sms.send({ to: '5551234567', body: 'Accept: https://example.com' });
|
|
16
|
+
expect(result.messageId).toBe('fake_sms_1');
|
|
17
|
+
expect(sms.sent[0]?.to).toBe('+15551234567');
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
describe('SnsSmsSender', () => {
|
|
21
|
+
it('publishes E.164 through the injected client', async () => {
|
|
22
|
+
const client = {
|
|
23
|
+
publishSms: vi.fn(async (input) => {
|
|
24
|
+
expect(input.phoneNumber).toBe('+15551234567');
|
|
25
|
+
expect(input.message).toBe('[local] Accept now');
|
|
26
|
+
expect(input.senderId).toBe('Sloth');
|
|
27
|
+
return { messageId: 'sns_1' };
|
|
28
|
+
}),
|
|
29
|
+
};
|
|
30
|
+
const sender = new SnsSmsSender(client, { stage: 'local', senderId: 'Sloth' });
|
|
31
|
+
const result = await sender.send({ to: '555-123-4567', body: 'Accept now' });
|
|
32
|
+
expect(result.messageId).toBe('sns_1');
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
//# sourceMappingURL=sms.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sms.spec.js","sourceRoot":"","sources":["../src/sms.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,YAAY,EAAqB,MAAM,YAAY,CAAC;AAE7D,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE;IACtB,EAAE,CAAC,uBAAuB,EAAE,GAAG,EAAE;QAC/B,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QACpD,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QACnD,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IACtD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,EAAE,CAAC,iCAAiC,EAAE,KAAK,IAAI,EAAE;QAC/C,MAAM,GAAG,GAAG,IAAI,aAAa,EAAE,CAAC;QAChC,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,6BAA6B,EAAE,CAAC,CAAC;QACzF,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAC5C,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,EAAE,CAAC,6CAA6C,EAAE,KAAK,IAAI,EAAE;QAC3D,MAAM,MAAM,GAAiB;YAC3B,UAAU,EAAE,EAAE,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;gBAChC,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;gBAC/C,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;gBACjD,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;gBACrC,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC;YAChC,CAAC,CAAC;SACH,CAAC;QACF,MAAM,MAAM,GAAG,IAAI,YAAY,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;QAC/E,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,cAAc,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC;QAC7E,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { SendSmsResult, SmsMessage, SmsSender, SnsSmsClient } from './ports.js';
|
|
2
|
+
export interface SnsSmsSenderOptions {
|
|
3
|
+
/** When not `prod`, prefix bodies with `[stage] `. */
|
|
4
|
+
stage?: string;
|
|
5
|
+
senderId?: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* SNS SMS adapter. The consuming app passes a narrow client so this package
|
|
9
|
+
* never imports `@aws-sdk/client-sns`.
|
|
10
|
+
*/
|
|
11
|
+
export declare class SnsSmsSender implements SmsSender {
|
|
12
|
+
private readonly client;
|
|
13
|
+
private readonly options;
|
|
14
|
+
constructor(client: SnsSmsClient, options?: SnsSmsSenderOptions);
|
|
15
|
+
send(message: SmsMessage): Promise<SendSmsResult>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=sns.adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sns.adapter.d.ts","sourceRoot":"","sources":["../src/sns.adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAGrF,MAAM,WAAW,mBAAmB;IAClC,sDAAsD;IACtD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAOD;;;GAGG;AACH,qBAAa,YAAa,YAAW,SAAS;IAE1C,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,OAAO;gBADP,MAAM,EAAE,YAAY,EACpB,OAAO,GAAE,mBAAwB;IAG9C,IAAI,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,aAAa,CAAC;CAexD"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { toE164 } from './phone.js';
|
|
2
|
+
function bodyFor(body, stage) {
|
|
3
|
+
if (!stage || stage === 'prod')
|
|
4
|
+
return body;
|
|
5
|
+
return `[${stage}] ${body}`;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* SNS SMS adapter. The consuming app passes a narrow client so this package
|
|
9
|
+
* never imports `@aws-sdk/client-sns`.
|
|
10
|
+
*/
|
|
11
|
+
export class SnsSmsSender {
|
|
12
|
+
client;
|
|
13
|
+
options;
|
|
14
|
+
constructor(client, options = {}) {
|
|
15
|
+
this.client = client;
|
|
16
|
+
this.options = options;
|
|
17
|
+
}
|
|
18
|
+
async send(message) {
|
|
19
|
+
const phoneNumber = toE164(message.to);
|
|
20
|
+
if (!phoneNumber.startsWith('+') || phoneNumber.length < 8) {
|
|
21
|
+
throw new Error('sms to must be an E.164 phone number');
|
|
22
|
+
}
|
|
23
|
+
if (!message.body)
|
|
24
|
+
throw new Error('sms body is required');
|
|
25
|
+
const result = await this.client.publishSms({
|
|
26
|
+
phoneNumber,
|
|
27
|
+
message: bodyFor(message.body, this.options.stage),
|
|
28
|
+
senderId: message.senderId ?? this.options.senderId,
|
|
29
|
+
});
|
|
30
|
+
if (!result.messageId)
|
|
31
|
+
throw new Error('SNS did not return a message id');
|
|
32
|
+
return { messageId: result.messageId };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=sns.adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sns.adapter.js","sourceRoot":"","sources":["../src/sns.adapter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAQpC,SAAS,OAAO,CAAC,IAAY,EAAE,KAAc;IAC3C,IAAI,CAAC,KAAK,IAAI,KAAK,KAAK,MAAM;QAAE,OAAO,IAAI,CAAC;IAC5C,OAAO,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;AAC9B,CAAC;AAED;;;GAGG;AACH,MAAM,OAAO,YAAY;IAEJ;IACA;IAFnB,YACmB,MAAoB,EACpB,UAA+B,EAAE;QADjC,WAAM,GAAN,MAAM,CAAc;QACpB,YAAO,GAAP,OAAO,CAA0B;IACjD,CAAC;IAEJ,KAAK,CAAC,IAAI,CAAC,OAAmB;QAC5B,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QACvC,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC3D,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;QAC1D,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,IAAI;YAAE,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;QAE3D,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC;YAC1C,WAAW;YACX,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;YAClD,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ;SACpD,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,CAAC,SAAS;YAAE,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;QAC1E,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC;IACzC,CAAC;CACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bubltec/mycota-sms",
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@types/node": "^22.10.0",
|
|
21
|
+
"typescript": "^5.8.0",
|
|
22
|
+
"vitest": "^2.1.0"
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "https://github.com/bubltec/mycota",
|
|
27
|
+
"directory": "packages/sms"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsc -b",
|
|
31
|
+
"typecheck": "tsc -b --noEmit",
|
|
32
|
+
"lint": "oxlint -c ../../.oxlintrc.json src",
|
|
33
|
+
"test": "vitest run"
|
|
34
|
+
}
|
|
35
|
+
}
|