@doist/comms-sdk 2.0.2 → 3.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.
Files changed (49) hide show
  1. package/dist/esm/transport/fetch-with-retry.js +44 -2
  2. package/dist/esm/types/errors.js +2 -2
  3. package/dist/esm/utils/url-helpers.js +104 -16
  4. package/dist/types/types/errors.d.ts +1 -1
  5. package/dist/types/utils/url-helpers.d.ts +41 -0
  6. package/package.json +5 -10
  7. package/dist/cjs/authentication.js +0 -256
  8. package/dist/cjs/clients/add-comment-helper.js +0 -43
  9. package/dist/cjs/clients/attachments-client.js +0 -71
  10. package/dist/cjs/clients/base-client.js +0 -33
  11. package/dist/cjs/clients/channels-client.js +0 -211
  12. package/dist/cjs/clients/comments-client.js +0 -175
  13. package/dist/cjs/clients/conversation-messages-client.js +0 -169
  14. package/dist/cjs/clients/conversations-client.js +0 -283
  15. package/dist/cjs/clients/groups-client.js +0 -172
  16. package/dist/cjs/clients/hooks-client.js +0 -52
  17. package/dist/cjs/clients/inbox-client.js +0 -184
  18. package/dist/cjs/clients/notify-audience.js +0 -45
  19. package/dist/cjs/clients/reactions-client.js +0 -97
  20. package/dist/cjs/clients/search-client.js +0 -138
  21. package/dist/cjs/clients/threads-client.js +0 -364
  22. package/dist/cjs/clients/users-client.js +0 -326
  23. package/dist/cjs/clients/workspace-users-client.js +0 -252
  24. package/dist/cjs/clients/workspaces-client.js +0 -174
  25. package/dist/cjs/comms-api.js +0 -70
  26. package/dist/cjs/consts/endpoints.js +0 -34
  27. package/dist/cjs/index.js +0 -53
  28. package/dist/cjs/migration.js +0 -96
  29. package/dist/cjs/package.json +0 -1
  30. package/dist/cjs/testUtils/msw-handlers.js +0 -51
  31. package/dist/cjs/testUtils/msw-setup.js +0 -35
  32. package/dist/cjs/testUtils/obsidian-fetch-adapter.js +0 -53
  33. package/dist/cjs/testUtils/test-defaults.js +0 -106
  34. package/dist/cjs/transport/fetch-with-retry.js +0 -146
  35. package/dist/cjs/transport/http-client.js +0 -56
  36. package/dist/cjs/transport/http-dispatcher.js +0 -190
  37. package/dist/cjs/types/api-version.js +0 -8
  38. package/dist/cjs/types/entities.js +0 -496
  39. package/dist/cjs/types/enums.js +0 -37
  40. package/dist/cjs/types/errors.js +0 -12
  41. package/dist/cjs/types/http.js +0 -4
  42. package/dist/cjs/types/index.js +0 -22
  43. package/dist/cjs/types/requests.js +0 -183
  44. package/dist/cjs/utils/case-conversion.js +0 -54
  45. package/dist/cjs/utils/index.js +0 -19
  46. package/dist/cjs/utils/multipart-upload.js +0 -202
  47. package/dist/cjs/utils/timestamp-conversion.js +0 -58
  48. package/dist/cjs/utils/url-helpers.js +0 -133
  49. package/dist/cjs/utils/uuidv7.js +0 -182
@@ -1,182 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UuidV7Error = void 0;
4
- exports.encodeUuidToBase58 = encodeUuidToBase58;
5
- exports.decodeBase58ToUuidBytes = decodeBase58ToUuidBytes;
6
- exports.generateId = generateId;
7
- exports.resolveReferenceId = resolveReferenceId;
8
- exports.resolveCreateId = resolveCreateId;
9
- exports.isValidUuidV7Base58 = isValidUuidV7Base58;
10
- exports.base58FromUuidString = base58FromUuidString;
11
- exports.uuidStringFromBase58 = uuidStringFromBase58;
12
- const uuid_1 = require("uuid");
13
- /**
14
- * ID utilities for entities that use opaque string identifiers (channels,
15
- * threads, comments, conversations, messages, groups).
16
- *
17
- * Use {@link generateId} to mint a new ID locally and pass it to a creation
18
- * endpoint. {@link encodeUuidToBase58} / {@link decodeBase58ToUuidBytes}
19
- * expose the underlying encoding for callers that need to round-trip raw
20
- * UUID bytes themselves.
21
- */
22
- const BASE58_ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
23
- const BASE58_MAP = (() => {
24
- const map = {};
25
- for (let i = 0; i < BASE58_ALPHABET.length; i++) {
26
- map[BASE58_ALPHABET[i]] = i;
27
- }
28
- return map;
29
- })();
30
- const UUID_BYTES_LEN = 16;
31
- const UUID_BASE58_MAX_LEN = 22;
32
- const HEX_RE = /^[0-9a-f]+$/;
33
- class UuidV7Error extends Error {
34
- constructor(message) {
35
- super(message);
36
- this.name = 'UuidV7Error';
37
- }
38
- }
39
- exports.UuidV7Error = UuidV7Error;
40
- /** Encode a 16-byte UUID as a base58 string. */
41
- function encodeUuidToBase58(bytes) {
42
- if (bytes.length !== UUID_BYTES_LEN) {
43
- throw new UuidV7Error(`id must be ${UUID_BYTES_LEN} bytes`);
44
- }
45
- let zeros = 0;
46
- while (zeros < bytes.length && bytes[zeros] === 0) {
47
- zeros++;
48
- }
49
- let n = 0n;
50
- for (const b of bytes) {
51
- n = (n << 8n) | BigInt(b);
52
- }
53
- let out = '';
54
- while (n > 0n) {
55
- const rem = Number(n % 58n);
56
- out = BASE58_ALPHABET[rem] + out;
57
- n /= 58n;
58
- }
59
- return '1'.repeat(zeros) + out;
60
- }
61
- /**
62
- * Decode a base58 string back into 16 UUID bytes. Throws {@link UuidV7Error}
63
- * if the input is malformed or doesn't decode to exactly 16 bytes.
64
- */
65
- function decodeBase58ToUuidBytes(value) {
66
- if (typeof value !== 'string') {
67
- throw new UuidV7Error('id must be a base58 string');
68
- }
69
- if (value.length === 0) {
70
- throw new UuidV7Error('id is empty');
71
- }
72
- if (value.length > UUID_BASE58_MAX_LEN) {
73
- throw new UuidV7Error('id is too long');
74
- }
75
- let zeros = 0;
76
- while (zeros < value.length && value[zeros] === '1') {
77
- zeros++;
78
- }
79
- let n = 0n;
80
- for (let i = 0; i < value.length; i++) {
81
- const ch = value[i];
82
- const v = BASE58_MAP[ch];
83
- if (v === undefined) {
84
- throw new UuidV7Error(`invalid base58 character: '${ch}'`);
85
- }
86
- n = n * 58n + BigInt(v);
87
- }
88
- const raw = [];
89
- while (n > 0n) {
90
- raw.unshift(Number(n & 0xffn));
91
- n >>= 8n;
92
- }
93
- const padded = new Uint8Array(zeros + raw.length);
94
- padded.set(raw, zeros);
95
- if (padded.length !== UUID_BYTES_LEN) {
96
- throw new UuidV7Error(`id must decode to ${UUID_BYTES_LEN} bytes`);
97
- }
98
- return padded;
99
- }
100
- function hexToBytes(hex) {
101
- const out = new Uint8Array(hex.length / 2);
102
- for (let i = 0; i < out.length; i++) {
103
- out[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
104
- }
105
- return out;
106
- }
107
- /**
108
- * Mint a fresh ID. Callers should generate one of these locally when
109
- * creating a new channel / thread / comment / conversation / message /
110
- * group — the backend requires the client to supply the ID on create.
111
- */
112
- function generateId() {
113
- const hex = (0, uuid_1.v7)().replace(/-/g, '');
114
- return encodeUuidToBase58(hexToBytes(hex));
115
- }
116
- /** Validate an existing entity ID without minting a replacement. */
117
- function resolveReferenceId(id, fieldName) {
118
- if (!isValidUuidV7Base58(id)) {
119
- throw new UuidV7Error(`invalid ${fieldName} ${JSON.stringify(id)} — use a base58 UUIDv7 value for \`${fieldName}\`.`);
120
- }
121
- return id;
122
- }
123
- /**
124
- * Resolve the `id` for a create-style API call: validate the caller-supplied
125
- * value (throwing {@link UuidV7Error} before the request leaves the SDK) or
126
- * mint a fresh one via {@link generateId}.
127
- */
128
- function resolveCreateId(id) {
129
- if (id === undefined)
130
- return generateId();
131
- if (!isValidUuidV7Base58(id)) {
132
- throw new UuidV7Error(`invalid id ${JSON.stringify(id)} — use generateId() or omit \`id\` and let the SDK mint one.`);
133
- }
134
- return id;
135
- }
136
- /**
137
- * Validate that a value matches the expected ID format (the decoded bytes
138
- * have the v7 version nibble + RFC 4122/9562 variant bits). Does NOT
139
- * validate the embedded timestamp — the backend may still reject a value
140
- * that is too far in the future or past.
141
- */
142
- function isValidUuidV7Base58(value) {
143
- if (typeof value !== 'string')
144
- return false;
145
- let bytes;
146
- try {
147
- bytes = decodeBase58ToUuidBytes(value);
148
- }
149
- catch {
150
- return false;
151
- }
152
- const versionNibble = bytes[6] & 0xf0;
153
- const variantBits = bytes[8] & 0xc0;
154
- return versionNibble === 0x70 && variantBits === 0x80;
155
- }
156
- /**
157
- * Encode a canonical UUID string (hyphenated or not, any case) as a
158
- * wire-format ID. Useful when interoperating with systems that hand you
159
- * UUIDs in canonical form.
160
- */
161
- function base58FromUuidString(uuid) {
162
- const stripped = uuid.replace(/-/g, '').toLowerCase();
163
- if (stripped.length !== 32 || !HEX_RE.test(stripped)) {
164
- throw new UuidV7Error('not a valid UUID string');
165
- }
166
- return encodeUuidToBase58(hexToBytes(stripped));
167
- }
168
- /**
169
- * Inverse of {@link base58FromUuidString}: takes a wire-format ID and
170
- * returns the canonical hyphenated UUID string.
171
- */
172
- function uuidStringFromBase58(value) {
173
- const bytes = decodeBase58ToUuidBytes(value);
174
- const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, '0')).join('');
175
- return [
176
- hex.slice(0, 8),
177
- hex.slice(8, 12),
178
- hex.slice(12, 16),
179
- hex.slice(16, 20),
180
- hex.slice(20, 32),
181
- ].join('-');
182
- }