@bitbitpress/client 0.1.3 → 0.1.5

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.
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SignalBatchManager = void 0;
4
+ const signal_js_1 = require("./signal.js");
5
+ // Timer functions for cross-platform compatibility
6
+ function getSetTimeout() {
7
+ return setTimeout;
8
+ }
9
+ function getClearTimeout() {
10
+ return clearTimeout;
11
+ }
12
+ const setTimer = getSetTimeout();
13
+ const clearTimer = getClearTimeout();
14
+ /**
15
+ * Batch manager for signalItem
16
+ * Batches individual signals and sends them together after the timeout
17
+ */
18
+ class SignalBatchManager {
19
+ queue = [];
20
+ timer = null;
21
+ config;
22
+ batchTimeout;
23
+ constructor(config, batchTimeout) {
24
+ this.config = config;
25
+ this.batchTimeout = batchTimeout;
26
+ }
27
+ /**
28
+ * Update the request configuration (e.g., when token changes)
29
+ */
30
+ updateConfig(config) {
31
+ this.config = config;
32
+ }
33
+ addSignal(signal) {
34
+ return new Promise((resolve, reject) => {
35
+ this.queue.push({ signal, resolve, reject });
36
+ // Reset timer
37
+ if (this.timer) {
38
+ clearTimer(this.timer);
39
+ }
40
+ this.timer = setTimer(() => {
41
+ this.flush();
42
+ }, this.batchTimeout);
43
+ });
44
+ }
45
+ async flush() {
46
+ if (this.queue.length === 0) {
47
+ return;
48
+ }
49
+ const batch = [...this.queue];
50
+ // Clear queue and reset state
51
+ this.queue = [];
52
+ this.timer = null;
53
+ try {
54
+ // Send batch request
55
+ const signals = batch.map((b) => b.signal);
56
+ const response = await (0, signal_js_1.recordSignal)(this.config, { signals });
57
+ // Resolve all promises with the same response
58
+ // The API returns a single response for the batch
59
+ for (const { resolve } of batch) {
60
+ resolve(response);
61
+ }
62
+ }
63
+ catch (error) {
64
+ // Reject all pending promises
65
+ const err = error instanceof Error ? error : new Error(String(error));
66
+ for (const { reject } of batch) {
67
+ reject(err);
68
+ }
69
+ }
70
+ }
71
+ }
72
+ exports.SignalBatchManager = SignalBatchManager;
73
+ //# sourceMappingURL=signal-batch-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signal-batch-manager.js","sourceRoot":"","sources":["../../src/user/signal-batch-manager.ts"],"names":[],"mappings":";;;AACA,2CAAwD;AAExD,mDAAmD;AACnD,SAAS,aAAa;IACpB,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,SAAS,eAAe;IACtB,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,MAAM,QAAQ,GAAG,aAAa,EAAE,CAAC;AACjC,MAAM,UAAU,GAAG,eAAe,EAAE,CAAC;AAMrC;;;GAGG;AACH,MAAa,kBAAkB;IACrB,KAAK,GAIR,EAAE,CAAC;IACA,KAAK,GAAiB,IAAI,CAAC;IAC3B,MAAM,CAAgB;IACtB,YAAY,CAAS;IAE7B,YAAY,MAAqB,EAAE,YAAoB;QACrD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;IAED;;OAEG;IACH,YAAY,CAAC,MAAqB;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,SAAS,CAAC,MAAc;QACtB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;YAE7C,cAAc;YACd,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;gBACf,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACzB,CAAC;YAED,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,GAAG,EAAE;gBACzB,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,CAAC,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QACxB,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,KAAK,CAAC,KAAK;QACjB,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC5B,OAAO;QACT,CAAC;QAED,MAAM,KAAK,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;QAE9B,8BAA8B;QAC9B,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;QAChB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAElB,IAAI,CAAC;YACH,qBAAqB;YACrB,MAAM,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;YAC3C,MAAM,QAAQ,GAAG,MAAM,IAAA,wBAAY,EAAC,IAAI,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;YAE9D,8CAA8C;YAC9C,kDAAkD;YAClD,KAAK,MAAM,EAAE,OAAO,EAAE,IAAI,KAAK,EAAE,CAAC;gBAChC,OAAO,CAAC,QAAQ,CAAC,CAAC;YACpB,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,8BAA8B;YAC9B,MAAM,GAAG,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;YACtE,KAAK,MAAM,EAAE,MAAM,EAAE,IAAI,KAAK,EAAE,CAAC;gBAC/B,MAAM,CAAC,GAAG,CAAC,CAAC;YACd,CAAC;QACH,CAAC;IACH,CAAC;CACF;AAlED,gDAkEC"}
@@ -2,11 +2,12 @@ import type { paths } from '../generated/openapi.js';
2
2
  import type { RequestConfig } from '../request.js';
3
3
  export type SignalRequest = paths['/v1/user/signal']['post']['requestBody']['content']['application/json'];
4
4
  export type SignalResponse = paths['/v1/user/signal']['post']['responses'][200]['content']['application/json']['data'];
5
+ export type Signal = SignalRequest['signals'][number];
5
6
  /**
6
- * Record a user signal (e.g. clicked topic, read article) to inform profile interests
7
+ * Record user signals (e.g. clicked topic, read article) to inform profile interests
7
8
  *
8
9
  * @param config - Request configuration with base URL, timeout, fetch, and optional token
9
- * @param options - Signal request parameters (type: SignalRequest)
10
+ * @param options - Signal request parameters (type: SignalRequest) containing an array of signals
10
11
  * @returns Promise that resolves with the signal response data
11
12
  */
12
13
  export declare function recordSignal(config: RequestConfig, options: SignalRequest): Promise<NonNullable<SignalResponse>>;
@@ -1 +1 @@
1
- {"version":3,"file":"signal.d.ts","sourceRoot":"","sources":["../../src/user/signal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAInD,MAAM,MAAM,aAAa,GACvB,KAAK,CAAC,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC,CAAC,SAAS,CAAC,CAAC,kBAAkB,CAAC,CAAC;AACjF,MAAM,MAAM,cAAc,GACxB,KAAK,CAAC,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE5F;;;;;;GAMG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,aAAa,EACrB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC,CActC"}
1
+ {"version":3,"file":"signal.d.ts","sourceRoot":"","sources":["../../src/user/signal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAInD,MAAM,MAAM,aAAa,GACvB,KAAK,CAAC,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC,CAAC,SAAS,CAAC,CAAC,kBAAkB,CAAC,CAAC;AACjF,MAAM,MAAM,cAAc,GACxB,KAAK,CAAC,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC;AAG5F,MAAM,MAAM,MAAM,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC;AAEtD;;;;;;GAMG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,aAAa,EACrB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC,CActC"}
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.recordSignal = recordSignal;
4
4
  const request_js_1 = require("../request.js");
5
5
  /**
6
- * Record a user signal (e.g. clicked topic, read article) to inform profile interests
6
+ * Record user signals (e.g. clicked topic, read article) to inform profile interests
7
7
  *
8
8
  * @param config - Request configuration with base URL, timeout, fetch, and optional token
9
- * @param options - Signal request parameters (type: SignalRequest)
9
+ * @param options - Signal request parameters (type: SignalRequest) containing an array of signals
10
10
  * @returns Promise that resolves with the signal response data
11
11
  */
12
12
  async function recordSignal(config, options) {
@@ -1 +1 @@
1
- {"version":3,"file":"signal.js","sourceRoot":"","sources":["../../src/user/signal.ts"],"names":[],"mappings":";;AAiBA,oCAiBC;AAhCD,8CAA4C;AAQ5C;;;;;;GAMG;AACI,KAAK,UAAU,YAAY,CAChC,MAAqB,EACrB,OAAsB;IAEtB,MAAM,QAAQ,GAAG,MAAM,IAAA,wBAAW,EAEhC,MAAM,EAAE;QACR,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,iBAAiB;QACvB,IAAI,EAAE,OAAO;KACd,CAAC,CAAC;IAEH,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IAClE,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC"}
1
+ {"version":3,"file":"signal.js","sourceRoot":"","sources":["../../src/user/signal.ts"],"names":[],"mappings":";;AAoBA,oCAiBC;AAnCD,8CAA4C;AAW5C;;;;;;GAMG;AACI,KAAK,UAAU,YAAY,CAChC,MAAqB,EACrB,OAAsB;IAEtB,MAAM,QAAQ,GAAG,MAAM,IAAA,wBAAW,EAEhC,MAAM,EAAE;QACR,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,iBAAiB;QACvB,IAAI,EAAE,OAAO;KACd,CAAC,CAAC;IAEH,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IAClE,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bitbitpress/client",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "BitBitPress TypeScript client library",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",