@peac/schema 0.10.9 → 0.10.10
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 +1 -1
- package/dist/attestation-receipt.cjs +127 -0
- package/dist/attestation-receipt.cjs.map +1 -0
- package/dist/attestation-receipt.mjs +113 -0
- package/dist/attestation-receipt.mjs.map +1 -0
- package/dist/attribution.cjs +249 -0
- package/dist/attribution.cjs.map +1 -0
- package/dist/attribution.mjs +227 -0
- package/dist/attribution.mjs.map +1 -0
- package/dist/dispute.d.ts.map +1 -1
- package/dist/index.cjs +2818 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.mjs +2577 -0
- package/dist/index.mjs.map +1 -0
- package/dist/interaction.cjs +619 -0
- package/dist/interaction.cjs.map +1 -0
- package/dist/interaction.mjs +583 -0
- package/dist/interaction.mjs.map +1 -0
- package/dist/normalize.cjs +84 -0
- package/dist/normalize.cjs.map +1 -0
- package/dist/normalize.d.ts +15 -9
- package/dist/normalize.d.ts.map +1 -1
- package/dist/normalize.mjs +82 -0
- package/dist/normalize.mjs.map +1 -0
- package/dist/receipt-parser.cjs +333 -0
- package/dist/receipt-parser.cjs.map +1 -0
- package/dist/receipt-parser.mjs +331 -0
- package/dist/receipt-parser.mjs.map +1 -0
- package/dist/workflow.cjs +321 -0
- package/dist/workflow.cjs.map +1 -0
- package/dist/workflow.mjs +292 -0
- package/dist/workflow.mjs.map +1 -0
- package/package.json +50 -6
- package/dist/agent-identity.js +0 -357
- package/dist/agent-identity.js.map +0 -1
- package/dist/attestation-receipt.js +0 -249
- package/dist/attestation-receipt.js.map +0 -1
- package/dist/attribution.js +0 -444
- package/dist/attribution.js.map +0 -1
- package/dist/constants.js +0 -73
- package/dist/constants.js.map +0 -1
- package/dist/control.js +0 -9
- package/dist/control.js.map +0 -1
- package/dist/dispute.js +0 -832
- package/dist/dispute.js.map +0 -1
- package/dist/envelope.js +0 -9
- package/dist/envelope.js.map +0 -1
- package/dist/errors.js +0 -116
- package/dist/errors.js.map +0 -1
- package/dist/evidence.js +0 -8
- package/dist/evidence.js.map +0 -1
- package/dist/index.js +0 -283
- package/dist/index.js.map +0 -1
- package/dist/interaction.js +0 -918
- package/dist/interaction.js.map +0 -1
- package/dist/json.js +0 -267
- package/dist/json.js.map +0 -1
- package/dist/normalize.js +0 -103
- package/dist/normalize.js.map +0 -1
- package/dist/obligations.js +0 -337
- package/dist/obligations.js.map +0 -1
- package/dist/purpose.js +0 -296
- package/dist/purpose.js.map +0 -1
- package/dist/receipt-parser.js +0 -89
- package/dist/receipt-parser.js.map +0 -1
- package/dist/schemas.js +0 -7
- package/dist/schemas.js.map +0 -1
- package/dist/subject.js +0 -9
- package/dist/subject.js.map +0 -1
- package/dist/types.js +0 -6
- package/dist/types.js.map +0 -1
- package/dist/validators.js +0 -421
- package/dist/validators.js.map +0 -1
- package/dist/version.js +0 -7
- package/dist/version.js.map +0 -1
- package/dist/workflow.js +0 -523
- package/dist/workflow.js.map +0 -1
package/dist/obligations.js
DELETED
|
@@ -1,337 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ObligationsExtensionSchema = exports.OBLIGATIONS_EXTENSION_KEY = exports.ContributionObligationSchema = exports.CreditObligationSchema = exports.CONTRIBUTION_TYPES = exports.ContributionTypeSchema = exports.CREDIT_METHODS = exports.CreditMethodSchema = void 0;
|
|
4
|
-
exports.validateCreditObligation = validateCreditObligation;
|
|
5
|
-
exports.validateContributionObligation = validateContributionObligation;
|
|
6
|
-
exports.validateObligationsExtension = validateObligationsExtension;
|
|
7
|
-
exports.extractObligationsExtension = extractObligationsExtension;
|
|
8
|
-
exports.isCreditRequired = isCreditRequired;
|
|
9
|
-
exports.isContributionRequired = isContributionRequired;
|
|
10
|
-
exports.createCreditObligation = createCreditObligation;
|
|
11
|
-
exports.createContributionObligation = createContributionObligation;
|
|
12
|
-
exports.createObligationsExtension = createObligationsExtension;
|
|
13
|
-
/**
|
|
14
|
-
* PEAC Obligations Extension Types (v0.9.26+)
|
|
15
|
-
*
|
|
16
|
-
* Defines credit and contribution obligations for receipts,
|
|
17
|
-
* aligned with Creative Commons Signals framework.
|
|
18
|
-
*
|
|
19
|
-
* The `peac/obligations` extension allows content owners to specify
|
|
20
|
-
* requirements for credit/attribution and contribution models.
|
|
21
|
-
*
|
|
22
|
-
* @see https://creativecommons.org/signals/ for CC Signals background
|
|
23
|
-
*/
|
|
24
|
-
const zod_1 = require("zod");
|
|
25
|
-
// =============================================================================
|
|
26
|
-
// CREDIT METHOD (v0.9.26+)
|
|
27
|
-
// =============================================================================
|
|
28
|
-
/**
|
|
29
|
-
* How credit/attribution should be provided.
|
|
30
|
-
*
|
|
31
|
-
* - 'inline': Credit appears inline with the generated content
|
|
32
|
-
* - 'references': Credit appears in a references/sources section
|
|
33
|
-
* - 'model-card': Credit appears in model documentation/card
|
|
34
|
-
*/
|
|
35
|
-
exports.CreditMethodSchema = zod_1.z.enum(['inline', 'references', 'model-card']);
|
|
36
|
-
/**
|
|
37
|
-
* Array of valid credit methods for runtime checks.
|
|
38
|
-
*/
|
|
39
|
-
exports.CREDIT_METHODS = ['inline', 'references', 'model-card'];
|
|
40
|
-
// =============================================================================
|
|
41
|
-
// CONTRIBUTION TYPE (v0.9.26+)
|
|
42
|
-
// =============================================================================
|
|
43
|
-
/**
|
|
44
|
-
* Type of contribution model.
|
|
45
|
-
*
|
|
46
|
-
* - 'direct': Direct payment to content owner
|
|
47
|
-
* - 'ecosystem': Contribution to ecosystem fund/coalition
|
|
48
|
-
* - 'open': Freely usable (no payment required)
|
|
49
|
-
*/
|
|
50
|
-
exports.ContributionTypeSchema = zod_1.z.enum(['direct', 'ecosystem', 'open']);
|
|
51
|
-
/**
|
|
52
|
-
* Array of valid contribution types for runtime checks.
|
|
53
|
-
*/
|
|
54
|
-
exports.CONTRIBUTION_TYPES = ['direct', 'ecosystem', 'open'];
|
|
55
|
-
// =============================================================================
|
|
56
|
-
// CREDIT OBLIGATION (v0.9.26+)
|
|
57
|
-
// =============================================================================
|
|
58
|
-
/**
|
|
59
|
-
* CreditObligation - specifies attribution/credit requirements.
|
|
60
|
-
*
|
|
61
|
-
* Content owners can require credit when their content is used,
|
|
62
|
-
* specifying where and how the credit should appear.
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* ```typescript
|
|
66
|
-
* const credit: CreditObligation = {
|
|
67
|
-
* required: true,
|
|
68
|
-
* citation_url: 'https://publisher.example/collection',
|
|
69
|
-
* method: 'references',
|
|
70
|
-
* };
|
|
71
|
-
* ```
|
|
72
|
-
*/
|
|
73
|
-
exports.CreditObligationSchema = zod_1.z
|
|
74
|
-
.object({
|
|
75
|
-
/** Whether credit is required (REQUIRED) */
|
|
76
|
-
required: zod_1.z.boolean(),
|
|
77
|
-
/** URL for citation/attribution (OPTIONAL) */
|
|
78
|
-
citation_url: zod_1.z.string().url().max(2048).optional(),
|
|
79
|
-
/** How credit should be provided (OPTIONAL, defaults to implementation choice) */
|
|
80
|
-
method: exports.CreditMethodSchema.optional(),
|
|
81
|
-
/** Human-readable credit text template (OPTIONAL) */
|
|
82
|
-
credit_text: zod_1.z.string().max(1024).optional(),
|
|
83
|
-
})
|
|
84
|
-
.strict()
|
|
85
|
-
.superRefine((data, ctx) => {
|
|
86
|
-
// If credit is required, at least one of citation_url, credit_text, or method must be specified
|
|
87
|
-
if (data.required && !data.citation_url && !data.credit_text && !data.method) {
|
|
88
|
-
ctx.addIssue({
|
|
89
|
-
code: zod_1.z.ZodIssueCode.custom,
|
|
90
|
-
message: 'When credit is required, at least one of citation_url, credit_text, or method must be specified',
|
|
91
|
-
path: ['required'],
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
// =============================================================================
|
|
96
|
-
// CONTRIBUTION OBLIGATION (v0.9.26+)
|
|
97
|
-
// =============================================================================
|
|
98
|
-
/**
|
|
99
|
-
* ContributionObligation - specifies contribution/payment model.
|
|
100
|
-
*
|
|
101
|
-
* Aligned with CC Signals reciprocity framework:
|
|
102
|
-
* - direct: Payment goes directly to content owner
|
|
103
|
-
* - ecosystem: Payment goes to shared ecosystem fund
|
|
104
|
-
* - open: Content is freely usable
|
|
105
|
-
*
|
|
106
|
-
* @example
|
|
107
|
-
* ```typescript
|
|
108
|
-
* const contribution: ContributionObligation = {
|
|
109
|
-
* type: 'ecosystem',
|
|
110
|
-
* destination: 'https://fund.creativecommons.org',
|
|
111
|
-
* };
|
|
112
|
-
* ```
|
|
113
|
-
*/
|
|
114
|
-
exports.ContributionObligationSchema = zod_1.z
|
|
115
|
-
.object({
|
|
116
|
-
/** Type of contribution (REQUIRED) */
|
|
117
|
-
type: exports.ContributionTypeSchema,
|
|
118
|
-
/** Destination for contributions (OPTIONAL, e.g., fund URL, wallet address) */
|
|
119
|
-
destination: zod_1.z.string().max(2048).optional(),
|
|
120
|
-
/** Minimum contribution amount in minor units (OPTIONAL) */
|
|
121
|
-
min_amount: zod_1.z.number().int().min(0).optional(),
|
|
122
|
-
/** Currency for min_amount (OPTIONAL, ISO 4217 or crypto symbol like USDC) */
|
|
123
|
-
currency: zod_1.z
|
|
124
|
-
.string()
|
|
125
|
-
.min(3)
|
|
126
|
-
.max(8)
|
|
127
|
-
.regex(/^[A-Z0-9]{3,8}$/)
|
|
128
|
-
.optional(),
|
|
129
|
-
})
|
|
130
|
-
.strict()
|
|
131
|
-
.superRefine((data, ctx) => {
|
|
132
|
-
// If type is 'direct' or 'ecosystem', destination is required
|
|
133
|
-
if ((data.type === 'direct' || data.type === 'ecosystem') && !data.destination) {
|
|
134
|
-
ctx.addIssue({
|
|
135
|
-
code: zod_1.z.ZodIssueCode.custom,
|
|
136
|
-
message: `Destination is required when contribution type is '${data.type}'`,
|
|
137
|
-
path: ['destination'],
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
// min_amount requires currency
|
|
141
|
-
if (data.min_amount !== undefined && !data.currency) {
|
|
142
|
-
ctx.addIssue({
|
|
143
|
-
code: zod_1.z.ZodIssueCode.custom,
|
|
144
|
-
message: 'Currency is required when min_amount is specified',
|
|
145
|
-
path: ['currency'],
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
// =============================================================================
|
|
150
|
-
// OBLIGATIONS EXTENSION (v0.9.26+)
|
|
151
|
-
// =============================================================================
|
|
152
|
-
/**
|
|
153
|
-
* Extension key for obligations
|
|
154
|
-
*/
|
|
155
|
-
exports.OBLIGATIONS_EXTENSION_KEY = 'peac/obligations';
|
|
156
|
-
/**
|
|
157
|
-
* ObligationsExtension - the full obligations extension block.
|
|
158
|
-
*
|
|
159
|
-
* This extension is added to receipt extensions under the key `peac/obligations`.
|
|
160
|
-
*
|
|
161
|
-
* @example
|
|
162
|
-
* ```typescript
|
|
163
|
-
* const receipt = {
|
|
164
|
-
* // ... receipt fields ...
|
|
165
|
-
* extensions: {
|
|
166
|
-
* 'peac/obligations': {
|
|
167
|
-
* credit: {
|
|
168
|
-
* required: true,
|
|
169
|
-
* citation_url: 'https://publisher.example/collection',
|
|
170
|
-
* method: 'references',
|
|
171
|
-
* },
|
|
172
|
-
* contribution: {
|
|
173
|
-
* type: 'ecosystem',
|
|
174
|
-
* destination: 'https://fund.example.org',
|
|
175
|
-
* },
|
|
176
|
-
* },
|
|
177
|
-
* },
|
|
178
|
-
* };
|
|
179
|
-
* ```
|
|
180
|
-
*/
|
|
181
|
-
exports.ObligationsExtensionSchema = zod_1.z
|
|
182
|
-
.object({
|
|
183
|
-
/** Credit/attribution obligations (OPTIONAL) */
|
|
184
|
-
credit: exports.CreditObligationSchema.optional(),
|
|
185
|
-
/** Contribution/payment model (OPTIONAL) */
|
|
186
|
-
contribution: exports.ContributionObligationSchema.optional(),
|
|
187
|
-
})
|
|
188
|
-
.strict();
|
|
189
|
-
// =============================================================================
|
|
190
|
-
// VALIDATION HELPERS (v0.9.26+)
|
|
191
|
-
// =============================================================================
|
|
192
|
-
/**
|
|
193
|
-
* Validate a CreditObligation.
|
|
194
|
-
*
|
|
195
|
-
* @param data - Unknown data to validate
|
|
196
|
-
* @returns Result with validated obligation or error message
|
|
197
|
-
*/
|
|
198
|
-
function validateCreditObligation(data) {
|
|
199
|
-
const result = exports.CreditObligationSchema.safeParse(data);
|
|
200
|
-
if (result.success) {
|
|
201
|
-
return { ok: true, value: result.data };
|
|
202
|
-
}
|
|
203
|
-
return { ok: false, error: result.error.message };
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Validate a ContributionObligation.
|
|
207
|
-
*
|
|
208
|
-
* @param data - Unknown data to validate
|
|
209
|
-
* @returns Result with validated obligation or error message
|
|
210
|
-
*/
|
|
211
|
-
function validateContributionObligation(data) {
|
|
212
|
-
const result = exports.ContributionObligationSchema.safeParse(data);
|
|
213
|
-
if (result.success) {
|
|
214
|
-
return { ok: true, value: result.data };
|
|
215
|
-
}
|
|
216
|
-
return { ok: false, error: result.error.message };
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Validate an ObligationsExtension.
|
|
220
|
-
*
|
|
221
|
-
* @param data - Unknown data to validate
|
|
222
|
-
* @returns Result with validated extension or error message
|
|
223
|
-
*
|
|
224
|
-
* @example
|
|
225
|
-
* ```typescript
|
|
226
|
-
* const result = validateObligationsExtension(data);
|
|
227
|
-
* if (result.ok) {
|
|
228
|
-
* if (result.value.credit?.required) {
|
|
229
|
-
* console.log('Credit required:', result.value.credit.citation_url);
|
|
230
|
-
* }
|
|
231
|
-
* }
|
|
232
|
-
* ```
|
|
233
|
-
*/
|
|
234
|
-
function validateObligationsExtension(data) {
|
|
235
|
-
const result = exports.ObligationsExtensionSchema.safeParse(data);
|
|
236
|
-
if (result.success) {
|
|
237
|
-
return { ok: true, value: result.data };
|
|
238
|
-
}
|
|
239
|
-
return { ok: false, error: result.error.message };
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* Extract obligations extension from a receipt's extensions object.
|
|
243
|
-
*
|
|
244
|
-
* @param extensions - Extensions object from receipt
|
|
245
|
-
* @returns Validated obligations or undefined if not present
|
|
246
|
-
*/
|
|
247
|
-
function extractObligationsExtension(extensions) {
|
|
248
|
-
if (!extensions || !(exports.OBLIGATIONS_EXTENSION_KEY in extensions)) {
|
|
249
|
-
return undefined;
|
|
250
|
-
}
|
|
251
|
-
const result = validateObligationsExtension(extensions[exports.OBLIGATIONS_EXTENSION_KEY]);
|
|
252
|
-
if (result.ok) {
|
|
253
|
-
return result.value;
|
|
254
|
-
}
|
|
255
|
-
return undefined;
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* Check if credit is required based on obligations.
|
|
259
|
-
*
|
|
260
|
-
* @param obligations - Obligations extension
|
|
261
|
-
* @returns True if credit is explicitly required
|
|
262
|
-
*/
|
|
263
|
-
function isCreditRequired(obligations) {
|
|
264
|
-
return obligations?.credit?.required === true;
|
|
265
|
-
}
|
|
266
|
-
/**
|
|
267
|
-
* Check if contribution is required (non-open type).
|
|
268
|
-
*
|
|
269
|
-
* @param obligations - Obligations extension
|
|
270
|
-
* @returns True if contribution type is 'direct' or 'ecosystem'
|
|
271
|
-
*/
|
|
272
|
-
function isContributionRequired(obligations) {
|
|
273
|
-
const type = obligations?.contribution?.type;
|
|
274
|
-
return type === 'direct' || type === 'ecosystem';
|
|
275
|
-
}
|
|
276
|
-
/**
|
|
277
|
-
* Create a credit-only obligations extension.
|
|
278
|
-
*
|
|
279
|
-
* @param params - Credit parameters
|
|
280
|
-
* @returns ObligationsExtension with credit only
|
|
281
|
-
*/
|
|
282
|
-
function createCreditObligation(params) {
|
|
283
|
-
const credit = { required: params.required };
|
|
284
|
-
if (params.citation_url)
|
|
285
|
-
credit.citation_url = params.citation_url;
|
|
286
|
-
if (params.method)
|
|
287
|
-
credit.method = params.method;
|
|
288
|
-
if (params.credit_text)
|
|
289
|
-
credit.credit_text = params.credit_text;
|
|
290
|
-
return { credit };
|
|
291
|
-
}
|
|
292
|
-
/**
|
|
293
|
-
* Create a contribution-only obligations extension.
|
|
294
|
-
*
|
|
295
|
-
* @param params - Contribution parameters
|
|
296
|
-
* @returns ObligationsExtension with contribution only
|
|
297
|
-
*/
|
|
298
|
-
function createContributionObligation(params) {
|
|
299
|
-
const contribution = { type: params.type };
|
|
300
|
-
if (params.destination)
|
|
301
|
-
contribution.destination = params.destination;
|
|
302
|
-
if (params.min_amount !== undefined)
|
|
303
|
-
contribution.min_amount = params.min_amount;
|
|
304
|
-
if (params.currency)
|
|
305
|
-
contribution.currency = params.currency;
|
|
306
|
-
return { contribution };
|
|
307
|
-
}
|
|
308
|
-
/**
|
|
309
|
-
* Create a full obligations extension with both credit and contribution.
|
|
310
|
-
*
|
|
311
|
-
* @param credit - Credit obligation parameters
|
|
312
|
-
* @param contribution - Contribution obligation parameters
|
|
313
|
-
* @returns Full ObligationsExtension
|
|
314
|
-
*/
|
|
315
|
-
function createObligationsExtension(credit, contribution) {
|
|
316
|
-
const result = {};
|
|
317
|
-
if (credit) {
|
|
318
|
-
result.credit = { required: credit.required };
|
|
319
|
-
if (credit.citation_url)
|
|
320
|
-
result.credit.citation_url = credit.citation_url;
|
|
321
|
-
if (credit.method)
|
|
322
|
-
result.credit.method = credit.method;
|
|
323
|
-
if (credit.credit_text)
|
|
324
|
-
result.credit.credit_text = credit.credit_text;
|
|
325
|
-
}
|
|
326
|
-
if (contribution) {
|
|
327
|
-
result.contribution = { type: contribution.type };
|
|
328
|
-
if (contribution.destination)
|
|
329
|
-
result.contribution.destination = contribution.destination;
|
|
330
|
-
if (contribution.min_amount !== undefined)
|
|
331
|
-
result.contribution.min_amount = contribution.min_amount;
|
|
332
|
-
if (contribution.currency)
|
|
333
|
-
result.contribution.currency = contribution.currency;
|
|
334
|
-
}
|
|
335
|
-
return result;
|
|
336
|
-
}
|
|
337
|
-
//# sourceMappingURL=obligations.js.map
|
package/dist/obligations.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"obligations.js","sourceRoot":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CAAC,YAAY;YAAE,MAAM,CAAC,MAAM,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC;QAC1E,IAAI,MAAM,CAAC,MAAM;YAAE,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QACxD,IAAI,MAAM,CAAC,WAAW;YAAE,MAAM,CAAC,MAAM,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;IACzE,CAAC;IAED,IAAI,YAAY,EAAE,CAAC;QACjB,MAAM,CAAC,YAAY,GAAG,EAAE,IAAI,EAAE,YAAY,CAAC,IAAI,EAAE,CAAC;QAClD,IAAI,YAAY,CAAC,WAAW;YAAE,MAAM,CAAC,YAAY,CAAC,WAAW,GAAG,YAAY,CAAC,WAAW,CAAC;QACzF,IAAI,YAAY,CAAC,UAAU,KAAK,SAAS;YACvC,MAAM,CAAC,YAAY,CAAC,UAAU,GAAG,YAAY,CAAC,UAAU,CAAC;QAC3D,IAAI,YAAY,CAAC,QAAQ;YAAE,MAAM,CAAC,YAAY,CAAC,QAAQ,GAAG,YAAY,CAAC,QAAQ,CAAC;IAClF,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/purpose.js
DELETED
|
@@ -1,296 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* PEAC Purpose Types (v0.9.24+)
|
|
4
|
-
*
|
|
5
|
-
* Purpose type hierarchy for forward-compatible purpose handling:
|
|
6
|
-
* - PurposeToken: Wire format (string) - preserves unknown tokens
|
|
7
|
-
* - CanonicalPurpose: PEAC's normative vocabulary - enforcement semantics
|
|
8
|
-
* - PurposeReason: Audit spine for enforcement decisions
|
|
9
|
-
*
|
|
10
|
-
* @see specs/kernel/constants.json for canonical values
|
|
11
|
-
*/
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.INTERNAL_PURPOSE_UNDECLARED = exports.PURPOSE_REASONS = exports.CANONICAL_PURPOSES = exports.MAX_PURPOSE_TOKENS_PER_REQUEST = exports.MAX_PURPOSE_TOKEN_LENGTH = exports.PURPOSE_TOKEN_REGEX = void 0;
|
|
14
|
-
exports.isValidPurposeToken = isValidPurposeToken;
|
|
15
|
-
exports.isCanonicalPurpose = isCanonicalPurpose;
|
|
16
|
-
exports.isLegacyPurpose = isLegacyPurpose;
|
|
17
|
-
exports.isValidPurposeReason = isValidPurposeReason;
|
|
18
|
-
exports.isUndeclaredPurpose = isUndeclaredPurpose;
|
|
19
|
-
exports.normalizePurposeToken = normalizePurposeToken;
|
|
20
|
-
exports.parsePurposeHeader = parsePurposeHeader;
|
|
21
|
-
exports.validatePurposeTokens = validatePurposeTokens;
|
|
22
|
-
exports.deriveKnownPurposes = deriveKnownPurposes;
|
|
23
|
-
exports.mapLegacyToCanonical = mapLegacyToCanonical;
|
|
24
|
-
exports.normalizeToCanonicalOrPreserve = normalizeToCanonicalOrPreserve;
|
|
25
|
-
exports.determinePurposeReason = determinePurposeReason;
|
|
26
|
-
exports.hasUnknownPurposeTokens = hasUnknownPurposeTokens;
|
|
27
|
-
// ============================================================================
|
|
28
|
-
// Validation Constants
|
|
29
|
-
// ============================================================================
|
|
30
|
-
/**
|
|
31
|
-
* Grammar validation for PurposeToken
|
|
32
|
-
*
|
|
33
|
-
* Pattern: lowercase letter, optionally followed by alphanumeric/underscore/hyphen
|
|
34
|
-
* characters that MUST end with a letter or digit (no trailing separators).
|
|
35
|
-
* Optional vendor prefix separated by colon follows the same rules.
|
|
36
|
-
*
|
|
37
|
-
* Hyphens are allowed for interoperability with external systems (Cloudflare,
|
|
38
|
-
* IETF AIPREF, etc.) that use hyphenated tokens like "user-action" or "train-ai".
|
|
39
|
-
*
|
|
40
|
-
* Valid: "train", "user_action", "user-action", "cf:ai_crawler", "cf:ai-crawler", "a", "a1"
|
|
41
|
-
* Invalid: "Train", "123abc", "", "-train", "train-", "train_", "cf:ai-", "cf:-ai"
|
|
42
|
-
*/
|
|
43
|
-
exports.PURPOSE_TOKEN_REGEX = /^[a-z](?:[a-z0-9_-]*[a-z0-9])?(?::[a-z](?:[a-z0-9_-]*[a-z0-9])?)?$/;
|
|
44
|
-
/** Maximum length for a purpose token */
|
|
45
|
-
exports.MAX_PURPOSE_TOKEN_LENGTH = 64;
|
|
46
|
-
/** Maximum number of purpose tokens per request (RECOMMENDED, not MUST) */
|
|
47
|
-
exports.MAX_PURPOSE_TOKENS_PER_REQUEST = 10;
|
|
48
|
-
/** Canonical purpose tokens (from constants.json) */
|
|
49
|
-
exports.CANONICAL_PURPOSES = [
|
|
50
|
-
'train',
|
|
51
|
-
'search',
|
|
52
|
-
'user_action',
|
|
53
|
-
'inference',
|
|
54
|
-
'index',
|
|
55
|
-
];
|
|
56
|
-
/** Purpose reason values (from constants.json) */
|
|
57
|
-
exports.PURPOSE_REASONS = [
|
|
58
|
-
'allowed',
|
|
59
|
-
'constrained',
|
|
60
|
-
'denied',
|
|
61
|
-
'downgraded',
|
|
62
|
-
'undeclared_default',
|
|
63
|
-
'unknown_preserved',
|
|
64
|
-
];
|
|
65
|
-
/** Internal-only purpose value */
|
|
66
|
-
exports.INTERNAL_PURPOSE_UNDECLARED = 'undeclared';
|
|
67
|
-
// ============================================================================
|
|
68
|
-
// Validation Functions
|
|
69
|
-
// ============================================================================
|
|
70
|
-
/**
|
|
71
|
-
* Check if a string is a valid PurposeToken
|
|
72
|
-
*
|
|
73
|
-
* Validates against the purpose token grammar:
|
|
74
|
-
* - Lowercase letters, digits, underscores, hyphens
|
|
75
|
-
* - Optional vendor prefix with colon
|
|
76
|
-
* - Max 64 characters
|
|
77
|
-
* - Must start with lowercase letter
|
|
78
|
-
*
|
|
79
|
-
* @param token - String to validate
|
|
80
|
-
* @returns true if valid PurposeToken
|
|
81
|
-
*/
|
|
82
|
-
function isValidPurposeToken(token) {
|
|
83
|
-
if (typeof token !== 'string')
|
|
84
|
-
return false;
|
|
85
|
-
if (token.length === 0 || token.length > exports.MAX_PURPOSE_TOKEN_LENGTH)
|
|
86
|
-
return false;
|
|
87
|
-
return exports.PURPOSE_TOKEN_REGEX.test(token);
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Check if a PurposeToken is a CanonicalPurpose
|
|
91
|
-
*
|
|
92
|
-
* @param token - Token to check
|
|
93
|
-
* @returns true if token is in canonical vocabulary
|
|
94
|
-
*/
|
|
95
|
-
function isCanonicalPurpose(token) {
|
|
96
|
-
return exports.CANONICAL_PURPOSES.includes(token);
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Check if a PurposeToken is a LegacyPurpose
|
|
100
|
-
*
|
|
101
|
-
* @param token - Token to check
|
|
102
|
-
* @returns true if token is a legacy purpose
|
|
103
|
-
*/
|
|
104
|
-
function isLegacyPurpose(token) {
|
|
105
|
-
return token === 'crawl' || token === 'ai_input' || token === 'ai_index';
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Check if a string is a valid PurposeReason
|
|
109
|
-
*
|
|
110
|
-
* @param reason - String to check
|
|
111
|
-
* @returns true if valid PurposeReason
|
|
112
|
-
*/
|
|
113
|
-
function isValidPurposeReason(reason) {
|
|
114
|
-
return exports.PURPOSE_REASONS.includes(reason);
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Check if a purpose token is the internal-only "undeclared" value
|
|
118
|
-
*
|
|
119
|
-
* Used to reject explicit "undeclared" on wire (400 Bad Request).
|
|
120
|
-
*
|
|
121
|
-
* @param token - Token to check
|
|
122
|
-
* @returns true if token is "undeclared"
|
|
123
|
-
*/
|
|
124
|
-
function isUndeclaredPurpose(token) {
|
|
125
|
-
return token === exports.INTERNAL_PURPOSE_UNDECLARED;
|
|
126
|
-
}
|
|
127
|
-
// ============================================================================
|
|
128
|
-
// Normalization Functions
|
|
129
|
-
// ============================================================================
|
|
130
|
-
/**
|
|
131
|
-
* Normalize a purpose token
|
|
132
|
-
*
|
|
133
|
-
* Applies normalization rules:
|
|
134
|
-
* - Trim whitespace
|
|
135
|
-
* - Lowercase
|
|
136
|
-
*
|
|
137
|
-
* @param token - Raw token from header
|
|
138
|
-
* @returns Normalized token
|
|
139
|
-
*/
|
|
140
|
-
function normalizePurposeToken(token) {
|
|
141
|
-
return token.trim().toLowerCase();
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Parse PEAC-Purpose header value into array of tokens
|
|
145
|
-
*
|
|
146
|
-
* Applies parsing rules:
|
|
147
|
-
* - Split on commas
|
|
148
|
-
* - Trim optional whitespace (OWS) around tokens
|
|
149
|
-
* - Lowercase all tokens
|
|
150
|
-
* - Drop empty tokens
|
|
151
|
-
* - Deduplicate
|
|
152
|
-
* - Preserve input order
|
|
153
|
-
*
|
|
154
|
-
* @param headerValue - Raw PEAC-Purpose header value
|
|
155
|
-
* @returns Array of normalized PurposeToken values
|
|
156
|
-
*/
|
|
157
|
-
function parsePurposeHeader(headerValue) {
|
|
158
|
-
if (!headerValue || typeof headerValue !== 'string') {
|
|
159
|
-
return [];
|
|
160
|
-
}
|
|
161
|
-
const seen = new Set();
|
|
162
|
-
const tokens = [];
|
|
163
|
-
for (const part of headerValue.split(',')) {
|
|
164
|
-
const normalized = normalizePurposeToken(part);
|
|
165
|
-
if (normalized.length > 0 && !seen.has(normalized)) {
|
|
166
|
-
seen.add(normalized);
|
|
167
|
-
tokens.push(normalized);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
return tokens;
|
|
171
|
-
}
|
|
172
|
-
function validatePurposeTokens(tokens) {
|
|
173
|
-
const invalidTokens = [];
|
|
174
|
-
let undeclaredPresent = false;
|
|
175
|
-
for (const token of tokens) {
|
|
176
|
-
if (isUndeclaredPurpose(token)) {
|
|
177
|
-
undeclaredPresent = true;
|
|
178
|
-
}
|
|
179
|
-
if (!isValidPurposeToken(token)) {
|
|
180
|
-
invalidTokens.push(token);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
return {
|
|
184
|
-
valid: invalidTokens.length === 0 && !undeclaredPresent,
|
|
185
|
-
tokens,
|
|
186
|
-
invalidTokens,
|
|
187
|
-
undeclaredPresent,
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* Derive known canonical purposes from declared tokens
|
|
192
|
-
*
|
|
193
|
-
* Filters purpose_declared to get only canonical purposes.
|
|
194
|
-
* This is a helper derivation, NOT stored on wire.
|
|
195
|
-
*
|
|
196
|
-
* @param declared - Array of declared PurposeTokens
|
|
197
|
-
* @returns Array of CanonicalPurpose tokens
|
|
198
|
-
*/
|
|
199
|
-
function deriveKnownPurposes(declared) {
|
|
200
|
-
return declared.filter(isCanonicalPurpose);
|
|
201
|
-
}
|
|
202
|
-
// ============================================================================
|
|
203
|
-
// Legacy Mapping
|
|
204
|
-
// ============================================================================
|
|
205
|
-
/**
|
|
206
|
-
* Legacy purpose to canonical mapping
|
|
207
|
-
*/
|
|
208
|
-
const LEGACY_TO_CANONICAL = {
|
|
209
|
-
crawl: 'index', // Crawl implies indexing
|
|
210
|
-
ai_input: 'inference', // RAG/grounding -> inference context
|
|
211
|
-
ai_index: 'index', // AI-powered indexing -> index
|
|
212
|
-
};
|
|
213
|
-
function mapLegacyToCanonical(legacy) {
|
|
214
|
-
const canonical = LEGACY_TO_CANONICAL[legacy];
|
|
215
|
-
return {
|
|
216
|
-
canonical,
|
|
217
|
-
mapping_note: `Mapped legacy '${legacy}' to canonical '${canonical}'`,
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* Normalize any purpose token (canonical, legacy, or unknown)
|
|
222
|
-
*
|
|
223
|
-
* Returns the canonical form if known, otherwise preserves the token.
|
|
224
|
-
*
|
|
225
|
-
* @param token - Any valid PurposeToken
|
|
226
|
-
* @returns Canonical purpose if mapped, otherwise original token
|
|
227
|
-
*/
|
|
228
|
-
function normalizeToCanonicalOrPreserve(token) {
|
|
229
|
-
if (isCanonicalPurpose(token)) {
|
|
230
|
-
return { purpose: token, mapped: false };
|
|
231
|
-
}
|
|
232
|
-
if (isLegacyPurpose(token)) {
|
|
233
|
-
return { purpose: LEGACY_TO_CANONICAL[token], mapped: true, from: token };
|
|
234
|
-
}
|
|
235
|
-
return { purpose: token, mapped: false, unknown: true };
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Determine the appropriate PurposeReason based on context
|
|
239
|
-
*
|
|
240
|
-
* This helper implements the decision logic for the audit spine:
|
|
241
|
-
* 1. If no purposes declared -> 'undeclared_default'
|
|
242
|
-
* 2. If unknown tokens present -> 'unknown_preserved'
|
|
243
|
-
* 3. Otherwise -> maps to policy decision
|
|
244
|
-
*
|
|
245
|
-
* @param context - Context for determination
|
|
246
|
-
* @returns The appropriate PurposeReason for the audit spine
|
|
247
|
-
*
|
|
248
|
-
* @example
|
|
249
|
-
* ```typescript
|
|
250
|
-
* // Missing PEAC-Purpose header
|
|
251
|
-
* determinePurposeReason({ declared: false, hasUnknownTokens: false });
|
|
252
|
-
* // => 'undeclared_default'
|
|
253
|
-
*
|
|
254
|
-
* // Has vendor-prefixed tokens
|
|
255
|
-
* determinePurposeReason({ declared: true, hasUnknownTokens: true, decision: 'allowed' });
|
|
256
|
-
* // => 'unknown_preserved'
|
|
257
|
-
*
|
|
258
|
-
* // All canonical tokens, allowed by policy
|
|
259
|
-
* determinePurposeReason({ declared: true, hasUnknownTokens: false, decision: 'allowed' });
|
|
260
|
-
* // => 'allowed'
|
|
261
|
-
* ```
|
|
262
|
-
*/
|
|
263
|
-
function determinePurposeReason(context) {
|
|
264
|
-
// Priority 1: No purposes declared
|
|
265
|
-
if (!context.declared) {
|
|
266
|
-
return 'undeclared_default';
|
|
267
|
-
}
|
|
268
|
-
// Priority 2: Unknown tokens present (preserved for forward-compat)
|
|
269
|
-
if (context.hasUnknownTokens) {
|
|
270
|
-
return 'unknown_preserved';
|
|
271
|
-
}
|
|
272
|
-
// Priority 3: Map policy decision to reason
|
|
273
|
-
const decision = context.decision ?? 'allowed';
|
|
274
|
-
switch (decision) {
|
|
275
|
-
case 'allowed':
|
|
276
|
-
return 'allowed';
|
|
277
|
-
case 'constrained':
|
|
278
|
-
return 'constrained';
|
|
279
|
-
case 'denied':
|
|
280
|
-
return 'denied';
|
|
281
|
-
case 'downgraded':
|
|
282
|
-
return 'downgraded';
|
|
283
|
-
default:
|
|
284
|
-
return 'allowed';
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* Check if any tokens in an array are unknown (non-canonical)
|
|
289
|
-
*
|
|
290
|
-
* @param tokens - Array of purpose tokens
|
|
291
|
-
* @returns true if any token is not a canonical purpose
|
|
292
|
-
*/
|
|
293
|
-
function hasUnknownPurposeTokens(tokens) {
|
|
294
|
-
return tokens.some((token) => !isCanonicalPurpose(token));
|
|
295
|
-
}
|
|
296
|
-
//# sourceMappingURL=purpose.js.map
|
package/dist/purpose.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"purpose.js","sourceRoot":"","sources":["../src/purpose.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AA2HH,kDAIC;AAQD,gDAEC;AAQD,0CAEC;AAQD,oDAEC;AAUD,kDAEC;AAgBD,sDAEC;AAgBD,gDAiBC;AAqBD,sDAmBC;AAWD,kDAEC;AA4BD,oDAMC;AAUD,wEAaC;AA8DD,wDAyBC;AAQD,0DAEC;AAhXD,+EAA+E;AAC/E,uBAAuB;AACvB,+EAA+E;AAE/E;;;;;;;;;;;;GAYG;AACU,QAAA,mBAAmB,GAC9B,oEAAoE,CAAC;AAEvE,yCAAyC;AAC5B,QAAA,wBAAwB,GAAG,EAAE,CAAC;AAE3C,2EAA2E;AAC9D,QAAA,8BAA8B,GAAG,EAAE,CAAC;AAEjD,qDAAqD;AACxC,QAAA,kBAAkB,GAAgC;IAC7D,OAAO;IACP,QAAQ;IACR,aAAa;IACb,WAAW;IACX,OAAO;CACC,CAAC;AAEX,kDAAkD;AACrC,QAAA,eAAe,GAA6B;IACvD,SAAS;I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