@logto/client 3.0.0-alpha.1 → 3.0.3
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/lib/adapter/defaults.d.ts +4 -2
- package/lib/adapter/defaults.js +9 -10
- package/lib/adapter/types.d.ts +5 -4
- package/lib/client.d.ts +64 -9
- package/lib/client.js +60 -31
- package/lib/index.js +1 -1
- package/lib/mock.d.ts +24 -36
- package/lib/shim.d.ts +3 -3
- package/lib/shim.js +1 -1
- package/lib/types/index.d.ts +12 -3
- package/lib/types/index.js +7 -4
- package/lib/utils/memoize.js +1 -1
- package/lib/utils/requester.js +4 -3
- package/package.json +22 -33
- package/lib/adapter/defaults.cjs +0 -28
- package/lib/adapter/index.cjs +0 -63
- package/lib/adapter/types.cjs +0 -24
- package/lib/client.cjs +0 -383
- package/lib/errors.cjs +0 -22
- package/lib/index.cjs +0 -81
- package/lib/shim.cjs +0 -66
- package/lib/types/index.cjs +0 -48
- package/lib/utils/index.cjs +0 -10
- package/lib/utils/memoize.cjs +0 -25
- package/lib/utils/once.cjs +0 -20
- package/lib/utils/requester.cjs +0 -29
package/lib/index.cjs
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var defaults = require('./adapter/defaults.cjs');
|
|
6
|
-
var client = require('./client.cjs');
|
|
7
|
-
var js = require('@logto/js');
|
|
8
|
-
var errors = require('./errors.cjs');
|
|
9
|
-
require('@silverhand/essentials');
|
|
10
|
-
var types = require('./adapter/types.cjs');
|
|
11
|
-
var requester = require('./utils/requester.cjs');
|
|
12
|
-
var index = require('./types/index.cjs');
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* The Logto base client class that provides the essential methods for
|
|
16
|
-
* interacting with the Logto server.
|
|
17
|
-
*
|
|
18
|
-
* It also provides an adapter object that allows the customizations of the
|
|
19
|
-
* client behavior for different environments.
|
|
20
|
-
*/
|
|
21
|
-
class LogtoClient extends client.StandardLogtoClient {
|
|
22
|
-
constructor(logtoConfig, adapter, buildJwtVerifier) {
|
|
23
|
-
super(logtoConfig, adapter, buildJwtVerifier ?? ((client) => new defaults.DefaultJwtVerifier(client)));
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
exports.StandardLogtoClient = client.StandardLogtoClient;
|
|
28
|
-
Object.defineProperty(exports, "LogtoError", {
|
|
29
|
-
enumerable: true,
|
|
30
|
-
get: function () { return js.LogtoError; }
|
|
31
|
-
});
|
|
32
|
-
Object.defineProperty(exports, "LogtoRequestError", {
|
|
33
|
-
enumerable: true,
|
|
34
|
-
get: function () { return js.LogtoRequestError; }
|
|
35
|
-
});
|
|
36
|
-
Object.defineProperty(exports, "OidcError", {
|
|
37
|
-
enumerable: true,
|
|
38
|
-
get: function () { return js.OidcError; }
|
|
39
|
-
});
|
|
40
|
-
Object.defineProperty(exports, "Prompt", {
|
|
41
|
-
enumerable: true,
|
|
42
|
-
get: function () { return js.Prompt; }
|
|
43
|
-
});
|
|
44
|
-
Object.defineProperty(exports, "ReservedResource", {
|
|
45
|
-
enumerable: true,
|
|
46
|
-
get: function () { return js.ReservedResource; }
|
|
47
|
-
});
|
|
48
|
-
Object.defineProperty(exports, "ReservedScope", {
|
|
49
|
-
enumerable: true,
|
|
50
|
-
get: function () { return js.ReservedScope; }
|
|
51
|
-
});
|
|
52
|
-
Object.defineProperty(exports, "UserScope", {
|
|
53
|
-
enumerable: true,
|
|
54
|
-
get: function () { return js.UserScope; }
|
|
55
|
-
});
|
|
56
|
-
Object.defineProperty(exports, "buildOrganizationUrn", {
|
|
57
|
-
enumerable: true,
|
|
58
|
-
get: function () { return js.buildOrganizationUrn; }
|
|
59
|
-
});
|
|
60
|
-
Object.defineProperty(exports, "getOrganizationIdFromUrn", {
|
|
61
|
-
enumerable: true,
|
|
62
|
-
get: function () { return js.getOrganizationIdFromUrn; }
|
|
63
|
-
});
|
|
64
|
-
Object.defineProperty(exports, "organizationUrnPrefix", {
|
|
65
|
-
enumerable: true,
|
|
66
|
-
get: function () { return js.organizationUrnPrefix; }
|
|
67
|
-
});
|
|
68
|
-
exports.LogtoClientError = errors.LogtoClientError;
|
|
69
|
-
Object.defineProperty(exports, "CacheKey", {
|
|
70
|
-
enumerable: true,
|
|
71
|
-
get: function () { return types.CacheKey; }
|
|
72
|
-
});
|
|
73
|
-
Object.defineProperty(exports, "PersistKey", {
|
|
74
|
-
enumerable: true,
|
|
75
|
-
get: function () { return types.PersistKey; }
|
|
76
|
-
});
|
|
77
|
-
exports.createRequester = requester.createRequester;
|
|
78
|
-
exports.isLogtoAccessTokenMap = index.isLogtoAccessTokenMap;
|
|
79
|
-
exports.isLogtoSignInSessionItem = index.isLogtoSignInSessionItem;
|
|
80
|
-
exports.normalizeLogtoConfig = index.normalizeLogtoConfig;
|
|
81
|
-
exports.default = LogtoClient;
|
package/lib/shim.cjs
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var js = require('@logto/js');
|
|
4
|
-
var errors = require('./errors.cjs');
|
|
5
|
-
require('@silverhand/essentials');
|
|
6
|
-
var types = require('./adapter/types.cjs');
|
|
7
|
-
var requester = require('./utils/requester.cjs');
|
|
8
|
-
var index = require('./types/index.cjs');
|
|
9
|
-
var client = require('./client.cjs');
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
Object.defineProperty(exports, "LogtoError", {
|
|
14
|
-
enumerable: true,
|
|
15
|
-
get: function () { return js.LogtoError; }
|
|
16
|
-
});
|
|
17
|
-
Object.defineProperty(exports, "LogtoRequestError", {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
get: function () { return js.LogtoRequestError; }
|
|
20
|
-
});
|
|
21
|
-
Object.defineProperty(exports, "OidcError", {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function () { return js.OidcError; }
|
|
24
|
-
});
|
|
25
|
-
Object.defineProperty(exports, "Prompt", {
|
|
26
|
-
enumerable: true,
|
|
27
|
-
get: function () { return js.Prompt; }
|
|
28
|
-
});
|
|
29
|
-
Object.defineProperty(exports, "ReservedResource", {
|
|
30
|
-
enumerable: true,
|
|
31
|
-
get: function () { return js.ReservedResource; }
|
|
32
|
-
});
|
|
33
|
-
Object.defineProperty(exports, "ReservedScope", {
|
|
34
|
-
enumerable: true,
|
|
35
|
-
get: function () { return js.ReservedScope; }
|
|
36
|
-
});
|
|
37
|
-
Object.defineProperty(exports, "UserScope", {
|
|
38
|
-
enumerable: true,
|
|
39
|
-
get: function () { return js.UserScope; }
|
|
40
|
-
});
|
|
41
|
-
Object.defineProperty(exports, "buildOrganizationUrn", {
|
|
42
|
-
enumerable: true,
|
|
43
|
-
get: function () { return js.buildOrganizationUrn; }
|
|
44
|
-
});
|
|
45
|
-
Object.defineProperty(exports, "getOrganizationIdFromUrn", {
|
|
46
|
-
enumerable: true,
|
|
47
|
-
get: function () { return js.getOrganizationIdFromUrn; }
|
|
48
|
-
});
|
|
49
|
-
Object.defineProperty(exports, "organizationUrnPrefix", {
|
|
50
|
-
enumerable: true,
|
|
51
|
-
get: function () { return js.organizationUrnPrefix; }
|
|
52
|
-
});
|
|
53
|
-
exports.LogtoClientError = errors.LogtoClientError;
|
|
54
|
-
Object.defineProperty(exports, "CacheKey", {
|
|
55
|
-
enumerable: true,
|
|
56
|
-
get: function () { return types.CacheKey; }
|
|
57
|
-
});
|
|
58
|
-
Object.defineProperty(exports, "PersistKey", {
|
|
59
|
-
enumerable: true,
|
|
60
|
-
get: function () { return types.PersistKey; }
|
|
61
|
-
});
|
|
62
|
-
exports.createRequester = requester.createRequester;
|
|
63
|
-
exports.isLogtoAccessTokenMap = index.isLogtoAccessTokenMap;
|
|
64
|
-
exports.isLogtoSignInSessionItem = index.isLogtoSignInSessionItem;
|
|
65
|
-
exports.normalizeLogtoConfig = index.normalizeLogtoConfig;
|
|
66
|
-
exports.StandardLogtoClient = client.StandardLogtoClient;
|
package/lib/types/index.cjs
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var js = require('@logto/js');
|
|
4
|
-
var essentials = require('@silverhand/essentials');
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Normalize the Logto client configuration per the following rules:
|
|
8
|
-
*
|
|
9
|
-
* - Add default scopes (`openid`, `offline_access` and `profile`) if not provided.
|
|
10
|
-
* - Add {@link ReservedResource.Organization} to resources if {@link UserScope.Organizations} is included in scopes.
|
|
11
|
-
*
|
|
12
|
-
* @param config The Logto client configuration to be normalized.
|
|
13
|
-
* @returns The normalized Logto client configuration.
|
|
14
|
-
*/
|
|
15
|
-
const normalizeLogtoConfig = (config) => {
|
|
16
|
-
const { prompt = js.Prompt.Consent, scopes = [], resources, ...rest } = config;
|
|
17
|
-
return {
|
|
18
|
-
...rest,
|
|
19
|
-
prompt,
|
|
20
|
-
scopes: js.withDefaultScopes(scopes).split(' '),
|
|
21
|
-
resources: scopes.includes(js.UserScope.Organizations)
|
|
22
|
-
? essentials.deduplicate([...(resources ?? []), js.ReservedResource.Organization])
|
|
23
|
-
: resources,
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
const isLogtoSignInSessionItem = (data) => {
|
|
27
|
-
if (!js.isArbitraryObject(data)) {
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
return ['redirectUri', 'codeVerifier', 'state'].every((key) => typeof data[key] === 'string');
|
|
31
|
-
};
|
|
32
|
-
const isLogtoAccessTokenMap = (data) => {
|
|
33
|
-
if (!js.isArbitraryObject(data)) {
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
return Object.values(data).every((value) => {
|
|
37
|
-
if (!js.isArbitraryObject(value)) {
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
return (typeof value.token === 'string' &&
|
|
41
|
-
typeof value.scope === 'string' &&
|
|
42
|
-
typeof value.expiresAt === 'number');
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
exports.isLogtoAccessTokenMap = isLogtoAccessTokenMap;
|
|
47
|
-
exports.isLogtoSignInSessionItem = isLogtoSignInSessionItem;
|
|
48
|
-
exports.normalizeLogtoConfig = normalizeLogtoConfig;
|
package/lib/utils/index.cjs
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var js = require('@logto/js');
|
|
4
|
-
var essentials = require('@silverhand/essentials');
|
|
5
|
-
|
|
6
|
-
const buildAccessTokenKey = (resource = '', organizationId, scopes = []) => `${scopes.slice().sort().join(' ')}@${resource}${essentials.conditionalString(organizationId && `#${organizationId}`)}`;
|
|
7
|
-
const getDiscoveryEndpoint = (endpoint) => new URL(js.discoveryPath, endpoint).toString();
|
|
8
|
-
|
|
9
|
-
exports.buildAccessTokenKey = buildAccessTokenKey;
|
|
10
|
-
exports.getDiscoveryEndpoint = getDiscoveryEndpoint;
|
package/lib/utils/memoize.cjs
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
function memoize(run) {
|
|
4
|
-
const promiseCache = new Map();
|
|
5
|
-
const memoized = async function (...args) {
|
|
6
|
-
const promiseKey = args[0];
|
|
7
|
-
const cachedPromise = promiseCache.get(promiseKey);
|
|
8
|
-
if (cachedPromise) {
|
|
9
|
-
return cachedPromise;
|
|
10
|
-
}
|
|
11
|
-
const promise = (async () => {
|
|
12
|
-
try {
|
|
13
|
-
return await run.apply(this, args);
|
|
14
|
-
}
|
|
15
|
-
finally {
|
|
16
|
-
promiseCache.delete(promiseKey);
|
|
17
|
-
}
|
|
18
|
-
})();
|
|
19
|
-
promiseCache.set(promiseKey, promise);
|
|
20
|
-
return promise;
|
|
21
|
-
};
|
|
22
|
-
return memoized;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
exports.memoize = memoize;
|
package/lib/utils/once.cjs
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// TODO @sijie move to essentials
|
|
4
|
-
/* eslint-disable @silverhand/fp/no-let */
|
|
5
|
-
/* eslint-disable @silverhand/fp/no-mutation */
|
|
6
|
-
function once(function_) {
|
|
7
|
-
let called = false;
|
|
8
|
-
let result;
|
|
9
|
-
return function (...args) {
|
|
10
|
-
if (!called) {
|
|
11
|
-
called = true;
|
|
12
|
-
result = function_.apply(this, args);
|
|
13
|
-
}
|
|
14
|
-
return result;
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
/* eslint-enable @silverhand/fp/no-mutation */
|
|
18
|
-
/* eslint-enable @silverhand/fp/no-let */
|
|
19
|
-
|
|
20
|
-
exports.once = once;
|
package/lib/utils/requester.cjs
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var js = require('@logto/js');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* A factory function that creates a requester by accepting a `fetch`-like function.
|
|
7
|
-
*
|
|
8
|
-
* @param fetchFunction A `fetch`-like function.
|
|
9
|
-
* @returns A requester function.
|
|
10
|
-
* @see {@link Requester}
|
|
11
|
-
*/
|
|
12
|
-
const createRequester = (fetchFunction) => {
|
|
13
|
-
return async (...args) => {
|
|
14
|
-
const response = await fetchFunction(...args);
|
|
15
|
-
if (!response.ok) {
|
|
16
|
-
const responseJson = await response.json();
|
|
17
|
-
console.error(`Logto requester error: [status=${response.status}]`, responseJson);
|
|
18
|
-
if (!js.isLogtoRequestError(responseJson)) {
|
|
19
|
-
throw new js.LogtoError('unexpected_response_error', responseJson);
|
|
20
|
-
}
|
|
21
|
-
// Expected request error from server
|
|
22
|
-
const { code, message } = responseJson;
|
|
23
|
-
throw new js.LogtoRequestError(code, message);
|
|
24
|
-
}
|
|
25
|
-
return response.json();
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
exports.createRequester = createRequester;
|