@coreiam/auth 1.0.392-beta.11 → 1.0.392-beta.12
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/dist/core/index.d.ts +10 -0
- package/dist/core/index.js +19 -2
- package/dist/express/index.js +1 -1
- package/dist/nextjs/middleware.js +2 -2
- package/package.json +3 -2
package/dist/core/index.d.ts
CHANGED
|
@@ -56,6 +56,16 @@ export class CoreIAM {
|
|
|
56
56
|
if (!this.baseUrl) throw new Error('CoreIAM: Missing Gateway URL (COREIAM_API_URL)');
|
|
57
57
|
}
|
|
58
58
|
*/
|
|
59
|
+
/** Default gateway labels (the retired coreiam.e-qalam.com is never a default). */
|
|
60
|
+
export declare const COREIAM_DEV_GATEWAY_URL = "https://dev.e-qalam.com";
|
|
61
|
+
export declare const COREIAM_LIVE_GATEWAY_URL = "https://api.e-qalam.com";
|
|
62
|
+
/** Default by key prefix: pk_dev_ → dev label, anything else → live. */
|
|
63
|
+
export declare function defaultGatewayUrlForKey(apiKey: string): string;
|
|
64
|
+
/** Resolution order: explicit baseUrl > COREIAM_API_URL > key-prefix default. */
|
|
65
|
+
export declare function resolveGatewayUrl(config?: {
|
|
66
|
+
baseUrl?: string;
|
|
67
|
+
apiKey?: string;
|
|
68
|
+
}): string;
|
|
59
69
|
export declare class CoreIAM {
|
|
60
70
|
private apiKey;
|
|
61
71
|
private baseUrl;
|
package/dist/core/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OAUTH_PROVIDERS = exports.CSRF_PROTECTED_PATHS = exports.CoreIAM = void 0;
|
|
3
|
+
exports.OAUTH_PROVIDERS = exports.CSRF_PROTECTED_PATHS = exports.CoreIAM = exports.COREIAM_LIVE_GATEWAY_URL = exports.COREIAM_DEV_GATEWAY_URL = void 0;
|
|
4
4
|
exports.toIdentity = toIdentity;
|
|
5
5
|
exports.retryAfterSeconds = retryAfterSeconds;
|
|
6
|
+
exports.defaultGatewayUrlForKey = defaultGatewayUrlForKey;
|
|
7
|
+
exports.resolveGatewayUrl = resolveGatewayUrl;
|
|
6
8
|
// src/core/index.ts
|
|
7
9
|
const jose_1 = require("jose");
|
|
8
10
|
/** Maps gateway token claims → CoreIAMIdentity (same shape the Next.js middleware injects). */
|
|
@@ -39,6 +41,21 @@ export class CoreIAM {
|
|
|
39
41
|
if (!this.baseUrl) throw new Error('CoreIAM: Missing Gateway URL (COREIAM_API_URL)');
|
|
40
42
|
}
|
|
41
43
|
*/
|
|
44
|
+
// ── K13c: config layer ──────────────────────────────────────────────
|
|
45
|
+
/** Default gateway labels (the retired coreiam.e-qalam.com is never a default). */
|
|
46
|
+
exports.COREIAM_DEV_GATEWAY_URL = 'https://dev.e-qalam.com';
|
|
47
|
+
exports.COREIAM_LIVE_GATEWAY_URL = 'https://api.e-qalam.com';
|
|
48
|
+
/** Default by key prefix: pk_dev_ → dev label, anything else → live. */
|
|
49
|
+
function defaultGatewayUrlForKey(apiKey) {
|
|
50
|
+
return (apiKey || '').startsWith('pk_dev_') ? exports.COREIAM_DEV_GATEWAY_URL : exports.COREIAM_LIVE_GATEWAY_URL;
|
|
51
|
+
}
|
|
52
|
+
/** Resolution order: explicit baseUrl > COREIAM_API_URL > key-prefix default. */
|
|
53
|
+
function resolveGatewayUrl(config) {
|
|
54
|
+
const explicit = (config?.baseUrl || process.env.COREIAM_API_URL || '').replace(/\/+$/, '');
|
|
55
|
+
if (explicit)
|
|
56
|
+
return explicit;
|
|
57
|
+
return defaultGatewayUrlForKey(config?.apiKey || process.env.COREIAM_API_KEY || '');
|
|
58
|
+
}
|
|
42
59
|
class CoreIAM {
|
|
43
60
|
apiKey = '';
|
|
44
61
|
baseUrl = '';
|
|
@@ -50,7 +67,7 @@ class CoreIAM {
|
|
|
50
67
|
refreshInFlight = null;
|
|
51
68
|
constructor(config) {
|
|
52
69
|
this.apiKey = config?.apiKey || process.env.COREIAM_API_KEY || '';
|
|
53
|
-
this.baseUrl = (config
|
|
70
|
+
this.baseUrl = resolveGatewayUrl(config);
|
|
54
71
|
this.issuer = config?.issuer ?? 'coreiam';
|
|
55
72
|
this.audience = config?.audience;
|
|
56
73
|
this.sessionCookieName = config?.sessionCookieName ?? 'jwt';
|
package/dist/express/index.js
CHANGED
|
@@ -16,7 +16,7 @@ function coreIamExpress(options) {
|
|
|
16
16
|
const authPath = (options.authPath ?? '/api/auth').replace(/\/+$/, '');
|
|
17
17
|
const successUrl = options.successUrl ?? '/';
|
|
18
18
|
const signInUrl = options.signInUrl ?? '/login';
|
|
19
|
-
const gatewayUrl = (
|
|
19
|
+
const gatewayUrl = (0, core_1.resolveGatewayUrl)(options);
|
|
20
20
|
const isProd = process.env.NODE_ENV === 'production';
|
|
21
21
|
const iam = new core_1.CoreIAM(options);
|
|
22
22
|
const router = (0, express_1.Router)();
|
|
@@ -126,7 +126,7 @@ exports.coreIamMiddleware = coreIamMiddleware;
|
|
|
126
126
|
const server_1 = require("next/server");
|
|
127
127
|
//import { jwtVerify, createRemoteJWKSet } from 'jose';
|
|
128
128
|
const core_1 = require("../core");
|
|
129
|
-
const gatewayUrl = process.env.
|
|
129
|
+
const gatewayUrl = (0, core_1.resolveGatewayUrl)({ apiKey: process.env.COREIAM_API_KEY || '' });
|
|
130
130
|
/**
|
|
131
131
|
const JWKS = gatewayUrl
|
|
132
132
|
? createRemoteJWKSet(new URL(`${gatewayUrl}/.well-known/jwks.json`))
|
|
@@ -235,7 +235,7 @@ async function coreIamAuth(request) {
|
|
|
235
235
|
const iam = getIam();
|
|
236
236
|
if (!iam) {
|
|
237
237
|
return {
|
|
238
|
-
response: new server_1.NextResponse('CoreIAM is not configured (
|
|
238
|
+
response: new server_1.NextResponse('CoreIAM is not configured (COREIAM_API_KEY required; gateway URL defaults by key prefix)', { status: 500 }),
|
|
239
239
|
isAuthenticated: false,
|
|
240
240
|
};
|
|
241
241
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coreiam/auth",
|
|
3
|
-
"version": "1.0.392-beta.
|
|
3
|
+
"version": "1.0.392-beta.12",
|
|
4
4
|
"main": "./dist/core/index.js",
|
|
5
5
|
"types": "./dist/core/index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -40,7 +40,8 @@
|
|
|
40
40
|
],
|
|
41
41
|
"scripts": {
|
|
42
42
|
"build": "tsc",
|
|
43
|
-
"test": "vitest run"
|
|
43
|
+
"test": "vitest run",
|
|
44
|
+
"prepublishOnly": "grep -q dev.e-qalam.com dist/core/index.js && grep -q api.e-qalam.com dist/core/index.js || { echo \"STALE DIST: rebuild before publish (beta.11 lesson)\"; exit 1; }"
|
|
44
45
|
},
|
|
45
46
|
"keywords": [
|
|
46
47
|
"coreiam",
|