@medusajs/locking-redis 0.0.2-snapshot-20241013171145

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ declare const _default: import("@medusajs/types").ModuleProviderExports;
2
+ export default _default;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAOA,wBAGE"}
package/dist/index.js ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("@medusajs/framework/utils");
7
+ const loaders_1 = __importDefault(require("./loaders"));
8
+ const redis_lock_1 = require("./services/redis-lock");
9
+ const services = [redis_lock_1.RedisLockingProvider];
10
+ const loaders = [loaders_1.default];
11
+ exports.default = (0, utils_1.ModuleProvider)(utils_1.Modules.LOCKING, {
12
+ services,
13
+ loaders,
14
+ });
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,qDAAmE;AACnE,wDAA8B;AAC9B,sDAA4D;AAE5D,MAAM,QAAQ,GAAG,CAAC,iCAAoB,CAAC,CAAA;AACvC,MAAM,OAAO,GAAG,CAAC,iBAAM,CAAC,CAAA;AAExB,kBAAe,IAAA,sBAAc,EAAC,eAAO,CAAC,OAAO,EAAE;IAC7C,QAAQ;IACR,OAAO;CACR,CAAC,CAAA"}
@@ -0,0 +1,4 @@
1
+ import { ProviderLoaderOptions } from "@medusajs/types";
2
+ declare const _default: ({ container, logger, options, moduleOptions, }: ProviderLoaderOptions) => Promise<void>;
3
+ export default _default;
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/loaders/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;yEAUpD,qBAAqB,KAAG,OAAO,CAAC,IAAI,CAAC;AALxC,wBAkCC"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("@medusajs/framework/utils");
7
+ const awilix_1 = require("awilix");
8
+ const ioredis_1 = __importDefault(require("ioredis"));
9
+ exports.default = async ({ container, logger, options, moduleOptions, }) => {
10
+ const { redisUrl, redisOptions, namespace } = options;
11
+ if (!redisUrl) {
12
+ throw Error(`No "redisUrl" provided in "${utils_1.Modules.LOCKING}" module, "locking-redis" provider options. It is required for the "locking-redis" Module provider.`);
13
+ }
14
+ const connection = new ioredis_1.default(redisUrl, {
15
+ // Lazy connect to properly handle connection errors
16
+ lazyConnect: true,
17
+ ...(redisOptions ?? {}),
18
+ });
19
+ try {
20
+ await connection.connect();
21
+ logger?.info(`Connection to Redis in "locking-redis" provider established`);
22
+ }
23
+ catch (err) {
24
+ logger?.error(`An error occurred while connecting to Redis in provider "locking-redis": ${err}`);
25
+ }
26
+ container.register({
27
+ redisClient: (0, awilix_1.asValue)(connection),
28
+ prefix: (0, awilix_1.asValue)(namespace ?? "medusa_lock:"),
29
+ });
30
+ };
31
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/loaders/index.ts"],"names":[],"mappings":";;;;;AAAA,qDAAmD;AAGnD,mCAAgC;AAChC,sDAA2B;AAE3B,kBAAe,KAAK,EAAE,EACpB,SAAS,EACT,MAAM,EACN,OAAO,EACP,aAAa,GACS,EAAiB,EAAE;IACzC,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,SAAS,EAAE,GACzC,OAAkC,CAAA;IAEpC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,KAAK,CACT,8BAA8B,eAAO,CAAC,OAAO,qGAAqG,CACnJ,CAAA;IACH,CAAC;IAED,MAAM,UAAU,GAAG,IAAI,iBAAK,CAAC,QAAQ,EAAE;QACrC,oDAAoD;QACpD,WAAW,EAAE,IAAI;QACjB,GAAG,CAAC,YAAY,IAAI,EAAE,CAAC;KACxB,CAAC,CAAA;IAEF,IAAI,CAAC;QACH,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;QAC1B,MAAM,EAAE,IAAI,CAAC,6DAA6D,CAAC,CAAA;IAC7E,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,EAAE,KAAK,CACX,4EAA4E,GAAG,EAAE,CAClF,CAAA;IACH,CAAC;IAED,SAAS,CAAC,QAAQ,CAAC;QACjB,WAAW,EAAE,IAAA,gBAAO,EAAC,UAAU,CAAC;QAChC,MAAM,EAAE,IAAA,gBAAO,EAAC,SAAS,IAAI,cAAc,CAAC;KAC7C,CAAC,CAAA;AACJ,CAAC,CAAA"}
@@ -0,0 +1,40 @@
1
+ import { ILockingProvider } from "@medusajs/types";
2
+ import { Redis } from "ioredis";
3
+ declare const RedisLockingProvider_base: import("@medusajs/framework/utils").MedusaServiceReturnType<import("@medusajs/framework/utils").ModelConfigurationsToConfigTemplate<{}>>;
4
+ export declare class RedisLockingProvider extends RedisLockingProvider_base implements ILockingProvider {
5
+ static identifier: string;
6
+ protected redisClient: Redis & {
7
+ acquireLock: (key: string, ownerId: string, ttl: number, awaitQueue?: boolean) => Promise<number>;
8
+ releaseLock: (key: string, ownerId: string) => Promise<number>;
9
+ };
10
+ protected keyNamePrefix: string;
11
+ constructor({ redisClient, prefix }: {
12
+ redisClient: any;
13
+ prefix: any;
14
+ });
15
+ private getKeyName;
16
+ execute<T>(keys: string | string[], job: () => Promise<T>, args?: {
17
+ timeout?: number;
18
+ }): Promise<T>;
19
+ acquire(keys: string | string[], args?: {
20
+ ownerId?: string;
21
+ expire?: number;
22
+ awaitQueue?: boolean;
23
+ }): Promise<void>;
24
+ acquire_(keys: string | string[], args?: {
25
+ ownerId?: string;
26
+ expire?: number;
27
+ awaitQueue?: boolean;
28
+ }, cancellationToken?: {
29
+ cancelled: boolean;
30
+ }): Promise<void>;
31
+ release(keys: string | string[], args?: {
32
+ ownerId?: string | null;
33
+ }): Promise<boolean>;
34
+ releaseAll(args?: {
35
+ ownerId?: string | null;
36
+ }): Promise<void>;
37
+ private getTimeout;
38
+ }
39
+ export {};
40
+ //# sourceMappingURL=redis-lock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redis-lock.d.ts","sourceRoot":"","sources":["../../src/services/redis-lock.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;;AAG/B,qBAAa,oBACX,SAAQ,yBACR,YAAW,gBAAgB;IAE3B,MAAM,CAAC,UAAU,SAAkB;IAEnC,SAAS,CAAC,WAAW,EAAE,KAAK,GAAG;QAC7B,WAAW,EAAE,CACX,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM,EACX,UAAU,CAAC,EAAE,OAAO,KACjB,OAAO,CAAC,MAAM,CAAC,CAAA;QACpB,WAAW,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;KAC/D,CAAA;IACD,SAAS,CAAC,aAAa,EAAE,MAAM,CAAA;gBAEnB,EAAE,WAAW,EAAE,MAAM,EAAE;;;KAAA;IAiDnC,OAAO,CAAC,UAAU;IAIZ,OAAO,CAAC,CAAC,EACb,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,EACvB,GAAG,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACrB,IAAI,CAAC,EAAE;QACL,OAAO,CAAC,EAAE,MAAM,CAAA;KACjB,GACA,OAAO,CAAC,CAAC,CAAC;IA6BP,OAAO,CACX,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,EACvB,IAAI,CAAC,EAAE;QACL,OAAO,CAAC,EAAE,MAAM,CAAA;QAChB,MAAM,CAAC,EAAE,MAAM,CAAA;QACf,UAAU,CAAC,EAAE,OAAO,CAAA;KACrB,GACA,OAAO,CAAC,IAAI,CAAC;IAIV,QAAQ,CACZ,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,EACvB,IAAI,CAAC,EAAE;QACL,OAAO,CAAC,EAAE,MAAM,CAAA;QAChB,MAAM,CAAC,EAAE,MAAM,CAAA;QACf,UAAU,CAAC,EAAE,OAAO,CAAA;KACrB,EACD,iBAAiB,CAAC,EAAE;QAAE,SAAS,EAAE,OAAO,CAAA;KAAE,GACzC,OAAO,CAAC,IAAI,CAAC;IA4CV,OAAO,CACX,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,EACvB,IAAI,CAAC,EAAE;QACL,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KACxB,GACA,OAAO,CAAC,OAAO,CAAC;IAeb,UAAU,CAAC,IAAI,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;YAwCrD,UAAU;CAUzB"}
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RedisLockingProvider = void 0;
4
+ const utils_1 = require("@medusajs/framework/utils");
5
+ const promises_1 = require("node:timers/promises");
6
+ class RedisLockingProvider extends (0, utils_1.MedusaService)({}) {
7
+ constructor({ redisClient, prefix }) {
8
+ super(...arguments);
9
+ this.redisClient = redisClient;
10
+ this.keyNamePrefix = prefix ?? "medusa_lock:";
11
+ // Define the custom command for acquiring locks
12
+ this.redisClient.defineCommand("acquireLock", {
13
+ numberOfKeys: 1,
14
+ lua: `
15
+ local key = KEYS[1]
16
+ local ownerId = ARGV[1]
17
+ local ttl = tonumber(ARGV[2])
18
+ local awaitQueue = ARGV[3] == 'true'
19
+
20
+ local setResult = redis.call('SET', key, ownerId, 'EX', ttl, 'NX')
21
+
22
+ if setResult then
23
+ return 1
24
+ elseif not awaitQueue then
25
+ -- Key already exists; retrieve the current ownerId
26
+ local currentOwnerId = redis.call('GET', key)
27
+ if currentOwnerId == ownerId then
28
+ redis.call('SET', key, ownerId, 'EX', ttl, 'XX')
29
+ return 1
30
+ else
31
+ return 0
32
+ end
33
+ else
34
+ return 0
35
+ end
36
+ `,
37
+ });
38
+ // Define the custom command for releasing locks
39
+ this.redisClient.defineCommand("releaseLock", {
40
+ numberOfKeys: 1,
41
+ lua: `
42
+ local key = KEYS[1]
43
+ local ownerId = ARGV[1]
44
+
45
+ if redis.call('GET', key) == ownerId then
46
+ return redis.call('DEL', key)
47
+ else
48
+ return 0
49
+ end
50
+ `,
51
+ });
52
+ }
53
+ getKeyName(key) {
54
+ return `${this.keyNamePrefix}${key}`;
55
+ }
56
+ async execute(keys, job, args) {
57
+ const timeout = Math.max(args?.timeout ?? 5, 1);
58
+ const timeoutSeconds = Number.isNaN(timeout) ? 1 : timeout;
59
+ const cancellationToken = { cancelled: false };
60
+ const promises = [];
61
+ if (timeoutSeconds > 0) {
62
+ promises.push(this.getTimeout(timeoutSeconds, cancellationToken));
63
+ }
64
+ promises.push(this.acquire_(keys, {
65
+ awaitQueue: true,
66
+ }, cancellationToken));
67
+ await Promise.race(promises);
68
+ try {
69
+ return await job();
70
+ }
71
+ finally {
72
+ await this.release(keys);
73
+ }
74
+ }
75
+ async acquire(keys, args) {
76
+ return this.acquire_(keys, args);
77
+ }
78
+ async acquire_(keys, args, cancellationToken) {
79
+ keys = Array.isArray(keys) ? keys : [keys];
80
+ const timeout = Math.max(args?.expire ?? 5, 1);
81
+ const timeoutSeconds = Number.isNaN(timeout) ? 1 : timeout;
82
+ const ownerId = args?.ownerId ?? "*";
83
+ const awaitQueue = args?.awaitQueue ?? false;
84
+ const acquirePromises = keys.map(async (key) => {
85
+ const keyName = this.getKeyName(key);
86
+ const acquireLock = async () => {
87
+ while (true) {
88
+ if (cancellationToken?.cancelled) {
89
+ return;
90
+ }
91
+ const result = await this.redisClient.acquireLock(keyName, ownerId, timeoutSeconds, awaitQueue);
92
+ if (result === 1) {
93
+ break;
94
+ }
95
+ else {
96
+ if (awaitQueue) {
97
+ // Wait for a short period before retrying
98
+ await (0, promises_1.setTimeout)(100);
99
+ }
100
+ else {
101
+ throw new Error(`Failed to acquire lock for key "${key}"`);
102
+ }
103
+ }
104
+ }
105
+ };
106
+ await acquireLock();
107
+ });
108
+ await Promise.all(acquirePromises);
109
+ }
110
+ async release(keys, args) {
111
+ const ownerId = args?.ownerId ?? "*";
112
+ keys = Array.isArray(keys) ? keys : [keys];
113
+ const releasePromises = keys.map(async (key) => {
114
+ const keyName = this.getKeyName(key);
115
+ const result = await this.redisClient.releaseLock(keyName, ownerId);
116
+ return result === 1;
117
+ });
118
+ const results = await Promise.all(releasePromises);
119
+ return results.every((released) => released);
120
+ }
121
+ async releaseAll(args) {
122
+ const ownerId = args?.ownerId ?? "*";
123
+ const pattern = `${this.keyNamePrefix}*`;
124
+ let cursor = "0";
125
+ do {
126
+ const result = await this.redisClient.scan(cursor, "MATCH", pattern, "COUNT", 100);
127
+ cursor = result[0];
128
+ const keys = result[1];
129
+ if (keys.length > 0) {
130
+ const pipeline = this.redisClient.pipeline();
131
+ keys.forEach((key) => {
132
+ pipeline.get(key);
133
+ });
134
+ const currentOwners = await pipeline.exec();
135
+ const deletePipeline = this.redisClient.pipeline();
136
+ keys.forEach((key, idx) => {
137
+ const currentOwner = currentOwners?.[idx]?.[1];
138
+ if (currentOwner === ownerId) {
139
+ deletePipeline.del(key);
140
+ }
141
+ });
142
+ await deletePipeline.exec();
143
+ }
144
+ } while (cursor !== "0");
145
+ }
146
+ async getTimeout(seconds, cancellationToken) {
147
+ return new Promise(async (_, reject) => {
148
+ await (0, promises_1.setTimeout)(seconds * 1000);
149
+ cancellationToken.cancelled = true;
150
+ reject(new Error("Timed-out acquiring lock."));
151
+ });
152
+ }
153
+ }
154
+ exports.RedisLockingProvider = RedisLockingProvider;
155
+ RedisLockingProvider.identifier = "locking-redis";
156
+ //# sourceMappingURL=redis-lock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redis-lock.js","sourceRoot":"","sources":["../../src/services/redis-lock.ts"],"names":[],"mappings":";;;AAAA,qDAAyD;AAGzD,mDAAiD;AAEjD,MAAa,oBACX,SAAQ,IAAA,qBAAa,EAAC,EAAE,CAAC;IAgBzB,YAAY,EAAE,WAAW,EAAE,MAAM,EAAE;QACjC,KAAK,CAAC,GAAG,SAAS,CAAC,CAAA;QACnB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;QAC9B,IAAI,CAAC,aAAa,GAAG,MAAM,IAAI,cAAc,CAAA;QAE7C,gDAAgD;QAChD,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,aAAa,EAAE;YAC5C,YAAY,EAAE,CAAC;YACf,GAAG,EAAE;;;;;;;;;;;;;;;;;;;;;;OAsBJ;SACF,CAAC,CAAA;QAEF,gDAAgD;QAChD,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,aAAa,EAAE;YAC5C,YAAY,EAAE,CAAC;YACf,GAAG,EAAE;;;;;;;;;OASJ;SACF,CAAC,CAAA;IACJ,CAAC;IAEO,UAAU,CAAC,GAAW;QAC5B,OAAO,GAAG,IAAI,CAAC,aAAa,GAAG,GAAG,EAAE,CAAA;IACtC,CAAC;IAED,KAAK,CAAC,OAAO,CACX,IAAuB,EACvB,GAAqB,EACrB,IAEC;QAED,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,IAAI,CAAC,EAAE,CAAC,CAAC,CAAA;QAC/C,MAAM,cAAc,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAA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AE;oBACxB,MAAM,YAAY,GAAG,aAAa,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;oBAE9C,IAAI,YAAY,KAAK,OAAO,EAAE,CAAC;wBAC7B,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;oBACzB,CAAC;gBACH,CAAC,CAAC,CAAA;gBAEF,MAAM,cAAc,CAAC,IAAI,EAAE,CAAA;YAC7B,CAAC;QACH,CAAC,QAAQ,MAAM,KAAK,GAAG,EAAC;IAC1B,CAAC;IAEO,KAAK,CAAC,UAAU,CACtB,OAAe,EACf,iBAAyC;QAEzC,OAAO,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE;YACrC,MAAM,IAAA,qBAAU,EAAC,OAAO,GAAG,IAAI,CAAC,CAAA;YAChC,iBAAiB,CAAC,SAAS,GAAG,IAAI,CAAA;YAClC,MAAM,CAAC,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC,CAAA;QAChD,CAAC,CAAC,CAAA;IACJ,CAAC;;AA7OH,oDA8OC;AA1OQ,+BAAU,GAAG,eAAe,CAAA"}
@@ -0,0 +1 @@
1
+ {"root":["../src/index.ts","../src/loaders/index.ts","../src/services/redis-lock.ts","../src/types/index.ts"],"version":"5.6.2"}
@@ -0,0 +1,24 @@
1
+ import { RedisOptions } from "ioredis";
2
+ /**
3
+ * Module config type
4
+ */
5
+ export type RedisCacheModuleOptions = {
6
+ /**
7
+ * Time to keep data in cache (in seconds)
8
+ */
9
+ ttl?: number;
10
+ /**
11
+ * Redis connection string
12
+ */
13
+ redisUrl?: string;
14
+ /**
15
+ * Redis client options
16
+ */
17
+ redisOptions?: RedisOptions;
18
+ /**
19
+ * Prefix for event keys
20
+ * @default `medusa_lock:`
21
+ */
22
+ namespace?: string;
23
+ };
24
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAEtC;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IAEZ;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IAEjB;;OAEG;IACH,YAAY,CAAC,EAAE,YAAY,CAAA;IAE3B;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@medusajs/locking-redis",
3
+ "version": "0.0.2-snapshot-20241013171145",
4
+ "description": "Redis Lock for Medusa",
5
+ "main": "dist/index.js",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/medusajs/medusa",
9
+ "directory": "packages/locking-redis"
10
+ },
11
+ "files": [
12
+ "dist",
13
+ "!dist/**/__tests__",
14
+ "!dist/**/__mocks__",
15
+ "!dist/**/__fixtures__"
16
+ ],
17
+ "engines": {
18
+ "node": ">=20"
19
+ },
20
+ "author": "Medusa",
21
+ "license": "MIT",
22
+ "devDependencies": {
23
+ "@medusajs/framework": "0.0.2-snapshot-20241013171145",
24
+ "@swc/core": "^1.7.28",
25
+ "@swc/jest": "^0.2.36",
26
+ "jest": "^29.7.0",
27
+ "rimraf": "^5.0.1",
28
+ "typescript": "^5.6.2"
29
+ },
30
+ "peerDependencies": {
31
+ "@medusajs/framework": "0.0.2-snapshot-20241013171145"
32
+ },
33
+ "dependencies": {
34
+ "ioredis": "^5.4.1"
35
+ },
36
+ "scripts": {
37
+ "watch": "tsc --build --watch",
38
+ "watch:test": "tsc --build tsconfig.spec.json --watch",
39
+ "resolve:aliases": "tsc --showConfig -p tsconfig.json > tsconfig.resolved.json && tsc-alias -p tsconfig.resolved.json && rimraf tsconfig.resolved.json",
40
+ "build": "rimraf dist && tsc --build && npm run resolve:aliases",
41
+ "test": "jest --passWithNoTests src",
42
+ "test:integration": "jest --runInBand --forceExit -- integration-tests/**/__tests__/**/*.spec.ts"
43
+ },
44
+ "keywords": [
45
+ "medusa-providers",
46
+ "medusa-providers-locking"
47
+ ]
48
+ }