@adonisjs/ally 5.0.0-0 → 5.0.0-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/build/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import './src/bindings/types.js';
2
2
  export { HttpClient as ApiRequest } from '@poppinss/oauth-client';
3
- export * as errors from './src/exceptions.js';
3
+ export * as errors from './src/errors.js';
4
4
  export { AllyManager } from './src/ally_manager.js';
5
5
  export { defineConfig } from './src/define_config.js';
6
6
  export { RedirectRequest } from './src/redirect_request.js';
package/build/index.js CHANGED
@@ -8,7 +8,7 @@
8
8
  */
9
9
  import './src/bindings/types.js';
10
10
  export { HttpClient as ApiRequest } from '@poppinss/oauth-client';
11
- export * as errors from './src/exceptions.js';
11
+ export * as errors from './src/errors.js';
12
12
  export { AllyManager } from './src/ally_manager.js';
13
13
  export { defineConfig } from './src/define_config.js';
14
14
  export { RedirectRequest } from './src/redirect_request.js';
@@ -1,4 +1,4 @@
1
- import { ApplicationService } from '@adonisjs/core/types';
1
+ import type { ApplicationService } from '@adonisjs/core/types';
2
2
  /**
3
3
  * AllyProvider extends the HTTP context with the "ally" property
4
4
  */
@@ -6,6 +6,7 @@
6
6
  * For the full copyright and license information, please view the LICENSE
7
7
  * file that was distributed with this source code.
8
8
  */
9
+ import driversList from '../src/drivers_collection.js';
9
10
  import { extendHttpContext } from '../src/bindings/http_context.js';
10
11
  /**
11
12
  * AllyProvider extends the HTTP context with the "ally" property
@@ -16,6 +17,8 @@ export default class AllyProvider {
16
17
  this.app = app;
17
18
  }
18
19
  async boot() {
19
- extendHttpContext(this.app.config.get('ally'));
20
+ const config = this.app.config.get('ally');
21
+ extendHttpContext(config.services);
22
+ await driversList.registerBundledDrivers(config.driversInUse);
20
23
  }
21
24
  }
@@ -8,7 +8,7 @@
8
8
  */
9
9
  import { Exception } from '@poppinss/utils';
10
10
  import { Oauth1Client } from '@poppinss/oauth-client';
11
- import * as errors from '../exceptions.js';
11
+ import * as errors from '../errors.js';
12
12
  import { RedirectRequest } from '../redirect_request.js';
13
13
  /**
14
14
  * Abstract implementation for an Oauth1 driver
@@ -8,7 +8,7 @@
8
8
  */
9
9
  import { Exception } from '@poppinss/utils';
10
10
  import { Oauth2Client } from '@poppinss/oauth-client';
11
- import * as errors from '../exceptions.js';
11
+ import * as errors from '../errors.js';
12
12
  import { RedirectRequest } from '../redirect_request.js';
13
13
  /**
14
14
  * Abstract implementation for an Oauth2 driver
@@ -1,6 +1,6 @@
1
1
  import './types.js';
2
- import { AllyManagerDriverFactory, SocialProviders } from '../types.js';
2
+ import { AllyManagerDriverFactory } from '../types.js';
3
3
  /**
4
4
  * Extends HttpContext class with the ally getter
5
5
  */
6
- export declare function extendHttpContext(config: SocialProviders extends Record<string, AllyManagerDriverFactory> ? SocialProviders : never): void;
6
+ export declare function extendHttpContext(config: Record<string, AllyManagerDriverFactory>): void;
@@ -0,0 +1,3 @@
1
+ /// <reference types="@types/node" resolution-mode="require"/>
2
+ declare const _default: import("util").DebugLogger;
3
+ export default _default;
@@ -0,0 +1,10 @@
1
+ /*
2
+ * @adonisjs/ally
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+ import { debuglog } from 'node:util';
10
+ export default debuglog('adonisjs:ally');
@@ -8,5 +8,8 @@ export declare function defineConfig<KnownSocialProviders extends Record<string,
8
8
  driver: K;
9
9
  } & Parameters<AllyDriversList[K]>[0];
10
10
  }[keyof AllyDriversList]>>(config: KnownSocialProviders): {
11
- [K in keyof KnownSocialProviders]: (ctx: HttpContext) => ReturnType<AllyDriversList[KnownSocialProviders[K]['driver']]>;
11
+ services: {
12
+ [K in keyof KnownSocialProviders]: (ctx: HttpContext) => ReturnType<AllyDriversList[KnownSocialProviders[K]['driver']]>;
13
+ };
14
+ driversInUse: Set<keyof AllyDriversList>;
12
15
  };
@@ -12,15 +12,20 @@ import allyDriversCollection from './drivers_collection.js';
12
12
  */
13
13
  export function defineConfig(config) {
14
14
  /**
15
- * Converting user defined config to an object of providers
15
+ * Converting user defined config to an object of services
16
16
  * that can be injected into the AllyManager class
17
17
  */
18
- const managerHashers = Object.keys(config).reduce((result, provider) => {
18
+ const driversInUse = new Set();
19
+ const services = Object.keys(config).reduce((result, provider) => {
19
20
  const providerConfig = config[provider];
21
+ driversInUse.add(providerConfig.driver);
20
22
  result[provider] = (ctx) => {
21
23
  return allyDriversCollection.create(providerConfig.driver, providerConfig, ctx);
22
24
  };
23
25
  return result;
24
26
  }, {});
25
- return managerHashers;
27
+ return {
28
+ services,
29
+ driversInUse,
30
+ };
26
31
  }
@@ -1,6 +1,10 @@
1
1
  import type { HttpContext } from '@adonisjs/core/http';
2
2
  import type { AllyDriversList } from './types.js';
3
+ /**
4
+ * A global collection of ally drivers.
5
+ */
3
6
  declare class AllyDriversCollection {
7
+ registerBundledDrivers(drivers: Set<keyof AllyDriversList>): Promise<void>;
4
8
  /**
5
9
  * List of registered drivers
6
10
  */
@@ -7,31 +7,52 @@
7
7
  * file that was distributed with this source code.
8
8
  */
9
9
  import { RuntimeException } from '@poppinss/utils';
10
- import { GithubDriver } from './drivers/github.js';
11
- import { GoogleDriver } from './drivers/google.js';
12
- import { SpotifyDriver } from './drivers/spotify.js';
13
- import { TwitterDriver } from './drivers/twitter.js';
14
- import { DiscordDriver } from './drivers/discord.js';
15
- import { FacebookDriver } from './drivers/facebook.js';
16
- import { LinkedInDriver } from './drivers/linked_in.js';
10
+ import debug from './debug.js';
11
+ /**
12
+ * A global collection of ally drivers.
13
+ */
17
14
  class AllyDriversCollection {
15
+ async registerBundledDrivers(drivers) {
16
+ debug('drivers in use %O', drivers);
17
+ if (drivers.has('discord') && !this.list['discord']) {
18
+ const { DiscordDriver } = await import('../src/drivers/discord.js');
19
+ this.extend('discord', (config, ctx) => new DiscordDriver(ctx, config));
20
+ }
21
+ if (drivers.has('facebook') && !this.list['facebook']) {
22
+ const { FacebookDriver } = await import('../src/drivers/facebook.js');
23
+ this.extend('facebook', (config, ctx) => new FacebookDriver(ctx, config));
24
+ }
25
+ if (drivers.has('github') && !this.list['github']) {
26
+ const { GithubDriver } = await import('../src/drivers/github.js');
27
+ this.extend('github', (config, ctx) => new GithubDriver(ctx, config));
28
+ }
29
+ if (drivers.has('google') && !this.list['google']) {
30
+ const { GoogleDriver } = await import('../src/drivers/google.js');
31
+ this.extend('google', (config, ctx) => new GoogleDriver(ctx, config));
32
+ }
33
+ if (drivers.has('linkedin') && !this.list['linkedin']) {
34
+ const { LinkedInDriver } = await import('../src/drivers/linked_in.js');
35
+ this.extend('linkedin', (config, ctx) => new LinkedInDriver(ctx, config));
36
+ }
37
+ if (drivers.has('spotify') && !this.list['spotify']) {
38
+ const { SpotifyDriver } = await import('../src/drivers/spotify.js');
39
+ this.extend('spotify', (config, ctx) => new SpotifyDriver(ctx, config));
40
+ }
41
+ if (drivers.has('twitter') && !this.list['twitter']) {
42
+ const { TwitterDriver } = await import('../src/drivers/twitter.js');
43
+ this.extend('twitter', (config, ctx) => new TwitterDriver(ctx, config));
44
+ }
45
+ }
18
46
  /**
19
47
  * List of registered drivers
20
48
  */
21
- list = {
22
- discord: (config, ctx) => new DiscordDriver(ctx, config),
23
- facebook: (config, ctx) => new FacebookDriver(ctx, config),
24
- github: (config, ctx) => new GithubDriver(ctx, config),
25
- google: (config, ctx) => new GoogleDriver(ctx, config),
26
- linkedin: (config, ctx) => new LinkedInDriver(ctx, config),
27
- spotify: (config, ctx) => new SpotifyDriver(ctx, config),
28
- twitter: (config, ctx) => new TwitterDriver(ctx, config),
29
- };
49
+ list = {};
30
50
  /**
31
51
  * Extend drivers collection and add a custom
32
52
  * driver to it.
33
53
  */
34
54
  extend(driverName, factoryCallback) {
55
+ debug('registering %s driver', driverName);
35
56
  this.list[driverName] = factoryCallback;
36
57
  return this;
37
58
  }
@@ -43,6 +64,7 @@ class AllyDriversCollection {
43
64
  if (!driverFactory) {
44
65
  throw new RuntimeException(`Unknown ally driver "${String(name)}". Make sure the driver is registered`);
45
66
  }
67
+ debug('creating instance of %s driver', name);
46
68
  return driverFactory(config, ctx);
47
69
  }
48
70
  }
@@ -380,4 +380,6 @@ export type AllyManagerDriverFactory = (ctx: HttpContext) => AllyDriverContract<
380
380
  */
381
381
  export interface SocialProviders {
382
382
  }
383
- export type InferSocialProviders<T extends Record<string, AllyManagerDriverFactory>> = T;
383
+ export type InferSocialProviders<T extends {
384
+ services: Record<string, AllyManagerDriverFactory>;
385
+ }> = T['services'];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adonisjs/ally",
3
- "version": "5.0.0-0",
3
+ "version": "5.0.0-1",
4
4
  "description": "Social authentication provider for AdonisJS",
5
5
  "type": "module",
6
6
  "main": "build/index.js",
@@ -47,23 +47,23 @@
47
47
  "author": "adonisjs,virk",
48
48
  "license": "MIT",
49
49
  "devDependencies": {
50
- "@adonisjs/core": "^6.1.5-8",
50
+ "@adonisjs/core": "^6.1.5-15",
51
51
  "@adonisjs/eslint-config": "^1.1.8",
52
52
  "@adonisjs/prettier-config": "^1.1.8",
53
53
  "@adonisjs/tsconfig": "^1.1.8",
54
- "@commitlint/cli": "^17.6.6",
55
- "@commitlint/config-conventional": "^17.6.6",
54
+ "@commitlint/cli": "^17.6.7",
55
+ "@commitlint/config-conventional": "^17.6.7",
56
56
  "@japa/assert": "^2.0.0-1",
57
57
  "@japa/expect-type": "^2.0.0-0",
58
58
  "@japa/file-system": "^2.0.0-1",
59
59
  "@japa/runner": "^3.0.0-6",
60
- "@swc/core": "^1.3.69",
61
- "@types/node": "^20.4.2",
62
- "c8": "^8.0.0",
60
+ "@swc/core": "^1.3.74",
61
+ "@types/node": "^20.4.6",
62
+ "c8": "^8.0.1",
63
63
  "copyfiles": "^2.4.1",
64
64
  "del-cli": "^5.0.0",
65
65
  "dotenv": "^16.3.1",
66
- "eslint": "^8.45.0",
66
+ "eslint": "^8.46.0",
67
67
  "github-label-sync": "^2.3.1",
68
68
  "husky": "^8.0.3",
69
69
  "nock": "^13.3.2",
@@ -76,6 +76,9 @@
76
76
  "@poppinss/oauth-client": "^5.1.0-3",
77
77
  "@poppinss/utils": "^6.5.0-3"
78
78
  },
79
+ "peerDependencies": {
80
+ "@adonisjs/core": "^6.1.5-15"
81
+ },
79
82
  "repository": {
80
83
  "type": "git",
81
84
  "url": "git+https://github.com/adonisjs/adonis-ally.git"
File without changes
File without changes