@learncard/helpers 1.6.2 → 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.
@@ -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(() => object, "object"),
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(object2, key, getter) {
1255
+ function defineLazy(object22, key, getter) {
1252
1256
  let value = void 0;
1253
- Object.defineProperty(object2, key, {
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(object2, key, {
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(() => object, "object"),
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 object(shape, params) {
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(object, "object");
14537
- __name2(object, "object");
14540
+ __name(object2, "object");
14541
+ __name2(object2, "object");
14538
14542
  function strictObject(shape, params) {
14539
14543
  return new ZodObject({
14540
14544
  type: "object",
@@ -15884,7 +15888,18 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
15884
15888
  verificationMethod: external_exports.string(),
15885
15889
  jws: external_exports.string().optional()
15886
15890
  }).catchall(external_exports.any()).superRefine((proof, ctx) => {
15887
- if (proof.created === void 0 && (proof.type !== "DataIntegrityProof" || proof.cryptosuite !== "ecdsa-rdfc-2019")) {
15891
+ if (proof.created === void 0 && // These standardized Data Integrity suites make created optional.
15892
+ // Keep the prior requirement for legacy and unknown proof suites.
15893
+ // https://www.w3.org/TR/vc-di-eddsa/#proof-configuration-eddsa-jcs-2022
15894
+ // https://www.w3.org/TR/vc-di-bbs/#proof-configuration
15895
+ (proof.type !== "DataIntegrityProof" || ![
15896
+ "ecdsa-rdfc-2019",
15897
+ "ecdsa-jcs-2019",
15898
+ "ecdsa-sd-2023",
15899
+ "eddsa-rdfc-2022",
15900
+ "eddsa-jcs-2022",
15901
+ "bbs-2023"
15902
+ ].includes(proof.cryptosuite))) {
15888
15903
  ctx.addIssue({
15889
15904
  code: "custom",
15890
15905
  path: ["created"],
@@ -16141,6 +16156,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
16141
16156
  term: external_exports.string().optional()
16142
16157
  }).catchall(external_exports.any());
16143
16158
  var UnsignedAchievementCredentialValidator = UnsignedVCValidator.extend({
16159
+ awardedDate: external_exports.string().optional(),
16144
16160
  name: external_exports.string().optional(),
16145
16161
  description: external_exports.string().optional(),
16146
16162
  image: ImageValidator.optional(),
@@ -18997,6 +19013,17 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
18997
19013
  contentUrl: external_exports.string(),
18998
19014
  receipt: external_exports.string().min(22).max(128).regex(/^[A-Za-z0-9_-]+$/)
18999
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 });
19000
19027
  }
19001
19028
  });
19002
19029
 
@@ -20189,21 +20216,94 @@ var canonicalizeShareContentRequestBody = /* @__PURE__ */ __name((body, options
20189
20216
  return serialized;
20190
20217
  }, "canonicalizeShareContentRequestBody");
20191
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
+
20192
20292
  // src/index.ts
20193
20293
  var isHex = /* @__PURE__ */ __name((str) => /^[0-9a-f]+$/i.test(str), "isHex");
20194
20294
  var isEncrypted = /* @__PURE__ */ __name((item) => {
20195
20295
  return import_types3.JWEValidator.safeParse(item).success;
20196
20296
  }, "isEncrypted");
20197
20297
  var RegExpTransformer = {
20198
- serialize(object) {
20199
- return JSON.stringify(object, (_key, value) => {
20298
+ serialize(object2) {
20299
+ return JSON.stringify(object2, (_key, value) => {
20200
20300
  if (value instanceof RegExp) return value.toString();
20201
20301
  return value;
20202
20302
  });
20203
20303
  },
20204
- deserialize(object) {
20205
- if (typeof object !== "string") return object;
20206
- return JSON.parse(object, (_key, value) => {
20304
+ deserialize(object2) {
20305
+ if (typeof object2 !== "string") return object2;
20306
+ return JSON.parse(object2, (_key, value) => {
20207
20307
  if (typeof value === "string") {
20208
20308
  const match = value.match(/^\/(.*)\/([gimsuy]*)$/);
20209
20309
  if (match) {
@@ -20238,6 +20338,7 @@ var isAppDidWeb = /* @__PURE__ */ __name((did) => {
20238
20338
  }, "isAppDidWeb");
20239
20339
  export {
20240
20340
  AGE_RATING_TO_MIN_AGE,
20341
+ CredentialFieldError,
20241
20342
  DEFAULT_MAX_CANONICAL_BYTES,
20242
20343
  DEFAULT_MAX_CANONICAL_DEPTH,
20243
20344
  DEFAULT_RESOLUTIONS,
@@ -20300,10 +20401,13 @@ export {
20300
20401
  isNotMaybe,
20301
20402
  isNotUndefined,
20302
20403
  isVC2Format,
20404
+ materializeCredentialFields,
20405
+ normalizeCredentialAwardDate,
20303
20406
  optionalEnvironmentBoolean,
20304
20407
  optionalEnvironmentPort,
20305
20408
  optionalEnvironmentString,
20306
20409
  optionalEnvironmentUrl,
20410
+ parseCredentialNumber,
20307
20411
  parseEnvironment,
20308
20412
  prepareManagedRefreshContext,
20309
20413
  projectEnvelopeToDisplayVc,