@engage_so/core 2.2.0 → 2.2.2
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/error.d.ts +4 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js +10 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +346 -0
- package/package.json +5 -1
- package/.github/workflows/test.yml +0 -75
- package/jest.config.js +0 -7
- package/src/error.ts +0 -6
- package/src/index.ts +0 -365
- package/tests/index.test.ts +0 -231
- package/tests/oop.test.ts +0 -41
- package/tests/overloads.test.ts +0 -133
- package/tests/overriding.test.ts +0 -121
- package/tsconfig.json +0 -17
package/dist/error.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA,qBAAa,WAAY,SAAQ,KAAK;gBACvB,OAAO,EAAE,MAAM;CAI7B"}
|
package/dist/error.js
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.EngageError = void 0;
|
4
|
+
class EngageError extends Error {
|
5
|
+
constructor(message) {
|
6
|
+
super(message);
|
7
|
+
this.name = 'EngageError';
|
8
|
+
}
|
9
|
+
}
|
10
|
+
exports.EngageError = EngageError;
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
export interface Key {
|
2
|
+
key?: string;
|
3
|
+
secret?: string;
|
4
|
+
}
|
5
|
+
export interface EventParameter {
|
6
|
+
event: string;
|
7
|
+
value?: string | number | Date | boolean;
|
8
|
+
properties?: {
|
9
|
+
[key: string]: string | number | Date | boolean;
|
10
|
+
};
|
11
|
+
timestamp?: string | number | Date;
|
12
|
+
}
|
13
|
+
export interface UserAttrParams {
|
14
|
+
[key: string]: string | number | Date | boolean;
|
15
|
+
}
|
16
|
+
export type UserIdentifyParams = UserAttrParams & {
|
17
|
+
id: string;
|
18
|
+
};
|
19
|
+
type Methods = 'POST' | 'PUT' | 'DELETE' | 'GET';
|
20
|
+
export declare function request(url: string, params?: Record<string, any> | null | undefined, method?: Methods): Promise<object>;
|
21
|
+
export declare function init(key: Key | string): void;
|
22
|
+
export declare function identify(user: UserIdentifyParams): Promise<object>;
|
23
|
+
export declare function addAttribute(attributes: UserAttrParams): Promise<object>;
|
24
|
+
export declare function addAttribute(uid: string, attributes: UserAttrParams): Promise<object>;
|
25
|
+
export declare function track(data: EventParameter): Promise<object>;
|
26
|
+
export declare function track(uid: string, data: EventParameter): Promise<object>;
|
27
|
+
export declare function merge(destinationUid: string): Promise<object>;
|
28
|
+
export declare function merge(sourceUid: string, destinationUid: string): Promise<object>;
|
29
|
+
export declare function addToAccount(uid: string, accountId: string, role?: string): Promise<object>;
|
30
|
+
export declare function removeFromAccount(accountId: string): Promise<object>;
|
31
|
+
export declare function removeFromAccount(uid: string, accountId: string): Promise<object>;
|
32
|
+
export declare function changeAccountRole(accountId: string, role: string): Promise<object>;
|
33
|
+
export declare function changeAccountRole(uid: string, accountId: string, role: string): Promise<object>;
|
34
|
+
export declare function convertToCustomer(): Promise<object>;
|
35
|
+
export declare function convertToAccount(): Promise<object>;
|
36
|
+
declare const EngageSDK: {
|
37
|
+
init: typeof init;
|
38
|
+
identify: typeof identify;
|
39
|
+
addAttribute: typeof addAttribute;
|
40
|
+
track: typeof track;
|
41
|
+
merge: typeof merge;
|
42
|
+
addToAccount: typeof addToAccount;
|
43
|
+
removeFromAccount: typeof removeFromAccount;
|
44
|
+
changeAccountRole: typeof changeAccountRole;
|
45
|
+
convertToCustomer: typeof convertToCustomer;
|
46
|
+
convertToAccount: typeof convertToAccount;
|
47
|
+
request: typeof request;
|
48
|
+
};
|
49
|
+
export default EngageSDK;
|
50
|
+
//# sourceMappingURL=index.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"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
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
|
+
};
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
+
exports.convertToAccount = exports.convertToCustomer = exports.changeAccountRole = exports.removeFromAccount = exports.addToAccount = exports.merge = exports.track = exports.addAttribute = exports.identify = exports.init = exports.request = void 0;
|
16
|
+
const buffer_1 = require("buffer");
|
17
|
+
const cross_fetch_1 = __importDefault(require("cross-fetch"));
|
18
|
+
const error_1 = require("./error");
|
19
|
+
if (typeof btoa === 'undefined') {
|
20
|
+
global.btoa = function (str) {
|
21
|
+
return buffer_1.Buffer.from(str).toString('base64');
|
22
|
+
};
|
23
|
+
}
|
24
|
+
// type UserIdentifyParams = {
|
25
|
+
// id: string
|
26
|
+
// [key: string]: string | number | Date | boolean
|
27
|
+
// }
|
28
|
+
// type UserAttrParams = Omit<UserIdentifyParams, 'id'>
|
29
|
+
// const rootURL = 'https://api.engage.so/v1'
|
30
|
+
let auth = '';
|
31
|
+
let currentUserId = '';
|
32
|
+
const notMeta = ['created_at', 'is_account', 'number', 'device_token', 'device_platform', 'email', 'first_name', 'last_name', 'tz', 'app_version', 'app_build', 'app_last_active'];
|
33
|
+
const apiRoot = 'https://api.engage.so/v1';
|
34
|
+
function isNull(v) {
|
35
|
+
return (v === null || v === undefined);
|
36
|
+
}
|
37
|
+
function isNullString(v) {
|
38
|
+
return (v === null || v === undefined || v === '');
|
39
|
+
}
|
40
|
+
function resolveUserId(uid) {
|
41
|
+
if (!isNullString(uid)) {
|
42
|
+
return uid;
|
43
|
+
}
|
44
|
+
if (isNullString(currentUserId)) {
|
45
|
+
throw new error_1.EngageError('User ID missing. Call identify() first or provide a uid parameter.');
|
46
|
+
}
|
47
|
+
return currentUserId;
|
48
|
+
}
|
49
|
+
function _request(url, params, method) {
|
50
|
+
return __awaiter(this, void 0, void 0, function* () {
|
51
|
+
try {
|
52
|
+
const o = {
|
53
|
+
method,
|
54
|
+
headers: {
|
55
|
+
'Content-Type': 'application/json;charset=utf-8',
|
56
|
+
Authorization: `Basic ${auth}`
|
57
|
+
}
|
58
|
+
// throwHttpErrors: false,
|
59
|
+
// prefixUrl: rootURL
|
60
|
+
};
|
61
|
+
if (!isNull(params)) {
|
62
|
+
o.body = JSON.stringify(params);
|
63
|
+
}
|
64
|
+
// const response = await ky(url, o)
|
65
|
+
const response = yield (0, cross_fetch_1.default)(`${apiRoot}${url}`, o);
|
66
|
+
const body = yield response.json();
|
67
|
+
let error = 'API connection error';
|
68
|
+
if (!response.ok) {
|
69
|
+
if (typeof (body === null || body === void 0 ? void 0 : body.error) === 'string') {
|
70
|
+
error = body.error;
|
71
|
+
}
|
72
|
+
return { error };
|
73
|
+
}
|
74
|
+
return body;
|
75
|
+
}
|
76
|
+
catch (e) {
|
77
|
+
return { error: 'API connection error' };
|
78
|
+
}
|
79
|
+
});
|
80
|
+
}
|
81
|
+
// Alias of _request method
|
82
|
+
// Same with _request for now but can later have modifications
|
83
|
+
function request(url, params, method = 'GET') {
|
84
|
+
return __awaiter(this, void 0, void 0, function* () {
|
85
|
+
return yield _request(url, params, method);
|
86
|
+
});
|
87
|
+
}
|
88
|
+
exports.request = request;
|
89
|
+
function init(key) {
|
90
|
+
var _a, _b;
|
91
|
+
if (isNull(key)) {
|
92
|
+
throw new error_1.EngageError('You need to pass in your API key(s).');
|
93
|
+
}
|
94
|
+
// Clear any stored user ID when reinitializing
|
95
|
+
currentUserId = '';
|
96
|
+
const options = {
|
97
|
+
key: '',
|
98
|
+
secret: ''
|
99
|
+
};
|
100
|
+
if (typeof key === 'string') {
|
101
|
+
if (key === '') {
|
102
|
+
throw new error_1.EngageError('`key` is empty.');
|
103
|
+
}
|
104
|
+
options.key = key;
|
105
|
+
}
|
106
|
+
else {
|
107
|
+
if (isNullString(key.key)) {
|
108
|
+
throw new error_1.EngageError('`key` missing in object.');
|
109
|
+
}
|
110
|
+
options.key = key.key;
|
111
|
+
if (!isNullString(key.secret)) {
|
112
|
+
options.secret = key.secret;
|
113
|
+
}
|
114
|
+
}
|
115
|
+
// Set auth
|
116
|
+
auth = btoa(`${(_a = options.key) !== null && _a !== void 0 ? _a : ''}:${(_b = options.secret) !== null && _b !== void 0 ? _b : ''}`);
|
117
|
+
}
|
118
|
+
exports.init = init;
|
119
|
+
// Data tracking
|
120
|
+
function identify(user) {
|
121
|
+
return __awaiter(this, void 0, void 0, function* () {
|
122
|
+
if (isNull(user)) {
|
123
|
+
throw new error_1.EngageError('You need to pass an object with at least an id.');
|
124
|
+
}
|
125
|
+
if (isNullString(user.id)) {
|
126
|
+
throw new error_1.EngageError('ID missing.');
|
127
|
+
}
|
128
|
+
if (!isNull(user.email) && (typeof user.email !== 'string' || !/^\S+@\S+$/.test(user.email))) {
|
129
|
+
throw new error_1.EngageError('Email invalid.');
|
130
|
+
}
|
131
|
+
const params = {};
|
132
|
+
params.meta = {};
|
133
|
+
for (const k in user) {
|
134
|
+
if (k === 'id' || notMeta.includes(k)) {
|
135
|
+
params[k] = user[k];
|
136
|
+
}
|
137
|
+
else {
|
138
|
+
params.meta[k] = user[k];
|
139
|
+
}
|
140
|
+
}
|
141
|
+
// Store the user ID for use in other functions
|
142
|
+
currentUserId = user.id;
|
143
|
+
return yield _request(`/users/${user.id}`, params, 'PUT');
|
144
|
+
});
|
145
|
+
}
|
146
|
+
exports.identify = identify;
|
147
|
+
function addAttribute(uidOrAttributes, attributes) {
|
148
|
+
return __awaiter(this, void 0, void 0, function* () {
|
149
|
+
let uid;
|
150
|
+
let attrs;
|
151
|
+
// Handle overloaded parameters
|
152
|
+
if (typeof uidOrAttributes === 'string') {
|
153
|
+
uid = resolveUserId(uidOrAttributes);
|
154
|
+
if (isNull(attributes)) {
|
155
|
+
throw new error_1.EngageError('Attributes missing when uid is provided.');
|
156
|
+
}
|
157
|
+
attrs = attributes;
|
158
|
+
}
|
159
|
+
else {
|
160
|
+
uid = resolveUserId();
|
161
|
+
attrs = uidOrAttributes;
|
162
|
+
}
|
163
|
+
if (isNull(attrs)) {
|
164
|
+
throw new error_1.EngageError('Attributes missing.');
|
165
|
+
}
|
166
|
+
if (Object.keys(attrs).length === 0) {
|
167
|
+
throw new error_1.EngageError('Attributes missing.');
|
168
|
+
}
|
169
|
+
const params = {};
|
170
|
+
params.meta = {};
|
171
|
+
for (const k in attrs) {
|
172
|
+
if (notMeta.includes(k)) {
|
173
|
+
params[k] = attrs[k];
|
174
|
+
}
|
175
|
+
else {
|
176
|
+
params.meta[k] = attrs[k];
|
177
|
+
}
|
178
|
+
}
|
179
|
+
if (Object.keys(params.meta).length === 0) {
|
180
|
+
delete params.meta;
|
181
|
+
}
|
182
|
+
return yield _request(`/users/${uid}`, params, 'PUT');
|
183
|
+
});
|
184
|
+
}
|
185
|
+
exports.addAttribute = addAttribute;
|
186
|
+
function track(uidOrData, data) {
|
187
|
+
return __awaiter(this, void 0, void 0, function* () {
|
188
|
+
let uid;
|
189
|
+
let eventData;
|
190
|
+
// Handle overloaded parameters
|
191
|
+
if (typeof uidOrData === 'string') {
|
192
|
+
uid = resolveUserId(uidOrData);
|
193
|
+
if (isNull(data)) {
|
194
|
+
throw new error_1.EngageError('Event data missing when uid is provided.');
|
195
|
+
}
|
196
|
+
eventData = data;
|
197
|
+
}
|
198
|
+
else {
|
199
|
+
uid = resolveUserId();
|
200
|
+
eventData = uidOrData;
|
201
|
+
}
|
202
|
+
if (isNull(eventData)) {
|
203
|
+
throw new error_1.EngageError('Event data missing.');
|
204
|
+
}
|
205
|
+
if (typeof eventData === 'string') {
|
206
|
+
eventData = {
|
207
|
+
event: eventData,
|
208
|
+
value: true
|
209
|
+
};
|
210
|
+
}
|
211
|
+
else {
|
212
|
+
if (Object.keys(eventData).length === 0) {
|
213
|
+
throw new error_1.EngageError('Attributes missing.');
|
214
|
+
}
|
215
|
+
}
|
216
|
+
return yield _request(`/users/${uid}/events`, eventData, 'POST');
|
217
|
+
});
|
218
|
+
}
|
219
|
+
exports.track = track;
|
220
|
+
function merge(sourceOrDestinationUid, destinationUid) {
|
221
|
+
return __awaiter(this, void 0, void 0, function* () {
|
222
|
+
let sourceUid;
|
223
|
+
let destUid;
|
224
|
+
// Handle overloaded parameters
|
225
|
+
if (isNullString(destinationUid)) {
|
226
|
+
// Called with one parameter: merge(destinationUid)
|
227
|
+
sourceUid = resolveUserId();
|
228
|
+
destUid = sourceOrDestinationUid;
|
229
|
+
}
|
230
|
+
else {
|
231
|
+
// Called with two parameters: merge(sourceUid, destinationUid)
|
232
|
+
sourceUid = resolveUserId(sourceOrDestinationUid);
|
233
|
+
destUid = destinationUid;
|
234
|
+
}
|
235
|
+
if (isNullString(destUid)) {
|
236
|
+
throw new error_1.EngageError('Destination ID missing.');
|
237
|
+
}
|
238
|
+
return yield _request('/users/merge', {
|
239
|
+
source: sourceUid,
|
240
|
+
destination: destUid
|
241
|
+
}, 'POST');
|
242
|
+
});
|
243
|
+
}
|
244
|
+
exports.merge = merge;
|
245
|
+
// Account functions
|
246
|
+
function addToAccount(uid, accountId, role) {
|
247
|
+
return __awaiter(this, void 0, void 0, function* () {
|
248
|
+
if (isNullString(uid)) {
|
249
|
+
throw new error_1.EngageError('User ID missing.');
|
250
|
+
}
|
251
|
+
if (isNullString(accountId)) {
|
252
|
+
throw new error_1.EngageError('Account ID missing.');
|
253
|
+
}
|
254
|
+
if (!isNull(role) && typeof role !== 'string') {
|
255
|
+
throw new error_1.EngageError('Role should be a text.');
|
256
|
+
}
|
257
|
+
const g = {
|
258
|
+
id: accountId
|
259
|
+
};
|
260
|
+
if (!isNullString(role)) {
|
261
|
+
g.role = role;
|
262
|
+
}
|
263
|
+
return yield _request(`/users/${uid}/accounts`, { accounts: [g] }, 'POST');
|
264
|
+
});
|
265
|
+
}
|
266
|
+
exports.addToAccount = addToAccount;
|
267
|
+
function removeFromAccount(uidOrAccountId, accountId) {
|
268
|
+
return __awaiter(this, void 0, void 0, function* () {
|
269
|
+
let uid;
|
270
|
+
let acctId;
|
271
|
+
// Handle overloaded parameters
|
272
|
+
if (isNullString(accountId)) {
|
273
|
+
// Called with one parameter: removeFromAccount(accountId)
|
274
|
+
uid = resolveUserId();
|
275
|
+
acctId = uidOrAccountId;
|
276
|
+
}
|
277
|
+
else {
|
278
|
+
// Called with two parameters: removeFromAccount(uid, accountId)
|
279
|
+
uid = resolveUserId(uidOrAccountId);
|
280
|
+
acctId = accountId;
|
281
|
+
}
|
282
|
+
if (isNullString(acctId)) {
|
283
|
+
throw new error_1.EngageError('Account ID missing.');
|
284
|
+
}
|
285
|
+
return yield _request(`/users/${uid}/accounts/${acctId}`, null, 'DELETE');
|
286
|
+
});
|
287
|
+
}
|
288
|
+
exports.removeFromAccount = removeFromAccount;
|
289
|
+
function changeAccountRole(uidOrAccountId, accountIdOrRole, role) {
|
290
|
+
return __awaiter(this, void 0, void 0, function* () {
|
291
|
+
let uid;
|
292
|
+
let accountId;
|
293
|
+
let newRole;
|
294
|
+
// Handle overloaded parameters
|
295
|
+
if (isNullString(role)) {
|
296
|
+
// Called with two parameters: changeAccountRole(accountId, role)
|
297
|
+
uid = resolveUserId();
|
298
|
+
accountId = uidOrAccountId;
|
299
|
+
newRole = accountIdOrRole;
|
300
|
+
}
|
301
|
+
else {
|
302
|
+
// Called with three parameters: changeAccountRole(uid, accountId, role)
|
303
|
+
uid = resolveUserId(uidOrAccountId);
|
304
|
+
accountId = accountIdOrRole;
|
305
|
+
newRole = role;
|
306
|
+
}
|
307
|
+
if (isNullString(accountId)) {
|
308
|
+
throw new error_1.EngageError('Account ID missing.');
|
309
|
+
}
|
310
|
+
if (isNullString(newRole)) {
|
311
|
+
throw new error_1.EngageError('New role missing.');
|
312
|
+
}
|
313
|
+
return yield _request(`/users/${uid}/accounts/${accountId}`, { role: newRole }, 'PUT');
|
314
|
+
});
|
315
|
+
}
|
316
|
+
exports.changeAccountRole = changeAccountRole;
|
317
|
+
function convertToCustomer(uid) {
|
318
|
+
return __awaiter(this, void 0, void 0, function* () {
|
319
|
+
const userId = resolveUserId(uid);
|
320
|
+
return yield _request(`/users/${userId}/convert`, { type: 'customer' }, 'POST');
|
321
|
+
});
|
322
|
+
}
|
323
|
+
exports.convertToCustomer = convertToCustomer;
|
324
|
+
function convertToAccount(uid) {
|
325
|
+
return __awaiter(this, void 0, void 0, function* () {
|
326
|
+
const userId = resolveUserId(uid);
|
327
|
+
return yield _request(`/users/${userId}/convert`, { type: 'account' }, 'POST');
|
328
|
+
});
|
329
|
+
}
|
330
|
+
exports.convertToAccount = convertToAccount;
|
331
|
+
// Create an object containing all exports for easy access
|
332
|
+
const EngageSDK = {
|
333
|
+
init,
|
334
|
+
identify,
|
335
|
+
addAttribute,
|
336
|
+
track,
|
337
|
+
merge,
|
338
|
+
addToAccount,
|
339
|
+
removeFromAccount,
|
340
|
+
changeAccountRole,
|
341
|
+
convertToCustomer,
|
342
|
+
convertToAccount,
|
343
|
+
request
|
344
|
+
};
|
345
|
+
// Export as default for import EngageSDK syntax
|
346
|
+
exports.default = EngageSDK;
|
package/package.json
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
{
|
2
2
|
"name": "@engage_so/core",
|
3
|
-
"version": "2.2.
|
3
|
+
"version": "2.2.2",
|
4
4
|
"description": "Engage JavaScript SDK (core)",
|
5
5
|
"main": "./dist/index.js",
|
6
6
|
"types": "./dist/index.d.ts",
|
7
|
+
"files": [
|
8
|
+
"dist/",
|
9
|
+
"README.md"
|
10
|
+
],
|
7
11
|
"scripts": {
|
8
12
|
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
|
9
13
|
"build": "rm -rf dist && tsc -p tsconfig.json",
|
@@ -1,75 +0,0 @@
|
|
1
|
-
name: Test
|
2
|
-
|
3
|
-
on:
|
4
|
-
push:
|
5
|
-
branches: [ master ]
|
6
|
-
pull_request:
|
7
|
-
branches: [ master ]
|
8
|
-
workflow_dispatch: # Allow manual trigger
|
9
|
-
|
10
|
-
jobs:
|
11
|
-
test:
|
12
|
-
runs-on: ubuntu-latest
|
13
|
-
|
14
|
-
strategy:
|
15
|
-
matrix:
|
16
|
-
node-version: [18.x, 20.x, 22.x]
|
17
|
-
|
18
|
-
steps:
|
19
|
-
- name: Checkout code
|
20
|
-
uses: actions/checkout@v4
|
21
|
-
|
22
|
-
- name: Setup Node.js ${{ matrix.node-version }}
|
23
|
-
uses: actions/setup-node@v4
|
24
|
-
with:
|
25
|
-
node-version: ${{ matrix.node-version }}
|
26
|
-
cache: 'npm'
|
27
|
-
|
28
|
-
- name: Install dependencies
|
29
|
-
run: npm ci
|
30
|
-
|
31
|
-
- name: Build project
|
32
|
-
run: npm run build
|
33
|
-
|
34
|
-
- name: Run tests
|
35
|
-
run: npm test
|
36
|
-
env:
|
37
|
-
KEY: ${{ secrets.ENGAGE_API_KEY }}
|
38
|
-
SECRET: ${{ secrets.ENGAGE_API_SECRET }}
|
39
|
-
|
40
|
-
- name: Upload test results
|
41
|
-
uses: actions/upload-artifact@v4
|
42
|
-
if: always()
|
43
|
-
with:
|
44
|
-
name: test-results-node-${{ matrix.node-version }}
|
45
|
-
path: |
|
46
|
-
coverage/
|
47
|
-
test-results.xml
|
48
|
-
retention-days: 7
|
49
|
-
|
50
|
-
build-check:
|
51
|
-
runs-on: ubuntu-latest
|
52
|
-
|
53
|
-
steps:
|
54
|
-
- name: Checkout code
|
55
|
-
uses: actions/checkout@v4
|
56
|
-
|
57
|
-
- name: Setup Node.js
|
58
|
-
uses: actions/setup-node@v4
|
59
|
-
with:
|
60
|
-
node-version: '20.x'
|
61
|
-
cache: 'npm'
|
62
|
-
|
63
|
-
- name: Install dependencies
|
64
|
-
run: npm ci
|
65
|
-
|
66
|
-
- name: Build project
|
67
|
-
run: npm run build
|
68
|
-
|
69
|
-
- name: Check build output
|
70
|
-
run: |
|
71
|
-
echo "Checking if dist files were created..."
|
72
|
-
ls -la dist/
|
73
|
-
echo "Checking TypeScript declaration files..."
|
74
|
-
ls -la dist/*.d.ts
|
75
|
-
echo "Build successful!"
|
package/jest.config.js
DELETED