@miguelmorales13/nestkit 0.20.0 → 0.24.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 +321 -9
- package/dist/auth/oauth/index.cjs +1059 -68
- package/dist/auth/oauth/index.d.ts +20 -7
- package/dist/auth/oauth/index.js +1049 -58
- package/dist/auth/oauth/magic-link.dto.d.ts +20 -0
- package/dist/auth/oauth/memory-security.stores.d.ts +19 -0
- package/dist/auth/oauth/oauth-auth.service.d.ts +168 -14
- package/dist/auth/oauth/oauth-provider.d.ts +54 -5
- package/dist/auth/oauth/oauth.options.d.ts +57 -1
- package/dist/auth/oauth/oauth.ports.d.ts +58 -0
- package/dist/auth/oauth/providers/apple.d.ts +58 -0
- package/dist/auth/oauth/providers/discord.d.ts +7 -0
- package/dist/auth/oauth/providers/github.d.ts +8 -0
- package/dist/auth/oauth/providers/linkedin.d.ts +7 -0
- package/dist/auth/oauth/providers/microsoft.d.ts +17 -0
- package/dist/auth/oauth/providers/tiktok.d.ts +17 -0
- package/dist/auth/oauth/totp.d.ts +33 -0
- package/dist/auth/oauth/webauthn.port.d.ts +17 -0
- package/dist/bootstrap/index.cjs +3 -3
- package/dist/bootstrap/index.js +2 -2
- package/dist/index.cjs +13 -13
- package/dist/index.js +17 -17
- package/dist/payments/adapters/mercadopago-connect.d.ts +70 -0
- package/dist/payments/adapters/mercadopago.terminal.d.ts +57 -0
- package/dist/payments/index.cjs +153 -1
- package/dist/payments/index.d.ts +3 -1
- package/dist/payments/index.js +152 -0
- package/dist/payments/payments.port.d.ts +24 -0
- package/dist/push/channels/fcm.channel.d.ts +73 -0
- package/dist/push/channels/webpush.channel.d.ts +62 -0
- package/dist/push/index.cjs +449 -0
- package/dist/push/index.d.ts +9 -0
- package/dist/push/index.js +449 -0
- package/dist/push/push.module.d.ts +40 -0
- package/dist/push/push.options.d.ts +40 -0
- package/dist/push/push.port.d.ts +148 -0
- package/dist/push/push.service.d.ts +31 -0
- package/dist/security/index.cjs +35 -0
- package/dist/security/index.d.ts +2 -0
- package/dist/security/index.js +35 -0
- package/dist/security/signed-state.d.ts +42 -0
- package/package.json +25 -4
- package/dist/{chunk-FQRF37NG.cjs → chunk-ALIKVFOV.cjs} +2 -2
- package/dist/{chunk-PLEY5EZT.js → chunk-PFHHLB7B.js} +3 -3
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** Base32 without padding — what `otpauth://` URIs carry. */
|
|
2
|
+
export declare function base32Encode(bytes: Uint8Array): string;
|
|
3
|
+
export declare function base32Decode(text: string): Uint8Array;
|
|
4
|
+
/** 160 bits, the size RFC 4226 recommends for SHA-1. */
|
|
5
|
+
export declare function generateTotpSecret(): string;
|
|
6
|
+
export interface TotpOptions {
|
|
7
|
+
/** Seconds per step. Default 30; the apps assume it. */
|
|
8
|
+
step?: number;
|
|
9
|
+
digits?: number;
|
|
10
|
+
}
|
|
11
|
+
/** HOTP: HMAC-SHA1 of the counter, dynamically truncated, mod 10^digits. */
|
|
12
|
+
export declare function hotp(secret: Uint8Array, counter: number, digits?: number): string;
|
|
13
|
+
export declare function totpStep(now: number, step?: number): number;
|
|
14
|
+
export declare function totp(secretBase32: string, now?: number, options?: TotpOptions): string;
|
|
15
|
+
/**
|
|
16
|
+
* Checks a code against the current step and one on each side — a phone
|
|
17
|
+
* clock a few seconds off, or a code typed just as it rolled over, must not
|
|
18
|
+
* fail. Returns the step that matched so the caller can refuse the same
|
|
19
|
+
* step twice: a code observed over someone's shoulder is good for thirty
|
|
20
|
+
* seconds, and the second use is the one that matters.
|
|
21
|
+
*/
|
|
22
|
+
export declare function verifyTotp(secretBase32: string, code: string, options?: TotpOptions & {
|
|
23
|
+
now?: number;
|
|
24
|
+
window?: number;
|
|
25
|
+
}): number | null;
|
|
26
|
+
/** The URI the QR code encodes. `issuer` is what the app shows above the code. */
|
|
27
|
+
export declare function otpauthUri(input: {
|
|
28
|
+
issuer: string;
|
|
29
|
+
account: string;
|
|
30
|
+
secret: string;
|
|
31
|
+
digits?: number;
|
|
32
|
+
step?: number;
|
|
33
|
+
}): string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { generateAuthenticationOptions, generateRegistrationOptions, verifyAuthenticationResponse, verifyRegistrationResponse } from '@simplewebauthn/server';
|
|
2
|
+
/**
|
|
3
|
+
* The four functions of `@simplewebauthn/server` nestkit uses, as a port.
|
|
4
|
+
*
|
|
5
|
+
* The library stays the implementation — WebAuthn attestation formats and
|
|
6
|
+
* COSE keys are not something to rewrite — but a port is what lets a test
|
|
7
|
+
* run the whole flow with a fake, and lets an app pin or swap the library
|
|
8
|
+
* without touching this package.
|
|
9
|
+
*/
|
|
10
|
+
export interface WebAuthnPort {
|
|
11
|
+
generateRegistrationOptions: typeof generateRegistrationOptions;
|
|
12
|
+
verifyRegistrationResponse: typeof verifyRegistrationResponse;
|
|
13
|
+
generateAuthenticationOptions: typeof generateAuthenticationOptions;
|
|
14
|
+
verifyAuthenticationResponse: typeof verifyAuthenticationResponse;
|
|
15
|
+
}
|
|
16
|
+
/** Lazily loads the library, once. An app without passkeys never does. */
|
|
17
|
+
export declare function loadWebAuthn(): Promise<WebAuthnPort>;
|
package/dist/bootstrap/index.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('../chunk-LSDY6ETG.cjs');
|
|
3
|
+
var _chunkALIKVFOVcjs = require('../chunk-ALIKVFOV.cjs');
|
|
5
4
|
require('../chunk-3AUOOEQO.cjs');
|
|
5
|
+
require('../chunk-LSDY6ETG.cjs');
|
|
6
6
|
require('../chunk-Q5Y33L7B.cjs');
|
|
7
7
|
require('../chunk-AXMW5JF7.cjs');
|
|
8
8
|
require('../chunk-Y72D5L6I.cjs');
|
|
@@ -11,4 +11,4 @@ require('../chunk-PNK5WMPP.cjs');
|
|
|
11
11
|
require('../chunk-2REOCMUD.cjs');
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
exports.applyNestKitDefaults =
|
|
14
|
+
exports.applyNestKitDefaults = _chunkALIKVFOVcjs.applyNestKitDefaults;
|
package/dist/bootstrap/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
applyNestKitDefaults
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-2DUEQKOI.js";
|
|
3
|
+
} from "../chunk-PFHHLB7B.js";
|
|
5
4
|
import "../chunk-DYHSOULW.js";
|
|
5
|
+
import "../chunk-2DUEQKOI.js";
|
|
6
6
|
import "../chunk-M3GQDRWR.js";
|
|
7
7
|
import "../chunk-X4PQJZ4G.js";
|
|
8
8
|
import "../chunk-TCAMLNUZ.js";
|
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});require('./chunk-KVBQBT3D.cjs');
|
|
2
|
+
|
|
2
3
|
|
|
3
4
|
|
|
4
5
|
|
|
5
6
|
var _chunkRF75KC63cjs = require('./chunk-RF75KC63.cjs');
|
|
6
|
-
require('./chunk-KVBQBT3D.cjs');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
@@ -14,36 +14,36 @@ var _chunkSPTDXUEDcjs = require('./chunk-SPTDXUED.cjs');
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
var _chunkHVHYZXBBcjs = require('./chunk-HVHYZXBB.cjs');
|
|
17
|
-
require('./chunk-7SOM7EZP.cjs');
|
|
18
|
-
require('./chunk-H2EHN366.cjs');
|
|
19
17
|
|
|
20
18
|
|
|
19
|
+
var _chunkQS2W5XCQcjs = require('./chunk-QS2W5XCQ.cjs');
|
|
20
|
+
require('./chunk-H2EHN366.cjs');
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
|
|
25
|
-
var
|
|
25
|
+
var _chunk52IOOHNXcjs = require('./chunk-52IOOHNX.cjs');
|
|
26
|
+
require('./chunk-W2T2VFLC.cjs');
|
|
26
27
|
|
|
27
28
|
|
|
28
|
-
var
|
|
29
|
+
var _chunkALIKVFOVcjs = require('./chunk-ALIKVFOV.cjs');
|
|
29
30
|
|
|
30
31
|
|
|
31
|
-
var
|
|
32
|
+
var _chunk3AUOOEQOcjs = require('./chunk-3AUOOEQO.cjs');
|
|
33
|
+
require('./chunk-7SOM7EZP.cjs');
|
|
32
34
|
|
|
33
35
|
|
|
34
|
-
var _chunk3AUOOEQOcjs = require('./chunk-3AUOOEQO.cjs');
|
|
35
36
|
|
|
36
37
|
|
|
37
38
|
|
|
38
39
|
|
|
39
|
-
var
|
|
40
|
-
require('./chunk-W2T2VFLC.cjs');
|
|
40
|
+
var _chunkHDFPSA2Vcjs = require('./chunk-HDFPSA2V.cjs');
|
|
41
41
|
|
|
42
42
|
|
|
43
|
-
var
|
|
43
|
+
var _chunkLSDY6ETGcjs = require('./chunk-LSDY6ETG.cjs');
|
|
44
44
|
|
|
45
45
|
|
|
46
|
-
var
|
|
46
|
+
var _chunkQ5Y33L7Bcjs = require('./chunk-Q5Y33L7B.cjs');
|
|
47
47
|
|
|
48
48
|
|
|
49
49
|
|
|
@@ -108,4 +108,4 @@ require('./chunk-2REOCMUD.cjs');
|
|
|
108
108
|
|
|
109
109
|
|
|
110
110
|
|
|
111
|
-
exports.AppException = _chunkQ5Y33L7Bcjs.AppException; exports.BaseCrudService = _chunk52IOOHNXcjs.BaseCrudService; exports.BaseResponseDto = _chunkQS2W5XCQcjs.BaseResponseDto; exports.ConflictAppException = _chunkHDFPSA2Vcjs.ConflictAppException; exports.ForbiddenAppException = _chunkHDFPSA2Vcjs.ForbiddenAppException; exports.GlobalExceptionFilter = _chunkLSDY6ETGcjs.GlobalExceptionFilter; exports.I18nInterceptor = _chunkAPUFKA4Kcjs.I18nInterceptor; exports.I18nMessage = _chunkPNK5WMPPcjs.I18nMessage; exports.I18nModule = _chunkAPUFKA4Kcjs.I18nModule; exports.ListQuery = _chunk52IOOHNXcjs.ListQuery; exports.NestI18nTranslator = _chunkAPUFKA4Kcjs.NestI18nTranslator; exports.NotFoundAppException = _chunkHDFPSA2Vcjs.NotFoundAppException; exports.PG_POOL = _chunkRF75KC63cjs.PG_POOL; exports.PgModule = _chunkRF75KC63cjs.PgModule; exports.REQUEST_ID_HEADER = _chunkHVHYZXBBcjs.REQUEST_ID_HEADER; exports.RequestContext = _chunkSDWHKPXIcjs.RequestContext; exports.RequestIdMiddleware = _chunkHVHYZXBBcjs.RequestIdMiddleware; exports.ResponseInterceptor = _chunk3AUOOEQOcjs.ResponseInterceptor; exports.SUPABASE_ANON_CLIENT = _chunkSPTDXUEDcjs.SUPABASE_ANON_CLIENT; exports.SUPABASE_SERVICE_ROLE_CLIENT = _chunkSPTDXUEDcjs.SUPABASE_SERVICE_ROLE_CLIENT; exports.SupabaseModule = _chunkSPTDXUEDcjs.SupabaseModule; exports.TrackingModule = _chunkHVHYZXBBcjs.TrackingModule; exports.UnauthorizedAppException = _chunkHDFPSA2Vcjs.UnauthorizedAppException; exports.ValidationAppException = _chunkHDFPSA2Vcjs.ValidationAppException; exports.applyNestKitDefaults =
|
|
111
|
+
exports.AppException = _chunkQ5Y33L7Bcjs.AppException; exports.BaseCrudService = _chunk52IOOHNXcjs.BaseCrudService; exports.BaseResponseDto = _chunkQS2W5XCQcjs.BaseResponseDto; exports.ConflictAppException = _chunkHDFPSA2Vcjs.ConflictAppException; exports.ForbiddenAppException = _chunkHDFPSA2Vcjs.ForbiddenAppException; exports.GlobalExceptionFilter = _chunkLSDY6ETGcjs.GlobalExceptionFilter; exports.I18nInterceptor = _chunkAPUFKA4Kcjs.I18nInterceptor; exports.I18nMessage = _chunkPNK5WMPPcjs.I18nMessage; exports.I18nModule = _chunkAPUFKA4Kcjs.I18nModule; exports.ListQuery = _chunk52IOOHNXcjs.ListQuery; exports.NestI18nTranslator = _chunkAPUFKA4Kcjs.NestI18nTranslator; exports.NotFoundAppException = _chunkHDFPSA2Vcjs.NotFoundAppException; exports.PG_POOL = _chunkRF75KC63cjs.PG_POOL; exports.PgModule = _chunkRF75KC63cjs.PgModule; exports.REQUEST_ID_HEADER = _chunkHVHYZXBBcjs.REQUEST_ID_HEADER; exports.RequestContext = _chunkSDWHKPXIcjs.RequestContext; exports.RequestIdMiddleware = _chunkHVHYZXBBcjs.RequestIdMiddleware; exports.ResponseInterceptor = _chunk3AUOOEQOcjs.ResponseInterceptor; exports.SUPABASE_ANON_CLIENT = _chunkSPTDXUEDcjs.SUPABASE_ANON_CLIENT; exports.SUPABASE_SERVICE_ROLE_CLIENT = _chunkSPTDXUEDcjs.SUPABASE_SERVICE_ROLE_CLIENT; exports.SupabaseModule = _chunkSPTDXUEDcjs.SupabaseModule; exports.TrackingModule = _chunkHVHYZXBBcjs.TrackingModule; exports.UnauthorizedAppException = _chunkHDFPSA2Vcjs.UnauthorizedAppException; exports.ValidationAppException = _chunkHDFPSA2Vcjs.ValidationAppException; exports.applyNestKitDefaults = _chunkALIKVFOVcjs.applyNestKitDefaults; exports.buildPageMeta = _chunkY72D5L6Icjs.buildPageMeta; exports.createCrudController = _chunk52IOOHNXcjs.createCrudController; exports.currentLanguage = _chunkAXMW5JF7cjs.currentLanguage; exports.isI18nMessage = _chunkPNK5WMPPcjs.isI18nMessage; exports.isPaginated = _chunkY72D5L6Icjs.isPaginated; exports.matchLanguage = _chunkAPUFKA4Kcjs.matchLanguage; exports.paginated = _chunkY72D5L6Icjs.paginated; exports.t = _chunkPNK5WMPPcjs.t; exports.translate = _chunkAXMW5JF7cjs.translate; exports.translateDeep = _chunkAXMW5JF7cjs.translateDeep; exports.translateOr = _chunkAPUFKA4Kcjs.translateOr; exports.withTenantScope = _chunkRF75KC63cjs.withTenantScope;
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import "./chunk-EPVKCBPT.js";
|
|
1
2
|
import {
|
|
2
3
|
PG_POOL,
|
|
3
4
|
PgModule,
|
|
4
5
|
withTenantScope
|
|
5
6
|
} from "./chunk-VKOPDDCC.js";
|
|
6
|
-
import "./chunk-EPVKCBPT.js";
|
|
7
7
|
import {
|
|
8
8
|
SUPABASE_ANON_CLIENT,
|
|
9
9
|
SUPABASE_SERVICE_ROLE_CLIENT,
|
|
@@ -14,8 +14,23 @@ import {
|
|
|
14
14
|
RequestIdMiddleware,
|
|
15
15
|
TrackingModule
|
|
16
16
|
} from "./chunk-4PFAKLT3.js";
|
|
17
|
-
import
|
|
17
|
+
import {
|
|
18
|
+
BaseResponseDto
|
|
19
|
+
} from "./chunk-XX2HPTRU.js";
|
|
18
20
|
import "./chunk-ODPSIFOB.js";
|
|
21
|
+
import {
|
|
22
|
+
BaseCrudService,
|
|
23
|
+
ListQuery,
|
|
24
|
+
createCrudController
|
|
25
|
+
} from "./chunk-IFNYRZP2.js";
|
|
26
|
+
import "./chunk-ZJMLEP5H.js";
|
|
27
|
+
import {
|
|
28
|
+
applyNestKitDefaults
|
|
29
|
+
} from "./chunk-PFHHLB7B.js";
|
|
30
|
+
import {
|
|
31
|
+
ResponseInterceptor
|
|
32
|
+
} from "./chunk-DYHSOULW.js";
|
|
33
|
+
import "./chunk-DQYAIQQ5.js";
|
|
19
34
|
import {
|
|
20
35
|
ConflictAppException,
|
|
21
36
|
ForbiddenAppException,
|
|
@@ -23,27 +38,12 @@ import {
|
|
|
23
38
|
UnauthorizedAppException,
|
|
24
39
|
ValidationAppException
|
|
25
40
|
} from "./chunk-ZFIDAX7K.js";
|
|
26
|
-
import {
|
|
27
|
-
applyNestKitDefaults
|
|
28
|
-
} from "./chunk-PLEY5EZT.js";
|
|
29
41
|
import {
|
|
30
42
|
GlobalExceptionFilter
|
|
31
43
|
} from "./chunk-2DUEQKOI.js";
|
|
32
|
-
import {
|
|
33
|
-
ResponseInterceptor
|
|
34
|
-
} from "./chunk-DYHSOULW.js";
|
|
35
|
-
import {
|
|
36
|
-
BaseCrudService,
|
|
37
|
-
ListQuery,
|
|
38
|
-
createCrudController
|
|
39
|
-
} from "./chunk-IFNYRZP2.js";
|
|
40
|
-
import "./chunk-ZJMLEP5H.js";
|
|
41
44
|
import {
|
|
42
45
|
AppException
|
|
43
46
|
} from "./chunk-M3GQDRWR.js";
|
|
44
|
-
import {
|
|
45
|
-
BaseResponseDto
|
|
46
|
-
} from "./chunk-XX2HPTRU.js";
|
|
47
47
|
import {
|
|
48
48
|
I18nInterceptor,
|
|
49
49
|
I18nModule,
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export interface MercadoPagoConnectOptions {
|
|
2
|
+
/** From the Mercado Pago application, not from any connected seller. */
|
|
3
|
+
clientId: string;
|
|
4
|
+
clientSecret: string;
|
|
5
|
+
/** Must match, character for character, the Redirect URI registered on the application. */
|
|
6
|
+
redirectUri: string;
|
|
7
|
+
/**
|
|
8
|
+
* Defaults to `offline_access`. Mercado Pago documents this as the one
|
|
9
|
+
* thing that turns on `refresh_token` for the authorization-code flow —
|
|
10
|
+
* drop it and every connection stops working the moment its access token
|
|
11
|
+
* expires, with no way back short of sending the seller through consent
|
|
12
|
+
* again.
|
|
13
|
+
*/
|
|
14
|
+
scope?: string;
|
|
15
|
+
/** Override for tests. Defaults to `https://api.mercadopago.com`. */
|
|
16
|
+
tokenBaseUrl?: string;
|
|
17
|
+
/** Override for tests. Defaults to `https://auth.mercadopago.com/authorization`. */
|
|
18
|
+
authorizeUrl?: string;
|
|
19
|
+
/** Override for tests. Defaults to the global `fetch`. */
|
|
20
|
+
fetchImpl?: typeof fetch;
|
|
21
|
+
}
|
|
22
|
+
/** A connected seller's tokens, ready to build a {@link MercadoPagoTerminalPayments} for them. */
|
|
23
|
+
export interface MercadoPagoConnectTokens {
|
|
24
|
+
accessToken: string;
|
|
25
|
+
refreshToken: string;
|
|
26
|
+
/** The seller's own Mercado Pago user id — what {@link MercadoPagoTerminalPayments.createStore} takes as `userId`. */
|
|
27
|
+
userId: string;
|
|
28
|
+
scope?: string;
|
|
29
|
+
liveMode?: boolean;
|
|
30
|
+
tokenType?: string;
|
|
31
|
+
expiresAt: Date;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Connects a seller's Mercado Pago account by OAuth: the marketplace flow a
|
|
35
|
+
* single fixed `MERCADOPAGO_ACCESS_TOKEN` (see
|
|
36
|
+
* {@link MercadoPagoTerminalPayments}) cannot cover — one integrator, many
|
|
37
|
+
* connected sellers, each operating their own terminals on their own
|
|
38
|
+
* tokens, none of them typed into a form by hand.
|
|
39
|
+
*
|
|
40
|
+
* This is deliberately a separate class from `MercadoPagoTerminalPayments`
|
|
41
|
+
* rather than an extra constructor mode: connecting a seller and charging a
|
|
42
|
+
* terminal happen at different times, usually in different parts of an
|
|
43
|
+
* application (an onboarding screen versus a checkout), and a seller's
|
|
44
|
+
* access token is the *output* of this class and the *input* to that one.
|
|
45
|
+
*/
|
|
46
|
+
export declare class MercadoPagoConnect {
|
|
47
|
+
private readonly options;
|
|
48
|
+
private readonly tokenBaseUrl;
|
|
49
|
+
private readonly authorizeUrl;
|
|
50
|
+
private readonly fetchImpl;
|
|
51
|
+
constructor(options: MercadoPagoConnectOptions);
|
|
52
|
+
/**
|
|
53
|
+
* The consent-screen URL to send the seller to. `state` comes back
|
|
54
|
+
* untouched on your callback — sign it yourself (see
|
|
55
|
+
* `@miguelmorales13/nestkit/security`'s `signState`) if you need to prove
|
|
56
|
+
* your own application started the flow and tie the callback back to
|
|
57
|
+
* whoever did; Mercado Pago's redirect carries it, nothing more.
|
|
58
|
+
*/
|
|
59
|
+
authorizationUrl(state?: string): string;
|
|
60
|
+
/** Trades the callback's `code` for the seller's tokens. */
|
|
61
|
+
exchangeCode(code: string): Promise<MercadoPagoConnectTokens>;
|
|
62
|
+
/**
|
|
63
|
+
* Renews an access token. Mercado Pago **rotates the refresh token on
|
|
64
|
+
* every renewal** — persist the whole result, not just `accessToken`, or
|
|
65
|
+
* the seller's connection silently stops renewing the first time this
|
|
66
|
+
* runs.
|
|
67
|
+
*/
|
|
68
|
+
refresh(refreshToken: string): Promise<MercadoPagoConnectTokens>;
|
|
69
|
+
private token;
|
|
70
|
+
}
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import type { MercadoPagoPointOptions } from '../payments.options.js';
|
|
2
2
|
import type { ChargeInput, Terminal, TerminalPayment, TerminalPaymentsPort, TerminalWebhookEvent, WebhookRequestLike } from '../payments.port.js';
|
|
3
|
+
/**
|
|
4
|
+
* Whether `terminalId` belongs to a model Mercado Pago will switch to PDV
|
|
5
|
+
* mode over the API. The id carries its model as a prefix
|
|
6
|
+
* (`NEWLAND_N950__SBX0000001`) — exactly the pattern
|
|
7
|
+
* `PATCH /terminals/v1/setup` validates and, for an unsupported model,
|
|
8
|
+
* rejects with a bare `"'$.terminals[0].id' - does not match pattern"` that
|
|
9
|
+
* names no model and suggests nothing is wrong with the id itself.
|
|
10
|
+
*/
|
|
11
|
+
export declare function isIntegrableTerminalModel(terminalId: string): boolean;
|
|
3
12
|
/**
|
|
4
13
|
* Mercado Pago Point over the Orders API.
|
|
5
14
|
*
|
|
@@ -42,6 +51,54 @@ export declare class MercadoPagoTerminalPayments implements TerminalPaymentsPort
|
|
|
42
51
|
* expensive way to discover this.
|
|
43
52
|
*/
|
|
44
53
|
setOperatingMode(terminalIds: string[], mode: 'PDV' | 'STANDALONE'): Promise<Terminal[]>;
|
|
54
|
+
/**
|
|
55
|
+
* Creates the "Store" a terminal has to belong to before the Orders API
|
|
56
|
+
* will accept a charge for it — Mercado Pago's own Point documentation
|
|
57
|
+
* describes a mandatory hierarchy, **Store → POS → Terminal**, and a
|
|
58
|
+
* terminal that only ever paired through the merchant app (standalone,
|
|
59
|
+
* never through this call) sits outside it: charging it fails with
|
|
60
|
+
* `PA_UNAUTHORIZED_RESULT_FROM_POLICIES`, a message that names no missing
|
|
61
|
+
* Store because the policy engine that rejects it does not know that is
|
|
62
|
+
* the reason either.
|
|
63
|
+
*
|
|
64
|
+
* `location` and `businessHours` are Mercado Pago requirements, not
|
|
65
|
+
* choices this method makes for you — filled with real values it is your
|
|
66
|
+
* integration's call whether to ask the merchant for them or default them.
|
|
67
|
+
*
|
|
68
|
+
* **Check {@link listTerminals} first.** A terminal paired through the app
|
|
69
|
+
* can already carry a `storeId`/`posId` of its own — Mercado Pago assigns
|
|
70
|
+
* them the moment it is paired, standalone or not. Calling this again for
|
|
71
|
+
* a terminal that already has one does not fail, but it litters the
|
|
72
|
+
* merchant's Mercado Pago panel with a Store nothing points at.
|
|
73
|
+
*/
|
|
74
|
+
createStore(input: {
|
|
75
|
+
/** The Mercado Pago user id the Store belongs to — the seller's, from their OAuth connection, not the application's. */
|
|
76
|
+
userId: string;
|
|
77
|
+
name: string;
|
|
78
|
+
location: {
|
|
79
|
+
streetNumber: string;
|
|
80
|
+
streetName: string;
|
|
81
|
+
cityName: string;
|
|
82
|
+
stateName: string;
|
|
83
|
+
latitude: number;
|
|
84
|
+
longitude: number;
|
|
85
|
+
};
|
|
86
|
+
/** All seven days. Each is a list of open/close windows, `HH:MM` 24h. */
|
|
87
|
+
businessHours: Record<'monday' | 'tuesday' | 'wednesday' | 'thursday' | 'friday' | 'saturday' | 'sunday', {
|
|
88
|
+
open: string;
|
|
89
|
+
close: string;
|
|
90
|
+
}[]>;
|
|
91
|
+
}): Promise<string>;
|
|
92
|
+
/**
|
|
93
|
+
* Creates the "POS" (register/cash-point) inside a Store — the second
|
|
94
|
+
* link in Mercado Pago's Store → POS → Terminal chain, and the one that
|
|
95
|
+
* actually takes a terminal out of `standalone` once it is assigned to it.
|
|
96
|
+
*/
|
|
97
|
+
createPos(input: {
|
|
98
|
+
storeId: string;
|
|
99
|
+
name: string;
|
|
100
|
+
externalId?: string;
|
|
101
|
+
}): Promise<string>;
|
|
45
102
|
/**
|
|
46
103
|
* Forces a final status on an order created with **test credentials**, so a
|
|
47
104
|
* whole flow — order, status change, webhook — can be exercised without a
|
package/dist/payments/index.cjs
CHANGED
|
@@ -100,6 +100,10 @@ async function requestJson(provider, fetchImpl, url, init) {
|
|
|
100
100
|
// src/payments/adapters/mercadopago.terminal.ts
|
|
101
101
|
var PROVIDER = "mercadopago";
|
|
102
102
|
var DEFAULT_BASE_URL = "https://api.mercadopago.com";
|
|
103
|
+
var INTEGRABLE_MODELS = ["NEWLAND_N950", "PAX_A910", "INGENICO_MOVE2500"];
|
|
104
|
+
function isIntegrableTerminalModel(terminalId) {
|
|
105
|
+
return INTEGRABLE_MODELS.some((model) => terminalId.startsWith(`${model}__`));
|
|
106
|
+
}
|
|
103
107
|
function toStatus(status) {
|
|
104
108
|
switch (status) {
|
|
105
109
|
case "created":
|
|
@@ -162,6 +166,9 @@ var MercadoPagoTerminalPayments = class {
|
|
|
162
166
|
// Mercado Pago's list says nothing about connectivity.
|
|
163
167
|
online: void 0,
|
|
164
168
|
operatingMode: terminal.operating_mode === "PDV" ? "pdv" : terminal.operating_mode === "STANDALONE" ? "standalone" : "unknown",
|
|
169
|
+
storeId: terminal.store_id,
|
|
170
|
+
posId: terminal.pos_id === void 0 ? void 0 : String(terminal.pos_id),
|
|
171
|
+
integrable: isIntegrableTerminalModel(terminal.id),
|
|
165
172
|
raw: terminal
|
|
166
173
|
});
|
|
167
174
|
}
|
|
@@ -281,6 +288,15 @@ var MercadoPagoTerminalPayments = class {
|
|
|
281
288
|
* expensive way to discover this.
|
|
282
289
|
*/
|
|
283
290
|
async setOperatingMode(terminalIds, mode) {
|
|
291
|
+
if (mode === "PDV") {
|
|
292
|
+
const unsupported = terminalIds.filter((id) => !isIntegrableTerminalModel(id));
|
|
293
|
+
if (unsupported.length > 0) {
|
|
294
|
+
throw new UnsupportedByProviderException(
|
|
295
|
+
PROVIDER,
|
|
296
|
+
`Mercado Pago only switches Point Smart 1 and Point Smart 2 to PDV mode over the API. Not integrable: ${unsupported.join(", ")}. Other models (Point Air among them) are official Mercado Pago hardware but standalone-only, permanently \u2014 there is no PDV mode for them to switch to.`
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
284
300
|
const response = await requestJson(
|
|
285
301
|
PROVIDER,
|
|
286
302
|
this.fetchImpl,
|
|
@@ -294,9 +310,71 @@ var MercadoPagoTerminalPayments = class {
|
|
|
294
310
|
return (_nullishCoalesce(response.terminals, () => ( []))).map((terminal) => ({
|
|
295
311
|
id: terminal.id,
|
|
296
312
|
operatingMode: terminal.operating_mode === "PDV" ? "pdv" : terminal.operating_mode === "STANDALONE" ? "standalone" : "unknown",
|
|
313
|
+
integrable: isIntegrableTerminalModel(terminal.id),
|
|
297
314
|
raw: terminal
|
|
298
315
|
}));
|
|
299
316
|
}
|
|
317
|
+
/**
|
|
318
|
+
* Creates the "Store" a terminal has to belong to before the Orders API
|
|
319
|
+
* will accept a charge for it — Mercado Pago's own Point documentation
|
|
320
|
+
* describes a mandatory hierarchy, **Store → POS → Terminal**, and a
|
|
321
|
+
* terminal that only ever paired through the merchant app (standalone,
|
|
322
|
+
* never through this call) sits outside it: charging it fails with
|
|
323
|
+
* `PA_UNAUTHORIZED_RESULT_FROM_POLICIES`, a message that names no missing
|
|
324
|
+
* Store because the policy engine that rejects it does not know that is
|
|
325
|
+
* the reason either.
|
|
326
|
+
*
|
|
327
|
+
* `location` and `businessHours` are Mercado Pago requirements, not
|
|
328
|
+
* choices this method makes for you — filled with real values it is your
|
|
329
|
+
* integration's call whether to ask the merchant for them or default them.
|
|
330
|
+
*
|
|
331
|
+
* **Check {@link listTerminals} first.** A terminal paired through the app
|
|
332
|
+
* can already carry a `storeId`/`posId` of its own — Mercado Pago assigns
|
|
333
|
+
* them the moment it is paired, standalone or not. Calling this again for
|
|
334
|
+
* a terminal that already has one does not fail, but it litters the
|
|
335
|
+
* merchant's Mercado Pago panel with a Store nothing points at.
|
|
336
|
+
*/
|
|
337
|
+
async createStore(input) {
|
|
338
|
+
const data = await requestJson(
|
|
339
|
+
PROVIDER,
|
|
340
|
+
this.fetchImpl,
|
|
341
|
+
`${this.baseUrl}/users/${encodeURIComponent(input.userId)}/stores`,
|
|
342
|
+
{
|
|
343
|
+
method: "POST",
|
|
344
|
+
headers: this.headers(),
|
|
345
|
+
body: JSON.stringify({
|
|
346
|
+
name: input.name,
|
|
347
|
+
business_hours: input.businessHours,
|
|
348
|
+
location: {
|
|
349
|
+
street_number: input.location.streetNumber,
|
|
350
|
+
street_name: input.location.streetName,
|
|
351
|
+
city_name: input.location.cityName,
|
|
352
|
+
state_name: input.location.stateName,
|
|
353
|
+
latitude: input.location.latitude,
|
|
354
|
+
longitude: input.location.longitude
|
|
355
|
+
}
|
|
356
|
+
})
|
|
357
|
+
}
|
|
358
|
+
);
|
|
359
|
+
return data.id;
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Creates the "POS" (register/cash-point) inside a Store — the second
|
|
363
|
+
* link in Mercado Pago's Store → POS → Terminal chain, and the one that
|
|
364
|
+
* actually takes a terminal out of `standalone` once it is assigned to it.
|
|
365
|
+
*/
|
|
366
|
+
async createPos(input) {
|
|
367
|
+
const data = await requestJson(PROVIDER, this.fetchImpl, `${this.baseUrl}/pos`, {
|
|
368
|
+
method: "POST",
|
|
369
|
+
headers: this.headers(),
|
|
370
|
+
body: JSON.stringify({
|
|
371
|
+
name: input.name,
|
|
372
|
+
store_id: input.storeId,
|
|
373
|
+
external_id: input.externalId
|
|
374
|
+
})
|
|
375
|
+
});
|
|
376
|
+
return data.id;
|
|
377
|
+
}
|
|
300
378
|
/**
|
|
301
379
|
* Forces a final status on an order created with **test credentials**, so a
|
|
302
380
|
* whole flow — order, status change, webhook — can be exercised without a
|
|
@@ -780,6 +858,80 @@ function createTerminalPaymentsWebhookController(options) {
|
|
|
780
858
|
return TerminalPaymentsWebhookControllerHost;
|
|
781
859
|
}
|
|
782
860
|
|
|
861
|
+
// src/payments/adapters/mercadopago-connect.ts
|
|
862
|
+
var PROVIDER3 = "mercadopago";
|
|
863
|
+
var DEFAULT_TOKEN_BASE_URL = "https://api.mercadopago.com";
|
|
864
|
+
var DEFAULT_AUTHORIZE_URL = "https://auth.mercadopago.com/authorization";
|
|
865
|
+
var MercadoPagoConnect = class {
|
|
866
|
+
constructor(options) {
|
|
867
|
+
this.options = options;
|
|
868
|
+
this.tokenBaseUrl = (_nullishCoalesce(options.tokenBaseUrl, () => ( DEFAULT_TOKEN_BASE_URL))).replace(/\/$/, "");
|
|
869
|
+
this.authorizeUrl = _nullishCoalesce(options.authorizeUrl, () => ( DEFAULT_AUTHORIZE_URL));
|
|
870
|
+
this.fetchImpl = _nullishCoalesce(options.fetchImpl, () => ( globalThis.fetch));
|
|
871
|
+
}
|
|
872
|
+
/**
|
|
873
|
+
* The consent-screen URL to send the seller to. `state` comes back
|
|
874
|
+
* untouched on your callback — sign it yourself (see
|
|
875
|
+
* `@miguelmorales13/nestkit/security`'s `signState`) if you need to prove
|
|
876
|
+
* your own application started the flow and tie the callback back to
|
|
877
|
+
* whoever did; Mercado Pago's redirect carries it, nothing more.
|
|
878
|
+
*/
|
|
879
|
+
authorizationUrl(state) {
|
|
880
|
+
const params = new URLSearchParams({
|
|
881
|
+
client_id: this.options.clientId,
|
|
882
|
+
response_type: "code",
|
|
883
|
+
platform_id: "mp",
|
|
884
|
+
redirect_uri: this.options.redirectUri,
|
|
885
|
+
scope: _nullishCoalesce(this.options.scope, () => ( "offline_access")),
|
|
886
|
+
...state ? { state } : {}
|
|
887
|
+
});
|
|
888
|
+
return `${this.authorizeUrl}?${params.toString()}`;
|
|
889
|
+
}
|
|
890
|
+
/** Trades the callback's `code` for the seller's tokens. */
|
|
891
|
+
exchangeCode(code) {
|
|
892
|
+
return this.token({ grant_type: "authorization_code", code, redirect_uri: this.options.redirectUri });
|
|
893
|
+
}
|
|
894
|
+
/**
|
|
895
|
+
* Renews an access token. Mercado Pago **rotates the refresh token on
|
|
896
|
+
* every renewal** — persist the whole result, not just `accessToken`, or
|
|
897
|
+
* the seller's connection silently stops renewing the first time this
|
|
898
|
+
* runs.
|
|
899
|
+
*/
|
|
900
|
+
refresh(refreshToken) {
|
|
901
|
+
return this.token({ grant_type: "refresh_token", refresh_token: refreshToken });
|
|
902
|
+
}
|
|
903
|
+
async token(extra) {
|
|
904
|
+
const data = await requestJson(PROVIDER3, this.fetchImpl, `${this.tokenBaseUrl}/oauth/token`, {
|
|
905
|
+
method: "POST",
|
|
906
|
+
headers: { "content-type": "application/json" },
|
|
907
|
+
body: JSON.stringify({
|
|
908
|
+
client_id: this.options.clientId,
|
|
909
|
+
client_secret: this.options.clientSecret,
|
|
910
|
+
...extra
|
|
911
|
+
})
|
|
912
|
+
});
|
|
913
|
+
if (!data.access_token || !data.refresh_token) {
|
|
914
|
+
throw new TerminalPaymentProviderException(
|
|
915
|
+
PROVIDER3,
|
|
916
|
+
200,
|
|
917
|
+
data,
|
|
918
|
+
"Mercado Pago did not return both an access and a refresh token \u2014 check that scope includes offline_access."
|
|
919
|
+
);
|
|
920
|
+
}
|
|
921
|
+
return {
|
|
922
|
+
accessToken: data.access_token,
|
|
923
|
+
refreshToken: data.refresh_token,
|
|
924
|
+
userId: String(_nullishCoalesce(data.user_id, () => ( ""))),
|
|
925
|
+
scope: data.scope,
|
|
926
|
+
liveMode: data.live_mode,
|
|
927
|
+
tokenType: data.token_type,
|
|
928
|
+
expiresAt: new Date(Date.now() + (_nullishCoalesce(data.expires_in, () => ( 0))) * 1e3)
|
|
929
|
+
};
|
|
930
|
+
}
|
|
931
|
+
};
|
|
932
|
+
|
|
933
|
+
|
|
934
|
+
|
|
783
935
|
|
|
784
936
|
|
|
785
937
|
|
|
@@ -793,4 +945,4 @@ function createTerminalPaymentsWebhookController(options) {
|
|
|
793
945
|
|
|
794
946
|
|
|
795
947
|
|
|
796
|
-
exports.ClipTerminalPayments = ClipTerminalPayments; exports.MercadoPagoTerminalPayments = MercadoPagoTerminalPayments; exports.PAYMENTS_OPTIONS = PAYMENTS_OPTIONS; exports.PaymentsModule = PaymentsModule; exports.TERMINAL_PAYMENTS = TERMINAL_PAYMENTS; exports.TerminalPaymentProviderException = TerminalPaymentProviderException; exports.UnsupportedByProviderException = UnsupportedByProviderException; exports.assertCents = assertCents; exports.centsToDecimalString = centsToDecimalString; exports.createTerminalPaymentsAdapter = createTerminalPaymentsAdapter; exports.createTerminalPaymentsWebhookController = createTerminalPaymentsWebhookController; exports.decimalToCents = decimalToCents; exports.resolvePaymentsOptions = resolvePaymentsOptions;
|
|
948
|
+
exports.ClipTerminalPayments = ClipTerminalPayments; exports.MercadoPagoConnect = MercadoPagoConnect; exports.MercadoPagoTerminalPayments = MercadoPagoTerminalPayments; exports.PAYMENTS_OPTIONS = PAYMENTS_OPTIONS; exports.PaymentsModule = PaymentsModule; exports.TERMINAL_PAYMENTS = TERMINAL_PAYMENTS; exports.TerminalPaymentProviderException = TerminalPaymentProviderException; exports.UnsupportedByProviderException = UnsupportedByProviderException; exports.assertCents = assertCents; exports.centsToDecimalString = centsToDecimalString; exports.createTerminalPaymentsAdapter = createTerminalPaymentsAdapter; exports.createTerminalPaymentsWebhookController = createTerminalPaymentsWebhookController; exports.decimalToCents = decimalToCents; exports.isIntegrableTerminalModel = isIntegrableTerminalModel; exports.resolvePaymentsOptions = resolvePaymentsOptions;
|
package/dist/payments/index.d.ts
CHANGED
|
@@ -5,8 +5,10 @@ export type { PaymentsOptions, PaymentsProvider, MercadoPagoPointOptions, ClipPi
|
|
|
5
5
|
export { PaymentsModule, createTerminalPaymentsAdapter, resolvePaymentsOptions, } from './payments.module.js';
|
|
6
6
|
export { createTerminalPaymentsWebhookController } from './payments-webhook.controller.js';
|
|
7
7
|
export type { CreateTerminalPaymentsWebhookControllerOptions } from './payments-webhook.controller.js';
|
|
8
|
-
export { MercadoPagoTerminalPayments } from './adapters/mercadopago.terminal.js';
|
|
8
|
+
export { MercadoPagoTerminalPayments, isIntegrableTerminalModel } from './adapters/mercadopago.terminal.js';
|
|
9
9
|
export { ClipTerminalPayments } from './adapters/clip.terminal.js';
|
|
10
10
|
export type { ClipTransaction } from './adapters/clip.terminal.js';
|
|
11
|
+
export { MercadoPagoConnect } from './adapters/mercadopago-connect.js';
|
|
12
|
+
export type { MercadoPagoConnectOptions, MercadoPagoConnectTokens } from './adapters/mercadopago-connect.js';
|
|
11
13
|
export { TerminalPaymentProviderException, UnsupportedByProviderException } from './provider-http.js';
|
|
12
14
|
export { assertCents, centsToDecimalString, decimalToCents } from './money.js';
|