Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/@envelop_auth0-2482-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@envelop/auth0": patch
---
dependencies updates:
- Added dependency [`@whatwg-node/promise-helpers@^1.2.4` ↗︎](https://www.npmjs.com/package/@whatwg-node/promise-helpers/v/1.2.4) (to `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/@envelop_auth0-2484-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@envelop/auth0": patch
---
dependencies updates:
- Added dependency [`@whatwg-node/promise-helpers@^1.2.4` ↗︎](https://www.npmjs.com/package/@whatwg-node/promise-helpers/v/1.2.4) (to `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/@envelop_core-2482-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@envelop/core": patch
---
dependencies updates:
- Updated dependency [`@whatwg-node/promise-helpers@^1.2.4` ↗︎](https://www.npmjs.com/package/@whatwg-node/promise-helpers/v/1.2.4) (from `^1.2.1`, in `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/@envelop_core-2484-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@envelop/core": patch
---
dependencies updates:
- Updated dependency [`@whatwg-node/promise-helpers@^1.2.4` ↗︎](https://www.npmjs.com/package/@whatwg-node/promise-helpers/v/1.2.4) (from `^1.2.1`, in `dependencies`)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@envelop/immediate-introspection": patch
---
dependencies updates:
- Removed dependency [`@sentry/node@^8.0.0` ↗︎](https://www.npmjs.com/package/@sentry/node/v/8.0.0) (from `peerDependencies`)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@envelop/operation-field-permissions": patch
---
dependencies updates:
- Added dependency [`@whatwg-node/promise-helpers@^1.2.4` ↗︎](https://www.npmjs.com/package/@whatwg-node/promise-helpers/v/1.2.4) (to `dependencies`)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@envelop/operation-field-permissions": patch
---
dependencies updates:
- Added dependency [`@whatwg-node/promise-helpers@^1.2.4` ↗︎](https://www.npmjs.com/package/@whatwg-node/promise-helpers/v/1.2.4) (to `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/@envelop_rate-limiter-2482-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@envelop/rate-limiter": patch
---
dependencies updates:
- Updated dependency [`@whatwg-node/promise-helpers@^1.2.4` ↗︎](https://www.npmjs.com/package/@whatwg-node/promise-helpers/v/1.2.4) (from `^1.0.0`, in `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/@envelop_rate-limiter-2484-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@envelop/rate-limiter": patch
---
dependencies updates:
- Updated dependency [`@whatwg-node/promise-helpers@^1.2.4` ↗︎](https://www.npmjs.com/package/@whatwg-node/promise-helpers/v/1.2.4) (from `^1.0.0`, in `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/@envelop_response-cache-2482-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@envelop/response-cache": patch
---
dependencies updates:
- Added dependency [`@whatwg-node/promise-helpers@^1.2.4` ↗︎](https://www.npmjs.com/package/@whatwg-node/promise-helpers/v/1.2.4) (to `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/@envelop_response-cache-2484-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@envelop/response-cache": patch
---
dependencies updates:
- Added dependency [`@whatwg-node/promise-helpers@^1.2.4` ↗︎](https://www.npmjs.com/package/@whatwg-node/promise-helpers/v/1.2.4) (to `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/@envelop_response-cache-redis-2482-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@envelop/response-cache-redis": patch
---
dependencies updates:
- Added dependency [`@whatwg-node/promise-helpers@^1.2.4` ↗︎](https://www.npmjs.com/package/@whatwg-node/promise-helpers/v/1.2.4) (to `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/@envelop_response-cache-redis-2484-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@envelop/response-cache-redis": patch
---
dependencies updates:
- Added dependency [`@whatwg-node/promise-helpers@^1.2.4` ↗︎](https://www.npmjs.com/package/@whatwg-node/promise-helpers/v/1.2.4) (to `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/@envelop_testing-2482-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@envelop/testing": patch
---
dependencies updates:
- Updated dependency [`@whatwg-node/promise-helpers@^1.2.4` ↗︎](https://www.npmjs.com/package/@whatwg-node/promise-helpers/v/1.2.4) (from `^1.2.2`, in `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/@envelop_testing-2484-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@envelop/testing": patch
---
dependencies updates:
- Updated dependency [`@whatwg-node/promise-helpers@^1.2.4` ↗︎](https://www.npmjs.com/package/@whatwg-node/promise-helpers/v/1.2.4) (from `^1.2.2`, in `dependencies`)
2 changes: 1 addition & 1 deletion examples/google-cloud-functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"dependencies": {
"@envelop/core": "workspace:^",
"@graphql-tools/schema": "10.0.21",
"firebase-admin": "13.1.0",
"firebase-admin": "13.2.0",
"firebase-functions": "6.3.2",
"graphql": "16.8.1",
"graphql-helix": "1.13.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"dependencies": {
"@envelop/instruments": "workspace:^",
"@envelop/types": "workspace:^",
"@whatwg-node/promise-helpers": "^1.2.1",
"@whatwg-node/promise-helpers": "^1.2.4",
"tslib": "^2.5.0"
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions packages/plugins/auth0/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@envelop/core": "workspace:^"
},
"dependencies": {
"@whatwg-node/promise-helpers": "^1.2.4",
"jsonwebtoken": "^9.0.0",
"jwks-rsa": "^3.0.1",
"tslib": "^2.5.0"
Expand Down
72 changes: 41 additions & 31 deletions packages/plugins/auth0/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import jwtPkg, { DecodeOptions, VerifyOptions } from 'jsonwebtoken';
import * as JwksRsa from 'jwks-rsa';
import { Plugin } from '@envelop/core';
import { handleMaybePromise } from '@whatwg-node/promise-helpers';

const { decode, verify } = jwtPkg;

Expand Down Expand Up @@ -89,49 +90,58 @@ export const useAuth0 = <TOptions extends Auth0PluginOptions>(
return null;
});

const verifyToken = async (token: string): Promise<any> => {
const verifyToken = (token: string) => {
const decodedToken =
(decode(token, { complete: true, ...options.jwtDecodeOptions }) as Record<
string,
{ kid?: string }
>) || {};

if (decodedToken && decodedToken.header && decodedToken.header.kid) {
const secret = await jkwsClient.getSigningKey(decodedToken.header.kid);
const signingKey = secret.getPublicKey();
const decoded = verify(token, signingKey, {
algorithms: ['RS256'],
audience: options.audience,
issuer: `https://${options.domain}/`,
...options.jwtVerifyOptions,
}) as { sub: string };

return decoded;
return handleMaybePromise(
() => jkwsClient.getSigningKey(decodedToken.header.kid),
secret => {
const signingKey = secret.getPublicKey();
const decoded = verify(token, signingKey, {
algorithms: ['RS256'],
audience: options.audience,
issuer: `https://${options.domain}/`,
...options.jwtVerifyOptions,
}) as { sub: string };

return decoded;
},
);
}
throw new Error(`Failed to decode authentication token!`);
};

return {
async onContextBuilding({ context, extendContext }) {
try {
const token = await extractFn(context);

if (token) {
const decodedPayload = await verifyToken(token);

extendContext({
[contextField]: decodedPayload,
} as BuildContext<TOptions>);
} else if (options.preventUnauthenticatedAccess) {
throw new UnauthenticatedError(`Unauthenticated!`);
}
} catch (e) {
if (options.onError) {
options.onError(e as Error);
} else {
throw e;
}
}
onContextBuilding({ context, extendContext }) {
return handleMaybePromise(
() => extractFn(context),
token => {
if (token) {
return handleMaybePromise(
() => verifyToken(token),
decodedPayload => {
extendContext({
[contextField]: decodedPayload,
} as BuildContext<TOptions>);
},
);
} else if (options.preventUnauthenticatedAccess) {
throw new UnauthenticatedError(`Unauthenticated!`);
}
},
e => {
if (options.onError) {
options.onError(e as Error);
} else {
throw e;
}
},
);
},
};
};
1 change: 0 additions & 1 deletion packages/plugins/immediate-introspection/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
"typings": "dist/typings/index.d.ts",
"peerDependencies": {
"@envelop/core": "workspace:^",
"@sentry/node": "^8.0.0",
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
},
"dependencies": {},
Expand Down
1 change: 1 addition & 0 deletions packages/plugins/operation-field-permissions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
},
"dependencies": {
"@envelop/extended-validation": "workspace:^",
"@whatwg-node/promise-helpers": "^1.2.4",
"tslib": "^2.5.0"
},
"devDependencies": {
Expand Down
44 changes: 23 additions & 21 deletions packages/plugins/operation-field-permissions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import {
isObjectType,
isUnionType,
} from 'graphql';
import { Plugin, useExtendContext } from '@envelop/core';
import { Plugin, PromiseOrValue, useExtendContext } from '@envelop/core';
import { ExtendedValidationRule, useExtendedValidation } from '@envelop/extended-validation';

type PromiseOrValue<T> = T | Promise<T>;
import { handleMaybePromise } from '@whatwg-node/promise-helpers';

const OPERATION_PERMISSIONS_SYMBOL = Symbol('OPERATION_PERMISSIONS_SYMBOL');

Expand Down Expand Up @@ -141,24 +140,27 @@ export const useOperationFieldPermissions = <TContext>(
);

addPlugin(
useExtendContext(async context => {
const permissions = await opts.getPermissions(context as TContext);

// Schema coordinates is a set of type-name field-name strings that
// describe the position of a field in the schema.
const schemaCoordinates = toSet(permissions);
const wildcardTypes = getWildcardTypes(schemaCoordinates);

const scopeContext: ScopeContext = {
schemaCoordinates,
wildcardTypes,
allowAll: schemaCoordinates.has('*'),
};

return {
[OPERATION_PERMISSIONS_SYMBOL]: scopeContext,
};
}),
useExtendContext(context =>
handleMaybePromise(
() => opts.getPermissions(context as TContext),
permissions => {
// Schema coordinates is a set of type-name field-name strings that
// describe the position of a field in the schema.
const schemaCoordinates = toSet(permissions);
const wildcardTypes = getWildcardTypes(schemaCoordinates);

const scopeContext: ScopeContext = {
schemaCoordinates,
wildcardTypes,
allowAll: schemaCoordinates.has('*'),
};

return {
[OPERATION_PERMISSIONS_SYMBOL]: scopeContext,
};
},
),
),
);
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ export class JsonFileStore implements PersistedOperationsStore {
this.storeData = new Map(Object.entries(data));
}

public async loadFromFile(path: string): Promise<void> {
const data = JSON.parse(await promises.readFile(path, 'utf-8'));
this.storeData = new Map(Object.entries(data));
public loadFromFile(path: string): Promise<void> {
return promises.readFile(path, 'utf-8').then(data => {
this.storeData = new Map(Object.entries(JSON.parse(data)));
});
}
}
2 changes: 1 addition & 1 deletion packages/plugins/rate-limiter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"dependencies": {
"@envelop/on-resolve": "workspace:^",
"@graphql-tools/utils": "^10.5.4",
"@whatwg-node/promise-helpers": "^1.0.0",
"@whatwg-node/promise-helpers": "^1.2.4",
"lodash.get": "^4.4.2",
"minimatch": "^10.0.1",
"ms": "^2.1.3",
Expand Down
Loading
Loading