@easy-cookie/core 0.1.0 → 0.1.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.
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- /*! @easy-cookie/core 0.1.0 | MIT | includes vanilla-cookieconsent v3.3.0 (c) Orest Bida, MIT */
1
+ /*! @easy-cookie/core 0.1.1 | MIT | includes vanilla-cookieconsent v3.3.0 (c) Orest Bida, MIT */
2
2
  "use strict";
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -2940,6 +2940,8 @@ function createEasyCookie() {
2940
2940
  let texts = null;
2941
2941
  const listeners = /* @__PURE__ */ new Map();
2942
2942
  let pendingMethod = null;
2943
+ let pendingSubject = null;
2944
+ let lastSend = Promise.resolve(true);
2943
2945
  let firstFlag = false;
2944
2946
  let previous = [];
2945
2947
  let reopen = null;
@@ -3022,6 +3024,12 @@ function createEasyCookie() {
3022
3024
  afterState(state);
3023
3025
  emit(first ? "consent" : "change", { consent: state, changed, first });
3024
3026
  const sent = config.log ? sendRecord(config.log, record(state)) : Promise.resolve(true);
3027
+ lastSend = sent;
3028
+ if (pendingSubject && config.log) {
3029
+ const subject = pendingSubject;
3030
+ pendingSubject = null;
3031
+ void sent.then((ok) => ok && sendSubject(config.log, state.id, subject));
3032
+ }
3025
3033
  if ((_a = config.log) == null ? void 0 : _a.requireLog)
3026
3034
  sent.then((ok) => {
3027
3035
  if (!ok) {
@@ -3036,6 +3044,7 @@ function createEasyCookie() {
3036
3044
  }
3037
3045
  };
3038
3046
  const afterState = (state) => {
3047
+ if (w) w.__easyCookieHead = { granted: state ? state.categories : config.resolvedCategories.filter((c) => c.readOnly).map((c) => c.id), valid: !!state };
3039
3048
  renderMosaic(document.querySelector("#cc-main .cm"), config, texts, lang, state);
3040
3049
  reopen == null ? void 0 : reopen.update(state);
3041
3050
  embeds == null ? void 0 : embeds.refresh();
@@ -3224,9 +3233,14 @@ function createEasyCookie() {
3224
3233
  hide();
3225
3234
  },
3226
3235
  async identify(subjectId) {
3236
+ if (!(config == null ? void 0 : config.log)) return false;
3227
3237
  const s = get();
3228
- if (!s || !(config == null ? void 0 : config.log)) return;
3229
- await sendSubject(config.log, s.id, subjectId);
3238
+ if (!s) {
3239
+ pendingSubject = subjectId;
3240
+ return false;
3241
+ }
3242
+ await lastSend;
3243
+ return sendSubject(config.log, s.id, subjectId);
3230
3244
  },
3231
3245
  reset() {
3232
3246
  if (!config) return;