@nuxtjs/strapi
Advanced tools
Comparing version 0.3.0 to 0.3.1
@@ -5,2 +5,9 @@ # Changelog | ||
### [0.3.1](https://github.com/nuxt-community/strapi-module/compare/v0.3.0...v0.3.1) (2021-03-25) | ||
### Bug Fixes | ||
* upgrade `ufo` ([#122](https://github.com/nuxt-community/strapi-module/issues/122)) ([41c99a2](https://github.com/nuxt-community/strapi-module/commit/41c99a214a80a8362d7c364f16da099990413acb)) | ||
## [0.3.0](https://github.com/nuxt-community/strapi-module/compare/v0.1.11...v0.3.0) (2021-01-19) | ||
@@ -7,0 +14,0 @@ |
'use strict'; | ||
const path = require('path'); | ||
const defu2 = require('defu'); | ||
const ms2 = require('ms'); | ||
const defu = require('defu'); | ||
const ms = require('ms'); | ||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
const defu2__default = /*#__PURE__*/_interopDefaultLegacy(defu2); | ||
const ms2__default = /*#__PURE__*/_interopDefaultLegacy(ms2); | ||
const defu__default = /*#__PURE__*/_interopDefaultLegacy(defu); | ||
const ms__default = /*#__PURE__*/_interopDefaultLegacy(ms); | ||
var name = "@nuxtjs/strapi"; | ||
var version = "0.1.11"; | ||
var version = "0.3.1"; | ||
@@ -24,5 +24,5 @@ const defaults = { | ||
const {nuxt} = this; | ||
const options = defu2__default['default'](moduleOptions, nuxt.options.strapi, defaults); | ||
const options = defu__default['default'](moduleOptions, nuxt.options.strapi, defaults); | ||
if (typeof options.expires === "string" && options.expires !== "session") { | ||
options.expires = ms2__default['default'](options.expires); | ||
options.expires = ms__default['default'](options.expires); | ||
} | ||
@@ -29,0 +29,0 @@ nuxt.options.publicRuntimeConfig = nuxt.options.publicRuntimeConfig || {}; |
@@ -1,1 +0,1 @@ | ||
export * from './strapi'; | ||
export * from "./strapi"; |
@@ -1,177 +0,172 @@ | ||
import Vue from 'vue'; | ||
import Hookable from 'hookable'; | ||
import destr from 'destr'; | ||
import reqURL from 'requrl'; | ||
import { joinURL } from 'ufo'; | ||
import { getExpirationDate, isExpired } from './utils'; | ||
import Vue from "vue"; | ||
import Hookable from "hookable"; | ||
import destr from "destr"; | ||
import reqURL from "requrl"; | ||
import {joinURL} from "ufo"; | ||
import {getExpirationDate, isExpired} from "./utils"; | ||
export class Strapi extends Hookable { | ||
constructor(ctx, options) { | ||
super(); | ||
ctx.$config = ctx.$config || {}; // fallback for Nuxt < 2.13 | ||
const runtimeConfig = ctx.$config.strapi || {}; | ||
this.$cookies = ctx.app.$cookies; | ||
this.$http = ctx.$http.create({}); | ||
this.options = options; | ||
this.state = Vue.observable({ user: null }); | ||
this.syncToken(); | ||
const url = runtimeConfig.url || this.options.url; | ||
if (process.server && ctx.req && url.startsWith('/')) { | ||
this.$http.setBaseURL(joinURL(reqURL(ctx.req), url)); | ||
} | ||
else { | ||
this.$http.setBaseURL(url); | ||
} | ||
this.$http.onError((err) => { | ||
if (!err.response) { | ||
this.callHook('error', err); | ||
return; | ||
} | ||
const { response: { data: { message: msg } } } = err; | ||
let message; | ||
if (Array.isArray(msg)) { | ||
message = msg[0].messages[0].message; | ||
} | ||
else if (typeof msg === 'object' && msg !== null) { | ||
message = msg.message; | ||
} | ||
else { | ||
message = msg; | ||
} | ||
err.message = message; | ||
err.original = err.response.data; | ||
this.callHook('error', err); | ||
}); | ||
constructor(ctx, options) { | ||
super(); | ||
ctx.$config = ctx.$config || {}; | ||
const runtimeConfig = ctx.$config.strapi || {}; | ||
this.$cookies = ctx.app.$cookies; | ||
this.$http = ctx.$http.create({}); | ||
this.options = options; | ||
this.state = Vue.observable({user: null}); | ||
this.syncToken(); | ||
const url = runtimeConfig.url || this.options.url; | ||
if (process.server && ctx.req && url.startsWith("/")) { | ||
this.$http.setBaseURL(joinURL(reqURL(ctx.req), url)); | ||
} else { | ||
this.$http.setBaseURL(url); | ||
} | ||
get user() { | ||
return this.state.user; | ||
this.$http.onError((err) => { | ||
if (!err.response) { | ||
this.callHook("error", err); | ||
return; | ||
} | ||
const {response: {data: {message: msg}}} = err; | ||
let message; | ||
if (Array.isArray(msg)) { | ||
message = msg[0].messages[0].message; | ||
} else if (typeof msg === "object" && msg !== null) { | ||
message = msg.message; | ||
} else { | ||
message = msg; | ||
} | ||
err.message = message; | ||
err.original = err.response.data; | ||
this.callHook("error", err); | ||
}); | ||
} | ||
get user() { | ||
return this.state.user; | ||
} | ||
set user(user) { | ||
Vue.set(this.state, "user", user); | ||
} | ||
async register(data) { | ||
this.clearToken(); | ||
const {user, jwt} = await this.$http.$post("/auth/local/register", data); | ||
this.setToken(jwt); | ||
await this.setUser(user); | ||
return {user, jwt}; | ||
} | ||
async login(data) { | ||
this.clearToken(); | ||
const {user, jwt} = await this.$http.$post("/auth/local", data); | ||
this.setToken(jwt); | ||
await this.setUser(user); | ||
return {user, jwt}; | ||
} | ||
forgotPassword(data) { | ||
this.clearToken(); | ||
return this.$http.$post("/auth/forgot-password", data); | ||
} | ||
async resetPassword(data) { | ||
this.clearToken(); | ||
const {user, jwt} = await this.$http.$post("/auth/reset-password", data); | ||
this.setToken(jwt); | ||
await this.setUser(user); | ||
return {user, jwt}; | ||
} | ||
sendEmailConfirmation(data) { | ||
return this.$http.$post("/auth/send-email-confirmation", data); | ||
} | ||
async logout() { | ||
await this.setUser(null); | ||
this.clearToken(); | ||
} | ||
async fetchUser() { | ||
const jwt = this.syncToken(); | ||
if (!jwt) { | ||
return null; | ||
} | ||
set user(user) { | ||
Vue.set(this.state, 'user', user); | ||
try { | ||
const user = await this.findOne("users", "me"); | ||
await this.setUser(user); | ||
} catch (e) { | ||
this.clearToken(); | ||
} | ||
async register(data) { | ||
this.clearToken(); | ||
const { user, jwt } = await this.$http.$post('/auth/local/register', data); | ||
this.setToken(jwt); | ||
await this.setUser(user); | ||
return { user, jwt }; | ||
return this.user; | ||
} | ||
async setUser(user) { | ||
this.user = user; | ||
await this.callHook("userUpdated", user); | ||
} | ||
find(entity, searchParams) { | ||
return this.$http.$get(`/${entity}`, {searchParams}); | ||
} | ||
count(entity, searchParams) { | ||
return this.$http.$get(`/${entity}/count`, {searchParams}); | ||
} | ||
findOne(entity, id) { | ||
return this.$http.$get(`/${entity}/${id}`); | ||
} | ||
create(entity, data) { | ||
return this.$http.$post(`/${entity}`, data); | ||
} | ||
update(entity, id, data) { | ||
if (typeof id === "object") { | ||
data = id; | ||
id = void 0; | ||
} | ||
async login(data) { | ||
this.clearToken(); | ||
const { user, jwt } = await this.$http.$post('/auth/local', data); | ||
this.setToken(jwt); | ||
await this.setUser(user); | ||
return { user, jwt }; | ||
const path = [entity, id].filter(Boolean).join("/"); | ||
return this.$http.$put(`/${path}`, data); | ||
} | ||
delete(entity, id) { | ||
const path = [entity, id].filter(Boolean).join("/"); | ||
return this.$http.$delete(`/${path}`); | ||
} | ||
graphql(query) { | ||
return this.$http.$post("/graphql", query).then((res) => res.data); | ||
} | ||
getClientStorage() { | ||
const storageType = this.options.expires === "session" ? "sessionStorage" : "localStorage"; | ||
if (process.client && typeof window[storageType] !== "undefined") { | ||
return window[storageType]; | ||
} | ||
forgotPassword(data) { | ||
this.clearToken(); | ||
return this.$http.$post('/auth/forgot-password', data); | ||
return null; | ||
} | ||
getToken() { | ||
let token; | ||
const clientStorage = this.getClientStorage(); | ||
if (clientStorage) { | ||
const session = destr(clientStorage.getItem(this.options.key)); | ||
if (session && !isExpired(session.expires)) { | ||
token = session.token; | ||
} | ||
} | ||
async resetPassword(data) { | ||
this.clearToken(); | ||
const { user, jwt } = await this.$http.$post('/auth/reset-password', data); | ||
this.setToken(jwt); | ||
await this.setUser(user); | ||
return { user, jwt }; | ||
if (!token) { | ||
token = this.$cookies.get(this.options.key); | ||
} | ||
sendEmailConfirmation(data) { | ||
return this.$http.$post('/auth/send-email-confirmation', data); | ||
return token; | ||
} | ||
setToken(token) { | ||
const expires = this.options.expires === "session" ? void 0 : getExpirationDate(this.options.expires); | ||
const clientStorage = this.getClientStorage(); | ||
clientStorage && clientStorage.setItem(this.options.key, JSON.stringify({token, expires})); | ||
this.$cookies.set(this.options.key, token, { | ||
...this.options.cookie, | ||
expires | ||
}); | ||
this.$http.setToken(token, "Bearer"); | ||
} | ||
clearToken() { | ||
this.$http.setToken(false); | ||
const clientStorage = this.getClientStorage(); | ||
clientStorage && clientStorage.removeItem(this.options.key); | ||
this.$cookies.remove(this.options.key); | ||
} | ||
syncToken(jwt) { | ||
if (!jwt) { | ||
jwt = this.getToken(); | ||
} | ||
async logout() { | ||
await this.setUser(null); | ||
this.clearToken(); | ||
if (jwt) { | ||
this.setToken(jwt); | ||
} else { | ||
this.clearToken(); | ||
} | ||
async fetchUser() { | ||
const jwt = this.syncToken(); | ||
if (!jwt) { | ||
return null; | ||
} | ||
try { | ||
const user = await this.findOne('users', 'me'); | ||
await this.setUser(user); | ||
} | ||
catch (e) { | ||
this.clearToken(); | ||
} | ||
return this.user; | ||
} | ||
async setUser(user) { | ||
this.user = user; | ||
await this.callHook('userUpdated', user); | ||
} | ||
find(entity, searchParams) { | ||
return this.$http.$get(`/${entity}`, { searchParams }); | ||
} | ||
count(entity, searchParams) { | ||
return this.$http.$get(`/${entity}/count`, { searchParams }); | ||
} | ||
findOne(entity, id) { | ||
return this.$http.$get(`/${entity}/${id}`); | ||
} | ||
create(entity, data) { | ||
return this.$http.$post(`/${entity}`, data); | ||
} | ||
update(entity, id, data) { | ||
if (typeof id === 'object') { | ||
data = id; | ||
id = undefined; | ||
} | ||
const path = [entity, id].filter(Boolean).join('/'); | ||
return this.$http.$put(`/${path}`, data); | ||
} | ||
delete(entity, id) { | ||
const path = [entity, id].filter(Boolean).join('/'); | ||
return this.$http.$delete(`/${path}`); | ||
} | ||
graphql(query) { | ||
return this.$http.$post('/graphql', query).then(res => res.data); | ||
} | ||
getClientStorage() { | ||
const storageType = this.options.expires === 'session' ? 'sessionStorage' : 'localStorage'; | ||
if (process.client && typeof window[storageType] !== 'undefined') { | ||
return window[storageType]; | ||
} | ||
return null; | ||
} | ||
getToken() { | ||
let token; | ||
const clientStorage = this.getClientStorage(); | ||
if (clientStorage) { | ||
const session = destr(clientStorage.getItem(this.options.key)); | ||
if (session && !isExpired(session.expires)) { | ||
token = session.token; | ||
} | ||
} | ||
if (!token) { | ||
token = this.$cookies.get(this.options.key); | ||
} | ||
return token; | ||
} | ||
setToken(token) { | ||
const expires = this.options.expires === 'session' ? undefined : getExpirationDate(this.options.expires); | ||
const clientStorage = this.getClientStorage(); | ||
clientStorage && clientStorage.setItem(this.options.key, JSON.stringify({ token, expires })); | ||
this.$cookies.set(this.options.key, token, { | ||
...this.options.cookie, | ||
expires | ||
}); | ||
this.$http.setToken(token, 'Bearer'); | ||
} | ||
clearToken() { | ||
this.$http.setToken(false); | ||
const clientStorage = this.getClientStorage(); | ||
clientStorage && clientStorage.removeItem(this.options.key); | ||
this.$cookies.remove(this.options.key); | ||
} | ||
syncToken(jwt) { | ||
if (!jwt) { | ||
jwt = this.getToken(); | ||
} | ||
if (jwt) { | ||
this.setToken(jwt); | ||
} | ||
else { | ||
this.clearToken(); | ||
} | ||
return jwt; | ||
} | ||
return jwt; | ||
} | ||
} |
export function getExpirationDate(ms) { | ||
return new Date(Date.now() + ms); | ||
return new Date(Date.now() + ms); | ||
} | ||
export function isExpired(expires) { | ||
if (!expires) { | ||
return false; | ||
} | ||
return new Date(expires) <= new Date(); | ||
if (!expires) { | ||
return false; | ||
} | ||
return new Date(expires) <= new Date(); | ||
} |
{ | ||
"name": "@nuxtjs/strapi", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "Strapi module for Nuxt", | ||
@@ -8,4 +8,9 @@ "repository": "nuxt-community/strapi-module", | ||
"sideEffects": false, | ||
"main": "lib/module.js", | ||
"typings": "./types/index.d.ts", | ||
"exports": { | ||
".": "./lib/module.js", | ||
"./lib/runtime/*": "./lib/runtime/*", | ||
"./package.json": "./package.json" | ||
}, | ||
"main": "./lib/module.js", | ||
"typings": "./lib/runtime.d.ts", | ||
"files": [ | ||
@@ -16,4 +21,3 @@ "lib", | ||
"scripts": { | ||
"build": "siroc build && yarn build:runtime", | ||
"build:runtime": "tsc -p tsconfig.runtime.json && copyfiles \"src/runtime/**/*\" -e \"**/*.ts\" -u 2 lib/runtime", | ||
"build": "siroc build", | ||
"dev": "yarn nuxt-ts example", | ||
@@ -26,37 +30,42 @@ "docs": "nuxt docs", | ||
"dependencies": { | ||
"@nuxt/http": "^0.6.2", | ||
"@nuxt/http": "^0.6.4", | ||
"cookie-universal-nuxt": "^2.1.4", | ||
"defu": "^3.2.2", | ||
"destr": "^1.0.1", | ||
"hookable": "^4.3.1", | ||
"destr": "^1.1.0", | ||
"hookable": "^4.4.1", | ||
"ms": "^2.1.3", | ||
"requrl": "^3.0.2", | ||
"ufo": "^0.5.4" | ||
"ufo": "^0.6.10" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.12.10", | ||
"@babel/preset-env": "^7.12.11", | ||
"@babel/preset-typescript": "^7.12.7", | ||
"@commitlint/cli": "^11.0.0", | ||
"@commitlint/config-conventional": "^11.0.0", | ||
"@nuxt/test-utils": "^0.1.2", | ||
"@nuxt/types": "^2.14.12", | ||
"@nuxt/typescript-build": "^2.0.3", | ||
"@nuxt/typescript-runtime": "^2.0.0", | ||
"@nuxtjs/eslint-config": "^5.0.0", | ||
"@nuxtjs/eslint-config-typescript": "^5.0.0", | ||
"@babel/core": "^7.13.10", | ||
"@babel/preset-env": "^7.13.12", | ||
"@babel/preset-typescript": "^7.13.0", | ||
"@commitlint/cli": "^12.0.1", | ||
"@commitlint/config-conventional": "^12.0.1", | ||
"@nuxt/test-utils": "^0.2.0", | ||
"@nuxt/types": "^2.15.3", | ||
"@nuxt/typescript-build": "^2.1.0", | ||
"@nuxt/typescript-runtime": "^2.1.0", | ||
"@nuxtjs/eslint-config": "^6.0.0", | ||
"@nuxtjs/eslint-config-typescript": "^6.0.0", | ||
"@nuxtjs/module-test-utils": "latest", | ||
"@types/jest": "^26.0.20", | ||
"@types/jest": "^26.0.21", | ||
"babel-eslint": "latest", | ||
"babel-jest": "^26.6.3", | ||
"copyfiles": "^2.4.1", | ||
"eslint": "^7.17.0", | ||
"husky": "^4.3.7", | ||
"eslint": "^7.22.0", | ||
"husky": "^5.2.0", | ||
"jest": "^26.6.3", | ||
"nuxt": "2.14.12", | ||
"siroc": "^0.6.0", | ||
"standard-version": "^9.1.0", | ||
"ts-loader": "^8.0.14", | ||
"typescript": "^4.1.3" | ||
"nuxt": "2.15.3", | ||
"siroc": "^0.8.0", | ||
"standard-version": "^9.1.1", | ||
"ts-loader": "^8.0.18", | ||
"typescript": "^4.2.3", | ||
"vuex": "^3.6.2" | ||
}, | ||
"peerDependencies": { | ||
"@nuxt/types": "*", | ||
"vuex": "*" | ||
}, | ||
"publishConfig": { | ||
@@ -63,0 +72,0 @@ "access": "public" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
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
0
22066
10
25
11
392
+ Added@babel/helper-string-parser@7.25.9(transitive)
+ Added@babel/helper-validator-identifier@7.25.9(transitive)
+ Added@babel/parser@7.26.5(transitive)
+ Added@babel/types@7.26.5(transitive)
+ Added@jridgewell/sourcemap-codec@1.5.0(transitive)
+ Added@nuxt/types@2.18.1(transitive)
+ Added@types/babel__core@7.20.5(transitive)
+ Added@types/babel__generator@7.6.8(transitive)
+ Added@types/babel__template@7.4.4(transitive)
+ Added@types/babel__traverse@7.20.6(transitive)
+ Added@types/body-parser@1.19.5(transitive)
+ Added@types/compression@1.7.5(transitive)
+ Added@types/connect@3.4.38(transitive)
+ Added@types/etag@1.8.3(transitive)
+ Added@types/express@5.0.0(transitive)
+ Added@types/express-serve-static-core@5.0.4(transitive)
+ Added@types/file-loader@5.0.4(transitive)
+ Added@types/html-minifier-terser@7.0.2(transitive)
+ Added@types/http-errors@2.0.4(transitive)
+ Added@types/less@3.0.6(transitive)
+ Added@types/mime@1.3.5(transitive)
+ Added@types/node@16.18.123(transitive)
+ Added@types/optimize-css-assets-webpack-plugin@5.0.8(transitive)
+ Added@types/pug@2.0.10(transitive)
+ Added@types/qs@6.9.18(transitive)
+ Added@types/range-parser@1.2.7(transitive)
+ Added@types/send@0.17.4(transitive)
+ Added@types/serve-static@1.15.7(transitive)
+ Added@types/source-list-map@0.1.6(transitive)
+ Added@types/tapable@1.0.12(transitive)
+ Added@types/terser-webpack-plugin@4.2.1(transitive)
+ Added@types/uglify-js@3.17.5(transitive)
+ Added@types/webpack@4.41.40(transitive)
+ Added@types/webpack-bundle-analyzer@3.9.5(transitive)
+ Added@types/webpack-hot-middleware@2.25.5(transitive)
+ Added@types/webpack-sources@3.2.3(transitive)
+ Added@vue/compiler-core@3.5.13(transitive)
+ Added@vue/compiler-dom@3.5.13(transitive)
+ Added@vue/compiler-sfc@3.5.13(transitive)
+ Added@vue/compiler-ssr@3.5.13(transitive)
+ Added@vue/devtools-api@6.6.4(transitive)
+ Added@vue/reactivity@3.5.13(transitive)
+ Added@vue/runtime-core@3.5.13(transitive)
+ Added@vue/runtime-dom@3.5.13(transitive)
+ Added@vue/server-renderer@3.5.13(transitive)
+ Added@vue/shared@3.5.13(transitive)
+ Addedanymatch@3.1.3(transitive)
+ Addedbuffer-from@1.1.2(transitive)
+ Addedcommander@2.20.3(transitive)
+ Addedcsstype@3.1.3(transitive)
+ Addedentities@4.5.0(transitive)
+ Addedestree-walker@2.0.2(transitive)
+ Addedmagic-string@0.30.17(transitive)
+ Addednanoid@3.3.8(transitive)
+ Addednormalize-path@3.0.0(transitive)
+ Addedpicocolors@1.1.1(transitive)
+ Addedpostcss@8.5.1(transitive)
+ Addedsource-map@0.6.10.7.4(transitive)
+ Addedsource-map-js@1.2.1(transitive)
+ Addedsource-map-support@0.5.21(transitive)
+ Addedterser@4.8.1(transitive)
+ Addedufo@0.6.12(transitive)
+ Addedvue@3.5.13(transitive)
+ Addedvuex@4.1.0(transitive)
- Removed@types/node@22.10.6(transitive)
- Removedufo@0.5.5(transitive)
- Removedundici-types@6.20.0(transitive)
Updated@nuxt/http@^0.6.4
Updateddestr@^1.1.0
Updatedhookable@^4.4.1
Updatedufo@^0.6.10