concordia-sdk-typescript 1.0.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/CHANGELOG.md +7 -0
- package/README.md +12 -0
- package/concordia-sdk-typescript-1.0.0.tgz +0 -0
- package/dist/client.d.ts +13 -0
- package/dist/client.js +68 -0
- package/dist/models.d.ts +63 -0
- package/dist/models.js +2 -0
- package/package.json +15 -0
- package/src/client.ts +45 -0
- package/src/models.ts +24 -0
- package/tsconfig.json +13 -0
package/CHANGELOG.md
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Concordia TypeScript SDK (minimal)
|
|
2
|
+
|
|
3
|
+
Usage:
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import ConcordiaClient from './dist/client';
|
|
7
|
+
const c = new ConcordiaClient('https://api.concordia.app/v1', 'YOUR_TOKEN');
|
|
8
|
+
await c.adminLogin({ email: 'a', password: 'b' });
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Notes:
|
|
12
|
+
- Methods are named after `operationId` values. The client uses `fetch` (node-fetch) under the hood.
|
|
Binary file
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import * as Models from './models';
|
|
4
|
+
export declare class ConcordiaClient {
|
|
5
|
+
baseUrl: string;
|
|
6
|
+
token?: string;
|
|
7
|
+
constructor(baseUrl?: string, token?: string);
|
|
8
|
+
private headers;
|
|
9
|
+
adminLogin(payload: Models.AdminLoginRequest): Promise<Models.AuthResponse>;
|
|
10
|
+
requestMagicLink(payload: Models.RequestMagicLinkRequest): Promise<any>;
|
|
11
|
+
}
|
|
12
|
+
export default ConcordiaClient;
|
|
13
|
+
export declare function verifyWebhookSignature(payload: string | Buffer, signature: string, secret: string): boolean;
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.verifyWebhookSignature = exports.ConcordiaClient = void 0;
|
|
30
|
+
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
31
|
+
const crypto = __importStar(require("crypto"));
|
|
32
|
+
class ConcordiaClient {
|
|
33
|
+
constructor(baseUrl = 'https://api.concordia.app/v1', token) {
|
|
34
|
+
this.baseUrl = baseUrl.replace(/\/$/, '');
|
|
35
|
+
this.token = token;
|
|
36
|
+
}
|
|
37
|
+
headers() {
|
|
38
|
+
const h = { 'Content-Type': 'application/json' };
|
|
39
|
+
if (this.token)
|
|
40
|
+
h.Authorization = `Bearer ${this.token}`;
|
|
41
|
+
return h;
|
|
42
|
+
}
|
|
43
|
+
// Operation methods (generated from operationId)
|
|
44
|
+
async adminLogin(payload) {
|
|
45
|
+
const res = await (0, node_fetch_1.default)(`${this.baseUrl}/api/auth/login`, { method: 'POST', headers: this.headers(), body: JSON.stringify(payload) });
|
|
46
|
+
return res.json();
|
|
47
|
+
}
|
|
48
|
+
async requestMagicLink(payload) {
|
|
49
|
+
const res = await (0, node_fetch_1.default)(`${this.baseUrl}/api/auth/request-link`, { method: 'POST', headers: this.headers(), body: JSON.stringify(payload) });
|
|
50
|
+
return res.json();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.ConcordiaClient = ConcordiaClient;
|
|
54
|
+
exports.default = ConcordiaClient;
|
|
55
|
+
// helper: verify webhook signature (HMAC-SHA256). Signature may be hex or prefixed with 'sha256='.
|
|
56
|
+
function verifyWebhookSignature(payload, signature, secret) {
|
|
57
|
+
if (!signature)
|
|
58
|
+
return false;
|
|
59
|
+
const sig = String(signature).replace(/^sha256=/i, '');
|
|
60
|
+
const h = crypto.createHmac('sha256', secret).update(Buffer.isBuffer(payload) ? payload : Buffer.from(payload)).digest('hex');
|
|
61
|
+
try {
|
|
62
|
+
return crypto.timingSafeEqual(Buffer.from(h, 'hex'), Buffer.from(sig, 'hex'));
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.verifyWebhookSignature = verifyWebhookSignature;
|
package/dist/models.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export type Address = {
|
|
2
|
+
[k: string]: any;
|
|
3
|
+
};
|
|
4
|
+
export type AdminLoginRequest = {
|
|
5
|
+
[k: string]: any;
|
|
6
|
+
};
|
|
7
|
+
export type AuthResponse = {
|
|
8
|
+
[k: string]: any;
|
|
9
|
+
};
|
|
10
|
+
export type ErrorResponse = {
|
|
11
|
+
[k: string]: any;
|
|
12
|
+
};
|
|
13
|
+
export type RequestMagicLinkRequest = {
|
|
14
|
+
[k: string]: any;
|
|
15
|
+
};
|
|
16
|
+
export type TokenResponse = {
|
|
17
|
+
[k: string]: any;
|
|
18
|
+
};
|
|
19
|
+
export type VerifyOtpRequest = {
|
|
20
|
+
[k: string]: any;
|
|
21
|
+
};
|
|
22
|
+
export type OrderItem = {
|
|
23
|
+
[k: string]: any;
|
|
24
|
+
};
|
|
25
|
+
export type OrderCreateRequest = {
|
|
26
|
+
[k: string]: any;
|
|
27
|
+
};
|
|
28
|
+
export type Order = {
|
|
29
|
+
[k: string]: any;
|
|
30
|
+
};
|
|
31
|
+
export type CourierActionRequest = {
|
|
32
|
+
[k: string]: any;
|
|
33
|
+
};
|
|
34
|
+
export type OpeningHoursResponse = {
|
|
35
|
+
[k: string]: any;
|
|
36
|
+
};
|
|
37
|
+
export type HolidayOverride = {
|
|
38
|
+
[k: string]: any;
|
|
39
|
+
};
|
|
40
|
+
export type Voucher = {
|
|
41
|
+
[k: string]: any;
|
|
42
|
+
};
|
|
43
|
+
export type Category = {
|
|
44
|
+
[k: string]: any;
|
|
45
|
+
};
|
|
46
|
+
export type MenuItem = {
|
|
47
|
+
[k: string]: any;
|
|
48
|
+
};
|
|
49
|
+
export type Variant = {
|
|
50
|
+
[k: string]: any;
|
|
51
|
+
};
|
|
52
|
+
export type VariantGroup = {
|
|
53
|
+
[k: string]: any;
|
|
54
|
+
};
|
|
55
|
+
export type OfferValidationResponse = {
|
|
56
|
+
[k: string]: any;
|
|
57
|
+
};
|
|
58
|
+
export type GenericRequest = {
|
|
59
|
+
[k: string]: any;
|
|
60
|
+
};
|
|
61
|
+
export type GenericResponse = {
|
|
62
|
+
[k: string]: any;
|
|
63
|
+
};
|
package/dist/models.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "concordia-sdk-typescript",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"clean": "rimraf dist node_modules"
|
|
10
|
+
},
|
|
11
|
+
"devDependencies": {
|
|
12
|
+
"typescript": "^4.9.0",
|
|
13
|
+
"@types/node": "^18.0.0"
|
|
14
|
+
}
|
|
15
|
+
}
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import fetch from 'node-fetch';
|
|
2
|
+
import * as Models from './models';
|
|
3
|
+
import * as crypto from 'crypto';
|
|
4
|
+
|
|
5
|
+
export class ConcordiaClient {
|
|
6
|
+
baseUrl: string;
|
|
7
|
+
token?: string;
|
|
8
|
+
constructor(baseUrl: string = 'https://api.concordia.app/v1', token?: string) {
|
|
9
|
+
this.baseUrl = baseUrl.replace(/\/$/, '');
|
|
10
|
+
this.token = token;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
private headers() {
|
|
14
|
+
const h: any = { 'Content-Type': 'application/json' };
|
|
15
|
+
if (this.token) h.Authorization = `Bearer ${this.token}`;
|
|
16
|
+
return h;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Operation methods (generated from operationId)
|
|
20
|
+
async adminLogin(payload: Models.AdminLoginRequest): Promise<Models.AuthResponse> {
|
|
21
|
+
const res = await fetch(`${this.baseUrl}/api/auth/login`, { method: 'POST', headers: this.headers(), body: JSON.stringify(payload) });
|
|
22
|
+
return res.json();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async requestMagicLink(payload: Models.RequestMagicLinkRequest): Promise<any> {
|
|
26
|
+
const res = await fetch(`${this.baseUrl}/api/auth/request-link`, { method: 'POST', headers: this.headers(), body: JSON.stringify(payload) });
|
|
27
|
+
return res.json();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// ... other methods should be added similarly. This SDK includes core examples.
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default ConcordiaClient;
|
|
34
|
+
|
|
35
|
+
// helper: verify webhook signature (HMAC-SHA256). Signature may be hex or prefixed with 'sha256='.
|
|
36
|
+
export function verifyWebhookSignature(payload: string | Buffer, signature: string, secret: string) {
|
|
37
|
+
if (!signature) return false;
|
|
38
|
+
const sig = String(signature).replace(/^sha256=/i, '');
|
|
39
|
+
const h = crypto.createHmac('sha256', secret).update(Buffer.isBuffer(payload) ? payload : Buffer.from(payload)).digest('hex');
|
|
40
|
+
try {
|
|
41
|
+
return crypto.timingSafeEqual(Buffer.from(h, 'hex'), Buffer.from(sig, 'hex'));
|
|
42
|
+
} catch (e) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
package/src/models.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Auto-generated minimal models: each schema is represented as an index signature.
|
|
2
|
+
export type Address = { [k: string]: any };
|
|
3
|
+
export type AdminLoginRequest = { [k: string]: any };
|
|
4
|
+
export type AuthResponse = { [k: string]: any };
|
|
5
|
+
export type ErrorResponse = { [k: string]: any };
|
|
6
|
+
export type RequestMagicLinkRequest = { [k: string]: any };
|
|
7
|
+
export type TokenResponse = { [k: string]: any };
|
|
8
|
+
export type VerifyOtpRequest = { [k: string]: any };
|
|
9
|
+
export type OrderItem = { [k: string]: any };
|
|
10
|
+
export type OrderCreateRequest = { [k: string]: any };
|
|
11
|
+
export type Order = { [k: string]: any };
|
|
12
|
+
export type CourierActionRequest = { [k: string]: any };
|
|
13
|
+
export type OpeningHoursResponse = { [k: string]: any };
|
|
14
|
+
export type HolidayOverride = { [k: string]: any };
|
|
15
|
+
export type Voucher = { [k: string]: any };
|
|
16
|
+
export type Category = { [k: string]: any };
|
|
17
|
+
export type MenuItem = { [k: string]: any };
|
|
18
|
+
export type Variant = { [k: string]: any };
|
|
19
|
+
export type VariantGroup = { [k: string]: any };
|
|
20
|
+
export type OfferValidationResponse = { [k: string]: any };
|
|
21
|
+
|
|
22
|
+
// Generic types
|
|
23
|
+
export type GenericRequest = { [k: string]: any };
|
|
24
|
+
export type GenericResponse = { [k: string]: any };
|
package/tsconfig.json
ADDED