Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ dist/

# File with yarn errors
yarn-error.log

tests.txt
16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug App",
"runtimeExecutable": "yarn",
"runtimeArgs": ["app:dev"],
"outputCapture": "std"
}
]
}
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ Para facilitar o desenvolvimento e manter o padrão de código proposto no proje

### Requerimentos

- Yarn (yarn config set workspaces-experimental true)

- [Node.JS >= v.14.6.0](https://nodejs.org/en/)

### Extensões do vscode
Expand Down
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ Uma **Client API** para o IFood que permite **gerenciar multiplas** sessões no

**Em um futuro, posso pensar em separar em SDK, para facilitar o uso.**

## Acesso rápido

Temos uma instância da aplicação rodando em um servidor. [Clique aqui]() e você poderá testar. =)

## Guias

Essa sessão contém diversos guias para a utilização da API.
Expand Down
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"doc": "docs"
},
"scripts": {
"prepare": "husky install"
"prepare": "husky install",
"app:dev": "yarn workspace @open-ifood/api dev"
},
"repository": {
"type": "git",
Expand All @@ -28,26 +29,29 @@
"homepage": "https://github.com/leoelias023/client-ifoodapi#readme",
"devDependencies": {
"@types/express": "^4.17.11",
"@types/jest": "^29.5.1",
"@types/node": "^14.14.32",
"@types/node-cron": "^2.0.3",
"@types/pino": "^6.3.6",
"husky": "^5.1.3",
"jest": "^29.5.0",
"pino-pretty": "^4.7.1",
"prettier": "2.2.1",
"ts-jest": "^29.1.0",
"ts-node-dev": "^1.1.6",
"typescript": "^4.2.3"
"typescript": "^5.0.3"
},
"engines": {
"node": ">= v14.6.0"
},
"dependencies": {
"@open-ifood/sdk": "1.0.0",
"@open-ifood/sdk": "1.0.2",
"@types/uuid": "^8.3.0",
"axios": "^0.21.1",
"dotenv": "^8.2.0",
"dotenv-expand": "^5.1.0",
"express": "^4.17.1",
"mongoose": "^5.11.13",
"mongoose": "^7.0.3",
"node-cron": "^3.0.0",
"pino": "^6.11.2",
"uuid": "^8.3.2"
Expand Down
14 changes: 14 additions & 0 deletions packages/faster-sdk/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "@open-ifood/faster-sdk",
"version": "1.0.0",
"main": "dist/index.js",
"scripts": {
"start": "yarn tsc && node dist/index.js",
"build": "yarn tsc",
"postinstall": "yarn tsc"
},
"license": "MIT",
"dependencies": {
"tsc": "^2.0.3"
}
}
37 changes: 37 additions & 0 deletions packages/faster-sdk/src/client/faster-client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import axios from 'axios';
import { CreateDeviceSession, FasterClientBuilder, SendEvents } from '../types';

export const create: FasterClientBuilder = config => {
const api = axios.create({
baseURL: config.url,
headers: {
'x-fstr-application-key': config.applicationKey,
},
validateStatus: () => true,
});

const createDeviceSession: CreateDeviceSession = async request => {
const { status, data } = await api.post('/v1/device', request);

return {
statusCode: status,
success: status === 201,
description: data?.description,
};
};

const dispatchEvent: SendEvents = async payload => {
const { status, data } = await api.post('/v1/event', payload);

return {
statusCode: status,
success: status === 200,
description: data?.description,
};
};

return {
createDeviceSession,
dispatchEvent,
};
};
1 change: 1 addition & 0 deletions packages/faster-sdk/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './client/faster-client';
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface FasterClientConfig {
url: string;
applicationKey: string;
}
100 changes: 100 additions & 0 deletions packages/faster-sdk/src/types/client/faster-client.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { FasterClientConfig } from './faster-client-config.interface';

export interface FasterClient {
createDeviceSession: CreateDeviceSession;
dispatchEvent: SendEvents;
}

export interface FasterClientBuilder {
(config: FasterClientConfig): FasterClient;
}

interface CreateDeviceRequest {
/** Random UUID V4 */
deviceId: string;

/** Random UUID V4 */
sessionId: string;
trackInstall: boolean;

/** WEB, ANDROID, IOS... */
platform: string;

/** Operational System */
system: string;

/** Operational System version */
systemVersion: string;

/** Version of running app (9.89.2) */
appVersion: string;

/** Version of SDK (By default 3.2.9) */
sdkVersion: string;

vendorId?: null;
advertisingId?: null;
pushToken?: null;
cloudId?: null;
carrierId?: null;

/** GMT-0300 */
timezone: string;

/** ISO language codes (pt-BR, en-US) */
language: string;

deviceProperties: DeviceProperties;

/** YYYY-mm-ddTHH:mm:ss.sssXZ */
localTimestamp: string;

ntpLocalTimestamp?: null;

/** YYYY-mm-ddTHH:mm:ss.sssXZ */
sentAt: string;

ntpsentAt?: null;
}

interface DeviceProperties {
browserName: string;
browserVersion: string;
}

interface Response {
success: boolean;
statusCode: number;
description: string;
}

export interface CreateDeviceSession {
(request: CreateDeviceRequest): Promise<Response>;
}

export interface SendEvents {
(eventPayload: EventPayload): Promise<Response>;
}

interface EventPayload {
deviceId: string;
sessionId: string;
events: Array<Event>;
sentAt: string;
ntpsentAt: string;
}

interface Event {
eventId: string;
eventType: string;
eventTypeRevision: number;
dimensions: Dimensions;
localTimestamp: string;
ntpLocalTimestamp: string;
}

interface Dimensions {
authType: string;
accessPoint: string;
authTypeValue: string;
}
2 changes: 2 additions & 0 deletions packages/faster-sdk/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './client/faster-client-config.interface';
export * from './client/faster-client.interface';
24 changes: 24 additions & 0 deletions packages/faster-sdk/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"target": "es2016",
"module": "commonjs",
"rootDir": "./src",
"resolveJsonModule": true,
"allowJs": false,
"outDir": "./dist",
"newLine": "lf",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"alwaysStrict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"allowUnreachableCode": false,
"skipLibCheck": true,
"declaration": true,
"sourceMap": true
}
}
7 changes: 7 additions & 0 deletions packages/sdk/jest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"transform": {
"^.+\\.ts?$": "ts-jest"
},
"setupFiles": ["dotenv/config"],
"testPathIgnorePatterns": ["<rootDir>/src/__test__/setup.test.ts", "/dist/"]
}
7 changes: 5 additions & 2 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
"scripts": {
"start": "yarn tsc && node dist/index.js",
"build": "yarn tsc",
"postinstall": "yarn tsc"
"postinstall": "yarn tsc",
"test": "jest --config=jest.json"
},
"license": "MIT",
"dependencies": {
"tsc": "^2.0.3"
"moment": "^2.29.4",
"tsc": "^2.0.3",
"uuid": "^9.0.0"
}
}
19 changes: 19 additions & 0 deletions packages/sdk/src/__test__/service/auth.service.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { assertNotEmpty } from '../../service/auth.service';

test('adds 1 + 2 to equal 3', () => {
expect(1 + 2).toBe(3);
});

test('assert not empty with empty value', () => {
const messageToBethrow = 'message_exception';

expect(() => {
assertNotEmpty(messageToBethrow, '');
}).toThrow(messageToBethrow);
});

test('assert not empty with any value', () => {
const message = 'any message here';

expect(assertNotEmpty('value', message)).toBe(message);
});
8 changes: 8 additions & 0 deletions packages/sdk/src/__test__/setup.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const dotenv = require('dotenv');
const expanded = require('dotenv-expand');

const myenv = dotenv.config({
path: 'src/.env.test',
});

expanded(myenv);
Loading