@learncard/helpers 1.6.3 → 1.7.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/credential-materialization.d.ts +14 -0
- package/dist/credential-materialization.d.ts.map +1 -0
- package/dist/credential-materialization.test.d.ts +2 -0
- package/dist/credential-materialization.test.d.ts.map +1 -0
- package/dist/helpers.cjs.development.cjs +1285 -1184
- package/dist/helpers.cjs.development.cjs.map +4 -4
- package/dist/helpers.cjs.production.min.cjs +13 -13
- package/dist/helpers.cjs.production.min.cjs.map +4 -4
- package/dist/helpers.esm.js +106 -13
- package/dist/helpers.esm.js.map +4 -4
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/credential-materialization.test.ts +91 -0
- package/src/credential-materialization.ts +101 -0
- package/src/index.ts +2 -0
package/dist/helpers.esm.js
CHANGED
|
@@ -203,6 +203,7 @@ var require_types_cjs_development = __commonJS({
|
|
|
203
203
|
FlatAuthGrantValidator: /* @__PURE__ */ __name(() => FlatAuthGrantValidator, "FlatAuthGrantValidator"),
|
|
204
204
|
FrameworkWithSkillsValidator: /* @__PURE__ */ __name(() => FrameworkWithSkillsValidator, "FrameworkWithSkillsValidator"),
|
|
205
205
|
FullClaimHookValidator: /* @__PURE__ */ __name(() => FullClaimHookValidator, "FullClaimHookValidator"),
|
|
206
|
+
GenerateSkillIconsInputValidator: /* @__PURE__ */ __name(() => GenerateSkillIconsInputValidator, "GenerateSkillIconsInputValidator"),
|
|
206
207
|
GeoCoordinatesValidator: /* @__PURE__ */ __name(() => GeoCoordinatesValidator, "GeoCoordinatesValidator"),
|
|
207
208
|
GetCounterEventValidator: /* @__PURE__ */ __name(() => GetCounterEventValidator, "GetCounterEventValidator"),
|
|
208
209
|
GetCountersEventValidator: /* @__PURE__ */ __name(() => GetCountersEventValidator, "GetCountersEventValidator"),
|
|
@@ -363,6 +364,8 @@ var require_types_cjs_development = __commonJS({
|
|
|
363
364
|
SHARE_RECOVERY_PROTOCOL: /* @__PURE__ */ __name(() => SHARE_RECOVERY_PROTOCOL, "SHARE_RECOVERY_PROTOCOL"),
|
|
364
365
|
SHARE_TAG_BYTES: /* @__PURE__ */ __name(() => SHARE_TAG_BYTES, "SHARE_TAG_BYTES"),
|
|
365
366
|
SHARE_VIEW_RECEIPT_TTL_SECONDS: /* @__PURE__ */ __name(() => SHARE_VIEW_RECEIPT_TTL_SECONDS, "SHARE_VIEW_RECEIPT_TTL_SECONDS"),
|
|
367
|
+
SKILL_ICON_MAX_CHARACTERS_PER_REQUEST: /* @__PURE__ */ __name(() => SKILL_ICON_MAX_CHARACTERS_PER_REQUEST, "SKILL_ICON_MAX_CHARACTERS_PER_REQUEST"),
|
|
368
|
+
SKILL_ICON_MAX_NAMES_PER_REQUEST: /* @__PURE__ */ __name(() => SKILL_ICON_MAX_NAMES_PER_REQUEST, "SKILL_ICON_MAX_NAMES_PER_REQUEST"),
|
|
366
369
|
SendAiSessionCredentialEventValidator: /* @__PURE__ */ __name(() => SendAiSessionCredentialEventValidator, "SendAiSessionCredentialEventValidator"),
|
|
367
370
|
SendBoostInputValidator: /* @__PURE__ */ __name(() => SendBoostInputValidator, "SendBoostInputValidator"),
|
|
368
371
|
SendBoostResponseValidator: /* @__PURE__ */ __name(() => SendBoostResponseValidator, "SendBoostResponseValidator"),
|
|
@@ -415,6 +418,7 @@ var require_types_cjs_development = __commonJS({
|
|
|
415
418
|
SkillFrameworkQueryValidator: /* @__PURE__ */ __name(() => SkillFrameworkQueryValidator, "SkillFrameworkQueryValidator"),
|
|
416
419
|
SkillFrameworkStatusEnum: /* @__PURE__ */ __name(() => SkillFrameworkStatusEnum, "SkillFrameworkStatusEnum"),
|
|
417
420
|
SkillFrameworkValidator: /* @__PURE__ */ __name(() => SkillFrameworkValidator, "SkillFrameworkValidator"),
|
|
421
|
+
SkillIconNamesValidator: /* @__PURE__ */ __name(() => SkillIconNamesValidator, "SkillIconNamesValidator"),
|
|
418
422
|
SkillQueryValidator: /* @__PURE__ */ __name(() => SkillQueryValidator, "SkillQueryValidator"),
|
|
419
423
|
SkillSemanticSearchInputValidator: /* @__PURE__ */ __name(() => SkillSemanticSearchInputValidator, "SkillSemanticSearchInputValidator"),
|
|
420
424
|
SkillSemanticSearchResultItemValidator: /* @__PURE__ */ __name(() => SkillSemanticSearchResultItemValidator, "SkillSemanticSearchResultItemValidator"),
|
|
@@ -662,7 +666,7 @@ var require_types_cjs_development = __commonJS({
|
|
|
662
666
|
nullable: /* @__PURE__ */ __name(() => nullable, "nullable"),
|
|
663
667
|
nullish: /* @__PURE__ */ __name(() => nullish2, "nullish"),
|
|
664
668
|
number: /* @__PURE__ */ __name(() => number2, "number"),
|
|
665
|
-
object: /* @__PURE__ */ __name(() =>
|
|
669
|
+
object: /* @__PURE__ */ __name(() => object2, "object"),
|
|
666
670
|
optional: /* @__PURE__ */ __name(() => optional, "optional"),
|
|
667
671
|
overwrite: /* @__PURE__ */ __name(() => _overwrite, "overwrite"),
|
|
668
672
|
parse: /* @__PURE__ */ __name(() => parse2, "parse"),
|
|
@@ -1248,9 +1252,9 @@ var require_types_cjs_development = __commonJS({
|
|
|
1248
1252
|
__name(floatSafeRemainder, "floatSafeRemainder");
|
|
1249
1253
|
__name2(floatSafeRemainder, "floatSafeRemainder");
|
|
1250
1254
|
var EVALUATING = /* @__PURE__ */ Symbol("evaluating");
|
|
1251
|
-
function defineLazy(
|
|
1255
|
+
function defineLazy(object22, key, getter) {
|
|
1252
1256
|
let value = void 0;
|
|
1253
|
-
Object.defineProperty(
|
|
1257
|
+
Object.defineProperty(object22, key, {
|
|
1254
1258
|
get() {
|
|
1255
1259
|
if (value === EVALUATING) {
|
|
1256
1260
|
return void 0;
|
|
@@ -1262,7 +1266,7 @@ var require_types_cjs_development = __commonJS({
|
|
|
1262
1266
|
return value;
|
|
1263
1267
|
},
|
|
1264
1268
|
set(v) {
|
|
1265
|
-
Object.defineProperty(
|
|
1269
|
+
Object.defineProperty(object22, key, {
|
|
1266
1270
|
value: v
|
|
1267
1271
|
// configurable: true,
|
|
1268
1272
|
});
|
|
@@ -13552,7 +13556,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
13552
13556
|
nullable: /* @__PURE__ */ __name(() => nullable, "nullable"),
|
|
13553
13557
|
nullish: /* @__PURE__ */ __name(() => nullish2, "nullish"),
|
|
13554
13558
|
number: /* @__PURE__ */ __name(() => number2, "number"),
|
|
13555
|
-
object: /* @__PURE__ */ __name(() =>
|
|
13559
|
+
object: /* @__PURE__ */ __name(() => object2, "object"),
|
|
13556
13560
|
optional: /* @__PURE__ */ __name(() => optional, "optional"),
|
|
13557
13561
|
partialRecord: /* @__PURE__ */ __name(() => partialRecord, "partialRecord"),
|
|
13558
13562
|
pipe: /* @__PURE__ */ __name(() => pipe, "pipe"),
|
|
@@ -14525,7 +14529,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
14525
14529
|
}
|
|
14526
14530
|
});
|
|
14527
14531
|
});
|
|
14528
|
-
function
|
|
14532
|
+
function object2(shape, params) {
|
|
14529
14533
|
const def = {
|
|
14530
14534
|
type: "object",
|
|
14531
14535
|
shape: shape ?? {},
|
|
@@ -14533,8 +14537,8 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
14533
14537
|
};
|
|
14534
14538
|
return new ZodObject(def);
|
|
14535
14539
|
}
|
|
14536
|
-
__name(
|
|
14537
|
-
__name2(
|
|
14540
|
+
__name(object2, "object");
|
|
14541
|
+
__name2(object2, "object");
|
|
14538
14542
|
function strictObject(shape, params) {
|
|
14539
14543
|
return new ZodObject({
|
|
14540
14544
|
type: "object",
|
|
@@ -16152,6 +16156,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
16152
16156
|
term: external_exports.string().optional()
|
|
16153
16157
|
}).catchall(external_exports.any());
|
|
16154
16158
|
var UnsignedAchievementCredentialValidator = UnsignedVCValidator.extend({
|
|
16159
|
+
awardedDate: external_exports.string().optional(),
|
|
16155
16160
|
name: external_exports.string().optional(),
|
|
16156
16161
|
description: external_exports.string().optional(),
|
|
16157
16162
|
image: ImageValidator.optional(),
|
|
@@ -19008,6 +19013,17 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
19008
19013
|
contentUrl: external_exports.string(),
|
|
19009
19014
|
receipt: external_exports.string().min(22).max(128).regex(/^[A-Za-z0-9_-]+$/)
|
|
19010
19015
|
}).strict();
|
|
19016
|
+
var SKILL_ICON_MAX_NAMES_PER_REQUEST = 100;
|
|
19017
|
+
var SKILL_ICON_MAX_CHARACTERS_PER_REQUEST = 2500;
|
|
19018
|
+
var SkillIconNamesValidator = external_exports.array(external_exports.string().nonempty()).min(1).max(SKILL_ICON_MAX_NAMES_PER_REQUEST, {
|
|
19019
|
+
message: `A maximum of ${SKILL_ICON_MAX_NAMES_PER_REQUEST} skill names can be sent per request`
|
|
19020
|
+
}).refine(
|
|
19021
|
+
(names) => names.reduce((total, name) => total + name.length, 0) <= SKILL_ICON_MAX_CHARACTERS_PER_REQUEST,
|
|
19022
|
+
{
|
|
19023
|
+
message: `Skill names may total at most ${SKILL_ICON_MAX_CHARACTERS_PER_REQUEST} characters per request`
|
|
19024
|
+
}
|
|
19025
|
+
);
|
|
19026
|
+
var GenerateSkillIconsInputValidator = external_exports.object({ names: SkillIconNamesValidator });
|
|
19011
19027
|
}
|
|
19012
19028
|
});
|
|
19013
19029
|
|
|
@@ -20200,21 +20216,94 @@ var canonicalizeShareContentRequestBody = /* @__PURE__ */ __name((body, options
|
|
|
20200
20216
|
return serialized;
|
|
20201
20217
|
}, "canonicalizeShareContentRequestBody");
|
|
20202
20218
|
|
|
20219
|
+
// src/credential-materialization.ts
|
|
20220
|
+
var CredentialFieldError = class extends Error {
|
|
20221
|
+
constructor(field) {
|
|
20222
|
+
super(`Invalid standard credential field: ${field}`);
|
|
20223
|
+
this.field = field;
|
|
20224
|
+
this.name = "CredentialFieldError";
|
|
20225
|
+
}
|
|
20226
|
+
static {
|
|
20227
|
+
__name(this, "CredentialFieldError");
|
|
20228
|
+
}
|
|
20229
|
+
};
|
|
20230
|
+
var parseCredentialNumber = /* @__PURE__ */ __name((value) => {
|
|
20231
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
20232
|
+
if (typeof value !== "string" || !/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i.test(value.trim()))
|
|
20233
|
+
throw new Error("Expected a finite decimal");
|
|
20234
|
+
const number = Number(value.trim());
|
|
20235
|
+
if (!Number.isFinite(number)) throw new Error("Expected a finite decimal");
|
|
20236
|
+
return number;
|
|
20237
|
+
}, "parseCredentialNumber");
|
|
20238
|
+
var normalizeCredentialAwardDate = /* @__PURE__ */ __name((value) => {
|
|
20239
|
+
const text = value.trim();
|
|
20240
|
+
const calendar = /^(\d{4})-(\d{2})-(\d{2})/.exec(text);
|
|
20241
|
+
if (!calendar || !/^\d{4}-\d{2}-\d{2}(?:T(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2}))?$/i.test(
|
|
20242
|
+
text
|
|
20243
|
+
))
|
|
20244
|
+
throw new CredentialFieldError("awardedDate");
|
|
20245
|
+
const day = /* @__PURE__ */ new Date(`${calendar[0]}T00:00:00Z`);
|
|
20246
|
+
if (!Number.isFinite(day.getTime()) || day.getUTCFullYear() !== Number(calendar[1]) || day.getUTCMonth() + 1 !== Number(calendar[2]) || day.getUTCDate() !== Number(calendar[3]))
|
|
20247
|
+
throw new CredentialFieldError("awardedDate");
|
|
20248
|
+
const instant = text.length === 10 ? day : new Date(text);
|
|
20249
|
+
if (!Number.isFinite(instant.getTime())) throw new CredentialFieldError("awardedDate");
|
|
20250
|
+
const fraction = /\.(\d+)(?:Z|[+-]\d{2}:\d{2})$/i.exec(text)?.[1];
|
|
20251
|
+
const iso = instant.toISOString();
|
|
20252
|
+
return fraction && fraction.length > 3 ? iso.replace(/\.\d{3}Z$/, `.${fraction}Z`) : iso;
|
|
20253
|
+
}, "normalizeCredentialAwardDate");
|
|
20254
|
+
var object = /* @__PURE__ */ __name((value) => Boolean(value && typeof value === "object" && !Array.isArray(value)), "object");
|
|
20255
|
+
var materializeCredentialFields = /* @__PURE__ */ __name((credential) => {
|
|
20256
|
+
if (credential.proof) return credential;
|
|
20257
|
+
const types = Array.isArray(credential.type) ? credential.type : [credential.type];
|
|
20258
|
+
if (!types.some(
|
|
20259
|
+
(type) => ["OpenBadgeCredential", "AchievementCredential", "ClrCredential"].includes(String(type))
|
|
20260
|
+
))
|
|
20261
|
+
return credential;
|
|
20262
|
+
const result = structuredClone(credential);
|
|
20263
|
+
const numeric = /* @__PURE__ */ __name((container, field) => {
|
|
20264
|
+
if (container[field] === void 0) return;
|
|
20265
|
+
if (typeof container[field] === "string" && !container[field].trim()) {
|
|
20266
|
+
delete container[field];
|
|
20267
|
+
return;
|
|
20268
|
+
}
|
|
20269
|
+
try {
|
|
20270
|
+
container[field] = parseCredentialNumber(container[field]);
|
|
20271
|
+
} catch {
|
|
20272
|
+
throw new CredentialFieldError(field);
|
|
20273
|
+
}
|
|
20274
|
+
}, "numeric");
|
|
20275
|
+
const subject = /* @__PURE__ */ __name((value) => {
|
|
20276
|
+
if (!object(value)) return;
|
|
20277
|
+
numeric(value, "creditsEarned");
|
|
20278
|
+
for (const achievement of Array.isArray(value.achievement) ? value.achievement : [value.achievement]) {
|
|
20279
|
+
if (object(achievement)) numeric(achievement, "creditsAvailable");
|
|
20280
|
+
}
|
|
20281
|
+
}, "subject");
|
|
20282
|
+
for (const value of Array.isArray(result.credentialSubject) ? result.credentialSubject : [result.credentialSubject])
|
|
20283
|
+
subject(value);
|
|
20284
|
+
if (result.awardedDate !== void 0) {
|
|
20285
|
+
if (typeof result.awardedDate !== "string") throw new CredentialFieldError("awardedDate");
|
|
20286
|
+
if (!result.awardedDate.trim()) delete result.awardedDate;
|
|
20287
|
+
else result.awardedDate = normalizeCredentialAwardDate(result.awardedDate);
|
|
20288
|
+
}
|
|
20289
|
+
return result;
|
|
20290
|
+
}, "materializeCredentialFields");
|
|
20291
|
+
|
|
20203
20292
|
// src/index.ts
|
|
20204
20293
|
var isHex = /* @__PURE__ */ __name((str) => /^[0-9a-f]+$/i.test(str), "isHex");
|
|
20205
20294
|
var isEncrypted = /* @__PURE__ */ __name((item) => {
|
|
20206
20295
|
return import_types3.JWEValidator.safeParse(item).success;
|
|
20207
20296
|
}, "isEncrypted");
|
|
20208
20297
|
var RegExpTransformer = {
|
|
20209
|
-
serialize(
|
|
20210
|
-
return JSON.stringify(
|
|
20298
|
+
serialize(object2) {
|
|
20299
|
+
return JSON.stringify(object2, (_key, value) => {
|
|
20211
20300
|
if (value instanceof RegExp) return value.toString();
|
|
20212
20301
|
return value;
|
|
20213
20302
|
});
|
|
20214
20303
|
},
|
|
20215
|
-
deserialize(
|
|
20216
|
-
if (typeof
|
|
20217
|
-
return JSON.parse(
|
|
20304
|
+
deserialize(object2) {
|
|
20305
|
+
if (typeof object2 !== "string") return object2;
|
|
20306
|
+
return JSON.parse(object2, (_key, value) => {
|
|
20218
20307
|
if (typeof value === "string") {
|
|
20219
20308
|
const match = value.match(/^\/(.*)\/([gimsuy]*)$/);
|
|
20220
20309
|
if (match) {
|
|
@@ -20249,6 +20338,7 @@ var isAppDidWeb = /* @__PURE__ */ __name((did) => {
|
|
|
20249
20338
|
}, "isAppDidWeb");
|
|
20250
20339
|
export {
|
|
20251
20340
|
AGE_RATING_TO_MIN_AGE,
|
|
20341
|
+
CredentialFieldError,
|
|
20252
20342
|
DEFAULT_MAX_CANONICAL_BYTES,
|
|
20253
20343
|
DEFAULT_MAX_CANONICAL_DEPTH,
|
|
20254
20344
|
DEFAULT_RESOLUTIONS,
|
|
@@ -20311,10 +20401,13 @@ export {
|
|
|
20311
20401
|
isNotMaybe,
|
|
20312
20402
|
isNotUndefined,
|
|
20313
20403
|
isVC2Format,
|
|
20404
|
+
materializeCredentialFields,
|
|
20405
|
+
normalizeCredentialAwardDate,
|
|
20314
20406
|
optionalEnvironmentBoolean,
|
|
20315
20407
|
optionalEnvironmentPort,
|
|
20316
20408
|
optionalEnvironmentString,
|
|
20317
20409
|
optionalEnvironmentUrl,
|
|
20410
|
+
parseCredentialNumber,
|
|
20318
20411
|
parseEnvironment,
|
|
20319
20412
|
prepareManagedRefreshContext,
|
|
20320
20413
|
projectEnvelopeToDisplayVc,
|