@nhost/nhost-js 4.4.0 → 4.5.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.
@@ -922,6 +922,300 @@ const createAPIClient = (baseURL, chainFunctions = []) => {
922
922
  headers: res.headers
923
923
  };
924
924
  };
925
+ const getOpenIDConfiguration = async (options) => {
926
+ const url = `${baseURL}/.well-known/openid-configuration`;
927
+ const res = await fetch(url, {
928
+ ...options,
929
+ method: "GET",
930
+ headers: {
931
+ ...options?.headers
932
+ }
933
+ });
934
+ if (res.status >= 300) {
935
+ const responseBody2 = [412].includes(res.status) ? null : await res.text();
936
+ const payload2 = responseBody2 ? JSON.parse(responseBody2) : {};
937
+ throw new FetchError(payload2, res.status, res.headers);
938
+ }
939
+ const responseBody = [204, 205, 304].includes(res.status) ? null : await res.text();
940
+ const payload = responseBody ? JSON.parse(responseBody) : {};
941
+ return {
942
+ body: payload,
943
+ status: res.status,
944
+ headers: res.headers
945
+ };
946
+ };
947
+ const getOAuthAuthorizationServer = async (options) => {
948
+ const url = `${baseURL}/.well-known/oauth-authorization-server`;
949
+ const res = await fetch(url, {
950
+ ...options,
951
+ method: "GET",
952
+ headers: {
953
+ ...options?.headers
954
+ }
955
+ });
956
+ if (res.status >= 300) {
957
+ const responseBody2 = [412].includes(res.status) ? null : await res.text();
958
+ const payload2 = responseBody2 ? JSON.parse(responseBody2) : {};
959
+ throw new FetchError(payload2, res.status, res.headers);
960
+ }
961
+ const responseBody = [204, 205, 304].includes(res.status) ? null : await res.text();
962
+ const payload = responseBody ? JSON.parse(responseBody) : {};
963
+ return {
964
+ body: payload,
965
+ status: res.status,
966
+ headers: res.headers
967
+ };
968
+ };
969
+ const oauth2AuthorizeURL = (params) => {
970
+ const encodedParameters = params && Object.entries(params).flatMap(([key, value]) => {
971
+ const stringValue = Array.isArray(value) ? value.join(",") : typeof value === "object" && value !== null ? JSON.stringify(value) : String(value);
972
+ return [`${key}=${encodeURIComponent(stringValue)}`];
973
+ }).join("&");
974
+ const url = encodedParameters ? `${baseURL}/oauth2/authorize?${encodedParameters}` : `${baseURL}/oauth2/authorize`;
975
+ return url;
976
+ };
977
+ const oauth2AuthorizePostURL = () => {
978
+ const url = `${baseURL}/oauth2/authorize`;
979
+ return url;
980
+ };
981
+ const oauth2Token = async (body, options) => {
982
+ const url = `${baseURL}/oauth2/token`;
983
+ const params = new URLSearchParams();
984
+ if (body["grant_type"] !== void 0) {
985
+ params.append("grant_type", String(body["grant_type"]));
986
+ }
987
+ if (body["code"] !== void 0) {
988
+ params.append("code", String(body["code"]));
989
+ }
990
+ if (body["redirect_uri"] !== void 0) {
991
+ params.append("redirect_uri", String(body["redirect_uri"]));
992
+ }
993
+ if (body["client_id"] !== void 0) {
994
+ params.append("client_id", String(body["client_id"]));
995
+ }
996
+ if (body["client_secret"] !== void 0) {
997
+ params.append("client_secret", String(body["client_secret"]));
998
+ }
999
+ if (body["code_verifier"] !== void 0) {
1000
+ params.append("code_verifier", String(body["code_verifier"]));
1001
+ }
1002
+ if (body["refresh_token"] !== void 0) {
1003
+ params.append("refresh_token", String(body["refresh_token"]));
1004
+ }
1005
+ if (body["resource"] !== void 0) {
1006
+ params.append("resource", String(body["resource"]));
1007
+ }
1008
+ const res = await fetch(url, {
1009
+ ...options,
1010
+ method: "POST",
1011
+ headers: {
1012
+ "Content-Type": "application/x-www-form-urlencoded",
1013
+ ...options?.headers
1014
+ },
1015
+ body: params.toString()
1016
+ });
1017
+ if (res.status >= 300) {
1018
+ const responseBody2 = [412].includes(res.status) ? null : await res.text();
1019
+ const payload2 = responseBody2 ? JSON.parse(responseBody2) : {};
1020
+ throw new FetchError(payload2, res.status, res.headers);
1021
+ }
1022
+ const responseBody = [204, 205, 304].includes(res.status) ? null : await res.text();
1023
+ const payload = responseBody ? JSON.parse(responseBody) : {};
1024
+ return {
1025
+ body: payload,
1026
+ status: res.status,
1027
+ headers: res.headers
1028
+ };
1029
+ };
1030
+ const oauth2UserinfoGet = async (options) => {
1031
+ const url = `${baseURL}/oauth2/userinfo`;
1032
+ const res = await fetch(url, {
1033
+ ...options,
1034
+ method: "GET",
1035
+ headers: {
1036
+ ...options?.headers
1037
+ }
1038
+ });
1039
+ if (res.status >= 300) {
1040
+ const responseBody2 = [412].includes(res.status) ? null : await res.text();
1041
+ const payload2 = responseBody2 ? JSON.parse(responseBody2) : {};
1042
+ throw new FetchError(payload2, res.status, res.headers);
1043
+ }
1044
+ const responseBody = [204, 205, 304].includes(res.status) ? null : await res.text();
1045
+ const payload = responseBody ? JSON.parse(responseBody) : {};
1046
+ return {
1047
+ body: payload,
1048
+ status: res.status,
1049
+ headers: res.headers
1050
+ };
1051
+ };
1052
+ const oauth2UserinfoPost = async (options) => {
1053
+ const url = `${baseURL}/oauth2/userinfo`;
1054
+ const res = await fetch(url, {
1055
+ ...options,
1056
+ method: "POST",
1057
+ headers: {
1058
+ ...options?.headers
1059
+ }
1060
+ });
1061
+ if (res.status >= 300) {
1062
+ const responseBody2 = [412].includes(res.status) ? null : await res.text();
1063
+ const payload2 = responseBody2 ? JSON.parse(responseBody2) : {};
1064
+ throw new FetchError(payload2, res.status, res.headers);
1065
+ }
1066
+ const responseBody = [204, 205, 304].includes(res.status) ? null : await res.text();
1067
+ const payload = responseBody ? JSON.parse(responseBody) : {};
1068
+ return {
1069
+ body: payload,
1070
+ status: res.status,
1071
+ headers: res.headers
1072
+ };
1073
+ };
1074
+ const oauth2Jwks = async (options) => {
1075
+ const url = `${baseURL}/oauth2/jwks`;
1076
+ const res = await fetch(url, {
1077
+ ...options,
1078
+ method: "GET",
1079
+ headers: {
1080
+ ...options?.headers
1081
+ }
1082
+ });
1083
+ if (res.status >= 300) {
1084
+ const responseBody2 = [412].includes(res.status) ? null : await res.text();
1085
+ const payload2 = responseBody2 ? JSON.parse(responseBody2) : {};
1086
+ throw new FetchError(payload2, res.status, res.headers);
1087
+ }
1088
+ const responseBody = [204, 205, 304].includes(res.status) ? null : await res.text();
1089
+ const payload = responseBody ? JSON.parse(responseBody) : {};
1090
+ return {
1091
+ body: payload,
1092
+ status: res.status,
1093
+ headers: res.headers
1094
+ };
1095
+ };
1096
+ const oauth2Revoke = async (body, options) => {
1097
+ const url = `${baseURL}/oauth2/revoke`;
1098
+ const params = new URLSearchParams();
1099
+ if (body["token"] !== void 0) {
1100
+ params.append("token", String(body["token"]));
1101
+ }
1102
+ if (body["token_type_hint"] !== void 0) {
1103
+ params.append("token_type_hint", String(body["token_type_hint"]));
1104
+ }
1105
+ if (body["client_id"] !== void 0) {
1106
+ params.append("client_id", String(body["client_id"]));
1107
+ }
1108
+ if (body["client_secret"] !== void 0) {
1109
+ params.append("client_secret", String(body["client_secret"]));
1110
+ }
1111
+ const res = await fetch(url, {
1112
+ ...options,
1113
+ method: "POST",
1114
+ headers: {
1115
+ "Content-Type": "application/x-www-form-urlencoded",
1116
+ ...options?.headers
1117
+ },
1118
+ body: params.toString()
1119
+ });
1120
+ if (res.status >= 300) {
1121
+ const responseBody = [412].includes(res.status) ? null : await res.text();
1122
+ const payload2 = responseBody ? JSON.parse(responseBody) : {};
1123
+ throw new FetchError(payload2, res.status, res.headers);
1124
+ }
1125
+ const payload = void 0;
1126
+ return {
1127
+ body: payload,
1128
+ status: res.status,
1129
+ headers: res.headers
1130
+ };
1131
+ };
1132
+ const oauth2Introspect = async (body, options) => {
1133
+ const url = `${baseURL}/oauth2/introspect`;
1134
+ const params = new URLSearchParams();
1135
+ if (body["token"] !== void 0) {
1136
+ params.append("token", String(body["token"]));
1137
+ }
1138
+ if (body["token_type_hint"] !== void 0) {
1139
+ params.append("token_type_hint", String(body["token_type_hint"]));
1140
+ }
1141
+ if (body["client_id"] !== void 0) {
1142
+ params.append("client_id", String(body["client_id"]));
1143
+ }
1144
+ if (body["client_secret"] !== void 0) {
1145
+ params.append("client_secret", String(body["client_secret"]));
1146
+ }
1147
+ const res = await fetch(url, {
1148
+ ...options,
1149
+ method: "POST",
1150
+ headers: {
1151
+ "Content-Type": "application/x-www-form-urlencoded",
1152
+ ...options?.headers
1153
+ },
1154
+ body: params.toString()
1155
+ });
1156
+ if (res.status >= 300) {
1157
+ const responseBody2 = [412].includes(res.status) ? null : await res.text();
1158
+ const payload2 = responseBody2 ? JSON.parse(responseBody2) : {};
1159
+ throw new FetchError(payload2, res.status, res.headers);
1160
+ }
1161
+ const responseBody = [204, 205, 304].includes(res.status) ? null : await res.text();
1162
+ const payload = responseBody ? JSON.parse(responseBody) : {};
1163
+ return {
1164
+ body: payload,
1165
+ status: res.status,
1166
+ headers: res.headers
1167
+ };
1168
+ };
1169
+ const oauth2LoginGet = async (params, options) => {
1170
+ const encodedParameters = params && Object.entries(params).flatMap(([key, value]) => {
1171
+ const stringValue = Array.isArray(value) ? value.join(",") : typeof value === "object" && value !== null ? JSON.stringify(value) : String(value);
1172
+ return [`${key}=${encodeURIComponent(stringValue)}`];
1173
+ }).join("&");
1174
+ const url = encodedParameters ? `${baseURL}/oauth2/login?${encodedParameters}` : `${baseURL}/oauth2/login`;
1175
+ const res = await fetch(url, {
1176
+ ...options,
1177
+ method: "GET",
1178
+ headers: {
1179
+ ...options?.headers
1180
+ }
1181
+ });
1182
+ if (res.status >= 300) {
1183
+ const responseBody2 = [412].includes(res.status) ? null : await res.text();
1184
+ const payload2 = responseBody2 ? JSON.parse(responseBody2) : {};
1185
+ throw new FetchError(payload2, res.status, res.headers);
1186
+ }
1187
+ const responseBody = [204, 205, 304].includes(res.status) ? null : await res.text();
1188
+ const payload = responseBody ? JSON.parse(responseBody) : {};
1189
+ return {
1190
+ body: payload,
1191
+ status: res.status,
1192
+ headers: res.headers
1193
+ };
1194
+ };
1195
+ const oauth2LoginPost = async (body, options) => {
1196
+ const url = `${baseURL}/oauth2/login`;
1197
+ const res = await fetch(url, {
1198
+ ...options,
1199
+ method: "POST",
1200
+ headers: {
1201
+ "Content-Type": "application/json",
1202
+ ...options?.headers
1203
+ },
1204
+ body: JSON.stringify(body)
1205
+ });
1206
+ if (res.status >= 300) {
1207
+ const responseBody2 = [412].includes(res.status) ? null : await res.text();
1208
+ const payload2 = responseBody2 ? JSON.parse(responseBody2) : {};
1209
+ throw new FetchError(payload2, res.status, res.headers);
1210
+ }
1211
+ const responseBody = [204, 205, 304].includes(res.status) ? null : await res.text();
1212
+ const payload = responseBody ? JSON.parse(responseBody) : {};
1213
+ return {
1214
+ body: payload,
1215
+ status: res.status,
1216
+ headers: res.headers
1217
+ };
1218
+ };
925
1219
  return {
926
1220
  baseURL,
927
1221
  pushChainFunction,
@@ -964,7 +1258,19 @@ const createAPIClient = (baseURL, chainFunctions = []) => {
964
1258
  addSecurityKey,
965
1259
  verifyAddSecurityKey,
966
1260
  verifyTicketURL,
967
- getVersion
1261
+ getVersion,
1262
+ getOpenIDConfiguration,
1263
+ getOAuthAuthorizationServer,
1264
+ oauth2AuthorizeURL,
1265
+ oauth2AuthorizePostURL,
1266
+ oauth2Token,
1267
+ oauth2UserinfoGet,
1268
+ oauth2UserinfoPost,
1269
+ oauth2Jwks,
1270
+ oauth2Revoke,
1271
+ oauth2Introspect,
1272
+ oauth2LoginGet,
1273
+ oauth2LoginPost
968
1274
  };
969
1275
  };
970
1276
  export {