@globus/sdk 4.4.0 → 5.0.0
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/core/authorization/index.js +98 -107
- package/dist/cjs/core/authorization/index.js.map +3 -3
- package/dist/cjs/core/info/index.js +1 -1
- package/dist/cjs/core/info/index.js.map +1 -1
- package/dist/cjs/index.js +98 -107
- package/dist/cjs/index.js.map +3 -3
- package/dist/cjs/services/globus-connect-server/client.js +1 -1
- package/dist/cjs/services/globus-connect-server/client.js.map +1 -1
- package/dist/esm/core/authorization/AuthorizationManager.d.ts +21 -7
- package/dist/esm/core/authorization/AuthorizationManager.d.ts.map +1 -1
- package/dist/esm/core/authorization/AuthorizationManager.js +45 -14
- package/dist/esm/core/authorization/AuthorizationManager.js.map +1 -1
- package/dist/esm/core/authorization/{TokenLookup.d.ts → TokenManager.d.ts} +3 -7
- package/dist/esm/core/authorization/TokenManager.d.ts.map +1 -0
- package/dist/esm/core/authorization/{TokenLookup.js → TokenManager.js} +36 -46
- package/dist/esm/core/authorization/TokenManager.js.map +1 -0
- package/dist/esm/core/info/version.d.ts +1 -1
- package/dist/esm/core/info/version.js +1 -1
- package/dist/esm/core/storage/memory.d.ts +10 -6
- package/dist/esm/core/storage/memory.d.ts.map +1 -1
- package/dist/esm/core/storage/memory.js +13 -6
- package/dist/esm/core/storage/memory.js.map +1 -1
- package/dist/esm/package.json +1 -1
- package/dist/umd/globus.production.js +2 -2
- package/dist/umd/globus.production.js.map +4 -4
- package/package.json +2 -2
- package/dist/esm/core/authorization/TokenLookup.d.ts.map +0 -1
- package/dist/esm/core/authorization/TokenLookup.js.map +0 -1
- package/dist/esm/core/storage/index.d.ts +0 -29
- package/dist/esm/core/storage/index.d.ts.map +0 -1
- package/dist/esm/core/storage/index.js +0 -37
- package/dist/esm/core/storage/index.js.map +0 -1
- package/dist/esm/core/storage/local-storage.d.ts +0 -10
- package/dist/esm/core/storage/local-storage.d.ts.map +0 -1
- package/dist/esm/core/storage/local-storage.js +0 -28
- package/dist/esm/core/storage/local-storage.js.map +0 -1
|
@@ -322,7 +322,7 @@ function toString(info) {
|
|
|
322
322
|
}
|
|
323
323
|
|
|
324
324
|
// src/core/info/version.ts
|
|
325
|
-
var VERSION = "
|
|
325
|
+
var VERSION = "5.0.0";
|
|
326
326
|
|
|
327
327
|
// src/core/info/index.ts
|
|
328
328
|
var VERSION2 = VERSION;
|
|
@@ -586,64 +586,6 @@ function isGlobusAuthTokenResponse(check) {
|
|
|
586
586
|
return isToken(check) && check !== null && "resource_server" in check;
|
|
587
587
|
}
|
|
588
588
|
|
|
589
|
-
// src/core/storage/memory.ts
|
|
590
|
-
var MemoryStorage = class {
|
|
591
|
-
#storage = {};
|
|
592
|
-
get(key) {
|
|
593
|
-
return this.#storage[key] !== void 0 ? this.#storage[key] : null;
|
|
594
|
-
}
|
|
595
|
-
set(key, value) {
|
|
596
|
-
this.#storage[key] = typeof value !== "string" ? JSON.stringify(value) : value;
|
|
597
|
-
}
|
|
598
|
-
remove(key) {
|
|
599
|
-
delete this.#storage[key];
|
|
600
|
-
}
|
|
601
|
-
keys() {
|
|
602
|
-
return Object.keys(this.#storage);
|
|
603
|
-
}
|
|
604
|
-
clear() {
|
|
605
|
-
this.#storage = {};
|
|
606
|
-
}
|
|
607
|
-
};
|
|
608
|
-
|
|
609
|
-
// src/core/storage/local-storage.ts
|
|
610
|
-
var LocalStorage = class {
|
|
611
|
-
#storage = globalThis.localStorage;
|
|
612
|
-
get(key) {
|
|
613
|
-
return this.#storage.getItem(key);
|
|
614
|
-
}
|
|
615
|
-
set(key, value) {
|
|
616
|
-
this.#storage.setItem(key, typeof value !== "string" ? JSON.stringify(value) : value);
|
|
617
|
-
}
|
|
618
|
-
keys() {
|
|
619
|
-
return Object.keys(this.#storage);
|
|
620
|
-
}
|
|
621
|
-
remove(key) {
|
|
622
|
-
this.#storage.removeItem(key);
|
|
623
|
-
}
|
|
624
|
-
clear() {
|
|
625
|
-
this.#storage.clear();
|
|
626
|
-
}
|
|
627
|
-
};
|
|
628
|
-
|
|
629
|
-
// src/core/storage/index.ts
|
|
630
|
-
var storage;
|
|
631
|
-
function createStorage(storageType = "memory") {
|
|
632
|
-
if (!storage) {
|
|
633
|
-
let Factory;
|
|
634
|
-
if (storageType === "localStorage") {
|
|
635
|
-
Factory = LocalStorage;
|
|
636
|
-
} else if (storageType === "memory") {
|
|
637
|
-
Factory = MemoryStorage;
|
|
638
|
-
} else {
|
|
639
|
-
Factory = storageType;
|
|
640
|
-
}
|
|
641
|
-
storage = new Factory();
|
|
642
|
-
}
|
|
643
|
-
return storage;
|
|
644
|
-
}
|
|
645
|
-
var getStorage = createStorage;
|
|
646
|
-
|
|
647
589
|
// src/core/authorization/Event.ts
|
|
648
590
|
var Event = class {
|
|
649
591
|
constructor(name) {
|
|
@@ -779,30 +721,33 @@ var RedirectTransport = class _RedirectTransport {
|
|
|
779
721
|
}
|
|
780
722
|
};
|
|
781
723
|
|
|
782
|
-
// src/core/authorization/
|
|
783
|
-
|
|
784
|
-
const raw = getStorage().get(key) || "null";
|
|
785
|
-
let token2 = null;
|
|
786
|
-
try {
|
|
787
|
-
const parsed = JSON.parse(raw);
|
|
788
|
-
if (isToken(parsed)) {
|
|
789
|
-
token2 = parsed;
|
|
790
|
-
}
|
|
791
|
-
} catch (e) {
|
|
792
|
-
}
|
|
793
|
-
return token2;
|
|
794
|
-
}
|
|
795
|
-
var TokenLookup = class {
|
|
724
|
+
// src/core/authorization/TokenManager.ts
|
|
725
|
+
var TokenManager = class {
|
|
796
726
|
#manager;
|
|
797
727
|
constructor(options) {
|
|
798
728
|
this.#manager = options.manager;
|
|
799
729
|
}
|
|
800
|
-
|
|
801
|
-
|
|
730
|
+
/**
|
|
731
|
+
* Retrieve and parse an item from the storage.
|
|
732
|
+
*/
|
|
733
|
+
#getTokenFromStorage(key) {
|
|
734
|
+
const raw = this.#manager.storage.getItem(key) || "null";
|
|
735
|
+
let token2 = null;
|
|
736
|
+
try {
|
|
737
|
+
const parsed = JSON.parse(raw);
|
|
738
|
+
if (isToken(parsed)) {
|
|
739
|
+
token2 = parsed;
|
|
740
|
+
}
|
|
741
|
+
} catch (e) {
|
|
742
|
+
}
|
|
743
|
+
return token2;
|
|
802
744
|
}
|
|
803
745
|
#getTokenForService(service) {
|
|
804
746
|
const resourceServer = CONFIG.RESOURCE_SERVERS?.[service];
|
|
805
|
-
return this
|
|
747
|
+
return this.getByResourceServer(resourceServer);
|
|
748
|
+
}
|
|
749
|
+
getByResourceServer(resourceServer) {
|
|
750
|
+
return this.#getTokenFromStorage(`${this.#manager.storageKeyPrefix}${resourceServer}`);
|
|
806
751
|
}
|
|
807
752
|
get auth() {
|
|
808
753
|
return this.#getTokenForService(SERVICES.AUTH);
|
|
@@ -828,16 +773,16 @@ var TokenLookup = class {
|
|
|
828
773
|
gcs(endpoint) {
|
|
829
774
|
return this.getByResourceServer(endpoint);
|
|
830
775
|
}
|
|
831
|
-
getByResourceServer(resourceServer) {
|
|
832
|
-
return this.#getClientStorageEntry(resourceServer);
|
|
833
|
-
}
|
|
834
776
|
getAll() {
|
|
835
|
-
const entries =
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
777
|
+
const entries = Object.keys(this.#manager.storage).reduce(
|
|
778
|
+
(acc, key) => {
|
|
779
|
+
if (key.startsWith(this.#manager.storageKeyPrefix)) {
|
|
780
|
+
acc.push(this.#getTokenFromStorage(key));
|
|
781
|
+
}
|
|
782
|
+
return acc;
|
|
783
|
+
},
|
|
784
|
+
[]
|
|
785
|
+
);
|
|
841
786
|
return entries.filter(isToken);
|
|
842
787
|
}
|
|
843
788
|
/**
|
|
@@ -846,16 +791,19 @@ var TokenLookup = class {
|
|
|
846
791
|
add(token2) {
|
|
847
792
|
const created = Date.now();
|
|
848
793
|
const expires = created + token2.expires_in * 1e3;
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
794
|
+
this.#manager.storage.setItem(
|
|
795
|
+
`${this.#manager.storageKeyPrefix}${token2.resource_server}`,
|
|
796
|
+
JSON.stringify({
|
|
797
|
+
...token2,
|
|
798
|
+
/**
|
|
799
|
+
* Add metadata to the token to track when it was created and when it expires.
|
|
800
|
+
*/
|
|
801
|
+
__metadata: {
|
|
802
|
+
created,
|
|
803
|
+
expires
|
|
804
|
+
}
|
|
805
|
+
})
|
|
806
|
+
);
|
|
859
807
|
if ("other_tokens" in token2) {
|
|
860
808
|
token2.other_tokens?.forEach((t) => {
|
|
861
809
|
this.add(t);
|
|
@@ -877,10 +825,38 @@ var TokenLookup = class {
|
|
|
877
825
|
}
|
|
878
826
|
};
|
|
879
827
|
|
|
828
|
+
// src/core/storage/memory.ts
|
|
829
|
+
var MemoryStorage = class {
|
|
830
|
+
#storage = {};
|
|
831
|
+
getItem(key) {
|
|
832
|
+
return this.#storage[key] !== void 0 ? this.#storage[key] : null;
|
|
833
|
+
}
|
|
834
|
+
setItem(key, value) {
|
|
835
|
+
this.#storage[key] = value;
|
|
836
|
+
}
|
|
837
|
+
removeItem(key) {
|
|
838
|
+
delete this.#storage[key];
|
|
839
|
+
}
|
|
840
|
+
key(index) {
|
|
841
|
+
return Object.keys(this.#storage)[index];
|
|
842
|
+
}
|
|
843
|
+
clear() {
|
|
844
|
+
this.#storage = {};
|
|
845
|
+
}
|
|
846
|
+
get length() {
|
|
847
|
+
return Object.keys(this.#storage).length;
|
|
848
|
+
}
|
|
849
|
+
};
|
|
850
|
+
|
|
880
851
|
// src/core/authorization/AuthorizationManager.ts
|
|
852
|
+
var TRANSPORTS = {
|
|
853
|
+
redirect: RedirectTransport
|
|
854
|
+
// popup: PopupTransport,
|
|
855
|
+
};
|
|
881
856
|
var DEFAULT_CONFIGURATION = {
|
|
882
857
|
useRefreshTokens: false,
|
|
883
|
-
defaultScopes: "openid profile email"
|
|
858
|
+
defaultScopes: "openid profile email",
|
|
859
|
+
transport: "redirect"
|
|
884
860
|
};
|
|
885
861
|
var DEFAULT_HANDLE_ERROR_OPTIONS = {
|
|
886
862
|
execute: true,
|
|
@@ -889,6 +865,11 @@ var DEFAULT_HANDLE_ERROR_OPTIONS = {
|
|
|
889
865
|
var AuthorizationManager = class {
|
|
890
866
|
#transport;
|
|
891
867
|
configuration;
|
|
868
|
+
/**
|
|
869
|
+
* The storage system used by the `AuthorizationManager`.
|
|
870
|
+
* @implements Storage
|
|
871
|
+
*/
|
|
872
|
+
storage;
|
|
892
873
|
#authenticated = false;
|
|
893
874
|
/**
|
|
894
875
|
* The `AuthorizationManager` is considered `authenticated` if it has a valid Globus Auth token.
|
|
@@ -924,7 +905,6 @@ var AuthorizationManager = class {
|
|
|
924
905
|
revoke: new Event("revoke")
|
|
925
906
|
};
|
|
926
907
|
constructor(configuration) {
|
|
927
|
-
createStorage(configuration.storage || "localStorage");
|
|
928
908
|
if (!configuration.client) {
|
|
929
909
|
throw new Error("You must provide a `client` for your application.");
|
|
930
910
|
}
|
|
@@ -934,6 +914,7 @@ var AuthorizationManager = class {
|
|
|
934
914
|
...configuration,
|
|
935
915
|
scopes: [configuration.scopes ? configuration.scopes : "", scopes].filter((s) => s.length).join(" ")
|
|
936
916
|
};
|
|
917
|
+
this.storage = configuration.storage || new MemoryStorage();
|
|
937
918
|
if (this.configuration.events) {
|
|
938
919
|
Object.entries(this.configuration.events).forEach(([name, callback]) => {
|
|
939
920
|
if (name in this.events) {
|
|
@@ -941,7 +922,7 @@ var AuthorizationManager = class {
|
|
|
941
922
|
}
|
|
942
923
|
});
|
|
943
924
|
}
|
|
944
|
-
this.tokens = new
|
|
925
|
+
this.tokens = new TokenManager({
|
|
945
926
|
manager: this
|
|
946
927
|
});
|
|
947
928
|
this.#checkAuthorizationState();
|
|
@@ -1013,7 +994,7 @@ var AuthorizationManager = class {
|
|
|
1013
994
|
* Retrieve the Globus Auth token managed by the instance.
|
|
1014
995
|
*/
|
|
1015
996
|
getGlobusAuthToken() {
|
|
1016
|
-
const entry =
|
|
997
|
+
const entry = this.storage.getItem(`${this.storageKeyPrefix}${RESOURCE_SERVERS.AUTH}`);
|
|
1017
998
|
return entry ? JSON.parse(entry) : null;
|
|
1018
999
|
}
|
|
1019
1000
|
#checkAuthorizationState() {
|
|
@@ -1035,9 +1016,9 @@ var AuthorizationManager = class {
|
|
|
1035
1016
|
* This method **does not** emit the `revoke` event. If you need to emit the `revoke` event, use the `AuthorizationManager.revoke` method.
|
|
1036
1017
|
*/
|
|
1037
1018
|
reset() {
|
|
1038
|
-
|
|
1019
|
+
Object.keys(this.storage).forEach((key) => {
|
|
1039
1020
|
if (key.startsWith(this.storageKeyPrefix)) {
|
|
1040
|
-
|
|
1021
|
+
this.storage.removeItem(key);
|
|
1041
1022
|
}
|
|
1042
1023
|
});
|
|
1043
1024
|
this.authenticated = false;
|
|
@@ -1049,16 +1030,26 @@ var AuthorizationManager = class {
|
|
|
1049
1030
|
#withOfflineAccess(scopes) {
|
|
1050
1031
|
return `${scopes}${this.configuration.useRefreshTokens ? " offline_access" : ""}`;
|
|
1051
1032
|
}
|
|
1052
|
-
#buildTransport(
|
|
1053
|
-
const scopes =
|
|
1054
|
-
|
|
1033
|
+
#buildTransport(options) {
|
|
1034
|
+
const { scopes, ...overrides } = options ?? {};
|
|
1035
|
+
const TransportFactory = TRANSPORTS[this.configuration.transport || "redirect"];
|
|
1036
|
+
let scopesToRequest = this.#withOfflineAccess(scopes ?? (this.configuration.scopes || ""));
|
|
1037
|
+
if (this.storage instanceof MemoryStorage) {
|
|
1038
|
+
scopesToRequest = [
|
|
1039
|
+
// Use a Set to deduplicate the scopes.
|
|
1040
|
+
...new Set(
|
|
1041
|
+
scopesToRequest.split(" ").concat((this.configuration?.scopes || "").split(" "))
|
|
1042
|
+
)
|
|
1043
|
+
].join(" ");
|
|
1044
|
+
}
|
|
1045
|
+
return new TransportFactory({
|
|
1055
1046
|
client: this.configuration.client,
|
|
1056
1047
|
redirect: this.configuration.redirect,
|
|
1057
|
-
scopes,
|
|
1048
|
+
scopes: scopesToRequest,
|
|
1058
1049
|
...overrides,
|
|
1059
|
-
// @todo Decide if we want to include the `include_consented_scopes` parameter by default.
|
|
1060
1050
|
params: {
|
|
1061
|
-
// include_consented_scopes
|
|
1051
|
+
// @todo @todo Decide if we want to include the `include_consented_scopes` parameter by default.
|
|
1052
|
+
// include_consented_scopes: 'true',
|
|
1062
1053
|
...overrides?.params
|
|
1063
1054
|
}
|
|
1064
1055
|
});
|