@softtynet/zca-js 2.1.18 → 2.1.19

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.
@@ -309,7 +309,7 @@ async function getDefaultHeaders(ctx, origin = "https://chat.zalo.me") {
309
309
  if (!ctx.userAgent)
310
310
  throw new ZaloApiError.ZaloApiError("User agent is not available");
311
311
  const secChUa = getSecChUaHeaders(ctx.userAgent);
312
- return Object.assign({ accept: "*/*", "accept-encoding": "gzip, deflate, br, zstd", "accept-language": getBrowserLanguage(ctx.language), "content-type": "application/x-www-form-urlencoded", cookie: await ctx.cookie.getCookieString(origin), origin: "https://chat.zalo.me", priority: "u=1, i", referer: "https://chat.zalo.me/", "user-agent": ctx.userAgent, "sec-fetch-dest": "empty", "sec-fetch-mode": "cors", "sec-fetch-site": "same-site" }, secChUa);
312
+ return Object.assign({ accept: "*/*", "accept-encoding": "gzip, deflate, br, zstd", "accept-language": getBrowserLanguage(ctx.language), "content-type": "application/x-www-form-urlencoded", cookie: await ctx.cookie.getCookieString(origin), origin: origin, priority: "u=1, i", referer: `${origin}/`, "user-agent": ctx.userAgent, "sec-fetch-dest": "empty", "sec-fetch-mode": "cors", "sec-fetch-site": origin === "https://id.zalo.me" ? "same-origin" : "same-site" }, secChUa);
313
313
  }
314
314
  async function request(ctx, url, options, raw = false) {
315
315
  var _a, _b;
@@ -318,11 +318,23 @@ async function request(ctx, url, options, raw = false) {
318
318
  const origin = new URL(url).origin;
319
319
  const defaultHeaders = await getDefaultHeaders(ctx, origin);
320
320
  if (!raw) {
321
- if (options) {
322
- options.headers = Object.assign(defaultHeaders, options.headers || {});
321
+ if (options && options.headers) {
322
+ const mergedHeaders = Object.assign({}, defaultHeaders);
323
+ const inputHeaders = options.headers;
324
+ for (const [key, value] of Object.entries(inputHeaders)) {
325
+ const lowerKey = key.toLowerCase();
326
+ for (const existingKey of Object.keys(mergedHeaders)) {
327
+ if (existingKey.toLowerCase() === lowerKey && existingKey !== key) {
328
+ delete mergedHeaders[existingKey];
329
+ }
330
+ }
331
+ mergedHeaders[key] = value;
332
+ }
333
+ options.headers = mergedHeaders;
334
+ }
335
+ else {
336
+ options = Object.assign(Object.assign({}, (options || {})), { headers: defaultHeaders });
323
337
  }
324
- else
325
- options = { headers: defaultHeaders };
326
338
  }
327
339
  const _options = Object.assign(Object.assign({}, (options !== null && options !== void 0 ? options : {})), (isBun
328
340
  ? {
package/dist/utils.js CHANGED
@@ -305,7 +305,7 @@ export async function getDefaultHeaders(ctx, origin = "https://chat.zalo.me") {
305
305
  if (!ctx.userAgent)
306
306
  throw new ZaloApiError("User agent is not available");
307
307
  const secChUa = getSecChUaHeaders(ctx.userAgent);
308
- return Object.assign({ accept: "*/*", "accept-encoding": "gzip, deflate, br, zstd", "accept-language": getBrowserLanguage(ctx.language), "content-type": "application/x-www-form-urlencoded", cookie: await ctx.cookie.getCookieString(origin), origin: "https://chat.zalo.me", priority: "u=1, i", referer: "https://chat.zalo.me/", "user-agent": ctx.userAgent, "sec-fetch-dest": "empty", "sec-fetch-mode": "cors", "sec-fetch-site": "same-site" }, secChUa);
308
+ return Object.assign({ accept: "*/*", "accept-encoding": "gzip, deflate, br, zstd", "accept-language": getBrowserLanguage(ctx.language), "content-type": "application/x-www-form-urlencoded", cookie: await ctx.cookie.getCookieString(origin), origin: origin, priority: "u=1, i", referer: `${origin}/`, "user-agent": ctx.userAgent, "sec-fetch-dest": "empty", "sec-fetch-mode": "cors", "sec-fetch-site": origin === "https://id.zalo.me" ? "same-origin" : "same-site" }, secChUa);
309
309
  }
310
310
  export async function request(ctx, url, options, raw = false) {
311
311
  var _a, _b;
@@ -314,11 +314,23 @@ export async function request(ctx, url, options, raw = false) {
314
314
  const origin = new URL(url).origin;
315
315
  const defaultHeaders = await getDefaultHeaders(ctx, origin);
316
316
  if (!raw) {
317
- if (options) {
318
- options.headers = Object.assign(defaultHeaders, options.headers || {});
317
+ if (options && options.headers) {
318
+ const mergedHeaders = Object.assign({}, defaultHeaders);
319
+ const inputHeaders = options.headers;
320
+ for (const [key, value] of Object.entries(inputHeaders)) {
321
+ const lowerKey = key.toLowerCase();
322
+ for (const existingKey of Object.keys(mergedHeaders)) {
323
+ if (existingKey.toLowerCase() === lowerKey && existingKey !== key) {
324
+ delete mergedHeaders[existingKey];
325
+ }
326
+ }
327
+ mergedHeaders[key] = value;
328
+ }
329
+ options.headers = mergedHeaders;
330
+ }
331
+ else {
332
+ options = Object.assign(Object.assign({}, (options || {})), { headers: defaultHeaders });
319
333
  }
320
- else
321
- options = { headers: defaultHeaders };
322
334
  }
323
335
  const _options = Object.assign(Object.assign({}, (options !== null && options !== void 0 ? options : {})), (isBun
324
336
  ? {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@softtynet/zca-js",
3
- "version": "2.1.18",
3
+ "version": "2.1.19",
4
4
  "description": "Unofficial Zalo API for JavaScript",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",