@jwork-space/strapi-sdk 1.0.5 → 1.0.7

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/index.d.mts CHANGED
@@ -212,6 +212,8 @@ declare class StrapiSDK<T extends BaseModel> extends BaseAPI<T> {
212
212
  findAndUpdate(data: T, optFilter: RequestOptions<T>, optPayload?: RequestOptions<T>, serializeOptionsPayload?: SerializeOptions): Promise<T | undefined>;
213
213
  finOneEntity: (opt?: RequestOptions<T>) => Promise<T | null>;
214
214
  upsert(data: T, opt?: RequestOptions<T>, serializeOptions?: SerializeOptions): Promise<T>;
215
+ invalidateQueries: (keys: (string | unknown[])[]) => () => Promise<void>;
216
+ invalidateListAll: () => () => Promise<void>;
215
217
  }
216
218
 
217
219
  type AnyObject = Record<string, any>;
package/dist/index.d.ts CHANGED
@@ -212,6 +212,8 @@ declare class StrapiSDK<T extends BaseModel> extends BaseAPI<T> {
212
212
  findAndUpdate(data: T, optFilter: RequestOptions<T>, optPayload?: RequestOptions<T>, serializeOptionsPayload?: SerializeOptions): Promise<T | undefined>;
213
213
  finOneEntity: (opt?: RequestOptions<T>) => Promise<T | null>;
214
214
  upsert(data: T, opt?: RequestOptions<T>, serializeOptions?: SerializeOptions): Promise<T>;
215
+ invalidateQueries: (keys: (string | unknown[])[]) => () => Promise<void>;
216
+ invalidateListAll: () => () => Promise<void>;
215
217
  }
216
218
 
217
219
  type AnyObject = Record<string, any>;
package/dist/index.js CHANGED
@@ -706,6 +706,20 @@ var StrapiSDK = class extends BaseAPI {
706
706
  const list = data;
707
707
  return list.length > 0 ? list[0] : null;
708
708
  };
709
+ this.invalidateQueries = (keys) => {
710
+ const queryClient = (0, import_react_query.useQueryClient)();
711
+ return async () => {
712
+ if (!keys || keys.length === 0) return;
713
+ for (const key of keys) {
714
+ await queryClient.invalidateQueries({
715
+ queryKey: Array.isArray(key) ? key : [key]
716
+ });
717
+ }
718
+ };
719
+ };
720
+ this.invalidateListAll = () => {
721
+ return this.invalidateQueries([[this.endpoint, "listAll"]]);
722
+ };
709
723
  this.config = {
710
724
  onCreate: {
711
725
  generateUID: config?.onCreate?.generateUID ?? true,
@@ -836,7 +850,7 @@ var StrapiUploaderSDK = class extends BaseUploaderAPI {
836
850
  const prefix = config?.prefix ?? "";
837
851
  super(resource, prefix, config?.tokenKey, baseURL);
838
852
  this.uploadStrapiFile = async (resource, opt) => {
839
- const uri = opt?.url ?? `${this.baseURL}/upload`;
853
+ const uri = opt?.url ?? this.endpoint;
840
854
  const data = this.getRequestParams(opt);
841
855
  const formData = new FormData();
842
856
  const isMultiple = Array.isArray(resource);
@@ -970,7 +984,7 @@ var StrapiUploaderSDK = class extends BaseUploaderAPI {
970
984
  };
971
985
  this.newUploadFile = async (resource, opt, serializeOptions) => {
972
986
  const options = { ...serializeOptions };
973
- const uri = opt?.url ?? "/strapi/upload-file";
987
+ const uri = opt?.url ?? this.endpoint;
974
988
  const data = this.getRequestParams(opt);
975
989
  options.exclude = ["id", ...options.exclude ?? []];
976
990
  const formData = new FormData();
@@ -979,6 +993,9 @@ var StrapiUploaderSDK = class extends BaseUploaderAPI {
979
993
  const dataResponse = await this.postCall(uri, data);
980
994
  return dataResponse;
981
995
  };
996
+ const paths = [prefix, resource];
997
+ const pathURL = this.normalizePath(this.buildPath(...paths));
998
+ this.endpoint = `${baseURL}${pathURL}`;
982
999
  this.config = {
983
1000
  onCreate: {
984
1001
  generateUID: config?.onCreate?.generateUID ?? true,
@@ -1017,7 +1034,7 @@ var StrapiUploaderSDK = class extends BaseUploaderAPI {
1017
1034
  return options;
1018
1035
  }
1019
1036
  async destroyFile(id) {
1020
- const uri = `${this.baseURL}/strapi/upload/files/${id}`;
1037
+ const uri = `${this.endpoint}/${id}`;
1021
1038
  await this.deleteCall(uri);
1022
1039
  return true;
1023
1040
  }
package/dist/index.mjs CHANGED
@@ -657,6 +657,20 @@ var StrapiSDK = class extends BaseAPI {
657
657
  const list = data;
658
658
  return list.length > 0 ? list[0] : null;
659
659
  };
660
+ this.invalidateQueries = (keys) => {
661
+ const queryClient = useQueryClient();
662
+ return async () => {
663
+ if (!keys || keys.length === 0) return;
664
+ for (const key of keys) {
665
+ await queryClient.invalidateQueries({
666
+ queryKey: Array.isArray(key) ? key : [key]
667
+ });
668
+ }
669
+ };
670
+ };
671
+ this.invalidateListAll = () => {
672
+ return this.invalidateQueries([[this.endpoint, "listAll"]]);
673
+ };
660
674
  this.config = {
661
675
  onCreate: {
662
676
  generateUID: config?.onCreate?.generateUID ?? true,
@@ -787,7 +801,7 @@ var StrapiUploaderSDK = class extends BaseUploaderAPI {
787
801
  const prefix = config?.prefix ?? "";
788
802
  super(resource, prefix, config?.tokenKey, baseURL);
789
803
  this.uploadStrapiFile = async (resource, opt) => {
790
- const uri = opt?.url ?? `${this.baseURL}/upload`;
804
+ const uri = opt?.url ?? this.endpoint;
791
805
  const data = this.getRequestParams(opt);
792
806
  const formData = new FormData();
793
807
  const isMultiple = Array.isArray(resource);
@@ -921,7 +935,7 @@ var StrapiUploaderSDK = class extends BaseUploaderAPI {
921
935
  };
922
936
  this.newUploadFile = async (resource, opt, serializeOptions) => {
923
937
  const options = { ...serializeOptions };
924
- const uri = opt?.url ?? "/strapi/upload-file";
938
+ const uri = opt?.url ?? this.endpoint;
925
939
  const data = this.getRequestParams(opt);
926
940
  options.exclude = ["id", ...options.exclude ?? []];
927
941
  const formData = new FormData();
@@ -930,6 +944,9 @@ var StrapiUploaderSDK = class extends BaseUploaderAPI {
930
944
  const dataResponse = await this.postCall(uri, data);
931
945
  return dataResponse;
932
946
  };
947
+ const paths = [prefix, resource];
948
+ const pathURL = this.normalizePath(this.buildPath(...paths));
949
+ this.endpoint = `${baseURL}${pathURL}`;
933
950
  this.config = {
934
951
  onCreate: {
935
952
  generateUID: config?.onCreate?.generateUID ?? true,
@@ -968,7 +985,7 @@ var StrapiUploaderSDK = class extends BaseUploaderAPI {
968
985
  return options;
969
986
  }
970
987
  async destroyFile(id) {
971
- const uri = `${this.baseURL}/strapi/upload/files/${id}`;
988
+ const uri = `${this.endpoint}/${id}`;
972
989
  await this.deleteCall(uri);
973
990
  return true;
974
991
  }
package/package.json CHANGED
@@ -1,66 +1,67 @@
1
1
  {
2
- "name": "@jwork-space/strapi-sdk",
3
- "version": "1.0.5",
4
- "description": "SDK para Strapi con soporte para React Query y TypeScript",
5
- "main": "dist/index.js",
6
- "module": "dist/index.mjs",
7
- "types": "dist/index.d.ts",
8
- "author": "Roman Ernesto Gonzalez Alas, Jonathan Fernando González Ramos",
9
- "license": "MIT",
10
- "repository": {
11
- "type": "git",
12
- "url": "https://gitlab.com/Jona11/strapi-sdk"
13
- },
14
- "publishConfig": {
15
- "access": "public"
16
- },
17
- "engines": {
18
- "node": ">=18.0.0"
19
- },
20
- "peerDependencies": {
21
- "@tanstack/react-query": ">=5.90.0",
22
- "antd": ">=5.0.0",
23
- "axios": ">=1.7.0",
24
- "dayjs": ">=1.11.10",
25
- "qs": ">=6.11.0",
26
- "react": ">=18.0.0",
27
- "react-dom": ">=18.0.0"
28
- },
29
- "devDependencies": {
30
- "@semantic-release/git": "^10.0.1",
31
- "@semantic-release/gitlab": "^13.2.9",
32
- "@semantic-release/npm": "^13.1.2",
33
- "@types/qs": "^6.14.0",
34
- "@types/react": "^19.2.2",
35
- "@types/react-dom": "^19.2.2",
36
- "semantic-release": "^25.0.2",
37
- "tsup": "^8.5.0",
38
- "typescript": "^5.9.3"
39
- },
40
- "release": {
41
- "plugins": [
42
- "@semantic-release/commit-analyzer",
43
- "@semantic-release/release-notes-generator",
44
- "@semantic-release/npm",
45
- "@semantic-release/gitlab",
46
- [
47
- "@semantic-release/git",
48
- {
49
- "assets": [
50
- "package.json"
51
- ],
52
- "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
53
- }
54
- ]
2
+ "name": "@jwork-space/strapi-sdk",
3
+ "version": "1.0.7",
4
+ "description": "SDK para Strapi con soporte para React Query y TypeScript",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "author": "Roman Ernesto Gonzalez Alas, Jonathan Fernando González Ramos",
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://gitlab.com/Jona11/strapi-sdk"
13
+ },
14
+ "scripts": {
15
+ "build": "tsup src/index.ts --format esm,cjs --dts",
16
+ "prepublishOnly": "npm run build",
17
+ "dev": "tsup src/index.ts --format esm,cjs --dts --watch",
18
+ "semantic-release": "semantic-release"
19
+ },
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "engines": {
24
+ "node": ">=18.0.0"
25
+ },
26
+ "peerDependencies": {
27
+ "@tanstack/react-query": ">=5.90.0",
28
+ "antd": ">=5.0.0",
29
+ "axios": ">=1.7.0",
30
+ "dayjs": ">=1.11.10",
31
+ "qs": ">=6.11.0",
32
+ "react": ">=18.0.0",
33
+ "react-dom": ">=18.0.0"
34
+ },
35
+ "devDependencies": {
36
+ "@semantic-release/git": "^10.0.1",
37
+ "@semantic-release/gitlab": "^13.2.9",
38
+ "@semantic-release/npm": "^13.1.2",
39
+ "@types/qs": "^6.14.0",
40
+ "@types/react": "^19.2.2",
41
+ "@types/react-dom": "^19.2.2",
42
+ "semantic-release": "^25.0.2",
43
+ "tsup": "^8.5.0",
44
+ "typescript": "^5.9.3"
45
+ },
46
+ "release": {
47
+ "plugins": [
48
+ "@semantic-release/commit-analyzer",
49
+ "@semantic-release/release-notes-generator",
50
+ "@semantic-release/npm",
51
+ "@semantic-release/gitlab",
52
+ [
53
+ "@semantic-release/git",
54
+ {
55
+ "assets": [
56
+ "package.json"
57
+ ],
58
+ "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
59
+ }
60
+ ]
61
+ ]
62
+ },
63
+ "files": [
64
+ "dist",
65
+ "README.md"
55
66
  ]
56
- },
57
- "files": [
58
- "dist",
59
- "README.md"
60
- ],
61
- "scripts": {
62
- "build": "tsup src/index.ts --format esm,cjs --dts",
63
- "dev": "tsup src/index.ts --format esm,cjs --dts --watch",
64
- "semantic-release": "semantic-release"
65
- }
66
- }
67
+ }