skapi-js 1.0.58 → 1.0.60
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/dist/skapi.js +1 -1
- package/dist/skapi.js.map +1 -1
- package/dist/skapi.module.js +1 -1
- package/dist/skapi.module.js.map +1 -1
- package/js/main/skapi.js +1 -1
- package/js/methods/subscription.d.ts +2 -2
- package/js/methods/subscription.js +16 -17
- package/js/methods/user.d.ts +0 -3
- package/package.json +2 -3
package/js/main/skapi.js
CHANGED
|
@@ -33,7 +33,7 @@ export declare function unsubscribeNewsletter(params: {
|
|
|
33
33
|
export declare function getNewsletters(params?: {
|
|
34
34
|
searchFor: 'message_id' | 'timestamp' | 'read' | 'complaint' | 'subject';
|
|
35
35
|
value: string | number;
|
|
36
|
-
range: string | number;
|
|
37
|
-
condition?: '>' | '>=' | '=' | '<' | '<=' | 'gt' | 'gte' | 'eq' | 'lt' | 'lte';
|
|
38
36
|
group: 'public' | 'authorized' | number;
|
|
37
|
+
range?: string | number;
|
|
38
|
+
condition?: '>' | '>=' | '=' | '<' | '<=' | 'gt' | 'gte' | 'eq' | 'lt' | 'lte';
|
|
39
39
|
}, fetchOptions?: FetchOptions): Promise<Newsletters>;
|
|
@@ -131,21 +131,19 @@ export async function getNewsletters(params, fetchOptions) {
|
|
|
131
131
|
'subject': 'string'
|
|
132
132
|
};
|
|
133
133
|
if (!params) {
|
|
134
|
-
|
|
135
|
-
fetchOptions = {};
|
|
136
|
-
}
|
|
137
|
-
fetchOptions.ascending = false;
|
|
134
|
+
fetchOptions = Object.assign({ ascending: false }, (fetchOptions || {}));
|
|
138
135
|
}
|
|
139
|
-
|
|
136
|
+
params = params || {
|
|
140
137
|
searchFor: 'timestamp',
|
|
141
|
-
value:
|
|
142
|
-
condition: '
|
|
138
|
+
value: Date.now(),
|
|
139
|
+
condition: '<',
|
|
140
|
+
group: 'public'
|
|
143
141
|
};
|
|
144
|
-
params = validator.Params(
|
|
142
|
+
params = validator.Params(params, {
|
|
145
143
|
searchFor: ['message_id', 'timestamp', 'read', 'complaint', 'group', 'subject'],
|
|
146
144
|
value: (v) => {
|
|
147
|
-
if (typeof v !== searchType[
|
|
148
|
-
throw new SkapiError(`"value" type does not match the type of "${
|
|
145
|
+
if (typeof v !== searchType[params.searchFor]) {
|
|
146
|
+
throw new SkapiError(`"value" type does not match the type of "${params.searchFor}" index.`, { code: 'INVALID_PARAMETER' });
|
|
149
147
|
}
|
|
150
148
|
else if (typeof v === 'string' && !v) {
|
|
151
149
|
throw new SkapiError('"value" should not be empty string.', { code: 'INVALID_PARAMETER' });
|
|
@@ -153,28 +151,29 @@ export async function getNewsletters(params, fetchOptions) {
|
|
|
153
151
|
return v;
|
|
154
152
|
},
|
|
155
153
|
range: (v) => {
|
|
156
|
-
if (!
|
|
154
|
+
if (!params.hasOwnProperty('value') || typeof v !== typeof params.value) {
|
|
157
155
|
throw new SkapiError('"range" should match type of "value".', { code: 'INVALID_PARAMETER' });
|
|
158
156
|
}
|
|
159
157
|
return v;
|
|
160
158
|
},
|
|
161
159
|
condition: ['>', '>=', '=', '<', '<=', 'gt', 'gte', 'eq', 'lt', 'lte', () => '='],
|
|
162
160
|
group: (x) => {
|
|
163
|
-
if (!this.session) {
|
|
164
|
-
throw new SkapiError('User should be logged in.', { code: 'INVALID_REQUEST' });
|
|
165
|
-
}
|
|
166
161
|
if (x === 'public') {
|
|
167
162
|
return 0;
|
|
168
163
|
}
|
|
169
|
-
|
|
164
|
+
if (!this.session) {
|
|
165
|
+
throw new SkapiError('User should be logged in.', { code: 'INVALID_REQUEST' });
|
|
166
|
+
}
|
|
167
|
+
if (x === 'authorized') {
|
|
170
168
|
return 1;
|
|
171
169
|
}
|
|
172
|
-
|
|
170
|
+
if (typeof x === 'number') {
|
|
173
171
|
if (!isAdmin && x > parseInt(this.session.idToken.payload.access_group)) {
|
|
174
172
|
throw new SkapiError('User has no access.', { code: 'INVALID_REQUEST' });
|
|
175
173
|
}
|
|
174
|
+
return x;
|
|
176
175
|
}
|
|
177
|
-
|
|
176
|
+
throw new SkapiError('"group" should be type: number | "public" | "authorized".', { code: 'INVALID_PARAMETER' });
|
|
178
177
|
}
|
|
179
178
|
}, ['searchFor', 'value', 'group']);
|
|
180
179
|
let mails = await request.bind(this)(params.group === 0 ? 'get-public-newsletters' : 'get-newsletters', params, Object.assign({ method: 'get', auth: params.group !== 0 }, { fetchOptions }));
|
package/js/methods/user.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "skapi-js",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.60",
|
|
4
4
|
"description": "Skapi: Backend API Library for HTML frontend.",
|
|
5
5
|
"main": "./dist/skapi.module.js",
|
|
6
6
|
"types": "./js/Main.d.ts",
|
|
@@ -9,8 +9,7 @@
|
|
|
9
9
|
"dist/"
|
|
10
10
|
],
|
|
11
11
|
"scripts": {
|
|
12
|
-
"build": "npx tsc --project tsconfig.json; npx webpack --config webpack.config.js"
|
|
13
|
-
"dev": "(cd playground; node server.js)"
|
|
12
|
+
"build": "npx tsc --project tsconfig.json; npx webpack --config webpack.config.js;"
|
|
14
13
|
},
|
|
15
14
|
"repository": {
|
|
16
15
|
"type": "git",
|