@openclaw/slack 2026.9.1-beta.1 → 2026.9.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 (99) hide show
  1. package/dist/{account-inspect-CN2hBsim.js → account-inspect-C3sePHWa.js} +3 -3
  2. package/dist/account-inspect-api.js +1 -1
  3. package/dist/{action-runtime-BoSeX09X.js → action-runtime-DftQWpI4.js} +84 -66
  4. package/dist/action-runtime.runtime-rHI3UAh4.js +2 -0
  5. package/dist/{actions-XdQyjG_p.js → actions-CFkvEv1d.js} +198 -54
  6. package/dist/api.js +14 -14
  7. package/dist/{approval-handler.runtime-DxXfGX_Z.js → approval-handler.runtime-BeILKdw4.js} +47 -25
  8. package/dist/{channel-C_vnTgxo.js → channel-CmOuxbOD.js} +76 -133
  9. package/dist/channel-config-api.js +1 -1
  10. package/dist/channel-plugin-api.js +1 -1
  11. package/dist/{channel-type-j-2lalcC.js → channel-type-BWt2CRaI.js} +2 -2
  12. package/dist/{channel.setup-aal8tokM.js → channel.setup-D5z1ReaT.js} +29 -23
  13. package/dist/{config-schema-CN3XZRX5.js → config-schema-JDx_f9Zb.js} +26 -17
  14. package/dist/{cursor-pages-eX7p8Wwt.js → cursor-pages-ByFwo-Py.js} +7 -1
  15. package/dist/{directory-config-DqfQ42OV.js → directory-config-Bmw4ykSy.js} +4 -3
  16. package/dist/directory-contract-api.js +1 -1
  17. package/dist/{directory-live-lC6X_Ru-.js → directory-live-BuBPHmju.js} +3 -8
  18. package/dist/{doctor-contract-BAy7-EUQ.js → doctor-contract-BNjw9bxb.js} +5 -4
  19. package/dist/doctor-contract-api.js +1 -1
  20. package/dist/{message-tool-api-CWosHSi5.js → message-tool-api-uNEfQYGY.js} +19 -2
  21. package/dist/message-tool-api.js +1 -1
  22. package/dist/{monitor-DrNCGneD.js → monitor-DI07pfJl.js} +3 -3
  23. package/dist/{outbound-adapter-DkT2vUE9.js → outbound-adapter-B5QyTRpJ.js} +96 -91
  24. package/dist/{pipeline.runtime-CRRng_Nw.js → pipeline.runtime-BdIwZgm4.js} +596 -920
  25. package/dist/{policy-BoP6t88v.js → policy-Bh5TOqII.js} +7 -4
  26. package/dist/{probe-4_aHtVT3.js → probe-Biy--yhL.js} +251 -12
  27. package/dist/{provider-D4nDgxCh.js → provider-DoaUvAM4.js} +5621 -4944
  28. package/dist/{relay-source-CEmze11m.js → relay-source-D4uecp68.js} +6 -4
  29. package/dist/{replies-D9XMM_S0.js → replies-DENuTcPO.js} +21 -16
  30. package/dist/reply-blocks-PRkhyAN7.js +790 -0
  31. package/dist/{resolve-channels-DSamDgVs.js → resolve-channels-DQGV2VrE.js} +6 -10
  32. package/dist/{resolve-users-CIzwbaJR.js → resolve-users-DRGt_Q4I.js} +5 -4
  33. package/dist/runtime-api.js +10 -10
  34. package/dist/{scopes-BBrUzpBH.js → scopes-CZzeGdWV.js} +1 -1
  35. package/dist/{send-DtjEnlLh.js → send-DElUcgIs.js} +32 -24
  36. package/dist/send-results-eeOu_HYm.js +23 -0
  37. package/dist/{send.runtime-DQeNKa2J.js → send.runtime-C8D6cKGm.js} +1 -1
  38. package/dist/{group-policy-CU1tEGpS.js → session-status-BynwcZSO.js} +284 -1013
  39. package/dist/setup-plugin-api.js +1 -1
  40. package/dist/{setup-surface-CsBCM4rP.js → setup-surface-B1_gpGBl.js} +5 -5
  41. package/dist/{shared-D9GeeR9K.js → shared-CNQsWJT7.js} +7 -5
  42. package/dist/{slash-dispatch.runtime-Chr3YHnT.js → slash-dispatch.runtime-DhsXavSY.js} +2 -2
  43. package/dist/{target-parsing-BnMD2ZqZ.js → target-parsing-PbxGDbr9.js} +11 -6
  44. package/dist/{targets-Cx5W_n3W.js → targets-7FexXJ62.js} +1 -1
  45. package/dist/{thread-ts-DUGhaYKq.js → thread-ts-CukseRVL.js} +5 -1
  46. package/node_modules/@slack/bolt/node_modules/negotiator/lib/accept.js +54 -0
  47. package/node_modules/@slack/bolt/node_modules/negotiator/lib/charset.js +10 -34
  48. package/node_modules/@slack/bolt/node_modules/negotiator/lib/encoding.js +9 -30
  49. package/node_modules/@slack/bolt/node_modules/negotiator/lib/language.js +15 -36
  50. package/node_modules/@slack/bolt/node_modules/negotiator/lib/mediaType.js +16 -134
  51. package/node_modules/@slack/bolt/node_modules/negotiator/node_modules/content-type/LICENSE +22 -0
  52. package/node_modules/@slack/bolt/node_modules/negotiator/node_modules/content-type/README.md +71 -0
  53. package/node_modules/@slack/bolt/node_modules/negotiator/node_modules/content-type/dist/index.d.ts +46 -0
  54. package/node_modules/@slack/bolt/node_modules/negotiator/node_modules/content-type/dist/index.js +176 -0
  55. package/node_modules/@slack/bolt/node_modules/negotiator/node_modules/content-type/dist/index.js.map +1 -0
  56. package/node_modules/@slack/bolt/node_modules/negotiator/node_modules/content-type/package.json +52 -0
  57. package/node_modules/@slack/bolt/node_modules/negotiator/package.json +16 -10
  58. package/node_modules/typebox/build/format/email.mjs +1 -1
  59. package/node_modules/typebox/build/format/idna/idn-hostname.mjs +19 -1
  60. package/node_modules/typebox/build/format/json_pointer.d.mts +2 -2
  61. package/node_modules/typebox/build/format/json_pointer.mjs +2 -2
  62. package/node_modules/typebox/build/format/json_pointer_uri_fragment.d.mts +2 -2
  63. package/node_modules/typebox/build/format/json_pointer_uri_fragment.mjs +2 -2
  64. package/node_modules/typebox/build/format/relative_json_pointer.d.mts +2 -2
  65. package/node_modules/typebox/build/format/relative_json_pointer.mjs +2 -2
  66. package/node_modules/typebox/build/system/memory/assign.mjs +2 -1
  67. package/node_modules/typebox/build/system/memory/create.mjs +3 -4
  68. package/node_modules/typebox/build/system/memory/discard.mjs +2 -2
  69. package/node_modules/typebox/build/system/memory/freeze.d.mts +4 -0
  70. package/node_modules/typebox/build/system/memory/freeze.mjs +6 -0
  71. package/node_modules/typebox/build/system/memory/update.mjs +3 -2
  72. package/node_modules/typebox/package.json +1 -1
  73. package/node_modules/undici/lib/dispatcher/balanced-pool.js +4 -2
  74. package/node_modules/undici/lib/dispatcher/client-h1.js +12 -4
  75. package/node_modules/undici/lib/dispatcher/client-h2.js +70 -14
  76. package/node_modules/undici/lib/dispatcher/client.js +6 -2
  77. package/node_modules/undici/lib/handler/cache-handler.js +21 -5
  78. package/node_modules/undici/lib/handler/retry-handler.js +42 -7
  79. package/node_modules/undici/lib/interceptor/cache.js +20 -1
  80. package/node_modules/undici/lib/interceptor/decompress.js +146 -14
  81. package/node_modules/undici/lib/interceptor/dump.js +10 -23
  82. package/node_modules/undici/lib/web/eventsource/eventsource-stream.js +245 -150
  83. package/node_modules/undici/lib/web/websocket/connection.js +1 -1
  84. package/node_modules/undici/lib/web/websocket/permessage-deflate.js +5 -0
  85. package/node_modules/undici/lib/web/websocket/stream/websocketstream.js +8 -10
  86. package/node_modules/undici/package.json +1 -1
  87. package/node_modules/undici/types/interceptors.d.ts +2 -0
  88. package/openclaw.plugin.json +17 -9
  89. package/package.json +6 -6
  90. package/skills/_vendor/slack-skills-plugin.LICENSE +21 -0
  91. package/skills/_vendor/slack-skills-plugin.json +31 -0
  92. package/skills/block-kit/SKILL.md +37 -0
  93. package/skills/block-kit/references/official-block-kit.md +257 -0
  94. package/skills/block-kit/references/official-common-patterns.md +385 -0
  95. package/skills/slack/SKILL.md +1 -1
  96. package/dist/action-runtime.runtime-Dpa16J87.js +0 -2
  97. package/dist/conversation-binding-route-DFVLUdYF.js +0 -115
  98. package/dist/slack-client-kind-hSfjXyUM.js +0 -94
  99. package/node_modules/@slack/bolt/node_modules/negotiator/HISTORY.md +0 -114
@@ -1,2 +1,2 @@
1
- import { t as slackSetupPlugin } from "./channel.setup-aal8tokM.js";
1
+ import { t as slackSetupPlugin } from "./channel.setup-D5z1ReaT.js";
2
2
  export { slackSetupPlugin };
@@ -1,9 +1,9 @@
1
1
  import { i as resolveDefaultSlackAccountId, o as resolveSlackAccountAllowFrom } from "./accounts-Dm_H77gH.js";
2
- import { t as inspectSlackAccount } from "./account-inspect-CN2hBsim.js";
3
- import "./shared-D9GeeR9K.js";
4
- import { o as SLACK_CHANNEL, r as createSlackSetupWizardBase } from "./channel.setup-aal8tokM.js";
5
- import { t as resolveSlackChannelAllowlist } from "./resolve-channels-DSamDgVs.js";
6
- import { t as resolveSlackUserAllowlist } from "./resolve-users-CIzwbaJR.js";
2
+ import { t as inspectSlackAccount } from "./account-inspect-C3sePHWa.js";
3
+ import "./shared-CNQsWJT7.js";
4
+ import { o as SLACK_CHANNEL, r as createSlackSetupWizardBase } from "./channel.setup-D5z1ReaT.js";
5
+ import { t as resolveSlackChannelAllowlist } from "./resolve-channels-DQGV2VrE.js";
6
+ import { t as resolveSlackUserAllowlist } from "./resolve-users-DRGt_Q4I.js";
7
7
  import { normalizeStringEntries } from "openclaw/plugin-sdk/string-coerce-runtime";
8
8
  import { resolveBasicAllowFromEntries } from "openclaw/plugin-sdk/allow-from";
9
9
  import { createSetupTranslator, noteChannelLookupFailure, noteChannelLookupSummary, parseMentionOrPrefixedId, patchChannelConfigForAccount, promptResolvedAllowFrom, resolveEntriesWithOptionalToken, resolveSetupAccountId, splitSetupEntries } from "openclaw/plugin-sdk/setup-runtime";
@@ -1,16 +1,17 @@
1
1
  import { n as isSlackPluginAccountConfigured } from "./account-configured-sUohAxZr.js";
2
2
  import { n as listSlackAccountIds, o as resolveSlackAccountAllowFrom, r as mergeSlackAccountConfig, s as resolveSlackAccountDmPolicy } from "./accounts-Dm_H77gH.js";
3
- import { t as inspectSlackAccount } from "./account-inspect-CN2hBsim.js";
4
- import { a as parseSlackTarget } from "./target-parsing-BnMD2ZqZ.js";
5
- import { t as probeSlack } from "./probe-4_aHtVT3.js";
6
- import { n as slackBaseConfigAdapter, t as slackSetupPlugin } from "./channel.setup-aal8tokM.js";
7
- import { n as normalizeCompatibilityConfig, t as legacyConfigRules } from "./doctor-contract-BAy7-EUQ.js";
3
+ import { t as inspectSlackAccount } from "./account-inspect-C3sePHWa.js";
4
+ import { a as parseSlackTarget } from "./target-parsing-PbxGDbr9.js";
5
+ import { a as slackIngressIdentity, t as probeSlack } from "./probe-Biy--yhL.js";
6
+ import { n as slackBaseConfigAdapter, t as slackSetupPlugin } from "./channel.setup-D5z1ReaT.js";
7
+ import { n as normalizeCompatibilityConfig, t as legacyConfigRules } from "./doctor-contract-BNjw9bxb.js";
8
8
  import { n as collectRuntimeConfigAssignments, r as secretTargetRegistryEntries } from "./secret-contract-DxmvbxBF.js";
9
9
  import { DEFAULT_ACCOUNT_ID as DEFAULT_ACCOUNT_ID$1 } from "openclaw/plugin-sdk/account-id";
10
10
  import { adaptScopedAccountAccessor, createScopedDmSecurityResolver } from "openclaw/plugin-sdk/channel-config-helpers";
11
11
  import { createLazyRuntimeModule } from "openclaw/plugin-sdk/lazy-runtime";
12
12
  import { PAIRING_APPROVED_MESSAGE, projectCredentialSnapshotFields, resolveConfiguredFromRequiredCredentialStatuses } from "openclaw/plugin-sdk/channel-status";
13
13
  import { buildMutableAllowEntryDetector, collectStandardAllowlistLists, createConditionalWarningCollector, createDangerousNameMatchingMutableAllowlistWarningCollector, createOpenProviderConfiguredRouteWarningCollector } from "openclaw/plugin-sdk/channel-policy";
14
+ import { identityEntryAuthenticationClassifier } from "openclaw/plugin-sdk/channel-ingress-runtime";
14
15
  import { describeAccountSnapshot } from "openclaw/plugin-sdk/account-helpers";
15
16
  import { asObjectRecord } from "openclaw/plugin-sdk/runtime-doctor-migrations";
16
17
  //#region extensions/slack/src/channel-api.ts
@@ -45,6 +46,7 @@ const resolveSlackDmPolicy = createScopedDmSecurityResolver({
45
46
  })
46
47
  }),
47
48
  policyPathSuffix: "dmPolicy",
49
+ classifyEntryAuthentication: identityEntryAuthenticationClassifier(slackIngressIdentity),
48
50
  normalizeEntry: (raw) => raw.trim().replace(/^(slack|user):/i, "").trim()
49
51
  });
50
52
  const collectSlackSecurityWarnings = createOpenProviderConfiguredRouteWarningCollector({
@@ -1,7 +1,7 @@
1
- import { r as deliverSlackSlashReplies$1, s as sanitizeSlackMonitorReplyPayload } from "./replies-D9XMM_S0.js";
1
+ import { o as sanitizeSlackMonitorReplyPayload, r as deliverSlackSlashReplies$1 } from "./replies-DENuTcPO.js";
2
2
  import { resolveAgentRoute as resolveAgentRoute$1 } from "openclaw/plugin-sdk/routing";
3
- import { resolveConversationLabel as resolveConversationLabel$1 } from "openclaw/plugin-sdk/conversation-runtime";
4
3
  import { resolveMarkdownTableMode as resolveMarkdownTableMode$1 } from "openclaw/plugin-sdk/markdown-table-runtime";
4
+ import { resolveConversationLabel as resolveConversationLabel$1 } from "openclaw/plugin-sdk/conversation-runtime";
5
5
  import { dispatchChannelInboundTurn as dispatchChannelInboundTurn$1, isChannelPartialDeliveryError as isChannelPartialDeliveryError$1 } from "openclaw/plugin-sdk/channel-inbound";
6
6
  import { finalizeInboundContext as finalizeInboundContext$1, resolveChunkMode as resolveChunkMode$1 } from "openclaw/plugin-sdk/reply-runtime";
7
7
  //#region extensions/slack/src/monitor/slash-dispatch.runtime.ts
@@ -73,19 +73,24 @@ function parseSlackTarget(raw, options = {}) {
73
73
  atUserErrorMessage: "Slack DMs require a user id (use user:<id> or <@id>)"
74
74
  });
75
75
  if (userTarget) return userTarget;
76
- if (trimmed.startsWith("#")) return buildMessagingTarget("channel", ensureTargetId({
77
- candidate: trimmed.slice(1).trim(),
78
- pattern: /^[A-Z0-9]+$/i,
79
- errorMessage: "Slack channels require a channel id (use channel:<id>)"
80
- }), trimmed);
76
+ if (trimmed.startsWith("#")) {
77
+ const candidate = trimmed.slice(1).trim();
78
+ const id = ensureTargetId({
79
+ candidate,
80
+ pattern: /^[A-Z0-9]+$/i,
81
+ errorMessage: "Slack channels require a channel id (use channel:<id>)"
82
+ });
83
+ return buildMessagingTarget("channel", id, trimmed);
84
+ }
81
85
  if (isUnambiguousSlackUserId(trimmed)) return buildMessagingTarget("user", trimmed, trimmed);
82
86
  if (options.defaultKind) return buildMessagingTarget(options.defaultKind, trimmed, trimmed);
83
87
  return buildMessagingTarget("channel", trimmed, trimmed);
84
88
  }
85
89
  function resolveSlackChannelId(raw) {
90
+ const target = parseSlackTarget(raw, { defaultKind: "channel" });
86
91
  return canonicalizeSlackApiTargetId("channel", requireTargetKind({
87
92
  platform: "Slack",
88
- target: parseSlackTarget(raw, { defaultKind: "channel" }),
93
+ target,
89
94
  kind: "channel"
90
95
  }), raw);
91
96
  }
@@ -1,4 +1,4 @@
1
- import { a as parseSlackTarget, s as slackTargetsMatch } from "./target-parsing-BnMD2ZqZ.js";
1
+ import { a as parseSlackTarget, s as slackTargetsMatch } from "./target-parsing-PbxGDbr9.js";
2
2
  //#region extensions/slack/src/targets.ts
3
3
  function matchesResolvedUserTarget(target, currentMessagingTarget) {
4
4
  const resolvedId = target.trim();
@@ -1,6 +1,10 @@
1
1
  import { normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
2
2
  //#region extensions/slack/src/thread-ts.ts
3
3
  const SLACK_THREAD_TS_PATTERN = /^\d+\.\d+$/;
4
+ function resolveSlackReplyThreadTs(params) {
5
+ const replyToId = params.replyToMode === "off" ? void 0 : params.replyToId;
6
+ return params.replyToCurrent || params.replyToIsExplicit === false ? params.threadId ?? replyToId : replyToId ?? params.threadId;
7
+ }
4
8
  function normalizeSlackThreadTsCandidate(value) {
5
9
  if (typeof value !== "string") return;
6
10
  const normalized = normalizeOptionalString(value);
@@ -10,4 +14,4 @@ function resolveSlackThreadTsValue(params) {
10
14
  return normalizeSlackThreadTsCandidate(params.replyToId) ?? normalizeSlackThreadTsCandidate(params.threadId);
11
15
  }
12
16
  //#endregion
13
- export { resolveSlackThreadTsValue as n, normalizeSlackThreadTsCandidate as t };
17
+ export { resolveSlackReplyThreadTs as n, resolveSlackThreadTsValue as r, normalizeSlackThreadTsCandidate as t };
@@ -0,0 +1,54 @@
1
+ /*!
2
+ * negotiator
3
+ * Copyright(c) 2026 Blake Embrey
4
+ * MIT Licensed
5
+ */
6
+
7
+ 'use strict';
8
+
9
+ var contentType = require('content-type');
10
+
11
+ /**
12
+ * Module exports.
13
+ * @private
14
+ */
15
+
16
+ module.exports = parseAccept;
17
+
18
+ /**
19
+ * Parse an Accept-style header.
20
+ * @private
21
+ */
22
+
23
+ function parseAccept(header) {
24
+ var values = [];
25
+ var index = 0;
26
+
27
+ while (index < header.length) {
28
+ var start = skipOptionalWhitespace(header, index);
29
+ var parsed = contentType.parse(header, { comma: true, start: start });
30
+
31
+ // `content-type` normalizes the type, but accept methods return original casing.
32
+ parsed.type = header.slice(start, start + parsed.type.length);
33
+ values.push(parsed);
34
+
35
+ index = parsed.index + 1;
36
+ }
37
+
38
+ return values;
39
+ }
40
+
41
+ /**
42
+ * Skip optional whitespace.
43
+ * @private
44
+ */
45
+
46
+ function skipOptionalWhitespace(header, index) {
47
+ var cursor = index;
48
+
49
+ while (header.charCodeAt(cursor) === 0x20 || header.charCodeAt(cursor) === 0x09) {
50
+ cursor++;
51
+ }
52
+
53
+ return cursor;
54
+ }
@@ -8,6 +8,8 @@
8
8
 
9
9
  'use strict';
10
10
 
11
+ var parseAccept = require('./accept');
12
+
11
13
  /**
12
14
  * Module exports.
13
15
  * @public
@@ -21,55 +23,29 @@ module.exports.preferredCharsets = preferredCharsets;
21
23
  * @private
22
24
  */
23
25
 
24
- var simpleCharsetRegExp = /^\s*([^\s;]+)\s*(?:;(.*))?$/;
25
-
26
- /**
27
- * Parse the Accept-Charset header.
28
- * @private
29
- */
30
-
31
26
  function parseAcceptCharset(accept) {
32
- var accepts = accept.split(',');
27
+ var accepts = parseAccept(accept);
33
28
 
34
29
  for (var i = 0, j = 0; i < accepts.length; i++) {
35
- var charset = parseCharset(accepts[i].trim(), i);
36
-
37
- if (charset) {
38
- accepts[j++] = charset;
39
- }
30
+ var charset = formatCharset(accepts[i], i);
31
+ if (charset) accepts[j++] = charset;
40
32
  }
41
33
 
42
- // trim accepts
43
34
  accepts.length = j;
44
-
45
35
  return accepts;
46
36
  }
47
37
 
48
38
  /**
49
- * Parse a charset from the Accept-Charset header.
39
+ * Format a parsed charset for negotiation.
50
40
  * @private
51
41
  */
52
42
 
53
- function parseCharset(str, i) {
54
- var match = simpleCharsetRegExp.exec(str);
55
- if (!match) return null;
56
-
57
- var charset = match[1];
58
- var q = 1;
59
- if (match[2]) {
60
- var params = match[2].split(';')
61
- for (var j = 0; j < params.length; j++) {
62
- var p = params[j].trim().split('=');
63
- if (p[0] === 'q') {
64
- q = parseFloat(p[1]);
65
- break;
66
- }
67
- }
68
- }
43
+ function formatCharset(parsed, i) {
44
+ if (!parsed.type) return null;
69
45
 
70
46
  return {
71
- charset: charset,
72
- q: q,
47
+ charset: parsed.type,
48
+ q: parsed.parameters.q ? parseFloat(parsed.parameters.q) : 1,
73
49
  i: i
74
50
  };
75
51
  }
@@ -8,6 +8,8 @@
8
8
 
9
9
  'use strict';
10
10
 
11
+ var parseAccept = require('./accept');
12
+
11
13
  /**
12
14
  * Module exports.
13
15
  * @public
@@ -21,20 +23,13 @@ module.exports.preferredEncodings = preferredEncodings;
21
23
  * @private
22
24
  */
23
25
 
24
- var simpleEncodingRegExp = /^\s*([^\s;]+)\s*(?:;(.*))?$/;
25
-
26
- /**
27
- * Parse the Accept-Encoding header.
28
- * @private
29
- */
30
-
31
26
  function parseAcceptEncoding(accept) {
32
- var accepts = accept.split(',');
27
+ var accepts = parseAccept(accept);
33
28
  var hasIdentity = false;
34
29
  var minQuality = 1;
35
30
 
36
31
  for (var i = 0, j = 0; i < accepts.length; i++) {
37
- var encoding = parseEncoding(accepts[i].trim(), i);
32
+ var encoding = formatEncoding(accepts[i], i);
38
33
 
39
34
  if (encoding) {
40
35
  accepts[j++] = encoding;
@@ -55,37 +50,21 @@ function parseAcceptEncoding(accept) {
55
50
  };
56
51
  }
57
52
 
58
- // trim accepts
59
53
  accepts.length = j;
60
-
61
54
  return accepts;
62
55
  }
63
56
 
64
57
  /**
65
- * Parse an encoding from the Accept-Encoding header.
58
+ * Format a parsed encoding for negotiation.
66
59
  * @private
67
60
  */
68
61
 
69
- function parseEncoding(str, i) {
70
- var match = simpleEncodingRegExp.exec(str);
71
- if (!match) return null;
72
-
73
- var encoding = match[1];
74
- var q = 1;
75
- if (match[2]) {
76
- var params = match[2].split(';');
77
- for (var j = 0; j < params.length; j++) {
78
- var p = params[j].trim().split('=');
79
- if (p[0] === 'q') {
80
- q = parseFloat(p[1]);
81
- break;
82
- }
83
- }
84
- }
62
+ function formatEncoding(parsed, i) {
63
+ if (!parsed.type) return null;
85
64
 
86
65
  return {
87
- encoding: encoding,
88
- q: q,
66
+ encoding: parsed.type,
67
+ q: parsed.parameters.q ? parseFloat(parsed.parameters.q) : 1,
89
68
  i: i
90
69
  };
91
70
  }
@@ -8,6 +8,9 @@
8
8
 
9
9
  'use strict';
10
10
 
11
+ var contentType = require('content-type');
12
+ var parseAccept = require('./accept');
13
+
11
14
  /**
12
15
  * Module exports.
13
16
  * @public
@@ -21,60 +24,36 @@ module.exports.preferredLanguages = preferredLanguages;
21
24
  * @private
22
25
  */
23
26
 
24
- var simpleLanguageRegExp = /^\s*([^\s\-;]+)(?:-([^\s;]+))?\s*(?:;(.*))?$/;
25
-
26
- /**
27
- * Parse the Accept-Language header.
28
- * @private
29
- */
30
-
31
27
  function parseAcceptLanguage(accept) {
32
- var accepts = accept.split(',');
28
+ var accepts = parseAccept(accept);
33
29
 
34
30
  for (var i = 0, j = 0; i < accepts.length; i++) {
35
- var language = parseLanguage(accepts[i].trim(), i);
36
-
37
- if (language) {
38
- accepts[j++] = language;
39
- }
31
+ var language = formatLanguage(accepts[i], i);
32
+ if (language) accepts[j++] = language;
40
33
  }
41
34
 
42
- // trim accepts
43
35
  accepts.length = j;
44
-
45
36
  return accepts;
46
37
  }
47
38
 
48
39
  /**
49
- * Parse a language from the Accept-Language header.
40
+ * Format a parsed language for negotiation.
50
41
  * @private
51
42
  */
52
43
 
53
- function parseLanguage(str, i) {
54
- var match = simpleLanguageRegExp.exec(str);
55
- if (!match) return null;
56
-
57
- var prefix = match[1]
58
- var suffix = match[2]
59
- var full = prefix
44
+ function formatLanguage(parsed, i) {
45
+ if (!parsed.type) return null;
60
46
 
61
- if (suffix) full += "-" + suffix;
62
-
63
- var q = 1;
64
- if (match[3]) {
65
- var params = match[3].split(';')
66
- for (var j = 0; j < params.length; j++) {
67
- var p = params[j].split('=');
68
- if (p[0] === 'q') q = parseFloat(p[1]);
69
- }
70
- }
47
+ var hyphen = parsed.type.indexOf('-');
48
+ var prefix = hyphen === -1 ? parsed.type : parsed.type.slice(0, hyphen);
49
+ var suffix = hyphen === -1 ? undefined : parsed.type.slice(hyphen + 1);
71
50
 
72
51
  return {
73
52
  prefix: prefix,
74
53
  suffix: suffix,
75
- q: q,
54
+ q: parsed.parameters.q ? parseFloat(parsed.parameters.q) : 1,
76
55
  i: i,
77
- full: full
56
+ full: parsed.type
78
57
  };
79
58
  }
80
59
 
@@ -103,7 +82,7 @@ function getLanguagePriority(language, accepted, index) {
103
82
  */
104
83
 
105
84
  function specify(language, spec, index) {
106
- var p = parseLanguage(language)
85
+ var p = formatLanguage(contentType.parse(language), 0)
107
86
  if (!p) return null;
108
87
  var s = 0;
109
88
  if(spec.full.toLowerCase() === p.full.toLowerCase()){
@@ -8,6 +8,9 @@
8
8
 
9
9
  'use strict';
10
10
 
11
+ var contentType = require('content-type');
12
+ var parseAcceptHeader = require('./accept');
13
+
11
14
  /**
12
15
  * Module exports.
13
16
  * @public
@@ -21,71 +24,35 @@ module.exports.preferredMediaTypes = preferredMediaTypes;
21
24
  * @private
22
25
  */
23
26
 
24
- var simpleMediaTypeRegExp = /^\s*([^\s\/;]+)\/([^;\s]+)\s*(?:;(.*))?$/;
25
-
26
- /**
27
- * Parse the Accept header.
28
- * @private
29
- */
30
-
31
27
  function parseAccept(accept) {
32
- var accepts = splitMediaTypes(accept);
28
+ var accepts = parseAcceptHeader(accept);
33
29
 
34
30
  for (var i = 0, j = 0; i < accepts.length; i++) {
35
- var mediaType = parseMediaType(accepts[i].trim(), i);
36
-
37
- if (mediaType) {
38
- accepts[j++] = mediaType;
39
- }
31
+ var mediaType = formatMediaType(accepts[i], i);
32
+ if (mediaType) accepts[j++] = mediaType;
40
33
  }
41
34
 
42
- // trim accepts
43
35
  accepts.length = j;
44
-
45
36
  return accepts;
46
37
  }
47
38
 
48
39
  /**
49
- * Parse a media type from the Accept header.
40
+ * Format a parsed content type for negotiation.
50
41
  * @private
51
42
  */
52
43
 
53
- function parseMediaType(str, i) {
54
- var match = simpleMediaTypeRegExp.exec(str);
55
- if (!match) return null;
56
-
57
- var params = Object.create(null);
58
- var q = 1;
59
- var subtype = match[2];
60
- var type = match[1];
61
-
62
- if (match[3]) {
63
- var kvps = splitParameters(match[3]).map(splitKeyValuePair);
64
-
65
- for (var j = 0; j < kvps.length; j++) {
66
- var pair = kvps[j];
67
- var key = pair[0].toLowerCase();
68
- var val = pair[1];
44
+ function formatMediaType(parsed, i) {
45
+ var slash = parsed.type.indexOf('/');
46
+ if (slash === -1) return null;
69
47
 
70
- // get the value, unwrapping quotes
71
- var value = val && val[0] === '"' && val[val.length - 1] === '"'
72
- ? val.slice(1, -1)
73
- : val;
48
+ var q = parsed.parameters.q ? parseFloat(parsed.parameters.q) : 1;
74
49
 
75
- if (key === 'q') {
76
- q = parseFloat(value);
77
- break;
78
- }
79
-
80
- // store parameter
81
- params[key] = value;
82
- }
83
- }
50
+ delete parsed.parameters.q;
84
51
 
85
52
  return {
86
- type: type,
87
- subtype: subtype,
88
- params: params,
53
+ type: parsed.type.slice(0, slash),
54
+ subtype: parsed.type.slice(slash + 1),
55
+ params: parsed.parameters,
89
56
  q: q,
90
57
  i: i
91
58
  };
@@ -116,7 +83,7 @@ function getMediaTypePriority(type, accepted, index) {
116
83
  */
117
84
 
118
85
  function specify(type, spec, index) {
119
- var p = parseMediaType(type);
86
+ var p = formatMediaType(contentType.parse(type), 0);
120
87
  var s = 0;
121
88
 
122
89
  if (!p) {
@@ -207,88 +174,3 @@ function getFullType(spec) {
207
174
  function isQuality(spec) {
208
175
  return spec.q > 0;
209
176
  }
210
-
211
- /**
212
- * Count the number of quotes in a string.
213
- * @private
214
- */
215
-
216
- function quoteCount(string) {
217
- var count = 0;
218
- var index = 0;
219
-
220
- while ((index = string.indexOf('"', index)) !== -1) {
221
- count++;
222
- index++;
223
- }
224
-
225
- return count;
226
- }
227
-
228
- /**
229
- * Split a key value pair.
230
- * @private
231
- */
232
-
233
- function splitKeyValuePair(str) {
234
- var index = str.indexOf('=');
235
- var key;
236
- var val;
237
-
238
- if (index === -1) {
239
- key = str;
240
- } else {
241
- key = str.slice(0, index);
242
- val = str.slice(index + 1);
243
- }
244
-
245
- return [key, val];
246
- }
247
-
248
- /**
249
- * Split an Accept header into media types.
250
- * @private
251
- */
252
-
253
- function splitMediaTypes(accept) {
254
- var accepts = accept.split(',');
255
-
256
- for (var i = 1, j = 0; i < accepts.length; i++) {
257
- if (quoteCount(accepts[j]) % 2 == 0) {
258
- accepts[++j] = accepts[i];
259
- } else {
260
- accepts[j] += ',' + accepts[i];
261
- }
262
- }
263
-
264
- // trim accepts
265
- accepts.length = j + 1;
266
-
267
- return accepts;
268
- }
269
-
270
- /**
271
- * Split a string of parameters.
272
- * @private
273
- */
274
-
275
- function splitParameters(str) {
276
- var parameters = str.split(';');
277
-
278
- for (var i = 1, j = 0; i < parameters.length; i++) {
279
- if (quoteCount(parameters[j]) % 2 == 0) {
280
- parameters[++j] = parameters[i];
281
- } else {
282
- parameters[j] += ';' + parameters[i];
283
- }
284
- }
285
-
286
- // trim parameters
287
- parameters.length = j + 1;
288
-
289
- for (var i = 0; i < parameters.length; i++) {
290
- parameters[i] = parameters[i].trim();
291
- }
292
-
293
- return parameters;
294
- }
@@ -0,0 +1,22 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2015 Douglas Christopher Wilson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.