@scalemule/sdk 0.0.74 → 0.0.76

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/dist/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __esm = (fn, res) => function __init() {
7
9
  return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
@@ -18,6 +20,14 @@ var __copyProps = (to, from, except, desc) => {
18
20
  }
19
21
  return to;
20
22
  };
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
+ // If the importer is in node compatibility mode or this is not an ESM
25
+ // file that has been converted to a CommonJS file using a Babel-
26
+ // compatible transform (i.e. "__esModule" has not been set), then set
27
+ // "default" to the CommonJS "module.exports" for node compatibility.
28
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
+ mod
30
+ ));
21
31
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
32
 
23
33
  // src/services/upload-resume.ts
@@ -258,7 +268,7 @@ async function loadImageCompression() {
258
268
  if (cachedImport === false) return null;
259
269
  if (cachedImport) return cachedImport;
260
270
  try {
261
- const mod = await Function('return import("browser-image-compression")')();
271
+ const mod = await import("browser-image-compression");
262
272
  cachedImport = mod.default || mod;
263
273
  return cachedImport;
264
274
  } catch {
@@ -328,6 +338,7 @@ __export(index_exports, {
328
338
  LeaderboardService: () => LeaderboardService,
329
339
  LeadsService: () => LeadsService,
330
340
  ListingsService: () => ListingsService,
341
+ LocalIntelligenceService: () => LocalIntelligenceService,
331
342
  LoggerService: () => LoggerService,
332
343
  MEDIA_PRESETS: () => MEDIA_PRESETS,
333
344
  MediaService: () => MediaService,
@@ -359,6 +370,7 @@ __export(index_exports, {
359
370
  WebPushManager: () => WebPushManager,
360
371
  WebhooksService: () => WebhooksService,
361
372
  WorkspacesService: () => WorkspacesService,
373
+ applyIntelligenceChanges: () => applyIntelligenceChanges,
362
374
  buildClientContextHeaders: () => buildClientContextHeaders,
363
375
  calculateTotalParts: () => calculateTotalParts,
364
376
  canPerform: () => canPerform,
@@ -382,8 +394,10 @@ __export(index_exports, {
382
394
  normalizePhoneNumber: () => normalizePhoneNumber,
383
395
  pollSharePercent: () => pollSharePercent,
384
396
  pollVoterKey: () => pollVoterKey,
397
+ prepareCommunityMapAttachment: () => prepareCommunityMapAttachment,
385
398
  readAnonymousId: () => readAnonymousId,
386
399
  resolveStrategy: () => resolveStrategy,
400
+ startMediaCapture: () => startMediaCapture,
387
401
  uploadMultipartToS3: () => uploadMultipartToS3,
388
402
  uploadSingleToS3: () => uploadSingleToS3,
389
403
  validateIP: () => validateIP
@@ -1690,7 +1704,7 @@ function asString(parent, key) {
1690
1704
  return typeof value === "string" ? value : void 0;
1691
1705
  }
1692
1706
 
1693
- // ../sdk/node_modules/@scalemule/ui/dist/phone/index.mjs
1707
+ // node_modules/@scalemule/ui/dist/phone/index.mjs
1694
1708
  var PHONE_COUNTRIES = [
1695
1709
  { code: "US", name: "United States", dialCode: "+1" },
1696
1710
  { code: "CA", name: "Canada", dialCode: "+1" },
@@ -6951,6 +6965,15 @@ var CommunityMapsService = class extends ServiceModule {
6951
6965
  createSubmission(slug, data, options) {
6952
6966
  return this.post("/collections/" + segment(slug) + "/submissions", data, options);
6953
6967
  }
6968
+ listOwnSubmissions(slug, after, options) {
6969
+ return this._get(
6970
+ "/collections/" + segment(slug) + "/submissions" + (after ? "?after=" + segment(after) : ""),
6971
+ options
6972
+ );
6973
+ }
6974
+ updateOwnSubmission(slug, id, data, options) {
6975
+ return this.post("/collections/" + segment(slug) + "/submissions/" + segment(id), data, options);
6976
+ }
6954
6977
  uploadMedia(slug, submission, file, fields, options) {
6955
6978
  return this._upload(
6956
6979
  "/collections/" + segment(slug) + "/submissions/" + segment(submission) + "/media",
@@ -6959,7 +6982,8 @@ var CommunityMapsService = class extends ServiceModule {
6959
6982
  caption: fields.caption,
6960
6983
  attribution: fields.attribution,
6961
6984
  rights_confirmed: String(fields.rights_confirmed),
6962
- consent_version: fields.consent_version
6985
+ consent_version: fields.consent_version,
6986
+ ...fields.idempotency_key ? { idempotency_key: fields.idempotency_key } : {}
6963
6987
  },
6964
6988
  options
6965
6989
  );
@@ -7128,6 +7152,97 @@ var CommunityMapsGeographyService = class extends ServiceModule {
7128
7152
  }
7129
7153
  };
7130
7154
 
7155
+ // src/services/local-intelligence.ts
7156
+ var LocalIntelligenceService = class extends ServiceModule {
7157
+ constructor() {
7158
+ super(...arguments);
7159
+ this.basePath = "/v1/news";
7160
+ }
7161
+ scope(publication) {
7162
+ return `/intelligence/publications/${encodeURIComponent(publication)}`;
7163
+ }
7164
+ records(publication, params = {}, options) {
7165
+ return this._get(this.withQuery(`${this.scope(publication)}/records`, params), options);
7166
+ }
7167
+ get(publication, record, options) {
7168
+ return this._get(`${this.scope(publication)}/records/${encodeURIComponent(record)}`, options);
7169
+ }
7170
+ changes(publication, params = {}, options) {
7171
+ return this._get(this.withQuery(`${this.scope(publication)}/changes`, params), options);
7172
+ }
7173
+ briefing(publication, params, options) {
7174
+ return this._get(this.withQuery(`${this.scope(publication)}/briefing`, params), options);
7175
+ }
7176
+ /** Agent-safe explicit preferences: evaluated for this request and never saved. */
7177
+ briefingForPreferences(publication, input, options) {
7178
+ return this.post(`${this.scope(publication)}/briefing`, input, options);
7179
+ }
7180
+ preferences(publication, options) {
7181
+ return this._get(`${this.scope(publication)}/preferences`, options);
7182
+ }
7183
+ savePreferences(publication, expectedRevision, preferences, options) {
7184
+ return this.put(
7185
+ `${this.scope(publication)}/preferences`,
7186
+ { expected_revision: expectedRevision, preferences },
7187
+ options
7188
+ );
7189
+ }
7190
+ deletePreferences(publication, options) {
7191
+ return this.del(`${this.scope(publication)}/preferences`, options);
7192
+ }
7193
+ feedback(publication, record, recordRevision, outcome, options) {
7194
+ return this.post(
7195
+ `${this.scope(publication)}/records/${encodeURIComponent(record)}/feedback`,
7196
+ { record_revision: recordRevision, outcome },
7197
+ options
7198
+ );
7199
+ }
7200
+ deleteFeedback(publication, record, options) {
7201
+ return this.del(`${this.scope(publication)}/records/${encodeURIComponent(record)}/feedback`, options);
7202
+ }
7203
+ /** Requires a human editor with publication publish authority. */
7204
+ release(publication, input, idempotencyKey, options) {
7205
+ return this.post(`/publications/${encodeURIComponent(publication)}/intelligence`, input, {
7206
+ ...options,
7207
+ headers: { ...options?.headers, "idempotency-key": idempotencyKey }
7208
+ });
7209
+ }
7210
+ withdraw(publication, record, expectedRevision, reason, options) {
7211
+ return this.post(
7212
+ `/publications/${encodeURIComponent(publication)}/intelligence/${encodeURIComponent(record)}/withdraw`,
7213
+ { expected_revision: expectedRevision, reason },
7214
+ options
7215
+ );
7216
+ }
7217
+ };
7218
+ function applyIntelligenceChanges(current, changes, now = Date.now()) {
7219
+ if (changes.contract_version !== "basenews/1" || changes.scope.application_id !== current.scope.application_id || changes.scope.publication_id !== current.scope.publication_id)
7220
+ throw new Error("Intelligence change scope mismatch");
7221
+ const sequenceValue = (value) => {
7222
+ if (!/^(0|[1-9][0-9]{0,19})$/.test(value)) throw new Error("Invalid intelligence sequence");
7223
+ return BigInt(value);
7224
+ };
7225
+ let sequence = sequenceValue(current.sequence);
7226
+ let previous = -1n;
7227
+ const next = new Map(current.records);
7228
+ for (const item of changes.items) {
7229
+ const received = sequenceValue(item.sequence);
7230
+ if (received <= previous) throw new Error("Unordered intelligence change batch");
7231
+ previous = received;
7232
+ if (received <= sequence) continue;
7233
+ if (received !== sequence + 1n) throw new Error("Intelligence change gap; resume the previous cursor");
7234
+ sequence = received;
7235
+ if (item.removed || !item.record) next.delete(item.id);
7236
+ else if (item.record.id !== item.id) throw new Error("Intelligence change identity mismatch");
7237
+ else if (!next.has(item.id) || next.get(item.id).revision <= item.record.revision) next.set(item.id, item.record);
7238
+ }
7239
+ for (const [id, record] of next) {
7240
+ const expiry = Date.parse(record.refresh_after);
7241
+ if (record.contract_version !== "basenews/1" || !Number.isFinite(expiry) || expiry <= now) next.delete(id);
7242
+ }
7243
+ return { scope: current.scope, sequence: sequence.toString(), records: next };
7244
+ }
7245
+
7131
7246
  // src/services/polls.ts
7132
7247
  var PollsService = class extends ServiceModule {
7133
7248
  constructor() {
@@ -9114,6 +9229,127 @@ var AgentSessionsService = class extends ServiceModule {
9114
9229
  }
9115
9230
  };
9116
9231
 
9232
+ // src/browser-capture.ts
9233
+ init_upload_compression();
9234
+ async function prepareCommunityMapAttachment(file) {
9235
+ const types = [
9236
+ "image/jpeg",
9237
+ "image/png",
9238
+ "image/webp",
9239
+ "video/mp4",
9240
+ "video/quicktime",
9241
+ "video/webm",
9242
+ "audio/mpeg",
9243
+ "audio/mp4",
9244
+ "audio/wav",
9245
+ "audio/x-wav",
9246
+ "audio/ogg",
9247
+ "audio/webm"
9248
+ ];
9249
+ if (!types.includes(file.type))
9250
+ throw new Error(
9251
+ "Choose JPEG, PNG or WebP photos, MP4/MOV/WebM video, or MP3/M4A/WAV/Ogg audio. For HEIC, export as JPEG first."
9252
+ );
9253
+ if (!file.size || file.size > 25 * 1024 * 1024)
9254
+ throw new Error("Choose a file up to 25 MiB. Record a shorter clip if needed.");
9255
+ if (!file.type.startsWith("image/")) return file;
9256
+ const compressed = await maybeCompressImage(
9257
+ file,
9258
+ { maxWidth: 2400, maxHeight: 2400, maxSizeMB: 2, quality: 0.82 },
9259
+ "community-capture",
9260
+ null
9261
+ );
9262
+ const result = compressed ? new File(
9263
+ [compressed],
9264
+ file.name.replace(/\.[^.]+$/, "") + (compressed.type === "image/webp" ? ".webp" : ".jpg"),
9265
+ { type: compressed.type, lastModified: file.lastModified }
9266
+ ) : file;
9267
+ if (result.size > 8 * 1024 * 1024)
9268
+ throw new Error("This photo is too large. Choose a photo up to 8 MiB or use a smaller camera setting.");
9269
+ return result;
9270
+ }
9271
+ async function startMediaCapture(kind, signal) {
9272
+ const candidates = kind === "video" ? ["video/mp4;codecs=h264,aac", "video/mp4", "video/webm;codecs=vp8,opus", "video/webm"] : ["audio/mp4", "audio/webm;codecs=opus", "audio/ogg;codecs=opus", "audio/webm"];
9273
+ const mimeType = typeof MediaRecorder === "undefined" ? void 0 : candidates.find((t) => MediaRecorder.isTypeSupported(t));
9274
+ if (!mimeType || !navigator.mediaDevices?.getUserMedia)
9275
+ throw new Error("Recording is unavailable in this browser. Use the camera or choose a file instead.");
9276
+ signal?.throwIfAborted();
9277
+ const stream = await navigator.mediaDevices.getUserMedia(
9278
+ kind === "video" ? {
9279
+ audio: true,
9280
+ video: {
9281
+ facingMode: { ideal: "environment" },
9282
+ width: { ideal: 1280, max: 1280 },
9283
+ height: { ideal: 720, max: 720 },
9284
+ frameRate: { ideal: 24, max: 30 }
9285
+ }
9286
+ } : { audio: { channelCount: { ideal: 1 }, echoCancellation: true, noiseSuppression: true }, video: false }
9287
+ );
9288
+ const release = () => stream.getTracks().forEach((t) => t.stop());
9289
+ if (signal?.aborted) {
9290
+ release();
9291
+ signal.throwIfAborted();
9292
+ }
9293
+ let recorder;
9294
+ try {
9295
+ recorder = new MediaRecorder(stream, { mimeType, videoBitsPerSecond: 2e6, audioBitsPerSecond: 96e3 });
9296
+ } catch (e) {
9297
+ release();
9298
+ throw e;
9299
+ }
9300
+ let cancelled = false;
9301
+ let failure;
9302
+ let bytes = 0;
9303
+ const chunks = [];
9304
+ let timer;
9305
+ const stop = () => {
9306
+ if (recorder.state !== "inactive") recorder.stop();
9307
+ };
9308
+ const cancel = () => {
9309
+ cancelled = true;
9310
+ stop();
9311
+ release();
9312
+ };
9313
+ const result = new Promise((resolve, reject) => {
9314
+ const clean = () => {
9315
+ clearTimeout(timer);
9316
+ signal?.removeEventListener("abort", cancel);
9317
+ release();
9318
+ };
9319
+ recorder.ondataavailable = (event) => {
9320
+ bytes += event.data.size;
9321
+ if (bytes > 25 * 1024 * 1024) {
9322
+ failure = new Error("The recording is too large. Try a shorter clip.");
9323
+ stop();
9324
+ } else if (event.data.size) chunks.push(event.data);
9325
+ };
9326
+ recorder.onerror = () => {
9327
+ failure = new Error("Recording was interrupted. Try again or choose a file.");
9328
+ stop();
9329
+ };
9330
+ recorder.onstop = () => {
9331
+ clean();
9332
+ if (failure) reject(failure);
9333
+ else if (cancelled || !chunks.length) resolve(null);
9334
+ else {
9335
+ const type = recorder.mimeType.split(";")[0] || (kind === "audio" ? "audio/webm" : "video/webm");
9336
+ const extension = type.includes("mp4") ? kind === "audio" ? "m4a" : "mp4" : type.includes("ogg") ? "ogg" : "webm";
9337
+ resolve(new File(chunks, `community-${kind}-${Date.now()}.${extension}`, { type }));
9338
+ }
9339
+ chunks.length = 0;
9340
+ };
9341
+ signal?.addEventListener("abort", cancel, { once: true });
9342
+ try {
9343
+ recorder.start(250);
9344
+ timer = setTimeout(stop, kind === "video" ? 15e3 : 6e4);
9345
+ } catch (error) {
9346
+ clean();
9347
+ reject(error);
9348
+ }
9349
+ });
9350
+ return { stream, result, stop, cancel };
9351
+ }
9352
+
9117
9353
  // src/index.ts
9118
9354
  var ScaleMule = class {
9119
9355
  /** @deprecated Use `workspaces` instead */
@@ -9154,6 +9390,7 @@ var ScaleMule = class {
9154
9390
  this.leaderboard = new LeaderboardService(this._client);
9155
9391
  this.listings = new ListingsService(this._client);
9156
9392
  this.communityMaps = new CommunityMapsService(this._client);
9393
+ this.localIntelligence = new LocalIntelligenceService(this._client);
9157
9394
  this.polls = new PollsService(this._client);
9158
9395
  this.events = new EventsService(this._client);
9159
9396
  this.graph = new GraphService(this._client);
@@ -9332,6 +9569,7 @@ var index_default = ScaleMule;
9332
9569
  LeaderboardService,
9333
9570
  LeadsService,
9334
9571
  ListingsService,
9572
+ LocalIntelligenceService,
9335
9573
  LoggerService,
9336
9574
  MEDIA_PRESETS,
9337
9575
  MediaService,
@@ -9363,6 +9601,7 @@ var index_default = ScaleMule;
9363
9601
  WebPushManager,
9364
9602
  WebhooksService,
9365
9603
  WorkspacesService,
9604
+ applyIntelligenceChanges,
9366
9605
  buildClientContextHeaders,
9367
9606
  calculateTotalParts,
9368
9607
  canPerform,
@@ -9385,8 +9624,10 @@ var index_default = ScaleMule;
9385
9624
  normalizePhoneNumber,
9386
9625
  pollSharePercent,
9387
9626
  pollVoterKey,
9627
+ prepareCommunityMapAttachment,
9388
9628
  readAnonymousId,
9389
9629
  resolveStrategy,
9630
+ startMediaCapture,
9390
9631
  uploadMultipartToS3,
9391
9632
  uploadSingleToS3,
9392
9633
  validateIP
package/dist/index.mjs CHANGED
@@ -246,7 +246,7 @@ async function loadImageCompression() {
246
246
  if (cachedImport === false) return null;
247
247
  if (cachedImport) return cachedImport;
248
248
  try {
249
- const mod = await Function('return import("browser-image-compression")')();
249
+ const mod = await import("browser-image-compression");
250
250
  cachedImport = mod.default || mod;
251
251
  return cachedImport;
252
252
  } catch {
@@ -1578,7 +1578,7 @@ function asString(parent, key) {
1578
1578
  return typeof value === "string" ? value : void 0;
1579
1579
  }
1580
1580
 
1581
- // ../sdk/node_modules/@scalemule/ui/dist/phone/index.mjs
1581
+ // node_modules/@scalemule/ui/dist/phone/index.mjs
1582
1582
  var PHONE_COUNTRIES = [
1583
1583
  { code: "US", name: "United States", dialCode: "+1" },
1584
1584
  { code: "CA", name: "Canada", dialCode: "+1" },
@@ -6839,6 +6839,15 @@ var CommunityMapsService = class extends ServiceModule {
6839
6839
  createSubmission(slug, data, options) {
6840
6840
  return this.post("/collections/" + segment(slug) + "/submissions", data, options);
6841
6841
  }
6842
+ listOwnSubmissions(slug, after, options) {
6843
+ return this._get(
6844
+ "/collections/" + segment(slug) + "/submissions" + (after ? "?after=" + segment(after) : ""),
6845
+ options
6846
+ );
6847
+ }
6848
+ updateOwnSubmission(slug, id, data, options) {
6849
+ return this.post("/collections/" + segment(slug) + "/submissions/" + segment(id), data, options);
6850
+ }
6842
6851
  uploadMedia(slug, submission, file, fields, options) {
6843
6852
  return this._upload(
6844
6853
  "/collections/" + segment(slug) + "/submissions/" + segment(submission) + "/media",
@@ -6847,7 +6856,8 @@ var CommunityMapsService = class extends ServiceModule {
6847
6856
  caption: fields.caption,
6848
6857
  attribution: fields.attribution,
6849
6858
  rights_confirmed: String(fields.rights_confirmed),
6850
- consent_version: fields.consent_version
6859
+ consent_version: fields.consent_version,
6860
+ ...fields.idempotency_key ? { idempotency_key: fields.idempotency_key } : {}
6851
6861
  },
6852
6862
  options
6853
6863
  );
@@ -7016,6 +7026,97 @@ var CommunityMapsGeographyService = class extends ServiceModule {
7016
7026
  }
7017
7027
  };
7018
7028
 
7029
+ // src/services/local-intelligence.ts
7030
+ var LocalIntelligenceService = class extends ServiceModule {
7031
+ constructor() {
7032
+ super(...arguments);
7033
+ this.basePath = "/v1/news";
7034
+ }
7035
+ scope(publication) {
7036
+ return `/intelligence/publications/${encodeURIComponent(publication)}`;
7037
+ }
7038
+ records(publication, params = {}, options) {
7039
+ return this._get(this.withQuery(`${this.scope(publication)}/records`, params), options);
7040
+ }
7041
+ get(publication, record, options) {
7042
+ return this._get(`${this.scope(publication)}/records/${encodeURIComponent(record)}`, options);
7043
+ }
7044
+ changes(publication, params = {}, options) {
7045
+ return this._get(this.withQuery(`${this.scope(publication)}/changes`, params), options);
7046
+ }
7047
+ briefing(publication, params, options) {
7048
+ return this._get(this.withQuery(`${this.scope(publication)}/briefing`, params), options);
7049
+ }
7050
+ /** Agent-safe explicit preferences: evaluated for this request and never saved. */
7051
+ briefingForPreferences(publication, input, options) {
7052
+ return this.post(`${this.scope(publication)}/briefing`, input, options);
7053
+ }
7054
+ preferences(publication, options) {
7055
+ return this._get(`${this.scope(publication)}/preferences`, options);
7056
+ }
7057
+ savePreferences(publication, expectedRevision, preferences, options) {
7058
+ return this.put(
7059
+ `${this.scope(publication)}/preferences`,
7060
+ { expected_revision: expectedRevision, preferences },
7061
+ options
7062
+ );
7063
+ }
7064
+ deletePreferences(publication, options) {
7065
+ return this.del(`${this.scope(publication)}/preferences`, options);
7066
+ }
7067
+ feedback(publication, record, recordRevision, outcome, options) {
7068
+ return this.post(
7069
+ `${this.scope(publication)}/records/${encodeURIComponent(record)}/feedback`,
7070
+ { record_revision: recordRevision, outcome },
7071
+ options
7072
+ );
7073
+ }
7074
+ deleteFeedback(publication, record, options) {
7075
+ return this.del(`${this.scope(publication)}/records/${encodeURIComponent(record)}/feedback`, options);
7076
+ }
7077
+ /** Requires a human editor with publication publish authority. */
7078
+ release(publication, input, idempotencyKey, options) {
7079
+ return this.post(`/publications/${encodeURIComponent(publication)}/intelligence`, input, {
7080
+ ...options,
7081
+ headers: { ...options?.headers, "idempotency-key": idempotencyKey }
7082
+ });
7083
+ }
7084
+ withdraw(publication, record, expectedRevision, reason, options) {
7085
+ return this.post(
7086
+ `/publications/${encodeURIComponent(publication)}/intelligence/${encodeURIComponent(record)}/withdraw`,
7087
+ { expected_revision: expectedRevision, reason },
7088
+ options
7089
+ );
7090
+ }
7091
+ };
7092
+ function applyIntelligenceChanges(current, changes, now = Date.now()) {
7093
+ if (changes.contract_version !== "basenews/1" || changes.scope.application_id !== current.scope.application_id || changes.scope.publication_id !== current.scope.publication_id)
7094
+ throw new Error("Intelligence change scope mismatch");
7095
+ const sequenceValue = (value) => {
7096
+ if (!/^(0|[1-9][0-9]{0,19})$/.test(value)) throw new Error("Invalid intelligence sequence");
7097
+ return BigInt(value);
7098
+ };
7099
+ let sequence = sequenceValue(current.sequence);
7100
+ let previous = -1n;
7101
+ const next = new Map(current.records);
7102
+ for (const item of changes.items) {
7103
+ const received = sequenceValue(item.sequence);
7104
+ if (received <= previous) throw new Error("Unordered intelligence change batch");
7105
+ previous = received;
7106
+ if (received <= sequence) continue;
7107
+ if (received !== sequence + 1n) throw new Error("Intelligence change gap; resume the previous cursor");
7108
+ sequence = received;
7109
+ if (item.removed || !item.record) next.delete(item.id);
7110
+ else if (item.record.id !== item.id) throw new Error("Intelligence change identity mismatch");
7111
+ else if (!next.has(item.id) || next.get(item.id).revision <= item.record.revision) next.set(item.id, item.record);
7112
+ }
7113
+ for (const [id, record] of next) {
7114
+ const expiry = Date.parse(record.refresh_after);
7115
+ if (record.contract_version !== "basenews/1" || !Number.isFinite(expiry) || expiry <= now) next.delete(id);
7116
+ }
7117
+ return { scope: current.scope, sequence: sequence.toString(), records: next };
7118
+ }
7119
+
7019
7120
  // src/services/polls.ts
7020
7121
  var PollsService = class extends ServiceModule {
7021
7122
  constructor() {
@@ -9002,6 +9103,127 @@ var AgentSessionsService = class extends ServiceModule {
9002
9103
  }
9003
9104
  };
9004
9105
 
9106
+ // src/browser-capture.ts
9107
+ init_upload_compression();
9108
+ async function prepareCommunityMapAttachment(file) {
9109
+ const types = [
9110
+ "image/jpeg",
9111
+ "image/png",
9112
+ "image/webp",
9113
+ "video/mp4",
9114
+ "video/quicktime",
9115
+ "video/webm",
9116
+ "audio/mpeg",
9117
+ "audio/mp4",
9118
+ "audio/wav",
9119
+ "audio/x-wav",
9120
+ "audio/ogg",
9121
+ "audio/webm"
9122
+ ];
9123
+ if (!types.includes(file.type))
9124
+ throw new Error(
9125
+ "Choose JPEG, PNG or WebP photos, MP4/MOV/WebM video, or MP3/M4A/WAV/Ogg audio. For HEIC, export as JPEG first."
9126
+ );
9127
+ if (!file.size || file.size > 25 * 1024 * 1024)
9128
+ throw new Error("Choose a file up to 25 MiB. Record a shorter clip if needed.");
9129
+ if (!file.type.startsWith("image/")) return file;
9130
+ const compressed = await maybeCompressImage(
9131
+ file,
9132
+ { maxWidth: 2400, maxHeight: 2400, maxSizeMB: 2, quality: 0.82 },
9133
+ "community-capture",
9134
+ null
9135
+ );
9136
+ const result = compressed ? new File(
9137
+ [compressed],
9138
+ file.name.replace(/\.[^.]+$/, "") + (compressed.type === "image/webp" ? ".webp" : ".jpg"),
9139
+ { type: compressed.type, lastModified: file.lastModified }
9140
+ ) : file;
9141
+ if (result.size > 8 * 1024 * 1024)
9142
+ throw new Error("This photo is too large. Choose a photo up to 8 MiB or use a smaller camera setting.");
9143
+ return result;
9144
+ }
9145
+ async function startMediaCapture(kind, signal) {
9146
+ const candidates = kind === "video" ? ["video/mp4;codecs=h264,aac", "video/mp4", "video/webm;codecs=vp8,opus", "video/webm"] : ["audio/mp4", "audio/webm;codecs=opus", "audio/ogg;codecs=opus", "audio/webm"];
9147
+ const mimeType = typeof MediaRecorder === "undefined" ? void 0 : candidates.find((t) => MediaRecorder.isTypeSupported(t));
9148
+ if (!mimeType || !navigator.mediaDevices?.getUserMedia)
9149
+ throw new Error("Recording is unavailable in this browser. Use the camera or choose a file instead.");
9150
+ signal?.throwIfAborted();
9151
+ const stream = await navigator.mediaDevices.getUserMedia(
9152
+ kind === "video" ? {
9153
+ audio: true,
9154
+ video: {
9155
+ facingMode: { ideal: "environment" },
9156
+ width: { ideal: 1280, max: 1280 },
9157
+ height: { ideal: 720, max: 720 },
9158
+ frameRate: { ideal: 24, max: 30 }
9159
+ }
9160
+ } : { audio: { channelCount: { ideal: 1 }, echoCancellation: true, noiseSuppression: true }, video: false }
9161
+ );
9162
+ const release = () => stream.getTracks().forEach((t) => t.stop());
9163
+ if (signal?.aborted) {
9164
+ release();
9165
+ signal.throwIfAborted();
9166
+ }
9167
+ let recorder;
9168
+ try {
9169
+ recorder = new MediaRecorder(stream, { mimeType, videoBitsPerSecond: 2e6, audioBitsPerSecond: 96e3 });
9170
+ } catch (e) {
9171
+ release();
9172
+ throw e;
9173
+ }
9174
+ let cancelled = false;
9175
+ let failure;
9176
+ let bytes = 0;
9177
+ const chunks = [];
9178
+ let timer;
9179
+ const stop = () => {
9180
+ if (recorder.state !== "inactive") recorder.stop();
9181
+ };
9182
+ const cancel = () => {
9183
+ cancelled = true;
9184
+ stop();
9185
+ release();
9186
+ };
9187
+ const result = new Promise((resolve, reject) => {
9188
+ const clean = () => {
9189
+ clearTimeout(timer);
9190
+ signal?.removeEventListener("abort", cancel);
9191
+ release();
9192
+ };
9193
+ recorder.ondataavailable = (event) => {
9194
+ bytes += event.data.size;
9195
+ if (bytes > 25 * 1024 * 1024) {
9196
+ failure = new Error("The recording is too large. Try a shorter clip.");
9197
+ stop();
9198
+ } else if (event.data.size) chunks.push(event.data);
9199
+ };
9200
+ recorder.onerror = () => {
9201
+ failure = new Error("Recording was interrupted. Try again or choose a file.");
9202
+ stop();
9203
+ };
9204
+ recorder.onstop = () => {
9205
+ clean();
9206
+ if (failure) reject(failure);
9207
+ else if (cancelled || !chunks.length) resolve(null);
9208
+ else {
9209
+ const type = recorder.mimeType.split(";")[0] || (kind === "audio" ? "audio/webm" : "video/webm");
9210
+ const extension = type.includes("mp4") ? kind === "audio" ? "m4a" : "mp4" : type.includes("ogg") ? "ogg" : "webm";
9211
+ resolve(new File(chunks, `community-${kind}-${Date.now()}.${extension}`, { type }));
9212
+ }
9213
+ chunks.length = 0;
9214
+ };
9215
+ signal?.addEventListener("abort", cancel, { once: true });
9216
+ try {
9217
+ recorder.start(250);
9218
+ timer = setTimeout(stop, kind === "video" ? 15e3 : 6e4);
9219
+ } catch (error) {
9220
+ clean();
9221
+ reject(error);
9222
+ }
9223
+ });
9224
+ return { stream, result, stop, cancel };
9225
+ }
9226
+
9005
9227
  // src/index.ts
9006
9228
  var ScaleMule = class {
9007
9229
  /** @deprecated Use `workspaces` instead */
@@ -9042,6 +9264,7 @@ var ScaleMule = class {
9042
9264
  this.leaderboard = new LeaderboardService(this._client);
9043
9265
  this.listings = new ListingsService(this._client);
9044
9266
  this.communityMaps = new CommunityMapsService(this._client);
9267
+ this.localIntelligence = new LocalIntelligenceService(this._client);
9045
9268
  this.polls = new PollsService(this._client);
9046
9269
  this.events = new EventsService(this._client);
9047
9270
  this.graph = new GraphService(this._client);
@@ -9219,6 +9442,7 @@ export {
9219
9442
  LeaderboardService,
9220
9443
  LeadsService,
9221
9444
  ListingsService,
9445
+ LocalIntelligenceService,
9222
9446
  LoggerService,
9223
9447
  MEDIA_PRESETS,
9224
9448
  MediaService,
@@ -9250,6 +9474,7 @@ export {
9250
9474
  WebPushManager,
9251
9475
  WebhooksService,
9252
9476
  WorkspacesService,
9477
+ applyIntelligenceChanges,
9253
9478
  buildClientContextHeaders,
9254
9479
  calculateTotalParts,
9255
9480
  canPerform,
@@ -9273,8 +9498,10 @@ export {
9273
9498
  normalizePhoneNumber,
9274
9499
  pollSharePercent,
9275
9500
  pollVoterKey,
9501
+ prepareCommunityMapAttachment,
9276
9502
  readAnonymousId,
9277
9503
  resolveStrategy,
9504
+ startMediaCapture,
9278
9505
  uploadMultipartToS3,
9279
9506
  uploadSingleToS3,
9280
9507
  validateIP
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scalemule/sdk",
3
- "version": "0.0.74",
3
+ "version": "0.0.76",
4
4
  "description": "Official TypeScript/JavaScript SDK for ScaleMule Backend-as-a-Service",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -63,15 +63,8 @@
63
63
  },
64
64
  "dependencies": {
65
65
  "@scalemule/ui": ">=0.0.1",
66
- "semver": "^7.7.4"
67
- },
68
- "peerDependencies": {
69
- "browser-image-compression": ">=2.0.0"
70
- },
71
- "peerDependenciesMeta": {
72
- "browser-image-compression": {
73
- "optional": true
74
- }
66
+ "semver": "^7.7.4",
67
+ "browser-image-compression": "^2.0.2"
75
68
  },
76
69
  "devDependencies": {
77
70
  "@scalemule/ui": ">=0.0.1",