@ancon/wildcat-utils 1.34.0 → 1.34.2

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.
@@ -1,4 +1,4 @@
1
- import { ModificationType } from '@ancon/wildcat-types';
1
+ import { CheckoutItemUnitPrice, ModificationType, ProductType, VariantType } from '@ancon/wildcat-types';
2
2
  export declare type CheckoutRequestItemModification = {
3
3
  modification: ModificationType;
4
4
  ingredientId: string;
@@ -8,10 +8,15 @@ export declare type CheckoutRequestItemModification = {
8
8
  replaceId?: string;
9
9
  };
10
10
  export declare type CheckoutRequestItem = {
11
- variantId: string;
11
+ variantId?: string;
12
+ variantType?: VariantType;
13
+ productId?: string;
14
+ productType?: ProductType;
12
15
  quantity: number;
13
16
  modifications: CheckoutRequestItemModification[];
14
17
  upsellGroupId?: string | null;
15
18
  showingPrice?: number;
19
+ price?: CheckoutItemUnitPrice;
20
+ metaData?: string | null;
16
21
  };
17
22
  export declare type CheckoutItemComparisonCandidate = Pick<CheckoutRequestItem, 'variantId' | 'modifications' | 'upsellGroupId'>;
@@ -30,9 +30,10 @@ declare class HangfirePoller {
30
30
  private startTimer;
31
31
  private executeWorkerRequest;
32
32
  private deleteWorker;
33
- createWorker(groupId: string, { workerId, url, }: {
33
+ createWorker(groupId: string, { workerId, url, headers, }: {
34
34
  workerId: string;
35
35
  url: string;
36
+ headers: APIHeaders;
36
37
  }): Promise<unknown>;
37
38
  triggerWorker(workerId: string): void;
38
39
  /** May be called either before or after `createWorker()` */
@@ -1 +1 @@
1
- "use strict";var g=Object.defineProperty;var f=(t,e,r)=>e in t?g(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var i=(t,e,r)=>(f(t,typeof e!="symbol"?e+"":e,r),r);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const p=require("axios"),n=require("@ancon/wildcat-types"),a=require("../error/createCodedError.js"),b=require("../api/isNoContentResponse.js");class c{constructor(e){i(this,"busyWorkers",new Set);i(this,"enabledGroups",new Set);i(this,"groups",new Map);i(this,"workerByIdMap",new Map);i(this,"timer",null);i(this,"config",{maxGroupsSize:50,maxWorkersSize:20,getIsNetworkOnline(){return!0},async getRequestHeaders(){return{}},debug(...e){console.log(...e)}});this.config={...this.config,...e??null}}stopTimer(){this.timer!=null&&(this.config.debug("*stop timer*"),clearInterval(this.timer),this.timer=null)}startTimer(){if(this.timer!=null)throw a(new Error("Timer already started"),n.ErrorCode.GenericUnexpectedHangfireError);this.config.debug("*start timer*"),this.timer=setInterval(()=>{this.config.debug("*tick*",{busyWorkers:this.busyWorkers.size,enabledGroups:this.enabledGroups.size,groups:this.groups}),this.enabledGroups.forEach(e=>{const r=this.groups.get(e);r&&r.forEach(s=>this.executeWorkerRequest(s))}),this.groups.size<1&&this.stopTimer()},5e3)}async executeWorkerRequest(e){const r=this.config.getIsNetworkOnline();!this.busyWorkers.has(e.workerId)&&r&&(this.busyWorkers.add(e.workerId),p({url:e.url,method:"get",headers:await this.config.getRequestHeaders()}).then(s=>{s&&!b(s)?(e.resolve(s),this.deleteWorker(e.groupId,e.workerId)):this.busyWorkers.delete(e.workerId)}).catch(s=>{e.reject(s),this.deleteWorker(e.groupId,e.workerId)}))}deleteWorker(e,r){const s=this.groups.get(e);s&&(this.config.debug("*delete worker*",s.size,s),s.delete(r),this.workerByIdMap.delete(r),this.busyWorkers.delete(r),s.size<1&&(this.groups.delete(e),this.enabledGroups.delete(e),this.enabledGroups.size<1&&this.stopTimer()))}createWorker(e,{workerId:r,url:s}){if(!this.groups.has(e)){if(this.groups.size>=this.config.maxGroupsSize){const u=a(new Error("Max number of Hangfire groups exceeded"),n.ErrorCode.GenericUnexpectedHangfireError,{count:this.groups.size});throw this.destroy(),u}this.groups.set(e,new Map)}const o=this.groups.get(e);return new Promise((u,h)=>{if(o.has(r))throw a(new Error("Duplicate Hangfire worker ID"),n.ErrorCode.GenericUnexpectedHangfireError);if(o.size>=this.config.maxWorkersSize){const d=a(new Error("Max number of Hangfire workers in group exceeded"),n.ErrorCode.GenericUnexpectedHangfireError,{groupId:e,count:o.size});throw h(d),this.destroy(),d}const l={workerId:r,groupId:e,url:s,resolve:u,reject:h};o.set(r,l),this.workerByIdMap.set(r,l),this.enabledGroups.has(e)||this.enabledGroups.add(e),this.timer==null&&this.enabledGroups.size>0&&this.startTimer()})}triggerWorker(e){this.config.debug("*triggerWorker*");const r=this.workerByIdMap.get(e);r&&this.executeWorkerRequest(r)}enableWorkers(e){this.config.debug("*enable*",e),this.enabledGroups.add(e),this.groups.has(e)&&this.timer==null&&this.startTimer()}disableWorkers(e){this.config.debug("*disable*",e),this.enabledGroups.delete(e),this.enabledGroups.size<1&&this.stopTimer()}destroy(){this.config.debug("*destroy*"),this.groups.clear(),this.stopTimer()}}function m(t){return new c(t)}exports.HangfirePoller=c;exports.default=m;
1
+ "use strict";var f=Object.defineProperty;var p=(t,e,r)=>e in t?f(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var i=(t,e,r)=>(p(t,typeof e!="symbol"?e+"":e,r),r);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const b=require("axios"),n=require("@ancon/wildcat-types"),a=require("../error/createCodedError.js"),m=require("../api/isNoContentResponse.js");class c{constructor(e){i(this,"busyWorkers",new Set);i(this,"enabledGroups",new Set);i(this,"groups",new Map);i(this,"workerByIdMap",new Map);i(this,"timer",null);i(this,"config",{maxGroupsSize:50,maxWorkersSize:20,getIsNetworkOnline(){return!0},async getRequestHeaders(){return{}},debug(...e){console.log(...e)}});this.config={...this.config,...e??null}}stopTimer(){this.timer!=null&&(this.config.debug("*stop timer*"),clearInterval(this.timer),this.timer=null)}startTimer(){if(this.timer!=null)throw a(new Error("Timer already started"),n.ErrorCode.GenericUnexpectedHangfireError);this.config.debug("*start timer*"),this.timer=setInterval(()=>{this.config.debug("*tick*",{busyWorkers:this.busyWorkers.size,enabledGroups:this.enabledGroups.size,groups:this.groups}),this.enabledGroups.forEach(e=>{const r=this.groups.get(e);r&&r.forEach(s=>this.executeWorkerRequest(s))}),this.groups.size<1&&this.stopTimer()},5e3)}async executeWorkerRequest(e){const r=this.config.getIsNetworkOnline();!this.busyWorkers.has(e.workerId)&&r&&(this.busyWorkers.add(e.workerId),b({url:e.url,method:"get",headers:{...await this.config.getRequestHeaders(),...e.headers}}).then(s=>{s&&!m(s)?(e.resolve(s),this.deleteWorker(e.groupId,e.workerId)):this.busyWorkers.delete(e.workerId)}).catch(s=>{e.reject(s),this.deleteWorker(e.groupId,e.workerId)}))}deleteWorker(e,r){const s=this.groups.get(e);s&&(this.config.debug("*delete worker*",s.size,s),s.delete(r),this.workerByIdMap.delete(r),this.busyWorkers.delete(r),s.size<1&&(this.groups.delete(e),this.enabledGroups.delete(e),this.enabledGroups.size<1&&this.stopTimer()))}createWorker(e,{workerId:r,url:s,headers:g}){if(!this.groups.has(e)){if(this.groups.size>=this.config.maxGroupsSize){const u=a(new Error("Max number of Hangfire groups exceeded"),n.ErrorCode.GenericUnexpectedHangfireError,{count:this.groups.size});throw this.destroy(),u}this.groups.set(e,new Map)}const o=this.groups.get(e);return new Promise((u,h)=>{if(o.has(r))throw a(new Error("Duplicate Hangfire worker ID"),n.ErrorCode.GenericUnexpectedHangfireError);if(o.size>=this.config.maxWorkersSize){const d=a(new Error("Max number of Hangfire workers in group exceeded"),n.ErrorCode.GenericUnexpectedHangfireError,{groupId:e,count:o.size});throw h(d),this.destroy(),d}const l={workerId:r,groupId:e,url:s,resolve:u,reject:h,headers:g};o.set(r,l),this.workerByIdMap.set(r,l),this.enabledGroups.has(e)||this.enabledGroups.add(e),this.timer==null&&this.enabledGroups.size>0&&this.startTimer()})}triggerWorker(e){this.config.debug("*triggerWorker*");const r=this.workerByIdMap.get(e);r&&this.executeWorkerRequest(r)}enableWorkers(e){this.config.debug("*enable*",e),this.enabledGroups.add(e),this.groups.has(e)&&this.timer==null&&this.startTimer()}disableWorkers(e){this.config.debug("*disable*",e),this.enabledGroups.delete(e),this.enabledGroups.size<1&&this.stopTimer()}destroy(){this.config.debug("*destroy*"),this.groups.clear(),this.stopTimer()}}function k(t){return new c(t)}exports.HangfirePoller=c;exports.default=k;
@@ -1,11 +1,11 @@
1
- var g = Object.defineProperty;
2
- var c = (t, e, r) => e in t ? g(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
3
- var i = (t, e, r) => (c(t, typeof e != "symbol" ? e + "" : e, r), r);
4
- import f from "axios";
1
+ var c = Object.defineProperty;
2
+ var f = (t, e, r) => e in t ? c(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
3
+ var i = (t, e, r) => (f(t, typeof e != "symbol" ? e + "" : e, r), r);
4
+ import p from "axios";
5
5
  import { ErrorCode as n } from "@ancon/wildcat-types";
6
6
  import h from "../error/createCodedError.mjs";
7
- import p from "../api/isNoContentResponse.mjs";
8
- class m {
7
+ import m from "../api/isNoContentResponse.mjs";
8
+ class b {
9
9
  constructor(e) {
10
10
  /** Workers currently executing a request */
11
11
  i(this, "busyWorkers", /* @__PURE__ */ new Set());
@@ -56,12 +56,15 @@ class m {
56
56
  }
57
57
  async executeWorkerRequest(e) {
58
58
  const r = this.config.getIsNetworkOnline();
59
- !this.busyWorkers.has(e.workerId) && r && (this.busyWorkers.add(e.workerId), f({
59
+ !this.busyWorkers.has(e.workerId) && r && (this.busyWorkers.add(e.workerId), p({
60
60
  url: e.url,
61
61
  method: "get",
62
- headers: await this.config.getRequestHeaders()
62
+ headers: {
63
+ ...await this.config.getRequestHeaders(),
64
+ ...e.headers
65
+ }
63
66
  }).then((s) => {
64
- s && !p(s) ? (e.resolve(s), this.deleteWorker(e.groupId, e.workerId)) : this.busyWorkers.delete(e.workerId);
67
+ s && !m(s) ? (e.resolve(s), this.deleteWorker(e.groupId, e.workerId)) : this.busyWorkers.delete(e.workerId);
65
68
  }).catch((s) => {
66
69
  e.reject(s), this.deleteWorker(e.groupId, e.workerId);
67
70
  }));
@@ -72,7 +75,8 @@ class m {
72
75
  }
73
76
  createWorker(e, {
74
77
  workerId: r,
75
- url: s
78
+ url: s,
79
+ headers: g
76
80
  }) {
77
81
  if (!this.groups.has(e)) {
78
82
  if (this.groups.size >= this.config.maxGroupsSize) {
@@ -105,7 +109,8 @@ class m {
105
109
  groupId: e,
106
110
  url: s,
107
111
  resolve: a,
108
- reject: u
112
+ reject: u,
113
+ headers: g
109
114
  };
110
115
  o.set(r, l), this.workerByIdMap.set(r, l), this.enabledGroups.has(e) || this.enabledGroups.add(e), this.timer == null && this.enabledGroups.size > 0 && this.startTimer();
111
116
  });
@@ -126,10 +131,10 @@ class m {
126
131
  this.config.debug("*destroy*"), this.groups.clear(), this.stopTimer();
127
132
  }
128
133
  }
129
- function G(t) {
130
- return new m(t);
134
+ function x(t) {
135
+ return new b(t);
131
136
  }
132
137
  export {
133
- m as HangfirePoller,
134
- G as default
138
+ b as HangfirePoller,
139
+ x as default
135
140
  };
@@ -1,4 +1,4 @@
1
- import type { APIParams, APIPostRequest, APIPutRequest } from '@ancon/wildcat-types';
1
+ import type { APIHeaders, APIParams, APIPostRequest, APIPutRequest } from '@ancon/wildcat-types';
2
2
  import type { AxiosResponse } from 'axios';
3
3
  import { HangfirePoller } from './createHangfirePoller';
4
4
  /**
@@ -6,5 +6,5 @@ import { HangfirePoller } from './createHangfirePoller';
6
6
  * @param hangfirePoller `HangfirePoller` instance from `createHangfirePoller()`
7
7
  * @returns `makeHangfireRequest()` callback function
8
8
  */
9
- declare function createMakeHangfireRequest(hangfirePoller: HangfirePoller): <TData extends Record<string, any>, TParams extends APIParams>(request: APIPostRequest<unknown, TData, TParams> | APIPutRequest<unknown, TData, TParams>, data: TData, params: TParams, groupId: string) => Promise<AxiosResponse>;
9
+ declare function createMakeHangfireRequest(hangfirePoller: HangfirePoller): <TData extends Record<string, any>, TParams extends APIParams>(request: APIPostRequest<unknown, TData, TParams> | APIPutRequest<unknown, TData, TParams>, data: TData, params: TParams, groupId: string, headers?: APIHeaders) => Promise<AxiosResponse>;
10
10
  export default createMakeHangfireRequest;
@@ -1 +1 @@
1
- "use strict";const o=require("./isHangfireResponse.js");require("../api/isAcceptedResponse.js");function c(e,t){return`${e.config.baseURL??""}/${e.config.url??""}/status/${t}`}function f(e){return async function(i,a,s,u){const r=await i(a,s);if(o(r)){const n=r.data.id;return e.createWorker(u,{workerId:n,url:c(r,n)})}return r}}module.exports=f;
1
+ "use strict";const c=require("./isHangfireResponse.js");require("../api/isAcceptedResponse.js");function f(e,t){return`${e.config.baseURL??""}/${e.config.url??""}/status/${t}`}function g(e){return async function(u,a,s,o,n={}){const r=await u(a,s,n);if(c(r)){const i=r.data.id;return e.createWorker(o,{workerId:i,url:f(r,i),headers:n})}return r}}module.exports=g;
@@ -1,21 +1,22 @@
1
1
  import s from "./isHangfireResponse.mjs";
2
2
  import "../api/isAcceptedResponse.mjs";
3
- function f(e, t) {
4
- return `${e.config.baseURL ?? ""}/${e.config.url ?? ""}/status/${t}`;
3
+ function c(r, t) {
4
+ return `${r.config.baseURL ?? ""}/${r.config.url ?? ""}/status/${t}`;
5
5
  }
6
- function k(e) {
7
- return async function(a, o, i, u) {
8
- const r = await a(o, i);
9
- if (s(r)) {
10
- const n = r.data.id;
11
- return e.createWorker(u, {
12
- workerId: n,
13
- url: f(r, n)
6
+ function l(r) {
7
+ return async function(o, i, u, f, n = {}) {
8
+ const e = await o(i, u, n);
9
+ if (s(e)) {
10
+ const a = e.data.id;
11
+ return r.createWorker(f, {
12
+ workerId: a,
13
+ url: c(e, a),
14
+ headers: n
14
15
  });
15
16
  }
16
- return r;
17
+ return e;
17
18
  };
18
19
  }
19
20
  export {
20
- k as default
21
+ l as default
21
22
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ancon/wildcat-utils",
3
- "version": "1.34.0",
3
+ "version": "1.34.2",
4
4
  "private": false,
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",