@poly-x/core 0.1.0-alpha.0 → 0.1.0-alpha.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/dist/index.cjs +27 -4
- package/dist/index.d.cts +19 -0
- package/dist/index.d.mts +19 -0
- package/dist/index.mjs +27 -4
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -167,11 +167,21 @@ function resolveConfig(input) {
|
|
|
167
167
|
}
|
|
168
168
|
baseUrl = normalizeBaseUrl(input.baseUrl);
|
|
169
169
|
} else baseUrl = `https://${normalizeBaseUrl(key.host)}`;
|
|
170
|
+
let signInUrl;
|
|
171
|
+
if (input.signInUrl !== void 0) {
|
|
172
|
+
try {
|
|
173
|
+
new URL(input.signInUrl);
|
|
174
|
+
} catch {
|
|
175
|
+
throw new PolyXConfigError("The signInUrl is not a valid URL.", { code: "SIGN_IN_URL_INVALID" });
|
|
176
|
+
}
|
|
177
|
+
signInUrl = normalizeBaseUrl(input.signInUrl);
|
|
178
|
+
}
|
|
170
179
|
return {
|
|
171
180
|
key,
|
|
172
181
|
kind: key.kind,
|
|
173
182
|
env: key.env,
|
|
174
183
|
baseUrl,
|
|
184
|
+
signInUrl,
|
|
175
185
|
context
|
|
176
186
|
};
|
|
177
187
|
}
|
|
@@ -815,10 +825,9 @@ var AuthClient = class {
|
|
|
815
825
|
this.transport = options.transport;
|
|
816
826
|
this.clock = options.clock ?? new SystemClock();
|
|
817
827
|
}
|
|
818
|
-
|
|
819
|
-
const url = new URL(this.config.baseUrl + ENDPOINTS.authorize);
|
|
828
|
+
appendAuthorizeParams(url, params) {
|
|
820
829
|
url.searchParams.set("response_type", "code");
|
|
821
|
-
url.searchParams.set("
|
|
830
|
+
url.searchParams.set("client_id", this.config.key.raw);
|
|
822
831
|
url.searchParams.set("redirect_uri", params.redirectUri);
|
|
823
832
|
url.searchParams.set("state", params.state);
|
|
824
833
|
url.searchParams.set("code_challenge", params.challenge);
|
|
@@ -827,6 +836,20 @@ var AuthClient = class {
|
|
|
827
836
|
if (params.prompt) url.searchParams.set("prompt", params.prompt);
|
|
828
837
|
return url.toString();
|
|
829
838
|
}
|
|
839
|
+
/** The API `GET /v1/idp/authorize` URL — used for the silent warm-hop probe. */
|
|
840
|
+
buildAuthorizeUrl(params) {
|
|
841
|
+
return this.appendAuthorizeParams(new URL(this.config.baseUrl + ENDPOINTS.authorize), params);
|
|
842
|
+
}
|
|
843
|
+
/**
|
|
844
|
+
* The URL the interactive sign-in popup/redirect opens. Targets the HOSTED login
|
|
845
|
+
* PAGE (`config.signInUrl`) — which renders the form, POSTs the API, and redirects
|
|
846
|
+
* to `redirect_uri` with the code. Falls back to the API authorize URL when no
|
|
847
|
+
* `signInUrl` is configured (deployments where the API host serves the page).
|
|
848
|
+
*/
|
|
849
|
+
buildSignInUrl(params) {
|
|
850
|
+
if (!this.config.signInUrl) return this.buildAuthorizeUrl(params);
|
|
851
|
+
return this.appendAuthorizeParams(new URL(this.config.signInUrl), params);
|
|
852
|
+
}
|
|
830
853
|
/** Probe the warm hop (GET /idp/authorize) and return the typed outcome. */
|
|
831
854
|
async completeAuthorize(params) {
|
|
832
855
|
const response = await this.transport.request({
|
|
@@ -845,7 +868,7 @@ var AuthClient = class {
|
|
|
845
868
|
code: params.code,
|
|
846
869
|
code_verifier: params.codeVerifier,
|
|
847
870
|
redirect_uri: params.redirectUri,
|
|
848
|
-
|
|
871
|
+
client_id: this.config.key.raw
|
|
849
872
|
}
|
|
850
873
|
});
|
|
851
874
|
if (response.status !== 200) throw this.toError(response);
|
package/dist/index.d.cts
CHANGED
|
@@ -27,6 +27,14 @@ interface ResolveConfigInput {
|
|
|
27
27
|
key: string;
|
|
28
28
|
/** Wins over the key-embedded host. */
|
|
29
29
|
baseUrl?: string;
|
|
30
|
+
/**
|
|
31
|
+
* URL of the HOSTED sign-in page (the account portal that renders the login
|
|
32
|
+
* form) — distinct from the API `baseUrl` the key encodes. The interactive
|
|
33
|
+
* sign-in popup/redirect targets this; the silent warm-hop probe still hits the
|
|
34
|
+
* API. When unset, sign-in falls back to the API's `/v1/idp/authorize` (for
|
|
35
|
+
* deployments where the API host also serves the login page).
|
|
36
|
+
*/
|
|
37
|
+
signInUrl?: string;
|
|
30
38
|
/** Defaults to runtime auto-detection. */
|
|
31
39
|
context?: RuntimeContext;
|
|
32
40
|
}
|
|
@@ -35,6 +43,8 @@ interface ResolvedConfig {
|
|
|
35
43
|
kind: KeyKind;
|
|
36
44
|
env: KeyEnv;
|
|
37
45
|
baseUrl: string;
|
|
46
|
+
/** Hosted sign-in page URL (see ResolveConfigInput.signInUrl); undefined = use the API. */
|
|
47
|
+
signInUrl?: string;
|
|
38
48
|
context: RuntimeContext;
|
|
39
49
|
}
|
|
40
50
|
declare function resolveConfig(input: ResolveConfigInput): ResolvedConfig;
|
|
@@ -467,7 +477,16 @@ declare class AuthClient {
|
|
|
467
477
|
private readonly transport;
|
|
468
478
|
private readonly clock;
|
|
469
479
|
constructor(options: AuthClientOptions);
|
|
480
|
+
private appendAuthorizeParams;
|
|
481
|
+
/** The API `GET /v1/idp/authorize` URL — used for the silent warm-hop probe. */
|
|
470
482
|
buildAuthorizeUrl(params: BuildAuthorizeUrlParams): string;
|
|
483
|
+
/**
|
|
484
|
+
* The URL the interactive sign-in popup/redirect opens. Targets the HOSTED login
|
|
485
|
+
* PAGE (`config.signInUrl`) — which renders the form, POSTs the API, and redirects
|
|
486
|
+
* to `redirect_uri` with the code. Falls back to the API authorize URL when no
|
|
487
|
+
* `signInUrl` is configured (deployments where the API host serves the page).
|
|
488
|
+
*/
|
|
489
|
+
buildSignInUrl(params: BuildAuthorizeUrlParams): string;
|
|
471
490
|
/** Probe the warm hop (GET /idp/authorize) and return the typed outcome. */
|
|
472
491
|
completeAuthorize(params: BuildAuthorizeUrlParams): Promise<AuthorizeOutcome>;
|
|
473
492
|
exchangeCode(params: ExchangeCodeParams): Promise<StoredSession>;
|
package/dist/index.d.mts
CHANGED
|
@@ -27,6 +27,14 @@ interface ResolveConfigInput {
|
|
|
27
27
|
key: string;
|
|
28
28
|
/** Wins over the key-embedded host. */
|
|
29
29
|
baseUrl?: string;
|
|
30
|
+
/**
|
|
31
|
+
* URL of the HOSTED sign-in page (the account portal that renders the login
|
|
32
|
+
* form) — distinct from the API `baseUrl` the key encodes. The interactive
|
|
33
|
+
* sign-in popup/redirect targets this; the silent warm-hop probe still hits the
|
|
34
|
+
* API. When unset, sign-in falls back to the API's `/v1/idp/authorize` (for
|
|
35
|
+
* deployments where the API host also serves the login page).
|
|
36
|
+
*/
|
|
37
|
+
signInUrl?: string;
|
|
30
38
|
/** Defaults to runtime auto-detection. */
|
|
31
39
|
context?: RuntimeContext;
|
|
32
40
|
}
|
|
@@ -35,6 +43,8 @@ interface ResolvedConfig {
|
|
|
35
43
|
kind: KeyKind;
|
|
36
44
|
env: KeyEnv;
|
|
37
45
|
baseUrl: string;
|
|
46
|
+
/** Hosted sign-in page URL (see ResolveConfigInput.signInUrl); undefined = use the API. */
|
|
47
|
+
signInUrl?: string;
|
|
38
48
|
context: RuntimeContext;
|
|
39
49
|
}
|
|
40
50
|
declare function resolveConfig(input: ResolveConfigInput): ResolvedConfig;
|
|
@@ -467,7 +477,16 @@ declare class AuthClient {
|
|
|
467
477
|
private readonly transport;
|
|
468
478
|
private readonly clock;
|
|
469
479
|
constructor(options: AuthClientOptions);
|
|
480
|
+
private appendAuthorizeParams;
|
|
481
|
+
/** The API `GET /v1/idp/authorize` URL — used for the silent warm-hop probe. */
|
|
470
482
|
buildAuthorizeUrl(params: BuildAuthorizeUrlParams): string;
|
|
483
|
+
/**
|
|
484
|
+
* The URL the interactive sign-in popup/redirect opens. Targets the HOSTED login
|
|
485
|
+
* PAGE (`config.signInUrl`) — which renders the form, POSTs the API, and redirects
|
|
486
|
+
* to `redirect_uri` with the code. Falls back to the API authorize URL when no
|
|
487
|
+
* `signInUrl` is configured (deployments where the API host serves the page).
|
|
488
|
+
*/
|
|
489
|
+
buildSignInUrl(params: BuildAuthorizeUrlParams): string;
|
|
471
490
|
/** Probe the warm hop (GET /idp/authorize) and return the typed outcome. */
|
|
472
491
|
completeAuthorize(params: BuildAuthorizeUrlParams): Promise<AuthorizeOutcome>;
|
|
473
492
|
exchangeCode(params: ExchangeCodeParams): Promise<StoredSession>;
|
package/dist/index.mjs
CHANGED
|
@@ -166,11 +166,21 @@ function resolveConfig(input) {
|
|
|
166
166
|
}
|
|
167
167
|
baseUrl = normalizeBaseUrl(input.baseUrl);
|
|
168
168
|
} else baseUrl = `https://${normalizeBaseUrl(key.host)}`;
|
|
169
|
+
let signInUrl;
|
|
170
|
+
if (input.signInUrl !== void 0) {
|
|
171
|
+
try {
|
|
172
|
+
new URL(input.signInUrl);
|
|
173
|
+
} catch {
|
|
174
|
+
throw new PolyXConfigError("The signInUrl is not a valid URL.", { code: "SIGN_IN_URL_INVALID" });
|
|
175
|
+
}
|
|
176
|
+
signInUrl = normalizeBaseUrl(input.signInUrl);
|
|
177
|
+
}
|
|
169
178
|
return {
|
|
170
179
|
key,
|
|
171
180
|
kind: key.kind,
|
|
172
181
|
env: key.env,
|
|
173
182
|
baseUrl,
|
|
183
|
+
signInUrl,
|
|
174
184
|
context
|
|
175
185
|
};
|
|
176
186
|
}
|
|
@@ -814,10 +824,9 @@ var AuthClient = class {
|
|
|
814
824
|
this.transport = options.transport;
|
|
815
825
|
this.clock = options.clock ?? new SystemClock();
|
|
816
826
|
}
|
|
817
|
-
|
|
818
|
-
const url = new URL(this.config.baseUrl + ENDPOINTS.authorize);
|
|
827
|
+
appendAuthorizeParams(url, params) {
|
|
819
828
|
url.searchParams.set("response_type", "code");
|
|
820
|
-
url.searchParams.set("
|
|
829
|
+
url.searchParams.set("client_id", this.config.key.raw);
|
|
821
830
|
url.searchParams.set("redirect_uri", params.redirectUri);
|
|
822
831
|
url.searchParams.set("state", params.state);
|
|
823
832
|
url.searchParams.set("code_challenge", params.challenge);
|
|
@@ -826,6 +835,20 @@ var AuthClient = class {
|
|
|
826
835
|
if (params.prompt) url.searchParams.set("prompt", params.prompt);
|
|
827
836
|
return url.toString();
|
|
828
837
|
}
|
|
838
|
+
/** The API `GET /v1/idp/authorize` URL — used for the silent warm-hop probe. */
|
|
839
|
+
buildAuthorizeUrl(params) {
|
|
840
|
+
return this.appendAuthorizeParams(new URL(this.config.baseUrl + ENDPOINTS.authorize), params);
|
|
841
|
+
}
|
|
842
|
+
/**
|
|
843
|
+
* The URL the interactive sign-in popup/redirect opens. Targets the HOSTED login
|
|
844
|
+
* PAGE (`config.signInUrl`) — which renders the form, POSTs the API, and redirects
|
|
845
|
+
* to `redirect_uri` with the code. Falls back to the API authorize URL when no
|
|
846
|
+
* `signInUrl` is configured (deployments where the API host serves the page).
|
|
847
|
+
*/
|
|
848
|
+
buildSignInUrl(params) {
|
|
849
|
+
if (!this.config.signInUrl) return this.buildAuthorizeUrl(params);
|
|
850
|
+
return this.appendAuthorizeParams(new URL(this.config.signInUrl), params);
|
|
851
|
+
}
|
|
829
852
|
/** Probe the warm hop (GET /idp/authorize) and return the typed outcome. */
|
|
830
853
|
async completeAuthorize(params) {
|
|
831
854
|
const response = await this.transport.request({
|
|
@@ -844,7 +867,7 @@ var AuthClient = class {
|
|
|
844
867
|
code: params.code,
|
|
845
868
|
code_verifier: params.codeVerifier,
|
|
846
869
|
redirect_uri: params.redirectUri,
|
|
847
|
-
|
|
870
|
+
client_id: this.config.key.raw
|
|
848
871
|
}
|
|
849
872
|
});
|
|
850
873
|
if (response.status !== 200) throw this.toError(response);
|