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/js/main/skapi.js CHANGED
@@ -24,7 +24,7 @@ export default class Skapi {
24
24
  set user(value) {
25
25
  }
26
26
  constructor(service, owner, options, __etc) {
27
- this.version = '1.0.58';
27
+ this.version = '1.0.60';
28
28
  this.session = null;
29
29
  this.connection = null;
30
30
  this.host = 'skapi';
@@ -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
- if (!fetchOptions) {
135
- fetchOptions = {};
136
- }
137
- fetchOptions.ascending = false;
134
+ fetchOptions = Object.assign({ ascending: false }, (fetchOptions || {}));
138
135
  }
139
- let _params = params || {
136
+ params = params || {
140
137
  searchFor: 'timestamp',
141
- value: 0,
142
- condition: '>'
138
+ value: Date.now(),
139
+ condition: '<',
140
+ group: 'public'
143
141
  };
144
- params = validator.Params(_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[_params.searchFor]) {
148
- throw new SkapiError(`"value" type does not match the type of "${_params.searchFor}" index.`, { code: 'INVALID_PARAMETER' });
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 (!_params.hasOwnProperty('value') || typeof v !== typeof _params.value) {
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
- else if (x === 'authorized') {
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
- else if (typeof x === 'number') {
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
- return x;
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 }));
@@ -81,9 +81,6 @@ export declare function registerTicket(params: {
81
81
  data?: Record<string, any>;
82
82
  params?: Record<string, any>;
83
83
  };
84
- update_service?: {
85
- [key: string]: any;
86
- };
87
84
  };
88
85
  description: string;
89
86
  count?: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "skapi-js",
3
- "version": "1.0.58",
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",