@geins/core 0.3.0-canary
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/.turbo/turbo-build.log +7 -0
- package/CHANGELOG.md +13 -0
- package/README.md +1 -0
- package/__tests__/Channel.test.ts +34 -0
- package/__tests__/EventService.test.ts +32 -0
- package/__tests__/GeinsCore.test.ts +69 -0
- package/__tests__/Graphql.test.ts +43 -0
- package/dist/api-client/endpointClient.d.ts +8 -0
- package/dist/api-client/index.d.ts +4 -0
- package/dist/api-client/managementApiClient.d.ts +10 -0
- package/dist/api-client/merchantApiClient.d.ts +46 -0
- package/dist/base/baseApiService.d.ts +14 -0
- package/dist/base/basePackage.d.ts +12 -0
- package/dist/base/baseStore.d.ts +14 -0
- package/dist/base/index.d.ts +3 -0
- package/dist/constants/cookies.d.ts +11 -0
- package/dist/constants/endpoints.d.ts +14 -0
- package/dist/constants/headerNames.d.ts +3 -0
- package/dist/constants/index.d.ts +3 -0
- package/dist/geinsCore.d.ts +88 -0
- package/dist/graphql/index.d.ts +1 -0
- package/dist/graphql/queries.d.ts +5 -0
- package/dist/index.cjs +21783 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.esm.js +21749 -0
- package/dist/logic/channel.d.ts +17 -0
- package/dist/logic/index.d.ts +1 -0
- package/dist/parsers/channelParser.d.ts +8 -0
- package/dist/services/channelService.d.ts +8 -0
- package/dist/services/channelsService.d.ts +8 -0
- package/dist/services/cookieService.d.ts +88 -0
- package/dist/services/eventService.d.ts +51 -0
- package/dist/services/graphQLService.d.ts +23 -0
- package/dist/services/index.d.ts +7 -0
- package/dist/services/logService.d.ts +19 -0
- package/dist/services/routingService.d.ts +74 -0
- package/dist/stores/channelStore.d.ts +11 -0
- package/dist/stores/index.d.ts +2 -0
- package/dist/stores/routingStore.d.ts +32 -0
- package/dist/utils/helpers.d.ts +21 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/simpleCache.d.ts +9 -0
- package/eslint.config.js +3 -0
- package/jest.config.js +8 -0
- package/package.json +32 -0
- package/rollup.config.js +26 -0
- package/src/api-client/endpointClient.ts +52 -0
- package/src/api-client/index.ts +4 -0
- package/src/api-client/managementApiClient.ts +41 -0
- package/src/api-client/merchantApiClient.ts +153 -0
- package/src/base/baseApiService.ts +96 -0
- package/src/base/basePackage.ts +39 -0
- package/src/base/baseStore.ts +21 -0
- package/src/base/index.ts +3 -0
- package/src/constants/cookies.ts +12 -0
- package/src/constants/endpoints.ts +27 -0
- package/src/constants/headerNames.ts +3 -0
- package/src/constants/index.ts +3 -0
- package/src/geinsCore.ts +214 -0
- package/src/graphql/channel.gql +16 -0
- package/src/graphql/channels.gql +16 -0
- package/src/graphql/fragments/channelFields.gql +8 -0
- package/src/graphql/fragments/countryFields.gql +4 -0
- package/src/graphql/fragments/currencyFields.gql +4 -0
- package/src/graphql/fragments/languageFields.gql +5 -0
- package/src/graphql/fragments/marketFields.gql +19 -0
- package/src/graphql/graphql.d.ts +4 -0
- package/src/graphql/index.ts +1 -0
- package/src/graphql/queries.ts +9 -0
- package/src/index.ts +10 -0
- package/src/logic/channel.ts +102 -0
- package/src/logic/index.ts +1 -0
- package/src/parsers/channelParser.ts +91 -0
- package/src/services/channelService.ts +33 -0
- package/src/services/channelsService.ts +35 -0
- package/src/services/cookieService.ts +168 -0
- package/src/services/eventService.ts +89 -0
- package/src/services/graphQLService.ts +55 -0
- package/src/services/index.ts +7 -0
- package/src/services/logService.ts +434 -0
- package/src/services/routingService.ts +196 -0
- package/src/stores/channelStore.ts +34 -0
- package/src/stores/index.ts +2 -0
- package/src/stores/routingStore.ts +56 -0
- package/src/utils/helpers.ts +39 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/simpleCache.ts +27 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import NodeCache from 'node-cache';
|
|
2
|
+
import { IStore } from '../base';
|
|
3
|
+
|
|
4
|
+
const TTL_SECONDS = 60 * 60 * 24; // 24 hours
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* RoutingStore implements the IStore interface using NodeCache for in-memory caching.
|
|
8
|
+
*/
|
|
9
|
+
export class RoutingStore implements IStore {
|
|
10
|
+
private store: NodeCache;
|
|
11
|
+
|
|
12
|
+
constructor() {
|
|
13
|
+
this.store = new NodeCache({
|
|
14
|
+
stdTTL: TTL_SECONDS,
|
|
15
|
+
checkperiod: TTL_SECONDS * 0.2,
|
|
16
|
+
useClones: false,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Sets a key-value pair in the cache.
|
|
22
|
+
* @param key - The key under which the value is stored.
|
|
23
|
+
* @param value - The value to store.
|
|
24
|
+
* @returns A promise that resolves when the operation is complete.
|
|
25
|
+
*/
|
|
26
|
+
public async setKey(key: string, value: string): Promise<void> {
|
|
27
|
+
this.store.set(key, value);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Retrieves a value from the cache by its key.
|
|
32
|
+
* @param key - The key of the value to retrieve.
|
|
33
|
+
* @returns A promise that resolves to the value or null if not found.
|
|
34
|
+
*/
|
|
35
|
+
public async getKey(key: string): Promise<string | null> {
|
|
36
|
+
const value = this.store.get<string>(key);
|
|
37
|
+
return value !== undefined ? value : null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Retrieves all keys from the cache.
|
|
42
|
+
* @returns A promise that resolves to an array of all keys.
|
|
43
|
+
*/
|
|
44
|
+
public async getKeys(): Promise<string[]> {
|
|
45
|
+
return this.store.keys();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Deletes a key-value pair from the cache.
|
|
50
|
+
* @param key - The key of the value to delete.
|
|
51
|
+
* @returns A promise that resolves when the operation is complete.
|
|
52
|
+
*/
|
|
53
|
+
public async deleteKey(key: string): Promise<void> {
|
|
54
|
+
this.store.del(key);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ENDPOINTS } from '../constants';
|
|
2
|
+
import type { Environment, GeinsEndpoints } from '@geins/types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Get context of the runtime.
|
|
6
|
+
* @returns If the context is server.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export function isServerContext() {
|
|
10
|
+
return typeof window === 'undefined';
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Builds the endpoints for the Geins API.
|
|
14
|
+
* @param apiKey - The API key.
|
|
15
|
+
* @param accountName - The account name.
|
|
16
|
+
* @param environment - The environment.
|
|
17
|
+
* @returns The endpoints.
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const apiKey
|
|
21
|
+
* const accountName
|
|
22
|
+
* const environment
|
|
23
|
+
* const endpoints = buildEndpoints(apiKey, accountName, environment);
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export function buildEndpoints(
|
|
27
|
+
apiKey: string,
|
|
28
|
+
accountName: string,
|
|
29
|
+
environment: Environment = 'prod',
|
|
30
|
+
): GeinsEndpoints {
|
|
31
|
+
return {
|
|
32
|
+
main: ENDPOINTS.main,
|
|
33
|
+
auth: ENDPOINTS.auth
|
|
34
|
+
.replace('{ACCOUNT}', accountName)
|
|
35
|
+
.replace('{ENV}', environment),
|
|
36
|
+
authSign: ENDPOINTS.auth_sign.replace('{API-KEY}', apiKey),
|
|
37
|
+
image: ENDPOINTS.image.replace('{ACCOUNT}', accountName),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export class SimpleCache<T> {
|
|
2
|
+
private cache: Map<string, { value: T; expiry: number }> = new Map();
|
|
3
|
+
|
|
4
|
+
constructor(private defaultTTL: number = 5 * 60 * 1000) {} // 5 minutes default TTL
|
|
5
|
+
|
|
6
|
+
set(key: string, value: T, ttl: number = this.defaultTTL): void {
|
|
7
|
+
const expiry = Date.now() + ttl;
|
|
8
|
+
this.cache.set(key, { value, expiry });
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
get(key: string): T | undefined {
|
|
12
|
+
const item = this.cache.get(key);
|
|
13
|
+
if (item && item.expiry > Date.now()) {
|
|
14
|
+
return item.value;
|
|
15
|
+
}
|
|
16
|
+
this.cache.delete(key);
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
delete(key: string): void {
|
|
21
|
+
this.cache.delete(key);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
clear(): void {
|
|
25
|
+
this.cache.clear();
|
|
26
|
+
}
|
|
27
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES5",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "node",
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"outDir": "./dist",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true,
|
|
12
|
+
"resolveJsonModule": true,
|
|
13
|
+
"allowSyntheticDefaultImports": true,
|
|
14
|
+
},
|
|
15
|
+
"include": [
|
|
16
|
+
"src/**/*.ts",
|
|
17
|
+
"src/**/*.gql"
|
|
18
|
+
]
|
|
19
|
+
}
|