@nhost/nhost-js 0.3.2 → 0.3.6
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/README.md +1 -0
- package/dist/cjs/clients/functions.js +1 -2
- package/dist/cjs/clients/functions.js.map +1 -1
- package/dist/cjs/clients/graphql.js +1 -2
- package/dist/cjs/clients/graphql.js.map +1 -1
- package/dist/cjs/core/nhost-client.js +4 -4
- package/dist/cjs/core/nhost-client.js.map +1 -1
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/index.js +6 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/clients/functions.js +1 -2
- package/dist/esm/clients/functions.js.map +1 -1
- package/dist/esm/clients/graphql.js +1 -2
- package/dist/esm/clients/graphql.js.map +1 -1
- package/dist/esm/core/nhost-client.js +4 -4
- package/dist/esm/core/nhost-client.js.map +1 -1
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/index.js.map +1 -1
- package/package.json +5 -4
- package/src/clients/functions.ts +68 -0
- package/src/clients/graphql.ts +102 -0
- package/src/core/index.ts +1 -0
- package/src/core/nhost-client.ts +84 -0
- package/src/index.ts +9 -0
- package/src/types.ts +26 -0
package/README.md
CHANGED
|
@@ -58,7 +58,6 @@ var NhostFunctionsClient = /** @class */ (function () {
|
|
|
58
58
|
this.accessToken = null;
|
|
59
59
|
this.instance = axios_1.default.create({
|
|
60
60
|
baseURL: url,
|
|
61
|
-
timeout: 5000,
|
|
62
61
|
});
|
|
63
62
|
}
|
|
64
63
|
NhostFunctionsClient.prototype.call = function (url, data, config) {
|
|
@@ -105,7 +104,7 @@ var NhostFunctionsClient = /** @class */ (function () {
|
|
|
105
104
|
return;
|
|
106
105
|
}
|
|
107
106
|
return {
|
|
108
|
-
Authorization: "Bearer "
|
|
107
|
+
Authorization: "Bearer ".concat(this.accessToken),
|
|
109
108
|
};
|
|
110
109
|
};
|
|
111
110
|
return NhostFunctionsClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../../../src/clients/functions.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAiE;AAOjE;IAIE,8BAAY,MAAuC;QACzC,IAAA,GAAG,GAAK,MAAM,IAAX,CAAY;QAEvB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,IAAI,CAAC,QAAQ,GAAG,eAAK,CAAC,MAAM,CAAC;YAC3B,OAAO,EAAE,GAAG;
|
|
1
|
+
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../../../src/clients/functions.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAiE;AAOjE;IAIE,8BAAY,MAAuC;QACzC,IAAA,GAAG,GAAK,MAAM,IAAX,CAAY;QAEvB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,IAAI,CAAC,QAAQ,GAAG,eAAK,CAAC,MAAM,CAAC;YAC3B,OAAO,EAAE,GAAG;SACb,CAAC,CAAC;IACL,CAAC;IAEY,mCAAI,GAAjB,UACE,GAAW,EACX,IAAS,EACT,MAA2B;;;;;;wBAErB,OAAO,yBACR,IAAI,CAAC,0BAA0B,EAAE,GACjC,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,OAAO,CACnB,CAAC;;;;wBAIM,qBAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,wBAAO,MAAM,KAAE,OAAO,SAAA,IAAG,EAAA;;wBAAjE,GAAG,GAAG,SAA2D,CAAC;;;;wBAElE,IAAI,OAAK,YAAY,KAAK,EAAE;4BAC1B,sBAAO,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,SAAA,EAAE,EAAC;yBAC7B;;;wBAGH,IAAI,CAAC,GAAG,EAAE;4BACR,sBAAO;oCACL,GAAG,EAAE,IAAI;oCACT,KAAK,EAAE,KAAK,CAAC,wCAAwC,CAAC;iCACvD,EAAC;yBACH;wBAED,sBAAO,EAAE,GAAG,KAAA,EAAE,KAAK,EAAE,IAAI,EAAE,EAAC;;;;KAC7B;IAEM,6CAAc,GAArB,UAAsB,WAA+B;QACnD,IAAI,CAAC,WAAW,EAAE;YAChB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;YACxB,OAAO;SACR;QAED,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;IAEO,yDAA0B,GAAlC;QACE,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;YACrB,OAAO;SACR;QAED,OAAO;YACL,aAAa,EAAE,iBAAU,IAAI,CAAC,WAAW,CAAE;SAC5C,CAAC;IACJ,CAAC;IACH,2BAAC;AAAD,CAAC,AA5DD,IA4DC;AA5DY,oDAAoB"}
|
|
@@ -59,7 +59,6 @@ var NhostGraphqlClient = /** @class */ (function () {
|
|
|
59
59
|
this.accessToken = null;
|
|
60
60
|
this.instance = axios_1.default.create({
|
|
61
61
|
baseURL: url,
|
|
62
|
-
timeout: 5000,
|
|
63
62
|
});
|
|
64
63
|
}
|
|
65
64
|
NhostGraphqlClient.prototype.request = function (document, variables, config) {
|
|
@@ -125,7 +124,7 @@ var NhostGraphqlClient = /** @class */ (function () {
|
|
|
125
124
|
return;
|
|
126
125
|
}
|
|
127
126
|
return {
|
|
128
|
-
Authorization: "Bearer "
|
|
127
|
+
Authorization: "Bearer ".concat(this.accessToken),
|
|
129
128
|
};
|
|
130
129
|
};
|
|
131
130
|
return NhostGraphqlClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql.js","sourceRoot":"","sources":["../../../src/clients/graphql.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAiE;AAOjE;IAKE,4BAAY,MAAqC;QACvC,IAAA,GAAG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,OAAO,CAAC,KAAK,CAAC,OAAK,CAAC,CAAC;wBACrB,sBAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,kCAAkC,CAAC,EAAE,EAAC;;wBAG1E,IACE,OAAO,YAAY,KAAK,QAAQ;4BAChC,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC;4BAC3B,YAAY,KAAK,IAAI,EACrB;4BACA,sBAAO;oCACL,IAAI,EAAE,IAAI;oCACV,KAAK,EAAE,KAAK,CAAC,6CAA6C,CAAC;iCAC5D,EAAC;yBACH;wBAED,YAAY,GAAG,YAA+B,CAAC;wBAE/C,IAAI,YAAY,CAAC,MAAM,EAAE;4BACvB,sBAAO;oCACL,IAAI,EAAE,IAAI;oCACV,KAAK,EAAE,YAAY,CAAC,MAAM;iCAC3B,EAAC;yBACH;wBAED,sBAAO,EAAE,IAAI,EAAE,YAAY,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,EAAC;;;;KACjD;IAEM,mCAAM,GAAb;QACE,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;IAEM,2CAAc,GAArB,UAAsB,WAA+B;QACnD,IAAI,CAAC,WAAW,EAAE;YAChB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;YACxB,OAAO;SACR;QAED,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;IAEO,uDAA0B,GAAlC;QACE,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;YACrB,OAAO;SACR;QAED,OAAO;YACL,aAAa,EAAE,iBAAU,IAAI,CAAC,WAAW,CAAE;SAC5C,CAAC;IACJ,CAAC;IACH,yBAAC;AAAD,CAAC,AA9FD,IA8FC;AA9FY,gDAAkB"}
|
|
@@ -20,7 +20,7 @@ var NhostClient = /** @class */ (function () {
|
|
|
20
20
|
throw 'Please specify a `backendUrl`. Docs: [todo]!';
|
|
21
21
|
var backendUrl = params.backendUrl, refreshIntervalTime = params.refreshIntervalTime, clientStorage = params.clientStorage, clientStorageType = params.clientStorageType, autoRefreshToken = params.autoRefreshToken, autoLogin = params.autoLogin;
|
|
22
22
|
this.auth = new hasura_auth_js_1.HasuraAuthClient({
|
|
23
|
-
url: backendUrl
|
|
23
|
+
url: "".concat(backendUrl, "/v1/auth"),
|
|
24
24
|
refreshIntervalTime: refreshIntervalTime,
|
|
25
25
|
clientStorage: clientStorage,
|
|
26
26
|
clientStorageType: clientStorageType,
|
|
@@ -28,13 +28,13 @@ var NhostClient = /** @class */ (function () {
|
|
|
28
28
|
autoLogin: autoLogin,
|
|
29
29
|
});
|
|
30
30
|
this.storage = new hasura_storage_js_1.HasuraStorageClient({
|
|
31
|
-
url: backendUrl
|
|
31
|
+
url: "".concat(backendUrl, "/v1/storage"),
|
|
32
32
|
});
|
|
33
33
|
this.functions = new functions_1.NhostFunctionsClient({
|
|
34
|
-
url: backendUrl
|
|
34
|
+
url: "".concat(backendUrl, "/v1/functions"),
|
|
35
35
|
});
|
|
36
36
|
this.graphql = new graphql_1.NhostGraphqlClient({
|
|
37
|
-
url: backendUrl
|
|
37
|
+
url: "".concat(backendUrl, "/v1/graphql"),
|
|
38
38
|
});
|
|
39
39
|
// set current token if token is already accessable
|
|
40
40
|
this.storage.setAccessToken(this.auth.getAccessToken());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nhost-client.js","sourceRoot":"","sources":["../../../src/core/nhost-client.ts"],"names":[],"mappings":";;;AAAA,wDAAyD;AACzD,8DAA+D;AAG/D,kDAA4D;AAC5D,8CAAwD;AAWxD;IAME;;;;;;;OAOG;IACH,qBAAY,MAAoC;QAAhD,iBAoDC;QAnDC,IAAI,CAAC,MAAM,CAAC,UAAU;YACpB,MAAM,8CAA8C,CAAC;QAGrD,IAAA,UAAU,GAMR,MAAM,WANE,EACV,mBAAmB,GAKjB,MAAM,oBALW,EACnB,aAAa,GAIX,MAAM,cAJK,EACb,iBAAiB,GAGf,MAAM,kBAHS,EACjB,gBAAgB,GAE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S,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC;QAC1D,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC;QAExD,kCAAkC;QAClC,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,UAAC,MAAM,EAAE,OAAO;YAC3C,KAAI,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,CAAC,CAAC;YAClD,KAAI,CAAC,SAAS,CAAC,cAAc,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,CAAC,CAAC;YACpD,KAAI,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;QAEH,kCAAkC;QAClC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,UAAC,OAAO;YAC/B,KAAI,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,CAAC,CAAC;YAClD,KAAI,CAAC,SAAS,CAAC,cAAc,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,CAAC,CAAC;YACpD,KAAI,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;IACL,CAAC;IACH,kBAAC;AAAD,CAAC,AAnED,IAmEC;AAnEY,kCAAW"}
|
package/dist/cjs/index.d.ts
CHANGED
package/dist/cjs/index.js
CHANGED
|
@@ -10,5 +10,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.createClient = void 0;
|
|
14
|
+
var _1 = require(".");
|
|
15
|
+
var createClient = function (config) {
|
|
16
|
+
return new _1.NhostClient(config);
|
|
17
|
+
};
|
|
18
|
+
exports.createClient = createClient;
|
|
13
19
|
__exportStar(require("./core"), exports);
|
|
14
20
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,sBAAgC;AAGhC,IAAM,YAAY,GAAG,UAAC,MAAoC;IACtD,OAAO,IAAI,cAAW,CAAC,MAAM,CAAC,CAAC;AACnC,CAAC,CAAC;AAGM,oCAAY;AADpB,yCAAuB"}
|
|
@@ -52,7 +52,6 @@ var NhostFunctionsClient = /** @class */ (function () {
|
|
|
52
52
|
this.accessToken = null;
|
|
53
53
|
this.instance = axios.create({
|
|
54
54
|
baseURL: url,
|
|
55
|
-
timeout: 5000,
|
|
56
55
|
});
|
|
57
56
|
}
|
|
58
57
|
NhostFunctionsClient.prototype.call = function (url, data, config) {
|
|
@@ -99,7 +98,7 @@ var NhostFunctionsClient = /** @class */ (function () {
|
|
|
99
98
|
return;
|
|
100
99
|
}
|
|
101
100
|
return {
|
|
102
|
-
Authorization: "Bearer "
|
|
101
|
+
Authorization: "Bearer ".concat(this.accessToken),
|
|
103
102
|
};
|
|
104
103
|
};
|
|
105
104
|
return NhostFunctionsClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../../../src/clients/functions.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,KAA4C,MAAM,OAAO,CAAC;AAOjE;IAIE,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AAc,GAArB,UAAsB,WAA+B;QACnD,IAAI,CAAC,WAAW,EAAE;YAChB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;YACxB,OAAO;SACR;QAED,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;IAEO,yDAA0B,GAAlC;QACE,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;YACrB,OAAO;SACR;QAED,OAAO;YACL,aAAa,EAAE,iBAAU,IAAI,CAAC,WAAW,CAAE;SAC5C,CAAC;IACJ,CAAC;IACH,2BAAC;AAAD,CAAC,AA5DD,IA4DC"}
|
|
@@ -53,7 +53,6 @@ var NhostGraphqlClient = /** @class */ (function () {
|
|
|
53
53
|
this.accessToken = null;
|
|
54
54
|
this.instance = axios.create({
|
|
55
55
|
baseURL: url,
|
|
56
|
-
timeout: 5000,
|
|
57
56
|
});
|
|
58
57
|
}
|
|
59
58
|
NhostGraphqlClient.prototype.request = function (document, variables, config) {
|
|
@@ -119,7 +118,7 @@ var NhostGraphqlClient = /** @class */ (function () {
|
|
|
119
118
|
return;
|
|
120
119
|
}
|
|
121
120
|
return {
|
|
122
|
-
Authorization: "Bearer "
|
|
121
|
+
Authorization: "Bearer ".concat(this.accessToken),
|
|
123
122
|
};
|
|
124
123
|
};
|
|
125
124
|
return NhostGraphqlClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql.js","sourceRoot":"","sources":["../../../src/clients/graphql.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,KAA4C,MAAM,OAAO,CAAC;AAOjE;IAKE,4BAAY,MAAqC;QACvC,IAAA,GAAG,GAAK,MAAM,IAAX,CAAY;QAEvB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC;YAC3B,OAAO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AY,KAAK,QAAQ;4BAChC,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC;4BAC3B,YAAY,KAAK,IAAI,EACrB;4BACA,sBAAO;oCACL,IAAI,EAAE,IAAI;oCACV,KAAK,EAAE,KAAK,CAAC,6CAA6C,CAAC;iCAC5D,EAAC;yBACH;wBAED,YAAY,GAAG,YAA+B,CAAC;wBAE/C,IAAI,YAAY,CAAC,MAAM,EAAE;4BACvB,sBAAO;oCACL,IAAI,EAAE,IAAI;oCACV,KAAK,EAAE,YAAY,CAAC,MAAM;iCAC3B,EAAC;yBACH;wBAED,sBAAO,EAAE,IAAI,EAAE,YAAY,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,EAAC;;;;KACjD;IAEM,mCAAM,GAAb;QACE,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;IAEM,2CAAc,GAArB,UAAsB,WAA+B;QACnD,IAAI,CAAC,WAAW,EAAE;YAChB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;YACxB,OAAO;SACR;QAED,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;IAEO,uDAA0B,GAAlC;QACE,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;YACrB,OAAO;SACR;QAED,OAAO;YACL,aAAa,EAAE,iBAAU,IAAI,CAAC,WAAW,CAAE;SAC5C,CAAC;IACJ,CAAC;IACH,yBAAC;AAAD,CAAC,AA9FD,IA8FC"}
|
|
@@ -17,7 +17,7 @@ var NhostClient = /** @class */ (function () {
|
|
|
17
17
|
throw 'Please specify a `backendUrl`. Docs: [todo]!';
|
|
18
18
|
var backendUrl = params.backendUrl, refreshIntervalTime = params.refreshIntervalTime, clientStorage = params.clientStorage, clientStorageType = params.clientStorageType, autoRefreshToken = params.autoRefreshToken, autoLogin = params.autoLogin;
|
|
19
19
|
this.auth = new HasuraAuthClient({
|
|
20
|
-
url: backendUrl
|
|
20
|
+
url: "".concat(backendUrl, "/v1/auth"),
|
|
21
21
|
refreshIntervalTime: refreshIntervalTime,
|
|
22
22
|
clientStorage: clientStorage,
|
|
23
23
|
clientStorageType: clientStorageType,
|
|
@@ -25,13 +25,13 @@ var NhostClient = /** @class */ (function () {
|
|
|
25
25
|
autoLogin: autoLogin,
|
|
26
26
|
});
|
|
27
27
|
this.storage = new HasuraStorageClient({
|
|
28
|
-
url: backendUrl
|
|
28
|
+
url: "".concat(backendUrl, "/v1/storage"),
|
|
29
29
|
});
|
|
30
30
|
this.functions = new NhostFunctionsClient({
|
|
31
|
-
url: backendUrl
|
|
31
|
+
url: "".concat(backendUrl, "/v1/functions"),
|
|
32
32
|
});
|
|
33
33
|
this.graphql = new NhostGraphqlClient({
|
|
34
|
-
url: backendUrl
|
|
34
|
+
url: "".concat(backendUrl, "/v1/graphql"),
|
|
35
35
|
});
|
|
36
36
|
// set current token if token is already accessable
|
|
37
37
|
this.storage.setAccessToken(this.auth.getAccessToken());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nhost-client.js","sourceRoot":"","sources":["../../../src/core/nhost-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAG/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAWxD;IAME;;;;;;;OAOG;IACH,qBAAY,MAAoC;QAAhD,iBAoDC;QAnDC,IAAI,CAAC,MAAM,CAAC,UAAU;YACpB,MAAM,8CAA8C,CAAC;QAGrD,IAAA,UAAU,GAMR,MAAM,WANE,EACV,mBAAmB,GAKjB,MAAM,oBALW,EACnB,aAAa,GAIX,MAAM,cAJK,EACb,iBAAiB,GAGf,MAAM,kBAHS,EACjB,gBAAgB,GAEd,MAAM,iBAFQ,EAChB,SAAS,GACP,MAAM,UADC,CACA;QAEX,IAAI,CAA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AAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC;QACxD,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC;QAC1D,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC;QAExD,kCAAkC;QAClC,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,UAAC,MAAM,EAAE,OAAO;YAC3C,KAAI,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,CAAC,CAAC;YAClD,KAAI,CAAC,SAAS,CAAC,cAAc,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,CAAC,CAAC;YACpD,KAAI,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;QAEH,kCAAkC;QAClC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,UAAC,OAAO;YAC/B,KAAI,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,CAAC,CAAC;YAClD,KAAI,CAAC,SAAS,CAAC,cAAc,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,CAAC,CAAC;YACpD,KAAI,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;IACL,CAAC;IACH,kBAAC;AAAD,CAAC,AAnED,IAmEC"}
|
package/dist/esm/index.d.ts
CHANGED
package/dist/esm/index.js
CHANGED
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,GAAG,CAAC;AAGhC,IAAM,YAAY,GAAG,UAAC,MAAoC;IACtD,OAAO,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC;AACnC,CAAC,CAAC;AAEF,cAAc,QAAQ,CAAC;AACvB,OAAO,EAAC,YAAY,EAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nhost/nhost-js",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.6",
|
|
4
4
|
"description": "Nhost JavaScript SDK",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"nhost"
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
"access": "public"
|
|
17
17
|
},
|
|
18
18
|
"files": [
|
|
19
|
-
"dist
|
|
19
|
+
"dist",
|
|
20
|
+
"src"
|
|
20
21
|
],
|
|
21
22
|
"scripts": {
|
|
22
23
|
"build": "run-p build:esm build:cjs",
|
|
@@ -31,8 +32,8 @@
|
|
|
31
32
|
"url": "git+https://github.com/nhost/nhost-js.git"
|
|
32
33
|
},
|
|
33
34
|
"dependencies": {
|
|
34
|
-
"@nhost/hasura-auth-js": "^0.1.
|
|
35
|
-
"@nhost/hasura-storage-js": "^0.0.
|
|
35
|
+
"@nhost/hasura-auth-js": "^0.1.10",
|
|
36
|
+
"@nhost/hasura-storage-js": "^0.0.6",
|
|
36
37
|
"axios": "^0.23.0",
|
|
37
38
|
"jwt-decode": "^3.1.2",
|
|
38
39
|
"query-string": "^7.0.1"
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import axios, { AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { FunctionCallResponse } from '../types';
|
|
3
|
+
|
|
4
|
+
export type NhostFunctionsConstructorParams = {
|
|
5
|
+
url: string;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export class NhostFunctionsClient {
|
|
9
|
+
private instance: AxiosInstance;
|
|
10
|
+
private accessToken: string | null;
|
|
11
|
+
|
|
12
|
+
constructor(params: NhostFunctionsConstructorParams) {
|
|
13
|
+
const { url } = params;
|
|
14
|
+
|
|
15
|
+
this.accessToken = null;
|
|
16
|
+
this.instance = axios.create({
|
|
17
|
+
baseURL: url,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public async call(
|
|
22
|
+
url: string,
|
|
23
|
+
data: any,
|
|
24
|
+
config?: AxiosRequestConfig
|
|
25
|
+
): Promise<FunctionCallResponse> {
|
|
26
|
+
const headers = {
|
|
27
|
+
...this.generateAccessTokenHeaders(),
|
|
28
|
+
...config?.headers,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
let res;
|
|
32
|
+
try {
|
|
33
|
+
res = await this.instance.post(url, data, { ...config, headers });
|
|
34
|
+
} catch (error) {
|
|
35
|
+
if (error instanceof Error) {
|
|
36
|
+
return { res: null, error };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (!res) {
|
|
41
|
+
return {
|
|
42
|
+
res: null,
|
|
43
|
+
error: Error('Unable to make post request to funtion'),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return { res, error: null };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public setAccessToken(accessToken: string | undefined) {
|
|
51
|
+
if (!accessToken) {
|
|
52
|
+
this.accessToken = null;
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
this.accessToken = accessToken;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
private generateAccessTokenHeaders() {
|
|
60
|
+
if (!this.accessToken) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import axios, { AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { GraphqlRequestResponse, GraphqlResponse } from '../types';
|
|
3
|
+
|
|
4
|
+
export type NhostGraphqlConstructorParams = {
|
|
5
|
+
url: string;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export class NhostGraphqlClient {
|
|
9
|
+
private url: string;
|
|
10
|
+
private instance: AxiosInstance;
|
|
11
|
+
private accessToken: string | null;
|
|
12
|
+
|
|
13
|
+
constructor(params: NhostGraphqlConstructorParams) {
|
|
14
|
+
const { url } = params;
|
|
15
|
+
|
|
16
|
+
this.url = url;
|
|
17
|
+
this.accessToken = null;
|
|
18
|
+
this.instance = axios.create({
|
|
19
|
+
baseURL: url,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public async request(
|
|
24
|
+
document: string,
|
|
25
|
+
variables?: any,
|
|
26
|
+
config?: AxiosRequestConfig
|
|
27
|
+
): Promise<GraphqlRequestResponse> {
|
|
28
|
+
// add auth headers if any
|
|
29
|
+
const headers = {
|
|
30
|
+
...config?.headers,
|
|
31
|
+
...this.generateAccessTokenHeaders(),
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const operationName = '';
|
|
35
|
+
|
|
36
|
+
let responseData;
|
|
37
|
+
try {
|
|
38
|
+
const res = await this.instance.post(
|
|
39
|
+
'',
|
|
40
|
+
{
|
|
41
|
+
operationName: operationName ? operationName : undefined,
|
|
42
|
+
query: document,
|
|
43
|
+
variables,
|
|
44
|
+
},
|
|
45
|
+
{ ...config, headers }
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
responseData = res.data;
|
|
49
|
+
} catch (error) {
|
|
50
|
+
if (error instanceof Error) {
|
|
51
|
+
return { data: null, error };
|
|
52
|
+
}
|
|
53
|
+
console.error(error);
|
|
54
|
+
return { data: null, error: Error('Unable to get do GraphQL request') };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (
|
|
58
|
+
typeof responseData !== 'object' ||
|
|
59
|
+
Array.isArray(responseData) ||
|
|
60
|
+
responseData === null
|
|
61
|
+
) {
|
|
62
|
+
return {
|
|
63
|
+
data: null,
|
|
64
|
+
error: Error('incorrect response data from GraphQL server'),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
responseData = responseData as GraphqlResponse;
|
|
69
|
+
|
|
70
|
+
if (responseData.errors) {
|
|
71
|
+
return {
|
|
72
|
+
data: null,
|
|
73
|
+
error: responseData.errors,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return { data: responseData.data, error: null };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public getUrl(): string {
|
|
81
|
+
return this.url;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
public setAccessToken(accessToken: string | undefined) {
|
|
85
|
+
if (!accessToken) {
|
|
86
|
+
this.accessToken = null;
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
this.accessToken = accessToken;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
private generateAccessTokenHeaders() {
|
|
94
|
+
if (!this.accessToken) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return {
|
|
99
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './nhost-client';
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { HasuraAuthClient } from '@nhost/hasura-auth-js';
|
|
2
|
+
import { HasuraStorageClient } from '@nhost/hasura-storage-js';
|
|
3
|
+
import { ClientStorage, ClientStorageType } from '@nhost/hasura-auth-js';
|
|
4
|
+
|
|
5
|
+
import { NhostFunctionsClient } from '../clients/functions';
|
|
6
|
+
import { NhostGraphqlClient } from '../clients/graphql';
|
|
7
|
+
|
|
8
|
+
export type NhostClientConstructorParams = {
|
|
9
|
+
backendUrl: string;
|
|
10
|
+
refreshIntervalTime?: number;
|
|
11
|
+
clientStorage?: ClientStorage;
|
|
12
|
+
clientStorageType?: ClientStorageType;
|
|
13
|
+
autoRefreshToken?: boolean;
|
|
14
|
+
autoLogin?: boolean;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export class NhostClient {
|
|
18
|
+
auth: HasuraAuthClient;
|
|
19
|
+
storage: HasuraStorageClient;
|
|
20
|
+
functions: NhostFunctionsClient;
|
|
21
|
+
graphql: NhostGraphqlClient;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Nhost Client
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* const nhost = new NhostClient({ url });
|
|
28
|
+
*
|
|
29
|
+
* @docs https://docs.nhost.io/TODO
|
|
30
|
+
*/
|
|
31
|
+
constructor(params: NhostClientConstructorParams) {
|
|
32
|
+
if (!params.backendUrl)
|
|
33
|
+
throw 'Please specify a `backendUrl`. Docs: [todo]!';
|
|
34
|
+
|
|
35
|
+
const {
|
|
36
|
+
backendUrl,
|
|
37
|
+
refreshIntervalTime,
|
|
38
|
+
clientStorage,
|
|
39
|
+
clientStorageType,
|
|
40
|
+
autoRefreshToken,
|
|
41
|
+
autoLogin,
|
|
42
|
+
} = params;
|
|
43
|
+
|
|
44
|
+
this.auth = new HasuraAuthClient({
|
|
45
|
+
url: `${backendUrl}/v1/auth`,
|
|
46
|
+
refreshIntervalTime,
|
|
47
|
+
clientStorage,
|
|
48
|
+
clientStorageType,
|
|
49
|
+
autoRefreshToken,
|
|
50
|
+
autoLogin,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
this.storage = new HasuraStorageClient({
|
|
54
|
+
url: `${backendUrl}/v1/storage`,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
this.functions = new NhostFunctionsClient({
|
|
58
|
+
url: `${backendUrl}/v1/functions`,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
this.graphql = new NhostGraphqlClient({
|
|
62
|
+
url: `${backendUrl}/v1/graphql`,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// set current token if token is already accessable
|
|
66
|
+
this.storage.setAccessToken(this.auth.getAccessToken());
|
|
67
|
+
this.functions.setAccessToken(this.auth.getAccessToken());
|
|
68
|
+
this.graphql.setAccessToken(this.auth.getAccessToken());
|
|
69
|
+
|
|
70
|
+
// update access token for clients
|
|
71
|
+
this.auth.onAuthStateChanged((_event, session) => {
|
|
72
|
+
this.storage.setAccessToken(session?.accessToken);
|
|
73
|
+
this.functions.setAccessToken(session?.accessToken);
|
|
74
|
+
this.graphql.setAccessToken(session?.accessToken);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// update access token for clients
|
|
78
|
+
this.auth.onTokenChanged((session) => {
|
|
79
|
+
this.storage.setAccessToken(session?.accessToken);
|
|
80
|
+
this.functions.setAccessToken(session?.accessToken);
|
|
81
|
+
this.graphql.setAccessToken(session?.accessToken);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
package/src/index.ts
ADDED
package/src/types.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { AxiosResponse } from 'axios';
|
|
2
|
+
|
|
3
|
+
export type GraphqlRequestResponse =
|
|
4
|
+
| {
|
|
5
|
+
data: unknown;
|
|
6
|
+
error: null;
|
|
7
|
+
}
|
|
8
|
+
| {
|
|
9
|
+
data: null;
|
|
10
|
+
error: Error | object;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type FunctionCallResponse =
|
|
14
|
+
| {
|
|
15
|
+
res: AxiosResponse;
|
|
16
|
+
error: null;
|
|
17
|
+
}
|
|
18
|
+
| {
|
|
19
|
+
res: null;
|
|
20
|
+
error: Error;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type GraphqlResponse = {
|
|
24
|
+
errors?: object[];
|
|
25
|
+
data?: object;
|
|
26
|
+
};
|