@ancon/wildcat-utils 1.51.0-check-optimizations.5 → 1.51.0
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/check/getOrganizedCheckItemModifications.d.ts +2 -2
- package/check/getOrganizedCheckItemModifications.js +1 -1
- package/check/getOrganizedCheckItemModifications.mjs +68 -74
- package/check/getUniqueCheckItemModificationId.d.ts +2 -2
- package/check/getUniqueCheckItemModificationId.js +1 -1
- package/check/getUniqueCheckItemModificationId.mjs +5 -5
- package/index.d.ts +1 -0
- package/index.js +1 -1
- package/index.mjs +339 -331
- package/mpsGiftCard/decodeMPSGiftCardQr.d.ts +14 -0
- package/mpsGiftCard/decodeMPSGiftCardQr.js +1 -0
- package/mpsGiftCard/decodeMPSGiftCardQr.mjs +54 -0
- package/mpsGiftCard/index.d.ts +4 -0
- package/mpsGiftCard/index.js +1 -0
- package/mpsGiftCard/index.mjs +10 -0
- package/mpsGiftCard/resolveMPSGiftCardScanAction.d.ts +8 -0
- package/mpsGiftCard/resolveMPSGiftCardScanAction.js +1 -0
- package/mpsGiftCard/resolveMPSGiftCardScanAction.mjs +10 -0
- package/mpsGiftCard/types.d.ts +30 -0
- package/mpsGiftCard/types.js +1 -0
- package/mpsGiftCard/types.mjs +4 -0
- package/multilingual/createLocalizedCheckDetails.d.ts +2 -2
- package/multilingual/createLocalizedCheckDetails.js +1 -1
- package/multilingual/createLocalizedCheckDetails.mjs +27 -31
- package/package.json +21 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { MPSQrDecodeResult } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Reverse the MPS obfuscation: every `??X` becomes the lowercase of `X`.
|
|
4
|
+
* Repeats until no `??` markers remain, with a guard against non-progress.
|
|
5
|
+
*/
|
|
6
|
+
export declare function deobfuscateMPSQrPayload(input: string): string;
|
|
7
|
+
/**
|
|
8
|
+
* Decode an MPS gift card QR reading into its card serial number and expiry.
|
|
9
|
+
* Never throws — every failure mode is represented in the return value.
|
|
10
|
+
*
|
|
11
|
+
* @param reading Raw scanner string.
|
|
12
|
+
* @param now Reference time for the expiry check (defaults to current time).
|
|
13
|
+
*/
|
|
14
|
+
export default function decodeMPSGiftCardQr(reading: string, now?: Date): MPSQrDecodeResult;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const d=require("bson"),c="QR=",l="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",f=(()=>{const r=new Int16Array(256).fill(-1);for(let e=0;e<l.length;e+=1)r[l.charCodeAt(e)]=e;return r})();function b(r){const e=r.replace(/=+$/,""),t=new Uint8Array(Math.floor(e.length*6/8));let s=0,n=0,i=0;for(let o=0;o<e.length;o+=1){const a=f[e.charCodeAt(o)];if(a===-1)throw new Error("Invalid base64 character");s=s<<6|a,n+=6,n>=8&&(n-=8,t[i]=s>>n&255,i+=1)}return t}function u(r){let e=r;for(;e.includes("??");){const t=e.replace(/\?\?(.)/g,(s,n)=>n.toLowerCase());if(t===e)break;e=t}return e}function S(r,e=new Date){if(!r)return{isMPSQr:!1};let t=r.trim().replace(/^['"]+/,"").replace(/['"]+$/,"").trim();if(!t.startsWith(c))return{isMPSQr:!1};t=t.slice(c.length);try{const s=u(t),n=b(s),i=d.deserialize(n),o=i.CardSerialnumber,a=i.ServerTimestamp;return typeof o!="string"||o.length===0||!(a instanceof Date)?{isMPSQr:!0,error:"decode"}:{isMPSQr:!0,cardSerialNumber:o,serverTimestamp:a,isExpired:a.getTime()<=e.getTime()}}catch{return{isMPSQr:!0,error:"decode"}}}exports.default=S;exports.deobfuscateMPSQrPayload=u;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { deserialize as u } from "bson";
|
|
2
|
+
const c = "QR=", l = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", f = (() => {
|
|
3
|
+
const r = new Int16Array(256).fill(-1);
|
|
4
|
+
for (let e = 0; e < l.length; e += 1)
|
|
5
|
+
r[l.charCodeAt(e)] = e;
|
|
6
|
+
return r;
|
|
7
|
+
})();
|
|
8
|
+
function d(r) {
|
|
9
|
+
const e = r.replace(/=+$/, ""), t = new Uint8Array(Math.floor(e.length * 6 / 8));
|
|
10
|
+
let s = 0, n = 0, i = 0;
|
|
11
|
+
for (let o = 0; o < e.length; o += 1) {
|
|
12
|
+
const a = f[e.charCodeAt(o)];
|
|
13
|
+
if (a === -1)
|
|
14
|
+
throw new Error("Invalid base64 character");
|
|
15
|
+
s = s << 6 | a, n += 6, n >= 8 && (n -= 8, t[i] = s >> n & 255, i += 1);
|
|
16
|
+
}
|
|
17
|
+
return t;
|
|
18
|
+
}
|
|
19
|
+
function h(r) {
|
|
20
|
+
let e = r;
|
|
21
|
+
for (; e.includes("??"); ) {
|
|
22
|
+
const t = e.replace(
|
|
23
|
+
/\?\?(.)/g,
|
|
24
|
+
(s, n) => n.toLowerCase()
|
|
25
|
+
);
|
|
26
|
+
if (t === e)
|
|
27
|
+
break;
|
|
28
|
+
e = t;
|
|
29
|
+
}
|
|
30
|
+
return e;
|
|
31
|
+
}
|
|
32
|
+
function S(r, e = /* @__PURE__ */ new Date()) {
|
|
33
|
+
if (!r)
|
|
34
|
+
return { isMPSQr: !1 };
|
|
35
|
+
let t = r.trim().replace(/^['"]+/, "").replace(/['"]+$/, "").trim();
|
|
36
|
+
if (!t.startsWith(c))
|
|
37
|
+
return { isMPSQr: !1 };
|
|
38
|
+
t = t.slice(c.length);
|
|
39
|
+
try {
|
|
40
|
+
const s = h(t), n = d(s), i = u(n), o = i.CardSerialnumber, a = i.ServerTimestamp;
|
|
41
|
+
return typeof o != "string" || o.length === 0 || !(a instanceof Date) ? { isMPSQr: !0, error: "decode" } : {
|
|
42
|
+
isMPSQr: !0,
|
|
43
|
+
cardSerialNumber: o,
|
|
44
|
+
serverTimestamp: a,
|
|
45
|
+
isExpired: a.getTime() <= e.getTime()
|
|
46
|
+
};
|
|
47
|
+
} catch {
|
|
48
|
+
return { isMPSQr: !0, error: "decode" };
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
S as default,
|
|
53
|
+
h as deobfuscateMPSQrPayload
|
|
54
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import decodeMPSGiftCardQr, { deobfuscateMPSQrPayload } from './decodeMPSGiftCardQr';
|
|
2
|
+
import resolveMPSGiftCardScanAction from './resolveMPSGiftCardScanAction';
|
|
3
|
+
export { decodeMPSGiftCardQr, deobfuscateMPSQrPayload, resolveMPSGiftCardScanAction, };
|
|
4
|
+
export * from './types';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./decodeMPSGiftCardQr.js"),r=require("./resolveMPSGiftCardScanAction.js"),t=require("./types.js");require("bson");exports.decodeMPSGiftCardQr=e.default;exports.deobfuscateMPSQrPayload=e.deobfuscateMPSQrPayload;exports.resolveMPSGiftCardScanAction=r;exports.MPSQrScanActionType=t.MPSQrScanActionType;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { default as a, deobfuscateMPSQrPayload as t } from "./decodeMPSGiftCardQr.mjs";
|
|
2
|
+
import { default as f } from "./resolveMPSGiftCardScanAction.mjs";
|
|
3
|
+
import { MPSQrScanActionType as S } from "./types.mjs";
|
|
4
|
+
import "bson";
|
|
5
|
+
export {
|
|
6
|
+
S as MPSQrScanActionType,
|
|
7
|
+
a as decodeMPSGiftCardQr,
|
|
8
|
+
t as deobfuscateMPSQrPayload,
|
|
9
|
+
f as resolveMPSGiftCardScanAction
|
|
10
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { MPSQrDecodeResult, MPSQrScanAction } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Decide what to do with an MPS QR decode result, given whether the currently
|
|
4
|
+
* selected check can be paid with a gift card. Pure — no side effects.
|
|
5
|
+
*/
|
|
6
|
+
export default function resolveMPSGiftCardScanAction(result: MPSQrDecodeResult, context: {
|
|
7
|
+
hasPayableCheck: boolean;
|
|
8
|
+
}): MPSQrScanAction;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const e=require("./types.js");function n(r,i){return r.isMPSQr?r.error?{type:e.MPSQrScanActionType.Invalid}:r.isExpired?{type:e.MPSQrScanActionType.Expired}:i.hasPayableCheck?{type:e.MPSQrScanActionType.Redeem,cardSerialNumber:r.cardSerialNumber}:{type:e.MPSQrScanActionType.NoPayableCheck}:{type:e.MPSQrScanActionType.Ignore}}module.exports=n;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { MPSQrScanActionType as e } from "./types.mjs";
|
|
2
|
+
function t(r, i) {
|
|
3
|
+
return r.isMPSQr ? r.error ? { type: e.Invalid } : r.isExpired ? { type: e.Expired } : i.hasPayableCheck ? {
|
|
4
|
+
type: e.Redeem,
|
|
5
|
+
cardSerialNumber: r.cardSerialNumber
|
|
6
|
+
} : { type: e.NoPayableCheck } : { type: e.Ignore };
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
t as default
|
|
10
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** Reason an MPS QR payload could not be decoded. */
|
|
2
|
+
export declare type MPSQrDecodeError = 'decode';
|
|
3
|
+
export interface MPSQrDecodeResult {
|
|
4
|
+
/** True when the reading is an MPS QR payload (has the QR= prefix). */
|
|
5
|
+
isMPSQr: boolean;
|
|
6
|
+
cardSerialNumber?: string;
|
|
7
|
+
serverTimestamp?: Date;
|
|
8
|
+
isExpired?: boolean;
|
|
9
|
+
/** Set when an MPS QR payload could not be decoded. */
|
|
10
|
+
error?: MPSQrDecodeError;
|
|
11
|
+
}
|
|
12
|
+
export declare enum MPSQrScanActionType {
|
|
13
|
+
Ignore = 0,
|
|
14
|
+
Invalid = 1,
|
|
15
|
+
Expired = 2,
|
|
16
|
+
NoPayableCheck = 3,
|
|
17
|
+
Redeem = 4
|
|
18
|
+
}
|
|
19
|
+
export declare type MPSQrScanAction = {
|
|
20
|
+
type: MPSQrScanActionType.Ignore;
|
|
21
|
+
} | {
|
|
22
|
+
type: MPSQrScanActionType.Invalid;
|
|
23
|
+
} | {
|
|
24
|
+
type: MPSQrScanActionType.Expired;
|
|
25
|
+
} | {
|
|
26
|
+
type: MPSQrScanActionType.NoPayableCheck;
|
|
27
|
+
} | {
|
|
28
|
+
type: MPSQrScanActionType.Redeem;
|
|
29
|
+
cardSerialNumber: string;
|
|
30
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var d=(e=>(e[e.Ignore=0]="Ignore",e[e.Invalid=1]="Invalid",e[e.Expired=2]="Expired",e[e.NoPayableCheck=3]="NoPayableCheck",e[e.Redeem=4]="Redeem",e))(d||{});exports.MPSQrScanActionType=d;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CheckDetails } from '@ancon/wildcat-types';
|
|
2
2
|
/**
|
|
3
3
|
* This creates localized check details by replacing following properties with localized values based on current app language.
|
|
4
4
|
* Affected properties on each check item (and its sub-items):
|
|
@@ -12,5 +12,5 @@ import { CheckDetailsV2 } from '@ancon/wildcat-types';
|
|
|
12
12
|
* @param locale - locale to be used for localization
|
|
13
13
|
* @returns localized check details
|
|
14
14
|
*/
|
|
15
|
-
declare function createLocalizedCheckDetails(checkDetails:
|
|
15
|
+
declare function createLocalizedCheckDetails(checkDetails: CheckDetails, locale: string): CheckDetails;
|
|
16
16
|
export default createLocalizedCheckDetails;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const l=require("@ancon/wildcat-types");function u(e){switch(e){case"sv":return l.IETFLanguageTag.Swedish;case"nb":return l.IETFLanguageTag.Norwegian;case"en":return l.IETFLanguageTag.English;default:return null}}function s(e,c){var i,o;const t=e,a=(i=e.localizedProductNames)==null?void 0:i[c],n=(o=e.localizedVariantNames)==null?void 0:o[c];return a&&(t.productName=a),n&&(t.variantName=n),t}function m(e,c){var i,o;const t=e,a=(i=e.localizedNames)==null?void 0:i[c],n=(o=e.localizedReplacementNames)==null?void 0:o[c];return a&&(t.name=a),n&&(t.replacementName=n),t}function z(e,c){const t=e;return t.product=s(e.product,c),t}function d(e,c){const t=e,{product:a,modifications:n,addOnProducts:i,subCheckItems:o}=e;return t.product=s(a,c),n.length&&(t.modifications=n.map(r=>m(r,c))),i!=null&&i.length&&(t.addOnProducts=i.map(r=>z(r,c))),o.length&&(t.subCheckItems=o.map(r=>d(r,c))),t}function f(e,c){const t=u(c);if(t){const a=e;return a.items=e.items.map(n=>d(n,t)),a}return e}module.exports=f;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IETFLanguageTag as r } from "@ancon/wildcat-types";
|
|
2
|
-
function
|
|
2
|
+
function u(e) {
|
|
3
3
|
switch (e) {
|
|
4
4
|
case "sv":
|
|
5
5
|
return r.Swedish;
|
|
@@ -11,47 +11,43 @@ function m(e) {
|
|
|
11
11
|
return null;
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
function
|
|
15
|
-
var
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return n && (c.productName = n), o && (c.variantName = o), c;
|
|
19
|
-
}
|
|
20
|
-
return e;
|
|
14
|
+
function d(e, c) {
|
|
15
|
+
var i, n;
|
|
16
|
+
const t = e, a = (i = e.localizedProductNames) == null ? void 0 : i[c], o = (n = e.localizedVariantNames) == null ? void 0 : n[c];
|
|
17
|
+
return a && (t.productName = a), o && (t.variantName = o), t;
|
|
21
18
|
}
|
|
22
|
-
function
|
|
23
|
-
var
|
|
24
|
-
const t = e,
|
|
25
|
-
return
|
|
19
|
+
function m(e, c) {
|
|
20
|
+
var i, n;
|
|
21
|
+
const t = e, a = (i = e.localizedNames) == null ? void 0 : i[c], o = (n = e.localizedReplacementNames) == null ? void 0 : n[c];
|
|
22
|
+
return a && (t.name = a), o && (t.replacementName = o), t;
|
|
26
23
|
}
|
|
27
|
-
function f(e,
|
|
24
|
+
function f(e, c) {
|
|
28
25
|
const t = e;
|
|
29
|
-
return t.product =
|
|
26
|
+
return t.product = d(
|
|
30
27
|
e.product,
|
|
31
|
-
|
|
28
|
+
c
|
|
32
29
|
), t;
|
|
33
30
|
}
|
|
34
|
-
function
|
|
35
|
-
const t = e, { product:
|
|
36
|
-
return t.product =
|
|
37
|
-
(l) =>
|
|
38
|
-
)),
|
|
39
|
-
(l) => f(l,
|
|
40
|
-
)),
|
|
41
|
-
(l) =>
|
|
31
|
+
function s(e, c) {
|
|
32
|
+
const t = e, { product: a, modifications: o, addOnProducts: i, subCheckItems: n } = e;
|
|
33
|
+
return t.product = d(a, c), o.length && (t.modifications = o.map(
|
|
34
|
+
(l) => m(l, c)
|
|
35
|
+
)), i != null && i.length && (t.addOnProducts = i.map(
|
|
36
|
+
(l) => f(l, c)
|
|
37
|
+
)), n.length && (t.subCheckItems = n.map(
|
|
38
|
+
(l) => s(l, c)
|
|
42
39
|
)), t;
|
|
43
40
|
}
|
|
44
|
-
function
|
|
45
|
-
|
|
46
|
-
const t = m(a);
|
|
41
|
+
function p(e, c) {
|
|
42
|
+
const t = u(c);
|
|
47
43
|
if (t) {
|
|
48
|
-
const
|
|
49
|
-
return
|
|
50
|
-
(
|
|
51
|
-
),
|
|
44
|
+
const a = e;
|
|
45
|
+
return a.items = e.items.map(
|
|
46
|
+
(o) => s(o, t)
|
|
47
|
+
), a;
|
|
52
48
|
}
|
|
53
49
|
return e;
|
|
54
50
|
}
|
|
55
51
|
export {
|
|
56
|
-
|
|
52
|
+
p as default
|
|
57
53
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ancon/wildcat-utils",
|
|
3
|
-
"version": "1.51.0
|
|
3
|
+
"version": "1.51.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"module": "index.mjs",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -670,6 +670,26 @@
|
|
|
670
670
|
"require": "./logger/types.js",
|
|
671
671
|
"types": "./logger/types.d.ts"
|
|
672
672
|
},
|
|
673
|
+
"./mpsGiftCard/decodeMPSGiftCardQr": {
|
|
674
|
+
"import": "./mpsGiftCard/decodeMPSGiftCardQr.mjs",
|
|
675
|
+
"require": "./mpsGiftCard/decodeMPSGiftCardQr.js",
|
|
676
|
+
"types": "./mpsGiftCard/decodeMPSGiftCardQr.d.ts"
|
|
677
|
+
},
|
|
678
|
+
"./mpsGiftCard": {
|
|
679
|
+
"import": "./mpsGiftCard/index.mjs",
|
|
680
|
+
"require": "./mpsGiftCard/index.js",
|
|
681
|
+
"types": "./mpsGiftCard/index.d.ts"
|
|
682
|
+
},
|
|
683
|
+
"./mpsGiftCard/resolveMPSGiftCardScanAction": {
|
|
684
|
+
"import": "./mpsGiftCard/resolveMPSGiftCardScanAction.mjs",
|
|
685
|
+
"require": "./mpsGiftCard/resolveMPSGiftCardScanAction.js",
|
|
686
|
+
"types": "./mpsGiftCard/resolveMPSGiftCardScanAction.d.ts"
|
|
687
|
+
},
|
|
688
|
+
"./mpsGiftCard/types": {
|
|
689
|
+
"import": "./mpsGiftCard/types.mjs",
|
|
690
|
+
"require": "./mpsGiftCard/types.js",
|
|
691
|
+
"types": "./mpsGiftCard/types.d.ts"
|
|
692
|
+
},
|
|
673
693
|
"./multilingual/createLocalizedCheckDetails": {
|
|
674
694
|
"import": "./multilingual/createLocalizedCheckDetails.mjs",
|
|
675
695
|
"require": "./multilingual/createLocalizedCheckDetails.js",
|