getta 0.4.7 → 1.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.
Files changed (104) hide show
  1. package/README.md +161 -7
  2. package/dist/main/index.mjs +621 -0
  3. package/dist/main/index.mjs.map +1 -0
  4. package/dist/tsconfig.build.tsbuildinfo +1 -0
  5. package/{lib → dist}/types/constants.d.ts +2 -2
  6. package/dist/types/constants.d.ts.map +1 -0
  7. package/dist/types/helpers/buildEndpoint/index.d.ts +3 -0
  8. package/dist/types/helpers/buildEndpoint/index.d.ts.map +1 -0
  9. package/{lib/types/helpers/build-endpoint → dist/types/helpers/buildEndpoint}/types.d.ts +2 -2
  10. package/dist/types/helpers/buildEndpoint/types.d.ts.map +1 -0
  11. package/dist/types/helpers/defaultPathTemplateCallback/index.d.ts +2 -0
  12. package/dist/types/helpers/defaultPathTemplateCallback/index.d.ts.map +1 -0
  13. package/dist/types/helpers/delay/index.d.ts +2 -0
  14. package/{lib → dist}/types/helpers/delay/index.d.ts.map +1 -1
  15. package/dist/types/helpers/getResponseGroup/index.d.ts +2 -0
  16. package/dist/types/helpers/getResponseGroup/index.d.ts.map +1 -0
  17. package/dist/types/helpers/isCacheabilityValid/index.d.ts +3 -0
  18. package/dist/types/helpers/isCacheabilityValid/index.d.ts.map +1 -0
  19. package/dist/types/index.d.ts +5 -0
  20. package/dist/types/index.d.ts.map +1 -0
  21. package/{lib → dist}/types/main.d.ts +12 -12
  22. package/dist/types/main.d.ts.map +1 -0
  23. package/dist/types/types.d.ts +161 -0
  24. package/dist/types/types.d.ts.map +1 -0
  25. package/package.json +113 -145
  26. package/src/{__tests__ → __testUtils__}/data/136-7317.json +1 -1
  27. package/src/{__tests__ → __testUtils__}/data/180-1387.json +1 -1
  28. package/src/{__tests__ → __testUtils__}/data/183-3905.json +1 -1
  29. package/src/{__tests__ → __testUtils__}/data/202-3315.json +1 -1
  30. package/src/__testUtils__/data/index.ts +23 -0
  31. package/src/__testUtils__/helpers/index.ts +49 -0
  32. package/src/constants.ts +28 -28
  33. package/src/helpers/buildEndpoint/index.ts +34 -0
  34. package/src/helpers/{build-endpoint → buildEndpoint}/types.ts +2 -2
  35. package/src/helpers/defaultPathTemplateCallback/index.test.ts +11 -0
  36. package/src/helpers/defaultPathTemplateCallback/index.ts +17 -0
  37. package/src/helpers/delay/index.ts +2 -2
  38. package/src/helpers/getResponseGroup/index.ts +25 -0
  39. package/src/helpers/isCacheabilityValid/index.ts +6 -0
  40. package/src/index.ts +4 -4
  41. package/src/main.test.ts +283 -411
  42. package/src/main.ts +238 -241
  43. package/src/types.ts +114 -16
  44. package/tsconfig.build.json +14 -0
  45. package/tsconfig.json +9 -0
  46. package/CHANGELOG.md +0 -250
  47. package/jest.setup.js +0 -10
  48. package/lib/browser/index.js +0 -2
  49. package/lib/browser/index.js.map +0 -1
  50. package/lib/browser/production.analysis.txt +0 -91
  51. package/lib/main/constants.js +0 -97
  52. package/lib/main/helpers/build-endpoint/index.js +0 -38
  53. package/lib/main/helpers/build-endpoint/types.js +0 -1
  54. package/lib/main/helpers/default-path-template-callback/index.js +0 -16
  55. package/lib/main/helpers/delay/index.js +0 -12
  56. package/lib/main/helpers/get-response-group/index.js +0 -27
  57. package/lib/main/helpers/is-cacheability-valid/index.js +0 -13
  58. package/lib/main/index.js +0 -62
  59. package/lib/main/main.js +0 -580
  60. package/lib/main/types.js +0 -1
  61. package/lib/module/constants.mjs +0 -49
  62. package/lib/module/helpers/build-endpoint/index.mjs +0 -28
  63. package/lib/module/helpers/build-endpoint/types.mjs +0 -0
  64. package/lib/module/helpers/default-path-template-callback/index.mjs +0 -9
  65. package/lib/module/helpers/delay/index.mjs +0 -4
  66. package/lib/module/helpers/get-response-group/index.mjs +0 -19
  67. package/lib/module/helpers/is-cacheability-valid/index.mjs +0 -6
  68. package/lib/module/index.mjs +0 -4
  69. package/lib/module/main.mjs +0 -576
  70. package/lib/module/types.mjs +0 -0
  71. package/lib/types/__tests__/data/index.d.ts +0 -17
  72. package/lib/types/__tests__/data/index.d.ts.map +0 -1
  73. package/lib/types/__tests__/helpers/index.d.ts +0 -29
  74. package/lib/types/__tests__/helpers/index.d.ts.map +0 -1
  75. package/lib/types/__tests__/types.d.ts +0 -13
  76. package/lib/types/__tests__/types.d.ts.map +0 -1
  77. package/lib/types/constants.d.ts.map +0 -1
  78. package/lib/types/helpers/build-endpoint/index.d.ts +0 -3
  79. package/lib/types/helpers/build-endpoint/index.d.ts.map +0 -1
  80. package/lib/types/helpers/build-endpoint/types.d.ts.map +0 -1
  81. package/lib/types/helpers/default-path-template-callback/index.d.ts +0 -3
  82. package/lib/types/helpers/default-path-template-callback/index.d.ts.map +0 -1
  83. package/lib/types/helpers/default-path-template-callback/index.test.d.ts +0 -2
  84. package/lib/types/helpers/default-path-template-callback/index.test.d.ts.map +0 -1
  85. package/lib/types/helpers/delay/index.d.ts +0 -2
  86. package/lib/types/helpers/get-response-group/index.d.ts +0 -2
  87. package/lib/types/helpers/get-response-group/index.d.ts.map +0 -1
  88. package/lib/types/helpers/is-cacheability-valid/index.d.ts +0 -3
  89. package/lib/types/helpers/is-cacheability-valid/index.d.ts.map +0 -1
  90. package/lib/types/index.d.ts +0 -5
  91. package/lib/types/index.d.ts.map +0 -1
  92. package/lib/types/main.d.ts.map +0 -1
  93. package/lib/types/main.test.d.ts +0 -2
  94. package/lib/types/main.test.d.ts.map +0 -1
  95. package/lib/types/types.d.ts +0 -69
  96. package/lib/types/types.d.ts.map +0 -1
  97. package/src/__tests__/data/index.ts +0 -19
  98. package/src/__tests__/helpers/index.ts +0 -61
  99. package/src/__tests__/types.ts +0 -14
  100. package/src/helpers/build-endpoint/index.ts +0 -34
  101. package/src/helpers/default-path-template-callback/index.test.ts +0 -11
  102. package/src/helpers/default-path-template-callback/index.ts +0 -16
  103. package/src/helpers/get-response-group/index.ts +0 -22
  104. package/src/helpers/is-cacheability-valid/index.ts +0 -6
@@ -1,7 +1,6 @@
1
- import Cachemap from "@cachemap/core";
2
- import { PlainObject } from "@repodog/types";
3
- import { Required } from "utility-types";
4
- import { ConstructorOptions, FetchResponse, RequestOptions, ShortcutProperties, Shortcuts } from "./types";
1
+ import { type Core } from '@cachemap/core';
2
+ import type { SetRequired } from 'type-fest';
3
+ import { type ConstructorOptions, type Context, type FetchResponse, type PlainObject, type RequestOptions, type ShortcutProperties, type Shortcuts } from './types.ts';
5
4
  export declare class Getta {
6
5
  private _basePath;
7
6
  private _bodyParser;
@@ -17,6 +16,7 @@ export declare class Getta {
17
16
  private _pathTemplateRegExp;
18
17
  private _performance;
19
18
  private _queryParams;
19
+ private _rateLimit;
20
20
  private _rateLimitCount;
21
21
  private _rateLimitedRequestQueue;
22
22
  private _rateLimitPerSecond;
@@ -25,15 +25,15 @@ export declare class Getta {
25
25
  private _requestTracker;
26
26
  private _streamReader;
27
27
  constructor(options: ConstructorOptions);
28
- get cache(): Cachemap | undefined;
29
- createShortcut(name: string, path: string, { method, ...otherOptions }: Required<RequestOptions, "method">): void;
30
- delete(path: string, options?: Omit<RequestOptions, "method">, context?: PlainObject): Promise<FetchResponse<PlainObject>>;
31
- get(path: string, options?: Omit<RequestOptions, "method">, context?: PlainObject): Promise<FetchResponse<PlainObject> | {
28
+ get cache(): Core | undefined;
29
+ createShortcut(name: string, path: string, { method, ...otherOptions }: SetRequired<RequestOptions, 'method'>): void;
30
+ delete(path: string, options?: Omit<RequestOptions, 'method'>, context?: Context): Promise<FetchResponse<PlainObject>>;
31
+ get(path: string, options?: Omit<RequestOptions, 'method'>, context?: Context): Promise<FetchResponse<PlainObject> | {
32
32
  data: PlainObject | undefined;
33
33
  headers: Headers;
34
34
  }>;
35
- post(path: string, options: Omit<Required<RequestOptions, "body">, "method">, context?: PlainObject): Promise<FetchResponse<PlainObject>>;
36
- put(path: string, options: Omit<Required<RequestOptions, "body">, "methood">, context?: PlainObject): Promise<FetchResponse<PlainObject>>;
35
+ post(path: string, options: Omit<SetRequired<RequestOptions, 'body'>, 'method'>, context?: Context): Promise<FetchResponse<PlainObject>>;
36
+ put(path: string, options: Omit<SetRequired<RequestOptions, 'body'>, 'methood'>, context?: Context): Promise<FetchResponse<PlainObject>>;
37
37
  private _addRequestToRateLimitedQueue;
38
38
  private _cacheEntryDelete;
39
39
  private _cacheEntryGet;
@@ -46,12 +46,12 @@ export declare class Getta {
46
46
  private _get;
47
47
  private _getResolve;
48
48
  private _logResponse;
49
- private _rateLimit;
50
49
  private _releaseRateLimitedRequestQueue;
51
50
  private _request;
52
51
  private _resolvePendingRequests;
53
52
  private _setPendingRequest;
53
+ private _startRateLimit;
54
54
  private _trackRequest;
55
55
  }
56
- export declare const createRestClient: <N extends string>(options: ConstructorOptions, shortcuts?: Shortcuts | undefined) => Getta & ShortcutProperties<N>;
56
+ export declare const createRestClient: <N extends string>(options: ConstructorOptions, shortcuts?: Shortcuts) => Getta & ShortcutProperties<N>;
57
57
  //# sourceMappingURL=main.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/main.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAI9D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAO7C,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,OAAO,EAGZ,KAAK,aAAa,EAOlB,KAAK,WAAW,EAChB,KAAK,cAAc,EAGnB,KAAK,kBAAkB,EACvB,KAAK,SAAS,EAEf,MAAM,YAAY,CAAC;AAEpB,qBAAa,KAAK;IAChB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,WAAW,CAAO;IAC1B,OAAO,CAAC,MAAM,CAAC,CAAO;IACtB,OAAO,CAAC,2BAA2B,CAAU;IAC7C,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAyB;IACzC,OAAO,CAAC,IAAI,CAAkB;IAC9B,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,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C,6BAA6B;YAMvB,iBAAiB;YAQjB,cAAc;YAQd,cAAc;YAYd,cAAc;YAQd,OAAO;YA+BP,MAAM;YA6FN,qBAAqB;YAmBrB,kBAAkB;YAclB,IAAI;YAyCJ,WAAW;IAoCzB,OAAO,CAAC,YAAY;YAsBN,+BAA+B;YAQ/B,QAAQ;IAyBtB,OAAO,CAAC,uBAAuB;IAc/B,OAAO,CAAC,kBAAkB;IAO1B,OAAO,CAAC,eAAe;IAevB,OAAO,CAAC,aAAa;CAUtB;AAED,eAAO,MAAM,gBAAgB,8BAA+B,kBAAkB,cAAc,SAAS,kCAgBpG,CAAC"}
@@ -0,0 +1,161 @@
1
+ import { type Core } from '@cachemap/core';
2
+ import type { SetRequired } from 'type-fest';
3
+ export type PlainObject = Record<string, any>;
4
+ export type Func = (...args: any[]) => any;
5
+ export type FetchMethod = 'get' | 'post' | 'put' | 'delete';
6
+ export type StreamReader = 'arrayBuffer' | 'blob' | 'formData' | 'json' | 'text';
7
+ export type ShortcutProperties<T extends string | number> = {
8
+ [K in T]: <Resource = PlainObject>(...args: any[]) => Promise<FetchResponse<Resource>>;
9
+ };
10
+ export interface ConstructorOptions {
11
+ /**
12
+ * The base path of the url for all requests made from
13
+ * an instance of the rest client, i.e. https://www.example.com/api.
14
+ */
15
+ basePath: string;
16
+ /**
17
+ * An optional callback to pass each response body through after
18
+ * it has been parsed by the stream reader.
19
+ */
20
+ bodyParser?: Func;
21
+ /**
22
+ * An instance of the @cachemap/core cache for caching responses
23
+ * against the request. Caching is only enabled on GET requests.
24
+ * For more info on @cachemap/core see https://github.com/badbatch/cachemap.
25
+ */
26
+ cache?: Core;
27
+ /**
28
+ * Enables conditional requests with If-None-Match header.
29
+ * Default is true
30
+ */
31
+ enableConditionalRequests?: boolean;
32
+ /**
33
+ * How long to wait for a request to respond before timing out
34
+ * and returning an error.
35
+ * Default is 5000
36
+ */
37
+ fetchTimeout?: number;
38
+ /**
39
+ * Any headers to attach to every request.
40
+ */
41
+ headers?: Record<string, string>;
42
+ /**
43
+ * Log function to pass rest client logs to a logger.
44
+ */
45
+ log?: Log;
46
+ /**
47
+ * The maximum number of times a request can redirect before
48
+ * the rest client returns an error.
49
+ * Default is 5
50
+ */
51
+ maxRedirects?: number;
52
+ /**
53
+ * The maximum number of times a request can retry before
54
+ * the rest client returns an error.
55
+ * Default is 3
56
+ */
57
+ maxRetries?: number;
58
+ /**
59
+ * An optional path template regex that can be used to clean up
60
+ * the template url.
61
+ * Default is /({\w+\?})/g
62
+ */
63
+ optionalPathTemplateRegExp?: RegExp;
64
+ /**
65
+ * A callback that takes the path template, the data to be injected into
66
+ * the template, and the path template regex, and returns the templated url.
67
+ * There is a default template callback that will cater to most needs.
68
+ */
69
+ pathTemplateCallback?: PathTemplateCallback;
70
+ /**
71
+ * A regex to tell the rest client where to inject data into the
72
+ * template. There is a default one that will cater to most needs.
73
+ */
74
+ pathTemplateRegExp?: RegExp;
75
+ /**
76
+ * The performance module to use for recording request
77
+ * durations.
78
+ */
79
+ performance: Performance;
80
+ /**
81
+ * Any query params to attach to every request.
82
+ */
83
+ queryParams?: PlainObject;
84
+ /**
85
+ * Whether to enable the rate limit feature.
86
+ */
87
+ rateLimit?: boolean;
88
+ /**
89
+ * How many requests per second to throttle the rest client.
90
+ * Default is 50
91
+ */
92
+ rateLimitPerSecond?: number;
93
+ /**
94
+ * How many milliseconds to wait before retrying a request.
95
+ * Default is 100
96
+ */
97
+ requestRetryWait?: number;
98
+ /**
99
+ * The stream reader to use when parsing the response body.
100
+ * Default is 'json'
101
+ */
102
+ streamReader?: StreamReader;
103
+ }
104
+ export interface FetchOptions {
105
+ body?: BodyInit;
106
+ headers: Record<string, string>;
107
+ method: FetchMethod;
108
+ redirects?: number;
109
+ retries?: number;
110
+ }
111
+ export interface FetchResponse<Resource = PlainObject> extends ResponseDataWithErrors<Resource>, Response {
112
+ }
113
+ export interface FetchRedirectHandlerOptions extends FetchOptions {
114
+ status: number;
115
+ }
116
+ export type Log = (message: string, data: PlainObject, logLevel?: LogLevel) => void;
117
+ export type LogLevel = 'error' | 'warn' | 'info' | 'http' | 'verbose' | 'debug' | 'silly';
118
+ export interface Performance {
119
+ now(): number;
120
+ }
121
+ export interface RequestOptions {
122
+ /**
123
+ * For POST and PUT methods, the body to send with the request.
124
+ */
125
+ body?: BodyInit;
126
+ /**
127
+ * Any headers to attach to the request.
128
+ */
129
+ headers?: Record<string, string>;
130
+ /**
131
+ * The fetch method.
132
+ */
133
+ method?: FetchMethod;
134
+ /**
135
+ * Data to be injected into the path template.
136
+ */
137
+ pathTemplateData?: Record<string, string>;
138
+ /**
139
+ * Any query params to attach to the request.
140
+ */
141
+ queryParams?: PlainObject;
142
+ }
143
+ export type RequestQueue = [(value: FetchResponse) => void, string, FetchOptions, PlainObject][];
144
+ export interface ResponseDataWithErrors<Resource = PlainObject> {
145
+ data?: Resource;
146
+ errors?: Error[];
147
+ }
148
+ export type PathTemplateCallback = (path: string, data: Record<string, string>, pathTemplateRegExp: RegExp) => string;
149
+ export type PendingRequestResolver = (value: FetchResponse) => void;
150
+ export interface PendingRequestResolvers {
151
+ resolve: PendingRequestResolver;
152
+ }
153
+ export interface RequestTracker {
154
+ active: string[];
155
+ pending: Map<string, PendingRequestResolvers[]>;
156
+ }
157
+ export type Shortcuts = Record<string, [string, SetRequired<RequestOptions, 'method'>]>;
158
+ export type Context = {
159
+ startTime?: number;
160
+ };
161
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAG7C,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAG9C,MAAM,MAAM,IAAI,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,K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CAAC,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,WAAW,CAAC,EAAE,CAAC;AAEjG,MAAM,WAAW,sBAAsB,CAAC,QAAQ,GAAG,WAAW;IAC5D,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;CAClB;AAED,MAAM,MAAM,oBAAoB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,kBAAkB,EAAE,MAAM,KAAK,MAAM,CAAC;AAEtH,MAAM,MAAM,sBAAsB,GAAG,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;AAEpE,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,sBAAsB,CAAC;CACjC;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,uBAAuB,EAAE,CAAC,CAAC;CACjD;AAED,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,WAAW,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;AAExF,MAAM,MAAM,OAAO,GAAG;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC"}
package/package.json CHANGED
@@ -1,160 +1,128 @@
1
1
  {
2
2
  "name": "getta",
3
- "version": "0.4.7",
4
3
  "description": "An isomorphic rest client based on the Fetch API.",
5
- "keywords": [
6
- "api-client",
7
- "fetch",
8
- "isomorphic",
9
- "rest"
10
- ],
11
- "homepage": "https://github.com/badbatch/getta",
12
- "bugs": {
13
- "url": "https://github.com/badbatch/getta/issues"
14
- },
15
- "repository": {
16
- "type": "git",
17
- "url": "git@github.com:badbatch/getta.git"
18
- },
4
+ "version": "1.0.1",
5
+ "author": "Dylan Aubrey",
19
6
  "license": "MIT",
20
- "author": "Dylan Aubrey <dylanaubrey@gmail.com>",
21
- "main": "lib/main/index.js",
22
- "module": "lib/module/index.mjs",
23
- "browser": "lib/browser/index.js",
24
- "types": "lib/types/index.d.ts",
25
- "scripts": {
26
- "build": "yarn run clean:libs && yarn run compile",
27
- "clean": "yarn run clean:libs && yarn run clean:docs && yarn run clean:repo",
28
- "clean:docs": "del-cli ./docs",
29
- "clean:libs": "del-cli ./lib",
30
- "clean:repo": "del-cli ./node_modules",
31
- "compile": "concurrently npm:compile:*",
32
- "compile-watch": "concurrently npm:compile-watch:*",
33
- "compile-watch:main": "yarn run compile:main --watch",
34
- "compile-watch:types": "yarn run compile:types --watch",
35
- "compile:browser": "cross-env BABEL_ENV=web rollup -c ./rollup.config.js",
36
- "compile:main": "cross-env BABEL_ENV=main babel ./src --out-dir ./lib/main --extensions \".ts\" --config-file ./babel.config.js",
37
- "compile:module": "cross-env BABEL_ENV=module babel ./src --out-dir ./lib/module --extensions \".ts\" --out-file-extension \".mjs\" --config-file ./babel.config.js",
38
- "compile:types": "tsc --declaration --declarationMap --emitDeclarationOnly",
39
- "cutoff": "cutoff",
40
- "cutoff:post-version": "yarn run compile && yarn run docs",
41
- "docs": "typedoc --includes ./src --out ./docs --options ./typedoc.js",
42
- "lint": "tslint --project ./tsconfig.json",
43
- "new-repo": "new-repo",
44
- "publish-cutoff": "publish-cutoff",
45
- "test": "jest --logHeapUsage",
46
- "type-check": "tsc --noEmit",
47
- "validate": "yarn run build && yarn run lint && yarn run type-check && yarn run test && yarn run docs",
48
- "wipe": "del-cli ./yarn.lock ./node_modules"
49
- },
50
- "husky": {
51
- "hooks": {
52
- "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
53
- }
7
+ "homepage": "https://github.com/badbatch/getta",
8
+ "repository": "https://github.com/badbatch/getta",
9
+ "bugs": "https://github.com/badbatch/getta/issues",
10
+ "type": "module",
11
+ "main": "./dist/main/index.mjs",
12
+ "types": "./dist/types/index.d.ts",
13
+ "publishConfig": {
14
+ "access": "public"
54
15
  },
55
16
  "dependencies": {
56
- "@cachemap/core": "^4.0.4",
57
- "@repodog/constants": "^0.3.29",
58
- "@repodog/helpers": "^0.3.27",
59
- "@repodog/types": "^0.3.26",
60
- "@types/md5": "^2.1.33",
61
- "cacheability": "^3.0.2",
62
- "md5": "^2.2.1",
63
- "query-string": "^6.11.1"
17
+ "cacheability": "^4.0.9",
18
+ "query-string": "^8.1.0",
19
+ "ts-md5": "^1.3.1"
64
20
  },
65
21
  "peerDependencies": {
66
- "@babel/runtime": "< 8",
67
- "core-js": "< 4",
68
- "isomorphic-fetch": "< 3",
69
- "lodash": "< 5"
22
+ "@babel/runtime": "<8",
23
+ "core-js": "<4",
24
+ "lodash-es": "<5"
70
25
  },
71
26
  "devDependencies": {
72
- "@babel/cli": "^7.8.4",
73
- "@babel/core": "^7.8.6",
74
- "@babel/plugin-proposal-class-properties": "^7.8.3",
75
- "@babel/plugin-proposal-decorators": "^7.8.3",
76
- "@babel/plugin-proposal-export-default-from": "^7.8.3",
77
- "@babel/plugin-proposal-export-namespace-from": "^7.8.3",
78
- "@babel/plugin-proposal-function-sent": "^7.8.3",
79
- "@babel/plugin-proposal-json-strings": "^7.8.3",
80
- "@babel/plugin-proposal-nullish-coalescing-operator": "^7.8.3",
81
- "@babel/plugin-proposal-numeric-separator": "^7.8.3",
82
- "@babel/plugin-proposal-optional-chaining": "^7.8.3",
83
- "@babel/plugin-proposal-throw-expressions": "^7.8.3",
27
+ "@babel/cli": "^7.21.5",
28
+ "@babel/core": "^7.21.8",
29
+ "@babel/eslint-parser": "^7.21.8",
30
+ "@babel/plugin-proposal-class-properties": "^7.18.6",
31
+ "@babel/plugin-proposal-export-namespace-from": "^7.18.9",
84
32
  "@babel/plugin-syntax-dynamic-import": "^7.8.3",
85
- "@babel/plugin-syntax-import-meta": "^7.8.3",
86
- "@babel/plugin-syntax-top-level-await": "^7.8.3",
87
- "@babel/plugin-transform-modules-commonjs": "^7.8.3",
88
- "@babel/plugin-transform-runtime": "^7.8.3",
89
- "@babel/preset-env": "^7.8.6",
90
- "@babel/preset-typescript": "^7.8.3",
91
- "@babel/register": "^7.8.6",
92
- "@babel/runtime": "^7.8.4",
93
- "@cachemap/constants": "^4.0.2",
94
- "@cachemap/controller": "^4.0.3",
95
- "@cachemap/map": "^4.0.3",
96
- "@commitlint/cli": "^8.3.5",
97
- "@commitlint/config-conventional": "^8.3.4",
98
- "@repodog/babel-config": "^0.3.31",
99
- "@repodog/commitlint-config": "^0.3.24",
100
- "@repodog/config-helpers": "^0.3.30",
101
- "@repodog/constants": "^0.3.29",
102
- "@repodog/eslint-config": "^0.3.26",
103
- "@repodog/jest-config": "^0.3.31",
104
- "@repodog/markdownlint-config": "^0.3.24",
105
- "@repodog/new-repo": "^0.3.38",
106
- "@repodog/prettier-config": "^0.3.25",
107
- "@repodog/rollup-config": "^0.3.27",
108
- "@repodog/ts-config": "^0.3.24",
109
- "@repodog/tslint-config": "^0.3.26",
110
- "@repodog/typedoc-config": "^0.3.24",
111
- "@types/fetch-mock": "^7.3.2",
112
- "@types/fs-extra": "^8.1.0",
33
+ "@babel/plugin-syntax-import-assertions": "^7.20.0",
34
+ "@babel/plugin-transform-runtime": "^7.21.4",
35
+ "@babel/preset-env": "^7.21.5",
36
+ "@babel/preset-react": "^7.18.6",
37
+ "@babel/preset-typescript": "^7.21.5",
38
+ "@babel/runtime": "^7.21.5",
39
+ "@cachemap/core": "^5.0.0",
40
+ "@cachemap/map": "^5.0.0",
41
+ "@commitlint/cli": "^17.6.3",
42
+ "@commitlint/config-conventional": "^17.6.3",
43
+ "@commitlint/prompt-cli": "^17.6.3",
44
+ "@jest/globals": "^29.5.0",
45
+ "@repodog/babel-config": "^1.1.7",
46
+ "@repodog/cli": "^1.1.9",
47
+ "@repodog/commitlint-config": "^1.1.5",
48
+ "@repodog/eslint-config": "^1.1.11",
49
+ "@repodog/eslint-config-jest": "^1.1.9",
50
+ "@repodog/jest-config": "^1.1.9",
51
+ "@repodog/markdownlint-config": "^1.1.5",
52
+ "@repodog/prettier-config": "^1.1.5",
53
+ "@repodog/rollup-config": "^1.1.6",
54
+ "@repodog/syncpack-config": "^1.1.5",
55
+ "@repodog/ts-config": "^1.1.5",
56
+ "@rollup/plugin-babel": "^6.0.3",
57
+ "@rollup/plugin-image": "^3.0.2",
58
+ "@rollup/plugin-json": "^6.0.0",
59
+ "@rollup/plugin-node-resolve": "^15.0.2",
60
+ "@rollup/plugin-terser": "^0.4.1",
113
61
  "@types/jest": "^25.1.3",
114
- "@types/lodash": "^4.14.149",
115
- "@types/node": "^13.7.7",
116
- "babel-eslint": "^10.1.0",
117
- "babel-plugin-lodash": "^3.3.4",
118
- "concurrently": "^5.1.0",
119
- "core-js": "^3.6.4",
120
- "cross-env": "^7.0.0",
121
- "cutoff": "^0.2.7",
62
+ "@types/lodash-es": "^4.17.9",
63
+ "@types/node": "^18.11.18",
64
+ "@typescript-eslint/eslint-plugin": "^5.59.5",
65
+ "@typescript-eslint/parser": "^5.59.5",
66
+ "babel-jest": "^29.5.0",
67
+ "babel-plugin-codegen": "^4.1.5",
68
+ "babel-plugin-macros": "^3.1.0",
69
+ "core-js": "^3.27.2",
122
70
  "del-cli": "^3.0.0",
123
- "dotenv": "^8.0.0",
124
- "eslint": "^6.8.0",
125
- "eslint-config-airbnb": "^18.0.1",
126
- "eslint-config-prettier": "^6.10.0",
127
- "eslint-plugin-import": "^2.20.1",
128
- "eslint-plugin-prettier": "^3.1.2",
129
- "eslint-plugin-sort-class-members": "^1.6.0",
130
- "fetch-mock": "^9.0.0",
131
- "fs-extra": "^8.1.0",
132
- "husky": "^4.2.3",
133
- "isomorphic-fetch": "^2.2.1",
134
- "jest": "^25.1.0",
135
- "lodash": "^4.17.5",
136
- "markdownlint-cli": "^0.22.0",
137
- "prettier": "^1.19.1",
138
- "rollup": "^1.32.0",
139
- "rollup-plugin-analyzer": "^3.2.2",
140
- "rollup-plugin-babel": "^5.0.0-alpha.1",
141
- "rollup-plugin-commonjs": "^10.1.0",
142
- "rollup-plugin-json": "^4.0.0",
143
- "rollup-plugin-node-resolve": "^5.2.0",
144
- "rollup-plugin-terser": "^5.2.0",
145
- "ts-jest": "^25.2.1",
146
- "ts-node": "^8.6.2",
147
- "ts-toolbelt": "^6.3.5",
148
- "tslint": "^6.0.0",
149
- "tslint-config-prettier": "^1.18.0",
150
- "tslint-plugin-prettier": "^2.1.0",
151
- "type-fest": "^0.11.0",
152
- "typedoc": "^0.16.11",
153
- "typedoc-plugin-markdown": "^2.2.17",
154
- "typescript": "^3.8.3",
155
- "utility-types": "^3.10.0"
71
+ "eslint": "^8.40.0",
72
+ "eslint-config-prettier": "^8.8.0",
73
+ "eslint-import-resolver-typescript": "^3.5.5",
74
+ "eslint-plugin-import": "^2.27.5",
75
+ "eslint-plugin-jest": "^27.2.1",
76
+ "eslint-plugin-prettier": "^4.2.1",
77
+ "eslint-plugin-sort-class-members": "^1.18.0",
78
+ "eslint-plugin-sort-destructure-keys": "^1.5.0",
79
+ "eslint-plugin-sort-keys-fix": "^1.1.2",
80
+ "eslint-plugin-typescript-sort-keys": "^2.3.0",
81
+ "eslint-plugin-unicorn": "^46.0.1",
82
+ "fetch-mocked": "^0.0.3",
83
+ "generate-changelog": "^1.8.0",
84
+ "husky": "^8.0.3",
85
+ "identity-obj-proxy": "^3.0.0",
86
+ "jest": "^29.5.0",
87
+ "jest-environment-jsdom": "^29.7.0",
88
+ "jest-environment-node": "^29.7.0",
89
+ "jest-mock": "^29.7.0",
90
+ "lodash-es": "^4.17.21",
91
+ "markdownlint-cli": "^0.34.0",
92
+ "node-fetch": "^3.3.2",
93
+ "prettier": "^2.8.8",
94
+ "rollup": "^3.21.6",
95
+ "rollup-plugin-analyzer": "^4.0.0",
96
+ "rollup-plugin-copy": "^3.4.0",
97
+ "rollup-plugin-sourcemaps": "^0.6.3",
98
+ "suppress-experimental-warnings": "^1.1.17",
99
+ "syncpack": "^9.8.6",
100
+ "type-fest": "^3.10.0",
101
+ "typescript": "^5.0.3",
102
+ "vitest": "^0.34.6",
103
+ "zod": "^3.22.4"
156
104
  },
157
- "engines": {
158
- "node": "< 10.16.0"
105
+ "keywords": [
106
+ "api-client",
107
+ "fetch",
108
+ "isomorphic",
109
+ "rest"
110
+ ],
111
+ "scripts": {
112
+ "build": "pnpm run clean:dist && pnpm run compile",
113
+ "clean:deps": "del-cli ./node_modules",
114
+ "clean:dist": "del-cli ./dist",
115
+ "commit": "commit",
116
+ "compile": "pnpm run /^compile:.*/",
117
+ "compile:main": "rollup -c ./rollup.config.cjs",
118
+ "compile:types": "tsc --project ./tsconfig.build.json",
119
+ "cut:changelog": "changelog",
120
+ "cut:post-version": "pnpm run build",
121
+ "lint": "eslint . --ext .ts,.cjs",
122
+ "repodog": "repodog",
123
+ "syncpack": "syncpack",
124
+ "test": "node --require=suppress-experimental-warnings --experimental-vm-modules node_modules/jest/bin/jest.js",
125
+ "type-check": "tsc --noEmit",
126
+ "validate": "syncpack format && syncpack lint-semver-ranges && pnpm run build && pnpm run lint && pnpm run type-check && pnpm run test"
159
127
  }
160
- }
128
+ }
@@ -56,7 +56,7 @@
56
56
  "defaultSku": {
57
57
  "defaultImage": {
58
58
  "mediaType": "Large",
59
- "src": "https://tesco.scene7.com/is/image/tesco/136-7317_PI_66650MN?$[preset]$",
59
+ "src": "https://example.scene7.com/is/image/example/136-7317_PI_66650MN?$[preset]$",
60
60
  "renderSource": "Scene 7",
61
61
  "defaultImage": true
62
62
  }
@@ -72,7 +72,7 @@
72
72
  "defaultSku": {
73
73
  "defaultImage": {
74
74
  "mediaType": "Large",
75
- "src": "https://tesco.scene7.com/is/image/tesco/180-1387_PI_TPS2696380?$[preset]$",
75
+ "src": "https://example.scene7.com/is/image/example/180-1387_PI_TPS2696380?$[preset]$",
76
76
  "renderSource": "Scene 7",
77
77
  "alt": "String",
78
78
  "defaultImage": true
@@ -74,7 +74,7 @@
74
74
  "defaultSku": {
75
75
  "defaultImage": {
76
76
  "mediaType": "Large",
77
- "src": "https://tesco.scene7.com/is/image/tesco/183-3905_PI_TPS2456767?$[preset]$",
77
+ "src": "https://example.scene7.com/is/image/example/183-3905_PI_TPS2456767?$[preset]$",
78
78
  "renderSource": "Scene 7",
79
79
  "alt": "String",
80
80
  "defaultImage": true
@@ -55,7 +55,7 @@
55
55
  "defaultSku": {
56
56
  "defaultImage": {
57
57
  "mediaType": "Large",
58
- "src": "https://tesco.scene7.com/is/image/tesco/202-3315_PI_66650AL2?$[preset]$",
58
+ "src": "https://example.scene7.com/is/image/example/202-3315_PI_66650AL2?$[preset]$",
59
59
  "renderSource": "Scene 7",
60
60
  "defaultImage": true
61
61
  }
@@ -0,0 +1,23 @@
1
+ export const PRD_136_7317 = {
2
+ // eslint-disable-next-line unicorn/no-await-expression-member
3
+ body: (await import('./136-7317.json')).default,
4
+ url: 'https://www.example.com/direct/rest/content/catalog/product/136-7317',
5
+ };
6
+
7
+ export const PRD_180_1387 = {
8
+ // eslint-disable-next-line unicorn/no-await-expression-member
9
+ body: (await import('./180-1387.json')).default,
10
+ url: 'https://www.example.com/direct/rest/content/catalog/product/180-1387',
11
+ };
12
+
13
+ export const PRD_183_3905 = {
14
+ // eslint-disable-next-line unicorn/no-await-expression-member
15
+ body: (await import('./183-3905.json')).default,
16
+ url: 'https://www.example.com/direct/rest/content/catalog/product/183-3905',
17
+ };
18
+
19
+ export const PRD_202_3315 = {
20
+ // eslint-disable-next-line unicorn/no-await-expression-member
21
+ body: (await import('./202-3315.json')).default,
22
+ url: 'https://www.example.com/direct/rest/content/catalog/product/202-3315',
23
+ };
@@ -0,0 +1,49 @@
1
+ import { Core } from '@cachemap/core';
2
+ import { init as map } from '@cachemap/map';
3
+ import { DEFAULT_PATH_TEMPLATE_REGEX } from '../../constants.ts';
4
+ import { buildEndpoint } from '../../helpers/buildEndpoint/index.ts';
5
+ import { defaultPathTemplateCallback } from '../../helpers/defaultPathTemplateCallback/index.ts';
6
+ import { OPTIONAL_PATH_TEMPLATE_REGEX } from '../../index.ts';
7
+ import { type RequestOptions } from '../../types.ts';
8
+
9
+ export const basePath = 'https://example.com';
10
+
11
+ export const defaultPath = '/direct/rest/content/catalog/{type}/{id,+}?format={brief|standard}';
12
+
13
+ export const graphqlPath = '/graphql/api';
14
+
15
+ export const defaultPathTemplateData = { 'brief|standard': 'standard', 'id,+': '136-7317', type: 'product' };
16
+
17
+ export const defaultPayload = { payload: true };
18
+
19
+ export const idPathTemplateData = { 'id,+': '136-7317' };
20
+
21
+ export const pathTemplateDataWithoutID = { 'brief|standard': 'standard', type: 'product' };
22
+
23
+ export const defaultEtag = '33a64df551425fcc55e4d42a148795d9f25f89d4';
24
+
25
+ export const defaultHeaders = {
26
+ 'cache-control': 'public, max-age=6000',
27
+ 'content-type': 'application/json',
28
+ etag: defaultEtag,
29
+ };
30
+
31
+ export const getCache = () => {
32
+ return new Core({
33
+ name: 'cachemap',
34
+ store: map(),
35
+ type: 'test',
36
+ });
37
+ };
38
+
39
+ export const buildTestEndpoint = (
40
+ path: string,
41
+ { pathTemplateData = defaultPathTemplateData, queryParams }: RequestOptions = {}
42
+ ) =>
43
+ buildEndpoint(basePath, path, {
44
+ optionalPathTemplateRegExp: OPTIONAL_PATH_TEMPLATE_REGEX,
45
+ pathTemplateCallback: defaultPathTemplateCallback,
46
+ pathTemplateData,
47
+ pathTemplateRegExp: DEFAULT_PATH_TEMPLATE_REGEX,
48
+ queryParams,
49
+ });