@bymax-one/nest-notification 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/CHANGELOG.md +70 -0
- package/LICENSE +21 -0
- package/README.md +785 -0
- package/dist/react/index.cjs +225 -0
- package/dist/react/index.d.cts +105 -0
- package/dist/react/index.d.ts +105 -0
- package/dist/react/index.mjs +222 -0
- package/dist/server/index.cjs +2087 -0
- package/dist/server/index.d.cts +2155 -0
- package/dist/server/index.d.ts +2155 -0
- package/dist/server/index.mjs +2067 -0
- package/dist/shared/index.cjs +49 -0
- package/dist/shared/index.d.cts +138 -0
- package/dist/shared/index.d.ts +138 -0
- package/dist/shared/index.mjs +46 -0
- package/package.json +244 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/shared/constants/error-codes.ts
|
|
4
|
+
var NOTIFICATION_ERROR_CODES = {
|
|
5
|
+
EMAIL_PROVIDER_NOT_CONFIGURED: "notification.email_provider_not_configured",
|
|
6
|
+
EMAIL_SEND_FAILED: "notification.email_send_failed",
|
|
7
|
+
EMAIL_ATTACHMENTS_TOO_LARGE: "notification.email_attachments_too_large",
|
|
8
|
+
EMAIL_INVALID_RECIPIENT: "notification.email_invalid_recipient",
|
|
9
|
+
/** The email payload carries neither a `template` nor a `subject` + `html` body source. */
|
|
10
|
+
EMAIL_MISSING_BODY: "notification.email_missing_body",
|
|
11
|
+
TEMPLATE_NOT_FOUND: "notification.template_not_found",
|
|
12
|
+
TEMPLATE_RENDER_FAILED: "notification.template_render_failed",
|
|
13
|
+
OTP_STORAGE_NOT_CONFIGURED: "notification.otp_storage_not_configured",
|
|
14
|
+
OTP_EMAIL_DELIVERY_NOT_CONFIGURED: "notification.otp_email_delivery_not_configured",
|
|
15
|
+
OTP_COOLDOWN_ACTIVE: "notification.otp_cooldown_active",
|
|
16
|
+
OTP_NOT_FOUND: "notification.otp_not_found",
|
|
17
|
+
OTP_EXPIRED: "notification.otp_expired",
|
|
18
|
+
OTP_MAX_ATTEMPTS_EXCEEDED: "notification.otp_max_attempts_exceeded",
|
|
19
|
+
OTP_INVALID_CODE: "notification.otp_invalid_code",
|
|
20
|
+
OTP_INVALID_LENGTH: "notification.otp_invalid_length",
|
|
21
|
+
SMS_PROVIDER_NOT_CONFIGURED: "notification.sms_provider_not_configured",
|
|
22
|
+
SMS_SEND_FAILED: "notification.sms_send_failed",
|
|
23
|
+
SMS_INVALID_RECIPIENT: "notification.sms_invalid_recipient",
|
|
24
|
+
PUSH_PROVIDER_NOT_CONFIGURED: "notification.push_provider_not_configured",
|
|
25
|
+
PUSH_SEND_FAILED: "notification.push_send_failed",
|
|
26
|
+
AUDIT_LOG_FAILED: "notification.audit_log_failed",
|
|
27
|
+
CHANNEL_DISABLED: "notification.channel_disabled"
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// src/shared/constants/default-ttls.ts
|
|
31
|
+
var DEFAULT_TTLS = {
|
|
32
|
+
/** Email verification: 1h — lets the user check their inbox at leisure. */
|
|
33
|
+
OTP_EMAIL_VERIFICATION_SECONDS: 3600,
|
|
34
|
+
/** Password reset: 10min — short window limits exposure of a sensitive flow. */
|
|
35
|
+
OTP_PASSWORD_RESET_SECONDS: 600,
|
|
36
|
+
/** MFA out-of-band: 5min — tight window for an interactive challenge. */
|
|
37
|
+
OTP_MFA_OOB_SECONDS: 300,
|
|
38
|
+
/** Phone verification: 10min — covers SMS delivery latency. */
|
|
39
|
+
OTP_PHONE_VERIFICATION_SECONDS: 600,
|
|
40
|
+
/** Magic link: 15min — slightly longer; a URL is often opened on another device. */
|
|
41
|
+
OTP_MAGIC_LINK_SECONDS: 900,
|
|
42
|
+
/** Resend cooldown: 60s — throttles repeated sends to the same recipient. */
|
|
43
|
+
RESEND_COOLDOWN_SECONDS: 60,
|
|
44
|
+
/** Generic fallback: 10min — used when no purpose-specific TTL applies. */
|
|
45
|
+
OTP_GENERIC_SECONDS: 600
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
exports.DEFAULT_TTLS = DEFAULT_TTLS;
|
|
49
|
+
exports.NOTIFICATION_ERROR_CODES = NOTIFICATION_ERROR_CODES;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Public `OtpPurpose` string union for the shared subpath.
|
|
3
|
+
* @layer shared
|
|
4
|
+
*
|
|
5
|
+
* Zero-dependency type importable from backend and frontend alike (e.g. to label
|
|
6
|
+
* an OTP flow in the UI). No runtime code.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Purpose of an OTP flow.
|
|
10
|
+
*
|
|
11
|
+
* The five canonical purposes are listed as string literals so editors offer
|
|
12
|
+
* autocompletion, while the `(string & {})` escape hatch keeps the union open to
|
|
13
|
+
* custom purposes (e.g. `'invoice_verification'`) without losing that
|
|
14
|
+
* autocompletion — a widening to a bare `string` would drop the literal hints.
|
|
15
|
+
*
|
|
16
|
+
* - `email_verification` — confirm ownership of an email address.
|
|
17
|
+
* - `password_reset` — authorize a password change.
|
|
18
|
+
* - `mfa_oob` — out-of-band multi-factor challenge.
|
|
19
|
+
* - `phone_verification` — confirm a phone number; delivered manually until an SMS channel exists.
|
|
20
|
+
* - `magic_link` — long, single-use token delivered as a URL rather than typed.
|
|
21
|
+
*/
|
|
22
|
+
type OtpPurpose = 'email_verification' | 'password_reset' | 'mfa_oob' | 'phone_verification' | 'magic_link' | (string & {});
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @fileoverview Public `NotificationChannel` union for the shared subpath.
|
|
26
|
+
* @layer shared
|
|
27
|
+
*
|
|
28
|
+
* Zero-dependency type. `'sms'` and `'push'` are part of the union so consumers can
|
|
29
|
+
* plan dispatch code paths against a stable shape, even though no service serves them.
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* A delivery/identity channel a notification can flow through.
|
|
33
|
+
*
|
|
34
|
+
* - `email` — transactional email.
|
|
35
|
+
* - `otp` — one-time-passcode lifecycle (generate / verify / consume).
|
|
36
|
+
* - `sms` — text message (declared; no service behind it).
|
|
37
|
+
* - `push` — device push notification (declared; no service behind it).
|
|
38
|
+
*/
|
|
39
|
+
type NotificationChannel = 'email' | 'otp' | 'sms' | 'push';
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @fileoverview Public error-response envelope for the shared subpath.
|
|
43
|
+
* @layer shared
|
|
44
|
+
*
|
|
45
|
+
* Zero-dependency type mirroring the body shape `NotificationException` emits on
|
|
46
|
+
* the server, so a frontend can type the parsed JSON and match on `error.code`.
|
|
47
|
+
*/
|
|
48
|
+
/**
|
|
49
|
+
* The JSON envelope every `NotificationException` serializes to.
|
|
50
|
+
*
|
|
51
|
+
* The frontend matches on `error.code` (a stable identifier from
|
|
52
|
+
* `NOTIFICATION_ERROR_CODES`) to render a localized message; `error.message` is
|
|
53
|
+
* the English default; `error.details` carries optional structured context and
|
|
54
|
+
* is `null` when absent.
|
|
55
|
+
*/
|
|
56
|
+
interface NotificationErrorResponse {
|
|
57
|
+
error: {
|
|
58
|
+
code: string;
|
|
59
|
+
message: string;
|
|
60
|
+
details: Record<string, unknown> | null;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @fileoverview Public error-code catalog for the shared subpath.
|
|
66
|
+
* @layer shared
|
|
67
|
+
*
|
|
68
|
+
* Zero-dependency map of every notification error code. The string values are
|
|
69
|
+
* the single source of truth a frontend matches against; the server's
|
|
70
|
+
* `NOTIFICATION_ERROR_DEFINITIONS` re-states the same codes (with HTTP status +
|
|
71
|
+
* message) and a CI gate asserts the two stay byte-for-byte identical.
|
|
72
|
+
*/
|
|
73
|
+
/**
|
|
74
|
+
* Stable error-code identifiers, keyed by their symbolic name.
|
|
75
|
+
*
|
|
76
|
+
* Values are namespaced under `notification.*` and never change once published —
|
|
77
|
+
* consumers branch on them to localize messages. The 22 entries cover the email,
|
|
78
|
+
* template, OTP, SMS, push, audit, and channel-config failure surfaces.
|
|
79
|
+
*/
|
|
80
|
+
declare const NOTIFICATION_ERROR_CODES: {
|
|
81
|
+
readonly EMAIL_PROVIDER_NOT_CONFIGURED: "notification.email_provider_not_configured";
|
|
82
|
+
readonly EMAIL_SEND_FAILED: "notification.email_send_failed";
|
|
83
|
+
readonly EMAIL_ATTACHMENTS_TOO_LARGE: "notification.email_attachments_too_large";
|
|
84
|
+
readonly EMAIL_INVALID_RECIPIENT: "notification.email_invalid_recipient";
|
|
85
|
+
/** The email payload carries neither a `template` nor a `subject` + `html` body source. */
|
|
86
|
+
readonly EMAIL_MISSING_BODY: "notification.email_missing_body";
|
|
87
|
+
readonly TEMPLATE_NOT_FOUND: "notification.template_not_found";
|
|
88
|
+
readonly TEMPLATE_RENDER_FAILED: "notification.template_render_failed";
|
|
89
|
+
readonly OTP_STORAGE_NOT_CONFIGURED: "notification.otp_storage_not_configured";
|
|
90
|
+
readonly OTP_EMAIL_DELIVERY_NOT_CONFIGURED: "notification.otp_email_delivery_not_configured";
|
|
91
|
+
readonly OTP_COOLDOWN_ACTIVE: "notification.otp_cooldown_active";
|
|
92
|
+
readonly OTP_NOT_FOUND: "notification.otp_not_found";
|
|
93
|
+
readonly OTP_EXPIRED: "notification.otp_expired";
|
|
94
|
+
readonly OTP_MAX_ATTEMPTS_EXCEEDED: "notification.otp_max_attempts_exceeded";
|
|
95
|
+
readonly OTP_INVALID_CODE: "notification.otp_invalid_code";
|
|
96
|
+
readonly OTP_INVALID_LENGTH: "notification.otp_invalid_length";
|
|
97
|
+
readonly SMS_PROVIDER_NOT_CONFIGURED: "notification.sms_provider_not_configured";
|
|
98
|
+
readonly SMS_SEND_FAILED: "notification.sms_send_failed";
|
|
99
|
+
readonly SMS_INVALID_RECIPIENT: "notification.sms_invalid_recipient";
|
|
100
|
+
readonly PUSH_PROVIDER_NOT_CONFIGURED: "notification.push_provider_not_configured";
|
|
101
|
+
readonly PUSH_SEND_FAILED: "notification.push_send_failed";
|
|
102
|
+
readonly AUDIT_LOG_FAILED: "notification.audit_log_failed";
|
|
103
|
+
readonly CHANNEL_DISABLED: "notification.channel_disabled";
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* The literal-union type of every value in {@link NOTIFICATION_ERROR_CODES}.
|
|
107
|
+
*/
|
|
108
|
+
type NotificationErrorCode = (typeof NOTIFICATION_ERROR_CODES)[keyof typeof NOTIFICATION_ERROR_CODES];
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* @fileoverview Recommended OTP/cooldown TTLs for the shared subpath.
|
|
112
|
+
* @layer shared
|
|
113
|
+
*
|
|
114
|
+
* Zero-dependency reference values a consumer can wire into per-purpose OTP
|
|
115
|
+
* config (or display as "expires in N minutes" in the UI). They are suggestions,
|
|
116
|
+
* not enforced defaults — the server defaults live in the OTP channel options.
|
|
117
|
+
*/
|
|
118
|
+
/**
|
|
119
|
+
* Recommended time-to-live values (in seconds), with rationale per entry.
|
|
120
|
+
*/
|
|
121
|
+
declare const DEFAULT_TTLS: {
|
|
122
|
+
/** Email verification: 1h — lets the user check their inbox at leisure. */
|
|
123
|
+
readonly OTP_EMAIL_VERIFICATION_SECONDS: 3600;
|
|
124
|
+
/** Password reset: 10min — short window limits exposure of a sensitive flow. */
|
|
125
|
+
readonly OTP_PASSWORD_RESET_SECONDS: 600;
|
|
126
|
+
/** MFA out-of-band: 5min — tight window for an interactive challenge. */
|
|
127
|
+
readonly OTP_MFA_OOB_SECONDS: 300;
|
|
128
|
+
/** Phone verification: 10min — covers SMS delivery latency. */
|
|
129
|
+
readonly OTP_PHONE_VERIFICATION_SECONDS: 600;
|
|
130
|
+
/** Magic link: 15min — slightly longer; a URL is often opened on another device. */
|
|
131
|
+
readonly OTP_MAGIC_LINK_SECONDS: 900;
|
|
132
|
+
/** Resend cooldown: 60s — throttles repeated sends to the same recipient. */
|
|
133
|
+
readonly RESEND_COOLDOWN_SECONDS: 60;
|
|
134
|
+
/** Generic fallback: 10min — used when no purpose-specific TTL applies. */
|
|
135
|
+
readonly OTP_GENERIC_SECONDS: 600;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
export { DEFAULT_TTLS, NOTIFICATION_ERROR_CODES, type NotificationChannel, type NotificationErrorCode, type NotificationErrorResponse, type OtpPurpose };
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Public `OtpPurpose` string union for the shared subpath.
|
|
3
|
+
* @layer shared
|
|
4
|
+
*
|
|
5
|
+
* Zero-dependency type importable from backend and frontend alike (e.g. to label
|
|
6
|
+
* an OTP flow in the UI). No runtime code.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Purpose of an OTP flow.
|
|
10
|
+
*
|
|
11
|
+
* The five canonical purposes are listed as string literals so editors offer
|
|
12
|
+
* autocompletion, while the `(string & {})` escape hatch keeps the union open to
|
|
13
|
+
* custom purposes (e.g. `'invoice_verification'`) without losing that
|
|
14
|
+
* autocompletion — a widening to a bare `string` would drop the literal hints.
|
|
15
|
+
*
|
|
16
|
+
* - `email_verification` — confirm ownership of an email address.
|
|
17
|
+
* - `password_reset` — authorize a password change.
|
|
18
|
+
* - `mfa_oob` — out-of-band multi-factor challenge.
|
|
19
|
+
* - `phone_verification` — confirm a phone number; delivered manually until an SMS channel exists.
|
|
20
|
+
* - `magic_link` — long, single-use token delivered as a URL rather than typed.
|
|
21
|
+
*/
|
|
22
|
+
type OtpPurpose = 'email_verification' | 'password_reset' | 'mfa_oob' | 'phone_verification' | 'magic_link' | (string & {});
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @fileoverview Public `NotificationChannel` union for the shared subpath.
|
|
26
|
+
* @layer shared
|
|
27
|
+
*
|
|
28
|
+
* Zero-dependency type. `'sms'` and `'push'` are part of the union so consumers can
|
|
29
|
+
* plan dispatch code paths against a stable shape, even though no service serves them.
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* A delivery/identity channel a notification can flow through.
|
|
33
|
+
*
|
|
34
|
+
* - `email` — transactional email.
|
|
35
|
+
* - `otp` — one-time-passcode lifecycle (generate / verify / consume).
|
|
36
|
+
* - `sms` — text message (declared; no service behind it).
|
|
37
|
+
* - `push` — device push notification (declared; no service behind it).
|
|
38
|
+
*/
|
|
39
|
+
type NotificationChannel = 'email' | 'otp' | 'sms' | 'push';
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @fileoverview Public error-response envelope for the shared subpath.
|
|
43
|
+
* @layer shared
|
|
44
|
+
*
|
|
45
|
+
* Zero-dependency type mirroring the body shape `NotificationException` emits on
|
|
46
|
+
* the server, so a frontend can type the parsed JSON and match on `error.code`.
|
|
47
|
+
*/
|
|
48
|
+
/**
|
|
49
|
+
* The JSON envelope every `NotificationException` serializes to.
|
|
50
|
+
*
|
|
51
|
+
* The frontend matches on `error.code` (a stable identifier from
|
|
52
|
+
* `NOTIFICATION_ERROR_CODES`) to render a localized message; `error.message` is
|
|
53
|
+
* the English default; `error.details` carries optional structured context and
|
|
54
|
+
* is `null` when absent.
|
|
55
|
+
*/
|
|
56
|
+
interface NotificationErrorResponse {
|
|
57
|
+
error: {
|
|
58
|
+
code: string;
|
|
59
|
+
message: string;
|
|
60
|
+
details: Record<string, unknown> | null;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @fileoverview Public error-code catalog for the shared subpath.
|
|
66
|
+
* @layer shared
|
|
67
|
+
*
|
|
68
|
+
* Zero-dependency map of every notification error code. The string values are
|
|
69
|
+
* the single source of truth a frontend matches against; the server's
|
|
70
|
+
* `NOTIFICATION_ERROR_DEFINITIONS` re-states the same codes (with HTTP status +
|
|
71
|
+
* message) and a CI gate asserts the two stay byte-for-byte identical.
|
|
72
|
+
*/
|
|
73
|
+
/**
|
|
74
|
+
* Stable error-code identifiers, keyed by their symbolic name.
|
|
75
|
+
*
|
|
76
|
+
* Values are namespaced under `notification.*` and never change once published —
|
|
77
|
+
* consumers branch on them to localize messages. The 22 entries cover the email,
|
|
78
|
+
* template, OTP, SMS, push, audit, and channel-config failure surfaces.
|
|
79
|
+
*/
|
|
80
|
+
declare const NOTIFICATION_ERROR_CODES: {
|
|
81
|
+
readonly EMAIL_PROVIDER_NOT_CONFIGURED: "notification.email_provider_not_configured";
|
|
82
|
+
readonly EMAIL_SEND_FAILED: "notification.email_send_failed";
|
|
83
|
+
readonly EMAIL_ATTACHMENTS_TOO_LARGE: "notification.email_attachments_too_large";
|
|
84
|
+
readonly EMAIL_INVALID_RECIPIENT: "notification.email_invalid_recipient";
|
|
85
|
+
/** The email payload carries neither a `template` nor a `subject` + `html` body source. */
|
|
86
|
+
readonly EMAIL_MISSING_BODY: "notification.email_missing_body";
|
|
87
|
+
readonly TEMPLATE_NOT_FOUND: "notification.template_not_found";
|
|
88
|
+
readonly TEMPLATE_RENDER_FAILED: "notification.template_render_failed";
|
|
89
|
+
readonly OTP_STORAGE_NOT_CONFIGURED: "notification.otp_storage_not_configured";
|
|
90
|
+
readonly OTP_EMAIL_DELIVERY_NOT_CONFIGURED: "notification.otp_email_delivery_not_configured";
|
|
91
|
+
readonly OTP_COOLDOWN_ACTIVE: "notification.otp_cooldown_active";
|
|
92
|
+
readonly OTP_NOT_FOUND: "notification.otp_not_found";
|
|
93
|
+
readonly OTP_EXPIRED: "notification.otp_expired";
|
|
94
|
+
readonly OTP_MAX_ATTEMPTS_EXCEEDED: "notification.otp_max_attempts_exceeded";
|
|
95
|
+
readonly OTP_INVALID_CODE: "notification.otp_invalid_code";
|
|
96
|
+
readonly OTP_INVALID_LENGTH: "notification.otp_invalid_length";
|
|
97
|
+
readonly SMS_PROVIDER_NOT_CONFIGURED: "notification.sms_provider_not_configured";
|
|
98
|
+
readonly SMS_SEND_FAILED: "notification.sms_send_failed";
|
|
99
|
+
readonly SMS_INVALID_RECIPIENT: "notification.sms_invalid_recipient";
|
|
100
|
+
readonly PUSH_PROVIDER_NOT_CONFIGURED: "notification.push_provider_not_configured";
|
|
101
|
+
readonly PUSH_SEND_FAILED: "notification.push_send_failed";
|
|
102
|
+
readonly AUDIT_LOG_FAILED: "notification.audit_log_failed";
|
|
103
|
+
readonly CHANNEL_DISABLED: "notification.channel_disabled";
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* The literal-union type of every value in {@link NOTIFICATION_ERROR_CODES}.
|
|
107
|
+
*/
|
|
108
|
+
type NotificationErrorCode = (typeof NOTIFICATION_ERROR_CODES)[keyof typeof NOTIFICATION_ERROR_CODES];
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* @fileoverview Recommended OTP/cooldown TTLs for the shared subpath.
|
|
112
|
+
* @layer shared
|
|
113
|
+
*
|
|
114
|
+
* Zero-dependency reference values a consumer can wire into per-purpose OTP
|
|
115
|
+
* config (or display as "expires in N minutes" in the UI). They are suggestions,
|
|
116
|
+
* not enforced defaults — the server defaults live in the OTP channel options.
|
|
117
|
+
*/
|
|
118
|
+
/**
|
|
119
|
+
* Recommended time-to-live values (in seconds), with rationale per entry.
|
|
120
|
+
*/
|
|
121
|
+
declare const DEFAULT_TTLS: {
|
|
122
|
+
/** Email verification: 1h — lets the user check their inbox at leisure. */
|
|
123
|
+
readonly OTP_EMAIL_VERIFICATION_SECONDS: 3600;
|
|
124
|
+
/** Password reset: 10min — short window limits exposure of a sensitive flow. */
|
|
125
|
+
readonly OTP_PASSWORD_RESET_SECONDS: 600;
|
|
126
|
+
/** MFA out-of-band: 5min — tight window for an interactive challenge. */
|
|
127
|
+
readonly OTP_MFA_OOB_SECONDS: 300;
|
|
128
|
+
/** Phone verification: 10min — covers SMS delivery latency. */
|
|
129
|
+
readonly OTP_PHONE_VERIFICATION_SECONDS: 600;
|
|
130
|
+
/** Magic link: 15min — slightly longer; a URL is often opened on another device. */
|
|
131
|
+
readonly OTP_MAGIC_LINK_SECONDS: 900;
|
|
132
|
+
/** Resend cooldown: 60s — throttles repeated sends to the same recipient. */
|
|
133
|
+
readonly RESEND_COOLDOWN_SECONDS: 60;
|
|
134
|
+
/** Generic fallback: 10min — used when no purpose-specific TTL applies. */
|
|
135
|
+
readonly OTP_GENERIC_SECONDS: 600;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
export { DEFAULT_TTLS, NOTIFICATION_ERROR_CODES, type NotificationChannel, type NotificationErrorCode, type NotificationErrorResponse, type OtpPurpose };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// src/shared/constants/error-codes.ts
|
|
2
|
+
var NOTIFICATION_ERROR_CODES = {
|
|
3
|
+
EMAIL_PROVIDER_NOT_CONFIGURED: "notification.email_provider_not_configured",
|
|
4
|
+
EMAIL_SEND_FAILED: "notification.email_send_failed",
|
|
5
|
+
EMAIL_ATTACHMENTS_TOO_LARGE: "notification.email_attachments_too_large",
|
|
6
|
+
EMAIL_INVALID_RECIPIENT: "notification.email_invalid_recipient",
|
|
7
|
+
/** The email payload carries neither a `template` nor a `subject` + `html` body source. */
|
|
8
|
+
EMAIL_MISSING_BODY: "notification.email_missing_body",
|
|
9
|
+
TEMPLATE_NOT_FOUND: "notification.template_not_found",
|
|
10
|
+
TEMPLATE_RENDER_FAILED: "notification.template_render_failed",
|
|
11
|
+
OTP_STORAGE_NOT_CONFIGURED: "notification.otp_storage_not_configured",
|
|
12
|
+
OTP_EMAIL_DELIVERY_NOT_CONFIGURED: "notification.otp_email_delivery_not_configured",
|
|
13
|
+
OTP_COOLDOWN_ACTIVE: "notification.otp_cooldown_active",
|
|
14
|
+
OTP_NOT_FOUND: "notification.otp_not_found",
|
|
15
|
+
OTP_EXPIRED: "notification.otp_expired",
|
|
16
|
+
OTP_MAX_ATTEMPTS_EXCEEDED: "notification.otp_max_attempts_exceeded",
|
|
17
|
+
OTP_INVALID_CODE: "notification.otp_invalid_code",
|
|
18
|
+
OTP_INVALID_LENGTH: "notification.otp_invalid_length",
|
|
19
|
+
SMS_PROVIDER_NOT_CONFIGURED: "notification.sms_provider_not_configured",
|
|
20
|
+
SMS_SEND_FAILED: "notification.sms_send_failed",
|
|
21
|
+
SMS_INVALID_RECIPIENT: "notification.sms_invalid_recipient",
|
|
22
|
+
PUSH_PROVIDER_NOT_CONFIGURED: "notification.push_provider_not_configured",
|
|
23
|
+
PUSH_SEND_FAILED: "notification.push_send_failed",
|
|
24
|
+
AUDIT_LOG_FAILED: "notification.audit_log_failed",
|
|
25
|
+
CHANNEL_DISABLED: "notification.channel_disabled"
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// src/shared/constants/default-ttls.ts
|
|
29
|
+
var DEFAULT_TTLS = {
|
|
30
|
+
/** Email verification: 1h — lets the user check their inbox at leisure. */
|
|
31
|
+
OTP_EMAIL_VERIFICATION_SECONDS: 3600,
|
|
32
|
+
/** Password reset: 10min — short window limits exposure of a sensitive flow. */
|
|
33
|
+
OTP_PASSWORD_RESET_SECONDS: 600,
|
|
34
|
+
/** MFA out-of-band: 5min — tight window for an interactive challenge. */
|
|
35
|
+
OTP_MFA_OOB_SECONDS: 300,
|
|
36
|
+
/** Phone verification: 10min — covers SMS delivery latency. */
|
|
37
|
+
OTP_PHONE_VERIFICATION_SECONDS: 600,
|
|
38
|
+
/** Magic link: 15min — slightly longer; a URL is often opened on another device. */
|
|
39
|
+
OTP_MAGIC_LINK_SECONDS: 900,
|
|
40
|
+
/** Resend cooldown: 60s — throttles repeated sends to the same recipient. */
|
|
41
|
+
RESEND_COOLDOWN_SECONDS: 60,
|
|
42
|
+
/** Generic fallback: 10min — used when no purpose-specific TTL applies. */
|
|
43
|
+
OTP_GENERIC_SECONDS: 600
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export { DEFAULT_TTLS, NOTIFICATION_ERROR_CODES };
|
package/package.json
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bymax-one/nest-notification",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Multi-channel notification library for NestJS — email, OTP, SMS, push — with pluggable providers and storage, multi-tenant by design, zero runtime dependencies.",
|
|
5
|
+
"author": "Bymax One <support@bymax.one>",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://github.com/bymaxone/nest-notification#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/bymaxone/nest-notification.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/bymaxone/nest-notification/issues"
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"LICENSE",
|
|
20
|
+
"README.md",
|
|
21
|
+
"CHANGELOG.md"
|
|
22
|
+
],
|
|
23
|
+
"main": "./dist/server/index.cjs",
|
|
24
|
+
"module": "./dist/server/index.mjs",
|
|
25
|
+
"types": "./dist/server/index.d.cts",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"import": {
|
|
29
|
+
"types": "./dist/server/index.d.ts",
|
|
30
|
+
"default": "./dist/server/index.mjs"
|
|
31
|
+
},
|
|
32
|
+
"require": {
|
|
33
|
+
"types": "./dist/server/index.d.cts",
|
|
34
|
+
"default": "./dist/server/index.cjs"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"./shared": {
|
|
38
|
+
"import": {
|
|
39
|
+
"types": "./dist/shared/index.d.ts",
|
|
40
|
+
"default": "./dist/shared/index.mjs"
|
|
41
|
+
},
|
|
42
|
+
"require": {
|
|
43
|
+
"types": "./dist/shared/index.d.cts",
|
|
44
|
+
"default": "./dist/shared/index.cjs"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"./react": {
|
|
48
|
+
"import": {
|
|
49
|
+
"types": "./dist/react/index.d.ts",
|
|
50
|
+
"default": "./dist/react/index.mjs"
|
|
51
|
+
},
|
|
52
|
+
"require": {
|
|
53
|
+
"types": "./dist/react/index.d.cts",
|
|
54
|
+
"default": "./dist/react/index.cjs"
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"./package.json": "./package.json"
|
|
58
|
+
},
|
|
59
|
+
"typesVersions": {
|
|
60
|
+
"*": {
|
|
61
|
+
"shared": [
|
|
62
|
+
"./dist/shared/index.d.cts"
|
|
63
|
+
],
|
|
64
|
+
"react": [
|
|
65
|
+
"./dist/react/index.d.cts"
|
|
66
|
+
]
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"dependencies": {},
|
|
70
|
+
"peerDependencies": {
|
|
71
|
+
"@nestjs/common": "^11.0.0",
|
|
72
|
+
"@nestjs/core": "^11.1.18",
|
|
73
|
+
"reflect-metadata": "^0.2.0",
|
|
74
|
+
"rxjs": "^7.8.0",
|
|
75
|
+
"ioredis": "^5.0.0",
|
|
76
|
+
"resend": "^4.0.0 || ^5.0.0 || ^6.0.0",
|
|
77
|
+
"@sendgrid/mail": "^8.0.0",
|
|
78
|
+
"@aws-sdk/client-ses": "^3.0.0",
|
|
79
|
+
"@aws-sdk/client-sns": "^3.0.0",
|
|
80
|
+
"mailgun.js": "^11.0.0 || ^12.0.0 || ^13.0.0",
|
|
81
|
+
"nodemailer": "^9.0.1",
|
|
82
|
+
"twilio": "^5.0.0 || ^6.0.0",
|
|
83
|
+
"firebase-admin": "^13.0.0 || ^14.0.0",
|
|
84
|
+
"@aws-sdk/client-dynamodb": "^3.0.0",
|
|
85
|
+
"handlebars": "^4.7.7",
|
|
86
|
+
"@react-email/render": "^1.0.0 || ^2.0.0",
|
|
87
|
+
"mjml": "^5.0.0",
|
|
88
|
+
"class-validator": "^0.14.0 || ^0.15.0",
|
|
89
|
+
"class-transformer": "^0.5.0",
|
|
90
|
+
"express": "^5.0.0",
|
|
91
|
+
"@types/express": "^5.0.0",
|
|
92
|
+
"react": "^19.0.0"
|
|
93
|
+
},
|
|
94
|
+
"peerDependenciesMeta": {
|
|
95
|
+
"ioredis": {
|
|
96
|
+
"optional": true
|
|
97
|
+
},
|
|
98
|
+
"resend": {
|
|
99
|
+
"optional": true
|
|
100
|
+
},
|
|
101
|
+
"@sendgrid/mail": {
|
|
102
|
+
"optional": true
|
|
103
|
+
},
|
|
104
|
+
"@aws-sdk/client-ses": {
|
|
105
|
+
"optional": true
|
|
106
|
+
},
|
|
107
|
+
"@aws-sdk/client-sns": {
|
|
108
|
+
"optional": true
|
|
109
|
+
},
|
|
110
|
+
"mailgun.js": {
|
|
111
|
+
"optional": true
|
|
112
|
+
},
|
|
113
|
+
"nodemailer": {
|
|
114
|
+
"optional": true
|
|
115
|
+
},
|
|
116
|
+
"twilio": {
|
|
117
|
+
"optional": true
|
|
118
|
+
},
|
|
119
|
+
"firebase-admin": {
|
|
120
|
+
"optional": true
|
|
121
|
+
},
|
|
122
|
+
"@aws-sdk/client-dynamodb": {
|
|
123
|
+
"optional": true
|
|
124
|
+
},
|
|
125
|
+
"handlebars": {
|
|
126
|
+
"optional": true
|
|
127
|
+
},
|
|
128
|
+
"@react-email/render": {
|
|
129
|
+
"optional": true
|
|
130
|
+
},
|
|
131
|
+
"mjml": {
|
|
132
|
+
"optional": true
|
|
133
|
+
},
|
|
134
|
+
"class-validator": {
|
|
135
|
+
"optional": true
|
|
136
|
+
},
|
|
137
|
+
"class-transformer": {
|
|
138
|
+
"optional": true
|
|
139
|
+
},
|
|
140
|
+
"express": {
|
|
141
|
+
"optional": true
|
|
142
|
+
},
|
|
143
|
+
"@types/express": {
|
|
144
|
+
"optional": true
|
|
145
|
+
},
|
|
146
|
+
"react": {
|
|
147
|
+
"optional": true
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
"devDependencies": {
|
|
151
|
+
"@arethetypeswrong/cli": "^0.18.5",
|
|
152
|
+
"@commitlint/cli": "^21.2.1",
|
|
153
|
+
"@commitlint/config-conventional": "^21.2.0",
|
|
154
|
+
"@eslint/js": "^9.39.4",
|
|
155
|
+
"@nestjs/common": "^11.1.20",
|
|
156
|
+
"@nestjs/core": "^11.1.20",
|
|
157
|
+
"@nestjs/testing": "^11.1.20",
|
|
158
|
+
"@stryker-mutator/core": "^9",
|
|
159
|
+
"@stryker-mutator/jest-runner": "^9",
|
|
160
|
+
"@stryker-mutator/typescript-checker": "^9",
|
|
161
|
+
"@testing-library/dom": "^10.4.1",
|
|
162
|
+
"@testing-library/react": "^16",
|
|
163
|
+
"@types/jest": "^30.0.0",
|
|
164
|
+
"@types/node": "^24",
|
|
165
|
+
"@types/react": "^19",
|
|
166
|
+
"@typescript-eslint/eslint-plugin": "^8.59.3",
|
|
167
|
+
"@typescript-eslint/parser": "^8.59.3",
|
|
168
|
+
"eslint": "^9.39.4",
|
|
169
|
+
"eslint-config-prettier": "^10.1.8",
|
|
170
|
+
"eslint-import-resolver-typescript": "^4.4.4",
|
|
171
|
+
"eslint-plugin-import": "^2.32.0",
|
|
172
|
+
"eslint-plugin-prettier": "^5.5.5",
|
|
173
|
+
"eslint-plugin-security": "^4.0.0",
|
|
174
|
+
"globals": "^17.6.0",
|
|
175
|
+
"husky": "^9.1.7",
|
|
176
|
+
"jest": "^30.4.2",
|
|
177
|
+
"jest-environment-jsdom": "^30",
|
|
178
|
+
"lint-staged": "^17.2.0",
|
|
179
|
+
"prettier": "^3.8.3",
|
|
180
|
+
"react": "^19",
|
|
181
|
+
"react-dom": "^19",
|
|
182
|
+
"reflect-metadata": "^0.2.2",
|
|
183
|
+
"rxjs": "^7.8.0",
|
|
184
|
+
"ts-jest": "^29.4.11",
|
|
185
|
+
"ts-node": "^10.9.2",
|
|
186
|
+
"tsup": "^8.5.1",
|
|
187
|
+
"typescript": "^5.9.3"
|
|
188
|
+
},
|
|
189
|
+
"keywords": [
|
|
190
|
+
"nestjs",
|
|
191
|
+
"notification",
|
|
192
|
+
"email",
|
|
193
|
+
"otp",
|
|
194
|
+
"sms",
|
|
195
|
+
"push",
|
|
196
|
+
"resend",
|
|
197
|
+
"sendgrid",
|
|
198
|
+
"ses",
|
|
199
|
+
"twilio",
|
|
200
|
+
"fcm",
|
|
201
|
+
"multi-tenant",
|
|
202
|
+
"redis",
|
|
203
|
+
"transactional",
|
|
204
|
+
"saas"
|
|
205
|
+
],
|
|
206
|
+
"lint-staged": {
|
|
207
|
+
"*.{ts,tsx,js,mjs,cjs}": [
|
|
208
|
+
"eslint --fix",
|
|
209
|
+
"prettier --write"
|
|
210
|
+
],
|
|
211
|
+
"*.{json,md,yml,yaml}": [
|
|
212
|
+
"prettier --write"
|
|
213
|
+
]
|
|
214
|
+
},
|
|
215
|
+
"engines": {
|
|
216
|
+
"node": ">=24.0.0"
|
|
217
|
+
},
|
|
218
|
+
"publishConfig": {
|
|
219
|
+
"access": "public",
|
|
220
|
+
"registry": "https://registry.npmjs.org/"
|
|
221
|
+
},
|
|
222
|
+
"scripts": {
|
|
223
|
+
"build": "pnpm clean && tsup",
|
|
224
|
+
"lint": "eslint src scripts test",
|
|
225
|
+
"lint:fix": "eslint src scripts test --fix",
|
|
226
|
+
"test": "jest",
|
|
227
|
+
"test:cov": "jest --coverage",
|
|
228
|
+
"test:watch": "jest --watch",
|
|
229
|
+
"test:e2e": "jest --config jest.e2e.config.ts --runInBand",
|
|
230
|
+
"test:all": "pnpm test && pnpm test:e2e",
|
|
231
|
+
"test:cov:all": "jest --config jest.coverage.config.ts --coverage",
|
|
232
|
+
"mutation": "stryker run",
|
|
233
|
+
"mutation:incremental": "stryker run --incremental",
|
|
234
|
+
"mutation:dry-run": "stryker run --dryRunOnly",
|
|
235
|
+
"typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.server.json",
|
|
236
|
+
"test:types": "tsc --noEmit -p tsconfig.typetest.json",
|
|
237
|
+
"size": "node scripts/check-size.mjs",
|
|
238
|
+
"smoke": "node scripts/dogfood-smoke-test.mjs",
|
|
239
|
+
"check:exports": "attw --pack .",
|
|
240
|
+
"clean": "rm -rf dist coverage",
|
|
241
|
+
"check:no-prisma": "grep -rq '@prisma/client' src; s=$?; [ $s -eq 1 ] && exit 0; [ $s -eq 0 ] && { echo check:no-prisma: found @prisma/client import in src/; exit 1; }; echo check:no-prisma: grep failed with exit $s; exit $s",
|
|
242
|
+
"release": "pnpm publish --provenance"
|
|
243
|
+
}
|
|
244
|
+
}
|