@storecraft/sdk 1.0.8 → 1.0.9

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 CHANGED
@@ -14,6 +14,8 @@ convenient manner with `javascript`, such as:
14
14
  `storage`, `storefronts`, `shipping`, `statistics`, `tags`, `posts`, `notifications`,
15
15
  `templates`, `extensions` and more :)
16
16
 
17
+ Plus, everything is typed so you dont have to guess any parameter or queryable key
18
+
17
19
  ```bash
18
20
  npm i @storecraft/sdk
19
21
  ```
@@ -111,10 +113,14 @@ const auth_result = await sdk.auth.signout();
111
113
  ## Querying
112
114
 
113
115
 
114
- Here are some examples for querying
116
+ Here are some examples for querying.
115
117
 
118
+ - Every key and string in the example below is fully typed with `typescript`,
119
+ - so you get **intellisense** out of the box for better developer experience
120
+ - And, you don't have to guess anything
116
121
 
117
- ```js
122
+
123
+ ```ts
118
124
  import { StorecraftSDK } from '@storecraft/sdk'
119
125
 
120
126
  const sdk = new StorecraftSDK();
@@ -122,10 +128,10 @@ const sdk = new StorecraftSDK();
122
128
  const products: ProductType[] = await sdk.products.list(
123
129
  {
124
130
  expand: ['collections', 'variants'],
125
- sortBy: ['updated_at', 'id'],
131
+ sortBy: ['updated_at', 'id'], // all keys will show up in intellisense
126
132
  order: 'desc',
127
133
  startAt: [
128
- ['updated_at': '2024-03-24']
134
+ ['updated_at': '2024-03-24'],
129
135
  ],
130
136
  limit: 5,
131
137
  vql: '(keyword1 | keyword2) -(keyword3)'
@@ -134,6 +140,21 @@ const products: ProductType[] = await sdk.products.list(
134
140
 
135
141
  ```
136
142
 
143
+ Or,
144
+
145
+ ```ts
146
+ import { StorecraftSDK } from '@storecraft/sdk'
147
+
148
+ const sdk = new StorecraftSDK();
149
+
150
+ const collections: CollectionType[] = await sdk.collections.list(
151
+ {
152
+ equals: [['active': true]]
153
+ limit: 5,
154
+ }
155
+ );
156
+
157
+ ```
137
158
 
138
159
  ```text
139
160
  Author: Tomer Shalev (tomer.shalev@gmail.com)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storecraft/sdk",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "Official storecraft Universal Javascript SDK",
5
5
  "license": "MIT",
6
6
  "author": "Tomer Shalev (https://github.com/store-craft)",
@@ -19,6 +19,7 @@
19
19
  "scripts": {
20
20
  "sdk:test": "echo \"Error: no test specified\" && exit 1",
21
21
  "test": "npm run sdk:test",
22
+ "sc-publish": "npm publish",
22
23
  "prepublishOnly": "npm version patch --force"
23
24
  },
24
25
  "type": "module",
package/src/auth.js CHANGED
@@ -1,3 +1,10 @@
1
+ /**
2
+ * @import {
3
+ * ApiAuthChangePasswordType, ApiAuthResult, ApiAuthSigninType, ApiAuthSignupType,
4
+ * ApiKeyResult, ApiQuery, AuthUserType, error
5
+ * } from '@storecraft/core/api'
6
+ */
7
+
1
8
  import { api_query_to_searchparams } from '@storecraft/core/api/utils.query.js';
2
9
  import { StorecraftSDK } from '../index.js';
3
10
  import { fetchApiWithAuth, url } from './utils.api.fetch.js';
@@ -136,7 +143,7 @@ export default class Auth {
136
143
  }
137
144
  );
138
145
 
139
- /** @type {import('@storecraft/core/api').ApiAuthResult} */
146
+ /** @type {ApiAuthResult} */
140
147
  let payload = undefined;
141
148
 
142
149
  if(auth_res.ok) {
@@ -203,7 +210,7 @@ export default class Auth {
203
210
 
204
211
  /**
205
212
  *
206
- * @param {import('@storecraft/core/api').ApiAuthResult} user
213
+ * @param {ApiAuthResult} user
207
214
  */
208
215
  #_update_and_notify_subscribers = (user) => {
209
216
  this.currentAuth = user
@@ -217,12 +224,12 @@ export default class Auth {
217
224
  * @param {string} password
218
225
  *
219
226
  *
220
- * @returns {Promise<import('@storecraft/core/api').ApiAuthResult>}
227
+ * @returns {Promise<ApiAuthResult>}
221
228
  */
222
229
  signin = async (email, password) => {
223
230
  // console.log('ep ', email, password)
224
231
 
225
- /** @type {import('@storecraft/core/api').ApiAuthSigninType} */
232
+ /** @type {ApiAuthSigninType} */
226
233
  const info = {
227
234
  email, password
228
235
  }
@@ -239,7 +246,7 @@ export default class Auth {
239
246
  );
240
247
 
241
248
  if(!res.ok) {
242
- /** @type {import('@storecraft/core/api').error} */
249
+ /** @type {error} */
243
250
  let error_payload = {
244
251
  messages: [
245
252
  {
@@ -257,7 +264,7 @@ export default class Auth {
257
264
  }
258
265
  // assert(res.ok, 'auth/error2');
259
266
 
260
- /** @type {import('@storecraft/core/api').ApiAuthResult} */
267
+ /** @type {ApiAuthResult} */
261
268
  const payload = await res.json();
262
269
 
263
270
  // console.log('auth_result', payload)
@@ -278,7 +285,7 @@ export default class Auth {
278
285
  * @param {string} [lastname]
279
286
  */
280
287
  signup = async (email, password, firstname, lastname) => {
281
- /** @type {import('@storecraft/core/api').ApiAuthSignupType} */
288
+ /** @type {ApiAuthSignupType} */
282
289
  const info = {
283
290
  email, password,
284
291
  firstname, lastname
@@ -297,7 +304,7 @@ export default class Auth {
297
304
 
298
305
  assert(res.ok, 'auth/error');
299
306
 
300
- /** @type {import('@storecraft/core/api').ApiAuthResult} */
307
+ /** @type {ApiAuthResult} */
301
308
  const payload = await res.json();
302
309
 
303
310
  this.#_update_and_notify_subscribers(
@@ -310,7 +317,7 @@ export default class Auth {
310
317
 
311
318
  /**
312
319
  *
313
- * @param {import('@storecraft/core/api').ApiAuthChangePasswordType} params
320
+ * @param {ApiAuthChangePasswordType} params
314
321
  */
315
322
 
316
323
  changePassword = async (params) => {
@@ -327,7 +334,7 @@ export default class Auth {
327
334
  );
328
335
 
329
336
  if(!res.ok) {
330
- /** @type {import('@storecraft/core/api').error} */
337
+ /** @type {error} */
331
338
  let error_payload = {
332
339
  messages: [
333
340
  {
@@ -344,7 +351,7 @@ export default class Auth {
344
351
  throw error_payload;
345
352
  }
346
353
 
347
- /** @type {import('@storecraft/core/api').ApiAuthResult} */
354
+ /** @type {ApiAuthResult} */
348
355
  const payload = await res.json();
349
356
 
350
357
  this.#_update_and_notify_subscribers(
@@ -367,7 +374,7 @@ export default class Auth {
367
374
 
368
375
 
369
376
  create_api_key = async () => {
370
- /** @type {import('@storecraft/core/api').ApiKeyResult} */
377
+ /** @type {ApiKeyResult} */
371
378
  const item = await fetchApiWithAuth(
372
379
  this.#sdk,
373
380
  '/auth/apikeys',
@@ -386,7 +393,7 @@ export default class Auth {
386
393
  * @param {string} email_or_id
387
394
  */
388
395
  get_auth_user = async (email_or_id) => {
389
- /** @type {import('@storecraft/core/api').AuthUserType} */
396
+ /** @type {AuthUserType} */
390
397
  const item = await fetchApiWithAuth(
391
398
  this.#sdk,
392
399
  `/auth/users/${email_or_id}`,
@@ -417,25 +424,26 @@ export default class Auth {
417
424
  /**
418
425
  *
419
426
  *
420
- * @param {import('@storecraft/core/api').ApiQuery} query
427
+ * @param {ApiQuery<AuthUserType>} query
421
428
  *
422
429
  */
423
430
  list_auth_users = async (query) => {
424
431
  const sq = api_query_to_searchparams(query);
425
-
426
- return fetchApiWithAuth(
432
+ /** @type {AuthUserType[]} */
433
+ const items = await fetchApiWithAuth(
427
434
  this.#sdk,
428
435
  `/auth/users?${sq.toString()}`,
429
436
  {
430
437
  method: 'get'
431
438
  }
432
439
  );
440
+ return items;
433
441
  }
434
442
 
435
443
 
436
444
  list_api_keys_auth_users = async () => {
437
445
 
438
- /** @type {import('@storecraft/core/api').AuthUserType[]} */
446
+ /** @type {AuthUserType[]} */
439
447
  const items = await fetchApiWithAuth(
440
448
  this.#sdk,
441
449
  '/auth/apikeys',
@@ -183,7 +183,7 @@ export async function remove(sdk, resource, handle_or_id) {
183
183
  *
184
184
  * @param {import('../index.js').StorecraftSDK} sdk
185
185
  * @param {string} resource base path of resource
186
- * @param {import('@storecraft/core/api').ApiQuery} [query]
186
+ * @param {import('@storecraft/core/api').ApiQuery<G>} [query]
187
187
  *
188
188
  *
189
189
  * @returns {Promise<G[]>}
@@ -262,7 +262,7 @@ export class collection_base {
262
262
 
263
263
  /**
264
264
  *
265
- * @param {import('@storecraft/core/api').ApiQuery} query Query object
265
+ * @param {import('@storecraft/core/api').ApiQuery<G>} query Query object
266
266
  *
267
267
  *
268
268
  * @returns {Promise<G[]>}