@openclaw/whatsapp 2026.8.1 → 2026.8.2

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.
Files changed (55) hide show
  1. package/dist/{action-runtime-YA_Yvunu.js → action-runtime-Bw0loEdy.js} +1 -1
  2. package/dist/action-runtime-api.js +1 -1
  3. package/dist/action-runtime.runtime.js +1 -1
  4. package/dist/agent-tools-api.js +2 -2
  5. package/dist/api.js +9 -9
  6. package/dist/{approval-handler.runtime-C7jZ8rsD.js → approval-handler.runtime-DeyPb57-.js} +2 -2
  7. package/dist/{approval-reactions-rpaNVHzZ.js → approval-reactions-DGDA6hQ7.js} +6 -4
  8. package/dist/{auth-store-CtpBqH5S.js → auth-store-DTj1H9pv.js} +5 -3
  9. package/dist/{channel-Dx09AAmX.js → channel-DxMmDjqK.js} +23 -19
  10. package/dist/channel-config-api.js +1 -1
  11. package/dist/channel-plugin-api.js +1 -1
  12. package/dist/{channel-react-action-n9a8Hk5i.js → channel-react-action-BUp7Wbfr.js} +2 -2
  13. package/dist/{channel.runtime-D_PjmeMT.js → channel.runtime-BwSnyXRX.js} +4 -4
  14. package/dist/{channel.setup-CRJQiWbh.js → channel.setup-aOFLSQyw.js} +1 -1
  15. package/dist/{config-schema-BQP5YCeK.js → config-schema-BYA6e_Ii.js} +6 -4
  16. package/dist/{connection-controller-CIYuBJrs.js → connection-controller-BvkxsbWi.js} +2 -2
  17. package/dist/{constants-HU41RHGI.js → constants-C7m81BNe.js} +1 -1
  18. package/dist/{directory-config-Ci8Jjsw4.js → directory-config-LgxYJLWY.js} +2 -2
  19. package/dist/directory-contract-api.js +1 -1
  20. package/dist/{group-session-key-CH9jJIVQ.js → group-session-key-KUguLmSZ.js} +3 -3
  21. package/dist/light-runtime-api.js +1 -1
  22. package/dist/{login-1u5WcfTn.js → login-Bk_jiXKD.js} +5 -4
  23. package/dist/{login-qr-B_1sr0hk.js → login-qr-B3m61NqA.js} +8 -6
  24. package/dist/login-qr-runtime.js +1 -1
  25. package/dist/{monitor-CySzv38g.js → monitor-CTsyo-HE.js} +77 -61
  26. package/dist/runtime-api.js +8 -8
  27. package/dist/{send-C3S-NqyO.js → send-DiPjiygK.js} +52 -27
  28. package/dist/{send-api-C-FFC1p_.js → send-api-kFcuhSiY.js} +42 -40
  29. package/dist/{setup-finalize-CRzMpx84.js → setup-finalize-CqH5wTK5.js} +5 -4
  30. package/dist/setup-plugin-api.js +1 -1
  31. package/dist/{setup-surface-ym4doiv3.js → setup-surface-Dm3T6S8t.js} +2 -2
  32. package/dist/{shared-D3B14d45.js → shared-DDjonGys.js} +6 -5
  33. package/dist/{socket-close-2T0_jZTN.js → socket-close-CpkkJZCU.js} +9 -6
  34. package/dist/{targets-runtime-TMk0lGuy.js → targets-runtime-RBjx3pg_.js} +1 -2
  35. package/dist/{text-runtime-CaKLhowd.js → text-runtime-DyfmcATV.js} +1 -1
  36. package/node_modules/baileys/node_modules/process-warning/.github/dependabot.yml +42 -2
  37. package/node_modules/baileys/node_modules/process-warning/.github/workflows/ci.yml +12 -1
  38. package/node_modules/baileys/node_modules/process-warning/.github/workflows/lock-threads.yml +19 -0
  39. package/node_modules/baileys/node_modules/process-warning/LICENSE +1 -1
  40. package/node_modules/baileys/node_modules/process-warning/README.md +41 -2
  41. package/node_modules/baileys/node_modules/process-warning/index.js +85 -17
  42. package/node_modules/baileys/node_modules/process-warning/package.json +6 -7
  43. package/node_modules/baileys/node_modules/process-warning/test/emit-once-only.test.js +3 -3
  44. package/node_modules/baileys/node_modules/process-warning/test/emit-reset.test.js +4 -4
  45. package/node_modules/baileys/node_modules/process-warning/test/emit-unlimited.test.js +2 -2
  46. package/node_modules/baileys/node_modules/process-warning/test/spy-warning.test.js +143 -0
  47. package/node_modules/baileys/node_modules/process-warning/types/index.d.ts +15 -1
  48. package/node_modules/baileys/node_modules/process-warning/types/index.tst.ts +48 -0
  49. package/node_modules/baileys/node_modules/ws/lib/permessage-deflate.js +3 -1
  50. package/node_modules/baileys/node_modules/ws/package.json +1 -1
  51. package/node_modules/typebox/build/format/email.mjs +1 -1
  52. package/node_modules/typebox/build/format/idna/idn-hostname.mjs +19 -1
  53. package/node_modules/typebox/package.json +1 -1
  54. package/package.json +5 -5
  55. package/node_modules/baileys/node_modules/process-warning/types/index.test-d.ts +0 -36
@@ -1,6 +1,6 @@
1
1
  import { o as resolveWhatsAppAuthDir } from "./accounts-CeKQbu_s.js";
2
2
  import { t as listAccountIds } from "./account-ids-CB5SOWjc.js";
3
- import { a as formatWhatsAppWebAuthStatusState, h as readWebAuthState } from "./auth-store-CtpBqH5S.js";
3
+ import { a as formatWhatsAppWebAuthStatusState, h as readWebAuthState } from "./auth-store-DTj1H9pv.js";
4
4
  import { DEFAULT_ACCOUNT_ID, createSetupTranslator, setSetupChannelEnabled } from "openclaw/plugin-sdk/setup";
5
5
  //#region extensions/whatsapp/src/setup-surface.ts
6
6
  const t = createSetupTranslator();
@@ -36,7 +36,7 @@ const whatsappSetupWizard = {
36
36
  },
37
37
  resolveShouldPromptAccountIds: ({ shouldPromptAccountIds }) => shouldPromptAccountIds,
38
38
  credentials: [],
39
- finalize: async (params) => await (await import("./setup-finalize-CRzMpx84.js")).finalizeWhatsAppSetup(params),
39
+ finalize: async (params) => await (await import("./setup-finalize-CqH5wTK5.js")).finalizeWhatsAppSetup(params),
40
40
  disable: (cfg) => setSetupChannelEnabled(cfg, channel, false),
41
41
  onAccountRecorded: (accountId, options) => {
42
42
  options?.onAccountId?.(channel, accountId);
@@ -1,7 +1,7 @@
1
1
  import { a as resolveWhatsAppAccount, n as hasAnyWhatsAppAuth } from "./accounts-CeKQbu_s.js";
2
2
  import { r as resolveDefaultWhatsAppAccountId, t as listAccountIds } from "./account-ids-CB5SOWjc.js";
3
3
  import { a as normalizeWhatsAppAllowFromEntries } from "./normalize-target-CugRyONv.js";
4
- import { t as WhatsAppChannelConfigSchema } from "./config-schema-BQP5YCeK.js";
4
+ import { t as WhatsAppChannelConfigSchema } from "./config-schema-BYA6e_Ii.js";
5
5
  import { n as whatsappDoctor } from "./doctor-CwzVXKoE.js";
6
6
  import { t as resolveWhatsAppConfigPath } from "./group-config-path-BGyzT9Lg.js";
7
7
  import { t as resolveLegacyGroupSessionKey } from "./group-session-contract-DDnZSsJ1.js";
@@ -20,14 +20,14 @@ import { adaptScopedAccountAccessor, createScopedChannelConfigAdapter, createSco
20
20
  import { createDelegatedSetupWizardProxy } from "openclaw/plugin-sdk/setup-runtime";
21
21
  import { readChannelAllowFromStore } from "openclaw/plugin-sdk/channel-pairing";
22
22
  //#region extensions/whatsapp/src/channel-runtime-loader.ts
23
- const loadWhatsAppAuthStore = createLazyRuntimeModule(() => import("./auth-store-CtpBqH5S.js").then((n) => n.i));
23
+ const loadWhatsAppAuthStore = createLazyRuntimeModule(() => import("./auth-store-DTj1H9pv.js").then((n) => n.i));
24
24
  async function readWhatsAppAccountLinkState(authDir) {
25
25
  const state = await (await loadWhatsAppAuthStore()).readWebAuthState(authDir);
26
26
  return state === "unstable" ? "unknown" : state;
27
27
  }
28
28
  const loadWhatsAppChannelRuntime = createLazyRuntimeModule(async () => {
29
29
  await loadWhatsAppAuthStore();
30
- return await import("./channel.runtime-D_PjmeMT.js");
30
+ return await import("./channel.runtime-BwSnyXRX.js");
31
31
  });
32
32
  //#endregion
33
33
  //#region extensions/whatsapp/src/config-accessors.ts
@@ -96,7 +96,8 @@ function applyGroupAllowFromFromStore(params) {
96
96
  return changed ? next : params.cfg;
97
97
  }
98
98
  async function applyWhatsAppSecurityConfigFixes(params) {
99
- const normalized = normalizeUniqueStringEntries(await readChannelAllowFromStore("whatsapp", params.env, DEFAULT_ACCOUNT_ID).catch(() => []));
99
+ const fromStore = await readChannelAllowFromStore("whatsapp", params.env, DEFAULT_ACCOUNT_ID).catch(() => []);
100
+ const normalized = normalizeUniqueStringEntries(fromStore);
100
101
  if (normalized.length === 0) return {
101
102
  config: params.cfg,
102
103
  changes: []
@@ -115,7 +116,7 @@ async function applyWhatsAppSecurityConfigFixes(params) {
115
116
  //#region extensions/whatsapp/src/shared.ts
116
117
  const WHATSAPP_CHANNEL = "whatsapp";
117
118
  async function loadWhatsAppSetupSurface() {
118
- return await import("./setup-surface-ym4doiv3.js");
119
+ return await import("./setup-surface-Dm3T6S8t.js");
119
120
  }
120
121
  const whatsappSetupWizardProxy = createWhatsAppSetupWizardProxy(async () => (await loadWhatsAppSetupSurface()).whatsappSetupWizard);
121
122
  const whatsappConfigAdapter = createScopedChannelConfigAdapter({
@@ -1,5 +1,5 @@
1
1
  import { c as resolveWebCredsPath, s as resolveWebCredsBackupPath, t as assertWebCredsPathRegularFileOrMissing } from "./creds-files-W6B3EMZ8.js";
2
- import { A as enqueueCredsSave, M as waitForCredsSaveQueueWithTimeout, N as writeCredsJsonAtomically, P as writeWebCredsRawAtomically, b as restoreCredsFromBackupIfNeeded, u as readCredsJsonRaw, y as resolveDefaultWebAuthDir } from "./auth-store-CtpBqH5S.js";
2
+ import { A as enqueueCredsSave, M as waitForCredsSaveQueueWithTimeout, N as writeCredsJsonAtomically, P as writeWebCredsRawAtomically, b as restoreCredsFromBackupIfNeeded, u as readCredsJsonRaw, y as resolveDefaultWebAuthDir } from "./auth-store-DTj1H9pv.js";
3
3
  import { n as getStatusCode } from "./session-errors-JuazczrA.js";
4
4
  import { a as makeWASocket, i as makeCacheableSignalKeyStore, n as createBaileysSignalRepository, r as fetchLatestBaileysVersion, s as useMultiFileAuthState } from "./session.runtime-Nsqaehbd.js";
5
5
  import { VERSION, formatCliCommand } from "openclaw/plugin-sdk/cli-runtime";
@@ -22,7 +22,7 @@ var WhatsAppConnectionOwnerBusyError = class extends Error {
22
22
  this.name = "WhatsAppConnectionOwnerBusyError";
23
23
  }
24
24
  };
25
- const OWNER_LOCK_STALE_MS = 5 * 6e4;
25
+ const OWNER_LOCK_STALE_MS = 3e5;
26
26
  const GATEWAY_LOCAL_OWNER_WAIT_MS = 15e4;
27
27
  const processOwners = /* @__PURE__ */ new Map();
28
28
  function ownershipCancelledError(signal) {
@@ -325,7 +325,8 @@ async function createWaSocket(printQr, verbose, opts = {}) {
325
325
  return await createWaSocketInternal(printQr, verbose, opts, "normal");
326
326
  }
327
327
  async function createWaSocketInternal(printQr, verbose, opts, receiveMode) {
328
- const logger = toPinoLikeLogger(getChildLogger({ module: "baileys" }, { level: verbose ? "info" : "silent" }), verbose ? "info" : "silent");
328
+ const baseLogger = getChildLogger({ module: "baileys" }, { level: verbose ? "info" : "silent" });
329
+ const logger = toPinoLikeLogger(baseLogger, verbose ? "info" : "silent");
329
330
  const authDir = resolveUserPath(opts.authDir ?? resolveDefaultWebAuthDir());
330
331
  await rejectUnsafeWebCredsPath(authDir);
331
332
  await opts.beforeCredentialPersistence?.();
@@ -357,13 +358,14 @@ async function createWaSocketInternal(printQr, verbose, opts, receiveMode) {
357
358
  else pendingSocketAbort = { error };
358
359
  opts.onCredentialPersistenceError?.(error);
359
360
  };
360
- const cachedSignalKeys = makeCacheableSignalKeyStore(opts.beforeCredentialPersistence ? {
361
+ const persistedSignalKeys = opts.beforeCredentialPersistence ? {
361
362
  ...state.keys,
362
363
  async set(data) {
363
364
  await opts.beforeCredentialPersistence?.();
364
365
  await state.keys.set(data);
365
366
  }
366
- } : state.keys, logger);
367
+ } : state.keys;
368
+ const cachedSignalKeys = makeCacheableSignalKeyStore(persistedSignalKeys, logger);
367
369
  const signalKeys = opts.beforeCredentialPersistence ? {
368
370
  ...cachedSignalKeys,
369
371
  get(type, ids) {
@@ -542,7 +544,8 @@ async function waitForWaConnection(sock, options = { timeout: "none" }) {
542
544
  }
543
545
  if (update.connection === "close") {
544
546
  cleanup();
545
- reject(toErrorObject(update.lastDisconnect?.error ?? update.lastDisconnect ?? /* @__PURE__ */ new Error("Connection closed"), "Non-Error rejection"));
547
+ const disconnectError = update.lastDisconnect?.error ?? update.lastDisconnect;
548
+ reject(toErrorObject(disconnectError ?? /* @__PURE__ */ new Error("Connection closed"), "Non-Error rejection"));
546
549
  }
547
550
  };
548
551
  sock.ev.on("connection.update", handler);
@@ -282,8 +282,7 @@ function markdownToWhatsAppChunks(text, limit, tableMode = "bullets", chunkMode
282
282
  if (!text.trim()) return chunkMarkdownTextWithMode(text, limit, chunkMode);
283
283
  const { ir, escapedMarkers } = prepareWhatsAppMarkdown(text, tableMode);
284
284
  const render = (chunk) => renderWhatsAppMarkdownIR(chunk, escapedMarkers);
285
- const rendered = render(ir);
286
- let chunks = ir.styles.length === 0 && ir.links.length === 0 ? chunkMarkdownTextWithMode(rendered, limit, chunkMode) : splitWhatsAppIRForChunkMode(ir, limit, chunkMode).flatMap((source) => renderMarkdownIRChunksWithinLimit({
285
+ let chunks = ir.styles.length === 0 && ir.links.length === 0 ? chunkMarkdownTextWithMode(render(ir), limit, chunkMode) : splitWhatsAppIRForChunkMode(ir, limit, chunkMode).flatMap((source) => renderMarkdownIRChunksWithinLimit({
287
286
  ir: source,
288
287
  limit,
289
288
  renderChunk: render,
@@ -1,4 +1,4 @@
1
- import "./targets-runtime-TMk0lGuy.js";
1
+ import "./targets-runtime-RBjx3pg_.js";
2
2
  import { sanitizeAssistantVisibleText, sanitizeAssistantVisibleTextWithProfile, stripToolCallXmlTags } from "openclaw/plugin-sdk/text-chunking";
3
3
  import { normalizeE164, resolveUserPath as resolveUserPath$1 } from "openclaw/plugin-sdk/text-utility-runtime";
4
4
  export { stripToolCallXmlTags as a, sanitizeAssistantVisibleTextWithProfile as i, resolveUserPath$1 as n, sanitizeAssistantVisibleText as r, normalizeE164 as t };
@@ -2,12 +2,52 @@ version: 2
2
2
  updates:
3
3
  - package-ecosystem: "github-actions"
4
4
  directory: "/"
5
+ commit-message:
6
+ # Prefix all commit messages with "chore: "
7
+ prefix: "chore"
5
8
  schedule:
6
- interval: "monthly"
9
+ interval: "weekly"
10
+ cooldown:
11
+ default-days: 7
12
+ allow:
13
+ - dependency-name: "*"
14
+ update-types:
15
+ - "version-update:semver-major"
7
16
  open-pull-requests-limit: 10
8
17
 
9
18
  - package-ecosystem: "npm"
10
19
  directory: "/"
20
+ commit-message:
21
+ # Prefix all commit messages with "chore: "
22
+ prefix: "chore"
11
23
  schedule:
12
- interval: "monthly"
24
+ interval: "weekly"
25
+ cooldown:
26
+ default-days: 7
27
+ versioning-strategy: "increase-if-necessary"
28
+ allow:
29
+ - dependency-name: "*"
30
+ update-types:
31
+ - "version-update:semver-major"
32
+ ignore:
33
+ # TODO: remove ignore until neostandard support ESLint 10
34
+ - dependency-name: "eslint"
35
+ - dependency-name: "neostandard"
36
+ - dependency-name: "@stylistic/*"
13
37
  open-pull-requests-limit: 10
38
+ groups:
39
+ # Production dependencies with breaking changes
40
+ dependencies:
41
+ dependency-type: "production"
42
+ # ESLint related dependencies
43
+ dev-dependencies-eslint:
44
+ patterns:
45
+ - "eslint"
46
+ - "neostandard"
47
+ - "@stylistic/*"
48
+ # TypeScript related dependencies
49
+ dev-dependencies-typescript:
50
+ patterns:
51
+ - "@types/*"
52
+ - "tstyche"
53
+ - "typescript"
@@ -14,9 +14,20 @@ on:
14
14
  - 'docs/**'
15
15
  - '*.md'
16
16
 
17
+ # This allows a subsequently queued workflow run to interrupt previous runs
18
+ concurrency:
19
+ group: "${{ github.workflow }}-${{ github.event.pull_request.head.label || github.head_ref || github.ref }}"
20
+ cancel-in-progress: true
21
+
22
+ permissions:
23
+ contents: read
24
+
17
25
  jobs:
18
26
  test:
19
- uses: fastify/workflows/.github/workflows/plugins-ci.yml@v5
27
+ permissions:
28
+ contents: write
29
+ pull-requests: write
30
+ uses: fastify/workflows/.github/workflows/plugins-ci.yml@2073dc8e1f9e172bf42daa3843c9dbd31af1e8cb # v6.0.0
20
31
  with:
21
32
  license-check: true
22
33
  lint: true
@@ -0,0 +1,19 @@
1
+ name: Lock Threads
2
+
3
+ on:
4
+ schedule:
5
+ - cron: '0 0 1 * *'
6
+ workflow_dispatch:
7
+
8
+ concurrency:
9
+ group: lock
10
+
11
+ permissions:
12
+ contents: read
13
+
14
+ jobs:
15
+ lock-threads:
16
+ permissions:
17
+ issues: write
18
+ pull-requests: write
19
+ uses: fastify/workflows/.github/workflows/lock-threads.yml@2073dc8e1f9e172bf42daa3843c9dbd31af1e8cb # v6.0.0
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) Fastify
3
+ Copyright (c) 2020-present The Fastify team <https://github.com/fastify/fastify#team>
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -4,7 +4,7 @@
4
4
  [![NPM version](https://img.shields.io/npm/v/process-warning.svg?style=flat)](https://www.npmjs.com/package/process-warning)
5
5
  [![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)
6
6
 
7
- A small utility for generating consistent warning objects across your codebase.
7
+ A small utility for generating consistent [warning objects](https://nodejs.org/api/process.html#event-warning) across your codebase.
8
8
  It also exposes a utility for emitting those warnings, guaranteeing that they are issued only once (unless configured otherwise).
9
9
 
10
10
  _This module is used by the [Fastify](https://fastify.dev) framework and it was called `fastify-warning` prior to version 1.0.0._
@@ -31,7 +31,7 @@ const warning = createWarning({
31
31
  message: 'Hello %s',
32
32
  unlimited: true
33
33
  })
34
- warning('world')
34
+ const emitted = warning('world')
35
35
  ```
36
36
 
37
37
  #### Methods
@@ -101,6 +101,45 @@ FST_ERROR_CODE('world') // will be emitted
101
101
  FST_ERROR_CODE('world') // will be emitted again
102
102
  ```
103
103
 
104
+ #### `spyWarning(warning)`
105
+
106
+ Spy the created warning function for testing purpose.
107
+
108
+ ```js
109
+ const { test } = require('node:test')
110
+ const { createWarning, spyWarning } = require('process-warning')
111
+ const FST_ERROR_CODE = createWarning({ name: 'MyAppWarning', code: 'FST_ERROR_CODE', message: 'Hello %s' })
112
+
113
+ test('spy warning', t => {
114
+ const spyData = spyWarning(FST_ERROR_CODE)
115
+
116
+ // call after spy
117
+ const emitted = FST_ERROR_CODE('world')
118
+ t.assert.strictEqual(emitted, true)
119
+
120
+ // restore the warning function
121
+ // it must be called when you do not need to spy anymore
122
+ // otherwise, the calls data will accumulates.
123
+ t.after(() => spyData.restore())
124
+
125
+ t.assert.strictEqual(FST_ERROR_CODE.emitted, true)
126
+ // calls return the arguments and result.
127
+ // result indicate whether warning is emitted through process.emitWarning
128
+ console.log(spyData.calls) // [{ arguments: ['world'], result: true }]
129
+ t.assert.deepStrictEqual(spyData.calls[0].arguments, ['world'])
130
+ t.assert.strictEqual(spyData.calls[0].result, true)
131
+ // number of times called the function
132
+ console.log(spyData.callCount()) // 1
133
+ t.assert.strictEqual(spyData.callCount(), 1)
134
+
135
+ // reset the spy stat and warning state
136
+ spyData.reset()
137
+ t.assert.strictEqual(FST_ERROR_CODE.emitted, false)
138
+ t.assert.deepStrictEqual(spyData.calls, [])
139
+ t.assert.strictEqual(spyData.callCount(), 0)
140
+ })
141
+ ```
142
+
104
143
  #### Suppressing warnings
105
144
 
106
145
  It is possible to suppress warnings by utilizing one of node's built-in warning suppression mechanisms.
@@ -17,6 +17,7 @@ const { format } = require('node:util')
17
17
  * @property {string} message - The warning message.
18
18
  * @property {boolean} emitted - Indicates if the warning has been emitted.
19
19
  * @property {function} format - Formats the warning message.
20
+ * @returns {boolean} emit - Indicates if the warning has been emitted by this call.
20
21
  */
21
22
 
22
23
  /**
@@ -33,8 +34,69 @@ const { format } = require('node:util')
33
34
  * @typedef {Object} ProcessWarning
34
35
  * @property {function} createWarning - Creates a warning item.
35
36
  * @property {function} createDeprecation - Creates a deprecation warning item.
37
+ * @property {function} spyWarning - Spy a warning item.
36
38
  */
37
39
 
40
+ /**
41
+ * Represents the spy data.
42
+ * @typedef {Object} WarningSpyData
43
+ * @property {object} calls - Arguments of WarningItem calls with.
44
+ * @property {function} callCount - Number of counts called the WarningItem.
45
+ * @property {function} reset - Reset the calls data and state of WarningItem.
46
+ * @property {function} restore - Remove spy from WarningItem.
47
+ */
48
+
49
+ const kWarningFn = Symbol('process-warning.fn')
50
+ const kWarningSpyData = Symbol('process-warning.spyData')
51
+
52
+ /**
53
+ * Spy a warning item.
54
+ * @function
55
+ * @memberof processWarning
56
+ * @param {WarningItem} warning - The warning item to spy.
57
+ * @returns {WarningSpyData} The created spy data.
58
+ */
59
+ function spyWarning (warning) {
60
+ // Do not double spy the same warning
61
+ if (warning[kWarningSpyData] === null) {
62
+ const warningFn = warning[kWarningFn]
63
+ warning[kWarningFn] = function (a, b, c) {
64
+ const args = []
65
+ // since warning always call by fn(a, b, c)
66
+ // it need to remove the trailing undefined arguments
67
+ if (c) {
68
+ args.push(a, b, c)
69
+ } else if (b) {
70
+ args.push(a, b)
71
+ } else if (a) {
72
+ args.push(a)
73
+ }
74
+ warning[kWarningSpyData].calls.push({
75
+ arguments: args,
76
+ result: warningFn(a, b, c)
77
+ })
78
+ }
79
+ const spyData = {
80
+ calls: [],
81
+ callCount () {
82
+ return spyData.calls.length
83
+ },
84
+ reset () {
85
+ warning.emitted = false
86
+ spyData.calls.length = 0
87
+ },
88
+ restore () {
89
+ spyData.reset()
90
+ warning[kWarningFn] = warningFn
91
+ warning[kWarningSpyData] = null
92
+ }
93
+ }
94
+ warning[kWarningSpyData] = spyData
95
+ }
96
+
97
+ return warning[kWarningSpyData]
98
+ }
99
+
38
100
  /**
39
101
  * Creates a deprecation warning item.
40
102
  * @function
@@ -62,21 +124,24 @@ function createWarning ({ name, code, message, unlimited = false } = {}) {
62
124
 
63
125
  code = code.toUpperCase()
64
126
 
65
- let warningContainer = {
66
- [name]: function (a, b, c) {
127
+ const warningFn = unlimited === true
128
+ ? function (a, b, c) {
129
+ warning.emitted = true
130
+ process.emitWarning(warning.format(a, b, c), warning.name, warning.code)
131
+ return true
132
+ }
133
+ : function (a, b, c) {
67
134
  if (warning.emitted === true && warning.unlimited !== true) {
68
- return
135
+ return false
69
136
  }
70
137
  warning.emitted = true
71
138
  process.emitWarning(warning.format(a, b, c), warning.name, warning.code)
139
+ return true
72
140
  }
73
- }
74
- if (unlimited) {
75
- warningContainer = {
76
- [name]: function (a, b, c) {
77
- warning.emitted = true
78
- process.emitWarning(warning.format(a, b, c), warning.name, warning.code)
79
- }
141
+
142
+ const warningContainer = {
143
+ [name]: function (a, b, c) {
144
+ return warning[kWarningFn](a, b, c)
80
145
  }
81
146
  }
82
147
 
@@ -86,14 +151,16 @@ function createWarning ({ name, code, message, unlimited = false } = {}) {
86
151
  warning.message = message
87
152
  warning.unlimited = unlimited
88
153
  warning.code = code
154
+ warning[kWarningFn] = warningFn
155
+ warning[kWarningSpyData] = null
89
156
 
90
157
  /**
91
- * Formats the warning message.
92
- * @param {*} [a] Possible message interpolation value.
93
- * @param {*} [b] Possible message interpolation value.
94
- * @param {*} [c] Possible message interpolation value.
95
- * @returns {string} The formatted warning message.
96
- */
158
+ * Formats the warning message.
159
+ * @param {*} [a] Possible message interpolation value.
160
+ * @param {*} [b] Possible message interpolation value.
161
+ * @param {*} [c] Possible message interpolation value.
162
+ * @returns {string} The formatted warning message.
163
+ */
97
164
  warning.format = function (a, b, c) {
98
165
  let formatted
99
166
  if (a && b && c) {
@@ -116,9 +183,10 @@ function createWarning ({ name, code, message, unlimited = false } = {}) {
116
183
  * @namespace
117
184
  * @property {function} createWarning - Creates a warning item.
118
185
  * @property {function} createDeprecation - Creates a deprecation warning item.
186
+ * @property {function} spyWarning - Spy a warning item.
119
187
  * @property {ProcessWarning} processWarning - Represents the process warning functionality.
120
188
  */
121
- const out = { createWarning, createDeprecation }
189
+ const out = { createWarning, createDeprecation, spyWarning }
122
190
  module.exports = out
123
191
  module.exports.default = out
124
192
  module.exports.processWarning = out
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "process-warning",
3
- "version": "5.0.0",
3
+ "version": "5.1.0",
4
4
  "description": "A small utility for creating warnings and emitting them.",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",
@@ -11,7 +11,7 @@
11
11
  "test": "npm run test:unit && npm run test:jest && npm run test:typescript",
12
12
  "test:jest": "jest jest.test.js",
13
13
  "test:unit": "c8 --100 node --test",
14
- "test:typescript": "tsd"
14
+ "test:typescript": "tstyche"
15
15
  },
16
16
  "repository": {
17
17
  "type": "git",
@@ -62,12 +62,11 @@
62
62
  }
63
63
  ],
64
64
  "devDependencies": {
65
- "@fastify/pre-commit": "^2.1.0",
66
65
  "benchmark": "^2.1.4",
67
- "c8": "^10.1.3",
66
+ "c8": "^12.0.0",
68
67
  "eslint": "^9.17.0",
69
- "jest": "^29.7.0",
70
- "neostandard": "^0.12.0",
71
- "tsd": "^0.31.0"
68
+ "jest": "^30.0.3",
69
+ "neostandard": "^0.13.0",
70
+ "tstyche": "^7.0.0"
72
71
  }
73
72
  }
@@ -5,7 +5,7 @@ const { createWarning } = require('..')
5
5
  const { withResolvers } = require('./promise')
6
6
 
7
7
  test('emit should emit a given code only once', t => {
8
- t.plan(4)
8
+ t.plan(6)
9
9
 
10
10
  const { promise, resolve } = withResolvers()
11
11
 
@@ -22,8 +22,8 @@ test('emit should emit a given code only once', t => {
22
22
  code: 'CODE',
23
23
  message: 'Hello world'
24
24
  })
25
- warn()
26
- warn()
25
+ t.assert.strictEqual(warn(), true)
26
+ t.assert.strictEqual(warn(), false)
27
27
  setImmediate(() => {
28
28
  process.removeListener('warning', onWarning)
29
29
  resolve()
@@ -5,7 +5,7 @@ const { createWarning } = require('../')
5
5
  const { withResolvers } = require('./promise')
6
6
 
7
7
  test('a limited warning can be re-set', t => {
8
- t.plan(4)
8
+ t.plan(7)
9
9
 
10
10
  const { promise, resolve } = withResolvers()
11
11
  let count = 0
@@ -20,14 +20,14 @@ test('a limited warning can be re-set', t => {
20
20
  message: 'Hello world'
21
21
  })
22
22
 
23
- warn()
23
+ t.assert.strictEqual(warn(), true)
24
24
  t.assert.ok(warn.emitted)
25
25
 
26
- warn()
26
+ t.assert.strictEqual(warn(), false)
27
27
  t.assert.ok(warn.emitted)
28
28
 
29
29
  warn.emitted = false
30
- warn()
30
+ t.assert.strictEqual(warn(), true)
31
31
  t.assert.ok(warn.emitted)
32
32
 
33
33
  setImmediate(() => {
@@ -5,7 +5,7 @@ const { createWarning } = require('..')
5
5
  const { withResolvers } = require('./promise')
6
6
 
7
7
  test('emit should emit a given code unlimited times', t => {
8
- t.plan(50)
8
+ t.plan(60)
9
9
 
10
10
  let runs = 0
11
11
  const expectedRun = []
@@ -31,7 +31,7 @@ test('emit should emit a given code unlimited times', t => {
31
31
 
32
32
  for (let i = 0; i < times; i++) {
33
33
  expectedRun.push(i)
34
- warn()
34
+ t.assert.strictEqual(warn(), true)
35
35
  }
36
36
  setImmediate(() => {
37
37
  process.removeListener('warning', onWarning)