@cratis/arc 18.9.0 → 18.9.2
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/cjs/identity/IdentityProvider.d.ts.map +1 -1
- package/dist/cjs/identity/IdentityProvider.js +4 -1
- package/dist/cjs/identity/IdentityProvider.js.map +1 -1
- package/dist/cjs/identity/for_IdentityProvider/given/an_identity_provider.d.ts.map +1 -1
- package/dist/cjs/identity/for_IdentityProvider/when_refreshing/with_origin_set.d.ts +2 -0
- package/dist/cjs/identity/for_IdentityProvider/when_refreshing/with_origin_set.d.ts.map +1 -0
- package/dist/esm/identity/IdentityProvider.d.ts.map +1 -1
- package/dist/esm/identity/IdentityProvider.js +4 -1
- package/dist/esm/identity/IdentityProvider.js.map +1 -1
- package/dist/esm/identity/for_IdentityProvider/given/an_identity_provider.d.ts.map +1 -1
- package/dist/esm/identity/for_IdentityProvider/given/an_identity_provider.js +6 -1
- package/dist/esm/identity/for_IdentityProvider/given/an_identity_provider.js.map +1 -1
- package/dist/esm/identity/for_IdentityProvider/when_refreshing/with_api_base_path_set.js +4 -2
- package/dist/esm/identity/for_IdentityProvider/when_refreshing/with_api_base_path_set.js.map +1 -1
- package/dist/esm/identity/for_IdentityProvider/when_refreshing/with_globals_api_base_path.js +4 -2
- package/dist/esm/identity/for_IdentityProvider/when_refreshing/with_globals_api_base_path.js.map +1 -1
- package/dist/esm/identity/for_IdentityProvider/when_refreshing/with_origin_set.d.ts +2 -0
- package/dist/esm/identity/for_IdentityProvider/when_refreshing/with_origin_set.d.ts.map +1 -0
- package/dist/esm/identity/for_IdentityProvider/when_refreshing/with_origin_set.js +34 -0
- package/dist/esm/identity/for_IdentityProvider/when_refreshing/with_origin_set.js.map +1 -0
- package/dist/esm/identity/for_IdentityProvider/when_refreshing/without_api_base_path.js +4 -2
- package/dist/esm/identity/for_IdentityProvider/when_refreshing/without_api_base_path.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/identity/IdentityProvider.ts +4 -1
- package/identity/for_IdentityProvider/given/an_identity_provider.ts +6 -1
- package/identity/for_IdentityProvider/when_refreshing/with_api_base_path_set.ts +6 -2
- package/identity/for_IdentityProvider/when_refreshing/with_globals_api_base_path.ts +5 -2
- package/identity/for_IdentityProvider/when_refreshing/with_origin_set.ts +45 -0
- package/identity/for_IdentityProvider/when_refreshing/without_api_base_path.ts +5 -2
- package/package.json +1 -1
|
@@ -7,6 +7,7 @@ import { IIdentity } from './IIdentity';
|
|
|
7
7
|
import { IdentityProviderResult } from './IdentityProviderResult';
|
|
8
8
|
import { GetHttpHeaders } from 'GetHttpHeaders';
|
|
9
9
|
import { Globals } from '../Globals';
|
|
10
|
+
import { UrlHelpers } from '../UrlHelpers';
|
|
10
11
|
import { joinPaths } from '../joinPaths';
|
|
11
12
|
|
|
12
13
|
/**
|
|
@@ -75,8 +76,10 @@ export class IdentityProvider extends IIdentityProvider {
|
|
|
75
76
|
|
|
76
77
|
static async refresh<TDetails extends object = object>(type?: Constructor<TDetails>): Promise<IIdentity<TDetails>> {
|
|
77
78
|
IdentityProvider.clearCookie();
|
|
79
|
+
const origin = IdentityProvider.origin || Globals.origin || '';
|
|
78
80
|
const apiBasePath = IdentityProvider.apiBasePath || Globals.apiBasePath || '';
|
|
79
|
-
const
|
|
81
|
+
const route = joinPaths(apiBasePath, '/.cratis/me');
|
|
82
|
+
const url = UrlHelpers.createUrlFrom(origin, apiBasePath, route);
|
|
80
83
|
const response = await fetch(
|
|
81
84
|
url, {
|
|
82
85
|
method: 'GET',
|
|
@@ -17,7 +17,12 @@ export class an_identity_provider {
|
|
|
17
17
|
|
|
18
18
|
// Mock document for tests that need it
|
|
19
19
|
if (typeof document === 'undefined') {
|
|
20
|
-
(global as { document?: { cookie: string } }).document = {
|
|
20
|
+
(global as { document?: { cookie: string; location: { origin: string } } }).document = {
|
|
21
|
+
cookie: '',
|
|
22
|
+
location: {
|
|
23
|
+
origin: 'http://localhost'
|
|
24
|
+
}
|
|
25
|
+
};
|
|
21
26
|
}
|
|
22
27
|
|
|
23
28
|
this.fetchHelper = createFetchHelper();
|
|
@@ -6,6 +6,8 @@ import { an_identity_provider } from '../given/an_identity_provider';
|
|
|
6
6
|
import { given } from '../../../given';
|
|
7
7
|
|
|
8
8
|
describe('when refreshing with api base path set', given(an_identity_provider, context => {
|
|
9
|
+
let actualUrl: URL;
|
|
10
|
+
|
|
9
11
|
beforeEach(async () => {
|
|
10
12
|
context.fetchStub.resolves({
|
|
11
13
|
ok: true,
|
|
@@ -18,13 +20,15 @@ describe('when refreshing with api base path set', given(an_identity_provider, c
|
|
|
18
20
|
|
|
19
21
|
IdentityProvider.setApiBasePath('/custom/api');
|
|
20
22
|
await IdentityProvider.refresh();
|
|
23
|
+
|
|
24
|
+
actualUrl = context.fetchStub.firstCall.args[0];
|
|
21
25
|
});
|
|
22
26
|
|
|
23
27
|
afterEach(() => {
|
|
24
28
|
IdentityProvider.setApiBasePath('');
|
|
25
29
|
});
|
|
26
30
|
|
|
27
|
-
it('
|
|
28
|
-
|
|
31
|
+
it('should_call_fetch_with_api_base_path_prefixed', () => {
|
|
32
|
+
actualUrl.pathname.should.equal('/custom/api/.cratis/me');
|
|
29
33
|
});
|
|
30
34
|
}));
|
|
@@ -8,6 +8,7 @@ import { given } from '../../../given';
|
|
|
8
8
|
|
|
9
9
|
describe('when refreshing with globals api base path', given(an_identity_provider, context => {
|
|
10
10
|
let originalGlobalsApiBasePath: string;
|
|
11
|
+
let actualUrl: URL;
|
|
11
12
|
|
|
12
13
|
beforeEach(async () => {
|
|
13
14
|
context.fetchStub.resolves({
|
|
@@ -23,6 +24,8 @@ describe('when refreshing with globals api base path', given(an_identity_provide
|
|
|
23
24
|
Globals.apiBasePath = '/global/api';
|
|
24
25
|
IdentityProvider.setApiBasePath('');
|
|
25
26
|
await IdentityProvider.refresh();
|
|
27
|
+
|
|
28
|
+
actualUrl = context.fetchStub.firstCall.args[0];
|
|
26
29
|
});
|
|
27
30
|
|
|
28
31
|
afterEach(() => {
|
|
@@ -30,7 +33,7 @@ describe('when refreshing with globals api base path', given(an_identity_provide
|
|
|
30
33
|
IdentityProvider.setApiBasePath('');
|
|
31
34
|
});
|
|
32
35
|
|
|
33
|
-
it('
|
|
34
|
-
|
|
36
|
+
it('should_call_fetch_with_globals_api_base_path_prefixed', () => {
|
|
37
|
+
actualUrl.pathname.should.equal('/global/api/.cratis/me');
|
|
35
38
|
});
|
|
36
39
|
}));
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { IdentityProvider } from '../../IdentityProvider';
|
|
5
|
+
import { an_identity_provider } from '../given/an_identity_provider';
|
|
6
|
+
import { given } from '../../../given';
|
|
7
|
+
|
|
8
|
+
describe('when refreshing with origin set', given(an_identity_provider, context => {
|
|
9
|
+
let actualUrl: URL;
|
|
10
|
+
|
|
11
|
+
beforeEach(async () => {
|
|
12
|
+
context.fetchStub.resolves({
|
|
13
|
+
ok: true,
|
|
14
|
+
json: async () => ({
|
|
15
|
+
id: 'test-user-id',
|
|
16
|
+
name: 'Test User',
|
|
17
|
+
details: { role: 'admin' }
|
|
18
|
+
})
|
|
19
|
+
} as Response);
|
|
20
|
+
|
|
21
|
+
IdentityProvider.setOrigin('https://example.com');
|
|
22
|
+
IdentityProvider.setApiBasePath('/api/v1');
|
|
23
|
+
|
|
24
|
+
await IdentityProvider.refresh();
|
|
25
|
+
|
|
26
|
+
actualUrl = context.fetchStub.firstCall.args[0];
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
afterEach(() => {
|
|
30
|
+
IdentityProvider.setOrigin('');
|
|
31
|
+
IdentityProvider.setApiBasePath('');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('should_call_fetch_with_full_url_including_origin', () => {
|
|
35
|
+
actualUrl.href.should.equal('https://example.com/api/v1/.cratis/me');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('should_have_correct_origin', () => {
|
|
39
|
+
actualUrl.origin.should.equal('https://example.com');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should_have_correct_pathname', () => {
|
|
43
|
+
actualUrl.pathname.should.equal('/api/v1/.cratis/me');
|
|
44
|
+
});
|
|
45
|
+
}));
|
|
@@ -8,6 +8,7 @@ import { given } from '../../../given';
|
|
|
8
8
|
|
|
9
9
|
describe('when refreshing without api base path', given(an_identity_provider, context => {
|
|
10
10
|
let originalGlobalsApiBasePath: string;
|
|
11
|
+
let actualUrl: URL;
|
|
11
12
|
|
|
12
13
|
beforeEach(async () => {
|
|
13
14
|
context.fetchStub.resolves({
|
|
@@ -23,13 +24,15 @@ describe('when refreshing without api base path', given(an_identity_provider, co
|
|
|
23
24
|
Globals.apiBasePath = '';
|
|
24
25
|
IdentityProvider.setApiBasePath('');
|
|
25
26
|
await IdentityProvider.refresh();
|
|
27
|
+
|
|
28
|
+
actualUrl = context.fetchStub.firstCall.args[0];
|
|
26
29
|
});
|
|
27
30
|
|
|
28
31
|
afterEach(() => {
|
|
29
32
|
Globals.apiBasePath = originalGlobalsApiBasePath;
|
|
30
33
|
});
|
|
31
34
|
|
|
32
|
-
it('
|
|
33
|
-
|
|
35
|
+
it('should_call_fetch_with_default_path', () => {
|
|
36
|
+
actualUrl.pathname.should.equal('/.cratis/me');
|
|
34
37
|
});
|
|
35
38
|
}));
|