@learncard/render-method-plugin 2.0.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/LICENSE +21 -0
- package/README.md +198 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/plugin.d.ts +35 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/read.d.ts +75 -0
- package/dist/read.d.ts.map +1 -0
- package/dist/render-method-plugin.cjs.development.js +32626 -0
- package/dist/render-method-plugin.cjs.development.js.map +7 -0
- package/dist/render-method-plugin.cjs.production.min.js +46 -0
- package/dist/render-method-plugin.cjs.production.min.js.map +7 -0
- package/dist/render-method-plugin.esm.js +32620 -0
- package/dist/render-method-plugin.esm.js.map +7 -0
- package/dist/types.d.ts +102 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +60 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { Plugin, LearnCard } from '@learncard/core';
|
|
2
|
+
import { UnsignedVC, VC, RenderMethod, TemplateRenderMethod } from '@learncard/types';
|
|
3
|
+
/**
|
|
4
|
+
* JSON-LD context for W3C `renderMethod`.
|
|
5
|
+
*
|
|
6
|
+
* ⚠️ DRAFT CONTEXT WARNING
|
|
7
|
+
* This URL points to a community-group draft hosted on Digital Bazaar's GitHub Pages, not a
|
|
8
|
+
* finalized W3C TR. The `v2rc2` suffix means "v2, release candidate 2".
|
|
9
|
+
*
|
|
10
|
+
* Risks of issuing VCs that reference this URL in their `@context`:
|
|
11
|
+
* - URL could move, be renamed, or 404 — JSON-LD context resolution would fail at verification time.
|
|
12
|
+
* - Term definitions could change between rc2 and a final spec, breaking interpretation.
|
|
13
|
+
* - Not statically cached by DidKit — verification incurs a network fetch.
|
|
14
|
+
*
|
|
15
|
+
* Mitigation plan (not yet implemented):
|
|
16
|
+
* - Bundle the context locally (see `packages/learn-card-contexts/` for the prior pattern).
|
|
17
|
+
* - Migrate to a stable W3C TR context URL when the spec finalizes.
|
|
18
|
+
*
|
|
19
|
+
* Tracking: https://www.w3.org/TR/vc-render-method/ (when published).
|
|
20
|
+
*/
|
|
21
|
+
export declare const RENDER_METHOD_CONTEXT = "https://digitalbazaar.github.io/vc-render-method-context/contexts/v2rc2.jsonld";
|
|
22
|
+
/**
|
|
23
|
+
* Config for building a render method. Exactly one of `templateId` or `templateValue` must be
|
|
24
|
+
* provided — the discriminated union enforces this at compile time.
|
|
25
|
+
*
|
|
26
|
+
* - `templateId`: HTTPS URL of a hosted SVG Mustache template (only `http://` or `https://` is accepted).
|
|
27
|
+
* - `templateValue`: Inline SVG Mustache content (URL-encoded into a `data:image/svg+xml,` URI).
|
|
28
|
+
* - `renderProperty`: Optional JSON Pointer paths (RFC 6901) scoping which VC fields are exposed
|
|
29
|
+
* to the template.
|
|
30
|
+
*/
|
|
31
|
+
export type AttachRenderMethodConfig = {
|
|
32
|
+
templateId: string;
|
|
33
|
+
templateValue?: never;
|
|
34
|
+
renderProperty?: string[];
|
|
35
|
+
} | {
|
|
36
|
+
templateValue: string;
|
|
37
|
+
templateId?: never;
|
|
38
|
+
renderProperty?: string[];
|
|
39
|
+
};
|
|
40
|
+
type AnyCredential = VC | UnsignedVC;
|
|
41
|
+
export type RenderMethodPluginMethods = {
|
|
42
|
+
/**
|
|
43
|
+
* Attaches a `TemplateRenderMethod` to an unsigned VC and injects the render-method JSON-LD
|
|
44
|
+
* context. Merges with any existing `renderMethod` entries.
|
|
45
|
+
*
|
|
46
|
+
* **Opt-in:** returns the VC unchanged if `config` is omitted. Callers must explicitly choose
|
|
47
|
+
* a template. Pass `{ templateId: DEFAULT_TEMPLATE_ID }` to use the default hosted LearnCard
|
|
48
|
+
* template.
|
|
49
|
+
*
|
|
50
|
+
* @throws if `templateId` is not an http(s) URL, or if `templateValue` is empty.
|
|
51
|
+
*/
|
|
52
|
+
attachRenderMethod: (vc: UnsignedVC, config?: AttachRenderMethodConfig) => UnsignedVC;
|
|
53
|
+
/**
|
|
54
|
+
* Builds a `TemplateRenderMethod` descriptor without mutating a VC. Useful when callers need
|
|
55
|
+
* to compose the descriptor independently.
|
|
56
|
+
*
|
|
57
|
+
* @throws if `templateId` is not an http(s) URL, or if `templateValue` is empty.
|
|
58
|
+
*/
|
|
59
|
+
buildTemplateRenderMethod: (config: AttachRenderMethodConfig) => TemplateRenderMethod;
|
|
60
|
+
/**
|
|
61
|
+
* Returns all `renderMethod` entries on a VC, normalizing single-object form to an array and
|
|
62
|
+
* unwrapping `CertifiedBoostCredential`. Entries are NOT validated — apply a type guard via
|
|
63
|
+
* `findRenderMethod` / `findRenderMethods` for selection.
|
|
64
|
+
*/
|
|
65
|
+
getRenderMethods: (vc: AnyCredential) => RenderMethod[];
|
|
66
|
+
/**
|
|
67
|
+
* First `renderMethod` matching a type-guard predicate, or `null`. The predicate's narrowed
|
|
68
|
+
* type is returned, so callers using `isSvgMustacheRenderMethod` get back a
|
|
69
|
+
* `TemplateRenderMethod` (validated against the Zod schema).
|
|
70
|
+
*/
|
|
71
|
+
findRenderMethod: <T extends RenderMethod = RenderMethod>(vc: AnyCredential, predicate: (rm: RenderMethod) => rm is T) => T | null;
|
|
72
|
+
/** Like `findRenderMethod`, but returns every matching entry. */
|
|
73
|
+
findRenderMethods: <T extends RenderMethod = RenderMethod>(vc: AnyCredential, predicate: (rm: RenderMethod) => rm is T) => T[];
|
|
74
|
+
/**
|
|
75
|
+
* First `TemplateRenderMethod` on a VC whose `renderSuite` matches the given suite name (or
|
|
76
|
+
* any of the names in an array — useful for capability negotiation). Returns the Zod-parsed
|
|
77
|
+
* shape, or `null` if no entry matches.
|
|
78
|
+
*/
|
|
79
|
+
findTemplateRenderMethod: (vc: AnyCredential, suite: string | readonly string[]) => TemplateRenderMethod | null;
|
|
80
|
+
/** Like `findTemplateRenderMethod`, but returns every matching entry. */
|
|
81
|
+
findTemplateRenderMethods: (vc: AnyCredential, suite: string | readonly string[]) => TemplateRenderMethod[];
|
|
82
|
+
/**
|
|
83
|
+
* Convenience: the first svg-mustache `TemplateRenderMethod` on a VC, or `null`. Equivalent
|
|
84
|
+
* to `findTemplateRenderMethod(vc, 'svg-mustache')`.
|
|
85
|
+
*/
|
|
86
|
+
getSvgMustacheRenderMethod: (vc: AnyCredential) => TemplateRenderMethod | null;
|
|
87
|
+
/**
|
|
88
|
+
* Portable Mustache render-data context for a VC. Spreads the credential at the top level and
|
|
89
|
+
* adds `vc`, `credential`, `credentialSubjects` aliases so templates authored against any
|
|
90
|
+
* common shape work uniformly. When `renderProperty` is provided (RFC 6901 JSON Pointers),
|
|
91
|
+
* those values are overlaid at their pointer paths.
|
|
92
|
+
*/
|
|
93
|
+
buildRenderData: (vc: AnyCredential, renderProperty?: string[]) => Record<string, unknown>;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* This plugin is stateless and has no required dependent methods or control planes. It accepts
|
|
97
|
+
* any wallet stack.
|
|
98
|
+
*/
|
|
99
|
+
export type RenderMethodDependentLearnCard = LearnCard<any[]>;
|
|
100
|
+
export type RenderMethodPlugin = Plugin<'Render Method', never, RenderMethodPluginMethods, never, Record<never, never>>;
|
|
101
|
+
export {};
|
|
102
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAEtF;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,qBAAqB,mFACkD,CAAC;AAErF;;;;;;;;GAQG;AACH,MAAM,MAAM,wBAAwB,GAC9B;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,aAAa,CAAC,EAAE,KAAK,CAAC;IAAC,cAAc,CAAC,EA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AoB,GAAG,IAAI,CAAC;IAC/E;;;;;OAKG;IACH,eAAe,EAAE,CAAC,EAAE,EAAE,aAAa,EAAE,cAAc,CAAC,EAAE,MAAM,EAAE,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC9F,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,8BAA8B,GAAG,SAAS,CAAC,GAAG,EAAE,CAAC,CAAC;AAE9D,MAAM,MAAM,kBAAkB,GAAG,MAAM,CACnC,eAAe,EACf,KAAK,EACL,yBAAyB,EACzB,KAAK,EACL,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CACvB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@learncard/render-method-plugin",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "LearnCard plugin for attaching W3C renderMethod to Verifiable Credentials",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/render-method-plugin.esm.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"module": "./dist/render-method-plugin.esm.js",
|
|
11
|
+
"import": "./dist/render-method-plugin.esm.js",
|
|
12
|
+
"require": "./dist/index.js",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"author": "Learning Economy Foundation (www.learningeconomy.io)",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"homepage": "https://github.com/learningeconomy/LearnCard/tree/main/packages/plugins/render-method/README.md",
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/learningeconomy/LearnCard.git"
|
|
25
|
+
},
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/learningeconomy/LearnCard/issues"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/jest": "^29.2.2",
|
|
31
|
+
"@types/node": "^17.0.31",
|
|
32
|
+
"aqu": "0.4.3",
|
|
33
|
+
"esbuild": "^0.14.38",
|
|
34
|
+
"esbuild-jest": "^0.5.0",
|
|
35
|
+
"esbuild-plugin-copy": "^1.3.0",
|
|
36
|
+
"jest": "^29.3.0",
|
|
37
|
+
"rimraf": "^3.0.2",
|
|
38
|
+
"shx": "^0.3.4",
|
|
39
|
+
"ts-jest": "^29.0.3",
|
|
40
|
+
"@learncard/core": "9.4.19",
|
|
41
|
+
"@learncard/helpers": "1.3.1",
|
|
42
|
+
"@learncard/types": "5.16.0"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"@learncard/core": "9.4.19",
|
|
46
|
+
"@learncard/helpers": "1.3.1",
|
|
47
|
+
"@learncard/types": "5.16.0"
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"@learncard/helpers": "1.3.1"
|
|
51
|
+
},
|
|
52
|
+
"types": "./dist/index.d.ts",
|
|
53
|
+
"sideEffects": false,
|
|
54
|
+
"scripts": {
|
|
55
|
+
"build": "node ./scripts/build.mjs && shx cp ./scripts/mixedEntrypoint.js ./dist/index.js && tsc --p tsconfig.json",
|
|
56
|
+
"test": "jest --passWithNoTests",
|
|
57
|
+
"test:watch": "jest --watch",
|
|
58
|
+
"test:coverage": "jest --silent --ci --coverage --coverageReporters=\"text\" --coverageReporters=\"text-summary\""
|
|
59
|
+
}
|
|
60
|
+
}
|