@knocklabs/client 0.8.5 → 0.8.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/dist/cjs/knock.js +13 -2
- package/dist/cjs/knock.js.map +1 -1
- package/dist/esm/knock.js +13 -3
- package/dist/esm/knock.js.map +1 -1
- package/dist/types/knock.d.ts +2 -1
- package/dist/types/knock.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/cjs/knock.js
CHANGED
|
@@ -27,9 +27,9 @@ var Knock = /*#__PURE__*/function () {
|
|
|
27
27
|
(0, _classCallCheck2["default"])(this, Knock);
|
|
28
28
|
this.apiKey = apiKey;
|
|
29
29
|
(0, _defineProperty2["default"])(this, "host", void 0);
|
|
30
|
-
(0, _defineProperty2["default"])(this, "userToken", void 0);
|
|
31
30
|
(0, _defineProperty2["default"])(this, "apiClient", null);
|
|
32
31
|
(0, _defineProperty2["default"])(this, "userId", void 0);
|
|
32
|
+
(0, _defineProperty2["default"])(this, "userToken", void 0);
|
|
33
33
|
(0, _defineProperty2["default"])(this, "feeds", new _feed["default"](this));
|
|
34
34
|
(0, _defineProperty2["default"])(this, "preferences", new _preferences["default"](this));
|
|
35
35
|
this.host = options.host || DEFAULT_HOST; // Fail loudly if we're using the wrong API key
|
|
@@ -42,7 +42,7 @@ var Knock = /*#__PURE__*/function () {
|
|
|
42
42
|
(0, _createClass2["default"])(Knock, [{
|
|
43
43
|
key: "client",
|
|
44
44
|
value: function client() {
|
|
45
|
-
if (!this.userId
|
|
45
|
+
if (!this.userId) {
|
|
46
46
|
console.warn("[Knock] You must call authenticate(userId, userToken) first before trying to make a request.\n Typically you'll see this message when you're creating a feed instance before having called\n authenticate with a user Id and token. That means we won't know who to issue the request\n to Knock on behalf of.\n ");
|
|
47
47
|
} // Initiate a new API client if we don't have one yet
|
|
48
48
|
|
|
@@ -68,6 +68,17 @@ var Knock = /*#__PURE__*/function () {
|
|
|
68
68
|
this.userId = userId;
|
|
69
69
|
this.userToken = userToken;
|
|
70
70
|
return;
|
|
71
|
+
}
|
|
72
|
+
/*
|
|
73
|
+
Returns whether or this Knock instance is authenticated. Passing `true` will check the presence
|
|
74
|
+
of the userToken as well.
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
}, {
|
|
78
|
+
key: "isAuthenticated",
|
|
79
|
+
value: function isAuthenticated() {
|
|
80
|
+
var checkUserToken = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
81
|
+
return checkUserToken ? this.userId && this.userToken : this.userId;
|
|
71
82
|
} // Used to teardown any connected instances
|
|
72
83
|
|
|
73
84
|
}, {
|
package/dist/cjs/knock.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/knock.ts"],"names":["DEFAULT_HOST","Knock","apiKey","options","FeedClient","Preferences","host","startsWith","Error","userId","
|
|
1
|
+
{"version":3,"sources":["../../src/knock.ts"],"names":["DEFAULT_HOST","Knock","apiKey","options","FeedClient","Preferences","host","startsWith","Error","userId","console","warn","apiClient","ApiClient","userToken","checkUserToken","socket","disconnect"],"mappings":";;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AAGA,IAAMA,YAAY,GAAG,uBAArB;;IAEMC,K;AASJ,iBAAqBC,MAArB,EAAiE;AAAA,QAA5BC,OAA4B,uEAAJ,EAAI;AAAA;AAAA,SAA5CD,MAA4C,GAA5CA,MAA4C;AAAA;AAAA,wDAP3B,IAO2B;AAAA;AAAA;AAAA,oDAHhD,IAAIE,gBAAJ,CAAe,IAAf,CAGgD;AAAA,0DAF1C,IAAIC,uBAAJ,CAAgB,IAAhB,CAE0C;AAC/D,SAAKC,IAAL,GAAYH,OAAO,CAACG,IAAR,IAAgBN,YAA5B,CAD+D,CAG/D;;AACA,QAAI,KAAKE,MAAL,IAAe,KAAKA,MAAL,CAAYK,UAAZ,CAAuB,KAAvB,CAAnB,EAAkD;AAChD,YAAM,IAAIC,KAAJ,CACJ,qFADI,CAAN;AAGD;AACF;;;;WAED,kBAAS;AACP,UAAI,CAAC,KAAKC,MAAV,EAAkB;AAChBC,QAAAA,OAAO,CAACC,IAAR;AAOD,OATM,CAWP;;;AACA,UAAI,CAAC,KAAKC,SAAV,EAAqB;AACnB,aAAKA,SAAL,GAAiB,IAAIC,eAAJ,CAAc;AAC7BX,UAAAA,MAAM,EAAE,KAAKA,MADgB;AAE7BI,UAAAA,IAAI,EAAE,KAAKA,IAFkB;AAG7BQ,UAAAA,SAAS,EAAE,KAAKA;AAHa,SAAd,CAAjB;AAKD;;AAED,aAAO,KAAKF,SAAZ;AACD;AAED;AACF;AACA;AACA;;;;WACE,sBAAaH,MAAb,EAA6BK,SAA7B,EAAiD;AAC/C,WAAKL,MAAL,GAAcA,MAAd;AACA,WAAKK,SAAL,GAAiBA,SAAjB;AAEA;AACD;AAED;AACF;AACA;AACA;;;;WACE,2BAAwC;AAAA,UAAxBC,cAAwB,uEAAP,KAAO;AACtC,aAAOA,cAAc,GAAG,KAAKN,MAAL,IAAe,KAAKK,SAAvB,GAAmC,KAAKL,MAA7D;AACD,K,CAED;;;;WACA,oBAAW;AACT,UAAI,CAAC,KAAKG,SAAV,EAAqB;AACrB,WAAKA,SAAL,CAAeI,MAAf,CAAsBC,UAAtB;AACD;;;;;eAGYhB,K","sourcesContent":["import ApiClient from \"./api\";\nimport FeedClient from \"./clients/feed\";\nimport Preferences from \"./clients/preferences\";\nimport { KnockOptions } from \"./interfaces\";\n\nconst DEFAULT_HOST = \"https://api.knock.app\";\n\nclass Knock {\n private host: string;\n private apiClient: ApiClient | null = null;\n public userId: string | undefined;\n public userToken: string | undefined;\n\n readonly feeds = new FeedClient(this);\n readonly preferences = new Preferences(this);\n\n constructor(readonly apiKey: string, options: KnockOptions = {}) {\n this.host = options.host || DEFAULT_HOST;\n\n // Fail loudly if we're using the wrong API key\n if (this.apiKey && this.apiKey.startsWith(\"sk_\")) {\n throw new Error(\n \"[Knock] You are using your secret API key on the client. Please use the public key.\",\n );\n }\n }\n\n client() {\n if (!this.userId) {\n console.warn(\n `[Knock] You must call authenticate(userId, userToken) first before trying to make a request.\n Typically you'll see this message when you're creating a feed instance before having called\n authenticate with a user Id and token. That means we won't know who to issue the request\n to Knock on behalf of.\n `,\n );\n }\n\n // Initiate a new API client if we don't have one yet\n if (!this.apiClient) {\n this.apiClient = new ApiClient({\n apiKey: this.apiKey,\n host: this.host,\n userToken: this.userToken,\n });\n }\n\n return this.apiClient;\n }\n\n /*\n Authenticates the current user. In non-sandbox environments\n the userToken must be specified.\n */\n authenticate(userId: string, userToken?: string) {\n this.userId = userId;\n this.userToken = userToken;\n\n return;\n }\n\n /*\n Returns whether or this Knock instance is authenticated. Passing `true` will check the presence\n of the userToken as well.\n */\n isAuthenticated(checkUserToken = false) {\n return checkUserToken ? this.userId && this.userToken : this.userId;\n }\n\n // Used to teardown any connected instances\n teardown() {\n if (!this.apiClient) return;\n this.apiClient.socket.disconnect();\n }\n}\n\nexport default Knock;\n"],"file":"knock.js"}
|
package/dist/esm/knock.js
CHANGED
|
@@ -11,12 +11,12 @@ class Knock {
|
|
|
11
11
|
|
|
12
12
|
_defineProperty(this, "host", void 0);
|
|
13
13
|
|
|
14
|
-
_defineProperty(this, "userToken", void 0);
|
|
15
|
-
|
|
16
14
|
_defineProperty(this, "apiClient", null);
|
|
17
15
|
|
|
18
16
|
_defineProperty(this, "userId", void 0);
|
|
19
17
|
|
|
18
|
+
_defineProperty(this, "userToken", void 0);
|
|
19
|
+
|
|
20
20
|
_defineProperty(this, "feeds", new FeedClient(this));
|
|
21
21
|
|
|
22
22
|
_defineProperty(this, "preferences", new Preferences(this));
|
|
@@ -29,7 +29,7 @@ class Knock {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
client() {
|
|
32
|
-
if (!this.userId
|
|
32
|
+
if (!this.userId) {
|
|
33
33
|
console.warn("[Knock] You must call authenticate(userId, userToken) first before trying to make a request.\n Typically you'll see this message when you're creating a feed instance before having called\n authenticate with a user Id and token. That means we won't know who to issue the request\n to Knock on behalf of.\n ");
|
|
34
34
|
} // Initiate a new API client if we don't have one yet
|
|
35
35
|
|
|
@@ -54,6 +54,16 @@ class Knock {
|
|
|
54
54
|
this.userId = userId;
|
|
55
55
|
this.userToken = userToken;
|
|
56
56
|
return;
|
|
57
|
+
}
|
|
58
|
+
/*
|
|
59
|
+
Returns whether or this Knock instance is authenticated. Passing `true` will check the presence
|
|
60
|
+
of the userToken as well.
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
isAuthenticated() {
|
|
65
|
+
var checkUserToken = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
66
|
+
return checkUserToken ? this.userId && this.userToken : this.userId;
|
|
57
67
|
} // Used to teardown any connected instances
|
|
58
68
|
|
|
59
69
|
|
package/dist/esm/knock.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/knock.ts"],"names":["ApiClient","FeedClient","Preferences","DEFAULT_HOST","Knock","constructor","apiKey","options","host","startsWith","Error","client","userId","
|
|
1
|
+
{"version":3,"sources":["../../src/knock.ts"],"names":["ApiClient","FeedClient","Preferences","DEFAULT_HOST","Knock","constructor","apiKey","options","host","startsWith","Error","client","userId","console","warn","apiClient","userToken","authenticate","isAuthenticated","checkUserToken","teardown","socket","disconnect"],"mappings":";AAAA,OAAOA,SAAP,MAAsB,OAAtB;AACA,OAAOC,UAAP,MAAuB,gBAAvB;AACA,OAAOC,WAAP,MAAwB,uBAAxB;AAGA,IAAMC,YAAY,GAAG,uBAArB;;AAEA,MAAMC,KAAN,CAAY;AASVC,EAAAA,WAAW,CAAUC,MAAV,EAAsD;AAAA,QAA5BC,OAA4B,uEAAJ,EAAI;AAAA,SAA5CD,MAA4C,GAA5CA,MAA4C;;AAAA;;AAAA,uCAP3B,IAO2B;;AAAA;;AAAA;;AAAA,mCAHhD,IAAIL,UAAJ,CAAe,IAAf,CAGgD;;AAAA,yCAF1C,IAAIC,WAAJ,CAAgB,IAAhB,CAE0C;;AAC/D,SAAKM,IAAL,GAAYD,OAAO,CAACC,IAAR,IAAgBL,YAA5B,CAD+D,CAG/D;;AACA,QAAI,KAAKG,MAAL,IAAe,KAAKA,MAAL,CAAYG,UAAZ,CAAuB,KAAvB,CAAnB,EAAkD;AAChD,YAAM,IAAIC,KAAJ,CACJ,qFADI,CAAN;AAGD;AACF;;AAEDC,EAAAA,MAAM,GAAG;AACP,QAAI,CAAC,KAAKC,MAAV,EAAkB;AAChBC,MAAAA,OAAO,CAACC,IAAR;AAOD,KATM,CAWP;;;AACA,QAAI,CAAC,KAAKC,SAAV,EAAqB;AACnB,WAAKA,SAAL,GAAiB,IAAIf,SAAJ,CAAc;AAC7BM,QAAAA,MAAM,EAAE,KAAKA,MADgB;AAE7BE,QAAAA,IAAI,EAAE,KAAKA,IAFkB;AAG7BQ,QAAAA,SAAS,EAAE,KAAKA;AAHa,OAAd,CAAjB;AAKD;;AAED,WAAO,KAAKD,SAAZ;AACD;AAED;AACF;AACA;AACA;;;AACEE,EAAAA,YAAY,CAACL,MAAD,EAAiBI,SAAjB,EAAqC;AAC/C,SAAKJ,MAAL,GAAcA,MAAd;AACA,SAAKI,SAAL,GAAiBA,SAAjB;AAEA;AACD;AAED;AACF;AACA;AACA;;;AACEE,EAAAA,eAAe,GAAyB;AAAA,QAAxBC,cAAwB,uEAAP,KAAO;AACtC,WAAOA,cAAc,GAAG,KAAKP,MAAL,IAAe,KAAKI,SAAvB,GAAmC,KAAKJ,MAA7D;AACD,GA5DS,CA8DV;;;AACAQ,EAAAA,QAAQ,GAAG;AACT,QAAI,CAAC,KAAKL,SAAV,EAAqB;AACrB,SAAKA,SAAL,CAAeM,MAAf,CAAsBC,UAAtB;AACD;;AAlES;;AAqEZ,eAAelB,KAAf","sourcesContent":["import ApiClient from \"./api\";\nimport FeedClient from \"./clients/feed\";\nimport Preferences from \"./clients/preferences\";\nimport { KnockOptions } from \"./interfaces\";\n\nconst DEFAULT_HOST = \"https://api.knock.app\";\n\nclass Knock {\n private host: string;\n private apiClient: ApiClient | null = null;\n public userId: string | undefined;\n public userToken: string | undefined;\n\n readonly feeds = new FeedClient(this);\n readonly preferences = new Preferences(this);\n\n constructor(readonly apiKey: string, options: KnockOptions = {}) {\n this.host = options.host || DEFAULT_HOST;\n\n // Fail loudly if we're using the wrong API key\n if (this.apiKey && this.apiKey.startsWith(\"sk_\")) {\n throw new Error(\n \"[Knock] You are using your secret API key on the client. Please use the public key.\",\n );\n }\n }\n\n client() {\n if (!this.userId) {\n console.warn(\n `[Knock] You must call authenticate(userId, userToken) first before trying to make a request.\n Typically you'll see this message when you're creating a feed instance before having called\n authenticate with a user Id and token. That means we won't know who to issue the request\n to Knock on behalf of.\n `,\n );\n }\n\n // Initiate a new API client if we don't have one yet\n if (!this.apiClient) {\n this.apiClient = new ApiClient({\n apiKey: this.apiKey,\n host: this.host,\n userToken: this.userToken,\n });\n }\n\n return this.apiClient;\n }\n\n /*\n Authenticates the current user. In non-sandbox environments\n the userToken must be specified.\n */\n authenticate(userId: string, userToken?: string) {\n this.userId = userId;\n this.userToken = userToken;\n\n return;\n }\n\n /*\n Returns whether or this Knock instance is authenticated. Passing `true` will check the presence\n of the userToken as well.\n */\n isAuthenticated(checkUserToken = false) {\n return checkUserToken ? this.userId && this.userToken : this.userId;\n }\n\n // Used to teardown any connected instances\n teardown() {\n if (!this.apiClient) return;\n this.apiClient.socket.disconnect();\n }\n}\n\nexport default Knock;\n"],"file":"knock.js"}
|
package/dist/types/knock.d.ts
CHANGED
|
@@ -5,14 +5,15 @@ import { KnockOptions } from "./interfaces";
|
|
|
5
5
|
declare class Knock {
|
|
6
6
|
readonly apiKey: string;
|
|
7
7
|
private host;
|
|
8
|
-
private userToken;
|
|
9
8
|
private apiClient;
|
|
10
9
|
userId: string | undefined;
|
|
10
|
+
userToken: string | undefined;
|
|
11
11
|
readonly feeds: FeedClient;
|
|
12
12
|
readonly preferences: Preferences;
|
|
13
13
|
constructor(apiKey: string, options?: KnockOptions);
|
|
14
14
|
client(): ApiClient;
|
|
15
15
|
authenticate(userId: string, userToken?: string): void;
|
|
16
|
+
isAuthenticated(checkUserToken?: boolean): string | undefined;
|
|
16
17
|
teardown(): void;
|
|
17
18
|
}
|
|
18
19
|
export default Knock;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"knock.d.ts","sourceRoot":"","sources":["../../src/knock.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,OAAO,CAAC;AAC9B,OAAO,UAAU,MAAM,gBAAgB,CAAC;AACxC,OAAO,WAAW,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAI5C,cAAM,KAAK;IASG,QAAQ,CAAC,MAAM,EAAE,MAAM;IARnC,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,SAAS,
|
|
1
|
+
{"version":3,"file":"knock.d.ts","sourceRoot":"","sources":["../../src/knock.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,OAAO,CAAC;AAC9B,OAAO,UAAU,MAAM,gBAAgB,CAAC;AACxC,OAAO,WAAW,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAI5C,cAAM,KAAK;IASG,QAAQ,CAAC,MAAM,EAAE,MAAM;IARnC,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,SAAS,CAA0B;IACpC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAErC,QAAQ,CAAC,KAAK,aAAwB;IACtC,QAAQ,CAAC,WAAW,cAAyB;gBAExB,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB;IAW/D,MAAM;IA2BN,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM;IAW/C,eAAe,CAAC,cAAc,UAAQ;IAKtC,QAAQ;CAIT;AAED,eAAe,KAAK,CAAC"}
|