@adonisjs/session 7.0.0-13 → 7.0.0-15
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.
- package/build/chunk-2X5L327N.js +28 -0
- package/build/chunk-2X5L327N.js.map +1 -0
- package/build/chunk-HIQQAMXD.js +133 -0
- package/build/chunk-HIQQAMXD.js.map +1 -0
- package/build/chunk-K4OSGJVW.js +402 -0
- package/build/chunk-K4OSGJVW.js.map +1 -0
- package/build/chunk-S6P3TBEK.js +85 -0
- package/build/chunk-S6P3TBEK.js.map +1 -0
- package/build/chunk-TE5JP3SX.js +151 -0
- package/build/chunk-TE5JP3SX.js.map +1 -0
- package/build/chunk-WBAYBMJJ.js +15 -0
- package/build/chunk-WBAYBMJJ.js.map +1 -0
- package/build/{stubs/config.stub → config/session.stub} +3 -1
- package/build/cookie-H7KRZB4T.js +56 -0
- package/build/cookie-H7KRZB4T.js.map +1 -0
- package/build/factories/main.js +50 -9
- package/build/factories/main.js.map +1 -0
- package/build/file-YO7C2QWO.js +112 -0
- package/build/file-YO7C2QWO.js.map +1 -0
- package/build/index.d.ts +0 -1
- package/build/index.js +16 -12
- package/build/index.js.map +1 -0
- package/build/providers/session_provider.js +51 -59
- package/build/providers/session_provider.js.map +1 -0
- package/build/redis-KDWIBKUQ.js +58 -0
- package/build/redis-KDWIBKUQ.js.map +1 -0
- package/build/src/client.js +9 -85
- package/build/src/client.js.map +1 -0
- package/build/src/plugins/edge.js +101 -91
- package/build/src/plugins/edge.js.map +1 -0
- package/build/src/plugins/japa/api_client.js +99 -140
- package/build/src/plugins/japa/api_client.js.map +1 -0
- package/build/src/plugins/japa/browser_client.js +82 -109
- package/build/src/plugins/japa/browser_client.js.map +1 -0
- package/build/src/session.d.ts +14 -5
- package/build/src/session_middleware.js +10 -58
- package/build/src/session_middleware.js.map +1 -0
- package/build/src/values_store.d.ts +7 -7
- package/package.json +60 -43
- package/build/configure.js +0 -45
- package/build/factories/session_middleware_factory.js +0 -48
- package/build/src/debug.js +0 -10
- package/build/src/define_config.js +0 -105
- package/build/src/errors.js +0 -17
- package/build/src/session.js +0 -387
- package/build/src/stores/cookie.js +0 -60
- package/build/src/stores/file.js +0 -133
- package/build/src/stores/memory.js +0 -33
- package/build/src/stores/redis.js +0 -66
- package/build/src/types.js +0 -9
- package/build/src/values_store.js +0 -159
- package/build/stubs/main.js +0 -10
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ValuesStore
|
|
3
|
+
} from "./chunk-TE5JP3SX.js";
|
|
4
|
+
import {
|
|
5
|
+
debug_default
|
|
6
|
+
} from "./chunk-WBAYBMJJ.js";
|
|
7
|
+
|
|
8
|
+
// src/client.ts
|
|
9
|
+
import { cuid } from "@adonisjs/core/helpers";
|
|
10
|
+
var SessionClient = class {
|
|
11
|
+
/**
|
|
12
|
+
* Data store
|
|
13
|
+
*/
|
|
14
|
+
#valuesStore = new ValuesStore({});
|
|
15
|
+
/**
|
|
16
|
+
* Flash messages store
|
|
17
|
+
*/
|
|
18
|
+
#flashMessagesStore = new ValuesStore({});
|
|
19
|
+
/**
|
|
20
|
+
* The session store to use for reading and writing session data
|
|
21
|
+
*/
|
|
22
|
+
#store;
|
|
23
|
+
/**
|
|
24
|
+
* Session key for setting flash messages
|
|
25
|
+
*/
|
|
26
|
+
flashKey = "__flash__";
|
|
27
|
+
/**
|
|
28
|
+
* Session to use when no explicit session id is
|
|
29
|
+
* defined
|
|
30
|
+
*/
|
|
31
|
+
sessionId = cuid();
|
|
32
|
+
constructor(store) {
|
|
33
|
+
this.#store = store;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Merge session data
|
|
37
|
+
*/
|
|
38
|
+
merge(values) {
|
|
39
|
+
this.#valuesStore.merge(values);
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Merge flash messages
|
|
44
|
+
*/
|
|
45
|
+
flash(values) {
|
|
46
|
+
this.#flashMessagesStore.merge(values);
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Commits data to the session store.
|
|
51
|
+
*/
|
|
52
|
+
async commit() {
|
|
53
|
+
if (!this.#flashMessagesStore.isEmpty) {
|
|
54
|
+
this.#valuesStore.set(this.flashKey, this.#flashMessagesStore.toJSON());
|
|
55
|
+
}
|
|
56
|
+
debug_default("committing session data during api request");
|
|
57
|
+
if (!this.#valuesStore.isEmpty) {
|
|
58
|
+
this.#store.write(this.sessionId, this.#valuesStore.toJSON());
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Destroys the session data with the store
|
|
63
|
+
*/
|
|
64
|
+
async destroy(sessionId) {
|
|
65
|
+
debug_default("destroying session data during api request");
|
|
66
|
+
this.#store.destroy(sessionId || this.sessionId);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Loads session data from the session store
|
|
70
|
+
*/
|
|
71
|
+
async load(sessionId) {
|
|
72
|
+
const contents = await this.#store.read(sessionId || this.sessionId);
|
|
73
|
+
const store = new ValuesStore(contents);
|
|
74
|
+
const flashMessages = store.pull(this.flashKey, {});
|
|
75
|
+
return {
|
|
76
|
+
values: store.all(),
|
|
77
|
+
flashMessages
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export {
|
|
83
|
+
SessionClient
|
|
84
|
+
};
|
|
85
|
+
//# sourceMappingURL=chunk-S6P3TBEK.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client.ts"],"sourcesContent":["/*\n * @adonisjs/session\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { cuid } from '@adonisjs/core/helpers'\n\nimport debug from './debug.js'\nimport { ValuesStore } from './values_store.js'\nimport type { SessionData, SessionStoreContract } from './types.js'\n\n/**\n * Session client exposes the API to set session data as a client\n */\nexport class SessionClient {\n /**\n * Data store\n */\n #valuesStore = new ValuesStore({})\n\n /**\n * Flash messages store\n */\n #flashMessagesStore = new ValuesStore({})\n\n /**\n * The session store to use for reading and writing session data\n */\n #store: SessionStoreContract\n\n /**\n * Session key for setting flash messages\n */\n flashKey = '__flash__'\n\n /**\n * Session to use when no explicit session id is\n * defined\n */\n sessionId = cuid()\n\n constructor(store: SessionStoreContract) {\n this.#store = store\n }\n\n /**\n * Merge session data\n */\n merge(values: SessionData) {\n this.#valuesStore.merge(values)\n return this\n }\n\n /**\n * Merge flash messages\n */\n flash(values: SessionData) {\n this.#flashMessagesStore.merge(values)\n return this\n }\n\n /**\n * Commits data to the session store.\n */\n async commit() {\n if (!this.#flashMessagesStore.isEmpty) {\n this.#valuesStore.set(this.flashKey, this.#flashMessagesStore.toJSON())\n }\n\n debug('committing session data during api request')\n if (!this.#valuesStore.isEmpty) {\n this.#store.write(this.sessionId, this.#valuesStore.toJSON())\n }\n }\n\n /**\n * Destroys the session data with the store\n */\n async destroy(sessionId?: string) {\n debug('destroying session data during api request')\n this.#store.destroy(sessionId || this.sessionId)\n }\n\n /**\n * Loads session data from the session store\n */\n async load(sessionId?: string) {\n const contents = await this.#store.read(sessionId || this.sessionId)\n const store = new ValuesStore(contents)\n const flashMessages = store.pull(this.flashKey, {})\n\n return {\n values: store.all(),\n flashMessages,\n }\n }\n}\n"],"mappings":";;;;;;;;AASA,SAAS,YAAY;AASd,IAAM,gBAAN,MAAoB;AAAA;AAAA;AAAA;AAAA,EAIzB,eAAe,IAAI,YAAY,CAAC,CAAC;AAAA;AAAA;AAAA;AAAA,EAKjC,sBAAsB,IAAI,YAAY,CAAC,CAAC;AAAA;AAAA;AAAA;AAAA,EAKxC;AAAA;AAAA;AAAA;AAAA,EAKA,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA,EAMX,YAAY,KAAK;AAAA,EAEjB,YAAY,OAA6B;AACvC,SAAK,SAAS;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,QAAqB;AACzB,SAAK,aAAa,MAAM,MAAM;AAC9B,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,QAAqB;AACzB,SAAK,oBAAoB,MAAM,MAAM;AACrC,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,SAAS;AACb,QAAI,CAAC,KAAK,oBAAoB,SAAS;AACrC,WAAK,aAAa,IAAI,KAAK,UAAU,KAAK,oBAAoB,OAAO,CAAC;AAAA,IACxE;AAEA,kBAAM,4CAA4C;AAClD,QAAI,CAAC,KAAK,aAAa,SAAS;AAC9B,WAAK,OAAO,MAAM,KAAK,WAAW,KAAK,aAAa,OAAO,CAAC;AAAA,IAC9D;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,QAAQ,WAAoB;AAChC,kBAAM,4CAA4C;AAClD,SAAK,OAAO,QAAQ,aAAa,KAAK,SAAS;AAAA,EACjD;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,KAAK,WAAoB;AAC7B,UAAM,WAAW,MAAM,KAAK,OAAO,KAAK,aAAa,KAAK,SAAS;AACnE,UAAM,QAAQ,IAAI,YAAY,QAAQ;AACtC,UAAM,gBAAgB,MAAM,KAAK,KAAK,UAAU,CAAC,CAAC;AAElD,WAAO;AAAA,MACL,QAAQ,MAAM,IAAI;AAAA,MAClB;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// src/values_store.ts
|
|
2
|
+
import lodash from "@poppinss/utils/lodash";
|
|
3
|
+
import { RuntimeException } from "@poppinss/utils";
|
|
4
|
+
var ReadOnlyValuesStore = class {
|
|
5
|
+
/**
|
|
6
|
+
* Underlying store values
|
|
7
|
+
*/
|
|
8
|
+
values;
|
|
9
|
+
/**
|
|
10
|
+
* Find if store is empty or not
|
|
11
|
+
*/
|
|
12
|
+
get isEmpty() {
|
|
13
|
+
return !this.values || Object.keys(this.values).length === 0;
|
|
14
|
+
}
|
|
15
|
+
constructor(values) {
|
|
16
|
+
this.values = values || {};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get value for a given key
|
|
20
|
+
*/
|
|
21
|
+
get(key, defaultValue) {
|
|
22
|
+
const value = lodash.get(this.values, key);
|
|
23
|
+
if (defaultValue !== void 0 && (value === null || value === void 0)) {
|
|
24
|
+
return defaultValue;
|
|
25
|
+
}
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A boolean to know if value exists. Extra guards to check
|
|
30
|
+
* arrays for it's length as well.
|
|
31
|
+
*/
|
|
32
|
+
has(key, checkForArraysLength = true) {
|
|
33
|
+
const value = this.get(key);
|
|
34
|
+
if (!Array.isArray(value)) {
|
|
35
|
+
return !!value;
|
|
36
|
+
}
|
|
37
|
+
return checkForArraysLength ? value.length > 0 : !!value;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Get all values
|
|
41
|
+
*/
|
|
42
|
+
all() {
|
|
43
|
+
return this.values;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Returns object representation of values
|
|
47
|
+
*/
|
|
48
|
+
toObject() {
|
|
49
|
+
return this.all();
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Returns the store values
|
|
53
|
+
*/
|
|
54
|
+
toJSON() {
|
|
55
|
+
return this.all();
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Returns string representation of the store
|
|
59
|
+
*/
|
|
60
|
+
toString() {
|
|
61
|
+
return JSON.stringify(this.all());
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
var ValuesStore = class extends ReadOnlyValuesStore {
|
|
65
|
+
/**
|
|
66
|
+
* A boolean to know if store has been
|
|
67
|
+
* modified
|
|
68
|
+
*/
|
|
69
|
+
#modified = false;
|
|
70
|
+
constructor(values) {
|
|
71
|
+
super(values);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Find if the store has been modified.
|
|
75
|
+
*/
|
|
76
|
+
get hasBeenModified() {
|
|
77
|
+
return this.#modified;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Set key/value pair
|
|
81
|
+
*/
|
|
82
|
+
set(key, value) {
|
|
83
|
+
this.#modified = true;
|
|
84
|
+
lodash.set(this.values, key, value);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Remove key
|
|
88
|
+
*/
|
|
89
|
+
unset(key) {
|
|
90
|
+
this.#modified = true;
|
|
91
|
+
lodash.unset(this.values, key);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Pull value from the store. It is same as calling
|
|
95
|
+
* store.get and then store.unset
|
|
96
|
+
*/
|
|
97
|
+
pull(key, defaultValue) {
|
|
98
|
+
return ((value) => {
|
|
99
|
+
this.unset(key);
|
|
100
|
+
return value;
|
|
101
|
+
})(this.get(key, defaultValue));
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Increment number. The method raises an error when
|
|
105
|
+
* nderlying value is not a number
|
|
106
|
+
*/
|
|
107
|
+
increment(key, steps = 1) {
|
|
108
|
+
const value = this.get(key, 0);
|
|
109
|
+
if (typeof value !== "number") {
|
|
110
|
+
throw new RuntimeException(`Cannot increment "${key}". Existing value is not a number`);
|
|
111
|
+
}
|
|
112
|
+
this.set(key, value + steps);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Increment number. The method raises an error when
|
|
116
|
+
* nderlying value is not a number
|
|
117
|
+
*/
|
|
118
|
+
decrement(key, steps = 1) {
|
|
119
|
+
const value = this.get(key, 0);
|
|
120
|
+
if (typeof value !== "number") {
|
|
121
|
+
throw new RuntimeException(`Cannot decrement "${key}". Existing value is not a number`);
|
|
122
|
+
}
|
|
123
|
+
this.set(key, value - steps);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Overwrite existing store data with new values.
|
|
127
|
+
*/
|
|
128
|
+
update(values) {
|
|
129
|
+
this.#modified = true;
|
|
130
|
+
this.values = values;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Update to merge values
|
|
134
|
+
*/
|
|
135
|
+
merge(values) {
|
|
136
|
+
this.#modified = true;
|
|
137
|
+
lodash.merge(this.values, values);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Reset store by clearing it's values.
|
|
141
|
+
*/
|
|
142
|
+
clear() {
|
|
143
|
+
this.update({});
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
export {
|
|
148
|
+
ReadOnlyValuesStore,
|
|
149
|
+
ValuesStore
|
|
150
|
+
};
|
|
151
|
+
//# sourceMappingURL=chunk-TE5JP3SX.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/values_store.ts"],"sourcesContent":["/*\n * @adonisjs/redis\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport lodash from '@poppinss/utils/lodash'\nimport { RuntimeException } from '@poppinss/utils'\nimport type { AllowedSessionValues, SessionData } from './types.js'\n\n/**\n * Readonly session store\n */\nexport class ReadOnlyValuesStore {\n /**\n * Underlying store values\n */\n protected values: SessionData\n\n /**\n * Find if store is empty or not\n */\n get isEmpty() {\n return !this.values || Object.keys(this.values).length === 0\n }\n\n constructor(values: SessionData | null) {\n this.values = values || {}\n }\n\n /**\n * Get value for a given key\n */\n get(key: string | string[], defaultValue?: any): any {\n const value = lodash.get(this.values, key)\n if (defaultValue !== undefined && (value === null || value === undefined)) {\n return defaultValue\n }\n\n return value\n }\n\n /**\n * A boolean to know if value exists. Extra guards to check\n * arrays for it's length as well.\n */\n has(key: string | string[], checkForArraysLength: boolean = true): boolean {\n const value = this.get(key)\n if (!Array.isArray(value)) {\n return !!value\n }\n\n return checkForArraysLength ? value.length > 0 : !!value\n }\n\n /**\n * Get all values\n */\n all(): any {\n return this.values\n }\n\n /**\n * Returns object representation of values\n */\n toObject() {\n return this.all()\n }\n\n /**\n * Returns the store values\n */\n toJSON(): any {\n return this.all()\n }\n\n /**\n * Returns string representation of the store\n */\n toString() {\n return JSON.stringify(this.all())\n }\n}\n\n/**\n * Session store encapsulates the session data and offers a\n * declarative API to mutate it.\n */\nexport class ValuesStore extends ReadOnlyValuesStore {\n /**\n * A boolean to know if store has been\n * modified\n */\n #modified: boolean = false\n\n constructor(values: SessionData | null) {\n super(values)\n }\n\n /**\n * Find if the store has been modified.\n */\n get hasBeenModified(): boolean {\n return this.#modified\n }\n\n /**\n * Set key/value pair\n */\n set(key: string | string[], value: AllowedSessionValues): void {\n this.#modified = true\n lodash.set(this.values, key, value)\n }\n\n /**\n * Remove key\n */\n unset(key: string | string[]): void {\n this.#modified = true\n lodash.unset(this.values, key)\n }\n\n /**\n * Pull value from the store. It is same as calling\n * store.get and then store.unset\n */\n pull(key: string | string[], defaultValue?: any): any {\n return ((value): any => {\n this.unset(key)\n return value\n })(this.get(key, defaultValue))\n }\n\n /**\n * Increment number. The method raises an error when\n * nderlying value is not a number\n */\n increment(key: string | string[], steps: number = 1): void {\n const value = this.get(key, 0)\n if (typeof value !== 'number') {\n throw new RuntimeException(`Cannot increment \"${key}\". Existing value is not a number`)\n }\n\n this.set(key, value + steps)\n }\n\n /**\n * Increment number. The method raises an error when\n * nderlying value is not a number\n */\n decrement(key: string | string[], steps: number = 1): void {\n const value = this.get(key, 0)\n if (typeof value !== 'number') {\n throw new RuntimeException(`Cannot decrement \"${key}\". Existing value is not a number`)\n }\n\n this.set(key, value - steps)\n }\n\n /**\n * Overwrite existing store data with new values.\n */\n update(values: { [key: string]: any }): void {\n this.#modified = true\n this.values = values\n }\n\n /**\n * Update to merge values\n */\n merge(values: { [key: string]: any }): any {\n this.#modified = true\n lodash.merge(this.values, values)\n }\n\n /**\n * Reset store by clearing it's values.\n */\n clear(): void {\n this.update({})\n }\n}\n"],"mappings":";AASA,OAAO,YAAY;AACnB,SAAS,wBAAwB;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|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// src/debug.ts
|
|
8
|
+
import { debuglog } from "node:util";
|
|
9
|
+
var debug_default = debuglog("adonisjs:session");
|
|
10
|
+
|
|
11
|
+
export {
|
|
12
|
+
__export,
|
|
13
|
+
debug_default
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=chunk-WBAYBMJJ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/debug.ts"],"sourcesContent":["/*\n * @adonisjs/session\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { debuglog } from 'node:util'\n\nexport default debuglog('adonisjs:session')\n"],"mappings":";;;;;;;AASA,SAAS,gBAAgB;AAEzB,IAAO,gBAAQ,SAAS,kBAAkB;","names":[]}
|
|
@@ -5,7 +5,7 @@ import env from '#start/env'
|
|
|
5
5
|
import app from '@adonisjs/core/services/app'
|
|
6
6
|
import { defineConfig, stores } from '@adonisjs/session'
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
const sessionConfig = defineConfig({
|
|
9
9
|
enabled: true,
|
|
10
10
|
cookieName: 'adonis-session',
|
|
11
11
|
|
|
@@ -47,3 +47,5 @@ export default defineConfig({
|
|
|
47
47
|
cookie: stores.cookie(),
|
|
48
48
|
}
|
|
49
49
|
})
|
|
50
|
+
|
|
51
|
+
export default sessionConfig
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {
|
|
2
|
+
debug_default
|
|
3
|
+
} from "./chunk-WBAYBMJJ.js";
|
|
4
|
+
|
|
5
|
+
// src/stores/cookie.ts
|
|
6
|
+
var CookieStore = class {
|
|
7
|
+
#ctx;
|
|
8
|
+
#config;
|
|
9
|
+
constructor(config, ctx) {
|
|
10
|
+
this.#config = config;
|
|
11
|
+
this.#ctx = ctx;
|
|
12
|
+
debug_default("initiating cookie store %O", this.#config);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Read session value from the cookie
|
|
16
|
+
*/
|
|
17
|
+
read(sessionId) {
|
|
18
|
+
debug_default("cookie store: reading session data %s", sessionId);
|
|
19
|
+
const cookieValue = this.#ctx.request.encryptedCookie(sessionId);
|
|
20
|
+
if (typeof cookieValue !== "object") {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
return cookieValue;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Write session values to the cookie
|
|
27
|
+
*/
|
|
28
|
+
write(sessionId, values) {
|
|
29
|
+
debug_default("cookie store: writing session data %s: %O", sessionId, values);
|
|
30
|
+
this.#ctx.response.encryptedCookie(sessionId, values, this.#config);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Removes the session cookie
|
|
34
|
+
*/
|
|
35
|
+
destroy(sessionId) {
|
|
36
|
+
debug_default("cookie store: destroying session data %s", sessionId);
|
|
37
|
+
if (this.#ctx.request.cookiesList()[sessionId]) {
|
|
38
|
+
this.#ctx.response.clearCookie(sessionId);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Updates the cookie with existing cookie values
|
|
43
|
+
*/
|
|
44
|
+
touch(sessionId) {
|
|
45
|
+
const value = this.read(sessionId);
|
|
46
|
+
debug_default("cookie store: touching session data %s", sessionId);
|
|
47
|
+
if (!value) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
this.write(sessionId, value);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
export {
|
|
54
|
+
CookieStore
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=cookie-H7KRZB4T.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/stores/cookie.ts"],"sourcesContent":["/*\n * @adonisjs/session\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport type { HttpContext } from '@adonisjs/core/http'\nimport type { CookieOptions } from '@adonisjs/core/types/http'\n\nimport debug from '../debug.js'\nimport type { SessionData, SessionStoreContract } from '../types.js'\n\n/**\n * Cookie store stores the session data inside an encrypted\n * cookie.\n */\nexport class CookieStore implements SessionStoreContract {\n #ctx: HttpContext\n #config: Partial<CookieOptions>\n\n constructor(config: Partial<CookieOptions>, ctx: HttpContext) {\n this.#config = config\n this.#ctx = ctx\n debug('initiating cookie store %O', this.#config)\n }\n\n /**\n * Read session value from the cookie\n */\n read(sessionId: string): SessionData | null {\n debug('cookie store: reading session data %s', sessionId)\n\n const cookieValue = this.#ctx.request.encryptedCookie(sessionId)\n if (typeof cookieValue !== 'object') {\n return null\n }\n\n return cookieValue\n }\n\n /**\n * Write session values to the cookie\n */\n write(sessionId: string, values: SessionData): void {\n debug('cookie store: writing session data %s: %O', sessionId, values)\n this.#ctx.response.encryptedCookie(sessionId, values, this.#config)\n }\n\n /**\n * Removes the session cookie\n */\n destroy(sessionId: string): void {\n debug('cookie store: destroying session data %s', sessionId)\n if (this.#ctx.request.cookiesList()[sessionId]) {\n this.#ctx.response.clearCookie(sessionId)\n }\n }\n\n /**\n * Updates the cookie with existing cookie values\n */\n touch(sessionId: string): void {\n const value = this.read(sessionId)\n debug('cookie store: touching session data %s', sessionId)\n if (!value) {\n return\n }\n\n this.write(sessionId, value)\n }\n}\n"],"mappings":";;;;;AAmBO,IAAM,cAAN,MAAkD;AAAA,EACvD;AAAA,EACA;AAAA,EAEA,YAAY,QAAgC,KAAkB;AAC5D,SAAK,UAAU;AACf,SAAK,OAAO;AACZ,kBAAM,8BAA8B,KAAK,OAAO;AAAA,EAClD;AAAA;AAAA;AAAA;AAAA,EAKA,KAAK,WAAuC;AAC1C,kBAAM,yCAAyC,SAAS;AAExD,UAAM,cAAc,KAAK,KAAK,QAAQ,gBAAgB,SAAS;AAC/D,QAAI,OAAO,gBAAgB,UAAU;AACnC,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,WAAmB,QAA2B;AAClD,kBAAM,6CAA6C,WAAW,MAAM;AACpE,SAAK,KAAK,SAAS,gBAAgB,WAAW,QAAQ,KAAK,OAAO;AAAA,EACpE;AAAA;AAAA;AAAA;AAAA,EAKA,QAAQ,WAAyB;AAC/B,kBAAM,4CAA4C,SAAS;AAC3D,QAAI,KAAK,KAAK,QAAQ,YAAY,EAAE,SAAS,GAAG;AAC9C,WAAK,KAAK,SAAS,YAAY,SAAS;AAAA,IAC1C;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,WAAyB;AAC7B,UAAM,QAAQ,KAAK,KAAK,SAAS;AACjC,kBAAM,0CAA0C,SAAS;AACzD,QAAI,CAAC,OAAO;AACV;AAAA,IACF;AAEA,SAAK,MAAM,WAAW,KAAK;AAAA,EAC7B;AACF;","names":[]}
|
package/build/factories/main.js
CHANGED
|
@@ -1,9 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import {
|
|
2
|
+
defineConfig
|
|
3
|
+
} from "../chunk-HIQQAMXD.js";
|
|
4
|
+
import {
|
|
5
|
+
SessionMiddleware
|
|
6
|
+
} from "../chunk-K4OSGJVW.js";
|
|
7
|
+
import "../chunk-2X5L327N.js";
|
|
8
|
+
import "../chunk-TE5JP3SX.js";
|
|
9
|
+
import "../chunk-WBAYBMJJ.js";
|
|
10
|
+
|
|
11
|
+
// factories/session_middleware_factory.ts
|
|
12
|
+
import { Emitter } from "@adonisjs/core/events";
|
|
13
|
+
import { AppFactory } from "@adonisjs/core/factories/app";
|
|
14
|
+
var SessionMiddlewareFactory = class {
|
|
15
|
+
#config = {
|
|
16
|
+
store: "memory",
|
|
17
|
+
stores: {}
|
|
18
|
+
};
|
|
19
|
+
#emitter;
|
|
20
|
+
#getApp() {
|
|
21
|
+
return new AppFactory().create(new URL("./", import.meta.url), () => {
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
#getEmitter() {
|
|
25
|
+
return this.#emitter || new Emitter(this.#getApp());
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Merge custom options
|
|
29
|
+
*/
|
|
30
|
+
merge(options) {
|
|
31
|
+
if (options.config) {
|
|
32
|
+
this.#config = options.config;
|
|
33
|
+
}
|
|
34
|
+
if (options.emitter) {
|
|
35
|
+
this.#emitter = options.emitter;
|
|
36
|
+
}
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Creates an instance of the session middleware
|
|
41
|
+
*/
|
|
42
|
+
async create() {
|
|
43
|
+
const config = await defineConfig(this.#config).resolver(this.#getApp());
|
|
44
|
+
return new SessionMiddleware(config, this.#getEmitter());
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
export {
|
|
48
|
+
SessionMiddlewareFactory
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../factories/session_middleware_factory.ts"],"sourcesContent":["/*\n * @adonisjs/session\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { Emitter } from '@adonisjs/core/events'\nimport { AppFactory } from '@adonisjs/core/factories/app'\nimport type { ApplicationService, EventsList } from '@adonisjs/core/types'\n\nimport { defineConfig } from '../index.js'\nimport SessionMiddleware from '../src/session_middleware.js'\nimport type { SessionConfig, SessionStoreFactory } from '../src/types.js'\n\n/**\n * Exposes the API to create an instance of the session middleware\n * without additional plumbing\n */\nexport class SessionMiddlewareFactory {\n #config: Partial<SessionConfig> & {\n store: string\n stores: Record<string, SessionStoreFactory>\n } = {\n store: 'memory',\n stores: {},\n }\n\n #emitter?: Emitter<EventsList>\n\n #getApp() {\n return new AppFactory().create(new URL('./', import.meta.url), () => {}) as ApplicationService\n }\n\n #getEmitter() {\n return this.#emitter || new Emitter<EventsList>(this.#getApp())\n }\n\n /**\n * Merge custom options\n */\n merge(options: {\n config?: Partial<SessionConfig> & {\n store: string\n stores: Record<string, SessionStoreFactory>\n }\n emitter?: Emitter<EventsList>\n }) {\n if (options.config) {\n this.#config = options.config\n }\n\n if (options.emitter) {\n this.#emitter = options.emitter\n }\n\n return this\n }\n\n /**\n * Creates an instance of the session middleware\n */\n async create() {\n const config = await defineConfig(this.#config).resolver(this.#getApp())\n return new SessionMiddleware(config, this.#getEmitter())\n }\n}\n"],"mappings":";;;;;;;;;;;AASA,SAAS,eAAe;AACxB,SAAS,kBAAkB;AAWpB,IAAM,2BAAN,MAA+B;AAAA,EACpC,UAGI;AAAA,IACF,OAAO;AAAA,IACP,QAAQ,CAAC;AAAA,EACX;AAAA,EAEA;AAAA,EAEA,UAAU;AACR,WAAO,IAAI,WAAW,EAAE,OAAO,IAAI,IAAI,MAAM,YAAY,GAAG,GAAG,MAAM;AAAA,IAAC,CAAC;AAAA,EACzE;AAAA,EAEA,cAAc;AACZ,WAAO,KAAK,YAAY,IAAI,QAAoB,KAAK,QAAQ,CAAC;AAAA,EAChE;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,SAMH;AACD,QAAI,QAAQ,QAAQ;AAClB,WAAK,UAAU,QAAQ;AAAA,IACzB;AAEA,QAAI,QAAQ,SAAS;AACnB,WAAK,WAAW,QAAQ;AAAA,IAC1B;AAEA,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,SAAS;AACb,UAAM,SAAS,MAAM,aAAa,KAAK,OAAO,EAAE,SAAS,KAAK,QAAQ,CAAC;AACvE,WAAO,IAAI,kBAAkB,QAAQ,KAAK,YAAY,CAAC;AAAA,EACzD;AACF;","names":[]}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import {
|
|
2
|
+
debug_default
|
|
3
|
+
} from "./chunk-WBAYBMJJ.js";
|
|
4
|
+
|
|
5
|
+
// src/stores/file.ts
|
|
6
|
+
import { dirname, join } from "node:path";
|
|
7
|
+
import string from "@poppinss/utils/string";
|
|
8
|
+
import { MessageBuilder } from "@adonisjs/core/helpers";
|
|
9
|
+
import { access, mkdir, readFile, rm, writeFile, utimes, stat } from "node:fs/promises";
|
|
10
|
+
var FileStore = class {
|
|
11
|
+
#config;
|
|
12
|
+
#age;
|
|
13
|
+
constructor(config, age) {
|
|
14
|
+
this.#config = config;
|
|
15
|
+
this.#age = age;
|
|
16
|
+
debug_default("initiating file store %O", this.#config);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Returns an absolute path to the session id file
|
|
20
|
+
*/
|
|
21
|
+
#getFilePath(sessionId) {
|
|
22
|
+
return join(this.#config.location, `${sessionId}.txt`);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Check if a file exists at a given path or not
|
|
26
|
+
*/
|
|
27
|
+
async #pathExists(path) {
|
|
28
|
+
try {
|
|
29
|
+
await access(path);
|
|
30
|
+
return true;
|
|
31
|
+
} catch {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Returns stats for a file and ignoring missing
|
|
37
|
+
* files.
|
|
38
|
+
*/
|
|
39
|
+
async #stats(path) {
|
|
40
|
+
try {
|
|
41
|
+
const stats = await stat(path);
|
|
42
|
+
return stats;
|
|
43
|
+
} catch {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Output file with contents to the given path
|
|
49
|
+
*/
|
|
50
|
+
async #outputFile(path, contents) {
|
|
51
|
+
const pathDirname = dirname(path);
|
|
52
|
+
const dirExists = await this.#pathExists(pathDirname);
|
|
53
|
+
if (!dirExists) {
|
|
54
|
+
await mkdir(pathDirname, { recursive: true });
|
|
55
|
+
}
|
|
56
|
+
await writeFile(path, contents, "utf-8");
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Reads the session data from the disk.
|
|
60
|
+
*/
|
|
61
|
+
async read(sessionId) {
|
|
62
|
+
const filePath = this.#getFilePath(sessionId);
|
|
63
|
+
debug_default("file store: reading session data %", sessionId);
|
|
64
|
+
const stats = await this.#stats(filePath);
|
|
65
|
+
if (!stats) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
const sessionWillExpireAt = stats.mtimeMs + string.milliseconds.parse(this.#age);
|
|
69
|
+
if (Date.now() > sessionWillExpireAt) {
|
|
70
|
+
debug_default("file store: expired session data %s", sessionId);
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
let contents = await readFile(filePath, "utf-8");
|
|
74
|
+
contents = contents.trim();
|
|
75
|
+
if (!contents) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
return new MessageBuilder().verify(contents, sessionId);
|
|
80
|
+
} catch {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Writes the session data to the disk as a string
|
|
86
|
+
*/
|
|
87
|
+
async write(sessionId, values) {
|
|
88
|
+
debug_default("file store: writing session data %s: %O", sessionId, values);
|
|
89
|
+
const filePath = this.#getFilePath(sessionId);
|
|
90
|
+
const message = new MessageBuilder().build(values, void 0, sessionId);
|
|
91
|
+
await this.#outputFile(filePath, message);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Removes the session file from the disk
|
|
95
|
+
*/
|
|
96
|
+
async destroy(sessionId) {
|
|
97
|
+
debug_default("file store: destroying session data %s", sessionId);
|
|
98
|
+
await rm(this.#getFilePath(sessionId), { force: true });
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Updates the session expiry by rewriting it to the
|
|
102
|
+
* persistence store
|
|
103
|
+
*/
|
|
104
|
+
async touch(sessionId) {
|
|
105
|
+
debug_default("file store: touching session data %s", sessionId);
|
|
106
|
+
await utimes(this.#getFilePath(sessionId), /* @__PURE__ */ new Date(), /* @__PURE__ */ new Date());
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
export {
|
|
110
|
+
FileStore
|
|
111
|
+
};
|
|
112
|
+
//# sourceMappingURL=file-YO7C2QWO.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/stores/file.ts"],"sourcesContent":["/**\n * @adonisjs/session\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport type { Stats } from 'node:fs'\nimport { dirname, join } from 'node:path'\nimport string from '@poppinss/utils/string'\nimport { MessageBuilder } from '@adonisjs/core/helpers'\nimport { access, mkdir, readFile, rm, writeFile, utimes, stat } from 'node:fs/promises'\n\nimport debug from '../debug.js'\nimport type { FileStoreConfig, SessionData, SessionStoreContract } from '../types.js'\n\n/**\n * File store writes the session data on the file system as. Each session\n * id gets its own file.\n */\nexport class FileStore implements SessionStoreContract {\n #config: FileStoreConfig\n #age: string | number\n\n constructor(config: FileStoreConfig, age: string | number) {\n this.#config = config\n this.#age = age\n debug('initiating file store %O', this.#config)\n }\n\n /**\n * Returns an absolute path to the session id file\n */\n #getFilePath(sessionId: string): string {\n return join(this.#config.location, `${sessionId}.txt`)\n }\n\n /**\n * Check if a file exists at a given path or not\n */\n async #pathExists(path: string) {\n try {\n await access(path)\n return true\n } catch {\n return false\n }\n }\n\n /**\n * Returns stats for a file and ignoring missing\n * files.\n */\n async #stats(path: string): Promise<Stats | null> {\n try {\n const stats = await stat(path)\n return stats\n } catch {\n return null\n }\n }\n\n /**\n * Output file with contents to the given path\n */\n async #outputFile(path: string, contents: string) {\n const pathDirname = dirname(path)\n\n const dirExists = await this.#pathExists(pathDirname)\n if (!dirExists) {\n await mkdir(pathDirname, { recursive: true })\n }\n\n await writeFile(path, contents, 'utf-8')\n }\n\n /**\n * Reads the session data from the disk.\n */\n async read(sessionId: string): Promise<SessionData | null> {\n const filePath = this.#getFilePath(sessionId)\n debug('file store: reading session data %', sessionId)\n\n /**\n * Return null when no session id file exists in first\n * place\n */\n const stats = await this.#stats(filePath)\n if (!stats) {\n return null\n }\n\n /**\n * Check if the file has been expired and return null (if expired)\n */\n const sessionWillExpireAt = stats.mtimeMs + string.milliseconds.parse(this.#age)\n if (Date.now() > sessionWillExpireAt) {\n debug('file store: expired session data %s', sessionId)\n return null\n }\n\n /**\n * Reading the file contents if the file exists\n */\n let contents = await readFile(filePath, 'utf-8')\n contents = contents.trim()\n if (!contents) {\n return null\n }\n\n /**\n * Verify contents with the session id and return them as an object. The verify\n * method can fail when the contents is not JSON>\n */\n try {\n return new MessageBuilder().verify<SessionData>(contents, sessionId)\n } catch {\n return null\n }\n }\n\n /**\n * Writes the session data to the disk as a string\n */\n async write(sessionId: string, values: SessionData): Promise<void> {\n debug('file store: writing session data %s: %O', sessionId, values)\n\n const filePath = this.#getFilePath(sessionId)\n const message = new MessageBuilder().build(values, undefined, sessionId)\n\n await this.#outputFile(filePath, message)\n }\n\n /**\n * Removes the session file from the disk\n */\n async destroy(sessionId: string): Promise<void> {\n debug('file store: destroying session data %s', sessionId)\n await rm(this.#getFilePath(sessionId), { force: true })\n }\n\n /**\n * Updates the session expiry by rewriting it to the\n * persistence store\n */\n async touch(sessionId: string): Promise<void> {\n debug('file store: touching session data %s', sessionId)\n await utimes(this.#getFilePath(sessionId), new Date(), new Date())\n }\n}\n"],"mappings":";;;;;AAUA,SAAS,SAAS,YAAY;AAC9B,OAAO,YAAY;AACnB,SAAS,sBAAsB;AAC/B,SAAS,QAAQ,OAAO,UAAU,IAAI,WAAW,QAAQ,YAAY;AAS9D,IAAM,YAAN,MAAgD;AAAA,EACrD;AAAA,EACA;AAAA,EAEA,YAAY,QAAyB,KAAsB;AACzD,SAAK,UAAU;AACf,SAAK,OAAO;AACZ,kBAAM,4BAA4B,KAAK,OAAO;AAAA,EAChD;AAAA;AAAA;AAAA;AAA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,IACT;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,MAAM,WAAmB,QAAoC;AACjE,kBAAM,2CAA2C,WAAW,MAAM;AAElE,UAAM,WAAW,KAAK,aAAa,SAAS;AAC5C,UAAM,UAAU,IAAI,eAAe,EAAE,MAAM,QAAQ,QAAW,SAAS;AAEvE,UAAM,KAAK,YAAY,UAAU,OAAO;AAAA,EAC1C;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,QAAQ,WAAkC;AAC9C,kBAAM,0CAA0C,SAAS;AACzD,UAAM,GAAG,KAAK,aAAa,SAAS,GAAG,EAAE,OAAO,KAAK,CAAC;AAAA,EACxD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,MAAM,WAAkC;AAC5C,kBAAM,wCAAwC,SAAS;AACvD,UAAM,OAAO,KAAK,aAAa,SAAS,GAAG,oBAAI,KAAK,GAAG,oBAAI,KAAK,CAAC;AAAA,EACnE;AACF;","names":[]}
|
package/build/index.d.ts
CHANGED
package/build/index.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export {
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import {
|
|
2
|
+
configure,
|
|
3
|
+
defineConfig,
|
|
4
|
+
stores
|
|
5
|
+
} from "./chunk-HIQQAMXD.js";
|
|
6
|
+
import {
|
|
7
|
+
errors_exports
|
|
8
|
+
} from "./chunk-2X5L327N.js";
|
|
9
|
+
import "./chunk-WBAYBMJJ.js";
|
|
10
|
+
export {
|
|
11
|
+
configure,
|
|
12
|
+
defineConfig,
|
|
13
|
+
errors_exports as errors,
|
|
14
|
+
stores
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|