swcombine.js 0.0.10 → 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.
Files changed (51) hide show
  1. package/LICENSE +5 -17
  2. package/README.md +668 -97
  3. package/dist/index.d.ts +5 -510
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +3 -0
  6. package/dist/index.js.map +23 -0
  7. package/dist/src/auth/index.d.ts +8 -0
  8. package/dist/src/auth/index.d.ts.map +1 -0
  9. package/dist/src/auth/oauth-manager.d.ts +168 -0
  10. package/dist/src/auth/oauth-manager.d.ts.map +1 -0
  11. package/dist/src/auth/oauth.d.ts +101 -0
  12. package/dist/src/auth/oauth.d.ts.map +1 -0
  13. package/dist/src/auth/scopes.d.ts +61 -0
  14. package/dist/src/auth/scopes.d.ts.map +1 -0
  15. package/dist/src/auth/types.d.ts +118 -0
  16. package/dist/src/auth/types.d.ts.map +1 -0
  17. package/dist/src/client/base-resource.d.ts +33 -0
  18. package/dist/src/client/base-resource.d.ts.map +1 -0
  19. package/dist/src/client/client.d.ts +85 -0
  20. package/dist/src/client/client.d.ts.map +1 -0
  21. package/dist/src/client/errors.d.ts +63 -0
  22. package/dist/src/client/errors.d.ts.map +1 -0
  23. package/dist/src/client/http-client.d.ts +35 -0
  24. package/dist/src/client/http-client.d.ts.map +1 -0
  25. package/dist/src/client/index.d.ts +15 -0
  26. package/dist/src/client/index.d.ts.map +1 -0
  27. package/dist/src/client/rate-limit.d.ts +12 -0
  28. package/dist/src/client/rate-limit.d.ts.map +1 -0
  29. package/dist/src/client/resources/api.d.ts +42 -0
  30. package/dist/src/client/resources/api.d.ts.map +1 -0
  31. package/dist/src/client/resources/character.d.ts +98 -0
  32. package/dist/src/client/resources/character.d.ts.map +1 -0
  33. package/dist/src/client/resources/faction.d.ts +70 -0
  34. package/dist/src/client/resources/faction.d.ts.map +1 -0
  35. package/dist/src/client/resources/index.d.ts +8 -0
  36. package/dist/src/client/resources/index.d.ts.map +1 -0
  37. package/dist/src/client/resources/inventory.d.ts +205 -0
  38. package/dist/src/client/resources/inventory.d.ts.map +1 -0
  39. package/dist/src/client/types.d.ts +78 -0
  40. package/dist/src/client/types.d.ts.map +1 -0
  41. package/dist/src/index.d.ts +11 -0
  42. package/dist/src/index.d.ts.map +1 -0
  43. package/dist/src/utils/index.d.ts +6 -0
  44. package/dist/src/utils/index.d.ts.map +1 -0
  45. package/dist/src/utils/timestamp.d.ts +188 -0
  46. package/dist/src/utils/timestamp.d.ts.map +1 -0
  47. package/dist/src/utils/types.d.ts +42 -0
  48. package/dist/src/utils/types.d.ts.map +1 -0
  49. package/package.json +35 -55
  50. package/dist/index.cjs.js +0 -704
  51. package/dist/index.esm.js +0 -704
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Utility functions and classes
3
+ */
4
+ export { Timestamp } from "./timestamp.ts";
5
+ export type { TimestampMoment, Duration, TimestampFormat, TimestampUnit, } from "./types.ts";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG3C,YAAY,EACV,eAAe,EACf,QAAQ,EACR,eAAe,EACf,aAAa,GACd,MAAM,YAAY,CAAC"}
@@ -0,0 +1,188 @@
1
+ /**
2
+ * Timestamp utility for working with Star Wars Combine Combine Galactic Time (CGT)
3
+ */
4
+ import type { TimestampMoment, Duration, TimestampFormat, TimestampUnit } from "./types.ts";
5
+ /**
6
+ * Utility class for working with Star Wars Combine timestamps.
7
+ * Represents Combine Galactic Time and can convert unix timestamps
8
+ * and Date objects to/from CGT.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * // Get current CGT
13
+ * const now = Timestamp.now();
14
+ *
15
+ * // Create from Unix timestamp
16
+ * const ts = Timestamp.fromUnixTimestamp(1735920000);
17
+ *
18
+ * // Create from Date
19
+ * const ts2 = Timestamp.fromDate(new Date());
20
+ *
21
+ * // Create specific moment
22
+ * const ts3 = new Timestamp({ year: 25, day: 60, hour: 12 });
23
+ *
24
+ * // Format as string
25
+ * console.log(now.toString("full")); // "Year 27 Day 134, 8:45:23"
26
+ * ```
27
+ */
28
+ export declare class Timestamp {
29
+ /**
30
+ * SWC start date (December 3, 1998 at 07:00:00 UTC)
31
+ */
32
+ private static readonly swcStart;
33
+ protected year: number;
34
+ protected day: number;
35
+ protected hour: number;
36
+ protected minute: number;
37
+ protected second: number;
38
+ /**
39
+ * Create a new Timestamp object for a specific moment in Combine Galactic Time
40
+ *
41
+ * @param source - Moment in CGT (year, day, and optionally hour, minute, second)
42
+ */
43
+ constructor(source: TimestampMoment);
44
+ /**
45
+ * Convert a unix timestamp to Combine Galactic Time
46
+ *
47
+ * @param unixTimestamp - Unix timestamp (seconds or milliseconds, auto-detected)
48
+ * @returns Timestamp instance representing the CGT moment
49
+ */
50
+ static fromUnixTimestamp(unixTimestamp: number): Timestamp;
51
+ /**
52
+ * Convert a Date object into Combine Galactic Time
53
+ *
54
+ * @param date - JavaScript Date object
55
+ * @returns Timestamp instance representing the CGT moment
56
+ */
57
+ static fromDate(date: Date): Timestamp;
58
+ /**
59
+ * Get the current Combine Galactic Time
60
+ *
61
+ * @returns Timestamp instance representing the current CGT moment
62
+ */
63
+ static now(): Timestamp;
64
+ /**
65
+ * Calculate CGT from milliseconds since SWC start
66
+ *
67
+ * @param msSinceSwcStart - Milliseconds since SWC start date
68
+ * @returns Timestamp instance
69
+ */
70
+ private static calculateTimestampFromMillisecondsSinceStart;
71
+ /**
72
+ * Convert the CGT timestamp into a unix timestamp
73
+ *
74
+ * @param unit - Output unit (seconds or milliseconds)
75
+ * @returns Unix timestamp
76
+ */
77
+ toUnixTimestamp(unit: TimestampUnit): number;
78
+ /**
79
+ * Convert the CGT timestamp into a Date object
80
+ *
81
+ * @returns JavaScript Date object
82
+ */
83
+ toDate(): Date;
84
+ /**
85
+ * Get the timestamp as a TimestampMoment object
86
+ *
87
+ * @returns TimestampMoment representation
88
+ */
89
+ asMoment(): TimestampMoment;
90
+ /**
91
+ * Get the year component
92
+ *
93
+ * @returns Year in CGT
94
+ */
95
+ getYear(): number;
96
+ /**
97
+ * Get the day component
98
+ *
99
+ * @returns Day of the year (1-365)
100
+ */
101
+ getDay(): number;
102
+ /**
103
+ * Get the hour component
104
+ *
105
+ * @returns Hour of the day (0-23)
106
+ */
107
+ getHour(): number;
108
+ /**
109
+ * Get the minute component
110
+ *
111
+ * @returns Minute of the hour (0-59)
112
+ */
113
+ getMinute(): number;
114
+ /**
115
+ * Get the second component
116
+ *
117
+ * @returns Second of the minute (0-59)
118
+ */
119
+ getSecond(): number;
120
+ /**
121
+ * Calculate a new timestamp by adding time to this timestamp
122
+ *
123
+ * @param duration - Duration to add (partial duration allowed)
124
+ * @returns New Timestamp with added duration
125
+ */
126
+ add(duration: Partial<Duration>): Timestamp;
127
+ /**
128
+ * Calculate a new timestamp by subtracting time from this timestamp
129
+ *
130
+ * @param duration - Duration to subtract (partial duration allowed)
131
+ * @returns New Timestamp with subtracted duration (won't go before SWC start)
132
+ */
133
+ subtract(duration: Partial<Duration>): Timestamp;
134
+ /**
135
+ * Calculate the duration from this timestamp to another timestamp
136
+ *
137
+ * @param otherTimestamp - Target timestamp
138
+ * @returns Duration between timestamps (positive if other is in future)
139
+ */
140
+ getDurationTo(otherTimestamp: Timestamp): Duration;
141
+ /**
142
+ * Convert the CGT timestamp to a string
143
+ *
144
+ * You can either pass in a preset name, or a custom format string.
145
+ *
146
+ * **Preset formats:**
147
+ * - `'full'`: Year 25 Day 60, 6:03:12
148
+ * - `'minute'`: Year 25 Day 60, 6:03
149
+ * - `'day'`: Year 25 Day 60
150
+ * - `'shortFull'`: Y25 D60, 6:03:12
151
+ * - `'shortMinute'`: Y25 D60, 6:03
152
+ * - `'shortDay'`: Y26 D60
153
+ *
154
+ * **Custom format tags:**
155
+ * - `{y}`: year
156
+ * - `{d}`: day
157
+ * - `{h}`: hour
158
+ * - `{m}`: minute
159
+ * - `{s}`: second
160
+ * - Double the tag for leading zeroes (e.g., `{hh}` = 08)
161
+ * - `{hms}`: shorthand for `{hh}:{mm}:{ss}`
162
+ *
163
+ * @param format - Preset format name or custom format string
164
+ * @returns Formatted timestamp string
165
+ *
166
+ * @example
167
+ * ```typescript
168
+ * const ts = new Timestamp({ year: 25, day: 6, hour: 8, minute: 12, second: 14 });
169
+ * ts.toString("full"); // "Year 25 Day 6, 8:12:14"
170
+ * ts.toString("{hms} on Day {d} of Year {y}"); // "08:12:14 on Day 6 of Year 25"
171
+ * ```
172
+ */
173
+ toString(format?: TimestampFormat | string): string;
174
+ /**
175
+ * Substitute a format tag with its value
176
+ *
177
+ * @param tag - Format tag (e.g., "y", "yy", "hms")
178
+ * @returns Substituted value
179
+ */
180
+ private substituteTag;
181
+ /**
182
+ * Calculate milliseconds since SWC start from this timestamp
183
+ *
184
+ * @returns Milliseconds since SWC start date
185
+ */
186
+ private calculateMillisecondsSinceStartFromTimestamp;
187
+ }
188
+ //# sourceMappingURL=timestamp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timestamp.d.ts","sourceRoot":"","sources":["../../../src/utils/timestamp.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,eAAe,EACf,QAAQ,EACR,eAAe,EACf,aAAa,EACd,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,SAAS;IACpB;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAA4C;IAE5E,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,GAAG,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,MAAM,EAAE,MAAM,CA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: number;
10
+ /** Day of the year (1-365) */
11
+ day: number;
12
+ /** Hour of the day (0-23) */
13
+ hour?: number;
14
+ /** Minute of the hour (0-59) */
15
+ minute?: number;
16
+ /** Second of the minute (0-59) */
17
+ second?: number;
18
+ }
19
+ /**
20
+ * Duration between two timestamps
21
+ */
22
+ export interface Duration {
23
+ /** Number of years */
24
+ years: number;
25
+ /** Number of days */
26
+ days: number;
27
+ /** Number of hours */
28
+ hours: number;
29
+ /** Number of minutes */
30
+ minutes: number;
31
+ /** Number of seconds */
32
+ seconds: number;
33
+ }
34
+ /**
35
+ * Timestamp format presets
36
+ */
37
+ export type TimestampFormat = "full" | "minute" | "day" | "shortFull" | "shortMinute" | "shortDay";
38
+ /**
39
+ * Unix timestamp units
40
+ */
41
+ export type TimestampUnit = "sec" | "ms" | "seconds" | "milliseconds";
42
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/utils/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,kBAAkB;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,8BAA8B;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,6BAA6B;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,gCAAgC;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kCAAkC;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,sBAAsB;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,qBAAqB;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,sBAAsB;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,wBAAwB;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,wBAAwB;IACxB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,GACvB,MAAM,GACN,QAAQ,GACR,KAAK,GACL,WAAW,GACX,aAAa,GACb,UAAU,CAAC;AAEf;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,IAAI,GAAG,SAAS,GAAG,cAAc,CAAC"}
package/package.json CHANGED
@@ -1,74 +1,54 @@
1
1
  {
2
2
  "name": "swcombine.js",
3
- "version": "0.0.10",
4
- "description": "",
5
- "keywords": [
6
- "swcombine",
7
- "sdk"
8
- ],
3
+ "version": "0.1.0",
4
+ "description": "TypeScript SDK for the Star Wars Combine API",
5
+ "author": "Your Name",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "main": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
9
10
  "exports": {
10
11
  ".": {
11
- "import": {
12
- "default": "./dist/index.esm.js",
13
- "types": "./dist/index.d.ts"
14
- },
15
- "require": {
16
- "default": "./dist/index.cjs.js",
17
- "types": "./dist/index.d.ts"
18
- }
12
+ "import": "./dist/index.js",
13
+ "types": "./dist/index.d.ts"
19
14
  }
20
15
  },
21
- "type": "module",
22
- "types": "./dist/index.d.ts",
23
- "module": "./dist/index.esm.js",
24
16
  "files": [
25
- "dist"
17
+ "dist",
18
+ "README.md",
19
+ "LICENSE"
26
20
  ],
27
- "contributors": [
28
- {
29
- "name": "kaelon",
30
- "email": "j.dekoning141@gmail.com"
31
- },
32
- {
33
- "name": "karnthis",
34
- "email": "me@erinrivas.com"
35
- }
21
+ "keywords": [
22
+ "swc",
23
+ "star-wars-combine",
24
+ "api",
25
+ "sdk",
26
+ "typescript",
27
+ "oauth",
28
+ "oauth2"
36
29
  ],
37
- "license": "MIT",
38
30
  "repository": {
39
31
  "type": "git",
40
- "url": "git+https://github.com/swc-unnamed/swcombine-js.git"
32
+ "url": "https://github.com/swc-unnamed/swcombine-js"
41
33
  },
42
34
  "bugs": {
43
35
  "url": "https://github.com/swc-unnamed/swcombine-js/issues"
44
36
  },
45
- "homepage": "https://github.com/swc-unnamed/swcombine-js/#README",
37
+ "homepage": "https://github.com/swc-unnamed/swcombine-js#readme",
38
+ "scripts": {
39
+ "test": "bun test",
40
+ "build": "bun run build:clean && bun run build:types && bun run build:bundle",
41
+ "build:clean": "rm -rf dist",
42
+ "build:types": "tsc --project tsconfig.build.json --emitDeclarationOnly",
43
+ "build:bundle": "bun build index.ts --outdir dist --target node --format esm --minify --sourcemap=external",
44
+ "prepublishOnly": "bun run build",
45
+ "example:oauth": "bun run examples/oauth-flow.ts"
46
+ },
46
47
  "devDependencies": {
47
- "@eslint/js": "^9.19.0",
48
- "@rollup/plugin-commonjs": "^28.0.2",
49
- "@rollup/plugin-typescript": "^12.1.2",
50
- "@types/node": "^22.13.0",
51
- "@vitest/coverage-v8": "^3.0.4",
52
- "eslint": "^9.19.0",
53
- "eslint-config-prettier": "^10.0.1",
54
- "eslint-plugin-prettier": "^5.2.3",
55
- "jiti": "^2.4.2",
56
- "prettier": "^3.4.2",
57
- "rollup-plugin-node-externals": "^8.0.0",
58
- "rollup-plugin-typescript-paths": "^1.5.0",
59
- "tslib": "^2.8.1",
60
- "typedoc": "^0.27.6",
61
- "typescript": "^5.7.3",
62
- "typescript-eslint": "^8.22.0",
63
- "vite": "^6.0.11",
64
- "vite-plugin-dts": "^4.5.0",
65
- "vite-tsconfig-paths": "^5.1.4",
66
- "vitest": "^3.0.4"
48
+ "@types/bun": "latest",
49
+ "typescript": "^5"
67
50
  },
68
- "scripts": {
69
- "build": "tsc && vite build",
70
- "packit": "npm run build && npm pack --pack-destination packs",
71
- "gen-docs": "npx typedoc",
72
- "test": "vitest"
51
+ "engines": {
52
+ "node": ">=18"
73
53
  }
74
54
  }