ADAPT-Chase commited on
Commit
7f300d1
·
verified ·
1 Parent(s): 79a7441

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/ajv-compiler/.github/tests_checker.yml +8 -0
  2. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/ajv-compiler/.github/workflows/ci.yml +26 -0
  3. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/ajv-compiler/lib/default-ajv-options.js +14 -0
  4. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/ajv-compiler/lib/serializer-compiler.js +27 -0
  5. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/ajv-compiler/lib/validator-compiler.js +58 -0
  6. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/ajv-compiler/test/.gitkeep +0 -0
  7. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/ajv-compiler/test/duplicated-id-compile.test.js +59 -0
  8. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/ajv-compiler/test/index.test.js +307 -0
  9. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/ajv-compiler/test/plugins.test.js +264 -0
  10. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/ajv-compiler/test/serialization.test.js +279 -0
  11. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/ajv-compiler/test/standalone.test.js +203 -0
  12. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/ajv-compiler/types/index.d.ts +72 -0
  13. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/ajv-compiler/types/index.test-d.ts +226 -0
  14. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/cors/.github/dependabot.yml +13 -0
  15. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/cors/.github/stale.yml +21 -0
  16. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/cors/.github/workflows/ci.yml +28 -0
  17. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/cors/benchmark/package.json +15 -0
  18. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/cors/benchmark/vary.js +34 -0
  19. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/cors/test/cors.test.js +1052 -0
  20. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/cors/test/hooks.test.js +787 -0
  21. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/cors/test/preflight.test.js +590 -0
  22. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/cors/test/vary.test.js +237 -0
  23. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/cors/types/index.d.ts +126 -0
  24. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/cors/types/index.test-d.ts +388 -0
  25. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/error/.github/dependabot.yml +13 -0
  26. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/error/.github/workflows/ci.yml +28 -0
  27. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/error/benchmarks/create.js +9 -0
  28. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/error/benchmarks/instantiate.js +18 -0
  29. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/error/benchmarks/no-stack.js +13 -0
  30. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/error/benchmarks/toString.js +11 -0
  31. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/error/test/index.test.js +232 -0
  32. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/error/test/instanceof.test.js +263 -0
  33. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/error/types/index.d.ts +49 -0
  34. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/error/types/index.test-d.ts +92 -0
  35. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/fast-json-stringify-compiler/.github/dependabot.yml +13 -0
  36. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/fast-json-stringify-compiler/.github/workflows/ci.yml +28 -0
  37. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/fast-json-stringify-compiler/test/duplicate-schema.test.js +26 -0
  38. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/fast-json-stringify-compiler/test/plugin.test.js +78 -0
  39. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/fast-json-stringify-compiler/test/standalone.test.js +230 -0
  40. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/fast-json-stringify-compiler/types/index.d.ts +41 -0
  41. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/fast-json-stringify-compiler/types/index.test-d.ts +142 -0
  42. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/forwarded/types/index.d.ts +14 -0
  43. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/merge-json-schemas/.github/dependabot.yml +13 -0
  44. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/merge-json-schemas/.github/workflows/ci.yml +23 -0
  45. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/merge-json-schemas/lib/errors.js +36 -0
  46. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/merge-json-schemas/lib/resolvers.js +127 -0
  47. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/merge-json-schemas/test/additional-items.test.js +164 -0
  48. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/merge-json-schemas/test/additional-properties.test.js +129 -0
  49. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/merge-json-schemas/test/all-of.test.js +43 -0
  50. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/merge-json-schemas/test/any-of.test.js +81 -0
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/ajv-compiler/.github/tests_checker.yml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ comment: |
2
+ Hello! Thank you for contributing!
3
+ It appears that you have changed the code, but the tests that verify your change are missing. Could you please add them?
4
+ fileExtensions:
5
+ - '.ts'
6
+ - '.js'
7
+
8
+ testDir: 'test'
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/ajv-compiler/.github/workflows/ci.yml ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ - master
8
+ - next
9
+ - 'v*'
10
+ paths-ignore:
11
+ - 'docs/**'
12
+ - '*.md'
13
+ pull_request:
14
+ paths-ignore:
15
+ - 'docs/**'
16
+ - '*.md'
17
+
18
+ env:
19
+ TZ: 'UTC'
20
+
21
+ jobs:
22
+ test:
23
+ uses: fastify/workflows/.github/workflows/plugins-ci.yml@v5
24
+ with:
25
+ lint: true
26
+ license-check: true
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/ajv-compiler/lib/default-ajv-options.js ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict'
2
+
3
+ const fastUri = require('fast-uri')
4
+
5
+ module.exports = Object.freeze({
6
+ coerceTypes: 'array',
7
+ useDefaults: true,
8
+ removeAdditional: true,
9
+ uriResolver: fastUri,
10
+ addUsedSchema: false,
11
+ // Explicitly set allErrors to `false`.
12
+ // When set to `true`, a DoS attack is possible.
13
+ allErrors: false
14
+ })
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/ajv-compiler/lib/serializer-compiler.js ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict'
2
+
3
+ const AjvJTD = require('ajv/dist/jtd')
4
+
5
+ const defaultAjvOptions = require('./default-ajv-options')
6
+
7
+ class SerializerCompiler {
8
+ constructor (_externalSchemas, options) {
9
+ this.ajv = new AjvJTD(Object.assign({}, defaultAjvOptions, options))
10
+
11
+ /**
12
+ * https://ajv.js.org/json-type-definition.html#ref-form
13
+ * Unlike JSON Schema, JTD does not allow to reference:
14
+ * - any schema fragment other than root level definitions member
15
+ * - root of the schema - there is another way to define a self-recursive schema (see Example 2)
16
+ * - another schema file (but you can still combine schemas from multiple files using JavaScript).
17
+ *
18
+ * So we ignore the externalSchemas parameter.
19
+ */
20
+ }
21
+
22
+ buildSerializerFunction ({ schema/*, method, url, httpStatus */ }) {
23
+ return this.ajv.compileSerializer(schema)
24
+ }
25
+ }
26
+
27
+ module.exports = SerializerCompiler
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/ajv-compiler/lib/validator-compiler.js ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict'
2
+
3
+ const Ajv = require('ajv').default
4
+ const AjvJTD = require('ajv/dist/jtd')
5
+
6
+ const defaultAjvOptions = require('./default-ajv-options')
7
+
8
+ class ValidatorCompiler {
9
+ constructor (externalSchemas, options) {
10
+ // This instance of Ajv is private
11
+ // it should not be customized or used
12
+ if (options.mode === 'JTD') {
13
+ this.ajv = new AjvJTD(Object.assign({}, defaultAjvOptions, options.customOptions))
14
+ } else {
15
+ this.ajv = new Ajv(Object.assign({}, defaultAjvOptions, options.customOptions))
16
+ }
17
+
18
+ let addFormatPlugin = true
19
+ if (options.plugins && options.plugins.length > 0) {
20
+ for (const plugin of options.plugins) {
21
+ if (Array.isArray(plugin)) {
22
+ addFormatPlugin = addFormatPlugin && plugin[0].name !== 'formatsPlugin'
23
+ plugin[0](this.ajv, plugin[1])
24
+ } else {
25
+ addFormatPlugin = addFormatPlugin && plugin.name !== 'formatsPlugin'
26
+ plugin(this.ajv)
27
+ }
28
+ }
29
+ }
30
+
31
+ if (addFormatPlugin) {
32
+ require('ajv-formats')(this.ajv)
33
+ }
34
+
35
+ options.onCreate?.(this.ajv)
36
+
37
+ const sourceSchemas = Object.values(externalSchemas)
38
+ for (const extSchema of sourceSchemas) {
39
+ this.ajv.addSchema(extSchema)
40
+ }
41
+ }
42
+
43
+ buildValidatorFunction ({ schema/*, method, url, httpPart */ }) {
44
+ // Ajv does not support compiling two schemas with the same
45
+ // id inside the same instance. Therefore if we have already
46
+ // compiled the schema with the given id, we just return it.
47
+ if (schema.$id) {
48
+ const stored = this.ajv.getSchema(schema.$id)
49
+ if (stored) {
50
+ return stored
51
+ }
52
+ }
53
+
54
+ return this.ajv.compile(schema)
55
+ }
56
+ }
57
+
58
+ module.exports = ValidatorCompiler
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/ajv-compiler/test/.gitkeep ADDED
File without changes
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/ajv-compiler/test/duplicated-id-compile.test.js ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict'
2
+
3
+ const t = require('tap')
4
+ const AjvCompiler = require('../index')
5
+
6
+ const postSchema = Object.freeze({
7
+ $schema: 'http://json-schema.org/draft-07/schema#',
8
+ type: 'object',
9
+ $id: 'http://mydomain.com/user',
10
+ title: 'User schema',
11
+ description: 'Contains all user fields',
12
+ properties: {
13
+ username: { type: 'string', minLength: 4 },
14
+ firstName: { type: 'string', minLength: 1 },
15
+ lastName: { type: 'string', minLength: 1 },
16
+ email: { type: 'string' },
17
+ password: { type: 'string', minLength: 6 },
18
+ bio: { type: 'string' }
19
+ },
20
+ required: ['username', 'firstName', 'lastName', 'email', 'bio', 'password']
21
+ })
22
+
23
+ const patchSchema = Object.freeze({
24
+ $schema: 'http://json-schema.org/draft-07/schema#',
25
+ type: 'object',
26
+ $id: 'http://mydomain.com/user',
27
+ title: 'User schema',
28
+ description: 'Contains all user fields',
29
+ properties: {
30
+ firstName: { type: 'string', minLength: 1 },
31
+ lastName: { type: 'string', minLength: 1 },
32
+ bio: { type: 'string' }
33
+ }
34
+ })
35
+
36
+ const fastifyAjvOptionsDefault = Object.freeze({
37
+ customOptions: {}
38
+ })
39
+
40
+ t.test('must not store schema on compile', t => {
41
+ t.plan(4)
42
+ const factory = AjvCompiler()
43
+ const compiler = factory({}, fastifyAjvOptionsDefault)
44
+ const postFn = compiler({ schema: postSchema })
45
+ const patchFn = compiler({ schema: patchSchema })
46
+
47
+ const resultForPost = postFn({})
48
+ t.equal(resultForPost, false)
49
+ t.has(postFn.errors, [
50
+ {
51
+ keyword: 'required',
52
+ message: "must have required property 'username'"
53
+ }
54
+ ])
55
+
56
+ const resultForPatch = patchFn({})
57
+ t.ok(resultForPatch)
58
+ t.notOk(patchFn.errors)
59
+ })
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/ajv-compiler/test/index.test.js ADDED
@@ -0,0 +1,307 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict'
2
+
3
+ const t = require('tap')
4
+ const fastify = require('fastify')
5
+ const AjvCompiler = require('../index')
6
+
7
+ const sym = Symbol.for('fastify.ajv-compiler.reference')
8
+
9
+ const sampleSchema = Object.freeze({
10
+ $id: 'example1',
11
+ type: 'object',
12
+ properties: {
13
+ name: { type: 'string' }
14
+ }
15
+ })
16
+
17
+ const externalSchemas1 = Object.freeze({})
18
+ const externalSchemas2 = Object.freeze({
19
+ foo: {
20
+ $id: 'foo',
21
+ type: 'object',
22
+ properties: {
23
+ name: { type: 'string' }
24
+ }
25
+ }
26
+ })
27
+
28
+ const fastifyAjvOptionsDefault = Object.freeze({
29
+ customOptions: {}
30
+ })
31
+
32
+ const fastifyJtdDefault = Object.freeze({
33
+ customOptions: { },
34
+ mode: 'JTD'
35
+ })
36
+
37
+ const fastifyAjvOptionsCustom = Object.freeze({
38
+ customOptions: {
39
+ allErrors: true,
40
+ removeAdditional: false
41
+ },
42
+ plugins: [
43
+ require('ajv-formats'),
44
+ [require('ajv-errors'), { singleError: false }]
45
+ ]
46
+ })
47
+
48
+ t.test('basic usage', t => {
49
+ t.plan(1)
50
+ const factory = AjvCompiler()
51
+ const compiler = factory(externalSchemas1, fastifyAjvOptionsDefault)
52
+ const validatorFunc = compiler({ schema: sampleSchema })
53
+ const result = validatorFunc({ name: 'hello' })
54
+ t.equal(result, true)
55
+ })
56
+
57
+ t.test('array coercion', t => {
58
+ t.plan(2)
59
+ const factory = AjvCompiler()
60
+ const compiler = factory(externalSchemas1, fastifyAjvOptionsDefault)
61
+
62
+ const arraySchema = {
63
+ $id: 'example1',
64
+ type: 'object',
65
+ properties: {
66
+ name: { type: 'array', items: { type: 'string' } }
67
+ }
68
+ }
69
+
70
+ const validatorFunc = compiler({ schema: arraySchema })
71
+
72
+ const inputObj = { name: 'hello' }
73
+ t.equal(validatorFunc(inputObj), true)
74
+ t.same(inputObj, { name: ['hello'] }, 'the name property should be coerced to an array')
75
+ })
76
+
77
+ t.test('nullable default', t => {
78
+ t.plan(2)
79
+ const factory = AjvCompiler()
80
+ const compiler = factory({}, fastifyAjvOptionsDefault)
81
+ const validatorFunc = compiler({
82
+ schema: {
83
+ type: 'object',
84
+ properties: {
85
+ nullable: { type: 'string', nullable: true },
86
+ notNullable: { type: 'string' }
87
+ }
88
+ }
89
+ })
90
+ const input = { nullable: null, notNullable: null }
91
+ const result = validatorFunc(input)
92
+ t.equal(result, true)
93
+ t.same(input, { nullable: null, notNullable: '' }, 'the notNullable field has been coerced')
94
+ })
95
+
96
+ t.test('plugin loading', t => {
97
+ t.plan(3)
98
+ const factory = AjvCompiler()
99
+ const compiler = factory(externalSchemas1, fastifyAjvOptionsCustom)
100
+ const validatorFunc = compiler({
101
+ schema: {
102
+ type: 'object',
103
+ properties: {
104
+ q: {
105
+ type: 'string',
106
+ format: 'date',
107
+ formatMinimum: '2016-02-06',
108
+ formatExclusiveMaximum: '2016-12-27'
109
+ }
110
+ },
111
+ required: ['q'],
112
+ errorMessage: 'hello world'
113
+ }
114
+ })
115
+ const result = validatorFunc({ q: '2016-10-02' })
116
+ t.equal(result, true)
117
+
118
+ const resultFail = validatorFunc({})
119
+ t.equal(resultFail, false)
120
+ t.equal(validatorFunc.errors[0].message, 'hello world')
121
+ })
122
+
123
+ t.test('optimization - cache ajv instance', t => {
124
+ t.plan(5)
125
+ const factory = AjvCompiler()
126
+ const compiler1 = factory(externalSchemas1, fastifyAjvOptionsDefault)
127
+ const compiler2 = factory(externalSchemas1, fastifyAjvOptionsDefault)
128
+ t.equal(compiler1, compiler2, 'same instance')
129
+ t.same(compiler1, compiler2, 'same instance')
130
+
131
+ const compiler3 = factory(externalSchemas2, fastifyAjvOptionsDefault)
132
+ t.not(compiler3, compiler1, 'new ajv instance when externa schema change')
133
+
134
+ const compiler4 = factory(externalSchemas1, fastifyAjvOptionsCustom)
135
+ t.not(compiler4, compiler1, 'new ajv instance when externa schema change')
136
+ t.not(compiler4, compiler3, 'new ajv instance when externa schema change')
137
+ })
138
+
139
+ t.test('the onCreate callback can enhance the ajv instance', t => {
140
+ t.plan(2)
141
+ const factory = AjvCompiler()
142
+
143
+ const fastifyAjvCustomOptionsFormats = Object.freeze({
144
+ onCreate (ajv) {
145
+ for (const [formatName, format] of Object.entries(this.customOptions.formats)) {
146
+ ajv.addFormat(formatName, format)
147
+ }
148
+ },
149
+ customOptions: {
150
+ formats: {
151
+ date: /foo/
152
+ }
153
+ }
154
+ })
155
+
156
+ const compiler1 = factory(externalSchemas1, fastifyAjvCustomOptionsFormats)
157
+ const validatorFunc = compiler1({
158
+ schema: {
159
+ type: 'string',
160
+ format: 'date'
161
+ }
162
+ })
163
+ const result = validatorFunc('foo')
164
+ t.equal(result, true)
165
+
166
+ const resultFail = validatorFunc('2016-10-02')
167
+ t.equal(resultFail, false)
168
+ })
169
+
170
+ // https://github.com/fastify/fastify/pull/2969
171
+ t.test('compile same $id when in external schema', t => {
172
+ t.plan(3)
173
+ const factory = AjvCompiler()
174
+
175
+ const base = {
176
+ $id: 'urn:schema:base',
177
+ definitions: {
178
+ hello: { type: 'string' }
179
+ },
180
+ type: 'object',
181
+ properties: {
182
+ hello: { $ref: '#/definitions/hello' }
183
+ }
184
+ }
185
+
186
+ const refSchema = {
187
+ $id: 'urn:schema:ref',
188
+ type: 'object',
189
+ properties: {
190
+ hello: { $ref: 'urn:schema:base#/definitions/hello' }
191
+ }
192
+ }
193
+
194
+ const compiler = factory({
195
+ [base.$id]: base,
196
+ [refSchema.$id]: refSchema
197
+
198
+ }, fastifyAjvOptionsDefault)
199
+
200
+ t.notOk(compiler[sym], 'the ajv reference do not exists if code is not activated')
201
+
202
+ const validatorFunc1 = compiler({
203
+ schema: {
204
+ $id: 'urn:schema:ref'
205
+ }
206
+ })
207
+
208
+ const validatorFunc2 = compiler({
209
+ schema: {
210
+ $id: 'urn:schema:ref'
211
+ }
212
+ })
213
+
214
+ t.pass('the compile does not fail if the schema compiled is already in the external schemas')
215
+ t.equal(validatorFunc1, validatorFunc2, 'the returned function is the same')
216
+ })
217
+
218
+ t.test('JTD MODE', t => {
219
+ t.plan(2)
220
+
221
+ t.test('compile jtd schema', t => {
222
+ t.plan(4)
223
+ const factory = AjvCompiler()
224
+
225
+ const jtdSchema = {
226
+ discriminator: 'version',
227
+ mapping: {
228
+ 1: {
229
+ properties: {
230
+ foo: { type: 'uint8' }
231
+ }
232
+ },
233
+ 2: {
234
+ properties: {
235
+ foo: { type: 'string' }
236
+ }
237
+ }
238
+ }
239
+ }
240
+
241
+ const compiler = factory({}, fastifyJtdDefault)
242
+ const validatorFunc = compiler({ schema: jtdSchema })
243
+ t.pass('generated validation function for JTD SCHEMA')
244
+
245
+ const result = validatorFunc({
246
+ version: '2',
247
+ foo: []
248
+ })
249
+ t.notOk(result, 'failed validation')
250
+ t.type(validatorFunc.errors, 'Array')
251
+
252
+ const success = validatorFunc({
253
+ version: '1',
254
+ foo: 42
255
+ })
256
+ t.ok(success)
257
+ })
258
+
259
+ t.test('fastify integration', async t => {
260
+ const factory = AjvCompiler()
261
+
262
+ const app = fastify({
263
+ jsonShorthand: false,
264
+ ajv: {
265
+ customOptions: { },
266
+ mode: 'JTD'
267
+ },
268
+ schemaController: {
269
+ compilersFactory: {
270
+ buildValidator: factory
271
+ }
272
+ }
273
+ })
274
+
275
+ app.post('/', {
276
+ schema: {
277
+ body: {
278
+ discriminator: 'version',
279
+ mapping: {
280
+ 1: {
281
+ properties: {
282
+ foo: { type: 'uint8' }
283
+ }
284
+ },
285
+ 2: {
286
+ properties: {
287
+ foo: { type: 'string' }
288
+ }
289
+ }
290
+ }
291
+ }
292
+ }
293
+ }, () => {})
294
+
295
+ const res = await app.inject({
296
+ url: '/',
297
+ method: 'POST',
298
+ payload: {
299
+ version: '1',
300
+ foo: 'this is not a number'
301
+ }
302
+ })
303
+
304
+ t.equal(res.statusCode, 400)
305
+ t.equal(res.json().message, 'body/foo must be uint8')
306
+ })
307
+ })
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/ajv-compiler/test/plugins.test.js ADDED
@@ -0,0 +1,264 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict'
2
+
3
+ const t = require('tap')
4
+ const fastify = require('fastify')
5
+ const AjvCompiler = require('../index')
6
+
7
+ const ajvFormats = require('ajv-formats')
8
+ const ajvErrors = require('ajv-errors')
9
+ const localize = require('ajv-i18n')
10
+
11
+ t.test('Format Baseline test', async (t) => {
12
+ const app = buildApplication({
13
+ customOptions: {
14
+ validateFormats: false
15
+ }
16
+ })
17
+
18
+ const res = await app.inject({
19
+ url: '/hello',
20
+ headers: {
21
+ 'x-foo': 'hello',
22
+ 'x-date': 'not a date',
23
+ 'x-email': 'not an email'
24
+ },
25
+ query: {
26
+ foo: 'hello',
27
+ date: 'not a date',
28
+ email: 'not an email'
29
+ }
30
+ })
31
+ t.equal(res.statusCode, 200, 'format validation does not apply as configured')
32
+ t.equal(res.payload, 'hello')
33
+ })
34
+
35
+ t.test('Custom Format plugin loading test', (t) => {
36
+ t.plan(6)
37
+ const app = buildApplication({
38
+ customOptions: {
39
+ validateFormats: true
40
+ },
41
+ plugins: [[ajvFormats, { mode: 'fast' }]]
42
+ })
43
+
44
+ app.inject('/hello', (err, res) => {
45
+ t.error(err)
46
+ t.equal(res.statusCode, 400, 'format validation applies')
47
+ })
48
+
49
+ app.inject('/2ad0612c-7578-4b18-9a6f-579863f40e0b', (err, res) => {
50
+ t.error(err)
51
+ t.equal(res.statusCode, 400, 'format validation applies')
52
+ })
53
+
54
+ app.inject({
55
+ url: '/2ad0612c-7578-4b18-9a6f-579863f40e0b',
56
+ headers: {
57
+ 'x-foo': 'hello',
58
+ 'x-date': new Date().toISOString(),
59
+ 'x-email': 'foo@bar.baz'
60
+ },
61
+ query: {
62
+ foo: 'hello',
63
+ date: new Date().toISOString(),
64
+ email: 'foo@bar.baz'
65
+ }
66
+ }, (err, res) => {
67
+ t.error(err)
68
+ t.equal(res.statusCode, 200)
69
+ })
70
+ })
71
+
72
+ t.test('Format plugin set by default test', (t) => {
73
+ t.plan(6)
74
+ const app = buildApplication({})
75
+
76
+ app.inject('/hello', (err, res) => {
77
+ t.error(err)
78
+ t.equal(res.statusCode, 400, 'format validation applies')
79
+ })
80
+
81
+ app.inject('/2ad0612c-7578-4b18-9a6f-579863f40e0b', (err, res) => {
82
+ t.error(err)
83
+ t.equal(res.statusCode, 400, 'format validation applies')
84
+ })
85
+
86
+ app.inject({
87
+ url: '/2ad0612c-7578-4b18-9a6f-579863f40e0b',
88
+ headers: {
89
+ 'x-foo': 'hello',
90
+ 'x-date': new Date().toISOString(),
91
+ 'x-email': 'foo@bar.baz'
92
+ },
93
+ query: {
94
+ foo: 'hello',
95
+ date: new Date().toISOString(),
96
+ email: 'foo@bar.baz'
97
+ }
98
+ }, (err, res) => {
99
+ t.error(err)
100
+ t.equal(res.statusCode, 200)
101
+ })
102
+ })
103
+
104
+ t.test('Custom error messages', (t) => {
105
+ t.plan(9)
106
+
107
+ const app = buildApplication({
108
+ customOptions: {
109
+ removeAdditional: false,
110
+ allErrors: true
111
+ },
112
+ plugins: [ajvFormats, ajvErrors]
113
+ })
114
+
115
+ const errorMessage = {
116
+ required: 'custom miss',
117
+ type: 'custom type', // will not replace internal "type" error for the property "foo"
118
+ _: 'custom type', // this prop will do it
119
+ additionalProperties: 'custom too many params'
120
+ }
121
+
122
+ app.post('/', {
123
+ handler: () => { t.fail('dont call me') },
124
+ schema: {
125
+ body: {
126
+ type: 'object',
127
+ required: ['foo'],
128
+ properties: {
129
+ foo: { type: 'integer' }
130
+ },
131
+ additionalProperties: false,
132
+ errorMessage
133
+ }
134
+ }
135
+ })
136
+
137
+ app.inject({
138
+ url: '/',
139
+ method: 'post',
140
+ payload: {}
141
+ }, (err, res) => {
142
+ t.error(err)
143
+ t.equal(res.statusCode, 400)
144
+ t.match(res.json().message, errorMessage.required)
145
+ })
146
+
147
+ app.inject({
148
+ url: '/',
149
+ method: 'post',
150
+ payload: { foo: 'not a number' }
151
+ }, (err, res) => {
152
+ t.error(err)
153
+ t.equal(res.statusCode, 400)
154
+ t.match(res.json().message, errorMessage.type)
155
+ })
156
+
157
+ app.inject({
158
+ url: '/',
159
+ method: 'post',
160
+ payload: { foo: 3, bar: 'ops' }
161
+ }, (err, res) => {
162
+ t.error(err)
163
+ t.equal(res.statusCode, 400)
164
+ t.match(res.json().message, errorMessage.additionalProperties)
165
+ })
166
+ })
167
+
168
+ t.test('Custom i18n error messages', (t) => {
169
+ t.plan(3)
170
+
171
+ const app = buildApplication({
172
+ customOptions: {
173
+ allErrors: true,
174
+ messages: false
175
+ },
176
+ plugins: [ajvFormats]
177
+ })
178
+
179
+ app.post('/', {
180
+ handler: () => { t.fail('dont call me') },
181
+ schema: {
182
+ body: {
183
+ type: 'object',
184
+ required: ['foo'],
185
+ properties: {
186
+ foo: { type: 'integer' }
187
+ }
188
+ }
189
+ }
190
+ })
191
+
192
+ app.setErrorHandler((error, request, reply) => {
193
+ t.pass('Error handler executed')
194
+ if (error.validation) {
195
+ localize.ru(error.validation)
196
+ reply.status(400).send(error.validation)
197
+ return
198
+ }
199
+ t.fail('not other errors')
200
+ })
201
+
202
+ app.inject({
203
+ method: 'POST',
204
+ url: '/',
205
+ payload: {
206
+ foo: 'string'
207
+ }
208
+ }, (err, res) => {
209
+ t.error(err)
210
+ t.equal(res.json()[0].message, 'должно быть integer')
211
+ })
212
+ })
213
+
214
+ function buildApplication (ajvOptions) {
215
+ const factory = AjvCompiler()
216
+
217
+ const app = fastify({
218
+ ajv: ajvOptions,
219
+ schemaController: {
220
+ compilersFactory: {
221
+ buildValidator: factory
222
+ }
223
+ }
224
+ })
225
+
226
+ app.get('/:id', {
227
+ schema: {
228
+ headers: {
229
+ type: 'object',
230
+ required: [
231
+ 'x-foo',
232
+ 'x-date',
233
+ 'x-email'
234
+ ],
235
+ properties: {
236
+ 'x-foo': { type: 'string' },
237
+ 'x-date': { type: 'string', format: 'date-time' },
238
+ 'x-email': { type: 'string', format: 'email' }
239
+ }
240
+ },
241
+ query: {
242
+ type: 'object',
243
+ required: [
244
+ 'foo',
245
+ 'date',
246
+ 'email'
247
+ ],
248
+ properties: {
249
+ foo: { type: 'string' },
250
+ date: { type: 'string', format: 'date-time' },
251
+ email: { type: 'string', format: 'email' }
252
+ }
253
+ },
254
+ params: {
255
+ type: 'object',
256
+ properties: {
257
+ id: { type: 'string', format: 'uuid' }
258
+ }
259
+ }
260
+ }
261
+ }, async () => 'hello')
262
+
263
+ return app
264
+ }
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/ajv-compiler/test/serialization.test.js ADDED
@@ -0,0 +1,279 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict'
2
+
3
+ const t = require('tap')
4
+ const fastify = require('fastify')
5
+ const AjvCompiler = require('../index')
6
+
7
+ const jtdSchema = {
8
+ discriminator: 'version',
9
+ mapping: {
10
+ 1: {
11
+ properties: {
12
+ foo: { type: 'uint8' }
13
+ }
14
+ },
15
+ 2: {
16
+ properties: {
17
+ foo: { type: 'string' }
18
+ }
19
+ }
20
+ }
21
+ }
22
+
23
+ const externalSchemas1 = Object.freeze({})
24
+ const externalSchemas2 = Object.freeze({
25
+ foo: {
26
+ definitions: {
27
+ coordinates: {
28
+ properties: {
29
+ lat: { type: 'float32' },
30
+ lng: { type: 'float32' }
31
+ }
32
+ }
33
+ }
34
+ }
35
+ })
36
+
37
+ const fastifyAjvOptionsDefault = Object.freeze({
38
+ customOptions: {}
39
+ })
40
+
41
+ t.test('basic serializer usage', t => {
42
+ t.plan(4)
43
+ const factory = AjvCompiler({ jtdSerializer: true })
44
+ const compiler = factory(externalSchemas1, fastifyAjvOptionsDefault)
45
+ const serializeFunc = compiler({ schema: jtdSchema })
46
+ t.equal(serializeFunc({ version: '1', foo: 42 }), '{"version":"1","foo":42}')
47
+ t.equal(serializeFunc({ version: '2', foo: 'hello' }), '{"version":"2","foo":"hello"}')
48
+ t.equal(serializeFunc({ version: '3', foo: 'hello' }), '{"version":"3"}')
49
+ t.equal(serializeFunc({ version: '2', foo: ['not', 1, { string: 'string' }] }), '{"version":"2","foo":"not,1,[object Object]"}')
50
+ })
51
+
52
+ t.test('external schemas are ignored', t => {
53
+ t.plan(1)
54
+ const factory = AjvCompiler({ jtdSerializer: true })
55
+ const compiler = factory(externalSchemas2, fastifyAjvOptionsDefault)
56
+ const serializeFunc = compiler({
57
+ schema: {
58
+ definitions: {
59
+ coordinates: {
60
+ properties: {
61
+ lat: { type: 'float32' },
62
+ lng: { type: 'float32' }
63
+ }
64
+ }
65
+ },
66
+ properties: {
67
+ userLoc: { ref: 'coordinates' },
68
+ serverLoc: { ref: 'coordinates' }
69
+ }
70
+ }
71
+ })
72
+ t.equal(serializeFunc(
73
+ { userLoc: { lat: 50, lng: -90 }, serverLoc: { lat: -15, lng: 50 } }),
74
+ '{"userLoc":{"lat":50,"lng":-90},"serverLoc":{"lat":-15,"lng":50}}'
75
+ )
76
+ })
77
+
78
+ t.test('fastify integration within JTD serializer', async t => {
79
+ const factoryValidator = AjvCompiler()
80
+ const factorySerializer = AjvCompiler({ jtdSerializer: true })
81
+
82
+ const app = fastify({
83
+ jsonShorthand: false,
84
+ ajv: {
85
+ customOptions: { },
86
+ mode: 'JTD'
87
+ },
88
+ schemaController: {
89
+ compilersFactory: {
90
+ buildValidator: factoryValidator,
91
+ buildSerializer: factorySerializer
92
+ }
93
+ }
94
+ })
95
+
96
+ app.post('/', {
97
+ schema: {
98
+ body: jtdSchema,
99
+ response: {
100
+ 200: {
101
+ properties: {
102
+ id: { type: 'string' },
103
+ createdAt: { type: 'timestamp' },
104
+ karma: { type: 'int32' },
105
+ isAdmin: { type: 'boolean' }
106
+ }
107
+ },
108
+ 400: jtdSchema
109
+ }
110
+ }
111
+ }, async () => {
112
+ return {
113
+ id: '123',
114
+ createdAt: new Date('1999-01-31T23:00:00.000Z'),
115
+ karma: 42,
116
+ isAdmin: true,
117
+ remove: 'me'
118
+ }
119
+ })
120
+
121
+ {
122
+ const res = await app.inject({
123
+ url: '/',
124
+ method: 'POST',
125
+ payload: {
126
+ version: '1',
127
+ foo: 'not a number'
128
+ }
129
+ })
130
+
131
+ t.equal(res.statusCode, 400)
132
+ t.same(res.json(), { version: 'undefined' })
133
+ }
134
+
135
+ {
136
+ const res = await app.inject({
137
+ url: '/',
138
+ method: 'POST',
139
+ payload: {
140
+ version: '1',
141
+ foo: 32
142
+ }
143
+ })
144
+
145
+ t.equal(res.statusCode, 200)
146
+ t.same(res.json(), {
147
+ id: '123',
148
+ createdAt: '1999-01-31T23:00:00.000Z',
149
+ karma: 42,
150
+ isAdmin: true
151
+ })
152
+ }
153
+ })
154
+
155
+ t.test('fastify integration and cached serializer', async t => {
156
+ const factoryValidator = AjvCompiler()
157
+ const factorySerializer = AjvCompiler({ jtdSerializer: true })
158
+
159
+ const app = fastify({
160
+ jsonShorthand: false,
161
+ ajv: {
162
+ customOptions: { },
163
+ mode: 'JTD'
164
+ },
165
+ schemaController: {
166
+ compilersFactory: {
167
+ buildValidator: factoryValidator,
168
+ buildSerializer: factorySerializer
169
+ }
170
+ }
171
+ })
172
+
173
+ app.register(async function plugin (app, opts) {
174
+ app.post('/', {
175
+ schema: {
176
+ body: jtdSchema,
177
+ response: {
178
+ 200: {
179
+ properties: {
180
+ id: { type: 'string' },
181
+ createdAt: { type: 'timestamp' },
182
+ karma: { type: 'int32' },
183
+ isAdmin: { type: 'boolean' }
184
+ }
185
+ },
186
+ 400: jtdSchema
187
+ }
188
+ }
189
+ }, async () => {
190
+ return {
191
+ id: '123',
192
+ createdAt: new Date('1999-01-31T23:00:00.000Z'),
193
+ karma: 42,
194
+ isAdmin: true,
195
+ remove: 'me'
196
+ }
197
+ })
198
+ })
199
+
200
+ app.register(async function plugin (app, opts) {
201
+ app.post('/two', {
202
+ schema: {
203
+ body: jtdSchema,
204
+ response: {
205
+ 400: jtdSchema
206
+ }
207
+ }
208
+ }, () => {})
209
+ })
210
+
211
+ {
212
+ const res = await app.inject({
213
+ url: '/',
214
+ method: 'POST',
215
+ payload: {
216
+ version: '1',
217
+ foo: 'not a number'
218
+ }
219
+ })
220
+
221
+ t.equal(res.statusCode, 400)
222
+ t.same(res.json(), { version: 'undefined' })
223
+ }
224
+
225
+ {
226
+ const res = await app.inject({
227
+ url: '/',
228
+ method: 'POST',
229
+ payload: {
230
+ version: '1',
231
+ foo: 32
232
+ }
233
+ })
234
+
235
+ t.equal(res.statusCode, 200)
236
+ t.same(res.json(), {
237
+ id: '123',
238
+ createdAt: '1999-01-31T23:00:00.000Z',
239
+ karma: 42,
240
+ isAdmin: true
241
+ })
242
+ }
243
+ })
244
+
245
+ t.test('fastify integration within JTD serializer and custom options', async t => {
246
+ const factorySerializer = AjvCompiler({ jtdSerializer: true })
247
+
248
+ const app = fastify({
249
+ jsonShorthand: false,
250
+ serializerOpts: {
251
+ allErrors: true,
252
+ logger: 'wrong-value'
253
+ },
254
+ schemaController: {
255
+ compilersFactory: {
256
+ buildSerializer: factorySerializer
257
+ }
258
+ }
259
+ })
260
+
261
+ app.post('/', {
262
+ schema: {
263
+ response: {
264
+ 200: {
265
+ properties: {
266
+ test: { type: 'boolean' }
267
+ }
268
+ }
269
+ }
270
+ }
271
+ }, async () => { })
272
+
273
+ try {
274
+ await app.ready()
275
+ t.fail('should throw')
276
+ } catch (error) {
277
+ t.equal(error.message, 'logger must implement log, warn and error methods', 'the wrong setting is forwarded to ajv/jtd')
278
+ }
279
+ })
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/ajv-compiler/test/standalone.test.js ADDED
@@ -0,0 +1,203 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict'
2
+
3
+ const fs = require('node:fs')
4
+ const path = require('node:path')
5
+ const t = require('tap')
6
+ const fastify = require('fastify')
7
+ const sanitize = require('sanitize-filename')
8
+
9
+ const { StandaloneValidator: AjvStandaloneValidator } = require('../')
10
+
11
+ function generateFileName (routeOpts) {
12
+ return `/ajv-generated-${sanitize(routeOpts.schema.$id)}-${routeOpts.method}-${routeOpts.httpPart}-${sanitize(routeOpts.url)}.js`
13
+ }
14
+
15
+ const generatedFileNames = []
16
+
17
+ t.test('standalone', t => {
18
+ t.plan(4)
19
+
20
+ t.teardown(async () => {
21
+ for (const fileName of generatedFileNames) {
22
+ await fs.promises.unlink(path.join(__dirname, fileName))
23
+ }
24
+ })
25
+
26
+ t.test('errors', t => {
27
+ t.plan(2)
28
+ t.throws(() => {
29
+ AjvStandaloneValidator()
30
+ }, 'missing restoreFunction')
31
+ t.throws(() => {
32
+ AjvStandaloneValidator({ readMode: false })
33
+ }, 'missing storeFunction')
34
+ })
35
+
36
+ t.test('generate standalone code', t => {
37
+ t.plan(5)
38
+
39
+ const base = {
40
+ $id: 'urn:schema:base',
41
+ definitions: {
42
+ hello: { type: 'string' }
43
+ },
44
+ type: 'object',
45
+ properties: {
46
+ hello: { $ref: '#/definitions/hello' }
47
+ }
48
+ }
49
+
50
+ const refSchema = {
51
+ $id: 'urn:schema:ref',
52
+ type: 'object',
53
+ properties: {
54
+ hello: { $ref: 'urn:schema:base#/definitions/hello' }
55
+ }
56
+ }
57
+
58
+ const endpointSchema = {
59
+ schema: {
60
+ $id: 'urn:schema:endpoint',
61
+ $ref: 'urn:schema:ref'
62
+ }
63
+ }
64
+
65
+ const schemaMap = {
66
+ [base.$id]: base,
67
+ [refSchema.$id]: refSchema
68
+ }
69
+
70
+ const factory = AjvStandaloneValidator({
71
+ readMode: false,
72
+ storeFunction (routeOpts, schemaValidationCode) {
73
+ t.same(routeOpts, endpointSchema)
74
+ t.type(schemaValidationCode, 'string')
75
+ fs.writeFileSync(path.join(__dirname, '/ajv-generated.js'), schemaValidationCode)
76
+ generatedFileNames.push('/ajv-generated.js')
77
+ t.pass('stored the validation function')
78
+ }
79
+ })
80
+
81
+ const compiler = factory(schemaMap)
82
+ compiler(endpointSchema)
83
+ t.pass('compiled the endpoint schema')
84
+
85
+ t.test('usage standalone code', t => {
86
+ t.plan(3)
87
+ const standaloneValidate = require('./ajv-generated')
88
+
89
+ const valid = standaloneValidate({ hello: 'world' })
90
+ t.ok(valid)
91
+
92
+ const invalid = standaloneValidate({ hello: [] })
93
+ t.notOk(invalid)
94
+
95
+ t.ok(standaloneValidate)
96
+ })
97
+ })
98
+
99
+ t.test('fastify integration - writeMode', async t => {
100
+ t.plan(6)
101
+
102
+ const factory = AjvStandaloneValidator({
103
+ readMode: false,
104
+ storeFunction (routeOpts, schemaValidationCode) {
105
+ const fileName = generateFileName(routeOpts)
106
+ t.ok(routeOpts)
107
+ fs.writeFileSync(path.join(__dirname, fileName), schemaValidationCode)
108
+ t.pass('stored the validation function')
109
+ generatedFileNames.push(fileName)
110
+ },
111
+ restoreFunction () {
112
+ t.fail('write mode ON')
113
+ }
114
+ })
115
+
116
+ const app = buildApp(factory)
117
+ await app.ready()
118
+ })
119
+
120
+ t.test('fastify integration - readMode', async t => {
121
+ t.plan(6)
122
+
123
+ const factory = AjvStandaloneValidator({
124
+ readMode: true,
125
+ storeFunction () {
126
+ t.fail('read mode ON')
127
+ },
128
+ restoreFunction (routeOpts) {
129
+ t.pass('restore the validation function')
130
+ const fileName = generateFileName(routeOpts)
131
+ return require(path.join(__dirname, fileName))
132
+ }
133
+ })
134
+
135
+ const app = buildApp(factory)
136
+ await app.ready()
137
+
138
+ let res = await app.inject({
139
+ url: '/foo',
140
+ method: 'POST',
141
+ payload: { hello: [] }
142
+ })
143
+ t.equal(res.statusCode, 400)
144
+
145
+ res = await app.inject({
146
+ url: '/bar?lang=invalid',
147
+ method: 'GET'
148
+ })
149
+ t.equal(res.statusCode, 400)
150
+
151
+ res = await app.inject({
152
+ url: '/bar?lang=it',
153
+ method: 'GET'
154
+ })
155
+ t.equal(res.statusCode, 200)
156
+ })
157
+
158
+ function buildApp (factory) {
159
+ const app = fastify({
160
+ jsonShorthand: false,
161
+ schemaController: {
162
+ compilersFactory: {
163
+ buildValidator: factory
164
+ }
165
+ }
166
+ })
167
+
168
+ app.addSchema({
169
+ $id: 'urn:schema:foo',
170
+ type: 'object',
171
+ properties: {
172
+ name: { type: 'string' },
173
+ id: { type: 'integer' }
174
+ }
175
+ })
176
+
177
+ app.post('/foo', {
178
+ schema: {
179
+ body: {
180
+ $id: 'urn:schema:body',
181
+ type: 'object',
182
+ properties: {
183
+ hello: { $ref: 'urn:schema:foo#/properties/name' }
184
+ }
185
+ }
186
+ }
187
+ }, () => { return 'ok' })
188
+
189
+ app.get('/bar', {
190
+ schema: {
191
+ query: {
192
+ $id: 'urn:schema:query',
193
+ type: 'object',
194
+ properties: {
195
+ lang: { type: 'string', enum: ['it', 'en'] }
196
+ }
197
+ }
198
+ }
199
+ }, () => { return 'ok' })
200
+
201
+ return app
202
+ }
203
+ })
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/ajv-compiler/types/index.d.ts ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import _ajv, { AnySchema, Options as AjvOptions, ValidateFunction } from 'ajv'
2
+ import AjvJTD, { JTDOptions } from 'ajv/dist/jtd'
3
+ import type { Options, ErrorObject } from 'ajv'
4
+ import { AnyValidateFunction } from 'ajv/dist/core'
5
+
6
+ type Ajv = _ajv
7
+ type AjvSerializerGenerator = typeof AjvCompiler
8
+
9
+ type AjvJTDCompile = AjvJTD['compileSerializer']
10
+ type AjvCompile = (schema: AnySchema, _meta?: boolean) => AnyValidateFunction
11
+
12
+ declare function buildCompilerFromPool (externalSchemas: { [key: string]: AnySchema | AnySchema[] }, options?: { mode: 'JTD'; customOptions?: JTDOptions; onCreate?: (ajvInstance: Ajv) => void }): AjvCompile
13
+ declare function buildCompilerFromPool (externalSchemas: { [key: string]: AnySchema | AnySchema[] }, options?: { mode?: never; customOptions?: AjvOptions; onCreate?: (ajvInstance: Ajv) => void }): AjvCompile
14
+
15
+ declare function buildSerializerFromPool (externalSchemas: any, serializerOpts?: { mode?: never; } & JTDOptions): AjvJTDCompile
16
+
17
+ declare function AjvCompiler (opts: { jtdSerializer: true }): AjvCompiler.BuildSerializerFromPool
18
+ declare function AjvCompiler (opts?: { jtdSerializer?: false }): AjvCompiler.BuildCompilerFromPool
19
+
20
+ declare function StandaloneValidator (options: AjvCompiler.StandaloneOptions): AjvCompiler.BuildCompilerFromPool
21
+
22
+ declare namespace AjvCompiler {
23
+ export type { Options, ErrorObject }
24
+ export { Ajv }
25
+
26
+ export type BuildSerializerFromPool = typeof buildSerializerFromPool
27
+
28
+ export type BuildCompilerFromPool = typeof buildCompilerFromPool
29
+
30
+ export const AjvReference: Symbol
31
+
32
+ export enum HttpParts {
33
+ Body = 'body',
34
+ Headers = 'headers',
35
+ Params = 'params',
36
+ Query = 'querystring',
37
+ }
38
+
39
+ export type RouteDefinition = {
40
+ method: string,
41
+ url: string,
42
+ httpPart: HttpParts,
43
+ schema?: unknown,
44
+ }
45
+
46
+ export type StandaloneRestoreFunction = (opts: RouteDefinition) => ValidateFunction
47
+
48
+ export type StandaloneStoreFunction = (opts: RouteDefinition, schemaValidationCode: string) => void
49
+
50
+ export type StandaloneOptionsReadModeOn = {
51
+ readMode: true;
52
+ restoreFunction?: StandaloneRestoreFunction
53
+ }
54
+
55
+ export type StandaloneOptionsReadModeOff = {
56
+ readMode?: false | undefined;
57
+ storeFunction?: StandaloneStoreFunction;
58
+ }
59
+
60
+ export type StandaloneOptions = StandaloneOptionsReadModeOn | StandaloneOptionsReadModeOff
61
+
62
+ export type ValidatorFactory = BuildCompilerFromPool | BuildSerializerFromPool
63
+
64
+ export type ValidatorCompiler = ReturnType<ValidatorFactory>
65
+
66
+ export { StandaloneValidator }
67
+
68
+ export const AjvCompiler: AjvSerializerGenerator
69
+ export { AjvCompiler as default }
70
+ }
71
+
72
+ export = AjvCompiler
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/ajv-compiler/types/index.test-d.ts ADDED
@@ -0,0 +1,226 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { AnySchemaObject, ValidateFunction } from 'ajv'
2
+ import { AnyValidateFunction } from 'ajv/dist/core'
3
+ import { expectAssignable, expectType } from 'tsd'
4
+ import AjvCompiler, { AjvReference, ValidatorFactory, StandaloneValidator, RouteDefinition, ErrorObject, BuildCompilerFromPool, BuildSerializerFromPool, ValidatorCompiler } from '..'
5
+
6
+ {
7
+ const compiler = AjvCompiler({})
8
+ expectType<BuildCompilerFromPool>(compiler)
9
+ }
10
+ {
11
+ const compiler = AjvCompiler()
12
+ expectType<BuildCompilerFromPool>(compiler)
13
+ }
14
+ {
15
+ const compiler = AjvCompiler({ jtdSerializer: false })
16
+ expectType<BuildCompilerFromPool>(compiler)
17
+ }
18
+
19
+ {
20
+ const factory = AjvCompiler({ jtdSerializer: false })
21
+ expectType<BuildCompilerFromPool>(factory)
22
+ factory({}, {
23
+ onCreate (ajv) {
24
+ expectType<import('ajv').default>(ajv)
25
+ }
26
+ })
27
+ }
28
+
29
+ {
30
+ const compiler = AjvCompiler({ jtdSerializer: true })
31
+ expectType<BuildSerializerFromPool>(compiler)
32
+ }
33
+ const reader = StandaloneValidator({
34
+ readMode: true,
35
+ restoreFunction: (route: RouteDefinition) => {
36
+ expectAssignable<RouteDefinition>(route)
37
+ return {} as ValidateFunction
38
+ },
39
+ })
40
+ expectAssignable<ValidatorFactory>(reader)
41
+
42
+ const writer = StandaloneValidator({
43
+ readMode: false,
44
+ storeFunction: (route: RouteDefinition, code: string) => {
45
+ expectAssignable<RouteDefinition>(route)
46
+ expectAssignable<string>(code)
47
+ },
48
+ })
49
+ expectAssignable<ValidatorFactory>(writer)
50
+
51
+ expectType<unknown>(({} as ErrorObject).data)
52
+ expectType<string>(({} as ErrorObject).instancePath)
53
+ expectType<string>(({} as ErrorObject).keyword)
54
+ expectType<string | undefined>(({} as ErrorObject).message)
55
+ expectType<Record<string, any>>(({} as ErrorObject).params)
56
+ expectType<AnySchemaObject | undefined>(({} as ErrorObject).parentSchema)
57
+ expectType<string | undefined>(({} as ErrorObject).propertyName)
58
+ expectType<unknown>(({} as ErrorObject).schema)
59
+ expectType<string>(({} as ErrorObject).schemaPath)
60
+
61
+ expectType<Symbol>(AjvReference)
62
+
63
+ {
64
+ const jtdSchema = {
65
+ discriminator: 'version',
66
+ mapping: {
67
+ 1: {
68
+ properties: {
69
+ foo: { type: 'uint8' }
70
+ }
71
+ },
72
+ 2: {
73
+ properties: {
74
+ foo: { type: 'string' }
75
+ }
76
+ }
77
+ }
78
+ }
79
+
80
+ const externalSchemas1 = {
81
+ foo: {
82
+ definitions: {
83
+ coordinates: {
84
+ properties: {
85
+ lat: { type: 'float32' },
86
+ lng: { type: 'float32' }
87
+ }
88
+ }
89
+ }
90
+ }
91
+ }
92
+
93
+ const factory = AjvCompiler({ jtdSerializer: true })
94
+ expectType<BuildSerializerFromPool>(factory)
95
+ const compiler = factory(externalSchemas1, {})
96
+ expectAssignable<Function>(compiler)
97
+ const serializeFunc = compiler({ schema: jtdSchema })
98
+ expectType<(data: unknown) => string>(serializeFunc)
99
+ expectType<string>(serializeFunc({ version: '1', foo: 42 }))
100
+ }
101
+ // JTD
102
+ {
103
+ const factory = AjvCompiler()
104
+ expectType<BuildCompilerFromPool>(factory)
105
+
106
+ const jtdSchema = {
107
+ discriminator: 'version',
108
+ mapping: {
109
+ 1: {
110
+ properties: {
111
+ foo: { type: 'uint8' }
112
+ }
113
+ },
114
+ 2: {
115
+ properties: {
116
+ foo: { type: 'string' }
117
+ }
118
+ }
119
+ }
120
+ }
121
+
122
+ const compiler = factory({}, {
123
+ customOptions: {},
124
+ mode: 'JTD'
125
+ })
126
+ expectAssignable<ValidatorCompiler>(compiler)
127
+ const validatorFunc = compiler({ schema: jtdSchema })
128
+ expectAssignable<ValidateFunction>(validatorFunc)
129
+
130
+ expectType<boolean | Promise<any>>(validatorFunc({
131
+ version: '2',
132
+ foo: []
133
+ }))
134
+ }
135
+
136
+ // generate standalone code
137
+ {
138
+ const base = {
139
+ $id: 'urn:schema:base',
140
+ definitions: {
141
+ hello: { type: 'string' }
142
+ },
143
+ type: 'object',
144
+ properties: {
145
+ hello: { $ref: '#/definitions/hello' }
146
+ }
147
+ }
148
+
149
+ const refSchema = {
150
+ $id: 'urn:schema:ref',
151
+ type: 'object',
152
+ properties: {
153
+ hello: { $ref: 'urn:schema:base#/definitions/hello' }
154
+ }
155
+ }
156
+
157
+ const endpointSchema = {
158
+ schema: {
159
+ $id: 'urn:schema:endpoint',
160
+ $ref: 'urn:schema:ref'
161
+ }
162
+ }
163
+
164
+ const schemaMap = {
165
+ [base.$id]: base,
166
+ [refSchema.$id]: refSchema
167
+ }
168
+
169
+ const factory = StandaloneValidator({
170
+ readMode: false,
171
+ storeFunction (routeOpts, schemaValidationCode) {
172
+ expectType<RouteDefinition>(routeOpts)
173
+ expectType<string>(schemaValidationCode)
174
+ }
175
+ })
176
+ expectAssignable<ValidatorFactory>(factory)
177
+
178
+ const compiler = factory(schemaMap)
179
+ expectAssignable<ValidatorCompiler>(compiler)
180
+ expectAssignable<Function>(compiler(endpointSchema))
181
+ }
182
+
183
+ {
184
+ const base = {
185
+ $id: 'urn:schema:base',
186
+ definitions: {
187
+ hello: { type: 'string' }
188
+ },
189
+ type: 'object',
190
+ properties: {
191
+ hello: { $ref: '#/definitions/hello' }
192
+ }
193
+ }
194
+
195
+ const refSchema = {
196
+ $id: 'urn:schema:ref',
197
+ type: 'object',
198
+ properties: {
199
+ hello: { $ref: 'urn:schema:base#/definitions/hello' }
200
+ }
201
+ }
202
+
203
+ const endpointSchema = {
204
+ schema: {
205
+ $id: 'urn:schema:endpoint',
206
+ $ref: 'urn:schema:ref'
207
+ }
208
+ }
209
+
210
+ const schemaMap = {
211
+ [base.$id]: base,
212
+ [refSchema.$id]: refSchema
213
+ }
214
+ const factory = StandaloneValidator({
215
+ readMode: true,
216
+ restoreFunction (routeOpts) {
217
+ expectType<RouteDefinition>(routeOpts)
218
+ return {} as ValidateFunction
219
+ }
220
+ })
221
+ expectAssignable<ValidatorFactory>(factory)
222
+
223
+ const compiler = factory(schemaMap)
224
+ expectAssignable<ValidatorCompiler>(compiler)
225
+ expectType<AnyValidateFunction<any>>(compiler(endpointSchema))
226
+ }
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/cors/.github/dependabot.yml ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: "github-actions"
4
+ directory: "/"
5
+ schedule:
6
+ interval: "monthly"
7
+ open-pull-requests-limit: 10
8
+
9
+ - package-ecosystem: "npm"
10
+ directory: "/"
11
+ schedule:
12
+ interval: "monthly"
13
+ open-pull-requests-limit: 10
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/cors/.github/stale.yml ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Number of days of inactivity before an issue becomes stale
2
+ daysUntilStale: 15
3
+ # Number of days of inactivity before a stale issue is closed
4
+ daysUntilClose: 7
5
+ # Issues with these labels will never be considered stale
6
+ exemptLabels:
7
+ - "discussion"
8
+ - "feature request"
9
+ - "bug"
10
+ - "help wanted"
11
+ - "plugin suggestion"
12
+ - "good first issue"
13
+ # Label to use when marking an issue as stale
14
+ staleLabel: stale
15
+ # Comment to post when marking an issue as stale. Set to `false` to disable
16
+ markComment: >
17
+ This issue has been automatically marked as stale because it has not had
18
+ recent activity. It will be closed if no further activity occurs. Thank you
19
+ for your contributions.
20
+ # Comment to post when closing a stale issue. Set to `false` to disable
21
+ closeComment: false
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/cors/.github/workflows/ci.yml ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ - next
8
+ - 'v*'
9
+ paths-ignore:
10
+ - 'docs/**'
11
+ - '*.md'
12
+ pull_request:
13
+ paths-ignore:
14
+ - 'docs/**'
15
+ - '*.md'
16
+
17
+ permissions:
18
+ contents: read
19
+
20
+ jobs:
21
+ test:
22
+ permissions:
23
+ contents: write
24
+ pull-requests: write
25
+ uses: fastify/workflows/.github/workflows/plugins-ci.yml@v5
26
+ with:
27
+ license-check: true
28
+ lint: true
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/cors/benchmark/package.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "benchmark",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "vary.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "author": "",
10
+ "license": "ISC",
11
+ "dependencies": {
12
+ "benchmark": "^2.1.4",
13
+ "vary": "^1.1.2"
14
+ }
15
+ }
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/cors/benchmark/vary.js ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict'
2
+
3
+ const benchmark = require('benchmark')
4
+ const vary = require('vary')
5
+ const createAddFieldnameToVary = require('../vary').createAddFieldnameToVary
6
+
7
+ const replyMock = (header) => ({
8
+ getHeader () { return header },
9
+ setHeader () { },
10
+ header () { }
11
+ })
12
+
13
+ const addAcceptToVary = createAddFieldnameToVary('Accept')
14
+ const addWildcardToVary = createAddFieldnameToVary('*')
15
+ const addAcceptEncodingToVary = createAddFieldnameToVary('Accept-Encoding')
16
+ const addXFooToVary = createAddFieldnameToVary('X-Foo')
17
+
18
+ new benchmark.Suite()
19
+ .add('vary - field to undefined', function () { vary(replyMock(undefined), 'Accept-Encoding') }, { minSamples: 100 })
20
+ .add('vary - field to *', function () { vary(replyMock('*'), 'Accept-Encoding') }, { minSamples: 100 })
21
+ .add('vary - * to field', function () { vary(replyMock('Accept-Encoding'), '*') }, { minSamples: 100 })
22
+ .add('vary - field to empty', function () { vary(replyMock(''), 'Accept-Encoding') }, { minSamples: 100 })
23
+ .add('vary - fields string to empty', function () { vary(replyMock(''), 'Accept') }, { minSamples: 100 })
24
+ .add('vary - field to fields', function () { vary(replyMock('Accept, Accept-Encoding, Accept-Language'), 'X-Foo') }, { minSamples: 100 })
25
+
26
+ .add('cors - field to undefined', function () { addAcceptEncodingToVary(replyMock(undefined)) }, { minSamples: 100 })
27
+ .add('cors - field to *', function () { addAcceptEncodingToVary(replyMock('*')) }, { minSamples: 100 })
28
+ .add('cors - * to field', function () { addWildcardToVary(replyMock('Accept-Encoding')) }, { minSamples: 100 })
29
+ .add('cors - field to empty', function () { addAcceptEncodingToVary(replyMock('')) }, { minSamples: 100 })
30
+ .add('cors - fields string to empty', function () { addAcceptToVary(replyMock('')) }, { minSamples: 100 })
31
+ .add('cors - field to fields', function () { addXFooToVary(replyMock('Accept, Accept-Encoding, Accept-Language')) }, { minSamples: 100 })
32
+
33
+ .on('cycle', function onCycle (event) { console.log(String(event.target)) })
34
+ .run({ async: false })
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/cors/test/cors.test.js ADDED
@@ -0,0 +1,1052 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict'
2
+
3
+ const { test } = require('node:test')
4
+ const { createReadStream, statSync, readFileSync } = require('node:fs')
5
+ const Fastify = require('fastify')
6
+ const cors = require('../')
7
+ const { resolve } = require('node:path')
8
+ const { setTimeout: sleep } = require('node:timers/promises')
9
+
10
+ test('Should add cors headers', async t => {
11
+ t.plan(4)
12
+
13
+ const fastify = Fastify()
14
+ fastify.register(cors)
15
+
16
+ fastify.get('/', (_req, reply) => {
17
+ reply.send('ok')
18
+ })
19
+
20
+ const res = await fastify.inject({
21
+ method: 'GET',
22
+ url: '/'
23
+ })
24
+
25
+ t.assert.ok(res)
26
+ delete res.headers.date
27
+ t.assert.strictEqual(res.statusCode, 200)
28
+ t.assert.strictEqual(res.payload, 'ok')
29
+ t.assert.deepStrictEqual(res.headers['access-control-allow-origin'],
30
+ '*'
31
+ )
32
+ })
33
+
34
+ test('Should add cors headers when payload is a stream', async t => {
35
+ t.plan(4)
36
+
37
+ const fastify = Fastify()
38
+ fastify.register(cors)
39
+ const filePath = resolve(__dirname, __filename)
40
+
41
+ fastify.get('/', (_req, reply) => {
42
+ const stream = createReadStream(filePath)
43
+ reply
44
+ .type('application/json')
45
+ .header('Content-Length', statSync(filePath).size)
46
+ .send(stream)
47
+ })
48
+
49
+ const fileContent = readFileSync(filePath, 'utf-8')
50
+
51
+ const res = await fastify.inject({
52
+ method: 'GET',
53
+ url: '/'
54
+ })
55
+ t.assert.ok(res)
56
+ delete res.headers.date
57
+ t.assert.strictEqual(res.statusCode, 200)
58
+ t.assert.strictEqual(res.payload, fileContent)
59
+ const actualHeaders = {
60
+ 'access-control-allow-origin': res.headers['access-control-allow-origin'],
61
+ 'content-length': res.headers['content-length']
62
+
63
+ }
64
+ t.assert.deepStrictEqual(actualHeaders, {
65
+ 'access-control-allow-origin': '*',
66
+ 'content-length': statSync(filePath).size.toString()
67
+ })
68
+ })
69
+
70
+ test('Should add cors headers (custom values)', async t => {
71
+ t.plan(10)
72
+
73
+ const fastify = Fastify()
74
+ fastify.register(cors, {
75
+ origin: 'example.com',
76
+ methods: 'GET',
77
+ credentials: true,
78
+ exposedHeaders: ['foo', 'bar'],
79
+ allowedHeaders: ['baz', 'woo'],
80
+ maxAge: 123,
81
+ cacheControl: 321
82
+ })
83
+
84
+ fastify.get('/', (_req, reply) => {
85
+ reply.send('ok')
86
+ })
87
+
88
+ let res = await fastify.inject({
89
+ method: 'OPTIONS',
90
+ url: '/',
91
+ headers: {
92
+ 'access-control-request-method': 'GET',
93
+ origin: 'example.com'
94
+ }
95
+ })
96
+ t.assert.ok(res)
97
+ delete res.headers.date
98
+ t.assert.strictEqual(res.statusCode, 204)
99
+ t.assert.strictEqual(res.payload, '')
100
+ const actualHeaders = {
101
+ 'access-control-allow-origin': res.headers['access-control-allow-origin'],
102
+ 'access-control-allow-credentials': res.headers['access-control-allow-credentials'],
103
+ 'access-control-expose-headers': res.headers['access-control-expose-headers'],
104
+ 'access-control-allow-methods': res.headers['access-control-allow-methods'],
105
+ 'access-control-allow-headers': res.headers['access-control-allow-headers'],
106
+ 'access-control-max-age': res.headers['access-control-max-age'],
107
+ 'cache-control': res.headers['cache-control'],
108
+ 'content-length': res.headers['content-length']
109
+ }
110
+ t.assert.deepStrictEqual(actualHeaders, {
111
+ 'access-control-allow-origin': 'example.com',
112
+ 'access-control-allow-credentials': 'true',
113
+ 'access-control-expose-headers': 'foo, bar',
114
+ 'access-control-allow-methods': 'GET',
115
+ 'access-control-allow-headers': 'baz, woo',
116
+ 'access-control-max-age': '123',
117
+ 'cache-control': 'max-age=321',
118
+ 'content-length': '0'
119
+ })
120
+ t.assert.notDeepEqual(res.headers, { vary: 'Origin' })
121
+
122
+ res = await fastify.inject({
123
+ method: 'GET',
124
+ url: '/'
125
+ })
126
+ t.assert.ok(res)
127
+ delete res.headers.date
128
+ t.assert.strictEqual(res.statusCode, 200)
129
+ t.assert.strictEqual(res.payload, 'ok')
130
+ const actualHeaders2 = {
131
+ 'access-control-allow-origin': res.headers['access-control-allow-origin'],
132
+ 'access-control-allow-credentials': res.headers['access-control-allow-credentials'],
133
+ 'access-control-expose-headers': res.headers['access-control-expose-headers'],
134
+ 'content-length': res.headers['content-length']
135
+ }
136
+ t.assert.deepStrictEqual(actualHeaders2, {
137
+ 'access-control-allow-origin': 'example.com',
138
+ 'access-control-allow-credentials': 'true',
139
+ 'access-control-expose-headers': 'foo, bar',
140
+ 'content-length': '2'
141
+ })
142
+ t.assert.notDeepEqual(res.headers, { vary: 'Origin' })
143
+ })
144
+
145
+ test('Should support dynamic config (callback)', async t => {
146
+ t.plan(16)
147
+
148
+ const configs = [{
149
+ origin: 'example.com',
150
+ methods: 'GET',
151
+ credentials: true,
152
+ exposedHeaders: ['foo', 'bar'],
153
+ allowedHeaders: ['baz', 'woo'],
154
+ maxAge: 123,
155
+ cacheControl: 456
156
+ }, {
157
+ origin: 'sample.com',
158
+ methods: 'GET',
159
+ credentials: true,
160
+ exposedHeaders: ['zoo', 'bar'],
161
+ allowedHeaders: ['baz', 'foo'],
162
+ maxAge: 321,
163
+ cacheControl: '456'
164
+ }]
165
+
166
+ const fastify = Fastify()
167
+ let requestId = 0
168
+ const configDelegation = async function (req, cb) {
169
+ // request should have id
170
+ t.assert.ok(req.id)
171
+ // request should not have send
172
+ t.assert.ifError(req.send)
173
+
174
+ const config = configs[requestId]
175
+ requestId++
176
+ if (config) {
177
+ cb(null, config)
178
+ } else {
179
+ cb(new Error('ouch'))
180
+ }
181
+ }
182
+ await fastify.register(cors, () => configDelegation)
183
+
184
+ fastify.get('/', (_req, reply) => {
185
+ reply.send('ok')
186
+ })
187
+
188
+ let res = await fastify.inject({
189
+ method: 'GET',
190
+ url: '/'
191
+ })
192
+ t.assert.ok(res)
193
+ delete res.headers.date
194
+ t.assert.strictEqual(res.statusCode, 200)
195
+ t.assert.strictEqual(res.payload, 'ok')
196
+ const actualHeaders = {
197
+ 'access-control-allow-origin': res.headers['access-control-allow-origin'],
198
+ 'access-control-allow-credentials': res.headers['access-control-allow-credentials'],
199
+ 'access-control-expose-headers': res.headers['access-control-expose-headers'],
200
+ 'content-length': res.headers['content-length'],
201
+ vary: res.headers.vary
202
+ }
203
+ // Sleep to wait for callback
204
+ sleep()
205
+ t.assert.deepStrictEqual(actualHeaders, {
206
+ 'access-control-allow-origin': 'example.com',
207
+ 'access-control-allow-credentials': 'true',
208
+ 'access-control-expose-headers': 'foo, bar',
209
+ 'content-length': '2',
210
+ vary: 'Origin'
211
+ })
212
+
213
+ res = await fastify.inject({
214
+ method: 'OPTIONS',
215
+ url: '/',
216
+ headers: {
217
+ 'access-control-request-method': 'GET',
218
+ origin: 'example.com'
219
+ }
220
+ })
221
+ t.assert.ok(res)
222
+ delete res.headers.date
223
+ t.assert.strictEqual(res.statusCode, 204)
224
+ t.assert.strictEqual(res.payload, '')
225
+ const actualHeaders2 = {
226
+ 'access-control-allow-origin': res.headers['access-control-allow-origin'],
227
+ 'access-control-allow-credentials': res.headers['access-control-allow-credentials'],
228
+ 'access-control-expose-headers': res.headers['access-control-expose-headers'],
229
+ 'access-control-allow-methods': res.headers['access-control-allow-methods'],
230
+ 'access-control-allow-headers': res.headers['access-control-allow-headers'],
231
+ 'access-control-max-age': res.headers['access-control-max-age'],
232
+ 'cache-control': res.headers['cache-control'],
233
+ 'content-length': res.headers['content-length'],
234
+ vary: res.headers.vary
235
+ }
236
+ // Sleep to wait for callback
237
+ sleep()
238
+ t.assert.deepStrictEqual(actualHeaders2, {
239
+ 'access-control-allow-origin': 'sample.com',
240
+ 'access-control-allow-credentials': 'true',
241
+ 'access-control-expose-headers': 'zoo, bar',
242
+ 'access-control-allow-methods': 'GET',
243
+ 'access-control-allow-headers': 'baz, foo',
244
+ 'access-control-max-age': '321',
245
+ 'cache-control': '456',
246
+ 'content-length': '0',
247
+ vary: 'Origin'
248
+ })
249
+
250
+ res = await fastify.inject({
251
+ method: 'GET',
252
+ url: '/',
253
+ headers: {
254
+ 'access-control-request-method': 'GET',
255
+ origin: 'example.com'
256
+ }
257
+ })
258
+ t.assert.ok(res)
259
+ t.assert.strictEqual(res.statusCode, 500)
260
+ })
261
+
262
+ test('Should support dynamic config (Promise)', async t => {
263
+ t.plan(23)
264
+
265
+ const configs = [{
266
+ origin: 'example.com',
267
+ methods: 'GET',
268
+ credentials: true,
269
+ exposedHeaders: ['foo', 'bar'],
270
+ allowedHeaders: ['baz', 'woo'],
271
+ maxAge: 123,
272
+ cacheControl: 456
273
+ }, {
274
+ origin: 'sample.com',
275
+ methods: 'GET',
276
+ credentials: true,
277
+ exposedHeaders: ['zoo', 'bar'],
278
+ allowedHeaders: ['baz', 'foo'],
279
+ maxAge: 321,
280
+ cacheControl: true // Invalid value should be ignored
281
+ }, {
282
+ origin: 'sample.com',
283
+ methods: 'GET',
284
+ credentials: true,
285
+ exposedHeaders: ['zoo', 'bar'],
286
+ allowedHeaders: ['baz', 'foo'],
287
+ maxAge: 321,
288
+ cacheControl: 'public, max-age=456'
289
+ }]
290
+
291
+ const fastify = Fastify()
292
+ let requestId = 0
293
+ const configDelegation = async function (req) {
294
+ // request should have id
295
+ t.assert.ok(req.id)
296
+ // request should not have send
297
+ t.assert.ifError(req.send)
298
+ const config = configs[requestId]
299
+ requestId++
300
+ if (config) {
301
+ return Promise.resolve(config)
302
+ } else {
303
+ return Promise.reject(new Error('ouch'))
304
+ }
305
+ }
306
+ await fastify.register(cors, () => configDelegation)
307
+
308
+ fastify.get('/', (_req, reply) => {
309
+ reply.send('ok')
310
+ })
311
+
312
+ let res = await fastify.inject({
313
+ method: 'GET',
314
+ url: '/'
315
+ })
316
+ t.assert.ok(res)
317
+ delete res.headers.date
318
+ t.assert.strictEqual(res.statusCode, 200)
319
+ t.assert.strictEqual(res.payload, 'ok')
320
+ const actualHeaders = {
321
+ 'access-control-allow-origin': res.headers['access-control-allow-origin'],
322
+ 'access-control-allow-credentials': res.headers['access-control-allow-credentials'],
323
+ 'access-control-expose-headers': res.headers['access-control-expose-headers'],
324
+ 'content-length': res.headers['content-length'],
325
+ vary: res.headers.vary
326
+ }
327
+ t.assert.deepStrictEqual(actualHeaders, {
328
+ 'access-control-allow-origin': 'example.com',
329
+ 'access-control-allow-credentials': 'true',
330
+ 'access-control-expose-headers': 'foo, bar',
331
+ 'content-length': '2',
332
+ vary: 'Origin'
333
+ })
334
+
335
+ res = await fastify.inject({
336
+ method: 'OPTIONS',
337
+ url: '/',
338
+ headers: {
339
+ 'access-control-request-method': 'GET',
340
+ origin: 'sample.com'
341
+ }
342
+ })
343
+ t.assert.ok(res)
344
+ delete res.headers.date
345
+ t.assert.strictEqual(res.statusCode, 204)
346
+ t.assert.strictEqual(res.payload, '')
347
+ const acutalHeaders2 = {
348
+ 'access-control-allow-origin': res.headers['access-control-allow-origin'],
349
+ 'access-control-allow-credentials': res.headers['access-control-allow-credentials'],
350
+ 'access-control-expose-headers': res.headers['access-control-expose-headers'],
351
+ 'access-control-allow-methods': res.headers['access-control-allow-methods'],
352
+ 'access-control-allow-headers': res.headers['access-control-allow-headers'],
353
+ 'access-control-max-age': res.headers['access-control-max-age'],
354
+ 'content-length': res.headers['content-length'],
355
+ vary: res.headers.vary
356
+ }
357
+ t.assert.deepStrictEqual(acutalHeaders2, {
358
+ 'access-control-allow-origin': 'sample.com',
359
+ 'access-control-allow-credentials': 'true',
360
+ 'access-control-expose-headers': 'zoo, bar',
361
+ 'access-control-allow-methods': 'GET',
362
+ 'access-control-allow-headers': 'baz, foo',
363
+ 'access-control-max-age': '321',
364
+ 'content-length': '0',
365
+ vary: 'Origin'
366
+ })
367
+ t.assert.strictEqual(res.headers['cache-control'], undefined, 'cache-control omitted (invalid value)')
368
+
369
+ res = await fastify.inject({
370
+ method: 'OPTIONS',
371
+ url: '/',
372
+ headers: {
373
+ 'access-control-request-method': 'GET',
374
+ origin: 'example.com'
375
+ }
376
+ })
377
+ t.assert.ok(res)
378
+ delete res.headers.date
379
+ t.assert.strictEqual(res.statusCode, 204)
380
+ t.assert.strictEqual(res.payload, '')
381
+ const actualHeaders3 = {
382
+ 'access-control-allow-origin': res.headers['access-control-allow-origin'],
383
+ 'access-control-allow-credentials': res.headers['access-control-allow-credentials'],
384
+ 'access-control-expose-headers': res.headers['access-control-expose-headers'],
385
+ 'access-control-allow-methods': res.headers['access-control-allow-methods'],
386
+ 'access-control-allow-headers': res.headers['access-control-allow-headers'],
387
+ 'access-control-max-age': res.headers['access-control-max-age'],
388
+ 'cache-control': res.headers['cache-control'],
389
+ 'content-length': res.headers['content-length'],
390
+ vary: res.headers.vary
391
+ }
392
+ t.assert.deepStrictEqual(actualHeaders3, {
393
+ 'access-control-allow-origin': 'sample.com',
394
+ 'access-control-allow-credentials': 'true',
395
+ 'access-control-expose-headers': 'zoo, bar',
396
+ 'access-control-allow-methods': 'GET',
397
+ 'access-control-allow-headers': 'baz, foo',
398
+ 'access-control-max-age': '321',
399
+ 'cache-control': 'public, max-age=456', // cache-control included (custom string)
400
+ 'content-length': '0',
401
+ vary: 'Origin'
402
+ })
403
+
404
+ res = await fastify.inject({
405
+ method: 'GET',
406
+ url: '/',
407
+ headers: {
408
+ 'access-control-request-method': 'GET',
409
+ origin: 'example.com'
410
+ }
411
+ })
412
+ t.assert.ok(res)
413
+ t.assert.strictEqual(res.statusCode, 500)
414
+ })
415
+
416
+ test('Should support dynamic config. (Invalid function)', async t => {
417
+ t.plan(2)
418
+
419
+ const fastify = Fastify()
420
+ fastify.register(cors, () => () => {})
421
+
422
+ fastify.get('/', (_req, reply) => {
423
+ reply.send('ok')
424
+ })
425
+
426
+ const res = await fastify.inject({
427
+ method: 'GET',
428
+ url: '/',
429
+ headers: {
430
+ 'access-control-request-method': 'GET',
431
+ origin: 'example.com'
432
+ }
433
+ })
434
+ t.assert.ok(res)
435
+ t.assert.strictEqual(res.statusCode, 500)
436
+ })
437
+
438
+ test('Dynamic origin resolution (valid origin)', async t => {
439
+ t.plan(6)
440
+
441
+ const fastify = Fastify()
442
+ const origin = function (header, cb) {
443
+ t.assert.strictEqual(header, 'example.com')
444
+ t.assert.equal(this, fastify)
445
+ cb(null, true)
446
+ }
447
+ fastify.register(cors, { origin })
448
+
449
+ fastify.get('/', (_req, reply) => {
450
+ reply.send('ok')
451
+ })
452
+
453
+ const res = await fastify.inject({
454
+ method: 'GET',
455
+ url: '/',
456
+ headers: { origin: 'example.com' }
457
+ })
458
+ t.assert.ok(res)
459
+ delete res.headers.date
460
+ t.assert.strictEqual(res.statusCode, 200)
461
+ t.assert.strictEqual(res.payload, 'ok')
462
+ const actualHeaders = {
463
+ 'access-control-allow-origin': res.headers['access-control-allow-origin'],
464
+ vary: res.headers.vary
465
+ }
466
+ t.assert.deepStrictEqual(actualHeaders, {
467
+ 'access-control-allow-origin': 'example.com',
468
+ vary: 'Origin'
469
+ })
470
+ })
471
+
472
+ test('Dynamic origin resolution (not valid origin)', async t => {
473
+ t.plan(5)
474
+
475
+ const fastify = Fastify()
476
+ const origin = (header, cb) => {
477
+ t.assert.strictEqual(header, 'example.com')
478
+ cb(null, false)
479
+ }
480
+ fastify.register(cors, { origin })
481
+
482
+ fastify.get('/', (_req, reply) => {
483
+ reply.send('ok')
484
+ })
485
+
486
+ const res = await fastify.inject({
487
+ method: 'GET',
488
+ url: '/',
489
+ headers: { origin: 'example.com' }
490
+ })
491
+ t.assert.ok(res)
492
+ delete res.headers.date
493
+ t.assert.strictEqual(res.statusCode, 200)
494
+ t.assert.strictEqual(res.payload, 'ok')
495
+ const actualHeaders = {
496
+ 'content-length': res.headers['content-length'],
497
+ 'content-type': res.headers['content-type'],
498
+ connection: res.headers.connection,
499
+ vary: res.headers.vary
500
+ }
501
+ t.assert.deepStrictEqual(actualHeaders, {
502
+ 'content-length': '2',
503
+ 'content-type': 'text/plain; charset=utf-8',
504
+ connection: 'keep-alive',
505
+ vary: 'Origin'
506
+ })
507
+ })
508
+
509
+ test('Dynamic origin resolution (errored)', async t => {
510
+ t.plan(3)
511
+
512
+ const fastify = Fastify()
513
+ const origin = (header, cb) => {
514
+ t.assert.strictEqual(header, 'example.com')
515
+ cb(new Error('ouch'))
516
+ }
517
+ fastify.register(cors, { origin })
518
+
519
+ const res = await fastify.inject({
520
+ method: 'GET',
521
+ url: '/',
522
+ headers: { origin: 'example.com' }
523
+ })
524
+ t.assert.ok(res)
525
+ t.assert.strictEqual(res.statusCode, 500)
526
+ })
527
+
528
+ test('Dynamic origin resolution (invalid result)', async t => {
529
+ t.plan(3)
530
+
531
+ const fastify = Fastify()
532
+ const origin = (header, cb) => {
533
+ t.assert.strictEqual(header, 'example.com')
534
+ cb(null, undefined)
535
+ }
536
+ fastify.register(cors, { origin })
537
+
538
+ const res = await fastify.inject({
539
+ method: 'GET',
540
+ url: '/',
541
+ headers: { origin: 'example.com' }
542
+ })
543
+ t.assert.ok(res)
544
+ t.assert.strictEqual(res.statusCode, 500)
545
+ })
546
+
547
+ test('Dynamic origin resolution (valid origin - promises)', async t => {
548
+ t.plan(5)
549
+
550
+ const fastify = Fastify()
551
+ const origin = (header) => {
552
+ return new Promise((resolve) => {
553
+ t.assert.strictEqual(header, 'example.com')
554
+ resolve(true)
555
+ })
556
+ }
557
+ fastify.register(cors, { origin })
558
+
559
+ fastify.get('/', (_req, reply) => {
560
+ reply.send('ok')
561
+ })
562
+
563
+ const res = await fastify.inject({
564
+ method: 'GET',
565
+ url: '/',
566
+ headers: { origin: 'example.com' }
567
+ })
568
+ t.assert.ok(res)
569
+ delete res.headers.date
570
+ t.assert.strictEqual(res.statusCode, 200)
571
+ t.assert.strictEqual(res.payload, 'ok')
572
+ const actualHeaders = {
573
+ 'access-control-allow-origin': res.headers['access-control-allow-origin'],
574
+ vary: res.headers.vary
575
+ }
576
+ t.assert.deepStrictEqual(actualHeaders, {
577
+ 'access-control-allow-origin': 'example.com',
578
+ vary: 'Origin'
579
+ })
580
+ })
581
+
582
+ test('Dynamic origin resolution (not valid origin - promises)', async t => {
583
+ t.plan(5)
584
+
585
+ const fastify = Fastify()
586
+ const origin = (header) => {
587
+ return new Promise((resolve) => {
588
+ t.assert.strictEqual(header, 'example.com')
589
+ resolve(false)
590
+ })
591
+ }
592
+ fastify.register(cors, { origin })
593
+
594
+ fastify.get('/', (_req, reply) => {
595
+ reply.send('ok')
596
+ })
597
+
598
+ const res = await fastify.inject({
599
+ method: 'GET',
600
+ url: '/',
601
+ headers: { origin: 'example.com' }
602
+ })
603
+ t.assert.ok(res)
604
+ delete res.headers.date
605
+ t.assert.strictEqual(res.statusCode, 200)
606
+ t.assert.strictEqual(res.payload, 'ok')
607
+ const actualHeaders = {
608
+ 'content-length': res.headers['content-length'],
609
+ 'content-type': res.headers['content-type'],
610
+ connection: res.headers.connection,
611
+ vary: res.headers.vary
612
+ }
613
+ t.assert.deepStrictEqual(actualHeaders, {
614
+ 'content-length': '2',
615
+ 'content-type': 'text/plain; charset=utf-8',
616
+ connection: 'keep-alive',
617
+ vary: 'Origin'
618
+ })
619
+ })
620
+
621
+ test('Dynamic origin resolution (errored - promises)', async t => {
622
+ t.plan(3)
623
+
624
+ const fastify = Fastify()
625
+ const origin = (header) => {
626
+ return new Promise((_resolve, reject) => {
627
+ t.assert.strictEqual(header, 'example.com')
628
+ reject(new Error('ouch'))
629
+ })
630
+ }
631
+ fastify.register(cors, { origin })
632
+
633
+ const res = await fastify.inject({
634
+ method: 'GET',
635
+ url: '/',
636
+ headers: { origin: 'example.com' }
637
+ })
638
+ t.assert.ok(res)
639
+ t.assert.strictEqual(res.statusCode, 500)
640
+ })
641
+
642
+ test('Should reply 404 without cors headers when origin is false', async t => {
643
+ t.plan(8)
644
+
645
+ const fastify = Fastify()
646
+ fastify.register(cors, {
647
+ origin: false,
648
+ methods: 'GET',
649
+ credentials: true,
650
+ exposedHeaders: ['foo', 'bar'],
651
+ allowedHeaders: ['baz', 'woo'],
652
+ maxAge: 123
653
+ })
654
+
655
+ fastify.get('/', (_req, reply) => {
656
+ reply.send('ok')
657
+ })
658
+
659
+ let res = await fastify.inject({
660
+ method: 'OPTIONS',
661
+ url: '/'
662
+ })
663
+ t.assert.ok(res)
664
+ delete res.headers.date
665
+ t.assert.strictEqual(res.statusCode, 404)
666
+ t.assert.strictEqual(res.payload, '{"message":"Route OPTIONS:/ not found","error":"Not Found","statusCode":404}')
667
+ const actualHeaders = {
668
+ 'content-length': res.headers['content-length'],
669
+ 'content-type': res.headers['content-type'],
670
+ connection: res.headers.connection
671
+ }
672
+ t.assert.deepStrictEqual(actualHeaders, {
673
+ 'content-length': '76',
674
+ 'content-type': 'application/json; charset=utf-8',
675
+ connection: 'keep-alive'
676
+ })
677
+
678
+ res = await fastify.inject({
679
+ method: 'GET',
680
+ url: '/'
681
+ })
682
+ t.assert.ok(res)
683
+ delete res.headers.date
684
+ t.assert.strictEqual(res.statusCode, 200)
685
+ t.assert.strictEqual(res.payload, 'ok')
686
+ t.assert.deepStrictEqual(res.headers, {
687
+ 'content-length': '2',
688
+ 'content-type': 'text/plain; charset=utf-8',
689
+ connection: 'keep-alive'
690
+ })
691
+ })
692
+
693
+ test('Server error if origin option is falsy but not false', async t => {
694
+ t.plan(4)
695
+
696
+ const fastify = Fastify()
697
+ fastify.register(cors, { origin: '' })
698
+
699
+ const res = await fastify.inject({
700
+ method: 'GET',
701
+ url: '/',
702
+ headers: { origin: 'example.com' }
703
+ })
704
+ t.assert.ok(res)
705
+ delete res.headers.date
706
+ t.assert.strictEqual(res.statusCode, 500)
707
+ t.assert.deepStrictEqual(res.json(), { statusCode: 500, error: 'Internal Server Error', message: 'Invalid CORS origin option' })
708
+ const actualHeaders = {
709
+ 'content-length': res.headers['content-length'],
710
+ 'content-type': res.headers['content-type'],
711
+ connection: res.headers.connection
712
+ }
713
+ t.assert.deepStrictEqual(actualHeaders, {
714
+ 'content-length': '89',
715
+ 'content-type': 'application/json; charset=utf-8',
716
+ connection: 'keep-alive'
717
+ })
718
+ })
719
+
720
+ test('Allow only request from a specific origin', async t => {
721
+ t.plan(5)
722
+
723
+ const fastify = Fastify()
724
+ fastify.register(cors, { origin: 'other.io' })
725
+
726
+ fastify.get('/', (_req, reply) => {
727
+ reply.send('ok')
728
+ })
729
+
730
+ const res = await fastify.inject({
731
+ method: 'GET',
732
+ url: '/',
733
+ headers: { origin: 'example.com' }
734
+ })
735
+ t.assert.ok(res)
736
+ delete res.headers.date
737
+ t.assert.strictEqual(res.statusCode, 200)
738
+ t.assert.strictEqual(res.payload, 'ok')
739
+ t.assert.deepStrictEqual(res.headers['access-control-allow-origin'],
740
+ 'other.io'
741
+ )
742
+ t.assert.notDeepEqual(res.headers, { vary: 'Origin' })
743
+ })
744
+
745
+ test('Allow only request from multiple specific origin', async t => {
746
+ t.plan(9)
747
+
748
+ const fastify = Fastify()
749
+ fastify.register(cors, { origin: ['other.io', 'example.com'] })
750
+
751
+ fastify.get('/', (_req, reply) => {
752
+ reply.send('ok')
753
+ })
754
+
755
+ let res = await fastify.inject({
756
+ method: 'GET',
757
+ url: '/',
758
+ headers: { origin: 'other.io' }
759
+ })
760
+ t.assert.ok(res)
761
+ delete res.headers.date
762
+ t.assert.strictEqual(res.statusCode, 200)
763
+ t.assert.strictEqual(res.payload, 'ok')
764
+ const actualHeaders = {
765
+ 'access-control-allow-origin': res.headers['access-control-allow-origin'],
766
+ vary: res.headers.vary
767
+ }
768
+ t.assert.deepStrictEqual(actualHeaders, {
769
+ 'access-control-allow-origin': 'other.io',
770
+ vary: 'Origin'
771
+ })
772
+
773
+ res = await fastify.inject({
774
+ method: 'GET',
775
+ url: '/',
776
+ headers: { origin: 'foo.com' }
777
+ })
778
+ t.assert.ok(res)
779
+ delete res.headers.date
780
+ t.assert.strictEqual(res.statusCode, 200)
781
+ t.assert.strictEqual(res.payload, 'ok')
782
+ t.assert.deepStrictEqual(res.headers.vary,
783
+ 'Origin'
784
+ )
785
+ t.assert.strictEqual(res.headers['access-control-allow-origin'], undefined)
786
+ })
787
+
788
+ test('Allow only request from a specific origin using regex', async t => {
789
+ t.plan(8)
790
+
791
+ const fastify = Fastify()
792
+ fastify.register(cors, { origin: /(?:example|other)\.com\/?$/giu })
793
+
794
+ fastify.get('/', (_req, reply) => {
795
+ reply.send('ok')
796
+ })
797
+
798
+ // .test was previously used, which caused 2 consecutive requests to return
799
+ // different results with global (e.g. /g) regexes. Therefore, check this
800
+ // twice to check consistency
801
+ for (let i = 0; i < 2; i++) {
802
+ const res = await fastify.inject({
803
+ method: 'GET',
804
+ url: '/',
805
+ headers: { origin: 'https://www.example.com/' }
806
+ })
807
+ t.assert.ok(res)
808
+ delete res.headers.date
809
+ t.assert.strictEqual(res.statusCode, 200)
810
+ t.assert.strictEqual(res.payload, 'ok')
811
+ const actualHeaders = {
812
+ 'access-control-allow-origin': res.headers['access-control-allow-origin'],
813
+ vary: res.headers.vary
814
+ }
815
+ t.assert.deepStrictEqual(actualHeaders, {
816
+ 'access-control-allow-origin': 'https://www.example.com/',
817
+ vary: 'Origin'
818
+ })
819
+ }
820
+ })
821
+
822
+ test('Disable preflight', async t => {
823
+ t.plan(7)
824
+
825
+ const fastify = Fastify()
826
+ fastify.register(cors, { preflight: false })
827
+
828
+ fastify.get('/', (_req, reply) => {
829
+ reply.send('ok')
830
+ })
831
+
832
+ let res = await fastify.inject({
833
+ method: 'OPTIONS',
834
+ url: '/hello'
835
+ })
836
+ t.assert.ok(res)
837
+ delete res.headers.date
838
+ t.assert.strictEqual(res.statusCode, 404)
839
+ t.assert.strictEqual(res.headers['access-control-allow-origin'],
840
+ '*'
841
+ )
842
+
843
+ res = await fastify.inject({
844
+ method: 'GET',
845
+ url: '/'
846
+ })
847
+ t.assert.ok(res)
848
+ delete res.headers.date
849
+ t.assert.strictEqual(res.statusCode, 200)
850
+ t.assert.strictEqual(res.payload, 'ok')
851
+ t.assert.strictEqual(res.headers['access-control-allow-origin'],
852
+ '*'
853
+ )
854
+ })
855
+
856
+ test('Should always add vary header to `Origin` for reflected origin', async t => {
857
+ t.plan(12)
858
+
859
+ const fastify = Fastify()
860
+ fastify.register(cors, { origin: true })
861
+
862
+ fastify.get('/', (_req, reply) => {
863
+ reply.send('ok')
864
+ })
865
+
866
+ // Invalid Preflight
867
+ let res = await fastify.inject({
868
+ method: 'OPTIONS',
869
+ url: '/'
870
+ })
871
+ t.assert.ok(res)
872
+ delete res.headers.date
873
+ t.assert.strictEqual(res.statusCode, 400)
874
+ t.assert.strictEqual(res.payload, 'Invalid Preflight Request')
875
+ t.assert.strictEqual(res.headers.vary,
876
+ 'Origin'
877
+ )
878
+
879
+ // Valid Preflight
880
+ res = await fastify.inject({
881
+ method: 'OPTIONS',
882
+ url: '/',
883
+ headers: {
884
+ 'access-control-request-method': 'GET',
885
+ origin: 'example.com'
886
+ }
887
+ })
888
+ t.assert.ok(res)
889
+ delete res.headers.date
890
+ t.assert.strictEqual(res.statusCode, 204)
891
+ t.assert.strictEqual(res.payload, '')
892
+ t.assert.strictEqual(res.headers.vary,
893
+ 'Origin, Access-Control-Request-Headers'
894
+ )
895
+
896
+ // Other Route
897
+ res = await fastify.inject({
898
+ method: 'GET',
899
+ url: '/'
900
+ })
901
+ t.assert.ok(res)
902
+ delete res.headers.date
903
+ t.assert.strictEqual(res.statusCode, 200)
904
+ t.assert.strictEqual(res.payload, 'ok')
905
+ t.assert.strictEqual(res.headers.vary,
906
+ 'Origin'
907
+ )
908
+ })
909
+
910
+ test('Should always add vary header to `Origin` for reflected origin (vary is array)', async t => {
911
+ t.plan(4)
912
+
913
+ const fastify = Fastify()
914
+
915
+ // Mock getHeader function
916
+ fastify.decorateReply('getHeader', () => ['foo', 'bar'])
917
+
918
+ fastify.register(cors, { origin: true })
919
+
920
+ fastify.get('/', (_req, reply) => {
921
+ reply.send('ok')
922
+ })
923
+
924
+ const res = await fastify.inject({
925
+ method: 'GET',
926
+ url: '/'
927
+ })
928
+ t.assert.ok(res)
929
+ delete res.headers.date
930
+ t.assert.strictEqual(res.statusCode, 200)
931
+ t.assert.strictEqual(res.payload, 'ok')
932
+ t.assert.strictEqual(res.headers.vary,
933
+ 'foo, bar, Origin'
934
+ )
935
+ })
936
+
937
+ test('Allow only request from with specific headers', async t => {
938
+ t.plan(8)
939
+
940
+ const fastify = Fastify()
941
+ fastify.register(cors, {
942
+ allowedHeaders: 'foo',
943
+ exposedHeaders: 'bar'
944
+ })
945
+
946
+ fastify.get('/', (_req, reply) => {
947
+ reply.send('ok')
948
+ })
949
+
950
+ let res = await fastify.inject({
951
+ method: 'OPTIONS',
952
+ url: '/',
953
+ headers: {
954
+ 'access-control-request-method': 'GET',
955
+ origin: 'example.com'
956
+ }
957
+ })
958
+ t.assert.ok(res)
959
+ delete res.headers.date
960
+ t.assert.strictEqual(res.statusCode, 204)
961
+ t.assert.deepStrictEqual(res.headers['access-control-allow-headers'],
962
+ 'foo'
963
+ )
964
+ t.assert.notDeepEqual(res.headers.vary, 'Origin')
965
+
966
+ res = await fastify.inject({
967
+ method: 'GET',
968
+ url: '/'
969
+ })
970
+ t.assert.ok(res)
971
+ delete res.headers.date
972
+ t.assert.strictEqual(res.statusCode, 200)
973
+ t.assert.strictEqual(res.payload, 'ok')
974
+ t.assert.strictEqual(res.headers['access-control-expose-headers'],
975
+ 'bar'
976
+ )
977
+ })
978
+
979
+ test('Should support wildcard config /1', async t => {
980
+ t.plan(4)
981
+
982
+ const fastify = Fastify()
983
+ fastify.register(cors, { origin: '*' })
984
+
985
+ fastify.get('/', (_req, reply) => {
986
+ reply.send('ok')
987
+ })
988
+
989
+ const res = await fastify.inject({
990
+ method: 'GET',
991
+ url: '/'
992
+ })
993
+ t.assert.ok(res)
994
+ t.assert.strictEqual(res.statusCode, 200)
995
+ t.assert.strictEqual(res.payload, 'ok')
996
+ t.assert.strictEqual(res.headers['access-control-allow-origin'], '*')
997
+ })
998
+
999
+ test('Should support wildcard config /2', async t => {
1000
+ t.plan(4)
1001
+
1002
+ const fastify = Fastify()
1003
+ fastify.register(cors, { origin: ['*'] })
1004
+
1005
+ fastify.get('/', (_req, reply) => {
1006
+ reply.send('ok')
1007
+ })
1008
+
1009
+ const res = await fastify.inject({
1010
+ method: 'GET',
1011
+ url: '/'
1012
+ })
1013
+ t.assert.ok(res)
1014
+ t.assert.strictEqual(res.statusCode, 200)
1015
+ t.assert.strictEqual(res.payload, 'ok')
1016
+ t.assert.strictEqual(res.headers['access-control-allow-origin'], '*')
1017
+ })
1018
+
1019
+ test('Should allow routes to disable CORS individually', async t => {
1020
+ t.plan(6)
1021
+
1022
+ const fastify = Fastify()
1023
+ fastify.register(cors, { origin: '*' })
1024
+
1025
+ fastify.get('/cors-enabled', (_req, reply) => {
1026
+ reply.send('ok')
1027
+ })
1028
+
1029
+ fastify.get('/cors-disabled', { config: { cors: false } }, (_req, reply) => {
1030
+ reply.send('ok')
1031
+ })
1032
+
1033
+ // Test CORS enabled route
1034
+ let res = await fastify.inject({
1035
+ method: 'GET',
1036
+ url: '/cors-enabled',
1037
+ headers: { origin: 'example.com' }
1038
+ })
1039
+ t.assert.ok(res)
1040
+ t.assert.strictEqual(res.statusCode, 200)
1041
+ t.assert.strictEqual(res.headers['access-control-allow-origin'], '*')
1042
+
1043
+ // Test CORS disabled route
1044
+ res = await fastify.inject({
1045
+ method: 'GET',
1046
+ url: '/cors-disabled',
1047
+ headers: { origin: 'example.com' }
1048
+ })
1049
+ t.assert.ok(res)
1050
+ t.assert.strictEqual(res.statusCode, 200)
1051
+ t.assert.strictEqual(res.headers['access-control-allow-origin'], undefined)
1052
+ })
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/cors/test/hooks.test.js ADDED
@@ -0,0 +1,787 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict'
2
+
3
+ const { test } = require('node:test')
4
+ const Fastify = require('fastify')
5
+ const kFastifyContext = require('fastify/lib/symbols').kRouteContext
6
+ const cors = require('..')
7
+ const { setTimeout: sleep } = require('node:timers/promises')
8
+
9
+ test('Should error on invalid hook option', async (t) => {
10
+ t.plan(3)
11
+
12
+ const fastify = Fastify()
13
+ await t.assert.rejects(
14
+ async () => fastify.register(cors, { hook: 'invalid' }),
15
+ (err) => {
16
+ t.assert.strictEqual(err.name, 'TypeError')
17
+ t.assert.strictEqual(err.message, '@fastify/cors: Invalid hook option provided.')
18
+ return true
19
+ }
20
+ )
21
+ })
22
+
23
+ test('Should set hook onRequest if hook option is not set', async (t) => {
24
+ t.plan(10)
25
+
26
+ const fastify = Fastify()
27
+
28
+ fastify.register(cors)
29
+
30
+ fastify.addHook('onResponse', (request, _reply, done) => {
31
+ t.assert.strictEqual(request[kFastifyContext].onError, null)
32
+ t.assert.strictEqual(request[kFastifyContext].onRequest.length, 1)
33
+ t.assert.strictEqual(request[kFastifyContext].onSend, null)
34
+ t.assert.strictEqual(request[kFastifyContext].preHandler, null)
35
+ t.assert.strictEqual(request[kFastifyContext].preParsing, null)
36
+ t.assert.strictEqual(request[kFastifyContext].preSerialization, null)
37
+ t.assert.strictEqual(request[kFastifyContext].preValidation, null)
38
+ done()
39
+ })
40
+
41
+ fastify.get('/', (_req, reply) => {
42
+ reply.send('ok')
43
+ })
44
+
45
+ await fastify.ready()
46
+
47
+ const res = await fastify.inject({
48
+ method: 'GET',
49
+ url: '/'
50
+ })
51
+ delete res.headers.date
52
+ t.assert.strictEqual(res.statusCode, 200)
53
+ t.assert.strictEqual(res.payload, 'ok')
54
+ const actualHeader = {
55
+ 'access-control-allow-origin': res.headers['access-control-allow-origin']
56
+ }
57
+ t.assert.deepStrictEqual(actualHeader, {
58
+ 'access-control-allow-origin': '*'
59
+ })
60
+ })
61
+
62
+ test('Should set hook onRequest if hook option is set to onRequest', async (t) => {
63
+ t.plan(10)
64
+
65
+ const fastify = Fastify()
66
+
67
+ fastify.register(cors, {
68
+ hook: 'onRequest'
69
+ })
70
+
71
+ fastify.addHook('onResponse', (request, _reply, done) => {
72
+ t.assert.strictEqual(request[kFastifyContext].onError, null)
73
+ t.assert.strictEqual(request[kFastifyContext].onRequest.length, 1)
74
+ t.assert.strictEqual(request[kFastifyContext].onSend, null)
75
+ t.assert.strictEqual(request[kFastifyContext].preHandler, null)
76
+ t.assert.strictEqual(request[kFastifyContext].preParsing, null)
77
+ t.assert.strictEqual(request[kFastifyContext].preSerialization, null)
78
+ t.assert.strictEqual(request[kFastifyContext].preValidation, null)
79
+ done()
80
+ })
81
+
82
+ fastify.get('/', (_req, reply) => {
83
+ reply.send('ok')
84
+ })
85
+
86
+ await fastify.ready()
87
+
88
+ const res = await fastify.inject({
89
+ method: 'GET',
90
+ url: '/'
91
+ })
92
+ delete res.headers.date
93
+ t.assert.strictEqual(res.statusCode, 200)
94
+ t.assert.strictEqual(res.payload, 'ok')
95
+ const actualHeader = {
96
+ 'access-control-allow-origin': res.headers['access-control-allow-origin']
97
+ }
98
+ t.assert.deepStrictEqual(actualHeader, {
99
+ 'access-control-allow-origin': '*'
100
+ })
101
+ })
102
+
103
+ test('Should set hook preParsing if hook option is set to preParsing', async (t) => {
104
+ t.plan(11)
105
+
106
+ const fastify = Fastify()
107
+
108
+ fastify.register(cors, {
109
+ hook: 'preParsing'
110
+ })
111
+
112
+ fastify.addHook('onResponse', (request, _reply, done) => {
113
+ t.assert.strictEqual(request[kFastifyContext].onError, null)
114
+ t.assert.strictEqual(request[kFastifyContext].onRequest, null)
115
+ t.assert.strictEqual(request[kFastifyContext].onSend, null)
116
+ t.assert.strictEqual(request[kFastifyContext].preHandler, null)
117
+ t.assert.strictEqual(request[kFastifyContext].preParsing.length, 1)
118
+ t.assert.strictEqual(request[kFastifyContext].preSerialization, null)
119
+ t.assert.strictEqual(request[kFastifyContext].preValidation, null)
120
+ done()
121
+ })
122
+
123
+ fastify.get('/', (_req, reply) => {
124
+ reply.send('ok')
125
+ })
126
+
127
+ await fastify.ready()
128
+
129
+ const res = await fastify.inject({
130
+ method: 'GET',
131
+ url: '/'
132
+ })
133
+ delete res.headers.date
134
+ t.assert.strictEqual(res.statusCode, 200)
135
+ t.assert.strictEqual(res.payload, 'ok')
136
+ const actualHeader = {
137
+ 'access-control-allow-origin': res.headers['access-control-allow-origin']
138
+ }
139
+ t.assert.deepStrictEqual(actualHeader, {
140
+ 'access-control-allow-origin': '*'
141
+ })
142
+ t.assert.notStrictEqual(res.headers.vary, 'Origin')
143
+ })
144
+
145
+ test('Should set hook preValidation if hook option is set to preValidation', async (t) => {
146
+ t.plan(11)
147
+
148
+ const fastify = Fastify()
149
+
150
+ fastify.register(cors, {
151
+ hook: 'preValidation'
152
+ })
153
+
154
+ fastify.addHook('onResponse', (request, _reply, done) => {
155
+ t.assert.strictEqual(request[kFastifyContext].onError, null)
156
+ t.assert.strictEqual(request[kFastifyContext].onRequest, null)
157
+ t.assert.strictEqual(request[kFastifyContext].onSend, null)
158
+ t.assert.strictEqual(request[kFastifyContext].preHandler, null)
159
+ t.assert.strictEqual(request[kFastifyContext].preParsing, null)
160
+ t.assert.strictEqual(request[kFastifyContext].preSerialization, null)
161
+ t.assert.strictEqual(request[kFastifyContext].preValidation.length, 1)
162
+ done()
163
+ })
164
+
165
+ fastify.get('/', (_req, reply) => {
166
+ reply.send('ok')
167
+ })
168
+
169
+ await fastify.ready()
170
+
171
+ const res = await fastify.inject({
172
+ method: 'GET',
173
+ url: '/'
174
+ })
175
+ delete res.headers.date
176
+ t.assert.strictEqual(res.statusCode, 200)
177
+ t.assert.strictEqual(res.payload, 'ok')
178
+ const actualHeader = {
179
+ 'access-control-allow-origin': res.headers['access-control-allow-origin']
180
+ }
181
+ t.assert.deepStrictEqual(actualHeader, {
182
+ 'access-control-allow-origin': '*'
183
+ })
184
+ t.assert.notStrictEqual(res.headers.vary, 'Origin')
185
+ })
186
+
187
+ test('Should set hook preParsing if hook option is set to preParsing', async (t) => {
188
+ t.plan(11)
189
+
190
+ const fastify = Fastify()
191
+
192
+ fastify.register(cors, {
193
+ hook: 'preParsing'
194
+ })
195
+
196
+ fastify.addHook('onResponse', (request, _reply, done) => {
197
+ t.assert.strictEqual(request[kFastifyContext].onError, null)
198
+ t.assert.strictEqual(request[kFastifyContext].onRequest, null)
199
+ t.assert.strictEqual(request[kFastifyContext].onSend, null)
200
+ t.assert.strictEqual(request[kFastifyContext].preHandler, null)
201
+ t.assert.strictEqual(request[kFastifyContext].preParsing.length, 1)
202
+ t.assert.strictEqual(request[kFastifyContext].preSerialization, null)
203
+ t.assert.strictEqual(request[kFastifyContext].preValidation, null)
204
+ done()
205
+ })
206
+
207
+ fastify.get('/', (_req, reply) => {
208
+ reply.send('ok')
209
+ })
210
+
211
+ await fastify.ready()
212
+
213
+ const res = await fastify.inject({
214
+ method: 'GET',
215
+ url: '/'
216
+ })
217
+ delete res.headers.date
218
+ t.assert.strictEqual(res.statusCode, 200)
219
+ t.assert.strictEqual(res.payload, 'ok')
220
+ const actualHeader = {
221
+ 'access-control-allow-origin': res.headers['access-control-allow-origin']
222
+ }
223
+ t.assert.deepStrictEqual(actualHeader, {
224
+ 'access-control-allow-origin': '*'
225
+ })
226
+ t.assert.notStrictEqual(res.headers.vary, 'Origin')
227
+ })
228
+
229
+ test('Should set hook preHandler if hook option is set to preHandler', async (t) => {
230
+ t.plan(11)
231
+
232
+ const fastify = Fastify()
233
+
234
+ fastify.register(cors, {
235
+ hook: 'preHandler'
236
+ })
237
+
238
+ fastify.addHook('onResponse', (request, _reply, done) => {
239
+ t.assert.strictEqual(request[kFastifyContext].onError, null)
240
+ t.assert.strictEqual(request[kFastifyContext].onRequest, null)
241
+ t.assert.strictEqual(request[kFastifyContext].onSend, null)
242
+ t.assert.strictEqual(request[kFastifyContext].preHandler.length, 1)
243
+ t.assert.strictEqual(request[kFastifyContext].preParsing, null)
244
+ t.assert.strictEqual(request[kFastifyContext].preSerialization, null)
245
+ t.assert.strictEqual(request[kFastifyContext].preValidation, null)
246
+ done()
247
+ })
248
+
249
+ fastify.get('/', (_req, reply) => {
250
+ reply.send('ok')
251
+ })
252
+
253
+ await fastify.ready()
254
+
255
+ const res = await fastify.inject({
256
+ method: 'GET',
257
+ url: '/'
258
+ })
259
+ delete res.headers.date
260
+ t.assert.strictEqual(res.statusCode, 200)
261
+ t.assert.strictEqual(res.payload, 'ok')
262
+ const actualHeader = {
263
+ 'access-control-allow-origin': res.headers['access-control-allow-origin']
264
+ }
265
+ t.assert.deepStrictEqual(actualHeader, {
266
+ 'access-control-allow-origin': '*'
267
+ })
268
+ t.assert.notStrictEqual(res.headers.vary, 'Origin')
269
+ })
270
+
271
+ test('Should set hook onSend if hook option is set to onSend', async (t) => {
272
+ t.plan(11)
273
+
274
+ const fastify = Fastify()
275
+
276
+ fastify.register(cors, {
277
+ hook: 'onSend'
278
+ })
279
+
280
+ fastify.addHook('onResponse', (request, _reply, done) => {
281
+ t.assert.strictEqual(request[kFastifyContext].onError, null)
282
+ t.assert.strictEqual(request[kFastifyContext].onRequest, null)
283
+ t.assert.strictEqual(request[kFastifyContext].onSend.length, 1)
284
+ t.assert.strictEqual(request[kFastifyContext].preHandler, null)
285
+ t.assert.strictEqual(request[kFastifyContext].preParsing, null)
286
+ t.assert.strictEqual(request[kFastifyContext].preSerialization, null)
287
+ t.assert.strictEqual(request[kFastifyContext].preValidation, null)
288
+ done()
289
+ })
290
+
291
+ fastify.get('/', (_req, reply) => {
292
+ reply.send('ok')
293
+ })
294
+
295
+ await fastify.ready()
296
+
297
+ const res = await fastify.inject({
298
+ method: 'GET',
299
+ url: '/'
300
+ })
301
+ delete res.headers.date
302
+ t.assert.strictEqual(res.statusCode, 200)
303
+ t.assert.strictEqual(res.payload, 'ok')
304
+ const actualHeader = {
305
+ 'access-control-allow-origin': res.headers['access-control-allow-origin']
306
+ }
307
+ t.assert.deepStrictEqual(actualHeader, {
308
+ 'access-control-allow-origin': '*'
309
+ })
310
+ t.assert.notStrictEqual(res.headers.vary, 'Origin')
311
+ })
312
+
313
+ test('Should set hook preSerialization if hook option is set to preSerialization', async (t) => {
314
+ t.plan(11)
315
+
316
+ const fastify = Fastify()
317
+
318
+ fastify.register(cors, {
319
+ hook: 'preSerialization'
320
+ })
321
+
322
+ fastify.addHook('onResponse', (request, _reply, done) => {
323
+ t.assert.strictEqual(request[kFastifyContext].onError, null)
324
+ t.assert.strictEqual(request[kFastifyContext].onRequest, null)
325
+ t.assert.strictEqual(request[kFastifyContext].onSend, null)
326
+ t.assert.strictEqual(request[kFastifyContext].preHandler, null)
327
+ t.assert.strictEqual(request[kFastifyContext].preParsing, null)
328
+ t.assert.strictEqual(request[kFastifyContext].preSerialization.length, 1)
329
+ t.assert.strictEqual(request[kFastifyContext].preValidation, null)
330
+ done()
331
+ })
332
+
333
+ fastify.get('/', (_req, reply) => {
334
+ reply.send({ nonString: true })
335
+ })
336
+
337
+ await fastify.ready()
338
+
339
+ const res = await fastify.inject({
340
+ method: 'GET',
341
+ url: '/'
342
+ })
343
+ delete res.headers.date
344
+ t.assert.strictEqual(res.statusCode, 200)
345
+ t.assert.strictEqual(res.payload, '{"nonString":true}')
346
+ const actualHeader = {
347
+ 'access-control-allow-origin': res.headers['access-control-allow-origin']
348
+ }
349
+ t.assert.deepStrictEqual(actualHeader, {
350
+ 'access-control-allow-origin': '*'
351
+ })
352
+ t.assert.notStrictEqual(res.headers.vary, 'Origin')
353
+ })
354
+
355
+ test('Should support custom hook with dynamic config', async t => {
356
+ t.plan(16)
357
+
358
+ const configs = [{
359
+ origin: 'example.com',
360
+ methods: 'GET',
361
+ credentials: true,
362
+ exposedHeaders: ['foo', 'bar'],
363
+ allowedHeaders: ['baz', 'woo'],
364
+ maxAge: 123
365
+ }, {
366
+ origin: 'sample.com',
367
+ methods: 'GET',
368
+ credentials: true,
369
+ exposedHeaders: ['zoo', 'bar'],
370
+ allowedHeaders: ['baz', 'foo'],
371
+ maxAge: 321
372
+ }]
373
+
374
+ const fastify = Fastify()
375
+ let requestId = 0
376
+ const configDelegation = async function (req) {
377
+ // request should have id
378
+ t.assert.ok(req.id)
379
+ // request should not have send
380
+ t.assert.ifError(req.send)
381
+ const config = configs[requestId]
382
+ requestId++
383
+ if (config) {
384
+ return Promise.resolve(config)
385
+ } else {
386
+ return Promise.reject(new Error('ouch'))
387
+ }
388
+ }
389
+ await fastify.register(cors, {
390
+ hook: 'preHandler',
391
+ delegator: configDelegation
392
+ })
393
+
394
+ fastify.get('/', (_req, reply) => {
395
+ reply.send('ok')
396
+ })
397
+
398
+ let res = await fastify.inject({
399
+ method: 'GET',
400
+ url: '/'
401
+ })
402
+ t.assert.ok(res)
403
+ delete res.headers.date
404
+ t.assert.strictEqual(res.statusCode, 200)
405
+ t.assert.strictEqual(res.payload, 'ok')
406
+ let actualHeaders = {
407
+ 'access-control-allow-origin': res.headers['access-control-allow-origin'],
408
+ 'access-control-allow-credentials': res.headers['access-control-allow-credentials'],
409
+ 'access-control-expose-headers': res.headers['access-control-expose-headers'],
410
+ 'content-length': res.headers['content-length'],
411
+ vary: res.headers.vary
412
+ }
413
+ t.assert.deepStrictEqual(actualHeaders, {
414
+ 'access-control-allow-origin': 'example.com',
415
+ 'access-control-allow-credentials': 'true',
416
+ 'access-control-expose-headers': 'foo, bar',
417
+ 'content-length': '2',
418
+ vary: 'Origin'
419
+ })
420
+
421
+ res = await fastify.inject({
422
+ method: 'OPTIONS',
423
+ url: '/',
424
+ headers: {
425
+ 'access-control-request-method': 'GET',
426
+ origin: 'example.com'
427
+ }
428
+ })
429
+ t.assert.ok(res)
430
+ delete res.headers.date
431
+ t.assert.strictEqual(res.statusCode, 204)
432
+ t.assert.strictEqual(res.payload, '')
433
+ actualHeaders = {
434
+ 'access-control-allow-origin': res.headers['access-control-allow-origin'],
435
+ 'access-control-allow-credentials': res.headers['access-control-allow-credentials'],
436
+ 'access-control-expose-headers': res.headers['access-control-expose-headers'],
437
+ 'access-control-allow-methods': res.headers['access-control-allow-methods'],
438
+ 'access-control-allow-headers': res.headers['access-control-allow-headers'],
439
+ 'access-control-max-age': res.headers['access-control-max-age'],
440
+ 'content-length': res.headers['content-length'],
441
+ vary: res.headers.vary
442
+ }
443
+ t.assert.deepStrictEqual(actualHeaders, {
444
+ 'access-control-allow-origin': 'sample.com',
445
+ 'access-control-allow-credentials': 'true',
446
+ 'access-control-expose-headers': 'zoo, bar',
447
+ 'access-control-allow-methods': 'GET',
448
+ 'access-control-allow-headers': 'baz, foo',
449
+ 'access-control-max-age': '321',
450
+ 'content-length': '0',
451
+ vary: 'Origin'
452
+ })
453
+
454
+ res = await fastify.inject({
455
+ method: 'GET',
456
+ url: '/',
457
+ headers: {
458
+ 'access-control-request-method': 'GET',
459
+ origin: 'example.com'
460
+ }
461
+ })
462
+ t.assert.ok(res)
463
+ t.assert.strictEqual(res.statusCode, 500)
464
+ })
465
+
466
+ test('Should support custom hook with dynamic config (callback)', async t => {
467
+ t.plan(16)
468
+
469
+ const configs = [{
470
+ origin: 'example.com',
471
+ methods: 'GET',
472
+ credentials: true,
473
+ exposedHeaders: ['foo', 'bar'],
474
+ allowedHeaders: ['baz', 'woo'],
475
+ maxAge: 123
476
+ }, {
477
+ origin: 'sample.com',
478
+ methods: 'GET',
479
+ credentials: true,
480
+ exposedHeaders: ['zoo', 'bar'],
481
+ allowedHeaders: ['baz', 'foo'],
482
+ maxAge: 321
483
+ }]
484
+
485
+ const fastify = Fastify()
486
+ let requestId = 0
487
+ const configDelegation = function (req, cb) {
488
+ // request should have id
489
+ t.assert.ok(req.id)
490
+ // request should not have send
491
+ t.assert.ifError(req.send)
492
+ const config = configs[requestId]
493
+ requestId++
494
+ if (config) {
495
+ cb(null, config)
496
+ } else {
497
+ cb(new Error('ouch'))
498
+ }
499
+ }
500
+ fastify.register(cors, {
501
+ hook: 'preParsing',
502
+ delegator: configDelegation
503
+ })
504
+
505
+ fastify.get('/', (_req, reply) => {
506
+ reply.send('ok')
507
+ })
508
+
509
+ fastify.inject({
510
+ method: 'GET',
511
+ url: '/'
512
+ }, (err, res) => {
513
+ t.assert.ifError(err)
514
+ delete res.headers.date
515
+ t.assert.strictEqual(res.statusCode, 200)
516
+ t.assert.strictEqual(res.payload, 'ok')
517
+ const actualHeaders = {
518
+ 'access-control-allow-origin': res.headers['access-control-allow-origin'],
519
+ 'access-control-allow-credentials': res.headers['access-control-allow-credentials'],
520
+ 'access-control-expose-headers': res.headers['access-control-expose-headers'],
521
+ 'content-length': res.headers['content-length'],
522
+ vary: res.headers.vary
523
+ }
524
+ t.assert.deepStrictEqual(actualHeaders, {
525
+ 'access-control-allow-origin': 'example.com',
526
+ 'access-control-allow-credentials': 'true',
527
+ 'access-control-expose-headers': 'foo, bar',
528
+ 'content-length': '2',
529
+ vary: 'Origin'
530
+ })
531
+ })
532
+
533
+ fastify.inject({
534
+ method: 'OPTIONS',
535
+ url: '/',
536
+ headers: {
537
+ 'access-control-request-method': 'GET',
538
+ origin: 'example.com'
539
+ }
540
+ }, (err, res) => {
541
+ t.assert.ifError(err)
542
+ delete res.headers.date
543
+ t.assert.strictEqual(res.statusCode, 204)
544
+ t.assert.strictEqual(res.payload, '')
545
+ const actualHeaders = {
546
+ 'access-control-allow-origin': res.headers['access-control-allow-origin'],
547
+ 'access-control-allow-credentials': res.headers['access-control-allow-credentials'],
548
+ 'access-control-expose-headers': res.headers['access-control-expose-headers'],
549
+ 'access-control-allow-methods': res.headers['access-control-allow-methods'],
550
+ 'access-control-allow-headers': res.headers['access-control-allow-headers'],
551
+ 'access-control-max-age': res.headers['access-control-max-age'],
552
+ 'content-length': res.headers['content-length'],
553
+ vary: res.headers.vary
554
+ }
555
+ t.assert.deepStrictEqual(actualHeaders, {
556
+ 'access-control-allow-origin': 'sample.com',
557
+ 'access-control-allow-credentials': 'true',
558
+ 'access-control-expose-headers': 'zoo, bar',
559
+ 'access-control-allow-methods': 'GET',
560
+ 'access-control-allow-headers': 'baz, foo',
561
+ 'access-control-max-age': '321',
562
+ 'content-length': '0',
563
+ vary: 'Origin'
564
+ })
565
+ })
566
+
567
+ fastify.inject({
568
+ method: 'GET',
569
+ url: '/',
570
+ headers: {
571
+ 'access-control-request-method': 'GET',
572
+ origin: 'example.com'
573
+ }
574
+ }, (err, res) => {
575
+ t.assert.ifError(err)
576
+ t.assert.strictEqual(res.statusCode, 500)
577
+ })
578
+ await sleep()
579
+ })
580
+
581
+ test('Should support custom hook with dynamic config (Promise)', async t => {
582
+ t.plan(16)
583
+
584
+ const configs = [{
585
+ origin: 'example.com',
586
+ methods: 'GET',
587
+ credentials: true,
588
+ exposedHeaders: ['foo', 'bar'],
589
+ allowedHeaders: ['baz', 'woo'],
590
+ maxAge: 123
591
+ }, {
592
+ origin: 'sample.com',
593
+ methods: 'GET',
594
+ credentials: true,
595
+ exposedHeaders: ['zoo', 'bar'],
596
+ allowedHeaders: ['baz', 'foo'],
597
+ maxAge: 321
598
+ }]
599
+
600
+ const fastify = Fastify()
601
+ let requestId = 0
602
+ const configDelegation = async function (req) {
603
+ // request should have id
604
+ t.assert.ok(req.id)
605
+ // request should not have send
606
+ t.assert.ifError(req.send)
607
+ const config = configs[requestId]
608
+ requestId++
609
+ if (config) {
610
+ return Promise.resolve(config)
611
+ } else {
612
+ return Promise.reject(new Error('ouch'))
613
+ }
614
+ }
615
+
616
+ await fastify.register(cors, {
617
+ hook: 'preParsing',
618
+ delegator: configDelegation
619
+ })
620
+
621
+ fastify.get('/', (_req, reply) => {
622
+ reply.send('ok')
623
+ })
624
+
625
+ let res = await fastify.inject({
626
+ method: 'GET',
627
+ url: '/'
628
+ })
629
+ t.assert.ok(res)
630
+ delete res.headers.date
631
+ t.assert.strictEqual(res.statusCode, 200)
632
+ t.assert.strictEqual(res.payload, 'ok')
633
+ let actualHeaders = {
634
+ 'access-control-allow-origin': res.headers['access-control-allow-origin'],
635
+ 'access-control-allow-credentials': res.headers['access-control-allow-credentials'],
636
+ 'access-control-expose-headers': res.headers['access-control-expose-headers'],
637
+ 'content-length': res.headers['content-length'],
638
+ vary: res.headers.vary
639
+ }
640
+
641
+ t.assert.deepStrictEqual(actualHeaders, {
642
+ 'access-control-allow-origin': 'example.com',
643
+ 'access-control-allow-credentials': 'true',
644
+ 'access-control-expose-headers': 'foo, bar',
645
+ 'content-length': '2',
646
+ vary: 'Origin'
647
+ })
648
+
649
+ res = await fastify.inject({
650
+ method: 'OPTIONS',
651
+ url: '/',
652
+ headers: {
653
+ 'access-control-request-method': 'GET',
654
+ origin: 'example.com'
655
+ }
656
+ })
657
+ t.assert.ok(res)
658
+ delete res.headers.date
659
+ t.assert.strictEqual(res.statusCode, 204)
660
+ t.assert.strictEqual(res.payload, '')
661
+ actualHeaders = {
662
+ 'access-control-allow-origin': res.headers['access-control-allow-origin'],
663
+ 'access-control-allow-credentials': res.headers['access-control-allow-credentials'],
664
+ 'access-control-expose-headers': res.headers['access-control-expose-headers'],
665
+ 'access-control-allow-methods': res.headers['access-control-allow-methods'],
666
+ 'access-control-allow-headers': res.headers['access-control-allow-headers'],
667
+ 'access-control-max-age': res.headers['access-control-max-age'],
668
+ 'content-length': res.headers['content-length'],
669
+ vary: res.headers.vary
670
+ }
671
+ t.assert.deepStrictEqual(actualHeaders, {
672
+ 'access-control-allow-origin': 'sample.com',
673
+ 'access-control-allow-credentials': 'true',
674
+ 'access-control-expose-headers': 'zoo, bar',
675
+ 'access-control-allow-methods': 'GET',
676
+ 'access-control-allow-headers': 'baz, foo',
677
+ 'access-control-max-age': '321',
678
+ 'content-length': '0',
679
+ vary: 'Origin'
680
+ })
681
+
682
+ res = await fastify.inject({
683
+ method: 'GET',
684
+ url: '/',
685
+ headers: {
686
+ 'access-control-request-method': 'GET',
687
+ origin: 'example.com'
688
+ }
689
+ })
690
+ t.assert.ok(res)
691
+ t.assert.strictEqual(res.statusCode, 500)
692
+ })
693
+
694
+ test('Should support custom hook with dynamic config (Promise), but should error /1', async t => {
695
+ t.plan(6)
696
+
697
+ const fastify = Fastify()
698
+ const configDelegation = function () {
699
+ return false
700
+ }
701
+
702
+ await fastify.register(cors, {
703
+ hook: 'preParsing',
704
+ delegator: configDelegation
705
+ })
706
+
707
+ fastify.get('/', (_req, reply) => {
708
+ reply.send('ok')
709
+ })
710
+
711
+ let res = await fastify.inject({
712
+ method: 'OPTIONS',
713
+ url: '/',
714
+ headers: {
715
+ 'access-control-request-method': 'GET',
716
+ origin: 'example.com'
717
+ }
718
+ })
719
+ t.assert.ok(res)
720
+ delete res.headers.date
721
+ t.assert.strictEqual(res.statusCode, 500)
722
+ t.assert.strictEqual(res.payload, '{"statusCode":500,"error":"Internal Server Error","message":"Invalid CORS origin option"}')
723
+ const actualHeaders = {
724
+ 'content-length': res.headers['content-length']
725
+ }
726
+ t.assert.deepStrictEqual(actualHeaders, {
727
+ 'content-length': '89'
728
+ })
729
+
730
+ res = await fastify.inject({
731
+ method: 'GET',
732
+ url: '/',
733
+ headers: {
734
+ 'access-control-request-method': 'GET',
735
+ origin: 'example.com'
736
+ }
737
+ })
738
+ t.assert.ok(res)
739
+ t.assert.strictEqual(res.statusCode, 500)
740
+ })
741
+
742
+ test('Should support custom hook with dynamic config (Promise), but should error /2', async t => {
743
+ t.plan(6)
744
+
745
+ const fastify = Fastify()
746
+ const configDelegation = function () {
747
+ return false
748
+ }
749
+
750
+ await fastify.register(cors, {
751
+ delegator: configDelegation
752
+ })
753
+
754
+ fastify.get('/', (_req, reply) => {
755
+ reply.send('ok')
756
+ })
757
+
758
+ let res = await fastify.inject({
759
+ method: 'OPTIONS',
760
+ url: '/',
761
+ headers: {
762
+ 'access-control-request-method': 'GET',
763
+ origin: 'example.com'
764
+ }
765
+ })
766
+ t.assert.ok(res)
767
+ delete res.headers.date
768
+ t.assert.strictEqual(res.statusCode, 500)
769
+ t.assert.strictEqual(res.payload, '{"statusCode":500,"error":"Internal Server Error","message":"Invalid CORS origin option"}')
770
+ const actualHeaders = {
771
+ 'content-length': res.headers['content-length']
772
+ }
773
+ t.assert.deepStrictEqual(actualHeaders, {
774
+ 'content-length': '89'
775
+ })
776
+
777
+ res = await fastify.inject({
778
+ method: 'GET',
779
+ url: '/',
780
+ headers: {
781
+ 'access-control-request-method': 'GET',
782
+ origin: 'example.com'
783
+ }
784
+ })
785
+ t.assert.ok(res)
786
+ t.assert.strictEqual(res.statusCode, 500)
787
+ })
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/cors/test/preflight.test.js ADDED
@@ -0,0 +1,590 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict'
2
+
3
+ const { test } = require('node:test')
4
+ const Fastify = require('fastify')
5
+ const cors = require('../')
6
+
7
+ test('Should reply to preflight requests', async t => {
8
+ t.plan(4)
9
+
10
+ const fastify = Fastify()
11
+ await fastify.register(cors)
12
+
13
+ const res = await fastify.inject({
14
+ method: 'OPTIONS',
15
+ url: '/',
16
+ headers: {
17
+ 'access-control-request-method': 'GET',
18
+ origin: 'example.com'
19
+ }
20
+ })
21
+ t.assert.ok(res)
22
+ delete res.headers.date
23
+ t.assert.strictEqual(res.statusCode, 204)
24
+ t.assert.strictEqual(res.payload, '')
25
+ const actualHeaders = {
26
+ 'access-control-allow-origin': res.headers['access-control-allow-origin'],
27
+ 'access-control-allow-methods': res.headers['access-control-allow-methods'],
28
+ vary: res.headers.vary,
29
+ 'content-length': res.headers['content-length']
30
+ }
31
+ t.assert.deepStrictEqual(actualHeaders, {
32
+ 'access-control-allow-origin': '*',
33
+ 'access-control-allow-methods': 'GET,HEAD,POST',
34
+ vary: 'Access-Control-Request-Headers',
35
+ 'content-length': '0'
36
+ })
37
+ })
38
+
39
+ test('Should add access-control-allow-headers to response if preflight req has access-control-request-headers', async t => {
40
+ t.plan(4)
41
+
42
+ const fastify = Fastify()
43
+ await fastify.register(cors)
44
+
45
+ const res = await fastify.inject({
46
+ method: 'OPTIONS',
47
+ url: '/',
48
+ headers: {
49
+ 'access-control-request-headers': 'x-requested-with',
50
+ 'access-control-request-method': 'GET',
51
+ origin: 'example.com'
52
+ }
53
+
54
+ })
55
+ t.assert.ok(res)
56
+ delete res.headers.date
57
+ t.assert.strictEqual(res.statusCode, 204)
58
+ t.assert.strictEqual(res.payload, '')
59
+ const actualHeaders = {
60
+ 'access-control-allow-origin': res.headers['access-control-allow-origin'],
61
+ 'access-control-allow-methods': res.headers['access-control-allow-methods'],
62
+ 'access-control-allow-headers': res.headers['access-control-allow-headers'],
63
+ vary: res.headers.vary,
64
+ 'content-length': res.headers['content-length']
65
+ }
66
+ t.assert.deepStrictEqual(actualHeaders, {
67
+ 'access-control-allow-origin': '*',
68
+ 'access-control-allow-methods': 'GET,HEAD,POST',
69
+ 'access-control-allow-headers': 'x-requested-with',
70
+ vary: 'Access-Control-Request-Headers',
71
+ 'content-length': '0'
72
+ })
73
+ })
74
+
75
+ test('Should reply to preflight requests with custom status code', async t => {
76
+ t.plan(4)
77
+
78
+ const fastify = Fastify()
79
+ await fastify.register(cors, { optionsSuccessStatus: 200 })
80
+
81
+ const res = await fastify.inject({
82
+ method: 'OPTIONS',
83
+ url: '/',
84
+ headers: {
85
+ 'access-control-request-method': 'GET',
86
+ origin: 'example.com'
87
+ }
88
+ })
89
+ t.assert.ok(res)
90
+ delete res.headers.date
91
+ t.assert.strictEqual(res.statusCode, 200)
92
+ t.assert.strictEqual(res.payload, '')
93
+ const actualHeaders = {
94
+ 'access-control-allow-origin': res.headers['access-control-allow-origin'],
95
+ 'access-control-allow-methods': res.headers['access-control-allow-methods'],
96
+ vary: res.headers.vary,
97
+ 'content-length': res.headers['content-length']
98
+ }
99
+ t.assert.deepStrictEqual(actualHeaders, {
100
+ 'access-control-allow-origin': '*',
101
+ 'access-control-allow-methods': 'GET,HEAD,POST',
102
+ vary: 'Access-Control-Request-Headers',
103
+ 'content-length': '0'
104
+ })
105
+ })
106
+
107
+ test('Should be able to override preflight response with a route', async t => {
108
+ t.plan(5)
109
+
110
+ const fastify = Fastify()
111
+ await fastify.register(cors, { preflightContinue: true })
112
+
113
+ fastify.options('/', (_req, reply) => {
114
+ reply.send('ok')
115
+ })
116
+
117
+ const res = await fastify.inject({
118
+ method: 'OPTIONS',
119
+ url: '/',
120
+ headers: {
121
+ 'access-control-request-method': 'GET',
122
+ origin: 'example.com'
123
+ }
124
+ })
125
+ t.assert.ok(res)
126
+ delete res.headers.date
127
+ t.assert.strictEqual(res.statusCode, 200)
128
+ t.assert.strictEqual(res.payload, 'ok')
129
+ const actualHeaders = {
130
+ 'access-control-allow-origin': res.headers['access-control-allow-origin']
131
+ }
132
+ t.assert.deepStrictEqual(actualHeaders, {
133
+ // Only the base cors headers and no preflight headers
134
+ 'access-control-allow-origin': '*'
135
+ })
136
+ t.assert.notStrictEqual(res.headers.vary, 'Origin')
137
+ })
138
+
139
+ test('Should reply to all options requests', async t => {
140
+ t.plan(4)
141
+
142
+ const fastify = Fastify()
143
+ await fastify.register(cors)
144
+
145
+ const res = await fastify.inject({
146
+ method: 'OPTIONS',
147
+ url: '/hello',
148
+ headers: {
149
+ 'access-control-request-method': 'GET',
150
+ origin: 'example.com'
151
+ }
152
+ })
153
+ t.assert.ok(res)
154
+ delete res.headers.date
155
+ t.assert.strictEqual(res.statusCode, 204)
156
+ t.assert.strictEqual(res.payload, '')
157
+ const actualHeaders = {
158
+ 'access-control-allow-origin': res.headers['access-control-allow-origin'],
159
+ 'access-control-allow-methods': res.headers['access-control-allow-methods'],
160
+ vary: res.headers.vary,
161
+ 'content-length': res.headers['content-length']
162
+ }
163
+ t.assert.deepStrictEqual(actualHeaders, {
164
+ 'access-control-allow-origin': '*',
165
+ 'access-control-allow-methods': 'GET,HEAD,POST',
166
+ vary: 'Access-Control-Request-Headers',
167
+ 'content-length': '0'
168
+ })
169
+ })
170
+
171
+ test('Should support a prefix for preflight requests', async t => {
172
+ t.plan(6)
173
+
174
+ const fastify = Fastify()
175
+ await fastify.register((instance, _opts, next) => {
176
+ instance.register(cors)
177
+ next()
178
+ }, { prefix: '/subsystem' })
179
+
180
+ let res = await fastify.inject({
181
+ method: 'OPTIONS',
182
+ url: '/hello'
183
+ })
184
+ t.assert.ok(res)
185
+ t.assert.strictEqual(res.statusCode, 404)
186
+
187
+ res = await fastify.inject({
188
+ method: 'OPTIONS',
189
+ url: '/subsystem/hello',
190
+ headers: {
191
+ 'access-control-request-method': 'GET',
192
+ origin: 'example.com'
193
+ }
194
+ })
195
+ t.assert.ok(res)
196
+ delete res.headers.date
197
+ t.assert.strictEqual(res.statusCode, 204)
198
+ t.assert.strictEqual(res.payload, '')
199
+ const actualHeaders = {
200
+ 'access-control-allow-origin': res.headers['access-control-allow-origin'],
201
+ 'access-control-allow-methods': res.headers['access-control-allow-methods'],
202
+ vary: res.headers.vary,
203
+ 'content-length': res.headers['content-length']
204
+ }
205
+ t.assert.deepStrictEqual(actualHeaders, {
206
+ 'access-control-allow-origin': '*',
207
+ 'access-control-allow-methods': 'GET,HEAD,POST',
208
+ vary: 'Access-Control-Request-Headers',
209
+ 'content-length': '0'
210
+ })
211
+ })
212
+
213
+ test('hide options route by default', async t => {
214
+ t.plan(2)
215
+
216
+ const fastify = Fastify()
217
+
218
+ fastify.addHook('onRoute', (route) => {
219
+ if (route.method === 'OPTIONS' && route.url === '*') {
220
+ t.assert.strictEqual(route.schema.hide, true)
221
+ }
222
+ })
223
+ await fastify.register(cors)
224
+
225
+ const ready = await fastify.ready()
226
+ t.assert.ok(ready)
227
+ })
228
+
229
+ test('show options route', async t => {
230
+ t.plan(2)
231
+
232
+ const fastify = Fastify()
233
+
234
+ fastify.addHook('onRoute', (route) => {
235
+ if (route.method === 'OPTIONS' && route.url === '*') {
236
+ t.assert.strictEqual(route.schema.hide, false)
237
+ }
238
+ })
239
+ await fastify.register(cors, { hideOptionsRoute: false })
240
+
241
+ const ready = await fastify.ready()
242
+ t.assert.ok(ready)
243
+ })
244
+
245
+ test('Allow only request from with specific methods', async t => {
246
+ t.plan(4)
247
+
248
+ const fastify = Fastify()
249
+ await fastify.register(cors, { methods: ['GET', 'POST'] })
250
+
251
+ const res = await fastify.inject({
252
+ method: 'OPTIONS',
253
+ url: '/',
254
+ headers: {
255
+ 'access-control-request-method': 'GET',
256
+ origin: 'example.com'
257
+ }
258
+ })
259
+ t.assert.ok(res)
260
+ delete res.headers.date
261
+ t.assert.strictEqual(res.statusCode, 204)
262
+ const actualHeaders = {
263
+ 'access-control-allow-methods': res.headers['access-control-allow-methods']
264
+ }
265
+ t.assert.deepStrictEqual(actualHeaders, {
266
+ 'access-control-allow-methods': 'GET, POST'
267
+ })
268
+ t.assert.notStrictEqual(res.headers.vary, 'Origin')
269
+ })
270
+
271
+ test('Should reply with 400 error to OPTIONS requests missing origin header when default strictPreflight', async t => {
272
+ t.plan(3)
273
+
274
+ const fastify = Fastify()
275
+ await fastify.register(cors)
276
+
277
+ const res = await fastify.inject({
278
+ method: 'OPTIONS',
279
+ url: '/',
280
+ headers: {
281
+ 'access-control-request-method': 'GET'
282
+ }
283
+ })
284
+ t.assert.ok(res)
285
+ t.assert.strictEqual(res.statusCode, 400)
286
+ t.assert.strictEqual(res.payload, 'Invalid Preflight Request')
287
+ })
288
+
289
+ test('Should reply with 400 to OPTIONS requests when missing Access-Control-Request-Method header when default strictPreflight', async t => {
290
+ t.plan(3)
291
+
292
+ const fastify = Fastify()
293
+ await fastify.register(cors, {
294
+ strictPreflight: true
295
+ })
296
+
297
+ const res = await fastify.inject({
298
+ method: 'OPTIONS',
299
+ url: '/',
300
+ headers: {
301
+ origin: 'example.com'
302
+ }
303
+ })
304
+ t.assert.ok(res)
305
+ t.assert.strictEqual(res.statusCode, 400)
306
+ t.assert.strictEqual(res.payload, 'Invalid Preflight Request')
307
+ })
308
+
309
+ test('Should reply to all preflight requests when strictPreflight is disabled', async t => {
310
+ t.plan(4)
311
+
312
+ const fastify = Fastify()
313
+ await fastify.register(cors, { strictPreflight: false })
314
+
315
+ const res = await fastify.inject({
316
+ method: 'OPTIONS',
317
+ url: '/'
318
+ // No access-control-request-method or origin headers
319
+ })
320
+ t.assert.ok(res)
321
+ delete res.headers.date
322
+ t.assert.strictEqual(res.statusCode, 204)
323
+ t.assert.strictEqual(res.payload, '')
324
+ const actualHeaders = {
325
+ 'access-control-allow-origin': res.headers['access-control-allow-origin'],
326
+ 'access-control-allow-methods': res.headers['access-control-allow-methods'],
327
+ vary: res.headers.vary,
328
+ 'content-length': res.headers['content-length']
329
+ }
330
+ t.assert.deepStrictEqual(actualHeaders, {
331
+ 'access-control-allow-origin': '*',
332
+ 'access-control-allow-methods': 'GET,HEAD,POST',
333
+ vary: 'Access-Control-Request-Headers',
334
+ 'content-length': '0'
335
+ })
336
+ })
337
+
338
+ test('Default empty 200 response with preflightContinue on OPTIONS routes', async t => {
339
+ t.plan(4)
340
+
341
+ const fastify = Fastify()
342
+ await fastify.register(cors, { preflightContinue: true })
343
+
344
+ const res = await fastify.inject({
345
+ method: 'OPTIONS',
346
+ url: '/doesnotexist',
347
+ headers: {
348
+ 'access-control-request-method': 'GET',
349
+ origin: 'example.com'
350
+ }
351
+ })
352
+ t.assert.ok(res)
353
+ delete res.headers.date
354
+ t.assert.strictEqual(res.statusCode, 200)
355
+ t.assert.strictEqual(res.payload, '')
356
+ const actualHeaders = {
357
+ 'access-control-allow-origin': res.headers['access-control-allow-origin'],
358
+ 'access-control-allow-methods': res.headers['access-control-allow-methods'],
359
+ vary: res.headers.vary
360
+ }
361
+ t.assert.deepStrictEqual(actualHeaders, {
362
+ 'access-control-allow-origin': '*',
363
+ 'access-control-allow-methods': 'GET,HEAD,POST',
364
+ vary: 'Access-Control-Request-Headers'
365
+ })
366
+ })
367
+
368
+ test('Can override preflight response with preflightContinue', async t => {
369
+ t.plan(4)
370
+
371
+ const fastify = Fastify()
372
+ await fastify.register(cors, { preflightContinue: true })
373
+
374
+ fastify.options('/', (_req, reply) => {
375
+ reply.send('ok')
376
+ })
377
+
378
+ const res = await fastify.inject({
379
+ method: 'OPTIONS',
380
+ url: '/',
381
+ headers: {
382
+ 'access-control-request-method': 'GET',
383
+ origin: 'example.com'
384
+ }
385
+ })
386
+ t.assert.ok(res)
387
+ delete res.headers.date
388
+ t.assert.strictEqual(res.statusCode, 200)
389
+ t.assert.strictEqual(res.payload, 'ok')
390
+ const actualHeaders = {
391
+ 'access-control-allow-origin': res.headers['access-control-allow-origin'],
392
+ 'access-control-allow-methods': res.headers['access-control-allow-methods'],
393
+ vary: res.headers.vary
394
+ }
395
+ t.assert.deepStrictEqual(actualHeaders, {
396
+ 'access-control-allow-origin': '*',
397
+ 'access-control-allow-methods': 'GET,HEAD,POST',
398
+ vary: 'Access-Control-Request-Headers'
399
+ })
400
+ })
401
+
402
+ test('Should support ongoing prefix ', async t => {
403
+ t.plan(12)
404
+
405
+ const fastify = Fastify()
406
+
407
+ await fastify.register(async (instance) => {
408
+ instance.register(cors)
409
+ }, { prefix: '/prefix' })
410
+
411
+ // support prefixed route
412
+ let res = await fastify.inject({
413
+ method: 'OPTIONS',
414
+ url: '/prefix',
415
+ headers: {
416
+ 'access-control-request-method': 'GET',
417
+ origin: 'example.com'
418
+ }
419
+ })
420
+ t.assert.ok(res)
421
+ delete res.headers.date
422
+ t.assert.strictEqual(res.statusCode, 204)
423
+ t.assert.strictEqual(res.payload, '')
424
+ let actualHeaders = {
425
+ 'access-control-allow-origin': res.headers['access-control-allow-origin'],
426
+ 'access-control-allow-methods': res.headers['access-control-allow-methods'],
427
+ vary: res.headers.vary,
428
+ 'content-length': res.headers['content-length']
429
+ }
430
+ t.assert.deepStrictEqual(actualHeaders, {
431
+ 'access-control-allow-origin': '*',
432
+ 'access-control-allow-methods': 'GET,HEAD,POST',
433
+ vary: 'Access-Control-Request-Headers',
434
+ 'content-length': '0'
435
+ })
436
+
437
+ // support prefixed route without / continue
438
+ res = await fastify.inject({
439
+ method: 'OPTIONS',
440
+ url: '/prefixfoo',
441
+ headers: {
442
+ 'access-control-request-method': 'GET',
443
+ origin: 'example.com'
444
+ }
445
+ })
446
+ t.assert.ok(res)
447
+ delete res.headers.date
448
+ t.assert.strictEqual(res.statusCode, 204)
449
+ t.assert.strictEqual(res.payload, '')
450
+ actualHeaders = {
451
+ 'access-control-allow-origin': res.headers['access-control-allow-origin'],
452
+ 'access-control-allow-methods': res.headers['access-control-allow-methods'],
453
+ vary: res.headers.vary,
454
+ 'content-length': res.headers['content-length']
455
+ }
456
+ t.assert.deepStrictEqual(actualHeaders, {
457
+ 'access-control-allow-origin': '*',
458
+ 'access-control-allow-methods': 'GET,HEAD,POST',
459
+ vary: 'Access-Control-Request-Headers',
460
+ 'content-length': '0'
461
+ })
462
+
463
+ // support prefixed route with / continue
464
+ res = await fastify.inject({
465
+ method: 'OPTIONS',
466
+ url: '/prefix/foo',
467
+ headers: {
468
+ 'access-control-request-method': 'GET',
469
+ origin: 'example.com'
470
+ }
471
+ })
472
+ t.assert.ok(res)
473
+ delete res.headers.date
474
+ t.assert.strictEqual(res.statusCode, 204)
475
+ t.assert.strictEqual(res.payload, '')
476
+ actualHeaders = {
477
+ 'access-control-allow-origin': res.headers['access-control-allow-origin'],
478
+ 'access-control-allow-methods': res.headers['access-control-allow-methods'],
479
+ vary: res.headers.vary,
480
+ 'content-length': res.headers['content-length']
481
+ }
482
+ t.assert.deepStrictEqual(actualHeaders, {
483
+ 'access-control-allow-origin': '*',
484
+ 'access-control-allow-methods': 'GET,HEAD,POST',
485
+ vary: 'Access-Control-Request-Headers',
486
+ 'content-length': '0'
487
+ })
488
+ })
489
+
490
+ test('Silences preflight logs when logLevel is "silent"', async t => {
491
+ const logs = []
492
+ const fastify = Fastify({
493
+ logger: {
494
+ level: 'info',
495
+ stream: {
496
+ write (line) {
497
+ try {
498
+ logs.push(JSON.parse(line))
499
+ } catch {
500
+ }
501
+ }
502
+ }
503
+ }
504
+ })
505
+
506
+ await fastify.register(cors, { logLevel: 'silent' })
507
+
508
+ fastify.get('/', async () => ({ ok: true }))
509
+
510
+ await fastify.ready()
511
+ t.assert.ok(fastify)
512
+
513
+ await fastify.inject({
514
+ method: 'OPTIONS',
515
+ url: '/',
516
+ headers: {
517
+ 'access-control-request-method': 'GET',
518
+ origin: 'https://example.com'
519
+ }
520
+ })
521
+
522
+ await fastify.inject({ method: 'GET', url: '/' })
523
+
524
+ const hasOptionsLog = logs.some(l => l.req && l.req.method === 'OPTIONS')
525
+ const hasGetLog = logs.some(l => l.req && l.req.method === 'GET')
526
+
527
+ t.assert.strictEqual(hasOptionsLog, false)
528
+ t.assert.strictEqual(hasGetLog, true)
529
+
530
+ await fastify.close()
531
+ })
532
+ test('delegator + logLevel:"silent" → OPTIONS logs are suppressed', async t => {
533
+ t.plan(3)
534
+
535
+ const logs = []
536
+ const app = Fastify({
537
+ logger: {
538
+ level: 'info',
539
+ stream: { write: l => { try { logs.push(JSON.parse(l)) } catch {} } }
540
+ }
541
+ })
542
+
543
+ await app.register(cors, {
544
+ delegator: () => ({ origin: '*' }),
545
+ logLevel: 'silent'
546
+ })
547
+
548
+ app.get('/', () => ({ ok: true }))
549
+ await app.ready()
550
+ t.assert.ok(app)
551
+
552
+ await app.inject({
553
+ method: 'OPTIONS',
554
+ url: '/',
555
+ headers: {
556
+ 'access-control-request-method': 'GET',
557
+ origin: 'https://example.com'
558
+ }
559
+ })
560
+
561
+ await app.inject({ method: 'GET', url: '/' })
562
+
563
+ const hasOptionsLog = logs.some(l => l.req?.method === 'OPTIONS')
564
+ const hasGetLog = logs.some(l => l.req?.method === 'GET')
565
+
566
+ t.assert.strictEqual(hasOptionsLog, false)
567
+ t.assert.strictEqual(hasGetLog, true)
568
+
569
+ await app.close()
570
+ })
571
+ test('delegator + hideOptionsRoute:false → OPTIONS route is visible', async t => {
572
+ t.plan(2)
573
+
574
+ const app = Fastify()
575
+
576
+ app.addHook('onRoute', route => {
577
+ if (route.method === 'OPTIONS' && route.url === '*') {
578
+ t.assert.strictEqual(route.schema.hide, false)
579
+ }
580
+ })
581
+
582
+ await app.register(cors, {
583
+ delegator: () => ({ origin: '*' }),
584
+ hideOptionsRoute: false
585
+ })
586
+
587
+ await app.ready()
588
+ t.assert.ok(app)
589
+ await app.close()
590
+ })
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/cors/test/vary.test.js ADDED
@@ -0,0 +1,237 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict'
2
+
3
+ const { test } = require('node:test')
4
+ const { createAddFieldnameToVary } = require('../vary')
5
+ const { parse } = require('../vary')
6
+
7
+ test('Should set * even if we set a specific field', async t => {
8
+ t.plan(1)
9
+
10
+ const addOriginToVary = createAddFieldnameToVary('Origin')
11
+ const replyMock = {
12
+ getHeader () {
13
+ return '*'
14
+ },
15
+ header () {
16
+ t.fail('Should not be here')
17
+ }
18
+ }
19
+
20
+ addOriginToVary(replyMock)
21
+ t.assert.ok(true) // equalivant to tap t.pass()
22
+ })
23
+
24
+ test('Should set * even if we set a specific field', t => {
25
+ t.plan(2)
26
+
27
+ const addWildcardToVary = createAddFieldnameToVary('*')
28
+ const replyMock = {
29
+ getHeader () {
30
+ return 'Origin'
31
+ },
32
+ header (name, value) {
33
+ t.assert.deepStrictEqual(name, 'Vary')
34
+ t.assert.deepStrictEqual(value, '*')
35
+ }
36
+ }
37
+
38
+ addWildcardToVary(replyMock)
39
+ })
40
+
41
+ test('Should set * when field contains a *', t => {
42
+ t.plan(3)
43
+
44
+ const addOriginToVary = createAddFieldnameToVary('Origin')
45
+ const replyMock = {
46
+ getHeader () {
47
+ return ['Origin', '*', 'Access-Control-Request-Headers']
48
+ },
49
+ header (name, value) {
50
+ t.assert.deepStrictEqual(name, 'Vary')
51
+ t.assert.deepStrictEqual(value, '*')
52
+ }
53
+ }
54
+
55
+ addOriginToVary(replyMock)
56
+ t.assert.ok(true) // equalivant to tap t.pass()
57
+ })
58
+
59
+ test('Should concat vary values', t => {
60
+ t.plan(3)
61
+
62
+ const addOriginToVary = createAddFieldnameToVary('Origin')
63
+ const replyMock = {
64
+ getHeader () {
65
+ return 'Access-Control-Request-Headers'
66
+ },
67
+ header (name, value) {
68
+ t.assert.deepStrictEqual(name, 'Vary')
69
+ t.assert.deepStrictEqual(value, 'Access-Control-Request-Headers, Origin')
70
+ }
71
+ }
72
+
73
+ addOriginToVary(replyMock)
74
+ t.assert.ok(true) // equalivant to tap t.pass()
75
+ })
76
+
77
+ test('Should concat vary values ignoring consecutive commas', t => {
78
+ t.plan(3)
79
+
80
+ const addOriginToVary = createAddFieldnameToVary('Origin')
81
+ const replyMock = {
82
+ getHeader () {
83
+ return ' Access-Control-Request-Headers,Access-Control-Request-Method'
84
+ },
85
+ header (name, value) {
86
+ t.assert.deepStrictEqual(name, 'Vary')
87
+ t.assert.deepStrictEqual(value, ' Access-Control-Request-Headers,Access-Control-Request-Method, Origin')
88
+ }
89
+ }
90
+
91
+ addOriginToVary(replyMock)
92
+ t.assert.ok(true) // equalivant to tap t.pass()
93
+ })
94
+
95
+ test('Should concat vary values ignoring whitespace', t => {
96
+ t.plan(3)
97
+
98
+ const addOriginToVary = createAddFieldnameToVary('Origin')
99
+ const replyMock = {
100
+ getHeader () {
101
+ return ' Access-Control-Request-Headers ,Access-Control-Request-Method'
102
+ },
103
+ header (name, value) {
104
+ t.assert.deepStrictEqual(name, 'Vary')
105
+ t.assert.deepStrictEqual(value, ' Access-Control-Request-Headers ,Access-Control-Request-Method, Origin')
106
+ }
107
+ }
108
+
109
+ addOriginToVary(replyMock)
110
+ t.assert.ok(true) // equalivant to tap t.pass()
111
+ })
112
+
113
+ test('Should set the field as value for vary if no vary is defined', t => {
114
+ t.plan(2)
115
+
116
+ const addOriginToVary = createAddFieldnameToVary('Origin')
117
+ const replyMock = {
118
+ getHeader () {
119
+ return undefined
120
+ },
121
+ header (name, value) {
122
+ t.assert.deepStrictEqual(name, 'Vary')
123
+ t.assert.deepStrictEqual(value, 'Origin')
124
+ }
125
+ }
126
+
127
+ addOriginToVary(replyMock)
128
+ })
129
+
130
+ test('Should set * as value for vary if vary contains *', t => {
131
+ t.plan(2)
132
+
133
+ const addOriginToVary = createAddFieldnameToVary('Origin')
134
+ const replyMock = {
135
+ getHeader () {
136
+ return 'Accept,*'
137
+ },
138
+ header (name, value) {
139
+ t.assert.deepStrictEqual(name, 'Vary')
140
+ t.assert.deepStrictEqual(value, '*')
141
+ }
142
+ }
143
+
144
+ addOriginToVary(replyMock)
145
+ })
146
+
147
+ test('Should set Accept-Encoding as value for vary if vary is empty string', t => {
148
+ t.plan(2)
149
+
150
+ const addAcceptEncodingToVary = createAddFieldnameToVary('Accept-Encoding')
151
+ const replyMock = {
152
+ getHeader () {
153
+ return ''
154
+ },
155
+ header (name, value) {
156
+ t.assert.deepStrictEqual(name, 'Vary')
157
+ t.assert.deepStrictEqual(value, 'Accept-Encoding')
158
+ }
159
+ }
160
+
161
+ addAcceptEncodingToVary(replyMock)
162
+ })
163
+
164
+ test('Should have no issues with values containing dashes', t => {
165
+ t.plan(2)
166
+
167
+ const addXFooToVary = createAddFieldnameToVary('X-Foo')
168
+ const replyMock = {
169
+ value: 'Accept-Encoding',
170
+ getHeader () {
171
+ return this.value
172
+ },
173
+ header (name, value) {
174
+ t.assert.deepStrictEqual(name, 'Vary')
175
+ t.assert.deepStrictEqual(value, 'Accept-Encoding, X-Foo')
176
+ this.value = value
177
+ }
178
+ }
179
+
180
+ addXFooToVary(replyMock)
181
+ addXFooToVary(replyMock)
182
+ })
183
+
184
+ test('Should ignore the header as value for vary if it is already in vary', t => {
185
+ t.plan(1)
186
+
187
+ const addOriginToVary = createAddFieldnameToVary('Origin')
188
+ const replyMock = {
189
+ getHeader () {
190
+ return 'Origin'
191
+ },
192
+ header () {
193
+ t.fail('Should not be here')
194
+ }
195
+ }
196
+ addOriginToVary(replyMock)
197
+ addOriginToVary(replyMock)
198
+
199
+ t.assert.ok(true) // equalivant to tap t.pass()
200
+ })
201
+
202
+ test('parse', t => {
203
+ t.plan(18)
204
+ t.assert.deepStrictEqual(parse(''), [])
205
+ t.assert.deepStrictEqual(parse('a'), ['a'])
206
+ t.assert.deepStrictEqual(parse('a,b'), ['a', 'b'])
207
+ t.assert.deepStrictEqual(parse(' a,b'), ['a', 'b'])
208
+ t.assert.deepStrictEqual(parse('a,b '), ['a', 'b'])
209
+ t.assert.deepStrictEqual(parse('a,b,c'), ['a', 'b', 'c'])
210
+ t.assert.deepStrictEqual(parse('A,b,c'), ['a', 'b', 'c'])
211
+ t.assert.deepStrictEqual(parse('a,b,c,'), ['a', 'b', 'c'])
212
+ t.assert.deepStrictEqual(parse('a,b,c, '), ['a', 'b', 'c'])
213
+ t.assert.deepStrictEqual(parse(',a,b,c'), ['a', 'b', 'c'])
214
+ t.assert.deepStrictEqual(parse(' ,a,b,c'), ['a', 'b', 'c'])
215
+ t.assert.deepStrictEqual(parse('a,,b,c'), ['a', 'b', 'c'])
216
+ t.assert.deepStrictEqual(parse('a,,,b,,c'), ['a', 'b', 'c'])
217
+ t.assert.deepStrictEqual(parse('a, b,c'), ['a', 'b', 'c'])
218
+ t.assert.deepStrictEqual(parse('a, b,c'), ['a', 'b', 'c'])
219
+ t.assert.deepStrictEqual(parse('a, , b,c'), ['a', 'b', 'c'])
220
+ t.assert.deepStrictEqual(parse('a, , b,c'), ['a', 'b', 'c'])
221
+
222
+ // one for the cache
223
+ t.assert.deepStrictEqual(parse('A,b,c'), ['a', 'b', 'c'])
224
+ })
225
+
226
+ test('createAddFieldnameToVary', async t => {
227
+ t.plan(4)
228
+ t.assert.strictEqual(typeof createAddFieldnameToVary('valid-header'), 'function')
229
+ await t.assert.rejects(
230
+ async () => createAddFieldnameToVary('invalid:header'),
231
+ (err) => {
232
+ t.assert.strictEqual(err.name, 'TypeError')
233
+ t.assert.strictEqual(err.message, 'Fieldname contains invalid characters.')
234
+ return true
235
+ }
236
+ )
237
+ })
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/cors/types/index.d.ts ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /// <reference types="node" />
2
+
3
+ import { FastifyInstance, FastifyPluginCallback, FastifyRequest, LogLevel } from 'fastify'
4
+
5
+ type OriginCallback = (err: Error | null, origin: ValueOrArray<OriginType>) => void
6
+ type OriginType = string | boolean | RegExp
7
+ type ValueOrArray<T> = T | ArrayOfValueOrArray<T>
8
+
9
+ interface ArrayOfValueOrArray<T> extends Array<ValueOrArray<T>> {
10
+ }
11
+
12
+ type FastifyCorsPlugin = FastifyPluginCallback<
13
+ NonNullable<fastifyCors.FastifyCorsOptions> | fastifyCors.FastifyCorsOptionsDelegate
14
+ >
15
+
16
+ type FastifyCorsHook =
17
+ | 'onRequest'
18
+ | 'preParsing'
19
+ | 'preValidation'
20
+ | 'preHandler'
21
+ | 'preSerialization'
22
+ | 'onSend'
23
+
24
+ declare namespace fastifyCors {
25
+ export type OriginFunction = (origin: string | undefined, callback: OriginCallback) => void
26
+ export type AsyncOriginFunction = (origin: string | undefined) => Promise<ValueOrArray<OriginType>>
27
+
28
+ export interface FastifyCorsOptions {
29
+ /**
30
+ * Configures the Lifecycle Hook.
31
+ */
32
+ hook?: FastifyCorsHook;
33
+
34
+ /**
35
+ * Configures the delegate function.
36
+ */
37
+ delegator?: FastifyCorsOptionsDelegate;
38
+
39
+ /**
40
+ * Configures the Access-Control-Allow-Origin CORS header.
41
+ */
42
+ origin?: ValueOrArray<OriginType> | fastifyCors.AsyncOriginFunction | fastifyCors.OriginFunction;
43
+ /**
44
+ * Configures the Access-Control-Allow-Credentials CORS header.
45
+ * Set to true to pass the header, otherwise it is omitted.
46
+ */
47
+ credentials?: boolean;
48
+ /**
49
+ * Configures the Access-Control-Expose-Headers CORS header.
50
+ * Expects a comma-delimited string (ex: 'Content-Range,X-Content-Range')
51
+ * or an array (ex: ['Content-Range', 'X-Content-Range']).
52
+ * If not specified, no custom headers are exposed.
53
+ */
54
+ exposedHeaders?: string | string[];
55
+ /**
56
+ * Configures the Access-Control-Allow-Headers CORS header.
57
+ * Expects a comma-delimited string (ex: 'Content-Type,Authorization')
58
+ * or an array (ex: ['Content-Type', 'Authorization']). If not
59
+ * specified, defaults to reflecting the headers specified in the
60
+ * request's Access-Control-Request-Headers header.
61
+ */
62
+ allowedHeaders?: string | string[];
63
+ /**
64
+ * Configures the Access-Control-Allow-Methods CORS header.
65
+ * Expects a comma-delimited string (ex: 'GET,PUT,POST') or an array (ex: ['GET', 'PUT', 'POST']).
66
+ */
67
+ methods?: string | string[];
68
+ /**
69
+ * Configures the Access-Control-Max-Age CORS header.
70
+ * Set to an integer to pass the header, otherwise it is omitted.
71
+ */
72
+ maxAge?: number;
73
+ /**
74
+ * Configures the Cache-Control header for CORS preflight responses.
75
+ * Set to an integer to pass the header as `Cache-Control: max-age=${cacheControl}`,
76
+ * or set to a string to pass the header as `Cache-Control: ${cacheControl}` (fully define
77
+ * the header value), otherwise the header is omitted.
78
+ */
79
+ cacheControl?: number | string;
80
+ /**
81
+ * Pass the CORS preflight response to the route handler (default: false).
82
+ */
83
+ preflightContinue?: boolean;
84
+ /**
85
+ * Provides a status code to use for successful OPTIONS requests,
86
+ * since some legacy browsers (IE11, various SmartTVs) choke on 204.
87
+ */
88
+ optionsSuccessStatus?: number;
89
+ /**
90
+ * Pass the CORS preflight response to the route handler (default: true).
91
+ */
92
+ preflight?: boolean;
93
+ /**
94
+ * Enforces strict requirement of the CORS preflight request headers (Access-Control-Request-Method and Origin).
95
+ * Preflight requests without the required headers will result in 400 errors when set to `true` (default: `true`).
96
+ */
97
+ strictPreflight?: boolean;
98
+ /**
99
+ * Hide options route from the documentation built using fastify-swagger (default: true).
100
+ */
101
+ hideOptionsRoute?: boolean;
102
+
103
+ /**
104
+ * Sets the Fastify log level specifically for the internal OPTIONS route
105
+ * used to handle CORS preflight requests. For example, setting this to `'silent'`
106
+ * will prevent these requests from being logged.
107
+ * Useful for reducing noise in application logs.
108
+ * Default: inherits Fastify's global log level.
109
+ */
110
+ logLevel?: LogLevel;
111
+ }
112
+
113
+ export interface FastifyCorsOptionsDelegateCallback { (req: FastifyRequest, cb: (error: Error | null, corsOptions?: FastifyCorsOptions) => void): void }
114
+ export interface FastifyCorsOptionsDelegatePromise { (req: FastifyRequest): Promise<FastifyCorsOptions> }
115
+ export type FastifyCorsOptionsDelegate = FastifyCorsOptionsDelegateCallback | FastifyCorsOptionsDelegatePromise
116
+ export type FastifyPluginOptionsDelegate<T = FastifyCorsOptionsDelegate> = (instance: FastifyInstance) => T
117
+
118
+ export const fastifyCors: FastifyCorsPlugin
119
+ export { fastifyCors as default }
120
+ }
121
+
122
+ declare function fastifyCors (
123
+ ...params: Parameters<FastifyCorsPlugin>
124
+ ): ReturnType<FastifyCorsPlugin>
125
+
126
+ export = fastifyCors
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/cors/types/index.test-d.ts ADDED
@@ -0,0 +1,388 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import fastify, { FastifyRequest } from 'fastify'
2
+ import { expectType } from 'tsd'
3
+ import fastifyCors, {
4
+ AsyncOriginFunction,
5
+ FastifyCorsOptions,
6
+ FastifyCorsOptionsDelegate,
7
+ FastifyCorsOptionsDelegatePromise,
8
+ FastifyPluginOptionsDelegate,
9
+ OriginFunction
10
+ } from '..'
11
+
12
+ const app = fastify()
13
+
14
+ app.register(fastifyCors)
15
+
16
+ app.register(fastifyCors, {
17
+ origin: true,
18
+ allowedHeaders: 'authorization,content-type',
19
+ methods: 'GET,POST,PUT,PATCH,DELETE,OPTIONS',
20
+ credentials: true,
21
+ exposedHeaders: 'authorization',
22
+ maxAge: 13000,
23
+ cacheControl: 13000,
24
+ preflightContinue: false,
25
+ optionsSuccessStatus: 200,
26
+ preflight: false,
27
+ strictPreflight: false
28
+ })
29
+
30
+ app.register(fastifyCors, {
31
+ origin: true,
32
+ allowedHeaders: ['authorization', 'content-type'],
33
+ methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
34
+ credentials: true,
35
+ exposedHeaders: ['authorization'],
36
+ maxAge: 13000,
37
+ cacheControl: 'public, max-age=3500',
38
+ preflightContinue: false,
39
+ optionsSuccessStatus: 200,
40
+ preflight: false,
41
+ strictPreflight: false
42
+ })
43
+
44
+ app.register(fastifyCors, {
45
+ origin: '*',
46
+ allowedHeaders: ['authorization', 'content-type'],
47
+ methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
48
+ credentials: true,
49
+ exposedHeaders: ['authorization'],
50
+ maxAge: 13000,
51
+ cacheControl: 13000,
52
+ preflightContinue: false,
53
+ optionsSuccessStatus: 200,
54
+ preflight: false,
55
+ strictPreflight: false
56
+ })
57
+
58
+ app.register(fastifyCors, {
59
+ origin: /\*/,
60
+ allowedHeaders: ['authorization', 'content-type'],
61
+ methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
62
+ credentials: true,
63
+ exposedHeaders: ['authorization'],
64
+ maxAge: 13000,
65
+ cacheControl: 13000,
66
+ preflightContinue: false,
67
+ optionsSuccessStatus: 200,
68
+ preflight: false,
69
+ strictPreflight: false
70
+ })
71
+
72
+ app.register(fastifyCors, {
73
+ origin: ['*', 'something'],
74
+ allowedHeaders: ['authorization', 'content-type'],
75
+ methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
76
+ credentials: true,
77
+ exposedHeaders: ['authorization'],
78
+ maxAge: 13000,
79
+ cacheControl: 13000,
80
+ preflightContinue: false,
81
+ optionsSuccessStatus: 200,
82
+ preflight: false,
83
+ strictPreflight: false
84
+ })
85
+
86
+ app.register(fastifyCors, {
87
+ origin: [/\*/, /something/],
88
+ allowedHeaders: ['authorization', 'content-type'],
89
+ methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
90
+ credentials: true,
91
+ exposedHeaders: ['authorization'],
92
+ maxAge: 13000,
93
+ cacheControl: 13000,
94
+ preflightContinue: false,
95
+ optionsSuccessStatus: 200,
96
+ preflight: false,
97
+ strictPreflight: false
98
+ })
99
+
100
+ const corsDelegate: OriginFunction = (origin, cb) => {
101
+ if (origin === undefined || /localhost/.test(origin)) {
102
+ cb(null, true)
103
+ return
104
+ }
105
+ cb(new Error(), false)
106
+ }
107
+
108
+ app.register(fastifyCors, {
109
+ origin: corsDelegate,
110
+ allowedHeaders: ['authorization', 'content-type'],
111
+ methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
112
+ credentials: true,
113
+ exposedHeaders: ['authorization'],
114
+ maxAge: 13000,
115
+ cacheControl: 13000,
116
+ optionsSuccessStatus: 200,
117
+ preflight: false,
118
+ strictPreflight: false
119
+ })
120
+
121
+ const asyncCorsDelegate: OriginFunction = async (origin) => {
122
+ if (origin === undefined || /localhost/.test(origin)) {
123
+ return true
124
+ }
125
+ return false
126
+ }
127
+
128
+ app.register(fastifyCors, {
129
+ origin: asyncCorsDelegate,
130
+ allowedHeaders: ['authorization', 'content-type'],
131
+ methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
132
+ credentials: true,
133
+ exposedHeaders: ['authorization'],
134
+ maxAge: 13000,
135
+ cacheControl: 13000,
136
+ optionsSuccessStatus: 200,
137
+ preflight: false,
138
+ strictPreflight: false
139
+ })
140
+
141
+ app.register(fastifyCors, {
142
+ origin: (_origin, cb) => cb(null, true)
143
+ })
144
+
145
+ app.register(fastifyCors, {
146
+ origin: (_origin, cb) => cb(null, '*')
147
+ })
148
+
149
+ app.register(fastifyCors, {
150
+ origin: (_origin, cb) => cb(null, /\*/)
151
+ })
152
+
153
+ const appHttp2 = fastify({ http2: true })
154
+
155
+ appHttp2.register(fastifyCors)
156
+
157
+ appHttp2.register(fastifyCors, {
158
+ origin: true,
159
+ allowedHeaders: 'authorization,content-type',
160
+ methods: 'GET,POST,PUT,PATCH,DELETE,OPTIONS',
161
+ credentials: true,
162
+ exposedHeaders: 'authorization',
163
+ maxAge: 13000,
164
+ cacheControl: 13000,
165
+ preflightContinue: false,
166
+ optionsSuccessStatus: 200,
167
+ preflight: false,
168
+ strictPreflight: false,
169
+ logLevel: 'silent'
170
+ })
171
+
172
+ appHttp2.register(fastifyCors, {
173
+ origin: true,
174
+ allowedHeaders: ['authorization', 'content-type'],
175
+ methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
176
+ credentials: true,
177
+ exposedHeaders: ['authorization'],
178
+ maxAge: 13000,
179
+ cacheControl: 13000,
180
+ preflightContinue: false,
181
+ optionsSuccessStatus: 200,
182
+ preflight: false,
183
+ strictPreflight: false
184
+ })
185
+
186
+ appHttp2.register(fastifyCors, {
187
+ origin: '*',
188
+ allowedHeaders: ['authorization', 'content-type'],
189
+ methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
190
+ credentials: true,
191
+ exposedHeaders: ['authorization'],
192
+ maxAge: 13000,
193
+ cacheControl: 13000,
194
+ preflightContinue: false,
195
+ optionsSuccessStatus: 200,
196
+ preflight: false,
197
+ strictPreflight: false
198
+ })
199
+
200
+ appHttp2.register(fastifyCors, {
201
+ origin: /\*/,
202
+ allowedHeaders: ['authorization', 'content-type'],
203
+ methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
204
+ credentials: true,
205
+ exposedHeaders: ['authorization'],
206
+ maxAge: 13000,
207
+ cacheControl: 13000,
208
+ preflightContinue: false,
209
+ optionsSuccessStatus: 200,
210
+ preflight: false,
211
+ strictPreflight: false
212
+ })
213
+
214
+ appHttp2.register(fastifyCors, {
215
+ origin: ['*', 'something'],
216
+ allowedHeaders: ['authorization', 'content-type'],
217
+ methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
218
+ credentials: true,
219
+ exposedHeaders: ['authorization'],
220
+ maxAge: 13000,
221
+ cacheControl: 13000,
222
+ preflightContinue: false,
223
+ optionsSuccessStatus: 200,
224
+ preflight: false,
225
+ strictPreflight: false
226
+ })
227
+
228
+ appHttp2.register(fastifyCors, {
229
+ origin: [/\*/, /something/],
230
+ allowedHeaders: ['authorization', 'content-type'],
231
+ methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
232
+ credentials: true,
233
+ exposedHeaders: ['authorization'],
234
+ maxAge: 13000,
235
+ cacheControl: 13000,
236
+ preflightContinue: false,
237
+ optionsSuccessStatus: 200,
238
+ preflight: false,
239
+ strictPreflight: false
240
+ })
241
+
242
+ appHttp2.register(fastifyCors, {
243
+ origin: (origin: string | undefined, cb: (err: Error | null, allow: boolean) => void) => {
244
+ if (origin === undefined || /localhost/.test(origin)) {
245
+ cb(null, true)
246
+ return
247
+ }
248
+ cb(new Error(), false)
249
+ },
250
+ allowedHeaders: ['authorization', 'content-type'],
251
+ methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
252
+ credentials: true,
253
+ exposedHeaders: ['authorization'],
254
+ maxAge: 13000,
255
+ cacheControl: 13000,
256
+ preflightContinue: false,
257
+ optionsSuccessStatus: 200,
258
+ preflight: false,
259
+ strictPreflight: false
260
+ })
261
+
262
+ appHttp2.register(fastifyCors, (): FastifyCorsOptionsDelegate => (_req, cb) => {
263
+ cb(null, {
264
+ origin: [/\*/, /something/],
265
+ allowedHeaders: ['authorization', 'content-type'],
266
+ methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
267
+ credentials: true,
268
+ exposedHeaders: ['authorization'],
269
+ maxAge: 13000,
270
+ cacheControl: 13000,
271
+ preflightContinue: false,
272
+ optionsSuccessStatus: 200,
273
+ preflight: false,
274
+ strictPreflight: false
275
+ })
276
+ })
277
+
278
+ appHttp2.register(fastifyCors, (): FastifyCorsOptionsDelegatePromise => () => {
279
+ return Promise.resolve({
280
+ origin: [/\*/, /something/],
281
+ allowedHeaders: ['authorization', 'content-type'],
282
+ methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
283
+ credentials: true,
284
+ exposedHeaders: ['authorization'],
285
+ maxAge: 13000,
286
+ cacheControl: 13000,
287
+ preflightContinue: false,
288
+ optionsSuccessStatus: 200,
289
+ preflight: false,
290
+ strictPreflight: false
291
+ })
292
+ })
293
+
294
+ const delegate: FastifyPluginOptionsDelegate<FastifyCorsOptionsDelegatePromise> = () => async () => {
295
+ return {
296
+ origin: [/\*/, /something/],
297
+ allowedHeaders: ['authorization', 'content-type'],
298
+ methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
299
+ credentials: true,
300
+ exposedHeaders: ['authorization'],
301
+ maxAge: 13000,
302
+ cacheControl: 13000,
303
+ preflightContinue: false,
304
+ optionsSuccessStatus: 200,
305
+ preflight: false,
306
+ strictPreflight: false
307
+ }
308
+ }
309
+
310
+ appHttp2.register(fastifyCors, {
311
+ hook: 'onRequest'
312
+ })
313
+ appHttp2.register(fastifyCors, {
314
+ hook: 'preParsing'
315
+ })
316
+ appHttp2.register(fastifyCors, {
317
+ hook: 'preValidation'
318
+ })
319
+ appHttp2.register(fastifyCors, {
320
+ hook: 'preHandler'
321
+ })
322
+ appHttp2.register(fastifyCors, {
323
+ hook: 'preSerialization'
324
+ })
325
+ appHttp2.register(fastifyCors, {
326
+ hook: 'onSend'
327
+ })
328
+
329
+ appHttp2.register(fastifyCors, {
330
+ hook: 'preParsing',
331
+ delegator: (req, cb) => {
332
+ if (req.url.startsWith('/some-value')) {
333
+ cb(new Error())
334
+ }
335
+ cb(null, {
336
+ origin: [/\*/, /something/],
337
+ allowedHeaders: ['authorization', 'content-type'],
338
+ methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
339
+ credentials: true,
340
+ exposedHeaders: ['authorization'],
341
+ maxAge: 13000,
342
+ cacheControl: 12000,
343
+ preflightContinue: false,
344
+ optionsSuccessStatus: 200,
345
+ preflight: false,
346
+ strictPreflight: false
347
+ })
348
+ }
349
+ })
350
+
351
+ appHttp2.register(fastifyCors, {
352
+ hook: 'preParsing',
353
+ delegator: async (_req: FastifyRequest): Promise<FastifyCorsOptions> => {
354
+ return {
355
+ origin: [/\*/, /something/],
356
+ allowedHeaders: ['authorization', 'content-type'],
357
+ methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
358
+ credentials: true,
359
+ exposedHeaders: ['authorization'],
360
+ maxAge: 13000,
361
+ cacheControl: 'public, max-age=3500',
362
+ preflightContinue: false,
363
+ optionsSuccessStatus: 200,
364
+ preflight: false,
365
+ strictPreflight: false
366
+ }
367
+ }
368
+ })
369
+
370
+ appHttp2.register(fastifyCors, delegate)
371
+
372
+ appHttp2.register(fastifyCors, {
373
+ hook: 'preParsing',
374
+ origin: function (origin, cb) {
375
+ expectType<string | undefined>(origin)
376
+ cb(null, false)
377
+ },
378
+ })
379
+
380
+ const asyncOriginFn: AsyncOriginFunction = async function (origin): Promise<boolean> {
381
+ expectType<string | undefined>(origin)
382
+ return false
383
+ }
384
+
385
+ appHttp2.register(fastifyCors, {
386
+ hook: 'preParsing',
387
+ origin: asyncOriginFn,
388
+ })
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/error/.github/dependabot.yml ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: "github-actions"
4
+ directory: "/"
5
+ schedule:
6
+ interval: "monthly"
7
+ open-pull-requests-limit: 10
8
+
9
+ - package-ecosystem: "npm"
10
+ directory: "/"
11
+ schedule:
12
+ interval: "monthly"
13
+ open-pull-requests-limit: 10
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/error/.github/workflows/ci.yml ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ - next
8
+ - 'v*'
9
+ paths-ignore:
10
+ - 'docs/**'
11
+ - '*.md'
12
+ pull_request:
13
+ paths-ignore:
14
+ - 'docs/**'
15
+ - '*.md'
16
+
17
+ permissions:
18
+ contents: read
19
+
20
+ jobs:
21
+ test:
22
+ permissions:
23
+ contents: write
24
+ pull-requests: write
25
+ uses: fastify/workflows/.github/workflows/plugins-ci.yml@v5
26
+ with:
27
+ license-check: true
28
+ lint: true
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/error/benchmarks/create.js ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict'
2
+
3
+ const benchmark = require('benchmark')
4
+ const createError = require('..')
5
+
6
+ new benchmark.Suite()
7
+ .add('create FastifyError', function () { createError('CODE', 'Not available') }, { minSamples: 100 })
8
+ .on('cycle', function onCycle (event) { console.log(String(event.target)) })
9
+ .run({ async: false })
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/error/benchmarks/instantiate.js ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict'
2
+
3
+ const benchmark = require('benchmark')
4
+ const createError = require('..')
5
+
6
+ const FastifyError = createError('CODE', 'Not available')
7
+ const FastifyError1 = createError('CODE', 'Not %s available')
8
+ const FastifyError2 = createError('CODE', 'Not %s available %s')
9
+
10
+ const cause = new Error('cause')
11
+ new benchmark.Suite()
12
+ .add('instantiate Error', function () { new Error() }, { minSamples: 100 }) // eslint-disable-line no-new
13
+ .add('instantiate FastifyError', function () { new FastifyError() }, { minSamples: 100 }) // eslint-disable-line no-new
14
+ .add('instantiate FastifyError arg 1', function () { new FastifyError1('q') }, { minSamples: 100 }) // eslint-disable-line no-new
15
+ .add('instantiate FastifyError arg 2', function () { new FastifyError2('qq', 'ss') }, { minSamples: 100 }) // eslint-disable-line no-new
16
+ .add('instantiate FastifyError cause', function () { new FastifyError2({ cause }) }, { minSamples: 100 }) // eslint-disable-line no-new
17
+ .on('cycle', function onCycle (event) { console.log(String(event.target)) })
18
+ .run({ async: false })
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/error/benchmarks/no-stack.js ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict'
2
+
3
+ const benchmark = require('benchmark')
4
+ const createError = require('..')
5
+
6
+ const FastifyError = createError('CODE', 'Not available')
7
+ Error.stackTraceLimit = 0
8
+
9
+ new benchmark.Suite()
10
+ .add('no-stack instantiate Error', function () { new Error() }, { minSamples: 100 }) // eslint-disable-line no-new
11
+ .add('no-stack instantiate FastifyError', function () { new FastifyError() }, { minSamples: 100 }) // eslint-disable-line no-new
12
+ .on('cycle', function onCycle (event) { console.log(String(event.target)) })
13
+ .run({ async: false })
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/error/benchmarks/toString.js ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict'
2
+
3
+ const benchmark = require('benchmark')
4
+ const createError = require('..')
5
+
6
+ const FastifyError = createError('CODE', 'Not available')
7
+
8
+ new benchmark.Suite()
9
+ .add('FastifyError toString', function () { new FastifyError().toString() }, { minSamples: 100 })
10
+ .on('cycle', function onCycle (event) { console.log(String(event.target)) })
11
+ .run({ async: false })
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/error/test/index.test.js ADDED
@@ -0,0 +1,232 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict'
2
+
3
+ const test = require('node:test')
4
+ const { createError, FastifyError } = require('..')
5
+
6
+ test('Create error with zero parameter', (t) => {
7
+ t.plan(6)
8
+
9
+ const NewError = createError('CODE', 'Not available')
10
+ const err = new NewError()
11
+ t.assert.ok(err instanceof Error)
12
+ t.assert.equal(err.name, 'FastifyError')
13
+ t.assert.equal(err.message, 'Not available')
14
+ t.assert.equal(err.code, 'CODE')
15
+ t.assert.equal(err.statusCode, 500)
16
+ t.assert.ok(err.stack)
17
+ })
18
+
19
+ test('Create error with 1 parameter', (t) => {
20
+ t.plan(6)
21
+
22
+ const NewError = createError('CODE', 'hey %s')
23
+ const err = new NewError('alice')
24
+ t.assert.equal(err.name, 'FastifyError')
25
+ t.assert.ok(err instanceof Error)
26
+ t.assert.equal(err.message, 'hey alice')
27
+ t.assert.equal(err.code, 'CODE')
28
+ t.assert.equal(err.statusCode, 500)
29
+ t.assert.ok(err.stack)
30
+ })
31
+
32
+ test('Create error with 1 parameter set to undefined', (t) => {
33
+ t.plan(1)
34
+
35
+ const NewError = createError('CODE', 'hey %s')
36
+ const err = new NewError(undefined)
37
+ t.assert.equal(err.message, 'hey undefined')
38
+ })
39
+
40
+ test('Create error with 2 parameters', (t) => {
41
+ t.plan(6)
42
+
43
+ const NewError = createError('CODE', 'hey %s, I like your %s')
44
+ const err = new NewError('alice', 'attitude')
45
+ t.assert.ok(err instanceof Error)
46
+ t.assert.equal(err.name, 'FastifyError')
47
+ t.assert.equal(err.message, 'hey alice, I like your attitude')
48
+ t.assert.equal(err.code, 'CODE')
49
+ t.assert.equal(err.statusCode, 500)
50
+ t.assert.ok(err.stack)
51
+ })
52
+
53
+ test('Create error with 2 parameters set to undefined', (t) => {
54
+ t.plan(1)
55
+
56
+ const NewError = createError('CODE', 'hey %s, I like your %s')
57
+ const err = new NewError(undefined, undefined)
58
+ t.assert.equal(err.message, 'hey undefined, I like your undefined')
59
+ })
60
+
61
+ test('Create error with 3 parameters', (t) => {
62
+ t.plan(6)
63
+
64
+ const NewError = createError('CODE', 'hey %s, I like your %s %s')
65
+ const err = new NewError('alice', 'attitude', 'see you')
66
+ t.assert.ok(err instanceof Error)
67
+ t.assert.equal(err.name, 'FastifyError')
68
+ t.assert.equal(err.message, 'hey alice, I like your attitude see you')
69
+ t.assert.equal(err.code, 'CODE')
70
+ t.assert.equal(err.statusCode, 500)
71
+ t.assert.ok(err.stack)
72
+ })
73
+
74
+ test('Create error with 3 parameters set to undefined', (t) => {
75
+ t.plan(4)
76
+
77
+ const NewError = createError('CODE', 'hey %s, I like your %s %s')
78
+ const err = new NewError(undefined, undefined, undefined)
79
+ t.assert.equal(err.message, 'hey undefined, I like your undefined undefined')
80
+ t.assert.equal(err.code, 'CODE')
81
+ t.assert.equal(err.statusCode, 500)
82
+ t.assert.ok(err.stack)
83
+ })
84
+
85
+ test('Create error with 4 parameters set to undefined', (t) => {
86
+ t.plan(4)
87
+
88
+ const NewError = createError('CODE', 'hey %s, I like your %s %s and %s')
89
+ const err = new NewError(undefined, undefined, undefined, undefined)
90
+ t.assert.equal(
91
+ err.message,
92
+ 'hey undefined, I like your undefined undefined and undefined'
93
+ )
94
+ t.assert.equal(err.code, 'CODE')
95
+ t.assert.equal(err.statusCode, 500)
96
+ t.assert.ok(err.stack)
97
+ })
98
+
99
+ test('Create error with no statusCode property', (t) => {
100
+ t.plan(6)
101
+
102
+ const NewError = createError('CODE', 'hey %s', 0)
103
+ const err = new NewError('dude')
104
+ t.assert.ok(err instanceof Error)
105
+ t.assert.equal(err.name, 'FastifyError')
106
+ t.assert.equal(err.message, 'hey dude')
107
+ t.assert.equal(err.code, 'CODE')
108
+ t.assert.equal(err.statusCode, undefined)
109
+ t.assert.ok(err.stack)
110
+ })
111
+
112
+ test('Should throw when error code has no fastify code', (t) => {
113
+ t.plan(1)
114
+ t.assert.throws(
115
+ () => createError(),
116
+ new Error('Fastify error code must not be empty')
117
+ )
118
+ })
119
+
120
+ test('Should throw when error code has no message', (t) => {
121
+ t.assert.throws(
122
+ () => createError('code'),
123
+ new Error('Fastify error message must not be empty')
124
+ )
125
+ })
126
+
127
+ test('Create error with different base', (t) => {
128
+ t.plan(7)
129
+
130
+ const NewError = createError('CODE', 'hey %s', 500, TypeError)
131
+ const err = new NewError('dude')
132
+ t.assert.ok(err instanceof Error)
133
+ t.assert.ok(err instanceof TypeError)
134
+ t.assert.equal(err.name, 'FastifyError')
135
+ t.assert.equal(err.message, 'hey dude')
136
+ t.assert.equal(err.code, 'CODE')
137
+ t.assert.equal(err.statusCode, 500)
138
+ t.assert.ok(err.stack)
139
+ })
140
+
141
+ test('Create error with different base (no stack) (global)', (t) => {
142
+ t.plan(7)
143
+
144
+ createError.captureStackTrace = false
145
+ const NewError = createError('CODE', 'hey %s', 500, TypeError)
146
+ const err = new NewError('dude')
147
+ t.assert.ok(err instanceof Error)
148
+ t.assert.ok(err instanceof TypeError)
149
+ t.assert.equal(err.name, 'FastifyError')
150
+ t.assert.equal(err.message, 'hey dude')
151
+ t.assert.equal(err.code, 'CODE')
152
+ t.assert.equal(err.statusCode, 500)
153
+ t.assert.equal(err.stack, undefined)
154
+ createError.captureStackTrace = true
155
+ })
156
+
157
+ test('Create error with different base (no stack) (parameter)', (t) => {
158
+ t.plan(7)
159
+
160
+ const NewError = createError('CODE', 'hey %s', 500, TypeError, false)
161
+ const err = new NewError('dude')
162
+ t.assert.ok(err instanceof Error)
163
+ t.assert.ok(err instanceof TypeError)
164
+ t.assert.equal(err.name, 'FastifyError')
165
+ t.assert.equal(err.message, 'hey dude')
166
+ t.assert.equal(err.code, 'CODE')
167
+ t.assert.equal(err.statusCode, 500)
168
+ t.assert.equal(err.stack, undefined)
169
+ })
170
+
171
+ test('FastifyError.toString returns code', (t) => {
172
+ t.plan(1)
173
+
174
+ const NewError = createError('CODE', 'foo')
175
+ const err = new NewError()
176
+ t.assert.equal(err.toString(), 'FastifyError [CODE]: foo')
177
+ })
178
+
179
+ test('Create the error without the new keyword', (t) => {
180
+ t.plan(6)
181
+
182
+ const NewError = createError('CODE', 'Not available')
183
+ const err = NewError()
184
+ t.assert.ok(err instanceof Error)
185
+ t.assert.equal(err.name, 'FastifyError')
186
+ t.assert.equal(err.message, 'Not available')
187
+ t.assert.equal(err.code, 'CODE')
188
+ t.assert.equal(err.statusCode, 500)
189
+ t.assert.ok(err.stack)
190
+ })
191
+
192
+ test('Create an error with cause', (t) => {
193
+ t.plan(2)
194
+
195
+ const cause = new Error('HEY')
196
+ const NewError = createError('CODE', 'Not available')
197
+ const err = NewError({ cause })
198
+
199
+ t.assert.ok(err instanceof Error)
200
+ t.assert.equal(err.cause, cause)
201
+ })
202
+
203
+ test('Create an error with cause and message', (t) => {
204
+ t.plan(2)
205
+
206
+ const cause = new Error('HEY')
207
+ const NewError = createError('CODE', 'Not available: %s')
208
+ const err = NewError('foo', { cause })
209
+
210
+ t.assert.ok(err instanceof Error)
211
+ t.assert.equal(err.cause, cause)
212
+ })
213
+
214
+ test('Create an error with last argument null', (t) => {
215
+ t.plan(2)
216
+
217
+ const cause = new Error('HEY')
218
+ const NewError = createError('CODE', 'Not available')
219
+ const err = NewError({ cause }, null)
220
+
221
+ t.assert.ok(err instanceof Error)
222
+ t.assert.ifError(err.cause)
223
+ })
224
+
225
+ test('check if FastifyError is instantiable', (t) => {
226
+ t.plan(2)
227
+
228
+ const err = new FastifyError()
229
+
230
+ t.assert.ok(err instanceof FastifyError)
231
+ t.assert.ok(err instanceof Error)
232
+ })
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/error/test/instanceof.test.js ADDED
@@ -0,0 +1,263 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict'
2
+
3
+ const cp = require('node:child_process')
4
+ const fs = require('node:fs')
5
+ const path = require('node:path')
6
+ const os = require('node:os')
7
+ const test = require('node:test')
8
+ const { createError, FastifyError } = require('..')
9
+
10
+ test('Readme: All errors created with `createError` will be instances of the base error constructor you provided, or `Error` if none was provided.', (t) => {
11
+ t.plan(3)
12
+
13
+ const CustomError = createError('ERROR_CODE', 'Hello %s', 500, TypeError)
14
+ const customError = new CustomError('world')
15
+
16
+ t.assert.ok(customError instanceof CustomError)
17
+ t.assert.ok(customError instanceof TypeError)
18
+ t.assert.ok(customError instanceof Error)
19
+ })
20
+
21
+ test('Readme: All instantiated errors will be instances of the `FastifyError` class. The `FastifyError` class can be required from the module directly.', (t) => {
22
+ t.plan(1)
23
+
24
+ const CustomError = createError('ERROR_CODE', 'Hello %s', 500, TypeError)
25
+ const customError = new CustomError('world')
26
+
27
+ t.assert.ok(customError instanceof FastifyError)
28
+ })
29
+
30
+ test('Readme: It is possible to create a `FastifyError` that extends another `FastifyError`, created by `createError`, while instanceof working correctly.', (t) => {
31
+ t.plan(5)
32
+
33
+ const CustomError = createError('ERROR_CODE', 'Hello %s', 500, TypeError)
34
+ const ChildCustomError = createError('CHILD_ERROR_CODE', 'Hello %s', 500, CustomError)
35
+
36
+ const customError = new ChildCustomError('world')
37
+
38
+ t.assert.ok(customError instanceof ChildCustomError)
39
+ t.assert.ok(customError instanceof CustomError)
40
+ t.assert.ok(customError instanceof FastifyError)
41
+ t.assert.ok(customError instanceof TypeError)
42
+ t.assert.ok(customError instanceof Error)
43
+ })
44
+
45
+ test('Readme: Changing the code of an instantiated Error will not change the result of the `instanceof` operator.', (t) => {
46
+ t.plan(3)
47
+
48
+ const CustomError = createError('ERROR_CODE', 'Hello %s', 500, TypeError)
49
+ const AnotherCustomError = createError('ANOTHER_ERROR_CODE', 'Hello %s', 500, CustomError)
50
+
51
+ const customError = new CustomError('world')
52
+ customError.code = 'ANOTHER_ERROR_CODE'
53
+
54
+ t.assert.ok(customError instanceof CustomError)
55
+ t.assert.ok(customError instanceof AnotherCustomError === false)
56
+ t.assert.ok(customError instanceof FastifyError)
57
+ })
58
+
59
+ test('check if createError creates an Error which is instanceof Error', (t) => {
60
+ t.plan(3)
61
+
62
+ const CustomFastifyError = createError('CODE', 'Not available')
63
+ const err = CustomFastifyError()
64
+
65
+ t.assert.ok(err instanceof Error)
66
+ t.assert.ok(err instanceof SyntaxError === false)
67
+ t.assert.ok(err instanceof TypeError === false)
68
+ })
69
+
70
+ test('check if createError creates an Error which is instanceof FastifyError', (t) => {
71
+ t.plan(4)
72
+
73
+ const CustomFastifyError = createError('CODE', 'Not available')
74
+ const err = CustomFastifyError()
75
+
76
+ t.assert.ok(err instanceof Error)
77
+ t.assert.ok(err instanceof FastifyError)
78
+ t.assert.ok(err instanceof SyntaxError === false)
79
+ t.assert.ok(err instanceof TypeError === false)
80
+ })
81
+
82
+ test('check if createError creates an Error with the right BaseConstructor', (t) => {
83
+ t.plan(2)
84
+
85
+ const CustomFastifyError = createError('CODE', 'Not available', 500, TypeError)
86
+ const err = CustomFastifyError()
87
+
88
+ t.assert.ok(err instanceof Error)
89
+ t.assert.ok(err instanceof TypeError)
90
+ })
91
+
92
+ test('check if createError creates an Error with the right BaseConstructor, which is a FastifyError', (t) => {
93
+ t.plan(6)
94
+
95
+ const BaseFastifyError = createError('CODE', 'Not available', 500, TypeError)
96
+ const CustomFastifyError = createError('CODE', 'Not available', 500, BaseFastifyError)
97
+ const err = CustomFastifyError()
98
+
99
+ t.assert.ok(err instanceof Error)
100
+ t.assert.ok(err instanceof TypeError)
101
+ t.assert.ok(err instanceof FastifyError)
102
+ t.assert.ok(err instanceof BaseFastifyError)
103
+ t.assert.ok(err instanceof CustomFastifyError)
104
+ t.assert.ok(err instanceof SyntaxError === false)
105
+ })
106
+
107
+ // for more information see https://github.com/fastify/fastify-error/pull/86#issuecomment-1301466407
108
+ test('ensure that instanceof works accross different installations of the fastify-error module', async (t) => {
109
+ const assertsPlanned = 5
110
+ t.plan(assertsPlanned)
111
+
112
+ // We need to create a test environment where fastify-error is installed in two different locations
113
+ // and then we will check if the error created in one location is instanceof the error created in the other location
114
+ // This is done by creating a test directory with the following structure:
115
+
116
+ // /
117
+ // ├── index.js
118
+ // └── node_modules/
119
+ // ├── fastify-error/
120
+ // │ └── index.js
121
+ // └── dep/
122
+ // ├── index.js
123
+ // └── node_modules/
124
+ // └── fastify-error/
125
+ // └── index.js
126
+
127
+ const testDirectoryPrefix = 'fastify-error-instanceof-test-'
128
+
129
+ const testCwd = path.resolve(os.tmpdir(), `${testDirectoryPrefix}${Math.random().toString(36).substring(2, 15)}`)
130
+ fs.mkdirSync(testCwd, { recursive: true })
131
+
132
+ // Create the index.js. It will be executed as a forked process, so we need to
133
+ // use process.send to send messages back to the parent process.
134
+ fs.writeFileSync(path.resolve(testCwd, 'index.js'), `
135
+ 'use strict'
136
+
137
+ const path = require('node:path')
138
+ const { createError, FastifyError } = require('fastify-error')
139
+ const { foo } = require('dep')
140
+
141
+ const actualPathOfFastifyError = require.resolve('fastify-error')
142
+ const expectedPathOfFastifyError = path.resolve('node_modules', 'fastify-error', 'index.js')
143
+
144
+ // Ensure that fastify-error is required from the node_modules directory of the test-project
145
+ if (actualPathOfFastifyError !== expectedPathOfFastifyError) {
146
+ console.error('actualPathOfFastifyError', actualPathOfFastifyError)
147
+ console.error('expectedPathOfFastifyError', expectedPathOfFastifyError)
148
+ throw new Error('fastify-error should be required from the node_modules directory of the test-project')
149
+ }
150
+
151
+ const Boom = createError('Boom', 'Boom', 500)
152
+ const ChildBoom = createError('ChildBoom', 'Boom', 500, Boom)
153
+ const NotChildBoom = createError('NotChildBoom', 'NotChildBoom', 500, Boom)
154
+
155
+ try {
156
+ foo()
157
+ } catch (err) {
158
+ process.send(err instanceof Error)
159
+ process.send(err instanceof FastifyError)
160
+ process.send(err instanceof NotChildBoom)
161
+ process.send(err instanceof Boom)
162
+ process.send(err instanceof ChildBoom)
163
+ }
164
+ `)
165
+
166
+ // Create /node_modules/fastify-error directory
167
+ // Copy the index.js file to the fastify-error directory
168
+ fs.mkdirSync(path.resolve(testCwd, 'node_modules', 'fastify-error'), { recursive: true })
169
+ fs.copyFileSync(path.resolve(process.cwd(), 'index.js'), path.resolve(testCwd, 'node_modules', 'fastify-error', 'index.js'))
170
+
171
+ // Create /node_modules/dep/node_modules/fastify-error directory
172
+ // Copy the index.js to the fastify-error directory
173
+ fs.mkdirSync(path.resolve(testCwd, 'node_modules', 'dep', 'node_modules', 'fastify-error'), { recursive: true })
174
+ fs.copyFileSync(path.resolve(process.cwd(), 'index.js'), path.resolve(testCwd, 'node_modules', 'dep', 'node_modules', 'fastify-error', 'index.js'))
175
+
176
+ // Create /node_modules/dep/index.js. It will export a function foo which will
177
+ // throw an error when called. The error will be an instance of ChildBoom, created
178
+ // by the fastify-error module in the node_modules directory of dep.
179
+ fs.writeFileSync(path.resolve(testCwd, 'node_modules', 'dep', 'index.js'), `
180
+ 'use strict'
181
+
182
+ const path = require('node:path')
183
+ const { createError } = require('fastify-error')
184
+
185
+ const actualPathOfFastifyError = require.resolve('fastify-error')
186
+ const expectedPathOfFastifyError = path.resolve('node_modules', 'dep', 'node_modules', 'fastify-error', 'index.js')
187
+
188
+ // Ensure that fastify-error is required from the node_modules directory of the test-project
189
+ if (actualPathOfFastifyError !== expectedPathOfFastifyError) {
190
+ console.error('actualPathOfFastifyError', actualPathOfFastifyError)
191
+ console.error('expectedPathOfFastifyError', expectedPathOfFastifyError)
192
+ throw new Error('fastify-error should be required from the node_modules directory of dep')
193
+ }
194
+
195
+ const Boom = createError('Boom', 'Boom', 500)
196
+ const ChildBoom = createError('ChildBoom', 'Boom', 500, Boom)
197
+
198
+ module.exports.foo = function foo () {
199
+ throw new ChildBoom('foo go Boom')
200
+ }
201
+ `)
202
+
203
+ const finishedPromise = {
204
+ promise: undefined,
205
+ reject: undefined,
206
+ resolve: undefined,
207
+ }
208
+
209
+ finishedPromise.promise = new Promise((resolve, reject) => {
210
+ finishedPromise.resolve = resolve
211
+ finishedPromise.reject = reject
212
+ })
213
+
214
+ const child = cp.fork(path.resolve(testCwd, 'index.js'), {
215
+ cwd: testCwd,
216
+ stdio: 'inherit',
217
+ env: {
218
+ ...process.env,
219
+ NODE_OPTIONS: '--no-warnings'
220
+ },
221
+ })
222
+
223
+ let messageCount = 0
224
+ child.on('message', message => {
225
+ try {
226
+ switch (messageCount) {
227
+ case 0:
228
+ t.assert.strictEqual(message, true, 'instanceof Error')
229
+ break
230
+ case 1:
231
+ t.assert.strictEqual(message, true, 'instanceof FastifyError')
232
+ break
233
+ case 2:
234
+ t.assert.strictEqual(message, false, 'instanceof NotChildBoom')
235
+ break
236
+ case 3:
237
+ t.assert.strictEqual(message, true, 'instanceof Boom')
238
+ break
239
+ case 4:
240
+ t.assert.strictEqual(message, true, 'instanceof ChildBoom')
241
+ break
242
+ }
243
+ if (++messageCount === assertsPlanned) {
244
+ finishedPromise.resolve()
245
+ }
246
+ } catch (err) {
247
+ finishedPromise.reject(err)
248
+ }
249
+ })
250
+
251
+ child.on('error', err => {
252
+ finishedPromise.reject(err)
253
+ })
254
+
255
+ await finishedPromise.promise
256
+
257
+ // Cleanup
258
+ // As we are creating the test-setup on the fly in the /tmp directory, we can remove it
259
+ // safely when we are done. It is not relevant for the test if the deletion fails.
260
+ try {
261
+ fs.rmSync(testCwd, { recursive: true, force: true })
262
+ } catch {}
263
+ })
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/error/types/index.d.ts ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ declare function createError<C extends string, SC extends number, Arg extends unknown[] = [any?, any?, any?]> (
2
+ code: C,
3
+ message: string,
4
+ statusCode: SC,
5
+ Base?: ErrorConstructor,
6
+ captureStackTrace?: boolean
7
+ ): createError.FastifyErrorConstructor<{ code: C, statusCode: SC }, Arg>
8
+
9
+ declare function createError<C extends string, Arg extends unknown[] = [any?, any?, any?]> (
10
+ code: C,
11
+ message: string,
12
+ statusCode?: number,
13
+ Base?: ErrorConstructor,
14
+ captureStackTrace?: boolean
15
+ ): createError.FastifyErrorConstructor<{ code: C }, Arg>
16
+
17
+ declare function createError<Arg extends unknown[] = [any?, any?, any?]> (
18
+ code: string,
19
+ message: string,
20
+ statusCode?: number,
21
+ Base?: ErrorConstructor,
22
+ captureStackTrace?: boolean
23
+ ): createError.FastifyErrorConstructor<{ code: string }, Arg>
24
+
25
+ type CreateError = typeof createError
26
+
27
+ declare namespace createError {
28
+ export interface FastifyError extends Error {
29
+ code: string
30
+ name: string
31
+ statusCode?: number
32
+ }
33
+
34
+ export interface FastifyErrorConstructor<
35
+ E extends { code: string, statusCode?: number } = { code: string, statusCode?: number },
36
+ T extends unknown[] = [any?, any?, any?]
37
+ > {
38
+ new(...arg: T): FastifyError & E
39
+ (...arg: T): FastifyError & E
40
+ readonly prototype: FastifyError & E
41
+ }
42
+
43
+ export const FastifyError: FastifyErrorConstructor
44
+
45
+ export const createError: CreateError
46
+ export { createError as default }
47
+ }
48
+
49
+ export = createError
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/error/types/index.test-d.ts ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import createError, { FastifyError, FastifyErrorConstructor } from '..'
2
+ import { expectType, expectError } from 'tsd'
3
+
4
+ const CustomError = createError('ERROR_CODE', 'message')
5
+ expectType<FastifyErrorConstructor<{ code: 'ERROR_CODE' }>>(CustomError)
6
+ const err = new CustomError()
7
+ expectType<FastifyError & { code: 'ERROR_CODE' }>(err)
8
+ expectType<'ERROR_CODE'>(err.code)
9
+ expectType<string>(err.message)
10
+ expectType<number | undefined>(err.statusCode)
11
+
12
+ const CustomErrorNoStackTrace = createError('ERROR_CODE', 'message', undefined, undefined, false)
13
+ expectType<FastifyErrorConstructor<{ code: 'ERROR_CODE' }>>(CustomErrorNoStackTrace)
14
+ const errNoStackTrace = new CustomErrorNoStackTrace()
15
+ expectType<FastifyError & { code: 'ERROR_CODE' }>(errNoStackTrace)
16
+ expectType<'ERROR_CODE'>(errNoStackTrace.code)
17
+ expectType<string>(errNoStackTrace.message)
18
+ expectType<number | undefined>(errNoStackTrace.statusCode)
19
+
20
+ const CustomTypedError = createError('OTHER_CODE', 'message', 400)
21
+ expectType<FastifyErrorConstructor<{ code: 'OTHER_CODE', statusCode: 400 }>>(CustomTypedError)
22
+ const typed = new CustomTypedError()
23
+ expectType<FastifyError & { code: 'OTHER_CODE', statusCode: 400 }>(typed)
24
+ expectType<'OTHER_CODE'>(typed.code)
25
+ expectType<string>(typed.message)
26
+ expectType<400>(typed.statusCode)
27
+
28
+ /* eslint-disable no-new */
29
+ const CustomTypedArgError = createError<[string]>('OTHER_CODE', 'expect %s message', 400)
30
+ CustomTypedArgError('a')
31
+ expectError(CustomTypedArgError('a', 'b'))
32
+ expectError(new CustomTypedArgError('a', 'b'))
33
+ expectError(CustomTypedArgError(1))
34
+ expectError(new CustomTypedArgError(1))
35
+
36
+ const CustomTypedArgError2 = createError<string, number, [string]>('OTHER_CODE', 'expect %s message', 400)
37
+ CustomTypedArgError2('a')
38
+ expectError(CustomTypedArgError2('a', 'b'))
39
+ expectError(new CustomTypedArgError2('a', 'b'))
40
+ expectError(CustomTypedArgError2(1))
41
+ expectError(new CustomTypedArgError2(1))
42
+
43
+ const CustomTypedArgError3 = createError<string, number, [string, string]>('OTHER_CODE', 'expect %s message but got %s', 400)
44
+ expectError(CustomTypedArgError3('a'))
45
+ CustomTypedArgError3('a', 'b')
46
+ new CustomTypedArgError3('a', 'b')
47
+ expectError(CustomTypedArgError3(1))
48
+ expectError(new CustomTypedArgError3(1))
49
+ expectError(new CustomTypedArgError3(1, 2))
50
+ expectError(new CustomTypedArgError3('1', 2))
51
+ expectError(new CustomTypedArgError3(1, '2'))
52
+
53
+ const CustomTypedArgError4 = createError<string, number, [string, string]>('OTHER_CODE', 'expect %s message but got %s', 400)
54
+ expectError(CustomTypedArgError4('a'))
55
+ CustomTypedArgError4('a', 'b')
56
+ new CustomTypedArgError4('a', 'b')
57
+ expectError(CustomTypedArgError4(1))
58
+ expectError(new CustomTypedArgError4(1))
59
+ expectError(new CustomTypedArgError4(1, 2))
60
+ expectError(new CustomTypedArgError4('1', 2))
61
+ expectError(new CustomTypedArgError4(1, '2'))
62
+
63
+ const CustomTypedArgError5 = createError<[string, string, string, string]>('OTHER_CODE', 'expect %s message but got %s. Please contact %s by emailing to %s', 400)
64
+ expectError(CustomTypedArgError5('a'))
65
+ expectError(new CustomTypedArgError5('a', 'b'))
66
+ expectError(new CustomTypedArgError5('a', 'b', 'c'))
67
+ CustomTypedArgError5('a', 'b', 'c', 'd')
68
+ expectError(new CustomTypedArgError5('a', 'b', 'c', 'd', 'e'))
69
+
70
+ const CustomTypedArgError6 = createError<string, number, [string, string, string, string]>('OTHER_CODE', 'expect %s message but got %s. Please contact %s by emailing to %s', 400)
71
+ expectError(CustomTypedArgError6('a'))
72
+ expectError(new CustomTypedArgError6('a', 'b'))
73
+ expectError(new CustomTypedArgError6('a', 'b', 'c'))
74
+ CustomTypedArgError6('a', 'b', 'c', 'd')
75
+ expectError(new CustomTypedArgError6('a', 'b', 'c', 'd', 'e'))
76
+
77
+ const CustomErrorWithErrorConstructor = createError('ERROR_CODE', 'message', 500, TypeError)
78
+ expectType<FastifyErrorConstructor<{ code: 'ERROR_CODE', statusCode: 500 }>>(CustomErrorWithErrorConstructor)
79
+ CustomErrorWithErrorConstructor({ cause: new Error('Error') })
80
+ const customErrorWithErrorConstructor = CustomErrorWithErrorConstructor()
81
+ if (customErrorWithErrorConstructor instanceof FastifyError) {
82
+ expectType<'ERROR_CODE'>(customErrorWithErrorConstructor.code)
83
+ expectType<string>(customErrorWithErrorConstructor.message)
84
+ expectType<500>(customErrorWithErrorConstructor.statusCode)
85
+ }
86
+
87
+ const error = new FastifyError('ERROR_CODE', 'message', 500)
88
+ if (error instanceof FastifyError) {
89
+ expectType<string>(error.code)
90
+ expectType<string>(error.message)
91
+ expectType<number | undefined>(error.statusCode)
92
+ }
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/fast-json-stringify-compiler/.github/dependabot.yml ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: "github-actions"
4
+ directory: "/"
5
+ schedule:
6
+ interval: "monthly"
7
+ open-pull-requests-limit: 10
8
+
9
+ - package-ecosystem: "npm"
10
+ directory: "/"
11
+ schedule:
12
+ interval: "monthly"
13
+ open-pull-requests-limit: 10
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/fast-json-stringify-compiler/.github/workflows/ci.yml ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ - next
8
+ - 'v*'
9
+ paths-ignore:
10
+ - 'docs/**'
11
+ - '*.md'
12
+ pull_request:
13
+ paths-ignore:
14
+ - 'docs/**'
15
+ - '*.md'
16
+
17
+ permissions:
18
+ contents: read
19
+
20
+ jobs:
21
+ test:
22
+ permissions:
23
+ contents: write
24
+ pull-requests: write
25
+ uses: fastify/workflows/.github/workflows/plugins-ci.yml@v5
26
+ with:
27
+ license-check: true
28
+ lint: true
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/fast-json-stringify-compiler/test/duplicate-schema.test.js ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict'
2
+
3
+ const { test } = require('node:test')
4
+ const FjsCompiler = require('../index')
5
+
6
+ test('Use input schema duplicate in the externalSchemas', async t => {
7
+ t.plan(1)
8
+ const externalSchemas = {
9
+ schema1: {
10
+ $id: 'schema1',
11
+ type: 'number'
12
+ },
13
+ schema2: {
14
+ $id: 'schema2',
15
+ type: 'string'
16
+ }
17
+ }
18
+
19
+ const factory = FjsCompiler()
20
+ const compiler = factory(externalSchemas)
21
+
22
+ compiler({ schema: externalSchemas.schema1 })
23
+ compiler({ schema: externalSchemas.schema2 })
24
+
25
+ t.assert.ok(true)
26
+ })
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/fast-json-stringify-compiler/test/plugin.test.js ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict'
2
+
3
+ const { test } = require('node:test')
4
+ const fastify = require('fastify')
5
+ const FjsCompiler = require('../index')
6
+
7
+ const echo = async (req) => { return req.body }
8
+
9
+ const sampleSchema = Object.freeze({
10
+ $id: 'example1',
11
+ type: 'object',
12
+ properties: {
13
+ name: { type: 'string' }
14
+ }
15
+ })
16
+
17
+ const externalSchemas1 = Object.freeze({})
18
+ const externalSchemas2 = Object.freeze({
19
+ foo: {
20
+ $id: 'foo',
21
+ type: 'object',
22
+ properties: {
23
+ name: { type: 'string' }
24
+ }
25
+ }
26
+ })
27
+
28
+ const fastifyFjsOptionsDefault = Object.freeze({})
29
+
30
+ test('basic usage', t => {
31
+ t.plan(1)
32
+ const factory = FjsCompiler()
33
+ const compiler = factory(externalSchemas1, fastifyFjsOptionsDefault)
34
+ const serializeFunc = compiler({ schema: sampleSchema })
35
+ const result = serializeFunc({ name: 'hello' })
36
+ t.assert.equal(result, '{"name":"hello"}')
37
+ })
38
+
39
+ test('fastify integration', async t => {
40
+ const factory = FjsCompiler()
41
+
42
+ const app = fastify({
43
+ serializerOpts: {
44
+ rounding: 'ceil'
45
+ },
46
+ schemaController: {
47
+ compilersFactory: {
48
+ buildSerializer: factory
49
+ }
50
+ }
51
+ })
52
+
53
+ app.addSchema(externalSchemas2.foo)
54
+
55
+ app.post('/', {
56
+ handler: echo,
57
+ schema: {
58
+ response: {
59
+ 200: {
60
+ $ref: 'foo#'
61
+ }
62
+ }
63
+ }
64
+ })
65
+
66
+ const res = await app.inject({
67
+ url: '/',
68
+ method: 'POST',
69
+ payload: {
70
+ version: '1',
71
+ foo: 'this is not a number',
72
+ name: 'serialize me'
73
+ }
74
+ })
75
+
76
+ t.assert.equal(res.statusCode, 200)
77
+ t.assert.deepStrictEqual(res.json(), { name: 'serialize me' })
78
+ })
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/fast-json-stringify-compiler/test/standalone.test.js ADDED
@@ -0,0 +1,230 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict'
2
+
3
+ const fs = require('node:fs')
4
+ const path = require('node:path')
5
+ const { test } = require('node:test')
6
+ const fastify = require('fastify')
7
+ const sanitize = require('sanitize-filename')
8
+
9
+ const { StandaloneSerializer: FjsStandaloneCompiler } = require('../')
10
+
11
+ const generatedFileNames = []
12
+
13
+ function generateFileName (routeOpts) {
14
+ const fileName = `/fjs-generated-${sanitize(routeOpts.schema.$id)}-${routeOpts.method}-${routeOpts.httpPart}-${sanitize(routeOpts.url)}.js`
15
+ generatedFileNames.push(fileName)
16
+ return fileName
17
+ }
18
+
19
+ test('standalone', async t => {
20
+ t.plan(5)
21
+
22
+ t.after(async () => {
23
+ for (const fileName of generatedFileNames) {
24
+ try {
25
+ await fs.promises.unlink(path.join(__dirname, fileName))
26
+ } catch {}
27
+ }
28
+ })
29
+
30
+ t.test('errors', t => {
31
+ t.plan(2)
32
+ t.assert.throws(() => {
33
+ FjsStandaloneCompiler()
34
+ }, 'missing restoreFunction')
35
+ t.assert.throws(() => {
36
+ FjsStandaloneCompiler({ readMode: false })
37
+ }, 'missing storeFunction')
38
+ })
39
+
40
+ t.test('generate standalone code', t => {
41
+ t.plan(5)
42
+
43
+ const base = {
44
+ $id: 'urn:schema:base',
45
+ definitions: {
46
+ hello: { type: 'string' }
47
+ },
48
+ type: 'object',
49
+ properties: {
50
+ hello: { $ref: '#/definitions/hello' }
51
+ }
52
+ }
53
+
54
+ const refSchema = {
55
+ $id: 'urn:schema:ref',
56
+ type: 'object',
57
+ properties: {
58
+ hello: { $ref: 'urn:schema:base#/definitions/hello' }
59
+ }
60
+ }
61
+
62
+ const endpointSchema = {
63
+ schema: {
64
+ $id: 'urn:schema:endpoint',
65
+ $ref: 'urn:schema:ref'
66
+ }
67
+ }
68
+
69
+ const schemaMap = {
70
+ [base.$id]: base,
71
+ [refSchema.$id]: refSchema
72
+ }
73
+
74
+ const factory = FjsStandaloneCompiler({
75
+ readMode: false,
76
+ storeFunction (routeOpts, schemaSerializerCode) {
77
+ t.assert.deepStrictEqual(routeOpts, endpointSchema)
78
+ t.assert.ok(typeof schemaSerializerCode === 'string')
79
+ fs.writeFileSync(path.join(__dirname, '/fjs-generated.js'), schemaSerializerCode)
80
+ generatedFileNames.push('/fjs-generated.js')
81
+ t.assert.ok('stored the serializer function')
82
+ }
83
+ })
84
+
85
+ const compiler = factory(schemaMap)
86
+ compiler(endpointSchema)
87
+ t.assert.ok('compiled the endpoint schema')
88
+
89
+ t.test('usage standalone code', t => {
90
+ t.plan(3)
91
+ const standaloneSerializer = require('./fjs-generated')
92
+ t.assert.ok(standaloneSerializer)
93
+
94
+ const valid = standaloneSerializer({ hello: 'world' })
95
+ t.assert.deepStrictEqual(valid, JSON.stringify({ hello: 'world' }))
96
+
97
+ const invalid = standaloneSerializer({ hello: [] })
98
+ t.assert.deepStrictEqual(invalid, '{"hello":""}')
99
+ })
100
+ })
101
+
102
+ t.test('fastify integration - writeMode', async t => {
103
+ t.plan(4)
104
+
105
+ const factory = FjsStandaloneCompiler({
106
+ readMode: false,
107
+ storeFunction (routeOpts, schemaSerializationCode) {
108
+ const fileName = generateFileName(routeOpts)
109
+ t.assert.ok(routeOpts)
110
+ fs.writeFileSync(path.join(__dirname, fileName), schemaSerializationCode)
111
+ t.assert.ok(`stored the serializer function ${fileName}`)
112
+ },
113
+ restoreFunction () {
114
+ t.fail('write mode ON')
115
+ }
116
+ })
117
+
118
+ const app = buildApp(factory)
119
+ await app.ready()
120
+ })
121
+
122
+ await t.test('fastify integration - writeMode forces standalone', async t => {
123
+ t.plan(4)
124
+
125
+ const factory = FjsStandaloneCompiler({
126
+ readMode: false,
127
+ storeFunction (routeOpts, schemaSerializationCode) {
128
+ const fileName = generateFileName(routeOpts)
129
+ t.assert.ok(routeOpts)
130
+ fs.writeFileSync(path.join(__dirname, fileName), schemaSerializationCode)
131
+ t.assert.ok(`stored the serializer function ${fileName}`)
132
+ },
133
+ restoreFunction () {
134
+ t.fail('write mode ON')
135
+ }
136
+ })
137
+
138
+ const app = buildApp(factory, {
139
+ mode: 'not-standalone',
140
+ rounding: 'ceil'
141
+ })
142
+
143
+ await app.ready()
144
+ })
145
+
146
+ await t.test('fastify integration - readMode', async t => {
147
+ t.plan(6)
148
+
149
+ const factory = FjsStandaloneCompiler({
150
+ readMode: true,
151
+ storeFunction () {
152
+ t.fail('read mode ON')
153
+ },
154
+ restoreFunction (routeOpts) {
155
+ const fileName = generateFileName(routeOpts)
156
+ t.assert.ok(`restore the serializer function ${fileName}}`)
157
+ return require(path.join(__dirname, fileName))
158
+ }
159
+ })
160
+
161
+ const app = buildApp(factory)
162
+ await app.ready()
163
+
164
+ let res = await app.inject({
165
+ url: '/foo',
166
+ method: 'POST'
167
+ })
168
+ t.assert.equal(res.statusCode, 200)
169
+ t.assert.equal(res.payload, JSON.stringify({ hello: 'world' }))
170
+
171
+ res = await app.inject({
172
+ url: '/bar?lang=it',
173
+ method: 'GET'
174
+ })
175
+ t.assert.equal(res.statusCode, 200)
176
+ t.assert.equal(res.payload, JSON.stringify({ lang: 'en' }))
177
+ })
178
+
179
+ function buildApp (factory, serializerOpts) {
180
+ const app = fastify({
181
+ exposeHeadRoutes: false,
182
+ jsonShorthand: false,
183
+ schemaController: {
184
+ compilersFactory: {
185
+ buildSerializer: factory
186
+ }
187
+ },
188
+ serializerOpts
189
+ })
190
+
191
+ app.addSchema({
192
+ $id: 'urn:schema:foo',
193
+ type: 'object',
194
+ properties: {
195
+ name: { type: 'string' },
196
+ id: { type: 'integer' }
197
+ }
198
+ })
199
+
200
+ app.post('/foo', {
201
+ schema: {
202
+ response: {
203
+ 200: {
204
+ $id: 'urn:schema:response',
205
+ type: 'object',
206
+ properties: {
207
+ hello: { $ref: 'urn:schema:foo#/properties/name' }
208
+ }
209
+ }
210
+ }
211
+ }
212
+ }, () => { return { hello: 'world' } })
213
+
214
+ app.get('/bar', {
215
+ schema: {
216
+ response: {
217
+ 200: {
218
+ $id: 'urn:schema:response:bar',
219
+ type: 'object',
220
+ properties: {
221
+ lang: { type: 'string', enum: ['it', 'en'] }
222
+ }
223
+ }
224
+ }
225
+ }
226
+ }, () => { return { lang: 'en' } })
227
+
228
+ return app
229
+ }
230
+ })
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/fast-json-stringify-compiler/types/index.d.ts ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { Options } from 'fast-json-stringify'
2
+
3
+ type FastJsonStringifyFactory = () => SerializerSelector.SerializerFactory
4
+
5
+ declare namespace SerializerSelector {
6
+ export type SerializerFactory = (
7
+ externalSchemas?: unknown,
8
+ options?: Options
9
+ ) => SerializerCompiler
10
+
11
+ export type SerializerCompiler = (routeDef: RouteDefinition) => Serializer
12
+ export type Serializer = (doc: any) => string
13
+
14
+ export type RouteDefinition = {
15
+ method: string;
16
+ url: string;
17
+ httpStatus: string;
18
+ schema?: unknown;
19
+ }
20
+
21
+ export type StandaloneOptions = StandaloneOptionsReadModeOn | StandaloneOptionsReadModeOff
22
+
23
+ export type StandaloneOptionsReadModeOn = {
24
+ readMode: true;
25
+ restoreFunction?(opts: RouteDefinition): Serializer;
26
+ }
27
+
28
+ export type StandaloneOptionsReadModeOff = {
29
+ readMode?: false | undefined;
30
+ storeFunction?(opts: RouteDefinition, schemaSerializationCode: string): void;
31
+ }
32
+
33
+ export type { Options }
34
+ export const SerializerSelector: FastJsonStringifyFactory
35
+ export function StandaloneSerializer (options: StandaloneOptions): SerializerFactory
36
+
37
+ export { SerializerSelector as default }
38
+ }
39
+
40
+ declare function SerializerSelector (...params: Parameters<FastJsonStringifyFactory>): ReturnType<FastJsonStringifyFactory>
41
+ export = SerializerSelector
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/fast-json-stringify-compiler/types/index.test-d.ts ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { expectAssignable, expectError, expectType } from 'tsd'
2
+ import SerializerSelector, {
3
+ RouteDefinition,
4
+ Serializer,
5
+ SerializerCompiler,
6
+ SerializerFactory,
7
+ SerializerSelector as SerializerSelectorNamed,
8
+ StandaloneSerializer,
9
+ } from '..'
10
+
11
+ /**
12
+ * SerializerSelector
13
+ */
14
+
15
+ {
16
+ const compiler = SerializerSelector()
17
+ expectType<SerializerFactory>(compiler)
18
+ }
19
+
20
+ {
21
+ const compiler = SerializerSelectorNamed()
22
+ expectType<SerializerFactory>(compiler)
23
+ }
24
+
25
+ {
26
+ const sampleSchema = {
27
+ $id: 'example1',
28
+ type: 'object',
29
+ properties: {
30
+ name: { type: 'string' }
31
+ }
32
+ }
33
+
34
+ const externalSchemas1 = {}
35
+
36
+ const factory = SerializerSelector()
37
+ expectType<SerializerFactory>(factory)
38
+ const compiler = factory(externalSchemas1, {})
39
+ expectType<SerializerCompiler>(compiler)
40
+ const serializeFunc = compiler({ schema: sampleSchema, method: '', url: '', httpStatus: '' })
41
+ expectType<Serializer>(serializeFunc)
42
+
43
+ expectType<string>(serializeFunc({ name: 'hello' }))
44
+ }
45
+
46
+ /**
47
+ * StandaloneSerializer
48
+ */
49
+
50
+ const reader = StandaloneSerializer({
51
+ readMode: true,
52
+ restoreFunction: (route: RouteDefinition) => {
53
+ expectAssignable<RouteDefinition>(route)
54
+ return {} as Serializer
55
+ },
56
+ })
57
+ expectType<SerializerFactory>(reader)
58
+
59
+ const writer = StandaloneSerializer({
60
+ readMode: false,
61
+ storeFunction: (route: RouteDefinition, code: string) => {
62
+ expectAssignable<RouteDefinition>(route)
63
+ expectAssignable<string>(code)
64
+ },
65
+ })
66
+ expectType<SerializerFactory>(writer)
67
+
68
+ {
69
+ const base = {
70
+ $id: 'urn:schema:base',
71
+ definitions: {
72
+ hello: { type: 'string' }
73
+ },
74
+ type: 'object',
75
+ properties: {
76
+ hello: { $ref: '#/definitions/hello' }
77
+ }
78
+ }
79
+
80
+ const refSchema = {
81
+ $id: 'urn:schema:ref',
82
+ type: 'object',
83
+ properties: {
84
+ hello: { $ref: 'urn:schema:base#/definitions/hello' }
85
+ }
86
+ }
87
+
88
+ const endpointSchema = {
89
+ method: '',
90
+ url: '',
91
+ httpStatus: '',
92
+ schema: {
93
+ $id: 'urn:schema:endpoint',
94
+ $ref: 'urn:schema:ref'
95
+ }
96
+ }
97
+
98
+ const schemaMap = {
99
+ [base.$id]: base,
100
+ [refSchema.$id]: refSchema
101
+ }
102
+
103
+ expectError(StandaloneSerializer({
104
+ readMode: true,
105
+ storeFunction () { }
106
+ }))
107
+ expectError(StandaloneSerializer({
108
+ readMode: false,
109
+ restoreFunction () {}
110
+ }))
111
+ expectError(StandaloneSerializer({
112
+ restoreFunction () {}
113
+ }))
114
+
115
+ expectType<SerializerFactory>(StandaloneSerializer({
116
+ storeFunction (routeOpts, schemaSerializerCode) {
117
+ expectType<RouteDefinition>(routeOpts)
118
+ expectType<string>(schemaSerializerCode)
119
+ }
120
+ }))
121
+
122
+ expectType<SerializerFactory>(StandaloneSerializer({
123
+ readMode: true,
124
+ restoreFunction (routeOpts) {
125
+ expectType<RouteDefinition>(routeOpts)
126
+ return {} as Serializer
127
+ }
128
+ }))
129
+
130
+ const factory = StandaloneSerializer({
131
+ readMode: false,
132
+ storeFunction (routeOpts, schemaSerializerCode) {
133
+ expectType<RouteDefinition>(routeOpts)
134
+ expectType<string>(schemaSerializerCode)
135
+ }
136
+ })
137
+ expectType<SerializerFactory>(factory)
138
+
139
+ const compiler = factory(schemaMap)
140
+ expectType<SerializerCompiler>(compiler)
141
+ expectType<Serializer>(compiler(endpointSchema))
142
+ }
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/forwarded/types/index.d.ts ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { IncomingMessage } from 'http';
2
+
3
+ type Forwarded = (req: IncomingMessage) => string[]
4
+
5
+ declare namespace forwarded {
6
+ export const forwarded: Forwarded
7
+ export { forwarded as default }
8
+ }
9
+
10
+ /**
11
+ * Get all addresses in the request used in the `X-Forwarded-For` header.
12
+ */
13
+ declare function forwarded(...params: Parameters<Forwarded>): ReturnType<Forwarded>
14
+ export = forwarded
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/merge-json-schemas/.github/dependabot.yml ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: "github-actions"
4
+ directory: "/"
5
+ schedule:
6
+ interval: "monthly"
7
+ open-pull-requests-limit: 10
8
+
9
+ - package-ecosystem: "npm"
10
+ directory: "/"
11
+ schedule:
12
+ interval: "weekly"
13
+ open-pull-requests-limit: 10
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/merge-json-schemas/.github/workflows/ci.yml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ - master
8
+ - next
9
+ - 'v*'
10
+ paths-ignore:
11
+ - 'docs/**'
12
+ - '*.md'
13
+ pull_request:
14
+ paths-ignore:
15
+ - 'docs/**'
16
+ - '*.md'
17
+
18
+ jobs:
19
+ test:
20
+ uses: fastify/workflows/.github/workflows/plugins-ci.yml@v5
21
+ with:
22
+ license-check: true
23
+ lint: true
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/merge-json-schemas/lib/errors.js ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict'
2
+
3
+ class MergeError extends Error {
4
+ constructor (keyword, schemas) {
5
+ super()
6
+ this.name = 'JsonSchemaMergeError'
7
+ this.code = 'JSON_SCHEMA_MERGE_ERROR'
8
+ this.message = `Failed to merge "${keyword}" keyword schemas.`
9
+ this.schemas = schemas
10
+ }
11
+ }
12
+
13
+ class ResolverNotFoundError extends Error {
14
+ constructor (keyword, schemas) {
15
+ super()
16
+ this.name = 'JsonSchemaMergeError'
17
+ this.code = 'JSON_SCHEMA_MERGE_ERROR'
18
+ this.message = `Resolver for "${keyword}" keyword not found.`
19
+ this.schemas = schemas
20
+ }
21
+ }
22
+
23
+ class InvalidOnConflictOptionError extends Error {
24
+ constructor (onConflict) {
25
+ super()
26
+ this.name = 'JsonSchemaMergeError'
27
+ this.code = 'JSON_SCHEMA_MERGE_ERROR'
28
+ this.message = `Invalid "onConflict" option: "${onConflict}".`
29
+ }
30
+ }
31
+
32
+ module.exports = {
33
+ MergeError,
34
+ ResolverNotFoundError,
35
+ InvalidOnConflictOptionError
36
+ }
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/merge-json-schemas/lib/resolvers.js ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict'
2
+
3
+ const { dequal: deepEqual } = require('dequal')
4
+ const { MergeError } = require('./errors')
5
+
6
+ function _arraysIntersection (arrays) {
7
+ let intersection = arrays[0]
8
+ for (let i = 1; i < arrays.length; i++) {
9
+ intersection = intersection.filter(
10
+ value => arrays[i].includes(value)
11
+ )
12
+ }
13
+ return intersection
14
+ }
15
+
16
+ function arraysIntersection (keyword, values, mergedSchema) {
17
+ const intersection = _arraysIntersection(values)
18
+ if (intersection.length === 0) {
19
+ throw new MergeError(keyword, values)
20
+ }
21
+ mergedSchema[keyword] = intersection
22
+ }
23
+
24
+ function hybridArraysIntersection (keyword, values, mergedSchema) {
25
+ for (let i = 0; i < values.length; i++) {
26
+ if (!Array.isArray(values[i])) {
27
+ values[i] = [values[i]]
28
+ }
29
+ }
30
+
31
+ const intersection = _arraysIntersection(values)
32
+ if (intersection.length === 0) {
33
+ throw new MergeError(keyword, values)
34
+ }
35
+
36
+ if (intersection.length === 1) {
37
+ mergedSchema[keyword] = intersection[0]
38
+ } else {
39
+ mergedSchema[keyword] = intersection
40
+ }
41
+ }
42
+
43
+ function arraysUnion (keyword, values, mergedSchema) {
44
+ const union = []
45
+
46
+ for (const array of values) {
47
+ for (const value of array) {
48
+ if (!union.includes(value)) {
49
+ union.push(value)
50
+ }
51
+ }
52
+ }
53
+
54
+ mergedSchema[keyword] = union
55
+ }
56
+
57
+ function minNumber (keyword, values, mergedSchema) {
58
+ mergedSchema[keyword] = Math.min(...values)
59
+ }
60
+
61
+ function maxNumber (keyword, values, mergedSchema) {
62
+ mergedSchema[keyword] = Math.max(...values)
63
+ }
64
+
65
+ function commonMultiple (keyword, values, mergedSchema) {
66
+ const gcd = (a, b) => (!b ? a : gcd(b, a % b))
67
+ const lcm = (a, b) => (a * b) / gcd(a, b)
68
+
69
+ let scale = 1
70
+ for (const value of values) {
71
+ while (value * scale % 1 !== 0) {
72
+ scale *= 10
73
+ }
74
+ }
75
+
76
+ let multiple = values[0] * scale
77
+ for (const value of values) {
78
+ multiple = lcm(multiple, value * scale)
79
+ }
80
+
81
+ mergedSchema[keyword] = multiple / scale
82
+ }
83
+
84
+ function allEqual (keyword, values, mergedSchema) {
85
+ const firstValue = values[0]
86
+ for (let i = 1; i < values.length; i++) {
87
+ if (!deepEqual(values[i], firstValue)) {
88
+ throw new MergeError(keyword, values)
89
+ }
90
+ }
91
+ mergedSchema[keyword] = firstValue
92
+ }
93
+
94
+ function skip () {}
95
+
96
+ function booleanAnd (keyword, values, mergedSchema) {
97
+ for (const value of values) {
98
+ if (value === false) {
99
+ mergedSchema[keyword] = false
100
+ return
101
+ }
102
+ }
103
+ mergedSchema[keyword] = true
104
+ }
105
+
106
+ function booleanOr (keyword, values, mergedSchema) {
107
+ for (const value of values) {
108
+ if (value === true) {
109
+ mergedSchema[keyword] = true
110
+ return
111
+ }
112
+ }
113
+ mergedSchema[keyword] = false
114
+ }
115
+
116
+ module.exports = {
117
+ arraysIntersection,
118
+ hybridArraysIntersection,
119
+ arraysUnion,
120
+ minNumber,
121
+ maxNumber,
122
+ commonMultiple,
123
+ allEqual,
124
+ booleanAnd,
125
+ booleanOr,
126
+ skip
127
+ }
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/merge-json-schemas/test/additional-items.test.js ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict'
2
+
3
+ const assert = require('node:assert/strict')
4
+ const { test } = require('node:test')
5
+ const { mergeSchemas } = require('../index')
6
+ const { defaultResolver } = require('./utils')
7
+
8
+ test('should merge empty schema and additionalItems = false keyword', () => {
9
+ const schema1 = { type: 'array' }
10
+ const schema2 = {
11
+ type: 'array',
12
+ additionalItems: false
13
+ }
14
+
15
+ const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
16
+ assert.deepStrictEqual(mergedSchema, {
17
+ type: 'array',
18
+ additionalItems: false
19
+ })
20
+ })
21
+
22
+ test('should merge two schemas with boolean additionalItems', () => {
23
+ const schema1 = {
24
+ type: 'array',
25
+ additionalItems: true
26
+ }
27
+ const schema2 = {
28
+ type: 'array',
29
+ additionalItems: false
30
+ }
31
+
32
+ const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
33
+ assert.deepStrictEqual(mergedSchema, {
34
+ type: 'array',
35
+ additionalItems: false
36
+ })
37
+ })
38
+
39
+ test('should merge additionalItems schema with false value', () => {
40
+ const schema1 = {
41
+ type: 'array',
42
+ additionalItems: {
43
+ type: 'string'
44
+ }
45
+ }
46
+ const schema2 = {
47
+ type: 'array',
48
+ additionalItems: false
49
+ }
50
+
51
+ const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
52
+ assert.deepStrictEqual(mergedSchema, {
53
+ type: 'array',
54
+ additionalItems: false
55
+ })
56
+ })
57
+
58
+ test('should merge additionalItems schema with true value', () => {
59
+ const schema1 = {
60
+ type: 'array',
61
+ additionalItems: {
62
+ type: 'string'
63
+ }
64
+ }
65
+ const schema2 = {
66
+ type: 'array',
67
+ additionalItems: true
68
+ }
69
+
70
+ const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
71
+ assert.deepStrictEqual(mergedSchema, {
72
+ type: 'array',
73
+ additionalItems: {
74
+ type: 'string'
75
+ }
76
+ })
77
+ })
78
+
79
+ test('should merge two additionalItems schemas', () => {
80
+ const schema1 = {
81
+ type: 'array',
82
+ additionalItems: {
83
+ type: 'string'
84
+ }
85
+ }
86
+ const schema2 = {
87
+ type: 'array',
88
+ additionalItems: {
89
+ type: 'string', minLength: 1
90
+ }
91
+ }
92
+
93
+ const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
94
+ assert.deepStrictEqual(mergedSchema, {
95
+ type: 'array',
96
+ additionalItems: {
97
+ type: 'string', minLength: 1
98
+ }
99
+ })
100
+ })
101
+
102
+ test('should merge additionalItems with items array', () => {
103
+ const schema1 = {
104
+ type: 'array',
105
+ items: [
106
+ { type: 'string', const: 'foo1' },
107
+ { type: 'string', const: 'foo2' },
108
+ { type: 'string', const: 'foo3' }
109
+ ]
110
+ }
111
+ const schema2 = {
112
+ type: 'array',
113
+ additionalItems: {
114
+ type: 'string', minLength: 42
115
+ }
116
+ }
117
+
118
+ const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
119
+ assert.deepStrictEqual(mergedSchema, {
120
+ type: 'array',
121
+ items: [
122
+ { type: 'string', const: 'foo1', minLength: 42 },
123
+ { type: 'string', const: 'foo2', minLength: 42 },
124
+ { type: 'string', const: 'foo3', minLength: 42 }
125
+ ],
126
+ additionalItems: {
127
+ type: 'string', minLength: 42
128
+ }
129
+ })
130
+ })
131
+
132
+ test('should merge items array and additionalItems with items array', () => {
133
+ const schema1 = {
134
+ type: 'array',
135
+ items: [
136
+ { type: 'string', const: 'foo1' },
137
+ { type: 'string', const: 'foo2' },
138
+ { type: 'string', const: 'foo3' }
139
+ ]
140
+ }
141
+ const schema2 = {
142
+ type: 'array',
143
+ items: [
144
+ { type: 'string', minLength: 1 },
145
+ { type: 'string', minLength: 2 }
146
+ ],
147
+ additionalItems: {
148
+ type: 'string', minLength: 3
149
+ }
150
+ }
151
+
152
+ const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
153
+ assert.deepStrictEqual(mergedSchema, {
154
+ type: 'array',
155
+ items: [
156
+ { type: 'string', const: 'foo1', minLength: 1 },
157
+ { type: 'string', const: 'foo2', minLength: 2 },
158
+ { type: 'string', const: 'foo3', minLength: 3 }
159
+ ],
160
+ additionalItems: {
161
+ type: 'string', minLength: 3
162
+ }
163
+ })
164
+ })
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/merge-json-schemas/test/additional-properties.test.js ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict'
2
+
3
+ const assert = require('node:assert/strict')
4
+ const { test } = require('node:test')
5
+ const { mergeSchemas } = require('../index')
6
+ const { defaultResolver } = require('./utils')
7
+
8
+ test('should merge empty schema and additionalProperties=false keyword', () => {
9
+ const schema1 = { type: 'object' }
10
+ const schema2 = {
11
+ type: 'object',
12
+ additionalProperties: false
13
+ }
14
+
15
+ const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
16
+ assert.deepStrictEqual(mergedSchema, {
17
+ type: 'object',
18
+ additionalProperties: false
19
+ })
20
+ })
21
+
22
+ test('should merge two schemas with boolean additionalProperties', () => {
23
+ const schema1 = {
24
+ type: 'object',
25
+ additionalProperties: true
26
+ }
27
+ const schema2 = {
28
+ type: 'object',
29
+ additionalProperties: false
30
+ }
31
+
32
+ const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
33
+ assert.deepStrictEqual(mergedSchema, {
34
+ type: 'object',
35
+ additionalProperties: false
36
+ })
37
+ })
38
+
39
+ test('should merge additionalProperties schema with false value', () => {
40
+ const schema1 = {
41
+ type: 'object',
42
+ additionalProperties: {
43
+ type: 'string'
44
+ }
45
+ }
46
+ const schema2 = {
47
+ type: 'object',
48
+ additionalProperties: false
49
+ }
50
+
51
+ const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
52
+ assert.deepStrictEqual(mergedSchema, {
53
+ type: 'object',
54
+ additionalProperties: false
55
+ })
56
+ })
57
+
58
+ test('should merge additionalProperties schema with true value', () => {
59
+ const schema1 = {
60
+ type: 'object',
61
+ additionalProperties: {
62
+ type: 'string'
63
+ }
64
+ }
65
+ const schema2 = {
66
+ type: 'object',
67
+ additionalProperties: true
68
+ }
69
+
70
+ const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
71
+ assert.deepStrictEqual(mergedSchema, {
72
+ type: 'object',
73
+ additionalProperties: {
74
+ type: 'string'
75
+ }
76
+ })
77
+ })
78
+
79
+ test('should merge two additionalProperties schemas', () => {
80
+ const schema1 = {
81
+ type: 'object',
82
+ additionalProperties: {
83
+ type: 'string'
84
+ }
85
+ }
86
+ const schema2 = {
87
+ type: 'object',
88
+ additionalProperties: {
89
+ type: 'string', minLength: 1
90
+ }
91
+ }
92
+
93
+ const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
94
+ assert.deepStrictEqual(mergedSchema, {
95
+ type: 'object',
96
+ additionalProperties: {
97
+ type: 'string', minLength: 1
98
+ }
99
+ })
100
+ })
101
+
102
+ test('should merge two additionalProperties and properties schemas', () => {
103
+ const schema1 = {
104
+ type: 'object',
105
+ additionalProperties: {
106
+ type: 'string'
107
+ }
108
+ }
109
+ const schema2 = {
110
+ type: 'object',
111
+ properties: {
112
+ foo: { type: ['string', 'number'] }
113
+ },
114
+ additionalProperties: {
115
+ type: 'string', minLength: 1
116
+ }
117
+ }
118
+
119
+ const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
120
+ assert.deepStrictEqual(mergedSchema, {
121
+ type: 'object',
122
+ properties: {
123
+ foo: { type: 'string' }
124
+ },
125
+ additionalProperties: {
126
+ type: 'string', minLength: 1
127
+ }
128
+ })
129
+ })
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/merge-json-schemas/test/all-of.test.js ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict'
2
+
3
+ const assert = require('node:assert/strict')
4
+ const { test } = require('node:test')
5
+ const { mergeSchemas } = require('../index')
6
+ const { defaultResolver } = require('./utils')
7
+
8
+ test('should merge empty schema and allOf keyword', () => {
9
+ const schema1 = {}
10
+ const schema2 = {
11
+ allOf: [
12
+ { type: 'string', const: 'foo' }
13
+ ]
14
+ }
15
+
16
+ const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
17
+ assert.deepStrictEqual(mergedSchema, {
18
+ allOf: [
19
+ { type: 'string', const: 'foo' }
20
+ ]
21
+ })
22
+ })
23
+
24
+ test('should merge schemas with allOfs schemas', () => {
25
+ const schema1 = {
26
+ allOf: [
27
+ { type: 'number', minimum: 0 }
28
+ ]
29
+ }
30
+ const schema2 = {
31
+ allOf: [
32
+ { type: 'string', const: 'foo' }
33
+ ]
34
+ }
35
+
36
+ const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
37
+ assert.deepStrictEqual(mergedSchema, {
38
+ allOf: [
39
+ { type: 'number', minimum: 0 },
40
+ { type: 'string', const: 'foo' }
41
+ ]
42
+ })
43
+ })
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/@fastify/merge-json-schemas/test/any-of.test.js ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict'
2
+
3
+ const assert = require('node:assert/strict')
4
+ const { test } = require('node:test')
5
+ const { mergeSchemas } = require('../index')
6
+ const { defaultResolver } = require('./utils')
7
+
8
+ test('should merge empty schema and anyOf keyword', () => {
9
+ const schema1 = {}
10
+ const schema2 = {
11
+ anyOf: [
12
+ { type: 'string', const: 'foo' }
13
+ ]
14
+ }
15
+
16
+ const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
17
+ assert.deepStrictEqual(mergedSchema, {
18
+ anyOf: [
19
+ { type: 'string', const: 'foo' }
20
+ ]
21
+ })
22
+ })
23
+
24
+ test('should merge two schemas with anyOfs schemas', () => {
25
+ const schema1 = {
26
+ anyOf: [
27
+ { type: 'string', enum: ['foo1', 'foo2', 'foo3'] },
28
+ { type: 'string', enum: ['foo3', 'foo4', 'foo5'] }
29
+ ]
30
+ }
31
+ const schema2 = {
32
+ anyOf: [
33
+ { type: 'string', enum: ['foo2', 'foo3', 'foo4'] },
34
+ { type: 'string', enum: ['foo3', 'foo6', 'foo7'] }
35
+ ]
36
+ }
37
+
38
+ const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
39
+ assert.deepStrictEqual(mergedSchema, {
40
+ anyOf: [
41
+ { type: 'string', enum: ['foo2', 'foo3'] },
42
+ { type: 'string', enum: ['foo3'] },
43
+ { type: 'string', enum: ['foo3', 'foo4'] },
44
+ { type: 'string', enum: ['foo3'] }
45
+ ]
46
+ })
47
+ })
48
+
49
+ test('should merge three schemas with anyOfs schemas', () => {
50
+ const schema1 = {
51
+ anyOf: [
52
+ { type: 'string', enum: ['foo1', 'foo2', 'foo3', 'foo4'] },
53
+ { type: 'string', enum: ['foo3', 'foo4', 'foo5', 'foo7'] }
54
+ ]
55
+ }
56
+ const schema2 = {
57
+ anyOf: [
58
+ { type: 'string', enum: ['foo2', 'foo3', 'foo4', 'foo5'] },
59
+ { type: 'string', enum: ['foo3', 'foo6', 'foo7', 'foo8'] }
60
+ ]
61
+ }
62
+
63
+ const schema3 = {
64
+ anyOf: [
65
+ { type: 'string', enum: ['foo1', 'foo3', 'foo5', 'foo7'] },
66
+ { type: 'string', enum: ['foo2', 'foo4', 'foo6', 'foo8'] }
67
+ ]
68
+ }
69
+
70
+ const mergedSchema = mergeSchemas([schema1, schema2, schema3], { defaultResolver })
71
+ assert.deepStrictEqual(mergedSchema, {
72
+ anyOf: [
73
+ { type: 'string', enum: ['foo3'] },
74
+ { type: 'string', enum: ['foo2', 'foo4'] },
75
+ { type: 'string', enum: ['foo3'] },
76
+ { type: 'string', enum: ['foo3', 'foo5'] },
77
+ { type: 'string', enum: ['foo4'] },
78
+ { type: 'string', enum: ['foo3', 'foo7'] }
79
+ ]
80
+ })
81
+ })