@nhost/nhost-js 1.5.2 → 1.6.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/clients/auth.d.ts +7 -0
- package/dist/clients/auth.d.ts.map +1 -0
- package/dist/clients/functions.d.ts +6 -1
- package/dist/clients/functions.d.ts.map +1 -1
- package/dist/clients/graphql.d.ts +5 -1
- package/dist/clients/graphql.d.ts.map +1 -1
- package/dist/clients/index.d.ts +3 -0
- package/dist/clients/index.d.ts.map +1 -1
- package/dist/{core/nhost-client.d.ts → clients/nhost.d.ts} +4 -3
- package/dist/clients/nhost.d.ts.map +1 -0
- package/dist/clients/storage.d.ts +7 -0
- package/dist/clients/storage.d.ts.map +1 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +0 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +168 -178
- package/dist/index.esm.js.map +1 -1
- package/dist/utils/helpers.d.ts +1 -1
- package/dist/utils/helpers.d.ts.map +1 -1
- package/dist/utils/types.d.ts +13 -7
- package/dist/utils/types.d.ts.map +1 -1
- package/package.json +7 -6
- package/umd/nhost-js.umd.js +8 -7
- package/umd/nhost-js.umd.js.map +1 -1
- package/dist/core/index.d.ts +0 -3
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/nhost-client.d.ts.map +0 -1
package/dist/index.esm.js
CHANGED
|
@@ -1,225 +1,215 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
var g = Object.defineProperty;
|
|
2
|
+
var A = (t, e, r) => e in t ? g(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
|
|
3
|
+
var o = (t, e, r) => (A(t, typeof e != "symbol" ? e + "" : e, r), r);
|
|
4
|
+
import { HasuraAuthClient as U } from "@nhost/hasura-auth-js";
|
|
5
|
+
import T from "axios";
|
|
6
|
+
import { print as b } from "graphql";
|
|
7
|
+
import { HasuraStorageClient as m } from "@nhost/hasura-storage-js";
|
|
8
|
+
const w = /^((?<protocol>http[s]?):\/\/)?(?<host>localhost)(:(?<port>\d+))?$/;
|
|
9
|
+
function f(t, e) {
|
|
10
|
+
const { backendUrl: r, subdomain: n, region: a } = t;
|
|
11
|
+
if (r)
|
|
12
|
+
return `${r}/v1/${e}`;
|
|
13
|
+
if (!n)
|
|
14
|
+
throw new Error("Either `backendUrl` or `subdomain` must be set.");
|
|
15
|
+
const s = n.match(w);
|
|
16
|
+
if (s != null && s.groups) {
|
|
17
|
+
const { protocol: u = "http", host: h, port: i = 1337 } = s.groups, l = E(e);
|
|
18
|
+
return l || `${u}://${h}:${i}/v1/${e}`;
|
|
19
|
+
}
|
|
20
|
+
if (!a)
|
|
21
|
+
throw new Error('`region` must be set when using a `subdomain` other than "localhost".');
|
|
22
|
+
return `https://${n}.${e}.${a}.nhost.run/v1`;
|
|
23
|
+
}
|
|
24
|
+
function S() {
|
|
25
|
+
return typeof window < "u";
|
|
26
|
+
}
|
|
27
|
+
function v() {
|
|
28
|
+
return typeof process < "u" && process.env;
|
|
29
|
+
}
|
|
30
|
+
function E(t) {
|
|
31
|
+
return S() || !v() ? null : process.env[`NHOST_${t.toUpperCase()}_URL`];
|
|
32
|
+
}
|
|
33
|
+
function q(t) {
|
|
34
|
+
const e = "subdomain" in t || "backendUrl" in t ? f(t, "auth") : t.authUrl;
|
|
35
|
+
if (!e)
|
|
36
|
+
throw new Error("Please provide `subdomain` or `authUrl`.");
|
|
37
|
+
return new U({ url: e, ...t });
|
|
38
|
+
}
|
|
39
|
+
function C(t) {
|
|
40
|
+
const e = "subdomain" in t || "backendUrl" in t ? f(t, "functions") : t.functionsUrl;
|
|
41
|
+
if (!e)
|
|
42
|
+
throw new Error("Please provide `subdomain` or `functionsUrl`.");
|
|
43
|
+
return new $({ url: e, ...t });
|
|
44
|
+
}
|
|
45
|
+
class $ {
|
|
46
|
+
constructor(e) {
|
|
47
|
+
o(this, "url");
|
|
48
|
+
o(this, "instance");
|
|
49
|
+
o(this, "accessToken");
|
|
50
|
+
o(this, "adminSecret");
|
|
51
|
+
const { url: r, adminSecret: n } = e;
|
|
52
|
+
this.url = r, this.accessToken = null, this.adminSecret = n, this.instance = T.create({
|
|
53
|
+
baseURL: r
|
|
12
54
|
});
|
|
13
55
|
}
|
|
14
|
-
async call(
|
|
15
|
-
const
|
|
56
|
+
async call(e, r, n) {
|
|
57
|
+
const a = {
|
|
16
58
|
...this.generateAccessTokenHeaders(),
|
|
17
|
-
...
|
|
59
|
+
...n == null ? void 0 : n.headers
|
|
18
60
|
};
|
|
19
|
-
let
|
|
61
|
+
let s;
|
|
20
62
|
try {
|
|
21
|
-
|
|
22
|
-
} catch (
|
|
23
|
-
if (
|
|
24
|
-
return { res: null, error };
|
|
25
|
-
}
|
|
63
|
+
s = await this.instance.post(e, r, { ...n, headers: a });
|
|
64
|
+
} catch (u) {
|
|
65
|
+
if (u instanceof Error)
|
|
66
|
+
return { res: null, error: u };
|
|
26
67
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
return { res, error: null };
|
|
68
|
+
return s ? { res: s, error: null } : {
|
|
69
|
+
res: null,
|
|
70
|
+
error: new Error("Unable to make post request to funtion")
|
|
71
|
+
};
|
|
34
72
|
}
|
|
35
|
-
setAccessToken(
|
|
36
|
-
if (!
|
|
73
|
+
setAccessToken(e) {
|
|
74
|
+
if (!e) {
|
|
37
75
|
this.accessToken = null;
|
|
38
76
|
return;
|
|
39
77
|
}
|
|
40
|
-
this.accessToken =
|
|
78
|
+
this.accessToken = e;
|
|
41
79
|
}
|
|
42
80
|
generateAccessTokenHeaders() {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
if (this.accessToken) {
|
|
49
|
-
return {
|
|
50
|
-
Authorization: `Bearer ${this.accessToken}`
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
return {};
|
|
81
|
+
return this.adminSecret ? {
|
|
82
|
+
"x-hasura-admin-secret": this.adminSecret
|
|
83
|
+
} : this.accessToken ? {
|
|
84
|
+
Authorization: `Bearer ${this.accessToken}`
|
|
85
|
+
} : {};
|
|
54
86
|
}
|
|
55
87
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
88
|
+
function y(t) {
|
|
89
|
+
const e = "subdomain" in t || "backendUrl" in t ? f(t, "graphql") : t.graphqlUrl;
|
|
90
|
+
if (!e)
|
|
91
|
+
throw new Error("Please provide `subdomain` or `graphqlUrl`.");
|
|
92
|
+
return new H({ url: e, ...t });
|
|
93
|
+
}
|
|
94
|
+
class H {
|
|
95
|
+
constructor(e) {
|
|
96
|
+
o(this, "url");
|
|
97
|
+
o(this, "instance");
|
|
98
|
+
o(this, "accessToken");
|
|
99
|
+
o(this, "adminSecret");
|
|
100
|
+
const { url: r, adminSecret: n } = e;
|
|
101
|
+
this.url = r, this.accessToken = null, this.adminSecret = n, this.instance = T.create({
|
|
102
|
+
baseURL: r
|
|
64
103
|
});
|
|
65
104
|
}
|
|
66
|
-
async request(
|
|
67
|
-
const
|
|
105
|
+
async request(e, r, n) {
|
|
106
|
+
const a = {
|
|
68
107
|
...this.generateAccessTokenHeaders(),
|
|
69
|
-
...
|
|
108
|
+
...n == null ? void 0 : n.headers
|
|
70
109
|
};
|
|
71
110
|
try {
|
|
72
|
-
const
|
|
73
|
-
const res = await this.instance.post(
|
|
111
|
+
const s = "", h = (await this.instance.post(
|
|
74
112
|
"",
|
|
75
113
|
{
|
|
76
|
-
operationName:
|
|
77
|
-
query: typeof
|
|
78
|
-
variables
|
|
114
|
+
operationName: s || void 0,
|
|
115
|
+
query: typeof e == "string" ? e : b(e),
|
|
116
|
+
variables: r
|
|
79
117
|
},
|
|
80
|
-
{ ...
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return {
|
|
92
|
-
data: null,
|
|
93
|
-
error: new Error("incorrect response data from GraphQL server")
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
return { data, error: null };
|
|
97
|
-
} catch (error) {
|
|
98
|
-
if (error instanceof Error) {
|
|
99
|
-
return { data: null, error };
|
|
100
|
-
}
|
|
101
|
-
console.error(error);
|
|
102
|
-
return {
|
|
118
|
+
{ ...n, headers: a }
|
|
119
|
+
)).data, { data: i } = h;
|
|
120
|
+
return h.errors ? {
|
|
121
|
+
data: null,
|
|
122
|
+
error: h.errors
|
|
123
|
+
} : typeof i != "object" || Array.isArray(i) || i === null ? {
|
|
124
|
+
data: null,
|
|
125
|
+
error: new Error("incorrect response data from GraphQL server")
|
|
126
|
+
} : { data: i, error: null };
|
|
127
|
+
} catch (s) {
|
|
128
|
+
return s instanceof Error ? { data: null, error: s } : (console.error(s), {
|
|
103
129
|
data: null,
|
|
104
130
|
error: new Error("Unable to get do GraphQL request")
|
|
105
|
-
};
|
|
131
|
+
});
|
|
106
132
|
}
|
|
107
133
|
}
|
|
108
134
|
getUrl() {
|
|
109
135
|
return this.url;
|
|
110
136
|
}
|
|
111
|
-
setAccessToken(
|
|
112
|
-
if (!
|
|
137
|
+
setAccessToken(e) {
|
|
138
|
+
if (!e) {
|
|
113
139
|
this.accessToken = null;
|
|
114
140
|
return;
|
|
115
141
|
}
|
|
116
|
-
this.accessToken =
|
|
142
|
+
this.accessToken = e;
|
|
117
143
|
}
|
|
118
144
|
generateAccessTokenHeaders() {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
if (this.accessToken) {
|
|
125
|
-
return {
|
|
126
|
-
Authorization: `Bearer ${this.accessToken}`
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
return {};
|
|
145
|
+
return this.adminSecret ? {
|
|
146
|
+
"x-hasura-admin-secret": this.adminSecret
|
|
147
|
+
} : this.accessToken ? {
|
|
148
|
+
Authorization: `Bearer ${this.accessToken}`
|
|
149
|
+
} : {};
|
|
130
150
|
}
|
|
131
151
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
if (backendUrl) {
|
|
139
|
-
return `${backendUrl}/v1/${service}`;
|
|
140
|
-
}
|
|
141
|
-
if (!subdomain) {
|
|
142
|
-
throw new Error("`subdomain` must be set if `backendUrl` is not set.");
|
|
143
|
-
}
|
|
144
|
-
const subdomainLocalhostFound = subdomain.match(LOCALHOST_REGEX);
|
|
145
|
-
if (subdomainLocalhostFound && subdomainLocalhostFound.length > 0) {
|
|
146
|
-
const localhostFound = subdomainLocalhostFound[0];
|
|
147
|
-
if (localhostFound === "localhost") {
|
|
148
|
-
return `http://localhost:1337/v1/${service}`;
|
|
149
|
-
}
|
|
150
|
-
return `http://${localhostFound}/v1/${service}`;
|
|
151
|
-
}
|
|
152
|
-
if (!region) {
|
|
153
|
-
throw new Error('`region` must be set when using a `subdomain` other than "localhost".');
|
|
154
|
-
}
|
|
155
|
-
return `https://${subdomain}.${service}.${region}.nhost.run/v1`;
|
|
152
|
+
function N(t) {
|
|
153
|
+
const e = "subdomain" in t || "backendUrl" in t ? f(t, "storage") : t.storageUrl;
|
|
154
|
+
if (!e)
|
|
155
|
+
throw new Error("Please provide `subdomain` or `storageUrl`.");
|
|
156
|
+
return new m({ url: e, ...t });
|
|
156
157
|
}
|
|
157
|
-
|
|
158
|
+
const B = (t) => new _(t);
|
|
159
|
+
class _ {
|
|
158
160
|
constructor({
|
|
159
|
-
refreshIntervalTime,
|
|
160
|
-
clientStorageGetter,
|
|
161
|
-
clientStorageSetter,
|
|
162
|
-
clientStorage,
|
|
163
|
-
clientStorageType,
|
|
164
|
-
autoRefreshToken,
|
|
165
|
-
autoSignIn,
|
|
166
|
-
adminSecret,
|
|
167
|
-
devTools,
|
|
168
|
-
start =
|
|
169
|
-
...
|
|
161
|
+
refreshIntervalTime: e,
|
|
162
|
+
clientStorageGetter: r,
|
|
163
|
+
clientStorageSetter: n,
|
|
164
|
+
clientStorage: a,
|
|
165
|
+
clientStorageType: s,
|
|
166
|
+
autoRefreshToken: u,
|
|
167
|
+
autoSignIn: h,
|
|
168
|
+
adminSecret: i,
|
|
169
|
+
devTools: l,
|
|
170
|
+
start: p = !0,
|
|
171
|
+
...d
|
|
170
172
|
}) {
|
|
171
|
-
|
|
172
|
-
this
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
adminSecret
|
|
194
|
-
});
|
|
195
|
-
this.storage.setAccessToken(this.auth.getAccessToken());
|
|
196
|
-
this.functions.setAccessToken(this.auth.getAccessToken());
|
|
197
|
-
this.graphql.setAccessToken(this.auth.getAccessToken());
|
|
198
|
-
(_a = this.auth.client) == null ? void 0 : _a.onStart(() => {
|
|
199
|
-
this.auth.onAuthStateChanged((_event, session) => {
|
|
200
|
-
if (_event === "SIGNED_OUT") {
|
|
201
|
-
this.storage.setAccessToken(void 0);
|
|
202
|
-
this.functions.setAccessToken(void 0);
|
|
203
|
-
this.graphql.setAccessToken(void 0);
|
|
204
|
-
}
|
|
173
|
+
o(this, "auth");
|
|
174
|
+
o(this, "storage");
|
|
175
|
+
o(this, "functions");
|
|
176
|
+
o(this, "graphql");
|
|
177
|
+
o(this, "_adminSecret");
|
|
178
|
+
o(this, "devTools");
|
|
179
|
+
var k;
|
|
180
|
+
this.auth = q({
|
|
181
|
+
refreshIntervalTime: e,
|
|
182
|
+
clientStorageGetter: r,
|
|
183
|
+
clientStorageSetter: n,
|
|
184
|
+
clientStorage: a,
|
|
185
|
+
clientStorageType: s,
|
|
186
|
+
autoRefreshToken: u,
|
|
187
|
+
autoSignIn: h,
|
|
188
|
+
start: p,
|
|
189
|
+
...d
|
|
190
|
+
}), this.storage = N({ adminSecret: i, ...d }), this.functions = C({ adminSecret: i, ...d }), this.graphql = y({ adminSecret: i, ...d }), this.storage.setAccessToken(this.auth.getAccessToken()), this.functions.setAccessToken(this.auth.getAccessToken()), this.graphql.setAccessToken(this.auth.getAccessToken()), (k = this.auth.client) == null || k.onStart(() => {
|
|
191
|
+
this.auth.onAuthStateChanged((c, G) => {
|
|
192
|
+
c === "SIGNED_OUT" && (this.storage.setAccessToken(void 0), this.functions.setAccessToken(void 0), this.graphql.setAccessToken(void 0));
|
|
193
|
+
}), this.auth.onTokenChanged((c) => {
|
|
194
|
+
this.storage.setAccessToken(c == null ? void 0 : c.accessToken), this.functions.setAccessToken(c == null ? void 0 : c.accessToken), this.graphql.setAccessToken(c == null ? void 0 : c.accessToken);
|
|
205
195
|
});
|
|
206
|
-
|
|
207
|
-
this.storage.setAccessToken(session == null ? void 0 : session.accessToken);
|
|
208
|
-
this.functions.setAccessToken(session == null ? void 0 : session.accessToken);
|
|
209
|
-
this.graphql.setAccessToken(session == null ? void 0 : session.accessToken);
|
|
210
|
-
});
|
|
211
|
-
});
|
|
212
|
-
this._adminSecret = adminSecret;
|
|
213
|
-
this.devTools = devTools;
|
|
196
|
+
}), this._adminSecret = i, this.devTools = l;
|
|
214
197
|
}
|
|
215
198
|
get adminSecret() {
|
|
216
199
|
return this._adminSecret;
|
|
217
200
|
}
|
|
218
|
-
set adminSecret(
|
|
219
|
-
this._adminSecret =
|
|
220
|
-
this.storage.setAdminSecret(newValue);
|
|
201
|
+
set adminSecret(e) {
|
|
202
|
+
this._adminSecret = e, this.storage.setAdminSecret(e);
|
|
221
203
|
}
|
|
222
204
|
}
|
|
223
|
-
|
|
224
|
-
|
|
205
|
+
export {
|
|
206
|
+
_ as NhostClient,
|
|
207
|
+
$ as NhostFunctionsClient,
|
|
208
|
+
H as NhostGraphqlClient,
|
|
209
|
+
q as createAuthClient,
|
|
210
|
+
C as createFunctionsClient,
|
|
211
|
+
y as createGraphqlClient,
|
|
212
|
+
B as createNhostClient,
|
|
213
|
+
N as createStorageClient
|
|
214
|
+
};
|
|
225
215
|
//# sourceMappingURL=index.esm.js.map
|
package/dist/index.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":["../src/clients/functions.ts","../src/clients/graphql.ts","../src/utils/helpers.ts","../src/core/nhost-client.ts","../src/index.ts"],"sourcesContent":["import axios, { AxiosInstance, AxiosRequestConfig, AxiosRequestHeaders, AxiosResponse } from 'axios'\n\nimport { FunctionCallResponse } from '../utils/types'\nexport interface NhostFunctionsConstructorParams {\n /**\n * Serverless Functions endpoint.\n */\n url: string\n /**\n * Admin secret. When set, it is sent as an `x-hasura-admin-secret` header for all requests.\n */\n adminSecret?: string\n}\n\n/**\n * @alias Functions\n */\nexport class NhostFunctionsClient {\n private instance: AxiosInstance\n private accessToken: string | null\n private adminSecret?: string\n\n constructor(params: NhostFunctionsConstructorParams) {\n const { url, adminSecret } = params\n\n this.accessToken = null\n this.adminSecret = adminSecret\n this.instance = axios.create({\n baseURL: url\n })\n }\n\n /**\n * Use `nhost.functions.call` to call (sending a POST request to) a serverless function.\n *\n * @example\n * ```ts\n * await nhost.functions.call('send-welcome-email', { email: 'joe@example.com', name: 'Joe Doe' })\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/call\n */\n async call<T = unknown, D = any>(\n url: string,\n data: D,\n config?: AxiosRequestConfig\n ): Promise<FunctionCallResponse<T>> {\n const headers = {\n ...this.generateAccessTokenHeaders(),\n ...config?.headers\n }\n\n let res\n try {\n res = await this.instance.post<T, AxiosResponse<T>, D>(url, data, { ...config, headers })\n } catch (error) {\n if (error instanceof Error) {\n return { res: null, error }\n }\n }\n\n if (!res) {\n return {\n res: null,\n error: new Error('Unable to make post request to funtion')\n }\n }\n\n return { res, error: null }\n }\n\n /**\n * Use `nhost.functions.setAccessToken` to a set an access token to be used in subsequent functions requests. Note that if you're signin in users with `nhost.auth.signIn()` the access token will be set automatically.\n *\n * @example\n * ```ts\n * nhost.functions.setAccessToken('some-access-token')\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/set-access-token\n */\n setAccessToken(accessToken: string | undefined) {\n if (!accessToken) {\n this.accessToken = null\n return\n }\n\n this.accessToken = accessToken\n }\n\n private generateAccessTokenHeaders(): AxiosRequestHeaders {\n if (this.adminSecret) {\n return {\n 'x-hasura-admin-secret': this.adminSecret\n }\n }\n if (this.accessToken) {\n return {\n Authorization: `Bearer ${this.accessToken}`\n }\n }\n return {}\n }\n}\n","import axios, { AxiosInstance, AxiosRequestConfig, AxiosRequestHeaders } from 'axios'\nimport { DocumentNode, print } from 'graphql'\n\nimport { GraphqlRequestResponse, GraphqlResponse } from '../utils/types'\n\nexport interface NhostGraphqlConstructorParams {\n /**\n * GraphQL endpoint.\n */\n url: string\n /**\n * Admin secret. When set, it is sent as an `x-hasura-admin-secret` header for all requests.\n */\n adminSecret?: string\n}\n\n/**\n * @alias GraphQL\n */\nexport class NhostGraphqlClient {\n private url: string\n private instance: AxiosInstance\n private accessToken: string | null\n private adminSecret?: string\n\n constructor(params: NhostGraphqlConstructorParams) {\n const { url, adminSecret } = params\n\n this.url = url\n this.accessToken = null\n this.adminSecret = adminSecret\n this.instance = axios.create({\n baseURL: url\n })\n }\n\n /**\n * Use `nhost.graphql.request` to send a GraphQL request. For more serious GraphQL usage we recommend using a GraphQL client such as Apollo Client (https://www.apollographql.com/docs/react).\n *\n * @example\n * ```ts\n * const CUSTOMERS = gql`\n * query {\n * customers {\n * id\n * name\n * }\n * }\n * `\n * const { data, error } = await nhost.graphql.request(CUSTOMERS)\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/graphql/request\n */\n async request<T = any, V = any>(\n document: string | DocumentNode,\n variables?: V,\n config?: AxiosRequestConfig\n ): Promise<GraphqlRequestResponse<T>> {\n // add auth headers if any\n const headers = {\n ...this.generateAccessTokenHeaders(),\n ...config?.headers\n }\n\n try {\n const operationName = ''\n const res = await this.instance.post<GraphqlResponse<T>>(\n '',\n {\n operationName: operationName || undefined,\n query: typeof document === 'string' ? document : print(document),\n variables\n },\n { ...config, headers }\n )\n\n const responseData = res.data\n const { data } = responseData\n\n if (responseData.errors) {\n return {\n data: null,\n error: responseData.errors\n }\n }\n\n if (typeof data !== 'object' || Array.isArray(data) || data === null) {\n return {\n data: null,\n error: new Error('incorrect response data from GraphQL server')\n }\n }\n\n return { data, error: null }\n } catch (error) {\n if (error instanceof Error) {\n return { data: null, error }\n }\n console.error(error)\n return {\n data: null,\n error: new Error('Unable to get do GraphQL request')\n }\n }\n }\n\n /**\n * Use `nhost.graphql.getUrl` to get the GraphQL URL.\n *\n * @example\n * ```ts\n * const url = nhost.graphql.getUrl();\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/graphql/get-url\n */\n getUrl(): string {\n return this.url\n }\n\n /**\n * Use `nhost.graphql.setAccessToken` to a set an access token to be used in subsequent graphql requests. Note that if you're signin in users with `nhost.auth.signIn()` the access token will be set automatically.\n *\n * @example\n * ```ts\n * nhost.graphql.setAccessToken('some-access-token')\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/graphql/set-access-token\n */\n setAccessToken(accessToken: string | undefined) {\n if (!accessToken) {\n this.accessToken = null\n return\n }\n\n this.accessToken = accessToken\n }\n\n private generateAccessTokenHeaders(): AxiosRequestHeaders {\n if (this.adminSecret) {\n return {\n 'x-hasura-admin-secret': this.adminSecret\n }\n }\n if (this.accessToken) {\n return {\n Authorization: `Bearer ${this.accessToken}`\n }\n }\n return {}\n }\n}\n","import { NhostClientConstructorParams } from './types'\n\nconst LOCALHOST_REGEX = /^localhost(:\\d+)*$/g\n\n/**\n * `backendUrl` should now be used only when self-hosting\n * `subdomain` and `region` should be used instead when using the Nhost platform\n * `\n * @param backendOrSubdomain\n * @param service\n * @returns\n */\nexport function urlFromParams(\n backendOrSubdomain: Pick<NhostClientConstructorParams, 'region' | 'subdomain' | 'backendUrl'>,\n service: string\n) {\n const { backendUrl, subdomain, region } = backendOrSubdomain\n\n if (!backendUrl && !subdomain) {\n throw new Error('Either `backendUrl` or `subdomain` must be set.')\n }\n\n if (backendUrl) {\n return `${backendUrl}/v1/${service}`\n }\n\n // to make TS happy\n if (!subdomain) {\n throw new Error('`subdomain` must be set if `backendUrl` is not set.')\n }\n\n // check if subdomain is localhost[:port]\n const subdomainLocalhostFound = subdomain.match(LOCALHOST_REGEX)\n if (subdomainLocalhostFound && subdomainLocalhostFound.length > 0) {\n const localhostFound = subdomainLocalhostFound[0]\n\n // no port specified, use standard port 1337\n if (localhostFound === 'localhost') {\n return `http://localhost:1337/v1/${service}`\n }\n\n // port specified\n return `http://${localhostFound}/v1/${service}`\n }\n\n if (!region) {\n throw new Error('`region` must be set when using a `subdomain` other than \"localhost\".')\n }\n\n return `https://${subdomain}.${service}.${region}.nhost.run/v1`\n}\n","import { HasuraAuthClient } from '@nhost/hasura-auth-js'\nimport { HasuraStorageClient } from '@nhost/hasura-storage-js'\n\nimport { NhostFunctionsClient } from '../clients/functions'\nimport { NhostGraphqlClient } from '../clients/graphql'\nimport { urlFromParams } from '../utils/helpers'\nimport { NhostClientConstructorParams } from '../utils/types'\nexport class NhostClient {\n auth: HasuraAuthClient\n storage: HasuraStorageClient\n functions: NhostFunctionsClient\n graphql: NhostGraphqlClient\n private _adminSecret?: string\n readonly devTools?: boolean\n\n /**\n * Nhost Client\n *\n * @example\n * ```ts\n * const nhost = new NhostClient({ subdomain, region });\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript\n */\n constructor({\n refreshIntervalTime,\n clientStorageGetter,\n clientStorageSetter,\n clientStorage,\n clientStorageType,\n autoRefreshToken,\n autoSignIn,\n adminSecret,\n devTools,\n start = true,\n ...urlParams\n }: NhostClientConstructorParams) {\n this.auth = new HasuraAuthClient({\n url: urlFromParams(urlParams, 'auth'),\n refreshIntervalTime,\n clientStorageGetter,\n clientStorageSetter,\n clientStorage,\n clientStorageType,\n autoRefreshToken,\n autoSignIn,\n start\n })\n\n this.storage = new HasuraStorageClient({\n url: urlFromParams(urlParams, 'storage'),\n adminSecret\n })\n\n this.functions = new NhostFunctionsClient({\n url: urlFromParams(urlParams, 'functions'),\n adminSecret\n })\n\n this.graphql = new NhostGraphqlClient({\n url: urlFromParams(urlParams, 'graphql'),\n adminSecret\n })\n\n // * Set current token if token is already accessable\n this.storage.setAccessToken(this.auth.getAccessToken())\n this.functions.setAccessToken(this.auth.getAccessToken())\n this.graphql.setAccessToken(this.auth.getAccessToken())\n\n this.auth.client?.onStart(() => {\n // * Set access token when signing out\n this.auth.onAuthStateChanged((_event, session) => {\n if (_event === 'SIGNED_OUT') {\n this.storage.setAccessToken(undefined)\n this.functions.setAccessToken(undefined)\n this.graphql.setAccessToken(undefined)\n }\n })\n\n // * Update access token for clients, including when signin in\n this.auth.onTokenChanged((session) => {\n this.storage.setAccessToken(session?.accessToken)\n this.functions.setAccessToken(session?.accessToken)\n this.graphql.setAccessToken(session?.accessToken)\n })\n })\n this._adminSecret = adminSecret\n this.devTools = devTools\n }\n\n get adminSecret(): string | undefined {\n return this._adminSecret\n }\n\n set adminSecret(newValue: string | undefined) {\n this._adminSecret = newValue\n this.storage.setAdminSecret(newValue)\n // TODO inconsistent API: storage can change admin secret, but functions/graphql cannot\n // this.functions.setAdminSecret(newValue)\n // this.graphql.setAdminSecret(newValue)\n }\n}\n","import { NhostClientConstructorParams } from './utils/types'\nimport { NhostClient } from './core'\n\nconst createClient = (config: NhostClientConstructorParams) => new NhostClient(config)\n\nexport * from './clients'\nexport * from './core'\nexport * from './utils/types'\nexport { createClient }\n"],"names":[],"mappings":";;;;AAiBO,MAAM,qBAAqB;AAAA,EAKhC,YAAY,QAAyC;AAC7C,UAAA,EAAE,KAAK,YAAgB,IAAA;AAE7B,SAAK,cAAc;AACnB,SAAK,cAAc;AACd,SAAA,WAAW,MAAM,OAAO;AAAA,MAC3B,SAAS;AAAA,IAAA,CACV;AAAA,EACH;AAAA,EAYA,MAAM,KACJ,KACA,MACA,QACkC;AAClC,UAAM,UAAU;AAAA,MACd,GAAG,KAAK,2BAA2B;AAAA,MACnC,GAAG,iCAAQ;AAAA,IAAA;AAGT,QAAA;AACA,QAAA;AACI,YAAA,MAAM,KAAK,SAAS,KAA6B,KAAK,MAAM,EAAE,GAAG,QAAQ,QAAA,CAAS;AAAA,aACjF;AACP,UAAI,iBAAiB,OAAO;AACnB,eAAA,EAAE,KAAK,MAAM;MACtB;AAAA,IACF;AAEA,QAAI,CAAC,KAAK;AACD,aAAA;AAAA,QACL,KAAK;AAAA,QACL,OAAO,IAAI,MAAM,wCAAwC;AAAA,MAAA;AAAA,IAE7D;AAEO,WAAA,EAAE,KAAK,OAAO;EACvB;AAAA,EAYA,eAAe,aAAiC;AAC9C,QAAI,CAAC,aAAa;AAChB,WAAK,cAAc;AACnB;AAAA,IACF;AAEA,SAAK,cAAc;AAAA,EACrB;AAAA,EAEQ,6BAAkD;AACxD,QAAI,KAAK,aAAa;AACb,aAAA;AAAA,QACL,yBAAyB,KAAK;AAAA,MAAA;AAAA,IAElC;AACA,QAAI,KAAK,aAAa;AACb,aAAA;AAAA,QACL,eAAe,UAAU,KAAK;AAAA,MAAA;AAAA,IAElC;AACA,WAAO;EACT;AACF;ACpFO,MAAM,mBAAmB;AAAA,EAM9B,YAAY,QAAuC;AAC3C,UAAA,EAAE,KAAK,YAAgB,IAAA;AAE7B,SAAK,MAAM;AACX,SAAK,cAAc;AACnB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Y,IAAI,qBAAqB;AAAA,MACxC,KAAK,cAAc,WAAW,WAAW;AAAA,MACzC;AAAA,IAAA,CACD;AAEI,SAAA,UAAU,IAAI,mBAAmB;AAAA,MACpC,KAAK,cAAc,WAAW,SAAS;AAAA,MACvC;AAAA,IAAA,CACD;AAGD,SAAK,QAAQ,eAAe,KAAK,KAAK,gBAAgB;AACtD,SAAK,UAAU,eAAe,KAAK,KAAK,gBAAgB;AACxD,SAAK,QAAQ,eAAe,KAAK,KAAK,gBAAgB;AAEjD,eAAA,KAAK,WAAL,mBAAa,QAAQ,MAAM;AAE9B,WAAK,KAAK,mBAAmB,CAAC,QAAQ,YAAY;AAChD,YAAI,WAAW,cAAc;AACtB,eAAA,QAAQ,eAAe,MAAS;AAChC,eAAA,UAAU,eAAe,MAAS;AAClC,eAAA,QAAQ,eAAe,MAAS;AAAA,QACvC;AAAA,MAAA,CACD;AAGI,WAAA,KAAK,eAAe,CAAC,YAAY;AAC/B,aAAA,QAAQ,eAAe,mCAAS,WAAW;AAC3C,aAAA,UAAU,eAAe,mCAAS,WAAW;AAC7C,aAAA,QAAQ,eAAe,mCAAS,WAAW;AAAA,MAAA,CACjD;AAAA,IAAA;AAEH,SAAK,eAAe;AACpB,SAAK,WAAW;AAAA,EAClB;AAAA,EAEA,IAAI,cAAkC;AACpC,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAI,YAAY,UAA8B;AAC5C,SAAK,eAAe;AACf,SAAA,QAAQ,eAAe,QAAQ;AAAA,EAItC;AACF;ACnGA,MAAM,eAAe,CAAC,WAAyC,IAAI,YAAY,MAAM;;"}
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../src/utils/helpers.ts","../src/clients/auth.ts","../src/clients/functions.ts","../src/clients/graphql.ts","../src/clients/storage.ts","../src/clients/nhost.ts"],"sourcesContent":["import { NhostClientConstructorParams } from './types'\n\nconst LOCALHOST_REGEX = /^((?<protocol>http[s]?):\\/\\/)?(?<host>localhost)(:(?<port>\\d+))?$/\n\n/**\n * `backendUrl` should now be used only when self-hosting\n * `subdomain` and `region` should be used instead when using the Nhost platform\n * `\n * @param backendOrSubdomain\n * @param service\n * @returns\n */\nexport function urlFromSubdomain(\n backendOrSubdomain: Pick<NhostClientConstructorParams, 'region' | 'subdomain' | 'backendUrl'>,\n service: string\n): string {\n const { backendUrl, subdomain, region } = backendOrSubdomain\n\n if (backendUrl) {\n return `${backendUrl}/v1/${service}`\n }\n\n if (!subdomain) {\n throw new Error('Either `backendUrl` or `subdomain` must be set.')\n }\n\n // check if subdomain is [http[s]://]localhost[:port]\n const subdomainLocalhostFound = subdomain.match(LOCALHOST_REGEX)\n if (subdomainLocalhostFound?.groups) {\n const { protocol = 'http', host, port = 1337 } = subdomainLocalhostFound.groups\n\n const urlFromEnv = getValueFromEnv(service)\n if (urlFromEnv) {\n return urlFromEnv\n }\n return `${protocol}://${host}:${port}/v1/${service}`\n }\n\n if (!region) {\n throw new Error('`region` must be set when using a `subdomain` other than \"localhost\".')\n }\n\n return `https://${subdomain}.${service}.${region}.nhost.run/v1`\n}\n\n/**\n *\n * @returns whether the code is running in a browser\n */\nfunction isBrowser(): boolean {\n return typeof window !== 'undefined'\n}\n\n/**\n *\n * @returns whether the code is running in a Node.js environment\n */\nfunction environmentIsAvailable() {\n return typeof process !== 'undefined' && process.env\n}\n\n/**\n *\n * @param service auth | storage | graphql | functions\n * @returns the service's url if the corresponding env var is set\n * NHOST_${service}_URL\n */\nfunction getValueFromEnv(service: string) {\n if (isBrowser() || !environmentIsAvailable()) {\n return null\n }\n\n return process.env[`NHOST_${service.toUpperCase()}_URL`]\n}\n","import { HasuraAuthClient } from '@nhost/hasura-auth-js'\n\nimport { urlFromSubdomain } from '../utils/helpers'\nimport { NhostClientConstructorParams } from '../utils/types'\n\n/**\n * Creates a client for Auth from either a subdomain or a URL\n */\nexport function createAuthClient(params: NhostClientConstructorParams) {\n const authUrl =\n 'subdomain' in params || 'backendUrl' in params\n ? urlFromSubdomain(params, 'auth')\n : params.authUrl\n\n if (!authUrl) {\n throw new Error('Please provide `subdomain` or `authUrl`.')\n }\n\n return new HasuraAuthClient({ url: authUrl, ...params })\n}\n","import axios, {\n AxiosInstance,\n AxiosRequestConfig,\n AxiosResponse,\n RawAxiosRequestHeaders\n} from 'axios'\n\nimport { urlFromSubdomain } from '../utils/helpers'\nimport { FunctionCallResponse, NhostClientConstructorParams } from '../utils/types'\nexport interface NhostFunctionsConstructorParams {\n /**\n * Serverless Functions endpoint.\n */\n url: string\n /**\n * Admin secret. When set, it is sent as an `x-hasura-admin-secret` header for all requests.\n */\n adminSecret?: string\n}\n\n/**\n * Creates a client for Functions from either a subdomain or a URL\n */\nexport function createFunctionsClient(params: NhostClientConstructorParams) {\n const functionsUrl =\n 'subdomain' in params || 'backendUrl' in params\n ? urlFromSubdomain(params, 'functions')\n : params.functionsUrl\n\n if (!functionsUrl) {\n throw new Error('Please provide `subdomain` or `functionsUrl`.')\n }\n\n return new NhostFunctionsClient({ url: functionsUrl, ...params })\n}\n\n/**\n * @alias Functions\n */\nexport class NhostFunctionsClient {\n private url: string\n private instance: AxiosInstance\n private accessToken: string | null\n private adminSecret?: string\n\n constructor(params: NhostFunctionsConstructorParams) {\n const { url, adminSecret } = params\n\n this.url = url\n this.accessToken = null\n this.adminSecret = adminSecret\n this.instance = axios.create({\n baseURL: url\n })\n }\n\n /**\n * Use `nhost.functions.call` to call (sending a POST request to) a serverless function.\n *\n * @example\n * ```ts\n * await nhost.functions.call('send-welcome-email', { email: 'joe@example.com', name: 'Joe Doe' })\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/call\n */\n async call<T = unknown, D = any>(\n url: string,\n data: D,\n config?: AxiosRequestConfig\n ): Promise<FunctionCallResponse<T>> {\n const headers = {\n ...this.generateAccessTokenHeaders(),\n ...config?.headers\n }\n\n let res\n try {\n res = await this.instance.post<T, AxiosResponse<T>, D>(url, data, { ...config, headers })\n } catch (error) {\n if (error instanceof Error) {\n return { res: null, error }\n }\n }\n\n if (!res) {\n return {\n res: null,\n error: new Error('Unable to make post request to funtion')\n }\n }\n\n return { res, error: null }\n }\n\n /**\n * Use `nhost.functions.setAccessToken` to a set an access token to be used in subsequent functions requests. Note that if you're signin in users with `nhost.auth.signIn()` the access token will be set automatically.\n *\n * @example\n * ```ts\n * nhost.functions.setAccessToken('some-access-token')\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/set-access-token\n */\n setAccessToken(accessToken: string | undefined) {\n if (!accessToken) {\n this.accessToken = null\n return\n }\n\n this.accessToken = accessToken\n }\n\n private generateAccessTokenHeaders(): RawAxiosRequestHeaders {\n if (this.adminSecret) {\n return {\n 'x-hasura-admin-secret': this.adminSecret\n }\n }\n if (this.accessToken) {\n return {\n Authorization: `Bearer ${this.accessToken}`\n }\n }\n return {}\n }\n}\n","import axios, { AxiosInstance, AxiosRequestConfig, RawAxiosRequestHeaders } from 'axios'\nimport { DocumentNode, print } from 'graphql'\n\nimport { urlFromSubdomain } from '../utils/helpers'\nimport {\n GraphqlRequestResponse,\n GraphqlResponse,\n NhostClientConstructorParams\n} from '../utils/types'\n\nexport interface NhostGraphqlConstructorParams {\n /**\n * GraphQL endpoint.\n */\n url: string\n /**\n * Admin secret. When set, it is sent as an `x-hasura-admin-secret` header for all requests.\n */\n adminSecret?: string\n}\n\n/**\n * Creates a client for GraphQL from either a subdomain or a URL\n */\nexport function createGraphqlClient(params: NhostClientConstructorParams) {\n const graphqlUrl =\n 'subdomain' in params || 'backendUrl' in params\n ? urlFromSubdomain(params, 'graphql')\n : params.graphqlUrl\n\n if (!graphqlUrl) {\n throw new Error('Please provide `subdomain` or `graphqlUrl`.')\n }\n\n return new NhostGraphqlClient({ url: graphqlUrl, ...params })\n}\n\n/**\n * @alias GraphQL\n */\nexport class NhostGraphqlClient {\n private url: string\n private instance: AxiosInstance\n private accessToken: string | null\n private adminSecret?: string\n\n constructor(params: NhostGraphqlConstructorParams) {\n const { url, adminSecret } = params\n\n this.url = url\n this.accessToken = null\n this.adminSecret = adminSecret\n this.instance = axios.create({\n baseURL: url\n })\n }\n\n /**\n * Use `nhost.graphql.request` to send a GraphQL request. For more serious GraphQL usage we recommend using a GraphQL client such as Apollo Client (https://www.apollographql.com/docs/react).\n *\n * @example\n * ```ts\n * const CUSTOMERS = gql`\n * query {\n * customers {\n * id\n * name\n * }\n * }\n * `\n * const { data, error } = await nhost.graphql.request(CUSTOMERS)\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/graphql/request\n */\n async request<T = any, V = any>(\n document: string | DocumentNode,\n variables?: V,\n config?: AxiosRequestConfig\n ): Promise<GraphqlRequestResponse<T>> {\n // add auth headers if any\n const headers = {\n ...this.generateAccessTokenHeaders(),\n ...config?.headers\n }\n\n try {\n const operationName = ''\n const res = await this.instance.post<GraphqlResponse<T>>(\n '',\n {\n operationName: operationName || undefined,\n query: typeof document === 'string' ? document : print(document),\n variables\n },\n { ...config, headers }\n )\n\n const responseData = res.data\n const { data } = responseData\n\n if (responseData.errors) {\n return {\n data: null,\n error: responseData.errors\n }\n }\n\n if (typeof data !== 'object' || Array.isArray(data) || data === null) {\n return {\n data: null,\n error: new Error('incorrect response data from GraphQL server')\n }\n }\n\n return { data, error: null }\n } catch (error) {\n if (error instanceof Error) {\n return { data: null, error }\n }\n console.error(error)\n return {\n data: null,\n error: new Error('Unable to get do GraphQL request')\n }\n }\n }\n\n /**\n * Use `nhost.graphql.getUrl` to get the GraphQL URL.\n *\n * @example\n * ```ts\n * const url = nhost.graphql.getUrl();\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/graphql/get-url\n */\n getUrl(): string {\n return this.url\n }\n\n /**\n * Use `nhost.graphql.setAccessToken` to a set an access token to be used in subsequent graphql requests. Note that if you're signin in users with `nhost.auth.signIn()` the access token will be set automatically.\n *\n * @example\n * ```ts\n * nhost.graphql.setAccessToken('some-access-token')\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/graphql/set-access-token\n */\n setAccessToken(accessToken: string | undefined) {\n if (!accessToken) {\n this.accessToken = null\n return\n }\n\n this.accessToken = accessToken\n }\n\n private generateAccessTokenHeaders(): RawAxiosRequestHeaders {\n if (this.adminSecret) {\n return {\n 'x-hasura-admin-secret': this.adminSecret\n }\n }\n if (this.accessToken) {\n return {\n Authorization: `Bearer ${this.accessToken}`\n }\n }\n return {}\n }\n}\n","import { HasuraStorageClient } from '@nhost/hasura-storage-js'\n\nimport { urlFromSubdomain } from '../utils/helpers'\nimport { NhostClientConstructorParams } from '../utils/types'\n\n/**\n * Creates a client for Storage from either a subdomain or a URL\n */\nexport function createStorageClient(params: NhostClientConstructorParams) {\n const storageUrl =\n 'subdomain' in params || 'backendUrl' in params\n ? urlFromSubdomain(params, 'storage')\n : params.storageUrl\n\n if (!storageUrl) {\n throw new Error('Please provide `subdomain` or `storageUrl`.')\n }\n\n return new HasuraStorageClient({ url: storageUrl, ...params })\n}\n","import { HasuraAuthClient } from '@nhost/hasura-auth-js'\nimport { HasuraStorageClient } from '@nhost/hasura-storage-js'\n\nimport { NhostClientConstructorParams } from '../utils/types'\n\nimport { createAuthClient } from './auth'\nimport { createFunctionsClient, NhostFunctionsClient } from './functions'\nimport { createGraphqlClient, NhostGraphqlClient } from './graphql'\nimport { createStorageClient } from './storage'\n\nexport const createNhostClient = (params: NhostClientConstructorParams) => new NhostClient(params)\nexport class NhostClient {\n auth: HasuraAuthClient\n storage: HasuraStorageClient\n functions: NhostFunctionsClient\n graphql: NhostGraphqlClient\n private _adminSecret?: string\n readonly devTools?: boolean\n\n /**\n * Nhost Client\n *\n * @example\n * ```ts\n * const nhost = new NhostClient({ subdomain, region });\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript\n */\n constructor({\n refreshIntervalTime,\n clientStorageGetter,\n clientStorageSetter,\n clientStorage,\n clientStorageType,\n autoRefreshToken,\n autoSignIn,\n adminSecret,\n devTools,\n start = true,\n ...urlParams\n }: NhostClientConstructorParams) {\n // * Set clients for all services\n this.auth = createAuthClient({\n refreshIntervalTime,\n clientStorageGetter,\n clientStorageSetter,\n clientStorage,\n clientStorageType,\n autoRefreshToken,\n autoSignIn,\n start,\n ...urlParams\n })\n this.storage = createStorageClient({ adminSecret, ...urlParams })\n this.functions = createFunctionsClient({ adminSecret, ...urlParams })\n this.graphql = createGraphqlClient({ adminSecret, ...urlParams })\n\n // * Set current token if token is already accessable\n this.storage.setAccessToken(this.auth.getAccessToken())\n this.functions.setAccessToken(this.auth.getAccessToken())\n this.graphql.setAccessToken(this.auth.getAccessToken())\n\n this.auth.client?.onStart(() => {\n // * Set access token when signing out\n this.auth.onAuthStateChanged((_event, session) => {\n if (_event === 'SIGNED_OUT') {\n this.storage.setAccessToken(undefined)\n this.functions.setAccessToken(undefined)\n this.graphql.setAccessToken(undefined)\n }\n })\n\n // * Update access token for clients, including when signin in\n this.auth.onTokenChanged((session) => {\n this.storage.setAccessToken(session?.accessToken)\n this.functions.setAccessToken(session?.accessToken)\n this.graphql.setAccessToken(session?.accessToken)\n })\n })\n this._adminSecret = adminSecret\n this.devTools = devTools\n }\n\n get adminSecret(): string | undefined {\n return this._adminSecret\n }\n\n set adminSecret(newValue: string | undefined) {\n this._adminSecret = newValue\n this.storage.setAdminSecret(newValue)\n // TODO inconsistent API: storage can change admin secret, but functions/graphql cannot\n // this.functions.setAdminSecret(newValue)\n // this.graphql.setAdminSecret(newValue)\n }\n}\n"],"names":["LOCALHOST_REGEX","urlFromSubdomain","backendOrSubdomain","service","backendUrl","subdomain","region","subdomainLocalhostFound","protocol","host","port","urlFromEnv","getValueFromEnv","isBrowser","environmentIsAvailable","createAuthClient","params","authUrl","HasuraAuthClient","createFunctionsClient","functionsUrl","NhostFunctionsClient","__publicField","url","adminSecret","axios","data","config","headers","res","error","accessToken","createGraphqlClient","graphqlUrl","NhostGraphqlClient","document","variables","operationName","responseData","print","createStorageClient","storageUrl","HasuraStorageClient","createNhostClient","NhostClient","refreshIntervalTime","clientStorageGetter","clientStorageSetter","clientStorage","clientStorageType","autoRefreshToken","autoSignIn","devTools","start","urlParams","_a","_event","session","newValue"],"mappings":";;;;;;;AAEA,MAAMA,IAAkB;AAUR,SAAAC,EACdC,GACAC,GACQ;AACR,QAAM,EAAE,YAAAC,GAAY,WAAAC,GAAW,QAAAC,EAAA,IAAWJ;AAE1C,MAAIE;AACF,WAAO,GAAGA,QAAiBD;AAG7B,MAAI,CAACE;AACG,UAAA,IAAI,MAAM,iDAAiD;AAI7D,QAAAE,IAA0BF,EAAU,MAAML,CAAe;AAC/D,MAAIO,KAAA,QAAAA,EAAyB,QAAQ;AACnC,UAAM,EAAE,UAAAC,IAAW,QAAQ,MAAAC,GAAM,MAAAC,IAAO,SAASH,EAAwB,QAEnEI,IAAaC,EAAgBT,CAAO;AAC1C,WAAIQ,KAGG,GAAGH,OAAcC,KAAQC,QAAWP;AAAA,EAC7C;AAEA,MAAI,CAACG;AACG,UAAA,IAAI,MAAM,uEAAuE;AAGlF,SAAA,WAAWD,KAAaF,KAAWG;AAC5C;AAMA,SAASO,IAAqB;AAC5B,SAAO,OAAO,SAAW;AAC3B;AAMA,SAASC,IAAyB;AACzB,SAAA,OAAO,UAAY,OAAe,QAAQ;AACnD;AAQA,SAASF,EAAgBT,GAAiB;AACxC,SAAIU,EAAU,KAAK,CAACC,MACX,OAGF,QAAQ,IAAI,SAASX,EAAQ,YAAY;AAClD;ACjEO,SAASY,EAAiBC,GAAsC;AAC/D,QAAAC,IACJ,eAAeD,KAAU,gBAAgBA,IACrCf,EAAiBe,GAAQ,MAAM,IAC/BA,EAAO;AAEb,MAAI,CAACC;AACG,UAAA,IAAI,MAAM,0CAA0C;AAG5D,SAAO,IAAIC,EAAiB,EAAE,KAAKD,GAAS,GAAGD,GAAQ;AACzD;ACIO,SAASG,EAAsBH,GAAsC;AACpE,QAAAI,IACJ,eAAeJ,KAAU,gBAAgBA,IACrCf,EAAiBe,GAAQ,WAAW,IACpCA,EAAO;AAEb,MAAI,CAACI;AACG,UAA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declare function
|
|
10
|
+
export declare function urlFromSubdomain(backendOrSubdomain: Pick<NhostClientConstructorParams, 'region' | 'subdomain' | 'backendUrl'>, service: string): string;
|
|
11
11
|
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,SAAS,CAAA;AAItD;;;;;;;GAOG;AACH,wBAAgB,
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,SAAS,CAAA;AAItD;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,kBAAkB,EAAE,IAAI,CAAC,4BAA4B,EAAE,QAAQ,GAAG,WAAW,GAAG,YAAY,CAAC,EAC7F,OAAO,EAAE,MAAM,GACd,MAAM,CA4BR"}
|
package/dist/utils/types.d.ts
CHANGED
|
@@ -4,14 +4,9 @@ export type { NhostAuthConstructorParams };
|
|
|
4
4
|
export declare type BackendUrl = {
|
|
5
5
|
/**
|
|
6
6
|
* Nhost backend URL
|
|
7
|
-
*
|
|
7
|
+
* Will be deprecated in a future release. Please look at 'subdomain' and 'region' instead.
|
|
8
8
|
*/
|
|
9
9
|
backendUrl: string;
|
|
10
|
-
/**
|
|
11
|
-
* When set, the admin secret is sent as a header, `x-hasura-admin-secret`,
|
|
12
|
-
* for all requests to GraphQL, Storage, and Serverless Functions.
|
|
13
|
-
*/
|
|
14
|
-
adminSecret?: string;
|
|
15
10
|
};
|
|
16
11
|
export declare type Subdomain = {
|
|
17
12
|
/**
|
|
@@ -30,8 +25,19 @@ export declare type Subdomain = {
|
|
|
30
25
|
*/
|
|
31
26
|
adminSecret?: string;
|
|
32
27
|
};
|
|
28
|
+
export declare type ServiceUrls = {
|
|
29
|
+
authUrl?: string;
|
|
30
|
+
graphqlUrl?: string;
|
|
31
|
+
storageUrl?: string;
|
|
32
|
+
functionsUrl?: string;
|
|
33
|
+
};
|
|
33
34
|
export declare type BackendOrSubdomain = BackendUrl | Subdomain;
|
|
34
|
-
export interface NhostClientConstructorParams extends Partial<BackendUrl>, Partial<Subdomain>, Omit<NhostAuthConstructorParams, 'url'> {
|
|
35
|
+
export interface NhostClientConstructorParams extends Partial<BackendUrl>, Partial<Subdomain>, Partial<ServiceUrls>, Omit<NhostAuthConstructorParams, 'url'> {
|
|
36
|
+
/**
|
|
37
|
+
* When set, the admin secret is sent as a header, `x-hasura-admin-secret`,
|
|
38
|
+
* for all requests to GraphQL, Storage, and Serverless Functions.
|
|
39
|
+
*/
|
|
40
|
+
adminSecret?: string;
|
|
35
41
|
}
|
|
36
42
|
export declare type GraphqlRequestResponse<T = unknown> = {
|
|
37
43
|
data: null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAE1C,OAAO,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAA;AAElE,YAAY,EAAE,0BAA0B,EAAE,CAAA;AAE1C,oBAAY,UAAU,GAAG;IACvB;;;OAGG;IACH,UAAU,EAAE,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAE1C,OAAO,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAA;AAElE,YAAY,EAAE,0BAA0B,EAAE,CAAA;AAE1C,oBAAY,UAAU,GAAG;IACvB;;;OAGG;IACH,UAAU,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,oBAAY,SAAS,GAAG;IACtB;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAA;IAEjB;;;OAGG;IACH,MAAM,CAA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|
"description": "Nhost JavaScript SDK",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
"access": "public"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@nhost/hasura-auth-js": "1.6.
|
|
47
|
-
"@nhost/hasura-storage-js": "0.7.
|
|
48
|
-
"axios": "^
|
|
46
|
+
"@nhost/hasura-auth-js": "1.6.2",
|
|
47
|
+
"@nhost/hasura-storage-js": "0.7.2",
|
|
48
|
+
"axios": "^1.1.3",
|
|
49
49
|
"jwt-decode": "^3.1.2",
|
|
50
50
|
"query-string": "^7.0.1"
|
|
51
51
|
},
|
|
@@ -62,10 +62,11 @@
|
|
|
62
62
|
"build": "run-p build:lib build:umd",
|
|
63
63
|
"build:lib": "vite build",
|
|
64
64
|
"build:umd": "vite build --config ../../config/vite.lib.umd.config.js",
|
|
65
|
+
"test": "vitest run",
|
|
66
|
+
"test:watch": "vitest",
|
|
65
67
|
"e2e": "start-test e2e:backend http-get://localhost:9695 ci:test",
|
|
66
|
-
"ci:test": "vitest run",
|
|
68
|
+
"ci:test": "vitest run --config vite.config.e2e.js",
|
|
67
69
|
"e2e:backend": "nhost dev --no-browser",
|
|
68
|
-
"test:watch": "vitest",
|
|
69
70
|
"test:coverage": "vitest run --coverage",
|
|
70
71
|
"prettier": "prettier --check src/",
|
|
71
72
|
"prettier:fix": "prettier --write src/",
|