@powfix/core-js 0.9.32 → 0.11.0

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/browser.d.ts CHANGED
@@ -1,32 +1,6 @@
1
- /** @constants */
2
- import { DURATION } from "./src/constants/DURATION";
3
- import { DISTANCE } from "./src/constants/DISTANCE";
4
- export { DISTANCE, DURATION, };
5
- /** @model */
6
- import { Coordinate, CoordinateM } from "./src/interfaces/Coordinate";
7
- import { Point2 } from "./src/interfaces/Point2";
8
- import { Point3 } from "./src/interfaces/Point3";
9
- export { Coordinate, CoordinateM, Point2, Point3, };
10
- /** @service */
11
- import { Session, SessionOptions, StorageProvider } from "./src/services/Session";
12
- export { Session, SessionOptions, StorageProvider, };
13
- /** @types */
14
- import { IntRange } from "./src/types/IntRage";
15
- export { IntRange, };
16
- /** @utils */
17
- import { between } from "./src/utils/global/between";
18
- import { sleep } from "./src/utils/global/sleep";
19
- import { StringUtils } from "./src/utils/StringUtils";
20
- import { NumberUtils } from "./src/utils/NumberUtils";
21
- import { UuidUtils } from "./src/utils/UuidUtils";
22
- import { ArrayUtils } from "./src/utils/ArrayUtils";
23
- import { parseBoolean } from "./src/utils/BooleanUtils";
24
- import { CoordinateUtils } from "./src/utils/CoordinateUtils";
25
- import { DateUtils } from "./src/utils/DateUtils";
26
- import { RandomUtils } from "./src/utils/RandomUtils";
27
- import { Validator } from './src/utils/Validator';
28
- import { JuminNumberUtils } from "./src/utils/JuminNumberUtils";
29
- import { Sequence, Sequencer, SequencerEvent, SequencerOption, SequencerStatus } from "./src/utils/Sequencer";
30
- import { base64Polyfill } from "./src/scripts/base64-polyfill";
31
- export { between, sleep, base64Polyfill, UuidUtils, ArrayUtils, RandomUtils, DateUtils, StringUtils, NumberUtils, CoordinateUtils, parseBoolean, Validator, JuminNumberUtils, Sequence, SequencerStatus, SequencerOption, SequencerEvent, Sequencer, };
1
+ export * from './src/constants';
2
+ export * from './src/interfaces';
3
+ export * from './src/scripts';
32
4
  export * from './src/services/browser';
5
+ export * from './src/types';
6
+ export * from './src/utils';
package/dist/browser.js CHANGED
@@ -14,45 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.Sequencer = exports.SequencerEvent = exports.SequencerStatus = exports.JuminNumberUtils = exports.Validator = exports.parseBoolean = exports.CoordinateUtils = exports.NumberUtils = exports.StringUtils = exports.DateUtils = exports.RandomUtils = exports.ArrayUtils = exports.UuidUtils = exports.base64Polyfill = exports.sleep = exports.between = exports.Session = exports.DURATION = exports.DISTANCE = void 0;
18
- /** @constants */
19
- const DURATION_1 = require("./src/constants/DURATION");
20
- Object.defineProperty(exports, "DURATION", { enumerable: true, get: function () { return DURATION_1.DURATION; } });
21
- const DISTANCE_1 = require("./src/constants/DISTANCE");
22
- Object.defineProperty(exports, "DISTANCE", { enumerable: true, get: function () { return DISTANCE_1.DISTANCE; } });
23
- /** @service */
24
- const Session_1 = require("./src/services/Session");
25
- Object.defineProperty(exports, "Session", { enumerable: true, get: function () { return Session_1.Session; } });
26
- /** @utils */
27
- const between_1 = require("./src/utils/global/between");
28
- Object.defineProperty(exports, "between", { enumerable: true, get: function () { return between_1.between; } });
29
- const sleep_1 = require("./src/utils/global/sleep");
30
- Object.defineProperty(exports, "sleep", { enumerable: true, get: function () { return sleep_1.sleep; } });
31
- const StringUtils_1 = require("./src/utils/StringUtils");
32
- Object.defineProperty(exports, "StringUtils", { enumerable: true, get: function () { return StringUtils_1.StringUtils; } });
33
- const NumberUtils_1 = require("./src/utils/NumberUtils");
34
- Object.defineProperty(exports, "NumberUtils", { enumerable: true, get: function () { return NumberUtils_1.NumberUtils; } });
35
- const UuidUtils_1 = require("./src/utils/UuidUtils");
36
- Object.defineProperty(exports, "UuidUtils", { enumerable: true, get: function () { return UuidUtils_1.UuidUtils; } });
37
- const ArrayUtils_1 = require("./src/utils/ArrayUtils");
38
- Object.defineProperty(exports, "ArrayUtils", { enumerable: true, get: function () { return ArrayUtils_1.ArrayUtils; } });
39
- const BooleanUtils_1 = require("./src/utils/BooleanUtils");
40
- Object.defineProperty(exports, "parseBoolean", { enumerable: true, get: function () { return BooleanUtils_1.parseBoolean; } });
41
- const CoordinateUtils_1 = require("./src/utils/CoordinateUtils");
42
- Object.defineProperty(exports, "CoordinateUtils", { enumerable: true, get: function () { return CoordinateUtils_1.CoordinateUtils; } });
43
- const DateUtils_1 = require("./src/utils/DateUtils");
44
- Object.defineProperty(exports, "DateUtils", { enumerable: true, get: function () { return DateUtils_1.DateUtils; } });
45
- const RandomUtils_1 = require("./src/utils/RandomUtils");
46
- Object.defineProperty(exports, "RandomUtils", { enumerable: true, get: function () { return RandomUtils_1.RandomUtils; } });
47
- const Validator_1 = require("./src/utils/Validator");
48
- Object.defineProperty(exports, "Validator", { enumerable: true, get: function () { return Validator_1.Validator; } });
49
- const JuminNumberUtils_1 = require("./src/utils/JuminNumberUtils");
50
- Object.defineProperty(exports, "JuminNumberUtils", { enumerable: true, get: function () { return JuminNumberUtils_1.JuminNumberUtils; } });
51
- const Sequencer_1 = require("./src/utils/Sequencer");
52
- Object.defineProperty(exports, "Sequencer", { enumerable: true, get: function () { return Sequencer_1.Sequencer; } });
53
- Object.defineProperty(exports, "SequencerEvent", { enumerable: true, get: function () { return Sequencer_1.SequencerEvent; } });
54
- Object.defineProperty(exports, "SequencerStatus", { enumerable: true, get: function () { return Sequencer_1.SequencerStatus; } });
55
- const base64_polyfill_1 = require("./src/scripts/base64-polyfill");
56
- Object.defineProperty(exports, "base64Polyfill", { enumerable: true, get: function () { return base64_polyfill_1.base64Polyfill; } });
57
- // Directories
17
+ __exportStar(require("./src/constants"), exports);
18
+ __exportStar(require("./src/interfaces"), exports);
19
+ __exportStar(require("./src/scripts"), exports);
58
20
  __exportStar(require("./src/services/browser"), exports);
21
+ __exportStar(require("./src/types"), exports);
22
+ __exportStar(require("./src/utils"), exports);
@@ -0,0 +1,3 @@
1
+ export * from './COORDINATE';
2
+ export * from './DISTANCE';
3
+ export * from './DURATION';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./COORDINATE"), exports);
18
+ __exportStar(require("./DISTANCE"), exports);
19
+ __exportStar(require("./DURATION"), exports);
@@ -0,0 +1,7 @@
1
+ export interface StorageProvider {
2
+ key?: () => string;
3
+ set: (key: string, value: string) => Promise<void> | void;
4
+ get: (key: string) => Promise<string | null> | (string | null);
5
+ remove: (key: string) => Promise<void> | void;
6
+ clear?: () => Promise<void> | void;
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ export * from './Coordinate';
2
+ export * from './Point2';
3
+ export * from './Point3';
4
+ export * from './StorageProvider';
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./Coordinate"), exports);
18
+ __exportStar(require("./Point2"), exports);
19
+ __exportStar(require("./Point3"), exports);
20
+ __exportStar(require("./StorageProvider"), exports);
@@ -0,0 +1 @@
1
+ export * from './base64-polyfill';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./base64-polyfill"), exports);
@@ -0,0 +1,27 @@
1
+ import { AxiosInstance } from "axios";
2
+ import { StorageProvider } from "@interfaces/StorageProvider";
3
+ import EventEmitter3 from 'eventemitter3';
4
+ export declare class SessionService {
5
+ private static readonly DEFAULT_AUTHORIZATION_STORAGE_KEY;
6
+ protected api: AxiosInstance;
7
+ protected storageProvider: StorageProvider;
8
+ private emitter;
9
+ readonly on: <T extends "AUTHORIZATION_CHANGED">(event: T, fn: (...args: EventEmitter3.ArgumentMap<SessionService.Event>[Extract<T, "AUTHORIZATION_CHANGED">]) => void, context?: any) => EventEmitter3<SessionService.Event, any>;
10
+ readonly off: <T extends "AUTHORIZATION_CHANGED">(event: T, fn?: ((...args: EventEmitter3.ArgumentMap<SessionService.Event>[Extract<T, "AUTHORIZATION_CHANGED">]) => void) | undefined, context?: any, once?: boolean | undefined) => EventEmitter3<SessionService.Event, any>;
11
+ protected readonly emit: <T extends "AUTHORIZATION_CHANGED">(event: T, ...args: EventEmitter3.ArgumentMap<SessionService.Event>[Extract<T, "AUTHORIZATION_CHANGED">]) => boolean;
12
+ constructor(options: SessionService.Options);
13
+ private get key();
14
+ hasAuthorization(): Promise<boolean>;
15
+ getAuthorization(): Promise<string | null>;
16
+ setAuthorization(authorization?: string | null): Promise<string | null>;
17
+ removeAuthorization(): Promise<void>;
18
+ }
19
+ export declare namespace SessionService {
20
+ interface Options {
21
+ api: AxiosInstance;
22
+ storageProvider: StorageProvider;
23
+ }
24
+ type Event = {
25
+ AUTHORIZATION_CHANGED: (authorization: string | null) => void;
26
+ };
27
+ }
@@ -12,25 +12,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.Session = void 0;
15
+ exports.SessionService = void 0;
16
16
  const jwt_decode_1 = require("jwt-decode");
17
17
  const moment_1 = __importDefault(require("moment"));
18
- const logWithTs = (...p) => {
19
- console.log(Date.now(), ...p);
20
- };
21
- class Session {
22
- // Emitter
23
- // private emitter = new EventEmitter({});
24
- // public on = this.emitter.on;
25
- // public off = this.emitter.off;
26
- // private emit = this.emitter.emit;
18
+ const eventemitter3_1 = __importDefault(require("eventemitter3"));
19
+ class SessionService {
27
20
  constructor(options) {
21
+ // Emitter
22
+ this.emitter = new eventemitter3_1.default();
23
+ this.on = this.emitter.on.bind(this.emitter);
24
+ this.off = this.emitter.off.bind(this.emitter);
25
+ this.emit = this.emitter.emit.bind(this.emitter);
28
26
  // Init service parameters
29
27
  console.log('Session initialized', Date.now(), options.api);
30
28
  this.api = options.api;
31
29
  this.storageProvider = options.storageProvider;
32
30
  }
33
- getKey() {
31
+ get key() {
34
32
  try {
35
33
  if (this.storageProvider.key) {
36
34
  return this.storageProvider.key();
@@ -39,7 +37,7 @@ class Session {
39
37
  catch (e) {
40
38
  console.error(e);
41
39
  }
42
- return Session.STORAGE_KEY.SESSION_AUTHORIZATION;
40
+ return SessionService.DEFAULT_AUTHORIZATION_STORAGE_KEY;
43
41
  }
44
42
  hasAuthorization() {
45
43
  return __awaiter(this, void 0, void 0, function* () {
@@ -48,7 +46,7 @@ class Session {
48
46
  }
49
47
  getAuthorization() {
50
48
  return __awaiter(this, void 0, void 0, function* () {
51
- return this.storageProvider.get(this.getKey());
49
+ return this.storageProvider.get(this.key);
52
50
  });
53
51
  }
54
52
  setAuthorization(authorization) {
@@ -110,9 +108,11 @@ class Session {
110
108
  })());
111
109
  })();
112
110
  // AsyncStorage 에 토큰 저장
113
- yield this.storageProvider.set(this.getKey(), nextAuthorization);
111
+ yield this.storageProvider.set(this.key, nextAuthorization);
114
112
  // API Instance header 설정
115
113
  this.api.defaults.headers.common.Authorization = `Bearer ${nextAuthorization}`;
114
+ // Emit
115
+ this.emit('AUTHORIZATION_CHANGED', nextAuthorization);
116
116
  // Return
117
117
  return nextAuthorization;
118
118
  }
@@ -127,14 +127,11 @@ class Session {
127
127
  // API Instance header 에서 토큰 제거
128
128
  delete this.api.defaults.headers.common.Authorization;
129
129
  // 스토리지에서 authorization 제거
130
- yield this.storageProvider.remove(this.getKey());
130
+ yield this.storageProvider.remove(this.key);
131
+ // Emit
132
+ this.emit('AUTHORIZATION_CHANGED', null);
131
133
  });
132
134
  }
133
135
  }
134
- exports.Session = Session;
135
- (function (Session) {
136
- let STORAGE_KEY;
137
- (function (STORAGE_KEY) {
138
- STORAGE_KEY["SESSION_AUTHORIZATION"] = "SESSION_AUTHORIZATION";
139
- })(STORAGE_KEY = Session.STORAGE_KEY || (Session.STORAGE_KEY = {}));
140
- })(Session || (exports.Session = Session = {}));
136
+ exports.SessionService = SessionService;
137
+ SessionService.DEFAULT_AUTHORIZATION_STORAGE_KEY = 'AUTHORIZATION';
@@ -1,2 +1,2 @@
1
1
  export * from './time';
2
- export * from './Session';
2
+ export * from './SessionService';
@@ -17,4 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  // Directories
18
18
  __exportStar(require("./time"), exports);
19
19
  // Files
20
- __exportStar(require("./Session"), exports);
20
+ __exportStar(require("./SessionService"), exports);
@@ -15,8 +15,8 @@ export declare class TimeService {
15
15
  private readonly emit;
16
16
  static calculateNTPResultOffset(ntpResult: TimeService.NTPResult): TimeService.Offset;
17
17
  constructor(option: TimeService.Option);
18
- getOption: () => TimeService.Option;
19
- setOption: (option: TimeService.Option) => TimeService.Option;
18
+ getOption(): TimeService.Option;
19
+ setOption(option: TimeService.Option): TimeService.Option;
20
20
  getOffset(defaultValue: TimeService.Offset): TimeService.Offset;
21
21
  getOffset(): TimeService.Offset | undefined;
22
22
  setOffset(offset: TimeService.Offset): TimeService.Offset;
@@ -30,9 +30,9 @@ export declare class TimeService {
30
30
  getTime(): number;
31
31
  private readonly fetchServerNTPResult;
32
32
  getStatus(): TimeServiceStatus;
33
- start: () => void;
34
- stop: () => void;
35
- sync: () => Promise<TimeService.Offset | null>;
33
+ start(): void;
34
+ stop(): void;
35
+ sync(): Promise<TimeService.Offset | null>;
36
36
  private syncHandler?;
37
37
  private startSync;
38
38
  private stopSync;
@@ -32,18 +32,6 @@ class TimeService {
32
32
  this.on = this.emitter.on.bind(this.emitter);
33
33
  this.off = this.emitter.off.bind(this.emitter);
34
34
  this.emit = this.emitter.emit.bind(this.emitter);
35
- this.getOption = () => {
36
- return this.option;
37
- };
38
- this.setOption = (option) => {
39
- return this.option = option;
40
- };
41
- this.setSyncedAt = (syncedAt) => {
42
- this.syncedAt = syncedAt;
43
- // Emit
44
- this.emit('SYNCED', syncedAt);
45
- return syncedAt;
46
- };
47
35
  this.fetchServerNTPResult = (t1) => __awaiter(this, void 0, void 0, function* () {
48
36
  try {
49
37
  if (typeof this.option.serverTimeProvider === 'function') {
@@ -55,91 +43,16 @@ class TimeService {
55
43
  }
56
44
  return null;
57
45
  });
58
- this.start = () => {
59
- if (this.status !== TimeServiceStatus.STOPPED) {
60
- console.warn(LOG_TAG, 'service is not stopped');
61
- return;
62
- }
63
- // Change status
64
- this.status = TimeServiceStatus.RUNNING;
65
- // Sync immediately
66
- this.sync().finally(() => { });
67
- // Start sync
68
- this.startSync();
69
- };
70
- this.stop = () => {
71
- if (this.status !== TimeServiceStatus.RUNNING) {
72
- console.warn(LOG_TAG, 'service is not running');
73
- return;
74
- }
75
- // Change status
76
- this.status = TimeServiceStatus.RUNNING;
77
- // Stop sync
78
- this.stopSync();
79
- // Reset offset
80
- this.setOffset(undefined);
81
- // Reset synced at
82
- this.setSyncedAt(undefined);
83
- };
84
- this.sync = () => __awaiter(this, void 0, void 0, function* () {
85
- try {
86
- // T1 (Client Request Time)
87
- const requestedAt = Date.now();
88
- // Fetch server time from server
89
- const serverNtpResult = yield this.fetchServerNTPResult(requestedAt);
90
- // Check is null
91
- if (serverNtpResult === null) {
92
- console.warn(LOG_TAG, 'Failed to get server time');
93
- return null;
94
- }
95
- // T2 (Server Receive Time)
96
- const { t2 } = serverNtpResult;
97
- // Check is not a number
98
- if (isNaN(Number(t2))) {
99
- // Not a Number
100
- console.error(LOG_TAG, 'invalid server time(t2), not a number', t2);
101
- return null;
102
- }
103
- // T3 (Server Transmit Time)
104
- const { t3 } = serverNtpResult;
105
- // Check is not a number
106
- if (isNaN(Number(t3))) {
107
- // Not a Number
108
- console.error(LOG_TAG, 'invalid server time(t2), not a number', t2);
109
- return null;
110
- }
111
- // T4 (Client Receive Time)
112
- const receivedAt = Date.now();
113
- const ntpResult = {
114
- t1: requestedAt,
115
- t2: t2,
116
- t3: t3,
117
- t4: receivedAt,
118
- };
119
- // Calculate offset
120
- const offset = TimeService.calculateNTPResultOffset(ntpResult);
121
- // Save calculated offset
122
- this.setOffset(offset);
123
- // Mark synced timestamp
124
- this.setSyncedAt(Date.now());
125
- }
126
- catch (e) {
127
- console.error(e);
128
- }
129
- return null;
130
- });
131
46
  this.option = option;
132
47
  if (option.autoStart) {
133
48
  this.start();
134
49
  }
135
- // Binding
136
- // this.emit = this.emit.bind(this);
137
- // this.start = this.start.bind(this);
138
- // this.stop = this.stop.bind(this);
139
- // this.sync = this.sync.bind(this);
140
- // this.getOption = this.getOption.bind(this);
141
- // this.setOption = this.setOption.bind(this);
142
- // this.setSyncedAt = this.setSyncedAt.bind(this);
50
+ }
51
+ getOption() {
52
+ return this.option;
53
+ }
54
+ setOption(option) {
55
+ return this.option = option;
143
56
  }
144
57
  getOffset(defaultValue) {
145
58
  if (this.offset !== undefined) {
@@ -156,6 +69,12 @@ class TimeService {
156
69
  getSyncedAt() {
157
70
  return this.syncedAt;
158
71
  }
72
+ setSyncedAt(syncedAt) {
73
+ this.syncedAt = syncedAt;
74
+ // Emit
75
+ this.emit('SYNCED', syncedAt);
76
+ return syncedAt;
77
+ }
159
78
  getSyncInterval() {
160
79
  if (this.option.syncInterval === undefined) {
161
80
  // If option is undefined using default value
@@ -203,6 +122,81 @@ class TimeService {
203
122
  getStatus() {
204
123
  return this.status;
205
124
  }
125
+ start() {
126
+ if (this.status !== TimeServiceStatus.STOPPED) {
127
+ console.warn(LOG_TAG, 'service is not stopped');
128
+ return;
129
+ }
130
+ // Change status
131
+ this.status = TimeServiceStatus.RUNNING;
132
+ // Sync immediately
133
+ this.sync().finally(() => { });
134
+ // Start sync
135
+ this.startSync();
136
+ }
137
+ stop() {
138
+ if (this.status !== TimeServiceStatus.RUNNING) {
139
+ console.warn(LOG_TAG, 'service is not running');
140
+ return;
141
+ }
142
+ // Change status
143
+ this.status = TimeServiceStatus.RUNNING;
144
+ // Stop sync
145
+ this.stopSync();
146
+ // Reset offset
147
+ this.setOffset(undefined);
148
+ // Reset synced at
149
+ this.setSyncedAt(undefined);
150
+ }
151
+ sync() {
152
+ return __awaiter(this, void 0, void 0, function* () {
153
+ try {
154
+ // T1 (Client Request Time)
155
+ const requestedAt = Date.now();
156
+ // Fetch server time from server
157
+ const serverNtpResult = yield this.fetchServerNTPResult(requestedAt);
158
+ // Check is null
159
+ if (serverNtpResult === null) {
160
+ console.warn(LOG_TAG, 'Failed to get server time');
161
+ return null;
162
+ }
163
+ // T2 (Server Receive Time)
164
+ const { t2 } = serverNtpResult;
165
+ // Check is not a number
166
+ if (isNaN(Number(t2))) {
167
+ // Not a Number
168
+ console.error(LOG_TAG, 'invalid server time(t2), not a number', t2);
169
+ return null;
170
+ }
171
+ // T3 (Server Transmit Time)
172
+ const { t3 } = serverNtpResult;
173
+ // Check is not a number
174
+ if (isNaN(Number(t3))) {
175
+ // Not a Number
176
+ console.error(LOG_TAG, 'invalid server time(t2), not a number', t2);
177
+ return null;
178
+ }
179
+ // T4 (Client Receive Time)
180
+ const receivedAt = Date.now();
181
+ const ntpResult = {
182
+ t1: requestedAt,
183
+ t2: t2,
184
+ t3: t3,
185
+ t4: receivedAt,
186
+ };
187
+ // Calculate offset
188
+ const offset = TimeService.calculateNTPResultOffset(ntpResult);
189
+ // Save calculated offset
190
+ this.setOffset(offset);
191
+ // Mark synced timestamp
192
+ this.setSyncedAt(Date.now());
193
+ }
194
+ catch (e) {
195
+ console.error(e);
196
+ }
197
+ return null;
198
+ });
199
+ }
206
200
  startSync() {
207
201
  if (this.syncHandler !== undefined) {
208
202
  console.warn('sync handler is not undefined', this.syncHandler);
@@ -0,0 +1 @@
1
+ export * from './IntRage';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./IntRage"), exports);
@@ -1,4 +1,4 @@
1
- import { Coordinate } from "../interfaces/Coordinate";
1
+ import { Coordinate } from "@interfaces/Coordinate";
2
2
  export declare class CoordinateUtils {
3
3
  static isValidLatitude(latitude: Coordinate['latitude'] | string): boolean;
4
4
  static isValidLongitude(longitude: Coordinate['longitude'] | string): boolean;
@@ -1,4 +1,4 @@
1
- import { Point3 } from "../interfaces/Point3";
1
+ import { Point3 } from "@interfaces/Point3";
2
2
  export declare class Point3Utils {
3
3
  static distance(p1: Point3, p2: Point3): number;
4
4
  }
@@ -0,0 +1,2 @@
1
+ export * from './between';
2
+ export * from './sleep';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./between"), exports);
18
+ __exportStar(require("./sleep"), exports);
@@ -0,0 +1,12 @@
1
+ export * from './global';
2
+ export * from './StringUtils';
3
+ export * from './NumberUtils';
4
+ export * from './UuidUtils';
5
+ export * from './ArrayUtils';
6
+ export * from './BooleanUtils';
7
+ export * from './CoordinateUtils';
8
+ export * from './DateUtils';
9
+ export * from './RandomUtils';
10
+ export * from './Validator';
11
+ export * from './JuminNumberUtils';
12
+ export * from './Sequencer';
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./global"), exports);
18
+ __exportStar(require("./StringUtils"), exports);
19
+ __exportStar(require("./NumberUtils"), exports);
20
+ __exportStar(require("./UuidUtils"), exports);
21
+ __exportStar(require("./ArrayUtils"), exports);
22
+ __exportStar(require("./BooleanUtils"), exports);
23
+ __exportStar(require("./CoordinateUtils"), exports);
24
+ __exportStar(require("./DateUtils"), exports);
25
+ __exportStar(require("./RandomUtils"), exports);
26
+ __exportStar(require("./Validator"), exports);
27
+ __exportStar(require("./JuminNumberUtils"), exports);
28
+ __exportStar(require("./Sequencer"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powfix/core-js",
3
- "version": "0.9.32",
3
+ "version": "0.11.0",
4
4
  "description": "core package",
5
5
  "author": "Kwon Kyung-Min <powfix@gmail.com>",
6
6
  "private": false,
@@ -36,6 +36,7 @@
36
36
  "@types/node": "20.9.5",
37
37
  "@types/uuid": "9.0.7",
38
38
  "axios": "1.7.9",
39
+ "babel-plugin-module-resolver": "^5.0.2",
39
40
  "moment": "^2.30.1",
40
41
  "typescript": "5.1.6"
41
42
  },
@@ -1,27 +0,0 @@
1
- import { AxiosInstance } from "axios";
2
- export interface SessionOptions {
3
- api: AxiosInstance;
4
- storageProvider: StorageProvider;
5
- }
6
- export interface StorageProvider {
7
- key?: () => string;
8
- set: (key: string, value: string) => Promise<void> | void;
9
- get: (key: string) => Promise<string | null> | (string | null);
10
- remove: (key: string) => Promise<void> | void;
11
- clear?: () => Promise<void> | void;
12
- }
13
- export declare class Session {
14
- protected api: AxiosInstance;
15
- protected storageProvider: StorageProvider;
16
- constructor(options: SessionOptions);
17
- private getKey;
18
- hasAuthorization(): Promise<boolean>;
19
- getAuthorization(): Promise<string | null>;
20
- setAuthorization(authorization?: string | null): Promise<string | null>;
21
- removeAuthorization(): Promise<void>;
22
- }
23
- export declare namespace Session {
24
- enum STORAGE_KEY {
25
- SESSION_AUTHORIZATION = "SESSION_AUTHORIZATION"
26
- }
27
- }