arc-services 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/README.md +15 -0
- package/dist/classes/index.d.ts +2 -0
- package/dist/classes/index.d.ts.map +1 -0
- package/dist/classes/instance.d.ts +12 -0
- package/dist/classes/instance.d.ts.map +1 -0
- package/dist/config/domains.d.ts +3 -0
- package/dist/config/domains.d.ts.map +1 -0
- package/dist/dist/index.d.ts +26 -0
- package/dist/dist/index.d.ts.map +1 -0
- package/dist/handlers/api/auth/createAuthSession.d.ts +4 -0
- package/dist/handlers/api/auth/createAuthSession.d.ts.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +127 -0
- package/dist/tests/index.test.d.ts +2 -0
- package/dist/tests/index.test.d.ts.map +1 -0
- package/dist/types/api/account.d.ts +6 -0
- package/dist/types/api/account.d.ts.map +1 -0
- package/dist/types/api/auth/index.d.ts +2 -0
- package/dist/types/api/auth/index.d.ts.map +1 -0
- package/dist/types/api/auth/session.d.ts +9 -0
- package/dist/types/api/auth/session.d.ts.map +1 -0
- package/dist/types/api/index.d.ts +2 -0
- package/dist/types/api/index.d.ts.map +1 -0
- package/dist/types/config/index.d.ts +2 -0
- package/dist/types/config/index.d.ts.map +1 -0
- package/dist/types/config/options.d.ts +6 -0
- package/dist/types/config/options.d.ts.map +1 -0
- package/dist/types/default/domain.d.ts +7 -0
- package/dist/types/default/domain.d.ts.map +1 -0
- package/dist/types/default/index.d.ts +2 -0
- package/dist/types/default/index.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/util/base64.d.ts +2 -0
- package/dist/util/base64.d.ts.map +1 -0
- package/dist/util/jwt.d.ts +2 -0
- package/dist/util/jwt.d.ts.map +1 -0
- package/package.json +48 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../classes/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Configuration, Domain } from "../types";
|
|
2
|
+
export declare class Instance {
|
|
3
|
+
readonly ClientID: string;
|
|
4
|
+
readonly stage: "dev" | "staging" | "prod";
|
|
5
|
+
readonly Hosts: Domain[];
|
|
6
|
+
constructor(config: Configuration);
|
|
7
|
+
getAuthDomain(): Domain | undefined;
|
|
8
|
+
getAccountDomain(): Domain | undefined;
|
|
9
|
+
CreateAuthSession(identity: string): Promise<import("../types/api/auth").Session>;
|
|
10
|
+
CreateIdentity(iss: string, sub: string, dn: string): string;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=instance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instance.d.ts","sourceRoot":"","sources":["../../classes/instance.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAGrD,qBAAa,QAAQ;IACjB,SAAgB,QAAQ,EAAE,MAAM,CAAM;IACtC,SAAgB,KAAK,EAAE,KAAK,GAAG,SAAS,GAAG,MAAM,CAAA;IACjD,SAAgB,KAAK,EAAE,MAAM,EAAE,CAAA;gBAEnB,MAAM,EAAE,aAAa;IAMjC,aAAa,IAAI,MAAM,GAAG,SAAS;IAInC,gBAAgB,IAAI,MAAM,GAAG,SAAS;IAItC,iBAAiB,CAAC,QAAQ,EAAE,MAAM;IAMlC,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM;CAU/D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"domains.d.ts","sourceRoot":"","sources":["../../config/domains.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC,eAAO,MAAM,OAAO,EAAE,MAAM,EAqC3B,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export class Instance {
|
|
2
|
+
constructor(config: any);
|
|
3
|
+
ClientID: string;
|
|
4
|
+
stage: any;
|
|
5
|
+
Hosts: {
|
|
6
|
+
service: string;
|
|
7
|
+
host: string;
|
|
8
|
+
ssl: boolean;
|
|
9
|
+
type: string;
|
|
10
|
+
}[];
|
|
11
|
+
getAuthDomain(): {
|
|
12
|
+
service: string;
|
|
13
|
+
host: string;
|
|
14
|
+
ssl: boolean;
|
|
15
|
+
type: string;
|
|
16
|
+
} | undefined;
|
|
17
|
+
getAccountDomain(): {
|
|
18
|
+
service: string;
|
|
19
|
+
host: string;
|
|
20
|
+
ssl: boolean;
|
|
21
|
+
type: string;
|
|
22
|
+
} | undefined;
|
|
23
|
+
CreateAuthSession(identity: any): Promise<any>;
|
|
24
|
+
CreateIdentity(iss: any, sub: any, dn: any): string;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.js"],"names":[],"mappings":"AA6FA;IAIE,yBAIC;IAPD,iBAAc;IACd,WAAM;IACN;;;;;QAAM;IAMN;;;;;kBAEC;IACD;;;;;kBAEC;IACD,+CAIC;IACD,oDASC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createAuthSession.d.ts","sourceRoot":"","sources":["../../../../handlers/api/auth/createAuthSession.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEjD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAEvD,wBAAsB,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CA4B9F"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,SAAS,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, {
|
|
5
|
+
get: all[name],
|
|
6
|
+
enumerable: true,
|
|
7
|
+
configurable: true,
|
|
8
|
+
set: (newValue) => all[name] = () => newValue
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// handlers/api/auth/createAuthSession.ts
|
|
13
|
+
var exports_createAuthSession = {};
|
|
14
|
+
__export(exports_createAuthSession, {
|
|
15
|
+
createAuthSession: () => createAuthSession
|
|
16
|
+
});
|
|
17
|
+
async function createAuthSession(instance, identity) {
|
|
18
|
+
const domain = instance.getAuthDomain();
|
|
19
|
+
if (!domain) {
|
|
20
|
+
throw new Error("Auth domain not found for the specified stage.");
|
|
21
|
+
}
|
|
22
|
+
const protocol = domain.ssl ? "https" : "http";
|
|
23
|
+
const url = `${protocol}://${domain.host}/api/v1/auth/session`;
|
|
24
|
+
const response = await fetch(url, {
|
|
25
|
+
method: "POST",
|
|
26
|
+
headers: {
|
|
27
|
+
"X-Arc-Client": instance.ClientID,
|
|
28
|
+
"Content-Type": "application/json"
|
|
29
|
+
},
|
|
30
|
+
body: JSON.stringify({ identity })
|
|
31
|
+
}).catch((error) => {
|
|
32
|
+
throw new Error(`error: ${error.message}`);
|
|
33
|
+
});
|
|
34
|
+
if (!response.ok) {
|
|
35
|
+
throw new Error(`failed to create auth session: ${response.status} ${response.statusText}`);
|
|
36
|
+
}
|
|
37
|
+
const data = await response.json().catch((error) => {
|
|
38
|
+
throw new Error(`error parsing response JSON: ${error.message}`);
|
|
39
|
+
});
|
|
40
|
+
return data;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// config/domains.ts
|
|
44
|
+
var Domains = [
|
|
45
|
+
{
|
|
46
|
+
service: "auth",
|
|
47
|
+
host: "dev-auth-v1.arc-services.dev",
|
|
48
|
+
ssl: true,
|
|
49
|
+
type: "dev"
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
service: "account",
|
|
53
|
+
host: "dev-account-v1.arc-services.dev",
|
|
54
|
+
ssl: true,
|
|
55
|
+
type: "dev"
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
service: "auth",
|
|
59
|
+
host: "staging-auth-v1.arc-services.dev",
|
|
60
|
+
ssl: true,
|
|
61
|
+
type: "staging"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
service: "account",
|
|
65
|
+
host: "staging-account-v1.arc-services.dev",
|
|
66
|
+
ssl: true,
|
|
67
|
+
type: "staging"
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
service: "auth",
|
|
71
|
+
host: "prod-auth-v1.arc-services.dev",
|
|
72
|
+
ssl: true,
|
|
73
|
+
type: "prod"
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
service: "account",
|
|
77
|
+
host: "prod-account-v1.arc-services.dev",
|
|
78
|
+
ssl: true,
|
|
79
|
+
type: "prod"
|
|
80
|
+
}
|
|
81
|
+
];
|
|
82
|
+
|
|
83
|
+
// util/base64.ts
|
|
84
|
+
function base64url(obj) {
|
|
85
|
+
return btoa(JSON.stringify(obj)).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// util/jwt.ts
|
|
89
|
+
function JWT(payload) {
|
|
90
|
+
return `${base64url({ alg: "none", typ: "JWT" })}.${base64url(payload)}.`;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// classes/instance.ts
|
|
94
|
+
class Instance {
|
|
95
|
+
ClientID = "";
|
|
96
|
+
stage;
|
|
97
|
+
Hosts;
|
|
98
|
+
constructor(config) {
|
|
99
|
+
this.ClientID = config.ClientID;
|
|
100
|
+
this.stage = config.stage ?? "prod";
|
|
101
|
+
this.Hosts = Domains.filter((domain) => domain.type === this.stage);
|
|
102
|
+
}
|
|
103
|
+
getAuthDomain() {
|
|
104
|
+
return this.Hosts.find((domain) => domain.service === "auth");
|
|
105
|
+
}
|
|
106
|
+
getAccountDomain() {
|
|
107
|
+
return this.Hosts.find((domain) => domain.service === "account");
|
|
108
|
+
}
|
|
109
|
+
CreateAuthSession(identity) {
|
|
110
|
+
return Promise.resolve().then(() => exports_createAuthSession).then(({ createAuthSession: createAuthSession2 }) => {
|
|
111
|
+
return createAuthSession2(this, identity);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
CreateIdentity(iss, sub, dn) {
|
|
115
|
+
const iat = Math.floor(Date.now() / 1000);
|
|
116
|
+
return JWT({
|
|
117
|
+
iat,
|
|
118
|
+
exp: iat + 300,
|
|
119
|
+
iss,
|
|
120
|
+
sub,
|
|
121
|
+
dn
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
export {
|
|
126
|
+
Instance
|
|
127
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../tests/index.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../../../types/api/account.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,OAAO;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,OAAO,CAAC;CACnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../types/api/auth/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../../../types/api/auth/session.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,MAAM,WAAW,OAAO;IACpB,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE;QACF,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;KACjB,CAAA;CACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../types/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../types/config/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../../types/config/options.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,KAAK,GAAG,SAAS,GAAG,MAAM,CAAA;CACrC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"domain.d.ts","sourceRoot":"","sources":["../../../types/default/domain.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,MAAM;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,OAAO,CAAC;IACb,IAAI,EAAE,KAAK,GAAG,SAAS,GAAG,MAAM,CAAA;CACnC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../types/default/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../types/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base64.d.ts","sourceRoot":"","sources":["../../util/base64.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,CAK1C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["../../util/jwt.ts"],"names":[],"mappings":"AAEA,wBAAgB,GAAG,CAAC,OAAO,EAAE,GAAG,GAAG,MAAM,CAExC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "arc-services",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Arc services client library",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"README.md",
|
|
12
|
+
"LICENSE"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "bun build index.ts --outdir dist --target node --format esm && bun run build:types",
|
|
16
|
+
"build:types": "tsc --emitDeclarationOnly --outDir dist",
|
|
17
|
+
"prepublishOnly": "bun run build",
|
|
18
|
+
"test": "bun test"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"arc",
|
|
22
|
+
"arc-services",
|
|
23
|
+
"authentication",
|
|
24
|
+
"api-client"
|
|
25
|
+
],
|
|
26
|
+
"author": "andr1ww <me@andr1ww.dev>",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "https://github.com/Arc-Services/Arc-Typescript.git"
|
|
31
|
+
},
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/Arc-Services/Arc-Typescript/issues"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://github.com/Arc-Services/Arc-Typescript#readme",
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/bun": "latest"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"typescript": "^5.0.0"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"jsonwebtoken": "^9.0.3"
|
|
44
|
+
},
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=18.0.0"
|
|
47
|
+
}
|
|
48
|
+
}
|