@nfcard/validation 0.14.0 → 0.16.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/dist/index.d.ts +77 -1
- package/dist/index.js +0 -0
- package/package.json +1 -1
- package/src/index.test.ts +102 -0
- package/src/index.ts +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -5300,6 +5300,34 @@ declare const digitalConfigSchema: z.ZodObject<{
|
|
|
5300
5300
|
label?: string | undefined;
|
|
5301
5301
|
}[] | undefined;
|
|
5302
5302
|
}>;
|
|
5303
|
+
declare const entrySourceSchema: z.ZodObject<{
|
|
5304
|
+
output: z.ZodOptional<z.ZodEnum<["with-card", "digital-only"]>>;
|
|
5305
|
+
entryFlow: z.ZodOptional<z.ZodEnum<["order", "try"]>>;
|
|
5306
|
+
ref: z.ZodOptional<z.ZodString>;
|
|
5307
|
+
path: z.ZodOptional<z.ZodString>;
|
|
5308
|
+
referrer: z.ZodOptional<z.ZodString>;
|
|
5309
|
+
material: z.ZodOptional<z.ZodEnum<["plastic", "3dprint_standard", "metal", "bamboo"]>>;
|
|
5310
|
+
template: z.ZodOptional<z.ZodString>;
|
|
5311
|
+
utm: z.ZodOptional<z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodString>, Record<string, string>, Record<string, string>>>;
|
|
5312
|
+
}, "strict", z.ZodTypeAny, {
|
|
5313
|
+
path?: string | undefined;
|
|
5314
|
+
material?: "plastic" | "3dprint_standard" | "metal" | "bamboo" | undefined;
|
|
5315
|
+
template?: string | undefined;
|
|
5316
|
+
output?: "with-card" | "digital-only" | undefined;
|
|
5317
|
+
entryFlow?: "order" | "try" | undefined;
|
|
5318
|
+
ref?: string | undefined;
|
|
5319
|
+
referrer?: string | undefined;
|
|
5320
|
+
utm?: Record<string, string> | undefined;
|
|
5321
|
+
}, {
|
|
5322
|
+
path?: string | undefined;
|
|
5323
|
+
material?: "plastic" | "3dprint_standard" | "metal" | "bamboo" | undefined;
|
|
5324
|
+
template?: string | undefined;
|
|
5325
|
+
output?: "with-card" | "digital-only" | undefined;
|
|
5326
|
+
entryFlow?: "order" | "try" | undefined;
|
|
5327
|
+
ref?: string | undefined;
|
|
5328
|
+
referrer?: string | undefined;
|
|
5329
|
+
utm?: Record<string, string> | undefined;
|
|
5330
|
+
}>;
|
|
5303
5331
|
declare const configurationCreateSchema: z.ZodObject<{
|
|
5304
5332
|
sessionId: z.ZodString;
|
|
5305
5333
|
userData: z.ZodObject<{
|
|
@@ -8838,6 +8866,34 @@ declare const configurationCreateSchema: z.ZodObject<{
|
|
|
8838
8866
|
quantity: z.ZodDefault<z.ZodNumber>;
|
|
8839
8867
|
existingProfileId: z.ZodOptional<z.ZodString>;
|
|
8840
8868
|
physicalTemplateId: z.ZodOptional<z.ZodString>;
|
|
8869
|
+
entrySource: z.ZodOptional<z.ZodObject<{
|
|
8870
|
+
output: z.ZodOptional<z.ZodEnum<["with-card", "digital-only"]>>;
|
|
8871
|
+
entryFlow: z.ZodOptional<z.ZodEnum<["order", "try"]>>;
|
|
8872
|
+
ref: z.ZodOptional<z.ZodString>;
|
|
8873
|
+
path: z.ZodOptional<z.ZodString>;
|
|
8874
|
+
referrer: z.ZodOptional<z.ZodString>;
|
|
8875
|
+
material: z.ZodOptional<z.ZodEnum<["plastic", "3dprint_standard", "metal", "bamboo"]>>;
|
|
8876
|
+
template: z.ZodOptional<z.ZodString>;
|
|
8877
|
+
utm: z.ZodOptional<z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodString>, Record<string, string>, Record<string, string>>>;
|
|
8878
|
+
}, "strict", z.ZodTypeAny, {
|
|
8879
|
+
path?: string | undefined;
|
|
8880
|
+
material?: "plastic" | "3dprint_standard" | "metal" | "bamboo" | undefined;
|
|
8881
|
+
template?: string | undefined;
|
|
8882
|
+
output?: "with-card" | "digital-only" | undefined;
|
|
8883
|
+
entryFlow?: "order" | "try" | undefined;
|
|
8884
|
+
ref?: string | undefined;
|
|
8885
|
+
referrer?: string | undefined;
|
|
8886
|
+
utm?: Record<string, string> | undefined;
|
|
8887
|
+
}, {
|
|
8888
|
+
path?: string | undefined;
|
|
8889
|
+
material?: "plastic" | "3dprint_standard" | "metal" | "bamboo" | undefined;
|
|
8890
|
+
template?: string | undefined;
|
|
8891
|
+
output?: "with-card" | "digital-only" | undefined;
|
|
8892
|
+
entryFlow?: "order" | "try" | undefined;
|
|
8893
|
+
ref?: string | undefined;
|
|
8894
|
+
referrer?: string | undefined;
|
|
8895
|
+
utm?: Record<string, string> | undefined;
|
|
8896
|
+
}>>;
|
|
8841
8897
|
}, "strip", z.ZodTypeAny, {
|
|
8842
8898
|
sessionId: string;
|
|
8843
8899
|
userData: {
|
|
@@ -9194,6 +9250,16 @@ declare const configurationCreateSchema: z.ZodObject<{
|
|
|
9194
9250
|
quantity: number;
|
|
9195
9251
|
existingProfileId?: string | undefined;
|
|
9196
9252
|
physicalTemplateId?: string | undefined;
|
|
9253
|
+
entrySource?: {
|
|
9254
|
+
path?: string | undefined;
|
|
9255
|
+
material?: "plastic" | "3dprint_standard" | "metal" | "bamboo" | undefined;
|
|
9256
|
+
template?: string | undefined;
|
|
9257
|
+
output?: "with-card" | "digital-only" | undefined;
|
|
9258
|
+
entryFlow?: "order" | "try" | undefined;
|
|
9259
|
+
ref?: string | undefined;
|
|
9260
|
+
referrer?: string | undefined;
|
|
9261
|
+
utm?: Record<string, string> | undefined;
|
|
9262
|
+
} | undefined;
|
|
9197
9263
|
}, {
|
|
9198
9264
|
sessionId: string;
|
|
9199
9265
|
userData: {
|
|
@@ -9550,6 +9616,16 @@ declare const configurationCreateSchema: z.ZodObject<{
|
|
|
9550
9616
|
quantity?: number | undefined;
|
|
9551
9617
|
existingProfileId?: string | undefined;
|
|
9552
9618
|
physicalTemplateId?: string | undefined;
|
|
9619
|
+
entrySource?: {
|
|
9620
|
+
path?: string | undefined;
|
|
9621
|
+
material?: "plastic" | "3dprint_standard" | "metal" | "bamboo" | undefined;
|
|
9622
|
+
template?: string | undefined;
|
|
9623
|
+
output?: "with-card" | "digital-only" | undefined;
|
|
9624
|
+
entryFlow?: "order" | "try" | undefined;
|
|
9625
|
+
ref?: string | undefined;
|
|
9626
|
+
referrer?: string | undefined;
|
|
9627
|
+
utm?: Record<string, string> | undefined;
|
|
9628
|
+
} | undefined;
|
|
9553
9629
|
}>;
|
|
9554
9630
|
declare const configurationUpdateSchema: z.ZodObject<{
|
|
9555
9631
|
userData: z.ZodOptional<z.ZodObject<{
|
|
@@ -19709,4 +19785,4 @@ declare function validatePhysicalConfig(data: unknown): ValidationResult<z.infer
|
|
|
19709
19785
|
declare function validateDigitalConfig(data: unknown): ValidationResult<z.infer<typeof digitalConfigSchema>>;
|
|
19710
19786
|
declare function validateConfiguration(data: unknown): ValidationResult<z.infer<typeof configurationCreateSchema>>;
|
|
19711
19787
|
|
|
19712
|
-
export { CARD_H_MM, CARD_W_MM, CHIP_RADIUS_MM, CHIP_SCALE_FLOOR, type ChipAxis, EDGE_MARGIN_MM, MAX_CTA_BUTTONS, MIN_WALL_MM, NFC_COIL_DIAMETER_MM, NFC_RADIAL_CLEARANCE_MM, type PrintabilityCtx, type Pt, QR_MATRIX_CELLS, QR_MIN_SIZE_MM, QR_MODULE_MIN_MM, TEXT_MIN_EM_MM, type ValidationResult, type Violation, adminCardCreateSchema, cardAssetSchema, cardDesignMaterialSchema, cardDesignPatternSchema, cardDesignSchema, cardElementSchema, cardElementsSchema, cardProfileUpdateSchema, cardUpdateSchema, chipAnchorToMm, comboIdSchema, configurationCreateSchema, configurationUpdateSchema, contactDetailTogglesSchema, contactExchangeSchema, cornersOnCard, createOrderSchema, ctaButtonSchema, ctaButtonsSchema, digitalConfigSchema, digitalVisibilitySchema, elementPrintability, elementTransformSchema, hubConfigSchema, hubProfilesUpdateSchema, isFiniteTransform, materialSchema, mmToNearestChipAnchor, obbCorners, patternFamilySchema, physicalConfigSchema, physicalContentOverridesSchema, profileAccessTokenCreateSchema, profileCreateSchema, profilePinVerifySchema, profileUpdateSchema, profileUserDataSchema, profileVisibilitySchema, sanitizeHttpUrl, sanitizeText, signupWithProfileSchema, socialLinksSchema, socialOverridesSchema, userDataSchema, validateConfiguration, validateDigitalConfig, validatePhysicalConfig, validateUserData, webAddressSchema };
|
|
19788
|
+
export { CARD_H_MM, CARD_W_MM, CHIP_RADIUS_MM, CHIP_SCALE_FLOOR, type ChipAxis, EDGE_MARGIN_MM, MAX_CTA_BUTTONS, MIN_WALL_MM, NFC_COIL_DIAMETER_MM, NFC_RADIAL_CLEARANCE_MM, type PrintabilityCtx, type Pt, QR_MATRIX_CELLS, QR_MIN_SIZE_MM, QR_MODULE_MIN_MM, TEXT_MIN_EM_MM, type ValidationResult, type Violation, adminCardCreateSchema, cardAssetSchema, cardDesignMaterialSchema, cardDesignPatternSchema, cardDesignSchema, cardElementSchema, cardElementsSchema, cardProfileUpdateSchema, cardUpdateSchema, chipAnchorToMm, comboIdSchema, configurationCreateSchema, configurationUpdateSchema, contactDetailTogglesSchema, contactExchangeSchema, cornersOnCard, createOrderSchema, ctaButtonSchema, ctaButtonsSchema, digitalConfigSchema, digitalVisibilitySchema, elementPrintability, elementTransformSchema, entrySourceSchema, hubConfigSchema, hubProfilesUpdateSchema, isFiniteTransform, materialSchema, mmToNearestChipAnchor, obbCorners, patternFamilySchema, physicalConfigSchema, physicalContentOverridesSchema, profileAccessTokenCreateSchema, profileCreateSchema, profilePinVerifySchema, profileUpdateSchema, profileUserDataSchema, profileVisibilitySchema, sanitizeHttpUrl, sanitizeText, signupWithProfileSchema, socialLinksSchema, socialOverridesSchema, userDataSchema, validateConfiguration, validateDigitalConfig, validatePhysicalConfig, validateUserData, webAddressSchema };
|
package/dist/index.js
CHANGED
|
Binary file
|
package/package.json
CHANGED
package/src/index.test.ts
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
cardElementsSchema,
|
|
5
5
|
comboIdSchema,
|
|
6
6
|
configurationCreateSchema,
|
|
7
|
+
configurationUpdateSchema,
|
|
7
8
|
contactExchangeSchema,
|
|
8
9
|
createOrderSchema,
|
|
9
10
|
ctaButtonsSchema,
|
|
@@ -973,3 +974,104 @@ describe('physicalConfig.cardDesign (nested, not stripped)', () => {
|
|
|
973
974
|
expect(physicalConfigSchema.safeParse(validPhysicalConfig).success).toBe(true);
|
|
974
975
|
});
|
|
975
976
|
});
|
|
977
|
+
|
|
978
|
+
// -- entrySourceSchema (NFCARD-392) --------------------------------
|
|
979
|
+
|
|
980
|
+
describe('entrySourceSchema on configurationCreateSchema', () => {
|
|
981
|
+
const base = {
|
|
982
|
+
sessionId: '550e8400-e29b-41d4-a716-446655440000',
|
|
983
|
+
userData: validUserData,
|
|
984
|
+
physicalConfig: validPhysicalConfig,
|
|
985
|
+
digitalConfig: validDigitalConfig,
|
|
986
|
+
};
|
|
987
|
+
|
|
988
|
+
it('accepts a full entry-attribution blob', () => {
|
|
989
|
+
const r = configurationCreateSchema.safeParse({
|
|
990
|
+
...base,
|
|
991
|
+
entrySource: {
|
|
992
|
+
output: 'with-card',
|
|
993
|
+
entryFlow: 'order',
|
|
994
|
+
ref: 'PROMO24',
|
|
995
|
+
path: '/configurator',
|
|
996
|
+
referrer: 'google.com',
|
|
997
|
+
utm: { utm_source: 'ads', utm_campaign: 'launch' },
|
|
998
|
+
},
|
|
999
|
+
});
|
|
1000
|
+
expect(r.success).toBe(true);
|
|
1001
|
+
if (r.success) expect(r.data.entrySource?.output).toBe('with-card');
|
|
1002
|
+
});
|
|
1003
|
+
|
|
1004
|
+
it('is optional — older clients omit it entirely', () => {
|
|
1005
|
+
const r = configurationCreateSchema.safeParse(base);
|
|
1006
|
+
expect(r.success).toBe(true);
|
|
1007
|
+
if (r.success) expect(r.data.entrySource).toBeUndefined();
|
|
1008
|
+
});
|
|
1009
|
+
|
|
1010
|
+
it('rejects unknown keys (strict) and out-of-enum values', () => {
|
|
1011
|
+
expect(
|
|
1012
|
+
configurationCreateSchema.safeParse({
|
|
1013
|
+
...base,
|
|
1014
|
+
entrySource: { output: 'with-card', evil: 'payload' },
|
|
1015
|
+
}).success,
|
|
1016
|
+
).toBe(false);
|
|
1017
|
+
expect(
|
|
1018
|
+
configurationCreateSchema.safeParse({
|
|
1019
|
+
...base,
|
|
1020
|
+
entrySource: { output: 'both-please' },
|
|
1021
|
+
}).success,
|
|
1022
|
+
).toBe(false);
|
|
1023
|
+
});
|
|
1024
|
+
|
|
1025
|
+
it('bounds the utm map (max 10 entries, capped value length)', () => {
|
|
1026
|
+
const utm: Record<string, string> = {};
|
|
1027
|
+
for (let i = 0; i < 11; i++) utm['k' + i] = 'v';
|
|
1028
|
+
expect(
|
|
1029
|
+
configurationCreateSchema.safeParse({ ...base, entrySource: { utm } }).success,
|
|
1030
|
+
).toBe(false);
|
|
1031
|
+
expect(
|
|
1032
|
+
configurationCreateSchema.safeParse({
|
|
1033
|
+
...base,
|
|
1034
|
+
entrySource: { referrer: 'x'.repeat(300) },
|
|
1035
|
+
}).success,
|
|
1036
|
+
).toBe(false);
|
|
1037
|
+
});
|
|
1038
|
+
|
|
1039
|
+
it('is create-only: the update schema strips/ignores it', () => {
|
|
1040
|
+
const r = configurationUpdateSchema.safeParse({
|
|
1041
|
+
entrySource: { output: 'with-card' },
|
|
1042
|
+
});
|
|
1043
|
+
// z.object strips unknown keys by default - the field must not survive.
|
|
1044
|
+
expect(r.success).toBe(true);
|
|
1045
|
+
if (r.success) expect((r.data as Record<string, unknown>).entrySource).toBeUndefined();
|
|
1046
|
+
});
|
|
1047
|
+
});
|
|
1048
|
+
|
|
1049
|
+
describe('entrySourceSchema material/template preselects (NFCARD-393)', () => {
|
|
1050
|
+
const base = {
|
|
1051
|
+
sessionId: '550e8400-e29b-41d4-a716-446655440000',
|
|
1052
|
+
userData: validUserData,
|
|
1053
|
+
physicalConfig: validPhysicalConfig,
|
|
1054
|
+
digitalConfig: validDigitalConfig,
|
|
1055
|
+
};
|
|
1056
|
+
|
|
1057
|
+
it('accepts the deep-link preselects', () => {
|
|
1058
|
+
const r = configurationCreateSchema.safeParse({
|
|
1059
|
+
...base,
|
|
1060
|
+
entrySource: { output: 'with-card', material: '3dprint_standard', template: 'tpl-pvc-white' },
|
|
1061
|
+
});
|
|
1062
|
+
expect(r.success).toBe(true);
|
|
1063
|
+
if (r.success) {
|
|
1064
|
+
expect(r.data.entrySource?.material).toBe('3dprint_standard');
|
|
1065
|
+
expect(r.data.entrySource?.template).toBe('tpl-pvc-white');
|
|
1066
|
+
}
|
|
1067
|
+
});
|
|
1068
|
+
|
|
1069
|
+
it('rejects a non-enum material', () => {
|
|
1070
|
+
expect(
|
|
1071
|
+
configurationCreateSchema.safeParse({
|
|
1072
|
+
...base,
|
|
1073
|
+
entrySource: { material: 'carbon-fiber' },
|
|
1074
|
+
}).success,
|
|
1075
|
+
).toBe(false);
|
|
1076
|
+
});
|
|
1077
|
+
});
|
package/src/index.ts
CHANGED
|
Binary file
|