@oxidezap/baileyrs 0.2.12 → 0.3.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.
- package/lib/Compatibility/encode-proto.d.ts +7 -3
- package/lib/Compatibility/encode-proto.js +10 -5
- package/lib/Compatibility/proto-runtime.js +54 -7
- package/lib/Compatibility/signal-repository.d.ts +1 -1
- package/lib/Compatibility/signal-repository.js +61 -57
- package/lib/Compatibility/stanza-responses.d.ts +3 -3
- package/lib/Compatibility/stanza-responses.js +16 -13
- package/lib/Socket/blocking.js +11 -9
- package/lib/Socket/bridge-error-boundary.d.ts +2 -2
- package/lib/Socket/bridge-error-boundary.js +2 -2
- package/lib/Socket/business.js +63 -61
- package/lib/Socket/chat-actions.js +102 -98
- package/lib/Socket/client-operations.d.ts +6 -0
- package/lib/Socket/client-operations.js +2 -0
- package/lib/Socket/communities.js +8 -8
- package/lib/Socket/contacts.js +29 -26
- package/lib/Socket/events.js +2 -37
- package/lib/Socket/groups.js +22 -21
- package/lib/Socket/index.d.ts +2 -2
- package/lib/Socket/index.js +163 -107
- package/lib/Socket/internals.js +1 -1
- package/lib/Socket/messages.js +224 -218
- package/lib/Socket/newsletter.js +137 -133
- package/lib/Socket/prekeys.d.ts +1 -1
- package/lib/Socket/prekeys.js +20 -18
- package/lib/Socket/presence.js +15 -13
- package/lib/Socket/privacy.js +10 -10
- package/lib/Socket/profile.js +20 -18
- package/lib/Socket/server-queries.js +4 -4
- package/lib/Socket/terminal-close.d.ts +2 -36
- package/lib/Socket/terminal-close.js +29 -5
- package/lib/Socket/types.d.ts +2 -6
- package/package.json +4 -4
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `encodeProto`, with the
|
|
2
|
+
* `encodeProto`, with the three inputs the bridge codec refuses put back.
|
|
3
3
|
*
|
|
4
4
|
* From 0.8.0 the codec refuses an empty string where the schema declares a
|
|
5
5
|
* 64-bit integer, and an unpaired surrogate in a text field. Both were written
|
|
6
6
|
* before — as `0` and as U+FFFD — and upstream Baileys still encodes both, so a
|
|
7
7
|
* message that used to reach the server would now throw in the caller's face.
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
* The codec also refuses enum names where the schema declares an enum
|
|
9
|
+
* (issue #109: `"NONE"` where an int32 goes on the wire), which upstream's
|
|
10
|
+
* `fromObject` resolves and its direct `encode` coerces — that repair lives in
|
|
11
|
+
* `repairProtoMessage`, next to the other two. This is where all three are
|
|
12
|
+
* absorbed, so the strict contract stays true of the bridge and the tolerant
|
|
13
|
+
* one stays true of this library.
|
|
10
14
|
*
|
|
11
15
|
* Repair on failure rather than check on write: the ordinary encode is exactly
|
|
12
16
|
* the call it was before, with no scan of any field, and the repair runs only
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { encodeProto } from '@oxidezap/whatsapp-rust-bridge';
|
|
2
2
|
import { repairProtoMessage } from './proto-runtime.js';
|
|
3
3
|
/**
|
|
4
|
-
* `encodeProto`, with the
|
|
4
|
+
* `encodeProto`, with the three inputs the bridge codec refuses put back.
|
|
5
5
|
*
|
|
6
6
|
* From 0.8.0 the codec refuses an empty string where the schema declares a
|
|
7
7
|
* 64-bit integer, and an unpaired surrogate in a text field. Both were written
|
|
8
8
|
* before — as `0` and as U+FFFD — and upstream Baileys still encodes both, so a
|
|
9
9
|
* message that used to reach the server would now throw in the caller's face.
|
|
10
|
-
*
|
|
11
|
-
*
|
|
10
|
+
* The codec also refuses enum names where the schema declares an enum
|
|
11
|
+
* (issue #109: `"NONE"` where an int32 goes on the wire), which upstream's
|
|
12
|
+
* `fromObject` resolves and its direct `encode` coerces — that repair lives in
|
|
13
|
+
* `repairProtoMessage`, next to the other two. This is where all three are
|
|
14
|
+
* absorbed, so the strict contract stays true of the bridge and the tolerant
|
|
15
|
+
* one stays true of this library.
|
|
12
16
|
*
|
|
13
17
|
* Repair on failure rather than check on write: the ordinary encode is exactly
|
|
14
18
|
* the call it was before, with no scan of any field, and the repair runs only
|
|
@@ -22,8 +26,9 @@ export const encodeProtoCompat = (path, message) => {
|
|
|
22
26
|
catch (error) {
|
|
23
27
|
const repaired = repairProtoMessage(path, message);
|
|
24
28
|
// Reference equality: nothing was coerced, so the failure is something this
|
|
25
|
-
// does not explain — an unmodelled type, a number no int64 can hold
|
|
26
|
-
// it has to keep propagating rather than be
|
|
29
|
+
// does not explain — an unmodelled type, a number no int64 can hold, an
|
|
30
|
+
// unknown enum name — and it has to keep propagating rather than be
|
|
31
|
+
// retried into a second throw.
|
|
27
32
|
if (repaired === message)
|
|
28
33
|
throw error;
|
|
29
34
|
return encodeProto(path, repaired);
|
|
@@ -53,7 +53,7 @@ const UNPAIRED_SURROGATE = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<|(?<![\uD800-\uDBF
|
|
|
62
62
|
* - An unpaired surrogate in a text field, replaced with U+FFFD. That is the
|
|
63
63
|
* substitution `TextEncoder` used to make, so the bytes are unchanged from what
|
|
64
64
|
* this library sent before.
|
|
65
|
+
* - An enum name where the schema declares an enum (issue #109: `"NONE"` where
|
|
66
|
+
* an int32 goes on the wire). Upstream's `fromObject` resolves names to numbers
|
|
67
|
+
* and its direct `encode` coerces any string with `| 0`, so a caller passing a
|
|
68
|
+
* name never sees a throw. The bridge codec accepts only numbers (numeric
|
|
69
|
+
* strings aside) and throws `invalid int32: "NONE"`. An unknown name is left to
|
|
70
|
+
* throw rather than silenced to `0`: upstream's direct encode would write `0`
|
|
71
|
+
* for it, but that puts a value on the wire nobody sent.
|
|
65
72
|
*
|
|
66
73
|
* Returns `item` itself when it has nothing to do, so the caller can tell a
|
|
67
74
|
* repair from a failure it does not understand.
|
|
@@ -77,6 +84,36 @@ const repairScalar = (kind, item) => {
|
|
|
77
84
|
const replaced = item.replace(UNPAIRED_SURROGATE, '\uFFFD');
|
|
78
85
|
return replaced === item ? item : replaced;
|
|
79
86
|
};
|
|
87
|
+
/**
|
|
88
|
+
* Enum name to wire number, built per enum on the first repair that needs it.
|
|
89
|
+
*
|
|
90
|
+
* Only the repair path reads this, and only for a field that actually holds a
|
|
91
|
+
* string — a message the codec accepts never reaches here, and a numeric enum
|
|
92
|
+
* never touches a map. Each table is built once from the generated entries and
|
|
93
|
+
* then reused; an importer that never sends a refused value allocates nothing.
|
|
94
|
+
* A `Map` (not a plain object) so names like `__proto__` are keys, not hazards.
|
|
95
|
+
*/
|
|
96
|
+
let enumTablesById;
|
|
97
|
+
const enumValueFor = (enumId, name) => {
|
|
98
|
+
if (enumId < 0 || enumId >= PROTO_ENUM_SCHEMAS.length)
|
|
99
|
+
return undefined;
|
|
100
|
+
enumTablesById ?? (enumTablesById = []);
|
|
101
|
+
let byName = enumTablesById[enumId];
|
|
102
|
+
if (byName === undefined) {
|
|
103
|
+
const entries = PROTO_ENUM_SCHEMAS[enumId]?.[1];
|
|
104
|
+
if (!entries)
|
|
105
|
+
return undefined;
|
|
106
|
+
byName = new Map();
|
|
107
|
+
for (let index = 0; index < entries.length; index += 2) {
|
|
108
|
+
const entryName = entries[index];
|
|
109
|
+
const entryValue = entries[index + 1];
|
|
110
|
+
if (typeof entryName === 'string' && typeof entryValue === 'number')
|
|
111
|
+
byName.set(entryName, entryValue);
|
|
112
|
+
}
|
|
113
|
+
enumTablesById[enumId] = byName;
|
|
114
|
+
}
|
|
115
|
+
return byName.get(name);
|
|
116
|
+
};
|
|
80
117
|
const longFromWords = (low, high, unsigned) => LongRuntime.fromBits(low, high, unsigned);
|
|
81
118
|
/**
|
|
82
119
|
* Split a decoded 64-bit value into the low/high words `longFromWords` takes.
|
|
@@ -254,12 +291,13 @@ const schemaIdFor = (path) => {
|
|
|
254
291
|
return schemaIdsByPath.get(path);
|
|
255
292
|
};
|
|
256
293
|
/**
|
|
257
|
-
* Coerces the
|
|
258
|
-
*
|
|
294
|
+
* Coerces the three inputs the bridge codec refuses back to what upstream
|
|
295
|
+
* Baileys writes, and returns `value` itself when there was nothing to coerce.
|
|
259
296
|
*
|
|
260
297
|
* Reference equality is the signal: the caller only reaches here after an
|
|
261
298
|
* encode threw, and an unchanged result means the failure was something else
|
|
262
|
-
* — a genuinely invalid number, a missing codec — which
|
|
299
|
+
* — a genuinely invalid number, an unknown enum name, a missing codec — which
|
|
300
|
+
* must keep propagating.
|
|
263
301
|
*
|
|
264
302
|
* Copy-on-write throughout, like `projectForEncode`: a branch with nothing to
|
|
265
303
|
* fix is shared, not rebuilt.
|
|
@@ -286,7 +324,16 @@ const repairMessage = (schemaId, value, ancestors) => {
|
|
|
286
324
|
const current = value[field[0]];
|
|
287
325
|
if (current === null || current === undefined)
|
|
288
326
|
continue;
|
|
289
|
-
const repair = (item) =>
|
|
327
|
+
const repair = (item) => {
|
|
328
|
+
if (field[1] === PROTO_FIELD_KIND.message)
|
|
329
|
+
return repairMessage(field[2], item, seen);
|
|
330
|
+
// `?? item`, not `|| item`: 0 is a valid wire value (e.g. `"NONE"`).
|
|
331
|
+
// Unknown names stay strings, so the retry still throws and the
|
|
332
|
+
// original failure keeps propagating instead of becoming a silent 0.
|
|
333
|
+
if (field[1] === PROTO_FIELD_KIND.enum && typeof item === 'string')
|
|
334
|
+
return enumValueFor(field[2], item) ?? item;
|
|
335
|
+
return repairScalar(field[1], item);
|
|
336
|
+
};
|
|
290
337
|
let converted = current;
|
|
291
338
|
if (field[3] & PROTO_FIELD_FLAG.repeated) {
|
|
292
339
|
if (Array.isArray(current)) {
|
|
@@ -457,8 +504,8 @@ class ProtoCompatibilityRuntime {
|
|
|
457
504
|
throw new Error(`protobuf codec unavailable for ${path}`);
|
|
458
505
|
const projected = this.projectForEncode(schemaId, message);
|
|
459
506
|
const encoded = sourceCodec.encode(projected);
|
|
460
|
-
// The bridge refuses
|
|
461
|
-
// Baileys still encodes
|
|
507
|
+
// The bridge refuses three inputs it used to accept silently, and upstream
|
|
508
|
+
// Baileys still encodes all three. Repairing on failure rather than checking
|
|
462
509
|
// every field on the way in is what keeps the ordinary encode free: a
|
|
463
510
|
// message the codec accepts never reaches the repair, and one that does
|
|
464
511
|
// not was already going to throw.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { LIDMapping, SignalAuthState, SignalRepositoryWithLIDStore } from '../Types/index.js';
|
|
2
2
|
import type { ILogger } from '../Utils/logger.js';
|
|
3
3
|
import type { SocketContext } from '../Socket/types.js';
|
|
4
|
-
type SignalRepositoryContext = Pick<SocketContext, '
|
|
4
|
+
type SignalRepositoryContext = Pick<SocketContext, 'logger' | 'withClient'>;
|
|
5
5
|
export declare const jidToSignalProtocolAddressCompat: (jid: string) => string;
|
|
6
6
|
export declare const bindSignalRepositoryContext: (auth: SignalAuthState, ctx: SignalRepositoryContext) => void;
|
|
7
7
|
/** Default public factory; the socket binds its native context before invoking it. */
|
|
@@ -34,12 +34,12 @@ export const bindSignalRepositoryContext = (auth, ctx) => {
|
|
|
34
34
|
/** Default public factory; the socket binds its native context before invoking it. */
|
|
35
35
|
export const makeDefaultSignalRepository = (auth, logger, _pnToLIDFunc) => makeSignalRepository({
|
|
36
36
|
logger,
|
|
37
|
-
|
|
37
|
+
withClient: operation => {
|
|
38
38
|
const ctx = nativeContexts.get(auth);
|
|
39
39
|
if (!ctx) {
|
|
40
40
|
return Promise.reject(new Error('Signal repository is not bound to an active socket; pass it through SocketConfig'));
|
|
41
41
|
}
|
|
42
|
-
return ctx.
|
|
42
|
+
return ctx.withClient(operation);
|
|
43
43
|
}
|
|
44
44
|
});
|
|
45
45
|
const resolveMappings = async (client, inputs, direction, ctx) => {
|
|
@@ -69,63 +69,67 @@ const resolveMappings = async (client, inputs, direction, ctx) => {
|
|
|
69
69
|
return mappings.length ? mappings : null;
|
|
70
70
|
};
|
|
71
71
|
/** Translate the neutral bridge Signal surface into the public repository contract. */
|
|
72
|
-
export const makeSignalRepository = (ctx) =>
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
validateSession: async (jid) => ({ exists: await (await ctx.getClient()).signalValidateSession(jid) }),
|
|
94
|
-
jidToSignalProtocolAddress: jidToSignalProtocolAddressCompat,
|
|
95
|
-
migrateSession: async (fromJid, toJid) => {
|
|
96
|
-
if (!fromJid || !isLidNamespace(toJid))
|
|
97
|
-
return { migrated: 0, skipped: 0, total: 0 };
|
|
98
|
-
if (!isPnNamespace(fromJid))
|
|
99
|
-
return { migrated: 0, skipped: 0, total: 1 };
|
|
100
|
-
return (await ctx.getClient()).signalMigrateSessions(fromJid, toJid);
|
|
101
|
-
},
|
|
102
|
-
deleteSession: async (jids) => {
|
|
103
|
-
if (jids.length)
|
|
104
|
-
await (await ctx.getClient()).signalDeleteSessions(jids);
|
|
105
|
-
},
|
|
106
|
-
lidMapping: {
|
|
107
|
-
storeLIDPNMappings: async (pairs) => {
|
|
108
|
-
const valid = pairs.filter(({ lid, pn }) => {
|
|
109
|
-
const accepted = isLidNamespace(lid) && isPnNamespace(pn);
|
|
110
|
-
if (!accepted)
|
|
111
|
-
ctx.logger.warn(`Invalid LID-PN mapping: ${lid}, ${pn}`);
|
|
112
|
-
return accepted;
|
|
113
|
-
});
|
|
114
|
-
if (valid.length)
|
|
115
|
-
await (await ctx.getClient()).addLidPnMappings(valid);
|
|
72
|
+
export const makeSignalRepository = (ctx) => {
|
|
73
|
+
return {
|
|
74
|
+
decryptMessage: async (opts) => ctx.withClient(client => client.signalDecryptMessage(opts.jid, opts.type, opts.ciphertext)),
|
|
75
|
+
encryptMessage: async (opts) => ctx.withClient(client => client.signalEncryptMessage(opts.jid, opts.data)),
|
|
76
|
+
decryptGroupMessage: async (opts) => ctx.withClient(client => client.signalDecryptGroupMessage(opts.group, opts.authorJid, opts.msg)),
|
|
77
|
+
encryptGroupMessage: async (opts) => ctx.withClient(client => client.signalEncryptGroupMessage(opts.group, opts.data, opts.meId)),
|
|
78
|
+
processSenderKeyDistributionMessage: async ({ item, authorJid }) => {
|
|
79
|
+
if (!item.groupId) {
|
|
80
|
+
throw new Error('Group ID is required for sender key distribution message');
|
|
81
|
+
}
|
|
82
|
+
const distribution = item.axolotlSenderKeyDistributionMessage;
|
|
83
|
+
if (!distribution) {
|
|
84
|
+
throw new Error('Sender key distribution payload is required');
|
|
85
|
+
}
|
|
86
|
+
await ctx.withClient(client => client.signalProcessSenderKeyDistribution(item.groupId, authorJid, distribution));
|
|
87
|
+
},
|
|
88
|
+
getSenderKeyDistributionMessage: async ({ group, meId }) => ctx.withClient(client => client.signalGetSenderKeyDistribution(group, meId)),
|
|
89
|
+
hasSenderKey: async ({ group, meId }) => ctx.withClient(client => client.signalHasSenderKey(group, meId)),
|
|
90
|
+
getSessionInfo: async (jid) => (await ctx.withClient(client => client.signalGetSessionInfo(jid))) ?? null,
|
|
91
|
+
injectE2ESession: async ({ jid, session }) => {
|
|
92
|
+
await ctx.withClient(client => client.signalInstallPreKeyBundle(jid, session));
|
|
116
93
|
},
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
94
|
+
validateSession: async (jid) => ({ exists: await ctx.withClient(client => client.signalValidateSession(jid)) }),
|
|
95
|
+
jidToSignalProtocolAddress: jidToSignalProtocolAddressCompat,
|
|
96
|
+
migrateSession: async (fromJid, toJid) => {
|
|
97
|
+
if (!fromJid || !isLidNamespace(toJid))
|
|
98
|
+
return { migrated: 0, skipped: 0, total: 0 };
|
|
99
|
+
if (!isPnNamespace(fromJid))
|
|
100
|
+
return { migrated: 0, skipped: 0, total: 1 };
|
|
101
|
+
return ctx.withClient(client => client.signalMigrateSessions(fromJid, toJid));
|
|
120
102
|
},
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
103
|
+
deleteSession: async (jids) => {
|
|
104
|
+
if (jids.length)
|
|
105
|
+
await ctx.withClient(client => client.signalDeleteSessions(jids));
|
|
106
|
+
},
|
|
107
|
+
lidMapping: {
|
|
108
|
+
storeLIDPNMappings: async (pairs) => {
|
|
109
|
+
const valid = pairs.filter(({ lid, pn }) => {
|
|
110
|
+
const accepted = isLidNamespace(lid) && isPnNamespace(pn);
|
|
111
|
+
if (!accepted)
|
|
112
|
+
ctx.logger.warn(`Invalid LID-PN mapping: ${lid}, ${pn}`);
|
|
113
|
+
return accepted;
|
|
114
|
+
});
|
|
115
|
+
if (valid.length)
|
|
116
|
+
await ctx.withClient(client => client.addLidPnMappings(valid));
|
|
117
|
+
},
|
|
118
|
+
getLIDForPN: async (pn) => {
|
|
119
|
+
return ctx.withClient(async (client) => {
|
|
120
|
+
return (await resolveMappings(client, [pn], 'pn-to-lid', ctx))?.[0]?.lid ?? null;
|
|
121
|
+
});
|
|
122
|
+
},
|
|
123
|
+
getLIDsForPNs: async (pns) => ctx.withClient(client => resolveMappings(client, pns, 'pn-to-lid', ctx)),
|
|
124
|
+
getPNForLID: async (lid) => {
|
|
125
|
+
return ctx.withClient(async (client) => {
|
|
126
|
+
return (await resolveMappings(client, [lid], 'lid-to-pn', ctx))?.[0]?.pn ?? null;
|
|
127
|
+
});
|
|
128
|
+
},
|
|
129
|
+
getPNsForLIDs: async (lids) => ctx.withClient(client => resolveMappings(client, lids, 'lid-to-pn', ctx)),
|
|
130
|
+
close: () => undefined
|
|
125
131
|
},
|
|
126
|
-
getPNsForLIDs: async (lids) => resolveMappings(await ctx.getClient(), lids, 'lid-to-pn', ctx),
|
|
127
132
|
close: () => undefined
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
});
|
|
133
|
+
};
|
|
134
|
+
};
|
|
131
135
|
//# sourceMappingURL=signal-repository.js.map
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { WasmWhatsAppClient } from '@oxidezap/whatsapp-rust-bridge';
|
|
2
2
|
import type { BinaryNode } from '../Types/index.js';
|
|
3
|
+
import type { ClientOperations } from '../Socket/client-operations.js';
|
|
3
4
|
type StanzaResponseClient = Pick<WasmWhatsAppClient, 'acknowledgeStanza' | 'rejectStanza' | 'requestMessageRetry'>;
|
|
4
|
-
export interface StanzaResponseContext {
|
|
5
|
-
getClient: () => Promise<StanzaResponseClient>;
|
|
5
|
+
export interface StanzaResponseContext extends ClientOperations<StanzaResponseClient> {
|
|
6
6
|
}
|
|
7
7
|
/** Translate the public socket calls into the core-owned response operations. */
|
|
8
|
-
export declare const makeStanzaResponseMethods: (
|
|
8
|
+
export declare const makeStanzaResponseMethods: (ctx: StanzaResponseContext) => {
|
|
9
9
|
sendMessageAck: (node: BinaryNode, errorCode?: number) => Promise<void>;
|
|
10
10
|
sendRetryRequest: (node: BinaryNode, forceIncludeKeys?: boolean) => Promise<void>;
|
|
11
11
|
};
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
/** Translate the public socket calls into the core-owned response operations. */
|
|
2
|
-
export const makeStanzaResponseMethods = (
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
export const makeStanzaResponseMethods = (ctx) => {
|
|
3
|
+
return {
|
|
4
|
+
sendMessageAck: async (node, errorCode) => {
|
|
5
|
+
return ctx.withClient(async (client) => {
|
|
6
|
+
if (errorCode) {
|
|
7
|
+
await client.rejectStanza(node, errorCode);
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
await client.acknowledgeStanza(node);
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
},
|
|
14
|
+
sendRetryRequest: async (node, forceIncludeKeys = false) => {
|
|
15
|
+
await ctx.withClient(client => client.requestMessageRetry(node, forceIncludeKeys));
|
|
7
16
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
},
|
|
12
|
-
sendRetryRequest: async (node, forceIncludeKeys = false) => {
|
|
13
|
-
await (await getClient()).requestMessageRetry(node, forceIncludeKeys);
|
|
14
|
-
}
|
|
15
|
-
});
|
|
17
|
+
};
|
|
18
|
+
};
|
|
16
19
|
//# sourceMappingURL=stanza-responses.js.map
|
package/lib/Socket/blocking.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { bridgeBlocklistToBaileys } from '../Compatibility/socket-results.js';
|
|
2
2
|
import { assertArgumentDomain } from '../Utils/argument-domain.js';
|
|
3
3
|
export const BLOCK_ACTIONS = ['block', 'unblock'];
|
|
4
|
-
export const makeBlockingMethods = (ctx) =>
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
4
|
+
export const makeBlockingMethods = (ctx) => {
|
|
5
|
+
return {
|
|
6
|
+
updateBlockStatus: async (jid, action) => {
|
|
7
|
+
assertArgumentDomain('updateBlockStatus', 'action', action, BLOCK_ACTIONS);
|
|
8
|
+
await ctx.withClient(client => client.updateBlockStatus(jid, action));
|
|
9
|
+
},
|
|
10
|
+
fetchBlocklist: async () => {
|
|
11
|
+
return bridgeBlocklistToBaileys(await ctx.withClient(client => client.fetchBlocklist()));
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
};
|
|
13
15
|
//# sourceMappingURL=blocking.js.map
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
* - Anything that is not the bridge's shape (an `Error` carrying a string
|
|
22
22
|
* `kind`) passes through with the same identity it arrived with.
|
|
23
23
|
*
|
|
24
|
-
* The
|
|
25
|
-
*
|
|
24
|
+
* The private `getClient()` getter returns a cached `Proxy` for each client.
|
|
25
|
+
* Its method wrappers are built on first access and cached, so
|
|
26
26
|
* the happy path pays one property trap and one extra promise layer, and the
|
|
27
27
|
* error path pays for everything else.
|
|
28
28
|
*/
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
* - Anything that is not the bridge's shape (an `Error` carrying a string
|
|
22
22
|
* `kind`) passes through with the same identity it arrived with.
|
|
23
23
|
*
|
|
24
|
-
* The
|
|
25
|
-
*
|
|
24
|
+
* The private `getClient()` getter returns a cached `Proxy` for each client.
|
|
25
|
+
* Its method wrappers are built on first access and cached, so
|
|
26
26
|
* the happy path pays one property trap and one extra promise layer, and the
|
|
27
27
|
* error path pays for everything else.
|
|
28
28
|
*/
|
package/lib/Socket/business.js
CHANGED
|
@@ -39,66 +39,68 @@ const catalogSubject = (method, ctx, jid) => {
|
|
|
39
39
|
}
|
|
40
40
|
return subject;
|
|
41
41
|
};
|
|
42
|
-
export const makeBusinessMethods = (ctx) =>
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
42
|
+
export const makeBusinessMethods = (ctx) => {
|
|
43
|
+
return {
|
|
44
|
+
getCatalog: async ({ jid, limit, cursor }) => {
|
|
45
|
+
const subject = catalogSubject('getCatalog', ctx, jid);
|
|
46
|
+
return await ctx.withClient(client => client.getCatalog(subject, { limit, after: cursor }));
|
|
47
|
+
},
|
|
48
|
+
getCollections: async (jid, limit) => {
|
|
49
|
+
const subject = catalogSubject('getCollections', ctx, jid);
|
|
50
|
+
return await ctx.withClient(client => client.getCollections(subject, { collectionLimit: limit }));
|
|
51
|
+
},
|
|
52
|
+
/**
|
|
53
|
+
* `sellerJid` is not in upstream's signature because upstream reads orders
|
|
54
|
+
* over the legacy `fb:thrift_iq` route, which addresses the server. The
|
|
55
|
+
* route the real client uses is a MEX query keyed by the seller, so the JID
|
|
56
|
+
* is required here. It is on the order message the token came from.
|
|
57
|
+
*/
|
|
58
|
+
getOrderDetails: async (orderId, tokenBase64, sellerJid) => {
|
|
59
|
+
if (!sellerJid) {
|
|
60
|
+
throw new Boom('getOrderDetails: a third argument with the seller jid is required, because orders are read through a query keyed by the business rather than the legacy server-addressed one', { statusCode: 400 });
|
|
61
|
+
}
|
|
62
|
+
return await ctx.withClient(client => client.getOrder(sellerJid, orderId, tokenBase64));
|
|
63
|
+
},
|
|
64
|
+
updateBussinesProfile: async (args) => {
|
|
65
|
+
const update = {
|
|
66
|
+
address: args.address,
|
|
67
|
+
description: args.description,
|
|
68
|
+
email: args.email,
|
|
69
|
+
websites: args.websites,
|
|
70
|
+
...(args.hours !== undefined
|
|
71
|
+
? {
|
|
72
|
+
businessHours: {
|
|
73
|
+
timezone: args.hours.timezone,
|
|
74
|
+
// Minutes past midnight as a number; upstream types the two
|
|
75
|
+
// as strings and the core rejects them on the other modes.
|
|
76
|
+
config: args.hours.days.map(day => ({
|
|
77
|
+
dayOfWeek: day.day,
|
|
78
|
+
mode: day.mode,
|
|
79
|
+
openTime: day.mode === 'specific_hours' ? minutesPastMidnight(day.openTimeInMinutes, 'open') : undefined,
|
|
80
|
+
closeTime: day.mode === 'specific_hours' ? minutesPastMidnight(day.closeTimeInMinutes, 'close') : undefined
|
|
81
|
+
}))
|
|
82
|
+
}
|
|
81
83
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
84
|
+
: {})
|
|
85
|
+
};
|
|
86
|
+
await ctx.withClient(client => client.updateBusinessProfile(update));
|
|
87
|
+
},
|
|
88
|
+
/**
|
|
89
|
+
* Declared but not callable end to end. The core and the bridge take the
|
|
90
|
+
* `{fbid, meta_hmac, ts}` receipt of a cover photo upload, and this
|
|
91
|
+
* package's upload path cannot produce one: it requires a url and a
|
|
92
|
+
* direct path, which that endpoint does not return.
|
|
93
|
+
*/
|
|
94
|
+
updateCoverPhoto: async (photo) => {
|
|
95
|
+
void photo;
|
|
96
|
+
throw new Boom('updateCoverPhoto is not available yet: the cover photo upload returns an {fbid, meta_hmac, ts} receipt that this package cannot obtain. removeCoverPhoto works.', { statusCode: 501 });
|
|
97
|
+
},
|
|
98
|
+
removeCoverPhoto: async (id) => {
|
|
99
|
+
await ctx.withClient(client => client.removeBusinessCoverPhoto(id));
|
|
100
|
+
},
|
|
101
|
+
productCreate: async (create) => noProductWriteRoute('productCreate', create),
|
|
102
|
+
productUpdate: async (productId, update) => noProductWriteRoute('productUpdate', productId, update),
|
|
103
|
+
productDelete: async (productIds) => noProductWriteRoute('productDelete', productIds)
|
|
104
|
+
};
|
|
105
|
+
};
|
|
104
106
|
//# sourceMappingURL=business.js.map
|