@miguelmorales13/nestkit 0.19.0 → 0.22.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.
@@ -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/index.cjs CHANGED
@@ -9,12 +9,12 @@ var _chunkRF75KC63cjs = require('./chunk-RF75KC63.cjs');
9
9
 
10
10
 
11
11
  var _chunkSPTDXUEDcjs = require('./chunk-SPTDXUED.cjs');
12
- require('./chunk-H2EHN366.cjs');
13
12
 
14
13
 
15
14
 
16
15
 
17
16
  var _chunkHVHYZXBBcjs = require('./chunk-HVHYZXBB.cjs');
17
+ require('./chunk-H2EHN366.cjs');
18
18
 
19
19
 
20
20
 
@@ -24,16 +24,16 @@ var _chunkHVHYZXBBcjs = require('./chunk-HVHYZXBB.cjs');
24
24
  var _chunkAPUFKA4Kcjs = require('./chunk-APUFKA4K.cjs');
25
25
 
26
26
 
27
- var _chunkFNUZGYUFcjs = require('./chunk-FNUZGYUF.cjs');
28
27
 
29
28
 
30
- var _chunk3AUOOEQOcjs = require('./chunk-3AUOOEQO.cjs');
29
+ var _chunk52IOOHNXcjs = require('./chunk-52IOOHNX.cjs');
30
+ require('./chunk-W2T2VFLC.cjs');
31
31
 
32
32
 
33
+ var _chunkFNUZGYUFcjs = require('./chunk-FNUZGYUF.cjs');
33
34
 
34
35
 
35
- var _chunk52IOOHNXcjs = require('./chunk-52IOOHNX.cjs');
36
- require('./chunk-W2T2VFLC.cjs');
36
+ var _chunk3AUOOEQOcjs = require('./chunk-3AUOOEQO.cjs');
37
37
 
38
38
 
39
39
  var _chunkQS2W5XCQcjs = require('./chunk-QS2W5XCQ.cjs');
package/dist/index.js CHANGED
@@ -9,12 +9,12 @@ import {
9
9
  SUPABASE_SERVICE_ROLE_CLIENT,
10
10
  SupabaseModule
11
11
  } from "./chunk-PA24P76K.js";
12
- import "./chunk-ODPSIFOB.js";
13
12
  import {
14
13
  REQUEST_ID_HEADER,
15
14
  RequestIdMiddleware,
16
15
  TrackingModule
17
16
  } from "./chunk-4PFAKLT3.js";
17
+ import "./chunk-ODPSIFOB.js";
18
18
  import {
19
19
  I18nInterceptor,
20
20
  I18nModule,
@@ -22,18 +22,18 @@ import {
22
22
  matchLanguage,
23
23
  translateOr
24
24
  } from "./chunk-6RAPVLJM.js";
25
- import {
26
- applyNestKitDefaults
27
- } from "./chunk-UNEVXCFW.js";
28
- import {
29
- ResponseInterceptor
30
- } from "./chunk-DYHSOULW.js";
31
25
  import {
32
26
  BaseCrudService,
33
27
  ListQuery,
34
28
  createCrudController
35
29
  } from "./chunk-IFNYRZP2.js";
36
30
  import "./chunk-ZJMLEP5H.js";
31
+ import {
32
+ applyNestKitDefaults
33
+ } from "./chunk-UNEVXCFW.js";
34
+ import {
35
+ ResponseInterceptor
36
+ } from "./chunk-DYHSOULW.js";
37
37
  import {
38
38
  BaseResponseDto
39
39
  } from "./chunk-XX2HPTRU.js";
@@ -24,6 +24,7 @@ export declare class FacturamaInvoicing implements InvoicingPort {
24
24
  /** True while this adapter points at the sandbox host. */
25
25
  get isSandbox(): boolean;
26
26
  private headers;
27
+ /** `draft.idempotencyKey` is intentionally unused: Facturama's API has no equivalent. */
27
28
  issue(draft: InvoiceDraft): Promise<Invoice>;
28
29
  get(id: string): Promise<Invoice>;
29
30
  /**
@@ -215,7 +215,10 @@ var FacturapiInvoicing = class {
215
215
  const lines = computeLines(draft.items);
216
216
  const invoice = await requestJson(PROVIDER, this.fetchImpl, `${this.baseUrl}/invoices`, {
217
217
  method: "POST",
218
- headers: this.headers(),
218
+ // The header is redundant with `idempotency_key` in the body — Facturapi only reads the
219
+ // body field — but it lets a generic resilience wrapper that sniffs for an
220
+ // `*idempotency*` header (rather than parsing the body) know this POST is safe to retry.
221
+ headers: draft.idempotencyKey ? { ...this.headers(), "idempotency-key": draft.idempotencyKey } : this.headers(),
219
222
  body: JSON.stringify({
220
223
  customer: typeof draft.customer === "string" ? draft.customer : {
221
224
  legal_name: draft.customer.legalName,
@@ -251,7 +254,8 @@ var FacturapiInvoicing = class {
251
254
  exchange: draft.exchangeRate,
252
255
  series: draft.series,
253
256
  folio_number: draft.folioNumber,
254
- external_id: draft.externalId
257
+ external_id: draft.externalId,
258
+ idempotency_key: draft.idempotencyKey
255
259
  })
256
260
  });
257
261
  return this.toInvoice(invoice);
@@ -357,6 +361,7 @@ var FacturamaInvoicing = class {
357
361
  headers() {
358
362
  return { authorization: `Basic ${this.token}`, "content-type": "application/json" };
359
363
  }
364
+ /** `draft.idempotencyKey` is intentionally unused: Facturama's API has no equivalent. */
360
365
  async issue(draft) {
361
366
  if (typeof draft.customer === "string") {
362
367
  throw new UnsupportedByProviderException(
@@ -215,7 +215,10 @@ var FacturapiInvoicing = class {
215
215
  const lines = computeLines(draft.items);
216
216
  const invoice = await requestJson(PROVIDER, this.fetchImpl, `${this.baseUrl}/invoices`, {
217
217
  method: "POST",
218
- headers: this.headers(),
218
+ // The header is redundant with `idempotency_key` in the body — Facturapi only reads the
219
+ // body field — but it lets a generic resilience wrapper that sniffs for an
220
+ // `*idempotency*` header (rather than parsing the body) know this POST is safe to retry.
221
+ headers: draft.idempotencyKey ? { ...this.headers(), "idempotency-key": draft.idempotencyKey } : this.headers(),
219
222
  body: JSON.stringify({
220
223
  customer: typeof draft.customer === "string" ? draft.customer : {
221
224
  legal_name: draft.customer.legalName,
@@ -251,7 +254,8 @@ var FacturapiInvoicing = class {
251
254
  exchange: draft.exchangeRate,
252
255
  series: draft.series,
253
256
  folio_number: draft.folioNumber,
254
- external_id: draft.externalId
257
+ external_id: draft.externalId,
258
+ idempotency_key: draft.idempotencyKey
255
259
  })
256
260
  });
257
261
  return this.toInvoice(invoice);
@@ -357,6 +361,7 @@ var FacturamaInvoicing = class {
357
361
  headers() {
358
362
  return { authorization: `Basic ${this.token}`, "content-type": "application/json" };
359
363
  }
364
+ /** `draft.idempotencyKey` is intentionally unused: Facturama's API has no equivalent. */
360
365
  async issue(draft) {
361
366
  if (typeof draft.customer === "string") {
362
367
  throw new UnsupportedByProviderException(
@@ -99,6 +99,16 @@ export interface InvoiceDraft {
99
99
  folioNumber?: number;
100
100
  /** Your own id for this invoice, echoed back by the provider. */
101
101
  externalId?: string;
102
+ /**
103
+ * A key unique to this **attempt** to issue the invoice — not to the sale.
104
+ * When set, Facturapi returns the same invoice instead of stamping a second
105
+ * one if the request is sent twice (a timeout or a dropped connection after
106
+ * it already stamped). Generate a fresh one per call to `issue()`; reusing
107
+ * the same key across a deliberate re-issue (e.g. after cancelling) makes
108
+ * the provider hand back the old, cancelled document instead of a new one.
109
+ * Facturapi only — Facturama has no equivalent and ignores this field.
110
+ */
111
+ idempotencyKey?: string;
102
112
  }
103
113
  export interface Invoice {
104
114
  /** The provider's id — what every other method here takes. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miguelmorales13/nestkit",
3
- "version": "0.19.0",
3
+ "version": "0.22.0",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -191,9 +191,13 @@
191
191
  "@aws-sdk/client-s3": "^3.0.0",
192
192
  "@aws-sdk/s3-request-presigner": "^3.0.0",
193
193
  "@aws-sdk/lib-storage": "^3.0.0",
194
- "typeorm": "^0.3.0 || ^1.0.0"
194
+ "typeorm": "^0.3.0 || ^1.0.0",
195
+ "@simplewebauthn/server": "^13.0.0 || ^14.0.0"
195
196
  },
196
197
  "peerDependenciesMeta": {
198
+ "@simplewebauthn/server": {
199
+ "optional": true
200
+ },
197
201
  "@aws-sdk/client-s3": {
198
202
  "optional": true
199
203
  },
@@ -249,6 +253,7 @@
249
253
  "@nestjs/common": "^11.0.0",
250
254
  "@nestjs/core": "^11.0.0",
251
255
  "@nestjs/swagger": "^11.0.0",
256
+ "@simplewebauthn/server": "^14.0.2",
252
257
  "@supabase/supabase-js": "^2.45.0",
253
258
  "@types/bun": "^1.4.2",
254
259
  "@types/jsonwebtoken": "^9.0.10",