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

@lu-development/pi-xstate-fetch

Package Overview
Dependencies
Maintainers
13
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lu-development/pi-xstate-fetch - npm Package Compare versions

Comparing version 0.0.13 to 0.0.14

dist/utils/csrf.d.ts

76

dist/fetch-machine.d.ts

@@ -1,73 +0,7 @@

import { FetchMethods } from './enums';
export declare const fetchModel: import("xstate/lib/model.types").Model<{
requestMethod: FetchMethods;
requestBody: any;
baseUrl: string | undefined;
path: string | undefined;
token: string | undefined;
delayBetweenRetriesMilliseconds: number;
retriesAllowed: number;
}, import("xstate/lib/model.types").UnionFromCreatorsReturnTypes<import("xstate/lib/model.types").FinalEventCreators<{
RETRY: () => {};
FAIL: (error: any) => {
error: any;
};
"done.invoke.fetchServiceInvoker": (data: any) => {
data: any;
};
}>>, import("xstate").BaseActionObject, import("xstate/lib/model.types").FinalModelCreators<{
events: {
RETRY: () => {};
FAIL: (error: any) => {
error: any;
};
"done.invoke.fetchServiceInvoker": (data: any) => {
data: any;
};
};
}>>;
import { FetchContext, FetchEvents } from './types';
export declare const fetchModel: import("xstate/lib/model.types").Model<FetchContext, FetchEvents, import("xstate").BaseActionObject, void>;
export declare const processFailure: (context: any, event: any) => (callback: any) => void;
export declare const fetchMachine: import("xstate").StateMachine<{
requestMethod: FetchMethods;
requestBody: any;
baseUrl: string | undefined;
path: string | undefined;
token: string | undefined;
delayBetweenRetriesMilliseconds: number;
retriesAllowed: number;
}, any, import("xstate/lib/model.types").UnionFromCreatorsReturnTypes<import("xstate/lib/model.types").FinalEventCreators<{
RETRY: () => {};
FAIL: (error: any) => {
error: any;
};
"done.invoke.fetchServiceInvoker": (data: any) => {
data: any;
};
}>>, {
export declare const fetchMachine: import("xstate").StateMachine<FetchContext, any, FetchEvents, {
value: any;
context: {
requestMethod: FetchMethods;
requestBody: any;
baseUrl: string | undefined;
path: string | undefined;
token: string | undefined;
delayBetweenRetriesMilliseconds: number;
retriesAllowed: number;
};
}, import("xstate").ActionObject<{
requestMethod: FetchMethods;
requestBody: any;
baseUrl: string | undefined;
path: string | undefined;
token: string | undefined;
delayBetweenRetriesMilliseconds: number;
retriesAllowed: number;
}, import("xstate/lib/model.types").UnionFromCreatorsReturnTypes<import("xstate/lib/model.types").FinalEventCreators<{
RETRY: () => {};
FAIL: (error: any) => {
error: any;
};
"done.invoke.fetchServiceInvoker": (data: any) => {
data: any;
};
}>>>>;
context: FetchContext;
}, import("xstate").ActionObject<FetchContext, FetchEvents>>;
"use strict";
var _a, _b, _c;
var _a, _b;
Object.defineProperty(exports, "__esModule", { value: true });

@@ -10,15 +10,6 @@ exports.fetchMachine = exports.processFailure = exports.fetchModel = void 0;

exports.fetchModel = (0, model_1.createModel)({
requestMethod: 'GET',
requestBody: undefined,
baseUrl: undefined,
path: undefined,
token: undefined,
requestMethod: enums_1.FetchMethods.GET,
delayBetweenRetriesMilliseconds: 400,
retriesAllowed: 0,
}, {
events: (_a = {},
_a[enums_1.fetchEvents.RETRY] = function () { return ({}); },
_a[enums_1.fetchEvents.FAIL] = function (error) { return ({ error: error }); },
_a[enums_1.fetchEvents.FETCH_SERVICE_SUCCESS] = function (data) { return ({ data: data }); },
_a),
sendCsrfTokenWithHeaders: false
});

@@ -44,7 +35,7 @@ // actions

context: exports.fetchModel.initialContext,
states: (_b = {},
_b[enums_1.fetchStates.IDLE] = {
states: (_a = {},
_a[enums_1.fetchStates.IDLE] = {
always: enums_1.fetchStates.FETCHING,
},
_b[enums_1.fetchStates.FETCHING] = {
_a[enums_1.fetchStates.FETCHING] = {
invoke: {

@@ -61,3 +52,3 @@ id: 'fetchServiceInvoker',

},
_b[enums_1.fetchStates.PROCESSING_FAILURE] = {
_a[enums_1.fetchStates.PROCESSING_FAILURE] = {
invoke: {

@@ -68,8 +59,8 @@ id: 'processFetchFailure',

exit: 'decrementRetriesAllowed',
on: (_c = {},
_c[enums_1.fetchEvents.RETRY] = enums_1.fetchStates.IDLE,
_c[enums_1.fetchEvents.FAIL] = enums_1.fetchStates.FAILED,
_c),
on: (_b = {},
_b[enums_1.fetchEvents.RETRY] = enums_1.fetchStates.IDLE,
_b[enums_1.fetchEvents.FAIL] = enums_1.fetchStates.FAILED,
_b),
},
_b[enums_1.fetchStates.SUCCESS] = {
_a[enums_1.fetchStates.SUCCESS] = {
type: 'final',

@@ -83,3 +74,3 @@ entry: (0, xstate_1.sendParent)(function (_, event) {

},
_b[enums_1.fetchStates.FAILED] = {
_a[enums_1.fetchStates.FAILED] = {
type: 'final',

@@ -93,3 +84,3 @@ entry: (0, xstate_1.sendParent)(function (_, event) {

},
_b),
_a),
}, {

@@ -96,0 +87,0 @@ services: {

@@ -51,2 +51,3 @@ "use strict";

exports.fetchService = void 0;
var csrf_1 = require("../utils/csrf");
var fetchService = function (context) { return __awaiter(void 0, void 0, void 0, function () {

@@ -57,9 +58,7 @@ var request, data, res, e_1;

case 0:
request = __assign(__assign({ method: context.requestMethod }, (!!context.token && {
headers: {
'Authorization': "Bearer " + context.token,
request = __assign(__assign(__assign({ method: context.requestMethod }, ((!!context.token || context.sendCsrfTokenWithHeaders) && {
headers: __assign(__assign({}, !!context.token && { 'Authorization': "Bearer " + context.token,
'Accept': "application/json",
'Content-Type': 'application/json',
},
})), (!!context.requestBody && { body: context.requestBody }));
'Content-Type': 'application/json' }), context.sendCsrfTokenWithHeaders && { 'CSRF-TOKEN': (0, csrf_1.getCsrfDecodedToken)() }),
})), (!!context.requestBody && { body: context.requestBody })), (context.sendCsrfTokenWithHeaders && { credentials: 'include' }));
_a.label = 1;

@@ -66,0 +65,0 @@ case 1:

import type { fetchEvents } from './enums';
import { ContextFrom, EventFrom, EventObject } from 'xstate';
import type { fetchModel } from './fetch-machine';
import { EventObject } from 'xstate';
import { FetchMethods } from './enums';
export declare type FetchSuccessEvent = {

@@ -18,3 +18,23 @@ data: any;

};
export declare type FetchContext = ContextFrom<typeof fetchModel>;
export declare type FetchEvents = EventFrom<typeof fetchModel>;
export declare type FetchContext = {
requestMethod: FetchMethods;
requestBody?: any;
baseUrl?: string;
path?: string;
token?: string;
delayBetweenRetriesMilliseconds: number;
retriesAllowed: number;
sendCsrfTokenWithHeaders: boolean;
};
export interface RetryEvent extends EventObject {
type: fetchEvents.RETRY;
}
export interface FailEvent extends EventObject {
type: fetchEvents.FAIL;
error: any;
}
export interface FetchServiceSuccessEvent extends EventObject {
type: fetchEvents.FETCH_SERVICE_SUCCESS;
data: any;
}
export declare type FetchEvents = RetryEvent | FailEvent | FetchServiceSuccessEvent;
{
"name": "@lu-development/pi-xstate-fetch",
"version": "0.0.13",
"version": "0.0.14",
"description": "Fetch State Machine",

@@ -14,3 +14,4 @@ "files": [

"test": "jest",
"pub": "npm run clean & npm run build && npm publish --access public"
"pub": "npm run clean & npm run build && npm publish --access public",
"prepare": "husky install"
},

@@ -30,3 +31,6 @@ "author": "",

"eslint": "^8.1.0",
"husky": "^7.0.4",
"jest": "^27.2.5",
"lint-staged": "^11.2.6",
"prettier-plugin-style-order": "^0.2.2",
"rimraf": "^3.0.2",

@@ -36,3 +40,6 @@ "sinon": "^11.1.2",

"typescript": "^4.4.4"
},
"lint-staged": {
"**/*": "prettier --write --ignore-unknown"
}
}
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