Comparing version 0.0.1 to 0.1.0
import { Locale } from '@m3cms/common'; | ||
declare type GetSchemaParsedResponse = Record<string, Record<string, unknown>>; | ||
declare type Visibility = { | ||
/** | ||
* This is the response of the CMS API. With the props of the components | ||
* that were applied in the CMS. | ||
* | ||
* @exemple | ||
* ```ts | ||
* { | ||
* FsAlert: { | ||
* icon: 'Bell', | ||
* link: { to: '/office', text: 'Compre aqui' }, | ||
* content: 'Novos textos', | ||
* dismissible: true | ||
* }, | ||
* Button: { text: 'quero um titulo legalzinho' } | ||
* } | ||
* ``` | ||
*/ | ||
type CmsComponentsDataResponse<T extends Record<string, Record<string, any>> = Record<string, Record<string, unknown>>> = T; | ||
type Visibility = { | ||
key: string; | ||
value: string; | ||
}; | ||
declare type M3CmsConfig = { | ||
/** | ||
* Data to configure the CMS API. So we can identify which environment to pull | ||
* the data from. | ||
* | ||
* We usually recommend creating a file in the root of your project called m3Cms.config.js | ||
* | ||
* @example | ||
* ```ts | ||
* { | ||
* locale: 'pt-BR', | ||
* projectName: 'StoreXPTO', | ||
* workspaceName: 'master', | ||
* baseUrl: 'http://localhost:3333/api/v1' | ||
* } | ||
* ``` | ||
*/ | ||
type M3CmsConfig = { | ||
locale?: Locale; | ||
@@ -20,3 +53,3 @@ projectName: string; | ||
constructor({ baseUrl, projectName, workspaceName, locale }: M3CmsConfig); | ||
getCmsData(tags: string[] | string, visibility?: Visibility[]): Promise<GetSchemaParsedResponse>; | ||
getCmsData<T extends Record<string, Record<string, any>> = Record<string, Record<string, unknown>>>(tags: string[] | string, visibility?: Visibility[]): Promise<T>; | ||
} | ||
@@ -30,2 +63,2 @@ | ||
export { M3Cms, M3CmsConfig, useCmsData }; | ||
export { CmsComponentsDataResponse, M3Cms, M3CmsConfig, useCmsData }; |
@@ -1,30 +0,27 @@ | ||
var __create = Object.create; | ||
"use strict"; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true }); | ||
var __export = (target, all) => { | ||
__markAsModule(target); | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __reExport = (target, module2, desc) => { | ||
if (module2 && typeof module2 === "object" || typeof module2 === "function") { | ||
for (let key of __getOwnPropNames(module2)) | ||
if (!__hasOwnProp.call(target, key) && key !== "default") | ||
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable }); | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return target; | ||
return to; | ||
}; | ||
var __toModule = (module2) => { | ||
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2); | ||
}; | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
// src/index.tsx | ||
__export(exports, { | ||
var src_exports = {}; | ||
__export(src_exports, { | ||
M3Cms: () => M3Cms, | ||
useCmsData: () => useCmsData | ||
}); | ||
module.exports = __toCommonJS(src_exports); | ||
@@ -47,2 +44,6 @@ // src/services/M3Cms.ts | ||
var M3Cms = class { | ||
locale; | ||
projectName; | ||
workspaceName; | ||
baseUrl; | ||
constructor({ | ||
@@ -85,12 +86,29 @@ baseUrl = BASE_URL_CMS_DEV, | ||
// src/hooks/useCmsData.ts | ||
var import_react = __toModule(require("react")); | ||
var import_react = require("react"); | ||
function useCmsData(tags, cmsConfig) { | ||
const keyTag = Array.isArray(tags) ? tags.join(",") : tags; | ||
const [data, setData] = (0, import_react.useState)(); | ||
const [loading, setLoading] = (0, import_react.useState)(true); | ||
const [loading, setLoading] = (0, import_react.useState)(false); | ||
const [error, setError] = (0, import_react.useState)(); | ||
const cache = (0, import_react.useRef)(); | ||
(0, import_react.useEffect)(() => { | ||
if (keyTag === "" || loading === true) | ||
return; | ||
if (cache.current) { | ||
if (cache.current[keyTag]) { | ||
setData(cache.current[keyTag]); | ||
return; | ||
} | ||
} | ||
setLoading(true); | ||
const m3Cms = new M3Cms(cmsConfig); | ||
m3Cms.getCmsData(tags).then(setData).then(() => setLoading(false)).catch(setError); | ||
}, []); | ||
m3Cms.getCmsData(tags).then((data2) => { | ||
if (!cache.current) { | ||
cache.current = {}; | ||
} | ||
cache.current[keyTag] = data2; | ||
setData(data2); | ||
setLoading(false); | ||
}).catch(setError); | ||
}, [tags]); | ||
return { data, loading, error }; | ||
@@ -97,0 +115,0 @@ } |
{ | ||
"name": "@m3cms/api", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"main": "./dist/index.js", | ||
@@ -12,24 +12,43 @@ "module": "./dist/index.mjs", | ||
], | ||
"scripts": { | ||
"build": "tsup src/index.tsx --format esm,cjs --dts --external react", | ||
"dev": "tsup src/index.tsx --format esm,cjs --watch --dts --external react", | ||
"lint": "eslint \"src/**/*.ts*\"", | ||
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist" | ||
}, | ||
"dependencies": { | ||
"@m3cms/common": "workspace:*" | ||
"@m3cms/common": "0.1.0" | ||
}, | ||
"devDependencies": { | ||
"@m3cms/tsconfig": "workspace:*", | ||
"@types/react": "^18.0.9", | ||
"@types/react-dom": "^18.0.4", | ||
"eslint": "^8.15.0", | ||
"eslint-config-m3cms": "workspace:*", | ||
"react": "^18.1.0", | ||
"tsup": "^5.10.1", | ||
"typescript": "^4.5.3" | ||
"@types/react": "^18.2.17", | ||
"@types/react-dom": "^18.2.7", | ||
"eslint": "^8.46.0", | ||
"react": "^18.2.0", | ||
"tsup": "^7.1.0", | ||
"typescript": "^5.1.6", | ||
"vitest": "^0.33.0", | ||
"@m3cms/tsconfig": "0.0.1", | ||
"eslint-config-m3cms": "0.0.1" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"keywords": [ | ||
"m3", | ||
"cms", | ||
"api" | ||
], | ||
"author": "M3, a Cadastra Company", | ||
"contributors": [ | ||
{ | ||
"name": "Marlon Passos", | ||
"email": "marlon.passos@m3ecommerce.com" | ||
} | ||
], | ||
"description": "M3 CMS API", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://bitbucket.org/m3ecommerce/m3_cms_web_adapter/src/master/" | ||
}, | ||
"homepage": "https://bitbucket.org/m3ecommerce/m3_cms_web_adapter/src/master/README.md", | ||
"scripts": { | ||
"build": "tsup src/index.tsx --format esm,cjs --dts --external react", | ||
"dev": "tsup src/index.tsx --format esm,cjs --watch --dts --external react", | ||
"lint": "eslint \"src/**/*.ts*\"", | ||
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
13411
6
378
1
0
9
4
+ Added@m3cms/common@0.1.0(transitive)
+ Addedjson-schema@0.4.0(transitive)
Updated@m3cms/common@0.1.0