@wbce-d9/api 10.0.0 → 10.3.0

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.
@@ -1,9 +1,9 @@
1
1
  import { Router } from 'express';
2
2
  import Joi from 'joi';
3
3
  import ldap from 'ldapjs';
4
+ import { GET_SET_HEADER } from '../../constants.js';
4
5
  import getDatabase from '../../database/index.js';
5
6
  import emitter from '../../emitter.js';
6
- import env from '../../env.js';
7
7
  import { RecordNotUniqueException } from '../../exceptions/database/record-not-unique.js';
8
8
  import { InvalidConfigException, InvalidCredentialsException, InvalidPayloadException, InvalidProviderException, ServiceUnavailableException, UnexpectedResponseException, } from '../../exceptions/index.js';
9
9
  import logger from '../../logger.js';
@@ -12,7 +12,6 @@ import { AuthenticationService } from '../../services/authentication.js';
12
12
  import { UsersService } from '../../services/users.js';
13
13
  import asyncHandler from '../../utils/async-handler.js';
14
14
  import { getIPFromReq } from '../../utils/get-ip-from-req.js';
15
- import { getMilliseconds } from '../../utils/get-milliseconds.js';
16
15
  import { AuthDriver } from '../auth.js';
17
16
  // 0x2: ACCOUNTDISABLE
18
17
  // 0x10: LOCKOUT
@@ -315,13 +314,7 @@ export function createLDAPAuthRouter(provider) {
315
314
  payload['data']['refresh_token'] = refreshToken;
316
315
  }
317
316
  if (mode === 'cookie') {
318
- res.cookie(env['REFRESH_TOKEN_COOKIE_NAME'], refreshToken, {
319
- httpOnly: true,
320
- domain: env['REFRESH_TOKEN_COOKIE_DOMAIN'],
321
- maxAge: getMilliseconds(env['REFRESH_TOKEN_TTL']),
322
- secure: env['REFRESH_TOKEN_COOKIE_SECURE'] ?? false,
323
- sameSite: env['REFRESH_TOKEN_COOKIE_SAME_SITE'] || 'strict',
324
- });
317
+ res.setHeader('Set-Cookie', GET_SET_HEADER(refreshToken));
325
318
  }
326
319
  res.locals['payload'] = payload;
327
320
  return next();
@@ -2,7 +2,7 @@ import argon2 from 'argon2';
2
2
  import { Router } from 'express';
3
3
  import Joi from 'joi';
4
4
  import { performance } from 'perf_hooks';
5
- import { COOKIE_OPTIONS } from '../../constants.js';
5
+ import { GET_SET_HEADER } from '../../constants.js';
6
6
  import env from '../../env.js';
7
7
  import { InvalidCredentialsException, InvalidPayloadException } from '../../exceptions/index.js';
8
8
  import { respond } from '../../middleware/respond.js';
@@ -74,7 +74,7 @@ export function createLocalAuthRouter(provider) {
74
74
  payload['data']['refresh_token'] = refreshToken;
75
75
  }
76
76
  if (mode === 'cookie') {
77
- res.cookie(env['REFRESH_TOKEN_COOKIE_NAME'], refreshToken, COOKIE_OPTIONS);
77
+ res.setHeader('Set-Cookie', GET_SET_HEADER(refreshToken));
78
78
  }
79
79
  res.locals['payload'] = payload;
80
80
  return next();
@@ -4,6 +4,7 @@ import flatten from 'flat';
4
4
  import jwt from 'jsonwebtoken';
5
5
  import { generators, Issuer } from 'openid-client';
6
6
  import { getAuthProvider } from '../../auth.js';
7
+ import { GET_SET_HEADER } from '../../constants.js';
7
8
  import env from '../../env.js';
8
9
  import { InvalidConfigException, InvalidCredentialsException, InvalidTokenException } from '../../exceptions/index.js';
9
10
  import logger from '../../logger.js';
@@ -13,7 +14,6 @@ import { UsersService } from '../../services/users.js';
13
14
  import asyncHandler from '../../utils/async-handler.js';
14
15
  import { getConfigFromEnv } from '../../utils/get-config-from-env.js';
15
16
  import { getIPFromReq } from '../../utils/get-ip-from-req.js';
16
- import { getMilliseconds } from '../../utils/get-milliseconds.js';
17
17
  import { Url } from '../../utils/url.js';
18
18
  import { BaseOAuthDriver } from './baseoauth.js';
19
19
  export class OAuth2AuthDriver extends BaseOAuthDriver {
@@ -186,13 +186,7 @@ export function createOAuth2AuthRouter(providerName) {
186
186
  }
187
187
  const { accessToken, refreshToken, expires } = authResponse;
188
188
  if (redirect) {
189
- res.cookie(env['REFRESH_TOKEN_COOKIE_NAME'], refreshToken, {
190
- httpOnly: true,
191
- domain: env['REFRESH_TOKEN_COOKIE_DOMAIN'],
192
- maxAge: getMilliseconds(env['REFRESH_TOKEN_TTL']),
193
- secure: env['REFRESH_TOKEN_COOKIE_SECURE'] ?? false,
194
- sameSite: env['REFRESH_TOKEN_COOKIE_SAME_SITE'] || 'strict',
195
- });
189
+ res.setHeader('Set-Cookie', GET_SET_HEADER(refreshToken));
196
190
  return res.redirect(redirect);
197
191
  }
198
192
  res.locals['payload'] = {
@@ -4,6 +4,7 @@ import flatten from 'flat';
4
4
  import jwt from 'jsonwebtoken';
5
5
  import { generators, Issuer } from 'openid-client';
6
6
  import { getAuthProvider } from '../../auth.js';
7
+ import { GET_SET_HEADER } from '../../constants.js';
7
8
  import env from '../../env.js';
8
9
  import { InvalidConfigException, InvalidCredentialsException, InvalidTokenException } from '../../exceptions/index.js';
9
10
  import logger from '../../logger.js';
@@ -13,7 +14,6 @@ import { UsersService } from '../../services/users.js';
13
14
  import asyncHandler from '../../utils/async-handler.js';
14
15
  import { getConfigFromEnv } from '../../utils/get-config-from-env.js';
15
16
  import { getIPFromReq } from '../../utils/get-ip-from-req.js';
16
- import { getMilliseconds } from '../../utils/get-milliseconds.js';
17
17
  import { Url } from '../../utils/url.js';
18
18
  import { BaseOAuthDriver } from './baseoauth.js';
19
19
  export class OpenIDAuthDriver extends BaseOAuthDriver {
@@ -211,13 +211,7 @@ export function createOpenIDAuthRouter(providerName) {
211
211
  }
212
212
  const { accessToken, refreshToken, expires } = authResponse;
213
213
  if (redirect) {
214
- res.cookie(env['REFRESH_TOKEN_COOKIE_NAME'], refreshToken, {
215
- httpOnly: true,
216
- domain: env['REFRESH_TOKEN_COOKIE_DOMAIN'],
217
- maxAge: getMilliseconds(env['REFRESH_TOKEN_TTL']),
218
- secure: env['REFRESH_TOKEN_COOKIE_SECURE'] ?? false,
219
- sameSite: env['REFRESH_TOKEN_COOKIE_SAME_SITE'] || 'strict',
220
- });
214
+ res.setHeader('Set-Cookie', GET_SET_HEADER(refreshToken));
221
215
  return res.redirect(redirect);
222
216
  }
223
217
  res.locals['payload'] = {
@@ -3,7 +3,7 @@ import { BaseException } from '@wbce-d9/exceptions';
3
3
  import express, { Router } from 'express';
4
4
  import * as samlify from 'samlify';
5
5
  import { getAuthProvider } from '../../auth.js';
6
- import { COOKIE_OPTIONS } from '../../constants.js';
6
+ import { COOKIE_OPTIONS, GET_SET_HEADER } from '../../constants.js';
7
7
  import getDatabase from '../../database/index.js';
8
8
  import emitter from '../../emitter.js';
9
9
  import env from '../../env.js';
@@ -121,7 +121,7 @@ export function createSAMLAuthRouter(providerName) {
121
121
  },
122
122
  };
123
123
  if (relayState) {
124
- res.cookie(env['REFRESH_TOKEN_COOKIE_NAME'], refreshToken, COOKIE_OPTIONS);
124
+ res.setHeader('Set-Cookie', GET_SET_HEADER(refreshToken));
125
125
  return res.redirect(relayState);
126
126
  }
127
127
  return next();
@@ -9,6 +9,7 @@ export declare const COLUMN_TRANSFORMS: string[];
9
9
  export declare const GENERATE_SPECIAL: string[];
10
10
  export declare const UUID_REGEX = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
11
11
  export declare const COOKIE_OPTIONS: CookieOptions;
12
+ export declare const GET_SET_HEADER: (cookieValue: string) => string;
12
13
  export declare const OAS_REQUIRED_SCHEMAS: string[];
13
14
  /** Formats from which transformation is supported */
14
15
  export declare const SUPPORTED_IMAGE_TRANSFORM_FORMATS: string[];
package/dist/constants.js CHANGED
@@ -55,6 +55,12 @@ export const COOKIE_OPTIONS = {
55
55
  secure: env['REFRESH_TOKEN_COOKIE_SECURE'] ?? false,
56
56
  sameSite: env['REFRESH_TOKEN_COOKIE_SAME_SITE'] || 'strict',
57
57
  };
58
+ export const GET_SET_HEADER = (cookieValue) => {
59
+ const domainHeader = env['REFRESH_TOKEN_COOKIE_DOMAIN'] ? ` Domain=${env['REFRESH_TOKEN_COOKIE_DOMAIN']};` : '';
60
+ const partitionedHeader = env['REFRESH_TOKEN_COOKIE_PARTITIONED'] == true ? ' Partitioned;' : '';
61
+ const cookieHeaderValue = `${env['REFRESH_TOKEN_COOKIE_NAME']}=${cookieValue}; HttpOnly; Max-Age=${getMilliseconds(env['REFRESH_TOKEN_TTL'])}; Secure=${env['REFRESH_TOKEN_COOKIE_SECURE'] ?? false}; SameSite=${env['REFRESH_TOKEN_COOKIE_SAME_SITE'] || 'strict'}; Path=/;${domainHeader}${partitionedHeader}`;
62
+ return cookieHeaderValue;
63
+ };
58
64
  export const OAS_REQUIRED_SCHEMAS = ['Diff', 'Schema', 'Query', 'x-metadata'];
59
65
  /** Formats from which transformation is supported */
60
66
  export const SUPPORTED_IMAGE_TRANSFORM_FORMATS = ['image/jpeg', 'image/png', 'image/webp', 'image/tiff', 'image/avif'];
@@ -1,6 +1,6 @@
1
1
  import { Router } from 'express';
2
2
  import { createLDAPAuthRouter, createLocalAuthRouter, createOAuth2AuthRouter, createOpenIDAuthRouter, createSAMLAuthRouter, } from '../auth/drivers/index.js';
3
- import { COOKIE_OPTIONS, DEFAULT_AUTH_PROVIDER } from '../constants.js';
3
+ import { DEFAULT_AUTH_PROVIDER, GET_SET_HEADER } from '../constants.js';
4
4
  import env from '../env.js';
5
5
  import { InvalidPayloadException } from '../exceptions/index.js';
6
6
  import logger from '../logger.js';
@@ -68,7 +68,7 @@ router.post('/refresh', asyncHandler(async (req, res, next) => {
68
68
  payload['data']['refresh_token'] = refreshToken;
69
69
  }
70
70
  if (mode === 'cookie') {
71
- res.cookie(env['REFRESH_TOKEN_COOKIE_NAME'], refreshToken, COOKIE_OPTIONS);
71
+ res.setHeader('Set-Cookie', GET_SET_HEADER(refreshToken));
72
72
  }
73
73
  res.locals['payload'] = payload;
74
74
  return next();
@@ -1,7 +1,6 @@
1
1
  import express from 'express';
2
2
  import Joi from 'joi';
3
- import { COOKIE_OPTIONS, UUID_REGEX } from '../constants.js';
4
- import env from '../env.js';
3
+ import { GET_SET_HEADER, UUID_REGEX } from '../constants.js';
5
4
  import { ForbiddenException, InvalidPayloadException } from '../exceptions/index.js';
6
5
  import { respond } from '../middleware/respond.js';
7
6
  import useCollection from '../middleware/use-collection.js';
@@ -25,7 +24,7 @@ router.post('/auth', asyncHandler(async (req, res, next) => {
25
24
  throw new InvalidPayloadException(error.message);
26
25
  }
27
26
  const { accessToken, refreshToken, expires } = await service.login(req.body);
28
- res.cookie(env['REFRESH_TOKEN_COOKIE_NAME'], refreshToken, COOKIE_OPTIONS);
27
+ res.setHeader('Set-Cookie', GET_SET_HEADER(refreshToken));
29
28
  res.locals['payload'] = { data: { access_token: accessToken, expires } };
30
29
  return next();
31
30
  }), respond);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wbce-d9/api",
3
- "version": "10.0.0",
3
+ "version": "10.3.0",
4
4
  "description": "Directus is a real-time API and App dashboard for managing SQL database content",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -144,19 +144,19 @@
144
144
  "vm2": "^3.9.19",
145
145
  "wellknown": "0.5.0",
146
146
  "@wbce-d9/app": "9.29.0",
147
+ "@wbce-d9/constants": "9.26.3",
147
148
  "@wbce-d9/exceptions": "9.26.3",
149
+ "@wbce-d9/extensions-sdk": "9.26.5",
148
150
  "@wbce-d9/schema": "9.26.3",
151
+ "@wbce-d9/storage-driver-azure": "9.26.5",
149
152
  "@wbce-d9/specs": "9.26.3",
150
- "@wbce-d9/extensions-sdk": "9.26.5",
151
153
  "@wbce-d9/storage": "9.26.3",
152
- "@wbce-d9/constants": "9.26.3",
153
- "@wbce-d9/storage-driver-azure": "9.26.5",
154
- "@wbce-d9/storage-driver-gcs": "9.26.5",
155
- "@wbce-d9/storage-driver-local": "9.26.5",
156
154
  "@wbce-d9/storage-driver-cloudinary": "9.26.5",
155
+ "@wbce-d9/storage-driver-gcs": "9.26.5",
157
156
  "@wbce-d9/storage-driver-s3": "9.26.7",
158
157
  "@wbce-d9/update-check": "9.26.3",
159
- "@wbce-d9/utils": "9.28.0"
158
+ "@wbce-d9/utils": "9.28.0",
159
+ "@wbce-d9/storage-driver-local": "9.26.5"
160
160
  },
161
161
  "devDependencies": {
162
162
  "@ngneat/falso": "6.4.0",