@pushwoosh/dumb-components 1.1.215 → 1.1.216
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/helpers/__tests__/barcodeUrl.test.d.ts +1 -0
- package/helpers/__tests__/barcodeUrl.test.js +43 -0
- package/helpers/barcodeUrl.d.ts +29 -0
- package/helpers/barcodeUrl.js +31 -0
- package/helpers/index.d.ts +1 -0
- package/helpers/index.js +2 -1
- package/index.d.ts +1 -0
- package/index.js +2 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { buildBarcodeUrl, barcodePlaceholderSafeEscape, isBarcodePlaceholder } from '../barcodeUrl';
|
|
2
|
+
const BASE = 'https://rag-mcp.svc-nue.pushwoosh.com';
|
|
3
|
+
describe('buildBarcodeUrl', () => {
|
|
4
|
+
it('omits every empty parameter', () => {
|
|
5
|
+
expect(buildBarcodeUrl({
|
|
6
|
+
value: '1234567890123456'
|
|
7
|
+
}, `${BASE}/`)).toBe(`${BASE}/barcode/v1/code.png?sym=code128&v=1234567890123456`);
|
|
8
|
+
});
|
|
9
|
+
// A percent-encoded brace never matches the substituter, on the server or on
|
|
10
|
+
// the device, so the barcode would encode the placeholder text itself.
|
|
11
|
+
it.each(['{{voucher}}', '{Coupon|String|}', 'BR-{{voucher}}'])('keeps the placeholder %s literal', value => {
|
|
12
|
+
expect(buildBarcodeUrl({
|
|
13
|
+
value
|
|
14
|
+
}, BASE).endsWith(`&v=${value}`)).toBe(true);
|
|
15
|
+
});
|
|
16
|
+
it('escapes what is not a placeholder', () => {
|
|
17
|
+
expect(barcodePlaceholderSafeEscape('a b&c={{v}}')).toBe('a+b%26c%3D{{v}}');
|
|
18
|
+
});
|
|
19
|
+
it('carries every set parameter', () => {
|
|
20
|
+
const url = buildBarcodeUrl({
|
|
21
|
+
value: '{Coupon|String|}',
|
|
22
|
+
symbology: 'qr',
|
|
23
|
+
showText: true,
|
|
24
|
+
width: 420,
|
|
25
|
+
height: 460,
|
|
26
|
+
quietModules: 6,
|
|
27
|
+
foregroundColor: '#101010',
|
|
28
|
+
backgroundColor: '#ffffff',
|
|
29
|
+
ecLevel: 'H'
|
|
30
|
+
}, BASE);
|
|
31
|
+
['sym=qr', 'hri=1', 'w=420', 'h=460', 'q=6', 'fg=101010', 'bg=ffffff', 'ec=H'].forEach(part => expect(url).toContain(part));
|
|
32
|
+
});
|
|
33
|
+
it('drops the error-correction level outside QR', () => {
|
|
34
|
+
expect(buildBarcodeUrl({
|
|
35
|
+
value: '1',
|
|
36
|
+
ecLevel: 'H'
|
|
37
|
+
}, BASE)).not.toContain('ec=');
|
|
38
|
+
});
|
|
39
|
+
it('recognizes a value that still needs substituting', () => {
|
|
40
|
+
expect(isBarcodePlaceholder('{Coupon|String|}')).toBe(true);
|
|
41
|
+
expect(isBarcodePlaceholder('4012345678901')).toBe(false);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export type BarcodeSymbology = 'code128' | 'ean13' | 'ean8' | 'upca' | 'qr';
|
|
2
|
+
export interface BarcodeUrlParams {
|
|
3
|
+
/** What to encode; normally a placeholder resolved per recipient. */
|
|
4
|
+
value: string;
|
|
5
|
+
symbology?: BarcodeSymbology;
|
|
6
|
+
/** Print the value in digits under the code. */
|
|
7
|
+
showText?: boolean;
|
|
8
|
+
width?: number;
|
|
9
|
+
height?: number;
|
|
10
|
+
/** Hex `#rrggbb`; empty = black on white. */
|
|
11
|
+
foregroundColor?: string;
|
|
12
|
+
backgroundColor?: string;
|
|
13
|
+
/** QR only: L, M, Q or H. */
|
|
14
|
+
ecLevel?: string;
|
|
15
|
+
/** Blank margin per side in modules; 0 = renderer default. */
|
|
16
|
+
quietModules?: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Encodes the value but leaves `{`, `}` and `|` literal: a percent-encoded
|
|
20
|
+
* placeholder never matches the substituter, on the server or on the device.
|
|
21
|
+
*/
|
|
22
|
+
export declare function barcodePlaceholderSafeEscape(value: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* Builds a URL for the onyx barcode-PNG endpoint, shared by every editor. The
|
|
25
|
+
* value is appended after the encoded query so a `{tag|type|}` stays literal.
|
|
26
|
+
*/
|
|
27
|
+
export declare function buildBarcodeUrl(params: BarcodeUrlParams, baseUrl: string): string;
|
|
28
|
+
/** A value that has to be resolved before the endpoint can encode it. */
|
|
29
|
+
export declare function isBarcodePlaceholder(value: string): boolean;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encodes the value but leaves `{`, `}` and `|` literal: a percent-encoded
|
|
3
|
+
* placeholder never matches the substituter, on the server or on the device.
|
|
4
|
+
*/
|
|
5
|
+
export function barcodePlaceholderSafeEscape(value) {
|
|
6
|
+
const escaped = new URLSearchParams({
|
|
7
|
+
v: value
|
|
8
|
+
}).toString().slice('v='.length);
|
|
9
|
+
return escaped.replace(/%7B/gi, '{').replace(/%7D/gi, '}').replace(/%7C/gi, '|');
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Builds a URL for the onyx barcode-PNG endpoint, shared by every editor. The
|
|
13
|
+
* value is appended after the encoded query so a `{tag|type|}` stays literal.
|
|
14
|
+
*/
|
|
15
|
+
export function buildBarcodeUrl(params, baseUrl) {
|
|
16
|
+
const q = new URLSearchParams();
|
|
17
|
+
q.set('sym', params.symbology ?? 'code128');
|
|
18
|
+
if (params.showText) q.set('hri', '1');
|
|
19
|
+
const hex = v => v.replace(/^#/, '');
|
|
20
|
+
if (params.foregroundColor) q.set('fg', hex(params.foregroundColor));
|
|
21
|
+
if (params.backgroundColor) q.set('bg', hex(params.backgroundColor));
|
|
22
|
+
if (params.width) q.set('w', String(params.width));
|
|
23
|
+
if (params.height) q.set('h', String(params.height));
|
|
24
|
+
if (params.quietModules) q.set('q', String(params.quietModules));
|
|
25
|
+
if (params.ecLevel && (params.symbology ?? 'code128') === 'qr') q.set('ec', params.ecLevel);
|
|
26
|
+
return `${baseUrl.replace(/\/$/, '')}/barcode/v1/code.png?${q.toString()}&v=${barcodePlaceholderSafeEscape(params.value)}`;
|
|
27
|
+
}
|
|
28
|
+
/** A value that has to be resolved before the endpoint can encode it. */
|
|
29
|
+
export function isBarcodePlaceholder(value) {
|
|
30
|
+
return value.includes('{');
|
|
31
|
+
}
|
package/helpers/index.d.ts
CHANGED
package/helpers/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from './assignRef';
|
|
1
|
+
export * from './assignRef';
|
|
2
|
+
export * from './barcodeUrl';
|
package/index.d.ts
CHANGED
|
@@ -57,3 +57,4 @@ export { Alert } from './Alert';
|
|
|
57
57
|
export { ApplicationPreloader, type ApplicationPreloaderProps, } from './ApplicationPreloader';
|
|
58
58
|
export { NotificationInbox, NotificationBar, NotificationBell, type Notification, type NotificationInboxProps, type NotificationSeverity, type NotificationBarType, type NotificationBarProps, type NotificationBellProps, } from './NotificationInbox';
|
|
59
59
|
export { LeafletTheme } from './LeafletTheme';
|
|
60
|
+
export { buildBarcodeUrl, barcodePlaceholderSafeEscape, isBarcodePlaceholder, type BarcodeSymbology, type BarcodeUrlParams, } from './helpers/barcodeUrl';
|
package/index.js
CHANGED
|
@@ -54,4 +54,5 @@ export { SendRateEdit, SendRateReadonly } from './SendRate';
|
|
|
54
54
|
export { Alert } from './Alert';
|
|
55
55
|
export { ApplicationPreloader } from './ApplicationPreloader';
|
|
56
56
|
export { NotificationInbox, NotificationBar, NotificationBell } from './NotificationInbox';
|
|
57
|
-
export { LeafletTheme } from './LeafletTheme';
|
|
57
|
+
export { LeafletTheme } from './LeafletTheme';
|
|
58
|
+
export { buildBarcodeUrl, barcodePlaceholderSafeEscape, isBarcodePlaceholder } from './helpers/barcodeUrl';
|