@originator-profile/model 0.5.2 → 0.5.4

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/index.cjs ADDED
@@ -0,0 +1,484 @@
1
+ 'use strict';
2
+
3
+ var zod = require('zod');
4
+ var websri = require('websri');
5
+
6
+ function isValidOrigin(val) {
7
+ try {
8
+ return new URL(val).origin === val;
9
+ } catch {
10
+ return false;
11
+ }
12
+ }
13
+ const Item$1 = zod.z.stringFormat("origin", isValidOrigin, {
14
+ error: "Origin MUST be in the format scheme://host[:port] (do not include a trailing slash or path. e.g. https://example.com)"
15
+ });
16
+ const AllowedOrigin = zod.z.union([Item$1, zod.z.array(Item$1).min(1)]).describe(
17
+ "@deprecated allowedOrigin is deprecated in Content Attestation. Use allowedUrl instead. Supported until September 2026.\n\nThe [origin](https://www.rfc-editor.org/rfc/rfc6454#section-7) of the information being asserted."
18
+ );
19
+
20
+ function isValidUrlPattern(val) {
21
+ try {
22
+ new URLPattern(val);
23
+ return true;
24
+ } catch {
25
+ return false;
26
+ }
27
+ }
28
+ const Item = zod.z.stringFormat("url-pattern", isValidUrlPattern, {
29
+ error: "Invalid URL Pattern string (* alone is not allowed. Specify a URL Pattern string such as https://example.com/*)"
30
+ });
31
+ const AllowedUrl = zod.z.union([Item, zod.z.array(Item).min(1)]).describe(
32
+ "The URL for which information is asserted by this Content Attestation. The string MUST be a URL Pattern string. It MUST NOT be an empty array."
33
+ );
34
+
35
+ const CertificationSystem = zod.z.object({
36
+ id: zod.z.url().describe("Certification system ID"),
37
+ type: zod.z.literal("CertificationSystem"),
38
+ name: zod.z.string().describe("Name of the certification system"),
39
+ description: zod.z.string().optional().describe("Description"),
40
+ ref: zod.z.url().optional().describe(
41
+ "A URL for people to read to find out more about the certification system."
42
+ )
43
+ });
44
+
45
+ const OpCipContext = zod.z.tuple([
46
+ zod.z.literal("https://www.w3.org/ns/credentials/v2"),
47
+ zod.z.literal("https://originator-profile.org/ns/credentials/v1"),
48
+ zod.z.literal("https://originator-profile.org/ns/cip/v1"),
49
+ zod.z.object({
50
+ "@language": zod.z.string().describe("Language code")
51
+ })
52
+ ]);
53
+
54
+ const DateTimeStamp = zod.z.iso.datetime({
55
+ offset: true,
56
+ error: "Must be an xsd:dateTimeStamp string (e.g. 2024-01-01T00:00:00Z or 2024-01-01T00:00:00+09:00)"
57
+ });
58
+
59
+ const DNS_URI_PATTERN = /^dns:([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)*[a-zA-Z](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$/;
60
+ const OpId = zod.z.string().regex(DNS_URI_PATTERN, {
61
+ error: "Invalid OP ID: must be dns:<valid-domain>"
62
+ });
63
+
64
+ const SubresourceIntegrity = zod.z.stringFormat(
65
+ "sri",
66
+ (val) => {
67
+ try {
68
+ const integrity = new websri.IntegrityMetadataSet(val);
69
+ return integrity.size > 0 && [...integrity].every((m) => m.alg in websri.supportedHashAlgorithms);
70
+ } catch {
71
+ return false;
72
+ }
73
+ },
74
+ {
75
+ error: "Must be in the format sha256-<base64>, sha384-<base64>, or sha512-<base64>."
76
+ }
77
+ ).describe("Subresource Integrity (SRI) string");
78
+
79
+ const RawImage = zod.z.object({
80
+ id: zod.z.url(),
81
+ content: zod.z.union([zod.z.string(), zod.z.array(zod.z.string())]).describe("Transient content for digestSRI auto-calculation")
82
+ });
83
+ const Image = zod.z.object({
84
+ id: zod.z.url(),
85
+ digestSRI: SubresourceIntegrity.optional()
86
+ });
87
+
88
+ const CertificateProperties = zod.z.object({
89
+ id: OpId.describe("OP ID of the subject"),
90
+ type: zod.z.literal("CertificateProperties"),
91
+ description: zod.z.string().optional().describe("Description"),
92
+ image: Image.optional(),
93
+ certifier: zod.z.string().optional().describe("Name of the certification authority"),
94
+ verifier: zod.z.string().optional().describe("Name of the verification authority"),
95
+ certificationSystem: CertificationSystem
96
+ });
97
+
98
+ const Certificate = zod.z.object({
99
+ "@context": OpCipContext,
100
+ type: zod.z.tuple([zod.z.literal("VerifiableCredential"), zod.z.literal("Certificate")]),
101
+ issuer: OpId,
102
+ validFrom: DateTimeStamp.optional().describe(
103
+ "Validity period start and time"
104
+ ),
105
+ validUntil: DateTimeStamp.optional().describe("Validity period end and time"),
106
+ credentialSubject: CertificateProperties
107
+ });
108
+
109
+ const JapaneseExistenceCertificateProperties = zod.z.object({
110
+ id: OpId.describe("OP ID of the subject"),
111
+ type: zod.z.literal("JP-OrganizationExistenceCertificate"),
112
+ name: zod.z.string().describe("PA name"),
113
+ description: zod.z.string().optional().describe("Description"),
114
+ image: Image.optional(),
115
+ corporateName: zod.z.string().describe("Corporate name"),
116
+ corporateNumber: zod.z.string().describe("Corporate number"),
117
+ postalCode: zod.z.string().describe("Postal code"),
118
+ addressCountry: zod.z.string().describe("Country"),
119
+ addressRegion: zod.z.string().describe("Prefecture / State"),
120
+ addressLocality: zod.z.string().describe("City / Municipality"),
121
+ streetAddress: zod.z.string().describe("Street address"),
122
+ certificationSystem: CertificationSystem
123
+ });
124
+ const JapaneseExistenceCertificate = zod.z.looseObject({
125
+ "@context": OpCipContext,
126
+ type: zod.z.tuple([zod.z.literal("VerifiableCredential"), zod.z.literal("Certificate")]),
127
+ issuer: OpId,
128
+ credentialSubject: JapaneseExistenceCertificateProperties,
129
+ validFrom: DateTimeStamp.optional().describe(
130
+ "Validity period start and time"
131
+ ),
132
+ validUntil: DateTimeStamp.optional().describe("Validity period end and time")
133
+ });
134
+
135
+ const Page = zod.z.object({
136
+ id: zod.z.url(),
137
+ name: zod.z.string()
138
+ });
139
+
140
+ const OpContextHead = zod.z.array(zod.z.unknown()).refine(
141
+ (arr) => arr.includes("https://www.w3.org/ns/credentials/v2") && arr.includes("https://originator-profile.org/ns/credentials/v1"),
142
+ {
143
+ error: "Context must include both W3C credentials v2 and OP credentials v1"
144
+ }
145
+ );
146
+
147
+ const BasicTarget = zod.z.looseObject({
148
+ type: zod.z.enum([
149
+ "TextTargetIntegrity",
150
+ "VisibleTextTargetIntegrity",
151
+ "HtmlTargetIntegrity"
152
+ ]),
153
+ integrity: SubresourceIntegrity,
154
+ cssSelector: zod.z.string().describe("CSS selector")
155
+ });
156
+
157
+ const ExternalResourceTarget = zod.z.looseObject({
158
+ type: zod.z.literal("ExternalResourceTargetIntegrity"),
159
+ integrity: SubresourceIntegrity
160
+ });
161
+
162
+ const RawTarget = zod.z.looseObject({
163
+ type: zod.z.enum([
164
+ "TextTargetIntegrity",
165
+ "VisibleTextTargetIntegrity",
166
+ "HtmlTargetIntegrity",
167
+ "ExternalResourceTargetIntegrity"
168
+ ]).describe("Target Integrity type (e.g., TextTargetIntegrity)"),
169
+ content: zod.z.union([
170
+ zod.z.array(zod.z.string().describe("Content body (text/html or URL)")),
171
+ zod.z.string().describe("Content body (text/html or URL)")
172
+ ]).optional(),
173
+ cssSelector: zod.z.string().optional().describe("CSS selector")
174
+ }).describe("Raw target");
175
+
176
+ const Target = zod.z.union([BasicTarget, ExternalResourceTarget]);
177
+
178
+ const subject$5 = zod.z.looseObject({
179
+ id: zod.z.url().describe("CA ID"),
180
+ type: zod.z.string().describe("JSON-LD type")
181
+ });
182
+ const ContentAttestation = zod.z.looseObject({
183
+ "@context": OpContextHead,
184
+ type: zod.z.array(zod.z.unknown()).refine((arr) => arr.includes("ContentAttestation"), {
185
+ error: `type must include "ContentAttestation"`
186
+ }),
187
+ issuer: OpId,
188
+ credentialSubject: subject$5,
189
+ allowedUrl: AllowedUrl.optional(),
190
+ allowedOrigin: AllowedOrigin.optional(),
191
+ target: zod.z.array(Target).min(1)
192
+ });
193
+
194
+ const subject$4 = zod.z.looseObject({
195
+ id: zod.z.url().describe("CA ID"),
196
+ type: zod.z.literal("OnlineAd"),
197
+ name: zod.z.string().optional().describe("Title of the ad."),
198
+ description: zod.z.string().optional().describe("Ad description (plain text)."),
199
+ image: Image.optional(),
200
+ genre: zod.z.string().optional().describe("Genre"),
201
+ landingPageUrl: zod.z.url().optional().describe("Landing page URL"),
202
+ adReportContact: Page.optional(),
203
+ adReviewGuidelines: Page.optional(),
204
+ targetingPolicy: Page.optional(),
205
+ adDataHandlingPolicy: Page.optional(),
206
+ adDisplayRationale: zod.z.object({
207
+ page: Page.optional(),
208
+ description: zod.z.string().optional()
209
+ }).refine(
210
+ (obj) => obj.page !== void 0 || obj.description !== void 0,
211
+ { error: "Either page or description must be provided" }
212
+ ).optional().describe("The reason this ad is being displayed")
213
+ }).refine(
214
+ (obj) => obj.name !== void 0 || obj.description !== void 0 || obj.image !== void 0,
215
+ { error: "At least one of name, description, or image must be provided" }
216
+ );
217
+ const withAllowedUrl = zod.z.object({
218
+ allowedUrl: AllowedUrl,
219
+ allowedOrigin: zod.z.never().optional()
220
+ });
221
+ const withAllowedOrigin = zod.z.object({
222
+ allowedUrl: zod.z.never().optional(),
223
+ allowedOrigin: AllowedOrigin
224
+ });
225
+ const AdvertisementCA = ContentAttestation.extend({
226
+ "@context": OpCipContext,
227
+ credentialSubject: subject$4
228
+ }).and(zod.z.union([withAllowedUrl, withAllowedOrigin]));
229
+
230
+ const subject$3 = zod.z.object({
231
+ id: zod.z.url().describe("CA ID"),
232
+ type: zod.z.literal("Advertorial"),
233
+ headline: zod.z.string().describe("Title of the advertorial."),
234
+ description: zod.z.string().describe("A description of the advertorial (string)."),
235
+ image: Image.optional(),
236
+ datePublished: DateTimeStamp.optional().describe("Publication date and time"),
237
+ dateModified: DateTimeStamp.optional().describe(
238
+ "Last modified date and time"
239
+ ),
240
+ author: zod.z.array(zod.z.string()).optional().describe("Author names"),
241
+ editor: zod.z.array(zod.z.string()).optional().describe("Editor names"),
242
+ sponsor: zod.z.array(zod.z.string()).optional().describe("Sponsor names"),
243
+ genre: zod.z.string().optional().describe("Genre")
244
+ });
245
+ const AdvertorialCA = ContentAttestation.extend({
246
+ "@context": OpCipContext,
247
+ credentialSubject: subject$3,
248
+ allowedUrl: AllowedUrl
249
+ }).refine((obj) => !("allowedOrigin" in obj), {
250
+ error: "allowedOrigin is not allowed in AdvertorialCA"
251
+ });
252
+
253
+ const subject$2 = zod.z.object({
254
+ id: zod.z.url().describe("CA ID"),
255
+ type: zod.z.literal("Article"),
256
+ headline: zod.z.string().describe("Title of the content."),
257
+ description: zod.z.string().describe("A description of the content (plain text)."),
258
+ image: Image.optional(),
259
+ datePublished: DateTimeStamp.optional().describe("Publication date and time"),
260
+ dateModified: DateTimeStamp.optional().describe(
261
+ "Last modified date and time"
262
+ ),
263
+ author: zod.z.array(zod.z.string()).optional().describe("Author names"),
264
+ editor: zod.z.array(zod.z.string()).optional().describe("Editor names"),
265
+ genre: zod.z.string().optional().describe("Genre")
266
+ });
267
+ const ArticleCA = ContentAttestation.extend({
268
+ "@context": OpCipContext,
269
+ credentialSubject: subject$2,
270
+ allowedUrl: AllowedUrl
271
+ }).refine((obj) => !("allowedOrigin" in obj), {
272
+ error: "allowedOrigin is not allowed in ArticleCA"
273
+ });
274
+
275
+ const UnsignedContentAttestation = zod.z.looseObject({
276
+ "@context": OpContextHead,
277
+ type: zod.z.array(zod.z.unknown()).refine((arr) => arr.includes("ContentAttestation"), {
278
+ error: `type must include "ContentAttestation"`
279
+ }),
280
+ issuer: OpId,
281
+ credentialSubject: subject$5,
282
+ allowedUrl: AllowedUrl.optional(),
283
+ allowedOrigin: AllowedOrigin.optional(),
284
+ target: zod.z.array(RawTarget).min(1)
285
+ });
286
+
287
+ const ContentAttestationSetItem = zod.z.union([
288
+ zod.z.looseObject({
289
+ main: zod.z.literal(true).describe("Main content"),
290
+ attestation: zod.z.string().describe("Content Attestation")
291
+ }),
292
+ zod.z.string().describe("Content Attestation")
293
+ ]);
294
+ const ContentAttestationSet = zod.z.array(ContentAttestationSetItem);
295
+
296
+ const CpContext = zod.z.tuple([
297
+ zod.z.literal("https://www.w3.org/ns/credentials/v2"),
298
+ zod.z.literal("https://originator-profile.org/ns/credentials/v1")
299
+ ]);
300
+
301
+ const Jwk = zod.z.looseObject({
302
+ kty: zod.z.string(),
303
+ use: zod.z.string().optional(),
304
+ key_ops: zod.z.array(zod.z.string()).optional(),
305
+ alg: zod.z.string().optional(),
306
+ kid: zod.z.string(),
307
+ x5u: zod.z.string().optional(),
308
+ x5c: zod.z.array(zod.z.string()).optional(),
309
+ x5t: zod.z.string().optional(),
310
+ "x5t#S256": zod.z.string().optional()
311
+ });
312
+
313
+ const Jwks = zod.z.looseObject({
314
+ keys: zod.z.array(Jwk)
315
+ });
316
+
317
+ const CoreProfile = zod.z.object({
318
+ "@context": CpContext,
319
+ type: zod.z.tuple([zod.z.literal("VerifiableCredential"), zod.z.literal("CoreProfile")]),
320
+ issuer: OpId,
321
+ credentialSubject: zod.z.object({
322
+ id: OpId,
323
+ type: zod.z.literal("Core"),
324
+ jwks: Jwks
325
+ })
326
+ });
327
+
328
+ const Description = zod.z.union([
329
+ zod.z.string(),
330
+ zod.z.looseObject({
331
+ text: zod.z.string().describe("Text value."),
332
+ encodingFormat: zod.z.enum(["text/plain", "text/html"]).describe(
333
+ "MIME type. Allowed values: 'text/plain' and 'text/html' (only br, p, ol, ul, li allowed)."
334
+ )
335
+ })
336
+ ]);
337
+
338
+ const OpMeta = zod.z.object({
339
+ targetopid: zod.z.string()
340
+ }).passthrough();
341
+
342
+ const OpVc = zod.z.looseObject({
343
+ "@context": OpContextHead,
344
+ type: zod.z.array(zod.z.unknown()).refine((arr) => arr.includes("VerifiableCredential"), {
345
+ error: `type must include "VerifiableCredential"`
346
+ }),
347
+ issuer: OpId,
348
+ credentialSubject: zod.z.looseObject({
349
+ id: OpId
350
+ })
351
+ });
352
+
353
+ const OriginatorProfile = zod.z.looseObject({
354
+ core: zod.z.string().describe("Core Profile"),
355
+ annotations: zod.z.array(zod.z.string().describe("Profile Annotation")).optional().describe("An array of Profile Annotation"),
356
+ /** @deprecated 後方互換性のため 2026-11-01 まで非配列 WMP を許容。代わりに配列を使用してください。 */
357
+ media: zod.z.union([zod.z.string(), zod.z.array(zod.z.string())]).optional().describe(
358
+ `An array of Web Media Profile
359
+
360
+ @deprecated \u5F8C\u65B9\u4E92\u63DB\u6027\u306E\u305F\u3081 2026-11-01 \u307E\u3067\u975E\u914D\u5217 WMP \u3092\u8A31\u5BB9\u3002\u4EE3\u308F\u308A\u306B\u914D\u5217\u3092\u4F7F\u7528\u3057\u3066\u304F\u3060\u3055\u3044\u3002
361
+ `
362
+ )
363
+ });
364
+ const OriginatorProfileSet = zod.z.array(OriginatorProfile);
365
+
366
+ const SiteProfile = zod.z.looseObject({
367
+ originators: zod.z.array(OriginatorProfile).min(1),
368
+ sites: zod.z.array(zod.z.string().describe("Website Profile")).optional().describe("An array of Website Profile"),
369
+ /** @deprecated 後方互換性のため 2026-11-01 まで許容。sites が優先され、存在しない場合に credential を使用。 */
370
+ credential: zod.z.string().optional().describe(
371
+ "@deprecated \u5F8C\u65B9\u4E92\u63DB\u6027\u306E\u305F\u3081 2026-11-01 \u307E\u3067\u8A31\u5BB9\u3002sites \u304C\u512A\u5148\u3055\u308C\u3001\u5B58\u5728\u3057\u306A\u3044\u5834\u5408\u306B credential \u3092\u4F7F\u7528\u3002"
372
+ )
373
+ });
374
+
375
+ const deprecatedSubject = zod.z.looseObject({
376
+ id: zod.z.url().describe("Web site origin (format: https://<hostname>)"),
377
+ type: zod.z.literal("WebSite"),
378
+ name: zod.z.string().describe("The name of the Web site."),
379
+ image: Image.optional(),
380
+ description: zod.z.string().optional().describe("A description of the Web site."),
381
+ url: AllowedOrigin
382
+ });
383
+ const subject$1 = zod.z.looseObject({
384
+ id: zod.z.url().describe(
385
+ "It MUST be the Web site URL. If the same content exists on multiple URLs, specify the most representative URL."
386
+ ),
387
+ type: zod.z.literal("WebSite"),
388
+ name: zod.z.string().describe("The name of the Web site."),
389
+ image: Image.optional(),
390
+ description: zod.z.string().optional().describe("A description of the Web site."),
391
+ allowedOrigin: AllowedOrigin
392
+ });
393
+ const WebsiteProfile = zod.z.looseObject({
394
+ "@context": OpCipContext,
395
+ type: zod.z.tuple([
396
+ zod.z.literal("VerifiableCredential"),
397
+ zod.z.literal("WebsiteProfile")
398
+ ]),
399
+ issuer: OpId,
400
+ credentialSubject: zod.z.union([deprecatedSubject, subject$1])
401
+ });
402
+
403
+ const UnsignedWebsiteProfile = zod.z.looseObject({
404
+ ...WebsiteProfile.shape,
405
+ credentialSubject: zod.z.union([
406
+ ...WebsiteProfile.shape.credentialSubject.options,
407
+ WebsiteProfile.shape.credentialSubject.options.at(-1)?.safeExtend({
408
+ image: zod.z.union([RawImage, Image])
409
+ }) ?? zod.z.never()
410
+ ])
411
+ });
412
+
413
+ const subject = zod.z.looseObject({
414
+ id: OpId.describe("OP ID of the WMP holding organization"),
415
+ type: zod.z.literal("OnlineBusiness"),
416
+ url: zod.z.url().describe("Web media URL"),
417
+ name: zod.z.string().describe("Organization name"),
418
+ logo: Image.optional(),
419
+ email: zod.z.email().optional().describe("Email address"),
420
+ telephone: zod.z.string().optional().describe("Phone number"),
421
+ contactPoint: zod.z.object({
422
+ id: zod.z.url().describe("Contact page URL"),
423
+ name: zod.z.string().describe("Contact page display name")
424
+ }).optional(),
425
+ informationTransmissionPolicy: zod.z.object({
426
+ id: zod.z.url().describe("Information transmission policy URL"),
427
+ name: zod.z.string().describe("Information transmission policy display name")
428
+ }).optional(),
429
+ publishingPrinciple: zod.z.object({
430
+ id: zod.z.url().describe("Editorial guidelines URL"),
431
+ name: zod.z.string().describe("Editorial guidelines display name")
432
+ }).optional(),
433
+ privacyPolicy: zod.z.object({
434
+ id: zod.z.url().describe("Privacy policy page URL"),
435
+ name: zod.z.string().describe("Privacy policy page display name")
436
+ }).optional(),
437
+ description: zod.z.union([Description, zod.z.array(Description)]).optional()
438
+ });
439
+ const WebMediaProfile = zod.z.looseObject({
440
+ "@context": OpCipContext,
441
+ type: zod.z.tuple([
442
+ zod.z.literal("VerifiableCredential"),
443
+ zod.z.literal("WebMediaProfile")
444
+ ]),
445
+ issuer: OpId,
446
+ credentialSubject: subject
447
+ });
448
+
449
+ exports.AdvertisementCA = AdvertisementCA;
450
+ exports.AdvertorialCA = AdvertorialCA;
451
+ exports.AllowedOrigin = AllowedOrigin;
452
+ exports.AllowedUrl = AllowedUrl;
453
+ exports.ArticleCA = ArticleCA;
454
+ exports.BasicTarget = BasicTarget;
455
+ exports.Certificate = Certificate;
456
+ exports.CertificationSystem = CertificationSystem;
457
+ exports.ContentAttestation = ContentAttestation;
458
+ exports.ContentAttestationSet = ContentAttestationSet;
459
+ exports.ContentAttestationSetItem = ContentAttestationSetItem;
460
+ exports.CoreProfile = CoreProfile;
461
+ exports.DateTimeStamp = DateTimeStamp;
462
+ exports.Description = Description;
463
+ exports.ExternalResourceTarget = ExternalResourceTarget;
464
+ exports.Image = Image;
465
+ exports.JapaneseExistenceCertificate = JapaneseExistenceCertificate;
466
+ exports.JapaneseExistenceCertificateProperties = JapaneseExistenceCertificateProperties;
467
+ exports.Jwk = Jwk;
468
+ exports.Jwks = Jwks;
469
+ exports.OpId = OpId;
470
+ exports.OpMeta = OpMeta;
471
+ exports.OpVc = OpVc;
472
+ exports.OriginatorProfile = OriginatorProfile;
473
+ exports.OriginatorProfileSet = OriginatorProfileSet;
474
+ exports.Page = Page;
475
+ exports.RawImage = RawImage;
476
+ exports.RawTarget = RawTarget;
477
+ exports.SiteProfile = SiteProfile;
478
+ exports.SubresourceIntegrity = SubresourceIntegrity;
479
+ exports.Target = Target;
480
+ exports.UnsignedContentAttestation = UnsignedContentAttestation;
481
+ exports.UnsignedWebsiteProfile = UnsignedWebsiteProfile;
482
+ exports.WebMediaProfile = WebMediaProfile;
483
+ exports.WebsiteProfile = WebsiteProfile;
484
+ exports.subject = subject$5;