Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/rare-forks-occur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@learncard/types": patch
"@learncard/vc-templates-plugin": patch
---

feat: LC-1310 - Add Evidence Support
252 changes: 252 additions & 0 deletions packages/learn-card-contexts/boosts/1.0.3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
{
"@context": {
"id": "@id",
"type": "@type",
"lcn": "https://docs.learncard.com/definitions#",
"cred": "https://www.w3.org/2018/credentials#",
"xsd": "https://www.w3.org/2001/XMLSchema#",
"EvidenceFile": {
"@id": "https://docs.learncard.com/definitions#EvidenceFile",
"@context": {
"fileName": {
"@id": "https://docs.learncard.com/definitions#evidenceFileName",
"@type": "xsd:string"
},
"fileType": {
"@id": "https://docs.learncard.com/definitions#evidenceFileType",
"@type": "xsd:string"
},
"fileSize": {
"@id": "https://docs.learncard.com/definitions#evidenceFileSize",
"@type": "xsd:string"
}
}
},
"BoostCredential": {
"@context": {
"address": {
"@id": "https://purl.imsglobal.org/spec/vc/ob/vocab.html#Address"
},
"attachments": {
"@container": "@set",
"@context": {
"title": {
"@id": "lcn:boostAttachmentTitle",
"@type": "xsd:string"
},
"type": {
"@id": "lcn:boostAttachmentType",
"@type": "xsd:string"
},
"url": {
"@id": "lcn:boostAttachmentUrl",
"@type": "xsd:string"
},
"fileName": {
"@id": "lcn:boostAttachmentFileName",
"@type": "xsd:string"
},
"fileSize": {
"@id": "lcn:boostAttachmentFileSize",
"@type": "xsd:string"
},
"fileType": {
"@id": "lcn:boostAttachmentFileType",
"@type": "xsd:string"
}
},
"@id": "lcn:boostAttachments"
},
"boostId": {
"@id": "lcn:boostId",
"@type": "xsd:string"
},
"display": {
"@context": {
"backgroundColor": {
"@id": "lcn:boostBackgroundColor",
"@type": "xsd:string"
},
"backgroundImage": {
"@id": "lcn:boostBackgroundImage",
"@type": "xsd:string"
},
"displayType": {
"@id": "lcn:boostDisplayType",
"@type": "xsd:string"
},
"previewType": {
"@id": "lcn:boostPreviewType",
"@type": "xsd:string"
},
"emoji": {
"@context": {
"activeSkinTone": {
"@id": "lcn:boostEmojiActiveSkinTone",
"@type": "xsd:string"
},
"imageUrl": {
"@id": "lcn:boostEmojiImageUrl",
"@type": "xsd:string"
},
"names": {
"@container": "@set",
"@id": "lcn:boostEmojiNames",
"@type": "xsd:string"
},
"unified": {
"@id": "lcn:boostEmojiUnified",
"@type": "xsd:string"
},
"unifiedWithoutSkinTone": {
"@id": "lcn:boostEmojiUnifiedWithoutSkinTone",
"@type": "xsd:string"
}
},
"@id": "lcn:boostEmoji"
},
"fadeBackgroundImage": {
"@id": "lcn:boostFadeBackgroundImage",
"@type": "xsd:boolean"
},
"repeatBackgroundImage": {
"@id": "lcn:boostRepeatBackgroundImage",
"@type": "xsd:boolean"
}
},
"@id": "lcn:boostDisplay"
},
"familyTitles": {
"@context": {
"dependents": {
"@container": "@set",
"@context": {
"plural": {
"@id": "lcn:plural",
"@type": "xsd:string"
},
"singular": {
"@id": "lcn:singular",
"@type": "xsd:string"
}
},
"@id": "lcn:dependents"
},
"guardians": {
"@container": "@set",
"@context": {
"plural": {
"@id": "lcn:plural",
"@type": "xsd:string"
},
"singular": {
"@id": "lcn:singular",
"@type": "xsd:string"
}
},
"@id": "lcn:guardians"
}
},
"@id": "lcn:familyTitles"
},
"groupID": {
"@id": "lcn:groupID",
"@type": "xsd:string"
},
"skills": {
"@container": "@set",
"@context": {
"category": {
"@id": "lcn:boostSkillCategory",
"@type": "xsd:string"
},
"skill": {
"@id": "lcn:boostSkill",
"@type": "xsd:string"
},
"subskills": {
"@container": "@set",
"@id": "lcn:boostSubskills",
"@type": "xsd:string"
}
},
"@id": "lcn:boostSkills"
}
},
"@id": "lcn:boostCredential"
},
"BoostID": {
"@id": "lcn:boostID",
"@context": {
"boostID": {
"@id": "lcn:boostIDField",
"@context": {
"fontColor": {
"@id": "lcn:boostIDFontColor",
"@type": "xsd:string"
},
"accentColor": {
"@id": "lcn:boostIDAccentColor",
"@type": "xsd:string"
},
"backgroundImage": {
"@id": "lcn:boostIDBackgroundImage",
"@type": "xsd:string"
},
"dimBackgroundImage": {
"@id": "lcn:boostIDDimBackgroundImage",
"@type": "xsd:boolean"
},
"issuerThumbnail": {
"@id": "lcn:boostIDIssuerThumbnail",
"@type": "xsd:string"
},
"showIssuerThumbnail": {
"@id": "lcn:boostIDShowIssuerThumbnail",
"@type": "xsd:boolean"
},
"IDIssuerName": {
"@id": "lcn:boostIDIssuerName",
"@type": "xsd:string"
},
"idThumbnail": {
"@id": "lcn:boostIDThumbnail",
"@type": "xsd:string"
},
"accentFontColor": {
"@id": "lcn:boostIDFontColor",
"@type": "xsd:string"
},
"idBackgroundColor": {
"@id": "lcn:boostIDBackgroundColor",
"@type": "xsd:string"
},
"repeatIdBackgroundImage": {
"@id": "lcn:boostIDRepeatIdBackgroundImage",
"@type": "xsd:boolean"
},
"idDescription": {
"@id": "lcn:boostIDDescription",
"@type": "xsd:string"
}
}
}
}
},
"CertifiedBoostCredential": {
"@id": "lcn:certifiedBoostCredential",
"@context": {
"@version": 1.1,
"boostId": {
"@id": "lcn:boostId",
"@type": "xsd:string"
},
"boostCredential": {
"@id": "cred:VerifiableCredential",
"@type": "@id",
"@container": "@graph"
}
}
}
}
}
32 changes: 16 additions & 16 deletions packages/learn-card-types/src/obv3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,24 @@ export const ResultDescriptionValidator = z
.catchall(z.any());
export type ResultDescription = z.infer<typeof ResultDescriptionValidator>;

export const EvidenceValidator = z
.object({
id: z.string().optional(),
type: z.array(z.string()).nonempty(),
name: z.string().optional(),
narrative: z.string().optional(),
description: z.string().optional(),
genre: z.string().optional(),
audience: z.string().optional(),
})
.catchall(z.any());

export type Evidence = z.infer<typeof EvidenceValidator>;

export const AchievementValidator = z
.object({
id: z.string().optional(),
type: z.string().array().nonempty(),
type: z.array(z.string()).nonempty(),
alignment: AlignmentValidator.array().optional(),
achievementType: AchievementTypeValidator.optional(),
creator: ProfileValidator.optional(),
Expand All @@ -162,7 +176,7 @@ export const AchievementValidator = z
related: RelatedValidator.array().optional(),
resultDescription: ResultDescriptionValidator.array().optional(),
specialization: z.string().optional(),
tag: z.string().array().optional(),
tag: z.array(z.string()).optional(),
version: z.string().optional(),
})
.catchall(z.any());
Expand Down Expand Up @@ -219,19 +233,6 @@ export const AchievementSubjectValidator = z
.catchall(z.any());
export type AchievementSubject = z.infer<typeof AchievementSubjectValidator>;

export const EvidenceValidator = z
.object({
id: z.string().optional(),
type: z.string().or(z.string().array().nonempty()),
narrative: z.string().optional(),
name: z.string().optional(),
description: z.string().optional(),
genre: z.string().optional(),
audience: z.string().optional(),
})
.catchall(z.any());
export type Evidence = z.infer<typeof EvidenceValidator>;

export const UnsignedAchievementCredentialValidator = UnsignedVCValidator.extend({
name: z.string().optional(),
description: z.string().optional(),
Expand All @@ -242,7 +243,6 @@ export const UnsignedAchievementCredentialValidator = UnsignedVCValidator.extend
[typeof AchievementSubjectValidator, z.ZodArray<typeof AchievementSubjectValidator>]
>,
endorsement: UnsignedVCValidator.array().optional(),
evidence: EvidenceValidator.array().optional(),
});
export type UnsignedAchievementCredential = z.infer<typeof UnsignedAchievementCredentialValidator>;

Expand Down
12 changes: 10 additions & 2 deletions packages/learn-card-types/src/vc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,15 @@ export const TermsOfUseValidator = z
export type TermsOfUse = z.infer<typeof TermsOfUseValidator>;

export const VC2EvidenceValidator = z
.object({ type: z.string().or(z.string().array().nonempty()), id: z.string().optional() })
.object({
id: z.string().optional(),
type: z.array(z.string()).nonempty(),
name: z.string().optional(),
narrative: z.string().optional(),
description: z.string().optional(),
genre: z.string().optional(),
audience: z.string().optional(),
})
.catchall(z.any());
export type VC2Evidence = z.infer<typeof VC2EvidenceValidator>;

Expand Down Expand Up @@ -152,7 +160,7 @@ export const UnsignedVCValidator = z
validUntil: z.string().optional(),
status: CredentialStatusValidator.or(CredentialStatusValidator.array()).optional(),
termsOfUse: TermsOfUseValidator.or(TermsOfUseValidator.array()).optional(),
evidence: VC2EvidenceValidator.or(VC2EvidenceValidator.array()).optional(),
evidence: z.union([VC2EvidenceValidator, z.array(VC2EvidenceValidator)]).optional(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Maintainability - Inconsistent Union Syntax: Use consistent syntax by changing to VC2EvidenceValidator.or(VC2EvidenceValidator.array()).optional() to match the pattern used for other similar fields.

Suggested change
evidence: z.union([VC2EvidenceValidator, z.array(VC2EvidenceValidator)]).optional(),
evidence: VC2EvidenceValidator.or(VC2EvidenceValidator.array()).optional(),

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Maintainability - Inconsistent Validation Pattern: Change to use the consistent .or() pattern: evidence: VC2EvidenceValidator.or(VC2EvidenceValidator.array()).optional()

Suggested change
evidence: z.union([VC2EvidenceValidator, z.array(VC2EvidenceValidator)]).optional(),
evidence: VC2EvidenceValidator.or(VC2EvidenceValidator.array()).optional(),

})
.catchall(z.any());
export type UnsignedVC = z.infer<typeof UnsignedVCValidator>;
Expand Down
Loading
Loading