-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathtargeting.json
594 lines (594 loc) · 20.4 KB
/
targeting.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
{
"$id": "https://flagd.dev/schema/v0/targeting.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "flagd Targeting",
"description": "Defines targeting logic for flagd; a extension of JSONLogic, including purpose-built feature-flagging operations.",
"type": "object",
"properties": {
"targeting": {
"$ref": "#/definitions/targeting"
}
},
"definitions": {
"targeting": {
"title": "Targeting",
"description": "An expression returning a value which is coerced to a string to be used as a targeting key, or null (to fall back to defaultVariant). If targeting returns a value which is not a variant key, it's considered an error.",
"anyOf": [
{
"$comment": "we need this to support empty targeting",
"type": "object",
"additionalProperties": false,
"properties": {}
},
{
"$ref": "#/definitions/anyRule"
}
]
},
"primitive": {
"oneOf": [
{
"description": "When returned from rules, a null value \"exits\", the targeting, and the \"defaultValue\" is returned, with the reason indicating the targeting did not match.",
"type": "null"
},
{
"description": "When returned from rules, booleans are converted to strings (\"true\"/\"false\"), and used to as keys to retrieve the associated value from the \"variants\" object. Be sure that the returned string is present as a key in the variants!",
"type": "boolean"
},
{
"description": "When returned from rules, the behavior of numbers is not defined.",
"type": "number"
},
{
"description": "When returned from rules, strings are used to as keys to retrieve the associated value from the \"variants\" object. Be sure that the returned string is present as a key in the variants!.",
"type": "string"
},
{
"description": "When returned from rules, strings are used to as keys to retrieve the associated value from the \"variants\" object. Be sure that the returned string is present as a key in the variants!.",
"type": "array"
}
]
},
"varRule": {
"title": "Var Operation",
"description": "Retrieve data from the provided data object.",
"type": "object",
"additionalProperties": false,
"properties": {
"var": {
"anyOf": [
{
"type": "string",
"description": "flagd automatically injects \"$flagd.timestamp\" (unix epoch) and \"$flagd.flagKey\" (the key of the flag in evaluation) into the context.",
"pattern": "^\\$flagd\\.((timestamp)|(flagKey))$"
},
{
"not": {
"$comment": "this is a negated (not) match of \"$flagd.{some-key}\", which is faster and more compatible that a negative lookahead regex",
"type": "string",
"description": "flagd automatically injects \"$flagd.timestamp\" (unix epoch) and \"$flagd.flagKey\" (the key of the flag in evaluation) into the context.",
"pattern": "^\\$flagd\\..*$"
}
},
{
"type": "array",
"$comment": "this is to support the form of var with a default... there seems to be a bug here, where ajv gives a warning (not an error) because maxItems doesn't equal the number of entries in items, though this is valid in this case",
"minItems": 1,
"items": [
{
"type": "string"
}
],
"additionalItems": {
"anyOf": [
{
"type": "null"
},
{
"type": "boolean"
},
{
"type": "string"
},
{
"type": "number"
}
]
}
}
]
}
}
},
"missingRule": {
"title": "Missing Operation",
"description": "Takes an array of data keys to search for (same format as var). Returns an array of any keys that are missing from the data object, or an empty array.",
"type": "object",
"additionalProperties": false,
"properties": {
"missing": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"missingSomeRule": {
"title": "Missing-Some Operation",
"description": "Takes a minimum number of data keys that are required, and an array of keys to search for (same format as var or missing). Returns an empty array if the minimum is met, or an array of the missing keys otherwise.",
"type": "object",
"additionalProperties": false,
"properties": {
"missing_some": {
"minItems": 2,
"maxItems": 2,
"type": "array",
"items": [
{
"type": "number"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
}
}
},
"binaryOrTernaryOp": {
"type": "array",
"minItems": 2,
"maxItems": 3,
"items": {
"$ref": "#/definitions/args"
}
},
"binaryOrTernaryRule": {
"type": "object",
"additionalProperties": false,
"properties": {
"substr": {
"title": "Substring Operation",
"description": "Get a portion of a string. Give a positive start position to return everything beginning at that index. Give a negative start position to work backwards from the end of the string, then return everything. Give a positive length to express how many characters to return.",
"$ref": "#/definitions/binaryOrTernaryOp"
},
"<": {
"title": "Less-Than/Between Operation. Can be used to test that one value is between two others.",
"$ref": "#/definitions/binaryOrTernaryOp"
},
"<=": {
"title": "Less-Than-Or-Equal-To/Between Operation. Can be used to test that one value is between two others.",
"$ref": "#/definitions/binaryOrTernaryOp"
}
}
},
"binaryOp": {
"type": "array",
"minItems": 2,
"maxItems": 2,
"items": {
"$ref": "#/definitions/args"
}
},
"binaryRule": {
"title": "Binary Operation",
"description": "Any primitive JSONLogic operation with 2 operands.",
"type": "object",
"additionalProperties": false,
"properties": {
"if": {
"title": "If Operator",
"description": "The if statement takes 1 or more arguments: a condition (\"if\"), what to do if its true (\"then\", optional, defaults to returning true), and what to do if its false (\"else\", optional, defaults to returning false). Note that the else condition can be used as an else-if statement by adding additional arguments.",
"$ref": "#/definitions/variadicOp"
},
"==": {
"title": "Lose Equality Operation",
"description": "Tests equality, with type coercion. Requires two arguments.",
"$ref": "#/definitions/binaryOp"
},
"===": {
"title": "Strict Equality Operation",
"description": "Tests strict equality. Requires two arguments.",
"$ref": "#/definitions/binaryOp"
},
"!=": {
"title": "Lose Inequality Operation",
"description": "Tests not-equal, with type coercion.",
"$ref": "#/definitions/binaryOp"
},
"!==": {
"title": "Strict Inequality Operation",
"description": "Tests strict not-equal.",
"$ref": "#/definitions/binaryOp"
},
">": {
"title": "Greater-Than Operation",
"$ref": "#/definitions/binaryOp"
},
">=": {
"title": "Greater-Than-Or-Equal-To Operation",
"$ref": "#/definitions/binaryOp"
},
"%": {
"title": "Modulo Operation",
"description": "Finds the remainder after the first argument is divided by the second argument.",
"$ref": "#/definitions/binaryOp"
},
"/": {
"title": "Division Operation",
"$ref": "#/definitions/binaryOp"
},
"map": {
"title": "Map Operation",
"description": "Perform an action on every member of an array. Note, that inside the logic being used to map, var operations are relative to the array element being worked on.",
"$ref": "#/definitions/binaryOp"
},
"filter": {
"title": "Filter Operation",
"description": "Keep only elements of the array that pass a test. Note, that inside the logic being used to filter, var operations are relative to the array element being worked on.",
"$ref": "#/definitions/binaryOp"
},
"all": {
"title": "All Operation",
"description": "Perform a test on each member of that array, returning true if all pass. Inside the test code, var operations are relative to the array element being tested.",
"$ref": "#/definitions/binaryOp"
},
"none": {
"title": "None Operation",
"description": "Perform a test on each member of that array, returning true if none pass. Inside the test code, var operations are relative to the array element being tested.",
"$ref": "#/definitions/binaryOp"
},
"some": {
"title": "Some Operation",
"description": "Perform a test on each member of that array, returning true if some pass. Inside the test code, var operations are relative to the array element being tested.",
"$ref": "#/definitions/binaryOp"
},
"in": {
"title": "In Operation",
"description": "If the second argument is an array, tests that the first argument is a member of the array.",
"$ref": "#/definitions/binaryOp"
}
}
},
"reduceRule": {
"type": "object",
"additionalProperties": false,
"properties": {
"reduce": {
"title": "Reduce Operation",
"description": "Combine all the elements in an array into a single value, like adding up a list of numbers. Note, that inside the logic being used to reduce, var operations only have access to an object with a \"current\" and a \"accumulator\".",
"type": "array",
"minItems": 3,
"maxItems": 3,
"items": {
"$ref": "#/definitions/args"
}
}
}
},
"associativeOp": {
"type": "array",
"minItems": 2,
"items": {
"$ref": "#/definitions/args"
}
},
"associativeRule": {
"title": "Mathematically Associative Operation",
"description": "Operation applicable to 2 or more parameters.",
"type": "object",
"additionalProperties": false,
"properties": {
"*": {
"title": "Multiplication Operation",
"description": "Multiplication; associative, will accept and unlimited amount of arguments.",
"$ref": "#/definitions/associativeOp"
}
}
},
"unaryOp": {
"anyOf": [
{
"type": "array",
"minItems": 1,
"maxItems": 1,
"items": {
"$ref": "#/definitions/args"
}
},
{
"$ref": "#/definitions/args"
}
]
},
"unaryRule": {
"title": "Unary Operation",
"description": "Any primitive JSONLogic operation with 1 operands.",
"type": "object",
"additionalProperties": false,
"properties": {
"!": {
"title": "Negation Operation",
"description": "Logical negation (“not”). Takes just one argument.",
"$ref": "#/definitions/unaryOp"
},
"!!": {
"title": "Double Negation Operation",
"description": "Double negation, or 'cast to a boolean'. Takes a single argument.",
"$ref": "#/definitions/unaryOp"
}
}
},
"variadicOp": {
"type": "array",
"minItems": 1,
"items": {
"$ref": "#/definitions/args"
}
},
"variadicRule": {
"$comment": "note < and <= can be used with up to 3 ops (between)",
"type": "object",
"additionalProperties": false,
"properties": {
"or": {
"title": "Or Operation",
"description": "Simple boolean test, with 1 or more arguments. At a more sophisticated level, \"or\" returns the first truthy argument, or the last argument.",
"$ref": "#/definitions/variadicOp"
},
"and": {
"title": "",
"description": "Simple boolean test, with 1 or more arguments. At a more sophisticated level, \"and\" returns the first falsy argument, or the last argument.",
"$ref": "#/definitions/variadicOp"
},
"+": {
"title": "Addition Operation",
"description": "Addition; associative, will accept and unlimited amount of arguments.",
"$ref": "#/definitions/variadicOp"
},
"-": {
"title": "Subtraction Operation",
"$ref": "#/definitions/variadicOp"
},
"max": {
"title": "Maximum Operation",
"description": "Return the maximum from a list of values.",
"$ref": "#/definitions/variadicOp"
},
"min": {
"title": "Minimum Operation",
"description": "Return the minimum from a list of values.",
"$ref": "#/definitions/variadicOp"
},
"merge": {
"title": "Merge Operation",
"description": "Takes one or more arrays, and merges them into one array. If arguments aren't arrays, they get cast to arrays.",
"$ref": "#/definitions/variadicOp"
},
"cat": {
"title": "Concatenate Operation",
"description": "Concatenate all the supplied arguments. Note that this is not a join or implode operation, there is no “glue” string.",
"$ref": "#/definitions/variadicOp"
}
}
},
"stringCompareArg": {
"oneOf": [
{
"type": "string"
},
{
"$ref": "#/definitions/anyRule"
}
]
},
"stringCompareArgs": {
"type": "array",
"minItems": 2,
"maxItems": 2,
"items": {
"$ref": "#/definitions/stringCompareArg"
}
},
"stringCompareRule": {
"type": "object",
"additionalProperties": false,
"properties": {
"starts_with": {
"title": "Starts-With Operation",
"description": "The string attribute starts with the specified string value.",
"$ref": "#/definitions/stringCompareArgs"
},
"ends_with": {
"title": "Ends-With Operation",
"description": "The string attribute ends with the specified string value.",
"$ref": "#/definitions/stringCompareArgs"
}
}
},
"semVerString": {
"title": "Semantic Version String",
"description": "A string representing a valid semantic version expression as per https://semver.org/.",
"type": "string",
"pattern": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$"
},
"ruleSemVer": {
"type": "object",
"additionalProperties": false,
"properties": {
"sem_ver": {
"title": "Semantic Version Operation",
"description": "Attribute matches a semantic version condition. Accepts \"npm-style\" range specifiers: \"=\", \"!=\", \">\", \"<\", \">=\", \"<=\", \"~\" (match minor version), \"^\" (match major version).",
"type": "array",
"minItems": 3,
"maxItems": 3,
"items": [
{
"oneOf": [
{
"$ref": "#/definitions/semVerString"
},
{
"$ref": "#/definitions/varRule"
}
]
},
{
"description": "Range specifiers: \"=\", \"!=\", \">\", \"<\", \">=\", \"<=\", \"~\" (match minor version), \"^\" (match major version).",
"enum": [
"=",
"!=",
">",
"<",
">=",
"<=",
"~",
"^"
]
},
{
"oneOf": [
{
"$ref": "#/definitions/semVerString"
},
{
"$ref": "#/definitions/varRule"
}
]
}
]
}
}
},
"fractionalWeightArg": {
"$comment": "if we remove the \"sum to 100\" restriction, update the descriptions below!",
"description": "Distribution for all possible variants, with their associated weighting out of 100.",
"type": "array",
"minItems": 1,
"maxItems": 2,
"items": [
{
"description": "If this bucket is randomly selected, this string is used to as a key to retrieve the associated value from the \"variants\" object.",
"type": "string"
},
{
"description": "Weighted distribution for this variant key (must sum to 100).",
"type": "number"
}
]
},
"fractionalOp": {
"type": "array",
"minItems": 3,
"$comment": "there seems to be a bug here, where ajv gives a warning (not an error) because maxItems doesn't equal the number of entries in items, though this is valid in this case",
"items": [
{
"description": "Bucketing value used in pseudorandom assignment; should be unique and stable for each subject of flag evaluation. Defaults to a concatenation of the flagKey and targetingKey.",
"$ref": "#/definitions/anyRule"
},
{
"$ref": "#/definitions/fractionalWeightArg"
},
{
"$ref": "#/definitions/fractionalWeightArg"
}
],
"additionalItems": {
"$ref": "#/definitions/fractionalWeightArg"
}
},
"fractionalShorthandOp": {
"type": "array",
"minItems": 2,
"items": {
"$ref": "#/definitions/fractionalWeightArg"
}
},
"fractionalRule": {
"type": "object",
"additionalProperties": false,
"properties": {
"fractional": {
"title": "Fractional Operation",
"description": "Deterministic, pseudorandom fractional distribution.",
"oneOf": [
{
"$ref": "#/definitions/fractionalOp"
},
{
"$ref": "#/definitions/fractionalShorthandOp"
}
]
}
}
},
"reference": {
"additionalProperties": false,
"type": "object",
"$comment": "patternProperties here is a bit of a hack to prevent this definition from being dereferenced early.",
"patternProperties": {
"^\\$ref$": {
"title": "Reference",
"description": "A reference to another entity, used for $evaluators (shared rules).",
"type": "string"
}
}
},
"args": {
"oneOf": [
{
"$ref": "#/definitions/reference"
},
{
"$ref": "#/definitions/anyRule"
},
{
"$ref": "#/definitions/primitive"
}
]
},
"anyRule": {
"anyOf": [
{
"$ref": "#/definitions/varRule"
},
{
"$ref": "#/definitions/missingRule"
},
{
"$ref": "#/definitions/missingSomeRule"
},
{
"$ref": "#/definitions/binaryRule"
},
{
"$ref": "#/definitions/binaryOrTernaryRule"
},
{
"$ref": "#/definitions/associativeRule"
},
{
"$ref": "#/definitions/unaryRule"
},
{
"$ref": "#/definitions/variadicRule"
},
{
"$ref": "#/definitions/reduceRule"
},
{
"$ref": "#/definitions/stringCompareRule"
},
{
"$ref": "#/definitions/ruleSemVer"
},
{
"$ref": "#/definitions/fractionalRule"
}
]
}
}
}