@learncard/render-method-plugin 3.0.3 → 3.0.5
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/render-method-plugin.cjs.development.cjs +8580 -5046
- package/dist/render-method-plugin.cjs.development.cjs.map +4 -4
- package/dist/render-method-plugin.cjs.production.min.cjs +111 -27
- package/dist/render-method-plugin.cjs.production.min.cjs.map +4 -4
- package/dist/render-method-plugin.esm.js +8580 -5046
- package/dist/render-method-plugin.esm.js.map +4 -4
- package/package.json +65 -63
- package/src/index.ts +3 -0
- package/src/plugin.ts +150 -0
- package/src/read.ts +225 -0
- package/src/test/plugin.test.ts +652 -0
- package/src/types.ts +119 -0
- package/LICENSE +0 -21
package/src/types.ts
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { Plugin, LearnCard } from '@learncard/core';
|
|
2
|
+
import { UnsignedVC, VC, RenderMethod, TemplateRenderMethod } from '@learncard/types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* JSON-LD context for W3C `renderMethod`.
|
|
6
|
+
*
|
|
7
|
+
* ⚠️ DRAFT CONTEXT WARNING
|
|
8
|
+
* This URL points to a community-group draft hosted on Digital Bazaar's GitHub Pages, not a
|
|
9
|
+
* finalized W3C TR. The `v2rc2` suffix means "v2, release candidate 2".
|
|
10
|
+
*
|
|
11
|
+
* Risks of issuing VCs that reference this URL in their `@context`:
|
|
12
|
+
* - URL could move, be renamed, or 404 — JSON-LD context resolution would fail at verification time.
|
|
13
|
+
* - Term definitions could change between rc2 and a final spec, breaking interpretation.
|
|
14
|
+
* - Not statically cached by DidKit — verification incurs a network fetch.
|
|
15
|
+
*
|
|
16
|
+
* Mitigation plan (not yet implemented):
|
|
17
|
+
* - Bundle the context locally (see `packages/learn-card-contexts/` for the prior pattern).
|
|
18
|
+
* - Migrate to a stable W3C TR context URL when the spec finalizes.
|
|
19
|
+
*
|
|
20
|
+
* Tracking: https://www.w3.org/TR/vc-render-method/ (when published).
|
|
21
|
+
*/
|
|
22
|
+
export const RENDER_METHOD_CONTEXT =
|
|
23
|
+
'https://digitalbazaar.github.io/vc-render-method-context/contexts/v2rc2.jsonld';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Config for building a render method. Exactly one of `templateId` or `templateValue` must be
|
|
27
|
+
* provided — the discriminated union enforces this at compile time.
|
|
28
|
+
*
|
|
29
|
+
* - `templateId`: HTTPS URL of a hosted SVG Mustache template (only `http://` or `https://` is accepted).
|
|
30
|
+
* - `templateValue`: Inline SVG Mustache content (URL-encoded into a `data:image/svg+xml,` URI).
|
|
31
|
+
* - `renderProperty`: Optional JSON Pointer paths (RFC 6901) scoping which VC fields are exposed
|
|
32
|
+
* to the template.
|
|
33
|
+
*/
|
|
34
|
+
export type AttachRenderMethodConfig =
|
|
35
|
+
| { templateId: string; templateValue?: never; renderProperty?: string[] }
|
|
36
|
+
| { templateValue: string; templateId?: never; renderProperty?: string[] };
|
|
37
|
+
|
|
38
|
+
type AnyCredential = VC | UnsignedVC;
|
|
39
|
+
|
|
40
|
+
export type RenderMethodPluginMethods = {
|
|
41
|
+
/**
|
|
42
|
+
* Attaches a `TemplateRenderMethod` to an unsigned VC and injects the render-method JSON-LD
|
|
43
|
+
* context. Merges with any existing `renderMethod` entries.
|
|
44
|
+
*
|
|
45
|
+
* **Opt-in:** returns the VC unchanged if `config` is omitted. Callers must explicitly choose
|
|
46
|
+
* a template. Pass `{ templateId: DEFAULT_TEMPLATE_ID }` to use the default hosted LearnCard
|
|
47
|
+
* template.
|
|
48
|
+
*
|
|
49
|
+
* @throws if `templateId` is not an http(s) URL, or if `templateValue` is empty.
|
|
50
|
+
*/
|
|
51
|
+
attachRenderMethod: (vc: UnsignedVC, config?: AttachRenderMethodConfig) => UnsignedVC;
|
|
52
|
+
/**
|
|
53
|
+
* Builds a `TemplateRenderMethod` descriptor without mutating a VC. Useful when callers need
|
|
54
|
+
* to compose the descriptor independently.
|
|
55
|
+
*
|
|
56
|
+
* @throws if `templateId` is not an http(s) URL, or if `templateValue` is empty.
|
|
57
|
+
*/
|
|
58
|
+
buildTemplateRenderMethod: (config: AttachRenderMethodConfig) => TemplateRenderMethod;
|
|
59
|
+
/**
|
|
60
|
+
* Returns all `renderMethod` entries on a VC, normalizing single-object form to an array and
|
|
61
|
+
* unwrapping `CertifiedBoostCredential`. Entries are NOT validated — apply a type guard via
|
|
62
|
+
* `findRenderMethod` / `findRenderMethods` for selection.
|
|
63
|
+
*/
|
|
64
|
+
getRenderMethods: (vc: AnyCredential) => RenderMethod[];
|
|
65
|
+
/**
|
|
66
|
+
* First `renderMethod` matching a type-guard predicate, or `null`. The predicate's narrowed
|
|
67
|
+
* type is returned, so callers using `isSvgMustacheRenderMethod` get back a
|
|
68
|
+
* `TemplateRenderMethod` (validated against the Zod schema).
|
|
69
|
+
*/
|
|
70
|
+
findRenderMethod: <T extends RenderMethod = RenderMethod>(
|
|
71
|
+
vc: AnyCredential,
|
|
72
|
+
predicate: (rm: RenderMethod) => rm is T
|
|
73
|
+
) => T | null;
|
|
74
|
+
/** Like `findRenderMethod`, but returns every matching entry. */
|
|
75
|
+
findRenderMethods: <T extends RenderMethod = RenderMethod>(
|
|
76
|
+
vc: AnyCredential,
|
|
77
|
+
predicate: (rm: RenderMethod) => rm is T
|
|
78
|
+
) => T[];
|
|
79
|
+
/**
|
|
80
|
+
* First `TemplateRenderMethod` on a VC whose `renderSuite` matches the given suite name (or
|
|
81
|
+
* any of the names in an array — useful for capability negotiation). Returns the Zod-parsed
|
|
82
|
+
* shape, or `null` if no entry matches.
|
|
83
|
+
*/
|
|
84
|
+
findTemplateRenderMethod: (
|
|
85
|
+
vc: AnyCredential,
|
|
86
|
+
suite: string | readonly string[]
|
|
87
|
+
) => TemplateRenderMethod | null;
|
|
88
|
+
/** Like `findTemplateRenderMethod`, but returns every matching entry. */
|
|
89
|
+
findTemplateRenderMethods: (
|
|
90
|
+
vc: AnyCredential,
|
|
91
|
+
suite: string | readonly string[]
|
|
92
|
+
) => TemplateRenderMethod[];
|
|
93
|
+
/**
|
|
94
|
+
* Convenience: the first svg-mustache `TemplateRenderMethod` on a VC, or `null`. Equivalent
|
|
95
|
+
* to `findTemplateRenderMethod(vc, 'svg-mustache')`.
|
|
96
|
+
*/
|
|
97
|
+
getSvgMustacheRenderMethod: (vc: AnyCredential) => TemplateRenderMethod | null;
|
|
98
|
+
/**
|
|
99
|
+
* Portable Mustache render-data context for a VC. Spreads the credential at the top level and
|
|
100
|
+
* adds `vc`, `credential`, `credentialSubjects` aliases so templates authored against any
|
|
101
|
+
* common shape work uniformly. When `renderProperty` is provided (RFC 6901 JSON Pointers),
|
|
102
|
+
* those values are overlaid at their pointer paths.
|
|
103
|
+
*/
|
|
104
|
+
buildRenderData: (vc: AnyCredential, renderProperty?: string[]) => Record<string, unknown>;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* This plugin is stateless and has no required dependent methods or control planes. It accepts
|
|
109
|
+
* any wallet stack.
|
|
110
|
+
*/
|
|
111
|
+
export type RenderMethodDependentLearnCard = LearnCard<any[]>;
|
|
112
|
+
|
|
113
|
+
export type RenderMethodPlugin = Plugin<
|
|
114
|
+
'Render Method',
|
|
115
|
+
never,
|
|
116
|
+
RenderMethodPluginMethods,
|
|
117
|
+
never,
|
|
118
|
+
Record<never, never>
|
|
119
|
+
>;
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Learning Economy Foundation <sdk@learningeconomy.io>
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|