@miguelmorales13/nestkit 0.1.1 → 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/README.md +305 -1
- package/dist/auth/auth-user.entity.d.ts +8 -0
- package/dist/auth/auth-user.port.d.ts +16 -0
- package/dist/auth/auth.controller.d.ts +25 -0
- package/dist/auth/auth.dto.d.ts +13 -0
- package/dist/auth/auth.service.d.ts +24 -0
- package/dist/auth/authenticated-user.d.ts +7 -0
- package/dist/auth/current-tenant.decorator.d.ts +2 -0
- package/dist/auth/current-user.decorator.d.ts +1 -0
- package/dist/auth/hash.util.d.ts +2 -0
- package/dist/auth/index.cjs +265 -0
- package/dist/auth/index.d.ts +16 -0
- package/dist/auth/index.js +265 -0
- package/dist/auth/jwt-auth.guard.d.ts +5 -0
- package/dist/auth/require-tenant.guard.d.ts +9 -0
- package/dist/auth/roles.decorator.d.ts +3 -0
- package/dist/auth/roles.guard.d.ts +11 -0
- package/dist/auth/token.service.d.ts +7 -0
- package/dist/bootstrap/index.cjs +4 -3
- package/dist/bootstrap/index.js +3 -2
- package/dist/{chunk-AUA4X3RE.cjs → chunk-54ZXIB5T.cjs} +3 -3
- package/dist/{chunk-EQXYK6AL.js → chunk-7I2Y7V52.js} +5 -13
- package/dist/chunk-7SOM7EZP.cjs +1 -0
- package/dist/{chunk-VPS5CLHT.js → chunk-AOCF5QCZ.js} +3 -3
- package/dist/chunk-DQYAIQQ5.js +0 -0
- package/dist/{chunk-AR3EKJBR.cjs → chunk-FDNGAYTZ.cjs} +6 -6
- package/dist/{chunk-4IDLJMQA.cjs → chunk-J7TURDAL.cjs} +6 -14
- package/dist/{chunk-HGJX2GPE.js → chunk-ORWJ7LES.js} +1 -1
- package/dist/chunk-R7BVS6CI.cjs +13 -0
- package/dist/chunk-YFYHLYHN.js +13 -0
- package/dist/email/nodemailer/index.cjs +40 -0
- package/dist/email/nodemailer/index.d.ts +1 -0
- package/dist/email/nodemailer/index.js +40 -0
- package/dist/email/nodemailer/nodemailer.module.d.ts +4 -0
- package/dist/email/resend/index.cjs +31 -0
- package/dist/email/resend/index.d.ts +1 -0
- package/dist/email/resend/index.js +31 -0
- package/dist/email/resend/resend.module.d.ts +4 -0
- package/dist/errors/index.cjs +7 -4
- package/dist/errors/index.js +6 -3
- package/dist/index.cjs +17 -14
- package/dist/index.js +20 -17
- package/dist/media/index.cjs +127 -0
- package/dist/media/index.d.ts +5 -0
- package/dist/media/index.js +127 -0
- package/dist/media/media.controller.d.ts +44 -0
- package/dist/media/media.module.d.ts +7 -0
- package/dist/media/media.options.d.ts +13 -0
- package/dist/media/media.service.d.ts +29 -0
- package/dist/meta/index.cjs +164 -0
- package/dist/meta/index.d.ts +3 -0
- package/dist/meta/index.js +164 -0
- package/dist/meta/meta.module.d.ts +16 -0
- package/dist/meta/meta.service.d.ts +81 -0
- package/dist/stripe/index.cjs +78 -0
- package/dist/stripe/index.d.ts +3 -0
- package/dist/stripe/index.js +78 -0
- package/dist/stripe/stripe-webhook.controller.d.ts +20 -0
- package/dist/stripe/stripe.module.d.ts +4 -0
- package/dist/telegram/index.cjs +31 -0
- package/dist/telegram/index.d.ts +1 -0
- package/dist/telegram/index.js +31 -0
- package/dist/telegram/telegram.module.d.ts +8 -0
- package/dist/whatsapp/index.cjs +68 -0
- package/dist/whatsapp/index.d.ts +3 -0
- package/dist/whatsapp/index.js +68 -0
- package/dist/whatsapp/whatsapp-client.d.ts +21 -0
- package/dist/whatsapp/whatsapp.module.d.ts +4 -0
- package/package.json +84 -10
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
var _chunkFDNGAYTZcjs = require('../chunk-FDNGAYTZ.cjs');
|
|
4
|
+
require('../chunk-R7BVS6CI.cjs');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
var _chunk2REOCMUDcjs = require('../chunk-2REOCMUD.cjs');
|
|
9
|
+
|
|
10
|
+
// src/stripe/stripe.module.ts
|
|
11
|
+
var _common = require('@nestjs/common');
|
|
12
|
+
var _stripe = require('stripe'); var _stripe2 = _interopRequireDefault(_stripe);
|
|
13
|
+
var STRIPE_CLIENT = /* @__PURE__ */ Symbol("STRIPE_CLIENT");
|
|
14
|
+
var StripeModule = class {
|
|
15
|
+
};
|
|
16
|
+
StripeModule = exports.StripeModule = _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
|
|
17
|
+
_common.Module.call(void 0, {
|
|
18
|
+
providers: [
|
|
19
|
+
{
|
|
20
|
+
provide: STRIPE_CLIENT,
|
|
21
|
+
useFactory: () => {
|
|
22
|
+
const secretKey = process.env.STRIPE_SECRET_KEY;
|
|
23
|
+
if (!secretKey) {
|
|
24
|
+
throw new Error("StripeModule: STRIPE_SECRET_KEY environment variable is not set");
|
|
25
|
+
}
|
|
26
|
+
const apiVersion = process.env.STRIPE_API_VERSION;
|
|
27
|
+
return apiVersion ? new (0, _stripe2.default)(secretKey, { apiVersion }) : new (0, _stripe2.default)(secretKey);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
],
|
|
31
|
+
exports: [STRIPE_CLIENT]
|
|
32
|
+
})
|
|
33
|
+
], StripeModule);
|
|
34
|
+
|
|
35
|
+
// src/stripe/stripe-webhook.controller.ts
|
|
36
|
+
|
|
37
|
+
function createStripeWebhookController(options) {
|
|
38
|
+
let StripeWebhookControllerHost = class {
|
|
39
|
+
constructor(stripe) {
|
|
40
|
+
this.stripe = stripe;
|
|
41
|
+
}
|
|
42
|
+
async handleWebhook(req, signature) {
|
|
43
|
+
const webhookSecret = process.env.STRIPE_WEBHOOK_SECRET;
|
|
44
|
+
if (!webhookSecret) {
|
|
45
|
+
throw new Error("StripeWebhookController: STRIPE_WEBHOOK_SECRET environment variable is not set");
|
|
46
|
+
}
|
|
47
|
+
const rawBody = req.rawBody;
|
|
48
|
+
if (!rawBody) {
|
|
49
|
+
throw new Error(
|
|
50
|
+
"StripeWebhookController: request.rawBody is undefined \u2014 create the Nest app with `NestFactory.create(AppModule, { rawBody: true })` (see README)."
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
let event;
|
|
54
|
+
try {
|
|
55
|
+
event = this.stripe.webhooks.constructEvent(rawBody, signature, webhookSecret);
|
|
56
|
+
} catch (e) {
|
|
57
|
+
throw new (0, _chunkFDNGAYTZcjs.UnauthorizedAppException)("Invalid Stripe webhook signature", void 0, "INVALID_STRIPE_SIGNATURE");
|
|
58
|
+
}
|
|
59
|
+
await _optionalChain([options, 'access', _ => _.handlers, 'access', _2 => _2[event.type], 'optionalCall', _3 => _3(event)]);
|
|
60
|
+
return { received: true };
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
_chunk2REOCMUDcjs.__decorateClass.call(void 0, [
|
|
64
|
+
_common.Post.call(void 0, ),
|
|
65
|
+
_chunk2REOCMUDcjs.__decorateParam.call(void 0, 0, _common.Req.call(void 0, )),
|
|
66
|
+
_chunk2REOCMUDcjs.__decorateParam.call(void 0, 1, _common.Headers.call(void 0, "stripe-signature"))
|
|
67
|
+
], StripeWebhookControllerHost.prototype, "handleWebhook", 1);
|
|
68
|
+
StripeWebhookControllerHost = _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
|
|
69
|
+
_common.Controller.call(void 0, _nullishCoalesce(options.path, () => ( "stripe/webhook"))),
|
|
70
|
+
_chunk2REOCMUDcjs.__decorateParam.call(void 0, 0, _common.Inject.call(void 0, STRIPE_CLIENT))
|
|
71
|
+
], StripeWebhookControllerHost);
|
|
72
|
+
return StripeWebhookControllerHost;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
exports.STRIPE_CLIENT = STRIPE_CLIENT; exports.StripeModule = StripeModule; exports.createStripeWebhookController = createStripeWebhookController;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import {
|
|
2
|
+
UnauthorizedAppException
|
|
3
|
+
} from "../chunk-ORWJ7LES.js";
|
|
4
|
+
import "../chunk-YFYHLYHN.js";
|
|
5
|
+
import {
|
|
6
|
+
__decorateClass,
|
|
7
|
+
__decorateParam
|
|
8
|
+
} from "../chunk-4MGIQFAJ.js";
|
|
9
|
+
|
|
10
|
+
// src/stripe/stripe.module.ts
|
|
11
|
+
import { Module } from "@nestjs/common";
|
|
12
|
+
import Stripe from "stripe";
|
|
13
|
+
var STRIPE_CLIENT = /* @__PURE__ */ Symbol("STRIPE_CLIENT");
|
|
14
|
+
var StripeModule = class {
|
|
15
|
+
};
|
|
16
|
+
StripeModule = __decorateClass([
|
|
17
|
+
Module({
|
|
18
|
+
providers: [
|
|
19
|
+
{
|
|
20
|
+
provide: STRIPE_CLIENT,
|
|
21
|
+
useFactory: () => {
|
|
22
|
+
const secretKey = process.env.STRIPE_SECRET_KEY;
|
|
23
|
+
if (!secretKey) {
|
|
24
|
+
throw new Error("StripeModule: STRIPE_SECRET_KEY environment variable is not set");
|
|
25
|
+
}
|
|
26
|
+
const apiVersion = process.env.STRIPE_API_VERSION;
|
|
27
|
+
return apiVersion ? new Stripe(secretKey, { apiVersion }) : new Stripe(secretKey);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
],
|
|
31
|
+
exports: [STRIPE_CLIENT]
|
|
32
|
+
})
|
|
33
|
+
], StripeModule);
|
|
34
|
+
|
|
35
|
+
// src/stripe/stripe-webhook.controller.ts
|
|
36
|
+
import { Controller, Headers, Inject, Post, Req } from "@nestjs/common";
|
|
37
|
+
function createStripeWebhookController(options) {
|
|
38
|
+
let StripeWebhookControllerHost = class {
|
|
39
|
+
constructor(stripe) {
|
|
40
|
+
this.stripe = stripe;
|
|
41
|
+
}
|
|
42
|
+
async handleWebhook(req, signature) {
|
|
43
|
+
const webhookSecret = process.env.STRIPE_WEBHOOK_SECRET;
|
|
44
|
+
if (!webhookSecret) {
|
|
45
|
+
throw new Error("StripeWebhookController: STRIPE_WEBHOOK_SECRET environment variable is not set");
|
|
46
|
+
}
|
|
47
|
+
const rawBody = req.rawBody;
|
|
48
|
+
if (!rawBody) {
|
|
49
|
+
throw new Error(
|
|
50
|
+
"StripeWebhookController: request.rawBody is undefined \u2014 create the Nest app with `NestFactory.create(AppModule, { rawBody: true })` (see README)."
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
let event;
|
|
54
|
+
try {
|
|
55
|
+
event = this.stripe.webhooks.constructEvent(rawBody, signature, webhookSecret);
|
|
56
|
+
} catch {
|
|
57
|
+
throw new UnauthorizedAppException("Invalid Stripe webhook signature", void 0, "INVALID_STRIPE_SIGNATURE");
|
|
58
|
+
}
|
|
59
|
+
await options.handlers[event.type]?.(event);
|
|
60
|
+
return { received: true };
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
__decorateClass([
|
|
64
|
+
Post(),
|
|
65
|
+
__decorateParam(0, Req()),
|
|
66
|
+
__decorateParam(1, Headers("stripe-signature"))
|
|
67
|
+
], StripeWebhookControllerHost.prototype, "handleWebhook", 1);
|
|
68
|
+
StripeWebhookControllerHost = __decorateClass([
|
|
69
|
+
Controller(options.path ?? "stripe/webhook"),
|
|
70
|
+
__decorateParam(0, Inject(STRIPE_CLIENT))
|
|
71
|
+
], StripeWebhookControllerHost);
|
|
72
|
+
return StripeWebhookControllerHost;
|
|
73
|
+
}
|
|
74
|
+
export {
|
|
75
|
+
STRIPE_CLIENT,
|
|
76
|
+
StripeModule,
|
|
77
|
+
createStripeWebhookController
|
|
78
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type Type } from '@nestjs/common';
|
|
2
|
+
import type Stripe from 'stripe';
|
|
3
|
+
export interface CreateStripeWebhookControllerOptions {
|
|
4
|
+
/** Route prefix for the generated controller. Defaults to 'stripe/webhook'. */
|
|
5
|
+
path?: string;
|
|
6
|
+
/** Keyed by Stripe event type, e.g. 'checkout.session.completed'. Unhandled types are acked and ignored. */
|
|
7
|
+
handlers: Record<string, (event: Stripe.Event) => Promise<void> | void>;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Requires the Nest app to be created with
|
|
11
|
+
* `NestFactory.create(AppModule, { rawBody: true })` — Stripe signature
|
|
12
|
+
* verification needs the exact raw request bytes, which nestkit's
|
|
13
|
+
* `applyNestKitDefaults` (applied after app creation) cannot retroactively
|
|
14
|
+
* enable. See README.
|
|
15
|
+
*/
|
|
16
|
+
export declare function createStripeWebhookController(options: CreateStripeWebhookControllerOptions): Type<{
|
|
17
|
+
handleWebhook(req: unknown, signature: string): Promise<{
|
|
18
|
+
received: true;
|
|
19
|
+
}>;
|
|
20
|
+
}>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunk2REOCMUDcjs = require('../chunk-2REOCMUD.cjs');
|
|
4
|
+
|
|
5
|
+
// src/telegram/telegram.module.ts
|
|
6
|
+
var _common = require('@nestjs/common');
|
|
7
|
+
var _telegraf = require('telegraf');
|
|
8
|
+
var TELEGRAM_BOT = /* @__PURE__ */ Symbol("TELEGRAM_BOT");
|
|
9
|
+
var TelegramModule = class {
|
|
10
|
+
};
|
|
11
|
+
TelegramModule = exports.TelegramModule = _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
|
|
12
|
+
_common.Module.call(void 0, {
|
|
13
|
+
providers: [
|
|
14
|
+
{
|
|
15
|
+
provide: TELEGRAM_BOT,
|
|
16
|
+
useFactory: () => {
|
|
17
|
+
const token = process.env.TELEGRAM_BOT_TOKEN;
|
|
18
|
+
if (!token) {
|
|
19
|
+
throw new Error("TelegramModule: TELEGRAM_BOT_TOKEN environment variable is not set");
|
|
20
|
+
}
|
|
21
|
+
return new (0, _telegraf.Telegram)(token);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
],
|
|
25
|
+
exports: [TELEGRAM_BOT]
|
|
26
|
+
})
|
|
27
|
+
], TelegramModule);
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
exports.TELEGRAM_BOT = TELEGRAM_BOT; exports.TelegramModule = TelegramModule;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { TelegramModule, TELEGRAM_BOT } from './telegram.module.js';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__decorateClass
|
|
3
|
+
} from "../chunk-4MGIQFAJ.js";
|
|
4
|
+
|
|
5
|
+
// src/telegram/telegram.module.ts
|
|
6
|
+
import { Module } from "@nestjs/common";
|
|
7
|
+
import { Telegram as TelegrafClient } from "telegraf";
|
|
8
|
+
var TELEGRAM_BOT = /* @__PURE__ */ Symbol("TELEGRAM_BOT");
|
|
9
|
+
var TelegramModule = class {
|
|
10
|
+
};
|
|
11
|
+
TelegramModule = __decorateClass([
|
|
12
|
+
Module({
|
|
13
|
+
providers: [
|
|
14
|
+
{
|
|
15
|
+
provide: TELEGRAM_BOT,
|
|
16
|
+
useFactory: () => {
|
|
17
|
+
const token = process.env.TELEGRAM_BOT_TOKEN;
|
|
18
|
+
if (!token) {
|
|
19
|
+
throw new Error("TelegramModule: TELEGRAM_BOT_TOKEN environment variable is not set");
|
|
20
|
+
}
|
|
21
|
+
return new TelegrafClient(token);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
],
|
|
25
|
+
exports: [TELEGRAM_BOT]
|
|
26
|
+
})
|
|
27
|
+
], TelegramModule);
|
|
28
|
+
export {
|
|
29
|
+
TELEGRAM_BOT,
|
|
30
|
+
TelegramModule
|
|
31
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DI token for the outbound Telegram Bot API client. Inject with
|
|
3
|
+
* `@Inject(TELEGRAM_BOT)`. Send-only — no polling, no webhook, no update
|
|
4
|
+
* handling, no full `Telegraf` bot instance.
|
|
5
|
+
*/
|
|
6
|
+
export declare const TELEGRAM_BOT: unique symbol;
|
|
7
|
+
export declare class TelegramModule {
|
|
8
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
|
+
|
|
3
|
+
var _chunk2REOCMUDcjs = require('../chunk-2REOCMUD.cjs');
|
|
4
|
+
|
|
5
|
+
// src/whatsapp/whatsapp.module.ts
|
|
6
|
+
var _common = require('@nestjs/common');
|
|
7
|
+
|
|
8
|
+
// src/whatsapp/whatsapp-client.ts
|
|
9
|
+
var DEFAULT_API_VERSION = "v21.0";
|
|
10
|
+
var WhatsAppClient = class {
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this.options = options;
|
|
13
|
+
const version = _nullishCoalesce(options.apiVersion, () => ( DEFAULT_API_VERSION));
|
|
14
|
+
this.baseUrl = `https://graph.facebook.com/${version}/${options.phoneNumberId}/messages`;
|
|
15
|
+
}
|
|
16
|
+
async sendTextMessage(to, body) {
|
|
17
|
+
const response = await fetch(this.baseUrl, {
|
|
18
|
+
method: "POST",
|
|
19
|
+
headers: {
|
|
20
|
+
Authorization: `Bearer ${this.options.accessToken}`,
|
|
21
|
+
"Content-Type": "application/json"
|
|
22
|
+
},
|
|
23
|
+
body: JSON.stringify({
|
|
24
|
+
messaging_product: "whatsapp",
|
|
25
|
+
to,
|
|
26
|
+
type: "text",
|
|
27
|
+
text: { body }
|
|
28
|
+
})
|
|
29
|
+
});
|
|
30
|
+
if (!response.ok) {
|
|
31
|
+
const errorBody = await response.text();
|
|
32
|
+
throw new Error(`WhatsAppClient: send failed (${response.status}): ${errorBody}`);
|
|
33
|
+
}
|
|
34
|
+
return await response.json();
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// src/whatsapp/whatsapp.module.ts
|
|
39
|
+
var WHATSAPP_CLIENT = /* @__PURE__ */ Symbol("WHATSAPP_CLIENT");
|
|
40
|
+
function requireEnv(name) {
|
|
41
|
+
const value = process.env[name];
|
|
42
|
+
if (!value) {
|
|
43
|
+
throw new Error(`WhatsAppModule: ${name} environment variable is not set`);
|
|
44
|
+
}
|
|
45
|
+
return value;
|
|
46
|
+
}
|
|
47
|
+
var WhatsAppModule = class {
|
|
48
|
+
};
|
|
49
|
+
WhatsAppModule = exports.WhatsAppModule = _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
|
|
50
|
+
_common.Module.call(void 0, {
|
|
51
|
+
providers: [
|
|
52
|
+
{
|
|
53
|
+
provide: WHATSAPP_CLIENT,
|
|
54
|
+
useFactory: () => new WhatsAppClient({
|
|
55
|
+
accessToken: requireEnv("WHATSAPP_ACCESS_TOKEN"),
|
|
56
|
+
phoneNumberId: requireEnv("WHATSAPP_PHONE_NUMBER_ID"),
|
|
57
|
+
apiVersion: process.env.WHATSAPP_API_VERSION
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
],
|
|
61
|
+
exports: [WHATSAPP_CLIENT]
|
|
62
|
+
})
|
|
63
|
+
], WhatsAppModule);
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
exports.WHATSAPP_CLIENT = WHATSAPP_CLIENT; exports.WhatsAppClient = WhatsAppClient; exports.WhatsAppModule = WhatsAppModule;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__decorateClass
|
|
3
|
+
} from "../chunk-4MGIQFAJ.js";
|
|
4
|
+
|
|
5
|
+
// src/whatsapp/whatsapp.module.ts
|
|
6
|
+
import { Module } from "@nestjs/common";
|
|
7
|
+
|
|
8
|
+
// src/whatsapp/whatsapp-client.ts
|
|
9
|
+
var DEFAULT_API_VERSION = "v21.0";
|
|
10
|
+
var WhatsAppClient = class {
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this.options = options;
|
|
13
|
+
const version = options.apiVersion ?? DEFAULT_API_VERSION;
|
|
14
|
+
this.baseUrl = `https://graph.facebook.com/${version}/${options.phoneNumberId}/messages`;
|
|
15
|
+
}
|
|
16
|
+
async sendTextMessage(to, body) {
|
|
17
|
+
const response = await fetch(this.baseUrl, {
|
|
18
|
+
method: "POST",
|
|
19
|
+
headers: {
|
|
20
|
+
Authorization: `Bearer ${this.options.accessToken}`,
|
|
21
|
+
"Content-Type": "application/json"
|
|
22
|
+
},
|
|
23
|
+
body: JSON.stringify({
|
|
24
|
+
messaging_product: "whatsapp",
|
|
25
|
+
to,
|
|
26
|
+
type: "text",
|
|
27
|
+
text: { body }
|
|
28
|
+
})
|
|
29
|
+
});
|
|
30
|
+
if (!response.ok) {
|
|
31
|
+
const errorBody = await response.text();
|
|
32
|
+
throw new Error(`WhatsAppClient: send failed (${response.status}): ${errorBody}`);
|
|
33
|
+
}
|
|
34
|
+
return await response.json();
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// src/whatsapp/whatsapp.module.ts
|
|
39
|
+
var WHATSAPP_CLIENT = /* @__PURE__ */ Symbol("WHATSAPP_CLIENT");
|
|
40
|
+
function requireEnv(name) {
|
|
41
|
+
const value = process.env[name];
|
|
42
|
+
if (!value) {
|
|
43
|
+
throw new Error(`WhatsAppModule: ${name} environment variable is not set`);
|
|
44
|
+
}
|
|
45
|
+
return value;
|
|
46
|
+
}
|
|
47
|
+
var WhatsAppModule = class {
|
|
48
|
+
};
|
|
49
|
+
WhatsAppModule = __decorateClass([
|
|
50
|
+
Module({
|
|
51
|
+
providers: [
|
|
52
|
+
{
|
|
53
|
+
provide: WHATSAPP_CLIENT,
|
|
54
|
+
useFactory: () => new WhatsAppClient({
|
|
55
|
+
accessToken: requireEnv("WHATSAPP_ACCESS_TOKEN"),
|
|
56
|
+
phoneNumberId: requireEnv("WHATSAPP_PHONE_NUMBER_ID"),
|
|
57
|
+
apiVersion: process.env.WHATSAPP_API_VERSION
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
],
|
|
61
|
+
exports: [WHATSAPP_CLIENT]
|
|
62
|
+
})
|
|
63
|
+
], WhatsAppModule);
|
|
64
|
+
export {
|
|
65
|
+
WHATSAPP_CLIENT,
|
|
66
|
+
WhatsAppClient,
|
|
67
|
+
WhatsAppModule
|
|
68
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface WhatsAppClientOptions {
|
|
2
|
+
accessToken: string;
|
|
3
|
+
phoneNumberId: string;
|
|
4
|
+
apiVersion?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface WhatsAppSendResult {
|
|
7
|
+
messagingProduct: 'whatsapp';
|
|
8
|
+
messages: Array<{
|
|
9
|
+
id: string;
|
|
10
|
+
}>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Minimal outbound client for the WhatsApp Cloud API (Meta Graph API).
|
|
14
|
+
* No SDK dependency — built on Node's global `fetch` (18+).
|
|
15
|
+
*/
|
|
16
|
+
export declare class WhatsAppClient {
|
|
17
|
+
private readonly options;
|
|
18
|
+
private readonly baseUrl;
|
|
19
|
+
constructor(options: WhatsAppClientOptions);
|
|
20
|
+
sendTextMessage(to: string, body: string): Promise<WhatsAppSendResult>;
|
|
21
|
+
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@miguelmorales13/nestkit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"description": "Reusable NestJS building blocks: i18n, error handling, standardized responses, request tracking, base entities, generic CRUD,
|
|
7
|
+
"description": "Reusable NestJS building blocks: i18n, error handling, standardized responses, request tracking, base entities, generic CRUD, Postgres/Supabase connection helpers, outbound Telegram/WhatsApp/Stripe/Meta clients, short-lived media hosting, batteries-included auth, Stripe webhooks, and Resend/Nodemailer email.",
|
|
8
8
|
"publishConfig": {
|
|
9
9
|
"access": "public"
|
|
10
10
|
},
|
|
@@ -61,6 +61,36 @@
|
|
|
61
61
|
"import": "./dist/database/mongo/index.js",
|
|
62
62
|
"require": "./dist/database/mongo/index.cjs"
|
|
63
63
|
},
|
|
64
|
+
"./telegram": {
|
|
65
|
+
"types": "./dist/telegram/index.d.ts",
|
|
66
|
+
"import": "./dist/telegram/index.js",
|
|
67
|
+
"require": "./dist/telegram/index.cjs"
|
|
68
|
+
},
|
|
69
|
+
"./whatsapp": {
|
|
70
|
+
"types": "./dist/whatsapp/index.d.ts",
|
|
71
|
+
"import": "./dist/whatsapp/index.js",
|
|
72
|
+
"require": "./dist/whatsapp/index.cjs"
|
|
73
|
+
},
|
|
74
|
+
"./stripe": {
|
|
75
|
+
"types": "./dist/stripe/index.d.ts",
|
|
76
|
+
"import": "./dist/stripe/index.js",
|
|
77
|
+
"require": "./dist/stripe/index.cjs"
|
|
78
|
+
},
|
|
79
|
+
"./auth": {
|
|
80
|
+
"types": "./dist/auth/index.d.ts",
|
|
81
|
+
"import": "./dist/auth/index.js",
|
|
82
|
+
"require": "./dist/auth/index.cjs"
|
|
83
|
+
},
|
|
84
|
+
"./email/resend": {
|
|
85
|
+
"types": "./dist/email/resend/index.d.ts",
|
|
86
|
+
"import": "./dist/email/resend/index.js",
|
|
87
|
+
"require": "./dist/email/resend/index.cjs"
|
|
88
|
+
},
|
|
89
|
+
"./email/nodemailer": {
|
|
90
|
+
"types": "./dist/email/nodemailer/index.d.ts",
|
|
91
|
+
"import": "./dist/email/nodemailer/index.js",
|
|
92
|
+
"require": "./dist/email/nodemailer/index.cjs"
|
|
93
|
+
},
|
|
64
94
|
"./i18n": {
|
|
65
95
|
"types": "./dist/i18n/index.d.ts",
|
|
66
96
|
"import": "./dist/i18n/index.js",
|
|
@@ -70,6 +100,16 @@
|
|
|
70
100
|
"types": "./dist/bootstrap/index.d.ts",
|
|
71
101
|
"import": "./dist/bootstrap/index.js",
|
|
72
102
|
"require": "./dist/bootstrap/index.cjs"
|
|
103
|
+
},
|
|
104
|
+
"./meta": {
|
|
105
|
+
"types": "./dist/meta/index.d.ts",
|
|
106
|
+
"import": "./dist/meta/index.js",
|
|
107
|
+
"require": "./dist/meta/index.cjs"
|
|
108
|
+
},
|
|
109
|
+
"./media": {
|
|
110
|
+
"types": "./dist/media/index.d.ts",
|
|
111
|
+
"import": "./dist/media/index.js",
|
|
112
|
+
"require": "./dist/media/index.cjs"
|
|
73
113
|
}
|
|
74
114
|
},
|
|
75
115
|
"scripts": {
|
|
@@ -85,7 +125,13 @@
|
|
|
85
125
|
"helmet": "^8.0.0",
|
|
86
126
|
"pg": "^8.11.0",
|
|
87
127
|
"reflect-metadata": "^0.2.0",
|
|
88
|
-
"rxjs": "^7.8.0"
|
|
128
|
+
"rxjs": "^7.8.0",
|
|
129
|
+
"telegraf": "^4.16.0",
|
|
130
|
+
"stripe": "^22.0.0",
|
|
131
|
+
"class-validator": "^0.15.0",
|
|
132
|
+
"class-transformer": "^0.5.1",
|
|
133
|
+
"resend": "^6.20.0",
|
|
134
|
+
"nodemailer": "^9.0.5"
|
|
89
135
|
},
|
|
90
136
|
"peerDependenciesMeta": {
|
|
91
137
|
"pg": {
|
|
@@ -99,25 +145,53 @@
|
|
|
99
145
|
},
|
|
100
146
|
"helmet": {
|
|
101
147
|
"optional": true
|
|
148
|
+
},
|
|
149
|
+
"telegraf": {
|
|
150
|
+
"optional": true
|
|
151
|
+
},
|
|
152
|
+
"stripe": {
|
|
153
|
+
"optional": true
|
|
154
|
+
},
|
|
155
|
+
"class-validator": {
|
|
156
|
+
"optional": true
|
|
157
|
+
},
|
|
158
|
+
"class-transformer": {
|
|
159
|
+
"optional": true
|
|
160
|
+
},
|
|
161
|
+
"resend": {
|
|
162
|
+
"optional": true
|
|
163
|
+
},
|
|
164
|
+
"nodemailer": {
|
|
165
|
+
"optional": true
|
|
102
166
|
}
|
|
103
167
|
},
|
|
104
168
|
"dependencies": {
|
|
105
|
-
"nestjs-i18n": "^10.4.5"
|
|
169
|
+
"nestjs-i18n": "^10.4.5",
|
|
170
|
+
"bcryptjs": "^3.0.3",
|
|
171
|
+
"jsonwebtoken": "^9.0.3"
|
|
106
172
|
},
|
|
107
173
|
"devDependencies": {
|
|
108
|
-
"typescript": "^5.6.0",
|
|
109
|
-
"tsup": "^8.5.1",
|
|
110
|
-
"@types/node": "^22.0.0",
|
|
111
174
|
"@nestjs/common": "^11.0.0",
|
|
112
175
|
"@nestjs/core": "^11.0.0",
|
|
113
176
|
"@nestjs/swagger": "^11.0.0",
|
|
114
177
|
"@supabase/supabase-js": "^2.45.0",
|
|
115
|
-
"
|
|
178
|
+
"@types/jsonwebtoken": "^9.0.10",
|
|
179
|
+
"@types/node": "^22.0.0",
|
|
180
|
+
"@types/nodemailer": "^8.0.1",
|
|
116
181
|
"@types/pg": "^8.11.0",
|
|
182
|
+
"bcryptjs": "^3.0.3",
|
|
183
|
+
"class-transformer": "^0.5.1",
|
|
184
|
+
"class-validator": "^0.15.1",
|
|
117
185
|
"helmet": "^8.0.0",
|
|
186
|
+
"jsonwebtoken": "^9.0.3",
|
|
187
|
+
"nodemailer": "^9.0.5",
|
|
188
|
+
"pg": "^8.11.0",
|
|
118
189
|
"reflect-metadata": "^0.2.0",
|
|
190
|
+
"resend": "^6.20.0",
|
|
119
191
|
"rxjs": "^7.8.0",
|
|
120
|
-
"
|
|
121
|
-
"
|
|
192
|
+
"stripe": "^22.5.0",
|
|
193
|
+
"telegraf": "^4.16.3",
|
|
194
|
+
"tsup": "^8.5.1",
|
|
195
|
+
"typescript": "^5.6.0"
|
|
122
196
|
}
|
|
123
197
|
}
|