@heramb1/provider-upstash 0.1.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/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +59 -0
- package/dist/index.js.map +1 -0
- package/package.json +37 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { CacheLock, DestroyResult } from '@heramb1/core';
|
|
2
|
+
export interface UpstashLockOptions {
|
|
3
|
+
email: string;
|
|
4
|
+
apiKey: string;
|
|
5
|
+
}
|
|
6
|
+
export declare class UpstashLock implements CacheLock {
|
|
7
|
+
readonly name = "upstash";
|
|
8
|
+
private email;
|
|
9
|
+
private apiKey;
|
|
10
|
+
constructor(options: UpstashLockOptions);
|
|
11
|
+
private headers;
|
|
12
|
+
provision(options?: {
|
|
13
|
+
name?: string;
|
|
14
|
+
region?: string;
|
|
15
|
+
}): Promise<{
|
|
16
|
+
url: string;
|
|
17
|
+
serviceId: string;
|
|
18
|
+
}>;
|
|
19
|
+
destroy(serviceId: string): Promise<DestroyResult>;
|
|
20
|
+
}
|
|
21
|
+
export declare function createUpstashLock(email: string, apiKey: string): UpstashLock;
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAI9D,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,qBAAa,WAAY,YAAW,SAAS;IAC3C,QAAQ,CAAC,IAAI,aAAa;IAC1B,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,MAAM,CAAS;gBAEX,OAAO,EAAE,kBAAkB;IAKvC,OAAO,CAAC,OAAO;IAQT,SAAS,CAAC,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IAkCpG,OAAO,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;CAczD;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW,CAE5E"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
const UPSTASH_API = 'https://api.upstash.com/v2/redis/database';
|
|
2
|
+
export class UpstashLock {
|
|
3
|
+
name = 'upstash';
|
|
4
|
+
email;
|
|
5
|
+
apiKey;
|
|
6
|
+
constructor(options) {
|
|
7
|
+
this.email = options.email;
|
|
8
|
+
this.apiKey = options.apiKey;
|
|
9
|
+
}
|
|
10
|
+
headers() {
|
|
11
|
+
const encoded = Buffer.from(`${this.email}:${this.apiKey}`).toString('base64');
|
|
12
|
+
return {
|
|
13
|
+
Authorization: `Basic ${encoded}`,
|
|
14
|
+
'Content-Type': 'application/json',
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
async provision(options) {
|
|
18
|
+
const name = options?.name ?? `heramb-redis-${Date.now()}`;
|
|
19
|
+
const region = options?.region ?? 'us-east-1';
|
|
20
|
+
const res = await fetch(UPSTASH_API, {
|
|
21
|
+
method: 'POST',
|
|
22
|
+
headers: this.headers(),
|
|
23
|
+
body: JSON.stringify({
|
|
24
|
+
name,
|
|
25
|
+
region,
|
|
26
|
+
primary_region: region,
|
|
27
|
+
tls: true,
|
|
28
|
+
}),
|
|
29
|
+
});
|
|
30
|
+
if (!res.ok) {
|
|
31
|
+
throw new Error(`Upstash provision failed: ${await res.text()}`);
|
|
32
|
+
}
|
|
33
|
+
const data = (await res.json());
|
|
34
|
+
const url = `rediss://default:${data.password}@${data.endpoint}:${data.port}`;
|
|
35
|
+
return {
|
|
36
|
+
url,
|
|
37
|
+
serviceId: data.database_id,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
async destroy(serviceId) {
|
|
41
|
+
try {
|
|
42
|
+
const res = await fetch(`${UPSTASH_API}/${serviceId}`, {
|
|
43
|
+
method: 'DELETE',
|
|
44
|
+
headers: this.headers(),
|
|
45
|
+
});
|
|
46
|
+
return { ok: res.ok };
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
return {
|
|
50
|
+
ok: false,
|
|
51
|
+
error: err instanceof Error ? err.message : String(err),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export function createUpstashLock(email, apiKey) {
|
|
57
|
+
return new UpstashLock({ email, apiKey });
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,GAAG,2CAA2C,CAAC;AAOhE,MAAM,OAAO,WAAW;IACb,IAAI,GAAG,SAAS,CAAC;IAClB,KAAK,CAAS;IACd,MAAM,CAAS;IAEvB,YAAY,OAA2B;QACrC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAC/B,CAAC;IAEO,OAAO;QACb,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAC/E,OAAO;YACL,aAAa,EAAE,SAAS,OAAO,EAAE;YACjC,cAAc,EAAE,kBAAkB;SACnC,CAAC;IACJ,CAAC;IAED,KAAK,CA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E,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;aACxD,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AAED,MAAM,UAAU,iBAAiB,CAAC,KAAa,EAAE,MAAc;IAC7D,OAAO,IAAI,WAAW,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;AAC5C,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@heramb1/provider-upstash",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Upstash lock — Redis provisioning for Heramb",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc"
|
|
16
|
+
},
|
|
17
|
+
"files": ["dist"],
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public"
|
|
21
|
+
},
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/buildwithrenuka/heremb.git",
|
|
25
|
+
"directory": "packages/providers/upstash"
|
|
26
|
+
},
|
|
27
|
+
"keywords": ["deploy", "upstash", "redis", "heramb"],
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=18"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@heramb1/core": "0.1.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"typescript": "^5.7.2"
|
|
36
|
+
}
|
|
37
|
+
}
|