strapi-rest-lite 0.1.0 → 0.1.3

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.
Files changed (109) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +61 -39
  3. package/dist/index.d.ts +18 -5
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +18 -5
  6. package/dist/index.js.map +1 -0
  7. package/dist/models/article.d.ts +21 -0
  8. package/dist/models/article.d.ts.map +1 -0
  9. package/dist/models/article.js +2 -0
  10. package/dist/models/article.js.map +1 -0
  11. package/dist/models/author.d.ts +13 -0
  12. package/dist/models/author.d.ts.map +1 -0
  13. package/dist/models/author.js +2 -0
  14. package/dist/models/author.js.map +1 -0
  15. package/dist/models/category.d.ts +11 -0
  16. package/dist/models/category.d.ts.map +1 -0
  17. package/dist/models/category.js +2 -0
  18. package/dist/models/category.js.map +1 -0
  19. package/dist/models/index.d.ts +6 -0
  20. package/dist/models/index.d.ts.map +1 -0
  21. package/dist/models/index.js +6 -0
  22. package/dist/models/index.js.map +1 -0
  23. package/dist/models/page.d.ts +13 -0
  24. package/dist/models/page.d.ts.map +1 -0
  25. package/dist/models/page.js +2 -0
  26. package/dist/models/page.js.map +1 -0
  27. package/dist/models/product.d.ts +14 -0
  28. package/dist/models/product.d.ts.map +1 -0
  29. package/dist/models/product.js +2 -0
  30. package/dist/models/product.js.map +1 -0
  31. package/dist/repositories/article-repository.d.ts +6 -0
  32. package/dist/repositories/article-repository.d.ts.map +1 -0
  33. package/dist/repositories/article-repository.js +4 -0
  34. package/dist/repositories/article-repository.js.map +1 -0
  35. package/dist/repositories/category-repository.d.ts +6 -0
  36. package/dist/repositories/category-repository.d.ts.map +1 -0
  37. package/dist/repositories/category-repository.js +4 -0
  38. package/dist/repositories/category-repository.js.map +1 -0
  39. package/dist/repositories/collection-repository.d.ts +7 -0
  40. package/dist/repositories/collection-repository.d.ts.map +1 -0
  41. package/dist/repositories/collection-repository.js +29 -0
  42. package/dist/repositories/collection-repository.js.map +1 -0
  43. package/dist/repositories/collections.d.ts +14 -0
  44. package/dist/repositories/collections.d.ts.map +1 -0
  45. package/dist/repositories/collections.js +15 -0
  46. package/dist/repositories/collections.js.map +1 -0
  47. package/dist/repositories/contracts.d.ts +37 -0
  48. package/dist/repositories/contracts.d.ts.map +1 -0
  49. package/dist/repositories/contracts.js +2 -0
  50. package/dist/repositories/contracts.js.map +1 -0
  51. package/dist/repositories/index.d.ts +10 -0
  52. package/dist/repositories/index.d.ts.map +1 -0
  53. package/dist/repositories/index.js +17 -0
  54. package/dist/repositories/index.js.map +1 -0
  55. package/dist/repositories/page-repository.d.ts +6 -0
  56. package/dist/repositories/page-repository.d.ts.map +1 -0
  57. package/dist/repositories/page-repository.js +4 -0
  58. package/dist/repositories/page-repository.js.map +1 -0
  59. package/dist/repositories/product-repository.d.ts +6 -0
  60. package/dist/repositories/product-repository.d.ts.map +1 -0
  61. package/dist/repositories/product-repository.js +4 -0
  62. package/dist/repositories/product-repository.js.map +1 -0
  63. package/dist/repositories/strapi-client.d.ts +4 -0
  64. package/dist/repositories/strapi-client.d.ts.map +1 -0
  65. package/dist/repositories/strapi-client.js +36 -0
  66. package/dist/repositories/strapi-client.js.map +1 -0
  67. package/dist/services/article-service.d.ts +3 -0
  68. package/dist/services/article-service.d.ts.map +1 -0
  69. package/dist/services/article-service.js +7 -0
  70. package/dist/services/article-service.js.map +1 -0
  71. package/dist/services/category-service.d.ts +3 -0
  72. package/dist/services/category-service.d.ts.map +1 -0
  73. package/dist/services/category-service.js +6 -0
  74. package/dist/services/category-service.js.map +1 -0
  75. package/dist/services/collection-service.d.ts +5 -0
  76. package/dist/services/collection-service.d.ts.map +1 -0
  77. package/dist/services/collection-service.js +15 -0
  78. package/dist/services/collection-service.js.map +1 -0
  79. package/dist/services/contracts.d.ts +10 -0
  80. package/dist/services/contracts.d.ts.map +1 -0
  81. package/dist/services/contracts.js +2 -0
  82. package/dist/services/contracts.js.map +1 -0
  83. package/dist/services/index.d.ts +9 -0
  84. package/dist/services/index.d.ts.map +1 -0
  85. package/dist/services/index.js +11 -0
  86. package/dist/services/index.js.map +1 -0
  87. package/dist/services/page-service.d.ts +3 -0
  88. package/dist/services/page-service.d.ts.map +1 -0
  89. package/dist/services/page-service.js +6 -0
  90. package/dist/services/page-service.js.map +1 -0
  91. package/dist/services/product-service.d.ts +3 -0
  92. package/dist/services/product-service.d.ts.map +1 -0
  93. package/dist/services/product-service.js +6 -0
  94. package/dist/services/product-service.js.map +1 -0
  95. package/dist/strapi-client.d.ts +3 -0
  96. package/dist/strapi-client.d.ts.map +1 -0
  97. package/dist/strapi-client.js +2 -0
  98. package/dist/strapi-client.js.map +1 -0
  99. package/package.json +31 -7
  100. package/dist/collection-repository.d.ts +0 -7
  101. package/dist/collection-repository.js +0 -16
  102. package/dist/collection-service.d.ts +0 -9
  103. package/dist/collection-service.js +0 -13
  104. package/dist/http-client.d.ts +0 -7
  105. package/dist/http-client.js +0 -33
  106. package/dist/media.d.ts +0 -4
  107. package/dist/media.js +0 -12
  108. package/dist/types.d.ts +0 -32
  109. package/dist/types.js +0 -1
@@ -0,0 +1,6 @@
1
+ import type { Product } from '../models/product.js';
2
+ import type { CollectionRepository, HttpClient } from './contracts.js';
3
+ import { CollectionName } from './collections.js';
4
+ export type ProductRepository = CollectionRepository<Product>;
5
+ export declare const createProductRepository: (client: HttpClient, collectionName?: CollectionName | string) => ProductRepository;
6
+ //# sourceMappingURL=product-repository.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"product-repository.d.ts","sourceRoot":"","sources":["../../src/repositories/product-repository.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AACnD,OAAO,KAAK,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAEtE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAEjD,MAAM,MAAM,iBAAiB,GAAG,oBAAoB,CAAC,OAAO,CAAC,CAAA;AAE7D,eAAO,MAAM,uBAAuB,GAClC,QAAQ,UAAU,EAClB,iBAAgB,cAAc,GAAG,MAA+B,KAC/D,iBAAgF,CAAA"}
@@ -0,0 +1,4 @@
1
+ import { createCollectionRepository } from './collection-repository.js';
2
+ import { CollectionName } from './collections.js';
3
+ export const createProductRepository = (client, collectionName = CollectionName.Product) => createCollectionRepository(collectionName, client);
4
+ //# sourceMappingURL=product-repository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"product-repository.js","sourceRoot":"","sources":["../../src/repositories/product-repository.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAA;AACvE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAIjD,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,MAAkB,EAClB,iBAA0C,cAAc,CAAC,OAAO,EAC7C,EAAE,CAAC,0BAA0B,CAAU,cAAc,EAAE,MAAM,CAAC,CAAA"}
@@ -0,0 +1,4 @@
1
+ import type { HttpClient, RepositoryQuery } from './contracts.js';
2
+ export declare const createStrapiClient: (apiBase: string) => HttpClient;
3
+ export declare const mergeFilters: (query: RepositoryQuery | undefined, filters: Record<string, unknown>) => RepositoryQuery;
4
+ //# sourceMappingURL=strapi-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strapi-client.d.ts","sourceRoot":"","sources":["../../src/repositories/strapi-client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAEjE,eAAO,MAAM,kBAAkB,GAAI,SAAS,MAAM,KAAG,UA8BpD,CAAA;AAED,eAAO,MAAM,YAAY,GACvB,OAAO,eAAe,GAAG,SAAS,EAClC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC/B,eAMD,CAAA"}
@@ -0,0 +1,36 @@
1
+ import { ofetch } from 'ofetch';
2
+ export const createStrapiClient = (apiBase) => {
3
+ const client = ofetch.create({ baseURL: apiBase });
4
+ const toQueryString = (value, prefix) => {
5
+ if (value === null || value === undefined)
6
+ return '';
7
+ if (typeof value === 'object' && !Array.isArray(value)) {
8
+ return Object.entries(value)
9
+ .map(([key, val]) => toQueryString(val, prefix ? `${prefix}[${key}]` : key))
10
+ .filter(Boolean)
11
+ .join('&');
12
+ }
13
+ if (Array.isArray(value)) {
14
+ return value
15
+ .map((val, index) => toQueryString(val, prefix ? `${prefix}[${index}]` : String(index)))
16
+ .filter(Boolean)
17
+ .join('&');
18
+ }
19
+ return `${encodeURIComponent(prefix ?? '')}=${encodeURIComponent(String(value))}`;
20
+ };
21
+ return {
22
+ get: async (path, params) => {
23
+ const query = params ? toQueryString(params) : '';
24
+ const url = query ? `${path}?${query}` : path;
25
+ return client(url);
26
+ },
27
+ };
28
+ };
29
+ export const mergeFilters = (query, filters) => ({
30
+ ...(query ?? {}),
31
+ filters: {
32
+ ...(query?.filters ?? {}),
33
+ ...filters,
34
+ },
35
+ });
36
+ //# sourceMappingURL=strapi-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strapi-client.js","sourceRoot":"","sources":["../../src/repositories/strapi-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAG/B,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,OAAe,EAAc,EAAE;IAChE,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAA;IAElD,MAAM,aAAa,GAAG,CAAC,KAAU,EAAE,MAAe,EAAU,EAAE;QAC5D,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,EAAE,CAAA;QAEpD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACvD,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;iBACzB,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,aAAa,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;iBAC3E,MAAM,CAAC,OAAO,CAAC;iBACf,IAAI,CAAC,GAAG,CAAC,CAAA;QACd,CAAC;QAED,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,OAAO,KAAK;iBACT,GAAG,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;iBACvF,MAAM,CAAC,OAAO,CAAC;iBACf,IAAI,CAAC,GAAG,CAAC,CAAA;QACd,CAAC;QAED,OAAO,GAAG,kBAAkB,CAAC,MAAM,IAAI,EAAE,CAAC,IAAI,kBAAkB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAA;IACnF,CAAC,CAAA;IAED,OAAO;QACL,GAAG,EAAE,KAAK,EAAK,IAAY,EAAE,MAAY,EAAE,EAAE;YAC3C,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;YACjD,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAA;YAC7C,OAAO,MAAM,CAAI,GAAG,CAAC,CAAA;QACvB,CAAC;KACF,CAAA;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,KAAkC,EAClC,OAAgC,EACf,EAAE,CAAC,CAAC;IACrB,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC;IAChB,OAAO,EAAE;QACP,GAAG,CAAC,KAAK,EAAE,OAAO,IAAI,EAAE,CAAC;QACzB,GAAG,OAAO;KACX;CACF,CAAC,CAAA"}
@@ -0,0 +1,3 @@
1
+ import type { Article } from '../models/article.js';
2
+ export declare const createArticleService: import("./contracts.js").CollectionServiceFactory<Article>;
3
+ //# sourceMappingURL=article-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"article-service.d.ts","sourceRoot":"","sources":["../../src/services/article-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAQnD,eAAO,MAAM,oBAAoB,4DAE/B,CAAA"}
@@ -0,0 +1,7 @@
1
+ import { createCollectionService, withDefaults } from './collection-service.js';
2
+ const createBaseArticleService = (repository) => createCollectionService(repository);
3
+ // Default populate to fetch related author/category/blocks unless overridden.
4
+ export const createArticleService = withDefaults(createBaseArticleService, {
5
+ populate: '*',
6
+ });
7
+ //# sourceMappingURL=article-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"article-service.js","sourceRoot":"","sources":["../../src/services/article-service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAE/E,MAAM,wBAAwB,GAAG,CAAC,UAAyC,EAAE,EAAE,CAC7E,uBAAuB,CAAU,UAAU,CAAC,CAAA;AAE9C,8EAA8E;AAC9E,MAAM,CAAC,MAAM,oBAAoB,GAAG,YAAY,CAAU,wBAAwB,EAAE;IAClF,QAAQ,EAAE,GAAG;CACd,CAAC,CAAA"}
@@ -0,0 +1,3 @@
1
+ import type { Category } from '../models/category.js';
2
+ export declare const createCategoryService: import("./contracts.js").CollectionServiceFactory<Category>;
3
+ //# sourceMappingURL=category-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"category-service.d.ts","sourceRoot":"","sources":["../../src/services/category-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAOrD,eAAO,MAAM,qBAAqB,6DAEhC,CAAA"}
@@ -0,0 +1,6 @@
1
+ import { createCollectionService, withDefaults } from './collection-service.js';
2
+ const createBaseCategoryService = (repository) => createCollectionService(repository);
3
+ export const createCategoryService = withDefaults(createBaseCategoryService, {
4
+ populate: '*',
5
+ });
6
+ //# sourceMappingURL=category-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"category-service.js","sourceRoot":"","sources":["../../src/services/category-service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAE/E,MAAM,yBAAyB,GAAG,CAAC,UAA0C,EAAE,EAAE,CAC/E,uBAAuB,CAAW,UAAU,CAAC,CAAA;AAE/C,MAAM,CAAC,MAAM,qBAAqB,GAAG,YAAY,CAAW,yBAAyB,EAAE;IACrF,QAAQ,EAAE,GAAG;CACd,CAAC,CAAA"}
@@ -0,0 +1,5 @@
1
+ import type { CollectionRepository, RepositoryQuery } from '../repositories/contracts.js';
2
+ import type { CollectionService, CollectionServiceFactory } from './contracts.js';
3
+ export declare const createCollectionService: <T>(repository: CollectionRepository<T>) => CollectionService<T>;
4
+ export declare const withDefaults: <T>(factory: CollectionServiceFactory<T>, defaults: RepositoryQuery) => CollectionServiceFactory<T>;
5
+ //# sourceMappingURL=collection-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collection-service.d.ts","sourceRoot":"","sources":["../../src/services/collection-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAA;AACzF,OAAO,KAAK,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAA;AAGjF,eAAO,MAAM,uBAAuB,GAAI,CAAC,EACvC,YAAY,oBAAoB,CAAC,CAAC,CAAC,KAClC,iBAAiB,CAAC,CAAC,CAIpB,CAAA;AAEF,eAAO,MAAM,YAAY,GAAI,CAAC,EAC5B,SAAS,wBAAwB,CAAC,CAAC,CAAC,EACpC,UAAU,eAAe,KACxB,wBAAwB,CAAC,CAAC,CAQ5B,CAAA"}
@@ -0,0 +1,15 @@
1
+ // Generic service builder: composes a repository and exposes semantic method names.
2
+ export const createCollectionService = (repository) => ({
3
+ list: (query) => repository.findAll(query),
4
+ getById: (id, query) => repository.findOneById(id, query),
5
+ getBySlug: (slug, query) => repository.findOneBySlug(slug, query),
6
+ });
7
+ export const withDefaults = (factory, defaults) => (repository) => {
8
+ const service = factory(repository);
9
+ return {
10
+ list: (query) => service.list({ ...defaults, ...query }),
11
+ getById: (id, query) => service.getById(id, { ...defaults, ...query }),
12
+ getBySlug: (slug, query) => service.getBySlug(slug, { ...defaults, ...query }),
13
+ };
14
+ };
15
+ //# sourceMappingURL=collection-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collection-service.js","sourceRoot":"","sources":["../../src/services/collection-service.ts"],"names":[],"mappings":"AAGA,oFAAoF;AACpF,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,UAAmC,EACb,EAAE,CAAC,CAAC;IAC1B,IAAI,EAAE,CAAC,KAAuB,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC;IAC5D,OAAO,EAAE,CAAC,EAAmB,EAAE,KAAuB,EAAE,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,EAAE,KAAK,CAAC;IAC5F,SAAS,EAAE,CAAC,IAAY,EAAE,KAAuB,EAAE,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC,IAAI,EAAE,KAAK,CAAC;CAC5F,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,OAAoC,EACpC,QAAyB,EACI,EAAE,CAAC,CAAC,UAAU,EAAE,EAAE;IAC/C,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;IAEnC,OAAO;QACL,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,GAAG,QAAQ,EAAE,GAAG,KAAK,EAAE,CAAC;QACxD,OAAO,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,GAAG,QAAQ,EAAE,GAAG,KAAK,EAAE,CAAC;QACtE,SAAS,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,GAAG,QAAQ,EAAE,GAAG,KAAK,EAAE,CAAC;KAC/E,CAAA;AACH,CAAC,CAAA"}
@@ -0,0 +1,10 @@
1
+ import type { CollectionRepository, RepositoryQuery, StrapiCollectionResponse, StrapiSingleResponse } from '../repositories/contracts.js';
2
+ export interface CollectionService<T> {
3
+ list(query?: RepositoryQuery): Promise<StrapiCollectionResponse<T>>;
4
+ getById(id: string | number, query?: RepositoryQuery): Promise<StrapiSingleResponse<T>>;
5
+ getBySlug(slug: string, query?: RepositoryQuery): Promise<StrapiSingleResponse<T>>;
6
+ }
7
+ export interface CollectionServiceFactory<T> {
8
+ (repository: CollectionRepository<T>): CollectionService<T>;
9
+ }
10
+ //# sourceMappingURL=contracts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contracts.d.ts","sourceRoot":"","sources":["../../src/services/contracts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,eAAe,EACf,wBAAwB,EACxB,oBAAoB,EACrB,MAAM,8BAA8B,CAAA;AAErC,MAAM,WAAW,iBAAiB,CAAC,CAAC;IAClC,IAAI,CAAC,KAAK,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC,CAAC,CAAC,CAAA;IACnE,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAA;IACvF,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAA;CACnF;AAED,MAAM,WAAW,wBAAwB,CAAC,CAAC;IACzC,CAAC,UAAU,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAA;CAC5D"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=contracts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contracts.js","sourceRoot":"","sources":["../../src/services/contracts.ts"],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ import type { createRepositories } from '../repositories/index.js';
2
+ export declare const createServices: (repositories: ReturnType<typeof createRepositories>) => {
3
+ articleService: import("./contracts.js").CollectionService<import("../index.js").Article>;
4
+ categoryService: import("./contracts.js").CollectionService<import("../index.js").Category>;
5
+ pageService: import("./contracts.js").CollectionService<import("../index.js").Page>;
6
+ productService: import("./contracts.js").CollectionService<import("../index.js").Product>;
7
+ };
8
+ export type Services = ReturnType<typeof createServices>;
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAElE,eAAO,MAAM,cAAc,GAAI,cAAc,UAAU,CAAC,OAAO,kBAAkB,CAAC;;;;;CAKhF,CAAA;AACF,MAAM,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAA"}
@@ -0,0 +1,11 @@
1
+ import { createArticleService } from './article-service.js';
2
+ import { createCategoryService } from './category-service.js';
3
+ import { createPageService } from './page-service.js';
4
+ import { createProductService } from './product-service.js';
5
+ export const createServices = (repositories) => ({
6
+ articleService: createArticleService(repositories.articleRepository),
7
+ categoryService: createCategoryService(repositories.categoryRepository),
8
+ pageService: createPageService(repositories.pageRepository),
9
+ productService: createProductService(repositories.productRepository),
10
+ });
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAG3D,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,YAAmD,EAAE,EAAE,CAAC,CAAC;IACtF,cAAc,EAAE,oBAAoB,CAAC,YAAY,CAAC,iBAAiB,CAAC;IACpE,eAAe,EAAE,qBAAqB,CAAC,YAAY,CAAC,kBAAkB,CAAC;IACvE,WAAW,EAAE,iBAAiB,CAAC,YAAY,CAAC,cAAc,CAAC;IAC3D,cAAc,EAAE,oBAAoB,CAAC,YAAY,CAAC,iBAAiB,CAAC;CACrE,CAAC,CAAA"}
@@ -0,0 +1,3 @@
1
+ import type { Page } from '../models/page.js';
2
+ export declare const createPageService: import("./contracts.js").CollectionServiceFactory<Page>;
3
+ //# sourceMappingURL=page-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page-service.d.ts","sourceRoot":"","sources":["../../src/services/page-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AAO7C,eAAO,MAAM,iBAAiB,yDAE5B,CAAA"}
@@ -0,0 +1,6 @@
1
+ import { createCollectionService, withDefaults } from './collection-service.js';
2
+ const createBasePageService = (repository) => createCollectionService(repository);
3
+ export const createPageService = withDefaults(createBasePageService, {
4
+ populate: '*',
5
+ });
6
+ //# sourceMappingURL=page-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page-service.js","sourceRoot":"","sources":["../../src/services/page-service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAE/E,MAAM,qBAAqB,GAAG,CAAC,UAAsC,EAAE,EAAE,CACvE,uBAAuB,CAAO,UAAU,CAAC,CAAA;AAE3C,MAAM,CAAC,MAAM,iBAAiB,GAAG,YAAY,CAAO,qBAAqB,EAAE;IACzE,QAAQ,EAAE,GAAG;CACd,CAAC,CAAA"}
@@ -0,0 +1,3 @@
1
+ import type { Product } from '../models/product.js';
2
+ export declare const createProductService: import("./contracts.js").CollectionServiceFactory<Product>;
3
+ //# sourceMappingURL=product-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"product-service.d.ts","sourceRoot":"","sources":["../../src/services/product-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAOnD,eAAO,MAAM,oBAAoB,4DAE/B,CAAA"}
@@ -0,0 +1,6 @@
1
+ import { createCollectionService, withDefaults } from './collection-service.js';
2
+ const createBaseProductService = (repository) => createCollectionService(repository);
3
+ export const createProductService = withDefaults(createBaseProductService, {
4
+ populate: '*',
5
+ });
6
+ //# sourceMappingURL=product-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"product-service.js","sourceRoot":"","sources":["../../src/services/product-service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAE/E,MAAM,wBAAwB,GAAG,CAAC,UAAyC,EAAE,EAAE,CAC7E,uBAAuB,CAAU,UAAU,CAAC,CAAA;AAE9C,MAAM,CAAC,MAAM,oBAAoB,GAAG,YAAY,CAAU,wBAAwB,EAAE;IAClF,QAAQ,EAAE,GAAG;CACd,CAAC,CAAA"}
@@ -0,0 +1,3 @@
1
+ export { createStrapiClient, mergeFilters } from './repositories/strapi-client.js';
2
+ export type { HttpClient, RepositoryQuery } from './repositories/contracts.js';
3
+ //# sourceMappingURL=strapi-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strapi-client.d.ts","sourceRoot":"","sources":["../src/strapi-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAA;AAClF,YAAY,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAA"}
@@ -0,0 +1,2 @@
1
+ export { createStrapiClient, mergeFilters } from './repositories/strapi-client.js';
2
+ //# sourceMappingURL=strapi-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strapi-client.js","sourceRoot":"","sources":["../src/strapi-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAA"}
package/package.json CHANGED
@@ -1,22 +1,46 @@
1
1
  {
2
2
  "name": "strapi-rest-lite",
3
- "version": "0.1.0",
3
+ "version": "0.1.3",
4
+ "license": "MIT",
4
5
  "type": "module",
5
6
  "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
6
8
  "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
7
15
  "files": [
8
16
  "dist"
9
17
  ],
18
+ "sideEffects": false,
10
19
  "scripts": {
11
- "build": "tsc -p tsconfig.json"
20
+ "build": "tsc -p tsconfig.json",
21
+ "prepack": "npm run build"
12
22
  },
13
- "dependencies": {
14
- "qs": "^6.12.0"
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "https://github.com/yakku361/strapi-rest-lite",
26
+ "directory": "packages/strapi-sdk"
15
27
  },
16
- "devDependencies": {
17
- "@types/qs": "^6.9.16"
28
+ "bugs": {
29
+ "url": "https://github.com/yakku361/strapi-rest-lite/issues"
30
+ },
31
+ "homepage": "https://github.com/yakku361/strapi-rest-lite",
32
+ "dependencies": {
33
+ "ofetch": "^1.4.0"
18
34
  },
19
35
  "peerDependencies": {
20
- "node-fetch": "^3.0.0"
36
+ "nitropack": "^2.9.0"
37
+ },
38
+ "peerDependenciesMeta": {
39
+ "nitropack": {
40
+ "optional": true
41
+ }
42
+ },
43
+ "devDependencies": {
44
+ "typescript": "^5.8.3"
21
45
  }
22
46
  }
@@ -1,7 +0,0 @@
1
- import type { HttpClient, RepositoryQuery, StrapiListResponse, StrapiSingleResponse } from './types';
2
- export interface CollectionRepository<T> {
3
- list(query?: RepositoryQuery): Promise<StrapiListResponse<T>>;
4
- get(id: number | string, query?: RepositoryQuery): Promise<StrapiSingleResponse<T>>;
5
- getBySlug(slug: string, query?: RepositoryQuery): Promise<StrapiListResponse<T>>;
6
- }
7
- export declare const createCollectionRepository: <T>(collection: string, client: HttpClient) => CollectionRepository<T>;
@@ -1,16 +0,0 @@
1
- const apiPath = (collection) => `/api/${collection}`;
2
- export const createCollectionRepository = (collection, client) => {
3
- return {
4
- list: (query) => client.get(apiPath(collection), { query }),
5
- get: (id, query) => client.get(`${apiPath(collection)}/${id}`, { query }),
6
- getBySlug: (slug, query) => client.get(apiPath(collection), {
7
- query: {
8
- ...(query ?? {}),
9
- filters: {
10
- ...(query?.filters ?? {}),
11
- slug: { $eq: slug },
12
- },
13
- },
14
- }),
15
- };
16
- };
@@ -1,9 +0,0 @@
1
- import type { CollectionRepository } from './collection-repository';
2
- import type { RepositoryQuery, StrapiListResponse, StrapiSingleResponse } from './types';
3
- export interface CollectionService<T> {
4
- list(query?: RepositoryQuery): Promise<StrapiListResponse<T>>;
5
- get(id: number | string, query?: RepositoryQuery): Promise<StrapiSingleResponse<T>>;
6
- getBySlug(slug: string, query?: RepositoryQuery): Promise<StrapiListResponse<T>>;
7
- }
8
- export declare const createCollectionService: <T>(repository: CollectionRepository<T>) => CollectionService<T>;
9
- export declare const withDefaults: <T>(factory: (repo: CollectionRepository<T>) => CollectionService<T>, defaults: RepositoryQuery) => (repo: CollectionRepository<T>) => CollectionService<T>;
@@ -1,13 +0,0 @@
1
- export const createCollectionService = (repository) => ({
2
- list: (query) => repository.list(query),
3
- get: (id, query) => repository.get(id, query),
4
- getBySlug: (slug, query) => repository.getBySlug(slug, query),
5
- });
6
- export const withDefaults = (factory, defaults) => (repo) => {
7
- const base = factory(repo);
8
- return {
9
- list: (query) => base.list({ ...defaults, ...(query ?? {}) }),
10
- get: (id, query) => base.get(id, { ...defaults, ...(query ?? {}) }),
11
- getBySlug: (slug, query) => base.getBySlug(slug, { ...defaults, ...(query ?? {}) }),
12
- };
13
- };
@@ -1,7 +0,0 @@
1
- import type { FetchLike, HttpClient } from './types';
2
- export interface HttpClientOptions {
3
- baseURL: string;
4
- token?: string;
5
- fetch?: FetchLike;
6
- }
7
- export declare const createHttpClient: ({ baseURL, token, fetch: fetchImpl }: HttpClientOptions) => HttpClient;
@@ -1,33 +0,0 @@
1
- import qs from 'qs';
2
- const buildUrl = (baseURL, path, query) => {
3
- const normalized = path.startsWith('/') ? path : `/${path}`;
4
- const qsPart = query && Object.keys(query).length ? `?${qs.stringify(query, { encodeValuesOnly: true })}` : '';
5
- return `${baseURL}${normalized}${qsPart}`;
6
- };
7
- export const createHttpClient = ({ baseURL, token, fetch: fetchImpl }) => {
8
- const f = fetchImpl ?? fetch;
9
- const request = async (method, path, body, options) => {
10
- const url = buildUrl(baseURL, path, options?.query);
11
- const headers = {
12
- 'Content-Type': 'application/json',
13
- ...(token ? { Authorization: `Bearer ${token}` } : {}),
14
- ...(options?.headers ?? {}),
15
- };
16
- const res = await f(url, {
17
- method,
18
- headers,
19
- body: body ? JSON.stringify(body) : undefined,
20
- });
21
- if (!res.ok) {
22
- const message = await res.text().catch(() => res.statusText);
23
- throw new Error(`HTTP ${res.status} ${res.statusText}: ${message}`);
24
- }
25
- return (await res.json());
26
- };
27
- return {
28
- get: (path, options) => request('GET', path, undefined, options),
29
- post: (path, body, options) => request('POST', path, body, options),
30
- put: (path, body, options) => request('PUT', path, body, options),
31
- delete: (path, options) => request('DELETE', path, undefined, options),
32
- };
33
- };
package/dist/media.d.ts DELETED
@@ -1,4 +0,0 @@
1
- /**
2
- * Converts Strapi media URLs to absolute URLs based on the API base URL.
3
- */
4
- export declare const resolveMediaUrl: (url?: string | null, apiBase?: string) => string | null;
package/dist/media.js DELETED
@@ -1,12 +0,0 @@
1
- /**
2
- * Converts Strapi media URLs to absolute URLs based on the API base URL.
3
- */
4
- export const resolveMediaUrl = (url, apiBase) => {
5
- if (!url)
6
- return null;
7
- if (url.startsWith('http'))
8
- return url;
9
- if (!apiBase)
10
- return url;
11
- return `${apiBase}${url}`;
12
- };
package/dist/types.d.ts DELETED
@@ -1,32 +0,0 @@
1
- export type FetchLike = typeof fetch;
2
- export interface HttpRequestOptions {
3
- query?: Record<string, unknown>;
4
- headers?: Record<string, string>;
5
- }
6
- export interface HttpClient {
7
- get<T = unknown>(path: string, options?: HttpRequestOptions): Promise<T>;
8
- post<T = unknown>(path: string, body?: unknown, options?: HttpRequestOptions): Promise<T>;
9
- put<T = unknown>(path: string, body?: unknown, options?: HttpRequestOptions): Promise<T>;
10
- delete<T = unknown>(path: string, options?: HttpRequestOptions): Promise<T>;
11
- }
12
- export interface RepositoryQuery {
13
- filters?: Record<string, unknown>;
14
- populate?: '*' | Record<string, unknown> | Array<string | Record<string, unknown>>;
15
- sort?: string[] | string;
16
- pagination?: {
17
- page?: number;
18
- pageSize?: number;
19
- start?: number;
20
- limit?: number;
21
- };
22
- fields?: string[];
23
- [key: string]: unknown;
24
- }
25
- export interface StrapiListResponse<T> {
26
- data: T[];
27
- meta: Record<string, unknown>;
28
- }
29
- export interface StrapiSingleResponse<T> {
30
- data: T | null;
31
- meta: Record<string, unknown>;
32
- }
package/dist/types.js DELETED
@@ -1 +0,0 @@
1
- export {};