@atproto/oauth-scopes 0.0.0-spaces-alpha-20260818021221
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +220 -0
- package/LICENSE.txt +7 -0
- package/dist/atproto-oauth-scope.d.ts +17 -0
- package/dist/atproto-oauth-scope.d.ts.map +1 -0
- package/dist/atproto-oauth-scope.js +63 -0
- package/dist/atproto-oauth-scope.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/lexicon.d.ts +26 -0
- package/dist/lib/lexicon.d.ts.map +1 -0
- package/dist/lib/lexicon.js +2 -0
- package/dist/lib/lexicon.js.map +1 -0
- package/dist/lib/mime.d.ts +7 -0
- package/dist/lib/mime.d.ts.map +1 -0
- package/dist/lib/mime.js +61 -0
- package/dist/lib/mime.js.map +1 -0
- package/dist/lib/nsid.d.ts +3 -0
- package/dist/lib/nsid.d.ts.map +1 -0
- package/dist/lib/nsid.js +3 -0
- package/dist/lib/nsid.js.map +1 -0
- package/dist/lib/parser.d.ts +29 -0
- package/dist/lib/parser.d.ts.map +1 -0
- package/dist/lib/parser.js +127 -0
- package/dist/lib/parser.js.map +1 -0
- package/dist/lib/resource-permission.d.ts +10 -0
- package/dist/lib/resource-permission.d.ts.map +1 -0
- package/dist/lib/resource-permission.js +2 -0
- package/dist/lib/resource-permission.js.map +1 -0
- package/dist/lib/syntax-lexicon.d.ts +17 -0
- package/dist/lib/syntax-lexicon.d.ts.map +1 -0
- package/dist/lib/syntax-lexicon.js +62 -0
- package/dist/lib/syntax-lexicon.js.map +1 -0
- package/dist/lib/syntax-string.d.ts +16 -0
- package/dist/lib/syntax-string.d.ts.map +1 -0
- package/dist/lib/syntax-string.js +102 -0
- package/dist/lib/syntax-string.js.map +1 -0
- package/dist/lib/syntax.d.ts +24 -0
- package/dist/lib/syntax.d.ts.map +1 -0
- package/dist/lib/syntax.js +22 -0
- package/dist/lib/syntax.js.map +1 -0
- package/dist/lib/util.d.ts +7 -0
- package/dist/lib/util.d.ts.map +1 -0
- package/dist/lib/util.js +15 -0
- package/dist/lib/util.js.map +1 -0
- package/dist/scope-missing-error.d.ts +9 -0
- package/dist/scope-missing-error.d.ts.map +1 -0
- package/dist/scope-missing-error.js +15 -0
- package/dist/scope-missing-error.js.map +1 -0
- package/dist/scope-permissions-transition.d.ts +21 -0
- package/dist/scope-permissions-transition.d.ts.map +1 -0
- package/dist/scope-permissions-transition.js +58 -0
- package/dist/scope-permissions-transition.js.map +1 -0
- package/dist/scope-permissions.d.ts +25 -0
- package/dist/scope-permissions.d.ts.map +1 -0
- package/dist/scope-permissions.js +72 -0
- package/dist/scope-permissions.js.map +1 -0
- package/dist/scopes/account-permission.d.ts +35 -0
- package/dist/scopes/account-permission.d.ts.map +1 -0
- package/dist/scopes/account-permission.js +55 -0
- package/dist/scopes/account-permission.js.map +1 -0
- package/dist/scopes/blob-permission.d.ts +27 -0
- package/dist/scopes/blob-permission.d.ts.map +1 -0
- package/dist/scopes/blob-permission.js +73 -0
- package/dist/scopes/blob-permission.js.map +1 -0
- package/dist/scopes/identity-permission.d.ts +25 -0
- package/dist/scopes/identity-permission.d.ts.map +1 -0
- package/dist/scopes/identity-permission.js +39 -0
- package/dist/scopes/identity-permission.js.map +1 -0
- package/dist/scopes/include-scope.d.ts +55 -0
- package/dist/scopes/include-scope.d.ts.map +1 -0
- package/dist/scopes/include-scope.js +165 -0
- package/dist/scopes/include-scope.js.map +1 -0
- package/dist/scopes/repo-permission.d.ts +40 -0
- package/dist/scopes/repo-permission.d.ts.map +1 -0
- package/dist/scopes/repo-permission.js +81 -0
- package/dist/scopes/repo-permission.js.map +1 -0
- package/dist/scopes/rpc-permission.d.ts +38 -0
- package/dist/scopes/rpc-permission.d.ts.map +1 -0
- package/dist/scopes/rpc-permission.js +59 -0
- package/dist/scopes/rpc-permission.js.map +1 -0
- package/dist/scopes/space-permission.d.ts +111 -0
- package/dist/scopes/space-permission.d.ts.map +1 -0
- package/dist/scopes/space-permission.js +195 -0
- package/dist/scopes/space-permission.js.map +1 -0
- package/dist/scopes-set.d.ts +34 -0
- package/dist/scopes-set.d.ts.map +1 -0
- package/dist/scopes-set.js +102 -0
- package/dist/scopes-set.js.map +1 -0
- package/package.json +43 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { ScopeStringSyntax } from './syntax-string.js';
|
|
2
|
+
export class Parser {
|
|
3
|
+
constructor(prefix, schema, positionalName) {
|
|
4
|
+
this.prefix = prefix;
|
|
5
|
+
this.schema = schema;
|
|
6
|
+
this.positionalName = positionalName;
|
|
7
|
+
this.schemaKeys = new Set(Object.keys(schema));
|
|
8
|
+
}
|
|
9
|
+
format(values) {
|
|
10
|
+
const params = new URLSearchParams();
|
|
11
|
+
let positional = undefined;
|
|
12
|
+
for (const key of this.schemaKeys) {
|
|
13
|
+
const value = values[key];
|
|
14
|
+
// Ignore undefined values
|
|
15
|
+
if (value === undefined)
|
|
16
|
+
continue;
|
|
17
|
+
const schema = this.schema[key];
|
|
18
|
+
// Normalize the value if a normalization function is provided
|
|
19
|
+
const normalized = schema.normalize
|
|
20
|
+
? schema.normalize(value)
|
|
21
|
+
: value;
|
|
22
|
+
// Ignore values that are equal to the default value
|
|
23
|
+
if (!schema.required) {
|
|
24
|
+
if (schema.default === normalized)
|
|
25
|
+
continue;
|
|
26
|
+
if (schema.multiple &&
|
|
27
|
+
schema.default &&
|
|
28
|
+
arrayParamEquals(schema.default, normalized)) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (Array.isArray(normalized)) {
|
|
33
|
+
if (key === this.positionalName && normalized.length === 1) {
|
|
34
|
+
positional = String(normalized[0]);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
// remove duplicates
|
|
38
|
+
const unique = new Set(normalized.map(String));
|
|
39
|
+
for (const v of unique)
|
|
40
|
+
params.append(key, v);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
if (key === this.positionalName) {
|
|
45
|
+
positional = String(normalized);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
params.set(key, String(normalized));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return new ScopeStringSyntax(this.prefix, positional, params).toString();
|
|
53
|
+
}
|
|
54
|
+
// @NOTE If we needed to ever have more detailed reason as to why parsing
|
|
55
|
+
// fails, this function could easily be updated to return a
|
|
56
|
+
// ValidationResult<T> type that explains the reason for failure.
|
|
57
|
+
parse(syntax) {
|
|
58
|
+
// @NOTE no need to check prefix, since the typing (P generic) already
|
|
59
|
+
// ensures it matches
|
|
60
|
+
for (const key of syntax.keys()) {
|
|
61
|
+
if (!this.schemaKeys.has(key))
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
const result = Object.create(null);
|
|
65
|
+
for (const key of this.schemaKeys) {
|
|
66
|
+
const definition = this.schema[key];
|
|
67
|
+
const param = definition.multiple
|
|
68
|
+
? syntax.getMulti(key)
|
|
69
|
+
: syntax.getSingle(key);
|
|
70
|
+
if (param === null) {
|
|
71
|
+
return null; // Value is not valid
|
|
72
|
+
}
|
|
73
|
+
else if (param !== undefined) {
|
|
74
|
+
if (key === this.positionalName && syntax.positional !== undefined) {
|
|
75
|
+
// Positional parameter cannot be used with named parameters
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
if (definition.multiple) {
|
|
79
|
+
// Empty array is not valid
|
|
80
|
+
if (!param.length)
|
|
81
|
+
return null;
|
|
82
|
+
if (!param.every(definition.validate)) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
if (!definition.validate(param)) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
result[key] = param;
|
|
92
|
+
}
|
|
93
|
+
else if (key === this.positionalName &&
|
|
94
|
+
syntax.positional !== undefined) {
|
|
95
|
+
// No named parameters found, but there is a positional parameter
|
|
96
|
+
const { positional } = syntax;
|
|
97
|
+
if (!definition.validate(positional)) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
result[key] = definition.multiple ? [positional] : positional;
|
|
101
|
+
}
|
|
102
|
+
else if (definition.required) {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
result[key] = definition.default;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return result;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Two param arrays are considered equal if they contain the same values,
|
|
114
|
+
* regardless of the order and duplicates.
|
|
115
|
+
* @param a - The first array to compare.
|
|
116
|
+
* @param b - The second array to compare.
|
|
117
|
+
*/
|
|
118
|
+
function arrayParamEquals(a, b) {
|
|
119
|
+
for (const item of a)
|
|
120
|
+
if (!b.includes(item))
|
|
121
|
+
return false;
|
|
122
|
+
for (const item of b)
|
|
123
|
+
if (!a.includes(item))
|
|
124
|
+
return false;
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/lib/parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAsCtD,MAAM,OAAO,MAAM;IAGjB,YACkB,MAAS,EACT,MAAS,EACT,cAAiC;sBAFjC,MAAM;sBACN,MAAM;8BACN,cAAc;QAE9B,IAAI,CAAC,UAAU,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAA;IAChD,CAAC;IAED,MAAM,CAAC,MAAsB;QAC3B,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAA;QACpC,IAAI,UAAU,GAAuB,SAAS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K,MAAM,IAAI,IAAI,CAAC;QAAE,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC;YAAE,OAAO,KAAK,CAAA;IACzD,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["import { ScopeStringSyntax } from './syntax-string.js'\nimport type { NeRoArray, ParamValue, ScopeSyntax } from './syntax.js'\n\ntype InferParamPredicate<T extends (value: ParamValue) => boolean> =\n T extends ((value: ParamValue) => value is infer U extends ParamValue)\n ? U\n : ParamValue\n\ntype ParamsSchema = Record<\n string,\n | {\n multiple: false\n required: boolean\n default?: ParamValue\n normalize?: (value: ParamValue) => ParamValue\n validate: (value: ParamValue) => boolean\n }\n | {\n multiple: true\n required: boolean\n default?: NeRoArray<ParamValue>\n normalize?: (value: NeRoArray<ParamValue>) => NeRoArray<ParamValue>\n validate: (value: ParamValue) => boolean\n }\n>\n\ntype InferParams<S extends ParamsSchema> = {\n [K in keyof S]:\n | (S[K]['required'] extends true\n ? never\n : 'default' extends keyof S[K]\n ? S[K]['default']\n : undefined)\n | (S[K]['multiple'] extends true\n ? NeRoArray<InferParamPredicate<S[K]['validate']>>\n : InferParamPredicate<S[K]['validate']>)\n} & NonNullable<unknown>\n\nexport class Parser<P extends string, S extends ParamsSchema> {\n public readonly schemaKeys: ReadonlySet<keyof S & string>\n\n constructor(\n public readonly prefix: P,\n public readonly schema: S,\n public readonly positionalName?: keyof S & string,\n ) {\n this.schemaKeys = new Set(Object.keys(schema))\n }\n\n format(values: InferParams<S>) {\n const params = new URLSearchParams()\n let positional: string | undefined = undefined\n\n for (const key of this.schemaKeys) {\n const value = values[key]\n // Ignore undefined values\n if (value === undefined) continue\n\n const schema = this.schema[key]\n\n // Normalize the value if a normalization function is provided\n const normalized = schema.normalize\n ? schema.normalize(value as any)\n : value\n\n // Ignore values that are equal to the default value\n if (!schema.required) {\n if (schema.default === normalized) continue\n if (\n schema.multiple &&\n schema.default &&\n arrayParamEquals(schema.default, normalized as NeRoArray<string>)\n ) {\n continue\n }\n }\n\n if (Array.isArray(normalized)) {\n if (key === this.positionalName && normalized.length === 1) {\n positional = String(normalized[0]!)\n } else {\n // remove duplicates\n const unique = new Set(normalized.map(String))\n for (const v of unique) params.append(key, v)\n }\n } else {\n if (key === this.positionalName) {\n positional = String(normalized)\n } else {\n params.set(key, String(normalized))\n }\n }\n }\n\n return new ScopeStringSyntax(this.prefix, positional, params).toString()\n }\n\n // @NOTE If we needed to ever have more detailed reason as to why parsing\n // fails, this function could easily be updated to return a\n // ValidationResult<T> type that explains the reason for failure.\n parse(syntax: ScopeSyntax<P>) {\n // @NOTE no need to check prefix, since the typing (P generic) already\n // ensures it matches\n\n for (const key of syntax.keys()) {\n if (!this.schemaKeys.has(key)) return null\n }\n\n const result: Record<\n string,\n undefined | ParamValue | NeRoArray<ParamValue>\n > = Object.create(null)\n\n for (const key of this.schemaKeys) {\n const definition = this.schema[key]\n\n const param = definition.multiple\n ? syntax.getMulti(key)\n : syntax.getSingle(key)\n\n if (param === null) {\n return null // Value is not valid\n } else if (param !== undefined) {\n if (key === this.positionalName && syntax.positional !== undefined) {\n // Positional parameter cannot be used with named parameters\n return null\n }\n\n if (definition.multiple) {\n // Empty array is not valid\n if (!(param as ParamValue[]).length) return null\n if (!(param as ParamValue[]).every(definition.validate)) {\n return null\n }\n } else {\n if (!definition.validate(param as ParamValue)) {\n return null\n }\n }\n\n result[key] = param as ParamValue | NeRoArray<ParamValue>\n } else if (\n key === this.positionalName &&\n syntax.positional !== undefined\n ) {\n // No named parameters found, but there is a positional parameter\n const { positional } = syntax\n if (!definition.validate(positional)) {\n return null\n }\n result[key] = definition.multiple ? [positional] : positional\n } else if (definition.required) {\n return null\n } else {\n result[key] = definition.default\n }\n }\n\n return result as InferParams<S>\n }\n}\n\n/**\n * Two param arrays are considered equal if they contain the same values,\n * regardless of the order and duplicates.\n * @param a - The first array to compare.\n * @param b - The second array to compare.\n */\nfunction arrayParamEquals(\n a: readonly unknown[],\n b: readonly unknown[],\n): boolean {\n for (const item of a) if (!b.includes(item)) return false\n for (const item of b) if (!a.includes(item)) return false\n return true\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ScopeStringFor } from './syntax.js';
|
|
2
|
+
import type { Matchable } from './util.js';
|
|
3
|
+
/**
|
|
4
|
+
* Interface destined to provide consistency across parsed permission scopes for
|
|
5
|
+
* resources (blob, repo, etc.).
|
|
6
|
+
*/
|
|
7
|
+
export interface ResourcePermission<R extends string, T> extends Matchable<T> {
|
|
8
|
+
toString(): ScopeStringFor<R>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=resource-permission.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource-permission.d.ts","sourceRoot":"","sources":["../../src/lib/resource-permission.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAE1C;;;GAGG;AACH,MAAM,WAAW,kBAAkB,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,CAAE,SAAQ,SAAS,CAAC,CAAC,CAAC;IAC3E,QAAQ,IAAI,cAAc,CAAC,CAAC,CAAC,CAAA;CAC9B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource-permission.js","sourceRoot":"","sources":["../../src/lib/resource-permission.ts"],"names":[],"mappings":"","sourcesContent":["import type { ScopeStringFor } from './syntax.js'\nimport type { Matchable } from './util.js'\n\n/**\n * Interface destined to provide consistency across parsed permission scopes for\n * resources (blob, repo, etc.).\n */\nexport interface ResourcePermission<R extends string, T> extends Matchable<T> {\n toString(): ScopeStringFor<R>\n}\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { LexiconPermission } from './lexicon.js';
|
|
2
|
+
import type { ScopeSyntax } from './syntax.js';
|
|
3
|
+
/**
|
|
4
|
+
* Translates a {@link LexiconPermission} into a {@link ScopeSyntax}.
|
|
5
|
+
*/
|
|
6
|
+
export declare class LexPermissionSyntax<P extends string = string> implements ScopeSyntax<P> {
|
|
7
|
+
readonly lexPermission: LexiconPermission<P>;
|
|
8
|
+
constructor(lexPermission: LexiconPermission<P>);
|
|
9
|
+
get prefix(): P;
|
|
10
|
+
get positional(): undefined;
|
|
11
|
+
get(key: string): readonly import("./syntax.js").ParamValue[] | import("./syntax.js").ParamValue | undefined;
|
|
12
|
+
keys(): Generator<string, void, unknown>;
|
|
13
|
+
getSingle(key: string): import("./syntax.js").ParamValue | null | undefined;
|
|
14
|
+
getMulti(key: string): readonly import("./syntax.js").ParamValue[] | null | undefined;
|
|
15
|
+
toJSON(): LexiconPermission<P>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=syntax-lexicon.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syntax-lexicon.d.ts","sourceRoot":"","sources":["../../src/lib/syntax-lexicon.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAI9C;;GAEG;AACH,qBAAa,mBAAmB,CAC9B,CAAC,SAAS,MAAM,GAAG,MAAM,CACzB,YAAW,WAAW,CAAC,CAAC,CAAC;IACb,QAAQ,CAAC,aAAa,EAAE,iBAAiB,CAAC,CAAC,CAAC;IAAxD,YAAqB,aAAa,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAAI;IAE5D,IAAI,MAAM,MAET;IAED,IAAI,UAAU,cAEb;IAED,GAAG,CAAC,GAAG,EAAE,MAAM,8FAkBd;IAEA,IAAI,qCAMJ;IAED,SAAS,CAAC,GAAG,EAAE,MAAM,uDAIpB;IAED,QAAQ,CAAC,GAAG,EAAE,MAAM,kEAKnB;IAED,MAAM,yBAEL;CACF"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const isArray = Array.isArray;
|
|
2
|
+
/**
|
|
3
|
+
* Translates a {@link LexiconPermission} into a {@link ScopeSyntax}.
|
|
4
|
+
*/
|
|
5
|
+
export class LexPermissionSyntax {
|
|
6
|
+
constructor(lexPermission) {
|
|
7
|
+
this.lexPermission = lexPermission;
|
|
8
|
+
}
|
|
9
|
+
get prefix() {
|
|
10
|
+
return this.lexPermission.resource;
|
|
11
|
+
}
|
|
12
|
+
get positional() {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
get(key) {
|
|
16
|
+
// Ignore reserved keywords
|
|
17
|
+
if (key === 'type') {
|
|
18
|
+
// JSON spells the space type as `spaceType`, since `type` is taken by the
|
|
19
|
+
// permission discriminator. The scope string calls it `type`.
|
|
20
|
+
if (this.lexPermission.resource === 'space') {
|
|
21
|
+
if (!Object.hasOwn(this.lexPermission, 'spaceType'))
|
|
22
|
+
return undefined;
|
|
23
|
+
return this.lexPermission['spaceType'];
|
|
24
|
+
}
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
if (key === 'resource')
|
|
28
|
+
return undefined;
|
|
29
|
+
if (key === 'spaceType')
|
|
30
|
+
return undefined;
|
|
31
|
+
// Ignore inherited properties (toString(), etc.)
|
|
32
|
+
if (!Object.hasOwn(this.lexPermission, key))
|
|
33
|
+
return undefined;
|
|
34
|
+
return this.lexPermission[key];
|
|
35
|
+
}
|
|
36
|
+
*keys() {
|
|
37
|
+
const isSpace = this.lexPermission.resource === 'space';
|
|
38
|
+
for (const key of Object.keys(this.lexPermission)) {
|
|
39
|
+
const surfaceKey = isSpace && key === 'spaceType' ? 'type' : key;
|
|
40
|
+
if (this.get(surfaceKey) !== undefined)
|
|
41
|
+
yield surfaceKey;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
getSingle(key) {
|
|
45
|
+
const value = this.get(key);
|
|
46
|
+
if (isArray(value))
|
|
47
|
+
return null;
|
|
48
|
+
return value;
|
|
49
|
+
}
|
|
50
|
+
getMulti(key) {
|
|
51
|
+
const value = this.get(key);
|
|
52
|
+
if (value === undefined)
|
|
53
|
+
return undefined;
|
|
54
|
+
if (!isArray(value))
|
|
55
|
+
return null;
|
|
56
|
+
return value;
|
|
57
|
+
}
|
|
58
|
+
toJSON() {
|
|
59
|
+
return this.lexPermission;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=syntax-lexicon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syntax-lexicon.js","sourceRoot":"","sources":["../../src/lib/syntax-lexicon.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,GAAoD,KAAK,CAAC,OAAO,CAAA;AAE9E;;GAEG;AACH,MAAM,OAAO,mBAAmB;IAG9B,YAAqB,aAAmC;6BAAnC,aAAa;IAAyB,CAAC;IAE5D,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAA;IACpC,CAAC;IAED,IAAI,UAAU;QACZ,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,GAAG,CAAC,GAAW;QACb,2BAA2B;QAC3B,IAAI,GAAG,KAAK,MAAM,EAAE,CAAC;YACnB,0EAA0E;YAC1E,8DAA8D;YAC9D,IAAI,IAAI,CAAC,aAAa,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;gBAC5C,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,EAAE,WAAW,CAAC;oBAAE,OAAO,SAAS,CAAA;gBACrE,OAAO,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,CAAA;YACxC,CAAC;YACD,OAAO,SAAS,CAAA;QAClB,CAAC;QACD,IAAI,GAAG,KAAK,UAAU;YAAE,OAAO,SAAS,CAAA;QACxC,IAAI,GAAG,KAAK,WAAW;YAAE,OAAO,SAAS,CAAA;QAEzC,iDAAiD;QACjD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,EAAE,GAAG,CAAC;YAAE,OAAO,SAAS,CAAA;QAE7D,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,CAAA;IAChC,CAAC;IAED,CAAC,IAAI;QACH,MAAM,OAAO,GAAG,IAAI,CAAC,aAAa,CAAC,QAAQ,KAAK,OAAO,CAAA;QACvD,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC;YAClD,MAAM,UAAU,GAAG,OAAO,IAAI,GAAG,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAA;YAChE,IAAI,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,SAAS;gBAAE,MAAM,UAAU,CAAA;QAC1D,CAAC;IACH,CAAC;IAED,SAAS,CAAC,GAAW;QACnB,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAC3B,IAAI,OAAO,CAAC,KAAK,CAAC;YAAE,OAAO,IAAI,CAAA;QAC/B,OAAO,KAAK,CAAA;IACd,CAAC;IAED,QAAQ,CAAC,GAAW;QAClB,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAC3B,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,SAAS,CAAA;QACzC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;YAAE,OAAO,IAAI,CAAA;QAChC,OAAO,KAAK,CAAA;IACd,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,aAAa,CAAA;IAC3B,CAAC;CACF","sourcesContent":["import type { LexiconPermission } from './lexicon.js'\nimport type { ScopeSyntax } from './syntax.js'\n\nconst isArray: (value: unknown) => value is readonly unknown[] = Array.isArray\n\n/**\n * Translates a {@link LexiconPermission} into a {@link ScopeSyntax}.\n */\nexport class LexPermissionSyntax<\n P extends string = string,\n> implements ScopeSyntax<P> {\n constructor(readonly lexPermission: LexiconPermission<P>) {}\n\n get prefix() {\n return this.lexPermission.resource\n }\n\n get positional() {\n return undefined\n }\n\n get(key: string) {\n // Ignore reserved keywords\n if (key === 'type') {\n // JSON spells the space type as `spaceType`, since `type` is taken by the\n // permission discriminator. The scope string calls it `type`.\n if (this.lexPermission.resource === 'space') {\n if (!Object.hasOwn(this.lexPermission, 'spaceType')) return undefined\n return this.lexPermission['spaceType']\n }\n return undefined\n }\n if (key === 'resource') return undefined\n if (key === 'spaceType') return undefined\n\n // Ignore inherited properties (toString(), etc.)\n if (!Object.hasOwn(this.lexPermission, key)) return undefined\n\n return this.lexPermission[key]\n }\n\n *keys() {\n const isSpace = this.lexPermission.resource === 'space'\n for (const key of Object.keys(this.lexPermission)) {\n const surfaceKey = isSpace && key === 'spaceType' ? 'type' : key\n if (this.get(surfaceKey) !== undefined) yield surfaceKey\n }\n }\n\n getSingle(key: string) {\n const value = this.get(key)\n if (isArray(value)) return null\n return value\n }\n\n getMulti(key: string) {\n const value = this.get(key)\n if (value === undefined) return undefined\n if (!isArray(value)) return null\n return value\n }\n\n toJSON() {\n return this.lexPermission\n }\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ScopeStringFor, ScopeSyntax } from './syntax.js';
|
|
2
|
+
/**
|
|
3
|
+
* Translates a scope string into a {@link ScopeSyntax}.
|
|
4
|
+
*/
|
|
5
|
+
export declare class ScopeStringSyntax<P extends string> implements ScopeSyntax<P> {
|
|
6
|
+
readonly prefix: P;
|
|
7
|
+
readonly positional?: string | undefined;
|
|
8
|
+
readonly params?: Readonly<URLSearchParams> | undefined;
|
|
9
|
+
constructor(prefix: P, positional?: string | undefined, params?: Readonly<URLSearchParams> | undefined);
|
|
10
|
+
keys(): Generator<string, void, unknown>;
|
|
11
|
+
getSingle(key: string): string | null | undefined;
|
|
12
|
+
getMulti(key: string): string[] | undefined;
|
|
13
|
+
toString(): ScopeStringFor<P>;
|
|
14
|
+
static fromString<P extends string>(scopeValue: ScopeStringFor<P>): ScopeStringSyntax<P>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=syntax-string.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syntax-string.d.ts","sourceRoot":"","sources":["../../src/lib/syntax-string.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAG9D;;GAEG;AACH,qBAAa,iBAAiB,CAAC,CAAC,SAAS,MAAM,CAAE,YAAW,WAAW,CAAC,CAAC,CAAC;IAEtE,QAAQ,CAAC,MAAM,EAAE,CAAC;IAClB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM;IAC5B,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,eAAe,CAAC;IAH7C,YACW,MAAM,EAAE,CAAC,EACT,UAAU,CAAC,EAAE,MAAM,YAAA,EACnB,MAAM,CAAC,EAAE,QAAQ,CAAC,eAAe,CAAC,YAAA,EACzC;IAEH,IAAI,qCAEJ;IAED,SAAS,CAAC,GAAG,EAAE,MAAM,6BAKpB;IAED,QAAQ,CAAC,GAAG,EAAE,MAAM,wBAGnB;IAED,QAAQ,IAWU,cAAc,CAAC,CAAC,CAAC,CAClC;IAED,MAAM,CAAC,UAAU,CAAC,CAAC,SAAS,MAAM,EAChC,UAAU,EAAE,cAAc,CAAC,CAAC,CAAC,GAC5B,iBAAiB,CAAC,CAAC,CAAC,CA6BtB;CACF"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { minIdx } from './util.js';
|
|
2
|
+
/**
|
|
3
|
+
* Translates a scope string into a {@link ScopeSyntax}.
|
|
4
|
+
*/
|
|
5
|
+
export class ScopeStringSyntax {
|
|
6
|
+
constructor(prefix, positional, params) {
|
|
7
|
+
this.prefix = prefix;
|
|
8
|
+
this.positional = positional;
|
|
9
|
+
this.params = params;
|
|
10
|
+
}
|
|
11
|
+
*keys() {
|
|
12
|
+
if (this.params)
|
|
13
|
+
yield* this.params.keys();
|
|
14
|
+
}
|
|
15
|
+
getSingle(key) {
|
|
16
|
+
if (!this.params?.has(key))
|
|
17
|
+
return undefined;
|
|
18
|
+
const value = this.params.getAll(key);
|
|
19
|
+
if (value.length > 1)
|
|
20
|
+
return null;
|
|
21
|
+
return value[0];
|
|
22
|
+
}
|
|
23
|
+
getMulti(key) {
|
|
24
|
+
if (!this.params?.has(key))
|
|
25
|
+
return undefined;
|
|
26
|
+
return this.params.getAll(key);
|
|
27
|
+
}
|
|
28
|
+
toString() {
|
|
29
|
+
let scope = this.prefix;
|
|
30
|
+
if (this.positional !== undefined) {
|
|
31
|
+
scope += `:${normalizeURIComponent(encodeURIComponent(this.positional))}`;
|
|
32
|
+
}
|
|
33
|
+
if (this.params?.size) {
|
|
34
|
+
scope += `?${normalizeURIComponent(this.params.toString())}`;
|
|
35
|
+
}
|
|
36
|
+
return scope;
|
|
37
|
+
}
|
|
38
|
+
static fromString(scopeValue) {
|
|
39
|
+
const paramIdx = scopeValue.indexOf('?');
|
|
40
|
+
const colonIdx = scopeValue.indexOf(':');
|
|
41
|
+
const prefixEnd = minIdx(paramIdx, colonIdx);
|
|
42
|
+
// No param or positional
|
|
43
|
+
if (prefixEnd === -1) {
|
|
44
|
+
return new ScopeStringSyntax(scopeValue);
|
|
45
|
+
}
|
|
46
|
+
const prefix = scopeValue.slice(0, prefixEnd);
|
|
47
|
+
// Parse the positional parameter if present
|
|
48
|
+
const positional = colonIdx !== -1
|
|
49
|
+
? paramIdx === -1
|
|
50
|
+
? decodeURIComponent(scopeValue.slice(colonIdx + 1))
|
|
51
|
+
: colonIdx < paramIdx
|
|
52
|
+
? decodeURIComponent(scopeValue.slice(colonIdx + 1, paramIdx))
|
|
53
|
+
: undefined
|
|
54
|
+
: undefined;
|
|
55
|
+
// Parse the query string if present and non empty
|
|
56
|
+
const params = paramIdx !== -1 && paramIdx < scopeValue.length - 1
|
|
57
|
+
? new URLSearchParams(scopeValue.slice(paramIdx + 1))
|
|
58
|
+
: undefined;
|
|
59
|
+
return new ScopeStringSyntax(prefix, positional, params);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Set of characters that are allowed in scope components without encoding. This
|
|
64
|
+
* is used to normalize scope components.
|
|
65
|
+
*/
|
|
66
|
+
const ALLOWED_SCOPE_CHARS = new Set(
|
|
67
|
+
// @NOTE This list must not contain "?" or "&" as it would interfere with
|
|
68
|
+
// query string parsing.
|
|
69
|
+
[':', '/', '+', ',', '@', '%']);
|
|
70
|
+
const NORMALIZABLE_CHARS_MAP = new Map(Array.from(ALLOWED_SCOPE_CHARS, (c) => [encodeURIComponent(c), c]).filter(([encoded, c]) =>
|
|
71
|
+
// Make sure that any char added to ALLOWED_SCOPE_CHARS that is a char
|
|
72
|
+
// that indeed needs encoding. Also, the normalizeURIComponent only
|
|
73
|
+
// supports three-character percent-encoded sequences.
|
|
74
|
+
encoded !== c && encoded.length === 3 && encoded.startsWith('%')));
|
|
75
|
+
/**
|
|
76
|
+
* Assumes a properly url-encoded string.
|
|
77
|
+
*/
|
|
78
|
+
function normalizeURIComponent(value) {
|
|
79
|
+
// No need to read the last two characters since percent encoded characters
|
|
80
|
+
// are always three characters long.
|
|
81
|
+
let end = value.length - 2;
|
|
82
|
+
for (let i = 0; i < end; i++) {
|
|
83
|
+
// Check if the character is a percent-encoded character
|
|
84
|
+
if (value.charCodeAt(i) === 0x25 /* % */) {
|
|
85
|
+
// Read the next encoded char. Current version only supports
|
|
86
|
+
// three-character percent-encoded sequences.
|
|
87
|
+
const encodedChar = value.slice(i, i + 3);
|
|
88
|
+
// Check if the encoded character is in the normalization map
|
|
89
|
+
const normalizedChar = NORMALIZABLE_CHARS_MAP.get(encodedChar);
|
|
90
|
+
if (normalizedChar) {
|
|
91
|
+
// Replace the encoded character with its normalized version
|
|
92
|
+
value = `${value.slice(0, i)}${normalizedChar}${value.slice(i + encodedChar.length)}`;
|
|
93
|
+
// Adjust index to account for the length change
|
|
94
|
+
i += normalizedChar.length - 1;
|
|
95
|
+
// Adjust end index since we replaced encoded char with normalized char
|
|
96
|
+
end -= encodedChar.length - normalizedChar.length;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return value;
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=syntax-string.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syntax-string.js","sourceRoot":"","sources":["../../src/lib/syntax-string.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAElC;;GAEG;AACH,MAAM,OAAO,iBAAiB;IAC5B,YACW,MAAS,EACT,UAAmB,EACnB,MAAkC;sBAFlC,MAAM;0BACN,UAAU;sBACV,MAAM;IACd,CAAC;IAEJ,CAAC,IAAI;QACH,IAAI,IAAI,CAAC,MAAM;YAAE,KAAK,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAA;IAC5C,CAAC;IAED,SAAS,CAAC,GAAW;QACnB,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC;YAAE,OAAO,SAAS,CAAA;QAC5C,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QACrC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;YAAE,OAAO,IAAI,CAAA;QACjC,OAAO,KAAK,CAAC,CAAC,CAAE,CAAA;IAClB,CAAC;IAED,QAAQ,CAAC,GAAW;QAClB,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC;YAAE,OAAO,SAAS,CAAA;QAC5C,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;IAChC,CAAC;IAED,QAAQ;QACN,IAAI,KAAK,GAAW,IAAI,CAAC,MAAM,CAAA;QAE/B,IAAI,IAAI,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;YAClC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AC,CAAC,CAAA;YAEzC,6DAA6D;YAC7D,MAAM,cAAc,GAAG,sBAAsB,CAAC,GAAG,CAAC,WAAW,CAAC,CAAA;YAC9D,IAAI,cAAc,EAAE,CAAC;gBACnB,4DAA4D;gBAC5D,KAAK,GAAG,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,cAAc,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,WAAW,CAAC,MAAM,CAAC,EAAE,CAAA;gBAErF,gDAAgD;gBAChD,CAAC,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,CAAA;gBAE9B,uEAAuE;gBACvE,GAAG,IAAI,WAAW,CAAC,MAAM,GAAG,cAAc,CAAC,MAAM,CAAA;YACnD,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC","sourcesContent":["import type { ScopeStringFor, ScopeSyntax } from './syntax.js'\nimport { minIdx } from './util.js'\n\n/**\n * Translates a scope string into a {@link ScopeSyntax}.\n */\nexport class ScopeStringSyntax<P extends string> implements ScopeSyntax<P> {\n constructor(\n readonly prefix: P,\n readonly positional?: string,\n readonly params?: Readonly<URLSearchParams>,\n ) {}\n\n *keys() {\n if (this.params) yield* this.params.keys()\n }\n\n getSingle(key: string) {\n if (!this.params?.has(key)) return undefined\n const value = this.params.getAll(key)\n if (value.length > 1) return null\n return value[0]!\n }\n\n getMulti(key: string) {\n if (!this.params?.has(key)) return undefined\n return this.params.getAll(key)\n }\n\n toString() {\n let scope: string = this.prefix\n\n if (this.positional !== undefined) {\n scope += `:${normalizeURIComponent(encodeURIComponent(this.positional))}`\n }\n\n if (this.params?.size) {\n scope += `?${normalizeURIComponent(this.params.toString())}`\n }\n\n return scope as ScopeStringFor<P>\n }\n\n static fromString<P extends string>(\n scopeValue: ScopeStringFor<P>,\n ): ScopeStringSyntax<P> {\n const paramIdx = scopeValue.indexOf('?')\n const colonIdx = scopeValue.indexOf(':')\n const prefixEnd = minIdx(paramIdx, colonIdx)\n\n // No param or positional\n if (prefixEnd === -1) {\n return new ScopeStringSyntax(scopeValue as P)\n }\n\n const prefix = scopeValue.slice(0, prefixEnd) as P\n\n // Parse the positional parameter if present\n const positional =\n colonIdx !== -1\n ? paramIdx === -1\n ? decodeURIComponent(scopeValue.slice(colonIdx + 1))\n : colonIdx < paramIdx\n ? decodeURIComponent(scopeValue.slice(colonIdx + 1, paramIdx))\n : undefined\n : undefined\n\n // Parse the query string if present and non empty\n const params =\n paramIdx !== -1 && paramIdx < scopeValue.length - 1\n ? new URLSearchParams(scopeValue.slice(paramIdx + 1))\n : undefined\n\n return new ScopeStringSyntax(prefix, positional, params)\n }\n}\n\n/**\n * Set of characters that are allowed in scope components without encoding. This\n * is used to normalize scope components.\n */\nconst ALLOWED_SCOPE_CHARS = new Set(\n // @NOTE This list must not contain \"?\" or \"&\" as it would interfere with\n // query string parsing.\n [':', '/', '+', ',', '@', '%'],\n)\n\nconst NORMALIZABLE_CHARS_MAP = new Map(\n Array.from(\n ALLOWED_SCOPE_CHARS,\n (c) => [encodeURIComponent(c), c] as const,\n ).filter(\n ([encoded, c]) =>\n // Make sure that any char added to ALLOWED_SCOPE_CHARS that is a char\n // that indeed needs encoding. Also, the normalizeURIComponent only\n // supports three-character percent-encoded sequences.\n encoded !== c && encoded.length === 3 && encoded.startsWith('%'),\n ),\n)\n\n/**\n * Assumes a properly url-encoded string.\n */\nfunction normalizeURIComponent(value: string): string {\n // No need to read the last two characters since percent encoded characters\n // are always three characters long.\n let end = value.length - 2\n\n for (let i = 0; i < end; i++) {\n // Check if the character is a percent-encoded character\n if (value.charCodeAt(i) === 0x25 /* % */) {\n // Read the next encoded char. Current version only supports\n // three-character percent-encoded sequences.\n const encodedChar = value.slice(i, i + 3)\n\n // Check if the encoded character is in the normalization map\n const normalizedChar = NORMALIZABLE_CHARS_MAP.get(encodedChar)\n if (normalizedChar) {\n // Replace the encoded character with its normalized version\n value = `${value.slice(0, i)}${normalizedChar}${value.slice(i + encodedChar.length)}`\n\n // Adjust index to account for the length change\n i += normalizedChar.length - 1\n\n // Adjust end index since we replaced encoded char with normalized char\n end -= encodedChar.length - normalizedChar.length\n }\n }\n }\n\n return value\n}\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type ParamValue = string | number | boolean;
|
|
2
|
+
export type NeArray<T> = [T, ...T[]];
|
|
3
|
+
/**
|
|
4
|
+
* Non-empty readonly array
|
|
5
|
+
*/
|
|
6
|
+
export type NeRoArray<T> = readonly [T, ...T[]];
|
|
7
|
+
export type ScopeStringFor<P extends string> = P | `${P}:${string}` | `${P}?${string}`;
|
|
8
|
+
/**
|
|
9
|
+
* Allows to quickly check if a scope is for a specific resource.
|
|
10
|
+
*/
|
|
11
|
+
export declare function isScopeStringFor<P extends string>(value: string, prefix: P): value is ScopeStringFor<P>;
|
|
12
|
+
/**
|
|
13
|
+
* Abstract interface that allows parsing various syntaxes into permission
|
|
14
|
+
* representations.
|
|
15
|
+
*/
|
|
16
|
+
export interface ScopeSyntax<P extends string> {
|
|
17
|
+
readonly prefix: P;
|
|
18
|
+
readonly positional?: ParamValue;
|
|
19
|
+
keys(): Iterable<string, void, unknown>;
|
|
20
|
+
getSingle(key: string): ParamValue | null | undefined;
|
|
21
|
+
getMulti(key: string): readonly ParamValue[] | null | undefined;
|
|
22
|
+
}
|
|
23
|
+
export declare function isScopeSyntaxFor<P extends string>(syntax: ScopeSyntax<string>, prefix: P): syntax is ScopeSyntax<P>;
|
|
24
|
+
//# sourceMappingURL=syntax.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syntax.d.ts","sourceRoot":"","sources":["../../src/lib/syntax.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAA;AAElD,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAA;AAEpC;;GAEG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAA;AAE/C,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,MAAM,IACzC,CAAC,GAAG,GAAG,CAAC,IAAI,MAAM,EAAE,GAAG,GAAG,CAAC,IAAI,MAAM,EAAE,CAAA;AAEzC;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,EAC/C,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,CAAC,GACR,KAAK,IAAI,cAAc,CAAC,CAAC,CAAC,CAc5B;AAED;;;GAGG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC,SAAS,MAAM;IAC3C,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAA;IAClB,QAAQ,CAAC,UAAU,CAAC,EAAE,UAAU,CAAA;IAChC,IAAI,IAAI,QAAQ,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;IACvC,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI,GAAG,SAAS,CAAA;IACrD,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,UAAU,EAAE,GAAG,IAAI,GAAG,SAAS,CAAA;CAChE;AAED,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,EAC/C,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,EAC3B,MAAM,EAAE,CAAC,GACR,MAAM,IAAI,WAAW,CAAC,CAAC,CAAC,CAE1B"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Allows to quickly check if a scope is for a specific resource.
|
|
3
|
+
*/
|
|
4
|
+
export function isScopeStringFor(value, prefix) {
|
|
5
|
+
if (value.length > prefix.length) {
|
|
6
|
+
// First, check the next char is either : or ?
|
|
7
|
+
const nextChar = value.charCodeAt(prefix.length);
|
|
8
|
+
if (nextChar !== 0x3a /* : */ && nextChar !== 0x3f /* ? */) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
// Then check the full prefix
|
|
12
|
+
return value.startsWith(prefix);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
// value and prefix must be equal
|
|
16
|
+
return value === prefix;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export function isScopeSyntaxFor(syntax, prefix) {
|
|
20
|
+
return syntax.prefix === prefix;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=syntax.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syntax.js","sourceRoot":"","sources":["../../src/lib/syntax.ts"],"names":[],"mappings":"AAYA;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAC9B,KAAa,EACb,MAAS;IAET,IAAI,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;QACjC,8CAA8C;QAC9C,MAAM,QAAQ,GAAG,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;QAChD,IAAI,QAAQ,KAAK,IAAI,CAAC,OAAO,IAAI,QAAQ,KAAK,IAAI,CAAC,OAAO,EAAE,CAAC;YAC3D,OAAO,KAAK,CAAA;QACd,CAAC;QAED,6BAA6B;QAC7B,OAAO,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA;IACjC,CAAC;SAAM,CAAC;QACN,iCAAiC;QACjC,OAAO,KAAK,KAAK,MAAM,CAAA;IACzB,CAAC;AACH,CAAC;AAcD,MAAM,UAAU,gBAAgB,CAC9B,MAA2B,EAC3B,MAAS;IAET,OAAO,MAAM,CAAC,MAAM,KAAK,MAAM,CAAA;AACjC,CAAC","sourcesContent":["export type ParamValue = string | number | boolean\n\nexport type NeArray<T> = [T, ...T[]]\n\n/**\n * Non-empty readonly array\n */\nexport type NeRoArray<T> = readonly [T, ...T[]]\n\nexport type ScopeStringFor<P extends string> =\n P | `${P}:${string}` | `${P}?${string}`\n\n/**\n * Allows to quickly check if a scope is for a specific resource.\n */\nexport function isScopeStringFor<P extends string>(\n value: string,\n prefix: P,\n): value is ScopeStringFor<P> {\n if (value.length > prefix.length) {\n // First, check the next char is either : or ?\n const nextChar = value.charCodeAt(prefix.length)\n if (nextChar !== 0x3a /* : */ && nextChar !== 0x3f /* ? */) {\n return false\n }\n\n // Then check the full prefix\n return value.startsWith(prefix)\n } else {\n // value and prefix must be equal\n return value === prefix\n }\n}\n\n/**\n * Abstract interface that allows parsing various syntaxes into permission\n * representations.\n */\nexport interface ScopeSyntax<P extends string> {\n readonly prefix: P\n readonly positional?: ParamValue\n keys(): Iterable<string, void, unknown>\n getSingle(key: string): ParamValue | null | undefined\n getMulti(key: string): readonly ParamValue[] | null | undefined\n}\n\nexport function isScopeSyntaxFor<P extends string>(\n syntax: ScopeSyntax<string>,\n prefix: P,\n): syntax is ScopeSyntax<P> {\n return syntax.prefix === prefix\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export interface Matchable<T> {
|
|
2
|
+
matches(options: T): boolean;
|
|
3
|
+
}
|
|
4
|
+
export declare function minIdx(a: number, b: number): number;
|
|
5
|
+
export declare function knownValuesValidator<T>(values: Iterable<T>): (value: unknown) => value is T;
|
|
6
|
+
export declare function isNonNullable<T>(value: T): value is NonNullable<T>;
|
|
7
|
+
//# sourceMappingURL=util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/lib/util.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS,CAAC,CAAC;IAC1B,OAAO,CAAC,OAAO,EAAE,CAAC,GAAG,OAAO,CAAA;CAC7B;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAInD;AAED,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,WAE1C,OAAO,KAAG,KAAK,IAAI,CAAC,CACpC;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,KAAK,IAAI,WAAW,CAAC,CAAC,CAAC,CAElE"}
|
package/dist/lib/util.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function minIdx(a, b) {
|
|
2
|
+
if (a === -1)
|
|
3
|
+
return b;
|
|
4
|
+
if (b === -1)
|
|
5
|
+
return a;
|
|
6
|
+
return Math.min(a, b);
|
|
7
|
+
}
|
|
8
|
+
export function knownValuesValidator(values) {
|
|
9
|
+
const set = new Set(values);
|
|
10
|
+
return (value) => set.has(value);
|
|
11
|
+
}
|
|
12
|
+
export function isNonNullable(value) {
|
|
13
|
+
return value != null;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/lib/util.ts"],"names":[],"mappings":"AAIA,MAAM,UAAU,MAAM,CAAC,CAAS,EAAE,CAAS;IACzC,IAAI,CAAC,KAAK,CAAC,CAAC;QAAE,OAAO,CAAC,CAAA;IACtB,IAAI,CAAC,KAAK,CAAC,CAAC;QAAE,OAAO,CAAC,CAAA;IACtB,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;AACvB,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAI,MAAmB;IACzD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAU,MAAM,CAAC,CAAA;IACpC,OAAO,CAAC,KAAc,EAAc,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;AACvD,CAAC;AAED,MAAM,UAAU,aAAa,CAAI,KAAQ;IACvC,OAAO,KAAK,IAAI,IAAI,CAAA;AACtB,CAAC","sourcesContent":["export interface Matchable<T> {\n matches(options: T): boolean\n}\n\nexport function minIdx(a: number, b: number): number {\n if (a === -1) return b\n if (b === -1) return a\n return Math.min(a, b)\n}\n\nexport function knownValuesValidator<T>(values: Iterable<T>) {\n const set = new Set<unknown>(values)\n return (value: unknown): value is T => set.has(value)\n}\n\nexport function isNonNullable<T>(value: T): value is NonNullable<T> {\n return value != null\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope-missing-error.d.ts","sourceRoot":"","sources":["../src/scope-missing-error.ts"],"names":[],"mappings":"AAAA,qBAAa,iBAAkB,SAAQ,KAAK;aAWd,KAAK,EAAE,MAAM;IAVzC,IAAI,SAAsB;IAI1B,MAAM,SAAM;IACZ,MAAM,UAAO;IACb,IAAI,UAAU,WAEb;IAED,YAA4B,KAAK,EAAE,MAAM,EAExC;CACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export class ScopeMissingError extends Error {
|
|
2
|
+
get statusCode() {
|
|
3
|
+
return this.status;
|
|
4
|
+
}
|
|
5
|
+
constructor(scope) {
|
|
6
|
+
super(`Missing required scope "${scope}"`);
|
|
7
|
+
this.scope = scope;
|
|
8
|
+
this.name = 'ScopeMissingError';
|
|
9
|
+
// compatibility layer with http-errors package. The goal if to make
|
|
10
|
+
// isHttpError(new ScopeMissingError) return true.
|
|
11
|
+
this.status = 403;
|
|
12
|
+
this.expose = true;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=scope-missing-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope-missing-error.js","sourceRoot":"","sources":["../src/scope-missing-error.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAO1C,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,MAAM,CAAA;IACpB,CAAC;IAED,YAA4B,KAAa;QACvC,KAAK,CAAC,2BAA2B,KAAK,GAAG,CAAC,CAAA;QADhB,UAAK,GAAL,KAAK,CAAQ;QAVzC,SAAI,GAAG,mBAAmB,CAAA;QAE1B,oEAAoE;QACpE,kDAAkD;QAClD,WAAM,GAAG,GAAG,CAAA;QACZ,WAAM,GAAG,IAAI,CAAA;IAOb,CAAC;CACF","sourcesContent":["export class ScopeMissingError extends Error {\n name = 'ScopeMissingError'\n\n // compatibility layer with http-errors package. The goal if to make\n // isHttpError(new ScopeMissingError) return true.\n status = 403\n expose = true\n get statusCode() {\n return this.status\n }\n\n constructor(public readonly scope: string) {\n super(`Missing required scope \"${scope}\"`)\n }\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type AccountPermissionMatch, type BlobPermissionMatch, type RepoPermissionMatch, type RpcPermissionMatch, ScopePermissions, type SpacePermissionMatch } from './scope-permissions.js';
|
|
2
|
+
/**
|
|
3
|
+
* Overrides the default permission set to allow transitional scopes to be used
|
|
4
|
+
* in place of the generic scopes.
|
|
5
|
+
*/
|
|
6
|
+
export declare class ScopePermissionsTransition extends ScopePermissions {
|
|
7
|
+
get hasTransitionGeneric(): boolean;
|
|
8
|
+
get hasTransitionEmail(): boolean;
|
|
9
|
+
get hasTransitionChatBsky(): boolean;
|
|
10
|
+
allowsAccount(options: AccountPermissionMatch): boolean;
|
|
11
|
+
allowsBlob(options: BlobPermissionMatch): boolean;
|
|
12
|
+
allowsRepo(options: RepoPermissionMatch): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Grants nothing extra: `transition:generic` predates permissioned data, so a
|
|
15
|
+
* legacy token must never reach a space. Overridden rather than omitted to
|
|
16
|
+
* keep that a decision rather than an oversight.
|
|
17
|
+
*/
|
|
18
|
+
allowsSpace(options: SpacePermissionMatch): boolean;
|
|
19
|
+
allowsRpc(options: RpcPermissionMatch): boolean;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=scope-permissions-transition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope-permissions-transition.d.ts","sourceRoot":"","sources":["../src/scope-permissions-transition.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,sBAAsB,EAC3B,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,gBAAgB,EAChB,KAAK,oBAAoB,EAC1B,MAAM,wBAAwB,CAAA;AAE/B;;;GAGG;AACH,qBAAa,0BAA2B,SAAQ,gBAAgB;IAC9D,IAAI,oBAAoB,IAAI,OAAO,CAElC;IAED,IAAI,kBAAkB,IAAI,OAAO,CAEhC;IAED,IAAI,qBAAqB,IAAI,OAAO,CAEnC;IAEQ,aAAa,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAU/D;IAEQ,UAAU,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAMzD;IAEQ,UAAU,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAMzD;IAED;;;;OAIG;IACM,WAAW,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAE3D;IAEQ,SAAS,CAAC,OAAO,EAAE,kBAAkB,WAgB7C;CACF"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { ScopePermissions, } from './scope-permissions.js';
|
|
2
|
+
/**
|
|
3
|
+
* Overrides the default permission set to allow transitional scopes to be used
|
|
4
|
+
* in place of the generic scopes.
|
|
5
|
+
*/
|
|
6
|
+
export class ScopePermissionsTransition extends ScopePermissions {
|
|
7
|
+
get hasTransitionGeneric() {
|
|
8
|
+
return this.scopes.has('transition:generic');
|
|
9
|
+
}
|
|
10
|
+
get hasTransitionEmail() {
|
|
11
|
+
return this.scopes.has('transition:email');
|
|
12
|
+
}
|
|
13
|
+
get hasTransitionChatBsky() {
|
|
14
|
+
return this.scopes.has('transition:chat.bsky');
|
|
15
|
+
}
|
|
16
|
+
allowsAccount(options) {
|
|
17
|
+
if (options.attr === 'email' &&
|
|
18
|
+
options.action === 'read' &&
|
|
19
|
+
this.hasTransitionEmail) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
return super.allowsAccount(options);
|
|
23
|
+
}
|
|
24
|
+
allowsBlob(options) {
|
|
25
|
+
if (this.hasTransitionGeneric) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
return super.allowsBlob(options);
|
|
29
|
+
}
|
|
30
|
+
allowsRepo(options) {
|
|
31
|
+
if (this.hasTransitionGeneric) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
return super.allowsRepo(options);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Grants nothing extra: `transition:generic` predates permissioned data, so a
|
|
38
|
+
* legacy token must never reach a space. Overridden rather than omitted to
|
|
39
|
+
* keep that a decision rather than an oversight.
|
|
40
|
+
*/
|
|
41
|
+
allowsSpace(options) {
|
|
42
|
+
return super.allowsSpace(options);
|
|
43
|
+
}
|
|
44
|
+
allowsRpc(options) {
|
|
45
|
+
const { lxm } = options;
|
|
46
|
+
if (this.hasTransitionGeneric && lxm === '*') {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
if (this.hasTransitionGeneric && !lxm.startsWith('chat.bsky.')) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
if (this.hasTransitionChatBsky && lxm.startsWith('chat.bsky.')) {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
return super.allowsRpc(options);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=scope-permissions-transition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope-permissions-transition.js","sourceRoot":"","sources":["../src/scope-permissions-transition.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,gBAAgB,GAEjB,MAAM,wBAAwB,CAAA;AAE/B;;;GAGG;AACH,MAAM,OAAO,0BAA2B,SAAQ,gBAAgB;IAC9D,IAAI,oBAAoB;QACtB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAA;IAC9C,CAAC;IAED,IAAI,kBAAkB;QACpB,OAAO,IAAI,CAAC,MAAM,CAAC,GAA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/D,OAAO,IAAI,CAAA;QACb,CAAC;QAED,OAAO,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;IACjC,CAAC;CACF","sourcesContent":["import {\n type AccountPermissionMatch,\n type BlobPermissionMatch,\n type RepoPermissionMatch,\n type RpcPermissionMatch,\n ScopePermissions,\n type SpacePermissionMatch,\n} from './scope-permissions.js'\n\n/**\n * Overrides the default permission set to allow transitional scopes to be used\n * in place of the generic scopes.\n */\nexport class ScopePermissionsTransition extends ScopePermissions {\n get hasTransitionGeneric(): boolean {\n return this.scopes.has('transition:generic')\n }\n\n get hasTransitionEmail(): boolean {\n return this.scopes.has('transition:email')\n }\n\n get hasTransitionChatBsky(): boolean {\n return this.scopes.has('transition:chat.bsky')\n }\n\n override allowsAccount(options: AccountPermissionMatch): boolean {\n if (\n options.attr === 'email' &&\n options.action === 'read' &&\n this.hasTransitionEmail\n ) {\n return true\n }\n\n return super.allowsAccount(options)\n }\n\n override allowsBlob(options: BlobPermissionMatch): boolean {\n if (this.hasTransitionGeneric) {\n return true\n }\n\n return super.allowsBlob(options)\n }\n\n override allowsRepo(options: RepoPermissionMatch): boolean {\n if (this.hasTransitionGeneric) {\n return true\n }\n\n return super.allowsRepo(options)\n }\n\n /**\n * Grants nothing extra: `transition:generic` predates permissioned data, so a\n * legacy token must never reach a space. Overridden rather than omitted to\n * keep that a decision rather than an oversight.\n */\n override allowsSpace(options: SpacePermissionMatch): boolean {\n return super.allowsSpace(options)\n }\n\n override allowsRpc(options: RpcPermissionMatch) {\n const { lxm } = options\n\n if (this.hasTransitionGeneric && lxm === '*') {\n return true\n }\n\n if (this.hasTransitionGeneric && !lxm.startsWith('chat.bsky.')) {\n return true\n }\n\n if (this.hasTransitionChatBsky && lxm.startsWith('chat.bsky.')) {\n return true\n }\n\n return super.allowsRpc(options)\n }\n}\n"]}
|