@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,25 @@
|
|
|
1
|
+
import { type AccountPermissionMatch } from './scopes/account-permission.js';
|
|
2
|
+
import { type BlobPermissionMatch } from './scopes/blob-permission.js';
|
|
3
|
+
import { type IdentityPermissionMatch } from './scopes/identity-permission.js';
|
|
4
|
+
import { type RepoPermissionMatch } from './scopes/repo-permission.js';
|
|
5
|
+
import { type RpcPermissionMatch } from './scopes/rpc-permission.js';
|
|
6
|
+
import { type SpacePermissionMatch } from './scopes/space-permission.js';
|
|
7
|
+
import { ScopesSet } from './scopes-set.js';
|
|
8
|
+
export type { AccountPermissionMatch, BlobPermissionMatch, IdentityPermissionMatch, RepoPermissionMatch, RpcPermissionMatch, SpacePermissionMatch, };
|
|
9
|
+
export declare class ScopePermissions {
|
|
10
|
+
readonly scopes: ScopesSet;
|
|
11
|
+
constructor(scope?: null | string | Iterable<string>);
|
|
12
|
+
allowsAccount(options: AccountPermissionMatch): boolean;
|
|
13
|
+
assertAccount(options: AccountPermissionMatch): void;
|
|
14
|
+
allowsIdentity(options: IdentityPermissionMatch): boolean;
|
|
15
|
+
assertIdentity(options: IdentityPermissionMatch): void;
|
|
16
|
+
allowsBlob(options: BlobPermissionMatch): boolean;
|
|
17
|
+
assertBlob(options: BlobPermissionMatch): void;
|
|
18
|
+
allowsRepo(options: RepoPermissionMatch): boolean;
|
|
19
|
+
assertRepo(options: RepoPermissionMatch): void;
|
|
20
|
+
allowsRpc(options: RpcPermissionMatch): boolean;
|
|
21
|
+
assertRpc(options: RpcPermissionMatch): void;
|
|
22
|
+
allowsSpace(options: SpacePermissionMatch): boolean;
|
|
23
|
+
assertSpace(options: SpacePermissionMatch): void;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=scope-permissions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope-permissions.d.ts","sourceRoot":"","sources":["../src/scope-permissions.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,sBAAsB,EAC5B,MAAM,gCAAgC,CAAA;AACvC,OAAO,EAEL,KAAK,mBAAmB,EACzB,MAAM,6BAA6B,CAAA;AACpC,OAAO,EAEL,KAAK,uBAAuB,EAC7B,MAAM,iCAAiC,CAAA;AACxC,OAAO,EAEL,KAAK,mBAAmB,EACzB,MAAM,6BAA6B,CAAA;AACpC,OAAO,EAEL,KAAK,kBAAkB,EACxB,MAAM,4BAA4B,CAAA;AACnC,OAAO,EAEL,KAAK,oBAAoB,EAC1B,MAAM,8BAA8B,CAAA;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE3C,YAAY,EACV,sBAAsB,EACtB,mBAAmB,EACnB,uBAAuB,EACvB,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,GACrB,CAAA;AAED,qBAAa,gBAAgB;IAC3B,SAAgB,MAAM,EAAE,SAAS,CAAA;IAEjC,YAAY,KAAK,CAAC,EAAE,IAAI,GAAG,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,EAQnD;IAEM,aAAa,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAE7D;IACM,aAAa,CAAC,OAAO,EAAE,sBAAsB,GAAG,IAAI,CAK1D;IAEM,cAAc,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAE/D;IACM,cAAc,CAAC,OAAO,EAAE,uBAAuB,GAAG,IAAI,CAK5D;IAEM,UAAU,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAEvD;IACM,UAAU,CAAC,OAAO,EAAE,mBAAmB,GAAG,IAAI,CAKpD;IAEM,UAAU,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAEvD;IACM,UAAU,CAAC,OAAO,EAAE,mBAAmB,GAAG,IAAI,CAKpD;IAEM,SAAS,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAErD;IACM,SAAS,CAAC,OAAO,EAAE,kBAAkB,GAAG,IAAI,CAKlD;IAEM,WAAW,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAEzD;IACM,WAAW,CAAC,OAAO,EAAE,oBAAoB,GAAG,IAAI,CAKtD;CACF"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { ScopeMissingError } from './scope-missing-error.js';
|
|
2
|
+
import { AccountPermission, } from './scopes/account-permission.js';
|
|
3
|
+
import { BlobPermission, } from './scopes/blob-permission.js';
|
|
4
|
+
import { IdentityPermission, } from './scopes/identity-permission.js';
|
|
5
|
+
import { RepoPermission, } from './scopes/repo-permission.js';
|
|
6
|
+
import { RpcPermission, } from './scopes/rpc-permission.js';
|
|
7
|
+
import { SpacePermission, } from './scopes/space-permission.js';
|
|
8
|
+
import { ScopesSet } from './scopes-set.js';
|
|
9
|
+
export class ScopePermissions {
|
|
10
|
+
constructor(scope) {
|
|
11
|
+
this.scopes = new ScopesSet(!scope // "" | null | undefined
|
|
12
|
+
? undefined
|
|
13
|
+
: typeof scope === 'string'
|
|
14
|
+
? scope.split(' ')
|
|
15
|
+
: scope);
|
|
16
|
+
}
|
|
17
|
+
allowsAccount(options) {
|
|
18
|
+
return this.scopes.matches('account', options);
|
|
19
|
+
}
|
|
20
|
+
assertAccount(options) {
|
|
21
|
+
if (!this.allowsAccount(options)) {
|
|
22
|
+
const scope = AccountPermission.scopeNeededFor(options);
|
|
23
|
+
throw new ScopeMissingError(scope);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
allowsIdentity(options) {
|
|
27
|
+
return this.scopes.matches('identity', options);
|
|
28
|
+
}
|
|
29
|
+
assertIdentity(options) {
|
|
30
|
+
if (!this.allowsIdentity(options)) {
|
|
31
|
+
const scope = IdentityPermission.scopeNeededFor(options);
|
|
32
|
+
throw new ScopeMissingError(scope);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
allowsBlob(options) {
|
|
36
|
+
return this.scopes.matches('blob', options);
|
|
37
|
+
}
|
|
38
|
+
assertBlob(options) {
|
|
39
|
+
if (!this.allowsBlob(options)) {
|
|
40
|
+
const scope = BlobPermission.scopeNeededFor(options);
|
|
41
|
+
throw new ScopeMissingError(scope);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
allowsRepo(options) {
|
|
45
|
+
return this.scopes.matches('repo', options);
|
|
46
|
+
}
|
|
47
|
+
assertRepo(options) {
|
|
48
|
+
if (!this.allowsRepo(options)) {
|
|
49
|
+
const scope = RepoPermission.scopeNeededFor(options);
|
|
50
|
+
throw new ScopeMissingError(scope);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
allowsRpc(options) {
|
|
54
|
+
return this.scopes.matches('rpc', options);
|
|
55
|
+
}
|
|
56
|
+
assertRpc(options) {
|
|
57
|
+
if (!this.allowsRpc(options)) {
|
|
58
|
+
const scope = RpcPermission.scopeNeededFor(options);
|
|
59
|
+
throw new ScopeMissingError(scope);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
allowsSpace(options) {
|
|
63
|
+
return this.scopes.matches('space', options);
|
|
64
|
+
}
|
|
65
|
+
assertSpace(options) {
|
|
66
|
+
if (!this.allowsSpace(options)) {
|
|
67
|
+
const scope = SpacePermission.scopeNeededFor(options);
|
|
68
|
+
throw new ScopeMissingError(scope);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=scope-permissions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope-permissions.js","sourceRoot":"","sources":["../src/scope-permissions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAC5D,OAAO,EACL,iBAAiB,G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,CAAA;IAC9C,CAAC;IACM,WAAW,CAAC,OAA6B;QAC9C,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC;YAC/B,MAAM,KAAK,GAAG,eAAe,CAAC,cAAc,CAAC,OAAO,CAAC,CAAA;YACrD,MAAM,IAAI,iBAAiB,CAAC,KAAK,CAAC,CAAA;QACpC,CAAC;IACH,CAAC;CACF","sourcesContent":["import { ScopeMissingError } from './scope-missing-error.js'\nimport {\n AccountPermission,\n type AccountPermissionMatch,\n} from './scopes/account-permission.js'\nimport {\n BlobPermission,\n type BlobPermissionMatch,\n} from './scopes/blob-permission.js'\nimport {\n IdentityPermission,\n type IdentityPermissionMatch,\n} from './scopes/identity-permission.js'\nimport {\n RepoPermission,\n type RepoPermissionMatch,\n} from './scopes/repo-permission.js'\nimport {\n RpcPermission,\n type RpcPermissionMatch,\n} from './scopes/rpc-permission.js'\nimport {\n SpacePermission,\n type SpacePermissionMatch,\n} from './scopes/space-permission.js'\nimport { ScopesSet } from './scopes-set.js'\n\nexport type {\n AccountPermissionMatch,\n BlobPermissionMatch,\n IdentityPermissionMatch,\n RepoPermissionMatch,\n RpcPermissionMatch,\n SpacePermissionMatch,\n}\n\nexport class ScopePermissions {\n public readonly scopes: ScopesSet\n\n constructor(scope?: null | string | Iterable<string>) {\n this.scopes = new ScopesSet(\n !scope // \"\" | null | undefined\n ? undefined\n : typeof scope === 'string'\n ? scope.split(' ')\n : scope,\n )\n }\n\n public allowsAccount(options: AccountPermissionMatch): boolean {\n return this.scopes.matches('account', options)\n }\n public assertAccount(options: AccountPermissionMatch): void {\n if (!this.allowsAccount(options)) {\n const scope = AccountPermission.scopeNeededFor(options)\n throw new ScopeMissingError(scope)\n }\n }\n\n public allowsIdentity(options: IdentityPermissionMatch): boolean {\n return this.scopes.matches('identity', options)\n }\n public assertIdentity(options: IdentityPermissionMatch): void {\n if (!this.allowsIdentity(options)) {\n const scope = IdentityPermission.scopeNeededFor(options)\n throw new ScopeMissingError(scope)\n }\n }\n\n public allowsBlob(options: BlobPermissionMatch): boolean {\n return this.scopes.matches('blob', options)\n }\n public assertBlob(options: BlobPermissionMatch): void {\n if (!this.allowsBlob(options)) {\n const scope = BlobPermission.scopeNeededFor(options)\n throw new ScopeMissingError(scope)\n }\n }\n\n public allowsRepo(options: RepoPermissionMatch): boolean {\n return this.scopes.matches('repo', options)\n }\n public assertRepo(options: RepoPermissionMatch): void {\n if (!this.allowsRepo(options)) {\n const scope = RepoPermission.scopeNeededFor(options)\n throw new ScopeMissingError(scope)\n }\n }\n\n public allowsRpc(options: RpcPermissionMatch): boolean {\n return this.scopes.matches('rpc', options)\n }\n public assertRpc(options: RpcPermissionMatch): void {\n if (!this.allowsRpc(options)) {\n const scope = RpcPermission.scopeNeededFor(options)\n throw new ScopeMissingError(scope)\n }\n }\n\n public allowsSpace(options: SpacePermissionMatch): boolean {\n return this.scopes.matches('space', options)\n }\n public assertSpace(options: SpacePermissionMatch): void {\n if (!this.allowsSpace(options)) {\n const scope = SpacePermission.scopeNeededFor(options)\n throw new ScopeMissingError(scope)\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Parser } from '../lib/parser.js';
|
|
2
|
+
import type { ResourcePermission } from '../lib/resource-permission.js';
|
|
3
|
+
import { type NeRoArray, type ScopeSyntax } from '../lib/syntax.js';
|
|
4
|
+
export declare const ACCOUNT_ATTRIBUTES: readonly ["email", "repo", "status"];
|
|
5
|
+
export type AccountAttribute = (typeof ACCOUNT_ATTRIBUTES)[number];
|
|
6
|
+
export declare const ACCOUNT_ACTIONS: readonly ["read", "manage"];
|
|
7
|
+
export type AccountAction = (typeof ACCOUNT_ACTIONS)[number];
|
|
8
|
+
export type AccountPermissionMatch = {
|
|
9
|
+
attr: AccountAttribute;
|
|
10
|
+
action: AccountAction;
|
|
11
|
+
};
|
|
12
|
+
export declare class AccountPermission implements ResourcePermission<'account', AccountPermissionMatch> {
|
|
13
|
+
readonly attr: AccountAttribute;
|
|
14
|
+
readonly action: NeRoArray<AccountAction>;
|
|
15
|
+
constructor(attr: AccountAttribute, action: NeRoArray<AccountAction>);
|
|
16
|
+
matches(options: AccountPermissionMatch): boolean;
|
|
17
|
+
toString(): import("../lib/syntax.js").ScopeStringFor<"account">;
|
|
18
|
+
protected static readonly parser: Parser<"account", {
|
|
19
|
+
attr: {
|
|
20
|
+
multiple: false;
|
|
21
|
+
required: true;
|
|
22
|
+
validate: (value: unknown) => value is "email" | "repo" | "status";
|
|
23
|
+
};
|
|
24
|
+
action: {
|
|
25
|
+
multiple: true;
|
|
26
|
+
required: false;
|
|
27
|
+
validate: (value: unknown) => value is "manage" | "read";
|
|
28
|
+
default: ["read"];
|
|
29
|
+
};
|
|
30
|
+
}>;
|
|
31
|
+
static fromString(scope: string): AccountPermission | null;
|
|
32
|
+
static fromSyntax(syntax: ScopeSyntax<'account'>): AccountPermission | null;
|
|
33
|
+
static scopeNeededFor(options: AccountPermissionMatch): import("../lib/syntax.js").ScopeStringFor<"account">;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=account-permission.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-permission.d.ts","sourceRoot":"","sources":["../../src/scopes/account-permission.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAA;AAEvE,OAAO,EACL,KAAK,SAAS,EACd,KAAK,WAAW,EAEjB,MAAM,kBAAkB,CAAA;AAGzB,eAAO,MAAM,kBAAkB,sCAIpB,CAAA;AACX,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAA;AAElE,eAAO,MAAM,eAAe,6BAA6C,CAAA;AACzE,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAA;AAE5D,MAAM,MAAM,sBAAsB,GAAG;IACnC,IAAI,EAAE,gBAAgB,CAAA;IACtB,MAAM,EAAE,aAAa,CAAA;CACtB,CAAA;AAED,qBAAa,iBAAkB,YAAW,kBAAkB,CAC1D,SAAS,EACT,sBAAsB,CACvB;aAEmB,IAAI,EAAE,gBAAgB;aACtB,MAAM,EAAE,SAAS,CAAC,aAAa,CAAC;IAFlD,YACkB,IAAI,EAAE,gBAAgB,EACtB,MAAM,EAAE,SAAS,CAAC,aAAa,CAAC,EAC9C;IAEJ,OAAO,CAAC,OAAO,EAAE,sBAAsB,WAKtC;IAED,QAAQ,yDAEP;IAED,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM;;;;;;;;;;;;OAgB/B;IAED,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,MAAM,4BAI9B;IAED,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,WAAW,CAAC,SAAS,CAAC,4BAK/C;IAED,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,sBAAsB,wDAKpD;CACF"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Parser } from '../lib/parser.js';
|
|
2
|
+
import { ScopeStringSyntax } from '../lib/syntax-string.js';
|
|
3
|
+
import { isScopeStringFor, } from '../lib/syntax.js';
|
|
4
|
+
import { knownValuesValidator } from '../lib/util.js';
|
|
5
|
+
export const ACCOUNT_ATTRIBUTES = Object.freeze([
|
|
6
|
+
'email',
|
|
7
|
+
'repo',
|
|
8
|
+
'status',
|
|
9
|
+
]);
|
|
10
|
+
export const ACCOUNT_ACTIONS = Object.freeze(['read', 'manage']);
|
|
11
|
+
export class AccountPermission {
|
|
12
|
+
constructor(attr, action) {
|
|
13
|
+
this.attr = attr;
|
|
14
|
+
this.action = action;
|
|
15
|
+
}
|
|
16
|
+
matches(options) {
|
|
17
|
+
return (this.attr === options.attr &&
|
|
18
|
+
(this.action.includes('manage') || this.action.includes(options.action)));
|
|
19
|
+
}
|
|
20
|
+
toString() {
|
|
21
|
+
return AccountPermission.parser.format(this);
|
|
22
|
+
}
|
|
23
|
+
static { this.parser = new Parser('account', {
|
|
24
|
+
attr: {
|
|
25
|
+
multiple: false,
|
|
26
|
+
required: true,
|
|
27
|
+
validate: knownValuesValidator(ACCOUNT_ATTRIBUTES),
|
|
28
|
+
},
|
|
29
|
+
action: {
|
|
30
|
+
multiple: true,
|
|
31
|
+
required: false,
|
|
32
|
+
validate: knownValuesValidator(ACCOUNT_ACTIONS),
|
|
33
|
+
default: ['read'],
|
|
34
|
+
},
|
|
35
|
+
}, 'attr'); }
|
|
36
|
+
static fromString(scope) {
|
|
37
|
+
if (!isScopeStringFor(scope, 'account'))
|
|
38
|
+
return null;
|
|
39
|
+
const syntax = ScopeStringSyntax.fromString(scope);
|
|
40
|
+
return AccountPermission.fromSyntax(syntax);
|
|
41
|
+
}
|
|
42
|
+
static fromSyntax(syntax) {
|
|
43
|
+
const result = AccountPermission.parser.parse(syntax);
|
|
44
|
+
if (!result)
|
|
45
|
+
return null;
|
|
46
|
+
return new AccountPermission(result.attr, result.action);
|
|
47
|
+
}
|
|
48
|
+
static scopeNeededFor(options) {
|
|
49
|
+
return AccountPermission.parser.format({
|
|
50
|
+
attr: options.attr,
|
|
51
|
+
action: [options.action],
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=account-permission.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-permission.js","sourceRoot":"","sources":["../../src/scopes/account-permission.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAEzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AAC3D,OAAO,EAGL,gBAAgB,GACjB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AAErD,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CA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AAU,CAAC,MAA8B;QAC9C,MAAM,MAAM,GAAG,iBAAiB,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;QACrD,IAAI,CAAC,MAAM;YAAE,OAAO,IAAI,CAAA;QAExB,OAAO,IAAI,iBAAiB,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;IAC1D,CAAC;IAED,MAAM,CAAC,cAAc,CAAC,OAA+B;QACnD,OAAO,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC;YACrC,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,MAAM,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC;SACzB,CAAC,CAAA;IACJ,CAAC;CACF","sourcesContent":["import { Parser } from '../lib/parser.js'\nimport type { ResourcePermission } from '../lib/resource-permission.js'\nimport { ScopeStringSyntax } from '../lib/syntax-string.js'\nimport {\n type NeRoArray,\n type ScopeSyntax,\n isScopeStringFor,\n} from '../lib/syntax.js'\nimport { knownValuesValidator } from '../lib/util.js'\n\nexport const ACCOUNT_ATTRIBUTES = Object.freeze([\n 'email',\n 'repo',\n 'status',\n] as const)\nexport type AccountAttribute = (typeof ACCOUNT_ATTRIBUTES)[number]\n\nexport const ACCOUNT_ACTIONS = Object.freeze(['read', 'manage'] as const)\nexport type AccountAction = (typeof ACCOUNT_ACTIONS)[number]\n\nexport type AccountPermissionMatch = {\n attr: AccountAttribute\n action: AccountAction\n}\n\nexport class AccountPermission implements ResourcePermission<\n 'account',\n AccountPermissionMatch\n> {\n constructor(\n public readonly attr: AccountAttribute,\n public readonly action: NeRoArray<AccountAction>,\n ) {}\n\n matches(options: AccountPermissionMatch) {\n return (\n this.attr === options.attr &&\n (this.action.includes('manage') || this.action.includes(options.action))\n )\n }\n\n toString() {\n return AccountPermission.parser.format(this)\n }\n\n protected static readonly parser = new Parser(\n 'account',\n {\n attr: {\n multiple: false,\n required: true,\n validate: knownValuesValidator(ACCOUNT_ATTRIBUTES),\n },\n action: {\n multiple: true,\n required: false,\n validate: knownValuesValidator(ACCOUNT_ACTIONS),\n default: ['read' as const],\n },\n },\n 'attr',\n )\n\n static fromString(scope: string) {\n if (!isScopeStringFor(scope, 'account')) return null\n const syntax = ScopeStringSyntax.fromString(scope)\n return AccountPermission.fromSyntax(syntax)\n }\n\n static fromSyntax(syntax: ScopeSyntax<'account'>) {\n const result = AccountPermission.parser.parse(syntax)\n if (!result) return null\n\n return new AccountPermission(result.attr, result.action)\n }\n\n static scopeNeededFor(options: AccountPermissionMatch) {\n return AccountPermission.parser.format({\n attr: options.attr,\n action: [options.action],\n })\n }\n}\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type Accept, isAccept } from '../lib/mime.js';
|
|
2
|
+
import { Parser } from '../lib/parser.js';
|
|
3
|
+
import type { ResourcePermission } from '../lib/resource-permission.js';
|
|
4
|
+
import { type NeArray, type NeRoArray, type ParamValue, type ScopeSyntax } from '../lib/syntax.js';
|
|
5
|
+
export { type Accept };
|
|
6
|
+
export declare const DEFAULT_ACCEPT: readonly ["*/*"];
|
|
7
|
+
export type BlobPermissionMatch = {
|
|
8
|
+
mime: string;
|
|
9
|
+
};
|
|
10
|
+
export declare class BlobPermission implements ResourcePermission<'blob', BlobPermissionMatch> {
|
|
11
|
+
readonly accept: NeRoArray<Accept>;
|
|
12
|
+
constructor(accept: NeRoArray<Accept>);
|
|
13
|
+
matches(options: BlobPermissionMatch): boolean;
|
|
14
|
+
toString(): import("../lib/syntax.js").ScopeStringFor<"blob">;
|
|
15
|
+
protected static readonly parser: Parser<"blob", {
|
|
16
|
+
accept: {
|
|
17
|
+
multiple: true;
|
|
18
|
+
required: true;
|
|
19
|
+
validate: typeof isAccept;
|
|
20
|
+
normalize: (value: NeRoArray<ParamValue>) => NeArray<Accept> | readonly ["*/*"];
|
|
21
|
+
};
|
|
22
|
+
}>;
|
|
23
|
+
static fromString(scope: string): BlobPermission | null;
|
|
24
|
+
static fromSyntax(syntax: ScopeSyntax<'blob'>): BlobPermission | null;
|
|
25
|
+
static scopeNeededFor(options: BlobPermissionMatch): import("../lib/syntax.js").ScopeStringFor<"blob">;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=blob-permission.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blob-permission.d.ts","sourceRoot":"","sources":["../../src/scopes/blob-permission.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,QAAQ,EAAoB,MAAM,gBAAgB,CAAA;AACxE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAA;AAEvE,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,WAAW,EAEjB,MAAM,kBAAkB,CAAA;AAEzB,OAAO,EAAE,KAAK,MAAM,EAAE,CAAA;AAEtB,eAAO,MAAM,cAAc,kBAAkC,CAAA;AAE7D,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED,qBAAa,cAAe,YAAW,kBAAkB,CACvD,MAAM,EACN,mBAAmB,CACpB;aAC6B,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC;IAArD,YAA4B,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,EAAI;IAEzD,OAAO,CAAC,OAAO,EAAE,mBAAmB,WAEnC;IAED,QAAQ,sDAEP;IAED,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM;;;;;;;OAmB/B;IAED,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,MAAM,yBAI9B;IAED,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,yBAK5C;IAED,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,mBAAmB,qDAIjD;CACF"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { isAccept, matchesAnyAccept } from '../lib/mime.js';
|
|
2
|
+
import { Parser } from '../lib/parser.js';
|
|
3
|
+
import { ScopeStringSyntax } from '../lib/syntax-string.js';
|
|
4
|
+
import { isScopeStringFor, } from '../lib/syntax.js';
|
|
5
|
+
export {};
|
|
6
|
+
export const DEFAULT_ACCEPT = Object.freeze(['*/*']);
|
|
7
|
+
export class BlobPermission {
|
|
8
|
+
constructor(accept) {
|
|
9
|
+
this.accept = accept;
|
|
10
|
+
}
|
|
11
|
+
matches(options) {
|
|
12
|
+
return matchesAnyAccept(this.accept, options.mime);
|
|
13
|
+
}
|
|
14
|
+
toString() {
|
|
15
|
+
return BlobPermission.parser.format(this);
|
|
16
|
+
}
|
|
17
|
+
static { this.parser = new Parser('blob', {
|
|
18
|
+
accept: {
|
|
19
|
+
multiple: true,
|
|
20
|
+
required: true,
|
|
21
|
+
validate: isAccept,
|
|
22
|
+
normalize: (value) => {
|
|
23
|
+
// Returns a more concise representation of the accept values.
|
|
24
|
+
if (value.includes('*/*'))
|
|
25
|
+
return DEFAULT_ACCEPT;
|
|
26
|
+
return value
|
|
27
|
+
.map(toLowerCase)
|
|
28
|
+
.filter(isNonRedundant)
|
|
29
|
+
.sort();
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
}, 'accept'); }
|
|
33
|
+
static fromString(scope) {
|
|
34
|
+
if (!isScopeStringFor(scope, 'blob'))
|
|
35
|
+
return null;
|
|
36
|
+
const syntax = ScopeStringSyntax.fromString(scope);
|
|
37
|
+
return BlobPermission.fromSyntax(syntax);
|
|
38
|
+
}
|
|
39
|
+
static fromSyntax(syntax) {
|
|
40
|
+
const result = BlobPermission.parser.parse(syntax);
|
|
41
|
+
if (!result)
|
|
42
|
+
return null;
|
|
43
|
+
return new BlobPermission(result.accept);
|
|
44
|
+
}
|
|
45
|
+
static scopeNeededFor(options) {
|
|
46
|
+
return BlobPermission.parser.format({
|
|
47
|
+
accept: [options.mime],
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function toLowerCase(value) {
|
|
52
|
+
return (typeof value === 'string' ? value.toLowerCase() : value);
|
|
53
|
+
}
|
|
54
|
+
function isNonRedundant(value, index, arr) {
|
|
55
|
+
if (typeof value !== 'string') {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
if (value.endsWith('/*')) {
|
|
59
|
+
// assuming the array contains unique element, wildcards cannot be redundant
|
|
60
|
+
// with one another ('image/*' is not redundant with 'text/*')
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
const base = value.split('/', 1)[0];
|
|
64
|
+
if (arr.includes(`${base}/*`)) {
|
|
65
|
+
// If another value in the array is a wildcard for the same base, we can
|
|
66
|
+
// skip this one as it is redundant. e.g. if the array contains 'image/png'
|
|
67
|
+
// and 'image/*', we can skip 'image/png' because 'image/*' already covers
|
|
68
|
+
// it.
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=blob-permission.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blob-permission.js","sourceRoot":"","sources":["../../src/scopes/blob-permission.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,QAAQ,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AACxE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAEzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AAC3D,OAAO,EAKL,gBAAgB,GACjB,MAAM,kBAAkB,CAAA;AAEzB,OAAO,EAAe,CAAA;AAEtB,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,CAAU,CAAC,CAAA;AAM7D,MAAM,OAAO,cAAc;IAIzB,YAA4B,MAAyB;sBAAzB,MAAM;IAAsB,CAAC;IAEzD,OAAO,CAAC,OAA4B;QAClC,OAAO,gBAAgB,CA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,CAAC;CACF;AAED,SAAS,WAAW,CAClB,KAAQ;IAER,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,KAAK,CACvB,CAAA;AACpC,CAAC;AAED,SAAS,cAAc,CACrB,KAAiB,EACjB,KAAa,EACb,GAA0B;IAE1B,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,IAAI,CAAA;IACb,CAAC;IACD,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QACzB,4EAA4E;QAC5E,8DAA8D;QAC9D,OAAO,IAAI,CAAA;IACb,CAAC;IACD,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IACnC,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,IAAI,IAAI,CAAC,EAAE,CAAC;QAC9B,wEAAwE;QACxE,2EAA2E;QAC3E,0EAA0E;QAC1E,MAAM;QACN,OAAO,KAAK,CAAA;IACd,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["import { type Accept, isAccept, matchesAnyAccept } from '../lib/mime.js'\nimport { Parser } from '../lib/parser.js'\nimport type { ResourcePermission } from '../lib/resource-permission.js'\nimport { ScopeStringSyntax } from '../lib/syntax-string.js'\nimport {\n type NeArray,\n type NeRoArray,\n type ParamValue,\n type ScopeSyntax,\n isScopeStringFor,\n} from '../lib/syntax.js'\n\nexport { type Accept }\n\nexport const DEFAULT_ACCEPT = Object.freeze(['*/*'] as const)\n\nexport type BlobPermissionMatch = {\n mime: string\n}\n\nexport class BlobPermission implements ResourcePermission<\n 'blob',\n BlobPermissionMatch\n> {\n constructor(public readonly accept: NeRoArray<Accept>) {}\n\n matches(options: BlobPermissionMatch) {\n return matchesAnyAccept(this.accept, options.mime)\n }\n\n toString() {\n return BlobPermission.parser.format(this)\n }\n\n protected static readonly parser = new Parser(\n 'blob',\n {\n accept: {\n multiple: true,\n required: true,\n validate: isAccept,\n normalize: (value) => {\n // Returns a more concise representation of the accept values.\n if (value.includes('*/*')) return DEFAULT_ACCEPT\n\n return value\n .map(toLowerCase)\n .filter(isNonRedundant)\n .sort() as NeArray<Accept>\n },\n },\n },\n 'accept',\n )\n\n static fromString(scope: string) {\n if (!isScopeStringFor(scope, 'blob')) return null\n const syntax = ScopeStringSyntax.fromString(scope)\n return BlobPermission.fromSyntax(syntax)\n }\n\n static fromSyntax(syntax: ScopeSyntax<'blob'>) {\n const result = BlobPermission.parser.parse(syntax)\n if (!result) return null\n\n return new BlobPermission(result.accept)\n }\n\n static scopeNeededFor(options: BlobPermissionMatch) {\n return BlobPermission.parser.format({\n accept: [options.mime as Accept],\n })\n }\n}\n\nfunction toLowerCase<T extends ParamValue>(\n value: T,\n): T extends string ? string : T {\n return (\n typeof value === 'string' ? value.toLowerCase() : value\n ) as T extends string ? string : T\n}\n\nfunction isNonRedundant(\n value: ParamValue,\n index: number,\n arr: readonly ParamValue[],\n): boolean {\n if (typeof value !== 'string') {\n return true\n }\n if (value.endsWith('/*')) {\n // assuming the array contains unique element, wildcards cannot be redundant\n // with one another ('image/*' is not redundant with 'text/*')\n return true\n }\n const base = value.split('/', 1)[0]\n if (arr.includes(`${base}/*`)) {\n // If another value in the array is a wildcard for the same base, we can\n // skip this one as it is redundant. e.g. if the array contains 'image/png'\n // and 'image/*', we can skip 'image/png' because 'image/*' already covers\n // it.\n return false\n }\n return true\n}\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Parser } from '../lib/parser.js';
|
|
2
|
+
import type { ResourcePermission } from '../lib/resource-permission.js';
|
|
3
|
+
import { type ScopeSyntax } from '../lib/syntax.js';
|
|
4
|
+
export declare const IDENTITY_ATTRIBUTES: readonly ["handle", "*"];
|
|
5
|
+
export type IdentityAttribute = (typeof IDENTITY_ATTRIBUTES)[number];
|
|
6
|
+
export type IdentityPermissionMatch = {
|
|
7
|
+
attr: IdentityAttribute;
|
|
8
|
+
};
|
|
9
|
+
export declare class IdentityPermission implements ResourcePermission<'identity', IdentityPermissionMatch> {
|
|
10
|
+
readonly attr: IdentityAttribute;
|
|
11
|
+
constructor(attr: IdentityAttribute);
|
|
12
|
+
matches(options: IdentityPermissionMatch): boolean;
|
|
13
|
+
toString(): import("../lib/syntax.js").ScopeStringFor<"identity">;
|
|
14
|
+
protected static readonly parser: Parser<"identity", {
|
|
15
|
+
attr: {
|
|
16
|
+
multiple: false;
|
|
17
|
+
required: true;
|
|
18
|
+
validate: (value: unknown) => value is "*" | "handle";
|
|
19
|
+
};
|
|
20
|
+
}>;
|
|
21
|
+
static fromString(scope: string): IdentityPermission | null;
|
|
22
|
+
static fromSyntax(syntax: ScopeSyntax<'identity'>): IdentityPermission | null;
|
|
23
|
+
static scopeNeededFor(options: IdentityPermissionMatch): string;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=identity-permission.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity-permission.d.ts","sourceRoot":"","sources":["../../src/scopes/identity-permission.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAA;AAEvE,OAAO,EAAE,KAAK,WAAW,EAAoB,MAAM,kBAAkB,CAAA;AAGrE,eAAO,MAAM,mBAAmB,0BAA0C,CAAA;AAC1E,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAA;AAEpE,MAAM,MAAM,uBAAuB,GAAG;IACpC,IAAI,EAAE,iBAAiB,CAAA;CACxB,CAAA;AAED,qBAAa,kBAAmB,YAAW,kBAAkB,CAC3D,UAAU,EACV,uBAAuB,CACxB;aAC6B,IAAI,EAAE,iBAAiB;IAAnD,YAA4B,IAAI,EAAE,iBAAiB,EAAI;IAEvD,OAAO,CAAC,OAAO,EAAE,uBAAuB,WAEvC;IAED,QAAQ,0DAEP;IAED,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM;;;;;;OAU/B;IAED,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,MAAM,6BAI9B;IAED,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,WAAW,CAAC,UAAU,CAAC,6BAIhD;IAED,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,uBAAuB,GAAG,MAAM,CAE9D;CACF"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Parser } from '../lib/parser.js';
|
|
2
|
+
import { ScopeStringSyntax } from '../lib/syntax-string.js';
|
|
3
|
+
import { isScopeStringFor } from '../lib/syntax.js';
|
|
4
|
+
import { knownValuesValidator } from '../lib/util.js';
|
|
5
|
+
export const IDENTITY_ATTRIBUTES = Object.freeze(['handle', '*']);
|
|
6
|
+
export class IdentityPermission {
|
|
7
|
+
constructor(attr) {
|
|
8
|
+
this.attr = attr;
|
|
9
|
+
}
|
|
10
|
+
matches(options) {
|
|
11
|
+
return this.attr === '*' || this.attr === options.attr;
|
|
12
|
+
}
|
|
13
|
+
toString() {
|
|
14
|
+
return IdentityPermission.parser.format(this);
|
|
15
|
+
}
|
|
16
|
+
static { this.parser = new Parser('identity', {
|
|
17
|
+
attr: {
|
|
18
|
+
multiple: false,
|
|
19
|
+
required: true,
|
|
20
|
+
validate: knownValuesValidator(IDENTITY_ATTRIBUTES),
|
|
21
|
+
},
|
|
22
|
+
}, 'attr'); }
|
|
23
|
+
static fromString(scope) {
|
|
24
|
+
if (!isScopeStringFor(scope, 'identity'))
|
|
25
|
+
return null;
|
|
26
|
+
const syntax = ScopeStringSyntax.fromString(scope);
|
|
27
|
+
return IdentityPermission.fromSyntax(syntax);
|
|
28
|
+
}
|
|
29
|
+
static fromSyntax(syntax) {
|
|
30
|
+
const result = IdentityPermission.parser.parse(syntax);
|
|
31
|
+
if (!result)
|
|
32
|
+
return null;
|
|
33
|
+
return new IdentityPermission(result.attr);
|
|
34
|
+
}
|
|
35
|
+
static scopeNeededFor(options) {
|
|
36
|
+
return IdentityPermission.parser.format(options);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=identity-permission.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity-permission.js","sourceRoot":"","sources":["../../src/scopes/identity-permission.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAEzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AAC3D,OAAO,EAAoB,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AACrE,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AAErD,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,GAAG,CAAU,CAAC,CAAA;AAO1E,MAAM,OAAO,kBAAkB;IAI7B,YAA4B,IAAuB;oBAAvB,IAAI;IAAsB,CAAC;IAEvD,OAAO,CAAC,OAAgC;QACtC,OAAO,IAAI,CAAC,IAAI,KAAK,GAAG,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO,CAAC,IAAI,CAAA;IACxD,CAAC;IAED,QAAQ;QACN,OAAO,kBAAkB,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAC/C,CAAC;aAEyB,WAAM,GAAG,IAAI,MAAM,CAC3C,UAAU,EACV;QACE,IAAI,EAAE;YACJ,QAAQ,EAAE,KAAK;YACf,QAAQ,EAAE,IAAI;YACd,QAAQ,EAAE,oBAAoB,CAAC,mBAAmB,CAAC;SACpD;KACF,EACD,MAAM,CACP,CAAA;IAED,MAAM,CAAC,UAAU,CAAC,KAAa;QAC7B,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,UAAU,CAAC;YAAE,OAAO,IAAI,CAAA;QACrD,MAAM,MAAM,GAAG,iBAAiB,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;QAClD,OAAO,kBAAkB,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA;IAC9C,CAAC;IAED,MAAM,CAAC,UAAU,CAAC,MAA+B;QAC/C,MAAM,MAAM,GAAG,kBAAkB,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;QACtD,IAAI,CAAC,MAAM;YAAE,OAAO,IAAI,CAAA;QACxB,OAAO,IAAI,kBAAkB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAC5C,CAAC;IAED,MAAM,CAAC,cAAc,CAAC,OAAgC;QACpD,OAAO,kBAAkB,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IAClD,CAAC;CACF","sourcesContent":["import { Parser } from '../lib/parser.js'\nimport type { ResourcePermission } from '../lib/resource-permission.js'\nimport { ScopeStringSyntax } from '../lib/syntax-string.js'\nimport { type ScopeSyntax, isScopeStringFor } from '../lib/syntax.js'\nimport { knownValuesValidator } from '../lib/util.js'\n\nexport const IDENTITY_ATTRIBUTES = Object.freeze(['handle', '*'] as const)\nexport type IdentityAttribute = (typeof IDENTITY_ATTRIBUTES)[number]\n\nexport type IdentityPermissionMatch = {\n attr: IdentityAttribute\n}\n\nexport class IdentityPermission implements ResourcePermission<\n 'identity',\n IdentityPermissionMatch\n> {\n constructor(public readonly attr: IdentityAttribute) {}\n\n matches(options: IdentityPermissionMatch) {\n return this.attr === '*' || this.attr === options.attr\n }\n\n toString() {\n return IdentityPermission.parser.format(this)\n }\n\n protected static readonly parser = new Parser(\n 'identity',\n {\n attr: {\n multiple: false,\n required: true,\n validate: knownValuesValidator(IDENTITY_ATTRIBUTES),\n },\n },\n 'attr',\n )\n\n static fromString(scope: string) {\n if (!isScopeStringFor(scope, 'identity')) return null\n const syntax = ScopeStringSyntax.fromString(scope)\n return IdentityPermission.fromSyntax(syntax)\n }\n\n static fromSyntax(syntax: ScopeSyntax<'identity'>) {\n const result = IdentityPermission.parser.parse(syntax)\n if (!result) return null\n return new IdentityPermission(result.attr)\n }\n\n static scopeNeededFor(options: IdentityPermissionMatch): string {\n return IdentityPermission.parser.format(options)\n }\n}\n"]}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { LexiconPermission, LexiconPermissionSet } from '../lib/lexicon.js';
|
|
2
|
+
import { type Nsid, isNsid } from '../lib/nsid.js';
|
|
3
|
+
import { Parser } from '../lib/parser.js';
|
|
4
|
+
import { type ScopeStringFor, type ScopeSyntax } from '../lib/syntax.js';
|
|
5
|
+
import { RepoPermission } from './repo-permission.js';
|
|
6
|
+
import { type AtprotoDidRefAbsolute, RpcPermission, isAtprotoDidRefAbsolute } from './rpc-permission.js';
|
|
7
|
+
import { SpacePermission } from './space-permission.js';
|
|
8
|
+
export { type LexiconPermission, type LexiconPermissionSet, type Nsid, isNsid };
|
|
9
|
+
/**
|
|
10
|
+
* This is used to handle "include:" oauth scope values, used to include
|
|
11
|
+
* permissions from a lexicon defined permission set. Not being a resource
|
|
12
|
+
* permission, it does not implement `Matchable`.
|
|
13
|
+
*/
|
|
14
|
+
export declare class IncludeScope {
|
|
15
|
+
readonly nsid: Nsid;
|
|
16
|
+
readonly aud: undefined | AtprotoDidRefAbsolute;
|
|
17
|
+
constructor(nsid: Nsid, aud?: undefined | AtprotoDidRefAbsolute);
|
|
18
|
+
toString(): ScopeStringFor<"include">;
|
|
19
|
+
toPermissions(permissionSet: LexiconPermissionSet): Array<RepoPermission | RpcPermission | SpacePermission>;
|
|
20
|
+
toScopes(permissionSet: LexiconPermissionSet): Array<ScopeStringFor<'repo' | 'rpc' | 'space'>>;
|
|
21
|
+
/**
|
|
22
|
+
* Converts an "include:" to the list of permissions it includes, based on the
|
|
23
|
+
* lexicon defined permission set.
|
|
24
|
+
*/
|
|
25
|
+
buildPermissions(permissionSet: LexiconPermissionSet): Generator<RepoPermission | RpcPermission | SpacePermission, void, unknown>;
|
|
26
|
+
protected parseLexPermission(permission: LexiconPermission): ScopeSyntax<'repo' | 'rpc' | 'space'> | null;
|
|
27
|
+
/**
|
|
28
|
+
* Verifies that a permission included through a lexicon permission set is
|
|
29
|
+
* allowed in the context of the `include:` scope. This basically checks that
|
|
30
|
+
* the permission is "under" the namespace authority of the `include:` scope,
|
|
31
|
+
* and that it only contains "repo:", "rpc:", or "blob:" permissions.
|
|
32
|
+
*/
|
|
33
|
+
protected isAllowedPermission(permission: RpcPermission | RepoPermission | SpacePermission): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Verifies that a permission item's nsid is under the same authority as the
|
|
36
|
+
* nsid of the lexicon itself (which is the same as the nsid of the `include:`
|
|
37
|
+
* scope).
|
|
38
|
+
*/
|
|
39
|
+
isParentAuthorityOf(otherNsid: '*' | Nsid): boolean;
|
|
40
|
+
protected static readonly parser: Parser<"include", {
|
|
41
|
+
nsid: {
|
|
42
|
+
multiple: false;
|
|
43
|
+
required: true;
|
|
44
|
+
validate: typeof isNsid;
|
|
45
|
+
};
|
|
46
|
+
aud: {
|
|
47
|
+
multiple: false;
|
|
48
|
+
required: false;
|
|
49
|
+
validate: typeof isAtprotoDidRefAbsolute;
|
|
50
|
+
};
|
|
51
|
+
}>;
|
|
52
|
+
static fromString(scope: string): IncludeScope | null;
|
|
53
|
+
static fromSyntax(syntax: ScopeSyntax<'include'>): IncludeScope | null;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=include-scope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"include-scope.d.ts","sourceRoot":"","sources":["../../src/scopes/include-scope.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAA;AAChF,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAG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