@jsontech/sdk-js 0.0.1

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.cjs ADDED
@@ -0,0 +1,61 @@
1
+ 'use strict';
2
+
3
+ // src/index.ts
4
+ var ShipItClient = class {
5
+ apiBaseUrl;
6
+ sdkKey;
7
+ projectKey;
8
+ envKey;
9
+ constructor(options) {
10
+ this.apiBaseUrl = options.apiBaseUrl.replace(/\/$/, "");
11
+ this.sdkKey = options.sdkKey?.trim() ? options.sdkKey.trim() : null;
12
+ this.projectKey = options.projectKey?.trim() ? options.projectKey.trim() : null;
13
+ this.envKey = options.envKey ?? "production";
14
+ if (!this.sdkKey && !this.projectKey) {
15
+ throw new Error("ShipItClient requires either sdkKey (recommended) or projectKey (legacy).");
16
+ }
17
+ }
18
+ normalizeUser(input) {
19
+ const key = (input.id ?? input.key ?? "").trim();
20
+ if (!key) throw new Error("ShipItClient requires user.id (or legacy user.key).");
21
+ return {
22
+ key,
23
+ email: input.email,
24
+ name: input.name,
25
+ country: input.country,
26
+ custom: input.meta ?? input.custom
27
+ };
28
+ }
29
+ async bool(flagKey, user, defaultValue = false) {
30
+ const normalizedUser = this.normalizeUser(user);
31
+ const res = this.sdkKey ? await fetch(`${this.apiBaseUrl}/api/v1/sdk/eval`, {
32
+ method: "POST",
33
+ headers: {
34
+ "content-type": "application/json",
35
+ "x-shipit-sdk-key": this.sdkKey
36
+ },
37
+ body: JSON.stringify({
38
+ flagKey,
39
+ user: normalizedUser,
40
+ defaultValue
41
+ })
42
+ }) : await fetch(`${this.apiBaseUrl}/api/v1/eval`, {
43
+ method: "POST",
44
+ headers: { "content-type": "application/json" },
45
+ body: JSON.stringify({
46
+ projectKey: this.projectKey,
47
+ envKey: this.envKey,
48
+ flagKey,
49
+ user: normalizedUser,
50
+ defaultValue
51
+ })
52
+ });
53
+ if (!res.ok) return defaultValue;
54
+ const json = await res.json();
55
+ return json.value;
56
+ }
57
+ };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AM,IAAA,CAAK,OAAA,EAAiB,IAAA,EAAyB,eAAe,KAAA,EAAyB;AAC3F,IAAA,MAAM,cAAA,GAAiB,IAAA,CAAK,aAAA,CAAc,IAAI,CAAA;AAC9C,IAAA,MAAM,GAAA,GAAM,KAAK,MAAA,GACb,MAAM,MAAM,CAAA,EAAG,IAAA,CAAK,UAAU,CAAA,gBAAA,CAAA,EAAoB;AAAA,MAChD,MAAA,EAAQ,MAAA;AAAA,MACR,OAAA,EAAS;AAAA,QACP,cAAA,EAAgB,kBAAA;AAAA,QAChB,oBAAoB,IAAA,CAAK;AAAA,OAC3B;AAAA,MACA,IAAA,EAAM,KAAK,SAAA,CAAU;AAAA,QACnB,OAAA;AAAA,QACA,IAAA,EAAM,cAAA;AAAA,QACN;AAAA,OACD;AAAA,KACF,CAAA,GACD,MAAM,MAAM,CAAA,EAAG,IAAA,CAAK,UAAU,CAAA,YAAA,CAAA,EAAgB;AAAA,MAC5C,MAAA,EAAQ,MAAA;AAAA,MACR,OAAA,EAAS,EAAE,cAAA,EAAgB,kBAAA,EAAmB;AAAA,MAC9C,IAAA,EAAM,KAAK,SAAA,CAAU;AAAA,QACnB,YAAY,IAAA,CAAK,UAAA;AAAA,QACjB,QAAQ,IAAA,CAAK,MAAA;AAAA,QACb,OAAA;AAAA,QACA,IAAA,EAAM,cAAA;AAAA,QACN;AAAA,OACD;AAAA,KACF,CAAA;AAEL,IAAA,IAAI,CAAC,GAAA,CAAI,EAAA,EAAI,OAAO,YAAA;AACpB,IAAA,MAAM,IAAA,GAAQ,MAAM,GAAA,CAAI,IAAA,EAAK;AAC7B,IAAA,OAAO,IAAA,CAAK,KAAA;AAAA,EACd;AACF","file":"index.cjs","sourcesContent":["export type ShipItUserPayload = {\n /** Unique user identifier (preferred). */\n id?: string;\n /** Legacy alias for id. */\n key?: string;\n email?: string;\n name?: string;\n country?: string;\n /** Queryable attributes. */\n meta?: Record<string, string | number | boolean | null>;\n /** Legacy alias for meta. */\n custom?: Record<string, string | number | boolean | null>;\n};\n\ntype ShipItUser = {\n key: string;\n email?: string;\n name?: string;\n country?: string;\n custom?: Record<string, string | number | boolean | null>;\n};\n\nexport type ShipItClientOptions = {\n apiBaseUrl: string;\n sdkKey?: string;\n projectKey?: string;\n envKey?: string;\n};\n\nexport class ShipItClient {\n private readonly apiBaseUrl: string;\n private readonly sdkKey: string | null;\n private readonly projectKey: string | null;\n private readonly envKey: string;\n\n constructor(options: ShipItClientOptions) {\n this.apiBaseUrl = options.apiBaseUrl.replace(/\\/$/, '');\n this.sdkKey = options.sdkKey?.trim() ? options.sdkKey.trim() : null;\n this.projectKey = options.projectKey?.trim() ? options.projectKey.trim() : null;\n this.envKey = options.envKey ?? 'production';\n\n if (!this.sdkKey && !this.projectKey) {\n throw new Error('ShipItClient requires either sdkKey (recommended) or projectKey (legacy).');\n }\n }\n\n private normalizeUser(input: ShipItUserPayload): ShipItUser {\n const key = (input.id ?? input.key ?? '').trim();\n if (!key) throw new Error('ShipItClient requires user.id (or legacy user.key).');\n return {\n key,\n email: input.email,\n name: input.name,\n country: input.country,\n custom: input.meta ?? input.custom\n };\n }\n\n async bool(flagKey: string, user: ShipItUserPayload, defaultValue = false): Promise<boolean> {\n const normalizedUser = this.normalizeUser(user);\n const res = this.sdkKey\n ? await fetch(`${this.apiBaseUrl}/api/v1/sdk/eval`, {\n method: 'POST',\n headers: {\n 'content-type': 'application/json',\n 'x-shipit-sdk-key': this.sdkKey\n },\n body: JSON.stringify({\n flagKey,\n user: normalizedUser,\n defaultValue\n })\n })\n : await fetch(`${this.apiBaseUrl}/api/v1/eval`, {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify({\n projectKey: this.projectKey,\n envKey: this.envKey,\n flagKey,\n user: normalizedUser,\n defaultValue\n })\n });\n\n if (!res.ok) return defaultValue;\n const json = (await res.json()) as { value: boolean };\n return json.value;\n }\n}\n"]}
@@ -0,0 +1,30 @@
1
+ type ShipItUserPayload = {
2
+ /** Unique user identifier (preferred). */
3
+ id?: string;
4
+ /** Legacy alias for id. */
5
+ key?: string;
6
+ email?: string;
7
+ name?: string;
8
+ country?: string;
9
+ /** Queryable attributes. */
10
+ meta?: Record<string, string | number | boolean | null>;
11
+ /** Legacy alias for meta. */
12
+ custom?: Record<string, string | number | boolean | null>;
13
+ };
14
+ type ShipItClientOptions = {
15
+ apiBaseUrl: string;
16
+ sdkKey?: string;
17
+ projectKey?: string;
18
+ envKey?: string;
19
+ };
20
+ declare class ShipItClient {
21
+ private readonly apiBaseUrl;
22
+ private readonly sdkKey;
23
+ private readonly projectKey;
24
+ private readonly envKey;
25
+ constructor(options: ShipItClientOptions);
26
+ private normalizeUser;
27
+ bool(flagKey: string, user: ShipItUserPayload, defaultValue?: boolean): Promise<boolean>;
28
+ }
29
+
30
+ export { ShipItClient, type ShipItClientOptions, type ShipItUserPayload };
@@ -0,0 +1,30 @@
1
+ type ShipItUserPayload = {
2
+ /** Unique user identifier (preferred). */
3
+ id?: string;
4
+ /** Legacy alias for id. */
5
+ key?: string;
6
+ email?: string;
7
+ name?: string;
8
+ country?: string;
9
+ /** Queryable attributes. */
10
+ meta?: Record<string, string | number | boolean | null>;
11
+ /** Legacy alias for meta. */
12
+ custom?: Record<string, string | number | boolean | null>;
13
+ };
14
+ type ShipItClientOptions = {
15
+ apiBaseUrl: string;
16
+ sdkKey?: string;
17
+ projectKey?: string;
18
+ envKey?: string;
19
+ };
20
+ declare class ShipItClient {
21
+ private readonly apiBaseUrl;
22
+ private readonly sdkKey;
23
+ private readonly projectKey;
24
+ private readonly envKey;
25
+ constructor(options: ShipItClientOptions);
26
+ private normalizeUser;
27
+ bool(flagKey: string, user: ShipItUserPayload, defaultValue?: boolean): Promise<boolean>;
28
+ }
29
+
30
+ export { ShipItClient, type ShipItClientOptions, type ShipItUserPayload };
package/dist/index.js ADDED
@@ -0,0 +1,59 @@
1
+ // src/index.ts
2
+ var ShipItClient = class {
3
+ apiBaseUrl;
4
+ sdkKey;
5
+ projectKey;
6
+ envKey;
7
+ constructor(options) {
8
+ this.apiBaseUrl = options.apiBaseUrl.replace(/\/$/, "");
9
+ this.sdkKey = options.sdkKey?.trim() ? options.sdkKey.trim() : null;
10
+ this.projectKey = options.projectKey?.trim() ? options.projectKey.trim() : null;
11
+ this.envKey = options.envKey ?? "production";
12
+ if (!this.sdkKey && !this.projectKey) {
13
+ throw new Error("ShipItClient requires either sdkKey (recommended) or projectKey (legacy).");
14
+ }
15
+ }
16
+ normalizeUser(input) {
17
+ const key = (input.id ?? input.key ?? "").trim();
18
+ if (!key) throw new Error("ShipItClient requires user.id (or legacy user.key).");
19
+ return {
20
+ key,
21
+ email: input.email,
22
+ name: input.name,
23
+ country: input.country,
24
+ custom: input.meta ?? input.custom
25
+ };
26
+ }
27
+ async bool(flagKey, user, defaultValue = false) {
28
+ const normalizedUser = this.normalizeUser(user);
29
+ const res = this.sdkKey ? await fetch(`${this.apiBaseUrl}/api/v1/sdk/eval`, {
30
+ method: "POST",
31
+ headers: {
32
+ "content-type": "application/json",
33
+ "x-shipit-sdk-key": this.sdkKey
34
+ },
35
+ body: JSON.stringify({
36
+ flagKey,
37
+ user: normalizedUser,
38
+ defaultValue
39
+ })
40
+ }) : await fetch(`${this.apiBaseUrl}/api/v1/eval`, {
41
+ method: "POST",
42
+ headers: { "content-type": "application/json" },
43
+ body: JSON.stringify({
44
+ projectKey: this.projectKey,
45
+ envKey: this.envKey,
46
+ flagKey,
47
+ user: normalizedUser,
48
+ defaultValue
49
+ })
50
+ });
51
+ if (!res.ok) return defaultValue;
52
+ const json = await res.json();
53
+ return json.value;
54
+ }
55
+ };
56
+
57
+ export { ShipItClient };
58
+ //# sourceMappingURL=index.js.map
59
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";AA6BO,IAAM,eAAN,MAAmB;AAAA,EACP,UAAA;AAAA,EACA,MAAA;AAAA,EACA,UAAA;AAAA,EACA,MAAA;AAAA,EAEj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AChD,MAAA,EAAQ,MAAA;AAAA,MACR,OAAA,EAAS;AAAA,QACP,cAAA,EAAgB,kBAAA;AAAA,QAChB,oBAAoB,IAAA,CAAK;AAAA,OAC3B;AAAA,MACA,IAAA,EAAM,KAAK,SAAA,CAAU;AAAA,QACnB,OAAA;AAAA,QACA,IAAA,EAAM,cAAA;AAAA,QACN;AAAA,OACD;AAAA,KACF,CAAA,GACD,MAAM,MAAM,CAAA,EAAG,IAAA,CAAK,UAAU,CAAA,YAAA,CAAA,EAAgB;AAAA,MAC5C,MAAA,EAAQ,MAAA;AAAA,MACR,OAAA,EAAS,EAAE,cAAA,EAAgB,kBAAA,EAAmB;AAAA,MAC9C,IAAA,EAAM,KAAK,SAAA,CAAU;AAAA,QACnB,YAAY,IAAA,CAAK,UAAA;AAAA,QACjB,QAAQ,IAAA,CAAK,MAAA;AAAA,QACb,OAAA;AAAA,QACA,IAAA,EAAM,cAAA;AAAA,QACN;AAAA,OACD;AAAA,KACF,CAAA;AAEL,IAAA,IAAI,CAAC,GAAA,CAAI,EAAA,EAAI,OAAO,YAAA;AACpB,IAAA,MAAM,IAAA,GAAQ,MAAM,GAAA,CAAI,IAAA,EAAK;AAC7B,IAAA,OAAO,IAAA,CAAK,KAAA;AAAA,EACd;AACF","file":"index.js","sourcesContent":["export type ShipItUserPayload = {\n /** Unique user identifier (preferred). */\n id?: string;\n /** Legacy alias for id. */\n key?: string;\n email?: string;\n name?: string;\n country?: string;\n /** Queryable attributes. */\n meta?: Record<string, string | number | boolean | null>;\n /** Legacy alias for meta. */\n custom?: Record<string, string | number | boolean | null>;\n};\n\ntype ShipItUser = {\n key: string;\n email?: string;\n name?: string;\n country?: string;\n custom?: Record<string, string | number | boolean | null>;\n};\n\nexport type ShipItClientOptions = {\n apiBaseUrl: string;\n sdkKey?: string;\n projectKey?: string;\n envKey?: string;\n};\n\nexport class ShipItClient {\n private readonly apiBaseUrl: string;\n private readonly sdkKey: string | null;\n private readonly projectKey: string | null;\n private readonly envKey: string;\n\n constructor(options: ShipItClientOptions) {\n this.apiBaseUrl = options.apiBaseUrl.replace(/\\/$/, '');\n this.sdkKey = options.sdkKey?.trim() ? options.sdkKey.trim() : null;\n this.projectKey = options.projectKey?.trim() ? options.projectKey.trim() : null;\n this.envKey = options.envKey ?? 'production';\n\n if (!this.sdkKey && !this.projectKey) {\n throw new Error('ShipItClient requires either sdkKey (recommended) or projectKey (legacy).');\n }\n }\n\n private normalizeUser(input: ShipItUserPayload): ShipItUser {\n const key = (input.id ?? input.key ?? '').trim();\n if (!key) throw new Error('ShipItClient requires user.id (or legacy user.key).');\n return {\n key,\n email: input.email,\n name: input.name,\n country: input.country,\n custom: input.meta ?? input.custom\n };\n }\n\n async bool(flagKey: string, user: ShipItUserPayload, defaultValue = false): Promise<boolean> {\n const normalizedUser = this.normalizeUser(user);\n const res = this.sdkKey\n ? await fetch(`${this.apiBaseUrl}/api/v1/sdk/eval`, {\n method: 'POST',\n headers: {\n 'content-type': 'application/json',\n 'x-shipit-sdk-key': this.sdkKey\n },\n body: JSON.stringify({\n flagKey,\n user: normalizedUser,\n defaultValue\n })\n })\n : await fetch(`${this.apiBaseUrl}/api/v1/eval`, {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify({\n projectKey: this.projectKey,\n envKey: this.envKey,\n flagKey,\n user: normalizedUser,\n defaultValue\n })\n });\n\n if (!res.ok) return defaultValue;\n const json = (await res.json()) as { value: boolean };\n return json.value;\n }\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@jsontech/sdk-js",
3
+ "version": "0.0.1",
4
+ "private": false,
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "type": "module",
9
+ "main": "./dist/index.cjs",
10
+ "module": "./dist/index.js",
11
+ "types": "./dist/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.js",
16
+ "require": "./dist/index.cjs"
17
+ }
18
+ },
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "sideEffects": false,
23
+ "scripts": {
24
+ "dev": "tsup --watch",
25
+ "build": "tsup",
26
+ "typecheck": "tsc -p tsconfig.json --noEmit",
27
+ "lint": "eslint .",
28
+ "format": "prettier -w ."
29
+ },
30
+ "dependencies": {},
31
+ "devDependencies": {
32
+ "@types/node": "^22.10.2",
33
+ "eslint": "^9.16.0",
34
+ "prettier": "^3.4.2",
35
+ "tsup": "^8.3.5",
36
+ "typescript": "^5.7.2",
37
+ "typescript-eslint": "^8.17.0"
38
+ }
39
+ }