@softistx/janus-graphql 0.0.0-stage → 0.30.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +716 -2
- package/dist/api-keys/index.d.ts +11 -0
- package/dist/api-keys/index.d.ts.map +1 -0
- package/dist/api-keys/resolvers/deps.d.ts +39 -0
- package/dist/api-keys/resolvers/deps.d.ts.map +1 -0
- package/dist/api-keys/resolvers/index.d.ts +39 -0
- package/dist/api-keys/resolvers/index.d.ts.map +1 -0
- package/dist/api-keys/resolvers/list.d.ts +16 -0
- package/dist/api-keys/resolvers/list.d.ts.map +1 -0
- package/dist/api-keys/resolvers/manage.d.ts +17 -0
- package/dist/api-keys/resolvers/manage.d.ts.map +1 -0
- package/dist/api-keys/sdl.d.ts +14 -0
- package/dist/api-keys/sdl.d.ts.map +1 -0
- package/dist/api-keys/shape.d.ts +38 -0
- package/dist/api-keys/shape.d.ts.map +1 -0
- package/dist/api-keys/types.d.ts +149 -0
- package/dist/api-keys/types.d.ts.map +1 -0
- package/dist/avatar/index.d.ts +32 -0
- package/dist/avatar/index.d.ts.map +1 -0
- package/dist/avatar/resolvers.d.ts +41 -0
- package/dist/avatar/resolvers.d.ts.map +1 -0
- package/dist/avatar/sdl.d.ts +16 -0
- package/dist/avatar/sdl.d.ts.map +1 -0
- package/dist/bad-input.d.ts +17 -0
- package/dist/bad-input.d.ts.map +1 -0
- package/dist/connection/connection.d.ts +36 -0
- package/dist/connection/connection.d.ts.map +1 -0
- package/dist/connection/credential.d.ts +34 -0
- package/dist/connection/credential.d.ts.map +1 -0
- package/dist/connection/types.d.ts +61 -0
- package/dist/connection/types.d.ts.map +1 -0
- package/dist/context/create.d.ts +32 -0
- package/dist/context/create.d.ts.map +1 -0
- package/dist/context/index.d.ts +9 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/context/registry.d.ts +72 -0
- package/dist/context/registry.d.ts.map +1 -0
- package/dist/context/resolve.d.ts +20 -0
- package/dist/context/resolve.d.ts.map +1 -0
- package/dist/device.d.ts +28 -0
- package/dist/device.d.ts.map +1 -0
- package/dist/directives/apply.d.ts +51 -0
- package/dist/directives/apply.d.ts.map +1 -0
- package/dist/directives/guard.d.ts +22 -0
- package/dist/directives/guard.d.ts.map +1 -0
- package/dist/directives/permission/enforce.d.ts +24 -0
- package/dist/directives/permission/enforce.d.ts.map +1 -0
- package/dist/directives/permission/model.d.ts +35 -0
- package/dist/directives/permission/model.d.ts.map +1 -0
- package/dist/directives/permission/path.d.ts +31 -0
- package/dist/directives/permission/path.d.ts.map +1 -0
- package/dist/directives/permission/validate.d.ts +42 -0
- package/dist/directives/permission/validate.d.ts.map +1 -0
- package/dist/directives/read.d.ts +43 -0
- package/dist/directives/read.d.ts.map +1 -0
- package/dist/directives/validate.d.ts +39 -0
- package/dist/directives/validate.d.ts.map +1 -0
- package/dist/directives/words.d.ts +7 -0
- package/dist/directives/words.d.ts.map +1 -0
- package/dist/errors/denial.d.ts +6 -0
- package/dist/errors/denial.d.ts.map +1 -0
- package/dist/errors/index.d.ts +12 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/janus-error.d.ts +20 -0
- package/dist/errors/janus-error.d.ts.map +1 -0
- package/dist/errors/mask.d.ts +69 -0
- package/dist/errors/mask.d.ts.map +1 -0
- package/dist/fresh.d.ts +44 -0
- package/dist/fresh.d.ts.map +1 -0
- package/dist/helpers.d.ts +56 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/index.d.ts +86 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3393 -0
- package/dist/index.js.map +75 -0
- package/dist/invitations/index.d.ts +12 -0
- package/dist/invitations/index.d.ts.map +1 -0
- package/dist/invitations/resolvers/anonymous.d.ts +11 -0
- package/dist/invitations/resolvers/anonymous.d.ts.map +1 -0
- package/dist/invitations/resolvers/deps.d.ts +38 -0
- package/dist/invitations/resolvers/deps.d.ts.map +1 -0
- package/dist/invitations/resolvers/index.d.ts +37 -0
- package/dist/invitations/resolvers/index.d.ts.map +1 -0
- package/dist/invitations/resolvers/owner.d.ts +17 -0
- package/dist/invitations/resolvers/owner.d.ts.map +1 -0
- package/dist/invitations/sdl/accept.d.ts +7 -0
- package/dist/invitations/sdl/accept.d.ts.map +1 -0
- package/dist/invitations/sdl/index.d.ts +14 -0
- package/dist/invitations/sdl/index.d.ts.map +1 -0
- package/dist/invitations/sdl/owner.d.ts +8 -0
- package/dist/invitations/sdl/owner.d.ts.map +1 -0
- package/dist/invitations/shape.d.ts +63 -0
- package/dist/invitations/shape.d.ts.map +1 -0
- package/dist/invitations/types/index.d.ts +5 -0
- package/dist/invitations/types/index.d.ts.map +1 -0
- package/dist/invitations/types/options.d.ts +104 -0
- package/dist/invitations/types/options.d.ts.map +1 -0
- package/dist/invitations/types/out.d.ts +136 -0
- package/dist/invitations/types/out.d.ts.map +1 -0
- package/dist/invitations/types/surface.d.ts +18 -0
- package/dist/invitations/types/surface.d.ts.map +1 -0
- package/dist/map-code.d.ts +10 -0
- package/dist/map-code.d.ts.map +1 -0
- package/dist/mask-error.d.ts +18 -0
- package/dist/mask-error.d.ts.map +1 -0
- package/dist/memo.d.ts +16 -0
- package/dist/memo.d.ts.map +1 -0
- package/dist/options.d.ts +17 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/passkeys/deps.d.ts +23 -0
- package/dist/passkeys/deps.d.ts.map +1 -0
- package/dist/passkeys/first-factor.types.d.ts +38 -0
- package/dist/passkeys/first-factor.types.d.ts.map +1 -0
- package/dist/passkeys/index.d.ts +14 -0
- package/dist/passkeys/index.d.ts.map +1 -0
- package/dist/passkeys/resolvers.d.ts +23 -0
- package/dist/passkeys/resolvers.d.ts.map +1 -0
- package/dist/passkeys/sdl.d.ts +14 -0
- package/dist/passkeys/sdl.d.ts.map +1 -0
- package/dist/passkeys/shape.d.ts +14 -0
- package/dist/passkeys/shape.d.ts.map +1 -0
- package/dist/passkeys/sign-in.resolvers.d.ts +19 -0
- package/dist/passkeys/sign-in.resolvers.d.ts.map +1 -0
- package/dist/passkeys/sign-in.sdl.d.ts +16 -0
- package/dist/passkeys/sign-in.sdl.d.ts.map +1 -0
- package/dist/passkeys/types.d.ts +193 -0
- package/dist/passkeys/types.d.ts.map +1 -0
- package/dist/plugin.d.ts +59 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/renewal.d.ts +51 -0
- package/dist/renewal.d.ts.map +1 -0
- package/dist/report.d.ts +29 -0
- package/dist/report.d.ts.map +1 -0
- package/dist/sdl.d.ts +12 -0
- package/dist/sdl.d.ts.map +1 -0
- package/dist/second-factor/index.d.ts +12 -0
- package/dist/second-factor/index.d.ts.map +1 -0
- package/dist/second-factor/resolvers/deps.d.ts +39 -0
- package/dist/second-factor/resolvers/deps.d.ts.map +1 -0
- package/dist/second-factor/resolvers/index.d.ts +39 -0
- package/dist/second-factor/resolvers/index.d.ts.map +1 -0
- package/dist/second-factor/resolvers/sign-in.d.ts +10 -0
- package/dist/second-factor/resolvers/sign-in.d.ts.map +1 -0
- package/dist/second-factor/resolvers/status.d.ts +10 -0
- package/dist/second-factor/resolvers/status.d.ts.map +1 -0
- package/dist/second-factor/resolvers/step-up.d.ts +16 -0
- package/dist/second-factor/resolvers/step-up.d.ts.map +1 -0
- package/dist/second-factor/resolvers/writes.d.ts +19 -0
- package/dist/second-factor/resolvers/writes.d.ts.map +1 -0
- package/dist/second-factor/sdl.d.ts +14 -0
- package/dist/second-factor/sdl.d.ts.map +1 -0
- package/dist/second-factor/shape.d.ts +18 -0
- package/dist/second-factor/shape.d.ts.map +1 -0
- package/dist/second-factor/types/index.d.ts +5 -0
- package/dist/second-factor/types/index.d.ts.map +1 -0
- package/dist/second-factor/types/options.d.ts +61 -0
- package/dist/second-factor/types/options.d.ts.map +1 -0
- package/dist/second-factor/types/out.d.ts +84 -0
- package/dist/second-factor/types/out.d.ts.map +1 -0
- package/dist/second-factor/types/surface.d.ts +89 -0
- package/dist/second-factor/types/surface.d.ts.map +1 -0
- package/dist/social/index.d.ts +10 -0
- package/dist/social/index.d.ts.map +1 -0
- package/dist/social/resolvers.d.ts +25 -0
- package/dist/social/resolvers.d.ts.map +1 -0
- package/dist/social/sdl.d.ts +13 -0
- package/dist/social/sdl.d.ts.map +1 -0
- package/dist/social/shape.d.ts +11 -0
- package/dist/social/shape.d.ts.map +1 -0
- package/dist/social/types.d.ts +160 -0
- package/dist/social/types.d.ts.map +1 -0
- package/dist/surface/api.d.ts +16 -0
- package/dist/surface/api.d.ts.map +1 -0
- package/dist/surface/request.d.ts +10 -0
- package/dist/surface/request.d.ts.map +1 -0
- package/dist/surface/signed-in.d.ts +30 -0
- package/dist/surface/signed-in.d.ts.map +1 -0
- package/dist/types.d.ts +117 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/wiring.d.ts +56 -0
- package/dist/wiring.d.ts.map +1 -0
- package/docs/README.md +26 -0
- package/docs/guide/api-keys.md +365 -0
- package/docs/guide/avatars.md +129 -0
- package/docs/guide/context.md +371 -0
- package/docs/guide/directives.md +371 -0
- package/docs/guide/errors.md +318 -0
- package/docs/guide/federation.md +71 -0
- package/docs/guide/invitations.md +269 -0
- package/docs/guide/passkeys.md +207 -0
- package/docs/guide/second-factor.md +238 -0
- package/docs/guide/social.md +190 -0
- package/docs/guide/step-up.md +208 -0
- package/docs/guide/subscriptions.md +255 -0
- package/docs/guide/telemetry.md +45 -0
- package/docs/roadmap.md +124 -0
- package/docs/troubleshooting.md +1265 -0
- package/graphql/janus-api-keys.graphqls +237 -0
- package/graphql/janus-avatar.graphqls +19 -0
- package/graphql/janus-invitations.graphqls +280 -0
- package/graphql/janus-passkey-sign-in.graphqls +40 -0
- package/graphql/janus-passkeys.graphqls +134 -0
- package/graphql/janus-second-factor.graphqls +199 -0
- package/graphql/janus-social.graphqls +155 -0
- package/graphql/janus.graphqls +44 -0
- package/package.json +80 -5
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The API key surface, opt-in: `apiKeysTypeDefs` beside your own type
|
|
3
|
+
* definitions and `apiKeysResolvers({ auth, lifetimes, authorize, bound? })`
|
|
4
|
+
* for its fields — the signed-in user's keys, the keys bound to an object,
|
|
5
|
+
* creating one (its secret answered once) and revoking one. Every field needs
|
|
6
|
+
* a signed-in user and your `authorize`.
|
|
7
|
+
*/
|
|
8
|
+
export { apiKeysResolvers } from './resolvers';
|
|
9
|
+
export { apiKeysTypeDefs } from './sdl';
|
|
10
|
+
export type { ApiKeyCreateSubject, ApiKeyLifetimes, ApiKeyListSubject, ApiKeyRevokeSubject, ApiKeySubjectBase, ApiKeysAuth, ApiKeysAuthorize, ApiKeysResolvers, ApiKeysResolversOptions, } from './types';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api-keys/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AACxC,YAAY,EACX,mBAAmB,EACnB,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,iBAAiB,EACjB,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,uBAAuB,GACvB,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** What every field's resolver reads, resolved once by `apiKeysResolvers()`, and the steps they share. */
|
|
2
|
+
import type { ApiKeyBound, Principal } from '@softistx/janus';
|
|
3
|
+
import type { AnyUser, ApiKeyLifetimes, ApiKeysAuth, ApiKeysAuthorize, ApiKeysResolversOptions, Context } from '../types';
|
|
4
|
+
export interface Deps {
|
|
5
|
+
readonly keys: ApiKeysAuth['apiKeys'];
|
|
6
|
+
readonly lifetimes: ApiKeyLifetimes;
|
|
7
|
+
readonly authorize: ApiKeysAuthorize;
|
|
8
|
+
readonly bound: ApiKeysResolversOptions['bound'];
|
|
9
|
+
}
|
|
10
|
+
export declare function depsOf(options: ApiKeysResolversOptions): Deps;
|
|
11
|
+
/** Who asks and about which object: the signed-in user, its principal, and the bound object. */
|
|
12
|
+
export interface Caller {
|
|
13
|
+
readonly user: AnyUser;
|
|
14
|
+
readonly bound: ApiKeyBound | null;
|
|
15
|
+
/** The request's time, from `useJanus({ clock })`: what a key's `status` is read at. */
|
|
16
|
+
readonly now: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The signed-in user (an API key's owner included), then the object `boundTo`
|
|
20
|
+
* names through the `bound` hook. A `boundTo` without the hook, or one the
|
|
21
|
+
* hook answers `null` for, is `NOT_FOUND`.
|
|
22
|
+
*/
|
|
23
|
+
export declare function callerOf(deps: Deps, ctx: Context, boundTo: string | null | undefined): Promise<Caller>;
|
|
24
|
+
/**
|
|
25
|
+
* What `authenticate` answered for the request: `apiKeys.create` needs the
|
|
26
|
+
* whole principal (its session's freshness), not the user alone.
|
|
27
|
+
*/
|
|
28
|
+
export declare function principalOf(ctx: Context): Promise<Principal<AnyUser>>;
|
|
29
|
+
/** Answers `true` or throws `NOT_FOUND`: a hook's `false` hides the object. */
|
|
30
|
+
export declare function allowed(answer: boolean | Promise<boolean>): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* The refusal of an id that names no key the call may reach: the hook is
|
|
33
|
+
* still asked, without the key, so a known and an unknown id take the same
|
|
34
|
+
* path; only a `GraphQLError` it throws (a step-up) gets through, and the
|
|
35
|
+
* answer is otherwise `NOT_FOUND`.
|
|
36
|
+
*/
|
|
37
|
+
export declare function unknownKey(ask: () => boolean | Promise<boolean>): Promise<never>;
|
|
38
|
+
export declare const sameBound: (a: ApiKeyBound | null, b: ApiKeyBound | null) => boolean;
|
|
39
|
+
//# sourceMappingURL=deps.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deps.d.ts","sourceRoot":"","sources":["../../../src/api-keys/resolvers/deps.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AOhB;AAED,eAAO,MAAM,SAAS,MAClB,WAAW,GAAG,IAAI,KAClB,WAAW,GAAG,IAAI,KACnB,OACqE,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The resolvers of the API key SDL: three `Query` fields and two `Mutation`
|
|
3
|
+
* fields over the core's `apiKeys`.
|
|
4
|
+
*/
|
|
5
|
+
import type { ApiKeysAuth, ApiKeysResolvers, ApiKeysResolversOptions } from '../types';
|
|
6
|
+
/**
|
|
7
|
+
* The resolvers of the API key SDL. A refusal of the core —
|
|
8
|
+
* `API_KEY_INVALID` (`field`), `API_KEY_LIMIT` (`maxActive`),
|
|
9
|
+
* `STEP_UP_REQUIRED`, `USER_INACTIVE`, `INVALID_CURSOR`… — is rethrown as its
|
|
10
|
+
* `GraphQLError`, so `janusMaskError()` answers its code and status. Needs
|
|
11
|
+
* `useJanus()` for the directives. Throws a `TypeError` at wiring when `auth`
|
|
12
|
+
* has no `apiKeys`, `authorize` lacks a hook, or `lifetimes` lists no
|
|
13
|
+
* lifetime or a default outside it.
|
|
14
|
+
*
|
|
15
|
+
* **`authorize` is the only guard**: say who may create, list and revoke,
|
|
16
|
+
* and which scopes a caller may grant. `bound` names the object a key acts
|
|
17
|
+
* in, for an application that binds keys.
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* const resolvers = mergeResolvers([
|
|
21
|
+
* apiKeysResolvers({
|
|
22
|
+
* auth,
|
|
23
|
+
* lifetimes: { days: [30, 90, 365], default: 90 },
|
|
24
|
+
* bound: (id) => (id === null ? null : { type: 'workspace', id }),
|
|
25
|
+
* authorize: {
|
|
26
|
+
* create: ({ bound }, ctx) => bound !== null && can(ctx, 'member', bound),
|
|
27
|
+
* list: ({ bound, every }, ctx) => bound !== null && can(ctx, every ? 'own' : 'member', bound),
|
|
28
|
+
* revoke: ({ bound, own }, ctx) => own === true || (bound !== null && can(ctx, 'own', bound)),
|
|
29
|
+
* },
|
|
30
|
+
* }),
|
|
31
|
+
* mine,
|
|
32
|
+
* ]);
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* `Query` and `Mutation` are keys of the map: merge it with yours rather than
|
|
36
|
+
* spreading over them.
|
|
37
|
+
*/
|
|
38
|
+
export declare function apiKeysResolvers<A extends ApiKeysAuth>(options: ApiKeysResolversOptions<A>): ApiKeysResolvers;
|
|
39
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api-keys/resolvers/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACX,WAAW,EACX,gBAAgB,EAChB,uBAAuB,EACvB,MAAM,UAAU,CAAC;AAKlB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,WAAW,EACrD,OAAO,EAAE,uBAAuB,CAAC,CAAC,CAAC,GACjC,gBAAgB,CAelB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** The read fields: `apiKeys`, `boundApiKeys` and `apiKeyLifetimes`. */
|
|
2
|
+
import type { ApiKeysResolvers } from '../types';
|
|
3
|
+
import { type Deps } from './deps';
|
|
4
|
+
type Queries = ApiKeysResolvers['Query'];
|
|
5
|
+
/**
|
|
6
|
+
* `Query.apiKeys`: the user's own keys, oldest first — only those bound to
|
|
7
|
+
* the call's object when the application binds keys (unbound ones when the
|
|
8
|
+
* call names none).
|
|
9
|
+
*/
|
|
10
|
+
export declare function apiKeys(deps: Deps): Queries['apiKeys'];
|
|
11
|
+
/** `Query.boundApiKeys`: every key bound to the call's object, whoever holds it. */
|
|
12
|
+
export declare function boundApiKeys(deps: Deps): Queries['boundApiKeys'];
|
|
13
|
+
/** `Query.apiKeyLifetimes`: what `createApiKey` offers. */
|
|
14
|
+
export declare function apiKeyLifetimes(deps: Deps): Queries['apiKeyLifetimes'];
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=list.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../src/api-keys/resolvers/list.ts"],"names":[],"mappings":"AAAA,wEAAwE;AAMxE,OAAO,KAAK,EAA0B,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACzE,OAAO,EAAqB,KAAK,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEtD,KAAK,OAAO,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;AAsBzC;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,SAAS,CAAC,CAqBtD;AAED,oFAAoF;AACpF,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,cAAc,CAAC,CAgBhE;AAED,2DAA2D;AAC3D,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAOtE"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** The write fields: `createApiKey` and `revokeApiKey`. */
|
|
2
|
+
import type { ApiKeysResolvers } from '../types';
|
|
3
|
+
import { type Deps } from './deps';
|
|
4
|
+
type Mutations = ApiKeysResolvers['Mutation'];
|
|
5
|
+
/**
|
|
6
|
+
* `Mutation.createApiKey`: a key for the signed-in user, bound to the call's
|
|
7
|
+
* object, and its secret once. The step-up is the core's: a session proved
|
|
8
|
+
* within `apiKeys.freshWithin`, never a key.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createApiKey(deps: Deps): Mutations['createApiKey'];
|
|
11
|
+
/**
|
|
12
|
+
* `Mutation.revokeApiKey`: revokes the caller's own key, or — as `authorize`
|
|
13
|
+
* allows — one bound to the call's object, and answers it as stored after.
|
|
14
|
+
*/
|
|
15
|
+
export declare function revokeApiKey(deps: Deps): Mutations['revokeApiKey'];
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=manage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manage.d.ts","sourceRoot":"","sources":["../../../src/api-keys/resolvers/manage.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAM3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EAIN,KAAK,IAAI,EAIT,MAAM,QAAQ,CAAC;AAEhB,KAAK,SAAS,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAC;AAE9C;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,CAAC,cAAc,CAAC,CAyBlE;AAmBD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,CAAC,cAAc,CAAC,CAuBlE"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The opt-in API key SDL: put it beside your own type definitions when users
|
|
3
|
+
* create keys for themselves (a CLI, an MCP client, a script). It `extend`s
|
|
4
|
+
* your `Query` and `Mutation`, and needs `janusTypeDefs` for its directives.
|
|
5
|
+
* The same text ships as `graphql/janus-api-keys.graphqls` — `sdl.spec.ts`
|
|
6
|
+
* holds that the two are identical. Timestamps are ISO-8601 `String`s: no
|
|
7
|
+
* scalar to collide with.
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* createSchema({ typeDefs: [janusTypeDefs, apiKeysTypeDefs, typeDefs], resolvers });
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export declare const apiKeysTypeDefs: string;
|
|
14
|
+
//# sourceMappingURL=sdl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdl.d.ts","sourceRoot":"","sources":["../../src/api-keys/sdl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,eAAe,EAAE,MA6O7B,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The answers of the API key resolvers — a core key as the plain object the
|
|
3
|
+
* schema's fields read — and the arguments checked here, before `authorize`
|
|
4
|
+
* or a store is asked.
|
|
5
|
+
*/
|
|
6
|
+
import { type ApiKey } from '@softistx/janus';
|
|
7
|
+
import type { ApiKeyLifetimes, ApiKeyOut } from './types';
|
|
8
|
+
/** A key as the schema reads it; `status` from `now`, the request's clock. */
|
|
9
|
+
export declare function apiKeyOut(key: ApiKey, now: number): ApiKeyOut;
|
|
10
|
+
/**
|
|
11
|
+
* The longest each argument may be. They mirror `@softistx/janus`'s own
|
|
12
|
+
* bounds — a name of 100 characters once trimmed, 32 scopes of 100
|
|
13
|
+
* characters, a bound id of 200 — held here so an oversized argument is
|
|
14
|
+
* refused before `authorize` or a store is asked; resolvers.create.spec.ts
|
|
15
|
+
* shows the core keeps a key at each maximum.
|
|
16
|
+
*/
|
|
17
|
+
export declare const API_KEY_LIMITS: {
|
|
18
|
+
readonly name: 100;
|
|
19
|
+
readonly scopes: 32;
|
|
20
|
+
readonly scope: 100;
|
|
21
|
+
readonly boundTo: 200;
|
|
22
|
+
};
|
|
23
|
+
/** Refuses a `name` over its maximum once trimmed, and `scopes` too many or too long. */
|
|
24
|
+
export declare function boundedCreate(name: string, scopes: readonly string[] | null | undefined): void;
|
|
25
|
+
/** The `boundTo` argument: absent (`null`), or 1 to 200 characters. */
|
|
26
|
+
export declare function boundToOf(boundTo: string | null | undefined): string | null;
|
|
27
|
+
/** The `lifetimeDays` argument: the default when absent, else one of the choices. */
|
|
28
|
+
export declare function lifetimeOf(lifetimes: ApiKeyLifetimes, lifetimeDays: number | null | undefined): number;
|
|
29
|
+
/** Refuses, at wiring, lifetimes that no key could be created with. */
|
|
30
|
+
export declare function checkedLifetimes(lifetimes: ApiKeyLifetimes | undefined): ApiKeyLifetimes;
|
|
31
|
+
/**
|
|
32
|
+
* A refusal of `apiKeys.create`, as the schema answers it. The core names the
|
|
33
|
+
* lifetime `lifetime`; the schema's argument is `lifetimeDays`, so a lifetime
|
|
34
|
+
* `lifetimes.days` offers but `janus({ apiKeys: { lifetimes } })` does not
|
|
35
|
+
* points at the argument the caller sent.
|
|
36
|
+
*/
|
|
37
|
+
export declare function createRefused(error: unknown): never;
|
|
38
|
+
//# sourceMappingURL=shape.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shape.d.ts","sourceRoot":"","sources":["../../src/api-keys/shape.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,MAAM,EAAc,MAAM,iBAAiB,CAAC;AAI1D,OAAO,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAK1D,8EAA8E;AAC9E,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,CAmB7D;AAED;;;;;;GAMG;AACH,eAAO,MAAM,cAAc;aAC1B,IAAI,EAAE,GAAG;aACT,MAAM,EAAE,EAAE;aACV,KAAK,EAAE,GAAG;aACV,OAAO,EAAE,GAAG;CACH,CAAC;AAEX,yFAAyF;AACzF,wBAAgB,aAAa,CAC5B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,GAAG,SAAS,GAC1C,IAAI,CAoBN;AAED,uEAAuE;AACvE,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAS3E;AAED,qFAAqF;AACrF,wBAAgB,UAAU,CACzB,SAAS,EAAE,eAAe,EAC1B,YAAY,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GACrC,MAAM,CASR;AAED,uEAAuE;AACvE,wBAAgB,gBAAgB,CAC/B,SAAS,EAAE,eAAe,GAAG,SAAS,GACpC,eAAe,CAqBjB;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,CASnD"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/** The types of the API key resolvers: the surface they call, their options, and their answers. */
|
|
2
|
+
import type { ApiKey, ApiKeyBound, ApiKeysApi } from '@softistx/janus';
|
|
3
|
+
/** The user as these resolvers read one. */
|
|
4
|
+
export type AnyUser = {
|
|
5
|
+
readonly type: string;
|
|
6
|
+
readonly id: string;
|
|
7
|
+
};
|
|
8
|
+
/** A GraphQL context as these resolvers read it. */
|
|
9
|
+
export interface Context {
|
|
10
|
+
readonly request?: Request;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* What `janus()` answered, as these resolvers read it: the `apiKeys` surface,
|
|
14
|
+
* which exists only for an instance configured with `apiKeys`. Binding keys
|
|
15
|
+
* needs a store with the `bound` capability (`listBound`); `get` reads one key by id.
|
|
16
|
+
*/
|
|
17
|
+
export interface ApiKeysAuth {
|
|
18
|
+
readonly apiKeys: Pick<ApiKeysApi<AnyUser, string>['apiKeys'], 'create' | 'get' | 'list' | 'listBound' | 'revoke'>;
|
|
19
|
+
}
|
|
20
|
+
/** The lifetimes a new key may have, in days, and the default. */
|
|
21
|
+
export interface ApiKeyLifetimes {
|
|
22
|
+
/**
|
|
23
|
+
* The choices, in whole days (`[30, 90, 365]`). Each must be one of the
|
|
24
|
+
* lifetimes `janus({ apiKeys: { lifetimes } })` configures (`'30d'`…),
|
|
25
|
+
* else the core refuses the key with `API_KEY_INVALID`.
|
|
26
|
+
*/
|
|
27
|
+
readonly days: readonly [number, ...number[]];
|
|
28
|
+
/** The one `createApiKey` takes when `lifetimeDays` is absent: one of `days`. */
|
|
29
|
+
readonly default: number;
|
|
30
|
+
}
|
|
31
|
+
/** What every `authorize` hook is told: who asks, and the object the call is about. */
|
|
32
|
+
export interface ApiKeySubjectBase {
|
|
33
|
+
readonly user: AnyUser;
|
|
34
|
+
/** The object `bound` answered, or `null` when keys are not bound (or this request names none). */
|
|
35
|
+
readonly bound: ApiKeyBound | null;
|
|
36
|
+
}
|
|
37
|
+
/** What `authorize.create` is asked about. */
|
|
38
|
+
export interface ApiKeyCreateSubject extends ApiKeySubjectBase {
|
|
39
|
+
readonly input: {
|
|
40
|
+
readonly name: string;
|
|
41
|
+
/** The lifetime asked for, or the default when absent. */
|
|
42
|
+
readonly lifetimeDays: number;
|
|
43
|
+
/** The scopes asked for, `null` for an unscoped key: refuse those the caller may not grant. */
|
|
44
|
+
readonly scopes: readonly string[] | null;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/** What `authorize.list` is asked about. */
|
|
48
|
+
export interface ApiKeyListSubject extends ApiKeySubjectBase {
|
|
49
|
+
/** `false` for `apiKeys` (the user's own), `true` for `boundApiKeys` (every key bound to `bound`). */
|
|
50
|
+
readonly every: boolean;
|
|
51
|
+
/** The arguments the query gave, only those present. */
|
|
52
|
+
readonly page: {
|
|
53
|
+
readonly limit?: number;
|
|
54
|
+
readonly after?: string;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/** What `authorize.revoke` is asked about. */
|
|
58
|
+
export interface ApiKeyRevokeSubject extends ApiKeySubjectBase {
|
|
59
|
+
/**
|
|
60
|
+
* The stored key, read before authorizing; absent when the id names none
|
|
61
|
+
* the call may reach (the answer is then `NOT_FOUND` whatever the hook says).
|
|
62
|
+
*/
|
|
63
|
+
readonly key?: ApiKey;
|
|
64
|
+
/** Whether `key` is the user's own; absent with `key`. */
|
|
65
|
+
readonly own?: boolean;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Who may do what: **the only guard there is**. Each hook answers `true` to
|
|
69
|
+
* let the call through; `false` answers `NOT_FOUND`, so an object's existence
|
|
70
|
+
* is not revealed; a thrown `GraphQLError` is answered as it is (a step-up, a
|
|
71
|
+
* `denial('FORBIDDEN')` for a scope beyond the caller's role).
|
|
72
|
+
*
|
|
73
|
+
* The hooks are methods so that `ctx` may be typed as the application's
|
|
74
|
+
* context (`YogaInitialContext & JanusContext<typeof auth, typeof access>`),
|
|
75
|
+
* which `can(ctx, …)` reads: the resolvers hand on the context Yoga gave them.
|
|
76
|
+
*/
|
|
77
|
+
export interface ApiKeysAuthorize {
|
|
78
|
+
create(subject: ApiKeyCreateSubject, ctx: Context): boolean | Promise<boolean>;
|
|
79
|
+
list(subject: ApiKeyListSubject, ctx: Context): boolean | Promise<boolean>;
|
|
80
|
+
revoke(subject: ApiKeyRevokeSubject, ctx: Context): boolean | Promise<boolean>;
|
|
81
|
+
}
|
|
82
|
+
export interface ApiKeysResolversOptions<A extends ApiKeysAuth = ApiKeysAuth> {
|
|
83
|
+
/** What `janus()` answered; its instance needs `apiKeys`. */
|
|
84
|
+
readonly auth: A;
|
|
85
|
+
/** The lifetimes `createApiKey` offers, in days, and its default. */
|
|
86
|
+
readonly lifetimes: ApiKeyLifetimes;
|
|
87
|
+
/** Who may create, list and revoke. Required: the core authorises nobody. */
|
|
88
|
+
readonly authorize: ApiKeysAuthorize;
|
|
89
|
+
/**
|
|
90
|
+
* The object a call is about, for an application that binds each key to
|
|
91
|
+
* one (a workspace, an account): `asked` is the field's `boundTo`
|
|
92
|
+
* argument, or `null` when absent, and the context may name it instead
|
|
93
|
+
* (a header, the route). Answer `null` for no object: an `asked` id then
|
|
94
|
+
* answers `NOT_FOUND`, and without one the call is about unbound keys.
|
|
95
|
+
* Absent, keys are never bound and a `boundTo` answers `NOT_FOUND`. A
|
|
96
|
+
* thrown `GraphQLError` is answered as it is.
|
|
97
|
+
*/
|
|
98
|
+
bound?(asked: string | null, ctx: Context): ApiKeyBound | null | Promise<ApiKeyBound | null>;
|
|
99
|
+
}
|
|
100
|
+
type Resolver<Args, Out> = (parent: unknown, args: Args, ctx: Context) => Promise<Out>;
|
|
101
|
+
/** A key as the schema's fields read it, timestamps as ISO-8601 strings. */
|
|
102
|
+
export interface ApiKeyOut {
|
|
103
|
+
readonly id: string;
|
|
104
|
+
readonly userId: string;
|
|
105
|
+
readonly name: string;
|
|
106
|
+
readonly prefix: string;
|
|
107
|
+
readonly scopes: readonly string[] | null;
|
|
108
|
+
readonly bound: ApiKeyBound | null;
|
|
109
|
+
readonly status: 'ACTIVE' | 'REVOKED' | 'EXPIRED';
|
|
110
|
+
readonly createdAt: string;
|
|
111
|
+
readonly expiresAt: string;
|
|
112
|
+
readonly lastUsedAt: string | null;
|
|
113
|
+
readonly revokedAt: string | null;
|
|
114
|
+
}
|
|
115
|
+
export interface ApiKeyPageOut {
|
|
116
|
+
readonly items: readonly ApiKeyOut[];
|
|
117
|
+
readonly nextCursor: string | null;
|
|
118
|
+
}
|
|
119
|
+
export interface CreatedApiKeyOut {
|
|
120
|
+
readonly apiKey: ApiKeyOut;
|
|
121
|
+
readonly secret: string;
|
|
122
|
+
}
|
|
123
|
+
type PageArgs = {
|
|
124
|
+
readonly boundTo?: string | null;
|
|
125
|
+
readonly limit?: number | null;
|
|
126
|
+
readonly after?: string | null;
|
|
127
|
+
};
|
|
128
|
+
/** The resolver map, keyed as `createSchema` expects. */
|
|
129
|
+
export interface ApiKeysResolvers {
|
|
130
|
+
readonly Query: {
|
|
131
|
+
readonly apiKeys: Resolver<PageArgs, ApiKeyPageOut>;
|
|
132
|
+
readonly boundApiKeys: Resolver<PageArgs, ApiKeyPageOut>;
|
|
133
|
+
readonly apiKeyLifetimes: Resolver<Record<never, never>, ApiKeyLifetimes>;
|
|
134
|
+
};
|
|
135
|
+
readonly Mutation: {
|
|
136
|
+
readonly createApiKey: Resolver<{
|
|
137
|
+
readonly name: string;
|
|
138
|
+
readonly lifetimeDays?: number | null;
|
|
139
|
+
readonly scopes?: readonly string[] | null;
|
|
140
|
+
readonly boundTo?: string | null;
|
|
141
|
+
}, CreatedApiKeyOut>;
|
|
142
|
+
readonly revokeApiKey: Resolver<{
|
|
143
|
+
readonly id: string;
|
|
144
|
+
readonly boundTo?: string | null;
|
|
145
|
+
}, ApiKeyOut>;
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
export {};
|
|
149
|
+
//# sourceMappingUR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AC;IACjC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B,CAAC;AAEF,yDAAyD;AACzD,MAAM,WAAW,gBAAgB;IAEhC,QAAQ,CAAC,KAAK,EAAE;QACf,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;QACpD,QAAQ,CAAC,YAAY,EAAE,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;QACzD,QAAQ,CAAC,eAAe,EAAE,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,eAAe,CAAC,CAAC;KAC1E,CAAC;IAEF,QAAQ,CAAC,QAAQ,EAAE;QAClB,QAAQ,CAAC,YAAY,EAAE,QAAQ,CAC9B;YACC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;YACtB,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;YACtC,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAAC;YAC3C,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;SACjC,EACD,gBAAgB,CAChB,CAAC;QACF,QAAQ,CAAC,YAAY,EAAE,QAAQ,CAC9B;YAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;YAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;SAAE,EACzD,SAAS,CACT,CAAC;KACF,CAAC;CACF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The avatar surface, opt-in: `JanusAvatar` for a field of your own types,
|
|
3
|
+
* `toJanusAvatar(user)` for the parent that field returns, and
|
|
4
|
+
* `avatarResolvers({ url })` for the type's fields. Janus keeps only the
|
|
5
|
+
* avatar's id; the bytes, and the route that serves them, are the
|
|
6
|
+
* application's.
|
|
7
|
+
*/
|
|
8
|
+
import type { UserBase } from '@softistx/janus';
|
|
9
|
+
/** What `toJanusAvatar()` reads: the part of a user this needs, as `@softistx/janus` types it. */
|
|
10
|
+
export type AvatarOwner = Pick<UserBase, 'id' | 'avatar'>;
|
|
11
|
+
/** The parent object of a `JanusAvatar` field: the owner's id, and the avatar. */
|
|
12
|
+
export interface AvatarParent {
|
|
13
|
+
readonly userId: string;
|
|
14
|
+
readonly id: string;
|
|
15
|
+
readonly updatedAt: Date;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The parent for an `avatar: JanusAvatar` field of your own type — `null`
|
|
19
|
+
* when the user has none.
|
|
20
|
+
*
|
|
21
|
+
* ```ts
|
|
22
|
+
* Viewer: { avatar: (user) => toJanusAvatar(user) }
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* **It checks nothing about who asks**: guard the field (`@permission`, or
|
|
26
|
+
* `can()` in the resolver) before it answers.
|
|
27
|
+
*/
|
|
28
|
+
export declare function toJanusAvatar(user: AvatarOwner): AvatarParent | null;
|
|
29
|
+
export type { AvatarResolvers, AvatarResolversOptions, } from './resolvers';
|
|
30
|
+
export { avatarResolvers } from './resolvers';
|
|
31
|
+
export { janusAvatarTypeDefs } from './sdl';
|
|
32
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/avatar/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEhD,kGAAkG;AAClG,MAAM,MAAM,WAAW,GAAG,IAAI,CAAC,QAAQ,EAAE,IAAI,GAAG,QAAQ,CAAC,CAAC;AAE1D,kFAAkF;AAClF,MAAM,WAAW,YAAY;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC;CACzB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,WAAW,GAAG,YAAY,GAAG,IAAI,CAIpE;AAED,YAAY,EACX,eAAe,EACf,sBAAsB,GACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,OAAO,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The resolvers of `JanusAvatar`, keyed as `createSchema` expects: `updatedAt`
|
|
3
|
+
* as an ISO-8601 string, and `url(size:)` from the application's own route.
|
|
4
|
+
*/
|
|
5
|
+
import type { AvatarParent } from './index';
|
|
6
|
+
/** What `avatarResolvers()` takes. */
|
|
7
|
+
export interface AvatarResolversOptions {
|
|
8
|
+
/**
|
|
9
|
+
* The URL of your own route that streams the image of `avatar.userId` at
|
|
10
|
+
* `size` — which checks the session and access first. Put the avatar's id
|
|
11
|
+
* in it (`?v=${encodeURIComponent(avatar.id)}`; ids are the application's
|
|
12
|
+
* own, so encode them), so a new upload is a new URL for the browser's
|
|
13
|
+
* cache. `avatar` is the parent `toJanusAvatar()` made — at least `userId` and `id`
|
|
14
|
+
* are what a route needs. `size` is already a positive integer.
|
|
15
|
+
*/
|
|
16
|
+
readonly url: (avatar: AvatarParent, size: number) => string;
|
|
17
|
+
}
|
|
18
|
+
/** The resolver map for `JanusAvatar`, keyed as `createSchema` expects. */
|
|
19
|
+
export interface AvatarResolvers {
|
|
20
|
+
readonly JanusAvatar: {
|
|
21
|
+
readonly updatedAt: (avatar: AvatarParent) => string;
|
|
22
|
+
readonly url: (avatar: AvatarParent, args: {
|
|
23
|
+
readonly size: number;
|
|
24
|
+
}) => string;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The resolvers of `JanusAvatar`: `updatedAt` as an ISO-8601 string, and
|
|
29
|
+
* `url(size:)` from your `url` function. A `size` that is not a positive
|
|
30
|
+
* integer is refused `BAD_USER_INPUT`, 400, before `url` is called; which
|
|
31
|
+
* sizes exist is your route's to decide — it answers 404 for the others.
|
|
32
|
+
*
|
|
33
|
+
* ```ts
|
|
34
|
+
* const resolvers = {
|
|
35
|
+
* ...avatarResolvers({ url: ({ userId, id }, size) => `/avatars/${userId}/${size}?v=${encodeURIComponent(id)}` }),
|
|
36
|
+
* Viewer: { avatar: (user) => toJanusAvatar(user) },
|
|
37
|
+
* };
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare function avatarResolvers(options: AvatarResolversOptions): AvatarResolvers;
|
|
41
|
+
//# sourceMappingURL=resolvers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolvers.d.ts","sourceRoot":"","sources":["../../src/avatar/resolvers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,sCAAsC;AACtC,MAAM,WAAW,sBAAsB;IACtC;;;;;;;OAOG;IACH,QAAQ,CAAC,GAAG,EAAE,CAAC,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;CAC7D;AAED,2EAA2E;AAC3E,MAAM,WAAW,eAAe;IAE/B,QAAQ,CAAC,WAAW,EAAE;QACrB,QAAQ,CAAC,SAAS,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,MAAM,CAAC;QACrD,QAAQ,CAAC,GAAG,EAAE,CACb,MAAM,EAAE,YAAY,EACpB,IAAI,EAAE;YAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;SAAE,KAC3B,MAAM,CAAC;KACZ,CAAC;CACF;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAC9B,OAAO,EAAE,sBAAsB,GAC7B,eAAe,CAgBjB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The opt-in avatar type as SDL: put it beside your own type definitions when
|
|
3
|
+
* accounts have avatars. The same text ships as
|
|
4
|
+
* `graphql/janus-avatar.graphqls` — `sdl.spec.ts` holds that the two are
|
|
5
|
+
* identical.
|
|
6
|
+
*
|
|
7
|
+
* `updatedAt` is an ISO-8601 `String` rather than a `DateTime`: the package
|
|
8
|
+
* defines no scalar, so it cannot collide with the one your schema already
|
|
9
|
+
* declares, or force you to declare one.
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* createSchema({ typeDefs: [janusTypeDefs, janusAvatarTypeDefs, typeDefs], resolvers });
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare const janusAvatarTypeDefs: string;
|
|
16
|
+
//# sourceMappingURL=sdl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdl.d.ts","sourceRoot":"","sources":["../../src/avatar/sdl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,mBAAmB,EAAE,MAmBjC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A bad argument, and the page `limit` every list field checks the same way.
|
|
3
|
+
* Shared by the invitation and API key resolvers.
|
|
4
|
+
*/
|
|
5
|
+
import { GraphQLError } from 'graphql';
|
|
6
|
+
/**
|
|
7
|
+
* `BAD_USER_INPUT` 400 naming the argument in `extensions.field`. Not
|
|
8
|
+
* `denial()`, which speaks of access: this is a bad argument.
|
|
9
|
+
*/
|
|
10
|
+
export declare function badInput(message: string, field: string): GraphQLError;
|
|
11
|
+
/** The `limit`: absent, or a positive integer (the core bounds it at 100). */
|
|
12
|
+
export declare function limitOf(limit: number | null | undefined): {
|
|
13
|
+
limit?: never;
|
|
14
|
+
} | {
|
|
15
|
+
limit: number;
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=bad-input.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bad-input.d.ts","sourceRoot":"","sources":["../src/bad-input.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,YAAY,CAIrE;AAED,8EAA8E;AAC9E,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS;;;;EAMvD"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `janusConnection()`: authenticated subscriptions over graphql-ws.
|
|
3
|
+
*/
|
|
4
|
+
import type { Auth, UserOfAuth } from '../types';
|
|
5
|
+
import type { JanusConnection, JanusConnectionOptions } from './types';
|
|
6
|
+
/**
|
|
7
|
+
* The pieces of graphql-ws's `useServer()` that authenticate a WebSocket
|
|
8
|
+
* connection, for Yoga's recommended setup:
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* const connection = janusConnection({ auth });
|
|
12
|
+
* useServer({
|
|
13
|
+
* onConnect: connection.onConnect,
|
|
14
|
+
* execute: (args) => args.rootValue.execute(args),
|
|
15
|
+
* subscribe: (args) => args.rootValue.subscribe(args),
|
|
16
|
+
* onSubscribe: async (ctx, _id, params) => { … yoga.getEnveloped({ ...ctx, … }) … },
|
|
17
|
+
* }, wsServer);
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* `onConnect` reads the connection's credential — `connectionParams`'
|
|
21
|
+
* `authorization`, else the upgrade request's headers and cookie — and
|
|
22
|
+
* refuses it unless it authenticates, as a user of `type` when it is given.
|
|
23
|
+
* Each operation on the connection then gets a `ctx.janus` of its own from
|
|
24
|
+
* `useJanus()`, authenticated again from that credential when a field asks:
|
|
25
|
+
* `@authenticated`, `@fresh` and `@permission` hold as over HTTP, and a
|
|
26
|
+
* session revoked since the connection opened is refused at the next
|
|
27
|
+
* subscribe.
|
|
28
|
+
*
|
|
29
|
+
* A server without Yoga passes `context` too, and applies the directives
|
|
30
|
+
* with `applyJanusDirectives()`.
|
|
31
|
+
*/
|
|
32
|
+
export declare function janusConnection<A extends Auth<{
|
|
33
|
+
readonly type: string;
|
|
34
|
+
readonly id: string;
|
|
35
|
+
}>, P extends object | undefined = undefined, const T extends UserOfAuth<A>['type'] = UserOfAuth<A>['type']>(options: JanusConnectionOptions<A, P, T>): JanusConnection<A, P, T>;
|
|
36
|
+
//# sourceMappingURL=connection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/connection/connection.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,EAAE,IAAI,EAAgB,UAAU,EAAE,MAAM,UAAU,CAAC;AAE/D,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAEvE;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,eAAe,CAC9B,CAAC,SAAS,IAAI,CAAC;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC,EAC9D,CAAC,SAAS,MAAM,GAAG,SAAS,GAAG,SAAS,EACxC,KAAK,CAAC,CAAC,SAAS,UAAU,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,EAC5D,OAAO,EAAE,sBAAsB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,eAAe,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CA+CpE"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The credential a graphql-ws connection presents, and the connections
|
|
3
|
+
* `janusConnection().onConnect` accepted: what each operation on one is
|
|
4
|
+
* authenticated from.
|
|
5
|
+
*/
|
|
6
|
+
import type { RequestLike } from '@softistx/janus';
|
|
7
|
+
import type { ConnectionContext } from './types';
|
|
8
|
+
/** Where the upgrade request is, when the transport does not say `extra.request`. */
|
|
9
|
+
export type Upgrade = (ctx: ConnectionContext) => RequestLike | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* The connection's credential, as `auth.authenticate` reads one:
|
|
12
|
+
*
|
|
13
|
+
* 1. `connectionParams.authorization`, when it is a `Bearer` token — a
|
|
14
|
+
* non-browser client's `'Bearer <token>'`;
|
|
15
|
+
* 2. otherwise the upgrade request itself, read as any request is —
|
|
16
|
+
* `Authorization`, then `X-Session-Token`, then the session cookie a
|
|
17
|
+
* browser sends with it.
|
|
18
|
+
*
|
|
19
|
+
* **The first present wins, not the first valid one**, as in `@softistx/janus`:
|
|
20
|
+
* a lapsed token in `connectionParams` beside a live cookie is refused. An
|
|
21
|
+
* `authorization` of another scheme (`Basic`) is not a session credential,
|
|
22
|
+
* as in `@softistx/janus`, and does not count. `null` when there is nothing to
|
|
23
|
+
* read, or an `authorization` that is not a string — refused, as a
|
|
24
|
+
* client's mistake.
|
|
25
|
+
*/
|
|
26
|
+
export declare function credentialOf(ctx: ConnectionContext, upgrade: Upgrade | undefined): RequestLike | null;
|
|
27
|
+
/** Remembers `credential` as the one `ctx`'s connection presented. */
|
|
28
|
+
export declare function accept(ctx: ConnectionContext, credential: RequestLike): void;
|
|
29
|
+
/**
|
|
30
|
+
* The credential of the connection a context was built for, or `undefined`
|
|
31
|
+
* for one no `onConnect` accepted — and for every HTTP request.
|
|
32
|
+
*/
|
|
33
|
+
export declare function acceptedOf(context: unknown): RequestLike | undefined;
|
|
34
|
+
//# sourceMappingURL=credential.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credential.d.ts","sourceRoot":"","sources":["../../src/connection/credential.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEjD,qFAAqF;AACrF,MAAM,MAAM,OAAO,GAAG,CAAC,GAAG,EAAE,iBAAiB,KAAK,WAAW,GAAG,SAAS,CAAC;AAK1E;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAC3B,GAAG,EAAE,iBAAiB,EACtB,OAAO,EAAE,OAAO,GAAG,SAAS,GAC1B,WAAW,GAAG,IAAI,CAcpB;AAWD,sEAAsE;AACtE,wBAAgB,MAAM,CAAC,GAAG,EAAE,iBAAiB,EAAE,UAAU,EAAE,WAAW,QAQrE;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,WAAW,GAAG,SAAS,CAIpE"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The public types of `janusConnection()`: what it takes, and the pieces
|
|
3
|
+
* it answers for graphql-ws's `useServer()`. Typed by their shape, so the
|
|
4
|
+
* package imports nothing from graphql-ws. Nothing here runs.
|
|
5
|
+
*/
|
|
6
|
+
import type { Clock, RequestLike } from '@softistx/janus';
|
|
7
|
+
import type { AuthSource, JanusContext, UserOfAuth } from '../types';
|
|
8
|
+
/**
|
|
9
|
+
* The part of graphql-ws's `Context` read here: the `connectionParams` the
|
|
10
|
+
* client sent with `connection_init`, and the transport's `extra` —
|
|
11
|
+
* `{ socket, request }` for `graphql-ws/use/ws`.
|
|
12
|
+
*/
|
|
13
|
+
export interface ConnectionContext {
|
|
14
|
+
readonly connectionParams?: Readonly<Record<string, unknown>> | undefined;
|
|
15
|
+
readonly extra: unknown;
|
|
16
|
+
}
|
|
17
|
+
/** What `janusConnection()` takes. */
|
|
18
|
+
export interface JanusConnectionOptions<A, P, T extends string> {
|
|
19
|
+
/**
|
|
20
|
+
* What `janus()` answered — or a function of the connection's context
|
|
21
|
+
* (`extra`, `connectionParams`) answering the instance that serves it.
|
|
22
|
+
* Called for `onConnect` and again for each operation's `context`.
|
|
23
|
+
*/
|
|
24
|
+
readonly auth: AuthSource<A, ConnectionContext>;
|
|
25
|
+
/**
|
|
26
|
+
* What `permissions()` answered: `ctx.janus.access` in the context
|
|
27
|
+
* `context()` builds. `useJanus()`'s own when Yoga builds it.
|
|
28
|
+
*/
|
|
29
|
+
readonly access?: P;
|
|
30
|
+
/** Only a user of this type may connect; any other is refused. */
|
|
31
|
+
readonly type?: T;
|
|
32
|
+
/** The clock `@fresh` reads in the context `context()` builds. */
|
|
33
|
+
readonly clock?: Clock;
|
|
34
|
+
/**
|
|
35
|
+
* The upgrade request of a connection, for a transport whose `extra`
|
|
36
|
+
* does not carry it as `request` — Bun's is `{ socket }`:
|
|
37
|
+
* `upgrade: (ctx) => ctx.extra.socket.data.request`, with the request
|
|
38
|
+
* passed to `server.upgrade(req, { data: { request: req } })`.
|
|
39
|
+
*
|
|
40
|
+
* A method, so `ctx` may be annotated with the transport's own `extra`.
|
|
41
|
+
*/
|
|
42
|
+
upgrade?(ctx: ConnectionContext): RequestLike | undefined;
|
|
43
|
+
}
|
|
44
|
+
/** What `janusConnection()` answers: the pieces of graphql-ws's `useServer()`. */
|
|
45
|
+
export interface JanusConnection<A, P = undefined, T extends UserOfAuth<A>['type'] = UserOfAuth<A>['type']> {
|
|
46
|
+
/**
|
|
47
|
+
* `useServer({ onConnect })`: accepts a connection whose credential
|
|
48
|
+
* authenticates, and answers `false` for any other — graphql-ws closes
|
|
49
|
+
* it `4403: Forbidden`. An outage rejects, never `false`: the transport
|
|
50
|
+
* closes it `4500`, and the client does not retry it as a refusal.
|
|
51
|
+
*/
|
|
52
|
+
readonly onConnect: (ctx: ConnectionContext) => Promise<boolean>;
|
|
53
|
+
/**
|
|
54
|
+
* `useServer({ context })`, for a server without Yoga: `ctx.janus` for
|
|
55
|
+
* one operation, authenticated from the connection's credential. Yoga's
|
|
56
|
+
* recipe builds the context itself, and `useJanus()` finds the
|
|
57
|
+
* connection there: leave this out.
|
|
58
|
+
*/
|
|
59
|
+
readonly context: (ctx: ConnectionContext) => JanusContext<A, P, T>;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=types.d.ts.map
|