hbsig 0.0.1
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/cjs/bin_to_str.js +44 -0
- package/cjs/collect-body-keys.js +470 -0
- package/cjs/encode-array-item.js +110 -0
- package/cjs/encode-utils.js +236 -0
- package/cjs/encode.js +1318 -0
- package/cjs/erl_json.js +317 -0
- package/cjs/erl_str.js +1037 -0
- package/cjs/flat.js +222 -0
- package/cjs/http-message-signatures/httpbis.js +489 -0
- package/cjs/http-message-signatures/index.js +25 -0
- package/cjs/http-message-signatures/structured-header.js +129 -0
- package/cjs/httpsig.js +716 -0
- package/cjs/httpsig2.js +1160 -0
- package/cjs/id.js +470 -0
- package/cjs/index.js +63 -0
- package/cjs/send.js +194 -0
- package/cjs/signer-utils.js +617 -0
- package/cjs/signer.js +606 -0
- package/cjs/structured.js +296 -0
- package/cjs/test.js +27 -0
- package/cjs/utils.js +42 -0
- package/esm/bin_to_str.js +46 -0
- package/esm/collect-body-keys.js +436 -0
- package/esm/encode-array-item.js +112 -0
- package/esm/encode-utils.js +185 -0
- package/esm/encode.js +1219 -0
- package/esm/erl_json.js +289 -0
- package/esm/erl_str.js +1139 -0
- package/esm/flat.js +196 -0
- package/esm/http-message-signatures/httpbis.js +438 -0
- package/esm/http-message-signatures/index.js +4 -0
- package/esm/http-message-signatures/structured-header.js +105 -0
- package/esm/httpsig.js +658 -0
- package/esm/httpsig2.js +1097 -0
- package/esm/id.js +459 -0
- package/esm/index.js +4 -0
- package/esm/package.json +3 -0
- package/esm/send.js +124 -0
- package/esm/signer-utils.js +494 -0
- package/esm/signer.js +452 -0
- package/esm/structured.js +269 -0
- package/esm/test.js +6 -0
- package/esm/utils.js +28 -0
- package/package.json +28 -0
package/cjs/flat.js
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.flat_from = flat_from;
|
|
7
|
+
exports.flat_to = flat_to;
|
|
8
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
9
|
+
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
10
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
11
|
+
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
12
|
+
function _toArray(r) { return _arrayWithHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableRest(); }
|
|
13
|
+
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
14
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
15
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
16
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
17
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
18
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
19
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
20
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
21
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
22
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
23
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
24
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
25
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
26
|
+
/**
|
|
27
|
+
* A codec for turning nested objects into/from flat objects that have
|
|
28
|
+
* (potentially multi-layer) paths as their keys, and values as their values.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Convert a flat map to a nested object.
|
|
33
|
+
* @param {Object|string} input - Either a flat object or a serialized string
|
|
34
|
+
* @returns {Object} - Nested object
|
|
35
|
+
*/
|
|
36
|
+
function flat_from(input) {
|
|
37
|
+
if (typeof input === "string" || input instanceof Buffer) {
|
|
38
|
+
// If input is binary/string, deserialize it first
|
|
39
|
+
return deserialize(input).ok;
|
|
40
|
+
}
|
|
41
|
+
if (_typeof(input) !== "object" || input === null) {
|
|
42
|
+
throw new Error("Input must be an object or string");
|
|
43
|
+
}
|
|
44
|
+
var result = {};
|
|
45
|
+
for (var _i = 0, _Object$entries = Object.entries(input); _i < _Object$entries.length; _i++) {
|
|
46
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
47
|
+
pathKey = _Object$entries$_i[0],
|
|
48
|
+
value = _Object$entries$_i[1];
|
|
49
|
+
var pathParts = pathToParts(pathKey);
|
|
50
|
+
injectAtPath(pathParts, value, result);
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Convert a nested object to a flat map.
|
|
57
|
+
* @param {Object|string} input - Either a nested object or a binary string (passthrough)
|
|
58
|
+
* @returns {Object|string} - Flat object or passthrough string
|
|
59
|
+
*/
|
|
60
|
+
function flat_to(input) {
|
|
61
|
+
if (typeof input === "string" || input instanceof Buffer) {
|
|
62
|
+
// Binary passthrough
|
|
63
|
+
return input;
|
|
64
|
+
}
|
|
65
|
+
if (_typeof(input) !== "object" || input === null) {
|
|
66
|
+
throw new Error("Input must be an object or string");
|
|
67
|
+
}
|
|
68
|
+
var result = {};
|
|
69
|
+
flattenRecursive(input, [], result);
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Helper function to convert a path string to path parts
|
|
75
|
+
* @param {string|Array} path - Path string like "a/b/c" or array of parts
|
|
76
|
+
* @returns {Array} - Array of path parts
|
|
77
|
+
*/
|
|
78
|
+
function pathToParts(path) {
|
|
79
|
+
if (Array.isArray(path)) {
|
|
80
|
+
// Handle array paths
|
|
81
|
+
if (path.length === 1 && Array.isArray(path[0])) {
|
|
82
|
+
return path[0];
|
|
83
|
+
}
|
|
84
|
+
return path;
|
|
85
|
+
}
|
|
86
|
+
if (typeof path === "string") {
|
|
87
|
+
// Split by '/' but handle edge cases
|
|
88
|
+
return path.split("/");
|
|
89
|
+
}
|
|
90
|
+
throw new Error("Path must be a string or array");
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Helper function to inject a value at a specific path in a nested object
|
|
95
|
+
* @param {Array} pathParts - Array of path parts
|
|
96
|
+
* @param {*} value - Value to inject
|
|
97
|
+
* @param {Object} obj - Object to inject into
|
|
98
|
+
*/
|
|
99
|
+
function injectAtPath(pathParts, value, obj) {
|
|
100
|
+
if (pathParts.length === 0) {
|
|
101
|
+
throw new Error("Path cannot be empty");
|
|
102
|
+
}
|
|
103
|
+
if (pathParts.length === 1) {
|
|
104
|
+
var _key = pathParts[0];
|
|
105
|
+
if (_key in obj) {
|
|
106
|
+
var existing = obj[_key];
|
|
107
|
+
|
|
108
|
+
// If both are objects, merge them
|
|
109
|
+
if (_typeof(existing) === "object" && existing !== null && _typeof(value) === "object" && value !== null && !Array.isArray(existing) && !Array.isArray(value)) {
|
|
110
|
+
obj[_key] = _objectSpread(_objectSpread({}, existing), value);
|
|
111
|
+
} else {
|
|
112
|
+
// Path collision
|
|
113
|
+
throw new Error("Path collision at key: ".concat(_key, ", existing: ").concat(JSON.stringify(existing), ", value: ").concat(JSON.stringify(value)));
|
|
114
|
+
}
|
|
115
|
+
} else {
|
|
116
|
+
obj[_key] = value;
|
|
117
|
+
}
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
var _pathParts = _toArray(pathParts),
|
|
121
|
+
key = _pathParts[0],
|
|
122
|
+
rest = _pathParts.slice(1);
|
|
123
|
+
if (!(key in obj)) {
|
|
124
|
+
obj[key] = {};
|
|
125
|
+
} else if (_typeof(obj[key]) !== "object" || obj[key] === null) {
|
|
126
|
+
throw new Error("Cannot create nested path at non-object key: ".concat(key));
|
|
127
|
+
}
|
|
128
|
+
injectAtPath(rest, value, obj[key]);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Helper function to recursively flatten an object
|
|
133
|
+
* @param {*} value - Current value
|
|
134
|
+
* @param {Array} currentPath - Current path parts
|
|
135
|
+
* @param {Object} result - Result object to populate
|
|
136
|
+
*/
|
|
137
|
+
function flattenRecursive(value, currentPath, result) {
|
|
138
|
+
if (_typeof(value) === "object" && value !== null && !Array.isArray(value)) {
|
|
139
|
+
// It's an object, recurse into it
|
|
140
|
+
for (var _i2 = 0, _Object$entries2 = Object.entries(value); _i2 < _Object$entries2.length; _i2++) {
|
|
141
|
+
var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
|
|
142
|
+
key = _Object$entries2$_i[0],
|
|
143
|
+
subValue = _Object$entries2$_i[1];
|
|
144
|
+
var newPath = [].concat(_toConsumableArray(currentPath), [key]);
|
|
145
|
+
flattenRecursive(subValue, newPath, result);
|
|
146
|
+
}
|
|
147
|
+
} else if (typeof value === "string") {
|
|
148
|
+
// It's a string leaf value (matching Erlang binary type)
|
|
149
|
+
if (currentPath.length === 0) {
|
|
150
|
+
throw new Error("Cannot flatten a non-object at root level");
|
|
151
|
+
}
|
|
152
|
+
var pathKey = currentPath.join("/");
|
|
153
|
+
result[pathKey] = value;
|
|
154
|
+
} else {
|
|
155
|
+
// Non-string leaf values cause errors in Erlang codec
|
|
156
|
+
throw new Error("Value type ".concat(_typeof(value), " not supported. Only strings and objects are allowed."));
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Serialize a map to a string format
|
|
162
|
+
* @param {Object} map - The map to serialize
|
|
163
|
+
* @returns {Object} - {ok: string} or {error: string}
|
|
164
|
+
*/
|
|
165
|
+
function serialize(map) {
|
|
166
|
+
try {
|
|
167
|
+
var flattened = flat_to(map);
|
|
168
|
+
var lines = [];
|
|
169
|
+
for (var _i3 = 0, _Object$entries3 = Object.entries(flattened); _i3 < _Object$entries3.length; _i3++) {
|
|
170
|
+
var _Object$entries3$_i = _slicedToArray(_Object$entries3[_i3], 2),
|
|
171
|
+
key = _Object$entries3$_i[0],
|
|
172
|
+
value = _Object$entries3$_i[1];
|
|
173
|
+
lines.push("".concat(key, ": ").concat(value));
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
ok: lines.join("\n") + (lines.length > 0 ? "\n" : "")
|
|
177
|
+
};
|
|
178
|
+
} catch (error) {
|
|
179
|
+
return {
|
|
180
|
+
error: error.message
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Deserialize a string to a map
|
|
187
|
+
* @param {string} input - The string to deserialize
|
|
188
|
+
* @returns {Object} - {ok: Object} or {error: string}
|
|
189
|
+
*/
|
|
190
|
+
function deserialize(input) {
|
|
191
|
+
try {
|
|
192
|
+
var str = input.toString();
|
|
193
|
+
var lines = str.split("\n").filter(function (line) {
|
|
194
|
+
return line.trim();
|
|
195
|
+
});
|
|
196
|
+
var flat = {};
|
|
197
|
+
var _iterator = _createForOfIteratorHelper(lines),
|
|
198
|
+
_step;
|
|
199
|
+
try {
|
|
200
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
201
|
+
var line = _step.value;
|
|
202
|
+
var colonIndex = line.indexOf(": ");
|
|
203
|
+
if (colonIndex !== -1) {
|
|
204
|
+
var key = line.substring(0, colonIndex);
|
|
205
|
+
var value = line.substring(colonIndex + 2);
|
|
206
|
+
flat[key] = value;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
} catch (err) {
|
|
210
|
+
_iterator.e(err);
|
|
211
|
+
} finally {
|
|
212
|
+
_iterator.f();
|
|
213
|
+
}
|
|
214
|
+
return {
|
|
215
|
+
ok: flat_from(flat)
|
|
216
|
+
};
|
|
217
|
+
} catch (error) {
|
|
218
|
+
return {
|
|
219
|
+
error: error.message
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
}
|