Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@nuxtjs/strapi

Package Overview
Dependencies
Maintainers
2
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nuxtjs/strapi - npm Package Compare versions

Comparing version 0.3.0 to 0.3.1

lib/runtime.d.ts

7

CHANGELOG.md

@@ -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 @@

14

lib/module.js
'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"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc