@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
package/dist/cjs/index.js
CHANGED
|
@@ -71,7 +71,7 @@ function toString(info2) {
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
// src/core/info/version.ts
|
|
74
|
-
var VERSION = "
|
|
74
|
+
var VERSION = "5.0.0";
|
|
75
75
|
|
|
76
76
|
// src/core/info/index.ts
|
|
77
77
|
var VERSION2 = VERSION;
|
|
@@ -739,64 +739,6 @@ function isGlobusAuthTokenResponse(check) {
|
|
|
739
739
|
return isToken(check) && check !== null && "resource_server" in check;
|
|
740
740
|
}
|
|
741
741
|
|
|
742
|
-
// src/core/storage/memory.ts
|
|
743
|
-
var MemoryStorage = class {
|
|
744
|
-
#storage = {};
|
|
745
|
-
get(key) {
|
|
746
|
-
return this.#storage[key] !== void 0 ? this.#storage[key] : null;
|
|
747
|
-
}
|
|
748
|
-
set(key, value) {
|
|
749
|
-
this.#storage[key] = typeof value !== "string" ? JSON.stringify(value) : value;
|
|
750
|
-
}
|
|
751
|
-
remove(key) {
|
|
752
|
-
delete this.#storage[key];
|
|
753
|
-
}
|
|
754
|
-
keys() {
|
|
755
|
-
return Object.keys(this.#storage);
|
|
756
|
-
}
|
|
757
|
-
clear() {
|
|
758
|
-
this.#storage = {};
|
|
759
|
-
}
|
|
760
|
-
};
|
|
761
|
-
|
|
762
|
-
// src/core/storage/local-storage.ts
|
|
763
|
-
var LocalStorage = class {
|
|
764
|
-
#storage = globalThis.localStorage;
|
|
765
|
-
get(key) {
|
|
766
|
-
return this.#storage.getItem(key);
|
|
767
|
-
}
|
|
768
|
-
set(key, value) {
|
|
769
|
-
this.#storage.setItem(key, typeof value !== "string" ? JSON.stringify(value) : value);
|
|
770
|
-
}
|
|
771
|
-
keys() {
|
|
772
|
-
return Object.keys(this.#storage);
|
|
773
|
-
}
|
|
774
|
-
remove(key) {
|
|
775
|
-
this.#storage.removeItem(key);
|
|
776
|
-
}
|
|
777
|
-
clear() {
|
|
778
|
-
this.#storage.clear();
|
|
779
|
-
}
|
|
780
|
-
};
|
|
781
|
-
|
|
782
|
-
// src/core/storage/index.ts
|
|
783
|
-
var storage;
|
|
784
|
-
function createStorage(storageType = "memory") {
|
|
785
|
-
if (!storage) {
|
|
786
|
-
let Factory;
|
|
787
|
-
if (storageType === "localStorage") {
|
|
788
|
-
Factory = LocalStorage;
|
|
789
|
-
} else if (storageType === "memory") {
|
|
790
|
-
Factory = MemoryStorage;
|
|
791
|
-
} else {
|
|
792
|
-
Factory = storageType;
|
|
793
|
-
}
|
|
794
|
-
storage = new Factory();
|
|
795
|
-
}
|
|
796
|
-
return storage;
|
|
797
|
-
}
|
|
798
|
-
var getStorage = createStorage;
|
|
799
|
-
|
|
800
742
|
// src/core/authorization/Event.ts
|
|
801
743
|
var Event = class {
|
|
802
744
|
constructor(name) {
|
|
@@ -932,30 +874,33 @@ var RedirectTransport = class _RedirectTransport {
|
|
|
932
874
|
}
|
|
933
875
|
};
|
|
934
876
|
|
|
935
|
-
// src/core/authorization/
|
|
936
|
-
|
|
937
|
-
const raw = getStorage().get(key) || "null";
|
|
938
|
-
let token2 = null;
|
|
939
|
-
try {
|
|
940
|
-
const parsed = JSON.parse(raw);
|
|
941
|
-
if (isToken(parsed)) {
|
|
942
|
-
token2 = parsed;
|
|
943
|
-
}
|
|
944
|
-
} catch (e) {
|
|
945
|
-
}
|
|
946
|
-
return token2;
|
|
947
|
-
}
|
|
948
|
-
var TokenLookup = class {
|
|
877
|
+
// src/core/authorization/TokenManager.ts
|
|
878
|
+
var TokenManager = class {
|
|
949
879
|
#manager;
|
|
950
880
|
constructor(options) {
|
|
951
881
|
this.#manager = options.manager;
|
|
952
882
|
}
|
|
953
|
-
|
|
954
|
-
|
|
883
|
+
/**
|
|
884
|
+
* Retrieve and parse an item from the storage.
|
|
885
|
+
*/
|
|
886
|
+
#getTokenFromStorage(key) {
|
|
887
|
+
const raw = this.#manager.storage.getItem(key) || "null";
|
|
888
|
+
let token2 = null;
|
|
889
|
+
try {
|
|
890
|
+
const parsed = JSON.parse(raw);
|
|
891
|
+
if (isToken(parsed)) {
|
|
892
|
+
token2 = parsed;
|
|
893
|
+
}
|
|
894
|
+
} catch (e) {
|
|
895
|
+
}
|
|
896
|
+
return token2;
|
|
955
897
|
}
|
|
956
898
|
#getTokenForService(service) {
|
|
957
899
|
const resourceServer = CONFIG.RESOURCE_SERVERS?.[service];
|
|
958
|
-
return this
|
|
900
|
+
return this.getByResourceServer(resourceServer);
|
|
901
|
+
}
|
|
902
|
+
getByResourceServer(resourceServer) {
|
|
903
|
+
return this.#getTokenFromStorage(`${this.#manager.storageKeyPrefix}${resourceServer}`);
|
|
959
904
|
}
|
|
960
905
|
get auth() {
|
|
961
906
|
return this.#getTokenForService(SERVICES.AUTH);
|
|
@@ -981,16 +926,16 @@ var TokenLookup = class {
|
|
|
981
926
|
gcs(endpoint) {
|
|
982
927
|
return this.getByResourceServer(endpoint);
|
|
983
928
|
}
|
|
984
|
-
getByResourceServer(resourceServer) {
|
|
985
|
-
return this.#getClientStorageEntry(resourceServer);
|
|
986
|
-
}
|
|
987
929
|
getAll() {
|
|
988
|
-
const entries =
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
930
|
+
const entries = Object.keys(this.#manager.storage).reduce(
|
|
931
|
+
(acc, key) => {
|
|
932
|
+
if (key.startsWith(this.#manager.storageKeyPrefix)) {
|
|
933
|
+
acc.push(this.#getTokenFromStorage(key));
|
|
934
|
+
}
|
|
935
|
+
return acc;
|
|
936
|
+
},
|
|
937
|
+
[]
|
|
938
|
+
);
|
|
994
939
|
return entries.filter(isToken);
|
|
995
940
|
}
|
|
996
941
|
/**
|
|
@@ -999,16 +944,19 @@ var TokenLookup = class {
|
|
|
999
944
|
add(token2) {
|
|
1000
945
|
const created = Date.now();
|
|
1001
946
|
const expires = created + token2.expires_in * 1e3;
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
947
|
+
this.#manager.storage.setItem(
|
|
948
|
+
`${this.#manager.storageKeyPrefix}${token2.resource_server}`,
|
|
949
|
+
JSON.stringify({
|
|
950
|
+
...token2,
|
|
951
|
+
/**
|
|
952
|
+
* Add metadata to the token to track when it was created and when it expires.
|
|
953
|
+
*/
|
|
954
|
+
__metadata: {
|
|
955
|
+
created,
|
|
956
|
+
expires
|
|
957
|
+
}
|
|
958
|
+
})
|
|
959
|
+
);
|
|
1012
960
|
if ("other_tokens" in token2) {
|
|
1013
961
|
token2.other_tokens?.forEach((t) => {
|
|
1014
962
|
this.add(t);
|
|
@@ -1030,10 +978,38 @@ var TokenLookup = class {
|
|
|
1030
978
|
}
|
|
1031
979
|
};
|
|
1032
980
|
|
|
981
|
+
// src/core/storage/memory.ts
|
|
982
|
+
var MemoryStorage = class {
|
|
983
|
+
#storage = {};
|
|
984
|
+
getItem(key) {
|
|
985
|
+
return this.#storage[key] !== void 0 ? this.#storage[key] : null;
|
|
986
|
+
}
|
|
987
|
+
setItem(key, value) {
|
|
988
|
+
this.#storage[key] = value;
|
|
989
|
+
}
|
|
990
|
+
removeItem(key) {
|
|
991
|
+
delete this.#storage[key];
|
|
992
|
+
}
|
|
993
|
+
key(index) {
|
|
994
|
+
return Object.keys(this.#storage)[index];
|
|
995
|
+
}
|
|
996
|
+
clear() {
|
|
997
|
+
this.#storage = {};
|
|
998
|
+
}
|
|
999
|
+
get length() {
|
|
1000
|
+
return Object.keys(this.#storage).length;
|
|
1001
|
+
}
|
|
1002
|
+
};
|
|
1003
|
+
|
|
1033
1004
|
// src/core/authorization/AuthorizationManager.ts
|
|
1005
|
+
var TRANSPORTS = {
|
|
1006
|
+
redirect: RedirectTransport
|
|
1007
|
+
// popup: PopupTransport,
|
|
1008
|
+
};
|
|
1034
1009
|
var DEFAULT_CONFIGURATION = {
|
|
1035
1010
|
useRefreshTokens: false,
|
|
1036
|
-
defaultScopes: "openid profile email"
|
|
1011
|
+
defaultScopes: "openid profile email",
|
|
1012
|
+
transport: "redirect"
|
|
1037
1013
|
};
|
|
1038
1014
|
var DEFAULT_HANDLE_ERROR_OPTIONS = {
|
|
1039
1015
|
execute: true,
|
|
@@ -1042,6 +1018,11 @@ var DEFAULT_HANDLE_ERROR_OPTIONS = {
|
|
|
1042
1018
|
var AuthorizationManager = class {
|
|
1043
1019
|
#transport;
|
|
1044
1020
|
configuration;
|
|
1021
|
+
/**
|
|
1022
|
+
* The storage system used by the `AuthorizationManager`.
|
|
1023
|
+
* @implements Storage
|
|
1024
|
+
*/
|
|
1025
|
+
storage;
|
|
1045
1026
|
#authenticated = false;
|
|
1046
1027
|
/**
|
|
1047
1028
|
* The `AuthorizationManager` is considered `authenticated` if it has a valid Globus Auth token.
|
|
@@ -1077,7 +1058,6 @@ var AuthorizationManager = class {
|
|
|
1077
1058
|
revoke: new Event("revoke")
|
|
1078
1059
|
};
|
|
1079
1060
|
constructor(configuration) {
|
|
1080
|
-
createStorage(configuration.storage || "localStorage");
|
|
1081
1061
|
if (!configuration.client) {
|
|
1082
1062
|
throw new Error("You must provide a `client` for your application.");
|
|
1083
1063
|
}
|
|
@@ -1087,6 +1067,7 @@ var AuthorizationManager = class {
|
|
|
1087
1067
|
...configuration,
|
|
1088
1068
|
scopes: [configuration.scopes ? configuration.scopes : "", scopes].filter((s) => s.length).join(" ")
|
|
1089
1069
|
};
|
|
1070
|
+
this.storage = configuration.storage || new MemoryStorage();
|
|
1090
1071
|
if (this.configuration.events) {
|
|
1091
1072
|
Object.entries(this.configuration.events).forEach(([name, callback]) => {
|
|
1092
1073
|
if (name in this.events) {
|
|
@@ -1094,7 +1075,7 @@ var AuthorizationManager = class {
|
|
|
1094
1075
|
}
|
|
1095
1076
|
});
|
|
1096
1077
|
}
|
|
1097
|
-
this.tokens = new
|
|
1078
|
+
this.tokens = new TokenManager({
|
|
1098
1079
|
manager: this
|
|
1099
1080
|
});
|
|
1100
1081
|
this.#checkAuthorizationState();
|
|
@@ -1166,7 +1147,7 @@ var AuthorizationManager = class {
|
|
|
1166
1147
|
* Retrieve the Globus Auth token managed by the instance.
|
|
1167
1148
|
*/
|
|
1168
1149
|
getGlobusAuthToken() {
|
|
1169
|
-
const entry =
|
|
1150
|
+
const entry = this.storage.getItem(`${this.storageKeyPrefix}${RESOURCE_SERVERS.AUTH}`);
|
|
1170
1151
|
return entry ? JSON.parse(entry) : null;
|
|
1171
1152
|
}
|
|
1172
1153
|
#checkAuthorizationState() {
|
|
@@ -1188,9 +1169,9 @@ var AuthorizationManager = class {
|
|
|
1188
1169
|
* This method **does not** emit the `revoke` event. If you need to emit the `revoke` event, use the `AuthorizationManager.revoke` method.
|
|
1189
1170
|
*/
|
|
1190
1171
|
reset() {
|
|
1191
|
-
|
|
1172
|
+
Object.keys(this.storage).forEach((key) => {
|
|
1192
1173
|
if (key.startsWith(this.storageKeyPrefix)) {
|
|
1193
|
-
|
|
1174
|
+
this.storage.removeItem(key);
|
|
1194
1175
|
}
|
|
1195
1176
|
});
|
|
1196
1177
|
this.authenticated = false;
|
|
@@ -1202,16 +1183,26 @@ var AuthorizationManager = class {
|
|
|
1202
1183
|
#withOfflineAccess(scopes) {
|
|
1203
1184
|
return `${scopes}${this.configuration.useRefreshTokens ? " offline_access" : ""}`;
|
|
1204
1185
|
}
|
|
1205
|
-
#buildTransport(
|
|
1206
|
-
const scopes =
|
|
1207
|
-
|
|
1186
|
+
#buildTransport(options) {
|
|
1187
|
+
const { scopes, ...overrides } = options ?? {};
|
|
1188
|
+
const TransportFactory = TRANSPORTS[this.configuration.transport || "redirect"];
|
|
1189
|
+
let scopesToRequest = this.#withOfflineAccess(scopes ?? (this.configuration.scopes || ""));
|
|
1190
|
+
if (this.storage instanceof MemoryStorage) {
|
|
1191
|
+
scopesToRequest = [
|
|
1192
|
+
// Use a Set to deduplicate the scopes.
|
|
1193
|
+
...new Set(
|
|
1194
|
+
scopesToRequest.split(" ").concat((this.configuration?.scopes || "").split(" "))
|
|
1195
|
+
)
|
|
1196
|
+
].join(" ");
|
|
1197
|
+
}
|
|
1198
|
+
return new TransportFactory({
|
|
1208
1199
|
client: this.configuration.client,
|
|
1209
1200
|
redirect: this.configuration.redirect,
|
|
1210
|
-
scopes,
|
|
1201
|
+
scopes: scopesToRequest,
|
|
1211
1202
|
...overrides,
|
|
1212
|
-
// @todo Decide if we want to include the `include_consented_scopes` parameter by default.
|
|
1213
1203
|
params: {
|
|
1214
|
-
// include_consented_scopes
|
|
1204
|
+
// @todo @todo Decide if we want to include the `include_consented_scopes` parameter by default.
|
|
1205
|
+
// include_consented_scopes: 'true',
|
|
1215
1206
|
...overrides?.params
|
|
1216
1207
|
}
|
|
1217
1208
|
});
|