@sweepbright/api-client 0.33.0 → 0.33.1-next
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,18 +1,20 @@
|
|
|
1
|
+
import { Cluster, Redis } from 'ioredis';
|
|
1
2
|
import { Env } from '../../types';
|
|
2
3
|
import { Logger, OAuthManager } from '../interfaces';
|
|
3
|
-
interface
|
|
4
|
+
interface CreateOAuthManagerOptionsBase {
|
|
4
5
|
env: Env;
|
|
5
6
|
apiVersion: string;
|
|
6
7
|
logger?: Logger;
|
|
7
|
-
storage: 'redis';
|
|
8
|
-
redisURL: string;
|
|
9
8
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
type RedisOptions = {
|
|
10
|
+
redisURL: string;
|
|
11
|
+
} | {
|
|
12
|
+
redis: Redis | Cluster;
|
|
13
|
+
};
|
|
14
|
+
type CreateOAuthManagerOptions = CreateOAuthManagerOptionsBase & ({
|
|
14
15
|
storage: 'memory';
|
|
15
|
-
}
|
|
16
|
-
|
|
16
|
+
} | ({
|
|
17
|
+
storage: 'redis';
|
|
18
|
+
} & RedisOptions));
|
|
17
19
|
export declare function createOAuthManager(opt: CreateOAuthManagerOptions): OAuthManager;
|
|
18
20
|
export {};
|
|
@@ -10,33 +10,36 @@ const SweepbrightOAuthManager_1 = require("../SweepbrightOAuthManager");
|
|
|
10
10
|
const TokensRepository_Memory_1 = require("../TokensRepository_Memory");
|
|
11
11
|
const TokensRepository_Redis_1 = require("../TokensRepository_Redis");
|
|
12
12
|
const TokensRepository_RedisWithMemoryFallback_1 = require("../TokensRepository_RedisWithMemoryFallback");
|
|
13
|
+
function createRedisClient(redisURL) {
|
|
14
|
+
const url = (0, url_1.parse)(redisURL);
|
|
15
|
+
const useTLS = url.protocol === 'rediss:';
|
|
16
|
+
return new ioredis_1.Redis.Cluster([
|
|
17
|
+
{
|
|
18
|
+
host: url.hostname ?? (0, assert_1.fail)('no hostname'),
|
|
19
|
+
port: Number(url.port) ?? (0, assert_1.fail)('no port'),
|
|
20
|
+
},
|
|
21
|
+
], {
|
|
22
|
+
clusterRetryStrategy: (times) => {
|
|
23
|
+
if (times > 2) {
|
|
24
|
+
return 0;
|
|
25
|
+
}
|
|
26
|
+
return 1000;
|
|
27
|
+
},
|
|
28
|
+
// recommended for ioredis + ElastiCache
|
|
29
|
+
dnsLookup(hostname, callback) {
|
|
30
|
+
callback(null, hostname);
|
|
31
|
+
},
|
|
32
|
+
redisOptions: {
|
|
33
|
+
tls: useTLS ? {} : undefined,
|
|
34
|
+
commandTimeout: 1000,
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
}
|
|
13
38
|
function createTokenStorage(opt, logger) {
|
|
14
39
|
let tokensRepository;
|
|
15
40
|
switch (opt.storage) {
|
|
16
41
|
case 'redis': {
|
|
17
|
-
const
|
|
18
|
-
const useTLS = url.protocol === 'rediss:';
|
|
19
|
-
const redis = new ioredis_1.Redis.Cluster([
|
|
20
|
-
{
|
|
21
|
-
host: url.hostname ?? (0, assert_1.fail)('no hostname'),
|
|
22
|
-
port: Number(url.port) ?? (0, assert_1.fail)('no port'),
|
|
23
|
-
},
|
|
24
|
-
], {
|
|
25
|
-
clusterRetryStrategy: (times) => {
|
|
26
|
-
if (times > 2) {
|
|
27
|
-
return 0;
|
|
28
|
-
}
|
|
29
|
-
return 1000;
|
|
30
|
-
},
|
|
31
|
-
// recommended for ioredis + ElastiCache
|
|
32
|
-
dnsLookup(hostname, callback) {
|
|
33
|
-
callback(null, hostname);
|
|
34
|
-
},
|
|
35
|
-
redisOptions: {
|
|
36
|
-
tls: useTLS ? {} : undefined,
|
|
37
|
-
commandTimeout: 1000,
|
|
38
|
-
},
|
|
39
|
-
});
|
|
42
|
+
const redis = 'redis' in opt ? opt.redis : createRedisClient(opt.redisURL);
|
|
40
43
|
tokensRepository = new TokensRepository_RedisWithMemoryFallback_1.TokensRepository_RedisWithMemoryFallback(new TokensRepository_Redis_1.TokensRepository_Redis(redis, logger), new TokensRepository_Memory_1.TokensRepository_Memory(logger), logger);
|
|
41
44
|
break;
|
|
42
45
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createOAuthManager.js","sourceRoot":"","sources":["../../../src/oauth-manager/factories/createOAuthManager.ts"],"names":[],"mappings":";;;AAAA,mCAAkC;AAClC,6BAAwC;AACxC,
|
|
1
|
+
{"version":3,"file":"createOAuthManager.js","sourceRoot":"","sources":["../../../src/oauth-manager/factories/createOAuthManager.ts"],"names":[],"mappings":";;;AAAA,mCAAkC;AAClC,6BAAwC;AACxC,qCAAyC;AACzC,oDAAiD;AAEjD,0FAAuF;AACvF,wEAAqE;AACrE,wEAAqE;AACrE,sEAAmE;AACnE,0GAAuG;AAoBvG,SAAS,iBAAiB,CAAC,QAAgB;IACzC,MAAM,GAAG,GAAG,IAAA,WAAQ,EAAC,QAAQ,CAAC,CAAC;IAC/B,MAAM,MAAM,GAAG,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC;IAE1C,OAAO,IAAI,eAAK,CAAC,OAAO,CACtB;QACE;YACE,IAAI,EAAE,GAAG,CAAC,QAAQ,IAAI,IAAA,aAAI,EAAC,aAAa,CAAC;YACzC,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAA,aAAI,EAAC,SAAS,CAAC;SAC1C;KACF,EACD;QACE,oBAAoB,EAAE,CAAC,KAAK,EAAE,EAAE;YAC9B,IAAI,KAAK,GAAG,CAAC,EAAE;gBACb,OAAO,CAAC,CAAC;aACV;YACD,OAAO,IAAI,CAAC;QACd,CAAC;QACD,wCAAwC;QACxC,SAAS,CAAC,QAAQ,EAAE,QAAQ;YAC1B,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QAC3B,CAAC;QACD,YAAY,EAAE;YACZ,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS;YAC5B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